@morpho-org/morpho-sdk 5.4.0 → 5.5.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 (84) hide show
  1. package/README.md +15 -1
  2. package/lib/cjs/abis.d.ts +313 -0
  3. package/lib/cjs/abis.js +167 -1
  4. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  5. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +9 -2
  6. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
  7. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +131 -0
  8. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  9. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  10. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  11. package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
  12. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
  13. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +91 -0
  14. package/lib/cjs/actions/signatures/index.d.ts +1 -0
  15. package/lib/cjs/actions/signatures/index.js +1 -0
  16. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +54 -0
  17. package/lib/cjs/actions/vaultV1/inKindRedeem.js +96 -0
  18. package/lib/cjs/actions/vaultV1/index.d.ts +1 -0
  19. package/lib/cjs/actions/vaultV1/index.js +1 -0
  20. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +56 -0
  21. package/lib/cjs/actions/vaultV2/inKindRedeem.js +97 -0
  22. package/lib/cjs/actions/vaultV2/index.d.ts +1 -0
  23. package/lib/cjs/actions/vaultV2/index.js +1 -0
  24. package/lib/cjs/bundler/actions.d.ts +1 -2
  25. package/lib/cjs/bundler/actions.js +1 -2
  26. package/lib/cjs/entities/blue/blue.d.ts +8 -8
  27. package/lib/cjs/entities/reallocationData.d.ts +1 -2
  28. package/lib/cjs/entities/reallocationData.js +1 -2
  29. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +82 -4
  30. package/lib/cjs/entities/vaultV1/vaultV1.js +164 -0
  31. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +89 -3
  32. package/lib/cjs/entities/vaultV2/vaultV2.js +181 -0
  33. package/lib/cjs/helpers/index.d.ts +1 -0
  34. package/lib/cjs/helpers/index.js +3 -1
  35. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
  36. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +73 -0
  37. package/lib/cjs/helpers/validate.d.ts +1 -1
  38. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  39. package/lib/cjs/helpers/validateRequirementSpender.js +2 -1
  40. package/lib/cjs/types/action.d.ts +21 -1
  41. package/lib/cjs/types/error.d.ts +139 -0
  42. package/lib/cjs/types/error.js +189 -2
  43. package/lib/esm/abis.d.ts +313 -0
  44. package/lib/esm/abis.js +166 -0
  45. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  46. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -2
  47. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
  48. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +127 -0
  49. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  50. package/lib/esm/actions/requirements/encode/index.js +1 -0
  51. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  52. package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
  53. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
  54. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +87 -0
  55. package/lib/esm/actions/signatures/index.d.ts +1 -0
  56. package/lib/esm/actions/signatures/index.js +1 -0
  57. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +54 -0
  58. package/lib/esm/actions/vaultV1/inKindRedeem.js +92 -0
  59. package/lib/esm/actions/vaultV1/index.d.ts +1 -0
  60. package/lib/esm/actions/vaultV1/index.js +1 -0
  61. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +56 -0
  62. package/lib/esm/actions/vaultV2/inKindRedeem.js +93 -0
  63. package/lib/esm/actions/vaultV2/index.d.ts +1 -0
  64. package/lib/esm/actions/vaultV2/index.js +1 -0
  65. package/lib/esm/bundler/actions.d.ts +1 -2
  66. package/lib/esm/bundler/actions.js +1 -2
  67. package/lib/esm/entities/blue/blue.d.ts +5 -5
  68. package/lib/esm/entities/reallocationData.d.ts +1 -2
  69. package/lib/esm/entities/reallocationData.js +1 -2
  70. package/lib/esm/entities/vaultV1/vaultV1.d.ts +80 -2
  71. package/lib/esm/entities/vaultV1/vaultV1.js +170 -6
  72. package/lib/esm/entities/vaultV2/vaultV2.d.ts +88 -2
  73. package/lib/esm/entities/vaultV2/vaultV2.js +187 -6
  74. package/lib/esm/helpers/index.d.ts +1 -0
  75. package/lib/esm/helpers/index.js +1 -0
  76. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
  77. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +70 -0
  78. package/lib/esm/helpers/validate.d.ts +1 -1
  79. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  80. package/lib/esm/helpers/validateRequirementSpender.js +2 -1
  81. package/lib/esm/types/action.d.ts +21 -1
  82. package/lib/esm/types/error.d.ts +139 -0
  83. package/lib/esm/types/error.js +175 -0
  84. package/package.json +9 -11
