@defisaver/positions-sdk 2.1.161-portfolio-api-1-dev → 2.1.161-portfolio-api-3-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/cjs/aaveV2/index.js +2 -0
  2. package/cjs/aaveV3/index.d.ts +41 -12
  3. package/cjs/aaveV3/index.js +237 -2
  4. package/cjs/aaveV3/sgho.d.ts +2 -16
  5. package/cjs/aaveV4/lend.d.ts +2 -43
  6. package/cjs/claiming/aaveV3.d.ts +2 -2
  7. package/cjs/claiming/ethena.d.ts +2 -1
  8. package/cjs/claiming/king.d.ts +2 -1
  9. package/cjs/claiming/spark.d.ts +2 -2
  10. package/cjs/curveUsd/index.d.ts +5 -2
  11. package/cjs/curveUsd/index.js +30 -15
  12. package/cjs/fluid/index.d.ts +10 -49
  13. package/cjs/fluid/index.js +36 -1
  14. package/cjs/helpers/aaveHelpers/index.d.ts +9 -1
  15. package/cjs/helpers/aaveHelpers/index.js +26 -6
  16. package/cjs/helpers/aaveV4Helpers/index.js +1 -0
  17. package/cjs/helpers/compoundHelpers/index.js +2 -0
  18. package/cjs/helpers/curveUsdHelpers/index.d.ts +3 -1
  19. package/cjs/helpers/curveUsdHelpers/index.js +15 -2
  20. package/cjs/helpers/fluidHelpers/index.js +1 -0
  21. package/cjs/helpers/liquityV2Helpers/index.js +1 -0
  22. package/cjs/helpers/llamaLendHelpers/index.js +1 -0
  23. package/cjs/helpers/makerHelpers/index.d.ts +1 -1
  24. package/cjs/helpers/makerHelpers/index.js +2 -2
  25. package/cjs/helpers/morphoBlueHelpers/index.js +2 -0
  26. package/cjs/helpers/morphoMidnightHelpers/index.js +2 -0
  27. package/cjs/helpers/sparkHelpers/index.js +1 -0
  28. package/cjs/liquity/index.d.ts +2 -12
  29. package/cjs/liquity/index.js +15 -2
  30. package/cjs/liquityV2/index.d.ts +8 -23
  31. package/cjs/liquityV2/index.js +37 -19
  32. package/cjs/maker/index.d.ts +7 -2
  33. package/cjs/maker/index.js +44 -12
  34. package/cjs/markets/index.d.ts +1 -0
  35. package/cjs/markets/index.js +3 -1
  36. package/cjs/markets/maker/index.d.ts +1 -0
  37. package/cjs/markets/maker/index.js +13 -0
  38. package/cjs/moneymarket/moneymarketCommonService.d.ts +9 -0
  39. package/cjs/moneymarket/moneymarketCommonService.js +13 -1
  40. package/cjs/portfolio/index.d.ts +17 -5
  41. package/cjs/portfolio/index.js +583 -381
  42. package/cjs/portfolio/lendingProtocols.d.ts +184 -0
  43. package/cjs/portfolio/lendingProtocols.js +196 -0
  44. package/cjs/savings/index.d.ts +8 -2
  45. package/cjs/savings/index.js +37 -5
  46. package/cjs/savings/morphoVaults/index.d.ts +1 -1
  47. package/cjs/savings/morphoVaults/index.js +56 -18
  48. package/cjs/savings/morphoVaults/options.d.ts +2 -0
  49. package/cjs/savings/morphoVaults/options.js +61 -1
  50. package/cjs/spark/index.js +1 -0
  51. package/cjs/staking/staking.d.ts +20 -0
  52. package/cjs/staking/staking.js +19 -1
  53. package/cjs/types/aave.d.ts +86 -0
  54. package/cjs/types/aaveV4.d.ts +45 -0
  55. package/cjs/types/compound.d.ts +2 -0
  56. package/cjs/types/curveUsd.d.ts +6 -0
  57. package/cjs/types/fluid.d.ts +14 -0
  58. package/cjs/types/index.d.ts +1 -0
  59. package/cjs/types/index.js +1 -0
  60. package/cjs/types/liquity.d.ts +16 -0
  61. package/cjs/types/liquityV2.d.ts +26 -0
  62. package/cjs/types/maker.d.ts +4 -0
  63. package/cjs/types/morphoBlue.d.ts +2 -0
  64. package/cjs/types/morphoMidnight.d.ts +1 -0
  65. package/cjs/types/portfolio.d.ts +127 -6
  66. package/cjs/types/savings/index.d.ts +9 -1
  67. package/cjs/types/savings/morphoVaults.d.ts +10 -2
  68. package/cjs/types/savings/morphoVaults.js +9 -1
  69. package/cjs/types/spark.d.ts +2 -0
  70. package/cjs/umbrella/index.d.ts +2 -3
  71. package/esm/aaveV2/index.js +2 -0
  72. package/esm/aaveV3/index.d.ts +41 -12
  73. package/esm/aaveV3/index.js +231 -2
  74. package/esm/aaveV3/sgho.d.ts +2 -16
  75. package/esm/aaveV4/lend.d.ts +2 -43
  76. package/esm/claiming/aaveV3.d.ts +2 -2
  77. package/esm/claiming/aaveV3.js +1 -1
  78. package/esm/claiming/ethena.d.ts +2 -1
  79. package/esm/claiming/king.d.ts +2 -1
  80. package/esm/claiming/spark.d.ts +2 -2
  81. package/esm/claiming/spark.js +1 -1
  82. package/esm/curveUsd/index.d.ts +5 -2
  83. package/esm/curveUsd/index.js +30 -15
  84. package/esm/fluid/index.d.ts +10 -49
  85. package/esm/fluid/index.js +33 -0
  86. package/esm/helpers/aaveHelpers/index.d.ts +9 -1
  87. package/esm/helpers/aaveHelpers/index.js +23 -5
  88. package/esm/helpers/aaveV4Helpers/index.js +1 -0
  89. package/esm/helpers/compoundHelpers/index.js +2 -0
  90. package/esm/helpers/curveUsdHelpers/index.d.ts +3 -1
  91. package/esm/helpers/curveUsdHelpers/index.js +16 -3
  92. package/esm/helpers/fluidHelpers/index.js +1 -0
  93. package/esm/helpers/liquityV2Helpers/index.js +1 -0
  94. package/esm/helpers/llamaLendHelpers/index.js +2 -1
  95. package/esm/helpers/makerHelpers/index.d.ts +1 -1
  96. package/esm/helpers/makerHelpers/index.js +2 -2
  97. package/esm/helpers/morphoBlueHelpers/index.js +2 -0
  98. package/esm/helpers/morphoMidnightHelpers/index.js +2 -0
  99. package/esm/helpers/sparkHelpers/index.js +1 -0
  100. package/esm/liquity/index.d.ts +2 -12
  101. package/esm/liquity/index.js +16 -3
  102. package/esm/liquityV2/index.d.ts +8 -23
  103. package/esm/liquityV2/index.js +35 -18
  104. package/esm/maker/index.d.ts +7 -2
  105. package/esm/maker/index.js +44 -14
  106. package/esm/markets/index.d.ts +1 -0
  107. package/esm/markets/index.js +1 -0
  108. package/esm/markets/maker/index.d.ts +1 -0
  109. package/esm/markets/maker/index.js +10 -0
  110. package/esm/moneymarket/moneymarketCommonService.d.ts +9 -0
  111. package/esm/moneymarket/moneymarketCommonService.js +11 -0
  112. package/esm/portfolio/index.d.ts +17 -5
  113. package/esm/portfolio/index.js +584 -385
  114. package/esm/portfolio/lendingProtocols.d.ts +184 -0
  115. package/esm/portfolio/lendingProtocols.js +189 -0
  116. package/esm/savings/index.d.ts +8 -2
  117. package/esm/savings/index.js +35 -4
  118. package/esm/savings/morphoVaults/index.d.ts +1 -1
  119. package/esm/savings/morphoVaults/index.js +57 -19
  120. package/esm/savings/morphoVaults/options.d.ts +2 -0
  121. package/esm/savings/morphoVaults/options.js +61 -1
  122. package/esm/spark/index.js +1 -0
  123. package/esm/staking/staking.d.ts +20 -0
  124. package/esm/staking/staking.js +17 -0
  125. package/esm/types/aave.d.ts +86 -0
  126. package/esm/types/aaveV4.d.ts +45 -0
  127. package/esm/types/compound.d.ts +2 -0
  128. package/esm/types/curveUsd.d.ts +6 -0
  129. package/esm/types/fluid.d.ts +14 -0
  130. package/esm/types/index.d.ts +1 -0
  131. package/esm/types/index.js +1 -0
  132. package/esm/types/liquity.d.ts +16 -0
  133. package/esm/types/liquityV2.d.ts +26 -0
  134. package/esm/types/maker.d.ts +4 -0
  135. package/esm/types/morphoBlue.d.ts +2 -0
  136. package/esm/types/morphoMidnight.d.ts +1 -0
  137. package/esm/types/portfolio.d.ts +127 -6
  138. package/esm/types/savings/index.d.ts +9 -1
  139. package/esm/types/savings/morphoVaults.d.ts +10 -2
  140. package/esm/types/savings/morphoVaults.js +8 -0
  141. package/esm/types/spark.d.ts +2 -0
  142. package/esm/umbrella/index.d.ts +2 -3
  143. package/package.json +3 -2
  144. package/src/aaveV2/index.ts +2 -0
  145. package/src/aaveV3/index.ts +293 -2
  146. package/src/aaveV3/sgho.ts +2 -17
  147. package/src/aaveV4/lend.ts +2 -48
  148. package/src/claiming/aaveV3.ts +4 -2
  149. package/src/claiming/ethena.ts +5 -5
  150. package/src/claiming/king.ts +3 -3
  151. package/src/claiming/spark.ts +6 -4
  152. package/src/curveUsd/index.ts +33 -16
  153. package/src/fluid/index.ts +44 -3
  154. package/src/helpers/aaveHelpers/index.ts +27 -7
  155. package/src/helpers/aaveV4Helpers/index.ts +1 -0
  156. package/src/helpers/compoundHelpers/index.ts +2 -0
  157. package/src/helpers/curveUsdHelpers/index.ts +23 -3
  158. package/src/helpers/fluidHelpers/index.ts +1 -0
  159. package/src/helpers/liquityV2Helpers/index.ts +1 -0
  160. package/src/helpers/llamaLendHelpers/index.ts +2 -1
  161. package/src/helpers/makerHelpers/index.ts +2 -1
  162. package/src/helpers/morphoBlueHelpers/index.ts +2 -0
  163. package/src/helpers/morphoMidnightHelpers/index.ts +2 -0
  164. package/src/helpers/sparkHelpers/index.ts +1 -0
  165. package/src/liquity/index.ts +19 -5
  166. package/src/liquityV2/index.ts +48 -22
  167. package/src/maker/index.ts +77 -30
  168. package/src/markets/index.ts +2 -1
  169. package/src/markets/maker/index.ts +10 -0
  170. package/src/moneymarket/moneymarketCommonService.ts +15 -0
  171. package/src/portfolio/index.ts +477 -248
  172. package/src/portfolio/lendingProtocols.ts +281 -0
  173. package/src/savings/index.ts +45 -5
  174. package/src/savings/morphoVaults/index.ts +73 -21
  175. package/src/savings/morphoVaults/options.ts +67 -1
  176. package/src/spark/index.ts +1 -0
  177. package/src/staking/staking.ts +28 -0
  178. package/src/types/aave.ts +90 -0
  179. package/src/types/aaveV4.ts +50 -0
  180. package/src/types/compound.ts +2 -0
  181. package/src/types/curveUsd.ts +7 -0
  182. package/src/types/fluid.ts +15 -0
  183. package/src/types/index.ts +2 -1
  184. package/src/types/liquity.ts +19 -1
  185. package/src/types/liquityV2.ts +28 -1
  186. package/src/types/maker.ts +6 -0
  187. package/src/types/morphoBlue.ts +2 -0
  188. package/src/types/morphoMidnight.ts +1 -0
  189. package/src/types/portfolio.ts +153 -7
  190. package/src/types/savings/index.ts +12 -1
  191. package/src/types/savings/morphoVaults.ts +11 -1
  192. package/src/types/spark.ts +2 -0
  193. package/src/umbrella/index.ts +2 -1
