@morpho-org/morpho-sdk 9.6.0 → 9.8.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 (87) hide show
  1. package/MIGRATION-v6-to-v7.md +1 -1
  2. package/README.md +64 -3
  3. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +12 -46
  4. package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -0
  5. package/lib/cjs/entities/requirements/getErc2612Permit.js +60 -0
  6. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
  7. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +3 -3
  8. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -2
  9. package/lib/cjs/helpers/validateMidnightCollateralBatch.d.ts +1 -0
  10. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +1 -0
  11. package/lib/cjs/index.d.ts +3 -0
  12. package/lib/cjs/index.js +20 -1
  13. package/lib/cjs/transactionPlan/approval.d.ts +2 -0
  14. package/lib/cjs/transactionPlan/approval.js +16 -0
  15. package/lib/cjs/transactionPlan/error.d.ts +145 -0
  16. package/lib/cjs/transactionPlan/error.js +186 -0
  17. package/lib/cjs/transactionPlan/getTokenPermit.d.ts +11 -0
  18. package/lib/cjs/transactionPlan/getTokenPermit.js +18 -0
  19. package/lib/cjs/transactionPlan/index.d.ts +9 -0
  20. package/lib/cjs/transactionPlan/index.js +24 -0
  21. package/lib/cjs/transactionPlan/intent.d.ts +51 -0
  22. package/lib/cjs/transactionPlan/intent.js +54 -0
  23. package/lib/cjs/transactionPlan/permit.d.ts +13 -0
  24. package/lib/cjs/transactionPlan/permit.js +145 -0
  25. package/lib/cjs/transactionPlan/plan.d.ts +99 -0
  26. package/lib/cjs/transactionPlan/plan.js +232 -0
  27. package/lib/cjs/transactionPlan/requirements.d.ts +44 -0
  28. package/lib/cjs/transactionPlan/requirements.js +79 -0
  29. package/lib/cjs/transactionPlan/serde.d.ts +33 -0
  30. package/lib/cjs/transactionPlan/serde.js +205 -0
  31. package/lib/cjs/transactionPlan/types.d.ts +91 -0
  32. package/lib/cjs/transactionPlan/types.js +2 -0
  33. package/lib/cjs/transactionPlan/validateActions.d.ts +8 -0
  34. package/lib/cjs/transactionPlan/validateActions.js +19 -0
  35. package/lib/cjs/transactionPlan/validation.d.ts +17 -0
  36. package/lib/cjs/transactionPlan/validation.js +70 -0
  37. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +81 -0
  38. package/lib/cjs/transactionPlan/vaultv2/deposit.js +211 -0
  39. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +77 -0
  40. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +190 -0
  41. package/lib/cjs/transactionPlan/version.d.ts +2 -0
  42. package/lib/cjs/transactionPlan/version.js +9 -0
  43. package/lib/cjs/version.d.ts +2 -0
  44. package/lib/cjs/version.js +6 -0
  45. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +14 -48
  46. package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -0
  47. package/lib/esm/entities/requirements/getErc2612Permit.js +57 -0
  48. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
  49. package/lib/esm/entities/vaultV1/vaultV1.d.ts +3 -3
  50. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -2
  51. package/lib/esm/helpers/validateMidnightCollateralBatch.d.ts +1 -0
  52. package/lib/esm/helpers/validateMidnightCollateralBatch.js +1 -0
  53. package/lib/esm/index.d.ts +3 -0
  54. package/lib/esm/index.js +2 -0
  55. package/lib/esm/transactionPlan/approval.d.ts +2 -0
  56. package/lib/esm/transactionPlan/approval.js +13 -0
  57. package/lib/esm/transactionPlan/error.d.ts +145 -0
  58. package/lib/esm/transactionPlan/error.js +175 -0
  59. package/lib/esm/transactionPlan/getTokenPermit.d.ts +11 -0
  60. package/lib/esm/transactionPlan/getTokenPermit.js +15 -0
  61. package/lib/esm/transactionPlan/index.d.ts +9 -0
  62. package/lib/esm/transactionPlan/index.js +5 -0
  63. package/lib/esm/transactionPlan/intent.d.ts +51 -0
  64. package/lib/esm/transactionPlan/intent.js +51 -0
  65. package/lib/esm/transactionPlan/permit.d.ts +13 -0
  66. package/lib/esm/transactionPlan/permit.js +140 -0
  67. package/lib/esm/transactionPlan/plan.d.ts +99 -0
  68. package/lib/esm/transactionPlan/plan.js +226 -0
  69. package/lib/esm/transactionPlan/requirements.d.ts +44 -0
  70. package/lib/esm/transactionPlan/requirements.js +74 -0
  71. package/lib/esm/transactionPlan/serde.d.ts +33 -0
  72. package/lib/esm/transactionPlan/serde.js +201 -0
  73. package/lib/esm/transactionPlan/types.d.ts +91 -0
  74. package/lib/esm/transactionPlan/types.js +1 -0
  75. package/lib/esm/transactionPlan/validateActions.d.ts +8 -0
  76. package/lib/esm/transactionPlan/validateActions.js +16 -0
  77. package/lib/esm/transactionPlan/validation.d.ts +17 -0
  78. package/lib/esm/transactionPlan/validation.js +64 -0
  79. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +81 -0
  80. package/lib/esm/transactionPlan/vaultv2/deposit.js +206 -0
  81. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +77 -0
  82. package/lib/esm/transactionPlan/vaultv2/withdraw.js +185 -0
  83. package/lib/esm/transactionPlan/version.d.ts +2 -0
  84. package/lib/esm/transactionPlan/version.js +6 -0
  85. package/lib/esm/version.d.ts +2 -0
  86. package/lib/esm/version.js +3 -0
  87. package/package.json +8 -7
