dodov2proxy

This commit is contained in:
owen05
2020-11-23 22:33:23 +08:00
parent 8458022a3c
commit 71e1d8717c
15 changed files with 589 additions and 206 deletions

View File

@@ -13,7 +13,6 @@ import {IPermissionManager} from "../../lib/PermissionManager.sol";
import {IExternalValue} from "../../lib/ExternalValue.sol";
import {IERC20} from "../../intf/IERC20.sol";
import {DPPTrader} from "./DPPTrader.sol";
import {ISmartApprove} from "../../intf/ISmartApprove.sol";
contract DPP is DPPTrader {
@@ -31,22 +30,19 @@ contract DPP is DPPTrader {
address kSource,
address iSource,
address gasPriceSource,
address tradePermissionManager,
address iSmartApprove
address tradePermissionManager
) external {
require(msg.sender == _FACTORY_, 'INIT FORBIDDEN');
initOwner(owner);
_MAINTAINER_ = maintainer;
_BASE_TOKEN_ = IERC20(baseTokenAddress);
_QUOTE_TOKEN_ = IERC20(quoteTokenAddress);
_DODO_SMART_APPROVE_ = ISmartApprove(iSmartApprove);
_LP_FEE_RATE_MODEL_ = IFeeRateModel(lpFeeRateModel);
_MT_FEE_RATE_MODEL_ = IFeeRateModel(mtFeeRateModel);
_I_ = IExternalValue(iSource);
_K_ = IExternalValue(kSource);
_GAS_PRICE_LIMIT_ = IExternalValue(gasPriceSource);
_TRADE_PERMISSION_ = IPermissionManager(tradePermissionManager);
_resetTargetAndReserve();
}
// ============ Version Control ============

View File

@@ -15,7 +15,6 @@ import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
import {IPermissionManager} from "../../lib/PermissionManager.sol";
import {IExternalValue} from "../../lib/ExternalValue.sol";
import {IFeeRateModel} from "../../lib/FeeRateModel.sol";
import {ISmartApprove} from "../../intf/ISmartApprove.sol";
import {IERC20} from "../../intf/IERC20.sol";
import {PMMPricing} from "../../lib/PMMPricing.sol";
@@ -29,7 +28,6 @@ contract DPPStorage is InitializableOwnable, ReentrancyGuard {
using SafeMath for uint256;
address public _FACTORY_;
ISmartApprove public _DODO_SMART_APPROVE_;
// ============ Variables for Control ============

View File

@@ -37,6 +37,11 @@ contract DPPVault is DPPStorage {
return _QUOTE_TOKEN_.balanceOf(address(this)).sub(_QUOTE_RESERVE_);
}
// ============ Vault Related
function getVaultReserve() public view returns (uint256 baseReserve, uint256 quoteReserve) {
return (_BASE_RESERVE_, _QUOTE_RESERVE_);
}
// ============ Set Status ============
function setTarget(uint256 baseTarget, uint256 quoteTarget) public onlyOwner {
@@ -50,6 +55,12 @@ contract DPPVault is DPPStorage {
_QUOTE_RESERVE_ = _QUOTE_TOKEN_.balanceOf(address(this));
}
//TODO:
function initTargetAndReserve() public {
require(tx.origin == _OWNER_, "INIT FORBIDDEN");
_resetTargetAndReserve();
}
function _resetTargetAndReserve() internal {
_BASE_TARGET_ = _BASE_TOKEN_.balanceOf(address(this));
_QUOTE_TARGET_ = _QUOTE_TOKEN_.balanceOf(address(this));
@@ -63,14 +74,13 @@ contract DPPVault is DPPStorage {
uint256 newI,
uint256 newK,
uint256 baseOutAmount,
uint256 quoteOutAmount,
address to
uint256 quoteOutAmount
) public {
//TODO: owner 权限可以是operator
require(msg.sender == _DODO_SMART_APPROVE_.getSmartSwap() || msg.sender == _OWNER_, "RESET FORBIDDEN");
require(tx.origin == _OWNER_, "RESET FORBIDDEN");
require(newK > 0 && newK <= 10**18, "K OUT OF RANGE!");
if(baseOutAmount > 0) _transferBaseOut(to, baseOutAmount);
if(quoteOutAmount > 0) _transferQuoteOut(to, quoteOutAmount);
if(baseOutAmount > 0) _transferBaseOut(tx.origin, baseOutAmount);
if(quoteOutAmount > 0) _transferQuoteOut(tx.origin, quoteOutAmount);
_resetTargetAndReserve();
_LP_FEE_RATE_MODEL_.setFeeRate(newLpFeeRate);
_MT_FEE_RATE_MODEL_.setFeeRate(newMtFeeRate);