Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
feat(market-service): safe URL construction with URL module (#1193)
Browse files Browse the repository at this point in the history
* fix: construct osmosis urls with url module

* fix update tests
  • Loading branch information
pastaghost authored Feb 7, 2023
1 parent 5301d20 commit 4b8931d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/market-service/src/osmosis/osmosis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const osmosisMarketService = new OsmosisMarketService({
jsonRpcProviderUrl: '',
unchainedEthereumHttpUrl: '',
unchainedEthereumWsUrl: '',
osmosisMarketDataUrl: '',
osmosisPoolMetadataUrl: '',
osmosisMarketDataUrl: 'https://api-osmosis.imperator.co/',
osmosisPoolMetadataUrl: 'https://daemon.osmosis.shapeshift.com',
})

describe('osmosis market service', () => {
Expand Down
24 changes: 18 additions & 6 deletions packages/market-service/src/osmosis/osmosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ export class OsmosisMarketService implements MarketService {
}

const symbol = adapters.assetIdToOsmosis(assetId)
const { data }: { data: OsmosisMarketCap[] } = await axios.get(
`${this.providerUrls.osmosisMarketDataUrl}/tokens/v2/${symbol}`,

const { data } = await axios.get<OsmosisMarketCap[]>(
(() => {
const url = new URL(`/tokens/v2/${symbol}`, this.providerUrls.osmosisMarketDataUrl)
return url.toString()
})(),
)

const marketData = data[0]

if (!marketData) return null
Expand Down Expand Up @@ -153,11 +158,18 @@ export class OsmosisMarketService implements MarketService {
try {
// Historical timeframe data from the v2 endpoint currently does not support ranges greater than 1 month
// and v1 doesn't support ranges less than 7 week, so we use both to get all ranges.
const url = `${this.providerUrls.osmosisMarketDataUrl}/tokens/${
isV1 ? 'v1' : 'v2'
}/historical/${symbol}/chart?${isV1 ? 'range' : 'tf'}=${range}`

const { data } = await axios.get<OsmosisHistoryData[]>(url)
const { data } = await axios.get<OsmosisHistoryData[]>(
(() => {
const url = new URL(
`/tokens/${isV1 ? 'v1' : 'v2'}/historical/${symbol}/chart?${
isV1 ? 'range' : 'tf'
}=${range}`,
this.providerUrls.osmosisMarketDataUrl,
)
return url.toString()
})(),
)

// return the correct range of data points for each timeframe
const taperedData = data.slice(-start)
Expand Down

0 comments on commit 4b8931d

Please sign in to comment.