@@ -26,18 +26,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getPortfolioMarketsData = getPortfolioMarketsData;
30
+ exports.getPortfolioUserData = getPortfolioUserData;
29
31
  exports.getPortfolioData = getPortfolioData;
32
+ exports.getShifterPortfolioData = getShifterPortfolioData;
30
33
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
34
  const common_1 = require("../types/common");
32
35
  const markets_1 = require("../markets");
33
36
  const morphoBlue_1 = require("../morphoBlue");
34
- const morphoMidnight_1 = require("../morphoMidnight");
35
37
  const types_1 = require("../types");
36
38
  const compoundV3_1 = require("../compoundV3");
37
39
  const spark_1 = require("../spark");
38
40
  const curveUsd_1 = require("../curveUsd");
39
41
  const llamaLend_1 = require("../llamaLend");
40
42
  const aaveV3_1 = require("../aaveV3");
43
+ const aaveV4_1 = require("../aaveV4");
41
44
  const constants_1 = require("../constants");
42
45
  const maker_1 = require("../maker");
43
46
  const aaveV2_1 = require("../aaveV2");
@@ -51,14 +54,512 @@ const aaveV3_2 = require("../claiming/aaveV3");
51
54
  const spark_2 = require("../claiming/spark");
52
55
  const king_1 = require("../claiming/king");
53
56
  const ethena_1 = require("../claiming/ethena");
54
- const aaveV4_1 = require("../aaveV4");
55
57
  const uniswap_1 = require("../claiming/uniswap");
