diff --git a/src/utils/currencies.js b/src/utils/currencies.js index de15aa8..76a6984 100644 --- a/src/utils/currencies.js +++ b/src/utils/currencies.js @@ -38,7 +38,7 @@ export const currencies = [ }, { value: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', - label: 'Wrapped Ether', + label: 'WETH', img: `${TOKEN_COIN_API}/60.png`, width: '5%', humanReadibleFn: toEther, diff --git a/src/utils/prices.js b/src/utils/prices.js index 76d86dc..c2eb56a 100644 --- a/src/utils/prices.js +++ b/src/utils/prices.js @@ -1,6 +1,7 @@ import cc from 'cryptocompare' import { getTokenLabel } from './currencies' +const COMPOUND_V2_API = 'https://api.compound.finance/api/v2/ctoken' export const generatePairKey = (from, to) => `${from}_${to}` export const getUsdPrice = async ticker => { const price = await cc.price(ticker, 'USD') @@ -11,9 +12,25 @@ export const formatPercent = number => Number(number).toLocaleString(undefined,{ export const percentToGoal = (pledged, goal) => formatPercent(Number(pledged) / Number(goal)) +const supportedCompoundTokens = ['cETH', 'cDAI'] +const getCompoundRates = async prices => { + const values = {} + const compound = await fetch(COMPOUND_V2_API) + const res = await compound.json() + res.cToken + .filter(t => supportedCompoundTokens.includes(t.symbol)) + .forEach(t => { + const { symbol, exchange_rate, underlying_price: { value } } = t + const underlyingUsd = Number(value) * Number(prices['ETH']['USD']) + const USD = Number(exchange_rate.value) * Number(underlyingUsd) + values[symbol] = { USD } + }) + return values +} export const getPrices = async () => { - const prices = await cc.priceMulti(['ETH', 'SNT'], ['USD']) - return prices + const prices = await cc.priceMulti(['ETH', 'SNT', 'DAI'], ['USD']) + const compound = await getCompoundRates(prices) + return { ...prices, ...compound, WETH: {...prices['ETH'] } } } const formatter = new Intl.NumberFormat('en-US', {