From eb631f62557974408d849bf357f6033d7c1224a7 Mon Sep 17 00:00:00 2001 From: tracy <25892474+traceurl@users.noreply.github.com> Date: Wed, 22 Jun 2022 14:18:37 +0800 Subject: [PATCH 1/4] update DPPOracle --- .../impl/DPPOracle/DPPOracle.sol | 46 +++++++++++++++++-- .../impl/DPPOracle/DPPOracleAdmin.sol | 44 +++++++++++++++++- .../impl/DPPOracle/DPPStorage.sol | 10 +++- .../impl/DPPOracle/DPPTrader.sol | 14 +++--- .../impl/DPPOracle/DPPVault.sol | 3 ++ .../impl/DPPOracle/OracleAdapter.sol | 42 +++++++++++++++++ contracts/DODOPrivatePool/intf/IDPPOracle.sol | 12 +++++ 7 files changed, 157 insertions(+), 14 deletions(-) create mode 100644 contracts/DODOPrivatePool/impl/DPPOracle/OracleAdapter.sol diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracle.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracle.sol index 086e9dd..adf676e 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracle.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracle.sol @@ -20,6 +20,9 @@ import {DPPTrader} from "./DPPTrader.sol"; */ contract DPPOracle is DPPTrader { + event ToggleOracleStatus(bool isEnabled); + event ChangeOracle(address indexed oracle); + function init( address owner, address maintainer, @@ -28,8 +31,10 @@ contract DPPOracle is DPPTrader { uint256 lpFeeRate, address mtFeeRateModel, uint256 k, - address i, - bool isOpenTWAP + uint256 i, + address o, + bool isOpenTWAP, + bool isOracleEnabled ) external { initOwner(owner); @@ -42,21 +47,36 @@ contract DPPOracle is DPPTrader { require(lpFeeRate <= 1e18, "LP_FEE_RATE_OUT_OF_RANGE"); require(k <= 1e18, "K_OUT_OF_RANGE"); - require(i != address(0), "INVALID_ORACLE"); + require(i > 0 && i <= 1e36, "I_OUT_OF_RANGE"); + require(o != address(0), "INVALID_ORACLE"); _LP_FEE_RATE_ = uint64(lpFeeRate); _K_ = uint64(k); - _I_ = i; + _I_ = uint128(i); + _O_ = o; _IS_OPEN_TWAP_ = isOpenTWAP; + _IS_ORACLE_ENABLED = isOracleEnabled; if(isOpenTWAP) _BLOCK_TIMESTAMP_LAST_ = uint32(block.timestamp % 2**32); _resetTargetAndReserve(); } + function changeOracle(address newOracle) public preventReentrant onlyOwner { + require(newOracle != address(0), "INVALID_ORACLE"); + _O_ = newOracle; + emit ChangeOracle(newOracle); + } + + function toggleOracleStatus(bool enabled) public preventReentrant onlyOwner returns (bool) { + _IS_ORACLE_ENABLED = enabled; + emit ToggleOracleStatus(enabled); + return enabled; + } function tuneParameters( uint256 newLpFeeRate, + uint256 newI, uint256 newK, uint256 minBaseReserve, uint256 minQuoteReserve @@ -67,18 +87,34 @@ contract DPPOracle is DPPTrader { ); 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() external pure returns (string memory) { - return "DPP Oracle 1.0.0"; + return "DPP Oracle 1.1.0"; } } diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol index 94042d9..95aa681 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol @@ -62,9 +62,28 @@ contract DPPOracleAdmin is InitializableOwnable { IDPPOracle(_DPP_).retrieve(to, token, amount); } + function changeOracle(address newOracle) external notFreezed { + require( + msg.sender == _OWNER_ || + (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)), + "CHANGEORACLE FORBIDDEN!" + ); + IDPPOracle(_DPP_).changeOracle(newOracle); + } + + function toggleOracleStatus(bool enabled) external notFreezed { + require( + msg.sender == _OWNER_ || + (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)), + "CHANGEORACLE FORBIDDEN!" + ); + IDPPOracle(_DPP_).toggleOracleStatus(enabled); + } + function tuneParameters( address operator, uint256 newLpFeeRate, + uint256 newI, uint256 newK, uint256 minBaseReserve, uint256 minQuoteReserve @@ -78,16 +97,38 @@ contract DPPOracleAdmin is InitializableOwnable { return IDPPOracle(_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 + IDPPOracle(_DPP_).tunePrice( + newI, + minBaseReserve, + minQuoteReserve + ); + } + function reset( address operator, uint256 newLpFeeRate, + uint256 newI, uint256 newK, uint256 baseOutAmount, uint256 quoteOutAmount, @@ -104,6 +145,7 @@ contract DPPOracleAdmin is InitializableOwnable { IDPPOracle(_DPP_).reset( _OWNER_, //only support asset transfer out to owner newLpFeeRate, + newI, newK, baseOutAmount, quoteOutAmount, @@ -115,6 +157,6 @@ contract DPPOracleAdmin is InitializableOwnable { // ============ Admin Version Control ============ function version() external pure returns (string memory) { - return "DPPOracle Admin 1.0.0"; // 1.0.0 + return "DPPOracle Admin 1.1.0"; } } diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPStorage.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPStorage.sol index 3396579..a04c57d 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPStorage.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPStorage.sol @@ -21,6 +21,7 @@ contract DPPStorage is InitializableOwnable, ReentrancyGuard { using SafeMath for uint256; bool public _IS_OPEN_TWAP_ = false; + bool public _IS_ORACLE_ENABLED = true; // ============ Core Address ============ @@ -45,12 +46,17 @@ contract DPPStorage is InitializableOwnable, ReentrancyGuard { uint64 public _LP_FEE_RATE_; uint64 public _K_; - address public _I_; + uint128 public _I_; + address public _O_; // ============ Helper Functions ============ function getPMMState() public view returns (PMMPricing.PMMState memory state) { - state.i = IOracle(_I_).prices(address(_BASE_TOKEN_)); + if (_IS_ORACLE_ENABLED) { + state.i = IOracle(_O_).prices(address(_BASE_TOKEN_)); + } else { + state.i = _I_; + } state.K = _K_; state.B = _BASE_RESERVE_; state.Q = _QUOTE_RESERVE_; diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPTrader.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPTrader.sol index e379a94..19420a2 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPTrader.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPTrader.sol @@ -38,9 +38,11 @@ contract DPPTrader is DPPVault { event RChange(PMMPricing.RState newRState); - modifier isOraclePriceValid() { - bool isFeasible = IOracle(_I_).isFeasible(address(_BASE_TOKEN_)); - require(isFeasible, "ORACLE_PRICE_INVALID"); + modifier isPriceValid() { + if (_IS_ORACLE_ENABLED) { + bool isFeasible = IOracle(_I_).isFeasible(address(_BASE_TOKEN_)); + require(isFeasible, "ORACLE_PRICE_INVALID"); + } _; } @@ -49,7 +51,7 @@ contract DPPTrader is DPPVault { function sellBase(address to) external preventReentrant - isOraclePriceValid + isPriceValid returns (uint256 receiveQuoteAmount) { uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this)); @@ -85,7 +87,7 @@ contract DPPTrader is DPPVault { function sellQuote(address to) external preventReentrant - isOraclePriceValid + isPriceValid returns (uint256 receiveBaseAmount) { uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this)); @@ -126,7 +128,7 @@ contract DPPTrader is DPPVault { uint256 quoteAmount, address _assetTo, bytes calldata data - ) external isOraclePriceValid preventReentrant { + ) external isPriceValid preventReentrant { address assetTo = _assetTo; _transferBaseOut(assetTo, baseAmount); _transferQuoteOut(assetTo, quoteAmount); diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPVault.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPVault.sol index 78495b9..0fc8c73 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPVault.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPVault.sol @@ -123,6 +123,7 @@ contract DPPVault is DPPStorage { function reset( address assetTo, uint256 newLpFeeRate, + uint256 newI, uint256 newK, uint256 baseOutAmount, uint256 quoteOutAmount, @@ -135,9 +136,11 @@ contract DPPVault is DPPStorage { ); 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); _transferBaseOut(assetTo, baseOutAmount); _transferQuoteOut(assetTo, quoteOutAmount); diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/OracleAdapter.sol b/contracts/DODOPrivatePool/impl/DPPOracle/OracleAdapter.sol new file mode 100644 index 0000000..e222ea9 --- /dev/null +++ b/contracts/DODOPrivatePool/impl/DPPOracle/OracleAdapter.sol @@ -0,0 +1,42 @@ +/* + + Copyright 2021 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; +pragma experimental ABIEncoderV2; + +import {IOracle} from "../../intf/IOracle.sol"; + +interface IWooracle { + function timestamp() external view returns (uint256); + function isFeasible(address base) external view returns (bool); + function getPrice(address base) external view returns (uint256); + function price(address base) external view returns (uint256 priceNow, bool feasible); +} + +contract OracleAdapter is IOracle { + IWooracle oracle; + + constructor(address oracleAddress) public { + oracle = IWooracle(oracleAddress); + } + + function getPrice(address base) external override view returns (uint256 latestPrice,bool isValid,bool isStale,uint256 timestamp) { + latestPrice = oracle.getPrice(base); + isValid = oracle.isFeasible(base); + isStale = !isValid; + timestamp = oracle.timestamp(); + return (latestPrice, isValid, isStale, timestamp); + } + + function prices(address base) external override view returns (uint256) { + return oracle.getPrice(base); + } + + function isFeasible(address base) external override view returns (bool) { + return oracle.isFeasible(base); + } +} \ No newline at end of file diff --git a/contracts/DODOPrivatePool/intf/IDPPOracle.sol b/contracts/DODOPrivatePool/intf/IDPPOracle.sol index fc542b4..4619684 100644 --- a/contracts/DODOPrivatePool/intf/IDPPOracle.sol +++ b/contracts/DODOPrivatePool/intf/IDPPOracle.sol @@ -35,6 +35,7 @@ interface IDPPOracle { function reset( address assetTo, uint256 newLpFeeRate, + uint256 newI, uint256 newK, uint256 baseOutAmount, uint256 quoteOutAmount, @@ -45,8 +46,19 @@ interface IDPPOracle { 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); + + function changeOracle(address newOracle) external; + + function toggleOracleStatus(bool enabled) external; } From 857f7d7fc0aca5379c5eb9392e121bf14eca1a06 Mon Sep 17 00:00:00 2001 From: tracy <25892474+traceurl@users.noreply.github.com> Date: Fri, 24 Jun 2022 21:41:59 +0800 Subject: [PATCH 2/4] enable/disable oracle; remove isPriceValid modifier --- .../impl/DPPOracle/DPPOracle.sol | 17 ++++++++++++----- .../impl/DPPOracle/DPPOracleAdmin.sol | 15 ++++++++++++--- .../impl/DPPOracle/DPPTrader.sol | 11 +---------- .../{OracleAdapter.sol => WooOracleAdapter.sol} | 3 ++- contracts/DODOPrivatePool/intf/IDPPOracle.sol | 4 +++- 5 files changed, 30 insertions(+), 20 deletions(-) rename contracts/DODOPrivatePool/impl/DPPOracle/{OracleAdapter.sol => WooOracleAdapter.sol} (92%) diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracle.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracle.sol index adf676e..f2019af 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracle.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracle.sol @@ -20,7 +20,8 @@ import {DPPTrader} from "./DPPTrader.sol"; */ contract DPPOracle is DPPTrader { - event ToggleOracleStatus(bool isEnabled); + event EnableOracle(); + event DisableOracle(uint256 newI); event ChangeOracle(address indexed oracle); function init( @@ -68,10 +69,16 @@ contract DPPOracle is DPPTrader { emit ChangeOracle(newOracle); } - function toggleOracleStatus(bool enabled) public preventReentrant onlyOwner returns (bool) { - _IS_ORACLE_ENABLED = enabled; - emit ToggleOracleStatus(enabled); - return enabled; + function enableOracle() public preventReentrant onlyOwner { + _IS_ORACLE_ENABLED = true; + emit EnableOracle(); + } + + function disableOracle(uint256 newI) public preventReentrant onlyOwner { + require(newI > 0 && newI <= 1e36, "I_OUT_OF_RANGE"); + _I_ = uint128(newI); + _IS_ORACLE_ENABLED = false; + emit DisableOracle(newI); } function tuneParameters( diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol index 95aa681..147951b 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol @@ -71,13 +71,22 @@ contract DPPOracleAdmin is InitializableOwnable { IDPPOracle(_DPP_).changeOracle(newOracle); } - function toggleOracleStatus(bool enabled) external notFreezed { - require( + function enableOracle() external notFreezed { + require( msg.sender == _OWNER_ || (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)), "CHANGEORACLE FORBIDDEN!" ); - IDPPOracle(_DPP_).toggleOracleStatus(enabled); + IDPPOracle(_DPP_).enableOracle(); + } + + function disableOracle(uint256 newI) external notFreezed { + require( + msg.sender == _OWNER_ || + (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)), + "CHANGEORACLE FORBIDDEN!" + ); + IDPPOracle(_DPP_).disableOracle(newI); } function tuneParameters( diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPTrader.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPTrader.sol index 19420a2..71f0006 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPTrader.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPTrader.sol @@ -38,20 +38,12 @@ contract DPPTrader is DPPVault { event RChange(PMMPricing.RState newRState); - modifier isPriceValid() { - if (_IS_ORACLE_ENABLED) { - bool isFeasible = IOracle(_I_).isFeasible(address(_BASE_TOKEN_)); - require(isFeasible, "ORACLE_PRICE_INVALID"); - } - _; - } // ============ Trade Functions ============ function sellBase(address to) external preventReentrant - isPriceValid returns (uint256 receiveQuoteAmount) { uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this)); @@ -87,7 +79,6 @@ contract DPPTrader is DPPVault { function sellQuote(address to) external preventReentrant - isPriceValid returns (uint256 receiveBaseAmount) { uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this)); @@ -128,7 +119,7 @@ contract DPPTrader is DPPVault { uint256 quoteAmount, address _assetTo, bytes calldata data - ) external isPriceValid preventReentrant { + ) external preventReentrant { address assetTo = _assetTo; _transferBaseOut(assetTo, baseAmount); _transferQuoteOut(assetTo, quoteAmount); diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/OracleAdapter.sol b/contracts/DODOPrivatePool/impl/DPPOracle/WooOracleAdapter.sol similarity index 92% rename from contracts/DODOPrivatePool/impl/DPPOracle/OracleAdapter.sol rename to contracts/DODOPrivatePool/impl/DPPOracle/WooOracleAdapter.sol index e222ea9..14eb47f 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/OracleAdapter.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/WooOracleAdapter.sol @@ -17,7 +17,7 @@ interface IWooracle { function price(address base) external view returns (uint256 priceNow, bool feasible); } -contract OracleAdapter is IOracle { +contract WooOracleAdapter is IOracle { IWooracle oracle; constructor(address oracleAddress) public { @@ -33,6 +33,7 @@ contract OracleAdapter is IOracle { } function prices(address base) external override view returns (uint256) { + require(oracle.isFeasible(base), "ORACLE NOT FEASIBLE"); return oracle.getPrice(base); } diff --git a/contracts/DODOPrivatePool/intf/IDPPOracle.sol b/contracts/DODOPrivatePool/intf/IDPPOracle.sol index 4619684..181b700 100644 --- a/contracts/DODOPrivatePool/intf/IDPPOracle.sol +++ b/contracts/DODOPrivatePool/intf/IDPPOracle.sol @@ -60,5 +60,7 @@ interface IDPPOracle { function changeOracle(address newOracle) external; - function toggleOracleStatus(bool enabled) external; + function enableOracle() external; + + function disableOracle(uint256 newI) external; } From fbd2057e86bb328a4b3ad66fa7669556480c491e Mon Sep 17 00:00:00 2001 From: tracy <25892474+traceurl@users.noreply.github.com> Date: Mon, 27 Jun 2022 10:32:27 +0800 Subject: [PATCH 3/4] remove dodoapprove in require --- .../impl/DPPOracle/DPPOracleAdmin.sol | 48 +++---------------- 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol index 147951b..4f962f2 100644 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol +++ b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol @@ -62,47 +62,25 @@ contract DPPOracleAdmin is InitializableOwnable { IDPPOracle(_DPP_).retrieve(to, token, amount); } - function changeOracle(address newOracle) external notFreezed { - require( - msg.sender == _OWNER_ || - (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)), - "CHANGEORACLE FORBIDDEN!" - ); + function changeOracle(address newOracle) external onlyOwner notFreezed { IDPPOracle(_DPP_).changeOracle(newOracle); } - function enableOracle() external notFreezed { - require( - msg.sender == _OWNER_ || - (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)), - "CHANGEORACLE FORBIDDEN!" - ); + function enableOracle() external onlyOwner notFreezed { IDPPOracle(_DPP_).enableOracle(); } - function disableOracle(uint256 newI) external notFreezed { - require( - msg.sender == _OWNER_ || - (IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)), - "CHANGEORACLE FORBIDDEN!" - ); + function disableOracle(uint256 newI) external onlyOwner notFreezed { IDPPOracle(_DPP_).disableOracle(newI); } 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!" - ); + ) external onlyOwner notFreezed returns (bool) { return IDPPOracle(_DPP_).tuneParameters( newLpFeeRate, @@ -114,17 +92,10 @@ contract DPPOracleAdmin is InitializableOwnable { } 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!" - ); + ) external onlyOwner notFreezed returns (bool) { return IDPPOracle(_DPP_).tunePrice( newI, @@ -135,7 +106,6 @@ contract DPPOracleAdmin is InitializableOwnable { function reset( - address operator, uint256 newLpFeeRate, uint256 newI, uint256 newK, @@ -143,13 +113,7 @@ contract DPPOracleAdmin is InitializableOwnable { 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!" - ); + ) external onlyOwner notFreezed returns (bool) { return IDPPOracle(_DPP_).reset( _OWNER_, //only support asset transfer out to owner From 5849e9915a35c5c21da43d25fe37168f246fddf4 Mon Sep 17 00:00:00 2001 From: tracy <25892474+traceurl@users.noreply.github.com> Date: Mon, 27 Jun 2022 11:12:59 +0800 Subject: [PATCH 4/4] delete DPPOracleAdmin --- .../impl/DPPOracle/DPPOracleAdmin.sol | 135 ------------------ 1 file changed, 135 deletions(-) delete mode 100644 contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol diff --git a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol b/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol deleted file mode 100644 index 4f962f2..0000000 --- a/contracts/DODOPrivatePool/impl/DPPOracle/DPPOracleAdmin.sol +++ /dev/null @@ -1,135 +0,0 @@ -/* - - Copyright 2021 DODO ZOO. - SPDX-License-Identifier: Apache-2.0 - -*/ - -pragma solidity 0.6.9; -pragma experimental ABIEncoderV2; - -import {IDPPOracle} from "../../intf/IDPPOracle.sol"; -import {IDODOApproveProxy} from "../../../SmartRoute/DODOApproveProxy.sol"; -import {InitializableOwnable} from "../../../lib/InitializableOwnable.sol"; - -/** - * @title DPPOracleAdmin - * @author DODO Breeder - * - * @notice Admin of Oracle DODOPrivatePool - */ -contract DPPOracleAdmin 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 { - IDPPOracle(_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 { - IDPPOracle(_DPP_).retrieve(to, token, amount); - } - - function changeOracle(address newOracle) external onlyOwner notFreezed { - IDPPOracle(_DPP_).changeOracle(newOracle); - } - - function enableOracle() external onlyOwner notFreezed { - IDPPOracle(_DPP_).enableOracle(); - } - - function disableOracle(uint256 newI) external onlyOwner notFreezed { - IDPPOracle(_DPP_).disableOracle(newI); - } - - function tuneParameters( - uint256 newLpFeeRate, - uint256 newI, - uint256 newK, - uint256 minBaseReserve, - uint256 minQuoteReserve - ) external onlyOwner notFreezed returns (bool) { - return - IDPPOracle(_DPP_).tuneParameters( - newLpFeeRate, - newI, - newK, - minBaseReserve, - minQuoteReserve - ); - } - - function tunePrice( - uint256 newI, - uint256 minBaseReserve, - uint256 minQuoteReserve - ) external onlyOwner notFreezed returns (bool) { - return - IDPPOracle(_DPP_).tunePrice( - newI, - minBaseReserve, - minQuoteReserve - ); - } - - - function reset( - uint256 newLpFeeRate, - uint256 newI, - uint256 newK, - uint256 baseOutAmount, - uint256 quoteOutAmount, - uint256 minBaseReserve, - uint256 minQuoteReserve - ) external onlyOwner notFreezed returns (bool) { - return - IDPPOracle(_DPP_).reset( - _OWNER_, //only support asset transfer out to owner - newLpFeeRate, - newI, - newK, - baseOutAmount, - quoteOutAmount, - minBaseReserve, - minQuoteReserve - ); - } - - // ============ Admin Version Control ============ - - function version() external pure returns (string memory) { - return "DPPOracle Admin 1.1.0"; - } -}