enable/disable oracle; remove isPriceValid modifier
This commit is contained in:
@@ -20,7 +20,8 @@ import {DPPTrader} from "./DPPTrader.sol";
|
|||||||
*/
|
*/
|
||||||
contract DPPOracle is DPPTrader {
|
contract DPPOracle is DPPTrader {
|
||||||
|
|
||||||
event ToggleOracleStatus(bool isEnabled);
|
event EnableOracle();
|
||||||
|
event DisableOracle(uint256 newI);
|
||||||
event ChangeOracle(address indexed oracle);
|
event ChangeOracle(address indexed oracle);
|
||||||
|
|
||||||
function init(
|
function init(
|
||||||
@@ -68,10 +69,16 @@ contract DPPOracle is DPPTrader {
|
|||||||
emit ChangeOracle(newOracle);
|
emit ChangeOracle(newOracle);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleOracleStatus(bool enabled) public preventReentrant onlyOwner returns (bool) {
|
function enableOracle() public preventReentrant onlyOwner {
|
||||||
_IS_ORACLE_ENABLED = enabled;
|
_IS_ORACLE_ENABLED = true;
|
||||||
emit ToggleOracleStatus(enabled);
|
emit EnableOracle();
|
||||||
return enabled;
|
}
|
||||||
|
|
||||||
|
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(
|
function tuneParameters(
|
||||||
|
|||||||
@@ -71,13 +71,22 @@ contract DPPOracleAdmin is InitializableOwnable {
|
|||||||
IDPPOracle(_DPP_).changeOracle(newOracle);
|
IDPPOracle(_DPP_).changeOracle(newOracle);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleOracleStatus(bool enabled) external notFreezed {
|
function enableOracle() external notFreezed {
|
||||||
require(
|
require(
|
||||||
msg.sender == _OWNER_ ||
|
msg.sender == _OWNER_ ||
|
||||||
(IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)),
|
(IDODOApproveProxy(_DODO_APPROVE_PROXY_).isAllowedProxy(msg.sender)),
|
||||||
"CHANGEORACLE FORBIDDEN!"
|
"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(
|
function tuneParameters(
|
||||||
|
|||||||
@@ -38,20 +38,12 @@ contract DPPTrader is DPPVault {
|
|||||||
|
|
||||||
event RChange(PMMPricing.RState newRState);
|
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 ============
|
// ============ Trade Functions ============
|
||||||
|
|
||||||
function sellBase(address to)
|
function sellBase(address to)
|
||||||
external
|
external
|
||||||
preventReentrant
|
preventReentrant
|
||||||
isPriceValid
|
|
||||||
returns (uint256 receiveQuoteAmount)
|
returns (uint256 receiveQuoteAmount)
|
||||||
{
|
{
|
||||||
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
|
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
|
||||||
@@ -87,7 +79,6 @@ contract DPPTrader is DPPVault {
|
|||||||
function sellQuote(address to)
|
function sellQuote(address to)
|
||||||
external
|
external
|
||||||
preventReentrant
|
preventReentrant
|
||||||
isPriceValid
|
|
||||||
returns (uint256 receiveBaseAmount)
|
returns (uint256 receiveBaseAmount)
|
||||||
{
|
{
|
||||||
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
|
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
|
||||||
@@ -128,7 +119,7 @@ contract DPPTrader is DPPVault {
|
|||||||
uint256 quoteAmount,
|
uint256 quoteAmount,
|
||||||
address _assetTo,
|
address _assetTo,
|
||||||
bytes calldata data
|
bytes calldata data
|
||||||
) external isPriceValid preventReentrant {
|
) external preventReentrant {
|
||||||
address assetTo = _assetTo;
|
address assetTo = _assetTo;
|
||||||
_transferBaseOut(assetTo, baseAmount);
|
_transferBaseOut(assetTo, baseAmount);
|
||||||
_transferQuoteOut(assetTo, quoteAmount);
|
_transferQuoteOut(assetTo, quoteAmount);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ interface IWooracle {
|
|||||||
function price(address base) external view returns (uint256 priceNow, bool feasible);
|
function price(address base) external view returns (uint256 priceNow, bool feasible);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract OracleAdapter is IOracle {
|
contract WooOracleAdapter is IOracle {
|
||||||
IWooracle oracle;
|
IWooracle oracle;
|
||||||
|
|
||||||
constructor(address oracleAddress) public {
|
constructor(address oracleAddress) public {
|
||||||
@@ -33,6 +33,7 @@ contract OracleAdapter is IOracle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function prices(address base) external override view returns (uint256) {
|
function prices(address base) external override view returns (uint256) {
|
||||||
|
require(oracle.isFeasible(base), "ORACLE NOT FEASIBLE");
|
||||||
return oracle.getPrice(base);
|
return oracle.getPrice(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,5 +60,7 @@ interface IDPPOracle {
|
|||||||
|
|
||||||
function changeOracle(address newOracle) external;
|
function changeOracle(address newOracle) external;
|
||||||
|
|
||||||
function toggleOracleStatus(bool enabled) external;
|
function enableOracle() external;
|
||||||
|
|
||||||
|
function disableOracle(uint256 newI) external;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user