finish dpp test
This commit is contained in:
@@ -9,59 +9,106 @@ pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {IDPP} from "../intf/IDPP.sol";
|
||||
import {ISmartApprove} from '../../intf/ISmartApprove.sol';
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
|
||||
contract DPPAdmin is InitializableOwnable {
|
||||
|
||||
address public dpp;
|
||||
address public _DPP_;
|
||||
address public _OPERATOR_;
|
||||
address public _DODO_SMART_APPROVE_;
|
||||
|
||||
function init(address owner, address _dpp) external {
|
||||
function init(address owner, address dpp,address operator, address dodoSmartApprove) external {
|
||||
initOwner(owner);
|
||||
dpp = _dpp;
|
||||
}
|
||||
|
||||
function setLpFeeRateModel(address newLpFeeRateModel) external onlyOwner {
|
||||
IDPP(dpp).setLpFeeRateModel(newLpFeeRateModel);
|
||||
}
|
||||
|
||||
function setMtFeeRateModel(address newMtFeeRateModel) external onlyOwner {
|
||||
IDPP(dpp).setMtFeeRateModel(newMtFeeRateModel);
|
||||
}
|
||||
|
||||
function setTradePermissionManager(address newTradePermissionManager) external onlyOwner {
|
||||
IDPP(dpp).setTradePermissionManager(newTradePermissionManager);
|
||||
}
|
||||
|
||||
function setMaintainer(address newMaintainer) external onlyOwner {
|
||||
IDPP(dpp).setMaintainer(newMaintainer);
|
||||
_DPP_ = dpp;
|
||||
_OPERATOR_ = operator;
|
||||
_DODO_SMART_APPROVE_ = dodoSmartApprove;
|
||||
}
|
||||
|
||||
function setOperator(address newOperator) external onlyOwner {
|
||||
IDPP(dpp).setOperator(newOperator);
|
||||
_OPERATOR_ = newOperator;
|
||||
}
|
||||
|
||||
function setLpFeeRateModel(address newLpFeeRateModel) external onlyOwner {
|
||||
IDPP(_DPP_).setLpFeeRateModel(newLpFeeRateModel);
|
||||
}
|
||||
|
||||
function setMtFeeRateModel(address newMtFeeRateModel) external onlyOwner {
|
||||
IDPP(_DPP_).setMtFeeRateModel(newMtFeeRateModel);
|
||||
}
|
||||
|
||||
function setTradePermissionManager(address newTradePermissionManager) external onlyOwner {
|
||||
IDPP(_DPP_).setTradePermissionManager(newTradePermissionManager);
|
||||
}
|
||||
|
||||
function setMaintainer(address newMaintainer) external onlyOwner {
|
||||
IDPP(_DPP_).setMaintainer(newMaintainer);
|
||||
}
|
||||
|
||||
function setGasPriceSource(address newGasPriceLimitSource) external onlyOwner {
|
||||
IDPP(dpp).setGasPriceSource(newGasPriceLimitSource);
|
||||
IDPP(_DPP_).setGasPriceSource(newGasPriceLimitSource);
|
||||
}
|
||||
|
||||
function setISource(address newISource) external onlyOwner {
|
||||
IDPP(dpp).setISource(newISource);
|
||||
IDPP(_DPP_).setISource(newISource);
|
||||
}
|
||||
|
||||
function setKSource(address newKSource) external onlyOwner {
|
||||
IDPP(dpp).setKSource(newKSource);
|
||||
IDPP(_DPP_).setKSource(newKSource);
|
||||
}
|
||||
|
||||
function setBuy(bool open) external onlyOwner {
|
||||
IDPP(dpp).setBuy(open);
|
||||
IDPP(_DPP_).setBuy(open);
|
||||
}
|
||||
|
||||
function setSell(bool open) external onlyOwner {
|
||||
IDPP(dpp).setSell(open);
|
||||
IDPP(_DPP_).setSell(open);
|
||||
}
|
||||
|
||||
function retrieve(address payable to,address token,uint256 amount) external onlyOwner {
|
||||
IDPP(dpp).retrieve(to,token,amount);
|
||||
IDPP(_DPP_).retrieve(to,token,amount);
|
||||
}
|
||||
|
||||
function reset(
|
||||
address assetTo,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount
|
||||
) external {
|
||||
require(msg.sender == _OWNER_ || (msg.sender == ISmartApprove(_DODO_SMART_APPROVE_).getSmartSwap() && assetTo == _OPERATOR_), "RESET FORBIDDEN!");
|
||||
IDPP(_DPP_).reset(
|
||||
assetTo,
|
||||
newLpFeeRate,
|
||||
newMtFeeRate,
|
||||
newI,
|
||||
newK,
|
||||
baseOutAmount,
|
||||
quoteOutAmount
|
||||
);
|
||||
}
|
||||
|
||||
function resetETH(
|
||||
address from,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount
|
||||
) external {
|
||||
require(msg.sender == _OWNER_ || (msg.sender == ISmartApprove(_DODO_SMART_APPROVE_).getSmartSwap() && from == _OPERATOR_), "RESET FORBIDDEN!");
|
||||
IDPP(_DPP_).reset(
|
||||
msg.sender,
|
||||
newLpFeeRate,
|
||||
newMtFeeRate,
|
||||
newI,
|
||||
newK,
|
||||
baseOutAmount,
|
||||
quoteOutAmount
|
||||
);
|
||||
}
|
||||
|
||||
// ============ Admin Version Control ============
|
||||
|
||||
@@ -105,4 +105,9 @@ contract DPPStorage is InitializableOwnable, ReentrancyGuard {
|
||||
function getMtFeeRate(address trader) external view returns (uint256 feeRate) {
|
||||
return _MT_FEE_RATE_MODEL_.getFeeRate(trader);
|
||||
}
|
||||
|
||||
function getOwner() external view returns (address) {
|
||||
return _OWNER_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ 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;
|
||||
|
||||
@@ -12,7 +12,6 @@ interface IDPP {
|
||||
function init(
|
||||
address owner,
|
||||
address maintainer,
|
||||
address operator,
|
||||
address baseTokenAddress,
|
||||
address quoteTokenAddress,
|
||||
address lpFeeRateModel,
|
||||
@@ -20,7 +19,6 @@ interface IDPP {
|
||||
address kSource,
|
||||
address iSource,
|
||||
address gasPriceSource,
|
||||
address dodoSmartApprove,
|
||||
address tradePermissionManager
|
||||
) external;
|
||||
|
||||
@@ -33,8 +31,6 @@ interface IDPP {
|
||||
|
||||
function setMaintainer(address newMaintainer) external;
|
||||
|
||||
function setOperator(address newOperator) external;
|
||||
|
||||
function setGasPriceSource(address newGasPriceLimitSource) external;
|
||||
|
||||
function setISource(address newISource) external;
|
||||
@@ -48,4 +44,15 @@ interface IDPP {
|
||||
|
||||
function retrieve(address payable to,address token,uint256 amount) external;
|
||||
|
||||
function reset(
|
||||
address assetTo,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount
|
||||
) external;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface IDPPAdmin {
|
||||
function init(address owner, address _dpp) external;
|
||||
function init(address owner, address dpp,address operator, address dodoSmartApprove) external;
|
||||
}
|
||||
@@ -13,39 +13,39 @@ import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
|
||||
contract DVMAdmin is InitializableOwnable {
|
||||
|
||||
address public dvm;
|
||||
address public _DVM_;
|
||||
|
||||
function init(address owner, address _dvm) external {
|
||||
function init(address owner, address dvm) external {
|
||||
initOwner(owner);
|
||||
dvm = _dvm;
|
||||
_DVM_ = dvm;
|
||||
}
|
||||
|
||||
function setLpFeeRateModel(address newLpFeeRateModel) external onlyOwner {
|
||||
IDVM(dvm).setLpFeeRateModel(newLpFeeRateModel);
|
||||
IDVM(_DVM_).setLpFeeRateModel(newLpFeeRateModel);
|
||||
}
|
||||
|
||||
function setMtFeeRateModel(address newMtFeeRateModel) external onlyOwner {
|
||||
IDVM(dvm).setMtFeeRateModel(newMtFeeRateModel);
|
||||
IDVM(_DVM_).setMtFeeRateModel(newMtFeeRateModel);
|
||||
}
|
||||
|
||||
function setTradePermissionManager(address newTradePermissionManager) external onlyOwner {
|
||||
IDVM(dvm).setTradePermissionManager(newTradePermissionManager);
|
||||
IDVM(_DVM_).setTradePermissionManager(newTradePermissionManager);
|
||||
}
|
||||
|
||||
function setMaintainer(address newMaintainer) external onlyOwner {
|
||||
IDVM(dvm).setMaintainer(newMaintainer);
|
||||
IDVM(_DVM_).setMaintainer(newMaintainer);
|
||||
}
|
||||
|
||||
function setGasPriceSource(address newGasPriceLimitSource) external onlyOwner {
|
||||
IDVM(dvm).setGasPriceSource(newGasPriceLimitSource);
|
||||
IDVM(_DVM_).setGasPriceSource(newGasPriceLimitSource);
|
||||
}
|
||||
|
||||
function setBuy(bool open) external onlyOwner {
|
||||
IDVM(dvm).setBuy(open);
|
||||
IDVM(_DVM_).setBuy(open);
|
||||
}
|
||||
|
||||
function setSell(bool open) external onlyOwner {
|
||||
IDVM(dvm).setSell(open);
|
||||
IDVM(_DVM_).setSell(open);
|
||||
}
|
||||
|
||||
// ============ Admin Version Control ============
|
||||
|
||||
@@ -99,4 +99,9 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
||||
function getMtFeeRate(address trader) external view returns (uint256 feeRate) {
|
||||
return _MT_FEE_RATE_MODEL_.getFeeRate(trader);
|
||||
}
|
||||
|
||||
function getOwner() external view returns (address) {
|
||||
return _OWNER_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,11 +54,11 @@ contract DPPFactory is Ownable {
|
||||
_CLONE_FACTORY_ = cloneFactory;
|
||||
_DPP_TEMPLATE_ = dppTemplate;
|
||||
_DPP_ADMIN_TEMPLATE_ = dppAdminTemplate;
|
||||
_DODO_SMART_APPROVE_ = dodoSmartApprove;
|
||||
_FEE_RATE_MODEL_TEMPLATE_ = defautFeeRateModelTemplate;
|
||||
_PERMISSION_MANAGER_TEMPLATE_ = defaultPermissionManagerTemplate;
|
||||
_VALUE_SOURCE_ = defaultExternalValueTemplate;
|
||||
_DEFAULT_GAS_PRICE_SOURCE_ = defaultGasPriceSource;
|
||||
_DODO_SMART_APPROVE_ = dodoSmartApprove;
|
||||
}
|
||||
|
||||
function createDODOPrivatePool() external returns(address newPrivatePool) {
|
||||
@@ -77,11 +77,10 @@ contract DPPFactory is Ownable {
|
||||
) external {
|
||||
{
|
||||
address _dppAddress = dppAddress;
|
||||
address adminModel = _createDPPAdminModel(from,_dppAddress);
|
||||
address adminModel = _createDPPAdminModel(from,_dppAddress,from,_DODO_SMART_APPROVE_);
|
||||
IDPP(_dppAddress).init(
|
||||
adminModel,
|
||||
from,
|
||||
from,
|
||||
baseToken,
|
||||
quoteToken,
|
||||
_createFeeRateModel(_dppAddress, lpFeeRate),
|
||||
@@ -89,7 +88,6 @@ contract DPPFactory is Ownable {
|
||||
_createExternalValueModel(_dppAddress, k),
|
||||
_createExternalValueModel(_dppAddress, i),
|
||||
_DEFAULT_GAS_PRICE_SOURCE_,
|
||||
_DODO_SMART_APPROVE_,
|
||||
_createPermissionManager(adminModel)
|
||||
);
|
||||
}
|
||||
@@ -123,16 +121,15 @@ contract DPPFactory is Ownable {
|
||||
IExternalValue(valueModel).init(owner, value);
|
||||
}
|
||||
|
||||
function _createDPPAdminModel(address owner, address dpp) internal returns (address adminModel) {
|
||||
function _createDPPAdminModel(address owner, address dpp,address operator, address dodoSmartApprove) internal returns (address adminModel) {
|
||||
adminModel = ICloneFactory(_CLONE_FACTORY_).clone(_DPP_ADMIN_TEMPLATE_);
|
||||
IDPPAdmin(adminModel).init(owner,dpp);
|
||||
IDPPAdmin(adminModel).init(owner,dpp,operator,dodoSmartApprove);
|
||||
}
|
||||
|
||||
function updateAdminTemplate(address _newDPPAdminTemplate) external onlyOwner {
|
||||
_DPP_ADMIN_TEMPLATE_ = _newDPPAdminTemplate;
|
||||
}
|
||||
|
||||
|
||||
function getPrivatePool(address baseToken, address quoteToken)
|
||||
external
|
||||
view
|
||||
|
||||
@@ -31,6 +31,10 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
_;
|
||||
}
|
||||
|
||||
fallback() external payable {}
|
||||
|
||||
receive() external payable {}
|
||||
|
||||
//============================== events ==================================
|
||||
event OrderHistory(
|
||||
address indexed fromToken,
|
||||
@@ -70,7 +74,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
uint256 k,
|
||||
uint256 deadline
|
||||
) external virtual override payable judgeExpired(deadline) returns (address newVendingMachine,uint256 shares) {
|
||||
require(k > 0 && k<= 10**18, "DODOV2Proxy01: K OUT OF RANGE");
|
||||
require(k > 0 && k<= 10**18, 'DODOV2Proxy01: K OUT OF RANGE');
|
||||
newVendingMachine = IDODOV2(dvmFactory).createDODOVendingMachine(msg.sender, baseToken,quoteToken,lpFeeRate,mtFeeRate,i,k);
|
||||
if(baseInAmount > 0)
|
||||
IDODOV2(smartApprove).claimTokens(baseToken, msg.sender, newVendingMachine, baseInAmount);
|
||||
@@ -125,7 +129,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
if(quoteAdjustedInAmount > 0)
|
||||
IDODOV2(smartApprove).claimTokens(IDODOV2(_dvm)._QUOTE_TOKEN_(), msg.sender, _dvm, quoteAdjustedInAmount);
|
||||
(shares,baseActualInAmount,quoteActualInAmount) = IDODOV2(_dvm).buyShares(to);
|
||||
require(baseActualInAmount >= baseMinAmount && quoteActualInAmount >= quoteMinAmount, "DODOV2Proxy01: deposit amount is not enough");
|
||||
require(baseActualInAmount >= baseMinAmount && quoteActualInAmount >= quoteMinAmount, 'DODOV2Proxy01: deposit amount is not enough');
|
||||
}
|
||||
|
||||
//TODO:ETH 构造data
|
||||
@@ -137,9 +141,9 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
uint256 quoteOutMinAmount,
|
||||
uint256 deadline
|
||||
) external virtual override payable judgeExpired(deadline) returns (uint256 baseOutAmount,uint256 quoteOutAmount) {
|
||||
require(shares > 0, "DODOV2Proxy01: Insufficient_Liquidity");
|
||||
require(shares > 0, 'DODOV2Proxy01: Insufficient_Liquidity');
|
||||
(baseOutAmount,quoteOutAmount) = IDODOV2(DVMAddress).sellShares(to, shares, "");
|
||||
require(baseOutAmount >= baseOutMinAmount && quoteOutAmount >= quoteOutMinAmount,"DODOV2Proxy01: withdraw amount is not enough");
|
||||
require(baseOutAmount >= baseOutMinAmount && quoteOutAmount >= quoteOutMinAmount,'DODOV2Proxy01: withdraw amount is not enough');
|
||||
}
|
||||
|
||||
function createDODOPrivatePool(
|
||||
@@ -158,7 +162,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
if(baseToken != ETH_ADDRESS){
|
||||
IDODOV2(smartApprove).claimTokens(baseToken, msg.sender, newPrivatePool, baseInAmount);
|
||||
}else {
|
||||
require(msg.value == baseInAmount, "DODOV2Proxy01: ETH_AMOUNT_NOT_MATCH");
|
||||
require(msg.value == baseInAmount, 'DODOV2Proxy01: ETH_AMOUNT_NOT_MATCH');
|
||||
IWETH(_WETH_).deposit{value: baseInAmount}();
|
||||
assert(IWETH(_WETH_).transfer(newPrivatePool, baseInAmount));
|
||||
baseToken = _WETH_;
|
||||
@@ -168,7 +172,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
if(quoteToken != ETH_ADDRESS){
|
||||
IDODOV2(smartApprove).claimTokens(quoteToken, msg.sender, newPrivatePool, quoteInAmount);
|
||||
}else {
|
||||
require(msg.value == quoteInAmount, "DODOV2Proxy01: ETH_AMOUNT_NOT_MATCH");
|
||||
require(msg.value == quoteInAmount, 'DODOV2Proxy01: ETH_AMOUNT_NOT_MATCH');
|
||||
IWETH(_WETH_).deposit{value: quoteInAmount}();
|
||||
assert(IWETH(_WETH_).transfer(newPrivatePool, quoteInAmount));
|
||||
quoteToken = _WETH_;
|
||||
@@ -186,7 +190,6 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
);
|
||||
}
|
||||
|
||||
//TODO:ETH
|
||||
function resetDODOPrivatePool(
|
||||
address DPPAddress,
|
||||
uint256 newLpFeeRate,
|
||||
@@ -198,12 +201,13 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount,
|
||||
uint256 deadline
|
||||
) external virtual override payable judgeExpired(deadline) {
|
||||
if(baseInAmount > 0)
|
||||
) external virtual override judgeExpired(deadline) {
|
||||
if(baseInAmount > 0)
|
||||
IDODOV2(smartApprove).claimTokens(IDODOV2(DPPAddress)._BASE_TOKEN_(), msg.sender, DPPAddress, baseInAmount);
|
||||
if(quoteInAmount > 0)
|
||||
IDODOV2(smartApprove).claimTokens(IDODOV2(DPPAddress)._QUOTE_TOKEN_(), msg.sender, DPPAddress, quoteInAmount);
|
||||
IDODOV2(DPPAddress).reset(
|
||||
IDODOV2(IDODOV2(DPPAddress).getOwner()).reset(
|
||||
msg.sender,
|
||||
newLpFeeRate,
|
||||
newMtFeeRate,
|
||||
newI,
|
||||
@@ -213,6 +217,81 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
);
|
||||
}
|
||||
|
||||
function resetDODOPrivatePoolETH(
|
||||
address DPPAddress,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseInAmount,
|
||||
uint256 quoteInAmount,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount,
|
||||
uint8 flag, // 1 - baseInETH, 2 - quoteInETH, 3 - baseOutETH, 4 - quoteOutETH
|
||||
uint256 deadline
|
||||
) external virtual override payable judgeExpired(deadline) {
|
||||
if(baseInAmount > 0){
|
||||
if(flag == 1){
|
||||
require(msg.value == baseInAmount, 'DODOV2Proxy01: ETH_AMOUNT_NOT_MATCH');
|
||||
IWETH(_WETH_).deposit{value: baseInAmount}();
|
||||
assert(IWETH(_WETH_).transfer(DPPAddress, baseInAmount));
|
||||
}else {
|
||||
IDODOV2(smartApprove).claimTokens(IDODOV2(DPPAddress)._BASE_TOKEN_(), msg.sender, DPPAddress, baseInAmount);
|
||||
}
|
||||
}
|
||||
if(quoteInAmount > 0){
|
||||
if(flag == 2){
|
||||
require(msg.value == quoteInAmount, 'DODOV2Proxy01: ETH_AMOUNT_NOT_MATCH');
|
||||
IWETH(_WETH_).deposit{value: quoteInAmount}();
|
||||
assert(IWETH(_WETH_).transfer(DPPAddress, quoteInAmount));
|
||||
}else {
|
||||
IDODOV2(smartApprove).claimTokens(IDODOV2(DPPAddress)._QUOTE_TOKEN_(), msg.sender, DPPAddress, quoteInAmount);
|
||||
}
|
||||
}
|
||||
if( (flag == 3 && baseOutAmount > 0) || (flag == 4 && quoteOutAmount > 0) ) {
|
||||
IDODOV2(IDODOV2(DPPAddress).getOwner()).resetETH(
|
||||
msg.sender,
|
||||
newLpFeeRate,
|
||||
newMtFeeRate,
|
||||
newI,
|
||||
newK,
|
||||
baseOutAmount,
|
||||
quoteOutAmount
|
||||
);
|
||||
if(baseOutAmount > 0) {
|
||||
if(flag == 3) {
|
||||
uint256 wethAmount = IWETH(_WETH_).balanceOf(address(this));
|
||||
IWETH(_WETH_).withdraw(wethAmount);
|
||||
(bool success,) = msg.sender.call{value:wethAmount}(new bytes(0));
|
||||
require(success, 'DODOV2Proxy01: ETH_TRANSFER_FAILED');
|
||||
}else {
|
||||
IERC20(IDODOV2(DPPAddress)._BASE_TOKEN_()).universalTransfer(msg.sender, baseOutAmount);
|
||||
}
|
||||
}
|
||||
|
||||
if(quoteOutAmount > 0) {
|
||||
if(flag == 4) {
|
||||
uint256 wethAmount = IWETH(_WETH_).balanceOf(address(this));
|
||||
IWETH(_WETH_).withdraw(wethAmount);
|
||||
(bool success,) = msg.sender.call{value:wethAmount}(new bytes(0));
|
||||
require(success, 'DODOV2Proxy01: ETH_TRANSFER_FAILED');
|
||||
}else {
|
||||
IERC20(IDODOV2(DPPAddress)._QUOTE_TOKEN_()).universalTransfer(msg.sender, quoteOutAmount);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
IDODOV2(IDODOV2(DPPAddress).getOwner()).reset(
|
||||
msg.sender,
|
||||
newLpFeeRate,
|
||||
newMtFeeRate,
|
||||
newI,
|
||||
newK,
|
||||
baseOutAmount,
|
||||
quoteOutAmount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function dodoSwap(
|
||||
address fromToken,
|
||||
address toToken,
|
||||
@@ -293,79 +372,4 @@ contract DODOV2Proxy01 is IDODOV2Proxy01 {
|
||||
emit OrderHistory(fromToken, toToken, msg.sender, fromTokenAmount, returnAmount, block.timestamp);
|
||||
emit ExternalRecord(to, msg.sender);
|
||||
}
|
||||
|
||||
//====================== temporary for test ======================
|
||||
// function sellBaseOnDVM(
|
||||
// address DVMAddress,
|
||||
// address to,
|
||||
// uint256 baseAmount,
|
||||
// uint256 minReceive
|
||||
// ) public returns (uint256 receiveAmount) {
|
||||
// IERC20(IDVM(DVMAddress)._BASE_TOKEN_()).safeTransferFrom(
|
||||
// msg.sender,
|
||||
// DVMAddress,
|
||||
// baseAmount
|
||||
// );
|
||||
// receiveAmount = IDVM(DVMAddress).sellBase(to);
|
||||
// require(receiveAmount >= minReceive, "RECEIVE_NOT_ENOUGH");
|
||||
// return receiveAmount;
|
||||
// }
|
||||
|
||||
// function sellQuoteOnDVM(
|
||||
// address DVMAddress,
|
||||
// address to,
|
||||
// uint256 quoteAmount,
|
||||
// uint256 minReceive
|
||||
// ) public returns (uint256 receiveAmount) {
|
||||
// IERC20(IDVM(DVMAddress)._QUOTE_TOKEN_()).safeTransferFrom(
|
||||
// msg.sender,
|
||||
// DVMAddress,
|
||||
// quoteAmount
|
||||
// );
|
||||
// receiveAmount = IDVM(DVMAddress).sellQuote(to);
|
||||
// require(receiveAmount >= minReceive, "RECEIVE_NOT_ENOUGU");
|
||||
// return receiveAmount;
|
||||
// }
|
||||
|
||||
// function depositToDVM(
|
||||
// address DVMAddress,
|
||||
// address to,
|
||||
// uint256 baseAmount,
|
||||
// uint256 quoteAmount
|
||||
// ) public returns (uint256 shares) {
|
||||
// uint256 adjustedBaseAmount;
|
||||
// uint256 adjustedQuoteAmount;
|
||||
// (uint256 baseReserve, uint256 quoteReserve) = IDVM(DVMAddress).getVaultReserve();
|
||||
// if (quoteReserve == 0 && baseReserve == 0) {
|
||||
// adjustedBaseAmount = baseAmount;
|
||||
// adjustedQuoteAmount = quoteAmount;
|
||||
// }
|
||||
// if (quoteReserve == 0 && baseReserve > 0) {
|
||||
// adjustedBaseAmount = baseAmount;
|
||||
// adjustedQuoteAmount = 0;
|
||||
// }
|
||||
// if (quoteReserve > 0 && baseReserve > 0) {
|
||||
// uint256 baseIncreaseRatio = DecimalMath.divFloor(baseAmount, baseReserve);
|
||||
// uint256 quoteIncreaseRatio = DecimalMath.divFloor(quoteAmount, quoteReserve);
|
||||
// if (baseIncreaseRatio <= quoteIncreaseRatio) {
|
||||
// adjustedBaseAmount = baseAmount;
|
||||
// adjustedQuoteAmount = DecimalMath.mulFloor(quoteReserve, baseIncreaseRatio);
|
||||
// } else {
|
||||
// adjustedQuoteAmount = quoteAmount;
|
||||
// adjustedBaseAmount = DecimalMath.mulFloor(baseReserve, quoteIncreaseRatio);
|
||||
// }
|
||||
// }
|
||||
// IERC20(IDVM(DVMAddress)._BASE_TOKEN_()).safeTransferFrom(
|
||||
// msg.sender,
|
||||
// DVMAddress,
|
||||
// adjustedBaseAmount
|
||||
// );
|
||||
// IERC20(IDVM(DVMAddress)._QUOTE_TOKEN_()).safeTransferFrom(
|
||||
// msg.sender,
|
||||
// DVMAddress,
|
||||
// adjustedQuoteAmount
|
||||
// );
|
||||
// shares = IDVM(DVMAddress).buyShares(to);
|
||||
// return shares;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ interface IDODOV2 {
|
||||
|
||||
function _QUOTE_TOKEN_() external returns (address);
|
||||
|
||||
function getOwner() external view returns (address);
|
||||
|
||||
//========== DODOVendingMachine ========
|
||||
|
||||
function createDODOVendingMachine(
|
||||
@@ -56,6 +58,17 @@ interface IDODOV2 {
|
||||
) external;
|
||||
|
||||
function reset(
|
||||
address assetTo,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount
|
||||
) external;
|
||||
|
||||
function resetETH(
|
||||
address from,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
|
||||
@@ -93,6 +93,21 @@ interface IDODOV2Proxy01 {
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount,
|
||||
uint256 deadline
|
||||
) external;
|
||||
|
||||
|
||||
function resetDODOPrivatePoolETH(
|
||||
address DPPAddress,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseInAmount,
|
||||
uint256 quoteInAmount,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount,
|
||||
uint8 flag, // 1 - baseInETH, 2 - quoteInETH, 3 - baseOutETH, 4 - quoteOutETH
|
||||
uint256 deadline
|
||||
) external payable;
|
||||
|
||||
//TODO: addLiquidityToClassical
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
*/
|
||||
|
||||
// import * as assert from 'assert';
|
||||
|
||||
import BigNumber from "bignumber.js";
|
||||
import { decimalStr, mweiStr} from '../utils/Converter';
|
||||
import { logGas } from '../utils/Log';
|
||||
import { ProxyContext, getProxyContext } from '../utils/ProxyContext';
|
||||
import { assert } from 'chai';
|
||||
import * as contracts from '../utils/Contracts';
|
||||
import { Contract } from 'web3-eth-contract';
|
||||
|
||||
let lp: string;
|
||||
let project: string;
|
||||
@@ -68,12 +70,16 @@ describe("DODOProxyV2.0", () => {
|
||||
let ctx: ProxyContext;
|
||||
let dpp_DODO_USDT: string;
|
||||
let dpp_WETH_USDT: string;
|
||||
let DPP_DODO_USDT: Contract;
|
||||
let DPP_WETH_USDT: Contract;
|
||||
|
||||
before(async () => {
|
||||
ctx = await getProxyContext();
|
||||
await init(ctx);
|
||||
dpp_DODO_USDT = await initCreateDPP(ctx,ctx.DODO.options.address,ctx.USDT.options.address,decimalStr("10000"),mweiStr("10000"),"0");
|
||||
dpp_WETH_USDT = await initCreateDPP(ctx,'0x000000000000000000000000000000000000000E',ctx.USDT.options.address,decimalStr("10"),mweiStr("10000"),"10");
|
||||
dpp_DODO_USDT = await initCreateDPP(ctx,ctx.DODO.options.address,ctx.USDT.options.address,decimalStr("10000"),mweiStr("10000"), "0");
|
||||
DPP_DODO_USDT = contracts.getContractWithAddress(contracts.DPP_NAME,dpp_DODO_USDT);
|
||||
dpp_WETH_USDT = await initCreateDPP(ctx,'0x000000000000000000000000000000000000000E',ctx.USDT.options.address,decimalStr("5"),mweiStr("10000"),"5");
|
||||
DPP_WETH_USDT = contracts.getContractWithAddress(contracts.DPP_NAME,dpp_WETH_USDT);
|
||||
console.log("dpp_DODO_USDT:",dpp_DODO_USDT);
|
||||
console.log("dpp_WETH_USDT:",dpp_WETH_USDT);
|
||||
});
|
||||
@@ -92,7 +98,7 @@ describe("DODOProxyV2.0", () => {
|
||||
var quoteToken = ctx.USDT.options.address;
|
||||
var baseAmount = decimalStr("10000");
|
||||
var quoteAmount = mweiStr("10000");
|
||||
await ctx.DODOProxy.methods.createDODOPrivatePool(
|
||||
await logGas(await ctx.DODOProxy.methods.createDODOPrivatePool(
|
||||
baseToken,
|
||||
quoteToken,
|
||||
baseAmount,
|
||||
@@ -102,7 +108,7 @@ describe("DODOProxyV2.0", () => {
|
||||
config.i,
|
||||
config.k,
|
||||
Math.floor(new Date().getTime()/1000 + 60 * 10)
|
||||
).send(ctx.sendParam(project));
|
||||
),ctx.sendParam(project),"createDPP");
|
||||
var addrs = await ctx.DPPFactory.methods.getPrivatePool(baseToken,quoteToken).call();
|
||||
var dppInfo = await ctx.DPPFactory.methods._DPP_INFO_(addrs[0]).call();
|
||||
assert.equal(
|
||||
@@ -123,9 +129,9 @@ describe("DODOProxyV2.0", () => {
|
||||
it("createDPP - ETH", async () => {
|
||||
var baseToken = '0x000000000000000000000000000000000000000E';
|
||||
var quoteToken = ctx.USDT.options.address;
|
||||
var baseAmount = decimalStr("10");
|
||||
var baseAmount = decimalStr("5");
|
||||
var quoteAmount = mweiStr("10000");
|
||||
await ctx.DODOProxy.methods.createDODOPrivatePool(
|
||||
await logGas(await ctx.DODOProxy.methods.createDODOPrivatePool(
|
||||
baseToken,
|
||||
quoteToken,
|
||||
baseAmount,
|
||||
@@ -135,7 +141,7 @@ describe("DODOProxyV2.0", () => {
|
||||
config.i,
|
||||
config.k,
|
||||
Math.floor(new Date().getTime()/1000 + 60 * 10)
|
||||
).send(ctx.sendParam(project, "10"));
|
||||
),ctx.sendParam(project, "5"),"createDPP - Wrap ETH");
|
||||
var addrs = await ctx.DPPFactory.methods.getPrivatePool(ctx.WETH.options.address,quoteToken).call();
|
||||
var dppInfo = await ctx.DPPFactory.methods._DPP_INFO_(addrs[0]).call();
|
||||
assert.equal(
|
||||
@@ -153,61 +159,56 @@ describe("DODOProxyV2.0", () => {
|
||||
});
|
||||
|
||||
it("resetDPP", async () => {
|
||||
// await ctx.DODOProxy.methods.resetDODOPrivatePool(
|
||||
// dpp_DODO_USDT,
|
||||
// config.lpFeeRate,
|
||||
// config.mtFeeRate,
|
||||
// config.i,
|
||||
// config.k,
|
||||
|
||||
// Math.floor(new Date().getTime()/1000 + 60 * 10)
|
||||
// ).send(ctx.sendParam(project, "10"));
|
||||
var beforeState = await DPP_DODO_USDT.methods.getPMMState().call();
|
||||
assert.equal(beforeState.K,config.k);
|
||||
assert.equal(beforeState.B0,decimalStr("10000"));
|
||||
assert.equal(beforeState.Q0,mweiStr("10000"));
|
||||
await logGas(await ctx.DODOProxy.methods.resetDODOPrivatePool(
|
||||
dpp_DODO_USDT,
|
||||
config.lpFeeRate,
|
||||
config.mtFeeRate,
|
||||
config.i,
|
||||
decimalStr("0.2"),
|
||||
decimalStr("1000"),
|
||||
mweiStr("1000"),
|
||||
decimalStr("0"),
|
||||
mweiStr("0"),
|
||||
Math.floor(new Date().getTime()/1000 + 60 * 10)
|
||||
),ctx.sendParam(project),"resetDPP");
|
||||
var afterState = await DPP_DODO_USDT.methods.getPMMState().call();
|
||||
assert.equal(afterState.K,decimalStr("0.2"));
|
||||
assert.equal(afterState.B0,decimalStr("11000"));
|
||||
assert.equal(afterState.Q0,mweiStr("11000"));
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* trade
|
||||
*/
|
||||
it("trade-sellQuote-R=1", async () => {
|
||||
//R变号与不变号
|
||||
it("resetDPP - OutETH", async () => {
|
||||
var beforeState = await DPP_WETH_USDT.methods.getPMMState().call();
|
||||
assert.equal(beforeState.K,config.k);
|
||||
assert.equal(beforeState.B0,decimalStr("5"));
|
||||
assert.equal(beforeState.Q0,mweiStr("10000"));
|
||||
var b_ETH = await ctx.Web3.eth.getBalance(project);
|
||||
var tx = await logGas(await ctx.DODOProxy.methods.resetDODOPrivatePoolETH(
|
||||
dpp_WETH_USDT,
|
||||
config.lpFeeRate,
|
||||
config.mtFeeRate,
|
||||
config.i,
|
||||
decimalStr("0.2"),
|
||||
decimalStr("0"),
|
||||
mweiStr("1000"),
|
||||
decimalStr("1"),
|
||||
mweiStr("0"),
|
||||
3,
|
||||
Math.floor(new Date().getTime()/1000 + 60 * 10)
|
||||
),ctx.sendParam(project),"resetDPP-ETH");
|
||||
var afterState = await DPP_WETH_USDT.methods.getPMMState().call();
|
||||
assert.equal(afterState.K,decimalStr("0.2"));
|
||||
assert.equal(afterState.B0,decimalStr("4"));
|
||||
assert.equal(afterState.Q0,mweiStr("11000"));
|
||||
var a_ETH = await ctx.Web3.eth.getBalance(project);
|
||||
console.log("b_ETH:",b_ETH);
|
||||
console.log("a_ETH:",a_ETH);
|
||||
assert.equal(new BigNumber(a_ETH).isGreaterThan(new BigNumber(b_ETH)),true);
|
||||
});
|
||||
|
||||
|
||||
it("trade-sellQuote-R>1", async () => {
|
||||
//R变号与不变号
|
||||
});
|
||||
|
||||
|
||||
it("trade-sellQuote-R<1", async () => {
|
||||
//R变号与不变号
|
||||
});
|
||||
|
||||
|
||||
it("trade-sellBase-R=1", async () => {
|
||||
//R变号与不变号
|
||||
});
|
||||
|
||||
|
||||
it("trade-sellBase-R>1", async () => {
|
||||
//R变号与不变号
|
||||
});
|
||||
|
||||
|
||||
it("trade-sellBase-R<1", async () => {
|
||||
//R变号与不变号
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("retrieve", async () => {
|
||||
//eth允许
|
||||
//控制无法提取base && quote
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* 直接底层dpp操作测试
|
||||
*/
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user