@morpho-org/morpho-sdk 10.4.0 → 10.5.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 (221) hide show
  1. package/lib/cjs/abis.d.ts +1 -1
  2. package/lib/cjs/abis.js +5 -1
  3. package/lib/cjs/actions/blue/common.js +12 -3
  4. package/lib/cjs/blue/abis.d.ts +1 -1
  5. package/lib/cjs/blue/abis.js +5 -1
  6. package/lib/cjs/blue/entities.d.ts +4 -4
  7. package/lib/cjs/blue/entities.js +3 -1
  8. package/lib/cjs/blue/errors.d.ts +2 -2
  9. package/lib/cjs/blue/errors.js +5 -1
  10. package/lib/cjs/blue/fetch.d.ts +2 -2
  11. package/lib/cjs/blue/fetch.js +3 -1
  12. package/lib/cjs/blue/utils.d.ts +1 -1
  13. package/lib/cjs/blue/utils.js +2 -1
  14. package/lib/cjs/entities/index.d.ts +4 -4
  15. package/lib/cjs/entities/index.js +3 -1
  16. package/lib/cjs/entities/midnight/midnight.d.ts +100 -103
  17. package/lib/cjs/entities/midnight/midnight.js +99 -99
  18. package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
  19. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
  20. package/lib/cjs/entities/vaultV2/vaultV2.js +39 -2
  21. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -2
  22. package/lib/cjs/entities/vaultV2BlueReallocationData.js +6 -2
  23. package/lib/cjs/errors.d.ts +4 -4
  24. package/lib/cjs/errors.js +7 -5
  25. package/lib/cjs/fetch.d.ts +2 -2
  26. package/lib/cjs/fetch.js +3 -1
  27. package/lib/cjs/helpers/deadShares.js +3 -0
  28. package/lib/cjs/helpers/validate.d.ts +11 -1
  29. package/lib/cjs/midnight/errors.d.ts +2 -1
  30. package/lib/cjs/midnight/errors.js +5 -4
  31. package/lib/cjs/transactionPlan/assemble.d.ts +24 -0
  32. package/lib/cjs/transactionPlan/assemble.js +25 -0
  33. package/lib/cjs/transactionPlan/blue/borrow.js +14 -64
  34. package/lib/cjs/transactionPlan/blue/refinance.js +9 -11
  35. package/lib/cjs/transactionPlan/blue/repay.js +10 -24
  36. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +49 -45
  37. package/lib/cjs/transactionPlan/blue/stored.d.ts +26 -0
  38. package/lib/cjs/transactionPlan/blue/stored.js +87 -0
  39. package/lib/cjs/transactionPlan/blue/supply.js +7 -22
  40. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  41. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +10 -15
  42. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +14 -64
  43. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -3
  44. package/lib/cjs/transactionPlan/blue/withdraw.js +67 -79
  45. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  46. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +31 -30
  47. package/lib/cjs/transactionPlan/deposit.js +4 -7
  48. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  49. package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +1 -1
  50. package/lib/cjs/transactionPlan/midnight/makeBorrow.js +1 -1
  51. package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +1 -1
  52. package/lib/cjs/transactionPlan/midnight/makeLend.js +1 -1
  53. package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +1 -1
  54. package/lib/cjs/transactionPlan/midnight/makeRepay.js +1 -1
  55. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
  56. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
  57. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
  58. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
  59. package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
  60. package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +1 -1
  61. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
  62. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
  63. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
  64. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
  65. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
  66. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
  67. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +2 -2
  68. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +2 -2
  69. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  70. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
  71. package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
  72. package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +1 -1
  73. package/lib/cjs/transactionPlan/permit.d.ts +15 -2
  74. package/lib/cjs/transactionPlan/permit.js +26 -68
  75. package/lib/cjs/transactionPlan/plan.d.ts +51 -1
  76. package/lib/cjs/transactionPlan/plan.js +56 -13
  77. package/lib/cjs/transactionPlan/redeem.js +4 -7
  78. package/lib/cjs/transactionPlan/types.d.ts +4 -3
  79. package/lib/cjs/transactionPlan/vaultBinding.d.ts +29 -0
  80. package/lib/cjs/transactionPlan/vaultBinding.js +69 -0
  81. package/lib/cjs/transactionPlan/vaultRequirements.d.ts +20 -0
  82. package/lib/cjs/transactionPlan/vaultRequirements.js +37 -0
  83. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -1
  84. package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -13
  85. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  86. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +10 -41
  87. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  88. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +6 -18
  89. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -12
  90. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  91. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -13
  92. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -1
  93. package/lib/cjs/transactionPlan/vaultv2/deposit.js +2 -13
  94. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  95. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +4 -7
  96. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  97. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +12 -42
  98. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  99. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +10 -41
  100. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -1
  101. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -13
  102. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  103. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -13
  104. package/lib/cjs/transactionPlan/withdraw.js +4 -7
  105. package/lib/cjs/types/error.d.ts +2 -1
  106. package/lib/cjs/types/error.js +3 -2
  107. package/lib/cjs/utils.d.ts +2 -2
  108. package/lib/cjs/utils.js +4 -2
  109. package/lib/cjs/version.d.ts +1 -1
  110. package/lib/cjs/version.js +1 -1
  111. package/lib/esm/abis.d.ts +1 -1
  112. package/lib/esm/abis.js +1 -1
  113. package/lib/esm/actions/blue/common.js +13 -4
  114. package/lib/esm/blue/abis.d.ts +1 -1
  115. package/lib/esm/blue/abis.js +1 -1
  116. package/lib/esm/blue/entities.d.ts +4 -4
  117. package/lib/esm/blue/entities.js +2 -2
  118. package/lib/esm/blue/errors.d.ts +2 -2
  119. package/lib/esm/blue/errors.js +2 -2
  120. package/lib/esm/blue/fetch.d.ts +2 -2
  121. package/lib/esm/blue/fetch.js +2 -2
  122. package/lib/esm/blue/utils.d.ts +1 -1
  123. package/lib/esm/blue/utils.js +1 -1
  124. package/lib/esm/entities/index.d.ts +4 -4
  125. package/lib/esm/entities/index.js +2 -2
  126. package/lib/esm/entities/midnight/midnight.d.ts +100 -103
  127. package/lib/esm/entities/midnight/midnight.js +99 -99
  128. package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
  129. package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
  130. package/lib/esm/entities/vaultV2/vaultV2.js +40 -3
  131. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -2
  132. package/lib/esm/entities/vaultV2BlueReallocationData.js +6 -2
  133. package/lib/esm/errors.d.ts +4 -4
  134. package/lib/esm/errors.js +4 -4
  135. package/lib/esm/fetch.d.ts +2 -2
  136. package/lib/esm/fetch.js +2 -2
  137. package/lib/esm/helpers/deadShares.js +4 -1
  138. package/lib/esm/helpers/validate.d.ts +11 -1
  139. package/lib/esm/midnight/errors.d.ts +2 -1
  140. package/lib/esm/midnight/errors.js +2 -1
  141. package/lib/esm/transactionPlan/assemble.d.ts +24 -0
  142. package/lib/esm/transactionPlan/assemble.js +21 -0
  143. package/lib/esm/transactionPlan/blue/borrow.js +15 -65
  144. package/lib/esm/transactionPlan/blue/refinance.js +10 -12
  145. package/lib/esm/transactionPlan/blue/repay.js +11 -25
  146. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +50 -46
  147. package/lib/esm/transactionPlan/blue/stored.d.ts +26 -0
  148. package/lib/esm/transactionPlan/blue/stored.js +80 -0
  149. package/lib/esm/transactionPlan/blue/supply.js +7 -22
  150. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  151. package/lib/esm/transactionPlan/blue/supplyCollateral.js +10 -15
  152. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +15 -65
  153. package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -3
  154. package/lib/esm/transactionPlan/blue/withdraw.js +70 -82
  155. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  156. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +32 -31
  157. package/lib/esm/transactionPlan/deposit.js +5 -8
  158. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  159. package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +1 -1
  160. package/lib/esm/transactionPlan/midnight/makeBorrow.js +1 -1
  161. package/lib/esm/transactionPlan/midnight/makeLend.d.ts +1 -1
  162. package/lib/esm/transactionPlan/midnight/makeLend.js +1 -1
  163. package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +1 -1
  164. package/lib/esm/transactionPlan/midnight/makeRepay.js +1 -1
  165. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
  166. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
  167. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
  168. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
  169. package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
  170. package/lib/esm/transactionPlan/midnight/supplyCollateral.js +1 -1
  171. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
  172. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
  173. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
  174. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
  175. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
  176. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
  177. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +2 -2
  178. package/lib/esm/transactionPlan/midnight/takeBorrow.js +2 -2
  179. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  180. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
  181. package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
  182. package/lib/esm/transactionPlan/midnight/takeWithdraw.js +1 -1
  183. package/lib/esm/transactionPlan/permit.d.ts +15 -2
  184. package/lib/esm/transactionPlan/permit.js +25 -68
  185. package/lib/esm/transactionPlan/plan.d.ts +51 -1
  186. package/lib/esm/transactionPlan/plan.js +55 -13
  187. package/lib/esm/transactionPlan/redeem.js +5 -8
  188. package/lib/esm/transactionPlan/types.d.ts +4 -3
  189. package/lib/esm/transactionPlan/vaultBinding.d.ts +29 -0
  190. package/lib/esm/transactionPlan/vaultBinding.js +65 -0
  191. package/lib/esm/transactionPlan/vaultRequirements.d.ts +20 -0
  192. package/lib/esm/transactionPlan/vaultRequirements.js +34 -0
  193. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -1
  194. package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -14
  195. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  196. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +12 -43
  197. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  198. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +9 -21
  199. package/lib/esm/transactionPlan/vaultv1/redeem.js +2 -13
  200. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  201. package/lib/esm/transactionPlan/vaultv1/withdraw.js +3 -14
  202. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -1
  203. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -14
  204. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  205. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +5 -8
  206. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  207. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +15 -45
  208. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  209. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +12 -43
  210. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -1
  211. package/lib/esm/transactionPlan/vaultv2/redeem.js +3 -14
  212. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  213. package/lib/esm/transactionPlan/vaultv2/withdraw.js +3 -14
  214. package/lib/esm/transactionPlan/withdraw.js +5 -8
  215. package/lib/esm/types/error.d.ts +2 -1
  216. package/lib/esm/types/error.js +3 -2
  217. package/lib/esm/utils.d.ts +2 -2
  218. package/lib/esm/utils.js +2 -2
  219. package/lib/esm/version.d.ts +1 -1
  220. package/lib/esm/version.js +1 -1
  221. package/package.json +7 -7
