1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Merge pull request #375 from oceanprotocol/fix/searchPool

search for pools on-chain
This commit is contained in:
Matthias Kretschmann 2020-10-19 10:13:10 +02:00 committed by GitHub
commit 272ef5c08b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 13 deletions

View File

@ -4,8 +4,7 @@ import { TransactionReceipt } from 'web3-core'
import { Pool } from './Pool'
import { EventData, Filter } from 'web3-eth-contract'
import BigNumber from 'bignumber.js'
import { MetadataCache } from '../metadatacache/MetadataCache'
import { didNoZeroX, didPrefixed } from '../utils'
declare type PoolTransactionType = 'swap' | 'join' | 'exit'
const POOL_MAX_AMOUNT_IN_LIMIT = 0.25 // maximum 1/4 of the pool reserve
@ -41,21 +40,19 @@ export interface PoolTransaction {
export class OceanPool extends Pool {
public oceanAddress: string = null
public dtAddress: string = null
public MetadataCache: MetadataCache = null
constructor(
web3: Web3,
factoryABI: AbiItem | AbiItem[] = null,
poolABI: AbiItem | AbiItem[] = null,
factoryAddress: string = null,
oceanAddress: string = null,
MetadataCache: MetadataCache = null,
gaslimit?: number
) {
super(web3, factoryABI, poolABI, factoryAddress, gaslimit)
if (oceanAddress) {
this.oceanAddress = oceanAddress
}
this.MetadataCache = MetadataCache
}
/**
@ -813,13 +810,7 @@ export class OceanPool extends Pool {
* @return {String[]}
*/
public async searchPoolforDT(dtAddress: string): Promise<string[]> {
const did = didPrefixed(didNoZeroX(dtAddress))
const result: string[] = []
try {
const ddo = await this.MetadataCache.retrieveDDO(did)
return ddo.price.pools
} catch (e) {}
// fallback in case we don't have the asset registred in aqua
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress)
const events = await factory.getPastEvents('BPoolRegistered', {
filter: {},

View File

@ -57,8 +57,7 @@ export class Ocean extends Instantiable {
instanceConfig.config.poolFactoryABI,
instanceConfig.config.poolABI,
instanceConfig.config.poolFactoryAddress,
instanceConfig.config.oceanTokenAddress,
instance.metadatacache
instanceConfig.config.oceanTokenAddress
)
instance.fixedRateExchange = new OceanFixedRateExchange(
instanceConfig.config.web3Provider,