@morpho-org/morpho-sdk 8.2.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/MIGRATION-v8-to-v9.md +54 -0
  2. package/README.md +14 -8
  3. package/lib/cjs/actions/bundles/common.d.ts +4 -7
  4. package/lib/cjs/actions/bundles/common.js +8 -14
  5. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -8
  7. package/lib/cjs/actions/midnight/authorization.d.ts +3 -1
  8. package/lib/cjs/actions/midnight/authorization.js +11 -1
  9. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -0
  10. package/lib/cjs/actions/midnight/cancelAndMake.js +10 -2
  11. package/lib/cjs/actions/midnight/redeem.d.ts +4 -1
  12. package/lib/cjs/actions/midnight/redeem.js +13 -3
  13. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
  14. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +7 -3
  15. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +5 -1
  16. package/lib/cjs/actions/midnight/supplyCollateral.js +14 -3
  17. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
  18. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +9 -3
  19. package/lib/cjs/actions/midnight/takeBorrow.d.ts +3 -1
  20. package/lib/cjs/actions/midnight/takeBorrow.js +9 -3
  21. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  22. package/lib/cjs/actions/midnight/takeLend.js +7 -2
  23. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  24. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +8 -2
  25. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +3 -1
  26. package/lib/cjs/actions/midnight/takeWithdraw.js +10 -3
  27. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
  28. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +5 -7
  29. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +7 -11
  30. package/lib/cjs/actions/requirements/getRequirementsApproval.js +8 -15
  31. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
  32. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +11 -8
  33. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
  34. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
  35. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -1
  36. package/lib/cjs/actions/vaultV1/inKindRedeem.js +1 -1
  37. package/lib/cjs/actions/vaultV1/withdraw.d.ts +4 -4
  38. package/lib/cjs/actions/vaultV1/withdraw.js +4 -4
  39. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
  40. package/lib/cjs/actions/vaultV2/forceWithdraw.js +1 -1
  41. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -1
  42. package/lib/cjs/actions/vaultV2/inKindRedeem.js +1 -1
  43. package/lib/cjs/actions/vaultV2/withdraw.d.ts +4 -4
  44. package/lib/cjs/actions/vaultV2/withdraw.js +4 -4
  45. package/lib/cjs/entities/blue/blue.d.ts +2 -12
  46. package/lib/cjs/entities/blue/blue.js +0 -4
  47. package/lib/cjs/entities/midnight/midnight.d.ts +58 -17
  48. package/lib/cjs/entities/midnight/midnight.js +133 -52
  49. package/lib/cjs/entities/midnight/types.d.ts +2 -9
  50. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
  51. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +0 -7
  52. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
  53. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -20
  54. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +40 -37
  55. package/lib/cjs/entities/vaultV1/vaultV1.js +5 -34
  56. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +36 -34
  57. package/lib/cjs/entities/vaultV2/vaultV2.js +8 -34
  58. package/lib/cjs/helpers/encodeMidnightCalldata.d.ts +48 -0
  59. package/lib/cjs/helpers/encodeMidnightCalldata.js +74 -0
  60. package/lib/cjs/helpers/slippage.d.ts +9 -25
  61. package/lib/cjs/helpers/slippage.js +10 -27
  62. package/lib/cjs/helpers/validate.d.ts +1 -0
  63. package/lib/cjs/helpers/validate.js +5 -0
  64. package/lib/cjs/helpers/validateMidnightAccount.d.ts +34 -0
  65. package/lib/cjs/helpers/validateMidnightAccount.js +47 -0
  66. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
  67. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +4 -0
  68. package/lib/cjs/helpers/validateMidnightMarket.d.ts +2 -0
  69. package/lib/cjs/helpers/validateMidnightMarket.js +5 -0
  70. package/lib/cjs/helpers/validateMidnightPublication.d.ts +11 -0
  71. package/lib/cjs/helpers/validateMidnightPublication.js +12 -1
  72. package/lib/cjs/helpers/validateMidnightReceiver.d.ts +1 -0
  73. package/lib/cjs/helpers/validateMidnightReceiver.js +8 -0
  74. package/lib/cjs/helpers/validateTakeableOffers.d.ts +2 -1
  75. package/lib/cjs/helpers/validateTakeableOffers.js +4 -3
  76. package/lib/cjs/types/action.d.ts +3 -1
  77. package/lib/cjs/types/error.d.ts +64 -5
  78. package/lib/cjs/types/error.js +152 -10
  79. package/lib/esm/actions/bundles/common.d.ts +4 -7
  80. package/lib/esm/actions/bundles/common.js +8 -14
  81. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
  82. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -9
  83. package/lib/esm/actions/midnight/authorization.d.ts +3 -1
  84. package/lib/esm/actions/midnight/authorization.js +12 -2
  85. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -0
  86. package/lib/esm/actions/midnight/cancelAndMake.js +11 -3
  87. package/lib/esm/actions/midnight/redeem.d.ts +4 -1
  88. package/lib/esm/actions/midnight/redeem.js +15 -5
  89. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
  90. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +8 -4
  91. package/lib/esm/actions/midnight/supplyCollateral.d.ts +5 -1
  92. package/lib/esm/actions/midnight/supplyCollateral.js +16 -5
  93. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
  94. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +10 -4
  95. package/lib/esm/actions/midnight/takeBorrow.d.ts +3 -1
  96. package/lib/esm/actions/midnight/takeBorrow.js +10 -4
  97. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  98. package/lib/esm/actions/midnight/takeLend.js +8 -3
  99. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  100. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +9 -3
  101. package/lib/esm/actions/midnight/takeWithdraw.d.ts +3 -1
  102. package/lib/esm/actions/midnight/takeWithdraw.js +11 -4
  103. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
  104. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -8
  105. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +7 -11
  106. package/lib/esm/actions/requirements/getRequirementsApproval.js +9 -16
  107. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
  108. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +12 -9
  109. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
  110. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
  111. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -1
  112. package/lib/esm/actions/vaultV1/inKindRedeem.js +1 -1
  113. package/lib/esm/actions/vaultV1/withdraw.d.ts +4 -4
  114. package/lib/esm/actions/vaultV1/withdraw.js +4 -4
  115. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  116. package/lib/esm/actions/vaultV2/forceWithdraw.js +1 -1
  117. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -1
  118. package/lib/esm/actions/vaultV2/inKindRedeem.js +1 -1
  119. package/lib/esm/actions/vaultV2/withdraw.d.ts +4 -4
  120. package/lib/esm/actions/vaultV2/withdraw.js +4 -4
  121. package/lib/esm/entities/blue/blue.d.ts +2 -12
  122. package/lib/esm/entities/blue/blue.js +0 -4
  123. package/lib/esm/entities/midnight/midnight.d.ts +58 -17
  124. package/lib/esm/entities/midnight/midnight.js +134 -53
  125. package/lib/esm/entities/midnight/types.d.ts +2 -9
  126. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
  127. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +1 -8
  128. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
  129. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +9 -21
  130. package/lib/esm/entities/vaultV1/vaultV1.d.ts +40 -37
  131. package/lib/esm/entities/vaultV1/vaultV1.js +6 -35
  132. package/lib/esm/entities/vaultV2/vaultV2.d.ts +36 -34
  133. package/lib/esm/entities/vaultV2/vaultV2.js +8 -34
  134. package/lib/esm/helpers/encodeMidnightCalldata.d.ts +48 -0
  135. package/lib/esm/helpers/encodeMidnightCalldata.js +69 -0
  136. package/lib/esm/helpers/slippage.d.ts +9 -25
  137. package/lib/esm/helpers/slippage.js +9 -25
  138. package/lib/esm/helpers/validate.d.ts +1 -0
  139. package/lib/esm/helpers/validate.js +5 -0
  140. package/lib/esm/helpers/validateMidnightAccount.d.ts +34 -0
  141. package/lib/esm/helpers/validateMidnightAccount.js +43 -0
  142. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
  143. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +4 -0
  144. package/lib/esm/helpers/validateMidnightMarket.d.ts +2 -0
  145. package/lib/esm/helpers/validateMidnightMarket.js +5 -0
  146. package/lib/esm/helpers/validateMidnightPublication.d.ts +11 -0
  147. package/lib/esm/helpers/validateMidnightPublication.js +10 -0
  148. package/lib/esm/helpers/validateMidnightReceiver.d.ts +1 -0
  149. package/lib/esm/helpers/validateMidnightReceiver.js +8 -0
  150. package/lib/esm/helpers/validateTakeableOffers.d.ts +2 -1
  151. package/lib/esm/helpers/validateTakeableOffers.js +4 -3
  152. package/lib/esm/types/action.d.ts +3 -1
  153. package/lib/esm/types/error.d.ts +64 -5
  154. package/lib/esm/types/error.js +146 -6
  155. package/package.json +6 -5
