@defisaver/positions-sdk 2.1.153-dev → 2.1.154-shifter-v2-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.
Files changed (118) hide show
  1. package/cjs/aaveV2/index.js +2 -0
  2. package/cjs/claiming/index.d.ts +1 -2
  3. package/cjs/claiming/index.js +1 -3
  4. package/cjs/fluid/index.d.ts +5 -0
  5. package/cjs/fluid/index.js +36 -1
  6. package/cjs/helpers/aaveHelpers/index.js +3 -0
  7. package/cjs/helpers/aaveV4Helpers/index.js +1 -0
  8. package/cjs/helpers/compoundHelpers/index.js +2 -0
  9. package/cjs/helpers/curveUsdHelpers/index.js +2 -0
  10. package/cjs/helpers/fluidHelpers/index.js +1 -0
  11. package/cjs/helpers/liquityV2Helpers/index.js +1 -0
  12. package/cjs/helpers/llamaLendHelpers/index.js +2 -0
  13. package/cjs/helpers/makerHelpers/index.d.ts +1 -1
  14. package/cjs/helpers/makerHelpers/index.js +2 -2
  15. package/cjs/helpers/morphoBlueHelpers/index.js +2 -0
  16. package/cjs/helpers/morphoMidnightHelpers/index.js +2 -0
  17. package/cjs/helpers/sparkHelpers/index.js +1 -0
  18. package/cjs/liquity/index.js +8 -1
  19. package/cjs/maker/index.d.ts +7 -2
  20. package/cjs/maker/index.js +32 -12
  21. package/cjs/markets/index.d.ts +1 -0
  22. package/cjs/markets/index.js +3 -1
  23. package/cjs/markets/maker/index.d.ts +1 -0
  24. package/cjs/markets/maker/index.js +13 -0
  25. package/cjs/markets/spark/marketAssets.js +1 -1
  26. package/cjs/portfolio/index.d.ts +5 -1
  27. package/cjs/portfolio/index.js +287 -13
  28. package/cjs/types/aave.d.ts +2 -0
  29. package/cjs/types/aaveV4.d.ts +1 -0
  30. package/cjs/types/claiming.d.ts +1 -9
  31. package/cjs/types/claiming.js +0 -2
  32. package/cjs/types/compound.d.ts +2 -0
  33. package/cjs/types/fluid.d.ts +1 -0
  34. package/cjs/types/liquity.d.ts +1 -0
  35. package/cjs/types/liquityV2.d.ts +2 -0
  36. package/cjs/types/maker.d.ts +1 -0
  37. package/cjs/types/morphoBlue.d.ts +2 -0
  38. package/cjs/types/morphoMidnight.d.ts +1 -0
  39. package/cjs/types/portfolio.d.ts +26 -10
  40. package/cjs/types/spark.d.ts +2 -0
  41. package/esm/aaveV2/index.js +2 -0
  42. package/esm/claiming/index.d.ts +1 -2
  43. package/esm/claiming/index.js +1 -2
  44. package/esm/fluid/index.d.ts +5 -0
  45. package/esm/fluid/index.js +33 -0
  46. package/esm/helpers/aaveHelpers/index.js +3 -0
  47. package/esm/helpers/aaveV4Helpers/index.js +1 -0
  48. package/esm/helpers/compoundHelpers/index.js +2 -0
  49. package/esm/helpers/curveUsdHelpers/index.js +2 -0
  50. package/esm/helpers/fluidHelpers/index.js +1 -0
  51. package/esm/helpers/liquityV2Helpers/index.js +1 -0
  52. package/esm/helpers/llamaLendHelpers/index.js +2 -0
  53. package/esm/helpers/makerHelpers/index.d.ts +1 -1
  54. package/esm/helpers/makerHelpers/index.js +2 -2
  55. package/esm/helpers/morphoBlueHelpers/index.js +2 -0
  56. package/esm/helpers/morphoMidnightHelpers/index.js +2 -0
  57. package/esm/helpers/sparkHelpers/index.js +1 -0
  58. package/esm/liquity/index.js +8 -1
  59. package/esm/maker/index.d.ts +7 -2
  60. package/esm/maker/index.js +31 -13
  61. package/esm/markets/index.d.ts +1 -0
  62. package/esm/markets/index.js +1 -0
  63. package/esm/markets/maker/index.d.ts +1 -0
  64. package/esm/markets/maker/index.js +10 -0
  65. package/esm/markets/spark/marketAssets.js +1 -1
  66. package/esm/portfolio/index.d.ts +5 -1
  67. package/esm/portfolio/index.js +289 -16
  68. package/esm/types/aave.d.ts +2 -0
  69. package/esm/types/aaveV4.d.ts +1 -0
  70. package/esm/types/claiming.d.ts +1 -9
  71. package/esm/types/claiming.js +0 -2
  72. package/esm/types/compound.d.ts +2 -0
  73. package/esm/types/fluid.d.ts +1 -0
  74. package/esm/types/liquity.d.ts +1 -0
  75. package/esm/types/liquityV2.d.ts +2 -0
  76. package/esm/types/maker.d.ts +1 -0
  77. package/esm/types/morphoBlue.d.ts +2 -0
  78. package/esm/types/morphoMidnight.d.ts +1 -0
  79. package/esm/types/portfolio.d.ts +26 -10
  80. package/esm/types/spark.d.ts +2 -0
  81. package/package.json +1 -1
  82. package/src/aaveV2/index.ts +2 -0
  83. package/src/claiming/index.ts +0 -2
  84. package/src/fluid/index.ts +40 -0
  85. package/src/helpers/aaveHelpers/index.ts +3 -0
  86. package/src/helpers/aaveV4Helpers/index.ts +1 -0
  87. package/src/helpers/compoundHelpers/index.ts +2 -0
  88. package/src/helpers/curveUsdHelpers/index.ts +2 -0
  89. package/src/helpers/fluidHelpers/index.ts +1 -0
  90. package/src/helpers/liquityV2Helpers/index.ts +1 -0
  91. package/src/helpers/llamaLendHelpers/index.ts +2 -0
  92. package/src/helpers/makerHelpers/index.ts +2 -1
  93. package/src/helpers/morphoBlueHelpers/index.ts +2 -0
  94. package/src/helpers/morphoMidnightHelpers/index.ts +2 -0
  95. package/src/helpers/sparkHelpers/index.ts +1 -0
  96. package/src/liquity/index.ts +8 -1
  97. package/src/maker/index.ts +62 -29
  98. package/src/markets/index.ts +2 -1
  99. package/src/markets/maker/index.ts +10 -0
  100. package/src/markets/spark/marketAssets.ts +1 -1
  101. package/src/portfolio/index.ts +270 -14
  102. package/src/types/aave.ts +3 -0
  103. package/src/types/aaveV4.ts +1 -0
  104. package/src/types/claiming.ts +0 -10
  105. package/src/types/compound.ts +2 -0
  106. package/src/types/fluid.ts +1 -0
  107. package/src/types/liquity.ts +2 -0
  108. package/src/types/liquityV2.ts +2 -0
  109. package/src/types/maker.ts +2 -0
  110. package/src/types/morphoBlue.ts +2 -0
  111. package/src/types/morphoMidnight.ts +1 -0
  112. package/src/types/portfolio.ts +31 -12
  113. package/src/types/spark.ts +2 -0
  114. package/cjs/claiming/compV3.d.ts +0 -15
  115. package/cjs/claiming/compV3.js +0 -50
  116. package/esm/claiming/compV3.d.ts +0 -15
  117. package/esm/claiming/compV3.js +0 -46
  118. package/src/claiming/compV3.ts +0 -37
