@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,51 @@
1
+ import { type Address, type Hex } from "viem";
2
+ /**
3
+ * Which balance pays a deposit: the vault asset, or native currency the bundle wraps.
4
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
5
+ */
6
+ export type Funding = {
7
+ readonly type: "erc20";
8
+ } | {
9
+ readonly type: "native";
10
+ };
11
+ /**
12
+ * Referral fee in basis points of the gross amount, paid to `recipient`.
13
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
14
+ */
15
+ export interface ReferralFee {
16
+ readonly bps: number;
17
+ readonly recipient: Address;
18
+ }
19
+ /**
20
+ * Intent fields shared by every prepare function, mirroring the Actions API intent inputs.
21
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
22
+ */
23
+ export interface IntentParams {
24
+ readonly chainId: number;
25
+ /** Non-zero account that funds, signs and sends the operation. */
26
+ readonly account: Address;
27
+ readonly referralFee?: ReferralFee;
28
+ /** Prefer an ERC-2612 permit when available, otherwise approve directly. Defaults to `false`. */
29
+ readonly supportSignature?: boolean;
30
+ /** Unix seconds. Defaults to two hours from now. */
31
+ readonly expiresAt?: number;
32
+ /** Optional attribution bytes appended verbatim to every built transaction's calldata. */
33
+ readonly calldataOrigin?: Hex;
34
+ /** Whether token metadata reads for permits may use deployless aggregation. */
35
+ readonly deployless?: boolean;
36
+ }
37
+ /** @internal Validated intent in the bigint units the encoders and requirement helpers take. */
38
+ export interface Intent {
39
+ readonly expiresAt: number;
40
+ readonly deadline: bigint;
41
+ readonly referralFeePct: bigint;
42
+ readonly referralFeeRecipient: Address | undefined;
43
+ readonly supportSignature: boolean;
44
+ readonly calldataOrigin: Hex | undefined;
45
+ readonly deployless: boolean | undefined;
46
+ }
47
+ /**
48
+ * @internal Normalizes caller intent before any RPC read: account, expiry, referral fee,
49
+ * signature support and calldata origin. Throws on invalid values so a plan never carries them.
50
+ */
51
+ export declare function resolveIntent(params: IntentParams, now: bigint): Intent;
@@ -0,0 +1,51 @@
1
+ import { MathLib, Time } from "@morpho-org/morpho-ts";
2
+ import { isHex, zeroAddress } from "viem";
3
+ import { ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, NonPositiveInputError, } from "../types/index.js";
4
+ import { InvalidCalldataOriginError, NonIntegerInputError, ZeroAccountError, } from "./error.js";
5
+ const BASIS_POINTS = 10000n;
6
+ const WAD_PER_BASIS_POINT = MathLib.WAD / BASIS_POINTS;
7
+ function toSafeInteger(field, value) {
8
+ if (!Number.isSafeInteger(value))
9
+ throw new NonIntegerInputError(field, value);
10
+ return BigInt(value);
11
+ }
12
+ /**
13
+ * @internal Normalizes caller intent before any RPC read: account, expiry, referral fee,
14
+ * signature support and calldata origin. Throws on invalid values so a plan never carries them.
15
+ */
16
+ export function resolveIntent(params, now) {
17
+ if (params.account === zeroAddress)
18
+ throw new ZeroAccountError(params.account);
19
+ const expiresAt = params.expiresAt ?? Number(now + Time.s.from.h(2n));
20
+ const deadline = toSafeInteger("expiresAt", expiresAt);
21
+ if (deadline <= 0n)
22
+ throw new NonPositiveInputError("expiresAt", deadline);
23
+ if (deadline <= now)
24
+ throw new ExpiredDeadlineError(deadline, now);
25
+ const bps = params.referralFee === undefined
26
+ ? 0n
27
+ : toSafeInteger("referralFee.bps", params.referralFee.bps);
28
+ if (bps < 0n)
29
+ throw new NegativeInputError("referralFee.bps", bps);
30
+ if (bps > BASIS_POINTS)
31
+ throw new InputExceedsMaxError({
32
+ field: "referralFee.bps",
33
+ value: bps,
34
+ max: BASIS_POINTS,
35
+ });
36
+ const { calldataOrigin } = params;
37
+ if (calldataOrigin !== undefined &&
38
+ (!isHex(calldataOrigin, { strict: true }) ||
39
+ calldataOrigin.length <= 2 ||
40
+ calldataOrigin.length % 2 !== 0))
41
+ throw new InvalidCalldataOriginError(calldataOrigin);
42
+ return {
43
+ expiresAt: Number(deadline),
44
+ deadline,
45
+ referralFeePct: bps * WAD_PER_BASIS_POINT,
46
+ referralFeeRecipient: params.referralFee?.recipient,
47
+ supportSignature: params.supportSignature ?? false,
48
+ calldataOrigin,
49
+ deployless: params.deployless,
50
+ };
51
+ }
@@ -0,0 +1,13 @@
1
+ import type { Address } from "viem";
2
+ import type { Erc2612RequirementSignature } from "../types/index.js";
3
+ import type { Action, SignatureRequest } from "./types.js";
4
+ /** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
5
+ export declare function validatePermitPlanRequest(request: Record<string, unknown>, path: string): void;
6
+ /** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
7
+ export declare function validateSignatureRequest(request: SignatureRequest, action: Action): void;
8
+ /** @internal Rebuilds a token permit from the action's account/asset and its resolved signature requests. */
9
+ export declare function getVaultPermit(requests: readonly SignatureRequest[], { id, asset, owner, }: {
10
+ readonly id: string | undefined;
11
+ readonly asset: Address;
12
+ readonly owner: Address;
13
+ }): Erc2612RequirementSignature | undefined;
@@ -0,0 +1,140 @@
1
+ import { getChainAddress } from "@morpho-org/morpho-ts";
2
+ import { IncompleteTransactionPlanError, TransactionPlanSignatureMismatchError, } from "./error.js";
3
+ import { getPlanObject, validatePlanField, validatePlanFields, } from "./validation.js";
4
+ /** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
5
+ export function validatePermitPlanRequest(request, path) {
6
+ const args = getPlanObject(request.args, `${path}.args`);
7
+ validatePlanFields(args, {
8
+ path: `${path}.args`,
9
+ fields: {
10
+ spender: "address",
11
+ amount: "uint256 bigint",
12
+ nonce: "uint256 bigint",
13
+ deadline: "uint256 bigint",
14
+ },
15
+ });
16
+ const typedData = getPlanObject(request.typedData, `${path}.typedData`);
17
+ validatePlanField(typedData.primaryType, {
18
+ path: `${path}.typedData.primaryType`,
19
+ type: "string",
20
+ });
21
+ const domain = getPlanObject(typedData.domain, `${path}.typedData.domain`);
22
+ validatePlanFields(domain, {
23
+ path: `${path}.typedData.domain`,
24
+ fields: { chainId: "positive safe integer", verifyingContract: "address" },
25
+ });
26
+ for (const field of ["name", "version"])
27
+ if (domain[field] !== undefined)
28
+ validatePlanField(domain[field], {
29
+ path: `${path}.typedData.domain.${field}`,
30
+ type: "string",
31
+ });
32
+ if (domain.salt !== undefined)
33
+ validatePlanField(domain.salt, {
34
+ path: `${path}.typedData.domain.salt`,
35
+ type: "hex",
36
+ });
37
+ const types = getPlanObject(typedData.types, `${path}.typedData.types`);
38
+ validatePlanField(types[typedData.primaryType], {
39
+ path: `${path}.typedData.types.${typedData.primaryType}`,
40
+ type: "array",
41
+ });
42
+ for (const [name, fields] of Object.entries(types)) {
43
+ const typePath = `${path}.typedData.types.${name}`;
44
+ validatePlanField(fields, { path: typePath, type: "array" });
45
+ for (const [index, field] of fields.entries()) {
46
+ const entry = getPlanObject(field, `${typePath}[${index}]`);
47
+ validatePlanFields(entry, {
48
+ path: `${typePath}[${index}]`,
49
+ fields: { name: "string", type: "string" },
50
+ });
51
+ }
52
+ }
53
+ const message = getPlanObject(typedData.message, `${path}.typedData.message`);
54
+ validatePlanFields(message, {
55
+ path: `${path}.typedData.message`,
56
+ fields: {
57
+ owner: "address",
58
+ spender: "address",
59
+ value: "uint256 bigint",
60
+ nonce: "uint256 bigint",
61
+ deadline: "uint256 bigint",
62
+ },
63
+ });
64
+ if (request.signature !== undefined)
65
+ validatePlanField(request.signature, {
66
+ path: `${path}.signature`,
67
+ type: "hex",
68
+ });
69
+ }
70
+ /** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
71
+ export function validateSignatureRequest(request, action) {
72
+ if (action.type === "erc20Approval" ||
73
+ action.signatureRequestIds.tokenPermit !== request.id)
74
+ throw new TransactionPlanSignatureMismatchError(request.id, "reference");
75
+ const { chainId, account } = action.inputs;
76
+ const { domain, message, primaryType } = request.typedData;
77
+ const spender = getChainAddress(chainId, "bundles.vaultBundlesV1");
78
+ const asset = action.type === "vaultV2Deposit"
79
+ ? action.inputs.asset
80
+ : action.inputs.vault;
81
+ const checks = [
82
+ ["domain.chainId", domain?.chainId === chainId],
83
+ [
84
+ "domain.verifyingContract",
85
+ typeof domain?.verifyingContract === "string" &&
86
+ domain.verifyingContract.toLowerCase() === asset.toLowerCase(),
87
+ ],
88
+ [
89
+ "message.owner",
90
+ typeof message?.owner === "string" &&
91
+ message.owner.toLowerCase() === account.toLowerCase(),
92
+ ],
93
+ [
94
+ "message.spender",
95
+ typeof message?.spender === "string" &&
96
+ message.spender.toLowerCase() === spender.toLowerCase(),
97
+ ],
98
+ [
99
+ "args.spender",
100
+ typeof request.args.spender === "string" &&
101
+ request.args.spender.toLowerCase() === spender.toLowerCase(),
102
+ ],
103
+ ["message.value", message?.value === request.args.amount],
104
+ [
105
+ "value",
106
+ action.type === "vaultV2Deposit"
107
+ ? request.args.amount === action.inputs.amount
108
+ : request.args.amount >= action.inputs.requiredShareAllowance,
109
+ ],
110
+ ["message.nonce", message?.nonce === request.args.nonce],
111
+ ["message.deadline", message?.deadline === request.args.deadline],
112
+ ["primaryType", primaryType === "Permit"],
113
+ ];
114
+ const mismatch = checks.find(([, matches]) => !matches);
115
+ if (mismatch)
116
+ throw new TransactionPlanSignatureMismatchError(request.id, mismatch[0]);
117
+ }
118
+ /** @internal Rebuilds a token permit from the action's account/asset and its resolved signature requests. */
119
+ export function getVaultPermit(requests, { id, asset, owner, }) {
120
+ if (id === undefined)
121
+ return undefined;
122
+ const request = requests.find((candidate) => candidate.id === id);
123
+ if (request?.signature === undefined)
124
+ throw new IncompleteTransactionPlanError(id);
125
+ return {
126
+ action: {
127
+ type: request.kind,
128
+ args: request.args,
129
+ typedData: request.typedData,
130
+ },
131
+ args: {
132
+ owner,
133
+ asset,
134
+ amount: request.args.amount,
135
+ nonce: request.args.nonce,
136
+ deadline: request.args.deadline,
137
+ signature: request.signature,
138
+ },
139
+ };
140
+ }
@@ -0,0 +1,99 @@
1
+ import { type Hex } from "viem";
2
+ import type { Transaction } from "../types/index.js";
3
+ import type { SignatureRequest, Step, TransactionPlan } from "./types.js";
4
+ /**
5
+ * Validates every request against its actions, verifies supplied ECDSA signatures synchronously,
6
+ * and attaches serialized signatures by request ID. No client or RPC is used; the EIP-712 domain
7
+ * binds the signature to its chain. Only low-s compact or serialized ECDSA permits are supported.
8
+ * Contract wallets should use `supportSignature: false` for direct approvals: deployed bundles
9
+ * consume ECDSA `v/r/s`, not arbitrary ERC-1271 or ERC-6492 signatures.
10
+ * Stored inputs remain trusted; verification does not establish the integrator's intent or protect
11
+ * a plan changed afterwards. Builders do not reverify signatures in restored plans.
12
+ * @param plan - Plan to update without mutating its requests or steps.
13
+ * @param signatures - Compact or serialized ECDSA signatures, each naming a unique existing request ID.
14
+ * @returns A new plan sharing steps and unpatched requests; omitted IDs are preserved. Empty input validates all requests and returns the original plan.
15
+ * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including when no signatures are supplied.
16
+ * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests or updates.
17
+ * @throws {TransactionPlanSignatureMismatchError} If a request disagrees with its actions, an ID is unknown, or an input ID is duplicated (`field: "duplicate"`).
18
+ * @throws {BundlesPermitMismatchError} If a supplied signature cannot be parsed by the bundle permit builders.
19
+ * @throws {InvalidSignatureError} If a signature has high s, cannot recover a public key, or does not match the permit owner and typed data.
20
+ * @example
21
+ * ```ts
22
+ * import { applySignatures, type TransactionPlan } from "@morpho-org/morpho-sdk";
23
+ * import type { Hex } from "viem";
24
+ * const complete = (plan: TransactionPlan, signature: Hex) =>
25
+ * applySignatures(plan, [{ id: "vaultV2Deposit:tokenPermit", signature }]);
26
+ * ```
27
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
28
+ */
29
+ export declare function applySignatures(plan: TransactionPlan, signatures: readonly {
30
+ readonly id: string;
31
+ readonly signature: Hex;
32
+ }[]): TransactionPlan;
33
+ /**
34
+ * Lists pending signature requests once per request ID after checking each against every referencing action.
35
+ * Sign each request's typed data with your wallet stack, then verify and attach the results with
36
+ * {@link applySignatures}.
37
+ * @param plan - Plan to inspect without changing it.
38
+ * @returns Pending requests in first-reference order, each carrying its `id`, `kind` and validated `typedData`. Dangling IDs are omitted. The SDK never signs.
39
+ * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
40
+ * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
41
+ * @throws {TransactionPlanSignatureMismatchError} If a pending permit disagrees with its action or arguments, including the action deadline, or any request has no referencing step.
42
+ * @example
43
+ * ```ts
44
+ * import { getPendingSignatureRequests, type TransactionPlan } from "@morpho-org/morpho-sdk";
45
+ * const prompts = (plan: TransactionPlan) =>
46
+ * getPendingSignatureRequests(plan).map(({ id, kind, typedData }) => ({ id, kind, typedData }));
47
+ * ```
48
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
49
+ */
50
+ export declare function getPendingSignatureRequests(plan: TransactionPlan): readonly SignatureRequest[];
51
+ /**
52
+ * Builds one transaction from a step, its fixed inputs and the signatures its action names.
53
+ * Plans are trusted as given, whether restored or supplied directly. Signature checks establish
54
+ * only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
55
+ * vaults or amounts against the intended operation. Integrators must protect stored plans from tampering.
56
+ * This builder does not verify signature ownership; use {@link applySignatures} to verify and attach signatures.
57
+ * @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
58
+ * @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
59
+ * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
60
+ * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
61
+ * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
62
+ * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
63
+ * @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
64
+ * @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
65
+ * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
66
+ * @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
67
+ * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with the step's action or its encoding arguments.
68
+ * @example
69
+ * ```ts
70
+ * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
71
+ * const resume = (saved: string) => {
72
+ * const plan = parseTransactionPlan(saved);
73
+ * return plan.steps.map((step) => buildTransaction(plan, step));
74
+ * };
75
+ * ```
76
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
77
+ */
78
+ export declare function buildTransaction(plan: TransactionPlan, step: Step): Readonly<Transaction>;
79
+ /**
80
+ * Builds every step of the plan in order.
81
+ * @param plan - Plan whose referenced signature requests all carry a signature.
82
+ * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
83
+ * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
84
+ * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
85
+ * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
86
+ * @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
87
+ * @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
88
+ * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
89
+ * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
90
+ * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with its action or encoding arguments.
91
+ * @example
92
+ * ```ts
93
+ * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
94
+ * const submit = (plan: TransactionPlan) => buildTransactions(plan);
95
+ * // Simulate and send in order from plan.account on plan.chainId.
96
+ * ```
97
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
98
+ */
99
+ export declare function buildTransactions(plan: TransactionPlan): readonly Readonly<Transaction>[];
@@ -0,0 +1,226 @@
1
+ import { deepFreeze } from "@morpho-org/morpho-ts";
2
+ import { secp256k1 } from "@noble/curves/secp256k1";
3
+ import { concatHex, hashTypedData, isAddressEqual, serializeSignature, toHex, } from "viem";
4
+ import { publicKeyToAddress } from "viem/accounts";
5
+ import { normalizeBundlesSignature } from "../actions/bundles/common.js";
6
+ import { encodeErc20Approval } from "../actions/index.js";
7
+ import { InvalidSignatureError } from "../types/error.js";
8
+ import { IncompleteTransactionPlanError, TransactionPlanSignatureMismatchError, } from "./error.js";
9
+ import { validateSignatureRequest } from "./permit.js";
10
+ import { validateTransactionPlanActions } from "./validateActions.js";
11
+ import { buildVaultV2Deposit } from "./vaultv2/deposit.js";
12
+ import { buildVaultV2Withdraw } from "./vaultv2/withdraw.js";
13
+ import { validateTransactionPlanVersion } from "./version.js";
14
+ /**
15
+ * Validates every request against its actions, verifies supplied ECDSA signatures synchronously,
16
+ * and attaches serialized signatures by request ID. No client or RPC is used; the EIP-712 domain
17
+ * binds the signature to its chain. Only low-s compact or serialized ECDSA permits are supported.
18
+ * Contract wallets should use `supportSignature: false` for direct approvals: deployed bundles
19
+ * consume ECDSA `v/r/s`, not arbitrary ERC-1271 or ERC-6492 signatures.
20
+ * Stored inputs remain trusted; verification does not establish the integrator's intent or protect
21
+ * a plan changed afterwards. Builders do not reverify signatures in restored plans.
22
+ * @param plan - Plan to update without mutating its requests or steps.
23
+ * @param signatures - Compact or serialized ECDSA signatures, each naming a unique existing request ID.
24
+ * @returns A new plan sharing steps and unpatched requests; omitted IDs are preserved. Empty input validates all requests and returns the original plan.
25
+ * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including when no signatures are supplied.
26
+ * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests or updates.
27
+ * @throws {TransactionPlanSignatureMismatchError} If a request disagrees with its actions, an ID is unknown, or an input ID is duplicated (`field: "duplicate"`).
28
+ * @throws {BundlesPermitMismatchError} If a supplied signature cannot be parsed by the bundle permit builders.
29
+ * @throws {InvalidSignatureError} If a signature has high s, cannot recover a public key, or does not match the permit owner and typed data.
30
+ * @example
31
+ * ```ts
32
+ * import { applySignatures, type TransactionPlan } from "@morpho-org/morpho-sdk";
33
+ * import type { Hex } from "viem";
34
+ * const complete = (plan: TransactionPlan, signature: Hex) =>
35
+ * applySignatures(plan, [{ id: "vaultV2Deposit:tokenPermit", signature }]);
36
+ * ```
37
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
38
+ */
39
+ export function applySignatures(plan, signatures) {
40
+ // Reject unknown formats before interpreting stored fields or signature updates.
41
+ validateTransactionPlanVersion(plan.version);
42
+ // Reject unknown actions before reading signature requests or updates.
43
+ validateTransactionPlanActions(plan.steps);
44
+ const requests = getPendingSignatureRequests({
45
+ ...plan,
46
+ signatureRequests: plan.signatureRequests.map((request) => ({
47
+ ...request,
48
+ signature: undefined,
49
+ })),
50
+ });
51
+ const updates = new Map();
52
+ for (const { id, signature } of signatures) {
53
+ if (!requests.some((request) => request.id === id))
54
+ throw new TransactionPlanSignatureMismatchError(id, "reference");
55
+ if (updates.has(id))
56
+ throw new TransactionPlanSignatureMismatchError(id, "duplicate");
57
+ updates.set(id, signature);
58
+ }
59
+ if (updates.size === 0)
60
+ return plan;
61
+ for (const [id, signature] of updates) {
62
+ const request = requests.find((candidate) => candidate.id === id);
63
+ const normalized = normalizeBundlesSignature(signature);
64
+ let recovered;
65
+ try {
66
+ const ecdsa = new secp256k1.Signature(BigInt(normalized.r), BigInt(normalized.s));
67
+ if (ecdsa.hasHighS())
68
+ throw new InvalidSignatureError();
69
+ const publicKey = ecdsa
70
+ .addRecoveryBit(normalized.v - 27)
71
+ .recoverPublicKey(hashTypedData(request.typedData).slice(2));
72
+ recovered = publicKeyToAddress(toHex(publicKey.toRawBytes(false)));
73
+ }
74
+ catch {
75
+ throw new InvalidSignatureError();
76
+ }
77
+ if (!isAddressEqual(recovered, request.typedData.message.owner))
78
+ throw new InvalidSignatureError();
79
+ updates.set(id, serializeSignature({ ...normalized, v: BigInt(normalized.v) }));
80
+ }
81
+ return {
82
+ ...plan,
83
+ signatureRequests: plan.signatureRequests.map((request) => updates.has(request.id)
84
+ ? { ...request, signature: updates.get(request.id) }
85
+ : request),
86
+ };
87
+ }
88
+ /** @internal Lists the signature request IDs a step's action names, in role order. */
89
+ function getStepSignatureRequestIds(step) {
90
+ const { action } = step;
91
+ if (!("signatureRequestIds" in action))
92
+ return [];
93
+ return Object.values(action.signatureRequestIds).filter((id) => id !== undefined);
94
+ }
95
+ /**
96
+ * Lists pending signature requests once per request ID after checking each against every referencing action.
97
+ * Sign each request's typed data with your wallet stack, then verify and attach the results with
98
+ * {@link applySignatures}.
99
+ * @param plan - Plan to inspect without changing it.
100
+ * @returns Pending requests in first-reference order, each carrying its `id`, `kind` and validated `typedData`. Dangling IDs are omitted. The SDK never signs.
101
+ * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
102
+ * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
103
+ * @throws {TransactionPlanSignatureMismatchError} If a pending permit disagrees with its action or arguments, including the action deadline, or any request has no referencing step.
104
+ * @example
105
+ * ```ts
106
+ * import { getPendingSignatureRequests, type TransactionPlan } from "@morpho-org/morpho-sdk";
107
+ * const prompts = (plan: TransactionPlan) =>
108
+ * getPendingSignatureRequests(plan).map(({ id, kind, typedData }) => ({ id, kind, typedData }));
109
+ * ```
110
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
111
+ */
112
+ export function getPendingSignatureRequests(plan) {
113
+ // Reject unknown formats before interpreting stored fields.
114
+ validateTransactionPlanVersion(plan.version);
115
+ // Reject unknown actions before exposing signature requests.
116
+ validateTransactionPlanActions(plan.steps);
117
+ const referenced = new Map();
118
+ for (const step of plan.steps) {
119
+ for (const id of getStepSignatureRequestIds(step)) {
120
+ referenced.set(id, [...(referenced.get(id) ?? []), step.action]);
121
+ }
122
+ }
123
+ for (const request of plan.signatureRequests) {
124
+ const actions = referenced.get(request.id);
125
+ if (actions === undefined)
126
+ throw new TransactionPlanSignatureMismatchError(request.id, "reference");
127
+ if (request.signature === undefined) {
128
+ for (const action of actions) {
129
+ validateSignatureRequest(request, action);
130
+ if (action.type !== "erc20Approval" &&
131
+ request.args.deadline !== action.inputs.deadline)
132
+ throw new TransactionPlanSignatureMismatchError(request.id, "args.deadline");
133
+ }
134
+ }
135
+ }
136
+ return [...referenced.keys()].flatMap((id) => {
137
+ const request = plan.signatureRequests.find((candidate) => candidate.id === id);
138
+ return request && request.signature === undefined ? [request] : [];
139
+ });
140
+ }
141
+ function encodeStep(action, requests) {
142
+ switch (action.type) {
143
+ case "erc20Approval":
144
+ return encodeErc20Approval(action.inputs);
145
+ case "vaultV2Deposit":
146
+ return buildVaultV2Deposit(action, requests);
147
+ case "vaultV2Withdraw":
148
+ return buildVaultV2Withdraw(action, requests);
149
+ }
150
+ }
151
+ /**
152
+ * Builds one transaction from a step, its fixed inputs and the signatures its action names.
153
+ * Plans are trusted as given, whether restored or supplied directly. Signature checks establish
154
+ * only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
155
+ * vaults or amounts against the intended operation. Integrators must protect stored plans from tampering.
156
+ * This builder does not verify signature ownership; use {@link applySignatures} to verify and attach signatures.
157
+ * @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
158
+ * @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
159
+ * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
160
+ * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
161
+ * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
162
+ * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
163
+ * @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
164
+ * @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
165
+ * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
166
+ * @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
167
+ * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with the step's action or its encoding arguments.
168
+ * @example
169
+ * ```ts
170
+ * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
171
+ * const resume = (saved: string) => {
172
+ * const plan = parseTransactionPlan(saved);
173
+ * return plan.steps.map((step) => buildTransaction(plan, step));
174
+ * };
175
+ * ```
176
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
177
+ */
178
+ export function buildTransaction(plan, step) {
179
+ // Reject unknown formats before interpreting stored fields.
180
+ validateTransactionPlanVersion(plan.version);
181
+ // Check the whole plan and any separately selected step before reading requests.
182
+ validateTransactionPlanActions([...plan.steps, step]);
183
+ const requests = getStepSignatureRequestIds(step).map((id) => {
184
+ const request = plan.signatureRequests.find((candidate) => candidate.id === id);
185
+ if (request === undefined)
186
+ throw new IncompleteTransactionPlanError(id);
187
+ validateSignatureRequest(request, step.action);
188
+ return request;
189
+ });
190
+ const { to, value, data, action } = encodeStep(step.action, requests);
191
+ return deepFreeze({
192
+ to,
193
+ value,
194
+ data: plan.calldataOrigin === undefined
195
+ ? data
196
+ : concatHex([data, plan.calldataOrigin]),
197
+ action,
198
+ });
199
+ }
200
+ /**
201
+ * Builds every step of the plan in order.
202
+ * @param plan - Plan whose referenced signature requests all carry a signature.
203
+ * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
204
+ * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
205
+ * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
206
+ * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
207
+ * @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
208
+ * @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
209
+ * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
210
+ * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
211
+ * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with its action or encoding arguments.
212
+ * @example
213
+ * ```ts
214
+ * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
215
+ * const submit = (plan: TransactionPlan) => buildTransactions(plan);
216
+ * // Simulate and send in order from plan.account on plan.chainId.
217
+ * ```
218
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
219
+ */
220
+ export function buildTransactions(plan) {
221
+ // Reject unknown formats even when there are no steps to build.
222
+ validateTransactionPlanVersion(plan.version);
223
+ // Validate every action before the first step can interpret requests.
224
+ validateTransactionPlanActions(plan.steps);
225
+ return plan.steps.map((step) => buildTransaction(plan, step));
226
+ }
@@ -0,0 +1,44 @@
1
+ import { type Address, type Client } from "viem";
2
+ import type { ERC20ApprovalAction, Erc2612RequirementSignature, Requirement, Transaction } from "../types/index.js";
3
+ import type { Action, SignatureRequest, Step } from "./types.js";
4
+ /**
5
+ * @internal Converts an ERC-2612 requirement into a plan-local signature request.
6
+ * @param requirement - Permit requirement carrying its typed data and encoding arguments.
7
+ * @param id - Signature request ID selected by the preparer.
8
+ * @returns The unsigned request with a concrete nonce.
9
+ * @throws {UnexpectedRequirementSignatureError} If the permit requirement has no nonce.
10
+ */
11
+ export declare function buildPermitSignatureRequest(requirement: Requirement<Erc2612RequirementSignature>, id: string): SignatureRequest;
12
+ /**
13
+ * @internal Converts an approval transaction into a step with prepared chain/account inputs.
14
+ * @param requirement - Direct token approval prerequisite.
15
+ * @param params - Step ID, chain and account selected by the preparer.
16
+ * @returns The approval recipe labeled for token spending.
17
+ */
18
+ export declare function buildApprovalStep(requirement: Readonly<Transaction<ERC20ApprovalAction>>, { id, chainId, account, }: {
19
+ readonly id: string;
20
+ readonly chainId: number;
21
+ readonly account: Address;
22
+ }): Step<Extract<Action, {
23
+ type: "erc20Approval";
24
+ }>>;
25
+ /** @internal Token pull prerequisites: direct approvals or an ERC-2612 permit. */
26
+ type TokenRequirement = Readonly<Transaction<ERC20ApprovalAction>> | Requirement<Erc2612RequirementSignature>;
27
+ interface TokenRequirementsParams {
28
+ readonly token: Address;
29
+ readonly spender: Address;
30
+ readonly amount: bigint;
31
+ readonly owner: Address;
32
+ readonly chainId: number;
33
+ readonly deadline: bigint;
34
+ readonly now: bigint;
35
+ readonly supportSignature: boolean;
36
+ readonly deployless: boolean | undefined;
37
+ }
38
+ /**
39
+ * @internal Resolves the token prerequisite of a VaultBundlesV1 pull without Permit2. A sufficient
40
+ * direct allowance yields nothing. Otherwise signature support prefers an ERC-2612 permit when
41
+ * available and falls back to a direct unlimited approval. Without signature support, always approve.
42
+ */
43
+ export declare function getTokenRequirements(client: Client, params: TokenRequirementsParams): Promise<readonly TokenRequirement[]>;
44
+ export {};