mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix bug when amountOut>=balanceOut
This commit is contained in:
parent
7d15d2d1d9
commit
d3f6cfd05c
@ -8,6 +8,9 @@ import { MetadataCache } from '../metadatacache/MetadataCache'
|
||||
import { didNoZeroX, didPrefixed } from '../utils'
|
||||
declare type PoolTransactionType = 'swap' | 'join' | 'exit'
|
||||
|
||||
const POOL_MAX_AMOUNT_IN_LIMIT = 0.25 // maximum 1/4 of the pool reserve
|
||||
const POOL_MAX_AMOUNT_OUT_LIMIT = 0.25 // maximum 1/4 of the pool reserve
|
||||
|
||||
export interface PoolDetails {
|
||||
poolAddress: string
|
||||
tokens: string[]
|
||||
@ -449,7 +452,7 @@ export class OceanPool extends Pool {
|
||||
const balance = await super.getReserve(poolAddress, tokenAddress)
|
||||
if (parseFloat(balance) > 0) {
|
||||
const result = new BigNumber(this.web3.utils.toWei(balance))
|
||||
.dividedBy(3)
|
||||
.multipliedBy(POOL_MAX_AMOUNT_IN_LIMIT)
|
||||
.integerValue(BigNumber.ROUND_DOWN)
|
||||
.minus(1)
|
||||
return this.web3.utils.fromWei(result.toString())
|
||||
@ -468,7 +471,7 @@ export class OceanPool extends Pool {
|
||||
const balance = await super.getReserve(poolAddress, tokenAddress)
|
||||
if (parseFloat(balance) > 0) {
|
||||
const result = new BigNumber(this.web3.utils.toWei(balance))
|
||||
.dividedBy(4)
|
||||
.multipliedBy(POOL_MAX_AMOUNT_OUT_LIMIT)
|
||||
.integerValue(BigNumber.ROUND_DOWN)
|
||||
.minus(1)
|
||||
return this.web3.utils.fromWei(result.toString())
|
||||
|
@ -812,6 +812,7 @@ export class Pool extends PoolFactory {
|
||||
): Promise<string> {
|
||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||
let amount = null
|
||||
if (parseFloat(tokenAmountOut) >= parseFloat(tokenBalanceOut)) return null
|
||||
try {
|
||||
const result = await pool.methods
|
||||
.calcInGivenOut(
|
||||
|
Loading…
x
Reference in New Issue
Block a user