@@ -0,0 +1,92 @@
1
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
2
+ import { encodeFunctionData } from "viem";
3
+ import { vaultExitBundlesV1Abi } from "../../abis.js";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { EmptyMarketParamsListError, NonPositiveInputError, } from "../../types/index.js";
6
+ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBundlesV1PermitStruct.js";
7
+ /**
8
+ * Prepares a Vault V1 in-kind redemption into Morpho Blue supply positions.
9
+ *
10
+ * The transaction calls VaultExitBundlesV1 directly. Without a signature it embeds the contract's
11
+ * empty-permit sentinel; the user must first approve enough shares for the exit.
12
+ *
13
+ * @param params - In-kind redemption parameters.
14
+ * @param params.vault.chainId - Chain containing the target Vault V1 and VaultExitBundlesV1.
15
+ * @param params.vault.address - Target Vault V1 address.
16
+ * @param params.args.amount - Asset-denominated amount to exit.
17
+ * @param params.args.marketParamsList - Ordered markets consumed greedily by the contract.
18
+ * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
19
+ * VaultExitBundlesV1 burns `msg.sender`'s vault shares, so the submitting account must equal this
20
+ * address.
21
+ * @param params.args.deadline - Permit and bundle deadline.
22
+ * @param params.args.requirementSignature - Optional bounded Vault V1 shares permit.
23
+ * @param params.metadata - Optional analytics metadata.
24
+ * @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
25
+ * `data`, and the typed action discriminator.
26
+ * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
27
+ * @throws {EmptyMarketParamsListError} when no markets are supplied.
28
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
29
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
30
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
31
+ * @example
32
+ * ```ts
33
+ * import { vaultV1InKindRedeem } from "@morpho-org/morpho-sdk";
34
+ *
35
+ * const tx = vaultV1InKindRedeem({
36
+ * vault: { chainId: 1, address: vault },
37
+ * args: { amount: 1_000_000n, marketParamsList, userAddress, deadline },
38
+ * });
39
+ * // tx satisfies Readonly<Transaction<VaultV1InKindRedeemAction>>
40
+ * ```
41
+ */
42
+ export const vaultV1InKindRedeem = ({ vault, args, metadata, }) => {
43
+ if (args.amount <= 0n)
44
+ throw new NonPositiveInputError("amount", args.amount);
45
+ if (args.deadline <= 0n)
46
+ throw new NonPositiveInputError("deadline", args.deadline);
47
+ if (args.marketParamsList.length === 0)
48
+ throw new EmptyMarketParamsListError();
49
+ const to = getChainAddress(vault.chainId, "bundles.vaultExitBundlesV1");
50
+ const marketParamsList = args.marketParamsList.map((marketParams) => ({
51
+ loanToken: marketParams.loanToken,
52
+ collateralToken: marketParams.collateralToken,
53
+ oracle: marketParams.oracle,
54
+ irm: marketParams.irm,
55
+ lltv: marketParams.lltv,
56
+ }));
57
+ const sharesPermit = getVaultExitBundlesV1PermitStruct({
58
+ vault: vault.address,
59
+ deadline: args.deadline,
60
+ requirementSignature: args.requirementSignature,
61
+ });
62
+ let tx = {
63
+ to,
64
+ value: 0n,
65
+ data: encodeFunctionData({
66
+ abi: vaultExitBundlesV1Abi,
67
+ functionName: "vaultExitBundlesV1InKindRedemptionVaultV1",
68
+ args: [
69
+ vault.address,
70
+ marketParamsList,
71
+ args.amount,
72
+ sharesPermit,
73
+ args.deadline,
74
+ ],
75
+ }),
76
+ };
77
+ if (metadata)
78
+ tx = addTransactionMetadata(tx, metadata);
79
+ return deepFreeze({
80
+ ...tx,
81
+ action: {
82
+ type: "vaultV1InKindRedeem",
83
+ args: {
84
+ vault: vault.address,
85
+ amount: args.amount,
86
+ marketParamsList,
87
+ onBehalf: args.userAddress,
88
+ deadline: args.deadline,
89
+ },
90
+ },
91
+ });
92
+ };
@@ -1,4 +1,5 @@
1
1
  export * from "./deposit.js";
