@morpho-org/morpho-sdk 10.3.1 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -5
- package/lib/cjs/actions/midnight/redeem.d.ts +20 -3
- package/lib/cjs/actions/midnight/redeem.js +58 -1
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +41 -0
- package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -2
- package/lib/cjs/actions/midnight/withdrawCollateral.js +26 -1
- package/lib/cjs/helpers/callback.d.ts +3 -2
- package/lib/cjs/helpers/callback.js +4 -20
- package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
- package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.js +30 -0
- package/lib/cjs/helpers/parseMidnightMaker.d.ts +21 -0
- package/lib/cjs/helpers/parseMidnightMaker.js +41 -1
- package/lib/cjs/helpers/validate.d.ts +49 -1
- package/lib/cjs/helpers/validate.js +87 -1
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +10 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +18 -1
- package/lib/cjs/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
- package/lib/cjs/helpers/validateMidnightTakeableOfferFields.js +85 -0
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +23 -1
- package/lib/cjs/midnight/utils.d.ts +1 -1
- package/lib/cjs/midnight/utils.js +2 -1
- package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
- package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.js +264 -0
- package/lib/cjs/transactionPlan/error.d.ts +27 -0
- package/lib/cjs/transactionPlan/error.js +30 -1
- package/lib/cjs/transactionPlan/index.d.ts +40 -1
- package/lib/cjs/transactionPlan/index.js +46 -5
- package/lib/cjs/transactionPlan/midnight/authorization.d.ts +15 -0
- package/lib/cjs/transactionPlan/midnight/authorization.js +45 -0
- package/lib/cjs/transactionPlan/midnight/cancelOffers.d.ts +80 -0
- package/lib/cjs/transactionPlan/midnight/cancelOffers.js +125 -0
- package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +104 -0
- package/lib/cjs/transactionPlan/midnight/makeBorrow.js +126 -0
- package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +140 -0
- package/lib/cjs/transactionPlan/midnight/makeLend.js +176 -0
- package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +118 -0
- package/lib/cjs/transactionPlan/midnight/makeRepay.js +118 -0
- package/lib/cjs/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
- package/lib/cjs/transactionPlan/midnight/makeWithdraw.js +126 -0
- package/lib/cjs/transactionPlan/midnight/makerPublication.d.ts +55 -0
- package/lib/cjs/transactionPlan/midnight/makerPublication.js +315 -0
- package/lib/cjs/transactionPlan/midnight/market.d.ts +49 -0
- package/lib/cjs/transactionPlan/midnight/market.js +120 -0
- package/lib/cjs/transactionPlan/midnight/prepare.d.ts +244 -0
- package/lib/cjs/transactionPlan/midnight/prepare.js +547 -0
- package/lib/cjs/transactionPlan/midnight/publicationState.d.ts +24 -0
- package/lib/cjs/transactionPlan/midnight/publicationState.js +50 -0
- package/lib/cjs/transactionPlan/midnight/redeem.d.ts +102 -0
- package/lib/cjs/transactionPlan/midnight/redeem.js +170 -0
- package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
- package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.js +51 -0
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +328 -0
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +199 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +190 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +221 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +179 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +259 -0
- package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +304 -0
- package/lib/cjs/transactionPlan/midnight/takeBorrow.js +545 -0
- package/lib/cjs/transactionPlan/midnight/takeLend.d.ts +99 -0
- package/lib/cjs/transactionPlan/midnight/takeLend.js +263 -0
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +440 -0
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +240 -0
- package/lib/cjs/transactionPlan/midnight/validation.d.ts +22 -0
- package/lib/cjs/transactionPlan/midnight/validation.js +158 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateral.js +228 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.js +232 -0
- package/lib/cjs/transactionPlan/plan.d.ts +48 -14
- package/lib/cjs/transactionPlan/plan.js +103 -18
- package/lib/cjs/transactionPlan/requirements.d.ts +7 -4
- package/lib/cjs/transactionPlan/requirements.js +2 -2
- package/lib/cjs/transactionPlan/serde.d.ts +13 -2
- package/lib/cjs/transactionPlan/serde.js +68 -21
- package/lib/cjs/transactionPlan/types.d.ts +147 -0
- package/lib/cjs/transactionPlan/validateActions.d.ts +3 -1
- package/lib/cjs/transactionPlan/validateActions.js +31 -3
- package/lib/cjs/transactionPlan/validation.d.ts +1 -1
- package/lib/cjs/transactionPlan/validation.js +37 -1
- package/lib/cjs/types/error.d.ts +2 -0
- package/lib/cjs/types/error.js +2 -0
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/midnight/redeem.d.ts +20 -3
- package/lib/esm/actions/midnight/redeem.js +56 -0
- package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
- package/lib/esm/actions/midnight/supplyCollateralWithNative.js +40 -0
- package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -2
- package/lib/esm/actions/midnight/withdrawCollateral.js +25 -1
- package/lib/esm/helpers/callback.d.ts +3 -2
- package/lib/esm/helpers/callback.js +5 -21
- package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
- package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.js +27 -0
- package/lib/esm/helpers/parseMidnightMaker.d.ts +21 -0
- package/lib/esm/helpers/parseMidnightMaker.js +40 -1
- package/lib/esm/helpers/validate.d.ts +49 -1
- package/lib/esm/helpers/validate.js +84 -1
- package/lib/esm/helpers/validateMidnightPublication.d.ts +10 -0
- package/lib/esm/helpers/validateMidnightPublication.js +16 -0
- package/lib/esm/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
- package/lib/esm/helpers/validateMidnightTakeableOfferFields.js +81 -0
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/midnight/utils.d.ts +1 -1
- package/lib/esm/midnight/utils.js +1 -1
- package/lib/esm/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
- package/lib/esm/transactionPlan/blue/withdrawBuyCallback.js +259 -0
- package/lib/esm/transactionPlan/error.d.ts +27 -0
- package/lib/esm/transactionPlan/error.js +28 -0
- package/lib/esm/transactionPlan/index.d.ts +40 -1
- package/lib/esm/transactionPlan/index.js +20 -1
- package/lib/esm/transactionPlan/midnight/authorization.d.ts +15 -0
- package/lib/esm/transactionPlan/midnight/authorization.js +40 -0
- package/lib/esm/transactionPlan/midnight/cancelOffers.d.ts +80 -0
- package/lib/esm/transactionPlan/midnight/cancelOffers.js +120 -0
- package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +104 -0
- package/lib/esm/transactionPlan/midnight/makeBorrow.js +123 -0
- package/lib/esm/transactionPlan/midnight/makeLend.d.ts +140 -0
- package/lib/esm/transactionPlan/midnight/makeLend.js +172 -0
- package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +118 -0
- package/lib/esm/transactionPlan/midnight/makeRepay.js +115 -0
- package/lib/esm/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
- package/lib/esm/transactionPlan/midnight/makeWithdraw.js +123 -0
- package/lib/esm/transactionPlan/midnight/makerPublication.d.ts +55 -0
- package/lib/esm/transactionPlan/midnight/makerPublication.js +310 -0
- package/lib/esm/transactionPlan/midnight/market.d.ts +49 -0
- package/lib/esm/transactionPlan/midnight/market.js +112 -0
- package/lib/esm/transactionPlan/midnight/prepare.d.ts +244 -0
- package/lib/esm/transactionPlan/midnight/prepare.js +536 -0
- package/lib/esm/transactionPlan/midnight/publicationState.d.ts +24 -0
- package/lib/esm/transactionPlan/midnight/publicationState.js +47 -0
- package/lib/esm/transactionPlan/midnight/redeem.d.ts +102 -0
- package/lib/esm/transactionPlan/midnight/redeem.js +165 -0
- package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
- package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.js +47 -0
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +323 -0
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +196 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateral.js +185 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +216 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +176 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +254 -0
- package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +304 -0
- package/lib/esm/transactionPlan/midnight/takeBorrow.js +539 -0
- package/lib/esm/transactionPlan/midnight/takeLend.d.ts +99 -0
- package/lib/esm/transactionPlan/midnight/takeLend.js +258 -0
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +435 -0
- package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
- package/lib/esm/transactionPlan/midnight/takeWithdraw.js +236 -0
- package/lib/esm/transactionPlan/midnight/validation.d.ts +22 -0
- package/lib/esm/transactionPlan/midnight/validation.js +151 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateral.js +223 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.js +227 -0
- package/lib/esm/transactionPlan/plan.d.ts +48 -14
- package/lib/esm/transactionPlan/plan.js +99 -14
- package/lib/esm/transactionPlan/requirements.d.ts +7 -4
- package/lib/esm/transactionPlan/requirements.js +2 -2
- package/lib/esm/transactionPlan/serde.d.ts +13 -2
- package/lib/esm/transactionPlan/serde.js +49 -2
- package/lib/esm/transactionPlan/types.d.ts +147 -0
- package/lib/esm/transactionPlan/validateActions.d.ts +3 -1
- package/lib/esm/transactionPlan/validateActions.js +31 -3
- package/lib/esm/transactionPlan/validation.d.ts +1 -1
- package/lib/esm/transactionPlan/validation.js +38 -2
- package/lib/esm/types/error.d.ts +2 -0
- package/lib/esm/types/error.js +2 -0
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -380,16 +380,21 @@ including requests with existing signatures. It allows extra keys. Malformed JSO
|
|
|
380
380
|
references throw `InvalidTransactionPlanError` with a JSON `path` and `reason`; unsupported versions
|
|
381
381
|
and action types retain their dedicated errors. Serialization remains unchecked. Parsing verifies
|
|
382
382
|
stored signatures against their expected signers offline and rejects signatures from the wrong
|
|
383
|
-
signer.
|
|
384
|
-
|
|
385
|
-
|
|
383
|
+
signer. Midnight maker publications, `midnightSupplyCollateralTakeBorrow` and
|
|
384
|
+
`midnightTakeRepayWithdrawCollateral` also rerun their builders' static input checks on restore, so
|
|
385
|
+
a stored recipe that fails those checks throws `InvalidTransactionPlanError` there. Building can
|
|
386
|
+
still fail on a restored plan: deployment lookups such as the Midnight bundle address run only in
|
|
387
|
+
`buildTransactions`. Parsing uses no clock or RPC and does not check expiry, live state or other
|
|
388
|
+
action-layer business constraints. A successful parse does not prove intent or protect unsigned
|
|
389
|
+
fields, so integrators must still protect stored plans.
|
|
386
390
|
|
|
387
391
|
Supported action types are `erc20Approval`, `morphoAuthorization`, `blueSupply`,
|
|
388
392
|
`blueSupplyCollateral`, `blueBorrow`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueWithdraw`,
|
|
389
|
-
`blueWithdrawCollateral`, `blueRepayWithdrawCollateral`, `blueRefinance`, `vaultV1Deposit`, `vaultV1Withdraw`,
|
|
393
|
+
`blueWithdrawCollateral`, `blueWithdrawBuyCallback`, `blueRepayWithdrawCollateral`, `blueRefinance`, `vaultV1Deposit`, `vaultV1Withdraw`,
|
|
390
394
|
`vaultV1Redeem`, `vaultV1InKindRedeem`, `vaultV1MigrateToV2`,
|
|
391
395
|
`vaultV2Deposit`, `vaultV2Withdraw`, `vaultV2Redeem`,
|
|
392
|
-
`vaultV2ForceWithdraw`, `vaultV2ForceRedeem
|
|
396
|
+
`vaultV2ForceWithdraw`, `vaultV2ForceRedeem`, `vaultV2InKindRedeem`, `midnightAuthorization`,
|
|
397
|
+
`midnightTakeLend`, `midnightTakeBorrow`, `midnightSupplyCollateralTakeBorrow`, `midnightTakeWithdraw`, `midnightTakeRepayWithdrawCollateral`, `midnightSupplyCollateral`, `midnightSupplyCollateralWithNative`, `midnightSupplyCollateralBatch`, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch`, `midnightRedeem`, `midnightCancelOffers`, `midnightRepayWithdrawCollateral`, `midnightMakeBorrow`, `midnightMakeLend`, `midnightMakeWithdraw`, `midnightMakeRepay`, `midnightSupplyCollateralMakeBorrow` and `midnightSupplyBlueMakeLend`. Builders return plain `Readonly<Transaction>` objects without step metadata.
|
|
393
398
|
|
|
394
399
|
| Prepare function | Operation |
|
|
395
400
|
| --- | --- |
|
|
@@ -400,8 +405,28 @@ Supported action types are `erc20Approval`, `morphoAuthorization`, `blueSupply`,
|
|
|
400
405
|
| `prepareBlueRepay` | Repay Blue debt by assets or shares |
|
|
401
406
|
| `prepareBlueWithdraw` | Withdraw supplied loan assets from a Blue market |
|
|
402
407
|
| `prepareBlueWithdrawCollateral` | Withdraw collateral from a Blue market |
|
|
408
|
+
| `prepareBlueWithdrawBuyCallback` | Withdraw a BlueBuyCallback's whole supply position to its owner |
|
|
403
409
|
| `prepareBlueRepayWithdrawCollateral` | Repay, withdraw collateral, or perform both atomically on Blue |
|
|
404
410
|
| `prepareBlueRefinance` | Move a Blue borrow position to another market |
|
|
411
|
+
| `prepareMidnightTakeLend` | Lend at a fixed rate on Midnight by taking caller-quoted borrow offers |
|
|
412
|
+
| `prepareMidnightSupplyCollateral` | Supply the selected collateral directly to a Midnight market |
|
|
413
|
+
| `prepareMidnightSupplyCollateralBatch` | Supply several collaterals atomically to a Midnight market |
|
|
414
|
+
| `prepareMidnightSupplyCollateralWithNative` | Supply wNative collateral to a Midnight market, funded partly or fully with native ETH |
|
|
415
|
+
| `prepareMidnightRedeem` | Redeem credit from a caller-fetched Midnight position |
|
|
416
|
+
| `prepareMidnightWithdrawCollateral` | Withdraw one collateral directly from a caller-fetched Midnight position |
|
|
417
|
+
| `prepareMidnightWithdrawCollateralBatch` | Withdraw several collaterals atomically from a caller-fetched Midnight position |
|
|
418
|
+
| `prepareMidnightTakeBorrow` | Borrow from lend-side Midnight offers against an existing position |
|
|
419
|
+
| `prepareMidnightSupplyCollateralTakeBorrow` | Supply collateral and borrow from lend-side Midnight offers atomically |
|
|
420
|
+
| `prepareMidnightMakeBorrow` | Publish resting Midnight borrow offers without supplying collateral |
|
|
421
|
+
| `prepareMidnightSupplyCollateralMakeBorrow` | Supply collateral and publish resting Midnight borrow offers atomically |
|
|
422
|
+
| `prepareMidnightMakeLend` | Publish resting Midnight lend offers funded by the maker when filled |
|
|
423
|
+
| `prepareMidnightSupplyBlueMakeLend` | Supply loan assets to the maker's BlueBuyCallback and publish resting Midnight lend offers atomically |
|
|
424
|
+
| `prepareMidnightMakeWithdraw` | Publish resting Midnight reduce-only sell offers against existing credit |
|
|
425
|
+
| `prepareMidnightMakeRepay` | Publish resting Midnight reduce-only buy offers against existing debt |
|
|
426
|
+
| `prepareMidnightTakeWithdraw` | Withdraw Midnight credit using lend-side offers without opening debt |
|
|
427
|
+
| `prepareMidnightTakeRepayWithdrawCollateral` | Repay Midnight debt by taking borrow offers, optionally repaying the rest directly and withdrawing collateral |
|
|
428
|
+
| `prepareMidnightCancelOffers` | Cancel Midnight offer groups in full with a direct Midnight call |
|
|
429
|
+
| `prepareMidnightRepayWithdrawCollateral` | Repay Midnight debt directly or withdraw collateral without filling offers |
|
|
405
430
|
| `prepareVaultV2Deposit` | Deposit assets into Vault V2 |
|
|
406
431
|
| `prepareVaultV2Withdraw` | Withdraw assets from Vault V2 |
|
|
407
432
|
| `prepareVaultV2Redeem` | Redeem an exact number of Vault V2 shares |
|
|
@@ -426,6 +451,145 @@ With insufficient ERC-20 allowance, it requests an unlimited approval or an exac
|
|
|
426
451
|
permit for BlueBundlesV1. Native funding is available only for wNative collateral, needs neither
|
|
427
452
|
approval nor permit, and stores `nativeAssets` equal to `collateralAssets`.
|
|
428
453
|
|
|
454
|
+
`prepareMidnightSupplyCollateralBatch` supplies a nonempty ordered list of `collateralSupplies`, one
|
|
455
|
+
per index, in one Midnight core multicall. For each token whose allowance is below that token's total,
|
|
456
|
+
it adds the approval steps to Midnight core that the token requires (usually one unlimited approval,
|
|
457
|
+
possibly a reset to zero first or a capped amount). It needs no authorization or signature request;
|
|
458
|
+
`expiresAt` is not an on-chain deadline.
|
|
459
|
+
|
|
460
|
+
`prepareMidnightSupplyCollateralWithNative` supplies `collateralAssets` of the wNative collateral at
|
|
461
|
+
`collateralIndex` through MidnightBundlesV2. A positive `nativeAmount`, at most `collateralAssets`, is
|
|
462
|
+
sent as transaction value and wrapped to the account; the bundle then pulls the full
|
|
463
|
+
`collateralAssets` as wNative, so the wallet's own wNative balance covers only
|
|
464
|
+
`collateralAssets - nativeAmount`. It adds an unlimited wNative approval to MidnightBundlesV2 when the
|
|
465
|
+
allowance is below `collateralAssets`, and a Midnight authorization of the bundle when it is missing.
|
|
466
|
+
Unlike the entity, it takes no `reservedCollateralAssets`, so the allowance check keeps no reserve
|
|
467
|
+
for a later maker operation. Simulate the whole sequence before asking the wallet for either
|
|
468
|
+
permission. It needs no signature requests, and `expiresAt` is the on-chain bundle deadline.
|
|
469
|
+
|
|
470
|
+
`prepareBlueWithdrawBuyCallback` takes the callback's market and position snapshots and
|
|
471
|
+
`callbackAddress`; `account` must be the callback's owner. It fixes every supply share in the
|
|
472
|
+
snapshot on one `blueWithdrawBuyCallback` step, a direct Morpho Blue `withdraw` with no approval,
|
|
473
|
+
authorization or signature request. Preparation rejects a callback the registered factory did not
|
|
474
|
+
create, another owner, or a revoked Blue authorization. It takes no referral fee, `supportSignature`
|
|
475
|
+
or `deployless`, and `expiresAt` is plan metadata only. Those checks run only at preparation:
|
|
476
|
+
`parseTransactionPlan` and `buildTransactions` are offline, and the built `withdraw` pays
|
|
477
|
+
`plan.account`. Restore only plans from a trusted source, send only from `plan.account` (reject a
|
|
478
|
+
plan whose `account` is not the connected wallet), and simulate before sending. The step withdraws
|
|
479
|
+
the snapshot's share count, not the position at send time: shares added later stay in the callback,
|
|
480
|
+
and a smaller position makes the withdrawal revert.
|
|
481
|
+
|
|
482
|
+
`prepareMidnightRedeem` takes a caller-fetched `positionData: AccrualPosition` bound to the
|
|
483
|
+
plan account and market. It fixes explicit `units` or defaults to the accrued face value.
|
|
484
|
+
`receiver` defaults to the account. This direct withdrawal needs no approvals or signature
|
|
485
|
+
requests, and `expiresAt` is plan metadata, not an on-chain deadline.
|
|
486
|
+
|
|
487
|
+
`prepareMidnightWithdrawCollateral` takes the sender's market and position snapshots from one
|
|
488
|
+
block, plus `collateralPrices` when the position has debt. It applies the entity
|
|
489
|
+
`withdrawCollateral` checks: `assets: maxUint256` withdraws the snapshot balance at
|
|
490
|
+
`collateralIndex`, and the remaining collateral must cover the debt at LLTV minus
|
|
491
|
+
`DEFAULT_LLTV_BUFFER`. `receiver` defaults to the account. The direct Midnight call needs no
|
|
492
|
+
approvals, authorizations or signature requests, and `expiresAt` is not an on-chain deadline.
|
|
493
|
+
`prepareMidnightWithdrawCollateralBatch` does the same for a nonempty ordered list of
|
|
494
|
+
`collateralWithdrawals`, one per index, in one Midnight core multicall to a shared `receiver`.
|
|
495
|
+
|
|
496
|
+
To withdraw credit into lend offers instead, fetch the owner-bound position at the reference
|
|
497
|
+
block and request a quote on the bid side. Pass the offers from `quote.data.takeableOffers`;
|
|
498
|
+
if the quote is empty, preparation throws `EmptyMidnightTakeableOffersError`.
|
|
499
|
+
|
|
500
|
+
```ts
|
|
501
|
+
import { buildTransactions, prepareMidnightTakeWithdraw, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
502
|
+
import { fetchMidnightAccrualPosition } from "@morpho-org/morpho-sdk/fetch";
|
|
503
|
+
import { MidnightApi } from "@morpho-org/morpho-sdk/midnight-api";
|
|
504
|
+
import { type Address, type Hash, createPublicClient, http } from "viem";
|
|
505
|
+
import { base } from "viem/chains";
|
|
506
|
+
|
|
507
|
+
async function prepareWithdrawal(account: Address, marketId: Hash) {
|
|
508
|
+
const client = createPublicClient({ chain: base, transport: http() });
|
|
509
|
+
const block = await client.getBlock();
|
|
510
|
+
const positionData = await fetchMidnightAccrualPosition(client, {
|
|
511
|
+
marketId,
|
|
512
|
+
user: account,
|
|
513
|
+
blockNumber: block.number,
|
|
514
|
+
});
|
|
515
|
+
const marketData = positionData.market;
|
|
516
|
+
const assets = 1_000_000n;
|
|
517
|
+
const maxUnits = 1_100_000n;
|
|
518
|
+
// Quote the unit ceiling: fees come out of the proceeds, so fills sized to the net
|
|
519
|
+
// assets could not deliver them.
|
|
520
|
+
const quote = await new MidnightApi().fetchBookQuote({
|
|
521
|
+
marketId,
|
|
522
|
+
side: "bids",
|
|
523
|
+
units: maxUnits,
|
|
524
|
+
taker: account,
|
|
525
|
+
});
|
|
526
|
+
const plan: TransactionPlan = await prepareMidnightTakeWithdraw(client, {
|
|
527
|
+
chainId: base.id,
|
|
528
|
+
account,
|
|
529
|
+
marketData,
|
|
530
|
+
positionData,
|
|
531
|
+
now: block.timestamp,
|
|
532
|
+
target: { type: "assets", assets, maxUnits },
|
|
533
|
+
takeableOffers: quote.data.takeableOffers,
|
|
534
|
+
});
|
|
535
|
+
// Simulate, then send in order from plan.account on plan.chainId.
|
|
536
|
+
return buildTransactions(plan);
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
`prepareMidnightMakeBorrow` publishes caller-created PriceRatifierV1 or RateRatifierV1 sell offers
|
|
541
|
+
without supplying collateral or borrowing immediately. It needs no token approval or root
|
|
542
|
+
signature. See the [TransactionPlan guide](src/transactionPlan/README.md#midnight-maker-borrow-offers)
|
|
543
|
+
for a tree example, offline restoration, and which authorizations persist.
|
|
544
|
+
|
|
545
|
+
`prepareMidnightMakeLend` publishes caller-created buy offers without moving loan tokens.
|
|
546
|
+
Midnight core pulls the maker's tokens when someone fills the offers, so the plan may add a
|
|
547
|
+
core token approval for the offered and reserved budget. It never approves the bundle to spend
|
|
548
|
+
tokens or uses native ETH. See the [TransactionPlan guide](src/transactionPlan/README.md#midnight-maker-lend-offers)
|
|
549
|
+
for a tree example and the lifetime of the approval and grants.
|
|
550
|
+
|
|
551
|
+
`prepareMidnightMakeWithdraw` publishes caller-created PriceRatifierV1 or RateRatifierV1
|
|
552
|
+
reduce-only sell offers against existing maker credit. It does not withdraw funds or
|
|
553
|
+
decrease credit on publication. See the [TransactionPlan guide](src/transactionPlan/README.md#midnight-maker-withdrawal-offers)
|
|
554
|
+
for a tree example, offline restoration, and which authorizations persist.
|
|
555
|
+
|
|
556
|
+
`prepareMidnightMakeRepay` publishes caller-created PriceRatifierV1 or RateRatifierV1
|
|
557
|
+
reduce-only buy offers against existing maker debt. It may add a core token approval for
|
|
558
|
+
later fills but does not repay debt or move tokens on publication. See the
|
|
559
|
+
[TransactionPlan guide](src/transactionPlan/README.md#midnight-maker-repayment-offers)
|
|
560
|
+
for a tree example, offline restoration, and which approvals and authorizations persist.
|
|
561
|
+
|
|
562
|
+
`prepareMidnightSupplyCollateralMakeBorrow` supplies collateral and activates the maker's
|
|
563
|
+
PriceRatifierV1 or RateRatifierV1 sell-offer root in one bundle. It does not fill an offer,
|
|
564
|
+
create debt, or disburse loan assets. Collateral indexes are zero-based positions
|
|
565
|
+
in ascending collateral token address order. See the [TransactionPlan guide](src/transactionPlan/README.md#midnight-collateral-backed-maker-borrow-offers)
|
|
566
|
+
for a tree example, wrapped-native funding, and which approvals and authorizations persist.
|
|
567
|
+
|
|
568
|
+
`prepareMidnightSupplyBlueMakeLend` parks loan assets on Blue for the maker's BlueBuyCallback
|
|
569
|
+
and activates the maker's lend-offer root in the same bundle, without filling an offer. See
|
|
570
|
+
the [TransactionPlan guide](src/transactionPlan/README.md#midnight-blue-backed-maker-lend-offers)
|
|
571
|
+
for the callback-bound tree, offline restoration, and persistent approvals and authorizations.
|
|
572
|
+
|
|
573
|
+
`prepareMidnightRepayWithdrawCollateral` takes the sender's market and position snapshots from
|
|
574
|
+
the same block.
|
|
575
|
+
Use `repay: { type: "assets", assets }` for an exact repayment (zero for a collateral-only
|
|
576
|
+
withdrawal), or `repay: { type: "full", maxBuyerAssets }` to close the debt under a finite cap.
|
|
577
|
+
Both amounts are in the loan token's smallest units. Withdrawals are optional and go to the
|
|
578
|
+
sender unless you set `collateralReceiver`. There are no offer fills, referral fees, or signature
|
|
579
|
+
requests. The bundle requires allowance for the full pull even if you provide `nativeAmount`
|
|
580
|
+
in wei for a wrapped-native loan, plus a standalone authorization if not already granted.
|
|
581
|
+
If allowance is insufficient, the plan requests an unlimited (`maxUint256`, subject to
|
|
582
|
+
`MAX_TOKEN_APPROVALS`) ERC-20 approval to MidnightBundlesV2. Once granted, the approval does
|
|
583
|
+
not expire with the plan.
|
|
584
|
+
See the [TransactionPlan guide](src/transactionPlan/README.md#midnight-repayment-and-collateral-withdrawal)
|
|
585
|
+
for a repayment example, collateral indexes, oracle prices, and expiry defaults.
|
|
586
|
+
|
|
587
|
+
`prepareMidnightCancelOffers` takes `account` and a nonempty list of distinct 32-byte `groups`,
|
|
588
|
+
fixed on one `midnightCancelOffers` step with no approvals, authorization or signature requests.
|
|
589
|
+
One group builds a bare Midnight `setConsumed(group, maxUint128, account)`; two or more build one
|
|
590
|
+
Midnight core `multicall`. It never targets MidnightBundlesV2, and `account` or a Midnight-authorized
|
|
591
|
+
operator must send it. `expiresAt` is plan metadata only, not an onchain deadline.
|
|
592
|
+
|
|
429
593
|
`prepareVaultV2ForceRedeem` takes `vaultAddress` and top-level `shares`, with no snapshot.
|
|
430
594
|
Caller-supplied `deallocations[].assets` and `shares` are fixed on one `vaultV2ForceRedeem` step
|
|
431
595
|
with no approvals or signature requests. It accepts neither `supportSignature` nor `deployless`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
-
import type
|
|
1
|
+
import type { AccrualPosition, MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
3
|
import { type MidnightMarket } from "../../helpers/parseMidnight.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type Metadata, type MidnightRedeemAction, type Transaction } from "../../types/index.js";
|
|
5
5
|
/** Parameters for encoding a direct Midnight credit redemption. */
|
|
6
6
|
export interface MidnightRedeemParams {
|
|
7
7
|
readonly chainId: number;
|
|
@@ -63,4 +63,21 @@ export interface ParsedMidnightRedeem extends Omit<MidnightRedeemParams, "market
|
|
|
63
63
|
}
|
|
64
64
|
/** Parses static redeem constraints using the existing error order. @internal */
|
|
65
65
|
export declare const parseMidnightRedeem: (params: MidnightRedeemParams) => ParsedMidnightRedeem;
|
|
66
|
+
/** Owner-bound position snapshot and optional amounts for a redemption. @internal */
|
|
67
|
+
export interface MidnightRedeemPreparationParams {
|
|
68
|
+
readonly chainId: number;
|
|
69
|
+
readonly accountAddress: Address;
|
|
70
|
+
readonly positionData: AccrualPosition;
|
|
71
|
+
readonly units?: bigint;
|
|
72
|
+
readonly receiver?: Address;
|
|
73
|
+
readonly now: bigint;
|
|
74
|
+
readonly metadata?: Metadata;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Owns redemption defaults and snapshot-dependent amount constraints in the same order as the
|
|
78
|
+
* entity `redeem`, then mints the complete redeem contract. Used by TransactionPlan preparation;
|
|
79
|
+
* the entity keeps its own copy of these checks.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export declare const parseMidnightRedeemPreparation: (params: MidnightRedeemPreparationParams) => ParsedMidnightRedeem;
|
|
66
83
|
export {};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseMidnightRedeem = exports.midnightRedeem = void 0;
|
|
3
|
+
exports.parseMidnightRedeemPreparation = exports.parseMidnightRedeem = exports.midnightRedeem = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
4
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
5
7
|
const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
|
|
8
|
+
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
6
9
|
const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightReceiver.js");
|
|
10
|
+
const index_js_1 = require("../../types/index.js");
|
|
7
11
|
const encode_js_1 = require("./encode.js");
|
|
8
12
|
const parse_js_1 = require("./parse.js");
|
|
9
13
|
/**
|
|
@@ -75,3 +79,56 @@ const parseMidnightRedeem = (params) => {
|
|
|
75
79
|
});
|
|
76
80
|
};
|
|
77
81
|
exports.parseMidnightRedeem = parseMidnightRedeem;
|
|
82
|
+
/**
|
|
83
|
+
* Owns redemption defaults and snapshot-dependent amount constraints in the same order as the
|
|
84
|
+
* entity `redeem`, then mints the complete redeem contract. Used by TransactionPlan preparation;
|
|
85
|
+
* the entity keeps its own copy of these checks.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
const parseMidnightRedeemPreparation = (params) => {
|
|
89
|
+
const address = (0, parseMidnight_js_1.parseMidnightAddress)("accountAddress", params.accountAddress);
|
|
90
|
+
if (!params.positionData) {
|
|
91
|
+
throw new index_js_1.MissingAccrualPositionError();
|
|
92
|
+
}
|
|
93
|
+
if (params.positionData.user != null) {
|
|
94
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("positionData.user", params.positionData.user);
|
|
95
|
+
}
|
|
96
|
+
if (params.positionData.user == null ||
|
|
97
|
+
!(0, viem_1.isAddressEqual)(params.positionData.user, address)) {
|
|
98
|
+
throw new index_js_1.AccrualPositionUserMismatchError(params.positionData.user ?? "unbound", address);
|
|
99
|
+
}
|
|
100
|
+
const marketData = params.positionData.market;
|
|
101
|
+
// Reject market/deployment errors before snapshot accrual and amount checks.
|
|
102
|
+
const market = (0, parseMidnight_js_1.parseMidnightMarket)(marketData, params.chainId);
|
|
103
|
+
const accrued = params.positionData.accrueInterest(blue_sdk_1.MathLib.max(params.now, params.positionData.lastAccrual));
|
|
104
|
+
const units = params.units ?? accrued.faceValue;
|
|
105
|
+
if (params.units === undefined && units <= 0n) {
|
|
106
|
+
throw new index_js_1.NoMidnightCreditToRedeemError(marketData.id);
|
|
107
|
+
}
|
|
108
|
+
// Bound the resolved amount before checking credit and liquidity.
|
|
109
|
+
(0, parseMidnight_js_1.parseMidnightPositiveAmount)("units", units);
|
|
110
|
+
if (accrued.credit < units) {
|
|
111
|
+
throw new index_js_1.MidnightRedeemExceedsCreditError({
|
|
112
|
+
market: marketData.id,
|
|
113
|
+
units,
|
|
114
|
+
credit: accrued.credit,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (marketData.withdrawable < units) {
|
|
118
|
+
throw new index_js_1.InsufficientMidnightWithdrawableLiquidityError({
|
|
119
|
+
market: marketData.id,
|
|
120
|
+
units,
|
|
121
|
+
withdrawable: marketData.withdrawable,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// The owning action constructor mints the complete contract only after snapshot checks.
|
|
125
|
+
return (0, exports.parseMidnightRedeem)({
|
|
126
|
+
chainId: params.chainId,
|
|
127
|
+
market: market.struct,
|
|
128
|
+
units,
|
|
129
|
+
onBehalf: address,
|
|
130
|
+
receiver: params.receiver ?? address,
|
|
131
|
+
metadata: params.metadata,
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
exports.parseMidnightRedeemPreparation = parseMidnightRedeemPreparation;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
1
|
+
import { type MarketInput, MarketUtils } from "@morpho-org/midnight-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
+
import { encodeMidnightMarketId } from "../../helpers/encodeMidnightCalldata.js";
|
|
3
4
|
import { type Metadata, type MidnightSupplyCollateralWithNativeAction, type Transaction } from "../../types/index.js";
|
|
4
5
|
/** Parameters for encoding a Midnight collateral supply. */
|
|
5
6
|
export interface MidnightSupplyCollateralWithNativeParams {
|
|
@@ -75,3 +76,25 @@ export declare function prepareMidnightSupplyCollateralWithNative(params: Midnig
|
|
|
75
76
|
token: `0x${string}`;
|
|
76
77
|
tx: Transaction<MidnightSupplyCollateralWithNativeAction>;
|
|
77
78
|
};
|
|
79
|
+
/** Owned native collateral supply inputs, checked in the encoder's order. @internal */
|
|
80
|
+
export interface ParsedMidnightSupplyCollateralWithNative {
|
|
81
|
+
readonly chainId: number;
|
|
82
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
83
|
+
readonly marketId: ReturnType<typeof encodeMidnightMarketId>;
|
|
84
|
+
readonly collateralIndex: bigint;
|
|
85
|
+
readonly assets: bigint;
|
|
86
|
+
/** wNative collateral pulled from the sender. */
|
|
87
|
+
readonly token: Address;
|
|
88
|
+
readonly accountAddress: Address;
|
|
89
|
+
/** Native funding sent as transaction value. */
|
|
90
|
+
readonly value: bigint;
|
|
91
|
+
readonly wrappedNative: Address;
|
|
92
|
+
readonly deadline: bigint;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parses a native collateral supply with the same checks, in the same order, as
|
|
96
|
+
* `midnightSupplyCollateralWithNative`, without encoding the bundle call. Resolving
|
|
97
|
+
* MidnightBundlesV2 is left to the caller. `assetsField` names the amount in its errors, so a
|
|
98
|
+
* caller can report its own parameter name. @internal
|
|
99
|
+
*/
|
|
100
|
+
export declare function parseMidnightSupplyCollateralWithNative(params: Omit<MidnightSupplyCollateralWithNativeParams, "metadata">, assetsField?: "assets" | "collateralAssets"): ParsedMidnightSupplyCollateralWithNative;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.midnightSupplyCollateralWithNative = void 0;
|
|
4
4
|
exports.prepareMidnightSupplyCollateralWithNative = prepareMidnightSupplyCollateralWithNative;
|
|
5
|
+
exports.parseMidnightSupplyCollateralWithNative = parseMidnightSupplyCollateralWithNative;
|
|
5
6
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
6
7
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
8
|
const viem_1 = require("viem");
|
|
@@ -140,3 +141,43 @@ function prepareMidnightSupplyCollateralWithNative(params) {
|
|
|
140
141
|
}),
|
|
141
142
|
};
|
|
142
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Parses a native collateral supply with the same checks, in the same order, as
|
|
146
|
+
* `midnightSupplyCollateralWithNative`, without encoding the bundle call. Resolving
|
|
147
|
+
* MidnightBundlesV2 is left to the caller. `assetsField` names the amount in its errors, so a
|
|
148
|
+
* caller can report its own parameter name. @internal
|
|
149
|
+
*/
|
|
150
|
+
function parseMidnightSupplyCollateralWithNative(params, assetsField = "assets") {
|
|
151
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("accountAddress", params.accountAddress);
|
|
152
|
+
const assets = (0, parseMidnight_js_1.parseMidnightNativeCollateralAmount)(assetsField, params.assets);
|
|
153
|
+
if ((0, viem_1.isAddressEqual)(params.accountAddress, viem_1.zeroAddress)) {
|
|
154
|
+
throw new index_js_2.MidnightZeroOnBehalfError("accountAddress");
|
|
155
|
+
}
|
|
156
|
+
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
|
|
157
|
+
const market = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("marketId", () => midnight_sdk_1.MarketUtils.toStruct(params.market));
|
|
158
|
+
const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(market);
|
|
159
|
+
const collateralIndex = params.collateralIndex ?? 0n;
|
|
160
|
+
const { token } = midnight_sdk_1.MarketUtils.getCollateralByIndex(market, collateralIndex);
|
|
161
|
+
if (params.nativeAmount === 0n || params.nativeAmount === undefined) {
|
|
162
|
+
throw new index_js_2.NonPositiveInputError("nativeAmount", params.nativeAmount ?? 0n);
|
|
163
|
+
}
|
|
164
|
+
const { value, wrappedNative } = (0, validate_js_1.validateMidnightNativeAmount)({
|
|
165
|
+
chainId: params.chainId,
|
|
166
|
+
nativeAmount: params.nativeAmount,
|
|
167
|
+
pulls: [{ token, assets }],
|
|
168
|
+
});
|
|
169
|
+
const deadline = params.deadline ?? 0n;
|
|
170
|
+
(0, validate_js_1.validateDeadline)(deadline);
|
|
171
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
172
|
+
chainId: params.chainId,
|
|
173
|
+
market,
|
|
174
|
+
marketId,
|
|
175
|
+
collateralIndex,
|
|
176
|
+
assets,
|
|
177
|
+
token,
|
|
178
|
+
accountAddress: params.accountAddress,
|
|
179
|
+
value,
|
|
180
|
+
wrappedNative,
|
|
181
|
+
deadline,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
-
import type
|
|
1
|
+
import type { AccrualPosition, Market, MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
3
|
import { type MidnightMarket } from "../../helpers/parseMidnight.js";
|
|
4
4
|
import type { Metadata, MidnightWithdrawCollateralAction, Transaction } from "../../types/index.js";
|
|
5
5
|
/** Parameters for encoding a direct Midnight collateral withdrawal. */
|
|
@@ -60,4 +60,18 @@ export interface ParsedMidnightWithdrawCollateral extends Omit<MidnightWithdrawC
|
|
|
60
60
|
}
|
|
61
61
|
/** Parses static withdrawCollateral constraints using the existing error order. @internal */
|
|
62
62
|
export declare const parseMidnightWithdrawCollateral: (params: MidnightWithdrawCollateralParams) => ParsedMidnightWithdrawCollateral;
|
|
63
|
+
/** Complete raw withdrawal preparation; domain snapshots stay caller-owned. @internal */
|
|
64
|
+
export interface MidnightWithdrawCollateralPreparationParams extends Omit<MidnightWithdrawCollateralParams, "market" | "onBehalf" | "receiver"> {
|
|
65
|
+
readonly accountAddress: Address;
|
|
66
|
+
readonly marketData: Market;
|
|
67
|
+
readonly positionData: AccrualPosition;
|
|
68
|
+
/** Defaults to `accountAddress`. */
|
|
69
|
+
readonly receiver?: Address;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Owns the snapshot-bound withdrawal checks in entity order: account, market, position binding,
|
|
73
|
+
* collateral index, `maxUint256` resolution to the snapshot balance, then the direct-call checks.
|
|
74
|
+
* Balance and health checks against the snapshot are left to the caller. @internal
|
|
75
|
+
*/
|
|
76
|
+
export declare const parseMidnightWithdrawCollateralPreparation: (params: MidnightWithdrawCollateralPreparationParams) => ParsedMidnightWithdrawCollateral;
|
|
63
77
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseMidnightWithdrawCollateral = exports.midnightWithdrawCollateral = void 0;
|
|
3
|
+
exports.parseMidnightWithdrawCollateralPreparation = exports.parseMidnightWithdrawCollateral = exports.midnightWithdrawCollateral = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const viem_1 = require("viem");
|
|
5
6
|
const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
|
|
6
7
|
const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightReceiver.js");
|
|
7
8
|
const encode_js_1 = require("./encode.js");
|
|
@@ -72,3 +73,27 @@ const parseMidnightWithdrawCollateral = (params) => {
|
|
|
72
73
|
});
|
|
73
74
|
};
|
|
74
75
|
exports.parseMidnightWithdrawCollateral = parseMidnightWithdrawCollateral;
|
|
76
|
+
/**
|
|
77
|
+
* Owns the snapshot-bound withdrawal checks in entity order: account, market, position binding,
|
|
78
|
+
* collateral index, `maxUint256` resolution to the snapshot balance, then the direct-call checks.
|
|
79
|
+
* Balance and health checks against the snapshot are left to the caller. @internal
|
|
80
|
+
*/
|
|
81
|
+
const parseMidnightWithdrawCollateralPreparation = (params) => {
|
|
82
|
+
const onBehalf = (0, parseMidnight_js_1.parseMidnightAccount)("accountAddress", params.accountAddress);
|
|
83
|
+
const market = (0, parseMidnight_js_1.parseMidnightMarket)(params.marketData, params.chainId);
|
|
84
|
+
// Bind the supplied snapshot before interpreting its collateral balances.
|
|
85
|
+
(0, parseMidnight_js_1.validateMidnightPositionBinding)(params);
|
|
86
|
+
const collateral = (0, parseMidnight_js_1.parseMidnightCollateral)(market, params.collateralIndex ?? 0n);
|
|
87
|
+
const available = params.positionData.collateral[Number(collateral.index)] ?? 0n;
|
|
88
|
+
const action = (0, exports.parseMidnightWithdrawCollateral)({
|
|
89
|
+
chainId: params.chainId,
|
|
90
|
+
market: market.struct,
|
|
91
|
+
assets: params.assets === viem_1.maxUint256 ? available : params.assets,
|
|
92
|
+
onBehalf,
|
|
93
|
+
receiver: params.receiver ?? onBehalf,
|
|
94
|
+
collateralIndex: collateral.index,
|
|
95
|
+
metadata: params.metadata,
|
|
96
|
+
});
|
|
97
|
+
return action;
|
|
98
|
+
};
|
|
99
|
+
exports.parseMidnightWithdrawCollateralPreparation = parseMidnightWithdrawCollateralPreparation;
|
|
@@ -4,7 +4,8 @@ import { type Address, type Hex } from "viem";
|
|
|
4
4
|
* Computes the CREATE2 address of `owner`'s `BlueBuyCallback` for `salt`, as deployed or
|
|
5
5
|
* returned by the chain's `midnightBlueBuyCallbackFactory.createBlueBuyCallback(owner, salt)`.
|
|
6
6
|
*
|
|
7
|
-
* Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`.
|
|
7
|
+
* Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`. It is the
|
|
8
|
+
* Midnight-qualified name of midnight-sdk's `getBlueBuyCallbackAddress`.
|
|
8
9
|
*
|
|
9
10
|
* @param params.chainId - Chain whose `midnightBlueBuyCallbackFactory`, `midnight` and `blue` are used.
|
|
10
11
|
* @param params.owner - Callback owner, the maker.
|
|
@@ -28,7 +29,7 @@ import { type Address, type Hex } from "viem";
|
|
|
28
29
|
* // `callbackFor(maker)` returns the maker's BlueBuyCallback address, deployed or not.
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
|
-
export declare const getMidnightBlueBuyCallbackAddress: (
|
|
32
|
+
export declare const getMidnightBlueBuyCallbackAddress: (params: {
|
|
32
33
|
readonly chainId: number;
|
|
33
34
|
readonly owner: Address;
|
|
34
35
|
readonly salt: Hex;
|
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
-
const
|
|
5
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
-
/**
|
|
8
|
-
* `BlueBuyCallback` creation bytecode from `morpho-org/midnight` commit
|
|
9
|
-
* `4603969e`, embedded in every `midnightBlueBuyCallbackFactory` of the address registry.
|
|
10
|
-
*/
|
|
11
|
-
const blueBuyCallbackBytecode = "0x60e0806040523461012657606081611611803803809161001f828561012a565b8339810103126101265761003281610161565b9061004b604061004460208401610161565b9201610161565b908260805260a0528060c05260018060a01b031690813b15610126576040516207767560ed1b81526001600160a01b03909116600482015260016024820152905f908290604490829084905af1801561011b5761010b575b60405161149b9081610176823960805181818160b4015281816102fc0152818161078201528181610dfd0152611004015260a0518181816102210152610dc3015260c051818181610103015281816102650152818161067c015281816108660152610f5e0152f35b5f6101159161012a565b5f6100a3565b6040513d5f823e3d90fd5b5f80fd5b601f909101601f19168101906001600160401b0382119082101761014d57604052565b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036101265756fe6080806040526004361015610012575f80fd5b5f905f3560e01c908163117803e314610fe7575080631c0bb54d14610d585780631e686318146107ef5780638069218f1461043d578063affed0e014610420578063bc25cf7714610289578063c011ff6414610245578063dc400c12146102015763eecea00014610081575f80fd5b346101a15760403660031901126101a15761009a61107c565b9060243591821515908184036101fd576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633036101ee576040516332f256cf60e11b81523060048201526001600160a01b038281166024830152939485947f000000000000000000000000000000000000000000000000000000000000000016939091602081604481885afa9081156101e35786916101b4575b5015150361014a57505050f35b823b156101af576040516207767560ed1b81526001600160a01b03929092166004830152151560248201529082908290604490829084905af180156101a4576101905750f35b8161019a91611044565b6101a15780f35b80fd5b6040513d84823e3d90fd5b505050fd5b6101d6915060203d6020116101dc575b6101ce8183611044565b810190611358565b5f61013d565b503d6101c4565b6040513d88823e3d90fd5b6330cd747160e01b8352600483fd5b8280fd5b50346101a157806003193601126101a15760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346101a157806003193601126101a15760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346101a15760203660031901126101a1576102a361107c565b6040516370a0823160e01b81523060048201526001600160a01b03821691602082602481865afa9182156104155784926103dd575b50803b156103ce5760405163a9059cbb60e01b602082019081526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001660248301526044820184905285928392909190839061034881606481015b03601f198101835282611044565b51925af1610354611370565b90156103c65780519081159182156103ac575b50501561039d576040519081527f2ae72b44f59d038340fca5739135a1d51fc5ab720bb02d983e4c5ff4119ca7b860203392a380f35b630bc11c3f60e21b8352600483fd5b6103bf9250602080918301019101611358565b5f80610367565b602081519101fd5b633c11a9c560e21b8452600484fd5b9091506020813d60201161040d575b816103f960209383611044565b810103126104095751905f6102d8565b5f80fd5b3d91506103ec565b6040513d86823e3d90fd5b50346101a157806003193601126101a15760209054604051908152f35b503461040957366003190161010081126104095760a0136104095760405161046481611028565b61046c61107c565b8152602435906001600160a01b038216820361040957602081019182526044359182151583036104095760408201928352606082019160643583526084356080820190808252606060a3193601126104095742116107e05783515f54905f1982146107cc57600182015f55036107bd5760405160208101917f81d0284fb0e2cde18d0553b06189d6f7613c96a01bb5b5e7828eade6a0dcac9183526001600160a01b0384511660408301526001600160a01b038551166060830152865115156080830152855160a08301525160c082015260c0815261054c60e082611044565b51902060405160208101907f47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218825246604082015230606082015260608152610595608082611044565b5190209060405190602082019261190160f01b845260228301526042820152604281526105c3606282611044565b51902060a4359060ff82168092036104095760805f916020936040519182528482015260c435604082015260e435606082015282805260015afa1561073b576001600160a01b035f511680151591826107a9575b5081610776575b5015610767576106af91516040519081527fbae999fc435f6200224444d8535f1936f9abd69060fcaec680f690f1810ae36a60203392a280516040516332f256cf60e11b81523060048201526001600160a01b0391821660248201527f0000000000000000000000000000000000000000000000000000000000000000909116939092602090849081906044820190565b0381875afa92831561073b575f93610746575b5051151580921515036106d3578380f35b516001600160a01b031690823b15610409576040516207767560ed1b81526001600160a01b0392909216600483015215156024820152905f908290604490829084905af1801561073b57610728575b80808380f35b61073491505f90611044565b5f5f610722565b6040513d5f823e3d90fd5b61076091935060203d6020116101dc576101ce8183611044565b915f6106c2565b638baa579f60e01b5f5260045ffd5b90506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016145f61061e565b516001600160a01b0316811491505f610617565b633ab3447f60e11b5f5260045ffd5b634e487b7160e01b5f52601160045260245ffd5b630f05f5bf60e01b5f5260045ffd5b346104095760803660031901126104095760243567ffffffffffffffff8111610409576108209036906004016110a6565b50610829611066565b5060643567ffffffffffffffff81116104095761084d61085c91369060040161122a565b60208082518301019101611284565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169060a0812060405190632e3071cd60e11b8252600482015260c081602481865afa90811561073b575f91610ca8575b50608081016108ce6001600160801b038251164261134b565b9081151580610c92575b80610c7c575b610a82575b50506001600160801b03815116906001600160801b03604081602084015116920151169060a08420604051906349e2903160e11b82526004820152306024820152606081604481895afa90811561073b575f916109f9575b505160018401928385116107cc57620f424083018093116107cc576109766001600160a01b039361097160209661097c956113cc565b611470565b9461134b565b935116936024604051809681936370a0823160e01b835260048301525afa91821561073b575f926109c4575b6020935081811090821802186040519181811090821802188152f35b91506020833d6020116109f1575b816109df60209383611044565b810103126104095760209251916109a8565b3d91506109d2565b90506060813d606011610a7a575b81610a1460609383611044565b8101031261040957604051906060820182811067ffffffffffffffff821117610a6657610a5b91604091825280518452610a5060208201611337565b602085015201611337565b60408201528661093b565b634e487b7160e01b5f52604160045260245ffd5b3d9150610a07565b6060840151604051638c00bf6b60e01b8152906001600160a01b0316610aab60048301876112e6565b6001600160801b0385511660a483015260208501936001600160801b0385511660c48401526001600160801b0360408701948186511660e48601528160608901511661010486015251166101248401526020836101648160a08a01956001600160801b038751166101448301525afa92831561073b575f93610c46575b50610b8b6001600160801b0393610b85610b4f670de0b6b3a76400009487895116936113cc565b610b80671bc16d674ec80000610b6583806113cc565b046729a2241af62c0000610b7984836113cc565b04926113bf565b6113bf565b906113cc565b049282610ba3610b9a866113df565b8284511661139f565b16905281610bbc610bb3856113df565b8288511661139f565b16855251169081610bce575b506108e3565b670de0b6b3a764000091610be1916113cc565b04610bf6816001600160801b0385511661134b565b6001600160801b0383511691620f424083018093116107cc57600182018092116107cc57610c36610c3b926109716001600160801b0395610b9a946113cc565b6113df565b169052838080610bc8565b92506020833d602011610c74575b81610c6160209383611044565b8101031261040957915191610b8b610b28565b3d9150610c54565b506001600160a01b0360608501511615156108de565b506001600160801b0360408401511615156108d8565b905060c0813d60c011610d50575b81610cc360c09383611044565b81010312610409576040519060c0820182811067ffffffffffffffff821117610a6657610d459160a091604052610cf981611337565b8452610d0760208201611337565b6020850152610d1860408201611337565b6040850152610d2960608201611337565b6060850152610d3a60808201611337565b608085015201611337565b60a0820152836108b5565b3d9150610cb6565b346104095760e03660031901126104095760243567ffffffffffffffff811161040957610d899036906004016110a6565b60443560a435916001600160a01b0383168093036104095760c43567ffffffffffffffff811161040957610dc190369060040161122a565b7f0000000000000000000000000000000000000000000000000000000000000000936001600160a01b0385163303610fd8576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001603610fc95780602080610e3593518301019101611284565b60406001600160a01b038251169201916001600160a01b0383511603610fba5782610f17575b505160405163095ea7b360e01b602082019081526001600160a01b03948516602483015260448201939093525f938493921691908390610e9e816064810161033a565b51925af1610eaa611370565b90156103c6578051908115918215610efd575b505015610eee5760206040517f7f87788ea698181ea4d28d1576d0ba4fc92c0dbe5bf75b43692af2ce91dbaea28152f35b631f55ddd960e21b5f5260045ffd5b610f109250602080918301019101611358565b8180610ebd565b604051635c2bea4960e01b815290610f339060048301906112e6565b8260a48201525f60c48201523060e482015230610104820152604081610124815f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165af1801561073b5715610e5b57604090819392933d8311610fb3575b610fa48183611044565b81010312610409579083610e5b565b503d610f9a565b63effb039160e01b5f5260045ffd5b631ec6e83760e21b5f5260045ffd5b631e6a35c760e01b5f5260045ffd5b34610409575f366003190112610409576020906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b60a0810190811067ffffffffffffffff821117610a6657604052565b90601f8019910116810190811067ffffffffffffffff821117610a6657604052565b604435906001600160a01b038216820361040957565b600435906001600160a01b038216820361040957565b35906001600160a01b038216820361040957565b919091610100818403126104095760405190610100820182811067ffffffffffffffff821117610a66576040528193813583526110e560208301611092565b60208401526110f660408301611092565b6040840152606082013567ffffffffffffffff811161040957820181601f820112156104095780359067ffffffffffffffff8211610a66576040519261114260208460051b0185611044565b82845260208085019360071b8301019181831161040957602001925b8284106111a6575050505060e080926111a19260608601526080810135608086015260a081013560a086015261119660c08201611092565b60c086015201611092565b910152565b6080848303126104095760405190608082019082821067ffffffffffffffff831117610a66576080926020926040526111de87611092565b81528287013583820152604087013560408201526111fe60608801611092565b606082015281520193019261115e565b67ffffffffffffffff8111610a6657601f01601f191660200190565b81601f82011215610409578035906112418261120e565b9261124f6040519485611044565b8284526020838301011161040957815f926020809301838601378301015290565b51906001600160a01b038216820361040957565b908160a09103126104095760806040519161129e83611028565b6112a781611270565b83526112b560208201611270565b60208401526112c660408201611270565b60408401526112d760608201611270565b60608401520151608082015290565b608080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b0360608201511660608501520151910152565b51906001600160801b038216820361040957565b919082039182116107cc57565b90816020910312610409575180151581036104095790565b3d1561139a573d906113818261120e565b9161138f6040519384611044565b82523d5f602084013e565b606090565b906001600160801b03809116911601906001600160801b0382116107cc57565b919082018092116107cc57565b818102929181159184041417156107cc57565b6040516113ed604082611044565b6014815260208101907f6d61782075696e7431323820657863656564656400000000000000000000000082526001600160801b0383116114355750506001600160801b031690565b60449060405192839162461bcd60e51b8352602060048401525180918160248501528484015e5f828201840152601f01601f19168101030190fd5b811561147a570490565b634e487b7160e01b5f52601260045260245ffdfea164736f6c6343000822000a";
|
|
12
7
|
/**
|
|
13
8
|
* Computes the CREATE2 address of `owner`'s `BlueBuyCallback` for `salt`, as deployed or
|
|
14
9
|
* returned by the chain's `midnightBlueBuyCallbackFactory.createBlueBuyCallback(owner, salt)`.
|
|
15
10
|
*
|
|
16
|
-
* Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`.
|
|
11
|
+
* Use it to fill each offer's `callback` before calling `supplyBlueMakeLend`. It is the
|
|
12
|
+
* Midnight-qualified name of midnight-sdk's `getBlueBuyCallbackAddress`.
|
|
17
13
|
*
|
|
18
14
|
* @param params.chainId - Chain whose `midnightBlueBuyCallbackFactory`, `midnight` and `blue` are used.
|
|
19
15
|
* @param params.owner - Callback owner, the maker.
|
|
@@ -37,19 +33,7 @@ const blueBuyCallbackBytecode = "0x60e080604052346101265760608161161180380380916
|
|
|
37
33
|
* // `callbackFor(maker)` returns the maker's BlueBuyCallback address, deployed or not.
|
|
38
34
|
* ```
|
|
39
35
|
*/
|
|
40
|
-
const getMidnightBlueBuyCallbackAddress = (
|
|
41
|
-
opcode: "CREATE2",
|
|
42
|
-
from: (0, morpho_ts_1.getChainAddress)(chainId, "midnightBlueBuyCallbackFactory"),
|
|
43
|
-
salt,
|
|
44
|
-
bytecode: (0, viem_1.concatHex)([
|
|
45
|
-
blueBuyCallbackBytecode,
|
|
46
|
-
(0, viem_1.encodeAbiParameters)([{ type: "address" }, { type: "address" }, { type: "address" }], [
|
|
47
|
-
owner,
|
|
48
|
-
(0, morpho_ts_1.getChainAddress)(chainId, "midnight"),
|
|
49
|
-
(0, morpho_ts_1.getChainAddress)(chainId, "blue"),
|
|
50
|
-
]),
|
|
51
|
-
]),
|
|
52
|
-
});
|
|
36
|
+
const getMidnightBlueBuyCallbackAddress = (params) => (0, midnight_sdk_1.getBlueBuyCallbackAddress)(params);
|
|
53
37
|
exports.getMidnightBlueBuyCallbackAddress = getMidnightBlueBuyCallbackAddress;
|
|
54
38
|
/**
|
|
55
39
|
* Returns the `callbackData` every `supplyBlueMakeLend` offer must carry: `abi.encode(blueMarket)`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IMarketParams, Market } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import type { MidnightCollateralTransfer } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* @internal Applies Midnight bundle withdrawals to a collateral snapshot in order. Callers parse the
|
|
5
|
+
* withdrawals first, so every `collateralIndex` is configured on `market`.
|
|
6
|
+
* A maxUint256 withdrawal uses the balance left at its index by earlier withdrawals.
|
|
7
|
+
* @throws {WithdrawExceedsCollateralError} If a withdrawal exceeds the remaining balance.
|
|
8
|
+
*/
|
|
9
|
+
export declare function computeMidnightPostWithdrawalCollateral({ market, marketId, collateral, withdrawals, }: {
|
|
10
|
+
readonly market: IMarketParams;
|
|
11
|
+
readonly marketId: Market["id"];
|
|
12
|
+
readonly collateral: readonly bigint[];
|
|
13
|
+
readonly withdrawals: readonly MidnightCollateralTransfer[];
|
|
14
|
+
}): {
|
|
15
|
+
postCollateral: bigint[];
|
|
16
|
+
withdrawAmount: bigint;
|
|
17
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeMidnightPostWithdrawalCollateral = computeMidnightPostWithdrawalCollateral;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const error_js_1 = require("../types/error.js");
|
|
6
|
+
/**
|
|
7
|
+
* @internal Applies Midnight bundle withdrawals to a collateral snapshot in order. Callers parse the
|
|
8
|
+
* withdrawals first, so every `collateralIndex` is configured on `market`.
|
|
9
|
+
* A maxUint256 withdrawal uses the balance left at its index by earlier withdrawals.
|
|
10
|
+
* @throws {WithdrawExceedsCollateralError} If a withdrawal exceeds the remaining balance.
|
|
11
|
+
*/
|
|
12
|
+
function computeMidnightPostWithdrawalCollateral({ market, marketId, collateral, withdrawals, }) {
|
|
13
|
+
const postCollateral = Array.from({ length: market.collateralParams.length }, (_, index) => collateral[index] ?? 0n);
|
|
14
|
+
let withdrawAmount = 0n;
|
|
15
|
+
for (const { collateralIndex, assets } of withdrawals) {
|
|
16
|
+
const index = Number(collateralIndex);
|
|
17
|
+
const available = postCollateral[index] ?? 0n;
|
|
18
|
+
const amount = assets === viem_1.maxUint256 ? available : assets;
|
|
19
|
+
if (amount > available) {
|
|
20
|
+
throw new error_js_1.WithdrawExceedsCollateralError({
|
|
21
|
+
withdrawAmount: amount,
|
|
22
|
+
available,
|
|
23
|
+
market: marketId,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
postCollateral[index] = available - amount;
|
|
27
|
+
withdrawAmount += amount;
|
|
28
|
+
}
|
|
29
|
+
return { postCollateral, withdrawAmount };
|
|
30
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Tree, type TreeCreateRequest } from "@morpho-org/midnight-sdk";
|
|
2
2
|
import { type Address, type Hex } from "viem";
|
|
3
|
+
import type { MidnightCancelAndMakeParams } from "../types/midnightCancelAndMake.js";
|
|
3
4
|
/** Preserves maker and sell-receiver errors before the upstream tree constructor. @internal */
|
|
4
5
|
export declare const parseMidnightMakerTree: (params: {
|
|
5
6
|
readonly offers: Extract<TreeCreateRequest, {
|
|
@@ -42,3 +43,23 @@ export declare const parseMidnightMakerFundingBinding: (params: {
|
|
|
42
43
|
}) => {
|
|
43
44
|
loanToken: `0x${string}`;
|
|
44
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Rejects malformed cancellations before any maker-state read, with the bundle parser's checks
|
|
48
|
+
* and order: group hex, then each ceiling's type, bounds and duplicate, then overlap with the new
|
|
49
|
+
* tree. Used by TransactionPlan maker constructors; entity flows run these checks in the bundle
|
|
50
|
+
* parser.
|
|
51
|
+
*
|
|
52
|
+
* @param params.cancellations - Groups to cancel with their consumption ceilings.
|
|
53
|
+
* @param params.tree - Parsed offer tree whose groups the bundle publishes.
|
|
54
|
+
* @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
|
|
55
|
+
* @throws {InvalidBigIntInputError} when a `maxConsumed` ceiling is not a bigint.
|
|
56
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
|
|
57
|
+
* @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds uint128.
|
|
58
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a group is cancelled more than once.
|
|
59
|
+
* @throws {MidnightReplacementGroupCancelledError} when a cancelled group is in the new tree.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
export declare const validateMidnightMakerCancellations: (params: {
|
|
63
|
+
readonly cancellations: MidnightCancelAndMakeParams["cancellations"];
|
|
64
|
+
readonly tree: ReturnType<typeof parseMidnightMakerTree>;
|
|
65
|
+
}) => void;
|