@morpho-org/morpho-sdk 9.6.0-next.0 → 9.7.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 (211) hide show
  1. package/MIGRATION-v6-to-v7.md +1 -1
  2. package/README.md +123 -3
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +1 -5
  5. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
  6. package/lib/cjs/actions/bundles/common.js +39 -32
  7. package/lib/cjs/actions/midnight/cancelAndMake.js +20 -98
  8. package/lib/cjs/actions/midnight/index.d.ts +2 -0
  9. package/lib/cjs/actions/midnight/index.js +2 -0
  10. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +5 -6
  11. package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +39 -0
  12. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +91 -0
  13. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +31 -32
  14. package/lib/cjs/actions/midnight/takeBorrow.js +24 -23
  15. package/lib/cjs/actions/midnight/takeLend.js +24 -23
  16. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
  17. package/lib/cjs/actions/midnight/takeWithdraw.js +24 -23
  18. package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
  19. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +104 -0
  20. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
  21. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
  22. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
  23. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +1 -0
  24. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
  25. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  26. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
  27. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
  28. package/lib/cjs/actions/vaultV1/migrateToV2.js +7 -7
  29. package/lib/cjs/blue/abis.d.ts +1 -1
  30. package/lib/cjs/blue/abis.js +1 -5
  31. package/lib/cjs/blue/entities.d.ts +4 -4
  32. package/lib/cjs/blue/entities.js +1 -3
  33. package/lib/cjs/blue/errors.d.ts +2 -2
  34. package/lib/cjs/blue/errors.js +1 -5
  35. package/lib/cjs/blue/fetch.d.ts +2 -2
  36. package/lib/cjs/blue/fetch.js +1 -3
  37. package/lib/cjs/blue/utils.d.ts +1 -1
  38. package/lib/cjs/blue/utils.js +1 -2
  39. package/lib/cjs/entities/index.d.ts +5 -5
  40. package/lib/cjs/entities/index.js +1 -3
  41. package/lib/cjs/entities/midnight/midnight.d.ts +77 -3
  42. package/lib/cjs/entities/midnight/midnight.js +174 -0
  43. package/lib/cjs/entities/midnight/types.d.ts +16 -0
  44. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +12 -46
  45. package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -0
  46. package/lib/cjs/entities/requirements/getErc2612Permit.js +60 -0
  47. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
  48. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +3 -3
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +10 -35
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -33
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
  53. package/lib/cjs/errors.d.ts +4 -4
  54. package/lib/cjs/errors.js +6 -7
  55. package/lib/cjs/fetch.d.ts +2 -2
  56. package/lib/cjs/fetch.js +1 -3
  57. package/lib/cjs/helpers/deadShares.js +0 -2
  58. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +1 -0
  59. package/lib/cjs/helpers/signAndVerifyTypedData.js +12 -5
  60. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
  61. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +129 -0
  62. package/lib/cjs/helpers/validateMidnightCollateralBatch.d.ts +15 -0
  63. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +28 -0
  64. package/lib/cjs/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
  65. package/lib/cjs/helpers/validateMidnightCollateralSupplies.js +28 -0
  66. package/lib/cjs/helpers/validatePositiveInput.d.ts +10 -0
  67. package/lib/cjs/helpers/validatePositiveInput.js +18 -0
  68. package/lib/cjs/index.d.ts +2 -0
  69. package/lib/cjs/index.js +18 -1
  70. package/lib/cjs/midnight/errors.d.ts +1 -2
  71. package/lib/cjs/midnight/errors.js +5 -5
  72. package/lib/cjs/transactionPlan/approval.d.ts +2 -0
  73. package/lib/cjs/transactionPlan/approval.js +16 -0
  74. package/lib/cjs/transactionPlan/error.d.ts +145 -0
  75. package/lib/cjs/transactionPlan/error.js +186 -0
  76. package/lib/cjs/transactionPlan/getTokenPermit.d.ts +11 -0
  77. package/lib/cjs/transactionPlan/getTokenPermit.js +18 -0
  78. package/lib/cjs/transactionPlan/index.d.ts +9 -0
  79. package/lib/cjs/transactionPlan/index.js +24 -0
  80. package/lib/cjs/transactionPlan/intent.d.ts +51 -0
  81. package/lib/cjs/transactionPlan/intent.js +54 -0
  82. package/lib/cjs/transactionPlan/permit.d.ts +13 -0
  83. package/lib/cjs/transactionPlan/permit.js +145 -0
  84. package/lib/cjs/transactionPlan/plan.d.ts +99 -0
  85. package/lib/cjs/transactionPlan/plan.js +232 -0
  86. package/lib/cjs/transactionPlan/requirements.d.ts +44 -0
  87. package/lib/cjs/transactionPlan/requirements.js +79 -0
  88. package/lib/cjs/transactionPlan/serde.d.ts +33 -0
  89. package/lib/cjs/transactionPlan/serde.js +205 -0
  90. package/lib/cjs/transactionPlan/types.d.ts +91 -0
  91. package/lib/cjs/transactionPlan/types.js +2 -0
  92. package/lib/cjs/transactionPlan/validateActions.d.ts +8 -0
  93. package/lib/cjs/transactionPlan/validateActions.js +19 -0
  94. package/lib/cjs/transactionPlan/validation.d.ts +17 -0
  95. package/lib/cjs/transactionPlan/validation.js +70 -0
  96. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +81 -0
  97. package/lib/cjs/transactionPlan/vaultv2/deposit.js +211 -0
  98. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +77 -0
  99. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +190 -0
  100. package/lib/cjs/transactionPlan/version.d.ts +2 -0
  101. package/lib/cjs/transactionPlan/version.js +9 -0
  102. package/lib/cjs/types/action.d.ts +18 -3
  103. package/lib/cjs/types/error.d.ts +23 -2
  104. package/lib/cjs/types/error.js +45 -5
  105. package/lib/cjs/utils.d.ts +2 -2
  106. package/lib/cjs/utils.js +2 -4
  107. package/lib/esm/abis.d.ts +1 -1
  108. package/lib/esm/abis.js +1 -1
  109. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  110. package/lib/esm/actions/bundles/common.js +39 -32
  111. package/lib/esm/actions/midnight/cancelAndMake.js +25 -103
  112. package/lib/esm/actions/midnight/index.d.ts +2 -0
  113. package/lib/esm/actions/midnight/index.js +2 -0
  114. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +5 -6
  115. package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +39 -0
  116. package/lib/esm/actions/midnight/supplyCollateralBatch.js +87 -0
  117. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -34
  118. package/lib/esm/actions/midnight/takeBorrow.js +25 -24
  119. package/lib/esm/actions/midnight/takeLend.js +25 -24
  120. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
  121. package/lib/esm/actions/midnight/takeWithdraw.js +25 -24
  122. package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
  123. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +100 -0
  124. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
  125. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
  126. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
  127. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +1 -0
  128. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
  129. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  130. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
  131. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
  132. package/lib/esm/actions/vaultV1/migrateToV2.js +8 -8
  133. package/lib/esm/blue/abis.d.ts +1 -1
  134. package/lib/esm/blue/abis.js +1 -1
  135. package/lib/esm/blue/entities.d.ts +4 -4
  136. package/lib/esm/blue/entities.js +2 -2
  137. package/lib/esm/blue/errors.d.ts +2 -2
  138. package/lib/esm/blue/errors.js +2 -2
  139. package/lib/esm/blue/fetch.d.ts +2 -2
  140. package/lib/esm/blue/fetch.js +2 -2
  141. package/lib/esm/blue/utils.d.ts +1 -1
  142. package/lib/esm/blue/utils.js +1 -1
  143. package/lib/esm/entities/index.d.ts +5 -5
  144. package/lib/esm/entities/index.js +2 -2
  145. package/lib/esm/entities/midnight/midnight.d.ts +77 -3
  146. package/lib/esm/entities/midnight/midnight.js +176 -2
  147. package/lib/esm/entities/midnight/types.d.ts +16 -0
  148. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +14 -48
  149. package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -0
  150. package/lib/esm/entities/requirements/getErc2612Permit.js +57 -0
  151. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
  152. package/lib/esm/entities/vaultV1/vaultV1.d.ts +3 -3
  153. package/lib/esm/entities/vaultV2/vaultV2.d.ts +10 -35
  154. package/lib/esm/entities/vaultV2/vaultV2.js +1 -33
  155. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
  156. package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
  157. package/lib/esm/errors.d.ts +4 -4
  158. package/lib/esm/errors.js +4 -4
  159. package/lib/esm/fetch.d.ts +2 -2
  160. package/lib/esm/fetch.js +2 -2
  161. package/lib/esm/helpers/deadShares.js +1 -3
  162. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +1 -0
  163. package/lib/esm/helpers/signAndVerifyTypedData.js +13 -6
  164. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
  165. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +124 -0
  166. package/lib/esm/helpers/validateMidnightCollateralBatch.d.ts +15 -0
  167. package/lib/esm/helpers/validateMidnightCollateralBatch.js +25 -0
  168. package/lib/esm/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
  169. package/lib/esm/helpers/validateMidnightCollateralSupplies.js +24 -0
  170. package/lib/esm/helpers/validatePositiveInput.d.ts +10 -0
  171. package/lib/esm/helpers/validatePositiveInput.js +14 -0
  172. package/lib/esm/index.d.ts +2 -0
  173. package/lib/esm/index.js +1 -0
  174. package/lib/esm/midnight/errors.d.ts +1 -2
  175. package/lib/esm/midnight/errors.js +1 -2
  176. package/lib/esm/transactionPlan/approval.d.ts +2 -0
  177. package/lib/esm/transactionPlan/approval.js +13 -0
  178. package/lib/esm/transactionPlan/error.d.ts +145 -0
  179. package/lib/esm/transactionPlan/error.js +175 -0
  180. package/lib/esm/transactionPlan/getTokenPermit.d.ts +11 -0
  181. package/lib/esm/transactionPlan/getTokenPermit.js +15 -0
  182. package/lib/esm/transactionPlan/index.d.ts +9 -0
  183. package/lib/esm/transactionPlan/index.js +5 -0
  184. package/lib/esm/transactionPlan/intent.d.ts +51 -0
  185. package/lib/esm/transactionPlan/intent.js +51 -0
  186. package/lib/esm/transactionPlan/permit.d.ts +13 -0
  187. package/lib/esm/transactionPlan/permit.js +140 -0
  188. package/lib/esm/transactionPlan/plan.d.ts +99 -0
  189. package/lib/esm/transactionPlan/plan.js +226 -0
  190. package/lib/esm/transactionPlan/requirements.d.ts +44 -0
  191. package/lib/esm/transactionPlan/requirements.js +74 -0
  192. package/lib/esm/transactionPlan/serde.d.ts +33 -0
  193. package/lib/esm/transactionPlan/serde.js +201 -0
  194. package/lib/esm/transactionPlan/types.d.ts +91 -0
  195. package/lib/esm/transactionPlan/types.js +1 -0
  196. package/lib/esm/transactionPlan/validateActions.d.ts +8 -0
  197. package/lib/esm/transactionPlan/validateActions.js +16 -0
  198. package/lib/esm/transactionPlan/validation.d.ts +17 -0
  199. package/lib/esm/transactionPlan/validation.js +64 -0
  200. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +81 -0
  201. package/lib/esm/transactionPlan/vaultv2/deposit.js +206 -0
  202. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +77 -0
  203. package/lib/esm/transactionPlan/vaultv2/withdraw.js +185 -0
  204. package/lib/esm/transactionPlan/version.d.ts +2 -0
  205. package/lib/esm/transactionPlan/version.js +6 -0
  206. package/lib/esm/types/action.d.ts +18 -3
  207. package/lib/esm/types/error.d.ts +23 -2
  208. package/lib/esm/types/error.js +40 -3
  209. package/lib/esm/utils.d.ts +2 -2
  210. package/lib/esm/utils.js +2 -2
  211. package/package.json +8 -7
