@defisaver/positions-sdk 2.1.169-portfolio-api-dev → 2.1.169

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 (101) hide show
  1. package/cjs/aaveV3/index.d.ts +12 -2
  2. package/cjs/aaveV3/sgho.d.ts +16 -2
  3. package/cjs/aaveV4/lend.d.ts +43 -2
  4. package/cjs/claiming/aaveV3.d.ts +2 -2
  5. package/cjs/claiming/ethena.d.ts +1 -2
  6. package/cjs/claiming/king.d.ts +1 -2
  7. package/cjs/claiming/spark.d.ts +2 -2
  8. package/cjs/fluid/index.d.ts +49 -5
  9. package/cjs/liquity/index.d.ts +12 -2
  10. package/cjs/liquityV2/index.d.ts +23 -8
  11. package/cjs/liquityV2/index.js +19 -37
  12. package/cjs/markets/morphoBlue/index.d.ts +2 -0
  13. package/cjs/markets/morphoBlue/index.js +18 -1
  14. package/cjs/portfolio/index.d.ts +8 -16
  15. package/cjs/portfolio/index.js +520 -458
  16. package/cjs/savings/index.d.ts +2 -8
  17. package/cjs/savings/index.js +4 -33
  18. package/cjs/types/aave.d.ts +2 -98
  19. package/cjs/types/aaveV4.d.ts +0 -44
  20. package/cjs/types/compound.d.ts +2 -26
  21. package/cjs/types/curveUsd.d.ts +1 -9
  22. package/cjs/types/fluid.d.ts +0 -13
  23. package/cjs/types/index.d.ts +0 -1
  24. package/cjs/types/index.js +0 -1
  25. package/cjs/types/liquity.d.ts +0 -12
  26. package/cjs/types/liquityV2.d.ts +0 -24
  27. package/cjs/types/llamaLend.d.ts +1 -12
  28. package/cjs/types/morphoBlue.d.ts +1 -2
  29. package/cjs/types/morphoBlue.js +1 -0
  30. package/cjs/types/portfolio.d.ts +5 -125
  31. package/cjs/types/savings/index.d.ts +1 -9
  32. package/cjs/types/spark.d.ts +1 -21
  33. package/cjs/umbrella/index.d.ts +3 -2
  34. package/esm/aaveV3/index.d.ts +12 -2
  35. package/esm/aaveV3/sgho.d.ts +16 -2
  36. package/esm/aaveV4/lend.d.ts +43 -2
  37. package/esm/claiming/aaveV3.d.ts +2 -2
  38. package/esm/claiming/aaveV3.js +1 -1
  39. package/esm/claiming/ethena.d.ts +1 -2
  40. package/esm/claiming/king.d.ts +1 -2
  41. package/esm/claiming/spark.d.ts +2 -2
  42. package/esm/claiming/spark.js +1 -1
  43. package/esm/fluid/index.d.ts +49 -5
  44. package/esm/liquity/index.d.ts +12 -2
  45. package/esm/liquityV2/index.d.ts +23 -8
  46. package/esm/liquityV2/index.js +18 -35
  47. package/esm/markets/morphoBlue/index.d.ts +2 -0
  48. package/esm/markets/morphoBlue/index.js +16 -0
  49. package/esm/portfolio/index.d.ts +8 -16
  50. package/esm/portfolio/index.js +522 -458
  51. package/esm/savings/index.d.ts +2 -8
  52. package/esm/savings/index.js +3 -31
  53. package/esm/types/aave.d.ts +2 -98
  54. package/esm/types/aaveV4.d.ts +0 -44
  55. package/esm/types/compound.d.ts +2 -26
  56. package/esm/types/curveUsd.d.ts +1 -9
  57. package/esm/types/fluid.d.ts +0 -13
  58. package/esm/types/index.d.ts +0 -1
  59. package/esm/types/index.js +0 -1
  60. package/esm/types/liquity.d.ts +0 -12
  61. package/esm/types/liquityV2.d.ts +0 -24
  62. package/esm/types/llamaLend.d.ts +1 -12
  63. package/esm/types/morphoBlue.d.ts +1 -2
  64. package/esm/types/morphoBlue.js +1 -0
  65. package/esm/types/portfolio.d.ts +5 -125
  66. package/esm/types/savings/index.d.ts +1 -9
  67. package/esm/types/spark.d.ts +1 -21
  68. package/esm/umbrella/index.d.ts +3 -2
  69. package/package.json +2 -2
  70. package/src/aaveV3/index.ts +1 -2
  71. package/src/aaveV3/sgho.ts +17 -2
  72. package/src/aaveV4/lend.ts +48 -2
  73. package/src/claiming/aaveV3.ts +2 -4
  74. package/src/claiming/ethena.ts +5 -5
  75. package/src/claiming/king.ts +3 -3
  76. package/src/claiming/spark.ts +4 -6
  77. package/src/fluid/index.ts +3 -4
  78. package/src/liquity/index.ts +2 -2
  79. package/src/liquityV2/index.ts +22 -48
  80. package/src/markets/morphoBlue/index.ts +16 -0
  81. package/src/portfolio/index.ts +331 -306
  82. package/src/savings/index.ts +4 -41
  83. package/src/types/aave.ts +1 -104
  84. package/src/types/aaveV4.ts +0 -49
  85. package/src/types/compound.ts +2 -38
  86. package/src/types/curveUsd.ts +1 -17
  87. package/src/types/fluid.ts +0 -14
  88. package/src/types/index.ts +0 -1
  89. package/src/types/liquity.ts +1 -13
  90. package/src/types/liquityV2.ts +1 -26
  91. package/src/types/llamaLend.ts +1 -19
  92. package/src/types/morphoBlue.ts +1 -3
  93. package/src/types/portfolio.ts +5 -151
  94. package/src/types/savings/index.ts +1 -12
  95. package/src/types/spark.ts +1 -25
  96. package/src/umbrella/index.ts +1 -2
  97. package/cjs/portfolio/lendingProtocols.d.ts +0 -184
  98. package/cjs/portfolio/lendingProtocols.js +0 -196
  99. package/esm/portfolio/lendingProtocols.d.ts +0 -184
  100. package/esm/portfolio/lendingProtocols.js +0 -189
  101. package/src/portfolio/lendingProtocols.ts +0 -281
@@ -9,249 +9,247 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import Dec from 'decimal.js';
11
11
  import { NetworkNumber } from '../types/common';
