From 7b8f08e3c13ef2782fc83a9eadefe2f7354df605 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Fri, 17 Jul 2020 02:51:04 -0700 Subject: [PATCH] refactor --- src/balancer/OceanPool.ts | 214 ++++++------ src/balancer/balancerlib.ts | 504 +++++++++++++++------------- src/ocean/Ocean.ts | 1 + test/unit/balancer/Balancer.test.ts | 139 ++++---- 4 files changed, 461 insertions(+), 397 deletions(-) diff --git a/src/balancer/OceanPool.ts b/src/balancer/OceanPool.ts index 3e394a6e..efadbdc8 100644 --- a/src/balancer/OceanPool.ts +++ b/src/balancer/OceanPool.ts @@ -1,55 +1,34 @@ -import { BalancerPool } from './balancerlib' +import { Pool } from './balancerlib' -export class OceanPool extends BalancerPool { +export class OceanPool extends Pool { /** Ocean related functions */ public oceanAddress: string = null public dtAddress: string = null constructor( web3: any, - account: string, FactoryABI: any = null, PoolABI: any = null, factoryAddress: string = null, - oceanAddress: string = null + oceanAddress: string = null, + gaslimit?: number ) { - super(web3, account, FactoryABI, PoolABI, factoryAddress) + super(web3, FactoryABI, PoolABI, factoryAddress, gaslimit) if (oceanAddress) { this.oceanAddress = oceanAddress } } - /* async getNetworkAddresses(): Promise { - if (this.factoryAddress && this.oceanAddress) { - return - } - const netId = await this.web3.eth.net.getId() - switch (netId) { - case 1: - if (!this.factoryAddress) - this.factoryAddress = '0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd' - if (!this.oceanAddress) - this.oceanAddress = '0x985dd3D42De1e256d09e1c10F112bCCB8015AD41' - break - case 42: - if (!this.factoryAddress) - this.factoryAddress = '0x8f7F78080219d4066A8036ccD30D588B416a40DB' - if (!this.oceanAddress) this.oceanAddress = null - break - default: - this.factoryAddress = null - this.oceanAddress = null - } - } */ - /** * create DataToken pool + @param {String} account * @param {String} token Data Token Address * @param {String} amount Data Token Amount * @param {String} weight Data Token Weight * @return {any} */ public async createDTPool( + account: string, token: string, amount: string, weight: string, @@ -64,7 +43,7 @@ export class OceanPool extends BalancerPool { console.error('Weight out of bounds (min 1, max9)') return null } - const address = await super.newPool() + const address = await super.createPool(account) const oceanWeight = 10 - parseFloat(weight) const oceanAmount = (parseFloat(amount) * oceanWeight) / parseFloat(weight) const tokens = [ @@ -80,65 +59,64 @@ export class OceanPool extends BalancerPool { } ] this.dtAddress = token - await super.addToPool(tokens) - await super.setSwapFee(fee) - if (finalize) await super.finalize() + await super.addToPool(account, address, tokens) + await super.setSwapFee(account, address, fee) + if (finalize) await super.finalize(account, address) return address } - /** - * Load a previous created DataToken pool - * @param {String} address Data Token Address - * @return {any} + /* Get DataToken address of token in this pool + * @param {String} account + * @param {String} poolAddress + * @return {string} */ - public async loadDTPool(address: string): Promise { - if (this.oceanAddress == null) { - console.error('oceanAddress is not defined') - return null - } - await super.loadPool(address) - const tokens = await this.getCurrentTokens() + public async getDTAddress(account: string, poolAddress: string): Promise{ + this.dtAddress = null + const tokens = await this.getCurrentTokens(account,poolAddress) let token for (token of tokens) { if (token !== this.oceanAddress) this.dtAddress = token } - return this + return this.dtAddress } /** * Get Ocean Token balance of a pool + * @param {String} account + * @param {String} poolAddress * @return {any} */ - public async getOceanBalance(): Promise { + public async getOceanReserve(account: string, poolAddress: string): Promise { if (this.oceanAddress == null) { console.error('oceanAddress is not defined') return null } - return super.getBalance(this.oceanAddress) + return super.getReserve(account, poolAddress, this.oceanAddress) } /** * Get Data Token balance of a pool + * @param {String} account + * @param {String} poolAddress * @return {any} */ - public async getDTBalance(): Promise { - if (this.dtAddress == null) { - console.error( - 'dtAddress is not defined. Did you do loadDTPool or createDTPool ?' - ) - return null - } - return super.getBalance(this.dtAddress) + public async getDTReserve(account: string, poolAddress: string): Promise { + await this.getDTAddress(account, poolAddress) + return super.getReserve(account, poolAddress, this.dtAddress) } /** * Buy Data Token from a pool + * @param {String} account + * @param {String} poolAddress * @param {String} amount Data Token Amount * @param {String} oceanAmount Ocean Token Amount payed * @param {String} maxPrice Maximum Price to pay * @return {any} */ public async buyDT( + account: string, + poolAddress: string, amount: string, oceanAmount: string, maxPrice: string @@ -147,21 +125,19 @@ export class OceanPool extends BalancerPool { console.error('oceanAddress is not defined') return null } - if (this.dtAddress == null) { - console.error( - 'dtAddress is not defined. Did you do loadDTPool or createDTPool ?' - ) - return null - } + await this.getDTAddress(account, poolAddress) // TODO - check balances first await super.approve( + account, this.oceanAddress, - this.poolAddress, + poolAddress, this.web3.utils.toWei(oceanAmount) ) return this.swapExactAmountOut( + account, + poolAddress, this.oceanAddress, oceanAmount, this.dtAddress, @@ -172,12 +148,16 @@ export class OceanPool extends BalancerPool { /** * Sell Data Token + * @param {String} account + * @param {String} poolAddress * @param {String} amount Data Token Amount * @param {String} oceanAmount Ocean Token Amount expected * @param {String} maxPrice Minimum Price to sell * @return {any} */ public async sellDT( + account: string, + poolAddress: string, amount: string, oceanAmount: string, minPrice: string @@ -186,13 +166,10 @@ export class OceanPool extends BalancerPool { console.error('oceanAddress is not defined') return null } - if (this.dtAddress == null) { - console.error( - 'dtAddress is not defined. Did you do loadDTPool or createDTPool ?' - ) - return null - } + await this.getDTAddress(account, poolAddress) return this.swapExactAmountOut( + account, + poolAddress, this.dtAddress, amount, this.oceanAddress, @@ -203,89 +180,128 @@ export class OceanPool extends BalancerPool { /** * Add Data Token amount to pool liquidity + * @param {String} account + * @param {String} poolAddress * @param {String} amount Data Token Amount * @return {any} */ - public async addDTLiquidity(amount: string): Promise { - if (this.dtAddress == null) { - console.error( - 'dtAddress is not defined. Did you do loadDTPool or createDTPool ?' - ) - return null - } - await this.approve( + public async addDTLiquidity( + account: string, + poolAddress: string, + amount: string + ): Promise { + await this.getDTAddress(account, poolAddress) + await super.approve( + account, this.dtAddress, - this.poolAddress, + poolAddress, this.web3.utils.toWei(amount) ) - const result = await this.joinswapExternAmountIn(this.dtAddress, amount, '0') + const result = await super.joinswapExternAmountIn( + account, + poolAddress, + this.dtAddress, + amount, + '0' + ) return result } /** * Remove Data Token amount from pool liquidity + * @param {String} account + * @param {String} poolAddress * @param {String} amount pool Liquidity Amount * @return {any} */ - public removeDTLiquidity(amount: string, maximumPoolShares: string): Promise { - if (this.dtAddress == null) { - console.error( - 'dtAddress is not defined. Did you do loadDTPool or createDTPool ?' - ) - return null - } + public async removeDTLiquidity( + account: string, + poolAddress: string, + amount: string, + maximumPoolShares: string + ): Promise { + await this.getDTAddress(account, poolAddress) // TODO Check balance of PoolShares before doing exit - return this.exitswapExternAmountOut(this.dtAddress, amount, maximumPoolShares) + return this.exitswapExternAmountOut( + account, + poolAddress, + this.dtAddress, + amount, + maximumPoolShares + ) } /** * Add Ocean Token amount to pool liquidity + * @param {String} account + * @param {String} poolAddress * @param {String} amount Data Token Amount * @return {any} */ - public async addOceanLiquidity(amount: string): Promise { + public async addOceanLiquidity( + account: string, + poolAddress: string, + amount: string + ): Promise { if (this.oceanAddress == null) { console.error('oceanAddress is not defined') return null } - await this.approve( + await super.approve( + account, this.oceanAddress, - this.poolAddress, + poolAddress, this.web3.utils.toWei(amount) ) - const result = await this.joinswapExternAmountIn(this.oceanAddress, amount, '0') + const result = await super.joinswapExternAmountIn( + account, + poolAddress, + this.oceanAddress, + amount, + '0' + ) return result } /** * Remove Ocean Token amount from pool liquidity + * @param {String} account + * @param {String} poolAddress * @param {String} amount pool Liquidity Amount * @return {any} */ - public removeOceanLiquidity(amount: string, maximumPoolShares: string): Promise { + public removeOceanLiquidity( + account: string, + poolAddress: string, + amount: string, + maximumPoolShares: string + ): Promise { if (this.oceanAddress == null) { console.error('oceanAddress is not defined') return null } // TODO Check balance of PoolShares before doing exit - return this.exitswapExternAmountOut(this.oceanAddress, amount, maximumPoolShares) + return super.exitswapExternAmountOut( + account, + poolAddress, + this.oceanAddress, + amount, + maximumPoolShares + ) } /** * Get Data Token Price from pool + * @param {String} account + * @param {String} poolAddress * @return {any} */ - public async getDTPrice(): Promise { + public async getDTPrice(account: string, poolAddress: string): Promise { if (this.oceanAddress == null) { console.error('oceanAddress is not defined') return null } - if (this.dtAddress == null) { - console.error( - 'dtAddress is not defined. Did you do loadDTPool or createDTPool ?' - ) - return null - } - return this.getSpotPrice(this.dtAddress, this.oceanAddress) + await this.getDTAddress(account, poolAddress) + return super.getSpotPrice(account, poolAddress, this.dtAddress, this.oceanAddress) } } diff --git a/src/balancer/balancerlib.ts b/src/balancer/balancerlib.ts index 059966b5..2cfc4cd3 100644 --- a/src/balancer/balancerlib.ts +++ b/src/balancer/balancerlib.ts @@ -15,49 +15,45 @@ export interface TokensToAdd { weight: string } -export class BalancerFactory { +export class PoolFactory { public GASLIMIT_DEFAULT: number = 5000000 public web3: any = null - public account: string = null private FactoryABI: any public factoryAddress: any constructor( web3: any, - account: string, FactoryABI: any = null, - factoryAddress: string = null + factoryAddress: string = null, + gaslimit?: number ) { this.web3 = web3 - this.account = account + if (FactoryABI) this.FactoryABI = FactoryABI else this.FactoryABI = jsonFactoryABI.abi if (factoryAddress) { this.factoryAddress = factoryAddress } + if (gaslimit) this.GASLIMIT_DEFAULT = gaslimit } /** * Creates a new pool */ - async newPool(): Promise { + async createPool(account: string): Promise { if (this.web3 == null) { console.error('Web3 object is null') return null } - if (this.account == null) { - console.error('Account is null') - return null - } if (this.factoryAddress == null) { console.error('bfactoryAddress is null') return null } const factory = new this.web3.eth.Contract(this.FactoryABI, this.factoryAddress, { - from: this.account + from: account }) const transactiondata = await factory.methods .newBPool() - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) let pooladdress = null try { pooladdress = transactiondata.events.LOG_NEW_POOL.returnValues[1] @@ -68,19 +64,17 @@ export class BalancerFactory { } } -export class BalancerPool extends BalancerFactory { +export class Pool extends PoolFactory { private PoolABI: any - private pool: any = null - public poolAddress: string = null constructor( web3: any, - account: string, FactoryABI: any = null, PoolABI: any = null, - factoryAddress: string = null + factoryAddress: string = null, + gaslimit?: number ) { - super(web3, account, FactoryABI, factoryAddress) + super(web3, FactoryABI, factoryAddress, gaslimit) if (PoolABI) this.PoolABI = PoolABI else this.PoolABI = jsonPoolABI.abi } @@ -88,50 +82,24 @@ export class BalancerPool extends BalancerFactory { /** * Creates a new pool */ - async newPool(): Promise { - const pooladdress = await super.newPool() - this.poolAddress = pooladdress - this.pool = new this.web3.eth.Contract(this.PoolABI, pooladdress, { - from: this.account - }) + async createPool(account: string): Promise { + const pooladdress = await super.createPool(account) return pooladdress } - /** - * Loads a new pool - */ - async loadPool(address: string): Promise { - if (this.web3 == null) { - console.error('Web3 object is null') - return null - } - if (this.account == null) { - console.error('Account is null') - return null - } - if (this.factoryAddress == null) { - console.error('Cannot init. Maybe wrong network?') - return null - } - try { - this.pool = new this.web3.eth.Contract(this.PoolABI, address, { - from: this.account - }) - this.poolAddress = address - return address - } catch (e) { - console.error(e) - return null - } - } - /** * Approve spender to spent amount tokens + * @param {String} account * @param {String} tokenAddress * @param {String} spender * @param {String} amount (always expressed as wei) */ - async approve(tokenAddress: string, spender: string, amount: string): Promise { + async approve( + account: string, + tokenAddress: string, + spender: string, + amount: string + ): Promise { const minABI = [ { constant: false, @@ -158,25 +126,26 @@ export class BalancerPool extends BalancerFactory { } ] const token = new this.web3.eth.Contract(minABI, tokenAddress, { - from: this.account + from: account }) let result = null try { result = await token.methods .approve(spender, amount) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } return result } - async sharesBalance(address: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } - const tokenAddress = this.poolAddress + /** + * Get Pool shares + * @param {String} account + * @param {String} poolAddress + + */ + async sharesBalance(account: string, poolAddress: string): Promise { const minABI = [ { constant: true, @@ -198,15 +167,15 @@ export class BalancerPool extends BalancerFactory { type: 'function' } ] - const token = new this.web3.eth.Contract(minABI, tokenAddress, { - from: this.account + const token = new this.web3.eth.Contract(minABI, poolAddress, { + from: account }) let result = null try { result = this.web3.utils.fromWei( await token.methods - .balanceOf(address) - .call({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .balanceOf(account) + .call({ from: account, gas: this.GASLIMIT_DEFAULT }) ) } catch (e) { console.error(e) @@ -216,29 +185,36 @@ export class BalancerPool extends BalancerFactory { /** * Adds tokens to pool + * @param {String} account + * @param {String} poolAddress * @param {Array} tokens Array of token object { address,amount,weight} */ - async addToPool(tokens: TokensToAdd[]): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async addToPool( + account: string, + poolAddress: string, + tokens: TokensToAdd[] + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) + let token for (token of tokens) { try { // approve spending first await this.approve( + account, token.address, - this.poolAddress, + poolAddress, this.web3.utils.toWei(token.amount) ) - await this.pool.methods + await pool.methods .bind( token.address, this.web3.utils.toWei(token.amount), this.web3.utils.toWei(token.weight) ) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -247,18 +223,19 @@ export class BalancerPool extends BalancerFactory { /** * Set pool fee + * @param {String} account + * @param {String} poolAddress * @param {String} fee (will be converted to wei) */ - async setSwapFee(fee: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async setSwapFee(account: string, poolAddress: string, fee: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods + result = await pool.methods .setSwapFee(this.web3.utils.toWei(fee)) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -267,17 +244,18 @@ export class BalancerPool extends BalancerFactory { /** * Finalize a pool + * @param {String} account + * @param {String} poolAddress */ - async finalize(): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async finalize(account: string, poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods + result = await pool.methods .finalize() - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -286,15 +264,16 @@ export class BalancerPool extends BalancerFactory { /** * Get number of tokens composing this pool + * @param {String} account + * @param {String} poolAddress */ - async getNumTokens(): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getNumTokens(account: string, poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods.getNumTokens().call() + result = await pool.methods.getNumTokens().call() } catch (e) { console.error(e) } @@ -303,16 +282,17 @@ export class BalancerPool extends BalancerFactory { /** * Get tokens composing this pool + * @param {String} account + * @param {String} poolAddress * @return {Array} */ - async getCurrentTokens(): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getCurrentTokens(account: string, poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods.getCurrentTokens().call() + result = await pool.methods.getCurrentTokens().call() } catch (e) { console.error(e) } @@ -321,16 +301,17 @@ export class BalancerPool extends BalancerFactory { /** * Get the final tokens composing this pool + * @param {String} account + * @param {String} poolAddress * @return {Array} */ - async getFinalTokens(): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getFinalTokens(account: string, poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods.getFinalTokens().call() + result = await pool.methods.getFinalTokens().call() } catch (e) { console.error(e) } @@ -339,16 +320,17 @@ export class BalancerPool extends BalancerFactory { /** * Get controller address of this pool + * @param {String} account + * @param {String} poolAddress * @return {String} */ - async getController(): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getController(account: string, poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods.getController().call() + result = await pool.methods.getController().call() } catch (e) { console.error(e) } @@ -357,19 +339,24 @@ export class BalancerPool extends BalancerFactory { /** * Set controller address of this pool - * @param {String} address + * @param {String} account + * @param {String} poolAddress + * @param {String} controllerAddress * @return {String} */ - async setController(address: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async setController( + account: string, + poolAddress: string, + controllerAddress: string + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods - .setController(address) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + result = await pool.methods + .setController(controllerAddress) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -378,17 +365,18 @@ export class BalancerPool extends BalancerFactory { /** * Get if a token is bounded to a pool + * @param {String} account + * @param {String} poolAddress * @param {String} token Address of the token * @return {Boolean} */ - async isBound(token: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async isBound(account: string, poolAddress: string, token: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods.isBound(token).call() + result = await pool.methods.isBound(token).call() } catch (e) { console.error(e) } @@ -397,17 +385,23 @@ export class BalancerPool extends BalancerFactory { /** * Get how many tokens are in the pool + * @param {String} account + * @param {String} poolAddress * @param {String} token Address of the token * @return {Boolean} */ - async getBalance(token: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getReserve( + account: string, + poolAddress: string, + token: string + ): Promise { + console.log('getReserve for token:' + token) + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let amount = null try { - const result = await this.pool.methods.getBalance(token).call() + const result = await pool.methods.getBalance(token).call() amount = this.web3.utils.fromWei(result) } catch (e) { console.error(e) @@ -417,16 +411,17 @@ export class BalancerPool extends BalancerFactory { /** * Get if a pool is finalized + * @param {String} account + * @param {String} poolAddress * @return {Boolean} */ - async isFinalized(): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async isFinalized(account: string, poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods.isFinalized().call() + result = await pool.methods.isFinalized().call() } catch (e) { console.error(e) } @@ -435,16 +430,17 @@ export class BalancerPool extends BalancerFactory { /** * Get pool fee - * @return {String} + * @param {String} account + * @param {String} poolAddress + * @return {String} Swap fee in wei */ - async getSwapFee(): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getSwapFee(account: string, poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let fee = null try { - const result = await this.pool.methods.getSwapFee().call() + const result = await pool.methods.getSwapFee().call() fee = this.web3.utils.fromWei(result) } catch (e) { console.error(e) @@ -454,17 +450,22 @@ export class BalancerPool extends BalancerFactory { /** * The normalized weight of a token. The combined normalized weights of all tokens will sum up to 1. (Note: the actual sum may be 1 plus or minus a few wei due to division precision loss) + * @param {String} account + * @param {String} poolAddress * @param {String} token * @return {Number} */ - async getNormalizedWeight(token: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getNormalizedWeight( + account: string, + poolAddress: string, + token: string + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let weight = null try { - const result = await this.pool.methods.getNormalizedWeight(token).call() + const result = await pool.methods.getNormalizedWeight(token).call() weight = this.web3.utils.fromWei(result) } catch (e) { console.error(e) @@ -474,17 +475,22 @@ export class BalancerPool extends BalancerFactory { /** * getDenormalizedWeight of a token in pool + * @param {String} account + * @param {String} poolAddress * @param {String} token * @return {Number} */ - async getDenormalizedWeight(token: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getDenormalizedWeight( + account: string, + poolAddress: string, + token: string + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let weight = null try { - const result = await this.pool.methods.getDenormalizedWeight(token).call() + const result = await pool.methods.getDenormalizedWeight(token).call() weight = this.web3.utils.fromWei(result) } catch (e) { console.error(e) @@ -494,16 +500,20 @@ export class BalancerPool extends BalancerFactory { /** * getTotalDenormalizedWeight in pool - * @return {Number} + * @param {String} account + * @param {String} poolAddress + * @return {String} */ - async getTotalDenormalizedWeight(): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getTotalDenormalizedWeight( + account: string, + poolAddress: string + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let weight = null try { - const result = await this.pool.methods.getTotalDenormalizedWeight().call() + const result = await pool.methods.getTotalDenormalizedWeight().call() weight = this.web3.utils.fromWei(result) } catch (e) { console.error(e) @@ -513,6 +523,8 @@ export class BalancerPool extends BalancerFactory { /** * swapExactAmountIn - Trades an exact tokenAmountIn of tokenIn taken from the caller by the pool, in exchange for at least minAmountOut of tokenOut given to the caller from the pool, with a maximum marginal price of maxPrice. Returns (tokenAmountOut, spotPriceAfter), where tokenAmountOut is the amount of token that came out of the pool, and spotPriceAfter is the new marginal spot price, ie, the result of getSpotPrice after the call. (These values are what are limited by the arguments; you are guaranteed tokenAmountOut >= minAmountOut and spotPriceAfter <= maxPrice). + * @param {String} account + * @param {String} poolAddress * @param {String} tokenIn * @param {String} tokenAmountIn will be converted to wei * @param {String} tokenOut @@ -521,19 +533,20 @@ export class BalancerPool extends BalancerFactory { * @return {any} */ async swapExactAmountIn( + account: string, + poolAddress: string, tokenIn: string, tokenAmountIn: string, tokenOut: string, minAmountOut: string, maxPrice: string ): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods + result = await pool.methods .swapExactAmountIn( tokenIn, this.web3.utils.toWei(tokenAmountIn), @@ -541,7 +554,7 @@ export class BalancerPool extends BalancerFactory { this.web3.utils.toWei(minAmountOut), this.web3.utils.toWei(maxPrice) ) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -550,6 +563,8 @@ export class BalancerPool extends BalancerFactory { /** * swapExactAmountOut + * @param {String} account + * @param {String} poolAddress * @param {String} tokenIn * @param {String} maxAmountIn will be converted to wei * @param {String} tokenOut @@ -558,19 +573,20 @@ export class BalancerPool extends BalancerFactory { * @return {any} */ async swapExactAmountOut( + account: string, + poolAddress: string, tokenIn: string, maxAmountIn: string, tokenOut: string, minAmountOut: string, maxPrice: string ): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods + result = await pool.methods .swapExactAmountOut( tokenIn, this.web3.utils.toWei(maxAmountIn), @@ -578,7 +594,7 @@ export class BalancerPool extends BalancerFactory { this.web3.utils.toWei(minAmountOut), this.web3.utils.toWei(maxPrice) ) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -587,15 +603,21 @@ export class BalancerPool extends BalancerFactory { /** * Join the pool, getting poolAmountOut pool tokens. This will pull some of each of the currently trading tokens in the pool, meaning you must have called approve for each token for this pool. These values are limited by the array of maxAmountsIn in the order of the pool tokens. + * @param {String} account + * @param {String} poolAddress * @param {String} poolAmountOut will be converted to wei * @param {String} maxAmountsIn array holding maxAmount per each token, will be converted to wei * @return {any} */ - async joinPool(poolAmountOut: string, maxAmountsIn: any): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async joinPool( + account: string, + poolAddress: string, + poolAmountOut: string, + maxAmountsIn: any + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) const weiMaxAmountsIn = [] let amount for (amount of maxAmountsIn) { @@ -603,9 +625,9 @@ export class BalancerPool extends BalancerFactory { } let result = null try { - result = await this.pool.methods + result = await pool.methods .joinPool(this.web3.utils.toWei(poolAmountOut), weiMaxAmountsIn) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -614,15 +636,21 @@ export class BalancerPool extends BalancerFactory { /** * Exit the pool, paying poolAmountIn pool tokens and getting some of each of the currently trading tokens in return. These values are limited by the array of minAmountsOut in the order of the pool tokens. + * @param {String} account + * @param {String} poolAddress * @param {String} poolAmountIn will be converted to wei * @param {String} maxAmountsIn array holding maxAmount per each token, will be converted to wei * @return {any} */ - async exitPool(poolAmountIn: string, minAmountsOut: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async exitPool( + account: string, + poolAddress: string, + poolAmountIn: string, + minAmountsOut: string + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) const weiMinAmountsOut = [] let amount for (amount of minAmountsOut) { @@ -630,9 +658,9 @@ export class BalancerPool extends BalancerFactory { } let result = null try { - result = await this.pool.methods + result = await pool.methods .exitPool(this.web3.utils.toWei(poolAmountIn), weiMinAmountsOut) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -641,29 +669,32 @@ export class BalancerPool extends BalancerFactory { /** * Pay tokenAmountIn of token tokenIn to join the pool, getting poolAmountOut of the pool shares. + * @param {String} account + * @param {String} poolAddress * @param {String} tokenIn * @param {String} tokenAmountIn will be converted to wei * @param {String} minPoolAmountOut will be converted to wei * @return {any} */ async joinswapExternAmountIn( + account: string, + poolAddress: string, tokenIn: string, tokenAmountIn: string, minPoolAmountOut: string ): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods + result = await pool.methods .joinswapExternAmountIn( tokenIn, this.web3.utils.toWei(tokenAmountIn), this.web3.utils.toWei(minPoolAmountOut) ) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -672,29 +703,32 @@ export class BalancerPool extends BalancerFactory { /** * 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} poolAddress * @param {String} tokenIn * @param {String} poolAmountOut will be converted to wei * @param {String} maxAmountIn will be converted to wei * @return {any} */ async joinswapPoolAmountOut( + account: string, + poolAddress: string, tokenIn: string, poolAmountOut: string, maxAmountIn: string ): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods + result = await pool.methods .joinswapPoolAmountOut( tokenIn, this.web3.utils.toWei(poolAmountOut), this.web3.utils.toWei(maxAmountIn) ) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -703,29 +737,32 @@ export class BalancerPool extends BalancerFactory { /** * Pay poolAmountIn pool shares into the pool, getting minTokenAmountOut of the given token tokenOut out of the pool. + * @param {String} account + * @param {String} poolAddress * @param {String} tokenOut * @param {String} poolAmountIn will be converted to wei * @param {String} minTokenAmountOut will be converted to wei * @return {any} */ async exitswapPoolAmountIn( + account: string, + poolAddress: string, tokenOut: string, poolAmountIn: string, minTokenAmountOut: string ): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods + result = await pool.methods .exitswapPoolAmountIn( tokenOut, this.web3.utils.toWei(poolAmountIn), this.web3.utils.toWei(minTokenAmountOut) ) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -734,29 +771,32 @@ export class BalancerPool extends BalancerFactory { /** * Specify tokenAmountOut of token tokenOut that you want to get out of the pool. This costs poolAmountIn pool shares (these went into the pool). + * @param {String} account + * @param {String} poolAddress * @param {String} tokenOut * @param {String} tokenAmountOut will be converted to wei * @param {String} maxPoolAmountIn will be converted to wei * @return {any} */ async exitswapExternAmountOut( + account: string, + poolAddress: string, tokenOut: string, tokenAmountOut: string, maxPoolAmountIn: string ): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let result = null try { - result = await this.pool.methods + result = await pool.methods .exitswapExternAmountOut( tokenOut, this.web3.utils.toWei(tokenAmountOut), this.web3.utils.toWei(maxPoolAmountIn) ) - .send({ from: this.account, gas: this.GASLIMIT_DEFAULT }) + .send({ from: account, gas: this.GASLIMIT_DEFAULT }) } catch (e) { console.error(e) } @@ -765,18 +805,24 @@ export class BalancerPool extends BalancerFactory { /** * Get Spot Price of swaping tokenIn to tokenOut + * @param {String} account + * @param {String} poolAddress * @param {String} tokenIn * @param {String} tokenOut * @return {any} */ - async getSpotPrice(tokenIn: string, tokenOut: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getSpotPrice( + account: string, + poolAddress: string, + tokenIn: string, + tokenOut: string + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let price = null try { - const result = await this.pool.methods.getSpotPrice(tokenIn, tokenOut).call() + const result = await pool.methods.getSpotPrice(tokenIn, tokenOut).call() price = this.web3.utils.fromWei(result) } catch (e) { console.error(e) @@ -786,18 +832,24 @@ export class BalancerPool extends BalancerFactory { /** * Get Spot Price of swaping tokenIn to tokenOut without fees + * @param {String} account + * @param {String} poolAddress * @param {String} tokenIn * @param {String} tokenOut * @return {any} */ - async getSpotPriceSansFee(tokenIn: string, tokenOut: string): Promise { - if (this.pool == null) { - console.error('BPool not initialiez. Maybe you missed newPool or loadPool ?') - return null - } + async getSpotPriceSansFee( + account: string, + poolAddress: string, + tokenIn: string, + tokenOut: string + ): Promise { + const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, { + from: account + }) let price = null try { - const result = await this.pool.methods + const result = await pool.methods .getSpotPriceSansFee(tokenIn, tokenOut) .call() price = this.web3.utils.fromWei(result) diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 6a2cafc9..99c7984b 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -18,6 +18,7 @@ import { generateIntantiableConfigFromConfig } from '../Instantiable.abstract' import { Compute } from './Compute' +import { OceanPool } from '../balancer/OceanPool' /** * Main interface for Ocean Protocol. diff --git a/test/unit/balancer/Balancer.test.ts b/test/unit/balancer/Balancer.test.ts index 70b46b5e..a7c0a2b1 100644 --- a/test/unit/balancer/Balancer.test.ts +++ b/test/unit/balancer/Balancer.test.ts @@ -25,20 +25,17 @@ describe('Balancer flow', () => { let Pool let OceanPoolContracts let oceandatatoken - let alicePool let alicePoolAddress - let bobPool let currentDtPrice - let bobPoolShares let owner let bob let alice let contracts let datatoken let tokenAddress - let transactionId - const tokenAmount = web3.utils.toWei('1000') - const transferAmount = web3.utils.toWei('200') + let consoleDebug: false + const tokenAmount = '1000' + const transferAmount = '200' const blob = 'http://localhost:8030/api/v1/services/consume' describe('#test', () => { it('Initialize Ocean contracts v3', async () => { @@ -94,7 +91,7 @@ describe('Balancer flow', () => { OceanPoolFactoryAddress = OceanPoolContracts.factoryAddress assert(OceanPoolFactoryAddress !== null) }) - it('Deploy Spool/SFactory', async () => { + /* it('Deploy Spool/SFactory', async () => { const SContracts = new BalancerContractHandler( SFactory.abi, SFactory.bytecode, @@ -109,11 +106,11 @@ describe('Balancer flow', () => { const SFactoryAddress = SContracts.factoryAddress assert(SFactoryAddress !== null) }) + */ it('should initialize OceanPool class', async () => { Pool = new OceanPool( web3, - alice, OceanPoolFactory.abi, OceanPoolPool.abi, OceanPoolFactoryAddress, @@ -135,126 +132,124 @@ describe('Balancer flow', () => { transferAmount, alice ) - transactionId = ts.transactionHash }) it('Alice creates a new OceanPool pool', async () => { /// new pool with total DT = 45 , dt weight=90% with swap fee 2% - alicePoolAddress = await Pool.createDTPool(tokenAddress, 45, 9, '0.02') - alicePool = await Pool.loadDTPool(alicePoolAddress) - assert(alicePool !== null) + alicePoolAddress = await Pool.createDTPool(alice, tokenAddress, 45, 9, '0.02') }) it('Get pool information', async () => { - const currentTokens = await alicePool.getCurrentTokens() + const currentTokens = await Pool.getCurrentTokens(alice, alicePoolAddress) assert(currentTokens.length === 2) assert(currentTokens.includes(tokenAddress)) assert(currentTokens.includes(oceanTokenAddress)) }) it('Get pool swap fee', async () => { - const currentSwapFee = await alicePool.getSwapFee() + const currentSwapFee = await Pool.getSwapFee(alice, alicePoolAddress) assert(currentSwapFee === '0.02') }) it('Get dtPrice from the pool ', async () => { - currentDtPrice = await alicePool.getDTPrice() + currentDtPrice = await Pool.getDTPrice(alice, alicePoolAddress) assert(currentDtPrice > 0) }) it('Get dtToken pool reserve ', async () => { - const currentDtReserve = await alicePool.getBalance(tokenAddress) + const currentDtReserve = await Pool.getDTReserve(alice, alicePoolAddress) assert(currentDtReserve > 0) }) it('Get dtToken pool reserve ', async () => { - const currentOceanReserve = await alicePool.getOceanBalance() + const currentOceanReserve = await Pool.getOceanReserve( + alice, + alicePoolAddress + ) assert(currentOceanReserve > 0) }) - it("Bob should load Alice's pool ", async () => { - bobPool = new OceanPool( - web3, - bob, - OceanPoolFactory.abi, - OceanPoolPool.abi, - OceanPoolFactoryAddress, - oceanTokenAddress - ) - await bobPool.loadDTPool(alicePoolAddress) - }) + it('Bob should buy a DT ', async () => { const maxPrice = parseFloat(currentDtPrice) * 2 - await bobPool.buyDT('1', '2', String(maxPrice)) + await Pool.buyDT(bob, alicePoolAddress, '1', '2', String(maxPrice)) const bobDtBalance = await datatoken.balance(tokenAddress, bob) const bobOceanBalance = await datatoken.balance(oceanTokenAddress, bob) assert(bobDtBalance > 0) assert(bobOceanBalance > 0) }) it('Bob should add DT liquidity to pool ', async () => { - const currentDtReserve = await alicePool.getBalance(tokenAddress) - const bobDtBalance = web3.utils.fromWei( - await datatoken.balance(tokenAddress, bob) - ) + const currentDtReserve = await Pool.getDTReserve(bob, alicePoolAddress) + if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve) + const bobDtBalance = await datatoken.balance(tokenAddress, bob) + if (consoleDebug) console.log('BOB DT Balance:' + bobDtBalance) + await Pool.addDTLiquidity(bob, alicePoolAddress, bobDtBalance) - await bobPool.addDTLiquidity(bobDtBalance) + const newbobDtBalance = await datatoken.balance(tokenAddress, bob) - const newbobDtBalance = web3.utils.fromWei( - await datatoken.balance(tokenAddress, bob) - ) + const newDtReserve = await Pool.getDTReserve(bob, alicePoolAddress) - const newDtReserve = await alicePool.getBalance(tokenAddress) - - const sharesBalance = await bobPool.sharesBalance(bob) + const sharesBalance = await Pool.sharesBalance(bob, alicePoolAddress) + if (consoleDebug) console.log('newDtReserve:' + newDtReserve) + if (consoleDebug) console.log('newbobDtBalance:' + newbobDtBalance) + if (consoleDebug) console.log('sharesBalance:' + sharesBalance) assert(parseFloat(newbobDtBalance) < parseFloat(bobDtBalance)) assert(parseFloat(newDtReserve) > parseFloat(currentDtReserve)) assert(parseFloat(sharesBalance) > 0) }) it('Bob should remove DT liquidity from pool ', async () => { - const currentDtReserve = await alicePool.getBalance(tokenAddress) - const bobDtBalance = web3.utils.fromWei( - await datatoken.balance(tokenAddress, bob) - ) - const poolShares = await bobPool.sharesBalance(bob) - await bobPool.removeDTLiquidity('0.75', poolShares) + const currentDtReserve = await Pool.getDTReserve(bob, alicePoolAddress) + if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve) + const bobDtBalance = await datatoken.balance(tokenAddress, bob) + if (consoleDebug) console.log('bobDtBalance:' + bobDtBalance) + const poolShares = await Pool.sharesBalance(bob, alicePoolAddress) + if (consoleDebug) console.log('poolShares:' + poolShares) + await Pool.removeDTLiquidity(bob, alicePoolAddress, '0.75', poolShares) - const newDtReserve = await alicePool.getBalance(tokenAddress) - const newbobDtBalance = web3.utils.fromWei( - await datatoken.balance(tokenAddress, bob) - ) - const newpoolShares = await bobPool.sharesBalance(bob) + const newDtReserve = await Pool.getDTReserve(bob, alicePoolAddress) + if (consoleDebug) console.log('newDtReserve:' + newDtReserve) + const newbobDtBalance = await datatoken.balance(tokenAddress, bob) + if (consoleDebug) console.log('newbobDtBalance:' + newbobDtBalance) + const newpoolShares = await Pool.sharesBalance(bob, alicePoolAddress) + if (consoleDebug) console.log('newpoolShares:' + newpoolShares) assert(parseFloat(newDtReserve) < parseFloat(currentDtReserve)) assert(parseFloat(bobDtBalance) < parseFloat(newbobDtBalance)) assert(parseFloat(poolShares) > parseFloat(newpoolShares)) }) it('Bob should add Ocean liquidity to pool ', async () => { - const currentDtReserve = await alicePool.getBalance(oceanTokenAddress) - const bobDtBalance = web3.utils.fromWei( - await datatoken.balance(oceanTokenAddress, bob) - ) + const currentDtReserve = await Pool.getOceanReserve(bob, alicePoolAddress) + const bobDtBalance = await datatoken.balance(oceanTokenAddress, bob) + if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve) + if (consoleDebug) console.log('bobDtBalance:' + bobDtBalance) - await bobPool.addOceanLiquidity('1') + await Pool.addOceanLiquidity(bob, alicePoolAddress, '1') - const newbobDtBalance = web3.utils.fromWei( - await datatoken.balance(oceanTokenAddress, bob) - ) + const newbobDtBalance = await datatoken.balance(oceanTokenAddress, bob) - const newDtReserve = await alicePool.getBalance(oceanTokenAddress) + const newDtReserve = await Pool.getOceanReserve(bob, alicePoolAddress) - const sharesBalance = await bobPool.sharesBalance(bob) + const sharesBalance = await Pool.sharesBalance(bob, alicePoolAddress) + if (consoleDebug) console.log('newDtReserve:' + newDtReserve) + if (consoleDebug) console.log('newbobDtBalance:' + newbobDtBalance) + if (consoleDebug) console.log('sharesBalance:' + sharesBalance) assert(parseFloat(newbobDtBalance) < parseFloat(bobDtBalance)) assert(parseFloat(newDtReserve) > parseFloat(currentDtReserve)) assert(parseFloat(sharesBalance) > 0) }) it('Bob should remove Ocean liquidity from pool ', async () => { - const currentDtReserve = await alicePool.getBalance(oceanTokenAddress) - const bobDtBalance = web3.utils.fromWei( - await datatoken.balance(oceanTokenAddress, bob) - ) - const poolShares = await bobPool.sharesBalance(bob) - await bobPool.removeOceanLiquidity('0.75', poolShares) + const currentDtReserve = await Pool.getOceanReserve(bob, alicePoolAddress) + const bobDtBalance = await datatoken.balance(oceanTokenAddress, bob) - const newDtReserve = await alicePool.getBalance(oceanTokenAddress) - const newbobDtBalance = web3.utils.fromWei( - await datatoken.balance(oceanTokenAddress, bob) - ) - const newpoolShares = await bobPool.sharesBalance(bob) + const poolShares = await Pool.sharesBalance(bob, alicePoolAddress) + if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve) + if (consoleDebug) console.log('bobDtBalance:' + bobDtBalance) + if (consoleDebug) console.log('poolShares:' + poolShares) + + await Pool.removeOceanLiquidity(bob, alicePoolAddress, '0.75', poolShares) + + const newDtReserve = await Pool.getOceanReserve(bob, alicePoolAddress) + const newbobDtBalance = await datatoken.balance(oceanTokenAddress, bob) + const newpoolShares = await Pool.sharesBalance(bob, alicePoolAddress) + + if (consoleDebug) console.log('newDtReserve:' + newDtReserve) + if (consoleDebug) console.log('newbobDtBalance:' + newbobDtBalance) + if (consoleDebug) console.log('newpoolShares:' + newpoolShares) assert(parseFloat(newDtReserve) < parseFloat(currentDtReserve)) assert(parseFloat(bobDtBalance) < parseFloat(newbobDtBalance)) assert(parseFloat(poolShares) > parseFloat(newpoolShares))