@morpho-org/morpho-sdk 8.3.0 → 9.0.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-v8-to-v9.md +54 -0
- package/README.md +13 -7
- package/lib/cjs/actions/bundles/common.d.ts +4 -7
- package/lib/cjs/actions/bundles/common.js +8 -14
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -8
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -1
- package/lib/cjs/actions/midnight/authorization.js +11 -1
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +10 -2
- package/lib/cjs/actions/midnight/redeem.d.ts +3 -1
- package/lib/cjs/actions/midnight/redeem.js +9 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +7 -3
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +4 -1
- package/lib/cjs/actions/midnight/supplyCollateral.js +10 -3
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +9 -3
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +3 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +9 -3
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeLend.js +7 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +8 -2
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +3 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +10 -3
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +5 -7
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +7 -11
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +8 -15
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +11 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +4 -4
- package/lib/cjs/actions/vaultV1/withdraw.js +4 -4
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +1 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +4 -4
- package/lib/cjs/actions/vaultV2/withdraw.js +4 -4
- package/lib/cjs/entities/blue/blue.d.ts +2 -12
- package/lib/cjs/entities/blue/blue.js +0 -4
- package/lib/cjs/entities/midnight/midnight.d.ts +56 -17
- package/lib/cjs/entities/midnight/midnight.js +131 -52
- package/lib/cjs/entities/midnight/types.d.ts +2 -9
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +0 -7
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -20
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +40 -37
- package/lib/cjs/entities/vaultV1/vaultV1.js +5 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +36 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +8 -34
- package/lib/cjs/helpers/encodeMidnightCalldata.d.ts +48 -0
- package/lib/cjs/helpers/encodeMidnightCalldata.js +74 -0
- package/lib/cjs/helpers/slippage.d.ts +9 -25
- package/lib/cjs/helpers/slippage.js +10 -27
- package/lib/cjs/helpers/validate.d.ts +1 -0
- package/lib/cjs/helpers/validate.js +5 -0
- package/lib/cjs/helpers/validateMidnightAccount.d.ts +34 -0
- package/lib/cjs/helpers/validateMidnightAccount.js +47 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +4 -0
- package/lib/cjs/helpers/validateMidnightMarket.d.ts +2 -0
- package/lib/cjs/helpers/validateMidnightMarket.js +5 -0
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +11 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +12 -1
- package/lib/cjs/helpers/validateMidnightReceiver.d.ts +1 -0
- package/lib/cjs/helpers/validateMidnightReceiver.js +8 -0
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +4 -3
- package/lib/cjs/types/action.d.ts +3 -1
- package/lib/cjs/types/error.d.ts +56 -5
- package/lib/cjs/types/error.js +139 -10
- package/lib/esm/actions/bundles/common.d.ts +4 -7
- package/lib/esm/actions/bundles/common.js +8 -14
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -9
- package/lib/esm/actions/midnight/authorization.d.ts +3 -1
- package/lib/esm/actions/midnight/authorization.js +12 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +11 -3
- package/lib/esm/actions/midnight/redeem.d.ts +3 -1
- package/lib/esm/actions/midnight/redeem.js +10 -4
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +8 -4
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +4 -1
- package/lib/esm/actions/midnight/supplyCollateral.js +11 -4
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +10 -4
- package/lib/esm/actions/midnight/takeBorrow.d.ts +3 -1
- package/lib/esm/actions/midnight/takeBorrow.js +10 -4
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
- package/lib/esm/actions/midnight/takeLend.js +8 -3
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +9 -3
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +3 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +11 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -8
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +7 -11
- package/lib/esm/actions/requirements/getRequirementsApproval.js +9 -16
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +12 -9
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +1 -1
- package/lib/esm/actions/vaultV1/withdraw.d.ts +4 -4
- package/lib/esm/actions/vaultV1/withdraw.js +4 -4
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +1 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +1 -1
- package/lib/esm/actions/vaultV2/withdraw.d.ts +4 -4
- package/lib/esm/actions/vaultV2/withdraw.js +4 -4
- package/lib/esm/entities/blue/blue.d.ts +2 -12
- package/lib/esm/entities/blue/blue.js +0 -4
- package/lib/esm/entities/midnight/midnight.d.ts +56 -17
- package/lib/esm/entities/midnight/midnight.js +132 -53
- package/lib/esm/entities/midnight/types.d.ts +2 -9
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +1 -8
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +9 -21
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +40 -37
- package/lib/esm/entities/vaultV1/vaultV1.js +6 -35
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +36 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +8 -34
- package/lib/esm/helpers/encodeMidnightCalldata.d.ts +48 -0
- package/lib/esm/helpers/encodeMidnightCalldata.js +69 -0
- package/lib/esm/helpers/slippage.d.ts +9 -25
- package/lib/esm/helpers/slippage.js +9 -25
- package/lib/esm/helpers/validate.d.ts +1 -0
- package/lib/esm/helpers/validate.js +5 -0
- package/lib/esm/helpers/validateMidnightAccount.d.ts +34 -0
- package/lib/esm/helpers/validateMidnightAccount.js +43 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +4 -0
- package/lib/esm/helpers/validateMidnightMarket.d.ts +2 -0
- package/lib/esm/helpers/validateMidnightMarket.js +5 -0
- package/lib/esm/helpers/validateMidnightPublication.d.ts +11 -0
- package/lib/esm/helpers/validateMidnightPublication.js +10 -0
- package/lib/esm/helpers/validateMidnightReceiver.d.ts +1 -0
- package/lib/esm/helpers/validateMidnightReceiver.js +8 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +4 -3
- package/lib/esm/types/action.d.ts +3 -1
- package/lib/esm/types/error.d.ts +56 -5
- package/lib/esm/types/error.js +134 -6
- package/package.json +4 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { isAddressEqual } from "viem";
|
|
3
3
|
import { UnsupportedMidnightAuthorizationTargetError } from "../types/index.js";
|
|
4
|
+
import { validateMidnightAddress } from "./validateMidnightAccount.js";
|
|
4
5
|
/**
|
|
5
6
|
* Validates that a Midnight authorization grant targets a supported protocol operator.
|
|
6
7
|
*
|
|
@@ -8,10 +9,13 @@ import { UnsupportedMidnightAuthorizationTargetError } from "../types/index.js";
|
|
|
8
9
|
* @param params.chainId - Chain id used to resolve supported Midnight operators.
|
|
9
10
|
* @param params.authorized - Operator address receiving authorization.
|
|
10
11
|
* @returns Nothing after the operator matches MidnightBundlesV2.
|
|
12
|
+
* @throws {MidnightCalldataEncodingError} when `authorized` is not a 20-byte hex address.
|
|
11
13
|
* @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
|
|
12
14
|
* @internal
|
|
13
15
|
*/
|
|
14
16
|
export const validateMidnightAuthorizationTarget = (params) => {
|
|
17
|
+
// Reject a malformed address before viem compares it.
|
|
18
|
+
validateMidnightAddress("authorized", params.authorized);
|
|
15
19
|
const { midnightBundlesV2 } = getChainAddresses(params.chainId);
|
|
16
20
|
const supportedTargets = midnightBundlesV2 == null ? [] : [midnightBundlesV2];
|
|
17
21
|
if (!supportedTargets.some((supported) => isAddressEqual(params.authorized, supported))) {
|
|
@@ -2,6 +2,8 @@ import type { MarketInput } from "@morpho-org/midnight-sdk";
|
|
|
2
2
|
/**
|
|
3
3
|
* Validates that a Midnight market belongs to the configured chain deployment.
|
|
4
4
|
*
|
|
5
|
+
* @throws {MidnightCalldataEncodingError} when `market.midnight` is not a 20-byte hex address.
|
|
6
|
+
*
|
|
5
7
|
* @internal
|
|
6
8
|
*/
|
|
7
9
|
export declare const validateMidnightMarket: (params: {
|
|
@@ -2,14 +2,19 @@ import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
|
2
2
|
import { isAddressEqual } from "viem";
|
|
3
3
|
import { MidnightMarketAddressMismatchError } from "../types/index.js";
|
|
4
4
|
import { validateChainId } from "./validate.js";
|
|
5
|
+
import { validateMidnightAddress } from "./validateMidnightAccount.js";
|
|
5
6
|
/**
|
|
6
7
|
* Validates that a Midnight market belongs to the configured chain deployment.
|
|
7
8
|
*
|
|
9
|
+
* @throws {MidnightCalldataEncodingError} when `market.midnight` is not a 20-byte hex address.
|
|
10
|
+
*
|
|
8
11
|
* @internal
|
|
9
12
|
*/
|
|
10
13
|
export const validateMidnightMarket = (params) => {
|
|
11
14
|
const market = "params" in params.market ? params.market.params : params.market;
|
|
12
15
|
validateChainId(Number(market.chainId), params.chainId);
|
|
16
|
+
// Reject a malformed address before viem compares it.
|
|
17
|
+
validateMidnightAddress("market.midnight", market.midnight);
|
|
13
18
|
const expectedMidnight = getChainAddress(params.chainId, "midnight");
|
|
14
19
|
if (!isAddressEqual(market.midnight, expectedMidnight)) {
|
|
15
20
|
throw new MidnightMarketAddressMismatchError({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
1
2
|
import type { MidnightCancelAndMakeParams } from "../types/midnightCancelAndMake.js";
|
|
2
3
|
/** @internal */
|
|
3
4
|
export declare const snapshotMidnightCancelAndMakeParams: (params: MidnightCancelAndMakeParams) => MidnightCancelAndMakeParams;
|
|
@@ -10,3 +11,13 @@ export declare const snapshotMidnightCancelAndMakeParams: (params: MidnightCance
|
|
|
10
11
|
* callback salt, or root-signature `r`/`s` is not 32-byte hex, or payload is malformed or oversized.
|
|
11
12
|
*/
|
|
12
13
|
export declare const validateMidnightPublication: (params: MidnightCancelAndMakeParams) => void;
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
* Rejects a value that is not exactly 32 bytes of hex before a Midnight flow derives or encodes
|
|
17
|
+
* from it.
|
|
18
|
+
*
|
|
19
|
+
* @param field - Input name reported by the error.
|
|
20
|
+
* @param value - Fixed-length bytes value to validate.
|
|
21
|
+
* @throws {InvalidMidnightHexInputError} when `value` is not exactly 32 bytes of hex.
|
|
22
|
+
*/
|
|
23
|
+
export declare const validateMidnightBytes32: (field: string, value: Hex) => void;
|
|
@@ -105,6 +105,16 @@ export const validateMidnightPublication = (params) => {
|
|
|
105
105
|
maxBytes: Payload.MAX_PAYLOAD_BYTES,
|
|
106
106
|
});
|
|
107
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* @internal
|
|
110
|
+
* Rejects a value that is not exactly 32 bytes of hex before a Midnight flow derives or encodes
|
|
111
|
+
* from it.
|
|
112
|
+
*
|
|
113
|
+
* @param field - Input name reported by the error.
|
|
114
|
+
* @param value - Fixed-length bytes value to validate.
|
|
115
|
+
* @throws {InvalidMidnightHexInputError} when `value` is not exactly 32 bytes of hex.
|
|
116
|
+
*/
|
|
117
|
+
export const validateMidnightBytes32 = (field, value) => validateHexInput(value, field, { exactBytes: 32 });
|
|
108
118
|
// biome-ignore lint/complexity/useMaxParams: Keep value, field, and size explicit.
|
|
109
119
|
const validateHexInput = (value, field, size) => {
|
|
110
120
|
if (!isHex(value)) {
|
|
@@ -12,6 +12,7 @@ import { type Address } from "viem";
|
|
|
12
12
|
* @param params.market - Midnight market whose token contracts are also rejected.
|
|
13
13
|
* @param params.field - Receiver field being validated, reported on the thrown error.
|
|
14
14
|
* @param params.receiver - Receiver address to check.
|
|
15
|
+
* @throws {MidnightCalldataEncodingError} when the receiver or a market token address is malformed.
|
|
15
16
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
16
17
|
* @throws {MidnightZeroReceiverError} when `receiver` is the zero address and `field` is not
|
|
17
18
|
* `"referralFeeRecipient"`.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { isAddressEqual, zeroAddress } from "viem";
|
|
3
3
|
import { MidnightContractReceiverError, MidnightZeroReceiverError, ReferralFeeRecipientMissingError, } from "../types/index.js";
|
|
4
|
+
import { validateMidnightAddress } from "./validateMidnightAccount.js";
|
|
4
5
|
/** Registry keys of the Midnight protocol contracts that cannot forward received assets. */
|
|
5
6
|
const MIDNIGHT_CONTRACT_KEYS = [
|
|
6
7
|
"midnight",
|
|
@@ -25,6 +26,7 @@ const MIDNIGHT_CONTRACT_KEYS = [
|
|
|
25
26
|
* @param params.market - Midnight market whose token contracts are also rejected.
|
|
26
27
|
* @param params.field - Receiver field being validated, reported on the thrown error.
|
|
27
28
|
* @param params.receiver - Receiver address to check.
|
|
29
|
+
* @throws {MidnightCalldataEncodingError} when the receiver or a market token address is malformed.
|
|
28
30
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
29
31
|
* @throws {MidnightZeroReceiverError} when `receiver` is the zero address and `field` is not
|
|
30
32
|
* `"referralFeeRecipient"`.
|
|
@@ -37,6 +39,12 @@ const MIDNIGHT_CONTRACT_KEYS = [
|
|
|
37
39
|
export const validateMidnightReceiver = (params) => {
|
|
38
40
|
const { field, receiver } = params;
|
|
39
41
|
const market = "params" in params.market ? params.market.params : params.market;
|
|
42
|
+
// Validate addresses before comparing them so malformed values stay a typed SDK error.
|
|
43
|
+
validateMidnightAddress(field, receiver);
|
|
44
|
+
validateMidnightAddress("market.loanToken", market.loanToken);
|
|
45
|
+
for (const [index, { token }] of market.collateralParams.entries()) {
|
|
46
|
+
validateMidnightAddress(`market.collateralParams[${index}].token`, token);
|
|
47
|
+
}
|
|
40
48
|
if (isAddressEqual(receiver, zeroAddress)) {
|
|
41
49
|
if (field === "referralFeeRecipient") {
|
|
42
50
|
throw new ReferralFeeRecipientMissingError();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MarketInput, OfferStruct } from "@morpho-org/midnight-sdk";
|
|
2
2
|
/**
|
|
3
3
|
* Validates the pure invariants shared by Midnight take entity and action layers.
|
|
4
4
|
*
|
|
@@ -7,6 +7,7 @@ import { type MarketInput, type OfferStruct } from "@morpho-org/midnight-sdk";
|
|
|
7
7
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
|
|
8
8
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
9
9
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
|
|
10
|
+
* @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
13
|
export declare const validateTakeableOffers: (params: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MarketUtils, } from "@morpho-org/midnight-sdk";
|
|
2
1
|
import { EmptyMidnightTakeableOffersError, MidnightTakeableOfferMarketMismatchError, } from "../types/index.js";
|
|
2
|
+
import { encodeMidnightMarketId } from "./encodeMidnightCalldata.js";
|
|
3
3
|
import { validateOfferSides } from "./validateOfferSides.js";
|
|
4
4
|
/**
|
|
5
5
|
* Validates the pure invariants shared by Midnight take entity and action layers.
|
|
@@ -9,16 +9,17 @@ import { validateOfferSides } from "./validateOfferSides.js";
|
|
|
9
9
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
|
|
10
10
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
11
11
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
|
|
12
|
+
* @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
|
|
12
13
|
* @internal
|
|
13
14
|
*/
|
|
14
15
|
export const validateTakeableOffers = (params) => {
|
|
15
16
|
if (params.takeableOffers.length === 0) {
|
|
16
17
|
throw new EmptyMidnightTakeableOffersError();
|
|
17
18
|
}
|
|
18
|
-
const marketId =
|
|
19
|
+
const marketId = encodeMidnightMarketId(params.market);
|
|
19
20
|
validateOfferSides(params.takeableOffers.map((take) => take.offer), params.expectedBuy);
|
|
20
21
|
for (const [index, take] of params.takeableOffers.entries()) {
|
|
21
|
-
const actualMarketId =
|
|
22
|
+
const actualMarketId = encodeMidnightMarketId(take.offer.market);
|
|
22
23
|
if (actualMarketId.toLowerCase() !== marketId.toLowerCase()) {
|
|
23
24
|
throw new MidnightTakeableOfferMarketMismatchError({
|
|
24
25
|
index,
|
|
@@ -37,7 +37,7 @@ export type MidnightBuyTarget = {
|
|
|
37
37
|
*/
|
|
38
38
|
export type MidnightSellTarget = {
|
|
39
39
|
readonly type: "assets";
|
|
40
|
-
/**
|
|
40
|
+
/** Exact loan assets paid to `receiver`; any referral fee is sold on top of this amount. */
|
|
41
41
|
readonly assets: bigint;
|
|
42
42
|
readonly maxUnits: bigint;
|
|
43
43
|
} | {
|
|
@@ -491,6 +491,8 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
|
|
|
491
491
|
readonly cancellations: readonly MidnightGroupCancellation[];
|
|
492
492
|
readonly collateralSupplies: readonly MidnightCollateralTransfer[];
|
|
493
493
|
readonly blueSupply?: MidnightBlueSupply;
|
|
494
|
+
/** Native ETH wrapped into wNative to fund this bundle. */
|
|
495
|
+
readonly nativeAmount?: bigint;
|
|
494
496
|
readonly deadline: bigint;
|
|
495
497
|
}> {
|
|
496
498
|
}
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketId, UnknownDataError } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { AddressLabel } from "@morpho-org/morpho-ts";
|
|
3
|
-
import type { Address, Hash, Hex } from "viem";
|
|
3
|
+
import type { Address, BaseError, Hash, Hex } from "viem";
|
|
4
4
|
/**
|
|
5
5
|
* Thrown when a morpho-sdk input that must be non-negative is negative.
|
|
6
6
|
*
|
|
@@ -713,10 +713,6 @@ export declare class CryptoUnavailableError extends Error {
|
|
|
713
713
|
export declare class MissingClientPropertyError extends Error {
|
|
714
714
|
constructor(property: string);
|
|
715
715
|
}
|
|
716
|
-
/** Thrown when an approval amount is smaller than the spend amount it must cover. */
|
|
717
|
-
export declare class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
718
|
-
constructor();
|
|
719
|
-
}
|
|
720
716
|
/** Thrown when a requirement encoder targets an unsupported spender. */
|
|
721
717
|
export declare class UnsupportedErc20ApprovalSpenderError extends Error {
|
|
722
718
|
constructor(params: {
|
|
@@ -1496,3 +1492,58 @@ export declare class MissingContractCodeError extends Error {
|
|
|
1496
1492
|
*/
|
|
1497
1493
|
constructor(address: Address, chainId: number, role: AddressLabel);
|
|
1498
1494
|
}
|
|
1495
|
+
/**
|
|
1496
|
+
* Thrown when a Midnight flow is prepared for the zero address. Midnight would revert
|
|
1497
|
+
* `Unauthorized()`, and requirements resolved for the zero address can never be sent.
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```ts
|
|
1501
|
+
* import { MidnightZeroAccountError } from "@morpho-org/morpho-sdk";
|
|
1502
|
+
*
|
|
1503
|
+
* const error = new MidnightZeroAccountError("accountAddress");
|
|
1504
|
+
* // error.field === "accountAddress"
|
|
1505
|
+
* ```
|
|
1506
|
+
*/
|
|
1507
|
+
export declare class MidnightZeroAccountError extends Error {
|
|
1508
|
+
readonly field: "accountAddress" | "owner";
|
|
1509
|
+
/**
|
|
1510
|
+
* @param field - Account field containing the zero address: `accountAddress` for an entity
|
|
1511
|
+
* method, `owner` for a requirement helper. A zero `onBehalf` on a direct Midnight call throws
|
|
1512
|
+
* {@link MidnightZeroOnBehalfError} instead.
|
|
1513
|
+
*/
|
|
1514
|
+
constructor(field: "accountAddress" | "owner");
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Thrown when a Midnight builder or `MorphoMidnight` method cannot ABI-encode its calldata,
|
|
1518
|
+
* offer tree or market id, for example a `bytes32` field that is not 32 bytes, an integer
|
|
1519
|
+
* outside its Solidity type or a malformed address. Wraps the viem error as `cause`.
|
|
1520
|
+
*
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```ts
|
|
1523
|
+
* import { MidnightCalldataEncodingError } from "@morpho-org/morpho-sdk";
|
|
1524
|
+
* import { BaseError } from "viem";
|
|
1525
|
+
*
|
|
1526
|
+
* const error = new MidnightCalldataEncodingError(
|
|
1527
|
+
* "midnightBundlesV2CancelAndMake",
|
|
1528
|
+
* new BaseError("bad bytes32"),
|
|
1529
|
+
* );
|
|
1530
|
+
* // error.input === "midnightBundlesV2CancelAndMake"
|
|
1531
|
+
* ```
|
|
1532
|
+
*/
|
|
1533
|
+
export declare class MidnightCalldataEncodingError extends Error {
|
|
1534
|
+
readonly input: string;
|
|
1535
|
+
readonly cause: BaseError;
|
|
1536
|
+
/**
|
|
1537
|
+
* @param input - Input that could not be encoded: the contract function whose calldata
|
|
1538
|
+
* failed, `"offers"` for offer-tree hashing, `"marketId"` for market-id hashing, or the name
|
|
1539
|
+
* of the malformed address input, such as `"accountAddress"`, `"onBehalf"`, `"owner"`,
|
|
1540
|
+
* `"receiver"`, `"collateralReceiver"`, `"referralFeeRecipient"`, `"market.midnight"`,
|
|
1541
|
+
* `"authorized"`, `"publication.ratifier"`, `"loanToken"`, `"market.loanToken"`,
|
|
1542
|
+
* `"market.collateralParams[i].token"`, `"positionData.user"`, `"spender"` or `"token"` (a token
|
|
1543
|
+
* pulled with native funding, or the token checked by
|
|
1544
|
+
* `getMidnightApprovalRequirements`). `"blueMarket"` reports the Blue market encoding in
|
|
1545
|
+
* `supplyBlueMakeLend`: a malformed address or an out-of-range `lltv`.
|
|
1546
|
+
* @param cause - viem encoding error.
|
|
1547
|
+
*/
|
|
1548
|
+
constructor(input: string, cause: BaseError);
|
|
1549
|
+
}
|