@defisaver/positions-sdk 2.1.49-aave-v4-dev-1-dev → 2.1.49-aave-v4-dev-2

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 (116) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +64 -64
  4. package/cjs/helpers/aaveV4Helpers/index.d.ts +4 -0
  5. package/cjs/helpers/aaveV4Helpers/index.js +54 -2
  6. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  7. package/cjs/savings/morphoVaults/index.js +17 -17
  8. package/esm/helpers/aaveV4Helpers/index.d.ts +4 -0
  9. package/esm/helpers/aaveV4Helpers/index.js +53 -2
  10. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  11. package/esm/savings/morphoVaults/index.js +17 -17
  12. package/package.json +48 -48
  13. package/src/aaveV2/index.ts +240 -240
  14. package/src/aaveV3/index.ts +635 -635
  15. package/src/aaveV3/merit.ts +97 -97
  16. package/src/aaveV3/merkl.ts +74 -74
  17. package/src/aaveV4/index.ts +168 -168
  18. package/src/claiming/aaveV3.ts +154 -154
  19. package/src/claiming/compV3.ts +22 -22
  20. package/src/claiming/ethena.ts +61 -61
  21. package/src/claiming/index.ts +12 -12
  22. package/src/claiming/king.ts +66 -66
  23. package/src/claiming/morphoBlue.ts +118 -118
  24. package/src/claiming/spark.ts +225 -225
  25. package/src/compoundV2/index.ts +244 -244
  26. package/src/compoundV3/index.ts +274 -274
  27. package/src/config/contracts.ts +1328 -1328
  28. package/src/constants/index.ts +10 -10
  29. package/src/contracts.ts +173 -173
  30. package/src/curveUsd/index.ts +254 -254
  31. package/src/eulerV2/index.ts +324 -324
  32. package/src/exchange/index.ts +25 -25
  33. package/src/fluid/index.ts +1800 -1800
  34. package/src/helpers/aaveHelpers/index.ts +191 -191
  35. package/src/helpers/aaveV4Helpers/index.ts +120 -68
  36. package/src/helpers/compoundHelpers/index.ts +283 -283
  37. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  38. package/src/helpers/eulerHelpers/index.ts +222 -222
  39. package/src/helpers/fluidHelpers/index.ts +326 -326
  40. package/src/helpers/index.ts +11 -11
  41. package/src/helpers/liquityV2Helpers/index.ts +82 -82
  42. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  43. package/src/helpers/makerHelpers/index.ts +52 -52
  44. package/src/helpers/morphoBlueHelpers/index.ts +396 -396
  45. package/src/helpers/sparkHelpers/index.ts +158 -158
  46. package/src/index.ts +51 -51
  47. package/src/liquity/index.ts +159 -159
  48. package/src/liquityV2/index.ts +703 -703
  49. package/src/llamaLend/index.ts +305 -305
  50. package/src/maker/index.ts +223 -223
  51. package/src/markets/aave/index.ts +118 -118
  52. package/src/markets/aave/marketAssets.ts +54 -54
  53. package/src/markets/aaveV4/index.ts +18 -18
  54. package/src/markets/compound/index.ts +243 -243
  55. package/src/markets/compound/marketsAssets.ts +97 -97
  56. package/src/markets/curveUsd/index.ts +69 -69
  57. package/src/markets/euler/index.ts +26 -26
  58. package/src/markets/fluid/index.ts +2900 -2900
  59. package/src/markets/index.ts +25 -25
  60. package/src/markets/liquityV2/index.ts +102 -102
  61. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  62. package/src/markets/llamaLend/index.ts +235 -235
  63. package/src/markets/morphoBlue/index.ts +971 -971
  64. package/src/markets/spark/index.ts +29 -29
  65. package/src/markets/spark/marketAssets.ts +12 -12
  66. package/src/moneymarket/moneymarketCommonService.ts +85 -85
  67. package/src/morphoBlue/index.ts +274 -274
  68. package/src/portfolio/index.ts +618 -618
  69. package/src/savings/index.ts +95 -95
  70. package/src/savings/makerDsr/index.ts +53 -53
  71. package/src/savings/makerDsr/options.ts +9 -9
  72. package/src/savings/morphoVaults/index.ts +80 -80
  73. package/src/savings/morphoVaults/options.ts +193 -193
  74. package/src/savings/skyOptions/index.ts +95 -95
  75. package/src/savings/skyOptions/options.ts +10 -10
  76. package/src/savings/sparkSavingsVaults/index.ts +60 -60
  77. package/src/savings/sparkSavingsVaults/options.ts +35 -35
  78. package/src/savings/yearnV3Vaults/index.ts +61 -61
  79. package/src/savings/yearnV3Vaults/options.ts +55 -55
  80. package/src/savings/yearnVaults/index.ts +73 -73
  81. package/src/savings/yearnVaults/options.ts +32 -32
  82. package/src/services/priceService.ts +278 -278
  83. package/src/services/utils.ts +115 -115
  84. package/src/services/viem.ts +34 -34
  85. package/src/setup.ts +8 -8
  86. package/src/spark/index.ts +459 -459
  87. package/src/staking/eligibility.ts +53 -53
  88. package/src/staking/index.ts +1 -1
  89. package/src/staking/staking.ts +192 -192
  90. package/src/types/aave.ts +198 -198
  91. package/src/types/aaveV4.ts +142 -142
  92. package/src/types/claiming.ts +114 -114
  93. package/src/types/common.ts +107 -107
  94. package/src/types/compound.ts +144 -144
  95. package/src/types/curveUsd.ts +123 -123
  96. package/src/types/euler.ts +175 -175
  97. package/src/types/fluid.ts +483 -483
  98. package/src/types/index.ts +15 -15
  99. package/src/types/liquity.ts +30 -30
  100. package/src/types/liquityV2.ts +126 -126
  101. package/src/types/llamaLend.ts +159 -159
  102. package/src/types/maker.ts +63 -63
  103. package/src/types/merit.ts +1 -1
  104. package/src/types/merkl.ts +70 -70
  105. package/src/types/morphoBlue.ts +200 -200
  106. package/src/types/portfolio.ts +64 -64
  107. package/src/types/savings/index.ts +23 -23
  108. package/src/types/savings/makerDsr.ts +13 -13
  109. package/src/types/savings/morphoVaults.ts +32 -32
  110. package/src/types/savings/sky.ts +14 -14
  111. package/src/types/savings/sparkSavingsVaults.ts +15 -15
  112. package/src/types/savings/yearnV3Vaults.ts +17 -17
  113. package/src/types/savings/yearnVaults.ts +14 -14
  114. package/src/types/spark.ts +134 -134
  115. package/src/umbrella/index.ts +69 -69
  116. package/src/umbrella/umbrellaUtils.ts +29 -29
