@morpho-org/morpho-sdk 10.3.1 → 10.5.0-next.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/abis.d.ts +1 -1
- package/lib/cjs/abis.js +5 -1
- package/lib/cjs/actions/blue/common.js +12 -3
- 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/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/midnight/midnight.d.ts +100 -103
- package/lib/cjs/entities/midnight/midnight.js +99 -99
- package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/cjs/entities/vaultV2/vaultV2.js +39 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +6 -2
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -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/deadShares.js +3 -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 +60 -2
- 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/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/midnight/utils.d.ts +1 -1
- package/lib/cjs/midnight/utils.js +2 -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/withdrawBuyCallback.d.ts +101 -0
- package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.js +264 -0
- 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/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/intent.d.ts +1 -1
- 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/permit.d.ts +15 -2
- package/lib/cjs/transactionPlan/permit.js +26 -68
- package/lib/cjs/transactionPlan/plan.d.ts +99 -15
- package/lib/cjs/transactionPlan/plan.js +159 -31
- package/lib/cjs/transactionPlan/redeem.js +4 -7
- 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 +151 -3
- 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/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 +4 -1
- package/lib/cjs/types/error.js +5 -2
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/blue/common.js +13 -4
- 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/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +100 -103
- package/lib/esm/entities/midnight/midnight.js +99 -99
- package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/esm/entities/vaultV2/vaultV2.js +40 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +6 -2
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/callback.d.ts +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/deadShares.js +4 -1
- package/lib/esm/helpers/parseMidnightMaker.d.ts +21 -0
- package/lib/esm/helpers/parseMidnightMaker.js +40 -1
- package/lib/esm/helpers/validate.d.ts +60 -2
- 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/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/midnight/utils.d.ts +1 -1
- package/lib/esm/midnight/utils.js +1 -1
- 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/withdrawBuyCallback.d.ts +101 -0
- package/lib/esm/transactionPlan/blue/withdrawBuyCallback.js +259 -0
- 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/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/intent.d.ts +1 -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/permit.d.ts +15 -2
- package/lib/esm/transactionPlan/permit.js +25 -68
- package/lib/esm/transactionPlan/plan.d.ts +99 -15
- package/lib/esm/transactionPlan/plan.js +154 -27
- package/lib/esm/transactionPlan/redeem.js +5 -8
- 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 +151 -3
- 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/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 +4 -1
- package/lib/esm/types/error.js +5 -2
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareMidnightRepayWithdrawCollateral = prepareMidnightRepayWithdrawCollateral;
|
|
4
|
+
exports.buildMidnightRepayWithdrawCollateral = buildMidnightRepayWithdrawCollateral;
|
|
5
|
+
exports.validateMidnightRepayWithdrawCollateralPlanAction = validateMidnightRepayWithdrawCollateralPlanAction;
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const repayWithdrawCollateral_js_1 = require("../../actions/midnight/repayWithdrawCollateral.js");
|
|
8
|
+
const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
|
|
9
|
+
const assertContractCode_js_1 = require("../../entities/requirements/assertContractCode.js");
|
|
10
|
+
const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
|
|
11
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
12
|
+
const index_js_1 = require("../../types/index.js");
|
|
13
|
+
const error_js_1 = require("../error.js");
|
|
14
|
+
const intent_js_1 = require("../intent.js");
|
|
15
|
+
const requirements_js_1 = require("../requirements.js");
|
|
16
|
+
const validation_js_1 = require("../validation.js");
|
|
17
|
+
const authorization_js_1 = require("./authorization.js");
|
|
18
|
+
const market_js_1 = require("./market.js");
|
|
19
|
+
const validation_js_2 = require("./validation.js");
|
|
20
|
+
const actionId = "midnightRepayWithdrawCollateral";
|
|
21
|
+
/**
|
|
22
|
+
* Prepares a direct Midnight repayment with no offer fills or referral fee. Use an assets
|
|
23
|
+
* target for an exact repayment (`0n` for collateral-only), or full repayment with a finite
|
|
24
|
+
* asset cap. Inputs go through the same parse-once constructor and position checks as the
|
|
25
|
+
* entity `repayWithdrawCollateral`, in the same order: the position is bound to the sender and
|
|
26
|
+
* market, then withdrawals, debt and buffered health are checked against the snapshot.
|
|
27
|
+
* Restoring and building offline does not refresh those checks; simulate against current
|
|
28
|
+
* state before sending.
|
|
29
|
+
*
|
|
30
|
+
* If allowance is below the full pull bound, the plan requests a standalone ERC-20 approval
|
|
31
|
+
* to MidnightBundlesV2 for `maxUint256`, subject to `MAX_TOKEN_APPROVALS`, even with native
|
|
32
|
+
* funding. The approval does not expire with the plan. Withdrawal-only plans do not read
|
|
33
|
+
* allowance. In a full repayment, any native funding above the debt paid stays in the
|
|
34
|
+
* sender's wallet as wrapped native, not as an ETH refund.
|
|
35
|
+
* The plan adds a standalone bundle authorization if needed and never requests signatures.
|
|
36
|
+
* The bundle enforces the plan expiry, which defaults to two hours after the reference time.
|
|
37
|
+
* @param client - Viem client used to check the network and deployments and read prerequisites.
|
|
38
|
+
* @param params - Repayment, market and position snapshots, and optional withdrawals and funding.
|
|
39
|
+
* @param params.chainId - EIP-155 chain ID of the market and submitting client.
|
|
40
|
+
* @param params.account - Nonzero position owner who funds and sends the transactions.
|
|
41
|
+
* @param params.repay - Use `{ type: "assets", assets }` for an exact amount (`0n` only withdraws)
|
|
42
|
+
* or `{ type: "full", maxBuyerAssets }` for full repayment. Both amounts are in the loan
|
|
43
|
+
* token's smallest units and must be below `maxUint256`. The full cap must be positive
|
|
44
|
+
* and cover all debt at execution, or the bundle reverts.
|
|
45
|
+
* @param params.nativeAmount - ETH in wei sent as transaction value for a wrapped-native loan,
|
|
46
|
+
* up to the exact repayment amount or full repayment cap. Omit it or set it to `0n` for no ETH funding.
|
|
47
|
+
* @param params.marketData - Hydrated market snapshot from the same block as `positionData`.
|
|
48
|
+
* @param params.positionData - Position snapshot for the same market, owned by `account`.
|
|
49
|
+
* @param params.collateralPrices - Raw `price()` values from each collateral oracle at the snapshot
|
|
50
|
+
* block, indexed like `positionData.collateral` and scaled by `ORACLE_PRICE_SCALE` (1e36). Not
|
|
51
|
+
* needed without withdrawals or when the repayment leaves no snapshot debt.
|
|
52
|
+
* @param params.collateralWithdrawals - Optional withdrawals; defaults to none. Each
|
|
53
|
+
* `collateralIndex` indexes `marketData.params.collateralParams`, and `assets` is in that
|
|
54
|
+
* token's smallest units, with `maxUint256` withdrawing the remaining balance at execution.
|
|
55
|
+
* @param params.collateralReceiver - Optional recipient of withdrawn collateral; defaults to
|
|
56
|
+
* `account`. With withdrawals it must be nonzero and not a blocked Midnight protocol or market
|
|
57
|
+
* token contract.
|
|
58
|
+
* @param params.now - Reference time in Unix seconds, normally the latest block's timestamp.
|
|
59
|
+
* omitting it uses the device clock (an untyped JavaScript `null` does too); that fallback is deprecated.
|
|
60
|
+
* @param params.expiresAt - Bundle execution deadline in Unix seconds. Defaults to two hours after `now`.
|
|
61
|
+
* @param params.calldataOrigin - Optional attribution bytes (at most 1 MiB) appended to each operation transaction's calldata; approval and authorization steps carry none.
|
|
62
|
+
* @returns A frozen plan with prerequisite calls first and no signature requests.
|
|
63
|
+
* @throws {InvalidBigIntInputError} If a supplied non-null `now`, the active repayment amount or a withdrawal's `collateralIndex` or `assets` is not a bigint; checked before any request.
|
|
64
|
+
* @throws {MarketIdMismatchError} If the position belongs to another market.
|
|
65
|
+
* @throws {AccrualPositionUserMismatchError} If the position is owned by another account.
|
|
66
|
+
* @throws {MidnightRepayExceedsDebtError} If an exact repayment exceeds the snapshot debt.
|
|
67
|
+
* @throws {MidnightTakeTargetUnreachableError} If the full repayment cap is below the snapshot debt.
|
|
68
|
+
* @throws {WithdrawExceedsCollateralError} If a withdrawal exceeds the supplied collateral balance.
|
|
69
|
+
* @throws {WithdrawMakesPositionUnhealthyError} If remaining debt exceeds buffered collateral capacity.
|
|
70
|
+
* @throws {MissingMarketPriceError} If remaining collateral has no price for the health check.
|
|
71
|
+
* @throws {UnknownCollateralIndexError} If a withdrawal targets an unconfigured index.
|
|
72
|
+
* @throws {MidnightZeroReceiverError} If withdrawn collateral is sent to the zero address.
|
|
73
|
+
* @throws {MidnightContractReceiverError} If withdrawn collateral is sent to a blocked contract.
|
|
74
|
+
* @throws {ChainIdMismatchError} If the market, configured client or transport is on another chain.
|
|
75
|
+
* @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
|
|
76
|
+
* @throws {InvalidMarketParameterError} If the market configuration is invalid.
|
|
77
|
+
* @throws {MissingContractCodeError} If the registered bundle or Midnight core has no code.
|
|
78
|
+
* @throws {viem.BaseError} If a chain, bytecode, allowance or authorization read fails.
|
|
79
|
+
* @throws {UnsupportedChainIdError} If the chain is not registered.
|
|
80
|
+
* @throws {UnknownAddressError} If a Midnight deployment is not registered on that chain.
|
|
81
|
+
* @throws {ChainWNativeMissingError} If native funding is requested without a registered wrapped-native token.
|
|
82
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If native funding is requested for a different loan token.
|
|
83
|
+
* @throws {InputExceedsMaxError} If an amount exceeds its encoding bound or native funding exceeds the pull.
|
|
84
|
+
* @throws {NegativeInputError} If the exact repayment amount or native funding is negative.
|
|
85
|
+
* @throws {InvalidMidnightNativeAmountTypeError} If `nativeAmount` is not a bigint.
|
|
86
|
+
* @throws {NonPositiveInputError} If there is neither repayment nor withdrawal, the cap or a withdrawal is nonpositive, or expiry is nonpositive.
|
|
87
|
+
* @throws {ZeroAccountError} If the sender is the zero address.
|
|
88
|
+
* @throws {NonIntegerInputError} If expiry is not a safe integer.
|
|
89
|
+
* @throws {ExpiredDeadlineError} If expiry is at or before the reference time.
|
|
90
|
+
* @throws {InvalidCalldataOriginError} If attribution bytes are empty or malformed.
|
|
91
|
+
* @throws {InvalidTransactionPlanError} If the sender address or attribution length is invalid, `repay` is not an object, or its type is unsupported.
|
|
92
|
+
* @throws {MidnightCalldataEncodingError} If a market, position owner or receiver address is malformed, or calldata cannot be encoded.
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { buildTransactions, prepareMidnightRepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
96
|
+
* import { fetchMidnightAccrualPosition } from "@morpho-org/morpho-sdk/fetch";
|
|
97
|
+
* import { type Address, type Hash, createPublicClient, http, maxUint256 } from "viem";
|
|
98
|
+
* import { base } from "viem/chains";
|
|
99
|
+
*
|
|
100
|
+
* async function prepareClose(account: Address, marketId: Hash, maxBuyerAssets: bigint) {
|
|
101
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
102
|
+
* const block = await client.getBlock();
|
|
103
|
+
* const positionData = await fetchMidnightAccrualPosition(client, {
|
|
104
|
+
* marketId, user: account, blockNumber: block.number,
|
|
105
|
+
* });
|
|
106
|
+
* const plan = await prepareMidnightRepayWithdrawCollateral(client, {
|
|
107
|
+
* chainId: base.id, account, marketData: positionData.market, positionData,
|
|
108
|
+
* collateralPrices: [], // No price check is needed for full repayment.
|
|
109
|
+
* now: block.timestamp,
|
|
110
|
+
* repay: { type: "full", maxBuyerAssets },
|
|
111
|
+
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
112
|
+
* });
|
|
113
|
+
* // Simulate, then send in order from plan.account on plan.chainId.
|
|
114
|
+
* return buildTransactions(plan);
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
118
|
+
*/
|
|
119
|
+
async function prepareMidnightRepayWithdrawCollateral(client, params) {
|
|
120
|
+
const { chainId, account, marketData, positionData, nativeAmount } = params;
|
|
121
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
122
|
+
// Reject a non-bigint clock before the default expiry sum can concatenate strings.
|
|
123
|
+
(0, validate_js_1.validateReferenceTime)(now);
|
|
124
|
+
const intent = (0, intent_js_1.resolveIntent)({
|
|
125
|
+
chainId,
|
|
126
|
+
account,
|
|
127
|
+
expiresAt: params.expiresAt,
|
|
128
|
+
calldataOrigin: params.calldataOrigin,
|
|
129
|
+
}, now);
|
|
130
|
+
// Throws before reading repay.type when a JS caller omits repay or passes a non-object.
|
|
131
|
+
(0, validation_js_1.getPlanObject)(params.repay, "$.repay");
|
|
132
|
+
if (params.repay.type !== "assets" && params.repay.type !== "full") {
|
|
133
|
+
throw invalidRepayType("$.repay");
|
|
134
|
+
}
|
|
135
|
+
const [repayField, repayAmount] = params.repay.type === "assets"
|
|
136
|
+
? ["assets", params.repay.assets]
|
|
137
|
+
: ["maxBuyerAssets", params.repay.maxBuyerAssets];
|
|
138
|
+
if (typeof repayAmount !== "bigint") {
|
|
139
|
+
throw new index_js_1.InvalidBigIntInputError(`repay.${repayField}`, repayAmount);
|
|
140
|
+
}
|
|
141
|
+
const collateralWithdrawals = params.collateralWithdrawals ?? [];
|
|
142
|
+
(0, market_js_1.validateCollateralIndexTypes)("collateralWithdrawals", collateralWithdrawals);
|
|
143
|
+
for (const [index, { assets }] of collateralWithdrawals.entries()) {
|
|
144
|
+
if (typeof assets !== "bigint") {
|
|
145
|
+
throw new index_js_1.InvalidBigIntInputError(`collateralWithdrawals[${index}].assets`, assets);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const parsed = (0, repayWithdrawCollateral_js_1.parseMidnightRepayWithdrawCollateral)({
|
|
149
|
+
chainId,
|
|
150
|
+
market: marketData.params,
|
|
151
|
+
repay: params.repay,
|
|
152
|
+
nativeAmount,
|
|
153
|
+
collateralWithdrawals,
|
|
154
|
+
collateralReceiver: params.collateralReceiver ?? account,
|
|
155
|
+
deadline: intent.deadline,
|
|
156
|
+
});
|
|
157
|
+
(0, parseMidnight_js_1.validateMidnightPositionBinding)({
|
|
158
|
+
positionData,
|
|
159
|
+
accountAddress: account,
|
|
160
|
+
marketData,
|
|
161
|
+
});
|
|
162
|
+
(0, validate_js_1.validateMidnightRepayWithdrawCollateralPosition)({
|
|
163
|
+
marketData,
|
|
164
|
+
positionData,
|
|
165
|
+
collateralPrices: params.collateralPrices,
|
|
166
|
+
repay: parsed.repay,
|
|
167
|
+
collateralWithdrawals: parsed.collateralWithdrawals,
|
|
168
|
+
});
|
|
169
|
+
const chainCheck = (0, chainCheck_js_1.createChainCheck)(client, chainId);
|
|
170
|
+
await chainCheck();
|
|
171
|
+
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "midnightBundlesV2");
|
|
172
|
+
// Check deployments before an allowance or authorization read can fail decoding empty data.
|
|
173
|
+
await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
174
|
+
{ role: "midnightBundlesV2", address: spender },
|
|
175
|
+
{ role: "midnight", address: (0, morpho_ts_1.getChainAddress)(chainId, "midnight") },
|
|
176
|
+
], chainCheck);
|
|
177
|
+
const { repay, market } = parsed;
|
|
178
|
+
const amount = repay.type === "assets" ? repay.assets : repay.maxBuyerAssets;
|
|
179
|
+
const [{ approvals }, authorization] = await Promise.all([
|
|
180
|
+
amount === 0n
|
|
181
|
+
? { approvals: [] }
|
|
182
|
+
: (0, requirements_js_1.getTokenRequirements)(client, {
|
|
183
|
+
chainId,
|
|
184
|
+
token: market.struct.loanToken,
|
|
185
|
+
owner: account,
|
|
186
|
+
spender,
|
|
187
|
+
amount,
|
|
188
|
+
approvalId: (index) => `${actionId}:approval:${index}`,
|
|
189
|
+
}),
|
|
190
|
+
(0, authorization_js_1.prepareMidnightBundleAuthorization)(client, { chainId, account }),
|
|
191
|
+
]);
|
|
192
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
193
|
+
version: 2,
|
|
194
|
+
chainId,
|
|
195
|
+
account,
|
|
196
|
+
expiresAt: intent.expiresAt,
|
|
197
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
198
|
+
steps: [
|
|
199
|
+
...approvals,
|
|
200
|
+
...(authorization === undefined ? [] : [authorization]),
|
|
201
|
+
{
|
|
202
|
+
id: actionId,
|
|
203
|
+
label: "Repay Midnight debt or withdraw collateral",
|
|
204
|
+
action: {
|
|
205
|
+
type: actionId,
|
|
206
|
+
inputs: {
|
|
207
|
+
chainId,
|
|
208
|
+
account,
|
|
209
|
+
market: market.struct,
|
|
210
|
+
repay,
|
|
211
|
+
...(nativeAmount !== undefined && {
|
|
212
|
+
nativeAssets: parsed.nativeFunding.value,
|
|
213
|
+
}),
|
|
214
|
+
collateralWithdrawals: parsed.collateralWithdrawals,
|
|
215
|
+
collateralReceiver: parsed.collateralReceiver,
|
|
216
|
+
deadline: parsed.deadline,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
signatureRequests: [],
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function invalidRepayType(path) {
|
|
225
|
+
return new error_js_1.InvalidTransactionPlanError({
|
|
226
|
+
path: `${path}.type`,
|
|
227
|
+
reason: "expected assets or full",
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function storedRepay(repay) {
|
|
231
|
+
// Throws before reading repay.type when a directly built step omits repay.
|
|
232
|
+
(0, validation_js_1.getPlanObject)(repay, "$.repay");
|
|
233
|
+
switch (repay.type) {
|
|
234
|
+
case "assets":
|
|
235
|
+
return { type: "assets", assets: repay.assets };
|
|
236
|
+
case "full":
|
|
237
|
+
return { type: "full", maxBuyerAssets: repay.maxBuyerAssets };
|
|
238
|
+
default:
|
|
239
|
+
throw invalidRepayType("$.repay");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @internal Encodes only the persisted inputs; no position, client or clock is needed.
|
|
244
|
+
* @throws {InvalidTransactionPlanError} If `repay` is not an object or its type is unsupported.
|
|
245
|
+
* @throws {NegativeInputError} If the exact asset amount or native funding is negative.
|
|
246
|
+
* @throws {NonPositiveInputError} If the full repayment cap, a withdrawal amount or the deadline is nonpositive, or the step neither repays nor withdraws.
|
|
247
|
+
* @throws {InputExceedsMaxError} If `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`, a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
|
|
248
|
+
* @throws {ChainIdMismatchError} If the market targets another chain.
|
|
249
|
+
* @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
|
|
250
|
+
* @throws {InvalidMarketParameterError} If the market configuration is invalid.
|
|
251
|
+
* @throws {UnknownCollateralIndexError} If a withdrawal targets an index not configured on the market.
|
|
252
|
+
* @throws {MidnightZeroReceiverError} If a collateral withdrawal names the zero address as its receiver.
|
|
253
|
+
* @throws {MidnightContractReceiverError} If a collateral withdrawal names a blocked protocol or token contract as its receiver.
|
|
254
|
+
* @throws {MidnightCalldataEncodingError} If an address is malformed or an input cannot be ABI-encoded.
|
|
255
|
+
* @throws {ChainWNativeMissingError} If native funding targets a chain without wNative.
|
|
256
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If native funding targets a loan token other than wNative.
|
|
257
|
+
* @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
|
|
258
|
+
* @throws {UnknownAddressError} If Midnight or MidnightBundlesV2 is not registered on the chain.
|
|
259
|
+
*/
|
|
260
|
+
function buildMidnightRepayWithdrawCollateral({ inputs }) {
|
|
261
|
+
(0, market_js_1.validateStoredCollateralOrder)(inputs.market.collateralParams, "$.inputs.market.collateralParams");
|
|
262
|
+
return (0, repayWithdrawCollateral_js_1.midnightRepayWithdrawCollateral)({
|
|
263
|
+
chainId: inputs.chainId,
|
|
264
|
+
market: (0, market_js_1.storedMarketTuple)(inputs.market),
|
|
265
|
+
repay: storedRepay(inputs.repay),
|
|
266
|
+
nativeAmount: inputs.nativeAssets,
|
|
267
|
+
collateralWithdrawals: inputs.collateralWithdrawals,
|
|
268
|
+
collateralReceiver: inputs.collateralReceiver,
|
|
269
|
+
deadline: inputs.deadline,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* @internal Validates the format of a stored repayment recipe without reading live state.
|
|
274
|
+
* @throws {InvalidTransactionPlanError} If the recipe has invalid fields or signature references.
|
|
275
|
+
*/
|
|
276
|
+
function validateMidnightRepayWithdrawCollateralPlanAction(action, path) {
|
|
277
|
+
const inputsPath = `${path}.inputs`;
|
|
278
|
+
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, inputsPath);
|
|
279
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
280
|
+
path: inputsPath,
|
|
281
|
+
fields: {
|
|
282
|
+
collateralReceiver: "address",
|
|
283
|
+
deadline: "uint256 bigint",
|
|
284
|
+
...(inputs.nativeAssets !== undefined && {
|
|
285
|
+
nativeAssets: "uint256 bigint",
|
|
286
|
+
}),
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
const repayPath = `${inputsPath}.repay`;
|
|
290
|
+
const repay = (0, validation_js_1.getPlanObject)(inputs.repay, repayPath);
|
|
291
|
+
switch (repay.type) {
|
|
292
|
+
case "assets":
|
|
293
|
+
(0, validation_js_1.validatePlanFields)(repay, {
|
|
294
|
+
path: repayPath,
|
|
295
|
+
fields: { assets: "uint256 bigint" },
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
case "full":
|
|
299
|
+
(0, validation_js_1.validatePlanFields)(repay, {
|
|
300
|
+
path: repayPath,
|
|
301
|
+
fields: { maxBuyerAssets: "uint256 bigint" },
|
|
302
|
+
});
|
|
303
|
+
break;
|
|
304
|
+
default:
|
|
305
|
+
throw invalidRepayType(repayPath);
|
|
306
|
+
}
|
|
307
|
+
const withdrawalsPath = `${inputsPath}.collateralWithdrawals`;
|
|
308
|
+
if (!Array.isArray(inputs.collateralWithdrawals)) {
|
|
309
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
310
|
+
path: withdrawalsPath,
|
|
311
|
+
reason: "expected an array",
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
for (const [index, withdrawal] of inputs.collateralWithdrawals.entries()) {
|
|
315
|
+
const itemPath = `${withdrawalsPath}[${index}]`;
|
|
316
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(withdrawal, itemPath), {
|
|
317
|
+
path: itemPath,
|
|
318
|
+
fields: { collateralIndex: "uint256 bigint", assets: "uint256 bigint" },
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
(0, validation_js_2.validateStoredMidnightMarket)(inputs.market, {
|
|
322
|
+
path: `${inputsPath}.market`,
|
|
323
|
+
chainId: inputs.chainId, // Checked by the parse dispatcher.
|
|
324
|
+
});
|
|
325
|
+
(0, market_js_1.validateStoredCollateralOrder)(inputs.market.collateralParams, `${inputsPath}.market.collateralParams`);
|
|
326
|
+
// Reject any stored signature-reference field; this action never consumes signatures.
|
|
327
|
+
(0, authorization_js_1.validateSignaturelessMidnightAction)(action, path);
|
|
328
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { InputMarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client, Hex } from "viem";
|
|
3
|
+
import type { TransactionPlan } from "../types.js";
|
|
4
|
+
import { type MidnightMakerPublicationPlanParams } from "./makerPublication.js";
|
|
5
|
+
/**
|
|
6
|
+
* Inputs for supplying Blue liquidity to a maker's callback and publishing Midnight lend offers.
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
*/
|
|
9
|
+
export interface MidnightSupplyBlueMakeLendPlanParams extends MidnightMakerPublicationPlanParams {
|
|
10
|
+
/** Blue market with the same loan token as every Midnight offer market. */
|
|
11
|
+
readonly blueMarket: InputMarketParams;
|
|
12
|
+
/** Positive loan assets to park for the callback. */
|
|
13
|
+
readonly assetsToPark: bigint;
|
|
14
|
+
/** 32-byte salt that selects the submitting maker's BlueBuyCallback. */
|
|
15
|
+
readonly callbackSalt: Hex;
|
|
16
|
+
/** Native ETH in wei, allowed only for wrapped-native loan tokens and capped at the parking amount. */
|
|
17
|
+
readonly nativeAmount?: bigint;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Prepares an atomic Blue supply to the maker's BlueBuyCallback and activation of a Price V1
|
|
21
|
+
* or Rate V1 Midnight lend-offer root, without filling any offer. Builds the offer tree and checks
|
|
22
|
+
* the offer-capped `expiresAt` first, then runs the entity `supplyBlueMakeLend` checks through a
|
|
23
|
+
* plan-side constructor, so an input with several errors can fail on another error here than in
|
|
24
|
+
* the entity. The input, tree, cancellation, deadline and binding checks run before any RPC read or
|
|
25
|
+
* mempool API call; payload encoding, which also checks market maturity, runs after the reads. The
|
|
26
|
+
* chain and the bundle, Midnight, ratifier, Blue and callback-factory code are checked once, right
|
|
27
|
+
* before the publication-state reads. The share preview reads the Blue market at the block the
|
|
28
|
+
* publication-state reads are pinned to; the transaction does not enforce a minimum share amount. Allowance to MidnightBundlesV2 is checked against the
|
|
29
|
+
* full parking amount, even when native ETH funds part of it; when it falls short, the plan
|
|
30
|
+
* approves `maxUint256` (capped by the SDK). This route needs no direct Midnight token approval
|
|
31
|
+
* and no signature request. Publishing authorizes the selected PriceRatifierV1 or RateRatifierV1 on
|
|
32
|
+
* the maker's Midnight account; that authorization remains until revoked, even after the plan's
|
|
33
|
+
* deadline. Standalone approvals and operator authorization can remain even if publication fails.
|
|
34
|
+
*
|
|
35
|
+
* @param client - Plain viem client for chain, deployment, market and prerequisite reads.
|
|
36
|
+
* @param params - Maker's offer tree or creation request, Blue market, salt and funding.
|
|
37
|
+
* @param params.chainId - Chain containing Midnight, MidnightBundlesV2, Blue and the selected ratifier.
|
|
38
|
+
* @param params.account - Non-zero maker that funds the parking supply, owns the callback, names itself on every offer and sends the plan.
|
|
39
|
+
* @param params.offers - Caller-supplied buy-offer tree routed through the callback, or a PriceRatifierV1 or RateRatifierV1 tree creation request.
|
|
40
|
+
* @param params.validation - Optional mempool API request controls; `false` skips the API call.
|
|
41
|
+
* @param params.validation.apiUrl - Optional Midnight API URL; defaults to `https://api.morpho.org/v0/midnight`.
|
|
42
|
+
* @param params.validation.timestamp - Optional ISO-8601 timestamp or `Date` selecting the API policy snapshot.
|
|
43
|
+
* @param params.validation.fetch - Optional fetch implementation for the API call; defaults to the global `fetch`.
|
|
44
|
+
* @param params.validation.request - Optional fetch options forwarded to the API request.
|
|
45
|
+
* @param params.cancellations - Optional groups and consumed ceilings to cancel atomically with publication; must not overlap the new tree.
|
|
46
|
+
* Omitting it cancels nothing (an untyped JavaScript `null` does too).
|
|
47
|
+
* @param params.blueMarket - Blue market with the same loan token as every Midnight offer market.
|
|
48
|
+
* @param params.blueMarket.loanToken - Blue loan token; must match every Midnight offer's loan token.
|
|
49
|
+
* @param params.blueMarket.collateralToken - Blue market collateral token.
|
|
50
|
+
* @param params.blueMarket.oracle - Blue market oracle.
|
|
51
|
+
* @param params.blueMarket.irm - Blue market interest rate model.
|
|
52
|
+
* @param params.blueMarket.lltv - Blue market liquidation LTV, scaled by WAD.
|
|
53
|
+
* @param params.assetsToPark - Positive loan assets supplied to Blue for the callback.
|
|
54
|
+
* @param params.callbackSalt - 32-byte salt that selects the maker's BlueBuyCallback.
|
|
55
|
+
* @param params.nativeAmount - Optional native ETH in wei, allowed only for a wrapped-native loan token and capped at the parking amount.
|
|
56
|
+
* @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
|
|
57
|
+
* The share preview uses the pinned block's timestamp instead.
|
|
58
|
+
* @param params.expiresAt - Unix seconds. Defaults to the earlier of now + 2 hours and one second before the first offer expiry.
|
|
59
|
+
* @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
|
|
60
|
+
* @returns A frozen plan with opaque publication bytes, buildable without the tree or API.
|
|
61
|
+
* @throws {InvalidBigIntInputError} If a supplied non-null `now` is not a bigint; checked first.
|
|
62
|
+
* @throws {ZeroAccountError} If the submitting account is zero.
|
|
63
|
+
* @throws {InvalidTransactionPlanError} If the account is not an address or calldata origin exceeds 1 MiB.
|
|
64
|
+
* @throws {InvalidCalldataOriginError} If the supplied calldata origin is not nonempty, even-length hex.
|
|
65
|
+
* @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
|
|
66
|
+
* @throws {InvalidTreeError} If the offer tree is empty or invalid.
|
|
67
|
+
* @throws {InvalidTreeHeightError} If the tree exceeds the maximum height.
|
|
68
|
+
* @throws {InvalidMidnightOfferGroupError} If a tree request uses an invalid explicit group.
|
|
69
|
+
* @throws {InvalidMidnightRateRatifierV1RateError} If a Rate V1 request has a negative leaf rate.
|
|
70
|
+
* @throws {InvalidMidnightRateRatifierV1TickError} If a Rate V1 request uses a tick below its minimum.
|
|
71
|
+
* @throws {MidnightOfferMakerMismatchError} If an offer names another maker.
|
|
72
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} If a tree creation request has a sell leaf for the
|
|
73
|
+
* maker with a zero `receiverIfMakerIsSeller`; checked while the tree is built, before the side check.
|
|
74
|
+
* @throws {InvalidBigIntInputError} If `assetsToPark`, `blueMarket.lltv` or a cancellation ceiling is not a
|
|
75
|
+
* bigint; checked after the tree is built and before any request.
|
|
76
|
+
* @throws {InvalidTransactionPlanError} If a supplied non-null `cancellations` is not an array or has a
|
|
77
|
+
* non-object entry; checked after the tree is built and before any request.
|
|
78
|
+
* @throws {MidnightOfferSideMismatchError} If an offer is not a buy offer.
|
|
79
|
+
* @throws {MidnightOfferReduceOnlyError} If an offer is reduce-only.
|
|
80
|
+
* @throws {MidnightOfferMarketLoanTokenMismatchError} If an offer names a different loan token.
|
|
81
|
+
* @throws {MidnightOfferCallbackMismatchError} If an offer targets a different callback.
|
|
82
|
+
* @throws {MidnightOfferCallbackDataMismatchError} If an offer does not encode the selected Blue market.
|
|
83
|
+
* @throws {InvalidMidnightHexInputError} If the salt or a cancellation group is not bytes32.
|
|
84
|
+
* @throws {DuplicateMidnightGroupCancellationError} If a cancellation group appears twice.
|
|
85
|
+
* @throws {MidnightReplacementGroupCancelledError} If a cancelled group overlaps the new tree.
|
|
86
|
+
* @throws {NonPositiveInputError} If the parking amount or explicit expiry is not positive.
|
|
87
|
+
* @throws {NegativeInputError} If native funding or a cancellation ceiling is negative.
|
|
88
|
+
* @throws {InputExceedsMaxError} If the parking amount or a cancellation ceiling exceeds uint128, native funding exceeds the parking amount, or explicit expiry reaches the first offer expiry while every offer is still live at the reference time.
|
|
89
|
+
* @throws {InvalidMidnightNativeAmountTypeError} If `nativeAmount` is not a bigint.
|
|
90
|
+
* @throws {ChainWNativeMissingError} If native funding is requested on a chain without registered wrapped native.
|
|
91
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If native funding is requested for another loan token.
|
|
92
|
+
* @throws {MidnightCalldataEncodingError} If the offer tree, Blue market or bundle input cannot be ABI-encoded.
|
|
93
|
+
* @throws {ExpiredDeadlineError} If the resolved deadline is at or before the reference time or
|
|
94
|
+
* pinned block timestamp, or an offer has expired by the reference time but not at the pinned
|
|
95
|
+
* block; this skips API validation.
|
|
96
|
+
* @throws {ChainIdMismatchError} If the configured or transport chain differs from the requested chain.
|
|
97
|
+
* @throws {UnsupportedChainIdError} If the chain has no address registry.
|
|
98
|
+
* @throws {UnknownAddressError} If Midnight, the bundle, Blue, the callback factory or the selected ratifier is not registered on the chain.
|
|
99
|
+
* @throws {MissingContractCodeError} If a required registered deployment has no code.
|
|
100
|
+
* @throws {MidnightOfferExpiredError} If an offer is already expired at the pinned block timestamp.
|
|
101
|
+
* @throws {MidnightOfferExpiryAfterMaturityError} If an offer expiry exceeds its market maturity.
|
|
102
|
+
* @throws {MidnightOfferGroupConsumedError} If an offer group has no capacity remaining.
|
|
103
|
+
* @throws {MidnightOfferTickSpacingError} If an offer tick is not accessible in its market.
|
|
104
|
+
* @throws {MidnightOfferContinuousFeeCapError} If an offer sets a nonzero continuous fee cap.
|
|
105
|
+
* @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} If the market fee exceeds an offer's cap.
|
|
106
|
+
* @throws {MidnightOfferRateBoundUnreachableError} If a Rate V1 offer cannot satisfy its rate bound.
|
|
107
|
+
* @throws {MidnightMarketMaturityTooFarError} If an uncreated market matures more than 100 years after an offer's expiry.
|
|
108
|
+
* @throws {MidnightMarketLltvNotEnabledError} If an uncreated market uses a disabled LLTV.
|
|
109
|
+
* @throws {MidnightMarketLiquidationCursorNotEnabledError} If an uncreated market uses a disabled liquidation cursor.
|
|
110
|
+
* @throws {MidnightMarketOracleWithoutCodeError} If an uncreated market's oracle has no code.
|
|
111
|
+
* @throws {MidnightOfferMarketChainMismatchError} If an offer's market uses another chain.
|
|
112
|
+
* @throws {MidnightOfferMarketAddressMismatchError} If an offer's market names another Midnight deployment.
|
|
113
|
+
* @throws {MidnightOfferRatifierMismatchError} If an offer names the wrong ratifier for its tree.
|
|
114
|
+
* @throws {MidnightPayloadDecodeError} If the offers cannot be encoded in the publication payload,
|
|
115
|
+
* including when the encoded payload exceeds its size limit; split the offer tree.
|
|
116
|
+
* @throws {MidnightMempoolValidationError} If optional mempool validation rejects the tree.
|
|
117
|
+
* @throws {MidnightApiError} If API validation returns a non-2xx response.
|
|
118
|
+
* @throws {InvalidMidnightApiResponseError} If the API returns malformed successful validation data.
|
|
119
|
+
* @throws {BlueMarketParamsIdMismatchError} If the Blue market read returns a nonzero market tuple whose ID differs from `blueMarket`.
|
|
120
|
+
* @throws {EmptyBlueParkingMarketError} If the Blue market has no supply shares.
|
|
121
|
+
* @throws {ZeroBlueParkingSharesError} If the parking amount would mint zero shares.
|
|
122
|
+
* @throws {viem.BaseError} If a chain, deployment, offer-state, Blue market, allowance or authorization read fails.
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* import {
|
|
126
|
+
* buildTransactions, getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData,
|
|
127
|
+
* prepareMidnightSupplyBlueMakeLend, type MidnightSupplyBlueMakeLendPlanParams,
|
|
128
|
+
* } from "@morpho-org/morpho-sdk";
|
|
129
|
+
* import { type Offer, Tree } from "@morpho-org/morpho-sdk/midnight/entities";
|
|
130
|
+
* import { createPublicClient, http } from "viem";
|
|
131
|
+
* import { base } from "viem/chains";
|
|
132
|
+
*
|
|
133
|
+
* async function buildBlueBackedLend(
|
|
134
|
+
* inputs: Pick<MidnightSupplyBlueMakeLendPlanParams, "account" | "blueMarket" | "callbackSalt">,
|
|
135
|
+
* createBuyOffers: (route: Pick<Offer, "callback" | "callbackData">) => readonly Offer[],
|
|
136
|
+
* ) {
|
|
137
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
138
|
+
* // The maker's strategy creates buy offers naming the Base PriceRatifierV1 and this route.
|
|
139
|
+
* const offers = Tree.create({ type: "priceV1", entries: createBuyOffers({
|
|
140
|
+
* callback: getMidnightBlueBuyCallbackAddress({
|
|
141
|
+
* chainId: base.id, owner: inputs.account, salt: inputs.callbackSalt,
|
|
142
|
+
* }),
|
|
143
|
+
* callbackData: getMidnightBlueBuyCallbackData(inputs.blueMarket),
|
|
144
|
+
* }).map(offer => ({ offer })) });
|
|
145
|
+
* const plan = await prepareMidnightSupplyBlueMakeLend(client, {
|
|
146
|
+
* ...inputs, chainId: base.id, offers, assetsToPark: 1_000_000n,
|
|
147
|
+
* now: (await client.getBlock()).timestamp,
|
|
148
|
+
* });
|
|
149
|
+
* // Simulate and send the transactions in order from inputs.account.
|
|
150
|
+
* return buildTransactions(plan);
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
154
|
+
*/
|
|
155
|
+
export declare function prepareMidnightSupplyBlueMakeLend(client: Client, params: MidnightSupplyBlueMakeLendPlanParams): Promise<TransactionPlan>;
|