From 6ba81c60f7f715a9c2fe3508cc0d9d005c56cbc3 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Wed, 7 Oct 2020 13:42:28 +0300 Subject: [PATCH] fix incorrect dtAddress Signed-off-by: mihaisc --- src/balancer/OceanPool.ts | 33 ++++++++++++++------------------- src/balancer/Pool.ts | 2 +- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/balancer/OceanPool.ts b/src/balancer/OceanPool.ts index 06f13b8c..930d92e6 100644 --- a/src/balancer/OceanPool.ts +++ b/src/balancer/OceanPool.ts @@ -139,8 +139,8 @@ export class OceanPool extends Pool { * @return {String} */ public async getDTReserve(poolAddress: string): Promise { - await this.getDTAddress(poolAddress) - return super.getReserve(poolAddress, this.dtAddress) + const dtAddress = await this.getDTAddress(poolAddress) + return super.getReserve(poolAddress, dtAddress) } /** @@ -163,7 +163,7 @@ export class OceanPool extends Pool { console.error('oceanAddress is not defined') return null } - await this.getDTAddress(poolAddress) + const dtAddress = await this.getDTAddress(poolAddress) // TODO - check balances first await super.approve( @@ -178,7 +178,7 @@ export class OceanPool extends Pool { poolAddress, this.oceanAddress, oceanAmount, - this.dtAddress, + dtAddress, amount, maxPrice ) @@ -204,11 +204,11 @@ export class OceanPool extends Pool { console.error('oceanAddress is not defined') return null } - await this.getDTAddress(poolAddress) + const dtAddress = await this.getDTAddress(poolAddress) return this.swapExactAmountOut( account, poolAddress, - this.dtAddress, + dtAddress, amount, this.oceanAddress, oceanAmount, @@ -228,17 +228,12 @@ export class OceanPool extends Pool { poolAddress: string, amount: string ): Promise { - await this.getDTAddress(poolAddress) - await super.approve( - account, - this.dtAddress, - poolAddress, - this.web3.utils.toWei(amount) - ) + const dtAddress = await this.getDTAddress(poolAddress) + await super.approve(account, dtAddress, poolAddress, this.web3.utils.toWei(amount)) const result = await super.joinswapExternAmountIn( account, poolAddress, - this.dtAddress, + dtAddress, amount, '0' ) @@ -258,12 +253,12 @@ export class OceanPool extends Pool { amount: string, maximumPoolShares: string ): Promise { - await this.getDTAddress(poolAddress) + const dtAddress = await this.getDTAddress(poolAddress) // TODO Check balance of PoolShares before doing exit return this.exitswapExternAmountOut( account, poolAddress, - this.dtAddress, + dtAddress, amount, maximumPoolShares ) @@ -362,11 +357,11 @@ export class OceanPool extends Pool { } public async getOceanNeeded(poolAddress: string, dtRequired: string): Promise { - await this.getDTAddress(poolAddress) + const dtAddress = await this.getDTAddress(poolAddress) const tokenBalanceIn = await this.getReserve(poolAddress, this.oceanAddress) const tokenWeightIn = await this.getDenormalizedWeight(poolAddress, this.oceanAddress) - const tokenBalanceOut = await this.getReserve(poolAddress, this.dtAddress) - const tokenWeightOut = await this.getDenormalizedWeight(poolAddress, this.dtAddress) + const tokenBalanceOut = await this.getReserve(poolAddress, dtAddress) + const tokenWeightOut = await this.getDenormalizedWeight(poolAddress, dtAddress) const swapFee = await this.getSwapFee(poolAddress) return super.calcInGivenOut( tokenBalanceIn, diff --git a/src/balancer/Pool.ts b/src/balancer/Pool.ts index d630231a..c5b2799e 100644 --- a/src/balancer/Pool.ts +++ b/src/balancer/Pool.ts @@ -368,9 +368,9 @@ export class Pool extends PoolFactory { * @return {String} */ async getReserve(poolAddress: string, token: string): Promise { - const pool = new this.web3.eth.Contract(this.poolABI, poolAddress) let amount = null try { + const pool = new this.web3.eth.Contract(this.poolABI, poolAddress) const result = await pool.methods.getBalance(token).call() amount = this.web3.utils.fromWei(result) } catch (e) {