@defisaver/positions-sdk 2.1.151-midnight-3-dev → 2.1.152-shifter-v2-dev-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/fluid/index.d.ts +2 -0
- package/cjs/fluid/index.js +36 -1
- package/cjs/maker/index.d.ts +7 -2
- package/cjs/maker/index.js +27 -10
- package/cjs/markets/aaveV4/index.d.ts +2 -0
- package/cjs/markets/aaveV4/index.js +13 -1
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/maker/index.d.ts +1 -0
- package/cjs/markets/maker/index.js +13 -0
- package/cjs/portfolio/index.d.ts +5 -1
- package/cjs/portfolio/index.js +287 -0
- package/cjs/types/aaveV4.d.ts +1 -0
- package/cjs/types/aaveV4.js +1 -0
- package/cjs/types/portfolio.d.ts +26 -10
- package/esm/fluid/index.d.ts +2 -0
- package/esm/fluid/index.js +33 -0
- package/esm/maker/index.d.ts +7 -2
- package/esm/maker/index.js +26 -11
- package/esm/markets/aaveV4/index.d.ts +2 -0
- package/esm/markets/aaveV4/index.js +11 -0
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/maker/index.d.ts +1 -0
- package/esm/markets/maker/index.js +10 -0
- package/esm/portfolio/index.d.ts +5 -1
- package/esm/portfolio/index.js +289 -3
- package/esm/types/aaveV4.d.ts +1 -0
- package/esm/types/aaveV4.js +1 -0
- package/esm/types/portfolio.d.ts +26 -10
- package/package.json +2 -2
- package/src/fluid/index.ts +40 -0
- package/src/maker/index.ts +56 -28
- package/src/markets/aaveV4/index.ts +12 -0
- package/src/markets/index.ts +2 -1
- package/src/markets/maker/index.ts +10 -0
- package/src/portfolio/index.ts +270 -2
- package/src/types/aaveV4.ts +1 -0
- package/src/types/portfolio.ts +31 -12
package/src/fluid/index.ts
CHANGED
|
@@ -1830,3 +1830,43 @@ export const _getUserPositionsPortfolio = async (provider: PublicClient, network
|
|
|
1830
1830
|
userData: userData[i],
|
|
1831
1831
|
})).filter(md => md.marketData !== undefined);
|
|
1832
1832
|
};
|
|
1833
|
+
|
|
1834
|
+
|
|
1835
|
+
export const _getAllFluidMarketDataPortfolio = async (provider: PublicClient, network: NetworkNumber): Promise<Record<string, FluidMarketData>> => {
|
|
1836
|
+
const versions = getFluidVersionsDataForNetwork(network);
|
|
1837
|
+
if (versions.length === 0) return {};
|
|
1838
|
+
|
|
1839
|
+
const view = FluidViewContractViem(provider, network);
|
|
1840
|
+
const vaultsData = await Promise.all(versions.map((version) => view.read.getVaultData([version.marketAddress])));
|
|
1841
|
+
|
|
1842
|
+
const tokens = Array.from(new Set(vaultsData.map((vaultData) => {
|
|
1843
|
+
const vaultTokens = [getAssetInfoByAddress(vaultData.supplyToken0, network).symbol, getAssetInfoByAddress(vaultData.borrowToken0, network).symbol];
|
|
1844
|
+
if (vaultData.supplyToken1 && !compareAddresses(ZERO_ADDRESS, vaultData.supplyToken1)) vaultTokens.push(getAssetInfoByAddress(vaultData.supplyToken1, network).symbol);
|
|
1845
|
+
if (vaultData.borrowToken1 && !compareAddresses(ZERO_ADDRESS, vaultData.borrowToken1)) vaultTokens.push(getAssetInfoByAddress(vaultData.borrowToken1, network).symbol);
|
|
1846
|
+
return vaultTokens;
|
|
1847
|
+
}).flat()));
|
|
1848
|
+
|
|
1849
|
+
// ETH and WBTC needed for other tokens prices
|
|
1850
|
+
if (!tokens.includes('ETH')) tokens.push('ETH');
|
|
1851
|
+
if (!tokens.includes('WBTC')) tokens.push('WBTC');
|
|
1852
|
+
|
|
1853
|
+
const [tokenPrices, merklCampaigns] = await Promise.all([
|
|
1854
|
+
getTokensPricesForPortfolio(tokens, provider, network),
|
|
1855
|
+
getFluidMerklCampaigns(network),
|
|
1856
|
+
]);
|
|
1857
|
+
|
|
1858
|
+
const parsedMarketsData = await Promise.all(vaultsData.map(async (vaultData) => parseMarketData(provider, vaultData, network, tokenPrices)));
|
|
1859
|
+
|
|
1860
|
+
const marketsData: Record<string, FluidMarketData> = {};
|
|
1861
|
+
parsedMarketsData.forEach((marketData, i) => {
|
|
1862
|
+
if (!marketData) return;
|
|
1863
|
+
marketsData[versions[i].value] = attachFluidMerklIncentives(marketData, merklCampaigns);
|
|
1864
|
+
});
|
|
1865
|
+
|
|
1866
|
+
return marketsData;
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
export const getAllFluidMarketDataPortfolio = async (
|
|
1870
|
+
provider: EthereumProvider,
|
|
1871
|
+
network: NetworkNumber,
|
|
1872
|
+
): Promise<Record<string, FluidMarketData>> => _getAllFluidMarketDataPortfolio(getViemProvider(provider, network, { batch: { multicall: true } }), network);
|
package/src/maker/index.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import {
|
|
3
|
-
assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset,
|
|
3
|
+
assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset, stringToBytes,
|
|
4
4
|
} from '@defisaver/tokens';
|
|
5
5
|
import { Client, PublicClient } from 'viem';
|
|
6
6
|
import {
|
|
7
|
-
Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances,
|
|
7
|
+
Blockish, EthAddress, EthereumProvider, HexString, NetworkNumber, PositionBalances,
|
|
8
8
|
} from '../types/common';
|
|
9
9
|
import {
|
|
10
10
|
getConfigContractAddress, McdDogContractViem, McdGetCdpsContractViem, McdJugContractViem, McdSpotterContractViem, McdVatContractViem, McdViewContractViem,
|
|
11
11
|
} from '../contracts';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
CdpData, CdpInfo, CdpType, IlkInfo,
|
|
14
|
+
} from '../types';
|
|
13
15
|
import { wethToEth } from '../services/utils';
|
|
14
16
|
import { parseCollateralInfo } from '../helpers/makerHelpers';
|
|
15
17
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
@@ -129,44 +131,70 @@ export const getUserCdps = async (
|
|
|
129
131
|
userAddress: EthAddress,
|
|
130
132
|
): Promise<CdpInfo[]> => _getUserCdps(getViemProvider(provider, network), network, userAddress);
|
|
131
133
|
|
|
132
|
-
export const
|
|
134
|
+
export const _getMakerIlksData = async (provider: Client, network: NetworkNumber, ilkLabels: string[]): Promise<Record<string, IlkInfo>> => {
|
|
133
135
|
const vatContract = McdVatContractViem(provider, network);
|
|
134
136
|
const spotterContract = McdSpotterContractViem(provider, network);
|
|
135
137
|
const dogContract = McdDogContractViem(provider, network);
|
|
136
138
|
const jugContract = McdJugContractViem(provider, network);
|
|
137
139
|
|
|
140
|
+
const par = await spotterContract.read.par();
|
|
141
|
+
|
|
142
|
+
const ilksInfo = await Promise.all(ilkLabels.map(async (ilkLabel) => {
|
|
143
|
+
const ilk = stringToBytes(ilkLabel) as HexString;
|
|
144
|
+
const [
|
|
145
|
+
[_, mat],
|
|
146
|
+
[artGlobal, rate, spot, line],
|
|
147
|
+
[duty],
|
|
148
|
+
futureRate,
|
|
149
|
+
chop,
|
|
150
|
+
] = await Promise.all([
|
|
151
|
+
spotterContract.read.ilks([ilk]),
|
|
152
|
+
vatContract.read.ilks([ilk]),
|
|
153
|
+
jugContract.read.ilks([ilk]),
|
|
154
|
+
jugContract.read.drip([ilk]),
|
|
155
|
+
dogContract.read.chop([ilk]),
|
|
156
|
+
]);
|
|
157
|
+
|
|
158
|
+
return parseCollateralInfo(
|
|
159
|
+
ilk,
|
|
160
|
+
par.toString(),
|
|
161
|
+
mat.toString(),
|
|
162
|
+
artGlobal.toString(),
|
|
163
|
+
rate.toString(),
|
|
164
|
+
spot.toString(),
|
|
165
|
+
line.toString(),
|
|
166
|
+
duty.toString(),
|
|
167
|
+
futureRate.toString(),
|
|
168
|
+
chop.toString(),
|
|
169
|
+
);
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
return Object.fromEntries(ilksInfo.map((ilkInfo) => [ilkInfo.ilkLabel, ilkInfo]));
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const getMakerIlksData = async (
|
|
176
|
+
provider: EthereumProvider,
|
|
177
|
+
network: NetworkNumber,
|
|
178
|
+
ilkLabels: string[],
|
|
179
|
+
): Promise<Record<string, IlkInfo>> => _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels);
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
|
|
183
|
+
*/
|
|
184
|
+
export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo, ilkInfo?: IlkInfo): Promise<CdpData> => {
|
|
185
|
+
const vatContract = McdVatContractViem(provider, network);
|
|
186
|
+
|
|
138
187
|
const [
|
|
139
188
|
[ink, art],
|
|
140
189
|
coll,
|
|
141
|
-
|
|
142
|
-
[_, mat],
|
|
143
|
-
[artGlobal, rate, spot, line],
|
|
144
|
-
[duty],
|
|
145
|
-
futureRate,
|
|
146
|
-
chop,
|
|
190
|
+
fetchedIlkInfo,
|
|
147
191
|
] = await Promise.all([
|
|
148
192
|
vatContract.read.urns([cdp.ilk, cdp.urn]),
|
|
149
193
|
vatContract.read.gem([cdp.ilk, cdp.urn]),
|
|
150
|
-
|
|
151
|
-
spotterContract.read.ilks([cdp.ilk]),
|
|
152
|
-
vatContract.read.ilks([cdp.ilk]),
|
|
153
|
-
jugContract.read.ilks([cdp.ilk]),
|
|
154
|
-
jugContract.read.drip([cdp.ilk]),
|
|
155
|
-
dogContract.read.chop([cdp.ilk]),
|
|
194
|
+
ilkInfo || _getMakerIlksData(provider, network, [cdp.ilkLabel]).then((ilks) => ilks[cdp.ilkLabel]),
|
|
156
195
|
]);
|
|
157
196
|
|
|
158
|
-
const collInfo =
|
|
159
|
-
cdp.ilk,
|
|
160
|
-
par.toString(),
|
|
161
|
-
mat.toString(),
|
|
162
|
-
artGlobal.toString(),
|
|
163
|
-
rate.toString(),
|
|
164
|
-
spot.toString(),
|
|
165
|
-
line.toString(),
|
|
166
|
-
duty.toString(),
|
|
167
|
-
futureRate.toString(),
|
|
168
|
-
chop.toString(),
|
|
169
|
-
);
|
|
197
|
+
const collInfo = fetchedIlkInfo;
|
|
170
198
|
|
|
171
199
|
const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
|
|
172
200
|
|
|
@@ -181,6 +181,17 @@ export const AAVE_V4_MAIN_SPOKE = (networkId: NetworkNumber): AaveV4SpokeInfo =>
|
|
|
181
181
|
],
|
|
182
182
|
});
|
|
183
183
|
|
|
184
|
+
export const AAVE_V4_PAXG_GOLD_SPOKE = (networkId: NetworkNumber): AaveV4SpokeInfo => ({
|
|
185
|
+
chainIds: [NetworkNumber.Eth],
|
|
186
|
+
label: 'PAXG Gold',
|
|
187
|
+
value: AaveV4SpokesType.AaveV4PaxgGoldSpoke,
|
|
188
|
+
url: 'paxg-gold',
|
|
189
|
+
address: '0xAD75cE6354f87F3135cE10621d385d8D1e2562C2',
|
|
190
|
+
hubs: [
|
|
191
|
+
AAVE_V4_PAXOS_HUB(NetworkNumber.Eth).address,
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
|
|
184
195
|
export const AAVE_V4_USDG_PENDLE_SPOKE = (networkId: NetworkNumber): AaveV4SpokeInfo => ({
|
|
185
196
|
chainIds: [NetworkNumber.Eth],
|
|
186
197
|
label: 'USDG Pendle',
|
|
@@ -216,6 +227,7 @@ export const AaveV4Spokes = (networkId: NetworkNumber) => ({
|
|
|
216
227
|
[AaveV4SpokesType.AaveV4LidoSpoke]: AAVE_V4_LIDO_SPOKE(networkId),
|
|
217
228
|
[AaveV4SpokesType.AaveV4LombardBtcSpoke]: AAVE_V4_LOMBARD_BTC_SPOKE(networkId),
|
|
218
229
|
[AaveV4SpokesType.AaveV4MainSpoke]: AAVE_V4_MAIN_SPOKE(networkId),
|
|
230
|
+
[AaveV4SpokesType.AaveV4PaxgGoldSpoke]: AAVE_V4_PAXG_GOLD_SPOKE(networkId),
|
|
219
231
|
[AaveV4SpokesType.AaveV4USDGPendleSpoke]: AAVE_V4_USDG_PENDLE_SPOKE(networkId),
|
|
220
232
|
[AaveV4SpokesType.AaveV4USDGMapleSpoke]: AAVE_V4_USDG_MAPLE_SPOKE(networkId),
|
|
221
233
|
}) as const;
|
package/src/markets/index.ts
CHANGED
|
@@ -30,4 +30,5 @@ export {
|
|
|
30
30
|
getFTokenAddress,
|
|
31
31
|
getFluidMarketInfoByAddress,
|
|
32
32
|
} from './fluid';
|
|
33
|
-
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|
|
33
|
+
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|
|
34
|
+
export { MakerActiveIlks } from './maker';
|
package/src/portfolio/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CrvUsdMarkets,
|
|
8
8
|
LiquityV2Markets,
|
|
9
9
|
LlamaLendMarkets,
|
|
10
|
+
MakerActiveIlks,
|
|
10
11
|
MorphoBlueMarkets,
|
|
11
12
|
MorphoMidnightMarkets,
|
|
12
13
|
SparkMarkets,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
LlamaLendGlobalMarketData,
|
|
28
29
|
MorphoBlueMarketInfo,
|
|
29
30
|
MorphoMidnightMarketInfo,
|
|
31
|
+
PortfolioMarketsData,
|
|
30
32
|
PortfolioPositionsData,
|
|
31
33
|
SparkMarketsData,
|
|
32
34
|
} from '../types';
|
|
@@ -36,13 +38,13 @@ import { _getCurveUsdGlobalData, _getCurveUsdUserData } from '../curveUsd';
|
|
|
36
38
|
import { _getLlamaLendGlobalData, _getLlamaLendUserData } from '../llamaLend';
|
|
37
39
|
import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
|
|
38
40
|
import { ZERO_ADDRESS } from '../constants';
|
|
39
|
-
import { _getMakerCdpData, _getUserCdps } from '../maker';
|
|
41
|
+
import { _getMakerCdpData, _getMakerIlksData, _getUserCdps } from '../maker';
|
|
40
42
|
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
41
43
|
import { _getCompoundV2AccountData, _getCompoundV2MarketsData } from '../compoundV2';
|
|
42
44
|
import { getViemProvider } from '../services/viem';
|
|
43
45
|
import { _getLiquityTroveInfo, getLiquityStakingData } from '../liquity';
|
|
44
46
|
import { _getLiquityV2MarketData, getLiquitySAndYBold, getLiquityV2Staking } from '../liquityV2';
|
|
45
|
-
import { _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
47
|
+
import { _getAllFluidMarketDataPortfolio, _getAllUserEarnPositionsWithFTokens, _getUserPositionsPortfolio } from '../fluid';
|
|
46
48
|
import { getUmbrellaData } from '../umbrella';
|
|
47
49
|
import { getMerklUnclaimedRewards, getUnclaimedRewardsForAllMarkets } from '../claiming/aaveV3';
|
|
48
50
|
import { getCompoundV3Rewards } from '../claiming/compV3';
|
|
@@ -596,4 +598,270 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
|
|
|
596
598
|
};
|
|
597
599
|
}
|
|
598
600
|
|
|
601
|
+
|
|
602
|
+
export async function getShifterPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim = false): Promise<{
|
|
603
|
+
positions: PortfolioPositionsData;
|
|
604
|
+
markets: PortfolioMarketsData;
|
|
605
|
+
}> {
|
|
606
|
+
const isMainnet = network === NetworkNumber.Eth;
|
|
607
|
+
const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
|
|
608
|
+
|
|
609
|
+
const morphoMarkets = Object.values(MorphoBlueMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
610
|
+
const morphoMidnightMarkets = Object.values(MorphoMidnightMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
611
|
+
const compoundV3Markets = Object.values(CompoundMarkets(network)).filter((market) => market.chainIds.includes(network) && market.value !== CompoundVersions.CompoundV2);
|
|
612
|
+
const sparkMarkets = Object.values(SparkMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
613
|
+
const aaveV3Markets = [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
614
|
+
const aaveV2Markets = [AaveVersions.AaveV2].map((version) => AaveMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
615
|
+
const compoundV2Markets = [CompoundVersions.CompoundV2].map((version) => CompoundMarkets(network)[version]).filter((market) => market.chainIds.includes(network));
|
|
616
|
+
const crvUsdMarkets = Object.values(CrvUsdMarkets(network)).filter((market) => market.chainIds.includes(network));
|
|
617
|
+
const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
|
|
618
|
+
const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
|
|
619
|
+
const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
|
|
620
|
+
|
|
621
|
+
const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 2_000 : 2_500_000 } } }];
|
|
622
|
+
const client = getViemProvider(provider, ...args);
|
|
623
|
+
const defaultClient = getViemProvider(defaultProvider, ...args);
|
|
624
|
+
|
|
625
|
+
const markets: PortfolioMarketsData = {
|
|
626
|
+
morphoMarketsData: {},
|
|
627
|
+
morphoMidnightMarketsData: {},
|
|
628
|
+
compoundV3MarketsData: {},
|
|
629
|
+
sparkMarketsData: {},
|
|
630
|
+
aaveV3MarketsData: {},
|
|
631
|
+
aaveV2MarketsData: {},
|
|
632
|
+
compoundV2MarketsData: {},
|
|
633
|
+
crvUsdMarketsData: {},
|
|
634
|
+
llamaLendMarketsData: {},
|
|
635
|
+
liquityV2MarketsData: {},
|
|
636
|
+
aaveV4SpokesData: {},
|
|
637
|
+
fluidMarketsData: {},
|
|
638
|
+
makerMarketsData: {},
|
|
639
|
+
};
|
|
640
|
+
const makerCdps: Record<string, CdpInfo[]> = {};
|
|
641
|
+
|
|
642
|
+
const positions: PortfolioPositionsData = {};
|
|
643
|
+
|
|
644
|
+
for (const address of addresses) {
|
|
645
|
+
positions[address.toLowerCase() as EthAddress] = {
|
|
646
|
+
aaveV3: {},
|
|
647
|
+
aaveV4: {},
|
|
648
|
+
morphoBlue: {},
|
|
649
|
+
morphoMidnight: {},
|
|
650
|
+
compoundV3: {},
|
|
651
|
+
spark: {},
|
|
652
|
+
maker: {},
|
|
653
|
+
aaveV2: {},
|
|
654
|
+
compoundV2: {},
|
|
655
|
+
liquity: {},
|
|
656
|
+
crvUsd: {},
|
|
657
|
+
llamaLend: {},
|
|
658
|
+
fluid: {
|
|
659
|
+
error: '',
|
|
660
|
+
data: {},
|
|
661
|
+
},
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
await Promise.allSettled([
|
|
666
|
+
// === MARKET DATA (needs to be fetched first) ===
|
|
667
|
+
...morphoMarkets.map(async (market) => {
|
|
668
|
+
markets.morphoMarketsData[market.value] = await _getMorphoBluePortfolioMarketData(client, network, market);
|
|
669
|
+
}),
|
|
670
|
+
...morphoMidnightMarkets.map(async (market) => {
|
|
671
|
+
markets.morphoMidnightMarketsData[market.value] = await _getMorphoMidnightMarketData(client, network, market);
|
|
672
|
+
}),
|
|
673
|
+
...compoundV3Markets.map(async (market) => {
|
|
674
|
+
markets.compoundV3MarketsData[market.value] = await _getCompoundV3MarketsData(client, network, market, defaultClient);
|
|
675
|
+
}),
|
|
676
|
+
...sparkMarkets.map(async (market) => {
|
|
677
|
+
markets.sparkMarketsData[market.value] = await _getSparkMarketsData(client, network, market);
|
|
678
|
+
}),
|
|
679
|
+
...aaveV3Markets.map(async (market) => {
|
|
680
|
+
markets.aaveV3MarketsData[market.value] = await _getAaveV3MarketData(client, network, market);
|
|
681
|
+
}),
|
|
682
|
+
...aaveV4Spokes.map(async (spoke) => {
|
|
683
|
+
markets.aaveV4SpokesData[spoke.value] = await _getAaveV4SpokeData(client, network, spoke);
|
|
684
|
+
}),
|
|
685
|
+
...aaveV2Markets.map(async (market) => {
|
|
686
|
+
markets.aaveV2MarketsData[market.value] = await _getAaveV2MarketsData(client, network, market);
|
|
687
|
+
}),
|
|
688
|
+
...compoundV2Markets.map(async (market) => {
|
|
689
|
+
markets.compoundV2MarketsData[market.value] = await _getCompoundV2MarketsData(client, network);
|
|
690
|
+
}),
|
|
691
|
+
...crvUsdMarkets.map(async (market) => {
|
|
692
|
+
markets.crvUsdMarketsData[market.value] = await _getCurveUsdGlobalData(client, network, market);
|
|
693
|
+
}),
|
|
694
|
+
...llamaLendMarkets.map(async (market) => {
|
|
695
|
+
markets.llamaLendMarketsData[market.value] = await _getLlamaLendGlobalData(client, network, market);
|
|
696
|
+
}),
|
|
697
|
+
...liquityV2Markets.map(async (market) => {
|
|
698
|
+
markets.liquityV2MarketsData[market.value] = await _getLiquityV2MarketData(client, network, market);
|
|
699
|
+
}),
|
|
700
|
+
(async () => {
|
|
701
|
+
if (!isFluidSupported) return;
|
|
702
|
+
try {
|
|
703
|
+
markets.fluidMarketsData = await _getAllFluidMarketDataPortfolio(client, network);
|
|
704
|
+
} catch (error) {
|
|
705
|
+
console.error('Error fetching Fluid markets data:', error);
|
|
706
|
+
}
|
|
707
|
+
})(),
|
|
708
|
+
(async () => {
|
|
709
|
+
if (!isMainnet) return; // Maker CDPs are only available on mainnet
|
|
710
|
+
try {
|
|
711
|
+
markets.makerMarketsData = await _getMakerIlksData(client, network, MakerActiveIlks);
|
|
712
|
+
} catch (error) {
|
|
713
|
+
console.error('Error fetching Maker ilks data:', error);
|
|
714
|
+
}
|
|
715
|
+
})(),
|
|
716
|
+
|
|
717
|
+
// === INDEPENDENT USER DATA (doesn't depend on market data) ===
|
|
718
|
+
...addresses.map(async (address) => {
|
|
719
|
+
if (!isMainnet) return; // Maker CDPs are only available on mainnet
|
|
720
|
+
const makerCdp = await _getUserCdps(client, network, address);
|
|
721
|
+
makerCdps[address.toLowerCase() as EthAddress] = makerCdp;
|
|
722
|
+
}),
|
|
723
|
+
...addresses.map(async (address) => {
|
|
724
|
+
try {
|
|
725
|
+
if (!isFluidSupported) return; // Fluid is not available on Optimism
|
|
726
|
+
const userPositions = (await _getUserPositionsPortfolio(client, network, address));
|
|
727
|
+
for (const position of userPositions) {
|
|
728
|
+
if (position.userData && new Dec(position.userData.suppliedUsd).gt(0)) {
|
|
729
|
+
positions[address.toLowerCase() as EthAddress].fluid.data[position.userData.nftId] = position.userData;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
} catch (error) {
|
|
733
|
+
console.error(`Error fetching Fluid positions for address ${address}:`, error);
|
|
734
|
+
positions[address.toLowerCase() as EthAddress].fluid = {
|
|
735
|
+
error: `Error fetching Fluid positions for address ${address}`,
|
|
736
|
+
data: {},
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
}),
|
|
740
|
+
]);
|
|
741
|
+
|
|
742
|
+
await Promise.all([
|
|
743
|
+
...aaveV3Markets.map((market) => addresses.map(async (address) => {
|
|
744
|
+
try {
|
|
745
|
+
const accData = await _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...markets.aaveV3MarketsData[market.value] });
|
|
746
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: '', data: accData };
|
|
747
|
+
} catch (error) {
|
|
748
|
+
console.error(`Error fetching AaveV3 account data for address ${address} on market ${market.value}:`, error);
|
|
749
|
+
positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
750
|
+
}
|
|
751
|
+
})).flat(),
|
|
752
|
+
...aaveV4Spokes.map((spoke) => addresses.map(async (address) => {
|
|
753
|
+
try {
|
|
754
|
+
const accData = await _getAaveV4AccountData(client, network, markets.aaveV4SpokesData[spoke.value], address);
|
|
755
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
|
|
756
|
+
} catch (error) {
|
|
757
|
+
console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
|
|
758
|
+
positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
|
|
759
|
+
}
|
|
760
|
+
})).flat(),
|
|
761
|
+
...morphoMarkets.map((market) => addresses.map(async (address) => {
|
|
762
|
+
try {
|
|
763
|
+
const accData = await _getMorphoBlueAccountData(client, network, address, market, markets.morphoMarketsData[market.value]);
|
|
764
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: '', data: accData };
|
|
765
|
+
} catch (error) {
|
|
766
|
+
console.error(`Error fetching MorphoBlue account data for address ${address} on market ${market.value}:`, error);
|
|
767
|
+
positions[address.toLowerCase() as EthAddress].morphoBlue[market.value] = { error: `Error fetching MorphoBlue account data for address ${address} on market ${market.value}`, data: null };
|
|
768
|
+
}
|
|
769
|
+
})).flat(),
|
|
770
|
+
...morphoMidnightMarkets.map((market) => addresses.map(async (address) => {
|
|
771
|
+
try {
|
|
772
|
+
const accData = await _getMorphoMidnightAccountData(client, network, address, market, markets.morphoMidnightMarketsData[market.value]);
|
|
773
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: '', data: accData };
|
|
774
|
+
} catch (error) {
|
|
775
|
+
console.error(`Error fetching MorphoMidnight account data for address ${address} on market ${market.value}:`, error);
|
|
776
|
+
positions[address.toLowerCase() as EthAddress].morphoMidnight[market.value] = { error: `Error fetching MorphoMidnight account data for address ${address} on market ${market.value}`, data: null };
|
|
777
|
+
}
|
|
778
|
+
})).flat(),
|
|
779
|
+
...compoundV3Markets.map((market) => addresses.map(async (address) => {
|
|
780
|
+
try {
|
|
781
|
+
const accData = await _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData });
|
|
782
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: '', data: accData };
|
|
783
|
+
} catch (error) {
|
|
784
|
+
console.error(`Error fetching CompoundV3 account data for address ${address} on market ${market.value}:`, error);
|
|
785
|
+
positions[address.toLowerCase() as EthAddress].compoundV3[market.value] = { error: `Error fetching CompoundV3 account data for address ${address} on market ${market.value}`, data: null };
|
|
786
|
+
}
|
|
787
|
+
})).flat(),
|
|
788
|
+
...sparkMarkets.map((market) => addresses.map(async (address) => {
|
|
789
|
+
try {
|
|
790
|
+
const accData = await _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData });
|
|
791
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: '', data: accData };
|
|
792
|
+
} catch (error) {
|
|
793
|
+
console.error(`Error fetching Spark account data for address ${address} on market ${market.value}:`, error);
|
|
794
|
+
positions[address.toLowerCase() as EthAddress].spark[market.value] = { error: `Error fetching Spark account data for address ${address} on market ${market.value}`, data: null };
|
|
795
|
+
}
|
|
796
|
+
})).flat(),
|
|
797
|
+
...addresses.map(async (address) => makerCdps[address.toLowerCase() as EthAddress]?.map(async (cdpInfo) => {
|
|
798
|
+
try {
|
|
799
|
+
// reuse ilk data fetched for the markets payload; ilks outside the active set are fetched on demand
|
|
800
|
+
const cdpData = await _getMakerCdpData(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel]);
|
|
801
|
+
if (cdpData) {
|
|
802
|
+
positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: '', data: cdpData };
|
|
803
|
+
}
|
|
804
|
+
} catch (error) {
|
|
805
|
+
console.error(`Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}:`, error);
|
|
806
|
+
positions[address.toLowerCase() as EthAddress].maker[cdpInfo.id] = { error: `Error fetching Maker CDP data for address ${address} with ID ${cdpInfo.id}`, data: null };
|
|
807
|
+
}
|
|
808
|
+
})).flat(),
|
|
809
|
+
...aaveV2Markets.map((market) => addresses.map(async (address) => {
|
|
810
|
+
try {
|
|
811
|
+
const accData = await _getAaveV2AccountData(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market);
|
|
812
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: '', data: accData };
|
|
813
|
+
} catch (error) {
|
|
814
|
+
console.error(`Error fetching AaveV2 account data for address ${address}:`, error);
|
|
815
|
+
positions[address.toLowerCase() as EthAddress].aaveV2[market.value] = { error: `Error fetching AaveV2 account data for address ${address}`, data: null };
|
|
816
|
+
}
|
|
817
|
+
})).flat(),
|
|
818
|
+
...compoundV2Markets.map((market) => addresses.map(async (address) => {
|
|
819
|
+
try {
|
|
820
|
+
const accData = await _getCompoundV2AccountData(client, network, address, markets.compoundV2MarketsData[market.value].assetsData);
|
|
821
|
+
if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: '', data: accData };
|
|
822
|
+
} catch (error) {
|
|
823
|
+
console.error(`Error fetching CompoundV2 account data for address ${address}:`, error);
|
|
824
|
+
positions[address.toLowerCase() as EthAddress].compoundV2[market.value] = { error: `Error fetching CompoundV2 account data for address ${address}`, data: null };
|
|
825
|
+
}
|
|
826
|
+
})).flat(),
|
|
827
|
+
...addresses.map(async (address) => {
|
|
828
|
+
try {
|
|
829
|
+
if (!isMainnet) return; // Liquity trove info is only available on mainnet
|
|
830
|
+
const troveInfo = await _getLiquityTroveInfo(client, network, address);
|
|
831
|
+
if (new Dec(troveInfo.collateral).gt(0)) positions[address.toLowerCase() as EthAddress].liquity = { error: '', data: troveInfo };
|
|
832
|
+
} catch (error) {
|
|
833
|
+
console.error(`Error fetching Liquity trove info for address ${address}:`, error);
|
|
834
|
+
positions[address.toLowerCase() as EthAddress].liquity = { error: `Error fetching Liquity trove info for address ${address}`, data: null };
|
|
835
|
+
}
|
|
836
|
+
}),
|
|
837
|
+
...crvUsdMarkets.map((market) => addresses.map(async (address) => {
|
|
838
|
+
try {
|
|
839
|
+
const accData = await _getCurveUsdUserData(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand);
|
|
840
|
+
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
841
|
+
positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: '', data: { ...accData, borrowRate: markets.crvUsdMarketsData[market.value].borrowRate } };
|
|
842
|
+
}
|
|
843
|
+
} catch (error) {
|
|
844
|
+
console.error(`Error fetching Curve USD account data for address ${address} on market ${market.value}:`, error);
|
|
845
|
+
positions[address.toLowerCase() as EthAddress].crvUsd[market.value] = { error: `Error fetching Curve USD account data for address ${address} on market ${market.value}`, data: null };
|
|
846
|
+
}
|
|
847
|
+
})).flat(),
|
|
848
|
+
...llamaLendMarkets.map((market) => addresses.map(async (address) => {
|
|
849
|
+
try {
|
|
850
|
+
const accData = await _getLlamaLendUserData(client, network, address, market, markets.llamaLendMarketsData[market.value]);
|
|
851
|
+
if (new Dec(accData.suppliedUsd).gt(0) || new Dec(accData.borrowedUsd).gt(0)) {
|
|
852
|
+
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: '', data: { ...accData, borrowRate: markets.llamaLendMarketsData[market.value].borrowRate } };
|
|
853
|
+
}
|
|
854
|
+
} catch (error) {
|
|
855
|
+
console.error(`Error fetching LlamaLend account data for address ${address} on market ${market.value}:`, error);
|
|
856
|
+
positions[address.toLowerCase() as EthAddress].llamaLend[market.value] = { error: `Error fetching LlamaLend account data for address ${address} on market ${market.value}`, data: null };
|
|
857
|
+
}
|
|
858
|
+
})).flat(),
|
|
859
|
+
]);
|
|
860
|
+
|
|
861
|
+
return {
|
|
862
|
+
positions,
|
|
863
|
+
markets,
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
|
|
599
867
|
export * from './discovery';
|
package/src/types/aaveV4.ts
CHANGED
|
@@ -20,6 +20,7 @@ export enum AaveV4SpokesType {
|
|
|
20
20
|
AaveV4LidoSpoke = 'aave_v4_lido_spoke',
|
|
21
21
|
AaveV4LombardBtcSpoke = 'aave_v4_lombard_btc_spoke',
|
|
22
22
|
AaveV4MainSpoke = 'aave_v4_main_spoke',
|
|
23
|
+
AaveV4PaxgGoldSpoke = 'aave_v4_paxg_gold_spoke',
|
|
23
24
|
AaveV4USDGPendleSpoke = 'aave_v4_usdg_pendle_spoke',
|
|
24
25
|
AaveV4USDGMapleSpoke = 'aave_v4_usdg_maple_spoke',
|
|
25
26
|
}
|
package/src/types/portfolio.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
AaveV2MarketData, AaveV2PositionData, AaveV3MarketData, AaveV3PositionData, AaveVersions,
|
|
3
|
+
} from './aave';
|
|
4
|
+
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokesType } from './aaveV4';
|
|
3
5
|
import { EthAddress } from './common';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import {
|
|
7
|
+
CompoundV2MarketsData, CompoundV2PositionData, CompoundV3MarketsData, CompoundV3PositionData, CompoundVersions,
|
|
8
|
+
} from './compound';
|
|
9
|
+
import { CrvUSDGlobalMarketData, CrvUSDUserData, CrvUSDVersions } from './curveUsd';
|
|
10
|
+
import { FluidMarketData, FluidVaultData } from './fluid';
|
|
7
11
|
import { LiquityTroveInfo } from './liquity';
|
|
8
|
-
import { LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
|
|
9
|
-
import { LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
10
|
-
import { CdpData } from './maker';
|
|
11
|
-
import { MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
12
|
-
import { MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
|
|
13
|
-
import { SparkPositionData, SparkVersions } from './spark';
|
|
12
|
+
import { LiquityV2MarketData, LiquityV2TroveData, LiquityV2Versions } from './liquityV2';
|
|
13
|
+
import { LlamaLendGlobalMarketData, LlamaLendUserData, LlamaLendVersionsType } from './llamaLend';
|
|
14
|
+
import { CdpData, IlkInfo } from './maker';
|
|
15
|
+
import { MorphoBlueMarketInfo, MorphoBluePositionData, MorphoBlueVersions } from './morphoBlue';
|
|
16
|
+
import { MorphoMidnightMarketInfo, MorphoMidnightPositionData, MorphoMidnightVersions } from './morphoMidnight';
|
|
17
|
+
import { SparkMarketsData, SparkPositionData, SparkVersions } from './spark';
|
|
14
18
|
|
|
15
19
|
export interface PortfolioProtocolData<T> {
|
|
16
20
|
error: string,
|
|
@@ -62,4 +66,19 @@ export interface PortfolioPositionsDataForAddress {
|
|
|
62
66
|
|
|
63
67
|
export interface PortfolioPositionsData {
|
|
64
68
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
|
65
|
-
}
|
|
69
|
+
}
|
|
70
|
+
export interface PortfolioMarketsData {
|
|
71
|
+
morphoMarketsData: Record<string, MorphoBlueMarketInfo>;
|
|
72
|
+
morphoMidnightMarketsData: Record<string, MorphoMidnightMarketInfo>;
|
|
73
|
+
compoundV3MarketsData: Record<string, CompoundV3MarketsData>;
|
|
74
|
+
sparkMarketsData: Record<string, SparkMarketsData>;
|
|
75
|
+
aaveV3MarketsData: Record<string, AaveV3MarketData>;
|
|
76
|
+
aaveV2MarketsData: Record<string, AaveV2MarketData>;
|
|
77
|
+
compoundV2MarketsData: Record<string, CompoundV2MarketsData>;
|
|
78
|
+
crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData>;
|
|
79
|
+
llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData>;
|
|
80
|
+
liquityV2MarketsData: Record<string, LiquityV2MarketData>;
|
|
81
|
+
aaveV4SpokesData: Record<string, AaveV4SpokeData>;
|
|
82
|
+
fluidMarketsData: Record<string, FluidMarketData>;
|
|
83
|
+
makerMarketsData: Record<string, IlkInfo>;
|
|
84
|
+
}
|