@morpho-org/morpho-sdk 6.6.0 → 7.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 (153) hide show
  1. package/MIGRATION-v6-to-v7.md +291 -0
  2. package/README.md +26 -12
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +3 -2
  5. package/lib/cjs/actions/bundles/common.d.ts +9 -5
  6. package/lib/cjs/actions/bundles/common.js +22 -13
  7. package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
  8. package/lib/cjs/actions/midnight/authorization.js +3 -2
  9. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
  10. package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +3 -3
  12. package/lib/cjs/actions/midnight/index.js +3 -3
  13. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  14. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
  18. package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
  20. package/lib/cjs/actions/midnight/takeLend.js +111 -54
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
  25. package/lib/cjs/actions/midnight/types.d.ts +7 -26
  26. package/lib/cjs/actions/midnight/types.js +0 -13
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
  32. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  33. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
  35. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  37. package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
  38. package/lib/cjs/actions/requirements/midnight/index.js +0 -1
  39. package/lib/cjs/constants.d.ts +1 -1
  40. package/lib/cjs/constants.js +2 -1
  41. package/lib/cjs/entities/index.d.ts +2 -2
  42. package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
  43. package/lib/cjs/entities/midnight/midnight.js +981 -509
  44. package/lib/cjs/entities/midnight/types.d.ts +142 -60
  45. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
  46. package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
  47. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
  48. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
  49. package/lib/cjs/helpers/callback.d.ts +54 -0
  50. package/lib/cjs/helpers/callback.js +73 -0
  51. package/lib/cjs/helpers/constant.d.ts +2 -0
  52. package/lib/cjs/helpers/constant.js +3 -1
  53. package/lib/cjs/helpers/index.d.ts +3 -2
  54. package/lib/cjs/helpers/index.js +6 -1
  55. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
  56. package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
  57. package/lib/cjs/helpers/validate.d.ts +43 -2
  58. package/lib/cjs/helpers/validate.js +60 -3
  59. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  60. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
  61. package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
  62. package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
  63. package/lib/cjs/midnight/abis.d.ts +1 -1
  64. package/lib/cjs/midnight/abis.js +3 -2
  65. package/lib/cjs/midnight/types.d.ts +1 -1
  66. package/lib/cjs/types/action.d.ts +117 -89
  67. package/lib/cjs/types/action.js +1 -19
  68. package/lib/cjs/types/error.d.ts +126 -40
  69. package/lib/cjs/types/error.js +154 -49
  70. package/lib/esm/abis.d.ts +1 -1
  71. package/lib/esm/abis.js +1 -1
  72. package/lib/esm/actions/bundles/common.d.ts +9 -5
  73. package/lib/esm/actions/bundles/common.js +22 -13
  74. package/lib/esm/actions/midnight/authorization.d.ts +3 -2
  75. package/lib/esm/actions/midnight/authorization.js +3 -2
  76. package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
  77. package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
  78. package/lib/esm/actions/midnight/index.d.ts +3 -3
  79. package/lib/esm/actions/midnight/index.js +3 -3
  80. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  81. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
  82. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  83. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
  84. package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
  85. package/lib/esm/actions/midnight/takeBorrow.js +98 -57
  86. package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
  87. package/lib/esm/actions/midnight/takeLend.js +114 -57
  88. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  89. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
  90. package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
  91. package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
  92. package/lib/esm/actions/midnight/types.d.ts +7 -26
  93. package/lib/esm/actions/midnight/types.js +1 -12
  94. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  95. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  96. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  97. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
  98. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
  99. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
  100. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  101. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
  102. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  103. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  104. package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
  105. package/lib/esm/actions/requirements/midnight/index.js +0 -1
  106. package/lib/esm/constants.d.ts +1 -1
  107. package/lib/esm/constants.js +1 -1
  108. package/lib/esm/entities/index.d.ts +2 -2
  109. package/lib/esm/entities/midnight/midnight.d.ts +582 -108
  110. package/lib/esm/entities/midnight/midnight.js +987 -515
  111. package/lib/esm/entities/midnight/types.d.ts +142 -60
  112. package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
  113. package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
  114. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
  115. package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
  116. package/lib/esm/helpers/callback.d.ts +54 -0
  117. package/lib/esm/helpers/callback.js +68 -0
  118. package/lib/esm/helpers/constant.d.ts +2 -0
  119. package/lib/esm/helpers/constant.js +2 -0
  120. package/lib/esm/helpers/index.d.ts +3 -2
  121. package/lib/esm/helpers/index.js +3 -2
  122. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
  123. package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
  124. package/lib/esm/helpers/validate.d.ts +43 -2
  125. package/lib/esm/helpers/validate.js +58 -2
  126. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  127. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
  128. package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
  129. package/lib/esm/helpers/validateRequirementSpender.js +4 -5
  130. package/lib/esm/midnight/abis.d.ts +1 -1
  131. package/lib/esm/midnight/abis.js +1 -1
  132. package/lib/esm/midnight/types.d.ts +1 -1
  133. package/lib/esm/types/action.d.ts +117 -89
  134. package/lib/esm/types/action.js +1 -18
  135. package/lib/esm/types/error.d.ts +126 -40
  136. package/lib/esm/types/error.js +135 -38
  137. package/package.json +8 -7
  138. package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
  139. package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
  140. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  141. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
  142. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  143. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
  144. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  145. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
  146. package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
  147. package/lib/esm/actions/midnight/cancelOffer.js +0 -69
  148. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  149. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
  150. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  151. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
  152. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  153. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
