Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: expose TVLs fetched via lib as part of api endpoints #1605

Merged
merged 39 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fb979a2
chore: bump lib version and fix breaking imports due to bump
bvotteler Oct 26, 2023
b9c8dca
Merge remote-tracking branch 'upstream/master' into brendon/feat-use-…
bvotteler Nov 15, 2023
1a18967
chore: added empty api/tvlDex and vercel defs
bvotteler Nov 20, 2023
8c2e296
chore: rename api/tvlDex to api/tvl_dex to keep naming consistent ins…
bvotteler Nov 20, 2023
df91047
feat: return pooled MonetaryAmounts in json format
bvotteler Nov 21, 2023
729b434
fix: incorrect path to js file
bvotteler Nov 21, 2023
86cd59e
chore: add lib as dependency to api/package.json
bvotteler Nov 21, 2023
a9cf745
chore: updated lock file
bvotteler Nov 21, 2023
b193a71
chore: align polkadot util-crypto version in deps with implicit one f…
bvotteler Nov 21, 2023
a24b33c
fix: process env var names
bvotteler Nov 21, 2023
9a3dbdd
chore: check connection, explicitly connect if necessary
bvotteler Nov 21, 2023
8df7c5b
chore: try to force connection on creation
bvotteler Nov 21, 2023
10f0592
fix: use parachain instead of relaychain url
bvotteler Nov 21, 2023
e8fe7bd
chore: increase max duration
bvotteler Nov 21, 2023
9ef64aa
chore: return atomic and human readable amounts
bvotteler Nov 22, 2023
3e07c33
fix: atomic amount
bvotteler Nov 22, 2023
c6c240d
chore: add coingecko ids for all currencies
bvotteler Nov 22, 2023
2f4f25e
chore: add monetary dependency, add usd conversions for dex tvl
bvotteler Nov 22, 2023
0f47718
fix: remove unnecessary conversion, incorrect parameter, and updated …
bvotteler Nov 22, 2023
6746e9a
chore: remove unused import
bvotteler Nov 22, 2023
fc4b188
chore: use monetary methods for usd conversion
bvotteler Nov 22, 2023
e2af6e3
chore: strip usd atomic amount
bvotteler Nov 22, 2023
84ff3fb
fix: get usd amount as normal string, not atomic amount string
bvotteler Nov 22, 2023
f7bb75e
fix: pass through usdPrice for exchange rate
bvotteler Nov 22, 2023
76aa46a
fix: remove undefined var from returned json blob
bvotteler Nov 22, 2023
281e8ea
chore: remove assert
bvotteler Nov 22, 2023
a5c8f10
chore: use defined var instead of reconstructing Big
bvotteler Nov 22, 2023
b25e257
chore: dedupe/consolidate monetary amounts with same currencies
bvotteler Nov 22, 2023
7d316b1
fix: typo
bvotteler Nov 22, 2023
c55c477
chore: replace for with forEach
bvotteler Nov 22, 2023
e355a38
refactor: improved name for helper method
bvotteler Nov 22, 2023
84b83c1
Revert "chore: bump lib version and fix breaking imports due to bump"
bvotteler Nov 22, 2023
f950699
Revert "Revert "chore: bump lib version and fix breaking imports due …
bvotteler Nov 22, 2023
6ad7b83
chore: undo consolidation of monetary amounts - having monetary amoun…
bvotteler Nov 22, 2023
cf7de3f
feat: first cut at adding loan tvl endpoint
bvotteler Nov 29, 2023
6f2d0af
fix: close interbtc api connections, fetch coingecko ids for lending …
bvotteler Nov 29, 2023
7ce2337
chore: bump lib to v 2.6.0 and update imports
bvotteler Nov 29, 2023
1dc403c
Merge branch 'master' into brendon/feat-use-lib-in-api
bvotteler Nov 29, 2023
428a9c9
chore: update api/package-lock
bvotteler Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions api/currency-utils.js
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 };
Loading
Loading