@curvefi/api 2.65.18 → 2.65.20

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.
@@ -707,8 +707,26 @@ export class PoolTemplate extends CorePool {
707
707
  return __awaiter(this, void 0, void 0, function* () {
708
708
  const amountsBN = amounts.map(BN);
709
709
  let pricesBN = [];
710
+ const multicallContract = curve.contracts[this.address].multicallContract;
710
711
  if (this.isCrypto || this.id === 'wsteth') {
711
- pricesBN = (yield this._underlyingPrices()).map(BN);
712
+ if (curve.isLiteChain) {
713
+ const prices = this.id.includes('twocrypto')
714
+ ? [
715
+ 1,
716
+ Number(yield curve.contracts[this.address].contract.price_oracle()) / (Math.pow(10, 18)),
717
+ ]
718
+ : [
719
+ 1,
720
+ ...(yield curve.multicallProvider.all([
721
+ multicallContract.price_oracle(0),
722
+ multicallContract.price_oracle(1),
723
+ ])).map((value) => Number(value) / (Math.pow(10, 18))),
724
+ ];
725
+ pricesBN = prices.map(BN);
726
+ }
727
+ else {
728
+ pricesBN = (yield this._underlyingPrices()).map(BN);
729
+ }
712
730
  }
713
731
  else {
714
732
  pricesBN = yield this._storedRatesBN(true);
package/lib/utils.js CHANGED
@@ -442,12 +442,34 @@ export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, functi
442
442
  const url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
443
443
  `https://api.coingecko.com/api/v3/simple/price?ids=${assetId}&vs_currencies=usd` :
444
444
  `https://api.coingecko.com/api/v3/simple/token_price/${chainName}?contract_addresses=${assetId}&vs_currencies=usd`;
445
- const response = yield axios.get(url);
446
445
  try {
447
- _usdRatesCache[assetId] = { 'rate': (_k = response.data[assetId]['usd']) !== null && _k !== void 0 ? _k : 0, 'time': Date.now() };
446
+ const response = yield axios.get(url, {
447
+ validateStatus: (status) => status < 500,
448
+ });
449
+ if (response.status === 200 && ((_k = response.data[assetId]) === null || _k === void 0 ? void 0 : _k.usd) !== undefined) {
450
+ _usdRatesCache[assetId] = {
451
+ 'rate': response.data[assetId].usd,
452
+ 'time': Date.now(),
453
+ };
454
+ }
455
+ else {
456
+ if (!curve.isLiteChain) {
457
+ console.warn(`Non-200 response for ${assetId}:`, response.status, response.data);
458
+ }
459
+ _usdRatesCache[assetId] = {
460
+ 'rate': 0,
461
+ 'time': Date.now(),
462
+ };
463
+ }
448
464
  }
449
- catch (err) { // TODO pay attention!
450
- _usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
465
+ catch (err) {
466
+ if (!curve.isLiteChain) {
467
+ console.error(`Error fetching USD rate for ${assetId}:`, err.message);
468
+ }
469
+ _usdRatesCache[assetId] = {
470
+ 'rate': 0,
471
+ 'time': Date.now(),
472
+ };
451
473
  }
452
474
  }
453
475
  return _usdRatesCache[assetId]['rate'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.65.18",
3
+ "version": "2.65.20",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",