@defisaver/positions-sdk 2.1.52-dev-3 → 2.1.53-aave-v4

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 (158) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +64 -64
  4. package/cjs/aaveV4/index.d.ts +7 -0
  5. package/cjs/aaveV4/index.js +174 -0
  6. package/cjs/config/contracts.d.ts +1277 -0
  7. package/cjs/config/contracts.js +9 -0
  8. package/cjs/contracts.d.ts +23120 -0
  9. package/cjs/contracts.js +2 -1
  10. package/cjs/fluid/index.d.ts +3 -3
  11. package/cjs/helpers/aaveV4Helpers/index.d.ts +13 -0
  12. package/cjs/helpers/aaveV4Helpers/index.js +117 -0
  13. package/cjs/helpers/index.d.ts +1 -0
  14. package/cjs/helpers/index.js +2 -1
  15. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  16. package/cjs/index.d.ts +2 -1
  17. package/cjs/index.js +3 -1
  18. package/cjs/markets/aaveV4/index.d.ts +13 -0
  19. package/cjs/markets/aaveV4/index.js +39 -0
  20. package/cjs/markets/index.d.ts +1 -0
  21. package/cjs/markets/index.js +3 -1
  22. package/cjs/portfolio/index.js +20 -0
  23. package/cjs/savings/morphoVaults/index.js +17 -17
  24. package/cjs/types/aaveV4.d.ts +137 -0
  25. package/cjs/types/aaveV4.js +11 -0
  26. package/cjs/types/index.d.ts +2 -0
  27. package/cjs/types/index.js +2 -0
  28. package/cjs/types/portfolio.d.ts +4 -0
  29. package/esm/aaveV4/index.d.ts +7 -0
  30. package/esm/aaveV4/index.js +165 -0
  31. package/esm/config/contracts.d.ts +1277 -0
  32. package/esm/config/contracts.js +8 -0
  33. package/esm/contracts.d.ts +23120 -0
  34. package/esm/contracts.js +1 -0
  35. package/esm/fluid/index.d.ts +3 -3
  36. package/esm/helpers/aaveV4Helpers/index.d.ts +13 -0
  37. package/esm/helpers/aaveV4Helpers/index.js +108 -0
  38. package/esm/helpers/index.d.ts +1 -0
  39. package/esm/helpers/index.js +1 -0
  40. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  41. package/esm/index.d.ts +2 -1
  42. package/esm/index.js +2 -1
  43. package/esm/markets/aaveV4/index.d.ts +13 -0
  44. package/esm/markets/aaveV4/index.js +29 -0
  45. package/esm/markets/index.d.ts +1 -0
  46. package/esm/markets/index.js +1 -0
  47. package/esm/portfolio/index.js +21 -1
  48. package/esm/savings/morphoVaults/index.js +17 -17
  49. package/esm/types/aaveV4.d.ts +137 -0
  50. package/esm/types/aaveV4.js +8 -0
  51. package/esm/types/index.d.ts +2 -0
  52. package/esm/types/index.js +2 -0
  53. package/esm/types/portfolio.d.ts +4 -0
  54. package/package.json +48 -48
  55. package/src/aaveV2/index.ts +240 -240
  56. package/src/aaveV3/index.ts +635 -635
  57. package/src/aaveV3/merit.ts +97 -97
  58. package/src/aaveV3/merkl.ts +74 -74
  59. package/src/aaveV4/index.ts +176 -0
  60. package/src/claiming/aaveV3.ts +154 -154
  61. package/src/claiming/compV3.ts +22 -22
  62. package/src/claiming/ethena.ts +61 -61
  63. package/src/claiming/index.ts +12 -12
  64. package/src/claiming/king.ts +66 -66
  65. package/src/claiming/morphoBlue.ts +118 -118
  66. package/src/claiming/spark.ts +225 -225
  67. package/src/compoundV2/index.ts +244 -244
  68. package/src/compoundV3/index.ts +274 -274
  69. package/src/config/contracts.ts +1328 -1320
  70. package/src/constants/index.ts +10 -10
  71. package/src/contracts.ts +174 -172
  72. package/src/curveUsd/index.ts +254 -254
  73. package/src/eulerV2/index.ts +324 -324
  74. package/src/exchange/index.ts +25 -25
  75. package/src/fluid/index.ts +1800 -1800
  76. package/src/helpers/aaveHelpers/index.ts +202 -202
  77. package/src/helpers/aaveV4Helpers/index.ts +128 -0
  78. package/src/helpers/compoundHelpers/index.ts +276 -276
  79. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  80. package/src/helpers/eulerHelpers/index.ts +229 -229
  81. package/src/helpers/fluidHelpers/index.ts +335 -335
  82. package/src/helpers/index.ts +11 -10
  83. package/src/helpers/liquityV2Helpers/index.ts +82 -82
  84. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  85. package/src/helpers/makerHelpers/index.ts +52 -52
  86. package/src/helpers/morphoBlueHelpers/index.ts +405 -405
  87. package/src/helpers/sparkHelpers/index.ts +169 -169
  88. package/src/index.ts +51 -49
  89. package/src/liquity/index.ts +159 -159
  90. package/src/liquityV2/index.ts +703 -703
  91. package/src/llamaLend/index.ts +305 -305
  92. package/src/maker/index.ts +223 -223
  93. package/src/markets/aave/index.ts +118 -118
  94. package/src/markets/aave/marketAssets.ts +54 -54
  95. package/src/markets/aaveV4/index.ts +42 -0
  96. package/src/markets/compound/index.ts +243 -243
  97. package/src/markets/compound/marketsAssets.ts +97 -97
  98. package/src/markets/curveUsd/index.ts +69 -69
  99. package/src/markets/euler/index.ts +26 -26
  100. package/src/markets/fluid/index.ts +2900 -2900
  101. package/src/markets/index.ts +26 -25
  102. package/src/markets/liquityV2/index.ts +102 -102
  103. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  104. package/src/markets/llamaLend/index.ts +235 -235
  105. package/src/markets/morphoBlue/index.ts +988 -988
  106. package/src/markets/spark/index.ts +29 -29
  107. package/src/markets/spark/marketAssets.ts +12 -12
  108. package/src/moneymarket/moneymarketCommonService.ts +84 -84
  109. package/src/morphoBlue/index.ts +274 -274
  110. package/src/portfolio/index.ts +606 -586
  111. package/src/savings/index.ts +95 -95
  112. package/src/savings/makerDsr/index.ts +53 -53
  113. package/src/savings/makerDsr/options.ts +9 -9
  114. package/src/savings/morphoVaults/index.ts +80 -80
  115. package/src/savings/morphoVaults/options.ts +193 -193
  116. package/src/savings/skyOptions/index.ts +95 -95
  117. package/src/savings/skyOptions/options.ts +10 -10
  118. package/src/savings/sparkSavingsVaults/index.ts +60 -60
  119. package/src/savings/sparkSavingsVaults/options.ts +35 -35
  120. package/src/savings/yearnV3Vaults/index.ts +61 -61
  121. package/src/savings/yearnV3Vaults/options.ts +55 -55
  122. package/src/savings/yearnVaults/index.ts +73 -73
  123. package/src/savings/yearnVaults/options.ts +32 -32
  124. package/src/services/priceService.ts +278 -278
  125. package/src/services/utils.ts +115 -115
  126. package/src/services/viem.ts +57 -57
  127. package/src/setup.ts +8 -8
  128. package/src/spark/index.ts +459 -459
  129. package/src/staking/eligibility.ts +53 -53
  130. package/src/staking/index.ts +1 -1
  131. package/src/staking/staking.ts +192 -192
  132. package/src/types/aave.ts +199 -199
  133. package/src/types/aaveV4.ts +153 -0
  134. package/src/types/claiming.ts +114 -114
  135. package/src/types/common.ts +115 -115
  136. package/src/types/compound.ts +145 -145
  137. package/src/types/curveUsd.ts +123 -123
  138. package/src/types/euler.ts +176 -176
  139. package/src/types/fluid.ts +485 -485
  140. package/src/types/index.ts +17 -15
  141. package/src/types/liquity.ts +30 -30
  142. package/src/types/liquityV2.ts +128 -128
  143. package/src/types/llamaLend.ts +161 -161
  144. package/src/types/maker.ts +63 -63
  145. package/src/types/merit.ts +1 -1
  146. package/src/types/merkl.ts +70 -70
  147. package/src/types/morphoBlue.ts +202 -202
  148. package/src/types/portfolio.ts +64 -60
  149. package/src/types/savings/index.ts +23 -23
  150. package/src/types/savings/makerDsr.ts +13 -13
  151. package/src/types/savings/morphoVaults.ts +32 -32
  152. package/src/types/savings/sky.ts +14 -14
  153. package/src/types/savings/sparkSavingsVaults.ts +15 -15
  154. package/src/types/savings/yearnV3Vaults.ts +17 -17
  155. package/src/types/savings/yearnVaults.ts +14 -14
  156. package/src/types/spark.ts +135 -135
  157. package/src/umbrella/index.ts +69 -69
  158. package/src/umbrella/umbrellaUtils.ts +29 -29