@@ -0,0 +1,206 @@
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, } from "@morpho-org/blue-sdk";
2
+ import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { isAddressEqual } from "viem";
4
+ import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
5
+ import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
6
+ import { vaultV2Deposit } from "../../actions/vaultV2/deposit.js";
7
+ import { assertRegistryTargetsHaveCode } from "../../entities/requirements/assertContractCode.js";
8
+ import { computeVaultMaxSharePrice } from "../../helpers/index.js";
9
+ import { validateNativeVaultAsset, validateSlippageTolerance, validateUint256Field, } from "../../helpers/validate.js";
10
+ import { NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
11
+ import { InvalidTransactionPlanError } from "../error.js";
12
+ import { resolveIntent } from "../intent.js";
13
+ import { getVaultPermit } from "../permit.js";
14
+ import { buildApprovalStep, buildPermitSignatureRequest, getTokenRequirements, } from "../requirements.js";
15
+ import { validatePlanField, validatePlanFields, validateVaultPlanAction, } from "../validation.js";
16
+ /** @internal Validates the stored Vault V2 deposit action's input shape. */
17
+ export function validateDepositPlanAction(action, path) {
18
+ const inputs = validateVaultPlanAction(action, path);
19
+ validatePlanFields(inputs, {
20
+ path: `${path}.inputs`,
21
+ fields: { asset: "address", maxSharePrice: "uint256 bigint" },
22
+ });
23
+ if ((inputs.amount === undefined) === (inputs.nativeAmount === undefined))
24
+ throw new InvalidTransactionPlanError({
25
+ path: `${path}.inputs`,
26
+ reason: "expected exactly one of amount or nativeAmount",
27
+ });
28
+ const field = inputs.amount === undefined ? "nativeAmount" : "amount";
29
+ validatePlanField(inputs[field], {
30
+ path: `${path}.inputs.${field}`,
31
+ type: "uint256 bigint",
32
+ });
33
+ }
34
+ function resolveDepositInputs(params, now) {
35
+ const { vault, chainId, amount, vaultData } = params;
36
+ const intent = resolveIntent(params, now);
37
+ const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
38
+ validateSlippageTolerance(slippageTolerance);
39
+ const native = (params.funding ?? { type: "erc20" }).type === "native";
40
+ if (amount <= 0n)
41
+ throw new NonPositiveInputError("amount", amount);
42
+ // Reject amounts that cannot be encoded as uint256 before making RPC requests.
43
+ validateUint256Field("amount", amount);
44
+ const common = normalizeBundlesCommonParams({
45
+ deadline: intent.deadline,
46
+ referralFeePct: intent.referralFeePct,
47
+ referralFeeRecipient: intent.referralFeeRecipient,
48
+ });
49
+ if (!isAddressEqual(vaultData.address, vault))
50
+ throw new VaultAddressMismatchError(vaultData.address, vault);
51
+ const { asset } = vaultData;
52
+ // Native funding must target the chain's wrapped-native vault asset.
53
+ if (native)
54
+ validateNativeVaultAsset(chainId, asset);
55
+ // The quote depends only on the snapshot and the intent, so it is fixed before any read.
56
+ const maxSharePrice = computeVaultMaxSharePrice({
57
+ vaultData,
58
+ deadline: intent.deadline,
59
+ assets: amount - getBundlesReferralFeeAssets(amount, common.referralFeePct),
60
+ slippageTolerance,
61
+ });
62
+ return { intent, native, common, asset, maxSharePrice };
63
+ }
64
+ /**
65
+ * Prepares a deposit plan from caller intent and a vault snapshot, reading the token prerequisites
66
+ * directly. The quote is fixed on the deposit step at preparation, so the returned plan is static:
67
+ * only signatures are added before building.
68
+ * @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
69
+ * @param params.vault - Vault V2 contract receiving the net deposit.
70
+ * @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the asset and deadline-accrued share-price bound.
71
+ * @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
72
+ * @param params.account - Non-zero account funding, signing and sending the deposit.
73
+ * @param params.amount - Positive gross deposit in asset base units, before referral fees.
74
+ * @param params.funding.type - Optional funding source: `"erc20"` (default) or `"native"`; native funding requires the vault asset to be wNative.
75
+ * @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
76
+ * @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
77
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
78
+ * @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
79
+ * @param params.expiresAt - Optional future Unix timestamp in seconds as a safe integer; defaults to two hours from preparation.
80
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
81
+ * @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
82
+ * @returns A plan with approvals, concrete signature requests and the deposit step.
83
+ * @throws {ZeroAccountError} when `account` is the zero address.
84
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
85
+ * @throws {NonPositiveInputError} when `expiresAt`, `amount`, net assets or previewed shares are not positive.
86
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
87
+ * @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
88
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `amount` exceeds uint256.
89
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
90
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
91
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
92
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
93
+ * @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
94
+ * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
95
+ * @throws {ChainIdMismatchError} when the client targets another chain.
96
+ * @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
97
+ * @see computeVaultMaxSharePrice for quote errors.
98
+ * @example
99
+ * ```ts
100
+ * import { prepareVaultV2Deposit } from "@morpho-org/morpho-sdk";
101
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
102
+ * import { createPublicClient, http } from "viem";
103
+ * import { mainnet } from "viem/chains";
104
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
105
+ * const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
106
+ * const plan = await prepareVaultV2Deposit(client, {
107
+ * vault, chainId: 1, account: "0x0000000000000000000000000000000000000001", amount: 1_000_000n, supportSignature: true,
108
+ * vaultData: await fetchAccrualVaultV2(vault, client),
109
+ * });
110
+ * // Sign the pending requests, verify and attach with applySignatures, then build.
111
+ * ```
112
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
113
+ */
114
+ export async function prepareVaultV2Deposit(client, params) {
115
+ const { vault, chainId, account, amount } = params;
116
+ const now = Time.timestamp();
117
+ const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
118
+ const spender = getChainAddress(chainId, "bundles.vaultBundlesV1");
119
+ const [requirements] = await Promise.all([
120
+ validateClientChainId(client, chainId).then(() => native
121
+ ? []
122
+ : getTokenRequirements(client, {
123
+ token: asset,
124
+ spender,
125
+ amount,
126
+ owner: account,
127
+ chainId,
128
+ deadline: intent.deadline,
129
+ now,
130
+ supportSignature: intent.supportSignature,
131
+ deployless: intent.deployless,
132
+ })),
133
+ assertRegistryTargetsHaveCode(client, chainId, [
134
+ { role: "bundles.vaultBundlesV1", address: spender },
135
+ ]),
136
+ ]);
137
+ const approvals = [];
138
+ const signatureRequests = [];
139
+ const tokenPermitRequestId = "vaultV2Deposit:tokenPermit";
140
+ for (const requirement of requirements) {
141
+ if ("sign" in requirement) {
142
+ signatureRequests.push(buildPermitSignatureRequest(requirement, tokenPermitRequestId));
143
+ }
144
+ else {
145
+ approvals.push(buildApprovalStep(requirement, {
146
+ id: approvals.length === 0
147
+ ? "vaultV2Deposit:approval"
148
+ : `vaultV2Deposit:approval:${approvals.length + 1}`,
149
+ chainId,
150
+ account,
151
+ }));
152
+ }
153
+ }
154
+ return deepFreeze(structuredClone({
155
+ version: 1,
156
+ account,
157
+ chainId,
158
+ expiresAt: intent.expiresAt,
159
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
160
+ steps: [
161
+ ...approvals,
162
+ {
163
+ id: "vaultV2Deposit",
164
+ label: "Deposit into vault",
165
+ action: {
166
+ type: "vaultV2Deposit",
167
+ inputs: {
168
+ chainId,
169
+ account,
170
+ vault,
171
+ asset,
172
+ maxSharePrice,
173
+ ...(native ? { nativeAmount: amount } : { amount }),
174
+ ...common,
175
+ },
176
+ signatureRequestIds: signatureRequests.length > 0
177
+ ? { tokenPermit: tokenPermitRequestId }
178
+ : {},
179
+ },
180
+ },
181
+ ],
182
+ signatureRequests,
183
+ }));
184
+ }
185
+ /** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
186
+ export function buildVaultV2Deposit(action, requests) {
187
+ const { asset, chainId, account, ...args } = action.inputs;
188
+ const signature = getVaultPermit(requests, {
189
+ id: action.signatureRequestIds.tokenPermit,
190
+ asset,
191
+ owner: account,
192
+ });
193
+ const requirementSignature = selectBundlesTokenRequirementSignature(signature ? [signature] : [], {
194
+ spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
195
+ amount: action.inputs.amount ?? action.inputs.nativeAmount,
196
+ deadline: action.inputs.deadline,
197
+ });
198
+ return vaultV2Deposit({
199
+ vault: { chainId, address: action.inputs.vault, asset },
200
+ args: {
201
+ ...args,
202
+ userAddress: account,
203
+ requirementSignature,
204
+ },
205
+ });
206
+ }
@@ -0,0 +1,77 @@
1
+ import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import { type Address, type Client } from "viem";
3
+ import { type Transaction, type VaultV2WithdrawAction } from "../../types/index.js";
4
+ import { type IntentParams } from "../intent.js";
5
+ import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
6
+ /** @internal Validates the stored Vault V2 withdrawal action's input shape. */
7
+ export declare function validateWithdrawPlanAction(action: Record<string, unknown>, path: string): void;
8
+ /**
9
+ * Caller intent for a Vault V2 asset withdrawal, mirroring the Actions API withdraw inputs, plus the snapshot.
10
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
11
+ */
12
+ export interface VaultV2WithdrawPlanParams extends IntentParams {
13
+ readonly vault: Address;
14
+ /** Gross assets withdrawn, before the referral fee. */
15
+ readonly amount: bigint;
16
+ /**
17
+ * Accrual snapshot of `vault`, fetched by the caller with `fetchAccrualVaultV2`. The required
18
+ * share allowance is derived from it at preparation; the snapshot itself is never stored.
19
+ */
20
+ readonly vaultData: AccrualVaultV2;
21
+ }
22
+ /**
23
+ * Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
24
+ * the withdrawal step at preparation, because the required share allowance decides the approval or
25
+ * permit prerequisite, so the returned plan is static: only signatures are added before building.
26
+ * When allowance is insufficient, both direct share approvals and ERC-2612 share permits authorize
27
+ * `maxUint256`, not the quote. Later withdrawals reuse that allowance without another signature.
28
+ * The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
29
+ * on-chain share-price or max-shares bound and accepts no slippage tolerance input.
30
+ * @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
31
+ * @param params.vault - Vault V2 contract whose shares are burned for the withdrawal.
32
+ * @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
33
+ * @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
34
+ * @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
35
+ * @param params.amount - Positive gross withdrawal in asset base units, before referral fees.
36
+ * @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
37
+ * @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
38
+ * @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
39
+ * @param params.expiresAt - Optional future Unix timestamp in seconds as a safe integer; defaults to two hours from preparation.
40
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
41
+ * @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
42
+ * @returns A plan with the withdrawal step and any required share approval or signature request.
43
+ * @throws {ZeroAccountError} when `account` is the zero address.
44
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
45
+ * @throws {NonPositiveInputError} when `expiresAt`, `amount` or the computed required shares are not positive.
46
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
47
+ * @throws {NegativeInputError} when `referralFee.bps` is negative.
48
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `amount` exceeds uint256.
49
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
50
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
51
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
52
+ * @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
53
+ * @throws {ChainIdMismatchError} when the client targets another chain.
54
+ * @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
55
+ * @see computeVaultMaxShareAllowance for quote errors.
56
+ * @see getVaultBundlesSharesRequirements for allowance and nonce reads.
57
+ * @example
58
+ * ```ts
59
+ * import { prepareVaultV2Withdraw } from "@morpho-org/morpho-sdk";
60
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
61
+ * import { createPublicClient, http } from "viem";
62
+ * import { mainnet } from "viem/chains";
63
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
64
+ * const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
65
+ * const plan = await prepareVaultV2Withdraw(client, {
66
+ * vault, chainId: 1, account: "0x0000000000000000000000000000000000000001", amount: 1_000_000n, supportSignature: true,
67
+ * vaultData: await fetchAccrualVaultV2(vault, client),
68
+ * });
69
+ * // Sign the pending requests, verify and attach with applySignatures, then build.
70
+ * ```
71
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
72
+ */
73
+ export declare function prepareVaultV2Withdraw(client: Client, params: VaultV2WithdrawPlanParams): Promise<TransactionPlan>;
74
+ /** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
75
+ export declare function buildVaultV2Withdraw(action: Extract<Action, {
76
+ type: "vaultV2Withdraw";
77
+ }>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV2WithdrawAction>>;
@@ -0,0 +1,185 @@
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, Token, } from "@morpho-org/blue-sdk";
2
+ import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { isAddressEqual } from "viem";
4
+ import { normalizeBundlesCommonParams, selectBundlesSharesPermitSignature, } from "../../actions/bundles/common.js";
5
+ import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
6
+ import { vaultV2Withdraw } from "../../actions/vaultV2/withdraw.js";
7
+ import { assertRegistryTargetsHaveCode } from "../../entities/requirements/assertContractCode.js";
8
+ import { getVaultBundlesSharesRequirements } from "../../entities/requirements/getVaultBundlesSharesRequirements.js";
9
+ import { computeVaultMaxShareAllowance } from "../../helpers/index.js";
10
+ import { validateUint256Field } from "../../helpers/validate.js";
11
+ import { NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
12
+ import { resolveIntent } from "../intent.js";
13
+ import { getVaultPermit } from "../permit.js";
14
+ import { buildApprovalStep, buildPermitSignatureRequest, } from "../requirements.js";
15
+ import { validatePlanFields, validateVaultPlanAction } from "../validation.js";
16
+ /** @internal Validates the stored Vault V2 withdrawal action's input shape. */
17
+ export function validateWithdrawPlanAction(action, path) {
18
+ const inputs = validateVaultPlanAction(action, path);
19
+ validatePlanFields(inputs, {
20
+ path: `${path}.inputs`,
21
+ fields: {
22
+ amount: "uint256 bigint",
23
+ requiredShareAllowance: "uint256 bigint",
24
+ },
25
+ });
26
+ }
27
+ function resolveWithdrawInputs(params, now) {
28
+ const { vault, amount, vaultData } = params;
29
+ const intent = resolveIntent(params, now);
30
+ if (amount <= 0n)
31
+ throw new NonPositiveInputError("amount", amount);
32
+ // Reject amounts that cannot be encoded as uint256 before making RPC requests.
33
+ validateUint256Field("amount", amount);
34
+ const common = normalizeBundlesCommonParams({
35
+ deadline: intent.deadline,
36
+ referralFeePct: intent.referralFeePct,
37
+ referralFeeRecipient: intent.referralFeeRecipient,
38
+ });
39
+ if (!isAddressEqual(vaultData.address, vault))
40
+ throw new VaultAddressMismatchError(vaultData.address, vault);
41
+ // The quote depends only on the snapshot and the intent, so it is fixed before any read.
42
+ const requiredShareAllowance = computeVaultMaxShareAllowance({
43
+ vaultData,
44
+ deadline: intent.deadline,
45
+ assets: amount,
46
+ slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
47
+ });
48
+ return { intent, common, requiredShareAllowance };
49
+ }
50
+ /**
51
+ * Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
52
+ * the withdrawal step at preparation, because the required share allowance decides the approval or
53
+ * permit prerequisite, so the returned plan is static: only signatures are added before building.
54
+ * When allowance is insufficient, both direct share approvals and ERC-2612 share permits authorize
55
+ * `maxUint256`, not the quote. Later withdrawals reuse that allowance without another signature.
56
+ * The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
57
+ * on-chain share-price or max-shares bound and accepts no slippage tolerance input.
58
+ * @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
59
+ * @param params.vault - Vault V2 contract whose shares are burned for the withdrawal.
60
+ * @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
61
+ * @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
62
+ * @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
63
+ * @param params.amount - Positive gross withdrawal in asset base units, before referral fees.
64
+ * @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
65
+ * @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
66
+ * @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
67
+ * @param params.expiresAt - Optional future Unix timestamp in seconds as a safe integer; defaults to two hours from preparation.
68
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
69
+ * @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
70
+ * @returns A plan with the withdrawal step and any required share approval or signature request.
71
+ * @throws {ZeroAccountError} when `account` is the zero address.
72
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
73
+ * @throws {NonPositiveInputError} when `expiresAt`, `amount` or the computed required shares are not positive.
74
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
75
+ * @throws {NegativeInputError} when `referralFee.bps` is negative.
76
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `amount` exceeds uint256.
77
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
78
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
79
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
80
+ * @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
81
+ * @throws {ChainIdMismatchError} when the client targets another chain.
82
+ * @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
83
+ * @see computeVaultMaxShareAllowance for quote errors.
84
+ * @see getVaultBundlesSharesRequirements for allowance and nonce reads.
85
+ * @example
86
+ * ```ts
87
+ * import { prepareVaultV2Withdraw } from "@morpho-org/morpho-sdk";
88
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
89
+ * import { createPublicClient, http } from "viem";
90
+ * import { mainnet } from "viem/chains";
91
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
92
+ * const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
93
+ * const plan = await prepareVaultV2Withdraw(client, {
94
+ * vault, chainId: 1, account: "0x0000000000000000000000000000000000000001", amount: 1_000_000n, supportSignature: true,
95
+ * vaultData: await fetchAccrualVaultV2(vault, client),
96
+ * });
97
+ * // Sign the pending requests, verify and attach with applySignatures, then build.
98
+ * ```
99
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
100
+ */
101
+ export async function prepareVaultV2Withdraw(client, params) {
102
+ const { vault, chainId, account, amount } = params;
103
+ const now = Time.timestamp();
104
+ const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
105
+ const spender = getChainAddress(chainId, "bundles.vaultBundlesV1");
106
+ const [, , requirements] = await Promise.all([
107
+ validateClientChainId(client, chainId),
108
+ assertRegistryTargetsHaveCode(client, chainId, [
109
+ { role: "bundles.vaultBundlesV1", address: spender },
110
+ ]),
111
+ getVaultBundlesSharesRequirements(client, {
112
+ vaultData: new Token({ address: vault }),
113
+ version: "vaultV2",
114
+ owner: account,
115
+ chainId,
116
+ requiredShareAllowance,
117
+ deadline: intent.deadline,
118
+ supportSignature: intent.supportSignature,
119
+ now,
120
+ }),
121
+ ]);
122
+ const approvals = [];
123
+ const signatureRequests = [];
124
+ const tokenPermitRequestId = "vaultV2Withdraw:tokenPermit";
125
+ const requirement = requirements[0];
126
+ if (requirement !== undefined) {
127
+ if ("sign" in requirement) {
128
+ signatureRequests.push(buildPermitSignatureRequest(requirement, tokenPermitRequestId));
129
+ }
130
+ else {
131
+ approvals.push(buildApprovalStep(requirement, {
132
+ id: "vaultV2Withdraw:approval",
133
+ chainId,
134
+ account,
135
+ }));
136
+ }
137
+ }
138
+ return deepFreeze(structuredClone({
139
+ version: 1,
140
+ account,
141
+ chainId,
142
+ expiresAt: intent.expiresAt,
143
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
144
+ steps: [
145
+ ...approvals,
146
+ {
147
+ id: "vaultV2Withdraw",
148
+ label: "Withdraw from vault",
149
+ action: {
150
+ type: "vaultV2Withdraw",
151
+ inputs: {
152
+ chainId,
153
+ account,
154
+ vault,
155
+ amount,
156
+ requiredShareAllowance,
157
+ ...common,
158
+ },
159
+ signatureRequestIds: signatureRequests.length > 0
160
+ ? { tokenPermit: tokenPermitRequestId }
161
+ : {},
162
+ },
163
+ },
164
+ ],
165
+ signatureRequests,
166
+ }));
167
+ }
168
+ /** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
169
+ export function buildVaultV2Withdraw(action, requests) {
170
+ const { requiredShareAllowance, chainId, account, ...args } = action.inputs;
171
+ const signature = getVaultPermit(requests, {
172
+ id: action.signatureRequestIds.tokenPermit,
173
+ asset: action.inputs.vault,
174
+ owner: account,
175
+ });
176
+ const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
177
+ spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
178
+ amount: requiredShareAllowance,
179
+ deadline: action.inputs.deadline,
180
+ });
181
+ return vaultV2Withdraw({
182
+ vault: { chainId, address: action.inputs.vault },
183
+ args: { ...args, userAddress: account, requirementSignature: permit },
184
+ });
185
+ }
@@ -0,0 +1,2 @@
1
+ /** @internal Rejects unsupported plan versions before interpreting stored fields. */
2
+ export declare function validateTransactionPlanVersion(version: number): void;
@@ -0,0 +1,6 @@
1
+ import { UnsupportedTransactionPlanVersionError } from "./error.js";
2
+ /** @internal Rejects unsupported plan versions before interpreting stored fields. */
3
+ export function validateTransactionPlanVersion(version) {
4
+ if (version !== 1)
5
+ throw new UnsupportedTransactionPlanVersionError(version);
6
+ }
@@ -283,12 +283,12 @@ export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
283
283
  }> {
284
284
  }