12
- import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LiquityV2Markets, LlamaLendMarkets, MakerActiveIlks, MorphoBlueMarkets, SparkMarkets, } from '../markets';
12
+ import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LiquityV2Markets, LlamaLendMarkets, MakerActiveIlks, MorphoBlueMarkets, MorphoMidnightMarkets, SparkMarkets, } from '../markets';
13
13
  import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData, getMorphoEarn } from '../morphoBlue';
14
+ import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
14
15
  import { AaveVersions, CompoundVersions, } from '../types';
15
16
  import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
16
17
  import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
17
18
  import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
18
19
  import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
19
20
  import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
20
- import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
21
21
  import { ZERO_ADDRESS } from '../constants';
22
22
  import { _getMakerCdpData, _getMakerIlksData, _getUserCdps } from '../maker';
23
23
  import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
24
24
  import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
25
25
  import { getViemProvider } from '../services/viem';
26
26
  import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
27
- import { _getLiquityV2MarketData, _getLiquityV2TroveData, _getLiquityV2UsersTroveIds, getLiquitySAndYBold, getLiquityV2Staking, } from '../liquityV2';
27
+ import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
28
28
  import { _getAllFluidMarketDataPortfolio, _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
29
29
  import { getUmbrellaData } from '../umbrella';
30
30
  import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
31
31
  import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
32
32
  import { getKingRewards } from '../claiming/king';
33
33
  import { fetchEthenaAirdropRewards } from '../claiming/ethena';
34
+ import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
34
35
  import { getUniswapRewards } from '../claiming/uniswap';
35
- import { aaveV3Lending, LENDING_PROTOCOLS, morphoBlueLending, requireMarket, sparkLending, } from './lendingProtocols';
36
- /** The markets of the protocols read by their own code below; LENDING_PROTOCOLS has the others'. */
37
- const getPortfolioMarkets = (network) => ({
38
- liquityV2Markets: [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [],
39
- liquityV2MarketsStaking: [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [],
40
- });
41
- const getPortfolioClients = (provider, defaultProvider, network, isSim) => {
42
- // batchSize is viem's cap on a batch's raw subcall calldata (bytes); the JSON-RPC body ends up
43
- // ~4x larger (hex + aggregate3 ABI + JSON overhead) and RPC providers reject bodies over
44
- // ~2.5MB with HTTP 413, so keep this small enough that no single body gets near that.
45
- // 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
46
- // (e.g. adding new markets may result in body size going over alchemy body size limit)
47
- const args = [network, { batch: { multicall: { batchSize: isSim ? 2000 : 250000 } } }];
48
- return {
49
- client: getViemProvider(provider, ...args),
50
- defaultClient: getViemProvider(defaultProvider, ...args),
51
- };
52
- };
53
- const _getPortfolioMarketsData = (client, defaultClient, network) => __awaiter(void 0, void 0, void 0, function* () {
54
- const { liquityV2Markets } = getPortfolioMarkets(network);
55
- const markets = {
56
- morphoMarketsData: {},
57
- morphoMidnightMarketsData: {},
58
- compoundV3MarketsData: {},
59
- sparkMarketsData: {},
60
- aaveV3MarketsData: {},
61
- aaveV2MarketsData: {},
62
- compoundV2MarketsData: {},
63
- crvUsdMarketsData: {},
64
- llamaLendMarketsData: {},
65
- liquityV2MarketsData: {},
66
- aaveV4SpokesData: {},
67
- };
68
- const liquityV2Failed = {};
69
- const [lendingFailed] = yield Promise.all([
70
- Promise.all(LENDING_PROTOCOLS.map((protocol) => __awaiter(void 0, void 0, void 0, function* () { return [protocol.marketsKey, yield protocol.readMarkets({ client, defaultClient, network }, markets)]; }))),
71
- // Liquity V2's markets: its troves are read by their own code below.
72
- ...liquityV2Markets.map((market) => __awaiter(void 0, void 0, void 0, function* () {
73
- try {
74
- markets.liquityV2MarketsData[market.value] = yield _getLiquityV2MarketData(client, network, market);
75
- }
76
- catch (error) {
77
- console.error(`Error fetching liquityV2MarketsData for market ${market.value}:`, error);
78
- liquityV2Failed[market.value] = `Error fetching liquityV2MarketsData for market ${market.value}`;
79
- }
80
- })),
81
- ]);
82
- // A market that failed is left out of markets and named here, under its protocol's key.
83
- const errors = {};
84
- for (const [key, failed] of [...lendingFailed, ['liquityV2MarketsData', liquityV2Failed]]) {
85
- if (Object.keys(failed).length)
86
- errors[key] = failed;
87
- }
88
- return { markets, errors };
89
- });
90
- const _getPortfolioUserData = (client, network, addresses, marketsData, isSim, options) => __awaiter(void 0, void 0, void 0, function* () {
91
- const isMainnet = network === NetworkNumber.Eth;
92
- const includePositions = options.positions !== false;
93
- const includeStaking = options.staking !== false;
94
- const includeRewards = options.rewards !== false;
95
- const includeLiquityV2 = includePositions && options.liquityV2 === true;
96
- // The addresses positions, staking, rewards and Liquity V2 troves are read for: none when left out, so their fetches
97
- // below make no calls.
98
- const positionsAddresses = includePositions ? addresses : [];
99
- const stakingAddresses = includeStaking ? addresses : [];
100
- const rewardsAddresses = includeRewards ? addresses : [];
101
- const liquityV2Addresses = includeLiquityV2 ? addresses : [];
102
- const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
103
- const { liquityV2Markets, liquityV2MarketsStaking } = getPortfolioMarkets(network);
104
- const positions = {};
105
- const stakingPositions = {};
106
- const rewardsData = {};
107
- const makerCdpsErrors = {};
108
- for (const address of positionsAddresses) {
109
- positions[address.toLowerCase()] = Object.assign(Object.assign(Object.assign({}, Object.fromEntries(LENDING_PROTOCOLS.map((protocol) => [protocol.key, {}]))), { maker: {}, liquity: {}, fluid: {
110
- error: '',
111
- data: {},
112
- } }), (includeLiquityV2 ? { liquityV2: {} } : {}));
113
- }
114
- // TODO: check default values, probably needed when fetching portfolio on unsupported networks
115
- for (const address of stakingAddresses) {
116
- stakingPositions[address.toLowerCase()] = {
117
- aaveV3: {},
118
- morphoBlue: {},
119
- compoundV3: {},
120
- spark: {},
121
- aaveV2: {},
122
- compoundV2: {},
123
- liquity: {},
124
- liquityV2: {},
125
- fluid: {
126
- error: '',
127
- data: {},
128
- },
129
- // Set by the sBOLD/yBOLD fetch below, whether it succeeds or fails.
130
- liquityV2SBoldYBold: { error: '', data: null },
131
- };
132
- }
133
- for (const address of rewardsAddresses) {
134
- // merkl, spk, king and uniswap are set by their fetches below, whether they succeed or fail.
135
- rewardsData[address.toLowerCase()] = {
136
- merkl: { error: '', data: null },
137
- aaveV3: {},
138
- spark: {},
139
- spk: { error: '', data: null },
140
- king: { error: '', data: null },
141
- ethena: {},
142
- uniswap: { error: '', data: null },
36
+ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
37
+ return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false) {
38
+ const isMainnet = network === NetworkNumber.Eth;
39
+ const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
40
+ const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
41
+ const morphoMidnightMarkets = Object.values(MorphoMidnightMarkets(network)).filter((market) => market.chainIds.includes(network));
42
+ const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
43
+ const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
44
+ const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
45
+ const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
46
+ const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
47
+ const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
48
+ const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
49
+ const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
50
+ const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
51
+ const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
52
+ // batchSize is viem's cap on a batch's raw subcall calldata (bytes); the JSON-RPC body ends up
53
+ // ~4x larger (hex + aggregate3 ABI + JSON overhead) and RPC providers reject bodies over
54
+ // ~2.5MB with HTTP 413, so keep this small enough that no single body gets near that.
55
+ // 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
56
+ // (e.g. adding new markets may result in body size going over alchemy body size limit)
57
+ const args = [network, { batch: { multicall: { batchSize: isSim ? 2000 : 250000 } } }];
58
+ const client = getViemProvider(provider, ...args);
59
+ const defaultClient = getViemProvider(defaultProvider, ...args);
60
+ const morphoMarketsData = {};
61
+ const morphoMidnightMarketsData = {};
62
+ const compoundV3MarketsData = {};
63
+ const sparkMarketsData = {};
64
+ const aaveV3MarketsData = {};
65
+ const makerCdps = {};
66
+ const aaveV2MarketsData = {};
67
+ const compoundV2MarketsData = {};
68
+ const crvUsdMarketsData = {};
69
+ const llamaLendMarketsData = {};
70
+ const liquityV2MarketsData = {};
71
+ const aaveV4SpokesData = {};
72
+ const markets = {
73
+ morphoMarketsData,
74
+ morphoMidnightMarketsData,
75
+ compoundV3MarketsData,
76
+ sparkMarketsData,
77
+ aaveV3MarketsData,
78
+ aaveV2MarketsData,
79
+ compoundV2MarketsData,
80
+ crvUsdMarketsData,
81
+ llamaLendMarketsData,
82
+ liquityV2MarketsData,
83
+ aaveV4SpokesData,
143
84
  };
144
- }
145
- // Everything starts at once; a read that needs a market's data waits for marketsData.
146
- yield Promise.all([
147
- // === POSITIONS THAT DO NOT NEED MARKET DATA ===
148
- // Maker: the address's vault list, then each vault. A failed list is reported in errors.makerCdps: maker stays {},
149
- // which would otherwise read as "no vaults".
150
- ...positionsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
151
- if (!isMainnet)
152
- return; // Maker CDPs are only available on mainnet
153
- let cdps;
154
- try {
155
- cdps = yield _getUserCdps(client, network, address);
156
- }
157
- catch (error) {
158
- console.error(`Error fetching Maker CDPs for address ${address}:`, error);
159
- makerCdpsErrors[address.toLowerCase()] = `Error fetching Maker CDPs for address ${address}`;
160
- return;
161
- }
162
- yield Promise.all(cdps.map((cdpInfo) => __awaiter(void 0, void 0, void 0, function* () {
85
+ const positions = {};
86
+ const stakingPositions = {};
87
+ const rewardsData = {};
88
+ const allAddresses = [...addresses];
89
+ for (const address of allAddresses) {
90
+ positions[address.toLowerCase()] = {
91
+ aaveV3: {},
92
+ aaveV4: {},
93
+ morphoBlue: {},
94
+ morphoMidnight: {},
95
+ compoundV3: {},
96
+ spark: {},
97
+ maker: {},
98
+ aaveV2: {},
99
+ compoundV2: {},
100
+ liquity: {},
101
+ crvUsd: {},
102
+ llamaLend: {},
103
+ fluid: {
104
+ error: '',
105
+ data: {},
106
+ },
107
+ };
108
+ }
109
+ // TODO: check default values, probably needed when fetching portfolio on unsupported networks
110
+ for (const address of addresses) {
111
+ stakingPositions[address.toLowerCase()] = {
112
+ aaveV3: {},
113
+ morphoBlue: {},
114
+ compoundV3: {},
115
+ spark: {},
116
+ aaveV2: {},
117
+ compoundV2: {},
118
+ liquity: {},
119
+ liquityV2: {},
120
+ fluid: {
121
+ error: '',
122
+ data: {},
123
+ },
124
+ };
125
+ rewardsData[address.toLowerCase()] = {
126
+ merkl: {},
127
+ aaveV3: {},
128
+ spark: {},
129
+ spk: {},
130
+ king: {},
131
+ ethena: {},
132
+ };
133
+ }
134
+ yield Promise.allSettled([
135
+ // === MARKET DATA (needs to be fetched first) ===
136
+ ...morphoMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
137
+ const marketData = yield _getMorphoBluePortfolioMarketData(client, network, market);
138
+ morphoMarketsData[market.value] = marketData;
139
+ })),
140
+ ...morphoMidnightMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
141
+ const marketData = yield _getMorphoMidnightMarketData(client, network, market);
142
+ morphoMidnightMarketsData[market.value] = marketData;
143
+ })),
144
+ ...compoundV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
145
+ const marketData = yield _getCompoundV3MarketsData(client, network, market, defaultClient);
146
+ compoundV3MarketsData[market.value] = marketData;
147
+ })),
148
+ ...sparkMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
149
+ const marketData = yield _getSparkMarketsData(client, network, market);
150
+ sparkMarketsData[market.value] = marketData;
151
+ })),
152
+ ...aaveV3Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
153
+ const marketData = yield _getAaveV3MarketData(client, network, market);
154
+ aaveV3MarketsData[market.value] = marketData;
155
+ })),
156
+ ...aaveV4Spokes.map((spoke) => __awaiter(this, void 0, void 0, function* () {
157
+ const spokeData = yield _getAaveV4SpokeData(client, network, spoke);
158
+ aaveV4SpokesData[spoke.value] = spokeData;
159
+ })),
160
+ ...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
161
+ const marketData = yield _getAaveV2MarketsData(client, network, market);
162
+ aaveV2MarketsData[market.value] = marketData;
163
+ })),
164
+ ...compoundV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
165
+ const marketData = yield _getCompoundV2MarketsData(client, network);
166
+ compoundV2MarketsData[market.value] = marketData;
167
+ })),
168
+ ...crvUsdMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
169
+ const marketData = yield _getCurveUsdGlobalData(client, network, market);
170
+ crvUsdMarketsData[market.value] = marketData;
171
+ })),
172
+ ...llamaLendMarkets.map((market) => __awaiter(this, void 0, void 0, function* () {
173
+ const marketData = yield _getLlamaLendGlobalData(client, network, market);
174
+ llamaLendMarketsData[market.value] = marketData;
175
+ })),
176
+ ...liquityV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
177
+ const marketData = yield _getLiquityV2MarketData(client, network, market);
178
+ liquityV2MarketsData[market.value] = marketData;
179
+ })),
180
+ // === INDEPENDENT USER DATA (doesn't depend on market data) ===
181
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
182
+ if (!isMainnet)
183
+ return; // Maker CDPs are only available on mainnet
184
+ const makerCdp = yield _getUserCdps(client, network, address);
185
+ makerCdps[address.toLowerCase()] = makerCdp;
186
+ })),
187
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
163
188
  try {
164
- const cdpData = yield _getMakerCdpData(client, network, cdpInfo);
165
- if (cdpData) {
166
- positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
189
+ if (!isFluidSupported)
190
+ return; // Fluid is not available on Optimism
191
+ const userPositions = (yield _getUserPositionsPortfolio(client, network, address));
192
+ for (const position of userPositions) {
193
+ if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
194
+ positions[address.toLowerCase()].fluid.data[position.userData.nftId] = position.userData;
195
+ }
167
196
  }
168
197
  }
