@defisaver/positions-sdk 2.1.49 → 2.1.51-aave-v4-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/cjs/aaveV3/index.d.ts +1 -1
  2. package/cjs/aaveV4/index.d.ts +7 -0
  3. package/cjs/aaveV4/index.js +167 -0
  4. package/cjs/config/contracts.d.ts +1277 -0
  5. package/cjs/config/contracts.js +9 -0
  6. package/cjs/contracts.d.ts +23120 -0
  7. package/cjs/contracts.js +2 -1
  8. package/cjs/helpers/aaveV4Helpers/index.d.ts +13 -0
  9. package/cjs/helpers/aaveV4Helpers/index.js +109 -0
  10. package/cjs/helpers/index.d.ts +1 -0
  11. package/cjs/helpers/index.js +2 -1
  12. package/cjs/index.d.ts +2 -1
  13. package/cjs/index.js +3 -1
  14. package/cjs/markets/aaveV4/index.d.ts +7 -0
  15. package/cjs/markets/aaveV4/index.js +22 -0
  16. package/cjs/markets/index.d.ts +1 -0
  17. package/cjs/markets/index.js +3 -1
  18. package/cjs/markets/morphoBlue/index.d.ts +2 -0
  19. package/cjs/markets/morphoBlue/index.js +19 -2
  20. package/cjs/portfolio/index.d.ts +1 -1
  21. package/cjs/portfolio/index.js +26 -17
  22. package/cjs/services/viem.d.ts +20 -8
  23. package/cjs/services/viem.js +13 -0
  24. package/cjs/types/aaveV4.d.ts +129 -0
  25. package/cjs/types/aaveV4.js +11 -0
  26. package/cjs/types/index.d.ts +1 -0
  27. package/cjs/types/index.js +1 -0
  28. package/cjs/types/morphoBlue.d.ts +1 -0
  29. package/cjs/types/morphoBlue.js +1 -0
  30. package/cjs/types/portfolio.d.ts +4 -0
  31. package/esm/aaveV3/index.d.ts +1 -1
  32. package/esm/aaveV4/index.d.ts +7 -0
  33. package/esm/aaveV4/index.js +158 -0
  34. package/esm/config/contracts.d.ts +1277 -0
  35. package/esm/config/contracts.js +8 -0
  36. package/esm/contracts.d.ts +23120 -0
  37. package/esm/contracts.js +1 -0
  38. package/esm/helpers/aaveV4Helpers/index.d.ts +13 -0
  39. package/esm/helpers/aaveV4Helpers/index.js +100 -0
  40. package/esm/helpers/index.d.ts +1 -0
  41. package/esm/helpers/index.js +1 -0
  42. package/esm/index.d.ts +2 -1
  43. package/esm/index.js +2 -1
  44. package/esm/markets/aaveV4/index.d.ts +7 -0
  45. package/esm/markets/aaveV4/index.js +16 -0
  46. package/esm/markets/index.d.ts +1 -0
  47. package/esm/markets/index.js +1 -0
  48. package/esm/markets/morphoBlue/index.d.ts +2 -0
  49. package/esm/markets/morphoBlue/index.js +16 -0
  50. package/esm/portfolio/index.d.ts +1 -1
  51. package/esm/portfolio/index.js +27 -18
  52. package/esm/services/viem.d.ts +20 -8
  53. package/esm/services/viem.js +13 -1
  54. package/esm/types/aaveV4.d.ts +129 -0
  55. package/esm/types/aaveV4.js +8 -0
  56. package/esm/types/index.d.ts +1 -0
  57. package/esm/types/index.js +1 -0
  58. package/esm/types/morphoBlue.d.ts +1 -0
  59. package/esm/types/morphoBlue.js +1 -0
  60. package/esm/types/portfolio.d.ts +4 -0
  61. package/package.json +1 -1
  62. package/src/aaveV3/index.ts +1 -1
  63. package/src/aaveV4/index.ts +169 -0
  64. package/src/config/contracts.ts +8 -0
  65. package/src/contracts.ts +3 -1
  66. package/src/helpers/aaveV4Helpers/index.ts +121 -0
  67. package/src/helpers/index.ts +1 -0
  68. package/src/index.ts +2 -0
  69. package/src/markets/aaveV4/index.ts +19 -0
  70. package/src/markets/index.ts +1 -0
  71. package/src/markets/morphoBlue/index.ts +17 -0
  72. package/src/portfolio/index.ts +25 -17
  73. package/src/services/viem.ts +24 -2
  74. package/src/types/aaveV4.ts +142 -0
  75. package/src/types/index.ts +2 -1
  76. package/src/types/morphoBlue.ts +2 -0
  77. package/src/types/portfolio.ts +4 -0
