From 67067f73c7b633b51019c543bc9b55296b8ad69c Mon Sep 17 00:00:00 2001 From: owen05 Date: Fri, 18 Dec 2020 21:33:40 +0800 Subject: [PATCH] Compatible with rebase token --- contracts/DODOPrivatePool/impl/DPPAdmin.sol | 6 ++++++ contracts/DODOPrivatePool/impl/DPPVault.sol | 13 +++++++++++++ contracts/DODOPrivatePool/intf/IDPP.sol | 2 ++ contracts/DODOVendingMachine/impl/DVMVault.sol | 5 +++++ 4 files changed, 26 insertions(+) diff --git a/contracts/DODOPrivatePool/impl/DPPAdmin.sol b/contracts/DODOPrivatePool/impl/DPPAdmin.sol index 8ba077b..756a6f1 100644 --- a/contracts/DODOPrivatePool/impl/DPPAdmin.sol +++ b/contracts/DODOPrivatePool/impl/DPPAdmin.sol @@ -36,6 +36,12 @@ contract DPPAdmin is InitializableOwnable { _DODO_APPROVE_ = dodoApprove; } + //For Rebase Token + function sync() external notFreezed onlyOwner { + IDPP(_DPP_).sync(); + } + + function setFreezeTimestamp(uint256 timestamp) external notFreezed onlyOwner { _FREEZE_TIMESTAMP_ = timestamp; } diff --git a/contracts/DODOPrivatePool/impl/DPPVault.sol b/contracts/DODOPrivatePool/impl/DPPVault.sol index 2e2f62f..bb520af 100644 --- a/contracts/DODOPrivatePool/impl/DPPVault.sol +++ b/contracts/DODOPrivatePool/impl/DPPVault.sol @@ -57,6 +57,19 @@ contract DPPVault is DPPStorage { // ============ Set States ============ + function sync() external preventReentrant onlyOwner { + uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this)); + uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this)); + if (baseBalance != _BASE_RESERVE_) { + _BASE_TARGET_ = _BASE_TARGET_.mul(baseBalance).div(_BASE_RESERVE_); + _BASE_RESERVE_ = baseBalance; + } + if (quoteBalance != _QUOTE_RESERVE_) { + _QUOTE_TARGET_ = _QUOTE_TARGET_.mul(quoteBalance).div(_QUOTE_RESERVE_); + _QUOTE_RESERVE_ = quoteBalance; + } + } + function setTarget(uint256 baseTarget, uint256 quoteTarget) public preventReentrant onlyOwner { _BASE_TARGET_ = baseTarget; _QUOTE_TARGET_ = quoteTarget; diff --git a/contracts/DODOPrivatePool/intf/IDPP.sol b/contracts/DODOPrivatePool/intf/IDPP.sol index a5c93d9..df7810c 100644 --- a/contracts/DODOPrivatePool/intf/IDPP.sol +++ b/contracts/DODOPrivatePool/intf/IDPP.sol @@ -45,6 +45,8 @@ interface IDPP { function setSell(bool open) external; + function sync() external; + //============================== function retrieve( diff --git a/contracts/DODOVendingMachine/impl/DVMVault.sol b/contracts/DODOVendingMachine/impl/DVMVault.sol index 5157c85..4d1d66e 100644 --- a/contracts/DODOVendingMachine/impl/DVMVault.sol +++ b/contracts/DODOVendingMachine/impl/DVMVault.sol @@ -68,6 +68,11 @@ contract DVMVault is DVMStorage { } } + + function sync() external preventReentrant { + _sync(); + } + // ============ Asset Out ============ function _transferBaseOut(address to, uint256 amount) internal {