@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,104 @@
|
|
|
1
|
+
import type { Client } from "viem";
|
|
2
|
+
import type { TransactionPlan } from "../types.js";
|
|
3
|
+
import { type MidnightMakerPublicationPlanParams } from "./makerPublication.js";
|
|
4
|
+
/**
|
|
5
|
+
* Inputs for publishing resting Midnight borrow offers without supplying collateral.
|
|
6
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
7
|
+
*/
|
|
8
|
+
export type MidnightMakeBorrowPlanParams = MidnightMakerPublicationPlanParams;
|
|
9
|
+
/**
|
|
10
|
+
* Prepares a PriceRatifierV1 or RateRatifierV1 sell-offer publication for the submitting maker.
|
|
11
|
+
* The bundle activates the root and optionally cancels old groups; it does not supply collateral
|
|
12
|
+
* or create debt. No ERC-20 approval or root signature is needed. The standalone bundle grant
|
|
13
|
+
* (if needed) and the ratifier authorization made by the bundle persist until revoked.
|
|
14
|
+
* The bundle accepts execution at its deadline, so the deadline must be strictly before every offer expiry.
|
|
15
|
+
* Builds the offer tree and checks the offer-capped `expiresAt` first, then validates the
|
|
16
|
+
* publication with a plan-side copy of the entity `makeBorrow` constructor, in its order, except
|
|
17
|
+
* that malformed cancellations are rejected before any state read, and a deadline already reached
|
|
18
|
+
* at the pinned block is rejected before the mempool API call. So an input with several errors can fail on the tree or expiry here where the entity reports another
|
|
19
|
+
* error first. The chain and the bundle, Midnight and ratifier code are checked once, right before
|
|
20
|
+
* the first publication-state read.
|
|
21
|
+
* @param client - Plain viem client used to check network, deployments, offers and bundle authorization.
|
|
22
|
+
* @param params - Maker, caller-supplied offer tree or tree creation request, and publication intent.
|
|
23
|
+
* @param params.chainId - Chain containing Midnight, MidnightBundlesV2 and the selected ratifier.
|
|
24
|
+
* @param params.account - Non-zero maker that names itself on every offer and sends the plan.
|
|
25
|
+
* @param params.offers - Caller-supplied sell-offer tree, or a PriceRatifierV1 or RateRatifierV1 tree creation request.
|
|
26
|
+
* @param params.validation - Optional mempool API request controls; `false` skips the API call.
|
|
27
|
+
* @param params.cancellations - Optional groups and consumed ceilings to cancel atomically with publication; must not overlap the new tree.
|
|
28
|
+
* Omitting it cancels nothing (an untyped JavaScript `null` does too).
|
|
29
|
+
* @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
|
|
30
|
+
* @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
|
|
31
|
+
* @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
|
|
32
|
+
* @returns A frozen plan with persisted publication data that can be restored and built offline.
|
|
33
|
+
* @throws {InvalidBigIntInputError} If a supplied non-null `now` or a cancellation ceiling is not a bigint; checked before any request.
|
|
34
|
+
* @throws {ZeroAccountError} If the submitting account is zero.
|
|
35
|
+
* @throws {InvalidTransactionPlanError} If the account is not an address, calldata origin exceeds 1 MiB, or a supplied non-null `cancellations` is not an array or has a non-object entry; checked before any request.
|
|
36
|
+
* @throws {InvalidCalldataOriginError} If the supplied calldata origin is not nonempty, even-length hex.
|
|
37
|
+
* @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
|
|
38
|
+
* @throws {NonPositiveInputError} If `expiresAt` is not positive.
|
|
39
|
+
* @throws {ExpiredDeadlineError} If the resolved deadline is at or before the reference time or
|
|
40
|
+
* pinned block timestamp, or an offer has expired by the reference time but not at the pinned
|
|
41
|
+
* block; this skips API validation, ratification and payload encoding.
|
|
42
|
+
* @throws {InputExceedsMaxError} If explicit `expiresAt` is at or after the first offer expiry while every offer is still live at the reference time, or a cancellation ceiling exceeds uint128.
|
|
43
|
+
* @throws {NegativeInputError} If a cancellation ceiling is negative.
|
|
44
|
+
* @throws {InvalidTreeError} If the offer tree is empty or invalid.
|
|
45
|
+
* @throws {InvalidTreeHeightError} If the tree exceeds the maximum height.
|
|
46
|
+
* @throws {InvalidMidnightOfferGroupError} If a tree request uses an invalid explicit group.
|
|
47
|
+
* @throws {InvalidMidnightRateRatifierV1RateError} If a Rate V1 tree request has a negative leaf rate.
|
|
48
|
+
* @throws {InvalidMidnightRateRatifierV1TickError} If a Rate V1 tree request has an offer tick below the ratifier's minimum.
|
|
49
|
+
* @throws {MidnightCalldataEncodingError} If the offer tree or bundle input cannot be ABI-encoded.
|
|
50
|
+
* @throws {InvalidMidnightHexInputError} If a cancellation group is not bytes32.
|
|
51
|
+
* @throws {DuplicateMidnightGroupCancellationError} If the same group is cancelled more than once.
|
|
52
|
+
* @throws {MidnightOfferMakerMismatchError} If an offer names another maker.
|
|
53
|
+
* @throws {MidnightOfferSideMismatchError} If an offer is not a sell offer.
|
|
54
|
+
* @throws {MidnightOfferReduceOnlyError} If an offer is reduce-only.
|
|
55
|
+
* @throws {MidnightOfferCallbackNotSupportedError} If an offer has a callback.
|
|
56
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} If an offer routes proceeds to someone other than the maker.
|
|
57
|
+
* @throws {MidnightOfferContinuousFeeCapError} If an offer sets a nonzero continuous fee cap.
|
|
58
|
+
* @throws {MidnightReplacementGroupCancelledError} If a cancelled group is also in the new tree.
|
|
59
|
+
* @throws {MidnightOfferExpiredError} If an offer expires at or before the pinned block timestamp.
|
|
60
|
+
* @throws {MidnightOfferExpiryAfterMaturityError} If an offer expiry exceeds its market maturity.
|
|
61
|
+
* @throws {MidnightOfferGroupConsumedError} If an offer group has no capacity remaining.
|
|
62
|
+
* @throws {MidnightOfferTickSpacingError} If an offer tick is not accessible in its market.
|
|
63
|
+
* @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} If the market fee exceeds an offer's cap.
|
|
64
|
+
* @throws {MidnightOfferZeroPriceSellError} If a sell offer has a zero tick.
|
|
65
|
+
* @throws {MidnightOfferRateBoundUnreachableError} If a Rate V1 offer cannot satisfy its rate bound.
|
|
66
|
+
* @throws {MidnightMarketMaturityTooFarError} If an uncreated market matures more than 100 years after the offer expires.
|
|
67
|
+
* @throws {MidnightMarketLltvNotEnabledError} If an uncreated market uses a disabled LLTV.
|
|
68
|
+
* @throws {MidnightMarketLiquidationCursorNotEnabledError} If an uncreated market uses a disabled liquidation cursor.
|
|
69
|
+
* @throws {MidnightMarketOracleWithoutCodeError} If an uncreated market's oracle has no code.
|
|
70
|
+
* @throws {MidnightOfferMarketChainMismatchError} If an offer's market uses another chain.
|
|
71
|
+
* @throws {MidnightOfferMarketAddressMismatchError} If an offer's market names another Midnight deployment.
|
|
72
|
+
* @throws {MidnightOfferRatifierMismatchError} If an offer names a different ratifier than the tree's route.
|
|
73
|
+
* @throws {MidnightPayloadDecodeError} If the offers cannot be encoded in the publication payload,
|
|
74
|
+
* including when the encoded payload exceeds its size limit; split the offer tree.
|
|
75
|
+
* @throws {MidnightMempoolValidationError} If the mempool API rejects the tree; not thrown with `validation: false`.
|
|
76
|
+
* @throws {MidnightApiError} If API validation returns a non-2xx response.
|
|
77
|
+
* @throws {InvalidMidnightApiResponseError} If the API returns malformed successful validation data.
|
|
78
|
+
* @throws {ChainIdMismatchError} If the configured or transport chain differs from `chainId`.
|
|
79
|
+
* @throws {UnsupportedChainIdError} If the chain has no address registry.
|
|
80
|
+
* @throws {UnknownAddressError} If Midnight, the bundle or the selected ratifier is not registered on the chain.
|
|
81
|
+
* @throws {MissingContractCodeError} If a registered write target has no code.
|
|
82
|
+
* @throws {viem.BaseError} If a chain, deployment, pinned offer-state or authorization read fails.
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { buildTransactions, prepareMidnightMakeBorrow } from "@morpho-org/morpho-sdk";
|
|
86
|
+
* import { type Offer, Tree } from "@morpho-org/morpho-sdk/midnight/entities";
|
|
87
|
+
* import { type Address, createPublicClient, http } from "viem";
|
|
88
|
+
* import { base } from "viem/chains";
|
|
89
|
+
*
|
|
90
|
+
* async function buildPublication(maker: Address, sellOffers: readonly Offer[]) {
|
|
91
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
92
|
+
* // Use your proposed sell offers, each naming the Base PriceRatifierV1.
|
|
93
|
+
* const offers = Tree.create({ type: "priceV1", entries: sellOffers.map(offer => ({ offer })) });
|
|
94
|
+
* const plan = await prepareMidnightMakeBorrow(client, {
|
|
95
|
+
* chainId: base.id, account: maker, offers, now: (await client.getBlock()).timestamp,
|
|
96
|
+
* });
|
|
97
|
+
* // Simulate, then send in order from maker. No token allowance is needed.
|
|
98
|
+
* // The bundle and ratifier grants remain active until you revoke them.
|
|
99
|
+
* return buildTransactions(plan);
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
103
|
+
*/
|
|
104
|
+
export declare function prepareMidnightMakeBorrow(client: Client, params: MidnightMakeBorrowPlanParams): Promise<TransactionPlan>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { prepareMidnightBundleAuthorization } from "./authorization.js";
|
|
3
|
+
import { prepareMidnightMakerPublication, } from "./makerPublication.js";
|
|
4
|
+
import { parseMakeBorrowParams } from "./prepare.js";
|
|
5
|
+
/**
|
|
6
|
+
* Prepares a PriceRatifierV1 or RateRatifierV1 sell-offer publication for the submitting maker.
|
|
7
|
+
* The bundle activates the root and optionally cancels old groups; it does not supply collateral
|
|
8
|
+
* or create debt. No ERC-20 approval or root signature is needed. The standalone bundle grant
|
|
9
|
+
* (if needed) and the ratifier authorization made by the bundle persist until revoked.
|
|
10
|
+
* The bundle accepts execution at its deadline, so the deadline must be strictly before every offer expiry.
|
|
11
|
+
* Builds the offer tree and checks the offer-capped `expiresAt` first, then validates the
|
|
12
|
+
* publication with a plan-side copy of the entity `makeBorrow` constructor, in its order, except
|
|
13
|
+
* that malformed cancellations are rejected before any state read, and a deadline already reached
|
|
14
|
+
* at the pinned block is rejected before the mempool API call. So an input with several errors can fail on the tree or expiry here where the entity reports another
|
|
15
|
+
* error first. The chain and the bundle, Midnight and ratifier code are checked once, right before
|
|
16
|
+
* the first publication-state read.
|
|
17
|
+
* @param client - Plain viem client used to check network, deployments, offers and bundle authorization.
|
|
18
|
+
* @param params - Maker, caller-supplied offer tree or tree creation request, and publication intent.
|
|
19
|
+
* @param params.chainId - Chain containing Midnight, MidnightBundlesV2 and the selected ratifier.
|
|
20
|
+
* @param params.account - Non-zero maker that names itself on every offer and sends the plan.
|
|
21
|
+
* @param params.offers - Caller-supplied sell-offer tree, or a PriceRatifierV1 or RateRatifierV1 tree creation request.
|
|
22
|
+
* @param params.validation - Optional mempool API request controls; `false` skips the API call.
|
|
23
|
+
* @param params.cancellations - Optional groups and consumed ceilings to cancel atomically with publication; must not overlap the new tree.
|
|
24
|
+
* Omitting it cancels nothing (an untyped JavaScript `null` does too).
|
|
25
|
+
* @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
|
|
26
|
+
* @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
|
|
27
|
+
* @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
|
|
28
|
+
* @returns A frozen plan with persisted publication data that can be restored and built offline.
|
|
29
|
+
* @throws {InvalidBigIntInputError} If a supplied non-null `now` or a cancellation ceiling is not a bigint; checked before any request.
|
|
30
|
+
* @throws {ZeroAccountError} If the submitting account is zero.
|
|
31
|
+
* @throws {InvalidTransactionPlanError} If the account is not an address, calldata origin exceeds 1 MiB, or a supplied non-null `cancellations` is not an array or has a non-object entry; checked before any request.
|
|
32
|
+
* @throws {InvalidCalldataOriginError} If the supplied calldata origin is not nonempty, even-length hex.
|
|
33
|
+
* @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
|
|
34
|
+
* @throws {NonPositiveInputError} If `expiresAt` is not positive.
|
|
35
|
+
* @throws {ExpiredDeadlineError} If the resolved deadline is at or before the reference time or
|
|
36
|
+
* pinned block timestamp, or an offer has expired by the reference time but not at the pinned
|
|
37
|
+
* block; this skips API validation, ratification and payload encoding.
|
|
38
|
+
* @throws {InputExceedsMaxError} If explicit `expiresAt` is at or after the first offer expiry while every offer is still live at the reference time, or a cancellation ceiling exceeds uint128.
|
|
39
|
+
* @throws {NegativeInputError} If a cancellation ceiling is negative.
|
|
40
|
+
* @throws {InvalidTreeError} If the offer tree is empty or invalid.
|
|
41
|
+
* @throws {InvalidTreeHeightError} If the tree exceeds the maximum height.
|
|
42
|
+
* @throws {InvalidMidnightOfferGroupError} If a tree request uses an invalid explicit group.
|
|
43
|
+
* @throws {InvalidMidnightRateRatifierV1RateError} If a Rate V1 tree request has a negative leaf rate.
|
|
44
|
+
* @throws {InvalidMidnightRateRatifierV1TickError} If a Rate V1 tree request has an offer tick below the ratifier's minimum.
|
|
45
|
+
* @throws {MidnightCalldataEncodingError} If the offer tree or bundle input cannot be ABI-encoded.
|
|
46
|
+
* @throws {InvalidMidnightHexInputError} If a cancellation group is not bytes32.
|
|
47
|
+
* @throws {DuplicateMidnightGroupCancellationError} If the same group is cancelled more than once.
|
|
48
|
+
* @throws {MidnightOfferMakerMismatchError} If an offer names another maker.
|
|
49
|
+
* @throws {MidnightOfferSideMismatchError} If an offer is not a sell offer.
|
|
50
|
+
* @throws {MidnightOfferReduceOnlyError} If an offer is reduce-only.
|
|
51
|
+
* @throws {MidnightOfferCallbackNotSupportedError} If an offer has a callback.
|
|
52
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} If an offer routes proceeds to someone other than the maker.
|
|
53
|
+
* @throws {MidnightOfferContinuousFeeCapError} If an offer sets a nonzero continuous fee cap.
|
|
54
|
+
* @throws {MidnightReplacementGroupCancelledError} If a cancelled group is also in the new tree.
|
|
55
|
+
* @throws {MidnightOfferExpiredError} If an offer expires at or before the pinned block timestamp.
|
|
56
|
+
* @throws {MidnightOfferExpiryAfterMaturityError} If an offer expiry exceeds its market maturity.
|
|
57
|
+
* @throws {MidnightOfferGroupConsumedError} If an offer group has no capacity remaining.
|
|
58
|
+
* @throws {MidnightOfferTickSpacingError} If an offer tick is not accessible in its market.
|
|
59
|
+
* @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} If the market fee exceeds an offer's cap.
|
|
60
|
+
* @throws {MidnightOfferZeroPriceSellError} If a sell offer has a zero tick.
|
|
61
|
+
* @throws {MidnightOfferRateBoundUnreachableError} If a Rate V1 offer cannot satisfy its rate bound.
|
|
62
|
+
* @throws {MidnightMarketMaturityTooFarError} If an uncreated market matures more than 100 years after the offer expires.
|
|
63
|
+
* @throws {MidnightMarketLltvNotEnabledError} If an uncreated market uses a disabled LLTV.
|
|
64
|
+
* @throws {MidnightMarketLiquidationCursorNotEnabledError} If an uncreated market uses a disabled liquidation cursor.
|
|
65
|
+
* @throws {MidnightMarketOracleWithoutCodeError} If an uncreated market's oracle has no code.
|
|
66
|
+
* @throws {MidnightOfferMarketChainMismatchError} If an offer's market uses another chain.
|
|
67
|
+
* @throws {MidnightOfferMarketAddressMismatchError} If an offer's market names another Midnight deployment.
|
|
68
|
+
* @throws {MidnightOfferRatifierMismatchError} If an offer names a different ratifier than the tree's route.
|
|
69
|
+
* @throws {MidnightPayloadDecodeError} If the offers cannot be encoded in the publication payload,
|
|
70
|
+
* including when the encoded payload exceeds its size limit; split the offer tree.
|
|
71
|
+
* @throws {MidnightMempoolValidationError} If the mempool API rejects the tree; not thrown with `validation: false`.
|
|
72
|
+
* @throws {MidnightApiError} If API validation returns a non-2xx response.
|
|
73
|
+
* @throws {InvalidMidnightApiResponseError} If the API returns malformed successful validation data.
|
|
74
|
+
* @throws {ChainIdMismatchError} If the configured or transport chain differs from `chainId`.
|
|
75
|
+
* @throws {UnsupportedChainIdError} If the chain has no address registry.
|
|
76
|
+
* @throws {UnknownAddressError} If Midnight, the bundle or the selected ratifier is not registered on the chain.
|
|
77
|
+
* @throws {MissingContractCodeError} If a registered write target has no code.
|
|
78
|
+
* @throws {viem.BaseError} If a chain, deployment, pinned offer-state or authorization read fails.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { buildTransactions, prepareMidnightMakeBorrow } from "@morpho-org/morpho-sdk";
|
|
82
|
+
* import { type Offer, Tree } from "@morpho-org/morpho-sdk/midnight/entities";
|
|
83
|
+
* import { type Address, createPublicClient, http } from "viem";
|
|
84
|
+
* import { base } from "viem/chains";
|
|
85
|
+
*
|
|
86
|
+
* async function buildPublication(maker: Address, sellOffers: readonly Offer[]) {
|
|
87
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
88
|
+
* // Use your proposed sell offers, each naming the Base PriceRatifierV1.
|
|
89
|
+
* const offers = Tree.create({ type: "priceV1", entries: sellOffers.map(offer => ({ offer })) });
|
|
90
|
+
* const plan = await prepareMidnightMakeBorrow(client, {
|
|
91
|
+
* chainId: base.id, account: maker, offers, now: (await client.getBlock()).timestamp,
|
|
92
|
+
* });
|
|
93
|
+
* // Simulate, then send in order from maker. No token allowance is needed.
|
|
94
|
+
* // The bundle and ratifier grants remain active until you revoke them.
|
|
95
|
+
* return buildTransactions(plan);
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
99
|
+
*/
|
|
100
|
+
export async function prepareMidnightMakeBorrow(client, params) {
|
|
101
|
+
const { chainId, account } = params;
|
|
102
|
+
const { inputs, calldataOrigin } = await prepareMidnightMakerPublication(client, { params, parse: parseMakeBorrowParams });
|
|
103
|
+
const authorization = await prepareMidnightBundleAuthorization(client, {
|
|
104
|
+
chainId,
|
|
105
|
+
account,
|
|
106
|
+
});
|
|
107
|
+
return deepFreeze({
|
|
108
|
+
version: 2,
|
|
109
|
+
chainId,
|
|
110
|
+
account,
|
|
111
|
+
expiresAt: Number(inputs.deadline),
|
|
112
|
+
...(calldataOrigin && { calldataOrigin }),
|
|
113
|
+
steps: [
|
|
114
|
+
...(authorization === undefined ? [] : [authorization]),
|
|
115
|
+
{
|
|
116
|
+
id: "midnightMakeBorrow",
|
|
117
|
+
label: "Publish Midnight borrow offers",
|
|
118
|
+
action: { type: "midnightMakeBorrow", inputs },
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
signatureRequests: [],
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { Address, Client } from "viem";
|
|
2
|
+
import type { TransactionPlan } from "../types.js";
|
|
3
|
+
import { type MidnightMakerPublicationPlanParams } from "./makerPublication.js";
|
|
4
|
+
import { parseMakeLendParams, parseMakeRepayParams } from "./prepare.js";
|
|
5
|
+
/**
|
|
6
|
+
* Inputs for publishing resting Midnight lend offers funded from the maker's token balance.
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
*/
|
|
9
|
+
export interface MidnightMakeLendPlanParams extends MidnightMakerPublicationPlanParams {
|
|
10
|
+
/** Loan token shared by every offer market. */
|
|
11
|
+
readonly loanToken: Address;
|
|
12
|
+
/** Loan assets to cover in the core allowance check. Count an alternative offer group's budget once. */
|
|
13
|
+
readonly loanAssets: bigint;
|
|
14
|
+
/** Additional loan assets reserved by other open groups, excluding groups being cancelled. */
|
|
15
|
+
readonly reservedLoanAssets?: bigint;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Prepares a PriceRatifierV1 or RateRatifierV1 buy-offer publication for the submitting maker.
|
|
19
|
+
* Midnight pulls loan tokens from the maker only at fill time. Preparation checks the core
|
|
20
|
+
* allowance against `loanAssets + reservedLoanAssets`, not the offer caps or the wallet balance.
|
|
21
|
+
* The publication bundle pulls nothing and cannot fund this flow with native ETH. Approvals
|
|
22
|
+
* and authorizations are separate transactions and do not expire with the plan.
|
|
23
|
+
* Builds the offer tree and checks the offer-capped `expiresAt` first, then validates the
|
|
24
|
+
* publication with a plan-side copy of the entity `makeLend` constructor, in its order, except
|
|
25
|
+
* that malformed cancellations are rejected before any state read, and a deadline already reached
|
|
26
|
+
* at the pinned block is rejected before the mempool API call. So an input with several errors can fail on the tree or expiry here where the entity reports another error
|
|
27
|
+
* first. The chain and the bundle, Midnight and ratifier code are checked once, right before
|
|
28
|
+
* the first publication-state read. The allowance bound is checked like the entity's
|
|
29
|
+
* `getRequirements()`, after the publication is parsed and before the allowance read.
|
|
30
|
+
* @param client - Plain viem client for network, deployment, offer and prerequisite reads.
|
|
31
|
+
* @param params - Maker, offer tree or tree creation request, and loan-token allowance bounds.
|
|
32
|
+
* @param params.chainId - Chain containing Midnight, MidnightBundlesV2 and the selected ratifier.
|
|
33
|
+
* @param params.account - Non-zero maker that names itself on every offer and sends the plan.
|
|
34
|
+
* @param params.offers - Caller-supplied buy-offer tree, or a PriceRatifierV1 or RateRatifierV1 tree creation request.
|
|
35
|
+
* @param params.validation - Optional mempool API request controls; `false` skips the API call.
|
|
36
|
+
* @param params.cancellations - Optional groups and consumed ceilings to cancel atomically with publication; must not overlap the new tree.
|
|
37
|
+
* Omitting it cancels nothing (an untyped JavaScript `null` does too).
|
|
38
|
+
* @param params.loanToken - Loan token shared by every offer market.
|
|
39
|
+
* @param params.loanAssets - Positive loan assets to cover in the core allowance check; count an alternative offer group's budget once.
|
|
40
|
+
* @param params.reservedLoanAssets - Optional loan assets reserved by other open groups, excluding cancelled groups; defaults to `0n`.
|
|
41
|
+
* @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
|
|
42
|
+
* @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
|
|
43
|
+
* @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
|
|
44
|
+
* @returns A frozen, signature-free plan whose publication payload can be built offline.
|
|
45
|
+
* @throws {InvalidBigIntInputError} If `loanAssets`, a cancellation ceiling, or a supplied non-null `now`
|
|
46
|
+
* or `reservedLoanAssets` is not a bigint; checked before any request.
|
|
47
|
+
* @throws {ZeroAccountError} If the submitting account is zero.
|
|
48
|
+
* @throws {InvalidTransactionPlanError} If the account is not an address, calldata origin exceeds 1 MiB,
|
|
49
|
+
* or a supplied non-null `cancellations` is not an array or has a non-object entry; checked
|
|
50
|
+
* before any request.
|
|
51
|
+
* @throws {InvalidCalldataOriginError} If calldata origin is not nonempty, even-length hex.
|
|
52
|
+
* @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
|
|
53
|
+
* @throws {InvalidTreeError} If the offer tree is empty or invalid.
|
|
54
|
+
* @throws {InvalidTreeHeightError} If the tree exceeds the allowed height.
|
|
55
|
+
* @throws {InvalidMidnightOfferGroupError} If a tree request uses an invalid explicit group.
|
|
56
|
+
* @throws {InvalidMidnightRateRatifierV1RateError} If a Rate V1 tree request has a negative leaf rate.
|
|
57
|
+
* @throws {InvalidMidnightRateRatifierV1TickError} If a Rate V1 tree request has an offer tick below the ratifier's minimum.
|
|
58
|
+
* @throws {NonPositiveInputError} If `loanAssets` or `expiresAt` is not positive.
|
|
59
|
+
* @throws {NegativeInputError} If `reservedLoanAssets` or a cancellation ceiling is negative.
|
|
60
|
+
* @throws {InputExceedsMaxError} If `loanAssets + reservedLoanAssets` exceeds uint256, a cancellation ceiling exceeds uint128, or explicit expiry reaches an offer's expiry while every offer is still live at the reference time.
|
|
61
|
+
* @throws {MidnightCalldataEncodingError} If the loan-token address or publication input cannot be encoded.
|
|
62
|
+
* @throws {MidnightOfferMarketLoanTokenMismatchError} If an offer uses a different loan token.
|
|
63
|
+
* @throws {MidnightOfferSideMismatchError} If an offer is not a buy offer.
|
|
64
|
+
* @throws {MidnightOfferReduceOnlyError} If an offer is reduce-only.
|
|
65
|
+
* @throws {MidnightOfferMakerMismatchError} If an offer names another maker.
|
|
66
|
+
* @throws {MidnightOfferCallbackNotSupportedError} If an offer has a callback.
|
|
67
|
+
* @throws {MidnightOfferContinuousFeeCapError} If an offer sets a nonzero continuous fee cap.
|
|
68
|
+
* @throws {MidnightOfferExpiredError} If an offer expires at or before the pinned block timestamp.
|
|
69
|
+
* @throws {MidnightOfferExpiryAfterMaturityError} If an offer expiry exceeds its market maturity.
|
|
70
|
+
* @throws {MidnightOfferGroupConsumedError} If an offer group has no capacity remaining.
|
|
71
|
+
* @throws {MidnightOfferTickSpacingError} If an offer tick is not accessible in its market.
|
|
72
|
+
* @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} If the market fee exceeds an offer's cap.
|
|
73
|
+
* @throws {MidnightOfferRateBoundUnreachableError} If a Rate V1 offer cannot satisfy its rate bound.
|
|
74
|
+
* @throws {MidnightMarketMaturityTooFarError} If an uncreated market matures more than 100 years after offer expiry.
|
|
75
|
+
* @throws {MidnightMarketLltvNotEnabledError} If an uncreated market uses a disabled LLTV.
|
|
76
|
+
* @throws {MidnightMarketLiquidationCursorNotEnabledError} If an uncreated market uses a disabled liquidation cursor.
|
|
77
|
+
* @throws {MidnightMarketOracleWithoutCodeError} If an uncreated market's oracle has no code.
|
|
78
|
+
* @throws {MidnightOfferMarketChainMismatchError} If an offer targets another chain.
|
|
79
|
+
* @throws {MidnightOfferMarketAddressMismatchError} If an offer targets another Midnight deployment.
|
|
80
|
+
* @throws {MidnightOfferRatifierMismatchError} If an offer uses a different ratifier than the tree's route.
|
|
81
|
+
* @throws {MidnightPayloadDecodeError} If the offers cannot be encoded in the publication payload,
|
|
82
|
+
* including when the encoded payload exceeds its size limit; split the offer tree.
|
|
83
|
+
* @throws {InvalidMidnightHexInputError} If a cancellation group is not bytes32.
|
|
84
|
+
* @throws {DuplicateMidnightGroupCancellationError} If the same group is cancelled more than once.
|
|
85
|
+
* @throws {MidnightReplacementGroupCancelledError} If a cancellation overlaps the published tree.
|
|
86
|
+
* @throws {ExpiredDeadlineError} If the resolved deadline is at or before the reference time or
|
|
87
|
+
* pinned block timestamp, or an offer has expired by the reference time but not at the pinned
|
|
88
|
+
* block; this skips API validation, ratification and payload encoding.
|
|
89
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} If an offer routes proceeds to someone other than the maker.
|
|
90
|
+
* @throws {ChainIdMismatchError} If the configured or transport chain differs from the requested chain.
|
|
91
|
+
* @throws {UnsupportedChainIdError} If the chain has no address registry.
|
|
92
|
+
* @throws {UnknownAddressError} If a required deployment is not registered.
|
|
93
|
+
* @throws {MissingContractCodeError} If a registered write target has no code.
|
|
94
|
+
* @throws {MidnightMempoolValidationError} If optional API validation rejects the tree.
|
|
95
|
+
* @throws {MidnightApiError} If API validation returns a non-2xx response.
|
|
96
|
+
* @throws {InvalidMidnightApiResponseError} If the API returns malformed successful validation data.
|
|
97
|
+
* @throws {viem.BaseError} If a chain, deployment, pinned offer-state, allowance or authorization read fails.
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { buildTransactions, prepareMidnightMakeLend } from "@morpho-org/morpho-sdk";
|
|
101
|
+
* import { type Offer, Tree } from "@morpho-org/morpho-sdk/midnight/entities";
|
|
102
|
+
* import { type Address, createPublicClient, http } from "viem";
|
|
103
|
+
* import { base } from "viem/chains";
|
|
104
|
+
*
|
|
105
|
+
* async function buildLend(maker: Address, loanToken: Address, buyOffers: readonly Offer[]) {
|
|
106
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
107
|
+
* // Use the maker's proposed buy offers, each naming the Base PriceRatifierV1.
|
|
108
|
+
* const offers = Tree.create({ type: "priceV1", entries: buyOffers.map(offer => ({ offer })) });
|
|
109
|
+
* const plan = await prepareMidnightMakeLend(client, {
|
|
110
|
+
* chainId: base.id, account: maker, offers, loanToken, loanAssets: 1_000_000n,
|
|
111
|
+
* now: (await client.getBlock()).timestamp,
|
|
112
|
+
* });
|
|
113
|
+
* // Simulate and send the transactions in order from maker.
|
|
114
|
+
* return buildTransactions(plan);
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
118
|
+
*/
|
|
119
|
+
export declare function prepareMidnightMakeLend(client: Client, params: MidnightMakeLendPlanParams): Promise<TransactionPlan>;
|
|
120
|
+
declare const fundedPublications: {
|
|
121
|
+
readonly lend: {
|
|
122
|
+
readonly type: "midnightMakeLend";
|
|
123
|
+
readonly label: "Publish Midnight lend offers";
|
|
124
|
+
readonly parse: typeof parseMakeLendParams;
|
|
125
|
+
};
|
|
126
|
+
readonly repay: {
|
|
127
|
+
readonly type: "midnightMakeRepay";
|
|
128
|
+
readonly label: "Publish Midnight repay offers";
|
|
129
|
+
readonly parse: typeof parseMakeRepayParams;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* @internal Prepares a buy-offer publication with the core loan-token allowance needed at fill
|
|
134
|
+
* time, through the operation's entity parse constructor.
|
|
135
|
+
*/
|
|
136
|
+
export declare function prepareFundedMidnightMakerPublication(client: Client, { params, operation, }: {
|
|
137
|
+
readonly params: MidnightMakeLendPlanParams;
|
|
138
|
+
readonly operation: keyof typeof fundedPublications;
|
|
139
|
+
}): Promise<TransactionPlan>;
|
|
140
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { parseMidnightApprovalRequirements } from "../../actions/requirements/midnight/getMidnightApprovalRequirements.js";
|
|
3
|
+
import { getTokenRequirements } from "../requirements.js";
|
|
4
|
+
import { prepareMidnightBundleAuthorization } from "./authorization.js";
|
|
5
|
+
import { prepareMidnightMakerPublication, } from "./makerPublication.js";
|
|
6
|
+
import { parseMakeLendParams, parseMakeRepayParams } from "./prepare.js";
|
|
7
|
+
/**
|
|
8
|
+
* Prepares a PriceRatifierV1 or RateRatifierV1 buy-offer publication for the submitting maker.
|
|
9
|
+
* Midnight pulls loan tokens from the maker only at fill time. Preparation checks the core
|
|
10
|
+
* allowance against `loanAssets + reservedLoanAssets`, not the offer caps or the wallet balance.
|
|
11
|
+
* The publication bundle pulls nothing and cannot fund this flow with native ETH. Approvals
|
|
12
|
+
* and authorizations are separate transactions and do not expire with the plan.
|
|
13
|
+
* Builds the offer tree and checks the offer-capped `expiresAt` first, then validates the
|
|
14
|
+
* publication with a plan-side copy of the entity `makeLend` constructor, in its order, except
|
|
15
|
+
* that malformed cancellations are rejected before any state read, and a deadline already reached
|
|
16
|
+
* at the pinned block is rejected before the mempool API call. So an input with several errors can fail on the tree or expiry here where the entity reports another error
|
|
17
|
+
* first. The chain and the bundle, Midnight and ratifier code are checked once, right before
|
|
18
|
+
* the first publication-state read. The allowance bound is checked like the entity's
|
|
19
|
+
* `getRequirements()`, after the publication is parsed and before the allowance read.
|
|
20
|
+
* @param client - Plain viem client for network, deployment, offer and prerequisite reads.
|
|
21
|
+
* @param params - Maker, offer tree or tree creation request, and loan-token allowance bounds.
|
|
22
|
+
* @param params.chainId - Chain containing Midnight, MidnightBundlesV2 and the selected ratifier.
|
|
23
|
+
* @param params.account - Non-zero maker that names itself on every offer and sends the plan.
|
|
24
|
+
* @param params.offers - Caller-supplied buy-offer tree, or a PriceRatifierV1 or RateRatifierV1 tree creation request.
|
|
25
|
+
* @param params.validation - Optional mempool API request controls; `false` skips the API call.
|
|
26
|
+
* @param params.cancellations - Optional groups and consumed ceilings to cancel atomically with publication; must not overlap the new tree.
|
|
27
|
+
* Omitting it cancels nothing (an untyped JavaScript `null` does too).
|
|
28
|
+
* @param params.loanToken - Loan token shared by every offer market.
|
|
29
|
+
* @param params.loanAssets - Positive loan assets to cover in the core allowance check; count an alternative offer group's budget once.
|
|
30
|
+
* @param params.reservedLoanAssets - Optional loan assets reserved by other open groups, excluding cancelled groups; defaults to `0n`.
|
|
31
|
+
* @param params.now - Reference Unix timestamp in seconds for plan expiry; omitting it uses the device clock (an untyped JavaScript `null` does too).
|
|
32
|
+
* @param params.expiresAt - Unix seconds. Defaults to the earlier of `now + 2h` and the first offer expiry minus one second.
|
|
33
|
+
* @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
|
|
34
|
+
* @returns A frozen, signature-free plan whose publication payload can be built offline.
|
|
35
|
+
* @throws {InvalidBigIntInputError} If `loanAssets`, a cancellation ceiling, or a supplied non-null `now`
|
|
36
|
+
* or `reservedLoanAssets` is not a bigint; checked before any request.
|
|
37
|
+
* @throws {ZeroAccountError} If the submitting account is zero.
|
|
38
|
+
* @throws {InvalidTransactionPlanError} If the account is not an address, calldata origin exceeds 1 MiB,
|
|
39
|
+
* or a supplied non-null `cancellations` is not an array or has a non-object entry; checked
|
|
40
|
+
* before any request.
|
|
41
|
+
* @throws {InvalidCalldataOriginError} If calldata origin is not nonempty, even-length hex.
|
|
42
|
+
* @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
|
|
43
|
+
* @throws {InvalidTreeError} If the offer tree is empty or invalid.
|
|
44
|
+
* @throws {InvalidTreeHeightError} If the tree exceeds the allowed height.
|
|
45
|
+
* @throws {InvalidMidnightOfferGroupError} If a tree request uses an invalid explicit group.
|
|
46
|
+
* @throws {InvalidMidnightRateRatifierV1RateError} If a Rate V1 tree request has a negative leaf rate.
|
|
47
|
+
* @throws {InvalidMidnightRateRatifierV1TickError} If a Rate V1 tree request has an offer tick below the ratifier's minimum.
|
|
48
|
+
* @throws {NonPositiveInputError} If `loanAssets` or `expiresAt` is not positive.
|
|
49
|
+
* @throws {NegativeInputError} If `reservedLoanAssets` or a cancellation ceiling is negative.
|
|
50
|
+
* @throws {InputExceedsMaxError} If `loanAssets + reservedLoanAssets` exceeds uint256, a cancellation ceiling exceeds uint128, or explicit expiry reaches an offer's expiry while every offer is still live at the reference time.
|
|
51
|
+
* @throws {MidnightCalldataEncodingError} If the loan-token address or publication input cannot be encoded.
|
|
52
|
+
* @throws {MidnightOfferMarketLoanTokenMismatchError} If an offer uses a different loan token.
|
|
53
|
+
* @throws {MidnightOfferSideMismatchError} If an offer is not a buy offer.
|
|
54
|
+
* @throws {MidnightOfferReduceOnlyError} If an offer is reduce-only.
|
|
55
|
+
* @throws {MidnightOfferMakerMismatchError} If an offer names another maker.
|
|
56
|
+
* @throws {MidnightOfferCallbackNotSupportedError} If an offer has a callback.
|
|
57
|
+
* @throws {MidnightOfferContinuousFeeCapError} If an offer sets a nonzero continuous fee cap.
|
|
58
|
+
* @throws {MidnightOfferExpiredError} If an offer expires at or before the pinned block timestamp.
|
|
59
|
+
* @throws {MidnightOfferExpiryAfterMaturityError} If an offer expiry exceeds its market maturity.
|
|
60
|
+
* @throws {MidnightOfferGroupConsumedError} If an offer group has no capacity remaining.
|
|
61
|
+
* @throws {MidnightOfferTickSpacingError} If an offer tick is not accessible in its market.
|
|
62
|
+
* @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} If the market fee exceeds an offer's cap.
|
|
63
|
+
* @throws {MidnightOfferRateBoundUnreachableError} If a Rate V1 offer cannot satisfy its rate bound.
|
|
64
|
+
* @throws {MidnightMarketMaturityTooFarError} If an uncreated market matures more than 100 years after offer expiry.
|
|
65
|
+
* @throws {MidnightMarketLltvNotEnabledError} If an uncreated market uses a disabled LLTV.
|
|
66
|
+
* @throws {MidnightMarketLiquidationCursorNotEnabledError} If an uncreated market uses a disabled liquidation cursor.
|
|
67
|
+
* @throws {MidnightMarketOracleWithoutCodeError} If an uncreated market's oracle has no code.
|
|
68
|
+
* @throws {MidnightOfferMarketChainMismatchError} If an offer targets another chain.
|
|
69
|
+
* @throws {MidnightOfferMarketAddressMismatchError} If an offer targets another Midnight deployment.
|
|
70
|
+
* @throws {MidnightOfferRatifierMismatchError} If an offer uses a different ratifier than the tree's route.
|
|
71
|
+
* @throws {MidnightPayloadDecodeError} If the offers cannot be encoded in the publication payload,
|
|
72
|
+
* including when the encoded payload exceeds its size limit; split the offer tree.
|
|
73
|
+
* @throws {InvalidMidnightHexInputError} If a cancellation group is not bytes32.
|
|
74
|
+
* @throws {DuplicateMidnightGroupCancellationError} If the same group is cancelled more than once.
|
|
75
|
+
* @throws {MidnightReplacementGroupCancelledError} If a cancellation overlaps the published tree.
|
|
76
|
+
* @throws {ExpiredDeadlineError} If the resolved deadline is at or before the reference time or
|
|
77
|
+
* pinned block timestamp, or an offer has expired by the reference time but not at the pinned
|
|
78
|
+
* block; this skips API validation, ratification and payload encoding.
|
|
79
|
+
* @throws {MidnightOfferSellerReceiverMismatchError} If an offer routes proceeds to someone other than the maker.
|
|
80
|
+
* @throws {ChainIdMismatchError} If the configured or transport chain differs from the requested chain.
|
|
81
|
+
* @throws {UnsupportedChainIdError} If the chain has no address registry.
|
|
82
|
+
* @throws {UnknownAddressError} If a required deployment is not registered.
|
|
83
|
+
* @throws {MissingContractCodeError} If a registered write target has no code.
|
|
84
|
+
* @throws {MidnightMempoolValidationError} If optional API validation rejects the tree.
|
|
85
|
+
* @throws {MidnightApiError} If API validation returns a non-2xx response.
|
|
86
|
+
* @throws {InvalidMidnightApiResponseError} If the API returns malformed successful validation data.
|
|
87
|
+
* @throws {viem.BaseError} If a chain, deployment, pinned offer-state, allowance or authorization read fails.
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { buildTransactions, prepareMidnightMakeLend } from "@morpho-org/morpho-sdk";
|
|
91
|
+
* import { type Offer, Tree } from "@morpho-org/morpho-sdk/midnight/entities";
|
|
92
|
+
* import { type Address, createPublicClient, http } from "viem";
|
|
93
|
+
* import { base } from "viem/chains";
|
|
94
|
+
*
|
|
95
|
+
* async function buildLend(maker: Address, loanToken: Address, buyOffers: readonly Offer[]) {
|
|
96
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
97
|
+
* // Use the maker's proposed buy offers, each naming the Base PriceRatifierV1.
|
|
98
|
+
* const offers = Tree.create({ type: "priceV1", entries: buyOffers.map(offer => ({ offer })) });
|
|
99
|
+
* const plan = await prepareMidnightMakeLend(client, {
|
|
100
|
+
* chainId: base.id, account: maker, offers, loanToken, loanAssets: 1_000_000n,
|
|
101
|
+
* now: (await client.getBlock()).timestamp,
|
|
102
|
+
* });
|
|
103
|
+
* // Simulate and send the transactions in order from maker.
|
|
104
|
+
* return buildTransactions(plan);
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
108
|
+
*/
|
|
109
|
+
export async function prepareMidnightMakeLend(client, params) {
|
|
110
|
+
return prepareFundedMidnightMakerPublication(client, {
|
|
111
|
+
params,
|
|
112
|
+
operation: "lend",
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const fundedPublications = {
|
|
116
|
+
lend: {
|
|
117
|
+
type: "midnightMakeLend",
|
|
118
|
+
label: "Publish Midnight lend offers",
|
|
119
|
+
parse: parseMakeLendParams,
|
|
120
|
+
},
|
|
121
|
+
repay: {
|
|
122
|
+
type: "midnightMakeRepay",
|
|
123
|
+
label: "Publish Midnight repay offers",
|
|
124
|
+
parse: parseMakeRepayParams,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* @internal Prepares a buy-offer publication with the core loan-token allowance needed at fill
|
|
129
|
+
* time, through the operation's entity parse constructor.
|
|
130
|
+
*/
|
|
131
|
+
export async function prepareFundedMidnightMakerPublication(client, { params, operation, }) {
|
|
132
|
+
const { chainId, account, loanToken, loanAssets, reservedLoanAssets } = params;
|
|
133
|
+
const { type, label, parse } = fundedPublications[operation];
|
|
134
|
+
const { parsed, inputs, calldataOrigin } = await prepareMidnightMakerPublication(client, {
|
|
135
|
+
params,
|
|
136
|
+
parse: (raw, context) => parse({ ...raw, loanToken, loanAssets, reservedLoanAssets }, context),
|
|
137
|
+
});
|
|
138
|
+
const midnight = getChainAddress(chainId, "midnight");
|
|
139
|
+
// Validation only; the entity checks the same allowance bound in getRequirements().
|
|
140
|
+
parseMidnightApprovalRequirements({
|
|
141
|
+
viemClient: client,
|
|
142
|
+
chainId,
|
|
143
|
+
token: parsed.loanToken,
|
|
144
|
+
owner: account,
|
|
145
|
+
spender: midnight,
|
|
146
|
+
amount: parsed.approvalAmount,
|
|
147
|
+
});
|
|
148
|
+
const [{ approvals }, authorization] = await Promise.all([
|
|
149
|
+
getTokenRequirements(client, {
|
|
150
|
+
chainId,
|
|
151
|
+
owner: account,
|
|
152
|
+
token: parsed.loanToken,
|
|
153
|
+
spender: midnight,
|
|
154
|
+
amount: parsed.approvalAmount,
|
|
155
|
+
approvalId: (index) => `${type}:approval:${index}`,
|
|
156
|
+
}),
|
|
157
|
+
prepareMidnightBundleAuthorization(client, { chainId, account }),
|
|
158
|
+
]);
|
|
159
|
+
return deepFreeze({
|
|
160
|
+
version: 2,
|
|
161
|
+
chainId,
|
|
162
|
+
account,
|
|
163
|
+
expiresAt: Number(inputs.deadline),
|
|
164
|
+
...(calldataOrigin && { calldataOrigin }),
|
|
165
|
+
steps: [
|
|
166
|
+
...approvals,
|
|
167
|
+
...(authorization === undefined ? [] : [authorization]),
|
|
168
|
+
{ id: type, label, action: { type, inputs } },
|
|
169
|
+
],
|
|
170
|
+
signatureRequests: [],
|
|
171
|
+
});
|
|
172
|
+
}
|