package/esm/contracts.js CHANGED
@@ -132,3 +132,4 @@ export const StkAAVEViem = createViemContractFromConfigFunc('StkAAVE');
132
132
  export const YearnViewContractViem = createViemContractFromConfigFunc('YearnView');
133
133
  export const MakerDsrContractViem = createViemContractFromConfigFunc('MakerDsr');
134
134
  export const SkySavingsContractView = createViemContractFromConfigFunc('SkySavings');
135
+ export const AaveV4ViewContractViem = createViemContractFromConfigFunc('AaveV4View');
@@ -130,7 +130,7 @@ export declare const _getUserPositions: (provider: PublicClient, network: Networ
130
130
  collRatio: string;
131
131
  minRatio: string;
132
132
  totalInterestUsd: string;
133
- leveragedType?: import("../types/common").LeverageType;
133
+ leveragedType?: import("../types").LeverageType;
134
134
  leveragedAsset?: string;
135
135
  liquidationPrice?: string;
136
136
  currentVolatilePairRatio?: string;
@@ -161,7 +161,7 @@ export declare const getUserPositions: (provider: EthereumProvider, network: Net
161
161
  collRatio: string;
162
162
  minRatio: string;
163
163
  totalInterestUsd: string;
164
- leveragedType?: import("../types/common").LeverageType;
164
+ leveragedType?: import("../types").LeverageType;
165
165
  leveragedAsset?: string;
166
166
  liquidationPrice?: string;
167
167
  currentVolatilePairRatio?: string;
@@ -192,7 +192,7 @@ export declare const _getUserPositionsPortfolio: (provider: PublicClient, networ
192
192
  collRatio: string;
193
193
  minRatio: string;
194
194
  totalInterestUsd: string;
195
- leveragedType?: import("../types/common").LeverageType;
195
+ leveragedType?: import("../types").LeverageType;
196
196
  leveragedAsset?: string;
197
197
  liquidationPrice?: string;
198
198
  currentVolatilePairRatio?: string;
@@ -0,0 +1,13 @@
1
+ import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets } from '../../types';
2
+ import { LeverageType, NetworkNumber } from '../../types/common';
3
+ export declare const aaveV4GetCollateralFactor: (assetData: AaveV4ReserveAssetData, usedAssetData: AaveV4UsedReserveAsset, useUserCollateralFactor?: boolean) => number;
4
+ export declare const isLeveragedPosAaveV4: (usedAssets: AaveV4UsedReserveAssets, dustLimit?: number) => {
5
+ leveragedType: LeverageType;
6
+ leveragedAsset: string;
7
+ };
8
+ export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData, network, useUserCollateralFactor, }: {
9
+ usedAssets: AaveV4UsedReserveAssets;
10
+ assetsData: AaveV4AssetsData;
11
+ network: NetworkNumber;
12
+ useUserCollateralFactor?: boolean;
13
+ }) => AaveV4AggregatedPositionData;
@@ -0,0 +1,108 @@
1
+ import Dec from 'decimal.js';
2
+ import { calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS } from '../../moneymarket';
3
+ import { LeverageType } from '../../types/common';
4
+ export const aaveV4GetCollateralFactor = (assetData, usedAssetData, useUserCollateralFactor = false) => (useUserCollateralFactor ? usedAssetData.collateralFactor : assetData.collateralFactor);
5
+ export const isLeveragedPosAaveV4 = (usedAssets, dustLimit = 5) => {
6
+ let borrowUnstable = 0;
7
+ let supplyStable = 0;
8
+ let borrowStable = 0;
9
+ let supplyUnstable = 0;
10
+ let longAsset = '';
11
+ let shortAsset = '';
12
+ Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, reserveId, }) => {
13
+ const spokeAsset = `${symbol}-${reserveId}`;
14
+ const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
15
+ const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
16
+ if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
17
+ supplyStable += 1;
18
+ if (isBorrowed && STABLE_ASSETS.includes(symbol))
19
+ borrowStable += 1;
20
+ if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
21
+ borrowUnstable += 1;
22
+ shortAsset = spokeAsset;
23
+ }
24
+ if (isSupplied && !STABLE_ASSETS.includes(symbol) && collateral) {
25
+ supplyUnstable += 1;
26
+ longAsset = spokeAsset;
27
+ }
28
+ });
29
+ const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
30
+ const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
31
+ const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
32
+ if (isLong) {
33
+ return {
34
+ leveragedType: LeverageType.Long,
35
+ leveragedAsset: longAsset,
36
+ };
37
+ }
38
+ if (isShort) {
39
+ return {
40
+ leveragedType: LeverageType.Short,
41
+ leveragedAsset: shortAsset,
42
+ };
43
+ }
44
+ if (isVolatilePair) {
45
+ return {
46
+ leveragedType: LeverageType.VolatilePair,
47
+ leveragedAsset: longAsset,
48
+ };
49
+ }
50
+ return {
51
+ leveragedType: LeverageType.None,
52
+ leveragedAsset: '',
53
+ };
54
+ };
55
+ export const aaveV4GetAggregatedPositionData = ({ usedAssets, assetsData, network, useUserCollateralFactor = false, }) => {
56
+ const payload = {};
57
+ payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
58
+ payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
59
+ payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd, reserveId }) => new Dec(suppliedUsd).mul(aaveV4GetCollateralFactor(assetsData[`${symbol}-${reserveId}`], usedAssets[`${symbol}-${reserveId}`], useUserCollateralFactor)));
60
+ payload.liquidationLimitUsd = payload.borrowLimitUsd;
61
+ payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
62
+ payload.drawnUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ drawnUsd }) => drawnUsd);
63
+ payload.premiumUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ premiumUsd }) => premiumUsd);
64
+ const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
65
+ payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
66
+ payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
67
+ payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
68
+ payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
69
+ payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
70
+ const { leveragedType, leveragedAsset } = isLeveragedPosAaveV4(usedAssets);
71
+ payload.leveragedType = leveragedType;
72
+ payload.leveragedAsset = leveragedAsset;
73
+ payload.liquidationPrice = '';
74
+ if (leveragedType !== '') {
75
+ const leveragedAssetData = assetsData[leveragedAsset];
76
+ let assetPrice = (leveragedAssetData === null || leveragedAssetData === void 0 ? void 0 : leveragedAssetData.price) || '0';
77
+ if (leveragedType === LeverageType.VolatilePair) {
78
+ const borrowedAsset = Object.values(usedAssets).find(({ borrowedUsd }) => +borrowedUsd > 0);
79
+ const borrowedAssetPrice = assetsData[`${borrowedAsset.symbol}-${borrowedAsset.reserveId}`].price;
80
+ const leveragedAssetPrice = assetsData[leveragedAsset].price;
81
+ const isReverse = new Dec(leveragedAssetPrice).lt(borrowedAssetPrice);
82
+ if (isReverse) {
83
+ payload.leveragedType = LeverageType.VolatilePairReverse;
84
+ payload.currentVolatilePairRatio = new Dec(borrowedAssetPrice).div(leveragedAssetPrice).toDP(18).toString();
85
+ assetPrice = new Dec(borrowedAssetPrice).div(assetPrice).toString();
86
+ }
87
+ else {
88
+ assetPrice = new Dec(assetPrice).div(borrowedAssetPrice).toString();
89
+ payload.currentVolatilePairRatio = new Dec(leveragedAssetPrice).div(borrowedAssetPrice).toDP(18).toString();
90
+ }
91
+ }
92
+ payload.liquidationPrice = calcLeverageLiqPrice(payload.leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
93
+ }
94
+ payload.minCollRatio = new Dec(payload.suppliedCollateralUsd).div(payload.borrowLimitUsd).mul(100).toString();
95
+ payload.collLiquidationRatio = new Dec(payload.suppliedCollateralUsd).div(payload.liquidationLimitUsd).mul(100).toString();
96
+ // payload.healthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
97
+ payload.minHealthRatio = new Dec(payload.liquidationLimitUsd).div(payload.borrowLimitUsd).toDP(4).toString();
98
+ // TODO: Re-implement netApy calculation
99
+ // const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({
100
+ // usedAssets,
101
+ // assetsData,
102
+ // optionalData: { healthRatio: payload.healthRatio },
103
+ // });
104
+ payload.netApy = '0';
105
+ payload.incentiveUsd = '0';
106
+ payload.totalInterestUsd = '0';
107
+ return payload;
108
+ };
@@ -8,3 +8,4 @@ export * as llamaLendHelpers from './llamaLendHelpers';
8
8
  export * as liquityV2Helpers from './liquityV2Helpers';
