@morpho-org/morpho-sdk 6.0.0-next.4 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/MIGRATION-v5-to-v6.md +20 -14
  2. package/README.md +6 -4
  3. package/lib/cjs/actions/bundles/common.d.ts +18 -23
  4. package/lib/cjs/actions/bundles/common.js +36 -83
  5. package/lib/cjs/actions/bundles/index.d.ts +1 -1
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
  8. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
  9. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
  10. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
  11. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +19 -1
  12. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
  13. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +12 -0
  14. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +62 -17
  15. package/lib/cjs/actions/vaultV1/migrateToV2.js +48 -17
  16. package/lib/cjs/actions/vaultV1/redeem.d.ts +28 -1
  17. package/lib/cjs/actions/vaultV1/redeem.js +17 -1
  18. package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
  19. package/lib/cjs/actions/vaultV1/withdraw.js +1 -1
  20. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +3 -2
  21. package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -2
  22. package/lib/cjs/actions/vaultV2/redeem.d.ts +28 -1
  23. package/lib/cjs/actions/vaultV2/redeem.js +17 -1
  24. package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
  25. package/lib/cjs/actions/vaultV2/withdraw.js +1 -1
  26. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +29 -20
  27. package/lib/cjs/entities/vaultV1/vaultV1.js +50 -84
  28. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +33 -24
  29. package/lib/cjs/entities/vaultV2/vaultV2.js +44 -72
  30. package/lib/cjs/types/action.d.ts +1 -0
  31. package/lib/esm/actions/bundles/common.d.ts +18 -23
  32. package/lib/esm/actions/bundles/common.js +34 -80
  33. package/lib/esm/actions/bundles/index.d.ts +1 -1
  34. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
  35. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
  36. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
  37. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
  38. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
  39. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -3
  40. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
  41. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +14 -2
  42. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +62 -17
  43. package/lib/esm/actions/vaultV1/migrateToV2.js +48 -17
  44. package/lib/esm/actions/vaultV1/redeem.d.ts +28 -1
  45. package/lib/esm/actions/vaultV1/redeem.js +17 -1
  46. package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
  47. package/lib/esm/actions/vaultV1/withdraw.js +1 -1
  48. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +3 -2
  49. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -2
  50. package/lib/esm/actions/vaultV2/redeem.d.ts +28 -1
  51. package/lib/esm/actions/vaultV2/redeem.js +17 -1
  52. package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
  53. package/lib/esm/actions/vaultV2/withdraw.js +1 -1
  54. package/lib/esm/entities/vaultV1/vaultV1.d.ts +29 -20
  55. package/lib/esm/entities/vaultV1/vaultV1.js +52 -86
  56. package/lib/esm/entities/vaultV2/vaultV2.d.ts +33 -24
  57. package/lib/esm/entities/vaultV2/vaultV2.js +46 -74
  58. package/lib/esm/types/action.d.ts +1 -0
  59. package/package.json +5 -5
