Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search for pools on-chain #375

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/balancer/OceanPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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: {},
Expand Down
3 changes: 1 addition & 2 deletions src/ocean/Ocean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down