mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix lint
This commit is contained in:
parent
475855d899
commit
65ab6c2c23
@ -759,7 +759,7 @@ export class Pool {
|
||||
|
||||
try {
|
||||
decimals = await tokenContract.methods.decimals().call()
|
||||
if (decimals == 0){
|
||||
if (decimals === 0) {
|
||||
decimals = 18
|
||||
}
|
||||
} catch (e) {
|
||||
@ -779,7 +779,7 @@ export class Pool {
|
||||
)
|
||||
try {
|
||||
decimals = await tokenContract.methods.decimals().call()
|
||||
if (decimals == 0){
|
||||
if (decimals === 0) {
|
||||
decimals = 18
|
||||
}
|
||||
} catch (e) {
|
||||
@ -1522,7 +1522,6 @@ export class Pool {
|
||||
.call()
|
||||
|
||||
amount = await this.unitsToAmount(tokenOut, result)
|
||||
|
||||
} catch (e) {
|
||||
this.logger.error('ERROR: Failed to calcOutGivenIn')
|
||||
}
|
||||
@ -1538,10 +1537,7 @@ export class Pool {
|
||||
let amount = null
|
||||
try {
|
||||
const result = await pool.methods
|
||||
.calcPoolOutSingleIn(
|
||||
tokenIn,
|
||||
await this.amountToUnits(tokenIn,tokenAmountIn)
|
||||
)
|
||||
.calcPoolOutSingleIn(tokenIn, await this.amountToUnits(tokenIn, tokenAmountIn))
|
||||
.call()
|
||||
amount = await this.unitsToAmount(poolAddress, result)
|
||||
} catch (e) {
|
||||
@ -1553,7 +1549,7 @@ export class Pool {
|
||||
public async calcSingleInGivenPoolOut(
|
||||
poolAddress: string,
|
||||
tokenIn: string,
|
||||
poolAmountOut: string,
|
||||
poolAmountOut: string
|
||||
): Promise<string> {
|
||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||
let amount = null
|
||||
@ -1562,15 +1558,11 @@ export class Pool {
|
||||
|
||||
try {
|
||||
const result = await pool.methods
|
||||
.calcSingleInPoolOut(
|
||||
tokenIn,
|
||||
amountFormatted
|
||||
)
|
||||
.calcSingleInPoolOut(tokenIn, amountFormatted)
|
||||
|
||||
.call()
|
||||
|
||||
amount = await this.unitsToAmount(tokenIn, result)
|
||||
|
||||
} catch (e) {
|
||||
this.logger.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`)
|
||||
}
|
||||
@ -1607,10 +1599,7 @@ export class Pool {
|
||||
let amount = null
|
||||
try {
|
||||
const result = await pool.methods
|
||||
.calcPoolInSingleOut(
|
||||
tokenOut,
|
||||
await this.amountToUnits(tokenOut,tokenAmountOut)
|
||||
)
|
||||
.calcPoolInSingleOut(tokenOut, await this.amountToUnits(tokenOut, tokenAmountOut))
|
||||
.call()
|
||||
|
||||
amount = await this.unitsToAmount(poolAddress, result)
|
||||
|
@ -641,39 +641,70 @@ describe('Pool unit test', () => {
|
||||
// since rate is 1 and the pool is just created
|
||||
// amount of pool out received for same amount of different token In is equal
|
||||
const tokenInAmount = '10' // 10 USDC or 10 DTs
|
||||
expect(await pool.calcPoolOutGivenSingleIn(poolAddress, erc20Token, tokenInAmount)).to.equal(
|
||||
await pool.calcPoolOutGivenSingleIn(poolAddress, contracts.usdcAddress, tokenInAmount)
|
||||
expect(
|
||||
await pool.calcPoolOutGivenSingleIn(poolAddress, erc20Token, tokenInAmount)
|
||||
).to.equal(
|
||||
await pool.calcPoolOutGivenSingleIn(
|
||||
poolAddress,
|
||||
contracts.usdcAddress,
|
||||
tokenInAmount
|
||||
)
|
||||
)
|
||||
// console.log(await pool.calcPoolOutGivenSingleIn(poolAddress, erc20Token, tokenInAmount))
|
||||
})
|
||||
|
||||
|
||||
it('#calcSingleInGivenPoolOut - should get the amount of token IN for exact pool token OUT', async () => {
|
||||
// since rate is 1 and the pool is just created
|
||||
// amount of different token In for getting same pool amount out is equal
|
||||
const poolAmountOut = '1'
|
||||
expect(parseInt(await pool.calcSingleInGivenPoolOut(poolAddress, erc20Token, poolAmountOut))).to.be.closeTo(
|
||||
parseInt(await pool.calcSingleInGivenPoolOut(poolAddress, contracts.usdcAddress, poolAmountOut)),1e9
|
||||
expect(
|
||||
parseInt(
|
||||
await pool.calcSingleInGivenPoolOut(poolAddress, erc20Token, poolAmountOut)
|
||||
)
|
||||
).to.be.closeTo(
|
||||
parseInt(
|
||||
await pool.calcSingleInGivenPoolOut(
|
||||
poolAddress,
|
||||
contracts.usdcAddress,
|
||||
poolAmountOut
|
||||
)
|
||||
),
|
||||
1e9
|
||||
)
|
||||
|
||||
})
|
||||
|
||||
it('#calcSingleOutGivenPoolIn - should get the amount of token OUT for exact pool token IN', async () => {
|
||||
// since rate is 1 and the pool is just created
|
||||
// amount amount of different token Out for rediming the same pool In is equal
|
||||
const poolAmountIn = '10'
|
||||
expect(await pool.calcSingleOutGivenPoolIn(poolAddress, erc20Token, poolAmountIn)).to.equal(
|
||||
await pool.calcSingleOutGivenPoolIn(poolAddress, contracts.usdcAddress, poolAmountIn)
|
||||
expect(
|
||||
await pool.calcSingleOutGivenPoolIn(poolAddress, erc20Token, poolAmountIn)
|
||||
).to.equal(
|
||||
await pool.calcSingleOutGivenPoolIn(
|
||||
poolAddress,
|
||||
contracts.usdcAddress,
|
||||
poolAmountIn
|
||||
)
|
||||
)
|
||||
|
||||
})
|
||||
|
||||
it('#calcPoolInGivenSingleOut - should get the amount of pool IN for exact token OUT', async () => {
|
||||
// since rate is 1 and the pool is just created
|
||||
// amount of pool In for getting the same amount of different token Out is equal
|
||||
const tokenAmountOut = '10'
|
||||
expect(parseInt(await pool.calcPoolInGivenSingleOut(poolAddress, erc20Token,tokenAmountOut))).to.be.closeTo(
|
||||
parseInt(await pool.calcPoolInGivenSingleOut(poolAddress, contracts.usdcAddress, tokenAmountOut)),1e9
|
||||
expect(
|
||||
parseInt(
|
||||
await pool.calcPoolInGivenSingleOut(poolAddress, erc20Token, tokenAmountOut)
|
||||
)
|
||||
).to.be.closeTo(
|
||||
parseInt(
|
||||
await pool.calcPoolInGivenSingleOut(
|
||||
poolAddress,
|
||||
contracts.usdcAddress,
|
||||
tokenAmountOut
|
||||
)
|
||||
),
|
||||
1e11
|
||||
)
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user