@morpho-org/morpho-sdk 6.5.0 → 7.0.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 (167) hide show
  1. package/MIGRATION-v6-to-v7.md +291 -0
  2. package/README.md +26 -12
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +3 -2
  5. package/lib/cjs/actions/bundles/common.d.ts +9 -5
  6. package/lib/cjs/actions/bundles/common.js +22 -13
  7. package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
  8. package/lib/cjs/actions/midnight/authorization.js +3 -2
  9. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
  10. package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +3 -3
  12. package/lib/cjs/actions/midnight/index.js +3 -3
  13. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  14. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
  18. package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
  20. package/lib/cjs/actions/midnight/takeLend.js +111 -54
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
  25. package/lib/cjs/actions/midnight/types.d.ts +7 -26
  26. package/lib/cjs/actions/midnight/types.js +0 -13
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
  32. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  33. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
  35. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  37. package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
  38. package/lib/cjs/actions/requirements/midnight/index.js +0 -1
  39. package/lib/cjs/constants.d.ts +1 -1
  40. package/lib/cjs/constants.js +3 -1
  41. package/lib/cjs/entities/blue/blue.d.ts +10 -6
  42. package/lib/cjs/entities/blue/blue.js +5 -3
  43. package/lib/cjs/entities/index.d.ts +2 -2
  44. package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
  45. package/lib/cjs/entities/midnight/midnight.js +981 -509
  46. package/lib/cjs/entities/midnight/types.d.ts +142 -60
  47. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
  48. package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -3
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +119 -43
  53. package/lib/cjs/helpers/callback.d.ts +54 -0
  54. package/lib/cjs/helpers/callback.js +73 -0
  55. package/lib/cjs/helpers/constant.d.ts +10 -0
  56. package/lib/cjs/helpers/constant.js +11 -1
  57. package/lib/cjs/helpers/index.d.ts +3 -2
  58. package/lib/cjs/helpers/index.js +7 -1
  59. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
  60. package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
  61. package/lib/cjs/helpers/utilization.d.ts +13 -0
  62. package/lib/cjs/helpers/utilization.js +26 -1
  63. package/lib/cjs/helpers/validate.d.ts +43 -2
  64. package/lib/cjs/helpers/validate.js +60 -3
  65. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  66. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
  67. package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
  68. package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
  69. package/lib/cjs/midnight/abis.d.ts +1 -1
  70. package/lib/cjs/midnight/abis.js +3 -2
  71. package/lib/cjs/midnight/types.d.ts +1 -1
  72. package/lib/cjs/types/action.d.ts +117 -89
  73. package/lib/cjs/types/action.js +1 -19
  74. package/lib/cjs/types/error.d.ts +126 -40
  75. package/lib/cjs/types/error.js +154 -49
  76. package/lib/cjs/types/sharedLiquidity.d.ts +17 -0
  77. package/lib/esm/abis.d.ts +1 -1
  78. package/lib/esm/abis.js +1 -1
  79. package/lib/esm/actions/bundles/common.d.ts +9 -5
  80. package/lib/esm/actions/bundles/common.js +22 -13
  81. package/lib/esm/actions/midnight/authorization.d.ts +3 -2
  82. package/lib/esm/actions/midnight/authorization.js +3 -2
  83. package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
  84. package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
  85. package/lib/esm/actions/midnight/index.d.ts +3 -3
  86. package/lib/esm/actions/midnight/index.js +3 -3
  87. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  88. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
  89. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  90. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
  91. package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
  92. package/lib/esm/actions/midnight/takeBorrow.js +98 -57
  93. package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
  94. package/lib/esm/actions/midnight/takeLend.js +114 -57
  95. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  96. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
  97. package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
  98. package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
  99. package/lib/esm/actions/midnight/types.d.ts +7 -26
  100. package/lib/esm/actions/midnight/types.js +1 -12
  101. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  102. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  103. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  104. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
  105. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
  106. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
  107. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  108. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
  109. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  110. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  111. package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
  112. package/lib/esm/actions/requirements/midnight/index.js +0 -1
  113. package/lib/esm/constants.d.ts +1 -1
  114. package/lib/esm/constants.js +1 -1
  115. package/lib/esm/entities/blue/blue.d.ts +10 -6
  116. package/lib/esm/entities/blue/blue.js +5 -3
  117. package/lib/esm/entities/index.d.ts +2 -2
  118. package/lib/esm/entities/midnight/midnight.d.ts +582 -108
  119. package/lib/esm/entities/midnight/midnight.js +987 -515
  120. package/lib/esm/entities/midnight/types.d.ts +142 -60
  121. package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
  122. package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
  123. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
  124. package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
  125. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -3
  126. package/lib/esm/entities/vaultV2BlueReallocationData.js +120 -44
  127. package/lib/esm/helpers/callback.d.ts +54 -0
  128. package/lib/esm/helpers/callback.js +68 -0
  129. package/lib/esm/helpers/constant.d.ts +10 -0
  130. package/lib/esm/helpers/constant.js +10 -0
  131. package/lib/esm/helpers/index.d.ts +3 -2
  132. package/lib/esm/helpers/index.js +3 -2
  133. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
  134. package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
  135. package/lib/esm/helpers/utilization.d.ts +13 -0
  136. package/lib/esm/helpers/utilization.js +25 -1
  137. package/lib/esm/helpers/validate.d.ts +43 -2
  138. package/lib/esm/helpers/validate.js +58 -2
  139. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  140. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
  141. package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
  142. package/lib/esm/helpers/validateRequirementSpender.js +4 -5
  143. package/lib/esm/midnight/abis.d.ts +1 -1
  144. package/lib/esm/midnight/abis.js +1 -1
  145. package/lib/esm/midnight/types.d.ts +1 -1
  146. package/lib/esm/types/action.d.ts +117 -89
  147. package/lib/esm/types/action.js +1 -18
  148. package/lib/esm/types/error.d.ts +126 -40
  149. package/lib/esm/types/error.js +135 -38
  150. package/lib/esm/types/sharedLiquidity.d.ts +17 -0
  151. package/package.json +9 -8
  152. package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
  153. package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
  154. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  155. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
  156. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  157. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
  158. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  159. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
  160. package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
  161. package/lib/esm/actions/midnight/cancelOffer.js +0 -69
  162. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  163. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
  164. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  165. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
  166. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  167. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
