@defisaver/positions-sdk 2.1.98-aave-v4-apy-2 → 2.1.101

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 (120) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +64 -64
  4. package/cjs/helpers/aaveV4Helpers/index.d.ts +2 -6
  5. package/cjs/helpers/aaveV4Helpers/index.js +3 -21
  6. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  7. package/cjs/savings/morphoVaults/index.js +17 -17
  8. package/esm/helpers/aaveV4Helpers/index.d.ts +2 -6
  9. package/esm/helpers/aaveV4Helpers/index.js +2 -19
  10. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  11. package/esm/savings/morphoVaults/index.js +17 -17
  12. package/package.json +48 -48
  13. package/src/aaveV2/index.ts +240 -240
  14. package/src/aaveV3/index.ts +634 -634
  15. package/src/aaveV3/merit.ts +97 -97
  16. package/src/aaveV3/merkl.ts +74 -74
  17. package/src/aaveV4/index.ts +238 -238
  18. package/src/aaveV4/lend.ts +185 -185
  19. package/src/claiming/aaveV3.ts +154 -154
  20. package/src/claiming/compV3.ts +22 -22
  21. package/src/claiming/ethena.ts +61 -61
  22. package/src/claiming/index.ts +12 -12
  23. package/src/claiming/king.ts +66 -66
  24. package/src/claiming/morphoBlue.ts +118 -118
  25. package/src/claiming/spark.ts +225 -225
  26. package/src/compoundV2/index.ts +245 -245
  27. package/src/compoundV3/index.ts +280 -280
  28. package/src/config/contracts.ts +1357 -1357
  29. package/src/constants/index.ts +10 -10
  30. package/src/contracts.ts +183 -183
  31. package/src/curveUsd/index.ts +254 -254
  32. package/src/eulerV2/index.ts +330 -330
  33. package/src/exchange/index.ts +25 -25
  34. package/src/fluid/index.ts +1800 -1800
  35. package/src/helpers/aaveHelpers/index.ts +203 -203
  36. package/src/helpers/aaveV4Helpers/index.ts +324 -349
  37. package/src/helpers/compoundHelpers/index.ts +280 -280
  38. package/src/helpers/curveUsdHelpers/index.ts +44 -44
  39. package/src/helpers/eulerHelpers/index.ts +230 -230
  40. package/src/helpers/fluidHelpers/index.ts +338 -338
  41. package/src/helpers/index.ts +11 -11
  42. package/src/helpers/liquityV2Helpers/index.ts +85 -85
  43. package/src/helpers/llamaLendHelpers/index.ts +56 -56
  44. package/src/helpers/makerHelpers/index.ts +52 -52
  45. package/src/helpers/morphoBlueHelpers/index.ts +406 -406
  46. package/src/helpers/sparkHelpers/index.ts +170 -170
  47. package/src/index.ts +51 -51
  48. package/src/liquity/index.ts +161 -161
  49. package/src/liquityV2/index.ts +703 -703
  50. package/src/llamaLend/index.ts +305 -305
  51. package/src/maker/index.ts +225 -225
  52. package/src/markets/aave/index.ts +118 -118
  53. package/src/markets/aave/marketAssets.ts +54 -54
  54. package/src/markets/aaveV4/index.ts +191 -191
  55. package/src/markets/compound/index.ts +243 -243
  56. package/src/markets/compound/marketsAssets.ts +97 -97
  57. package/src/markets/curveUsd/index.ts +69 -69
  58. package/src/markets/euler/index.ts +26 -26
  59. package/src/markets/fluid/index.ts +2900 -2900
  60. package/src/markets/index.ts +29 -29
  61. package/src/markets/liquityV2/index.ts +102 -102
  62. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  63. package/src/markets/llamaLend/index.ts +235 -235
  64. package/src/markets/morphoBlue/index.ts +1370 -1370
  65. package/src/markets/spark/index.ts +29 -29
  66. package/src/markets/spark/marketAssets.ts +12 -12
  67. package/src/moneymarket/moneymarketCommonService.ts +91 -91
  68. package/src/morphoBlue/index.ts +274 -274
  69. package/src/portfolio/index.ts +606 -606
  70. package/src/savings/index.ts +111 -111
  71. package/src/savings/makerDsr/index.ts +53 -53
  72. package/src/savings/makerDsr/options.ts +9 -9
  73. package/src/savings/morphoVaults/index.ts +80 -80
  74. package/src/savings/morphoVaults/options.ts +193 -193
  75. package/src/savings/skyOptions/index.ts +95 -95
  76. package/src/savings/skyOptions/options.ts +10 -10
  77. package/src/savings/sparkSavingsVaults/index.ts +60 -60
  78. package/src/savings/sparkSavingsVaults/options.ts +35 -35
  79. package/src/savings/summerVaults/index.ts +56 -56
  80. package/src/savings/summerVaults/options.ts +117 -117
  81. package/src/savings/yearnV3Vaults/index.ts +61 -61
  82. package/src/savings/yearnV3Vaults/options.ts +55 -55
  83. package/src/savings/yearnVaults/index.ts +73 -73
  84. package/src/savings/yearnVaults/options.ts +32 -32
  85. package/src/services/priceService.ts +278 -278
  86. package/src/services/utils.ts +122 -122
  87. package/src/services/viem.ts +57 -57
  88. package/src/setup.ts +8 -8
  89. package/src/spark/index.ts +460 -460
  90. package/src/staking/eligibility.ts +105 -105
  91. package/src/staking/index.ts +1 -1
  92. package/src/staking/staking.ts +201 -201
  93. package/src/types/aave.ts +200 -200
  94. package/src/types/aaveV4.ts +179 -179
  95. package/src/types/claiming.ts +114 -114
  96. package/src/types/common.ts +117 -117
  97. package/src/types/compound.ts +147 -147
  98. package/src/types/curveUsd.ts +125 -125
  99. package/src/types/euler.ts +177 -177
  100. package/src/types/fluid.ts +486 -486
  101. package/src/types/index.ts +16 -16
  102. package/src/types/liquity.ts +31 -31
  103. package/src/types/liquityV2.ts +130 -130
  104. package/src/types/llamaLend.ts +163 -163
  105. package/src/types/maker.ts +64 -64
  106. package/src/types/merit.ts +1 -1
  107. package/src/types/merkl.ts +70 -70
  108. package/src/types/morphoBlue.ts +228 -228
  109. package/src/types/portfolio.ts +64 -64
  110. package/src/types/savings/index.ts +25 -25
  111. package/src/types/savings/makerDsr.ts +13 -13
  112. package/src/types/savings/morphoVaults.ts +32 -32
  113. package/src/types/savings/sky.ts +14 -14
  114. package/src/types/savings/sparkSavingsVaults.ts +15 -15
  115. package/src/types/savings/summerVaults.ts +24 -24
  116. package/src/types/savings/yearnV3Vaults.ts +17 -17
  117. package/src/types/savings/yearnVaults.ts +14 -14
  118. package/src/types/spark.ts +136 -136
  119. package/src/umbrella/index.ts +69 -69
  120. package/src/umbrella/umbrellaUtils.ts +29 -29
