@defisaver/positions-sdk 2.1.69 → 2.1.70-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 (62) hide show
  1. package/cjs/aaveV4/index.d.ts +7 -0
  2. package/cjs/aaveV4/index.js +174 -0
  3. package/cjs/config/contracts.d.ts +1535 -0
  4. package/cjs/config/contracts.js +9 -0
  5. package/cjs/contracts.d.ts +32401 -0
  6. package/cjs/contracts.js +2 -1
  7. package/cjs/helpers/aaveV4Helpers/index.d.ts +13 -0
  8. package/cjs/helpers/aaveV4Helpers/index.js +117 -0
  9. package/cjs/helpers/index.d.ts +1 -0
  10. package/cjs/helpers/index.js +2 -1
  11. package/cjs/index.d.ts +2 -1
  12. package/cjs/index.js +3 -1
  13. package/cjs/markets/aaveV4/index.d.ts +28 -0
  14. package/cjs/markets/aaveV4/index.js +140 -0
  15. package/cjs/markets/index.d.ts +1 -0
  16. package/cjs/markets/index.js +3 -1
  17. package/cjs/portfolio/index.js +20 -0
  18. package/cjs/types/aaveV4.d.ts +145 -0
  19. package/cjs/types/aaveV4.js +19 -0
  20. package/cjs/types/common.d.ts +1 -1
  21. package/cjs/types/common.js +1 -1
  22. package/cjs/types/index.d.ts +1 -0
  23. package/cjs/types/index.js +1 -0
  24. package/cjs/types/portfolio.d.ts +4 -0
  25. package/esm/aaveV4/index.d.ts +7 -0
  26. package/esm/aaveV4/index.js +165 -0
  27. package/esm/config/contracts.d.ts +1535 -0
  28. package/esm/config/contracts.js +8 -0
  29. package/esm/contracts.d.ts +32401 -0
  30. package/esm/contracts.js +1 -0
  31. package/esm/helpers/aaveV4Helpers/index.d.ts +13 -0
  32. package/esm/helpers/aaveV4Helpers/index.js +108 -0
  33. package/esm/helpers/index.d.ts +1 -0
  34. package/esm/helpers/index.js +1 -0
  35. package/esm/index.d.ts +2 -1
  36. package/esm/index.js +2 -1
  37. package/esm/markets/aaveV4/index.d.ts +28 -0
  38. package/esm/markets/aaveV4/index.js +122 -0
  39. package/esm/markets/index.d.ts +1 -0
  40. package/esm/markets/index.js +1 -0
  41. package/esm/portfolio/index.js +21 -1
  42. package/esm/types/aaveV4.d.ts +145 -0
  43. package/esm/types/aaveV4.js +16 -0
  44. package/esm/types/common.d.ts +1 -1
  45. package/esm/types/common.js +1 -1
  46. package/esm/types/index.d.ts +1 -0
  47. package/esm/types/index.js +1 -0
  48. package/esm/types/portfolio.d.ts +4 -0
  49. package/package.json +1 -1
  50. package/src/aaveV4/index.ts +176 -0
  51. package/src/config/contracts.ts +9 -1
  52. package/src/contracts.ts +3 -1
  53. package/src/helpers/aaveV4Helpers/index.ts +128 -0
  54. package/src/helpers/index.ts +1 -0
  55. package/src/index.ts +2 -0
  56. package/src/markets/aaveV4/index.ts +149 -0
  57. package/src/markets/index.ts +6 -1
  58. package/src/portfolio/index.ts +20 -0
  59. package/src/types/aaveV4.ts +161 -0
  60. package/src/types/common.ts +1 -1
  61. package/src/types/index.ts +2 -1
  62. 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,6 +51,7 @@ 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
