@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.
- package/MIGRATION-v6-to-v7.md +291 -0
- package/README.md +26 -12
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +3 -2
- package/lib/cjs/actions/bundles/common.d.ts +9 -5
- package/lib/cjs/actions/bundles/common.js +22 -13
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
- package/lib/cjs/actions/midnight/authorization.js +3 -2
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
- package/lib/cjs/actions/midnight/index.d.ts +3 -3
- package/lib/cjs/actions/midnight/index.js +3 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
- package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
- package/lib/cjs/actions/midnight/takeLend.js +111 -54
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
- package/lib/cjs/actions/midnight/types.d.ts +7 -26
- package/lib/cjs/actions/midnight/types.js +0 -13
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/midnight/index.js +0 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/entities/index.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
- package/lib/cjs/entities/midnight/midnight.js +981 -509
- package/lib/cjs/entities/midnight/types.d.ts +142 -60
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
- package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
- package/lib/cjs/helpers/callback.d.ts +54 -0
- package/lib/cjs/helpers/callback.js +73 -0
- package/lib/cjs/helpers/constant.d.ts +2 -0
- package/lib/cjs/helpers/constant.js +3 -1
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +6 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/cjs/helpers/validate.d.ts +43 -2
- package/lib/cjs/helpers/validate.js +60 -3
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +3 -2
- package/lib/cjs/midnight/types.d.ts +1 -1
- package/lib/cjs/types/action.d.ts +117 -89
- package/lib/cjs/types/action.js +1 -19
- package/lib/cjs/types/error.d.ts +126 -40
- package/lib/cjs/types/error.js +154 -49
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +9 -5
- package/lib/esm/actions/bundles/common.js +22 -13
- package/lib/esm/actions/midnight/authorization.d.ts +3 -2
- package/lib/esm/actions/midnight/authorization.js +3 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
- package/lib/esm/actions/midnight/index.d.ts +3 -3
- package/lib/esm/actions/midnight/index.js +3 -3
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
- package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/esm/actions/midnight/takeBorrow.js +98 -57
- package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
- package/lib/esm/actions/midnight/takeLend.js +114 -57
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
- package/lib/esm/actions/midnight/types.d.ts +7 -26
- package/lib/esm/actions/midnight/types.js +1 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/esm/actions/requirements/midnight/index.js +0 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/index.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +582 -108
- package/lib/esm/entities/midnight/midnight.js +987 -515
- package/lib/esm/entities/midnight/types.d.ts +142 -60
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
- package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
- package/lib/esm/helpers/callback.d.ts +54 -0
- package/lib/esm/helpers/callback.js +68 -0
- package/lib/esm/helpers/constant.d.ts +2 -0
- package/lib/esm/helpers/constant.js +2 -0
- package/lib/esm/helpers/index.d.ts +3 -2
- package/lib/esm/helpers/index.js +3 -2
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/esm/helpers/validate.d.ts +43 -2
- package/lib/esm/helpers/validate.js +58 -2
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/esm/helpers/validateRequirementSpender.js +4 -5
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/types.d.ts +1 -1
- package/lib/esm/types/action.d.ts +117 -89
- package/lib/esm/types/action.js +1 -18
- package/lib/esm/types/error.d.ts +126 -40
- package/lib/esm/types/error.js +135 -38
- package/package.json +8 -7
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
- package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/esm/actions/midnight/cancelOffer.js +0 -69
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- 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
|
|
25
|
-
*
|
|
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
|
|
36
|
-
*
|
|
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: ["
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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 {
|
|
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
|
|
17
|
-
* `
|
|
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 -
|
|
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
|
|
28
|
-
* @throws {
|
|
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
|
|
54
|
+
* chainId,
|
|
39
55
|
* token: loanToken,
|
|
40
56
|
* owner: user,
|
|
41
|
-
* spender:
|
|
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
|
|
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
|
|
14
|
-
* `
|
|
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 -
|
|
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
|
|
25
|
-
* @throws {
|
|
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
|
|
46
|
+
* chainId,
|
|
36
47
|
* token: loanToken,
|
|
37
48
|
* owner: user,
|
|
38
|
-
* spender:
|
|
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
|
-
|
|
49
|
-
|
|
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", "
|
|
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.
|
|
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
|
|
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
|
-
*
|
|
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 -
|
|
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
|
|
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
|
|
35
|
+
* chainId,
|
|
32
36
|
* owner: user,
|
|
33
|
-
* authorized:
|
|
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
|
|
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
|
-
*
|
|
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 -
|
|
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
|
|
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
|
|
35
|
+
* chainId,
|
|
32
36
|
* owner: user,
|
|
33
|
-
* authorized:
|
|
37
|
+
* authorized: midnightBundlesV2,
|
|
34
38
|
* });
|
|
35
39
|
* if (tx) {
|
|
36
40
|
* await walletClient.sendTransaction({
|
|
@@ -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);
|
package/lib/cjs/constants.d.ts
CHANGED
|
@@ -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";
|
package/lib/cjs/constants.js
CHANGED
|
@@ -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
|
|
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";
|