@morpho-org/morpho-sdk 9.6.0-next.0 → 9.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v6-to-v7.md +1 -1
- package/README.md +123 -3
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.js +39 -32
- package/lib/cjs/actions/midnight/cancelAndMake.js +20 -98
- package/lib/cjs/actions/midnight/index.d.ts +2 -0
- package/lib/cjs/actions/midnight/index.js +2 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +5 -6
- package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +39 -0
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +91 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +31 -32
- package/lib/cjs/actions/midnight/takeBorrow.js +24 -23
- package/lib/cjs/actions/midnight/takeLend.js +24 -23
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
- package/lib/cjs/actions/midnight/takeWithdraw.js +24 -23
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +104 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +7 -7
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +1 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/entities/index.d.ts +5 -5
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +77 -3
- package/lib/cjs/entities/midnight/midnight.js +174 -0
- package/lib/cjs/entities/midnight/types.d.ts +16 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +12 -46
- package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -0
- package/lib/cjs/entities/requirements/getErc2612Permit.js +60 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +3 -3
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +10 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -33
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +6 -7
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/deadShares.js +0 -2
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +1 -0
- package/lib/cjs/helpers/signAndVerifyTypedData.js +12 -5
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +129 -0
- package/lib/cjs/helpers/validateMidnightCollateralBatch.d.ts +15 -0
- package/lib/cjs/helpers/validateMidnightCollateralBatch.js +28 -0
- package/lib/cjs/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
- package/lib/cjs/helpers/validateMidnightCollateralSupplies.js +28 -0
- package/lib/cjs/helpers/validatePositiveInput.d.ts +10 -0
- package/lib/cjs/helpers/validatePositiveInput.js +18 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +18 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +5 -5
- package/lib/cjs/transactionPlan/approval.d.ts +2 -0
- package/lib/cjs/transactionPlan/approval.js +16 -0
- package/lib/cjs/transactionPlan/error.d.ts +145 -0
- package/lib/cjs/transactionPlan/error.js +186 -0
- package/lib/cjs/transactionPlan/getTokenPermit.d.ts +11 -0
- package/lib/cjs/transactionPlan/getTokenPermit.js +18 -0
- package/lib/cjs/transactionPlan/index.d.ts +9 -0
- package/lib/cjs/transactionPlan/index.js +24 -0
- package/lib/cjs/transactionPlan/intent.d.ts +51 -0
- package/lib/cjs/transactionPlan/intent.js +54 -0
- package/lib/cjs/transactionPlan/permit.d.ts +13 -0
- package/lib/cjs/transactionPlan/permit.js +145 -0
- package/lib/cjs/transactionPlan/plan.d.ts +99 -0
- package/lib/cjs/transactionPlan/plan.js +232 -0
- package/lib/cjs/transactionPlan/requirements.d.ts +44 -0
- package/lib/cjs/transactionPlan/requirements.js +79 -0
- package/lib/cjs/transactionPlan/serde.d.ts +33 -0
- package/lib/cjs/transactionPlan/serde.js +205 -0
- package/lib/cjs/transactionPlan/types.d.ts +91 -0
- package/lib/cjs/transactionPlan/types.js +2 -0
- package/lib/cjs/transactionPlan/validateActions.d.ts +8 -0
- package/lib/cjs/transactionPlan/validateActions.js +19 -0
- package/lib/cjs/transactionPlan/validation.d.ts +17 -0
- package/lib/cjs/transactionPlan/validation.js +70 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +81 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +211 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +77 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +190 -0
- package/lib/cjs/transactionPlan/version.d.ts +2 -0
- package/lib/cjs/transactionPlan/version.js +9 -0
- package/lib/cjs/types/action.d.ts +18 -3
- package/lib/cjs/types/error.d.ts +23 -2
- package/lib/cjs/types/error.js +45 -5
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.js +39 -32
- package/lib/esm/actions/midnight/cancelAndMake.js +25 -103
- package/lib/esm/actions/midnight/index.d.ts +2 -0
- package/lib/esm/actions/midnight/index.js +2 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +5 -6
- package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +39 -0
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +87 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -34
- package/lib/esm/actions/midnight/takeBorrow.js +25 -24
- package/lib/esm/actions/midnight/takeLend.js +25 -24
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
- package/lib/esm/actions/midnight/takeWithdraw.js +25 -24
- package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +100 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +8 -8
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/index.d.ts +5 -5
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +77 -3
- package/lib/esm/entities/midnight/midnight.js +176 -2
- package/lib/esm/entities/midnight/types.d.ts +16 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +14 -48
- package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -0
- package/lib/esm/entities/requirements/getErc2612Permit.js +57 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +3 -3
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +10 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -33
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +1 -3
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +1 -0
- package/lib/esm/helpers/signAndVerifyTypedData.js +13 -6
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +124 -0
- package/lib/esm/helpers/validateMidnightCollateralBatch.d.ts +15 -0
- package/lib/esm/helpers/validateMidnightCollateralBatch.js +25 -0
- package/lib/esm/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
- package/lib/esm/helpers/validateMidnightCollateralSupplies.js +24 -0
- package/lib/esm/helpers/validatePositiveInput.d.ts +10 -0
- package/lib/esm/helpers/validatePositiveInput.js +14 -0
- package/lib/esm/index.d.ts +2 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/transactionPlan/approval.d.ts +2 -0
- package/lib/esm/transactionPlan/approval.js +13 -0
- package/lib/esm/transactionPlan/error.d.ts +145 -0
- package/lib/esm/transactionPlan/error.js +175 -0
- package/lib/esm/transactionPlan/getTokenPermit.d.ts +11 -0
- package/lib/esm/transactionPlan/getTokenPermit.js +15 -0
- package/lib/esm/transactionPlan/index.d.ts +9 -0
- package/lib/esm/transactionPlan/index.js +5 -0
- package/lib/esm/transactionPlan/intent.d.ts +51 -0
- package/lib/esm/transactionPlan/intent.js +51 -0
- package/lib/esm/transactionPlan/permit.d.ts +13 -0
- package/lib/esm/transactionPlan/permit.js +140 -0
- package/lib/esm/transactionPlan/plan.d.ts +99 -0
- package/lib/esm/transactionPlan/plan.js +226 -0
- package/lib/esm/transactionPlan/requirements.d.ts +44 -0
- package/lib/esm/transactionPlan/requirements.js +74 -0
- package/lib/esm/transactionPlan/serde.d.ts +33 -0
- package/lib/esm/transactionPlan/serde.js +201 -0
- package/lib/esm/transactionPlan/types.d.ts +91 -0
- package/lib/esm/transactionPlan/types.js +1 -0
- package/lib/esm/transactionPlan/validateActions.d.ts +8 -0
- package/lib/esm/transactionPlan/validateActions.js +16 -0
- package/lib/esm/transactionPlan/validation.d.ts +17 -0
- package/lib/esm/transactionPlan/validation.js +64 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +81 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.js +206 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +77 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +185 -0
- package/lib/esm/transactionPlan/version.d.ts +2 -0
- package/lib/esm/transactionPlan/version.js +6 -0
- package/lib/esm/types/action.d.ts +18 -3
- package/lib/esm/types/error.d.ts +23 -2
- package/lib/esm/types/error.js +40 -3
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +8 -7
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { InvalidTreeError } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { getChainAddresses } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { isAddressEqual, zeroAddress, zeroHash } from "viem";
|
|
4
|
+
import { EmptyMidnightCollateralSuppliesError, MidnightReplacementGroupCancelledError, UnsupportedMidnightAuthorizationTargetError, } from "../types/index.js";
|
|
5
|
+
import { validateMidnightAddress } from "./validateMidnightAccount.js";
|
|
6
|
+
import { validateMidnightUint128Field } from "./validateMidnightBounds.js";
|
|
7
|
+
import { validateMidnightCollateralSupplies } from "./validateMidnightCollateralSupplies.js";
|
|
8
|
+
import { validateMidnightMarket } from "./validateMidnightMarket.js";
|
|
9
|
+
import { validatePositiveInput } from "./validatePositiveInput.js";
|
|
10
|
+
/** Blue market argument for `MidnightBundlesV2` calls that park no loan assets. */
|
|
11
|
+
const emptyBlueMarket = {
|
|
12
|
+
loanToken: zeroAddress,
|
|
13
|
+
collateralToken: zeroAddress,
|
|
14
|
+
oracle: zeroAddress,
|
|
15
|
+
irm: zeroAddress,
|
|
16
|
+
lltv: 0n,
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Validates publication content after snapshot and hex-shape validation.
|
|
20
|
+
*
|
|
21
|
+
* @param params - Publication, chain deployment, and groups cancelled by this bundle.
|
|
22
|
+
* @returns Nothing when publication content and funding inputs are valid.
|
|
23
|
+
* @throws {InvalidTreeError} when the root is zero, payload empty, or groups empty.
|
|
24
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
25
|
+
* @throws {MidnightCalldataEncodingError} when the ratifier or collateral market address is malformed.
|
|
26
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when the ratifier is not supported.
|
|
27
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is cancelled.
|
|
28
|
+
* @throws {NonPositiveInputError} when Blue funding or a collateral supply is not positive.
|
|
29
|
+
* @throws {InputExceedsMaxError} when funding or collateral supply totals exceed uint128.
|
|
30
|
+
* @throws {EmptyMidnightCollateralSuppliesError} when collateral supplies are empty.
|
|
31
|
+
* @throws {ChainIdMismatchError} when the collateral market targets another chain.
|
|
32
|
+
* @throws {MidnightMarketAddressMismatchError} when its Midnight deployment differs.
|
|
33
|
+
* @throws {UnknownCollateralIndexError} when a supply index is not configured.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export const validateMidnightCancelAndMakePublication = ({ publication, chainId, cancelledGroups, }) => {
|
|
37
|
+
if (publication.root === zeroHash) {
|
|
38
|
+
throw new InvalidTreeError("Offer root cannot be zero.");
|
|
39
|
+
}
|
|
40
|
+
if (publication.payload === "0x") {
|
|
41
|
+
throw new InvalidTreeError("Offer payload cannot be empty.");
|
|
42
|
+
}
|
|
43
|
+
if (publication.groups.length === 0) {
|
|
44
|
+
throw new InvalidTreeError("Offer groups cannot be empty.");
|
|
45
|
+
}
|
|
46
|
+
const { priceRatifierV1, rateRatifierV1 } = getChainAddresses(chainId);
|
|
47
|
+
const supportedTargets = [priceRatifierV1, rateRatifierV1].filter((target) => target != null);
|
|
48
|
+
validateMidnightAddress("publication.ratifier", publication.ratifier);
|
|
49
|
+
if (!supportedTargets.some((target) => isAddressEqual(publication.ratifier, target))) {
|
|
50
|
+
throw new UnsupportedMidnightAuthorizationTargetError({
|
|
51
|
+
authorized: publication.ratifier,
|
|
52
|
+
chainId,
|
|
53
|
+
supportedTargets,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
for (const group of publication.groups) {
|
|
57
|
+
if (cancelledGroups.has(group.toLowerCase())) {
|
|
58
|
+
throw new MidnightReplacementGroupCancelledError({ group });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (publication.blueSupply != null) {
|
|
62
|
+
// Validation only; rejects non-positive Blue supply amounts.
|
|
63
|
+
validatePositiveInput("blueSupply.assets", publication.blueSupply.assets);
|
|
64
|
+
validateMidnightUint128Field("blueSupply.assets", publication.blueSupply.assets);
|
|
65
|
+
}
|
|
66
|
+
if (publication.collateral != null) {
|
|
67
|
+
if (publication.collateral.supplies.length === 0) {
|
|
68
|
+
throw new EmptyMidnightCollateralSuppliesError();
|
|
69
|
+
}
|
|
70
|
+
validateMidnightMarket({
|
|
71
|
+
market: publication.collateral.market,
|
|
72
|
+
chainId,
|
|
73
|
+
});
|
|
74
|
+
// Validation only; checks supply entries and their per-index totals.
|
|
75
|
+
validateMidnightCollateralSupplies({
|
|
76
|
+
market: publication.collateral.market,
|
|
77
|
+
field: "collateral.supplies",
|
|
78
|
+
supplies: publication.collateral.supplies,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Copies validated publication fields and supplies zero ABI defaults for omitted steps.
|
|
84
|
+
*
|
|
85
|
+
* @param publication - Snapshotted publication, or undefined for cancellation only.
|
|
86
|
+
* @returns ABI defaults and copied publication fields, without mutating the input.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export const normalizeMidnightCancelAndMakePublication = (publication) => {
|
|
90
|
+
const supplies = (publication?.collateral?.supplies ?? []).map(({ collateralIndex, assets }) => ({ collateralIndex, assets }));
|
|
91
|
+
const blueSupply = publication?.blueSupply == null
|
|
92
|
+
? undefined
|
|
93
|
+
: {
|
|
94
|
+
market: {
|
|
95
|
+
loanToken: publication.blueSupply.market.loanToken,
|
|
96
|
+
collateralToken: publication.blueSupply.market.collateralToken,
|
|
97
|
+
oracle: publication.blueSupply.market.oracle,
|
|
98
|
+
irm: publication.blueSupply.market.irm,
|
|
99
|
+
lltv: publication.blueSupply.market.lltv,
|
|
100
|
+
},
|
|
101
|
+
assets: publication.blueSupply.assets,
|
|
102
|
+
callbackSalt: publication.blueSupply.callbackSalt,
|
|
103
|
+
};
|
|
104
|
+
const signature = publication?.rootSignature ?? {
|
|
105
|
+
height: 0n,
|
|
106
|
+
nonce: 0n,
|
|
107
|
+
deadline: 0n,
|
|
108
|
+
v: 0,
|
|
109
|
+
r: zeroHash,
|
|
110
|
+
s: zeroHash,
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
supplies,
|
|
114
|
+
blueSupply,
|
|
115
|
+
signature,
|
|
116
|
+
blueMarket: blueSupply?.market ?? emptyBlueMarket,
|
|
117
|
+
assetsToPark: blueSupply?.assets ?? 0n,
|
|
118
|
+
callbackSalt: blueSupply?.callbackSalt ?? zeroHash,
|
|
119
|
+
ratifier: publication?.ratifier ?? zeroAddress,
|
|
120
|
+
root: publication?.root ?? zeroHash,
|
|
121
|
+
groups: [...(publication?.groups ?? [])],
|
|
122
|
+
payload: publication?.payload ?? "0x",
|
|
123
|
+
};
|
|
124
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MidnightCollateralTransfer } from "../types/action.js";
|
|
2
|
+
/**
|
|
3
|
+
* Rejects empty batches and repeated collateral indexes.
|
|
4
|
+
* @internal
|
|
5
|
+
* @param transfers - Ordered collateral transfers.
|
|
6
|
+
* @param emptyError - Operation-specific error thrown for an empty batch.
|
|
7
|
+
* @returns Nothing.
|
|
8
|
+
* @throws `emptyError` when `transfers` is empty.
|
|
9
|
+
* @throws {DuplicateMidnightCollateralIndexError} when an index appears twice.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* validateMidnightCollateralBatch(supplies, new EmptyMidnightCollateralSuppliesError());
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateMidnightCollateralBatch(transfers: readonly MidnightCollateralTransfer[], emptyError: Error): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DuplicateMidnightCollateralIndexError } from "../types/error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Rejects empty batches and repeated collateral indexes.
|
|
4
|
+
* @internal
|
|
5
|
+
* @param transfers - Ordered collateral transfers.
|
|
6
|
+
* @param emptyError - Operation-specific error thrown for an empty batch.
|
|
7
|
+
* @returns Nothing.
|
|
8
|
+
* @throws `emptyError` when `transfers` is empty.
|
|
9
|
+
* @throws {DuplicateMidnightCollateralIndexError} when an index appears twice.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* validateMidnightCollateralBatch(supplies, new EmptyMidnightCollateralSuppliesError());
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function validateMidnightCollateralBatch(transfers, emptyError) {
|
|
16
|
+
if (transfers.length === 0)
|
|
17
|
+
throw emptyError;
|
|
18
|
+
const indexes = new Set();
|
|
19
|
+
for (const { collateralIndex } of transfers) {
|
|
20
|
+
if (indexes.has(collateralIndex)) {
|
|
21
|
+
throw new DuplicateMidnightCollateralIndexError(collateralIndex);
|
|
22
|
+
}
|
|
23
|
+
indexes.add(collateralIndex);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import type { MidnightCollateralTransfer } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validates collateral supply entries and their per-index totals.
|
|
5
|
+
*
|
|
6
|
+
* @param params - Market, error-field prefix, and collateral supplies.
|
|
7
|
+
* @returns Nothing when every entry and total is valid; accepts an empty list.
|
|
8
|
+
* @throws {NonPositiveInputError} when an entry is not positive.
|
|
9
|
+
* @throws {InputExceedsMaxError} when an entry or per-index sum exceeds uint128.
|
|
10
|
+
* @throws {UnknownCollateralIndexError} when an index is not configured on the market.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare const validateMidnightCollateralSupplies: (params: {
|
|
14
|
+
readonly market: MarketInput;
|
|
15
|
+
readonly field: string;
|
|
16
|
+
readonly supplies: readonly MidnightCollateralTransfer[];
|
|
17
|
+
}) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MarketUtils } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { validateMidnightCollateralSupplySums, validateMidnightUint128Field, } from "./validateMidnightBounds.js";
|
|
3
|
+
import { validatePositiveInput } from "./validatePositiveInput.js";
|
|
4
|
+
/**
|
|
5
|
+
* Validates collateral supply entries and their per-index totals.
|
|
6
|
+
*
|
|
7
|
+
* @param params - Market, error-field prefix, and collateral supplies.
|
|
8
|
+
* @returns Nothing when every entry and total is valid; accepts an empty list.
|
|
9
|
+
* @throws {NonPositiveInputError} when an entry is not positive.
|
|
10
|
+
* @throws {InputExceedsMaxError} when an entry or per-index sum exceeds uint128.
|
|
11
|
+
* @throws {UnknownCollateralIndexError} when an index is not configured on the market.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export const validateMidnightCollateralSupplies = (params) => {
|
|
15
|
+
for (const [index, { collateralIndex, assets },] of params.supplies.entries()) {
|
|
16
|
+
const field = `${params.field}[${index}].assets`;
|
|
17
|
+
// Validation only; rejects non-positive supply amounts.
|
|
18
|
+
validatePositiveInput(field, assets);
|
|
19
|
+
validateMidnightUint128Field(field, assets);
|
|
20
|
+
// Validation only; rejects indices not configured on the market.
|
|
21
|
+
MarketUtils.getCollateralByIndex(params.market, collateralIndex);
|
|
22
|
+
}
|
|
23
|
+
validateMidnightCollateralSupplySums(params.field, params.supplies);
|
|
24
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Requires a strictly positive input amount.
|
|
3
|
+
*
|
|
4
|
+
* @param field - Input field name used in the error.
|
|
5
|
+
* @param value - Candidate amount.
|
|
6
|
+
* @returns Nothing when the amount is positive.
|
|
7
|
+
* @throws {NonPositiveInputError} when the amount is zero or negative.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const validatePositiveInput: (field: string, value: bigint) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NonPositiveInputError } from "../types/error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Requires a strictly positive input amount.
|
|
4
|
+
*
|
|
5
|
+
* @param field - Input field name used in the error.
|
|
6
|
+
* @param value - Candidate amount.
|
|
7
|
+
* @returns Nothing when the amount is positive.
|
|
8
|
+
* @throws {NonPositiveInputError} when the amount is zero or negative.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const validatePositiveInput = (field, value) => {
|
|
12
|
+
if (value <= 0n)
|
|
13
|
+
throw new NonPositiveInputError(field, value);
|
|
14
|
+
};
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
|
|
|
3
3
|
export * from "./client/index.js";
|
|
4
4
|
export * from "./entities/requirements/index.js";
|
|
5
5
|
export * from "./helpers/index.js";
|
|
6
|
+
export type { Action, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV2DepositPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
|
|
7
|
+
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV2Deposit, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
|
|
6
8
|
export * from "./types/index.js";
|
package/lib/esm/index.js
CHANGED
|
@@ -3,4 +3,5 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
|
|
|
3
3
|
export * from "./client/index.js";
|
|
4
4
|
export * from "./entities/requirements/index.js";
|
|
5
5
|
export * from "./helpers/index.js";
|
|
6
|
+
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV2Deposit, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
|
|
6
7
|
export * from "./types/index.js";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
2
|
-
export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
|
|
1
|
+
export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
2
|
-
export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
|
|
1
|
+
export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getPlanObject, validatePlanFields } from "./validation.js";
|
|
2
|
+
/** @internal Validates the stored ERC-20 approval action's input shape. */
|
|
3
|
+
export function validateApprovalPlanAction(action, path) {
|
|
4
|
+
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
5
|
+
validatePlanFields(inputs, {
|
|
6
|
+
path: `${path}.inputs`,
|
|
7
|
+
fields: {
|
|
8
|
+
token: "address",
|
|
9
|
+
spender: "address",
|
|
10
|
+
amount: "uint256 bigint",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when an operation's account is the zero address.
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { ZeroAccountError } from "@morpho-org/morpho-sdk";
|
|
7
|
+
* import { zeroAddress } from "viem";
|
|
8
|
+
* const error = new ZeroAccountError(zeroAddress);
|
|
9
|
+
* ```
|
|
10
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ZeroAccountError extends Error {
|
|
13
|
+
readonly account: Address;
|
|
14
|
+
/** @param account - Rejected account address. */
|
|
15
|
+
constructor(account: Address);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A stored plan uses a format version this SDK cannot interpret.
|
|
19
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
20
|
+
*/
|
|
21
|
+
export declare class UnsupportedTransactionPlanVersionError extends Error {
|
|
22
|
+
readonly version: number;
|
|
23
|
+
/**
|
|
24
|
+
* @param version - Unsupported stored plan version.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { UnsupportedTransactionPlanVersionError } from "@morpho-org/morpho-sdk";
|
|
28
|
+
* const error = new UnsupportedTransactionPlanVersionError(2);
|
|
29
|
+
* console.error(error.version);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
constructor(version: number);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A selected plan step names an action this SDK cannot build.
|
|
36
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
37
|
+
*/
|
|
38
|
+
export declare class UnsupportedTransactionPlanActionError extends Error {
|
|
39
|
+
readonly actionType: string;
|
|
40
|
+
/**
|
|
41
|
+
* @param actionType - Unsupported stored action discriminator.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { UnsupportedTransactionPlanActionError } from "@morpho-org/morpho-sdk";
|
|
45
|
+
* const error = new UnsupportedTransactionPlanActionError("futureAction");
|
|
46
|
+
* console.error(error.actionType);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
constructor(actionType: string);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Restored plan data has an invalid shape or inconsistent references.
|
|
53
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
54
|
+
*/
|
|
55
|
+
export declare class InvalidTransactionPlanError extends Error {
|
|
56
|
+
/** JSON path of the first rejected value. */
|
|
57
|
+
readonly path: string;
|
|
58
|
+
/** Shape or consistency constraint that the value failed. */
|
|
59
|
+
readonly reason: string;
|
|
60
|
+
/**
|
|
61
|
+
* @param details - JSON path, validation failure and optional underlying error.
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { InvalidTransactionPlanError } from "@morpho-org/morpho-sdk";
|
|
65
|
+
* const error = new InvalidTransactionPlanError({ path: "$.chainId", reason: "expected a positive safe integer" });
|
|
66
|
+
* console.error(error.path);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
constructor({ path, reason, cause, }: {
|
|
70
|
+
readonly path: string;
|
|
71
|
+
readonly reason: string;
|
|
72
|
+
readonly cause?: unknown;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A step references a signature request that is absent or has no signature yet.
|
|
77
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
78
|
+
*/
|
|
79
|
+
export declare class IncompleteTransactionPlanError extends Error {
|
|
80
|
+
readonly id: string;
|
|
81
|
+
/**
|
|
82
|
+
* Identifies the signature request needed to build the transaction.
|
|
83
|
+
* @param id - Plan-local signature request ID.
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { IncompleteTransactionPlanError } from "@morpho-org/morpho-sdk";
|
|
87
|
+
* const error = new IncompleteTransactionPlanError("vaultV2Deposit:tokenPermit");
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
constructor(id: string);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A plan's signature request disagrees with its referencing action or has no reference.
|
|
94
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
95
|
+
*/
|
|
96
|
+
export declare class TransactionPlanSignatureMismatchError extends Error {
|
|
97
|
+
readonly id: string;
|
|
98
|
+
readonly field: string;
|
|
99
|
+
/**
|
|
100
|
+
* @param id - Rejected signature request ID.
|
|
101
|
+
* @param field - Mismatched typed-data, argument or reference field.
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { TransactionPlanSignatureMismatchError } from "@morpho-org/morpho-sdk";
|
|
105
|
+
* const error = new TransactionPlanSignatureMismatchError("vaultV2Deposit:tokenPermit", "message.owner");
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
constructor(id: string, field: string);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
|
|
112
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
113
|
+
*/
|
|
114
|
+
export declare class InvalidCalldataOriginError extends Error {
|
|
115
|
+
readonly calldataOrigin: string;
|
|
116
|
+
/**
|
|
117
|
+
* Identifies the rejected origin.
|
|
118
|
+
* @param calldataOrigin - Value supplied by the caller.
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { InvalidCalldataOriginError } from "@morpho-org/morpho-sdk";
|
|
122
|
+
* const error = new InvalidCalldataOriginError("0xabc");
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
constructor(calldataOrigin: string);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A number input that must be an integer is fractional, infinite or not a number.
|
|
129
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
130
|
+
*/
|
|
131
|
+
export declare class NonIntegerInputError extends Error {
|
|
132
|
+
readonly field: string;
|
|
133
|
+
readonly value: number;
|
|
134
|
+
/**
|
|
135
|
+
* Identifies the invalid input.
|
|
136
|
+
* @param field - Public input field whose value is invalid.
|
|
137
|
+
* @param value - Non-integer number supplied for the field.
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { NonIntegerInputError } from "@morpho-org/morpho-sdk";
|
|
141
|
+
* const error = new NonIntegerInputError("expiresAt", 1.5);
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
constructor(field: string, value: number);
|
|
145
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when an operation's account is the zero address.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { ZeroAccountError } from "@morpho-org/morpho-sdk";
|
|
6
|
+
* import { zeroAddress } from "viem";
|
|
7
|
+
* const error = new ZeroAccountError(zeroAddress);
|
|
8
|
+
* ```
|
|
9
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
10
|
+
*/
|
|
11
|
+
export class ZeroAccountError extends Error {
|
|
12
|
+
account;
|
|
13
|
+
/** @param account - Rejected account address. */
|
|
14
|
+
constructor(account) {
|
|
15
|
+
super(`Account "${account}" cannot be the zero address. Pass the account that sends the transaction.`);
|
|
16
|
+
this.account = account;
|
|
17
|
+
this.name = "ZeroAccountError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A stored plan uses a format version this SDK cannot interpret.
|
|
22
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
23
|
+
*/
|
|
24
|
+
export class UnsupportedTransactionPlanVersionError extends Error {
|
|
25
|
+
version;
|
|
26
|
+
/**
|
|
27
|
+
* @param version - Unsupported stored plan version.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { UnsupportedTransactionPlanVersionError } from "@morpho-org/morpho-sdk";
|
|
31
|
+
* const error = new UnsupportedTransactionPlanVersionError(2);
|
|
32
|
+
* console.error(error.version);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
constructor(version) {
|
|
36
|
+
super(`Unsupported transaction plan version "${version}". Use an SDK that supports this plan version.`);
|
|
37
|
+
this.version = version;
|
|
38
|
+
this.name = "UnsupportedTransactionPlanVersionError";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A selected plan step names an action this SDK cannot build.
|
|
43
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
44
|
+
*/
|
|
45
|
+
export class UnsupportedTransactionPlanActionError extends Error {
|
|
46
|
+
actionType;
|
|
47
|
+
/**
|
|
48
|
+
* @param actionType - Unsupported stored action discriminator.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { UnsupportedTransactionPlanActionError } from "@morpho-org/morpho-sdk";
|
|
52
|
+
* const error = new UnsupportedTransactionPlanActionError("futureAction");
|
|
53
|
+
* console.error(error.actionType);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
constructor(actionType) {
|
|
57
|
+
super(`Unsupported transaction plan action "${actionType}". Use an SDK that supports this action.`);
|
|
58
|
+
this.actionType = actionType;
|
|
59
|
+
this.name = "UnsupportedTransactionPlanActionError";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Restored plan data has an invalid shape or inconsistent references.
|
|
64
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
65
|
+
*/
|
|
66
|
+
export class InvalidTransactionPlanError extends Error {
|
|
67
|
+
/** JSON path of the first rejected value. */
|
|
68
|
+
path;
|
|
69
|
+
/** Shape or consistency constraint that the value failed. */
|
|
70
|
+
reason;
|
|
71
|
+
/**
|
|
72
|
+
* @param details - JSON path, validation failure and optional underlying error.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { InvalidTransactionPlanError } from "@morpho-org/morpho-sdk";
|
|
76
|
+
* const error = new InvalidTransactionPlanError({ path: "$.chainId", reason: "expected a positive safe integer" });
|
|
77
|
+
* console.error(error.path);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
constructor({ path, reason, cause, }) {
|
|
81
|
+
super(`Invalid transaction plan at "${path}": ${reason}. Restore a valid saved plan or prepare a new plan.`, { cause });
|
|
82
|
+
this.name = "InvalidTransactionPlanError";
|
|
83
|
+
this.path = path;
|
|
84
|
+
this.reason = reason;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A step references a signature request that is absent or has no signature yet.
|
|
89
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
90
|
+
*/
|
|
91
|
+
export class IncompleteTransactionPlanError extends Error {
|
|
92
|
+
id;
|
|
93
|
+
/**
|
|
94
|
+
* Identifies the signature request needed to build the transaction.
|
|
95
|
+
* @param id - Plan-local signature request ID.
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { IncompleteTransactionPlanError } from "@morpho-org/morpho-sdk";
|
|
99
|
+
* const error = new IncompleteTransactionPlanError("vaultV2Deposit:tokenPermit");
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
constructor(id) {
|
|
103
|
+
super(`Missing signature for request "${id}". Verify and attach it with applySignatures before building this step.`);
|
|
104
|
+
this.id = id;
|
|
105
|
+
this.name = "IncompleteTransactionPlanError";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A plan's signature request disagrees with its referencing action or has no reference.
|
|
110
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
111
|
+
*/
|
|
112
|
+
export class TransactionPlanSignatureMismatchError extends Error {
|
|
113
|
+
id;
|
|
114
|
+
field;
|
|
115
|
+
/**
|
|
116
|
+
* @param id - Rejected signature request ID.
|
|
117
|
+
* @param field - Mismatched typed-data, argument or reference field.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { TransactionPlanSignatureMismatchError } from "@morpho-org/morpho-sdk";
|
|
121
|
+
* const error = new TransactionPlanSignatureMismatchError("vaultV2Deposit:tokenPermit", "message.owner");
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
constructor(id, field) {
|
|
125
|
+
super(`Signature request "${id}" has a mismatched "${field}". Prepare a new plan before signing or building.`);
|
|
126
|
+
this.id = id;
|
|
127
|
+
this.field = field;
|
|
128
|
+
this.name = "TransactionPlanSignatureMismatchError";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
|
|
133
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
134
|
+
*/
|
|
135
|
+
export class InvalidCalldataOriginError extends Error {
|
|
136
|
+
calldataOrigin;
|
|
137
|
+
/**
|
|
138
|
+
* Identifies the rejected origin.
|
|
139
|
+
* @param calldataOrigin - Value supplied by the caller.
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* import { InvalidCalldataOriginError } from "@morpho-org/morpho-sdk";
|
|
143
|
+
* const error = new InvalidCalldataOriginError("0xabc");
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
constructor(calldataOrigin) {
|
|
147
|
+
super(`Calldata origin "${calldataOrigin}" must be 0x-prefixed hex with an even number of hex characters, such as "0xdeadbeef". Fix the value or omit it.`);
|
|
148
|
+
this.calldataOrigin = calldataOrigin;
|
|
149
|
+
this.name = "InvalidCalldataOriginError";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A number input that must be an integer is fractional, infinite or not a number.
|
|
154
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
155
|
+
*/
|
|
156
|
+
export class NonIntegerInputError extends Error {
|
|
157
|
+
field;
|
|
158
|
+
value;
|
|
159
|
+
/**
|
|
160
|
+
* Identifies the invalid input.
|
|
161
|
+
* @param field - Public input field whose value is invalid.
|
|
162
|
+
* @param value - Non-integer number supplied for the field.
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* import { NonIntegerInputError } from "@morpho-org/morpho-sdk";
|
|
166
|
+
* const error = new NonIntegerInputError("expiresAt", 1.5);
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
constructor(field, value) {
|
|
170
|
+
super(`Input "${field}" must be a safe integer, got "${value}".`);
|
|
171
|
+
this.field = field;
|
|
172
|
+
this.value = value;
|
|
173
|
+
this.name = "NonIntegerInputError";
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Client } from "viem";
|
|
2
|
+
import type { GetBundlesTokenRequirementsParams } from "../entities/requirements/getBundlesTokenRequirements.js";
|
|
3
|
+
import type { Erc2612RequirementSignature, Requirement } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal Builds an ERC-2612 permit requirement, or returns undefined when the token has no
|
|
6
|
+
* usable permit: DAI's non-standard permit, a reverting or undecodable `nonces()`, or no known
|
|
7
|
+
* compatible permit domain and matching DOMAIN_SEPARATOR. Transport failures propagate.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTokenPermit(client: Client, params: Pick<GetBundlesTokenRequirementsParams, "token" | "spender" | "amount" | "owner" | "chainId" | "deadline" | "supportDeployless"> & {
|
|
10
|
+
readonly now: bigint;
|
|
11
|
+
}): Promise<Requirement<Erc2612RequirementSignature> | undefined>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { isDefined } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { isAddressEqual } from "viem";
|
|
4
|
+
import { getErc2612Permit } from "../entities/requirements/getErc2612Permit.js";
|
|
5
|
+
/**
|
|
6
|
+
* @internal Builds an ERC-2612 permit requirement, or returns undefined when the token has no
|
|
7
|
+
* usable permit: DAI's non-standard permit, a reverting or undecodable `nonces()`, or no known
|
|
8
|
+
* compatible permit domain and matching DOMAIN_SEPARATOR. Transport failures propagate.
|
|
9
|
+
*/
|
|
10
|
+
export async function getTokenPermit(client, params) {
|
|
11
|
+
const { dai } = getChainAddresses(params.chainId);
|
|
12
|
+
if (isDefined(dai) && isAddressEqual(params.token, dai))
|
|
13
|
+
return undefined;
|
|
14
|
+
return getErc2612Permit(client, params);
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
|
|
2
|
+
export type { Funding, IntentParams, ReferralFee, } from "./intent.js";
|
|
3
|
+
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
|
|
4
|
+
export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
|
|
5
|
+
export type { Action, SignatureRequest, Step, TransactionPlan, } from "./types.js";
|
|
6
|
+
export type { VaultV2DepositPlanParams } from "./vaultv2/deposit.js";
|
|
7
|
+
export { prepareVaultV2Deposit } from "./vaultv2/deposit.js";
|
|
8
|
+
export type { VaultV2WithdrawPlanParams } from "./vaultv2/withdraw.js";
|
|
9
|
+
export { prepareVaultV2Withdraw } from "./vaultv2/withdraw.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
|
|
2
|
+
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
|
|
3
|
+
export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
|
|
4
|
+
export { prepareVaultV2Deposit } from "./vaultv2/deposit.js";
|
|
5
|
+
export { prepareVaultV2Withdraw } from "./vaultv2/withdraw.js";
|