mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add complete multi decimals support in Pool, add test
This commit is contained in:
parent
6df2123f91
commit
22746a10e0
@ -1,5 +1,6 @@
|
|||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
|
import BigNumber from 'bignumber.js'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import defaultFactory721ABI from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
import defaultFactory721ABI from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||||
@ -37,7 +38,7 @@ interface ErcCreateData {
|
|||||||
|
|
||||||
interface PoolData {
|
interface PoolData {
|
||||||
addresses: string[]
|
addresses: string[]
|
||||||
ssParams: (string | number)[]
|
ssParams: (string | number | BigNumber)[]
|
||||||
swapFees: number[]
|
swapFees: number[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,8 +134,7 @@ export class Router {
|
|||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) {
|
) {
|
||||||
const routerContract =
|
const routerContract = contractInstance || this.router
|
||||||
contractInstance || this.router
|
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||||
let estGas
|
let estGas
|
||||||
@ -148,6 +147,7 @@ export class Router {
|
|||||||
}
|
}
|
||||||
return estGas
|
return estGas
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new token to oceanTokens list, pools with basetoken in this list have NO opf Fee
|
* Add a new token to oceanTokens list, pools with basetoken in this list have NO opf Fee
|
||||||
* @param {String} address caller address
|
* @param {String} address caller address
|
||||||
@ -162,9 +162,7 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const estGas = await this.estGasAddOceanToken(address, tokenAddress)
|
||||||
const estGas = await this.estGasAddOceanToken(address,tokenAddress)
|
|
||||||
|
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addOceanToken(tokenAddress).send({
|
const trxReceipt = await this.router.methods.addOceanToken(tokenAddress).send({
|
||||||
@ -188,8 +186,7 @@ export class Router {
|
|||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) {
|
) {
|
||||||
const routerContract =
|
const routerContract = contractInstance || this.router
|
||||||
contractInstance || this.router
|
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||||
let estGas
|
let estGas
|
||||||
@ -217,8 +214,7 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemoveOceanToken(address,tokenAddress)
|
const estGas = await this.estGasRemoveOceanToken(address, tokenAddress)
|
||||||
|
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.removeOceanToken(tokenAddress).send({
|
const trxReceipt = await this.router.methods.removeOceanToken(tokenAddress).send({
|
||||||
|
@ -40,11 +40,9 @@ export class Pool {
|
|||||||
spender: string
|
spender: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const tokenAbi = defaultERC20ABI.abi as AbiItem[]
|
const tokenAbi = defaultERC20ABI.abi as AbiItem[]
|
||||||
const datatoken = new this.web3.eth.Contract(tokenAbi, tokenAddress, {
|
const datatoken = new this.web3.eth.Contract(tokenAbi, tokenAddress)
|
||||||
from: spender
|
|
||||||
})
|
|
||||||
const trxReceipt = await datatoken.methods.allowance(owner, spender).call()
|
const trxReceipt = await datatoken.methods.allowance(owner, spender).call()
|
||||||
return this.web3.utils.fromWei(trxReceipt)
|
return (await this.unitsToAmount(tokenAddress, trxReceipt)).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,14 +101,16 @@ export class Pool {
|
|||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await token.methods
|
estGas = await token.methods
|
||||||
.approve(spender, amount)
|
.approve(spender, await this.amountToUnits(tokenAddress, amount))
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await token.methods.approve(spender, amount).send({
|
result = await token.methods
|
||||||
|
.approve(spender, await this.amountToUnits(tokenAddress, amount))
|
||||||
|
.send({
|
||||||
from: account,
|
from: account,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3)
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
@ -279,7 +279,6 @@ export class Pool {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get marketFeeCollector of this pool
|
* Get marketFeeCollector of this pool
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
@ -296,7 +295,6 @@ export class Pool {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get OPF Collector of this pool
|
* Get OPF Collector of this pool
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
@ -312,6 +310,7 @@ export class Pool {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get if a token is bounded to a pool
|
* Get if a token is bounded to a pool
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
@ -341,7 +340,7 @@ export class Pool {
|
|||||||
try {
|
try {
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
const result = await pool.methods.getBalance(token).call()
|
const result = await pool.methods.getBalance(token).call()
|
||||||
amount = await this.unitsToAmount(token,result)
|
amount = await this.unitsToAmount(token, result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get how many tokens \
|
this.logger.error(`ERROR: Failed to get how many tokens \
|
||||||
are in the pool: ${e.message}`)
|
are in the pool: ${e.message}`)
|
||||||
@ -482,7 +481,7 @@ export class Pool {
|
|||||||
address: string,
|
address: string,
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -499,28 +498,19 @@ export class Pool {
|
|||||||
return estGas
|
return estGas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* collectOPF - collect opf fee - can be called by anyone
|
* collectOPF - collect opf fee - can be called by anyone
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @return {TransactionReceipt}
|
* @return {TransactionReceipt}
|
||||||
*/
|
*/
|
||||||
async collectOPF(
|
async collectOPF(address: string, poolAddress: string): Promise<TransactionReceipt> {
|
||||||
address: string,
|
|
||||||
poolAddress: string
|
|
||||||
): Promise<TransactionReceipt> {
|
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
let result = null
|
let result = null
|
||||||
const estGas = await this.estCollectOPF(
|
const estGas = await this.estCollectOPF(address, poolAddress)
|
||||||
address,
|
|
||||||
poolAddress
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
result = await pool.methods.collectOPF().send({
|
||||||
.collectOPF()
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3)
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
@ -542,9 +532,9 @@ export class Pool {
|
|||||||
public async estCollectMarketFee(
|
public async estCollectMarketFee(
|
||||||
address: string,
|
address: string,
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
to:string,
|
to: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -561,7 +551,6 @@ export class Pool {
|
|||||||
return estGas
|
return estGas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* collectOPF - collect market fees - can be called by the marketFeeCollector
|
* collectOPF - collect market fees - can be called by the marketFeeCollector
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
@ -579,16 +568,10 @@ export class Pool {
|
|||||||
}
|
}
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
let result = null
|
let result = null
|
||||||
const estGas = await this.estCollectMarketFee(
|
const estGas = await this.estCollectMarketFee(address, poolAddress, to)
|
||||||
address,
|
|
||||||
poolAddress,
|
|
||||||
to
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
result = await pool.methods.collectMarketFee(to).send({
|
||||||
.collectMarketFee(to)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3)
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
@ -610,9 +593,9 @@ export class Pool {
|
|||||||
public async estUpdateMarketFeeCollector(
|
public async estUpdateMarketFeeCollector(
|
||||||
address: string,
|
address: string,
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
newCollector:string,
|
newCollector: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -629,7 +612,6 @@ export class Pool {
|
|||||||
return estGas
|
return estGas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updateMarketFeeCollector - updates marketFeeCollector - can be called only by the marketFeeCollector
|
* updateMarketFeeCollector - updates marketFeeCollector - can be called only by the marketFeeCollector
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
@ -654,9 +636,7 @@ export class Pool {
|
|||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
result = await pool.methods.updateMarketFeeCollector(newCollector).send({
|
||||||
.updateMarketFeeCollector(newCollector)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3)
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
@ -667,7 +647,6 @@ export class Pool {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Estimate gas cost for swapExactAmountIn
|
* Estimate gas cost for swapExactAmountIn
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
@ -689,7 +668,7 @@ export class Pool {
|
|||||||
minAmountOut: string,
|
minAmountOut: string,
|
||||||
maxPrice: string,
|
maxPrice: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -712,7 +691,7 @@ export class Pool {
|
|||||||
return estGas
|
return estGas
|
||||||
}
|
}
|
||||||
|
|
||||||
async amountToUnits(token:string,amount:string):Promise<number>{
|
async amountToUnits(token: string, amount: string): Promise<number> {
|
||||||
let decimals = 18
|
let decimals = 18
|
||||||
let amountFormatted
|
let amountFormatted
|
||||||
const tokenContract = new this.web3.eth.Contract(
|
const tokenContract = new this.web3.eth.Contract(
|
||||||
@ -724,15 +703,13 @@ export class Pool {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
}
|
}
|
||||||
console.log(decimals,'decimals')
|
|
||||||
|
|
||||||
amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
||||||
|
|
||||||
return amountFormatted
|
return amountFormatted
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async unitsToAmount(token:string,amount:string):Promise<number>{
|
async unitsToAmount(token: string, amount: string): Promise<number> {
|
||||||
let decimals = 18
|
let decimals = 18
|
||||||
let amountFormatted
|
let amountFormatted
|
||||||
const tokenContract = new this.web3.eth.Contract(
|
const tokenContract = new this.web3.eth.Contract(
|
||||||
@ -744,12 +721,10 @@ export class Pool {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
}
|
}
|
||||||
console.log(decimals,'decimals')
|
|
||||||
|
|
||||||
amountFormatted = new BigNumber(parseInt(amount) /(10 ** decimals) )
|
amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
|
||||||
|
|
||||||
return amountFormatted
|
return amountFormatted
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -781,39 +756,12 @@ export class Pool {
|
|||||||
let amountInFormatted
|
let amountInFormatted
|
||||||
let minAmountOutFormatted
|
let minAmountOutFormatted
|
||||||
|
|
||||||
// let tokenInDecimals = 18
|
amountInFormatted = await this.amountToUnits(tokenIn, tokenAmountIn)
|
||||||
// let tokenOutDecimals = 18
|
|
||||||
// try {
|
|
||||||
// tokenInDecimals = await tokenInContract.methods.decimals().call()
|
|
||||||
// } catch (e) {
|
|
||||||
// this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
|
||||||
// }
|
|
||||||
// try {
|
|
||||||
// tokenOutDecimals = await tokenOutContract.methods.decimals().call()
|
|
||||||
// } catch (e) {
|
|
||||||
// this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
|
||||||
// }
|
|
||||||
amountInFormatted = await this.amountToUnits(tokenIn,tokenAmountIn)
|
|
||||||
console.log(amountInFormatted,'amountinformatted')
|
|
||||||
//const tokenInDecimals = await tokenInContract.methods.decimals().call()
|
|
||||||
// if (tokenInDecimals == 18) {
|
|
||||||
// amountInFormatted = this.web3.utils.toWei(tokenAmountIn)
|
|
||||||
// } else {
|
|
||||||
// amountInFormatted = parseInt(tokenAmountIn) * 10 ** tokenInDecimals
|
|
||||||
// }
|
|
||||||
|
|
||||||
minAmountOutFormatted = await this.amountToUnits(tokenOut,minAmountOut)
|
minAmountOutFormatted = await this.amountToUnits(tokenOut, minAmountOut)
|
||||||
// console.log(test)
|
|
||||||
// if (tokenOutDecimals == 18) {
|
|
||||||
// minAmountOutFormatted = this.web3.utils.toWei(minAmountOut)
|
|
||||||
// } else {
|
|
||||||
// minAmountOutFormatted = parseInt(minAmountOut) * 10 ** tokenOutDecimals
|
|
||||||
// }
|
|
||||||
// console.log(tokenInDecimals,'tokenin decimals')
|
|
||||||
// console.log(tokenOutDecimals,'token out decimals')
|
|
||||||
|
|
||||||
let result = null
|
let result = null
|
||||||
// TODO: add multiple decimals support
|
|
||||||
const estGas = await this.estSwapExactAmountIn(
|
const estGas = await this.estSwapExactAmountIn(
|
||||||
address,
|
address,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -823,7 +771,7 @@ export class Pool {
|
|||||||
minAmountOutFormatted,
|
minAmountOutFormatted,
|
||||||
maxPrice ? this.web3.utils.toWei(maxPrice) : MaxUint256
|
maxPrice ? this.web3.utils.toWei(maxPrice) : MaxUint256
|
||||||
)
|
)
|
||||||
console.log(minAmountOutFormatted,'minamoutnoutformatted')
|
console.log(minAmountOutFormatted, 'minamoutnoutformatted')
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
result = await pool.methods
|
||||||
.swapExactAmountIn(
|
.swapExactAmountIn(
|
||||||
@ -838,7 +786,6 @@ export class Pool {
|
|||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3)
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
})
|
})
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
this.logger.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -867,7 +814,7 @@ export class Pool {
|
|||||||
amountOut: string,
|
amountOut: string,
|
||||||
maxPrice?: string,
|
maxPrice?: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -914,8 +861,8 @@ export class Pool {
|
|||||||
let result = null
|
let result = null
|
||||||
let maxAmountInFormatted
|
let maxAmountInFormatted
|
||||||
let amountOutFormatted
|
let amountOutFormatted
|
||||||
maxAmountInFormatted = await this.amountToUnits(tokenIn,maxAmountIn)
|
maxAmountInFormatted = await this.amountToUnits(tokenIn, maxAmountIn)
|
||||||
amountOutFormatted = await this.amountToUnits(tokenOut,amountOut)
|
amountOutFormatted = await this.amountToUnits(tokenOut, amountOut)
|
||||||
const estGas = await this.estSwapExactAmountOut(
|
const estGas = await this.estSwapExactAmountOut(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -961,7 +908,7 @@ export class Pool {
|
|||||||
poolAmountOut: string,
|
poolAmountOut: string,
|
||||||
maxAmountsIn: string[],
|
maxAmountsIn: string[],
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -996,13 +943,11 @@ export class Pool {
|
|||||||
const weiMaxAmountsIn = []
|
const weiMaxAmountsIn = []
|
||||||
const tokens = await this.getFinalTokens(poolAddress)
|
const tokens = await this.getFinalTokens(poolAddress)
|
||||||
|
|
||||||
|
for (let i = 0; i < 2; i++) {
|
||||||
for (let i=0;i<2;i++){
|
const amount = await this.amountToUnits(tokens[i], maxAmountsIn[i])
|
||||||
const amount = await this.amountToUnits(tokens[i],maxAmountsIn[i])
|
|
||||||
weiMaxAmountsIn.push(amount)
|
weiMaxAmountsIn.push(amount)
|
||||||
}
|
}
|
||||||
//console.log(weiMaxAmountsIn)
|
// console.log(weiMaxAmountsIn)
|
||||||
|
|
||||||
|
|
||||||
let result = null
|
let result = null
|
||||||
|
|
||||||
@ -1042,7 +987,7 @@ export class Pool {
|
|||||||
poolAmountIn: string,
|
poolAmountIn: string,
|
||||||
minAmountsOut: string[],
|
minAmountsOut: string[],
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -1077,9 +1022,8 @@ export class Pool {
|
|||||||
const weiMinAmountsOut = []
|
const weiMinAmountsOut = []
|
||||||
const tokens = await this.getFinalTokens(poolAddress)
|
const tokens = await this.getFinalTokens(poolAddress)
|
||||||
|
|
||||||
|
for (let i = 0; i < 2; i++) {
|
||||||
for (let i=0;i<2;i++){
|
const amount = await this.amountToUnits(tokens[i], minAmountsOut[i])
|
||||||
const amount = await this.amountToUnits(tokens[i],minAmountsOut[i])
|
|
||||||
weiMinAmountsOut.push(amount)
|
weiMinAmountsOut.push(amount)
|
||||||
}
|
}
|
||||||
let result = null
|
let result = null
|
||||||
@ -1116,7 +1060,7 @@ export class Pool {
|
|||||||
tokenAmountIn: string,
|
tokenAmountIn: string,
|
||||||
minPoolAmountOut: string,
|
minPoolAmountOut: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -1152,7 +1096,7 @@ export class Pool {
|
|||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
let result = null
|
let result = null
|
||||||
let amountInFormatted
|
let amountInFormatted
|
||||||
amountInFormatted = await this.amountToUnits(tokenIn,tokenAmountIn)
|
amountInFormatted = await this.amountToUnits(tokenIn, tokenAmountIn)
|
||||||
const estGas = await this.estJoinswapExternAmountIn(
|
const estGas = await this.estJoinswapExternAmountIn(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -1197,7 +1141,7 @@ export class Pool {
|
|||||||
poolAmountOut: string,
|
poolAmountOut: string,
|
||||||
maxAmountIn: string,
|
maxAmountIn: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -1214,8 +1158,6 @@ export class Pool {
|
|||||||
return estGas
|
return estGas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify poolAmountOut pool shares that you want to get, and a token tokenIn to pay with. This costs tokenAmountIn tokens (these went into the pool).
|
* Specify poolAmountOut pool shares that you want to get, and a token tokenIn to pay with. This costs tokenAmountIn tokens (these went into the pool).
|
||||||
* @param {String} account
|
* @param {String} account
|
||||||
@ -1235,7 +1177,7 @@ export class Pool {
|
|||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
let result = null
|
let result = null
|
||||||
let maxAmountInFormatted
|
let maxAmountInFormatted
|
||||||
maxAmountInFormatted = await this.amountToUnits(tokenIn,maxAmountIn)
|
maxAmountInFormatted = await this.amountToUnits(tokenIn, maxAmountIn)
|
||||||
const estGas = await this.estJoinswapPoolAmountOut(
|
const estGas = await this.estJoinswapPoolAmountOut(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -1278,7 +1220,7 @@ export class Pool {
|
|||||||
poolAmountIn: string,
|
poolAmountIn: string,
|
||||||
minTokenAmountOut: string,
|
minTokenAmountOut: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -1314,7 +1256,7 @@ export class Pool {
|
|||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
let result = null
|
let result = null
|
||||||
let minTokenOutFormatted
|
let minTokenOutFormatted
|
||||||
minTokenOutFormatted = await this.amountToUnits(tokenOut,minTokenAmountOut)
|
minTokenOutFormatted = await this.amountToUnits(tokenOut, minTokenAmountOut)
|
||||||
const estGas = await this.estExitswapPoolAmountIn(
|
const estGas = await this.estExitswapPoolAmountIn(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -1357,7 +1299,7 @@ export class Pool {
|
|||||||
tokenAmountOut: string,
|
tokenAmountOut: string,
|
||||||
maxPoolAmountIn: string,
|
maxPoolAmountIn: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) :Promise<number>{
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
new this.web3.eth.Contract(this.poolABI as AbiItem[], poolAddress)
|
||||||
@ -1431,42 +1373,52 @@ export class Pool {
|
|||||||
tokenOut: string
|
tokenOut: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
|
let decimalsTokenIn = 18
|
||||||
|
let decimalsTokenOut = 18
|
||||||
|
|
||||||
|
const tokenInContract = new this.web3.eth.Contract(
|
||||||
|
defaultERC20ABI.abi as AbiItem[],
|
||||||
|
tokenIn
|
||||||
|
)
|
||||||
|
const tokenOutContract = new this.web3.eth.Contract(
|
||||||
|
defaultERC20ABI.abi as AbiItem[],
|
||||||
|
tokenOut
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
decimalsTokenIn = await tokenInContract.methods.decimals().call()
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
decimalsTokenOut = await tokenOutContract.methods.decimals().call()
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
|
}
|
||||||
|
|
||||||
let price = null
|
let price = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods.getSpotPrice(tokenIn, tokenOut).call()
|
price = await pool.methods.getSpotPrice(tokenIn, tokenOut).call()
|
||||||
price = this.web3.utils.fromWei(result)
|
price = new BigNumber(price.toString())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: Failed to get spot price of swapping tokenIn to tokenOut')
|
this.logger.error('ERROR: Failed to get spot price of swapping tokenIn to tokenOut')
|
||||||
}
|
}
|
||||||
return price
|
|
||||||
|
let decimalsDiff
|
||||||
|
if (decimalsTokenIn > decimalsTokenOut) {
|
||||||
|
decimalsDiff = decimalsTokenIn - decimalsTokenOut
|
||||||
|
price = new BigNumber(price / 10 ** decimalsDiff)
|
||||||
|
// console.log(price.toString())
|
||||||
|
price = price / 10 ** decimalsTokenOut
|
||||||
|
// console.log('dtIn')
|
||||||
|
} else {
|
||||||
|
decimalsDiff = decimalsTokenOut - decimalsTokenIn
|
||||||
|
price = new BigNumber(price * 10 ** (2 * decimalsDiff))
|
||||||
|
price = price / 10 ** decimalsTokenOut
|
||||||
|
// console.log('usdcIn')
|
||||||
}
|
}
|
||||||
|
|
||||||
// public async calcSpotPrice(
|
return price.toString()
|
||||||
// poolAddress: string,
|
}
|
||||||
// tokenBalanceIn: string,
|
|
||||||
// tokenWeightIn: string,
|
|
||||||
// tokenBalanceOut: string,
|
|
||||||
// tokenWeightOut: string,
|
|
||||||
// swapFee: string
|
|
||||||
// ): Promise<string> {
|
|
||||||
// const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
|
||||||
// let amount = '0'
|
|
||||||
// try {
|
|
||||||
// const result = await pool.methods
|
|
||||||
// .calcSpotPrice(
|
|
||||||
// this.web3.utils.toWei(tokenBalanceIn),
|
|
||||||
// this.web3.utils.toWei(tokenWeightIn),
|
|
||||||
// this.web3.utils.toWei(tokenBalanceOut),
|
|
||||||
// this.web3.utils.toWei(tokenWeightOut),
|
|
||||||
// this.web3.utils.toWei(swapFee)
|
|
||||||
// )
|
|
||||||
// .call()
|
|
||||||
// amount = this.web3.utils.fromWei(result)
|
|
||||||
// } catch (e) {
|
|
||||||
// this.logger.error('ERROR: Failed to call calcSpotPrice')
|
|
||||||
// }
|
|
||||||
// return amount
|
|
||||||
// }
|
|
||||||
|
|
||||||
public async getAmountInExactOut(
|
public async getAmountInExactOut(
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
@ -1476,14 +1428,15 @@ export class Pool {
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
let amountOutFormatted
|
let amountOutFormatted
|
||||||
amountOutFormatted = await this.amountToUnits(tokenOut,tokenAmountOut)
|
amountOutFormatted = await this.amountToUnits(tokenOut, tokenAmountOut)
|
||||||
|
|
||||||
let amount = null
|
let amount = null
|
||||||
// if (new Decimal(tokenAmountOut).gte(tokenBalanceOut)) return null
|
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const result = await pool.methods
|
||||||
.getAmountInExactOut(tokenIn, tokenOut,amountOutFormatted)
|
.getAmountInExactOut(tokenIn, tokenOut, amountOutFormatted)
|
||||||
.call()
|
.call()
|
||||||
amount = await this.unitsToAmount(tokenIn,result)
|
amount = await this.unitsToAmount(tokenIn, result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: Failed to calcInGivenOut')
|
this.logger.error('ERROR: Failed to calcInGivenOut')
|
||||||
}
|
}
|
||||||
@ -1496,34 +1449,18 @@ export class Pool {
|
|||||||
tokenOut: string,
|
tokenOut: string,
|
||||||
tokenAmountIn: string
|
tokenAmountIn: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// TODO: solve decimals issue FIRST
|
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
const tokenInContract = new this.web3.eth.Contract(
|
|
||||||
defaultERC20ABI.abi as AbiItem[],
|
|
||||||
tokenIn
|
|
||||||
)
|
|
||||||
let amountInFormatted
|
let amountInFormatted
|
||||||
amountInFormatted = await this.amountToUnits(tokenIn,tokenAmountIn)
|
amountInFormatted = await this.amountToUnits(tokenIn, tokenAmountIn)
|
||||||
// let tokenInDecimals = 18
|
|
||||||
// try {
|
|
||||||
// tokenInDecimals = await tokenInContract.methods.decimals().call()
|
|
||||||
// } catch (e) {
|
|
||||||
// this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
|
||||||
// }
|
|
||||||
// //const tokenInDecimals = await tokenInContract.methods.decimals().call()
|
|
||||||
// if (tokenInDecimals == 18) {
|
|
||||||
// amountInFormatted = this.web3.utils.toWei(tokenAmountIn)
|
|
||||||
// } else {
|
|
||||||
// amountInFormatted = parseInt(tokenAmountIn) * 10 ** tokenInDecimals
|
|
||||||
// }
|
|
||||||
let amount = null
|
let amount = null
|
||||||
console.log(amountInFormatted)
|
// console.log(amountInFormatted)
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const result = await pool.methods
|
||||||
.getAmountOutExactIn(tokenIn, tokenOut, amountInFormatted)
|
.getAmountOutExactIn(tokenIn, tokenOut, amountInFormatted)
|
||||||
.call()
|
.call()
|
||||||
amount = await this.unitsToAmount(tokenOut,result)
|
amount = await this.unitsToAmount(tokenOut, result)
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: Failed to calcOutGivenIn')
|
this.logger.error('ERROR: Failed to calcOutGivenIn')
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { Contract } from 'web3-eth-contract'
|
|||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
|
|
||||||
|
|
||||||
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
const oceanAddress = '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
||||||
export class TestContractHandler {
|
export class TestContractHandler {
|
||||||
public accounts: string[]
|
public accounts: string[]
|
||||||
@ -31,7 +30,6 @@ export class TestContractHandler {
|
|||||||
public MockERC20Bytecode: string
|
public MockERC20Bytecode: string
|
||||||
public OPFBytecode: string
|
public OPFBytecode: string
|
||||||
|
|
||||||
|
|
||||||
public factory721Address: string
|
public factory721Address: string
|
||||||
public template721Address: string
|
public template721Address: string
|
||||||
public template20Address: string
|
public template20Address: string
|
||||||
@ -66,7 +64,7 @@ export class TestContractHandler {
|
|||||||
sideStakingBytecode?: string,
|
sideStakingBytecode?: string,
|
||||||
fixedRateBytecode?: string,
|
fixedRateBytecode?: string,
|
||||||
dispenserBytecode?: string,
|
dispenserBytecode?: string,
|
||||||
opfBytecode?:string
|
opfBytecode?: string
|
||||||
) {
|
) {
|
||||||
this.web3 = web3
|
this.web3 = web3
|
||||||
this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI)
|
this.ERC721Template = new this.web3.eth.Contract(ERC721TemplateABI)
|
||||||
@ -104,7 +102,7 @@ export class TestContractHandler {
|
|||||||
// get est gascost
|
// get est gascost
|
||||||
estGas = await this.OPFCollector.deploy({
|
estGas = await this.OPFCollector.deploy({
|
||||||
data: this.OPFBytecode,
|
data: this.OPFBytecode,
|
||||||
arguments: [owner,owner]
|
arguments: [owner, owner]
|
||||||
}).estimateGas(function (err, estGas) {
|
}).estimateGas(function (err, estGas) {
|
||||||
if (err) console.log('DeployContracts: ' + err)
|
if (err) console.log('DeployContracts: ' + err)
|
||||||
return estGas
|
return estGas
|
||||||
@ -112,7 +110,7 @@ export class TestContractHandler {
|
|||||||
// deploy the contract and get it's address
|
// deploy the contract and get it's address
|
||||||
this.opfCollectorAddress = await this.OPFCollector.deploy({
|
this.opfCollectorAddress = await this.OPFCollector.deploy({
|
||||||
data: this.OPFBytecode,
|
data: this.OPFBytecode,
|
||||||
arguments: [owner,owner]
|
arguments: [owner, owner]
|
||||||
})
|
})
|
||||||
.send({
|
.send({
|
||||||
from: owner,
|
from: owner,
|
||||||
@ -123,7 +121,6 @@ export class TestContractHandler {
|
|||||||
return contract.options.address
|
return contract.options.address
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// DEPLOY POOL TEMPLATE
|
// DEPLOY POOL TEMPLATE
|
||||||
// get est gascost
|
// get est gascost
|
||||||
estGas = await this.PoolTemplate.deploy({
|
estGas = await this.PoolTemplate.deploy({
|
||||||
|
@ -3,6 +3,7 @@ import { AbiItem } from 'web3-utils/types'
|
|||||||
import { TestContractHandler } from '../../../TestContractHandler'
|
import { TestContractHandler } from '../../../TestContractHandler'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
|
import BigNumber from 'bignumber.js'
|
||||||
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
|
||||||
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
|
import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
|
||||||
import SideStaking from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
import SideStaking from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||||
@ -17,6 +18,7 @@ import { LoggerInstance } from '../../../../src/utils'
|
|||||||
import { NFTFactory } from '../../../../src/factories/NFTFactory'
|
import { NFTFactory } from '../../../../src/factories/NFTFactory'
|
||||||
import { Pool } from '../../../../src/pools/balancer/Pool'
|
import { Pool } from '../../../../src/pools/balancer/Pool'
|
||||||
import { CONNREFUSED } from 'dns'
|
import { CONNREFUSED } from 'dns'
|
||||||
|
import exp from 'constants'
|
||||||
const { keccak256 } = require('@ethersproject/keccak256')
|
const { keccak256 } = require('@ethersproject/keccak256')
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
||||||
@ -69,6 +71,10 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
await contracts.deployContracts(factoryOwner, FactoryRouter.abi as AbiItem[])
|
await contracts.deployContracts(factoryOwner, FactoryRouter.abi as AbiItem[])
|
||||||
|
|
||||||
|
// initialize Pool instance
|
||||||
|
pool = new Pool(web3, LoggerInstance, PoolTemplate.abi as AbiItem[])
|
||||||
|
assert(pool != null)
|
||||||
|
|
||||||
daiContract = new web3.eth.Contract(
|
daiContract = new web3.eth.Contract(
|
||||||
contracts.MockERC20.options.jsonInterface,
|
contracts.MockERC20.options.jsonInterface,
|
||||||
contracts.daiAddress
|
contracts.daiAddress
|
||||||
@ -78,26 +84,44 @@ describe('Pool unit test', () => {
|
|||||||
contracts.MockERC20.options.jsonInterface,
|
contracts.MockERC20.options.jsonInterface,
|
||||||
contracts.usdcAddress
|
contracts.usdcAddress
|
||||||
)
|
)
|
||||||
await daiContract.methods
|
await pool.approve(
|
||||||
.approve(contracts.factory721Address, web3.utils.toWei('10000'))
|
contracts.accounts[0],
|
||||||
.send({ from: contracts.accounts[0] })
|
contracts.daiAddress,
|
||||||
await usdcContract.methods
|
contracts.factory721Address,
|
||||||
.approve(contracts.factory721Address, web3.utils.toWei('10000'))
|
'2000'
|
||||||
.send({ from: contracts.accounts[0] })
|
)
|
||||||
|
await pool.approve(
|
||||||
|
contracts.accounts[0],
|
||||||
|
contracts.usdcAddress,
|
||||||
|
contracts.factory721Address,
|
||||||
|
'10000'
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await pool.allowance(
|
||||||
|
contracts.daiAddress,
|
||||||
|
contracts.accounts[0],
|
||||||
|
contracts.factory721Address
|
||||||
|
)
|
||||||
|
).to.equal('2000')
|
||||||
|
expect(
|
||||||
|
await pool.allowance(
|
||||||
|
contracts.usdcAddress,
|
||||||
|
contracts.accounts[0],
|
||||||
|
contracts.factory721Address
|
||||||
|
)
|
||||||
|
).to.equal('10000')
|
||||||
expect(await daiContract.methods.balanceOf(contracts.accounts[0]).call()).to.equal(
|
expect(await daiContract.methods.balanceOf(contracts.accounts[0]).call()).to.equal(
|
||||||
web3.utils.toWei('100000')
|
web3.utils.toWei('100000')
|
||||||
)
|
)
|
||||||
console.log(await usdcContract.methods.balanceOf(contracts.accounts[0]).call())
|
|
||||||
console.log(await usdcContract.methods.decimals().call())
|
console.log(
|
||||||
|
await usdcContract.methods.decimals().call(),
|
||||||
|
'USDC DECIMALS IN THIS TEST'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should initiate Pool instance', async () => {
|
describe('Test a pool with DAI (18 Decimals)', () => {
|
||||||
pool = new Pool(web3, LoggerInstance, PoolTemplate.abi as AbiItem[])
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Test a pool with DAI (18 Decimals)',()=>{
|
|
||||||
it('#create a pool', async () => {
|
it('#create a pool', async () => {
|
||||||
// CREATE A POOL
|
// CREATE A POOL
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
@ -120,6 +144,8 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
bytess: []
|
bytess: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const basetokenInitialLiq = await pool.amountToUnits(contracts.daiAddress, '2000')
|
||||||
|
|
||||||
const poolData = {
|
const poolData = {
|
||||||
addresses: [
|
addresses: [
|
||||||
contracts.sideStakingAddress,
|
contracts.sideStakingAddress,
|
||||||
@ -171,7 +197,10 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
|
|
||||||
it('#getPoolSharesTotalSupply - should return totalSupply of LPT', async () => {
|
it('#getPoolSharesTotalSupply - should return totalSupply of LPT', async () => {
|
||||||
// dt owner which added liquidity has half of pool shares (the rest is in the sidestaking contracta)
|
// dt owner which added liquidity has half of pool shares (the rest is in the sidestaking contracta)
|
||||||
const dtOwnerLPTBalance = await pool.sharesBalance(contracts.accounts[0], poolAddress)
|
const dtOwnerLPTBalance = await pool.sharesBalance(
|
||||||
|
contracts.accounts[0],
|
||||||
|
poolAddress
|
||||||
|
)
|
||||||
expect(await pool.sharesBalance(contracts.accounts[0], poolAddress)).to.equal(
|
expect(await pool.sharesBalance(contracts.accounts[0], poolAddress)).to.equal(
|
||||||
await pool.sharesBalance(contracts.sideStakingAddress, poolAddress)
|
await pool.sharesBalance(contracts.sideStakingAddress, poolAddress)
|
||||||
)
|
)
|
||||||
@ -213,7 +242,7 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getSwapFee - should return the swap fee', async () => {
|
it('#getSwapFee - should return the swap fee', async () => {
|
||||||
expect(await pool.getSwapFee(poolAddress)).to.equal('0.001') //0.1%
|
expect(await pool.getSwapFee(poolAddress)).to.equal('0.001') // 0.1%
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getNormalizedWeight - should return the normalized weight', async () => {
|
it('#getNormalizedWeight - should return the normalized weight', async () => {
|
||||||
@ -224,23 +253,18 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getDenormalizedWeight - should return the denormalized weight', async () => {
|
it('#getDenormalizedWeight - should return the denormalized weight', async () => {
|
||||||
expect(await pool.getDenormalizedWeight(poolAddress, contracts.daiAddress)).to.equal(
|
expect(
|
||||||
'5'
|
await pool.getDenormalizedWeight(poolAddress, contracts.daiAddress)
|
||||||
)
|
).to.equal('5')
|
||||||
expect(await pool.getDenormalizedWeight(poolAddress, erc20Token)).to.equal('5')
|
expect(await pool.getDenormalizedWeight(poolAddress, erc20Token)).to.equal('5')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getBasetoken - should return the basetoken address', async () => {
|
it('#getBasetoken - should return the basetoken address', async () => {
|
||||||
expect(await pool.getBasetoken(poolAddress)).to.equal(
|
expect(await pool.getBasetoken(poolAddress)).to.equal(contracts.daiAddress)
|
||||||
contracts.daiAddress
|
|
||||||
)
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getDatatoken - should return the datatoken address', async () => {
|
it('#getDatatoken - should return the datatoken address', async () => {
|
||||||
expect(await pool.getDatatoken(poolAddress)).to.equal(
|
expect(await pool.getDatatoken(poolAddress)).to.equal(erc20Token)
|
||||||
erc20Token
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountIn - should swap', async () => {
|
it('#swapExactAmountIn - should swap', async () => {
|
||||||
@ -251,7 +275,7 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
web3.utils.toWei('1000')
|
web3.utils.toWei('1000')
|
||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
await pool.approve(user2, contracts.daiAddress, poolAddress, web3.utils.toWei('100'))
|
await pool.approve(user2, contracts.daiAddress, poolAddress, '10')
|
||||||
const tx = await pool.swapExactAmountIn(
|
const tx = await pool.swapExactAmountIn(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -266,7 +290,7 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountOut - should swap', async () => {
|
it('#swapExactAmountOut - should swap', async () => {
|
||||||
// await pool.approve(contracts.accounts[0],contracts.daiAddress,poolAddress,web3.utils.toWei('100'))
|
await pool.approve(user2, contracts.daiAddress, poolAddress, '100')
|
||||||
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
|
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
|
||||||
web3.utils.toWei('990')
|
web3.utils.toWei('990')
|
||||||
)
|
)
|
||||||
@ -288,23 +312,21 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
'50' // Amounts IN
|
'50' // Amounts IN
|
||||||
]
|
]
|
||||||
|
|
||||||
await pool.approve(user2, erc20Token, poolAddress, web3.utils.toWei('1000'))
|
await pool.approve(user2, erc20Token, poolAddress, '50')
|
||||||
await pool.approve(user2, contracts.daiAddress, poolAddress, '1000')
|
await pool.approve(user2, contracts.daiAddress, poolAddress, '50')
|
||||||
const tx = await pool.joinPool(user2, poolAddress, BPTAmountOut, maxAmountsIn)
|
const tx = await pool.joinPool(user2, poolAddress, BPTAmountOut, maxAmountsIn)
|
||||||
assert(tx != null)
|
assert(tx != null)
|
||||||
expect(await pool.sharesBalance(user2, poolAddress)).to.equal(BPTAmountOut)
|
expect(await pool.sharesBalance(user2, poolAddress)).to.equal(BPTAmountOut)
|
||||||
expect(tx.events.LOG_JOIN.event === 'LOG_JOIN')
|
expect(tx.events.LOG_JOIN.event === 'LOG_JOIN')
|
||||||
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
||||||
|
|
||||||
//console.log(tx)
|
|
||||||
// console.log(tx.events.LOG_JOIN)
|
|
||||||
// console.log(tx.events.LOG_BPT)
|
|
||||||
})
|
})
|
||||||
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
||||||
const daiAmountIn = '100'
|
const daiAmountIn = '100'
|
||||||
const minBPTOut = '0.1'
|
const minBPTOut = '0.1'
|
||||||
await pool.approve(user2, contracts.daiAddress, poolAddress, web3.utils.toWei('1000'))
|
await pool.approve(user2, contracts.daiAddress, poolAddress, '100', true)
|
||||||
|
expect(await pool.allowance(contracts.daiAddress, user2, poolAddress)).to.equal(
|
||||||
|
'100'
|
||||||
|
)
|
||||||
const tx = await pool.joinswapExternAmountIn(
|
const tx = await pool.joinswapExternAmountIn(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -319,7 +341,7 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
||||||
// 2 JOIN EVENTS BECAUSE SIDE STAKING ALSO STAKED DTs, TODO: we should add to whom has been sent in the LOG_BPT event
|
// 2 JOIN EVENTS BECAUSE SIDE STAKING ALSO STAKED DTs, TODO: we should add to whom has been sent in the LOG_BPT event
|
||||||
expect(tx.events.LOG_JOIN[0].returnValues.bptAmount).to.equal(
|
expect(tx.events.LOG_JOIN[0].returnValues.bptAmount).to.equal(
|
||||||
tx.events.LOG_JOIN[0].returnValues.bptAmount
|
tx.events.LOG_JOIN[1].returnValues.bptAmount
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -327,7 +349,7 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
const BPTAmountOut = '0.1'
|
const BPTAmountOut = '0.1'
|
||||||
const maxDAIIn = '100'
|
const maxDAIIn = '100'
|
||||||
|
|
||||||
await pool.approve(user2, contracts.daiAddress, poolAddress, web3.utils.toWei('1000'))
|
await pool.approve(user2, contracts.daiAddress, poolAddress, '100')
|
||||||
|
|
||||||
const tx = await pool.joinswapPoolAmountOut(
|
const tx = await pool.joinswapPoolAmountOut(
|
||||||
user2,
|
user2,
|
||||||
@ -343,7 +365,7 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
||||||
// 2 JOIN EVENTS BECAUSE SIDE STAKING ALSO STAKED DTs, TODO: we should add to whom has been sent in the LOG_BPT event
|
// 2 JOIN EVENTS BECAUSE SIDE STAKING ALSO STAKED DTs, TODO: we should add to whom has been sent in the LOG_BPT event
|
||||||
expect(tx.events.LOG_JOIN[0].returnValues.bptAmount).to.equal(
|
expect(tx.events.LOG_JOIN[0].returnValues.bptAmount).to.equal(
|
||||||
tx.events.LOG_JOIN[0].returnValues.bptAmount
|
tx.events.LOG_JOIN[1].returnValues.bptAmount
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -383,8 +405,8 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#exitswapExternAmountOut- user2 exit the pool receiving only DAI', async () => {
|
it('#exitswapExternAmountOut- user2 exit the pool receiving only DAI', async () => {
|
||||||
const maxBTPIn = "0.5"
|
const maxBTPIn = '0.5'
|
||||||
const exactDAIOut = "1"
|
const exactDAIOut = '1'
|
||||||
|
|
||||||
const tx = await pool.exitswapPoolAmountIn(
|
const tx = await pool.exitswapPoolAmountIn(
|
||||||
user2,
|
user2,
|
||||||
@ -403,8 +425,8 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getAmountInExactOut- should get the amount in for exact out', async () => {
|
it('#getAmountInExactOut- should get the amount in for exact out', async () => {
|
||||||
const maxBTPIn = "0.5"
|
const maxBTPIn = '0.5'
|
||||||
const exactDAIOut = "1"
|
const exactDAIOut = '1'
|
||||||
|
|
||||||
const amountIn = await pool.getAmountInExactOut(
|
const amountIn = await pool.getAmountInExactOut(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -417,14 +439,18 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
|
|
||||||
// console.log(tx)
|
// console.log(tx)
|
||||||
|
|
||||||
const spotPrice = await pool.getSpotPrice(poolAddress,erc20Token,contracts.daiAddress)
|
const spotPrice = await pool.getSpotPrice(
|
||||||
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.daiAddress
|
||||||
|
)
|
||||||
|
|
||||||
// amount of DAI In will be slightly bigger than spotPrice
|
// amount of DAI In will be slightly bigger than spotPrice
|
||||||
assert(amountIn >spotPrice)
|
assert(amountIn > spotPrice)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getAmountOutExactIn- should get the amount out for exact In', async () => {
|
it('#getAmountOutExactIn- should get the amount out for exact In', async () => {
|
||||||
const exactDTIn= "1"
|
const exactDTIn = '1'
|
||||||
|
|
||||||
const amountOut = await pool.getAmountOutExactIn(
|
const amountOut = await pool.getAmountOutExactIn(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -437,101 +463,111 @@ describe('Test a pool with DAI (18 Decimals)',()=>{
|
|||||||
|
|
||||||
console.log(amountOut)
|
console.log(amountOut)
|
||||||
|
|
||||||
const spotPrice = await pool.getSpotPrice(poolAddress,contracts.daiAddress,erc20Token)
|
const spotPrice = await pool.getSpotPrice(
|
||||||
|
poolAddress,
|
||||||
|
contracts.daiAddress,
|
||||||
|
erc20Token
|
||||||
|
)
|
||||||
console.log(spotPrice)
|
console.log(spotPrice)
|
||||||
// amount of DAI received will be slightly less than spotPrice
|
// amount of DAI received will be slightly less than spotPrice
|
||||||
assert(amountOut< spotPrice)
|
assert(amountOut < spotPrice)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getSpotPrice- should get the spot price', async () => {
|
it('#getSpotPrice- should get the spot price', async () => {
|
||||||
|
assert(
|
||||||
|
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) != null
|
||||||
assert(await pool.getSpotPrice(poolAddress,erc20Token,contracts.daiAddress) != null)
|
)
|
||||||
assert(await pool.getSpotPrice(poolAddress,contracts.daiAddress,erc20Token) != null)
|
assert(
|
||||||
|
(await pool.getSpotPrice(poolAddress, contracts.daiAddress, erc20Token)) != null
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getMarketFees- should get market fees for each token', async () => {
|
it('#getMarketFees- should get market fees for each token', async () => {
|
||||||
|
|
||||||
// we haven't performed any swap DT => DAI so there's no fee in erc20Token
|
// we haven't performed any swap DT => DAI so there's no fee in erc20Token
|
||||||
// but there's a fee in DAI
|
// but there's a fee in DAI
|
||||||
assert(await pool.getMarketFees(poolAddress,erc20Token) == '0')
|
assert((await pool.getMarketFees(poolAddress, erc20Token)) === '0')
|
||||||
assert(await pool.getMarketFees(poolAddress,contracts.daiAddress) > '0')
|
assert((await pool.getMarketFees(poolAddress, contracts.daiAddress)) > '0')
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getCommunityFees- should get community fees for each token', async () => {
|
it('#getCommunityFees- should get community fees for each token', async () => {
|
||||||
// we haven't performed any swap DT => DAI so there's no fee in erc20Token
|
// we haven't performed any swap DT => DAI so there's no fee in erc20Token
|
||||||
// but there's a fee in DAI
|
// but there's a fee in DAI
|
||||||
|
|
||||||
assert(await pool.getCommunityFees(poolAddress,erc20Token) == '0')
|
assert((await pool.getCommunityFees(poolAddress, erc20Token)) === '0')
|
||||||
assert(await pool.getCommunityFees(poolAddress,contracts.daiAddress) > '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) > '0')
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#collectMarketFee- should collect market fees for each token', async () => {
|
it('#collectMarketFee- should collect market fees for each token', async () => {
|
||||||
const spotPriceBefore = await pool.getSpotPrice(poolAddress,erc20Token,contracts.daiAddress)
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.daiAddress
|
||||||
|
)
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
assert(await pool.getMarketFeeCollector(poolAddress) == contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
// user3 has no DAI (we are going to send DAI fee to him)
|
// user3 has no DAI (we are going to send DAI fee to him)
|
||||||
assert(await daiContract.methods.balanceOf(user3).call() == '0')
|
assert((await daiContract.methods.balanceOf(user3).call()) === '0')
|
||||||
// only marketFeeCollector can call this, set user3 as receiver
|
// only marketFeeCollector can call this, set user3 as receiver
|
||||||
await pool.collectMarketFee(contracts.accounts[0],poolAddress,user3)
|
await pool.collectMarketFee(contracts.accounts[0], poolAddress, user3)
|
||||||
// DAI fees have been collected
|
// DAI fees have been collected
|
||||||
assert(await pool.getMarketFees(poolAddress,contracts.daiAddress) == '0')
|
assert((await pool.getMarketFees(poolAddress, contracts.daiAddress)) === '0')
|
||||||
// user3 got DAI
|
// user3 got DAI
|
||||||
assert(await daiContract.methods.balanceOf(user3).call() > '0')
|
assert((await daiContract.methods.balanceOf(user3).call()) > '0')
|
||||||
// Spot price hasn't changed after fee collection
|
// Spot price hasn't changed after fee collection
|
||||||
assert(await pool.getSpotPrice(poolAddress,erc20Token,contracts.daiAddress)== spotPriceBefore)
|
assert(
|
||||||
|
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) ===
|
||||||
|
spotPriceBefore
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
it('#getMarketFeeCollector- should get market fees for each token', async () => {
|
it('#getMarketFeeCollector- should get market fees for each token', async () => {
|
||||||
|
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
assert(await pool.getMarketFeeCollector(poolAddress) == contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
it('#getOPFCollector- should get market fees for each token', async () => {
|
it('#getOPFCollector- should get market fees for each token', async () => {
|
||||||
|
assert((await pool.getOPFCollector(poolAddress)) === contracts.opfCollectorAddress)
|
||||||
|
|
||||||
assert(await pool.getOPFCollector(poolAddress) == contracts.opfCollectorAddress)
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#collectCommunityFee- should get community fees for each token', async () => {
|
it('#collectCommunityFee- should get community fees for each token', async () => {
|
||||||
const spotPriceBefore = await pool.getSpotPrice(poolAddress,erc20Token,contracts.daiAddress)
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.daiAddress
|
||||||
|
)
|
||||||
// some fee are available in DAI
|
// some fee are available in DAI
|
||||||
assert(await pool.getCommunityFees(poolAddress,contracts.daiAddress) > '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) > '0')
|
||||||
// opf collector has no DAI
|
// opf collector has no DAI
|
||||||
assert(await daiContract.methods.balanceOf(contracts.opfCollectorAddress).call() == '0')
|
assert(
|
||||||
|
(await daiContract.methods.balanceOf(contracts.opfCollectorAddress).call()) ===
|
||||||
|
'0'
|
||||||
|
)
|
||||||
// anyone can call callectOPF
|
// anyone can call callectOPF
|
||||||
await pool.collectOPF(contracts.accounts[0],poolAddress)
|
await pool.collectOPF(contracts.accounts[0], poolAddress)
|
||||||
// DAI fees have been collected
|
// DAI fees have been collected
|
||||||
assert(await pool.getCommunityFees(poolAddress,contracts.daiAddress) == '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) === '0')
|
||||||
// OPF collector got DAI
|
// OPF collector got DAI
|
||||||
assert(await daiContract.methods.balanceOf(contracts.opfCollectorAddress).call() > '0')
|
assert(
|
||||||
|
(await daiContract.methods.balanceOf(contracts.opfCollectorAddress).call()) > '0'
|
||||||
|
)
|
||||||
// Spot price hasn't changed after fee collection
|
// Spot price hasn't changed after fee collection
|
||||||
assert(await pool.getSpotPrice(poolAddress,erc20Token,contracts.daiAddress)== spotPriceBefore)
|
assert(
|
||||||
|
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) ===
|
||||||
|
spotPriceBefore
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
||||||
|
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
assert(await pool.getMarketFeeCollector(poolAddress) == contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
|
|
||||||
await pool.updateMarketFeeCollector(contracts.accounts[0],poolAddress,user3)
|
await pool.updateMarketFeeCollector(contracts.accounts[0], poolAddress, user3)
|
||||||
|
|
||||||
assert(await pool.getMarketFeeCollector(poolAddress) == user3)
|
|
||||||
|
|
||||||
|
assert((await pool.getMarketFeeCollector(poolAddress)) === user3)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe('Test a pool with USDC (6 Decimals)',()=>{
|
describe('Test a pool with USDC (6 Decimals)', () => {
|
||||||
it('#create a pool', async () => {
|
it('#create a pool', async () => {
|
||||||
// CREATE A POOL
|
// CREATE A POOL
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
@ -553,7 +589,10 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
uints: [web3.utils.toWei('1000000'), 0],
|
uints: [web3.utils.toWei('1000000'), 0],
|
||||||
bytess: []
|
bytess: []
|
||||||
}
|
}
|
||||||
|
const basetokenInitialLiq = Number(
|
||||||
|
await pool.amountToUnits(contracts.usdcAddress, '2000')
|
||||||
|
)
|
||||||
|
console.log(basetokenInitialLiq.toString())
|
||||||
const poolData = {
|
const poolData = {
|
||||||
addresses: [
|
addresses: [
|
||||||
contracts.sideStakingAddress,
|
contracts.sideStakingAddress,
|
||||||
@ -565,10 +604,10 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
],
|
],
|
||||||
ssParams: [
|
ssParams: [
|
||||||
web3.utils.toWei('1'), // rate
|
web3.utils.toWei('1'), // rate
|
||||||
6, // basetokenDecimals
|
await usdcContract.methods.decimals().call(), // basetokenDecimals
|
||||||
web3.utils.toWei('10000'),
|
web3.utils.toWei('10000'),
|
||||||
2500000, // vested blocks
|
2500000, // vested blocks
|
||||||
2000 * 1e6 // baseToken initial pool liquidity
|
basetokenInitialLiq // baseToken initial pool liquidity
|
||||||
],
|
],
|
||||||
swapFees: [
|
swapFees: [
|
||||||
1e15, //
|
1e15, //
|
||||||
@ -605,7 +644,10 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
|
|
||||||
it('#getPoolSharesTotalSupply - should return totalSupply of LPT', async () => {
|
it('#getPoolSharesTotalSupply - should return totalSupply of LPT', async () => {
|
||||||
// dt owner which added liquidity has half of pool shares (the rest is in the sidestaking contracta)
|
// dt owner which added liquidity has half of pool shares (the rest is in the sidestaking contracta)
|
||||||
const dtOwnerLPTBalance = await pool.sharesBalance(contracts.accounts[0], poolAddress)
|
const dtOwnerLPTBalance = await pool.sharesBalance(
|
||||||
|
contracts.accounts[0],
|
||||||
|
poolAddress
|
||||||
|
)
|
||||||
expect(await pool.sharesBalance(contracts.accounts[0], poolAddress)).to.equal(
|
expect(await pool.sharesBalance(contracts.accounts[0], poolAddress)).to.equal(
|
||||||
await pool.sharesBalance(contracts.sideStakingAddress, poolAddress)
|
await pool.sharesBalance(contracts.sideStakingAddress, poolAddress)
|
||||||
)
|
)
|
||||||
@ -635,7 +677,7 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
expect(await pool.isBound(poolAddress, contracts.oceanAddress)).to.equal(false)
|
expect(await pool.isBound(poolAddress, contracts.oceanAddress)).to.equal(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getReserve - should return final pool tokens', async () => {
|
it('#getReserve - should return final pool tokens Reserve', async () => {
|
||||||
expect(await pool.getReserve(poolAddress, contracts.usdcAddress)).to.equal('2000') // base token initial liquidity
|
expect(await pool.getReserve(poolAddress, contracts.usdcAddress)).to.equal('2000') // base token initial liquidity
|
||||||
// rate is 1 so we have the same amount of DTs
|
// rate is 1 so we have the same amount of DTs
|
||||||
expect(await pool.getReserve(poolAddress, erc20Token)).to.equal('2000')
|
expect(await pool.getReserve(poolAddress, erc20Token)).to.equal('2000')
|
||||||
@ -647,7 +689,7 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getSwapFee - should return the swap fee', async () => {
|
it('#getSwapFee - should return the swap fee', async () => {
|
||||||
expect(await pool.getSwapFee(poolAddress)).to.equal('0.001') //0.1%
|
expect(await pool.getSwapFee(poolAddress)).to.equal('0.001') // 0.1%
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getNormalizedWeight - should return the normalized weight', async () => {
|
it('#getNormalizedWeight - should return the normalized weight', async () => {
|
||||||
@ -658,35 +700,31 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getDenormalizedWeight - should return the denormalized weight', async () => {
|
it('#getDenormalizedWeight - should return the denormalized weight', async () => {
|
||||||
expect(await pool.getDenormalizedWeight(poolAddress, contracts.usdcAddress)).to.equal(
|
expect(
|
||||||
'5'
|
await pool.getDenormalizedWeight(poolAddress, contracts.usdcAddress)
|
||||||
)
|
).to.equal('5')
|
||||||
expect(await pool.getDenormalizedWeight(poolAddress, erc20Token)).to.equal('5')
|
expect(await pool.getDenormalizedWeight(poolAddress, erc20Token)).to.equal('5')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getBasetoken - should return the basetoken address', async () => {
|
it('#getBasetoken - should return the basetoken address', async () => {
|
||||||
expect(await pool.getBasetoken(poolAddress)).to.equal(
|
expect(await pool.getBasetoken(poolAddress)).to.equal(contracts.usdcAddress)
|
||||||
contracts.usdcAddress
|
|
||||||
)
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getDatatoken - should return the datatoken address', async () => {
|
it('#getDatatoken - should return the datatoken address', async () => {
|
||||||
expect(await pool.getDatatoken(poolAddress)).to.equal(
|
expect(await pool.getDatatoken(poolAddress)).to.equal(erc20Token)
|
||||||
erc20Token
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountIn - should swap', async () => {
|
it('#swapExactAmountIn - should swap', async () => {
|
||||||
const transferAmount = 1e9 // 1000 USDC
|
const transferAmount = await pool.amountToUnits(contracts.usdcAddress, '1000') // 1000 USDC
|
||||||
await usdcContract.methods
|
await usdcContract.methods
|
||||||
.transfer(user2, transferAmount)
|
.transfer(user2, transferAmount)
|
||||||
.send({ from: contracts.accounts[0] })
|
.send({ from: contracts.accounts[0] })
|
||||||
expect(await usdcContract.methods.balanceOf(user2).call()).to.equal(
|
expect(await usdcContract.methods.balanceOf(user2).call()).to.equal(
|
||||||
transferAmount.toString())
|
transferAmount.toString()
|
||||||
|
)
|
||||||
|
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
await pool.approve(user2, contracts.usdcAddress, poolAddress, web3.utils.toWei('100'))
|
await pool.approve(user2, contracts.usdcAddress, poolAddress, '10')
|
||||||
const tx = await pool.swapExactAmountIn(
|
const tx = await pool.swapExactAmountIn(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -701,10 +739,10 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountOut - should swap', async () => {
|
it('#swapExactAmountOut - should swap', async () => {
|
||||||
|
|
||||||
expect(await usdcContract.methods.balanceOf(user2).call()).to.equal(
|
expect(await usdcContract.methods.balanceOf(user2).call()).to.equal(
|
||||||
(990*1e6).toString()
|
(await pool.amountToUnits(contracts.usdcAddress, '990')).toString()
|
||||||
)
|
)
|
||||||
|
await pool.approve(user2, contracts.usdcAddress, poolAddress, '100')
|
||||||
const tx = await pool.swapExactAmountOut(
|
const tx = await pool.swapExactAmountOut(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -714,7 +752,7 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
'50'
|
'50'
|
||||||
)
|
)
|
||||||
assert(tx != null)
|
assert(tx != null)
|
||||||
//console.log(tx.events)
|
// console.log(tx.events)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#joinPool- user2 should add liquidity, receiving LP tokens', async () => {
|
it('#joinPool- user2 should add liquidity, receiving LP tokens', async () => {
|
||||||
@ -724,22 +762,22 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
'50' // Amounts IN
|
'50' // Amounts IN
|
||||||
]
|
]
|
||||||
|
|
||||||
await pool.approve(user2, erc20Token, poolAddress, web3.utils.toWei('1000'))
|
await pool.approve(user2, erc20Token, poolAddress, '50')
|
||||||
await pool.approve(user2, contracts.usdcAddress, poolAddress, '1000')
|
await pool.approve(user2, contracts.usdcAddress, poolAddress, '50')
|
||||||
const tx = await pool.joinPool(user2, poolAddress, BPTAmountOut, maxAmountsIn)
|
const tx = await pool.joinPool(user2, poolAddress, BPTAmountOut, maxAmountsIn)
|
||||||
assert(tx != null)
|
assert(tx != null)
|
||||||
expect(await pool.sharesBalance(user2, poolAddress)).to.equal(BPTAmountOut)
|
expect(await pool.sharesBalance(user2, poolAddress)).to.equal(BPTAmountOut)
|
||||||
expect(tx.events.LOG_JOIN.event === 'LOG_JOIN')
|
expect(tx.events.LOG_JOIN.event === 'LOG_JOIN')
|
||||||
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
||||||
|
|
||||||
//console.log(tx)
|
// console.log(tx)
|
||||||
// console.log(tx.events.LOG_JOIN)
|
// console.log(tx.events.LOG_JOIN)
|
||||||
// console.log(tx.events.LOG_BPT)
|
// console.log(tx.events.LOG_BPT)
|
||||||
})
|
})
|
||||||
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
||||||
const usdcAmountIn = '100'
|
const usdcAmountIn = '100'
|
||||||
const minBPTOut = '0.1'
|
const minBPTOut = '0.1'
|
||||||
await pool.approve(user2, contracts.usdcAddress, poolAddress, web3.utils.toWei('1000'))
|
await pool.approve(user2, contracts.usdcAddress, poolAddress, '100', true)
|
||||||
|
|
||||||
const tx = await pool.joinswapExternAmountIn(
|
const tx = await pool.joinswapExternAmountIn(
|
||||||
user2,
|
user2,
|
||||||
@ -755,7 +793,7 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
||||||
// 2 JOIN EVENTS BECAUSE SIDE STAKING ALSO STAKED DTs, TODO: we should add to whom has been sent in the LOG_BPT event
|
// 2 JOIN EVENTS BECAUSE SIDE STAKING ALSO STAKED DTs, TODO: we should add to whom has been sent in the LOG_BPT event
|
||||||
expect(tx.events.LOG_JOIN[0].returnValues.bptAmount).to.equal(
|
expect(tx.events.LOG_JOIN[0].returnValues.bptAmount).to.equal(
|
||||||
tx.events.LOG_JOIN[0].returnValues.bptAmount
|
tx.events.LOG_JOIN[1].returnValues.bptAmount
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -763,7 +801,7 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
const BPTAmountOut = '0.1'
|
const BPTAmountOut = '0.1'
|
||||||
const maxUSDCIn = '100'
|
const maxUSDCIn = '100'
|
||||||
|
|
||||||
await pool.approve(user2, contracts.usdcAddress, poolAddress, web3.utils.toWei('1000'))
|
await pool.approve(user2, contracts.usdcAddress, poolAddress, '100')
|
||||||
|
|
||||||
const tx = await pool.joinswapPoolAmountOut(
|
const tx = await pool.joinswapPoolAmountOut(
|
||||||
user2,
|
user2,
|
||||||
@ -779,7 +817,7 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
expect(tx.events.LOG_BPT.event === 'LOG_BPT')
|
||||||
// 2 JOIN EVENTS BECAUSE SIDE STAKING ALSO STAKED DTs, TODO: we should add to whom has been sent in the LOG_BPT event
|
// 2 JOIN EVENTS BECAUSE SIDE STAKING ALSO STAKED DTs, TODO: we should add to whom has been sent in the LOG_BPT event
|
||||||
expect(tx.events.LOG_JOIN[0].returnValues.bptAmount).to.equal(
|
expect(tx.events.LOG_JOIN[0].returnValues.bptAmount).to.equal(
|
||||||
tx.events.LOG_JOIN[0].returnValues.bptAmount
|
tx.events.LOG_JOIN[1].returnValues.bptAmount
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -819,8 +857,8 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#exitswapExternAmountOut- user2 exit the pool receiving only USDC', async () => {
|
it('#exitswapExternAmountOut- user2 exit the pool receiving only USDC', async () => {
|
||||||
const maxBTPIn = "0.5"
|
const maxBTPIn = '0.5'
|
||||||
const exactUSDCOut = "1"
|
const exactUSDCOut = '1'
|
||||||
|
|
||||||
const tx = await pool.exitswapPoolAmountIn(
|
const tx = await pool.exitswapPoolAmountIn(
|
||||||
user2,
|
user2,
|
||||||
@ -839,8 +877,8 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#getAmountInExactOut- should get the amount in for exact out', async () => {
|
it('#getAmountInExactOut- should get the amount in for exact out', async () => {
|
||||||
const maxBTPIn = "0.5"
|
const maxBTPIn = '0.5'
|
||||||
const exactUSDCOut = "1"
|
const exactUSDCOut = '1'
|
||||||
|
|
||||||
const amountIn = await pool.getAmountInExactOut(
|
const amountIn = await pool.getAmountInExactOut(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -853,14 +891,18 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
|
|
||||||
console.log(amountIn.toString())
|
console.log(amountIn.toString())
|
||||||
|
|
||||||
const spotPrice = await pool.getSpotPrice(poolAddress,erc20Token,contracts.usdcAddress)
|
const spotPrice = await pool.getSpotPrice(
|
||||||
console.log(spotPrice.toString())
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.usdcAddress
|
||||||
|
)
|
||||||
|
console.log(spotPrice.toString(), 'spotPrice')
|
||||||
// amount of USDC In will be slightly bigger than spotPrice
|
// amount of USDC In will be slightly bigger than spotPrice
|
||||||
// assert(amountIn >spotPrice)
|
assert(amountIn > spotPrice)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getAmountOutExactIn- should get the amount out for exact In', async () => {
|
it('#getAmountOutExactIn- should get the amount out for exact In', async () => {
|
||||||
const exactDTIn= "1"
|
const exactDTIn = '1'
|
||||||
|
|
||||||
const amountOut = await pool.getAmountOutExactIn(
|
const amountOut = await pool.getAmountOutExactIn(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -873,98 +915,107 @@ describe('Test a pool with USDC (6 Decimals)',()=>{
|
|||||||
|
|
||||||
console.log(amountOut)
|
console.log(amountOut)
|
||||||
|
|
||||||
const spotPrice = await pool.getSpotPrice(poolAddress,contracts.usdcAddress,erc20Token)
|
const spotPrice = await pool.getSpotPrice(
|
||||||
console.log(spotPrice)
|
poolAddress,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
erc20Token
|
||||||
|
)
|
||||||
|
console.log(spotPrice, 'spotPrice')
|
||||||
// amount of USDC received will be slightly less than spotPrice
|
// amount of USDC received will be slightly less than spotPrice
|
||||||
// assert(amountOut< spotPrice)
|
assert(amountOut < spotPrice)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getSpotPrice- should get the spot price', async () => {
|
it('#getSpotPrice- should get the spot price', async () => {
|
||||||
|
assert(
|
||||||
|
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) != null
|
||||||
assert(await pool.getSpotPrice(poolAddress,erc20Token,contracts.usdcAddress) != null)
|
)
|
||||||
assert(await pool.getSpotPrice(poolAddress,contracts.usdcAddress,erc20Token) != null)
|
assert(
|
||||||
|
(await pool.getSpotPrice(poolAddress, contracts.usdcAddress, erc20Token)) != null
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getMarketFees- should get market fees for each token', async () => {
|
it('#getMarketFees- should get market fees for each token', async () => {
|
||||||
|
|
||||||
// we haven't performed any swap DT => USDC so there's no fee in erc20Token
|
// we haven't performed any swap DT => USDC so there's no fee in erc20Token
|
||||||
// but there's a fee in USDC
|
// but there's a fee in USDC
|
||||||
assert(await pool.getMarketFees(poolAddress,erc20Token) == '0')
|
assert((await pool.getMarketFees(poolAddress, erc20Token)) === '0')
|
||||||
assert(await pool.getMarketFees(poolAddress,contracts.usdcAddress) > '0')
|
assert((await pool.getMarketFees(poolAddress, contracts.usdcAddress)) > '0')
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getCommunityFees- should get community fees for each token', async () => {
|
it('#getCommunityFees- should get community fees for each token', async () => {
|
||||||
// we haven't performed any swap DT => USDC so there's no fee in erc20Token
|
// we haven't performed any swap DT => USDC so there's no fee in erc20Token
|
||||||
// but there's a fee in USDC
|
// but there's a fee in USDC
|
||||||
|
|
||||||
assert(await pool.getCommunityFees(poolAddress,erc20Token) == '0')
|
assert((await pool.getCommunityFees(poolAddress, erc20Token)) === '0')
|
||||||
assert(await pool.getCommunityFees(poolAddress,contracts.usdcAddress) > '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) > '0')
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#collectMarketFee- should collect market fees for each token', async () => {
|
it('#collectMarketFee- should collect market fees for each token', async () => {
|
||||||
const spotPriceBefore = await pool.getSpotPrice(poolAddress,erc20Token,contracts.usdcAddress)
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.usdcAddress
|
||||||
|
)
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
assert(await pool.getMarketFeeCollector(poolAddress) == contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
// user3 has no USDC (we are going to send USDC fee to him)
|
// user3 has no USDC (we are going to send USDC fee to him)
|
||||||
assert(await usdcContract.methods.balanceOf(user3).call() == '0')
|
assert((await usdcContract.methods.balanceOf(user3).call()) === '0')
|
||||||
// only marketFeeCollector can call this, set user3 as receiver
|
// only marketFeeCollector can call this, set user3 as receiver
|
||||||
await pool.collectMarketFee(contracts.accounts[0],poolAddress,user3)
|
await pool.collectMarketFee(contracts.accounts[0], poolAddress, user3)
|
||||||
// USDC fees have been collected
|
// USDC fees have been collected
|
||||||
assert(await pool.getMarketFees(poolAddress,contracts.usdcAddress) == '0')
|
assert((await pool.getMarketFees(poolAddress, contracts.usdcAddress)) === '0')
|
||||||
// user3 got USDC
|
// user3 got USDC
|
||||||
assert(await usdcContract.methods.balanceOf(user3).call() > '0')
|
assert((await usdcContract.methods.balanceOf(user3).call()) > '0')
|
||||||
// Spot price hasn't changed after fee collection
|
// Spot price hasn't changed after fee collection
|
||||||
assert(await pool.getSpotPrice(poolAddress,erc20Token,contracts.usdcAddress)== spotPriceBefore)
|
assert(
|
||||||
|
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) ===
|
||||||
|
spotPriceBefore
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
it('#getMarketFeeCollector- should get market fees for each token', async () => {
|
it('#getMarketFeeCollector- should get market fees for each token', async () => {
|
||||||
|
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
assert(await pool.getMarketFeeCollector(poolAddress) == contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
it('#getOPFCollector- should get market fees for each token', async () => {
|
it('#getOPFCollector- should get market fees for each token', async () => {
|
||||||
|
assert((await pool.getOPFCollector(poolAddress)) === contracts.opfCollectorAddress)
|
||||||
|
|
||||||
assert(await pool.getOPFCollector(poolAddress) == contracts.opfCollectorAddress)
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#collectCommunityFee- should get community fees for each token', async () => {
|
it('#collectCommunityFee- should get community fees for each token', async () => {
|
||||||
const spotPriceBefore = await pool.getSpotPrice(poolAddress,erc20Token,contracts.usdcAddress)
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.usdcAddress
|
||||||
|
)
|
||||||
// some fee are available in USDC
|
// some fee are available in USDC
|
||||||
assert(await pool.getCommunityFees(poolAddress,contracts.usdcAddress) > '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) > '0')
|
||||||
// opf collector has no USDC
|
// opf collector has no USDC
|
||||||
assert(await usdcContract.methods.balanceOf(contracts.opfCollectorAddress).call() == '0')
|
assert(
|
||||||
|
(await usdcContract.methods.balanceOf(contracts.opfCollectorAddress).call()) ===
|
||||||
|
'0'
|
||||||
|
)
|
||||||
// anyone can call callectOPF
|
// anyone can call callectOPF
|
||||||
await pool.collectOPF(contracts.accounts[0],poolAddress)
|
await pool.collectOPF(contracts.accounts[0], poolAddress)
|
||||||
// USDC fees have been collected
|
// USDC fees have been collected
|
||||||
assert(await pool.getCommunityFees(poolAddress,contracts.usdcAddress) == '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) === '0')
|
||||||
// OPF collector got USDC
|
// OPF collector got USDC
|
||||||
assert(await usdcContract.methods.balanceOf(contracts.opfCollectorAddress).call() > '0')
|
assert(
|
||||||
|
(await usdcContract.methods.balanceOf(contracts.opfCollectorAddress).call()) > '0'
|
||||||
|
)
|
||||||
// Spot price hasn't changed after fee collection
|
// Spot price hasn't changed after fee collection
|
||||||
assert(await pool.getSpotPrice(poolAddress,erc20Token,contracts.usdcAddress)== spotPriceBefore)
|
assert(
|
||||||
|
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) ===
|
||||||
|
spotPriceBefore
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
||||||
|
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
assert(await pool.getMarketFeeCollector(poolAddress) == contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
|
|
||||||
await pool.updateMarketFeeCollector(contracts.accounts[0],poolAddress,user3)
|
await pool.updateMarketFeeCollector(contracts.accounts[0], poolAddress, user3)
|
||||||
|
|
||||||
assert(await pool.getMarketFeeCollector(poolAddress) == user3)
|
|
||||||
|
|
||||||
|
assert((await pool.getMarketFeeCollector(poolAddress)) === user3)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user