From 3163f10cbd224013d28d91d847c52b87c3057c12 Mon Sep 17 00:00:00 2001 From: owen05 Date: Wed, 3 Feb 2021 18:56:01 +0800 Subject: [PATCH] add bsc migration --- contracts/DODOToken/DODOBscToken.sol | 95 +++++++++++++++++++ contracts/DODOToken/DODOCirculationHelper.sol | 13 ++- contracts/DODOToken/DODOMigrationBSC.sol | 38 +++++--- contracts/DODOToken/Governance.sol | 7 +- 4 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 contracts/DODOToken/DODOBscToken.sol diff --git a/contracts/DODOToken/DODOBscToken.sol b/contracts/DODOToken/DODOBscToken.sol new file mode 100644 index 0000000..8aeb597 --- /dev/null +++ b/contracts/DODOToken/DODOBscToken.sol @@ -0,0 +1,95 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; + +import {SafeMath} from "../lib/SafeMath.sol"; +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; + +/** + * @title DODO Token Mapped on BSC + * @author DODO Breeder + */ +contract DODOBscToken is InitializableOwnable { + using SafeMath for uint256; + + string public name = "DODO bird"; + uint256 public decimals = 18; + string public symbol = "DODO"; + uint256 public totalSupply; + + mapping(address => uint256) balances; + mapping(address => mapping(address => uint256)) internal allowed; + + + event Transfer(address indexed from, address indexed to, uint256 amount); + event Approval(address indexed owner, address indexed spender, uint256 amount); + event Mint(address indexed user, uint256 value); + event Burn(address indexed user, uint256 value); + event Redeem(address indexed sender, address indexed redeemToEthAccount, uint256 value); + + function transfer(address to, uint256 amount) public returns (bool) { + require(to != address(0), "TO_ADDRESS_IS_EMPTY"); + require(amount <= balances[msg.sender], "BALANCE_NOT_ENOUGH"); + + balances[msg.sender] = balances[msg.sender].sub(amount); + balances[to] = balances[to].add(amount); + emit Transfer(msg.sender, to, amount); + return true; + } + + function balanceOf(address owner) public view returns (uint256 balance) { + return balances[owner]; + } + + function transferFrom( + address from, + address to, + uint256 amount + ) public returns (bool) { + require(to != address(0), "TO_ADDRESS_IS_EMPTY"); + require(amount <= balances[from], "BALANCE_NOT_ENOUGH"); + require(amount <= allowed[from][msg.sender], "ALLOWANCE_NOT_ENOUGH"); + + balances[from] = balances[from].sub(amount); + balances[to] = balances[to].add(amount); + allowed[from][msg.sender] = allowed[from][msg.sender].sub(amount); + emit Transfer(from, to, amount); + return true; + } + + function approve(address spender, uint256 amount) public returns (bool) { + allowed[msg.sender][spender] = amount; + emit Approval(msg.sender, spender, amount); + return true; + } + + function allowance(address owner, address spender) public view returns (uint256) { + return allowed[owner][spender]; + } + + + function redeem(uint256 amount, uint256 value, address redeemToEthAccount) external { + balances[msg.sender] = balances[msg.sender].sub(value); + totalSupply = totalSupply.sub(value); + emit Redeem(msg.sender, redeemToEthAccount, value); + } + + function mint(address user, uint256 value) external onlyOwner { + balances[user] = balances[user].add(value); + totalSupply = totalSupply.add(value); + emit Mint(user, value); + emit Transfer(address(0), user, value); + } + + function burn(address user, uint256 value) external onlyOwner { + balances[user] = balances[user].sub(value); + totalSupply = totalSupply.sub(value); + emit Burn(user, value); + emit Transfer(user, address(0), value); + } +} diff --git a/contracts/DODOToken/DODOCirculationHelper.sol b/contracts/DODOToken/DODOCirculationHelper.sol index daac59d..1601925 100644 --- a/contracts/DODOToken/DODOCirculationHelper.sol +++ b/contracts/DODOToken/DODOCirculationHelper.sol @@ -13,7 +13,7 @@ import {DecimalMath} from "../lib/DecimalMath.sol"; import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; interface IDODOCirculationHelper { - // vDODO 锁仓不算流通 + // Locked vDOOD not counted in circulation function getCirculation() external returns (uint256); function getVDODOWithdrawFeeRatio() external returns (uint256); @@ -49,10 +49,6 @@ contract DODOCirculationHelper is InitializableOwnable { 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, @@ -61,7 +57,14 @@ contract DODOCirculationHelper is InitializableOwnable { ratio = geRatioValue(x); } + function geRatioValue(uint256 input) public view returns (uint256 ratio) { + + // (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) + if (input <= 10**18) { return _MIN_PENALTY_RATIO_; } else if (input >= 10**19) { diff --git a/contracts/DODOToken/DODOMigrationBSC.sol b/contracts/DODOToken/DODOMigrationBSC.sol index b0635e5..90b26f2 100644 --- a/contracts/DODOToken/DODOMigrationBSC.sol +++ b/contracts/DODOToken/DODOMigrationBSC.sol @@ -9,42 +9,50 @@ pragma experimental ABIEncoderV2; import {IERC20} from "../intf/IERC20.sol"; import {SafeMath} from "../lib/SafeMath.sol"; -import {Ownable} from "../lib/Ownable.sol"; +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; +import {IDODOApproveProxy} from "../SmartRoute/DODOApproveProxy.sol"; -contract DODOMigrationBSC is Ownable { +/** + * @title DODOMigration between Ethereum and BSC + * @author DODO Breeder + */ +contract DODOMigrationBSC is InitializableOwnable { using SafeMath for uint256; // ============ Storage ============ - address immutable _ETH_DODO_TOKEN_ = 0x43Dfc4159D86F3A37A5A4B3D4580b888ad7d4DDd; - address immutable _BSC_DODO_TOKEN_ = 0xa6E37b1d3690C8E608Bb11AFE193fA7C88141643; + address immutable _ETH_DODO_TOKEN_; + address immutable _DODO_APPROVE_PROXY_; mapping(address => uint256) internal balances; - bool immutable _IS_ETH_NETWORK_; - - constructor(bool isETHNetwork) public { - _IS_ETH_NETWORK_ = isETHNetwork; + constructor(address ethDodoToken, address dodoApproveProxy) public { + _ETH_DODO_TOKEN_ = ethDodoToken; + _DODO_APPROVE_PROXY_ = dodoApproveProxy; } // ============ Events ============ - event Lock(address indexed sender, address indexed mintTo, uint256 amount); + event Lock(address indexed sender, address indexed mintToBscAccount, uint256 amount); event Unlock(address indexed to, uint256 amount); // ============ Functions ============ - function lock(uint256 amount, address mintTo) external { - address dodoToken = _IS_ETH_NETWORK_ ? _ETH_DODO_TOKEN_ : _BSC_DODO_TOKEN_; - IERC20(dodoToken).transferFrom(msg.sender, address(this), amount); + function lock(uint256 amount, address mintToBscAccount) external { + IDODOApproveProxy(_DODO_APPROVE_PROXY_).claimTokens( + _ETH_DODO_TOKEN_, + msg.sender, + address(this), + amount + ); balances[msg.sender] = balances[msg.sender].add(amount); - emit Lock(msg.sender, mintTo, amount); + emit Lock(msg.sender, mintToBscAccount, amount); } function unlock(address unlockTo, uint256 amount) external onlyOwner { - address dodoToken = _IS_ETH_NETWORK_ ? _ETH_DODO_TOKEN_ : _BSC_DODO_TOKEN_; require(balances[unlockTo] >= amount); balances[unlockTo] = balances[unlockTo].sub(amount); - IERC20(dodoToken).transfer(unlockTo, amount); + IERC20(_ETH_DODO_TOKEN_).transfer(unlockTo, amount); emit Unlock(unlockTo, amount); } + } diff --git a/contracts/DODOToken/Governance.sol b/contracts/DODOToken/Governance.sol index ca0cbb5..37a1657 100644 --- a/contracts/DODOToken/Governance.sol +++ b/contracts/DODOToken/Governance.sol @@ -9,17 +9,18 @@ pragma experimental ABIEncoderV2; import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; +//todo contract Governance is InitializableOwnable { // ============ Storage ============ - address _DODO_TOKEN_; + address _VDODO_TOKEN_; function setVDODOAddress(address vodoToken) public onlyOwner{ - _DODO_TOKEN_ = vodoToken; + _VDODO_TOKEN_ = vodoToken; } function getLockedvDODO(address account) external pure returns (uint256 lockedvDODO) { - lockedvDODO = 0;//DOTO,0 for test + lockedvDODO = 0;//todo for test } }