@morpho-org/morpho-sdk 10.3.1 → 10.4.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 +169 -5
- package/lib/cjs/actions/midnight/redeem.d.ts +20 -3
- package/lib/cjs/actions/midnight/redeem.js +58 -1
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +41 -0
- package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -2
- package/lib/cjs/actions/midnight/withdrawCollateral.js +26 -1
- package/lib/cjs/helpers/callback.d.ts +3 -2
- package/lib/cjs/helpers/callback.js +4 -20
- package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
- package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.js +30 -0
- package/lib/cjs/helpers/parseMidnightMaker.d.ts +21 -0
- package/lib/cjs/helpers/parseMidnightMaker.js +41 -1
- package/lib/cjs/helpers/validate.d.ts +49 -1
- package/lib/cjs/helpers/validate.js +87 -1
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +10 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +18 -1
- package/lib/cjs/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
- package/lib/cjs/helpers/validateMidnightTakeableOfferFields.js +85 -0
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +23 -1
- package/lib/cjs/midnight/utils.d.ts +1 -1
- package/lib/cjs/midnight/utils.js +2 -1
- package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
- package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.js +264 -0
- package/lib/cjs/transactionPlan/error.d.ts +27 -0
- package/lib/cjs/transactionPlan/error.js +30 -1
- package/lib/cjs/transactionPlan/index.d.ts +40 -1
- package/lib/cjs/transactionPlan/index.js +46 -5
- package/lib/cjs/transactionPlan/midnight/authorization.d.ts +15 -0
- package/lib/cjs/transactionPlan/midnight/authorization.js +45 -0
- package/lib/cjs/transactionPlan/midnight/cancelOffers.d.ts +80 -0
- package/lib/cjs/transactionPlan/midnight/cancelOffers.js +125 -0
- package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +104 -0
- package/lib/cjs/transactionPlan/midnight/makeBorrow.js +126 -0
- package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +140 -0
- package/lib/cjs/transactionPlan/midnight/makeLend.js +176 -0
- package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +118 -0
- package/lib/cjs/transactionPlan/midnight/makeRepay.js +118 -0
- package/lib/cjs/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
- package/lib/cjs/transactionPlan/midnight/makeWithdraw.js +126 -0
- package/lib/cjs/transactionPlan/midnight/makerPublication.d.ts +55 -0
- package/lib/cjs/transactionPlan/midnight/makerPublication.js +315 -0
- package/lib/cjs/transactionPlan/midnight/market.d.ts +49 -0
- package/lib/cjs/transactionPlan/midnight/market.js +120 -0
- package/lib/cjs/transactionPlan/midnight/prepare.d.ts +244 -0
- package/lib/cjs/transactionPlan/midnight/prepare.js +547 -0
- package/lib/cjs/transactionPlan/midnight/publicationState.d.ts +24 -0
- package/lib/cjs/transactionPlan/midnight/publicationState.js +50 -0
- package/lib/cjs/transactionPlan/midnight/redeem.d.ts +102 -0
- package/lib/cjs/transactionPlan/midnight/redeem.js +170 -0
- package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
- package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.js +51 -0
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +328 -0
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +199 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +190 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +221 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +179 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +259 -0
- package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +304 -0
- package/lib/cjs/transactionPlan/midnight/takeBorrow.js +545 -0
- package/lib/cjs/transactionPlan/midnight/takeLend.d.ts +99 -0
- package/lib/cjs/transactionPlan/midnight/takeLend.js +263 -0
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +440 -0
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +240 -0
- package/lib/cjs/transactionPlan/midnight/validation.d.ts +22 -0
- package/lib/cjs/transactionPlan/midnight/validation.js +158 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateral.js +228 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.js +232 -0
- package/lib/cjs/transactionPlan/plan.d.ts +48 -14
- package/lib/cjs/transactionPlan/plan.js +103 -18
- package/lib/cjs/transactionPlan/requirements.d.ts +7 -4
- package/lib/cjs/transactionPlan/requirements.js +2 -2
- package/lib/cjs/transactionPlan/serde.d.ts +13 -2
- package/lib/cjs/transactionPlan/serde.js +68 -21
- package/lib/cjs/transactionPlan/types.d.ts +147 -0
- package/lib/cjs/transactionPlan/validateActions.d.ts +3 -1
- package/lib/cjs/transactionPlan/validateActions.js +31 -3
- package/lib/cjs/transactionPlan/validation.d.ts +1 -1
- package/lib/cjs/transactionPlan/validation.js +37 -1
- package/lib/cjs/types/error.d.ts +2 -0
- package/lib/cjs/types/error.js +2 -0
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/midnight/redeem.d.ts +20 -3
- package/lib/esm/actions/midnight/redeem.js +56 -0
- package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
- package/lib/esm/actions/midnight/supplyCollateralWithNative.js +40 -0
- package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -2
- package/lib/esm/actions/midnight/withdrawCollateral.js +25 -1
- package/lib/esm/helpers/callback.d.ts +3 -2
- package/lib/esm/helpers/callback.js +5 -21
- package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
- package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.js +27 -0
- package/lib/esm/helpers/parseMidnightMaker.d.ts +21 -0
- package/lib/esm/helpers/parseMidnightMaker.js +40 -1
- package/lib/esm/helpers/validate.d.ts +49 -1
- package/lib/esm/helpers/validate.js +84 -1
- package/lib/esm/helpers/validateMidnightPublication.d.ts +10 -0
- package/lib/esm/helpers/validateMidnightPublication.js +16 -0
- package/lib/esm/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
- package/lib/esm/helpers/validateMidnightTakeableOfferFields.js +81 -0
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/midnight/utils.d.ts +1 -1
- package/lib/esm/midnight/utils.js +1 -1
- package/lib/esm/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
- package/lib/esm/transactionPlan/blue/withdrawBuyCallback.js +259 -0
- package/lib/esm/transactionPlan/error.d.ts +27 -0
- package/lib/esm/transactionPlan/error.js +28 -0
- package/lib/esm/transactionPlan/index.d.ts +40 -1
- package/lib/esm/transactionPlan/index.js +20 -1
- package/lib/esm/transactionPlan/midnight/authorization.d.ts +15 -0
- package/lib/esm/transactionPlan/midnight/authorization.js +40 -0
- package/lib/esm/transactionPlan/midnight/cancelOffers.d.ts +80 -0
- package/lib/esm/transactionPlan/midnight/cancelOffers.js +120 -0
- package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +104 -0
- package/lib/esm/transactionPlan/midnight/makeBorrow.js +123 -0
- package/lib/esm/transactionPlan/midnight/makeLend.d.ts +140 -0
- package/lib/esm/transactionPlan/midnight/makeLend.js +172 -0
- package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +118 -0
- package/lib/esm/transactionPlan/midnight/makeRepay.js +115 -0
- package/lib/esm/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
- package/lib/esm/transactionPlan/midnight/makeWithdraw.js +123 -0
- package/lib/esm/transactionPlan/midnight/makerPublication.d.ts +55 -0
- package/lib/esm/transactionPlan/midnight/makerPublication.js +310 -0
- package/lib/esm/transactionPlan/midnight/market.d.ts +49 -0
- package/lib/esm/transactionPlan/midnight/market.js +112 -0
- package/lib/esm/transactionPlan/midnight/prepare.d.ts +244 -0
- package/lib/esm/transactionPlan/midnight/prepare.js +536 -0
- package/lib/esm/transactionPlan/midnight/publicationState.d.ts +24 -0
- package/lib/esm/transactionPlan/midnight/publicationState.js +47 -0
- package/lib/esm/transactionPlan/midnight/redeem.d.ts +102 -0
- package/lib/esm/transactionPlan/midnight/redeem.js +165 -0
- package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
- package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.js +47 -0
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +323 -0
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +196 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateral.js +185 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +216 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +176 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +254 -0
- package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +304 -0
- package/lib/esm/transactionPlan/midnight/takeBorrow.js +539 -0
- package/lib/esm/transactionPlan/midnight/takeLend.d.ts +99 -0
- package/lib/esm/transactionPlan/midnight/takeLend.js +258 -0
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +435 -0
- package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
- package/lib/esm/transactionPlan/midnight/takeWithdraw.js +236 -0
- package/lib/esm/transactionPlan/midnight/validation.d.ts +22 -0
- package/lib/esm/transactionPlan/midnight/validation.js +151 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateral.js +223 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.js +227 -0
- package/lib/esm/transactionPlan/plan.d.ts +48 -14
- package/lib/esm/transactionPlan/plan.js +99 -14
- package/lib/esm/transactionPlan/requirements.d.ts +7 -4
- package/lib/esm/transactionPlan/requirements.js +2 -2
- package/lib/esm/transactionPlan/serde.d.ts +13 -2
- package/lib/esm/transactionPlan/serde.js +49 -2
- package/lib/esm/transactionPlan/types.d.ts +147 -0
- package/lib/esm/transactionPlan/validateActions.d.ts +3 -1
- package/lib/esm/transactionPlan/validateActions.js +31 -3
- package/lib/esm/transactionPlan/validation.d.ts +1 -1
- package/lib/esm/transactionPlan/validation.js +38 -2
- package/lib/esm/types/error.d.ts +2 -0
- package/lib/esm/types/error.js +2 -0
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +2 -2
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { InputMarketParams, MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { MarketUtils } from "@morpho-org/midnight-sdk";
|
|
2
3
|
import type { Address, Hex } from "viem";
|
|
3
4
|
import type { BlueRepayParams } from "../actions/blue/repay.js";
|
|
4
5
|
import type { BlueRepayWithdrawCollateralParams } from "../actions/blue/repayWithdrawCollateral.js";
|
|
5
6
|
import type { BlueSupplyCollateralBorrowParams } from "../actions/blue/supplyCollateralBorrow.js";
|
|
7
|
+
import type { MidnightRepayWithdrawCollateralParams } from "../actions/midnight/repayWithdrawCollateral.js";
|
|
8
|
+
import type { MidnightTakeBorrowParams } from "../actions/midnight/takeBorrow.js";
|
|
9
|
+
import type { MidnightTakeLendParams } from "../actions/midnight/takeLend.js";
|
|
10
|
+
import type { MidnightTakeRepayWithdrawCollateralParams } from "../actions/midnight/takeRepayWithdrawCollateral.js";
|
|
11
|
+
import type { MidnightTakeableOffer } from "../actions/midnight/types.js";
|
|
12
|
+
import type { MidnightBlueSupply, MidnightCollateralTransfer } from "../types/action.js";
|
|
6
13
|
import type { AuthorizationSignatureArgs, PermitAction, RequirementTypedData, VaultV1MigrateToV2AmountArgs, VaultV2BlueReallocation } from "../types/index.js";
|
|
14
|
+
import type { MidnightCancelAndMakeParams } from "../types/midnightCancelAndMake.js";
|
|
7
15
|
interface ActionInputs {
|
|
8
16
|
readonly chainId: number;
|
|
9
17
|
readonly account: Address;
|
|
@@ -25,6 +33,18 @@ type VaultSignatureRequestIds = {
|
|
|
25
33
|
/** Token permit consumed by the action; omitted when no permit is needed. */
|
|
26
34
|
readonly tokenPermit?: string;
|
|
27
35
|
};
|
|
36
|
+
type MidnightSellInputs = ActionInputs & Omit<MidnightTakeBorrowParams, "chainId" | "market" | "metadata" | "referralFeePct" | "referralFeeRecipient"> & {
|
|
37
|
+
readonly market: MidnightTakeableOffer["offer"]["market"];
|
|
38
|
+
readonly referralFeePct: bigint;
|
|
39
|
+
readonly referralFeeRecipient: Address;
|
|
40
|
+
};
|
|
41
|
+
type MidnightMakerPublicationInputs = ActionInputs & Pick<MidnightCancelAndMakeParams, "cancellations" | "deadline"> & {
|
|
42
|
+
readonly ratifierType: "priceV1" | "rateV1";
|
|
43
|
+
readonly ratifier: Address;
|
|
44
|
+
readonly root: Hex;
|
|
45
|
+
readonly groups: readonly Hex[];
|
|
46
|
+
readonly payload: Hex;
|
|
47
|
+
};
|
|
28
48
|
/**
|
|
29
49
|
* Recipes supported by TransactionPlan.
|
|
30
50
|
* Snapshot-derived values such as the asset and the quote are fixed on `inputs` at preparation;
|
|
@@ -33,6 +53,119 @@ type VaultSignatureRequestIds = {
|
|
|
33
53
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
34
54
|
*/
|
|
35
55
|
export type Action = {
|
|
56
|
+
readonly type: "midnightMakeBorrow";
|
|
57
|
+
readonly inputs: MidnightMakerPublicationInputs;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "midnightMakeLend";
|
|
60
|
+
readonly inputs: MidnightMakerPublicationInputs;
|
|
61
|
+
} | {
|
|
62
|
+
readonly type: "midnightMakeRepay";
|
|
63
|
+
readonly inputs: MidnightMakerPublicationInputs;
|
|
64
|
+
} | {
|
|
65
|
+
readonly type: "midnightMakeWithdraw";
|
|
66
|
+
readonly inputs: MidnightMakerPublicationInputs;
|
|
67
|
+
} | {
|
|
68
|
+
readonly type: "midnightSupplyBlueMakeLend";
|
|
69
|
+
readonly inputs: MidnightMakerPublicationInputs & {
|
|
70
|
+
readonly blueSupply: MidnightBlueSupply;
|
|
71
|
+
/** Native ETH in wei, passed as transaction value. */
|
|
72
|
+
readonly nativeAssets?: bigint;
|
|
73
|
+
};
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: "midnightSupplyCollateralMakeBorrow";
|
|
76
|
+
readonly inputs: MidnightMakerPublicationInputs & {
|
|
77
|
+
readonly collateral: {
|
|
78
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
79
|
+
readonly supplies: readonly MidnightCollateralTransfer[];
|
|
80
|
+
};
|
|
81
|
+
/** Native ETH in wei, passed as transaction value. */
|
|
82
|
+
readonly nativeAssets?: bigint;
|
|
83
|
+
};
|
|
84
|
+
} | {
|
|
85
|
+
readonly type: "midnightRepayWithdrawCollateral";
|
|
86
|
+
readonly inputs: ActionInputs & Omit<MidnightRepayWithdrawCollateralParams, "chainId" | "market" | "metadata" | "nativeAmount"> & {
|
|
87
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
88
|
+
/** Native ETH in wei, passed as transaction value. Omitted or zero means no ETH funding. */
|
|
89
|
+
readonly nativeAssets?: bigint;
|
|
90
|
+
};
|
|
91
|
+
} | {
|
|
92
|
+
readonly type: "midnightTakeBorrow";
|
|
93
|
+
readonly inputs: MidnightSellInputs;
|
|
94
|
+
} | {
|
|
95
|
+
readonly type: "midnightTakeRepayWithdrawCollateral";
|
|
96
|
+
readonly inputs: ActionInputs & Omit<MidnightTakeRepayWithdrawCollateralParams, "chainId" | "market" | "metadata" | "nativeAmount" | "referralFeePct" | "referralFeeRecipient"> & {
|
|
97
|
+
readonly market: MidnightTakeableOffer["offer"]["market"];
|
|
98
|
+
readonly nativeAssets?: bigint;
|
|
99
|
+
readonly referralFeePct: bigint;
|
|
100
|
+
readonly referralFeeRecipient: Address;
|
|
101
|
+
};
|
|
102
|
+
} | {
|
|
103
|
+
readonly type: "midnightSupplyCollateralTakeBorrow";
|
|
104
|
+
readonly inputs: MidnightSellInputs & {
|
|
105
|
+
readonly collateralSupplies: readonly MidnightCollateralTransfer[];
|
|
106
|
+
/** Native ETH in wei, passed as transaction value. */
|
|
107
|
+
readonly nativeAssets?: bigint;
|
|
108
|
+
};
|
|
109
|
+
} | {
|
|
110
|
+
readonly type: "midnightTakeWithdraw";
|
|
111
|
+
readonly inputs: MidnightSellInputs;
|
|
112
|
+
} | {
|
|
113
|
+
readonly type: "midnightTakeLend";
|
|
114
|
+
readonly inputs: ActionInputs & Omit<MidnightTakeLendParams, "chainId" | "market" | "metadata" | "nativeAmount" | "referralFeePct" | "referralFeeRecipient"> & {
|
|
115
|
+
readonly market: MidnightTakeableOffer["offer"]["market"];
|
|
116
|
+
readonly nativeAssets?: bigint;
|
|
117
|
+
readonly referralFeePct: bigint;
|
|
118
|
+
readonly referralFeeRecipient: Address;
|
|
119
|
+
};
|
|
120
|
+
} | {
|
|
121
|
+
readonly type: "midnightAuthorization";
|
|
122
|
+
readonly inputs: ActionInputs;
|
|
123
|
+
} | {
|
|
124
|
+
readonly type: "midnightSupplyCollateral";
|
|
125
|
+
readonly inputs: ActionInputs & {
|
|
126
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
127
|
+
readonly collateralIndex: bigint;
|
|
128
|
+
readonly collateralAssets: bigint;
|
|
129
|
+
};
|
|
130
|
+
} | {
|
|
131
|
+
readonly type: "midnightWithdrawCollateral";
|
|
132
|
+
readonly inputs: ActionInputs & {
|
|
133
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
134
|
+
readonly collateralIndex: bigint;
|
|
135
|
+
readonly assets: bigint;
|
|
136
|
+
readonly receiver: Address;
|
|
137
|
+
};
|
|
138
|
+
} | {
|
|
139
|
+
readonly type: "midnightWithdrawCollateralBatch";
|
|
140
|
+
readonly inputs: ActionInputs & {
|
|
141
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
142
|
+
readonly collateralWithdrawals: readonly MidnightCollateralTransfer[];
|
|
143
|
+
readonly receiver: Address;
|
|
144
|
+
};
|
|
145
|
+
} | {
|
|
146
|
+
readonly type: "midnightSupplyCollateralBatch";
|
|
147
|
+
readonly inputs: ActionInputs & {
|
|
148
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
149
|
+
readonly collateralSupplies: readonly MidnightCollateralTransfer[];
|
|
150
|
+
};
|
|
151
|
+
} | {
|
|
152
|
+
readonly type: "midnightSupplyCollateralWithNative";
|
|
153
|
+
readonly inputs: ActionInputs & {
|
|
154
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
155
|
+
readonly collateralIndex: bigint;
|
|
156
|
+
readonly collateralAssets: bigint;
|
|
157
|
+
/** Native ETH in wei, passed as transaction value. */
|
|
158
|
+
readonly nativeAssets: bigint;
|
|
159
|
+
readonly deadline: bigint;
|
|
160
|
+
};
|
|
161
|
+
} | {
|
|
162
|
+
readonly type: "midnightRedeem";
|
|
163
|
+
readonly inputs: ActionInputs & {
|
|
164
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
165
|
+
readonly units: bigint;
|
|
166
|
+
readonly receiver: Address;
|
|
167
|
+
};
|
|
168
|
+
} | {
|
|
36
169
|
readonly type: "vaultV2ForceRedeem";
|
|
37
170
|
readonly inputs: ActionInputs & {
|
|
38
171
|
readonly vault: Address;
|
|
@@ -151,6 +284,15 @@ export type Action = {
|
|
|
151
284
|
readonly referralFeePct: bigint;
|
|
152
285
|
readonly referralFeeRecipient: Address;
|
|
153
286
|
};
|
|
287
|
+
} | {
|
|
288
|
+
readonly type: "blueWithdrawBuyCallback";
|
|
289
|
+
readonly inputs: ActionInputs & {
|
|
290
|
+
readonly marketParams: Readonly<InputMarketParams>;
|
|
291
|
+
/** BlueBuyCallback whose supply position is withdrawn to `account`, its owner. */
|
|
292
|
+
readonly callbackAddress: Address;
|
|
293
|
+
/** Every supply share the callback held in the prepared snapshot. */
|
|
294
|
+
readonly shares: bigint;
|
|
295
|
+
};
|
|
154
296
|
} | {
|
|
155
297
|
readonly type: "blueRepayWithdrawCollateral";
|
|
156
298
|
readonly inputs: ActionInputs & Omit<BlueRepayWithdrawCollateralParams["args"], "userAddress" | "requirementSignature" | "authorizationSignature" | "nativeAmount"> & {
|
|
@@ -283,6 +425,11 @@ export type Action = {
|
|
|
283
425
|
} | {
|
|
284
426
|
readonly type: "morphoAuthorization";
|
|
285
427
|
readonly inputs: ActionInputs;
|
|
428
|
+
} | {
|
|
429
|
+
readonly type: "midnightCancelOffers";
|
|
430
|
+
readonly inputs: ActionInputs & {
|
|
431
|
+
readonly groups: readonly Hex[];
|
|
432
|
+
};
|
|
286
433
|
};
|
|
287
434
|
/**
|
|
288
435
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Step } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
* @internal Rejects unknown action types
|
|
3
|
+
* @internal Rejects unknown action types, and Midnight steps carrying a signature-request map,
|
|
4
|
+
* before interpreting requests or updates.
|
|
4
5
|
* @param steps - Steps whose action discriminators must be supported.
|
|
5
6
|
* @returns Nothing when every action type is supported.
|
|
6
7
|
* @throws {UnsupportedTransactionPlanActionError} when any step names an unsupported action type.
|
|
8
|
+
* @throws {InvalidTransactionPlanError} when a Midnight step carries `signatureRequestIds`, as restore does.
|
|
7
9
|
*/
|
|
8
10
|
export declare function validateTransactionPlanActions(steps: readonly Step[]): void;
|
|
@@ -2,16 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateTransactionPlanActions = validateTransactionPlanActions;
|
|
4
4
|
const error_js_1 = require("./error.js");
|
|
5
|
+
const authorization_js_1 = require("./midnight/authorization.js");
|
|
5
6
|
/**
|
|
6
|
-
* @internal Rejects unknown action types
|
|
7
|
+
* @internal Rejects unknown action types, and Midnight steps carrying a signature-request map,
|
|
8
|
+
* before interpreting requests or updates.
|
|
7
9
|
* @param steps - Steps whose action discriminators must be supported.
|
|
8
10
|
* @returns Nothing when every action type is supported.
|
|
9
11
|
* @throws {UnsupportedTransactionPlanActionError} when any step names an unsupported action type.
|
|
12
|
+
* @throws {InvalidTransactionPlanError} when a Midnight step carries `signatureRequestIds`, as restore does.
|
|
10
13
|
*/
|
|
11
14
|
function validateTransactionPlanActions(steps) {
|
|
12
|
-
for (const step of steps) {
|
|
15
|
+
for (const [index, step] of steps.entries()) {
|
|
13
16
|
const actionType = step.action.type;
|
|
14
|
-
if (actionType !== "
|
|
17
|
+
if (actionType !== "midnightRedeem" &&
|
|
18
|
+
actionType !== "blueRefinance" &&
|
|
15
19
|
actionType !== "erc20Approval" &&
|
|
16
20
|
actionType !== "vaultV1Deposit" &&
|
|
17
21
|
actionType !== "vaultV1MigrateToV2" &&
|
|
@@ -23,8 +27,28 @@ function validateTransactionPlanActions(steps) {
|
|
|
23
27
|
actionType !== "blueRepay" &&
|
|
24
28
|
actionType !== "blueWithdraw" &&
|
|
25
29
|
actionType !== "blueWithdrawCollateral" &&
|
|
30
|
+
actionType !== "blueWithdrawBuyCallback" &&
|
|
26
31
|
actionType !== "blueRepayWithdrawCollateral" &&
|
|
27
32
|
actionType !== "morphoAuthorization" &&
|
|
33
|
+
actionType !== "midnightAuthorization" &&
|
|
34
|
+
actionType !== "midnightMakeBorrow" &&
|
|
35
|
+
actionType !== "midnightMakeLend" &&
|
|
36
|
+
actionType !== "midnightMakeRepay" &&
|
|
37
|
+
actionType !== "midnightMakeWithdraw" &&
|
|
38
|
+
actionType !== "midnightSupplyBlueMakeLend" &&
|
|
39
|
+
actionType !== "midnightSupplyCollateralMakeBorrow" &&
|
|
40
|
+
actionType !== "midnightTakeBorrow" &&
|
|
41
|
+
actionType !== "midnightSupplyCollateralTakeBorrow" &&
|
|
42
|
+
actionType !== "midnightTakeLend" &&
|
|
43
|
+
actionType !== "midnightTakeRepayWithdrawCollateral" &&
|
|
44
|
+
actionType !== "midnightTakeWithdraw" &&
|
|
45
|
+
actionType !== "midnightRepayWithdrawCollateral" &&
|
|
46
|
+
actionType !== "midnightSupplyCollateral" &&
|
|
47
|
+
actionType !== "midnightSupplyCollateralWithNative" &&
|
|
48
|
+
actionType !== "midnightSupplyCollateralBatch" &&
|
|
49
|
+
actionType !== "midnightWithdrawCollateral" &&
|
|
50
|
+
actionType !== "midnightWithdrawCollateralBatch" &&
|
|
51
|
+
actionType !== "midnightCancelOffers" &&
|
|
28
52
|
actionType !== "vaultV2Deposit" &&
|
|
29
53
|
actionType !== "vaultV2Withdraw" &&
|
|
30
54
|
actionType !== "vaultV2Redeem" &&
|
|
@@ -35,5 +59,9 @@ function validateTransactionPlanActions(steps) {
|
|
|
35
59
|
actionType !== "vaultV2InKindRedeem") {
|
|
36
60
|
throw new error_js_1.UnsupportedTransactionPlanActionError(actionType);
|
|
37
61
|
}
|
|
62
|
+
if (actionType.startsWith("midnight")) {
|
|
63
|
+
// Every Midnight step is signatureless: build and inspection reject the maps restore rejects.
|
|
64
|
+
(0, authorization_js_1.validateSignaturelessMidnightAction)(step.action, `$.steps[${index}].action`);
|
|
65
|
+
}
|
|
38
66
|
}
|
|
39
67
|
}
|
|
@@ -7,7 +7,7 @@ export declare function validateTransactionPlanHeader(plan: TransactionPlan): vo
|
|
|
7
7
|
/** @internal Compares an untrusted address without throwing on malformed input. */
|
|
8
8
|
export declare function matchesAddress(value: unknown, expected: Address): boolean;
|
|
9
9
|
/** @internal Scalar and collection shapes used by stored plan fields. */
|
|
10
|
-
type PlanFieldType = "string" | "address" | "hex" | "safe integer" | "positive safe integer" | "bigint" | "uint256 bigint" | "array";
|
|
10
|
+
type PlanFieldType = "string" | "address" | "hex" | "bytes32" | "boolean" | "safe integer" | "positive safe integer" | "bigint" | "uint128 bigint" | "uint256 bigint" | "array";
|
|
11
11
|
/** @internal Validates one restored field without coercing it. */
|
|
12
12
|
export declare function validatePlanField(value: unknown, options: {
|
|
13
13
|
readonly path: string;
|
|
@@ -9,6 +9,25 @@ exports.validatePlanFields = validatePlanFields;
|
|
|
9
9
|
exports.validateVaultPlanAction = validateVaultPlanAction;
|
|
10
10
|
const viem_1 = require("viem");
|
|
11
11
|
const error_js_1 = require("./error.js");
|
|
12
|
+
/**
|
|
13
|
+
* @internal Actions whose preparation stores `deadline = BigInt(expiresAt)`, so any other stored
|
|
14
|
+
* deadline would let the bundle execute after the expiry the plan reports.
|
|
15
|
+
*/
|
|
16
|
+
const EXPIRES_AT_DEADLINE_ACTIONS = new Set([
|
|
17
|
+
"midnightTakeLend",
|
|
18
|
+
"midnightTakeBorrow",
|
|
19
|
+
"midnightTakeWithdraw",
|
|
20
|
+
"midnightRepayWithdrawCollateral",
|
|
21
|
+
"midnightMakeBorrow",
|
|
22
|
+
"midnightMakeLend",
|
|
23
|
+
"midnightMakeWithdraw",
|
|
24
|
+
"midnightMakeRepay",
|
|
25
|
+
"midnightSupplyCollateralMakeBorrow",
|
|
26
|
+
"midnightSupplyBlueMakeLend",
|
|
27
|
+
"midnightSupplyCollateralTakeBorrow",
|
|
28
|
+
"midnightTakeRepayWithdrawCollateral",
|
|
29
|
+
"midnightSupplyCollateralWithNative",
|
|
30
|
+
]);
|
|
12
31
|
/** @internal Maximum calldata-origin length in bytes. */
|
|
13
32
|
const MAX_CALLDATA_ORIGIN_BYTES = 1024 * 1024;
|
|
14
33
|
/** @internal Rejects attribution bytes above the preparation and stored-plan limit. */
|
|
@@ -70,6 +89,13 @@ function validateTransactionPlanHeader(plan) {
|
|
|
70
89
|
reason: "expected a deadline no earlier than expiresAt",
|
|
71
90
|
});
|
|
72
91
|
}
|
|
92
|
+
if (EXPIRES_AT_DEADLINE_ACTIONS.has(step.action.type) &&
|
|
93
|
+
(!("deadline" in inputs) || inputs.deadline !== BigInt(plan.expiresAt))) {
|
|
94
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
95
|
+
path: `${path}.action.inputs.deadline`,
|
|
96
|
+
reason: "expected the plan expiresAt",
|
|
97
|
+
});
|
|
98
|
+
}
|
|
73
99
|
}
|
|
74
100
|
const requestIds = new Set();
|
|
75
101
|
for (const [index, request] of plan.signatureRequests.entries()) {
|
|
@@ -111,6 +137,12 @@ function validatePlanField(value, options) {
|
|
|
111
137
|
valid =
|
|
112
138
|
typeof value === "string" && /^0x(?:[0-9a-fA-F]{2})*$/.test(value);
|
|
113
139
|
break;
|
|
140
|
+
case "bytes32":
|
|
141
|
+
valid = typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value);
|
|
142
|
+
break;
|
|
143
|
+
case "boolean":
|
|
144
|
+
valid = typeof value === "boolean";
|
|
145
|
+
break;
|
|
114
146
|
case "safe integer":
|
|
115
147
|
valid = typeof value === "number" && Number.isSafeInteger(value);
|
|
116
148
|
break;
|
|
@@ -121,8 +153,12 @@ function validatePlanField(value, options) {
|
|
|
121
153
|
case "bigint":
|
|
122
154
|
valid = typeof value === "bigint";
|
|
123
155
|
break;
|
|
156
|
+
case "uint128 bigint":
|
|
124
157
|
case "uint256 bigint":
|
|
125
|
-
valid =
|
|
158
|
+
valid =
|
|
159
|
+
typeof value === "bigint" &&
|
|
160
|
+
value >= 0n &&
|
|
161
|
+
value <= (type === "uint128 bigint" ? viem_1.maxUint128 : viem_1.maxUint256);
|
|
126
162
|
break;
|
|
127
163
|
case "array":
|
|
128
164
|
valid = Array.isArray(value);
|
package/lib/cjs/types/error.d.ts
CHANGED
|
@@ -1683,6 +1683,8 @@ export declare class MidnightCalldataEncodingError extends Error {
|
|
|
1683
1683
|
* pulled with native funding, or the token checked by
|
|
1684
1684
|
* `getMidnightApprovalRequirements`). `"blueMarket"` reports the Blue market encoding in
|
|
1685
1685
|
* `supplyBlueMakeLend`: a malformed address or an out-of-range `lltv`.
|
|
1686
|
+
* TransactionPlan take preparers report a malformed taken offer field by its path, such as
|
|
1687
|
+
* `"takeableOffers[i].offer.maker"` or `"takeableOffers[i].units"`.
|
|
1686
1688
|
* @param cause - viem encoding error.
|
|
1687
1689
|
*/
|
|
1688
1690
|
constructor(input: string, cause: BaseError);
|
package/lib/cjs/types/error.js
CHANGED
|
@@ -2172,6 +2172,8 @@ class MidnightCalldataEncodingError extends Error {
|
|
|
2172
2172
|
* pulled with native funding, or the token checked by
|
|
2173
2173
|
* `getMidnightApprovalRequirements`). `"blueMarket"` reports the Blue market encoding in
|
|
2174
2174
|
* `supplyBlueMakeLend`: a malformed address or an out-of-range `lltv`.
|
|
2175
|
+
* TransactionPlan take preparers report a malformed taken offer field by its path, such as
|
|
2176
|
+
* `"takeableOffers[i].offer.maker"` or `"takeableOffers[i].units"`.
|
|
2175
2177
|
* @param cause - viem encoding error.
|
|
2176
2178
|
*/
|
|
2177
2179
|
constructor(input, cause) {
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Installed @morpho-org/morpho-sdk package version. */
|
|
2
|
-
export declare const version = "10.
|
|
2
|
+
export declare const version = "10.4.0";
|
package/lib/cjs/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
-
import type
|
|
1
|
+
import type { AccrualPosition, MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
3
|
import { type MidnightMarket } from "../../helpers/parseMidnight.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type Metadata, type MidnightRedeemAction, type Transaction } from "../../types/index.js";
|
|
5
5
|
/** Parameters for encoding a direct Midnight credit redemption. */
|
|
6
6
|
export interface MidnightRedeemParams {
|
|
7
7
|
readonly chainId: number;
|
|
@@ -63,4 +63,21 @@ export interface ParsedMidnightRedeem extends Omit<MidnightRedeemParams, "market
|
|
|
63
63
|
}
|
|
64
64
|
/** Parses static redeem constraints using the existing error order. @internal */
|
|
65
65
|
export declare const parseMidnightRedeem: (params: MidnightRedeemParams) => ParsedMidnightRedeem;
|
|
66
|
+
/** Owner-bound position snapshot and optional amounts for a redemption. @internal */
|
|
67
|
+
export interface MidnightRedeemPreparationParams {
|
|
68
|
+
readonly chainId: number;
|
|
69
|
+
readonly accountAddress: Address;
|
|
70
|
+
readonly positionData: AccrualPosition;
|
|
71
|
+
readonly units?: bigint;
|
|
72
|
+
readonly receiver?: Address;
|
|
73
|
+
readonly now: bigint;
|
|
74
|
+
readonly metadata?: Metadata;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Owns redemption defaults and snapshot-dependent amount constraints in the same order as the
|
|
78
|
+
* entity `redeem`, then mints the complete redeem contract. Used by TransactionPlan preparation;
|
|
79
|
+
* the entity keeps its own copy of these checks.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export declare const parseMidnightRedeemPreparation: (params: MidnightRedeemPreparationParams) => ParsedMidnightRedeem;
|
|
66
83
|
export {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { MathLib } from "@morpho-org/blue-sdk";
|
|
1
2
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { isAddressEqual } from "viem";
|
|
2
4
|
import { parseMidnightAddress, parseMidnightMarket, parseMidnightOwner, parseMidnightPositiveAmount, } from "../../helpers/parseMidnight.js";
|
|
5
|
+
import { validateMidnightAddress } from "../../helpers/validateMidnightAccount.js";
|
|
3
6
|
import { validateMidnightReceiver } from "../../helpers/validateMidnightReceiver.js";
|
|
7
|
+
import { AccrualPositionUserMismatchError, InsufficientMidnightWithdrawableLiquidityError, MidnightRedeemExceedsCreditError, MissingAccrualPositionError, NoMidnightCreditToRedeemError, } from "../../types/index.js";
|
|
4
8
|
import { encodeMidnightRedeem } from "./encode.js";
|
|
5
9
|
import { snapshotMidnightMetadata } from "./parse.js";
|
|
6
10
|
/**
|
|
@@ -70,3 +74,55 @@ export const parseMidnightRedeem = (params) => {
|
|
|
70
74
|
[parsedRedeem]: true,
|
|
71
75
|
});
|
|
72
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Owns redemption defaults and snapshot-dependent amount constraints in the same order as the
|
|
79
|
+
* entity `redeem`, then mints the complete redeem contract. Used by TransactionPlan preparation;
|
|
80
|
+
* the entity keeps its own copy of these checks.
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export const parseMidnightRedeemPreparation = (params) => {
|
|
84
|
+
const address = parseMidnightAddress("accountAddress", params.accountAddress);
|
|
85
|
+
if (!params.positionData) {
|
|
86
|
+
throw new MissingAccrualPositionError();
|
|
87
|
+
}
|
|
88
|
+
if (params.positionData.user != null) {
|
|
89
|
+
validateMidnightAddress("positionData.user", params.positionData.user);
|
|
90
|
+
}
|
|
91
|
+
if (params.positionData.user == null ||
|
|
92
|
+
!isAddressEqual(params.positionData.user, address)) {
|
|
93
|
+
throw new AccrualPositionUserMismatchError(params.positionData.user ?? "unbound", address);
|
|
94
|
+
}
|
|
95
|
+
const marketData = params.positionData.market;
|
|
96
|
+
// Reject market/deployment errors before snapshot accrual and amount checks.
|
|
97
|
+
const market = parseMidnightMarket(marketData, params.chainId);
|
|
98
|
+
const accrued = params.positionData.accrueInterest(MathLib.max(params.now, params.positionData.lastAccrual));
|
|
99
|
+
const units = params.units ?? accrued.faceValue;
|
|
100
|
+
if (params.units === undefined && units <= 0n) {
|
|
101
|
+
throw new NoMidnightCreditToRedeemError(marketData.id);
|
|
102
|
+
}
|
|
103
|
+
// Bound the resolved amount before checking credit and liquidity.
|
|
104
|
+
parseMidnightPositiveAmount("units", units);
|
|
105
|
+
if (accrued.credit < units) {
|
|
106
|
+
throw new MidnightRedeemExceedsCreditError({
|
|
107
|
+
market: marketData.id,
|
|
108
|
+
units,
|
|
109
|
+
credit: accrued.credit,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (marketData.withdrawable < units) {
|
|
113
|
+
throw new InsufficientMidnightWithdrawableLiquidityError({
|
|
114
|
+
market: marketData.id,
|
|
115
|
+
units,
|
|
116
|
+
withdrawable: marketData.withdrawable,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// The owning action constructor mints the complete contract only after snapshot checks.
|
|
120
|
+
return parseMidnightRedeem({
|
|
121
|
+
chainId: params.chainId,
|
|
122
|
+
market: market.struct,
|
|
123
|
+
units,
|
|
124
|
+
onBehalf: address,
|
|
125
|
+
receiver: params.receiver ?? address,
|
|
126
|
+
metadata: params.metadata,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
1
|
+
import { type MarketInput, MarketUtils } from "@morpho-org/midnight-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
+
import { encodeMidnightMarketId } from "../../helpers/encodeMidnightCalldata.js";
|
|
3
4
|
import { type Metadata, type MidnightSupplyCollateralWithNativeAction, type Transaction } from "../../types/index.js";
|
|
4
5
|
/** Parameters for encoding a Midnight collateral supply. */
|
|
5
6
|
export interface MidnightSupplyCollateralWithNativeParams {
|
|
@@ -75,3 +76,25 @@ export declare function prepareMidnightSupplyCollateralWithNative(params: Midnig
|
|
|
75
76
|
token: `0x${string}`;
|
|
76
77
|
tx: Transaction<MidnightSupplyCollateralWithNativeAction>;
|
|
77
78
|
};
|
|
79
|
+
/** Owned native collateral supply inputs, checked in the encoder's order. @internal */
|
|
80
|
+
export interface ParsedMidnightSupplyCollateralWithNative {
|
|
81
|
+
readonly chainId: number;
|
|
82
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
83
|
+
readonly marketId: ReturnType<typeof encodeMidnightMarketId>;
|
|
84
|
+
readonly collateralIndex: bigint;
|
|
85
|
+
readonly assets: bigint;
|
|
86
|
+
/** wNative collateral pulled from the sender. */
|
|
87
|
+
readonly token: Address;
|
|
88
|
+
readonly accountAddress: Address;
|
|
89
|
+
/** Native funding sent as transaction value. */
|
|
90
|
+
readonly value: bigint;
|
|
91
|
+
readonly wrappedNative: Address;
|
|
92
|
+
readonly deadline: bigint;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parses a native collateral supply with the same checks, in the same order, as
|
|
96
|
+
* `midnightSupplyCollateralWithNative`, without encoding the bundle call. Resolving
|
|
97
|
+
* MidnightBundlesV2 is left to the caller. `assetsField` names the amount in its errors, so a
|
|
98
|
+
* caller can report its own parameter name. @internal
|
|
99
|
+
*/
|
|
100
|
+
export declare function parseMidnightSupplyCollateralWithNative(params: Omit<MidnightSupplyCollateralWithNativeParams, "metadata">, assetsField?: "assets" | "collateralAssets"): ParsedMidnightSupplyCollateralWithNative;
|
|
@@ -135,3 +135,43 @@ export function prepareMidnightSupplyCollateralWithNative(params) {
|
|
|
135
135
|
}),
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Parses a native collateral supply with the same checks, in the same order, as
|
|
140
|
+
* `midnightSupplyCollateralWithNative`, without encoding the bundle call. Resolving
|
|
141
|
+
* MidnightBundlesV2 is left to the caller. `assetsField` names the amount in its errors, so a
|
|
142
|
+
* caller can report its own parameter name. @internal
|
|
143
|
+
*/
|
|
144
|
+
export function parseMidnightSupplyCollateralWithNative(params, assetsField = "assets") {
|
|
145
|
+
validateMidnightAddress("accountAddress", params.accountAddress);
|
|
146
|
+
const assets = parseMidnightNativeCollateralAmount(assetsField, params.assets);
|
|
147
|
+
if (isAddressEqual(params.accountAddress, zeroAddress)) {
|
|
148
|
+
throw new MidnightZeroOnBehalfError("accountAddress");
|
|
149
|
+
}
|
|
150
|
+
validateMidnightMarket({ market: params.market, chainId: params.chainId });
|
|
151
|
+
const market = wrapMidnightEncoding("marketId", () => MarketUtils.toStruct(params.market));
|
|
152
|
+
const marketId = encodeMidnightMarketId(market);
|
|
153
|
+
const collateralIndex = params.collateralIndex ?? 0n;
|
|
154
|
+
const { token } = MarketUtils.getCollateralByIndex(market, collateralIndex);
|
|
155
|
+
if (params.nativeAmount === 0n || params.nativeAmount === undefined) {
|
|
156
|
+
throw new NonPositiveInputError("nativeAmount", params.nativeAmount ?? 0n);
|
|
157
|
+
}
|
|
158
|
+
const { value, wrappedNative } = validateMidnightNativeAmount({
|
|
159
|
+
chainId: params.chainId,
|
|
160
|
+
nativeAmount: params.nativeAmount,
|
|
161
|
+
pulls: [{ token, assets }],
|
|
162
|
+
});
|
|
163
|
+
const deadline = params.deadline ?? 0n;
|
|
164
|
+
validateDeadline(deadline);
|
|
165
|
+
return deepFreeze({
|
|
166
|
+
chainId: params.chainId,
|
|
167
|
+
market,
|
|
168
|
+
marketId,
|
|
169
|
+
collateralIndex,
|
|
170
|
+
assets,
|
|
171
|
+
token,
|
|
172
|
+
accountAddress: params.accountAddress,
|
|
173
|
+
value,
|
|
174
|
+
wrappedNative,
|
|
175
|
+
deadline,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
-
import type
|
|
1
|
+
import type { AccrualPosition, Market, MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
3
|
import { type MidnightMarket } from "../../helpers/parseMidnight.js";
|
|
4
4
|
import type { Metadata, MidnightWithdrawCollateralAction, Transaction } from "../../types/index.js";
|
|
5
5
|
/** Parameters for encoding a direct Midnight collateral withdrawal. */
|
|
@@ -60,4 +60,18 @@ export interface ParsedMidnightWithdrawCollateral extends Omit<MidnightWithdrawC
|
|
|
60
60
|
}
|
|
61
61
|
/** Parses static withdrawCollateral constraints using the existing error order. @internal */
|
|
62
62
|
export declare const parseMidnightWithdrawCollateral: (params: MidnightWithdrawCollateralParams) => ParsedMidnightWithdrawCollateral;
|
|
63
|
+
/** Complete raw withdrawal preparation; domain snapshots stay caller-owned. @internal */
|
|
64
|
+
export interface MidnightWithdrawCollateralPreparationParams extends Omit<MidnightWithdrawCollateralParams, "market" | "onBehalf" | "receiver"> {
|
|
65
|
+
readonly accountAddress: Address;
|
|
66
|
+
readonly marketData: Market;
|
|
67
|
+
readonly positionData: AccrualPosition;
|
|
68
|
+
/** Defaults to `accountAddress`. */
|
|
69
|
+
readonly receiver?: Address;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Owns the snapshot-bound withdrawal checks in entity order: account, market, position binding,
|
|
73
|
+
* collateral index, `maxUint256` resolution to the snapshot balance, then the direct-call checks.
|
|
74
|
+
* Balance and health checks against the snapshot are left to the caller. @internal
|
|
75
|
+
*/
|
|
76
|
+
export declare const parseMidnightWithdrawCollateralPreparation: (params: MidnightWithdrawCollateralPreparationParams) => ParsedMidnightWithdrawCollateral;
|
|
63
77
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
|
-
import {
|
|
2
|
+
import { maxUint256 } from "viem";
|
|
3
|
+
import { parseMidnightAccount, parseMidnightAddress, parseMidnightCollateral, parseMidnightMarket, parseMidnightOwner, parseMidnightPositiveAmount, validateMidnightPositionBinding, } from "../../helpers/parseMidnight.js";
|
|
3
4
|
import { validateMidnightReceiver } from "../../helpers/validateMidnightReceiver.js";
|
|
4
5
|
import { encodeMidnightWithdrawCollateral } from "./encode.js";
|
|
5
6
|
import { snapshotMidnightMetadata } from "./parse.js";
|
|
@@ -67,3 +68,26 @@ export const parseMidnightWithdrawCollateral = (params) => {
|
|
|
67
68
|
[parsedWithdrawCollateral]: true,
|
|
68
69
|
});
|
|
69
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* Owns the snapshot-bound withdrawal checks in entity order: account, market, position binding,
|
|
73
|
+
* collateral index, `maxUint256` resolution to the snapshot balance, then the direct-call checks.
|
|
74
|
+
* Balance and health checks against the snapshot are left to the caller. @internal
|
|
75
|
+
*/
|
|
76
|
+
export const parseMidnightWithdrawCollateralPreparation = (params) => {
|
|
77
|
+
const onBehalf = parseMidnightAccount("accountAddress", params.accountAddress);
|
|
78
|
+
const market = parseMidnightMarket(params.marketData, params.chainId);
|
|
79
|
+
// Bind the supplied snapshot before interpreting its collateral balances.
|
|
80
|
+
validateMidnightPositionBinding(params);
|
|
81
|
+
const collateral = parseMidnightCollateral(market, params.collateralIndex ?? 0n);
|
|
82
|
+
const available = params.positionData.collateral[Number(collateral.index)] ?? 0n;
|
|
83
|
+
const action = parseMidnightWithdrawCollateral({
|
|
84
|
+
chainId: params.chainId,
|
|
85
|
+
market: market.struct,
|
|
86
|
+
assets: params.assets === maxUint256 ? available : params.assets,
|
|
87
|
+
onBehalf,
|
|
88
|
+
receiver: params.receiver ?? onBehalf,
|
|
89
|
+
collateralIndex: collateral.index,
|
|
90
|
+
metadata: params.metadata,
|
|
91
|
+
});
|
|
92
|
+
return action;
|
|
93
|
+
};
|
|
@@ -4,7 +4,8 @@ import { type Address, type Hex } from "viem";
|
|
|
4
4
|
* Computes the CREATE2 address of `owner`'s `BlueBuyCallback` for `salt`, as deployed or
|
|
5
5
|
* returned by the chain's `midnightBlueBuyCallbackFactory.createBlueBuyCallback(owner, salt)`.
|
|
6
6
|
*
|
|
7
|
-
* Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`.
|
|
7
|
+
* Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`. It is the
|
|
8
|
+
* Midnight-qualified name of midnight-sdk's `getBlueBuyCallbackAddress`.
|
|
8
9
|
*
|
|
9
10
|
* @param params.chainId - Chain whose `midnightBlueBuyCallbackFactory`, `midnight` and `blue` are used.
|
|
10
11
|
* @param params.owner - Callback owner, the maker.
|
|
@@ -28,7 +29,7 @@ import { type Address, type Hex } from "viem";
|
|
|
28
29
|
* // `callbackFor(maker)` returns the maker's BlueBuyCallback address, deployed or not.
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
|
-
export declare const getMidnightBlueBuyCallbackAddress: (
|
|
32
|
+
export declare const getMidnightBlueBuyCallbackAddress: (params: {
|
|
32
33
|
readonly chainId: number;
|
|
33
34
|
readonly owner: Address;
|
|
34
35
|
readonly salt: Hex;
|