@defisaver/positions-sdk 2.1.149 → 2.1.150-cirbtc-dev

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.
@@ -127,6 +127,7 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
127
127
  stakingPositions[address.toLowerCase()] = {
128
128
  aaveV3: {},
129
129
  morphoBlue: {},
130
+ morphoMidnight: {},
130
131
  compoundV3: {},
131
132
  spark: {},
132
133
  aaveV2: {},
@@ -494,9 +495,32 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
494
495
  }))).flat(),
495
496
  ...morphoMidnightMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
496
497
  try {
497
- const accData = yield (0, morphoMidnight_1._getMorphoMidnightAccountData)(client, network, address, market, morphoMidnightMarketsData[market.value]);
498
- if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
499
- positions[address.toLowerCase()].morphoMidnight[market.value] = { error: '', data: accData };
498
+ const [accDataPromise, earnDataPromise] = yield Promise.allSettled([
499
+ (0, morphoMidnight_1._getMorphoMidnightAccountData)(client, network, address, market, morphoMidnightMarketsData[market.value]),
500
+ (0, morphoMidnight_1.getMorphoMidnightEarn)(client, network, address, market, morphoMidnightMarketsData[market.value]),
501
+ ]);
502
+ if (accDataPromise.status === 'rejected') {
503
+ console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, accDataPromise.reason);
504
+ positions[address.toLowerCase()].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
505
+ }
506
+ if (earnDataPromise.status === 'rejected') {
507
+ console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, earnDataPromise.reason);
508
+ positions[address.toLowerCase()].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
509
+ }
510
+ if (accDataPromise.status !== 'rejected') {
511
+ const accData = accDataPromise.value;
512
+ if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
513
+ positions[address.toLowerCase()].morphoMidnight[market.value] = { error: '', data: accData };
514
+ }
515
+ if (earnDataPromise.status !== 'rejected') {
516
+ const earnData = earnDataPromise.value;
517
+ if (earnData && new decimal_js_1.default(earnData.amount).gt(0)) {
518
+ stakingPositions[address.toLowerCase()].morphoMidnight[market.value] = {
519
+ error: '',
520
+ data: earnData,
521
+ };
522
+ }
523
+ }
500
524
  }
501
525
  catch (error) {
502
526
  console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, error);
@@ -7,7 +7,8 @@ export declare enum CompoundVersions {
7
7
  'CompoundV3USDbC' = "v3-USDbC",
8
8
  'CompoundV3USDT' = "v3-USDT",
9
9
  'CompoundV3USDS' = "v3-USDS",
10
- 'CompoundV3wstETH' = "v3-wstETH"
10
+ 'CompoundV3wstETH' = "v3-wstETH",
11
+ 'CompoundV3InstitutionalUSDC' = "v3-institutional-USDC"
11
12
  }
12
13
  export declare enum CompoundVersionType {
13
14
  V2 = "v2",
@@ -21,6 +22,7 @@ export interface CompoundMarketData {
21
22
  chainIds: NetworkNumber[];
22
23
  label: string;
23
24
  shortLabel: string;
25
+ url: string;
24
26
  value: CompoundVersions;
25
27
  baseAsset: string;
26
28
  collAssets: readonly string[];
@@ -11,6 +11,7 @@ var CompoundVersions;
11
11
  CompoundVersions["CompoundV3USDT"] = "v3-USDT";
12
12
  CompoundVersions["CompoundV3USDS"] = "v3-USDS";
13
13
  CompoundVersions["CompoundV3wstETH"] = "v3-wstETH";
14
+ CompoundVersions["CompoundV3InstitutionalUSDC"] = "v3-institutional-USDC";
14
15
  })(CompoundVersions || (exports.CompoundVersions = CompoundVersions = {}));
15
16
  var CompoundVersionType;
16
17
  (function (CompoundVersionType) {
@@ -7,12 +7,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { BaseError, ContractFunctionRevertedError } from 'viem';
10
11
  import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
11
12
  import { CompV3ViewContractViem } from '../contracts';
12
13
  import { ClaimType } from '../types/claiming';
14
+ // `CometRewards.NotSupported(address)`. CometRewards reverts with it for any Comet that has no
15
+ // `rewardConfig` set - such a market never accrues COMP, so there is nothing to claim.
16
+ // Not decodable by name, since the error lives in CometRewards' ABI and we call through CompV3View.
17
+ const NOT_SUPPORTED_ERROR_SIG = '0x9c58e3b6';
18
+ // Only an actual on-chain revert counts - viem reports transport failures as ContractFunctionExecutionError too.
19
+ const isMarketWithoutRewardsConfig = (err) => {
20
+ var _a;
21
+ if (!(err instanceof BaseError))
22
+ return false;
23
+ const revert = err.walk((e) => e instanceof ContractFunctionRevertedError);
24
+ return revert instanceof ContractFunctionRevertedError && !!((_a = revert.raw) === null || _a === void 0 ? void 0 : _a.startsWith(NOT_SUPPORTED_ERROR_SIG));
25
+ };
13
26
  export const getCompoundV3Rewards = (provider, network, user, market) => __awaiter(void 0, void 0, void 0, function* () {
14
27
  const compV3View = CompV3ViewContractViem(provider, network);
15
- const rewards = yield compV3View.read.getRewardsOwed([market, user]);
28
+ const rewards = yield compV3View.read.getRewardsOwed([market, user]).catch((err) => {
29
+ if (isMarketWithoutRewardsConfig(err))
30
+ return null;
31
+ throw err;
32
+ });
16
33
  if (!rewards || rewards.owed.toString() === '0' || getAssetInfoByAddress(rewards.token, network).symbol !== 'COMP')
17
34
  return [];
18
35
  return [{