@morpho-org/morpho-sdk 7.0.0 → 8.1.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 +6 -0
- 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 +432 -74
- package/lib/cjs/entities/midnight/midnight.js +869 -188
- 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 +83 -49
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +54 -12
- package/lib/cjs/entities/vaultV2/vaultV2.js +86 -55
- 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/action.d.ts +102 -1
- package/lib/cjs/types/action.js +102 -1
- 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.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 +432 -74
- package/lib/esm/entities/midnight/midnight.js +870 -189
- 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 +85 -51
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +54 -12
- package/lib/esm/entities/vaultV2/vaultV2.js +88 -57
- 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/action.d.ts +102 -1
- package/lib/esm/types/action.js +102 -1
- 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.d.ts +1 -1
- package/lib/esm/utils.d.ts +2 -1
- package/lib/esm/utils.js +2 -1
- package/package.json +10 -10
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertRegistryTargetsHaveCode = exports.assertContractCode = void 0;
|
|
4
|
+
const actions_1 = require("viem/actions");
|
|
5
|
+
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
6
|
+
const index_js_1 = require("../../types/index.js");
|
|
7
|
+
/**
|
|
8
|
+
* Asserts that a configured contract address holds deployed code on the client's chain.
|
|
9
|
+
*
|
|
10
|
+
* A call to a code-less address succeeds on-chain as a no-op, so entity flows check each
|
|
11
|
+
* registered target before returning requirements. The `eth_getCode` read runs at the
|
|
12
|
+
* client's default block; transport failures propagate unwrapped because they are
|
|
13
|
+
* infrastructure failures, not configuration failures.
|
|
14
|
+
*
|
|
15
|
+
* @param client - Connected viem client used for the `eth_getCode` read.
|
|
16
|
+
* @param params - Assertion parameters.
|
|
17
|
+
* @param params.address - Contract address expected to hold code.
|
|
18
|
+
* @param params.chainId - Chain id the flow targets, reported on the error.
|
|
19
|
+
* @param params.role - Registry label naming the address's role in the flow.
|
|
20
|
+
* @returns Nothing when the address holds code.
|
|
21
|
+
* @throws {MissingContractCodeError} when the address has no deployed bytecode.
|
|
22
|
+
* @throws {viem.BaseError} when the `eth_getCode` read itself fails.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
const assertContractCode = async (client, params) => {
|
|
26
|
+
const bytecode = await (0, actions_1.getBytecode)(client, { address: params.address });
|
|
27
|
+
if (bytecode === undefined || bytecode === "0x") {
|
|
28
|
+
throw new index_js_1.MissingContractCodeError(params.address, params.chainId, params.role);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.assertContractCode = assertContractCode;
|
|
32
|
+
/**
|
|
33
|
+
* Asserts that each distinct target in a flow's write-surface list holds code.
|
|
34
|
+
*
|
|
35
|
+
* One `eth_getCode` per distinct address runs before any other requirement read.
|
|
36
|
+
* A wrong-chain RPC reports no code at every target, so on the first
|
|
37
|
+
* {@link MissingContractCodeError} a single `eth_chainId` probe decides: a served
|
|
38
|
+
* chain mismatch surfaces as {@link ChainIdMismatchError} (never as missing
|
|
39
|
+
* code), a failed probe keeps the original missing-code error, and a matching
|
|
40
|
+
* chain rethrows it unchanged. Other assertion errors propagate unwrapped.
|
|
41
|
+
*
|
|
42
|
+
* @param client - Connected viem client used for the `eth_getCode` reads.
|
|
43
|
+
* @param chainId - Chain id the flow targets, reported on the errors.
|
|
44
|
+
* @param targets - Distinct-by-address targets to check, in reporting order.
|
|
45
|
+
* @returns Nothing when every target holds code.
|
|
46
|
+
* @throws {MissingContractCodeError} when a target has no deployed bytecode on
|
|
47
|
+
* the endpoint's chain.
|
|
48
|
+
* @throws {ChainIdMismatchError} when the endpoint serves another chain id.
|
|
49
|
+
* @throws {viem.BaseError} when an `eth_getCode` read itself fails.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
// biome-ignore lint/complexity/useMaxParams: positional (client, chainId, targets) signature
|
|
53
|
+
const assertRegistryTargetsHaveCode = async (client, chainId, targets) => {
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
for (const target of targets) {
|
|
56
|
+
if (seen.has(target.address))
|
|
57
|
+
continue;
|
|
58
|
+
seen.add(target.address);
|
|
59
|
+
try {
|
|
60
|
+
await (0, exports.assertContractCode)(client, {
|
|
61
|
+
address: target.address,
|
|
62
|
+
chainId,
|
|
63
|
+
role: target.role,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (!(error instanceof index_js_1.MissingContractCodeError))
|
|
68
|
+
throw error;
|
|
69
|
+
try {
|
|
70
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
|
|
71
|
+
}
|
|
72
|
+
catch (probeError) {
|
|
73
|
+
throw probeError instanceof index_js_1.ChainIdMismatchError ? probeError : error;
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.assertRegistryTargetsHaveCode = assertRegistryTargetsHaveCode;
|
|
@@ -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";
|
|
@@ -8,6 +8,7 @@ const viem_1 = require("viem");
|
|
|
8
8
|
const actions_1 = require("viem/actions");
|
|
9
9
|
const index_js_1 = require("../../actions/bundles/index.js");
|
|
10
10
|
const encodeErc20Permit_js_1 = require("../../actions/requirements/encode/encodeErc20Permit.js");
|
|
11
|
+
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
11
12
|
const index_js_2 = require("../../helpers/index.js");
|
|
12
13
|
const index_js_3 = require("../../types/index.js");
|
|
13
14
|
const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
|
|
@@ -29,13 +30,18 @@ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
|
|
|
29
30
|
* @param params.owner - Account funding the operation.
|
|
30
31
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
31
32
|
* @param params.deadline - Final-call and signature deadline.
|
|
33
|
+
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
32
34
|
* @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
|
|
33
35
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
34
|
-
* @param params.useSimplePermit - Prefer ERC-2612 when
|
|
36
|
+
* @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's permit
|
|
37
|
+
* domain is known; a recognized `nonces()` revert or undecodable result, or a missing domain
|
|
38
|
+
* (no `name()` and no EIP-5267 domain), falls back to Permit2 or classic approval. A malformed
|
|
39
|
+
* `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
|
|
35
40
|
* @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
|
|
36
41
|
* found via {@link getUnusedPermit2Nonce}.
|
|
37
42
|
* @returns Ordered deep-frozen approval transactions and/or signable token requirements.
|
|
38
|
-
* @throws {ChainIdMismatchError} when the
|
|
43
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
44
|
+
* another chain than `params.chainId`.
|
|
39
45
|
* @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
|
|
40
46
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
41
47
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
@@ -47,8 +53,16 @@ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
|
|
|
47
53
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
48
54
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
49
55
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
50
|
-
* @throws {
|
|
51
|
-
*
|
|
56
|
+
* @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
|
|
57
|
+
* undecodable data, or is out of range.
|
|
58
|
+
* @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
|
|
59
|
+
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
60
|
+
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
61
|
+
* @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, ERC-2612 metadata,
|
|
62
|
+
* or `eth_chainId` read fails. An ERC-2612 nonce probe falls back to Permit2 or classic approval
|
|
63
|
+
* only when the token reverts or returns undecodable data; other read failures propagate. A
|
|
64
|
+
* missing permit domain is handled internally and also falls back; this function does not
|
|
65
|
+
* surface `MissingPermitDomainNameError`.
|
|
52
66
|
* @example
|
|
53
67
|
* ```ts
|
|
54
68
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
@@ -103,12 +117,13 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
103
117
|
// Reject an already-expired deadline before the RPC reads so a direct caller of this resolver
|
|
104
118
|
// never signs a permit for a supply the BlueBundlesV1 call would revert. The entity validates
|
|
105
119
|
// this too, but the exported resolver must guard its own callers.
|
|
106
|
-
const timestamp = morpho_ts_1.Time.timestamp();
|
|
120
|
+
const timestamp = params.now ?? morpho_ts_1.Time.timestamp();
|
|
107
121
|
if (params.deadline <= timestamp) {
|
|
108
122
|
throw new index_js_3.ExpiredDeadlineError(params.deadline, timestamp);
|
|
109
123
|
}
|
|
110
124
|
if (params.amount === 0n)
|
|
111
125
|
return [];
|
|
126
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, params.chainId);
|
|
112
127
|
const { permit2, dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
|
|
113
128
|
if (params.supportSignature) {
|
|
114
129
|
const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
|
|
@@ -118,20 +133,30 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
118
133
|
address: params.token,
|
|
119
134
|
functionName: "nonces",
|
|
120
135
|
args: [params.owner],
|
|
121
|
-
}).catch(() =>
|
|
136
|
+
}).catch((error) => {
|
|
137
|
+
if ((0, blue_sdk_viem_1.isTransportError)(error))
|
|
138
|
+
throw error;
|
|
139
|
+
if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))
|
|
140
|
+
return undefined;
|
|
141
|
+
throw error;
|
|
142
|
+
});
|
|
122
143
|
if ((0, morpho_ts_1.isDefined)(nonce)) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
144
|
+
const permit = await (0, morpho_ts_1._try)(() => (0, encodeErc20Permit_js_1.encodeErc20Permit)(viemClient, {
|
|
145
|
+
token: params.token,
|
|
146
|
+
owner: params.owner,
|
|
147
|
+
spender: params.spender,
|
|
148
|
+
amount: params.amount,
|
|
149
|
+
chainId: params.chainId,
|
|
150
|
+
nonce,
|
|
151
|
+
deadline: params.deadline,
|
|
152
|
+
now: timestamp,
|
|
153
|
+
supportDeployless: params.supportDeployless,
|
|
154
|
+
}), blue_sdk_viem_1.MissingPermitDomainNameError);
|
|
155
|
+
if ((0, morpho_ts_1.isDefined)(permit))
|
|
156
|
+
return [permit];
|
|
157
|
+
// A token that exposes nonces() but has neither name() nor
|
|
158
|
+
// eip712Domain() cannot be permitted over a known domain: fall
|
|
159
|
+
// through to the Permit2/classic-approval path.
|
|
135
160
|
}
|
|
136
161
|
}
|
|
137
162
|
if (permit2 != null) {
|
|
@@ -172,6 +197,7 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
172
197
|
chainId: params.chainId,
|
|
173
198
|
amount: params.amount,
|
|
174
199
|
deadline: params.deadline,
|
|
200
|
+
now: timestamp,
|
|
175
201
|
state: {
|
|
176
202
|
type: "permit2SignatureTransfer",
|
|
177
203
|
permit2Allowance: allowance,
|
|
@@ -198,6 +224,7 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
198
224
|
chainId: params.chainId,
|
|
199
225
|
amount: params.amount,
|
|
200
226
|
deadline: params.deadline,
|
|
227
|
+
now: timestamp,
|
|
201
228
|
state: {
|
|
202
229
|
type: "approval",
|
|
203
230
|
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
|
|
@@ -5,6 +5,7 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
const actions_1 = require("viem/actions");
|
|
8
|
+
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
8
9
|
const index_js_1 = require("../../helpers/index.js");
|
|
9
10
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
10
11
|
const index_js_2 = require("../../types/index.js");
|
|
@@ -26,12 +27,13 @@ const MAX_PERMIT2_NONCE_WORD = viem_1.maxUint256 >> 8n;
|
|
|
26
27
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
27
28
|
* @param params.startNonce - Lowest nonce to consider; defaults to 0.
|
|
28
29
|
* @returns The lowest unused Permit2 nonce at or after `startNonce`.
|
|
29
|
-
* @throws {ChainIdMismatchError} when the
|
|
30
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
31
|
+
* another chain than `params.chainId`.
|
|
30
32
|
* @throws {NegativeInputError} when `startNonce` is negative.
|
|
31
33
|
* @throws {InputExceedsMaxError} when `startNonce` exceeds `uint256`.
|
|
32
34
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
33
35
|
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
34
|
-
* @throws {viem.BaseError} when a Permit2 nonce-bitmap RPC read fails.
|
|
36
|
+
* @throws {viem.BaseError} when a Permit2 nonce-bitmap or `eth_chainId` RPC read fails.
|
|
35
37
|
* @throws {NoUnusedPermit2NonceError} when every nonce at or after `startNonce` is consumed.
|
|
36
38
|
* @example
|
|
37
39
|
* ```ts
|
|
@@ -51,6 +53,7 @@ const getUnusedPermit2Nonce = async (viemClient, params) => {
|
|
|
51
53
|
(0, index_js_1.validateChainId)(viemClient.chain?.id, params.chainId);
|
|
52
54
|
const startNonce = params.startNonce ?? 0n;
|
|
53
55
|
(0, validate_js_1.validateUint256Field)("startNonce", startNonce);
|
|
56
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, params.chainId);
|
|
54
57
|
const permit2 = (0, morpho_ts_1.getChainAddress)(params.chainId, "permit2");
|
|
55
58
|
const startWord = startNonce >> 8n;
|
|
56
59
|
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[]>;
|
|
@@ -6,6 +6,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
const actions_1 = require("viem/actions");
|
|
8
8
|
const index_js_1 = require("../../actions/index.js");
|
|
9
|
+
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
9
10
|
const index_js_2 = require("../../helpers/index.js");
|
|
10
11
|
const index_js_3 = require("../../types/index.js");
|
|
11
12
|
/**
|
|
@@ -23,19 +24,23 @@ const index_js_3 = require("../../types/index.js");
|
|
|
23
24
|
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
24
25
|
* @param params - Vault snapshot, owner, allowance bounds, and deadline values. `maxShareAllowance`
|
|
25
26
|
* defaults to `requiredShareAllowance`, which accepts only an exact match.
|
|
27
|
+
* @param params.now - Timestamp the deadline is validated against; defaults to the current time.
|
|
26
28
|
* @returns No requirement when the allowance is within `[requiredShareAllowance,
|
|
27
29
|
* maxShareAllowance]`, otherwise one
|
|
28
30
|
* approval that sets it to exactly that cap, or one permit when the allowance is below the cap
|
|
29
31
|
* and signatures are supported.
|
|
32
|
+
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
33
|
+
* another chain than `params.chainId`.
|
|
30
34
|
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
31
|
-
* @throws {viem.BaseError} when an allowance
|
|
35
|
+
* @throws {viem.BaseError} when an allowance, permit nonce, or `eth_chainId` read fails.
|
|
32
36
|
*/
|
|
33
37
|
const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
34
38
|
(0, index_js_2.validateChainId)(viemClient.chain?.id, params.chainId);
|
|
35
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
39
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
36
40
|
if (params.deadline <= now) {
|
|
37
41
|
throw new index_js_3.ExpiredDeadlineError(params.deadline, now);
|
|
38
42
|
}
|
|
43
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, params.chainId);
|
|
39
44
|
const spender = (0, morpho_ts_1.getChainAddress)(params.chainId, "bundles.vaultBundlesV1");
|
|
40
45
|
// The allowance is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
|
|
41
46
|
const allowance = await (0, actions_1.readContract)(viemClient, {
|
|
@@ -66,6 +71,7 @@ const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
|
66
71
|
nonce,
|
|
67
72
|
amount: params.requiredShareAllowance,
|
|
68
73
|
deadline: params.deadline,
|
|
74
|
+
now,
|
|
69
75
|
}),
|
|
70
76
|
];
|
|
71
77
|
}
|
|
@@ -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;
|