58
+ const lendingProtocols_1 = require("./lendingProtocols");
59
+ /** The markets of the protocols read by their own code below; LENDING_PROTOCOLS has the others'. */
60
+ const getPortfolioMarkets = (network) => ({
61
+ liquityV2Markets: [common_1.NetworkNumber.Eth].includes(network) ? Object.values((0, markets_1.LiquityV2Markets)(network)) : [],
62
+ liquityV2MarketsStaking: [common_1.NetworkNumber.Eth].includes(network) ? Object.values((0, markets_1.LiquityV2Markets)(network)).filter(market => !market.isLegacy) : [],
63
+ });
64
+ const getPortfolioClients = (provider, defaultProvider, network, isSim) => {
65
+ // batchSize is viem's cap on a batch's raw subcall calldata (bytes); the JSON-RPC body ends up
66
+ // ~4x larger (hex + aggregate3 ABI + JSON overhead) and RPC providers reject bodies over
67
+ // ~2.5MB with HTTP 413, so keep this small enough that no single body gets near that.
68
+ // 250k gives the largest body of around 1.26MB - if we bump, we can save maybe 2-3 rpc calls but scaling takes a hit
69
+ // (e.g. adding new markets may result in body size going over alchemy body size limit)
70
+ const args = [network, { batch: { multicall: { batchSize: isSim ? 2000 : 250000 } } }];
71
+ return {
72
+ client: (0, viem_1.getViemProvider)(provider, ...args),
73
+ defaultClient: (0, viem_1.getViemProvider)(defaultProvider, ...args),
74
+ };
75
+ };
76
+ const _getPortfolioMarketsData = (client, defaultClient, network) => __awaiter(void 0, void 0, void 0, function* () {
77
+ const { liquityV2Markets } = getPortfolioMarkets(network);
78
+ const markets = {
79
+ morphoMarketsData: {},
80
+ morphoMidnightMarketsData: {},
81
+ compoundV3MarketsData: {},
82
+ sparkMarketsData: {},
83
+ aaveV3MarketsData: {},
84
+ aaveV2MarketsData: {},
85
+ compoundV2MarketsData: {},
86
+ crvUsdMarketsData: {},
87
+ llamaLendMarketsData: {},
88
+ liquityV2MarketsData: {},
89
+ aaveV4SpokesData: {},
90
+ };
91
+ const liquityV2Failed = {};
92
+ const [lendingFailed] = yield Promise.all([
93
+ Promise.all(lendingProtocols_1.LENDING_PROTOCOLS.map((protocol) => __awaiter(void 0, void 0, void 0, function* () { return [protocol.marketsKey, yield protocol.readMarkets({ client, defaultClient, network }, markets)]; }))),
94
+ // Liquity V2's markets: its troves are read by their own code below.
95
+ ...liquityV2Markets.map((market) => __awaiter(void 0, void 0, void 0, function* () {
96
+ try {
97
+ markets.liquityV2MarketsData[market.value] = yield (0, liquityV2_1._getLiquityV2MarketData)(client, network, market);
98
+ }
99
+ catch (error) {
100
+ console.error(`Error fetching liquityV2MarketsData for market ${market.value}:`, error);
101
+ liquityV2Failed[market.value] = `Error fetching liquityV2MarketsData for market ${market.value}`;
102
+ }
103
+ })),
104
+ ]);
105
+ // A market that failed is left out of markets and named here, under its protocol's key.
106
+ const errors = {};
107
+ for (const [key, failed] of [...lendingFailed, ['liquityV2MarketsData', liquityV2Failed]]) {
108
+ if (Object.keys(failed).length)
109
+ errors[key] = failed;
110
+ }
111
+ return { markets, errors };
112
+ });
113
+ const _getPortfolioUserData = (client, network, addresses, marketsData, isSim, options) => __awaiter(void 0, void 0, void 0, function* () {
114
+ const isMainnet = network === common_1.NetworkNumber.Eth;
115
+ const includePositions = options.positions !== false;
116
+ const includeStaking = options.staking !== false;
117
+ const includeRewards = options.rewards !== false;
118
+ const includeLiquityV2 = includePositions && options.liquityV2 === true;
119
+ // The addresses positions, staking, rewards and Liquity V2 troves are read for: none when left out, so their fetches
120
+ // below make no calls.
121
+ const positionsAddresses = includePositions ? addresses : [];
122
+ const stakingAddresses = includeStaking ? addresses : [];
123
+ const rewardsAddresses = includeRewards ? addresses : [];
124
+ const liquityV2Addresses = includeLiquityV2 ? addresses : [];
125
+ const isFluidSupported = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Base, common_1.NetworkNumber.Plasma].includes(network);
126
+ const { liquityV2Markets, liquityV2MarketsStaking } = getPortfolioMarkets(network);
127
+ const positions = {};
128
+ const stakingPositions = {};
129
+ const rewardsData = {};
130
+ const makerCdpsErrors = {};
131
+ for (const address of positionsAddresses) {
132
+ positions[address.toLowerCase()] = Object.assign(Object.assign(Object.assign({}, Object.fromEntries(lendingProtocols_1.LENDING_PROTOCOLS.map((protocol) => [protocol.key, {}]))), { maker: {}, liquity: {}, fluid: {
133
+ error: '',
134
+ data: {},
135
+ } }), (includeLiquityV2 ? { liquityV2: {} } : {}));
136
+ }
137
+ // TODO: check default values, probably needed when fetching portfolio on unsupported networks
138
+ for (const address of stakingAddresses) {
139
+ stakingPositions[address.toLowerCase()] = {
140
+ aaveV3: {},
141
+ morphoBlue: {},
142
+ compoundV3: {},
143
+ spark: {},
144
+ aaveV2: {},
145
+ compoundV2: {},
146
+ liquity: {},
147
+ liquityV2: {},
148
+ fluid: {
149
+ error: '',
150
+ data: {},
151
+ },
152
+ // Set by the sBOLD/yBOLD fetch below, whether it succeeds or fails.
153
+ liquityV2SBoldYBold: { error: '', data: null },
154
+ };
155
+ }
156
+ for (const address of rewardsAddresses) {
157
+ // merkl, spk, king and uniswap are set by their fetches below, whether they succeed or fail.
158
+ rewardsData[address.toLowerCase()] = {
159
+ merkl: { error: '', data: null },
160
+ aaveV3: {},
161
+ spark: {},
162
+ spk: { error: '', data: null },
163
+ king: { error: '', data: null },
164
+ ethena: {},
165
+ uniswap: { error: '', data: null },
166
+ };
167
+ }
168
+ // Everything starts at once; a read that needs a market's data waits for marketsData.
169
+ yield Promise.all([
170
+ // === POSITIONS THAT DO NOT NEED MARKET DATA ===
171
+ // Maker: the address's vault list, then each vault. A failed list is reported in errors.makerCdps: maker stays {},
172
+ // which would otherwise read as "no vaults".
173
+ ...positionsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
174
+ if (!isMainnet)
175
+ return; // Maker CDPs are only available on mainnet
176
+ let cdps;
177
+ try {
178
+ cdps = yield (0, maker_1._getUserCdps)(client, network, address);
179
+ }
180
+ catch (error) {
181
+ console.error(`Error fetching Maker CDPs for address ${address}:`, error);
182
+ makerCdpsErrors[address.toLowerCase()] = `Error fetching Maker CDPs for address ${address}`;
183
+ return;
184
+ }
185
+ yield Promise.all(cdps.map((cdpInfo) => __awaiter(void 0, void 0, void 0, function* () {
186
+ try {
187
+ const cdpData = yield (0, maker_1._getMakerCdpData)(client, network, cdpInfo);
188
+ if (cdpData) {
189
+ positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
190
+ }
191
+ }
192
+ catch (error) {
193
+ console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
194
+ positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
195
+ }
196
+ })));
197
+ })),
198
+ ...positionsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
199
+ try {
200
+ if (!isFluidSupported)
201
+ return; // Fluid is not available on Optimism
202
+ const userPositions = (yield (0, fluid_1._getUserPositionsPortfolio)(client, network, address));
203
+ for (const position of userPositions) {
204
+ if (position.userData && new decimal_js_1.default(position.userData.suppliedUsd).gt(0)) {
205
+ positions[address.toLowerCase()].fluid.data[position.userData.nftId] = position.userData;
206
+ }
207
+ }
208
+ }
209
+ catch (error) {
210
+ console.error(`Error fetching Fluid positions for address ${address}:`, error);
211
+ positions[address.toLowerCase()].fluid = {
212
+ error: `Error fetching Fluid positions for address ${address}`,
213
+ data: {},
214
+ };
215
+ }
216
+ })),
217
+ ...positionsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
218
+ try {
219
+ if (!isMainnet)
220
+ return; // Liquity trove info is only available on mainnet
221
+ const troveInfo = yield (0, liquity_1._getLiquityTroveInfo)(client, network, address);
222
+ if (new decimal_js_1.default(troveInfo.collateral).gt(0))
223
+ positions[address.toLowerCase()].liquity = { error: '', data: troveInfo };
224
+ }
225
+ catch (error) {
226
+ console.error(`Error fetching Liquity trove info for address ${address}:`, error);
227
+ positions[address.toLowerCase()].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
228
+ }
229
+ })),
230
+ // === STAKING DATA (independent of market data; Morpho Earn is with the positions below) ===
231
+ ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
232
+ try {
233
+ if (!isFluidSupported)
234
+ return;
235
+ stakingPositions[address.toLowerCase()].fluid = yield (0, fluid_1._getAllUserEarnPositionsWithFTokens)(client, network, address);
236
+ }
237
+ catch (error) {
238
+ console.error(`Error fetching Fluid lend data for address ${address}:`, error);
239
+ stakingPositions[address.toLowerCase()].fluid = { error: `Error fetching Fluid lend data for address ${address}`, data: null };
240
+ }
241
+ })),
242
+ ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
243
+ try {
244
+ if (!isMainnet)
245
+ return;
246
+ stakingPositions[address.toLowerCase()].liquity = yield (0, liquity_1.getLiquityStakingData)(client, network, address);
247
+ }
248
+ catch (error) {
249
+ console.error(`Error fetching Liquity staking data for address ${address}:`, error);
250
+ stakingPositions[address.toLowerCase()].liquity = { error: `Error fetching Liquity staking data for address ${address}`, data: null };
251
+ }
252
+ })),
253
+ ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
254
+ try {
255
+ if (!isMainnet)
256
+ return;
257
+ stakingPositions[address.toLowerCase()].aaveV3 = yield (0, aaveV3_1.getStakeAaveData)(client, network, address);
258
+ }
259
+ catch (error) {
260
+ console.error(`Error fetching Aave V3 staking data for address ${address}:`, error);
261
+ stakingPositions[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 staking data for address ${address}`, data: null };
262
+ }
263
+ })),
264
+ ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
265
+ try {
266
+ if (!isMainnet)
267
+ return;
268
+ stakingPositions[address.toLowerCase()].umbrella = yield (0, umbrella_1.getUmbrellaData)(client, network, address);
269
+ }
270
+ catch (error) {
271
+ console.error(`Error fetching Umbrella staking data for address ${address}:`, error);
272
+ stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
273
+ }
274
+ })),
275
+ // Liquity V2 stability pools, then sBOLD/yBOLD, which reads them.
276
+ ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
277
+ yield Promise.all(liquityV2MarketsStaking.map((market) => __awaiter(void 0, void 0, void 0, function* () {
278
+ try {
279
+ if (!isMainnet) {
280
+ stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
281
+ return;
282
+ }
283
+ const liquityV2StakingData = yield (0, liquityV2_1.getLiquityV2Staking)(client, network, market.value, address);
284
+ stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: liquityV2StakingData };
285
+ }
286
+ catch (error) {
287
+ console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
288
+ stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
289
+ }
290
+ })));
291
+ try {
292
+ if (!isMainnet) {
293
+ stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data: null };
294
+ return;
295
+ }
296
+ const data = yield (0, liquityV2_1.getLiquitySAndYBold)(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
297
+ stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data };
298
+ }
299
+ catch (error) {
300
+ console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
301
+ stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: `Error fetching sBold/yBold data for address ${address}`, data: null };
302
+ }
303
+ })),
304
+ // === REWARDS DATA (independent of market data) ===
305
+ // Batch King rewards
306
+ (() => __awaiter(void 0, void 0, void 0, function* () {
307
+ try {
308
+ if (!isMainnet) {
309
+ for (const address of rewardsAddresses) {
310
+ rewardsData[address.toLowerCase()].king = { error: '', data: [] };
311
+ }
312
+ return;
313
+ }
314
+ const kingRewards = yield (0, king_1.getKingRewards)(client, network, rewardsAddresses);
315
+ for (const address of rewardsAddresses) {
316
+ const lowerAddress = address.toLowerCase();
317
+ rewardsData[lowerAddress].king = {
318
+ error: '',
319
+ data: kingRewards[lowerAddress] || [],
320
+ };
321
+ }
322
+ }
323
+ catch (error) {
324
+ console.error('Error fetching King rewards data in batch:', error);
325
+ for (const address of rewardsAddresses) {
326
+ rewardsData[address.toLowerCase()].king = {
327
+ error: 'Error fetching King rewards data in batch',
328
+ data: null,
329
+ };
330
+ }
331
+ }
332
+ }))(),
333
+ // Batch UNI rewards
334
+ (() => __awaiter(void 0, void 0, void 0, function* () {
335
+ try {
336
+ if (!isMainnet) {
337
+ for (const address of rewardsAddresses) {
338
+ rewardsData[address.toLowerCase()].uniswap = { error: '', data: [] };
339
+ }
340
+ return;
341
+ }
342
+ const uniswapRewards = yield (0, uniswap_1.getUniswapRewards)(client, network, rewardsAddresses);
343
+ for (const address of rewardsAddresses) {
344
+ const lowerAddress = address.toLowerCase();
345
+ rewardsData[lowerAddress].uniswap = {
346
+ error: '',
347
+ data: uniswapRewards[lowerAddress] || [],
348
+ };
349
+ }
350
+ }
351
+ catch (error) {
352
+ console.error('Error fetching Uniswap rewards data in batch:', error);
353
+ for (const address of rewardsAddresses) {
354
+ rewardsData[address.toLowerCase()].uniswap = {
355
+ error: 'Error fetching Uniswap rewards data in batch',
356
+ data: null,
357
+ };
358
+ }
359
+ }
360
+ }))(),
361
+ ...lendingProtocols_1.sparkLending.markets(network).map((market) => rewardsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
362
+ try {
363
+ if (!isMainnet) {
364
+ rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: [] };
365
+ return;
366
+ }
367
+ const sparkData = yield (0, spark_2.fetchSparkRewards)(client, network, address, market.providerAddress);
368
+ rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: sparkData };
369
+ }
370
+ catch (error) {
371
+ console.error(`Error fetching Spark rewards data for address ${address}, market ${market.value}:`, error);
372
+ rewardsData[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark rewards data for address ${address}`, data: null };
373
+ }
374
+ }))).flat(),
375
+ ...rewardsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
376
+ try {
377
+ const merklData = yield (0, aaveV3_2.getMerklUnclaimedRewards)(address, network);
378
+ rewardsData[address.toLowerCase()].merkl = { error: '', data: merklData };
379
+ }
380
+ catch (error) {
381
+ console.error(`Error fetching Merkl rewards data for address ${address}:`, error);
382
+ rewardsData[address.toLowerCase()].merkl = { error: `Error fetching Merkl rewards data for address ${address}`, data: null };
383
+ }
384
+ })),
385
+ ...lendingProtocols_1.aaveV3Lending.markets(network).map(market => rewardsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
386
+ try {
387
+ const aaveData = yield (0, aaveV3_2.getUnclaimedRewardsForAllMarkets)(client, network, address, market.providerAddress);
388
+ rewardsData[address.toLowerCase()].aaveV3[market.value] = { error: '', data: aaveData };
389
+ }
390
+ catch (error) {
391
+ console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
392
+ // This market only: the other markets keep their rewards.
393
+ rewardsData[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching Aave V3 rewards data for address ${address} on market ${market.value}`, data: null };
394
+ }
395
+ }))).flat(),
396
+ // Batch Spark Airdrop rewards
397
+ (() => __awaiter(void 0, void 0, void 0, function* () {
398
+ try {
399
+ if (!isMainnet) {
400
+ for (const address of rewardsAddresses) {
401
+ rewardsData[address.toLowerCase()].spk = { error: '', data: [] };
402
+ }
403
+ return;
404
+ }
405
+ const sparkAirdropRewards = yield (0, spark_2.fetchSparkAirdropRewards)(client, network, rewardsAddresses);
406
+ for (const address of rewardsAddresses) {
407
+ const lowerAddress = address.toLowerCase();
408
+ rewardsData[lowerAddress].spk = {
409
+ error: '',
410
+ data: sparkAirdropRewards[lowerAddress] || [],
411
+ };
412
+ }
413
+ }
414
+ catch (error) {
415
+ console.error('Error fetching Spark Airdrop rewards data in batch:', error);
416
+ for (const address of rewardsAddresses) {
417
+ rewardsData[address.toLowerCase()].spk = {
418
+ error: 'Error fetching Spark Airdrop rewards data in batch',
419
+ data: null,
420
+ };
421
+ }
422
+ }
423
+ }))(),
424
+ (() => __awaiter(void 0, void 0, void 0, function* () {
425
+ try {
426
+ if (!isMainnet) {
427
+ return;
428
+ }
429
+ const ethenaAirdropRewards = yield (0, ethena_1.fetchEthenaAirdropRewards)(rewardsAddresses);
430
+ for (const address of rewardsAddresses) {
431
+ const lowerAddress = address.toLowerCase();
432
+ rewardsData[lowerAddress].ethena = {
433
+ error: '',
434
+ data: ethenaAirdropRewards[lowerAddress] || [],
435
+ };
436
+ }
437
+ }
438
+ catch (error) {
439
+ console.error('Error fetching Ethena Airdrop rewards data:', error);
440
+ for (const address of rewardsAddresses) {
441
+ rewardsData[address.toLowerCase()].ethena = {
442
+ error: 'Error fetching Ethena Airdrop rewards data in batch',
443
+ data: null,
444
+ };
445
+ }
446
+ }
447
+ }))(),
448
+ // === POSITIONS ON MARKETS (each waits for its market's data) ===
449
+ ...lendingProtocols_1.LENDING_PROTOCOLS.flatMap((protocol) => protocol.readPositions({ client, network }, positionsAddresses, marketsData, positions)),
450
+ // Morpho Blue Earn: a supply without a borrow, kept as staking, read on the same markets as Morpho Blue's positions.
451
+ ...lendingProtocols_1.morphoBlueLending.markets(network).flatMap((market) => stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
452
+ try {
453
+ const marketData = (0, lendingProtocols_1.requireMarket)((yield marketsData).morphoMarketsData, market.value);
454
+ const earnData = yield (0, morphoBlue_1.getMorphoEarn)(client, network, address, market, marketData);
455
+ if (earnData && new decimal_js_1.default(earnData.amount).gt(0)) {
456
+ stakingPositions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: earnData };
457
+ }
458
+ }
459
+ catch (error) {
460
+ console.error(`Error fetching MorphoBlue earn data for address ${address} on market ${market.value}:`, error);
461
+ stakingPositions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue earn data for address ${address} on market ${market.value}`, data: null };
462
+ }
463
+ }))),
464
+ // Liquity V2 troves: one market's trove ids for every address at once, then each trove's data. A failure is the
465
+ // market's error; the troves that did load stay in its data.
466
+ ...(liquityV2Addresses.length ? liquityV2Markets : []).map((market) => __awaiter(void 0, void 0, void 0, function* () {
467
+ const setEntry = (address, entry) => {
468
+ positions[address.toLowerCase()].liquityV2[market.value] = entry;
469
+ };
470
+ const failAll = (error) => liquityV2Addresses.forEach((address) => setEntry(address, { error, data: {} }));
471
+ const allMarketsData = (yield marketsData).liquityV2MarketsData;
472
+ const marketData = allMarketsData[market.value];
473
+ if (!marketData) {
474
+ failAll(`Error fetching Liquity V2 market data for market ${market.value}`);
475
+ return;
476
+ }
477
+ let troveIds;
478
+ try {
479
+ troveIds = yield (0, liquityV2_1._getLiquityV2UsersTroveIds)(client, network, market, marketData.marketData.troveNFTAddress, isSim, liquityV2Addresses);
480
+ }
481
+ catch (error) {
482
+ console.error(`Error fetching Liquity V2 trove ids on market ${market.value}:`, error);
483
+ failAll(`Error fetching Liquity V2 troves on market ${market.value}`);
484
+ return;
485
+ }
486
+ yield Promise.all(liquityV2Addresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
487
+ var _a;
488
+ const entry = { error: '', data: {} };
489
+ const failed = [];
490
+ yield Promise.all(((_a = troveIds[address]) !== null && _a !== void 0 ? _a : []).map((troveId) => __awaiter(void 0, void 0, void 0, function* () {
491
+ try {
492
+ entry.data[troveId] = yield (0, liquityV2_1._getLiquityV2TroveData)(client, network, {
493
+ selectedMarket: market,
494
+ assetsData: marketData.assetsData,
495
+ troveId,
496
+ allMarketsData: allMarketsData,
497
+ });
498
+ }
499
+ catch (error) {
500
+ console.error(`Error fetching Liquity V2 trove ${troveId} for address ${address} on market ${market.value}:`, error);
501
+ failed.push(troveId);
502
+ }
503
+ })));
504
+ if (failed.length)
505
+ entry.error = `Error fetching Liquity V2 troves ${failed.join(', ')} for address ${address} on market ${market.value}`;
506
+ setEntry(address, entry);
507
+ })));
508
+ })),
509
+ ]);
510
+ return {
511
+ positions,
512
+ stakingPositions,
513
+ rewardsData,
514
+ errors: Object.keys(makerCdpsErrors).length ? { makerCdps: makerCdpsErrors } : {},
515
+ };
516
+ });
517
+ /**
518
+ * Every market the portfolio reads on a network — the markets half of getPortfolioData, for a caller that keeps
519
+ * markets apart from what it reads per address (a cache shared by many addresses). A market that fails is left out
520
+ * of `markets` and named in `errors`.
521
+ */
522
+ function getPortfolioMarketsData(provider_1, network_1, defaultProvider_1) {
523
+ return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, isSim = false) {
524
+ const { client, defaultClient } = getPortfolioClients(provider, defaultProvider, network, isSim);
525
+ return _getPortfolioMarketsData(client, defaultClient, network);
526
+ });
527
+ }
528
+ /**
529
+ * What the portfolio reads per address — the other half of getPortfolioData — against `markets` from
530
+ * getPortfolioMarketsData. `markets` can be a promise: reads that do not need a market (Maker, Fluid, Liquity, staking,
531
+ * rewards) start at once, and each read on a market waits for it. A position on a market missing from `markets` is an
532
+ * entry with an error.
533
+ */
534
+ function getPortfolioUserData(provider_1, network_1, addresses_1, markets_2) {
535
+ return __awaiter(this, arguments, void 0, function* (provider, network, addresses, markets, isSim = false, options = {}) {
536
+ const { client } = getPortfolioClients(provider, provider, network, isSim);
537
+ return _getPortfolioUserData(client, network, addresses, Promise.resolve(markets), isSim, options);
538
+ });
539
+ }
56
540
  function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
