finish DPP test

This commit is contained in:
mingda
2020-11-26 20:13:16 +08:00
parent 61479dbf04
commit af48643f92
3 changed files with 243 additions and 21 deletions

View File

@@ -15,7 +15,7 @@ import {SafeMath} from "../../lib/SafeMath.sol";
import {DecimalMath} from "../../lib/DecimalMath.sol";
import {SafeERC20} from "../../lib/SafeERC20.sol";
import {Ownable} from "../../lib/Ownable.sol";
import {ISmartApprove} from "../../intf/ISmartApprove.sol";
import {PMMPricing} from "../../lib/PMMPricing.sol";
contract DPPVault is DPPStorage {
using SafeMath for uint256;
@@ -45,15 +45,16 @@ contract DPPVault is DPPStorage {
// ============ Set Status ============
function setTarget(uint256 baseTarget, uint256 quoteTarget) public onlyOwner {
function setTarget(uint256 baseTarget, uint256 quoteTarget) public preventReentrant onlyOwner {
_BASE_TARGET_ = baseTarget;
_QUOTE_TARGET_ = quoteTarget;
_checkStatus();
_setRState();
}
function _syncReserve() internal {
_BASE_RESERVE_ = _BASE_TOKEN_.balanceOf(address(this));
_QUOTE_RESERVE_ = _QUOTE_TOKEN_.balanceOf(address(this));
_setRState();
}
function _resetTargetAndReserve() internal {
@@ -61,6 +62,7 @@ contract DPPVault is DPPStorage {
_QUOTE_TARGET_ = _QUOTE_TOKEN_.balanceOf(address(this));
_BASE_RESERVE_ = _BASE_TARGET_;
_QUOTE_RESERVE_ = _QUOTE_TARGET_;
_setRState();
}
function reset(
@@ -71,22 +73,28 @@ contract DPPVault is DPPStorage {
uint256 newK,
uint256 baseOutAmount,
uint256 quoteOutAmount
) public onlyOwner {
require(newK > 0 && newK <= 10**18, "K OUT OF RANGE!");
_transferBaseOut(assetTo, baseOutAmount);
_transferQuoteOut(assetTo, quoteOutAmount);
_resetTargetAndReserve();
) public preventReentrant onlyOwner {
require(newK >= 1e12 && newK <= 1e18, "K_OUT_OF_RANGE");
require(newI > 0 && newI <= 1e36, "I_OUT_OF_RANGE");
_LP_FEE_RATE_MODEL_.setFeeRate(newLpFeeRate);
_MT_FEE_RATE_MODEL_.setFeeRate(newMtFeeRate);
_I_.set(newI);
_K_.set(newK);
_transferBaseOut(assetTo, baseOutAmount);
_transferQuoteOut(assetTo, quoteOutAmount);
_resetTargetAndReserve();
}
function _checkStatus() internal view {
require(
!(_BASE_RESERVE_ < _BASE_TARGET_ && _QUOTE_RESERVE_ < _QUOTE_TARGET_),
"STATUS_WRONG"
);
function _setRState() internal {
if (_BASE_RESERVE_ == _BASE_TARGET_ && _QUOTE_RESERVE_ == _QUOTE_TARGET_) {
_RState_ = PMMPricing.RState.ONE;
} else if (_BASE_RESERVE_ > _BASE_TARGET_) {
_RState_ = PMMPricing.RState.BELOW_ONE;
} else if (_QUOTE_RESERVE_ > _QUOTE_TARGET_) {
_RState_ = PMMPricing.RState.ABOVE_ONE;
} else {
require(false, "R_STATE_WRONG");
}
}
// ============ Assets Transfer ============
@@ -104,15 +112,11 @@ contract DPPVault is DPPStorage {
}
function retrieve(
address payable to,
address to,
address token,
uint256 amount
) external onlyOwner {
require(to != address(_BASE_TOKEN_) && to != address(_QUOTE_TOKEN_), "USE_WITHDRAW");
if (token == 0x000000000000000000000000000000000000000E) {
to.transfer(amount);
} else {
IERC20(token).safeTransfer(msg.sender, amount);
}
) external preventReentrant onlyOwner {
require(token != address(_BASE_TOKEN_) && token != address(_QUOTE_TOKEN_), "USE_RESET");
IERC20(token).safeTransfer(to, amount);
}
}