Skip to content

Commit

Permalink
chore: undo consolidation of monetary amounts - having monetary amoun…
Browse files Browse the repository at this point in the history
…t pairs can be useful and consolidation can easily be done by consumers of the api instead
  • Loading branch information
bvotteler committed Nov 22, 2023
1 parent f950699 commit 6ad7b83
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions api/tvl_dex.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
import { createInterBtcApi } from "@interlay/interbtc-api";
import { getCoingeckoId, getCoingeckoQueryUrl, getUsdMonetaryAmount } from "./currency-utils";

const consolidateMonetaryAmounts = (monetaryAmounts) => {
// { <ticker_string>: <MonetaryAmount> }
const tickerToAmountMap = new Map();

monetaryAmounts.forEach(monAmt => {
const ticker = monAmt.currency.ticker;
if (tickerToAmountMap.has(ticker)) {
const newMonAmt = tickerToAmountMap.get(ticker).add(monAmt);
tickerToAmountMap.set(ticker, newMonAmt);
} else {
tickerToAmountMap.set(ticker, monAmt);
}
});

return Array.from(tickerToAmountMap.values());
};

const tvlDex = async (request, response) => {
if (request.method === 'GET') {
const interbtcApi = await createInterBtcApi(
Expand All @@ -40,9 +23,7 @@ const tvlDex = async (request, response) => {
const cgResponse = await fetch(queryUrl, { headers: { "accept": "application/json" } });
const cgData = await cgResponse.json();

const allAmounts = pools.flatMap((pool) => pool.pooledCurrencies);

const amounts = consolidateMonetaryAmounts(allAmounts)
const amounts = pools.flatMap((pool) => pool.pooledCurrencies)
.map((monetaryAmount) => {
const atomicAmount = monetaryAmount.toString(true);
const amount = monetaryAmount.toString();
Expand Down

0 comments on commit 6ad7b83

Please sign in to comment.