541
+ return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false, options = {}) {
542
+ // One pair of clients for both halves, so their calls batch together.
543
+ const { client, defaultClient } = getPortfolioClients(provider, defaultProvider, network, isSim);
544
+ const marketsResult = _getPortfolioMarketsData(client, defaultClient, network);
545
+ const [{ markets, errors: marketsErrors }, userData] = yield Promise.all([
546
+ marketsResult,
547
+ _getPortfolioUserData(client, network, addresses, marketsResult.then((result) => result.markets), isSim, options),
548
+ ]);
549
+ return {
550
+ positions: userData.positions,
551
+ stakingPositions: userData.stakingPositions,
552
+ rewardsData: userData.rewardsData,
553
+ markets,
554
+ errors: Object.assign(Object.assign({}, (Object.keys(marketsErrors).length ? { markets: marketsErrors } : {})), userData.errors),
555
+ };
556
+ });
557
+ }
558
+ function getShifterPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
57
559
  return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false) {
58
560
  const isMainnet = network === common_1.NetworkNumber.Eth;
59
561
  const isFluidSupported = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Base, common_1.NetworkNumber.Plasma].includes(network);
60
562
  const morphoMarkets = Object.values((0, markets_1.MorphoBlueMarkets)(network)).filter((market) => market.chainIds.includes(network));