2
+ export * from "./inKindRedeem.js";
2
3
  export * from "./migrateToV2.js";
3
4
  export * from "./redeem.js";
4
5
  export * from "./withdraw.js";
@@ -1,4 +1,5 @@
1
1
  export * from "./deposit.js";
2
+ export * from "./inKindRedeem.js";
2
3
  export * from "./migrateToV2.js";
3
4
  export * from "./redeem.js";
4
5
  export * from "./withdraw.js";
@@ -0,0 +1,56 @@
1
+ import type { InputMarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address } from "viem";
3
+ import { type Metadata, type PermitRequirementSignature, type Transaction, type VaultV2InKindRedeemAction } from "../../types/index.js";
4
+ /** Parameters for {@link vaultV2InKindRedeem}. */
5
+ export interface VaultV2InKindRedeemParams {
6
+ readonly vault: {
7
+ readonly chainId: number;
8
+ readonly address: Address;
9
+ };
10
+ readonly args: {
11
+ readonly adapter: Address;
12
+ readonly amount: bigint;
13
+ readonly marketParamsList: readonly InputMarketParams[];
14
+ readonly userAddress: Address;
15
+ readonly deadline: bigint;
16
+ readonly requirementSignature?: PermitRequirementSignature;
17
+ };
18
+ readonly metadata?: Metadata;
19
+ }
20
+ /**
21
+ * Prepares a Vault V2 in-kind redemption into idle assets and Morpho Blue supply positions.
22
+ *
23
+ * `amount` includes the Vault V2 force-deallocation penalty. Without a signature this embeds the
24
+ * empty-permit sentinel and requires a sufficient share approval to VaultExitBundlesV1.
25
+ *
26
+ * @param params - In-kind redemption parameters.
27
+ * @param params.vault.chainId - Chain containing the target Vault V2 and VaultExitBundlesV1.
28
+ * @param params.vault.address - Target Vault V2 address.
29
+ * @param params.args.adapter - Vault's sole MorphoMarketV1AdapterV2.
30
+ * @param params.args.amount - Penalty-inclusive, asset-denominated amount to exit.
31
+ * @param params.args.marketParamsList - Ordered markets consumed greedily after idle assets. May be
32
+ * empty when the vault's idle balance covers `amount`.
33
+ * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
34
+ * VaultExitBundlesV1 burns `msg.sender`'s vault shares, so the submitting account must equal this
35
+ * address.
36
+ * @param params.args.deadline - Permit and bundle deadline.
37
+ * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
38
+ * @param params.metadata - Optional analytics metadata.
39
+ * @returns A deep-frozen `Readonly<Transaction<VaultV2InKindRedeemAction>>` with `to`, `value`,
40
+ * `data`, and the typed action discriminator.
41
+ * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
42
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
43
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
44
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
45
+ * @example
46
+ * ```ts
47
+ * import { vaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
48
+ *
49
+ * const tx = vaultV2InKindRedeem({
50
+ * vault: { chainId: 1, address: vault },
51
+ * args: { adapter, amount: 1_000_000n, marketParamsList, userAddress, deadline },
52
+ * });
53
+ * // tx satisfies Readonly<Transaction<VaultV2InKindRedeemAction>>
54
+ * ```
55
+ */
56
+ export declare const vaultV2InKindRedeem: ({ vault, args, metadata, }: VaultV2InKindRedeemParams) => Readonly<Transaction<VaultV2InKindRedeemAction>>;
@@ -0,0 +1,93 @@
1
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
2
+ import { encodeFunctionData } from "viem";
3
+ import { vaultExitBundlesV1Abi } from "../../abis.js";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { NonPositiveInputError, } from "../../types/index.js";
6
+ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBundlesV1PermitStruct.js";
7
+ /**
8
+ * Prepares a Vault V2 in-kind redemption into idle assets and Morpho Blue supply positions.
9
+ *
10
+ * `amount` includes the Vault V2 force-deallocation penalty. Without a signature this embeds the
11
+ * empty-permit sentinel and requires a sufficient share approval to VaultExitBundlesV1.
12
+ *
13
+ * @param params - In-kind redemption parameters.
14
+ * @param params.vault.chainId - Chain containing the target Vault V2 and VaultExitBundlesV1.
15
+ * @param params.vault.address - Target Vault V2 address.
16
+ * @param params.args.adapter - Vault's sole MorphoMarketV1AdapterV2.
17
+ * @param params.args.amount - Penalty-inclusive, asset-denominated amount to exit.
18
+ * @param params.args.marketParamsList - Ordered markets consumed greedily after idle assets. May be
19
+ * empty when the vault's idle balance covers `amount`.
20
+ * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
21
+ * VaultExitBundlesV1 burns `msg.sender`'s vault shares, so the submitting account must equal this
22
+ * address.
23
+ * @param params.args.deadline - Permit and bundle deadline.
24
+ * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
25
+ * @param params.metadata - Optional analytics metadata.
26
+ * @returns A deep-frozen `Readonly<Transaction<VaultV2InKindRedeemAction>>` with `to`, `value`,
27
+ * `data`, and the typed action discriminator.
28
+ * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
29
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
30
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
31
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
32
+ * @example
33
+ * ```ts
34
+ * import { vaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
35
+ *
36
+ * const tx = vaultV2InKindRedeem({
37
+ * vault: { chainId: 1, address: vault },
38
+ * args: { adapter, amount: 1_000_000n, marketParamsList, userAddress, deadline },
39
+ * });
40
+ * // tx satisfies Readonly<Transaction<VaultV2InKindRedeemAction>>
41
+ * ```
42
+ */
43
+ export const vaultV2InKindRedeem = ({ vault, args, metadata, }) => {
44
+ if (args.amount <= 0n)
45
+ throw new NonPositiveInputError("amount", args.amount);
46
+ if (args.deadline <= 0n)
47
+ throw new NonPositiveInputError("deadline", args.deadline);
48
+ const to = getChainAddress(vault.chainId, "bundles.vaultExitBundlesV1");
49
+ const marketParamsList = args.marketParamsList.map((marketParams) => ({
50
+ loanToken: marketParams.loanToken,
51
+ collateralToken: marketParams.collateralToken,
52
+ oracle: marketParams.oracle,
53
+ irm: marketParams.irm,
54
+ lltv: marketParams.lltv,
55
+ }));
56
+ const sharesPermit = getVaultExitBundlesV1PermitStruct({
57
+ vault: vault.address,
58
+ deadline: args.deadline,
59
+ requirementSignature: args.requirementSignature,
60
+ });
61
+ let tx = {
62
+ to,
63
+ value: 0n,
64
+ data: encodeFunctionData({
65
+ abi: vaultExitBundlesV1Abi,
66
+ functionName: "vaultExitBundlesV1InKindRedemptionVaultV2",
67
+ args: [
68
+ vault.address,
69
+ args.adapter,
70
+ marketParamsList,
71
+ args.amount,
72
+ sharesPermit,
73
+ args.deadline,
74
+ ],
75
+ }),
76
+ };
77
+ if (metadata)
78
+ tx = addTransactionMetadata(tx, metadata);
79
+ return deepFreeze({
80
+ ...tx,
81
+ action: {
82
+ type: "vaultV2InKindRedeem",
83
+ args: {
84
+ vault: vault.address,
85
+ adapter: args.adapter,
86
+ amount: args.amount,
87
+ marketParamsList,
88
+ onBehalf: args.userAddress,
89
+ deadline: args.deadline,
90
+ },
91
+ },
92
+ });
93
+ };
@@ -1,5 +1,6 @@
1
1
  export * from "./deposit.js";
