@morpho-org/morpho-sdk 6.2.0 → 6.3.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.
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/entities/blue/blue.d.ts +14 -2
- package/lib/cjs/entities/blue/blue.js +7 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +34 -9
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +167 -47
- package/lib/cjs/helpers/constant.d.ts +8 -0
- package/lib/cjs/helpers/constant.js +10 -1
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/utilization.d.ts +13 -0
- package/lib/cjs/helpers/utilization.js +19 -1
- package/lib/cjs/types/sharedLiquidity.d.ts +19 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +14 -2
- package/lib/esm/entities/blue/blue.js +7 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +34 -9
- package/lib/esm/entities/vaultV2BlueReallocationData.js +168 -48
- package/lib/esm/helpers/constant.d.ts +8 -0
- package/lib/esm/helpers/constant.js +9 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/utilization.d.ts +13 -0
- package/lib/esm/helpers/utilization.js +18 -1
- package/lib/esm/types/sharedLiquidity.d.ts +19 -1
- package/package.json +1 -1
package/lib/cjs/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType, } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, MAX_TREE_HEIGHT as MIDNIGHT_MAX_TREE_HEIGHT, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, RATE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
|
|
3
3
|
export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
|
|
4
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
|
4
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.ZERO_ADDRESS = exports.REWARDS_BASE_URL = exports.MORPHO_DOMAIN = exports.DOCS_BASE_URL = exports.ChainUtils = exports.ChainId = exports.BLUE_API_GRAPHQL_URL = exports.BLUE_API_BASE_URL = exports.MIDNIGHT_TIME_TO_MAX_LIF = exports.MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS = exports.MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_PRICE_ROUNDING_STEP = exports.MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_OFFER_TYPEHASH = exports.MIDNIGHT_MAX_TREE_HEIGHT = exports.MIDNIGHT_MAX_TICK = exports.MIDNIGHT_MAX_SETTLEMENT_FEES = exports.MIDNIGHT_MAX_OFFER_CAP = exports.MIDNIGHT_MAX_CONTINUOUS_FEE = exports.MIDNIGHT_MAX_COLLATERALS_PER_BORROWER = exports.MIDNIGHT_MAX_COLLATERALS = exports.MIDNIGHT_MARKET_TYPEHASH = exports.MIDNIGHT_EIP712_DOMAIN_TYPEHASH = exports.MIDNIGHT_DEFAULT_TICK_SPACING = exports.MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH = exports.MIDNIGHT_CBP = exports.BlueTransactionType = exports.SECONDS_PER_YEAR = exports.ORACLE_PRICE_SCALE = exports.BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.BLUE_LIQUIDATION_CURSOR = exports.isBlueMarketId = exports.ERC20_ALLOWANCE_RECIPIENTS = exports.EIP_712_FIELDS = exports.DEFAULT_SLIPPAGE_TOLERANCE = void 0;
|
|
3
|
+
exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.ZERO_ADDRESS = exports.REWARDS_BASE_URL = exports.MORPHO_DOMAIN = exports.DOCS_BASE_URL = exports.ChainUtils = exports.ChainId = exports.BLUE_API_GRAPHQL_URL = exports.BLUE_API_BASE_URL = exports.MIDNIGHT_TIME_TO_MAX_LIF = exports.MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS = exports.MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_PRICE_ROUNDING_STEP = exports.MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_OFFER_TYPEHASH = exports.MIDNIGHT_MAX_TREE_HEIGHT = exports.MIDNIGHT_MAX_TICK = exports.MIDNIGHT_MAX_SETTLEMENT_FEES = exports.MIDNIGHT_MAX_OFFER_CAP = exports.MIDNIGHT_MAX_CONTINUOUS_FEE = exports.MIDNIGHT_MAX_COLLATERALS_PER_BORROWER = exports.MIDNIGHT_MAX_COLLATERALS = exports.MIDNIGHT_MARKET_TYPEHASH = exports.MIDNIGHT_EIP712_DOMAIN_TYPEHASH = exports.MIDNIGHT_DEFAULT_TICK_SPACING = exports.MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH = exports.MIDNIGHT_CBP = exports.BlueTransactionType = exports.SECONDS_PER_YEAR = exports.ORACLE_PRICE_SCALE = exports.BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.BLUE_LIQUIDATION_CURSOR = exports.isBlueMarketId = exports.ERC20_ALLOWANCE_RECIPIENTS = exports.EIP_712_FIELDS = exports.DEFAULT_SLIPPAGE_TOLERANCE = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
Object.defineProperty(exports, "DEFAULT_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE; } });
|
|
6
6
|
Object.defineProperty(exports, "EIP_712_FIELDS", { enumerable: true, get: function () { return blue_sdk_1.EIP_712_FIELDS; } });
|
|
@@ -41,6 +41,7 @@ Object.defineProperty(exports, "REWARDS_BASE_URL", { enumerable: true, get: func
|
|
|
41
41
|
Object.defineProperty(exports, "ZERO_ADDRESS", { enumerable: true, get: function () { return morpho_ts_1.ZERO_ADDRESS; } });
|
|
42
42
|
var constant_js_1 = require("./helpers/constant.js");
|
|
43
43
|
Object.defineProperty(exports, "APPROVE_ONLY_ONCE_TOKENS", { enumerable: true, get: function () { return constant_js_1.APPROVE_ONLY_ONCE_TOKENS; } });
|
|
44
|
+
Object.defineProperty(exports, "DEFAULT_CAP_ACCRUAL_BUFFER", { enumerable: true, get: function () { return constant_js_1.DEFAULT_CAP_ACCRUAL_BUFFER; } });
|
|
44
45
|
Object.defineProperty(exports, "DEFAULT_LLTV_BUFFER", { enumerable: true, get: function () { return constant_js_1.DEFAULT_LLTV_BUFFER; } });
|
|
45
46
|
Object.defineProperty(exports, "DEFAULT_MAX_REALLOCATION_PENALTY", { enumerable: true, get: function () { return constant_js_1.DEFAULT_MAX_REALLOCATION_PENALTY; } });
|
|
46
47
|
Object.defineProperty(exports, "DEFAULT_SUPPLY_TARGET_UTILIZATION", { enumerable: true, get: function () { return constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION; } });
|
|
@@ -814,13 +814,19 @@ export interface BlueActions {
|
|
|
814
814
|
}) => Promise<VaultV2BlueReallocationData>;
|
|
815
815
|
/**
|
|
816
816
|
* Computes Vault V2 BluePublicAllocator reallocations for this market.
|
|
817
|
+
* Market/vault state and returned post-state stay at `options.timestamp`;
|
|
818
|
+
* only target-market cap checks reserve interest on the vault's existing
|
|
819
|
+
* allocation through `timestamp + capAccrualBuffer` (two hours by default;
|
|
820
|
+
* `0n` disables it). For market-source reallocations the source position's
|
|
821
|
+
* interest is also reserved on cap ids shared with the target, and reserves
|
|
822
|
+
* persist across every leg of a plan.
|
|
817
823
|
*
|
|
818
824
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
819
825
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
820
826
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
821
827
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
822
828
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
823
|
-
* @throws {NegativeInputError} when
|
|
829
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
|
|
824
830
|
* @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
|
|
825
831
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
826
832
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -1026,13 +1032,19 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1026
1032
|
}): Promise<VaultV2BlueReallocationData>;
|
|
1027
1033
|
/**
|
|
1028
1034
|
* Computes Vault V2 BluePublicAllocator reallocations for this market.
|
|
1035
|
+
* Market/vault state and returned post-state stay at `options.timestamp`;
|
|
1036
|
+
* only target-market cap checks reserve interest on the vault's existing
|
|
1037
|
+
* allocation through `timestamp + capAccrualBuffer` (two hours by default;
|
|
1038
|
+
* `0n` disables it). For market-source reallocations the source position's
|
|
1039
|
+
* interest is also reserved on cap ids shared with the target, and reserves
|
|
1040
|
+
* persist across every leg of a plan.
|
|
1029
1041
|
*
|
|
1030
1042
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
1031
1043
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
1032
1044
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
1033
1045
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
1034
1046
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
1035
|
-
* @throws {NegativeInputError} when
|
|
1047
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
|
|
1036
1048
|
* @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
|
|
1037
1049
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
1038
1050
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -733,13 +733,19 @@ class MorphoBlue {
|
|
|
733
733
|
}
|
|
734
734
|
/**
|
|
735
735
|
* Computes Vault V2 BluePublicAllocator reallocations for this market.
|
|
736
|
+
* Market/vault state and returned post-state stay at `options.timestamp`;
|
|
737
|
+
* only target-market cap checks reserve interest on the vault's existing
|
|
738
|
+
* allocation through `timestamp + capAccrualBuffer` (two hours by default;
|
|
739
|
+
* `0n` disables it). For market-source reallocations the source position's
|
|
740
|
+
* interest is also reserved on cap ids shared with the target, and reserves
|
|
741
|
+
* persist across every leg of a plan.
|
|
736
742
|
*
|
|
737
743
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
738
744
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
739
745
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
740
746
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
741
747
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
742
|
-
* @throws {NegativeInputError} when
|
|
748
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
|
|
743
749
|
* @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
|
|
744
750
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
745
751
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -363,9 +363,15 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
363
363
|
* utilization defaults to 90% and is configurable through
|
|
364
364
|
* `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
|
|
365
365
|
* `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
|
|
366
|
-
* considered.
|
|
367
|
-
*
|
|
368
|
-
*
|
|
366
|
+
* considered. Market/vault state and the returned post-state stay at
|
|
367
|
+
* `timestamp`; only target-market cap checks reserve interest the vault's
|
|
368
|
+
* existing allocation would accrue through `timestamp + capAccrualBuffer`
|
|
369
|
+
* (two hours by default; `0n` disables it). For market-source reallocations
|
|
370
|
+
* the source position's interest is also reserved on cap ids shared with the
|
|
371
|
+
* target, and reserves persist across every leg of a plan. Targets with no remaining supply
|
|
372
|
+
* or allocator capacity are skipped before projecting source interest. The
|
|
373
|
+
* adapter's minimum share minting requirement, supply-share limits, and target
|
|
374
|
+
* absolute or zero relative caps are checked against a one-asset deposit.
|
|
369
375
|
* Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
|
|
370
376
|
* allocation does not increase after rounding.
|
|
371
377
|
*
|
|
@@ -377,9 +383,15 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
377
383
|
*
|
|
378
384
|
* @param marketId - Target Blue market id.
|
|
379
385
|
* @param options - Optional discovery controls and operation to support.
|
|
386
|
+
* Market/vault state and returned post-state stay at `timestamp`; only
|
|
387
|
+
* target-market cap checks reserve interest on the vault's existing allocation
|
|
388
|
+
* through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
|
|
389
|
+
* For market-source reallocations the source position's interest is also
|
|
390
|
+
* reserved on cap ids shared with the target, and reserves persist across
|
|
391
|
+
* every leg of a plan.
|
|
380
392
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
381
393
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
382
|
-
* @throws {NegativeInputError} when `maxWithdrawalUtilization
|
|
394
|
+
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
383
395
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
384
396
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
385
397
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -431,12 +443,19 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
431
443
|
private computeVaultV2BlueReallocationsAtUtilizationInPlace;
|
|
432
444
|
/**
|
|
433
445
|
* Sums friendly Vault V2 shared liquidity available to a target market.
|
|
446
|
+
* Market/vault state and returned post-state stay at `timestamp`; only
|
|
447
|
+
* target-market cap checks reserve interest on the vault's existing allocation
|
|
448
|
+
* through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
|
|
449
|
+
* For market-source reallocations the source position's interest is also
|
|
450
|
+
* reserved on cap ids shared with the target, and reserves persist across
|
|
451
|
+
* every leg of a plan.
|
|
434
452
|
*
|
|
435
453
|
* @param marketId - Target Blue market id.
|
|
436
|
-
* @param options - Optional timestamp, enable flag, vault
|
|
454
|
+
* @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
|
|
455
|
+
* allowlist, source utilization ceiling, and maximum penalty.
|
|
437
456
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
438
457
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
439
|
-
* @throws {NegativeInputError} when `maxWithdrawalUtilization
|
|
458
|
+
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
440
459
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
441
460
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
442
461
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -470,14 +489,20 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
470
489
|
getPublicReallocationLiquidity(marketId: MarketId, options?: VaultV2BluePublicAllocatorOptions): bigint;
|
|
471
490
|
/**
|
|
472
491
|
* Computes borrow liquidity to a target utilization, including friendly
|
|
473
|
-
* Vault V2 public reallocations.
|
|
492
|
+
* Vault V2 public reallocations. Market/vault state and returned post-state
|
|
493
|
+
* stay at `timestamp`; only target-market cap checks reserve interest on the
|
|
494
|
+
* vault's existing allocation through `timestamp + capAccrualBuffer` (two
|
|
495
|
+
* hours by default; `0n` disables). For market-source reallocations the
|
|
496
|
+
* source position's interest is also reserved on cap ids shared with the
|
|
497
|
+
* target, and reserves persist across every leg of a plan.
|
|
474
498
|
*
|
|
475
499
|
* @param marketId - Target Blue market id.
|
|
476
500
|
* @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
|
|
477
|
-
* @param options - Optional timestamp, enable flag, vault
|
|
501
|
+
* @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
|
|
502
|
+
* allowlist, source utilization ceiling, and maximum penalty.
|
|
478
503
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
479
504
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
480
|
-
* @throws {NegativeInputError} when `maxWithdrawalUtilization
|
|
505
|
+
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
481
506
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
482
507
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
483
508
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -8,6 +8,12 @@ const constant_js_1 = require("../helpers/constant.js");
|
|
|
8
8
|
const utilization_js_1 = require("../helpers/utilization.js");
|
|
9
9
|
const index_js_1 = require("../types/index.js");
|
|
10
10
|
const MAX_SHARED_CAP_SEARCH_STEPS = 1024n;
|
|
11
|
+
const createCapReserveState = (markets) => ({
|
|
12
|
+
initialMarkets: { ...markets },
|
|
13
|
+
marketAccruals: new Map(),
|
|
14
|
+
touchedPairs: new Map(),
|
|
15
|
+
reserveByPairKey: new Map(),
|
|
16
|
+
});
|
|
11
17
|
/** Creates isolated transaction-scoped state for one simulation. @internal */
|
|
12
18
|
const createSimulationContext = () => ({
|
|
13
19
|
donatedPenaltyAssets: {},
|
|
@@ -558,9 +564,15 @@ class VaultV2BlueReallocationData {
|
|
|
558
564
|
* utilization defaults to 90% and is configurable through
|
|
559
565
|
* `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
|
|
560
566
|
* `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
|
|
561
|
-
* considered.
|
|
562
|
-
*
|
|
563
|
-
*
|
|
567
|
+
* considered. Market/vault state and the returned post-state stay at
|
|
568
|
+
* `timestamp`; only target-market cap checks reserve interest the vault's
|
|
569
|
+
* existing allocation would accrue through `timestamp + capAccrualBuffer`
|
|
570
|
+
* (two hours by default; `0n` disables it). For market-source reallocations
|
|
571
|
+
* the source position's interest is also reserved on cap ids shared with the
|
|
572
|
+
* target, and reserves persist across every leg of a plan. Targets with no remaining supply
|
|
573
|
+
* or allocator capacity are skipped before projecting source interest. The
|
|
574
|
+
* adapter's minimum share minting requirement, supply-share limits, and target
|
|
575
|
+
* absolute or zero relative caps are checked against a one-asset deposit.
|
|
564
576
|
* Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
|
|
565
577
|
* allocation does not increase after rounding.
|
|
566
578
|
*
|
|
@@ -572,9 +584,15 @@ class VaultV2BlueReallocationData {
|
|
|
572
584
|
*
|
|
573
585
|
* @param marketId - Target Blue market id.
|
|
574
586
|
* @param options - Optional discovery controls and operation to support.
|
|
587
|
+
* Market/vault state and returned post-state stay at `timestamp`; only
|
|
588
|
+
* target-market cap checks reserve interest on the vault's existing allocation
|
|
589
|
+
* through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
|
|
590
|
+
* For market-source reallocations the source position's interest is also
|
|
591
|
+
* reserved on cap ids shared with the target, and reserves persist across
|
|
592
|
+
* every leg of a plan.
|
|
575
593
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
576
594
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
577
|
-
* @throws {NegativeInputError} when `maxWithdrawalUtilization
|
|
595
|
+
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
578
596
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
579
597
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
580
598
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -619,13 +637,16 @@ class VaultV2BlueReallocationData {
|
|
|
619
637
|
return { reallocations: [], data: this };
|
|
620
638
|
const maxWithdrawalUtilization = (0, utilization_js_1.resolveMaxWithdrawalUtilization)(options.maxWithdrawalUtilization);
|
|
621
639
|
const maxPenalty = resolveMaxPenalty(options.maxPenalty);
|
|
640
|
+
const capAccrualBuffer = (0, utilization_js_1.resolveCapAccrualBuffer)(options.capAccrualBuffer);
|
|
622
641
|
const resolvedOptions = { ...options, maxPenalty };
|
|
623
642
|
const operation = options.operation;
|
|
624
643
|
if (operation == null) {
|
|
625
644
|
const { reallocations, data } = this.clone().computeVaultV2BlueReallocationsAtUtilizationInPlace({
|
|
626
645
|
context: createSimulationContext(),
|
|
646
|
+
reserves: createCapReserveState(this.mutableMarkets),
|
|
627
647
|
marketId,
|
|
628
648
|
maxWithdrawalUtilization,
|
|
649
|
+
capAccrualBuffer,
|
|
629
650
|
options: resolvedOptions,
|
|
630
651
|
});
|
|
631
652
|
return { reallocations, data };
|
|
@@ -666,11 +687,14 @@ class VaultV2BlueReallocationData {
|
|
|
666
687
|
newTotalSupplyAssets;
|
|
667
688
|
if (requiredAssets <= 0n)
|
|
668
689
|
return { reallocations: [], data: this };
|
|
690
|
+
const reserves = createCapReserveState(this.mutableMarkets);
|
|
669
691
|
const friendly = this.clone().computeVaultV2BlueReallocationsAtUtilizationInPlace({
|
|
670
692
|
context: createSimulationContext(),
|
|
693
|
+
reserves,
|
|
671
694
|
marketId,
|
|
672
695
|
maxWithdrawalUtilization,
|
|
673
696
|
maxAssets: requiredAssets,
|
|
697
|
+
capAccrualBuffer,
|
|
674
698
|
options: normalizedOptions,
|
|
675
699
|
});
|
|
676
700
|
const reallocations = [...friendly.reallocations];
|
|
@@ -685,9 +709,11 @@ class VaultV2BlueReallocationData {
|
|
|
685
709
|
if (friendlyBorrow > friendlySupply) {
|
|
686
710
|
const fallback = data.computeVaultV2BlueReallocationsAtUtilizationInPlace({
|
|
687
711
|
context: friendly.context,
|
|
712
|
+
reserves,
|
|
688
713
|
marketId,
|
|
689
714
|
maxWithdrawalUtilization: blue_sdk_1.MathLib.WAD,
|
|
690
715
|
maxAssets: friendlyBorrow - friendlySupply,
|
|
716
|
+
capAccrualBuffer,
|
|
691
717
|
options: normalizedOptions,
|
|
692
718
|
});
|
|
693
719
|
reallocations.push(...fallback.reallocations);
|
|
@@ -705,7 +731,7 @@ class VaultV2BlueReallocationData {
|
|
|
705
731
|
}
|
|
706
732
|
return { reallocations, data };
|
|
707
733
|
}
|
|
708
|
-
computeVaultV2BlueReallocationsAtUtilizationInPlace({ context, marketId, maxWithdrawalUtilization, maxAssets, options = {}, }) {
|
|
734
|
+
computeVaultV2BlueReallocationsAtUtilizationInPlace({ context, reserves, marketId, maxWithdrawalUtilization, maxAssets, capAccrualBuffer, options = {}, }) {
|
|
709
735
|
if (options.enabled === false)
|
|
710
736
|
return { reallocations: [], data: this, context };
|
|
711
737
|
this.getMarket(marketId);
|
|
@@ -725,6 +751,56 @@ class VaultV2BlueReallocationData {
|
|
|
725
751
|
const adapterIdsCache = new Map();
|
|
726
752
|
const activeAdaptersCache = new Map();
|
|
727
753
|
let remainingAssets = maxAssets;
|
|
754
|
+
// Onchain, market interest is booked once at transaction start, on pre-plan
|
|
755
|
+
// positions at pre-plan rates, and stays on touched positions' cap ids.
|
|
756
|
+
// This reserve state is shared across every planner pass and leg of the plan.
|
|
757
|
+
// biome-ignore lint/complexity/useMaxParams: a pair is identified by its vault, adapter, and market.
|
|
758
|
+
const getPair = (vault, adapter, market) => {
|
|
759
|
+
const key = `${vault}:${adapter.address}:${market.id}`.toLowerCase();
|
|
760
|
+
const touched = reserves.touchedPairs.get(vault.toLowerCase())?.get(key);
|
|
761
|
+
if (touched != null)
|
|
762
|
+
return touched;
|
|
763
|
+
const shares = adapter.supplyShares[market.id] ?? 0n;
|
|
764
|
+
return {
|
|
765
|
+
key,
|
|
766
|
+
ids: getAdapterIds(adapterIdsCache, adapter, market),
|
|
767
|
+
reserve: () => {
|
|
768
|
+
let reserve = reserves.reserveByPairKey.get(key);
|
|
769
|
+
if (reserve == null) {
|
|
770
|
+
let accruals = reserves.marketAccruals.get(market.id);
|
|
771
|
+
if (accruals == null) {
|
|
772
|
+
const initialMarket = reserves.initialMarkets[market.id];
|
|
773
|
+
if (initialMarket == null)
|
|
774
|
+
throw new index_js_1.UnknownReallocationMarketError(market.id);
|
|
775
|
+
accruals = [
|
|
776
|
+
initialMarket.accrueInterest(timestamp),
|
|
777
|
+
initialMarket.accrueInterest(timestamp + capAccrualBuffer),
|
|
778
|
+
];
|
|
779
|
+
reserves.marketAccruals.set(market.id, accruals);
|
|
780
|
+
}
|
|
781
|
+
const [atTimestamp, projected] = accruals;
|
|
782
|
+
reserve = blue_sdk_1.MathLib.zeroFloorSub(projected.toSupplyAssets(shares), atTimestamp.toSupplyAssets(shares));
|
|
783
|
+
reserves.reserveByPairKey.set(key, reserve);
|
|
784
|
+
}
|
|
785
|
+
return reserve;
|
|
786
|
+
},
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
// biome-ignore lint/complexity/useMaxParams: the reserve is scoped to one vault, cap id, and candidate set.
|
|
790
|
+
const capReserve = (vault, id, candidatePairs) => {
|
|
791
|
+
let reserve = 0n;
|
|
792
|
+
const seen = new Set();
|
|
793
|
+
for (const pair of [
|
|
794
|
+
...(reserves.touchedPairs.get(vault.toLowerCase())?.values() ?? []),
|
|
795
|
+
...candidatePairs,
|
|
796
|
+
]) {
|
|
797
|
+
if (seen.has(pair.key) || !pair.ids.includes(id))
|
|
798
|
+
continue;
|
|
799
|
+
seen.add(pair.key);
|
|
800
|
+
reserve += pair.reserve();
|
|
801
|
+
}
|
|
802
|
+
return reserve;
|
|
803
|
+
};
|
|
728
804
|
while (remainingAssets == null || remainingAssets > 0n) {
|
|
729
805
|
const candidates = vaults
|
|
730
806
|
.map((vaultAddress) => {
|
|
@@ -762,6 +838,7 @@ class VaultV2BlueReallocationData {
|
|
|
762
838
|
if (!(0, viem_1.isAddressEqual)(targetMarket.params.loanToken, vault.asset) ||
|
|
763
839
|
!(0, viem_1.isAddressEqual)(targetMarket.params.irm, adapter.adaptiveCurveIrm))
|
|
764
840
|
continue;
|
|
841
|
+
const targetPair = getPair(vaultAddress, adapter, targetMarket);
|
|
765
842
|
const [adapterCapId, collateralCapId, adapterMarketCapId] = getAdapterIds(adapterIdsCache, adapter, targetMarket);
|
|
766
843
|
const marketPublicAllocatorConfig = data.getMarketPublicAllocatorConfig(vaultAddress, adapterMarketCapId);
|
|
767
844
|
if (!(0, viem_1.isAddressEqual)(marketPublicAllocatorConfig.vault, vaultAddress) ||
|
|
@@ -778,14 +855,19 @@ class VaultV2BlueReallocationData {
|
|
|
778
855
|
];
|
|
779
856
|
if (targetAllocations.some(({ absoluteCap }) => absoluteCap === 0n))
|
|
780
857
|
continue;
|
|
781
|
-
const
|
|
858
|
+
const adapterShares = adapter.supplyShares[marketId] ?? 0n;
|
|
859
|
+
const expectedSupplyAssets = targetMarket.toSupplyAssets(adapterShares);
|
|
782
860
|
const untracked = blue_sdk_1.MathLib.zeroFloorSub(expectedSupplyAssets, adapterMarketCapAllocation.allocation);
|
|
783
|
-
const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation +
|
|
784
|
-
|
|
861
|
+
const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation +
|
|
862
|
+
untracked +
|
|
863
|
+
targetPair.reserve());
|
|
864
|
+
const minimumAllocation = minimumSupply.market.toSupplyAssets(adapterShares + minimumSupply.shares);
|
|
785
865
|
const minimumAllocationChange = minimumAllocation - adapterMarketCapAllocation.allocation;
|
|
786
866
|
const blockedTargetIds = targetAllocations
|
|
787
|
-
.filter(({ allocation, absoluteCap, relativeCap }) => {
|
|
788
|
-
const nextAllocation = allocation +
|
|
867
|
+
.filter(({ allocation, absoluteCap, relativeCap, id }) => {
|
|
868
|
+
const nextAllocation = allocation +
|
|
869
|
+
capReserve(vaultAddress, id, [targetPair]) +
|
|
870
|
+
minimumAllocationChange;
|
|
789
871
|
return (nextAllocation > absoluteCap ||
|
|
790
872
|
(relativeCap === 0n && nextAllocation > 0n));
|
|
791
873
|
})
|
|
@@ -803,11 +885,14 @@ class VaultV2BlueReallocationData {
|
|
|
803
885
|
const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, availableIdleAssets);
|
|
804
886
|
if (assets > 0n) {
|
|
805
887
|
rawCandidates.push({
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
888
|
+
reallocation: {
|
|
889
|
+
vault: vaultAddress,
|
|
890
|
+
from: { type: "idle" },
|
|
891
|
+
to: { adapter: adapter.address },
|
|
892
|
+
assets,
|
|
893
|
+
penalty: publicAllocatorConfig.penalty,
|
|
894
|
+
},
|
|
895
|
+
targetPair,
|
|
811
896
|
});
|
|
812
897
|
}
|
|
813
898
|
}
|
|
@@ -841,6 +926,7 @@ class VaultV2BlueReallocationData {
|
|
|
841
926
|
// A withdrawal can create target headroom only for shared cap IDs.
|
|
842
927
|
if (blockedTargetIds.some((id) => !sourceIds.includes(id)))
|
|
843
928
|
continue;
|
|
929
|
+
const sourcePair = getPair(vaultAddress, sourceAdapter, sourceMarket);
|
|
844
930
|
const accruedSourceMarket = sourceMarket.accrueInterest(timestamp);
|
|
845
931
|
data.setMarkets([accruedSourceMarket]);
|
|
846
932
|
const expectedSourceSupplyAssets = accruedSourceMarket.toSupplyAssets(sourceSupplyShares);
|
|
@@ -848,32 +934,32 @@ class VaultV2BlueReallocationData {
|
|
|
848
934
|
if (assets <= 0n)
|
|
849
935
|
continue;
|
|
850
936
|
rawCandidates.push({
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
937
|
+
reallocation: {
|
|
938
|
+
vault: vaultAddress,
|
|
939
|
+
from: {
|
|
940
|
+
type: "market",
|
|
941
|
+
adapter: sourceAdapter.address,
|
|
942
|
+
marketParams: sourceMarket.params,
|
|
943
|
+
},
|
|
944
|
+
to: { adapter: adapter.address },
|
|
945
|
+
assets,
|
|
946
|
+
penalty: publicAllocatorConfig.penalty,
|
|
856
947
|
},
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
penalty: publicAllocatorConfig.penalty,
|
|
948
|
+
targetPair,
|
|
949
|
+
sourcePair,
|
|
860
950
|
});
|
|
861
951
|
}
|
|
862
952
|
}
|
|
863
953
|
}
|
|
864
954
|
const capCompatibleCandidates = [];
|
|
865
|
-
for (const reallocation of rawCandidates) {
|
|
955
|
+
for (const { reallocation, targetPair, sourcePair, } of rawCandidates) {
|
|
866
956
|
let lower = 0n;
|
|
867
957
|
let upper = reallocation.assets;
|
|
868
|
-
const
|
|
869
|
-
const
|
|
870
|
-
const
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
const sourceMarket = data.getMarket(reallocation.from.marketParams.id);
|
|
874
|
-
for (const id of getAdapterIds(adapterIdsCache, sourceAdapter, sourceMarket))
|
|
875
|
-
sourceIds.add(id);
|
|
876
|
-
}
|
|
958
|
+
const targetIds = targetPair.ids;
|
|
959
|
+
const sourceIds = new Set(sourcePair?.ids ?? []);
|
|
960
|
+
const reserveById = new Map();
|
|
961
|
+
for (const id of targetIds)
|
|
962
|
+
reserveById.set(id, capReserve(reallocation.vault, id, sourcePair == null ? [targetPair] : [targetPair, sourcePair]));
|
|
877
963
|
const probeReallocation = (assets) => {
|
|
878
964
|
if (targetMarket.totalSupplyShares +
|
|
879
965
|
targetMarket.toSupplyShares(assets, "Down") >
|
|
@@ -897,8 +983,11 @@ class VaultV2BlueReallocationData {
|
|
|
897
983
|
for (const id of targetIds) {
|
|
898
984
|
const allocation = postTransition.data.getAllocation(reallocation.vault, id);
|
|
899
985
|
const capacity = blue_sdk_1.VaultV2Utils.allocationHeadroom({ ...allocation, allocation: 0n }, firstTotalAssets).value;
|
|
986
|
+
// The reserve covers interest accrued before inclusion by every
|
|
987
|
+
// position the plan touched on this cap id, as booked onchain.
|
|
900
988
|
const withinCap = allocation.absoluteCap > 0n &&
|
|
901
|
-
allocation.allocation <=
|
|
989
|
+
allocation.allocation + (reserveById.get(id) ?? 0n) <=
|
|
990
|
+
capacity;
|
|
902
991
|
if (!withinCap) {
|
|
903
992
|
withinAllCaps = false;
|
|
904
993
|
if (!sourceIds.has(id))
|
|
@@ -935,22 +1024,34 @@ class VaultV2BlueReallocationData {
|
|
|
935
1024
|
}
|
|
936
1025
|
if (selectedAssets > 0n && probe?.withinAllCaps === true)
|
|
937
1026
|
capCompatibleCandidates.push({
|
|
938
|
-
...reallocation,
|
|
939
|
-
|
|
1027
|
+
reallocation: { ...reallocation, assets: selectedAssets },
|
|
1028
|
+
targetPair,
|
|
1029
|
+
sourcePair,
|
|
940
1030
|
});
|
|
941
1031
|
}
|
|
942
|
-
return capCompatibleCandidates.sort((0, morpho_ts_1.bigIntComparator)(({
|
|
1032
|
+
return capCompatibleCandidates.sort((0, morpho_ts_1.bigIntComparator)(({ reallocation }) => reallocation.assets, "desc"))[0];
|
|
943
1033
|
})
|
|
944
1034
|
.filter((candidate) => candidate != null)
|
|
945
|
-
.sort((0, morpho_ts_1.bigIntComparator)(({
|
|
1035
|
+
.sort((0, morpho_ts_1.bigIntComparator)(({ reallocation }) => reallocation.assets, "desc"));
|
|
946
1036
|
const largest = candidates[0];
|
|
947
1037
|
if (largest == null)
|
|
948
1038
|
return { reallocations, data, context: simulationContext };
|
|
949
|
-
const reallocation = largest;
|
|
950
|
-
|
|
1039
|
+
const { reallocation: acceptedReallocation, targetPair: acceptedTargetPair, sourcePair: acceptedSourcePair, } = largest;
|
|
1040
|
+
const touchedVaultKey = acceptedReallocation.vault.toLowerCase();
|
|
1041
|
+
let touchedVaultPairs = reserves.touchedPairs.get(touchedVaultKey);
|
|
1042
|
+
if (touchedVaultPairs == null) {
|
|
1043
|
+
touchedVaultPairs = new Map();
|
|
1044
|
+
reserves.touchedPairs.set(touchedVaultKey, touchedVaultPairs);
|
|
1045
|
+
}
|
|
1046
|
+
if (!touchedVaultPairs.has(acceptedTargetPair.key))
|
|
1047
|
+
touchedVaultPairs.set(acceptedTargetPair.key, acceptedTargetPair);
|
|
1048
|
+
if (acceptedSourcePair != null &&
|
|
1049
|
+
!touchedVaultPairs.has(acceptedSourcePair.key))
|
|
1050
|
+
touchedVaultPairs.set(acceptedSourcePair.key, acceptedSourcePair);
|
|
1051
|
+
reallocations.push(acceptedReallocation);
|
|
951
1052
|
const transition = data.applyPublicReallocation({
|
|
952
1053
|
context: simulationContext,
|
|
953
|
-
reallocation,
|
|
1054
|
+
reallocation: acceptedReallocation,
|
|
954
1055
|
targetMarketId: marketId,
|
|
955
1056
|
timestamp,
|
|
956
1057
|
adapterIdsCache,
|
|
@@ -958,18 +1059,25 @@ class VaultV2BlueReallocationData {
|
|
|
958
1059
|
data = transition.data;
|
|
959
1060
|
simulationContext = transition.context;
|
|
960
1061
|
if (remainingAssets != null)
|
|
961
|
-
remainingAssets -=
|
|
1062
|
+
remainingAssets -= acceptedReallocation.assets;
|
|
962
1063
|
}
|
|
963
1064
|
return { reallocations, data, context: simulationContext };
|
|
964
1065
|
}
|
|
965
1066
|
/**
|
|
966
1067
|
* Sums friendly Vault V2 shared liquidity available to a target market.
|
|
1068
|
+
* Market/vault state and returned post-state stay at `timestamp`; only
|
|
1069
|
+
* target-market cap checks reserve interest on the vault's existing allocation
|
|
1070
|
+
* through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
|
|
1071
|
+
* For market-source reallocations the source position's interest is also
|
|
1072
|
+
* reserved on cap ids shared with the target, and reserves persist across
|
|
1073
|
+
* every leg of a plan.
|
|
967
1074
|
*
|
|
968
1075
|
* @param marketId - Target Blue market id.
|
|
969
|
-
* @param options - Optional timestamp, enable flag, vault
|
|
1076
|
+
* @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
|
|
1077
|
+
* allowlist, source utilization ceiling, and maximum penalty.
|
|
970
1078
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
971
1079
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
972
|
-
* @throws {NegativeInputError} when `maxWithdrawalUtilization
|
|
1080
|
+
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
973
1081
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
974
1082
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
975
1083
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -1003,26 +1111,35 @@ class VaultV2BlueReallocationData {
|
|
|
1003
1111
|
getPublicReallocationLiquidity(marketId, options) {
|
|
1004
1112
|
if (options?.enabled === false)
|
|
1005
1113
|
return 0n;
|
|
1114
|
+
const capAccrualBuffer = (0, utilization_js_1.resolveCapAccrualBuffer)(options?.capAccrualBuffer);
|
|
1006
1115
|
const maxPenalty = resolveMaxPenalty(options?.maxPenalty);
|
|
1007
1116
|
return this.clone()
|
|
1008
1117
|
.computeVaultV2BlueReallocationsAtUtilizationInPlace({
|
|
1009
1118
|
context: createSimulationContext(),
|
|
1119
|
+
reserves: createCapReserveState(this.mutableMarkets),
|
|
1010
1120
|
marketId,
|
|
1011
1121
|
maxWithdrawalUtilization: (0, utilization_js_1.resolveMaxWithdrawalUtilization)(options?.maxWithdrawalUtilization),
|
|
1122
|
+
capAccrualBuffer,
|
|
1012
1123
|
options: { ...options, maxPenalty },
|
|
1013
1124
|
})
|
|
1014
1125
|
.reallocations.reduce((total, { assets }) => total + assets, 0n);
|
|
1015
1126
|
}
|
|
1016
1127
|
/**
|
|
1017
1128
|
* Computes borrow liquidity to a target utilization, including friendly
|
|
1018
|
-
* Vault V2 public reallocations.
|
|
1129
|
+
* Vault V2 public reallocations. Market/vault state and returned post-state
|
|
1130
|
+
* stay at `timestamp`; only target-market cap checks reserve interest on the
|
|
1131
|
+
* vault's existing allocation through `timestamp + capAccrualBuffer` (two
|
|
1132
|
+
* hours by default; `0n` disables). For market-source reallocations the
|
|
1133
|
+
* source position's interest is also reserved on cap ids shared with the
|
|
1134
|
+
* target, and reserves persist across every leg of a plan.
|
|
1019
1135
|
*
|
|
1020
1136
|
* @param marketId - Target Blue market id.
|
|
1021
1137
|
* @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
|
|
1022
|
-
* @param options - Optional timestamp, enable flag, vault
|
|
1138
|
+
* @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
|
|
1139
|
+
* allowlist, source utilization ceiling, and maximum penalty.
|
|
1023
1140
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
1024
1141
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
1025
|
-
* @throws {NegativeInputError} when `maxWithdrawalUtilization
|
|
1142
|
+
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
1026
1143
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
1027
1144
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
1028
1145
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -1056,6 +1173,7 @@ class VaultV2BlueReallocationData {
|
|
|
1056
1173
|
*/
|
|
1057
1174
|
// biome-ignore lint/complexity/useMaxParams: mirrors the existing V1 metric API
|
|
1058
1175
|
getAvailableLiquidityToUtilization(marketId, utilization = constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
1176
|
+
const capAccrualBuffer = (0, utilization_js_1.resolveCapAccrualBuffer)(options?.capAccrualBuffer);
|
|
1059
1177
|
const timestamp = options?.timestamp == null
|
|
1060
1178
|
? this.getLatestSnapshotTimestamp()
|
|
1061
1179
|
: BigInt(options.timestamp);
|
|
@@ -1066,8 +1184,10 @@ class VaultV2BlueReallocationData {
|
|
|
1066
1184
|
const availableLiquidity = this.clone()
|
|
1067
1185
|
.computeVaultV2BlueReallocationsAtUtilizationInPlace({
|
|
1068
1186
|
context: createSimulationContext(),
|
|
1187
|
+
reserves: createCapReserveState(this.mutableMarkets),
|
|
1069
1188
|
marketId,
|
|
1070
1189
|
maxWithdrawalUtilization: (0, utilization_js_1.resolveMaxWithdrawalUtilization)(options?.maxWithdrawalUtilization),
|
|
1190
|
+
capAccrualBuffer,
|
|
1071
1191
|
options: {
|
|
1072
1192
|
...options,
|
|
1073
1193
|
timestamp,
|
|
@@ -7,6 +7,14 @@ export declare const DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
|
|
|
7
7
|
export declare const MAX_REALLOCATION_PENALTY = 1000000000000000000n;
|
|
8
8
|
/** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
|
|
9
9
|
export declare const DEFAULT_LLTV_BUFFER: bigint;
|
|
10
|
+
/**
|
|
11
|
+
* Forward interest-accrual window, in seconds (2 hours), reserved in target-market
|
|
12
|
+
* cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
|
|
13
|
+
* planning reallocations, so a transaction included after the quote block does not
|
|
14
|
+
* revert on a cap check. Override with
|
|
15
|
+
* `VaultV2BluePublicAllocatorOptions.capAccrualBuffer`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_CAP_ACCRUAL_BUFFER: bigint;
|
|
10
18
|
/** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
|
|
11
19
|
export declare const MAX_ABSOLUTE_SHARE_PRICE: bigint;
|
|
12
20
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = void 0;
|
|
3
|
+
exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
6
|
const viem_1 = require("viem");
|
|
6
7
|
/** Maximum slippage tolerance: 10% */
|
|
7
8
|
exports.MAX_SLIPPAGE_TOLERANCE = blue_sdk_1.MathLib.WAD / 10n;
|
|
@@ -11,6 +12,14 @@ exports.DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
|
|
|
11
12
|
exports.MAX_REALLOCATION_PENALTY = blue_sdk_1.MathLib.WAD;
|
|
12
13
|
/** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
|
|
13
14
|
exports.DEFAULT_LLTV_BUFFER = blue_sdk_1.MathLib.WAD / 200n;
|
|
15
|
+
/**
|
|
16
|
+
* Forward interest-accrual window, in seconds (2 hours), reserved in target-market
|
|
17
|
+
* cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
|
|
18
|
+
* planning reallocations, so a transaction included after the quote block does not
|
|
19
|
+
* revert on a cap check. Override with
|
|
20
|
+
* `VaultV2BluePublicAllocatorOptions.capAccrualBuffer`.
|
|
21
|
+
*/
|
|
22
|
+
exports.DEFAULT_CAP_ACCRUAL_BUFFER = morpho_ts_1.Time.s.from.h(2n);
|
|
14
23
|
/** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
|
|
15
24
|
exports.MAX_ABSOLUTE_SHARE_PRICE = 100n * blue_sdk_1.MathLib.RAY;
|
|
16
25
|
/**
|