@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.2

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 (174) hide show
  1. package/MIGRATION-v5-to-v6.md +127 -16
  2. package/README.md +17 -11
  3. package/lib/cjs/abis.d.ts +17 -2
  4. package/lib/cjs/abis.js +14 -1
  5. package/lib/cjs/actions/blue/common.js +5 -26
  6. package/lib/cjs/actions/blue/supply.js +2 -7
  7. package/lib/cjs/actions/bundles/common.d.ts +32 -2
  8. package/lib/cjs/actions/bundles/common.js +68 -30
  9. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  10. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
  11. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  12. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  13. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  14. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +20 -20
  15. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -27
  17. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  18. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  19. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  20. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  21. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  22. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  23. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  24. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  25. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  26. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
  27. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
  28. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
  29. package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
  30. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  31. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  32. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
  33. package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
  34. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  35. package/lib/cjs/blue/abis.d.ts +5 -1
  36. package/lib/cjs/blue/abis.js +2 -0
  37. package/lib/cjs/blue/entities.d.ts +8 -2
  38. package/lib/cjs/blue/entities.js +1 -0
  39. package/lib/cjs/blue/errors.d.ts +1 -1
  40. package/lib/cjs/blue/errors.js +2 -1
  41. package/lib/cjs/blue/fetch.d.ts +3 -1
  42. package/lib/cjs/blue/fetch.js +1 -0
  43. package/lib/cjs/entities/blue/blue.d.ts +15 -6
  44. package/lib/cjs/entities/blue/blue.js +3 -0
  45. package/lib/cjs/entities/index.d.ts +8 -2
  46. package/lib/cjs/entities/index.js +1 -0
  47. package/lib/cjs/entities/midnight/midnight.js +20 -24
  48. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  49. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
  50. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  51. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  52. package/lib/cjs/entities/requirements/index.js +1 -0
  53. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +10 -5
  54. package/lib/cjs/entities/vaultV1/vaultV1.js +13 -1
  55. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  56. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  57. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +140 -34
  58. package/lib/cjs/entities/vaultV2/vaultV2.js +229 -16
  59. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  60. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  61. package/lib/cjs/errors.d.ts +1 -1
  62. package/lib/cjs/errors.js +3 -2
  63. package/lib/cjs/fetch.d.ts +3 -1
  64. package/lib/cjs/fetch.js +1 -0
  65. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  66. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  67. package/lib/cjs/helpers/index.d.ts +3 -1
  68. package/lib/cjs/helpers/index.js +10 -1
  69. package/lib/cjs/helpers/metadata.d.ts +3 -5
  70. package/lib/cjs/helpers/metadata.js +4 -6
  71. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  72. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  73. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  74. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  75. package/lib/cjs/helpers/slippage.d.ts +46 -0
  76. package/lib/cjs/helpers/slippage.js +65 -0
  77. package/lib/cjs/helpers/validate.d.ts +65 -8
  78. package/lib/cjs/helpers/validate.js +83 -9
  79. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  80. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  81. package/lib/cjs/types/action.d.ts +95 -13
  82. package/lib/cjs/types/error.d.ts +290 -12
  83. package/lib/cjs/types/error.js +312 -24
  84. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  85. package/lib/cjs/utils.d.ts +3 -1
  86. package/lib/cjs/utils.js +10 -1
  87. package/lib/esm/abis.d.ts +17 -2
  88. package/lib/esm/abis.js +17 -2
  89. package/lib/esm/actions/blue/common.js +7 -28
  90. package/lib/esm/actions/blue/supply.js +4 -9
  91. package/lib/esm/actions/bundles/common.d.ts +32 -2
  92. package/lib/esm/actions/bundles/common.js +68 -31
  93. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  94. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
  95. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  96. package/lib/esm/actions/requirements/blue/index.js +0 -1
  97. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  98. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
  99. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  100. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -28
  101. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  102. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  103. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  104. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  105. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  106. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  107. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  108. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  109. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  110. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
  111. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
  112. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
  113. package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
  114. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  115. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  116. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
  117. package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
  118. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  119. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  120. package/lib/esm/blue/abis.d.ts +5 -1
  121. package/lib/esm/blue/abis.js +5 -1
  122. package/lib/esm/blue/entities.d.ts +8 -2
  123. package/lib/esm/blue/entities.js +3 -1
  124. package/lib/esm/blue/errors.d.ts +1 -1
  125. package/lib/esm/blue/errors.js +1 -1
  126. package/lib/esm/blue/fetch.d.ts +3 -1
  127. package/lib/esm/blue/fetch.js +3 -1
  128. package/lib/esm/entities/blue/blue.d.ts +15 -6
  129. package/lib/esm/entities/blue/blue.js +3 -0
  130. package/lib/esm/entities/index.d.ts +8 -2
  131. package/lib/esm/entities/index.js +3 -1
  132. package/lib/esm/entities/midnight/midnight.js +20 -24
  133. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  134. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
  135. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  136. package/lib/esm/entities/requirements/index.d.ts +1 -0
  137. package/lib/esm/entities/requirements/index.js +1 -0
  138. package/lib/esm/entities/vaultV1/vaultV1.d.ts +10 -5
  139. package/lib/esm/entities/vaultV1/vaultV1.js +14 -2
  140. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  141. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  142. package/lib/esm/entities/vaultV2/vaultV2.d.ts +140 -34
  143. package/lib/esm/entities/vaultV2/vaultV2.js +234 -21
  144. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  145. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  146. package/lib/esm/errors.d.ts +1 -1
  147. package/lib/esm/errors.js +1 -1
  148. package/lib/esm/fetch.d.ts +3 -1
  149. package/lib/esm/fetch.js +3 -1
  150. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  151. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  152. package/lib/esm/helpers/index.d.ts +3 -1
  153. package/lib/esm/helpers/index.js +3 -1
  154. package/lib/esm/helpers/metadata.d.ts +3 -5
  155. package/lib/esm/helpers/metadata.js +4 -6
  156. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  157. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  158. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  159. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  160. package/lib/esm/helpers/slippage.d.ts +46 -0
  161. package/lib/esm/helpers/slippage.js +65 -1
  162. package/lib/esm/helpers/validate.d.ts +65 -8
  163. package/lib/esm/helpers/validate.js +82 -10
  164. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  165. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  166. package/lib/esm/types/action.d.ts +95 -13
  167. package/lib/esm/types/error.d.ts +290 -12
  168. package/lib/esm/types/error.js +301 -19
  169. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  170. package/lib/esm/utils.d.ts +3 -1
  171. package/lib/esm/utils.js +3 -1
  172. package/package.json +7 -7
  173. /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
  174. /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
