From b698218993b1a6d62d732eb1eca042013d933d37 Mon Sep 17 00:00:00 2001 From: owen05 Date: Tue, 2 Feb 2021 14:35:05 +0800 Subject: [PATCH] update vdodo --- contracts/DODOToken/vDODOToken.sol | 128 +++++++++++++++-------------- deploy-detail-v1.5.txt | 8 ++ deploy-detail-v2.0.txt | 14 ++++ migrations/3_deploy_v2.js | 6 +- truffle-config.js | 2 +- 5 files changed, 91 insertions(+), 67 deletions(-) diff --git a/contracts/DODOToken/vDODOToken.sol b/contracts/DODOToken/vDODOToken.sol index 818ef3c..ce6f437 100644 --- a/contracts/DODOToken/vDODOToken.sol +++ b/contracts/DODOToken/vDODOToken.sol @@ -52,21 +52,21 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { uint256 public dodoFeeBurnRation; // accounting - uint256 public alpha = 100 * 10**18; // 100 - uint256 public lastRewardBlock; + uint128 public alpha = 100 * 10**18; // 100 + uint128 public lastRewardBlock; mapping(address => UserInfo) public userInfo; struct UserInfo { - uint256 VDODOAmount; - uint256 credit; + uint128 VDODOAmount; + uint128 superiorVDODO; address superior; - uint256 superiorVDODO; + uint256 credit; } // ============ Events ============ - event Deposit(address user, address superior, uint256 amount); - event Withdraw(address user, uint256 amount); + event MintVDODO(address user, address superior, uint256 amount); + event RedeemVDODO(address user, uint256 amount); event SetCantransfer(bool allowed); event ChangePerReward(uint256 dodoPerBlock); @@ -94,17 +94,17 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { address dodoToken, address dodoCirculationHelper, address dodoApproveProxy, - string memory name, - string memory symbol + string memory _name, + string memory _symbol ) public { - name = name; - symbol = symbol; + name = _name; + symbol = _symbol; decimals = 18; _DODO_APPROVE_PROXY_ = dodoApproveProxy; _DOOD_GOV_ = dodoGov; _DODO_CIRCULATION_HELPER_ = dodoCirculationHelper; _DODO_TOKEN_ = dodoToken; - lastRewardBlock = block.number; + lastRewardBlock = uint128(block.number); } // ============ Ownable Functions ============` @@ -114,58 +114,54 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { emit SetCantransfer(allowed); } - function changePerReward(uint256 dodoPerBlock) public onlyOwner { - _updateAlpha(getLatestAlpha()); - dodoPerBlock = dodoPerBlock; - emit ChangePerReward(dodoPerBlock); + function changePerReward(uint256 _dodoPerBlock) public onlyOwner { + _updateAlpha(); + dodoPerBlock = _dodoPerBlock; + emit ChangePerReward(_dodoPerBlock); } - function updatedodoFeeBurnRation(uint256 dodoFeeBurnRation) public onlyOwner { - dodoFeeBurnRation = dodoFeeBurnRation; - emit UpdatedodoFeeBurnRation(dodoFeeBurnRation); + function updatedodoFeeBurnRation(uint256 _dodoFeeBurnRation) public onlyOwner { + dodoFeeBurnRation = _dodoFeeBurnRation; + emit UpdatedodoFeeBurnRation(_dodoFeeBurnRation); } function updateDODOCirculationHelper(address helper) public onlyOwner { _DODO_CIRCULATION_HELPER_ = helper; } - function updateGovernance(address _governance) public onlyOwner { - _DOOD_GOV_ = _governance; + function updateGovernance(address governance) public onlyOwner { + _DOOD_GOV_ = governance; } // ============ Functions ============ function mint(uint256 dodoAmount, address superiorAddress) public preventReentrant { + require(superiorAddress != address(0) && superiorAddress != msg.sender, "vDODOToken: Superior INVALID"); require(dodoAmount > 0, "vDODOToken: must mint greater than 0"); + + _updateAlpha(); + IDODOApproveProxy(_DODO_APPROVE_PROXY_).claimTokens( _DODO_TOKEN_, msg.sender, address(this), dodoAmount ); - uint256 newAlpha = getLatestAlpha(); - uint256 newVdodoAmount = DecimalMath.divFloor(dodoAmount, newAlpha); + uint256 newVdodoAmount = DecimalMath.divFloor(dodoAmount, alpha); UserInfo storage user = userInfo[msg.sender]; _mint(user, newVdodoAmount); - uint256 superiorVDODO; - if (user.superior == address(0) && superiorAddress != address(0)) { - require(superiorAddress != msg.sender, "COULD NOT SET SELF AS SUPERIOR"); - superiorVDODO = DecimalMath.mulFloor(user.VDODOAmount, _SUPERIOR_RATIO_); - user.superior = superiorAddress; - } else if (user.superior != address(0)) { - superiorVDODO = DecimalMath.mulFloor(newVdodoAmount, _SUPERIOR_RATIO_); - } - - if (user.superior != address(0)) { - _mintToSuperior(user, superiorVDODO); - } + uint256 increSuperiorVDODO = DecimalMath.mulFloor(newVdodoAmount, _SUPERIOR_RATIO_); - _updateAlpha(newAlpha); + if (user.superior == address(0)) { + user.superior = superiorAddress; + } - emit Deposit(msg.sender, superiorAddress, dodoAmount); + _mintToSuperior(user, increSuperiorVDODO); + + emit MintVDODO(msg.sender, superiorAddress, dodoAmount); } function redeem(uint256 vDodoAmount) @@ -173,7 +169,7 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { preventReentrant balanceEnough(msg.sender, vDodoAmount) { - uint256 newAlpha = getLatestAlpha(); + _updateAlpha(); UserInfo storage user = userInfo[msg.sender]; _redeem(user, vDodoAmount); @@ -185,15 +181,20 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { (uint256 dodoReceive, uint256 burnDodoAmount, uint256 withdrawFeeDodoAmount) = getWithdrawAmount(vDodoAmount); - IERC20(_DODO_TOKEN_).transfer(msg.sender, dodoReceive); - _transfer(address(this), address(0), burnDodoAmount); + IERC20(_DODO_TOKEN_).transfer(msg.sender, dodoReceive); - newAlpha = newAlpha.add(DecimalMath.divFloor(withdrawFeeDodoAmount, totalSupply)); - _updateAlpha(newAlpha); + if(burnDodoAmount > 0){ + _transfer(address(this), address(0), burnDodoAmount); + } - emit Withdraw(msg.sender, vDodoAmount); + if(withdrawFeeDodoAmount > 0) { + alpha = uint128(uint256(alpha).add(DecimalMath.divFloor(withdrawFeeDodoAmount, totalSupply))); + } + + emit RedeemVDODO(msg.sender, vDodoAmount); } + function donate(uint256 dodoAmount) public { IDODOApproveProxy(_DODO_APPROVE_PROXY_).claimTokens( _DODO_TOKEN_, @@ -201,14 +202,14 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { address(this), dodoAmount ); - alpha = alpha.add(DecimalMath.divFloor(dodoAmount, totalSupply)); + alpha = uint128(uint256(alpha).add(DecimalMath.divFloor(dodoAmount, totalSupply))); } // ============ Functions(ERC20) ============ function balanceOf(address account) public view returns (uint256 balance) { UserInfo memory user = userInfo[account]; - balance = user.VDODOAmount.sub(DecimalMath.divFloor(user.credit, getLatestAlpha())); + balance = uint256(user.VDODOAmount).sub(DecimalMath.divFloor(user.credit, getLatestAlpha())); } function availableBalanceOf(address account) public view returns (uint256 balance) { @@ -217,6 +218,7 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { } function transfer(address to, uint256 amount) public returns (bool) { + _updateAlpha(); _transfer(msg.sender, to, amount); return true; } @@ -233,6 +235,7 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { uint256 amount ) public returns (bool) { require(amount <= _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); @@ -247,13 +250,13 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { function canWithdraw(address account) public view returns (uint256 dodoAmount) { UserInfo memory user = userInfo[account]; - dodoAmount = DecimalMath.mulFloor(user.VDODOAmount,getLatestAlpha()).sub(user.credit); + dodoAmount = DecimalMath.mulFloor(uint256(user.VDODOAmount),getLatestAlpha()).sub(user.credit); } function getLatestAlpha() public view returns(uint256) { uint256 accuDODO = dodoPerBlock * (block.number.sub(lastRewardBlock)); if (totalSupply > 0) { - return alpha.add(DecimalMath.divFloor(accuDODO, totalSupply)); + return uint256(alpha).add(DecimalMath.divFloor(accuDODO, totalSupply)); } else { return alpha; } @@ -278,49 +281,48 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { // ============ Internal Functions ============ - function _updateAlpha(uint256 newAlpha) internal { - alpha = newAlpha; - lastRewardBlock = block.number; + function _updateAlpha() internal { + uint256 newAlpha = getLatestAlpha(); + require(newAlpha <= uint128(-1), "OVERFLOW"); + alpha = uint128(newAlpha); + lastRewardBlock = uint128(block.number); } function _mint(UserInfo storage to, uint256 vdodoAmount) internal { - to.VDODOAmount = to.VDODOAmount.add(vdodoAmount); + require(vdodoAmount <= uint128(-1), "OVERFLOW"); + to.VDODOAmount = uint128(uint256(to.VDODOAmount).add(vdodoAmount)); totalSupply = totalSupply.add(vdodoAmount); } function _mintToSuperior(UserInfo storage user, uint256 vdodoAmount) internal { if (vdodoAmount > 0) { - uint256 newAlpha = getLatestAlpha(); - - user.superiorVDODO = user.superiorVDODO.add(vdodoAmount); + user.superiorVDODO = uint128(uint256(user.superiorVDODO).add(vdodoAmount)); UserInfo storage superiorUser = userInfo[user.superior]; _mint(superiorUser, vdodoAmount); - uint256 dodoAmount = DecimalMath.mulFloor(vdodoAmount, newAlpha); + uint256 dodoAmount = DecimalMath.mulFloor(vdodoAmount, alpha); superiorUser.credit = superiorUser.credit.add(DecimalMath.mulFloor(dodoAmount, _SUPERIOR_RATIO_)); } } function _redeem(UserInfo storage from, uint256 vdodoAmount) internal { - from.VDODOAmount = from.VDODOAmount.sub(vdodoAmount); + from.VDODOAmount = uint128(uint256(from.VDODOAmount).sub(vdodoAmount)); totalSupply = totalSupply.sub(vdodoAmount); } function _redeemFromSuperior(UserInfo storage user, uint256 vdodoAmount) internal { if (vdodoAmount > 0) { - uint256 newAlpha = getLatestAlpha(); - vdodoAmount = user.superiorVDODO <= vdodoAmount ? user.superiorVDODO : vdodoAmount; - user.superiorVDODO = user.superiorVDODO.sub(vdodoAmount); + user.superiorVDODO = uint128(uint256(user.superiorVDODO).sub(vdodoAmount)); UserInfo storage superiorUser = userInfo[user.superior]; - uint256 creditVDODO = DecimalMath.divFloor(superiorUser.credit, newAlpha); + uint256 creditVDODO = DecimalMath.divFloor(superiorUser.credit, alpha); if (vdodoAmount >= creditVDODO) { superiorUser.credit = 0; _redeem(superiorUser, creditVDODO); } else { superiorUser.credit = superiorUser.credit.sub( - DecimalMath.mulFloor(vdodoAmount, newAlpha) + DecimalMath.mulFloor(vdodoAmount, alpha) ); _redeem(superiorUser, vdodoAmount); } @@ -336,10 +338,10 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { require(to != address(0), "transfer to the zero address"); UserInfo storage fromUser = userInfo[from]; - fromUser.VDODOAmount = fromUser.VDODOAmount.sub(_amount); + fromUser.VDODOAmount = uint128(uint256(fromUser.VDODOAmount).sub(_amount)); UserInfo storage toUser = userInfo[to]; - toUser.VDODOAmount = toUser.VDODOAmount.add(_amount); + toUser.VDODOAmount = uint128(uint256(toUser.VDODOAmount).add(_amount)); uint256 superiorRedeemVDODO = DecimalMath.mulFloor(_amount, _SUPERIOR_RATIO_); diff --git a/deploy-detail-v1.5.txt b/deploy-detail-v1.5.txt index 10ef18c..488512c 100644 --- a/deploy-detail-v1.5.txt +++ b/deploy-detail-v1.5.txt @@ -112,3 +112,11 @@ Deploy time: 2021/1/26 下午5:41:41 Deploy type: Proxy DODOV1Proxy04 Address: 0xa2CB66EBB947D217f61510882096F6e95c1DE97D Set DODOProxy Owner tx: 0xe49234c67bc710a7f4797aacbb2ef26fac458832f101e856d8113cc21721cd81 +==================================================== +network type: kovan +Deploy time: 2021/2/1 下午11:07:47 +Deploy type: Proxy +==================================================== +network type: kovan +Deploy time: 2021/2/1 下午11:08:57 +Deploy type: Proxy diff --git a/deploy-detail-v2.0.txt b/deploy-detail-v2.0.txt index 83b513d..eefcc3e 100644 --- a/deploy-detail-v2.0.txt +++ b/deploy-detail-v2.0.txt @@ -542,3 +542,17 @@ Deploy time: 2021/1/26 下午5:29:51 ==================================================== network type: live Deploy time: 2021/1/26 下午5:42:23 +==================================================== +network type: kovan +Deploy time: 2021/2/1 下午11:09:38 +Deploy type: V2 +DODOApprove Address: 0x929ce7b28aA759a1C0E6e855ff2545f9e5ca846A +DODOApproveProxy Address: 0x8a61c59e2DE32af51A252d754c7f852aA44191C8 +DODOV2Proxy02 Address: 0xf47BEA4D26026810787b56670502E058CEe5c386 +Init DODOProxyV2 Tx: 0x48c4de1d6008c96d82a92da63747385b218b56fe3451d4256b9b8429623d34f4 +DODOApproveProxy Init tx: 0xb12443d847d426fbeed3c0c3d0e796d52b214ebff65ca604a72dd7400b94e42c +DODOApprove Init tx: 0x26d3f4be069eccf94b0b6d3ee1db07a534cadc98c4dd2b96fd5921d00f57403c +DODOIncentive ChangeProxy tx: 0x9564307e19b26aed9980d9ac007dc88b789450893540426618de4f1039f5584f +==================================================== +network type: kovan +Deploy time: 2021/2/2 下午2:28:36 diff --git a/migrations/3_deploy_v2.js b/migrations/3_deploy_v2.js index 0013aef..946a977 100644 --- a/migrations/3_deploy_v2.js +++ b/migrations/3_deploy_v2.js @@ -85,7 +85,7 @@ module.exports = async (deployer, network, accounts) => { DefaultPermissionAddress = "0xACc7E23368261e1E02103c4e5ae672E7D01f5797"; DvmTemplateAddress = "0xA6384D1501842e9907D43148E2ca0d50E4ad56E2"; - DppTemplateAddress = "0x044b48D64E77Ab8854C46c8456dC05C540c9dd53"; + DppTemplateAddress = ""; DppAdminTemplateAddress = ""; CpTemplateAddress = "0x81c802080c3CE0dE98fcb625670A14Eb8440184a"; //Factory @@ -379,8 +379,8 @@ module.exports = async (deployer, network, accounts) => { logger.log("DODOIncentive ChangeProxy tx: ", tx.tx); //3. Open trade incentive - var tx = await DODOIncentiveInstance.changePerReward("10000000000000000000"); - logger.log("DODOIncentive OpenSwitch tx: ", tx.tx); + // var tx = await DODOIncentiveInstance.changePerReward("10000000000000000000"); + // logger.log("DODOIncentive OpenSwitch tx: ", tx.tx); //4. Transfer DODO to Trade Incentive } diff --git a/truffle-config.js b/truffle-config.js index 5559589..e2ad8f4 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -38,7 +38,7 @@ module.exports = { * $ truffle test --network */ deploySwitch: { - DEPLOY_V1: true, + DEPLOY_V1: false, DEPLOY_V2: false, ADAPTER: false, MOCK_TOKEN: false,