@defisaver/positions-sdk 2.1.68 → 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 (65) 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/markets/morphoBlue/index.js +5 -5
  18. package/cjs/portfolio/index.js +20 -0
  19. package/cjs/types/aaveV4.d.ts +145 -0
  20. package/cjs/types/aaveV4.js +19 -0
  21. package/cjs/types/common.d.ts +1 -1
  22. package/cjs/types/common.js +1 -1
  23. package/cjs/types/index.d.ts +1 -0
  24. package/cjs/types/index.js +1 -0
  25. package/cjs/types/portfolio.d.ts +4 -0
  26. package/esm/aaveV4/index.d.ts +7 -0
  27. package/esm/aaveV4/index.js +165 -0
  28. package/esm/config/contracts.d.ts +1535 -0
  29. package/esm/config/contracts.js +8 -0
  30. package/esm/contracts.d.ts +32401 -0
  31. package/esm/contracts.js +1 -0
  32. package/esm/helpers/aaveV4Helpers/index.d.ts +13 -0
  33. package/esm/helpers/aaveV4Helpers/index.js +108 -0
  34. package/esm/helpers/index.d.ts +1 -0
  35. package/esm/helpers/index.js +1 -0
  36. package/esm/index.d.ts +2 -1
  37. package/esm/index.js +2 -1
  38. package/esm/markets/aaveV4/index.d.ts +28 -0
  39. package/esm/markets/aaveV4/index.js +122 -0
  40. package/esm/markets/index.d.ts +1 -0
  41. package/esm/markets/index.js +1 -0
  42. package/esm/markets/morphoBlue/index.js +5 -5
  43. package/esm/portfolio/index.js +21 -1
  44. package/esm/types/aaveV4.d.ts +145 -0
  45. package/esm/types/aaveV4.js +16 -0
  46. package/esm/types/common.d.ts +1 -1
  47. package/esm/types/common.js +1 -1
  48. package/esm/types/index.d.ts +1 -0
  49. package/esm/types/index.js +1 -0
  50. package/esm/types/portfolio.d.ts +4 -0
  51. package/package.json +1 -1
  52. package/src/aaveV4/index.ts +176 -0
  53. package/src/config/contracts.ts +9 -1
  54. package/src/contracts.ts +3 -1
  55. package/src/helpers/aaveV4Helpers/index.ts +128 -0
  56. package/src/helpers/index.ts +1 -0
  57. package/src/index.ts +2 -0
  58. package/src/markets/aaveV4/index.ts +149 -0
  59. package/src/markets/index.ts +6 -1
  60. package/src/markets/morphoBlue/index.ts +5 -5
  61. package/src/portfolio/index.ts +20 -0
  62. package/src/types/aaveV4.ts +161 -0
  63. package/src/types/common.ts +1 -1
  64. package/src/types/index.ts +2 -1
  65. package/src/types/portfolio.ts +4 -0
@@ -548,7 +548,7 @@ export const MORPHO_BLUE_SUSDE_DAI_777 = (networkId: NetworkNumber = NetworkNumb
548
548
  oracle: '0x5D916980D5Ae1737a8330Bf24dF812b2911Aae25',
549
549
  oracleType: MorphoBlueOracleType.MARKET_RATE,
550
550
  irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
551
- lltv: 0.777,
551
+ lltv: 0.77,
552
552
  marketId: '0x42dcfb38bb98767afb6e38ccf90d59d0d3f0aa216beb3a234f12850323d17536',
553
553
  protocolName: 'morpho-blue',
554
554
  });
@@ -609,7 +609,7 @@ export const MORPHO_BLUE_USDE_DAI_777 = (networkId: NetworkNumber = NetworkNumbe
609
609
  oracle: '0xaE4750d0813B5E37A51f7629beedd72AF1f9cA35',
610
610
  oracleType: MorphoBlueOracleType.MARKET_RATE,
611
611
  irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
612
- lltv: 0.777,
612
+ lltv: 0.77,
613
613
  marketId: '0xfd8493f09eb6203615221378d89f53fcd92ff4f7d62cca87eece9a2fff59e86f',
614
614
  protocolName: 'morpho-blue',
615
615
  });
@@ -1063,7 +1063,7 @@ export const MORPHO_BLUE_WEETH_USDC_777_BASE = (networkId: NetworkNumber = Netwo
1063
1063
  oracle: '0xaacbD2BbCA7927F772145f99EC942024Ddd0FAB0',
1064
1064
  oracleType: MorphoBlueOracleType.MARKET_RATE,
1065
1065
  irm: '0x46415998764C29aB2a25CbeA6254146D50D22687',
1066
- lltv: 0.777,
1066
+ lltv: 0.77,
1067
1067
  marketId: '0x6a331b22b56c9c0ee32a1a7d6f852d2c682ea8b27a1b0f99a9c484a37a951eb7',
1068
1068
  protocolName: 'morpho-blue',
1069
1069
  });
@@ -1095,7 +1095,7 @@ export const MORPHO_BLUE_EZETH_USDC_777_BASE = (networkId: NetworkNumber = Netwo
1095
1095
  oracle: '0x1BAaB21821c6468f8aee73ee60Fd8Fdc39c0C973',
1096
1096
  oracleType: MorphoBlueOracleType.MARKET_RATE,
1097
1097
  irm: '0x46415998764C29aB2a25CbeA6254146D50D22687',
1098
- lltv: 0.777,
1098
+ lltv: 0.77,
1099
1099
  marketId: '0xf24417ee06adc0b0836cf0dbec3ba56c1059f62f53a55990a38356d42fa75fa2',
1100
1100
  protocolName: 'morpho-blue',
1101
1101
  });
@@ -1111,7 +1111,7 @@ export const MORPHO_BLUE_EZETH_ETH_777_BASE = (networkId: NetworkNumber = Networ
1111
1111
  oracle: '0x09ECeE1Ab6f37a3D8D01f93A622b7A3021A5D91F',
1112
1112
  oracleType: MorphoBlueOracleType.MARKET_RATE,
1113
1113
  irm: '0x46415998764C29aB2a25CbeA6254146D50D22687',
1114
- lltv: 0.777,
1114
+ lltv: 0.77,
1115
1115
  marketId: '0xdf13c46bf7bd41597f27e32ae9c306eb63859c134073cb81c796ff20b520c7cf',
1116
1116
  protocolName: 'morpho-blue',
1117
1117
  });
@@ -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 {