diff --git a/contracts/DODOToken/DODOCirculationHelper.sol b/contracts/DODOToken/DODOCirculationHelper.sol index 05dcd29..0c66fb1 100644 --- a/contracts/DODOToken/DODOCirculationHelper.sol +++ b/contracts/DODOToken/DODOCirculationHelper.sol @@ -1,4 +1,4 @@ - /* +/* Copyright 2020 DODO ZOO. SPDX-License-Identifier: Apache-2.0 @@ -10,10 +10,7 @@ pragma experimental ABIEncoderV2; import {IERC20} from "../intf/IERC20.sol"; import {SafeMath} from "../lib/SafeMath.sol"; import {DecimalMath} from "../lib/DecimalMath.sol"; -import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; -import {SafeERC20} from "../lib/SafeERC20.sol"; -import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol"; -import {IDODOApproveProxy} from "../SmartRoute/DODOApproveProxy.sol"; +import {Ownable} from "../lib/Ownable.sol"; interface IDODOCirculationHelper { // vDODO 锁仓不算流通 @@ -30,16 +27,30 @@ contract DODOCirculationHelper is Ownable { address immutable _DODO_TOKEN_; address[] _LOCKED_CONTRACT_ADDRESS_; - uint256 public _MIN_PENALTY_RATIO_ = 5 * 10**16; // 5% + uint256 public _MIN_PENALTY_RATIO_ = 5 * 10**16; // 5% uint256 public _MAX_PENALTY_RATIO_ = 15 * 10**16; // 15% - // ============= Helper and calculation function =============== - function getVDODOWithdrawFeeRatio() internal returns (uint256) { - uint256 dodoCirculationAmout = - IDODOCirculationHelper(_DODO_CIRCULATION_HELPER_).getCirculation(); - // (x - 1)^2 / 81 + (y - 15)^2 / 100 = 1 ==> y = sqrt(100* (x*x +2x ) / 81)) +15 + constructor(address dodoToken) public { + _DODO_TOKEN_ = dodoToken; + } // todo + + function addLockedContractAddress(address lockedContract) external onlyOwner {} // todo + + function removeLockedContractAddress(address lockedContract) external onlyOwner {} // todo + + function getCirculation() public view returns (uint256 circulation) { + circulation = 10**9; + for (uint256 i = 0; i < _LOCKED_CONTRACT_ADDRESS_.length; i++) { + circulation -= IERC20(_DODO_TOKEN_).balanceOf(_LOCKED_CONTRACT_ADDRESS_[i]); + } + } + + function getVDODOWithdrawFeeRatio() external view returns (uint256 ratio) { + uint256 dodoCirculationAmout = getCirculation(); + // (x - 1)^2 / 81 + (y - 15)^2 / 100 = 1 // y = 5% (x ≤ 1) // y = 15% (x ≥ 10) + // y = 15% - 10% * sqrt(1-[(x-1)/9]^2) uint256 x = DecimalMath.divCeil( dodoCirculationAmout, @@ -51,16 +62,11 @@ contract DODOCirculationHelper is Ownable { } else if (x >= 10**19) { return _MAX_PENALTY_RATIO_; } else { - uint256 xSubOne = x.sub(DecimalMath.ONE); - xSubOne.sub(9) - uint256 rewardAmount = - uint256(81 * 10**18).sub(xSubOne.mul(xSubOne)).mul(100).div(81).sqrt().add(15); - return rewardAmount; + uint256 xTemp = x.sub(DecimalMath.ONE).div(9); + uint256 premium = DecimalMath.ONE2.sub(xTemp.mul(xTemp)).sqrt(); + ratio = + _MAX_PENALTY_RATIO_ - + DecimalMath.mulFloor(_MAX_PENALTY_RATIO_ - _MIN_PENALTY_RATIO_, premium); } } - - - } - - \ No newline at end of file