285
285
  /**
286
- * Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's whole supply position,
286
+ * Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's supply shares,
287
287
  * sent by the callback's owner.
288
288
  */
289
289
  export interface BlueWithdrawBuyCallbackAction extends BaseAction<"blueWithdrawBuyCallback", {
290
290
  readonly market: Hex;
291
- /** Supply shares burned: the callback's whole position. */
291
+ /** Caller-supplied number of supply shares burned. */
292
292
  readonly shares: bigint;
293
293
  /** BlueBuyCallback whose supply position is withdrawn. */
294
294
  readonly onBehalf: Address;
@@ -449,6 +449,13 @@ export interface MidnightSupplyCollateralAction extends BaseAction<"midnightSupp
449
449
  readonly onBehalf: Address;
450
450
  }> {
451
451
  }
452
+ /** Metadata for an atomic direct Midnight collateral supply batch. */
453
+ export interface MidnightSupplyCollateralBatchAction extends BaseAction<"midnightSupplyCollateralBatch", {
454
+ readonly market: Hex;
455
+ readonly collateralSupplies: readonly MidnightCollateralTransfer[];
456
+ readonly onBehalf: Address;
457
+ }> {
458
+ }
452
459
  /** Metadata for a direct Midnight collateral withdrawal transaction. */
453
460
  export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWithdrawCollateral", {
