Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Allow to not specify hops
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Nov 16, 2020
1 parent edc7e7d commit 24fb254
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/api/dexPriceEstimator/DexPriceEstimatorApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js'
import { assert, TEN_BIG_NUMBER, ONE_BIG_NUMBER } from '@gnosis.pm/dex-js'
import { ORDER_BOOK_HOPS_DEFAULT, ORDER_BOOK_HOPS_MAX } from 'const'
import { ORDER_BOOK_HOPS_MAX } from 'const'

export interface DexPriceEstimatorApi {
getPrice(params: GetPriceParams): Promise<BigNumber | null>
Expand Down Expand Up @@ -155,16 +155,20 @@ export class DexPriceEstimatorApiImpl implements DexPriceEstimatorApi {
}

public getOrderBookUrl(params: OrderBookParams): string {
const { networkId, baseTokenId, quoteTokenId, hops = ORDER_BOOK_HOPS_DEFAULT, batchId } = params
assert(hops >= 0, 'Hops should be positive')
assert(hops <= ORDER_BOOK_HOPS_MAX, 'Hops should be not be greater than ' + ORDER_BOOK_HOPS_MAX)
const { networkId, baseTokenId, quoteTokenId, hops, batchId } = params
if (hops) {
assert(hops <= ORDER_BOOK_HOPS_MAX, 'Hops should be not be greater than ' + ORDER_BOOK_HOPS_MAX)
}

const baseUrl = this._getBaseUrl(networkId)

let url = `${baseUrl}markets/${baseTokenId}-${quoteTokenId}?atoms=true&hops=${hops}`
let url = `${baseUrl}markets/${baseTokenId}-${quoteTokenId}?atoms=true`
if (batchId) {
url += `&batchId=${batchId}`
}
if (hops) {
url += `hops=${hops}`
}
return url
}

Expand Down
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const WXDAI_ADDRESS_XDAI = '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d'
export const WETH_ADDRESS_XDAI = '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1'

export const ORDER_BOOK_HOPS_DEFAULT = 2
export const ORDER_BOOK_HOPS_MAX = 2
export const ORDER_BOOK_HOPS_MAX = 100

export const REFRESH_WHEN_SECONDS_LEFT = 60 // 1min before batch done
// for stable reference
Expand Down

0 comments on commit 24fb254

Please sign in to comment.