61
- const morphoMidnightMarkets = Object.values((0, markets_1.MorphoMidnightMarkets)(network)).filter((market) => market.chainIds.includes(network));
62
563
  const compoundV3Markets = Object.values((0, markets_1.CompoundMarkets)(network)).filter((market) => market.chainIds.includes(network) && market.value !== types_1.CompoundVersions.CompoundV2);
63
564
  const sparkMarkets = Object.values((0, markets_1.SparkMarkets)(network)).filter((market) => market.chainIds.includes(network));
64
565
  const aaveV3Markets = [types_1.AaveVersions.AaveV3, types_1.AaveVersions.AaveV3Lido, types_1.AaveVersions.AaveV3Etherfi].map((version) => (0, markets_1.AaveMarkets)(network)[version]).filter((market) => market.chainIds.includes(network));
@@ -67,51 +568,33 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
67
568
  const crvUsdMarkets = Object.values((0, markets_1.CrvUsdMarkets)(network)).filter((market) => market.chainIds.includes(network));
68
569
  const llamaLendMarkets = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb].includes(network) ? Object.values((0, markets_1.LlamaLendMarkets)(network)).filter((market) => market.chainIds.includes(network)) : [];
69
570
  const liquityV2Markets = [common_1.NetworkNumber.Eth].includes(network) ? Object.values((0, markets_1.LiquityV2Markets)(network)) : [];
70
- const liquityV2MarketsStaking = [common_1.NetworkNumber.Eth].includes(network) ? Object.values((0, markets_1.LiquityV2Markets)(network)).filter(market => !market.isLegacy) : [];
71
571
  const aaveV4Spokes = Object.values((0, markets_1.AaveV4Spokes)(network)).filter((market) => market.chainIds.includes(network));
72
- // batchSize is viem's cap on a batch's raw subcall calldata (bytes); the JSON-RPC body ends up
73
- // ~4x larger (hex + aggregate3 ABI + JSON overhead) and RPC providers reject bodies over
74
- // ~2.5MB with HTTP 413, so keep this small enough that no single body gets near that.
75
- // 250k gives the largest body of around 1.26MB - if we bump, we can save maybe 2-3 rpc calls but scaling takes a hit
76
- // (e.g. adding new markets may result in body size going over alchemy body size limit)
77
- const args = [network, { batch: { multicall: { batchSize: isSim ? 2000 : 250000 } } }];
572
+ const args = [network, { batch: { multicall: { batchSize: isSim ? 2000 : 2500000 } } }];
78
573
  const client = (0, viem_1.getViemProvider)(provider, ...args);
79
574
  const defaultClient = (0, viem_1.getViemProvider)(defaultProvider, ...args);
