dodo-start && cpV2 ing
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {InstantFunding} from "./InstantFunding.sol";
|
||||
import {Storage} from "./Storage.sol";
|
||||
import {IDVM} from "../../DODOVendingMachine/intf/IDVM.sol";
|
||||
import {IDVMFactory} from "../../Factory/DVMFactory.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
@@ -16,69 +16,82 @@ import {DecimalMath} from "../../lib/DecimalMath.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||
|
||||
contract Vesting is InstantFunding {
|
||||
contract Vesting is Storage {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
// ============ Timeline ============
|
||||
|
||||
uint256 public _TOKEN_VESTING_START_;
|
||||
uint256 public _TOKEN_VESTING_DURATION_;
|
||||
mapping(address => uint256) _CLAIMED_TOKEN_;
|
||||
|
||||
uint256 public _FUNDS_VESTING_START_;
|
||||
uint256 public _FUNDS_VESTING_DURATION_;
|
||||
uint256 _CLAIMED_FUNDS_;
|
||||
|
||||
uint256 public _LP_VESTING_START_;
|
||||
uint256 public _LP_VESTING_DURATION_;
|
||||
uint256 _CLAIMED_LP_;
|
||||
|
||||
// ============ Liquidity Params ============
|
||||
|
||||
address public _POOL_FACTORY_;
|
||||
address public _INITIAL_POOL_;
|
||||
uint256 public _INITIAL_FUND_LIQUIDITY_;
|
||||
uint256 public _TOTAL_LP_;
|
||||
|
||||
function claimToken(address to) external {
|
||||
uint256 totalAllocation = getUserTokenAllocation(msg.sender);
|
||||
uint256 unlockedAllocation = totalAllocation
|
||||
.mul(block.timestamp.sub(_TOKEN_VESTING_START_))
|
||||
.div(_TOKEN_VESTING_DURATION_);
|
||||
IERC20(_TOKEN_ADDRESS_).safeTransfer(
|
||||
to,
|
||||
unlockedAllocation.sub(_CLAIMED_TOKEN_[msg.sender])
|
||||
function _claimToken(address to, uint256 totalAllocation) internal {
|
||||
uint256 remainingToken = DecimalMath.mulFloor(
|
||||
getRemainingRatio(block.timestamp,0),
|
||||
totalAllocation
|
||||
);
|
||||
_CLAIMED_TOKEN_[msg.sender] = unlockedAllocation;
|
||||
uint256 claimableTokenAmount = totalAllocation.sub(remainingToken).sub(_CLAIMED_TOKEN_[msg.sender]);
|
||||
IERC20(_TOKEN_ADDRESS_).safeTransfer(to,claimableTokenAmount);
|
||||
_CLAIMED_TOKEN_[msg.sender] = _CLAIMED_TOKEN_[msg.sender].add(claimableTokenAmount);
|
||||
}
|
||||
|
||||
function claimFunds(address to) external preventReentrant onlyOwner {
|
||||
uint256 vestingFunds = _TOTAL_RAISED_FUNDS_.sub(_INITIAL_FUND_LIQUIDITY_);
|
||||
uint256 unlockedFunds = vestingFunds.mul(block.timestamp.sub(_FUNDS_VESTING_START_)).div(
|
||||
_FUNDS_VESTING_DURATION_
|
||||
uint256 remainingFund = DecimalMath.mulFloor(
|
||||
getRemainingRatio(block.timestamp,1),
|
||||
vestingFunds
|
||||
);
|
||||
IERC20(_TOKEN_ADDRESS_).safeTransfer(to, unlockedFunds.sub(_CLAIMED_FUNDS_));
|
||||
_CLAIMED_FUNDS_ = unlockedFunds;
|
||||
uint256 claimableFund = vestingFunds.sub(remainingFund).sub(_CLAIMED_FUNDS_);
|
||||
IERC20(_FUNDS_ADDRESS_).safeTransfer(to, claimableFund);
|
||||
_CLAIMED_FUNDS_ = _CLAIMED_FUNDS_.add(claimableFund);
|
||||
}
|
||||
|
||||
function claimLp(address to) external preventReentrant onlyOwner {
|
||||
require(_INITIAL_POOL_ != address(0), "LIQUIDITY_NOT_ESTABLISHED");
|
||||
uint256 unlockedLp = _TOTAL_LP_.mul(block.timestamp.sub(_LP_VESTING_START_)).div(
|
||||
_LP_VESTING_DURATION_
|
||||
uint256 remainingLp = DecimalMath.mulFloor(
|
||||
getRemainingRatio(block.timestamp,2),
|
||||
_TOTAL_LP_
|
||||
);
|
||||
IERC20(_TOKEN_ADDRESS_).safeTransfer(to, unlockedLp.sub(_CLAIMED_LP_));
|
||||
_CLAIMED_LP_ = unlockedLp;
|
||||
uint256 claimableLp = _TOTAL_LP_.sub(remainingLp).sub(_CLAIMED_LP_);
|
||||
|
||||
IERC20(_INITIAL_POOL_).safeTransfer(to, claimableLp);
|
||||
_CLAIMED_LP_ = _CLAIMED_LP_.add(claimableLp);
|
||||
}
|
||||
|
||||
function initializeLiquidity(uint256 initialTokenAmount) external preventReentrant onlyOwner {
|
||||
|
||||
//tokenType 0: BaseToken, 1: Fund, 2: LpToken
|
||||
function getRemainingRatio(uint256 timestamp, uint256 tokenType) public view returns (uint256) {
|
||||
uint256 vestingStart;
|
||||
uint256 vestingDuration;
|
||||
uint256 cliffRate;
|
||||
|
||||
if(tokenType == 0) {
|
||||
vestingStart = _TOKEN_VESTING_START_;
|
||||
vestingDuration = _TOKEN_VESTING_DURATION_;
|
||||
cliffRate = _TOKEN_CLIFF_RATE_;
|
||||
} else if(tokenType == 1) {
|
||||
vestingStart = _FUNDS_VESTING_START_;
|
||||
vestingDuration = _FUNDS_VESTING_DURATION_;
|
||||
cliffRate = _FUNDS_CLIFF_RATE_;
|
||||
} else {
|
||||
vestingStart = _LP_VESTING_START_;
|
||||
vestingDuration = _LP_VESTING_DURATION_;
|
||||
cliffRate = _LP_CLIFF_RATE_;
|
||||
}
|
||||
|
||||
uint256 timePast = timestamp.sub(vestingStart);
|
||||
if (timePast < vestingDuration) {
|
||||
uint256 remainingTime = vestingDuration.sub(timePast);
|
||||
return DecimalMath.ONE.sub(cliffRate).mul(remainingTime).div(vestingDuration);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function initializeLiquidity(uint256 initialTokenAmount, uint256 lpFeeRate, bool isOpenTWAP) external preventReentrant onlyOwner {
|
||||
_INITIAL_POOL_ = IDVMFactory(_POOL_FACTORY_).createDODOVendingMachine(
|
||||
_TOKEN_ADDRESS_,
|
||||
_FUNDS_ADDRESS_,
|
||||
3e15, // 0.3% lp feeRate DIP3
|
||||
lpFeeRate,
|
||||
1,
|
||||
DecimalMath.ONE,
|
||||
true //TODO:是否开启
|
||||
isOpenTWAP
|
||||
);
|
||||
IERC20(_TOKEN_ADDRESS_).transferFrom(msg.sender, _INITIAL_POOL_, initialTokenAmount);
|
||||
IERC20(_FUNDS_ADDRESS_).transfer(_INITIAL_POOL_, _INITIAL_FUND_LIQUIDITY_);
|
||||
|
||||
Reference in New Issue
Block a user