56
  export async function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim = false): Promise<{
54
57
  positions: PortfolioPositionsData;
@@ -71,6 +74,7 @@ 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
79
  const args: [NetworkNumber, any?] = [network, { batch: { multicall: { batchSize: isSim ? 500_000 : 2_500_000 } } }];
76
80
  const client = getViemProvider(provider, ...args);
@@ -87,6 +91,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
87
91
  const crvUsdMarketsData: Record<string, CrvUSDGlobalMarketData> = {};
88
92
  const llamaLendMarketsData: Record<string, LlamaLendGlobalMarketData> = {};
89
93
  const liquityV2MarketsData: Record<string, LiquityV2MarketData> = {};
94
+ const aaveV4SpokesData: Record<string, AaveV4SpokeData> = {};
90
95
 
91
96
  const markets = {
92
97
  morphoMarketsData,
@@ -99,6 +104,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
99
104
  crvUsdMarketsData,
100
105
  llamaLendMarketsData,
101
106
  liquityV2MarketsData,
107
+ aaveV4SpokesData,
102
108
  };
103
109
 
104
110
  const positions: PortfolioPositionsData = {};
@@ -109,6 +115,7 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
109
115
  for (const address of allAddresses) {
110
116
  positions[address.toLowerCase() as EthAddress] = {
111
117
  aaveV3: {},
118
+ aaveV4: {},
112
119
  morphoBlue: {},
113
120
  compoundV3: {},
114
121
  spark: {},
@@ -177,6 +184,10 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
177
184
  const marketData = await _getAaveV3MarketData(client, network, market);
178
185
  aaveV3MarketsData[market.value] = marketData;
179
186
  }),
187
+ ...aaveV4Spokes.map(async (spoke) => {
188
+ const spokeData = await _getAaveV4SpokeData(client, network, spoke);
189
+ aaveV4SpokesData[spoke.value] = spokeData;
190
+ }),
180
191
  ...aaveV2Markets.map(async (market) => {
181
192
  const marketData = await _getAaveV2MarketsData(client, network, market);
182
193
  aaveV2MarketsData[market.value] = marketData;
@@ -429,6 +440,15 @@ export async function getPortfolioData(provider: EthereumProvider, network: Netw
429
440
  positions[address.toLowerCase() as EthAddress].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
430
441
  }
431
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(),
432
452
  ...morphoMarkets.map((market) => addresses.map(async (address) => {
433
453
  try {
434
454
  const [accDataPromise, earnDataPromise] = await Promise.allSettled([
@@ -0,0 +1,161 @@
1
+ import {
2
+ EthAddress, IncentiveData, LeverageType, NetworkNumber,
3
+ } from './common';
4
+
5
+ export enum AaveV4HubsType {
6
+ AaveV4CoreHub = 'aave_v4_core_hub',
7
+ AaveV4PlusHub = 'aave_v4_plus_hub',
8
+ AaveV4PrimeHub = 'aave_v4_prime_hub',
9
+ }
10
+
11
+ export enum AaveV4SpokesType {
12
+ AaveV4BluechipSpoke = 'aave_v4_bluechip_spoke',
13
+ AaveV4EthenaSpoke = 'aave_v4_ethena_spoke',
14
+ AaveV4EtherfiSpoke = 'aave_v4_etherfi_spoke',
15
+ AaveV4GoldSpoke = 'aave_v4_gold_spoke',
16
+ AaveV4KelpSpoke = 'aave_v4_kelp_spoke',
17
+ AaveV4LidoSpoke = 'aave_v4_lido_spoke',
18
+ AaveV4MainSpoke = 'aave_v4_main_spoke',
19
+ }
20
+
21
+ export interface AaveV4HubInfo {
22
+ chainIds: NetworkNumber[],
23
+ label: string,
24
+ value: AaveV4HubsType,
25
+ address: EthAddress,
26
+ }
27
+
28
+ export interface AaveV4HubAssetOnChainData {
29
+ assetId: number,
30
+ drawnRate: bigint,
31
+ }
32
+
33
+ export interface AaveV4HubOnChainData {
34
+ assets: Record<number, AaveV4HubAssetOnChainData>,
35
+ }
36
+
37
+ export interface AaveV4SpokeInfo {
38
+ chainIds: NetworkNumber[],
39
+ label: string,
40
+ value: AaveV4SpokesType,
41
+ url: string,
42
+ address: EthAddress,
43
+ hubs: EthAddress[],
44
+ }
45
+
46
+ export interface AaveV4SpokeData {
47
+ assetsData: AaveV4AssetsData,
48
+ oracle: EthAddress,
49
+ oracleDecimals: number,
50
+ address: EthAddress,
51
+ }
52
+
53
+ export interface AaveV4ReserveAssetOnChain {
54
+ underlying: EthAddress,
55
+ hub: EthAddress,
56
+ assetId: number,
57
+ decimals: number,
58
+ paused: boolean,
59
+ frozen: boolean,
60
+ borrowable: boolean,
61
+ collateralRisk: number,
62
+ collateralFactor: number,
63
+ maxLiquidationBonus: number,
64
+ liquidationFee: number,
65
+ price: bigint,
66
+ totalSupplied: bigint,
67
+ totalDrawn: bigint,
68
+ totalPremium: bigint,
69
+ totalDebt: bigint,
70
+ supplyCap: bigint,
71
+ borrowCap: bigint,
72
+ deficitRay: bigint,
73
+ spokeActive: boolean,
74
+ spokeHalted: boolean
75
+ }
76
+
77
+ export interface AaveV4ReserveAssetData {
78
+ symbol: string,
79
+ underlying: EthAddress,
80
+ hub: EthAddress,
81
+ hubName: string,
82
+ assetId: number,
83
+ reserveId: number,
84
+ paused: boolean,
85
+ frozen: boolean,
86
+ borrowable: boolean,
87
+ collateralRisk: number,
88
+ collateralFactor: number,
89
+ liquidationFee: number,
90
+ price: string,
91
+ totalSupplied: string,
92
+ totalDrawn: string,
93
+ totalPremium: string,
94
+ totalDebt: string,
95
+ supplyCap: string,
96
+ borrowCap: string,
97
+ spokeActive: boolean,
98
+ spokeHalted: boolean,
99
+ drawnRate: string,
100
+ supplyRate: string,
101
+ supplyIncentives: IncentiveData[];
102
+ borrowIncentives: IncentiveData[];
103
+ canBeBorrowed: boolean;
104
+ canBeSupplied: boolean;
105
+ canBeWithdrawn: boolean;
106
+ canBePayBacked: boolean;
107
+ utilization: string;
108
+ }
109
+
110
+ export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
111
+
112
+ export interface AaveV4UsedReserveAsset {
113
+ symbol: string,
114
+ hubName: string,
115
+ assetId: number,
116
+ reserveId: number,
117
+ supplied: string,
118
+ suppliedUsd: string,
119
+ drawn: string,
120
+ drawnUsd: string,
121
+ premium: string,
122
+ premiumUsd: string,
123
+ borrowed: string,
124
+ borrowedUsd: string,
125
+ isSupplied: boolean,
126
+ isBorrowed: boolean,
127
+ collateral: boolean,
128
+ collateralFactor: number,
129
+ }
130
+
131
+ export interface AaveV4AggregatedPositionData {
132
+ suppliedUsd: string,
133
+ suppliedCollateralUsd: string,
134
+ borrowLimitUsd: string,
135
+ liquidationLimitUsd: string,
136
+ borrowedUsd: string,
137
+ drawnUsd: string,
138
+ premiumUsd: string,
139
+ leftToBorrowUsd: string,
140
+ ratio: string,
141
+ collRatio: string,
142
+ liqRatio: string,
143
+ liqPercent: string,
144
+ leveragedType: LeverageType,
145
+ leveragedAsset: string,
146
+ liquidationPrice: string,
147
+ minCollRatio: string,
148
+ collLiquidationRatio: string,
149
+ minHealthRatio: string,
150
+ netApy: string,
151
+ incentiveUsd: string,
152
+ totalInterestUsd: string,
153
+ currentVolatilePairRatio?: string,
154
+ }
155
+
156
+ export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
157
+
158
+ export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
159
+ usedAssets: AaveV4UsedReserveAssets,
160
+ healthFactor: string,
161
+ }
@@ -7,7 +7,7 @@ export enum IncentiveEligibilityId {
7
7
  AaveV3EthenaLiquidLeverage = '0x8014e0076e5393e62c49a7134070d8fccc922e46BORROW_BL',
8
8
  AaveV3ArbitrumEthSupply = '0x5d16261c6715a653248269861bbacf68a9774cde',
9
9
  AaveV3ArbitrumETHLSBorrow = '0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351',
10
- AaveV3EthenaLiquidLeveragePlasma = '0x67264783f1e9a2af8627a235853057a6fc975bd2BORROW_BL',
10
+ AaveV3EthenaLiquidLeveragePlasma = '0xeefac321069fbecc9d6b2aed2948f6d5503d8633BORROW_BL',
11
11
  }
12
12
 
13
13
  export enum LeverageType {
@@ -13,4 +13,5 @@ export * from './portfolio';
13
13
  export * from './merit';
14
14
  export * from './merkl';
15
15
  export * from './savings';
16
- export * from './common';
16
+ export * from './common';
17
+ export * from './aaveV4';
@@ -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 {