Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 864ea92

Browse files
authored
fix: filter tokens in prices which do not exist on the network (#265)
1 parent 939cae1 commit 864ea92

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/services/swap_service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { OrderPrunerPermittedFeeTypes } from '@0x/asset-swapper/lib/src/types';
1111
import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
1212
import { ERC20TokenContract, WETH9Contract } from '@0x/contract-wrappers';
1313
import { assetDataUtils, SupportedProvider } from '@0x/order-utils';
14-
import { BigNumber, decodeThrownErrorAsRevertError, RevertError } from '@0x/utils';
14+
import { BigNumber, decodeThrownErrorAsRevertError, NULL_ADDRESS, RevertError } from '@0x/utils';
1515
import { TxData, Web3Wrapper } from '@0x/web3-wrapper';
1616
import * as _ from 'lodash';
1717

@@ -190,7 +190,9 @@ export class SwapService {
190190
// returns price in sellToken units, e.g What is the price of 1 ZRX (in DAI)
191191
// Equivalent to performing multiple swap quotes selling sellToken and buying 1 whole buy token
192192
const takerAssetData = assetDataUtils.encodeERC20AssetData(sellToken.tokenAddress);
193-
const queryAssetData = TokenMetadatasForChains.filter(m => m.symbol !== sellToken.symbol);
193+
const queryAssetData = TokenMetadatasForChains.filter(m => m.symbol !== sellToken.symbol).filter(
194+
m => m.tokenAddresses[CHAIN_ID] !== NULL_ADDRESS,
195+
);
194196
const chunkSize = 20;
195197
const assetDataChunks = _.chunk(queryAssetData, chunkSize);
196198
const allResults = _.flatten(
@@ -226,7 +228,7 @@ export class SwapService {
226228
const { makerAssetAmount, totalTakerAssetAmount } = quote.bestCaseQuoteInfo;
227229
const unitMakerAssetAmount = Web3Wrapper.toUnitAmount(makerAssetAmount, buyTokenDecimals);
228230
const unitTakerAssetAmount = Web3Wrapper.toUnitAmount(totalTakerAssetAmount, sellTokenDecimals);
229-
const price = unitTakerAssetAmount.dividedBy(unitMakerAssetAmount).decimalPlaces(buyTokenDecimals);
231+
const price = unitTakerAssetAmount.dividedBy(unitMakerAssetAmount).decimalPlaces(sellTokenDecimals);
230232
return {
231233
symbol: queryAssetData[i].symbol,
232234
price,

0 commit comments

Comments
 (0)