From d1d815b6f48f91c8df2b300aa9b127de3beec8c3 Mon Sep 17 00:00:00 2001 From: owen05 Date: Mon, 1 Mar 2021 21:13:33 +0800 Subject: [PATCH] add advanced dpp --- contracts/DODOPrivatePool/impl/DPP.sol | 2 +- .../DODOPrivatePool/impl/DPPAdvanced.sol | 63 ++++++++ .../DODOPrivatePool/impl/DPPAdvancedAmin.sol | 143 ++++++++++++++++++ contracts/DODOPrivatePool/intf/IDPP.sol | 15 ++ 4 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 contracts/DODOPrivatePool/impl/DPPAdvanced.sol create mode 100644 contracts/DODOPrivatePool/impl/DPPAdvancedAmin.sol diff --git a/contracts/DODOPrivatePool/impl/DPP.sol b/contracts/DODOPrivatePool/impl/DPP.sol index 8adfc3a..594adcb 100644 --- a/contracts/DODOPrivatePool/impl/DPP.sol +++ b/contracts/DODOPrivatePool/impl/DPP.sol @@ -54,7 +54,7 @@ contract DPP is DPPTrader { // ============ Version Control ============ - function version() external pure returns (string memory) { + function version() virtual external pure returns (string memory) { return "DPP 1.0.0"; } } diff --git a/contracts/DODOPrivatePool/impl/DPPAdvanced.sol b/contracts/DODOPrivatePool/impl/DPPAdvanced.sol new file mode 100644 index 0000000..2f4aaf8 --- /dev/null +++ b/contracts/DODOPrivatePool/impl/DPPAdvanced.sol @@ -0,0 +1,63 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; +pragma experimental ABIEncoderV2; + +import {DPP} from "./DPP.sol"; + +/** + * @title DODO PrivatePool + * @author DODO Breeder + * + * @notice Advanced DODOPrivatePool + */ +contract DPPAdvanced is DPP { + + function tuneParameters( + uint256 newLpFeeRate, + uint256 newI, + uint256 newK, + uint256 minBaseReserve, + uint256 minQuoteReserve + ) public preventReentrant onlyOwner returns (bool) { + require( + _BASE_RESERVE_ >= minBaseReserve && _QUOTE_RESERVE_ >= minQuoteReserve, + "RESERVE_AMOUNT_IS_NOT_ENOUGH" + ); + require(newLpFeeRate <= 1e18, "LP_FEE_RATE_OUT_OF_RANGE"); + require(newK <= 1e18, "K_OUT_OF_RANGE"); + require(newI > 0 && newI <= 1e36, "I_OUT_OF_RANGE"); + _LP_FEE_RATE_ = uint64(newLpFeeRate); + _K_ = uint64(newK); + _I_ = uint128(newI); + emit LpFeeRateChange(newLpFeeRate); + return true; + } + + + function tunePrice( + uint256 newI, + uint256 minBaseReserve, + uint256 minQuoteReserve + ) public preventReentrant onlyOwner returns (bool) { + require( + _BASE_RESERVE_ >= minBaseReserve && _QUOTE_RESERVE_ >= minQuoteReserve, + "RESERVE_AMOUNT_IS_NOT_ENOUGH" + ); + require(newI > 0 && newI <= 1e36, "I_OUT_OF_RANGE"); + _I_ = uint128(newI); + return true; + } + + + // ============ Version Control ============ + + function version() override external pure returns (string memory) { + return "DPP Advanced 1.0.0"; + } +} diff --git a/contracts/DODOPrivatePool/impl/DPPAdvancedAmin.sol b/contracts/DODOPrivatePool/impl/DPPAdvancedAmin.sol new file mode 100644 index 0000000..31e3ddf --- /dev/null +++ b/contracts/DODOPrivatePool/impl/DPPAdvancedAmin.sol @@ -0,0 +1,143 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; +pragma experimental ABIEncoderV2; + +import {IDPP} from "../intf/IDPP.sol"; +import {IDODOApproveProxy} from "../../SmartRoute/DODOApproveProxy.sol"; +import {InitializableOwnable} from "../../lib/InitializableOwnable.sol"; + +/** + * @title DPPAdmin + * @author DODO Breeder + * + * @notice Admin of Advanced DODOPrivatePool + */ +contract DPPAdvancedAdmin is InitializableOwnable { + address public _DPP_; + address public _OPERATOR_; + address public _DODO_APPROVE_PROXY_; + uint256 public _FREEZE_TIMESTAMP_; + + + modifier notFreezed() { + require(block.timestamp >= _FREEZE_TIMESTAMP_, "ADMIN_FREEZED"); + _; + } + + function init( + address owner, + address dpp, + address operator, + address dodoApproveProxy + ) external { + initOwner(owner); + _DPP_ = dpp; + _OPERATOR_ = operator; + _DODO_APPROVE_PROXY_ = dodoApproveProxy; + } + + function sync() external notFreezed onlyOwner { + IDPP(_DPP_).ratioSync(); + } + + function setFreezeTimestamp(uint256 timestamp) external notFreezed onlyOwner { + _FREEZE_TIMESTAMP_ = timestamp; + } + + function setOperator(address newOperator) external notFreezed onlyOwner { + _OPERATOR_ = newOperator; + } + + function retrieve( + address payable to, + address token, + uint256 amount + ) external notFreezed onlyOwner { + IDPP(_DPP_).retrieve(to, token, amount); + } + + function tuneParameters( + address operator, + uint256 newLpFeeRate, + uint256 newI, + uint256 newK, + uint256 minBaseReserve, + uint256 minQuoteReserve + ) external notFreezed returns (bool) { + require( + msg.sender == _OWNER_ || + (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender) && + operator == _OPERATOR_), + "TUNEPARAMS FORBIDDEN!" + ); + return + IDPP(_DPP_).tuneParameters( + newLpFeeRate, + newI, + newK, + minBaseReserve, + minQuoteReserve + ); + } + + function tunePrice( + address operator, + uint256 newI, + uint256 minBaseReserve, + uint256 minQuoteReserve + ) external notFreezed returns (bool) { + require( + msg.sender == _OWNER_ || + (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender) && + operator == _OPERATOR_), + "TUNEPRICE FORBIDDEN!" + ); + return + IDPP(_DPP_).tunePrice( + newI, + minBaseReserve, + minQuoteReserve + ); + } + + function reset( + address operator, + uint256 newLpFeeRate, + uint256 newI, + uint256 newK, + uint256 baseOutAmount, + uint256 quoteOutAmount, + uint256 minBaseReserve, + uint256 minQuoteReserve + ) external notFreezed returns (bool) { + require( + msg.sender == _OWNER_ || + (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender) && + operator == _OPERATOR_), + "RESET FORBIDDEN!" + ); + return + IDPP(_DPP_).reset( + msg.sender, + newLpFeeRate, + newI, + newK, + baseOutAmount, + quoteOutAmount, + minBaseReserve, + minQuoteReserve + ); + } + + // ============ Admin Version Control ============ + + function version() external pure returns (string memory) { + return "DPPAdvanced Admin 1.0.0"; // 1.0.0 + } +} diff --git a/contracts/DODOPrivatePool/intf/IDPP.sol b/contracts/DODOPrivatePool/intf/IDPP.sol index ee1c7b9..ed04556 100644 --- a/contracts/DODOPrivatePool/intf/IDPP.sol +++ b/contracts/DODOPrivatePool/intf/IDPP.sol @@ -42,4 +42,19 @@ interface IDPP { uint256 minBaseReserve, uint256 minQuoteReserve ) external returns (bool); + + //========== advanced ======== + function tuneParameters( + uint256 newLpFeeRate, + uint256 newI, + uint256 newK, + uint256 minBaseReserve, + uint256 minQuoteReserve + ) external returns (bool); + + function tunePrice( + uint256 newI, + uint256 minBaseReserve, + uint256 minQuoteReserve + ) external returns (bool); }