@defisaver/positions-sdk 2.1.148 → 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.
@@ -10,12 +10,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getCompoundV3Rewards = void 0;
13
+ const viem_1 = require("viem");
13
14
  const tokens_1 = require("@defisaver/tokens");
14
15
  const contracts_1 = require("../contracts");
15
16
  const claiming_1 = require("../types/claiming");
17
+ // `CometRewards.NotSupported(address)`. CometRewards reverts with it for any Comet that has no
18
+ // `rewardConfig` set - such a market never accrues COMP, so there is nothing to claim.
19
+ // Not decodable by name, since the error lives in CometRewards' ABI and we call through CompV3View.
20
+ const NOT_SUPPORTED_ERROR_SIG = '0x9c58e3b6';
21
+ // Only an actual on-chain revert counts - viem reports transport failures as ContractFunctionExecutionError too.
22
+ const isMarketWithoutRewardsConfig = (err) => {
23
+ var _a;
24
+ if (!(err instanceof viem_1.BaseError))
25
+ return false;
26
+ const revert = err.walk((e) => e instanceof viem_1.ContractFunctionRevertedError);
27
+ return revert instanceof viem_1.ContractFunctionRevertedError && !!((_a = revert.raw) === null || _a === void 0 ? void 0 : _a.startsWith(NOT_SUPPORTED_ERROR_SIG));
28
+ };
16
29
  const getCompoundV3Rewards = (provider, network, user, market) => __awaiter(void 0, void 0, void 0, function* () {
17
30
  const compV3View = (0, contracts_1.CompV3ViewContractViem)(provider, network);
18
- const rewards = yield compV3View.read.getRewardsOwed([market, user]);
31
+ const rewards = yield compV3View.read.getRewardsOwed([market, user]).catch((err) => {
32
+ if (isMarketWithoutRewardsConfig(err))
33
+ return null;
34
+ throw err;
35
+ });
19
36
  if (!rewards || rewards.owed.toString() === '0' || (0, tokens_1.getAssetInfoByAddress)(rewards.token, network).symbol !== 'COMP')
20
37
  return [];
21
38
  return [{