@@ -9,7 +9,8 @@ const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTyped
9
9
  * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
10
10
  * via the Permit2 contract.
11
11
  *
12
- * Deadline defaults to two hours from `Time.timestamp()`.
12
+ * The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
13
+ * displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
13
14
  *
14
15
  * @param params - Permit2 encoding parameters.
15
16
  * @param params.token - ERC-20 token address.
@@ -17,7 +18,8 @@ const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTyped
17
18
  * @param params.chainId - Target chain id.
18
19
  * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
19
20
  * @param params.expiration - Permit2-managed allowance expiration timestamp.
20
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
21
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
22
+ * `sign(client, userAddress)` produces the deep-frozen signature.
21
23
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
22
24
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
23
25
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -40,6 +42,16 @@ const encodeErc20Permit2Approve = (params) => {
40
42
  const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
41
43
  const now = morpho_ts_1.Time.timestamp();
42
44
  const deadline = now + morpho_ts_1.Time.s.from.h(2n);
45
+ // Permit2 AllowanceTransfer signs over `PermitSingle` (token, spender, expiration, nonce), which
46
+ // does not include the owner, so the payload is fully determined at build time.
47
+ const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getPermit2PermitTypedData)({
48
+ spender: generalAdapter1,
49
+ allowance: amount,
50
+ erc20: token,
51
+ nonce: Number(nonce),
52
+ deadline,
53
+ expiration: Number(expiration),
54
+ }, chainId));
43
55
  const action = {
44
56
  type: "permit2",
45
57
  args: {
@@ -48,18 +60,11 @@ const encodeErc20Permit2Approve = (params) => {
48
60
  deadline,
49
61
  expiration,
50
62
  },
63
+ typedData,
51
64
  };
52
65
  return {
53
66
  action,
54
67
  async sign(client, userAddress) {
55
- const typedData = (0, blue_sdk_viem_1.getPermit2PermitTypedData)({
56
- spender: generalAdapter1,
57
- allowance: amount,
58
- erc20: token,
59
- nonce: Number(nonce),
60
- deadline,
61
- expiration: Number(expiration),
62
- }, chainId);
63
68
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
64
69
  client,
65
70
  userAddress,
@@ -19,7 +19,8 @@ export interface EncodeErc20Permit2SignatureTransferParams {
19
19
  * Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
20
20
  *
21
21
  * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
22
- * it has no managed allowance expiration.
22
+ * it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
23
+ * payload so it can be inspected or displayed before signing.
23
24
  *
24
25
  * @param params - SignatureTransfer parameters.
25
26
  * @param params.token - ERC-20 token pulled through Permit2.
@@ -28,7 +29,8 @@ export interface EncodeErc20Permit2SignatureTransferParams {
28
29
  * @param params.chainId - Target chain id.
29
30
  * @param params.nonce - Unused Permit2 unordered nonce.
30
31
  * @param params.deadline - Signature expiration timestamp in seconds.
31
- * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
32
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
33
+ * `sign(client, userAddress)` returns a deep-frozen signature result.
32
34
  * @throws {NegativeInputError} when `amount` or `nonce` is negative.
33
35
  * @throws {NonPositiveInputError} when `deadline` is not positive.
34
36
  * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
@@ -12,7 +12,8 @@ const index_js_1 = require("../../../types/index.js");
12
12
  * Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
13
13
  *
14
14
  * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
15
- * it has no managed allowance expiration.
15
+ * it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
16
+ * payload so it can be inspected or displayed before signing.
16
17
  *
17
18
  * @param params - SignatureTransfer parameters.
18
19
  * @param params.token - ERC-20 token pulled through Permit2.
@@ -21,7 +22,8 @@ const index_js_1 = require("../../../types/index.js");
21
22
  * @param params.chainId - Target chain id.
22
23
  * @param params.nonce - Unused Permit2 unordered nonce.
23
24
  * @param params.deadline - Signature expiration timestamp in seconds.
24
- * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
25
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
26
+ * `sign(client, userAddress)` returns a deep-frozen signature result.
25
27
  * @throws {NegativeInputError} when `amount` or `nonce` is negative.
26
28
  * @throws {NonPositiveInputError} when `deadline` is not positive.
27
29
  * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
@@ -87,20 +89,23 @@ const encodeErc20Permit2SignatureTransfer = (params) => {
87
89
  // sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
88
90
  // this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
89
91
  (0, morpho_ts_1.getChainAddress)(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
92
+ // Permit2 SignatureTransfer signs over `PermitTransferFrom` (permitted, spender, nonce,
93
+ // deadline), which does not include the owner, so the payload is fully determined at build time.
94
+ const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getPermit2TransferFromTypedData)({
95
+ erc20: token,
96
+ allowance: amount,
97
+ spender,
98
+ nonce,
99
+ deadline,
100
+ }, chainId));
90
101
  const action = {
91
102
  type: "permit2SignatureTransfer",
92
103
  args: { spender, amount, nonce, deadline },
104
+ typedData,
93
105
  };
94
106
  return {
95
107
  action,
96
108
  async sign(client, userAddress) {
97
- const typedData = (0, blue_sdk_viem_1.getPermit2TransferFromTypedData)({
98
- erc20: token,
99
- allowance: amount,
100
- spender,
101
- nonce,
102
- deadline,
103
- }, chainId);
104
109
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
105
110
  client,
106
111
  userAddress,
@@ -23,7 +23,8 @@ export interface EncodeVaultSharesPermitParams {
23
23
  * Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
24
24
  *
25
25
  * Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
26
- * only `chainId` and `verifyingContract`.
26
+ * only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
27
+ * payload so it can be inspected or displayed before signing.
27
28
  *
28
29
  * @param params.vault - Vault share token, including V1 permit-domain metadata when available.
29
30
  * @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
@@ -33,16 +34,18 @@ export interface EncodeVaultSharesPermitParams {
33
34
  * @param params.nonce - Current vault permit nonce for the owner.
34
35
  * @param params.amount - Vault-share allowance to authorize.
35
36
  * @param params.deadline - Shared permit and bundle deadline.
36
- * @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
37
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
38
+ * can be embedded in fixed vault-bundles calldata.
37
39
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
38
40
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
39
41
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
40
- * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
42
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
43
+ * wallet account differs from `userAddress`.
41
44
  * @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
42
45
  * @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
43
- * @throws {InvalidPermitDomainChainIdError} from `sign()` when a Vault V1 permit domain targets another chain or omits `chainId`.
44
- * @throws {InvalidPermitDomainVerifyingContractError} from `sign()` when a Vault V1 permit domain targets another token or omits `verifyingContract`.
45
- * @throws {UnsupportedPermitDomainExtensionsError} from `sign()` when a Vault V1 permit domain advertises unsupported extensions.
46
+ * @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
47
+ * @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
48
+ * @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
46
49
  * @example
47
50
  * ```ts
48
51
  * import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
@@ -12,7 +12,8 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
12
12
  * Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
13
13
  *
14
14
  * Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
15
- * only `chainId` and `verifyingContract`.
15
+ * only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
16
+ * payload so it can be inspected or displayed before signing.
16
17
  *
17
18
  * @param params.vault - Vault share token, including V1 permit-domain metadata when available.
18
19
  * @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
@@ -22,16 +23,18 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
22
23
  * @param params.nonce - Current vault permit nonce for the owner.
23
24
  * @param params.amount - Vault-share allowance to authorize.
24
25
  * @param params.deadline - Shared permit and bundle deadline.
25
- * @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
26
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
27
+ * can be embedded in fixed vault-bundles calldata.
26
28
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
27
29
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
28
30
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
29
- * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
31
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
32
+ * wallet account differs from `userAddress`.
30
33
  * @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
31
34
  * @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
32
- * @throws {InvalidPermitDomainChainIdError} from `sign()` when a Vault V1 permit domain targets another chain or omits `chainId`.
33
- * @throws {InvalidPermitDomainVerifyingContractError} from `sign()` when a Vault V1 permit domain targets another token or omits `verifyingContract`.
34
- * @throws {UnsupportedPermitDomainExtensionsError} from `sign()` when a Vault V1 permit domain advertises unsupported extensions.
35
+ * @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
36
+ * @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
37
+ * @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
35
38
  * @example
36
39
  * ```ts
37
40
  * import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
@@ -85,6 +88,18 @@ const encodeVaultSharesPermit = (params) => {
85
88
  spender,
86
89
  allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
87
90
  });
91
+ const permitTypedData = (0, blue_sdk_viem_1.getPermitTypedData)({
92
+ owner,
93
+ spender,
94
+ allowance: amount,
95
+ nonce,
96
+ deadline,
97
+ erc20: vault,
98
+ }, chainId);
99
+ const typedData = (0, morpho_ts_1.deepFreeze)({
100
+ ...permitTypedData,
101
+ domain: { ...permitTypedData.domain },
102
+ });
88
103
  const action = {
89
104
  type: "permit",
90
105
  args: {
@@ -93,23 +108,13 @@ const encodeVaultSharesPermit = (params) => {
93
108
  deadline,
94
109
  nonce,
95
110
  },
111
+ typedData,
96
112
  };
97
113
  return {
98
114
  action,
99
115
  async sign(client, userAddress) {
100
116
  // The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
101
117
  (0, validate_js_1.validateUserAddress)(userAddress, owner);
102
- const permit = {
103
- owner,
104
- spender,
105
- allowance: amount,
106
- nonce,
107
- deadline,
108
- };
109
- const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
110
- ...permit,
111
- erc20: vault,
112
- }, chainId);
113
118
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
114
119
  client,
115
120
  userAddress,
@@ -95,6 +95,7 @@ const getGeneralAdapterRequirements = async (viemClient, params) => {
95
95
  // the pulled amount leaves no residual direct allowance after inclusion.
96
96
  return (0, getGeneralAdapterRequirementsPermit_js_1.getGeneralAdapterRequirementsPermit)(viemClient, {
97
97
  token: address,
98
+ owner: from,
98
99
  chainId,
99
100
  args: { amount },
100
101
  nonce: erc2612Nonce,
@@ -5,9 +5,10 @@ import type { Address, Client } from "viem";
5
5
  *
6
6
  * @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
7
7
  * @param params.token - ERC-20 token address (must support EIP-2612).
8
+ * @param params.owner - Account that owns the tokens and signs the permit.
8
9
  * @param params.chainId - The chain the bundle targets.
9
10
  * @param params.args.amount - Required token amount.
10
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
11
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
11
12
  * @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
12
13
  * @returns A single-element array containing the exact-amount `Requirement` to sign.
13
14
  * @example
@@ -19,6 +20,7 @@ import type { Address, Client } from "viem";
19
20
  * const client = createWalletClient({ chain: mainnet, transport: http() });
20
21
  * const reqs = await getGeneralAdapterRequirementsPermit(client, {
21
22
  * token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
23
+ * owner,
22
24
  * chainId: 1,
23
25
  * args: { amount: 1_000_000n },
24
26
  * nonce: 0n,
@@ -28,6 +30,7 @@ import type { Address, Client } from "viem";
28
30
  */
29
31
  export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, params: {
30
32
  token: Address;
33
+ owner: Address;
31
34
  chainId: number;
32
35
  args: {
33
36
  amount: bigint;
@@ -9,9 +9,10 @@ const index_js_1 = require("../encode/index.js");
9
9
  *
10
10
  * @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
11
11
  * @param params.token - ERC-20 token address (must support EIP-2612).
12
+ * @param params.owner - Account that owns the tokens and signs the permit.
12
13
  * @param params.chainId - The chain the bundle targets.
13
14
  * @param params.args.amount - Required token amount.
14
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
15
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
15
16
  * @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
16
17
  * @returns A single-element array containing the exact-amount `Requirement` to sign.
17
18
  * @example
@@ -23,6 +24,7 @@ const index_js_1 = require("../encode/index.js");
23
24
  * const client = createWalletClient({ chain: mainnet, transport: http() });
24
25
  * const reqs = await getGeneralAdapterRequirementsPermit(client, {
25
26
  * token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
27
+ * owner,
26
28
  * chainId: 1,
27
29
  * args: { amount: 1_000_000n },
28
30
  * nonce: 0n,
@@ -31,7 +33,7 @@ const index_js_1 = require("../encode/index.js");
31
33
  * ```
32
34
  */
33
35
  const getGeneralAdapterRequirementsPermit = async (viemClient, params) => {
34
- const { token, chainId, args: { amount }, nonce, supportDeployless, } = params;
36
+ const { token, owner, chainId, args: { amount }, nonce, supportDeployless, } = params;
35
37
  const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
36
38
  // Existing direct ERC-20 allowance is intentionally not an input here. ERC-2612 overwrites the
37
39
  // allowance with the signed amount, and the bundle spends exactly `amount`, leaving no residual
@@ -39,6 +41,7 @@ const getGeneralAdapterRequirementsPermit = async (viemClient, params) => {
39
41
  return [
40
42
  await (0, index_js_1.encodeErc20Permit)(viemClient, {
41
43
  token,
44
+ owner,
42
45
  spender: generalAdapter1,
43
46
  amount,
44
47
  chainId,
@@ -17,6 +17,10 @@ export interface GetVaultExitBundlesV1PermitStructParams {
17
17
  readonly vault: Address;
18
18
  /** Bundle deadline used by the empty-permit sentinel. */
19
19
  readonly deadline: bigint;
20
+ /** Optional expected owner of the signed permit. */
21
+ readonly owner?: Address;
22
+ /** Optional expected spender of the signed permit. */
23
+ readonly spender?: Address;
20
24
  /** Optional signed bounded ERC-2612 requirement. */
21
25
  readonly requirementSignature?: PermitRequirementSignature;
22
26
  }
@@ -25,6 +29,8 @@ export interface GetVaultExitBundlesV1PermitStructParams {
25
29
  *
26
30
  * @param params.vault - Vault share token authorized by the permit.
27
31
  * @param params.deadline - Bundle deadline used by the empty-permit sentinel.
32
+ * @param params.owner - Optional expected owner of the signed permit.
33
+ * @param params.spender - Optional expected spender of the signed permit.
28
34
  * @param params.requirementSignature - Optional signed ERC-2612 vault-share requirement.
29
35
  * @returns The shared bundles share-permit tuple.
30
36
  * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement is incompatible.
@@ -8,6 +8,8 @@ const common_js_1 = require("../bundles/common.js");
8
8
  *
9
9
  * @param params.vault - Vault share token authorized by the permit.
10
10
  * @param params.deadline - Bundle deadline used by the empty-permit sentinel.
11
+ * @param params.owner - Optional expected owner of the signed permit.
12
+ * @param params.spender - Optional expected spender of the signed permit.
11
13
  * @param params.requirementSignature - Optional signed ERC-2612 vault-share requirement.
12
14
  * @returns The shared bundles share-permit tuple.
13
15
  * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement is incompatible.
@@ -36,6 +36,7 @@ export interface VaultV1InKindRedeemParams {
36
36
  * @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
37
37
  * `data`, and the typed action discriminator.
38
38
  * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
39
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
39
40
  * @throws {EmptyMarketParamsListError} when no markets are supplied.
40
41
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
41
42
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -5,6 +5,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const viem_1 = require("viem");
6
6
  const abis_js_1 = require("../../abis.js");
7
7
  const index_js_1 = require("../../helpers/index.js");
8
+ const validate_js_1 = require("../../helpers/validate.js");
8
9
  const index_js_2 = require("../../types/index.js");
9
10
  const getVaultExitBundlesV1PermitStruct_js_1 = require("../signatures/getVaultExitBundlesV1PermitStruct.js");
10
11
  /**
@@ -27,6 +28,7 @@ const getVaultExitBundlesV1PermitStruct_js_1 = require("../signatures/getVaultEx
27
28
  * @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
28
29
  * `data`, and the typed action discriminator.
29
30
  * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
31
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
30
32
  * @throws {EmptyMarketParamsListError} when no markets are supplied.
31
33
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
32
34
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -45,8 +47,7 @@ const getVaultExitBundlesV1PermitStruct_js_1 = require("../signatures/getVaultEx
45
47
  const vaultV1InKindRedeem = ({ vault, args, metadata, }) => {
46
48
  if (args.amount <= 0n)
47
49
  throw new index_js_2.NonPositiveInputError("amount", args.amount);
48
- if (args.deadline <= 0n)
49
- throw new index_js_2.NonPositiveInputError("deadline", args.deadline);
50
+ (0, validate_js_1.validateDeadline)(args.deadline);
50
51
  if (args.marketParamsList.length === 0)
51
52
  throw new index_js_2.EmptyMarketParamsListError();
52
53
  const to = (0, morpho_ts_1.getChainAddress)(vault.chainId, "bundles.vaultExitBundlesV1");
@@ -1,58 +1,77 @@
1
1
  import { type Address } from "viem";
2
- import { type Deallocation, type Metadata, type Transaction, type VaultV2ForceWithdrawAction } from "../../types/index.js";
2
+ import { type Metadata, type PermitRequirementSignature, type Transaction, type VaultV2ForceWithdrawAction } from "../../types/index.js";
3
3
  /** Parameters for {@link vaultV2ForceWithdraw}. */
4
4
  export interface VaultV2ForceWithdrawParams {
5
- vault: {
6
- address: Address;
5
+ readonly vault: {
6
+ readonly chainId: number;
7
+ readonly address: Address;
7
8
  };
8
- args: {
9
- deallocations: readonly Deallocation[];
10
- withdraw: {
11
- amount: bigint;
12
- recipient: Address;
13
- };
14
- onBehalf: Address;
9
+ readonly args: {
10
+ readonly adapter: Address;
11
+ readonly exitAssets: bigint;
12
+ readonly minSharePriceE27: bigint;
13
+ readonly userAddress: Address;
14
+ readonly deadline: bigint;
15
+ readonly referralFeePct?: bigint;
16
+ readonly referralFeeRecipient?: Address;
17
+ readonly requirementSignature?: PermitRequirementSignature;
15
18
  };
16
- metadata?: Metadata;
19
+ readonly metadata?: Metadata;
17
20
  }
18
21
  /**
19
- * Prepares a force-withdraw transaction for a VaultV2 contract via the vault's native `multicall`.
22
+ * Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
20
23
  *
21
- * Encodes one or more `forceDeallocate` calls followed by a single `withdraw`, executed
22
- * atomically through VaultV2's `multicall`. Frees liquidity from non-liquidity adapters and
23
- * withdraws the resulting assets in one transaction.
24
+ * The contract first withdraws everything the vault can pay without a penalty — its idle assets
25
+ * plus the liquidity available through its liquidity adapter — then force-deallocates the remainder
26
+ * by looping over the adapter's markets.
24
27
  *
25
- * A penalty is taken from `onBehalf` for each deallocation to discourage allocation
26
- * manipulation. The penalty is applied as a share burn where assets are returned to the vault,
27
- * so the share price stays stable (except for rounding).
28
+ * `exitAssets` is **penalty-inclusive**: it is what the contract debits from the user's position,
29
+ * while the assets actually delivered are
30
+ * `assetsToWithdraw + floor((exitAssets - assetsToWithdraw) * WAD / (WAD + penalty))` minus the
31
+ * referral fee. Use `previewVaultV2ForceWithdraw` to quote the split.
28
32
  *
29
- * @param params.vault.address - The VaultV2 address.
30
- * @param params.args.deallocations - The deallocations to perform before withdrawing. Must be
31
- * non-empty.
32
- * @param params.args.withdraw.amount - Amount of underlying assets to withdraw after the
33
- * deallocations complete.
34
- * @param params.args.withdraw.recipient - Address that receives the withdrawn assets.
35
- * @param params.args.onBehalf - Address whose shares are burned and from which the deallocation
36
- * penalty is taken.
37
- * @param params.metadata - Optional analytics metadata attached to the multicall transaction.
38
- * @returns A deep-frozen `Transaction<VaultV2ForceWithdrawAction>` with `to`, `value`, `data`,
39
- * and the typed `action` discriminator the simulation layer consumes.
40
- * @throws {EmptyDeallocationsError} when `deallocations` is empty.
41
- * @throws {NonPositiveInputError} when `withdraw.amount <= 0n`, or when any
42
- * `deallocations[i].amount <= 0n` (raised by `encodeForceDeallocateCall`).
33
+ * Without a signature this embeds the empty-permit sentinel and requires a sufficient vault-share
34
+ * approval to VaultExitBundlesV1.
35
+ *
36
+ * @param params - Force withdrawal parameters.
37
+ * @param params.vault.chainId - Chain containing the target Vault V2 and VaultExitBundlesV1.
38
+ * @param params.vault.address - Target Vault V2 address.
39
+ * @param params.args.adapter - Vault's sole MorphoMarketV1AdapterV2.
40
+ * @param params.args.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
41
+ * @param params.args.minSharePriceE27 - RAY-scaled lower bound on the realized exit share price
42
+ * (withdrawn assets per share burned). `0n` disables the on-chain bound; prefer the value the
43
+ * entity computes.
44
+ * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
45
+ * VaultExitBundlesV1 burns `msg.sender`'s vault shares and pays out to `msg.sender`, so the
46
+ * submitting account must equal this address.
47
+ * @param params.args.deadline - Permit and bundle deadline.
48
+ * @param params.args.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
49
+ * `referralFeeRecipient`. Defaults to `0n`. Deducted *after* the `minSharePriceE27` check, so it
50
+ * is outside that bound's protection.
51
+ * @param params.args.referralFeeRecipient - Optional referral fee recipient. Defaults to the zero
52
+ * address, which is only valid alongside a zero `referralFeePct`.
53
+ * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
54
+ * @param params.metadata - Optional analytics metadata.
55
+ * @returns A deep-frozen `Readonly<Transaction<VaultV2ForceWithdrawAction>>` with `to`, `value`,
56
+ * `data`, and the typed action discriminator.
57
+ * @throws {NonPositiveInputError} when `exitAssets` or `deadline` is not positive.
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`.
61
+ * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
62
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
63
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
64
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind,
65
+ * asset, owner, spender, or signature encoding.
43
66
  * @example
44
67
  * ```ts
45
68
  * import { vaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
46
69
  *
47
70
  * const tx = vaultV2ForceWithdraw({
48
- * vault: { address: vaultAddress },
49
- * args: {
50
- * deallocations: [{ adapter, marketParams, amount: 500_000n }],
51
- * withdraw: { amount: 500_000n, recipient },
52
- * onBehalf,
53
- * },
71
+ * vault: { chainId: 1, address: vault },
72
+ * args: { adapter, exitAssets: 1_000_000n, minSharePriceE27, userAddress, deadline },
54
73
  * });
55
74
  * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
56
75
  * ```
57
76
  */
58
- export declare const vaultV2ForceWithdraw: ({ vault: { address: vaultAddress }, args: { deallocations, withdraw, onBehalf }, metadata, }: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
77
+ export declare const vaultV2ForceWithdraw: ({ vault, args, metadata, }: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;