@morpho-org/morpho-sdk 6.5.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 +3 -1
- package/lib/cjs/entities/blue/blue.d.ts +10 -6
- package/lib/cjs/entities/blue/blue.js +5 -3
- 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/entities/vaultV2BlueReallocationData.d.ts +11 -3
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +119 -43
- package/lib/cjs/helpers/callback.d.ts +54 -0
- package/lib/cjs/helpers/callback.js +73 -0
- package/lib/cjs/helpers/constant.d.ts +10 -0
- package/lib/cjs/helpers/constant.js +11 -1
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +7 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/cjs/helpers/utilization.d.ts +13 -0
- package/lib/cjs/helpers/utilization.js +26 -1
- 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/cjs/types/sharedLiquidity.d.ts +17 -0
- 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/blue/blue.d.ts +10 -6
- package/lib/esm/entities/blue/blue.js +5 -3
- 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/entities/vaultV2BlueReallocationData.d.ts +11 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.js +120 -44
- package/lib/esm/helpers/callback.d.ts +54 -0
- package/lib/esm/helpers/callback.js +68 -0
- package/lib/esm/helpers/constant.d.ts +10 -0
- package/lib/esm/helpers/constant.js +10 -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/utilization.d.ts +13 -0
- package/lib/esm/helpers/utilization.js +25 -1
- 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/lib/esm/types/sharedLiquidity.d.ts +17 -0
- package/package.json +9 -8
- 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
|
@@ -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) {
|
|
@@ -1,38 +1,49 @@
|
|
|
1
|
-
import { erc20Abi } from "viem";
|
|
1
|
+
import { erc20Abi, maxUint256 } from "viem";
|
|
2
2
|
import { readContract } from "viem/actions";
|
|
3
3
|
import { validateChainId, validateRequirementSpender, } from "../../../helpers/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { validateUint256Field } from "../../../helpers/validate.js";
|
|
5
5
|
import { getRequirementsApproval } from "../getRequirementsApproval.js";
|
|
6
6
|
/**
|
|
7
7
|
* Resolves classic ERC20 approval requirements for a Midnight spender.
|
|
8
8
|
*
|
|
9
9
|
* Entity flows call this from `getRequirements()`. Direct low-level consumers
|
|
10
|
-
* should
|
|
11
|
-
* `
|
|
10
|
+
* should pass the spender used by the action: `Midnight` for direct calls, or
|
|
11
|
+
* `MidnightBundlesV2` for bundle flows, including `repayWithdrawCollateral`.
|
|
12
|
+
*
|
|
13
|
+
* The returned approval sets an unlimited allowance (`maxUint256`, capped per
|
|
14
|
+
* token by `MAX_TOKEN_APPROVALS`) whenever the current allowance is below
|
|
15
|
+
* `amount`, because all of an account's Midnight offers and bundle calls share
|
|
16
|
+
* one allowance per token. Pass `approvalAmount` to set a different allowance.
|
|
12
17
|
*
|
|
13
18
|
* @param params.viemClient - Viem client used to read ERC20 allowance.
|
|
14
19
|
* @param params.chainId - Chain id expected by the viem client.
|
|
15
20
|
* @param params.token - ERC20 token that may need approval.
|
|
16
21
|
* @param params.owner - Token owner.
|
|
17
22
|
* @param params.spender - Midnight spender that will pull tokens.
|
|
18
|
-
* @param params.amount -
|
|
23
|
+
* @param params.amount - Minimum allowance the spender needs.
|
|
24
|
+
* @param params.approvalAmount - Allowance to approve when one is needed; defaults to `maxUint256` and must be at least `amount`.
|
|
19
25
|
* @returns Approval transactions required for `spender` to pull `amount`.
|
|
20
26
|
* @throws {ChainIdMismatchError} when the viem client is connected to another chain.
|
|
21
|
-
* @throws {NegativeInputError} when `amount
|
|
22
|
-
* @throws {
|
|
27
|
+
* @throws {NegativeInputError} when `amount` or `approvalAmount` is negative.
|
|
28
|
+
* @throws {InputExceedsMaxError} when `amount` or `approvalAmount` exceeds `maxUint256`.
|
|
29
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount < amount`.
|
|
30
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's Midnight or MidnightBundlesV2 deployment.
|
|
23
31
|
* @example
|
|
24
32
|
* ```ts
|
|
33
|
+
* import { getChainAddress } from "@morpho-org/morpho-sdk/addresses";
|
|
25
34
|
* import {
|
|
26
35
|
* getMidnightApprovalRequirements,
|
|
27
36
|
* midnightTakeLend,
|
|
28
37
|
* } from "@morpho-org/morpho-sdk";
|
|
29
38
|
*
|
|
39
|
+
* const chainId = 8453;
|
|
40
|
+
* const midnightBundlesV2 = getChainAddress(chainId, "midnightBundlesV2");
|
|
30
41
|
* const approvals = await getMidnightApprovalRequirements({
|
|
31
42
|
* viemClient: client,
|
|
32
|
-
* chainId
|
|
43
|
+
* chainId,
|
|
33
44
|
* token: loanToken,
|
|
34
45
|
* owner: user,
|
|
35
|
-
* spender:
|
|
46
|
+
* spender: midnightBundlesV2,
|
|
36
47
|
* amount: 1_000_000n,
|
|
37
48
|
* });
|
|
38
49
|
* if (approvals.length === 0) {
|
|
@@ -42,14 +53,14 @@ import { getRequirementsApproval } from "../getRequirementsApproval.js";
|
|
|
42
53
|
*/
|
|
43
54
|
export const getMidnightApprovalRequirements = async (params) => {
|
|
44
55
|
validateChainId(params.viemClient.chain?.id, params.chainId);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
validateUint256Field("amount", params.amount);
|
|
57
|
+
if (params.approvalAmount !== undefined)
|
|
58
|
+
validateUint256Field("approvalAmount", params.approvalAmount);
|
|
48
59
|
// Validate the target even when no approval transaction needs to be encoded.
|
|
49
60
|
validateRequirementSpender({
|
|
50
61
|
chainId: params.chainId,
|
|
51
62
|
spender: params.spender,
|
|
52
|
-
allowed: ["midnight", "
|
|
63
|
+
allowed: ["midnight", "midnightBundlesV2"],
|
|
53
64
|
});
|
|
54
65
|
if (params.amount === 0n)
|
|
55
66
|
return [];
|
|
@@ -65,7 +76,7 @@ export const getMidnightApprovalRequirements = async (params) => {
|
|
|
65
76
|
args: {
|
|
66
77
|
spender: params.spender,
|
|
67
78
|
spendAmount: params.amount,
|
|
68
|
-
approvalAmount: params.
|
|
79
|
+
approvalAmount: params.approvalAmount ?? maxUint256,
|
|
69
80
|
},
|
|
70
81
|
allowances: allowance,
|
|
71
82
|
});
|
|
@@ -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({
|
|
@@ -5,29 +5,33 @@ import { readContract } from "viem/actions";
|
|
|
5
5
|
import { validateChainId } from "../../../helpers/index.js";
|
|
6
6
|
import { validateMidnightAuthorizationTarget } from "../../../helpers/validateMidnightAuthorizationTarget.js";
|
|
7
7
|
/**
|
|
8
|
-
* Resolves the Midnight authorization transaction for a
|
|
8
|
+
* Resolves the Midnight authorization transaction for a Midnight bundle operator.
|
|
9
9
|
*
|
|
10
|
-
* Call before actions that rely on `Midnight.isAuthorized(owner, authorized)
|
|
11
|
-
*
|
|
10
|
+
* Call before actions that rely on `Midnight.isAuthorized(owner, authorized)`.
|
|
11
|
+
* MidnightBundlesV2 taker and cancel-and-make flows, including
|
|
12
|
+
* `repayWithdrawCollateral`, authorize `MidnightBundlesV2`. Entity flows call
|
|
12
13
|
* this from `getRequirements()` and omit the transaction when authorization is
|
|
13
14
|
* already set.
|
|
14
15
|
*
|
|
15
16
|
* @param params.viemClient - Viem client used to read `Midnight.isAuthorized`.
|
|
16
17
|
* @param params.chainId - Chain id expected by the viem client.
|
|
17
18
|
* @param params.owner - Account granting authorization.
|
|
18
|
-
* @param params.authorized -
|
|
19
|
+
* @param params.authorized - MidnightBundlesV2.
|
|
19
20
|
* @returns Authorization transaction, or `null` when already authorized.
|
|
20
21
|
* @throws {ChainIdMismatchError} when the viem client is connected to another chain.
|
|
21
|
-
* @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not
|
|
22
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not MidnightBundlesV2.
|
|
22
23
|
* @example
|
|
23
24
|
* ```ts
|
|
25
|
+
* import { getChainAddress } from "@morpho-org/morpho-sdk/addresses";
|
|
24
26
|
* import { getMidnightAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
25
27
|
*
|
|
28
|
+
* const chainId = 8453;
|
|
29
|
+
* const midnightBundlesV2 = getChainAddress(chainId, "midnightBundlesV2");
|
|
26
30
|
* const tx = await getMidnightAuthorizationRequirement({
|
|
27
31
|
* viemClient: client,
|
|
28
|
-
* chainId
|
|
32
|
+
* chainId,
|
|
29
33
|
* owner: user,
|
|
30
|
-
* authorized:
|
|
34
|
+
* authorized: midnightBundlesV2,
|
|
31
35
|
* });
|
|
32
36
|
* if (tx) {
|
|
33
37
|
* await walletClient.sendTransaction({
|
package/lib/esm/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_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/esm/constants.js
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_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";
|
|
@@ -819,15 +819,17 @@ export interface BlueActions {
|
|
|
819
819
|
* allocation through `timestamp + capAccrualBuffer` (two hours by default;
|
|
820
820
|
* `0n` disables it). For market-source reallocations the source position's
|
|
821
821
|
* interest is also reserved on cap ids shared with the target, and reserves
|
|
822
|
-
* persist across every leg of a plan.
|
|
822
|
+
* persist across every leg of a plan. Operation plans keep
|
|
823
|
+
* `allocatorCapHeadroom` (1% of the cap by default) free under each target
|
|
824
|
+
* BluePublicAllocator cap unless the operation shortfall needs it.
|
|
823
825
|
*
|
|
824
826
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
825
827
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
826
828
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
827
829
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
828
830
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
829
|
-
* @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
|
|
830
|
-
* @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
|
|
831
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
|
|
832
|
+
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
|
|
831
833
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
832
834
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
833
835
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -1037,15 +1039,17 @@ export declare class MorphoBlue implements BlueActions {
|
|
|
1037
1039
|
* allocation through `timestamp + capAccrualBuffer` (two hours by default;
|
|
1038
1040
|
* `0n` disables it). For market-source reallocations the source position's
|
|
1039
1041
|
* interest is also reserved on cap ids shared with the target, and reserves
|
|
1040
|
-
* persist across every leg of a plan.
|
|
1042
|
+
* persist across every leg of a plan. Operation plans keep
|
|
1043
|
+
* `allocatorCapHeadroom` (1% of the cap by default) free under each target
|
|
1044
|
+
* BluePublicAllocator cap unless the operation shortfall needs it.
|
|
1041
1045
|
*
|
|
1042
1046
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
1043
1047
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
1044
1048
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
1045
1049
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
1046
1050
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
1047
|
-
* @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
|
|
1048
|
-
* @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
|
|
1051
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
|
|
1052
|
+
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
|
|
1049
1053
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
1050
1054
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
1051
1055
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -735,15 +735,17 @@ export class MorphoBlue {
|
|
|
735
735
|
* allocation through `timestamp + capAccrualBuffer` (two hours by default;
|
|
736
736
|
* `0n` disables it). For market-source reallocations the source position's
|
|
737
737
|
* interest is also reserved on cap ids shared with the target, and reserves
|
|
738
|
-
* persist across every leg of a plan.
|
|
738
|
+
* persist across every leg of a plan. Operation plans keep
|
|
739
|
+
* `allocatorCapHeadroom` (1% of the cap by default) free under each target
|
|
740
|
+
* BluePublicAllocator cap unless the operation shortfall needs it.
|
|
739
741
|
*
|
|
740
742
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
741
743
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
742
744
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
743
745
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
744
746
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
745
|
-
* @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
|
|
746
|
-
* @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
|
|
747
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
|
|
748
|
+
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
|
|
747
749
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
748
750
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
749
751
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -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";
|