fix dodomath

This commit is contained in:
owen05
2021-01-13 20:39:41 +08:00
parent 847d0bf895
commit 74a12f54c6
9 changed files with 108 additions and 27 deletions

View File

@@ -97,7 +97,7 @@ contract DODOIncentive is InitializableOwnable {
}
// ============ Incentive function============
// ============ Incentive function ============
function triggerIncentive(address fromToken,address toToken, address assetTo) external {
require(msg.sender == _DODO_PROXY_, "DODOIncentive:Access restricted");
@@ -128,4 +128,23 @@ contract DODOIncentive is InitializableOwnable {
totalReward = uint112(_totalReward);
totalDistribution = uint112(_totalDistribution);
}
// ============= Helper function ===============
function incentiveStatus(address fromToken, address toToken) external view returns (bool isOpen, uint256 reward, uint256 baseRate, uint256 totalRate) {
if(startBlock != 0 && block.number >= startBlock) {
isOpen = true;
baseRate = defaultRate;
uint256 fromRate = boosts[fromToken];
uint256 toRate = boosts[toToken];
totalRate = (fromRate >= toRate ? fromRate : toRate) + defaultRate;
uint256 _totalReward = totalReward + (block.number - lastRewardBlock) * dodoPerBlock;
reward = (_totalReward - totalDistribution) * totalRate / 1000;
}else {
isOpen = false;
reward = 0;
baseRate = 0;
totalRate = 0;
}
}
}

View File

@@ -645,17 +645,22 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
IUni(curPair).swapExactTokensForTokens(curAmountIn,0,portionPath,address(this),deadLine);
}
}
IERC20(_toToken).universalTransfer(
msg.sender,
IERC20(_toToken).universalBalanceOf(address(this))
);
{
uint256 toBalance;
if (_toToken == _ETH_ADDRESS_) {
toBalance = IWETH(_WETH_).balanceOf(address(this));
IWETH(_WETH_).withdraw(toBalance);
} else {
toBalance = IERC20(_toToken).tokenBalanceOf(address(this));
}
IERC20(_toToken).universalTransfer(msg.sender,toBalance);
}
// {
// uint256 toBalance;
// if (_toToken == _ETH_ADDRESS_) {
// toBalance = IWETH(_WETH_).balanceOf(address(this));
// IWETH(_WETH_).withdraw(toBalance);
// } else {
// toBalance = IERC20(_toToken).tokenBalanceOf(address(this));
// }
// IERC20(_toToken).universalTransfer(msg.sender,toBalance);
// }
returnAmount = IERC20(_toToken).universalBalanceOf(msg.sender).sub(toTokenOriginBalance);
require(returnAmount >= minReturnAmount, "DODOV2Proxy01: Return amount is not enough");