@morpho-org/morpho-sdk 10.4.0 → 10.5.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/lib/cjs/actions/blue/common.js +12 -3
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
- package/lib/cjs/actions/midnight/takeBorrow.js +14 -8
- package/lib/cjs/actions/midnight/takeLend.js +15 -9
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
- package/lib/cjs/actions/midnight/takeWithdraw.js +14 -8
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +3 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +106 -103
- package/lib/cjs/entities/midnight/midnight.js +120 -101
- package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +0 -1
- package/lib/cjs/helpers/constant.d.ts +7 -0
- package/lib/cjs/helpers/constant.js +8 -1
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/validate.d.ts +25 -1
- package/lib/cjs/helpers/validate.js +25 -1
- package/lib/cjs/transactionPlan/assemble.d.ts +24 -0
- package/lib/cjs/transactionPlan/assemble.js +25 -0
- package/lib/cjs/transactionPlan/blue/borrow.js +14 -64
- package/lib/cjs/transactionPlan/blue/refinance.js +9 -11
- package/lib/cjs/transactionPlan/blue/repay.js +10 -24
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +49 -45
- package/lib/cjs/transactionPlan/blue/stored.d.ts +26 -0
- package/lib/cjs/transactionPlan/blue/stored.js +87 -0
- package/lib/cjs/transactionPlan/blue/supply.js +7 -22
- package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/blue/supplyCollateral.js +10 -15
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +14 -64
- package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -3
- package/lib/cjs/transactionPlan/blue/withdraw.js +67 -79
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +31 -30
- package/lib/cjs/transactionPlan/deposit.js +4 -7
- package/lib/cjs/transactionPlan/intent.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeBorrow.js +1 -1
- package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeLend.js +1 -1
- package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/makeRepay.js +1 -1
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
- package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +6 -2
- package/lib/cjs/transactionPlan/midnight/takeBorrow.js +10 -4
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +1 -1
- package/lib/cjs/transactionPlan/permit.d.ts +15 -2
- package/lib/cjs/transactionPlan/permit.js +26 -68
- package/lib/cjs/transactionPlan/plan.d.ts +51 -1
- package/lib/cjs/transactionPlan/plan.js +56 -13
- package/lib/cjs/transactionPlan/redeem.js +4 -7
- package/lib/cjs/transactionPlan/types.d.ts +4 -3
- package/lib/cjs/transactionPlan/vaultBinding.d.ts +29 -0
- package/lib/cjs/transactionPlan/vaultBinding.js +69 -0
- package/lib/cjs/transactionPlan/vaultRequirements.d.ts +20 -0
- package/lib/cjs/transactionPlan/vaultRequirements.js +37 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -13
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +10 -41
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +6 -18
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -12
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +4 -7
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +12 -42
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +10 -41
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -13
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -1
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -13
- package/lib/cjs/transactionPlan/withdraw.js +4 -7
- package/lib/cjs/types/error.d.ts +27 -1
- package/lib/cjs/types/error.js +32 -3
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/blue/common.js +13 -4
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
- package/lib/esm/actions/midnight/takeBorrow.js +14 -8
- package/lib/esm/actions/midnight/takeLend.js +15 -9
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
- package/lib/esm/actions/midnight/takeWithdraw.js +14 -8
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/midnight/midnight.d.ts +106 -103
- package/lib/esm/entities/midnight/midnight.js +120 -101
- package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +0 -1
- package/lib/esm/helpers/constant.d.ts +7 -0
- package/lib/esm/helpers/constant.js +7 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +25 -1
- package/lib/esm/helpers/validate.js +25 -2
- package/lib/esm/transactionPlan/assemble.d.ts +24 -0
- package/lib/esm/transactionPlan/assemble.js +21 -0
- package/lib/esm/transactionPlan/blue/borrow.js +15 -65
- package/lib/esm/transactionPlan/blue/refinance.js +10 -12
- package/lib/esm/transactionPlan/blue/repay.js +11 -25
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +50 -46
- package/lib/esm/transactionPlan/blue/stored.d.ts +26 -0
- package/lib/esm/transactionPlan/blue/stored.js +80 -0
- package/lib/esm/transactionPlan/blue/supply.js +7 -22
- package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/blue/supplyCollateral.js +10 -15
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +15 -65
- package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -3
- package/lib/esm/transactionPlan/blue/withdraw.js +70 -82
- package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
- package/lib/esm/transactionPlan/blue/withdrawCollateral.js +32 -31
- package/lib/esm/transactionPlan/deposit.js +5 -8
- package/lib/esm/transactionPlan/intent.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeBorrow.js +1 -1
- package/lib/esm/transactionPlan/midnight/makeLend.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeLend.js +1 -1
- package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/makeRepay.js +1 -1
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
- package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +6 -2
- package/lib/esm/transactionPlan/midnight/takeBorrow.js +11 -5
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/midnight/takeWithdraw.js +1 -1
- package/lib/esm/transactionPlan/permit.d.ts +15 -2
- package/lib/esm/transactionPlan/permit.js +25 -68
- package/lib/esm/transactionPlan/plan.d.ts +51 -1
- package/lib/esm/transactionPlan/plan.js +55 -13
- package/lib/esm/transactionPlan/redeem.js +5 -8
- package/lib/esm/transactionPlan/types.d.ts +4 -3
- package/lib/esm/transactionPlan/vaultBinding.d.ts +29 -0
- package/lib/esm/transactionPlan/vaultBinding.js +65 -0
- package/lib/esm/transactionPlan/vaultRequirements.d.ts +20 -0
- package/lib/esm/transactionPlan/vaultRequirements.js +34 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -14
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +12 -43
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +9 -21
- package/lib/esm/transactionPlan/vaultv1/redeem.js +2 -13
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +5 -8
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +15 -45
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +12 -43
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/redeem.js +3 -14
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -1
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +3 -14
- package/lib/esm/transactionPlan/withdraw.js +5 -8
- package/lib/esm/types/error.d.ts +27 -1
- package/lib/esm/types/error.js +30 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +3 -3
|
@@ -15,6 +15,7 @@ const getMidnightAuthorizationRequirement_js_1 = require("../../actions/requirem
|
|
|
15
15
|
const index_js_1 = require("../../helpers/index.js");
|
|
16
16
|
const metadata_js_1 = require("../../helpers/metadata.js");
|
|
17
17
|
const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
|
|
18
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
18
19
|
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
19
20
|
const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
|
|
20
21
|
const validateMidnightTakeFeasibility_js_1 = require("../../helpers/validateMidnightTakeFeasibility.js");
|
|
@@ -166,22 +167,22 @@ class MorphoMidnight {
|
|
|
166
167
|
* On an assets target, sell offers whose tick is out of range or whose buyer price is zero or
|
|
167
168
|
* above one are dropped from the transaction because one of them would revert the whole bundle.
|
|
168
169
|
*
|
|
169
|
-
* @param
|
|
170
|
-
* @param
|
|
171
|
-
* @param
|
|
172
|
-
* @param
|
|
173
|
-
* @param
|
|
170
|
+
* @param raw - Lender, market snapshot, buy target, offers, fee cap, deadline, and optional referral fee.
|
|
171
|
+
* @param raw.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
|
|
172
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
173
|
+
* @param raw.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`.
|
|
174
|
+
* @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
174
175
|
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
175
176
|
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
176
177
|
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
177
178
|
* required for the full pulled amount.
|
|
178
|
-
* @param
|
|
179
|
-
* @param
|
|
179
|
+
* @param raw.takeableOffers - Borrow-side offers returned by the Midnight API.
|
|
180
|
+
* @param raw.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
|
|
180
181
|
* onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
|
|
181
182
|
* is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
|
|
182
|
-
* @param
|
|
183
|
-
* @param
|
|
184
|
-
* @param
|
|
183
|
+
* @param raw.deadline - Bundle execution deadline timestamp.
|
|
184
|
+
* @param raw.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
|
|
185
|
+
* @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
185
186
|
* @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
|
|
186
187
|
* @throws {ChainIdMismatchError} when client or market data targets another chain, or from
|
|
187
188
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
@@ -229,7 +230,7 @@ class MorphoMidnight {
|
|
|
229
230
|
* marketData,
|
|
230
231
|
* target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
|
|
231
232
|
* takeableOffers: quote.data.takeableOffers,
|
|
232
|
-
* maxContinuousFee:
|
|
233
|
+
* maxContinuousFee: BigInt(marketData.continuousFee),
|
|
233
234
|
* now: (await client.getBlock()).timestamp,
|
|
234
235
|
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
235
236
|
* });
|
|
@@ -289,26 +290,26 @@ class MorphoMidnight {
|
|
|
289
290
|
* settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
|
|
290
291
|
* revert the whole bundle.
|
|
291
292
|
*
|
|
292
|
-
* @param
|
|
293
|
-
* @param
|
|
294
|
-
* @param
|
|
295
|
-
* @param
|
|
293
|
+
* @param raw - Borrower, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
|
|
294
|
+
* @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
|
|
295
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
296
|
+
* @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
|
|
296
297
|
* `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
|
|
297
298
|
* does not see transactions mined or prices moved since, so two transactions built from one
|
|
298
299
|
* snapshot can together end inside the buffer. Midnight still rejects any position above
|
|
299
300
|
* LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
|
|
300
|
-
* @param
|
|
301
|
+
* @param raw.collateralPrices - Values from `price()` on each
|
|
301
302
|
* `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
|
|
302
303
|
* scaled by `ORACLE_PRICE_SCALE`. A price is required for every held or supplied collateral
|
|
303
304
|
* index, because debt after a borrow is always positive.
|
|
304
|
-
* @param
|
|
305
|
-
* @param
|
|
305
|
+
* @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
|
|
306
|
+
* @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
|
|
306
307
|
* Midnight protocol and market token contracts are rejected.
|
|
307
|
-
* @param
|
|
308
|
-
* @param
|
|
309
|
-
* @param
|
|
308
|
+
* @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
|
|
309
|
+
* @param raw.deadline - Bounded bundle execution deadline timestamp.
|
|
310
|
+
* @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
|
|
310
311
|
* proceeds; on an assets target it is added on top of `target.assets`.
|
|
311
|
-
* @param
|
|
312
|
+
* @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
312
313
|
* @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
|
|
313
314
|
* @throws {ChainIdMismatchError} when client or market data targets another chain, or from
|
|
314
315
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
@@ -349,6 +350,9 @@ class MorphoMidnight {
|
|
|
349
350
|
* withdrawal.
|
|
350
351
|
* @throws {MidnightTakeTargetUnreachableError} when the live offers cannot hold the target, or
|
|
351
352
|
* its bounds cannot hold at any fill.
|
|
353
|
+
* @throws {MidnightBorrowTooCloseToMaturityError} when `now` is not past maturity and `deadline` is less
|
|
354
|
+
* than `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` (2 hours) before it, even when credit covers the
|
|
355
|
+
* target; use `takeWithdraw` to sell credit only.
|
|
352
356
|
* @example
|
|
353
357
|
* ```ts
|
|
354
358
|
* import { blueOracleAbi } from "@morpho-org/morpho-sdk/abis";
|
|
@@ -401,12 +405,13 @@ class MorphoMidnight {
|
|
|
401
405
|
throw new index_js_2.BorrowExceedsSafeLtvError(requestedUnits, blue_sdk_1.MathLib.zeroFloorSub(maxSafeDebt, params.positionData.debt));
|
|
402
406
|
}
|
|
403
407
|
}
|
|
408
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
404
409
|
const takeableOffers = (0, validateMidnightTakeFeasibility_js_1.validateMidnightTakeFeasibility)({
|
|
405
410
|
side: "sell",
|
|
406
411
|
takeableOffers: parsed.takeableOffers,
|
|
407
412
|
accountAddress: accountAddress,
|
|
408
413
|
marketData: params.marketData,
|
|
409
|
-
now
|
|
414
|
+
now,
|
|
410
415
|
deadline: parsed.deadline,
|
|
411
416
|
referralFeePct: parsed.referralFeePct,
|
|
412
417
|
// Credit is withdrawn first, up to the market's withdrawable liquidity.
|
|
@@ -415,6 +420,11 @@ class MorphoMidnight {
|
|
|
415
420
|
target: parsed.target,
|
|
416
421
|
increasesDebt: true,
|
|
417
422
|
});
|
|
423
|
+
(0, validate_js_1.validateMidnightBorrowMaturity)({
|
|
424
|
+
marketData: params.marketData,
|
|
425
|
+
now,
|
|
426
|
+
deadline: parsed.deadline,
|
|
427
|
+
});
|
|
418
428
|
if (takeableOffers !== parsed.takeableOffers) {
|
|
419
429
|
tx = (0, encode_js_1.encodeMidnightTakeBorrow)(parsed, takeableOffers.map((offer) => parsed.takeableOffers.indexOf(offer)));
|
|
420
430
|
}
|
|
@@ -434,17 +444,17 @@ class MorphoMidnight {
|
|
|
434
444
|
* settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
|
|
435
445
|
* revert the whole bundle.
|
|
436
446
|
*
|
|
437
|
-
* @param
|
|
438
|
-
* @param
|
|
439
|
-
* @param
|
|
440
|
-
* @param
|
|
441
|
-
* @param
|
|
447
|
+
* @param raw - Lender, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
|
|
448
|
+
* @param raw.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
|
|
449
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
450
|
+
* @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
|
|
451
|
+
* @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
|
|
442
452
|
* Midnight protocol and market token contracts are rejected.
|
|
443
|
-
* @param
|
|
444
|
-
* @param
|
|
445
|
-
* @param
|
|
453
|
+
* @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
|
|
454
|
+
* @param raw.deadline - Bundle execution deadline timestamp.
|
|
455
|
+
* @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
|
|
446
456
|
* proceeds; on an assets target it is added on top of `target.assets`.
|
|
447
|
-
* @param
|
|
457
|
+
* @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
448
458
|
* @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
|
|
449
459
|
* @throws {ChainIdMismatchError} when client or market data targets another chain, or from
|
|
450
460
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
@@ -531,32 +541,32 @@ class MorphoMidnight {
|
|
|
531
541
|
* settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
|
|
532
542
|
* revert the whole bundle.
|
|
533
543
|
*
|
|
534
|
-
* @param
|
|
535
|
-
* @param
|
|
536
|
-
* @param
|
|
537
|
-
* @param
|
|
544
|
+
* @param raw - Borrower, market snapshot, collateral supplies, sell target, offers, deadline, receiver, and optional referral fee.
|
|
545
|
+
* @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
|
|
546
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
547
|
+
* @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
|
|
538
548
|
* `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
|
|
539
549
|
* does not see transactions mined or prices moved since, so two transactions built from one
|
|
540
550
|
* snapshot can together end inside the buffer. Midnight still rejects any position above
|
|
541
551
|
* LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
|
|
542
|
-
* @param
|
|
552
|
+
* @param raw.collateralPrices - Values from `price()` on each
|
|
543
553
|
* `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
|
|
544
554
|
* scaled by `ORACLE_PRICE_SCALE`. A price is required for every held or supplied collateral
|
|
545
555
|
* index, because debt after a borrow is always positive.
|
|
546
|
-
* @param
|
|
547
|
-
* @param
|
|
548
|
-
* @param
|
|
556
|
+
* @param raw.collateralSupplies - Collateral index and assets per supply; must not be empty.
|
|
557
|
+
* @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
|
|
558
|
+
* @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
549
559
|
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
550
560
|
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
551
561
|
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
552
562
|
* required for the full pulled amount.
|
|
553
|
-
* @param
|
|
563
|
+
* @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
|
|
554
564
|
* Midnight protocol and market token contracts are rejected.
|
|
555
|
-
* @param
|
|
556
|
-
* @param
|
|
557
|
-
* @param
|
|
565
|
+
* @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
|
|
566
|
+
* @param raw.deadline - Bounded bundle execution deadline timestamp.
|
|
567
|
+
* @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
|
|
558
568
|
* proceeds; on an assets target it is added on top of `target.assets`.
|
|
559
|
-
* @param
|
|
569
|
+
* @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
560
570
|
* @returns Lazy collateral approvals and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
|
|
561
571
|
* @throws {ChainIdMismatchError} when client or market data targets another chain, or from
|
|
562
572
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
@@ -603,6 +613,9 @@ class MorphoMidnight {
|
|
|
603
613
|
* withdrawal.
|
|
604
614
|
* @throws {MidnightTakeTargetUnreachableError} when the live offers cannot hold the target, or
|
|
605
615
|
* its bounds cannot hold at any fill.
|
|
616
|
+
* @throws {MidnightBorrowTooCloseToMaturityError} when `now` is not past maturity and `deadline` is less
|
|
617
|
+
* than `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` (2 hours) before it, even when credit covers the
|
|
618
|
+
* target; use `takeWithdraw` to sell credit only.
|
|
606
619
|
* @example
|
|
607
620
|
* ```ts
|
|
608
621
|
* const output = midnight.supplyCollateralTakeBorrow({
|
|
@@ -651,12 +664,13 @@ class MorphoMidnight {
|
|
|
651
664
|
throw new index_js_2.BorrowExceedsSafeLtvError(requestedUnits, blue_sdk_1.MathLib.zeroFloorSub(maxSafeDebt, params.positionData.debt));
|
|
652
665
|
}
|
|
653
666
|
}
|
|
667
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
654
668
|
const takeableOffers = (0, validateMidnightTakeFeasibility_js_1.validateMidnightTakeFeasibility)({
|
|
655
669
|
side: "sell",
|
|
656
670
|
takeableOffers: parsed.takeableOffers,
|
|
657
671
|
accountAddress: accountAddress,
|
|
658
672
|
marketData: params.marketData,
|
|
659
|
-
now
|
|
673
|
+
now,
|
|
660
674
|
deadline: parsed.deadline,
|
|
661
675
|
referralFeePct: parsed.referralFeePct,
|
|
662
676
|
// Credit is withdrawn first, up to the market's withdrawable liquidity.
|
|
@@ -665,6 +679,11 @@ class MorphoMidnight {
|
|
|
665
679
|
target: parsed.target,
|
|
666
680
|
increasesDebt: true,
|
|
667
681
|
});
|
|
682
|
+
(0, validate_js_1.validateMidnightBorrowMaturity)({
|
|
683
|
+
marketData: params.marketData,
|
|
684
|
+
now,
|
|
685
|
+
deadline: parsed.deadline,
|
|
686
|
+
});
|
|
668
687
|
if (takeableOffers !== parsed.takeableOffers) {
|
|
669
688
|
tx = (0, encode_js_1.encodeMidnightSupplyCollateralTakeBorrow)(parsed, takeableOffers.map((offer) => parsed.takeableOffers.indexOf(offer)));
|
|
670
689
|
}
|
|
@@ -699,37 +718,37 @@ class MorphoMidnight {
|
|
|
699
718
|
* On an assets target, sell offers whose tick is out of range or whose buyer price is zero or
|
|
700
719
|
* above one are dropped from the transaction because one of them would revert the whole bundle.
|
|
701
720
|
*
|
|
702
|
-
* @param
|
|
703
|
-
* @param
|
|
704
|
-
* @param
|
|
705
|
-
* @param
|
|
721
|
+
* @param raw - Borrower, market snapshot, buy target, offers, repay fallback, withdrawals, fee cap, deadline and optional referral fee.
|
|
722
|
+
* @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
|
|
723
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
724
|
+
* @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
|
|
706
725
|
* `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
|
|
707
726
|
* does not see transactions mined or prices moved since, so two transactions built from one
|
|
708
727
|
* snapshot can together end inside the buffer. Midnight still rejects any position above
|
|
709
728
|
* LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
|
|
710
|
-
* @param
|
|
729
|
+
* @param raw.collateralPrices - Values from `price()` on each
|
|
711
730
|
* `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
|
|
712
731
|
* scaled by `ORACLE_PRICE_SCALE`. An empty array is safe only when
|
|
713
732
|
* `collateralWithdrawals` is empty or the conservative post-operation debt is zero: a units
|
|
714
733
|
* `target` covering `positionData.debt`, or an assets target whose `minUnits` covers it.
|
|
715
|
-
* @param
|
|
716
|
-
* @param
|
|
734
|
+
* @param raw.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).
|
|
735
|
+
* @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
717
736
|
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
718
737
|
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
719
738
|
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
720
739
|
* required for the full pulled amount.
|
|
721
|
-
* @param
|
|
722
|
-
* @param
|
|
723
|
-
* @param
|
|
724
|
-
* @param
|
|
740
|
+
* @param raw.takeableOffers - Borrow-side offers returned by the Midnight API.
|
|
741
|
+
* @param raw.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
|
|
742
|
+
* @param raw.collateralWithdrawals - Optional collateral withdrawals; `maxUint256` assets withdraws the whole balance.
|
|
743
|
+
* @param raw.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
|
|
725
744
|
* must be non-zero and not a Midnight protocol or market token contract when
|
|
726
745
|
* `collateralWithdrawals` is non-empty, and is unused otherwise.
|
|
727
|
-
* @param
|
|
746
|
+
* @param raw.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
|
|
728
747
|
* onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
|
|
729
748
|
* is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
|
|
730
|
-
* @param
|
|
731
|
-
* @param
|
|
732
|
-
* @param
|
|
749
|
+
* @param raw.deadline - Bundle execution deadline timestamp.
|
|
750
|
+
* @param raw.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
|
|
751
|
+
* @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
|
|
733
752
|
* @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
|
|
734
753
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
735
754
|
* @throws {ChainIdMismatchError} when client or market data targets another chain, or from
|
|
@@ -793,7 +812,7 @@ class MorphoMidnight {
|
|
|
793
812
|
* takeableOffers: quote.data.takeableOffers,
|
|
794
813
|
* repayEnabled: true,
|
|
795
814
|
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
796
|
-
* maxContinuousFee:
|
|
815
|
+
* maxContinuousFee: BigInt(marketData.continuousFee),
|
|
797
816
|
* now: (await client.getBlock()).timestamp,
|
|
798
817
|
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
799
818
|
* });
|
|
@@ -893,18 +912,18 @@ class MorphoMidnight {
|
|
|
893
912
|
* Uses the supplied position snapshot to resolve maxUint256 and check collateral health.
|
|
894
913
|
* No requirements or RPC reads are needed. The signing account must be accountAddress.
|
|
895
914
|
*
|
|
896
|
-
* @param
|
|
897
|
-
* @param
|
|
898
|
-
* @param
|
|
899
|
-
* @param
|
|
900
|
-
* @param
|
|
915
|
+
* @param raw - Market, owner-bound position, collateral prices and withdrawal amount.
|
|
916
|
+
* @param raw.accountAddress - Collateral owner. This account must send the transaction.
|
|
917
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
918
|
+
* @param raw.positionData - Owner-bound position snapshot returned by getPositionData.
|
|
919
|
+
* @param raw.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
|
|
901
920
|
* ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
|
|
902
|
-
* @param
|
|
921
|
+
* @param raw.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
|
|
903
922
|
* market's collateral parameters, which Midnight sorts by token address, not the order they were
|
|
904
923
|
* listed in when the market was built; check marketData.getCollateralByIndex(index).token.
|
|
905
|
-
* @param
|
|
924
|
+
* @param raw.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
|
|
906
925
|
* the selected collateral from positionData before building the transaction.
|
|
907
|
-
* @param
|
|
926
|
+
* @param raw.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
|
|
908
927
|
* @returns Lazy handles for a direct Midnight withdrawal.
|
|
909
928
|
* @throws {ChainIdMismatchError} when the client or market targets another chain.
|
|
910
929
|
* @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
|
|
@@ -973,15 +992,15 @@ class MorphoMidnight {
|
|
|
973
992
|
* Duplicates are rejected, unlike bundle flows which sum them.
|
|
974
993
|
* No requirements or RPC reads are needed. The signing account must be accountAddress.
|
|
975
994
|
*
|
|
976
|
-
* @param
|
|
977
|
-
* @param
|
|
978
|
-
* @param
|
|
979
|
-
* @param
|
|
980
|
-
* @param
|
|
995
|
+
* @param raw - Market, owner-bound position, collateral prices and withdrawal amount.
|
|
996
|
+
* @param raw.accountAddress - Collateral owner. This account must send the transaction.
|
|
997
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
998
|
+
* @param raw.positionData - Owner-bound position snapshot returned by getPositionData.
|
|
999
|
+
* @param raw.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
|
|
981
1000
|
* ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
|
|
982
|
-
* @param
|
|
1001
|
+
* @param raw.collateralWithdrawals - Nonempty ordered withdrawals, one per index.
|
|
983
1002
|
* maxUint256 resolves that index's full snapshot balance.
|
|
984
|
-
* @param
|
|
1003
|
+
* @param raw.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
|
|
985
1004
|
* @returns Lazy handles for a direct Midnight withdrawal.
|
|
986
1005
|
* @throws {ChainIdMismatchError} when the client or market targets another chain.
|
|
987
1006
|
* @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
|
|
@@ -1051,18 +1070,18 @@ class MorphoMidnight {
|
|
|
1051
1070
|
/**
|
|
1052
1071
|
* Prepares a direct collateral supply using a caller-provided market snapshot.
|
|
1053
1072
|
*
|
|
1054
|
-
* @param
|
|
1073
|
+
* @param raw.accountAddress - Account receiving the supplied collateral position. It must send
|
|
1055
1074
|
* the transaction: Midnight pulls the collateral from `msg.sender` and only lets the position owner
|
|
1056
1075
|
* or its operators supply for it, and the approval requirements are resolved for this account.
|
|
1057
|
-
* @param
|
|
1058
|
-
* @param
|
|
1059
|
-
* @param
|
|
1076
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
1077
|
+
* @param raw.collateralAssets - Collateral assets supplied in this transaction.
|
|
1078
|
+
* @param raw.reservedCollateralAssets - Existing collateral reserved by other open maker groups.
|
|
1060
1079
|
* Only raises the approval requirement so those groups keep their allowance; the transaction
|
|
1061
1080
|
* transfers only `collateralAssets`.
|
|
1062
|
-
* @param
|
|
1081
|
+
* @param raw.collateralIndex - Optional collateral index; defaults to `0n`. Indexes follow the
|
|
1063
1082
|
* market's collateral parameters, which Midnight sorts by token address, not the order they were
|
|
1064
1083
|
* listed in when the market was built; check `marketData.getCollateralByIndex(index).token`.
|
|
1065
|
-
* @param
|
|
1084
|
+
* @param raw.now - Optional reference timestamp in seconds; used for metadata only when the
|
|
1066
1085
|
* client sets `metadata.timestamp: true`.
|
|
1067
1086
|
* @returns Lazy token-approval requirements and a synchronous transaction builder.
|
|
1068
1087
|
* @throws {NegativeInputError} when the resolved metadata timestamp is negative, or the reserve is negative.
|
|
@@ -1260,9 +1279,9 @@ class MorphoMidnight {
|
|
|
1260
1279
|
* Prepares ordered direct collateral supplies in one Midnight multicall.
|
|
1261
1280
|
* Pass one entry per index: duplicates are rejected, unlike bundle flows which sum them.
|
|
1262
1281
|
*
|
|
1263
|
-
* @param
|
|
1264
|
-
* @param
|
|
1265
|
-
* @param
|
|
1282
|
+
* @param raw.accountAddress - Sender and collateral beneficiary.
|
|
1283
|
+
* @param raw.marketData - Snapshot of the target market.
|
|
1284
|
+
* @param raw.collateralSupplies - Ordered supplies with optional reserved allowance amounts.
|
|
1266
1285
|
* @returns A lazy approval resolver and synchronous stateless transaction builder.
|
|
1267
1286
|
* @throws {ChainIdMismatchError} when the client or market targets another chain.
|
|
1268
1287
|
* @throws {MidnightMarketAddressMismatchError} when the deployment differs.
|
|
@@ -1911,14 +1930,14 @@ class MorphoMidnight {
|
|
|
1911
1930
|
/**
|
|
1912
1931
|
* Prepares redemption of accrued Midnight credit from a position snapshot.
|
|
1913
1932
|
*
|
|
1914
|
-
* @param
|
|
1915
|
-
* @param
|
|
1933
|
+
* @param raw - Position owner, accrued position, optional unit amount, and receiver.
|
|
1934
|
+
* @param raw.accountAddress - Position owner whose credit is redeemed. It must send the
|
|
1916
1935
|
* transaction (or authorize the sender): Midnight reverts `Unauthorized()` otherwise, which
|
|
1917
1936
|
* `getRequirements()` cannot detect because it does not know the sender.
|
|
1918
|
-
* @param
|
|
1919
|
-
* @param
|
|
1937
|
+
* @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`.
|
|
1938
|
+
* @param raw.receiver - Optional credit receiver; defaults to the position owner.
|
|
1920
1939
|
* Midnight protocol and market token contracts are rejected.
|
|
1921
|
-
* @param
|
|
1940
|
+
* @param raw.units - Optional credit units to redeem; defaults to the position face value.
|
|
1922
1941
|
* Credit is checked after applying the realized losses and continuous fees that Midnight
|
|
1923
1942
|
* charges before a withdrawal, accrued up to now. Fees keep accruing until maturity, so `units` close to the accrued
|
|
1924
1943
|
* credit can still revert when the transaction lands later. The default face value does not
|
|
@@ -1967,30 +1986,30 @@ class MorphoMidnight {
|
|
|
1967
1986
|
/**
|
|
1968
1987
|
* Prepares a direct `MidnightBundlesV2` repayment, collateral withdrawal, or both, for `accountAddress`.
|
|
1969
1988
|
*
|
|
1970
|
-
* @param
|
|
1971
|
-
* @param
|
|
1972
|
-
* @param
|
|
1973
|
-
* @param
|
|
1989
|
+
* @param raw - Account, market snapshot, `repay` mode, collateral withdrawals, optional collateral receiver, and deadline.
|
|
1990
|
+
* @param raw.accountAddress - Position owner and transaction sender.
|
|
1991
|
+
* @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
1992
|
+
* @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
|
|
1974
1993
|
* `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
|
|
1975
1994
|
* does not see transactions mined or prices moved since, so two transactions built from one
|
|
1976
1995
|
* snapshot can together end inside the buffer. Midnight still rejects any position above
|
|
1977
1996
|
* LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
|
|
1978
|
-
* @param
|
|
1997
|
+
* @param raw.collateralPrices - Values from `price()` on each
|
|
1979
1998
|
* `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
|
|
1980
1999
|
* scaled by `ORACLE_PRICE_SCALE`. An empty array is safe only when
|
|
1981
2000
|
* `collateralWithdrawals` is empty or the conservative post-operation debt is zero: a `full`
|
|
1982
2001
|
* repay, or `repay.assets` covering `positionData.debt`.
|
|
1983
|
-
* @param
|
|
1984
|
-
* @param
|
|
2002
|
+
* @param raw.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`, capped per token by `MAX_TOKEN_APPROVALS`), and any unused part is refunded.
|
|
2003
|
+
* @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
1985
2004
|
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
|
|
1986
2005
|
* the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
|
|
1987
2006
|
* stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
|
|
1988
2007
|
* required for the full pulled amount.
|
|
1989
|
-
* @param
|
|
1990
|
-
* @param
|
|
2008
|
+
* @param raw.collateralWithdrawals - Optional withdrawals; `assets: maxUint256` withdraws the full balance.
|
|
2009
|
+
* @param raw.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
|
|
1991
2010
|
* must be non-zero and not a Midnight protocol or market token contract when
|
|
1992
2011
|
* `collateralWithdrawals` is non-empty, and is unused otherwise.
|
|
1993
|
-
* @param
|
|
2012
|
+
* @param raw.deadline - Bundle execution deadline timestamp. Unlike taker builders,
|
|
1994
2013
|
* `maxUint256` is accepted because no offers are filled; the pull remains bounded by
|
|
1995
2014
|
* `repay.assets` or `repay.maxBuyerAssets`.
|
|
1996
2015
|
* @returns Lazy loan approval/authorization requirements and a synchronous transaction builder.
|
|
@@ -198,7 +198,6 @@ class MorphoVaultV1 {
|
|
|
198
198
|
if (amount <= 0n) {
|
|
199
199
|
throw new index_js_2.NonPositiveInputError("amount", amount);
|
|
200
200
|
}
|
|
201
|
-
// Reject values outside the ABI range before resolving any requirements.
|
|
202
201
|
const parsedAmount = (0, parse_js_1.parseUint256)("amount", amount);
|
|
203
202
|
const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
204
203
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
@@ -199,7 +199,6 @@ class MorphoVaultV2 {
|
|
|
199
199
|
if (amount <= 0n) {
|
|
200
200
|
throw new index_js_2.NonPositiveInputError("amount", amount);
|
|
201
201
|
}
|
|
202
|
-
// Reject values outside the ABI range before resolving any requirements.
|
|
203
202
|
const parsedAmount = (0, parse_js_1.parseUint256)("amount", amount);
|
|
204
203
|
const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
205
204
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
@@ -3,6 +3,13 @@ import { type Address } from "viem";
|
|
|
3
3
|
export declare const VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = 604800n;
|
|
4
4
|
/** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
|
|
5
5
|
export declare const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
|
|
6
|
+
/**
|
|
7
|
+
* Minimum time between a Midnight borrow's deadline and its market maturity, in seconds (2 hours).
|
|
8
|
+
* Debt still open at maturity becomes liquidatable, so entity and TransactionPlan borrows prepared at
|
|
9
|
+
* or before maturity that could execute closer to it are rejected. Credit covering the target at
|
|
10
|
+
* preparation does not exempt a borrow; sell credit only inside the window with `takeWithdraw`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY: bigint;
|
|
6
13
|
/**
|
|
7
14
|
* Matches MAX_SLIPPAGE_TOLERANCE, the SDK's other ceiling on a WAD share of user funds; higher fees are rejected as likely unit mistakes.
|
|
8
15
|
* @internal
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = void 0;
|
|
3
|
+
exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
@@ -8,6 +8,13 @@ const viem_1 = require("viem");
|
|
|
8
8
|
exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = 604800n;
|
|
9
9
|
/** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
|
|
10
10
|
exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
|
|
11
|
+
/**
|
|
12
|
+
* Minimum time between a Midnight borrow's deadline and its market maturity, in seconds (2 hours).
|
|
13
|
+
* Debt still open at maturity becomes liquidatable, so entity and TransactionPlan borrows prepared at
|
|
14
|
+
* or before maturity that could execute closer to it are rejected. Credit covering the target at
|
|
15
|
+
* preparation does not exempt a borrow; sell credit only inside the window with `takeWithdraw`.
|
|
16
|
+
*/
|
|
17
|
+
exports.MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY = morpho_ts_1.Time.s.from.h(2n);
|
|
11
18
|
/**
|
|
12
19
|
* Matches MAX_SLIPPAGE_TOLERANCE, the SDK's other ceiling on a WAD share of user funds; higher fees are rejected as likely unit mistakes.
|
|
13
20
|
* @internal
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
|
|
2
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
2
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
3
3
|
export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
|
|
4
4
|
export { addTransactionMetadata } from "./metadata.js";
|
|
5
5
|
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
|
package/lib/cjs/helpers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateVaultV2DeadShares = exports.validateVaultV1DeadShares = exports.validateBlueMarketDeadShares = exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
|
|
3
|
+
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateVaultV2DeadShares = exports.validateVaultV1DeadShares = exports.validateBlueMarketDeadShares = exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
|
|
4
4
|
var callback_js_1 = require("./callback.js");
|
|
5
5
|
Object.defineProperty(exports, "getMidnightBlueBuyCallbackAddress", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackAddress; } });
|
|
6
6
|
Object.defineProperty(exports, "getMidnightBlueBuyCallbackData", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackData; } });
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "MAX_ABSOLUTE_SHARE_PRICE", { enumerable: true, g
|
|
|
16
16
|
Object.defineProperty(exports, "MAX_REALLOCATION_PENALTY", { enumerable: true, get: function () { return constant_js_1.MAX_REALLOCATION_PENALTY; } });
|
|
17
17
|
Object.defineProperty(exports, "MAX_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return constant_js_1.MAX_SLIPPAGE_TOLERANCE; } });
|
|
18
18
|
Object.defineProperty(exports, "MAX_TOKEN_APPROVALS", { enumerable: true, get: function () { return constant_js_1.MAX_TOKEN_APPROVALS; } });
|
|
19
|
+
Object.defineProperty(exports, "MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY", { enumerable: true, get: function () { return constant_js_1.MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY; } });
|
|
19
20
|
Object.defineProperty(exports, "MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS", { enumerable: true, get: function () { return constant_js_1.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS; } });
|
|
20
21
|
Object.defineProperty(exports, "MIN_DEAD_SHARES", { enumerable: true, get: function () { return constant_js_1.MIN_DEAD_SHARES; } });
|
|
21
22
|
Object.defineProperty(exports, "MIN_VAULT_V2_DEAD_ASSETS", { enumerable: true, get: function () { return constant_js_1.MIN_VAULT_V2_DEAD_ASSETS; } });
|
|
@@ -235,6 +235,20 @@ export declare const validateMidnightBorrowHealth: (params: {
|
|
|
235
235
|
readonly debt: bigint;
|
|
236
236
|
readonly borrowUnits: bigint;
|
|
237
237
|
}) => void;
|
|
238
|
+
/**
|
|
239
|
+
* @internal Rejects a Midnight borrow that could execute less than
|
|
240
|
+
* `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` before the market's maturity, when unpaid debt becomes
|
|
241
|
+
* liquidatable. The sell is not reduce-only, so any units beyond the credit left at execution open
|
|
242
|
+
* debt; credit covering the target when the borrow is prepared does not exempt it. Once `now` is
|
|
243
|
+
* past maturity the protocol rejects new debt, so the check does not apply, matching the
|
|
244
|
+
* post-maturity credit cap in `validateMidnightTakeFeasibility`.
|
|
245
|
+
* Used by the entity and TransactionPlan borrow flows.
|
|
246
|
+
*/
|
|
247
|
+
export declare const validateMidnightBorrowMaturity: (params: {
|
|
248
|
+
readonly marketData: MidnightMarket;
|
|
249
|
+
readonly now: bigint;
|
|
250
|
+
readonly deadline: bigint;
|
|
251
|
+
}) => void;
|
|
238
252
|
/**
|
|
239
253
|
* @internal Rejects a Midnight collateral withdrawal whose post-operation debt exceeds the remaining
|
|
240
254
|
* collateral's capacity at LLTV minus `DEFAULT_LLTV_BUFFER`, with the same check and error as the
|
|
@@ -497,8 +511,18 @@ export declare const validateRepayShares: (params: {
|
|
|
497
511
|
repayShares: bigint;
|
|
498
512
|
marketId: MarketId;
|
|
499
513
|
}) => void;
|
|
514
|
+
/** Plain allocation fields shared by reallocation validation and stored withdrawal plans. @internal */
|
|
515
|
+
export type BlueReallocationInput = Omit<VaultV2BlueReallocation, "from"> & {
|
|
516
|
+
readonly from: {
|
|
517
|
+
readonly type: "market";
|
|
518
|
+
readonly adapter: Address;
|
|
519
|
+
readonly marketParams: Readonly<InputMarketParams>;
|
|
520
|
+
} | Extract<VaultV2BlueReallocation["from"], {
|
|
521
|
+
type: "idle";
|
|
522
|
+
}>;
|
|
523
|
+
};
|
|
500
524
|
/** @internal */
|
|
501
|
-
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<
|
|
525
|
+
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<BlueReallocationInput>, { targetMarketId, maxPenalty, }: {
|
|
502
526
|
readonly targetMarketId: MarketId;
|
|
503
527
|
readonly maxPenalty?: bigint;
|
|
504
528
|
}) => void;
|