@@ -294,4 +294,4 @@ Removed: `cancelOffer`, `midnightCancelOffer`, `MidnightCancelOfferParams`, `Mid
294
294
 
295
295
  ## Deployment
296
296
 
297
- MidnightBundlesV2 is pinned on Ethereum, Base, Arc, and Robinhood.
297
+ MidnightBundlesV2 is pinned on Ethereum, Base, Arbitrum, Arc, Robinhood, and Tempo.
package/README.md CHANGED
@@ -55,10 +55,10 @@ BlueBundlesV1, and the remaining rows identify their destination.
55
55
  | | `inKindRedeem` | VaultExitBundlesV1 |
56
56
  | **Blue** | `supply`, `withdraw`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `refinance` | BlueBundlesV1 |
57
57
  | **Blue** | `withdrawBuyCallback` | Morpho Blue (direct `withdraw` for a BlueBuyCallback's owner) |
58
- | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `takeRepayWithdrawCollateral`, `repayWithdrawCollateral`, `takeWithdraw` | MidnightBundlesV2 (Ethereum, Base, Arc, Robinhood, Tempo) |
58
+ | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `takeRepayWithdrawCollateral`, `repayWithdrawCollateral`, `takeWithdraw` | MidnightBundlesV2 (Ethereum, Base, Arbitrum, Arc, Robinhood, Tempo) |
59
59
  | | `supplyCollateral`, `withdrawCollateral`, `redeem` | Direct call |
60
60
  | | `supplyCollateralBatch`, `withdrawCollateralBatch` | Midnight multicall |
61
- | | `makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`, `supplyCollateralMakeBorrow`, `supplyBlueMakeLend`, `cancelOffers` | MidnightBundlesV2 (Ethereum, Base, Arc, Robinhood, Tempo) |
61
+ | | `makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`, `supplyCollateralMakeBorrow`, `supplyBlueMakeLend`, `cancelOffers` | MidnightBundlesV2 (Ethereum, Base, Arbitrum, Arc, Robinhood, Tempo) |
62
62
 
63
63
  `makeBorrow` publishes without collateral; `supplyCollateralMakeBorrow` requires collateral and
64
64
  supplies it in the same transaction.
@@ -268,11 +268,72 @@ instant liquidation. Blue writes do not accept `slippageTolerance`, `minSharePri
268
268
  > High-level Blue writes and shared-liquidity planning use Vault V2 only. Vault V1 allocator and
269
269
  > low-level composition surfaces were removed in v6; direct Vault V1 flows remain.
270
270
 
