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] 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; }