@@ -0,0 +1,54 @@
1
+ import { type InputMarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address, type Hex } from "viem";
3
+ /**
4
+ * Computes the CREATE2 address of `owner`'s `BlueBuyCallback` for `salt`, as deployed or
5
+ * returned by the chain's `midnightBlueBuyCallbackFactory.createBlueBuyCallback(owner, salt)`.
6
+ *
7
+ * Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`.
8
+ *
9
+ * @param params.chainId - Chain whose `midnightBlueBuyCallbackFactory`, `midnight` and `blue` are used.
10
+ * @param params.owner - Callback owner, the maker.
11
+ * @param params.salt - Callback salt.
12
+ * @returns The callback address, whether or not it is deployed yet.
13
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
14
+ * @throws {UnknownAddressError} when the chain has no `midnightBlueBuyCallbackFactory`, `midnight` or `blue` deployment.
15
+ * @example
16
+ * ```ts
17
+ * import { getMidnightBlueBuyCallbackAddress } from "@morpho-org/morpho-sdk";
18
+ * import { ChainId } from "@morpho-org/morpho-ts";
19
+ * import { keccak256, toHex } from "viem";
20
+ * import type { Address } from "viem";
21
+ *
22
+ * const callbackFor = (maker: Address) =>
23
+ * getMidnightBlueBuyCallbackAddress({
24
+ * chainId: ChainId.EthMainnet,
25
+ * owner: maker,
26
+ * salt: keccak256(toHex("my-strategy")),
27
+ * });
28
+ * // `callbackFor(maker)` returns the maker's BlueBuyCallback address, deployed or not.
29
+ * ```
30
+ */
31
+ export declare const getMidnightBlueBuyCallbackAddress: ({ chainId, owner, salt, }: {
32
+ readonly chainId: number;
33
+ readonly owner: Address;
34
+ readonly salt: Hex;
35
+ }) => Address;
36
+ /**
37
+ * Returns the `callbackData` every `supplyBlueMakeLend` offer must carry: `abi.encode(blueMarket)`.
38
+ *
39
+ * @param blueMarket - Morpho Blue market encoded as the callback data.
40
+ * @returns The ABI-encoded Morpho Blue market parameters.
41
+ * @example
42
+ * ```ts
43
+ * import { getMidnightBlueBuyCallbackData } from "@morpho-org/morpho-sdk";
44
+ * import type { InputMarketParams as MarketParams } from "@morpho-org/blue-sdk";
45
+ * import type { Hex } from "viem";
46
+ *
47
+ * function getCallbackData(blueMarket: MarketParams) {
48
+ * const callbackData = getMidnightBlueBuyCallbackData(blueMarket);
49
+ * // callbackData satisfies Hex
50
+ * return callbackData;
51
+ * }
52
+ * ```
53
+ */
54
+ export declare const getMidnightBlueBuyCallbackData: (blueMarket: InputMarketParams) => Hex;
@@ -0,0 +1,68 @@
1
+ import { marketParamsAbi } from "@morpho-org/blue-sdk";
2
+ import { getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { concatHex, encodeAbiParameters, getContractAddress, } from "viem";
4
+ /**
5
+ * `BlueBuyCallback` creation bytecode from `morpho-org/midnight` commit
6
+ * `4603969e`, embedded in the `BlueBuyCallbackFactory` deployed on Ethereum, Base, Robinhood and Arc.
7
+ */
8
+ const blueBuyCallbackBytecode = "0x60e0806040523461012657606081611611803803809161001f828561012a565b8339810103126101265761003281610161565b9061004b604061004460208401610161565b9201610161565b908260805260a0528060c05260018060a01b031690813b15610126576040516207767560ed1b81526001600160a01b03909116600482015260016024820152905f908290604490829084905af1801561011b5761010b575b60405161149b9081610176823960805181818160b4015281816102fc0152818161078201528181610dfd0152611004015260a0518181816102210152610dc3015260c051818181610103015281816102650152818161067c015281816108660152610f5e0152f35b5f6101159161012a565b5f6100a3565b6040513d5f823e3d90fd5b5f80fd5b601f909101601f19168101906001600160401b0382119082101761014d57604052565b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036101265756fe6080806040526004361015610012575f80fd5b5f905f3560e01c908163117803e314610fe7575080631c0bb54d14610d585780631e686318146107ef5780638069218f1461043d578063affed0e014610420578063bc25cf7714610289578063c011ff6414610245578063dc400c12146102015763eecea00014610081575f80fd5b346101a15760403660031901126101a15761009a61107c565b9060243591821515908184036101fd576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633036101ee576040516332f256cf60e11b81523060048201526001600160a01b038281166024830152939485947f000000000000000000000000000000000000000000000000000000000000000016939091602081604481885afa9081156101e35786916101b4575b5015150361014a57505050f35b823b156101af576040516207767560ed1b81526001600160a01b03929092166004830152151560248201529082908290604490829084905af180156101a4576101905750f35b8161019a91611044565b6101a15780f35b80fd5b6040513d84823e3d90fd5b505050fd5b6101d6915060203d6020116101dc575b6101ce8183611044565b810190611358565b5f61013d565b503d6101c4565b6040513d88823e3d90fd5b6330cd747160e01b8352600483fd5b8280fd5b50346101a157806003193601126101a15760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346101a157806003193601126101a15760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346101a15760203660031901126101a1576102a361107c565b6040516370a0823160e01b81523060048201526001600160a01b03821691602082602481865afa9182156104155784926103dd575b50803b156103ce5760405163a9059cbb60e01b602082019081526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001660248301526044820184905285928392909190839061034881606481015b03601f198101835282611044565b51925af1610354611370565b90156103c65780519081159182156103ac575b50501561039d576040519081527f2ae72b44f59d038340fca5739135a1d51fc5ab720bb02d983e4c5ff4119ca7b860203392a380f35b630bc11c3f60e21b8352600483fd5b6103bf9250602080918301019101611358565b5f80610367565b602081519101fd5b633c11a9c560e21b8452600484fd5b9091506020813d60201161040d575b816103f960209383611044565b810103126104095751905f6102d8565b5f80fd5b3d91506103ec565b6040513d86823e3d90fd5b50346101a157806003193601126101a15760209054604051908152f35b503461040957366003190161010081126104095760a0136104095760405161046481611028565b61046c61107c565b8152602435906001600160a01b038216820361040957602081019182526044359182151583036104095760408201928352606082019160643583526084356080820190808252606060a3193601126104095742116107e05783515f54905f1982146107cc57600182015f55036107bd5760405160208101917f81d0284fb0e2cde18d0553b06189d6f7613c96a01bb5b5e7828eade6a0dcac9183526001600160a01b0384511660408301526001600160a01b038551166060830152865115156080830152855160a08301525160c082015260c0815261054c60e082611044565b51902060405160208101907f47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218825246604082015230606082015260608152610595608082611044565b5190209060405190602082019261190160f01b845260228301526042820152604281526105c3606282611044565b51902060a4359060ff82168092036104095760805f916020936040519182528482015260c435604082015260e435606082015282805260015afa1561073b576001600160a01b035f511680151591826107a9575b5081610776575b5015610767576106af91516040519081527fbae999fc435f6200224444d8535f1936f9abd69060fcaec680f690f1810ae36a60203392a280516040516332f256cf60e11b81523060048201526001600160a01b0391821660248201527f0000000000000000000000000000000000000000000000000000000000000000909116939092602090849081906044820190565b0381875afa92831561073b575f93610746575b5051151580921515036106d3578380f35b516001600160a01b031690823b15610409576040516207767560ed1b81526001600160a01b0392909216600483015215156024820152905f908290604490829084905af1801561073b57610728575b80808380f35b61073491505f90611044565b5f5f610722565b6040513d5f823e3d90fd5b61076091935060203d6020116101dc576101ce8183611044565b915f6106c2565b638baa579f60e01b5f5260045ffd5b90506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016145f61061e565b516001600160a01b0316811491505f610617565b633ab3447f60e11b5f5260045ffd5b634e487b7160e01b5f52601160045260245ffd5b630f05f5bf60e01b5f5260045ffd5b346104095760803660031901126104095760243567ffffffffffffffff8111610409576108209036906004016110a6565b50610829611066565b5060643567ffffffffffffffff81116104095761084d61085c91369060040161122a565b60208082518301019101611284565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169060a0812060405190632e3071cd60e11b8252600482015260c081602481865afa90811561073b575f91610ca8575b50608081016108ce6001600160801b038251164261134b565b9081151580610c92575b80610c7c575b610a82575b50506001600160801b03815116906001600160801b03604081602084015116920151169060a08420604051906349e2903160e11b82526004820152306024820152606081604481895afa90811561073b575f916109f9575b505160018401928385116107cc57620f424083018093116107cc576109766001600160a01b039361097160209661097c956113cc565b611470565b9461134b565b935116936024604051809681936370a0823160e01b835260048301525afa91821561073b575f926109c4575b6020935081811090821802186040519181811090821802188152f35b91506020833d6020116109f1575b816109df60209383611044565b810103126104095760209251916109a8565b3d91506109d2565b90506060813d606011610a7a575b81610a1460609383611044565b8101031261040957604051906060820182811067ffffffffffffffff821117610a6657610a5b91604091825280518452610a5060208201611337565b602085015201611337565b60408201528661093b565b634e487b7160e01b5f52604160045260245ffd5b3d9150610a07565b6060840151604051638c00bf6b60e01b8152906001600160a01b0316610aab60048301876112e6565b6001600160801b0385511660a483015260208501936001600160801b0385511660c48401526001600160801b0360408701948186511660e48601528160608901511661010486015251166101248401526020836101648160a08a01956001600160801b038751166101448301525afa92831561073b575f93610c46575b50610b8b6001600160801b0393610b85610b4f670de0b6b3a76400009487895116936113cc565b610b80671bc16d674ec80000610b6583806113cc565b046729a2241af62c0000610b7984836113cc565b04926113bf565b6113bf565b906113cc565b049282610ba3610b9a866113df565b8284511661139f565b16905281610bbc610bb3856113df565b8288511661139f565b16855251169081610bce575b506108e3565b670de0b6b3a764000091610be1916113cc565b04610bf6816001600160801b0385511661134b565b6001600160801b0383511691620f424083018093116107cc57600182018092116107cc57610c36610c3b926109716001600160801b0395610b9a946113cc565b6113df565b169052838080610bc8565b92506020833d602011610c74575b81610c6160209383611044565b8101031261040957915191610b8b610b28565b3d9150610c54565b506001600160a01b0360608501511615156108de565b506001600160801b0360408401511615156108d8565b905060c0813d60c011610d50575b81610cc360c09383611044565b81010312610409576040519060c0820182811067ffffffffffffffff821117610a6657610d459160a091604052610cf981611337565b8452610d0760208201611337565b6020850152610d1860408201611337565b6040850152610d2960608201611337565b6060850152610d3a60808201611337565b608085015201611337565b60a0820152836108b5565b3d9150610cb6565b346104095760e03660031901126104095760243567ffffffffffffffff811161040957610d899036906004016110a6565b60443560a435916001600160a01b0383168093036104095760c43567ffffffffffffffff811161040957610dc190369060040161122a565b7f0000000000000000000000000000000000000000000000000000000000000000936001600160a01b0385163303610fd8576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001603610fc95780602080610e3593518301019101611284565b60406001600160a01b038251169201916001600160a01b0383511603610fba5782610f17575b505160405163095ea7b360e01b602082019081526001600160a01b03948516602483015260448201939093525f938493921691908390610e9e816064810161033a565b51925af1610eaa611370565b90156103c6578051908115918215610efd575b505015610eee5760206040517f7f87788ea698181ea4d28d1576d0ba4fc92c0dbe5bf75b43692af2ce91dbaea28152f35b631f55ddd960e21b5f5260045ffd5b610f109250602080918301019101611358565b8180610ebd565b604051635c2bea4960e01b815290610f339060048301906112e6565b8260a48201525f60c48201523060e482015230610104820152604081610124815f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165af1801561073b5715610e5b57604090819392933d8311610fb3575b610fa48183611044565b81010312610409579083610e5b565b503d610f9a565b63effb039160e01b5f5260045ffd5b631ec6e83760e21b5f5260045ffd5b631e6a35c760e01b5f5260045ffd5b34610409575f366003190112610409576020906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b60a0810190811067ffffffffffffffff821117610a6657604052565b90601f8019910116810190811067ffffffffffffffff821117610a6657604052565b604435906001600160a01b038216820361040957565b600435906001600160a01b038216820361040957565b35906001600160a01b038216820361040957565b919091610100818403126104095760405190610100820182811067ffffffffffffffff821117610a66576040528193813583526110e560208301611092565b60208401526110f660408301611092565b6040840152606082013567ffffffffffffffff811161040957820181601f820112156104095780359067ffffffffffffffff8211610a66576040519261114260208460051b0185611044565b82845260208085019360071b8301019181831161040957602001925b8284106111a6575050505060e080926111a19260608601526080810135608086015260a081013560a086015261119660c08201611092565b60c086015201611092565b910152565b6080848303126104095760405190608082019082821067ffffffffffffffff831117610a66576080926020926040526111de87611092565b81528287013583820152604087013560408201526111fe60608801611092565b606082015281520193019261115e565b67ffffffffffffffff8111610a6657601f01601f191660200190565b81601f82011215610409578035906112418261120e565b9261124f6040519485611044565b8284526020838301011161040957815f926020809301838601378301015290565b51906001600160a01b038216820361040957565b908160a09103126104095760806040519161129e83611028565b6112a781611270565b83526112b560208201611270565b60208401526112c660408201611270565b60408401526112d760608201611270565b60608401520151608082015290565b608080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b0360608201511660608501520151910152565b51906001600160801b038216820361040957565b919082039182116107cc57565b90816020910312610409575180151581036104095790565b3d1561139a573d906113818261120e565b9161138f6040519384611044565b82523d5f602084013e565b606090565b906001600160801b03809116911601906001600160801b0382116107cc57565b919082018092116107cc57565b818102929181159184041417156107cc57565b6040516113ed604082611044565b6014815260208101907f6d61782075696e7431323820657863656564656400000000000000000000000082526001600160801b0383116114355750506001600160801b031690565b60449060405192839162461bcd60e51b8352602060048401525180918160248501528484015e5f828201840152601f01601f19168101030190fd5b811561147a570490565b634e487b7160e01b5f52601260045260245ffdfea164736f6c6343000822000a";
9
+ /**
10
+ * Computes the CREATE2 address of `owner`'s `BlueBuyCallback` for `salt`, as deployed or
11
+ * returned by the chain's `midnightBlueBuyCallbackFactory.createBlueBuyCallback(owner, salt)`.
12
+ *
13
+ * Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`.
14
+ *
15
+ * @param params.chainId - Chain whose `midnightBlueBuyCallbackFactory`, `midnight` and `blue` are used.
16
+ * @param params.owner - Callback owner, the maker.
17
+ * @param params.salt - Callback salt.
18
+ * @returns The callback address, whether or not it is deployed yet.
19
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
20
+ * @throws {UnknownAddressError} when the chain has no `midnightBlueBuyCallbackFactory`, `midnight` or `blue` deployment.
21
+ * @example
22
+ * ```ts
23
+ * import { getMidnightBlueBuyCallbackAddress } from "@morpho-org/morpho-sdk";
24
+ * import { ChainId } from "@morpho-org/morpho-ts";
25
+ * import { keccak256, toHex } from "viem";
26
+ * import type { Address } from "viem";
27
+ *
28
+ * const callbackFor = (maker: Address) =>
29
+ * getMidnightBlueBuyCallbackAddress({
30
+ * chainId: ChainId.EthMainnet,
31
+ * owner: maker,
32
+ * salt: keccak256(toHex("my-strategy")),
33
+ * });
34
+ * // `callbackFor(maker)` returns the maker's BlueBuyCallback address, deployed or not.
35
+ * ```
36
+ */
37
+ export const getMidnightBlueBuyCallbackAddress = ({ chainId, owner, salt, }) => getContractAddress({
38
+ opcode: "CREATE2",
39
+ from: getChainAddress(chainId, "midnightBlueBuyCallbackFactory"),
40
+ salt,
41
+ bytecode: concatHex([
42
+ blueBuyCallbackBytecode,
43
+ encodeAbiParameters([{ type: "address" }, { type: "address" }, { type: "address" }], [
44
+ owner,
45
+ getChainAddress(chainId, "midnight"),
46
+ getChainAddress(chainId, "blue"),
47
+ ]),
48
+ ]),
49
+ });
50
+ /**
51
+ * Returns the `callbackData` every `supplyBlueMakeLend` offer must carry: `abi.encode(blueMarket)`.
52
+ *
53
+ * @param blueMarket - Morpho Blue market encoded as the callback data.
54
+ * @returns The ABI-encoded Morpho Blue market parameters.
55
+ * @example
56
+ * ```ts
57
+ * import { getMidnightBlueBuyCallbackData } from "@morpho-org/morpho-sdk";
58
+ * import type { InputMarketParams as MarketParams } from "@morpho-org/blue-sdk";
59
+ * import type { Hex } from "viem";
60
+ *
61
+ * function getCallbackData(blueMarket: MarketParams) {
62
+ * const callbackData = getMidnightBlueBuyCallbackData(blueMarket);
63
+ * // callbackData satisfies Hex
64
+ * return callbackData;
65
+ * }
66
+ * ```
67
+ */
68
+ export const getMidnightBlueBuyCallbackData = (blueMarket) => encodeAbiParameters([marketParamsAbi], [blueMarket]);
@@ -1,4 +1,6 @@
1
1
  import { type Address } from "viem";
2
+ /** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
3
+ export declare const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
2
4
  /** Maximum slippage tolerance: 10% */
3
5
  export declare const MAX_SLIPPAGE_TOLERANCE: bigint;
4
6
  /** Default maximum Vault V2 reallocation penalty: zero. */
@@ -15,6 +17,14 @@ export declare const DEFAULT_LLTV_BUFFER: bigint;
15
17
  * `VaultV2BluePublicAllocatorOptions.capAccrualBuffer`.
16
18
  */
17
19
  export declare const DEFAULT_CAP_ACCRUAL_BUFFER: bigint;
20
+ /**
21
+ * Default headroom, as a WAD-scaled share of a BluePublicAllocator target-market
22
+ * cap (1%), kept below that cap when an operation's reallocation would
23
+ * otherwise fill it. It absorbs other allocations to the same market between
24
+ * the quote and inclusion. Override with
25
+ * `VaultV2BluePublicAllocatorOptions.allocatorCapHeadroom`.
26
+ */
27
+ export declare const DEFAULT_ALLOCATOR_CAP_HEADROOM: bigint;
18
28
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
19
29
  export declare const MAX_ABSOLUTE_SHARE_PRICE: bigint;
20
30
  /**
@@ -1,6 +1,8 @@
1
1
  import { ChainId, MathLib } from "@morpho-org/blue-sdk";
2
2
  import { Time } from "@morpho-org/morpho-ts";
3
3
  import { maxUint96 } from "viem";
4
+ /** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
5
+ export const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
4
6
  /** Maximum slippage tolerance: 10% */
5
7
  export const MAX_SLIPPAGE_TOLERANCE = MathLib.WAD / 10n;
6
8
  /** Default maximum Vault V2 reallocation penalty: zero. */
@@ -17,6 +19,14 @@ export const DEFAULT_LLTV_BUFFER = MathLib.WAD / 200n;
17
19
  * `VaultV2BluePublicAllocatorOptions.capAccrualBuffer`.
18
20
  */
19
21
  export const DEFAULT_CAP_ACCRUAL_BUFFER = Time.s.from.h(2n);
22
+ /**
23
+ * Default headroom, as a WAD-scaled share of a BluePublicAllocator target-market
24
+ * cap (1%), kept below that cap when an operation's reallocation would
25
+ * otherwise fill it. It absorbs other allocations to the same market between
26
+ * the quote and inclusion. Override with
27
+ * `VaultV2BluePublicAllocatorOptions.allocatorCapHeadroom`.
28
+ */
29
+ export const DEFAULT_ALLOCATOR_CAP_HEADROOM = MathLib.WAD / 100n;
20
30
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
21
31
  export const MAX_ABSOLUTE_SHARE_PRICE = 100n * MathLib.RAY;
22
32
  /**
@@ -1,11 +1,12 @@
1
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
1
+ export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./constant.js";
2
3
  export { addTransactionMetadata } from "./metadata.js";
3
4
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
4
5
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
5
6
  export { grossFromNetAssets } from "./referralFee.js";
6
7
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
7
8
  export { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
8
- export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
+ export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateMidnightNativeAmount, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
10
  export { validateOfferSides } from "./validateOfferSides.js";
10
11
  export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
11
12
  export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
@@ -1,11 +1,12 @@
1
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
1
+ export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./constant.js";
2
3
  export { addTransactionMetadata } from "./metadata.js";
3
4
  export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
4
5
  export { previewVaultV2InKindRedeem, } from "./previewVaultV2InKindRedeem.js";
5
6
  export { grossFromNetAssets } from "./referralFee.js";
6
7
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
7
8
  export { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
8
- export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
+ export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateMidnightNativeAmount, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
10
  export { validateOfferSides } from "./validateOfferSides.js";
10
11
  export { validateRequirementSpender, } from "./validateRequirementSpender.js";
11
12
  export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
@@ -4,7 +4,7 @@ import type { Address, Hex, TypedDataDefinition, WalletClient } from "viem";
4
4
  * `userAddress`, and returns the signature.
5
5
  *
6
6
  * Use inside requirement `sign(...)` callbacks before converting a signature
7
- * into protocol calldata or mempool payload bytes. The verification step keeps
7
+ * into protocol calldata. The verification step keeps
8
8
  * wallet/account mismatches from reaching transaction builders.
9
9
  *
10
10
  * @param params - Signing and verification parameters.
@@ -22,8 +22,8 @@ import type { Address, Hex, TypedDataDefinition, WalletClient } from "viem";
22
22
  *
23
23
  * const signature = await signAndVerifyTypedData({
24
24
  * client: walletClient,
25
- * userAddress: maker,
26
- * typedData: offerRootTypedData,
25
+ * userAddress: user,
26
+ * typedData: permitTypedData,
27
27
  * });
28
28
  * ```
29
29
  */
@@ -7,7 +7,7 @@ import { validateChainId, validateUserAddress } from "./validate.js";
7
7
  * `userAddress`, and returns the signature.
8
8
  *
9
9
  * Use inside requirement `sign(...)` callbacks before converting a signature
10
- * into protocol calldata or mempool payload bytes. The verification step keeps
10
+ * into protocol calldata. The verification step keeps
11
11
  * wallet/account mismatches from reaching transaction builders.
12
12
  *
13
13
  * @param params - Signing and verification parameters.
@@ -25,8 +25,8 @@ import { validateChainId, validateUserAddress } from "./validate.js";
25
25
  *
26
26
  * const signature = await signAndVerifyTypedData({
27
27
  * client: walletClient,
28
- * userAddress: maker,
29
- * typedData: offerRootTypedData,
28
+ * userAddress: user,
29
+ * typedData: permitTypedData,
30
30
  * });
31
31
  * ```
32
32
  */
@@ -11,6 +11,19 @@ import { type BigIntish } from "@morpho-org/blue-sdk";
11
11
  * ```
12
12
  */
13
13
  export declare const resolveCapAccrualBuffer: (value?: BigIntish) => bigint;
14
+ /**
15
+ * Resolves and validates the BluePublicAllocator cap headroom share.
16
+ * @internal
17
+ * @param value - Optional WAD-scaled share of the allocator cap.
18
+ * @returns A share between zero and WAD, defaulting to 1%.
19
+ * @throws {NegativeInputError} when the share is negative.
20
+ * @throws {InputExceedsMaxError} when the share exceeds WAD.
21
+ * @example
22
+ * ```ts
23
+ * const headroom = resolveAllocatorCapHeadroom(undefined);
24
+ * ```
25
+ */
26
+ export declare const resolveAllocatorCapHeadroom: (value?: bigint) => bigint;
14
27
  /**
15
28
  * Resolves and validates a source withdrawal utilization ceiling.
16
29
  * @internal
@@ -1,6 +1,6 @@
1
1
  import { MathLib } from "@morpho-org/blue-sdk";
2
2
  import { InputExceedsMaxError, NegativeInputError } from "../types/index.js";
3
- import { DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, } from "./constant.js";
3
+ import { DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, } from "./constant.js";
4
4
  /**
5
5
  * Resolves and validates the target-market cap-accrual buffer.
6
6
  * @internal
@@ -18,6 +18,30 @@ export const resolveCapAccrualBuffer = (value) => {
18
18
  throw new NegativeInputError("capAccrualBuffer", buffer);
19
19
  return buffer;
20
20
  };
21
+ /**
22
+ * Resolves and validates the BluePublicAllocator cap headroom share.
23
+ * @internal
24
+ * @param value - Optional WAD-scaled share of the allocator cap.
25
+ * @returns A share between zero and WAD, defaulting to 1%.
26
+ * @throws {NegativeInputError} when the share is negative.
27
+ * @throws {InputExceedsMaxError} when the share exceeds WAD.
28
+ * @example
29
+ * ```ts
30
+ * const headroom = resolveAllocatorCapHeadroom(undefined);
31
+ * ```
32
+ */
33
+ export const resolveAllocatorCapHeadroom = (value) => {
34
+ const headroom = value ?? DEFAULT_ALLOCATOR_CAP_HEADROOM;
35
+ if (headroom < 0n)
36
+ throw new NegativeInputError("allocatorCapHeadroom", headroom);
37
+ if (headroom > MathLib.WAD)
38
+ throw new InputExceedsMaxError({
39
+ field: "allocatorCapHeadroom",
40
+ value: headroom,
41
+ max: MathLib.WAD,
42
+ });
43
+ return headroom;
44
+ };
21
45
  /**
22
46
  * Resolves and validates a source withdrawal utilization ceiling.
23
47
  * @internal
@@ -70,8 +70,7 @@ export declare const validateMidnightMarketChainId: (market: MidnightMarketInput
70
70
  * the provided user address.
71
71
  *
72
72
  * Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which
73
- * backs the permit, Permit2, Blue authorization, and Midnight offer-root
74
- * signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
73
+ * backs the permit, Permit2, and Blue authorization signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
75
74
  * signer: the signing flow is
76
75
  * the only path where an account/address mismatch is a real security concern
77
76
  * (rather than just an integrator footgun).
@@ -163,6 +162,48 @@ export declare const validateChainId: (clientChainId: number | undefined, expect
163
162
  * @throws {NativeAmountOnNonWNativeAssetError} if the asset is not wNative.
164
163
  */
165
164
  export declare const validateNativeAsset: (chainId: number, asset: Address) => void;
165
+ /**
166
+ * Validates native ETH funding against the wNative tokens pulled by a MidnightBundlesV2 action.
167
+ *
168
+ * @param params.chainId - Chain used to resolve wNative.
169
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
170
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
171
+ * maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
172
+ * the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
173
+ * for the full pulled amount.
174
+ * @param params.pulls - Token pulls performed by the bundle action.
175
+ * @returns The transaction `value` and the `wrappedNative` contract argument.
176
+ * @throws {NegativeInputError} when `nativeAmount` is negative.
177
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
178
+ * @throws {NativeAmountOnNonWNativeAssetError} when pulls are non-empty and none use wNative.
179
+ * @throws {InputExceedsMaxError} when `nativeAmount` exceeds the maximum wNative pull, including
180
+ * when the call pulls none.
181
+ * @example
182
+ * ```ts
183
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
184
+ * import { validateMidnightNativeAmount } from "@morpho-org/morpho-sdk";
185
+ *
186
+ * const wNative = getChainAddress(8453, "wNative");
187
+ * const funding = validateMidnightNativeAmount({
188
+ * chainId: 8453,
189
+ * nativeAmount: 1_000n,
190
+ * pulls: [{ token: wNative, assets: 2_000n }],
191
+ * });
192
+ * funding.value; // 1_000n
193
+ * funding.wrappedNative; // wNative
194
+ * ```
195
+ */
196
+ export declare const validateMidnightNativeAmount: (params: {
197
+ readonly chainId: number;
198
+ readonly nativeAmount?: bigint;
199
+ readonly pulls: readonly {
200
+ readonly token: Address;
201
+ readonly assets: bigint;
202
+ }[];
203
+ }) => {
204
+ value: bigint;
205
+ wrappedNative: Address;
206
+ };
166
207
  /** @internal Validates native funding against a vault's wrapped-native asset. */
167
208
  export declare const validateNativeVaultAsset: (chainId: number, vaultAsset: Address) => void;
168
209
  /**
@@ -105,8 +105,7 @@ export const validateMidnightMarketChainId = (market, chainId) => {
105
105
  * the provided user address.
106
106
  *
107
107
  * Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which
108
- * backs the permit, Permit2, Blue authorization, and Midnight offer-root
109
- * signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
108
+ * backs the permit, Permit2, and Blue authorization signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
110
109
  * signer: the signing flow is
111
110
  * the only path where an account/address mismatch is a real security concern
112
111
  * (rather than just an integrator footgun).
@@ -230,6 +229,63 @@ export const validateNativeAsset = (chainId, asset) => {
230
229
  throw new NativeAmountOnNonWNativeAssetError(asset, wNative);
231
230
  }
232
231
  };
232
+ /**
233
+ * Validates native ETH funding against the wNative tokens pulled by a MidnightBundlesV2 action.
234
+ *
235
+ * @param params.chainId - Chain used to resolve wNative.
236
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
237
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
238
+ * maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
239
+ * the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
240
+ * for the full pulled amount.
241
+ * @param params.pulls - Token pulls performed by the bundle action.
242
+ * @returns The transaction `value` and the `wrappedNative` contract argument.
243
+ * @throws {NegativeInputError} when `nativeAmount` is negative.
244
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
245
+ * @throws {NativeAmountOnNonWNativeAssetError} when pulls are non-empty and none use wNative.
246
+ * @throws {InputExceedsMaxError} when `nativeAmount` exceeds the maximum wNative pull, including
247
+ * when the call pulls none.
248
+ * @example
249
+ * ```ts
250
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
251
+ * import { validateMidnightNativeAmount } from "@morpho-org/morpho-sdk";
252
+ *
253
+ * const wNative = getChainAddress(8453, "wNative");
254
+ * const funding = validateMidnightNativeAmount({
255
+ * chainId: 8453,
256
+ * nativeAmount: 1_000n,
257
+ * pulls: [{ token: wNative, assets: 2_000n }],
258
+ * });
259
+ * funding.value; // 1_000n
260
+ * funding.wrappedNative; // wNative
261
+ * ```
262
+ */
263
+ export const validateMidnightNativeAmount = (params) => {
264
+ const { nativeAmount, chainId, pulls } = params;
265
+ if (nativeAmount === undefined || nativeAmount === 0n) {
266
+ return { value: 0n, wrappedNative: zeroAddress };
267
+ }
268
+ if (nativeAmount < 0n) {
269
+ throw new NegativeInputError("nativeAmount", nativeAmount);
270
+ }
271
+ const { wNative } = getChainAddresses(chainId);
272
+ if (!isDefined(wNative)) {
273
+ throw new ChainWNativeMissingError(chainId);
274
+ }
275
+ const wNativePulled = pulls.reduce((total, pull) => isAddressEqual(pull.token, wNative) ? total + pull.assets : total, 0n);
276
+ const firstPull = pulls[0];
277
+ if (firstPull && !pulls.some((pull) => isAddressEqual(pull.token, wNative))) {
278
+ throw new NativeAmountOnNonWNativeAssetError(firstPull.token, wNative);
279
+ }
280
+ if (nativeAmount > wNativePulled) {
281
+ throw new InputExceedsMaxError({
282
+ field: "nativeAmount",
283
+ value: nativeAmount,
284
+ max: wNativePulled,
285
+ });
286
+ }
287
+ return { value: nativeAmount, wrappedNative: wNative };
288
+ };
233
289
  /** @internal Validates native funding against a vault's wrapped-native asset. */
234
290
  export const validateNativeVaultAsset = (chainId, vaultAsset) => {
235
291
  const { wNative } = getChainAddresses(chainId);
@@ -5,7 +5,7 @@ import { type Address } from "viem";
5
5
  * @param params - Authorization target validation parameters.
6
6
  * @param params.chainId - Chain id used to resolve supported Midnight operators.
7
7
  * @param params.authorized - Operator address receiving authorization.
8
- * @returns Nothing after the operator matches MidnightBundles or a supported ratifier.
8
+ * @returns Nothing after the operator matches MidnightBundlesV2.
9
9
  * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
10
10
  * @internal
11
11
  */
@@ -7,17 +7,13 @@ import { UnsupportedMidnightAuthorizationTargetError } from "../types/index.js";
7
7
  * @param params - Authorization target validation parameters.
8
8
  * @param params.chainId - Chain id used to resolve supported Midnight operators.
9
9
  * @param params.authorized - Operator address receiving authorization.
10
- * @returns Nothing after the operator matches MidnightBundles or a supported ratifier.
10
+ * @returns Nothing after the operator matches MidnightBundlesV2.
11
11
  * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
12
12
  * @internal
13
13
  */
14
14
  export const validateMidnightAuthorizationTarget = (params) => {
15
- const { midnightBundles, ecrecoverRatifier, setterRatifier } = getChainAddresses(params.chainId);
16
- const supportedTargets = [
17
- midnightBundles,
18
- ecrecoverRatifier,
19
- setterRatifier,
20
- ].filter((target) => target != null);
15
+ const { midnightBundlesV2 } = getChainAddresses(params.chainId);
16
+ const supportedTargets = midnightBundlesV2 == null ? [] : [midnightBundlesV2];
21
17
  if (!supportedTargets.some((supported) => isAddressEqual(params.authorized, supported))) {
22
18
  throw new UnsupportedMidnightAuthorizationTargetError({
23
19
  authorized: params.authorized,
@@ -1,6 +1,6 @@
1
1
  import { type Address } from "@morpho-org/blue-sdk";
2
2
  /** Supported spender slots that can be validated against the chain address registry. */
3
- export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
3
+ export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundlesV2" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
4
4
  /**
5
5
  * Validates that a requirement encoder spender matches one of the allowed chain addresses.
6
6
  *
@@ -18,8 +18,8 @@ export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundles" |
18
18
  *
19
19
  * validateRequirementSpender({
20
20
  * chainId: 8453,
21
- * spender: getChainAddress(8453, "midnightBundles"),
22
- * allowed: ["midnightBundles"],
21
+ * spender: getChainAddress(8453, "midnight"),
22
+ * allowed: ["midnight"],
23
23
  * });
24
24
  * ```
25
25
  */
@@ -18,17 +18,17 @@ import { UnsupportedErc20ApprovalSpenderError } from "../types/index.js";
18
18
  *
19
19
  * validateRequirementSpender({
20
20
  * chainId: 8453,
21
- * spender: getChainAddress(8453, "midnightBundles"),
22
- * allowed: ["midnightBundles"],
21
+ * spender: getChainAddress(8453, "midnight"),
22
+ * allowed: ["midnight"],
23
23
  * });
24
24
  * ```
25
25
  */
26
26
  export const validateRequirementSpender = (params) => {
27
- const { permit2, midnight, midnightBundles, bundles } = getChainAddresses(params.chainId);
27
+ const { permit2, midnight, midnightBundlesV2, bundles } = getChainAddresses(params.chainId);
28
28
  const addresses = {
29
29
  permit2,
30
30
  midnight,
31
- midnightBundles,
31
+ midnightBundlesV2,
32
32
  vaultExitBundlesV1: bundles?.vaultExitBundlesV1,
33
33
  vaultBundlesV1: bundles?.vaultBundlesV1,
34
34
  blueBundlesV1: bundles?.blueBundlesV1,
@@ -40,7 +40,6 @@ export const validateRequirementSpender = (params) => {
40
40
  chainId: params.chainId,
41
41
  permit2,
42
42
  midnight,
43
- midnightBundles,
44
43
  supportedSpenders,
45
44
  });
46
45
  }
@@ -1 +1 @@
1
- export { ecrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
1
+ export { blueBuyCallbackFactoryAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
@@ -1 +1 @@
1
- export { ecrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
1
+ export { blueBuyCallbackFactoryAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
@@ -1 +1 @@
1
- export type { BuildFixedRateOfferChainParams, DecodedEcrecoverRatifierData, DecodedPriceRatifierV1Data, DecodedRateRatifierV1Data, DecodedSetterRatifierData, DeploylessFetchParameters, EcrecoverRatificationTypedData, EcrecoverRatifierDataDigestParams, EcrecoverRatifierDataParams, EcrecoverRatifierDataRequest, EcrecoverRatifierDataVerificationParams, EcrecoverRatifierRatifyParams, EcrecoverRatifierRatifyRequest, EcrecoverRatifierRootDigestParams, EcrecoverRatifierSignRequest, EcrecoverRatifierTypedDataParams, EcrecoverRatifierTypedDataRequest, EcrecoverSignatureInput, FixedRateOfferChainLeg, GetRatifierInfoParams, MidnightCallParameters, MidnightFetchParams, PriceRatifierV1Leaf, PriceRatifierV1LeafStruct, PriceRatifierV1TreeDescriptor, PriceRatifierV1TreeInput, RateRatifierV1Leaf, RateRatifierV1LeafStruct, RateRatifierV1TreeDescriptor, RateRatifierV1TreeInput, RatifierInfo, SetterRatifierDataParams, SetterRatifierDataRequest, SetterRatifierDataVerificationParams, SetterRatifierRatifyRequest, VerifiedEcrecoverRatifierData, } from "@morpho-org/midnight-sdk";
1
+ export type { BuildFixedRateOfferChainParams, CollateralTransfer, DecodedEcrecoverRatifierData, DecodedPriceRatifierV1Data, DecodedRateRatifierV1Data, DecodedSetterRatifierData, DeploylessFetchParameters, EcrecoverRatificationTypedData, EcrecoverRatifierDataDigestParams, EcrecoverRatifierDataParams, EcrecoverRatifierDataRequest, EcrecoverRatifierDataVerificationParams, EcrecoverRatifierRatifyParams, EcrecoverRatifierRatifyRequest, EcrecoverRatifierRootDigestParams, EcrecoverRatifierSignRequest, EcrecoverRatifierTypedDataParams, EcrecoverRatifierTypedDataRequest, EcrecoverSignatureInput, FixedRateOfferChainLeg, GetRatifierInfoParams, GroupCancellation, MidnightCallParameters, MidnightFetchParams, PriceRatifierV1Leaf, PriceRatifierV1LeafStruct, PriceRatifierV1TreeDescriptor, PriceRatifierV1TreeInput, RateRatifierV1Leaf, RateRatifierV1LeafStruct, RateRatifierV1TreeDescriptor, RateRatifierV1TreeInput, RatifierInfo, SetterRatifierDataParams, SetterRatifierDataRequest, SetterRatifierDataVerificationParams, SetterRatifierRatifyRequest, VerifiedEcrecoverRatifierData, } from "@morpho-org/midnight-sdk";