@@ -2,6 +2,7 @@ import Dec from 'decimal.js';
2
2
  import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
3
3
  import {
4
4
  AaveMarkets,
5
+ AaveV4Spokes,
5
6
  CompoundMarkets,
6
7
  CrvUsdMarkets,
7
8
  EulerV2Markets,
@@ -14,6 +15,7 @@ import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } fr
14
15
  import {
15
16
  AaveV2MarketData,
16
17
  AaveV3MarketData,
18
+ AaveV4SpokeData,
17
19
  AaveVersions,
18
20
  CdpInfo,
19
21
  CompoundV2MarketsData,
@@ -49,8 +51,9 @@ import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
49
51
  import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
50
52
  import { getKingRewards } from '../claiming/king';
51
53
  import { fetchEthenaAirdropRewards } from '../claiming/ethena';
54
+ import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
52
55
 
53
- export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], summerFiAddresses: EthAddress[]): Promise<{
56
+ export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim = false): Promise<{
54
57
  positions: PortfolioPositionsData;
55
58
  stakingPositions: any;
56
59
  rewardsData: any;
@@ -71,21 +74,11 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
71
74
  const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
72
75
  const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
73
76
  const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
77
+ const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
74
78
 
75
- const client = getViemProvider(provider, network, {
76
- batch: {
77
- multicall: {
78
- batchSize: 2500000,
79
- },
80
- },
81
- });
82
- const defaultClient = getViemProvider(defaultProvider, network, {
83
- batch: {
84
- multicall: {
85
- batchSize: 2500000,
86
- },
87
- },
88
- });
79
+ const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 500_000 : 2_500_000 } } }];
80
+ const client = getViemProvider(provider, ...args);
81
+ const defaultClient = getViemProvider(defaultProvider, ...args);
89
82
 
90
83
  const morphoMarketsData: Record<string, MorphoBlueMarketInfo> = {};
91
84
  const compoundV3MarketsData: Record<string, CompoundV3MarketsData> = {};
@@ -98,6 +91,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
98
91
  const crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData> = {};
99
92
  const llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData> = {};
100
93
  const liquityV2MarketsData: Record<string, LiquityV2MarketData> = {};
94
+ const aaveV4SpokesData: Record<string, AaveV4SpokeData> = {};
101
95
 
102
96
  const markets = {
103
97
  morphoMarketsData,
@@ -110,16 +104,18 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
110
104
  crvUsdMarketsData,
111
105
  llamaLendMarketsData,
112
106
  liquityV2MarketsData,
107
+ aaveV4SpokesData,
113
108
  };
114
109
 
115
110
  const positions: PortfolioPositionsData = {};
116
111
  const stakingPositions: any = {};
117
112
  const rewardsData: any = {};
118
- const allAddresses = [...addresses, ...summerFiAddresses];
113
+ const allAddresses = [...addresses];
119
114
 
120
115
  for (const address of allAddresses) {
121
116
  positions[address.toLowerCase() as EthAddress] = {
122
117
  aaveV3: {},
118
+ aaveV4: {},
123
119
  morphoBlue: {},
124
120
  compoundV3: {},
125
121
  spark: {},
@@ -188,6 +184,10 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
188
184
  const marketData = await _getAaveV3MarketData(client, network, market);
189
185
  aaveV3MarketsData[market.value] = marketData;
190
186
  }),
187
+ ...aaveV4Spokes.map(async (spoke) => {
188
+ const spokeData = await _getAaveV4SpokeData(client, network, spoke);
189
+ aaveV4SpokesData[spoke.value] = spokeData;
190
+ }),
191
191
  ...aaveV2Markets.map(async (market) => {
192
192
  const marketData = await _getAaveV2MarketsData(client, network, market);
193
193
  aaveV2MarketsData[market.value] = marketData;
@@ -430,7 +430,6 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
430
430
  })(),
431
431
  ]);
432
432
 
