@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v5-to-v6.md +206 -3
- package/README.md +81 -41
- package/lib/cjs/abis.d.ts +210 -0
- package/lib/cjs/abis.js +142 -2
- package/lib/cjs/actions/blue/borrow.d.ts +1 -1
- package/lib/cjs/actions/blue/borrow.js +1 -1
- package/lib/cjs/actions/blue/common.d.ts +6 -19
- package/lib/cjs/actions/blue/common.js +25 -138
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +1 -1
- package/lib/cjs/actions/blue/repay.d.ts +3 -3
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/blue/supply.d.ts +3 -3
- package/lib/cjs/actions/blue/supply.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
- package/lib/cjs/actions/blue/withdraw.js +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
- package/lib/cjs/actions/bundles/common.d.ts +200 -0
- package/lib/cjs/actions/bundles/common.js +469 -0
- package/lib/cjs/actions/bundles/index.d.ts +3 -0
- package/lib/cjs/actions/bundles/index.js +23 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +10 -4
- package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +13 -13
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/index.js +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
- package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/cjs/actions/vaultV1/deposit.js +110 -109
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
- package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/cjs/actions/vaultV1/redeem.js +56 -33
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
- package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/cjs/actions/vaultV2/deposit.js +111 -109
- package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/cjs/actions/vaultV2/redeem.js +56 -34
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
- package/lib/cjs/entities/blue/blue.d.ts +19 -19
- package/lib/cjs/entities/blue/blue.js +3 -1
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +61 -65
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +17 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
- package/lib/cjs/helpers/index.d.ts +2 -1
- package/lib/cjs/helpers/index.js +5 -1
- package/lib/cjs/helpers/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +90 -1
- package/lib/cjs/helpers/slippage.js +123 -0
- package/lib/cjs/helpers/validate.d.ts +2 -0
- package/lib/cjs/helpers/validate.js +12 -1
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +179 -70
- package/lib/cjs/types/action.js +12 -12
- package/lib/cjs/types/error.d.ts +62 -14
- package/lib/cjs/types/error.js +88 -22
- package/lib/esm/abis.d.ts +210 -0
- package/lib/esm/abis.js +140 -0
- package/lib/esm/actions/blue/borrow.d.ts +1 -1
- package/lib/esm/actions/blue/borrow.js +1 -1
- package/lib/esm/actions/blue/common.d.ts +6 -19
- package/lib/esm/actions/blue/common.js +27 -140
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +1 -1
- package/lib/esm/actions/blue/repay.d.ts +3 -3
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/blue/supply.d.ts +3 -3
- package/lib/esm/actions/blue/supply.js +1 -1
- package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateral.js +1 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -1
- package/lib/esm/actions/blue/withdraw.js +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +200 -0
- package/lib/esm/actions/bundles/common.js +457 -0
- package/lib/esm/actions/bundles/index.d.ts +3 -0
- package/lib/esm/actions/bundles/index.js +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +10 -4
- package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +11 -11
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/index.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
- package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/esm/actions/vaultV1/deposit.js +112 -111
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
- package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/esm/actions/vaultV1/redeem.js +56 -33
- package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/esm/actions/vaultV1/withdraw.js +86 -34
- package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/esm/actions/vaultV2/deposit.js +113 -111
- package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/esm/actions/vaultV2/redeem.js +56 -34
- package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/esm/actions/vaultV2/withdraw.js +86 -35
- package/lib/esm/entities/blue/blue.d.ts +19 -19
- package/lib/esm/entities/blue/blue.js +4 -2
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +51 -55
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
- package/lib/esm/helpers/index.d.ts +2 -1
- package/lib/esm/helpers/index.js +2 -1
- package/lib/esm/helpers/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +90 -1
- package/lib/esm/helpers/slippage.js +122 -2
- package/lib/esm/helpers/validate.d.ts +2 -0
- package/lib/esm/helpers/validate.js +11 -1
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +179 -70
- package/lib/esm/types/action.js +11 -11
- package/lib/esm/types/error.d.ts +62 -14
- package/lib/esm/types/error.js +80 -16
- package/package.json +3 -3
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getBundlesTokenRequirements = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
7
|
const viem_1 = require("viem");
|
|
8
8
|
const actions_1 = require("viem/actions");
|
|
9
|
-
const index_js_1 = require("
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
|
|
9
|
+
const index_js_1 = require("../../actions/bundles/index.js");
|
|
10
|
+
const encodeErc20Permit_js_1 = require("../../actions/requirements/encode/encodeErc20Permit.js");
|
|
11
|
+
const index_js_2 = require("../../helpers/index.js");
|
|
12
|
+
const index_js_3 = require("../../types/index.js");
|
|
14
13
|
/**
|
|
15
14
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
16
|
-
*
|
|
15
|
+
* a registered fixed bundles contract.
|
|
17
16
|
*
|
|
18
17
|
* Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
|
|
19
|
-
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names
|
|
18
|
+
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
|
|
20
19
|
* as spender. Permit2 SignatureTransfer requires an explicit unused unordered nonce so concurrent
|
|
21
20
|
* requirements never silently sign the same owner-global nonce.
|
|
22
21
|
*
|
|
23
22
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
24
23
|
* @param params - Token requirement parameters.
|
|
25
24
|
* @param params.token - ERC-20 token funded by the operation.
|
|
26
|
-
* @param params.
|
|
25
|
+
* @param params.spender - Registered fixed bundles contract that pulls the token.
|
|
26
|
+
* @param params.amount - Exact amount the contract will pull; zero returns no requirements.
|
|
27
27
|
* @param params.approvalAmount - Classic approval amount; defaults to `amount` and is ignored by signature paths.
|
|
28
28
|
* @param params.owner - Account funding the operation.
|
|
29
29
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
@@ -38,9 +38,10 @@ const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
|
|
|
38
38
|
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
39
39
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
40
40
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
41
|
-
* @throws {
|
|
42
|
-
*
|
|
43
|
-
* @throws {
|
|
41
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
42
|
+
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
43
|
+
* @throws {MissingPermit2SignatureTransferNonceError} when Permit2 is selected without a nonce.
|
|
44
|
+
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
44
45
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
45
46
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
46
47
|
* @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, or ERC-2612 metadata
|
|
@@ -48,13 +49,16 @@ const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
|
|
|
48
49
|
* @example
|
|
49
50
|
* ```ts
|
|
50
51
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
52
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
51
53
|
* import { createPublicClient, http, zeroAddress } from "viem";
|
|
52
54
|
* import { mainnet } from "viem/chains";
|
|
53
|
-
* import {
|
|
55
|
+
* import { getBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
|
|
54
56
|
*
|
|
55
57
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
56
|
-
* const
|
|
58
|
+
* const vaultBundlesV1 = getChainAddress(mainnet.id, "bundles.vaultBundlesV1");
|
|
59
|
+
* const requirements = await getBundlesTokenRequirements(client, {
|
|
57
60
|
* token: addressesRegistry[mainnet.id].usdc,
|
|
61
|
+
* spender: vaultBundlesV1,
|
|
58
62
|
* amount: 1_000_000n,
|
|
59
63
|
* owner: zeroAddress,
|
|
60
64
|
* chainId: mainnet.id,
|
|
@@ -62,28 +66,33 @@ const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
|
|
|
62
66
|
* supportSignature: true,
|
|
63
67
|
* permit2Nonce: 42n,
|
|
64
68
|
* });
|
|
65
|
-
* // requirements contains approvals and/or signable
|
|
69
|
+
* // requirements contains approvals and/or signable bundles token requirements.
|
|
66
70
|
* ```
|
|
67
71
|
*/
|
|
68
|
-
const
|
|
69
|
-
(0,
|
|
72
|
+
const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
73
|
+
(0, index_js_2.validateChainId)(viemClient.chain?.id, params.chainId);
|
|
74
|
+
(0, index_js_2.validateRequirementSpender)({
|
|
75
|
+
chainId: params.chainId,
|
|
76
|
+
spender: params.spender,
|
|
77
|
+
allowed: ["blueBundlesV1", "vaultBundlesV1"],
|
|
78
|
+
});
|
|
70
79
|
if (params.amount < 0n) {
|
|
71
|
-
throw new
|
|
80
|
+
throw new index_js_3.NegativeInputError("amount", params.amount);
|
|
72
81
|
}
|
|
73
82
|
// Reject oversized inputs before any RPC read so this resolver never asks the user to sign or
|
|
74
83
|
// submit an approval/permit that the eventual BlueBundlesV1 call (uint256 ABI) would reject.
|
|
75
84
|
if (params.amount > viem_1.maxUint256) {
|
|
76
|
-
throw new
|
|
85
|
+
throw new index_js_3.InputExceedsMaxError({
|
|
77
86
|
field: "amount",
|
|
78
87
|
value: params.amount,
|
|
79
88
|
max: viem_1.maxUint256,
|
|
80
89
|
});
|
|
81
90
|
}
|
|
82
91
|
if (params.deadline <= 0n) {
|
|
83
|
-
throw new
|
|
92
|
+
throw new index_js_3.NonPositiveInputError("deadline", params.deadline);
|
|
84
93
|
}
|
|
85
94
|
if (params.deadline > viem_1.maxUint256) {
|
|
86
|
-
throw new
|
|
95
|
+
throw new index_js_3.InputExceedsMaxError({
|
|
87
96
|
field: "deadline",
|
|
88
97
|
value: params.deadline,
|
|
89
98
|
max: viem_1.maxUint256,
|
|
@@ -94,11 +103,10 @@ const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
94
103
|
// this too, but the exported resolver must guard its own callers.
|
|
95
104
|
const timestamp = morpho_ts_1.Time.timestamp();
|
|
96
105
|
if (params.deadline <= timestamp) {
|
|
97
|
-
throw new
|
|
106
|
+
throw new index_js_3.ExpiredDeadlineError(params.deadline, timestamp);
|
|
98
107
|
}
|
|
99
108
|
if (params.amount === 0n)
|
|
100
109
|
return [];
|
|
101
|
-
const blueBundlesV1 = (0, morpho_ts_1.getChainAddress)(params.chainId, "bundles.blueBundlesV1");
|
|
102
110
|
const { permit2, dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
|
|
103
111
|
if (params.supportSignature) {
|
|
104
112
|
const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
|
|
@@ -113,7 +121,7 @@ const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
113
121
|
return [
|
|
114
122
|
await (0, encodeErc20Permit_js_1.encodeErc20Permit)(viemClient, {
|
|
115
123
|
token: params.token,
|
|
116
|
-
spender:
|
|
124
|
+
spender: params.spender,
|
|
117
125
|
amount: params.amount,
|
|
118
126
|
chainId: params.chainId,
|
|
119
127
|
nonce,
|
|
@@ -125,20 +133,19 @@ const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
125
133
|
}
|
|
126
134
|
if (permit2 != null) {
|
|
127
135
|
if (params.permit2Nonce == null) {
|
|
128
|
-
throw new
|
|
136
|
+
throw new index_js_3.MissingPermit2SignatureTransferNonceError();
|
|
129
137
|
}
|
|
130
138
|
if (params.permit2Nonce < 0n) {
|
|
131
|
-
throw new
|
|
139
|
+
throw new index_js_3.NegativeInputError("permit2Nonce", params.permit2Nonce);
|
|
132
140
|
}
|
|
133
141
|
if (params.permit2Nonce > viem_1.maxUint256) {
|
|
134
|
-
throw new
|
|
142
|
+
throw new index_js_3.InputExceedsMaxError({
|
|
135
143
|
field: "permit2Nonce",
|
|
136
144
|
value: params.permit2Nonce,
|
|
137
145
|
max: viem_1.maxUint256,
|
|
138
146
|
});
|
|
139
147
|
}
|
|
140
148
|
const wordPosition = params.permit2Nonce >> 8n;
|
|
141
|
-
const bitPosition = params.permit2Nonce & 255n;
|
|
142
149
|
const [allowance, nonceBitmap] = await Promise.all([
|
|
143
150
|
(0, actions_1.readContract)(viemClient, {
|
|
144
151
|
abi: viem_1.erc20Abi,
|
|
@@ -153,55 +160,44 @@ const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
|
|
|
153
160
|
args: [params.owner, wordPosition],
|
|
154
161
|
}),
|
|
155
162
|
]);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
(0, encodeErc20Permit2TransferFrom_js_1.encodeErc20Permit2TransferFrom)({
|
|
171
|
-
token: params.token,
|
|
172
|
-
spender: blueBundlesV1,
|
|
173
|
-
amount: params.amount,
|
|
174
|
-
chainId: params.chainId,
|
|
175
|
-
nonce: params.permit2Nonce,
|
|
176
|
-
deadline: params.deadline,
|
|
177
|
-
}),
|
|
178
|
-
];
|
|
163
|
+
return (0, index_js_1.resolveBundlesTokenRequirements)({
|
|
164
|
+
token: params.token,
|
|
165
|
+
spender: params.spender,
|
|
166
|
+
owner: params.owner,
|
|
167
|
+
chainId: params.chainId,
|
|
168
|
+
amount: params.amount,
|
|
169
|
+
deadline: params.deadline,
|
|
170
|
+
state: {
|
|
171
|
+
type: "permit2SignatureTransfer",
|
|
172
|
+
permit2Allowance: allowance,
|
|
173
|
+
permit2Nonce: params.permit2Nonce,
|
|
174
|
+
nonceBitmap,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
179
177
|
}
|
|
180
178
|
}
|
|
181
179
|
const approvalAmount = params.approvalAmount ?? params.amount;
|
|
182
180
|
if (approvalAmount < params.amount) {
|
|
183
|
-
throw new
|
|
181
|
+
throw new index_js_3.ApprovalAmountLessThanSpendAmountError();
|
|
184
182
|
}
|
|
185
183
|
const allowance = await (0, actions_1.readContract)(viemClient, {
|
|
186
184
|
abi: viem_1.erc20Abi,
|
|
187
185
|
address: params.token,
|
|
188
186
|
functionName: "allowance",
|
|
189
|
-
args: [params.owner,
|
|
187
|
+
args: [params.owner, params.spender],
|
|
190
188
|
});
|
|
191
|
-
return (0,
|
|
192
|
-
|
|
189
|
+
return (0, index_js_1.resolveBundlesTokenRequirements)({
|
|
190
|
+
token: params.token,
|
|
191
|
+
spender: params.spender,
|
|
192
|
+
owner: params.owner,
|
|
193
193
|
chainId: params.chainId,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
// redundant approval — and a zero-reset on approve-only-once tokens like
|
|
200
|
-
// USDT — when the current allowance already covers the pull.
|
|
201
|
-
spendAmount: params.amount,
|
|
194
|
+
amount: params.amount,
|
|
195
|
+
deadline: params.deadline,
|
|
196
|
+
state: {
|
|
197
|
+
type: "approval",
|
|
198
|
+
allowance,
|
|
202
199
|
approvalAmount,
|
|
203
200
|
},
|
|
204
|
-
allowances: allowance,
|
|
205
201
|
});
|
|
206
202
|
};
|
|
207
|
-
exports.
|
|
203
|
+
exports.getBundlesTokenRequirements = getBundlesTokenRequirements;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Token } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address, Client } from "viem";
|
|
3
|
+
import { type ActionRequirement } from "../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the exact vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
|
|
6
|
+
*
|
|
7
|
+
* The exit burns however many shares the vault prices at execution time, so the share allowance is
|
|
8
|
+
* the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
|
|
9
|
+
* satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*
|
|
13
|
+
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
14
|
+
* @param params - Vault snapshot, owner, exact allowance, and deadline values.
|
|
15
|
+
* @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
|
|
16
|
+
* permit or approval that sets it to exactly that cap.
|
|
17
|
+
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
18
|
+
* @throws {viem.BaseError} when an allowance or nonce read fails.
|
|
19
|
+
*/
|
|
20
|
+
export declare const getVaultBundlesSharesRequirements: (viemClient: Client, params: {
|
|
21
|
+
readonly vaultData: Token;
|
|
22
|
+
readonly version: "vaultV1" | "vaultV2";
|
|
23
|
+
readonly owner: Address;
|
|
24
|
+
readonly chainId: number;
|
|
25
|
+
readonly requiredShareAllowance: bigint;
|
|
26
|
+
readonly deadline: bigint;
|
|
27
|
+
readonly supportSignature: boolean;
|
|
28
|
+
}) => Promise<readonly ActionRequirement[]>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVaultBundlesSharesRequirements = void 0;
|
|
4
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const actions_1 = require("viem/actions");
|
|
8
|
+
const index_js_1 = require("../../actions/index.js");
|
|
9
|
+
const index_js_2 = require("../../helpers/index.js");
|
|
10
|
+
const index_js_3 = require("../../types/index.js");
|
|
11
|
+
/**
|
|
12
|
+
* Resolves the exact vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
|
|
13
|
+
*
|
|
14
|
+
* The exit burns however many shares the vault prices at execution time, so the share allowance is
|
|
15
|
+
* the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
|
|
16
|
+
* satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*
|
|
20
|
+
* @param viemClient - Client used to read the current share allowance and permit nonce.
|
|
21
|
+
* @param params - Vault snapshot, owner, exact allowance, and deadline values.
|
|
22
|
+
* @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
|
|
23
|
+
* permit or approval that sets it to exactly that cap.
|
|
24
|
+
* @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
|
|
25
|
+
* @throws {viem.BaseError} when an allowance or nonce read fails.
|
|
26
|
+
*/
|
|
27
|
+
const getVaultBundlesSharesRequirements = async (viemClient, params) => {
|
|
28
|
+
(0, index_js_2.validateChainId)(viemClient.chain?.id, params.chainId);
|
|
29
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
30
|
+
if (params.deadline <= now) {
|
|
31
|
+
throw new index_js_3.ExpiredDeadlineError(params.deadline, now);
|
|
32
|
+
}
|
|
33
|
+
const spender = (0, morpho_ts_1.getChainAddress)(params.chainId, "bundles.vaultBundlesV1");
|
|
34
|
+
const allowance = await (0, actions_1.readContract)(viemClient, {
|
|
35
|
+
address: params.vaultData.address,
|
|
36
|
+
abi: viem_1.erc20Abi,
|
|
37
|
+
functionName: "allowance",
|
|
38
|
+
args: [params.owner, spender],
|
|
39
|
+
});
|
|
40
|
+
// Asset-mode withdrawals carry no onchain share cap, so the allowance itself is the cap. A
|
|
41
|
+
// larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`,
|
|
42
|
+
// so only an exact match skips the approval or permit that resets it to the computed cap.
|
|
43
|
+
if (allowance === params.requiredShareAllowance)
|
|
44
|
+
return [];
|
|
45
|
+
if (params.supportSignature) {
|
|
46
|
+
const nonce = await (0, actions_1.readContract)(viemClient, {
|
|
47
|
+
address: params.vaultData.address,
|
|
48
|
+
abi: blue_sdk_viem_1.erc2612Abi,
|
|
49
|
+
functionName: "nonces",
|
|
50
|
+
args: [params.owner],
|
|
51
|
+
});
|
|
52
|
+
return [
|
|
53
|
+
(0, index_js_1.encodeVaultSharesPermit)({
|
|
54
|
+
vault: params.vaultData,
|
|
55
|
+
version: params.version,
|
|
56
|
+
spender,
|
|
57
|
+
owner: params.owner,
|
|
58
|
+
chainId: params.chainId,
|
|
59
|
+
nonce,
|
|
60
|
+
amount: params.requiredShareAllowance,
|
|
61
|
+
deadline: params.deadline,
|
|
62
|
+
}),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
return [
|
|
66
|
+
(0, index_js_1.encodeErc20Approval)({
|
|
67
|
+
token: params.vaultData.address,
|
|
68
|
+
spender,
|
|
69
|
+
amount: params.requiredShareAllowance,
|
|
70
|
+
chainId: params.chainId,
|
|
71
|
+
}),
|
|
72
|
+
];
|
|
73
|
+
};
|
|
74
|
+
exports.getVaultBundlesSharesRequirements = getVaultBundlesSharesRequirements;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./getBundlesTokenRequirements.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getBundlesTokenRequirements.js"), exports);
|