@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
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
exports.resolveBundlesFunding = exports.getBundlesTokenPermit = exports.getBundlesSharesPermit = exports.BundlesPermitKind = void 0;
|
|
18
|
+
var common_js_1 = require("./common.js");
|
|
19
|
+
Object.defineProperty(exports, "BundlesPermitKind", { enumerable: true, get: function () { return common_js_1.BundlesPermitKind; } });
|
|
20
|
+
Object.defineProperty(exports, "getBundlesSharesPermit", { enumerable: true, get: function () { return common_js_1.getBundlesSharesPermit; } });
|
|
21
|
+
Object.defineProperty(exports, "getBundlesTokenPermit", { enumerable: true, get: function () { return common_js_1.getBundlesTokenPermit; } });
|
|
22
|
+
Object.defineProperty(exports, "resolveBundlesFunding", { enumerable: true, get: function () { return common_js_1.resolveBundlesFunding; } });
|
|
23
|
+
__exportStar(require("./resolveBundlesTokenRequirements.js"), exports);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type Transaction } from "../../types/index.js";
|
|
3
|
+
/** Plain onchain state used by {@link resolveBundlesTokenRequirements}. */
|
|
4
|
+
export type BundlesTokenRequirementsState = {
|
|
5
|
+
readonly type: "approval";
|
|
6
|
+
/** Current allowance of the funding token for `spender`. */
|
|
7
|
+
readonly allowance: bigint;
|
|
8
|
+
/** Allowance to set when the current allowance cannot cover `amount`. */
|
|
9
|
+
readonly approvalAmount: bigint;
|
|
10
|
+
} | {
|
|
11
|
+
readonly type: "permit2SignatureTransfer";
|
|
12
|
+
readonly permit2Allowance: bigint;
|
|
13
|
+
readonly permit2Nonce: bigint;
|
|
14
|
+
readonly nonceBitmap: bigint;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Resolves pre-fetched allowance and Permit2 nonce state into ordered bundles requirements.
|
|
18
|
+
*
|
|
19
|
+
* `spender` is validated against the chain registry's fixed bundles deployments, and the
|
|
20
|
+
* SignatureTransfer branch resolves canonical Permit2 from that same registry, so no caller can
|
|
21
|
+
* route an approval or a signed pull to an address the SDK does not know.
|
|
22
|
+
*
|
|
23
|
+
* The SignatureTransfer branch always places any ERC-20 approval to canonical Permit2 before the
|
|
24
|
+
* one-time signature requirement.
|
|
25
|
+
*
|
|
26
|
+
* @param params - Funding values, expected bundles spender, and pre-fetched state.
|
|
27
|
+
* @param params.token - ERC-20 token funded by the operation.
|
|
28
|
+
* @param params.spender - Registered fixed bundles contract that pulls the token; must be the
|
|
29
|
+
* chain's BlueBundlesV1 or VaultBundlesV1 deployment.
|
|
30
|
+
* @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
|
|
31
|
+
* @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
|
|
32
|
+
* @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
|
|
33
|
+
* @param params.deadline - Signature expiration as a Unix timestamp in seconds.
|
|
34
|
+
* @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
|
|
35
|
+
* @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
|
|
36
|
+
* @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
|
|
37
|
+
* @param params.state.approvalAmount - In the approval branch, allowance to set if needed; must cover `amount`.
|
|
38
|
+
* @param params.state.permit2Allowance - In the SignatureTransfer branch, current token allowance from `owner` to canonical Permit2.
|
|
39
|
+
* @param params.state.permit2Nonce - In the SignatureTransfer branch, caller-selected unused uint256 unordered nonce.
|
|
40
|
+
* @param params.state.nonceBitmap - In the SignatureTransfer branch, owner's Permit2 bitmap word at `permit2Nonce >> 8n`.
|
|
41
|
+
* @returns Ordered approval transactions and/or a Permit2 SignatureTransfer requirement.
|
|
42
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
43
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
44
|
+
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
45
|
+
* @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
|
|
46
|
+
* @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
|
|
47
|
+
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
|
|
48
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
|
|
49
|
+
* @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { resolveBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
|
|
53
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
54
|
+
* import { zeroAddress } from "viem";
|
|
55
|
+
*
|
|
56
|
+
* const requirements = resolveBundlesTokenRequirements({
|
|
57
|
+
* token: zeroAddress,
|
|
58
|
+
* spender: getChainAddress(1, "bundles.vaultBundlesV1"),
|
|
59
|
+
* owner: zeroAddress,
|
|
60
|
+
* chainId: 1,
|
|
61
|
+
* amount: 1_000_000n,
|
|
62
|
+
* deadline: 1_900_000_000n,
|
|
63
|
+
* state: { type: "approval", allowance: 1_000_000n, approvalAmount: 1_000_000n },
|
|
64
|
+
* });
|
|
65
|
+
* // requirements is empty because the allowance already covers the amount.
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare const resolveBundlesTokenRequirements: (params: {
|
|
69
|
+
readonly token: Address;
|
|
70
|
+
readonly spender: Address;
|
|
71
|
+
readonly owner: Address;
|
|
72
|
+
readonly chainId: number;
|
|
73
|
+
readonly amount: bigint;
|
|
74
|
+
readonly deadline: bigint;
|
|
75
|
+
readonly state: BundlesTokenRequirementsState;
|
|
76
|
+
}) => readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveBundlesTokenRequirements = void 0;
|
|
4
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
7
|
+
const validateRequirementSpender_js_1 = require("../../helpers/validateRequirementSpender.js");
|
|
8
|
+
const index_js_1 = require("../../types/index.js");
|
|
9
|
+
const index_js_2 = require("../requirements/encode/index.js");
|
|
10
|
+
const getRequirementsApproval_js_1 = require("../requirements/getRequirementsApproval.js");
|
|
11
|
+
/**
|
|
12
|
+
* Resolves pre-fetched allowance and Permit2 nonce state into ordered bundles requirements.
|
|
13
|
+
*
|
|
14
|
+
* `spender` is validated against the chain registry's fixed bundles deployments, and the
|
|
15
|
+
* SignatureTransfer branch resolves canonical Permit2 from that same registry, so no caller can
|
|
16
|
+
* route an approval or a signed pull to an address the SDK does not know.
|
|
17
|
+
*
|
|
18
|
+
* The SignatureTransfer branch always places any ERC-20 approval to canonical Permit2 before the
|
|
19
|
+
* one-time signature requirement.
|
|
20
|
+
*
|
|
21
|
+
* @param params - Funding values, expected bundles spender, and pre-fetched state.
|
|
22
|
+
* @param params.token - ERC-20 token funded by the operation.
|
|
23
|
+
* @param params.spender - Registered fixed bundles contract that pulls the token; must be the
|
|
24
|
+
* chain's BlueBundlesV1 or VaultBundlesV1 deployment.
|
|
25
|
+
* @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
|
|
26
|
+
* @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
|
|
27
|
+
* @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
|
|
28
|
+
* @param params.deadline - Signature expiration as a Unix timestamp in seconds.
|
|
29
|
+
* @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
|
|
30
|
+
* @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
|
|
31
|
+
* @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
|
|
32
|
+
* @param params.state.approvalAmount - In the approval branch, allowance to set if needed; must cover `amount`.
|
|
33
|
+
* @param params.state.permit2Allowance - In the SignatureTransfer branch, current token allowance from `owner` to canonical Permit2.
|
|
34
|
+
* @param params.state.permit2Nonce - In the SignatureTransfer branch, caller-selected unused uint256 unordered nonce.
|
|
35
|
+
* @param params.state.nonceBitmap - In the SignatureTransfer branch, owner's Permit2 bitmap word at `permit2Nonce >> 8n`.
|
|
36
|
+
* @returns Ordered approval transactions and/or a Permit2 SignatureTransfer requirement.
|
|
37
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
38
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
39
|
+
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
40
|
+
* @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
|
|
41
|
+
* @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
|
|
42
|
+
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
|
|
43
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
|
|
44
|
+
* @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { resolveBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
|
|
48
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
49
|
+
* import { zeroAddress } from "viem";
|
|
50
|
+
*
|
|
51
|
+
* const requirements = resolveBundlesTokenRequirements({
|
|
52
|
+
* token: zeroAddress,
|
|
53
|
+
* spender: getChainAddress(1, "bundles.vaultBundlesV1"),
|
|
54
|
+
* owner: zeroAddress,
|
|
55
|
+
* chainId: 1,
|
|
56
|
+
* amount: 1_000_000n,
|
|
57
|
+
* deadline: 1_900_000_000n,
|
|
58
|
+
* state: { type: "approval", allowance: 1_000_000n, approvalAmount: 1_000_000n },
|
|
59
|
+
* });
|
|
60
|
+
* // requirements is empty because the allowance already covers the amount.
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
const resolveBundlesTokenRequirements = (params) => {
|
|
64
|
+
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
65
|
+
chainId: params.chainId,
|
|
66
|
+
spender: params.spender,
|
|
67
|
+
allowed: ["blueBundlesV1", "vaultBundlesV1"],
|
|
68
|
+
});
|
|
69
|
+
// Reject invalid pulls before an approval encoder can cap the requested amount.
|
|
70
|
+
(0, validate_js_1.validateUint256Field)("amount", params.amount);
|
|
71
|
+
if (params.amount === 0n)
|
|
72
|
+
return [];
|
|
73
|
+
if (params.state.type === "approval") {
|
|
74
|
+
if (params.state.approvalAmount < params.amount) {
|
|
75
|
+
throw new index_js_1.ApprovalAmountLessThanSpendAmountError();
|
|
76
|
+
}
|
|
77
|
+
return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
|
|
78
|
+
address: params.token,
|
|
79
|
+
chainId: params.chainId,
|
|
80
|
+
args: {
|
|
81
|
+
// Compare against the bounded pull to avoid redundant approvals and USDT zero-resets.
|
|
82
|
+
spender: params.spender,
|
|
83
|
+
spendAmount: params.amount,
|
|
84
|
+
approvalAmount: params.state.approvalAmount,
|
|
85
|
+
},
|
|
86
|
+
allowances: params.state.allowance,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (params.state.permit2Nonce < 0n) {
|
|
90
|
+
throw new index_js_1.NegativeInputError("permit2Nonce", params.state.permit2Nonce);
|
|
91
|
+
}
|
|
92
|
+
if (params.state.permit2Nonce > viem_1.maxUint256) {
|
|
93
|
+
throw new index_js_1.InputExceedsMaxError({
|
|
94
|
+
field: "permit2Nonce",
|
|
95
|
+
value: params.state.permit2Nonce,
|
|
96
|
+
max: viem_1.maxUint256,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const bitPosition = params.state.permit2Nonce & 255n;
|
|
100
|
+
if ((params.state.nonceBitmap & (1n << bitPosition)) !== 0n) {
|
|
101
|
+
throw new index_js_1.Permit2SignatureTransferNonceAlreadyUsedError(params.owner, params.state.permit2Nonce);
|
|
102
|
+
}
|
|
103
|
+
const permit2 = (0, morpho_ts_1.getChainAddress)(params.chainId, "permit2");
|
|
104
|
+
return [
|
|
105
|
+
...(0, getRequirementsApproval_js_1.getRequirementsApproval)({
|
|
106
|
+
address: params.token,
|
|
107
|
+
chainId: params.chainId,
|
|
108
|
+
args: {
|
|
109
|
+
spender: permit2,
|
|
110
|
+
spendAmount: params.amount,
|
|
111
|
+
approvalAmount: viem_1.maxUint256,
|
|
112
|
+
},
|
|
113
|
+
allowances: params.state.permit2Allowance,
|
|
114
|
+
}),
|
|
115
|
+
(0, index_js_2.encodeErc20Permit2SignatureTransfer)({
|
|
116
|
+
token: params.token,
|
|
117
|
+
spender: params.spender,
|
|
118
|
+
amount: params.amount,
|
|
119
|
+
chainId: params.chainId,
|
|
120
|
+
nonce: params.state.permit2Nonce,
|
|
121
|
+
deadline: params.deadline,
|
|
122
|
+
}),
|
|
123
|
+
];
|
|
124
|
+
};
|
|
125
|
+
exports.resolveBundlesTokenRequirements = resolveBundlesTokenRequirements;
|
|
@@ -3,6 +3,7 @@ export type { MidnightActions } from "../entities/midnight/index.js";
|
|
|
3
3
|
export type { VaultV1Actions } from "../entities/vaultV1/index.js";
|
|
4
4
|
export type { VaultV2Actions } from "../entities/vaultV2/index.js";
|
|
5
5
|
export * from "./blue/index.js";
|
|
6
|
+
export * from "./bundles/index.js";
|
|
6
7
|
export * from "./midnight/index.js";
|
|
7
8
|
export * from "./requirements/index.js";
|
|
8
9
|
export * from "./signatures/index.js";
|
package/lib/cjs/actions/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./blue/index.js"), exports);
|
|
18
|
+
__exportStar(require("./bundles/index.js"), exports);
|
|
18
19
|
__exportStar(require("./midnight/index.js"), exports);
|
|
19
20
|
__exportStar(require("./requirements/index.js"), exports);
|
|
20
21
|
__exportStar(require("./signatures/index.js"), exports);
|
|
@@ -40,8 +40,8 @@ export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBo
|
|
|
40
40
|
* chainId: 8453,
|
|
41
41
|
* market: marketData.params,
|
|
42
42
|
* collateralAssets: 2_000_000n,
|
|
43
|
-
* loanAssets:
|
|
44
|
-
* maxUnits:
|
|
43
|
+
* loanAssets: 1_000_000n,
|
|
44
|
+
* maxUnits: 1_100_000n,
|
|
45
45
|
* taker: borrower,
|
|
46
46
|
* takeableOffers: quote.data.takeableOffers,
|
|
47
47
|
* deadline: maxUint256,
|
|
@@ -44,8 +44,8 @@ const types_js_1 = require("./types.js");
|
|
|
44
44
|
* chainId: 8453,
|
|
45
45
|
* market: marketData.params,
|
|
46
46
|
* collateralAssets: 2_000_000n,
|
|
47
|
-
* loanAssets:
|
|
48
|
-
* maxUnits:
|
|
47
|
+
* loanAssets: 1_000_000n,
|
|
48
|
+
* maxUnits: 1_100_000n,
|
|
49
49
|
* taker: borrower,
|
|
50
50
|
* takeableOffers: quote.data.takeableOffers,
|
|
51
51
|
* deadline: maxUint256,
|
|
@@ -46,8 +46,8 @@ export interface MidnightTakeBorrowParams {
|
|
|
46
46
|
* const tx = midnightTakeBorrow({
|
|
47
47
|
* chainId: 8453,
|
|
48
48
|
* market: marketData.params,
|
|
49
|
-
* loanAssets:
|
|
50
|
-
* maxUnits:
|
|
49
|
+
* loanAssets: 1_000_000n,
|
|
50
|
+
* maxUnits: 1_100_000n,
|
|
51
51
|
* taker: borrower,
|
|
52
52
|
* takeableOffers: quote.data.takeableOffers,
|
|
53
53
|
* deadline: maxUint256,
|
|
@@ -40,8 +40,8 @@ const index_js_2 = require("../../types/index.js");
|
|
|
40
40
|
* const tx = midnightTakeBorrow({
|
|
41
41
|
* chainId: 8453,
|
|
42
42
|
* market: marketData.params,
|
|
43
|
-
* loanAssets:
|
|
44
|
-
* maxUnits:
|
|
43
|
+
* loanAssets: 1_000_000n,
|
|
44
|
+
* maxUnits: 1_100_000n,
|
|
45
45
|
* taker: borrower,
|
|
46
46
|
* takeableOffers: quote.data.takeableOffers,
|
|
47
47
|
* deadline: maxUint256,
|
|
@@ -46,8 +46,8 @@ export interface MidnightTakeLendParams {
|
|
|
46
46
|
* const tx = midnightTakeLend({
|
|
47
47
|
* chainId: 8453,
|
|
48
48
|
* market: marketData.params,
|
|
49
|
-
* assets:
|
|
50
|
-
* minUnits:
|
|
49
|
+
* assets: 1_000_000n,
|
|
50
|
+
* minUnits: 900_000n,
|
|
51
51
|
* taker: lender,
|
|
52
52
|
* takeableOffers: quote.data.takeableOffers,
|
|
53
53
|
* deadline: maxUint256,
|
|
@@ -41,8 +41,8 @@ const types_js_1 = require("./types.js");
|
|
|
41
41
|
* const tx = midnightTakeLend({
|
|
42
42
|
* chainId: 8453,
|
|
43
43
|
* market: marketData.params,
|
|
44
|
-
* assets:
|
|
45
|
-
* minUnits:
|
|
44
|
+
* assets: 1_000_000n,
|
|
45
|
+
* minUnits: 900_000n,
|
|
46
46
|
* taker: lender,
|
|
47
47
|
* takeableOffers: quote.data.takeableOffers,
|
|
48
48
|
* deadline: maxUint256,
|
|
@@ -10,7 +10,7 @@ export interface GetUnusedPermit2NonceParams {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
|
|
13
|
-
* {@link
|
|
13
|
+
* {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
|
|
14
14
|
*
|
|
15
15
|
* Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
|
|
16
16
|
* `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
|
|
@@ -12,7 +12,7 @@ const index_js_2 = require("../../../types/index.js");
|
|
|
12
12
|
const MAX_PERMIT2_NONCE_WORD = viem_1.maxUint256 >> 8n;
|
|
13
13
|
/**
|
|
14
14
|
* Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
|
|
15
|
-
* {@link
|
|
15
|
+
* {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
|
|
16
16
|
*
|
|
17
17
|
* Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
|
|
18
18
|
* `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
|
|
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./getBlueAuthorizationRequirement.js"), exports);
|
|
18
|
-
__exportStar(require("./getBlueBundlesV1TokenRequirements.js"), exports);
|
|
19
18
|
__exportStar(require("./getUnusedPermit2Nonce.js"), exports);
|
|
@@ -53,7 +53,7 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
|
|
|
53
53
|
}
|
|
54
54
|
// Reject an invalid or already-expired caller-supplied deadline before signing, so a direct caller
|
|
55
55
|
// is never walked through a wallet EIP-712 prompt for an authorization Morpho would reject with
|
|
56
|
-
// `SIGNATURE_EXPIRED`. Mirrors the sibling `
|
|
56
|
+
// `SIGNATURE_EXPIRED`. Mirrors the sibling `encodeErc20Permit2SignatureTransfer` and the
|
|
57
57
|
// `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
|
|
58
58
|
// from now and is always valid.
|
|
59
59
|
if (params.deadline != null) {
|
|
@@ -16,7 +16,7 @@ interface EncodeErc20ApprovalParams {
|
|
|
16
16
|
* @param params - Encoding parameters.
|
|
17
17
|
* @param params.token - ERC-20 token address to approve.
|
|
18
18
|
* @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
|
|
19
|
-
* Midnight, MidnightBundles, VaultExitBundlesV1, or BlueBundlesV1 for the chain.
|
|
19
|
+
* Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
20
20
|
* @param params.amount - Allowance amount before per-token cap.
|
|
21
21
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
22
22
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
@@ -15,7 +15,7 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
|
|
|
15
15
|
* @param params - Encoding parameters.
|
|
16
16
|
* @param params.token - ERC-20 token address to approve.
|
|
17
17
|
* @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
|
|
18
|
-
* Midnight, MidnightBundles, VaultExitBundlesV1, or BlueBundlesV1 for the chain.
|
|
18
|
+
* Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
19
19
|
* @param params.amount - Allowance amount before per-token cap.
|
|
20
20
|
* @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
|
|
21
21
|
* @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
|
|
@@ -46,6 +46,7 @@ const encodeErc20Approval = (params) => {
|
|
|
46
46
|
"midnight",
|
|
47
47
|
"midnightBundles",
|
|
48
48
|
"vaultExitBundlesV1",
|
|
49
|
+
"vaultBundlesV1",
|
|
49
50
|
"blueBundlesV1",
|
|
50
51
|
],
|
|
51
52
|
});
|
|
@@ -23,8 +23,8 @@ interface EncodeErc20PermitParams {
|
|
|
23
23
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
24
24
|
* @param params - Permit encoding parameters.
|
|
25
25
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
26
|
-
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
27
|
-
* BlueBundlesV1 for the chain.
|
|
26
|
+
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
27
|
+
* VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
28
28
|
* @param params.amount - Permit allowance amount.
|
|
29
29
|
* @param params.chainId - Target chain id.
|
|
30
30
|
* @param params.nonce - The user's current EIP-2612 nonce on `token`.
|
|
@@ -34,7 +34,7 @@ interface EncodeErc20PermitParams {
|
|
|
34
34
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
35
35
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
36
36
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
|
|
37
|
-
* MidnightBundles, or BlueBundlesV1 for `chainId`.
|
|
37
|
+
* MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
|
|
38
38
|
* @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
|
|
39
39
|
* @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
|
|
40
40
|
* @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
|
|
@@ -19,8 +19,8 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
19
19
|
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
20
20
|
* @param params - Permit encoding parameters.
|
|
21
21
|
* @param params.token - ERC-20 token address (must support EIP-2612).
|
|
22
|
-
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
23
|
-
* BlueBundlesV1 for the chain.
|
|
22
|
+
* @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
|
|
23
|
+
* VaultBundlesV1, or BlueBundlesV1 for the chain.
|
|
24
24
|
* @param params.amount - Permit allowance amount.
|
|
25
25
|
* @param params.chainId - Target chain id.
|
|
26
26
|
* @param params.nonce - The user's current EIP-2612 nonce on `token`.
|
|
@@ -30,7 +30,7 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
30
30
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
31
31
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
32
32
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
|
|
33
|
-
* MidnightBundles, or BlueBundlesV1 for `chainId`.
|
|
33
|
+
* MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
|
|
34
34
|
* @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
|
|
35
35
|
* @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
|
|
36
36
|
* @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
|
|
@@ -63,7 +63,12 @@ const encodeErc20Permit = async (viemClient, params) => {
|
|
|
63
63
|
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
64
64
|
chainId,
|
|
65
65
|
spender,
|
|
66
|
-
allowed: [
|
|
66
|
+
allowed: [
|
|
67
|
+
"generalAdapter1",
|
|
68
|
+
"midnightBundles",
|
|
69
|
+
"vaultBundlesV1",
|
|
70
|
+
"blueBundlesV1",
|
|
71
|
+
],
|
|
67
72
|
});
|
|
68
73
|
const now = morpho_ts_1.Time.timestamp();
|
|
69
74
|
// Validate an explicit deadline before the token-metadata read: this exported encoder can be
|
|
@@ -94,6 +99,7 @@ const encodeErc20Permit = async (viemClient, params) => {
|
|
|
94
99
|
spender,
|
|
95
100
|
amount,
|
|
96
101
|
deadline,
|
|
102
|
+
nonce,
|
|
97
103
|
},
|
|
98
104
|
};
|
|
99
105
|
return {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { type
|
|
3
|
-
/** Parameters for {@link
|
|
4
|
-
export interface
|
|
2
|
+
import { type Permit2SignatureTransferRequirementSignature, type Requirement } from "../../../types/index.js";
|
|
3
|
+
/** Parameters for {@link encodeErc20Permit2SignatureTransfer}. */
|
|
4
|
+
export interface EncodeErc20Permit2SignatureTransferParams {
|
|
5
5
|
/** ERC-20 token pulled through Permit2. */
|
|
6
6
|
readonly token: Address;
|
|
7
|
-
/**
|
|
7
|
+
/** Registered fixed bundles deployment receiving permission to pull the token. */
|
|
8
8
|
readonly spender: Address;
|
|
9
9
|
/** Exact token amount authorized by the one-time transfer. */
|
|
10
10
|
readonly amount: bigint;
|
|
@@ -16,14 +16,14 @@ export interface EncodeErc20Permit2TransferFromParams {
|
|
|
16
16
|
readonly deadline: bigint;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Builds a Permit2 SignatureTransfer requirement for a direct
|
|
19
|
+
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
20
20
|
*
|
|
21
21
|
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
22
22
|
* it has no managed allowance expiration.
|
|
23
23
|
*
|
|
24
24
|
* @param params - SignatureTransfer parameters.
|
|
25
25
|
* @param params.token - ERC-20 token pulled through Permit2.
|
|
26
|
-
* @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
|
|
26
|
+
* @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
|
|
27
27
|
* @param params.amount - Exact `uint256` token amount authorized.
|
|
28
28
|
* @param params.chainId - Target chain id.
|
|
29
29
|
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
@@ -35,7 +35,7 @@ export interface EncodeErc20Permit2TransferFromParams {
|
|
|
35
35
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
36
36
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
37
37
|
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
38
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
38
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
|
|
39
39
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
|
|
40
40
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
|
|
41
41
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
|
|
@@ -43,19 +43,19 @@ export interface EncodeErc20Permit2TransferFromParams {
|
|
|
43
43
|
* @example
|
|
44
44
|
* ```ts
|
|
45
45
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
46
|
-
* import {
|
|
46
|
+
* import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
|
|
47
47
|
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
48
48
|
* import { mainnet } from "viem/chains";
|
|
49
49
|
*
|
|
50
|
-
* const requirement =
|
|
50
|
+
* const requirement = encodeErc20Permit2SignatureTransfer({
|
|
51
51
|
* token: addressesRegistry[mainnet.id].usdc,
|
|
52
|
-
* spender: getChainAddress(mainnet.id, "bundles.
|
|
52
|
+
* spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
|
|
53
53
|
* amount: 1_000_000n,
|
|
54
54
|
* chainId: mainnet.id,
|
|
55
55
|
* nonce: 0n,
|
|
56
56
|
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
57
57
|
* });
|
|
58
|
-
* // requirement satisfies Requirement<
|
|
58
|
+
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
export declare const
|
|
61
|
+
export declare const encodeErc20Permit2SignatureTransfer: (params: EncodeErc20Permit2SignatureTransferParams) => Requirement<Permit2SignatureTransferRequirementSignature>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.encodeErc20Permit2SignatureTransfer = void 0;
|
|
4
4
|
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");
|
|
@@ -9,14 +9,14 @@ const validate_js_1 = require("../../../helpers/validate.js");
|
|
|
9
9
|
const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
|
|
10
10
|
const index_js_1 = require("../../../types/index.js");
|
|
11
11
|
/**
|
|
12
|
-
* Builds a Permit2 SignatureTransfer requirement for a direct
|
|
12
|
+
* Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
|
|
13
13
|
*
|
|
14
14
|
* Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
|
|
15
15
|
* it has no managed allowance expiration.
|
|
16
16
|
*
|
|
17
17
|
* @param params - SignatureTransfer parameters.
|
|
18
18
|
* @param params.token - ERC-20 token pulled through Permit2.
|
|
19
|
-
* @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
|
|
19
|
+
* @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
|
|
20
20
|
* @param params.amount - Exact `uint256` token amount authorized.
|
|
21
21
|
* @param params.chainId - Target chain id.
|
|
22
22
|
* @param params.nonce - Unused Permit2 unordered nonce.
|
|
@@ -28,7 +28,7 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
28
28
|
* @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
|
|
29
29
|
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
30
30
|
* @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
|
|
31
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
31
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
|
|
32
32
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
|
|
33
33
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
|
|
34
34
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
|
|
@@ -36,22 +36,22 @@ const index_js_1 = require("../../../types/index.js");
|
|
|
36
36
|
* @example
|
|
37
37
|
* ```ts
|
|
38
38
|
* import { addressesRegistry } from "@morpho-org/blue-sdk";
|
|
39
|
-
* import {
|
|
39
|
+
* import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
|
|
40
40
|
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
41
41
|
* import { mainnet } from "viem/chains";
|
|
42
42
|
*
|
|
43
|
-
* const requirement =
|
|
43
|
+
* const requirement = encodeErc20Permit2SignatureTransfer({
|
|
44
44
|
* token: addressesRegistry[mainnet.id].usdc,
|
|
45
|
-
* spender: getChainAddress(mainnet.id, "bundles.
|
|
45
|
+
* spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
|
|
46
46
|
* amount: 1_000_000n,
|
|
47
47
|
* chainId: mainnet.id,
|
|
48
48
|
* nonce: 0n,
|
|
49
49
|
* deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
|
|
50
50
|
* });
|
|
51
|
-
* // requirement satisfies Requirement<
|
|
51
|
+
* // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
const
|
|
54
|
+
const encodeErc20Permit2SignatureTransfer = (params) => {
|
|
55
55
|
const { token, spender, amount, chainId, nonce, deadline } = params;
|
|
56
56
|
// Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
|
|
57
57
|
// oversized allowance to maxUint256, which would desync the signed value from the requirement
|
|
@@ -79,7 +79,7 @@ const encodeErc20Permit2TransferFrom = (params) => {
|
|
|
79
79
|
(0, validateRequirementSpender_js_1.validateRequirementSpender)({
|
|
80
80
|
chainId,
|
|
81
81
|
spender,
|
|
82
|
-
allowed: ["blueBundlesV1"],
|
|
82
|
+
allowed: ["vaultBundlesV1", "blueBundlesV1"],
|
|
83
83
|
});
|
|
84
84
|
// getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
|
|
85
85
|
// getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
|
|
@@ -88,8 +88,8 @@ const encodeErc20Permit2TransferFrom = (params) => {
|
|
|
88
88
|
// this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
|
|
89
89
|
(0, morpho_ts_1.getChainAddress)(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
|
|
90
90
|
const action = {
|
|
91
|
-
type: "
|
|
92
|
-
args: { spender, amount, deadline },
|
|
91
|
+
type: "permit2SignatureTransfer",
|
|
92
|
+
args: { spender, amount, nonce, deadline },
|
|
93
93
|
};
|
|
94
94
|
return {
|
|
95
95
|
action,
|
|
@@ -120,4 +120,4 @@ const encodeErc20Permit2TransferFrom = (params) => {
|
|
|
120
120
|
},
|
|
121
121
|
};
|
|
122
122
|
};
|
|
123
|
-
exports.
|
|
123
|
+
exports.encodeErc20Permit2SignatureTransfer = encodeErc20Permit2SignatureTransfer;
|
|
@@ -6,7 +6,7 @@ export interface EncodeVaultSharesPermitParams {
|
|
|
6
6
|
readonly vault: Token;
|
|
7
7
|
/** Vault generation, which selects the standard V1 or two-field V2 domain. */
|
|
8
8
|
readonly version: "vaultV1" | "vaultV2";
|
|
9
|
-
/**
|
|
9
|
+
/** Registered fixed vault bundles spender. */
|
|
10
10
|
readonly spender: Address;
|
|
11
11
|
/** Account that owns the vault shares. */
|
|
12
12
|
readonly owner: Address;
|
|
@@ -27,15 +27,15 @@ export interface EncodeVaultSharesPermitParams {
|
|
|
27
27
|
*
|
|
28
28
|
* @param params.vault - Vault share token, including V1 permit-domain metadata when available.
|
|
29
29
|
* @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
|
|
30
|
-
* @param params.spender - Registered VaultExitBundlesV1 spender.
|
|
30
|
+
* @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
|
|
31
31
|
* @param params.owner - Account that owns and authorizes spending of the vault shares.
|
|
32
32
|
* @param params.chainId - Chain on which the vault and spender are deployed.
|
|
33
33
|
* @param params.nonce - Current vault permit nonce for the owner.
|
|
34
34
|
* @param params.amount - Vault-share allowance to authorize.
|
|
35
35
|
* @param params.deadline - Shared permit and bundle deadline.
|
|
36
|
-
* @returns A requirement whose `sign()` result can be embedded in
|
|
36
|
+
* @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
|
|
37
37
|
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
38
|
-
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not
|
|
38
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
|
|
39
39
|
* @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
|
|
40
40
|
* @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
|
|
41
41
|
* @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
|