433
-
434
433
  await Promise.all([
435
434
  ...aaveV3Markets.map((market) => allAddresses.map(async (address) => {
436
435
  try {
@@ -441,6 +440,15 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
441
440
  positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
442
441
  }
443
442
  })).flat(),
443
+ ...aaveV4Spokes.map((spoke) => allAddresses.map(async (address) => {
444
+ try {
445
+ const accData = await _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
446
+ if (new Dec(accData.suppliedUsd).gt(0)) positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: '', data: accData };
447
+ } catch (error) {
448
+ console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
449
+ positions[address.toLowerCase() as EthAddress].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
450
+ }
451
+ })).flat(),
444
452
  ...morphoMarkets.map((market) => addresses.map(async (address) => {
445
453
  try {
446
454
  const [accDataPromise, earnDataPromise] = await Promise.allSettled([
@@ -1,4 +1,9 @@
1
- import { createPublicClient, custom } from 'viem';
1
+ import {
2
+ createPublicClient,
3
+ custom,
4
+ encodeFunctionData,
5
+ type Abi,
6
+ } from 'viem';
2
7
  import {
3
8
  arbitrum, base, mainnet, optimism, linea, plasma,
4
9
  } from 'viem/chains';
@@ -32,4 +37,21 @@ export const getViemProvider = (provider: EthereumProvider, network: NetworkNumb
32
37
  export const setViemBlockNumber = (block: Blockish) => {
33
38
  if (block === 'latest') return {};
34
39
  return { blockNumber: BigInt(block) };
35
- };
40
+ };
41
+
42
+ /**
43
+ * Utility function to return callData
44
+ * Useful for Tenderly simulation
45
+ *
46
+ * @param contract
47
+ * @param functionName
48
+ * @param args
49
+ */
50
+ export function encodeCalldata(
51
+ contract: { abi: Abi },
52
+ functionName: string,
53
+ args?: readonly unknown[],
54
+ ): `0x${string}` {
55
+ const callDescriptor = { abi: contract.abi, functionName } as const;
56
+ return encodeFunctionData((args ? { ...callDescriptor, args } : callDescriptor) as any);
57
+ }
@@ -0,0 +1,142 @@
1
+ import { EthAddress, IncentiveData, NetworkNumber } from './common';
2
+
3
+ export enum AaveV4SpokesType {
4
+ AaveV4CoreSpoke = 'aave_v4_core_spoke',
5
+ }
6
+
7
+ export enum AaveV4HubsType {
8
+ AaveV4CoreHub = 'aave_v4_core_hub',
9
+ }
10
+
11
+ export interface AaveV4SpokeInfo {
12
+ chainIds: NetworkNumber[],
13
+ label: string,
14
+ value: AaveV4SpokesType,
15
+ url: string,
16
+ address: EthAddress,
17
+ hubs: EthAddress[],
18
+ }
19
+
20
+ export interface AaveV4HubAssetOnChainData {
21
+ assetId: number,
22
+ drawnRate: bigint,
23
+ }
24
+
25
+ export interface AaveV4HubOnChainData {
26
+ assets: Record<number, AaveV4HubAssetOnChainData>,
27
+ }
28
+
29
+ export interface AaveV4ReserveAssetOnChain {
30
+ underlying: EthAddress,
31
+ hub: EthAddress,
32
+ assetId: number,
33
+ decimals: number,
34
+ paused: boolean,
35
+ frozen: boolean,
36
+ borrowable: boolean,
37
+ collateralRisk: number,
38
+ collateralFactor: number,
39
+ maxLiquidationBonus: number,
40
+ liquidationFee: number,
41
+ price: bigint,
42
+ totalSupplied: bigint,
43
+ totalDrawn: bigint,
44
+ totalPremium: bigint,
45
+ totalDebt: bigint,
46
+ supplyCap: bigint,
47
+ borrowCap: bigint,
48
+ deficitRay: bigint,
49
+ spokeActive: boolean,
50
+ spokePaused: boolean
51
+ }
52
+
53
+ export interface AaveV4ReserveAssetData {
54
+ symbol: string,
55
+ underlying: EthAddress,
56
+ hub: EthAddress,
57
+ assetId: number,
58
+ reserveId: number,
59
+ paused: boolean,
60
+ frozen: boolean,
61
+ borrowable: boolean,
62
+ collateralRisk: number,
63
+ collateralFactor: number,
64
+ liquidationFee: number,
65
+ price: string,
66
+ totalSupplied: string,
67
+ totalDrawn: string,
68
+ totalPremium: string,
69
+ totalDebt: string,
70
+ supplyCap: string,
71
+ borrowCap: string,
72
+ spokeActive: boolean,
73
+ spokePaused: boolean,
74
+ drawnRate: string,
75
+ supplyRate: string,
76
+ supplyIncentives: IncentiveData[];
77
+ borrowIncentives: IncentiveData[];
78
+ canBeBorrowed: boolean;
79
+ canBeSupplied: boolean;
80
+ canBeWithdrawn: boolean;
81
+ canBePayBacked: boolean;
82
+ utilization: string;
83
+ }
84
+
85
+ export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
86
+
87
+ export interface AaveV4SpokeData {
88
+ assetsData: AaveV4AssetsData,
89
+ oracle: EthAddress,
90
+ oracleDecimals: number,
91
+ address: EthAddress,
92
+ }
93
+
94
+ export interface AaveV4UsedReserveAsset {
95
+ symbol: string,
96
+ assetId: number,
97
+ reserveId: number,
98
+ supplied: string,
99
+ suppliedUsd: string,
100
+ drawn: string,
101
+ drawnUsd: string,
102
+ premium: string,
103
+ premiumUsd: string,
104
+ borrowed: string,
105
+ borrowedUsd: string,
106
+ isSupplied: boolean,
107
+ isBorrowed: boolean,
108
+ collateral: boolean,
109
+ collateralFactor: number,
110
+ }
111
+
112
+ export interface AaveV4AggregatedPositionData {
113
+ suppliedUsd: string,
114
+ suppliedCollateralUsd: string,
115
+ borrowLimitUsd: string,
116
+ liquidationLimitUsd: string,
117
+ borrowedUsd: string,
118
+ drawnUsd: string,
119
+ premiumUsd: string,
120
+ leftToBorrowUsd: string,
121
+ ratio: string,
122
+ collRatio: string,
123
+ liqRatio: string,
124
+ liqPercent: string,
125
+ leveragedType: string,
126
+ leveragedAsset: string,
127
+ liquidationPrice: string,
128
+ leveragedLsdAssetRatio?: string,
129
+ minCollRatio: string,
130
+ collLiquidationRatio: string,
131
+ minHealthRatio: string,
132
+ netApy: string,
133
+ incentiveUsd: string,
134
+ totalInterestUsd: string,
135
+ }
136
+
137
+ export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
138
+
139
+ export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
140
+ usedAssets: AaveV4UsedReserveAssets,
141
+ healthFactor: string,
142
+ }
@@ -12,4 +12,5 @@ export * from './fluid';
12
12
  export * from './portfolio';
13
13
  export * from './merit';
14
14
  export * from './merkl';
15
- export * from './savings';
15
+ export * from './savings';
16
+ export * from './aaveV4';
@@ -44,6 +44,8 @@ export enum MorphoBlueVersions {
44
44
  MorphoBlueUSDeDAI_860 = 'morphoblueusdedai_860',
45
45
  MorphoBlueUSDeDAI_915 = 'morphoblueusdedai_915',
46
46
 
47
+ MorphoBlueMORPHOUSDC_625 = 'morphobluemorphousdc_625',
48
+
47
49
  // BASE
48
50
  MorphoBlueCbEthUSDC_860_Base = 'morphobluecbethusdc_860_base',
49
51
  MorphoBlueCbEthUSDC_860_Base_1c21c59d = 'morphobluecbethusdc_860_base_1c21c59d',
@@ -1,4 +1,5 @@
1
1
  import { AaveV2PositionData, AaveV3PositionData, AaveVersions } from './aave';
2
+ import { AaveV4AccountData, AaveV4SpokesType } from './aaveV4';
2
3
  import { EthAddress } from './common';
3
4
  import { CompoundV2PositionData, CompoundV3PositionData, CompoundVersions } from './compound';
4
5
  import { CrvUSDUserData, CrvUSDVersions } from './curveUsd';
@@ -54,6 +55,9 @@ export interface PortfolioPositionsDataForAddress {
54
55
  [key: string]: FluidVaultData;
55
56
  };
56
57
  };
58
+ aaveV4: {
59
+ [key in AaveV4SpokesType]?: PortfolioProtocolData<AaveV4AccountData>;
60
+ };
57
61
  }
58
62
 
59
63
  export interface PortfolioPositionsData {