SetProtocol / set.js

Javascript library for the Set Protocol V2
Apache License 2.0
33 stars 14 forks source link

Set to/from token prices to zero if CoinGecko price fetch fails #81

Open cgewecke opened 2 years ago

cgewecke commented 2 years ago

Especially on Polygon, CoinGecko price requests return an empty object for some (liquid) tokens, crashing the quote API

In the initial TradeQuoter review Alex suggested we set the price as 0 when this happens as a way of failing gracefully. (#61).

Would that work for set-ui, or is there a more convenient default value?

Example response with zero values:

{
  from: '0x1494ca1f11d487c2bbe4543e90080aeba4ba3c2b',
  fromTokenAddress: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2',
  toTokenAddress: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2',
  exchangeAdapterName: 'ZeroExApiAdapterV4',
  calldata: '0x415565b00000000000000000000000009f8f72aa9304c8b593d555f12ef6589cc3a579a2',
  gas: '315000',
  gasPrice: '61',
  slippagePercentage: '2.00%',
  fromTokenAmount: '1126868991563',
  toTokenAmount: '90314741816',
  display: {
    inputAmountRaw: '.5',
    inputAmount: '500000000000000000',
    quoteAmount: '499999999999793729',
    fromTokenDisplayAmount: '0.4999999999997937',
    toTokenDisplayAmount: '0.04131269116050703',
+    fromTokenPriceUsd: '$0.00', 
+    toTokenPriceUsd: '$0.00', 
+    gasCostsUsd: '$0.00', 
    gasCostsChainCurrency: '0.0192150 ETH',
    feePercentage: '1.00%',
+    slippage: '0.00%', 
  },
},
asoong commented 2 years ago

This is fine for now, something to add as an issue: