@curvefi/api 2.65.6 → 2.65.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/curve.js CHANGED
@@ -445,6 +445,9 @@ class Curve {
445
445
  this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
446
446
  this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
447
447
  this.constants.GAUGES = extractGauges(this.constants.POOLS_DATA);
448
+ if (this.isLiteChain) {
449
+ this.constants.API_CONSTANTS = network_constants.API_CONSTANTS;
450
+ }
448
451
  const [cTokens, yTokens, ycTokens, aTokens] = [
449
452
  (_e = network_constants.cTokens) !== null && _e !== void 0 ? _e : [],
450
453
  (_f = network_constants.yTokens) !== null && _f !== void 0 ? _f : [],
@@ -221,6 +221,9 @@ export const _getLiteNetworksData = memoize((networkName) => __awaiter(void 0, v
221
221
  : `W${native_currency_symbol}`,
222
222
  wrappedAddress: wrapped_native_token,
223
223
  },
224
+ API_CONSTANTS: {
225
+ nativeTokenName: config.native_currency_coingecko_id,
226
+ },
224
227
  };
225
228
  }
226
229
  catch (error) {
@@ -87,6 +87,9 @@ export interface INetworkConstants {
87
87
  GAUGES: string[];
88
88
  FACTORY_GAUGE_IMPLEMENTATIONS: any;
89
89
  ZERO_ADDRESS: string;
90
+ API_CONSTANTS?: {
91
+ nativeTokenName: string;
92
+ };
90
93
  }
91
94
  export interface ICurve {
92
95
  provider: ethers.BrowserProvider | ethers.JsonRpcProvider;
package/lib/utils.js CHANGED
@@ -366,7 +366,7 @@ export const _getRewardsFromApi = () => __awaiter(void 0, void 0, void 0, functi
366
366
  });
367
367
  const _usdRatesCache = {};
368
368
  export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, function* () {
369
- var _f, _g;
369
+ var _f, _g, _h, _j;
370
370
  if (curve.chainId === 1 && assetId.toLowerCase() === '0x8762db106b2c2a0bccb3a80d1ed41273552616e8')
371
371
  return 0; // RSR
372
372
  const pricesFromApi = yield _getUsdPricesFromApi();
@@ -374,7 +374,7 @@ export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, functi
374
374
  return pricesFromApi[assetId.toLowerCase()];
375
375
  if (assetId === 'USD' || (curve.chainId === 137 && (assetId.toLowerCase() === curve.constants.COINS.am3crv.toLowerCase())))
376
376
  return 1;
377
- let chainName = {
377
+ let chainName = curve.isLiteChain ? yield curve.constants.NETWORK_NAME : {
378
378
  1: 'ethereum',
379
379
  10: 'optimistic-ethereum',
380
380
  56: "binance-smart-chain",
@@ -393,7 +393,7 @@ export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, functi
393
393
  42161: 'arbitrum-one',
394
394
  1313161554: 'aurora',
395
395
  }[curve.chainId];
396
- const nativeTokenName = {
396
+ const nativeTokenName = curve.isLiteChain ? (_g = (_f = curve.constants) === null || _f === void 0 ? void 0 : _f.API_CONSTANTS) === null || _g === void 0 ? void 0 : _g.nativeTokenName : {
397
397
  1: 'ethereum',
398
398
  10: 'ethereum',
399
399
  56: 'binancecoin',
@@ -415,6 +415,9 @@ export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, functi
415
415
  if (chainName === undefined) {
416
416
  throw Error('curve object is not initialized');
417
417
  }
418
+ if (nativeTokenName === undefined) {
419
+ throw Error('nativeTokenName not found');
420
+ }
418
421
  assetId = {
419
422
  'CRV': 'curve-dao-token',
420
423
  'EUR': 'stasis-eurs',
@@ -432,13 +435,13 @@ export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, functi
432
435
  if (assetId.toLowerCase() === curve.constants.ALIASES.crv) {
433
436
  assetId = 'curve-dao-token';
434
437
  }
435
- if ((((_f = _usdRatesCache[assetId]) === null || _f === void 0 ? void 0 : _f.time) || 0) + 600000 < Date.now()) {
438
+ if ((((_h = _usdRatesCache[assetId]) === null || _h === void 0 ? void 0 : _h.time) || 0) + 600000 < Date.now()) {
436
439
  const url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
437
440
  `https://api.coingecko.com/api/v3/simple/price?ids=${assetId}&vs_currencies=usd` :
438
441
  `https://api.coingecko.com/api/v3/simple/token_price/${chainName}?contract_addresses=${assetId}&vs_currencies=usd`;
439
442
  const response = yield axios.get(url);
440
443
  try {
441
- _usdRatesCache[assetId] = { 'rate': (_g = response.data[assetId]['usd']) !== null && _g !== void 0 ? _g : 0, 'time': Date.now() };
444
+ _usdRatesCache[assetId] = { 'rate': (_j = response.data[assetId]['usd']) !== null && _j !== void 0 ? _j : 0, 'time': Date.now() };
442
445
  }
443
446
  catch (err) { // TODO pay attention!
444
447
  _usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.65.6",
3
+ "version": "2.65.7",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",