80
- const morphoMarketsData = {};
81
- const morphoMidnightMarketsData = {};
82
- const compoundV3MarketsData = {};
83
- const sparkMarketsData = {};
84
- const aaveV3MarketsData = {};
85
- const makerCdps = {};
86
- const aaveV2MarketsData = {};
87
- const compoundV2MarketsData = {};
88
- const crvUsdMarketsData = {};
89
- const llamaLendMarketsData = {};
90
- const liquityV2MarketsData = {};
91
- const aaveV4SpokesData = {};
92
575
  const markets = {
93
- morphoMarketsData,
94
- morphoMidnightMarketsData,
95
- compoundV3MarketsData,
96
- sparkMarketsData,
97
- aaveV3MarketsData,
98
- aaveV2MarketsData,
99
- compoundV2MarketsData,
100
- crvUsdMarketsData,
101
- llamaLendMarketsData,
102
- liquityV2MarketsData,
103
- aaveV4SpokesData,
576
+ morphoMarketsData: {},
577
+ morphoMidnightMarketsData: {}, // Morpho Midnight is not fetched for the shifter; key kept so the payload shape is stable
578
+ compoundV3MarketsData: {},
579
+ sparkMarketsData: {},
580
+ aaveV3MarketsData: {},
581
+ aaveV2MarketsData: {},
582
+ compoundV2MarketsData: {},
583
+ crvUsdMarketsData: {},
584
+ llamaLendMarketsData: {},
585
+ liquityV2MarketsData: {},
586
+ aaveV4SpokesData: {},
587
+ fluidMarketsData: {},
588
+ makerMarketsData: {},
104
589
  };
590
+ const makerCdps = {};
105
591
  const positions = {};
106
- const stakingPositions = {};
107
- const rewardsData = {};
108
- const allAddresses = [...addresses];
109
- for (const address of allAddresses) {
592
+ for (const address of addresses) {
110
593
  positions[address.toLowerCase()] = {
111
594
  aaveV3: {},
112
595
  aaveV4: {},
113
596
  morphoBlue: {},
114
- morphoMidnight: {},
597
+ morphoMidnight: {}, // not fetched for the shifter (see markets above)
115
598
  compoundV3: {},
116
599
  spark: {},
117
600
  maker: {},
@@ -126,77 +609,58 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
126
609
  },
127
610
  };
128
611
  }
129
- // TODO: check default values, probably needed when fetching portfolio on unsupported networks
130
- for (const address of addresses) {
131
- stakingPositions[address.toLowerCase()] = {
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
- rewardsData[address.toLowerCase()] = {
146
- merkl: {},
147
- aaveV3: {},
148
- spark: {},
149
- spk: {},
150
- king: {},
151
- ethena: {},
152
- };
153
- }
154
612
  yield Promise.allSettled([
155
613
  // === MARKET DATA (needs to be fetched first) ===
156
614
  ...morphoMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
157
- const marketData = yield (0, morphoBlue_1._getMorphoBluePortfolioMarketData)(client, network, market);
158
- morphoMarketsData[market.value] = marketData;
159
- })),
160
- ...morphoMidnightMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
161
- const marketData = yield (0, morphoMidnight_1._getMorphoMidnightMarketData)(client, network, market);
162
- morphoMidnightMarketsData[market.value] = marketData;
615
+ markets.morphoMarketsData[market.value] = yield (0, morphoBlue_1._getMorphoBluePortfolioMarketData)(client, network, market);
163
616
  })),
164
617
  ...compoundV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
165
- const marketData = yield (0, compoundV3_1._getCompoundV3MarketsData)(client, network, market, defaultClient);
166
- compoundV3MarketsData[market.value] = marketData;
618
+ markets.compoundV3MarketsData[market.value] = yield (0, compoundV3_1._getCompoundV3MarketsData)(client, network, market, defaultClient);
167
619
  })),
168
620
  ...sparkMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
169
- const marketData = yield (0, spark_1._getSparkMarketsData)(client, network, market);
170
- sparkMarketsData[market.value] = marketData;
621
+ markets.sparkMarketsData[market.value] = yield (0, spark_1._getSparkMarketsData)(client, network, market);
171
622
  })),
172
623
  ...aaveV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
173
- const marketData = yield (0, aaveV3_1._getAaveV3MarketData)(client, network, market);
174
- aaveV3MarketsData[market.value] = marketData;
624
+ markets.aaveV3MarketsData[market.value] = yield (0, aaveV3_1._getAaveV3MarketData)(client, network, market);
175
625
  })),
176
626
  ...aaveV4Spokes.map((spoke) => __awaiter(this, void 0, void 0, function* () {
177
- const spokeData = yield (0, aaveV4_1._getAaveV4SpokeData)(client, network, spoke);
178
- aaveV4SpokesData[spoke.value] = spokeData;
627
+ markets.aaveV4SpokesData[spoke.value] = yield (0, aaveV4_1._getAaveV4SpokeData)(client, network, spoke);
179
628
  })),
180
629
  ...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
181
- const marketData = yield (0, aaveV2_1._getAaveV2MarketsData)(client, network, market);
182
- aaveV2MarketsData[market.value] = marketData;
630
+ markets.aaveV2MarketsData[market.value] = yield (0, aaveV2_1._getAaveV2MarketsData)(client, network, market);
183
631
  })),
184
632
  ...compoundV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
185
- const marketData = yield (0, compoundV2_1._getCompoundV2MarketsData)(client, network);
186
- compoundV2MarketsData[market.value] = marketData;
633
+ markets.compoundV2MarketsData[market.value] = yield (0, compoundV2_1._getCompoundV2MarketsData)(client, network);
187
634
  })),
188
635
  ...crvUsdMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
189
- const marketData = yield (0, curveUsd_1._getCurveUsdGlobalData)(client, network, market);
190
- crvUsdMarketsData[market.value] = marketData;
636
+ markets.crvUsdMarketsData[market.value] = yield (0, curveUsd_1._getCurveUsdGlobalData)(client, network, market);
191
637
  })),
192
638
  ...llamaLendMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
193
- const marketData = yield (0, llamaLend_1._getLlamaLendGlobalData)(client, network, market);
194
- llamaLendMarketsData[market.value] = marketData;
639
+ markets.llamaLendMarketsData[market.value] = yield (0, llamaLend_1._getLlamaLendGlobalData)(client, network, market);
195
640
  })),
196
641
  ...liquityV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
197
- const marketData = yield (0, liquityV2_1._getLiquityV2MarketData)(client, network, market);
198
- liquityV2MarketsData[market.value] = marketData;
642
+ markets.liquityV2MarketsData[market.value] = yield (0, liquityV2_1._getLiquityV2MarketData)(client, network, market);
199
643
  })),
644
+ (() => __awaiter(this, void 0, void 0, function* () {
645
+ if (!isFluidSupported)
646
+ return;
647
+ try {
648
+ markets.fluidMarketsData = yield (0, fluid_1._getAllFluidMarketDataPortfolio)(client, network);
649
+ }
650
+ catch (error) {
651
+ console.error('Error fetching Fluid markets data:', error);
652
+ }
653
+ }))(),
654
+ (() => __awaiter(this, void 0, void 0, function* () {
655
+ if (!isMainnet)
656
+ return; // Maker CDPs are only available on mainnet
657
+ try {
658
+ markets.makerMarketsData = yield (0, maker_1._getMakerIlksData)(client, network, markets_1.MakerActiveIlks);
659
+ }
660
+ catch (error) {
661
+ console.error('Error fetching Maker ilks data:', error);
662
+ }
663
+ }))(),
200
664
  // === INDEPENDENT USER DATA (doesn't depend on market data) ===
201
665
  ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
202
666
  if (!isMainnet)
@@ -223,225 +687,22 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
223
687
  };
224
688
  }
225
689
  })),
