emergency withdraw & refactor lp management
This commit is contained in:
parent
f853f019d7
commit
6beafd9b35
@ -1,79 +0,0 @@
|
|||||||
pragma solidity 0.8.0;
|
|
||||||
|
|
||||||
import "@openzeppelin/token/ERC20/IERC20.sol";
|
|
||||||
import "@interfaces/IUniswapV2Router02.sol";
|
|
||||||
|
|
||||||
contract LiquidityManagement {
|
|
||||||
|
|
||||||
address constant DAI_ADDRESS = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
|
|
||||||
address constant TORN_ADDRESS = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
|
|
||||||
address constant ETH_TORN_ADDRESS = 0x0C722a487876989Af8a05FFfB6e32e45cc23FB3A;
|
|
||||||
address constant DAI_TORN_ADDRESS = 0xb9C6f39dB4e81DB44Cf057C7D4d8e3193745101E;
|
|
||||||
address constant UNIV2_ROUTER02_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
|
|
||||||
address constant TORN_TREASURY = 0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce;
|
|
||||||
|
|
||||||
IERC20 DAI;
|
|
||||||
IERC20 TORN;
|
|
||||||
IERC20 UNIV2_DAI_TORN;
|
|
||||||
IERC20 UNIV2_ETH_TORN;
|
|
||||||
IUniswapV2Router02 UNIV2_ROUTER;
|
|
||||||
|
|
||||||
constructor() public {
|
|
||||||
IERC20 DAI = IERC20(DAI_ADDRESS);
|
|
||||||
IERC20 TORN = IERC20(TORN_ADDRESS);
|
|
||||||
IERC20 UNIV2_DAI_TORN = IERC20(DAI_TORN_ADDRESS);
|
|
||||||
IERC20 UNIV2_ETH_TORN = IERC20(ETH_TORN_ADDRESS);
|
|
||||||
IUniswapV2Router02 UNIV2_ROUTER = IUniswapV2Router02(UNIV2_ROUTER02_ADDRESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add liquidity to the DAI/TORN and ETH/TORN pools
|
|
||||||
function addLiquidityAndWithdrawToTreasury(
|
|
||||||
uint256 amountETH,
|
|
||||||
uint256 amountDAI,
|
|
||||||
uint256 amountTORN,
|
|
||||||
uint256 slippageETH,
|
|
||||||
uint256 slippageTORN,
|
|
||||||
uint256 slippageDAI
|
|
||||||
) public returns (bool) {
|
|
||||||
// transfer tokens from the user to the contract
|
|
||||||
require(DAI.transferFrom(msg.sender, address(this), amountDAI));
|
|
||||||
require(TORN.transferFrom(msg.sender, address(this), amountTORN));
|
|
||||||
require(msg.value == amountETH);
|
|
||||||
|
|
||||||
// deadline for the transaction to be mined (10 minutes)
|
|
||||||
uint256 deploymentDeadline = block.timestamp + 10 minutes;
|
|
||||||
// Split the TORN amount in half for the two liquidity pools
|
|
||||||
uint256 amountSeedTORN = amountTORN / 2;
|
|
||||||
// configure slippage
|
|
||||||
uint256 minimumAmountDAI = amountDAI - slippageDAI;
|
|
||||||
uint256 minimumAmountETH = amountETH - slippageETH;
|
|
||||||
uint256 minimumAmountTORN = amountSeedTORN - slippageTORN;
|
|
||||||
|
|
||||||
// DAI/TORN
|
|
||||||
DAI.approve(UNIV2_ROUTER02_ADDRESS, amountDAI);
|
|
||||||
UNIV2_ROUTER.addLiquidity(
|
|
||||||
DAI_ADDRESS, // tokenA address
|
|
||||||
TORN_ADDRESS, // tokenB address
|
|
||||||
amountDAI, // tokenA amount
|
|
||||||
amountSeedTORN, // tokenB amount
|
|
||||||
minimumAmountDAI, // minimum tokenA amount
|
|
||||||
minimumAmountTORN, // minimum tokenB amount
|
|
||||||
TORN_TREASURY, // to
|
|
||||||
deploymentDeadline, // deadline
|
|
||||||
);
|
|
||||||
|
|
||||||
// ETH/TORN
|
|
||||||
TORN.approve(UNIV2_ROUTER02_ADDRESS, amountTORN);
|
|
||||||
UNIV2_ROUTER.addLiquidityETH(
|
|
||||||
TORN_ADDRESS, // token address
|
|
||||||
amountSeedTORN, // token amount
|
|
||||||
minimumAmountTORN, // minimum token amount
|
|
||||||
minimumAmountETH, // minimum eth amount
|
|
||||||
TORN_TREASURY, // to
|
|
||||||
deploymentDeadline, // deadline
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +1,41 @@
|
|||||||
pragma solidity 0.8.13;
|
pragma solidity 0.8.13;
|
||||||
|
|
||||||
import "@openzeppelin/token/ERC20/IERC20.sol";
|
import "@openzeppelin/token/ERC20/IERC20.sol";
|
||||||
|
import "@interfaces/IUniswapV2Router02.sol";
|
||||||
import "@root/DelegatedVesting.sol";
|
import "@root/DelegatedVesting.sol";
|
||||||
import "@root/RDA.sol";
|
import "@root/RDA.sol";
|
||||||
|
|
||||||
contract Proposal {
|
contract Proposal {
|
||||||
|
|
||||||
address tokenAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
|
address _tokenAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
|
||||||
address wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
|
address _wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
|
||||||
address governanceAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
|
address _governanceAddress = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C;
|
||||||
|
address _routerAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
|
||||||
|
|
||||||
address vestingAddress = address(new DelegatedVesting(tokenAddress, governanceAddress));
|
address _vestingAddress = address(new DelegatedVesting(_tokenAddress, _governanceAddress));
|
||||||
address auctionAddress = address(new RDA());
|
address _auctionAddress = address(new RDA());
|
||||||
|
|
||||||
uint256 VESTING_PERIOD = 10 weeks;
|
uint256 VESTING_PERIOD = 10 weeks;
|
||||||
uint256 AUCTION_START_TS = block.timestamp;
|
uint256 AUCTION_START_TS = block.timestamp;
|
||||||
uint256 AUCTION_END_TS = AUCTION_START_TS + 1 weeks;
|
uint256 AUCTION_END_TS = AUCTION_START_TS + 1 weeks;
|
||||||
uint256 AUCTION_ORIGIN_PRICE = 4172000 gwei;
|
uint256 AUCTION_ORIGIN_PRICE = 4172000 gwei;
|
||||||
uint256 AUCTION_RESERVE_AMOUNT = 100000 ether;
|
uint256 AUCTION_RESERVE_AMOUNT = 100000 ether;
|
||||||
|
uint256 AUCTION_PROVISION_AMOUNT = 100000 ether;
|
||||||
uint256 AUCTION_MINIMUM_AMOUNT = 1 ether;
|
uint256 AUCTION_MINIMUM_AMOUNT = 1 ether;
|
||||||
uint256 AUCTION_WINDOW_LENGTH = 8 hours;
|
uint256 AUCTION_WINDOW_LENGTH = 8 hours;
|
||||||
|
|
||||||
function executeProposal() external {
|
function executeProposal() external {
|
||||||
IERC20(tokenAddress).approve(auctionAddress, AUCTION_RESERVE_AMOUNT);
|
uint256 totalExpenditures = AUCTION_RESERVE_AMOUNT + AUCTION_PROVISION_AMOUNT;
|
||||||
IRDA(auctionAddress).createAuction(
|
|
||||||
vestingAddress,
|
IERC20(_tokenAddress).approve(address(this), totalExpenditures);
|
||||||
governanceAddress,
|
IERC20(_tokenAddress).transferFrom(msg.sender, address(this), totalExpenditures);
|
||||||
tokenAddress,
|
IERC20(_tokenAddress).approve(_auctionAddress, AUCTION_RESERVE_AMOUNT);
|
||||||
wethAddress,
|
|
||||||
|
IRDA(_auctionAddress).createAuction(
|
||||||
|
_vestingAddress,
|
||||||
|
address(this),
|
||||||
|
_tokenAddress,
|
||||||
|
_wethAddress,
|
||||||
AUCTION_RESERVE_AMOUNT,
|
AUCTION_RESERVE_AMOUNT,
|
||||||
AUCTION_MINIMUM_AMOUNT,
|
AUCTION_MINIMUM_AMOUNT,
|
||||||
AUCTION_ORIGIN_PRICE,
|
AUCTION_ORIGIN_PRICE,
|
||||||
@ -38,4 +46,36 @@ contract Proposal {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addLiquidity(uint256 amountA, uint256 amountB) external {
|
||||||
|
uint256 amountMinimumA = amountA - 1;
|
||||||
|
uint256 amountMinimumB = amountB - 1;
|
||||||
|
uint256 expiryTimestamp = block.timestamp + 5 minutes;
|
||||||
|
|
||||||
|
IERC20(_tokenAddress).approve(_routerAddress, amountB);
|
||||||
|
IERC20(_wethAddress).approve(_routerAddress, amountA);
|
||||||
|
IUniswapV2Router02(_routerAddress).addLiquidity(
|
||||||
|
_wethAddress,
|
||||||
|
_tokenAddress,
|
||||||
|
amountMinimumA,
|
||||||
|
amountMinimumB,
|
||||||
|
amountA,
|
||||||
|
amountB,
|
||||||
|
_governanceAddress,
|
||||||
|
expiryTimestamp
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function emergencyWithdraw() external {
|
||||||
|
require(AUCTION_END_TS + 2 weeks < block.timestamp, "INVALID EMERGENCY PERIOD");
|
||||||
|
|
||||||
|
uint256 tokenBalance = IERC20(_tokenAddress).balanceOf(address(this));
|
||||||
|
uint256 wethBalance = IERC20(_wethAddress).balanceOf(address(this));
|
||||||
|
|
||||||
|
if(0 < tokenBalance) {
|
||||||
|
IERC20(_tokenAddress).transfer(_governanceAddress, tokenBalance);
|
||||||
|
} if (0 < wethBalance) {
|
||||||
|
IERC20(_wethAddress).transfer(_governanceAddress, wethBalance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user