@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,200 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { type BaseAction, type BundlesFundingArgs, type BundlesTokenRequirementSignature, type Erc2612RequirementSignature, type Metadata, type Permit2SignatureTransferAction, type PermitAction, type PermitRequirementSignature, type RequirementSignature, type TokenRequirementSignature, type Transaction } from "../../types/index.js";
|
|
3
|
+
/** Numeric permit kinds consumed by `TokenLib.pullToken`. */
|
|
4
|
+
export declare const BundlesPermitKind: {
|
|
5
|
+
readonly None: 0;
|
|
6
|
+
readonly ERC2612: 1;
|
|
7
|
+
readonly Permit2: 2;
|
|
8
|
+
};
|
|
9
|
+
/** A numeric permit kind consumed by `TokenLib.pullToken`. */
|
|
10
|
+
export type BundlesPermitKind = (typeof BundlesPermitKind)[keyof typeof BundlesPermitKind];
|
|
11
|
+
/** ABI-ready token permit consumed by fixed bundles deposit and funding entrypoints. */
|
|
12
|
+
export interface BundlesTokenPermit {
|
|
13
|
+
/** TokenLib permit dispatch kind. */
|
|
14
|
+
readonly kind: BundlesPermitKind;
|
|
15
|
+
/** ABI-encoded permit payload, or empty bytes for classic allowance funding. */
|
|
16
|
+
readonly data: Hex;
|
|
17
|
+
}
|
|
18
|
+
/** ABI-ready ERC-2612 share permit consumed by vault bundles. */
|
|
19
|
+
export interface BundleSharesPermit {
|
|
20
|
+
/** Exact vault-share allowance authorized by the permit. */
|
|
21
|
+
readonly value: bigint;
|
|
22
|
+
/** Vault permit nonce signed by the owner. */
|
|
23
|
+
readonly nonce: bigint;
|
|
24
|
+
/** Permit signature deadline. */
|
|
25
|
+
readonly deadline: bigint;
|
|
26
|
+
/** ECDSA recovery identifier, or zero for the empty sentinel. */
|
|
27
|
+
readonly v: number;
|
|
28
|
+
/** ECDSA signature `r`, or zero for the empty sentinel. */
|
|
29
|
+
readonly r: Hex;
|
|
30
|
+
/** ECDSA signature `s`, or zero for the empty sentinel. */
|
|
31
|
+
readonly s: Hex;
|
|
32
|
+
}
|
|
33
|
+
/** Compatibility alias for the canonical {@link BundleSharesPermit} tuple. */
|
|
34
|
+
export type BundlesSharesPermit = BundleSharesPermit;
|
|
35
|
+
/** Common deadline and referral fields shared by fixed bundles calls. */
|
|
36
|
+
export interface BundlesCommonParams {
|
|
37
|
+
/** Contract execution deadline. */
|
|
38
|
+
readonly deadline: bigint;
|
|
39
|
+
/** Optional WAD-scaled referral fee percentage. */
|
|
40
|
+
readonly referralFeePct?: bigint;
|
|
41
|
+
/** Recipient required when `referralFeePct` is positive. */
|
|
42
|
+
readonly referralFeeRecipient?: Address;
|
|
43
|
+
}
|
|
44
|
+
/** Normalized deadline and referral fields encoded by fixed bundles calls. */
|
|
45
|
+
export interface NormalizedBundlesCommonParams {
|
|
46
|
+
/** Validated contract execution deadline. */
|
|
47
|
+
readonly deadline: bigint;
|
|
48
|
+
/** Validated WAD-scaled referral fee percentage. */
|
|
49
|
+
readonly referralFeePct: bigint;
|
|
50
|
+
/** Referral recipient, or the zero address when fees are disabled. */
|
|
51
|
+
readonly referralFeeRecipient: Address;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates and normalizes a bundles deadline and referral fee configuration.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*
|
|
58
|
+
* @param params - Common bundles parameters.
|
|
59
|
+
* @returns Validated values with explicit zero defaults.
|
|
60
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
61
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds uint256.
|
|
62
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
63
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
64
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
|
|
65
|
+
*/
|
|
66
|
+
export declare const normalizeBundlesCommonParams: (params: BundlesCommonParams) => NormalizedBundlesCommonParams;
|
|
67
|
+
/**
|
|
68
|
+
* Resolves mutually exclusive ERC-20/native funding into the entrypoint amount and transaction value.
|
|
69
|
+
*
|
|
70
|
+
* @param params - Exclusive bundles funding.
|
|
71
|
+
* @param params.amount - ERC-20 funding in the token's smallest unit; mutually exclusive with `nativeAmount`.
|
|
72
|
+
* @param params.nativeAmount - Native funding in wei; mutually exclusive with `amount`.
|
|
73
|
+
* @returns The gross ABI asset amount and native transaction value.
|
|
74
|
+
* @throws {MixedBundlesFundingError} when both funding keys are present.
|
|
75
|
+
* @throws {NegativeInputError} when the selected amount is negative.
|
|
76
|
+
* @throws {NonPositiveInputError} when the selected amount is not positive.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { resolveBundlesFunding } from "@morpho-org/morpho-sdk";
|
|
80
|
+
*
|
|
81
|
+
* const funding = resolveBundlesFunding({ amount: 1_000_000n });
|
|
82
|
+
* // funding is { assets: 1_000_000n, value: 0n }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare const resolveBundlesFunding: (params: BundlesFundingArgs) => {
|
|
86
|
+
readonly assets: bigint;
|
|
87
|
+
readonly value: bigint;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Converts an optional signed token requirement into the ABI-ready TokenLib permit tuple.
|
|
91
|
+
*
|
|
92
|
+
* @param params - Expected funding values and optional signed requirement.
|
|
93
|
+
* @param params.userAddress - Account funding the operation; must match the signature owner.
|
|
94
|
+
* @param params.token - ERC-20 funding token; must match the signed asset.
|
|
95
|
+
* @param params.spender - Fixed bundles contract authorized to pull the token.
|
|
96
|
+
* @param params.amount - Exact pull amount in the token's smallest unit; must match both signed amount fields.
|
|
97
|
+
* @param params.requirementSignature - Optional signed ERC-2612 or Permit2 SignatureTransfer requirement; omit for allowance funding.
|
|
98
|
+
* @returns An empty, ERC-2612, or Permit2 SignatureTransfer token permit.
|
|
99
|
+
* @throws {UnexpectedRequirementSignatureError} when Permit2 AllowanceTransfer is supplied.
|
|
100
|
+
* @throws {DepositOwnerMismatchError} when the signature owner differs from `userAddress`.
|
|
101
|
+
* @throws {DepositAssetMismatchError} when the signed token differs from `token`.
|
|
102
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
|
|
103
|
+
* @throws {DepositSpenderMismatchError} when the signed spender differs from `spender`.
|
|
104
|
+
* @throws {BundlesRequirementSignatureMismatchError} when signature metadata is malformed.
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { getBundlesTokenPermit } from "@morpho-org/morpho-sdk";
|
|
108
|
+
* import { zeroAddress } from "viem";
|
|
109
|
+
*
|
|
110
|
+
* const permit = getBundlesTokenPermit({
|
|
111
|
+
* userAddress: zeroAddress,
|
|
112
|
+
* token: zeroAddress,
|
|
113
|
+
* spender: zeroAddress,
|
|
114
|
+
* amount: 1n,
|
|
115
|
+
* });
|
|
116
|
+
* // permit is { kind: 0, data: "0x" }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare const getBundlesTokenPermit: (params: {
|
|
120
|
+
readonly userAddress: Address;
|
|
121
|
+
readonly token: Address;
|
|
122
|
+
readonly spender: Address;
|
|
123
|
+
readonly amount: bigint;
|
|
124
|
+
readonly requirementSignature?: TokenRequirementSignature;
|
|
125
|
+
}) => BundlesTokenPermit;
|
|
126
|
+
/** @internal Normalizes a compact or serialized ECDSA signature for bundles permit tuples. */
|
|
127
|
+
export declare const normalizeBundlesSignature: (serializedSignature: Hex) => {
|
|
128
|
+
readonly v: number;
|
|
129
|
+
readonly r: Hex;
|
|
130
|
+
readonly s: Hex;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Converts an optional vault-share ERC-2612 requirement into the ABI-ready Permit tuple.
|
|
134
|
+
*
|
|
135
|
+
* @param params - Vault token, empty-sentinel deadline, and optional signed requirement.
|
|
136
|
+
* @param params.vault - Vault share token authorized by the permit.
|
|
137
|
+
* @param params.deadline - Unix timestamp in seconds used by the empty-permit sentinel.
|
|
138
|
+
* @param params.owner - Optional expected signature owner.
|
|
139
|
+
* @param params.spender - Optional expected fixed bundles contract authorized to pull shares.
|
|
140
|
+
* @param params.amount - Optional exact share allowance in the vault share token's smallest unit.
|
|
141
|
+
* @param params.requirementSignature - Optional signed ERC-2612 share requirement; omit for the empty-permit sentinel.
|
|
142
|
+
* @returns The signed share permit or the contract's empty-permit sentinel.
|
|
143
|
+
* @throws {BundlesPermitMismatchError} when the requirement kind, token, or signature is invalid.
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { getBundlesSharesPermit } from "@morpho-org/morpho-sdk";
|
|
147
|
+
* import { zeroAddress } from "viem";
|
|
148
|
+
*
|
|
149
|
+
* const permit = getBundlesSharesPermit({
|
|
150
|
+
* vault: zeroAddress,
|
|
151
|
+
* deadline: 1_900_000_000n,
|
|
152
|
+
* });
|
|
153
|
+
* // permit.value === 0n
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare const getBundlesSharesPermit: (params: {
|
|
157
|
+
readonly vault: Address;
|
|
158
|
+
readonly deadline: bigint;
|
|
159
|
+
readonly owner?: Address;
|
|
160
|
+
readonly spender?: Address;
|
|
161
|
+
readonly amount?: bigint;
|
|
162
|
+
readonly requirementSignature?: PermitRequirementSignature;
|
|
163
|
+
}) => BundleSharesPermit;
|
|
164
|
+
/**
|
|
165
|
+
* Selects the one token signature accepted by a bundles-funded call.
|
|
166
|
+
*
|
|
167
|
+
* @internal
|
|
168
|
+
*
|
|
169
|
+
* @param signatures - Signatures passed to `buildTx`.
|
|
170
|
+
* @param expectedRequirement - Signature requirement captured by this prepared operation.
|
|
171
|
+
* @returns The selected ERC-2612 or Permit2 SignatureTransfer signature.
|
|
172
|
+
* @throws {UnexpectedRequirementSignatureError} when a non-token signature is supplied.
|
|
173
|
+
* @throws {AmbiguousRequirementSignaturesError} when both token signature kinds are supplied.
|
|
174
|
+
*/
|
|
175
|
+
export declare const selectBundlesTokenRequirementSignature: (signatures: readonly RequirementSignature[] | undefined, expectedRequirement?: PermitAction | Permit2SignatureTransferAction) => BundlesTokenRequirementSignature | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* Selects the exact ERC-2612 vault-share permit produced for one prepared exit.
|
|
178
|
+
*
|
|
179
|
+
* @internal
|
|
180
|
+
*
|
|
181
|
+
* @param signatures - Signatures passed to the prepared operation's `buildTx` function.
|
|
182
|
+
* @param prepared - Exact share cap and permit requirement captured by this prepared operation.
|
|
183
|
+
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
184
|
+
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, was built for another
|
|
185
|
+
* share cap, or is supplied before this operation resolves its share cap.
|
|
186
|
+
*/
|
|
187
|
+
export declare const selectBundlesSharesRequirementSignature: (signatures: readonly RequirementSignature[] | undefined, prepared: {
|
|
188
|
+
readonly requiredShareAllowance: bigint | undefined;
|
|
189
|
+
readonly expectedRequirement?: PermitAction;
|
|
190
|
+
}) => Erc2612RequirementSignature | undefined;
|
|
191
|
+
/** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
|
|
192
|
+
export declare const getBundlesReferralFeeAssets: (assets: bigint, referralFeePct: bigint) => bigint;
|
|
193
|
+
/** @internal Finalizes a direct VaultBundlesV1 transaction with metadata and immutable action data. */
|
|
194
|
+
export declare const finalizeVaultBundlesV1Transaction: <TAction extends BaseAction>(params: {
|
|
195
|
+
readonly chainId: number;
|
|
196
|
+
readonly value: bigint;
|
|
197
|
+
readonly data: Hex;
|
|
198
|
+
readonly action: TAction;
|
|
199
|
+
readonly metadata?: Metadata;
|
|
200
|
+
}) => Readonly<Transaction<TAction>>;
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.finalizeVaultBundlesV1Transaction = exports.getBundlesReferralFeeAssets = exports.selectBundlesSharesRequirementSignature = exports.selectBundlesTokenRequirementSignature = exports.getBundlesSharesPermit = exports.normalizeBundlesSignature = exports.getBundlesTokenPermit = exports.resolveBundlesFunding = exports.normalizeBundlesCommonParams = exports.BundlesPermitKind = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
8
|
+
const index_js_2 = require("../../types/index.js");
|
|
9
|
+
/** Numeric permit kinds consumed by `TokenLib.pullToken`. */
|
|
10
|
+
exports.BundlesPermitKind = {
|
|
11
|
+
None: 0,
|
|
12
|
+
ERC2612: 1,
|
|
13
|
+
Permit2: 2,
|
|
14
|
+
};
|
|
15
|
+
const EMPTY_TOKEN_PERMIT = {
|
|
16
|
+
kind: exports.BundlesPermitKind.None,
|
|
17
|
+
data: "0x",
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Validates and normalizes a bundles deadline and referral fee configuration.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*
|
|
24
|
+
* @param params - Common bundles parameters.
|
|
25
|
+
* @returns Validated values with explicit zero defaults.
|
|
26
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
27
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds uint256.
|
|
28
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
29
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
30
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
|
|
31
|
+
*/
|
|
32
|
+
const normalizeBundlesCommonParams = (params) => {
|
|
33
|
+
if (params.deadline <= 0n) {
|
|
34
|
+
throw new index_js_2.NonPositiveInputError("deadline", params.deadline);
|
|
35
|
+
}
|
|
36
|
+
if (params.deadline > viem_1.maxUint256) {
|
|
37
|
+
throw new index_js_2.InputExceedsMaxError({
|
|
38
|
+
field: "deadline",
|
|
39
|
+
value: params.deadline,
|
|
40
|
+
max: viem_1.maxUint256,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const referralFeePct = params.referralFeePct ?? 0n;
|
|
44
|
+
if (referralFeePct < 0n) {
|
|
45
|
+
throw new index_js_2.NegativeInputError("referralFeePct", referralFeePct);
|
|
46
|
+
}
|
|
47
|
+
if (referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
48
|
+
throw new index_js_2.ReferralFeePctExceededError(referralFeePct);
|
|
49
|
+
}
|
|
50
|
+
if (referralFeePct > 0n &&
|
|
51
|
+
(params.referralFeeRecipient == null ||
|
|
52
|
+
(0, viem_1.isAddressEqual)(params.referralFeeRecipient, viem_1.zeroAddress))) {
|
|
53
|
+
throw new index_js_2.ReferralFeeRecipientMissingError();
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
deadline: params.deadline,
|
|
57
|
+
referralFeePct,
|
|
58
|
+
referralFeeRecipient: params.referralFeeRecipient ?? viem_1.zeroAddress,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.normalizeBundlesCommonParams = normalizeBundlesCommonParams;
|
|
62
|
+
/**
|
|
63
|
+
* Resolves mutually exclusive ERC-20/native funding into the entrypoint amount and transaction value.
|
|
64
|
+
*
|
|
65
|
+
* @param params - Exclusive bundles funding.
|
|
66
|
+
* @param params.amount - ERC-20 funding in the token's smallest unit; mutually exclusive with `nativeAmount`.
|
|
67
|
+
* @param params.nativeAmount - Native funding in wei; mutually exclusive with `amount`.
|
|
68
|
+
* @returns The gross ABI asset amount and native transaction value.
|
|
69
|
+
* @throws {MixedBundlesFundingError} when both funding keys are present.
|
|
70
|
+
* @throws {NegativeInputError} when the selected amount is negative.
|
|
71
|
+
* @throws {NonPositiveInputError} when the selected amount is not positive.
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { resolveBundlesFunding } from "@morpho-org/morpho-sdk";
|
|
75
|
+
*
|
|
76
|
+
* const funding = resolveBundlesFunding({ amount: 1_000_000n });
|
|
77
|
+
* // funding is { assets: 1_000_000n, value: 0n }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
const resolveBundlesFunding = (params) => {
|
|
81
|
+
const amount = "amount" in params ? params.amount : undefined;
|
|
82
|
+
const nativeAmount = "nativeAmount" in params ? params.nativeAmount : undefined;
|
|
83
|
+
if (amount != null && nativeAmount != null) {
|
|
84
|
+
throw new index_js_2.MixedBundlesFundingError();
|
|
85
|
+
}
|
|
86
|
+
const assets = amount ?? nativeAmount ?? 0n;
|
|
87
|
+
if (assets < 0n) {
|
|
88
|
+
throw new index_js_2.NegativeInputError(amount != null ? "amount" : "nativeAmount", assets);
|
|
89
|
+
}
|
|
90
|
+
if (assets === 0n) {
|
|
91
|
+
throw new index_js_2.NonPositiveInputError(amount != null ? "amount" : "nativeAmount", assets);
|
|
92
|
+
}
|
|
93
|
+
return { assets, value: nativeAmount ?? 0n };
|
|
94
|
+
};
|
|
95
|
+
exports.resolveBundlesFunding = resolveBundlesFunding;
|
|
96
|
+
/**
|
|
97
|
+
* Converts an optional signed token requirement into the ABI-ready TokenLib permit tuple.
|
|
98
|
+
*
|
|
99
|
+
* @param params - Expected funding values and optional signed requirement.
|
|
100
|
+
* @param params.userAddress - Account funding the operation; must match the signature owner.
|
|
101
|
+
* @param params.token - ERC-20 funding token; must match the signed asset.
|
|
102
|
+
* @param params.spender - Fixed bundles contract authorized to pull the token.
|
|
103
|
+
* @param params.amount - Exact pull amount in the token's smallest unit; must match both signed amount fields.
|
|
104
|
+
* @param params.requirementSignature - Optional signed ERC-2612 or Permit2 SignatureTransfer requirement; omit for allowance funding.
|
|
105
|
+
* @returns An empty, ERC-2612, or Permit2 SignatureTransfer token permit.
|
|
106
|
+
* @throws {UnexpectedRequirementSignatureError} when Permit2 AllowanceTransfer is supplied.
|
|
107
|
+
* @throws {DepositOwnerMismatchError} when the signature owner differs from `userAddress`.
|
|
108
|
+
* @throws {DepositAssetMismatchError} when the signed token differs from `token`.
|
|
109
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
|
|
110
|
+
* @throws {DepositSpenderMismatchError} when the signed spender differs from `spender`.
|
|
111
|
+
* @throws {BundlesRequirementSignatureMismatchError} when signature metadata is malformed.
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { getBundlesTokenPermit } from "@morpho-org/morpho-sdk";
|
|
115
|
+
* import { zeroAddress } from "viem";
|
|
116
|
+
*
|
|
117
|
+
* const permit = getBundlesTokenPermit({
|
|
118
|
+
* userAddress: zeroAddress,
|
|
119
|
+
* token: zeroAddress,
|
|
120
|
+
* spender: zeroAddress,
|
|
121
|
+
* amount: 1n,
|
|
122
|
+
* });
|
|
123
|
+
* // permit is { kind: 0, data: "0x" }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
const getBundlesTokenPermit = (params) => {
|
|
127
|
+
const { requirementSignature } = params;
|
|
128
|
+
if (requirementSignature == null)
|
|
129
|
+
return { ...EMPTY_TOKEN_PERMIT };
|
|
130
|
+
if (requirementSignature.action.type === "permit2") {
|
|
131
|
+
throw new index_js_2.UnexpectedRequirementSignatureError("permit");
|
|
132
|
+
}
|
|
133
|
+
if (!(0, viem_1.isAddressEqual)(requirementSignature.args.owner, params.userAddress)) {
|
|
134
|
+
throw new index_js_2.DepositOwnerMismatchError(params.userAddress, requirementSignature.args.owner);
|
|
135
|
+
}
|
|
136
|
+
if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, params.token)) {
|
|
137
|
+
throw new index_js_2.DepositAssetMismatchError(params.token, requirementSignature.args.asset);
|
|
138
|
+
}
|
|
139
|
+
if (requirementSignature.args.amount !== params.amount ||
|
|
140
|
+
requirementSignature.action.args.amount !== params.amount) {
|
|
141
|
+
throw new index_js_2.DepositAmountMismatchError(params.amount, requirementSignature.args.amount);
|
|
142
|
+
}
|
|
143
|
+
if (!(0, viem_1.isAddressEqual)(requirementSignature.action.args.spender, params.spender)) {
|
|
144
|
+
throw new index_js_2.DepositSpenderMismatchError(params.spender, requirementSignature.action.args.spender);
|
|
145
|
+
}
|
|
146
|
+
if (requirementSignature.action.args.deadline !==
|
|
147
|
+
requirementSignature.args.deadline) {
|
|
148
|
+
throw new index_js_2.BundlesRequirementSignatureMismatchError({
|
|
149
|
+
field: "deadline",
|
|
150
|
+
expected: String(requirementSignature.args.deadline),
|
|
151
|
+
actual: String(requirementSignature.action.args.deadline),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (requirementSignature.action.type === "permit2SignatureTransfer" &&
|
|
155
|
+
requirementSignature.action.args.nonce !== requirementSignature.args.nonce) {
|
|
156
|
+
throw new index_js_2.BundlesRequirementSignatureMismatchError({
|
|
157
|
+
field: "nonce",
|
|
158
|
+
expected: String(requirementSignature.args.nonce),
|
|
159
|
+
actual: String(requirementSignature.action.args.nonce),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (requirementSignature.action.type === "permit2SignatureTransfer") {
|
|
163
|
+
return {
|
|
164
|
+
kind: exports.BundlesPermitKind.Permit2,
|
|
165
|
+
data: (0, viem_1.encodeAbiParameters)([
|
|
166
|
+
{ type: "uint256", name: "nonce" },
|
|
167
|
+
{ type: "uint256", name: "deadline" },
|
|
168
|
+
{ type: "bytes", name: "signature" },
|
|
169
|
+
], [
|
|
170
|
+
requirementSignature.args.nonce,
|
|
171
|
+
requirementSignature.args.deadline,
|
|
172
|
+
requirementSignature.args.signature,
|
|
173
|
+
]),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
let signature;
|
|
177
|
+
try {
|
|
178
|
+
signature = (0, exports.normalizeBundlesSignature)(requirementSignature.args.signature);
|
|
179
|
+
}
|
|
180
|
+
catch (cause) {
|
|
181
|
+
if (cause instanceof index_js_2.BundlesPermitMismatchError) {
|
|
182
|
+
throw new index_js_2.BundlesRequirementSignatureMismatchError({
|
|
183
|
+
field: "signature",
|
|
184
|
+
expected: cause.expected,
|
|
185
|
+
actual: cause.actual,
|
|
186
|
+
cause,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
throw cause;
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
kind: exports.BundlesPermitKind.ERC2612,
|
|
193
|
+
data: (0, viem_1.encodeAbiParameters)([
|
|
194
|
+
{ type: "uint256", name: "deadline" },
|
|
195
|
+
{ type: "uint8", name: "v" },
|
|
196
|
+
{ type: "bytes32", name: "r" },
|
|
197
|
+
{ type: "bytes32", name: "s" },
|
|
198
|
+
], [
|
|
199
|
+
requirementSignature.args.deadline,
|
|
200
|
+
signature.v,
|
|
201
|
+
signature.r,
|
|
202
|
+
signature.s,
|
|
203
|
+
]),
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
exports.getBundlesTokenPermit = getBundlesTokenPermit;
|
|
207
|
+
/** @internal Normalizes a compact or serialized ECDSA signature for bundles permit tuples. */
|
|
208
|
+
const normalizeBundlesSignature = (serializedSignature) => {
|
|
209
|
+
let parsed;
|
|
210
|
+
try {
|
|
211
|
+
parsed =
|
|
212
|
+
(0, viem_1.size)(serializedSignature) === 64
|
|
213
|
+
? (0, viem_1.compactSignatureToSignature)((0, viem_1.parseCompactSignature)(serializedSignature))
|
|
214
|
+
: (0, viem_1.parseSignature)(serializedSignature);
|
|
215
|
+
}
|
|
216
|
+
catch (cause) {
|
|
217
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
218
|
+
field: "signature",
|
|
219
|
+
expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
|
|
220
|
+
actual: serializedSignature,
|
|
221
|
+
cause,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
const normalizedV = parsed.v ??
|
|
225
|
+
(parsed.yParity == null ? undefined : BigInt(parsed.yParity + 27));
|
|
226
|
+
if (normalizedV == null) {
|
|
227
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
228
|
+
field: "signature",
|
|
229
|
+
expected: "a signature containing v or yParity",
|
|
230
|
+
actual: serializedSignature,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return { v: Number(normalizedV), r: parsed.r, s: parsed.s };
|
|
234
|
+
};
|
|
235
|
+
exports.normalizeBundlesSignature = normalizeBundlesSignature;
|
|
236
|
+
/**
|
|
237
|
+
* Converts an optional vault-share ERC-2612 requirement into the ABI-ready Permit tuple.
|
|
238
|
+
*
|
|
239
|
+
* @param params - Vault token, empty-sentinel deadline, and optional signed requirement.
|
|
240
|
+
* @param params.vault - Vault share token authorized by the permit.
|
|
241
|
+
* @param params.deadline - Unix timestamp in seconds used by the empty-permit sentinel.
|
|
242
|
+
* @param params.owner - Optional expected signature owner.
|
|
243
|
+
* @param params.spender - Optional expected fixed bundles contract authorized to pull shares.
|
|
244
|
+
* @param params.amount - Optional exact share allowance in the vault share token's smallest unit.
|
|
245
|
+
* @param params.requirementSignature - Optional signed ERC-2612 share requirement; omit for the empty-permit sentinel.
|
|
246
|
+
* @returns The signed share permit or the contract's empty-permit sentinel.
|
|
247
|
+
* @throws {BundlesPermitMismatchError} when the requirement kind, token, or signature is invalid.
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { getBundlesSharesPermit } from "@morpho-org/morpho-sdk";
|
|
251
|
+
* import { zeroAddress } from "viem";
|
|
252
|
+
*
|
|
253
|
+
* const permit = getBundlesSharesPermit({
|
|
254
|
+
* vault: zeroAddress,
|
|
255
|
+
* deadline: 1_900_000_000n,
|
|
256
|
+
* });
|
|
257
|
+
* // permit.value === 0n
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
const getBundlesSharesPermit = (params) => {
|
|
261
|
+
const { requirementSignature } = params;
|
|
262
|
+
if (requirementSignature == null) {
|
|
263
|
+
return {
|
|
264
|
+
value: 0n,
|
|
265
|
+
nonce: 0n,
|
|
266
|
+
deadline: params.deadline,
|
|
267
|
+
v: 0,
|
|
268
|
+
r: viem_1.zeroHash,
|
|
269
|
+
s: viem_1.zeroHash,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
if (requirementSignature.action.type !== "permit") {
|
|
273
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
274
|
+
field: "type",
|
|
275
|
+
expected: "permit",
|
|
276
|
+
actual: requirementSignature.action.type,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, params.vault)) {
|
|
280
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
281
|
+
field: "asset",
|
|
282
|
+
expected: params.vault,
|
|
283
|
+
actual: requirementSignature.args.asset,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
if (params.owner != null &&
|
|
287
|
+
!(0, viem_1.isAddressEqual)(requirementSignature.args.owner, params.owner)) {
|
|
288
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
289
|
+
field: "owner",
|
|
290
|
+
expected: params.owner,
|
|
291
|
+
actual: requirementSignature.args.owner,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
if (params.spender != null &&
|
|
295
|
+
!(0, viem_1.isAddressEqual)(requirementSignature.action.args.spender, params.spender)) {
|
|
296
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
297
|
+
field: "spender",
|
|
298
|
+
expected: params.spender,
|
|
299
|
+
actual: requirementSignature.action.args.spender,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
if (params.amount != null &&
|
|
303
|
+
(requirementSignature.args.amount !== params.amount ||
|
|
304
|
+
requirementSignature.action.args.amount !== params.amount)) {
|
|
305
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
306
|
+
field: "amount",
|
|
307
|
+
expected: String(params.amount),
|
|
308
|
+
actual: String(requirementSignature.args.amount),
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
if ((params.owner != null || params.spender != null || params.amount != null) &&
|
|
312
|
+
requirementSignature.action.args.deadline !==
|
|
313
|
+
requirementSignature.args.deadline) {
|
|
314
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
315
|
+
field: "deadline",
|
|
316
|
+
expected: String(requirementSignature.args.deadline),
|
|
317
|
+
actual: String(requirementSignature.action.args.deadline),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
const signature = (0, exports.normalizeBundlesSignature)(requirementSignature.args.signature);
|
|
321
|
+
return {
|
|
322
|
+
value: requirementSignature.args.amount,
|
|
323
|
+
nonce: requirementSignature.args.nonce,
|
|
324
|
+
deadline: requirementSignature.args.deadline,
|
|
325
|
+
...signature,
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
exports.getBundlesSharesPermit = getBundlesSharesPermit;
|
|
329
|
+
/**
|
|
330
|
+
* Selects the one token signature accepted by a bundles-funded call.
|
|
331
|
+
*
|
|
332
|
+
* @internal
|
|
333
|
+
*
|
|
334
|
+
* @param signatures - Signatures passed to `buildTx`.
|
|
335
|
+
* @param expectedRequirement - Signature requirement captured by this prepared operation.
|
|
336
|
+
* @returns The selected ERC-2612 or Permit2 SignatureTransfer signature.
|
|
337
|
+
* @throws {UnexpectedRequirementSignatureError} when a non-token signature is supplied.
|
|
338
|
+
* @throws {AmbiguousRequirementSignaturesError} when both token signature kinds are supplied.
|
|
339
|
+
*/
|
|
340
|
+
const selectBundlesTokenRequirementSignature = (signatures, expectedRequirement) => {
|
|
341
|
+
if (signatures == null || signatures.length === 0)
|
|
342
|
+
return undefined;
|
|
343
|
+
const selected = signatures.filter((signature) => signature.action.type === "permit" ||
|
|
344
|
+
signature.action.type === "permit2SignatureTransfer");
|
|
345
|
+
if (selected.length !== signatures.length) {
|
|
346
|
+
const unexpected = signatures.find((signature) => signature.action.type !== "permit" &&
|
|
347
|
+
signature.action.type !== "permit2SignatureTransfer");
|
|
348
|
+
throw new index_js_2.UnexpectedRequirementSignatureError(unexpected?.action.type === "authorization"
|
|
349
|
+
? "authorization"
|
|
350
|
+
: unexpected?.action.type === "midnightOfferRootSignature"
|
|
351
|
+
? "midnightOfferRootSignature"
|
|
352
|
+
: "permit");
|
|
353
|
+
}
|
|
354
|
+
if (selected.length > 1) {
|
|
355
|
+
throw new index_js_2.AmbiguousRequirementSignaturesError("permit", selected.length);
|
|
356
|
+
}
|
|
357
|
+
const selectedSignature = selected[0];
|
|
358
|
+
if (selectedSignature == null)
|
|
359
|
+
return undefined;
|
|
360
|
+
validatePreparedBundlesRequirementSignature(selectedSignature, expectedRequirement);
|
|
361
|
+
return selectedSignature;
|
|
362
|
+
};
|
|
363
|
+
exports.selectBundlesTokenRequirementSignature = selectBundlesTokenRequirementSignature;
|
|
364
|
+
const validatePreparedBundlesRequirementSignature = (signature, expectedRequirement) => {
|
|
365
|
+
if (expectedRequirement == null) {
|
|
366
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
367
|
+
field: "nonce",
|
|
368
|
+
expected: "the nonce from getRequirements()",
|
|
369
|
+
actual: String(signature.args.nonce),
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
if (signature.action.type !== expectedRequirement.type) {
|
|
373
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
374
|
+
field: "type",
|
|
375
|
+
expected: expectedRequirement.type,
|
|
376
|
+
actual: signature.action.type,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
const expectedArgs = expectedRequirement.args;
|
|
380
|
+
if (!(0, viem_1.isAddressEqual)(signature.action.args.spender, expectedArgs.spender)) {
|
|
381
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
382
|
+
field: "spender",
|
|
383
|
+
expected: expectedArgs.spender,
|
|
384
|
+
actual: signature.action.args.spender,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
if (signature.args.amount !== expectedArgs.amount ||
|
|
388
|
+
signature.action.args.amount !== expectedArgs.amount) {
|
|
389
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
390
|
+
field: "amount",
|
|
391
|
+
expected: String(expectedArgs.amount),
|
|
392
|
+
actual: String(signature.args.amount),
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
if (signature.args.deadline !== expectedArgs.deadline ||
|
|
396
|
+
signature.action.args.deadline !== expectedArgs.deadline) {
|
|
397
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
398
|
+
field: "deadline",
|
|
399
|
+
expected: String(expectedArgs.deadline),
|
|
400
|
+
actual: String(signature.args.deadline),
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (expectedArgs.nonce == null ||
|
|
404
|
+
signature.args.nonce !== expectedArgs.nonce ||
|
|
405
|
+
signature.action.args.nonce !== expectedArgs.nonce) {
|
|
406
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
407
|
+
field: "nonce",
|
|
408
|
+
expected: expectedArgs.nonce == null
|
|
409
|
+
? "the nonce from getRequirements()"
|
|
410
|
+
: String(expectedArgs.nonce),
|
|
411
|
+
actual: String(signature.args.nonce),
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* Selects the exact ERC-2612 vault-share permit produced for one prepared exit.
|
|
417
|
+
*
|
|
418
|
+
* @internal
|
|
419
|
+
*
|
|
420
|
+
* @param signatures - Signatures passed to the prepared operation's `buildTx` function.
|
|
421
|
+
* @param prepared - Exact share cap and permit requirement captured by this prepared operation.
|
|
422
|
+
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
423
|
+
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, was built for another
|
|
424
|
+
* share cap, or is supplied before this operation resolves its share cap.
|
|
425
|
+
*/
|
|
426
|
+
const selectBundlesSharesRequirementSignature = (signatures, prepared) => {
|
|
427
|
+
const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, { permit: true });
|
|
428
|
+
if (permit == null)
|
|
429
|
+
return undefined;
|
|
430
|
+
const { action } = permit;
|
|
431
|
+
if (action.type !== "permit") {
|
|
432
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
433
|
+
field: "type",
|
|
434
|
+
expected: "permit",
|
|
435
|
+
actual: action.type,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
if (prepared.requiredShareAllowance == null ||
|
|
439
|
+
permit.args.amount !== prepared.requiredShareAllowance ||
|
|
440
|
+
action.args.amount !== prepared.requiredShareAllowance) {
|
|
441
|
+
throw new index_js_2.BundlesPermitMismatchError({
|
|
442
|
+
field: "amount",
|
|
443
|
+
expected: prepared.requiredShareAllowance == null
|
|
444
|
+
? "the current cap from getRequirements()"
|
|
445
|
+
: String(prepared.requiredShareAllowance),
|
|
446
|
+
actual: String(permit.args.amount),
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
const selectedPermit = { args: permit.args, action };
|
|
450
|
+
validatePreparedBundlesRequirementSignature(selectedPermit, prepared.expectedRequirement);
|
|
451
|
+
return selectedPermit;
|
|
452
|
+
};
|
|
453
|
+
exports.selectBundlesSharesRequirementSignature = selectBundlesSharesRequirementSignature;
|
|
454
|
+
/** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
|
|
455
|
+
const getBundlesReferralFeeAssets = (assets, referralFeePct) => blue_sdk_1.MathLib.mulDivDown(assets, referralFeePct, blue_sdk_1.MathLib.WAD);
|
|
456
|
+
exports.getBundlesReferralFeeAssets = getBundlesReferralFeeAssets;
|
|
457
|
+
/** @internal Finalizes a direct VaultBundlesV1 transaction with metadata and immutable action data. */
|
|
458
|
+
const finalizeVaultBundlesV1Transaction = (params) => {
|
|
459
|
+
let transaction = {
|
|
460
|
+
to: (0, morpho_ts_1.getChainAddress)(params.chainId, "bundles.vaultBundlesV1"),
|
|
461
|
+
value: params.value,
|
|
462
|
+
data: params.data,
|
|
463
|
+
};
|
|
464
|
+
if (params.metadata != null) {
|
|
465
|
+
transaction = (0, index_js_1.addTransactionMetadata)(transaction, params.metadata);
|
|
466
|
+
}
|
|
467
|
+
return (0, morpho_ts_1.deepFreeze)({ ...transaction, action: params.action });
|
|
468
|
+
};
|
|
469
|
+
exports.finalizeVaultBundlesV1Transaction = finalizeVaultBundlesV1Transaction;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { BundleSharesPermit, BundlesCommonParams, BundlesSharesPermit, BundlesTokenPermit, NormalizedBundlesCommonParams, } from "./common.js";
|
|
2
|
+
export { BundlesPermitKind, getBundlesSharesPermit, getBundlesTokenPermit, resolveBundlesFunding, } from "./common.js";
|
|
3
|
+
export * from "./resolveBundlesTokenRequirements.js";
|