169
198
  catch (error) {
170
- console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
171
- positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
199
+ console.error(`Error fetching Fluid positions for address ${address}:`, error);
200
+ positions[address.toLowerCase()].fluid = {
201
+ error: `Error fetching Fluid positions for address ${address}`,
202
+ data: {},
203
+ };
172
204
  }
173
- })));
174
- })),
175
- ...positionsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
176
- try {
177
- if (!isFluidSupported)
178
- return; // Fluid is not available on Optimism
179
- const userPositions = (yield _getUserPositionsPortfolio(client, network, address));
180
- for (const position of userPositions) {
181
- if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
182
- positions[address.toLowerCase()].fluid.data[position.userData.nftId] = position.userData;
183
- }
205
+ })),
206
+ // === STAKING DATA (independent of market data) ===
207
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
208
+ try {
209
+ if (!isFluidSupported)
210
+ return;
211
+ stakingPositions[address.toLowerCase()].fluid = yield _getAllUserEarnPositionsWithFTokens(client, network, address);
184
212
  }
185
- }
186
- catch (error) {
187
- console.error(`Error fetching Fluid positions for address ${address}:`, error);
188
- positions[address.toLowerCase()].fluid = {
189
- error: `Error fetching Fluid positions for address ${address}`,
190
- data: {},
191
- };
192
- }
193
- })),
194
- ...positionsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
195
- try {
196
- if (!isMainnet)
197
- return; // Liquity trove info is only available on mainnet
198
- const troveInfo = yield _getLiquityTroveInfo(client, network, address);
199
- if (new Dec(troveInfo.collateral).gt(0))
200
- positions[address.toLowerCase()].liquity = { error: '', data: troveInfo };
201
- }
202
- catch (error) {
203
- console.error(`Error fetching Liquity trove info for address ${address}:`, error);
204
- positions[address.toLowerCase()].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
205
- }
206
- })),
207
- // === STAKING DATA (independent of market data; Morpho Earn is with the positions below) ===
208
- ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
209
- try {
210
- if (!isFluidSupported)
211
- return;
212
- stakingPositions[address.toLowerCase()].fluid = yield _getAllUserEarnPositionsWithFTokens(client, network, address);
213
- }
214
- catch (error) {
215
- console.error(`Error fetching Fluid lend data for address ${address}:`, error);
216
- stakingPositions[address.toLowerCase()].fluid = { error: `Error fetching Fluid lend data for address ${address}`, data: null };
217
- }
218
- })),
219
- ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
220
- try {
221
- if (!isMainnet)
222
- return;
223
- stakingPositions[address.toLowerCase()].liquity = yield getLiquityStakingData(client, network, address);
224
- }
225
- catch (error) {
226
- console.error(`Error fetching Liquity staking data for address ${address}:`, error);
227
- stakingPositions[address.toLowerCase()].liquity = { error: `Error fetching Liquity staking data for address ${address}`, data: null };
228
- }
229
- })),
230
- ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
231
- try {
232
- if (!isMainnet)
233
- return;
234
- stakingPositions[address.toLowerCase()].aaveV3 = yield getStakeAaveData(client, network, address);
235
- }
236
- catch (error) {
237
- console.error(`Error fetching Aave V3 staking data for address ${address}:`, error);
238
- stakingPositions[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 staking data for address ${address}`, data: null };
239
- }
240
- })),
241
- ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
242
- try {
243
- if (!isMainnet)
244
- return;
245
- stakingPositions[address.toLowerCase()].umbrella = yield getUmbrellaData(client, network, address);
246
- }
247
- catch (error) {
248
- console.error(`Error fetching Umbrella staking data for address ${address}:`, error);
249
- stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
250
- }
251
- })),
252
- // Liquity V2 stability pools, then sBOLD/yBOLD, which reads them.
253
- ...stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
254
- yield Promise.all(liquityV2MarketsStaking.map((market) => __awaiter(void 0, void 0, void 0, function* () {
213
+ catch (error) {
214
+ console.error(`Error fetching Fluid lend data for address ${address}:`, error);
215
+ stakingPositions[address.toLowerCase()].fluid = { error: `Error fetching Fluid lend data for address ${address}`, data: null };
216
+ }
217
+ })),
218
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
219
+ try {
220
+ if (!isMainnet)
221
+ return;
222
+ stakingPositions[address.toLowerCase()].liquity = yield getLiquityStakingData(client, network, address);
223
+ }
224
+ catch (error) {
225
+ console.error(`Error fetching Liquity staking data for address ${address}:`, error);
226
+ stakingPositions[address.toLowerCase()].liquity = { error: `Error fetching Liquity staking data for address ${address}`, data: null };
227
+ }
228
+ })),
229
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
230
+ try {
231
+ if (!isMainnet)
232
+ return;
233
+ stakingPositions[address.toLowerCase()].aaveV3 = yield getStakeAaveData(client, network, address);
234
+ }
235
+ catch (error) {
236
+ console.error(`Error fetching Aave V3 staking data for address ${address}:`, error);
237
+ stakingPositions[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 staking data for address ${address}`, data: null };
238
+ }
239
+ })),
240
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
241
+ try {
242
+ if (!isMainnet)
243
+ return;
244
+ stakingPositions[address.toLowerCase()].umbrella = yield getUmbrellaData(client, network, address);
245
+ }
246
+ catch (error) {
247
+ console.error(`Error fetching Umbrella staking data for address ${address}:`, error);
248
+ stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
249
+ }
250
+ })),
251
+ // Liquity V2 staking
252
+ ...liquityV2MarketsStaking.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
255
253
  try {
256
254
  if (!isMainnet) {
257
255
  stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
@@ -264,271 +262,337 @@ const _getPortfolioUserData = (client, network, addresses, marketsData, isSim, o
264
262
  console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
265
263
  stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
266
264
  }
267
- })));
268
- try {
269
- if (!isMainnet) {
270
- stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data: null };
271
- return;
265
+ }))).flat(),
266
+ // === REWARDS DATA (independent of market data) ===
267
+ // Batch King rewards
268
+ (() => __awaiter(this, void 0, void 0, function* () {
269
+ try {
270
+ if (!isMainnet) {
271
+ for (const address of addresses) {
272
+ rewardsData[address.toLowerCase()].king = { error: '', data: [] };
273
+ }
274
+ return;
275
+ }
276
+ const kingRewards = yield getKingRewards(client, network, addresses);
277
+ for (const address of addresses) {
278
+ const lowerAddress = address.toLowerCase();
279
+ rewardsData[lowerAddress].king = {
280
+ error: '',
281
+ data: kingRewards[lowerAddress] || [],
282
+ };
283
+ }
272
284
  }
273
- const data = yield getLiquitySAndYBold(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
274
- stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data };
275
- }
276
- catch (error) {
277
- console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
278
- stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: `Error fetching sBold/yBold data for address ${address}`, data: null };
279
- }
280
- })),
281
- // === REWARDS DATA (independent of market data) ===
282
- // Batch King rewards
283
- (() => __awaiter(void 0, void 0, void 0, function* () {
284
- try {
285
- if (!isMainnet) {
286
- for (const address of rewardsAddresses) {
287
- rewardsData[address.toLowerCase()].king = { error: '', data: [] };
285
+ catch (error) {
286
+ console.error('Error fetching King rewards data in batch:', error);
287
+ for (const address of addresses) {
288
+ rewardsData[address.toLowerCase()].king = {
289
+ error: 'Error fetching King rewards data in batch',
290
+ data: null,
291
+ };
288
292
  }
289
- return;
290
293
  }
291
- const kingRewards = yield getKingRewards(client, network, rewardsAddresses);
292
- for (const address of rewardsAddresses) {
293
- const lowerAddress = address.toLowerCase();
294
- rewardsData[lowerAddress].king = {
295
- error: '',
296
- data: kingRewards[lowerAddress] || [],
297
- };
294
+ }))(),
295
+ // Batch UNI rewards
296
+ (() => __awaiter(this, void 0, void 0, function* () {
297
+ try {
298
+ if (!isMainnet) {
299
+ for (const address of addresses) {
300
+ rewardsData[address.toLowerCase()].uniswap = { error: '', data: [] };
301
+ }
302
+ return;
303
+ }
304
+ const uniswapRewards = yield getUniswapRewards(client, network, addresses);
305
+ for (const address of addresses) {
306
+ const lowerAddress = address.toLowerCase();
307
+ rewardsData[lowerAddress].uniswap = {
308
+ error: '',
309
+ data: uniswapRewards[lowerAddress] || [],
310
+ };
311
+ }
298
312
  }
299
- }
300
- catch (error) {
301
- console.error('Error fetching King rewards data in batch:', error);
302
- for (const address of rewardsAddresses) {
303
- rewardsData[address.toLowerCase()].king = {
304
- error: 'Error fetching King rewards data in batch',
305
- data: null,
306
- };
313
+ catch (error) {
314
+ console.error('Error fetching Uniswap rewards data in batch:', error);
315
+ for (const address of addresses) {
316
+ rewardsData[address.toLowerCase()].uniswap = {
317
+ error: 'Error fetching Uniswap rewards data in batch',
318
+ data: null,
319
+ };
320
+ }
307
321
  }
308
- }
309
- }))(),
310
- // Batch UNI rewards
311
- (() => __awaiter(void 0, void 0, void 0, function* () {
312
- try {
313
- if (!isMainnet) {
314
- for (const address of rewardsAddresses) {
315
- rewardsData[address.toLowerCase()].uniswap = { error: '', data: [] };
322
+ }))(),
323
+ ...sparkMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
324
+ try {
325
+ if (!isMainnet) {
326
+ rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: [] };
327
+ return;
316
328
  }
317
- return;
329
+ const sparkData = yield fetchSparkRewards(client, network, address, market.providerAddress);
330
+ rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: sparkData };
318
331
  }
319
- const uniswapRewards = yield getUniswapRewards(client, network, rewardsAddresses);
320
- for (const address of rewardsAddresses) {
321
- const lowerAddress = address.toLowerCase();
322
- rewardsData[lowerAddress].uniswap = {
323
- error: '',
324
- data: uniswapRewards[lowerAddress] || [],
325
- };
332
+ catch (error) {
333
+ console.error(`Error fetching Spark rewards data for address ${address}, market ${market.value}:`, error);
334
+ rewardsData[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark rewards data for address ${address}`, data: null };
326
335
  }
327
- }
328
- catch (error) {
329
- console.error('Error fetching Uniswap rewards data in batch:', error);
330
- for (const address of rewardsAddresses) {
331
- rewardsData[address.toLowerCase()].uniswap = {
332
- error: 'Error fetching Uniswap rewards data in batch',
333
- data: null,
334
- };
336
+ }))).flat(),
337
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
338
+ try {
339
+ const merklData = yield getMerklUnclaimedRewards(address, network);
340
+ rewardsData[address.toLowerCase()].merkl = { error: '', data: merklData };
335
341
  }
336
- }
337
- }))(),
338
- ...sparkLending.markets(network).map((market) => rewardsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
339
- try {
340
- if (!isMainnet) {
341
- rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: [] };
342
- return;
342
+ catch (error) {
343
+ console.error(`Error fetching Merkl rewards data for address ${address}:`, error);
344
+ rewardsData[address.toLowerCase()].merkl = { error: `Error fetching Merkl rewards data for address ${address}`, data: null };
343
345
  }
344
- const sparkData = yield fetchSparkRewards(client, network, address, market.providerAddress);
345
- rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: sparkData };
346
- }
347
- catch (error) {
348
- console.error(`Error fetching Spark rewards data for address ${address}, market ${market.value}:`, error);
349
- rewardsData[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark rewards data for address ${address}`, data: null };
350
- }
351
- }))).flat(),
352
- ...rewardsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
353
- try {
354
- const merklData = yield getMerklUnclaimedRewards(address, network);
355
- rewardsData[address.toLowerCase()].merkl = { error: '', data: merklData };
356
- }
357
- catch (error) {
358
- console.error(`Error fetching Merkl rewards data for address ${address}:`, error);
359
- rewardsData[address.toLowerCase()].merkl = { error: `Error fetching Merkl rewards data for address ${address}`, data: null };
360
- }
361
- })),
362
- ...aaveV3Lending.markets(network).map(market => rewardsAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
363
- try {
364
- const aaveData = yield getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress);
365
- rewardsData[address.toLowerCase()].aaveV3[market.value] = { error: '', data: aaveData };
366
- }
367
- catch (error) {
368
- console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
369
- // This market only: the other markets keep their rewards.
370
- rewardsData[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching Aave V3 rewards data for address ${address} on market ${market.value}`, data: null };
371
- }
372
- }))).flat(),
373
- // Batch Spark Airdrop rewards
374
- (() => __awaiter(void 0, void 0, void 0, function* () {
375
- try {
376
- if (!isMainnet) {
377
- for (const address of rewardsAddresses) {
378
- rewardsData[address.toLowerCase()].spk = { error: '', data: [] };
346
+ })),
347
+ ...aaveV3Markets.map(market => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
348
+ try {
349
+ const aaveData = yield getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress);
350
+ rewardsData[address.toLowerCase()].aaveV3[market.value] = { error: '', data: aaveData };
351
+ }
352
+ catch (error) {
353
+ console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
354
+ rewardsData[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
355
+ }
356
+ }))).flat(),
357
+ // Batch Spark Airdrop rewards
358
+ (() => __awaiter(this, void 0, void 0, function* () {
359
+ try {
360
+ if (!isMainnet) {
361
+ for (const address of addresses) {
362
+ rewardsData[address.toLowerCase()].spk = { error: '', data: [] };
363
+ }
364
+ return;
365
+ }
366
+ const sparkAirdropRewards = yield fetchSparkAirdropRewards(client, network, addresses);
367
+ for (const address of addresses) {
368
+ const lowerAddress = address.toLowerCase();
369
+ rewardsData[lowerAddress].spk = {
370
+ error: '',
371
+ data: sparkAirdropRewards[lowerAddress] || [],
372
+ };
379
373
  }
380
- return;
381
374
  }
382
- const sparkAirdropRewards = yield fetchSparkAirdropRewards(client, network, rewardsAddresses);
383
- for (const address of rewardsAddresses) {
384
- const lowerAddress = address.toLowerCase();
385
- rewardsData[lowerAddress].spk = {
386
- error: '',
387
- data: sparkAirdropRewards[lowerAddress] || [],
388
- };
375
+ catch (error) {
376
+ console.error('Error fetching Spark Airdrop rewards data in batch:', error);
377
+ for (const address of addresses) {
378
+ rewardsData[address.toLowerCase()].spk = {
379
+ error: 'Error fetching Spark Airdrop rewards data in batch',
380
+ data: null,
381
+ };
382
+ }
389
383
  }
390
- }
391
- catch (error) {
392
- console.error('Error fetching Spark Airdrop rewards data in batch:', error);
393
- for (const address of rewardsAddresses) {
394
- rewardsData[address.toLowerCase()].spk = {
395
- error: 'Error fetching Spark Airdrop rewards data in batch',
396
- data: null,
397
- };
384
+ }))(),
385
+ (() => __awaiter(this, void 0, void 0, function* () {
386
+ try {
387
+ if (!isMainnet) {
388
+ return;
389
+ }
390
+ const ethenaAirdropRewards = yield fetchEthenaAirdropRewards(addresses);
391
+ for (const address of addresses) {
392
+ const lowerAddress = address.toLowerCase();
393
+ rewardsData[lowerAddress].ethena = {
394
+ error: '',
395
+ data: ethenaAirdropRewards[lowerAddress] || [],
396
+ };
397
+ }
398
398
  }
399
- }
400
- }))(),
401
- (() => __awaiter(void 0, void 0, void 0, function* () {
402
- try {
403
- if (!isMainnet) {
404
- return;
399
+ catch (error) {
400
+ console.error('Error fetching Ethena Airdrop rewards data:', error);
401
+ for (const address of addresses) {
402
+ rewardsData[address.toLowerCase()].ethena = {
403
+ error: 'Error fetching Ethena Airdrop rewards data in batch',
404
+ data: null,
405
+ };
406
+ }
405
407
  }
406
- const ethenaAirdropRewards = yield fetchEthenaAirdropRewards(rewardsAddresses);
407
- for (const address of rewardsAddresses) {
408
- const lowerAddress = address.toLowerCase();
409
- rewardsData[lowerAddress].ethena = {
410
- error: '',
411
- data: ethenaAirdropRewards[lowerAddress] || [],
412
- };
408
+ }))(),
409
+ ]);
410
+ yield Promise.all([
411
+ ...aaveV3Markets.map((market) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
412
+ try {
413
+ const accData = yield _getAaveV3AccountData(client, network, address, Object.assign({ selectedMarket: market }, aaveV3MarketsData[market.value]));
414
+ if (new Dec(accData.suppliedUsd).gt(0))
415
+ positions[address.toLowerCase()].aaveV3[market.value] = { error: '', data: accData };
413
416
  }
414
- }
415
- catch (error) {
416
- console.error('Error fetching Ethena Airdrop rewards data:', error);
417
- for (const address of rewardsAddresses) {
418
- rewardsData[address.toLowerCase()].ethena = {
419
- error: 'Error fetching Ethena Airdrop rewards data in batch',
420
- data: null,
421
- };
417
+ catch (error) {
418
+ console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
419
+ positions[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
422
420
  }
423
- }
424
- }))(),
425
- // === POSITIONS ON MARKETS (each waits for its market's data) ===
426
- ...LENDING_PROTOCOLS.flatMap((protocol) => protocol.readPositions({ client, network }, positionsAddresses, marketsData, positions)),
427
- // Morpho Blue Earn: a supply without a borrow, kept as staking, read on the same markets as Morpho Blue's positions.
428
- ...morphoBlueLending.markets(network).flatMap((market) => stakingAddresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
429
- try {
430
- const marketData = requireMarket((yield marketsData).morphoMarketsData, market.value);
431
- const earnData = yield getMorphoEarn(client, network, address, market, marketData);
432
- if (earnData && new Dec(earnData.amount).gt(0)) {
433
- stakingPositions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: earnData };
434
- }
435
- }
436
- catch (error) {
437
- console.error(`Error fetching MorphoBlue earn data for address ${address} on market ${market.value}:`, error);
438
- stakingPositions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue earn data for address ${address} on market ${market.value}`, data: null };
439
- }
440
- }))),
441
- // Liquity V2 troves: one market's trove ids for every address at once, then each trove's data. A failure is the
442
- // market's error; the troves that did load stay in its data.
443
- ...(liquityV2Addresses.length ? liquityV2Markets : []).map((market) => __awaiter(void 0, void 0, void 0, function* () {
444
- const setEntry = (address, entry) => {
445
- positions[address.toLowerCase()].liquityV2[market.value] = entry;
446
- };
447
- const failAll = (error) => liquityV2Addresses.forEach((address) => setEntry(address, { error, data: {} }));
448
- const allMarketsData = (yield marketsData).liquityV2MarketsData;
449
- const marketData = allMarketsData[market.value];
450
- if (!marketData) {
451
- failAll(`Error fetching Liquity V2 market data for market ${market.value}`);
452
- return;
453
- }
454
- let troveIds;
455
- try {
456
- troveIds = yield _getLiquityV2UsersTroveIds(client, network, market, marketData.marketData.troveNFTAddress, isSim, liquityV2Addresses);
457
- }
458
- catch (error) {
459
- console.error(`Error fetching Liquity V2 trove ids on market ${market.value}:`, error);
460
- failAll(`Error fetching Liquity V2 troves on market ${market.value}`);
461
- return;
462
- }
463
- yield Promise.all(liquityV2Addresses.map((address) => __awaiter(void 0, void 0, void 0, function* () {
421
+ }))).flat(),
422
+ ...aaveV4Spokes.map((spoke) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
423
+ try {
424
+ const accData = yield _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
425
+ if (new Dec(accData.suppliedUsd).gt(0))
426
+ positions[address.toLowerCase()].aaveV4[spoke.value] = { error: '', data: accData };
427
+ }
428
+ catch (error) {
429
+ console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
430
+ positions[address.toLowerCase()].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
431
+ }
432
+ }))).flat(),
433
+ ...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
434
+ try {
435
+ const [accDataPromise, earnDataPromise] = yield Promise.allSettled([
436
+ _getMorphoBlueAccountData(client, network, address, market, morphoMarketsData[market.value]),
437
+ getMorphoEarn(client, network, address, market, morphoMarketsData[market.value]),
438
+ ]);
439
+ if (accDataPromise.status === 'rejected') {
440
+ console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, accDataPromise.reason);
441
+ positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
442
+ }
443
+ if (earnDataPromise.status === 'rejected') {
444
+ console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, earnDataPromise.reason);
445
+ positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
446
+ }
447
+ if (accDataPromise.status !== 'rejected') {
448
+ const accData = accDataPromise.value;
449
+ if (new Dec(accData.suppliedUsd).gt(0))
450
+ positions[address.toLowerCase()].morphoBlue[market.value] = { error: '', data: accData };
451
+ }
452
+ if (earnDataPromise.status !== 'rejected') {
453
+ const earnData = earnDataPromise.value;
454
+ if (earnData && new Dec(earnData.amount).gt(0)) {
455
+ stakingPositions[address.toLowerCase()].morphoBlue[market.value] = {
456
+ error: '',
457
+ data: earnData,
458
+ };
459
+ }
460
+ }
461
+ }
462
+ catch (error) {
463
+ console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
464
+ positions[address.toLowerCase()].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
465
+ }
466
+ }))).flat(),
467
+ ...morphoMidnightMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
464
468
  var _a;
