update vdodo

This commit is contained in:
owen05
2021-02-06 18:11:07 +08:00
parent e4b3b86ebb
commit 749c180627
3 changed files with 37 additions and 46 deletions

View File

@@ -55,7 +55,7 @@ contract DODOCirculationHelper is InitializableOwnable {
}
}
function getVDODOWithdrawFeeRatio() external view returns (uint256 ratio) {
function getDodoWithdrawFeeRatio() external view returns (uint256 ratio) {
uint256 dodoCirculationAmout = getCirculation();
uint256 x =
DecimalMath.divCeil(

View File

@@ -12,15 +12,7 @@ import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
//todo
contract Governance is InitializableOwnable {
// ============ Storage ============
address _VDODO_TOKEN_;
function setVDODOAddress(address vodoToken) public onlyOwner{
_VDODO_TOKEN_ = vodoToken;
}
function getLockedvDODO(address account) external pure returns (uint256 lockedvDODO) {
lockedvDODO = 0;//todo for test
function getLockedDODO(address account) external pure returns (uint256 lockedDODO) {
lockedDODO = 0;//todo for test
}
}

View File

@@ -15,14 +15,14 @@ import {SafeERC20} from "../lib/SafeERC20.sol";
import {IDODOApproveProxy} from "../SmartRoute/DODOApproveProxy.sol";
interface IGovernance {
function getLockedvDODO(address account) external view returns (uint256);
function getLockedDODO(address account) external view returns (uint256);
}
interface IDODOCirculationHelper {
// Locked vDOOD not counted in circulation
function getCirculation() external view returns (uint256);
function getVDODOWithdrawFeeRatio() external view returns (uint256);
function getDodoWithdrawFeeRatio() external view returns (uint256);
}
contract vDODOToken is InitializableOwnable {
@@ -49,10 +49,11 @@ contract vDODOToken is InitializableOwnable {
// staking reward parameters
uint256 public dodoPerBlock;
uint256 public constant _SUPERIOR_RATIO_ = 10**17; // 0.1
uint256 public constant _DODO_RATIO_ = 100 * 10**18; // 100
uint256 public dodoFeeBurnRation;
// accounting
uint128 public alpha = 100 * 10**18; // 100
uint128 public alpha = 10**18; // 1
uint128 public lastRewardBlock;
mapping(address => UserInfo) public userInfo;
@@ -148,7 +149,7 @@ contract vDODOToken is InitializableOwnable {
dodoAmount
);
uint256 newVdodoAmount = DecimalMath.divFloor(dodoAmount, alpha);
uint256 newVdodoAmount = DecimalMath.divFloor(dodoAmount,_DODO_RATIO_);
UserInfo storage user = userInfo[msg.sender];
_mint(user, newVdodoAmount);
@@ -165,13 +166,14 @@ contract vDODOToken is InitializableOwnable {
emit MintVDODO(msg.sender, superiorAddress, dodoAmount);
}
function redeem(uint256 vDodoAmount)
function redeem(uint256 dodoAmount)
public
balanceEnough(msg.sender, vDodoAmount)
balanceEnough(msg.sender, dodoAmount)
{
_updateAlpha();
UserInfo storage user = userInfo[msg.sender];
uint256 vDodoAmount = DecimalMath.divFloor(dodoAmount,_DODO_RATIO_);
_redeem(user, vDodoAmount);
if (user.superior != address(0)) {
@@ -179,7 +181,7 @@ contract vDODOToken is InitializableOwnable {
_redeemFromSuperior(user, superiorRedeemVDODO);
}
(uint256 dodoReceive, uint256 burnDodoAmount, uint256 withdrawFeeDodoAmount) = getWithdrawAmount(vDodoAmount);
(uint256 dodoReceive, uint256 burnDodoAmount, uint256 withdrawFeeDodoAmount) = getWithdrawAmount(dodoAmount);
IERC20(_DODO_TOKEN_).transfer(msg.sender, dodoReceive);
@@ -191,7 +193,7 @@ contract vDODOToken is InitializableOwnable {
alpha = uint128(uint256(alpha).add(DecimalMath.divFloor(withdrawFeeDodoAmount, totalSupply)));
}
emit RedeemVDODO(msg.sender, vDodoAmount);
emit RedeemVDODO(msg.sender, dodoAmount);
}
@@ -207,42 +209,41 @@ contract vDODOToken is InitializableOwnable {
// ============ Functions(ERC20) ============
function balanceOf(address account) public view returns (uint256 balance) {
function balanceOf(address account) public view returns (uint256 dodoAmount) {
UserInfo memory user = userInfo[account];
balance = uint256(user.VDODOAmount).sub(DecimalMath.divFloor(user.credit, getLatestAlpha()));
dodoAmount = DecimalMath.mulFloor(uint256(user.VDODOAmount),_DODO_RATIO_.add(getLatestAlpha())).sub(user.credit);
}
function availableBalanceOf(address account) public view returns (uint256 balance) {
if(_DOOD_GOV_ == address(0)){
balance = balanceOf(account);
}else {
uint256 lockedBalance = IGovernance(_DOOD_GOV_).getLockedvDODO(account);
uint256 lockedBalance = IGovernance(_DOOD_GOV_).getLockedDODO(account);
balance = balanceOf(account).sub(lockedBalance);
}
}
function transfer(address to, uint256 amount) public returns (bool) {
function transfer(address to, uint256 dodoAmount) public returns (bool) {
_updateAlpha();
_transfer(msg.sender, to, amount);
_transfer(msg.sender, to, dodoAmount);
return true;
}
function approve(address spender, uint256 amount) public returns (bool) {
_ALLOWED_[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
function approve(address spender, uint256 dodoAmount) public returns (bool) {
_ALLOWED_[msg.sender][spender] = dodoAmount;
emit Approval(msg.sender, spender, dodoAmount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
uint256 dodoAmount
) public returns (bool) {
require(amount <= _ALLOWED_[from][msg.sender], "ALLOWANCE_NOT_ENOUGH");
require(dodoAmount <= _ALLOWED_[from][msg.sender], "ALLOWANCE_NOT_ENOUGH");
_updateAlpha();
_transfer(from, to, amount);
_ALLOWED_[from][msg.sender] = _ALLOWED_[from][msg.sender].sub(amount);
emit Transfer(from, to, amount);
_transfer(from, to, dodoAmount);
_ALLOWED_[from][msg.sender] = _ALLOWED_[from][msg.sender].sub(dodoAmount);
return true;
}
@@ -252,11 +253,6 @@ contract vDODOToken is InitializableOwnable {
// ============ View Functions ============
function dodoBalanceOf(address account) public view returns (uint256 dodoAmount) {
UserInfo memory user = userInfo[account];
dodoAmount = DecimalMath.mulFloor(uint256(user.VDODOAmount),getLatestAlpha()).sub(user.credit);
}
function getLatestAlpha() public view returns(uint256) {
uint256 accuDODO = dodoPerBlock * (block.number - lastRewardBlock);
if (totalSupply > 0) {
@@ -266,11 +262,12 @@ contract vDODOToken is InitializableOwnable {
}
}
function getWithdrawAmount(uint256 vDodoAmount) public view returns(uint256 dodoReceive, uint256 burnDodoAmount, uint256 withdrawFeeDodoAmount) {
uint256 feeRatio = IDODOCirculationHelper(_DODO_CIRCULATION_HELPER_).getVDODOWithdrawFeeRatio();
function getWithdrawAmount(uint256 dodoAmount) public view returns(uint256 dodoReceive, uint256 burnDodoAmount, uint256 withdrawFeeDodoAmount) {
uint256 vDodoAmount = DecimalMath.divFloor(dodoAmount,_DODO_RATIO_);
uint256 feeRatio = IDODOCirculationHelper(_DODO_CIRCULATION_HELPER_).getDodoWithdrawFeeRatio();
uint256 newAlpha = getLatestAlpha();
uint256 withdrawDodoAmount = DecimalMath.mulFloor(vDodoAmount, newAlpha);
uint256 withdrawDodoAmount = DecimalMath.mulFloor(vDodoAmount, _DODO_RATIO_.add(newAlpha));
withdrawFeeDodoAmount = DecimalMath.mulCeil(withdrawDodoAmount, feeRatio);
dodoReceive = withdrawDodoAmount.sub(withdrawFeeDodoAmount);
@@ -303,7 +300,7 @@ contract vDODOToken is InitializableOwnable {
user.superiorVDODO = uint128(uint256(user.superiorVDODO).add(vdodoAmount));
UserInfo storage superiorUser = userInfo[user.superior];
_mint(superiorUser, vdodoAmount);
uint256 dodoAmount = DecimalMath.mulCeil(vdodoAmount, alpha);
uint256 dodoAmount = DecimalMath.mulCeil(vdodoAmount, _DODO_RATIO_.add(alpha));
superiorUser.credit = superiorUser.credit.add(dodoAmount);
}
}
@@ -319,14 +316,14 @@ contract vDODOToken is InitializableOwnable {
user.superiorVDODO = uint128(uint256(user.superiorVDODO).sub(vdodoAmount));
UserInfo storage superiorUser = userInfo[user.superior];
uint256 creditVDODO = DecimalMath.divFloor(superiorUser.credit, alpha);
uint256 creditVDODO = DecimalMath.divFloor(superiorUser.credit, _DODO_RATIO_.add(alpha));
if (vdodoAmount >= creditVDODO) {
superiorUser.credit = 0;
_redeem(superiorUser, creditVDODO);
} else {
superiorUser.credit = superiorUser.credit.sub(
DecimalMath.mulFloor(vdodoAmount, alpha)
DecimalMath.mulFloor(vdodoAmount, _DODO_RATIO_.add(alpha))
);
_redeem(superiorUser, vdodoAmount);
}
@@ -336,10 +333,12 @@ contract vDODOToken is InitializableOwnable {
function _transfer(
address from,
address to,
uint256 _amount
) internal balanceEnough(from, _amount) canTransfer {
uint256 _dodoAmount
) internal balanceEnough(from, _dodoAmount) canTransfer {
require(from != address(0), "transfer from the zero address");
require(to != address(0), "transfer to the zero address");
uint256 _amount = DecimalMath.divFloor(_dodoAmount,_DODO_RATIO_);
UserInfo storage fromUser = userInfo[from];
fromUser.VDODOAmount = uint128(uint256(fromUser.VDODOAmount).sub(_amount));
@@ -357,6 +356,6 @@ contract vDODOToken is InitializableOwnable {
_mintToSuperior(toUser, superiorRedeemVDODO);
}
emit Transfer(from, to, _amount);
emit Transfer(from, to, _dodoAmount);
}
}