init dvm context
This commit is contained in:
@@ -53,9 +53,11 @@ contract SmartRoute is Ownable {
|
|||||||
|
|
||||||
function depositToDVM(
|
function depositToDVM(
|
||||||
address DVM,
|
address DVM,
|
||||||
|
address to,
|
||||||
uint256 baseAmount,
|
uint256 baseAmount,
|
||||||
uint256 quoteAmount
|
uint256 quoteAmount
|
||||||
) public returns (uint256 shares) {
|
) public returns (uint256 shares) {
|
||||||
|
address vault = address(DVMController(DVM)._VAULT_());
|
||||||
uint256 adjustedBaseAmount;
|
uint256 adjustedBaseAmount;
|
||||||
uint256 adjustedQuoteAmount;
|
uint256 adjustedQuoteAmount;
|
||||||
(uint256 baseReserve, uint256 quoteReserve) = DVMController(DVM)
|
(uint256 baseReserve, uint256 quoteReserve) = DVMController(DVM)
|
||||||
@@ -75,9 +77,26 @@ contract SmartRoute is Ownable {
|
|||||||
if (quoteReserve > 0 && baseReserve > 0) {
|
if (quoteReserve > 0 && baseReserve > 0) {
|
||||||
uint256 baseIncreaseRatio = DecimalMath.divFloor(baseAmount, baseReserve);
|
uint256 baseIncreaseRatio = DecimalMath.divFloor(baseAmount, baseReserve);
|
||||||
uint256 quoteIncreaseRatio = DecimalMath.divFloor(quoteAmount, quoteReserve);
|
uint256 quoteIncreaseRatio = DecimalMath.divFloor(quoteAmount, quoteReserve);
|
||||||
uint256 increaseRatio = baseIncreaseRatio>quoteIncreaseRatio?quoteIncreaseRatio:baseIncreaseRatio
|
if (baseIncreaseRatio <= quoteIncreaseRatio) {
|
||||||
adjustedBaseAmount = baseAmount;
|
adjustedBaseAmount = baseAmount;
|
||||||
adjustedQuoteAmount = 0;
|
adjustedQuoteAmount = DecimalMath.mulFloor(quoteReserve, baseIncreaseRatio);
|
||||||
|
} else {
|
||||||
|
adjustedQuoteAmount = quoteAmount;
|
||||||
|
adjustedBaseAmount = DecimalMath.mulFloor(baseReserve, quoteIncreaseRatio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IERC20(DVMController(DVM)._BASE_TOKEN_()).safeTransferFrom(
|
||||||
|
msg.sender,
|
||||||
|
vault,
|
||||||
|
adjustedBaseAmount
|
||||||
|
);
|
||||||
|
IERC20(DVMController(DVM)._QUOTE_TOKEN_()).safeTransferFrom(
|
||||||
|
msg.sender,
|
||||||
|
vault,
|
||||||
|
adjustedQuoteAmount
|
||||||
|
);
|
||||||
|
|
||||||
|
return DVMController(DVM).buyShares(to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pragma experimental ABIEncoderV2;
|
|||||||
import {IFeeRateModel} from "../intf/IFeeRateModel.sol";
|
import {IFeeRateModel} from "../intf/IFeeRateModel.sol";
|
||||||
import {Ownable} from "../lib/Ownable.sol";
|
import {Ownable} from "../lib/Ownable.sol";
|
||||||
|
|
||||||
contract ConstFeeRateModel is Ownable, IFeeRateModel {
|
contract NaiveFeeRateModel is Ownable, IFeeRateModel {
|
||||||
uint256 public _FEE_RATE_;
|
uint256 public _FEE_RATE_;
|
||||||
|
|
||||||
constructor(uint256 feeRate) public {
|
constructor(uint256 feeRate) public {
|
||||||
|
|||||||
@@ -13,6 +13,27 @@ if (process.env["COVERAGE"]) {
|
|||||||
import { getDefaultWeb3 } from './EVM';
|
import { getDefaultWeb3 } from './EVM';
|
||||||
import { Contract } from 'web3-eth-contract';
|
import { Contract } from 'web3-eth-contract';
|
||||||
|
|
||||||
|
export const CLONE_FACTORY_CONTRACT_NAME = "CloneFactory"
|
||||||
|
export const DODO_CONTRACT_NAME = "DODO"
|
||||||
|
export const TEST_ERC20_CONTRACT_NAME = "TestERC20"
|
||||||
|
export const NAIVE_ORACLE_CONTRACT_NAME = "NaiveOracle"
|
||||||
|
export const DODO_LP_TOKEN_CONTRACT_NAME = "DODOLpToken"
|
||||||
|
export const DODO_ZOO_CONTRACT_NAME = "DOOZoo"
|
||||||
|
export const DODO_WILD_CONTRACT_NAME = "DOOWild"
|
||||||
|
export const DODO_ETH_PROXY_CONTRACT_NAME = "DODOEthProxy"
|
||||||
|
export const WETH_CONTRACT_NAME = "WETH"
|
||||||
|
export const UNISWAP_CONTRACT_NAME = "Uniswap"
|
||||||
|
export const UNISWAP_ARBITRAGEUR_CONTRACT_NAME = "UniswapArbitrageur"
|
||||||
|
export const DODO_TOKEN_CONTRACT_NAME = "DODOToken"
|
||||||
|
export const LOCKED_TOKEN_VAULT_CONTRACT_NAME = "LockedTokenVault"
|
||||||
|
export const DODO_MINE_NAME = "DODOMine"
|
||||||
|
export const DODO_MINE_READER_NAME = "DODOMineReader"
|
||||||
|
export const DVM_VAULT_NAME = "DVMVault"
|
||||||
|
export const DVM_CONTROLLER_NAME = "DVMController"
|
||||||
|
export const DVM_FACTORY_NAME = "DVMFactory"
|
||||||
|
export const SMART_ROUTE_NAME = "SmartRoute"
|
||||||
|
export const NAIVE_FEE_RATE_MODEL_NAME = "NaiveFeeRateModel"
|
||||||
|
|
||||||
interface ContractJson {
|
interface ContractJson {
|
||||||
abi: any;
|
abi: any;
|
||||||
networks: { [network: number]: any };
|
networks: { [network: number]: any };
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export interface DVMContextInitConfig {
|
|||||||
| 70% | 23.3% |
|
| 70% | 23.3% |
|
||||||
+──────────────────────+───────────────+
|
+──────────────────────+───────────────+
|
||||||
*/
|
*/
|
||||||
export let DefaultDODOContextInitConfig = {
|
export let DefaultDVMContextInitConfig = {
|
||||||
lpFeeRate: decimalStr("0.002"),
|
lpFeeRate: decimalStr("0.002"),
|
||||||
mtFeeRate: decimalStr("0.001"),
|
mtFeeRate: decimalStr("0.001"),
|
||||||
k: decimalStr("0.1"),
|
k: decimalStr("0.1"),
|
||||||
@@ -48,29 +48,33 @@ export let DefaultDODOContextInitConfig = {
|
|||||||
gasPriceLimit: gweiStr("100"),
|
gasPriceLimit: gweiStr("100"),
|
||||||
};
|
};
|
||||||
|
|
||||||
export class DODOContext {
|
export class DVMContext {
|
||||||
EVM: EVM;
|
EVM: EVM;
|
||||||
Web3: Web3;
|
Web3: Web3;
|
||||||
DODO: Contract;
|
Route: Contract;
|
||||||
DODOZoo: Contract;
|
DVMFactory: Contract;
|
||||||
|
DVM: Contract;
|
||||||
|
Vault: Contract;
|
||||||
BASE: Contract;
|
BASE: Contract;
|
||||||
BaseCapital: Contract;
|
|
||||||
QUOTE: Contract;
|
QUOTE: Contract;
|
||||||
QuoteCapital: Contract;
|
|
||||||
ORACLE: Contract;
|
|
||||||
Deployer: string;
|
Deployer: string;
|
||||||
Supervisor: string;
|
|
||||||
Maintainer: string;
|
Maintainer: string;
|
||||||
spareAccounts: string[];
|
SpareAccounts: string[];
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
async init(config: DODOContextInitConfig) {
|
async init(config: DVMContextInitConfig) {
|
||||||
this.EVM = new EVM();
|
this.EVM = new EVM();
|
||||||
this.Web3 = getDefaultWeb3();
|
this.Web3 = getDefaultWeb3();
|
||||||
|
this.Route = await contracts.newContract(contracts.SMART_ROUTE_NAME)
|
||||||
|
|
||||||
var cloneFactory = await contracts.newContract(
|
var cloneFactory = await contracts.newContract(
|
||||||
contracts.CLONE_FACTORY_CONTRACT_NAME
|
contracts.CLONE_FACTORY_CONTRACT_NAME
|
||||||
);
|
);
|
||||||
|
var vaultTemplate = await contracts.newContract(contracts.DVM_VAULT_NAME)
|
||||||
|
var controllerTemplate = await contracts.newContract(contracts.DVM_CONTROLLER_NAME)
|
||||||
|
|
||||||
|
this.DVMFactory = await contracts.newContract(contracts.DVM_FACTORY_NAME, [cloneFactory.options.address, vaultTemplate.options.address, controllerTemplate.options.address])
|
||||||
|
|
||||||
this.BASE = await contracts.newContract(
|
this.BASE = await contracts.newContract(
|
||||||
contracts.TEST_ERC20_CONTRACT_NAME,
|
contracts.TEST_ERC20_CONTRACT_NAME,
|
||||||
@@ -80,65 +84,27 @@ export class DODOContext {
|
|||||||
contracts.TEST_ERC20_CONTRACT_NAME,
|
contracts.TEST_ERC20_CONTRACT_NAME,
|
||||||
["TestQuote", 18]
|
["TestQuote", 18]
|
||||||
);
|
);
|
||||||
this.ORACLE = await contracts.newContract(
|
|
||||||
contracts.NAIVE_ORACLE_CONTRACT_NAME
|
|
||||||
);
|
|
||||||
|
|
||||||
const allAccounts = await this.Web3.eth.getAccounts();
|
const allAccounts = await this.Web3.eth.getAccounts();
|
||||||
this.Deployer = allAccounts[0];
|
this.Deployer = allAccounts[0];
|
||||||
this.Supervisor = allAccounts[1];
|
this.Maintainer = allAccounts[1];
|
||||||
this.Maintainer = allAccounts[2];
|
this.SpareAccounts = allAccounts.slice(2, 10);
|
||||||
this.spareAccounts = allAccounts.slice(3, 10);
|
|
||||||
|
|
||||||
var DODOTemplate = await contracts.newContract(
|
var lpFeeRateModel = await contracts.newContract(contracts.NAIVE_FEE_RATE_MODEL_NAME, [config.lpFeeRate])
|
||||||
contracts.DODO_CONTRACT_NAME
|
var mtFeeRateModel = await contracts.newContract(contracts.NAIVE_FEE_RATE_MODEL_NAME, [config.mtFeeRate])
|
||||||
);
|
var DVMAddress = this.DVMFactory.methods.createDODOVenderMachine(
|
||||||
this.DODOZoo = await contracts.newContract(
|
this.Maintainer,
|
||||||
contracts.DODO_ZOO_CONTRACT_NAME,
|
this.BASE.options.address,
|
||||||
[
|
this.QUOTE.options.address,
|
||||||
DODOTemplate.options.address,
|
lpFeeRateModel.options.address,
|
||||||
cloneFactory.options.address,
|
mtFeeRateModel.options.address,
|
||||||
this.Supervisor,
|
config.i,
|
||||||
]
|
config.k,
|
||||||
);
|
config.gasPriceLimit).send(this.sendParam(this.Deployer))
|
||||||
|
|
||||||
await this.DODOZoo.methods
|
this.DVM = contracts.getContractWithAddress(contracts.DVM_CONTROLLER_NAME, DVMAddress)
|
||||||
.breedDODO(
|
|
||||||
this.Maintainer,
|
|
||||||
this.BASE.options.address,
|
|
||||||
this.QUOTE.options.address,
|
|
||||||
this.ORACLE.options.address,
|
|
||||||
config.lpFeeRate,
|
|
||||||
config.mtFeeRate,
|
|
||||||
config.k,
|
|
||||||
config.gasPriceLimit
|
|
||||||
)
|
|
||||||
.send(this.sendParam(this.Deployer));
|
|
||||||
|
|
||||||
this.DODO = contracts.getContractWithAddress(
|
console.log(log.blueText("[Init DVM context]"));
|
||||||
contracts.DODO_CONTRACT_NAME,
|
|
||||||
await this.DODOZoo.methods
|
|
||||||
.getDODO(this.BASE.options.address, this.QUOTE.options.address)
|
|
||||||
.call()
|
|
||||||
);
|
|
||||||
await this.DODO.methods
|
|
||||||
.enableBaseDeposit()
|
|
||||||
.send(this.sendParam(this.Deployer));
|
|
||||||
await this.DODO.methods
|
|
||||||
.enableQuoteDeposit()
|
|
||||||
.send(this.sendParam(this.Deployer));
|
|
||||||
await this.DODO.methods.enableTrading().send(this.sendParam(this.Deployer));
|
|
||||||
|
|
||||||
this.BaseCapital = contracts.getContractWithAddress(
|
|
||||||
contracts.DODO_LP_TOKEN_CONTRACT_NAME,
|
|
||||||
await this.DODO.methods._BASE_CAPITAL_TOKEN_().call()
|
|
||||||
);
|
|
||||||
this.QuoteCapital = contracts.getContractWithAddress(
|
|
||||||
contracts.DODO_LP_TOKEN_CONTRACT_NAME,
|
|
||||||
await this.DODO.methods._QUOTE_CAPITAL_TOKEN_().call()
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(log.blueText("[Init dodo context]"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendParam(sender, value = "0") {
|
sendParam(sender, value = "0") {
|
||||||
@@ -150,12 +116,6 @@ export class DODOContext {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async setOraclePrice(price: string) {
|
|
||||||
await this.ORACLE.methods
|
|
||||||
.setPrice(price)
|
|
||||||
.send(this.sendParam(this.Deployer));
|
|
||||||
}
|
|
||||||
|
|
||||||
async mintTestToken(to: string, base: string, quote: string) {
|
async mintTestToken(to: string, base: string, quote: string) {
|
||||||
await this.BASE.methods.mint(to, base).send(this.sendParam(this.Deployer));
|
await this.BASE.methods.mint(to, base).send(this.sendParam(this.Deployer));
|
||||||
await this.QUOTE.methods
|
await this.QUOTE.methods
|
||||||
@@ -163,20 +123,20 @@ export class DODOContext {
|
|||||||
.send(this.sendParam(this.Deployer));
|
.send(this.sendParam(this.Deployer));
|
||||||
}
|
}
|
||||||
|
|
||||||
async approveDODO(account: string) {
|
async approveRoute(account: string) {
|
||||||
await this.BASE.methods
|
await this.BASE.methods
|
||||||
.approve(this.DODO.options.address, MAX_UINT256)
|
.approve(this.Route.options.address, MAX_UINT256)
|
||||||
.send(this.sendParam(account));
|
.send(this.sendParam(account));
|
||||||
await this.QUOTE.methods
|
await this.QUOTE.methods
|
||||||
.approve(this.DODO.options.address, MAX_UINT256)
|
.approve(this.Route.options.address, MAX_UINT256)
|
||||||
.send(this.sendParam(account));
|
.send(this.sendParam(account));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getDODOContext(
|
export async function getDODOContext(
|
||||||
config: DODOContextInitConfig = DefaultDODOContextInitConfig
|
config: DVMContextInitConfig = DefaultDVMContextInitConfig
|
||||||
): Promise<DODOContext> {
|
): Promise<DVMContext> {
|
||||||
var context = new DODOContext();
|
var context = new DVMContext();
|
||||||
await context.init(config);
|
await context.init(config);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user