flash loan test
This commit is contained in:
@@ -25,7 +25,10 @@ contract DPPTrader is DPPVault {
|
||||
}
|
||||
|
||||
modifier isSellAllow(address trader) {
|
||||
require(!_SELLING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(trader),"TRADER_SELL_NOT_ALLOWED");
|
||||
require(
|
||||
!_SELLING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(trader),
|
||||
"TRADER_SELL_NOT_ALLOWED"
|
||||
);
|
||||
_;
|
||||
}
|
||||
|
||||
@@ -75,7 +78,10 @@ contract DPPTrader is DPPVault {
|
||||
uint256 newQuoteTarget;
|
||||
|
||||
PMMPricing.RState newRState;
|
||||
(receiveBaseAmount, mtFee, newRState, newQuoteTarget) = querySellQuote(tx.origin,quoteInput);
|
||||
(receiveBaseAmount, mtFee, newRState, newQuoteTarget) = querySellQuote(
|
||||
tx.origin,
|
||||
quoteInput
|
||||
);
|
||||
|
||||
_transferBaseOut(to, receiveBaseAmount);
|
||||
_transferBaseOut(_MAINTAINER_, mtFee);
|
||||
@@ -105,15 +111,15 @@ contract DPPTrader is DPPVault {
|
||||
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
|
||||
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
|
||||
|
||||
// no output -> pure profit
|
||||
if (baseBalance >= _BASE_RESERVE_ && quoteBalance >= _QUOTE_RESERVE_) return;
|
||||
|
||||
// no input -> pure loss
|
||||
require(
|
||||
baseBalance >= _BASE_RESERVE_ || quoteBalance >= _QUOTE_RESERVE_,
|
||||
"FLASH_LOAN_FAILED"
|
||||
);
|
||||
|
||||
// no output -> pure profit
|
||||
if (baseBalance >= _BASE_RESERVE_ && quoteBalance >= _QUOTE_RESERVE_) return;
|
||||
|
||||
// sell quote case
|
||||
// quote input + base output
|
||||
if (baseBalance < _BASE_RESERVE_) {
|
||||
@@ -223,4 +229,9 @@ contract DPPTrader is DPPVault {
|
||||
function getMidPrice() public view returns (uint256 midPrice) {
|
||||
return PMMPricing.getMidPrice(getPMMState());
|
||||
}
|
||||
|
||||
function _syncReserve() internal {
|
||||
_BASE_RESERVE_ = _BASE_TOKEN_.balanceOf(address(this));
|
||||
_QUOTE_RESERVE_ = _QUOTE_TOKEN_.balanceOf(address(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,12 +51,6 @@ contract DPPVault is DPPStorage {
|
||||
_setRState();
|
||||
}
|
||||
|
||||
function _syncReserve() internal {
|
||||
_BASE_RESERVE_ = _BASE_TOKEN_.balanceOf(address(this));
|
||||
_QUOTE_RESERVE_ = _QUOTE_TOKEN_.balanceOf(address(this));
|
||||
_setRState();
|
||||
}
|
||||
|
||||
function _resetTargetAndReserve() internal {
|
||||
_BASE_TARGET_ = _BASE_TOKEN_.balanceOf(address(this));
|
||||
_QUOTE_TARGET_ = _QUOTE_TOKEN_.balanceOf(address(this));
|
||||
|
||||
Reference in New Issue
Block a user