@morpho-org/morpho-sdk 10.5.0 → 10.6.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 (192) hide show
  1. package/README.md +44 -1
  2. package/lib/cjs/abis.d.ts +794 -1
  3. package/lib/cjs/abis.js +815 -1
  4. package/lib/cjs/actions/blue/close.d.ts +169 -0
  5. package/lib/cjs/actions/blue/close.js +270 -0
  6. package/lib/cjs/actions/blue/common.js +2 -2
  7. package/lib/cjs/actions/blue/delever.d.ts +156 -0
  8. package/lib/cjs/actions/blue/delever.js +223 -0
  9. package/lib/cjs/actions/blue/index.d.ts +3 -0
  10. package/lib/cjs/actions/blue/index.js +3 -0
  11. package/lib/cjs/actions/blue/lever.d.ts +184 -0
  12. package/lib/cjs/actions/blue/lever.js +272 -0
  13. package/lib/cjs/actions/blue/leverageIntent.d.ts +65 -0
  14. package/lib/cjs/actions/blue/leverageIntent.js +103 -0
  15. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  16. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.js +59 -0
  17. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  18. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.js +193 -0
  19. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  20. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.js +66 -0
  21. package/lib/cjs/actions/requirements/blue/index.d.ts +3 -0
  22. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  23. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  24. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  25. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +11 -6
  26. package/lib/cjs/actions/requirements/getRequirementsApproval.js +29 -5
  27. package/lib/cjs/addresses.d.ts +1 -1
  28. package/lib/cjs/addresses.js +6 -1
  29. package/lib/cjs/blue/abis.d.ts +1 -1
  30. package/lib/cjs/blue/abis.js +5 -1
  31. package/lib/cjs/blue/addresses.d.ts +1 -1
  32. package/lib/cjs/blue/addresses.js +6 -1
  33. package/lib/cjs/blue/entities.d.ts +4 -4
  34. package/lib/cjs/blue/entities.js +3 -1
  35. package/lib/cjs/blue/errors.d.ts +2 -2
  36. package/lib/cjs/blue/errors.js +5 -1
  37. package/lib/cjs/blue/fetch.d.ts +2 -2
  38. package/lib/cjs/blue/fetch.js +3 -1
  39. package/lib/cjs/blue/utils.d.ts +1 -1
  40. package/lib/cjs/blue/utils.js +2 -1
  41. package/lib/cjs/constants.d.ts +1 -1
  42. package/lib/cjs/constants.js +6 -2
  43. package/lib/cjs/entities/blue/blue.d.ts +486 -2
  44. package/lib/cjs/entities/blue/blue.js +529 -34
  45. package/lib/cjs/entities/index.d.ts +5 -5
  46. package/lib/cjs/entities/index.js +3 -1
  47. package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
  48. package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +120 -2
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +232 -4
  53. package/lib/cjs/errors.d.ts +4 -4
  54. package/lib/cjs/errors.js +7 -5
  55. package/lib/cjs/fetch.d.ts +2 -2
  56. package/lib/cjs/fetch.js +3 -1
  57. package/lib/cjs/helpers/constant.d.ts +34 -0
  58. package/lib/cjs/helpers/constant.js +35 -1
  59. package/lib/cjs/helpers/deadShares.js +3 -0
  60. package/lib/cjs/helpers/getZeroExLeverageBundle.d.ts +13 -0
  61. package/lib/cjs/helpers/getZeroExLeverageBundle.js +27 -0
  62. package/lib/cjs/helpers/index.d.ts +4 -1
  63. package/lib/cjs/helpers/index.js +28 -1
  64. package/lib/cjs/helpers/leverage/index.d.ts +1 -0
  65. package/lib/cjs/helpers/leverage/index.js +11 -0
  66. package/lib/cjs/helpers/leverage/limits.d.ts +472 -0
  67. package/lib/cjs/helpers/leverage/limits.js +715 -0
  68. package/lib/cjs/helpers/leverage/positionMarket.d.ts +17 -0
  69. package/lib/cjs/helpers/leverage/positionMarket.js +28 -0
  70. package/lib/cjs/helpers/leverage/reallocations.d.ts +159 -0
  71. package/lib/cjs/helpers/leverage/reallocations.js +276 -0
  72. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  73. package/lib/cjs/helpers/validateRequirementSpender.js +4 -0
  74. package/lib/cjs/helpers/zeroExQuote.d.ts +250 -0
  75. package/lib/cjs/helpers/zeroExQuote.js +763 -0
  76. package/lib/cjs/index.d.ts +1 -0
  77. package/lib/cjs/index.js +5 -2
  78. package/lib/cjs/midnight/errors.d.ts +2 -1
  79. package/lib/cjs/midnight/errors.js +5 -4
  80. package/lib/cjs/reads/assertContractCode.d.ts +25 -0
  81. package/lib/cjs/reads/assertContractCode.js +30 -0
  82. package/lib/cjs/reads/fetchZeroExQuote.d.ts +123 -0
  83. package/lib/cjs/reads/fetchZeroExQuote.js +330 -0
  84. package/lib/cjs/types/action.d.ts +130 -1
  85. package/lib/cjs/types/error.d.ts +59 -0
  86. package/lib/cjs/types/error.js +82 -3
  87. package/lib/cjs/types/index.d.ts +2 -0
  88. package/lib/cjs/types/index.js +2 -0
  89. package/lib/cjs/types/leverageError.d.ts +1552 -0
  90. package/lib/cjs/types/leverageError.js +1711 -0
  91. package/lib/cjs/types/zeroEx.d.ts +171 -0
  92. package/lib/cjs/types/zeroEx.js +2 -0
  93. package/lib/cjs/utils.d.ts +2 -2
  94. package/lib/cjs/utils.js +4 -2
  95. package/lib/cjs/version.d.ts +1 -1
  96. package/lib/cjs/version.js +1 -1
  97. package/lib/esm/abis.d.ts +794 -1
  98. package/lib/esm/abis.js +810 -1
  99. package/lib/esm/actions/blue/close.d.ts +169 -0
  100. package/lib/esm/actions/blue/close.js +266 -0
  101. package/lib/esm/actions/blue/common.js +3 -3
  102. package/lib/esm/actions/blue/delever.d.ts +156 -0
  103. package/lib/esm/actions/blue/delever.js +219 -0
  104. package/lib/esm/actions/blue/index.d.ts +3 -0
  105. package/lib/esm/actions/blue/index.js +3 -0
  106. package/lib/esm/actions/blue/lever.d.ts +184 -0
  107. package/lib/esm/actions/blue/lever.js +268 -0
  108. package/lib/esm/actions/blue/leverageIntent.d.ts +65 -0
  109. package/lib/esm/actions/blue/leverageIntent.js +96 -0
  110. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  111. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.js +55 -0
  112. package/lib/esm/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  113. package/lib/esm/actions/requirements/blue/getLeverageRequirements.js +189 -0
  114. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  115. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.js +62 -0
  116. package/lib/esm/actions/requirements/blue/index.d.ts +3 -0
  117. package/lib/esm/actions/requirements/blue/index.js +3 -0
  118. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  119. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  120. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +11 -6
  121. package/lib/esm/actions/requirements/getRequirementsApproval.js +29 -5
  122. package/lib/esm/addresses.d.ts +1 -1
  123. package/lib/esm/addresses.js +1 -1
  124. package/lib/esm/blue/abis.d.ts +1 -1
  125. package/lib/esm/blue/abis.js +1 -1
  126. package/lib/esm/blue/addresses.d.ts +1 -1
  127. package/lib/esm/blue/addresses.js +1 -1
  128. package/lib/esm/blue/entities.d.ts +4 -4
  129. package/lib/esm/blue/entities.js +2 -2
  130. package/lib/esm/blue/errors.d.ts +2 -2
  131. package/lib/esm/blue/errors.js +2 -2
  132. package/lib/esm/blue/fetch.d.ts +2 -2
  133. package/lib/esm/blue/fetch.js +2 -2
  134. package/lib/esm/blue/utils.d.ts +1 -1
  135. package/lib/esm/blue/utils.js +1 -1
  136. package/lib/esm/constants.d.ts +1 -1
  137. package/lib/esm/constants.js +1 -1
  138. package/lib/esm/entities/blue/blue.d.ts +486 -2
  139. package/lib/esm/entities/blue/blue.js +501 -6
  140. package/lib/esm/entities/index.d.ts +5 -5
  141. package/lib/esm/entities/index.js +2 -2
  142. package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
  143. package/lib/esm/entities/requirements/assertContractCode.js +1 -25
  144. package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
  145. package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
  146. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +120 -2
  147. package/lib/esm/entities/vaultV2BlueReallocationData.js +233 -5
  148. package/lib/esm/errors.d.ts +4 -4
  149. package/lib/esm/errors.js +4 -4
  150. package/lib/esm/fetch.d.ts +2 -2
  151. package/lib/esm/fetch.js +2 -2
  152. package/lib/esm/helpers/constant.d.ts +34 -0
  153. package/lib/esm/helpers/constant.js +34 -0
  154. package/lib/esm/helpers/deadShares.js +4 -1
  155. package/lib/esm/helpers/getZeroExLeverageBundle.d.ts +13 -0
  156. package/lib/esm/helpers/getZeroExLeverageBundle.js +23 -0
  157. package/lib/esm/helpers/index.d.ts +4 -1
  158. package/lib/esm/helpers/index.js +4 -1
  159. package/lib/esm/helpers/leverage/index.d.ts +1 -0
  160. package/lib/esm/helpers/leverage/index.js +1 -0
  161. package/lib/esm/helpers/leverage/limits.d.ts +472 -0
  162. package/lib/esm/helpers/leverage/limits.js +705 -0
  163. package/lib/esm/helpers/leverage/positionMarket.d.ts +17 -0
  164. package/lib/esm/helpers/leverage/positionMarket.js +24 -0
  165. package/lib/esm/helpers/leverage/reallocations.d.ts +159 -0
  166. package/lib/esm/helpers/leverage/reallocations.js +271 -0
  167. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  168. package/lib/esm/helpers/validateRequirementSpender.js +5 -1
  169. package/lib/esm/helpers/zeroExQuote.d.ts +250 -0
  170. package/lib/esm/helpers/zeroExQuote.js +754 -0
  171. package/lib/esm/index.d.ts +1 -0
  172. package/lib/esm/index.js +1 -0
  173. package/lib/esm/midnight/errors.d.ts +2 -1
  174. package/lib/esm/midnight/errors.js +2 -1
  175. package/lib/esm/reads/assertContractCode.d.ts +25 -0
  176. package/lib/esm/reads/assertContractCode.js +26 -0
  177. package/lib/esm/reads/fetchZeroExQuote.d.ts +123 -0
  178. package/lib/esm/reads/fetchZeroExQuote.js +326 -0
  179. package/lib/esm/types/action.d.ts +130 -1
  180. package/lib/esm/types/error.d.ts +59 -0
  181. package/lib/esm/types/error.js +76 -0
  182. package/lib/esm/types/index.d.ts +2 -0
  183. package/lib/esm/types/index.js +2 -0
  184. package/lib/esm/types/leverageError.d.ts +1552 -0
  185. package/lib/esm/types/leverageError.js +1660 -0
  186. package/lib/esm/types/zeroEx.d.ts +171 -0
  187. package/lib/esm/types/zeroEx.js +1 -0
  188. package/lib/esm/utils.d.ts +2 -2
  189. package/lib/esm/utils.js +2 -2
  190. package/lib/esm/version.d.ts +1 -1
  191. package/lib/esm/version.js +1 -1
  192. package/package.json +7 -7
