@defisaver/positions-sdk 0.0.182 → 0.0.183-dev-allocator-2

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 (85) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +69 -69
  4. package/cjs/aaveV3/index.js +3 -3
  5. package/cjs/config/contracts.d.ts +3 -0
  6. package/cjs/config/contracts.js +3 -0
  7. package/cjs/helpers/aaveHelpers/index.js +0 -1
  8. package/cjs/helpers/morphoBlueHelpers/index.d.ts +5 -0
  9. package/cjs/helpers/morphoBlueHelpers/index.js +142 -1
  10. package/cjs/staking/staking.d.ts +2 -3
  11. package/cjs/staking/staking.js +2 -2
  12. package/cjs/types/morphoBlue.d.ts +31 -0
  13. package/esm/aaveV3/index.js +4 -4
  14. package/esm/config/contracts.d.ts +3 -0
  15. package/esm/config/contracts.js +3 -0
  16. package/esm/helpers/aaveHelpers/index.js +0 -1
  17. package/esm/helpers/morphoBlueHelpers/index.d.ts +5 -0
  18. package/esm/helpers/morphoBlueHelpers/index.js +139 -0
  19. package/esm/staking/staking.d.ts +2 -3
  20. package/esm/staking/staking.js +2 -2
  21. package/esm/types/morphoBlue.d.ts +31 -0
  22. package/package.json +49 -49
  23. package/src/aaveV2/index.ts +227 -227
  24. package/src/aaveV3/index.ts +624 -628
  25. package/src/assets/index.ts +60 -60
  26. package/src/chickenBonds/index.ts +123 -123
  27. package/src/compoundV2/index.ts +220 -220
  28. package/src/compoundV3/index.ts +282 -282
  29. package/src/config/contracts.js +1043 -1040
  30. package/src/constants/index.ts +6 -6
  31. package/src/contracts.ts +130 -130
  32. package/src/curveUsd/index.ts +229 -229
  33. package/src/eulerV2/index.ts +303 -303
  34. package/src/exchange/index.ts +17 -17
  35. package/src/helpers/aaveHelpers/index.ts +198 -199
  36. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  37. package/src/helpers/compoundHelpers/index.ts +246 -246
  38. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  39. package/src/helpers/eulerHelpers/index.ts +232 -232
  40. package/src/helpers/index.ts +8 -8
  41. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  42. package/src/helpers/makerHelpers/index.ts +94 -94
  43. package/src/helpers/morphoBlueHelpers/index.ts +274 -115
  44. package/src/helpers/sparkHelpers/index.ts +150 -150
  45. package/src/index.ts +48 -48
  46. package/src/liquity/index.ts +116 -116
  47. package/src/llamaLend/index.ts +275 -275
  48. package/src/maker/index.ts +117 -117
  49. package/src/markets/aave/index.ts +152 -152
  50. package/src/markets/aave/marketAssets.ts +46 -46
  51. package/src/markets/compound/index.ts +173 -173
  52. package/src/markets/compound/marketsAssets.ts +64 -64
  53. package/src/markets/curveUsd/index.ts +69 -69
  54. package/src/markets/euler/index.ts +26 -26
  55. package/src/markets/index.ts +23 -23
  56. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  57. package/src/markets/llamaLend/index.ts +235 -235
  58. package/src/markets/morphoBlue/index.ts +809 -809
  59. package/src/markets/spark/index.ts +29 -29
  60. package/src/markets/spark/marketAssets.ts +10 -10
  61. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  62. package/src/morphoAaveV2/index.ts +256 -256
  63. package/src/morphoAaveV3/index.ts +630 -630
  64. package/src/morphoBlue/index.ts +171 -171
  65. package/src/multicall/index.ts +22 -22
  66. package/src/services/dsrService.ts +15 -15
  67. package/src/services/priceService.ts +21 -21
  68. package/src/services/utils.ts +56 -56
  69. package/src/setup.ts +8 -8
  70. package/src/spark/index.ts +461 -461
  71. package/src/staking/staking.ts +220 -222
  72. package/src/types/aave.ts +270 -270
  73. package/src/types/chickenBonds.ts +45 -45
  74. package/src/types/common.ts +84 -84
  75. package/src/types/compound.ts +129 -129
  76. package/src/types/curveUsd.ts +118 -118
  77. package/src/types/euler.ts +171 -171
  78. package/src/types/index.ts +9 -9
  79. package/src/types/liquity.ts +30 -30
  80. package/src/types/llamaLend.ts +155 -155
  81. package/src/types/maker.ts +50 -50
  82. package/src/types/morphoBlue.ts +184 -154
  83. package/src/types/spark.ts +131 -131
  84. package/.vscode/launch.json +0 -17
  85. package/.vscode/settings.json +0 -37
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,69 +1,69 @@
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
- - [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
10
- - [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
11
- - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
12
- - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
13
- - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
14
- - [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
15
-
16
- ## Setup
17
- Supported Node version is v10.
18
-
19
- - run `npm install` (first time)
20
- - run `npm run build`
21
-
22
- `build` command will generate contracts and build ejs and esm folders
23
-
24
- ## How to use
25
- [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
26
-
27
- This is a Compound V3 example, and every other protocol is similar
28
- ```js
29
- import Web3 from 'web3';
30
- import { compoundV3 } from '@defisaver/positions-sdk';
31
-
32
-
33
- // every protocol has market data and user data getters
34
- const {
35
- getCompoundV3MarketsData,
36
- getCompoundV3AccountData,
37
- } = compoundV3;
38
-
39
- const provider = 'Your RPC provider';
40
- const web3 = new Web3(provider);
41
-
42
- const user = '0x123...';
43
-
44
- const { assetsData } = await getCompoundV3MarketsData(
45
- web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
46
- 1, // network
47
- selectedMarket, // market object like in /src/markets/compound/index.ts
48
- web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
49
- );
50
-
51
- const userData = await getCompoundV3AccountData(
52
- web3,
53
- 1, // network
54
- userAddress, // EOA or DSProxy
55
- '', // proxy address of the user, or just empty string if checking for EOA
56
- {
57
- selectedMarket, // market object as in /src/markets/compound/index.ts
58
- assetsData,
59
- }
60
- );
61
- ```
62
-
63
- More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
64
-
65
- ## Testing
66
-
67
- `npm run test` - Run all tests
68
-
69
- `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
+ - [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
10
+ - [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
11
+ - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
12
+ - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
13
+ - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
14
+ - [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
15
+
16
+ ## Setup
17
+ Supported Node version is v10.
18
+
19
+ - run `npm install` (first time)
20
+ - run `npm run build`
21
+
22
+ `build` command will generate contracts and build ejs and esm folders
23
+
24
+ ## How to use
25
+ [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
26
+
27
+ This is a Compound V3 example, and every other protocol is similar
28
+ ```js
29
+ import Web3 from 'web3';
30
+ import { compoundV3 } from '@defisaver/positions-sdk';
31
+
32
+
33
+ // every protocol has market data and user data getters
34
+ const {
35
+ getCompoundV3MarketsData,
36
+ getCompoundV3AccountData,
37
+ } = compoundV3;
38
+
39
+ const provider = 'Your RPC provider';
40
+ const web3 = new Web3(provider);
41
+
42
+ const user = '0x123...';
43
+
44
+ const { assetsData } = await getCompoundV3MarketsData(
45
+ web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
46
+ 1, // network
47
+ selectedMarket, // market object like in /src/markets/compound/index.ts
48
+ web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
49
+ );
50
+
51
+ const userData = await getCompoundV3AccountData(
52
+ web3,
53
+ 1, // network
54
+ userAddress, // EOA or DSProxy
55
+ '', // proxy address of the user, or just empty string if checking for EOA
56
+ {
57
+ selectedMarket, // market object as in /src/markets/compound/index.ts
58
+ assetsData,
59
+ }
60
+ );
61
+ ```
62
+
63
+ More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
64
+
65
+ ## Testing
66
+
67
+ `npm run test` - Run all tests
68
+
69
+ `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
@@ -104,7 +104,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
104
104
  params: [],
105
105
  },
106
106
  {
107
- target: (0, tokens_1.getAssetInfo)('GHO').address,
107
+ target: (0, tokens_1.getAssetInfo)('GHO', network).address,
108
108
  abiItem: (0, utils_1.getAbiItem)(GhoTokenAbi, 'getFacilitatorsList'),
109
109
  params: [],
110
110
  },
@@ -148,7 +148,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
148
148
  const assetsData = yield Promise.all(loanInfo
149
149
  .map((tokenMarket, i) => __awaiter(this, void 0, void 0, function* () {
150
150
  const symbol = market.assets[i];
151
- const nativeAsset = symbol === 'GHO';
151
+ const nativeAsset = symbol === 'GHO' && network === common_1.NetworkNumber.Eth;
152
152
  // eslint-disable-next-line guard-for-in
153
153
  for (const eModeIndex in eModeCategoriesData) {
154
154
  if ((0, utils_1.isEnabledOnBitmap)(Number(eModeCategoriesData[eModeIndex].collateralBitmap), Number(tokenMarket.assetId)))
@@ -423,7 +423,7 @@ const getAaveV3AccountData = (web3, network, address, extractedState) => __await
423
423
  }
424
424
  if (!usedAssets[asset])
425
425
  usedAssets[asset] = {};
426
- const nativeAsset = asset === 'GHO';
426
+ const nativeAsset = asset === 'GHO' && network === common_1.NetworkNumber.Eth;
427
427
  let discountRateOnBorrow = '0';
428
428
  const borrowed = new decimal_js_1.default(borrowedStable).add(borrowedVariable).toString();
429
429
  if (nativeAsset && new decimal_js_1.default(borrowed).gt(0) && new decimal_js_1.default(stkAaveBalance).gt(0)) {
@@ -2280,6 +2280,9 @@ export namespace GHO {
2280
2280
  "1": {
2281
2281
  address: string;
2282
2282
  };
2283
+ "42161": {
2284
+ address: string;
2285
+ };
2283
2286
  };
2284
2287
  export { networks_15 as networks };
2285
2288
  }
@@ -312,6 +312,9 @@ module.exports = {
312
312
  "networks": {
313
313
  "1": {
314
314
  "address": "0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f"
315
+ },
316
+ "42161": {
317
+ "address": "0x7dfF72693f6A4149b17e7C6314655f6A9F7c8B33"
315
318
  }
316
319
  }
317
320
  },
@@ -115,7 +115,6 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
115
115
  usedAssets,
116
116
  assetsData,
117
117
  isMorpho: (0, exports.isMorphoAave)({ selectedMarket }),
118
- network,
119
118
  });
120
119
  payload.netApy = netApy;
121
120
  payload.incentiveUsd = incentiveUsd;
@@ -12,3 +12,8 @@ export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMar
12
12
  borrowRate: string;
13
13
  supplyRate: string;
14
14
  }>;
15
+ export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<string>;
16
+ export declare const getReallocation: (marketId: string, amountToBorrow: string, network?: NetworkNumber) => Promise<{
17
+ vaults: string[];
18
+ withdrawals: [string[], string][][];
19
+ }>;
@@ -12,13 +12,15 @@ 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.getApyAfterValuesEstimation = exports.getBorrowRate = exports.getSupplyRate = exports.getMorphoBlueAggregatedPositionData = void 0;
15
+ exports.getReallocation = exports.getReallocatableLiquidity = exports.getApyAfterValuesEstimation = exports.getBorrowRate = exports.getSupplyRate = exports.getMorphoBlueAggregatedPositionData = 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");
19
19
  const staking_1 = require("../../staking");
20
+ const common_1 = require("../../types/common");
20
21
  const constants_1 = require("../../constants");
21
22
  const contracts_1 = require("../../contracts");
23
+ const utils_1 = require("../../services/utils");
22
24
  const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, marketInfo }) => {
23
25
  var _a, _b, _c, _d, _e, _f;
24
26
  const payload = {};
@@ -110,3 +112,142 @@ const getApyAfterValuesEstimation = (selectedMarket, action, amount, asset, web3
110
112
  return { borrowRate, supplyRate };
111
113
  });
112
114
  exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
115
+ const API_URL = 'https://blue-api.morpho.org/graphql';
116
+ const MARKET_QUERY = `
117
+ query MarketByUniqueKey($uniqueKey: String!, $chainId: Int!) {
118
+ marketByUniqueKey(uniqueKey: $uniqueKey, chainId: $chainId) {
119
+ reallocatableLiquidityAssets
120
+ targetBorrowUtilization
121
+ loanAsset {
122
+ address
123
+ decimals
124
+ priceUsd
125
+ }
126
+ state {
127
+ liquidityAssets
128
+ borrowAssets
129
+ supplyAssets
130
+ }
131
+ publicAllocatorSharedLiquidity {
132
+ assets
133
+ vault {
134
+ address
135
+ name
136
+ }
137
+ allocationMarket {
138
+ uniqueKey
139
+ loanAsset {
140
+ address
141
+ }
142
+ collateralAsset {
143
+ address
144
+ }
145
+ irmAddress
146
+ oracle {
147
+ address
148
+ }
149
+ lltv
150
+ }
151
+ }
152
+ loanAsset {
153
+ address
154
+ }
155
+ collateralAsset {
156
+ address
157
+ }
158
+ oracle {
159
+ address
160
+ }
161
+ irmAddress
162
+ lltv
163
+ }
164
+ }
165
+ `;
166
+ const getReallocatableLiquidity = (marketId, network = common_1.NetworkNumber.Eth) => __awaiter(void 0, void 0, void 0, function* () {
167
+ var _a;
168
+ const response = yield fetch(API_URL, {
169
+ method: 'POST',
170
+ headers: { 'Content-Type': 'application/json' },
171
+ body: JSON.stringify({
172
+ query: MARKET_QUERY,
173
+ variables: { uniqueKey: marketId, chainId: network },
174
+ }),
175
+ });
176
+ const data = yield response.json();
177
+ const marketData = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.marketByUniqueKey;
178
+ if (!marketData)
179
+ throw new Error('Market data not found');
180
+ return marketData.reallocatableLiquidityAssets;
181
+ });
182
+ exports.getReallocatableLiquidity = getReallocatableLiquidity;
183
+ const getReallocation = (marketId, amountToBorrow, network = common_1.NetworkNumber.Eth) => __awaiter(void 0, void 0, void 0, function* () {
184
+ var _b, _c, _d;
185
+ const response = yield fetch(API_URL, {
186
+ method: 'POST',
187
+ headers: { 'Content-Type': 'application/json' },
188
+ body: JSON.stringify({
189
+ query: MARKET_QUERY,
190
+ variables: { uniqueKey: marketId, chainId: network },
191
+ }),
192
+ });
193
+ const data = yield response.json();
194
+ const marketData = (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.marketByUniqueKey;
195
+ if (!marketData)
196
+ throw new Error('Market data not found');
197
+ const newTotalBorrowAssets = new decimal_js_1.default(marketData.state.borrowAssets).add(amountToBorrow).toString();
198
+ const leftToBorrow = new decimal_js_1.default(marketData.state.supplyAssets).sub(marketData.state.borrowAssets).toString();
199
+ const newUtil = new decimal_js_1.default(newTotalBorrowAssets).div(marketData.state.supplyAssets).toString();
200
+ const newUtilScaled = new decimal_js_1.default(newUtil).mul(1e18).toString();
201
+ if (new decimal_js_1.default(newUtilScaled).lt(marketData.targetBorrowUtilization))
202
+ return { vaults: [], withdrawals: [] };
203
+ let liquidityToAllocate = new decimal_js_1.default(newTotalBorrowAssets).div(marketData.targetBorrowUtilization).mul(1e18).sub(marketData.state.supplyAssets)
204
+ .toFixed(0)
205
+ .toString();
206
+ if (new decimal_js_1.default(marketData.reallocatableLiquidityAssets).lt(liquidityToAllocate)) {
207
+ liquidityToAllocate = new decimal_js_1.default(amountToBorrow).sub(leftToBorrow).toString();
208
+ if (new decimal_js_1.default(marketData.reallocatableLiquidityAssets).lt(liquidityToAllocate))
209
+ throw new Error('Not enough liquidity available to allocate');
210
+ }
211
+ const vaultTotalAssets = marketData.publicAllocatorSharedLiquidity.reduce((acc, item) => {
212
+ const vaultAddress = item.vault.address;
213
+ acc[vaultAddress] = new decimal_js_1.default(acc[vaultAddress] || '0').add(item.assets).toString();
214
+ return acc;
215
+ }, {});
216
+ const sortedVaults = Object.entries(vaultTotalAssets).sort(([, a], [, b]) => new decimal_js_1.default(b || '0').sub(a || '0').toNumber());
217
+ const withdrawalsPerVault = {};
218
+ let totalReallocated = '0';
219
+ for (const [vaultAddress] of sortedVaults) {
220
+ if (new decimal_js_1.default(totalReallocated).gte(liquidityToAllocate))
221
+ break;
222
+ const vaultAllocations = marketData.publicAllocatorSharedLiquidity.filter((item) => (0, utils_1.compareAddresses)(item.vault.address, vaultAddress));
223
+ for (const item of vaultAllocations) {
224
+ if (new decimal_js_1.default(totalReallocated).gte(liquidityToAllocate))
225
+ break;
226
+ const itemAmount = item.assets;
227
+ const leftToAllocate = new decimal_js_1.default(liquidityToAllocate).sub(totalReallocated).toString();
228
+ const amountToTake = new decimal_js_1.default(itemAmount).lt(leftToAllocate) ? itemAmount : leftToAllocate;
229
+ totalReallocated = new decimal_js_1.default(totalReallocated).add(amountToTake).toString();
230
+ const withdrawal = [
231
+ [
232
+ item.allocationMarket.loanAsset.address,
233
+ (_c = item.allocationMarket.collateralAsset) === null || _c === void 0 ? void 0 : _c.address,
234
+ (_d = item.allocationMarket.oracle) === null || _d === void 0 ? void 0 : _d.address,
235
+ item.allocationMarket.irmAddress,
236
+ item.allocationMarket.lltv,
237
+ ],
238
+ amountToTake.toString(),
239
+ ];
240
+ if (!withdrawalsPerVault[vaultAddress]) {
241
+ withdrawalsPerVault[vaultAddress] = [];
242
+ }
243
+ withdrawalsPerVault[vaultAddress].push(withdrawal);
244
+ }
245
+ }
246
+ const vaults = Object.keys(withdrawalsPerVault);
247
+ const withdrawals = vaults.map((vaultAddress) => withdrawalsPerVault[vaultAddress]);
248
+ return {
249
+ vaults,
250
+ withdrawals,
251
+ };
252
+ });
253
+ exports.getReallocation = getReallocation;
@@ -1,5 +1,5 @@
1
1
  import Web3 from 'web3';
2
- import { MMAssetsData, MMUsedAssets, NetworkNumber } from '../types/common';
2
+ import { MMAssetsData, MMUsedAssets } from '../types/common';
3
3
  export declare const getStETHApy: (web3: Web3, fromBlock?: number, blockNumber?: 'latest' | number) => Promise<string>;
4
4
  export declare const getCbETHApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
5
5
  export declare const getREthApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
@@ -8,11 +8,10 @@ export declare const getSsrApy: () => Promise<string>;
8
8
  export declare const STAKING_ASSETS: string[];
9
9
  export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => "0" | Promise<any> | undefined;
10
10
  export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
11
- export declare const calculateNetApy: ({ usedAssets, assetsData, isMorpho, network, }: {
11
+ export declare const calculateNetApy: ({ usedAssets, assetsData, isMorpho }: {
12
12
  usedAssets: MMUsedAssets;
13
13
  assetsData: MMAssetsData;
14
14
  isMorpho?: boolean | undefined;
15
- network?: NetworkNumber | undefined;
16
15
  }) => {
17
16
  netApy: string;
18
17
  totalInterestUsd: string;
@@ -170,7 +170,7 @@ const calculateInterestEarned = (principal, interest, type, apy = false) => {
170
170
  return (+principal * (Math.pow(((1 + (+interest / 100) / constants_1.BLOCKS_IN_A_YEAR)), (constants_1.BLOCKS_IN_A_YEAR * interval)))) - +principal; // eslint-disable-line
171
171
  };
172
172
  exports.calculateInterestEarned = calculateInterestEarned;
173
- const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false, network = 1, }) => {
173
+ const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false }) => {
174
174
  const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
175
175
  const acc = Object.assign({}, _acc);
176
176
  const assetData = assetsData[usedAsset.symbol];
@@ -193,7 +193,7 @@ const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false, network = 1
193
193
  acc.borrowedUsd = new decimal_js_1.default(acc.borrowedUsd).add(amount).toString();
194
194
  const rate = isMorpho
195
195
  ? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
196
- : (usedAsset.symbol === 'GHO' && network === common_1.NetworkNumber.Eth)
196
+ : (usedAsset.symbol === 'GHO' && assetsData.nativeAsset)
197
197
  ? usedAsset.discountedBorrowRate
198
198
  : ((usedAsset === null || usedAsset === void 0 ? void 0 : usedAsset.interestMode) === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
199
199
  const borrowInterest = (0, exports.calculateInterestEarned)(amount, rate, 'year', true);
@@ -137,3 +137,34 @@ export interface MorphoBluePositionData {
137
137
  supplyShares: string;
138
138
  borrowShares: string;
139
139
  }
140
+ export interface MorphoBlueVault {
141
+ address: string;
142
+ }
143
+ export interface MorphoBlueAllocationMarket {
144
+ loanAsset: {
145
+ address: string;
146
+ };
147
+ collateralAsset: {
148
+ address: string;
149
+ };
150
+ oracle: {
151
+ address: string;
152
+ };
153
+ irmAddress: string;
154
+ lltv: string;
155
+ }
156
+ export interface MorphoBluePublicAllocatorItem {
157
+ vault: MorphoBlueVault;
158
+ assets: string;
159
+ allocationMarket: MorphoBlueAllocationMarket;
160
+ }
161
+ export interface MorphoBlueAllocatorMarketState {
162
+ borrowAssets: string;
163
+ supplyAssets: string;
164
+ }
165
+ export interface MorphoBlueRealloactionMarketData {
166
+ reallocatableLiquidityAssets: string;
167
+ targetBorrowUtilization: string;
168
+ publicAllocatorSharedLiquidity: MorphoBluePublicAllocatorItem[];
169
+ state: MorphoBlueAllocatorMarketState;
170
+ }
@@ -16,7 +16,7 @@ import { getStakingApy, STAKING_ASSETS } from '../staking';
16
16
  import { multicall } from '../multicall';
17
17
  import { getAssetsBalances } from '../assets';
18
18
  import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
19
- import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode, } from '../helpers/aaveHelpers';
19
+ import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode } from '../helpers/aaveHelpers';
20
20
  import { AAVE_V3 } from '../markets/aave';
21
21
  export const test = (web3, network) => {
22
22
  const contract = AaveV3ViewContract(web3, 1);
@@ -95,7 +95,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
95
95
  params: [],
96
96
  },
97
97
  {
98
- target: getAssetInfo('GHO').address,
98
+ target: getAssetInfo('GHO', network).address,
99
99
  abiItem: getAbiItem(GhoTokenAbi, 'getFacilitatorsList'),
100
100
  params: [],
101
101
  },
@@ -139,7 +139,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
139
139
  const assetsData = yield Promise.all(loanInfo
140
140
  .map((tokenMarket, i) => __awaiter(this, void 0, void 0, function* () {
141
141
  const symbol = market.assets[i];
142
- const nativeAsset = symbol === 'GHO';
142
+ const nativeAsset = symbol === 'GHO' && network === NetworkNumber.Eth;
143
143
  // eslint-disable-next-line guard-for-in
144
144
  for (const eModeIndex in eModeCategoriesData) {
145
145
  if (isEnabledOnBitmap(Number(eModeCategoriesData[eModeIndex].collateralBitmap), Number(tokenMarket.assetId)))
@@ -412,7 +412,7 @@ export const getAaveV3AccountData = (web3, network, address, extractedState) =>
412
412
  }
413
413
  if (!usedAssets[asset])
414
414
  usedAssets[asset] = {};
415
- const nativeAsset = asset === 'GHO';
415
+ const nativeAsset = asset === 'GHO' && network === NetworkNumber.Eth;
416
416
  let discountRateOnBorrow = '0';
417
417
  const borrowed = new Dec(borrowedStable).add(borrowedVariable).toString();
418
418
  if (nativeAsset && new Dec(borrowed).gt(0) && new Dec(stkAaveBalance).gt(0)) {
@@ -2280,6 +2280,9 @@ export namespace GHO {
2280
2280
  "1": {
2281
2281
  address: string;
2282
2282
  };
2283
+ "42161": {
2284
+ address: string;
2285
+ };
2283
2286
  };
2284
2287
  export { networks_15 as networks };
2285
2288
  }
@@ -311,6 +311,9 @@ module.exports = {
311
311
  "networks": {
312
312
  "1": {
313
313
  "address": "0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f"
314
+ },
315
+ "42161": {
316
+ "address": "0x7dfF72693f6A4149b17e7C6314655f6A9F7c8B33"
314
317
  }
315
318
  }
316
319
  },
@@ -98,7 +98,6 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
98
98
  usedAssets,
99
99
  assetsData,
100
100
  isMorpho: isMorphoAave({ selectedMarket }),
101
- network,
102
101
  });
103
102
  payload.netApy = netApy;
104
103
  payload.incentiveUsd = incentiveUsd;
@@ -12,3 +12,8 @@ export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMar
12
12
  borrowRate: string;
13
13
  supplyRate: string;
14
14
  }>;
15
+ export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<string>;
16
+ export declare const getReallocation: (marketId: string, amountToBorrow: string, network?: NetworkNumber) => Promise<{
17
+ vaults: string[];
18
+ withdrawals: [string[], string][][];
19
+ }>;