fix admin control && update proxy test framework

This commit is contained in:
owen05
2020-11-25 17:08:28 +08:00
parent 8a4da4b525
commit 8da583d5a8
25 changed files with 383 additions and 177 deletions

View File

@@ -15,13 +15,10 @@ import {IERC20} from "../../intf/IERC20.sol";
import {DPPTrader} from "./DPPTrader.sol";
contract DPP is DPPTrader {
constructor() public {
_FACTORY_ = msg.sender;
}
function init(
address owner,
address maintainer,
address operator,
address baseTokenAddress,
address quoteTokenAddress,
address lpFeeRateModel,
@@ -29,12 +26,13 @@ contract DPP is DPPTrader {
address kSource,
address iSource,
address gasPriceSource,
address dodoSmartApprove,
address tradePermissionManager
) external {
require(msg.sender == _FACTORY_, 'INIT FORBIDDEN');
initOwner(owner);
_ADMIN_ = owner;
_MAINTAINER_ = maintainer;
_OPERATOR_ = operator;
_BASE_TOKEN_ = IERC20(baseTokenAddress);
_QUOTE_TOKEN_ = IERC20(quoteTokenAddress);
_LP_FEE_RATE_MODEL_ = IFeeRateModel(lpFeeRateModel);
@@ -43,6 +41,8 @@ contract DPP is DPPTrader {
_K_ = IExternalValue(kSource);
_GAS_PRICE_LIMIT_ = IExternalValue(gasPriceSource);
_TRADE_PERMISSION_ = IPermissionManager(tradePermissionManager);
_DODO_SMART_APPROVE_ = dodoSmartApprove;
_resetTargetAndReserve();
}
// ============ Version Control ============

View File

@@ -36,6 +36,10 @@ contract DPPAdmin is InitializableOwnable {
IDPP(dpp).setMaintainer(newMaintainer);
}
function setOperator(address newOperator) external onlyOwner {
IDPP(dpp).setOperator(newOperator);
}
function setGasPriceSource(address newGasPriceLimitSource) external onlyOwner {
IDPP(dpp).setGasPriceSource(newGasPriceLimitSource);
}
@@ -55,4 +59,13 @@ contract DPPAdmin is InitializableOwnable {
function setSell(bool open) external onlyOwner {
IDPP(dpp).setSell(open);
}
function retrieve(address payable to,address token,uint256 amount) external onlyOwner {
IDPP(dpp).retrieve(to,token,amount);
}
// ============ Admin Version Control ============
function version() external pure returns (uint256) {
return 100; // 1.0.0
}
}

View File

@@ -27,8 +27,8 @@ import {PMMPricing} from "../../lib/PMMPricing.sol";
contract DPPStorage is InitializableOwnable, ReentrancyGuard {
using SafeMath for uint256;
address public _FACTORY_;
address public _ADMIN_;
address public _DODO_SMART_APPROVE_;
// ============ Variables for Control ============
@@ -44,6 +44,7 @@ contract DPPStorage is InitializableOwnable, ReentrancyGuard {
// ============ Core Address ============
address public _MAINTAINER_; // collect maintainer fee
address public _OPERATOR_;
IERC20 public _BASE_TOKEN_;
IERC20 public _QUOTE_TOKEN_;
@@ -79,6 +80,10 @@ contract DPPStorage is InitializableOwnable, ReentrancyGuard {
_MAINTAINER_ = newMaintainer;
}
function setOperator(address newOperator) external onlyOwner {
_OPERATOR_ = newOperator;
}
function setGasPriceSource(address newGasPriceLimitSource) external onlyOwner {
_GAS_PRICE_LIMIT_ = IExternalValue(newGasPriceLimitSource);
}

View File

@@ -15,6 +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';
contract DPPVault is DPPStorage {
using SafeMath for uint256;
@@ -55,12 +56,6 @@ 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));
@@ -69,6 +64,7 @@ contract DPPVault is DPPStorage {
}
function reset(
address from,
uint256 newLpFeeRate,
uint256 newMtFeeRate,
uint256 newI,
@@ -76,11 +72,10 @@ contract DPPVault is DPPStorage {
uint256 baseOutAmount,
uint256 quoteOutAmount
) public {
//TODO: owner 权限可以是operator
require(tx.origin == _OWNER_, "RESET FORBIDDEN");
require(msg.sender == ISmartApprove(_DODO_SMART_APPROVE_).getSmartSwap() && from == _OPERATOR_, "RESET FORBIDDEN");
require(newK > 0 && newK <= 10**18, "K OUT OF RANGE!");
if(baseOutAmount > 0) _transferBaseOut(tx.origin, baseOutAmount);
if(quoteOutAmount > 0) _transferQuoteOut(tx.origin, quoteOutAmount);
if(baseOutAmount > 0) _transferBaseOut(from, baseOutAmount);
if(quoteOutAmount > 0) _transferQuoteOut(from, quoteOutAmount);
_resetTargetAndReserve();
_LP_FEE_RATE_MODEL_.setFeeRate(newLpFeeRate);
_MT_FEE_RATE_MODEL_.setFeeRate(newMtFeeRate);
@@ -115,7 +110,7 @@ contract DPPVault is DPPStorage {
uint256 amount
) external onlyOwner {
require(to != address(_BASE_TOKEN_) && to != address(_QUOTE_TOKEN_), "USE_WITHDRAW");
if (token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
if (token == 0x000000000000000000000000000000000000000E) {
to.transfer(amount);
} else {
IERC20(token).safeTransfer(msg.sender, amount);