add twap switch

This commit is contained in:
owen05
2021-01-19 17:10:46 +08:00
parent 059778b27b
commit 8b683af08f
34 changed files with 519 additions and 174 deletions

View File

@@ -56,10 +56,10 @@ contract DPPTrader is DPPVault {
_setReserve(baseBalance, _QUOTE_TOKEN_.balanceOf(address(this)));
// update TARGET
if (_RState_ != uint16(newRState)) {
_RState_ = uint16(newRState);
require(newBaseTarget <= uint120(-1),"OVERFLOW");
_BASE_TARGET_ = uint120(newBaseTarget);
if (_RState_ != uint32(newRState)) {
require(newBaseTarget <= uint112(-1),"OVERFLOW");
_BASE_TARGET_ = uint112(newBaseTarget);
_RState_ = uint32(newRState);
emit RChange(newRState);
}
@@ -93,10 +93,10 @@ contract DPPTrader is DPPVault {
_setReserve(_BASE_TOKEN_.balanceOf(address(this)), quoteBalance);
// update TARGET
if (_RState_ != uint16(newRState)) {
_RState_ = uint16(newRState);
require(newQuoteTarget <= uint120(-1),"OVERFLOW");
_QUOTE_TARGET_ = uint120(newQuoteTarget);
if (_RState_ != uint32(newRState)) {
require(newQuoteTarget <= uint112(-1),"OVERFLOW");
_QUOTE_TARGET_ = uint112(newQuoteTarget);
_RState_ = uint32(newRState);
emit RChange(newRState);
}
@@ -144,10 +144,10 @@ contract DPPTrader is DPPVault {
require(uint256(_BASE_RESERVE_).sub(baseBalance) <= receiveBaseAmount, "FLASH_LOAN_FAILED");
_transferBaseOut(_MAINTAINER_, mtFee);
if (_RState_ != uint16(newRState)) {
_RState_ = uint16(newRState);
require(newQuoteTarget <= uint120(-1),"OVERFLOW");
_QUOTE_TARGET_ = uint120(newQuoteTarget);
if (_RState_ != uint32(newRState)) {
require(newQuoteTarget <= uint112(-1),"OVERFLOW");
_QUOTE_TARGET_ = uint112(newQuoteTarget);
_RState_ = uint32(newRState);
emit RChange(newRState);
}
emit DODOSwap(
@@ -173,10 +173,10 @@ contract DPPTrader is DPPVault {
require(uint256(_QUOTE_RESERVE_).sub(quoteBalance) <= receiveQuoteAmount, "FLASH_LOAN_FAILED");
_transferQuoteOut(_MAINTAINER_, mtFee);
if (_RState_ != uint16(newRState)) {
_RState_ = uint16(newRState);
require(newBaseTarget <= uint120(-1),"OVERFLOW");
_BASE_TARGET_ = uint120(newBaseTarget);
if (_RState_ != uint32(newRState)) {
require(newBaseTarget <= uint112(-1),"OVERFLOW");
_BASE_TARGET_ = uint112(newBaseTarget);
_RState_ = uint32(newRState);
emit RChange(newRState);
}
emit DODOSwap(
@@ -239,44 +239,4 @@ contract DPPTrader is DPPVault {
.sub(mtFee);
newQuoteTarget = state.Q0;
}
// ============ Helper Functions ============
function getPMMState() public view returns (PMMPricing.PMMState memory state) {
state.i = _I_;
state.K = _K_;
state.B = _BASE_RESERVE_;
state.Q = _QUOTE_RESERVE_;
state.B0 = _BASE_TARGET_;
state.Q0 = _QUOTE_TARGET_;
state.R = PMMPricing.RState(_RState_);
PMMPricing.adjustedTarget(state);
}
function getPMMStateForCall()
external
view
returns (
uint256 i,
uint256 K,
uint256 B,
uint256 Q,
uint256 B0,
uint256 Q0,
uint256 R
)
{
PMMPricing.PMMState memory state = getPMMState();
i = state.i;
K = state.K;
B = state.B;
Q = state.Q;
B0 = state.B0;
Q0 = state.Q0;
R = uint256(state.R);
}
function getMidPrice() public view returns (uint256 midPrice) {
return PMMPricing.getMidPrice(getPMMState());
}
}