@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
@@ -1,16 +1,16 @@
1
- export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
1
+ export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MidnightAdapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  IPreLiquidationParams as IBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
6
- export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
5
+ IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MidnightAdapter, IVaultV2MidnightAdapterAccrualMarket, IVaultV2MidnightAdapterCollateralParams, IVaultV2MidnightAdapterMarket, IVaultV2MidnightAdapterMarketData, IVaultV2MidnightAdapterMarketState, IVaultV2MidnightAdapterMidnightMarket, IVaultV2MidnightAdapterPosition, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultV2MidnightAdapterAccrualMarket, VaultV2MidnightAdapterMarketData, } from "@morpho-org/blue-sdk";
6
+ export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
7
7
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
8
8
  PreLiquidationParams as BluePreLiquidationParams,
9
9
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
10
- PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
10
+ PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MidnightAdapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
11
11
  export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnapshot, BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, EcrecoverTreeCreateRequest as MidnightEcrecoverTreeCreateRequest, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, PriceRatifierV1TreeCreateRequest as MidnightPriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest as MidnightRateRatifierV1TreeCreateRequest, RatifierKind as MidnightRatifierKind, RatifierTreeInput as MidnightRatifierTreeInput, RatifierTypes as MidnightRatifierTypes, SetterTreeCreateRequest as MidnightSetterTreeCreateRequest, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeCreateRequest as MidnightTreeCreateRequest, TreeData as MidnightTreeData, TreeDescriptor as MidnightTreeDescriptor, TreeEntry as MidnightTreeEntry, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, TreeSnapshot as MidnightTreeSnapshot, TypedRatifierTreeInput as MidnightTypedRatifierTreeInput, TypedTreeMempoolValidateParams as MidnightTypedTreeMempoolValidateParams, } from "@morpho-org/midnight-sdk";
12
12
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
13
- export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
13
+ export type { BlueActions, BlueLeverageData, BlueTokenRequirementsParams, } from "./blue/index.js";
14
14
  export { MorphoBlue } from "./blue/index.js";
15
15
  export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, MidnightPositionHealthParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralBatchParams as MidnightSupplyCollateralBatchParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, WithdrawCollateralBatchParams as MidnightWithdrawCollateralBatchParams, WithdrawCollateralParams as MidnightWithdrawCollateralParams, } from "./midnight/index.js";
16
16
  export { type MidnightActionOutput, type MidnightActions, type MidnightRequirementsParams, MorphoMidnight, } from "./midnight/index.js";
@@ -14,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2BluePublicAllocatorConfig = exports.VaultV2BlueMarketPublicAllocatorConfig = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.BlueUser = exports.Token = exports.BluePreLiquidationPosition = exports.BluePreLiquidationParams = exports.BluePosition = exports.BlueMarketParams = exports.BlueMarket = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.BlueAccrualPosition = void 0;
17
+ exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2MidnightAdapter = exports.VaultV2BluePublicAllocatorConfig = exports.VaultV2BlueMarketPublicAllocatorConfig = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.BlueUser = exports.Token = exports.BluePreLiquidationPosition = exports.BluePreLiquidationParams = exports.BluePosition = exports.BlueMarketParams = exports.BlueMarket = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2MidnightAdapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.BlueAccrualPosition = void 0;
18
18
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
19
19
  Object.defineProperty(exports, "BlueAccrualPosition", { enumerable: true, get: function () { return blue_sdk_1.AccrualPosition; } });
20
20
  Object.defineProperty(exports, "AccrualVault", { enumerable: true, get: function () { return blue_sdk_1.AccrualVault; } });
21
21
  Object.defineProperty(exports, "AccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2; } });
22
+ Object.defineProperty(exports, "AccrualVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MidnightAdapter; } });
22
23
  Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter; } });
23
24
  Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2; } });