226
- // === STAKING DATA (independent of market data) ===
227
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
228
- try {
229
- if (!isFluidSupported)
230
- return;
231
- stakingPositions[address.toLowerCase()].fluid = yield (0, fluid_1._getAllUserEarnPositionsWithFTokens)(client, network, address);
232
- }
233
- catch (error) {
234
- console.error(`Error fetching Fluid lend data for address ${address}:`, error);
235
- stakingPositions[address.toLowerCase()].fluid = { error: `Error fetching Fluid lend data for address ${address}`, data: null };
236
- }
237
- })),
238
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
239
- try {
240
- if (!isMainnet)
241
- return;
242
- stakingPositions[address.toLowerCase()].liquity = yield (0, liquity_1.getLiquityStakingData)(client, network, address);
243
- }
244
- catch (error) {
245
- console.error(`Error fetching Liquity staking data for address ${address}:`, error);
246
- stakingPositions[address.toLowerCase()].liquity = { error: `Error fetching Liquity staking data for address ${address}`, data: null };
247
- }
248
- })),
249
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
250
- try {
251
- if (!isMainnet)
252
- return;
253
- stakingPositions[address.toLowerCase()].aaveV3 = yield (0, aaveV3_1.getStakeAaveData)(client, network, address);
254
- }
255
- catch (error) {
256
- console.error(`Error fetching Aave V3 staking data for address ${address}:`, error);
257
- stakingPositions[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 staking data for address ${address}`, data: null };
258
- }
259
- })),
260
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
261
- try {
262
- if (!isMainnet)
263
- return;
264
- stakingPositions[address.toLowerCase()].umbrella = yield (0, umbrella_1.getUmbrellaData)(client, network, address);
265
- }
266
- catch (error) {
267
- console.error(`Error fetching Umbrella staking data for address ${address}:`, error);
268
- stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
269
- }
270
- })),
271
- // Liquity V2 staking
272
- ...liquityV2MarketsStaking.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
273
- try {
274
- if (!isMainnet) {
275
- stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
276
- return;
277
- }
278
- const liquityV2StakingData = yield (0, liquityV2_1.getLiquityV2Staking)(client, network, market.value, address);
279
- stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: liquityV2StakingData };
280
- }
281
- catch (error) {
282
- console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
283
- stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
284
- }
285
- }))).flat(),
286
- // === REWARDS DATA (independent of market data) ===
287
- // Batch King rewards
288
- (() => __awaiter(this, void 0, void 0, function* () {
289
- try {
290
- if (!isMainnet) {
291
- for (const address of addresses) {
292
- rewardsData[address.toLowerCase()].king = { error: '', data: [] };
293
- }
294
- return;
295
- }
296
- const kingRewards = yield (0, king_1.getKingRewards)(client, network, addresses);
297
- for (const address of addresses) {
298
- const lowerAddress = address.toLowerCase();
299
- rewardsData[lowerAddress].king = {
300
- error: '',
301
- data: kingRewards[lowerAddress] || [],
302
- };
303
- }
304
- }
305
- catch (error) {
306
- console.error('Error fetching King rewards data in batch:', error);
307
- for (const address of addresses) {
308
- rewardsData[address.toLowerCase()].king = {
309
- error: 'Error fetching King rewards data in batch',
310
- data: null,
311
- };
312
- }
313
- }
314
- }))(),
315
- // Batch UNI rewards
316
- (() => __awaiter(this, void 0, void 0, function* () {
317
- try {
318
- if (!isMainnet) {
319
- for (const address of addresses) {
320
- rewardsData[address.toLowerCase()].uniswap = { error: '', data: [] };
321
- }
322
- return;
323
- }
324
- const uniswapRewards = yield (0, uniswap_1.getUniswapRewards)(client, network, addresses);
325
- for (const address of addresses) {
326
- const lowerAddress = address.toLowerCase();
327
- rewardsData[lowerAddress].uniswap = {
328
- error: '',
329
- data: uniswapRewards[lowerAddress] || [],
330
- };
331
- }
332
- }
333
- catch (error) {
334
- console.error('Error fetching Uniswap rewards data in batch:', error);
335
- for (const address of addresses) {
336
- rewardsData[address.toLowerCase()].uniswap = {
337
- error: 'Error fetching Uniswap rewards data in batch',
338
- data: null,
339
- };
340
- }
341
- }
342
- }))(),
343
- ...sparkMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
344
- try {
345
- if (!isMainnet) {
346
- rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: [] };
347
- return;
348
- }
349
- const sparkData = yield (0, spark_2.fetchSparkRewards)(client, network, address, market.providerAddress);
350
- rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: sparkData };
351
- }
352
- catch (error) {
353
- console.error(`Error fetching Spark rewards data for address ${address}, market ${market.value}:`, error);
354
- rewardsData[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark rewards data for address ${address}`, data: null };
355
- }
356
- }))).flat(),
357
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
358
- try {
359
- const merklData = yield (0, aaveV3_2.getMerklUnclaimedRewards)(address, network);
360
- rewardsData[address.toLowerCase()].merkl = { error: '', data: merklData };
361
- }
362
- catch (error) {
363
- console.error(`Error fetching Merkl rewards data for address ${address}:`, error);
364
- rewardsData[address.toLowerCase()].merkl = { error: `Error fetching Merkl rewards data for address ${address}`, data: null };
365
- }
366
- })),
367
- ...aaveV3Markets.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
368
- try {
369
- const aaveData = yield (0, aaveV3_2.getUnclaimedRewardsForAllMarkets)(client, network, address, market.providerAddress);
370
- rewardsData[address.toLowerCase()].aaveV3[market.value] = { error: '', data: aaveData };
371
- }
372
- catch (error) {
373
- console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
374
- rewardsData[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
375
- }
376
- }))).flat(),
377
- // Batch Spark Airdrop rewards
378
- (() => __awaiter(this, void 0, void 0, function* () {
379
- try {
380
- if (!isMainnet) {
381
- for (const address of addresses) {
382
- rewardsData[address.toLowerCase()].spk = { error: '', data: [] };
383
- }
384
- return;
385
- }
386
- const sparkAirdropRewards = yield (0, spark_2.fetchSparkAirdropRewards)(client, network, addresses);
387
- for (const address of addresses) {
388
- const lowerAddress = address.toLowerCase();
389
- rewardsData[lowerAddress].spk = {
390
- error: '',
391
- data: sparkAirdropRewards[lowerAddress] || [],
392
- };
393
- }
394
- }
395
- catch (error) {
396
- console.error('Error fetching Spark Airdrop rewards data in batch:', error);
397
- for (const address of addresses) {
398
- rewardsData[address.toLowerCase()].spk = {
399
- error: 'Error fetching Spark Airdrop rewards data in batch',
400
- data: null,
401
- };
402
- }
403
- }
404
- }))(),
405
- (() => __awaiter(this, void 0, void 0, function* () {
406
- try {
407
- if (!isMainnet) {
408
- return;
409
- }
410
- const ethenaAirdropRewards = yield (0, ethena_1.fetchEthenaAirdropRewards)(addresses);
411
- for (const address of addresses) {
412
- const lowerAddress = address.toLowerCase();
413
- rewardsData[lowerAddress].ethena = {
414
- error: '',
415
- data: ethenaAirdropRewards[lowerAddress] || [],
416
- };
417
- }
418
- }
419
- catch (error) {
420
- console.error('Error fetching Ethena Airdrop rewards data:', error);
421
- for (const address of addresses) {
422
- rewardsData[address.toLowerCase()].ethena = {
423
- error: 'Error fetching Ethena Airdrop rewards data in batch',
424
- data: null,
425
- };
426
- }
427
- }
428
- }))(),
429
690
  ]);
430
691
  yield Promise.all([
431
- ...aaveV3Markets.map((market) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
692
+ ...aaveV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
432
693
  try {
433
- const accData = yield (0, aaveV3_1._getAaveV3AccountData)(client, network, address, Object.assign({ selectedMarket: market }, aaveV3MarketsData[market.value]));
434
- if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
435
- positions[address.toLowerCase()].aaveV3[market.value] = { error: '', data: accData };
694
+ const accData = yield (0, aaveV3_1._getAaveV3AccountData)(client, network, address, Object.assign({ selectedMarket: market }, markets.aaveV3MarketsData[market.value]));
695
+ // Always store the position (even with no supply) so the eMode category is available to the shifter
696
+ positions[address.toLowerCase()].aaveV3[market.value] = { error: '', data: accData };
436
697
  }
437
698
  catch (error) {
438
699
  console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
439
700
  positions[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
440
701
  }
441
702
  }))).flat(),
442
- ...aaveV4Spokes.map((spoke) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
703
+ ...aaveV4Spokes.map((spoke) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
443
704
  try {
444
- const accData = yield (0, aaveV4_1._getAaveV4AccountData)(client, network, aaveV4SpokesData[spoke.value], address);
705
+ const accData = yield (0, aaveV4_1._getAaveV4AccountData)(client, network, markets.aaveV4SpokesData[spoke.value], address);
445
706
  if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
446
707
  positions[address.toLowerCase()].aaveV4[spoke.value] = { error: '', data: accData };
447
708
  }
@@ -452,56 +713,18 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
452
713
  }))).flat(),