@@ -1,618 +1,618 @@
1
- import Dec from 'decimal.js';
2
- import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
3
- import {
4
- AaveMarkets,
5
- AaveV4Spokes,
6
- CompoundMarkets,
7
- CrvUsdMarkets,
8
- EulerV2Markets,
9
- LiquityV2Markets,
10
- LlamaLendMarkets,
11
- MorphoBlueMarkets,
12
- SparkMarkets,
13
- } from '../markets';
14
- import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } from '../morphoBlue';
15
- import {
16
- AaveV2MarketData,
17
- AaveV3MarketData,
18
- AaveV4SpokeData,
19
- AaveVersions,
20
- CdpInfo,
21
- CompoundV2MarketsData,
22
- CompoundV3MarketsData,
23
- CompoundVersions,
24
- CrvUSDGlobalMarketData,
25
- EulerV2FullMarketData,
26
- LiquityV2MarketData,
27
- LlamaLendGlobalMarketData,
28
- MorphoBlueMarketInfo,
29
- PortfolioPositionsData,
30
- SparkMarketsData,
31
- } from '../types';
32
- import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
33
- import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
34
- import { _getEulerV2AccountData, _getEulerV2MarketsData } from '../eulerV2';
35
- import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
36
- import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
37
- import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
38
- import { ZERO_ADDRESS } from '../constants';
39
- import { _getMakerCdpData, _getUserCdps } from '../maker';
40
- import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
41
- import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
42
- import { getViemProvider } from '../services/viem';
43
- import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
44
- import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
45
- import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
46
- import { getEulerV2SubAccounts } from '../helpers/eulerHelpers';
47
- import { getUmbrellaData } from '../umbrella';
48
- import { getMeritUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
49
- import { getCompoundV3Rewards } from '../claiming/compV3';
50
- import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
51
- import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
52
- import { getKingRewards } from '../claiming/king';
53
- import { fetchEthenaAirdropRewards } from '../claiming/ethena';
54
- import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
55
-
56
- export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], summerFiAddresses: EthAddress[]): Promise<{
57
- positions: PortfolioPositionsData;
58
- stakingPositions: any;
59
- rewardsData: any;
60
- markets: any;
61
- }> {
62
- const isMainnet = network === NetworkNumber.Eth;
63
- const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
64
- const isMorphoRewardsSupported = [NetworkNumber.Eth, NetworkNumber.Base].includes(network);
65
-
66
- const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
67
- const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
68
- const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
69
- const eulerV2Markets = Object.values(EulerV2Markets(network)).filter((market) => market.chainIds.includes(network));
70
- const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
71
- const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
72
- const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
73
- const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
74
- const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
75
- const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
76
- const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
77
- const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
78
-
79
- const client = getViemProvider(provider, network, {
80
- batch: {
81
- multicall: {
82
- batchSize: 2500000,
83
- },
84
- },
85
- });
86
- const defaultClient = getViemProvider(defaultProvider, network, {
87
- batch: {
88
- multicall: {
89
- batchSize: 2500000,
90
- },
91
- },
92
- });
93
-
94
- const morphoMarketsData: Record<string, MorphoBlueMarketInfo> = {};
95
- const compoundV3MarketsData: Record<string, CompoundV3MarketsData> = {};
96
- const sparkMarketsData: Record<string, SparkMarketsData> = {};
97
- const eulerV2MarketsData: Record<string, EulerV2FullMarketData> = {};
98
- const aaveV3MarketsData: Record<string, AaveV3MarketData> = {};
99
- const makerCdps: Record<string, CdpInfo[]> = {};
100
- const aaveV2MarketsData: Record<string, AaveV2MarketData> = {};
101
- const compoundV2MarketsData: Record<string, CompoundV2MarketsData> = {};
102
- const crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData> = {};
103
- const llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData> = {};
104
- const liquityV2MarketsData: Record<string, LiquityV2MarketData> = {};
105
- const aaveV4SpokesData: Record<string, AaveV4SpokeData> = {};
106
-
107
- const markets = {
108
- morphoMarketsData,
109
- compoundV3MarketsData,
110
- sparkMarketsData,
111
- eulerV2MarketsData,
112
- aaveV3MarketsData,
113
- aaveV2MarketsData,
114
- compoundV2MarketsData,
115
- crvUsdMarketsData,
116
- llamaLendMarketsData,
117
- liquityV2MarketsData,
118
- aaveV4SpokesData,
119
- };
120
-
121
- const positions: PortfolioPositionsData = {};
122
- const stakingPositions: any = {};
123
- const rewardsData: any = {};
124
- const allAddresses = [...addresses, ...summerFiAddresses];
125
-
126
- for (const address of allAddresses) {
127
- positions[address.toLowerCase() as EthAddress] = {
128
- aaveV3: {},
129
- aaveV4: {},
130
- morphoBlue: {},
131
- compoundV3: {},
132
- spark: {},
133
- eulerV2: {},
134
- maker: {},
135
- aaveV2: {},
136
- compoundV2: {},
137
- liquity: {},
138
- crvUsd: {},
139
- llamaLend: {},
140
- fluid: {
141
- error: '',
142
- data: {},
143
- },
144
- };
145
- }
146
-
147
- // TODO: check default values, probably needed when fetching portfolio on unsupported networks
148
- for (const address of addresses) {
149
- stakingPositions[address.toLowerCase() as EthAddress] = {
150
- aaveV3: {},
151
- morphoBlue: {},
152
- compoundV3: {},
153
- spark: {},
154
- aaveV2: {},
155
- compoundV2: {},
156
- liquity: {},
157
- liquityV2: {},
158
- fluid: {
159
- error: '',
160
- data: {},
161
- },
162
- };
163
-
164
- rewardsData[address.toLowerCase() as EthAddress] = {
165
- aaveV3merit: {},
166
- aaveV3: {},
167
- compV3: {},
168
- spark: {},
169
- spk: {},
170
- king: {},
171
- morpho: {},
172
- ethena: {},
173
- };
174
- }
175
-
176
- await Promise.allSettled([
177
- // === MARKET DATA (needs to be fetched first) ===
178
- ...morphoMarkets.map(async (market) => {
179
- const marketData = await _getMorphoBlueMarketData(client, network, market);
180
- morphoMarketsData[market.value] = marketData;
181
- }),
182
- ...compoundV3Markets.map(async (market) => {
183
- const marketData = await _getCompoundV3MarketsData(client, network, market, defaultClient);
184
- compoundV3MarketsData[market.value] = marketData;
185
- }),
186
- ...sparkMarkets.map(async (market) => {
187
- const marketData = await _getSparkMarketsData(client, network, market);
188
- sparkMarketsData[market.value] = marketData;
189
- }),
190
- ...eulerV2Markets.map(async (market) => {
191
- const marketData = await _getEulerV2MarketsData(client, network, market);
192
- eulerV2MarketsData[market.value] = marketData;
193
- }),
194
- ...aaveV3Markets.map(async (market) => {
195
- const marketData = await _getAaveV3MarketData(client, network, market);
196
- aaveV3MarketsData[market.value] = marketData;
197
- }),
198
- ...aaveV4Spokes.map(async (spoke) => {
199
- const spokeData = await _getAaveV4SpokeData(client, network, spoke);
200
- aaveV4SpokesData[spoke.value] = spokeData;
201
- }),
202
- ...aaveV2Markets.map(async (market) => {
203
- const marketData = await _getAaveV2MarketsData(client, network, market);
204
- aaveV2MarketsData[market.value] = marketData;
205
- }),
206
- ...compoundV2Markets.map(async (market) => {
207
- const marketData = await _getCompoundV2MarketsData(client, network);
208
- compoundV2MarketsData[market.value] = marketData;
209
- }),
210
- ...crvUsdMarkets.map(async (market) => {
211
- const marketData = await _getCurveUsdGlobalData(client, network, market);
212
- crvUsdMarketsData[market.value] = marketData;
213
- }),
214
- ...llamaLendMarkets.map(async (market) => {
215
- const marketData = await _getLlamaLendGlobalData(client, network, market);
216
- llamaLendMarketsData[market.value] = marketData;
217
- }),
218
- ...liquityV2Markets.map(async (market) => {
219
- const marketData = await _getLiquityV2MarketData(client, network, market);
220
- liquityV2MarketsData[market.value] = marketData;
221
- }),
222
-
223
- // === INDEPENDENT USER DATA (doesn't depend on market data) ===
224
- ...addresses.map(async (address) => {
225
- if (!isMainnet) return; // Maker CDPs are only available on mainnet
226
- const makerCdp = await _getUserCdps(client, network, address);
227
- makerCdps[address.toLowerCase() as EthAddress] = makerCdp;
228
- }),
229
- ...addresses.map(async (address) => {
230
- try {
231
- if (!isFluidSupported) return; // Fluid is not available on Optimism
232
- const userPositions = (await _getUserPositionsPortfolio(client, network, address));
233
- for (const position of userPositions) {
234
- if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
235
- positions[address.toLowerCase() as EthAddress].fluid.data[position.userData.nftId] = position.userData;
236
- }
237
- }
238
- } catch (error) {
239
- console.error(`Error fetching Fluid positions for address ${address}:`, error);
240
- positions[address.toLowerCase() as EthAddress].fluid = {
241
- error: `Error fetching Fluid positions for address ${address}`,
242
- data: {},
243
- };
244
- }
245
- }),
246
-
247
- // === STAKING DATA (independent of market data) ===
248
- ...addresses.map(async (address) => {
249
- try {
250
- if (!isFluidSupported) return;
251
- stakingPositions[address.toLowerCase()].fluid = await _getAllUserEarnPositionsWithFTokens(client, network, address);
252
- } catch (error) {
253
- console.error(`Error fetching Fluid lend data for address ${address}:`, error);
254
- stakingPositions[address.toLowerCase()].fluid = { error: `Error fetching Fluid lend data for address ${address}`, data: null };
255
- }
256
- }),
257
- ...addresses.map(async (address) => {
258
- try {
259
- if (!isMainnet) return;
260
- stakingPositions[address.toLowerCase()].liquity = await getLiquityStakingData(client, network, address);
261
- } catch (error) {
262
- console.error(`Error fetching Liquity staking data for address ${address}:`, error);
263
- stakingPositions[address.toLowerCase()].liquity = { error: `Error fetching Liquity staking data for address ${address}`, data: null };
264
- }
265
- }),
266
- ...addresses.map(async (address) => {
267
- try {
268
- if (!isMainnet) return;
269
- stakingPositions[address.toLowerCase()].aaveV3 = await getStakeAaveData(client, network, address);
270
- } catch (error) {
271
- console.error(`Error fetching Aave V3 staking data for address ${address}:`, error);
272
- stakingPositions[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 staking data for address ${address}`, data: null };
273
- }
274
- }),
275
- ...addresses.map(async (address) => {
276
- try {
277
- if (!isMainnet) return;
278
- stakingPositions[address.toLowerCase()].umbrella = await getUmbrellaData(client, network, address);
279
- } catch (error) {
280
- console.error(`Error fetching Umbrella staking data for address ${address}:`, error);
281
- stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
282
- }
283
- }),
284
- // Liquity V2 staking
285
- ...liquityV2MarketsStaking.map(market => addresses.map(async (address) => {
286
- try {
287
- if (!isMainnet) {
288
- stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
289
- return;
290
- }
291
- const liquityV2StakingData = await getLiquityV2Staking(client, network, market.value, address);
292
- stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: liquityV2StakingData };
293
- } catch (error) {
294
- console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
295
- stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
296
- }
297
- })).flat(),
298
-
299
- // === REWARDS DATA (independent of market data) ===
300
- // Batch King rewards
301
- (async () => {
302
- try {
303
- if (!isMainnet) {
304
- for (const address of addresses) {
305
- rewardsData[address.toLowerCase()].king = { error: '', data: [] };
306
- }
307
- return;
308
- }
309
- const kingRewards = await getKingRewards(client, network, addresses);
310
- for (const address of addresses) {
311
- const lowerAddress = address.toLowerCase() as EthAddress;
312
- rewardsData[lowerAddress].king = {
313
- error: '',
314
- data: kingRewards[lowerAddress] || [],
315
- };
316
- }
317
- } catch (error) {
318
- console.error('Error fetching King rewards data in batch:', error);
319
- for (const address of addresses) {
320
- rewardsData[address.toLowerCase() as EthAddress].king = {
321
- error: 'Error fetching King rewards data in batch',
322
- data: null,
323
- };
324
- }
325
- }
326
- })(),
327
- ...sparkMarkets.map((market) => addresses.map(async address => {
328
- try {
329
- if (!isMainnet) {
330
- rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: [] };
331
- return;
332
- }
333
- const sparkData = await fetchSparkRewards(client, network, address, market.providerAddress);
334
- rewardsData[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: sparkData };
335
- } catch (error) {
336
- console.error(`Error fetching Spark rewards data for address ${address}, market ${market.value}:`, error);
337
- rewardsData[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark rewards data for address ${address}`, data: null };
338
- }
339
- })).flat(),
340
- // CompV3 rewards
341
- ...compoundV3Markets.map(market => addresses.map(async (address) => {
342
- try {
343
- const compV3Rewards = await getCompoundV3Rewards(client, network, address, market.baseMarketAddress);
344
- rewardsData[address.toLowerCase() as EthAddress].compV3[market.value] = { error: '', data: compV3Rewards };
345
- } catch (error) {
346
- console.error(`Error fetching Compound V3 rewards data for address ${address}:`, error);
347
- rewardsData[address.toLowerCase() as EthAddress].compV3[market.value] = { error: `Error fetching Compound V3 rewards data for address ${address}`, data: null };
348
- }
349
- })).flat(),
350
- ...addresses.map(async (address) => {
351
- try {
352
- const aaveMeritData = await getMeritUnclaimedRewards(address, network);
353
- rewardsData[address.toLowerCase() as EthAddress].aaveV3merit = { error: '', data: aaveMeritData };
354
- } catch (error) {
355
- console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
356
- rewardsData[address.toLowerCase() as EthAddress].aaveV3merit = { error: `Error fetching Aave V3 Merit rewards data for address ${address}`, data: null };
357
- }
358
- }),
359
- ...aaveV3Markets.map(market => addresses.map(async (address) => {
360
- try {
361
- const aaveData = await getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress);
362
- rewardsData[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: aaveData };
363
- } catch (error) {
364
- console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
365
- rewardsData[address.toLowerCase() as EthAddress].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
366
- }
367
- })).flat(),
368
- // Batch Morpho Blue rewards
369
- (async () => {
370
- if (!isMorphoRewardsSupported) return;
371
- try {
372
- const morphoRewards = await fetchMorphoBlueRewards(client, network, addresses);
373
- for (const address of addresses) {
374
- const lowerAddress = address.toLowerCase() as EthAddress;
375
- rewardsData[lowerAddress].morpho = {
376
- error: '',
377
- data: morphoRewards[lowerAddress] || [],
378
- };
379
- }
380
- } catch (error) {
381
- console.error('Error fetching Morpho Blue rewards data in batch:', error);
382
- for (const address of addresses) {
383
- rewardsData[address.toLowerCase() as EthAddress].morpho = {
384
- error: 'Error fetching Morpho Blue rewards data in batch',
385
- data: null,
386
- };
387
- }
388
- }
389
- })(),
390
- // Batch Spark Airdrop rewards
391
- (async () => {
392
- try {
393
- if (!isMainnet) {
394
- for (const address of addresses) {
395
- rewardsData[address.toLowerCase()].spk = { error: '', data: [] };
396
- }
397
- return;
398
- }
399
-
400
- const sparkAirdropRewards = await fetchSparkAirdropRewards(client, network, addresses);
401
- for (const address of addresses) {
402
- const lowerAddress = address.toLowerCase() as EthAddress;
403
- rewardsData[lowerAddress].spk = {
404
- error: '',
405
- data: sparkAirdropRewards[lowerAddress] || [],
406
- };
407
- }
408
- } catch (error) {
409
- console.error('Error fetching Spark Airdrop rewards data in batch:', error);
410
- for (const address of addresses) {
411
- rewardsData[address.toLowerCase() as EthAddress].spk = {
412
- error: 'Error fetching Spark Airdrop rewards data in batch',
413
- data: null,
414
- };
415
- }
416
- }
417
- })(),
418
- (async () => {
419
- try {
420
- if (!isMainnet) {
421
- return;
422
- }
423
-
424
- const ethenaAirdropRewards = await fetchEthenaAirdropRewards(addresses);
425
- for (const address of addresses) {
426
- const lowerAddress = address.toLowerCase() as EthAddress;
427
- rewardsData[lowerAddress].ethena = {
428
- error: '',
429
- data: ethenaAirdropRewards[lowerAddress] || [],
430
- };
431
- }
432
- } catch (error) {
433
- console.error('Error fetching Ethena Airdrop rewards data:', error);
434
- for (const address of addresses) {
435
- rewardsData[address.toLowerCase() as EthAddress].ethena = {
436
- error: 'Error fetching Ethena Airdrop rewards data in batch',
437
- data: null,
438
- };
439
- }
440
- }
441
- })(),
442
- ]);
443
-
444
-
445
- await Promise.all([
446
- ...aaveV3Markets.map((market) => allAddresses.map(async (address) => {
447
- try {
448
- const accData = await _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...aaveV3MarketsData[market.value] });
449
- if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: accData };
450
- } catch (error) {
451
- console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
452
- positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
453
- }
454
- })).flat(),
455
- ...aaveV4Spokes.map((spoke) => allAddresses.map(async (address) => {
456
- try {
457
- const accData = await _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
458
- if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
459
- } catch (error) {
460
- console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
461
- positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
462
- }
463
- })).flat(),
464
- ...morphoMarkets.map((market) => addresses.map(async (address) => {
465
- try {
466
- const [accDataPromise, earnDataPromise] = await Promise.allSettled([
467
- _getMorphoBlueAccountData(client, network, address, market, morphoMarketsData[market.value]),
468
- getMorphoEarn(client, network, address, market, morphoMarketsData[market.value]),
469
- ]);
470
- if (accDataPromise.status === 'rejected') {
471
- console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, accDataPromise.reason);
472
- positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
473
- }
474
- if (earnDataPromise.status === 'rejected') {
475
- console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, earnDataPromise.reason);
476
- positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
477
- }
478
- if (accDataPromise.status !== 'rejected') {
479
- const accData = accDataPromise.value;
480
- if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: '', data: accData };
481
- }
482
- if (earnDataPromise.status !== 'rejected') {
483
- const earnData = earnDataPromise.value;
484
- if (earnData && new Dec(earnData.amount).gt(0)) {
485
- stakingPositions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = {
486
- error: '',
487
- data: earnData,
488
- };
489
- }
490
- }
491
- } catch (error) {
492
- console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
493
- positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
494
- }
495
- })).flat(),
496
- ...compoundV3Markets.map((market) => addresses.map(async (address) => {
497
- try {
498
- const accData = await _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: compoundV3MarketsData[market.value].assetsData });
499
- if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: '', data: accData };
500
- } catch (error) {
501
- console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
502
- positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
503
- }
504
- })).flat(),
505
- ...sparkMarkets.map((market) => allAddresses.map(async (address) => {
506
- try {
507
- const accData = await _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: sparkMarketsData[market.value].assetsData, eModeCategoriesData: sparkMarketsData[market.value].eModeCategoriesData });
508
- if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: accData };
509
- } catch (error) {
510
- console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
511
- positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
512
- }
513
- })).flat(),
514
- ...eulerV2Markets.map((market) => addresses.map((address) => {
515
- const eulerV2SubAccounts = getEulerV2SubAccounts(address);
516
- const eulerV2Addresses = [address, ...eulerV2SubAccounts];
517
- return Promise.all(eulerV2Addresses.map(async (eulerAddress) => {
518
- try {
519
- const accData = await _getEulerV2AccountData(client, network, eulerAddress, eulerAddress, { selectedMarket: market, ...eulerV2MarketsData[market.value] });
520
- if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
521
- if (!positions[address.toLowerCase() as EthAddress].eulerV2[market.value]) {
522
- positions[address.toLowerCase() as EthAddress].eulerV2[market.value] = {};
523
- }
524
- positions[address.toLowerCase() as EthAddress].eulerV2[market.value]![eulerAddress.toLowerCase() as EthAddress] = { error: '', data: accData };
525
- }
526
- } catch (error) {
527
- console.error(`Error fetching EulerV2 account data for address ${eulerAddress} on market ${market.value}:`, error);
528
- if (!positions[address.toLowerCase() as EthAddress].eulerV2[market.value]) {
529
- positions[address.toLowerCase() as EthAddress].eulerV2[market.value] = {};
530
- }
531
- positions[address.toLowerCase() as EthAddress].eulerV2[market.value]![eulerAddress.toLowerCase() as EthAddress] = { error: `Error fetching EulerV2 account data for address ${eulerAddress} on market ${market.value}`, data: null };
532
- }
533
- }));
534
- }).flat()).flat(),
535
- ...addresses.map(async (address) => makerCdps[address.toLowerCase() as EthAddress]?.map(async (cdpInfo) => {
536
- try {
537
- const cdpData = await _getMakerCdpData(client, network, cdpInfo);
538
- if (cdpData) {
539
- positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: '', data: cdpData };
540
- }
541
- } catch (error) {
542
- console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
543
- positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
544
- }
545
- })).flat(),
546
- ...aaveV2Markets.map((market) => addresses.map(async (address) => {
547
- try {
548
- const accData = await _getAaveV2AccountData(client, network, address, aaveV2MarketsData[market.value].assetsData, market);
549
- if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: '', data: accData };
550
- } catch (error) {
551
- console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
552
- positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
553
- }
554
- })).flat(),
555
- ...compoundV2Markets.map((market) => addresses.map(async (address) => {
556
- try {
557
- const accData = await _getCompoundV2AccountData(client, network, address, compoundV2MarketsData[market.value].assetsData);
558
- if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: '', data: accData };
559
- } catch (error) {
560
- console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
561
- positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
562
- }
563
- })).flat(),
564
- ...addresses.map(async (address) => {
565
- try {
566
- if (!isMainnet) return; // Liquity trove info is only available on mainnet
567
- const troveInfo = await _getLiquityTroveInfo(client, network, address);
568
- if (new Dec(troveInfo.collateral).gt(0)) positions[address.toLowerCase() as EthAddress].liquity = { error: '', data: troveInfo };
569
- } catch (error) {
570
- console.error(`Error fetching Liquity trove info for address ${address}:`, error);
571
- positions[address.toLowerCase() as EthAddress].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
572
- }
573
- }),
574
- ...crvUsdMarkets.map((market) => addresses.map(async (address) => {
575
- try {
576
- const accData = await _getCurveUsdUserData(client, network, address, market, crvUsdMarketsData[market.value].activeBand);
577
- if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
578
- positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: '', data: { ...accData, borrowRate: crvUsdMarketsData[market.value].borrowRate } };
579
- }
580
- } catch (error) {
581
- console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
582
- positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
583
- }
584
- })).flat(),
585
- ...llamaLendMarkets.map((market) => addresses.map(async (address) => {
586
- try {
587
- const accData = await _getLlamaLendUserData(client, network, address, market, llamaLendMarketsData[market.value]);
588
- if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
589
- positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: '', data: { ...accData, borrowRate: llamaLendMarketsData[market.value].borrowRate } };
590
- }
591
- } catch (error) {
592
- console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
593
- positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
594
- }
595
- })).flat(),
596
- // liquity sBold/yBold and staking options
597
- ...addresses.map(async (address) => {
598
- try {
599
- if (!isMainnet) {
600
- stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: '', data: null };
601
- return;
602
- }
603
- const data = await getLiquitySAndYBold(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
604
- stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: '', data };
605
- } catch (error) {
606
- console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
607
- stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: `Error fetching sBold/yBold data for address ${address}`, data: null };
608
- }
609
- }),
610
- ]);
611
-
612
- return {
613
- positions,
614
- stakingPositions,
615
- rewardsData,
616
- markets,
617
- };
618
- }
1
+ import Dec from 'decimal.js';
2
+ import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
3
+ import {
4
+ AaveMarkets,
5
+ AaveV4Spokes,
6
+ CompoundMarkets,
7
+ CrvUsdMarkets,
8
+ EulerV2Markets,
9
+ LiquityV2Markets,
10
+ LlamaLendMarkets,
11
+ MorphoBlueMarkets,
12
+ SparkMarkets,
13
+ } from '../markets';
14
+ import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } from '../morphoBlue';
15
+ import {
16
+ AaveV2MarketData,
17
+ AaveV3MarketData,
18
+ AaveV4SpokeData,
19
+ AaveVersions,
20
+ CdpInfo,
21
+ CompoundV2MarketsData,
22
+ CompoundV3MarketsData,
23
+ CompoundVersions,
24
+ CrvUSDGlobalMarketData,
25
+ EulerV2FullMarketData,
26
+ LiquityV2MarketData,
27
+ LlamaLendGlobalMarketData,
28
+ MorphoBlueMarketInfo,
29
+ PortfolioPositionsData,
30
+ SparkMarketsData,
31
+ } from '../types';
32
+ import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
33
+ import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
34
+ import { _getEulerV2AccountData, _getEulerV2MarketsData } from '../eulerV2';
35
+ import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
36
+ import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
37
+ import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
38
+ import { ZERO_ADDRESS } from '../constants';
39
+ import { _getMakerCdpData, _getUserCdps } from '../maker';
40
+ import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
41
+ import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
42
+ import { getViemProvider } from '../services/viem';
43
+ import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
44
+ import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
45
+ import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
46
+ import { getEulerV2SubAccounts } from '../helpers/eulerHelpers';
47
+ import { getUmbrellaData } from '../umbrella';
48
+ import { getMeritUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
49
+ import { getCompoundV3Rewards } from '../claiming/compV3';
50
+ import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
51
+ import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
52
+ import { getKingRewards } from '../claiming/king';
53
+ import { fetchEthenaAirdropRewards } from '../claiming/ethena';
54
+ import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
55
+
56
+ export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], summerFiAddresses: EthAddress[]): Promise<{
57
+ positions: PortfolioPositionsData;
58
+ stakingPositions: any;
59
+ rewardsData: any;
60
+ markets: any;
61
+ }> {
62
+ const isMainnet = network === NetworkNumber.Eth;
63
+ const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
64
+ const isMorphoRewardsSupported = [NetworkNumber.Eth, NetworkNumber.Base].includes(network);
65
+
66
+ const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
67
+ const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
68
+ const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
69
+ const eulerV2Markets = Object.values(EulerV2Markets(network)).filter((market) => market.chainIds.includes(network));
70
+ const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
71
+ const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
72
+ const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
73
+ const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
74
+ const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
75
+ const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
76
+ const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
77
+ const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
78
+
79
+ const client = getViemProvider(provider, network, {
80
+ batch: {
81
+ multicall: {
82
+ batchSize: 2500000,
83
+ },
84
+ },
85
+ });
86
+ const defaultClient = getViemProvider(defaultProvider, network, {
87
+ batch: {
88
+ multicall: {
89
+ batchSize: 2500000,
90
+ },
91
+ },
92
+ });
93
+
94
+ const morphoMarketsData: Record<string, MorphoBlueMarketInfo> = {};
95
+ const compoundV3MarketsData: Record<string, CompoundV3MarketsData> = {};
96
+ const sparkMarketsData: Record<string, SparkMarketsData> = {};
97
+ const eulerV2MarketsData: Record<string, EulerV2FullMarketData> = {};
98
+ const aaveV3MarketsData: Record<string, AaveV3MarketData> = {};
99
+ const makerCdps: Record<string, CdpInfo[]> = {};
100
+ const aaveV2MarketsData: Record<string, AaveV2MarketData> = {};
101
+ const compoundV2MarketsData: Record<string, CompoundV2MarketsData> = {};
102
+ const crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData> = {};
103
+ const llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData> = {};
104
+ const liquityV2MarketsData: Record<string, LiquityV2MarketData> = {};
105
+ const aaveV4SpokesData: Record<string, AaveV4SpokeData> = {};
106
+
107
+ const markets = {
108
+ morphoMarketsData,
109
+ compoundV3MarketsData,
110
+ sparkMarketsData,
111
+ eulerV2MarketsData,
112
+ aaveV3MarketsData,
113
+ aaveV2MarketsData,
114
+ compoundV2MarketsData,
115
+ crvUsdMarketsData,
116
+ llamaLendMarketsData,
117
+ liquityV2MarketsData,
118
+ aaveV4SpokesData,
119
+ };
120
+
121
+ const positions: PortfolioPositionsData = {};
122
+ const stakingPositions: any = {};
123
+ const rewardsData: any = {};
124
+ const allAddresses = [...addresses, ...summerFiAddresses];
125
+
126
+ for (const address of allAddresses) {
127
+ positions[address.toLowerCase() as EthAddress] = {
128
+ aaveV3: {},
129
+ aaveV4: {},
130
+ morphoBlue: {},
131
+ compoundV3: {},
132
+ spark: {},
133
+ eulerV2: {},
134
+ maker: {},
135
+ aaveV2: {},
136
+ compoundV2: {},
137
+ liquity: {},
138
+ crvUsd: {},
139
+ llamaLend: {},
140
+ fluid: {
141
+ error: '',
142
+ data: {},
143
+ },
144
+ };
145
+ }
146
+
147
+ // TODO: check default values, probably needed when fetching portfolio on unsupported networks
148
+ for (const address of addresses) {
149
+ stakingPositions[address.toLowerCase() as EthAddress] = {
150
+ aaveV3: {},
151
+ morphoBlue: {},
152
+ compoundV3: {},
153
+ spark: {},
154
+ aaveV2: {},
155
+ compoundV2: {},
156
+ liquity: {},
157
+ liquityV2: {},
158
+ fluid: {
159
+ error: '',
160
+ data: {},
161
+ },
162
+ };
163
+
164
+ rewardsData[address.toLowerCase() as EthAddress] = {
165
+ aaveV3merit: {},
166
+ aaveV3: {},
167
+ compV3: {},
168
+ spark: {},
169
+ spk: {},
170
+ king: {},
171
+ morpho: {},
172
+ ethena: {},
173
+ };
174
+ }
175
+
176
+ await Promise.allSettled([
177
+ // === MARKET DATA (needs to be fetched first) ===
178
+ ...morphoMarkets.map(async (market) => {
179
+ const marketData = await _getMorphoBlueMarketData(client, network, market);
180
+ morphoMarketsData[market.value] = marketData;
181
+ }),
182
+ ...compoundV3Markets.map(async (market) => {
183
+ const marketData = await _getCompoundV3MarketsData(client, network, market, defaultClient);
184
+ compoundV3MarketsData[market.value] = marketData;
185
+ }),
186
+ ...sparkMarkets.map(async (market) => {
187
+ const marketData = await _getSparkMarketsData(client, network, market);
188
+ sparkMarketsData[market.value] = marketData;
189
+ }),
190
+ ...eulerV2Markets.map(async (market) => {
191
+ const marketData = await _getEulerV2MarketsData(client, network, market);
192
+ eulerV2MarketsData[market.value] = marketData;
193
+ }),
194
+ ...aaveV3Markets.map(async (market) => {
195
+ const marketData = await _getAaveV3MarketData(client, network, market);
196
+ aaveV3MarketsData[market.value] = marketData;
197
+ }),
198
+ ...aaveV4Spokes.map(async (spoke) => {
199
+ const spokeData = await _getAaveV4SpokeData(client, network, spoke);
200
+ aaveV4SpokesData[spoke.value] = spokeData;
201
+ }),
202
+ ...aaveV2Markets.map(async (market) => {
203
+ const marketData = await _getAaveV2MarketsData(client, network, market);
204
+ aaveV2MarketsData[market.value] = marketData;
205
+ }),
206
+ ...compoundV2Markets.map(async (market) => {
207
+ const marketData = await _getCompoundV2MarketsData(client, network);
208
+ compoundV2MarketsData[market.value] = marketData;
209
+ }),
210
+ ...crvUsdMarkets.map(async (market) => {
211
+ const marketData = await _getCurveUsdGlobalData(client, network, market);
212
+ crvUsdMarketsData[market.value] = marketData;
213
+ }),
214
+ ...llamaLendMarkets.map(async (market) => {
215
+ const marketData = await _getLlamaLendGlobalData(client, network, market);
216
+ llamaLendMarketsData[market.value] = marketData;
217
+ }),
218
+ ...liquityV2Markets.map(async (market) => {
219
+ const marketData = await _getLiquityV2MarketData(client, network, market);
220
+ liquityV2MarketsData[market.value] = marketData;
221
+ }),
222
+
223
+ // === INDEPENDENT USER DATA (doesn't depend on market data) ===
224
+ ...addresses.map(async (address) => {
225
+ if (!isMainnet) return; // Maker CDPs are only available on mainnet
226
+ const makerCdp = await _getUserCdps(client, network, address);
227
+ makerCdps[address.toLowerCase() as EthAddress] = makerCdp;
228
+ }),
229
+ ...addresses.map(async (address) => {
230
+ try {
231
+ if (!isFluidSupported) return; // Fluid is not available on Optimism
232
+ const userPositions = (await _getUserPositionsPortfolio(client, network, address));
233
+ for (const position of userPositions) {
234
+ if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
235
+ positions[address.toLowerCase() as EthAddress].fluid.data[position.userData.nftId] = position.userData;
236
+ }
237
+ }
238
+ } catch (error) {
239
+ console.error(`Error fetching Fluid positions for address ${address}:`, error);
240
+ positions[address.toLowerCase() as EthAddress].fluid = {
241
+ error: `Error fetching Fluid positions for address ${address}`,
242
+ data: {},
243
+ };
244
+ }
245
+ }),
246
+
247
+ // === STAKING DATA (independent of market data) ===
248
+ ...addresses.map(async (address) => {
249
+ try {
250
+ if (!isFluidSupported) return;
251
+ stakingPositions[address.toLowerCase()].fluid = await _getAllUserEarnPositionsWithFTokens(client, network, address);
252
+ } catch (error) {
253
+ console.error(`Error fetching Fluid lend data for address ${address}:`, error);
254
+ stakingPositions[address.toLowerCase()].fluid = { error: `Error fetching Fluid lend data for address ${address}`, data: null };
255
+ }
256
+ }),
257
+ ...addresses.map(async (address) => {
258
+ try {
259
+ if (!isMainnet) return;
260
+ stakingPositions[address.toLowerCase()].liquity = await getLiquityStakingData(client, network, address);
261
+ } catch (error) {
262
+ console.error(`Error fetching Liquity staking data for address ${address}:`, error);
263
+ stakingPositions[address.toLowerCase()].liquity = { error: `Error fetching Liquity staking data for address ${address}`, data: null };
264
+ }
265
+ }),
266
+ ...addresses.map(async (address) => {
267
+ try {
268
+ if (!isMainnet) return;
269
+ stakingPositions[address.toLowerCase()].aaveV3 = await getStakeAaveData(client, network, address);
270
+ } catch (error) {
271
+ console.error(`Error fetching Aave V3 staking data for address ${address}:`, error);
272
+ stakingPositions[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 staking data for address ${address}`, data: null };
273
+ }
274
+ }),
275
+ ...addresses.map(async (address) => {
276
+ try {
277
+ if (!isMainnet) return;
278
+ stakingPositions[address.toLowerCase()].umbrella = await getUmbrellaData(client, network, address);
279
+ } catch (error) {
280
+ console.error(`Error fetching Umbrella staking data for address ${address}:`, error);
281
+ stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
282
+ }
283
+ }),
284
+ // Liquity V2 staking
285
+ ...liquityV2MarketsStaking.map(market => addresses.map(async (address) => {
286
+ try {
287
+ if (!isMainnet) {
288
+ stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
289
+ return;
290
+ }
291
+ const liquityV2StakingData = await getLiquityV2Staking(client, network, market.value, address);
292
+ stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: liquityV2StakingData };
293
+ } catch (error) {
294
+ console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
295
+ stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
296
+ }
297
+ })).flat(),
298
+
299
+ // === REWARDS DATA (independent of market data) ===
300
+ // Batch King rewards
301
+ (async () => {
302
+ try {
303
+ if (!isMainnet) {
304
+ for (const address of addresses) {
305
+ rewardsData[address.toLowerCase()].king = { error: '', data: [] };
306
+ }
307
+ return;
308
+ }
309
+ const kingRewards = await getKingRewards(client, network, addresses);
310
+ for (const address of addresses) {
311
+ const lowerAddress = address.toLowerCase() as EthAddress;
312
+ rewardsData[lowerAddress].king = {
313
+ error: '',
314
+ data: kingRewards[lowerAddress] || [],
315
+ };
316
+ }
317
+ } catch (error) {
318
+ console.error('Error fetching King rewards data in batch:', error);
319
+ for (const address of addresses) {
320
+ rewardsData[address.toLowerCase() as EthAddress].king = {
321
+ error: 'Error fetching King rewards data in batch',
322
+ data: null,
323
+ };
324
+ }
325
+ }
326
+ })(),
327
+ ...sparkMarkets.map((market) => addresses.map(async address => {
328
+ try {
329
+ if (!isMainnet) {
330
+ rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: [] };
331
+ return;
332
+ }
333
+ const sparkData = await fetchSparkRewards(client, network, address, market.providerAddress);
334
+ rewardsData[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: sparkData };
335
+ } catch (error) {
336
+ console.error(`Error fetching Spark rewards data for address ${address}, market ${market.value}:`, error);
337
+ rewardsData[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark rewards data for address ${address}`, data: null };
338
+ }
339
+ })).flat(),
340
+ // CompV3 rewards
341
+ ...compoundV3Markets.map(market => addresses.map(async (address) => {
342
+ try {
343
+ const compV3Rewards = await getCompoundV3Rewards(client, network, address, market.baseMarketAddress);
344
+ rewardsData[address.toLowerCase() as EthAddress].compV3[market.value] = { error: '', data: compV3Rewards };
345
+ } catch (error) {
346
+ console.error(`Error fetching Compound V3 rewards data for address ${address}:`, error);
347
+ rewardsData[address.toLowerCase() as EthAddress].compV3[market.value] = { error: `Error fetching Compound V3 rewards data for address ${address}`, data: null };
348
+ }
349
+ })).flat(),
350
+ ...addresses.map(async (address) => {
351
+ try {
352
+ const aaveMeritData = await getMeritUnclaimedRewards(address, network);
353
+ rewardsData[address.toLowerCase() as EthAddress].aaveV3merit = { error: '', data: aaveMeritData };
354
+ } catch (error) {
355
+ console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
356
+ rewardsData[address.toLowerCase() as EthAddress].aaveV3merit = { error: `Error fetching Aave V3 Merit rewards data for address ${address}`, data: null };
357
+ }
358
+ }),
359
+ ...aaveV3Markets.map(market => addresses.map(async (address) => {
360
+ try {
361
+ const aaveData = await getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress);
362
+ rewardsData[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: aaveData };
363
+ } catch (error) {
364
+ console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
365
+ rewardsData[address.toLowerCase() as EthAddress].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
366
+ }
367
+ })).flat(),
368
+ // Batch Morpho Blue rewards
369
+ (async () => {
370
+ if (!isMorphoRewardsSupported) return;
371
+ try {
372
+ const morphoRewards = await fetchMorphoBlueRewards(client, network, addresses);
373
+ for (const address of addresses) {
374
+ const lowerAddress = address.toLowerCase() as EthAddress;
375
+ rewardsData[lowerAddress].morpho = {
376
+ error: '',
377
+ data: morphoRewards[lowerAddress] || [],
378
+ };
379
+ }
380
+ } catch (error) {
381
+ console.error('Error fetching Morpho Blue rewards data in batch:', error);
382
+ for (const address of addresses) {
383
+ rewardsData[address.toLowerCase() as EthAddress].morpho = {
384
+ error: 'Error fetching Morpho Blue rewards data in batch',
385
+ data: null,
386
+ };
387
+ }
388
+ }
389
+ })(),
390
+ // Batch Spark Airdrop rewards
391
+ (async () => {
392
+ try {
393
+ if (!isMainnet) {
394
+ for (const address of addresses) {
395
+ rewardsData[address.toLowerCase()].spk = { error: '', data: [] };
396
+ }
397
+ return;
398
+ }
399
+
400
+ const sparkAirdropRewards = await fetchSparkAirdropRewards(client, network, addresses);
401
+ for (const address of addresses) {
402
+ const lowerAddress = address.toLowerCase() as EthAddress;
403
+ rewardsData[lowerAddress].spk = {
404
+ error: '',
405
+ data: sparkAirdropRewards[lowerAddress] || [],
406
+ };
407
+ }
408
+ } catch (error) {
409
+ console.error('Error fetching Spark Airdrop rewards data in batch:', error);
410
+ for (const address of addresses) {
411
+ rewardsData[address.toLowerCase() as EthAddress].spk = {
412
+ error: 'Error fetching Spark Airdrop rewards data in batch',
413
+ data: null,
414
+ };
415
+ }
416
+ }
417
+ })(),
418
+ (async () => {
419
+ try {
420
+ if (!isMainnet) {
421
+ return;
422
+ }
423
+
424
+ const ethenaAirdropRewards = await fetchEthenaAirdropRewards(addresses);
425
+ for (const address of addresses) {
426
+ const lowerAddress = address.toLowerCase() as EthAddress;
427
+ rewardsData[lowerAddress].ethena = {
428
+ error: '',
429
+ data: ethenaAirdropRewards[lowerAddress] || [],
430
+ };
431
+ }
432
+ } catch (error) {
433
+ console.error('Error fetching Ethena Airdrop rewards data:', error);
434
+ for (const address of addresses) {
435
+ rewardsData[address.toLowerCase() as EthAddress].ethena = {
436
+ error: 'Error fetching Ethena Airdrop rewards data in batch',
437
+ data: null,
438
+ };
439
+ }
440
+ }
441
+ })(),
442
+ ]);
443
+
444
+
445
+ await Promise.all([
446
+ ...aaveV3Markets.map((market) => allAddresses.map(async (address) => {
447
+ try {
448
+ const accData = await _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...aaveV3MarketsData[market.value] });
449
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: accData };
450
+ } catch (error) {
451
+ console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
452
+ positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
453
+ }
454
+ })).flat(),
455
+ ...aaveV4Spokes.map((spoke) => allAddresses.map(async (address) => {
456
+ try {
457
+ const accData = await _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
458
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
459
+ } catch (error) {
460
+ console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
461
+ positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
462
+ }
463
+ })).flat(),
464
+ ...morphoMarkets.map((market) => addresses.map(async (address) => {
465
+ try {
466
+ const [accDataPromise, earnDataPromise] = await Promise.allSettled([
467
+ _getMorphoBlueAccountData(client, network, address, market, morphoMarketsData[market.value]),
468
+ getMorphoEarn(client, network, address, market, morphoMarketsData[market.value]),
469
+ ]);
470
+ if (accDataPromise.status === 'rejected') {
471
+ console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, accDataPromise.reason);
472
+ positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
473
+ }
474
+ if (earnDataPromise.status === 'rejected') {
475
+ console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, earnDataPromise.reason);
476
+ positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
477
+ }
478
+ if (accDataPromise.status !== 'rejected') {
479
+ const accData = accDataPromise.value;
480
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: '', data: accData };
481
+ }
482
+ if (earnDataPromise.status !== 'rejected') {
483
+ const earnData = earnDataPromise.value;
484
+ if (earnData && new Dec(earnData.amount).gt(0)) {
485
+ stakingPositions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = {
486
+ error: '',
487
+ data: earnData,
488
+ };
489
+ }
490
+ }
491
+ } catch (error) {
492
+ console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
493
+ positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
494
+ }
495
+ })).flat(),
496
+ ...compoundV3Markets.map((market) => addresses.map(async (address) => {
497
+ try {
498
+ const accData = await _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: compoundV3MarketsData[market.value].assetsData });
499
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: '', data: accData };
500
+ } catch (error) {
501
+ console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
502
+ positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
503
+ }
504
+ })).flat(),
505
+ ...sparkMarkets.map((market) => allAddresses.map(async (address) => {
506
+ try {
507
+ const accData = await _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: sparkMarketsData[market.value].assetsData, eModeCategoriesData: sparkMarketsData[market.value].eModeCategoriesData });
508
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: accData };
509
+ } catch (error) {
510
+ console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
511
+ positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
512
+ }
513
+ })).flat(),
514
+ ...eulerV2Markets.map((market) => addresses.map((address) => {
515
+ const eulerV2SubAccounts = getEulerV2SubAccounts(address);
516
+ const eulerV2Addresses = [address, ...eulerV2SubAccounts];
517
+ return Promise.all(eulerV2Addresses.map(async (eulerAddress) => {
518
+ try {
519
+ const accData = await _getEulerV2AccountData(client, network, eulerAddress, eulerAddress, { selectedMarket: market, ...eulerV2MarketsData[market.value] });
520
+ if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
521
+ if (!positions[address.toLowerCase() as EthAddress].eulerV2[market.value]) {
522
+ positions[address.toLowerCase() as EthAddress].eulerV2[market.value] = {};
523
+ }
524
+ positions[address.toLowerCase() as EthAddress].eulerV2[market.value]![eulerAddress.toLowerCase() as EthAddress] = { error: '', data: accData };
525
+ }
526
+ } catch (error) {
527
+ console.error(`Error fetching EulerV2 account data for address ${eulerAddress} on market ${market.value}:`, error);
528
+ if (!positions[address.toLowerCase() as EthAddress].eulerV2[market.value]) {
529
+ positions[address.toLowerCase() as EthAddress].eulerV2[market.value] = {};
530
+ }
531
+ positions[address.toLowerCase() as EthAddress].eulerV2[market.value]![eulerAddress.toLowerCase() as EthAddress] = { error: `Error fetching EulerV2 account data for address ${eulerAddress} on market ${market.value}`, data: null };
532
+ }
533
+ }));
534
+ }).flat()).flat(),
535
+ ...addresses.map(async (address) => makerCdps[address.toLowerCase() as EthAddress]?.map(async (cdpInfo) => {
536
+ try {
537
+ const cdpData = await _getMakerCdpData(client, network, cdpInfo);
538
+ if (cdpData) {
539
+ positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: '', data: cdpData };
540
+ }
541
+ } catch (error) {
542
+ console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
543
+ positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
544
+ }
545
+ })).flat(),
546
+ ...aaveV2Markets.map((market) => addresses.map(async (address) => {
547
+ try {
548
+ const accData = await _getAaveV2AccountData(client, network, address, aaveV2MarketsData[market.value].assetsData, market);
549
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: '', data: accData };
550
+ } catch (error) {
551
+ console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
552
+ positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
553
+ }
554
+ })).flat(),
555
+ ...compoundV2Markets.map((market) => addresses.map(async (address) => {
556
+ try {
557
+ const accData = await _getCompoundV2AccountData(client, network, address, compoundV2MarketsData[market.value].assetsData);
558
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: '', data: accData };
559
+ } catch (error) {
560
+ console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
561
+ positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
562
+ }
563
+ })).flat(),
564
+ ...addresses.map(async (address) => {
565
+ try {
566
+ if (!isMainnet) return; // Liquity trove info is only available on mainnet
567
+ const troveInfo = await _getLiquityTroveInfo(client, network, address);
568
+ if (new Dec(troveInfo.collateral).gt(0)) positions[address.toLowerCase() as EthAddress].liquity = { error: '', data: troveInfo };
569
+ } catch (error) {
570
+ console.error(`Error fetching Liquity trove info for address ${address}:`, error);
571
+ positions[address.toLowerCase() as EthAddress].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
572
+ }
573
+ }),
574
+ ...crvUsdMarkets.map((market) => addresses.map(async (address) => {
575
+ try {
576
+ const accData = await _getCurveUsdUserData(client, network, address, market, crvUsdMarketsData[market.value].activeBand);
577
+ if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
578
+ positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: '', data: { ...accData, borrowRate: crvUsdMarketsData[market.value].borrowRate } };
579
+ }
580
+ } catch (error) {
581
+ console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
582
+ positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
583
+ }
584
+ })).flat(),
585
+ ...llamaLendMarkets.map((market) => addresses.map(async (address) => {
586
+ try {
587
+ const accData = await _getLlamaLendUserData(client, network, address, market, llamaLendMarketsData[market.value]);
588
+ if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
589
+ positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: '', data: { ...accData, borrowRate: llamaLendMarketsData[market.value].borrowRate } };
590
+ }
591
+ } catch (error) {
592
+ console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
593
+ positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
594
+ }
595
+ })).flat(),
596
+ // liquity sBold/yBold and staking options
597
+ ...addresses.map(async (address) => {
598
+ try {
599
+ if (!isMainnet) {
600
+ stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: '', data: null };
601
+ return;
602
+ }
603
+ const data = await getLiquitySAndYBold(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
604
+ stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: '', data };
605
+ } catch (error) {
606
+ console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
607
+ stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: `Error fetching sBold/yBold data for address ${address}`, data: null };
608
+ }
609
+ }),
610
+ ]);
611
+
612
+ return {
613
+ positions,
614
+ stakingPositions,
615
+ rewardsData,
616
+ markets,
617
+ };
618
+ }