271
+ ### TransactionPlan: sign and verify permits
272
+
273
+ > **Beta:** TransactionPlan is experimental; breaking changes may ship in minor releases.
274
+ > Existing entity flows remain the recommended stable path during the shadow-mode rollout.
275
+
276
+ Prepare a Vault V2 deposit or withdrawal plan, then sign its pending requests with your wallet.
277
+ `applySignatures(plan, signatures)` synchronously verifies every supplied signature before attaching
278
+ it, without a client or RPC. It validates all requests against their actions, including permit/action
279
+ deadline agreement, rejects unknown or duplicate input IDs, and recovers the permit owner from the
280
+ EIP-712 typed-data hash. The domain
281
+ binds the signature to its chain. Only low-s ECDSA permits encodable as `v/r/s` are supported
282
+ (64-byte compact or 65-byte serialized signatures, stored in serialized form). Contract wallets
283
+ should use `supportSignature: false` for direct approvals: deployed bundles do not consume
284
+ arbitrary ERC-1271 or ERC-6492 signatures.
285
+
286
+ `parseTransactionPlan` revives bigint tags and validates supported versions/actions, field shapes
287
+ and uint256 ranges, unique IDs, references, action chain/account agreement and permit consistency,
288
+ including requests with existing signatures. It allows extra keys. Malformed JSON, shapes or
289
+ references throw `InvalidTransactionPlanError` with a JSON `path` and `reason`; unsupported versions
290
+ and action types retain their dedicated errors. Serialization remains unchecked. Parsing uses no
291
+ clock or RPC and does not check expiry, live state, signature ownership or action-layer business
292
+ constraints. It does not prove authenticity or intent: tampered-but-well-formed, internally consistent
293
+ plans pass, so integrators must still protect stored plans.
294
+
295
+ When existing allowance is insufficient, withdrawal plans request an unlimited (`maxUint256`)
296
+ ERC-2612 vault-share permit or direct share approval. The quote's `requiredShareAllowance` remains
297
+ the minimum needed for that withdrawal; later withdrawals reuse sufficient allowance without a
298
+ new signature. Deposit asset permits must instead sign the exact pull amount, not an unlimited
299
+ value. Existing stored withdrawal permits covering the minimum allowance remain supported.
300
+
301
+ Only deposit plans accept `slippageTolerance`, which sets their on-chain maximum share price.
302
+ Withdrawal plans do not accept it: the share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE`
303
+ internally, but withdrawals have no on-chain share-price or maximum-shares bound. A price drop
304
+ before inclusion can burn more shares than quoted.
305
+
306
+ ```typescript
307
+ import {
308
+ buildTransactions,
309
+ getPendingSignatureRequests,
310
+ applySignatures,
311
+ type TransactionPlan,
312
+ } from "@morpho-org/morpho-sdk";
313
+ import type { WalletClient } from "viem";
314
+ import { signTypedData } from "viem/actions";
315
+
316
+ async function finalize(wallet: WalletClient, plan: TransactionPlan) {
317
+ const signatures = await Promise.all(
318
+ getPendingSignatureRequests(plan).map(async ({ id, typedData }) => ({
319
+ id,
320
+ signature: await signTypedData(wallet, { ...typedData, account: plan.account }),
321
+ })),
322
+ );
323
+ return buildTransactions(applySignatures(plan, signatures));
324
+ }
325
+ ```
326
+
327
+ Protect stored plans: verification checks permit consistency and signers, not whether stored action
328
+ inputs match your intended operation. Builders do not reverify signatures in restored plans. Do not
329
+ change the plan after applying signatures. Empty signature input still validates all requests and
330
+ returns the original plan; omitted IDs retain their existing signatures.
331
+
271
332
  ### Midnight: take a fixed-rate offer
272
333
 
273
334
  Protocol-specific names are qualified in shared facades, for example `fetchBluePosition` and `fetchMidnightPosition` from `@morpho-org/morpho-sdk/fetch`. Canonical raw upstream names remain available under `/blue/{abis,addresses,constants,entities,errors,fetch,types,utils}` and `/midnight/{abis,constants,entities,errors,fetch,types,utils}`.
274
335
 
275
- Morpho-ts registers MidnightBundlesV2 on Ethereum, Base, Arc, Robinhood, and Tempo.
336
+ Morpho-ts registers MidnightBundlesV2 on Ethereum, Base, Arbitrum, Arc, Robinhood, and Tempo.
276
337
 
277
338
  ```typescript
278
339
  const midnight = client.morpho.midnight(8453);
@@ -2,15 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBundlesTokenRequirements = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
6
  const viem_1 = require("viem");
8
7
  const actions_1 = require("viem/actions");