@@ -48,7 +48,7 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
48
48
  * @param params.supportSignature - Optional Morpho authorization signature preference, defaulting to `false`; otherwise prepares a direct authorization transaction when needed.
49
49
  * @param params.now - Optional reference timestamp in Unix seconds, normally the latest block timestamp; defaults to the device clock.
50
50
  * @param params.expiresAt - Optional safe-integer Unix expiry later than `now`; defaults to `now + 2h` and governs every deadline.
51
- * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to every built transaction.
51
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to the action transaction's calldata; approval and authorization steps carry none.
52
52
  * @param params.deployless - Optional shared intent field; unused because this operation reads no token metadata or allowances.
53
53
  * @returns A deep-frozen, data-only `TransactionPlan` with chain, account, expiry, withdrawal step,
54
54
  * and any preceding Morpho authorization step and signature request. The caller signs; the SDK never does.
@@ -74,7 +74,6 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
74
74
  * @throws {viem.BaseError} when a contract-code, chain ID, authorization or nonce RPC read fails.
75
75
  * @example
76
76
  * ```ts
77
- * import assert from "node:assert/strict";
78
77
  * import { markets } from "@morpho-org/morpho-test";
79
78
  * import { fetchAccrualPosition } from "@morpho-org/morpho-sdk/blue/fetch";
80
79
  * import {
@@ -89,7 +88,7 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
89
88
  * if (!ethereum) throw new Error("Install an Ethereum wallet to continue.");
90
89
  * const wallet = createWalletClient({ chain: mainnet, transport: custom(ethereum) });
91
90
  * const [account] = await wallet.requestAddresses();
92
- * assert(account, "Connect a wallet holding collateral in this market.");
91
+ * if (!account) throw new Error("Connect a wallet holding collateral in this market.");
93
92
  * const market = markets[mainnet.id].usdc_wbtc;
94
93
  * const position = await fetchAccrualPosition(account, market.id, client);
95
94
  * const plan = await prepareBlueWithdrawCollateral(client, {
@@ -1,15 +1,17 @@
1
1
  import { AccrualPosition, MarketParams, MathLib, } from "@morpho-org/blue-sdk";
2
- import { deepFreeze, Time } from "@morpho-org/morpho-ts";
2
+ import { Time } from "@morpho-org/morpho-ts";
3
3
  import { blueWithdrawCollateral } from "../../actions/blue/withdrawCollateral.js";
4
4
  import { normalizeBundlesCommonParams } from "../../actions/bundles/common.js";
5
5
  import { DEFAULT_LLTV_BUFFER } from "../../helpers/constant.js";
6
6
  import { getBlueBundlesV1QuoteTimestamp } from "../../helpers/getBlueBundlesV1QuoteTimestamp.js";
7
7
  import { validatePositionHealthAfterWithdraw, validateUint256Field, } from "../../helpers/validate.js";
8
8
  import { NonPositiveInputError, } from "../../types/index.js";
9
+ import { freezePlan, planHeader } from "../assemble.js";
9
10
  import { IncompleteTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
10
11
  import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
11
12
  import { validateMorphoAuthorizationRequest } from "./authorization.js";
12
13
  import { prepareBlue, } from "./prepare.js";
14
+ import { BUNDLES_COMMON_FIELDS, signatureRoles, validateStoredBlueMarketParams, } from "./stored.js";
13
15
  /**
14
16
  * Prepares a BlueBundlesV1 collateral withdrawal with direct or inline signed Morpho authorization.
15
17
  * Health uses the expiry floored at max(now, lastUpdate), with the entity's LLTV buffer.
@@ -30,7 +32,7 @@ import { prepareBlue, } from "./prepare.js";
30
32
  * @param params.supportSignature - Optional Morpho authorization signature preference, defaulting to `false`; otherwise prepares a direct authorization transaction when needed.
31
33
  * @param params.now - Optional reference timestamp in Unix seconds, normally the latest block timestamp; defaults to the device clock.
32
34
  * @param params.expiresAt - Optional safe-integer Unix expiry later than `now`; defaults to `now + 2h` and governs every deadline.
33
- * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to every built transaction.
35
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to the action transaction's calldata; approval and authorization steps carry none.
34
36
  * @param params.deployless - Optional shared intent field; unused because this operation reads no token metadata or allowances.
35
37
  * @returns A deep-frozen, data-only `TransactionPlan` with chain, account, expiry, withdrawal step,
36
38
  * and any preceding Morpho authorization step and signature request. The caller signs; the SDK never does.
@@ -56,7 +58,6 @@ import { prepareBlue, } from "./prepare.js";
56
58
  * @throws {viem.BaseError} when a contract-code, chain ID, authorization or nonce RPC read fails.
57
59
  * @example
58
60
  * ```ts