9
9
  export * as eulerV2Helpers from './eulerHelpers';
10
10
  export * as fluidHelpers from './fluidHelpers';
11
+ export * as aaveV4Helpers from './aaveV4Helpers';
@@ -8,3 +8,4 @@ export * as llamaLendHelpers from './llamaLendHelpers';
8
8
  export * as liquityV2Helpers from './liquityV2Helpers';
9
9
  export * as eulerV2Helpers from './eulerHelpers';
10
10
  export * as fluidHelpers from './fluidHelpers';
11
+ export * as aaveV4Helpers from './aaveV4Helpers';
@@ -128,73 +128,73 @@ export const getApyAfterValuesEstimation = (selectedMarket, actions, provider, n
128
128
  return { borrowRate, supplyRate };
129
129
  });
130
130
  const API_URL = 'https://blue-api.morpho.org/graphql';
131
- const MARKET_QUERY = `
132
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
133
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
134
- reallocatableLiquidityAssets
135
- targetBorrowUtilization
136
- loanAsset {
137
- address
138
- decimals
139
- priceUsd
140
- }
141
- state {
142
- liquidityAssets
143
- borrowAssets
144
- supplyAssets
145
- }
146
- publicAllocatorSharedLiquidity {
147
- assets
148
- vault {
149
- address
150
- name
151
- }
152
- allocationMarket {
153
- uniqueKey
154
- loanAsset {
155
- address
156
- }
157
- collateralAsset {
158
- address
159
- }
160
- irmAddress
161
- oracle {
162
- address
163
- }
164
- lltv
165
- }
166
- }
167
- loanAsset {
168
- address
169
- }
170
- collateralAsset {
171
- address
172
- }
173
- oracle {
174
- address
175
- }
176
- irmAddress
177
- lltv
178
- }
179
- }
131
+ const MARKET_QUERY = `
132
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
133
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
134
+ reallocatableLiquidityAssets
135
+ targetBorrowUtilization
136
+ loanAsset {
137
+ address
138
+ decimals
139
+ priceUsd
140
+ }
141
+ state {
142
+ liquidityAssets
143
+ borrowAssets
144
+ supplyAssets
145
+ }
146
+ publicAllocatorSharedLiquidity {
147
+ assets
148
+ vault {
149
+ address
150
+ name
151
+ }
152
+ allocationMarket {
153
+ uniqueKey
154
+ loanAsset {
155
+ address
156
+ }
157
+ collateralAsset {
158
+ address
159
+ }
160
+ irmAddress
161
+ oracle {
162
+ address
163
+ }
164
+ lltv
165
+ }
166
+ }
167
+ loanAsset {
168
+ address
169
+ }
170
+ collateralAsset {
171
+ address
172
+ }
173
+ oracle {
174
+ address
175
+ }
176
+ irmAddress
177
+ lltv
178
+ }
179
+ }
180
180
  `;
181
- const REWARDS_QUERY = `
182
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
183
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
184
- uniqueKey
185
- state {
186
- rewards {
187
- amountPerSuppliedToken
188
- supplyApr
189
- amountPerBorrowedToken
190
- borrowApr
191
- asset {
192
- address
193
- }
194
- }
195
- }
196
- }
197
- }
181
+ const REWARDS_QUERY = `
182
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
183
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
184
+ uniqueKey
185
+ state {
186
+ rewards {
187
+ amountPerSuppliedToken
188
+ supplyApr
189
+ amountPerBorrowedToken
190
+ borrowApr
191
+ asset {
192
+ address
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
198
  `;