9
8
  const index_js_1 = require("../../actions/bundles/index.js");
10
- const encodeErc20Permit_js_1 = require("../../actions/requirements/encode/encodeErc20Permit.js");
11
9
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
10
  const index_js_2 = require("../../helpers/index.js");
13
11
  const index_js_3 = require("../../types/index.js");
12
+ const getErc2612Permit_js_1 = require("./getErc2612Permit.js");
14
13
  /**
15
14
  * Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
16
15
  *
@@ -129,51 +128,18 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
129
128
  if (params.supportSignature) {
130
129
  const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
131
130
  if ((params.useSimplePermit ?? true) && !isDai) {
132
- const nonce = await (0, actions_1.readContract)(viemClient, {
133
- abi: blue_sdk_viem_1.erc2612Abi,
134
- address: params.token,
135
- functionName: "nonces",
136
- args: [params.owner],
137
- }).catch((error) => {
138
- if ((0, blue_sdk_viem_1.isTransportError)(error))
139
- throw error;
140
- if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))
141
- return undefined;
142
- throw error;
131
+ const permit = await (0, getErc2612Permit_js_1.getErc2612Permit)(viemClient, {
132
+ token: params.token,
133
+ owner: params.owner,
134
+ spender: params.spender,
135
+ amount: params.amount,
136
+ chainId: params.chainId,
137
+ deadline: params.deadline,
138
+ now: timestamp,
139
+ supportDeployless: params.supportDeployless,
143
140
  });
144
- if ((0, morpho_ts_1.isDefined)(nonce)) {
145
- const permit = await (0, morpho_ts_1._try)(() => (0, encodeErc20Permit_js_1.encodeErc20Permit)(viemClient, {
146
- token: params.token,
147
- owner: params.owner,
148
- spender: params.spender,
149
- amount: params.amount,
150
- chainId: params.chainId,
151
- nonce,
152
- deadline: params.deadline,
153
- now: timestamp,
154
- supportDeployless: params.supportDeployless,
155
- }), blue_sdk_viem_1.MissingPermitDomainNameError, blue_sdk_viem_1.InvalidPermitDomainChainIdError, blue_sdk_viem_1.InvalidPermitDomainVerifyingContractError, blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError);
156
- if ((0, morpho_ts_1.isDefined)(permit)) {
157
- const separator = await (0, actions_1.readContract)(viemClient, {
158
- abi: blue_sdk_viem_1.erc2612Abi,
159
- address: params.token,
160
- functionName: "DOMAIN_SEPARATOR",
161
- }).catch((error) => {
162
- if ((0, blue_sdk_viem_1.isTransportError)(error))
163
- throw error;
164
- if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))
165
- return undefined;
166
- throw error;
167
- });
168
- const domain = permit.action.typedData.domain ?? {};
169
- if (separator?.toLowerCase() ===
170
- (0, viem_1.hashDomain)({
171
- domain,
172
- types: { EIP712Domain: (0, viem_1.getTypesForEIP712Domain)({ domain }) },
173
- }).toLowerCase())
174
- return [permit];
175
- }
176
- }
141
+ if ((0, morpho_ts_1.isDefined)(permit))
142
+ return [permit];
177
143
  }
178
144
  }
179
145
  return (0, index_js_1.resolveBundlesTokenRequirements)({
@@ -0,0 +1,7 @@
1
+ import { type Client } from "viem";
2
+ import { encodeErc20Permit } from "../../actions/requirements/encode/encodeErc20Permit.js";
3
+ /**
4
+ * @internal Resolves ERC-2612 eligibility from the nonce, signing domain and onchain separator.
5
+ * Unsupported domains and reverted or undecodable probes return undefined; other errors propagate.
6
+ */
7
+ export declare function getErc2612Permit(viemClient: Client, params: Omit<Parameters<typeof encodeErc20Permit>[1], "nonce">): Promise<import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined> | undefined>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErc2612Permit = getErc2612Permit;
4
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const actions_1 = require("viem/actions");
8
+ const encodeErc20Permit_js_1 = require("../../actions/requirements/encode/encodeErc20Permit.js");
9
+ /**
10
+ * @internal Resolves ERC-2612 eligibility from the nonce, signing domain and onchain separator.
11
+ * Unsupported domains and reverted or undecodable probes return undefined; other errors propagate.
12
+ */
13
+ async function getErc2612Permit(viemClient, params) {
14
+ const nonce = await (0, actions_1.readContract)(viemClient, {
15
+ abi: blue_sdk_viem_1.erc2612Abi,
16
+ address: params.token,
17
+ functionName: "nonces",
18
+ args: [params.owner],
19
+ }).catch((error) => {
20
+ if ((0, blue_sdk_viem_1.isTransportError)(error))
21
+ throw error;
22
+ if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))
23
+ return undefined;
24
+ throw error;
25
+ });
26
+ if ((0, morpho_ts_1.isDefined)(nonce)) {
27
+ const permit = await (0, morpho_ts_1._try)(() => (0, encodeErc20Permit_js_1.encodeErc20Permit)(viemClient, {
28
+ token: params.token,
29
+ owner: params.owner,
30
+ spender: params.spender,
31
+ amount: params.amount,
32
+ chainId: params.chainId,
33
+ nonce,
34
+ deadline: params.deadline,
35
+ now: params.now,
36
+ supportDeployless: params.supportDeployless,
37
+ }), blue_sdk_viem_1.MissingPermitDomainNameError, blue_sdk_viem_1.InvalidPermitDomainChainIdError, blue_sdk_viem_1.InvalidPermitDomainVerifyingContractError, blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError);
38
+ if ((0, morpho_ts_1.isDefined)(permit)) {
39
+ const separator = await (0, actions_1.readContract)(viemClient, {
40
+ abi: blue_sdk_viem_1.erc2612Abi,
41
+ address: params.token,
42
+ functionName: "DOMAIN_SEPARATOR",
43
+ }).catch((error) => {
44
+ if ((0, blue_sdk_viem_1.isTransportError)(error))
45
+ throw error;
46
+ if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))
47
+ return undefined;
48
+ throw error;
49
+ });
50
+ const domain = permit.action.typedData.domain ?? {};
51
+ if (separator?.toLowerCase() ===
52
+ (0, viem_1.hashDomain)({
53
+ domain,
54
+ types: { EIP712Domain: (0, viem_1.getTypesForEIP712Domain)({ domain }) },
55
+ }).toLowerCase())
56
+ return permit;
57
+ }
58
+ }
59
+ return undefined;
60
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Token } from "@morpho-org/blue-sdk";
2
2
  import type { Address, Client } from "viem";
