update isOpenTWAP
This commit is contained in:
@@ -41,7 +41,8 @@ describe("Funding", () => {
|
|||||||
freezeDuration: new BigNumber(86400),
|
freezeDuration: new BigNumber(86400),
|
||||||
vestingDuration: new BigNumber(86400),
|
vestingDuration: new BigNumber(86400),
|
||||||
cliffRate: decimalStr("1"),
|
cliffRate: decimalStr("1"),
|
||||||
quoteTokenContract:""
|
quoteTokenContract:"",
|
||||||
|
isOpenTWAP:true
|
||||||
}
|
}
|
||||||
ctx = new CPContext();
|
ctx = new CPContext();
|
||||||
await ctx.init(config);
|
await ctx.init(config);
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ describe("Funding", () => {
|
|||||||
freezeDuration: new BigNumber(86400),
|
freezeDuration: new BigNumber(86400),
|
||||||
vestingDuration: new BigNumber(86400),
|
vestingDuration: new BigNumber(86400),
|
||||||
cliffRate: decimalStr("1"),
|
cliffRate: decimalStr("1"),
|
||||||
quoteTokenContract:"WETH9"
|
quoteTokenContract:"WETH9",
|
||||||
|
isOpenTWAP:true
|
||||||
}
|
}
|
||||||
ctx = new CPContext();
|
ctx = new CPContext();
|
||||||
await ctx.init(config);
|
await ctx.init(config);
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ describe("Funding", () => {
|
|||||||
freezeDuration: new BigNumber(86400),
|
freezeDuration: new BigNumber(86400),
|
||||||
vestingDuration: new BigNumber(86400),
|
vestingDuration: new BigNumber(86400),
|
||||||
cliffRate: decimalStr("1"),
|
cliffRate: decimalStr("1"),
|
||||||
quoteTokenContract:''
|
quoteTokenContract:'',
|
||||||
|
isOpenTWAP:true
|
||||||
}
|
}
|
||||||
ctx = new CPContext();
|
ctx = new CPContext();
|
||||||
await ctx.init(config);
|
await ctx.init(config);
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ describe("Funding", () => {
|
|||||||
freezeDuration: new BigNumber(86400),
|
freezeDuration: new BigNumber(86400),
|
||||||
vestingDuration: new BigNumber(86400),
|
vestingDuration: new BigNumber(86400),
|
||||||
cliffRate: decimalStr("1"),
|
cliffRate: decimalStr("1"),
|
||||||
quoteTokenContract:''
|
quoteTokenContract:'',
|
||||||
|
isOpenTWAP:true
|
||||||
}
|
}
|
||||||
ctx = new CPContext();
|
ctx = new CPContext();
|
||||||
await ctx.init(config);
|
await ctx.init(config);
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ describe("Funding", () => {
|
|||||||
freezeDuration: new BigNumber(86400),
|
freezeDuration: new BigNumber(86400),
|
||||||
vestingDuration: new BigNumber(86400),
|
vestingDuration: new BigNumber(86400),
|
||||||
cliffRate: decimalStr("1"),
|
cliffRate: decimalStr("1"),
|
||||||
quoteTokenContract:''
|
quoteTokenContract:'',
|
||||||
|
isOpenTWAP:true
|
||||||
}
|
}
|
||||||
ctx = new CPContext();
|
ctx = new CPContext();
|
||||||
await ctx.init(config);
|
await ctx.init(config);
|
||||||
|
|||||||
@@ -49,23 +49,6 @@ describe("DPP Trader", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("trade", () => {
|
describe("trade", () => {
|
||||||
// it.only("basic check", async () => {
|
|
||||||
// console.log(await ctx.DPP.methods.getVaultReserve().call())
|
|
||||||
// console.log(await ctx.DPP.methods.getPMMState().call())
|
|
||||||
// console.log(await ctx.DPP.methods.getMidPrice().call())
|
|
||||||
// console.log(await ctx.DPP.methods.querySellQuote(ctx.Deployer, decimalStr("200")).call())
|
|
||||||
// console.log(ctx.BASE.options.address)
|
|
||||||
// console.log(await ctx.DPP.methods._BASE_TOKEN_().call())
|
|
||||||
// console.log(ctx.QUOTE.options.address)
|
|
||||||
// console.log(await ctx.DPP.methods._QUOTE_TOKEN_().call())
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it.only("mannually buy", async () => {
|
|
||||||
// await ctx.QUOTE.methods.transfer(ctx.DPP.options.address, decimalStr("100")).send(ctx.sendParam(lp))
|
|
||||||
// console.log(await ctx.DPP.methods.getQuoteInput().call())
|
|
||||||
// console.log(await ctx.DPP.methods.querySellQuote(lp, decimalStr("100")).call())
|
|
||||||
// await ctx.DPP.methods.sellQuote(lp).send(ctx.sendParam(lp))
|
|
||||||
// })
|
|
||||||
|
|
||||||
it("first buy and then sell", async () => {
|
it("first buy and then sell", async () => {
|
||||||
// buy at R=1
|
// buy at R=1
|
||||||
@@ -95,7 +78,6 @@ describe("DPP Trader", () => {
|
|||||||
// sell at R>1 and R not change state
|
// sell at R>1 and R not change state
|
||||||
await ctx.transferBaseToDPP(trader, decimalStr("1"))
|
await ctx.transferBaseToDPP(trader, decimalStr("1"))
|
||||||
await logGas(ctx.DPP.methods.sellBase(trader), ctx.sendParam(trader), "sellBase - sell at R>1 and R not change state")
|
await logGas(ctx.DPP.methods.sellBase(trader), ctx.sendParam(trader), "sellBase - sell at R>1 and R not change state")
|
||||||
balances = await ctx.getBalances(trader)
|
|
||||||
|
|
||||||
assert.equal(balances.traderBase, "10946772292527553373")
|
assert.equal(balances.traderBase, "10946772292527553373")
|
||||||
assert.equal(balances.traderQuote, "903421814651005338950")
|
assert.equal(balances.traderQuote, "903421814651005338950")
|
||||||
@@ -104,8 +86,14 @@ describe("DPP Trader", () => {
|
|||||||
assert.equal(balances.maintainerBase, "1952630183076783")
|
assert.equal(balances.maintainerBase, "1952630183076783")
|
||||||
assert.equal(balances.maintainerQuote, "103733013692081583")
|
assert.equal(balances.maintainerQuote, "103733013692081583")
|
||||||
|
|
||||||
|
|
||||||
// sell at R>1 and R change state
|
// sell at R>1 and R change state
|
||||||
await ctx.transferBaseToDPP(trader, decimalStr("2"))
|
await ctx.transferBaseToDPP(trader, decimalStr("2"))
|
||||||
|
|
||||||
|
let resp = await ctx.DPP.methods.querySellBase(trader,decimalStr("2")).call();
|
||||||
|
let bs = await ctx.getBalances(trader);
|
||||||
|
let lpFeeRate = await ctx.DPP.methods._LP_FEE_RATE_().call();
|
||||||
|
|
||||||
await logGas(ctx.DPP.methods.sellBase(trader), ctx.sendParam(trader), "sellBase - sell at R>1 and R change state")
|
await logGas(ctx.DPP.methods.sellBase(trader), ctx.sendParam(trader), "sellBase - sell at R>1 and R change state")
|
||||||
balances = await ctx.getBalances(trader)
|
balances = await ctx.getBalances(trader)
|
||||||
|
|
||||||
@@ -176,7 +164,6 @@ describe("DPP Trader", () => {
|
|||||||
assert.equal(PMMStat.Q0, "1000595024934809920179")
|
assert.equal(PMMStat.Q0, "1000595024934809920179")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("flash loan", async () => {
|
it("flash loan", async () => {
|
||||||
// buy
|
// buy
|
||||||
await ctx.transferQuoteToDPP(trader, decimalStr("200"))
|
await ctx.transferQuoteToDPP(trader, decimalStr("200"))
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export interface CPContextInitConfig {
|
|||||||
vestingDuration: BigNumber;
|
vestingDuration: BigNumber;
|
||||||
cliffRate: string;
|
cliffRate: string;
|
||||||
quoteTokenContract: string;
|
quoteTokenContract: string;
|
||||||
|
isOpenTWAP:true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -124,7 +125,8 @@ export class CPContext {
|
|||||||
config.k,
|
config.k,
|
||||||
config.i,
|
config.i,
|
||||||
config.cliffRate
|
config.cliffRate
|
||||||
]
|
],
|
||||||
|
config.isOpenTWAP
|
||||||
).send(this.sendParam(this.Deployer))
|
).send(this.sendParam(this.Deployer))
|
||||||
|
|
||||||
await defaultGasSource.methods.init(this.Deployer, MAX_UINT256).send(this.sendParam(this.Deployer));
|
await defaultGasSource.methods.init(this.Deployer, MAX_UINT256).send(this.sendParam(this.Deployer));
|
||||||
|
|||||||
@@ -5,18 +5,18 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from "bignumber.js";
|
||||||
import Web3 from 'web3';
|
import Web3 from "web3";
|
||||||
import { Contract } from 'web3-eth-contract';
|
import { Contract } from "web3-eth-contract";
|
||||||
|
|
||||||
import * as contracts from './Contracts';
|
import * as contracts from "./Contracts";
|
||||||
import { decimalStr, MAX_UINT256 } from './Converter';
|
import { decimalStr, MAX_UINT256 } from "./Converter";
|
||||||
import { EVM, getDefaultWeb3 } from './EVM';
|
import { EVM, getDefaultWeb3 } from "./EVM";
|
||||||
import * as log from './Log';
|
import * as log from "./Log";
|
||||||
|
|
||||||
BigNumber.config({
|
BigNumber.config({
|
||||||
EXPONENTIAL_AT: 1000,
|
EXPONENTIAL_AT: 1000,
|
||||||
DECIMAL_PLACES: 80,
|
DECIMAL_PLACES: 80
|
||||||
});
|
});
|
||||||
|
|
||||||
export interface DPPContextBalances {
|
export interface DPPContextBalances {
|
||||||
@@ -33,6 +33,7 @@ export interface DPPContextInitConfig {
|
|||||||
mtFeeRate: string;
|
mtFeeRate: string;
|
||||||
k: string;
|
k: string;
|
||||||
i: string;
|
i: string;
|
||||||
|
isOpenTWAP: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -53,6 +54,7 @@ export let DefaultDPPContextInitConfig = {
|
|||||||
mtFeeRate: decimalStr("0.001"),
|
mtFeeRate: decimalStr("0.001"),
|
||||||
k: decimalStr("0.1"),
|
k: decimalStr("0.1"),
|
||||||
i: decimalStr("100"),
|
i: decimalStr("100"),
|
||||||
|
isOpenTWAP: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export class DPPContext {
|
export class DPPContext {
|
||||||
@@ -65,19 +67,20 @@ export class DPPContext {
|
|||||||
Maintainer: string;
|
Maintainer: string;
|
||||||
SpareAccounts: string[];
|
SpareAccounts: string[];
|
||||||
|
|
||||||
constructor() { }
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
async init(config: DPPContextInitConfig) {
|
async init(config: DPPContextInitConfig) {
|
||||||
this.EVM = new EVM();
|
this.EVM = new EVM();
|
||||||
this.Web3 = getDefaultWeb3();
|
this.Web3 = getDefaultWeb3();
|
||||||
|
|
||||||
this.DPP = await contracts.newContract(contracts.DPP_NAME)
|
this.DPP = await contracts.newContract(contracts.DPP_NAME);
|
||||||
var lpFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME)
|
var lpFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME);
|
||||||
var mtFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME)
|
var mtFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME);
|
||||||
var permissionManager = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME)
|
var permissionManager = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME);
|
||||||
var gasPriceSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME)
|
var gasPriceSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME);
|
||||||
var iSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME)
|
var iSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME);
|
||||||
var kSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME)
|
var kSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME);
|
||||||
this.BASE = await contracts.newContract(
|
this.BASE = await contracts.newContract(
|
||||||
contracts.MINTABLE_ERC20_CONTRACT_NAME,
|
contracts.MINTABLE_ERC20_CONTRACT_NAME,
|
||||||
["TestBase", "BASE", 18]
|
["TestBase", "BASE", 18]
|
||||||
@@ -92,12 +95,12 @@ export class DPPContext {
|
|||||||
this.Maintainer = allAccounts[2];
|
this.Maintainer = allAccounts[2];
|
||||||
this.SpareAccounts = allAccounts.slice(2, 10);
|
this.SpareAccounts = allAccounts.slice(2, 10);
|
||||||
|
|
||||||
await gasPriceSource.methods.init(this.Deployer, MAX_UINT256).send(this.sendParam(this.Deployer))
|
await gasPriceSource.methods.init(this.Deployer, MAX_UINT256).send(this.sendParam(this.Deployer));
|
||||||
await lpFeeRateModel.methods.init(this.DPP.options.address, config.lpFeeRate).send(this.sendParam(this.Deployer))
|
await lpFeeRateModel.methods.init(this.DPP.options.address, config.lpFeeRate).send(this.sendParam(this.Deployer));
|
||||||
await mtFeeRateModel.methods.init(this.DPP.options.address, config.mtFeeRate).send(this.sendParam(this.Deployer))
|
await mtFeeRateModel.methods.init(this.DPP.options.address, config.mtFeeRate).send(this.sendParam(this.Deployer));
|
||||||
|
|
||||||
await kSource.methods.init(this.DPP.options.address, config.k).send(this.sendParam(this.Deployer))
|
await kSource.methods.init(this.DPP.options.address, config.k).send(this.sendParam(this.Deployer));
|
||||||
await iSource.methods.init(this.DPP.options.address, config.i).send(this.sendParam(this.Deployer))
|
await iSource.methods.init(this.DPP.options.address, config.i).send(this.sendParam(this.Deployer));
|
||||||
|
|
||||||
await this.DPP.methods.init(
|
await this.DPP.methods.init(
|
||||||
this.Deployer,
|
this.Deployer,
|
||||||
@@ -108,7 +111,8 @@ export class DPPContext {
|
|||||||
mtFeeRateModel.options.address,
|
mtFeeRateModel.options.address,
|
||||||
config.k,
|
config.k,
|
||||||
config.i,
|
config.i,
|
||||||
).send(this.sendParam(this.Deployer))
|
config.isOpenTWAP
|
||||||
|
).send(this.sendParam(this.Deployer));
|
||||||
|
|
||||||
console.log(log.blueText("[Init DPP context]"));
|
console.log(log.blueText("[Init DPP context]"));
|
||||||
}
|
}
|
||||||
@@ -118,7 +122,7 @@ export class DPPContext {
|
|||||||
from: sender,
|
from: sender,
|
||||||
gas: process.env["COVERAGE"] ? 10000000000 : 7000000,
|
gas: process.env["COVERAGE"] ? 10000000000 : 7000000,
|
||||||
gasPrice: process.env.GAS_PRICE,
|
gasPrice: process.env.GAS_PRICE,
|
||||||
value: decimalStr(value),
|
value: decimalStr(value)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,11 +134,11 @@ export class DPPContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async transferBaseToDPP(account: string, amount: string) {
|
async transferBaseToDPP(account: string, amount: string) {
|
||||||
await this.BASE.methods.transfer(this.DPP.options.address, amount).send(this.sendParam(account))
|
await this.BASE.methods.transfer(this.DPP.options.address, amount).send(this.sendParam(account));
|
||||||
}
|
}
|
||||||
|
|
||||||
async transferQuoteToDPP(account: string, amount: string) {
|
async transferQuoteToDPP(account: string, amount: string) {
|
||||||
await this.QUOTE.methods.transfer(this.DPP.options.address, amount).send(this.sendParam(account))
|
await this.QUOTE.methods.transfer(this.DPP.options.address, amount).send(this.sendParam(account));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBalances(trader: string) {
|
async getBalances(trader: string) {
|
||||||
@@ -144,9 +148,9 @@ export class DPPContext {
|
|||||||
DPPBase: await this.BASE.methods.balanceOf(this.DPP.options.address).call(),
|
DPPBase: await this.BASE.methods.balanceOf(this.DPP.options.address).call(),
|
||||||
DPPQuote: await this.QUOTE.methods.balanceOf(this.DPP.options.address).call(),
|
DPPQuote: await this.QUOTE.methods.balanceOf(this.DPP.options.address).call(),
|
||||||
maintainerBase: await this.BASE.methods.balanceOf(this.Maintainer).call(),
|
maintainerBase: await this.BASE.methods.balanceOf(this.Maintainer).call(),
|
||||||
maintainerQuote: await this.QUOTE.methods.balanceOf(this.Maintainer).call(),
|
maintainerQuote: await this.QUOTE.methods.balanceOf(this.Maintainer).call()
|
||||||
}
|
};
|
||||||
return balances
|
return balances;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user