465
- const entry = { error: '', data: {} };
466
- const failed = [];
467
- yield Promise.all(((_a = troveIds[address]) !== null && _a !== void 0 ? _a : []).map((troveId) => __awaiter(void 0, void 0, void 0, function* () {
468
- try {
469
- entry.data[troveId] = yield _getLiquityV2TroveData(client, network, {
470
- selectedMarket: market,
471
- assetsData: marketData.assetsData,
472
- troveId,
473
- allMarketsData: allMarketsData,
474
- });
469
+ try {
470
+ // Markets are created lazily on the first position, so an uncreated one can hold no position.
471
+ if (!((_a = morphoMidnightMarketsData[market.value]) === null || _a === void 0 ? void 0 : _a.isCreated))
472
+ return;
473
+ const accData = yield _getMorphoMidnightAccountData(client, network, address, market, morphoMidnightMarketsData[market.value]);
474
+ if (new Dec(accData.suppliedUsd).gt(0))
475
+ positions[address.toLowerCase()].morphoMidnight[market.value] = { error: '', data: accData };
476
+ }
477
+ catch (error) {
478
+ console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, error);
479
+ positions[address.toLowerCase()].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
480
+ }
481
+ }))).flat(),
482
+ ...compoundV3Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
483
+ try {
484
+ const accData = yield _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: compoundV3MarketsData[market.value].assetsData });
485
+ if (new Dec(accData.suppliedUsd).gt(0))
486
+ positions[address.toLowerCase()].compoundV3[market.value] = { error: '', data: accData };
487
+ }
488
+ catch (error) {
489
+ console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
490
+ positions[address.toLowerCase()].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
491
+ }
492
+ }))).flat(),
493
+ ...sparkMarkets.map((market) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
494
+ try {
495
+ const accData = yield _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: sparkMarketsData[market.value].assetsData, eModeCategoriesData: sparkMarketsData[market.value].eModeCategoriesData });
496
+ if (new Dec(accData.suppliedUsd).gt(0))
497
+ positions[address.toLowerCase()].spark[market.value] = { error: '', data: accData };
498
+ }
499
+ catch (error) {
500
+ console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
501
+ positions[address.toLowerCase()].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
502
+ }
503
+ }))).flat(),
504
+ ...addresses.map((address) => (makerCdps[address.toLowerCase()] || []).map((cdpInfo) => __awaiter(this, void 0, void 0, function* () {
505
+ try {
506
+ const cdpData = yield _getMakerCdpData(client, network, cdpInfo);
507
+ if (cdpData) {
508
+ positions[address.toLowerCase()].maker[cdpInfo.id] = { error: '', data: cdpData };
509
+ }
510
+ }
511
+ catch (error) {
512
+ console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
513
+ positions[address.toLowerCase()].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
514
+ }
515
+ }))).flat(),
516
+ ...aaveV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
517
+ try {
518
+ const accData = yield _getAaveV2AccountData(client, network, address, aaveV2MarketsData[market.value].assetsData, market);
519
+ if (new Dec(accData.suppliedUsd).gt(0))
520
+ positions[address.toLowerCase()].aaveV2[market.value] = { error: '', data: accData };
521
+ }
522
+ catch (error) {
523
+ console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
524
+ positions[address.toLowerCase()].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
525
+ }
526
+ }))).flat(),
527
+ ...compoundV2Markets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
528
+ try {
529
+ const accData = yield _getCompoundV2AccountData(client, network, address, compoundV2MarketsData[market.value].assetsData);
530
+ if (new Dec(accData.suppliedUsd).gt(0))
531
+ positions[address.toLowerCase()].compoundV2[market.value] = { error: '', data: accData };
532
+ }
533
+ catch (error) {
534
+ console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
535
+ positions[address.toLowerCase()].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
536
+ }
537
+ }))).flat(),
538
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
539
+ try {
540
+ if (!isMainnet)
541
+ return; // Liquity trove info is only available on mainnet
542
+ const troveInfo = yield _getLiquityTroveInfo(client, network, address);
543
+ if (new Dec(troveInfo.collateral).gt(0))
544
+ positions[address.toLowerCase()].liquity = { error: '', data: troveInfo };
545
+ }
546
+ catch (error) {
547
+ console.error(`Error fetching Liquity trove info for address ${address}:`, error);
548
+ positions[address.toLowerCase()].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
549
+ }
550
+ })),
551
+ ...crvUsdMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
552
+ try {
553
+ const accData = yield _getCurveUsdUserData(client, network, address, market, crvUsdMarketsData[market.value].activeBand, crvUsdMarketsData[market.value].borrowRate);
554
+ if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
555
+ positions[address.toLowerCase()].crvUsd[market.value] = { error: '', data: accData };
556
+ }
557
+ }
558
+ catch (error) {
559
+ console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
560
+ positions[address.toLowerCase()].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
561
+ }
562
+ }))).flat(),
563
+ ...llamaLendMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
564
+ try {
565
+ const accData = yield _getLlamaLendUserData(client, network, address, market, llamaLendMarketsData[market.value]);
566
+ if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
567
+ positions[address.toLowerCase()].llamaLend[market.value] = { error: '', data: Object.assign(Object.assign({}, accData), { borrowRate: llamaLendMarketsData[market.value].borrowRate }) };
475
568
  }