package/.mocharc.json CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "require": "ts-node/register",
3
- "extension": ["ts"]
4
- }
1
+ {
2
+ "require": "ts-node/register",
3
+ "extension": ["ts"]
4
+ }
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- v20.17.0
1
+ v20.17.0
package/README.md CHANGED
@@ -1,64 +1,64 @@
1
- # DeFi Saver Positions SDK
2
-
3
- Supported protocols:
4
- - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
- - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
- - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
- - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
- - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
- - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
10
- - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
11
- - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
12
-
13
- ## Setup
14
- Supported Node version is v10.
15
-
16
- - run `npm install` (first time)
17
- - run `npm run build`
18
-
19
- `build` command will generate contracts and build ejs and esm folders
20
-
21
- ## How to use
22
- [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
23
-
24
- This is a Compound V3 example, and every other protocol is similar
25
- ```js
26
- import { compoundV3 } from '@defisaver/positions-sdk';
27
-
28
-
29
- // every protocol has market data and user data getters
30
- const {
31
- getCompoundV3MarketsData,
32
- getCompoundV3AccountData,
33
- } = compoundV3;
34
-
35
- const provider = 'Your RPC provider';
36
-
37
- const user = '0x123...';
38
-
39
- const { assetsData } = await getCompoundV3MarketsData(
40
- provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
41
- 1, // network
42
- selectedMarket, // market object like in /src/markets/compound/index.ts
43
- provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
44
- );
45
-
46
- const userData = await getCompoundV3AccountData(
47
- provider,
48
- 1, // network
49
- userAddress, // EOA or DSProxy
50
- '', // proxy address of the user, or just empty string if checking for EOA
51
- {
52
- selectedMarket, // market object as in /src/markets/compound/index.ts
53
- assetsData,
54
- }
55
- );
56
- ```
57
-
58
- More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
59
-
60
- ## Testing
61
-
62
- `npm run test` - Run all tests
63
-
64
- `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
1
+ # DeFi Saver Positions SDK
2
+
3
+ Supported protocols:
4
+ - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
+ - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
+ - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
+ - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
+ - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
+ - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
10
+ - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
11
+ - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
12
+
13
+ ## Setup
14
+ Supported Node version is v10.
15
+
16
+ - run `npm install` (first time)
17
+ - run `npm run build`
18
+
19
+ `build` command will generate contracts and build ejs and esm folders
20
+
21
+ ## How to use
22
+ [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
23
+
24
+ This is a Compound V3 example, and every other protocol is similar
25
+ ```js
26
+ import { compoundV3 } from '@defisaver/positions-sdk';
27
+
28
+
29
+ // every protocol has market data and user data getters
30
+ const {
31
+ getCompoundV3MarketsData,
32
+ getCompoundV3AccountData,
33
+ } = compoundV3;
34
+
35
+ const provider = 'Your RPC provider';
36
+
37
+ const user = '0x123...';
38
+
39
+ const { assetsData } = await getCompoundV3MarketsData(
40
+ provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
41
+ 1, // network
42
+ selectedMarket, // market object like in /src/markets/compound/index.ts
43
+ provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
44
+ );
45
+
46
+ const userData = await getCompoundV3AccountData(
47
+ provider,
48
+ 1, // network
49
+ userAddress, // EOA or DSProxy
50
+ '', // proxy address of the user, or just empty string if checking for EOA
51
+ {
52
+ selectedMarket, // market object as in /src/markets/compound/index.ts
53
+ assetsData,
54
+ }
55
+ );
56
+ ```
57
+
58
+ More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
59
+
60
+ ## Testing
61
+
62
+ `npm run test` - Run all tests
63
+
64
+ `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
@@ -1,9 +1,5 @@
1
1
  import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4SpokeInfo, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets, EthereumProvider, LeverageType, NetworkNumber } from '../../types';
