@morpho-org/morpho-sdk 9.1.0 → 9.3.0-next.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.
Files changed (112) hide show
  1. package/README.md +5 -1
  2. package/lib/cjs/abis.d.ts +2 -2
  3. package/lib/cjs/abis.js +7 -1
  4. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  5. package/lib/cjs/actions/midnight/index.js +1 -0
  6. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +50 -0
  7. package/lib/cjs/actions/midnight/withdrawCollateral.js +105 -0
  8. package/lib/cjs/blue/abis.d.ts +1 -1
  9. package/lib/cjs/blue/abis.js +5 -1
  10. package/lib/cjs/blue/constants.d.ts +1 -1
  11. package/lib/cjs/blue/constants.js +2 -1
  12. package/lib/cjs/blue/entities.d.ts +4 -4
  13. package/lib/cjs/blue/entities.js +3 -1
  14. package/lib/cjs/blue/errors.d.ts +2 -2
  15. package/lib/cjs/blue/errors.js +5 -1
  16. package/lib/cjs/blue/fetch.d.ts +2 -2
  17. package/lib/cjs/blue/fetch.js +3 -1
  18. package/lib/cjs/blue/utils.d.ts +1 -1
  19. package/lib/cjs/blue/utils.js +2 -1
  20. package/lib/cjs/constants.d.ts +2 -2
  21. package/lib/cjs/constants.js +4 -1
  22. package/lib/cjs/entities/blue/blue.d.ts +71 -16
  23. package/lib/cjs/entities/blue/blue.js +32 -4
  24. package/lib/cjs/entities/index.d.ts +5 -5
  25. package/lib/cjs/entities/index.js +3 -1
  26. package/lib/cjs/entities/midnight/midnight.d.ts +58 -11
  27. package/lib/cjs/entities/midnight/midnight.js +103 -11
  28. package/lib/cjs/entities/midnight/publication.d.ts +2 -1
  29. package/lib/cjs/entities/midnight/publication.js +44 -64
  30. package/lib/cjs/entities/midnight/types.d.ts +8 -0
  31. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +8 -0
  32. package/lib/cjs/entities/vaultV1/vaultV1.js +5 -0
  33. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +37 -9
  34. package/lib/cjs/entities/vaultV2/vaultV2.js +36 -1
  35. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +42 -7
  36. package/lib/cjs/entities/vaultV2BlueReallocationData.js +206 -35
  37. package/lib/cjs/errors.d.ts +4 -4
  38. package/lib/cjs/errors.js +10 -5
  39. package/lib/cjs/fetch.d.ts +2 -2
  40. package/lib/cjs/fetch.js +3 -1
  41. package/lib/cjs/helpers/constant.d.ts +7 -0
  42. package/lib/cjs/helpers/constant.js +8 -1
  43. package/lib/cjs/helpers/deadShares.d.ts +82 -0
  44. package/lib/cjs/helpers/deadShares.js +202 -0
  45. package/lib/cjs/helpers/index.d.ts +2 -1
  46. package/lib/cjs/helpers/index.js +7 -1
  47. package/lib/cjs/midnight/abis.d.ts +1 -1
  48. package/lib/cjs/midnight/abis.js +3 -1
  49. package/lib/cjs/midnight/errors.d.ts +2 -1
  50. package/lib/cjs/midnight/errors.js +5 -4
  51. package/lib/cjs/types/action.d.ts +10 -1
  52. package/lib/cjs/types/error.d.ts +54 -5
  53. package/lib/cjs/types/error.js +60 -6
  54. package/lib/cjs/types/sharedLiquidity.d.ts +10 -6
  55. package/lib/cjs/utils.d.ts +2 -2
  56. package/lib/cjs/utils.js +4 -2
  57. package/lib/esm/abis.d.ts +2 -2
  58. package/lib/esm/abis.js +2 -2
  59. package/lib/esm/actions/midnight/index.d.ts +1 -0
  60. package/lib/esm/actions/midnight/index.js +1 -0
  61. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +50 -0
  62. package/lib/esm/actions/midnight/withdrawCollateral.js +101 -0
  63. package/lib/esm/blue/abis.d.ts +1 -1
  64. package/lib/esm/blue/abis.js +1 -1
  65. package/lib/esm/blue/constants.d.ts +1 -1
  66. package/lib/esm/blue/constants.js +1 -1
  67. package/lib/esm/blue/entities.d.ts +4 -4
  68. package/lib/esm/blue/entities.js +2 -2
  69. package/lib/esm/blue/errors.d.ts +2 -2
  70. package/lib/esm/blue/errors.js +2 -2
  71. package/lib/esm/blue/fetch.d.ts +2 -2
  72. package/lib/esm/blue/fetch.js +2 -2
  73. package/lib/esm/blue/utils.d.ts +1 -1
  74. package/lib/esm/blue/utils.js +1 -1
  75. package/lib/esm/constants.d.ts +2 -2
  76. package/lib/esm/constants.js +2 -2
  77. package/lib/esm/entities/blue/blue.d.ts +71 -16
  78. package/lib/esm/entities/blue/blue.js +34 -6
  79. package/lib/esm/entities/index.d.ts +5 -5
  80. package/lib/esm/entities/index.js +2 -2
  81. package/lib/esm/entities/midnight/midnight.d.ts +58 -11
  82. package/lib/esm/entities/midnight/midnight.js +105 -13
  83. package/lib/esm/entities/midnight/publication.d.ts +2 -1
  84. package/lib/esm/entities/midnight/publication.js +45 -65
  85. package/lib/esm/entities/midnight/types.d.ts +8 -0
  86. package/lib/esm/entities/vaultV1/vaultV1.d.ts +8 -0
  87. package/lib/esm/entities/vaultV1/vaultV1.js +5 -0
  88. package/lib/esm/entities/vaultV2/vaultV2.d.ts +37 -9
  89. package/lib/esm/entities/vaultV2/vaultV2.js +36 -1
  90. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +42 -7
  91. package/lib/esm/entities/vaultV2BlueReallocationData.js +206 -35
  92. package/lib/esm/errors.d.ts +4 -4
  93. package/lib/esm/errors.js +4 -4
  94. package/lib/esm/fetch.d.ts +2 -2
  95. package/lib/esm/fetch.js +2 -2
  96. package/lib/esm/helpers/constant.d.ts +7 -0
  97. package/lib/esm/helpers/constant.js +7 -0
  98. package/lib/esm/helpers/deadShares.d.ts +82 -0
  99. package/lib/esm/helpers/deadShares.js +197 -0
  100. package/lib/esm/helpers/index.d.ts +2 -1
  101. package/lib/esm/helpers/index.js +2 -1
  102. package/lib/esm/midnight/abis.d.ts +1 -1
  103. package/lib/esm/midnight/abis.js +1 -1
  104. package/lib/esm/midnight/errors.d.ts +2 -1
  105. package/lib/esm/midnight/errors.js +2 -1
  106. package/lib/esm/types/action.d.ts +10 -1
  107. package/lib/esm/types/error.d.ts +54 -5
  108. package/lib/esm/types/error.js +57 -5
  109. package/lib/esm/types/sharedLiquidity.d.ts +10 -6
  110. package/lib/esm/utils.d.ts +2 -2
  111. package/lib/esm/utils.js +2 -2
  112. package/package.json +9 -8