@@ -7,7 +7,30 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
7
7
  /**
8
8
  * Encodes an assets-or-shares Vault V1 to Vault V2 migration through VaultBundlesV1.
9
9
  *
10
- * @param params - Source/destination vaults, exclusive migration amount, fee, permit, and deadline.
10
+ * @param params.vault.chainId - Chain containing the vaults and their registered VaultBundlesV1 contract.
11
+ * @param params.vault.address - Source Vault V1 address whose shares are burned.
12
+ * @param params.vault.asset - Source vault's underlying ERC-20 asset; must equal `args.targetAsset`.
13
+ * @param params.args.assets - Gross migrated amount in asset base units, exclusive with `shares`.
14
+ * @param params.args.shares - Source vault shares to burn for the migration, exclusive with `assets`.
15
+ * @param params.args.targetVault - Destination Vault V2 contract receiving the net migrated assets.
16
+ * @param params.args.targetAsset - Destination vault's underlying ERC-20 asset; must equal `vault.asset`.
17
+ * @param params.args.maxSharePriceVaultV2 - Positive maximum asset base units per share base unit
18
+ * on the destination Vault V2 deposit, scaled by RAY (1e27).
19
+ * @param params.args.userAddress - Share owner and transaction sender; VaultBundlesV1 mints shares to this account.
20
+ * @param params.args.recipient - Unsupported; shares are always minted to the transaction sender.
21
+ * @param params.args.minSharePriceVaultV1 - Unsupported; the source Vault V1 withdrawal carries no
22
+ * share-price bound.
23
+ * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
24
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance is already set.
25
+ * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
26
+ * The fee is rounded down and deducted from gross assets before depositing.
27
+ * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
28
+ * when `referralFeePct > 0n`.
29
+ * @param params.args.deadline - Required positive uint256 Unix timestamp in seconds after which
30
+ * execution reverts. This pure builder does not check the current time.
31
+ * @param params.metadata - Optional analytics metadata appended to the transaction calldata.
32
+ * @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
33
+ * @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
11
34
  * @returns A deep-frozen VaultBundlesV1 migration transaction.
12
35
  * @throws {VaultAssetMismatchError} when source and destination assets differ.
13
36
  * @throws {SameVaultMigrationError} when source and destination vaults are identical.
@@ -22,24 +45,32 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
22
45
  * @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
23
46
  * @example
24
47
  * ```ts
48
+ * import { vaults } from "@morpho-org/morpho-test";
25
49
  * import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
50
+ * import type { Address } from "viem";
51
+ * import { mainnet } from "viem/chains";
26
52
  *
27
- * const tx = vaultV1MigrateToV2({
28
- * vault: {
29
- * chainId: 1,
30
- * address: "0x0000000000000000000000000000000000000001",
31
- * asset: "0x0000000000000000000000000000000000000003",
32
- * },
33
- * args: {
34
- * shares: 1_000_000n,
35
- * targetVault: "0x0000000000000000000000000000000000000002",
36
- * targetAsset: "0x0000000000000000000000000000000000000003",
37
- * maxSharePriceVaultV2: 1_000_000_000_000_000_000_000_000_000n,
38
- * userAddress: "0x0000000000000000000000000000000000000004",
39
- * deadline: 1_900_000_000n,
40
- * },
41
- * });
42
- * // tx.action.type === "vaultV1MigrateToV2"
53
+ * export function buildSteakUsdcMigration(
54
+ * targetVault: Address,
55
+ * userAddress: Address,
56
+ * maxSharePriceVaultV2: bigint,
57
+ * deadline: bigint,
58
+ * ) {
59
+ * const vault = vaults[mainnet.id].steakUsdc;
60
+ * const tx = vaultV1MigrateToV2({
61
+ * vault: { chainId: mainnet.id, address: vault.address, asset: vault.asset },
62
+ * args: {
63
+ * shares: 1_000_000n,
64
+ * targetVault,
65
+ * targetAsset: vault.asset,
66
+ * maxSharePriceVaultV2,
67
+ * userAddress,
68
+ * deadline,
69
+ * },
70
+ * });
71
+ * // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
72
+ * return tx;
73
+ * }
43
74
  * ```
44
75
  */