453
714
  ...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
454
715
  try {
455
- const [accDataPromise, earnDataPromise] = yield Promise.allSettled([
456
- (0, morphoBlue_1._getMorphoBlueAccountData)(client, network, address, market, morphoMarketsData[market.value]),
457
- (0, morphoBlue_1.getMorphoEarn)(client, network, address, market, morphoMarketsData[market.value]),
458
- ]);
459
- if (accDataPromise.status === 'rejected') {
460
- console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, accDataPromise.reason);
461
- positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
462
- }
463
- if (earnDataPromise.status === 'rejected') {
464
- console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, earnDataPromise.reason);
465
- positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
466
- }
467
- if (accDataPromise.status !== 'rejected') {
468
- const accData = accDataPromise.value;
469
- if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
470
- positions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: accData };
471
- }
472
- if (earnDataPromise.status !== 'rejected') {
473
- const earnData = earnDataPromise.value;
474
- if (earnData && new decimal_js_1.default(earnData.amount).gt(0)) {
475
- stakingPositions[address.toLowerCase()].morphoBlue[market.value] = {
476
- error: '',
477
- data: earnData,
478
- };
479
- }
480
- }
716
+ const accData = yield (0, morphoBlue_1._getMorphoBlueAccountData)(client, network, address, market, markets.morphoMarketsData[market.value]);
717
+ if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
718
+ positions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: accData };
481
719
  }
482
720
  catch (error) {
483
721
  console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
484
722
  positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
485
723
  }
486
724
  }))).flat(),
487
- ...morphoMidnightMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
488
- var _a;
489
- try {
490
- // Markets are created lazily on the first position, so an uncreated one can hold no position.
491
- if (!((_a = morphoMidnightMarketsData[market.value]) === null || _a === void 0 ? void 0 : _a.isCreated))
492
- return;
493
- const accData = yield (0, morphoMidnight_1._getMorphoMidnightAccountData)(client, network, address, market, morphoMidnightMarketsData[market.value]);
494
- if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
495
- positions[address.toLowerCase()].morphoMidnight[market.value] = { error: '', data: accData };
496
- }
497
- catch (error) {
498
- console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, error);
499
- positions[address.toLowerCase()].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
500
- }
501
- }))).flat(),
502
725
  ...compoundV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
503
726
  try {
504
- const accData = yield (0, compoundV3_1._getCompoundV3AccountData)(client, network, address, constants_1.ZERO_ADDRESS, { selectedMarket: market, assetsData: compoundV3MarketsData[market.value].assetsData });
727
+ const accData = yield (0, compoundV3_1._getCompoundV3AccountData)(client, network, address, constants_1.ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData });
505
728
  if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
506
729
  positions[address.toLowerCase()].compoundV3[market.value] = { error: '', data: accData };
507
730
  }
@@ -510,37 +733,33 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
510
733
  positions[address.toLowerCase()].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
511
734
  }
512
735
  }))).flat(),
513
- ...sparkMarkets.map((market) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
736
+ ...sparkMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
514
737
  try {
515
- const accData = yield (0, spark_1._getSparkAccountData)(client, network, address, { selectedMarket: market, assetsData: sparkMarketsData[market.value].assetsData, eModeCategoriesData: sparkMarketsData[market.value].eModeCategoriesData });
516
- if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
517
- positions[address.toLowerCase()].spark[market.value] = { error: '', data: accData };
738
+ const accData = yield (0, spark_1._getSparkAccountData)(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData });
739
+ // Always store the position (even with no supply) so the eMode category is available to the shifter
740
+ positions[address.toLowerCase()].spark[market.value] = { error: '', data: accData };
518
741
  }
519
742
  catch (error) {
520
743
  console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
521
744
  positions[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
522
745
  }
523
746
  }))).flat(),
524
- // flatMap, not map: each CDP's fetch has to be one of the awaited promises, or getPortfolioData can return
525
- // before a vault's data lands and the vault is missing from the result.
526
- ...addresses.flatMap((address) => {
527
- var _a;
528
- return ((_a = makerCdps[address.toLowerCase()]) !== null && _a !== void 0 ? _a : []).map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
529
- try {
530
- const cdpData = yield (0, maker_1._getMakerCdpData)(client, network, cdpInfo);
531
- if (cdpData) {
532
- positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
533
- }
534
- }
535
- catch (error) {
536
- console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
537
- positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
747
+ ...addresses.map((address) => (makerCdps[address.toLowerCase()] || []).map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
748
+ try {
749
+ // reuse ilk data fetched for the markets payload; ilks outside the active set are fetched on demand
750
+ const cdpData = yield (0, maker_1._getMakerCdpData)(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel]);
751
+ if (cdpData) {
752
+ positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
538
753
  }
539
- }));
540
- }),
754
+ }
755
+ catch (error) {
756
+ console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
757
+ positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
758
+ }
759
+ }))).flat(),
541
760
  ...aaveV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
542
761
  try {
543
- const accData = yield (0, aaveV2_1._getAaveV2AccountData)(client, network, address, aaveV2MarketsData[market.value].assetsData, market);
762
+ const accData = yield (0, aaveV2_1._getAaveV2AccountData)(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market);
544
763
  if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
545
764
  positions[address.toLowerCase()].aaveV2[market.value] = { error: '', data: accData };
546
765
  }
@@ -551,7 +770,7 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
551
770
  }))).flat(),
552
771
  ...compoundV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
553
772
  try {
554
- const accData = yield (0, compoundV2_1._getCompoundV2AccountData)(client, network, address, compoundV2MarketsData[market.value].assetsData);
773
+ const accData = yield (0, compoundV2_1._getCompoundV2AccountData)(client, network, address, markets.compoundV2MarketsData[market.value].assetsData);
555
774
  if (new decimal_js_1.default(accData.suppliedUsd).gt(0))
556
775
  positions[address.toLowerCase()].compoundV2[market.value] = { error: '', data: accData };
557
776
  }
@@ -575,9 +794,9 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
575
794
  })),
576
795
  ...crvUsdMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
577
796
  try {
578
- const accData = yield (0, curveUsd_1._getCurveUsdUserData)(client, network, address, market, crvUsdMarketsData[market.value].activeBand);
797
+ const accData = yield (0, curveUsd_1._getCurveUsdUserData)(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand, markets.crvUsdMarketsData[market.value].borrowRate);
579
798
  if (new decimal_js_1.default(accData.suppliedUsd).gt(0) || new decimal_js_1.default(accData.borrowedUsd).gt(0)) {
580
- positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: crvUsdMarketsData[market.value].borrowRate }) };
799
+ positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: accData };
581
800
  }
582
801
  }
583
802
  catch (error) {
@@ -587,9 +806,9 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
587
806
  }))).flat(),
588
807
  ...llamaLendMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
589
808
  try {
590
- const accData = yield (0, llamaLend_1._getLlamaLendUserData)(client, network, address, market, llamaLendMarketsData[market.value]);
809
+ const accData = yield (0, llamaLend_1._getLlamaLendUserData)(client, network, address, market, markets.llamaLendMarketsData[market.value]);
591
810
  if (new decimal_js_1.default(accData.suppliedUsd).gt(0) || new decimal_js_1.default(accData.borrowedUsd).gt(0)) {
592
- positions[address.toLowerCase()].llamaLend[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: llamaLendMarketsData[market.value].borrowRate }) };
811
+ positions[address.toLowerCase()].llamaLend[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: markets.llamaLendMarketsData[market.value].borrowRate }) };
593
812
  }
594
813
  }
595
814
  catch (error) {
@@ -597,26 +816,9 @@ function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1)
597
816
  positions[address.toLowerCase()].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
598
817
  }
599
818
  }))).flat(),
600
- // liquity sBold/yBold and staking options
601
- ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
602
- try {
603
- if (!isMainnet) {
604
- stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data: null };
605
- return;
606
- }
607
- const data = yield (0, liquityV2_1.getLiquitySAndYBold)(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
608
- stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data };
609
- }
610
- catch (error) {
611
- console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
612
- stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: `Error fetching sBold/yBold data for address ${address}`, data: null };
613
- }
614
- })),
615
819
  ]);
616
820
  return {
617
821
  positions,
618
- stakingPositions,
619
- rewardsData,
620
822
  markets,
621
823
  };
622
824
  });