package/lib/cjs/fetch.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchMidnightRatifierInfo = exports.fetchMidnightPosition = exports.fetchMidnightMarketParams = exports.fetchMidnightMarket = exports.fetchMidnightAccrualPosition = exports.fetchVaultV2MorphoVaultV1Adapter = exports.fetchVaultV2MorphoMarketV1AdapterV2 = exports.fetchVaultV2MorphoMarketV1Adapter = exports.fetchVaultV2BluePublicAllocatorData = exports.fetchVaultV2BluePublicAllocatorConfig = exports.fetchVaultV2BlueMarketPublicAllocatorConfig = exports.fetchVaultV2Adapter = exports.fetchVaultV2 = exports.fetchVaultUser = exports.fetchVaultMarketConfig = exports.fetchVaultMarketAllocation = exports.fetchVaultConfig = exports.fetchVault = exports.fetchBlueUser = exports.fetchToken = exports.fetchBluePreLiquidationPosition = exports.fetchBluePreLiquidationParams = exports.fetchBluePosition = exports.fetchBlueMarketParams = exports.fetchBlueMarket = exports.fetchHolding = exports.fetchAccrualVaultV2MorphoVaultV1Adapter = exports.fetchAccrualVaultV2MorphoMarketV1AdapterV2 = exports.fetchAccrualVaultV2MorphoMarketV1Adapter = exports.fetchAccrualVaultV2Adapter = exports.fetchAccrualVaultV2 = exports.fetchAccrualVault = exports.fetchBlueAccrualPosition = void 0;
3
+ exports.fetchMidnightRatifierInfo = exports.fetchMidnightPosition = exports.fetchMidnightMarketParams = exports.fetchMidnightMarket = exports.fetchMidnightAccrualPosition = exports.fetchVaultV2MorphoVaultV1Adapter = exports.fetchVaultV2MorphoMarketV1AdapterV2 = exports.fetchVaultV2MorphoMarketV1Adapter = exports.fetchVaultV2MidnightAdapter = exports.fetchVaultV2BluePublicAllocatorData = exports.fetchVaultV2BluePublicAllocatorConfig = exports.fetchVaultV2BlueMarketPublicAllocatorConfig = exports.fetchVaultV2Adapter = exports.fetchVaultV2 = exports.fetchVaultUser = exports.fetchVaultMarketConfig = exports.fetchVaultMarketAllocation = exports.fetchVaultConfig = exports.fetchVault = exports.fetchBlueUser = exports.fetchToken = exports.fetchBluePreLiquidationPosition = exports.fetchBluePreLiquidationParams = exports.fetchBluePosition = exports.fetchBlueMarketParams = exports.fetchBlueMarket = exports.fetchHolding = exports.fetchAccrualVaultV2MorphoVaultV1Adapter = exports.fetchAccrualVaultV2MorphoMarketV1AdapterV2 = exports.fetchAccrualVaultV2MorphoMarketV1Adapter = exports.fetchAccrualVaultV2MidnightAdapter = exports.fetchAccrualVaultV2Adapter = exports.fetchAccrualVaultV2 = exports.fetchAccrualVault = exports.fetchBlueAccrualPosition = void 0;
4
4
  var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  Object.defineProperty(exports, "fetchBlueAccrualPosition", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualPosition; } });
