2020-10-23 01:16:52 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
Copyright 2020 DODO ZOO.
|
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
pragma solidity 0.6.9;
|
|
|
|
|
pragma experimental ABIEncoderV2;
|
2020-11-23 10:43:12 +08:00
|
|
|
|
|
|
|
|
import {IFeeRateModel} from "../../lib/FeeRateModel.sol";
|
2020-11-18 17:51:50 +08:00
|
|
|
import {IERC20} from "../../intf/IERC20.sol";
|
2020-10-23 01:16:52 +08:00
|
|
|
import {DVMTrader} from "./DVMTrader.sol";
|
|
|
|
|
import {DVMFunding} from "./DVMFunding.sol";
|
|
|
|
|
import {DVMVault} from "./DVMVault.sol";
|
|
|
|
|
|
2021-01-08 17:19:23 +08:00
|
|
|
/**
|
|
|
|
|
* @title DODO VendingMachine
|
|
|
|
|
* @author DODO Breeder
|
|
|
|
|
*
|
|
|
|
|
* @notice DODOVendingMachine initialization
|
|
|
|
|
*/
|
2020-11-05 00:26:45 +08:00
|
|
|
contract DVM is DVMTrader, DVMFunding {
|
2020-10-23 01:16:52 +08:00
|
|
|
function init(
|
|
|
|
|
address maintainer,
|
2020-11-18 17:51:50 +08:00
|
|
|
address baseTokenAddress,
|
|
|
|
|
address quoteTokenAddress,
|
2020-12-30 12:23:52 +08:00
|
|
|
uint256 lpFeeRate,
|
2020-10-23 01:16:52 +08:00
|
|
|
address mtFeeRateModel,
|
|
|
|
|
uint256 i,
|
2021-01-19 17:10:46 +08:00
|
|
|
uint256 k,
|
|
|
|
|
bool isOpenTWAP
|
2020-10-23 01:16:52 +08:00
|
|
|
) external {
|
2021-03-09 15:43:02 +08:00
|
|
|
require(!_DVM_INITIALIZED_, "DVM_INITIALIZED");
|
|
|
|
|
_DVM_INITIALIZED_ = true;
|
|
|
|
|
|
2020-11-29 17:38:13 +08:00
|
|
|
require(baseTokenAddress != quoteTokenAddress, "BASE_QUOTE_CAN_NOT_BE_SAME");
|
2020-11-18 17:51:50 +08:00
|
|
|
_BASE_TOKEN_ = IERC20(baseTokenAddress);
|
|
|
|
|
_QUOTE_TOKEN_ = IERC20(quoteTokenAddress);
|
2020-11-28 17:44:39 +08:00
|
|
|
|
|
|
|
|
require(i > 0 && i <= 10**36);
|
2020-10-23 01:16:52 +08:00
|
|
|
_I_ = i;
|
2020-11-23 21:26:18 +08:00
|
|
|
|
2020-12-01 00:02:33 +08:00
|
|
|
require(k <= 10**18);
|
2020-10-23 01:16:52 +08:00
|
|
|
_K_ = k;
|
2020-11-18 17:51:50 +08:00
|
|
|
|
2020-12-30 12:23:52 +08:00
|
|
|
_LP_FEE_RATE_ = lpFeeRate;
|
2020-11-29 17:38:13 +08:00
|
|
|
_MT_FEE_RATE_MODEL_ = IFeeRateModel(mtFeeRateModel);
|
|
|
|
|
_MAINTAINER_ = maintainer;
|
|
|
|
|
|
2021-01-19 17:10:46 +08:00
|
|
|
_IS_OPEN_TWAP_ = isOpenTWAP;
|
|
|
|
|
if(isOpenTWAP) _BLOCK_TIMESTAMP_LAST_ = uint32(block.timestamp % 2**32);
|
|
|
|
|
|
2020-11-18 17:51:50 +08:00
|
|
|
string memory connect = "_";
|
|
|
|
|
string memory suffix = "DLP";
|
2020-11-28 17:44:39 +08:00
|
|
|
|
2020-11-29 17:38:13 +08:00
|
|
|
name = string(abi.encodePacked(suffix, connect, addressToShortString(address(this))));
|
2020-11-18 17:51:50 +08:00
|
|
|
symbol = "DLP";
|
|
|
|
|
decimals = _BASE_TOKEN_.decimals();
|
2020-11-29 23:40:19 +08:00
|
|
|
|
|
|
|
|
// ============================== Permit ====================================
|
|
|
|
|
uint256 chainId;
|
|
|
|
|
assembly {
|
|
|
|
|
chainId := chainid()
|
|
|
|
|
}
|
|
|
|
|
DOMAIN_SEPARATOR = keccak256(
|
|
|
|
|
abi.encode(
|
|
|
|
|
// keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
|
|
|
|
|
0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f,
|
|
|
|
|
keccak256(bytes(name)),
|
2020-12-01 00:02:33 +08:00
|
|
|
keccak256(bytes("1")),
|
2020-11-29 23:40:19 +08:00
|
|
|
chainId,
|
|
|
|
|
address(this)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
// ==========================================================================
|
2020-11-05 00:26:45 +08:00
|
|
|
}
|
|
|
|
|
|
2020-11-29 17:38:13 +08:00
|
|
|
function addressToShortString(address _addr) public pure returns (string memory) {
|
|
|
|
|
bytes32 value = bytes32(uint256(_addr));
|
|
|
|
|
bytes memory alphabet = "0123456789abcdef";
|
|
|
|
|
|
|
|
|
|
bytes memory str = new bytes(8);
|
|
|
|
|
for (uint256 i = 0; i < 4; i++) {
|
|
|
|
|
str[i * 2] = alphabet[uint8(value[i + 12] >> 4)];
|
|
|
|
|
str[1 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)];
|
|
|
|
|
}
|
|
|
|
|
return string(str);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 00:26:45 +08:00
|
|
|
// ============ Version Control ============
|
2021-01-08 17:19:23 +08:00
|
|
|
|
2020-11-29 17:38:13 +08:00
|
|
|
function version() external pure returns (string memory) {
|
2021-03-14 16:49:33 +08:00
|
|
|
return "DVM 1.0.2";
|
2020-10-23 01:16:52 +08:00
|
|
|
}
|
|
|
|
|
}
|