199
199
  /**
200
200
  * Get reallocatable liquidity to a given market and target borrow utilization
package/esm/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import './setup';
2
2
  import * as fluid from './fluid';
3
+ import * as aaveV4 from './aaveV4';
3
4
  import * as aaveV3 from './aaveV3';
4
5
  import * as aaveV2 from './aaveV2';
5
6
  import * as compoundV3 from './compoundV3';
@@ -21,4 +22,4 @@ import * as portfolio from './portfolio';
21
22
  import * as claiming from './claiming';
22
23
  import * as savings from './savings';
23
24
  export * from './types';
24
- export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
25
+ export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
package/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import './setup';
2
2
  import * as fluid from './fluid';
3
+ import * as aaveV4 from './aaveV4';
3
4
  import * as aaveV3 from './aaveV3';
4
5
  import * as aaveV2 from './aaveV2';
5
6
  import * as compoundV3 from './compoundV3';
@@ -21,4 +22,4 @@ import * as portfolio from './portfolio';
21
22
  import * as claiming from './claiming';
22
23
  import * as savings from './savings';
23
24
  export * from './types';
24
- export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
25
+ export { aaveV2, aaveV3, aaveV4, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
@@ -0,0 +1,13 @@
1
+ import { AaveV4HubInfo, AaveV4HubsType, AaveV4SpokeInfo, AaveV4SpokesType } from '../../types';
2
+ import { NetworkNumber } from '../../types/common';
3
+ export declare const AAVE_V4_CORE_SPOKE: (networkId: NetworkNumber) => AaveV4SpokeInfo;
4
+ export declare const AaveV4Spokes: (networkId: NetworkNumber) => {
5
+ readonly aave_v4_core_spoke: AaveV4SpokeInfo;
6
+ };
7
+ export declare const getAaveV4SpokeTypeInfo: (type: AaveV4SpokesType, network?: NetworkNumber) => AaveV4SpokeInfo;
8
+ export declare const AAVE_V4_CORE_HUB: (networkId: NetworkNumber) => AaveV4HubInfo;
9
+ export declare const AaveV4Hubs: (networkId: NetworkNumber) => {
10
+ readonly aave_v4_core_hub: AaveV4HubInfo;
11
+ };
12
+ export declare const getAaveV4HubTypeInfo: (type: AaveV4HubsType, network?: NetworkNumber) => AaveV4HubInfo;
13
+ export declare const getAaveV4HubByAddress: (networkId: NetworkNumber, address: string) => AaveV4HubInfo | undefined;
@@ -0,0 +1,29 @@
1
+ import { AaveV4HubsType, AaveV4SpokesType, } from '../../types';
2
+ import { NetworkNumber } from '../../types/common';
3
+ // SPOKES
4
+ export const AAVE_V4_CORE_SPOKE = (networkId) => ({
5
+ chainIds: [NetworkNumber.Eth],
6
+ label: 'Core Spoke',
7
+ value: AaveV4SpokesType.AaveV4CoreSpoke,
8
+ url: 'core',
9
+ address: '0xBa97c5E52cd5BC3D7950Ae70779F8FfE92d40CdC',
10
+ hubs: [
11
+ '0xaD905aD5EA5B98cD50AE40Cfe368344686a21366',
12
+ ],
13
+ });
14
+ export const AaveV4Spokes = (networkId) => ({
15
+ [AaveV4SpokesType.AaveV4CoreSpoke]: AAVE_V4_CORE_SPOKE(networkId),
16
+ });
17
+ export const getAaveV4SpokeTypeInfo = (type, network) => (Object.assign({}, AaveV4Spokes(network !== null && network !== void 0 ? network : NetworkNumber.Eth))[type]);
18
+ // HUBS
19
+ export const AAVE_V4_CORE_HUB = (networkId) => ({
20
+ chainIds: [NetworkNumber.Eth],
21
+ label: 'Core Hub',
22
+ value: AaveV4HubsType.AaveV4CoreHub,
23
+ address: '0xaD905aD5EA5B98cD50AE40Cfe368344686a21366',
24
+ });
25
+ export const AaveV4Hubs = (networkId) => ({
26
+ [AaveV4HubsType.AaveV4CoreHub]: AAVE_V4_CORE_HUB(networkId),
27
+ });
28
+ export const getAaveV4HubTypeInfo = (type, network) => (Object.assign({}, AaveV4Hubs(network !== null && network !== void 0 ? network : NetworkNumber.Eth))[type]);
29
+ export const getAaveV4HubByAddress = (networkId, address) => Object.values(AaveV4Hubs(networkId)).find(hub => hub.address.toLowerCase() === address.toLowerCase());
@@ -7,3 +7,4 @@ export { LlamaLendMarkets } from './llamaLend';
7
7
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
8
8
  export { EulerV2Markets } from './euler';
9
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
10
+ export { AaveV4Spokes } from './aaveV4';
@@ -7,3 +7,4 @@ export { LlamaLendMarkets } from './llamaLend';
7
7
  export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
8
8
  export { EulerV2Markets } from './euler';
9
9
  export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
10
+ export { AaveV4Spokes } from './aaveV4';
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import Dec from 'decimal.js';
11
11
  import { NetworkNumber } from '../types/common';
12
- import { AaveMarkets, CompoundMarkets, CrvUsdMarkets, EulerV2Markets, LiquityV2Markets, LlamaLendMarkets, MorphoBlueMarkets, SparkMarkets, } from '../markets';
12
+ import { AaveMarkets, AaveV4Spokes, CompoundMarkets, CrvUsdMarkets, EulerV2Markets, LiquityV2Markets, LlamaLendMarkets, MorphoBlueMarkets, SparkMarkets, } from '../markets';
13
13
  import { _getMorphoBlueAccountData, _getMorphoBlueMarketData, getMorphoEarn } from '../morphoBlue';
14
14
  import { AaveVersions, CompoundVersions, } from '../types';
15
15
  import { _getCompoundV3AccountData, _getCompoundV3MarketsData } from '../compoundV3';
@@ -34,6 +34,7 @@ import { fetchSparkAirdropRewards, fetchSparkRewards } from '../claiming/spark';
34
34
  import { fetchMorphoBlueRewards } from '../claiming/morphoBlue';
35
35
  import { getKingRewards } from '../claiming/king';
36
36
  import { fetchEthenaAirdropRewards } from '../claiming/ethena';
37
+ import { _getAaveV4AccountData, _getAaveV4SpokeData } from '../aaveV4';
37
38
  export function getPortfolioData(provider_1, network_1, defaultProvider_1, addresses_1) {
38
39
  return __awaiter(this, arguments, void 0, function* (provider, network, defaultProvider, addresses, isSim = false) {
39
40
  const isMainnet = network === NetworkNumber.Eth;
@@ -50,6 +51,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
50
51
  const llamaLendMarkets = [NetworkNumber.Eth, NetworkNumber.Arb].includes(network) ? Object.values(LlamaLendMarkets(network)).filter((market) => market.chainIds.includes(network)) : [];
51
52
  const liquityV2Markets = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)) : [];
52
53
  const liquityV2MarketsStaking = [NetworkNumber.Eth].includes(network) ? Object.values(LiquityV2Markets(network)).filter(market => !market.isLegacy) : [];
54
+ const aaveV4Spokes = Object.values(AaveV4Spokes(network)).filter((market) => market.chainIds.includes(network));
53
55
  const args = [network, { batch: { multicall: { batchSize: isSim ? 500000 : 2500000 } } }];
54
56
  const client = getViemProvider(provider, ...args);
55
57
  const defaultClient = getViemProvider(defaultProvider, ...args);
@@ -64,6 +66,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
64
66
  const crvUsdMarketsData = {};
65
67
  const llamaLendMarketsData = {};
66
68
  const liquityV2MarketsData = {};
69
+ const aaveV4SpokesData = {};
67
70
  const markets = {
68
71
  morphoMarketsData,
69
72
  compoundV3MarketsData,
@@ -75,6 +78,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
75
78
  crvUsdMarketsData,
76
79
  llamaLendMarketsData,
77
80
  liquityV2MarketsData,
81
+ aaveV4SpokesData,
78
82
  };
79
83
  const positions = {};
80
84
  const stakingPositions = {};
@@ -83,6 +87,7 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
83
87
  for (const address of allAddresses) {
84
88
  positions[address.toLowerCase()] = {
85
89
  aaveV3: {},
90
+ aaveV4: {},
86
91
  morphoBlue: {},
87
92
  compoundV3: {},
88
93
  spark: {},
@@ -148,6 +153,10 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
148
153
  const marketData = yield _getAaveV3MarketData(client, network, market);
149
154
  aaveV3MarketsData[market.value] = marketData;
150
155
  })),
156
+ ...aaveV4Spokes.map((spoke) => __awaiter(this, void 0, void 0, function* () {
157
+ const spokeData = yield _getAaveV4SpokeData(client, network, spoke);
158
+ aaveV4SpokesData[spoke.value] = spokeData;
159
+ })),
151
160
  ...aaveV2Markets.map((market) => __awaiter(this, void 0, void 0, function* () {
152
161
  const marketData = yield _getAaveV2MarketsData(client, network, market);
153
162
  aaveV2MarketsData[market.value] = marketData;
@@ -417,6 +426,17 @@ export function getPortfolioData(provider_1, network_1, defaultProvider_1, addre
417
426
  positions[address.toLowerCase()].aaveV3[market.value] = { error: `Error fetching AaveV3 account data for address ${address} on market ${market.value}`, data: null };
418
427
  }
419
428
  }))).flat(),
429
+ ...aaveV4Spokes.map((spoke) => allAddresses.map((address) => __awaiter(this, void 0, void 0, function* () {
430
+ try {
431
+ const accData = yield _getAaveV4AccountData(client, network, aaveV4SpokesData[spoke.value], address);
432
+ if (new Dec(accData.suppliedUsd).gt(0))
433
+ positions[address.toLowerCase()].aaveV4[spoke.value] = { error: '', data: accData };
434
+ }
435
+ catch (error) {
436
+ console.error(`Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}:`, error);
437
+ positions[address.toLowerCase()].aaveV4[spoke.value] = { error: `Error fetching AaveV4 account data for address ${address} on spoke ${spoke.value}`, data: null };
438
+ }
439
+ }))).flat(),
420
440
  ...morphoMarkets.map((market) => addresses.map((address) => __awaiter(this, void 0, void 0, function* () {
421
441
  try {
422
442
  const [accDataPromise, earnDataPromise] = yield Promise.allSettled([
@@ -14,23 +14,23 @@ import * as morphoVaultsOptions from './options';
14
14
  import { getViemProvider } from '../../services/viem';
15
15
  import { getMorphoVaultContractViem } from '../../contracts';
16
16
  export { morphoVaultsOptions, };
17
- const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
18
- vaultByAddress(chainId: 1, address: "${vaultAddress}") {
19
- id,
20
- dailyApy,
21
- dailyApys {
22
- apy, netApy
23
- },
24
- monthlyApys {
25
- apy, netApy
26
- },
27
- liquidity {
28
- underlying, usd,
29
- },
30
- asset {
31
- priceUsd
32
- }
33
- }
17
+ const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
18
+ vaultByAddress(chainId: 1, address: "${vaultAddress}") {
19
+ id,
20
+ dailyApy,
21
+ dailyApys {
22
+ apy, netApy
23
+ },
24
+ monthlyApys {
25
+ apy, netApy
26
+ },
27
+ liquidity {
28
+ underlying, usd,
29
+ },
30
+ asset {
31
+ priceUsd
32
+ }
33
+ }
34
34
  }`;
35
35
  const MORPHO_BLUE_API = 'https://blue-api.morpho.org/graphql';
36
36
  export const _getMorphoVaultData = (provider, network, morphoVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
@@ -0,0 +1,137 @@
1
+ import { EthAddress, IncentiveData, LeverageType, NetworkNumber } from './common';
2
+ export declare enum AaveV4SpokesType {
3
+ AaveV4CoreSpoke = "aave_v4_core_spoke"
4
+ }
5
+ export declare enum AaveV4HubsType {
6
+ AaveV4CoreHub = "aave_v4_core_hub"
7
+ }
8
+ export interface AaveV4SpokeInfo {
9
+ chainIds: NetworkNumber[];
10
+ label: string;
11
+ value: AaveV4SpokesType;
12
+ url: string;
13
+ address: EthAddress;
14
+ hubs: EthAddress[];
15
+ }
16
+ export interface AaveV4HubInfo {
17
+ chainIds: NetworkNumber[];
18
+ label: string;
19
+ value: AaveV4HubsType;
20
+ address: EthAddress;
21
+ }
22
+ export interface AaveV4HubAssetOnChainData {
23
+ assetId: number;
24
+ drawnRate: bigint;
25
+ }
26
+ export interface AaveV4HubOnChainData {
27
+ assets: Record<number, AaveV4HubAssetOnChainData>;
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
+ export interface AaveV4ReserveAssetData {
53
+ symbol: string;
54
+ underlying: EthAddress;
55
+ hub: EthAddress;
56
+ hubName: string;
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
+ export type AaveV4AssetsData = Record<string, AaveV4ReserveAssetData>;
85
+ export interface AaveV4SpokeData {
86
+ assetsData: AaveV4AssetsData;
87
+ oracle: EthAddress;
88
+ oracleDecimals: number;
89
+ address: EthAddress;
90
+ }
91
+ export interface AaveV4UsedReserveAsset {
92
+ symbol: string;
93
+ hubName: string;
94
+ assetId: number;
95
+ reserveId: number;
96
+ supplied: string;
97
+ suppliedUsd: string;
98
+ drawn: string;
99
+ drawnUsd: string;
100
+ premium: string;
101
+ premiumUsd: string;
102
+ borrowed: string;
103
+ borrowedUsd: string;
104
+ isSupplied: boolean;
105
+ isBorrowed: boolean;
106
+ collateral: boolean;
107
+ collateralFactor: number;
108
+ }
109
+ export interface AaveV4AggregatedPositionData {
110
+ suppliedUsd: string;
111
+ suppliedCollateralUsd: string;
112
+ borrowLimitUsd: string;
113
+ liquidationLimitUsd: string;
114
+ borrowedUsd: string;
115
+ drawnUsd: string;
116
+ premiumUsd: string;
117
+ leftToBorrowUsd: string;
118
+ ratio: string;
119
+ collRatio: string;
120
+ liqRatio: string;
121
+ liqPercent: string;
122
+ leveragedType: LeverageType;
123
+ leveragedAsset: string;
124
+ liquidationPrice: string;
125
+ minCollRatio: string;
126
+ collLiquidationRatio: string;
127
+ minHealthRatio: string;
128
+ netApy: string;
129
+ incentiveUsd: string;
130
+ totalInterestUsd: string;
131
+ currentVolatilePairRatio?: string;
132
+ }
133
+ export type AaveV4UsedReserveAssets = Record<string, AaveV4UsedReserveAsset>;
134
+ export interface AaveV4AccountData extends AaveV4AggregatedPositionData {
135
+ usedAssets: AaveV4UsedReserveAssets;
136
+ healthFactor: string;
137
+ }
@@ -0,0 +1,8 @@
1
+ export var AaveV4SpokesType;
2
+ (function (AaveV4SpokesType) {
3
+ AaveV4SpokesType["AaveV4CoreSpoke"] = "aave_v4_core_spoke";
4
+ })(AaveV4SpokesType || (AaveV4SpokesType = {}));
5
+ export var AaveV4HubsType;
6
+ (function (AaveV4HubsType) {
7
+ AaveV4HubsType["AaveV4CoreHub"] = "aave_v4_core_hub";
8
+ })(AaveV4HubsType || (AaveV4HubsType = {}));
@@ -13,3 +13,5 @@ export * from './portfolio';
13
13
  export * from './merit';
14
14
  export * from './merkl';
15
15
  export * from './savings';
16
+ export * from './common';
17
+ export * from './aaveV4';