@defisaver/positions-sdk 2.1.54 → 2.1.56-dev-exposure

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