diff --git a/src/balancer/Pool.ts b/src/balancer/Pool.ts index f2103dd9..2c76f194 100644 --- a/src/balancer/Pool.ts +++ b/src/balancer/Pool.ts @@ -89,7 +89,7 @@ export class Pool extends PoolFactory { } /** - * Get Pool shares + * Get user shares of pool tokens * @param {String} account * @param {String} poolAddress * @return {String} @@ -116,16 +116,35 @@ export class Pool extends PoolFactory { type: 'function' } ] as AbiItem[] - const token = new this.web3.eth.Contract(minABI, poolAddress, { - from: account - }) + let result = null + try { - result = this.web3.utils.fromWei( - await token.methods - .balanceOf(account) - .call({ from: account, gas: this.GASLIMIT_DEFAULT }) - ) + const token = new this.web3.eth.Contract(minABI, poolAddress, { + from: account + }) + const balance = await token.methods + .balanceOf(account) + .call({ from: account, gas: this.GASLIMIT_DEFAULT }) + result = this.web3.utils.fromWei(balance) + } catch (e) { + console.error(e) + } + return result + } + + /** + * Get total supply of pool tokens + * @param {String} poolAddress + * @return {String} + */ + async totalSupply(poolAddress: string): Promise { + let result = null + + try { + const pool = new this.web3.eth.Contract(this.poolABI, poolAddress) + const totalSupply = await pool.methods.totalSupply().call() + result = this.web3.utils.fromWei(totalSupply) } catch (e) { console.error(e) } diff --git a/test/unit/balancer/Balancer.test.ts b/test/unit/balancer/Balancer.test.ts index fd399495..c8cf83d0 100644 --- a/test/unit/balancer/Balancer.test.ts +++ b/test/unit/balancer/Balancer.test.ts @@ -133,6 +133,10 @@ describe('Balancer flow', () => { const currentOceanReserve = await Pool.getOceanReserve(alice, alicePoolAddress) assert(currentOceanReserve > 0) }) + it('Get total supply of pool tokens', async () => { + const totalSupply = await Pool.totalSupply(alicePoolAddress) + assert(totalSupply > 0) + }) it('Get amount of Ocean needed to buy 1 dtToken', async () => { const requiredOcean = await Pool.getOceanNeeded(alice, alicePoolAddress, '1') assert(requiredOcean > 0)