-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: expose TVLs fetched via lib as part of api endpoints (#1605)
* bump lib to v 2.6.0 and update imports * return pooled MonetaryAmounts in json format for dex and lending * align polkadot util-crypto version in dependencies
- Loading branch information
Showing
12 changed files
with
2,534 additions
and
673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
MonetaryAmount, | ||
ExchangeRate, | ||
Bitcoin, | ||
InterBtc, | ||
Interlay, | ||
KBtc, | ||
Kintsugi, | ||
Kusama, | ||
Polkadot | ||
} from '@interlay/monetary-js'; | ||
import { isForeignAsset } from "@interlay/interbtc-api"; | ||
import Big from "big.js"; | ||
|
||
const COINGECKO_ID_BY_CURRENCY_TICKER = { | ||
[Bitcoin.ticker]: 'bitcoin', | ||
[Kintsugi.ticker]: 'kintsugi', | ||
[KBtc.ticker]: 'bitcoin', | ||
[Kusama.ticker]: 'kusama', | ||
[Polkadot.ticker]: 'polkadot', | ||
[Interlay.ticker]: 'interlay', | ||
[InterBtc.ticker]: 'bitcoin' | ||
}; | ||
|
||
const getCoingeckoId = (currency) => { | ||
if (isForeignAsset(currency)) { | ||
// Force V[DOT/KSM] prices. | ||
switch (currency.ticker) { | ||
case 'VDOT': | ||
return 'voucher-dot'; | ||
case 'VKSM': | ||
return 'voucher-ksm'; | ||
default: | ||
return currency.foreignAsset.coingeckoId; | ||
} | ||
} | ||
return COINGECKO_ID_BY_CURRENCY_TICKER[currency.ticker]; | ||
}; | ||
|
||
const getCoingeckoQueryUrl = (vsId, coingeckoIds) => { | ||
const idsString = coingeckoIds.join(","); | ||
return `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vsId}&ids=${idsString}`; | ||
}; | ||
|
||
const getUsdMonetaryAmount = (monetaryAmount, usdPrice) => { | ||
const usdCurrency = { | ||
name: "US Dollar", | ||
decimals: 2, | ||
ticker: "USD", | ||
humanDecimals: 2 | ||
}; | ||
|
||
const rate = new Big(usdPrice); | ||
|
||
const xToUsd = new ExchangeRate(monetaryAmount.currency, usdCurrency, rate); | ||
return xToUsd.toCounter(monetaryAmount); | ||
} | ||
|
||
export { getCoingeckoId, getCoingeckoQueryUrl, getUsdMonetaryAmount }; |
Oops, something went wrong.
c98b33e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
interbtc-ui-kintsugi-testnet – ./
interbtc-ui.vercel.app
interbtc-ui-kintsugi-testnet-git-master-interlay.vercel.app
interbtc-ui-kintsugi-testnet-interlay.vercel.app
kintnet.interlay.io
c98b33e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
interbtc-ui-interlay-testnet – ./
interbtc-ui-interlay-testnet-git-master-interlay.vercel.app
interbtc-ui-interlay-testnet-interlay.vercel.app
interbtc-ui-interlay-testnet.vercel.app
testnet.interlay.io