@morpho-org/morpho-sdk 4.1.0 → 4.2.0
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.
|
@@ -200,28 +200,28 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
200
200
|
*/
|
|
201
201
|
getPublicReallocationLiquidity(marketId: MarketId, options?: PublicAllocatorOptions): bigint;
|
|
202
202
|
/**
|
|
203
|
-
* Computes the liquidity available to bring `marketId` to `
|
|
203
|
+
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
204
204
|
* counting the public-allocator liquidity reallocatable into it.
|
|
205
205
|
*
|
|
206
206
|
* Returns the max borrow `x` keeping post-borrow utilization
|
|
207
|
-
* `(borrow + x) / (supply + L) ≤
|
|
207
|
+
* `(borrow + x) / (supply + L) ≤ utilization`, where `L` is the
|
|
208
208
|
* reallocatable liquidity added to the market's supply — equivalently
|
|
209
|
-
* `getBorrowToUtilization({ supply + L, borrow },
|
|
210
|
-
*
|
|
209
|
+
* `getBorrowToUtilization({ supply + L, borrow }, utilization)`. Below
|
|
210
|
+
* `utilization` this is the market's own borrow headroom plus `utilization · L`;
|
|
211
211
|
* reallocated supply also raises the supply denominator, so only that scaled
|
|
212
212
|
* share backs further borrow.
|
|
213
213
|
*
|
|
214
214
|
* Read-only metric — never throws on insufficiency:
|
|
215
215
|
* - returns only the market's own borrow headroom when
|
|
216
|
-
* `supplyTargetUtilization >
|
|
217
|
-
* trigger at that
|
|
218
|
-
* - returns `0n` when the market is already at or above
|
|
219
|
-
* too small to bring it back under.
|
|
216
|
+
* `supplyTargetUtilization > utilization` (reallocation would not
|
|
217
|
+
* trigger at that utilization);
|
|
218
|
+
* - returns `0n` when the market is already at or above `utilization` and `L`
|
|
219
|
+
* is too small to bring it back under.
|
|
220
220
|
*
|
|
221
221
|
* @param marketId - Target market to borrow from.
|
|
222
|
-
* @param
|
|
222
|
+
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
223
223
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
224
|
-
* @returns Available liquidity to the
|
|
224
|
+
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
225
225
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
226
226
|
* @example
|
|
227
227
|
* ```ts
|
|
@@ -245,6 +245,50 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
245
245
|
*
|
|
246
246
|
* // Max borrow keeping utilization at or below 90%, counting shared liquidity.
|
|
247
247
|
* const available: bigint =
|
|
248
|
+
* reallocationData.getAvailableLiquidityToUtilization(
|
|
249
|
+
* marketParams.id,
|
|
250
|
+
* parseEther("0.9"),
|
|
251
|
+
* { timestamp: block.timestamp },
|
|
252
|
+
* );
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
getAvailableLiquidityToUtilization(marketId: MarketId, utilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
256
|
+
/**
|
|
257
|
+
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
258
|
+
* counting the public-allocator liquidity reallocatable into it.
|
|
259
|
+
*
|
|
260
|
+
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
261
|
+
* `target` wording wrongly implied a market's configured supply-target
|
|
262
|
+
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
263
|
+
* Delegates to the new method; will be removed in the next major.
|
|
264
|
+
*
|
|
265
|
+
* @param marketId - Target market to borrow from.
|
|
266
|
+
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
267
|
+
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
268
|
+
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
269
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* import { createPublicClient, http, parseEther } from "viem";
|
|
273
|
+
* import { mainnet } from "viem/chains";
|
|
274
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
275
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
276
|
+
*
|
|
277
|
+
* const client = createPublicClient({
|
|
278
|
+
* chain: mainnet,
|
|
279
|
+
* transport: http(),
|
|
280
|
+
* }).extend(morphoViemExtension());
|
|
281
|
+
*
|
|
282
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
283
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
284
|
+
* const block = await client.getBlock();
|
|
285
|
+
* const reallocationData = await market.getReallocationData({
|
|
286
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
287
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
291
|
+
* const available: bigint =
|
|
248
292
|
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
249
293
|
* marketParams.id,
|
|
250
294
|
* parseEther("0.9"),
|
|
@@ -348,28 +348,28 @@ class ReallocationData {
|
|
|
348
348
|
return withdrawals.reduce((total, { assets }) => total + assets, 0n);
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
|
-
* Computes the liquidity available to bring `marketId` to `
|
|
351
|
+
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
352
352
|
* counting the public-allocator liquidity reallocatable into it.
|
|
353
353
|
*
|
|
354
354
|
* Returns the max borrow `x` keeping post-borrow utilization
|
|
355
|
-
* `(borrow + x) / (supply + L) ≤
|
|
355
|
+
* `(borrow + x) / (supply + L) ≤ utilization`, where `L` is the
|
|
356
356
|
* reallocatable liquidity added to the market's supply — equivalently
|
|
357
|
-
* `getBorrowToUtilization({ supply + L, borrow },
|
|
358
|
-
*
|
|
357
|
+
* `getBorrowToUtilization({ supply + L, borrow }, utilization)`. Below
|
|
358
|
+
* `utilization` this is the market's own borrow headroom plus `utilization · L`;
|
|
359
359
|
* reallocated supply also raises the supply denominator, so only that scaled
|
|
360
360
|
* share backs further borrow.
|
|
361
361
|
*
|
|
362
362
|
* Read-only metric — never throws on insufficiency:
|
|
363
363
|
* - returns only the market's own borrow headroom when
|
|
364
|
-
* `supplyTargetUtilization >
|
|
365
|
-
* trigger at that
|
|
366
|
-
* - returns `0n` when the market is already at or above
|
|
367
|
-
* too small to bring it back under.
|
|
364
|
+
* `supplyTargetUtilization > utilization` (reallocation would not
|
|
365
|
+
* trigger at that utilization);
|
|
366
|
+
* - returns `0n` when the market is already at or above `utilization` and `L`
|
|
367
|
+
* is too small to bring it back under.
|
|
368
368
|
*
|
|
369
369
|
* @param marketId - Target market to borrow from.
|
|
370
|
-
* @param
|
|
370
|
+
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
371
371
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
372
|
-
* @returns Available liquidity to the
|
|
372
|
+
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
373
373
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
374
374
|
* @example
|
|
375
375
|
* ```ts
|
|
@@ -393,26 +393,73 @@ class ReallocationData {
|
|
|
393
393
|
*
|
|
394
394
|
* // Max borrow keeping utilization at or below 90%, counting shared liquidity.
|
|
395
395
|
* const available: bigint =
|
|
396
|
-
* reallocationData.
|
|
396
|
+
* reallocationData.getAvailableLiquidityToUtilization(
|
|
397
397
|
* marketParams.id,
|
|
398
398
|
* parseEther("0.9"),
|
|
399
399
|
* { timestamp: block.timestamp },
|
|
400
400
|
* );
|
|
401
401
|
* ```
|
|
402
402
|
*/
|
|
403
|
-
// biome-ignore lint/complexity/useMaxParams: (marketId,
|
|
404
|
-
|
|
403
|
+
// biome-ignore lint/complexity/useMaxParams: (marketId, utilization, options) is the metric's public API
|
|
404
|
+
getAvailableLiquidityToUtilization(marketId, utilization = constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
405
405
|
const market = this.getMarket(marketId).accrueInterest(options?.timestamp);
|
|
406
406
|
// Below the allocator's trigger, no reallocation happens: own headroom only.
|
|
407
407
|
const supplyTargetUtilization = (0, utilization_js_1.getSupplyTargetUtilization)(marketId, options);
|
|
408
|
-
if (supplyTargetUtilization >
|
|
409
|
-
return market.getBorrowToUtilization(
|
|
408
|
+
if (supplyTargetUtilization > utilization)
|
|
409
|
+
return market.getBorrowToUtilization(utilization);
|
|
410
410
|
// Borrow-to-target on the post-reallocation supply; clamps to 0n above target.
|
|
411
411
|
const availableLiquidity = this.getPublicReallocationLiquidity(marketId, options);
|
|
412
412
|
return blue_sdk_1.MarketUtils.getBorrowToUtilization({
|
|
413
413
|
totalSupplyAssets: market.totalSupplyAssets + availableLiquidity,
|
|
414
414
|
totalBorrowAssets: market.totalBorrowAssets,
|
|
415
|
-
},
|
|
415
|
+
}, utilization);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
419
|
+
* counting the public-allocator liquidity reallocatable into it.
|
|
420
|
+
*
|
|
421
|
+
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
422
|
+
* `target` wording wrongly implied a market's configured supply-target
|
|
423
|
+
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
424
|
+
* Delegates to the new method; will be removed in the next major.
|
|
425
|
+
*
|
|
426
|
+
* @param marketId - Target market to borrow from.
|
|
427
|
+
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
428
|
+
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
429
|
+
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
430
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
431
|
+
* @example
|
|
432
|
+
* ```ts
|
|
433
|
+
* import { createPublicClient, http, parseEther } from "viem";
|
|
434
|
+
* import { mainnet } from "viem/chains";
|
|
435
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
436
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
437
|
+
*
|
|
438
|
+
* const client = createPublicClient({
|
|
439
|
+
* chain: mainnet,
|
|
440
|
+
* transport: http(),
|
|
441
|
+
* }).extend(morphoViemExtension());
|
|
442
|
+
*
|
|
443
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
444
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
445
|
+
* const block = await client.getBlock();
|
|
446
|
+
* const reallocationData = await market.getReallocationData({
|
|
447
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
448
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
449
|
+
* });
|
|
450
|
+
*
|
|
451
|
+
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
452
|
+
* const available: bigint =
|
|
453
|
+
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
454
|
+
* marketParams.id,
|
|
455
|
+
* parseEther("0.9"),
|
|
456
|
+
* { timestamp: block.timestamp },
|
|
457
|
+
* );
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
// biome-ignore lint/complexity/useMaxParams: (marketId, targetUtilization, options) is the metric's public API
|
|
461
|
+
getAvailableLiquidityToTargetUtilization(marketId, targetUtilization = constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
462
|
+
return this.getAvailableLiquidityToUtilization(marketId, targetUtilization, options);
|
|
416
463
|
}
|
|
417
464
|
/**
|
|
418
465
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
@@ -200,28 +200,28 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
200
200
|
*/
|
|
201
201
|
getPublicReallocationLiquidity(marketId: MarketId, options?: PublicAllocatorOptions): bigint;
|
|
202
202
|
/**
|
|
203
|
-
* Computes the liquidity available to bring `marketId` to `
|
|
203
|
+
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
204
204
|
* counting the public-allocator liquidity reallocatable into it.
|
|
205
205
|
*
|
|
206
206
|
* Returns the max borrow `x` keeping post-borrow utilization
|
|
207
|
-
* `(borrow + x) / (supply + L) ≤
|
|
207
|
+
* `(borrow + x) / (supply + L) ≤ utilization`, where `L` is the
|
|
208
208
|
* reallocatable liquidity added to the market's supply — equivalently
|
|
209
|
-
* `getBorrowToUtilization({ supply + L, borrow },
|
|
210
|
-
*
|
|
209
|
+
* `getBorrowToUtilization({ supply + L, borrow }, utilization)`. Below
|
|
210
|
+
* `utilization` this is the market's own borrow headroom plus `utilization · L`;
|
|
211
211
|
* reallocated supply also raises the supply denominator, so only that scaled
|
|
212
212
|
* share backs further borrow.
|
|
213
213
|
*
|
|
214
214
|
* Read-only metric — never throws on insufficiency:
|
|
215
215
|
* - returns only the market's own borrow headroom when
|
|
216
|
-
* `supplyTargetUtilization >
|
|
217
|
-
* trigger at that
|
|
218
|
-
* - returns `0n` when the market is already at or above
|
|
219
|
-
* too small to bring it back under.
|
|
216
|
+
* `supplyTargetUtilization > utilization` (reallocation would not
|
|
217
|
+
* trigger at that utilization);
|
|
218
|
+
* - returns `0n` when the market is already at or above `utilization` and `L`
|
|
219
|
+
* is too small to bring it back under.
|
|
220
220
|
*
|
|
221
221
|
* @param marketId - Target market to borrow from.
|
|
222
|
-
* @param
|
|
222
|
+
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
223
223
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
224
|
-
* @returns Available liquidity to the
|
|
224
|
+
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
225
225
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
226
226
|
* @example
|
|
227
227
|
* ```ts
|
|
@@ -245,6 +245,50 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
245
245
|
*
|
|
246
246
|
* // Max borrow keeping utilization at or below 90%, counting shared liquidity.
|
|
247
247
|
* const available: bigint =
|
|
248
|
+
* reallocationData.getAvailableLiquidityToUtilization(
|
|
249
|
+
* marketParams.id,
|
|
250
|
+
* parseEther("0.9"),
|
|
251
|
+
* { timestamp: block.timestamp },
|
|
252
|
+
* );
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
getAvailableLiquidityToUtilization(marketId: MarketId, utilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
256
|
+
/**
|
|
257
|
+
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
258
|
+
* counting the public-allocator liquidity reallocatable into it.
|
|
259
|
+
*
|
|
260
|
+
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
261
|
+
* `target` wording wrongly implied a market's configured supply-target
|
|
262
|
+
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
263
|
+
* Delegates to the new method; will be removed in the next major.
|
|
264
|
+
*
|
|
265
|
+
* @param marketId - Target market to borrow from.
|
|
266
|
+
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
267
|
+
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
268
|
+
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
269
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* import { createPublicClient, http, parseEther } from "viem";
|
|
273
|
+
* import { mainnet } from "viem/chains";
|
|
274
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
275
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
276
|
+
*
|
|
277
|
+
* const client = createPublicClient({
|
|
278
|
+
* chain: mainnet,
|
|
279
|
+
* transport: http(),
|
|
280
|
+
* }).extend(morphoViemExtension());
|
|
281
|
+
*
|
|
282
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
283
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
284
|
+
* const block = await client.getBlock();
|
|
285
|
+
* const reallocationData = await market.getReallocationData({
|
|
286
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
287
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
291
|
+
* const available: bigint =
|
|
248
292
|
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
249
293
|
* marketParams.id,
|
|
250
294
|
* parseEther("0.9"),
|
|
@@ -345,28 +345,28 @@ export class ReallocationData {
|
|
|
345
345
|
return withdrawals.reduce((total, { assets }) => total + assets, 0n);
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
348
|
-
* Computes the liquidity available to bring `marketId` to `
|
|
348
|
+
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
349
349
|
* counting the public-allocator liquidity reallocatable into it.
|
|
350
350
|
*
|
|
351
351
|
* Returns the max borrow `x` keeping post-borrow utilization
|
|
352
|
-
* `(borrow + x) / (supply + L) ≤
|
|
352
|
+
* `(borrow + x) / (supply + L) ≤ utilization`, where `L` is the
|
|
353
353
|
* reallocatable liquidity added to the market's supply — equivalently
|
|
354
|
-
* `getBorrowToUtilization({ supply + L, borrow },
|
|
355
|
-
*
|
|
354
|
+
* `getBorrowToUtilization({ supply + L, borrow }, utilization)`. Below
|
|
355
|
+
* `utilization` this is the market's own borrow headroom plus `utilization · L`;
|
|
356
356
|
* reallocated supply also raises the supply denominator, so only that scaled
|
|
357
357
|
* share backs further borrow.
|
|
358
358
|
*
|
|
359
359
|
* Read-only metric — never throws on insufficiency:
|
|
360
360
|
* - returns only the market's own borrow headroom when
|
|
361
|
-
* `supplyTargetUtilization >
|
|
362
|
-
* trigger at that
|
|
363
|
-
* - returns `0n` when the market is already at or above
|
|
364
|
-
* too small to bring it back under.
|
|
361
|
+
* `supplyTargetUtilization > utilization` (reallocation would not
|
|
362
|
+
* trigger at that utilization);
|
|
363
|
+
* - returns `0n` when the market is already at or above `utilization` and `L`
|
|
364
|
+
* is too small to bring it back under.
|
|
365
365
|
*
|
|
366
366
|
* @param marketId - Target market to borrow from.
|
|
367
|
-
* @param
|
|
367
|
+
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
368
368
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
369
|
-
* @returns Available liquidity to the
|
|
369
|
+
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
370
370
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
371
371
|
* @example
|
|
372
372
|
* ```ts
|
|
@@ -390,26 +390,73 @@ export class ReallocationData {
|
|
|
390
390
|
*
|
|
391
391
|
* // Max borrow keeping utilization at or below 90%, counting shared liquidity.
|
|
392
392
|
* const available: bigint =
|
|
393
|
-
* reallocationData.
|
|
393
|
+
* reallocationData.getAvailableLiquidityToUtilization(
|
|
394
394
|
* marketParams.id,
|
|
395
395
|
* parseEther("0.9"),
|
|
396
396
|
* { timestamp: block.timestamp },
|
|
397
397
|
* );
|
|
398
398
|
* ```
|
|
399
399
|
*/
|
|
400
|
-
// biome-ignore lint/complexity/useMaxParams: (marketId,
|
|
401
|
-
|
|
400
|
+
// biome-ignore lint/complexity/useMaxParams: (marketId, utilization, options) is the metric's public API
|
|
401
|
+
getAvailableLiquidityToUtilization(marketId, utilization = DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
402
402
|
const market = this.getMarket(marketId).accrueInterest(options?.timestamp);
|
|
403
403
|
// Below the allocator's trigger, no reallocation happens: own headroom only.
|
|
404
404
|
const supplyTargetUtilization = getSupplyTargetUtilization(marketId, options);
|
|
405
|
-
if (supplyTargetUtilization >
|
|
406
|
-
return market.getBorrowToUtilization(
|
|
405
|
+
if (supplyTargetUtilization > utilization)
|
|
406
|
+
return market.getBorrowToUtilization(utilization);
|
|
407
407
|
// Borrow-to-target on the post-reallocation supply; clamps to 0n above target.
|
|
408
408
|
const availableLiquidity = this.getPublicReallocationLiquidity(marketId, options);
|
|
409
409
|
return MarketUtils.getBorrowToUtilization({
|
|
410
410
|
totalSupplyAssets: market.totalSupplyAssets + availableLiquidity,
|
|
411
411
|
totalBorrowAssets: market.totalBorrowAssets,
|
|
412
|
-
},
|
|
412
|
+
}, utilization);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
416
|
+
* counting the public-allocator liquidity reallocatable into it.
|
|
417
|
+
*
|
|
418
|
+
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
419
|
+
* `target` wording wrongly implied a market's configured supply-target
|
|
420
|
+
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
421
|
+
* Delegates to the new method; will be removed in the next major.
|
|
422
|
+
*
|
|
423
|
+
* @param marketId - Target market to borrow from.
|
|
424
|
+
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
425
|
+
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
426
|
+
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
427
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
428
|
+
* @example
|
|
429
|
+
* ```ts
|
|
430
|
+
* import { createPublicClient, http, parseEther } from "viem";
|
|
431
|
+
* import { mainnet } from "viem/chains";
|
|
432
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
433
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
434
|
+
*
|
|
435
|
+
* const client = createPublicClient({
|
|
436
|
+
* chain: mainnet,
|
|
437
|
+
* transport: http(),
|
|
438
|
+
* }).extend(morphoViemExtension());
|
|
439
|
+
*
|
|
440
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
441
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
442
|
+
* const block = await client.getBlock();
|
|
443
|
+
* const reallocationData = await market.getReallocationData({
|
|
444
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
445
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
446
|
+
* });
|
|
447
|
+
*
|
|
448
|
+
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
449
|
+
* const available: bigint =
|
|
450
|
+
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
451
|
+
* marketParams.id,
|
|
452
|
+
* parseEther("0.9"),
|
|
453
|
+
* { timestamp: block.timestamp },
|
|
454
|
+
* );
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
// biome-ignore lint/complexity/useMaxParams: (marketId, targetUtilization, options) is the metric's public API
|
|
458
|
+
getAvailableLiquidityToTargetUtilization(marketId, targetUtilization = DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
459
|
+
return this.getAvailableLiquidityToUtilization(marketId, targetUtilization, options);
|
|
413
460
|
}
|
|
414
461
|
/**
|
|
415
462
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
package/package.json
CHANGED