Merge branch 'feature/V2' of github.com:DODOEX/contractV2 into feature/V2
This commit is contained in:
@@ -74,24 +74,22 @@ contract CPFunding is CPStorage {
|
||||
address _poolBaseToken;
|
||||
address _poolQuoteToken;
|
||||
uint256 _poolI;
|
||||
if (poolQuote == baseDepth) {
|
||||
if (poolQuote.mul(_UNUSED_BASE_) == poolQuote.add(ownerQuote).mul(poolBase)) {
|
||||
_poolBaseToken = address(_BASE_TOKEN_);
|
||||
_poolQuoteToken = address(_QUOTE_TOKEN_);
|
||||
_poolI = 1;
|
||||
} else if (poolQuote < baseDepth) {
|
||||
// poolI round up
|
||||
} else if (poolQuote.mul(_UNUSED_BASE_) < poolQuote.add(ownerQuote).mul(poolBase)) {
|
||||
// poolI up round
|
||||
_poolBaseToken = address(_BASE_TOKEN_);
|
||||
_poolQuoteToken = address(_QUOTE_TOKEN_);
|
||||
uint256 ratio = DecimalMath.ONE.sub(DecimalMath.divFloor(poolQuote, baseDepth));
|
||||
_poolI = avgPrice.mul(ratio).mul(ratio).divCeil(DecimalMath.ONE2);
|
||||
} else if (poolQuote > baseDepth) {
|
||||
// poolI round down
|
||||
} else if (poolQuote.mul(_UNUSED_BASE_) > poolQuote.add(ownerQuote).mul(poolBase)) {
|
||||
// poolI down round
|
||||
_poolBaseToken = address(_QUOTE_TOKEN_);
|
||||
_poolQuoteToken = address(_BASE_TOKEN_);
|
||||
uint256 ratio = DecimalMath.ONE.sub(DecimalMath.divCeil(baseDepth, poolQuote));
|
||||
_poolI = DecimalMath.reciprocalFloor(avgPrice).mul(ratio).mul(ratio).div(
|
||||
DecimalMath.ONE2
|
||||
);
|
||||
_poolI = ratio.mul(ratio).div(avgPrice).div(DecimalMath.ONE2);
|
||||
}
|
||||
_POOL_ = IUnownedDVMFactory(_POOL_FACTORY_).createDODOVendingMachine(
|
||||
address(this),
|
||||
@@ -113,7 +111,7 @@ contract CPFunding is CPStorage {
|
||||
|
||||
// in case something wrong with base token contract
|
||||
function emergencySettle() external phaseSettlement preventReentrant {
|
||||
require(block.timestamp > _PHASE_CALM_ENDTIME_.add(_SETTLEMENT_EXPIRE_), "NOT_EMERGENCY");
|
||||
require(block.timestamp >= _PHASE_CALM_ENDTIME_.add(_SETTLEMENT_EXPIRE_), "NOT_EMERGENCY");
|
||||
_settle();
|
||||
_UNUSED_QUOTE_ = _QUOTE_TOKEN_.balanceOf(address(this));
|
||||
_UNUSED_BASE_ = _BASE_TOKEN_.balanceOf(address(this));
|
||||
|
||||
@@ -95,22 +95,26 @@ contract DPPAdmin is InitializableOwnable {
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount
|
||||
) external notFreezed {
|
||||
uint256 quoteOutAmount,
|
||||
uint256 minBaseReserve,
|
||||
uint256 minQuoteReserve
|
||||
) external notFreezed returns (bool) {
|
||||
require(
|
||||
msg.sender == _OWNER_ ||
|
||||
(msg.sender == IDODOApprove(_DODO_APPROVE_).getDODOProxy() &&
|
||||
operator == _OPERATOR_),
|
||||
"RESET FORBIDDEN!"
|
||||
);
|
||||
IDPP(_DPP_).reset(
|
||||
return IDPP(_DPP_).reset(
|
||||
msg.sender,
|
||||
newLpFeeRate,
|
||||
newMtFeeRate,
|
||||
newI,
|
||||
newK,
|
||||
baseOutAmount,
|
||||
quoteOutAmount
|
||||
quoteOutAmount,
|
||||
minBaseReserve,
|
||||
minQuoteReserve
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,15 @@ contract DPPTrader is DPPVault {
|
||||
address trader
|
||||
);
|
||||
|
||||
event DODOFlashLoan(
|
||||
address borrower,
|
||||
address assetTo,
|
||||
uint256 baseAmount,
|
||||
uint256 quoteAmount
|
||||
);
|
||||
|
||||
event RChange(PMMPricing.RState newRState);
|
||||
|
||||
// ============ Modifiers ============
|
||||
|
||||
modifier isBuyAllow(address trader) {
|
||||
@@ -70,6 +79,7 @@ contract DPPTrader is DPPVault {
|
||||
if (_RState_ != newRState) {
|
||||
_RState_ = newRState;
|
||||
_BASE_TARGET_ = newBaseTarget;
|
||||
emit RChange(newRState);
|
||||
}
|
||||
|
||||
emit DODOSwap(
|
||||
@@ -77,7 +87,7 @@ contract DPPTrader is DPPVault {
|
||||
address(_QUOTE_TOKEN_),
|
||||
baseInput,
|
||||
receiveQuoteAmount,
|
||||
tx.origin
|
||||
msg.sender
|
||||
);
|
||||
}
|
||||
|
||||
@@ -106,6 +116,7 @@ contract DPPTrader is DPPVault {
|
||||
if (_RState_ != newRState) {
|
||||
_RState_ = newRState;
|
||||
_QUOTE_TARGET_ = newQuoteTarget;
|
||||
emit RChange(newRState);
|
||||
}
|
||||
|
||||
emit DODOSwap(
|
||||
@@ -113,7 +124,7 @@ contract DPPTrader is DPPVault {
|
||||
address(_BASE_TOKEN_),
|
||||
quoteInput,
|
||||
receiveBaseAmount,
|
||||
tx.origin
|
||||
msg.sender
|
||||
);
|
||||
}
|
||||
|
||||
@@ -154,13 +165,14 @@ contract DPPTrader is DPPVault {
|
||||
if (_RState_ != newRState) {
|
||||
_RState_ = newRState;
|
||||
_QUOTE_TARGET_ = newQuoteTarget;
|
||||
emit RChange(newRState);
|
||||
}
|
||||
emit DODOSwap(
|
||||
address(_QUOTE_TOKEN_),
|
||||
address(_BASE_TOKEN_),
|
||||
quoteInput,
|
||||
receiveBaseAmount,
|
||||
tx.origin
|
||||
msg.sender
|
||||
);
|
||||
}
|
||||
|
||||
@@ -180,17 +192,20 @@ contract DPPTrader is DPPVault {
|
||||
if (_RState_ != newRState) {
|
||||
_RState_ = newRState;
|
||||
_BASE_TARGET_ = newBaseTarget;
|
||||
emit RChange(newRState);
|
||||
}
|
||||
emit DODOSwap(
|
||||
address(_BASE_TOKEN_),
|
||||
address(_QUOTE_TOKEN_),
|
||||
baseInput,
|
||||
receiveQuoteAmount,
|
||||
tx.origin
|
||||
msg.sender
|
||||
);
|
||||
}
|
||||
|
||||
_sync();
|
||||
|
||||
emit DODOFlashLoan(msg.sender, assetTo, baseAmount, quoteAmount);
|
||||
}
|
||||
|
||||
// ============ Query Functions ============
|
||||
|
||||
@@ -23,7 +23,10 @@ contract DPPVault is DPPStorage {
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event Reset();
|
||||
event Reset(
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate
|
||||
);
|
||||
|
||||
// ============ View Functions ============
|
||||
|
||||
@@ -32,6 +35,16 @@ contract DPPVault is DPPStorage {
|
||||
quoteReserve = _QUOTE_RESERVE_;
|
||||
}
|
||||
|
||||
function getUserFeeRate(address user) external view returns (uint256 lpFeeRate, uint256 mtFeeRate) {
|
||||
lpFeeRate = _LP_FEE_RATE_MODEL_.getFeeRate(user);
|
||||
mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(user);
|
||||
}
|
||||
|
||||
function getUserTradePermission(address user) external view returns (bool isBuyAllow, bool isSellAllow) {
|
||||
isBuyAllow = (!_BUYING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(user));
|
||||
isSellAllow = (!_SELLING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(user));
|
||||
}
|
||||
|
||||
// ============ Get Input ============
|
||||
|
||||
function getBaseInput() public view returns (uint256 input) {
|
||||
@@ -65,8 +78,11 @@ contract DPPVault is DPPStorage {
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount
|
||||
) public preventReentrant onlyOwner {
|
||||
uint256 quoteOutAmount,
|
||||
uint256 minBaseReserve,
|
||||
uint256 minQuoteReserve
|
||||
) public preventReentrant onlyOwner returns (bool) {
|
||||
require(_BASE_RESERVE_ >= minBaseReserve && _QUOTE_RESERVE_ >= minQuoteReserve, "Reserve amount is not enough");
|
||||
_LP_FEE_RATE_MODEL_.setFeeRate(newLpFeeRate);
|
||||
_MT_FEE_RATE_MODEL_.setFeeRate(newMtFeeRate);
|
||||
_I_.set(newI);
|
||||
@@ -75,7 +91,8 @@ contract DPPVault is DPPStorage {
|
||||
_transferQuoteOut(assetTo, quoteOutAmount);
|
||||
_resetTargetAndReserve();
|
||||
_checkIK();
|
||||
emit Reset();
|
||||
emit Reset(newLpFeeRate, newMtFeeRate);
|
||||
return true;
|
||||
}
|
||||
|
||||
function _setRState() internal {
|
||||
|
||||
@@ -60,6 +60,8 @@ interface IDPP {
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount
|
||||
) external;
|
||||
uint256 quoteOutAmount,
|
||||
uint256 minBaseReserve,
|
||||
uint256 minQuoteReserve
|
||||
) external returns (bool);
|
||||
}
|
||||
|
||||
@@ -15,12 +15,6 @@ import {IExternalValue} from "../../lib/ExternalValue.sol";
|
||||
contract DVMAdmin is InitializableOwnable {
|
||||
address public _DVM_;
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event SetLpFeeRate(uint256 newLpFeeRate);
|
||||
|
||||
event SetMtFeeRate(uint256 newMtFeeRate);
|
||||
|
||||
function init(address owner, address dvm) external {
|
||||
initOwner(owner);
|
||||
_DVM_ = dvm;
|
||||
@@ -31,8 +25,7 @@ contract DVMAdmin is InitializableOwnable {
|
||||
// }
|
||||
|
||||
function setLpFeeRateValue(uint256 newLpFeeRate) external onlyOwner {
|
||||
IExternalValue(IDVM(_DVM_)._LP_FEE_RATE_MODEL_()).set(newLpFeeRate);
|
||||
emit SetLpFeeRate(newLpFeeRate);
|
||||
IDVM(_DVM_).setLpFeeRateValue(newLpFeeRate);
|
||||
}
|
||||
|
||||
// function setMtFeeRateModel(address newMtFeeRateModel) external onlyOwner {
|
||||
@@ -40,8 +33,7 @@ contract DVMAdmin is InitializableOwnable {
|
||||
// }
|
||||
|
||||
function setMtFeeRateValue(uint256 newMtFeeRate) external onlyOwner {
|
||||
IExternalValue(IDVM(_DVM_)._MT_FEE_RATE_MODEL_()).set(newMtFeeRate);
|
||||
emit SetMtFeeRate(newMtFeeRate);
|
||||
IDVM(_DVM_).setMtFeeRateValue(newMtFeeRate);
|
||||
}
|
||||
|
||||
// function setTradePermissionManager(address newTradePermissionManager) external onlyOwner {
|
||||
|
||||
@@ -15,14 +15,9 @@ import {IDODOCallee} from "../../intf/IDODOCallee.sol";
|
||||
contract DVMFunding is DVMVault {
|
||||
// ============ Events ============
|
||||
|
||||
event BuyShares(address indexed to, uint256 increaseShares, uint256 totalShares);
|
||||
event BuyShares(address to, uint256 increaseShares, uint256 totalShares);
|
||||
|
||||
event SellShares(
|
||||
address indexed payer,
|
||||
address indexed to,
|
||||
uint256 decreaseShares,
|
||||
uint256 totalShares
|
||||
);
|
||||
event SellShares(address payer, address to, uint256 decreaseShares, uint256 totalShares);
|
||||
|
||||
// ============ Buy & Sell Shares ============
|
||||
|
||||
@@ -50,8 +45,8 @@ contract DVMFunding is DVMVault {
|
||||
// 在提币的时候向下取整。因此永远不会出现,balance为0但totalsupply不为0的情况
|
||||
// 但有可能出现,reserve>0但totalSupply=0的场景
|
||||
if (totalSupply == 0) {
|
||||
require(baseBalance >= 10**3); // 以免出现balance很大但shares很小的情况
|
||||
shares = baseBalance;
|
||||
require(baseBalance >= 10**3, "INSUFFICIENT_LIQUIDITY_MINED");
|
||||
shares = baseBalance; // 以免出现balance很大但shares很小的情况
|
||||
} else if (baseReserve > 0 && quoteReserve == 0) {
|
||||
// case 2. supply when quote reserve is 0
|
||||
shares = baseInput.mul(totalSupply).div(baseReserve);
|
||||
@@ -62,7 +57,6 @@ contract DVMFunding is DVMVault {
|
||||
uint256 mintRatio = quoteInputRatio < baseInputRatio ? quoteInputRatio : baseInputRatio;
|
||||
shares = DecimalMath.mulFloor(totalSupply, mintRatio);
|
||||
}
|
||||
require(shares > 0, "INSUFFICIENT_LIQUIDITY_MINED");
|
||||
_mint(to, shares);
|
||||
_sync();
|
||||
emit BuyShares(to, shares, _SHARES_[to]);
|
||||
|
||||
@@ -80,6 +80,10 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
||||
|
||||
event SetSell(bool allow);
|
||||
|
||||
event SetLpFeeRate(uint256 newValue);
|
||||
|
||||
event SetMtFeeRate(uint256 newValue);
|
||||
|
||||
// ============ Setting Functions ============
|
||||
|
||||
function setLpFeeRateModel(address newLpFeeRateModel) external onlyOwner {
|
||||
@@ -92,6 +96,16 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
||||
_MT_FEE_RATE_MODEL_ = IFeeRateModel(newMtFeeRateModel);
|
||||
}
|
||||
|
||||
function setLpFeeRateValue(uint256 newLpFeeRate) external onlyOwner {
|
||||
_LP_FEE_RATE_MODEL_.setFeeRate(newLpFeeRate);
|
||||
emit SetLpFeeRate(newLpFeeRate);
|
||||
}
|
||||
|
||||
function setMtFeeRateValue(uint256 newMtFeeRate) external onlyOwner {
|
||||
_MT_FEE_RATE_MODEL_.setFeeRate(newMtFeeRate);
|
||||
emit SetMtFeeRate(newMtFeeRate);
|
||||
}
|
||||
|
||||
function setTradePermissionManager(address newTradePermissionManager) external onlyOwner {
|
||||
emit SetTradePermissionManager(address(_TRADE_PERMISSION_), newTradePermissionManager);
|
||||
_TRADE_PERMISSION_ = IPermissionManager(newTradePermissionManager);
|
||||
|
||||
@@ -28,6 +28,13 @@ contract DVMTrader is DVMVault {
|
||||
address trader
|
||||
);
|
||||
|
||||
event DODOFlashLoan(
|
||||
address borrower,
|
||||
address assetTo,
|
||||
uint256 baseAmount,
|
||||
uint256 quoteAmount
|
||||
);
|
||||
|
||||
// ============ Modifiers ============
|
||||
|
||||
modifier isBuyAllow(address trader) {
|
||||
@@ -70,7 +77,7 @@ contract DVMTrader is DVMVault {
|
||||
address(_QUOTE_TOKEN_),
|
||||
baseInput,
|
||||
receiveQuoteAmount,
|
||||
tx.origin
|
||||
msg.sender
|
||||
);
|
||||
}
|
||||
|
||||
@@ -94,7 +101,7 @@ contract DVMTrader is DVMVault {
|
||||
address(_BASE_TOKEN_),
|
||||
quoteInput,
|
||||
receiveBaseAmount,
|
||||
tx.origin
|
||||
msg.sender
|
||||
);
|
||||
}
|
||||
|
||||
@@ -112,7 +119,7 @@ contract DVMTrader is DVMVault {
|
||||
|
||||
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
|
||||
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
|
||||
|
||||
|
||||
// no input -> pure loss
|
||||
require(
|
||||
baseBalance >= _BASE_RESERVE_ || quoteBalance >= _QUOTE_RESERVE_,
|
||||
@@ -147,11 +154,13 @@ contract DVMTrader is DVMVault {
|
||||
address(_QUOTE_TOKEN_),
|
||||
baseInput,
|
||||
receiveQuoteAmount,
|
||||
tx.origin
|
||||
msg.sender
|
||||
);
|
||||
}
|
||||
|
||||
_sync();
|
||||
|
||||
emit DODOFlashLoan(msg.sender, assetTo, baseAmount, quoteAmount);
|
||||
}
|
||||
|
||||
// ============ Query Functions ============
|
||||
|
||||
@@ -35,6 +35,16 @@ contract DVMVault is DVMStorage {
|
||||
quoteReserve = _QUOTE_RESERVE_;
|
||||
}
|
||||
|
||||
function getUserFeeRate(address user) external view returns (uint256 lpFeeRate, uint256 mtFeeRate) {
|
||||
lpFeeRate = _LP_FEE_RATE_MODEL_.getFeeRate(user);
|
||||
mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(user);
|
||||
}
|
||||
|
||||
function getUserTradePermission(address user) external view returns (bool isBuyAllow, bool isSellAllow) {
|
||||
isBuyAllow = (!_BUYING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(user));
|
||||
isSellAllow = (!_SELLING_CLOSE_ && _TRADE_PERMISSION_.isAllowed(user));
|
||||
}
|
||||
|
||||
// ============ Asset In ============
|
||||
|
||||
function getBaseInput() public view returns (uint256 input) {
|
||||
|
||||
@@ -41,7 +41,11 @@ interface IDVM {
|
||||
//=========== admin ==========
|
||||
function setLpFeeRateModel(address newLpFeeRateModel) external;
|
||||
|
||||
function setLpFeeRateValue(uint256 newLpFeeRate) external;
|
||||
|
||||
function setMtFeeRateModel(address newMtFeeRateModel) external;
|
||||
|
||||
function setMtFeeRateValue(uint256 newMtFeeRate) external;
|
||||
|
||||
function setTradePermissionManager(address newTradePermissionManager) external;
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ contract CrowdPoolingFactory {
|
||||
// ============ Events ============
|
||||
|
||||
event NewCP(
|
||||
address indexed baseToken,
|
||||
address indexed quoteToken,
|
||||
address indexed creator,
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address creator,
|
||||
address cp
|
||||
);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "../lib/Ownable.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
import {ICloneFactory} from "../lib/CloneFactory.sol";
|
||||
import {IFeeRateModel} from "../lib/FeeRateModel.sol";
|
||||
import {IExternalValue} from "../lib/ExternalValue.sol";
|
||||
@@ -16,7 +16,7 @@ import {IDPP} from "../DODOPrivatePool/intf/IDPP.sol";
|
||||
import {IDPPAdmin} from "../DODOPrivatePool/intf/IDPPAdmin.sol";
|
||||
import {IPermissionManager} from "../lib/PermissionManager.sol";
|
||||
|
||||
contract DPPFactory is Ownable {
|
||||
contract DPPFactory is InitializableOwnable {
|
||||
// ============ Templates ============
|
||||
|
||||
address public immutable _CLONE_FACTORY_;
|
||||
@@ -38,9 +38,9 @@ contract DPPFactory is Ownable {
|
||||
// ============ Events ============
|
||||
|
||||
event NewDPP(
|
||||
address indexed baseToken,
|
||||
address indexed quoteToken,
|
||||
address indexed creator,
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address creator,
|
||||
address dpp
|
||||
);
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "../lib/Ownable.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
import {ICloneFactory} from "../lib/CloneFactory.sol";
|
||||
import {IConstFeeRateModel} from "../lib/ConstFeeRateModel.sol";
|
||||
import {IFeeRateModel} from "../lib/FeeRateModel.sol";
|
||||
import {IDVM} from "../DODOVendingMachine/intf/IDVM.sol";
|
||||
import {IDVMAdmin} from "../DODOVendingMachine/intf/IDVMAdmin.sol";
|
||||
import {IPermissionManager} from "../lib/PermissionManager.sol";
|
||||
@@ -27,7 +27,7 @@ interface IDVMFactory {
|
||||
) external returns (address newVendingMachine);
|
||||
}
|
||||
|
||||
contract DVMFactory is Ownable {
|
||||
contract DVMFactory is InitializableOwnable {
|
||||
// ============ Templates ============
|
||||
|
||||
address public immutable _CLONE_FACTORY_;
|
||||
@@ -47,9 +47,9 @@ contract DVMFactory is Ownable {
|
||||
// ============ Events ============
|
||||
|
||||
event NewDVM(
|
||||
address indexed baseToken,
|
||||
address indexed quoteToken,
|
||||
address indexed creator,
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address creator,
|
||||
address dvm
|
||||
);
|
||||
|
||||
@@ -106,7 +106,7 @@ contract DVMFactory is Ownable {
|
||||
returns (address feeRateModel)
|
||||
{
|
||||
feeRateModel = ICloneFactory(_CLONE_FACTORY_).clone(_FEE_RATE_MODEL_TEMPLATE_);
|
||||
IConstFeeRateModel(feeRateModel).init(owner, feeRate);
|
||||
IFeeRateModel(feeRateModel).init(owner, feeRate);
|
||||
}
|
||||
|
||||
function _createPermissionManager(address owner) internal returns (address permissionManager) {
|
||||
|
||||
@@ -8,16 +8,11 @@
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "../lib/Ownable.sol";
|
||||
import {ICloneFactory} from "../lib/CloneFactory.sol";
|
||||
import {IConstFeeRateModel} from "../lib/ConstFeeRateModel.sol";
|
||||
import {IDVM} from "../DODOVendingMachine/intf/IDVM.sol";
|
||||
import {IDVMAdmin} from "../DODOVendingMachine/intf/IDVMAdmin.sol";
|
||||
import {IPermissionManager} from "../lib/PermissionManager.sol";
|
||||
import {InitializableERC20} from "../external/ERC20/InitializableERC20.sol";
|
||||
import {InitializableMintableERC20} from "../external/ERC20/InitializableMintableERC20.sol";
|
||||
|
||||
contract ERC20Factory is Ownable {
|
||||
contract ERC20Factory {
|
||||
// ============ Templates ============
|
||||
|
||||
address public immutable _CLONE_FACTORY_;
|
||||
@@ -26,7 +21,7 @@ contract ERC20Factory is Ownable {
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event NewERC20(address indexed erc20, address indexed creator, bool isMintable);
|
||||
event NewERC20(address erc20, address creator, bool isMintable);
|
||||
|
||||
// ============ Functions ============
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "../lib/Ownable.sol";
|
||||
import {ICloneFactory} from "../lib/CloneFactory.sol";
|
||||
import {IConstFeeRateModel} from "../lib/ConstFeeRateModel.sol";
|
||||
import {IFeeRateModel} from "../lib/FeeRateModel.sol";
|
||||
import {IDVM} from "../DODOVendingMachine/intf/IDVM.sol";
|
||||
import {IDVMAdmin} from "../DODOVendingMachine/intf/IDVMAdmin.sol";
|
||||
import {IPermissionManager} from "../lib/PermissionManager.sol";
|
||||
@@ -49,10 +49,10 @@ contract UnownedDVMFactory {
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event NewDVM(
|
||||
address indexed baseToken,
|
||||
address indexed quoteToken,
|
||||
address indexed creator,
|
||||
event NewUnOwnedDVM(
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address creator,
|
||||
address dvm
|
||||
);
|
||||
|
||||
@@ -102,7 +102,7 @@ contract UnownedDVMFactory {
|
||||
}
|
||||
_REGISTRY_[baseToken][quoteToken].push(newVendingMachine);
|
||||
_USER_REGISTRY_[creator].push(newVendingMachine);
|
||||
emit NewDVM(baseToken, quoteToken, creator, newVendingMachine);
|
||||
emit NewUnOwnedDVM(baseToken, quoteToken, creator, newVendingMachine);
|
||||
}
|
||||
|
||||
function _createFeeRateModel(address owner, uint256 feeRate)
|
||||
@@ -110,7 +110,7 @@ contract UnownedDVMFactory {
|
||||
returns (address feeRateModel)
|
||||
{
|
||||
feeRateModel = ICloneFactory(_CLONE_FACTORY_).clone(_FEE_RATE_MODEL_TEMPLATE_);
|
||||
IConstFeeRateModel(feeRateModel).init(owner, feeRate);
|
||||
IFeeRateModel(feeRateModel).init(owner, feeRate);
|
||||
}
|
||||
|
||||
// ============ View Functions ============
|
||||
|
||||
@@ -40,11 +40,12 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
// ============ Events ============
|
||||
|
||||
event OrderHistory(
|
||||
address indexed fromToken,
|
||||
address indexed toToken,
|
||||
address indexed sender,
|
||||
address fromToken,
|
||||
address toToken,
|
||||
address sender,
|
||||
uint256 fromAmount,
|
||||
uint256 returnAmount
|
||||
uint256 returnAmount,
|
||||
uint8 sourceFlag
|
||||
);
|
||||
|
||||
// ============ Modifiers ============
|
||||
@@ -257,44 +258,42 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
|
||||
function resetDODOPrivatePool(
|
||||
address dppAddress,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseInAmount,
|
||||
uint256 quoteInAmount,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount,
|
||||
uint256[] memory paramList, //0 - newLpFeeRate, 1 - newMtFeeRate, 2 - newI, 3 - newK
|
||||
uint256[] memory amountList, //0 - baseInAmount, 1 - quoteInAmount, 2 - baseOutAmount, 3- quoteOutAmount
|
||||
uint8 flag, // 0 - ERC20, 1 - baseInETH, 2 - quoteInETH, 3 - baseOutETH, 4 - quoteOutETH
|
||||
uint256 minBaseReserve,
|
||||
uint256 minQuoteReserve,
|
||||
uint256 deadLine
|
||||
) external override payable preventReentrant judgeExpired(deadLine) {
|
||||
_deposit(
|
||||
msg.sender,
|
||||
dppAddress,
|
||||
IDODOV2(dppAddress)._BASE_TOKEN_(),
|
||||
baseInAmount,
|
||||
amountList[0],
|
||||
flag == 1
|
||||
);
|
||||
_deposit(
|
||||
msg.sender,
|
||||
dppAddress,
|
||||
IDODOV2(dppAddress)._QUOTE_TOKEN_(),
|
||||
quoteInAmount,
|
||||
amountList[1],
|
||||
flag == 2
|
||||
);
|
||||
|
||||
IDODOV2(IDODOV2(dppAddress)._OWNER_()).reset(
|
||||
require(IDODOV2(IDODOV2(dppAddress)._OWNER_()).reset(
|
||||
msg.sender,
|
||||
newLpFeeRate,
|
||||
newMtFeeRate,
|
||||
newI,
|
||||
newK,
|
||||
baseOutAmount,
|
||||
quoteOutAmount
|
||||
);
|
||||
paramList[0],
|
||||
paramList[1],
|
||||
paramList[2],
|
||||
paramList[3],
|
||||
amountList[2],
|
||||
amountList[3],
|
||||
minBaseReserve,
|
||||
minQuoteReserve
|
||||
), "Reset Failed");
|
||||
|
||||
_withdraw(msg.sender, IDODOV2(dppAddress)._BASE_TOKEN_(), baseOutAmount, flag == 3);
|
||||
_withdraw(msg.sender, IDODOV2(dppAddress)._QUOTE_TOKEN_(), quoteOutAmount, flag == 4);
|
||||
_withdraw(msg.sender, IDODOV2(dppAddress)._BASE_TOKEN_(), amountList[2], flag == 3);
|
||||
_withdraw(msg.sender, IDODOV2(dppAddress)._QUOTE_TOKEN_(), amountList[3], flag == 4);
|
||||
}
|
||||
|
||||
// ============ Swap ============
|
||||
@@ -342,7 +341,8 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
toToken,
|
||||
assetTo,
|
||||
msg.value,
|
||||
returnAmount
|
||||
returnAmount,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -387,7 +387,8 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
_ETH_ADDRESS_,
|
||||
assetTo,
|
||||
fromTokenAmount,
|
||||
returnAmount
|
||||
returnAmount,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -432,7 +433,8 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
toToken,
|
||||
assetTo,
|
||||
fromTokenAmount,
|
||||
returnAmount
|
||||
returnAmount,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -487,7 +489,8 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
toToken,
|
||||
msg.sender,
|
||||
fromTokenAmount,
|
||||
returnAmount
|
||||
returnAmount,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
@@ -538,7 +541,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
require(returnAmount >= minReturnAmount, "DODOV2Proxy01: Return amount is not enough");
|
||||
IERC20(toToken).universalTransfer(msg.sender, returnAmount);
|
||||
|
||||
emit OrderHistory(fromToken, toToken, msg.sender, fromTokenAmount, returnAmount);
|
||||
emit OrderHistory(fromToken, toToken, msg.sender, fromTokenAmount, returnAmount, 1);
|
||||
}
|
||||
|
||||
function mixSwapV1(
|
||||
@@ -594,7 +597,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, InitializableOwnable
|
||||
returnAmount = IERC20(_toToken).universalBalanceOf(msg.sender).sub(toTokenOriginBalance);
|
||||
require(returnAmount >= minReturnAmount, "DODOV2Proxy01: Return amount is not enough");
|
||||
|
||||
emit OrderHistory(_fromToken, _toToken, msg.sender, fromTokenAmount, returnAmount);
|
||||
emit OrderHistory(_fromToken, _toToken, msg.sender, fromTokenAmount, returnAmount, 2);
|
||||
}
|
||||
|
||||
//============ CrowdPooling Functions (create & bid) ============
|
||||
|
||||
@@ -21,9 +21,10 @@ contract DODOSwapCalcHelper {
|
||||
uint256 fromTokenAmount,
|
||||
address[] memory dodoPairs,
|
||||
uint8[] memory directions
|
||||
) external view returns (uint256 returnAmount,uint256[] memory midPrices) {
|
||||
) external view returns (uint256 returnAmount,uint256[] memory midPrices,uint256[] memory feeRates) {
|
||||
returnAmount = fromTokenAmount;
|
||||
midPrices = new uint256[](dodoPairs.length);
|
||||
feeRates = new uint256[](dodoPairs.length);
|
||||
for (uint256 i = 0; i < dodoPairs.length; i++) {
|
||||
address curDodoPair = dodoPairs[i];
|
||||
if (directions[i] == 0) {
|
||||
@@ -35,6 +36,7 @@ contract DODOSwapCalcHelper {
|
||||
);
|
||||
}
|
||||
midPrices[i] = IDODOV1(curDodoPair).getMidPrice();
|
||||
feeRates[i] = IDODOV1(curDodoPair)._MT_FEE_RATE_() + IDODOV1(curDodoPair)._LP_FEE_RATE_();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,8 +61,10 @@ interface IDODOV2 {
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount
|
||||
) external;
|
||||
uint256 quoteOutAmount,
|
||||
uint256 minBaseReserve,
|
||||
uint256 minQuoteReserve
|
||||
) external returns (bool);
|
||||
|
||||
//========== CrowdPooling ===========
|
||||
|
||||
|
||||
@@ -86,15 +86,11 @@ interface IDODOV2Proxy01 is IDODOV1Proxy01 {
|
||||
|
||||
function resetDODOPrivatePool(
|
||||
address dppAddress,
|
||||
uint256 newLpFeeRate,
|
||||
uint256 newMtFeeRate,
|
||||
uint256 newI,
|
||||
uint256 newK,
|
||||
uint256 baseInAmount,
|
||||
uint256 quoteInAmount,
|
||||
uint256 baseOutAmount,
|
||||
uint256 quoteOutAmount,
|
||||
uint256[] memory paramList, //0 - newLpFeeRate, 1 - newMtFeeRate, 2 - newI, 3 - newK
|
||||
uint256[] memory amountList, //0 - baseInAmount, 1 - quoteInAmount, 2 - baseOutAmount, 3 - quoteOutAmount
|
||||
uint8 flag, // 0 - ERC20, 1 - baseInETH, 2 - quoteInETH, 3 - baseOutETH, 4 - quoteOutETH
|
||||
uint256 minBaseReserve,
|
||||
uint256 minQuoteReserve,
|
||||
uint256 deadLine
|
||||
) external payable;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import {InitializableOwnable} from "./InitializableOwnable.sol";
|
||||
interface IPermissionManager {
|
||||
function initOwner(address) external;
|
||||
|
||||
function isAllowed(address) external returns (bool);
|
||||
function isAllowed(address) external view returns (bool);
|
||||
}
|
||||
|
||||
contract PermissionManager is InitializableOwnable {
|
||||
|
||||
Reference in New Issue
Block a user