@morpho-org/morpho-sdk 5.4.1 → 5.6.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 (140) hide show
  1. package/README.md +23 -7
  2. package/lib/cjs/abis.d.ts +314 -1
  3. package/lib/cjs/abis.js +169 -1
  4. package/lib/cjs/actions/blue/borrow.d.ts +21 -15
  5. package/lib/cjs/actions/blue/borrow.js +25 -18
  6. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +1 -1
  7. package/lib/cjs/actions/blue/buildAssetFundingActions.js +1 -1
  8. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +62 -19
  9. package/lib/cjs/actions/blue/buildReallocationActions.js +123 -27
  10. package/lib/cjs/actions/blue/refinance.d.ts +14 -7
  11. package/lib/cjs/actions/blue/refinance.js +18 -10
  12. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  13. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +39 -23
  14. package/lib/cjs/actions/blue/withdraw.d.ts +20 -13
  15. package/lib/cjs/actions/blue/withdraw.js +23 -18
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  17. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +9 -2
  18. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
  19. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +131 -0
  20. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  21. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  22. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  23. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -3
  24. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
  25. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +91 -0
  26. package/lib/cjs/actions/signatures/index.d.ts +1 -0
  27. package/lib/cjs/actions/signatures/index.js +1 -0
  28. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +54 -0
  29. package/lib/cjs/actions/vaultV1/inKindRedeem.js +96 -0
  30. package/lib/cjs/actions/vaultV1/index.d.ts +1 -0
  31. package/lib/cjs/actions/vaultV1/index.js +1 -0
  32. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +56 -0
  33. package/lib/cjs/actions/vaultV2/inKindRedeem.js +97 -0
  34. package/lib/cjs/actions/vaultV2/index.d.ts +1 -0
  35. package/lib/cjs/actions/vaultV2/index.js +1 -0
  36. package/lib/cjs/bundler/actions.d.ts +118 -2
  37. package/lib/cjs/bundler/actions.js +212 -6
  38. package/lib/cjs/bundler/types.d.ts +20 -0
  39. package/lib/cjs/constants.d.ts +1 -1
  40. package/lib/cjs/constants.js +3 -1
  41. package/lib/cjs/entities/blue/blue.d.ts +365 -76
  42. package/lib/cjs/entities/blue/blue.js +285 -52
  43. package/lib/cjs/entities/index.d.ts +2 -1
  44. package/lib/cjs/entities/index.js +6 -3
  45. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +82 -4
  46. package/lib/cjs/entities/vaultV1/vaultV1.js +164 -0
  47. package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +41 -17
  48. package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +30 -18
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +89 -3
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +181 -0
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1311 -0
  53. package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  54. package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
  55. package/lib/cjs/helpers/constant.d.ts +5 -3
  56. package/lib/cjs/helpers/constant.js +6 -4
  57. package/lib/cjs/helpers/index.d.ts +3 -2
  58. package/lib/cjs/helpers/index.js +8 -3
  59. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
  60. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +73 -0
  61. package/lib/cjs/helpers/validate.d.ts +31 -15
  62. package/lib/cjs/helpers/validate.js +140 -27
  63. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  64. package/lib/cjs/helpers/validateRequirementSpender.js +2 -1
  65. package/lib/cjs/types/action.d.ts +33 -1
  66. package/lib/cjs/types/error.d.ts +363 -5
  67. package/lib/cjs/types/error.js +455 -6
  68. package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
  69. package/lib/cjs/utils.d.ts +2 -2
  70. package/lib/cjs/utils.js +6 -4
  71. package/lib/esm/abis.d.ts +314 -1
  72. package/lib/esm/abis.js +167 -1
  73. package/lib/esm/actions/blue/borrow.d.ts +21 -15
  74. package/lib/esm/actions/blue/borrow.js +26 -19
  75. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
  76. package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
  77. package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
  78. package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
  79. package/lib/esm/actions/blue/refinance.d.ts +14 -7
  80. package/lib/esm/actions/blue/refinance.js +19 -11
  81. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  82. package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
  83. package/lib/esm/actions/blue/withdraw.d.ts +20 -13
  84. package/lib/esm/actions/blue/withdraw.js +24 -19
  85. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  86. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -2
  87. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
  88. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +127 -0
  89. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  90. package/lib/esm/actions/requirements/encode/index.js +1 -0
  91. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  92. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -3
  93. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
  94. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +87 -0
  95. package/lib/esm/actions/signatures/index.d.ts +1 -0
  96. package/lib/esm/actions/signatures/index.js +1 -0
  97. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +54 -0
  98. package/lib/esm/actions/vaultV1/inKindRedeem.js +92 -0
  99. package/lib/esm/actions/vaultV1/index.d.ts +1 -0
  100. package/lib/esm/actions/vaultV1/index.js +1 -0
  101. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +56 -0
  102. package/lib/esm/actions/vaultV2/inKindRedeem.js +93 -0
  103. package/lib/esm/actions/vaultV2/index.d.ts +1 -0
  104. package/lib/esm/actions/vaultV2/index.js +1 -0
  105. package/lib/esm/bundler/actions.d.ts +118 -2
  106. package/lib/esm/bundler/actions.js +215 -9
  107. package/lib/esm/bundler/types.d.ts +20 -0
  108. package/lib/esm/constants.d.ts +1 -1
  109. package/lib/esm/constants.js +1 -1
  110. package/lib/esm/entities/blue/blue.d.ts +362 -73
  111. package/lib/esm/entities/blue/blue.js +288 -55
  112. package/lib/esm/entities/index.d.ts +2 -1
  113. package/lib/esm/entities/index.js +2 -1
  114. package/lib/esm/entities/vaultV1/vaultV1.d.ts +80 -2
  115. package/lib/esm/entities/vaultV1/vaultV1.js +170 -6
  116. package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +41 -17
  117. package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +33 -16
  118. package/lib/esm/entities/vaultV2/vaultV2.d.ts +88 -2
  119. package/lib/esm/entities/vaultV2/vaultV2.js +187 -6
  120. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
  121. package/lib/esm/entities/vaultV2BlueReallocationData.js +1307 -0
  122. package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  123. package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
  124. package/lib/esm/helpers/constant.d.ts +5 -3
  125. package/lib/esm/helpers/constant.js +5 -3
  126. package/lib/esm/helpers/index.d.ts +3 -2
  127. package/lib/esm/helpers/index.js +3 -2
  128. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
  129. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +70 -0
  130. package/lib/esm/helpers/validate.d.ts +31 -15
  131. package/lib/esm/helpers/validate.js +141 -30
  132. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  133. package/lib/esm/helpers/validateRequirementSpender.js +2 -1
  134. package/lib/esm/types/action.d.ts +33 -1
  135. package/lib/esm/types/error.d.ts +363 -5
  136. package/lib/esm/types/error.js +428 -4
  137. package/lib/esm/types/sharedLiquidity.d.ts +72 -8
  138. package/lib/esm/utils.d.ts +2 -2
  139. package/lib/esm/utils.js +2 -2
  140. package/package.json +9 -11