2
2
  export * from "./forceRedeem.js";
3
3
  export * from "./forceWithdraw.js";
4
+ export * from "./inKindRedeem.js";
4
5
  export * from "./redeem.js";
5
6
  export * from "./withdraw.js";
@@ -1,5 +1,6 @@
1
1
  export * from "./deposit.js";
2
2
  export * from "./forceRedeem.js";
3
3
  export * from "./forceWithdraw.js";
4
+ export * from "./inKindRedeem.js";
4
5
  export * from "./redeem.js";
5
6
  export * from "./withdraw.js";
@@ -21,8 +21,7 @@ export interface BundlerCall {
21
21
  *
22
22
  * @remarks
23
23
  * The namespace covers only the Bundler3 actions required by `morpho-sdk`.
24
- * It does not expose operation population or simulation helpers from
25
- * `@morpho-org/bundler-sdk-viem`.
24
+ * It does not expose operation population or broad simulation helpers.
26
25
  */
27
26
  export declare namespace BundlerAction {
28
27
  /**
@@ -41,8 +41,7 @@ const consumeCallValue = (state, call) => {
41
41
  *
42
42
  * @remarks
43
43
  * The namespace covers only the Bundler3 actions required by `morpho-sdk`.
44
- * It does not expose operation population or simulation helpers from
45
- * `@morpho-org/bundler-sdk-viem`.
44
+ * It does not expose operation population or broad simulation helpers.
46
45
  */
47
46
  export var BundlerAction;
48
47
  (function (BundlerAction) {
@@ -383,7 +383,7 @@ export declare class MorphoBlue implements BlueActions {
383
383
  slippageTolerance?: bigint;
384
384
  reallocations?: readonly VaultReallocation[];
385
385
  } & AssetsOrSharesArgs): {
386
- getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
386
+ getRequirements: () => Promise<(Readonly<Transaction<BlueAuthorizationAction>> | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined>)[]>;
387
387
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueWithdrawAction>>;
388
388
  };
389
389
  supplyCollateral({ amount, userAddress, nativeAmount, }: {
@@ -401,7 +401,7 @@ export declare class MorphoBlue implements BlueActions {
401
401
  slippageTolerance?: bigint;
402
402
  reallocations?: readonly VaultReallocation[];
403
403
  }): {
404
- getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
404
+ getRequirements: () => Promise<(Readonly<Transaction<BlueAuthorizationAction>> | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined>)[]>;
405
405
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueBorrowAction>>;
406
406
  };
407
407
  repay(params: {
@@ -429,7 +429,7 @@ export declare class MorphoBlue implements BlueActions {
429
429
  } & RepayAmountArgs): {
430
430
  getRequirements: (reqParams?: {
431
431
  useSimplePermit?: boolean;
432
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
432
+ }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined>)[]>;
433
433
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
434
434
  };
435
435
  supplyCollateralBorrow({ amount, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance, reallocations, }: {
@@ -441,7 +441,7 @@ export declare class MorphoBlue implements BlueActions {
441
441
  } & DepositAmountArgs): {
442
442
  getRequirements: (params?: {
443
443
  useSimplePermit?: boolean;
444
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
444
+ }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<BlueAuthorizationAction>> | Readonly<Transaction<ERC20ApprovalAction>> | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined>)[]>;
445
445
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
446
446
  };
447
447
  refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance, targetReallocations, }: {
@@ -457,7 +457,7 @@ export declare class MorphoBlue implements BlueActions {
457
457
  slippageTolerance?: bigint;
458
458
  targetReallocations?: readonly VaultReallocation[];
459
459
  }): {
460
- getRequirements: () => Promise<(Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined> | Readonly<Transaction<BlueAuthorizationAction>>)[]>;
460
+ getRequirements: () => Promise<(Readonly<Transaction<BlueAuthorizationAction>> | Requirement<import("../../types/action.js").AuthorizationRequirementSignature, undefined>)[]>;
461
461
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<BlueRefinanceAction>>;
462
462
  };
463
463
  /**
@@ -109,8 +109,7 @@ export declare class ReallocationData implements InputReallocationData {
109
109
  *
110
110
  * Pass `options.timestamp` to evaluate market interest and pending public
111
111
  * allocator caps at the same block as the fetched reallocation data.
112
- * This method does not add the legacy one-hour delay margin that
113
- * `SimulationState.getMarketPublicReallocations` applied before measuring
112
+ * This method does not add an implicit delay margin before measuring
114
113
  * target-market vault headroom. If a transaction may land later than the
115
114
  * fetched block, pass a future `timestamp` or reserve your own headroom so
116
115
  * interest accrued before inclusion does not make `reallocateTo` exceed the
@@ -199,8 +199,7 @@ export class ReallocationData {
199
199
  *
200
200
  * Pass `options.timestamp` to evaluate market interest and pending public
201
201
  * allocator caps at the same block as the fetched reallocation data.
202
- * This method does not add the legacy one-hour delay margin that
203
- * `SimulationState.getMarketPublicReallocations` applied before measuring
202
+ * This method does not add an implicit delay margin before measuring
204
203
  * target-market vault headroom. If a transaction may land later than the
205
204
  * fetched block, pass a future `timestamp` or reserve your own headroom so
206
205
  * interest accrued before inclusion does not make `reallocateTo` exceed the
@@ -1,8 +1,8 @@
1
- import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
1
+ import { type AccrualVault, type AccrualVaultV2, type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
- import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
5
+ import { type ActionOutput, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
6
6
  export interface VaultV1Actions {
7
7
  /**
8
8
  * Fetches the latest vault data with accrued interest.
@@ -63,6 +63,76 @@ export interface VaultV1Actions {
63
63
  }) => {
64
64
  buildTx: () => Readonly<Transaction<VaultV1RedeemAction>>;
65
65
  };
66
+ /**
67
+ * Prepares an illiquid Vault V1 exit into the vault's Morpho Blue supply positions.
68
+ *
69
+ * The caller controls market order and must call `getRequirements()` before `buildTx()` so the
70
+ * RPC-backed Blue-balance and Morpho-deployment checks run. The SDK validates market coverage but
71
+ * intentionally does not validate the user's share balance; size `amount` in asset terms against
72
+ * `previewRedeem(sharesHeld)`. The share allowance first accrues pending performance-fee shares,
73
+ * then uses the current rounded-up share preview; future interest can only reduce the required
74
+ * burn.
75
+ *
76
+ * Snapshot state can drift before inclusion, so a later reallocation may still make the on-chain
77
+ * loop under-cover even after pre-flight succeeds.
78
+ *
79
+ * @param params - In-kind redemption parameters.
80
+ * @param params.amount - Asset-denominated amount to exit.
81
+ * @param params.marketParamsList - Ordered vault markets consumed greedily by the contract;
82
+ * repeated entries cannot draw from the same vault position twice.
83
+ * @param params.vaultData - Pre-fetched Vault V1 accrual snapshot.
84
+ * @param params.userAddress - Account that signs and submits the exit.
85
+ * @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
86
+ * @returns Lazy prerequisite resolution and a synchronous transaction builder.
87
+ * @throws {ChainIdMismatchError} when the client and entity target different chains.
88
+ * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
89
+ * @throws {NonPositiveInputError} when `amount` is not positive.
90
+ * @throws {EmptyMarketParamsListError} when the market list is empty.
91
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
92
+ * requirement resolution.
93
+ * @throws {InKindRedeemCoverageError} when the ordered list cannot cover `amount` without
94
+ * assigning more than the vault owns in a repeated market.
95
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
96
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
97
+ * @throws {viem.BaseError} from `getRequirements()` when an RPC or multicall contract read fails.
98
+ * @throws {VaultMorphoMismatchError} from `getRequirements()` when the vault uses another Morpho deployment.
99
+ * @throws {VaultIsBlueFeeRecipientError} from `getRequirements()` when Morpho Blue accrues protocol fees to the vault.
100
+ * @throws {InsufficientBlueBalanceForInKindRedeemError} from `getRequirements()` when Blue cannot fund the flash loan.
101
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
102
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
103
+ * @throws {VaultExitBundlesV1PermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
104
+ * @example
105
+ * ```ts
106
+ * import { isRequirementSignature } from "@morpho-org/morpho-sdk";
107
+ *
108
+ * const vault = client.morpho.vaultV1(vaultAddress, 1);
109
+ * const vaultData = await vault.getData();
110
+ * const exit = vault.inKindRedeem({
111
+ * amount: 1_000_000n,
112
+ * marketParamsList,
113
+ * vaultData,
114
+ * userAddress,
115
+ * });
116
+ * const signatures = [];
117
+ * for (const requirement of await exit.getRequirements()) {
118
+ * if (isRequirementSignature(requirement)) {
119
+ * signatures.push(await requirement.sign(walletClient, userAddress));
120
+ * } else {
121
+ * const hash = await walletClient.sendTransaction(requirement);
122
+ * await client.waitForTransactionReceipt({ hash });
123
+ * }
124
+ * }
125
+ * const tx = exit.buildTx(signatures);
126
+ * // tx satisfies Readonly<Transaction<VaultV1InKindRedeemAction>>
127
+ * ```
128
+ */
129
+ readonly inKindRedeem: (params: {
130
+ readonly amount: bigint;
131
+ readonly marketParamsList: readonly MarketParams[];
132
+ readonly vaultData: AccrualVault;
133
+ readonly userAddress: Address;
134
+ readonly deadline?: bigint;
135
+ }) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
66
136
  /**
67
137
  * Prepares a full migration from VaultV1 to VaultV2.
68
138
  *
@@ -116,6 +186,14 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
116
186
  }): {
117
187
  buildTx: () => Readonly<Transaction<VaultV1RedeemAction>>;
118
188
  };
189
+ /** {@inheritDoc VaultV1Actions.inKindRedeem} */
190
+ inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }: {
191
+ readonly amount: bigint;
192
+ readonly marketParamsList: readonly MarketParams[];
193
+ readonly vaultData: AccrualVault;
194
+ readonly userAddress: Address;
195
+ readonly deadline?: bigint;
196
+ }): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
119
197
  migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance, }: {
120
198
  userAddress: Address;
121
199
  sourceVault: AccrualVault;
@@ -1,11 +1,12 @@
1
- import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MathLib, } from "@morpho-org/blue-sdk";
2
- import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
- import { Time } from "@morpho-org/morpho-ts";
4
- import { isAddressEqual } from "viem";
5
- import { getGeneralAdapterRequirements, vaultV1Deposit, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MarketUtils, MathLib, } from "@morpho-org/blue-sdk";
2
+ import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-org/blue-sdk-viem";
3
+ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
4
+ import { erc20Abi, isAddressEqual } from "viem";
5
+ import { multicall } from "viem/actions";
6
+ import { encodeErc20Approval, encodeVaultSharesPermit, getGeneralAdapterRequirements, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
6
7
  import { MAX_ABSOLUTE_SHARE_PRICE } from "../../helpers/constant.js";
7
8
  import { validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
8
- import { ChainIdMismatchError, ChainWNativeMissingError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
9
+ import { ChainIdMismatchError, ChainWNativeMissingError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
9
10
  export class MorphoVaultV1 {
10
11
  client;
11
12
  vault;
@@ -128,6 +129,169 @@ export class MorphoVaultV1 {
128
129
  }),
129
130
  };
130
131
  }
132
+ /** {@inheritDoc VaultV1Actions.inKindRedeem} */
133
+ inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
134
+ if (this.client.viemClient.chain?.id !== this.chainId) {
135
+ throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
136
+ }
137
+ if (!isAddressEqual(vaultData.address, this.vault)) {
138
+ throw new VaultAddressMismatchError(this.vault, vaultData.address);
139
+ }
140
+ if (amount <= 0n)
141
+ throw new NonPositiveInputError("amount", amount);
142
+ if (marketParamsList.length === 0)
143
+ throw new EmptyMarketParamsListError();
144
+ const marketParamsListSnapshot = marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => ({
145
+ loanToken,
146
+ collateralToken,
147
+ oracle,
148
+ irm,
149
+ lltv,
150
+ }));
151
+ const now = Time.timestamp();
152
+ const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
153
+ if (deadline <= now)
154
+ throw new ExpiredDeadlineError(deadline, now);
155
+ const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
156
+ const addresses = getChainAddresses(this.chainId);
157
+ const blue = addresses.blue ?? addresses.morpho;
158
+ let covered = 0n;
159
+ const assignedByMarket = new Map();
160
+ for (const marketParams of marketParamsListSnapshot) {
161
+ if (covered === amount)
162
+ break;
163
+ const marketId = MarketUtils.getMarketId(marketParams);
164
+ const allocation = vaultData.allocations.get(marketId);
165
+ if (allocation?.config.enabled !== true)
166
+ continue;
167
+ const market = allocation.position.market.accrueInterest(now);
168
+ const available = market.toSupplyAssets(allocation.position.supplyShares);
169
+ const assigned = assignedByMarket.get(marketId) ?? 0n;
170
+ const chunk = MathLib.min(available, amount - covered);
171
+ if (assigned + chunk > available) {
172
+ throw new InKindRedeemCoverageError({
173
+ required: amount,
174
+ covered,
175
+ maxExitAssets: covered,
176
+ });
177
+ }
178
+ assignedByMarket.set(marketId, assigned + chunk);
179
+ covered += chunk;
180
+ }
181
+ if (covered < amount) {
182
+ throw new InKindRedeemCoverageError({
183
+ required: amount,
184
+ covered,
185
+ maxExitAssets: covered,
186
+ });
187
+ }
188
+ // Account for pending performance-fee shares before previewing the burn. Once accrued, future
189
+ // V1 interest cannot lower the share price, so this upper-bounds execution.
190
+ const requiredShareAllowance = vaultData
191
+ .accrueInterest(now)
192
+ .toShares(amount);
193
+ return {
194
+ getRequirements: async () => {
195
+ const requirementsTimestamp = Time.timestamp();
196
+ if (deadline <= requirementsTimestamp) {
197
+ throw new ExpiredDeadlineError(deadline, requirementsTimestamp);
198
+ }
199
+ const [allowance, nonce, blueBalance, morpho, blueFeeRecipient] = await multicall(this.client.viemClient, {
200
+ allowFailure: false,
201
+ contracts: [
202
+ {
203
+ address: this.vault,
204
+ abi: erc20Abi,
205
+ functionName: "allowance",
206
+ args: [userAddress, vaultExitBundlesV1],
207
+ },
208
+ {
209
+ address: this.vault,
210
+ abi: erc2612Abi,
211
+ functionName: "nonces",
212
+ args: [userAddress],
213
+ },
214
+ {
215
+ address: vaultData.asset,
216
+ abi: erc20Abi,
217
+ functionName: "balanceOf",
218
+ args: [blue],
219
+ },
220
+ {
221
+ address: this.vault,
222
+ abi: metaMorphoAbi,
223
+ functionName: "MORPHO",
224
+ },
225
+ {
226
+ address: blue,
227
+ abi: blueAbi,
228
+ functionName: "feeRecipient",
229
+ },
230
+ ],
231
+ });
232
+ if (!isAddressEqual(morpho, blue)) {
233
+ throw new VaultMorphoMismatchError({
234
+ vault: this.vault,
235
+ expected: blue,
236
+ actual: morpho,
237
+ });
238
+ }
239
+ // Reject this unsupported configuration before authorizing vault shares:
240
+ // VaultExitBundlesV1 omits newly accrued Morpho fee shares when estimating the
241
+ // vault position, so its callback can exhaust marketParamsList and panic on-chain.
242
+ if (isAddressEqual(blueFeeRecipient, this.vault)) {
243
+ throw new VaultIsBlueFeeRecipientError(this.vault, blue);
244
+ }
245
+ if (blueBalance < amount) {
246
+ throw new InsufficientBlueBalanceForInKindRedeemError({
247
+ asset: vaultData.asset,
248
+ available: blueBalance,
249
+ required: amount,
250
+ });
251
+ }
252
+ if (allowance >= requiredShareAllowance)
253
+ return [];
254
+ if (this.client.options.supportSignature) {
255
+ return [
256
+ encodeVaultSharesPermit({
257
+ vault: vaultData,
258
+ version: "vaultV1",
259
+ spender: vaultExitBundlesV1,
260
+ owner: userAddress,
261
+ chainId: this.chainId,
262
+ nonce,
263
+ amount: requiredShareAllowance,
264
+ deadline,
265
+ }),
266
+ ];
267
+ }
268
+ return [
269
+ encodeErc20Approval({
270
+ token: this.vault,
271
+ spender: vaultExitBundlesV1,
272
+ amount: requiredShareAllowance,
273
+ chainId: this.chainId,
274
+ }),
275
+ ];
276
+ },
277
+ buildTx: (signatures) => {
278
+ const { permit } = selectRequirementSignatures(signatures, {
279
+ permit: true,
280
+ });
281
+ return vaultV1InKindRedeem({
282
+ vault: { chainId: this.chainId, address: this.vault },
283
+ args: {
284
+ amount,
285
+ marketParamsList: marketParamsListSnapshot,
286
+ userAddress,
287
+ deadline,
288
+ requirementSignature: permit,
289
+ },
290
+ metadata: this.client.options.metadata,
291
+ });
292
+ },
293
+ };
294
+ }
131
295
  migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, }) {
132
296
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
133
297
  if (!isAddressEqual(sourceVault.address, this.vault)) {