@@ -1,7 +1,8 @@
1
- import { erc20Abi, maxUint256 } from "viem";
1
+ import { erc20Abi } from "viem";
2
2
  import { readContract } from "viem/actions";
3
3
  import { validateChainId, validateRequirementSpender, } from "../../../helpers/index.js";
4
4
  import { validateUint256Field } from "../../../helpers/validate.js";
5
+ import { validateMidnightAccount, validateMidnightAddress, } from "../../../helpers/validateMidnightAccount.js";
5
6
  import { getRequirementsApproval } from "../getRequirementsApproval.js";
6
7
  import { validateClientChainId } from "../validateClientChainId.js";
7
8
  /**
@@ -14,7 +15,7 @@ import { validateClientChainId } from "../validateClientChainId.js";
14
15
  * The returned approval sets an unlimited allowance (`maxUint256`, capped per
15
16
  * token by `MAX_TOKEN_APPROVALS`) whenever the current allowance is below
16
17
  * `amount`, because all of an account's Midnight offers and bundle calls share
17
- * one allowance per token. Pass `approvalAmount` to set a different allowance.
18
+ * one allowance per token.
18
19
  *
19
20
  * @param params.viemClient - Viem client used to read ERC20 allowance.
20
21
  * @param params.chainId - Chain id expected by the viem client.
@@ -22,14 +23,14 @@ import { validateClientChainId } from "../validateClientChainId.js";
22
23
  * @param params.owner - Token owner.
23
24
  * @param params.spender - Midnight spender that will pull tokens.
24
25
  * @param params.amount - Minimum allowance the spender needs.
25
- * @param params.approvalAmount - Allowance to approve when one is needed; defaults to `maxUint256` and must be at least `amount`.
26
26
  * @returns Approval transactions required for `spender` to pull `amount`.
27
27
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
28
28
  * another chain than `params.chainId`.
29
+ * @throws {MidnightCalldataEncodingError} when `owner`, `token` or `spender` is not a well-formed address.
30
+ * @throws {MidnightZeroAccountError} when `owner` is the zero address.
29
31
  * @throws {viem.BaseError} when the `eth_chainId` request or allowance read fails.
30
- * @throws {NegativeInputError} when `amount` or `approvalAmount` is negative.
31
- * @throws {InputExceedsMaxError} when `amount` or `approvalAmount` exceeds `maxUint256`.
32
- * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < amount`.
32
+ * @throws {NegativeInputError} when `amount` is negative.
33
+ * @throws {InputExceedsMaxError} when `amount` exceeds `maxUint256`.
33
34
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundlesV2 deployment.
34
35
  * @example
35
36
  * ```ts
@@ -55,10 +56,13 @@ import { validateClientChainId } from "../validateClientChainId.js";
55
56
  * ```
56
57
  */