@@ -0,0 +1,87 @@
1
+ import { compactSignatureToSignature, isAddressEqual, parseCompactSignature, parseSignature, size, zeroHash, } from "viem";
2
+ import { VaultExitBundlesV1PermitMismatchError, } from "../../types/index.js";
3
+ /**
4
+ * Returns the permit struct consumed by VaultExitBundlesV1 from an optional vault-share
5
+ * requirement signature.
6
+ *
7
+ * Without a signature, returns the contract's empty-permit sentinel. With a signature, validates
8
+ * the ERC-2612 kind and vault asset before splitting the serialized signature.
9
+ * Owner, spender, deadline, nonce, and cryptographic validity are verified onchain by the vault.
10
+ *
11
+ * @param params.vault - Vault share token authorized by the permit.
12
+ * @param params.deadline - Bundle deadline used by the empty-permit sentinel.
13
+ * @param params.requirementSignature - Optional signed bounded ERC-2612 requirement.
14
+ * @returns The VaultExitBundlesV1 permit tuple.
15
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
16
+ * @example
17
+ * ```ts
18
+ * import { getVaultExitBundlesV1PermitStruct } from "@morpho-org/morpho-sdk";
19
+ *
20
+ * const permit = getVaultExitBundlesV1PermitStruct({
21
+ * vault,
22
+ * deadline,
23
+ * requirementSignature,
24
+ * });
25
+ * // permit satisfies VaultExitBundlesV1PermitStruct
26
+ * ```
27
+ */
28
+ export const getVaultExitBundlesV1PermitStruct = (params) => {
29
+ const { requirementSignature } = params;
30
+ if (requirementSignature == null) {
31
+ return {
32
+ value: 0n,
33
+ nonce: 0n,
34
+ deadline: params.deadline,
35
+ v: 0,
36
+ r: zeroHash,
37
+ s: zeroHash,
38
+ };
39
+ }
40
+ if (requirementSignature.action.type !== "permit") {
41
+ throw new VaultExitBundlesV1PermitMismatchError({
42
+ field: "type",
43
+ expected: "permit",
44
+ actual: requirementSignature.action.type,
45
+ });
46
+ }
47
+ if (!isAddressEqual(requirementSignature.args.asset, params.vault)) {
48
+ throw new VaultExitBundlesV1PermitMismatchError({
49
+ field: "asset",
50
+ expected: params.vault,
51
+ actual: requirementSignature.args.asset,
52
+ });
53
+ }
54
+ const signature = (() => {
55
+ try {
56
+ const serializedSignature = requirementSignature.args.signature;
57
+ return size(serializedSignature) === 64
58
+ ? compactSignatureToSignature(parseCompactSignature(serializedSignature))
59
+ : parseSignature(serializedSignature);
60
+ }
61
+ catch (cause) {
62
+ throw new VaultExitBundlesV1PermitMismatchError({
63
+ field: "signature",
64
+ expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
65
+ actual: requirementSignature.args.signature,
66
+ cause,
67
+ });
68
+ }
69
+ })();
70
+ const { r, s, v, yParity } = signature;
71
+ const normalizedV = v ?? (yParity == null ? undefined : BigInt(yParity + 27));
72
+ if (normalizedV == null) {
73
+ throw new VaultExitBundlesV1PermitMismatchError({
74
+ field: "signature",
75
+ expected: "a signature containing v or yParity",
76
+ actual: requirementSignature.args.signature,
77
+ });
78
+ }
79
+ return {
80
+ value: requirementSignature.args.amount,
81
+ nonce: requirementSignature.args.nonce,
82
+ deadline: requirementSignature.args.deadline,
83
+ v: Number(normalizedV),
84
+ r,
85
+ s,
86
+ };
87
+ };
@@ -1,2 +1,3 @@
1
1
  export * from "./getBlueAuthorizationAction.js";
