@morpho-org/morpho-sdk 6.6.0 → 7.1.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v6-to-v7.md +297 -0
- package/README.md +26 -12
- package/lib/cjs/abis.d.ts +2 -2
- package/lib/cjs/abis.js +7 -2
- package/lib/cjs/actions/bundles/common.d.ts +9 -5
- package/lib/cjs/actions/bundles/common.js +22 -13
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
- package/lib/cjs/actions/midnight/authorization.js +3 -2
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
- package/lib/cjs/actions/midnight/index.d.ts +3 -3
- package/lib/cjs/actions/midnight/index.js +3 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
- package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
- package/lib/cjs/actions/midnight/takeLend.js +111 -54
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
- package/lib/cjs/actions/midnight/types.d.ts +7 -26
- package/lib/cjs/actions/midnight/types.js +0 -13
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/midnight/index.js +0 -1
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/entities/index.d.ts +6 -6
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/midnight/midnight.d.ts +585 -108
- package/lib/cjs/entities/midnight/midnight.js +984 -509
- package/lib/cjs/entities/midnight/types.d.ts +142 -60
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +3 -2
- package/lib/cjs/entities/vaultV1/vaultV1.js +32 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +37 -12
- package/lib/cjs/entities/vaultV2/vaultV2.js +68 -41
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +5 -3
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +9 -3
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +10 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/callback.d.ts +54 -0
- package/lib/cjs/helpers/callback.js +73 -0
- package/lib/cjs/helpers/constant.d.ts +2 -0
- package/lib/cjs/helpers/constant.js +3 -1
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +6 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/cjs/helpers/validate.d.ts +43 -2
- package/lib/cjs/helpers/validate.js +60 -3
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +3 -2
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/midnight/types.d.ts +1 -1
- package/lib/cjs/types/action.d.ts +219 -90
- package/lib/cjs/types/action.js +103 -20
- package/lib/cjs/types/error.d.ts +126 -40
- package/lib/cjs/types/error.js +154 -49
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/esm/abis.d.ts +2 -2
- package/lib/esm/abis.js +2 -2
- package/lib/esm/actions/bundles/common.d.ts +9 -5
- package/lib/esm/actions/bundles/common.js +22 -13
- package/lib/esm/actions/midnight/authorization.d.ts +3 -2
- package/lib/esm/actions/midnight/authorization.js +3 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
- package/lib/esm/actions/midnight/index.d.ts +3 -3
- package/lib/esm/actions/midnight/index.js +3 -3
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
- package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/esm/actions/midnight/takeBorrow.js +98 -57
- package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
- package/lib/esm/actions/midnight/takeLend.js +114 -57
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
- package/lib/esm/actions/midnight/types.d.ts +7 -26
- package/lib/esm/actions/midnight/types.js +1 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/esm/actions/requirements/midnight/index.js +0 -1
- 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/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/index.d.ts +6 -6
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +585 -108
- package/lib/esm/entities/midnight/midnight.js +990 -515
- package/lib/esm/entities/midnight/types.d.ts +142 -60
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +3 -2
- package/lib/esm/entities/vaultV1/vaultV1.js +33 -35
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +37 -12
- package/lib/esm/entities/vaultV2/vaultV2.js +69 -42
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +5 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.js +9 -3
- 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/callback.d.ts +54 -0
- package/lib/esm/helpers/callback.js +68 -0
- package/lib/esm/helpers/constant.d.ts +2 -0
- package/lib/esm/helpers/constant.js +2 -0
- package/lib/esm/helpers/index.d.ts +3 -2
- package/lib/esm/helpers/index.js +3 -2
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/esm/helpers/validate.d.ts +43 -2
- package/lib/esm/helpers/validate.js +58 -2
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/esm/helpers/validateRequirementSpender.js +4 -5
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/midnight/types.d.ts +1 -1
- package/lib/esm/types/action.d.ts +219 -90
- package/lib/esm/types/action.js +103 -19
- package/lib/esm/types/error.d.ts +126 -40
- package/lib/esm/types/error.js +135 -38
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +10 -10
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
- package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/esm/actions/midnight/cancelOffer.js +0 -69
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AccrualPosition, type Market, type MidnightFetchParams } from "@morpho-org/midnight-sdk";
|
|
2
2
|
import { type Address, type Hex } from "viem";
|
|
3
3
|
import type { MorphoClientType } from "../../types/client.js";
|
|
4
|
-
import { type
|
|
5
|
-
import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams } from "./types.js";
|
|
4
|
+
import { type MidnightCancelAndMakeAction, type MidnightGroupCancellation, type MidnightRedeemAction, type MidnightRepayWithdrawCollateralAction, type MidnightSupplyCollateralAction, type MidnightSupplyCollateralTakeBorrowAction, type MidnightTakeBorrowAction, type MidnightTakeLendAction, type MidnightTakeRepayWithdrawCollateralAction, type MidnightTakeWithdrawAction } from "../../types/index.js";
|
|
5
|
+
import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams, TakeRepayWithdrawCollateralParams, TakeWithdrawParams } from "./types.js";
|
|
6
6
|
/**
|
|
7
7
|
* Entity methods exposed by `client.morpho.midnight(chainId)`.
|
|
8
8
|
*
|
|
@@ -13,6 +13,7 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
|
+
* import { Time } from "@morpho-org/morpho-ts";
|
|
16
17
|
* import { maxUint256 } from "viem";
|
|
17
18
|
*
|
|
18
19
|
* const midnight = client.morpho.midnight(8453);
|
|
@@ -20,16 +21,16 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
|
|
|
20
21
|
* const output = midnight.takeLend({
|
|
21
22
|
* accountAddress: lender,
|
|
22
23
|
* marketData,
|
|
23
|
-
* assets: 1_000_000n,
|
|
24
|
-
* minUnits: 900_000n,
|
|
24
|
+
* target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
|
|
25
25
|
* takeableOffers: quote.data.takeableOffers,
|
|
26
|
-
*
|
|
26
|
+
* maxContinuousFee: maxUint256,
|
|
27
|
+
* deadline: Time.timestamp() + 600n,
|
|
27
28
|
* });
|
|
28
29
|
* const requirements = await output.getRequirements();
|
|
29
30
|
* const tx = output.buildTx();
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
|
-
export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "supplyCollateralTakeBorrow" | "supplyCollateral" | "makeLend" | "makeBorrow" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "
|
|
33
|
+
export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "takeWithdraw" | "supplyCollateralTakeBorrow" | "takeRepayWithdrawCollateral" | "supplyCollateral" | "makeLend" | "makeBorrow" | "supplyBlueMakeLend" | "makeWithdraw" | "makeRepay" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "cancelOffers">;
|
|
33
34
|
/**
|
|
34
35
|
* Entity facade for Midnight fixed-rate action flows.
|
|
35
36
|
*
|
|
@@ -100,123 +101,299 @@ export declare class MorphoMidnight {
|
|
|
100
101
|
/**
|
|
101
102
|
* Builds and validates a maker offer tree against the Midnight mempool API.
|
|
102
103
|
*
|
|
103
|
-
* @param params - Maker account,
|
|
104
|
+
* @param params - Maker account, PriceRatifierV1 or RateRatifierV1 tree input, and optional API validation controls.
|
|
104
105
|
* @param params.accountAddress - Maker expected on every offer.
|
|
105
|
-
* @param params.offers -
|
|
106
|
+
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
106
107
|
* @param params.validation - Optional Midnight mempool API request controls.
|
|
107
|
-
* @returns Prepared tree
|
|
108
|
+
* @returns Prepared tree, groups, ratifier, and encoded payload used by maker flows.
|
|
108
109
|
* @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
|
|
109
110
|
* @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
|
|
111
|
+
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
|
|
110
112
|
* @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
|
|
113
|
+
* @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
|
|
114
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
|
|
111
115
|
* @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
|
|
112
116
|
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
113
|
-
* @throws {
|
|
117
|
+
* @throws {UnknownAddressError} when the chain has no deployment for the tree's V1 ratifier.
|
|
118
|
+
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
114
119
|
* @example
|
|
115
120
|
* ```ts
|
|
116
121
|
* const offersData = await midnight.getOffersData({
|
|
117
122
|
* accountAddress: maker,
|
|
118
|
-
* offers: [offer],
|
|
123
|
+
* offers: { type: "rateV1", entries: [{ offer, rate }] },
|
|
119
124
|
* });
|
|
120
125
|
* ```
|
|
121
126
|
*/
|
|
122
127
|
getOffersData(params: GetOffersDataParams): Promise<OffersData>;
|
|
123
128
|
/**
|
|
124
|
-
* Prepares a
|
|
129
|
+
* Prepares a `MidnightBundlesV2` buy that lends into borrow-side offers for `accountAddress`.
|
|
125
130
|
*
|
|
126
|
-
* @param params - Lender, market snapshot, target
|
|
127
|
-
* @param params.accountAddress - Lender
|
|
131
|
+
* @param params - Lender, market snapshot, buy target, offers, fee cap, deadline, and optional referral fee.
|
|
132
|
+
* @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
|
|
128
133
|
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
129
|
-
* @param params.
|
|
130
|
-
* @param params.
|
|
134
|
+
* @param params.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`.
|
|
135
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
136
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
137
|
+
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
138
|
+
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
139
|
+
* required for the full pulled amount.
|
|
131
140
|
* @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
|
|
141
|
+
* @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
|
|
142
|
+
* onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
|
|
143
|
+
* is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
|
|
132
144
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
133
|
-
* @
|
|
145
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
|
|
146
|
+
* @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
147
|
+
* @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
|
|
134
148
|
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
149
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
150
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
151
|
+
* @throws {InputExceedsMaxError} when `target.assets`, `target.units`, `minUnits`, `maxBuyerAssets`
|
|
152
|
+
* or `maxContinuousFee` exceeds `uint256`, or `nativeAmount` exceeds the maximum
|
|
153
|
+
* wNative amount this call can pull.
|
|
135
154
|
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
136
|
-
* @throws {NonPositiveInputError} when `
|
|
137
|
-
* @throws {NegativeInputError} when `
|
|
155
|
+
* @throws {NonPositiveInputError} when the target amount, `minUnits` or `maxBuyerAssets` is not positive.
|
|
156
|
+
* @throws {NegativeInputError} when `maxContinuousFee`, `referralFeePct` or `nativeAmount` is negative.
|
|
157
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
158
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
|
|
159
|
+
* @throws {UnboundedMidnightTakeInputError} when `target.units` or
|
|
160
|
+
* `target.maxBuyerAssets` is `maxUint256`.
|
|
161
|
+
* @throws {ExpiredDeadlineError} when `deadline` has expired.
|
|
162
|
+
* @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
|
|
138
163
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
139
164
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
140
165
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
166
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
167
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
168
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
|
|
141
169
|
* @example
|
|
142
170
|
* ```ts
|
|
143
171
|
* const output = midnight.takeLend({
|
|
144
172
|
* accountAddress: lender,
|
|
145
173
|
* marketData,
|
|
146
|
-
* assets: 1_000_000n,
|
|
147
|
-
* minUnits: 900_000n,
|
|
174
|
+
* target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
|
|
148
175
|
* takeableOffers: quote.data.takeableOffers,
|
|
149
|
-
*
|
|
176
|
+
* maxContinuousFee: maxUint256,
|
|
177
|
+
* deadline: Time.timestamp() + 600n,
|
|
150
178
|
* });
|
|
151
179
|
* ```
|
|
152
180
|
*/
|
|
153
181
|
takeLend(params: TakeLendParams): MidnightActionOutput<MidnightTakeLendAction>;
|
|
154
182
|
/**
|
|
155
|
-
* Prepares a
|
|
183
|
+
* Prepares a `MidnightBundlesV2` sell that borrows from lend-side offers for `accountAddress`.
|
|
184
|
+
*
|
|
185
|
+
* The bundle first withdraws as much of the sender's existing credit as the target and market
|
|
186
|
+
* liquidity allow, then fills the rest from offers.
|
|
156
187
|
*
|
|
157
|
-
* @param params - Borrower, market snapshot, target
|
|
158
|
-
* @param params.accountAddress - Borrower
|
|
188
|
+
* @param params - Borrower, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
|
|
189
|
+
* @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
|
|
159
190
|
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
160
|
-
* @param params.
|
|
161
|
-
* @param params.
|
|
191
|
+
* @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
|
|
192
|
+
* @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
|
|
162
193
|
* @param params.takeableOffers - Lend-side offers returned by the Midnight API.
|
|
163
|
-
* @param params.deadline -
|
|
164
|
-
* @
|
|
194
|
+
* @param params.deadline - Bounded bundle execution deadline timestamp.
|
|
195
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
|
|
196
|
+
* @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
197
|
+
* @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
|
|
165
198
|
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
199
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
200
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
201
|
+
* @throws {InputExceedsMaxError} when `target.assets`, `target.maxUnits`, `target.units`
|
|
202
|
+
* or `target.minSellerAssets` exceeds `uint256`.
|
|
166
203
|
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
167
|
-
* @throws {NonPositiveInputError} when `
|
|
168
|
-
* @throws {NegativeInputError} when `
|
|
204
|
+
* @throws {NonPositiveInputError} when the target amount, `maxUnits` or `minSellerAssets` is not positive.
|
|
205
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
206
|
+
* @throws {UnboundedMidnightTakeInputError} when `target.units` or
|
|
207
|
+
* `target.maxUnits` is `maxUint256`.
|
|
208
|
+
* @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
|
|
209
|
+
* @throws {ExpiredDeadlineError} when `deadline` has expired.
|
|
210
|
+
* @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
|
|
169
211
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
170
212
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
171
213
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
214
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
215
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
172
216
|
* @example
|
|
173
217
|
* ```ts
|
|
174
218
|
* const output = midnight.takeBorrow({
|
|
175
219
|
* accountAddress: borrower,
|
|
176
220
|
* marketData,
|
|
177
|
-
*
|
|
178
|
-
* maxUnits: 1_100_000n,
|
|
221
|
+
* target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
|
|
179
222
|
* takeableOffers: quote.data.takeableOffers,
|
|
180
|
-
* deadline:
|
|
223
|
+
* deadline: Time.timestamp() + 600n,
|
|
181
224
|
* });
|
|
182
225
|
* ```
|
|
183
226
|
*/
|
|
184
227
|
takeBorrow(params: TakeBorrowParams): MidnightActionOutput<MidnightTakeBorrowAction>;
|
|
185
228
|
/**
|
|
186
|
-
* Prepares
|
|
229
|
+
* Prepares a reduce-only `MidnightBundlesV2` sell that withdraws `accountAddress`'s credit.
|
|
187
230
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
231
|
+
* The bundle first redeems as much credit as the target and market liquidity allow, then sells
|
|
232
|
+
* the rest to lend-side offers. `reduceOnly` is always set, so it never opens debt. Use `redeem`
|
|
233
|
+
* for a direct redemption without offers.
|
|
234
|
+
*
|
|
235
|
+
* @param params - Lender, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
|
|
236
|
+
* @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
|
|
190
237
|
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
191
|
-
* @param params.
|
|
192
|
-
* @param params.
|
|
193
|
-
* @param params.loanAssets - Loan assets received by the borrower.
|
|
194
|
-
* @param params.maxUnits - Maximum debt units accepted.
|
|
238
|
+
* @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
|
|
239
|
+
* @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
|
|
195
240
|
* @param params.takeableOffers - Lend-side offers returned by the Midnight API.
|
|
196
241
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
197
|
-
* @
|
|
242
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
|
|
243
|
+
* @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
244
|
+
* @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
|
|
198
245
|
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
246
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
247
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
248
|
+
* @throws {InputExceedsMaxError} when `target.assets`, `target.maxUnits`, `target.units`
|
|
249
|
+
* or `target.minSellerAssets` exceeds `uint256`.
|
|
199
250
|
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
200
|
-
* @throws {NonPositiveInputError} when
|
|
201
|
-
*
|
|
202
|
-
* @throws {
|
|
251
|
+
* @throws {NonPositiveInputError} when the target amount, `maxUnits` or `minSellerAssets` is
|
|
252
|
+
* not positive.
|
|
253
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
254
|
+
* @throws {UnboundedMidnightTakeInputError} when `target.units` or `target.maxUnits` is `maxUint256`.
|
|
255
|
+
* @throws {ExpiredDeadlineError} when `deadline` has expired.
|
|
256
|
+
* @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
|
|
203
257
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
204
258
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
205
259
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
260
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
261
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* const output = midnight.takeWithdraw({
|
|
265
|
+
* accountAddress: lender,
|
|
266
|
+
* marketData,
|
|
267
|
+
* target: { type: "units", units: credit, minSellerAssets: 990_000n },
|
|
268
|
+
* takeableOffers: quote.data.takeableOffers,
|
|
269
|
+
* deadline: Time.timestamp() + 600n,
|
|
270
|
+
* });
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
takeWithdraw(params: TakeWithdrawParams): MidnightActionOutput<MidnightTakeWithdrawAction>;
|
|
274
|
+
/**
|
|
275
|
+
* Prepares one `MidnightBundlesV2` sell that supplies collateral and borrows from lend-side
|
|
276
|
+
* offers for `accountAddress`.
|
|
277
|
+
*
|
|
278
|
+
* Like `takeBorrow`, the sender's existing credit is withdrawn before offers are taken.
|
|
279
|
+
*
|
|
280
|
+
* @param params - Borrower, market snapshot, collateral supplies, sell target, offers, deadline, receiver, and optional referral fee.
|
|
281
|
+
* @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
|
|
282
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
283
|
+
* @param params.collateralSupplies - Collateral index and assets per supply; must not be empty.
|
|
284
|
+
* @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
|
|
285
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
286
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
287
|
+
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
288
|
+
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
289
|
+
* required for the full pulled amount.
|
|
290
|
+
* @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
|
|
291
|
+
* @param params.takeableOffers - Lend-side offers returned by the Midnight API.
|
|
292
|
+
* @param params.deadline - Bounded bundle execution deadline timestamp.
|
|
293
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
|
|
294
|
+
* @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
295
|
+
* @returns Lazy collateral approvals and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
|
|
296
|
+
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
297
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
298
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
299
|
+
* @throws {InputExceedsMaxError} when a `collateralSupplies[].assets` amount, `target.assets`,
|
|
300
|
+
* `target.maxUnits`, `target.units` or `target.minSellerAssets` exceeds `uint256`, or
|
|
301
|
+
* `nativeAmount` exceeds the maximum wNative collateral amount this call can pull.
|
|
302
|
+
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
303
|
+
* @throws {EmptyMidnightCollateralSuppliesError} when no collateral supply is provided.
|
|
304
|
+
* @throws {UnknownCollateralIndexError} when a collateral index is not configured.
|
|
305
|
+
* @throws {NonPositiveInputError} when a supply amount, the target amount, `maxUnits` or `minSellerAssets` is not positive.
|
|
306
|
+
* @throws {NegativeInputError} when `referralFeePct` or `nativeAmount` is negative.
|
|
307
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
308
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
|
|
309
|
+
* @throws {UnboundedMidnightTakeInputError} when `target.units` or
|
|
310
|
+
* `target.maxUnits` is `maxUint256`.
|
|
311
|
+
* @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
|
|
312
|
+
* @throws {ExpiredDeadlineError} when `deadline` has expired.
|
|
313
|
+
* @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
|
|
314
|
+
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
315
|
+
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
316
|
+
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
317
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
318
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
319
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below a collateral token's pulled assets.
|
|
206
320
|
* @example
|
|
207
321
|
* ```ts
|
|
208
322
|
* const output = midnight.supplyCollateralTakeBorrow({
|
|
209
323
|
* accountAddress: borrower,
|
|
210
324
|
* marketData,
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* maxUnits: 1_100_000n,
|
|
325
|
+
* collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
|
|
326
|
+
* target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
|
|
214
327
|
* takeableOffers: quote.data.takeableOffers,
|
|
215
|
-
* deadline:
|
|
328
|
+
* deadline: Time.timestamp() + 600n,
|
|
216
329
|
* });
|
|
217
330
|
* ```
|
|
218
331
|
*/
|
|
219
332
|
supplyCollateralTakeBorrow(params: SupplyCollateralTakeBorrowParams): MidnightActionOutput<MidnightSupplyCollateralTakeBorrowAction>;
|
|
333
|
+
/**
|
|
334
|
+
* Prepares a `MidnightBundlesV2` reduce-only buy that repays `accountAddress`'s debt by taking
|
|
335
|
+
* borrow-side offers, optionally repays the remainder directly, then withdraws collateral.
|
|
336
|
+
*
|
|
337
|
+
* `reduceOnly` is always set, so the buy never opens a lender position.
|
|
338
|
+
*
|
|
339
|
+
* @param params - Borrower, market snapshot, buy target, offers, repay fallback, withdrawals, fee cap, deadline and optional referral fee.
|
|
340
|
+
* @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
|
|
341
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
342
|
+
* @param params.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`; `units: maxUint256` targets the sender's whole debt, capped by `maxBuyerAssets` (must be finite; `units: maxUint256` already selects the whole debt).
|
|
343
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
344
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
345
|
+
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
346
|
+
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
347
|
+
* required for the full pulled amount.
|
|
348
|
+
* @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
|
|
349
|
+
* @param params.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
|
|
350
|
+
* @param params.collateralWithdrawals - Optional collateral withdrawals; `maxUint256` assets withdraws the whole balance.
|
|
351
|
+
* @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`.
|
|
352
|
+
* @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
|
|
353
|
+
* onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
|
|
354
|
+
* is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
|
|
355
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
356
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
|
|
357
|
+
* @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
358
|
+
* @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
|
|
359
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
360
|
+
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
361
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
362
|
+
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
363
|
+
* @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or a
|
|
364
|
+
* withdrawal amount is not positive.
|
|
365
|
+
* @throws {NegativeInputError} when `maxContinuousFee`, `referralFeePct` or `nativeAmount` is negative.
|
|
366
|
+
* @throws {InputExceedsMaxError} when `target.assets` or `target.maxBuyerAssets` is at
|
|
367
|
+
* least `maxUint256`, or a `collateralWithdrawals[].assets` amount, `target.units`,
|
|
368
|
+
* `minUnits`, `maxBuyerAssets` or `maxContinuousFee` exceeds `uint256`, or
|
|
369
|
+
* `nativeAmount` exceeds the maximum wNative amount this call can pull, including zero for a
|
|
370
|
+
* withdraw-only call.
|
|
371
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
372
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
|
|
373
|
+
* @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
|
|
374
|
+
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
375
|
+
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
376
|
+
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
377
|
+
* @throws {ExpiredDeadlineError} when `deadline` has expired.
|
|
378
|
+
* @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
|
|
379
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
380
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
381
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const output = midnight.takeRepayWithdrawCollateral({
|
|
385
|
+
* accountAddress: borrower,
|
|
386
|
+
* marketData,
|
|
387
|
+
* target: { type: "units", units: 1_000_000n, maxBuyerAssets: 990_000n },
|
|
388
|
+
* takeableOffers: quote.data.takeableOffers,
|
|
389
|
+
* repayEnabled: true,
|
|
390
|
+
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
391
|
+
* maxContinuousFee: maxUint256,
|
|
392
|
+
* deadline: Time.timestamp() + 600n,
|
|
393
|
+
* });
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
takeRepayWithdrawCollateral(params: TakeRepayWithdrawCollateralParams): MidnightActionOutput<MidnightTakeRepayWithdrawCollateralAction>;
|
|
220
397
|
/**
|
|
221
398
|
* Prepares a direct collateral supply using a caller-provided market snapshot.
|
|
222
399
|
*
|
|
@@ -232,6 +409,7 @@ export declare class MorphoMidnight {
|
|
|
232
409
|
* @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
|
|
233
410
|
* @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
|
|
234
411
|
* @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
|
|
412
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled collateral assets.
|
|
235
413
|
* @example
|
|
236
414
|
* ```ts
|
|
237
415
|
* const output = midnight.supplyCollateral({
|
|
@@ -243,30 +421,49 @@ export declare class MorphoMidnight {
|
|
|
243
421
|
*/
|
|
244
422
|
supplyCollateral(params: SupplyCollateralParams): MidnightActionOutput<MidnightSupplyCollateralAction>;
|
|
245
423
|
/**
|
|
246
|
-
*
|
|
424
|
+
* Prepares an atomic lend-offer publication or repost through `MidnightBundlesV2`.
|
|
247
425
|
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
426
|
+
* One transaction cancels `cancellations` under their consumption ceilings, activates the
|
|
427
|
+
* PriceRatifierV1 or RateRatifierV1 root, and publishes its payload. Pass no cancellations
|
|
428
|
+
* for a new publication. Calls the Midnight mempool validation API while preparing the tree.
|
|
250
429
|
*
|
|
251
|
-
* @param params - Maker,
|
|
252
|
-
* @param params.accountAddress - Maker expected on every offer.
|
|
253
|
-
* @param params.offers -
|
|
430
|
+
* @param params - Maker, lend-side offers, loan reserve, cancellations, and deadline.
|
|
431
|
+
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
432
|
+
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
433
|
+
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
434
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
254
435
|
* @param params.validation - Optional Midnight mempool API request controls.
|
|
255
436
|
* @param params.loanToken - Loan token shared by every offer market.
|
|
256
|
-
* @param params.loanAssets - New loan reserve assigned to the
|
|
257
|
-
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups
|
|
258
|
-
* @returns Prepared group metadata, lazy requirements, and a synchronous
|
|
437
|
+
* @param params.loanAssets - New loan reserve assigned to the published groups.
|
|
438
|
+
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
|
|
439
|
+
* @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
|
|
259
440
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
260
|
-
* @throws {
|
|
441
|
+
* @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
|
|
442
|
+
* @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
|
|
443
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
|
|
261
444
|
* @throws {NonPositiveInputError} when `loanAssets` is non-positive.
|
|
262
|
-
* @throws {NegativeInputError} when `reservedLoanAssets` is negative.
|
|
445
|
+
* @throws {NegativeInputError} when `reservedLoanAssets` or a `maxConsumed` ceiling is negative.
|
|
446
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
447
|
+
* @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128` or `deadline` exceeds `uint256`.
|
|
448
|
+
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
|
|
449
|
+
* @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
|
|
450
|
+
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
451
|
+
* @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
|
|
452
|
+
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
453
|
+
* @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
|
|
454
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
|
|
263
455
|
* @throws {MidnightOfferSideMismatchError} when an offer is not lend-side.
|
|
264
456
|
* @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
|
|
457
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
458
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
459
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `loanAssets + reservedLoanAssets`.
|
|
265
460
|
* @example
|
|
266
461
|
* ```ts
|
|
267
462
|
* const output = await midnight.makeLend({
|
|
268
463
|
* accountAddress: maker,
|
|
269
|
-
* offers: [offer],
|
|
464
|
+
* offers: { type: "rateV1", entries: [{ offer, rate }] },
|
|
465
|
+
* cancellations: [{ group: previousGroup, maxConsumed: 0n }],
|
|
466
|
+
* deadline: maxUint256,
|
|
270
467
|
* loanToken,
|
|
271
468
|
* loanAssets: 1_000_000n,
|
|
272
469
|
* });
|
|
@@ -274,51 +471,290 @@ export declare class MorphoMidnight {
|
|
|
274
471
|
*/
|
|
275
472
|
makeLend(params: MakeLendParams): Promise<MakeOffersOutput>;
|
|
276
473
|
/**
|
|
277
|
-
*
|
|
474
|
+
* Prepares an atomic borrow-offer publication or repost through `MidnightBundlesV2`.
|
|
278
475
|
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
476
|
+
* One transaction cancels `cancellations` under their consumption ceilings, activates the
|
|
477
|
+
* PriceRatifierV1 or RateRatifierV1 root, and publishes its payload. Pass no cancellations for
|
|
478
|
+
* a new publication. Calls the Midnight mempool validation API while preparing the tree.
|
|
479
|
+
*
|
|
480
|
+
* @param params - Maker, borrow-side offers, cancellations, and deadline.
|
|
481
|
+
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
482
|
+
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
483
|
+
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
484
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
282
485
|
* @param params.validation - Optional Midnight mempool API request controls.
|
|
283
|
-
* @returns Prepared group metadata, lazy
|
|
284
|
-
* @throws {ChainIdMismatchError} when the client
|
|
486
|
+
* @returns Prepared group metadata, lazy authorization requirements, and a synchronous transaction builder.
|
|
487
|
+
* @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
|
|
488
|
+
* @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
|
|
489
|
+
* @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
|
|
490
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
|
|
491
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
|
|
492
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
493
|
+
* @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128` or `deadline` exceeds `uint256`.
|
|
494
|
+
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
|
|
495
|
+
* @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
|
|
285
496
|
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
497
|
+
* @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
|
|
498
|
+
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
499
|
+
* @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
|
|
500
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
|
|
286
501
|
* @throws {MidnightOfferSideMismatchError} when an offer is not borrow-side.
|
|
502
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
503
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
287
504
|
* @example
|
|
288
505
|
* ```ts
|
|
289
506
|
* const output = await midnight.makeBorrow({
|
|
290
507
|
* accountAddress: maker,
|
|
291
|
-
* offers: [offer],
|
|
508
|
+
* offers: { type: "rateV1", entries: [{ offer, rate }] },
|
|
509
|
+
* deadline: maxUint256,
|
|
292
510
|
* });
|
|
293
511
|
* ```
|
|
294
512
|
*/
|
|
295
513
|
makeBorrow(params: MakeOffersParams): Promise<MakeOffersOutput>;
|
|
296
514
|
/**
|
|
297
|
-
* Prepares
|
|
515
|
+
* Prepares lend-side offers for publication.
|
|
516
|
+
*/
|
|
517
|
+
private prepareLendOffers;
|
|
518
|
+
/**
|
|
519
|
+
* Prepares an atomic Blue-funded lend-offer publication or repost through `MidnightBundlesV2`.
|
|
298
520
|
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
521
|
+
* One transaction cancels `cancellations` under their consumption ceilings, pulls `assetsToPark`
|
|
522
|
+
* from the maker and supplies them to `blueMarket` on Morpho Blue for the maker's
|
|
523
|
+
* `BlueBuyCallback` (created if missing), activates the PriceRatifierV1 or RateRatifierV1 root,
|
|
524
|
+
* and publishes its payload. When an offer is taken, the callback withdraws the bought assets
|
|
525
|
+
* from Blue and pays Midnight, so the maker needs no loan-token approval to Midnight.
|
|
526
|
+
*
|
|
527
|
+
* Every offer must set `callback` to the maker's derived `BlueBuyCallback` and `callbackData`
|
|
528
|
+
* to `abi.encode(blueMarket)`. The contract does not check supply share-price slippage, so
|
|
529
|
+
* `blueMarket` must be protected against supply-share-price inflation; this method rejects
|
|
530
|
+
* Blue markets with no supply shares and parked amounts that would mint zero shares. Calls the
|
|
531
|
+
* Midnight mempool validation API while preparing the tree. Computes the callback's CREATE2 address from the chain's
|
|
532
|
+
* `midnightBlueBuyCallbackFactory`, `accountAddress` and `callbackSalt`, and fetches the Morpho Blue market,
|
|
533
|
+
* accruing interest to the current time before previewing parked shares (markets whose
|
|
534
|
+
* IRM the SDK cannot accrue are previewed on their last-updated state).
|
|
535
|
+
*
|
|
536
|
+
* @param params - Maker, lend-side offers, Blue market, parked assets, cancellations, and deadline.
|
|
537
|
+
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
538
|
+
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
539
|
+
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
540
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
302
541
|
* @param params.validation - Optional Midnight mempool API request controls.
|
|
303
|
-
* @param params.
|
|
304
|
-
* @param params.
|
|
305
|
-
* @param params.
|
|
306
|
-
*
|
|
307
|
-
*
|
|
542
|
+
* @param params.blueMarket - Morpho Blue market the parked assets are supplied to.
|
|
543
|
+
* @param params.assetsToPark - Loan assets supplied to `blueMarket` for the maker's callback.
|
|
544
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
545
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
546
|
+
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
547
|
+
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
548
|
+
* required for the full pulled amount.
|
|
549
|
+
* @param params.callbackSalt - Salt selecting the maker's callback; the same salt reuses the same callback.
|
|
550
|
+
* @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
|
|
308
551
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
309
|
-
* @throws {
|
|
310
|
-
* @throws {NonPositiveInputError} when `
|
|
311
|
-
* @throws {NegativeInputError} when `
|
|
312
|
-
* @throws {
|
|
552
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2`, `midnightBlueBuyCallbackFactory`, `midnight`, `blue` or V1 ratifier deployment.
|
|
553
|
+
* @throws {NonPositiveInputError} when `assetsToPark` is non-positive.
|
|
554
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling or `nativeAmount` is negative.
|
|
555
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
556
|
+
* @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128`, `deadline` exceeds
|
|
557
|
+
* `uint256`, or `nativeAmount` exceeds `assetsToPark` when `blueMarket.loanToken` is wNative.
|
|
558
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
559
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `blueMarket.loanToken` is not wNative.
|
|
560
|
+
* @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
|
|
561
|
+
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
|
|
562
|
+
* @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
|
|
563
|
+
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
564
|
+
* @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
|
|
565
|
+
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
566
|
+
* @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
|
|
567
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
|
|
568
|
+
* @throws {MidnightOfferSideMismatchError} when an offer is not lend-side.
|
|
569
|
+
* @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
|
|
570
|
+
* @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer's loan token differs from `blueMarket`'s.
|
|
571
|
+
* @throws {MidnightOfferCallbackMismatchError} when an offer does not use the maker's derived callback.
|
|
572
|
+
* @throws {MidnightOfferCallbackDataMismatchError} when an offer's callback data is not `abi.encode(blueMarket)`.
|
|
573
|
+
* @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
|
|
574
|
+
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price.
|
|
575
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
576
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
577
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `assetsToPark`.
|
|
578
|
+
* @example
|
|
579
|
+
* ```ts
|
|
580
|
+
* const callback = getMidnightBlueBuyCallbackAddress({ chainId, owner: maker, salt: callbackSalt });
|
|
581
|
+
* const callbackData = getMidnightBlueBuyCallbackData(blueMarket);
|
|
582
|
+
* const output = await midnight.supplyBlueMakeLend({
|
|
583
|
+
* accountAddress: maker,
|
|
584
|
+
* offers: {
|
|
585
|
+
* type: "rateV1",
|
|
586
|
+
* entries: [{ offer: { ...offer, callback, callbackData }, rate }],
|
|
587
|
+
* },
|
|
588
|
+
* deadline: maxUint256,
|
|
589
|
+
* blueMarket,
|
|
590
|
+
* assetsToPark: 1_000_000n,
|
|
591
|
+
* callbackSalt,
|
|
592
|
+
* });
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
supplyBlueMakeLend(params: SupplyBlueMakeLendParams): Promise<MakeOffersOutput>;
|
|
596
|
+
/**
|
|
597
|
+
* Prepares borrow-side offers for publication.
|
|
598
|
+
*/
|
|
599
|
+
private prepareBorrowOffers;
|
|
600
|
+
/**
|
|
601
|
+
* Publishes reduce-only sell offers for a lend limit exit through MidnightBundlesV2.
|
|
602
|
+
*
|
|
603
|
+
* Shares the borrow-side publication and requirement handling of {@link MorphoMidnight.makeBorrow}.
|
|
604
|
+
* No tokens are pulled during publication and no token approval is required.
|
|
605
|
+
* Execution waits for a taker; publication does not close the position or withdraw collateral.
|
|
606
|
+
* Every offer must already have `buy = false` and `reduceOnly = true`.
|
|
607
|
+
* The supplied tree, group caps and prices are preserved; no separate root signature is needed.
|
|
608
|
+
*
|
|
609
|
+
* @param params - Maker, reduce-only offers, optional cancellations, and deadline.
|
|
610
|
+
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
611
|
+
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
612
|
+
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
613
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
614
|
+
* @param params.validation - Optional Midnight mempool API request controls.
|
|
615
|
+
* @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
|
|
616
|
+
* @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
|
|
617
|
+
* @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
|
|
618
|
+
* @throws {MidnightOfferSideMismatchError} when an offer is not a sell offer (`buy = false`).
|
|
619
|
+
* @throws {MidnightOfferNotReduceOnlyError} when any offer can increase a position.
|
|
620
|
+
* @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
|
|
621
|
+
* @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
|
|
622
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
|
|
623
|
+
* @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
|
|
624
|
+
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
625
|
+
* @throws {UnknownAddressError} when the chain has no V1 ratifier or `midnightBundlesV2` deployment.
|
|
626
|
+
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
627
|
+
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
|
|
628
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
629
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
|
|
630
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
|
|
631
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
632
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
633
|
+
* @example
|
|
634
|
+
* ```ts
|
|
635
|
+
* const output = await midnight.makeWithdraw({
|
|
636
|
+
* accountAddress: maker,
|
|
637
|
+
* offers: { type: "priceV1", entries: [{ offer: reduceOnlySellOffer }] },
|
|
638
|
+
* deadline: maxUint256,
|
|
639
|
+
* });
|
|
640
|
+
* const requirements = await output.getRequirements();
|
|
641
|
+
* const tx = output.buildTx();
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
makeWithdraw(params: MakeOffersParams): Promise<MakeOffersOutput>;
|
|
645
|
+
/**
|
|
646
|
+
* Publishes reduce-only buy offers for a borrow limit exit through MidnightBundlesV2.
|
|
647
|
+
*
|
|
648
|
+
* Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
|
|
649
|
+
* Loan assets are pulled by Midnight when the offers fill, not during publication.
|
|
650
|
+
* The loan reserve uses the same approval sizing as `makeLend`.
|
|
651
|
+
* Execution waits for a taker; publication does not close the position or withdraw collateral.
|
|
652
|
+
* Every offer must already have `buy = true` and `reduceOnly = true`.
|
|
653
|
+
* The supplied tree, group caps and prices are preserved; no separate root signature is needed.
|
|
654
|
+
*
|
|
655
|
+
* @param params - Maker, reduce-only offers, optional cancellations, loan reserve, and deadline.
|
|
656
|
+
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
657
|
+
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
658
|
+
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
659
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
660
|
+
* @param params.validation - Optional Midnight mempool API request controls.
|
|
661
|
+
* @param params.loanToken - Loan token shared by every offer market.
|
|
662
|
+
* @param params.loanAssets - New loan reserve assigned to the published groups.
|
|
663
|
+
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
|
|
664
|
+
* @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
|
|
665
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
666
|
+
* @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
|
|
667
|
+
* @throws {MidnightOfferSideMismatchError} when an offer is not a buy offer (`buy = true`).
|
|
668
|
+
* @throws {MidnightOfferNotReduceOnlyError} when any offer can increase a position.
|
|
669
|
+
* @throws {NonPositiveInputError} when `loanAssets` or `deadline` is not positive.
|
|
670
|
+
* @throws {NegativeInputError} when `reservedLoanAssets` or a `maxConsumed` ceiling is negative.
|
|
671
|
+
* @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
|
|
672
|
+
* @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
|
|
673
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
|
|
674
|
+
* @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
|
|
675
|
+
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
676
|
+
* @throws {UnknownAddressError} when the chain has no V1 ratifier or `midnightBundlesV2` deployment.
|
|
677
|
+
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
678
|
+
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
|
|
679
|
+
* @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
|
|
680
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
|
|
681
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
682
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
683
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `loanAssets + reservedLoanAssets`.
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* const output = await midnight.makeRepay({
|
|
687
|
+
* accountAddress: maker,
|
|
688
|
+
* offers: { type: "priceV1", entries: [{ offer: reduceOnlyBuyOffer }] },
|
|
689
|
+
* loanToken,
|
|
690
|
+
* loanAssets: 1_000_000n,
|
|
691
|
+
* deadline: maxUint256,
|
|
692
|
+
* });
|
|
693
|
+
* const requirements = await output.getRequirements();
|
|
694
|
+
* const tx = output.buildTx();
|
|
695
|
+
* ```
|
|
696
|
+
*/
|
|
697
|
+
makeRepay(params: MakeLendParams): Promise<MakeOffersOutput>;
|
|
698
|
+
/**
|
|
699
|
+
* Prepares an atomic borrow-offer publication or repost through `MidnightBundlesV2`,
|
|
700
|
+
* requiring collateral before activation.
|
|
701
|
+
*
|
|
702
|
+
* One transaction cancels `cancellations` under their consumption ceilings, pulls and supplies
|
|
703
|
+
* required `collateral`, activates the PriceRatifierV1 or RateRatifierV1 root, and publishes its
|
|
704
|
+
* payload. Pass no cancellations for a new publication. Calls the Midnight mempool validation
|
|
705
|
+
* API while preparing the tree.
|
|
706
|
+
*
|
|
707
|
+
* @param params - Maker, borrow-side offers, required collateral, cancellations, and deadline.
|
|
708
|
+
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
709
|
+
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
710
|
+
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
711
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
712
|
+
* @param params.validation - Optional Midnight mempool API request controls.
|
|
713
|
+
* @param params.collateral - Required market and collateral supplies; every offer must target that market.
|
|
714
|
+
* @param params.collateral.market - Midnight market receiving the collateral; every offer must target it.
|
|
715
|
+
* @param params.collateral.supplies - Collateral index and assets per supply; must not be empty.
|
|
716
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
717
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
718
|
+
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
719
|
+
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
720
|
+
* required for the full pulled amount.
|
|
721
|
+
* @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
|
|
722
|
+
* @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
|
|
723
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
|
|
724
|
+
* @throws {UnknownCollateralIndexError} when a collateral index is not configured.
|
|
725
|
+
* @throws {NonPositiveInputError} when a collateral supply amount is non-positive.
|
|
726
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling or `nativeAmount` is negative.
|
|
727
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
728
|
+
* @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128`, `deadline` or a
|
|
729
|
+
* collateral supply amount exceeds `uint256`, or `nativeAmount` exceeds the maximum wNative
|
|
730
|
+
* collateral amount this call can pull.
|
|
731
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
732
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
|
|
733
|
+
* @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
|
|
734
|
+
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
|
|
735
|
+
* @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
|
|
736
|
+
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
737
|
+
* @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
|
|
738
|
+
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
739
|
+
* @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
|
|
740
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
|
|
313
741
|
* @throws {MidnightOfferSideMismatchError} when an offer is not borrow-side.
|
|
314
|
-
* @throws {
|
|
742
|
+
* @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
|
|
743
|
+
* @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
|
|
744
|
+
* @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
|
|
745
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
746
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
747
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below a collateral token's pulled assets.
|
|
315
748
|
* @example
|
|
316
749
|
* ```ts
|
|
317
750
|
* const output = await midnight.supplyCollateralMakeBorrow({
|
|
318
751
|
* accountAddress: maker,
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
752
|
+
* offers: { type: "rateV1", entries: [{ offer, rate }] },
|
|
753
|
+
* collateral: {
|
|
754
|
+
* market: marketData.params,
|
|
755
|
+
* supplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
|
|
756
|
+
* },
|
|
757
|
+
* deadline: maxUint256,
|
|
322
758
|
* });
|
|
323
759
|
* ```
|
|
324
760
|
*/
|
|
@@ -350,53 +786,94 @@ export declare class MorphoMidnight {
|
|
|
350
786
|
*/
|
|
351
787
|
redeem(params: RedeemParams): MidnightActionOutput<MidnightRedeemAction>;
|
|
352
788
|
/**
|
|
353
|
-
* Prepares a
|
|
789
|
+
* Prepares a direct `MidnightBundlesV2` repayment, collateral withdrawal, or both, for `accountAddress`.
|
|
354
790
|
*
|
|
355
|
-
* @param params - Account, market snapshot, repay
|
|
356
|
-
* @param params.accountAddress - Position owner
|
|
791
|
+
* @param params - Account, market snapshot, `repay` mode, collateral withdrawals, optional collateral receiver, and deadline.
|
|
792
|
+
* @param params.accountAddress - Position owner and transaction sender.
|
|
357
793
|
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
358
|
-
* @param params.
|
|
359
|
-
* @param params.
|
|
360
|
-
*
|
|
794
|
+
* @param params.repay - `{ type: "assets", assets }` (`0n` to only withdraw) or `{ type: "full", maxBuyerAssets }`; a loan-token approval to `MidnightBundlesV2` is required when the allowance is below the pulled amount — unlimited (`maxUint256`) by default, or `approvalAmount` when passed to `getRequirements()` — and any unused part is refunded.
|
|
795
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
796
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
797
|
+
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
798
|
+
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
799
|
+
* required for the full pulled amount.
|
|
800
|
+
* @param params.collateralWithdrawals - Optional withdrawals; `assets: maxUint256` withdraws the full balance.
|
|
801
|
+
* @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`.
|
|
361
802
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
362
803
|
* @returns Lazy loan approval/authorization requirements and a synchronous transaction builder.
|
|
363
804
|
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
364
805
|
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
365
|
-
* @throws {NegativeInputError} when
|
|
366
|
-
* @throws {NonPositiveInputError} when
|
|
367
|
-
* @throws {
|
|
806
|
+
* @throws {NegativeInputError} when `repay.assets` or `nativeAmount` is negative.
|
|
807
|
+
* @throws {NonPositiveInputError} when nothing is repaid or withdrawn, a withdrawal amount is zero, `repay.maxBuyerAssets` is zero, or `deadline` is not positive.
|
|
808
|
+
* @throws {InputExceedsMaxError} when `repay.assets` or `repay.maxBuyerAssets` is at least
|
|
809
|
+
* `maxUint256`, a withdrawal amount or `deadline` exceeds uint256, or `nativeAmount` exceeds
|
|
810
|
+
* the maximum wNative amount this call can pull, including zero for a withdraw-only call.
|
|
811
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
812
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
|
|
813
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
814
|
+
* @throws {UnknownCollateralIndexError} when a withdrawal selects an unconfigured collateral.
|
|
815
|
+
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
|
|
368
816
|
* @example
|
|
369
817
|
* ```ts
|
|
818
|
+
* // Close the position: repay all debt, withdraw all collateral.
|
|
370
819
|
* const output = midnight.repayWithdrawCollateral({
|
|
371
820
|
* accountAddress: borrower,
|
|
372
821
|
* marketData,
|
|
373
|
-
*
|
|
374
|
-
*
|
|
822
|
+
* repay: { type: "full", maxBuyerAssets: 1_010_000n },
|
|
823
|
+
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
375
824
|
* deadline: maxUint256,
|
|
376
825
|
* });
|
|
377
826
|
* ```
|
|
378
827
|
*/
|
|
379
828
|
repayWithdrawCollateral(params: RepayWithdrawCollateralParams): MidnightActionOutput<MidnightRepayWithdrawCollateralAction>;
|
|
380
829
|
/**
|
|
381
|
-
* Prepares
|
|
830
|
+
* Prepares guarded cancellation of several maker offer groups through `MidnightBundlesV2`.
|
|
382
831
|
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
* @
|
|
832
|
+
* The transaction reverts as a whole when any group's consumption exceeds its
|
|
833
|
+
* `maxConsumed` ceiling, so fills landing before execution never leave a partial cancel.
|
|
834
|
+
*
|
|
835
|
+
* @param params - Maker account, groups with consumption ceilings, and deadline.
|
|
836
|
+
* @param params.accountAddress - Maker that must send the transaction. It is used only to check
|
|
837
|
+
* the maker's Midnight authorization of `MidnightBundlesV2`; the bundle cancels the groups of
|
|
838
|
+
* `msg.sender`. A transaction sent from another account that has also authorized
|
|
839
|
+
* `MidnightBundlesV2` does not revert: it cancels that account's groups and leaves the maker's
|
|
840
|
+
* offers fillable.
|
|
841
|
+
* @param params.cancellations - Offer groups and the largest consumption accepted for each.
|
|
842
|
+
* To cancel unconditionally, set `maxConsumed` to `maxUint128`; the contract treats
|
|
843
|
+
* `type(uint128).max` as no limit.
|
|
844
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
845
|
+
* @returns Lazy Midnight authorization requirement for `MidnightBundlesV2` and a synchronous transaction builder.
|
|
387
846
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
847
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
848
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
849
|
+
* @throws {EmptyMidnightGroupCancellationsError} when no groups are provided.
|
|
850
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
|
|
851
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
852
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
|
|
853
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
|
|
388
854
|
* @example
|
|
389
855
|
* ```ts
|
|
390
|
-
*
|
|
391
|
-
*
|
|
856
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
857
|
+
* import { createPublicClient, http, maxUint256, type Address, type Hex } from "viem";
|
|
858
|
+
* import { base } from "viem/chains";
|
|
859
|
+
*
|
|
860
|
+
* declare const maker: Address;
|
|
861
|
+
* declare const group: Hex;
|
|
862
|
+
* const client = createPublicClient({ chain: base, transport: http() }).extend(
|
|
863
|
+
* morphoViemExtension(),
|
|
864
|
+
* );
|
|
865
|
+
* const midnight = client.morpho.midnight(base.id);
|
|
866
|
+
* const output = midnight.cancelOffers({
|
|
392
867
|
* accountAddress: maker,
|
|
868
|
+
* cancellations: [{ group, maxConsumed: 0n }],
|
|
869
|
+
* deadline: maxUint256,
|
|
393
870
|
* });
|
|
394
871
|
* ```
|
|
395
872
|
*/
|
|
396
|
-
|
|
397
|
-
readonly group: Hex;
|
|
873
|
+
cancelOffers(params: {
|
|
398
874
|
readonly accountAddress: Address;
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
875
|
+
readonly cancellations: readonly MidnightGroupCancellation[];
|
|
876
|
+
readonly deadline: bigint;
|
|
877
|
+
}): MidnightActionOutput<MidnightCancelAndMakeAction>;
|
|
878
|
+
private getBundlesV2AuthorizationRequirements;
|
|
402
879
|
}
|