@@ -83,6 +83,9 @@ const cloneAccrualVault = (vault, markets) => new blue_sdk_1.AccrualVault({
83
83
  position: clonePosition(position, markets),
84
84
  })));
85
85
  const cloneAdapter = (adapter, markets) => {
86
+ if (adapter.type === "VaultV2MidnightAdapter") {
87
+ return adapter;
88
+ }
86
89
  const base = {
87
90
  address: adapter.address,
88
91
  parentVault: adapter.parentVault,
@@ -134,7 +137,8 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
134
137
  /**
135
138
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
136
139
  *
137
- * Constructor inputs are cloned. Every simulated reallocation returns a new
140
+ * Constructor inputs are cloned, except read-only Midnight adapter snapshots, which are
141
+ * shared by reference. Every simulated reallocation returns a new
138
142
  * instance. Planning keeps the transaction-scoped `firstTotalAssets`
139
143
  * denominator outside the durable snapshot while applying reallocations in
140
144
  * contract order. Penalty donations update simulated vault accounting but are
@@ -265,7 +269,7 @@ class VaultV2BlueReallocationData {
265
269
  /**
266
270
  * Clones the complete simulation snapshot.
267
271
  *
268
- * @returns A deep clone of this simulation state.
272
+ * @returns A deep clone of this simulation state; read-only Midnight adapter snapshots are shared by reference.
269
273
  * @example
270
274
  * ```ts
271
275
  * import { markets } from "@morpho-org/morpho-test";
@@ -986,6 +990,230 @@ class VaultV2BlueReallocationData {
986
990
  })
987
991
  .reallocations.reduce((total, { assets }) => total + assets, 0n);
988
992
  }
993
+ /**
994
+ * Replays `reallocations` toward `marketId` in order, as one transaction at `timestamp`, and
995
+ * returns the first leg that leaves a target cap id over its cap, with the interest reserve the
996
+ * planner keeps through `timestamp + capAccrualBuffer`, or a market-sourced leg whose source market's
997
+ * liquidity or source adapter's supply no longer covers its amount (for example, replayed against a newer snapshot). Idle legs are checked against
998
+ * the caps only. A plan from
999
+ * `computeVaultV2BlueReallocations` fits; a leg cut below the amount the planner chose may not,
1000
+ * because a shared relative cap can require a larger move whose penalty donation lifts the cap.
1001
+ *
1002
+ * @param params - Replay inputs.
1003
+ * @param params.marketId - Target Blue market id.
1004
+ * @param params.reallocations - Legs to replay, in execution order.
1005
+ * @param params.timestamp - Optional timestamp, as given to the planner.
1006
+ * @param params.capAccrualBuffer - Optional cap-accrual buffer, as given to the planner.
1007
+ * @returns The first leg outside its caps or not funded by its source market, or `undefined` when every
1008
+ * leg fits.
1009
+ * @throws {UnsupportedBlueMarketIrmError} when a Blue market the replay accrues has positive debt and an unsupported
1010
+ * IRM: the target, a source, or, on a vault's first allocation, any other market the vault holds.
1011
+ * @throws {NegativeInputError} when `capAccrualBuffer` is negative.
1012
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
1013
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
1014
+ * @throws {UnknownReallocationAdapterError} when a leg's adapter is absent.
1015
+ * @throws {UnknownReallocationAllocationError} when a leg's cap or allocation state is absent.
1016
+ * @example
1017
+ * ```ts
1018
+ * // `client` is a mainnet viem client extended with `morphoViemExtension()`, and
1019
+ * // `market = client.morpho.blue(marketParams, mainnet.id)` for a USDC market Keyrock's vault supplies.
1020
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
1021
+ * const block = await client.getBlock();
1022
+ * const data = await market.getVaultV2BlueReallocationData({
1023
+ * vaultAddresses: [keyrockUsdcVaultV2],
1024
+ * block: { number: block.number, timestamp: block.timestamp },
1025
+ * });
1026
+ * const { reallocations } = data.computeVaultV2BlueReallocations(
1027
+ * marketParams.id,
1028
+ * { timestamp: block.timestamp, operation: { type: "borrow", amount: 1_000_000n } },
1029
+ * );
1030
+ * const outside = data.findVaultV2BlueReallocationOutsideCaps({
1031
+ * marketId: marketParams.id,
1032
+ * reallocations,
1033
+ * timestamp: block.timestamp,
1034
+ * });
1035
+ * // outside === undefined: the planner's own plan fits every cap.
1036
+ * ```
1037
+ */
1038
+ findVaultV2BlueReallocationOutsideCaps({ marketId, reallocations, timestamp, capAccrualBuffer, }) {
1039
+ const prepareLeg = this.createCapReplay({
1040
+ marketId,
1041
+ timestamp,
1042
+ capAccrualBuffer,
1043
+ });
1044
+ for (const reallocation of reallocations) {
1045
+ const leg = prepareLeg(reallocation);
1046
+ if ((reallocation.from.type === "market" &&
1047
+ !leg.funds(reallocation.assets)) ||
1048
+ !leg.fits(reallocation.assets)) {
1049
+ return reallocation;
1050
+ }
1051
+ leg.apply();
1052
+ }
1053
+ }
1054
+ /**
1055
+ * Replays `reallocations` toward `marketId` once, as in
1056
+ * `findVaultV2BlueReallocationOutsideCaps`, then returns the first of `amounts` at which
1057
+ * `reallocation`, executed next, stays within its target vault's caps. It checks the vault caps and the interest
1058
+ * reserve only, not the allocator's own max-in, which the planner applies when it sizes a leg, so only try amounts at
1059
+ * or below a planned leg's `assets`. Amounts outside the positive `uint128`
1060
+ * range are skipped, since no reallocation can move them, and so are amounts the leg's source cannot
1061
+ * fund: above the source market's liquidity or the source adapter's supply in it, or, from idle, above the vault's idle balance left by
1062
+ * the earlier legs, not counting their penalty donations, as the planner counts it. Only `reallocation` is probed at
1063
+ * each amount, so a search over many amounts costs one replay of the earlier legs.
1064
+ *
1065
+ * @param params - Search inputs.
1066
+ * @param params.marketId - Target Blue market id.
1067
+ * @param params.reallocations - Earlier legs, in execution order.
1068
+ * @param params.reallocation - Leg to size; its `assets` is ignored.
1069
+ * @param params.amounts - Candidate amounts, tried in order; non-positive or above-`uint128` ones are skipped.
1070
+ * @param params.timestamp - Optional timestamp, as given to the planner.
1071
+ * @param params.capAccrualBuffer - Optional cap-accrual buffer, as given to the planner.
1072
+ * @returns The first amount that fits, or `undefined` when none does or an earlier leg is outside its
1073
+ * caps, outside the positive `uint128` range, or above what its source can fund.
1074
+ * @throws {UnsupportedBlueMarketIrmError} when a Blue market the replay accrues has positive debt and an unsupported
1075
+ * IRM: the target, a source, or, on a vault's first allocation, any other market the vault holds.
1076
+ * @throws {NegativeInputError} when `capAccrualBuffer` is negative.
1077
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
1078
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
1079
+ * @throws {UnknownReallocationAdapterError} when a leg's adapter is absent.
1080
+ * @throws {UnknownReallocationAllocationError} when a leg's cap or allocation state is absent.
1081
+ * @example
1082
+ * ```ts
1083
+ * // `client` is a mainnet viem client extended with `morphoViemExtension()`, and
1084
+ * // `market = client.morpho.blue(marketParams, mainnet.id)` for a USDC market Keyrock's vault supplies.
1085
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
1086
+ * const block = await client.getBlock();
1087
+ * const data = await market.getVaultV2BlueReallocationData({
1088
+ * vaultAddresses: [keyrockUsdcVaultV2],
1089
+ * block: { number: block.number, timestamp: block.timestamp },
1090
+ * });
1091
+ * const {
1092
+ * reallocations: [leg],
1093
+ * } = data.computeVaultV2BlueReallocations(marketParams.id, {
1094
+ * timestamp: block.timestamp,
1095
+ * operation: { type: "borrow", amount: 1_000_000n },
1096
+ * });
1097
+ * // No leg: the market funds the borrow without a reallocation, so there is nothing to resize.
1098
+ * if (leg == null) return;
1099
+ * const assets = data.findVaultV2BlueReallocationFittingAssets({
1100
+ * marketId: marketParams.id,
1101
+ * reallocations: [],
1102
+ * reallocation: leg,
1103
+ * amounts: [leg.assets / 2n, leg.assets],
1104
+ * timestamp: block.timestamp,
1105
+ * });
1106
+ * // assets === leg.assets / 2n when that smaller move fits the vault caps, else leg.assets.
1107
+ * ```
1108
+ */
1109
+ findVaultV2BlueReallocationFittingAssets({ marketId, reallocations, reallocation, amounts, timestamp, capAccrualBuffer, }) {
1110
+ const prepareLeg = this.createCapReplay({
1111
+ marketId,
1112
+ timestamp,
1113
+ capAccrualBuffer,
1114
+ });
1115
+ for (const earlier of reallocations) {
1116
+ const leg = prepareLeg(earlier);
1117
+ if (!(leg.funds(earlier.assets) && leg.fits(earlier.assets))) {
1118
+ return undefined;
1119
+ }
1120
+ leg.apply();
1121
+ }
1122
+ const leg = prepareLeg(reallocation);
1123
+ for (const assets of amounts) {
1124
+ if (!leg.funds(assets)) {
1125
+ continue;
1126
+ }
1127
+ if (leg.fits(assets)) {
1128
+ return assets;
1129
+ }
1130
+ }
1131
+ }
1132
+ /**
1133
+ * Starts a cap replay toward `marketId` at `timestamp`. Each call of the returned function prepares
1134
+ * the next leg: `funds(assets)` checks that `assets` is a positive `uint128` its source holds
1135
+ * (market liquidity capped at the source adapter's supply, or idle without penalty donations), `fits(assets)` probes the leg at a positive `assets`, at the replay timestamp, against its target caps and
1136
+ * the planner's interest reserve, and `apply()` executes it at its own amount so later legs see it.
1137
+ */
1138
+ createCapReplay({ marketId, timestamp: inputTimestamp, capAccrualBuffer, }) {
1139
+ const timestamp = inputTimestamp == null
1140
+ ? this.getLatestSnapshotTimestamp()
1141
+ : BigInt(inputTimestamp);
1142
+ const reserves = createCapReserveState(this.mutableMarkets);
1143
+ const adapterIdsCache = new Map();
1144
+ const { getPair, capReserve } = createCapReserveResolvers({
1145
+ reserves,
1146
+ adapterIdsCache,
1147
+ timestamp,
1148
+ capAccrualBuffer: (0, utilization_js_1.resolveCapAccrualBuffer)(capAccrualBuffer),
1149
+ });
1150
+ let data = this.clone();
1151
+ data.setMarkets([data.getMarket(marketId).accrueInterest(timestamp)]);
1152
+ let context = createSimulationContext();
1153
+ return (reallocation) => {
1154
+ const { vault, from } = reallocation;
1155
+ const targetMarket = data.getMarket(marketId);
1156
+ const targetPair = getPair(vault, data.getAdapter(vault, reallocation.to.adapter), targetMarket);
1157
+ let sourcePair;
1158
+ let fundable;
1159
+ if (from.type === "market") {
1160
+ const sourceMarket = data
1161
+ .getMarket(from.marketParams.id)
1162
+ .accrueInterest(timestamp);
1163
+ data.setMarkets([sourceMarket]);
1164
+ const sourceAdapter = data.getAdapter(vault, from.adapter);
1165
+ fundable = blue_sdk_1.MathLib.min(sourceMarket.liquidity, sourceMarket.toSupplyAssets(sourceAdapter.supplyShares[sourceMarket.id] ?? 0n));
1166
+ sourcePair = getPair(vault, sourceAdapter, sourceMarket);
1167
+ }
1168
+ else {
1169
+ const donatedKey = findAddressKey(context.donatedPenaltyAssets, vault);
1170
+ fundable = blue_sdk_1.MathLib.zeroFloorSub(data.getVault(vault).assetBalance, donatedKey == null
1171
+ ? 0n
1172
+ : /* v8 ignore start: findAddressKey returns a key the record holds. */
1173
+ (context.donatedPenaltyAssets[donatedKey] ?? 0n));
1174
+ }
1175
+ const pairs = sourcePair == null ? [targetPair] : [targetPair, sourcePair];
1176
+ const sourceIds = new Set(sourcePair?.ids ?? []);
1177
+ const reserveById = new Map(targetPair.ids.map((id) => [id, capReserve(vault, id, pairs)]));
1178
+ const applyPublicReallocation = data.applyPublicReallocation.bind(data);
1179
+ const simulationContext = context;
1180
+ const targetSupplyHeadroom = blue_sdk_1.MathLib.zeroFloorSub(blue_sdk_1.MathLib.MAX_UINT_128, targetMarket.totalSupplyAssets);
1181
+ return {
1182
+ funds: (assets) => assets > 0n && assets <= viem_1.maxUint128 && assets <= fundable,
1183
+ fits: (assets) => assets > 0n &&
1184
+ assets <= targetSupplyHeadroom &&
1185
+ probeCandidateReallocation({
1186
+ assets,
1187
+ timestamp,
1188
+ targetMarket,
1189
+ applyPublicReallocation,
1190
+ simulationContext,
1191
+ reallocation,
1192
+ marketId,
1193
+ adapterIdsCache,
1194
+ targetIds: targetPair.ids,
1195
+ sourceIds,
1196
+ reserveById,
1197
+ })?.withinAllCaps === true,
1198
+ apply: () => {
1199
+ const vaultKey = vault.toLowerCase();
1200
+ const touched = reserves.touchedPairs.get(vaultKey) ??
1201
+ new Map();
1202
+ for (const pair of pairs) {
1203
+ touched.set(pair.key, pair);
1204
+ }
1205
+ reserves.touchedPairs.set(vaultKey, touched);
1206
+ ({ data, context } = data.applyPublicReallocation({
1207
+ context,
1208
+ reallocation,
1209
+ targetMarketId: marketId,
1210
+ timestamp,
1211
+ adapterIdsCache,
1212
+ }));
1213
+ },
1214
+ };
1215
+ };
1216
+ }
989
1217
  /**
990
1218
  * Computes borrow liquidity to a target utilization, including friendly
991
1219
  * Vault V2 public reallocations. Market/vault state and returned post-state
@@ -1888,7 +2116,7 @@ function fitCandidateCaps(params) {
1888
2116
  }
1889
2117
  /** Simulates one candidate amount and tests its reserved target-cap headroom. @internal */
1890
2118
  function probeCandidateReallocation(params) {
1891
- const { assets, targetMarket, applyPublicReallocation, simulationContext, reallocation, marketId, adapterIdsCache, targetIds, sourceIds, reserveById, } = params;
2119
+ const { assets, timestamp = params.targetMarket.lastUpdate, targetMarket, applyPublicReallocation, simulationContext, reallocation, marketId, adapterIdsCache, targetIds, sourceIds, reserveById, } = params;
1892
2120
  if (targetMarket.totalSupplyShares +
1893
2121
  targetMarket.toSupplyShares(assets, "Down") >
1894
2122
  blue_sdk_1.MathLib.MAX_UINT_128) {
@@ -1898,7 +2126,7 @@ function probeCandidateReallocation(params) {
1898
2126
  context: simulationContext,
1899
2127
  reallocation: { ...reallocation, assets },
1900
2128
  targetMarketId: marketId,
1901
- timestamp: targetMarket.lastUpdate,
2129
+ timestamp,
1902
2130
  adapterIdsCache,
1903
2131
  probe: true,
1904
2132
  }), index_js_1.ReallocationAllocationUnderflowError, index_js_1.ReallocationAdapterSupplySharesUnderflowError);
@@ -1,7 +1,7 @@
1
- export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
1
+ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, InvalidVaultV2MidnightAdapterMarketsError as InvalidBlueVaultV2MidnightAdapterMarketsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureError as InvalidMidnightEcrecoverSignatureError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureError as InvalidMidnightEcrecoverSignatureError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
6
  export type { ErrorClass } from "@morpho-org/morpho-ts";
7
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, MissingLocalePartError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
7
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, MissingLocalePartError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
package/lib/cjs/errors.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.InvalidMidnightEcrecoverSignatureError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.Permit2ExpirationOutOfRangeError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
- exports.RetryStoppedError = exports.RetriesExhaustedError = exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.MissingLocalePartError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = void 0;
3
+ exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.InvalidMidnightEcrecoverSignatureError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnresolvedBlockNumberError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.Permit2ExpirationOutOfRangeError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueVaultV2MidnightAdapterMarketsError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
+ exports.RetryStoppedError = exports.RetriesExhaustedError = exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.MissingLocalePartError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = void 0;
5
5
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
7
7
  Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
8
8
  Object.defineProperty(exports, "InvalidBlueMarketParamsError", { enumerable: true, get: function () { return blue_sdk_1.InvalidMarketParamsError; } });
9
+ Object.defineProperty(exports, "InvalidBlueVaultV2MidnightAdapterMarketsError", { enumerable: true, get: function () { return blue_sdk_1.InvalidVaultV2MidnightAdapterMarketsError; } });
9
10
  Object.defineProperty(exports, "UnknownAddressError", { enumerable: true, get: function () { return blue_sdk_1.UnknownAddressError; } });
10
11
  Object.defineProperty(exports, "UnknownBlueDataError", { enumerable: true, get: function () { return blue_sdk_1.UnknownDataError; } });
11
12
  Object.defineProperty(exports, "UnknownBlueFactory", { enumerable: true, get: function () { return blue_sdk_1.UnknownFactory; } });
@@ -34,6 +35,7 @@ Object.defineProperty(exports, "NonTupleReturnValueError", { enumerable: true, g
34
35
  Object.defineProperty(exports, "Permit2ExpirationOutOfRangeError", { enumerable: true, get: function () { return blue_sdk_viem_1.Permit2ExpirationOutOfRangeError; } });
35
36
  Object.defineProperty(exports, "UnknownAbiFunctionError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnknownAbiFunctionError; } });
36
37
  Object.defineProperty(exports, "UnnamedAbiOutputsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnnamedAbiOutputsError; } });
38
+ Object.defineProperty(exports, "UnresolvedBlockNumberError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnresolvedBlockNumberError; } });
37
39
  Object.defineProperty(exports, "UnsupportedPermitDomainExtensionsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError; } });
38
40
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
39
41
  Object.defineProperty(exports, "MidnightChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
@@ -44,9 +46,6 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
44
46
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
45
47
  Object.defineProperty(exports, "InvalidMidnightOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
46
48
  Object.defineProperty(exports, "InvalidMidnightOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
47
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
48
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
49
- Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
50
49
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
51
50
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
52
51
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -69,6 +68,9 @@ Object.defineProperty(exports, "_try", { enumerable: true, get: function () { re
69
68
  Object.defineProperty(exports, "DivisionByZeroError", { enumerable: true, get: function () { return morpho_ts_1.DivisionByZeroError; } });
70
69
  Object.defineProperty(exports, "InvalidAddressError", { enumerable: true, get: function () { return morpho_ts_1.InvalidAddressError; } });
71
70
  Object.defineProperty(exports, "InvalidBitLengthError", { enumerable: true, get: function () { return morpho_ts_1.InvalidBitLengthError; } });
71
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
72
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
73
+ Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
72
74
  Object.defineProperty(exports, "MissingLocalePartError", { enumerable: true, get: function () { return morpho_ts_1.MissingLocalePartError; } });
73
75
  Object.defineProperty(exports, "NegativeValueError", { enumerable: true, get: function () { return morpho_ts_1.NegativeValueError; } });
74
76
  Object.defineProperty(exports, "RegistryValueAlreadyRegisteredError", { enumerable: true, get: function () { return morpho_ts_1.RegistryValueAlreadyRegisteredError; } });
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams as fetchBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
6
6
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
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; } });
@@ -21,8 +21,42 @@ export declare const MAX_SLIPPAGE_TOLERANCE: bigint;
21
21
  export declare const DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
22
22
  /** Maximum Vault V2 reallocation penalty: 100%. */
23
23
  export declare const MAX_REALLOCATION_PENALTY = 1000000000000000000n;
24
+ /**
25
+ * Maximum penalty rate a ZeroExLeverageBundlesV1 Lever accepts per public-allocator reallocation:
26
+ * 1%, WAD-scaled. Fixed; no caller option.
27
+ */
28
+ export declare const LEVERAGE_MAX_REALLOCATION_PENALTY: bigint;
24
29
  /** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
25
30
  export declare const DEFAULT_LLTV_BUFFER: bigint;
31
+ /**
32
+ * SDK slippage ceiling per leverage action, WAD-scaled: `MAX_SLIPPAGE_TOLERANCE` (10%) for every action, the
33
+ * ceiling `fetchZeroExQuote` enforces, so the fetch and the builders cannot drift apart. Not configurable.
34
+ */
35
+ export declare const LEVERAGE_MAX_EXECUTION_LOSS: Readonly<{
36
+ readonly lever: bigint;
37
+ readonly delever: bigint;
38
+ readonly close: bigint;
39
+ }>;
40
+ /**
41
+ * Largest amount a Lever's worst swap price (`maxSwapIn` per `minCollateralToBuy`) may be above the market's oracle
42
+ * price, WAD-scaled: 15%. Exactly 15% is accepted, and a price below the oracle, which favours the user, is never
43
+ * refused. Delever and Close are not checked. The worst price uses `maxSwapIn`, which already includes the caller's
44
+ * slippage, so the room left for a gap between 0x's price and the oracle is about 15% minus that slippage (5% at the
45
+ * 10% ceiling).
46
+ * Not configurable.
47
+ */
48
+ export declare const LEVERAGE_MAX_ORACLE_DEVIATION: bigint;
49
+ /** Leverage deadline window after the data block, in seconds (1 hour). */
50
+ export declare const LEVERAGE_DEADLINE_WINDOW = 3600n;
51
+ /**
52
+ * Margin applied to the interest a Close's debt may accrue before its deadline: the buffer is the debt accrued for
53
+ * the one-hour deadline window at 4× the data block's borrow rate. The factor matches the AdaptiveCurveIrm curve
54
+ * steepness (`AdaptiveCurveIrmLib.CURVE_STEEPNESS` in blue-sdk), the most utilization can raise the rate over its
55
+ * rate at target, while that rate at target itself drifts by well under 1% in an hour (`ADJUSTMENT_SPEED` is 50 per
56
+ * year). It does not cover a rate that rises more than 4×, such as one quoted below target that jumps to full
57
+ * utilization; the Close then reverts instead of overpaying. Fixed; no caller option.
58
+ */
59
+ export declare const LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR = 4n;
26
60
  /**
27
61
  * Forward interest-accrual window, in seconds (2 hours), reserved in target-market
28
62
  * cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
@@ -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.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_MIN_BORROW_TIME_TO_MATURITY = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.VAULT_DEPOSIT_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.LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR = exports.LEVERAGE_DEADLINE_WINDOW = exports.LEVERAGE_MAX_ORACLE_DEVIATION = exports.LEVERAGE_MAX_EXECUTION_LOSS = exports.DEFAULT_LLTV_BUFFER = exports.LEVERAGE_MAX_REALLOCATION_PENALTY = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.VAULT_DEPOSIT_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");
@@ -26,8 +26,42 @@ exports.MAX_SLIPPAGE_TOLERANCE = blue_sdk_1.MathLib.WAD / 10n;
26
26
  exports.DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
27
27
  /** Maximum Vault V2 reallocation penalty: 100%. */
28
28
  exports.MAX_REALLOCATION_PENALTY = blue_sdk_1.MathLib.WAD;
29
+ /**
30
+ * Maximum penalty rate a ZeroExLeverageBundlesV1 Lever accepts per public-allocator reallocation:
31
+ * 1%, WAD-scaled. Fixed; no caller option.
32
+ */
33
+ exports.LEVERAGE_MAX_REALLOCATION_PENALTY = blue_sdk_1.MathLib.WAD / 100n;
29
34
  /** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
30
35
  exports.DEFAULT_LLTV_BUFFER = blue_sdk_1.MathLib.WAD / 200n;
36
+ /**
37
+ * SDK slippage ceiling per leverage action, WAD-scaled: `MAX_SLIPPAGE_TOLERANCE` (10%) for every action, the
38
+ * ceiling `fetchZeroExQuote` enforces, so the fetch and the builders cannot drift apart. Not configurable.
39
+ */
40
+ exports.LEVERAGE_MAX_EXECUTION_LOSS = Object.freeze({
41
+ lever: exports.MAX_SLIPPAGE_TOLERANCE,
42
+ delever: exports.MAX_SLIPPAGE_TOLERANCE,
43
+ close: exports.MAX_SLIPPAGE_TOLERANCE,
44
+ });
45
+ /**
46
+ * Largest amount a Lever's worst swap price (`maxSwapIn` per `minCollateralToBuy`) may be above the market's oracle
47
+ * price, WAD-scaled: 15%. Exactly 15% is accepted, and a price below the oracle, which favours the user, is never
48
+ * refused. Delever and Close are not checked. The worst price uses `maxSwapIn`, which already includes the caller's
49
+ * slippage, so the room left for a gap between 0x's price and the oracle is about 15% minus that slippage (5% at the
50
+ * 10% ceiling).
51
+ * Not configurable.
52
+ */
53
+ exports.LEVERAGE_MAX_ORACLE_DEVIATION = (blue_sdk_1.MathLib.WAD * 15n) / 100n;
54
+ /** Leverage deadline window after the data block, in seconds (1 hour). */
55
+ exports.LEVERAGE_DEADLINE_WINDOW = 3600n;
56
+ /**
57
+ * Margin applied to the interest a Close's debt may accrue before its deadline: the buffer is the debt accrued for
58
+ * the one-hour deadline window at 4× the data block's borrow rate. The factor matches the AdaptiveCurveIrm curve
59
+ * steepness (`AdaptiveCurveIrmLib.CURVE_STEEPNESS` in blue-sdk), the most utilization can raise the rate over its
60
+ * rate at target, while that rate at target itself drifts by well under 1% in an hour (`ADJUSTMENT_SPEED` is 50 per
61
+ * year). It does not cover a rate that rises more than 4×, such as one quoted below target that jumps to full
62
+ * utilization; the Close then reverts instead of overpaying. Fixed; no caller option.
63
+ */
64
+ exports.LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR = 4n;
31
65
  /**
32
66
  * Forward interest-accrual window, in seconds (2 hours), reserved in target-market
33
67
  * cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
@@ -193,6 +193,9 @@ function getDeadSharesAbsoluteCap(id, { absoluteCaps, entity, adapter, }) {
193
193
  }
194
194
  /** Checks the currently allocated positions of one supported adapter. @internal */
195
195
  function assertAdapterDeadShares(adapter, { absoluteCaps, entity, }) {
196
+ if (adapter instanceof blue_sdk_1.AccrualVaultV2MidnightAdapter) {
197
+ return;
198
+ }
196
199
  if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter) {
197
200
  const id = blue_sdk_1.VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
198
201
  if (getDeadSharesAbsoluteCap(id, {
@@ -0,0 +1,13 @@
1
+ import { type Address } from "viem";
2
+ /**
3
+ * Returns the ZeroExLeverageBundlesV1 address registered for `chainId`, whether or not the bundle
4
+ * can run there.
5
+ *
6
+ * @param chainId - Target chain id.
7
+ * @returns The registered ZeroExLeverageBundlesV1 address.
8
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
9
+ * @throws {LeverageUnsupportedChainError} with reason `noBundle` when no bundle, the zero address or a value that
10
+ * is not an address is registered.
11
+ * @internal
12
+ */
13
+ export declare const getRegisteredZeroExLeverageBundle: (chainId: number) => Address;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRegisteredZeroExLeverageBundle = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const viem_1 = require("viem");
6
+ const index_js_1 = require("../types/index.js");
7
+ /**
8
+ * Returns the ZeroExLeverageBundlesV1 address registered for `chainId`, whether or not the bundle
9
+ * can run there.
10
+ *
11
+ * @param chainId - Target chain id.
12
+ * @returns The registered ZeroExLeverageBundlesV1 address.
13
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
14
+ * @throws {LeverageUnsupportedChainError} with reason `noBundle` when no bundle, the zero address or a value that
15
+ * is not an address is registered.
16
+ * @internal
17
+ */
18
+ const getRegisteredZeroExLeverageBundle = (chainId) => {
19
+ const bundle = (0, blue_sdk_1.getChainAddresses)(chainId).bundles?.zeroExLeverageBundlesV1;
20
+ if (typeof bundle !== "string" ||
21
+ !(0, viem_1.isAddress)(bundle, { strict: false }) ||
22
+ (0, viem_1.isAddressEqual)(bundle, viem_1.zeroAddress)) {
23
+ throw new index_js_1.LeverageUnsupportedChainError({ chainId, reason: "noBundle" });
24
+ }
25
+ return bundle;
26
+ };
27
+ exports.getRegisteredZeroExLeverageBundle = getRegisteredZeroExLeverageBundle;
@@ -1,6 +1,8 @@
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_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_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, LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR, LEVERAGE_DEADLINE_WINDOW, LEVERAGE_MAX_EXECUTION_LOSS, LEVERAGE_MAX_ORACLE_DEVIATION, LEVERAGE_MAX_REALLOCATION_PENALTY, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
3
3
  export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
4
+ export * from "./leverage/index.js";
5
+ export { computeLeveragePenaltyAssets, type LeverageAllocatorState, type LeverageReallocation, validateLeverageReallocations, } from "./leverage/reallocations.js";
4
6
  export { addTransactionMetadata } from "./metadata.js";
5
7
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
6
8
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
@@ -11,3 +13,4 @@ export { getMidnightMaxSafeDebt, validateAccrualPosition, validateChainId, valid
11
13
  export { validateOfferSides } from "./validateOfferSides.js";
12
14
  export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
13
15
  export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
16
+ export { getZeroExSwapRoute, validateZeroExQuote, type ZeroExSwapRoute, } from "./zeroExQuote.js";