@morpho-org/morpho-sdk 9.6.0-next.0 → 9.6.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/README.md +59 -0
- 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/vaultV2/vaultV2.d.ts +8 -33
- 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 +14 -0
- package/lib/cjs/helpers/validateMidnightCollateralBatch.js +27 -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/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +5 -5
- 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/vaultV2/vaultV2.d.ts +8 -33
- 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 +14 -0
- package/lib/esm/helpers/validateMidnightCollateralBatch.js +24 -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/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- 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 +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { InsufficientDeadSharesError, MissingDeadSharesDataError, } from "../types/error.js";
|
|
3
3
|
import { MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS } from "./constant.js";
|
|
4
4
|
/**
|
|
@@ -151,8 +151,6 @@ export function validateVaultV2DeadShares(vault, path = []) {
|
|
|
151
151
|
return cap;
|
|
152
152
|
};
|
|
153
153
|
for (const adapter of vault.accrualAdapters) {
|
|
154
|
-
if (adapter instanceof AccrualVaultV2MidnightAdapter)
|
|
155
|
-
continue;
|
|
156
154
|
if (adapter instanceof AccrualVaultV2MorphoVaultV1Adapter) {
|
|
157
155
|
const id = VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
|
|
158
156
|
if (capOf(id, adapter.address) > 0n)
|
|
@@ -16,6 +16,7 @@ import type { Address, Hex, TypedDataDefinition, WalletClient } from "viem";
|
|
|
16
16
|
* @throws {AddressMismatchError} when the wallet client account differs from `userAddress`.
|
|
17
17
|
* @throws {ChainIdMismatchError} when the wallet client targets a different chain than the typed-data domain.
|
|
18
18
|
* @throws {InvalidSignatureError} when the signature does not recover to `userAddress`.
|
|
19
|
+
* @throws {MalformedSignatureError} when verification throws; preserves the original error as `cause` with redacted signature diagnostics. Extends `InvalidSignatureError`.
|
|
19
20
|
* @example
|
|
20
21
|
* ```ts
|
|
21
22
|
* import { signAndVerifyTypedData } from "@morpho-org/morpho-sdk";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { verifyTypedData } from "viem";
|
|
2
2
|
import { signTypedData } from "viem/actions";
|
|
3
|
-
import { InvalidSignatureError } from "../types/index.js";
|
|
3
|
+
import { InvalidSignatureError, MalformedSignatureError, } from "../types/index.js";
|
|
4
4
|
import { validateChainId, validateUserAddress } from "./validate.js";
|
|
5
5
|
/**
|
|
6
6
|
* Signs EIP-712 typed data with a wallet client, verifies that the produced signature recovers
|
|
@@ -19,6 +19,7 @@ import { validateChainId, validateUserAddress } from "./validate.js";
|
|
|
19
19
|
* @throws {AddressMismatchError} when the wallet client account differs from `userAddress`.
|
|
20
20
|
* @throws {ChainIdMismatchError} when the wallet client targets a different chain than the typed-data domain.
|
|
21
21
|
* @throws {InvalidSignatureError} when the signature does not recover to `userAddress`.
|
|
22
|
+
* @throws {MalformedSignatureError} when verification throws; preserves the original error as `cause` with redacted signature diagnostics. Extends `InvalidSignatureError`.
|
|
22
23
|
* @example
|
|
23
24
|
* ```ts
|
|
24
25
|
* import { signAndVerifyTypedData } from "@morpho-org/morpho-sdk";
|
|
@@ -42,11 +43,17 @@ export const signAndVerifyTypedData = async (params) => {
|
|
|
42
43
|
...typedData,
|
|
43
44
|
account,
|
|
44
45
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
let isValid;
|
|
47
|
+
try {
|
|
48
|
+
isValid = await verifyTypedData({
|
|
49
|
+
...typedData,
|
|
50
|
+
address: userAddress,
|
|
51
|
+
signature,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (cause) {
|
|
55
|
+
throw new MalformedSignatureError({ signature, cause });
|
|
56
|
+
}
|
|
50
57
|
if (!isValid) {
|
|
51
58
|
throw new InvalidSignatureError();
|
|
52
59
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { MidnightCancelAndMakeParams } from "../types/midnightCancelAndMake.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validates publication content after snapshot and hex-shape validation.
|
|
4
|
+
*
|
|
5
|
+
* @param params - Publication, chain deployment, and groups cancelled by this bundle.
|
|
6
|
+
* @returns Nothing when publication content and funding inputs are valid.
|
|
7
|
+
* @throws {InvalidTreeError} when the root is zero, payload empty, or groups empty.
|
|
8
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the registry.
|
|
9
|
+
* @throws {MidnightCalldataEncodingError} when the ratifier or collateral market address is malformed.
|
|
10
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when the ratifier is not supported.
|
|
11
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is cancelled.
|
|
12
|
+
* @throws {NonPositiveInputError} when Blue funding or a collateral supply is not positive.
|
|
13
|
+
* @throws {InputExceedsMaxError} when funding or collateral supply totals exceed uint128.
|
|
14
|
+
* @throws {EmptyMidnightCollateralSuppliesError} when collateral supplies are empty.
|
|
15
|
+
* @throws {ChainIdMismatchError} when the collateral market targets another chain.
|
|
16
|
+
* @throws {MidnightMarketAddressMismatchError} when its Midnight deployment differs.
|
|
17
|
+
* @throws {UnknownCollateralIndexError} when a supply index is not configured.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare const validateMidnightCancelAndMakePublication: ({ publication, chainId, cancelledGroups, }: {
|
|
21
|
+
readonly publication: NonNullable<MidnightCancelAndMakeParams["publication"]>;
|
|
22
|
+
readonly chainId: number;
|
|
23
|
+
readonly cancelledGroups: ReadonlySet<string>;
|
|
24
|
+
}) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Copies validated publication fields and supplies zero ABI defaults for omitted steps.
|
|
27
|
+
*
|
|
28
|
+
* @param publication - Snapshotted publication, or undefined for cancellation only.
|
|
29
|
+
* @returns ABI defaults and copied publication fields, without mutating the input.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare const normalizeMidnightCancelAndMakePublication: (publication: MidnightCancelAndMakeParams["publication"]) => {
|
|
33
|
+
supplies: {
|
|
34
|
+
collateralIndex: bigint;
|
|
35
|
+
assets: bigint;
|
|
36
|
+
}[];
|
|
37
|
+
blueSupply: {
|
|
38
|
+
market: {
|
|
39
|
+
loanToken: `0x${string}`;
|
|
40
|
+
collateralToken: `0x${string}`;
|
|
41
|
+
oracle: `0x${string}`;
|
|
42
|
+
irm: `0x${string}`;
|
|
43
|
+
lltv: bigint;
|
|
44
|
+
};
|
|
45
|
+
assets: bigint;
|
|
46
|
+
callbackSalt: `0x${string}`;
|
|
47
|
+
} | undefined;
|
|
48
|
+
signature: import("../types/midnightCancelAndMake.js").MidnightRootActivationSignature;
|
|
49
|
+
blueMarket: {
|
|
50
|
+
readonly loanToken: "0x0000000000000000000000000000000000000000";
|
|
51
|
+
readonly collateralToken: "0x0000000000000000000000000000000000000000";
|
|
52
|
+
readonly oracle: "0x0000000000000000000000000000000000000000";
|
|
53
|
+
readonly irm: "0x0000000000000000000000000000000000000000";
|
|
54
|
+
readonly lltv: 0n;
|
|
55
|
+
} | {
|
|
56
|
+
loanToken: `0x${string}`;
|
|
57
|
+
collateralToken: `0x${string}`;
|
|
58
|
+
oracle: `0x${string}`;
|
|
59
|
+
irm: `0x${string}`;
|
|
60
|
+
lltv: bigint;
|
|
61
|
+
};
|
|
62
|
+
assetsToPark: bigint;
|
|
63
|
+
callbackSalt: `0x${string}`;
|
|
64
|
+
ratifier: `0x${string}`;
|
|
65
|
+
root: `0x${string}`;
|
|
66
|
+
groups: `0x${string}`[];
|
|
67
|
+
payload: `0x${string}`;
|
|
68
|
+
};
|
|
@@ -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,14 @@
|
|
|
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 {DuplicateMidnightCollateralIndexError} when an index appears twice.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* validateMidnightCollateralBatch(supplies, new EmptyMidnightCollateralSuppliesError());
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateMidnightCollateralBatch(transfers: readonly MidnightCollateralTransfer[], emptyError: Error): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 {DuplicateMidnightCollateralIndexError} when an index appears twice.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* validateMidnightCollateralBatch(supplies, new EmptyMidnightCollateralSuppliesError());
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function validateMidnightCollateralBatch(transfers, emptyError) {
|
|
15
|
+
if (transfers.length === 0)
|
|
16
|
+
throw emptyError;
|
|
17
|
+
const indexes = new Set();
|
|
18
|
+
for (const { collateralIndex } of transfers) {
|
|
19
|
+
if (indexes.has(collateralIndex)) {
|
|
20
|
+
throw new DuplicateMidnightCollateralIndexError(collateralIndex);
|
|
21
|
+
}
|
|
22
|
+
indexes.add(collateralIndex);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -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";
|
|
@@ -283,12 +283,12 @@ export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
|
|
|
283
283
|
}> {
|
|
284
284
|
}
|
|
285
285
|
/**
|
|
286
|
-
* Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's
|
|
286
|
+
* Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's supply shares,
|
|
287
287
|
* sent by the callback's owner.
|
|
288
288
|
*/
|
|
289
289
|
export interface BlueWithdrawBuyCallbackAction extends BaseAction<"blueWithdrawBuyCallback", {
|
|
290
290
|
readonly market: Hex;
|
|
291
|
-
/**
|
|
291
|
+
/** Caller-supplied number of supply shares burned. */
|
|
292
292
|
readonly shares: bigint;
|
|
293
293
|
/** BlueBuyCallback whose supply position is withdrawn. */
|
|
294
294
|
readonly onBehalf: Address;
|
|
@@ -449,6 +449,13 @@ export interface MidnightSupplyCollateralAction extends BaseAction<"midnightSupp
|
|
|
449
449
|
readonly onBehalf: Address;
|
|
450
450
|
}> {
|
|
451
451
|
}
|
|
452
|
+
/** Metadata for an atomic direct Midnight collateral supply batch. */
|
|
453
|
+
export interface MidnightSupplyCollateralBatchAction extends BaseAction<"midnightSupplyCollateralBatch", {
|
|
454
|
+
readonly market: Hex;
|
|
455
|
+
readonly collateralSupplies: readonly MidnightCollateralTransfer[];
|
|
456
|
+
readonly onBehalf: Address;
|
|
457
|
+
}> {
|
|
458
|
+
}
|
|
452
459
|
/** Metadata for a direct Midnight collateral withdrawal transaction. */
|
|
453
460
|
export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWithdrawCollateral", {
|
|
454
461
|
readonly market: Hex;
|
|
@@ -458,6 +465,14 @@ export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWi
|
|
|
458
465
|
readonly receiver: Address;
|
|
459
466
|
}> {
|
|
460
467
|
}
|
|
468
|
+
/** Metadata for an atomic direct Midnight collateral withdrawal batch. */
|
|
469
|
+
export interface MidnightWithdrawCollateralBatchAction extends BaseAction<"midnightWithdrawCollateralBatch", {
|
|
470
|
+
readonly market: Hex;
|
|
471
|
+
readonly collateralWithdrawals: readonly MidnightCollateralTransfer[];
|
|
472
|
+
readonly onBehalf: Address;
|
|
473
|
+
readonly receiver: Address;
|
|
474
|
+
}> {
|
|
475
|
+
}
|
|
461
476
|
/** Metadata for a direct Midnight credit redemption transaction. */
|
|
462
477
|
export interface MidnightRedeemAction extends BaseAction<"midnightRedeem", {
|
|
463
478
|
readonly market: Hex;
|
|
@@ -524,7 +539,7 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
|
|
|
524
539
|
* VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
|
|
525
540
|
* consumers can `switch` exhaustively on it.
|
|
526
541
|
*/
|
|
527
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
|
|
542
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
|
|
528
543
|
/**
|
|
529
544
|
* Describes a single, immutable, deep-frozen transaction to submit on-chain:
|
|
530
545
|
* the target `to`, native `value`, encoded call `data`, and the originating
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -922,9 +922,22 @@ export declare class RepayExceedsDebtError extends Error {
|
|
|
922
922
|
market: string;
|
|
923
923
|
});
|
|
924
924
|
}
|
|
925
|
-
/** Thrown when EIP-712 signature verification fails
|
|
925
|
+
/** Thrown when EIP-712 signature verification fails to recover the expected signer. */
|
|
926
926
|
export declare class InvalidSignatureError extends Error {
|
|
927
|
-
constructor();
|
|
927
|
+
constructor(options?: ErrorOptions);
|
|
928
|
+
}
|
|
929
|
+
/** Thrown when signature recovery fails, with redacted diagnostics and the original error as `cause`. */
|
|
930
|
+
export declare class MalformedSignatureError extends InvalidSignatureError {
|
|
931
|
+
/** JavaScript type returned by the wallet, without the signature value. */
|
|
932
|
+
readonly signatureType: string;
|
|
933
|
+
/** Whether the returned value is an even-length hex string. */
|
|
934
|
+
readonly signatureIsHex: boolean;
|
|
935
|
+
/** Signature byte length, when it is an even-length hex string. */
|
|
936
|
+
readonly signatureByteLength: number | undefined;
|
|
937
|
+
constructor(params: {
|
|
938
|
+
readonly signature: unknown;
|
|
939
|
+
readonly cause: unknown;
|
|
940
|
+
});
|
|
928
941
|
}
|
|
929
942
|
/** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
|
|
930
943
|
export declare class RepaySharesExceedDebtError extends Error {
|
|
@@ -1056,6 +1069,14 @@ export declare class EmptyMidnightGroupCancellationsError extends Error {
|
|
|
1056
1069
|
export declare class EmptyMidnightCollateralSuppliesError extends Error {
|
|
1057
1070
|
constructor();
|
|
1058
1071
|
}
|
|
1072
|
+
/** Thrown when a direct Midnight collateral withdrawal batch is empty. */
|
|
1073
|
+
export declare class EmptyMidnightCollateralWithdrawalsError extends Error {
|
|
1074
|
+
constructor();
|
|
1075
|
+
}
|
|
1076
|
+
/** Thrown when a direct Midnight collateral batch repeats an index. */
|
|
1077
|
+
export declare class DuplicateMidnightCollateralIndexError extends Error {
|
|
1078
|
+
constructor(collateralIndex: bigint);
|
|
1079
|
+
}
|
|
1059
1080
|
/** Thrown when a Midnight batch cancellation lists the same offer group twice. */
|
|
1060
1081
|
export declare class DuplicateMidnightGroupCancellationError extends Error {
|
|
1061
1082
|
constructor(params: {
|
package/lib/esm/types/error.js
CHANGED
|
@@ -1135,13 +1135,36 @@ export class RepayExceedsDebtError extends Error {
|
|
|
1135
1135
|
this.name = "RepayExceedsDebtError";
|
|
1136
1136
|
}
|
|
1137
1137
|
}
|
|
1138
|
-
/** Thrown when EIP-712 signature verification fails
|
|
1138
|
+
/** Thrown when EIP-712 signature verification fails to recover the expected signer. */
|
|
1139
1139
|
export class InvalidSignatureError extends Error {
|
|
1140
|
-
constructor() {
|
|
1141
|
-
super("Signature verification failed: the signed data does not match the expected signer address");
|
|
1140
|
+
constructor(options) {
|
|
1141
|
+
super("Signature verification failed: the signed data does not match the expected signer address", options);
|
|
1142
1142
|
this.name = "InvalidSignatureError";
|
|
1143
1143
|
}
|
|
1144
1144
|
}
|
|
1145
|
+
/** Thrown when signature recovery fails, with redacted diagnostics and the original error as `cause`. */
|
|
1146
|
+
export class MalformedSignatureError extends InvalidSignatureError {
|
|
1147
|
+
/** JavaScript type returned by the wallet, without the signature value. */
|
|
1148
|
+
signatureType;
|
|
1149
|
+
/** Whether the returned value is an even-length hex string. */
|
|
1150
|
+
signatureIsHex;
|
|
1151
|
+
/** Signature byte length, when it is an even-length hex string. */
|
|
1152
|
+
signatureByteLength;
|
|
1153
|
+
constructor(params) {
|
|
1154
|
+
super({ cause: params.cause });
|
|
1155
|
+
this.name = "MalformedSignatureError";
|
|
1156
|
+
this.message =
|
|
1157
|
+
"Signature verification failed: the wallet returned a malformed signature. Check the wallet signing transport and sign the typed data again.";
|
|
1158
|
+
this.signatureType = typeof params.signature;
|
|
1159
|
+
this.signatureIsHex =
|
|
1160
|
+
typeof params.signature === "string" &&
|
|
1161
|
+
/^0x(?:[0-9a-fA-F]{2})*$/.test(params.signature);
|
|
1162
|
+
this.signatureByteLength =
|
|
1163
|
+
this.signatureIsHex && typeof params.signature === "string"
|
|
1164
|
+
? (params.signature.length - 2) / 2
|
|
1165
|
+
: undefined;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1145
1168
|
/** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
|
|
1146
1169
|
export class RepaySharesExceedDebtError extends Error {
|
|
1147
1170
|
constructor(params) {
|
|
@@ -1290,6 +1313,20 @@ export class EmptyMidnightCollateralSuppliesError extends Error {
|
|
|
1290
1313
|
this.name = "EmptyMidnightCollateralSuppliesError";
|
|
1291
1314
|
}
|
|
1292
1315
|
}
|
|
1316
|
+
/** Thrown when a direct Midnight collateral withdrawal batch is empty. */
|
|
1317
|
+
export class EmptyMidnightCollateralWithdrawalsError extends Error {
|
|
1318
|
+
constructor() {
|
|
1319
|
+
super("Midnight collateral withdrawals cannot be empty. Pass at least one collateral withdrawal.");
|
|
1320
|
+
this.name = "EmptyMidnightCollateralWithdrawalsError";
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
/** Thrown when a direct Midnight collateral batch repeats an index. */
|
|
1324
|
+
export class DuplicateMidnightCollateralIndexError extends Error {
|
|
1325
|
+
constructor(collateralIndex) {
|
|
1326
|
+
super(`Midnight collateral batch repeats index "${collateralIndex}". Pass each collateral index once.`);
|
|
1327
|
+
this.name = "DuplicateMidnightCollateralIndexError";
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1293
1330
|
/** Thrown when a Midnight batch cancellation lists the same offer group twice. */
|
|
1294
1331
|
export class DuplicateMidnightGroupCancellationError extends Error {
|
|
1295
1332
|
constructor(params) {
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
|
-
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils,
|
|
6
|
+
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
7
7
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
8
8
|
export { EcrecoverRatifier as MidnightEcrecoverRatifier,
|
|
9
9
|
/** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
|
|
@@ -17,7 +17,7 @@ RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier
|
|
|
17
17
|
/** @deprecated Use MidnightSetterRatifier with a tagged tree. */
|
|
18
18
|
SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
|
|
19
19
|
export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
|
|
20
|
-
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys,
|
|
20
|
+
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|
|
21
21
|
export { validateClientChainId } from "./actions/requirements/validateClientChainId.js";
|
|
22
22
|
export { addTransactionMetadata } from "./helpers/metadata.js";
|
|
23
23
|
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./helpers/previewVaultV2ForceWithdraw.js";
|
package/lib/esm/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils,
|
|
5
|
+
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
6
6
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
7
7
|
export { EcrecoverRatifier as MidnightEcrecoverRatifier,
|
|
8
8
|
/** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
|
|
@@ -15,7 +15,7 @@ RateRatifierV1Utils as MidnightRateRatifierV1Utils, Ratifier as MidnightRatifier
|
|
|
15
15
|
RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier,
|
|
16
16
|
/** @deprecated Use MidnightSetterRatifier with a tagged tree. */
|
|
17
17
|
SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
|
|
18
|
-
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys,
|
|
18
|
+
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|
|
19
19
|
export { validateClientChainId } from "./actions/requirements/validateClientChainId.js";
|
|
20
20
|
export { addTransactionMetadata } from "./helpers/metadata.js";
|
|
21
21
|
export { previewVaultV2ForceWithdraw, } from "./helpers/previewVaultV2ForceWithdraw.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/morpho-sdk",
|
|
3
3
|
"description": "Abstraction layer for Morpho's complexity.",
|
|
4
|
-
"version": "9.6.0
|
|
4
|
+
"version": "9.6.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -154,17 +154,17 @@
|
|
|
154
154
|
"DEAD-SHARE-PROTECTION.md"
|
|
155
155
|
],
|
|
156
156
|
"dependencies": {
|
|
157
|
-
"@morpho-org/blue-sdk": "^8.
|
|
158
|
-
"@morpho-org/blue-sdk-viem": "^7.4.0
|
|
159
|
-
"@morpho-org/midnight-sdk": "^2.5.0
|
|
160
|
-
"@morpho-org/morpho-ts": "^4.3.0
|
|
157
|
+
"@morpho-org/blue-sdk": "^8.2.2",
|
|
158
|
+
"@morpho-org/blue-sdk-viem": "^7.4.0",
|
|
159
|
+
"@morpho-org/midnight-sdk": "^2.5.0",
|
|
160
|
+
"@morpho-org/morpho-ts": "^4.3.0"
|
|
161
161
|
},
|
|
162
162
|
"peerDependencies": {
|
|
163
163
|
"viem": "^2.0.0"
|
|
164
164
|
},
|
|
165
165
|
"devDependencies": {
|
|
166
166
|
"@morpho-org/morpho-test": "^4.2.0",
|
|
167
|
-
"@morpho-org/test": "^2.
|
|
167
|
+
"@morpho-org/test": "^2.12.1",
|
|
168
168
|
"fast-check": "^4.9.0",
|
|
169
169
|
"typescript": "7.0.2",
|
|
170
170
|
"viem": "^2.55.10",
|