Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use new cg function to get price by id
Browse files Browse the repository at this point in the history
melisaguevara committed Nov 15, 2024
1 parent eb1afaa commit aedff31
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion api/_constants.ts
Original file line number Diff line number Diff line change
@@ -159,7 +159,10 @@ export const BLOCK_TAG_LAG = -1;
// we've decided to keep this list small for now.
export const SUPPORTED_CG_BASE_CURRENCIES = new Set(["eth", "usd"]);
// Note: this is a small set of currencies that the API will derive from the base currencies by using USD as an intermediary.
export const SUPPORTED_CG_DERIVED_CURRENCIES = new Set(["matic"]);
export const SUPPORTED_CG_DERIVED_CURRENCIES = new Set(["azero", "matic"]);
export const CG_CONTRACTS_DEFERRED_TO_ID = new Set([
TOKEN_SYMBOLS_MAP.AZERO.addresses[CHAIN_IDs.MAINNET],
]);

// 1:1 because we don't need to handle underlying tokens on FE
export const EXTERNAL_POOL_TOKEN_EXCHANGE_RATE = utils.fixedPointAdjustment;
16 changes: 11 additions & 5 deletions api/coingecko.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import {
getCachedTokenPrice,
} from "./_utils";
import {
CG_CONTRACTS_DEFERRED_TO_ID,
CHAIN_IDs,
SUPPORTED_CG_BASE_CURRENCIES,
SUPPORTED_CG_DERIVED_CURRENCIES,
@@ -121,11 +122,16 @@ const handler = async (
modifiedBaseCurrency
);
} else {
[, price] = await coingeckoClient.getCurrentPriceByContract(
l1Token,
modifiedBaseCurrency,
platformId
);
[, price] = CG_CONTRACTS_DEFERRED_TO_ID.has(l1Token)
? await coingeckoClient.getCurrentPriceById(
l1Token,
modifiedBaseCurrency
)
: await coingeckoClient.getCurrentPriceByContract(
l1Token,
modifiedBaseCurrency,
platformId
);
}
}

0 comments on commit aedff31

Please sign in to comment.