@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,545 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareMidnightTakeBorrow = prepareMidnightTakeBorrow;
|
|
4
|
+
exports.prepareMidnightSupplyCollateralTakeBorrow = prepareMidnightSupplyCollateralTakeBorrow;
|
|
5
|
+
exports.buildMidnightTakeBorrow = buildMidnightTakeBorrow;
|
|
6
|
+
exports.validateMidnightSupplyCollateralTakeBorrowPlanAction = validateMidnightSupplyCollateralTakeBorrowPlanAction;
|
|
7
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
8
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
9
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
10
|
+
const supplyCollateralTakeBorrow_js_1 = require("../../actions/midnight/supplyCollateralTakeBorrow.js");
|
|
11
|
+
const takeBorrow_js_1 = require("../../actions/midnight/takeBorrow.js");
|
|
12
|
+
const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
|
|
13
|
+
const getMidnightApprovalRequirements_js_1 = require("../../actions/requirements/midnight/getMidnightApprovalRequirements.js");
|
|
14
|
+
const assertContractCode_js_1 = require("../../entities/requirements/assertContractCode.js");
|
|
15
|
+
const constant_js_1 = require("../../helpers/constant.js");
|
|
16
|
+
const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
|
|
17
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
18
|
+
const validateMidnightTakeableOfferFields_js_1 = require("../../helpers/validateMidnightTakeableOfferFields.js");
|
|
19
|
+
const validateMidnightTakeFeasibility_js_1 = require("../../helpers/validateMidnightTakeFeasibility.js");
|
|
20
|
+
const error_js_1 = require("../../types/error.js");
|
|
21
|
+
const error_js_2 = require("../error.js");
|
|
22
|
+
const intent_js_1 = require("../intent.js");
|
|
23
|
+
const requirements_js_1 = require("../requirements.js");
|
|
24
|
+
const validation_js_1 = require("../validation.js");
|
|
25
|
+
const authorization_js_1 = require("./authorization.js");
|
|
26
|
+
const market_js_1 = require("./market.js");
|
|
27
|
+
const validation_js_2 = require("./validation.js");
|
|
28
|
+
/**
|
|
29
|
+
* Prepares a MidnightBundlesV2 borrow for the submitting account, using existing
|
|
30
|
+
* credit first and then filling lend offers under the given target and referral fee.
|
|
31
|
+
* Validates inputs with the same parse-once constructor, position binding, buffered health
|
|
32
|
+
* check and fill feasibility check as the entity `takeBorrow`, then reads the registry
|
|
33
|
+
* targets' bytecode and the bundle authorization. Feasibility uses the position's credit
|
|
34
|
+
* accrued to the reference timestamp against `marketData`, the same snapshot that caps
|
|
35
|
+
* withdrawable credit. On an assets target, offers that would revert the
|
|
36
|
+
* whole bundle are dropped from the stored fills. Like the entity check, fill feasibility counts
|
|
37
|
+
* units at par and does not price discounted bids after settlement fees, so a plan can pass
|
|
38
|
+
* preparation and still revert onchain; the onchain bounds keep funds safe. Simulate before sending.
|
|
39
|
+
* @param client - Viem client used to verify chain, deployments and authorization.
|
|
40
|
+
* @param params - Account, market and position snapshots, collateral prices, fills and intent.
|
|
41
|
+
* @param params.chainId - Chain containing the market and MidnightBundlesV2.
|
|
42
|
+
* @param params.account - Non-zero borrower that sends the plan and owns any new debt.
|
|
43
|
+
* @param params.marketData - Hydrated market snapshot used for fill feasibility and collateral capacity.
|
|
44
|
+
* @param params.positionData - Borrower's position snapshot for the same market.
|
|
45
|
+
* @param params.collateralPrices - Oracle prices indexed by market collateral, scaled by `ORACLE_PRICE_SCALE`.
|
|
46
|
+
* @param params.takeableOffers - ABI-ready lend offers from the caller's quote, in fill order.
|
|
47
|
+
* @param params.target.type - `"assets"` to receive loan assets, or `"units"` to sell exact units.
|
|
48
|
+
* @param params.target.assets - Exact loan assets paid to the receiver on an assets target; any referral fee is sold on top.
|
|
49
|
+
* @param params.target.maxUnits - Unit cap on an assets target; also bounds the buffered health check.
|
|
50
|
+
* @param params.target.units - Exact units to sell on a units target.
|
|
51
|
+
* @param params.target.minSellerAssets - Loan-asset floor on a units target, checked against the
|
|
52
|
+
* proceeds after any referral fee.
|
|
53
|
+
* @param params.receiver - Optional recipient of the loan assets; defaults to `account`.
|
|
54
|
+
* @param params.referralFee.bps - Optional referral fee in integer basis points, at most 10%.
|
|
55
|
+
* @param params.referralFee.recipient - Recipient required for a positive referral fee.
|
|
56
|
+
* @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
|
|
57
|
+
* @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
|
|
58
|
+
* @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
|
|
59
|
+
* @returns A frozen plan with a standalone authorization step if needed and no signature requests.
|
|
60
|
+
* @throws {InvalidBigIntInputError} If a supplied non-null `now`, or a target amount, is not a bigint;
|
|
61
|
+
* checked before any request.
|
|
62
|
+
* @throws {ZeroAccountError} If `account` is the zero address.
|
|
63
|
+
* @throws {NonIntegerInputError} If `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
64
|
+
* @throws {NonPositiveInputError} If `expiresAt`, the target amount, `maxUnits` or
|
|
65
|
+
* `minSellerAssets` is not positive.
|
|
66
|
+
* @throws {ExpiredDeadlineError} If expiry is at or before the reference timestamp.
|
|
67
|
+
* @throws {NegativeInputError} If `referralFee.bps` or an offer cap is negative.
|
|
68
|
+
* @throws {InputExceedsMaxError} If `referralFee.bps` exceeds 1,000 (10%), or a target amount or
|
|
69
|
+
* offer cap exceeds uint128.
|
|
70
|
+
* @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
71
|
+
* @throws {MidnightTakeDeadlineTooFarError} If expiry is more than one hour away.
|
|
72
|
+
* @throws {InvalidTransactionPlanError} If `account` is malformed or the target type is neither assets nor units.
|
|
73
|
+
* @throws {ChainIdMismatchError} If the client, transport or market is on a different chain.
|
|
74
|
+
* @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
|
|
75
|
+
* @throws {EmptyMidnightTakeableOffersError} If no offers are supplied.
|
|
76
|
+
* @throws {MidnightOfferSideMismatchError} If an offer is not a lend offer.
|
|
77
|
+
* @throws {MidnightTakeableOfferMarketMismatchError} If an offer trades another market.
|
|
78
|
+
* @throws {MidnightCalldataEncodingError} If an offer field cannot be ABI-encoded.
|
|
79
|
+
* @throws {MidnightZeroReceiverError} If the receiver is the zero address.
|
|
80
|
+
* @throws {MidnightContractReceiverError} If the receiver, or the referral fee recipient of a
|
|
81
|
+
* positive fee, is a Midnight protocol or market token contract.
|
|
82
|
+
* @throws {UnboundedMidnightTakeInputError} If `target.units` or `target.maxUnits` is `maxUint256`.
|
|
83
|
+
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no recipient.
|
|
84
|
+
* @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
|
|
85
|
+
* @throws {UnknownAddressError} If the chain has no `midnightBundlesV2` deployment.
|
|
86
|
+
* @throws {MarketIdMismatchError} If the position belongs to another market.
|
|
87
|
+
* @throws {AccrualPositionUserMismatchError} If the position is not owned by the account.
|
|
88
|
+
* @throws {BorrowExceedsSafeLtvError} If the debt bound exceeds buffered collateral capacity.
|
|
89
|
+
* @throws {MissingMarketPriceError} If any held collateral has no supplied price.
|
|
90
|
+
* @throws {InvalidMidnightPositionLossFactorError} If `marketData`'s loss factor is below the position's
|
|
91
|
+
* last loss factor; fetch the market and position at the same block.
|
|
92
|
+
* @throws {InvalidMidnightPositionAccrualStateError} If the position's credit and fee snapshot cannot be accrued.
|
|
93
|
+
* @throws {MidnightTakeableOffersNotFillableError} If the supplied offers cannot be used.
|
|
94
|
+
* @throws {MidnightTakeTargetUnreachableError} If the supplied target and bounds cannot be met.
|
|
95
|
+
* @throws {MissingContractCodeError} If either registered Midnight target has no deployed code.
|
|
96
|
+
* @throws {viem.BaseError} If an `eth_chainId` request or the authorization read fails.
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { buildTransactions, prepareMidnightTakeBorrow, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
100
|
+
* import { fetchMidnightAccrualPosition } from "@morpho-org/morpho-sdk/fetch";
|
|
101
|
+
* import { MidnightApi } from "@morpho-org/morpho-sdk/midnight-api";
|
|
102
|
+
* import { type Address, type Hash, createPublicClient, http, parseAbi } from "viem";
|
|
103
|
+
* import { base } from "viem/chains";
|
|
104
|
+
*
|
|
105
|
+
* async function prepareBorrow(account: Address, marketId: Hash) {
|
|
106
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
107
|
+
* const block = await client.getBlock();
|
|
108
|
+
* const positionData = await fetchMidnightAccrualPosition(client, {
|
|
109
|
+
* marketId,
|
|
110
|
+
* user: account,
|
|
111
|
+
* blockNumber: block.number,
|
|
112
|
+
* });
|
|
113
|
+
* const marketData = positionData.market;
|
|
114
|
+
* const collateralPrices = await Promise.all(
|
|
115
|
+
* marketData.params.collateralParams.map(({ oracle }) =>
|
|
116
|
+
* client.readContract({
|
|
117
|
+
* address: oracle,
|
|
118
|
+
* abi: parseAbi(["function price() view returns (uint256)"]),
|
|
119
|
+
* functionName: "price",
|
|
120
|
+
* blockNumber: block.number,
|
|
121
|
+
* }),
|
|
122
|
+
* ),
|
|
123
|
+
* );
|
|
124
|
+
* const assets = 1_000_000n;
|
|
125
|
+
* const maxUnits = 1_100_000n;
|
|
126
|
+
* // Quote the unit ceiling: fees come out of the proceeds, so fills sized to the net
|
|
127
|
+
* // assets could not deliver them.
|
|
128
|
+
* const quote = await new MidnightApi().fetchBookQuote({
|
|
129
|
+
* marketId,
|
|
130
|
+
* side: "bids",
|
|
131
|
+
* units: maxUnits,
|
|
132
|
+
* taker: account,
|
|
133
|
+
* });
|
|
134
|
+
* const plan: TransactionPlan = await prepareMidnightTakeBorrow(client, {
|
|
135
|
+
* chainId: base.id,
|
|
136
|
+
* account,
|
|
137
|
+
* marketData,
|
|
138
|
+
* positionData,
|
|
139
|
+
* collateralPrices,
|
|
140
|
+
* now: block.timestamp,
|
|
141
|
+
* target: { type: "assets", assets, maxUnits },
|
|
142
|
+
* takeableOffers: quote.data.takeableOffers,
|
|
143
|
+
* });
|
|
144
|
+
* // Simulate, then send in order from plan.account on plan.chainId.
|
|
145
|
+
* return buildTransactions(plan);
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
149
|
+
*/
|
|
150
|
+
async function prepareMidnightTakeBorrow(client, params) {
|
|
151
|
+
return prepareBorrow(client, { params });
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Prepares an atomic collateral supply and fixed-rate borrow on MidnightBundlesV2.
|
|
155
|
+
* Validates inputs with the same parse-once constructor, position binding, buffered health
|
|
156
|
+
* check and fill feasibility check as the entity `supplyCollateralTakeBorrow`. Pass the
|
|
157
|
+
* position before the supply: the health check adds the supplied collateral to it, and
|
|
158
|
+
* repeated collateral indexes are summed. Native ETH may fund wrapped-native collateral, but
|
|
159
|
+
* the ERC-20 allowance must cover the full pull. Approvals and authorization are separate
|
|
160
|
+
* steps, so they can remain even if the bundled transaction fails.
|
|
161
|
+
* @param client - Viem client used to verify chain, deployments, allowances and authorization.
|
|
162
|
+
* @param params - Account, market and pre-supply position snapshots, collateral prices,
|
|
163
|
+
* collateral supplies, optional native funding, fills and intent.
|
|
164
|
+
* @param params.chainId - Chain containing the market and MidnightBundlesV2.
|
|
165
|
+
* @param params.account - Non-zero borrower that supplies the collateral, sends the plan and owns any new debt.
|
|
166
|
+
* @param params.marketData - Hydrated market snapshot used for fill feasibility and collateral capacity.
|
|
167
|
+
* @param params.positionData - Borrower's position snapshot for the same market, taken before the supply.
|
|
168
|
+
* @param params.collateralPrices - Oracle prices indexed by market collateral, scaled by `ORACLE_PRICE_SCALE`.
|
|
169
|
+
* @param params.collateralSupplies - Positive collateral supplies; each `collateralIndex` indexes
|
|
170
|
+
* `marketData.params.collateralParams`, `assets` is in that token's base units, and repeated indexes are summed.
|
|
171
|
+
* @param params.nativeAmount - Optional native ETH in wei for wrapped-native collateral, capped by its pull.
|
|
172
|
+
* @param params.takeableOffers - ABI-ready lend offers from the caller's quote, in fill order.
|
|
173
|
+
* @param params.target.type - `"assets"` to receive loan assets, or `"units"` to sell exact units.
|
|
174
|
+
* @param params.target.assets - Exact loan assets paid to the receiver on an assets target; any referral fee is sold on top.
|
|
175
|
+
* @param params.target.maxUnits - Unit cap on an assets target; also bounds the buffered health check.
|
|
176
|
+
* @param params.target.units - Exact units to sell on a units target.
|
|
177
|
+
* @param params.target.minSellerAssets - Loan-asset floor on a units target, checked against the
|
|
178
|
+
* proceeds after any referral fee.
|
|
179
|
+
* @param params.receiver - Optional recipient of the loan assets; defaults to `account`.
|
|
180
|
+
* @param params.referralFee.bps - Optional referral fee in integer basis points, at most 10%.
|
|
181
|
+
* @param params.referralFee.recipient - Recipient required for a positive referral fee.
|
|
182
|
+
* @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
|
|
183
|
+
* @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
|
|
184
|
+
* @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
|
|
185
|
+
* @returns A frozen plan with any necessary approvals and authorization, without signature requests.
|
|
186
|
+
* @throws {InvalidBigIntInputError} If a supplied non-null `now`, a target amount or a collateral index
|
|
187
|
+
* is not a bigint; checked before any request.
|
|
188
|
+
* @throws {ZeroAccountError} If `account` is the zero address.
|
|
189
|
+
* @throws {NonIntegerInputError} If `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
190
|
+
* @throws {NonPositiveInputError} If `expiresAt`, a supply amount, the target amount,
|
|
191
|
+
* `maxUnits` or `minSellerAssets` is not positive.
|
|
192
|
+
* @throws {ExpiredDeadlineError} If expiry is at or before the reference timestamp.
|
|
193
|
+
* @throws {NegativeInputError} If `referralFee.bps`, an offer cap or `nativeAmount` is negative.
|
|
194
|
+
* @throws {InputExceedsMaxError} If `referralFee.bps` exceeds 1,000 (10%), a supply amount, per-index
|
|
195
|
+
* sum, target amount or offer cap exceeds uint128, or `nativeAmount` exceeds the wrapped-native pull.
|
|
196
|
+
* @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
197
|
+
* @throws {MidnightTakeDeadlineTooFarError} If expiry is more than one hour away.
|
|
198
|
+
* @throws {InvalidTransactionPlanError} If `account` is malformed, `collateralSupplies` is not an
|
|
199
|
+
* array of objects, or the target type is neither assets nor units.
|
|
200
|
+
* @throws {ChainIdMismatchError} If the client, transport or market is on a different chain.
|
|
201
|
+
* @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
|
|
202
|
+
* @throws {EmptyMidnightCollateralSuppliesError} If no collateral is supplied.
|
|
203
|
+
* @throws {UnknownCollateralIndexError} If a supply names an unconfigured collateral index.
|
|
204
|
+
* @throws {EmptyMidnightTakeableOffersError} If no offers are supplied.
|
|
205
|
+
* @throws {MidnightOfferSideMismatchError} If an offer is not a lend offer.
|
|
206
|
+
* @throws {MidnightTakeableOfferMarketMismatchError} If an offer trades another market.
|
|
207
|
+
* @throws {MidnightCalldataEncodingError} If an offer field cannot be ABI-encoded.
|
|
208
|
+
* @throws {MidnightZeroReceiverError} If the receiver is the zero address.
|
|
209
|
+
* @throws {MidnightContractReceiverError} If the receiver, or the referral fee recipient of a
|
|
210
|
+
* positive fee, is a Midnight protocol or market token contract.
|
|
211
|
+
* @throws {UnboundedMidnightTakeInputError} If `target.units` or `target.maxUnits` is `maxUint256`.
|
|
212
|
+
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no recipient.
|
|
213
|
+
* @throws {MidnightTakeTargetUnreachableError} If the supplied target and bounds cannot be met.
|
|
214
|
+
* @throws {InvalidMidnightNativeAmountTypeError} If `nativeAmount` is not a bigint.
|
|
215
|
+
* @throws {ChainWNativeMissingError} If native funding is used on a chain without wrapped native.
|
|
216
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If native funding is used without a wrapped-native supply.
|
|
217
|
+
* @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
|
|
218
|
+
* @throws {UnknownAddressError} If the chain has no `midnightBundlesV2` deployment.
|
|
219
|
+
* @throws {MarketIdMismatchError} If the position belongs to another market.
|
|
220
|
+
* @throws {AccrualPositionUserMismatchError} If the position is not owned by the account.
|
|
221
|
+
* @throws {BorrowExceedsSafeLtvError} If the debt bound exceeds the post-supply buffered capacity.
|
|
222
|
+
* @throws {MissingMarketPriceError} If any held collateral has no supplied price.
|
|
223
|
+
* @throws {InvalidMidnightPositionLossFactorError} If `marketData`'s loss factor is below the position's
|
|
224
|
+
* last loss factor; fetch the market and position at the same block.
|
|
225
|
+
* @throws {InvalidMidnightPositionAccrualStateError} If the position's credit and fee snapshot cannot be accrued.
|
|
226
|
+
* @throws {MidnightTakeableOffersNotFillableError} If the supplied offers cannot be used.
|
|
227
|
+
* @throws {MissingContractCodeError} If either registered Midnight target has no deployed code.
|
|
228
|
+
* @throws {viem.BaseError} If an `eth_chainId` request, an allowance read or the authorization read fails.
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* import {
|
|
232
|
+
* buildTransactions,
|
|
233
|
+
* prepareMidnightSupplyCollateralTakeBorrow,
|
|
234
|
+
* type TransactionPlan,
|
|
235
|
+
* } from "@morpho-org/morpho-sdk";
|
|
236
|
+
* import { fetchMidnightAccrualPosition } from "@morpho-org/morpho-sdk/fetch";
|
|
237
|
+
* import { MidnightApi } from "@morpho-org/morpho-sdk/midnight-api";
|
|
238
|
+
* import { type Address, type Hash, createPublicClient, http, parseAbi } from "viem";
|
|
239
|
+
* import { base } from "viem/chains";
|
|
240
|
+
*
|
|
241
|
+
* async function prepareSupplyAndBorrow(account: Address, marketId: Hash, collateralAssets: bigint) {
|
|
242
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
243
|
+
* const block = await client.getBlock();
|
|
244
|
+
* // Read the position before the supply; the health check adds the supplied collateral.
|
|
245
|
+
* const positionData = await fetchMidnightAccrualPosition(client, {
|
|
246
|
+
* marketId,
|
|
247
|
+
* user: account,
|
|
248
|
+
* blockNumber: block.number,
|
|
249
|
+
* });
|
|
250
|
+
* const marketData = positionData.market;
|
|
251
|
+
* const collateralPrices = await Promise.all(
|
|
252
|
+
* marketData.params.collateralParams.map(({ oracle }) =>
|
|
253
|
+
* client.readContract({
|
|
254
|
+
* address: oracle,
|
|
255
|
+
* abi: parseAbi(["function price() view returns (uint256)"]),
|
|
256
|
+
* functionName: "price",
|
|
257
|
+
* blockNumber: block.number,
|
|
258
|
+
* }),
|
|
259
|
+
* ),
|
|
260
|
+
* );
|
|
261
|
+
* const assets = 1_000_000n;
|
|
262
|
+
* const maxUnits = 1_100_000n;
|
|
263
|
+
* // Quote the unit ceiling: fees come out of the proceeds.
|
|
264
|
+
* const quote = await new MidnightApi().fetchBookQuote({
|
|
265
|
+
* marketId,
|
|
266
|
+
* side: "bids",
|
|
267
|
+
* units: maxUnits,
|
|
268
|
+
* taker: account,
|
|
269
|
+
* });
|
|
270
|
+
* const plan: TransactionPlan = await prepareMidnightSupplyCollateralTakeBorrow(client, {
|
|
271
|
+
* chainId: base.id,
|
|
272
|
+
* account,
|
|
273
|
+
* marketData,
|
|
274
|
+
* positionData,
|
|
275
|
+
* collateralPrices,
|
|
276
|
+
* now: block.timestamp,
|
|
277
|
+
* collateralSupplies: [{ collateralIndex: 0n, assets: collateralAssets }],
|
|
278
|
+
* target: { type: "assets", assets, maxUnits },
|
|
279
|
+
* takeableOffers: quote.data.takeableOffers,
|
|
280
|
+
* });
|
|
281
|
+
* // Simulate, then send in order from plan.account on plan.chainId.
|
|
282
|
+
* return buildTransactions(plan);
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
285
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
286
|
+
*/
|
|
287
|
+
async function prepareMidnightSupplyCollateralTakeBorrow(client, params) {
|
|
288
|
+
return prepareBorrow(client, {
|
|
289
|
+
params,
|
|
290
|
+
supply: {
|
|
291
|
+
collateralSupplies: params.collateralSupplies,
|
|
292
|
+
nativeAmount: params.nativeAmount,
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
const supplyActionId = "midnightSupplyCollateralTakeBorrow";
|
|
297
|
+
const sellTargetAmounts = {
|
|
298
|
+
assets: ["assets", "maxUnits"],
|
|
299
|
+
units: ["units", "minSellerAssets"],
|
|
300
|
+
};
|
|
301
|
+
function parseFundedBorrow(borrow, supply) {
|
|
302
|
+
// Throws typed errors before reading entries when a JS caller passes a malformed list.
|
|
303
|
+
validateStoredSuppliesArray(supply.collateralSupplies, "$.collateralSupplies");
|
|
304
|
+
for (const [index, entry] of supply.collateralSupplies.entries()) {
|
|
305
|
+
(0, validation_js_1.getPlanObject)(entry, `$.collateralSupplies[${index}]`);
|
|
306
|
+
}
|
|
307
|
+
(0, market_js_1.validateCollateralIndexTypes)("collateralSupplies", supply.collateralSupplies);
|
|
308
|
+
return (0, supplyCollateralTakeBorrow_js_1.parseMidnightSupplyCollateralTakeBorrow)({ ...borrow, ...supply });
|
|
309
|
+
}
|
|
310
|
+
async function prepareBorrow(client, { params, supply, }) {
|
|
311
|
+
const { chainId, account, marketData, positionData, collateralPrices, target, } = params;
|
|
312
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
313
|
+
// Reject a non-bigint clock so the window sum below cannot throw a generic TypeError.
|
|
314
|
+
(0, validate_js_1.validateReferenceTime)(now);
|
|
315
|
+
const maxDeadline = now + constant_js_1.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS;
|
|
316
|
+
const intent = (0, intent_js_1.resolveIntent)({ ...params, expiresAt: params.expiresAt ?? Number(maxDeadline) }, now);
|
|
317
|
+
if (intent.deadline > maxDeadline) {
|
|
318
|
+
throw new error_js_1.MidnightTakeDeadlineTooFarError({
|
|
319
|
+
deadline: intent.deadline,
|
|
320
|
+
maxDeadline,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (target.type !== "assets" && target.type !== "units") {
|
|
324
|
+
throw (0, validation_js_2.invalidSellTargetType)("$.target");
|
|
325
|
+
}
|
|
326
|
+
(0, validation_js_2.validateMidnightTargetAmountTypes)(target, sellTargetAmounts[target.type]);
|
|
327
|
+
const borrow = {
|
|
328
|
+
chainId,
|
|
329
|
+
market: marketData.params,
|
|
330
|
+
target,
|
|
331
|
+
receiver: params.receiver ?? account,
|
|
332
|
+
takeableOffers: params.takeableOffers,
|
|
333
|
+
deadline: intent.deadline,
|
|
334
|
+
referralFeePct: intent.referralFeePct,
|
|
335
|
+
referralFeeRecipient: intent.referralFeeRecipient,
|
|
336
|
+
};
|
|
337
|
+
const funded = supply && parseFundedBorrow(borrow, supply);
|
|
338
|
+
const parsed = funded ?? (0, takeBorrow_js_1.parseMidnightTakeBorrow)(borrow);
|
|
339
|
+
(0, validateMidnightTakeableOfferFields_js_1.validateMidnightTakeableOfferFields)(parsed.takeableOffers);
|
|
340
|
+
const bundle = (0, morpho_ts_1.getChainAddress)(chainId, "midnightBundlesV2");
|
|
341
|
+
(0, parseMidnight_js_1.validateMidnightPositionBinding)({
|
|
342
|
+
positionData,
|
|
343
|
+
accountAddress: account,
|
|
344
|
+
marketData,
|
|
345
|
+
});
|
|
346
|
+
const collateral = funded
|
|
347
|
+
? Array.from({ length: parsed.market.collateralParams.length }, (_, index) => positionData.collateral[index] ?? 0n)
|
|
348
|
+
: [...positionData.collateral];
|
|
349
|
+
const pulls = new Map();
|
|
350
|
+
for (const { collateralIndex, token, assets } of funded?.collateralSupplies ??
|
|
351
|
+
[]) {
|
|
352
|
+
const index = Number(collateralIndex);
|
|
353
|
+
collateral[index] = (collateral[index] ?? 0n) + assets;
|
|
354
|
+
pulls.set(token, (pulls.get(token) ?? 0n) + assets);
|
|
355
|
+
}
|
|
356
|
+
(0, validate_js_1.validateMidnightBorrowHealth)({
|
|
357
|
+
market: marketData,
|
|
358
|
+
collateral,
|
|
359
|
+
collateralPrices,
|
|
360
|
+
debt: positionData.debt,
|
|
361
|
+
borrowUnits: parsed.target.type === "units"
|
|
362
|
+
? parsed.target.units
|
|
363
|
+
: parsed.target.maxUnits,
|
|
364
|
+
});
|
|
365
|
+
const { credit } = new midnight_sdk_1.AccrualPosition(positionData, marketData).accrueInterest(blue_sdk_1.MathLib.max(now, positionData.lastAccrual));
|
|
366
|
+
const takeableOffers = (0, validateMidnightTakeFeasibility_js_1.validateMidnightTakeFeasibility)({
|
|
367
|
+
side: "sell",
|
|
368
|
+
takeableOffers: parsed.takeableOffers,
|
|
369
|
+
accountAddress: account,
|
|
370
|
+
marketData,
|
|
371
|
+
now,
|
|
372
|
+
deadline: parsed.deadline,
|
|
373
|
+
referralFeePct: parsed.referralFeePct,
|
|
374
|
+
fallbackUnits: blue_sdk_1.MathLib.min(credit, marketData.withdrawable),
|
|
375
|
+
credit,
|
|
376
|
+
target: parsed.target,
|
|
377
|
+
increasesDebt: true,
|
|
378
|
+
});
|
|
379
|
+
const requirement = { chainId, account, bundle, pulls };
|
|
380
|
+
const [approvals, authorization] = await prepareBorrowRequirements(client, requirement);
|
|
381
|
+
const inputs = {
|
|
382
|
+
chainId,
|
|
383
|
+
account,
|
|
384
|
+
market: parsed.market,
|
|
385
|
+
target: parsed.target,
|
|
386
|
+
receiver: parsed.receiver,
|
|
387
|
+
takeableOffers,
|
|
388
|
+
deadline: parsed.deadline,
|
|
389
|
+
referralFeePct: parsed.referralFeePct,
|
|
390
|
+
referralFeeRecipient: parsed.referralFeeRecipient,
|
|
391
|
+
};
|
|
392
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
393
|
+
version: 2,
|
|
394
|
+
chainId,
|
|
395
|
+
account,
|
|
396
|
+
expiresAt: intent.expiresAt,
|
|
397
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
398
|
+
steps: [
|
|
399
|
+
...approvals,
|
|
400
|
+
...(authorization === undefined ? [] : [authorization]),
|
|
401
|
+
funded
|
|
402
|
+
? {
|
|
403
|
+
id: supplyActionId,
|
|
404
|
+
label: "Supply collateral and borrow on Midnight",
|
|
405
|
+
action: {
|
|
406
|
+
type: supplyActionId,
|
|
407
|
+
inputs: {
|
|
408
|
+
...inputs,
|
|
409
|
+
collateralSupplies: funded.collateralSupplies.map(({ collateralIndex, assets }) => ({
|
|
410
|
+
collateralIndex,
|
|
411
|
+
assets,
|
|
412
|
+
})),
|
|
413
|
+
...(supply?.nativeAmount !== undefined && {
|
|
414
|
+
nativeAssets: supply.nativeAmount,
|
|
415
|
+
}),
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
}
|
|
419
|
+
: {
|
|
420
|
+
id: "midnightTakeBorrow",
|
|
421
|
+
label: "Borrow on Midnight",
|
|
422
|
+
action: { type: "midnightTakeBorrow", inputs },
|
|
423
|
+
},
|
|
424
|
+
],
|
|
425
|
+
signatureRequests: [],
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
async function prepareBorrowRequirements(client, requirement) {
|
|
429
|
+
const { chainId, account, bundle } = requirement;
|
|
430
|
+
const chainCheck = (0, chainCheck_js_1.createChainCheck)(client, chainId);
|
|
431
|
+
await chainCheck();
|
|
432
|
+
// Check deployments before an authorization read can fail decoding empty data.
|
|
433
|
+
await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
434
|
+
{ role: "midnightBundlesV2", address: bundle },
|
|
435
|
+
{ role: "midnight", address: (0, morpho_ts_1.getChainAddress)(chainId, "midnight") },
|
|
436
|
+
], chainCheck);
|
|
437
|
+
return Promise.all([
|
|
438
|
+
prepareCollateralApprovals(client, requirement),
|
|
439
|
+
(0, authorization_js_1.prepareMidnightBundleAuthorization)(client, { chainId, account }),
|
|
440
|
+
]);
|
|
441
|
+
}
|
|
442
|
+
async function prepareCollateralApprovals(client, { chainId, account, bundle, pulls, }) {
|
|
443
|
+
const requirements = await Promise.all([...pulls].map(([token, amount], tokenIndex) => {
|
|
444
|
+
// Validation only; the entity checks the same per-token bound in getRequirements().
|
|
445
|
+
(0, getMidnightApprovalRequirements_js_1.parseMidnightApprovalRequirements)({
|
|
446
|
+
viemClient: client,
|
|
447
|
+
chainId,
|
|
448
|
+
token,
|
|
449
|
+
owner: account,
|
|
450
|
+
spender: bundle,
|
|
451
|
+
amount,
|
|
452
|
+
});
|
|
453
|
+
return (0, requirements_js_1.getTokenRequirements)(client, {
|
|
454
|
+
chainId,
|
|
455
|
+
owner: account,
|
|
456
|
+
token,
|
|
457
|
+
spender: bundle,
|
|
458
|
+
amount,
|
|
459
|
+
approvalId: (index) => `${supplyActionId}:approval:${tokenIndex}:${index}`,
|
|
460
|
+
});
|
|
461
|
+
}));
|
|
462
|
+
return requirements.flatMap(({ approvals }) => approvals);
|
|
463
|
+
}
|
|
464
|
+
function storedBorrowParams({ chainId, market, target, receiver, takeableOffers, deadline, referralFeePct, referralFeeRecipient, }) {
|
|
465
|
+
if (target.type !== "assets" && target.type !== "units") {
|
|
466
|
+
throw (0, validation_js_2.invalidSellTargetType)("$.inputs.target");
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
chainId,
|
|
470
|
+
market: (0, market_js_1.storedMarketTuple)(market),
|
|
471
|
+
target,
|
|
472
|
+
receiver,
|
|
473
|
+
takeableOffers: (0, market_js_1.storedFills)(takeableOffers),
|
|
474
|
+
deadline,
|
|
475
|
+
referralFeePct,
|
|
476
|
+
referralFeeRecipient,
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function storedSupplyBorrowParams({ inputs }) {
|
|
480
|
+
return {
|
|
481
|
+
...storedBorrowParams(inputs),
|
|
482
|
+
collateralSupplies: inputs.collateralSupplies.map(({ collateralIndex, assets }) => ({ collateralIndex, assets })),
|
|
483
|
+
nativeAmount: inputs.nativeAssets,
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/** @internal Encodes the prepared borrow from persisted inputs without state reads. */
|
|
487
|
+
function buildMidnightTakeBorrow(action) {
|
|
488
|
+
if (action.type !== supplyActionId) {
|
|
489
|
+
return (0, takeBorrow_js_1.midnightTakeBorrow)(storedBorrowParams(action.inputs));
|
|
490
|
+
}
|
|
491
|
+
(0, market_js_1.validateStoredCollateralOrder)(action.inputs.market.collateralParams, "$.inputs.market.collateralParams");
|
|
492
|
+
validateStoredSuppliesArray(action.inputs.collateralSupplies, "$.inputs.collateralSupplies");
|
|
493
|
+
for (const [index, supply] of action.inputs.collateralSupplies.entries()) {
|
|
494
|
+
(0, validation_js_1.getPlanObject)(supply, `$.inputs.collateralSupplies[${index}]`);
|
|
495
|
+
}
|
|
496
|
+
const { type } = (0, validation_js_1.getPlanObject)(action.inputs.target, "$.inputs.target");
|
|
497
|
+
if (type !== "assets" && type !== "units") {
|
|
498
|
+
throw (0, validation_js_2.invalidSellTargetType)("$.inputs.target");
|
|
499
|
+
}
|
|
500
|
+
return (0, supplyCollateralTakeBorrow_js_1.midnightSupplyCollateralTakeBorrow)(storedSupplyBorrowParams(action));
|
|
501
|
+
}
|
|
502
|
+
function validateStoredSuppliesArray(value, path) {
|
|
503
|
+
if (!Array.isArray(value)) {
|
|
504
|
+
throw new error_js_2.InvalidTransactionPlanError({
|
|
505
|
+
path,
|
|
506
|
+
reason: "expected an array",
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* @internal Validates a stored collateral supply and borrow recipe: the sell shape, the
|
|
512
|
+
* collateral order, the supply and native funding fields, then the action's clock-free parse
|
|
513
|
+
* checks on the stored inputs.
|
|
514
|
+
*/
|
|
515
|
+
function validateMidnightSupplyCollateralTakeBorrowPlanAction(action, path) {
|
|
516
|
+
(0, validation_js_2.validateMidnightSellPlanAction)(action, path);
|
|
517
|
+
const inputsPath = `${path}.inputs`;
|
|
518
|
+
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, inputsPath);
|
|
519
|
+
(0, market_js_1.validateStoredCollateralOrder)(inputs.market.collateralParams, `${inputsPath}.market.collateralParams`);
|
|
520
|
+
const suppliesPath = `${inputsPath}.collateralSupplies`;
|
|
521
|
+
validateStoredSuppliesArray(inputs.collateralSupplies, suppliesPath);
|
|
522
|
+
for (const [index, supply] of inputs.collateralSupplies.entries()) {
|
|
523
|
+
const supplyPath = `${suppliesPath}[${index}]`;
|
|
524
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(supply, supplyPath), {
|
|
525
|
+
path: supplyPath,
|
|
526
|
+
fields: { collateralIndex: "uint256 bigint", assets: "uint128 bigint" },
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
if (inputs.nativeAssets !== undefined) {
|
|
530
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
531
|
+
path: inputsPath,
|
|
532
|
+
fields: { nativeAssets: "uint256 bigint" },
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
(0, supplyCollateralTakeBorrow_js_1.parseMidnightSupplyCollateralTakeBorrow)(storedSupplyBorrowParams(action));
|
|
537
|
+
}
|
|
538
|
+
catch (cause) {
|
|
539
|
+
throw new error_js_2.InvalidTransactionPlanError({
|
|
540
|
+
path: inputsPath,
|
|
541
|
+
reason: "expected a valid Midnight collateral supply and borrow",
|
|
542
|
+
cause,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Market } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import { type MidnightTakeLendParams } from "../../actions/midnight/takeLend.js";
|
|
4
|
+
import { type IntentParams } from "../intent.js";
|
|
5
|
+
import type { Action, TransactionPlan } from "../types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Inputs for preparing a fixed-rate lend from caller-selected borrow offers.
|
|
8
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
9
|
+
*/
|
|
10
|
+
export interface MidnightTakeLendPlanParams extends Omit<IntentParams, "supportSignature" | "deployless">, Pick<MidnightTakeLendParams, "target" | "takeableOffers" | "nativeAmount" | "maxContinuousFee"> {
|
|
11
|
+
/** Hydrated market snapshot used for validation and fill feasibility. */
|
|
12
|
+
readonly marketData: Market;
|
|
13
|
+
/** Reference timestamp in seconds; defaults to the device clock. */
|
|
14
|
+
readonly now?: bigint;
|
|
15
|
+
/** Unix seconds; defaults to one hour after the reference timestamp. */
|
|
16
|
+
readonly expiresAt?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Prepares an ordered plan to lend through MidnightBundlesV2. Validates inputs with the same
|
|
20
|
+
* parse-once constructor and fill feasibility check as the entity `takeLend`, then reads the
|
|
21
|
+
* registry targets' bytecode, allowance, and authorization. It does not read live fill availability.
|
|
22
|
+
* On an assets target, an offer is dropped from the stored fills only when its price would revert
|
|
23
|
+
* the bundle at every time up to the deadline; one that is invalid for part of that window stays, so
|
|
24
|
+
* simulate before sending.
|
|
25
|
+
* Even with native input, the bundle needs allowance for the full loan-token pull.
|
|
26
|
+
* @param client - Viem client connected to the intent chain for prerequisite reads.
|
|
27
|
+
* @param params - Sender, market snapshot, ABI-ready fills, target bounds, funding and expiry.
|
|
28
|
+
* @param params.now - Optional reference timestamp in Unix seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
|
|
29
|
+
* @returns A frozen plan with any approval and authorization steps before the lend.
|
|
30
|
+
* @throws {InvalidBigIntInputError} If a supplied non-null `now`, `maxContinuousFee` or a target amount
|
|
31
|
+
* is not a bigint.
|
|
32
|
+
* @throws {ZeroAccountError} If `account` is the zero address.
|
|
33
|
+
* @throws {NonIntegerInputError} If `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
34
|
+
* @throws {NonPositiveInputError} If `expiresAt`, the target amount, `minUnits` or
|
|
35
|
+
* `maxBuyerAssets` is not positive.
|
|
36
|
+
* @throws {ExpiredDeadlineError} If expiry is at or before the reference timestamp.
|
|
37
|
+
* @throws {NegativeInputError} If `referralFee.bps`, an offer cap, `maxContinuousFee` or
|
|
38
|
+
* `nativeAmount` is negative.
|
|
39
|
+
* @throws {InputExceedsMaxError} If `referralFee.bps` exceeds 1,000 (10%), a target amount or offer
|
|
40
|
+
* cap exceeds uint128, `maxContinuousFee` exceeds uint256, or `nativeAmount` exceeds the pull.
|
|
41
|
+
* @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
42
|
+
* @throws {MidnightTakeDeadlineTooFarError} If expiry is more than one hour away.
|
|
43
|
+
* @throws {InvalidTransactionPlanError} If `account` is malformed or the target type is neither assets nor units.
|
|
44
|
+
* @throws {ChainIdMismatchError} If the client, transport or market is on a different chain.
|
|
45
|
+
* @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
|
|
46
|
+
* @throws {UnknownAddressError} If the chain has no `midnightBundlesV2` deployment.
|
|
47
|
+
* @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
|
|
48
|
+
* @throws {EmptyMidnightTakeableOffersError} If no offers are supplied.
|
|
49
|
+
* @throws {MidnightOfferSideMismatchError} If an offer is not borrow-side.
|
|
50
|
+
* @throws {MidnightTakeableOfferMarketMismatchError} If an offer trades a different market.
|
|
51
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} If an offer routes seller proceeds to the zero address.
|
|
52
|
+
* @throws {UnboundedMidnightTakeInputError} If `target.units` or `target.maxBuyerAssets` is `maxUint256`.
|
|
53
|
+
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no recipient.
|
|
54
|
+
* @throws {MidnightContractReceiverError} If the referral fee recipient is a Midnight protocol or market token contract.
|
|
55
|
+
* @throws {InvalidMidnightNativeAmountTypeError} If `nativeAmount` is not a bigint.
|
|
56
|
+
* @throws {MidnightCalldataEncodingError} If an offer field, including a `maxUnits` or
|
|
57
|
+
* `maxAssets` cap that is not a bigint, cannot be ABI-encoded.
|
|
58
|
+
* @throws {ChainWNativeMissingError} If wNative is not configured for the chain.
|
|
59
|
+
* @throws {NativeAmountOnNonWNativeAssetError} If positive native input is used with another loan token.
|
|
60
|
+
* @throws {MidnightContinuousFeeAboveMaxError} If `maxContinuousFee` is below the market's continuous fee.
|
|
61
|
+
* @throws {MidnightTakeableOffersNotFillableError} If every offer is expired, not yet started,
|
|
62
|
+
* self-made, capped below the market fee or otherwise dead.
|
|
63
|
+
* @throws {MidnightTakeTargetUnreachableError} If the live offers cannot meet the target and its bounds.
|
|
64
|
+
* @throws {MissingContractCodeError} If either registered Midnight target has no deployed code.
|
|
65
|
+
* @throws {viem.BaseError} If an `eth_chainId` request or prerequisite read fails.
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { buildTransactions, prepareMidnightTakeLend } from "@morpho-org/morpho-sdk";
|
|
69
|
+
* import { fetchMidnightMarket } from "@morpho-org/morpho-sdk/fetch";
|
|
70
|
+
* import { MidnightApi } from "@morpho-org/morpho-sdk/midnight-api";
|
|
71
|
+
* import { type Address, createPublicClient, type Hex, http, maxUint256 } from "viem";
|
|
72
|
+
* import { base } from "viem/chains";
|
|
73
|
+
*
|
|
74
|
+
* export async function takeLendTransactions(marketId: Hex, account: Address) {
|
|
75
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
76
|
+
* const marketData = await fetchMidnightMarket(client, { marketId });
|
|
77
|
+
* const quote = await new MidnightApi().fetchBookQuote({
|
|
78
|
+
* marketId, side: "asks", units: 1_000_000n, taker: account,
|
|
79
|
+
* });
|
|
80
|
+
* const plan = await prepareMidnightTakeLend(client, {
|
|
81
|
+
* chainId: base.id, account, marketData, takeableOffers: quote.data.takeableOffers,
|
|
82
|
+
* target: { type: "units", units: 1_000_000n, maxBuyerAssets: 990_000n },
|
|
83
|
+
* maxContinuousFee: maxUint256,
|
|
84
|
+
* });
|
|
85
|
+
* // Simulate, then send in order from plan.account on plan.chainId.
|
|
86
|
+
* return buildTransactions(plan);
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
90
|
+
*/
|
|
91
|
+
export declare function prepareMidnightTakeLend(client: Client, params: MidnightTakeLendPlanParams): Promise<TransactionPlan>;
|
|
92
|
+
type TakeLendAction = Extract<Action, {
|
|
93
|
+
type: "midnightTakeLend";
|
|
94
|
+
}>;
|
|
95
|
+
/** @internal Encodes the prepared lend from persisted inputs without state reads. */
|
|
96
|
+
export declare function buildMidnightTakeLend({ inputs: { chainId, market, target, takeableOffers, maxContinuousFee, deadline, referralFeePct, referralFeeRecipient, nativeAssets, }, }: TakeLendAction): Readonly<import("../../index.js").Transaction<import("../../index.js").MidnightTakeLendAction>>;
|
|
97
|
+
/** @internal Validates the restored recipe shape without encoding or fetching offers. */
|
|
98
|
+
export declare function validateMidnightTakeLendPlanAction(action: Record<string, unknown>, path: string): void;
|
|
99
|
+
export {};
|