3
- import { type ActionRequirement } from "../../types/index.js";
3
+ import { type ERC20ApprovalAction, type PermitRequirementSignature, type Requirement, type Transaction } from "../../types/index.js";
4
4
  /**
5
5
  * Resolves the vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
6
6
  *
@@ -27,4 +27,4 @@ export declare const getVaultBundlesSharesRequirements: (viemClient: Client, par
27
27
  readonly deadline: bigint;
28
28
  readonly supportSignature: boolean;
29
29
  readonly now?: bigint;
30
- }) => Promise<readonly ActionRequirement[]>;
30
+ }) => Promise<readonly (Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
@@ -500,7 +500,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
500
500
  readonly referralFeeRecipient?: Address;
501
501
  readonly deadline?: bigint;
502
502
  }): Readonly<{
503
- getRequirements: () => Promise<readonly ActionRequirement[]>;
503
+ getRequirements: () => Promise<readonly (Readonly<import("../../index.js").Transaction<import("../../index.js").ERC20ApprovalAction>> | import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined>)[]>;
504
504
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<VaultV1WithdrawAction>>;
505
505
  }>;
506
506
  /** {@inheritDoc VaultV1Actions.redeem} */
@@ -511,7 +511,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
511
511
  readonly referralFeeRecipient?: Address;
512
512
  readonly deadline?: bigint;
513
513
  }): Readonly<{
514
- getRequirements: () => Promise<readonly ActionRequirement[]>;
514
+ getRequirements: () => Promise<readonly (Readonly<import("../../index.js").Transaction<import("../../index.js").ERC20ApprovalAction>> | import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined>)[]>;
515
515
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<VaultV1RedeemAction>>;
516
516
  }>;
517
517
  /** {@inheritDoc VaultV1Actions.inKindRedeem} */
@@ -532,7 +532,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
532
532
  readonly referralFeeRecipient?: Address;
533
533
  readonly deadline?: bigint;