2
2
  export declare const calcUserRiskPremiumBps: (usedAssets: AaveV4UsedReserveAssets, assetsData: AaveV4AssetsData) => number;
3
- export declare const getApyAfterValuesEstimation: (usedAssets: AaveV4UsedReserveAssets, assetsData: AaveV4AssetsData) => Record<string, {
4
- borrowRate: string;
5
- supplyRate: string;
6
- }>;
7
3
  export declare const calculateNetApyAaveV4: ({ usedAssets, assetsData, }: {
8
4
  usedAssets: AaveV4UsedReserveAssets;
9
5
  assetsData: AaveV4AssetsData;
@@ -23,11 +19,11 @@ export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData,
23
19
  network: NetworkNumber;
24
20
  useUserCollateralFactor?: boolean;
25
21
  }) => AaveV4AggregatedPositionData;
26
- export declare const getAaveV4ApyAfterValuesEstimation: (selectedSpoke: AaveV4SpokeInfo, assetsData: AaveV4AssetsData, actions: [{
22
+ export declare const getAaveV4ApyAfterValuesEstimation: (selectedSpoke: AaveV4SpokeInfo, assetsData: AaveV4AssetsData, actions: {
27
23
  action: string;
28
24
  amount: string;
29
25
  asset: string;
30
- }], provider: EthereumProvider, network: NetworkNumber) => Promise<{
26
+ }[], provider: EthereumProvider, network: NetworkNumber) => Promise<{
31
27
  [key: string]: {
32
28
  supplyRate: string;
33
29
  borrowRate: string;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getAaveV4ApyAfterValuesEstimation = exports.aaveV4GetAggregatedPositionData = exports.isLeveragedPosAaveV4 = exports.aaveV4GetCollateralFactor = exports.calculateNetApyAaveV4 = exports.getApyAfterValuesEstimation = exports.calcUserRiskPremiumBps = void 0;
15
+ exports.getAaveV4ApyAfterValuesEstimation = exports.aaveV4GetAggregatedPositionData = exports.isLeveragedPosAaveV4 = exports.aaveV4GetCollateralFactor = exports.calculateNetApyAaveV4 = exports.calcUserRiskPremiumBps = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const tokens_1 = require("@defisaver/tokens");
18
18
  const moneymarket_1 = require("../../moneymarket");
@@ -74,24 +74,6 @@ const calcUserRiskPremiumBps = (usedAssets, assetsData) => {
74
74
  return riskPremiumBps.toNumber();
75
75
  };
76
76
  exports.calcUserRiskPremiumBps = calcUserRiskPremiumBps;
77
- const getApyAfterValuesEstimation = (usedAssets, assetsData) => {
78
- const riskPremiumBps = (0, exports.calcUserRiskPremiumBps)(usedAssets, assetsData);
79
- const riskPremiumFraction = new decimal_js_1.default(riskPremiumBps).div(10000); // bps to fraction
80
- const result = {};
81
- Object.entries(assetsData).forEach(([identifier, assetData]) => {
82
- const drawnRate = new decimal_js_1.default(assetData.drawnRate);
83
- const baseBorrowApr = drawnRate.mul(100);
84
- // finalBorrowRate = baseBorrowRate * (1 + riskPremiumFraction)
85
- const userBorrowApr = baseBorrowApr.mul(new decimal_js_1.default(1).add(riskPremiumFraction));
86
- result[identifier] = {
87
- borrowRate: (0, moneymarket_1.aprToApy)(userBorrowApr.toString()),
88
- // Supply rate is market-level (not user-specific), use existing value
89
- supplyRate: assetData.supplyRate,
90
- };
91
- });
92
- return result;
93
- };
94
- exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
95
77
  const calculateNetApyAaveV4 = ({ usedAssets, assetsData, }) => {
96
78
  const riskPremiumBps = (0, exports.calcUserRiskPremiumBps)(usedAssets, assetsData);
97
79
  const riskPremiumFraction = new decimal_js_1.default(riskPremiumBps).div(10000);
@@ -270,7 +252,7 @@ const getAaveV4ApyAfterValuesEstimationInner = (selectedSpoke, assetsData, actio
270
252
  const data = yield viewContract.read.getApyAfterValuesEstimation([selectedSpoke.address, params]);
271
253
  const rates = {};
272
254
  data.forEach((item) => {
273
- const { hubDrawnRateEstimation, hubTotalDrawnEstimation, hubTotalLiquidityEstimation, hubSwept, liquidityFee, reserveId, } = item;
255
+ const { hubDrawnRateEstimation, hubTotalDrawnEstimation, hubTotalLiquidityEstimation, hubSwept, reserveId, } = item;
274
256
  const drawnRate = new decimal_js_1.default(hubDrawnRateEstimation.toString()).div(new decimal_js_1.default(10).pow(27));
275
257
  const borrowApr = drawnRate.mul(100);
276
258
  const assetData = Object.values(assetsData).find(({ reserveId: rId }) => rId === Number(reserveId));
@@ -278,7 +260,7 @@ const getAaveV4ApyAfterValuesEstimationInner = (selectedSpoke, assetsData, actio
278
260
  const swept = new decimal_js_1.default(hubSwept.toString());
279
261
  const hubUtilizationDenominator = totalDrawn.add(swept).add(hubTotalLiquidityEstimation.toString());
280
262
  const hubUtilization = hubUtilizationDenominator.isZero() ? new decimal_js_1.default(0) : totalDrawn.div(hubUtilizationDenominator);
281
- const supplyApr = borrowApr.mul(hubUtilization).mul((assetData === null || assetData === void 0 ? void 0 : assetData.premiumMultiplier) || '0').mul(new decimal_js_1.default(1).minus((assetData === null || assetData === void 0 ? void 0 : assetData.liquidityFee) || '0'));
263
+ const supplyApr = borrowApr.mul(hubUtilization).mul((assetData === null || assetData === void 0 ? void 0 : assetData.premiumMultiplier) || '1').mul(new decimal_js_1.default(1).minus((assetData === null || assetData === void 0 ? void 0 : assetData.liquidityFee) || '0'));
282
264
  rates[`${assetData === null || assetData === void 0 ? void 0 : assetData.symbol}-${assetData === null || assetData === void 0 ? void 0 : assetData.reserveId}`] = {
283
265
  borrowRate: (0, moneymarket_1.aprToApy)(borrowApr.toString()),
284
266
  supplyRate: (0, moneymarket_1.aprToApy)(supplyApr.toString()),
@@ -139,73 +139,73 @@ const getApyAfterValuesEstimation = (selectedMarket, actions, provider, network)
139
139
  });
140
140
  exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
141
141
  const API_URL = 'https://blue-api.morpho.org/graphql';
142
- const MARKET_QUERY = `
143
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
144
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
145
- reallocatableLiquidityAssets
146
- targetBorrowUtilization
147
- loanAsset {
148
- address
149
- decimals
150
- priceUsd
151
- }
152
- state {
153
- liquidityAssets
154
- borrowAssets
155
- supplyAssets
156
- }
157
- publicAllocatorSharedLiquidity {
158
- assets
159
- vault {
160
- address
161
- name
162
- }
163
- allocationMarket {
164
- uniqueKey
165
- loanAsset {
166
- address
167
- }
168
- collateralAsset {
169
- address
170
- }
171
- irmAddress
172
- oracle {
173
- address
174
- }
175
- lltv
176
- }
177
- }
178
- loanAsset {
179
- address
180
- }
181
- collateralAsset {
182
- address
183
- }
184
- oracle {
185
- address
186
- }
187
- irmAddress
188
- lltv
189
- }
190
- }
142
+ const MARKET_QUERY = `
143
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
144
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
145
+ reallocatableLiquidityAssets
146
+ targetBorrowUtilization
147
+ loanAsset {
148
+ address
149
+ decimals
150
+ priceUsd
151
+ }
152
+ state {
153
+ liquidityAssets
154
+ borrowAssets
155
+ supplyAssets
156
+ }
157
+ publicAllocatorSharedLiquidity {
158
+ assets
159
+ vault {
160
+ address
161
+ name
162
+ }
163
+ allocationMarket {
164
+ uniqueKey
165
+ loanAsset {
166
+ address
167
+ }
168
+ collateralAsset {
169
+ address
170
+ }
171
+ irmAddress
172
+ oracle {
173
+ address
174
+ }
175
+ lltv
176
+ }
177
+ }
178
+ loanAsset {
179
+ address
180
+ }
181
+ collateralAsset {
182
+ address
183
+ }
184
+ oracle {
185
+ address
186
+ }
187
+ irmAddress
188
+ lltv
189
+ }
190
+ }
191
191
  `;
192
- const REWARDS_QUERY = `
193
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
194
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
195
- uniqueKey
196
- state {
197
- rewards {
198
- amountPerSuppliedToken
199
- supplyApr
200
- amountPerBorrowedToken
201
- borrowApr
202
- asset {
203
- address
204
- }
205
- }
206
- }
207
- }
208
- }
192
+ const REWARDS_QUERY = `
193
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
194
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
195
+ uniqueKey
196
+ state {
197
+ rewards {
198
+ amountPerSuppliedToken
199
+ supplyApr
200
+ amountPerBorrowedToken
201
+ borrowApr
202
+ asset {
203
+ address
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
209
  `;
210
210
  /**
211
211
  * Get reallocatable liquidity to a given market and target borrow utilization
@@ -54,23 +54,23 @@ const morphoVaultsOptions = __importStar(require("./options"));
54
54
  exports.morphoVaultsOptions = morphoVaultsOptions;
55
55
  const viem_1 = require("../../services/viem");
56
56
  const contracts_1 = require("../../contracts");
57
- const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
58
- vaultByAddress(chainId: 1, address: "${vaultAddress}") {
59
- id,
60
- dailyApy,
61
- dailyApys {
62
- apy, netApy
63
- },
64
- monthlyApys {
65
- apy, netApy
66
- },
67
- liquidity {
68
- underlying, usd,
69
- },
70
- asset {
71
- priceUsd
72
- }
73
- }
57
+ const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
58
+ vaultByAddress(chainId: 1, address: "${vaultAddress}") {
59
+ id,
60
+ dailyApy,
61
+ dailyApys {
62
+ apy, netApy
63
+ },
64
+ monthlyApys {
65
+ apy, netApy
66
+ },
67
+ liquidity {
68
+ underlying, usd,
69
+ },
70
+ asset {
71
+ priceUsd
72
+ }
73
+ }
74
74
  }`;
75
75
  const MORPHO_BLUE_API = 'https://blue-api.morpho.org/graphql';
76
76
  const _getMorphoVaultData = (provider, network, morphoVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
@@ -1,9 +1,5 @@
1
1
  import { AaveV4AggregatedPositionData, AaveV4AssetsData, AaveV4ReserveAssetData, AaveV4SpokeInfo, AaveV4UsedReserveAsset, AaveV4UsedReserveAssets, EthereumProvider, LeverageType, NetworkNumber } from '../../types';
2
2
  export declare const calcUserRiskPremiumBps: (usedAssets: AaveV4UsedReserveAssets, assetsData: AaveV4AssetsData) => number;
3
- export declare const getApyAfterValuesEstimation: (usedAssets: AaveV4UsedReserveAssets, assetsData: AaveV4AssetsData) => Record<string, {
4
- borrowRate: string;
5
- supplyRate: string;
6
- }>;
7
3
  export declare const calculateNetApyAaveV4: ({ usedAssets, assetsData, }: {
8
4
  usedAssets: AaveV4UsedReserveAssets;
9
5
  assetsData: AaveV4AssetsData;
@@ -23,11 +19,11 @@ export declare const aaveV4GetAggregatedPositionData: ({ usedAssets, assetsData,
23
19
  network: NetworkNumber;
24
20
  useUserCollateralFactor?: boolean;
25
21
  }) => AaveV4AggregatedPositionData;
26
- export declare const getAaveV4ApyAfterValuesEstimation: (selectedSpoke: AaveV4SpokeInfo, assetsData: AaveV4AssetsData, actions: [{
22
+ export declare const getAaveV4ApyAfterValuesEstimation: (selectedSpoke: AaveV4SpokeInfo, assetsData: AaveV4AssetsData, actions: {
27
23
  action: string;
28
24
  amount: string;
29
25
  asset: string;
30
- }], provider: EthereumProvider, network: NetworkNumber) => Promise<{
26
+ }[], provider: EthereumProvider, network: NetworkNumber) => Promise<{
31
27
  [key: string]: {
32
28
  supplyRate: string;
33
29
  borrowRate: string;
@@ -67,23 +67,6 @@ export const calcUserRiskPremiumBps = (usedAssets, assetsData) => {
67
67
  const riskPremiumBps = numerator.div(coveredDebt);
68
68
  return riskPremiumBps.toNumber();
69
69
  };
70
- export const getApyAfterValuesEstimation = (usedAssets, assetsData) => {
71
- const riskPremiumBps = calcUserRiskPremiumBps(usedAssets, assetsData);
72
- const riskPremiumFraction = new Dec(riskPremiumBps).div(10000); // bps to fraction
73
- const result = {};
74
- Object.entries(assetsData).forEach(([identifier, assetData]) => {
75
- const drawnRate = new Dec(assetData.drawnRate);
76
- const baseBorrowApr = drawnRate.mul(100);
77
- // finalBorrowRate = baseBorrowRate * (1 + riskPremiumFraction)
78
- const userBorrowApr = baseBorrowApr.mul(new Dec(1).add(riskPremiumFraction));
79
- result[identifier] = {
80
- borrowRate: aprToApy(userBorrowApr.toString()),
81
- // Supply rate is market-level (not user-specific), use existing value
82
- supplyRate: assetData.supplyRate,
83
- };
84
- });
85
- return result;
86
- };
87
70
  export const calculateNetApyAaveV4 = ({ usedAssets, assetsData, }) => {
88
71
  const riskPremiumBps = calcUserRiskPremiumBps(usedAssets, assetsData);
89
72
  const riskPremiumFraction = new Dec(riskPremiumBps).div(10000);
@@ -258,7 +241,7 @@ const getAaveV4ApyAfterValuesEstimationInner = (selectedSpoke, assetsData, actio
258
241
  const data = yield viewContract.read.getApyAfterValuesEstimation([selectedSpoke.address, params]);
259
242
  const rates = {};
260
243
  data.forEach((item) => {
261
- const { hubDrawnRateEstimation, hubTotalDrawnEstimation, hubTotalLiquidityEstimation, hubSwept, liquidityFee, reserveId, } = item;
244
+ const { hubDrawnRateEstimation, hubTotalDrawnEstimation, hubTotalLiquidityEstimation, hubSwept, reserveId, } = item;
262
245
  const drawnRate = new Dec(hubDrawnRateEstimation.toString()).div(new Dec(10).pow(27));
263
246
  const borrowApr = drawnRate.mul(100);
264
247
  const assetData = Object.values(assetsData).find(({ reserveId: rId }) => rId === Number(reserveId));
@@ -266,7 +249,7 @@ const getAaveV4ApyAfterValuesEstimationInner = (selectedSpoke, assetsData, actio
266
249
  const swept = new Dec(hubSwept.toString());
267
250
  const hubUtilizationDenominator = totalDrawn.add(swept).add(hubTotalLiquidityEstimation.toString());
268
251
  const hubUtilization = hubUtilizationDenominator.isZero() ? new Dec(0) : totalDrawn.div(hubUtilizationDenominator);
269
- const supplyApr = borrowApr.mul(hubUtilization).mul((assetData === null || assetData === void 0 ? void 0 : assetData.premiumMultiplier) || '0').mul(new Dec(1).minus((assetData === null || assetData === void 0 ? void 0 : assetData.liquidityFee) || '0'));
252
+ const supplyApr = borrowApr.mul(hubUtilization).mul((assetData === null || assetData === void 0 ? void 0 : assetData.premiumMultiplier) || '1').mul(new Dec(1).minus((assetData === null || assetData === void 0 ? void 0 : assetData.liquidityFee) || '0'));
270
253
  rates[`${assetData === null || assetData === void 0 ? void 0 : assetData.symbol}-${assetData === null || assetData === void 0 ? void 0 : assetData.reserveId}`] = {
271
254
  borrowRate: aprToApy(borrowApr.toString()),
272
255
  supplyRate: aprToApy(supplyApr.toString()),
@@ -129,73 +129,73 @@ export const getApyAfterValuesEstimation = (selectedMarket, actions, provider, n
129
129
  return { borrowRate, supplyRate };
130
130
  });
131
131
  const API_URL = 'https://blue-api.morpho.org/graphql';
132
- const MARKET_QUERY = `
133
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
134
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
135
- reallocatableLiquidityAssets
136
- targetBorrowUtilization
137
- loanAsset {
138
- address
139
- decimals
140
- priceUsd
141
- }
142
- state {
143
- liquidityAssets
144
- borrowAssets
145
- supplyAssets
146
- }
147
- publicAllocatorSharedLiquidity {
148
- assets
149
- vault {
150
- address
151
- name
152
- }
153
- allocationMarket {
154
- uniqueKey
155
- loanAsset {
156
- address
157
- }
158
- collateralAsset {
159
- address
160
- }
161
- irmAddress
162
- oracle {
163
- address
164
- }
165
- lltv
166
- }
167
- }
168
- loanAsset {
169
- address
170
- }
171
- collateralAsset {
172
- address
173
- }
174
- oracle {
175
- address
176
- }
177
- irmAddress
178
- lltv
179
- }
180
- }
132
+ const MARKET_QUERY = `
133
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
134
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
135
+ reallocatableLiquidityAssets
136
+ targetBorrowUtilization
137
+ loanAsset {
138
+ address
139
+ decimals
140
+ priceUsd
141
+ }
142
+ state {
143
+ liquidityAssets
144
+ borrowAssets
145
+ supplyAssets
146
+ }
147
+ publicAllocatorSharedLiquidity {
148
+ assets
149
+ vault {
150
+ address
151
+ name
152
+ }
153
+ allocationMarket {
154
+ uniqueKey
155
+ loanAsset {
156
+ address
157
+ }
158
+ collateralAsset {
159
+ address
160
+ }
161
+ irmAddress
162
+ oracle {
163
+ address
164
+ }
165
+ lltv
166
+ }
167
+ }
168
+ loanAsset {
169
+ address
170
+ }
171
+ collateralAsset {
172
+ address
173
+ }
174
+ oracle {
175
+ address
176
+ }
177
+ irmAddress
178
+ lltv
179
+ }
180
+ }
181
181
  `;
182
- const REWARDS_QUERY = `
183
- query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
184
- marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
185
- uniqueKey
186
- state {
187
- rewards {
188
- amountPerSuppliedToken
189
- supplyApr
190
- amountPerBorrowedToken
191
- borrowApr
192
- asset {
193
- address
194
- }
195
- }
196
- }
197
- }
198
- }
182
+ const REWARDS_QUERY = `
183
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
184
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
185
+ uniqueKey
186
+ state {
187
+ rewards {
188
+ amountPerSuppliedToken
189
+ supplyApr
190
+ amountPerBorrowedToken
191
+ borrowApr
192
+ asset {
193
+ address
194
+ }
195
+ }
196
+ }
197
+ }
198
+ }
199
199
  `;
200
200
  /**
201
201
  * Get reallocatable liquidity to a given market and target borrow utilization
@@ -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* () {