Skip to content

Commit

Permalink
Merge pull request #414 from curvefi/fix/fix-getUsdRate-for-lite
Browse files Browse the repository at this point in the history
fix: fixed getUsdRate for wrapped native token
  • Loading branch information
Macket authored Nov 20, 2024
2 parents 80e8e64 + 84ffc6b commit 984a824
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/api",
"version": "2.65.7",
"version": "2.65.8",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
1 change: 1 addition & 0 deletions src/external-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export const _getLiteNetworksData = memoize(
},
API_CONSTANTS: {
nativeTokenName: config.native_currency_coingecko_id,
wrappedNativeTokenAddress: config.wrapped_native_token,
},
};
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface INetworkConstants {
ZERO_ADDRESS: string,
API_CONSTANTS?: {
nativeTokenName: string
wrappedNativeTokenAddress: string
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ export const _getUsdRate = async (assetId: string): Promise<number> => {
assetId = 'curve-dao-token';
}

if(curve.isLiteChain && assetId.toLowerCase() === curve.constants.API_CONSTANTS?.wrappedNativeTokenAddress.toLowerCase()) {
assetId = nativeTokenName
}

if ((_usdRatesCache[assetId]?.time || 0) + 600000 < Date.now()) {
const url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
`https://api.coingecko.com/api/v3/simple/price?ids=${assetId}&vs_currencies=usd` :
Expand Down

0 comments on commit 984a824

Please sign in to comment.