454
461
  readonly market: Hex;
@@ -458,6 +465,14 @@ export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWi
458
465
  readonly receiver: Address;
459
466
  }> {
460
467
  }
468
+ /** Metadata for an atomic direct Midnight collateral withdrawal batch. */
469
+ export interface MidnightWithdrawCollateralBatchAction extends BaseAction<"midnightWithdrawCollateralBatch", {
470
+ readonly market: Hex;
471
+ readonly collateralWithdrawals: readonly MidnightCollateralTransfer[];
472
+ readonly onBehalf: Address;
473
+ readonly receiver: Address;
474
+ }> {
475
+ }
461
476
  /** Metadata for a direct Midnight credit redemption transaction. */
462
477
  export interface MidnightRedeemAction extends BaseAction<"midnightRedeem", {
463
478
  readonly market: Hex;
@@ -524,7 +539,7 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
524
539
  * VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
525
540
  * consumers can `switch` exhaustively on it.
526
541
  */
527
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
542
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
528
543
  /**
529
544
  * Describes a single, immutable, deep-frozen transaction to submit on-chain:
530
545
  * the target `to`, native `value`, encoded call `data`, and the originating
@@ -922,9 +922,22 @@ export declare class RepayExceedsDebtError extends Error {
922
922
  market: string;
923
923
  });
924
924
  }
925
- /** Thrown when EIP-712 signature verification fails (the signed data does not match the expected signer). */
925
+ /** Thrown when EIP-712 signature verification fails to recover the expected signer. */
926
926
  export declare class InvalidSignatureError extends Error {
927
- constructor();
927
+ constructor(options?: ErrorOptions);
928
+ }
929
+ /** Thrown when signature recovery fails, with redacted diagnostics and the original error as `cause`. */
930
+ export declare class MalformedSignatureError extends InvalidSignatureError {
931
+ /** JavaScript type returned by the wallet, without the signature value. */
932
+ readonly signatureType: string;
933
+ /** Whether the returned value is an even-length hex string. */
934
+ readonly signatureIsHex: boolean;
935
+ /** Signature byte length, when it is an even-length hex string. */
936
+ readonly signatureByteLength: number | undefined;
937
+ constructor(params: {
938
+ readonly signature: unknown;
939
+ readonly cause: unknown;
940
+ });
928
941
  }
929
942
  /** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
930
943
  export declare class RepaySharesExceedDebtError extends Error {
@@ -1056,6 +1069,14 @@ export declare class EmptyMidnightGroupCancellationsError extends Error {
1056
1069
  export declare class EmptyMidnightCollateralSuppliesError extends Error {
1057
1070
  constructor();
1058
1071
  }
1072
+ /** Thrown when a direct Midnight collateral withdrawal batch is empty. */
1073
+ export declare class EmptyMidnightCollateralWithdrawalsError extends Error {
1074
+ constructor();
1075
+ }
1076
+ /** Thrown when a direct Midnight collateral batch repeats an index. */
1077
+ export declare class DuplicateMidnightCollateralIndexError extends Error {
1078
+ constructor(collateralIndex: bigint);
1079
+ }
1059
1080
  /** Thrown when a Midnight batch cancellation lists the same offer group twice. */
1060
1081
  export declare class DuplicateMidnightGroupCancellationError extends Error {
1061
1082
  constructor(params: {
@@ -1135,13 +1135,36 @@ export class RepayExceedsDebtError extends Error {
1135
1135
  this.name = "RepayExceedsDebtError";
1136
1136
  }
1137
1137
  }
1138
- /** Thrown when EIP-712 signature verification fails (the signed data does not match the expected signer). */
1138
+ /** Thrown when EIP-712 signature verification fails to recover the expected signer. */
1139
1139
  export class InvalidSignatureError extends Error {
1140
- constructor() {
1141
- super("Signature verification failed: the signed data does not match the expected signer address");
1140
+ constructor(options) {
1141
+ super("Signature verification failed: the signed data does not match the expected signer address", options);
1142
1142
  this.name = "InvalidSignatureError";
1143
1143
  }
1144
1144
  }
1145
+ /** Thrown when signature recovery fails, with redacted diagnostics and the original error as `cause`. */
1146
+ export class MalformedSignatureError extends InvalidSignatureError {
1147
+ /** JavaScript type returned by the wallet, without the signature value. */
1148
+ signatureType;
1149
+ /** Whether the returned value is an even-length hex string. */
1150
+ signatureIsHex;
1151
+ /** Signature byte length, when it is an even-length hex string. */
1152
+ signatureByteLength;
1153
+ constructor(params) {
1154
+ super({ cause: params.cause });
1155
+ this.name = "MalformedSignatureError";
1156
+ this.message =
1157
+ "Signature verification failed: the wallet returned a malformed signature. Check the wallet signing transport and sign the typed data again.";
1158
+ this.signatureType = typeof params.signature;
1159
+ this.signatureIsHex =
1160
+ typeof params.signature === "string" &&
1161
+ /^0x(?:[0-9a-fA-F]{2})*$/.test(params.signature);
1162
+ this.signatureByteLength =
1163
+ this.signatureIsHex && typeof params.signature === "string"
1164
+ ? (params.signature.length - 2) / 2
1165
+ : undefined;
1166
+ }
1167
+ }
1145
1168
  /** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
1146
1169
  export class RepaySharesExceedDebtError extends Error {
1147
1170
  constructor(params) {
@@ -1290,6 +1313,20 @@ export class EmptyMidnightCollateralSuppliesError extends Error {
1290
1313
  this.name = "EmptyMidnightCollateralSuppliesError";
1291
1314
  }
1292
1315
  }
1316
+ /** Thrown when a direct Midnight collateral withdrawal batch is empty. */
1317
+ export class EmptyMidnightCollateralWithdrawalsError extends Error {
1318
+ constructor() {
1319
+ super("Midnight collateral withdrawals cannot be empty. Pass at least one collateral withdrawal.");
1320
+ this.name = "EmptyMidnightCollateralWithdrawalsError";
1321
+ }
1322
+ }
1323
+ /** Thrown when a direct Midnight collateral batch repeats an index. */
1324
+ export class DuplicateMidnightCollateralIndexError extends Error {
1325
+ constructor(collateralIndex) {
1326
+ super(`Midnight collateral batch repeats index "${collateralIndex}". Pass each collateral index once.`);
1327
+ this.name = "DuplicateMidnightCollateralIndexError";
1328
+ }
1329
+ }
1293
1330
  /** Thrown when a Midnight batch cancellation lists the same offer group twice. */
1294
1331
  export class DuplicateMidnightGroupCancellationError extends Error {
1295
1332
  constructor(params) {