476
- catch (error) {
477
- console.error(`Error fetching Liquity V2 trove ${troveId} for address ${address} on market ${market.value}:`, error);
478
- failed.push(troveId);
569
+ }
570
+ catch (error) {
571
+ console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
572
+ positions[address.toLowerCase()].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
573
+ }
574
+ }))).flat(),
575
+ // liquity sBold/yBold and staking options
576
+ ...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
577
+ try {
578
+ if (!isMainnet) {
579
+ stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data: null };
580
+ return;
479
581
  }
480
- })));
481
- if (failed.length)
482
- entry.error = `Error fetching Liquity V2 troves ${failed.join(', ')} for address ${address} on market ${market.value}`;
483
- setEntry(address, entry);
484
- })));
485
- })),
486
- ]);
487
- return {
488
- positions,
489
- stakingPositions,
490
- rewardsData,
491
- errors: Object.keys(makerCdpsErrors).length ? { makerCdps: makerCdpsErrors } : {},
492
- };
493
- });
494
- /**
495
- * Every market the portfolio reads on a network — the markets half of getPortfolioData, for a caller that keeps
496
- * markets apart from what it reads per address (a cache shared by many addresses). A market that fails is left out
497
- * of `markets` and named in `errors`.
498
- */
499
- export function getPortfolioMarketsData(provider_1, network_1, defaultProvider_1) {
500
- return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, isSim = false) {
501
- const { client, defaultClient } = getPortfolioClients(provider, defaultProvider, network, isSim);
502
- return _getPortfolioMarketsData(client, defaultClient, network);
503
- });
504
- }
505
- /**
506
- * What the portfolio reads per address — the other half of getPortfolioData — against `markets` from
507
- * getPortfolioMarketsData. `markets` can be a promise: reads that do not need a market (Maker, Fluid, Liquity, staking,
508
- * rewards) start at once, and each read on a market waits for it. A position on a market missing from `markets` is an
509
- * entry with an error.
510
- */
511
- export function getPortfolioUserData(provider_1, network_1, addresses_1, markets_1) {
512
- return __awaiter(this, arguments, void 0, function* (provider, network, addresses, markets, isSim = false, options = {}) {
513
- const { client } = getPortfolioClients(provider, provider, network, isSim);
514
- return _getPortfolioUserData(client, network, addresses, Promise.resolve(markets), isSim, options);
515
- });
516
- }
517
- export function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
518
- return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false, options = {}) {
519
- // One pair of clients for both halves, so their calls batch together.
520
- const { client, defaultClient } = getPortfolioClients(provider, defaultProvider, network, isSim);
521
- const marketsResult = _getPortfolioMarketsData(client, defaultClient, network);
522
- const [{ markets, errors: marketsErrors }, userData] = yield Promise.all([
523
- marketsResult,
524
- _getPortfolioUserData(client, network, addresses, marketsResult.then((result) => result.markets), isSim, options),
582
+ const data = yield getLiquitySAndYBold(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
583
+ stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: '', data };
584
+ }
585
+ catch (error) {
586
+ console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
587
+ stakingPositions[address.toLowerCase()].liquityV2SBoldYBold = { error: `Error fetching sBold/yBold data for address ${address}`, data: null };
588
+ }
589
+ })),
525
590
  ]);
526
591
  return {
527
- positions: userData.positions,
528
- stakingPositions: userData.stakingPositions,
529
- rewardsData: userData.rewardsData,
592
+ positions,
593
+ stakingPositions,
594
+ rewardsData,
530
595
  markets,
531
- errors: Object.assign(Object.assign({}, (Object.keys(marketsErrors).length ? { markets: marketsErrors } : {})), userData.errors),
532
596
  };
533
597
  });
534
598
  }