57
58
  export const getMidnightApprovalRequirements = async (params) => {
59
+ // Reject the zero account before reading state for it.
60
+ validateMidnightAccount("owner", params.owner);
61
+ // Reject malformed addresses typed before the spender comparison and the allowance read.
62
+ validateMidnightAddress("token", params.token);
63
+ validateMidnightAddress("spender", params.spender);
58
64
  validateChainId(params.viemClient.chain?.id, params.chainId);
59
65
  validateUint256Field("amount", params.amount);
60
- if (params.approvalAmount !== undefined)
61
- validateUint256Field("approvalAmount", params.approvalAmount);
62
66
  // Validate the target even when no approval transaction needs to be encoded.
63
67
  validateRequirementSpender({
64
68
  chainId: params.chainId,
@@ -80,7 +84,6 @@ export const getMidnightApprovalRequirements = async (params) => {
80
84
  args: {
81
85
  spender: params.spender,
82
86
  spendAmount: params.amount,
83
- approvalAmount: params.approvalAmount ?? maxUint256,
84
87
  },
85
88
  allowances: allowance,
86
89
  });
@@ -23,6 +23,8 @@ export interface GetMidnightAuthorizationRequirementParams {
23
23
  * @returns Authorization transaction, or `null` when already authorized.
24
24
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
25
25
  * another chain than `params.chainId`.
26
+ * @throws {MidnightCalldataEncodingError} when `owner` or `authorized` is not a well-formed address.
27
+ * @throws {MidnightZeroAccountError} when `owner` is the zero address.
26
28
  * @throws {viem.BaseError} when the `eth_chainId` request or authorization read fails.
27
29
  * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not MidnightBundlesV2.
28
30
  * @example
@@ -3,6 +3,7 @@ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
3
  import { encodeFunctionData } from "viem";
4
4
  import { readContract } from "viem/actions";
5
5
  import { validateChainId } from "../../../helpers/index.js";
6
+ import { validateMidnightAccount } from "../../../helpers/validateMidnightAccount.js";
6
7
  import { validateMidnightAuthorizationTarget } from "../../../helpers/validateMidnightAuthorizationTarget.js";
7
8
  import { validateClientChainId } from "../validateClientChainId.js";
8
9
  /**
@@ -21,6 +22,8 @@ import { validateClientChainId } from "../validateClientChainId.js";
21
22
  * @returns Authorization transaction, or `null` when already authorized.
22
23
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
23
24
  * another chain than `params.chainId`.
25
+ * @throws {MidnightCalldataEncodingError} when `owner` or `authorized` is not a well-formed address.
26
+ * @throws {MidnightZeroAccountError} when `owner` is the zero address.
24
27
  * @throws {viem.BaseError} when the `eth_chainId` request or authorization read fails.
25
28
  * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not MidnightBundlesV2.
26
29
  * @example
@@ -46,6 +49,8 @@ import { validateClientChainId } from "../validateClientChainId.js";
46
49
  * ```
47
50
  */
48
51
  export const getMidnightAuthorizationRequirement = async (params) => {
52
+ // Reject the zero account before reading state for it.
53
+ validateMidnightAccount("owner", params.owner);
49
54
  validateChainId(params.viemClient.chain?.id, params.chainId);
50
55
  // Reject unknown operators before reading authorization state.
51
56
  validateMidnightAuthorizationTarget({
@@ -31,7 +31,7 @@ export interface VaultV1InKindRedeemParams {
31
31
  * the expected owner of an optional `requirementSignature` permit. VaultExitBundlesV1 burns
32
32
  * `msg.sender`'s vault shares, so the submitting account must equal this address.
33
33
  * @param params.args.deadline - Permit and bundle deadline.
34
- * @param params.args.requirementSignature - Optional bounded Vault V1 shares permit.
34
+ * @param params.args.requirementSignature - Optional unlimited Vault V1 shares permit.
35
35
  * @param params.metadata - Optional analytics metadata.
36
36
  * @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
37
37
  * `data`, and the typed action discriminator.
@@ -20,7 +20,7 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
20
20
  * the expected owner of an optional `requirementSignature` permit. VaultExitBundlesV1 burns
21
21
  * `msg.sender`'s vault shares, so the submitting account must equal this address.
22
22
  * @param params.args.deadline - Permit and bundle deadline.
23
- * @param params.args.requirementSignature - Optional bounded Vault V1 shares permit.
23
+ * @param params.args.requirementSignature - Optional unlimited Vault V1 shares permit.
24
24
  * @param params.metadata - Optional analytics metadata.
25
25
  * @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
26
26
  * `data`, and the typed action discriminator.
@@ -21,8 +21,8 @@ export interface VaultV1WithdrawParams {
21
21
  /**
22
22
  * Encodes an exact-assets Vault V1 withdrawal through VaultBundlesV1.
23
23
  *
24
- * This low-level builder does not bind `permit.value` to a share cap; use
25
- * `MorphoVaultV1.withdraw().buildTx()` to validate it against the share cap derived from the handle's `vaultData`.
24
+ * This low-level builder does not bind `permit.value` to the required share amount; use
25
+ * `MorphoVaultV1.withdraw().buildTx()` to validate it against the minimum derived from the handle's `vaultData`.
26
26
  *
27
27
  * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
28
28
  * @param params.vault.address - Vault V1 whose shares are burned for the withdrawal.
@@ -31,7 +31,7 @@ export interface VaultV1WithdrawParams {
31
31
  * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
32
32
  * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
33
33
  * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
34
- * and the registered VaultBundlesV1 spender. Omit when the exact share allowance is already set.
34
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance meets the required amount.
35
35
  * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
36
36
  * The fee is rounded down and deducted from the gross withdrawn assets.
37
37
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
@@ -60,7 +60,7 @@ export interface VaultV1WithdrawParams {
60
60
  *
61
61
  * export function buildUsdcWithdrawal(userAddress: Address, deadline: bigint) {
62
62
  * const vault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
63
- * // Set the exact vault-share allowance before submitting; the entity API derives that cap.
63
+ * // Satisfy the required vault-share allowance before submitting; the entity API derives it.
64
64
  * const tx = vaultV1Withdraw({
65
65
  * vault: { chainId: mainnet.id, address: vault },
66
66
  * args: { amount: 1_000_000n, userAddress, deadline },
@@ -7,8 +7,8 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
7
7
  /**
8
8
  * Encodes an exact-assets Vault V1 withdrawal through VaultBundlesV1.
9
9
  *
10
- * This low-level builder does not bind `permit.value` to a share cap; use
11
- * `MorphoVaultV1.withdraw().buildTx()` to validate it against the share cap derived from the handle's `vaultData`.
10
+ * This low-level builder does not bind `permit.value` to the required share amount; use
11
+ * `MorphoVaultV1.withdraw().buildTx()` to validate it against the minimum derived from the handle's `vaultData`.
12
12
  *
13
13
  * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
14
14
  * @param params.vault.address - Vault V1 whose shares are burned for the withdrawal.
@@ -17,7 +17,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
17
17
  * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
18
18
  * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
19
19
  * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
20
- * and the registered VaultBundlesV1 spender. Omit when the exact share allowance is already set.
20
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance meets the required amount.
21
21
  * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
22
22
  * The fee is rounded down and deducted from the gross withdrawn assets.
23
23
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
@@ -46,7 +46,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
46
46
  *
47
47
  * export function buildUsdcWithdrawal(userAddress: Address, deadline: bigint) {
48
48
  * const vault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
49
- * // Set the exact vault-share allowance before submitting; the entity API derives that cap.
49
+ * // Satisfy the required vault-share allowance before submitting; the entity API derives it.
50
50
  * const tx = vaultV1Withdraw({
51
51
  * vault: { chainId: mainnet.id, address: vault },
52
52
  * args: { amount: 1_000_000n, userAddress, deadline },
@@ -50,7 +50,7 @@ export interface VaultV2ForceWithdrawParams {
50
50
  * is outside that bound's protection.
51
51
  * @param params.args.referralFeeRecipient - Optional referral fee recipient. Defaults to the zero
52
52
  * address, which is only valid alongside a zero `referralFeePct`.
53
- * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
53
+ * @param params.args.requirementSignature - Optional unlimited Vault V2 shares permit.
54
54
  * @param params.metadata - Optional analytics metadata.
55
55
  * @returns A deep-frozen `Readonly<Transaction<VaultV2ForceWithdrawAction>>` with `to`, `value`,
56
56
  * `data`, and the typed action discriminator.
@@ -37,7 +37,7 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
37
37
  * is outside that bound's protection.
38
38
  * @param params.args.referralFeeRecipient - Optional referral fee recipient. Defaults to the zero
39
39
  * address, which is only valid alongside a zero `referralFeePct`.
40
- * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
40
+ * @param params.args.requirementSignature - Optional unlimited Vault V2 shares permit.
41
41
  * @param params.metadata - Optional analytics metadata.
42
42
  * @returns A deep-frozen `Readonly<Transaction<VaultV2ForceWithdrawAction>>` with `to`, `value`,
43
43
  * `data`, and the typed action discriminator.
@@ -34,7 +34,7 @@ export interface VaultV2InKindRedeemParams {
34
34
  * the expected owner of an optional `requirementSignature` permit. VaultExitBundlesV1 burns
35
35
  * `msg.sender`'s vault shares, so the submitting account must equal this address.
36
36
  * @param params.args.deadline - Permit and bundle deadline.
37
- * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
37
+ * @param params.args.requirementSignature - Optional unlimited Vault V2 shares permit.
38
38
  * @param params.metadata - Optional analytics metadata.
39
39
  * @returns A deep-frozen `Readonly<Transaction<VaultV2InKindRedeemAction>>` with `to`, `value`,
40
40
  * `data`, and the typed action discriminator.
@@ -22,7 +22,7 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
22
22
  * the expected owner of an optional `requirementSignature` permit. VaultExitBundlesV1 burns
23
23
  * `msg.sender`'s vault shares, so the submitting account must equal this address.
24
24
  * @param params.args.deadline - Permit and bundle deadline.
25
- * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
25
+ * @param params.args.requirementSignature - Optional unlimited Vault V2 shares permit.
26
26
  * @param params.metadata - Optional analytics metadata.
27
27
  * @returns A deep-frozen `Readonly<Transaction<VaultV2InKindRedeemAction>>` with `to`, `value`,
28
28
  * `data`, and the typed action discriminator.
@@ -21,8 +21,8 @@ export interface VaultV2WithdrawParams {
21
21
  /**
22
22
  * Encodes an exact-assets Vault V2 withdrawal through VaultBundlesV1.
23
23
  *
24
- * This low-level builder does not bind `permit.value` to a share cap; use
25
- * `MorphoVaultV2.withdraw().buildTx()` to validate it against the share cap derived from the handle's `vaultData`.
24
+ * This low-level builder does not bind `permit.value` to the required share amount; use
25
+ * `MorphoVaultV2.withdraw().buildTx()` to validate it against the minimum derived from the handle's `vaultData`.
26
26
  *
27
27
  * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
28
28
  * @param params.vault.address - Vault V2 whose shares are burned for the withdrawal.
@@ -31,7 +31,7 @@ export interface VaultV2WithdrawParams {
31
31
  * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
32
32
  * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
33
33
  * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
34
- * and the registered VaultBundlesV1 spender. Omit when the exact share allowance is already set.
34
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance meets the required amount.
35
35
  * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
36
36
  * The fee is rounded down and deducted from the gross withdrawn assets.
37
37
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
@@ -60,7 +60,7 @@ export interface VaultV2WithdrawParams {
60
60
  *
61
61
  * export function buildUsdcWithdrawal(userAddress: Address, deadline: bigint) {
62
62
  * const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
63
- * // Set the exact vault-share allowance before submitting; the entity API derives that cap.
63
+ * // Satisfy the required vault-share allowance before submitting; the entity API derives it.
64
64
  * const tx = vaultV2Withdraw({
65
65
  * vault: { chainId: mainnet.id, address: vault },
66
66
  * args: { amount: 1_000_000n, userAddress, deadline },
@@ -7,8 +7,8 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
7
7
  /**
8
8
  * Encodes an exact-assets Vault V2 withdrawal through VaultBundlesV1.
9
9
  *
10
- * This low-level builder does not bind `permit.value` to a share cap; use
11
- * `MorphoVaultV2.withdraw().buildTx()` to validate it against the share cap derived from the handle's `vaultData`.
10
+ * This low-level builder does not bind `permit.value` to the required share amount; use
11
+ * `MorphoVaultV2.withdraw().buildTx()` to validate it against the minimum derived from the handle's `vaultData`.
12
12
  *
13
13
  * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
14
14
  * @param params.vault.address - Vault V2 whose shares are burned for the withdrawal.
@@ -17,7 +17,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
17
17
  * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
18
18
  * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
19
19
  * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
20
- * and the registered VaultBundlesV1 spender. Omit when the exact share allowance is already set.
20
+ * and the registered VaultBundlesV1 spender. Omit when the share allowance meets the required amount.
21
21
  * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
22
22
  * The fee is rounded down and deducted from the gross withdrawn assets.
23
23
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
@@ -46,7 +46,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
46
46
  *
47
47
  * export function buildUsdcWithdrawal(userAddress: Address, deadline: bigint) {
48
48
  * const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
49
- * // Set the exact vault-share allowance before submitting; the entity API derives that cap.
49
+ * // Satisfy the required vault-share allowance before submitting; the entity API derives it.
50
50
  * const tx = vaultV2Withdraw({
51
51
  * vault: { chainId: mainnet.id, address: vault },
52
52
  * args: { amount: 1_000_000n, userAddress, deadline },
@@ -18,11 +18,6 @@ export interface BlueTokenRequirementsParams {
18
18
  readonly useSimplePermit?: boolean;
19
19
  /** Explicit unused Permit2 SignatureTransfer unordered nonce; defaults to the lowest unused nonce. */
20
20
  readonly permit2Nonce?: bigint;
21
- /**
22
- * Classic ERC-20 allowance to set when an approval is needed, enabling a reusable approval (for
23
- * example `maxUint256`). Defaults to the exact pulled amount. Ignored by signature paths.
24
- */
25
- readonly approvalAmount?: bigint;
26
21
  }
27
22
  /** Action surface for Morpho Blue reads and writes; writes route through BlueBundlesV1. */
28
23
  export interface BlueActions {
@@ -169,7 +164,6 @@ export interface BlueActions {
169
164
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
170
165
  * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
171
166
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
172
- * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when a classic `approvalAmount` is below the funded `assets`.
173
167
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
174
168
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when the route cannot consume a supplied signature.
175
169
  * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
@@ -405,8 +399,6 @@ export interface BlueActions {
405
399
  * @throws {RepayExceedsDebtError} when an exact asset repay exceeds current debt.
406
400
  * @throws {RepaySharesExceedDebtError} when non-saturated shares exceed current debt shares.
407
401
  * @throws {InputExceedsMaxError} when a fee is out of bounds or a share quote deadline is too far away.
408
- * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when a classic
409
- * `approvalAmount` is below the derived `maxRepayAssets`.
410
402
  * @throws {MaxRepayAssetsBelowRepayAssetsError} when a signed share cap no longer covers the fresh quote.
411
403
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
412
404
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
@@ -550,8 +542,8 @@ export interface BlueActions {
550
542
  * saturated full close; the entity derives `maxRepayAssets` from debt projected through the
551
543
  * requested deadline plus the referral fee, and the contract refunds unused funding. A
552
544
  * previously signed share-mode cap remains valid when it still covers the fresh derived minimum.
553
- * Full-repay requirements fund exactly the derived `maxRepayAssets`; pass `approvalAmount` to
554
- * request a reusable allowance instead. The transaction remains bounded by the derived cap.
545
+ * Full-repay requirements use unlimited classic approvals while the transaction remains bounded
546
+ * by the derived `maxRepayAssets` cap.
555
547
  * Share-mode deadlines cannot exceed the two-hour quote horizon. Blue authorization is required
556
548
  * only for collateral withdrawal. Pure repay uses `maxLtv = maxUint256`; withdrawals use buffered
557
549
  * LLTV. No share-price or `slippageTolerance` input exists.
@@ -582,8 +574,6 @@ export interface BlueActions {
582
574
  * @throws {WithdrawMakesPositionUnhealthyError} when the post-repay withdrawal exceeds buffered LLTV.
583
575
  * @throws {ExpiredDeadlineError} when the deadline is stale.
584
576
  * @throws {InputExceedsMaxError} when the referral fee is at least WAD or a share-mode deadline exceeds the funding quote horizon.
585
- * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when a classic
586
- * `approvalAmount` is below the derived `maxRepayAssets`.
587
577
  * @throws {MaxRepayAssetsBelowRepayAssetsError} from `buildTx()` when a previously signed share-mode cap no longer covers the fresh derived minimum.
588
578
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
589
579
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
@@ -84,7 +84,6 @@ export class MorphoBlue {
84
84
  supportDeployless: this.client.options.supportDeployless,
85
85
  useSimplePermit: params.useSimplePermit,
86
86
  permit2Nonce: params.permit2Nonce,
87
- approvalAmount: params.approvalAmount,
88
87
  now: params.now,
89
88
  });
90
89
  }
@@ -144,7 +143,6 @@ export class MorphoBlue {
144
143
  now,
145
144
  useSimplePermit: requirementsParams?.useSimplePermit,
146
145
  permit2Nonce: requirementsParams?.permit2Nonce,
147
- approvalAmount: requirementsParams?.approvalAmount,
148
146
  });
149
147
  });
150
148
  },
@@ -482,7 +480,6 @@ export class MorphoBlue {
482
480
  ? this.getTokenRequirements({
483
481
  token: this.marketParams.loanToken,
484
482
  amount: maxRepayAssets,
485
- approvalAmount: requirementsParams?.approvalAmount,
486
483
  userAddress,
487
484
  deadline,
488
485
  now,
@@ -594,7 +591,6 @@ export class MorphoBlue {
594
591
  ? this.getTokenRequirements({
595
592
  token: this.marketParams.collateralToken,
596
593
  amount: collateralAssets,
597
- approvalAmount: requirementsParams?.approvalAmount,
598
594
  userAddress,
599
595
  deadline,
600
596
  now,