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

Commit

Permalink
fix: filter tokens in prices which do not exist on the network (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
dekz authored Jun 21, 2020
1 parent 939cae1 commit 864ea92
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/services/swap_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { OrderPrunerPermittedFeeTypes } from '@0x/asset-swapper/lib/src/types';
import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
import { ERC20TokenContract, WETH9Contract } from '@0x/contract-wrappers';
import { assetDataUtils, SupportedProvider } from '@0x/order-utils';
import { BigNumber, decodeThrownErrorAsRevertError, RevertError } from '@0x/utils';
import { BigNumber, decodeThrownErrorAsRevertError, NULL_ADDRESS, RevertError } from '@0x/utils';
import { TxData, Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';

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

0 comments on commit 864ea92

Please sign in to comment.