1
0
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:
alexcos20 2020-10-15 04:11:34 -07:00
parent 7d15d2d1d9
commit d3f6cfd05c
2 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,9 @@ import { MetadataCache } from '../metadatacache/MetadataCache'
import { didNoZeroX, didPrefixed } from '../utils' import { didNoZeroX, didPrefixed } from '../utils'
declare type PoolTransactionType = 'swap' | 'join' | 'exit' 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 { export interface PoolDetails {
poolAddress: string poolAddress: string
tokens: string[] tokens: string[]
@ -449,7 +452,7 @@ export class OceanPool extends Pool {
const balance = await super.getReserve(poolAddress, tokenAddress) const balance = await super.getReserve(poolAddress, tokenAddress)
if (parseFloat(balance) > 0) { if (parseFloat(balance) > 0) {
const result = new BigNumber(this.web3.utils.toWei(balance)) const result = new BigNumber(this.web3.utils.toWei(balance))
.dividedBy(3) .multipliedBy(POOL_MAX_AMOUNT_IN_LIMIT)
.integerValue(BigNumber.ROUND_DOWN) .integerValue(BigNumber.ROUND_DOWN)
.minus(1) .minus(1)
return this.web3.utils.fromWei(result.toString()) return this.web3.utils.fromWei(result.toString())
@ -468,7 +471,7 @@ export class OceanPool extends Pool {
const balance = await super.getReserve(poolAddress, tokenAddress) const balance = await super.getReserve(poolAddress, tokenAddress)
if (parseFloat(balance) > 0) { if (parseFloat(balance) > 0) {
const result = new BigNumber(this.web3.utils.toWei(balance)) const result = new BigNumber(this.web3.utils.toWei(balance))
.dividedBy(4) .multipliedBy(POOL_MAX_AMOUNT_OUT_LIMIT)
.integerValue(BigNumber.ROUND_DOWN) .integerValue(BigNumber.ROUND_DOWN)
.minus(1) .minus(1)
return this.web3.utils.fromWei(result.toString()) return this.web3.utils.fromWei(result.toString())

View File

@ -812,6 +812,7 @@ export class Pool extends PoolFactory {
): 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 amount = null let amount = null
if (parseFloat(tokenAmountOut) >= parseFloat(tokenBalanceOut)) return null
try { try {
const result = await pool.methods const result = await pool.methods
.calcInGivenOut( .calcInGivenOut(