534
534
  } & VaultV1MigrateToV2AmountArgs): Readonly<{
535
- getRequirements: () => Promise<readonly ActionRequirement[]>;
535
+ getRequirements: () => Promise<readonly (Readonly<import("../../index.js").Transaction<import("../../index.js").ERC20ApprovalAction>> | import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined>)[]>;
536
536
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<VaultV1MigrateToV2Action>>;
537
537
  }>;
538
538
  }
@@ -574,7 +574,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
574
574
  readonly referralFeeRecipient?: Address;
575
575
  readonly deadline?: bigint;
576
576
  }): Readonly<{
577
- getRequirements: () => Promise<readonly ActionRequirement[]>;
577
+ getRequirements: () => Promise<readonly (Readonly<Transaction<import("../../index.js").ERC20ApprovalAction>> | import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined>)[]>;
578
578
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2WithdrawAction>>;
579
579
  }>;
580
580
  /** {@inheritDoc VaultV2Actions.redeem} */
@@ -585,7 +585,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
585
585
  readonly referralFeeRecipient?: Address;
586
586
  readonly deadline?: bigint;
587
587
  }): Readonly<{
588
- getRequirements: () => Promise<readonly ActionRequirement[]>;
588
+ getRequirements: () => Promise<readonly (Readonly<Transaction<import("../../index.js").ERC20ApprovalAction>> | import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined>)[]>;
589
589
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2RedeemAction>>;
590
590
  }>;
591
591
  /** {@inheritDoc VaultV2Actions.inKindRedeem} */
@@ -5,6 +5,7 @@ import type { MidnightCollateralTransfer } from "../types/action.js";
5
5
  * @param transfers - Ordered collateral transfers.
6
6
  * @param emptyError - Operation-specific error thrown for an empty batch.
7
7
  * @returns Nothing.
8
+ * @throws `emptyError` when `transfers` is empty.
8
9
  * @throws {DuplicateMidnightCollateralIndexError} when an index appears twice.
9
10
  * @example
10
11
  * ```ts
@@ -8,6 +8,7 @@ const error_js_1 = require("../types/error.js");
8
8
  * @param transfers - Ordered collateral transfers.
9
9
  * @param emptyError - Operation-specific error thrown for an empty batch.
10
10
  * @returns Nothing.
11
+ * @throws `emptyError` when `transfers` is empty.
11
12
  * @throws {DuplicateMidnightCollateralIndexError} when an index appears twice.
12
13
  * @example
13
14
  * ```ts
@@ -3,4 +3,7 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
3
3
  export * from "./client/index.js";
4
4
  export * from "./entities/requirements/index.js";
5
5
  export * from "./helpers/index.js";
