@defisaver/positions-sdk 2.1.171 → 2.1.172

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.
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getLiquitySAndYBold = exports.getLiquityV2Staking = exports.getLiquityV2ClaimableCollateral = exports.getLiquityV2TroveData = exports._getLiquityV2TroveData = exports.getDebtInFrontForInterestRateLiquityV2 = exports.getDebtInFrontForInterestRateIncludingNewDebtLiquityV2 = exports.calculateDebtInFrontLiquityV2 = exports.getLiquityV2UserTroveIds = exports._getLiquityV2UserTroveIds = exports.nftContractCreationBlockMapping = exports.getLiquityV2MarketData = exports._getLiquityV2MarketData = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const memoizee_1 = __importDefault(require("memoizee"));
17
18
  const tokens_1 = require("@defisaver/tokens");
18
19
  const contracts_1 = require("../contracts");
19
20
  const common_1 = require("../types/common");
@@ -392,19 +393,20 @@ const calculateStabilityPoolApy = (spYieldGainParams) => {
392
393
  .toString();
393
394
  return new decimal_js_1.default(annualizedYield).div(totalBoldDeposits).mul(100).toString();
394
395
  };
395
- const getYBoldApyApi = () => __awaiter(void 0, void 0, void 0, function* () {
396
+ const getYBoldApyApi = (0, memoizee_1.default)(() => __awaiter(void 0, void 0, void 0, function* () {
396
397
  try {
397
398
  const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
398
- const yBoldData = yield fetch(url)
399
- .then(res => res.json())
400
- .catch(console.error);
399
+ const response = yield fetch(url, { signal: AbortSignal.timeout(utils_1.DEFAULT_TIMEOUT) });
400
+ if (!response.ok)
401
+ throw new Error(`Failed to fetch yBold APY: ${response.status}`);
402
+ const yBoldData = yield response.json();
401
403
  return new decimal_js_1.default(yBoldData.apr.netAPR).mul(100).toString();
402
404
  }
403
405
  catch (error) {
404
406
  console.error('External API Failure: YBold ', error);
405
407
  return '0';
406
408
  }
407
- });
409
+ }), { promise: true, maxAge: 2 * 60 * 1000 });
408
410
  const calculateSPApy = (spYieldGainParams, spAPYs) => {
409
411
  const { WETH, wsETH, rETH, } = spYieldGainParams;
410
412
  const apy = new decimal_js_1.default(WETH).mul(spAPYs.apyEth).add(new decimal_js_1.default(wsETH).mul(spAPYs.apyWstEth)).add(new decimal_js_1.default(rETH).mul(spAPYs.apyREth))
@@ -8,13 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
+ import memoize from 'memoizee';
11
12
  import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
12
13
  import { createViemContractFromConfigFunc, LiquityV2LegacyViewContractViem, LiquityV2sBoldVaultViem, LiquityV2ViewContractViem, } from '../contracts';
13
14
  import { IncentiveKind, NetworkNumber, } from '../types/common';
14
15
  import { LIQUITY_V2_TROVE_STATUS_ENUM, LiquityV2Versions, } from '../types';
15
16
  import { getStakingApy, STAKING_ASSETS } from '../staking';
16
17
  import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
17
- import { compareAddresses, ethToWeth, getEthAmountForDecimals, MAXUINT, } from '../services/utils';
18
+ import { compareAddresses, DEFAULT_TIMEOUT, ethToWeth, getEthAmountForDecimals, MAXUINT, } from '../services/utils';
18
19
  import { SECONDS_PER_YEAR, ZERO_ADDRESS } from '../constants';
19
20
  import { LiquityV2Markets } from '../markets';
20
21
  import { getViemProvider } from '../services/viem';
@@ -376,19 +377,20 @@ const calculateStabilityPoolApy = (spYieldGainParams) => {
376
377
  .toString();
377
378
  return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
378
379
  };
379
- const getYBoldApyApi = () => __awaiter(void 0, void 0, void 0, function* () {
380
+ const getYBoldApyApi = memoize(() => __awaiter(void 0, void 0, void 0, function* () {
380
381
  try {
381
382
  const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
382
- const yBoldData = yield fetch(url)
383
- .then(res => res.json())
384
- .catch(console.error);
383
+ const response = yield fetch(url, { signal: AbortSignal.timeout(DEFAULT_TIMEOUT) });
384
+ if (!response.ok)
385
+ throw new Error(`Failed to fetch yBold APY: ${response.status}`);
386
+ const yBoldData = yield response.json();
385
387
  return new Dec(yBoldData.apr.netAPR).mul(100).toString();
386
388
  }
387
389
  catch (error) {
388
390
  console.error('External API Failure: YBold ', error);
389
391
  return '0';
390
392
  }
391
- });
393
+ }), { promise: true, maxAge: 2 * 60 * 1000 });
392
394
  const calculateSPApy = (spYieldGainParams, spAPYs) => {
393
395
  const { WETH, wsETH, rETH, } = spYieldGainParams;
394
396
  const apy = new Dec(WETH).mul(spAPYs.apyEth).add(new Dec(wsETH).mul(spAPYs.apyWstEth)).add(new Dec(rETH).mul(spAPYs.apyREth))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.171",
3
+ "version": "2.1.172",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -1,4 +1,5 @@
1
1
  import Dec from 'decimal.js';
2
+ import memoize from 'memoizee';
2
3
  import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
3
4
  import { Client, PublicClient } from 'viem';
4
5
  import {
@@ -19,6 +20,7 @@ import { getStakingApy, STAKING_ASSETS } from '../staking';
19
20
  import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
20
21
  import {
21
22
  compareAddresses,
23
+ DEFAULT_TIMEOUT,
22
24
  ethToWeth,
23
25
  getEthAmountForDecimals,
24
26
  MAXUINT,
@@ -546,20 +548,20 @@ const calculateStabilityPoolApy = (
546
548
  return new Dec(annualizedYield).div(totalBoldDeposits).mul(100).toString();
547
549
  };
548
550
 
549
- const getYBoldApyApi = async () => {
551
+ const getYBoldApyApi = memoize(async () => {
550
552
  try {
551
553
  const url = 'https://ydaemon.yearn.fi/1/vaults/0x23346B04a7f55b8760E5860AA5A77383D63491cD?strategiesDetails=withDetails&strategiesCondition=inQueue';
552
554
 
553
- const yBoldData = await fetch(url)
554
- .then(res => res.json())
555
- .catch(console.error);
555
+ const response = await fetch(url, { signal: AbortSignal.timeout(DEFAULT_TIMEOUT) });
556
+ if (!response.ok) throw new Error(`Failed to fetch yBold APY: ${response.status}`);
557
+ const yBoldData = await response.json();
556
558
 
557
559
  return new Dec(yBoldData.apr.netAPR).mul(100).toString();
558
560
  } catch (error) {
559
561
  console.error('External API Failure: YBold ', error);
560
562
  return '0';
561
563
  }
562
- };
564
+ }, { promise: true, maxAge: 2 * 60 * 1000 });
563
565
 
564
566
  export type sBoldYieldParameters = {
565
567
  WETH: string;
@@ -707,4 +709,4 @@ export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumb
707
709
  yBoldBalance: assetAmountInEth(yBoldBalance.toString(), 'yBOLD'),
708
710
  stYBoldBalance: assetAmountInEth(stYBoldBalance.toString(), 'yBOLD'),
709
711
  };
710
- };
712
+ };