2
2
  export * from "./getTokenRequirementActions.js";
3
+ export * from "./getVaultExitBundlesV1PermitStruct.js";
@@ -1,2 +1,3 @@
1
1
  export * from "./getBlueAuthorizationAction.js";
2
2
  export * from "./getTokenRequirementActions.js";
3
+ export * from "./getVaultExitBundlesV1PermitStruct.js";
@@ -0,0 +1,54 @@
1
+ import type { InputMarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address } from "viem";
3
+ import { type Metadata, type PermitRequirementSignature, type Transaction, type VaultV1InKindRedeemAction } from "../../types/index.js";
4
+ /** Parameters for {@link vaultV1InKindRedeem}. */
5
+ export interface VaultV1InKindRedeemParams {
6
+ readonly vault: {
7
+ readonly chainId: number;
8
+ readonly address: Address;
9
+ };
10
+ readonly args: {
11
+ readonly amount: bigint;
12
+ readonly marketParamsList: readonly InputMarketParams[];
13
+ readonly userAddress: Address;
14
+ readonly deadline: bigint;
15
+ readonly requirementSignature?: PermitRequirementSignature;
16
+ };
17
+ readonly metadata?: Metadata;
18
+ }
19
+ /**
20
+ * Prepares a Vault V1 in-kind redemption into Morpho Blue supply positions.
21
+ *
22
+ * The transaction calls VaultExitBundlesV1 directly. Without a signature it embeds the contract's
23
+ * empty-permit sentinel; the user must first approve enough shares for the exit.
24
+ *
25
+ * @param params - In-kind redemption parameters.
26
+ * @param params.vault.chainId - Chain containing the target Vault V1 and VaultExitBundlesV1.
27
+ * @param params.vault.address - Target Vault V1 address.
28
+ * @param params.args.amount - Asset-denominated amount to exit.
29
+ * @param params.args.marketParamsList - Ordered markets consumed greedily by the contract.
30
+ * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
31
+ * VaultExitBundlesV1 burns `msg.sender`'s vault shares, so the submitting account must equal this
32
+ * address.
33
+ * @param params.args.deadline - Permit and bundle deadline.
34
+ * @param params.args.requirementSignature - Optional bounded Vault V1 shares permit.
35
+ * @param params.metadata - Optional analytics metadata.
36
+ * @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
37
+ * `data`, and the typed action discriminator.
38
+ * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
39
+ * @throws {EmptyMarketParamsListError} when no markets are supplied.
40
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
41
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
42
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
43
+ * @example
44
+ * ```ts
45
+ * import { vaultV1InKindRedeem } from "@morpho-org/morpho-sdk";
46
+ *
47
+ * const tx = vaultV1InKindRedeem({
48
+ * vault: { chainId: 1, address: vault },
49
+ * args: { amount: 1_000_000n, marketParamsList, userAddress, deadline },
50
+ * });
51
+ * // tx satisfies Readonly<Transaction<VaultV1InKindRedeemAction>>
52
+ * ```
53
+ */
54
+ export declare const vaultV1InKindRedeem: ({ vault, args, metadata, }: VaultV1InKindRedeemParams) => Readonly<Transaction<VaultV1InKindRedeemAction>>;
@@ -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
  /**
@@ -651,6 +650,123 @@ export declare namespace BundlerAction {
651
650
  * ```
652
651
  */
