@defisaver/positions-sdk 2.1.168-stable-pair-dev → 2.1.169-custom-fetching-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.
- package/cjs/markets/morphoBlue/index.d.ts +2 -0
- package/cjs/markets/morphoBlue/index.js +18 -1
- package/cjs/portfolio/customDeFiData.d.ts +3 -0
- package/cjs/portfolio/customDeFiData.js +262 -0
- package/cjs/portfolio/index.d.ts +1 -0
- package/cjs/portfolio/index.js +15 -851
- package/cjs/types/morphoBlue.d.ts +1 -0
- package/cjs/types/morphoBlue.js +1 -0
- package/cjs/types/portfolio.d.ts +34 -0
- package/cjs/types/portfolio.js +18 -0
- package/esm/markets/morphoBlue/index.d.ts +2 -0
- package/esm/markets/morphoBlue/index.js +16 -0
- package/esm/portfolio/customDeFiData.d.ts +3 -0
- package/esm/portfolio/customDeFiData.js +256 -0
- package/esm/portfolio/index.d.ts +1 -0
- package/esm/portfolio/index.js +16 -849
- package/esm/types/morphoBlue.d.ts +1 -0
- package/esm/types/morphoBlue.js +1 -0
- package/esm/types/portfolio.d.ts +34 -0
- package/esm/types/portfolio.js +17 -1
- package/package.json +2 -2
- package/src/markets/morphoBlue/index.ts +16 -0
- package/src/portfolio/customDeFiData.ts +378 -0
- package/src/portfolio/index.ts +16 -834
- package/src/types/morphoBlue.ts +1 -0
- package/src/types/portfolio.ts +37 -0
package/src/portfolio/index.ts
CHANGED
|
@@ -1,57 +1,6 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
1
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
AaveV4Spokes,
|
|
6
|
-
CompoundMarkets,
|
|
7
|
-
CrvUsdMarkets,
|
|
8
|
-
LiquityV2Markets,
|
|
9
|
-
LlamaLendMarkets,
|
|
10
|
-
MakerActiveIlks,
|
|
11
|
-
MorphoBlueMarkets,
|
|
12
|
-
MorphoMidnightMarkets,
|
|
13
|
-
SparkMarkets,
|
|
14
|
-
} from '../markets';
|
|
15
|
-
import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData, getMorphoEarn } from '../morphoBlue';
|
|
16
|
-
import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
|
|
17
|
-
import {
|
|
18
|
-
AaveV2MarketData,
|
|
19
|
-
AaveV3MarketData,
|
|
20
|
-
AaveV4SpokeData,
|
|
21
|
-
AaveVersions,
|
|
22
|
-
CdpInfo,
|
|
23
|
-
CompoundV2MarketsData,
|
|
24
|
-
CompoundV3MarketsData,
|
|
25
|
-
CompoundVersions,
|
|
26
|
-
CrvUSDGlobalMarketData,
|
|
27
|
-
LiquityV2MarketData,
|
|
28
|
-
LlamaLendGlobalMarketData,
|
|
29
|
-
MorphoBlueMarketInfo,
|
|
30
|
-
MorphoMidnightMarketInfo,
|
|
31
|
-
PortfolioMarketsData,
|
|
32
|
-
PortfolioPositionsData,
|
|
33
|
-
SparkMarketsData,
|
|
34
|
-
} from '../types';
|
|
35
|
-
import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
|
|
36
|
-
import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
|
|
37
|
-
import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
38
|
-
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
39
|
-
import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
|
|
40
|
-
import { ZERO_ADDRESS } from '../constants';
|
|
41
|
-
import { _getMakerCdpData, _getMakerIlksData, _getUserCdps } from '../maker';
|
|
42
|
-
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
43
|
-
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
44
|
-
import { getViemProvider } from '../services/viem';
|
|
45
|
-
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
46
|
-
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
47
|
-
import { _getAllFluidMarketDataPortfolio, _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
48
|
-
import { getUmbrellaData } from '../umbrella';
|
|
49
|
-
import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
50
|
-
import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
51
|
-
import { getKingRewards } from '../claiming/king';
|
|
52
|
-
import { fetchEthenaAirdropRewards } from '../claiming/ethena';
|
|
53
|
-
import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
|
|
54
|
-
import { getUniswapRewards } from '../claiming/uniswap';
|
|
2
|
+
import { PortfolioMarketsData, PortfolioPositionsData, PortfolioProtocol } from '../types';
|
|
3
|
+
import { getCustomDeFiData } from './customDeFiData';
|
|
55
4
|
|
|
56
5
|
export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim = false): Promise<{
|
|
57
6
|
positions: PortfolioPositionsData;
|
|
@@ -59,795 +8,28 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
59
8
|
rewardsData: any;
|
|
60
9
|
markets: any;
|
|
61
10
|
}> {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
|
|
68
|
-
const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
69
|
-
const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
70
|
-
const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
71
|
-
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
72
|
-
const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
73
|
-
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
74
|
-
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
75
|
-
const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
|
|
76
|
-
const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// batchSize is viem's cap on a batch's raw subcall calldata (bytes); the JSON-RPC body ends up
|
|
80
|
-
// ~4x larger (hex + aggregate3 ABI + JSON overhead) and RPC providers reject bodies over
|
|
81
|
-
// ~2.5MB with HTTP 413, so keep this small enough that no single body gets near that.
|
|
82
|
-
// 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
|
|
83
|
-
// (e.g. adding new markets may result in body size going over alchemy body size limit)
|
|
84
|
-
const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 2_000 : 250_000 } } }];
|
|
85
|
-
const client = getViemProvider(provider, ...args);
|
|
86
|
-
const defaultClient = getViemProvider(defaultProvider, ...args);
|
|
87
|
-
|
|
88
|
-
const morphoMarketsData: Record<string, MorphoBlueMarketInfo> = {};
|
|
89
|
-
const morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo> = {};
|
|
90
|
-
const compoundV3MarketsData: Record<string, CompoundV3MarketsData> = {};
|
|
91
|
-
const sparkMarketsData: Record<string, SparkMarketsData> = {};
|
|
92
|
-
const aaveV3MarketsData: Record<string, AaveV3MarketData> = {};
|
|
93
|
-
const makerCdps: Record<string, CdpInfo[]> = {};
|
|
94
|
-
const aaveV2MarketsData: Record<string, AaveV2MarketData> = {};
|
|
95
|
-
const compoundV2MarketsData: Record<string, CompoundV2MarketsData> = {};
|
|
96
|
-
const crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData> = {};
|
|
97
|
-
const llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData> = {};
|
|
98
|
-
const liquityV2MarketsData: Record<string, LiquityV2MarketData> = {};
|
|
99
|
-
const aaveV4SpokesData: Record<string, AaveV4SpokeData> = {};
|
|
100
|
-
|
|
101
|
-
const markets = {
|
|
102
|
-
morphoMarketsData,
|
|
103
|
-
morphoMidnightMarketsData,
|
|
104
|
-
compoundV3MarketsData,
|
|
105
|
-
sparkMarketsData,
|
|
106
|
-
aaveV3MarketsData,
|
|
107
|
-
aaveV2MarketsData,
|
|
108
|
-
compoundV2MarketsData,
|
|
109
|
-
crvUsdMarketsData,
|
|
110
|
-
llamaLendMarketsData,
|
|
111
|
-
liquityV2MarketsData,
|
|
112
|
-
aaveV4SpokesData,
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const positions: PortfolioPositionsData = {};
|
|
116
|
-
const stakingPositions: any = {};
|
|
117
|
-
const rewardsData: any = {};
|
|
118
|
-
const allAddresses = [...addresses];
|
|
119
|
-
|
|
120
|
-
for (const address of allAddresses) {
|
|
121
|
-
positions[address.toLowerCase() as EthAddress] = {
|
|
122
|
-
aaveV3: {},
|
|
123
|
-
aaveV4: {},
|
|
124
|
-
morphoBlue: {},
|
|
125
|
-
morphoMidnight: {},
|
|
126
|
-
compoundV3: {},
|
|
127
|
-
spark: {},
|
|
128
|
-
maker: {},
|
|
129
|
-
aaveV2: {},
|
|
130
|
-
compoundV2: {},
|
|
131
|
-
liquity: {},
|
|
132
|
-
crvUsd: {},
|
|
133
|
-
llamaLend: {},
|
|
134
|
-
fluid: {
|
|
135
|
-
error: '',
|
|
136
|
-
data: {},
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// TODO: check default values, probably needed when fetching portfolio on unsupported networks
|
|
142
|
-
for (const address of addresses) {
|
|
143
|
-
stakingPositions[address.toLowerCase() as EthAddress] = {
|
|
144
|
-
aaveV3: {},
|
|
145
|
-
morphoBlue: {},
|
|
146
|
-
compoundV3: {},
|
|
147
|
-
spark: {},
|
|
148
|
-
aaveV2: {},
|
|
149
|
-
compoundV2: {},
|
|
150
|
-
liquity: {},
|
|
151
|
-
liquityV2: {},
|
|
152
|
-
fluid: {
|
|
153
|
-
error: '',
|
|
154
|
-
data: {},
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
rewardsData[address.toLowerCase() as EthAddress] = {
|
|
159
|
-
merkl: {},
|
|
160
|
-
aaveV3: {},
|
|
161
|
-
spark: {},
|
|
162
|
-
spk: {},
|
|
163
|
-
king: {},
|
|
164
|
-
ethena: {},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
await Promise.allSettled([
|
|
169
|
-
// === MARKET DATA (needs to be fetched first) ===
|
|
170
|
-
...morphoMarkets.map(async (market) => {
|
|
171
|
-
const marketData = await _getMorphoBluePortfolioMarketData(client, network, market);
|
|
172
|
-
morphoMarketsData[market.value] = marketData;
|
|
173
|
-
}),
|
|
174
|
-
...morphoMidnightMarkets.map(async (market) => {
|
|
175
|
-
const marketData = await _getMorphoMidnightMarketData(client, network, market);
|
|
176
|
-
morphoMidnightMarketsData[market.value] = marketData;
|
|
177
|
-
}),
|
|
178
|
-
...compoundV3Markets.map(async (market) => {
|
|
179
|
-
const marketData = await _getCompoundV3MarketsData(client, network, market, defaultClient);
|
|
180
|
-
compoundV3MarketsData[market.value] = marketData;
|
|
181
|
-
}),
|
|
182
|
-
...sparkMarkets.map(async (market) => {
|
|
183
|
-
const marketData = await _getSparkMarketsData(client, network, market);
|
|
184
|
-
sparkMarketsData[market.value] = marketData;
|
|
185
|
-
}),
|
|
186
|
-
...aaveV3Markets.map(async (market) => {
|
|
187
|
-
const marketData = await _getAaveV3MarketData(client, network, market);
|
|
188
|
-
aaveV3MarketsData[market.value] = marketData;
|
|
189
|
-
}),
|
|
190
|
-
...aaveV4Spokes.map(async (spoke) => {
|
|
191
|
-
const spokeData = await _getAaveV4SpokeData(client, network, spoke);
|
|
192
|
-
aaveV4SpokesData[spoke.value] = spokeData;
|
|
193
|
-
}),
|
|
194
|
-
...aaveV2Markets.map(async (market) => {
|
|
195
|
-
const marketData = await _getAaveV2MarketsData(client, network, market);
|
|
196
|
-
aaveV2MarketsData[market.value] = marketData;
|
|
197
|
-
}),
|
|
198
|
-
...compoundV2Markets.map(async (market) => {
|
|
199
|
-
const marketData = await _getCompoundV2MarketsData(client, network);
|
|
200
|
-
compoundV2MarketsData[market.value] = marketData;
|
|
201
|
-
}),
|
|
202
|
-
...crvUsdMarkets.map(async (market) => {
|
|
203
|
-
const marketData = await _getCurveUsdGlobalData(client, network, market);
|
|
204
|
-
crvUsdMarketsData[market.value] = marketData;
|
|
205
|
-
}),
|
|
206
|
-
...llamaLendMarkets.map(async (market) => {
|
|
207
|
-
const marketData = await _getLlamaLendGlobalData(client, network, market);
|
|
208
|
-
llamaLendMarketsData[market.value] = marketData;
|
|
209
|
-
}),
|
|
210
|
-
...liquityV2Markets.map(async (market) => {
|
|
211
|
-
const marketData = await _getLiquityV2MarketData(client, network, market);
|
|
212
|
-
liquityV2MarketsData[market.value] = marketData;
|
|
213
|
-
}),
|
|
214
|
-
|
|
215
|
-
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
216
|
-
...addresses.map(async (address) => {
|
|
217
|
-
if (!isMainnet) return; // Maker CDPs are only available on mainnet
|
|
218
|
-
const makerCdp = await _getUserCdps(client, network, address);
|
|
219
|
-
makerCdps[address.toLowerCase() as EthAddress] = makerCdp;
|
|
220
|
-
}),
|
|
221
|
-
...addresses.map(async (address) => {
|
|
222
|
-
try {
|
|
223
|
-
if (!isFluidSupported) return; // Fluid is not available on Optimism
|
|
224
|
-
const userPositions = (await _getUserPositionsPortfolio(client, network, address));
|
|
225
|
-
for (const position of userPositions) {
|
|
226
|
-
if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
|
|
227
|
-
positions[address.toLowerCase() as EthAddress].fluid.data[position.userData.nftId] = position.userData;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
} catch (error) {
|
|
231
|
-
console.error(`Error fetching Fluid positions for address ${address}:`, error);
|
|
232
|
-
positions[address.toLowerCase() as EthAddress].fluid = {
|
|
233
|
-
error: `Error fetching Fluid positions for address ${address}`,
|
|
234
|
-
data: {},
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}),
|
|
238
|
-
|
|
239
|
-
// === STAKING DATA (independent of market data) ===
|
|
240
|
-
...addresses.map(async (address) => {
|
|
241
|
-
try {
|
|
242
|
-
if (!isFluidSupported) return;
|
|
243
|
-
stakingPositions[address.toLowerCase()].fluid = await _getAllUserEarnPositionsWithFTokens(client, network, address);
|
|
244
|
-
} catch (error) {
|
|
245
|
-
console.error(`Error fetching Fluid lend data for address ${address}:`, error);
|
|
246
|
-
stakingPositions[address.toLowerCase()].fluid = { error: `Error fetching Fluid lend data for address ${address}`, data: null };
|
|
247
|
-
}
|
|
248
|
-
}),
|
|
249
|
-
...addresses.map(async (address) => {
|
|
250
|
-
try {
|
|
251
|
-
if (!isMainnet) return;
|
|
252
|
-
stakingPositions[address.toLowerCase()].liquity = await getLiquityStakingData(client, network, address);
|
|
253
|
-
} catch (error) {
|
|
254
|
-
console.error(`Error fetching Liquity staking data for address ${address}:`, error);
|
|
255
|
-
stakingPositions[address.toLowerCase()].liquity = { error: `Error fetching Liquity staking data for address ${address}`, data: null };
|
|
256
|
-
}
|
|
257
|
-
}),
|
|
258
|
-
...addresses.map(async (address) => {
|
|
259
|
-
try {
|
|
260
|
-
if (!isMainnet) return;
|
|
261
|
-
stakingPositions[address.toLowerCase()].aaveV3 = await getStakeAaveData(client, network, address);
|
|
262
|
-
} catch (error) {
|
|
263
|
-
console.error(`Error fetching Aave V3 staking data for address ${address}:`, error);
|
|
264
|
-
stakingPositions[address.toLowerCase()].aaveV3 = { error: `Error fetching Aave V3 staking data for address ${address}`, data: null };
|
|
265
|
-
}
|
|
266
|
-
}),
|
|
267
|
-
...addresses.map(async (address) => {
|
|
268
|
-
try {
|
|
269
|
-
if (!isMainnet) return;
|
|
270
|
-
stakingPositions[address.toLowerCase()].umbrella = await getUmbrellaData(client, network, address);
|
|
271
|
-
} catch (error) {
|
|
272
|
-
console.error(`Error fetching Umbrella staking data for address ${address}:`, error);
|
|
273
|
-
stakingPositions[address.toLowerCase()].umbrella = { error: `Error fetching Umbrella staking data for address ${address}`, data: null };
|
|
274
|
-
}
|
|
275
|
-
}),
|
|
276
|
-
// Liquity V2 staking
|
|
277
|
-
...liquityV2MarketsStaking.map(market => addresses.map(async (address) => {
|
|
278
|
-
try {
|
|
279
|
-
if (!isMainnet) {
|
|
280
|
-
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: null };
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
const liquityV2StakingData = await getLiquityV2Staking(client, network, market.value, address);
|
|
284
|
-
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: '', data: liquityV2StakingData };
|
|
285
|
-
} catch (error) {
|
|
286
|
-
console.error(`Error fetching Liquity V2 staking data for address ${address}, market ${market.value}:`, error);
|
|
287
|
-
stakingPositions[address.toLowerCase()].liquityV2[market.value] = { error: `Error fetching Liquity V2 staking data for address ${address}`, data: null };
|
|
288
|
-
}
|
|
289
|
-
})).flat(),
|
|
290
|
-
|
|
291
|
-
// === REWARDS DATA (independent of market data) ===
|
|
292
|
-
// Batch King rewards
|
|
293
|
-
(async () => {
|
|
294
|
-
try {
|
|
295
|
-
if (!isMainnet) {
|
|
296
|
-
for (const address of addresses) {
|
|
297
|
-
rewardsData[address.toLowerCase()].king = { error: '', data: [] };
|
|
298
|
-
}
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
const kingRewards = await getKingRewards(client, network, addresses);
|
|
302
|
-
for (const address of addresses) {
|
|
303
|
-
const lowerAddress = address.toLowerCase() as EthAddress;
|
|
304
|
-
rewardsData[lowerAddress].king = {
|
|
305
|
-
error: '',
|
|
306
|
-
data: kingRewards[lowerAddress] || [],
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
} catch (error) {
|
|
310
|
-
console.error('Error fetching King rewards data in batch:', error);
|
|
311
|
-
for (const address of addresses) {
|
|
312
|
-
rewardsData[address.toLowerCase() as EthAddress].king = {
|
|
313
|
-
error: 'Error fetching King rewards data in batch',
|
|
314
|
-
data: null,
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
})(),
|
|
319
|
-
// Batch UNI rewards
|
|
320
|
-
(async () => {
|
|
321
|
-
try {
|
|
322
|
-
if (!isMainnet) {
|
|
323
|
-
for (const address of addresses) {
|
|
324
|
-
rewardsData[address.toLowerCase()].uniswap = { error: '', data: [] };
|
|
325
|
-
}
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
const uniswapRewards = await getUniswapRewards(client, network, addresses);
|
|
329
|
-
for (const address of addresses) {
|
|
330
|
-
const lowerAddress = address.toLowerCase() as EthAddress;
|
|
331
|
-
rewardsData[lowerAddress].uniswap = {
|
|
332
|
-
error: '',
|
|
333
|
-
data: uniswapRewards[lowerAddress] || [],
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
} catch (error) {
|
|
337
|
-
console.error('Error fetching Uniswap rewards data in batch:', error);
|
|
338
|
-
for (const address of addresses) {
|
|
339
|
-
rewardsData[address.toLowerCase() as EthAddress].uniswap = {
|
|
340
|
-
error: 'Error fetching Uniswap rewards data in batch',
|
|
341
|
-
data: null,
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
})(),
|
|
346
|
-
...sparkMarkets.map((market) => addresses.map(async address => {
|
|
347
|
-
try {
|
|
348
|
-
if (!isMainnet) {
|
|
349
|
-
rewardsData[address.toLowerCase()].spark[market.value] = { error: '', data: [] };
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const sparkData = await fetchSparkRewards(client, network, address, market.providerAddress);
|
|
353
|
-
rewardsData[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: sparkData };
|
|
354
|
-
} catch (error) {
|
|
355
|
-
console.error(`Error fetching Spark rewards data for address ${address}, market ${market.value}:`, error);
|
|
356
|
-
rewardsData[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark rewards data for address ${address}`, data: null };
|
|
357
|
-
}
|
|
358
|
-
})).flat(),
|
|
359
|
-
...addresses.map(async (address) => {
|
|
360
|
-
try {
|
|
361
|
-
const merklData = await getMerklUnclaimedRewards(address, network);
|
|
362
|
-
rewardsData[address.toLowerCase() as EthAddress].merkl = { error: '', data: merklData };
|
|
363
|
-
} catch (error) {
|
|
364
|
-
console.error(`Error fetching Merkl rewards data for address ${address}:`, error);
|
|
365
|
-
rewardsData[address.toLowerCase() as EthAddress].merkl = { error: `Error fetching Merkl rewards data for address ${address}`, data: null };
|
|
366
|
-
}
|
|
367
|
-
}),
|
|
368
|
-
...aaveV3Markets.map(market => addresses.map(async (address) => {
|
|
369
|
-
try {
|
|
370
|
-
const aaveData = await getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress);
|
|
371
|
-
rewardsData[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: aaveData };
|
|
372
|
-
} catch (error) {
|
|
373
|
-
console.error(`Error fetching Aave V3 Merit rewards data for address ${address}:`, error);
|
|
374
|
-
rewardsData[address.toLowerCase() as EthAddress].aaveV3 = { error: `Error fetching Aave V3 rewards data for address ${address}`, data: null };
|
|
375
|
-
}
|
|
376
|
-
})).flat(),
|
|
377
|
-
// Batch Spark Airdrop rewards
|
|
378
|
-
(async () => {
|
|
379
|
-
try {
|
|
380
|
-
if (!isMainnet) {
|
|
381
|
-
for (const address of addresses) {
|
|
382
|
-
rewardsData[address.toLowerCase()].spk = { error: '', data: [] };
|
|
383
|
-
}
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const sparkAirdropRewards = await fetchSparkAirdropRewards(client, network, addresses);
|
|
388
|
-
for (const address of addresses) {
|
|
389
|
-
const lowerAddress = address.toLowerCase() as EthAddress;
|
|
390
|
-
rewardsData[lowerAddress].spk = {
|
|
391
|
-
error: '',
|
|
392
|
-
data: sparkAirdropRewards[lowerAddress] || [],
|
|
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() as EthAddress].spk = {
|
|
399
|
-
error: 'Error fetching Spark Airdrop rewards data in batch',
|
|
400
|
-
data: null,
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
})(),
|
|
405
|
-
(async () => {
|
|
406
|
-
try {
|
|
407
|
-
if (!isMainnet) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const ethenaAirdropRewards = await fetchEthenaAirdropRewards(addresses);
|
|
412
|
-
for (const address of addresses) {
|
|
413
|
-
const lowerAddress = address.toLowerCase() as EthAddress;
|
|
414
|
-
rewardsData[lowerAddress].ethena = {
|
|
415
|
-
error: '',
|
|
416
|
-
data: ethenaAirdropRewards[lowerAddress] || [],
|
|
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() as EthAddress].ethena = {
|
|
423
|
-
error: 'Error fetching Ethena Airdrop rewards data in batch',
|
|
424
|
-
data: null,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
})(),
|
|
429
|
-
]);
|
|
430
|
-
|
|
431
|
-
await Promise.all([
|
|
432
|
-
...aaveV3Markets.map((market) => allAddresses.map(async (address) => {
|
|
433
|
-
try {
|
|
434
|
-
const accData = await _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...aaveV3MarketsData[market.value] });
|
|
435
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: accData };
|
|
436
|
-
} catch (error) {
|
|
437
|
-
console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
|
|
438
|
-
positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
439
|
-
}
|
|
440
|
-
})).flat(),
|
|
441
|
-
...aaveV4Spokes.map((spoke) => allAddresses.map(async (address) => {
|
|
442
|
-
try {
|
|
443
|
-
const accData = await _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
|
|
444
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
|
|
445
|
-
} catch (error) {
|
|
446
|
-
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
447
|
-
positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
448
|
-
}
|
|
449
|
-
})).flat(),
|
|
450
|
-
...morphoMarkets.map((market) => addresses.map(async (address) => {
|
|
451
|
-
try {
|
|
452
|
-
const [accDataPromise, earnDataPromise] = await Promise.allSettled([
|
|
453
|
-
_getMorphoBlueAccountData(client, network, address, market, morphoMarketsData[market.value]),
|
|
454
|
-
getMorphoEarn(client, network, address, market, morphoMarketsData[market.value]),
|
|
455
|
-
]);
|
|
456
|
-
if (accDataPromise.status === 'rejected') {
|
|
457
|
-
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, accDataPromise.reason);
|
|
458
|
-
positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
459
|
-
}
|
|
460
|
-
if (earnDataPromise.status === 'rejected') {
|
|
461
|
-
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, earnDataPromise.reason);
|
|
462
|
-
positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
463
|
-
}
|
|
464
|
-
if (accDataPromise.status !== 'rejected') {
|
|
465
|
-
const accData = accDataPromise.value;
|
|
466
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: '', data: accData };
|
|
467
|
-
}
|
|
468
|
-
if (earnDataPromise.status !== 'rejected') {
|
|
469
|
-
const earnData = earnDataPromise.value;
|
|
470
|
-
if (earnData && new Dec(earnData.amount).gt(0)) {
|
|
471
|
-
stakingPositions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = {
|
|
472
|
-
error: '',
|
|
473
|
-
data: earnData,
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
} catch (error) {
|
|
478
|
-
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
|
|
479
|
-
positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
480
|
-
}
|
|
481
|
-
})).flat(),
|
|
482
|
-
...morphoMidnightMarkets.map((market) => addresses.map(async (address) => {
|
|
483
|
-
try {
|
|
484
|
-
// Markets are created lazily on the first position, so an uncreated one can hold no position.
|
|
485
|
-
if (!morphoMidnightMarketsData[market.value]?.isCreated) return;
|
|
486
|
-
const accData = await _getMorphoMidnightAccountData(client, network, address, market, morphoMidnightMarketsData[market.value]);
|
|
487
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: '', data: accData };
|
|
488
|
-
} catch (error) {
|
|
489
|
-
console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, error);
|
|
490
|
-
positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
|
|
491
|
-
}
|
|
492
|
-
})).flat(),
|
|
493
|
-
...compoundV3Markets.map((market) => addresses.map(async (address) => {
|
|
494
|
-
try {
|
|
495
|
-
const accData = await _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: compoundV3MarketsData[market.value].assetsData });
|
|
496
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: '', data: accData };
|
|
497
|
-
} catch (error) {
|
|
498
|
-
console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
|
|
499
|
-
positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
500
|
-
}
|
|
501
|
-
})).flat(),
|
|
502
|
-
...sparkMarkets.map((market) => allAddresses.map(async (address) => {
|
|
503
|
-
try {
|
|
504
|
-
const accData = await _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: sparkMarketsData[market.value].assetsData, eModeCategoriesData: sparkMarketsData[market.value].eModeCategoriesData });
|
|
505
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: accData };
|
|
506
|
-
} catch (error) {
|
|
507
|
-
console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
|
|
508
|
-
positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
|
|
509
|
-
}
|
|
510
|
-
})).flat(),
|
|
511
|
-
...addresses.map((address) => (makerCdps[address.toLowerCase() as EthAddress] || []).map(async (cdpInfo) => {
|
|
512
|
-
try {
|
|
513
|
-
const cdpData = await _getMakerCdpData(client, network, cdpInfo);
|
|
514
|
-
if (cdpData) {
|
|
515
|
-
positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: '', data: cdpData };
|
|
516
|
-
}
|
|
517
|
-
} catch (error) {
|
|
518
|
-
console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
|
|
519
|
-
positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
|
|
520
|
-
}
|
|
521
|
-
})).flat(),
|
|
522
|
-
...aaveV2Markets.map((market) => addresses.map(async (address) => {
|
|
523
|
-
try {
|
|
524
|
-
const accData = await _getAaveV2AccountData(client, network, address, aaveV2MarketsData[market.value].assetsData, market);
|
|
525
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: '', data: accData };
|
|
526
|
-
} catch (error) {
|
|
527
|
-
console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
|
|
528
|
-
positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
|
|
529
|
-
}
|
|
530
|
-
})).flat(),
|
|
531
|
-
...compoundV2Markets.map((market) => addresses.map(async (address) => {
|
|
532
|
-
try {
|
|
533
|
-
const accData = await _getCompoundV2AccountData(client, network, address, compoundV2MarketsData[market.value].assetsData);
|
|
534
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: '', data: accData };
|
|
535
|
-
} catch (error) {
|
|
536
|
-
console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
|
|
537
|
-
positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
|
|
538
|
-
}
|
|
539
|
-
})).flat(),
|
|
540
|
-
...addresses.map(async (address) => {
|
|
541
|
-
try {
|
|
542
|
-
if (!isMainnet) return; // Liquity trove info is only available on mainnet
|
|
543
|
-
const troveInfo = await _getLiquityTroveInfo(client, network, address);
|
|
544
|
-
if (new Dec(troveInfo.collateral).gt(0)) positions[address.toLowerCase() as EthAddress].liquity = { error: '', data: troveInfo };
|
|
545
|
-
} catch (error) {
|
|
546
|
-
console.error(`Error fetching Liquity trove info for address ${address}:`, error);
|
|
547
|
-
positions[address.toLowerCase() as EthAddress].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
|
|
548
|
-
}
|
|
549
|
-
}),
|
|
550
|
-
...crvUsdMarkets.map((market) => addresses.map(async (address) => {
|
|
551
|
-
try {
|
|
552
|
-
const accData = await _getCurveUsdUserData(client, network, address, market, crvUsdMarketsData[market.value].activeBand, crvUsdMarketsData[market.value].borrowRate);
|
|
553
|
-
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
554
|
-
positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: '', data: accData };
|
|
555
|
-
}
|
|
556
|
-
} catch (error) {
|
|
557
|
-
console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
|
|
558
|
-
positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
|
|
559
|
-
}
|
|
560
|
-
})).flat(),
|
|
561
|
-
...llamaLendMarkets.map((market) => addresses.map(async (address) => {
|
|
562
|
-
try {
|
|
563
|
-
const accData = await _getLlamaLendUserData(client, network, address, market, llamaLendMarketsData[market.value]);
|
|
564
|
-
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
565
|
-
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: '', data: { ...accData, borrowRate: llamaLendMarketsData[market.value].borrowRate } };
|
|
566
|
-
}
|
|
567
|
-
} catch (error) {
|
|
568
|
-
console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
|
|
569
|
-
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
570
|
-
}
|
|
571
|
-
})).flat(),
|
|
572
|
-
// liquity sBold/yBold and staking options
|
|
573
|
-
...addresses.map(async (address) => {
|
|
574
|
-
try {
|
|
575
|
-
if (!isMainnet) {
|
|
576
|
-
stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: '', data: null };
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
const data = await getLiquitySAndYBold(client, network, stakingPositions[address.toLowerCase()].liquityV2, address);
|
|
580
|
-
stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: '', data };
|
|
581
|
-
} catch (error) {
|
|
582
|
-
console.error(`Error fetching SBold/YBold data for address ${address}:`, error);
|
|
583
|
-
stakingPositions[address.toLowerCase() as EthAddress].liquityV2SBoldYBold = { error: `Error fetching sBold/yBold data for address ${address}`, data: null };
|
|
584
|
-
}
|
|
585
|
-
}),
|
|
586
|
-
]);
|
|
587
|
-
|
|
588
|
-
return {
|
|
589
|
-
positions,
|
|
590
|
-
stakingPositions,
|
|
591
|
-
rewardsData,
|
|
592
|
-
markets,
|
|
593
|
-
};
|
|
11
|
+
return getCustomDeFiData(provider, network, defaultProvider, addresses, {
|
|
12
|
+
fetchStaking: true,
|
|
13
|
+
fetchRewards: true,
|
|
14
|
+
isSim,
|
|
15
|
+
});
|
|
594
16
|
}
|
|
595
17
|
|
|
596
|
-
|
|
597
18
|
export async function getShifterPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim = false): Promise<{
|
|
598
19
|
positions: PortfolioPositionsData;
|
|
599
20
|
markets: PortfolioMarketsData;
|
|
600
21
|
}> {
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
610
|
-
const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
611
|
-
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
612
|
-
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
613
|
-
const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
|
|
614
|
-
|
|
615
|
-
const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 2_000 : 2_500_000 } } }];
|
|
616
|
-
const client = getViemProvider(provider, ...args);
|
|
617
|
-
const defaultClient = getViemProvider(defaultProvider, ...args);
|
|
618
|
-
|
|
619
|
-
const markets: PortfolioMarketsData = {
|
|
620
|
-
morphoMarketsData: {},
|
|
621
|
-
morphoMidnightMarketsData: {}, // Morpho Midnight is not fetched for the shifter; key kept so the payload shape is stable
|
|
622
|
-
compoundV3MarketsData: {},
|
|
623
|
-
sparkMarketsData: {},
|
|
624
|
-
aaveV3MarketsData: {},
|
|
625
|
-
aaveV2MarketsData: {},
|
|
626
|
-
compoundV2MarketsData: {},
|
|
627
|
-
crvUsdMarketsData: {},
|
|
628
|
-
llamaLendMarketsData: {},
|
|
629
|
-
liquityV2MarketsData: {},
|
|
630
|
-
aaveV4SpokesData: {},
|
|
631
|
-
fluidMarketsData: {},
|
|
632
|
-
makerMarketsData: {},
|
|
633
|
-
};
|
|
634
|
-
const makerCdps: Record<string, CdpInfo[]> = {};
|
|
635
|
-
|
|
636
|
-
const positions: PortfolioPositionsData = {};
|
|
637
|
-
|
|
638
|
-
for (const address of addresses) {
|
|
639
|
-
positions[address.toLowerCase() as EthAddress] = {
|
|
640
|
-
aaveV3: {},
|
|
641
|
-
aaveV4: {},
|
|
642
|
-
morphoBlue: {},
|
|
643
|
-
morphoMidnight: {}, // not fetched for the shifter (see markets above)
|
|
644
|
-
compoundV3: {},
|
|
645
|
-
spark: {},
|
|
646
|
-
maker: {},
|
|
647
|
-
aaveV2: {},
|
|
648
|
-
compoundV2: {},
|
|
649
|
-
liquity: {},
|
|
650
|
-
crvUsd: {},
|
|
651
|
-
llamaLend: {},
|
|
652
|
-
fluid: {
|
|
653
|
-
error: '',
|
|
654
|
-
data: {},
|
|
655
|
-
},
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
await Promise.allSettled([
|
|
660
|
-
// === MARKET DATA (needs to be fetched first) ===
|
|
661
|
-
...morphoMarkets.map(async (market) => {
|
|
662
|
-
markets.morphoMarketsData[market.value] = await _getMorphoBluePortfolioMarketData(client, network, market);
|
|
663
|
-
}),
|
|
664
|
-
...compoundV3Markets.map(async (market) => {
|
|
665
|
-
markets.compoundV3MarketsData[market.value] = await _getCompoundV3MarketsData(client, network, market, defaultClient);
|
|
666
|
-
}),
|
|
667
|
-
...sparkMarkets.map(async (market) => {
|
|
668
|
-
markets.sparkMarketsData[market.value] = await _getSparkMarketsData(client, network, market);
|
|
669
|
-
}),
|
|
670
|
-
...aaveV3Markets.map(async (market) => {
|
|
671
|
-
markets.aaveV3MarketsData[market.value] = await _getAaveV3MarketData(client, network, market);
|
|
672
|
-
}),
|
|
673
|
-
...aaveV4Spokes.map(async (spoke) => {
|
|
674
|
-
markets.aaveV4SpokesData[spoke.value] = await _getAaveV4SpokeData(client, network, spoke);
|
|
675
|
-
}),
|
|
676
|
-
...aaveV2Markets.map(async (market) => {
|
|
677
|
-
markets.aaveV2MarketsData[market.value] = await _getAaveV2MarketsData(client, network, market);
|
|
678
|
-
}),
|
|
679
|
-
...compoundV2Markets.map(async (market) => {
|
|
680
|
-
markets.compoundV2MarketsData[market.value] = await _getCompoundV2MarketsData(client, network);
|
|
681
|
-
}),
|
|
682
|
-
...crvUsdMarkets.map(async (market) => {
|
|
683
|
-
markets.crvUsdMarketsData[market.value] = await _getCurveUsdGlobalData(client, network, market);
|
|
684
|
-
}),
|
|
685
|
-
...llamaLendMarkets.map(async (market) => {
|
|
686
|
-
markets.llamaLendMarketsData[market.value] = await _getLlamaLendGlobalData(client, network, market);
|
|
687
|
-
}),
|
|
688
|
-
...liquityV2Markets.map(async (market) => {
|
|
689
|
-
markets.liquityV2MarketsData[market.value] = await _getLiquityV2MarketData(client, network, market);
|
|
690
|
-
}),
|
|
691
|
-
(async () => {
|
|
692
|
-
if (!isFluidSupported) return;
|
|
693
|
-
try {
|
|
694
|
-
markets.fluidMarketsData = await _getAllFluidMarketDataPortfolio(client, network);
|
|
695
|
-
} catch (error) {
|
|
696
|
-
console.error('Error fetching Fluid markets data:', error);
|
|
697
|
-
}
|
|
698
|
-
})(),
|
|
699
|
-
(async () => {
|
|
700
|
-
if (!isMainnet) return; // Maker CDPs are only available on mainnet
|
|
701
|
-
try {
|
|
702
|
-
markets.makerMarketsData = await _getMakerIlksData(client, network, MakerActiveIlks);
|
|
703
|
-
} catch (error) {
|
|
704
|
-
console.error('Error fetching Maker ilks data:', error);
|
|
705
|
-
}
|
|
706
|
-
})(),
|
|
707
|
-
|
|
708
|
-
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
709
|
-
...addresses.map(async (address) => {
|
|
710
|
-
if (!isMainnet) return; // Maker CDPs are only available on mainnet
|
|
711
|
-
const makerCdp = await _getUserCdps(client, network, address);
|
|
712
|
-
makerCdps[address.toLowerCase() as EthAddress] = makerCdp;
|
|
713
|
-
}),
|
|
714
|
-
...addresses.map(async (address) => {
|
|
715
|
-
try {
|
|
716
|
-
if (!isFluidSupported) return; // Fluid is not available on Optimism
|
|
717
|
-
const userPositions = (await _getUserPositionsPortfolio(client, network, address));
|
|
718
|
-
for (const position of userPositions) {
|
|
719
|
-
if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
|
|
720
|
-
positions[address.toLowerCase() as EthAddress].fluid.data[position.userData.nftId] = position.userData;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
} catch (error) {
|
|
724
|
-
console.error(`Error fetching Fluid positions for address ${address}:`, error);
|
|
725
|
-
positions[address.toLowerCase() as EthAddress].fluid = {
|
|
726
|
-
error: `Error fetching Fluid positions for address ${address}`,
|
|
727
|
-
data: {},
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
}),
|
|
731
|
-
]);
|
|
732
|
-
|
|
733
|
-
await Promise.all([
|
|
734
|
-
...aaveV3Markets.map((market) => addresses.map(async (address) => {
|
|
735
|
-
try {
|
|
736
|
-
const accData = await _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...markets.aaveV3MarketsData[market.value] });
|
|
737
|
-
// Always store the position (even with no supply) so the eMode category is available to the shifter
|
|
738
|
-
positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: accData };
|
|
739
|
-
} catch (error) {
|
|
740
|
-
console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
|
|
741
|
-
positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
742
|
-
}
|
|
743
|
-
})).flat(),
|
|
744
|
-
...aaveV4Spokes.map((spoke) => addresses.map(async (address) => {
|
|
745
|
-
try {
|
|
746
|
-
const accData = await _getAaveV4AccountData(client, network, markets.aaveV4SpokesData[spoke.value], address);
|
|
747
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
|
|
748
|
-
} catch (error) {
|
|
749
|
-
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
750
|
-
positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
751
|
-
}
|
|
752
|
-
})).flat(),
|
|
753
|
-
...morphoMarkets.map((market) => addresses.map(async (address) => {
|
|
754
|
-
try {
|
|
755
|
-
const accData = await _getMorphoBlueAccountData(client, network, address, market, markets.morphoMarketsData[market.value]);
|
|
756
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: '', data: accData };
|
|
757
|
-
} catch (error) {
|
|
758
|
-
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
|
|
759
|
-
positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
760
|
-
}
|
|
761
|
-
})).flat(),
|
|
762
|
-
...compoundV3Markets.map((market) => addresses.map(async (address) => {
|
|
763
|
-
try {
|
|
764
|
-
const accData = await _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData });
|
|
765
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: '', data: accData };
|
|
766
|
-
} catch (error) {
|
|
767
|
-
console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
|
|
768
|
-
positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
769
|
-
}
|
|
770
|
-
})).flat(),
|
|
771
|
-
...sparkMarkets.map((market) => addresses.map(async (address) => {
|
|
772
|
-
try {
|
|
773
|
-
const accData = await _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData });
|
|
774
|
-
// Always store the position (even with no supply) so the eMode category is available to the shifter
|
|
775
|
-
positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: accData };
|
|
776
|
-
} catch (error) {
|
|
777
|
-
console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
|
|
778
|
-
positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
|
|
779
|
-
}
|
|
780
|
-
})).flat(),
|
|
781
|
-
...addresses.map((address) => (makerCdps[address.toLowerCase() as EthAddress] || []).map(async (cdpInfo) => {
|
|
782
|
-
try {
|
|
783
|
-
// reuse ilk data fetched for the markets payload; ilks outside the active set are fetched on demand
|
|
784
|
-
const cdpData = await _getMakerCdpData(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel]);
|
|
785
|
-
if (cdpData) {
|
|
786
|
-
positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: '', data: cdpData };
|
|
787
|
-
}
|
|
788
|
-
} catch (error) {
|
|
789
|
-
console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
|
|
790
|
-
positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
|
|
791
|
-
}
|
|
792
|
-
})).flat(),
|
|
793
|
-
...aaveV2Markets.map((market) => addresses.map(async (address) => {
|
|
794
|
-
try {
|
|
795
|
-
const accData = await _getAaveV2AccountData(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market);
|
|
796
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: '', data: accData };
|
|
797
|
-
} catch (error) {
|
|
798
|
-
console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
|
|
799
|
-
positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
|
|
800
|
-
}
|
|
801
|
-
})).flat(),
|
|
802
|
-
...compoundV2Markets.map((market) => addresses.map(async (address) => {
|
|
803
|
-
try {
|
|
804
|
-
const accData = await _getCompoundV2AccountData(client, network, address, markets.compoundV2MarketsData[market.value].assetsData);
|
|
805
|
-
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: '', data: accData };
|
|
806
|
-
} catch (error) {
|
|
807
|
-
console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
|
|
808
|
-
positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
|
|
809
|
-
}
|
|
810
|
-
})).flat(),
|
|
811
|
-
...addresses.map(async (address) => {
|
|
812
|
-
try {
|
|
813
|
-
if (!isMainnet) return; // Liquity trove info is only available on mainnet
|
|
814
|
-
const troveInfo = await _getLiquityTroveInfo(client, network, address);
|
|
815
|
-
if (new Dec(troveInfo.collateral).gt(0)) positions[address.toLowerCase() as EthAddress].liquity = { error: '', data: troveInfo };
|
|
816
|
-
} catch (error) {
|
|
817
|
-
console.error(`Error fetching Liquity trove info for address ${address}:`, error);
|
|
818
|
-
positions[address.toLowerCase() as EthAddress].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
|
|
819
|
-
}
|
|
820
|
-
}),
|
|
821
|
-
...crvUsdMarkets.map((market) => addresses.map(async (address) => {
|
|
822
|
-
try {
|
|
823
|
-
const accData = await _getCurveUsdUserData(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand, markets.crvUsdMarketsData[market.value].borrowRate);
|
|
824
|
-
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
825
|
-
positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: '', data: accData };
|
|
826
|
-
}
|
|
827
|
-
} catch (error) {
|
|
828
|
-
console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
|
|
829
|
-
positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
|
|
830
|
-
}
|
|
831
|
-
})).flat(),
|
|
832
|
-
...llamaLendMarkets.map((market) => addresses.map(async (address) => {
|
|
833
|
-
try {
|
|
834
|
-
const accData = await _getLlamaLendUserData(client, network, address, market, markets.llamaLendMarketsData[market.value]);
|
|
835
|
-
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
836
|
-
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: '', data: { ...accData, borrowRate: markets.llamaLendMarketsData[market.value].borrowRate } };
|
|
837
|
-
}
|
|
838
|
-
} catch (error) {
|
|
839
|
-
console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
|
|
840
|
-
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
841
|
-
}
|
|
842
|
-
})).flat(),
|
|
843
|
-
]);
|
|
844
|
-
|
|
845
|
-
return {
|
|
846
|
-
positions,
|
|
847
|
-
markets,
|
|
848
|
-
};
|
|
22
|
+
const { positions, markets } = await getCustomDeFiData(provider, network, defaultProvider, addresses, {
|
|
23
|
+
protocols: Object.values(PortfolioProtocol).filter((p) => p !== PortfolioProtocol.MorphoMidnight),
|
|
24
|
+
returnEmptyEModePositions: true,
|
|
25
|
+
fetchFluidMarkets: true,
|
|
26
|
+
isSim,
|
|
27
|
+
batchSize: isSim ? 2_000 : 2_500_000,
|
|
28
|
+
});
|
|
29
|
+
return { positions, markets };
|
|
849
30
|
}
|
|
850
31
|
|
|
851
32
|
export * from './discovery';
|
|
33
|
+
export * from './customDeFiData';
|
|
852
34
|
|
|
853
35
|
export { getWalletLendingSummaries } from './lendingSummaries';
|