2021-02-01 13:31:03 +08:00
|
|
|
/*
|
2021-02-01 11:58:01 +08:00
|
|
|
|
|
|
|
|
Copyright 2020 DODO ZOO.
|
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
pragma solidity 0.6.9;
|
|
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
|
|
|
|
|
import {IERC20} from "../intf/IERC20.sol";
|
|
|
|
|
import {SafeMath} from "../lib/SafeMath.sol";
|
|
|
|
|
import {DecimalMath} from "../lib/DecimalMath.sol";
|
2021-02-03 00:05:45 +08:00
|
|
|
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
2021-02-01 11:58:01 +08:00
|
|
|
|
|
|
|
|
|
2021-02-03 00:05:45 +08:00
|
|
|
contract DODOCirculationHelper is InitializableOwnable {
|
2021-02-01 11:58:01 +08:00
|
|
|
using SafeMath for uint256;
|
|
|
|
|
|
|
|
|
|
// ============ Storage ============
|
|
|
|
|
|
2021-02-03 00:05:45 +08:00
|
|
|
address immutable _VDODO_TOKEN_;
|
2021-02-01 11:58:01 +08:00
|
|
|
address immutable _DODO_TOKEN_;
|
|
|
|
|
address[] _LOCKED_CONTRACT_ADDRESS_;
|
|
|
|
|
|
2021-02-01 13:31:03 +08:00
|
|
|
uint256 public _MIN_PENALTY_RATIO_ = 5 * 10**16; // 5%
|
2021-02-01 11:58:01 +08:00
|
|
|
uint256 public _MAX_PENALTY_RATIO_ = 15 * 10**16; // 15%
|
|
|
|
|
|
2021-02-03 00:05:45 +08:00
|
|
|
constructor(address vDodoToken,address dodoToken) public {
|
|
|
|
|
_VDODO_TOKEN_ = vDodoToken;
|
2021-02-01 13:31:03 +08:00
|
|
|
_DODO_TOKEN_ = dodoToken;
|
2021-02-03 00:05:45 +08:00
|
|
|
}
|
2021-02-01 13:31:03 +08:00
|
|
|
|
2021-02-04 15:32:05 +08:00
|
|
|
function addLockedContractAddress(address lockedContract) external onlyOwner {
|
|
|
|
|
require(lockedContract != address(0));
|
|
|
|
|
_LOCKED_CONTRACT_ADDRESS_.push(lockedContract);
|
|
|
|
|
}
|
2021-02-01 13:31:03 +08:00
|
|
|
|
2021-02-04 15:32:05 +08:00
|
|
|
function removeLockedContractAddress(address lockedContract) external onlyOwner {
|
|
|
|
|
require(lockedContract != address(0));
|
|
|
|
|
address[] memory lockedContractAddress = _LOCKED_CONTRACT_ADDRESS_;
|
|
|
|
|
for (uint256 i = 0; i < lockedContractAddress.length; i++) {
|
|
|
|
|
if (lockedContractAddress[i] == lockedContract) {
|
|
|
|
|
lockedContractAddress[i] = lockedContractAddress[lockedContractAddress.length - 1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_LOCKED_CONTRACT_ADDRESS_ = lockedContractAddress;
|
|
|
|
|
_LOCKED_CONTRACT_ADDRESS_.pop();
|
|
|
|
|
}
|
2021-02-01 13:31:03 +08:00
|
|
|
|
|
|
|
|
function getCirculation() public view returns (uint256 circulation) {
|
2021-02-19 17:37:46 +08:00
|
|
|
circulation = 10**9 * 10**18;
|
2021-02-01 13:31:03 +08:00
|
|
|
for (uint256 i = 0; i < _LOCKED_CONTRACT_ADDRESS_.length; i++) {
|
|
|
|
|
circulation -= IERC20(_DODO_TOKEN_).balanceOf(_LOCKED_CONTRACT_ADDRESS_[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-06 18:11:07 +08:00
|
|
|
function getDodoWithdrawFeeRatio() external view returns (uint256 ratio) {
|
2021-02-01 13:31:03 +08:00
|
|
|
uint256 dodoCirculationAmout = getCirculation();
|
2021-02-01 11:58:01 +08:00
|
|
|
uint256 x =
|
|
|
|
|
DecimalMath.divCeil(
|
2021-02-09 18:56:35 +08:00
|
|
|
IERC20(_VDODO_TOKEN_).totalSupply() * 100,
|
|
|
|
|
dodoCirculationAmout
|
2021-02-01 11:58:01 +08:00
|
|
|
);
|
2021-02-03 15:28:49 +08:00
|
|
|
|
|
|
|
|
ratio = geRatioValue(x);
|
|
|
|
|
}
|
2021-02-03 18:56:01 +08:00
|
|
|
|
2021-02-09 18:56:35 +08:00
|
|
|
function geRatioValue(uint256 input) public view returns (uint256) {
|
2021-02-03 18:56:01 +08:00
|
|
|
|
2021-02-09 18:56:35 +08:00
|
|
|
// y = 15% (x < 0.1)
|
|
|
|
|
// y = 5% (x > 0.5)
|
|
|
|
|
// y = 0.175 - 0.25 * x
|
2021-02-03 18:56:01 +08:00
|
|
|
|
2021-02-09 18:56:35 +08:00
|
|
|
if (input < 10**17) {
|
2021-02-01 11:58:01 +08:00
|
|
|
return _MAX_PENALTY_RATIO_;
|
2021-02-09 18:56:35 +08:00
|
|
|
} else if (input > 5 * 10**17) {
|
|
|
|
|
return _MIN_PENALTY_RATIO_;
|
2021-02-01 11:58:01 +08:00
|
|
|
} else {
|
2021-02-09 18:56:35 +08:00
|
|
|
return 175 * 10**15 - DecimalMath.mulFloor(input, 25 * 10**16);
|
2021-02-01 11:58:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|