653
652
  function publicAllocatorReallocateTo(chainId: number, vault: Address, fee: bigint, withdrawals: InputReallocation[], supplyMarketParams: InputMarketParams, skipRevert?: boolean): BundlerCall[];
653
+ /**
654
+ * Encodes a Vault V2 Blue Public Allocator market-to-market reallocation.
655
+ *
656
+ * @remarks Bundler3 must already hold the computed penalty assets. The
657
+ * high-level Blue builders add the corresponding GeneralAdapter1 transfer.
658
+ *
659
+ * @param chainId - Chain whose canonical Blue Public Allocator is called.
660
+ * @param vault - Vault whose liquidity is reallocated.
661
+ * @param deallocateAdapter - Vault V2 adapter supplying the source market.
662
+ * @param deallocateMarket - Source Morpho Blue market parameters.
663
+ * @param allocateAdapter - Vault V2 adapter supplying the target market.
664
+ * @param allocateMarket - Target Morpho Blue market parameters.
665
+ * @param assets - Assets to reallocate, bounded by `uint128` by the high-level action.
666
+ * @param penalty - Vault-configured proportional penalty, scaled by WAD.
667
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
668
+ * @returns A zero reset and exact approval when needed, then the allocator call.
669
+ * @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
670
+ * @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
671
+ * @example
672
+ * ```ts
673
+ * import { ChainId, type InputMarketParams } from "@morpho-org/blue-sdk";
674
+ * import {
675
+ * BundlerAction,
676
+ * type BundlerCall,
677
+ * } from "@morpho-org/morpho-sdk/bundler";
678
+ * import type { Address } from "viem";
679
+ *
680
+ * const keyrockUsdcVault =
681
+ * "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
682
+ * const sourceAdapterFixture =
683
+ * "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" satisfies Address;
684
+ * const targetAdapterFixture =
685
+ * "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
686
+ * const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
687
+ * const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
688
+ * const wbtc = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" satisfies Address;
689
+ * const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
690
+ * const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
691
+ * const sourceMarket = {
692
+ * loanToken: usdc,
693
+ * collateralToken: weth,
694
+ * oracle: ethUsdOracle,
695
+ * irm: adaptiveCurveIrm,
696
+ * lltv: 860_000_000_000_000_000n,
697
+ * } satisfies InputMarketParams;
698
+ * const targetMarket = {
699
+ * ...sourceMarket,
700
+ * collateralToken: wbtc,
701
+ * } satisfies InputMarketParams;
702
+ *
703
+ * const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorReallocate(
704
+ * ChainId.EthMainnet,
705
+ * keyrockUsdcVault,
706
+ * sourceAdapterFixture,
707
+ * sourceMarket,
708
+ * targetAdapterFixture,
709
+ * targetMarket,
710
+ * 1_000_000n,
711
+ * 1_000_000_000_000_000n,
712
+ * );
713
+ * // Bundler3 resets and approves 1_000 USDC units, then calls `reallocate` with zero native value.
714
+ * ```
715
+ */
716
+ function vaultV2BluePublicAllocatorReallocate(chainId: number, vault: Address, deallocateAdapter: Address, deallocateMarket: InputMarketParams, allocateAdapter: Address, allocateMarket: InputMarketParams, assets: bigint, penalty: bigint, skipRevert?: boolean): BundlerCall[];
717
+ /**
718
+ * Encodes a Vault V2 Blue Public Allocator allocation from vault idle liquidity.
719
+ *
720
+ * @remarks Bundler3 must already hold the computed penalty assets. The
721
+ * high-level Blue builders add the corresponding GeneralAdapter1 transfer.
722
+ *
723
+ * @param chainId - Chain whose canonical Blue Public Allocator is called.
724
+ * @param vault - Vault whose idle liquidity is allocated.
725
+ * @param adapter - Vault V2 adapter supplying the target market.
726
+ * @param market - Target Morpho Blue market parameters.
727
+ * @param assets - Assets to allocate, bounded by `uint128` by the high-level action.
728
+ * @param penalty - Vault-configured proportional penalty, scaled by WAD.
729
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
730
+ * @returns A zero reset and exact approval when needed, then the allocator call.
731
+ * @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
732
+ * @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
733
+ * @example
734
+ * ```ts
735
+ * import { ChainId, type InputMarketParams } from "@morpho-org/blue-sdk";
736
+ * import {
737
+ * BundlerAction,
738
+ * type BundlerCall,
739
+ * } from "@morpho-org/morpho-sdk/bundler";
740
+ * import type { Address } from "viem";
741
+ *
742
+ * const keyrockUsdcVault =
743
+ * "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
744
+ * const targetAdapterFixture =
745
+ * "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
746
+ * const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
747
+ * const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
748
+ * const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
749
+ * const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
750
+ * const targetMarket = {
751
+ * loanToken: usdc,
752
+ * collateralToken: weth,
753
+ * oracle: ethUsdOracle,
754
+ * irm: adaptiveCurveIrm,
755
+ * lltv: 860_000_000_000_000_000n,
756
+ * } satisfies InputMarketParams;
757
+ *
758
+ * const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle(
759
+ * ChainId.EthMainnet,
760
+ * keyrockUsdcVault,
761
+ * targetAdapterFixture,
762
+ * targetMarket,
763
+ * 1_000_000n,
764
+ * 1_000_000_000_000_000n,
765
+ * );
766
+ * // Bundler3 resets and approves 1_000 USDC units, then calls `allocateFromIdle` with zero native value.
767
+ * ```
768
+ */
769
+ function vaultV2BluePublicAllocatorAllocateFromIdle(chainId: number, vault: Address, adapter: Address, market: InputMarketParams, assets: bigint, penalty: bigint, skipRevert?: boolean): BundlerCall[];
654
770
  /**
655
771
  * Encodes a GeneralAdapter1 native-token wrap call.
656
772
  *