45
76
  export const vaultV1MigrateToV2 = (params) => {
@@ -3,25 +3,52 @@ import { type Erc2612RequirementSignature, type Metadata, type Transaction, type
3
3
  /** Parameters for {@link vaultV1Redeem}. */
4
4
  export interface VaultV1RedeemParams {
5
5
  readonly vault: {
6
+ /** Chain containing the vault and its registered VaultBundlesV1 contract. */
6
7
  readonly chainId: number;
8
+ /** Vault V1 whose shares are burned for the redemption. */
7
9
  readonly address: Address;
8
10
  };
9
11
  readonly args: {
12
+ /** Vault shares to redeem, in share base units. */
10
13
  readonly shares: bigint;
14
+ /** Share owner and transaction sender; receives the net redeemed assets. */
11
15
  readonly userAddress: Address;
16
+ /** Unsupported; net assets are always paid to the transaction sender. */
12
17
  readonly recipient?: never;
18
+ /** Unsupported; VaultBundlesV1 always burns the transaction sender's shares. */
13
19
  readonly onBehalf?: never;
20
+ /** Optional ERC-2612 vault-share permit for the redeemed shares. */
14
21
  readonly requirementSignature?: Erc2612RequirementSignature;
22
+ /** Optional WAD-scaled fee in [0, 1e18), defaulting to zero. */
15
23
  readonly referralFeePct?: bigint;
24
+ /** Optional fee recipient; a nonzero address is required when `referralFeePct > 0n`. */
16
25
  readonly referralFeeRecipient?: Address;
26
+ /** Positive uint256 Unix timestamp in seconds after which execution reverts. */
17
27
  readonly deadline: bigint;
18
28
  };
29
+ /** Optional analytics metadata appended to the transaction calldata. */
19
30
  readonly metadata?: Metadata;
20
31
  }
21
32
  /**
22
33
  * Encodes an exact-shares Vault V1 redemption through VaultBundlesV1.
23
34
  *
24
- * @param params - Vault, shares, share permit, fee, and deadline values.
35
+ * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
36
+ * @param params.vault.address - Vault V1 whose shares are burned for the redemption.
37
+ * @param params.args.shares - Positive vault shares to redeem, in share base units.
38
+ * @param params.args.userAddress - Share owner and transaction sender; receives the net redeemed assets.
39
+ * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
40
+ * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
41
+ * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
42
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance is already set.
43
+ * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
44
+ * The fee is rounded down and deducted from the gross redeemed assets.
45
+ * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
46
+ * when `referralFeePct > 0n`.
47
+ * @param params.args.deadline - Required positive uint256 Unix timestamp in seconds after which
48
+ * execution reverts. This pure builder does not check the current time.
49
+ * @param params.metadata - Optional analytics metadata appended to the transaction calldata.
50
+ * @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
51
+ * @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
25
52
  * @returns A deep-frozen VaultBundlesV1 redemption transaction.
26
53
  * @throws {NonPositiveInputError} when `shares` or `deadline` is not positive.
27
54
  * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
@@ -7,7 +7,23 @@ import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBun
7
7
  /**
8
8
  * Encodes an exact-shares Vault V1 redemption through VaultBundlesV1.
9
9
  *
10
- * @param params - Vault, shares, share permit, fee, and deadline values.
10
+ * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
11
+ * @param params.vault.address - Vault V1 whose shares are burned for the redemption.
12
+ * @param params.args.shares - Positive vault shares to redeem, in share base units.
13
+ * @param params.args.userAddress - Share owner and transaction sender; receives the net redeemed assets.
14
+ * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
15
+ * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
16
+ * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
17
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance is already set.
18
+ * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
19
+ * The fee is rounded down and deducted from the gross redeemed assets.
20
+ * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
21
+ * when `referralFeePct > 0n`.
22
+ * @param params.args.deadline - Required positive uint256 Unix timestamp in seconds after which
23
+ * execution reverts. This pure builder does not check the current time.
24
+ * @param params.metadata - Optional analytics metadata appended to the transaction calldata.
25
+ * @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
26
+ * @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
11
27
  * @returns A deep-frozen VaultBundlesV1 redemption transaction.
12
28
  * @throws {NonPositiveInputError} when `shares` or `deadline` is not positive.
13
29
  * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
@@ -22,7 +22,7 @@ export interface VaultV1WithdrawParams {
22
22
  * Encodes an exact-assets Vault V1 withdrawal through VaultBundlesV1.
23
23
  *
24
24
  * This low-level builder does not bind `permit.value` to a share cap; use
25
- * `MorphoVaultV1.withdraw().buildTx()` to validate it against the cap from `getRequirements()`.
25
+ * `MorphoVaultV1.withdraw().buildTx()` to validate it against the share cap derived from the handle's `vaultData`.
26
26
  *
27
27
  * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
28
28
  * @param params.vault.address - Vault V1 whose shares are burned for the withdrawal.
@@ -8,7 +8,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
8
8
  * Encodes an exact-assets Vault V1 withdrawal through VaultBundlesV1.
9
9
  *
10
10
  * This low-level builder does not bind `permit.value` to a share cap; use
11
- * `MorphoVaultV1.withdraw().buildTx()` to validate it against the cap from `getRequirements()`.
11
+ * `MorphoVaultV1.withdraw().buildTx()` to validate it against the share cap derived from the handle's `vaultData`.
12
12
  *
13
13
  * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
14
14
  * @param params.vault.address - Vault V1 whose shares are burned for the withdrawal.
@@ -56,8 +56,9 @@ export interface VaultV2ForceWithdrawParams {
56
56
  * `data`, and the typed action discriminator.
57
57
  * @throws {NonPositiveInputError} when `exitAssets` or `deadline` is not positive.
58
58
  * @throws {NegativeInputError} when `referralFeePct` or `minSharePriceE27` is negative.
59
- * @throws {InputExceedsMaxError} when `referralFeePct` is not below WAD (the contract rejects it
60
- * with `PctExceeded`), or when `exitAssets`, `deadline`, or `minSharePriceE27` exceeds `uint256`.
59
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD (the contract
60
+ * rejects it with `PctExceeded`); it extends {@link InputExceedsMaxError}.
61
+ * @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or `minSharePriceE27` exceeds `uint256`.
61
62
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
62
63
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
63
64
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -43,8 +43,9 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
43
43
  * `data`, and the typed action discriminator.
44
44
  * @throws {NonPositiveInputError} when `exitAssets` or `deadline` is not positive.
45
45
  * @throws {NegativeInputError} when `referralFeePct` or `minSharePriceE27` is negative.
46
- * @throws {InputExceedsMaxError} when `referralFeePct` is not below WAD (the contract rejects it
47
- * with `PctExceeded`), or when `exitAssets`, `deadline`, or `minSharePriceE27` exceeds `uint256`.
46
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD (the contract
47
+ * rejects it with `PctExceeded`); it extends {@link InputExceedsMaxError}.
48
+ * @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or `minSharePriceE27` exceeds `uint256`.
48
49
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
49
50
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
50
51
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -3,25 +3,52 @@ import { type Erc2612RequirementSignature, type Metadata, type Transaction, type
3
3
  /** Parameters for {@link vaultV2Redeem}. */
4
4
  export interface VaultV2RedeemParams {
5
5
  readonly vault: {
6
+ /** Chain containing the vault and its registered VaultBundlesV1 contract. */
6
7
  readonly chainId: number;
8
+ /** Vault V2 whose shares are burned for the redemption. */
7
9
  readonly address: Address;
8
10
  };
9
11
  readonly args: {
12
+ /** Vault shares to redeem, in share base units. */
10
13
  readonly shares: bigint;
14
+ /** Share owner and transaction sender; receives the net redeemed assets. */
11
15
  readonly userAddress: Address;
16
+ /** Unsupported; net assets are always paid to the transaction sender. */
12
17
  readonly recipient?: never;
18
+ /** Unsupported; VaultBundlesV1 always burns the transaction sender's shares. */
13
19
  readonly onBehalf?: never;
20
+ /** Optional ERC-2612 vault-share permit for the redeemed shares. */
14
21
  readonly requirementSignature?: Erc2612RequirementSignature;
22
+ /** Optional WAD-scaled fee in [0, 1e18), defaulting to zero. */
15
23
  readonly referralFeePct?: bigint;
24
+ /** Optional fee recipient; a nonzero address is required when `referralFeePct > 0n`. */
16
25
  readonly referralFeeRecipient?: Address;
26
+ /** Positive uint256 Unix timestamp in seconds after which execution reverts. */
17
27
  readonly deadline: bigint;
18
28
  };
29
+ /** Optional analytics metadata appended to the transaction calldata. */
19
30
  readonly metadata?: Metadata;
20
31
  }
21
32
  /**
22
33
  * Encodes an exact-shares Vault V2 redemption through VaultBundlesV1.
23
34
  *
24
- * @param params - Vault, shares, share permit, fee, and deadline values.
35
+ * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
36
+ * @param params.vault.address - Vault V2 whose shares are burned for the redemption.
37
+ * @param params.args.shares - Positive vault shares to redeem, in share base units.
38
+ * @param params.args.userAddress - Share owner and transaction sender; receives the net redeemed assets.
39
+ * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
40
+ * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
41
+ * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
42
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance is already set.
43
+ * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
44
+ * The fee is rounded down and deducted from the gross redeemed assets.
45
+ * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
46
+ * when `referralFeePct > 0n`.
47
+ * @param params.args.deadline - Required positive uint256 Unix timestamp in seconds after which
48
+ * execution reverts. This pure builder does not check the current time.
49
+ * @param params.metadata - Optional analytics metadata appended to the transaction calldata.
50
+ * @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
51
+ * @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
25
52
  * @returns A deep-frozen VaultBundlesV1 redemption transaction.
26
53
  * @throws {NonPositiveInputError} when `shares` or `deadline` is not positive.
27
54
  * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
@@ -7,7 +7,23 @@ import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBun
7
7
  /**
8
8
  * Encodes an exact-shares Vault V2 redemption through VaultBundlesV1.
9
9
  *
10
- * @param params - Vault, shares, share permit, fee, and deadline values.
10
+ * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
11
+ * @param params.vault.address - Vault V2 whose shares are burned for the redemption.
12
+ * @param params.args.shares - Positive vault shares to redeem, in share base units.
13
+ * @param params.args.userAddress - Share owner and transaction sender; receives the net redeemed assets.
14
+ * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
15
+ * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
16
+ * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
17
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance is already set.
18
+ * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
19
+ * The fee is rounded down and deducted from the gross redeemed assets.
20
+ * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
21
+ * when `referralFeePct > 0n`.
22
+ * @param params.args.deadline - Required positive uint256 Unix timestamp in seconds after which
23
+ * execution reverts. This pure builder does not check the current time.
24
+ * @param params.metadata - Optional analytics metadata appended to the transaction calldata.
25
+ * @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
26
+ * @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
11
27
  * @returns A deep-frozen VaultBundlesV1 redemption transaction.
12
28
  * @throws {NonPositiveInputError} when `shares` or `deadline` is not positive.
13
29
  * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
@@ -22,7 +22,7 @@ export interface VaultV2WithdrawParams {
22
22
  * Encodes an exact-assets Vault V2 withdrawal through VaultBundlesV1.
23
23
  *
24
24
  * This low-level builder does not bind `permit.value` to a share cap; use
25
- * `MorphoVaultV2.withdraw().buildTx()` to validate it against the cap from `getRequirements()`.
25
+ * `MorphoVaultV2.withdraw().buildTx()` to validate it against the share cap derived from the handle's `vaultData`.
26
26
  *
27
27
  * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
28
28
  * @param params.vault.address - Vault V2 whose shares are burned for the withdrawal.
@@ -8,7 +8,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
8
8
  * Encodes an exact-assets Vault V2 withdrawal through VaultBundlesV1.
9
9
  *
10
10
  * This low-level builder does not bind `permit.value` to a share cap; use
11
- * `MorphoVaultV2.withdraw().buildTx()` to validate it against the cap from `getRequirements()`.
11
+ * `MorphoVaultV2.withdraw().buildTx()` to validate it against the share cap derived from the handle's `vaultData`.
12
12
  *
13
13
  * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
14
14
  * @param params.vault.address - Vault V2 whose shares are burned for the withdrawal.
@@ -9,6 +9,7 @@ export interface VaultV1Actions {
9
9
  *
10
10
  * @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
11
11
  * @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The requested vault state.
12
+ * @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
12
13
  */
13
14
  getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
14
15
  /**
@@ -19,7 +20,7 @@ export interface VaultV1Actions {
19
20
  * Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
20
21
  * always minted to the transaction sender, which must be `userAddress`.
21
22
  * Concurrent requirement reads share the first caller's options; later calls refresh on-chain
22
- * state using their own options. `buildTx()` accepts signatures from the latest completed read.
23
+ * state using their own options.
23
24
  *
24
25
  * @param params.userAddress - Account that funds, signs, submits, and receives the vault shares.
25
26
  * @param params.vaultData - Pre-fetched Vault V1 snapshot used for asset and share conversion.
@@ -55,8 +56,9 @@ export interface VaultV1Actions {
55
56
  * `getRequirements()` when the Permit2 nonce exceeds uint256.
56
57
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
57
58
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
58
- * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature was not produced for
59
- * this prepared handle.
59
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
60
+ * deadline differ from this operation's, or when the signature's carried action nonce is
61
+ * inconsistent with its signed nonce.
60
62
  * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
61
63
  * @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the vault asset.
62
64
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
@@ -95,13 +97,14 @@ export interface VaultV1Actions {
95
97
  /**
96
98
  * Prepares an exact-assets Vault V1 withdrawal through VaultBundlesV1.
97
99
  *
98
- * Reads the vault accrual state on the first `getRequirements()` call, then reads the live
99
- * vault-share allowance and, when a signature is needed, the permit nonce on each call.
100
- * Captures the requested amount and owner at creation, so later changes to `params` do not
101
- * change this handle's requirements or transaction.
100
+ * Derives the share-burn cap from the supplied `vaultData` snapshot at handle creation, then
101
+ * reads the live vault-share allowance and, when a signature is needed, the permit nonce on
102
+ * each `getRequirements()` call. Captures the requested amount and owner at creation, so later
103
+ * changes to `params` do not change this handle's requirements or transaction.
102
104
  *
103
105
  * @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
104
106
  * @param params.userAddress - Share owner that must sign and submit; receives the net assets.
107
+ * @param params.vaultData - Pre-fetched Vault V1 snapshot used to derive the share cap.
105
108
  * @param params.slippageTolerance - Optional WAD-scaled share-price loss tolerance applied to
106
109
  * the share cap for MetaMorpho 1.0; MetaMorpho 1.1 retains its lost-assets clamp.
107
110
  * Defaults to 0.03% and cannot exceed 10%.
@@ -114,8 +117,11 @@ export interface VaultV1Actions {
114
117
  * which returns a deep-frozen `Transaction<VaultV1WithdrawAction>`. Requirements are empty
115
118
  * when the allowance equals the cap; an oversized allowance is always reset with an exact
116
119
  * onchain approval, and an insufficient one is raised by an approval or, with signature
117
- * support, an ERC-2612 request. The cap stays pinned to the first resolution while each call
118
- * re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
120
+ * support, an ERC-2612 request. The cap is fixed at handle creation while each call re-reads
121
+ * the allowance. Confirm the approval or pass its signed permit to `buildTx`.
122
+ * @remarks VaultBundlesV1 skips a share permit whose nonce was already consumed and proceeds
123
+ * under the live allowance, so execute every requirement returned by the latest
124
+ * `getRequirements()` — including the oversized-allowance reset — before submitting.
119
125
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
120
126
  * @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
121
127
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
@@ -125,14 +131,14 @@ export interface VaultV1Actions {
125
131
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
126
132
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
127
133
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
134
+ * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
128
135
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
129
136
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
130
137
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
131
138
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
132
- * @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed,
133
- * was not resolved for this handle, or has incompatible vault, owner, spender, amount,
134
- * deadline, or nonce values.
135
- * @throws {viem.BaseError} when a vault, allowance, or nonce read or transaction encoding fails.
139
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed or
140
+ * its spender, amount or deadline differ from this operation's.
141
+ * @throws {viem.BaseError} when an allowance or nonce read or transaction encoding fails.
136
142
  * @example
137
143
  * ```ts
138
144
  * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
@@ -144,7 +150,8 @@ export interface VaultV1Actions {
144
150
  * const client = createPublicClient({ chain: mainnet, transport: http() })
145
151
  * .extend(morphoViemExtension({ supportSignature: false }));
146
152
  * const vault = client.morpho.vaultV1(vaultAddress, mainnet.id);
147
- * const action = vault.withdraw({ amount: 1_000_000n, userAddress });
153
+ * const vaultData = await vault.getData();
154
+ * const action = vault.withdraw({ amount: 1_000_000n, userAddress, vaultData });
148
155
  * const requirements = await action.getRequirements();
149
156
  * // Send and confirm each approval before calling action.buildTx().
150
157
  * // action.buildTx() returns Readonly<Transaction<VaultV1WithdrawAction>>.
@@ -155,6 +162,7 @@ export interface VaultV1Actions {
155
162
  withdraw: (params: {
156
163
  readonly amount: bigint;
157
164
  readonly userAddress: Address;
165
+ readonly vaultData: AccrualVault;
158
166
  readonly slippageTolerance?: bigint;
159
167
  readonly referralFeePct?: bigint;
160
168
  readonly referralFeeRecipient?: Address;
@@ -166,7 +174,6 @@ export interface VaultV1Actions {
166
174
  * Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
167
175
  * The caller must satisfy the exact vault-share allowance returned by `getRequirements()` before
168
176
  * `buildTx()`; every requirement resolution re-reads the live allowance and checks the deadline.
169
- * `buildTx()` accepts permits from the latest completed requirement resolution.
170
177
  *
171
178
  * @param params.shares - Exact vault shares to burn.
172
179
  * @param params.userAddress - Account that signs and submits the transaction; VaultBundlesV1
@@ -180,6 +187,7 @@ export interface VaultV1Actions {
180
187
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
181
188
  * @throws {NonPositiveInputError} when `shares` is not positive.
182
189
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
190
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
183
191
  * @throws {NegativeInputError} when `referralFeePct` is negative.
184
192
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
185
193
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
@@ -188,8 +196,8 @@ export interface VaultV1Actions {
188
196
  * @throws {viem.BaseError} from `getRequirements()` when an allowance or permit-nonce read fails.
189
197
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permit signatures are supplied.
190
198
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
191
- * @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit does not match
192
- * the resolved share amount, spender, owner, nonce, or deadline.
199
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
200
+ * deadline differ from this operation's.
193
201
  * @example
194
202
  * ```ts
195
203
  * import { vaults } from "@morpho-org/morpho-test";
@@ -314,7 +322,6 @@ export interface VaultV1Actions {
314
322
  * VaultBundlesV1. Only the destination deposit has an onchain share-price bound. The caller must
315
323
  * satisfy the exact source-vault share requirement before building the transaction.
316
324
  * Captures vault identities, permit-domain metadata, and the owner at handle creation.
317
- * `buildTx()` accepts permits from the latest completed requirement resolution.
318
325
  *
319
326
  * @param params.userAddress - Account that signs and submits the transaction; VaultBundlesV1
320
327
  * burns and mints shares for `msg.sender`.
@@ -347,6 +354,7 @@ export interface VaultV1Actions {
347
354
  * @throws {NegativeInputError} when slippage tolerance or `referralFeePct` is negative.
348
355
  * @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
349
356
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
357
+ * @throws {InputExceedsMaxError} when the selected amount, `maxSharePriceVaultV2`, or `deadline` exceeds uint256.
350
358
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
351
359
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
352
360
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
@@ -354,8 +362,8 @@ export interface VaultV1Actions {
354
362
  * @throws {viem.BaseError} from `getRequirements()` when an allowance or permit-nonce read fails.
355
363
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permit signatures are supplied.
356
364
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
357
- * @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit does not match
358
- * the prepared source share cap, spender, owner, nonce, or deadline.
365
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
366
+ * deadline differ from this operation's.
359
367
  * @example
360
368
  * ```ts
361
369
  * import { vaults } from "@morpho-org/morpho-test";
@@ -427,6 +435,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
427
435
  withdraw(params: {
428
436
  readonly amount: bigint;
429
437
  readonly userAddress: Address;
438
+ readonly vaultData: AccrualVault;
430
439
  readonly slippageTolerance?: bigint;
431
440
  readonly referralFeePct?: bigint;
432
441
  readonly referralFeeRecipient?: Address;