update DPPOracle

This commit is contained in:
tracy
2022-06-22 14:18:37 +08:00
parent a1453561ae
commit eb631f6255
7 changed files with 157 additions and 14 deletions

View File

@@ -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";
}
}