package/src/types/aave.ts CHANGED
@@ -143,6 +143,8 @@ export interface AavePositionData extends MMPositionData {
143
143
  collRatio: string,
144
144
  // Safety ratio as evaluated by automation bots (LTV-0 collateral credited at LLTV - 5%). Aave v3 only.
145
145
  safetyRatioWithLtvZeroFallback?: string,
146
+ // Normalised safety ratio (100 = liquidation on every protocol). Aave v3: the LTV-0 fallback ratio, Aave v2: `ratio`.
147
+ safetyRatio?: string,
146
148
  suppliedUsd: string,
147
149
  borrowedUsd: string,
148
150
  borrowLimitUsd: string,
@@ -177,6 +179,7 @@ export interface AaveV3AggregatedPositionData {
177
179
  collRatio: string,
178
180
  borrowLimitWithLtvZeroFallbackUsd: string,
179
181
  safetyRatioWithLtvZeroFallback: string,
182
+ safetyRatio: string,
180
183
  netApy: string,
181
184
  incentiveUsd: string,
182
185
  totalInterestUsd: string,
@@ -183,6 +183,7 @@ export interface AaveV4AggregatedPositionData {
183
183
  leftToBorrowUsd: string,
184
184
  ratio: string,
185
185
  collRatio: string,
186
+ safetyRatio: string,
186
187
  liqRatio: string,
187
188
  liqPercent: string,
188
189
  leveragedType: LeverageType,
@@ -7,8 +7,6 @@ export enum ClaimType {
7
7
  AAVE_MERIT_REWARDS = 'AAVE_MERIT_REWARDS',
8
8
  /** Rewards distributed through Merkl across supported protocols */
9
9
  MERKL_REWARDS = 'MERKL_REWARDS',
10
- /** Rewards from Compound V3 (only in COMP) */
11
- COMPOUND_V3_COMP = 'COMPOUND_V3_COMP',
12
10
  /** Rewards from Spark (wstETH only for now) */
13
11
  SPARK_REWARDS = 'SPARK_REWARDS',
14
12
  /** Rewards from King (prev LTR^2 - received for weETH holding) */
@@ -75,13 +73,6 @@ export type KingRewardsClaimableToken = _ClaimableTokenPartial & {
75
73
  };
76
74
  };
77
75
 
78
- export type CompoundV3CompClaimableToken = _ClaimableTokenPartial & {
79
- claimType: ClaimType.COMPOUND_V3_COMP,
80
- additionalClaimFields: {
81
- marketAddress: EthAddress;
82
- }
83
- };
84
-
85
76
  export enum SparkAirdropType {
86
77
  SPARK_IGNITION = 'spark-ignition',
87
78
  PRE_FARMING_AND_SOCIAL = 'pre-farming-and-social',
@@ -115,7 +106,6 @@ export type ClaimableToken =
115
106
  AaveRewardsClaimableToken
116
107
  | AaveMeritRewardsClaimableToken
117
108
  | MerklRewardsClaimableToken
118
- | CompoundV3CompClaimableToken
119
109
  | SparkRewardsClaimableToken
120
110
  | KingRewardsClaimableToken
121
111
  | SparkAirdropClaimableToken
@@ -112,6 +112,7 @@ export interface CompoundAggregatedPositionData {
112
112
  leftToBorrowUsd: string,
113
113
  ratio: string,
114
114
  collRatio: string,
115
+ safetyRatio: string,
115
116
  netApy: string,
116
117
  incentiveUsd: string,
117
118
  totalInterestUsd: string,
@@ -132,6 +133,7 @@ export interface CompoundAggregatedPositionData {
132
133
  export interface CompoundPositionData extends MMPositionData {
133
134
  ratio: string,
134
135
  minRatio: string,
136
+ safetyRatio?: string,
135
137
  suppliedUsd: string,
136
138
  borrowedUsd: string,
137
139
  borrowLimitUsd: string,
@@ -344,6 +344,7 @@ export interface FluidAggregatedVaultData {
344
344
  merklBorrowIncentives: IncentiveData[],
345
345
  ratio: string,
346
346
  collRatio: string,
347
+ safetyRatio: string,
347
348
  minRatio: string,
348
349
  totalInterestUsd: string,
349
350
  leveragedType?: LeverageType,
@@ -26,6 +26,8 @@ export interface LiquityTroveInfo {
26
26
  totalETH: string,
27
27
  totalLUSD: string,
28
28
  minCollateralRatio: number,
29
+ // Collateral ratio rebased so 100 sits on `minCollateralRatio` (normalised safety ratio).
30
+ safetyRatio: string,
29
31
  priceForRecovery: string,
30
32
  debtInFront: string,
31
33
  exposure: string,
@@ -104,6 +104,7 @@ export interface LiquityV2AggregatedTroveData {
104
104
  liquidationPrice: string,
105
105
  ratio: string,
106
106
  collRatio: string,
107
+ safetyRatio: string,
107
108
  exposure: string,
108
109
  }
109
110
 
@@ -112,6 +113,7 @@ export interface LiquityV2TroveData {
112
113
  troveId: string,
113
114
  ratio: string,
114
115
  collRatio: string,
116
+ safetyRatio?: string,
115
117
  liqRatio: string,
116
118
  borrowLimitRatio: string,
117
119
  interestRate: string,
@@ -47,6 +47,8 @@ export interface CdpData {
47
47
  debtAssetMarketPrice: string,
48
48
  liquidationPrice: string,
49
49
  ratio: string,
50
+ // Collateral ratio rebased so 100 sits on `liqPercent` (normalised safety ratio).
51
+ safetyRatio: string,
50
52
  liqRatio: string,
51
53
  liqPercent: number,
52
54
  assetPrice: string,
@@ -206,6 +206,7 @@ export interface MorphoBlueAggregatedPositionData {
206
206
  totalInterestUsd: string,
207
207
  ltv: string,
208
208
  ratio: string,
209
+ safetyRatio: string, // borrowLimitUsd / borrowedUsd as a percentage (100 = liquidation)
209
210
  leveragedType: LeverageType,
210
211
  leveragedAsset?: string,
211
212
  currentVolatilePairRatio?: string,
@@ -229,6 +230,7 @@ export interface MorphoBluePositionData {
229
230
  totalInterestUsd: string,
230
231
  ltv: string,
231
232
  ratio: string,
233
+ safetyRatio?: string,
232
234
  leveragedType: LeverageType,
233
235
  leveragedAsset?: string,
234
236
  currentVolatilePairRatio?: string,
@@ -190,6 +190,7 @@ export interface MorphoMidnightAggregatedPositionData {
190
190
  ltv: string,
191
191
  ratio: string, // health ratio as a percentage (from MidnightView.ratio, 1e18-scaled)
192
192
  healthRatio: string, // liquidationLimitUsd / borrowedUsd
193
+ safetyRatio: string, // borrowLimitUsd / borrowedUsd as a percentage (100 = liquidation)
193
194
  leveragedType: LeverageType,
194
195
  leveragedAsset?: string,
195
196
  currentVolatilePairRatio?: string,
@@ -1,16 +1,20 @@
1
- import { AaveV2PositionData, AaveV3PositionData, AaveVersions } from './aave';
2
- import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
1
+ import {
2
+ AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions,
3
+ } from './aave';
4
+ import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokesType } from './aaveV4';
3
5
  import { EthAddress } from './common';
4
- import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
5
- import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
6
- import { FluidVaultData } from './fluid';
6
+ import {
7
+ CompoundV2MarketsData, CompoundV2PositionData, CompoundV3MarketsData, CompoundV3PositionData, CompoundVersions,
8
+ } from './compound';
9
+ import { CrvUSDGlobalMarketData, CrvUSDUserData, CrvUSDVersions } from './curveUsd';
10
+ import { FluidMarketData, FluidVaultData } from './fluid';
7
11
  import { LiquityTroveInfo } from './liquity';
8
- import { LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
9
- import { LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
10
- import { CdpData } from './maker';
11
- import { MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
12
- import { MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
13
- import { SparkPositionData, SparkVersions } from './spark';
12
+ import { LiquityV2MarketData, LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
13
+ import { LlamaLendGlobalMarketData, LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
14
+ import { CdpData, IlkInfo } from './maker';
15
+ import { MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
16
+ import { MorphoMidnightMarketInfo, MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
17
+ import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
14
18
 
15
19
  export interface PortfolioProtocolData<T> {
16
20
  error: string,
@@ -62,4 +66,19 @@ export interface PortfolioPositionsDataForAddress {
62
66
 
63
67
  export interface PortfolioPositionsData {
64
68
  [key: EthAddress]: PortfolioPositionsDataForAddress;
65
- }
69
+ }
70
+ export interface PortfolioMarketsData {
71
+ morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
72
+ morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo>;
73
+ compoundV3MarketsData: Record<string, CompoundV3MarketsData>;
74
+ sparkMarketsData: Record<string, SparkMarketsData>;
75
+ aaveV3MarketsData: Record<string, AaveV3MarketData>;
76
+ aaveV2MarketsData: Record<string, AaveV2MarketData>;
77
+ compoundV2MarketsData: Record<string, CompoundV2MarketsData>;
78
+ crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData>;
79
+ llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData>;
80
+ liquityV2MarketsData: Record<string, LiquityV2MarketData>;
81
+ aaveV4SpokesData: Record<string, AaveV4SpokeData>;
82
+ fluidMarketsData: Record<string, FluidMarketData>;
83
+ makerMarketsData: Record<string, IlkInfo>;
84
+ }
@@ -99,6 +99,7 @@ export interface SparkAggregatedPositionData {
99
99
  leftToBorrowUsd: string,
100
100
  ratio: string,
101
101
  collRatio: string,
102
+ safetyRatio: string,
102
103
  netApy: string,
103
104
  incentiveUsd: string,
104
105
  totalInterestUsd: string,
@@ -119,6 +120,7 @@ export interface SparkPositionData extends MMPositionData {
119
120
  ratio: string,
120
121
  minRatio: string,
121
122
  collRatio: string,
123
+ safetyRatio?: string,
122
124
  suppliedUsd: string,
123
125
  borrowedUsd: string,
124
126
  borrowLimitUsd: string,
@@ -1,15 +0,0 @@
1
- import { Client } from 'viem';
2
- import { EthAddress, NetworkNumber } from '../types/common';
3
- import { ClaimType } from '../types/claiming';
4
- export declare const getCompoundV3Rewards: (provider: Client, network: NetworkNumber, user: EthAddress, market: any) => Promise<{
5
- symbol: string;
6
- underlyingSymbol: string;
7
- tokenAddress: `0x${string}`;
8
- amount: string;
9
- walletAddress: `0x${string}`;
10
- label: string;
11
- claimType: ClaimType;
12
- additionalClaimFields: {
13
- marketAddress: any;
14
- };
15
- }[]>;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getCompoundV3Rewards = void 0;
13
- const viem_1 = require("viem");
14
- const tokens_1 = require("@defisaver/tokens");
15
- const contracts_1 = require("../contracts");
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
- const isMarketWithoutRewardsConfig = (err) => {
22
- var _a;
23
- if (!(err instanceof viem_1.BaseError))
24
- return false;
25
- const revert = err.walk((e) => e instanceof viem_1.ContractFunctionRevertedError);
26
- return revert instanceof viem_1.ContractFunctionRevertedError && !!((_a = revert.raw) === null || _a === void 0 ? void 0 : _a.startsWith(NOT_SUPPORTED_ERROR_SIG));
27
- };
28
- const getCompoundV3Rewards = (provider, network, user, market) => __awaiter(void 0, void 0, void 0, function* () {
29
- const compV3View = (0, contracts_1.CompV3ViewContractViem)(provider, network);
30
- const rewards = yield compV3View.read.getRewardsOwed([market, user]).catch((err) => {
31
- if (isMarketWithoutRewardsConfig(err))
32
- return null;
33
- throw err;
34
- });
35
- if (!rewards || rewards.owed.toString() === '0' || (0, tokens_1.getAssetInfoByAddress)(rewards.token, network).symbol !== 'COMP')
36
- return [];
37
- return [{
38
- symbol: 'COMP',
39
- underlyingSymbol: 'COMP',
40
- tokenAddress: rewards.token,
41
- amount: (0, tokens_1.assetAmountInEth)(rewards.owed.toString() || 0, 'COMP'),
42
- walletAddress: user,
43
- label: 'Compound V3',
44
- claimType: claiming_1.ClaimType.COMPOUND_V3_COMP,
45
- additionalClaimFields: {
46
- marketAddress: market,
47
- },
48
- }];
49
- });
50
- exports.getCompoundV3Rewards = getCompoundV3Rewards;
@@ -1,15 +0,0 @@
1
- import { Client } from 'viem';
2
- import { EthAddress, NetworkNumber } from '../types/common';
3
- import { ClaimType } from '../types/claiming';
4
- export declare const getCompoundV3Rewards: (provider: Client, network: NetworkNumber, user: EthAddress, market: any) => Promise<{
5
- symbol: string;
6
- underlyingSymbol: string;
7
- tokenAddress: `0x${string}`;
8
- amount: string;
9
- walletAddress: `0x${string}`;
10
- label: string;
11
- claimType: ClaimType;
12
- additionalClaimFields: {
13
- marketAddress: any;
14
- };
15
- }[]>;
@@ -1,46 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { BaseError, ContractFunctionRevertedError } from 'viem';
11
- import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
12
- import { CompV3ViewContractViem } from '../contracts';
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
- const isMarketWithoutRewardsConfig = (err) => {
19
- var _a;
20
- if (!(err instanceof BaseError))
21
- return false;
22
- const revert = err.walk((e) => e instanceof ContractFunctionRevertedError);
23
- return revert instanceof ContractFunctionRevertedError && !!((_a = revert.raw) === null || _a === void 0 ? void 0 : _a.startsWith(NOT_SUPPORTED_ERROR_SIG));
24
- };
25
- export const getCompoundV3Rewards = (provider, network, user, market) => __awaiter(void 0, void 0, void 0, function* () {
26
- const compV3View = CompV3ViewContractViem(provider, network);
27
- const rewards = yield compV3View.read.getRewardsOwed([market, user]).catch((err) => {
28
- if (isMarketWithoutRewardsConfig(err))
29
- return null;
30
- throw err;
31
- });
32
- if (!rewards || rewards.owed.toString() === '0' || getAssetInfoByAddress(rewards.token, network).symbol !== 'COMP')
33
- return [];
34
- return [{
35
- symbol: 'COMP',
36
- underlyingSymbol: 'COMP',
37
- tokenAddress: rewards.token,
38
- amount: assetAmountInEth(rewards.owed.toString() || 0, 'COMP'),
39
- walletAddress: user,
40
- label: 'Compound V3',
41
- claimType: ClaimType.COMPOUND_V3_COMP,
42
- additionalClaimFields: {
43
- marketAddress: market,
44
- },
45
- }];
46
- });
@@ -1,37 +0,0 @@
1
- import { BaseError, Client, ContractFunctionRevertedError } from 'viem';
2
- import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
3
- import { EthAddress, NetworkNumber } from '../types/common';
4
- import { CompV3ViewContractViem } from '../contracts';
5
- import { ClaimType } from '../types/claiming';
6
-
7
- // `CometRewards.NotSupported(address)`. CometRewards reverts with it for any Comet that has no
8
- // `rewardConfig` set - such a market never accrues COMP, so there is nothing to claim.
9
- // Not decodable by name, since the error lives in CometRewards' ABI and we call through CompV3View.
10
- const NOT_SUPPORTED_ERROR_SIG = '0x9c58e3b6';
11
-
12
- const isMarketWithoutRewardsConfig = (err: unknown) => {
13
- if (!(err instanceof BaseError)) return false;
14
- const revert = err.walk((e) => e instanceof ContractFunctionRevertedError);
15
- return revert instanceof ContractFunctionRevertedError && !!revert.raw?.startsWith(NOT_SUPPORTED_ERROR_SIG);
16
- };
17
-
18
- export const getCompoundV3Rewards = async (provider: Client, network: NetworkNumber, user: EthAddress, market: any) => {
19
- const compV3View = CompV3ViewContractViem(provider, network);
20
- const rewards = await compV3View.read.getRewardsOwed([market, user]).catch((err) => {
21
- if (isMarketWithoutRewardsConfig(err)) return null;
22
- throw err;
23
- });
24
- if (!rewards || rewards.owed.toString() === '0' || getAssetInfoByAddress(rewards.token, network).symbol !== 'COMP') return [];
25
- return [{
26
- symbol: 'COMP',
27
- underlyingSymbol: 'COMP',
28
- tokenAddress: rewards.token,
29
- amount: assetAmountInEth(rewards.owed.toString() || 0, 'COMP'),
30
- walletAddress: user,
31
- label: 'Compound V3',
32
- claimType: ClaimType.COMPOUND_V3_COMP,
33
- additionalClaimFields: {
34
- marketAddress: market,
35
- },
36
- }];
37
- };