mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add getPoolsbyCreator
This commit is contained in:
parent
34daf5cfe9
commit
1f15a67d64
@ -3,6 +3,11 @@ import { AbiItem } from 'web3-utils/types'
|
|||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { Pool } from './Pool'
|
import { Pool } from './Pool'
|
||||||
|
|
||||||
|
export interface PoolDetails {
|
||||||
|
poolAddress: string
|
||||||
|
tokens: string[]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ocean Pools submodule exposed under ocean.pool
|
* Ocean Pools submodule exposed under ocean.pool
|
||||||
*/
|
*/
|
||||||
@ -84,7 +89,7 @@ export class OceanPool extends Pool {
|
|||||||
*/
|
*/
|
||||||
public async getDTAddress(account: string, poolAddress: string): Promise<string> {
|
public async getDTAddress(account: string, poolAddress: string): Promise<string> {
|
||||||
this.dtAddress = null
|
this.dtAddress = null
|
||||||
const tokens = await this.getCurrentTokens(account, poolAddress)
|
const tokens = await this.getCurrentTokens(poolAddress)
|
||||||
let token: string
|
let token: string
|
||||||
|
|
||||||
for (token of tokens) {
|
for (token of tokens) {
|
||||||
@ -335,10 +340,7 @@ export class OceanPool extends Pool {
|
|||||||
toBlock: 'latest'
|
toBlock: 'latest'
|
||||||
})
|
})
|
||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
const constituents = await super.getCurrentTokens(
|
const constituents = await super.getCurrentTokens(events[i].returnValues[0])
|
||||||
account,
|
|
||||||
events[i].returnValues[0]
|
|
||||||
)
|
|
||||||
if (constituents.includes(dtAddress)) result.push(events[i].returnValues[0])
|
if (constituents.includes(dtAddress)) result.push(events[i].returnValues[0])
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@ -378,8 +380,8 @@ export class OceanPool extends Pool {
|
|||||||
* @param {String} account If empty, will return all pools ever created by anybody
|
* @param {String} account If empty, will return all pools ever created by anybody
|
||||||
* @return {String[]}
|
* @return {String[]}
|
||||||
*/
|
*/
|
||||||
public async searchPoolsbyCreator(account?: string): Promise<string[]> {
|
public async getPoolsbyCreator(account?: string): Promise<PoolDetails[]> {
|
||||||
const result: string[] = []
|
const result: PoolDetails[] = []
|
||||||
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
|
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
|
||||||
from: account
|
from: account
|
||||||
})
|
})
|
||||||
@ -397,13 +399,20 @@ export class OceanPool extends Pool {
|
|||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
if (account) {
|
if (account) {
|
||||||
if (events[i].returnValues[1] === 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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getPoolDetails(poolAddress: string): Promise<PoolDetails> {
|
||||||
|
const details: PoolDetails = null
|
||||||
|
details.poolAddress = poolAddress
|
||||||
|
details.tokens = await super.getFinalTokens(poolAddress)
|
||||||
|
return details
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all actions from a pool (join,exit,swap)
|
* Get all actions from a pool (join,exit,swap)
|
||||||
* @param {String} poolAddress Pool address
|
* @param {String} poolAddress Pool address
|
||||||
|
@ -275,14 +275,11 @@ export class Pool extends PoolFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tokens composing this pool
|
* Get tokens composing this pool
|
||||||
* @param {String} account
|
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @return {String[]}
|
* @return {String[]}
|
||||||
*/
|
*/
|
||||||
async getCurrentTokens(account: string, poolAddress: string): Promise<string[]> {
|
async getCurrentTokens(poolAddress: string): Promise<string[]> {
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
from: account
|
|
||||||
})
|
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getCurrentTokens().call()
|
result = await pool.methods.getCurrentTokens().call()
|
||||||
@ -294,14 +291,11 @@ export class Pool extends PoolFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the final tokens composing this pool
|
* Get the final tokens composing this pool
|
||||||
* @param {String} account
|
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @return {String[]}
|
* @return {String[]}
|
||||||
*/
|
*/
|
||||||
async getFinalTokens(account: string, poolAddress: string): Promise<string[]> {
|
async getFinalTokens(poolAddress: string): Promise<string[]> {
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
from: account
|
|
||||||
})
|
|
||||||
let result = null
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.getFinalTokens().call()
|
result = await pool.methods.getFinalTokens().call()
|
||||||
|
@ -122,7 +122,7 @@ describe('Balancer flow', () => {
|
|||||||
assert(String(n) === '2', 'unexpected num tokens: ' + n)
|
assert(String(n) === '2', 'unexpected num tokens: ' + n)
|
||||||
})
|
})
|
||||||
it('Get pool information', async () => {
|
it('Get pool information', async () => {
|
||||||
const currentTokens = await Pool.getCurrentTokens(alice, alicePoolAddress)
|
const currentTokens = await Pool.getCurrentTokens(alicePoolAddress)
|
||||||
assert(currentTokens.length === 2)
|
assert(currentTokens.length === 2)
|
||||||
assert(currentTokens.includes(tokenAddress))
|
assert(currentTokens.includes(tokenAddress))
|
||||||
assert(currentTokens.includes(oceanTokenAddress))
|
assert(currentTokens.includes(oceanTokenAddress))
|
||||||
@ -272,7 +272,7 @@ describe('Balancer flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('ALice should get all the pools that she created', async () => {
|
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)
|
assert(alicePools.length > 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user