24
25
  Object.defineProperty(exports, "AccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter; } });
@@ -46,6 +47,7 @@ Object.defineProperty(exports, "VaultV2", { enumerable: true, get: function () {
46
47
  Object.defineProperty(exports, "VaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Adapter; } });
47
48
  Object.defineProperty(exports, "VaultV2BlueMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BlueMarketPublicAllocatorConfig; } });
48
49
  Object.defineProperty(exports, "VaultV2BluePublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BluePublicAllocatorConfig; } });
50
+ Object.defineProperty(exports, "VaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MidnightAdapter; } });
49
51
  Object.defineProperty(exports, "VaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1Adapter; } });
50
52
  Object.defineProperty(exports, "VaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1AdapterV2; } });
51
53
  Object.defineProperty(exports, "VaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoVaultV1Adapter; } });
@@ -1,29 +1,6 @@
1
1
  import type { AddressLabel } from "@morpho-org/morpho-ts";
2
2
  import type { Address, Client } from "viem";
3
3
  import { type ChainCheck } from "../../actions/requirements/chainCheck.js";
4
- /**
5
- * Asserts that a configured contract address holds deployed code on the client's chain.
6
- *
7
- * A call to a code-less address succeeds on-chain as a no-op, so entity flows check each
8
- * registered target before returning requirements. The `eth_getCode` read runs at the
9
- * client's default block; transport failures propagate unwrapped because they are
10
- * infrastructure failures, not configuration failures.
11
- *
12
- * @param client - Connected viem client used for the `eth_getCode` read.
13
- * @param params - Assertion parameters.
14
- * @param params.address - Contract address expected to hold code.
15
- * @param params.chainId - Chain id the flow targets, reported on the error.
16
- * @param params.role - Registry label naming the address's role in the flow.
17
- * @returns Nothing when the address holds code.
18
- * @throws {MissingContractCodeError} when the address has no deployed bytecode.
19
- * @throws {viem.BaseError} when the `eth_getCode` read itself fails.
20
- * @internal
21
- */
22
- export declare const assertContractCode: (client: Client, params: {
23
- readonly address: Address;
24
- readonly chainId: number;
25
- readonly role: AddressLabel;
26
- }) => Promise<void>;
27
4
  /**
28
5
  * Asserts that each distinct target in a flow's write-surface list holds code.
29
6
  *
@@ -1,34 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertRegistryTargetsHaveCode = exports.assertContractCode = void 0;
4
- const actions_1 = require("viem/actions");
3
+ exports.assertRegistryTargetsHaveCode = void 0;
5
4
  const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
5
+ const assertContractCode_js_1 = require("../../reads/assertContractCode.js");
6
6
  const index_js_1 = require("../../types/index.js");
7
- /**
8
- * Asserts that a configured contract address holds deployed code on the client's chain.
9
- *
10
- * A call to a code-less address succeeds on-chain as a no-op, so entity flows check each
11
- * registered target before returning requirements. The `eth_getCode` read runs at the
12
- * client's default block; transport failures propagate unwrapped because they are
13
- * infrastructure failures, not configuration failures.
14
- *
15
- * @param client - Connected viem client used for the `eth_getCode` read.
16
- * @param params - Assertion parameters.
17
- * @param params.address - Contract address expected to hold code.
18
- * @param params.chainId - Chain id the flow targets, reported on the error.
19
- * @param params.role - Registry label naming the address's role in the flow.
20
- * @returns Nothing when the address holds code.
21
- * @throws {MissingContractCodeError} when the address has no deployed bytecode.
22
- * @throws {viem.BaseError} when the `eth_getCode` read itself fails.
23
- * @internal
24
- */
25
- const assertContractCode = async (client, params) => {
26
- const bytecode = await (0, actions_1.getBytecode)(client, { address: params.address });
27
- if (bytecode === undefined || bytecode === "0x") {
28
- throw new index_js_1.MissingContractCodeError(params.address, params.chainId, params.role);
29
- }
30
- };
31
- exports.assertContractCode = assertContractCode;
32
7
  /**
33
8
  * Asserts that each distinct target in a flow's write-surface list holds code.
34
9
  *
@@ -62,7 +37,7 @@ const assertRegistryTargetsHaveCode = async (client, chainId, targets, chainChec
62
37
  continue;
63
38
  }
64
39
  seen.add(target.address);
65
- checks.push((0, exports.assertContractCode)(client, {
40
+ checks.push((0, assertContractCode_js_1.assertContractCode)(client, {
66
41
  address: target.address,
67
42
  chainId,
68
43
  role: target.role,
@@ -67,7 +67,9 @@ export interface VaultV2Actions {
67
67
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
68
68
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
69
69
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
70
- * @throws {InputExceedsMaxError} when the deadline exceeds seven days after creation or funding or the deadline exceeds uint256.
70
+ * @throws {InputExceedsMaxError} when the deadline exceeds seven days after creation or funding or
71
+ * the deadline exceeds uint256, or when the vault's liquidity adapter is a Midnight adapter (it
72
+ * cannot receive vault allocations, so no deposit fits and `max` is `0n`).
71
73
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
72
74
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
73
75
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -149,7 +151,9 @@ export interface VaultV2Actions {
149
151
  * @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
150
152
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
151
153
  * at any `getRequirements()` call.
152
- * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
154
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation,
155
+ * or when the vault's liquidity adapter is a Midnight adapter and `amount` exceeds the vault's
156
+ * idle assets plus what the adapter can withdraw from the liquidity market.
153
157
  * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
154
158
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
155
159
  * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
@@ -216,7 +220,25 @@ export interface VaultV2Actions {
216
220
  * @throws {NonPositiveInputError} when `shares` is not positive.
217
221
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
218
222
  * requirement resolution.
219
- * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
223
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256, or from
224
+ * `getRequirements()` when the vault's liquidity adapter is a Midnight adapter and `shares`
225
+ * are worth more than the vault's idle assets plus what the adapter can withdraw from the
226
+ * liquidity market.
227
+ * @throws {UnknownBlueFactory} from `getRequirements()` when the configured chain has no VaultV2 factory.
228
+ * @throws {UnknownBlueOfFactory} from `getRequirements()` when the vault is not a VaultV2 from the
229
+ * configured factory.
230
+ * @throws {UnsupportedBlueVaultV2AdapterError} from `getRequirements()` when the vault or one of its
231
+ * adapters uses an unsupported adapter class.
232
+ * @throws {UnsupportedBlueMarketIrmError} from `getRequirements()` when the vault's liquidity adapter
233
+ * is a Midnight adapter and accrual projects an underlying market with positive debt that uses an
234
+ * unsupported IRM.
235
+ * @throws {UnknownBlueMarketAllocationError} from `getRequirements()` when the vault's liquidity
236
+ * adapter is a Midnight adapter and accrual meets a nested Vault V1 withdraw queue market without
237
+ * allocation data.
238
+ * @throws {InvalidMidnightPositionLossFactorError} from `getRequirements()` when the vault's liquidity
239
+ * adapter is a Midnight adapter and accrual meets a market loss factor below a position's.
240
+ * @throws {InvalidMidnightPositionAccrualStateError} from `getRequirements()` when the vault's
241
+ * liquidity adapter is a Midnight adapter and accrual meets invalid Midnight position inputs.
220
242
  * @throws {NegativeInputError} when `referralFeePct` is negative.
221
243
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
222
244
  * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
@@ -225,7 +247,7 @@ export interface VaultV2Actions {
225
247
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
226
248
  * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
227
249
  * contract has no code at its registered address.
228
- * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
250
+ * @throws {viem.BaseError} from `getRequirements()` when a vault-state, allowance, nonce, `eth_chainId`, or
229
251
  * `eth_getCode` read fails.
230
252
  * @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
231
253
  * `getData()` has unusable decimals.
@@ -303,9 +325,11 @@ export interface VaultV2Actions {
303
325
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
304
326
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
305
327
  * requirement resolution.
306
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
328
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter, including
329
+ * a vault that mixes Blue and Midnight adapters.
307
330
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
308
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
331
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
332
+ * including a Midnight adapter.
309
333
  * @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
310
334
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
311
335
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -431,9 +455,11 @@ export interface VaultV2Actions {
431
455
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
432
456
  * requirement resolution.
433
457
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
434
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
458
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter,
459
+ * including a vault that mixes Blue and Midnight adapters.
435
460
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
436
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
461
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
462
+ * including a Midnight adapter.
437
463
  * @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
438
464
  * another adapter.
439
465
  * @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
@@ -26,6 +26,16 @@ const getVaultV2InKindRedeemRequirements_js_1 = require("../requirements/getVaul
26
26
  const validateNativeRequirements_js_1 = require("../requirements/validateNativeRequirements.js");
27
27
  const forceWithdrawQuote_js_1 = require("./forceWithdrawQuote.js");
28
28
  const inKindRedeemQuote_js_1 = require("./inKindRedeemQuote.js");
29
+ /**
30
+ * Midnight adapters revert vault-initiated `allocate` (`SelfAllocationOnly`), so a vault routing
31
+ * liquidity through one accepts no deposit. Exits are served from idle assets plus what the adapter's
32
+ * `withdrawToVault` path can withdraw from the liquidity market.
33
+ */
34
+ const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
35
+ /** Idle assets plus what the Midnight liquidity adapter can withdraw to the vault onchain. */
36
+ const midnightWithdrawLiquidity = (vaultData) => vaultData.assetBalance +
37
+ (vaultData.accrualLiquidityAdapter?.maxWithdraw(vaultData.liquidityData)
38
+ .value ?? 0n);
29
39
  /** Binds a viem client to a Vault V2 vault's action builders. */
30
40
  class MorphoVaultV2 {
31
41
  client;
@@ -94,6 +104,13 @@ class MorphoVaultV2 {
94
104
  if (funding.value > 0n) {
95
105
  (0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
96
106
  }
107
+ if (isMidnightLiquidityAdapter(vaultData)) {
108
+ throw new index_js_2.InputExceedsMaxError({
109
+ field: funding.value > 0n ? "nativeAmount" : "amount",
110
+ value: funding.assets,
111
+ max: 0n,
112
+ });
113
+ }
97
114
  const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
98
115
  // Bound forward accrual before deriving the deposit price protection.
99
116
  (0, validate_js_1.validateVaultDepositDeadline)(deadline, { now: createdAt });
@@ -200,6 +217,14 @@ class MorphoVaultV2 {
200
217
  throw new index_js_2.NonPositiveInputError("amount", amount);
201
218
  }
202
219
  const parsedAmount = (0, parse_js_1.parseUint256)("amount", amount);
220
+ if (isMidnightLiquidityAdapter(vaultData) &&
221
+ amount > midnightWithdrawLiquidity(vaultData)) {
222
+ throw new index_js_2.InputExceedsMaxError({
223
+ field: "amount",
224
+ value: amount,
225
+ max: midnightWithdrawLiquidity(vaultData),
226
+ });
227
+ }
203
228
  const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
204
229
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
205
230
  if (deadline <= createdAt) {
@@ -309,8 +334,21 @@ class MorphoVaultV2 {
309
334
  }
310
335
  const chainCheck = (0, chainCheck_js_1.createChainCheck)(this.client.viemClient, this.chainId);
311
336
  await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
337
+ const vaultData = await this.getDataWithChainCheck(chainCheck);
338
+ if (isMidnightLiquidityAdapter(vaultData)) {
339
+ // Onchain redeem accrues interest before converting shares to assets.
340
+ const { vault: accrued } = vaultData.accrueInterest(now);
341
+ const liquidity = midnightWithdrawLiquidity(accrued);
342
+ if (accrued.toAssets(shares) > liquidity) {
343
+ throw new index_js_2.InputExceedsMaxError({
344
+ field: "shares",
345
+ value: shares,
346
+ max: accrued.toShares(liquidity),
347
+ });
348
+ }
349
+ }
312
350
  return (0, getVaultBundlesSharesRequirements_js_1.getParsedVaultBundlesSharesRequirements)({ viemClient: this.client.viemClient, chainCheck }, (0, getVaultBundlesSharesRequirements_js_1.parseVaultBundlesSharesRequirements)(this.client.viemClient, {
313
- vaultData: await this.getDataWithChainCheck(chainCheck),
351
+ vaultData,
314
352
  version: "vaultV2",
315
353
  owner: userAddress,
316
354
  chainId: this.chainId,
@@ -56,7 +56,8 @@ export interface InputVaultV2BlueReallocationData {
56
56
  /**
57
57
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
58
58
  *
59
- * Constructor inputs are cloned. Every simulated reallocation returns a new
59
+ * Constructor inputs are cloned, except read-only Midnight adapter snapshots, which are
60
+ * shared by reference. Every simulated reallocation returns a new
60
61
  * instance. Planning keeps the transaction-scoped `firstTotalAssets`
61
62
  * denominator outside the durable snapshot while applying reallocations in
62
63
  * contract order. Penalty donations update simulated vault accounting but are
@@ -133,7 +134,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
133
134
  /**
134
135
  * Clones the complete simulation snapshot.
135
136
  *
136
- * @returns A deep clone of this simulation state.
137
+ * @returns A deep clone of this simulation state; read-only Midnight adapter snapshots are shared by reference.
137
138
  * @example
138
139
  * ```ts
139
140
  * import { markets } from "@morpho-org/morpho-test";
@@ -577,6 +578,123 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
577
578
  * ```
578
579
  */
579
580
  getPublicReallocationLiquidity(marketId: MarketId, options?: VaultV2BluePublicAllocatorOptions): bigint;
581
+ /**
582
+ * Replays `reallocations` toward `marketId` in order, as one transaction at `timestamp`, and
583
+ * returns the first leg that leaves a target cap id over its cap, with the interest reserve the
584
+ * planner keeps through `timestamp + capAccrualBuffer`, or a market-sourced leg whose source market's
585
+ * liquidity or source adapter's supply no longer covers its amount (for example, replayed against a newer snapshot). Idle legs are checked against
586
+ * the caps only. A plan from
587
+ * `computeVaultV2BlueReallocations` fits; a leg cut below the amount the planner chose may not,
588
+ * because a shared relative cap can require a larger move whose penalty donation lifts the cap.
589
+ *
590
+ * @param params - Replay inputs.
591
+ * @param params.marketId - Target Blue market id.
592
+ * @param params.reallocations - Legs to replay, in execution order.
593
+ * @param params.timestamp - Optional timestamp, as given to the planner.
594
+ * @param params.capAccrualBuffer - Optional cap-accrual buffer, as given to the planner.
595
+ * @returns The first leg outside its caps or not funded by its source market, or `undefined` when every
596
+ * leg fits.
597
+ * @throws {UnsupportedBlueMarketIrmError} when a Blue market the replay accrues has positive debt and an unsupported
598
+ * IRM: the target, a source, or, on a vault's first allocation, any other market the vault holds.
599
+ * @throws {NegativeInputError} when `capAccrualBuffer` is negative.
600
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
601
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
602
+ * @throws {UnknownReallocationAdapterError} when a leg's adapter is absent.
603
+ * @throws {UnknownReallocationAllocationError} when a leg's cap or allocation state is absent.
604
+ * @example
605
+ * ```ts
606
+ * // `client` is a mainnet viem client extended with `morphoViemExtension()`, and
607
+ * // `market = client.morpho.blue(marketParams, mainnet.id)` for a USDC market Keyrock's vault supplies.
608
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
609
+ * const block = await client.getBlock();
610
+ * const data = await market.getVaultV2BlueReallocationData({
611
+ * vaultAddresses: [keyrockUsdcVaultV2],
612
+ * block: { number: block.number, timestamp: block.timestamp },
613
+ * });
614
+ * const { reallocations } = data.computeVaultV2BlueReallocations(
615
+ * marketParams.id,
616
+ * { timestamp: block.timestamp, operation: { type: "borrow", amount: 1_000_000n } },
617
+ * );
618
+ * const outside = data.findVaultV2BlueReallocationOutsideCaps({
619
+ * marketId: marketParams.id,
620
+ * reallocations,
621
+ * timestamp: block.timestamp,
622
+ * });
623
+ * // outside === undefined: the planner's own plan fits every cap.
624
+ * ```
625
+ */
626
+ findVaultV2BlueReallocationOutsideCaps({ marketId, reallocations, timestamp, capAccrualBuffer, }: Pick<VaultV2BluePublicAllocatorOptions, "timestamp" | "capAccrualBuffer"> & {
627
+ readonly marketId: MarketId;
628
+ readonly reallocations: readonly VaultV2BlueReallocation[];
629
+ }): VaultV2BlueReallocation | undefined;
630
+ /**
631
+ * Replays `reallocations` toward `marketId` once, as in
632
+ * `findVaultV2BlueReallocationOutsideCaps`, then returns the first of `amounts` at which
633
+ * `reallocation`, executed next, stays within its target vault's caps. It checks the vault caps and the interest
634
+ * reserve only, not the allocator's own max-in, which the planner applies when it sizes a leg, so only try amounts at
635
+ * or below a planned leg's `assets`. Amounts outside the positive `uint128`
636
+ * range are skipped, since no reallocation can move them, and so are amounts the leg's source cannot
637
+ * 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
638
+ * the earlier legs, not counting their penalty donations, as the planner counts it. Only `reallocation` is probed at
639
+ * each amount, so a search over many amounts costs one replay of the earlier legs.
640
+ *
641
+ * @param params - Search inputs.
642
+ * @param params.marketId - Target Blue market id.
643
+ * @param params.reallocations - Earlier legs, in execution order.
644
+ * @param params.reallocation - Leg to size; its `assets` is ignored.
645
+ * @param params.amounts - Candidate amounts, tried in order; non-positive or above-`uint128` ones are skipped.
646
+ * @param params.timestamp - Optional timestamp, as given to the planner.
647
+ * @param params.capAccrualBuffer - Optional cap-accrual buffer, as given to the planner.
648
+ * @returns The first amount that fits, or `undefined` when none does or an earlier leg is outside its
649
+ * caps, outside the positive `uint128` range, or above what its source can fund.
650
+ * @throws {UnsupportedBlueMarketIrmError} when a Blue market the replay accrues has positive debt and an unsupported
651
+ * IRM: the target, a source, or, on a vault's first allocation, any other market the vault holds.
652
+ * @throws {NegativeInputError} when `capAccrualBuffer` is negative.
653
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
654
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
655
+ * @throws {UnknownReallocationAdapterError} when a leg's adapter is absent.
656
+ * @throws {UnknownReallocationAllocationError} when a leg's cap or allocation state is absent.
657
+ * @example
658
+ * ```ts
659
+ * // `client` is a mainnet viem client extended with `morphoViemExtension()`, and
660
+ * // `market = client.morpho.blue(marketParams, mainnet.id)` for a USDC market Keyrock's vault supplies.
661
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
662
+ * const block = await client.getBlock();
663
+ * const data = await market.getVaultV2BlueReallocationData({
664
+ * vaultAddresses: [keyrockUsdcVaultV2],
665
+ * block: { number: block.number, timestamp: block.timestamp },
666
+ * });
667
+ * const {
668
+ * reallocations: [leg],
669
+ * } = data.computeVaultV2BlueReallocations(marketParams.id, {
670
+ * timestamp: block.timestamp,
671
+ * operation: { type: "borrow", amount: 1_000_000n },
672
+ * });
673
+ * // No leg: the market funds the borrow without a reallocation, so there is nothing to resize.
674
+ * if (leg == null) return;
675
+ * const assets = data.findVaultV2BlueReallocationFittingAssets({
676
+ * marketId: marketParams.id,
677
+ * reallocations: [],
678
+ * reallocation: leg,
679
+ * amounts: [leg.assets / 2n, leg.assets],
680
+ * timestamp: block.timestamp,
681
+ * });
682
+ * // assets === leg.assets / 2n when that smaller move fits the vault caps, else leg.assets.
683
+ * ```
684
+ */
685
+ findVaultV2BlueReallocationFittingAssets({ marketId, reallocations, reallocation, amounts, timestamp, capAccrualBuffer, }: Pick<VaultV2BluePublicAllocatorOptions, "timestamp" | "capAccrualBuffer"> & {
686
+ readonly marketId: MarketId;
687
+ readonly reallocations: readonly VaultV2BlueReallocation[];
688
+ readonly reallocation: VaultV2BlueReallocation;
689
+ readonly amounts: Iterable<bigint>;
690
+ }): bigint | undefined;
691
+ /**
692
+ * Starts a cap replay toward `marketId` at `timestamp`. Each call of the returned function prepares
693
+ * the next leg: `funds(assets)` checks that `assets` is a positive `uint128` its source holds
694
+ * (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
695
+ * the planner's interest reserve, and `apply()` executes it at its own amount so later legs see it.
696
+ */
697
+ private createCapReplay;
580
698
  /**
581
699
  * Computes borrow liquidity to a target utilization, including friendly
582
700
  * Vault V2 public reallocations. Market/vault state and returned post-state