@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AccrualPosition, MarketParams, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { getBlueBundlesV1ReferralFeeAssets, parseBlueBundlesV1Common, } from "../../actions/blue/common.js";
|
|
5
5
|
import { blueRepayWithdrawCollateral } from "../../actions/blue/repayWithdrawCollateral.js";
|
|
@@ -9,11 +9,13 @@ import { DEFAULT_LLTV_BUFFER, validateChainId, validatePositionHealthAfterWithdr
|
|
|
9
9
|
import { parseNativeFunding } from "../../helpers/parse.js";
|
|
10
10
|
import { quoteBlueRepay, quoteBlueRepayFunding, } from "../../helpers/quoteBlueRepay.js";
|
|
11
11
|
import { MutuallyExclusiveRepayAmountsError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
12
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
12
13
|
import { BlueSnapshotStateMismatchError, IncompleteTransactionPlanError, InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
|
|
13
14
|
import { getVaultPermit, validateTokenPermitRequest } from "../permit.js";
|
|
14
15
|
import { getPlanObject, validatePlanFields } from "../validation.js";
|
|
15
16
|
import { validateMorphoAuthorizationRequest } from "./authorization.js";
|
|
16
17
|
import { prepareBlue, } from "./prepare.js";
|
|
18
|
+
import { BUNDLES_COMMON_FIELDS, signatureRoles, validateStoredBlueMarketParams, } from "./stored.js";
|
|
17
19
|
/**
|
|
18
20
|
* Prepares one BlueBundlesV1 repayment and collateral withdrawal from caller-fetched snapshots.
|
|
19
21
|
* Withdrawal health uses the expiry floored at max(now, lastUpdate); expiries more than
|
|
@@ -73,23 +75,24 @@ import { prepareBlue, } from "./prepare.js";
|
|
|
73
75
|
*/
|
|
74
76
|
export async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
75
77
|
const id = "blueRepayWithdrawCollateral";
|
|
76
|
-
const
|
|
78
|
+
const captured = captureRepayWithdrawInputs(params);
|
|
79
|
+
const { chainId, account, marketId, marketData, now } = captured;
|
|
77
80
|
let inputs;
|
|
78
|
-
const prepared = await prepareBlue({ client, params:
|
|
79
|
-
const marketParams =
|
|
81
|
+
const prepared = await prepareBlue({ client, params: captured }, (intent) => {
|
|
82
|
+
const marketParams = marketData.market.params;
|
|
80
83
|
// Reject chain and referral mismatches before deriving a repayment quote.
|
|
81
|
-
validateChainId(client.chain?.id,
|
|
84
|
+
validateChainId(client.chain?.id, chainId);
|
|
82
85
|
const common = parseBlueBundlesV1Common({
|
|
83
|
-
chainId
|
|
84
|
-
userAddress:
|
|
86
|
+
chainId,
|
|
87
|
+
userAddress: account,
|
|
85
88
|
deadline: intent.deadline,
|
|
86
89
|
referralFeePct: intent.referralFeePct,
|
|
87
90
|
referralFeeRecipient: intent.referralFeeRecipient,
|
|
88
91
|
});
|
|
89
|
-
const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params);
|
|
92
|
+
const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params, marketId);
|
|
90
93
|
const quoteParams = {
|
|
91
|
-
positionData: getMatchingPosition(
|
|
92
|
-
marketId
|
|
94
|
+
positionData: getMatchingPosition(captured),
|
|
95
|
+
marketId,
|
|
93
96
|
repayAssets,
|
|
94
97
|
repayShares,
|
|
95
98
|
deadline: intent.deadline,
|
|
@@ -100,7 +103,7 @@ export async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
100
103
|
const maxRepayAssets = expectedRepayAssets +
|
|
101
104
|
getBlueBundlesV1ReferralFeeAssets(expectedRepayAssets, common.referralFeePct);
|
|
102
105
|
const nativeValue = parseNativeFunding({
|
|
103
|
-
chainId
|
|
106
|
+
chainId,
|
|
104
107
|
token: marketParams.loanToken,
|
|
105
108
|
fundedAmount: maxRepayAssets,
|
|
106
109
|
nativeAmount: params.funding?.type === "native" ? maxRepayAssets : undefined,
|
|
@@ -115,13 +118,13 @@ export async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
115
118
|
positionData: postRepayPosition,
|
|
116
119
|
withdrawAmount: collateralAssets,
|
|
117
120
|
lltv: marketParams.lltv,
|
|
118
|
-
marketId
|
|
121
|
+
marketId,
|
|
119
122
|
});
|
|
120
123
|
}
|
|
121
124
|
const tx = blueRepayWithdrawCollateral({
|
|
122
|
-
market: { chainId
|
|
125
|
+
market: { chainId, marketParams },
|
|
123
126
|
args: {
|
|
124
|
-
userAddress:
|
|
127
|
+
userAddress: account,
|
|
125
128
|
repayAssets,
|
|
126
129
|
repayShares,
|
|
127
130
|
maxRepayAssets,
|
|
@@ -137,8 +140,8 @@ export async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
137
140
|
inputs = {
|
|
138
141
|
...args,
|
|
139
142
|
...(nativeAmount !== undefined && { nativeAssets: nativeAmount }),
|
|
140
|
-
chainId
|
|
141
|
-
account
|
|
143
|
+
chainId,
|
|
144
|
+
account,
|
|
142
145
|
marketParams: {
|
|
143
146
|
loanToken: marketParams.loanToken,
|
|
144
147
|
collateralToken: marketParams.collateralToken,
|
|
@@ -155,27 +158,20 @@ export async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
155
158
|
needsAuthorization: args.collateralAssets > 0n,
|
|
156
159
|
};
|
|
157
160
|
});
|
|
158
|
-
await validateClientChainId(client,
|
|
161
|
+
await validateClientChainId(client, chainId);
|
|
159
162
|
if (inputs === undefined) {
|
|
160
163
|
throw new IncompleteTransactionPlanError(id);
|
|
161
164
|
}
|
|
162
|
-
const signatureRequestIds =
|
|
163
|
-
.
|
|
164
|
-
.
|
|
165
|
-
|
|
166
|
-
signatureRequestIds.morphoAuthorization =
|
|
167
|
-
prepared.morphoAuthorizationRequestId;
|
|
168
|
-
}
|
|
165
|
+
const signatureRequestIds = signatureRoles({
|
|
166
|
+
tokenPermit: prepared.signatureRequests.find((request) => request.kind === "permit")?.id,
|
|
167
|
+
morphoAuthorization: prepared.morphoAuthorizationRequestId,
|
|
168
|
+
});
|
|
169
169
|
const authorization = prepared.signatureRequests.find((request) => request.kind === "morphoAuthorization");
|
|
170
170
|
if (authorization !== undefined) {
|
|
171
171
|
inputs = { ...inputs, authorizationNonce: authorization.args.nonce };
|
|
172
172
|
}
|
|
173
|
-
return
|
|
174
|
-
|
|
175
|
-
chainId: params.chainId,
|
|
176
|
-
account: params.account,
|
|
177
|
-
expiresAt: prepared.intent.expiresAt,
|
|
178
|
-
calldataOrigin: prepared.intent.calldataOrigin,
|
|
173
|
+
return freezePlan({
|
|
174
|
+
...planHeader({ chainId, account }, prepared.intent),
|
|
179
175
|
steps: [
|
|
180
176
|
...prepared.steps,
|
|
181
177
|
{
|
|
@@ -185,7 +181,7 @@ export async function prepareBlueRepayWithdrawCollateral(client, params) {
|
|
|
185
181
|
},
|
|
186
182
|
],
|
|
187
183
|
signatureRequests: prepared.signatureRequests,
|
|
188
|
-
})
|
|
184
|
+
}, { detach: true });
|
|
189
185
|
}
|
|
190
186
|
function getRepayWithdrawLabel(inputs) {
|
|
191
187
|
if (inputs.collateralAssets === 0n) {
|
|
@@ -206,6 +202,25 @@ const MARKET_STATE_FIELDS = [
|
|
|
206
202
|
"price",
|
|
207
203
|
"rateAtTarget",
|
|
208
204
|
];
|
|
205
|
+
function captureRepayWithdrawInputs(params) {
|
|
206
|
+
const { chainId, account, marketId, marketData, positionData } = params;
|
|
207
|
+
return {
|
|
208
|
+
chainId,
|
|
209
|
+
account,
|
|
210
|
+
marketId,
|
|
211
|
+
marketData: { chainId: marketData.chainId, market: marketData.market },
|
|
212
|
+
positionData: {
|
|
213
|
+
chainId: positionData.chainId,
|
|
214
|
+
position: positionData.position,
|
|
215
|
+
},
|
|
216
|
+
now: params.now ?? Time.timestamp(),
|
|
217
|
+
expiresAt: params.expiresAt,
|
|
218
|
+
supportSignature: params.supportSignature,
|
|
219
|
+
referralFee: params.referralFee,
|
|
220
|
+
calldataOrigin: params.calldataOrigin,
|
|
221
|
+
deployless: params.deployless,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
209
224
|
function getMatchingPosition(params) {
|
|
210
225
|
const { position } = params.positionData;
|
|
211
226
|
const positionMarket = position.market;
|
|
@@ -247,8 +262,8 @@ function quoteWithdrawal(quoteParams, collateralAssets) {
|
|
|
247
262
|
}),
|
|
248
263
|
});
|
|
249
264
|
}
|
|
250
|
-
function getRepayWithdrawAmounts(params) {
|
|
251
|
-
const { collateralAssets
|
|
265
|
+
function getRepayWithdrawAmounts(params, marketId) {
|
|
266
|
+
const { collateralAssets } = params;
|
|
252
267
|
const repayAssets = params.repayAssets ?? 0n;
|
|
253
268
|
const repayShares = params.repayShares ?? 0n;
|
|
254
269
|
if (repayAssets < 0n) {
|
|
@@ -362,9 +377,7 @@ export function validateRepayWithdrawCollateralPlanAction(action, path) {
|
|
|
362
377
|
maxRepayAssets: "uint256 bigint",
|
|
363
378
|
collateralAssets: "uint256 bigint",
|
|
364
379
|
maxLtv: "uint256 bigint",
|
|
365
|
-
|
|
366
|
-
referralFeePct: "uint256 bigint",
|
|
367
|
-
referralFeeRecipient: "address",
|
|
380
|
+
...BUNDLES_COMMON_FIELDS,
|
|
368
381
|
},
|
|
369
382
|
});
|
|
370
383
|
if (inputs.repayAssets > 0n &&
|
|
@@ -380,16 +393,7 @@ export function validateRepayWithdrawCollateralPlanAction(action, path) {
|
|
|
380
393
|
fields: { nativeAssets: "uint256 bigint" },
|
|
381
394
|
});
|
|
382
395
|
}
|
|
383
|
-
|
|
384
|
-
path: `${path}.inputs.marketParams`,
|
|
385
|
-
fields: {
|
|
386
|
-
loanToken: "address",
|
|
387
|
-
collateralToken: "address",
|
|
388
|
-
oracle: "address",
|
|
389
|
-
irm: "address",
|
|
390
|
-
lltv: "uint256 bigint",
|
|
391
|
-
},
|
|
392
|
-
});
|
|
396
|
+
validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
393
397
|
const ids = getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
394
398
|
if (inputs.authorizationNonce !== undefined ||
|
|
395
399
|
ids.morphoAuthorization !== undefined) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @internal The stored BlueBundlesV1 deadline and referral fields, in their validation order. */
|
|
2
|
+
export declare const BUNDLES_COMMON_FIELDS: {
|
|
3
|
+
readonly deadline: "uint256 bigint";
|
|
4
|
+
readonly referralFeePct: "uint256 bigint";
|
|
5
|
+
readonly referralFeeRecipient: "address";
|
|
6
|
+
};
|
|
7
|
+
/** @internal Validates a stored five-field Blue market tuple at `path`. */
|
|
8
|
+
export declare function validateStoredBlueMarketParams(value: unknown, path: string): void;
|
|
9
|
+
/** @internal Validates a stored Blue market tuple that also carries its 32-byte market ID. */
|
|
10
|
+
export declare function validateStoredBlueMarket(value: unknown, path: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* @internal Validates stored Vault V2 reallocations at `path`, checking each source market tuple
|
|
13
|
+
* with `marketParams`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateStoredReallocations(reallocations: readonly unknown[], { path, marketParams, }: {
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly marketParams: (value: unknown, path: string) => void;
|
|
18
|
+
}): void;
|
|
19
|
+
/** @internal Builds an action's role map with only the roles that reference a request, in argument order. */
|
|
20
|
+
export declare function signatureRoles({ tokenPermit, morphoAuthorization, }: {
|
|
21
|
+
readonly tokenPermit?: string;
|
|
22
|
+
readonly morphoAuthorization?: string;
|
|
23
|
+
}): {
|
|
24
|
+
tokenPermit?: string | undefined;
|
|
25
|
+
morphoAuthorization?: string | undefined;
|
|
26
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { InvalidTransactionPlanError } from "../error.js";
|
|
2
|
+
import { getPlanObject, validatePlanFields } from "../validation.js";
|
|
3
|
+
/** @internal The stored BlueBundlesV1 deadline and referral fields, in their validation order. */
|
|
4
|
+
export const BUNDLES_COMMON_FIELDS = {
|
|
5
|
+
deadline: "uint256 bigint",
|
|
6
|
+
referralFeePct: "uint256 bigint",
|
|
7
|
+
referralFeeRecipient: "address",
|
|
8
|
+
};
|
|
9
|
+
const MARKET_PARAMS_FIELDS = {
|
|
10
|
+
loanToken: "address",
|
|
11
|
+
collateralToken: "address",
|
|
12
|
+
oracle: "address",
|
|
13
|
+
irm: "address",
|
|
14
|
+
lltv: "uint256 bigint",
|
|
15
|
+
};
|
|
16
|
+
/** @internal Validates a stored five-field Blue market tuple at `path`. */
|
|
17
|
+
export function validateStoredBlueMarketParams(value, path) {
|
|
18
|
+
validatePlanFields(getPlanObject(value, path), {
|
|
19
|
+
path,
|
|
20
|
+
fields: MARKET_PARAMS_FIELDS,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** @internal Validates a stored Blue market tuple that also carries its 32-byte market ID. */
|
|
24
|
+
export function validateStoredBlueMarket(value, path) {
|
|
25
|
+
const market = getPlanObject(value, path);
|
|
26
|
+
validatePlanFields(market, {
|
|
27
|
+
path,
|
|
28
|
+
fields: { id: "hex", ...MARKET_PARAMS_FIELDS },
|
|
29
|
+
});
|
|
30
|
+
if (typeof market.id !== "string" || market.id.length !== 66) {
|
|
31
|
+
throw new InvalidTransactionPlanError({
|
|
32
|
+
path: `${path}.id`,
|
|
33
|
+
reason: "expected a 32-byte market ID",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @internal Validates stored Vault V2 reallocations at `path`, checking each source market tuple
|
|
39
|
+
* with `marketParams`.
|
|
40
|
+
*/
|
|
41
|
+
export function validateStoredReallocations(reallocations, { path, marketParams, }) {
|
|
42
|
+
for (const [index, value] of reallocations.entries()) {
|
|
43
|
+
const entryPath = `${path}[${index}]`;
|
|
44
|
+
const entry = getPlanObject(value, entryPath);
|
|
45
|
+
validatePlanFields(entry, {
|
|
46
|
+
path: entryPath,
|
|
47
|
+
fields: {
|
|
48
|
+
vault: "address",
|
|
49
|
+
assets: "uint256 bigint",
|
|
50
|
+
penalty: "uint256 bigint",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
validatePlanFields(getPlanObject(entry.to, `${entryPath}.to`), {
|
|
54
|
+
path: `${entryPath}.to`,
|
|
55
|
+
fields: { adapter: "address" },
|
|
56
|
+
});
|
|
57
|
+
const from = getPlanObject(entry.from, `${entryPath}.from`);
|
|
58
|
+
if (from.type === "idle") {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (from.type !== "market") {
|
|
62
|
+
throw new InvalidTransactionPlanError({
|
|
63
|
+
path: `${entryPath}.from.type`,
|
|
64
|
+
reason: "expected market or idle",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
validatePlanFields(from, {
|
|
68
|
+
path: `${entryPath}.from`,
|
|
69
|
+
fields: { adapter: "address" },
|
|
70
|
+
});
|
|
71
|
+
marketParams(from.marketParams, `${entryPath}.from.marketParams`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** @internal Builds an action's role map with only the roles that reference a request, in argument order. */
|
|
75
|
+
export function signatureRoles({ tokenPermit, morphoAuthorization, }) {
|
|
76
|
+
return {
|
|
77
|
+
...(tokenPermit !== undefined && { tokenPermit }),
|
|
78
|
+
...(morphoAuthorization !== undefined && { morphoAuthorization }),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
2
|
import { blueSupply } from "../../actions/blue/supply.js";
|
|
4
3
|
import { normalizeBundlesCommonParams } from "../../actions/bundles/common.js";
|
|
5
4
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
5
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
6
6
|
import { InvalidTransactionPlanError } from "../error.js";
|
|
7
7
|
import { getVaultPermit, validateTokenPermitRequest } from "../permit.js";
|
|
8
8
|
import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
|
|
9
9
|
import { prepareBlue } from "./prepare.js";
|
|
10
|
+
import { BUNDLES_COMMON_FIELDS, validateStoredBlueMarketParams, } from "./stored.js";
|
|
10
11
|
/** @internal Validates the stored supply recipe without requiring class instances. */
|
|
11
12
|
export function validateBlueSupplyPlanAction(action, path) {
|
|
12
13
|
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
@@ -14,9 +15,7 @@ export function validateBlueSupplyPlanAction(action, path) {
|
|
|
14
15
|
path: `${path}.inputs`,
|
|
15
16
|
fields: {
|
|
16
17
|
assets: "uint256 bigint",
|
|
17
|
-
|
|
18
|
-
referralFeePct: "uint256 bigint",
|
|
19
|
-
referralFeeRecipient: "address",
|
|
18
|
+
...BUNDLES_COMMON_FIELDS,
|
|
20
19
|
},
|
|
21
20
|
});
|
|
22
21
|
if (inputs.nativeAssets !== undefined) {
|
|
@@ -26,17 +25,7 @@ export function validateBlueSupplyPlanAction(action, path) {
|
|
|
26
25
|
});
|
|
27
26
|
validateNativeAssets(inputs, `${path}.inputs.nativeAssets`);
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
validatePlanFields(market, {
|
|
31
|
-
path: `${path}.inputs.marketParams`,
|
|
32
|
-
fields: {
|
|
33
|
-
loanToken: "address",
|
|
34
|
-
collateralToken: "address",
|
|
35
|
-
oracle: "address",
|
|
36
|
-
irm: "address",
|
|
37
|
-
lltv: "uint256 bigint",
|
|
38
|
-
},
|
|
39
|
-
});
|
|
28
|
+
validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
40
29
|
getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
41
30
|
}
|
|
42
31
|
/**
|
|
@@ -151,12 +140,8 @@ export async function prepareBlueSupply(client, params) {
|
|
|
151
140
|
});
|
|
152
141
|
await validateClientChainId(client, chainId);
|
|
153
142
|
const { intent, steps, signatureRequests } = prepared;
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
chainId,
|
|
157
|
-
account,
|
|
158
|
-
expiresAt: intent.expiresAt,
|
|
159
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
143
|
+
return freezePlan({
|
|
144
|
+
...planHeader({ chainId, account }, intent),
|
|
160
145
|
steps: [
|
|
161
146
|
...steps,
|
|
162
147
|
{
|
|
@@ -179,7 +164,7 @@ export async function prepareBlueSupply(client, params) {
|
|
|
179
164
|
},
|
|
180
165
|
],
|
|
181
166
|
signatureRequests,
|
|
182
|
-
})
|
|
167
|
+
}, { detach: true });
|
|
183
168
|
}
|
|
184
169
|
/** @internal Binds an exact token permit to this supply's pull. */
|
|
185
170
|
export function validateBlueSupplyPermitRequest(request, action) {
|
|
@@ -45,7 +45,7 @@ export interface BlueSupplyCollateralPlanParams extends IntentParams, ReferenceT
|
|
|
45
45
|
* @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
|
|
46
46
|
* @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
|
|
47
47
|
* @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
|
|
48
|
-
* @param params.calldataOrigin - Optional non-empty hex bytes appended to
|
|
48
|
+
* @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
49
49
|
* @param params.deployless - Whether permit metadata reads may use deployless aggregation.
|
|
50
50
|
* @returns A frozen plan containing the collateral supply step and any token prerequisites.
|
|
51
51
|
* @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
2
|
import { zeroAddress } from "viem";
|
|
4
3
|
import { blueSupplyCollateral } from "../../actions/blue/supplyCollateral.js";
|
|
5
4
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
6
5
|
import { validateNativeAsset, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
|
|
7
6
|
import { NonPositiveInputError, } from "../../types/index.js";
|
|
7
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
8
8
|
import { InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
|
|
9
9
|
import { getSignedTokenPermit, validateTokenPermitRequest } from "../permit.js";
|
|
10
10
|
import { getPlanObject, validatePlanFields } from "../validation.js";
|
|
11
11
|
import { prepareBlue } from "./prepare.js";
|
|
12
|
+
import { BUNDLES_COMMON_FIELDS, signatureRoles } from "./stored.js";
|
|
12
13
|
const actionId = "blueSupplyCollateral";
|
|
13
14
|
/**
|
|
14
15
|
* Prepares a collateral-only supply through BlueBundlesV1 from a caller-fetched market snapshot.
|
|
@@ -28,7 +29,7 @@ const actionId = "blueSupplyCollateral";
|
|
|
28
29
|
* @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
|
|
29
30
|
* @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
|
|
30
31
|
* @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
|
|
31
|
-
* @param params.calldataOrigin - Optional non-empty hex bytes appended to
|
|
32
|
+
* @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
|
|
32
33
|
* @param params.deployless - Whether permit metadata reads may use deployless aggregation.
|
|
33
34
|
* @returns A frozen plan containing the collateral supply step and any token prerequisites.
|
|
34
35
|
* @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
|
|
@@ -93,12 +94,8 @@ export async function prepareBlueSupplyCollateral(client, params) {
|
|
|
93
94
|
await validateClientChainId(client, chainId);
|
|
94
95
|
}
|
|
95
96
|
const tokenPermit = signatureRequests.find(({ kind }) => kind === "permit");
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
chainId,
|
|
99
|
-
account,
|
|
100
|
-
expiresAt: intent.expiresAt,
|
|
101
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
97
|
+
return freezePlan({
|
|
98
|
+
...planHeader({ chainId, account }, intent),
|
|
102
99
|
steps: [
|
|
103
100
|
...steps,
|
|
104
101
|
{
|
|
@@ -116,14 +113,14 @@ export async function prepareBlueSupplyCollateral(client, params) {
|
|
|
116
113
|
referralFeePct: intent.referralFeePct,
|
|
117
114
|
referralFeeRecipient: intent.referralFeeRecipient ?? zeroAddress,
|
|
118
115
|
},
|
|
119
|
-
signatureRequestIds:
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
signatureRequestIds: signatureRoles({
|
|
117
|
+
tokenPermit: tokenPermit?.id,
|
|
118
|
+
}),
|
|
122
119
|
},
|
|
123
120
|
},
|
|
124
121
|
],
|
|
125
122
|
signatureRequests,
|
|
126
|
-
})
|
|
123
|
+
}, { detach: true });
|
|
127
124
|
}
|
|
128
125
|
/** @internal Validates the stored collateral supply action and its token permit role. */
|
|
129
126
|
export function validateSupplyCollateralPlanAction(action, path) {
|
|
@@ -133,9 +130,7 @@ export function validateSupplyCollateralPlanAction(action, path) {
|
|
|
133
130
|
path: inputsPath,
|
|
134
131
|
fields: {
|
|
135
132
|
collateralAssets: "uint256 bigint",
|
|
136
|
-
|
|
137
|
-
referralFeePct: "uint256 bigint",
|
|
138
|
-
referralFeeRecipient: "address",
|
|
133
|
+
...BUNDLES_COMMON_FIELDS,
|
|
139
134
|
},
|
|
140
135
|
});
|
|
141
136
|
const marketPath = `${inputsPath}.marketParams`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MathLib } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { blueSupplyCollateralBorrow } from "../../actions/blue/supplyCollateralBorrow.js";
|
|
5
5
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
@@ -7,11 +7,13 @@ import { getBlueBundlesV1QuoteTimestamp } from "../../helpers/getBlueBundlesV1Qu
|
|
|
7
7
|
import { DEFAULT_LLTV_BUFFER, validatePositionHealth, } from "../../helpers/index.js";
|
|
8
8
|
import { parseNativeFunding } from "../../helpers/parse.js";
|
|
9
9
|
import { MissingAccrualPositionError, } from "../../types/index.js";
|
|
10
|
+
import { freezePlan, planHeader } from "../assemble.js";
|
|
10
11
|
import { IncompleteTransactionPlanError, InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
|
|
11
12
|
import { getVaultPermit, validateTokenPermitRequest } from "../permit.js";
|
|
12
13
|
import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
|
|
13
14
|
import { validateMorphoAuthorizationRequest } from "./authorization.js";
|
|
14
15
|
import { prepareBlue, } from "./prepare.js";
|
|
16
|
+
import { signatureRoles, validateStoredBlueMarket, validateStoredReallocations, } from "./stored.js";
|
|
15
17
|
/**
|
|
16
18
|
* Prepares collateral funding and Morpho authorization for one BlueBundlesV1 call. Snapshots
|
|
17
19
|
* are validated before reads; health uses the expiry floored at max(now, lastUpdate).
|
|
@@ -156,14 +158,8 @@ export async function prepareBlueSupplyCollateralBorrow(client, params) {
|
|
|
156
158
|
await validateClientChainId(client, chainId);
|
|
157
159
|
const authorization = prepared.signatureRequests.find((request) => request.id === prepared.morphoAuthorizationRequestId);
|
|
158
160
|
const permit = prepared.signatureRequests.find((request) => request.kind === "permit");
|
|
159
|
-
return
|
|
160
|
-
|
|
161
|
-
chainId,
|
|
162
|
-
account,
|
|
163
|
-
expiresAt: prepared.intent.expiresAt,
|
|
164
|
-
...(prepared.intent.calldataOrigin && {
|
|
165
|
-
calldataOrigin: prepared.intent.calldataOrigin,
|
|
166
|
-
}),
|
|
161
|
+
return freezePlan({
|
|
162
|
+
...planHeader({ chainId, account }, prepared.intent),
|
|
167
163
|
steps: [
|
|
168
164
|
...prepared.steps,
|
|
169
165
|
{
|
|
@@ -199,15 +195,15 @@ export async function prepareBlueSupplyCollateralBorrow(client, params) {
|
|
|
199
195
|
authorizationNonce: authorization.args.nonce,
|
|
200
196
|
}),
|
|
201
197
|
},
|
|
202
|
-
signatureRequestIds: {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
},
|
|
198
|
+
signatureRequestIds: signatureRoles({
|
|
199
|
+
tokenPermit: permit?.id,
|
|
200
|
+
morphoAuthorization: authorization?.id,
|
|
201
|
+
}),
|
|
206
202
|
},
|
|
207
203
|
},
|
|
208
204
|
],
|
|
209
205
|
signatureRequests: prepared.signatureRequests,
|
|
210
|
-
})
|
|
206
|
+
}, { detach: true });
|
|
211
207
|
}
|
|
212
208
|
function captureSupplyBorrowIntent(params) {
|
|
213
209
|
const { chainId, account, marketId, marketData, positionData, expiresAt, referralFee, supportSignature, calldataOrigin, deployless, now = Time.timestamp(), } = params;
|
|
@@ -294,26 +290,6 @@ export function buildBlueSupplyCollateralBorrow(action, requests) {
|
|
|
294
290
|
},
|
|
295
291
|
});
|
|
296
292
|
}
|
|
297
|
-
function validateMarket(value, path) {
|
|
298
|
-
const market = getPlanObject(value, path);
|
|
299
|
-
validatePlanFields(market, {
|
|
300
|
-
path,
|
|
301
|
-
fields: {
|
|
302
|
-
id: "hex",
|
|
303
|
-
loanToken: "address",
|
|
304
|
-
collateralToken: "address",
|
|
305
|
-
oracle: "address",
|
|
306
|
-
irm: "address",
|
|
307
|
-
lltv: "uint256 bigint",
|
|
308
|
-
},
|
|
309
|
-
});
|
|
310
|
-
if (typeof market.id !== "string" || market.id.length !== 66) {
|
|
311
|
-
throw new InvalidTransactionPlanError({
|
|
312
|
-
path: `${path}.id`,
|
|
313
|
-
reason: "expected a 32-byte market ID",
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
293
|
/** @internal Validates the complete stored input and reallocation shape. */
|
|
318
294
|
export function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
319
295
|
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
@@ -346,7 +322,7 @@ export function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
|
346
322
|
type: "address",
|
|
347
323
|
});
|
|
348
324
|
}
|
|
349
|
-
|
|
325
|
+
validateStoredBlueMarket(inputs.marketParams, `${path}.inputs.marketParams`);
|
|
350
326
|
const ids = getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
351
327
|
for (const key of Object.keys(ids)) {
|
|
352
328
|
if (key !== "tokenPermit" && key !== "morphoAuthorization") {
|
|
@@ -373,34 +349,8 @@ export function validateSupplyCollateralBorrowPlanAction(action, path) {
|
|
|
373
349
|
type: "uint256 bigint",
|
|
374
350
|
});
|
|
375
351
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
path: entryPath,
|
|
381
|
-
fields: {
|
|
382
|
-
vault: "address",
|
|
383
|
-
assets: "uint256 bigint",
|
|
384
|
-
penalty: "uint256 bigint",
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
validatePlanFields(getPlanObject(entry.to, `${entryPath}.to`), {
|
|
388
|
-
path: `${entryPath}.to`,
|
|
389
|
-
fields: { adapter: "address" },
|
|
390
|
-
});
|
|
391
|
-
const from = getPlanObject(entry.from, `${entryPath}.from`);
|
|
392
|
-
if (from.type === "market") {
|
|
393
|
-
validatePlanFields(from, {
|
|
394
|
-
path: `${entryPath}.from`,
|
|
395
|
-
fields: { adapter: "address" },
|
|
396
|
-
});
|
|
397
|
-
validateMarket(from.marketParams, `${entryPath}.from.marketParams`);
|
|
398
|
-
}
|
|
399
|
-
else if (from.type !== "idle") {
|
|
400
|
-
throw new InvalidTransactionPlanError({
|
|
401
|
-
path: `${entryPath}.from.type`,
|
|
402
|
-
reason: "expected market or idle",
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
}
|
|
352
|
+
validateStoredReallocations(inputs.reallocations, {
|
|
353
|
+
path: `${path}.inputs.reallocations`,
|
|
354
|
+
marketParams: validateStoredBlueMarket,
|
|
355
|
+
});
|
|
406
356
|
}
|
|
@@ -69,7 +69,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
|
|
|
69
69
|
* @param params.supportSignature - Optional Morpho authorization signature preference; defaults to `false`, selecting a direct authorization transaction when needed. Neither mode requests a token allowance or Permit2 signature.
|
|
70
70
|
* @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
|
|
71
71
|
* @param params.expiresAt - Optional Unix expiry in safe-integer seconds, later than `now`; defaults to `now + 2h`.
|
|
72
|
-
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to
|
|
72
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata, not to approval or authorization steps; omitted by default.
|
|
73
73
|
* @param params.deployless - Optional shared intent field; unused because withdrawal reads no token metadata.
|
|
74
74
|
* @returns A deep-frozen, data-only `{ version, chainId, account, expiresAt, steps, signatureRequests, calldataOrigin? }` plan with a withdrawal step. Direct Morpho authorization is a preceding step; signed authorization is consumed inline by the withdrawal. Attach signatures before building.
|
|
75
75
|
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
@@ -100,7 +100,6 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
|
|
|
100
100
|
* @throws {WithdrawSharesExceedSupplyError} when `shares` exceeds the position's supply shares.
|
|
101
101
|
* @throws {MissingContractCodeError} when registered BlueBundlesV1 or Blue has no deployed code.
|
|
102
102
|
* @throws {viem.BaseError} when a chain, bytecode, authorization or nonce RPC read fails, or ABI encoding rejects malformed input.
|
|
103
|
-
* @throws {UnexpectedRequirementSignatureError} when an authorization requirement returns a nonce that is not a bigint.
|
|
104
103
|
* @throws {TransactionPlanSignatureMismatchError} when the authorization requirement does not match the prepared account, chain, nonce or deadline.
|
|
105
104
|
* @example
|
|
106
105
|
* ```ts
|
|
@@ -120,7 +119,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
|
|
|
120
119
|
* positionData: { chainId: mainnet.id, position },
|
|
121
120
|
* now: (await client.getBlock()).timestamp,
|
|
122
121
|
* });
|
|
123
|
-
* // plan: { version:
|
|
122
|
+
* // plan: { version: 2, chainId, account, expiresAt, steps, signatureRequests }
|
|
124
123
|
* // Sign any pending Morpho authorization request, then build and submit each step in order.
|
|
125
124
|
* ```
|
|
126
125
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|