enable/disable oracle; remove isPriceValid modifier
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user