6
6
  Object.defineProperty(exports, "fetchAccrualVault", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVault; } });
7
7
  Object.defineProperty(exports, "fetchAccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2; } });
8
8
  Object.defineProperty(exports, "fetchAccrualVaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2Adapter; } });
9
+ Object.defineProperty(exports, "fetchAccrualVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MidnightAdapter; } });
9
10
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1Adapter; } });
10
11
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1AdapterV2; } });
11
12
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoVaultV1Adapter; } });
@@ -29,6 +30,7 @@ Object.defineProperty(exports, "fetchVaultV2Adapter", { enumerable: true, get: f
29
30
  Object.defineProperty(exports, "fetchVaultV2BlueMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BlueMarketPublicAllocatorConfig; } });
30
31
  Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorConfig; } });
31
32
  Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorData", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorData; } });
33
+ Object.defineProperty(exports, "fetchVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MidnightAdapter; } });
32
34
  Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1Adapter; } });
33
35
  Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1AdapterV2; } });
34
36
  Object.defineProperty(exports, "fetchVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoVaultV1Adapter; } });
@@ -30,6 +30,13 @@ export declare const DEFAULT_CAP_ACCRUAL_BUFFER: bigint;
30
30
  * `VaultV2BluePublicAllocatorOptions.allocatorCapHeadroom`.
31
31
  */
32
32
  export declare const DEFAULT_ALLOCATOR_CAP_HEADROOM: bigint;
33
+ /**
34
+ * Minimum shares a Morpho Blue market, Vault V1 or Vault V2 must hold at `DEAD_ADDRESS` to count as
35
+ * protected against share-price inflation (1e9, Protocol team rule).
36
+ */
37
+ export declare const MIN_DEAD_SHARES = 1000000000n;
38
+ /** Minimum assets, in the vault asset's smallest unit, a Vault V2's dead shares must be worth (1e6). */
39
+ export declare const MIN_VAULT_V2_DEAD_ASSETS = 1000000n;
33
40
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
34
41
  export declare const MAX_ABSOLUTE_SHARE_PRICE: bigint;
35
42
  /**
@@ -1,6 +1,6 @@
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_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 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.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
@@ -35,6 +35,13 @@ exports.DEFAULT_CAP_ACCRUAL_BUFFER = morpho_ts_1.Time.s.from.h(2n);
35
35
  * `VaultV2BluePublicAllocatorOptions.allocatorCapHeadroom`.
36
36
  */
37
37
  exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = blue_sdk_1.MathLib.WAD / 100n;
38
+ /**
39
+ * Minimum shares a Morpho Blue market, Vault V1 or Vault V2 must hold at `DEAD_ADDRESS` to count as
40
+ * protected against share-price inflation (1e9, Protocol team rule).
41
+ */
42
+ exports.MIN_DEAD_SHARES = 1000000000n;
43
+ /** Minimum assets, in the vault asset's smallest unit, a Vault V2's dead shares must be worth (1e6). */
44
+ exports.MIN_VAULT_V2_DEAD_ASSETS = 1000000n;
38
45
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
39
46
  exports.MAX_ABSOLUTE_SHARE_PRICE = 100n * blue_sdk_1.MathLib.RAY;
40
47
  /**
@@ -0,0 +1,82 @@
1
+ import { type AccrualVault, type AccrualVaultV2, type IMarket } from "@morpho-org/blue-sdk";
2
+ import type { Address, Hash } from "viem";
3
+ type DeadSharesPath = readonly (Address | Hash)[];
4
+ /**
5
+ * Checks that a Morpho Blue market holds at least `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
6
+ *
7
+ * @param market - Fetched market snapshot.
8
+ * @param path - Vaults leading to this market, outermost first; empty for a direct market.
9
+ * @returns Nothing; returns normally when the market passes.
10
+ * @throws {MissingDeadSharesDataError} when `market.deadSupplyShares` was not fetched.
11
+ * @throws {InsufficientDeadSharesError} when the market holds fewer than `MIN_DEAD_SHARES` dead supply shares.
12
+ * @example
13
+ * ```ts
14
+ * import { validateBlueMarketDeadShares } from "@morpho-org/morpho-sdk";
15
+ * import { fetchBlueMarket } from "@morpho-org/morpho-sdk/fetch";
16
+ * import { markets } from "@morpho-org/morpho-test";
17
+ * import { createPublicClient, http } from "viem";
18
+ * import { mainnet } from "viem/chains";
19
+ *
20
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
21
+ * const market = await fetchBlueMarket(markets[mainnet.id].usdc_wbtc.id, client);
22
+ * validateBlueMarketDeadShares(market);
23
+ * // Returns void on success; throws if the snapshot fails the rule.
24
+ * ```
25
+ */
26
+ export declare function validateBlueMarketDeadShares(market: Pick<IMarket, "params" | "deadSupplyShares"> & {
27
+ readonly id: Hash;
28
+ }, path?: DeadSharesPath): void;
29
+ /**
30
+ * Checks that a Vault V1 holds at least `MIN_DEAD_SHARES` shares at `DEAD_ADDRESS` and that every
31
+ * market in its withdraw queue passes `validateBlueMarketDeadShares`.
32
+ *
33
+ * @param vault - Fetched vault snapshot with its withdraw-queue allocations.
34
+ * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
35
+ * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
36
+ * @throws {MissingDeadSharesDataError} when `vault.deadShares`, a withdraw-queue allocation or a
37
+ * market's `deadSupplyShares` was not fetched.
38
+ * @throws {InsufficientDeadSharesError} when the vault or one of its withdraw-queue markets holds
39
+ * too few dead shares.
40
+ * @example
41
+ * ```ts
42
+ * import { validateVaultV1DeadShares } from "@morpho-org/morpho-sdk";
43
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
44
+ * import { vaults } from "@morpho-org/morpho-test";
45
+ * import { createPublicClient, http } from "viem";
46
+ * import { mainnet } from "viem/chains";
47
+ *
48
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
49
+ * const vault = await fetchAccrualVault(vaults[mainnet.id].steakUsdc.address, client);
50
+ * validateVaultV1DeadShares(vault);
51
+ * // Returns void on success; throws if the snapshot fails the rule.
52
+ * ```
53
+ */
54
+ export declare function validateVaultV1DeadShares(vault: AccrualVault, path?: DeadSharesPath): void;
55
+ /**
56
+ * Checks a Vault V2 against the dead-deposit rule: at least `MIN_DEAD_SHARES` shares at
57
+ * `DEAD_ADDRESS` worth at least `MIN_VAULT_V2_DEAD_ASSETS` assets, a share price above
58
+ * `1 / (10 * virtualShares)`, and every Blue market or Vault V1 it can allocate to (non-zero
59
+ * absolute cap) passing its own rule. Zero-cap entries are skipped.
60
+ *
61
+ * @param vault - Fetched vault snapshot with its adapters and `absoluteCaps`.
62
+ * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
63
+ * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
64
+ * @throws {MissingDeadSharesDataError} when a dead-share field, an adapter cap, or the data of an
65
+ * adapter the SDK cannot hydrate is missing.
66
+ * @throws {InsufficientDeadSharesError} when the vault or an allocatable market or Vault V1 fails the rule.
67
+ * @example
68
+ * ```ts
69
+ * import { validateVaultV2DeadShares } from "@morpho-org/morpho-sdk";
70
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
71
+ * import { createPublicClient, http } from "viem";
72
+ * import { mainnet } from "viem/chains";
73
+ *
74
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
75
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
76
+ * const vault = await fetchAccrualVaultV2(keyrockUsdcVaultV2, client);
77
+ * validateVaultV2DeadShares(vault);
78
+ * // Returns void on success; throws if the snapshot fails the rule.
79
+ * ```
80
+ */
81
+ export declare function validateVaultV2DeadShares(vault: AccrualVaultV2, path?: DeadSharesPath): void;
82
+ export {};
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateBlueMarketDeadShares = validateBlueMarketDeadShares;
4
+ exports.validateVaultV1DeadShares = validateVaultV1DeadShares;
5
+ exports.validateVaultV2DeadShares = validateVaultV2DeadShares;
6
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
7
+ const error_js_1 = require("../types/error.js");
8
+ const constant_js_1 = require("./constant.js");
9
+ /**
10
+ * Checks that a Morpho Blue market holds at least `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
11
+ *
12
+ * @param market - Fetched market snapshot.
13
+ * @param path - Vaults leading to this market, outermost first; empty for a direct market.
14
+ * @returns Nothing; returns normally when the market passes.
15
+ * @throws {MissingDeadSharesDataError} when `market.deadSupplyShares` was not fetched.
16
+ * @throws {InsufficientDeadSharesError} when the market holds fewer than `MIN_DEAD_SHARES` dead supply shares.
17
+ * @example
18
+ * ```ts
19
+ * import { validateBlueMarketDeadShares } from "@morpho-org/morpho-sdk";
20
+ * import { fetchBlueMarket } from "@morpho-org/morpho-sdk/fetch";
21
+ * import { markets } from "@morpho-org/morpho-test";
22
+ * import { createPublicClient, http } from "viem";
23
+ * import { mainnet } from "viem/chains";
24
+ *
25
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
26
+ * const market = await fetchBlueMarket(markets[mainnet.id].usdc_wbtc.id, client);
27
+ * validateBlueMarketDeadShares(market);
28
+ * // Returns void on success; throws if the snapshot fails the rule.
29
+ * ```
30
+ */
31
+ function validateBlueMarketDeadShares(market, path = []) {
32
+ const entity = [...path, market.id];
33
+ if (market.deadSupplyShares == null)
34
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadSupplyShares" });
35
+ if (market.deadSupplyShares < constant_js_1.MIN_DEAD_SHARES)
36
+ throw new error_js_1.InsufficientDeadSharesError({
37
+ entity,
38
+ reason: "deadShares",
39
+ observed: market.deadSupplyShares,
40
+ required: constant_js_1.MIN_DEAD_SHARES,
41
+ });
42
+ }
43
+ /**
44
+ * Checks that a Vault V1 holds at least `MIN_DEAD_SHARES` shares at `DEAD_ADDRESS` and that every
45
+ * market in its withdraw queue passes `validateBlueMarketDeadShares`.
46
+ *
47
+ * @param vault - Fetched vault snapshot with its withdraw-queue allocations.
48
+ * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
49
+ * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
50
+ * @throws {MissingDeadSharesDataError} when `vault.deadShares`, a withdraw-queue allocation or a
51
+ * market's `deadSupplyShares` was not fetched.
52
+ * @throws {InsufficientDeadSharesError} when the vault or one of its withdraw-queue markets holds
53
+ * too few dead shares.
54
+ * @example
55
+ * ```ts
56
+ * import { validateVaultV1DeadShares } from "@morpho-org/morpho-sdk";
57
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
58
+ * import { vaults } from "@morpho-org/morpho-test";
59
+ * import { createPublicClient, http } from "viem";
60
+ * import { mainnet } from "viem/chains";
61
+ *
62
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
63
+ * const vault = await fetchAccrualVault(vaults[mainnet.id].steakUsdc.address, client);
64
+ * validateVaultV1DeadShares(vault);
65
+ * // Returns void on success; throws if the snapshot fails the rule.
66
+ * ```
67
+ */
68
+ function validateVaultV1DeadShares(vault, path = []) {
69
+ const entity = [...path, vault.address];
70
+ if (vault.deadShares == null)
71
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadShares" });
72
+ if (vault.deadShares < constant_js_1.MIN_DEAD_SHARES)
73
+ throw new error_js_1.InsufficientDeadSharesError({
74
+ entity,
75
+ reason: "deadShares",
76
+ observed: vault.deadShares,
77
+ required: constant_js_1.MIN_DEAD_SHARES,
78
+ });
79
+ for (const marketId of vault.withdrawQueue) {
80
+ const allocation = vault.allocations.get(marketId);
81
+ if (allocation == null)
82
+ throw new error_js_1.MissingDeadSharesDataError({
83
+ entity: [...entity, marketId],
84
+ field: "allocation",
85
+ });
86
+ validateBlueMarketDeadShares(allocation.position.market, entity);
87
+ }
88
+ }
89
+ /**
90
+ * Checks a Vault V2 against the dead-deposit rule: at least `MIN_DEAD_SHARES` shares at
91
+ * `DEAD_ADDRESS` worth at least `MIN_VAULT_V2_DEAD_ASSETS` assets, a share price above
92
+ * `1 / (10 * virtualShares)`, and every Blue market or Vault V1 it can allocate to (non-zero
93
+ * absolute cap) passing its own rule. Zero-cap entries are skipped.
94
+ *
95
+ * @param vault - Fetched vault snapshot with its adapters and `absoluteCaps`.
96
+ * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
97
+ * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
98
+ * @throws {MissingDeadSharesDataError} when a dead-share field, an adapter cap, or the data of an
99
+ * adapter the SDK cannot hydrate is missing.
100
+ * @throws {InsufficientDeadSharesError} when the vault or an allocatable market or Vault V1 fails the rule.
101
+ * @example
102
+ * ```ts
103
+ * import { validateVaultV2DeadShares } from "@morpho-org/morpho-sdk";
104
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
105
+ * import { createPublicClient, http } from "viem";
106
+ * import { mainnet } from "viem/chains";
107
+ *
108
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
109
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
110
+ * const vault = await fetchAccrualVaultV2(keyrockUsdcVaultV2, client);
111
+ * validateVaultV2DeadShares(vault);
112
+ * // Returns void on success; throws if the snapshot fails the rule.
113
+ * ```
114
+ */
115
+ function validateVaultV2DeadShares(vault, path = []) {
116
+ const entity = [...path, vault.address];
117
+ const { deadShares, deadAssets, absoluteCaps } = vault;
118
+ if (deadShares == null)
119
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadShares" });
120
+ if (deadAssets == null)
121
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadAssets" });
122
+ if (absoluteCaps == null)
123
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "absoluteCaps" });
124
+ if (deadShares < constant_js_1.MIN_DEAD_SHARES)
125
+ throw new error_js_1.InsufficientDeadSharesError({
126
+ entity,
127
+ reason: "deadShares",
128
+ observed: deadShares,
129
+ required: constant_js_1.MIN_DEAD_SHARES,
130
+ });
131
+ if (deadAssets < constant_js_1.MIN_VAULT_V2_DEAD_ASSETS)
132
+ throw new error_js_1.InsufficientDeadSharesError({
133
+ entity,
134
+ reason: "deadAssets",
135
+ observed: deadAssets,
136
+ required: constant_js_1.MIN_VAULT_V2_DEAD_ASSETS,
137
+ });
138
+ // Share price (totalAssets + 1) / (totalSupply + virtualShares) must exceed 1 / (10 * virtualShares).
139
+ const priceNumerator = (vault._totalAssets + 1n) * 10n * vault.virtualShares;
140
+ const priceDenominator = vault.totalSupply + vault.virtualShares;
141
+ if (priceNumerator <= priceDenominator)
142
+ throw new error_js_1.InsufficientDeadSharesError({
143
+ entity,
144
+ reason: "sharePrice",
145
+ observed: priceNumerator,
146
+ required: priceDenominator + 1n,
147
+ });
148
+ const capOf = (id, adapter) => {
149
+ const cap = absoluteCaps[id];
150
+ if (cap == null)
151
+ throw new error_js_1.MissingDeadSharesDataError({
152
+ entity: [...entity, adapter],
153
+ field: "absoluteCaps",
154
+ });
155
+ return cap;
156
+ };
157
+ for (const adapter of vault.accrualAdapters) {
158
+ if (adapter instanceof blue_sdk_1.AccrualVaultV2MidnightAdapter)
159
+ continue;
160
+ if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter) {
161
+ const id = blue_sdk_1.VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
162
+ if (capOf(id, adapter.address) > 0n)
163
+ validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
164
+ }
165
+ else if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter) {
166
+ for (const { market } of adapter.positions) {
167
+ const id = blue_sdk_1.VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
168
+ if (capOf(id, adapter.address) > 0n)
169
+ validateBlueMarketDeadShares(market, entity);
170
+ }
171
+ }
172
+ else if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2) {
173
+ for (const market of adapter.markets) {
174
+ const id = blue_sdk_1.VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
175
+ if (capOf(id, adapter.address) > 0n)
176
+ validateBlueMarketDeadShares(market, entity);
177
+ }
178
+ }
179
+ else {
180
+ throw new error_js_1.MissingDeadSharesDataError({
181
+ entity: [...entity, adapter.address],
182
+ field: "adapter",
183
+ });
184
+ }
185
+ }
186
+ // Deposits are allocated to the liquidity market, so the snapshot must hold it even when it
187
+ // has no allocation yet (the adapters only list markets they currently supply to).
188
+ const liquidityAdapter = vault.accrualLiquidityAdapter;
189
+ if (vault.liquidityData === "0x" ||
190
+ !(liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter ||
191
+ liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2))
192
+ return;
193
+ const liquidityMarketId = blue_sdk_1.MarketParams.fromHex(vault.liquidityData).id;
194
+ const markets = liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter
195
+ ? liquidityAdapter.positions.map(({ market }) => market)
196
+ : liquidityAdapter.markets;
197
+ if (!markets.some(({ id }) => id === liquidityMarketId))
198
+ throw new error_js_1.MissingDeadSharesDataError({
199
+ entity: [...entity, liquidityAdapter.address, liquidityMarketId],
200
+ field: "liquidityMarket",
201
+ });
202
+ }
@@ -1,5 +1,6 @@
1
1
  export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, 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, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./constant.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, 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, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./constant.js";
