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:
commit
272ef5c08b
@ -4,8 +4,7 @@ import { TransactionReceipt } from 'web3-core'
|
|||||||
import { Pool } from './Pool'
|
import { Pool } from './Pool'
|
||||||
import { EventData, Filter } from 'web3-eth-contract'
|
import { EventData, Filter } from 'web3-eth-contract'
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import { MetadataCache } from '../metadatacache/MetadataCache'
|
|
||||||
import { didNoZeroX, didPrefixed } from '../utils'
|
|
||||||
declare type PoolTransactionType = 'swap' | 'join' | 'exit'
|
declare type PoolTransactionType = 'swap' | 'join' | 'exit'
|
||||||
|
|
||||||
const POOL_MAX_AMOUNT_IN_LIMIT = 0.25 // maximum 1/4 of the pool reserve
|
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 {
|
export class OceanPool extends Pool {
|
||||||
public oceanAddress: string = null
|
public oceanAddress: string = null
|
||||||
public dtAddress: string = null
|
public dtAddress: string = null
|
||||||
public MetadataCache: MetadataCache = null
|
|
||||||
constructor(
|
constructor(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
factoryABI: AbiItem | AbiItem[] = null,
|
factoryABI: AbiItem | AbiItem[] = null,
|
||||||
poolABI: AbiItem | AbiItem[] = null,
|
poolABI: AbiItem | AbiItem[] = null,
|
||||||
factoryAddress: string = null,
|
factoryAddress: string = null,
|
||||||
oceanAddress: string = null,
|
oceanAddress: string = null,
|
||||||
MetadataCache: MetadataCache = null,
|
|
||||||
gaslimit?: number
|
gaslimit?: number
|
||||||
) {
|
) {
|
||||||
super(web3, factoryABI, poolABI, factoryAddress, gaslimit)
|
super(web3, factoryABI, poolABI, factoryAddress, gaslimit)
|
||||||
if (oceanAddress) {
|
if (oceanAddress) {
|
||||||
this.oceanAddress = oceanAddress
|
this.oceanAddress = oceanAddress
|
||||||
}
|
}
|
||||||
this.MetadataCache = MetadataCache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -813,13 +810,7 @@ export class OceanPool extends Pool {
|
|||||||
* @return {String[]}
|
* @return {String[]}
|
||||||
*/
|
*/
|
||||||
public async searchPoolforDT(dtAddress: string): Promise<string[]> {
|
public async searchPoolforDT(dtAddress: string): Promise<string[]> {
|
||||||
const did = didPrefixed(didNoZeroX(dtAddress))
|
|
||||||
const result: string[] = []
|
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 factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress)
|
||||||
const events = await factory.getPastEvents('BPoolRegistered', {
|
const events = await factory.getPastEvents('BPoolRegistered', {
|
||||||
filter: {},
|
filter: {},
|
||||||
|
@ -57,8 +57,7 @@ export class Ocean extends Instantiable {
|
|||||||
instanceConfig.config.poolFactoryABI,
|
instanceConfig.config.poolFactoryABI,
|
||||||
instanceConfig.config.poolABI,
|
instanceConfig.config.poolABI,
|
||||||
instanceConfig.config.poolFactoryAddress,
|
instanceConfig.config.poolFactoryAddress,
|
||||||
instanceConfig.config.oceanTokenAddress,
|
instanceConfig.config.oceanTokenAddress
|
||||||
instance.metadatacache
|
|
||||||
)
|
)
|
||||||
instance.fixedRateExchange = new OceanFixedRateExchange(
|
instance.fixedRateExchange = new OceanFixedRateExchange(
|
||||||
instanceConfig.config.web3Provider,
|
instanceConfig.config.web3Provider,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user