@morpho-org/morpho-sdk 7.1.0-next.1 → 8.2.0-next.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-v7-to-v8.md +290 -0
- package/README.md +11 -6
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +17 -71
- package/lib/cjs/actions/midnight/cancelAndMake.js +41 -29
- package/lib/cjs/actions/midnight/redeem.d.ts +8 -1
- package/lib/cjs/actions/midnight/redeem.js +18 -1
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +24 -2
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/supplyCollateral.js +3 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +49 -14
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +18 -5
- package/lib/cjs/actions/midnight/takeBorrow.js +44 -12
- package/lib/cjs/actions/midnight/takeLend.d.ts +10 -5
- package/lib/cjs/actions/midnight/takeLend.js +27 -9
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +51 -27
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +14 -5
- package/lib/cjs/actions/midnight/takeWithdraw.js +40 -9
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +17 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
- package/lib/cjs/actions/requirements/validateClientChainId.d.ts +26 -0
- package/lib/cjs/actions/requirements/validateClientChainId.js +34 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +3 -1
- package/lib/cjs/blue/types.d.ts +1 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +5 -1
- package/lib/cjs/entities/blue/blue.d.ts +109 -27
- package/lib/cjs/entities/blue/blue.js +103 -28
- package/lib/cjs/entities/index.d.ts +1 -1
- package/lib/cjs/entities/midnight/deadline.d.ts +15 -0
- package/lib/cjs/entities/midnight/deadline.js +24 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +427 -72
- package/lib/cjs/entities/midnight/midnight.js +864 -186
- package/lib/cjs/entities/midnight/publication.d.ts +134 -0
- package/lib/cjs/entities/midnight/publication.js +404 -0
- package/lib/cjs/entities/midnight/types.d.ts +26 -5
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +49 -0
- package/lib/cjs/entities/requirements/assertContractCode.js +79 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +45 -18
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +5 -2
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +63 -11
- package/lib/cjs/entities/vaultV1/vaultV1.js +52 -15
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +54 -12
- package/lib/cjs/entities/vaultV2/vaultV2.js +52 -15
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +12 -6
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +42 -14
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +4 -2
- package/lib/cjs/helpers/constant.d.ts +5 -0
- package/lib/cjs/helpers/constant.js +6 -1
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/validate.d.ts +163 -8
- package/lib/cjs/helpers/validate.js +179 -8
- package/lib/cjs/helpers/validateMidnightBounds.d.ts +47 -0
- package/lib/cjs/helpers/validateMidnightBounds.js +79 -0
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +12 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +144 -0
- package/lib/cjs/helpers/validateMidnightReceiver.d.ts +29 -0
- package/lib/cjs/helpers/validateMidnightReceiver.js +84 -0
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +231 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +3 -0
- package/lib/cjs/types/error.d.ts +197 -4
- package/lib/cjs/types/error.js +265 -5
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/midnightCancelAndMake.d.ts +70 -0
- package/lib/cjs/types/midnightCancelAndMake.js +2 -0
- package/lib/cjs/types/midnightPublicationError.d.ts +332 -0
- package/lib/cjs/types/midnightPublicationError.js +376 -0
- package/lib/cjs/types/sharedLiquidity.d.ts +12 -7
- package/lib/cjs/types.d.ts +1 -1
- package/lib/cjs/utils.d.ts +2 -1
- package/lib/cjs/utils.js +8 -2
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +17 -71
- package/lib/esm/actions/midnight/cancelAndMake.js +42 -30
- package/lib/esm/actions/midnight/redeem.d.ts +8 -1
- package/lib/esm/actions/midnight/redeem.js +18 -1
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +24 -2
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/supplyCollateral.js +3 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +52 -17
- package/lib/esm/actions/midnight/takeBorrow.d.ts +18 -5
- package/lib/esm/actions/midnight/takeBorrow.js +47 -15
- package/lib/esm/actions/midnight/takeLend.d.ts +10 -5
- package/lib/esm/actions/midnight/takeLend.js +27 -9
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +52 -28
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +14 -5
- package/lib/esm/actions/midnight/takeWithdraw.js +41 -10
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +13 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +17 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
- package/lib/esm/actions/requirements/validateClientChainId.d.ts +26 -0
- package/lib/esm/actions/requirements/validateClientChainId.js +30 -0
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/blue/types.d.ts +1 -1
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +109 -27
- package/lib/esm/entities/blue/blue.js +104 -29
- package/lib/esm/entities/index.d.ts +1 -1
- package/lib/esm/entities/midnight/deadline.d.ts +15 -0
- package/lib/esm/entities/midnight/deadline.js +20 -0
- package/lib/esm/entities/midnight/midnight.d.ts +427 -72
- package/lib/esm/entities/midnight/midnight.js +865 -187
- package/lib/esm/entities/midnight/publication.d.ts +134 -0
- package/lib/esm/entities/midnight/publication.js +397 -0
- package/lib/esm/entities/midnight/types.d.ts +26 -5
- package/lib/esm/entities/requirements/assertContractCode.d.ts +49 -0
- package/lib/esm/entities/requirements/assertContractCode.js +74 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +47 -20
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +5 -2
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +63 -11
- package/lib/esm/entities/vaultV1/vaultV1.js +53 -16
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +54 -12
- package/lib/esm/entities/vaultV2/vaultV2.js +53 -16
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +12 -6
- package/lib/esm/entities/vaultV2BlueReallocationData.js +42 -14
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/helpers/constant.d.ts +5 -0
- package/lib/esm/helpers/constant.js +5 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +163 -8
- package/lib/esm/helpers/validate.js +177 -7
- package/lib/esm/helpers/validateMidnightBounds.d.ts +47 -0
- package/lib/esm/helpers/validateMidnightBounds.js +72 -0
- package/lib/esm/helpers/validateMidnightPublication.d.ts +12 -0
- package/lib/esm/helpers/validateMidnightPublication.js +139 -0
- package/lib/esm/helpers/validateMidnightReceiver.d.ts +29 -0
- package/lib/esm/helpers/validateMidnightReceiver.js +80 -0
- package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +226 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/error.d.ts +197 -4
- package/lib/esm/types/error.js +253 -2
- package/lib/esm/types/index.d.ts +1 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/midnightCancelAndMake.d.ts +70 -0
- package/lib/esm/types/midnightCancelAndMake.js +1 -0
- package/lib/esm/types/midnightPublicationError.d.ts +332 -0
- package/lib/esm/types/midnightPublicationError.js +359 -0
- package/lib/esm/types/sharedLiquidity.d.ts +12 -7
- package/lib/esm/types.d.ts +1 -1
- package/lib/esm/utils.d.ts +2 -1
- package/lib/esm/utils.js +2 -1
- package/package.json +7 -6
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getBytecode } from "viem/actions";
|
|
2
|
+
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
3
|
+
import { ChainIdMismatchError, MissingContractCodeError, } from "../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Asserts that a configured contract address holds deployed code on the client's chain.
|
|
6
|
+
*
|
|
7
|
+
* A call to a code-less address succeeds on-chain as a no-op, so entity flows check each
|
|
8
|
+
* registered target before returning requirements. The `eth_getCode` read runs at the
|
|
9
|
+
* client's default block; transport failures propagate unwrapped because they are
|
|
10
|
+
* infrastructure failures, not configuration failures.
|
|
11
|
+
*
|
|
12
|
+
* @param client - Connected viem client used for the `eth_getCode` read.
|
|
13
|
+
* @param params - Assertion parameters.
|
|
14
|
+
* @param params.address - Contract address expected to hold code.
|
|
15
|
+
* @param params.chainId - Chain id the flow targets, reported on the error.
|
|
16
|
+
* @param params.role - Registry label naming the address's role in the flow.
|
|
17
|
+
* @returns Nothing when the address holds code.
|
|
18
|
+
* @throws {MissingContractCodeError} when the address has no deployed bytecode.
|
|
19
|
+
* @throws {viem.BaseError} when the `eth_getCode` read itself fails.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export const assertContractCode = async (client, params) => {
|
|
23
|
+
const bytecode = await getBytecode(client, { address: params.address });
|
|
24
|
+
if (bytecode === undefined || bytecode === "0x") {
|
|
25
|
+
throw new MissingContractCodeError(params.address, params.chainId, params.role);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Asserts that each distinct target in a flow's write-surface list holds code.
|
|
30
|
+
*
|
|
31
|
+
* One `eth_getCode` per distinct address runs before any other requirement read.
|
|
32
|
+
* A wrong-chain RPC reports no code at every target, so on the first
|
|
33
|
+
* {@link MissingContractCodeError} a single `eth_chainId` probe decides: a served
|
|
34
|
+
* chain mismatch surfaces as {@link ChainIdMismatchError} (never as missing
|
|
35
|
+
* code), a failed probe keeps the original missing-code error, and a matching
|
|
36
|
+
* chain rethrows it unchanged. Other assertion errors propagate unwrapped.
|
|
37
|
+
*
|
|
38
|
+
* @param client - Connected viem client used for the `eth_getCode` reads.
|
|
39
|
+
* @param chainId - Chain id the flow targets, reported on the errors.
|
|
40
|
+
* @param targets - Distinct-by-address targets to check, in reporting order.
|
|
41
|
+
* @returns Nothing when every target holds code.
|
|
42
|
+
* @throws {MissingContractCodeError} when a target has no deployed bytecode on
|
|
43
|
+
* the endpoint's chain.
|
|
44
|
+
* @throws {ChainIdMismatchError} when the endpoint serves another chain id.
|
|
45
|
+
* @throws {viem.BaseError} when an `eth_getCode` read itself fails.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
// biome-ignore lint/complexity/useMaxParams: positional (client, chainId, targets) signature
|
|
49
|
+
export const assertRegistryTargetsHaveCode = async (client, chainId, targets) => {
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
for (const target of targets) {
|
|
52
|
+
if (seen.has(target.address))
|
|
53
|
+
continue;
|
|
54
|
+
seen.add(target.address);
|
|
55
|
+
try {
|
|
56
|
+
await assertContractCode(client, {
|
|
57
|
+
address: target.address,
|
|
58
|
+
chainId,
|
|
59
|
+
role: target.role,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (!(error instanceof MissingContractCodeError))
|
|
64
|
+
throw error;
|
|
65
|
+
try {
|
|
66
|
+
await validateClientChainId(client, chainId);
|
|
67
|
+
}
|
|
68
|
+
catch (probeError) {
|
|
69
|
+
throw probeError instanceof ChainIdMismatchError ? probeError : error;
|
|
70
|
+
}
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
@@ -24,6 +24,8 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
24
24
|
readonly useSimplePermit?: boolean;
|
|
25
25
|
/** Explicit unused uint256 nonce; defaults to the lowest unused nonce found via getUnusedPermit2Nonce. */
|
|
26
26
|
readonly permit2Nonce?: bigint;
|
|
27
|
+
/** Timestamp the deadline is validated against; defaults to the current time. */
|
|
28
|
+
readonly now?: bigint;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
@@ -43,13 +45,18 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
43
45
|
* @param params.owner - Account funding the operation.
|
|
44
46
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
45
47
|
* @param params.deadline - Final-call and signature deadline.
|
|
48
|
+
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
46
49
|
* @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
|
|
47
50
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
48
|
-
* @param params.useSimplePermit - Prefer ERC-2612 when
|
|
51
|
+
* @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's permit
|
|
52
|
+
* domain is known; a recognized `nonces()` revert or undecodable result, or a missing domain
|
|
53
|
+
* (no `name()` and no EIP-5267 domain), falls back to Permit2 or classic approval. A malformed
|
|
54
|
+
* `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
|
|
49
55
|
* @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
|
|
50
56
|
* found via {@link getUnusedPermit2Nonce}.
|
|
51
57
|
* @returns Ordered deep-frozen approval transactions and/or signable token requirements.
|
|
52
|
-
* @throws {ChainIdMismatchError} when the
|
|
58
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
59
|
+
* another chain than `params.chainId`.
|
|
53
60
|
* @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
|
|
54
61
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
55
62
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
@@ -61,8 +68,16 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
61
68
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
62
69
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
63
70
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
64
|
-
* @throws {
|
|
65
|
-
*
|
|
71
|
+
* @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
|
|
72
|
+
* undecodable data, or is out of range.
|
|
73
|
+
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
74
|
+
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
75
|
+
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
76
|
+
* @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, ERC-2612 metadata,
|
|
77
|
+
* or `eth_chainId` read fails. An ERC-2612 nonce probe falls back to Permit2 or classic approval
|
|
78
|
+
* only when the token reverts or returns undecodable data; other read failures propagate. A
|
|
79
|
+
* missing permit domain is handled internally and also falls back; this function does not
|
|
80
|
+
* surface `MissingPermitDomainNameError`.
|
|
66
81
|
* @example
|
|
67
82
|
* ```ts
|
|
68
83
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { erc2612Abi, permit2Abi } from "@morpho-org/blue-sdk-viem";
|
|
3
|
-
import { isDefined, Time } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { erc2612Abi, isContractRevertError, isTransportError, isUndecodableResultError, MissingPermitDomainNameError, permit2Abi, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
import { _try, isDefined, Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, 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
|
+
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
8
9
|
import { validateChainId, validateRequirementSpender, } from "../../helpers/index.js";
|
|
9
10
|
import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
10
11
|
import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
|
|
@@ -26,13 +27,18 @@ import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
|
|
|
26
27
|
* @param params.owner - Account funding the operation.
|
|
27
28
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
28
29
|
* @param params.deadline - Final-call and signature deadline.
|
|
30
|
+
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
29
31
|
* @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
|
|
30
32
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
31
|
-
* @param params.useSimplePermit - Prefer ERC-2612 when
|
|
33
|
+
* @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's permit
|
|
34
|
+
* domain is known; a recognized `nonces()` revert or undecodable result, or a missing domain
|
|
35
|
+
* (no `name()` and no EIP-5267 domain), falls back to Permit2 or classic approval. A malformed
|
|
36
|
+
* `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
|
|
32
37
|
* @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
|
|
33
38
|
* found via {@link getUnusedPermit2Nonce}.
|
|
34
39
|
* @returns Ordered deep-frozen approval transactions and/or signable token requirements.
|
|
35
|
-
* @throws {ChainIdMismatchError} when the
|
|
40
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
41
|
+
* another chain than `params.chainId`.
|
|
36
42
|
* @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
|
|
37
43
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
38
44
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
@@ -44,8 +50,16 @@ import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
|
|
|
44
50
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
45
51
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
46
52
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
47
|
-
* @throws {
|
|
48
|
-
*
|
|
53
|
+
* @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
|
|
54
|
+
* undecodable data, or is out of range.
|
|
55
|
+
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
56
|
+
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
57
|
+
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
58
|
+
* @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, ERC-2612 metadata,
|
|
59
|
+
* or `eth_chainId` read fails. An ERC-2612 nonce probe falls back to Permit2 or classic approval
|
|
60
|
+
* only when the token reverts or returns undecodable data; other read failures propagate. A
|
|
61
|
+
* missing permit domain is handled internally and also falls back; this function does not
|
|
62
|
+
* surface `MissingPermitDomainNameError`.
|
|
49
63
|
* @example
|
|
50
64
|
* ```ts
|
|
51
65
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
@@ -100,12 +114,13 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
100
114
|
// Reject an already-expired deadline before the RPC reads so a direct caller of this resolver
|
|
101
115
|
// never signs a permit for a supply the BlueBundlesV1 call would revert. The entity validates
|
|
102
116
|
// this too, but the exported resolver must guard its own callers.
|
|
103
|
-
const timestamp = Time.timestamp();
|
|
117
|
+
const timestamp = params.now ?? Time.timestamp();
|
|
104
118
|
if (params.deadline <= timestamp) {
|
|
105
119
|
throw new ExpiredDeadlineError(params.deadline, timestamp);
|
|
106
120
|
}
|
|
107
121
|
if (params.amount === 0n)
|
|
108
122
|
return [];
|
|
123
|
+
await validateClientChainId(viemClient, params.chainId);
|
|
109
124
|
const { permit2, dai } = getChainAddresses(params.chainId);
|
|
110
125
|
if (params.supportSignature) {
|
|
111
126
|
const isDai = isDefined(dai) && isAddressEqual(params.token, dai);
|
|
@@ -115,20 +130,30 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
115
130
|
address: params.token,
|
|
116
131
|
functionName: "nonces",
|
|
117
132
|
args: [params.owner],
|
|
118
|
-
}).catch(() =>
|
|
133
|
+
}).catch((error) => {
|
|
134
|
+
if (isTransportError(error))
|
|
135
|
+
throw error;
|
|
136
|
+
if (isContractRevertError(error) || isUndecodableResultError(error))
|
|
137
|
+
return undefined;
|
|
138
|
+
throw error;
|
|
139
|
+
});
|
|
119
140
|
if (isDefined(nonce)) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
const permit = await _try(() => encodeErc20Permit(viemClient, {
|
|
142
|
+
token: params.token,
|
|
143
|
+
owner: params.owner,
|
|
144
|
+
spender: params.spender,
|
|
145
|
+
amount: params.amount,
|
|
146
|
+
chainId: params.chainId,
|
|
147
|
+
nonce,
|
|
148
|
+
deadline: params.deadline,
|
|
149
|
+
now: timestamp,
|
|
150
|
+
supportDeployless: params.supportDeployless,
|
|
151
|
+
}), MissingPermitDomainNameError);
|
|
152
|
+
if (isDefined(permit))
|
|
153
|
+
return [permit];
|
|
154
|
+
// A token that exposes nonces() but has neither name() nor
|
|
155
|
+
// eip712Domain() cannot be permitted over a known domain: fall
|
|
156
|
+
// through to the Permit2/classic-approval path.
|
|
132
157
|
}
|
|
133
158
|
}
|
|
134
159
|
if (permit2 != null) {
|
|
@@ -169,6 +194,7 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
169
194
|
chainId: params.chainId,
|
|
170
195
|
amount: params.amount,
|
|
171
196
|
deadline: params.deadline,
|
|
197
|
+
now: timestamp,
|
|
172
198
|
state: {
|
|
173
199
|
type: "permit2SignatureTransfer",
|
|
174
200
|
permit2Allowance: allowance,
|
|
@@ -195,6 +221,7 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
195
221
|
chainId: params.chainId,
|
|
196
222
|
amount: params.amount,
|
|
197
223
|
deadline: params.deadline,
|
|
224
|
+
now: timestamp,
|
|
198
225
|
state: {
|
|
199
226
|
type: "approval",
|
|
200
227
|
allowance,
|
|
@@ -24,12 +24,13 @@ export interface GetUnusedPermit2NonceParams {
|
|
|
24
24
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
25
25
|
* @param params.startNonce - Lowest nonce to consider; defaults to 0.
|
|
26
26
|
* @returns The lowest unused Permit2 nonce at or after `startNonce`.
|
|
27
|
-
* @throws {ChainIdMismatchError} when the
|
|
27
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
28
|
+
* another chain than `params.chainId`.
|
|
28
29
|
* @throws {NegativeInputError} when `startNonce` is negative.
|
|
29
30
|
* @throws {InputExceedsMaxError} when `startNonce` exceeds `uint256`.
|
|
30
31
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
31
32
|
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
32
|
-
* @throws {viem.BaseError} when a Permit2 nonce-bitmap RPC read fails.
|
|
33
|
+
* @throws {viem.BaseError} when a Permit2 nonce-bitmap or `eth_chainId` RPC read fails.
|
|
33
34
|
* @throws {NoUnusedPermit2NonceError} when every nonce at or after `startNonce` is consumed.
|
|
34
35
|
* @example
|
|
35
36
|
* ```ts
|
|
@@ -2,6 +2,7 @@ import { permit2Abi } from "@morpho-org/blue-sdk-viem";
|
|
|
2
2
|
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { readContract } from "viem/actions";
|
|
5
|
+
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
5
6
|
import { validateChainId } from "../../helpers/index.js";
|
|
6
7
|
import { validateUint256Field } from "../../helpers/validate.js";
|
|
7
8
|
import { NoUnusedPermit2NonceError } from "../../types/index.js";
|
|
@@ -23,12 +24,13 @@ const MAX_PERMIT2_NONCE_WORD = maxUint256 >> 8n;
|
|
|
23
24
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
24
25
|
* @param params.startNonce - Lowest nonce to consider; defaults to 0.
|
|
25
26
|
* @returns The lowest unused Permit2 nonce at or after `startNonce`.
|
|
26
|
-
* @throws {ChainIdMismatchError} when the
|
|
27
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
28
|
+
* another chain than `params.chainId`.
|
|
27
29
|
* @throws {NegativeInputError} when `startNonce` is negative.
|
|
28
30
|
* @throws {InputExceedsMaxError} when `startNonce` exceeds `uint256`.
|
|
29
31
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
30
32
|
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
31
|
-
* @throws {viem.BaseError} when a Permit2 nonce-bitmap RPC read fails.
|
|
33
|
+
* @throws {viem.BaseError} when a Permit2 nonce-bitmap or `eth_chainId` RPC read fails.
|
|
32
34
|
* @throws {NoUnusedPermit2NonceError} when every nonce at or after `startNonce` is consumed.
|
|
33
35
|
* @example
|
|
34
36
|
* ```ts
|
|
@@ -48,6 +50,7 @@ export const getUnusedPermit2Nonce = async (viemClient, params) => {
|
|
|
48
50
|
validateChainId(viemClient.chain?.id, params.chainId);
|
|
49
51
|
const startNonce = params.startNonce ?? 0n;
|
|
50
52
|
validateUint256Field("startNonce", startNonce);
|
|
53
|
+
await validateClientChainId(viemClient, params.chainId);
|
|
51
54
|
const permit2 = getChainAddress(params.chainId, "permit2");
|
|
52
55
|
const startWord = startNonce >> 8n;
|
|
53
56
|
for (let word = startWord; word <= MAX_PERMIT2_NONCE_WORD; word++) {
|
|
@@ -16,12 +16,15 @@ import { type ActionRequirement } from "../../types/index.js";
|
|
|
16
16
|
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
17
17
|
* @param params - Vault snapshot, owner, allowance bounds, and deadline values. `maxShareAllowance`
|
|
18
18
|
* defaults to `requiredShareAllowance`, which accepts only an exact match.
|
|
19
|
+
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
19
20
|
* @returns No requirement when the allowance is within `[requiredShareAllowance,
|
|
20
21
|
* maxShareAllowance]`, otherwise one
|
|
21
22
|
* approval that sets it to exactly that cap, or one permit when the allowance is below the cap
|
|
22
23
|
* and signatures are supported.
|
|
24
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
25
|
+
* another chain than `params.chainId`.
|
|
23
26
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
24
|
-
* @throws {viem.BaseError} when an allowance
|
|
27
|
+
* @throws {viem.BaseError} when an allowance, permit nonce, or `eth_chainId` read fails.
|
|
25
28
|
*/
|
|
26
29
|
export declare const getVaultBundlesSharesRequirements: (viemClient: Client, params: {
|
|
27
30
|
readonly vaultData: Token;
|
|
@@ -32,4 +35,5 @@ export declare const getVaultBundlesSharesRequirements: (viemClient: Client, par
|
|
|
32
35
|
readonly maxShareAllowance?: bigint;
|
|
33
36
|
readonly deadline: bigint;
|
|
34
37
|
readonly supportSignature: boolean;
|
|
38
|
+
readonly now?: bigint;
|
|
35
39
|
}) => Promise<readonly ActionRequirement[]>;
|
|
@@ -3,6 +3,7 @@ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
|
3
3
|
import { erc20Abi } from "viem";
|
|
4
4
|
import { readContract } from "viem/actions";
|
|
5
5
|
import { encodeErc20Approval, encodeVaultSharesPermit, } from "../../actions/index.js";
|
|
6
|
+
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
6
7
|
import { validateChainId } from "../../helpers/index.js";
|
|
7
8
|
import { ExpiredDeadlineError, } from "../../types/index.js";
|
|
8
9
|
/**
|
|
@@ -20,19 +21,23 @@ import { ExpiredDeadlineError, } from "../../types/index.js";
|
|
|
20
21
|
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
21
22
|
* @param params - Vault snapshot, owner, allowance bounds, and deadline values. `maxShareAllowance`
|
|
22
23
|
* defaults to `requiredShareAllowance`, which accepts only an exact match.
|
|
24
|
+
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
23
25
|
* @returns No requirement when the allowance is within `[requiredShareAllowance,
|
|
24
26
|
* maxShareAllowance]`, otherwise one
|
|
25
27
|
* approval that sets it to exactly that cap, or one permit when the allowance is below the cap
|
|
26
28
|
* and signatures are supported.
|
|
29
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
30
|
+
* another chain than `params.chainId`.
|
|
27
31
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
28
|
-
* @throws {viem.BaseError} when an allowance
|
|
32
|
+
* @throws {viem.BaseError} when an allowance, permit nonce, or `eth_chainId` read fails.
|
|
29
33
|
*/
|
|
30
34
|
export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
31
35
|
validateChainId(viemClient.chain?.id, params.chainId);
|
|
32
|
-
const now = Time.timestamp();
|
|
36
|
+
const now = params.now ?? Time.timestamp();
|
|
33
37
|
if (params.deadline <= now) {
|
|
34
38
|
throw new ExpiredDeadlineError(params.deadline, now);
|
|
35
39
|
}
|
|
40
|
+
await validateClientChainId(viemClient, params.chainId);
|
|
36
41
|
const spender = getChainAddress(params.chainId, "bundles.vaultBundlesV1");
|
|
37
42
|
// The allowance is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
|
|
38
43
|
const allowance = await readContract(viemClient, {
|
|
@@ -63,6 +68,7 @@ export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
|
63
68
|
nonce,
|
|
64
69
|
amount: params.requiredShareAllowance,
|
|
65
70
|
deadline: params.deadline,
|
|
71
|
+
now,
|
|
66
72
|
}),
|
|
67
73
|
];
|
|
68
74
|
}
|
|
@@ -12,10 +12,15 @@ export interface VaultV1Actions {
|
|
|
12
12
|
*
|
|
13
13
|
* @param parameters - Optional viem fetch parameters (block number, block tag, state override).
|
|
14
14
|
* @returns The hydrated `AccrualVault` snapshot.
|
|
15
|
-
* @throws {ChainIdMismatchError} when the connected client
|
|
15
|
+
* @throws {ChainIdMismatchError} when the connected client declares another chain or none, or its RPC reports another chain via `eth_chainId`.
|
|
16
|
+
* @throws {viem.BaseError} when the `eth_chainId` request or a state read fails.
|
|
16
17
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
17
18
|
* @throws {UnknownBlueFactory} when the configured chain has no MetaMorpho factory.
|
|
18
19
|
* @throws {UnknownBlueOfFactory} when the vault is not a MetaMorpho vault from the configured factory.
|
|
20
|
+
* @throws {UnknownTokenError} when the vault's share token has unusable decimals.
|
|
21
|
+
* @throws {MalformedTokenMetadataError} when the share token's `eip712Domain()` or
|
|
22
|
+
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
23
|
+
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
19
24
|
*/
|
|
20
25
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
|
|
21
26
|
/**
|
|
@@ -42,7 +47,8 @@ export interface VaultV1Actions {
|
|
|
42
47
|
* two hours from handle creation.
|
|
43
48
|
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
|
|
44
49
|
* transaction builder.
|
|
45
|
-
* @throws {ChainIdMismatchError} when the connected client targets another chain
|
|
50
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain, or from
|
|
51
|
+
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
46
52
|
* @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
|
|
47
53
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
48
54
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
@@ -70,7 +76,14 @@ export interface VaultV1Actions {
|
|
|
70
76
|
* @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
|
|
71
77
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
72
78
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered.
|
|
73
|
-
* @throws {
|
|
79
|
+
* @throws {UnknownTokenError} from `getRequirements()` when the token's `decimals()` is unusable.
|
|
80
|
+
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
81
|
+
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
82
|
+
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
83
|
+
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
|
|
84
|
+
* contract has no code at its registered address.
|
|
85
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, token metadata
|
|
86
|
+
* read, or `eth_chainId` request fails.
|
|
74
87
|
* @example
|
|
75
88
|
* ```ts
|
|
76
89
|
* import { vaults } from "@morpho-org/morpho-test";
|
|
@@ -129,7 +142,8 @@ export interface VaultV1Actions {
|
|
|
129
142
|
* @remarks VaultBundlesV1 skips a share permit whose nonce was already consumed and proceeds
|
|
130
143
|
* under the live allowance, so execute every requirement returned by the latest
|
|
131
144
|
* `getRequirements()` — including the oversized-allowance reset — before submitting.
|
|
132
|
-
* @throws {ChainIdMismatchError} when the connected client targets another chain
|
|
145
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain, or from
|
|
146
|
+
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
133
147
|
* @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
|
|
134
148
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
135
149
|
* at any `getRequirements()` call.
|
|
@@ -146,7 +160,13 @@ export interface VaultV1Actions {
|
|
|
146
160
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed or
|
|
147
161
|
* its spender or deadline differ from this operation's, or its amount is outside
|
|
148
162
|
* `[cap, cap / (1 - slippageTolerance)]`.
|
|
149
|
-
* @throws {
|
|
163
|
+
* @throws {MissingPermitDomainNameError} from `getRequirements()` when signatures are enabled,
|
|
164
|
+
* the share allowance is insufficient, and the supplied `vaultData` share token exposes
|
|
165
|
+
* neither `name()` nor an EIP-5267 domain.
|
|
166
|
+
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
|
|
167
|
+
* contract has no code at its registered address.
|
|
168
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, permit-nonce, or
|
|
169
|
+
* `eth_chainId` read fails, or transaction encoding fails.
|
|
150
170
|
* @example
|
|
151
171
|
* ```ts
|
|
152
172
|
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
@@ -192,7 +212,8 @@ export interface VaultV1Actions {
|
|
|
192
212
|
* @param params.deadline - Optional execution and share-permit deadline in Unix seconds; defaults
|
|
193
213
|
* to two hours from handle creation.
|
|
194
214
|
* @returns Lazy exact share-allowance requirements and a synchronous transaction builder.
|
|
195
|
-
* @throws {ChainIdMismatchError} when the connected client targets another chain
|
|
215
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain, or from
|
|
216
|
+
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
196
217
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
197
218
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
198
219
|
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
@@ -201,7 +222,17 @@ export interface VaultV1Actions {
|
|
|
201
222
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
202
223
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
203
224
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered.
|
|
204
|
-
* @throws {
|
|
225
|
+
* @throws {UnknownTokenError} from `getRequirements()` when the vault share token's `decimals()` is unusable.
|
|
226
|
+
* @throws {MalformedTokenMetadataError} when the share token's `eip712Domain()` or
|
|
227
|
+
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
228
|
+
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
229
|
+
* @throws {MissingPermitDomainNameError} from `getRequirements()` when signatures are enabled,
|
|
230
|
+
* the share allowance is insufficient, and the share token fetched by `getData()` exposes
|
|
231
|
+
* neither `name()` nor an EIP-5267 domain.
|
|
232
|
+
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
|
|
233
|
+
* contract has no code at its registered address.
|
|
234
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, permit-nonce, or
|
|
235
|
+
* `eth_chainId` read fails.
|
|
205
236
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permit signatures are supplied.
|
|
206
237
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
207
238
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
@@ -270,7 +301,8 @@ export interface VaultV1Actions {
|
|
|
270
301
|
* @param params.userAddress - Account that signs and submits the exit.
|
|
271
302
|
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
272
303
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
273
|
-
* @throws {ChainIdMismatchError} when the client and entity target different chains
|
|
304
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains, or from
|
|
305
|
+
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
274
306
|
* @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
|
|
275
307
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
276
308
|
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
@@ -282,7 +314,12 @@ export interface VaultV1Actions {
|
|
|
282
314
|
* assigning more than the vault owns in a repeated market.
|
|
283
315
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
284
316
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
285
|
-
* @throws {
|
|
317
|
+
* @throws {MissingPermitDomainNameError} from `getRequirements()` when signatures are enabled,
|
|
318
|
+
* the share allowance is insufficient, and the supplied `vaultData` share token exposes
|
|
319
|
+
* neither `name()` nor an EIP-5267 domain.
|
|
320
|
+
* @throws {viem.BaseError} from `getRequirements()` when the `eth_chainId` request or an
|
|
321
|
+
* RPC contract read fails.
|
|
322
|
+
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol contract has no code at its registered address.
|
|
286
323
|
* @throws {VaultMorphoMismatchError} from `getRequirements()` when the vault uses another Morpho deployment.
|
|
287
324
|
* @throws {VaultIsBlueFeeRecipientError} from `getRequirements()` when Morpho Blue accrues protocol fees to the vault.
|
|
288
325
|
* @throws {InsufficientBlueBalanceForInKindRedeemError} from `getRequirements()` when Blue cannot fund the flash loan.
|
|
@@ -353,7 +390,8 @@ export interface VaultV1Actions {
|
|
|
353
390
|
* satisfied between calls stops being reported, while the derived source share cap stays
|
|
354
391
|
* pinned to the supplied snapshot.
|
|
355
392
|
* @throws {UnknownBlueMarketAllocationError} when a source withdraw-queue market has no allocation snapshot.
|
|
356
|
-
* @throws {ChainIdMismatchError} when the connected client targets another chain
|
|
393
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain, or from
|
|
394
|
+
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
357
395
|
* @throws {UnsupportedBlueMarketIrmError} when an allocated source or target market with positive debt uses an unsupported IRM.
|
|
358
396
|
* @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
|
|
359
397
|
* @throws {VaultAssetMismatchError} when the source and destination vault assets differ.
|
|
@@ -368,7 +406,11 @@ export interface VaultV1Actions {
|
|
|
368
406
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
369
407
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
370
408
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered.
|
|
371
|
-
* @throws {
|
|
409
|
+
* @throws {MissingPermitDomainNameError} from `getRequirements()` when a Vault V1 share permit needs a domain name but the supplied vault data has neither one nor an EIP-5267 domain.
|
|
410
|
+
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
|
|
411
|
+
* contract has no code at its registered address.
|
|
412
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, permit-nonce, or
|
|
413
|
+
* `eth_chainId` read fails.
|
|
372
414
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permit signatures are supplied.
|
|
373
415
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
374
416
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
@@ -430,6 +472,16 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
430
472
|
private readonly chainId;
|
|
431
473
|
constructor(client: MorphoClientType, vault: Address, chainId: number);
|
|
432
474
|
getData(parameters?: FetchParameters): Promise<AccrualVault>;
|
|
475
|
+
/**
|
|
476
|
+
* Asserts that every registry contract this flow's transaction targets or names as
|
|
477
|
+
* spender/authorized operator holds code, with one `eth_getCode` per distinct address
|
|
478
|
+
* before any other requirement read. This VaultV1 `inKindRedeem` path validates the client chain
|
|
479
|
+
* before this code check.
|
|
480
|
+
*
|
|
481
|
+
* @param roles - Registry labels to resolve and check; `permit2` is skipped when the
|
|
482
|
+
* chain registers none.
|
|
483
|
+
*/
|
|
484
|
+
private assertWriteTargets;
|
|
433
485
|
/** {@inheritDoc VaultV1Actions.deposit} */
|
|
434
486
|
deposit(params: {
|
|
435
487
|
readonly userAddress: Address;
|