diff --git a/src/balancer/OceanPool.ts b/src/balancer/OceanPool.ts index 21c77c73..f6935d73 100644 --- a/src/balancer/OceanPool.ts +++ b/src/balancer/OceanPool.ts @@ -3,6 +3,11 @@ import { AbiItem } from 'web3-utils/types' import { TransactionReceipt } from 'web3-core' import { Pool } from './Pool' +export interface PoolDetails { + poolAddress: string + tokens: string[] +} + /** * Ocean Pools submodule exposed under ocean.pool */ @@ -84,7 +89,7 @@ export class OceanPool extends Pool { */ public async getDTAddress(account: string, poolAddress: string): Promise { this.dtAddress = null - const tokens = await this.getCurrentTokens(account, poolAddress) + const tokens = await this.getCurrentTokens(poolAddress) let token: string for (token of tokens) { @@ -335,10 +340,7 @@ export class OceanPool extends Pool { toBlock: 'latest' }) for (let i = 0; i < events.length; i++) { - const constituents = await super.getCurrentTokens( - account, - events[i].returnValues[0] - ) + const constituents = await super.getCurrentTokens(events[i].returnValues[0]) if (constituents.includes(dtAddress)) result.push(events[i].returnValues[0]) } return result @@ -378,8 +380,8 @@ export class OceanPool extends Pool { * @param {String} account If empty, will return all pools ever created by anybody * @return {String[]} */ - public async searchPoolsbyCreator(account?: string): Promise { - const result: string[] = [] + public async getPoolsbyCreator(account?: string): Promise { + const result: PoolDetails[] = [] const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, { from: account }) @@ -397,13 +399,20 @@ export class OceanPool extends Pool { for (let i = 0; i < events.length; i++) { if (account) { if (events[i].returnValues[1] === account) { - result.push(events[i].returnValues[0]) + result.push(await this.getPoolDetails(events[i].returnValues[0])) } - } else result.push(events[i].returnValues[0]) + } else result.push(await this.getPoolDetails(events[i].returnValues[0])) } return result } + public async getPoolDetails(poolAddress: string): Promise { + const details: PoolDetails = null + details.poolAddress = poolAddress + details.tokens = await super.getFinalTokens(poolAddress) + return details + } + /** * Get all actions from a pool (join,exit,swap) * @param {String} poolAddress Pool address diff --git a/src/balancer/Pool.ts b/src/balancer/Pool.ts index 4e093e1e..cb930518 100644 --- a/src/balancer/Pool.ts +++ b/src/balancer/Pool.ts @@ -275,14 +275,11 @@ export class Pool extends PoolFactory { /** * Get tokens composing this pool - * @param {String} account * @param {String} poolAddress * @return {String[]} */ - async getCurrentTokens(account: string, poolAddress: string): Promise { - const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { - from: account - }) + async getCurrentTokens(poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.poolABI, poolAddress) let result = null try { result = await pool.methods.getCurrentTokens().call() @@ -294,14 +291,11 @@ export class Pool extends PoolFactory { /** * Get the final tokens composing this pool - * @param {String} account * @param {String} poolAddress * @return {String[]} */ - async getFinalTokens(account: string, poolAddress: string): Promise { - const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { - from: account - }) + async getFinalTokens(poolAddress: string): Promise { + const pool = new this.web3.eth.Contract(this.poolABI, poolAddress) let result = null try { result = await pool.methods.getFinalTokens().call() diff --git a/test/unit/balancer/Balancer.test.ts b/test/unit/balancer/Balancer.test.ts index 92be1aa2..8133de13 100644 --- a/test/unit/balancer/Balancer.test.ts +++ b/test/unit/balancer/Balancer.test.ts @@ -122,7 +122,7 @@ describe('Balancer flow', () => { assert(String(n) === '2', 'unexpected num tokens: ' + n) }) it('Get pool information', async () => { - const currentTokens = await Pool.getCurrentTokens(alice, alicePoolAddress) + const currentTokens = await Pool.getCurrentTokens(alicePoolAddress) assert(currentTokens.length === 2) assert(currentTokens.includes(tokenAddress)) assert(currentTokens.includes(oceanTokenAddress)) @@ -272,7 +272,7 @@ describe('Balancer flow', () => { }) it('ALice should get all the pools that she created', async () => { - const alicePools = await Pool.searchPoolsbyCreator(alice) + const alicePools = await Pool.getPoolsbyCreator(alice) assert(alicePools.length > 0) })