@defisaver/positions-sdk 2.1.168-stable-pair-dev → 2.1.169-aave-v4-exposure-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/aaveV2/index.d.ts +4 -4
- package/cjs/aaveV2/index.js +7 -7
- package/cjs/aaveV3/index.d.ts +4 -3
- package/cjs/aaveV3/index.js +14 -10
- package/cjs/aaveV3/merkl.d.ts +5 -1
- package/cjs/aaveV3/merkl.js +8 -3
- package/cjs/aaveV4/index.d.ts +4 -3
- package/cjs/aaveV4/index.js +19 -16
- package/cjs/aaveV4/merkl.d.ts +10 -2
- package/cjs/aaveV4/merkl.js +15 -6
- package/cjs/claiming/aaveV3.d.ts +2 -2
- package/cjs/claiming/aaveV3.js +5 -4
- package/cjs/claiming/king.d.ts +2 -2
- package/cjs/claiming/king.js +3 -2
- package/cjs/claiming/spark.d.ts +3 -3
- package/cjs/claiming/spark.js +8 -7
- package/cjs/claiming/uniswap.d.ts +2 -2
- package/cjs/claiming/uniswap.js +3 -2
- package/cjs/compoundV2/index.d.ts +4 -4
- package/cjs/compoundV2/index.js +9 -9
- package/cjs/compoundV3/index.d.ts +5 -4
- package/cjs/compoundV3/index.js +17 -13
- package/cjs/compoundV3/merkl.d.ts +1 -1
- package/cjs/compoundV3/merkl.js +2 -5
- package/cjs/curveUsd/index.d.ts +5 -5
- package/cjs/curveUsd/index.js +17 -17
- package/cjs/fluid/index.d.ts +23 -22
- package/cjs/fluid/index.js +75 -72
- package/cjs/fluid/merkl.d.ts +5 -3
- package/cjs/fluid/merkl.js +11 -6
- package/cjs/helpers/aaveV4Helpers/index.js +1 -0
- package/cjs/liquity/index.d.ts +4 -4
- package/cjs/liquity/index.js +23 -23
- package/cjs/liquityV2/index.d.ts +10 -10
- package/cjs/liquityV2/index.js +59 -59
- package/cjs/llamaLend/index.d.ts +5 -5
- package/cjs/llamaLend/index.js +13 -13
- package/cjs/maker/index.d.ts +6 -6
- package/cjs/maker/index.js +16 -16
- package/cjs/markets/morphoBlue/index.d.ts +2 -0
- package/cjs/markets/morphoBlue/index.js +18 -1
- package/cjs/morphoBlue/index.d.ts +7 -7
- package/cjs/morphoBlue/index.js +28 -26
- package/cjs/morphoBlue/merkl.d.ts +5 -3
- package/cjs/morphoBlue/merkl.js +6 -8
- package/cjs/morphoMidnight/index.d.ts +5 -5
- package/cjs/morphoMidnight/index.js +18 -18
- package/cjs/portfolio/customDeFiData.d.ts +3 -0
- package/cjs/portfolio/customDeFiData.js +267 -0
- package/cjs/portfolio/index.d.ts +1 -0
- package/cjs/portfolio/index.js +15 -851
- package/cjs/services/merkl.d.ts +46 -2
- package/cjs/services/merkl.js +190 -19
- package/cjs/services/priceService.d.ts +12 -12
- package/cjs/services/priceService.js +30 -29
- package/cjs/services/viem.d.ts +10 -2
- package/cjs/services/viem.js +27 -1
- package/cjs/spark/index.d.ts +4 -4
- package/cjs/spark/index.js +9 -9
- package/cjs/types/aaveV4.d.ts +1 -0
- package/cjs/types/merkl.d.ts +18 -0
- package/cjs/types/morphoBlue.d.ts +1 -0
- package/cjs/types/morphoBlue.js +1 -0
- package/cjs/types/portfolio.d.ts +36 -0
- package/cjs/types/portfolio.js +18 -0
- package/cjs/umbrella/index.d.ts +2 -2
- package/cjs/umbrella/index.js +5 -4
- package/esm/aaveV2/index.d.ts +4 -4
- package/esm/aaveV2/index.js +8 -8
- package/esm/aaveV3/index.d.ts +4 -3
- package/esm/aaveV3/index.js +15 -11
- package/esm/aaveV3/merkl.d.ts +5 -1
- package/esm/aaveV3/merkl.js +9 -4
- package/esm/aaveV4/index.d.ts +4 -3
- package/esm/aaveV4/index.js +20 -17
- package/esm/aaveV4/merkl.d.ts +10 -2
- package/esm/aaveV4/merkl.js +16 -7
- package/esm/claiming/aaveV3.d.ts +2 -2
- package/esm/claiming/aaveV3.js +5 -4
- package/esm/claiming/king.d.ts +2 -2
- package/esm/claiming/king.js +3 -2
- package/esm/claiming/spark.d.ts +3 -3
- package/esm/claiming/spark.js +8 -7
- package/esm/claiming/uniswap.d.ts +2 -2
- package/esm/claiming/uniswap.js +3 -2
- package/esm/compoundV2/index.d.ts +4 -4
- package/esm/compoundV2/index.js +9 -9
- package/esm/compoundV3/index.d.ts +5 -4
- package/esm/compoundV3/index.js +19 -15
- package/esm/compoundV3/merkl.d.ts +1 -1
- package/esm/compoundV3/merkl.js +3 -6
- package/esm/curveUsd/index.d.ts +5 -5
- package/esm/curveUsd/index.js +17 -17
- package/esm/fluid/index.d.ts +23 -22
- package/esm/fluid/index.js +76 -73
- package/esm/fluid/merkl.d.ts +5 -3
- package/esm/fluid/merkl.js +12 -7
- package/esm/helpers/aaveV4Helpers/index.js +2 -1
- package/esm/liquity/index.d.ts +4 -4
- package/esm/liquity/index.js +23 -23
- package/esm/liquityV2/index.d.ts +10 -10
- package/esm/liquityV2/index.js +60 -60
- package/esm/llamaLend/index.d.ts +5 -5
- package/esm/llamaLend/index.js +13 -13
- package/esm/maker/index.d.ts +6 -6
- package/esm/maker/index.js +16 -16
- package/esm/markets/morphoBlue/index.d.ts +2 -0
- package/esm/markets/morphoBlue/index.js +16 -0
- package/esm/morphoBlue/index.d.ts +7 -7
- package/esm/morphoBlue/index.js +29 -27
- package/esm/morphoBlue/merkl.d.ts +5 -3
- package/esm/morphoBlue/merkl.js +7 -9
- package/esm/morphoMidnight/index.d.ts +5 -5
- package/esm/morphoMidnight/index.js +18 -18
- package/esm/portfolio/customDeFiData.d.ts +3 -0
- package/esm/portfolio/customDeFiData.js +261 -0
- package/esm/portfolio/index.d.ts +1 -0
- package/esm/portfolio/index.js +16 -849
- package/esm/services/merkl.d.ts +46 -2
- package/esm/services/merkl.js +180 -18
- package/esm/services/priceService.d.ts +12 -12
- package/esm/services/priceService.js +31 -30
- package/esm/services/viem.d.ts +10 -2
- package/esm/services/viem.js +25 -0
- package/esm/spark/index.d.ts +4 -4
- package/esm/spark/index.js +10 -10
- package/esm/types/aaveV4.d.ts +1 -0
- package/esm/types/merkl.d.ts +18 -0
- package/esm/types/morphoBlue.d.ts +1 -0
- package/esm/types/morphoBlue.js +1 -0
- package/esm/types/portfolio.d.ts +36 -0
- package/esm/types/portfolio.js +17 -1
- package/esm/umbrella/index.d.ts +2 -2
- package/esm/umbrella/index.js +5 -4
- package/package.json +2 -2
- package/src/aaveV2/index.ts +7 -7
- package/src/aaveV3/index.ts +15 -11
- package/src/aaveV3/merkl.ts +9 -4
- package/src/aaveV4/index.ts +19 -16
- package/src/aaveV4/merkl.ts +16 -7
- package/src/claiming/aaveV3.ts +5 -3
- package/src/claiming/king.ts +6 -3
- package/src/claiming/spark.ts +9 -6
- package/src/claiming/uniswap.ts +4 -3
- package/src/compoundV2/index.ts +10 -9
- package/src/compoundV3/index.ts +20 -14
- package/src/compoundV3/merkl.ts +5 -4
- package/src/curveUsd/index.ts +19 -17
- package/src/fluid/index.ts +88 -70
- package/src/fluid/merkl.ts +12 -7
- package/src/helpers/aaveV4Helpers/index.ts +2 -0
- package/src/liquity/index.ts +23 -23
- package/src/liquityV2/index.ts +64 -56
- package/src/llamaLend/index.ts +15 -13
- package/src/maker/index.ts +19 -16
- package/src/markets/morphoBlue/index.ts +16 -0
- package/src/morphoBlue/index.ts +23 -20
- package/src/morphoBlue/merkl.ts +9 -6
- package/src/morphoMidnight/index.ts +13 -13
- package/src/portfolio/customDeFiData.ts +385 -0
- package/src/portfolio/index.ts +16 -834
- package/src/services/merkl.ts +209 -19
- package/src/services/priceService.ts +33 -30
- package/src/services/viem.ts +16 -0
- package/src/spark/index.ts +11 -8
- package/src/types/aaveV4.ts +1 -0
- package/src/types/merkl.ts +20 -0
- package/src/types/morphoBlue.ts +1 -0
- package/src/types/portfolio.ts +39 -0
- package/src/umbrella/index.ts +6 -5
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import Dec from 'decimal.js';
|
|
11
|
+
import { NetworkNumber, } from '../types/common';
|
|
12
|
+
import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, LiquityV2Markets, LlamaLendMarkets, MakerActiveIlks, MorphoBlueMarkets, MorphoMidnightMarkets, SparkMarkets, } from '../markets';
|
|
13
|
+
import { AaveVersions, CompoundVersions, PortfolioProtocol, } from '../types';
|
|
14
|
+
import { getBlockTimestamp, getViemProvider } from '../services/viem';
|
|
15
|
+
import { ZERO_ADDRESS } from '../constants';
|
|
16
|
+
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
17
|
+
import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
|
|
18
|
+
import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
|
|
19
|
+
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
20
|
+
import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
|
|
21
|
+
import { _getSparkAccountData, _getSparkMarketsData } from '../spark';
|
|
22
|
+
import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
23
|
+
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
24
|
+
import { _getMorphoBlueAccountData, _getMorphoBluePortfolioMarketData, getMorphoEarn } from '../morphoBlue';
|
|
25
|
+
import { _getMorphoMidnightAccountData, _getMorphoMidnightMarketData } from '../morphoMidnight';
|
|
26
|
+
import { _getMakerCdpData, _getMakerIlksData, _getUserCdps } from '../maker';
|
|
27
|
+
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
28
|
+
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
29
|
+
import { _getAllFluidMarketDataPortfolio, _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
30
|
+
import { getUmbrellaData } from '../umbrella';
|
|
31
|
+
import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
32
|
+
import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
|
|
33
|
+
import { getKingRewards } from '../claiming/king';
|
|
34
|
+
import { fetchEthenaAirdropRewards } from '../claiming/ethena';
|
|
35
|
+
import { getUniswapRewards } from '../claiming/uniswap';
|
|
36
|
+
const lower = (address) => address.toLowerCase();
|
|
37
|
+
const positive = (value) => new Dec(value || '0').gt(0);
|
|
38
|
+
const supported = (list, network) => (Object.values(list).filter((m) => m.chainIds.includes(network)));
|
|
39
|
+
export function getCustomDeFiData(provider_1, network_1, defaultProvider_1, addresses_1) {
|
|
40
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, options = {}) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const { protocols = Object.values(PortfolioProtocol), fetchStaking = false, fetchRewards = false, returnEmptyEModePositions = false, fetchFluidMarkets = false, isSim = false, } = options;
|
|
43
|
+
// JSON-RPC body ends up ~4x the calldata cap; 250k keeps it under the ~2.5MB provider limit.
|
|
44
|
+
const batchSize = (_a = options.batchSize) !== null && _a !== void 0 ? _a : (isSim ? 2000 : 250000);
|
|
45
|
+
const has = (protocol) => protocols.includes(protocol);
|
|
46
|
+
const isMainnet = network === NetworkNumber.Eth;
|
|
47
|
+
const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
|
|
48
|
+
const client = getViemProvider(provider, network, { batch: { multicall: { batchSize } } });
|
|
49
|
+
const defaultClient = getViemProvider(defaultProvider, network, { batch: { multicall: { batchSize } } });
|
|
50
|
+
// Every fetch below takes the block explicitly and passes it to each of its contract reads.
|
|
51
|
+
// Time-keyed sources (Merkl rewards) need the block's timestamp instead, resolved once here (no
|
|
52
|
+
// RPC call for 'latest') and handed to the market fetches so they don't each look it up.
|
|
53
|
+
const blockNumber = (_b = options.blockNumber) !== null && _b !== void 0 ? _b : 'latest';
|
|
54
|
+
const blockTimestamp = yield getBlockTimestamp(client, blockNumber);
|
|
55
|
+
const aaveV3Markets = has(PortfolioProtocol.AaveV3)
|
|
56
|
+
? [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((v) => AaveMarkets(network)[v]).filter((m) => m.chainIds.includes(network))
|
|
57
|
+
: [];
|
|
58
|
+
const aaveV2Markets = has(PortfolioProtocol.AaveV2) ? [AaveMarkets(network)[AaveVersions.AaveV2]].filter((m) => m.chainIds.includes(network)) : [];
|
|
59
|
+
const aaveV4Spokes = has(PortfolioProtocol.AaveV4) ? supported(AaveV4Spokes(network), network) : [];
|
|
60
|
+
const compoundV3Markets = has(PortfolioProtocol.CompoundV3) ? supported(CompoundMarkets(network), network).filter((m) => m.value !== CompoundVersions.CompoundV2) : [];
|
|
61
|
+
const compoundV2Markets = has(PortfolioProtocol.CompoundV2) ? [CompoundMarkets(network)[CompoundVersions.CompoundV2]].filter((m) => m.chainIds.includes(network)) : [];
|
|
62
|
+
const sparkMarkets = has(PortfolioProtocol.Spark) ? supported(SparkMarkets(network), network) : [];
|
|
63
|
+
const morphoMarkets = has(PortfolioProtocol.MorphoBlue) ? supported(MorphoBlueMarkets(network), network) : [];
|
|
64
|
+
const morphoMidnightMarkets = has(PortfolioProtocol.MorphoMidnight) ? supported(MorphoMidnightMarkets(network), network) : [];
|
|
65
|
+
const crvUsdMarkets = has(PortfolioProtocol.CrvUsd) ? supported(CrvUsdMarkets(network), network) : [];
|
|
66
|
+
const llamaLendMarkets = has(PortfolioProtocol.LlamaLend) && [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? supported(LlamaLendMarkets(network), network) : [];
|
|
67
|
+
const liquityV2Markets = has(PortfolioProtocol.LiquityV2) && isMainnet ? Object.values(LiquityV2Markets(network)) : [];
|
|
68
|
+
const liquityV2StakingMarkets = liquityV2Markets.filter((m) => !m.isLegacy);
|
|
69
|
+
const fetchMaker = has(PortfolioProtocol.Maker) && isMainnet;
|
|
70
|
+
const fetchLiquity = has(PortfolioProtocol.Liquity) && isMainnet;
|
|
71
|
+
const fetchFluid = has(PortfolioProtocol.Fluid) && isFluidSupported;
|
|
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: {},
|
|
84
|
+
fluidMarketsData: {},
|
|
85
|
+
makerMarketsData: {},
|
|
86
|
+
};
|
|
87
|
+
const makerCdps = {};
|
|
88
|
+
const positions = {};
|
|
89
|
+
const stakingPositions = {};
|
|
90
|
+
const rewardsData = {};
|
|
91
|
+
for (const address of addresses) {
|
|
92
|
+
positions[lower(address)] = {
|
|
93
|
+
aaveV3: {},
|
|
94
|
+
aaveV4: {},
|
|
95
|
+
morphoBlue: {},
|
|
96
|
+
morphoMidnight: {},
|
|
97
|
+
compoundV3: {},
|
|
98
|
+
spark: {},
|
|
99
|
+
maker: {},
|
|
100
|
+
aaveV2: {},
|
|
101
|
+
compoundV2: {},
|
|
102
|
+
liquity: {},
|
|
103
|
+
crvUsd: {},
|
|
104
|
+
llamaLend: {},
|
|
105
|
+
fluid: { error: '', data: {} },
|
|
106
|
+
};
|
|
107
|
+
if (fetchStaking) {
|
|
108
|
+
stakingPositions[lower(address)] = {
|
|
109
|
+
aaveV3: {}, morphoBlue: {}, liquity: {}, liquityV2: {}, fluid: { error: '', data: {} },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (fetchRewards) {
|
|
113
|
+
rewardsData[lower(address)] = {
|
|
114
|
+
merkl: {}, aaveV3: {}, spark: {}, spk: {}, king: {}, ethena: {}, uniswap: {},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const run = (label, fetch, store, onError) => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
try {
|
|
120
|
+
store(yield fetch());
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error(`Error fetching ${label}:`, error);
|
|
124
|
+
onError({ error: `Error fetching ${label}`, data: null });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
const perAddress = (list, task) => list.map((m) => addresses.map((a) => task(m, a))).flat();
|
|
128
|
+
const batchRewards = (key, label, fetch, enabled = true) => (() => __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
if (!enabled) {
|
|
130
|
+
for (const address of addresses)
|
|
131
|
+
rewardsData[lower(address)][key] = { error: '', data: [] };
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const result = yield fetch();
|
|
136
|
+
for (const address of addresses)
|
|
137
|
+
rewardsData[lower(address)][key] = { error: '', data: result[lower(address)] || [] };
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error(`Error fetching ${label}:`, error);
|
|
141
|
+
for (const address of addresses)
|
|
142
|
+
rewardsData[lower(address)][key] = { error: `Error fetching ${label}`, data: null };
|
|
143
|
+
}
|
|
144
|
+
}))();
|
|
145
|
+
yield Promise.allSettled([
|
|
146
|
+
...morphoMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.morphoMarketsData[m.value] = yield _getMorphoBluePortfolioMarketData(client, network, m, blockNumber); })),
|
|
147
|
+
...morphoMidnightMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.morphoMidnightMarketsData[m.value] = yield _getMorphoMidnightMarketData(client, network, m, blockNumber); })),
|
|
148
|
+
...compoundV3Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.compoundV3MarketsData[m.value] = yield _getCompoundV3MarketsData(client, network, m, defaultClient, blockNumber, blockTimestamp); })),
|
|
149
|
+
...sparkMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.sparkMarketsData[m.value] = yield _getSparkMarketsData(client, network, m, blockNumber); })),
|
|
150
|
+
...aaveV3Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.aaveV3MarketsData[m.value] = yield _getAaveV3MarketData(client, network, m, blockNumber, blockTimestamp); })),
|
|
151
|
+
...aaveV4Spokes.map((s) => __awaiter(this, void 0, void 0, function* () { markets.aaveV4SpokesData[s.value] = yield _getAaveV4SpokeData(client, network, s, blockNumber, blockTimestamp); })),
|
|
152
|
+
...aaveV2Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.aaveV2MarketsData[m.value] = yield _getAaveV2MarketsData(client, network, m, blockNumber); })),
|
|
153
|
+
...compoundV2Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.compoundV2MarketsData[m.value] = yield _getCompoundV2MarketsData(client, network, blockNumber); })),
|
|
154
|
+
...crvUsdMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.crvUsdMarketsData[m.value] = yield _getCurveUsdGlobalData(client, network, m, blockNumber); })),
|
|
155
|
+
...llamaLendMarkets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.llamaLendMarketsData[m.value] = yield _getLlamaLendGlobalData(client, network, m, blockNumber); })),
|
|
156
|
+
...liquityV2Markets.map((m) => __awaiter(this, void 0, void 0, function* () { markets.liquityV2MarketsData[m.value] = yield _getLiquityV2MarketData(client, network, m, blockNumber); })),
|
|
157
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
if (!fetchFluid || !fetchFluidMarkets)
|
|
159
|
+
return;
|
|
160
|
+
try {
|
|
161
|
+
markets.fluidMarketsData = yield _getAllFluidMarketDataPortfolio(client, network, blockNumber, blockTimestamp);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error('Error fetching Fluid markets data:', error);
|
|
165
|
+
}
|
|
166
|
+
}))(),
|
|
167
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
if (!fetchMaker)
|
|
169
|
+
return;
|
|
170
|
+
try {
|
|
171
|
+
markets.makerMarketsData = yield _getMakerIlksData(client, network, MakerActiveIlks, blockNumber);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.error('Error fetching Maker ilks data:', error);
|
|
175
|
+
}
|
|
176
|
+
}))(),
|
|
177
|
+
...addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
if (!fetchMaker)
|
|
179
|
+
return;
|
|
180
|
+
makerCdps[lower(address)] = yield _getUserCdps(client, network, address, blockNumber);
|
|
181
|
+
})),
|
|
182
|
+
...addresses.map((address) => fetchFluid && run(`Fluid positions for address ${address}`, () => _getUserPositionsPortfolio(client, network, address, blockNumber), (userPositions) => {
|
|
183
|
+
for (const position of userPositions) {
|
|
184
|
+
if (position.userData && positive(position.userData.suppliedUsd))
|
|
185
|
+
positions[lower(address)].fluid.data[position.userData.nftId] = position.userData;
|
|
186
|
+
}
|
|
187
|
+
}, (err) => { positions[lower(address)].fluid = { error: err.error, data: {} }; })),
|
|
188
|
+
...(fetchStaking ? [
|
|
189
|
+
...addresses.map((address) => fetchFluid && run(`Fluid lend data for address ${address}`, () => _getAllUserEarnPositionsWithFTokens(client, network, address, blockNumber), (data) => { stakingPositions[lower(address)].fluid = data; }, (err) => { stakingPositions[lower(address)].fluid = err; })),
|
|
190
|
+
...addresses.map((address) => fetchLiquity && run(`Liquity staking data for address ${address}`, () => getLiquityStakingData(client, network, address, blockNumber), (data) => { stakingPositions[lower(address)].liquity = data; }, (err) => { stakingPositions[lower(address)].liquity = err; })),
|
|
191
|
+
...addresses.map((address) => has(PortfolioProtocol.AaveV3) && isMainnet && run(`Aave V3 staking data for address ${address}`, () => getStakeAaveData(client, network, address, blockNumber), (data) => { stakingPositions[lower(address)].aaveV3 = data; }, (err) => { stakingPositions[lower(address)].aaveV3 = err; })),
|
|
192
|
+
...addresses.map((address) => has(PortfolioProtocol.AaveV3) && isMainnet && run(`Umbrella staking data for address ${address}`, () => getUmbrellaData(client, network, address, blockNumber), (data) => { stakingPositions[lower(address)].umbrella = data; }, (err) => { stakingPositions[lower(address)].umbrella = err; })),
|
|
193
|
+
...perAddress(liquityV2StakingMarkets, (market, address) => run(`Liquity V2 staking data for address ${address}, market ${market.value}`, () => getLiquityV2Staking(client, network, market.value, address, blockNumber), (data) => { stakingPositions[lower(address)].liquityV2[market.value] = { error: '', data }; }, (err) => { stakingPositions[lower(address)].liquityV2[market.value] = err; })),
|
|
194
|
+
] : []),
|
|
195
|
+
...(fetchRewards ? [
|
|
196
|
+
batchRewards('king', 'King rewards data', () => getKingRewards(client, network, addresses, blockNumber), isMainnet),
|
|
197
|
+
batchRewards('uniswap', 'Uniswap rewards data', () => getUniswapRewards(client, network, addresses, blockNumber), isMainnet),
|
|
198
|
+
batchRewards('spk', 'Spark Airdrop rewards data', () => fetchSparkAirdropRewards(client, network, addresses, blockNumber), isMainnet && has(PortfolioProtocol.Spark)),
|
|
199
|
+
batchRewards('ethena', 'Ethena Airdrop rewards data', () => fetchEthenaAirdropRewards(addresses), isMainnet),
|
|
200
|
+
...addresses.map((address) => run(`Merkl rewards data for address ${address}`, () => getMerklUnclaimedRewards(address, network), (data) => { rewardsData[lower(address)].merkl = { error: '', data }; }, (err) => { rewardsData[lower(address)].merkl = err; })),
|
|
201
|
+
...perAddress(aaveV3Markets, (market, address) => run(`Aave V3 rewards data for address ${address}, market ${market.value}`, () => getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress, blockNumber), (data) => { rewardsData[lower(address)].aaveV3[market.value] = { error: '', data }; }, (err) => { rewardsData[lower(address)].aaveV3[market.value] = err; })),
|
|
202
|
+
...perAddress(sparkMarkets, (market, address) => {
|
|
203
|
+
if (!isMainnet) {
|
|
204
|
+
rewardsData[lower(address)].spark[market.value] = { error: '', data: [] };
|
|
205
|
+
return Promise.resolve();
|
|
206
|
+
}
|
|
207
|
+
return run(`Spark rewards data for address ${address}, market ${market.value}`, () => fetchSparkRewards(client, network, address, market.providerAddress, blockNumber), (data) => { rewardsData[lower(address)].spark[market.value] = { error: '', data }; }, (err) => { rewardsData[lower(address)].spark[market.value] = err; });
|
|
208
|
+
}),
|
|
209
|
+
] : []),
|
|
210
|
+
]);
|
|
211
|
+
yield Promise.all([
|
|
212
|
+
...perAddress(aaveV3Markets, (market, address) => run(`AaveV3 account data for address ${address} on market ${market.value}`, () => _getAaveV3AccountData(client, network, address, Object.assign({ selectedMarket: market }, markets.aaveV3MarketsData[market.value]), blockNumber), (data) => { if (returnEmptyEModePositions || positive(data.suppliedUsd))
|
|
213
|
+
positions[lower(address)].aaveV3[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].aaveV3[market.value] = err; })),
|
|
214
|
+
...perAddress(sparkMarkets, (market, address) => run(`Spark account data for address ${address} on market ${market.value}`, () => _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData }, blockNumber), (data) => { if (returnEmptyEModePositions || positive(data.suppliedUsd))
|
|
215
|
+
positions[lower(address)].spark[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].spark[market.value] = err; })),
|
|
216
|
+
...perAddress(aaveV4Spokes, (spoke, address) => run(`AaveV4 account data for address ${address} on spoke ${spoke.value}`, () => _getAaveV4AccountData(client, network, markets.aaveV4SpokesData[spoke.value], address, blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
217
|
+
positions[lower(address)].aaveV4[spoke.value] = { error: '', data }; }, (err) => { positions[lower(address)].aaveV4[spoke.value] = err; })),
|
|
218
|
+
...perAddress(morphoMarkets, (market, address) => run(`MorphoBlue account data for address ${address} on market ${market.value}`, () => _getMorphoBlueAccountData(client, network, address, market, markets.morphoMarketsData[market.value], blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
219
|
+
positions[lower(address)].morphoBlue[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].morphoBlue[market.value] = err; })),
|
|
220
|
+
...(fetchStaking ? perAddress(morphoMarkets, (market, address) => run(`MorphoBlue earn data for address ${address} on market ${market.value}`, () => getMorphoEarn(client, network, address, market, markets.morphoMarketsData[market.value], blockNumber), (data) => { if (data && positive(data.amount))
|
|
221
|
+
stakingPositions[lower(address)].morphoBlue[market.value] = { error: '', data }; }, (err) => { stakingPositions[lower(address)].morphoBlue[market.value] = err; })) : []),
|
|
222
|
+
...perAddress(morphoMidnightMarkets, (market, address) => {
|
|
223
|
+
var _a;
|
|
224
|
+
if (!((_a = markets.morphoMidnightMarketsData[market.value]) === null || _a === void 0 ? void 0 : _a.isCreated))
|
|
225
|
+
return Promise.resolve();
|
|
226
|
+
return run(`MorphoMidnight account data for address ${address} on market ${market.value}`, () => _getMorphoMidnightAccountData(client, network, address, market, markets.morphoMidnightMarketsData[market.value], blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
227
|
+
positions[lower(address)].morphoMidnight[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].morphoMidnight[market.value] = err; });
|
|
228
|
+
}),
|
|
229
|
+
...perAddress(compoundV3Markets, (market, address) => run(`CompoundV3 account data for address ${address} on market ${market.value}`, () => _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData }, blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
230
|
+
positions[lower(address)].compoundV3[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].compoundV3[market.value] = err; })),
|
|
231
|
+
...perAddress(compoundV2Markets, (market, address) => run(`CompoundV2 account data for address ${address}`, () => _getCompoundV2AccountData(client, network, address, markets.compoundV2MarketsData[market.value].assetsData, blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
232
|
+
positions[lower(address)].compoundV2[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].compoundV2[market.value] = err; })),
|
|
233
|
+
...perAddress(aaveV2Markets, (market, address) => run(`AaveV2 account data for address ${address}`, () => _getAaveV2AccountData(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market, blockNumber), (data) => { if (positive(data.suppliedUsd))
|
|
234
|
+
positions[lower(address)].aaveV2[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].aaveV2[market.value] = err; })),
|
|
235
|
+
...perAddress(crvUsdMarkets, (market, address) => run(`Curve USD account data for address ${address} on market ${market.value}`, () => _getCurveUsdUserData(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand, markets.crvUsdMarketsData[market.value].borrowRate, blockNumber), (data) => { if (positive(data.suppliedUsd) || positive(data.borrowedUsd))
|
|
236
|
+
positions[lower(address)].crvUsd[market.value] = { error: '', data }; }, (err) => { positions[lower(address)].crvUsd[market.value] = err; })),
|
|
237
|
+
...perAddress(llamaLendMarkets, (market, address) => run(`LlamaLend account data for address ${address} on market ${market.value}`, () => _getLlamaLendUserData(client, network, address, market, markets.llamaLendMarketsData[market.value], blockNumber), (data) => {
|
|
238
|
+
if (positive(data.suppliedUsd) || positive(data.borrowedUsd)) {
|
|
239
|
+
positions[lower(address)].llamaLend[market.value] = { error: '', data: Object.assign(Object.assign({}, data), { borrowRate: markets.llamaLendMarketsData[market.value].borrowRate }) };
|
|
240
|
+
}
|
|
241
|
+
}, (err) => { positions[lower(address)].llamaLend[market.value] = err; })),
|
|
242
|
+
...addresses.map((address) => (makerCdps[lower(address)] || []).map((cdpInfo) => run(`Maker CDP data for address ${address} with ID ${cdpInfo.id}`, () => _getMakerCdpData(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel], blockNumber), (data) => { if (data)
|
|
243
|
+
positions[lower(address)].maker[cdpInfo.id] = { error: '', data }; }, (err) => { positions[lower(address)].maker[cdpInfo.id] = err; }))).flat(),
|
|
244
|
+
...addresses.map((address) => fetchLiquity && run(`Liquity trove info for address ${address}`, () => _getLiquityTroveInfo(client, network, address, blockNumber), (data) => { if (positive(data.collateral))
|
|
245
|
+
positions[lower(address)].liquity = { error: '', data }; }, (err) => { positions[lower(address)].liquity = err; })),
|
|
246
|
+
...(fetchStaking && has(PortfolioProtocol.LiquityV2) ? addresses.map((address) => {
|
|
247
|
+
if (!isMainnet) {
|
|
248
|
+
stakingPositions[lower(address)].liquityV2SBoldYBold = { error: '', data: null };
|
|
249
|
+
return Promise.resolve();
|
|
250
|
+
}
|
|
251
|
+
return run(`sBold/yBold data for address ${address}`, () => getLiquitySAndYBold(client, network, stakingPositions[lower(address)].liquityV2, address, blockNumber), (data) => { stakingPositions[lower(address)].liquityV2SBoldYBold = { error: '', data }; }, (err) => { stakingPositions[lower(address)].liquityV2SBoldYBold = err; });
|
|
252
|
+
}) : []),
|
|
253
|
+
]);
|
|
254
|
+
return {
|
|
255
|
+
positions,
|
|
256
|
+
stakingPositions,
|
|
257
|
+
rewardsData,
|
|
258
|
+
markets,
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
}
|
package/esm/portfolio/index.d.ts
CHANGED