6
+ export type { Action, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV2DepositPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
7
+ export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV2Deposit, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
6
8
  export * from "./types/index.js";
9
+ export { version } from "./version.js";
package/lib/cjs/index.js CHANGED
@@ -14,11 +14,30 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.validateClientChainId = void 0;
17
+ exports.version = exports.ZeroAccountError = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.serializeTransactionPlan = exports.prepareVaultV2Withdraw = exports.prepareVaultV2Deposit = exports.parseTransactionPlan = exports.NonIntegerInputError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.applySignatures = exports.validateClientChainId = void 0;
18
18
  __exportStar(require("./actions/index.js"), exports);
19
19
  var validateClientChainId_js_1 = require("./actions/requirements/validateClientChainId.js");
20
20
  Object.defineProperty(exports, "validateClientChainId", { enumerable: true, get: function () { return validateClientChainId_js_1.validateClientChainId; } });
21
21
  __exportStar(require("./client/index.js"), exports);
22
22
  __exportStar(require("./entities/requirements/index.js"), exports);
23
23
  __exportStar(require("./helpers/index.js"), exports);
24
+ var index_js_1 = require("./transactionPlan/index.js");
25
+ Object.defineProperty(exports, "applySignatures", { enumerable: true, get: function () { return index_js_1.applySignatures; } });
26
+ Object.defineProperty(exports, "buildTransaction", { enumerable: true, get: function () { return index_js_1.buildTransaction; } });
27
+ Object.defineProperty(exports, "buildTransactions", { enumerable: true, get: function () { return index_js_1.buildTransactions; } });
28
+ Object.defineProperty(exports, "getPendingSignatureRequests", { enumerable: true, get: function () { return index_js_1.getPendingSignatureRequests; } });
29
+ Object.defineProperty(exports, "IncompleteTransactionPlanError", { enumerable: true, get: function () { return index_js_1.IncompleteTransactionPlanError; } });
30
+ Object.defineProperty(exports, "InvalidCalldataOriginError", { enumerable: true, get: function () { return index_js_1.InvalidCalldataOriginError; } });
31
+ Object.defineProperty(exports, "InvalidTransactionPlanError", { enumerable: true, get: function () { return index_js_1.InvalidTransactionPlanError; } });
32
+ Object.defineProperty(exports, "NonIntegerInputError", { enumerable: true, get: function () { return index_js_1.NonIntegerInputError; } });
33
+ Object.defineProperty(exports, "parseTransactionPlan", { enumerable: true, get: function () { return index_js_1.parseTransactionPlan; } });
34
+ Object.defineProperty(exports, "prepareVaultV2Deposit", { enumerable: true, get: function () { return index_js_1.prepareVaultV2Deposit; } });
35
+ Object.defineProperty(exports, "prepareVaultV2Withdraw", { enumerable: true, get: function () { return index_js_1.prepareVaultV2Withdraw; } });
36
+ Object.defineProperty(exports, "serializeTransactionPlan", { enumerable: true, get: function () { return index_js_1.serializeTransactionPlan; } });
37
+ Object.defineProperty(exports, "TransactionPlanSignatureMismatchError", { enumerable: true, get: function () { return index_js_1.TransactionPlanSignatureMismatchError; } });
38
+ Object.defineProperty(exports, "UnsupportedTransactionPlanActionError", { enumerable: true, get: function () { return index_js_1.UnsupportedTransactionPlanActionError; } });
39
+ Object.defineProperty(exports, "UnsupportedTransactionPlanVersionError", { enumerable: true, get: function () { return index_js_1.UnsupportedTransactionPlanVersionError; } });
40
+ Object.defineProperty(exports, "ZeroAccountError", { enumerable: true, get: function () { return index_js_1.ZeroAccountError; } });
24
41
  __exportStar(require("./types/index.js"), exports);
42
+ var version_js_1 = require("./version.js");
43
+ Object.defineProperty(exports, "version", { enumerable: true, get: function () { return version_js_1.version; } });
@@ -0,0 +1,2 @@
1
+ /** @internal Validates the stored ERC-20 approval action's input shape. */
2
+ export declare function validateApprovalPlanAction(action: Record<string, unknown>, path: string): void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateApprovalPlanAction = validateApprovalPlanAction;
4
+ const validation_js_1 = require("./validation.js");
5
+ /** @internal Validates the stored ERC-20 approval action's input shape. */
6
+ function validateApprovalPlanAction(action, path) {
7
+ const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
8
+ (0, validation_js_1.validatePlanFields)(inputs, {
9
+ path: `${path}.inputs`,
10
+ fields: {
11
+ token: "address",
12
+ spender: "address",
13
+ amount: "uint256 bigint",
14
+ },
15
+ });
16
+ }
@@ -0,0 +1,145 @@
1
+ import type { Address } from "viem";
2
+ /**
3
+ * Thrown when an operation's account is the zero address.
4
+ * @example
5
+ * ```ts
6
+ * import { ZeroAccountError } from "@morpho-org/morpho-sdk";
7
+ * import { zeroAddress } from "viem";
8
+ * const error = new ZeroAccountError(zeroAddress);
9
+ * ```
10
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
11
+ */
12
+ export declare class ZeroAccountError extends Error {
13
+ readonly account: Address;
14
+ /** @param account - Rejected account address. */
15
+ constructor(account: Address);
16
+ }
17
+ /**
18
+ * A stored plan uses a format version this SDK cannot interpret.
19
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
20
+ */
21
+ export declare class UnsupportedTransactionPlanVersionError extends Error {
22
+ readonly version: number;
23
+ /**
24
+ * @param version - Unsupported stored plan version.
25
+ * @example
26
+ * ```ts
27
+ * import { UnsupportedTransactionPlanVersionError } from "@morpho-org/morpho-sdk";
28
+ * const error = new UnsupportedTransactionPlanVersionError(2);
29
+ * console.error(error.version);
30
+ * ```
31
+ */
32
+ constructor(version: number);
33
+ }
34
+ /**
35
+ * A selected plan step names an action this SDK cannot build.
36
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
37
+ */
38
+ export declare class UnsupportedTransactionPlanActionError extends Error {
39
+ readonly actionType: string;
40
+ /**
41
+ * @param actionType - Unsupported stored action discriminator.
42
+ * @example
43
+ * ```ts
44
+ * import { UnsupportedTransactionPlanActionError } from "@morpho-org/morpho-sdk";
45
+ * const error = new UnsupportedTransactionPlanActionError("futureAction");
46
+ * console.error(error.actionType);
47
+ * ```
48
+ */
49
+ constructor(actionType: string);
50
+ }
51
+ /**
52
+ * Restored plan data has an invalid shape or inconsistent references.
53
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
54
+ */
55
+ export declare class InvalidTransactionPlanError extends Error {
56
+ /** JSON path of the first rejected value. */
57
+ readonly path: string;
58
+ /** Shape or consistency constraint that the value failed. */
59
+ readonly reason: string;
60
+ /**
61
+ * @param details - JSON path, validation failure and optional underlying error.
62
+ * @example
63
+ * ```ts
64
+ * import { InvalidTransactionPlanError } from "@morpho-org/morpho-sdk";
65
+ * const error = new InvalidTransactionPlanError({ path: "$.chainId", reason: "expected a positive safe integer" });
66
+ * console.error(error.path);
67
+ * ```
68
+ */
69
+ constructor({ path, reason, cause, }: {
70
+ readonly path: string;
71
+ readonly reason: string;
72
+ readonly cause?: unknown;
73
+ });
74
+ }
75
+ /**
76
+ * A step references a signature request that is absent or has no signature yet.
77
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
78
+ */
79
+ export declare class IncompleteTransactionPlanError extends Error {
80
+ readonly id: string;
81
+ /**
82
+ * Identifies the signature request needed to build the transaction.
83
+ * @param id - Plan-local signature request ID.
84
+ * @example
85
+ * ```ts
86
+ * import { IncompleteTransactionPlanError } from "@morpho-org/morpho-sdk";
87
+ * const error = new IncompleteTransactionPlanError("vaultV2Deposit:tokenPermit");
88
+ * ```
89
+ */
90
+ constructor(id: string);
91
+ }
92
+ /**
93
+ * A plan's signature request disagrees with its referencing action or has no reference.
94
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
95
+ */
96
+ export declare class TransactionPlanSignatureMismatchError extends Error {
97
+ readonly id: string;
98
+ readonly field: string;
99
+ /**
100
+ * @param id - Rejected signature request ID.
101
+ * @param field - Mismatched typed-data, argument or reference field.
102
+ * @example
103
+ * ```ts
104
+ * import { TransactionPlanSignatureMismatchError } from "@morpho-org/morpho-sdk";
105
+ * const error = new TransactionPlanSignatureMismatchError("vaultV2Deposit:tokenPermit", "message.owner");
106
+ * ```
107
+ */
108
+ constructor(id: string, field: string);
109
+ }
110
+ /**
111
+ * `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
112
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
113
+ */
114
+ export declare class InvalidCalldataOriginError extends Error {
115
+ readonly calldataOrigin: string;
116
+ /**
117
+ * Identifies the rejected origin.
118
+ * @param calldataOrigin - Value supplied by the caller.
119
+ * @example
120
+ * ```ts
121
+ * import { InvalidCalldataOriginError } from "@morpho-org/morpho-sdk";
122
+ * const error = new InvalidCalldataOriginError("0xabc");
123
+ * ```
124
+ */
125
+ constructor(calldataOrigin: string);
126
+ }
127
+ /**
128
+ * A number input that must be an integer is fractional, infinite or not a number.
129
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
130
+ */
131
+ export declare class NonIntegerInputError extends Error {
132
+ readonly field: string;
133
+ readonly value: number;
134
+ /**
135
+ * Identifies the invalid input.
136
+ * @param field - Public input field whose value is invalid.
137
+ * @param value - Non-integer number supplied for the field.
138
+ * @example
139
+ * ```ts
140
+ * import { NonIntegerInputError } from "@morpho-org/morpho-sdk";
141
+ * const error = new NonIntegerInputError("expiresAt", 1.5);
142
+ * ```
143
+ */
144
+ constructor(field: string, value: number);
145
+ }