59
- * import assert from "node:assert/strict";
60
61
  * import { markets } from "@morpho-org/morpho-test";
61
62
  * import { fetchAccrualPosition } from "@morpho-org/morpho-sdk/blue/fetch";
62
63
  * import {
@@ -71,7 +72,7 @@ import { prepareBlue, } from "./prepare.js";
71
72
  * if (!ethereum) throw new Error("Install an Ethereum wallet to continue.");
72
73
  * const wallet = createWalletClient({ chain: mainnet, transport: custom(ethereum) });
73
74
  * const [account] = await wallet.requestAddresses();
74
- * assert(account, "Connect a wallet holding collateral in this market.");
75
+ * if (!account) throw new Error("Connect a wallet holding collateral in this market.");
75
76
  * const market = markets[mainnet.id].usdc_wbtc;
76
77
  * const position = await fetchAccrualPosition(account, market.id, client);
77
78
  * const plan = await prepareBlueWithdrawCollateral(client, {
@@ -92,10 +93,25 @@ import { prepareBlue, } from "./prepare.js";
92
93
  */
93
94
  export async function prepareBlueWithdrawCollateral(client, params) {
94
95
  const now = params.now ?? Time.timestamp();
95
- const { chainId, account, collateralAssets, marketId } = params;
96
- const { loanToken, collateralToken, oracle, irm, lltv } = params.marketData.market.params;
96
+ const { chainId, account, collateralAssets, marketId, marketData, positionData, expiresAt, supportSignature, referralFee, calldataOrigin, deployless, } = params;
97
+ const { loanToken, collateralToken, oracle, irm, lltv } = marketData.market.params;
97
98
  const marketParams = { loanToken, collateralToken, oracle, irm, lltv };
98
- const { intent, steps, signatureRequests, morphoAuthorizationRequestId } = await prepareBlue({ client, params: { ...params, now } }, (resolvedIntent) => {
99
+ const { intent, steps, signatureRequests, morphoAuthorizationRequestId } = await prepareBlue({
100
+ client,
101
+ params: {
102
+ chainId,
103
+ account,
104
+ marketId,
105
+ marketData,
106
+ positionData,
107
+ now,
108
+ expiresAt,
109
+ supportSignature,
110
+ referralFee,
111
+ calldataOrigin,
112
+ deployless,
113
+ },
114
+ }, (resolvedIntent) => {
99
115
  // Reject invalid fees and deadlines before authorization reads.
100
116
  normalizeBundlesCommonParams(resolvedIntent);
101
117
  if (collateralAssets <= 0n) {
@@ -103,7 +119,7 @@ export async function prepareBlueWithdrawCollateral(client, params) {
103
119
  }
104
120
  // Reject amounts outside the ABI range before reading authorization state.
105
121
  validateUint256Field("collateralAssets", collateralAssets);
106
- const position = params.positionData.position;
122
+ const { position } = positionData;
107
123
  // Validate health against the same accrual horizon used by the existing handle.
108
124
  validatePositionHealthAfterWithdraw({
109
125
  positionData: position.borrowShares === 0n
@@ -119,12 +135,8 @@ export async function prepareBlueWithdrawCollateral(client, params) {
119
135
  });
120
136
  return { id: "blueWithdrawCollateral", needsAuthorization: true };
121
137
  });
122
- return deepFreeze({
123
- version: 2,
124
- chainId,
125
- account,
126
- expiresAt: intent.expiresAt,
127
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
138
+ return freezePlan({
139
+ ...planHeader({ chainId, account }, intent),
128
140
  steps: [
129
141
  ...steps,
130
142
  {
@@ -132,9 +144,9 @@ export async function prepareBlueWithdrawCollateral(client, params) {
132
144
  label: "Withdraw Blue collateral",
133
145
  action: {
134
146
  type: "blueWithdrawCollateral",
135
- signatureRequestIds: morphoAuthorizationRequestId === undefined
136
- ? {}
137
- : { morphoAuthorization: morphoAuthorizationRequestId },
147
+ signatureRequestIds: signatureRoles({
148
+ morphoAuthorization: morphoAuthorizationRequestId,
149
+ }),
138
150
  inputs: {
139
151
  chainId,
140
152
  account,
@@ -152,7 +164,7 @@ export async function prepareBlueWithdrawCollateral(client, params) {
152
164
  },
153
165
  ],
154
166
  signatureRequests,
155
- });
167
+ }, { detach: false });
156
168
  }
157
169
  /** @internal Binds an inline authorization to the collateral withdrawal that consumes it. */
158
170
  export function validateBlueWithdrawCollateralAuthorizationRequest(request, action) {
@@ -230,19 +242,8 @@ export function validateBlueWithdrawCollateralPlanAction(action, path) {
230
242
  fields: {
231
243
  collateralAssets: "uint256 bigint",
232
244
  maxLtv: "uint256 bigint",
233
- deadline: "uint256 bigint",
234
- referralFeePct: "uint256 bigint",
235
- referralFeeRecipient: "address",
236
- },
237
- });
238
- validatePlanFields(getPlanObject(inputs.marketParams, `${path}.inputs.marketParams`), {
239
- path: `${path}.inputs.marketParams`,
240
- fields: {
241
- loanToken: "address",
242
- collateralToken: "address",
243
- oracle: "address",
244
- irm: "address",
245
- lltv: "uint256 bigint",
245
+ ...BUNDLES_COMMON_FIELDS,
246
246
  },
247
247
  });
248
+ validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
248
249
  }
@@ -1,11 +1,12 @@
1
1
  import { DEFAULT_SLIPPAGE_TOLERANCE, } from "@morpho-org/blue-sdk";
2
- import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
2
+ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
3
3
  import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, } from "../actions/bundles/common.js";
4
4
  import { validateClientChainId } from "../actions/requirements/validateClientChainId.js";
5
5
  import { assertRegistryTargetsHaveCode } from "../entities/requirements/assertContractCode.js";
6
6
  import { computeVaultMaxSharePrice } from "../helpers/index.js";
7
7
  import { validateNativeVaultAsset, validateReferenceTime, validateSlippageTolerance, validateUint256Field, validateVaultDepositDeadline, } from "../helpers/validate.js";
8
8
  import { NonPositiveInputError, } from "../types/index.js";
9
+ import { freezePlan, planHeader } from "./assemble.js";
9
10
  import { InvalidTransactionPlanError } from "./error.js";
10
11
  import { resolveIntent } from "./intent.js";
11
12
  import { getTokenRequirements } from "./requirements.js";
@@ -95,12 +96,8 @@ export async function prepareVaultDeposit(client, params) {
95
96
  ]);
96
97
  const approvals = requirements?.approvals ?? [];
97
98
  const signatureRequests = requirements?.permit === undefined ? [] : [requirements.permit];
98
- return deepFreeze(structuredClone({
99
- version: 2,
100
- account,
101
- chainId,
102
- expiresAt: intent.expiresAt,
103
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
99
+ return freezePlan({
100
+ ...planHeader({ chainId, account }, intent),
104
101
  steps: [
105
102
  ...approvals,
106
103
  {
@@ -124,5 +121,5 @@ export async function prepareVaultDeposit(client, params) {
124
121
  },
125
122
  ],
126
123
  signatureRequests,
127
- }));
124
+ }, { detach: true });
128
125
  }
@@ -29,7 +29,7 @@ export interface IntentParams {
29
29
  readonly supportSignature?: boolean;
30
30
  /** Unix seconds. Defaults to two hours from now. */
31
31
  readonly expiresAt?: number;
32
- /** Optional attribution bytes (at most 1 MiB) appended verbatim to every built transaction's calldata. */
32
+ /** Optional attribution bytes (at most 1 MiB) appended verbatim to the action transaction's calldata; ERC-20 approval, Morpho authorization and Midnight authorization steps carry none. */
33
33
  readonly calldataOrigin?: Hex;
34
34
  /** Whether token metadata reads for permits may use deployless aggregation. */
35
35
  readonly deployless?: boolean;
@@ -28,7 +28,7 @@ export type MidnightMakeBorrowPlanParams = MidnightMakerPublicationPlanParams;
28
28
  * Omitting it cancels nothing (an untyped JavaScript `null` does too).
29
29
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
30
30
  * @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
31
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
31
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
32
32
  * @returns A frozen plan with persisted publication data that can be restored and built offline.
33
33
  * @throws {InvalidBigIntInputError} If a supplied non-null `now` or a cancellation ceiling is not a bigint; checked before any request.
34
34
  * @throws {ZeroAccountError} If the submitting account is zero.
@@ -24,7 +24,7 @@ import { parseMakeBorrowParams } from "./prepare.js";
24
24
  * Omitting it cancels nothing (an untyped JavaScript `null` does too).
25
25
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
26
26
  * @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
27
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
27
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
28
28
  * @returns A frozen plan with persisted publication data that can be restored and built offline.
29
29
  * @throws {InvalidBigIntInputError} If a supplied non-null `now` or a cancellation ceiling is not a bigint; checked before any request.
30
30
  * @throws {ZeroAccountError} If the submitting account is zero.
@@ -40,7 +40,7 @@ export interface MidnightMakeLendPlanParams extends MidnightMakerPublicationPlan
40
40
  * @param params.reservedLoanAssets - Optional loan assets reserved by other open groups, excluding cancelled groups; defaults to `0n`.
41
41
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
42
42
  * @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
43
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
43
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
44
44
  * @returns A frozen, signature-free plan whose publication payload can be built offline.
45
45
  * @throws {InvalidBigIntInputError} If `loanAssets`, a cancellation ceiling, or a supplied non-null `now`
46
46
  * or `reservedLoanAssets` is not a bigint; checked before any request.
@@ -30,7 +30,7 @@ import { parseMakeLendParams, parseMakeRepayParams } from "./prepare.js";
30
30
  * @param params.reservedLoanAssets - Optional loan assets reserved by other open groups, excluding cancelled groups; defaults to `0n`.
31
31
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
32
32
  * @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
33
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
33
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
34
34
  * @returns A frozen, signature-free plan whose publication payload can be built offline.
35
35
  * @throws {InvalidBigIntInputError} If `loanAssets`, a cancellation ceiling, or a supplied non-null `now`
36
36
  * or `reservedLoanAssets` is not a bigint; checked before any request.
@@ -36,7 +36,7 @@ export type MidnightMakeRepayPlanParams = MidnightMakeLendPlanParams;
36
36
  * @param params.reservedLoanAssets - Optional loan assets reserved by other open groups, excluding cancelled groups; defaults to `0n`.
37
37
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
38
38
  * @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the earliest offer expiry minus one second.
39
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
39
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
40
40
  * @returns A frozen, signature-free plan.
41
41
  * @throws {InvalidBigIntInputError} If `loanAssets`, a cancellation ceiling, or a supplied non-null `now`
42
42
  * or `reservedLoanAssets` is not a bigint; checked before any request.
@@ -28,7 +28,7 @@ import { prepareFundedMidnightMakerPublication, } from "./makeLend.js";
28
28
  * @param params.reservedLoanAssets - Optional loan assets reserved by other open groups, excluding cancelled groups; defaults to `0n`.
29
29
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
30
30
  * @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the earliest offer expiry minus one second.
31
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
31
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
32
32
  * @returns A frozen, signature-free plan.
33
33
  * @throws {InvalidBigIntInputError} If `loanAssets`, a cancellation ceiling, or a supplied non-null `now`
34
34
  * or `reservedLoanAssets` is not a bigint; checked before any request.
@@ -76,7 +76,7 @@ export interface MidnightRepayWithdrawCollateralPlanParams extends Pick<IntentPa
76
76
  * @param params.now - Reference time in Unix seconds, normally the latest block's timestamp.
77
77
  * omitting it uses the device clock (an untyped JavaScript `null` does too); that fallback is deprecated.
78
78
  * @param params.expiresAt - Bundle execution deadline in Unix seconds. Defaults to two hours after `now`.
79
- * @param params.calldataOrigin - Optional attribution bytes (at most 1 MiB) appended to each transaction's calldata.
79
+ * @param params.calldataOrigin - Optional attribution bytes (at most 1 MiB) appended to each operation transaction's calldata; approval and authorization steps carry none.
80
80
  * @returns A frozen plan with prerequisite calls first and no signature requests.
81
81
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, the active repayment amount or a withdrawal's `collateralIndex` or `assets` is not a bigint; checked before any request.
82
82
  * @throws {MarketIdMismatchError} If the position belongs to another market.
@@ -53,7 +53,7 @@ const actionId = "midnightRepayWithdrawCollateral";
53
53
  * @param params.now - Reference time in Unix seconds, normally the latest block's timestamp.
54
54
  * omitting it uses the device clock (an untyped JavaScript `null` does too); that fallback is deprecated.
55
55
  * @param params.expiresAt - Bundle execution deadline in Unix seconds. Defaults to two hours after `now`.
56
- * @param params.calldataOrigin - Optional attribution bytes (at most 1 MiB) appended to each transaction's calldata.
56
+ * @param params.calldataOrigin - Optional attribution bytes (at most 1 MiB) appended to each operation transaction's calldata; approval and authorization steps carry none.
57
57
  * @returns A frozen plan with prerequisite calls first and no signature requests.
58
58
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, the active repayment amount or a withdrawal's `collateralIndex` or `assets` is not a bigint; checked before any request.
59
59
  * @throws {MarketIdMismatchError} If the position belongs to another market.
@@ -56,7 +56,7 @@ export interface MidnightSupplyBlueMakeLendPlanParams extends MidnightMakerPubli
56
56
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
57
57
  * The share preview uses the pinned block's timestamp instead.
58
58
  * @param params.expiresAt - Unix seconds. Defaults to the earlier of now + 2 hours and one second before the first offer expiry.
59
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
59
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
60
60
  * @returns A frozen plan with opaque publication bytes, buildable without the tree or API.
61
61
  * @throws {InvalidBigIntInputError} If a supplied non-null `now` is not a bigint; checked first.
62
62
  * @throws {ZeroAccountError} If the submitting account is zero.
@@ -45,7 +45,7 @@ const actionId = "midnightSupplyBlueMakeLend";
45
45
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
46
46
  * The share preview uses the pinned block's timestamp instead.
47
47
  * @param params.expiresAt - Unix seconds. Defaults to the earlier of now + 2 hours and one second before the first offer expiry.
48
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
48
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
49
49
  * @returns A frozen plan with opaque publication bytes, buildable without the tree or API.
50
50
  * @throws {InvalidBigIntInputError} If a supplied non-null `now` is not a bigint; checked first.
51
51
  * @throws {ZeroAccountError} If the submitting account is zero.
@@ -39,7 +39,7 @@ export interface MidnightSupplyCollateralPlanParams extends Pick<IntentParams, "
39
39
  * @param params.collateralAssets - Positive collateral quantity in token base units.
40
40
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
41
41
  * @param params.expiresAt - Plan expiry in Unix seconds; defaults to two hours after `now`. Midnight does not enforce it onchain.
42
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
42
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
43
43
  * @returns A frozen plan whose steps must be submitted in order from `params.account`.
44
44
  * @throws {InvalidBigIntInputError} when a supplied non-null `now`, the collateral amount or the index
45
45
  * is not a bigint.
@@ -27,7 +27,7 @@ const actionId = "midnightSupplyCollateral";
27
27
  * @param params.collateralAssets - Positive collateral quantity in token base units.
28
28
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
29
29
  * @param params.expiresAt - Plan expiry in Unix seconds; defaults to two hours after `now`. Midnight does not enforce it onchain.
30
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
30
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
31
31
  * @returns A frozen plan whose steps must be submitted in order from `params.account`.
32
32
  * @throws {InvalidBigIntInputError} when a supplied non-null `now`, the collateral amount or the index
33
33
  * is not a bigint.
@@ -54,7 +54,7 @@ export interface MidnightSupplyCollateralBatchPlanParams extends Pick<IntentPara
54
54
  * @param params.collateralSupplies - Nonempty ordered supplies, one per collateral index.
55
55
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
56
56
  * @param params.expiresAt - Plan expiry in Unix seconds; defaults to two hours after `now`. Midnight does not enforce it onchain.
57
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
57
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
58
58
  * @returns A frozen plan whose approval steps, if any, precede the multicall step; send them in order from `params.account`.
59
59
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, or a supply's `collateralIndex` or `assets`, is not a bigint; checked before any request.
60
60
  * @throws {ZeroAccountError} If the account is the zero address.
@@ -37,7 +37,7 @@ const actionId = "midnightSupplyCollateralBatch";
37
37
  * @param params.collateralSupplies - Nonempty ordered supplies, one per collateral index.
38
38
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
39
39
  * @param params.expiresAt - Plan expiry in Unix seconds; defaults to two hours after `now`. Midnight does not enforce it onchain.
40
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
40
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
41
41
  * @returns A frozen plan whose approval steps, if any, precede the multicall step; send them in order from `params.account`.
42
42
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, or a supply's `collateralIndex` or `assets`, is not a bigint; checked before any request.
43
43
  * @throws {ZeroAccountError} If the account is the zero address.
@@ -42,7 +42,7 @@ export interface MidnightSupplyCollateralMakeBorrowPlanParams extends MidnightMa
42
42
  * @param params.nativeAmount - Optional native ETH in wei, capped by the wrapped-native collateral pull.
43
43
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
44
44
  * @param params.expiresAt - Unix seconds. The default is the earlier of now + 2 hours and the first offer expiry minus one second.
45
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
45
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
46
46
  * @returns A frozen plan that builds offline from saved steps and opaque offer payload bytes.
47
47
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, a cancellation ceiling, or a collateral
48
48
  * index or amount is not a bigint; checked before any request.
@@ -32,7 +32,7 @@ const actionId = "midnightSupplyCollateralMakeBorrow";
32
32
  * @param params.nativeAmount - Optional native ETH in wei, capped by the wrapped-native collateral pull.
33
33
  * @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
34
34
  * @param params.expiresAt - Unix seconds. The default is the earlier of now + 2 hours and the first offer expiry minus one second.
35
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
35
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
36
36
  * @returns A frozen plan that builds offline from saved steps and opaque offer payload bytes.
37
37
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, a cancellation ceiling, or a collateral
38
38
  * index or amount is not a bigint; checked before any request.
@@ -50,7 +50,7 @@ export interface MidnightSupplyCollateralWithNativePlanParams extends Pick<Inten
50
50
  * @param params.nativeAmount - Positive native funding in wei, at most `collateralAssets`; any rest is pulled as wNative.
51
51
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
52
52
  * @param params.expiresAt - Bundle execution deadline in Unix seconds; defaults to two hours after `now`.
53
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
53
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
54
54
  * @returns A frozen plan whose steps must be submitted in order from `params.account`.
55
55
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, the collateral amount or the index is not a bigint; checked before any request.
56
56
  * @throws {ZeroAccountError} If the account is the zero address.
@@ -35,7 +35,7 @@ const actionId = "midnightSupplyCollateralWithNative";
35
35
  * @param params.nativeAmount - Positive native funding in wei, at most `collateralAssets`; any rest is pulled as wNative.
36
36
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
37
37
  * @param params.expiresAt - Bundle execution deadline in Unix seconds; defaults to two hours after `now`.
38
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
38
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
39
39
  * @returns A frozen plan whose steps must be submitted in order from `params.account`.
40
40
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, the collateral amount or the index is not a bigint; checked before any request.
41
41
  * @throws {ZeroAccountError} If the account is the zero address.
@@ -52,7 +52,7 @@ export interface MidnightTakeBorrowPlanParams extends Omit<IntentParams, "suppor
52
52
  * @param params.referralFee.recipient - Recipient required for a positive referral fee.
53
53
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
54
54
  * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
55
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
55
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
56
56
  * @returns A frozen plan with a standalone authorization step if needed and no signature requests.
57
57
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, or a target amount, is not a bigint;
58
58
  * checked before any request.
@@ -182,7 +182,7 @@ export interface MidnightSupplyCollateralTakeBorrowPlanParams extends MidnightTa
182
182
  * @param params.referralFee.recipient - Recipient required for a positive referral fee.
183
183
  * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
184
184
  * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
185
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
185
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
186
186
  * @returns A frozen plan with any necessary approvals and authorization, without signature requests.
187
187
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, a target amount or a collateral index
188
188
  * is not a bigint; checked before any request.
@@ -49,7 +49,7 @@ import { invalidSellTargetType, validateMidnightSellPlanAction, validateMidnight
49
49
  * @param params.referralFee.recipient - Recipient required for a positive referral fee.
50
50
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
51
51
  * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
52
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
52
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
53
53
  * @returns A frozen plan with a standalone authorization step if needed and no signature requests.
54
54
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, or a target amount, is not a bigint;
55
55
  * checked before any request.
@@ -175,7 +175,7 @@ export async function prepareMidnightTakeBorrow(client, params) {
175
175
  * @param params.referralFee.recipient - Recipient required for a positive referral fee.
176
176
  * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
177
177
  * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
178
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
178
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
179
179
  * @returns A frozen plan with any necessary approvals and authorization, without signature requests.
180
180
  * @throws {InvalidBigIntInputError} If a supplied non-null `now`, a target amount or a collateral index
181
181
  * is not a bigint; checked before any request.
@@ -61,7 +61,7 @@ export interface MidnightTakeRepayWithdrawCollateralPlanParams extends Omit<Inte
61
61
  * @param params.referralFee.recipient - Recipient required for a positive referral fee.
62
62
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
63
63
  * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
64
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
64
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
65
65
  * @returns A frozen plan with any needed approval and standalone authorization, without signatures.
66
66
  * @throws {InvalidBigIntInputError} when a supplied non-null `now`, `maxContinuousFee`, a target amount, or a withdrawal's collateral index or amount is not a bigint; checked before any request.
67
67
  * @throws {ZeroAccountError} when the sender is the zero address.
@@ -86,7 +86,7 @@ const validateTakeRepayWithdrawCollateralPosition = (params) => {
86
86
  * @param params.referralFee.recipient - Recipient required for a positive referral fee.
87
87
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
88
88
  * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
89
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
89
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
90
90
  * @returns A frozen plan with any needed approval and standalone authorization, without signatures.
91
91
  * @throws {InvalidBigIntInputError} when a supplied non-null `now`, `maxContinuousFee`, a target amount, or a withdrawal's collateral index or amount is not a bigint; checked before any request.
92
92
  * @throws {ZeroAccountError} when the sender is the zero address.
@@ -48,7 +48,7 @@ export interface MidnightTakeWithdrawPlanParams extends Omit<IntentParams, "supp
48
48
  * @param params.referralFee.recipient - Recipient required for a positive referral fee.
49
49
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
50
50
  * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
51
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
51
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
52
52
  * @returns A frozen plan with a standalone authorization step if needed and no signature requests.
53
53
  * @throws {InvalidBigIntInputError} If a supplied non-null `now` or a target amount is not a
54
54
  * bigint; checked before any request.
@@ -43,7 +43,7 @@ import { invalidSellTargetType, validateMidnightTargetAmountTypes, } from "./val
43
43
  * @param params.referralFee.recipient - Recipient required for a positive referral fee.
44
44
  * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
45
45
  * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
46
- * @param params.calldataOrigin - Optional attribution bytes appended to each built transaction.
46
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
47
47
  * @returns A frozen plan with a standalone authorization step if needed and no signature requests.
48
48
  * @throws {InvalidBigIntInputError} If a supplied non-null `now` or a target amount is not a
49
49
  * bigint; checked before any request.
@@ -1,6 +1,7 @@
1
- import { type Address } from "viem";
2
- import type { Erc2612RequirementSignature } from "../types/index.js";
1
+ import type { Address } from "viem";
2
+ import type { BundlesTokenRequirementSignature, Erc2612RequirementSignature } from "../types/index.js";
3
3
  import type { Action, SignatureRequest } from "./types.js";
4
+ import { type VaultPermitAction } from "./vaultBinding.js";
4
5
  /** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
5
6
  export declare function validatePermitPlanRequest(request: Record<string, unknown>, path: string): void;
6
7
  /** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
@@ -23,5 +24,17 @@ export declare function getSignedTokenPermit(requests: readonly SignatureRequest
23
24
  readonly asset: Address;
24
25
  readonly owner: Address;
25
26
  }): Erc2612RequirementSignature | undefined;
27
+ /**
28
+ * @internal Selects the vault action's signed token permit for its bundle pull, as its builder encodes it.
29
+ * @throws {IncompleteTransactionPlanError} If the referenced request is missing or unsigned.
30
+ * @throws {TransactionPlanSignatureMismatchError} If the referenced request is not a permit.
31
+ * @throws {BundlesPermitMismatchError} If the permit does not match the pull's spender, amount or deadline.
32
+ */
33
+ export declare function selectVaultPermit(action: Extract<VaultPermitAction, {
34
+ readonly type: "vaultV1Deposit" | "vaultV2Deposit";
35
+ }>, requests: readonly SignatureRequest[]): BundlesTokenRequirementSignature | undefined;
36
+ export declare function selectVaultPermit(action: Exclude<VaultPermitAction, {
37
+ readonly type: "vaultV1Deposit" | "vaultV2Deposit";
38
+ }>, requests: readonly SignatureRequest[]): Erc2612RequirementSignature | undefined;
26
39
  /** @internal Alias for existing Vault V2 plan builders. */
27
40
  export { getSignedTokenPermit as getVaultPermit };