3
+ export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
3
4
  export { addTransactionMetadata } from "./metadata.js";
4
5
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
5
6
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 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.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
3
+ exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateVaultV2DeadShares = exports.validateVaultV1DeadShares = exports.validateBlueMarketDeadShares = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 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.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
4
4
  var callback_js_1 = require("./callback.js");
5
5
  Object.defineProperty(exports, "getMidnightBlueBuyCallbackAddress", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackAddress; } });
6
6
  Object.defineProperty(exports, "getMidnightBlueBuyCallbackData", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackData; } });
@@ -17,6 +17,12 @@ Object.defineProperty(exports, "MAX_REALLOCATION_PENALTY", { enumerable: true, g
17
17
  Object.defineProperty(exports, "MAX_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return constant_js_1.MAX_SLIPPAGE_TOLERANCE; } });
18
18
  Object.defineProperty(exports, "MAX_TOKEN_APPROVALS", { enumerable: true, get: function () { return constant_js_1.MAX_TOKEN_APPROVALS; } });
19
19
  Object.defineProperty(exports, "MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS", { enumerable: true, get: function () { return constant_js_1.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS; } });
20
+ Object.defineProperty(exports, "MIN_DEAD_SHARES", { enumerable: true, get: function () { return constant_js_1.MIN_DEAD_SHARES; } });
21
+ Object.defineProperty(exports, "MIN_VAULT_V2_DEAD_ASSETS", { enumerable: true, get: function () { return constant_js_1.MIN_VAULT_V2_DEAD_ASSETS; } });
22
+ var deadShares_js_1 = require("./deadShares.js");
23
+ Object.defineProperty(exports, "validateBlueMarketDeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateBlueMarketDeadShares; } });
24
+ Object.defineProperty(exports, "validateVaultV1DeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateVaultV1DeadShares; } });
25
+ Object.defineProperty(exports, "validateVaultV2DeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateVaultV2DeadShares; } });
20
26
  var metadata_js_1 = require("./metadata.js");
21
27
  Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return metadata_js_1.addTransactionMetadata; } });
22
28
  var previewVaultV2ForceWithdraw_js_1 = require("./previewVaultV2ForceWithdraw.js");
@@ -1 +1 @@
1
- export { blueBuyCallbackFactoryAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
1
+ export { blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setterRatifierAbi = exports.rateRatifierV1Abi = exports.priceRatifierV1Abi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.blueBuyCallbackFactoryAbi = void 0;
3
+ exports.setterRatifierAbi = exports.rateRatifierV1Abi = exports.priceRatifierV1Abi = exports.midnightEventsAbi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.ecrecoverAuthorizerAbi = exports.blueBuyCallbackFactoryAbi = void 0;
4
4
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  Object.defineProperty(exports, "blueBuyCallbackFactoryAbi", { enumerable: true, get: function () { return midnight_sdk_1.blueBuyCallbackFactoryAbi; } });
6
+ Object.defineProperty(exports, "ecrecoverAuthorizerAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverAuthorizerAbi; } });
6
7
  Object.defineProperty(exports, "ecrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
7
8
  Object.defineProperty(exports, "midnightAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightAbi; } });
8
9
  Object.defineProperty(exports, "midnightBundlesV2Abi", { enumerable: true, get: function () { return midnight_sdk_1.midnightBundlesV2Abi; } });
10
+ Object.defineProperty(exports, "midnightEventsAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightEventsAbi; } });
9
11
  Object.defineProperty(exports, "priceRatifierV1Abi", { enumerable: true, get: function () { return midnight_sdk_1.priceRatifierV1Abi; } });
10
12
  Object.defineProperty(exports, "rateRatifierV1Abi", { enumerable: true, get: function () { return midnight_sdk_1.rateRatifierV1Abi; } });
11
13
  Object.defineProperty(exports, "setterRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.setterRatifierAbi; } });
@@ -1 +1,2 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
+ export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.ChainIdMismatchError = void 0;
3
+ exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.ChainIdMismatchError = void 0;
4
4
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  Object.defineProperty(exports, "ChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
6
6
  Object.defineProperty(exports, "InvalidEcrecoverSignatureVError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureVError; } });
@@ -9,9 +9,6 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
9
9
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
10
10
  Object.defineProperty(exports, "InvalidOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
11
11
  Object.defineProperty(exports, "InvalidOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
12
- Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
13
- Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
14
- Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
15
12
  Object.defineProperty(exports, "InvalidRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
16
13
  Object.defineProperty(exports, "InvalidRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
17
14
  Object.defineProperty(exports, "InvalidRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -29,3 +26,7 @@ Object.defineProperty(exports, "RatifierV1TakerNotAllowedError", { enumerable: t
29
26
  Object.defineProperty(exports, "SettlementFeeExceedsPriceError", { enumerable: true, get: function () { return midnight_sdk_1.SettlementFeeExceedsPriceError; } });
30
27
  Object.defineProperty(exports, "TickOutOfRangeError", { enumerable: true, get: function () { return midnight_sdk_1.TickOutOfRangeError; } });
31
28
  Object.defineProperty(exports, "UnknownCollateralIndexError", { enumerable: true, get: function () { return midnight_sdk_1.UnknownCollateralIndexError; } });
29
+ var morpho_ts_1 = require("@morpho-org/morpho-ts");
30
+ Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
31
+ Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
32
+ Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
@@ -435,6 +435,15 @@ export interface MidnightSupplyCollateralAction extends BaseAction<"midnightSupp
435
435
  readonly onBehalf: Address;
436
436
  }> {
437
437
  }
438
+ /** Metadata for a direct Midnight collateral withdrawal transaction. */
439
+ export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWithdrawCollateral", {
440
+ readonly market: Hex;
441
+ readonly collateralIndex: bigint;
442
+ readonly assets: bigint;
443
+ readonly onBehalf: Address;
444
+ readonly receiver: Address;
445
+ }> {
446
+ }
438
447
  /** Metadata for a direct Midnight credit redemption transaction. */
439
448
  export interface MidnightRedeemAction extends BaseAction<"midnightRedeem", {
440
449
  readonly market: Hex;
@@ -501,7 +510,7 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
501
510
  * VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
502
511
  * consumers can `switch` exhaustively on it.
503
512
  */
504
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
513
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
505
514
  /**
506
515
  * Describes a single, immutable, deep-frozen transaction to submit on-chain:
507
516
  * the target `to`, native `value`, encoded call `data`, and the originating
@@ -929,11 +929,16 @@ export declare class RepaySharesExceedDebtError extends Error {
929
929
  });
930
930
  }
931
931
  /**
932
- * Thrown when shared liquidity selected by a Vault V2 reallocation planner cannot
933
- * cover the operation's absolute shortfall on the target market — the resulting
934
- * `morphoBorrow` or `morphoWithdraw` would still revert onchain.
932
+ * Thrown when shared liquidity cannot cover the operation's required
933
+ * reallocated assets. When Blue's balance is explicit, it is also thrown if
934
+ * that balance cannot fund the penalty flash loan, an earlier market-sourced
935
+ * withdrawal, or the final operation transfer. A borrow or withdraw plan that
936
+ * otherwise covers its shortfall but whose planned penalty exceeds its amount
937
+ * instead throws `InputExceedsMaxError`.
935
938
  *
936
- * Pattern-match on the class and inspect `params` to surface the gap to users.
939
+ * `shortfall` is the reallocated assets required by the operation and is
940
+ * comparable to `available`. Pattern-match on the class and inspect `params`
941
+ * to surface the gap to users.
937
942
  */
938
943
  export declare class InsufficientSharedLiquidityError extends Error {
939
944
  readonly params: {
@@ -1316,7 +1321,12 @@ export declare class MidnightOfferCallbackDataMismatchError extends Error {
1316
1321
  readonly actualCallbackData: Hex;
1317
1322
  });
1318
1323
  }
1319
- /** Thrown when loan assets would be parked in a Morpho Blue market with no existing supply. */
1324
+ /**
1325
+ * Thrown when loan assets would be parked in a Morpho Blue market with no existing supply.
1326
+ *
1327
+ * @deprecated `supplyBlueMakeLend` now throws `InsufficientDeadSharesError` or
1328
+ * `MissingDeadSharesDataError` instead; kept exported so existing `instanceof` checks compile.
1329
+ */
1320
1330
  export declare class EmptyBlueParkingMarketError extends Error {
1321
1331
  constructor(params: {
1322
1332
  readonly marketId: MarketId;
@@ -1332,6 +1342,45 @@ export declare class ZeroBlueParkingSharesError extends Error {
1332
1342
  readonly assets: bigint;
1333
1343
  });
1334
1344
  }
1345
+ /** Which dead-deposit condition an entity failed. */
1346
+ export type DeadSharesFailureReason = "deadShares" | "deadAssets" | "sharePrice";
1347
+ /**
1348
+ * Thrown when a Morpho Blue market or vault, or a market or Vault V1 it can allocate to, fails the
1349
+ * dead-deposit rule that protects deposits against share-price inflation.
1350
+ */
1351
+ export declare class InsufficientDeadSharesError extends Error {
1352
+ /** Failing entity, outermost vault first; the last element is the market id or vault address. */
1353
+ readonly entity: readonly (Address | Hash)[];
1354
+ /** Failed condition. */
1355
+ readonly reason: DeadSharesFailureReason;
1356
+ /** Observed dead shares or assets; for `sharePrice`, `(totalAssets + 1) * 10 * virtualShares`. */
1357
+ readonly observed: bigint;
1358
+ /** Required minimum; for `sharePrice`, `totalSupply + virtualShares + 1`. */
1359
+ readonly required: bigint;
1360
+ constructor(params: {
1361
+ readonly entity: readonly (Address | Hash)[];
1362
+ readonly reason: DeadSharesFailureReason;
1363
+ readonly observed: bigint;
1364
+ readonly required: bigint;
1365
+ });
1366
+ }
1367
+ /** Snapshot field the dead-deposit check needs but the snapshot does not carry. */
1368
+ export type DeadSharesDataField = "deadSupplyShares" | "deadShares" | "deadAssets" | "absoluteCaps" | "allocation" | "adapter" | "liquidityMarket";
1369
+ /**
1370
+ * Thrown when a market or vault snapshot lacks the data the dead-deposit check needs, such as a
1371
+ * snapshot built by hand, from the Morpho API or by an older fetcher, or a Vault V2 adapter the
1372
+ * SDK cannot hydrate. The check fails closed rather than pass unverified data.
1373
+ */
1374
+ export declare class MissingDeadSharesDataError extends Error {
1375
+ /** Entity missing the data, outermost vault first. */
1376
+ readonly entity: readonly (Address | Hash)[];
1377
+ /** Missing field. */
1378
+ readonly field: DeadSharesDataField;
1379
+ constructor(params: {
1380
+ readonly entity: readonly (Address | Hash)[];
1381
+ readonly field: DeadSharesDataField;
1382
+ });
1383
+ }
1335
1384
  /** Thrown when a quoted Midnight takeable offer belongs to a different market than the requested flow. */
1336
1385
  export declare class MidnightTakeableOfferMarketMismatchError extends Error {
1337
1386
  constructor(params: {