@morpho-org/morpho-sdk 9.4.0 → 9.5.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-v5-to-v6.md +7 -0
- package/MIGRATION-v7-to-v8.md +7 -0
- package/MIGRATION-v8-to-v9.md +7 -0
- package/README.md +6 -4
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -1
- package/lib/cjs/entities/blue/blue.d.ts +7 -21
- package/lib/cjs/entities/blue/blue.js +4 -22
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +21 -26
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +42 -80
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +6 -3
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +2 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +5 -11
- package/lib/cjs/entities/vaultV1/vaultV1.js +3 -11
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +5 -11
- package/lib/cjs/entities/vaultV2/vaultV2.js +3 -11
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +40 -4
- package/lib/cjs/types/action.d.ts +11 -4
- package/lib/cjs/types/action.js +1 -0
- package/lib/cjs/types/error.d.ts +8 -2
- package/lib/cjs/types/error.js +8 -2
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +4 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +7 -21
- package/lib/esm/entities/blue/blue.js +4 -22
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +21 -26
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +44 -82
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +6 -3
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +2 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +5 -11
- package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +5 -11
- package/lib/esm/entities/vaultV2/vaultV2.js +4 -12
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +40 -4
- package/lib/esm/types/action.d.ts +11 -4
- package/lib/esm/types/action.js +1 -0
- package/lib/esm/types/error.d.ts +8 -2
- package/lib/esm/types/error.js +8 -2
- package/package.json +2 -2
|
@@ -58,11 +58,8 @@ export class MorphoBlue {
|
|
|
58
58
|
* spender/authorized operator holds code, with one `eth_getCode` per distinct address
|
|
59
59
|
* before any other requirement read. Blue write flows probe `eth_chainId` only after a target
|
|
60
60
|
* has no code and report a chain mismatch when the RPC serves another chain.
|
|
61
|
-
*
|
|
62
|
-
* @param params.erc20Funding - Whether the flow resolves an ERC-20 funding leg, which
|
|
63
|
-
* may name canonical Permit2 when signatures are supported.
|
|
64
61
|
*/
|
|
65
|
-
async assertWriteTargets(
|
|
62
|
+
async assertWriteTargets() {
|
|
66
63
|
const targets = [
|
|
67
64
|
{
|
|
68
65
|
role: "bundles.blueBundlesV1",
|
|
@@ -70,11 +67,6 @@ export class MorphoBlue {
|
|
|
70
67
|
},
|
|
71
68
|
{ role: "blue", address: getChainAddress(this.chainId, "blue") },
|
|
72
69
|
];
|
|
73
|
-
if (params?.erc20Funding && this.client.options.supportSignature) {
|
|
74
|
-
const permit2 = getChainAddresses(this.chainId).permit2;
|
|
75
|
-
if (permit2 != null)
|
|
76
|
-
targets.push({ role: "permit2", address: permit2 });
|
|
77
|
-
}
|
|
78
70
|
await assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets);
|
|
79
71
|
}
|
|
80
72
|
getMaxLtv(marketParams = this.marketParams) {
|
|
@@ -95,7 +87,6 @@ export class MorphoBlue {
|
|
|
95
87
|
supportSignature: this.client.options.supportSignature,
|
|
96
88
|
supportDeployless: this.client.options.supportDeployless,
|
|
97
89
|
useSimplePermit: params.useSimplePermit,
|
|
98
|
-
permit2Nonce: params.permit2Nonce,
|
|
99
90
|
now: params.now,
|
|
100
91
|
});
|
|
101
92
|
}
|
|
@@ -146,9 +137,7 @@ export class MorphoBlue {
|
|
|
146
137
|
getRequirements: (requirementsParams) => {
|
|
147
138
|
const now = Time.timestamp();
|
|
148
139
|
this.validateDeadline(deadline, now);
|
|
149
|
-
return this.assertWriteTargets({
|
|
150
|
-
erc20Funding: nativeValue === 0n,
|
|
151
|
-
}).then(() => {
|
|
140
|
+
return this.assertWriteTargets().then(() => {
|
|
152
141
|
if (nativeValue > 0n)
|
|
153
142
|
return [];
|
|
154
143
|
return this.getTokenRequirements({
|
|
@@ -158,7 +147,6 @@ export class MorphoBlue {
|
|
|
158
147
|
deadline,
|
|
159
148
|
now,
|
|
160
149
|
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
161
|
-
permit2Nonce: requirementsParams?.permit2Nonce,
|
|
162
150
|
});
|
|
163
151
|
});
|
|
164
152
|
},
|
|
@@ -572,9 +560,7 @@ export class MorphoBlue {
|
|
|
572
560
|
getRequirements: async (requirementsParams) => {
|
|
573
561
|
const now = Time.timestamp();
|
|
574
562
|
this.validateDeadline(deadline, now);
|
|
575
|
-
await this.assertWriteTargets(
|
|
576
|
-
erc20Funding: hasRepay && nativeValue === 0n,
|
|
577
|
-
});
|
|
563
|
+
await this.assertWriteTargets();
|
|
578
564
|
const [tokenRequirements, authorizationRequirements] = await Promise.all([
|
|
579
565
|
hasRepay && nativeValue === 0n
|
|
580
566
|
? this.getTokenRequirements({
|
|
@@ -584,7 +570,6 @@ export class MorphoBlue {
|
|
|
584
570
|
deadline,
|
|
585
571
|
now,
|
|
586
572
|
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
587
|
-
permit2Nonce: requirementsParams?.permit2Nonce,
|
|
588
573
|
})
|
|
589
574
|
: Promise.resolve([]),
|
|
590
575
|
collateralAssets > 0n
|
|
@@ -683,9 +668,7 @@ export class MorphoBlue {
|
|
|
683
668
|
getRequirements: async (requirementsParams) => {
|
|
684
669
|
const now = Time.timestamp();
|
|
685
670
|
this.validateDeadline(deadline, now);
|
|
686
|
-
await this.assertWriteTargets(
|
|
687
|
-
erc20Funding: collateralAssets > 0n && nativeValue === 0n,
|
|
688
|
-
});
|
|
671
|
+
await this.assertWriteTargets();
|
|
689
672
|
const [tokenRequirements, authorizationRequirements] = await Promise.all([
|
|
690
673
|
collateralAssets > 0n && nativeValue === 0n
|
|
691
674
|
? this.getTokenRequirements({
|
|
@@ -695,7 +678,6 @@ export class MorphoBlue {
|
|
|
695
678
|
deadline,
|
|
696
679
|
now,
|
|
697
680
|
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
698
|
-
permit2Nonce: requirementsParams?.permit2Nonce,
|
|
699
681
|
})
|
|
700
682
|
: Promise.resolve([]),
|
|
701
683
|
borrowAssets > 0n
|
|
@@ -18,22 +18,19 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
18
18
|
readonly supportSignature: boolean;
|
|
19
19
|
/** Whether token metadata reads may use deployless aggregation. */
|
|
20
20
|
readonly supportDeployless?: boolean;
|
|
21
|
-
/** Prefer ERC-2612 when the token exposes a compatible nonce. */
|
|
21
|
+
/** Prefer ERC-2612 when the token exposes a compatible nonce; defaults to true when signatures are supported. */
|
|
22
22
|
readonly useSimplePermit?: boolean;
|
|
23
|
-
/**
|
|
23
|
+
/** @deprecated Ignored. The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals. */
|
|
24
24
|
readonly permit2Nonce?: bigint;
|
|
25
25
|
/** Timestamp the deadline is validated against; defaults to the current time. */
|
|
26
26
|
readonly now?: bigint;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Resolves direct approval
|
|
30
|
-
* a registered fixed bundles contract.
|
|
29
|
+
* Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
|
|
31
30
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
|
|
36
|
-
* by default; concurrent flows for the same owner should pass explicit nonces.
|
|
31
|
+
* Reads the direct allowance first for nonzero amounts. Only when it is insufficient does
|
|
32
|
+
* the selected signature path try ERC-2612 nonce and metadata reads. A permit is returned only
|
|
33
|
+
* when the token's DOMAIN_SEPARATOR matches the domain to be signed; otherwise use approval.
|
|
37
34
|
*
|
|
38
35
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
39
36
|
* @param params - Token requirement parameters.
|
|
@@ -44,37 +41,35 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
44
41
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
45
42
|
* @param params.deadline - Final-call and signature deadline.
|
|
46
43
|
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
47
|
-
* @param params.supportSignature - Whether ERC-2612
|
|
44
|
+
* @param params.supportSignature - Whether ERC-2612 signatures may be requested.
|
|
48
45
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
49
|
-
* @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's
|
|
50
|
-
*
|
|
51
|
-
*
|
|
46
|
+
* @param params.useSimplePermit - Defaults to true when signatures are supported. Prefer ERC-2612 when `nonces()` succeeds and the token's
|
|
47
|
+
* DOMAIN_SEPARATOR matches the signing domain. Missing, mismatched, or unsupported domains,
|
|
48
|
+
* or recognized nonce/separator reverts or undecodable results, fall back to classic approval. A malformed
|
|
52
49
|
* `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
|
|
53
|
-
* @param params.permit2Nonce -
|
|
54
|
-
*
|
|
55
|
-
*
|
|
50
|
+
* @param params.permit2Nonce - Deprecated and ignored.
|
|
51
|
+
* @returns Ordered deep-frozen approval transactions and/or signable token requirements;
|
|
52
|
+
* empty when the direct allowance already covers the amount, without probing permit support.
|
|
56
53
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
57
54
|
* another chain than `params.chainId`.
|
|
58
|
-
* @throws {NegativeInputError} when `amount`
|
|
55
|
+
* @throws {NegativeInputError} when `amount` is negative.
|
|
59
56
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
60
57
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
61
58
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
62
59
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
63
60
|
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
64
|
-
* @throws {
|
|
65
|
-
* was passed explicitly.
|
|
66
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
67
|
-
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
61
|
+
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
|
|
68
62
|
* @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
|
|
69
63
|
* undecodable data, or is out of range.
|
|
70
64
|
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
71
65
|
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
72
66
|
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
73
|
-
* @throws {viem.BaseError} when a required allowance,
|
|
74
|
-
* or `eth_chainId` read fails.
|
|
75
|
-
* only when the token reverts or returns undecodable data; other read failures propagate.
|
|
76
|
-
*
|
|
77
|
-
*
|
|
67
|
+
* @throws {viem.BaseError} when a required allowance, ERC-2612 metadata, DOMAIN_SEPARATOR,
|
|
68
|
+
* or `eth_chainId` read fails. Nonce and separator probes fall back to classic approval
|
|
69
|
+
* only when the token reverts or returns undecodable data; other read failures propagate.
|
|
70
|
+
* `MissingPermitDomainNameError`, `InvalidPermitDomainChainIdError`,
|
|
71
|
+
* `InvalidPermitDomainVerifyingContractError`, and `UnsupportedPermitDomainExtensionsError`
|
|
72
|
+
* are handled internally and fall back to approval.
|
|
78
73
|
* @example
|
|
79
74
|
* ```ts
|
|
80
75
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { erc2612Abi, isContractRevertError, isTransportError, isUndecodableResultError, MissingPermitDomainNameError,
|
|
2
|
+
import { erc2612Abi, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isContractRevertError, isTransportError, isUndecodableResultError, MissingPermitDomainNameError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { _try, isDefined, Time } from "@morpho-org/morpho-ts";
|
|
4
|
-
import { erc20Abi, isAddressEqual, maxUint256, } from "viem";
|
|
4
|
+
import { erc20Abi, getTypesForEIP712Domain, hashDomain, isAddressEqual, maxUint256, } from "viem";
|
|
5
5
|
import { readContract } from "viem/actions";
|
|
6
6
|
import { resolveBundlesTokenRequirements } from "../../actions/bundles/index.js";
|
|
7
7
|
import { encodeErc20Permit } from "../../actions/requirements/encode/encodeErc20Permit.js";
|
|
8
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
9
|
import { validateChainId, validateRequirementSpender, } from "../../helpers/index.js";
|
|
10
10
|
import { ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
11
|
-
import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
|
|
12
11
|
/**
|
|
13
|
-
* Resolves direct approval
|
|
14
|
-
* a registered fixed bundles contract.
|
|
12
|
+
* Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
|
|
15
13
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
|
|
20
|
-
* by default; concurrent flows for the same owner should pass explicit nonces.
|
|
14
|
+
* Reads the direct allowance first for nonzero amounts. Only when it is insufficient does
|
|
15
|
+
* the selected signature path try ERC-2612 nonce and metadata reads. A permit is returned only
|
|
16
|
+
* when the token's DOMAIN_SEPARATOR matches the domain to be signed; otherwise use approval.
|
|
21
17
|
*
|
|
22
18
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
23
19
|
* @param params - Token requirement parameters.
|
|
@@ -28,37 +24,35 @@ import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
|
|
|
28
24
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
29
25
|
* @param params.deadline - Final-call and signature deadline.
|
|
30
26
|
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
31
|
-
* @param params.supportSignature - Whether ERC-2612
|
|
27
|
+
* @param params.supportSignature - Whether ERC-2612 signatures may be requested.
|
|
32
28
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
33
|
-
* @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's
|
|
34
|
-
*
|
|
35
|
-
*
|
|
29
|
+
* @param params.useSimplePermit - Defaults to true when signatures are supported. Prefer ERC-2612 when `nonces()` succeeds and the token's
|
|
30
|
+
* DOMAIN_SEPARATOR matches the signing domain. Missing, mismatched, or unsupported domains,
|
|
31
|
+
* or recognized nonce/separator reverts or undecodable results, fall back to classic approval. A malformed
|
|
36
32
|
* `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
|
|
37
|
-
* @param params.permit2Nonce -
|
|
38
|
-
*
|
|
39
|
-
*
|
|
33
|
+
* @param params.permit2Nonce - Deprecated and ignored.
|
|
34
|
+
* @returns Ordered deep-frozen approval transactions and/or signable token requirements;
|
|
35
|
+
* empty when the direct allowance already covers the amount, without probing permit support.
|
|
40
36
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
41
37
|
* another chain than `params.chainId`.
|
|
42
|
-
* @throws {NegativeInputError} when `amount`
|
|
38
|
+
* @throws {NegativeInputError} when `amount` is negative.
|
|
43
39
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
44
40
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
45
41
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
46
42
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
47
43
|
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
48
|
-
* @throws {
|
|
49
|
-
* was passed explicitly.
|
|
50
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
51
|
-
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
44
|
+
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
|
|
52
45
|
* @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
|
|
53
46
|
* undecodable data, or is out of range.
|
|
54
47
|
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
55
48
|
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
56
49
|
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
57
|
-
* @throws {viem.BaseError} when a required allowance,
|
|
58
|
-
* or `eth_chainId` read fails.
|
|
59
|
-
* only when the token reverts or returns undecodable data; other read failures propagate.
|
|
60
|
-
*
|
|
61
|
-
*
|
|
50
|
+
* @throws {viem.BaseError} when a required allowance, ERC-2612 metadata, DOMAIN_SEPARATOR,
|
|
51
|
+
* or `eth_chainId` read fails. Nonce and separator probes fall back to classic approval
|
|
52
|
+
* only when the token reverts or returns undecodable data; other read failures propagate.
|
|
53
|
+
* `MissingPermitDomainNameError`, `InvalidPermitDomainChainIdError`,
|
|
54
|
+
* `InvalidPermitDomainVerifyingContractError`, and `UnsupportedPermitDomainExtensionsError`
|
|
55
|
+
* are handled internally and fall back to approval.
|
|
62
56
|
* @example
|
|
63
57
|
* ```ts
|
|
64
58
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
@@ -128,10 +122,10 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
128
122
|
});
|
|
129
123
|
if (allowance >= params.amount)
|
|
130
124
|
return [];
|
|
131
|
-
const {
|
|
125
|
+
const { dai } = getChainAddresses(params.chainId);
|
|
132
126
|
if (params.supportSignature) {
|
|
133
127
|
const isDai = isDefined(dai) && isAddressEqual(params.token, dai);
|
|
134
|
-
if (params.useSimplePermit && !isDai) {
|
|
128
|
+
if ((params.useSimplePermit ?? true) && !isDai) {
|
|
135
129
|
const nonce = await readContract(viemClient, {
|
|
136
130
|
abi: erc2612Abi,
|
|
137
131
|
address: params.token,
|
|
@@ -155,61 +149,29 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
155
149
|
deadline: params.deadline,
|
|
156
150
|
now: timestamp,
|
|
157
151
|
supportDeployless: params.supportDeployless,
|
|
158
|
-
}), MissingPermitDomainNameError);
|
|
159
|
-
if (isDefined(permit))
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
}), MissingPermitDomainNameError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, UnsupportedPermitDomainExtensionsError);
|
|
153
|
+
if (isDefined(permit)) {
|
|
154
|
+
const separator = await readContract(viemClient, {
|
|
155
|
+
abi: erc2612Abi,
|
|
156
|
+
address: params.token,
|
|
157
|
+
functionName: "DOMAIN_SEPARATOR",
|
|
158
|
+
}).catch((error) => {
|
|
159
|
+
if (isTransportError(error))
|
|
160
|
+
throw error;
|
|
161
|
+
if (isContractRevertError(error) || isUndecodableResultError(error))
|
|
162
|
+
return undefined;
|
|
163
|
+
throw error;
|
|
164
|
+
});
|
|
165
|
+
const domain = permit.action.typedData.domain ?? {};
|
|
166
|
+
if (separator?.toLowerCase() ===
|
|
167
|
+
hashDomain({
|
|
168
|
+
domain,
|
|
169
|
+
types: { EIP712Domain: getTypesForEIP712Domain({ domain }) },
|
|
170
|
+
}).toLowerCase())
|
|
171
|
+
return [permit];
|
|
172
|
+
}
|
|
164
173
|
}
|
|
165
174
|
}
|
|
166
|
-
if (permit2 != null) {
|
|
167
|
-
const permit2Nonce = params.permit2Nonce ??
|
|
168
|
-
(await getUnusedPermit2Nonce(viemClient, {
|
|
169
|
-
owner: params.owner,
|
|
170
|
-
chainId: params.chainId,
|
|
171
|
-
}));
|
|
172
|
-
if (permit2Nonce < 0n) {
|
|
173
|
-
throw new NegativeInputError("permit2Nonce", permit2Nonce);
|
|
174
|
-
}
|
|
175
|
-
if (permit2Nonce > maxUint256) {
|
|
176
|
-
throw new InputExceedsMaxError({
|
|
177
|
-
field: "permit2Nonce",
|
|
178
|
-
value: permit2Nonce,
|
|
179
|
-
max: maxUint256,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
const wordPosition = permit2Nonce >> 8n;
|
|
183
|
-
const [permit2Allowance, nonceBitmap] = await Promise.all([
|
|
184
|
-
readContract(viemClient, {
|
|
185
|
-
abi: erc20Abi,
|
|
186
|
-
address: params.token,
|
|
187
|
-
functionName: "allowance",
|
|
188
|
-
args: [params.owner, permit2],
|
|
189
|
-
}),
|
|
190
|
-
readContract(viemClient, {
|
|
191
|
-
abi: permit2Abi,
|
|
192
|
-
address: permit2,
|
|
193
|
-
functionName: "nonceBitmap",
|
|
194
|
-
args: [params.owner, wordPosition],
|
|
195
|
-
}),
|
|
196
|
-
]);
|
|
197
|
-
return resolveBundlesTokenRequirements({
|
|
198
|
-
token: params.token,
|
|
199
|
-
spender: params.spender,
|
|
200
|
-
owner: params.owner,
|
|
201
|
-
chainId: params.chainId,
|
|
202
|
-
amount: params.amount,
|
|
203
|
-
deadline: params.deadline,
|
|
204
|
-
now: timestamp,
|
|
205
|
-
state: {
|
|
206
|
-
type: "permit2SignatureTransfer",
|
|
207
|
-
permit2Allowance,
|
|
208
|
-
permit2Nonce,
|
|
209
|
-
nonceBitmap,
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
175
|
}
|
|
214
176
|
return resolveBundlesTokenRequirements({
|
|
215
177
|
token: params.token,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type Address, type Client } from "viem";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for {@link getUnusedPermit2Nonce}.
|
|
4
|
+
* @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
|
|
5
|
+
*/
|
|
3
6
|
export interface GetUnusedPermit2NonceParams {
|
|
4
7
|
/** Account that will sign the Permit2 SignatureTransfer. */
|
|
5
8
|
readonly owner: Address;
|
|
@@ -9,8 +12,7 @@ export interface GetUnusedPermit2NonceParams {
|
|
|
9
12
|
readonly startNonce?: bigint;
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
|
-
* Finds the lowest unused Permit2 unordered nonce for
|
|
13
|
-
* {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
|
|
15
|
+
* Finds the lowest unused Permit2 unordered nonce for legacy SignatureTransfer integrations.
|
|
14
16
|
*
|
|
15
17
|
* Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
|
|
16
18
|
* `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
|
|
@@ -45,5 +47,6 @@ export interface GetUnusedPermit2NonceParams {
|
|
|
45
47
|
* });
|
|
46
48
|
* // permit2Nonce satisfies bigint
|
|
47
49
|
* ```
|
|
50
|
+
* @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
|
|
48
51
|
*/
|
|
49
52
|
export declare const getUnusedPermit2Nonce: (viemClient: Client, params: GetUnusedPermit2NonceParams) => Promise<bigint>;
|
|
@@ -9,8 +9,7 @@ import { NoUnusedPermit2NonceError } from "../../types/index.js";
|
|
|
9
9
|
/** Highest Permit2 nonce-bitmap word index; each word covers 256 unordered nonces. */
|
|
10
10
|
const MAX_PERMIT2_NONCE_WORD = maxUint256 >> 8n;
|
|
11
11
|
/**
|
|
12
|
-
* Finds the lowest unused Permit2 unordered nonce for
|
|
13
|
-
* {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
|
|
12
|
+
* Finds the lowest unused Permit2 unordered nonce for legacy SignatureTransfer integrations.
|
|
14
13
|
*
|
|
15
14
|
* Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
|
|
16
15
|
* `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
|
|
@@ -45,6 +44,7 @@ const MAX_PERMIT2_NONCE_WORD = maxUint256 >> 8n;
|
|
|
45
44
|
* });
|
|
46
45
|
* // permit2Nonce satisfies bigint
|
|
47
46
|
* ```
|
|
47
|
+
* @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
|
|
48
48
|
*/
|
|
49
49
|
export const getUnusedPermit2Nonce = async (viemClient, params) => {
|
|
50
50
|
validateChainId(viemClient.chain?.id, params.chainId);
|
|
@@ -27,8 +27,8 @@ export interface VaultV1Actions {
|
|
|
27
27
|
* Prepares a Vault V1 deposit through the registered VaultBundlesV1 contract.
|
|
28
28
|
*
|
|
29
29
|
* Uses the supplied vault snapshot to compute the deadline-accrued `maxSharePrice`.
|
|
30
|
-
* `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612
|
|
31
|
-
*
|
|
30
|
+
* `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612
|
|
31
|
+
* nonce state. Native funding is exclusive and skips token requirements. Shares are
|
|
32
32
|
* always minted to the transaction sender, which must be `userAddress`.
|
|
33
33
|
* Concurrent requirement reads share the first caller's options; later calls refresh on-chain
|
|
34
34
|
* state using their own options.
|
|
@@ -53,19 +53,14 @@ export interface VaultV1Actions {
|
|
|
53
53
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
54
54
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
55
55
|
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
56
|
-
* @throws {NegativeInputError} when funding, slippage, the referral fee
|
|
56
|
+
* @throws {NegativeInputError} when funding, slippage, or the referral fee is negative.
|
|
57
57
|
* @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
|
|
58
58
|
* @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
|
|
59
59
|
* @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
|
|
60
60
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
61
61
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
62
62
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
63
|
-
* @throws {
|
|
64
|
-
* owner is consumed and none was passed explicitly.
|
|
65
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
66
|
-
* explicit Permit2 nonce is consumed.
|
|
67
|
-
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
68
|
-
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
63
|
+
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256.
|
|
69
64
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
70
65
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
71
66
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
@@ -481,8 +476,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
481
476
|
* before any other requirement read. This VaultV1 `inKindRedeem` path validates the client chain
|
|
482
477
|
* before this code check.
|
|
483
478
|
*
|
|
484
|
-
* @param roles - Registry labels to resolve and check
|
|
485
|
-
* chain registers none.
|
|
479
|
+
* @param roles - Registry labels to resolve and check.
|
|
486
480
|
*/
|
|
487
481
|
private assertWriteTargets;
|
|
488
482
|
/** {@inheritDoc VaultV1Actions.deposit} */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, MarketUtils, MathLib, Token, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
-
import { getChainAddress,
|
|
3
|
+
import { getChainAddress, Time, } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { readContract } from "viem/actions";
|
|
6
6
|
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
@@ -36,17 +36,12 @@ export class MorphoVaultV1 {
|
|
|
36
36
|
* before any other requirement read. This VaultV1 `inKindRedeem` path validates the client chain
|
|
37
37
|
* before this code check.
|
|
38
38
|
*
|
|
39
|
-
* @param roles - Registry labels to resolve and check
|
|
40
|
-
* chain registers none.
|
|
39
|
+
* @param roles - Registry labels to resolve and check.
|
|
41
40
|
*/
|
|
42
41
|
async assertWriteTargets(roles) {
|
|
43
42
|
const targets = [];
|
|
44
43
|
for (const role of roles) {
|
|
45
|
-
const address = role
|
|
46
|
-
? getChainAddresses(this.chainId).permit2
|
|
47
|
-
: getChainAddress(this.chainId, role);
|
|
48
|
-
if (address == null)
|
|
49
|
-
continue;
|
|
44
|
+
const address = getChainAddress(this.chainId, role);
|
|
50
45
|
targets.push({ role, address });
|
|
51
46
|
}
|
|
52
47
|
await assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets);
|
|
@@ -94,9 +89,7 @@ export class MorphoVaultV1 {
|
|
|
94
89
|
// Memoize the in-flight promise so concurrent callers share one round of
|
|
95
90
|
// allowance/nonce reads.
|
|
96
91
|
const pending = (async () => {
|
|
97
|
-
await this.assertWriteTargets(
|
|
98
|
-
? ["bundles.vaultBundlesV1", "permit2"]
|
|
99
|
-
: ["bundles.vaultBundlesV1"]);
|
|
92
|
+
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
100
93
|
return funding.value > 0n
|
|
101
94
|
? []
|
|
102
95
|
: getBundlesTokenRequirements(this.client.viemClient, {
|
|
@@ -109,7 +102,6 @@ export class MorphoVaultV1 {
|
|
|
109
102
|
supportSignature: this.client.options.supportSignature,
|
|
110
103
|
supportDeployless: this.client.options.supportDeployless,
|
|
111
104
|
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
112
|
-
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
113
105
|
now,
|
|
114
106
|
});
|
|
115
107
|
})();
|
|
@@ -32,8 +32,8 @@ export interface VaultV2Actions {
|
|
|
32
32
|
* Prepares a Vault V2 deposit through the registered VaultBundlesV1 contract.
|
|
33
33
|
*
|
|
34
34
|
* Uses the supplied vault snapshot to compute the deadline-accrued `maxSharePrice`.
|
|
35
|
-
* `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612
|
|
36
|
-
*
|
|
35
|
+
* `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612
|
|
36
|
+
* nonce state. Native funding is exclusive and skips token requirements. Shares are
|
|
37
37
|
* always minted to the transaction sender, which must be `userAddress`.
|
|
38
38
|
* Concurrent requirement reads share the first caller's options; later calls refresh on-chain
|
|
39
39
|
* state using their own options.
|
|
@@ -58,19 +58,14 @@ export interface VaultV2Actions {
|
|
|
58
58
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
59
59
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
60
60
|
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
61
|
-
* @throws {NegativeInputError} when funding, slippage, the referral fee
|
|
61
|
+
* @throws {NegativeInputError} when funding, slippage, or the referral fee is negative.
|
|
62
62
|
* @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
|
|
63
63
|
* @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
|
|
64
64
|
* @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
|
|
65
65
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
66
66
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
67
67
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
68
|
-
* @throws {
|
|
69
|
-
* owner is consumed and none was passed explicitly.
|
|
70
|
-
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
71
|
-
* explicit Permit2 nonce is consumed.
|
|
72
|
-
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
73
|
-
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
68
|
+
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256.
|
|
74
69
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
75
70
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
76
71
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
@@ -555,8 +550,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
555
550
|
* before any other requirement read. The `inKindRedeem` and `forceWithdraw` paths validate the
|
|
556
551
|
* client chain before this code check.
|
|
557
552
|
*
|
|
558
|
-
* @param roles - Registry labels to resolve and check
|
|
559
|
-
* chain registers none.
|
|
553
|
+
* @param roles - Registry labels to resolve and check.
|
|
560
554
|
*/
|
|
561
555
|
private assertWriteTargets;
|
|
562
556
|
/** {@inheritDoc VaultV2Actions.deposit} */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AccrualVaultV2MorphoMarketV1AdapterV2, DEFAULT_SLIPPAGE_TOLERANCE, MarketParams, MarketUtils, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { erc2612Abi, fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
|
-
import { _try, getChainAddress,
|
|
3
|
+
import { _try, getChainAddress, Time, } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { readContract } from "viem/actions";
|
|
6
6
|
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
@@ -39,17 +39,12 @@ export class MorphoVaultV2 {
|
|
|
39
39
|
* before any other requirement read. The `inKindRedeem` and `forceWithdraw` paths validate the
|
|
40
40
|
* client chain before this code check.
|
|
41
41
|
*
|
|
42
|
-
* @param roles - Registry labels to resolve and check
|
|
43
|
-
* chain registers none.
|
|
42
|
+
* @param roles - Registry labels to resolve and check.
|
|
44
43
|
*/
|
|
45
44
|
async assertWriteTargets(roles) {
|
|
46
45
|
const targets = [];
|
|
47
46
|
for (const role of roles) {
|
|
48
|
-
const address = role
|
|
49
|
-
? getChainAddresses(this.chainId).permit2
|
|
50
|
-
: getChainAddress(this.chainId, role);
|
|
51
|
-
if (address == null)
|
|
52
|
-
continue;
|
|
47
|
+
const address = getChainAddress(this.chainId, role);
|
|
53
48
|
targets.push({ role, address });
|
|
54
49
|
}
|
|
55
50
|
await assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets);
|
|
@@ -97,9 +92,7 @@ export class MorphoVaultV2 {
|
|
|
97
92
|
// Memoize the in-flight promise so concurrent callers share one round of
|
|
98
93
|
// allowance/nonce reads.
|
|
99
94
|
const pending = (async () => {
|
|
100
|
-
await this.assertWriteTargets(
|
|
101
|
-
? ["bundles.vaultBundlesV1", "permit2"]
|
|
102
|
-
: ["bundles.vaultBundlesV1"]);
|
|
95
|
+
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
103
96
|
return funding.value > 0n
|
|
104
97
|
? []
|
|
105
98
|
: getBundlesTokenRequirements(this.client.viemClient, {
|
|
@@ -112,7 +105,6 @@ export class MorphoVaultV2 {
|
|
|
112
105
|
supportSignature: this.client.options.supportSignature,
|
|
113
106
|
supportDeployless: this.client.options.supportDeployless,
|
|
114
107
|
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
115
|
-
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
116
108
|
now,
|
|
117
109
|
});
|
|
118
110
|
})();
|
|
@@ -450,6 +450,9 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
450
450
|
* Full-liquidity discovery omits a candidate when its non-shared maximum
|
|
451
451
|
* violates a shared cap instead of scanning smaller base-unit amounts. These
|
|
452
452
|
* bounds can understate executable liquidity in rounding-only edge cases.
|
|
453
|
+
* With an explicit Blue balance, a paid operation may retry the same search
|
|
454
|
+
* from a physical-funding budget and keep a strictly cheaper feasible plan.
|
|
455
|
+
* This bounded refinement does not guarantee globally minimal penalties.
|
|
453
456
|
*
|
|
454
457
|
* @param marketId - Target Blue market id.
|
|
455
458
|
* @param options - Optional discovery controls and operation to support.
|