Skip to content

Commit

Permalink
Merge pull request #413 from curvefi/fix/fix-getUsdRate-for-lite
Browse files Browse the repository at this point in the history
fix: fixed getUsdRate for lite chain
  • Loading branch information
fedorovdg authored Nov 19, 2024
2 parents 7dd09b3 + d4e94d0 commit 80e8e64
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
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.6",
"version": "2.65.7",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
5 changes: 5 additions & 0 deletions src/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ class Curve implements ICurve {
this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
this.constants.GAUGES = extractGauges(this.constants.POOLS_DATA);

if(this.isLiteChain) {
this.constants.API_CONSTANTS = network_constants.API_CONSTANTS
}

const [cTokens, yTokens, ycTokens, aTokens] = [
network_constants.cTokens ?? [],
network_constants.yTokens ?? [],
Expand Down
3 changes: 3 additions & 0 deletions src/external-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ export const _getLiteNetworksData = memoize(
: `W${native_currency_symbol}`,
wrappedAddress: wrapped_native_token,
},
API_CONSTANTS: {
nativeTokenName: config.native_currency_coingecko_id,
},
};
} catch (error) {
console.error('Error fetching network data:', error);
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export interface INetworkConstants {
GAUGES: string[],
FACTORY_GAUGE_IMPLEMENTATIONS: any,
ZERO_ADDRESS: string,
API_CONSTANTS?: {
nativeTokenName: string
}
}

export interface ICurve {
Expand Down
9 changes: 7 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export const _getUsdRate = async (assetId: string): Promise<number> => {

if (assetId === 'USD' || (curve.chainId === 137 && (assetId.toLowerCase() === curve.constants.COINS.am3crv.toLowerCase()))) return 1

let chainName = {
let chainName = curve.isLiteChain? await curve.constants.NETWORK_NAME : {
1: 'ethereum',
10: 'optimistic-ethereum',
56: "binance-smart-chain",
Expand All @@ -451,7 +451,7 @@ export const _getUsdRate = async (assetId: string): Promise<number> => {
1313161554: 'aurora',
}[curve.chainId];

const nativeTokenName = {
const nativeTokenName = curve.isLiteChain ? curve.constants?.API_CONSTANTS?.nativeTokenName:{
1: 'ethereum',
10: 'ethereum',
56: 'binancecoin',
Expand All @@ -475,13 +475,18 @@ export const _getUsdRate = async (assetId: string): Promise<number> => {
throw Error('curve object is not initialized')
}

if (nativeTokenName === undefined) {
throw Error('nativeTokenName not found')
}

assetId = {
'CRV': 'curve-dao-token',
'EUR': 'stasis-eurs',
'BTC': 'bitcoin',
'ETH': 'ethereum',
'LINK': 'link',
}[assetId.toUpperCase()] || assetId

assetId = isEth(assetId) ? nativeTokenName : assetId.toLowerCase();

// No EURT on Coingecko Polygon
Expand Down

0 comments on commit 80e8e64

Please sign in to comment.