@@ -21,8 +21,8 @@ const index_js_1 = require("../../../types/index.js");
21
21
  * @param params - Permit encoding parameters.
22
22
  * @param params.token - ERC-20 token address (must support EIP-2612).
23
23
  * @param params.owner - Account that owns the tokens and signs the permit.
24
- * @param params.spender - Permit spender. Must be MidnightBundles, VaultBundlesV1, or
25
- * BlueBundlesV1 for the chain.
24
+ * @param params.spender - Permit spender. Must be VaultBundlesV1 or BlueBundlesV1 for the
25
+ * chain.
26
26
  * @param params.amount - Permit allowance amount.
27
27
  * @param params.chainId - Target chain id.
28
28
  * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
@@ -32,8 +32,8 @@ const index_js_1 = require("../../../types/index.js");
32
32
  * `sign(client, userAddress)` produces the deep-frozen signature.
33
33
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
34
34
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
35
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not MidnightBundles,
36
- * VaultBundlesV1, or BlueBundlesV1 for `chainId`.
35
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not VaultBundlesV1 or
36
+ * BlueBundlesV1 for `chainId`.
37
37
  * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
38
38
  * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
39
39
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
@@ -70,7 +70,7 @@ const encodeErc20Permit = async (viemClient, params) => {
70
70
  (0, validateRequirementSpender_js_1.validateRequirementSpender)({
71
71
  chainId,
72
72
  spender,
73
- allowed: ["midnightBundles", "vaultBundlesV1", "blueBundlesV1"],
73
+ allowed: ["vaultBundlesV1", "blueBundlesV1"],
74
74
  });
75
75
  const now = morpho_ts_1.Time.timestamp();
76
76
  // Validate an explicit deadline before the token-metadata read: this exported encoder can be
@@ -5,7 +5,7 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
5
5
  * allowance.
6
6
  *
7
7
  * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
8
- * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
8
+ * Permit2, Midnight, MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
9
9
  * addresses when configured.
10
10
  *
11
11
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
@@ -20,7 +20,7 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
20
20
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
21
21
  * may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
22
22
  * @param params.args.spender - Address that will be granted the approval. Must be Permit2,
23
- * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
23
+ * Midnight, MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
24
24
  * @param params.allowances - The user's current allowance of `address` for `spender`.
25
25
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
26
26
  * followed by the new approval. Empty when no approval is needed.
@@ -10,7 +10,7 @@ const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
10
10
  * allowance.
11
11
  *
12
12
  * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
13
- * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
13
+ * Permit2, Midnight, MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
14
14
  * addresses when configured.
15
15
  *
16
16
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
@@ -25,7 +25,7 @@ const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
25
25
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
26
26
  * may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
27
27
  * @param params.args.spender - Address that will be granted the approval. Must be Permit2,
28
- * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
28
+ * Midnight, MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
29
29
  * @param params.allowances - The user's current allowance of `address` for `spender`.
30
30
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
31
31
  * followed by the new approval. Empty when no approval is needed.
@@ -1,5 +1,5 @@
1
1
  import type { Address, Client } from "viem";
2
- import { type ERC20ApprovalAction, type Transaction } from "../../../types/index.js";
2
+ import type { ERC20ApprovalAction, Transaction } from "../../../types/index.js";
3
3
  /** Parameters for {@link getMidnightApprovalRequirements}. */
4
4
  export interface GetMidnightApprovalRequirementsParams {
5
5
  readonly viemClient: Client;
@@ -8,37 +8,53 @@ export interface GetMidnightApprovalRequirementsParams {
8
8
  readonly owner: Address;
9
9
  readonly spender: Address;
10
10
  readonly amount: bigint;
11
+ /**
12
+ * Allowance to set when an approval is needed. Defaults to `maxUint256`; must be
13
+ * at least `amount`.
14
+ */
15
+ readonly approvalAmount?: bigint;
11
16
  }
12
17
  /**
13
18
  * Resolves classic ERC20 approval requirements for a Midnight spender.
14
19
  *
15
20
  * Entity flows call this from `getRequirements()`. Direct low-level consumers
16
- * should call it before encoding a Midnight action that lets `Midnight` or
17
- * `MidnightBundles` pull ERC20 tokens from the user.
21
+ * should pass the spender used by the action: `Midnight` for direct calls, or
22
+ * `MidnightBundlesV2` for bundle flows, including `repayWithdrawCollateral`.
23
+ *
24
+ * The returned approval sets an unlimited allowance (`maxUint256`, capped per
25
+ * token by `MAX_TOKEN_APPROVALS`) whenever the current allowance is below
26
+ * `amount`, because all of an account's Midnight offers and bundle calls share
27
+ * one allowance per token. Pass `approvalAmount` to set a different allowance.
18
28
  *
19
29
  * @param params.viemClient - Viem client used to read ERC20 allowance.
20
30
  * @param params.chainId - Chain id expected by the viem client.
21
31
  * @param params.token - ERC20 token that may need approval.
22
32
  * @param params.owner - Token owner.
23
33
  * @param params.spender - Midnight spender that will pull tokens.
24
- * @param params.amount - Token amount the spender must be able to pull.
34
+ * @param params.amount - Minimum allowance the spender needs.
35
+ * @param params.approvalAmount - Allowance to approve when one is needed; defaults to `maxUint256` and must be at least `amount`.
25
36
  * @returns Approval transactions required for `spender` to pull `amount`.
26
37
  * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
27
- * @throws {NegativeInputError} when `amount < 0n`.
28
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundles deployment.
38
+ * @throws {NegativeInputError} when `amount` or `approvalAmount` is negative.
39
+ * @throws {InputExceedsMaxError} when `amount` or `approvalAmount` exceeds `maxUint256`.
40
+ * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < amount`.
41
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundlesV2 deployment.
29
42
  * @example
30
43
  * ```ts
44
+ * import { getChainAddress } from "@morpho-org/morpho-sdk/addresses";
31
45
  * import {
32
46
  * getMidnightApprovalRequirements,
33
47
  * midnightTakeLend,
34
48
  * } from "@morpho-org/morpho-sdk";
35
49
  *
50
+ * const chainId = 8453;
51
+ * const midnightBundlesV2 = getChainAddress(chainId, "midnightBundlesV2");
36
52
  * const approvals = await getMidnightApprovalRequirements({
37
53
  * viemClient: client,
38
- * chainId: 8453,
54
+ * chainId,
39
55
  * token: loanToken,
40
56
  * owner: user,
41
- * spender: midnightBundles,
57
+ * spender: midnightBundlesV2,
42
58
  * amount: 1_000_000n,
43
59
  * });
44
60
  * if (approvals.length === 0) {
@@ -4,38 +4,49 @@ exports.getMidnightApprovalRequirements = void 0;
4
4
  const viem_1 = require("viem");
5
5
  const actions_1 = require("viem/actions");
6
6
  const index_js_1 = require("../../../helpers/index.js");
7
- const index_js_2 = require("../../../types/index.js");
7
+ const validate_js_1 = require("../../../helpers/validate.js");
8
8
  const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
9
9
  /**
10
10
  * Resolves classic ERC20 approval requirements for a Midnight spender.
11
11
  *
12
12
  * Entity flows call this from `getRequirements()`. Direct low-level consumers
13
- * should call it before encoding a Midnight action that lets `Midnight` or
14
- * `MidnightBundles` pull ERC20 tokens from the user.
13
+ * should pass the spender used by the action: `Midnight` for direct calls, or
14
+ * `MidnightBundlesV2` for bundle flows, including `repayWithdrawCollateral`.
15
+ *
16
+ * The returned approval sets an unlimited allowance (`maxUint256`, capped per
17
+ * token by `MAX_TOKEN_APPROVALS`) whenever the current allowance is below
18
+ * `amount`, because all of an account's Midnight offers and bundle calls share
19
+ * one allowance per token. Pass `approvalAmount` to set a different allowance.
15
20
  *
16
21
  * @param params.viemClient - Viem client used to read ERC20 allowance.
17
22
  * @param params.chainId - Chain id expected by the viem client.
18
23
  * @param params.token - ERC20 token that may need approval.
19
24
  * @param params.owner - Token owner.
20
25
  * @param params.spender - Midnight spender that will pull tokens.
21
- * @param params.amount - Token amount the spender must be able to pull.
26
+ * @param params.amount - Minimum allowance the spender needs.
27
+ * @param params.approvalAmount - Allowance to approve when one is needed; defaults to `maxUint256` and must be at least `amount`.
22
28
  * @returns Approval transactions required for `spender` to pull `amount`.
23
29
  * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
24
- * @throws {NegativeInputError} when `amount < 0n`.
25
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundles deployment.
30
+ * @throws {NegativeInputError} when `amount` or `approvalAmount` is negative.
31
+ * @throws {InputExceedsMaxError} when `amount` or `approvalAmount` exceeds `maxUint256`.
32
+ * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < amount`.
33
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundlesV2 deployment.
26
34
  * @example
27
35
  * ```ts
36
+ * import { getChainAddress } from "@morpho-org/morpho-sdk/addresses";
28
37
  * import {
29
38
  * getMidnightApprovalRequirements,
30
39
  * midnightTakeLend,
31
40
  * } from "@morpho-org/morpho-sdk";
32
41
  *
42
+ * const chainId = 8453;
43
+ * const midnightBundlesV2 = getChainAddress(chainId, "midnightBundlesV2");
33
44
  * const approvals = await getMidnightApprovalRequirements({
34
45
  * viemClient: client,
35
- * chainId: 8453,
46
+ * chainId,
36
47
  * token: loanToken,
37
48
  * owner: user,
38
- * spender: midnightBundles,
49
+ * spender: midnightBundlesV2,
39
50
  * amount: 1_000_000n,
40
51
  * });
41
52
  * if (approvals.length === 0) {
@@ -45,14 +56,14 @@ const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
45
56
  */
46
57
  const getMidnightApprovalRequirements = async (params) => {
47
58
  (0, index_js_1.validateChainId)(params.viemClient.chain?.id, params.chainId);
48
- if (params.amount < 0n) {
49
- throw new index_js_2.NegativeInputError("amount", params.amount);
50
- }
59
+ (0, validate_js_1.validateUint256Field)("amount", params.amount);
60
+ if (params.approvalAmount !== undefined)
61
+ (0, validate_js_1.validateUint256Field)("approvalAmount", params.approvalAmount);
51
62
  // Validate the target even when no approval transaction needs to be encoded.
52
63
  (0, index_js_1.validateRequirementSpender)({
53
64
  chainId: params.chainId,
54
65
  spender: params.spender,
55
- allowed: ["midnight", "midnightBundles"],
66
+ allowed: ["midnight", "midnightBundlesV2"],
56
67
  });
57
68
  if (params.amount === 0n)
58
69
  return [];
@@ -68,7 +79,7 @@ const getMidnightApprovalRequirements = async (params) => {
68
79
  args: {
69
80
  spender: params.spender,
70
81
  spendAmount: params.amount,
71
- approvalAmount: params.amount,
82
+ approvalAmount: params.approvalAmount ?? viem_1.maxUint256,
72
83
  },
73
84
  allowances: allowance,
74
85
  });
@@ -8,29 +8,33 @@ export interface GetMidnightAuthorizationRequirementParams {
8
8
  readonly authorized: Address;
9
9
  }
10
10
  /**
11
- * Resolves the Midnight authorization transaction for a ratifier or bundle spender.
11
+ * Resolves the Midnight authorization transaction for a Midnight bundle operator.
12
12
  *
13
- * Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`,
14
- * such as bundle takes or Ecrecover offer-root ratification. Entity flows call
13
+ * Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`.
14
+ * MidnightBundlesV2 taker and cancel-and-make flows, including
15
+ * `repayWithdrawCollateral`, authorize `MidnightBundlesV2`. Entity flows call
15
16
  * this from `getRequirements()` and omit the transaction when authorization is
16
17
  * already set.
17
18
  *
18
19
  * @param params.viemClient - Viem client used to read `Midnight.isAuthorized`.
19
20
  * @param params.chainId - Chain id expected by the viem client.
20
21
  * @param params.owner - Account granting authorization.
21
- * @param params.authorized - Spender or ratifier that needs authorization.
22
+ * @param params.authorized - MidnightBundlesV2.
22
23
  * @returns Authorization transaction, or `null` when already authorized.
23
24
  * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
24
- * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported bundle or ratifier address.
25
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not MidnightBundlesV2.
25
26
  * @example
26
27
  * ```ts
28
+ * import { getChainAddress } from "@morpho-org/morpho-sdk/addresses";
27
29
  * import { getMidnightAuthorizationRequirement } from "@morpho-org/morpho-sdk";
28
30
  *
31
+ * const chainId = 8453;
32
+ * const midnightBundlesV2 = getChainAddress(chainId, "midnightBundlesV2");
29
33
  * const tx = await getMidnightAuthorizationRequirement({
30
34
  * viemClient: client,
31
- * chainId: 8453,
35
+ * chainId,
32
36
  * owner: user,
33
- * authorized: midnightBundles,
37
+ * authorized: midnightBundlesV2,
34
38
  * });
35
39
  * if (tx) {
36
40
  * await walletClient.sendTransaction({
@@ -8,29 +8,33 @@ const actions_1 = require("viem/actions");
8
8
  const index_js_1 = require("../../../helpers/index.js");
9
9
  const validateMidnightAuthorizationTarget_js_1 = require("../../../helpers/validateMidnightAuthorizationTarget.js");
10
10
  /**
11
- * Resolves the Midnight authorization transaction for a ratifier or bundle spender.
11
+ * Resolves the Midnight authorization transaction for a Midnight bundle operator.
12
12
  *
13
- * Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`,
14
- * such as bundle takes or Ecrecover offer-root ratification. Entity flows call
13
+ * Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`.
14
+ * MidnightBundlesV2 taker and cancel-and-make flows, including
15
+ * `repayWithdrawCollateral`, authorize `MidnightBundlesV2`. Entity flows call
15
16
  * this from `getRequirements()` and omit the transaction when authorization is
16
17
  * already set.
17
18
  *
18
19
  * @param params.viemClient - Viem client used to read `Midnight.isAuthorized`.
19
20
  * @param params.chainId - Chain id expected by the viem client.
20
21
  * @param params.owner - Account granting authorization.
21
- * @param params.authorized - Spender or ratifier that needs authorization.
22
+ * @param params.authorized - MidnightBundlesV2.
22
23
  * @returns Authorization transaction, or `null` when already authorized.
23
24
  * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
24
- * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported bundle or ratifier address.
25
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not MidnightBundlesV2.
25
26
  * @example
26
27
  * ```ts
28
+ * import { getChainAddress } from "@morpho-org/morpho-sdk/addresses";
27
29
  * import { getMidnightAuthorizationRequirement } from "@morpho-org/morpho-sdk";
28
30
  *
31
+ * const chainId = 8453;
32
+ * const midnightBundlesV2 = getChainAddress(chainId, "midnightBundlesV2");
29
33
  * const tx = await getMidnightAuthorizationRequirement({
30
34
  * viemClient: client,
31
- * chainId: 8453,
35
+ * chainId,
32
36
  * owner: user,
33
- * authorized: midnightBundles,
37
+ * authorized: midnightBundlesV2,
34
38
  * });
35
39
  * if (tx) {
36
40
  * await walletClient.sendTransaction({
@@ -1,3 +1,2 @@
1
1
  export * from "./getMidnightApprovalRequirements.js";
2
2
  export * from "./getMidnightAuthorizationRequirement.js";
3
- export * from "./getSetterRatifierRatifyRootRequirement.js";
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./getMidnightApprovalRequirements.js"), exports);
18
18
  __exportStar(require("./getMidnightAuthorizationRequirement.js"), exports);
19
- __exportStar(require("./getSetterRatifierRatifyRootRequirement.js"), exports);
@@ -1,4 +1,4 @@
1
1
  export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType, } from "@morpho-org/blue-sdk";
2
2
  export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, MAX_TREE_HEIGHT as MIDNIGHT_MAX_TREE_HEIGHT, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, RATE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
3
3
  export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
4
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
4
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./helpers/constant.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.ZERO_ADDRESS = exports.REWARDS_BASE_URL = exports.MORPHO_DOMAIN = exports.DOCS_BASE_URL = exports.ChainUtils = exports.ChainId = exports.BLUE_API_GRAPHQL_URL = exports.BLUE_API_BASE_URL = exports.MIDNIGHT_TIME_TO_MAX_LIF = exports.MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS = exports.MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_PRICE_ROUNDING_STEP = exports.MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_OFFER_TYPEHASH = exports.MIDNIGHT_MAX_TREE_HEIGHT = exports.MIDNIGHT_MAX_TICK = exports.MIDNIGHT_MAX_SETTLEMENT_FEES = exports.MIDNIGHT_MAX_OFFER_CAP = exports.MIDNIGHT_MAX_CONTINUOUS_FEE = exports.MIDNIGHT_MAX_COLLATERALS_PER_BORROWER = exports.MIDNIGHT_MAX_COLLATERALS = exports.MIDNIGHT_MARKET_TYPEHASH = exports.MIDNIGHT_EIP712_DOMAIN_TYPEHASH = exports.MIDNIGHT_DEFAULT_TICK_SPACING = exports.MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH = exports.MIDNIGHT_CBP = exports.BlueTransactionType = exports.SECONDS_PER_YEAR = exports.ORACLE_PRICE_SCALE = exports.BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.BLUE_LIQUIDATION_CURSOR = exports.isBlueMarketId = exports.ERC20_ALLOWANCE_RECIPIENTS = exports.EIP_712_FIELDS = exports.DEFAULT_SLIPPAGE_TOLERANCE = void 0;
3
+ exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.ZERO_ADDRESS = exports.REWARDS_BASE_URL = exports.MORPHO_DOMAIN = exports.DOCS_BASE_URL = exports.ChainUtils = exports.ChainId = exports.BLUE_API_GRAPHQL_URL = exports.BLUE_API_BASE_URL = exports.MIDNIGHT_TIME_TO_MAX_LIF = exports.MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS = exports.MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_PRICE_ROUNDING_STEP = exports.MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_OFFER_TYPEHASH = exports.MIDNIGHT_MAX_TREE_HEIGHT = exports.MIDNIGHT_MAX_TICK = exports.MIDNIGHT_MAX_SETTLEMENT_FEES = exports.MIDNIGHT_MAX_OFFER_CAP = exports.MIDNIGHT_MAX_CONTINUOUS_FEE = exports.MIDNIGHT_MAX_COLLATERALS_PER_BORROWER = exports.MIDNIGHT_MAX_COLLATERALS = exports.MIDNIGHT_MARKET_TYPEHASH = exports.MIDNIGHT_EIP712_DOMAIN_TYPEHASH = exports.MIDNIGHT_DEFAULT_TICK_SPACING = exports.MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH = exports.MIDNIGHT_CBP = exports.BlueTransactionType = exports.SECONDS_PER_YEAR = exports.ORACLE_PRICE_SCALE = exports.BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.BLUE_LIQUIDATION_CURSOR = exports.isBlueMarketId = exports.ERC20_ALLOWANCE_RECIPIENTS = exports.EIP_712_FIELDS = exports.DEFAULT_SLIPPAGE_TOLERANCE = void 0;
4
4
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  Object.defineProperty(exports, "DEFAULT_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE; } });
6
6
  Object.defineProperty(exports, "EIP_712_FIELDS", { enumerable: true, get: function () { return blue_sdk_1.EIP_712_FIELDS; } });
@@ -51,3 +51,4 @@ Object.defineProperty(exports, "MAX_ABSOLUTE_SHARE_PRICE", { enumerable: true, g
51
51
  Object.defineProperty(exports, "MAX_REALLOCATION_PENALTY", { enumerable: true, get: function () { return constant_js_1.MAX_REALLOCATION_PENALTY; } });
52
52
  Object.defineProperty(exports, "MAX_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return constant_js_1.MAX_SLIPPAGE_TOLERANCE; } });
53
53
  Object.defineProperty(exports, "MAX_TOKEN_APPROVALS", { enumerable: true, get: function () { return constant_js_1.MAX_TOKEN_APPROVALS; } });
54
+ Object.defineProperty(exports, "MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS", { enumerable: true, get: function () { return constant_js_1.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS; } });
@@ -12,8 +12,8 @@ export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnap
12
12
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
13
13
  export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
14
14
  export { MorphoBlue } from "./blue/index.js";
15
- export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, } from "./midnight/index.js";
16
- export { type MidnightActionOutput, type MidnightActionSignatures, type MidnightActions, MorphoMidnight, } from "./midnight/index.js";
15
+ export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, } from "./midnight/index.js";
16
+ export { type MidnightActionOutput, type MidnightActions, type MidnightRequirementsParams, MorphoMidnight, } from "./midnight/index.js";
17
17
  export * from "./requirements/index.js";
18
18
  export { MorphoVaultV1 } from "./vaultV1/index.js";
19
19
  export { MorphoVaultV2 } from "./vaultV2/index.js";