mirror of
https://github.com/status-im/liquid-funding.git
synced 2025-02-19 22:58:16 +00:00
add price conversion for all currencies
This commit is contained in:
parent
772e165f7a
commit
35a39fa10d
@ -38,7 +38,7 @@ export const currencies = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
value: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
||||||
label: 'Wrapped Ether',
|
label: 'WETH',
|
||||||
img: `${TOKEN_COIN_API}/60.png`,
|
img: `${TOKEN_COIN_API}/60.png`,
|
||||||
width: '5%',
|
width: '5%',
|
||||||
humanReadibleFn: toEther,
|
humanReadibleFn: toEther,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import cc from 'cryptocompare'
|
import cc from 'cryptocompare'
|
||||||
import { getTokenLabel } from './currencies'
|
import { getTokenLabel } from './currencies'
|
||||||
|
|
||||||
|
const COMPOUND_V2_API = 'https://api.compound.finance/api/v2/ctoken'
|
||||||
export const generatePairKey = (from, to) => `${from}_${to}`
|
export const generatePairKey = (from, to) => `${from}_${to}`
|
||||||
export const getUsdPrice = async ticker => {
|
export const getUsdPrice = async ticker => {
|
||||||
const price = await cc.price(ticker, 'USD')
|
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))
|
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 () => {
|
export const getPrices = async () => {
|
||||||
const prices = await cc.priceMulti(['ETH', 'SNT'], ['USD'])
|
const prices = await cc.priceMulti(['ETH', 'SNT', 'DAI'], ['USD'])
|
||||||
return prices
|
const compound = await getCompoundRates(prices)
|
||||||
|
return { ...prices, ...compound, WETH: {...prices['ETH'] } }
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatter = new Intl.NumberFormat('en-US', {
|
const formatter = new Intl.NumberFormat('en-US', {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user