@morpho-org/morpho-sdk 10.1.0-next.0 → 10.2.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 +6 -2
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- package/lib/cjs/actions/blue/borrow.d.ts +13 -4
- package/lib/cjs/actions/blue/borrow.internal.d.ts +13 -0
- package/lib/cjs/actions/blue/borrow.internal.js +36 -0
- package/lib/cjs/actions/blue/borrow.js +12 -18
- package/lib/cjs/actions/blue/common.d.ts +53 -28
- package/lib/cjs/actions/blue/common.js +36 -35
- package/lib/cjs/actions/blue/encode.d.ts +23 -0
- package/lib/cjs/actions/blue/encode.js +171 -0
- package/lib/cjs/actions/blue/refinance.d.ts +14 -5
- package/lib/cjs/actions/blue/refinance.internal.d.ts +42 -0
- package/lib/cjs/actions/blue/refinance.internal.js +65 -0
- package/lib/cjs/actions/blue/refinance.js +13 -65
- package/lib/cjs/actions/blue/refinanceValidation.d.ts +6 -6
- package/lib/cjs/actions/blue/refinanceValidation.js +10 -8
- package/lib/cjs/actions/blue/repay.d.ts +5 -4
- package/lib/cjs/actions/blue/repay.internal.d.ts +13 -0
- package/lib/cjs/actions/blue/repay.internal.js +38 -0
- package/lib/cjs/actions/blue/repay.js +5 -19
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +6 -5
- package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
- package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.js +112 -0
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +6 -118
- package/lib/cjs/actions/blue/signatures.d.ts +30 -0
- package/lib/cjs/actions/blue/signatures.js +90 -0
- package/lib/cjs/actions/blue/supply.d.ts +6 -4
- package/lib/cjs/actions/blue/supply.internal.d.ts +32 -0
- package/lib/cjs/actions/blue/supply.internal.js +101 -0
- package/lib/cjs/actions/blue/supply.js +6 -69
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +5 -4
- package/lib/cjs/actions/blue/supplyCollateral.internal.d.ts +13 -0
- package/lib/cjs/actions/blue/supplyCollateral.internal.js +37 -0
- package/lib/cjs/actions/blue/supplyCollateral.js +5 -19
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +15 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +65 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +98 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +13 -108
- package/lib/cjs/actions/blue/withdraw.d.ts +15 -6
- package/lib/cjs/actions/blue/withdraw.internal.d.ts +56 -0
- package/lib/cjs/actions/blue/withdraw.internal.js +87 -0
- package/lib/cjs/actions/blue/withdraw.js +13 -80
- package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +2 -2
- package/lib/cjs/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
- package/lib/cjs/actions/blue/withdrawBuyCallback.internal.js +58 -0
- package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -39
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +4 -3
- package/lib/cjs/actions/blue/withdrawCollateral.internal.d.ts +16 -0
- package/lib/cjs/actions/blue/withdrawCollateral.internal.js +39 -0
- package/lib/cjs/actions/blue/withdrawCollateral.js +5 -19
- package/lib/cjs/actions/bundles/common.d.ts +9 -0
- package/lib/cjs/actions/bundles/common.js +18 -6
- package/lib/cjs/actions/bundles/index.d.ts +1 -1
- package/lib/cjs/actions/bundles/index.js +3 -16
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +59 -60
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +22 -1
- package/lib/cjs/actions/midnight/cancelAndMake.js +46 -87
- package/lib/cjs/actions/midnight/cancelOffers.d.ts +11 -0
- package/lib/cjs/actions/midnight/cancelOffers.js +22 -4
- package/lib/cjs/actions/midnight/encode.d.ts +36 -0
- package/lib/cjs/actions/midnight/encode.js +554 -0
- package/lib/cjs/actions/midnight/index.d.ts +14 -13
- package/lib/cjs/actions/midnight/index.js +29 -13
- package/lib/cjs/actions/midnight/parse.d.ts +35 -0
- package/lib/cjs/actions/midnight/parse.js +73 -0
- package/lib/cjs/actions/midnight/parseCollateralBatch.d.ts +58 -0
- package/lib/cjs/actions/midnight/parseCollateralBatch.js +216 -0
- package/lib/cjs/actions/midnight/redeem.d.ts +16 -3
- package/lib/cjs/actions/midnight/redeem.js +22 -51
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +42 -67
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +40 -5
- package/lib/cjs/actions/midnight/supplyCollateral.js +60 -54
- package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +3 -3
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +3 -62
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +39 -67
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +142 -0
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +17 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +25 -56
- package/lib/cjs/actions/midnight/takeLend.d.ts +21 -1
- package/lib/cjs/actions/midnight/takeLend.js +30 -58
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +34 -62
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +17 -2
- package/lib/cjs/actions/midnight/takeWithdraw.js +77 -115
- package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -3
- package/lib/cjs/actions/midnight/withdrawCollateral.js +25 -56
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +3 -71
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +39 -19
- package/lib/cjs/actions/requirements/blue/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/index.js +3 -15
- package/lib/cjs/actions/requirements/chainCheck.d.ts +5 -0
- package/lib/cjs/actions/requirements/chainCheck.js +10 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +40 -27
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +36 -17
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +44 -9
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +61 -24
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +25 -4
- package/lib/cjs/actions/requirements/encode/index.d.ts +5 -5
- package/lib/cjs/actions/requirements/encode/index.js +11 -19
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +26 -11
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +40 -12
- package/lib/cjs/actions/requirements/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/index.js +3 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +34 -19
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +26 -12
- package/lib/cjs/actions/requirements/midnight/index.d.ts +2 -2
- package/lib/cjs/actions/requirements/midnight/index.js +5 -16
- package/lib/cjs/actions/vaultV1/deposit.d.ts +23 -1
- package/lib/cjs/actions/vaultV1/deposit.js +48 -11
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +18 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +36 -16
- package/lib/cjs/actions/vaultV1/index.d.ts +5 -5
- package/lib/cjs/actions/vaultV1/index.js +11 -19
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +24 -2
- package/lib/cjs/actions/vaultV1/migrateToV2.js +51 -12
- package/lib/cjs/actions/vaultV1/redeem.d.ts +22 -2
- package/lib/cjs/actions/vaultV1/redeem.js +30 -8
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +21 -1
- package/lib/cjs/actions/vaultV1/withdraw.js +30 -8
- package/lib/cjs/actions/vaultV2/deposit.d.ts +23 -1
- package/lib/cjs/actions/vaultV2/deposit.js +48 -11
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +20 -2
- package/lib/cjs/actions/vaultV2/forceRedeem.js +39 -8
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +25 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +38 -15
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +18 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +35 -15
- package/lib/cjs/actions/vaultV2/index.d.ts +6 -6
- package/lib/cjs/actions/vaultV2/index.js +13 -20
- package/lib/cjs/actions/vaultV2/redeem.d.ts +22 -2
- package/lib/cjs/actions/vaultV2/redeem.js +30 -8
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +21 -1
- package/lib/cjs/actions/vaultV2/withdraw.js +30 -8
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +1 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -0
- package/lib/cjs/entities/blue/blue.d.ts +118 -28
- package/lib/cjs/entities/blue/blue.js +503 -416
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +117 -41
- package/lib/cjs/entities/midnight/midnight.js +472 -843
- package/lib/cjs/entities/midnight/parse.d.ts +74 -0
- package/lib/cjs/entities/midnight/parse.js +336 -0
- package/lib/cjs/entities/midnight/prepare.d.ts +47 -0
- package/lib/cjs/entities/midnight/prepare.js +293 -0
- package/lib/cjs/entities/midnight/publication.d.ts +7 -3
- package/lib/cjs/entities/midnight/publication.js +10 -7
- package/lib/cjs/entities/midnight/types.d.ts +7 -0
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +10 -5
- package/lib/cjs/entities/requirements/assertContractCode.js +24 -15
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +59 -51
- package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -3
- package/lib/cjs/entities/requirements/getErc2612Permit.js +20 -4
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +24 -7
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +27 -7
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
- package/lib/cjs/entities/requirements/index.d.ts +2 -2
- package/lib/cjs/entities/requirements/index.js +5 -16
- package/lib/cjs/entities/requirements/validateNativeRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/validateNativeRequirements.js +37 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +1 -7
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +5 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +29 -46
- package/lib/cjs/entities/vaultV1/vaultV1.js +234 -159
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +9 -4
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +1 -7
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +40 -92
- package/lib/cjs/entities/vaultV2/vaultV2.js +230 -188
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +13 -5
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +21 -27
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +5 -7
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/constant.d.ts +2 -0
- package/lib/cjs/helpers/constant.js +3 -1
- package/lib/cjs/helpers/deadShares.js +0 -3
- package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
- package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.js +18 -0
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/parse.d.ts +33 -0
- package/lib/cjs/helpers/parse.js +71 -0
- package/lib/cjs/helpers/parseMidnight.d.ts +48 -0
- package/lib/cjs/helpers/parseMidnight.js +95 -0
- package/lib/cjs/helpers/parseMidnightMaker.d.ts +44 -0
- package/lib/cjs/helpers/parseMidnightMaker.js +154 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +4 -5
- package/lib/cjs/helpers/quoteBlueRepay.d.ts +7 -3
- package/lib/cjs/helpers/quoteBlueRepay.js +20 -7
- package/lib/cjs/helpers/reallocationPenalty.d.ts +10 -0
- package/lib/cjs/helpers/reallocationPenalty.js +32 -0
- package/lib/cjs/helpers/referralFee.d.ts +2 -1
- package/lib/cjs/helpers/referralFee.js +5 -1
- package/lib/cjs/helpers/validate.d.ts +34 -6
- package/lib/cjs/helpers/validate.js +52 -9
- package/lib/cjs/helpers/validateMidnightBounds.d.ts +1 -2
- package/lib/cjs/helpers/validateMidnightBounds.js +1 -2
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +4 -4
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +17 -1
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- package/lib/cjs/transactionPlan/blue/borrow.d.ts +11 -5
- package/lib/cjs/transactionPlan/blue/borrow.js +26 -8
- package/lib/cjs/transactionPlan/blue/refinance.d.ts +9 -2
- package/lib/cjs/transactionPlan/blue/refinance.js +36 -11
- package/lib/cjs/transactionPlan/blue/repay.d.ts +1 -2
- package/lib/cjs/transactionPlan/blue/repay.js +3 -3
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +35 -7
- package/lib/cjs/transactionPlan/blue/supply.d.ts +1 -2
- package/lib/cjs/transactionPlan/blue/supply.js +1 -2
- package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +2 -3
- package/lib/cjs/transactionPlan/blue/supplyCollateral.js +2 -3
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +25 -8
- package/lib/cjs/transactionPlan/blue/withdraw.d.ts +17 -7
- package/lib/cjs/transactionPlan/blue/withdraw.js +28 -9
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +17 -9
- package/lib/cjs/transactionPlan/deposit.js +4 -0
- package/lib/cjs/transactionPlan/intent.d.ts +1 -1
- package/lib/cjs/transactionPlan/intent.js +4 -2
- package/lib/cjs/transactionPlan/plan.d.ts +8 -4
- package/lib/cjs/transactionPlan/plan.js +8 -4
- package/lib/cjs/transactionPlan/types.d.ts +6 -0
- package/lib/cjs/transactionPlan/validation.d.ts +1 -1
- package/lib/cjs/transactionPlan/validation.js +3 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +5 -5
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +5 -5
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +7 -3
- package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -2
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -2
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +2 -3
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -3
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +3 -3
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +3 -3
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +3 -3
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +2 -3
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -3
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +2 -3
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -3
- package/lib/cjs/types/action.d.ts +13 -2
- package/lib/cjs/types/error.d.ts +27 -8
- package/lib/cjs/types/error.js +42 -12
- package/lib/cjs/types/sharedLiquidity.d.ts +7 -2
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- 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/borrow.d.ts +13 -4
- package/lib/esm/actions/blue/borrow.internal.d.ts +13 -0
- package/lib/esm/actions/blue/borrow.internal.js +31 -0
- package/lib/esm/actions/blue/borrow.js +12 -18
- package/lib/esm/actions/blue/common.d.ts +53 -28
- package/lib/esm/actions/blue/common.js +36 -34
- package/lib/esm/actions/blue/encode.d.ts +23 -0
- package/lib/esm/actions/blue/encode.js +164 -0
- package/lib/esm/actions/blue/refinance.d.ts +14 -5
- package/lib/esm/actions/blue/refinance.internal.d.ts +42 -0
- package/lib/esm/actions/blue/refinance.internal.js +59 -0
- package/lib/esm/actions/blue/refinance.js +13 -65
- package/lib/esm/actions/blue/refinanceValidation.d.ts +6 -6
- package/lib/esm/actions/blue/refinanceValidation.js +11 -9
- package/lib/esm/actions/blue/repay.d.ts +5 -4
- package/lib/esm/actions/blue/repay.internal.d.ts +13 -0
- package/lib/esm/actions/blue/repay.internal.js +33 -0
- package/lib/esm/actions/blue/repay.js +5 -19
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +6 -5
- package/lib/esm/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
- package/lib/esm/actions/blue/repayWithdrawCollateral.internal.js +104 -0
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +6 -118
- package/lib/esm/actions/blue/signatures.d.ts +30 -0
- package/lib/esm/actions/blue/signatures.js +82 -0
- package/lib/esm/actions/blue/supply.d.ts +6 -4
- package/lib/esm/actions/blue/supply.internal.d.ts +32 -0
- package/lib/esm/actions/blue/supply.internal.js +95 -0
- package/lib/esm/actions/blue/supply.js +6 -69
- package/lib/esm/actions/blue/supplyCollateral.d.ts +5 -4
- package/lib/esm/actions/blue/supplyCollateral.internal.d.ts +13 -0
- package/lib/esm/actions/blue/supplyCollateral.internal.js +32 -0
- package/lib/esm/actions/blue/supplyCollateral.js +5 -19
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +15 -6
- package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +65 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +91 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +13 -108
- package/lib/esm/actions/blue/withdraw.d.ts +15 -6
- package/lib/esm/actions/blue/withdraw.internal.d.ts +56 -0
- package/lib/esm/actions/blue/withdraw.internal.js +80 -0
- package/lib/esm/actions/blue/withdraw.js +13 -80
- package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +2 -2
- package/lib/esm/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
- package/lib/esm/actions/blue/withdrawBuyCallback.internal.js +53 -0
- package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -39
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +4 -3
- package/lib/esm/actions/blue/withdrawCollateral.internal.d.ts +16 -0
- package/lib/esm/actions/blue/withdrawCollateral.internal.js +34 -0
- package/lib/esm/actions/blue/withdrawCollateral.js +5 -19
- package/lib/esm/actions/bundles/common.d.ts +9 -0
- package/lib/esm/actions/bundles/common.js +15 -4
- package/lib/esm/actions/bundles/index.d.ts +1 -1
- package/lib/esm/actions/bundles/index.js +1 -1
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +58 -61
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +22 -1
- package/lib/esm/actions/midnight/cancelAndMake.js +43 -85
- package/lib/esm/actions/midnight/cancelOffers.d.ts +11 -0
- package/lib/esm/actions/midnight/cancelOffers.js +18 -2
- package/lib/esm/actions/midnight/encode.d.ts +36 -0
- package/lib/esm/actions/midnight/encode.js +539 -0
- package/lib/esm/actions/midnight/index.d.ts +14 -13
- package/lib/esm/actions/midnight/index.js +14 -13
- package/lib/esm/actions/midnight/parse.d.ts +35 -0
- package/lib/esm/actions/midnight/parse.js +68 -0
- package/lib/esm/actions/midnight/parseCollateralBatch.d.ts +58 -0
- package/lib/esm/actions/midnight/parseCollateralBatch.js +209 -0
- package/lib/esm/actions/midnight/redeem.d.ts +16 -3
- package/lib/esm/actions/midnight/redeem.js +20 -50
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +38 -64
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +40 -5
- package/lib/esm/actions/midnight/supplyCollateral.js +57 -53
- package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +3 -3
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +3 -62
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +34 -63
- package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
- package/lib/esm/actions/midnight/supplyCollateralWithNative.js +137 -0
- package/lib/esm/actions/midnight/takeBorrow.d.ts +17 -2
- package/lib/esm/actions/midnight/takeBorrow.js +21 -53
- package/lib/esm/actions/midnight/takeLend.d.ts +21 -1
- package/lib/esm/actions/midnight/takeLend.js +27 -56
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +31 -60
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +17 -2
- package/lib/esm/actions/midnight/takeWithdraw.js +76 -115
- package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -3
- package/lib/esm/actions/midnight/withdrawCollateral.js +23 -55
- package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +3 -71
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +36 -18
- package/lib/esm/actions/requirements/blue/index.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/index.js +1 -1
- package/lib/esm/actions/requirements/chainCheck.d.ts +5 -0
- package/lib/esm/actions/requirements/chainCheck.js +6 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +36 -25
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +33 -16
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +41 -8
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +59 -24
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +21 -2
- package/lib/esm/actions/requirements/encode/index.d.ts +5 -5
- package/lib/esm/actions/requirements/encode/index.js +5 -5
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +26 -11
- package/lib/esm/actions/requirements/getRequirementsApproval.js +38 -12
- package/lib/esm/actions/requirements/index.d.ts +1 -1
- package/lib/esm/actions/requirements/index.js +1 -1
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +31 -18
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +22 -10
- package/lib/esm/actions/requirements/midnight/index.d.ts +2 -2
- package/lib/esm/actions/requirements/midnight/index.js +2 -2
- package/lib/esm/actions/vaultV1/deposit.d.ts +23 -1
- package/lib/esm/actions/vaultV1/deposit.js +45 -10
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +18 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +33 -15
- package/lib/esm/actions/vaultV1/index.d.ts +5 -5
- package/lib/esm/actions/vaultV1/index.js +5 -5
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +24 -2
- package/lib/esm/actions/vaultV1/migrateToV2.js +49 -12
- package/lib/esm/actions/vaultV1/redeem.d.ts +22 -2
- package/lib/esm/actions/vaultV1/redeem.js +28 -8
- package/lib/esm/actions/vaultV1/withdraw.d.ts +21 -1
- package/lib/esm/actions/vaultV1/withdraw.js +28 -8
- package/lib/esm/actions/vaultV2/deposit.d.ts +23 -1
- package/lib/esm/actions/vaultV2/deposit.js +45 -10
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +20 -2
- package/lib/esm/actions/vaultV2/forceRedeem.js +35 -6
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +25 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.js +35 -14
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +18 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +32 -14
- package/lib/esm/actions/vaultV2/index.d.ts +6 -6
- package/lib/esm/actions/vaultV2/index.js +6 -6
- package/lib/esm/actions/vaultV2/redeem.d.ts +22 -2
- package/lib/esm/actions/vaultV2/redeem.js +28 -8
- package/lib/esm/actions/vaultV2/withdraw.d.ts +21 -1
- package/lib/esm/actions/vaultV2/withdraw.js +28 -8
- 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/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +118 -28
- package/lib/esm/entities/blue/blue.js +485 -398
- 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 +117 -41
- package/lib/esm/entities/midnight/midnight.js +455 -826
- package/lib/esm/entities/midnight/parse.d.ts +74 -0
- package/lib/esm/entities/midnight/parse.js +320 -0
- package/lib/esm/entities/midnight/prepare.d.ts +47 -0
- package/lib/esm/entities/midnight/prepare.js +282 -0
- package/lib/esm/entities/midnight/publication.d.ts +7 -3
- package/lib/esm/entities/midnight/publication.js +7 -3
- package/lib/esm/entities/midnight/types.d.ts +7 -0
- package/lib/esm/entities/requirements/assertContractCode.d.ts +10 -5
- package/lib/esm/entities/requirements/assertContractCode.js +24 -15
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +53 -47
- package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -3
- package/lib/esm/entities/requirements/getErc2612Permit.js +19 -4
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +20 -5
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +23 -5
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
- package/lib/esm/entities/requirements/index.d.ts +2 -2
- package/lib/esm/entities/requirements/index.js +2 -2
- package/lib/esm/entities/requirements/validateNativeRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/validateNativeRequirements.js +33 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +1 -7
- package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.js +5 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +29 -46
- package/lib/esm/entities/vaultV1/vaultV1.js +214 -139
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +10 -5
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +1 -7
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +40 -92
- package/lib/esm/entities/vaultV2/vaultV2.js +214 -172
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +13 -5
- package/lib/esm/entities/vaultV2BlueReallocationData.js +19 -25
- 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/constant.d.ts +2 -0
- package/lib/esm/helpers/constant.js +2 -0
- package/lib/esm/helpers/deadShares.js +1 -4
- package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
- package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.js +15 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/parse.d.ts +33 -0
- package/lib/esm/helpers/parse.js +61 -0
- package/lib/esm/helpers/parseMidnight.d.ts +48 -0
- package/lib/esm/helpers/parseMidnight.js +80 -0
- package/lib/esm/helpers/parseMidnightMaker.d.ts +44 -0
- package/lib/esm/helpers/parseMidnightMaker.js +147 -0
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +4 -5
- package/lib/esm/helpers/quoteBlueRepay.d.ts +7 -3
- package/lib/esm/helpers/quoteBlueRepay.js +21 -8
- package/lib/esm/helpers/reallocationPenalty.d.ts +10 -0
- package/lib/esm/helpers/reallocationPenalty.js +28 -0
- package/lib/esm/helpers/referralFee.d.ts +2 -1
- package/lib/esm/helpers/referralFee.js +5 -1
- package/lib/esm/helpers/validate.d.ts +34 -6
- package/lib/esm/helpers/validate.js +52 -11
- package/lib/esm/helpers/validateMidnightBounds.d.ts +1 -2
- package/lib/esm/helpers/validateMidnightBounds.js +1 -2
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +2 -2
- package/lib/esm/helpers/validateMidnightPublication.d.ts +17 -1
- package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +1 -1
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/transactionPlan/blue/borrow.d.ts +11 -5
- package/lib/esm/transactionPlan/blue/borrow.js +27 -9
- package/lib/esm/transactionPlan/blue/refinance.d.ts +9 -2
- package/lib/esm/transactionPlan/blue/refinance.js +37 -12
- package/lib/esm/transactionPlan/blue/repay.d.ts +1 -2
- package/lib/esm/transactionPlan/blue/repay.js +4 -4
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +36 -8
- package/lib/esm/transactionPlan/blue/supply.d.ts +1 -2
- package/lib/esm/transactionPlan/blue/supply.js +1 -2
- package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +2 -3
- package/lib/esm/transactionPlan/blue/supplyCollateral.js +2 -3
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +25 -8
- package/lib/esm/transactionPlan/blue/withdraw.d.ts +17 -7
- package/lib/esm/transactionPlan/blue/withdraw.js +28 -9
- package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
- package/lib/esm/transactionPlan/blue/withdrawCollateral.js +17 -9
- package/lib/esm/transactionPlan/deposit.js +5 -1
- package/lib/esm/transactionPlan/intent.d.ts +1 -1
- package/lib/esm/transactionPlan/intent.js +4 -2
- package/lib/esm/transactionPlan/plan.d.ts +8 -4
- package/lib/esm/transactionPlan/plan.js +8 -4
- package/lib/esm/transactionPlan/types.d.ts +6 -0
- package/lib/esm/transactionPlan/validation.d.ts +1 -1
- package/lib/esm/transactionPlan/validation.js +3 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +5 -5
- package/lib/esm/transactionPlan/vaultv1/deposit.js +5 -5
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +8 -4
- package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -2
- package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -2
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +2 -3
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +2 -3
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +3 -3
- package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -3
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +3 -3
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +2 -3
- package/lib/esm/transactionPlan/vaultv2/redeem.js +2 -3
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +2 -3
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +2 -3
- package/lib/esm/types/action.d.ts +13 -2
- package/lib/esm/types/error.d.ts +27 -8
- package/lib/esm/types/error.js +38 -10
- package/lib/esm/types/sharedLiquidity.d.ts +7 -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,26 +1,35 @@
|
|
|
1
|
-
import { MathLib, } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { MarketParams, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket, fetchVaultV2BluePublicAllocatorData, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
-
import { getChainAddress, getChainAddresses, Time, } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { deepFreeze, getChainAddress, getChainAddresses, Time, } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { readContract } from "viem/actions";
|
|
6
6
|
import { blueAbi, midnightBlueBuyCallbackAbi, midnightBlueBuyCallbackFactoryAbi, } from "../../abis.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { getBlueBundlesV1ReferralFeeAssets, parseBlueAllocations, parseBlueBundlesV1Common, selectBlueBundlesV1RequirementSignatures, } from "../../actions/blue/common.js";
|
|
8
|
+
import { buildBlueRefinance, parseBlueRefinanceMarkets, } from "../../actions/blue/refinance.internal.js";
|
|
9
|
+
import { validateBlueRefinanceQuote } from "../../actions/blue/refinanceValidation.js";
|
|
10
|
+
import { buildBlueRepayWithdrawCollateral, parseBlueRepayCap, parseBlueRepayCoverage, parseBlueRepayMode, } from "../../actions/blue/repayWithdrawCollateral.internal.js";
|
|
11
|
+
import { buildBlueSupply, } from "../../actions/blue/supply.internal.js";
|
|
12
|
+
import { buildBlueSupplyCollateralBorrow, parseBlueSupplyCollateralBorrowAllocations, parseBlueSupplyCollateralBorrowMode, } from "../../actions/blue/supplyCollateralBorrow.internal.js";
|
|
13
|
+
import { buildBlueWithdraw, parseBlueWithdrawMode, parseBlueWithdrawPenalty, } from "../../actions/blue/withdraw.internal.js";
|
|
14
|
+
import { buildBlueWithdrawBuyCallback, } from "../../actions/blue/withdrawBuyCallback.internal.js";
|
|
15
|
+
import { getParsedBlueAuthorizationRequirement, parseBlueAuthorizationRequirement, } from "../../actions/requirements/blue/getBlueAuthorizationRequirement.js";
|
|
16
|
+
import { createChainCheck, } from "../../actions/requirements/chainCheck.js";
|
|
17
|
+
import { getBlueBundlesV1QuoteTimestamp } from "../../helpers/getBlueBundlesV1QuoteTimestamp.js";
|
|
11
18
|
import { DEFAULT_LLTV_BUFFER, validateAccrualPosition, validateChainId, validatePositionHealth, validatePositionHealthAfterWithdraw, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
12
19
|
import { resolveTransactionMetadata } from "../../helpers/metadata.js";
|
|
20
|
+
import { parseBlueMarket, parseNativeFunding, parseNonnegative, parseUint256, parseUint256Max, } from "../../helpers/parse.js";
|
|
13
21
|
import { quoteBlueRepay } from "../../helpers/quoteBlueRepay.js";
|
|
14
|
-
import {
|
|
15
|
-
import { BlueBuyCallbackOwnerMismatchError, BlueBuyCallbackUnauthorizedError, EmptyBlueSupplyPositionError, ExpiredDeadlineError, InputExceedsMaxError, InsufficientBlueLiquidityError, MarketIdMismatchError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, NotBlueBuyCallbackError, ReallocationsRequireBorrowError, } from "../../types/index.js";
|
|
22
|
+
import { BlueBuyCallbackOwnerMismatchError, BlueBuyCallbackUnauthorizedError, EmptyBlueSupplyPositionError, ExpiredDeadlineError, InputExceedsMaxError, InsufficientBlueLiquidityError, MarketIdMismatchError, MissingAccrualPositionError, NonPositiveInputError, NotBlueBuyCallbackError, } from "../../types/index.js";
|
|
16
23
|
import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
|
|
17
|
-
import {
|
|
24
|
+
import { getParsedBundlesTokenRequirements, parseGetBundlesTokenRequirements, } from "../requirements/getBundlesTokenRequirements.js";
|
|
25
|
+
import { validateNativeRequirements } from "../requirements/validateNativeRequirements.js";
|
|
18
26
|
import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
|
|
19
27
|
/** Binds a viem client to a Morpho Blue market's action builders. */
|
|
20
28
|
export class MorphoBlue {
|
|
21
29
|
client;
|
|
22
30
|
marketParams;
|
|
23
31
|
chainId;
|
|
32
|
+
parsedMarket;
|
|
24
33
|
/**
|
|
25
34
|
* Binds `client` to the market described by `marketParams` on `chainId`.
|
|
26
35
|
*
|
|
@@ -34,7 +43,7 @@ export class MorphoBlue {
|
|
|
34
43
|
this.client = client;
|
|
35
44
|
this.marketParams = marketParams;
|
|
36
45
|
this.chainId = chainId;
|
|
37
|
-
|
|
46
|
+
this.parsedMarket = parseBlueMarket(marketParams);
|
|
38
47
|
}
|
|
39
48
|
validateDeadline(deadline, now = Time.timestamp()) {
|
|
40
49
|
if (deadline <= now) {
|
|
@@ -42,13 +51,13 @@ export class MorphoBlue {
|
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
validateWriteCommon(params, now) {
|
|
54
|
+
// Reject cross-chain inputs before continuing.
|
|
45
55
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
56
|
+
// Reject expiry before continuing this call.
|
|
46
57
|
this.validateDeadline(params.deadline, now);
|
|
47
58
|
// Resolve at handle creation so unsupported deployments fail before any RPC prerequisite work.
|
|
48
59
|
getChainAddress(this.chainId, "bundles.blueBundlesV1");
|
|
49
|
-
|
|
50
|
-
// because the pure action re-normalizes it at encode time.
|
|
51
|
-
normalizeBlueBundlesV1CommonParams({
|
|
60
|
+
return parseBlueBundlesV1Common({
|
|
52
61
|
chainId: this.chainId,
|
|
53
62
|
userAddress: params.userAddress,
|
|
54
63
|
deadline: params.deadline,
|
|
@@ -59,10 +68,13 @@ export class MorphoBlue {
|
|
|
59
68
|
/**
|
|
60
69
|
* Asserts that every registry contract this flow's transaction targets or names as
|
|
61
70
|
* spender/authorized operator holds code, with one `eth_getCode` per distinct address
|
|
62
|
-
* before any other requirement read.
|
|
63
|
-
*
|
|
71
|
+
* before any other requirement read. Native-only funding validates the served chain
|
|
72
|
+
* concurrently; other flows probe it here only when a target has no code.
|
|
73
|
+
*
|
|
74
|
+
* @param chainCheck - Chain validation shared within this operation.
|
|
75
|
+
* @param nativeFundingOnly - Whether no token or authorization resolver checks the chain.
|
|
64
76
|
*/
|
|
65
|
-
async assertWriteTargets() {
|
|
77
|
+
async assertWriteTargets(chainCheck, nativeFundingOnly = false) {
|
|
66
78
|
const targets = [
|
|
67
79
|
{
|
|
68
80
|
role: "bundles.blueBundlesV1",
|
|
@@ -70,27 +82,25 @@ export class MorphoBlue {
|
|
|
70
82
|
},
|
|
71
83
|
{ role: "blue", address: getChainAddress(this.chainId, "blue") },
|
|
72
84
|
];
|
|
73
|
-
|
|
85
|
+
const assertTargets = () => assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets, chainCheck);
|
|
86
|
+
if (nativeFundingOnly) {
|
|
87
|
+
await validateNativeRequirements(this.client.viemClient, {
|
|
88
|
+
chainId: this.chainId,
|
|
89
|
+
chainCheck,
|
|
90
|
+
assertWriteTargets: assertTargets,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
await assertTargets();
|
|
95
|
+
}
|
|
74
96
|
}
|
|
75
|
-
getMaxLtv(marketParams = this.
|
|
97
|
+
getMaxLtv(marketParams = this.parsedMarket) {
|
|
76
98
|
return MathLib.zeroFloorSub(marketParams.lltv, DEFAULT_LLTV_BUFFER);
|
|
77
99
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
quoteRepay({ positionData, repayAssets, repayShares, deadline, now, }) {
|
|
82
|
-
return quoteBlueRepay({
|
|
83
|
-
positionData,
|
|
84
|
-
marketId: this.marketParams.id,
|
|
85
|
-
repayAssets,
|
|
86
|
-
repayShares,
|
|
87
|
-
deadline,
|
|
88
|
-
now,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
async getTokenRequirements(params) {
|
|
100
|
+
async getTokenRequirements(chainCheck, params) {
|
|
101
|
+
// Reject expiry before continuing this call.
|
|
92
102
|
this.validateDeadline(params.deadline, params.now);
|
|
93
|
-
return
|
|
103
|
+
return getParsedBundlesTokenRequirements({ viemClient: this.client.viemClient, chainCheck }, parseGetBundlesTokenRequirements(this.client.viemClient, {
|
|
94
104
|
token: params.token,
|
|
95
105
|
spender: getChainAddress(this.chainId, "bundles.blueBundlesV1"),
|
|
96
106
|
amount: params.amount,
|
|
@@ -101,11 +111,12 @@ export class MorphoBlue {
|
|
|
101
111
|
supportDeployless: this.client.options.supportDeployless,
|
|
102
112
|
useSimplePermit: params.useSimplePermit,
|
|
103
113
|
now: params.now,
|
|
104
|
-
});
|
|
114
|
+
}));
|
|
105
115
|
}
|
|
106
|
-
async getAuthorizationRequirements(params) {
|
|
116
|
+
async getAuthorizationRequirements(chainCheck, params) {
|
|
117
|
+
// Reject expiry before continuing this call.
|
|
107
118
|
this.validateDeadline(params.deadline, params.now);
|
|
108
|
-
const requirement = await
|
|
119
|
+
const requirement = await getParsedBlueAuthorizationRequirement(parseBlueAuthorizationRequirement({
|
|
109
120
|
viemClient: this.client.viemClient,
|
|
110
121
|
chainId: this.chainId,
|
|
111
122
|
userAddress: params.userAddress,
|
|
@@ -113,135 +124,168 @@ export class MorphoBlue {
|
|
|
113
124
|
authorized: getChainAddress(this.chainId, "bundles.blueBundlesV1"),
|
|
114
125
|
deadline: params.deadline,
|
|
115
126
|
now: params.now,
|
|
116
|
-
});
|
|
127
|
+
}), chainCheck);
|
|
117
128
|
return requirement == null ? [] : [requirement];
|
|
118
129
|
}
|
|
119
130
|
async getMarketData(parameters) {
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
// Confirm the RPC chain before contract reads.
|
|
132
|
+
await createChainCheck(this.client.viemClient, this.chainId)();
|
|
133
|
+
return fetchMarket(this.parsedMarket.id, this.client.viemClient, {
|
|
122
134
|
...parameters,
|
|
123
135
|
deployless: this.client.options.supportDeployless,
|
|
124
136
|
});
|
|
125
137
|
}
|
|
126
138
|
async getPositionData(userAddress, parameters) {
|
|
127
|
-
|
|
128
|
-
|
|
139
|
+
// Confirm the RPC chain before contract reads.
|
|
140
|
+
await createChainCheck(this.client.viemClient, this.chainId)();
|
|
141
|
+
return fetchAccrualPosition(userAddress, this.parsedMarket.id, this.client.viemClient, {
|
|
129
142
|
...parameters,
|
|
130
143
|
deployless: this.client.options.supportDeployless,
|
|
131
144
|
});
|
|
132
145
|
}
|
|
133
146
|
supply(params) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
this.
|
|
147
|
+
return this.supplyPrepared(this.parseSupplyParams(params));
|
|
148
|
+
}
|
|
149
|
+
parseSupplyParams(params) {
|
|
150
|
+
const { assets } = params;
|
|
151
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
|
|
152
|
+
const createdAt = params.now ?? Time.timestamp();
|
|
153
|
+
const normalized = this.validateWriteCommon(params, createdAt);
|
|
139
154
|
if (assets <= 0n) {
|
|
140
155
|
throw new NonPositiveInputError("assets", assets);
|
|
141
156
|
}
|
|
142
|
-
const nativeValue =
|
|
157
|
+
const nativeValue = parseNativeFunding({
|
|
143
158
|
chainId: this.chainId,
|
|
144
|
-
token: this.
|
|
159
|
+
token: this.parsedMarket.loanToken,
|
|
145
160
|
fundedAmount: assets,
|
|
146
|
-
nativeAmount,
|
|
161
|
+
nativeAmount: params.nativeAmount,
|
|
147
162
|
});
|
|
148
|
-
if (params.marketData != null
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
163
|
+
if (params.marketData != null &&
|
|
164
|
+
params.marketData.id !== this.parsedMarket.id) {
|
|
165
|
+
throw new MarketIdMismatchError(params.marketData.id, this.parsedMarket.id);
|
|
152
166
|
}
|
|
167
|
+
const input = {
|
|
168
|
+
...normalized,
|
|
169
|
+
chainId: this.chainId,
|
|
170
|
+
userAddress: params.userAddress,
|
|
171
|
+
marketParams: this.parsedMarket,
|
|
172
|
+
now: params.now,
|
|
173
|
+
metadata,
|
|
174
|
+
assets: parseUint256Max("assets", assets),
|
|
175
|
+
value: nativeValue,
|
|
176
|
+
};
|
|
177
|
+
return input;
|
|
178
|
+
}
|
|
179
|
+
supplyPrepared(parsed) {
|
|
180
|
+
const { userAddress, assets, deadline, value: nativeValue, marketParams, } = parsed;
|
|
153
181
|
return {
|
|
154
182
|
getRequirements: (requirementsParams) => {
|
|
155
|
-
const
|
|
183
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
184
|
+
const now = parsed.now ?? Time.timestamp();
|
|
185
|
+
// Reject expiry before continuing this call.
|
|
156
186
|
this.validateDeadline(deadline, now);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
187
|
+
if (nativeValue > 0n) {
|
|
188
|
+
// Neither token requirements nor authorization will validate the chain.
|
|
189
|
+
return this.assertWriteTargets(chainCheck, true).then(() => []);
|
|
190
|
+
}
|
|
191
|
+
return this.assertWriteTargets(chainCheck).then(() => this.getTokenRequirements(chainCheck, {
|
|
192
|
+
token: marketParams.loanToken,
|
|
193
|
+
amount: assets,
|
|
194
|
+
userAddress,
|
|
195
|
+
deadline,
|
|
196
|
+
now,
|
|
197
|
+
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
198
|
+
}));
|
|
170
199
|
},
|
|
171
200
|
buildTx: (signatures) => {
|
|
172
201
|
const { token } = selectBlueBundlesV1RequirementSignatures(signatures, {
|
|
173
202
|
token: nativeValue === 0n,
|
|
174
203
|
});
|
|
175
|
-
return
|
|
176
|
-
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
177
|
-
args: {
|
|
178
|
-
userAddress,
|
|
179
|
-
assets,
|
|
180
|
-
nativeAmount: nativeValue > 0n ? nativeValue : undefined,
|
|
181
|
-
deadline,
|
|
182
|
-
referralFeePct,
|
|
183
|
-
referralFeeRecipient,
|
|
184
|
-
requirementSignature: token,
|
|
185
|
-
},
|
|
186
|
-
metadata,
|
|
187
|
-
});
|
|
204
|
+
return buildBlueSupply(parsed, { requirementSignature: token });
|
|
188
205
|
},
|
|
189
206
|
};
|
|
190
207
|
}
|
|
191
208
|
/** {@inheritDoc BlueActions.withdraw} */
|
|
192
209
|
withdraw(params) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const
|
|
197
|
-
this.
|
|
210
|
+
return this.withdrawPrepared(this.parseWithdrawParams(params));
|
|
211
|
+
}
|
|
212
|
+
parseWithdrawParams(params) {
|
|
213
|
+
const { userAddress, positionData } = params;
|
|
214
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
|
|
215
|
+
const createdAt = params.now ?? Time.timestamp();
|
|
216
|
+
const normalized = this.validateWriteCommon(params, createdAt);
|
|
198
217
|
const assets = ("assets" in params ? params.assets : undefined) ?? 0n;
|
|
199
218
|
const shares = ("shares" in params ? params.shares : undefined) ?? 0n;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
throw new MutuallyExclusiveWithdrawAmountsError(this.marketParams.id);
|
|
208
|
-
}
|
|
209
|
-
if (assets === 0n && shares === 0n) {
|
|
210
|
-
throw new NonPositiveInputError("assets or shares", 0n);
|
|
211
|
-
}
|
|
219
|
+
const lowerAssets = parseNonnegative("assets", assets);
|
|
220
|
+
const lowerShares = parseNonnegative("shares", shares);
|
|
221
|
+
const mode = parseBlueWithdrawMode(this.parsedMarket, {
|
|
222
|
+
withdrawAssets: assets,
|
|
223
|
+
withdrawShares: shares,
|
|
224
|
+
field: "assets or shares",
|
|
225
|
+
});
|
|
212
226
|
if (positionData == null) {
|
|
213
|
-
throw new MissingAccrualPositionError(this.
|
|
227
|
+
throw new MissingAccrualPositionError(this.parsedMarket.id);
|
|
214
228
|
}
|
|
229
|
+
// Reject a snapshot for another user or market.
|
|
215
230
|
validateAccrualPosition({
|
|
216
231
|
positionData,
|
|
217
|
-
expectedMarketId: this.
|
|
232
|
+
expectedMarketId: this.parsedMarket.id,
|
|
218
233
|
expectedUser: userAddress,
|
|
219
234
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
235
|
+
if (shares > 0n) {
|
|
236
|
+
// Reject a withdrawal larger than the supplied share balance.
|
|
237
|
+
validateWithdrawShares({
|
|
238
|
+
positionData,
|
|
239
|
+
withdrawShares: shares,
|
|
240
|
+
marketId: this.parsedMarket.id,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
// Reject a withdrawal larger than the supplied asset balance.
|
|
245
|
+
validateWithdrawAmount({
|
|
246
|
+
positionData,
|
|
247
|
+
withdrawAssets: assets,
|
|
248
|
+
marketId: this.parsedMarket.id,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
const allocations = parseBlueWithdrawPenalty(parseBlueAllocations([...(params.reallocations ?? [])], {
|
|
252
|
+
marketParams: this.parsedMarket,
|
|
253
|
+
maxPenalty: params.maxPenalty,
|
|
254
|
+
}), mode);
|
|
255
|
+
const reallocationPenaltyAssets = allocations.penaltyAssets;
|
|
231
256
|
const expectedWithdrawAssets = assets > 0n ? assets : positionData.market.toSupplyAssets(shares, "Down");
|
|
232
|
-
if (reallocationPenaltyAssets > expectedWithdrawAssets) {
|
|
257
|
+
if (shares > 0n && reallocationPenaltyAssets > expectedWithdrawAssets) {
|
|
233
258
|
throw new InputExceedsMaxError({
|
|
234
259
|
field: "reallocationPenaltyAssets",
|
|
235
260
|
value: reallocationPenaltyAssets,
|
|
236
261
|
max: expectedWithdrawAssets,
|
|
237
262
|
});
|
|
238
263
|
}
|
|
264
|
+
const input = {
|
|
265
|
+
...normalized,
|
|
266
|
+
chainId: this.chainId,
|
|
267
|
+
userAddress,
|
|
268
|
+
marketParams: this.parsedMarket,
|
|
269
|
+
now: params.now,
|
|
270
|
+
metadata,
|
|
271
|
+
publicAllocations: allocations.publicAllocations,
|
|
272
|
+
reallocationPenaltyAssets,
|
|
273
|
+
withdrawAssets: parseUint256Max("withdrawAssets", lowerAssets),
|
|
274
|
+
withdrawShares: parseUint256Max("withdrawShares", lowerShares),
|
|
275
|
+
};
|
|
276
|
+
return input;
|
|
277
|
+
}
|
|
278
|
+
withdrawPrepared(parsed) {
|
|
279
|
+
const { userAddress, deadline } = parsed;
|
|
239
280
|
return {
|
|
240
281
|
getRequirements: async () => {
|
|
241
|
-
const
|
|
282
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
283
|
+
const now = parsed.now ?? Time.timestamp();
|
|
284
|
+
// Reject expiry before continuing this call.
|
|
242
285
|
this.validateDeadline(deadline, now);
|
|
243
|
-
|
|
244
|
-
|
|
286
|
+
// Reject missing write targets before resolving requirements.
|
|
287
|
+
await this.assertWriteTargets(chainCheck);
|
|
288
|
+
return this.getAuthorizationRequirements(chainCheck, {
|
|
245
289
|
userAddress,
|
|
246
290
|
deadline,
|
|
247
291
|
now,
|
|
@@ -251,40 +295,34 @@ export class MorphoBlue {
|
|
|
251
295
|
const { authorization } = selectBlueBundlesV1RequirementSignatures(signatures, {
|
|
252
296
|
authorization: true,
|
|
253
297
|
});
|
|
254
|
-
return
|
|
255
|
-
|
|
256
|
-
args: {
|
|
257
|
-
userAddress,
|
|
258
|
-
withdrawAssets: assets,
|
|
259
|
-
withdrawShares: shares,
|
|
260
|
-
reallocations,
|
|
261
|
-
deadline,
|
|
262
|
-
referralFeePct,
|
|
263
|
-
referralFeeRecipient,
|
|
264
|
-
authorizationSignature: authorization,
|
|
265
|
-
},
|
|
266
|
-
metadata,
|
|
298
|
+
return buildBlueWithdraw(parsed, {
|
|
299
|
+
authorizationSignature: authorization,
|
|
267
300
|
});
|
|
268
301
|
},
|
|
269
302
|
};
|
|
270
303
|
}
|
|
271
304
|
/** {@inheritDoc BlueActions.withdrawBuyCallback} */
|
|
272
305
|
withdrawBuyCallback(params) {
|
|
306
|
+
return this.withdrawBuyCallbackPrepared(this.parseWithdrawBuyCallbackParams(params));
|
|
307
|
+
}
|
|
308
|
+
parseWithdrawBuyCallbackParams(params) {
|
|
273
309
|
const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
|
|
274
310
|
const { userAddress, callbackAddress, positionData } = params;
|
|
311
|
+
// Reject cross-chain inputs before continuing.
|
|
275
312
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
276
313
|
if (positionData == null) {
|
|
277
|
-
throw new MissingAccrualPositionError(this.
|
|
314
|
+
throw new MissingAccrualPositionError(this.parsedMarket.id);
|
|
278
315
|
}
|
|
316
|
+
// Reject a snapshot for another user or market.
|
|
279
317
|
validateAccrualPosition({
|
|
280
318
|
positionData,
|
|
281
|
-
expectedMarketId: this.
|
|
319
|
+
expectedMarketId: this.parsedMarket.id,
|
|
282
320
|
expectedUser: callbackAddress,
|
|
283
321
|
});
|
|
284
322
|
const shares = positionData.supplyShares;
|
|
285
323
|
if (shares === 0n) {
|
|
286
324
|
throw new EmptyBlueSupplyPositionError({
|
|
287
|
-
market: this.
|
|
325
|
+
market: this.parsedMarket.id,
|
|
288
326
|
user: callbackAddress,
|
|
289
327
|
});
|
|
290
328
|
}
|
|
@@ -292,26 +330,41 @@ export class MorphoBlue {
|
|
|
292
330
|
const liquidity = positionData.market.liquidity;
|
|
293
331
|
if (assets > liquidity) {
|
|
294
332
|
throw new InsufficientBlueLiquidityError({
|
|
295
|
-
market: this.
|
|
333
|
+
market: this.parsedMarket.id,
|
|
296
334
|
assets,
|
|
297
335
|
liquidity,
|
|
298
336
|
});
|
|
299
337
|
}
|
|
300
338
|
const blue = getChainAddress(this.chainId, "blue");
|
|
301
339
|
const factory = getChainAddress(this.chainId, "midnightBlueBuyCallbackFactory");
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
340
|
+
const boundedShares = parseUint256("shares", shares);
|
|
341
|
+
if (boundedShares === 0n) {
|
|
342
|
+
throw new NonPositiveInputError("shares", boundedShares);
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
marketParams: this.parsedMarket,
|
|
346
|
+
callbackAddress,
|
|
347
|
+
userAddress,
|
|
348
|
+
shares: boundedShares,
|
|
305
349
|
metadata,
|
|
306
|
-
|
|
350
|
+
to: blue,
|
|
351
|
+
factory,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
withdrawBuyCallbackPrepared(parsed) {
|
|
355
|
+
const { userAddress, callbackAddress, factory, to: blue } = parsed;
|
|
356
|
+
const tx = buildBlueWithdrawBuyCallback(parsed);
|
|
307
357
|
return {
|
|
308
358
|
getRequirements: async () => {
|
|
359
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
309
360
|
const viemClient = this.client.viemClient;
|
|
310
|
-
|
|
361
|
+
// Confirm the RPC chain before prerequisite reads.
|
|
362
|
+
await chainCheck();
|
|
363
|
+
// Reject missing registry contracts before prerequisite reads.
|
|
311
364
|
await assertRegistryTargetsHaveCode(viemClient, this.chainId, [
|
|
312
365
|
{ role: "blue", address: blue },
|
|
313
366
|
{ role: "midnightBlueBuyCallbackFactory", address: factory },
|
|
314
|
-
]);
|
|
367
|
+
], chainCheck);
|
|
315
368
|
// Check the factory first: OWNER() on an arbitrary address can revert or lie.
|
|
316
369
|
const isBlueBuyCallback = await readContract(viemClient, {
|
|
317
370
|
address: factory,
|
|
@@ -355,194 +408,192 @@ export class MorphoBlue {
|
|
|
355
408
|
}
|
|
356
409
|
/** {@inheritDoc BlueActions.supplyCollateral} */
|
|
357
410
|
supplyCollateral(params) {
|
|
358
|
-
|
|
411
|
+
return this.supplyCollateralPrepared(this.parseSupplyCollateralParams(params));
|
|
412
|
+
}
|
|
413
|
+
parseSupplyCollateralParams(params) {
|
|
359
414
|
const { userAddress, collateralAssets, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
415
|
+
return {
|
|
416
|
+
...this.parseSupplyCollateralBorrowParams({
|
|
417
|
+
now: params.now,
|
|
418
|
+
userAddress,
|
|
419
|
+
collateralAssets,
|
|
420
|
+
borrowAssets: 0n,
|
|
421
|
+
nativeAmount,
|
|
422
|
+
deadline,
|
|
423
|
+
referralFeePct,
|
|
424
|
+
referralFeeRecipient,
|
|
425
|
+
}),
|
|
364
426
|
borrowAssets: 0n,
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
});
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
supplyCollateralPrepared(parsed) {
|
|
430
|
+
const combinedAction = this.supplyCollateralBorrowPrepared(parsed);
|
|
370
431
|
return {
|
|
371
432
|
getRequirements: combinedAction.getRequirements,
|
|
372
433
|
buildTx: (signatures) => {
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
userAddress,
|
|
380
|
-
collateralAssets,
|
|
381
|
-
nativeAmount,
|
|
382
|
-
deadline,
|
|
383
|
-
referralFeePct,
|
|
384
|
-
referralFeeRecipient,
|
|
385
|
-
requirementSignature: token,
|
|
434
|
+
const transaction = combinedAction.buildTx(signatures);
|
|
435
|
+
return deepFreeze({
|
|
436
|
+
...transaction,
|
|
437
|
+
action: {
|
|
438
|
+
...transaction.action,
|
|
439
|
+
type: "blueSupplyCollateral",
|
|
386
440
|
},
|
|
387
|
-
metadata,
|
|
388
441
|
});
|
|
389
442
|
},
|
|
390
443
|
};
|
|
391
444
|
}
|
|
392
445
|
/** {@inheritDoc BlueActions.borrow} */
|
|
393
446
|
borrow(params) {
|
|
394
|
-
|
|
395
|
-
|
|
447
|
+
return this.borrowPrepared(this.parseBorrowParams(params));
|
|
448
|
+
}
|
|
449
|
+
parseBorrowParams(params) {
|
|
450
|
+
const { userAddress, borrowAssets, positionData, reallocations, maxPenalty, deadline, referralFeePct, referralFeeRecipient, } = params;
|
|
396
451
|
const normalizedReallocations = [...(reallocations ?? [])];
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
452
|
+
return {
|
|
453
|
+
...this.parseSupplyCollateralBorrowParams({
|
|
454
|
+
now: params.now,
|
|
455
|
+
userAddress,
|
|
456
|
+
collateralAssets: 0n,
|
|
457
|
+
borrowAssets,
|
|
458
|
+
positionData,
|
|
459
|
+
reallocations: normalizedReallocations,
|
|
460
|
+
maxPenalty,
|
|
461
|
+
deadline,
|
|
462
|
+
referralFeePct,
|
|
463
|
+
referralFeeRecipient,
|
|
464
|
+
}),
|
|
400
465
|
collateralAssets: 0n,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
referralFeePct,
|
|
406
|
-
referralFeeRecipient,
|
|
407
|
-
});
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
borrowPrepared(parsed) {
|
|
469
|
+
const combinedAction = this.supplyCollateralBorrowPrepared(parsed);
|
|
408
470
|
return {
|
|
409
471
|
getRequirements: () => combinedAction.getRequirements(),
|
|
410
472
|
buildTx: (signatures) => {
|
|
411
|
-
const
|
|
412
|
-
return
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
userAddress,
|
|
416
|
-
borrowAssets,
|
|
417
|
-
maxLtv: this.getMaxLtv(),
|
|
418
|
-
reallocations: normalizedReallocations,
|
|
419
|
-
deadline,
|
|
420
|
-
referralFeePct,
|
|
421
|
-
referralFeeRecipient,
|
|
422
|
-
authorizationSignature: authorization,
|
|
423
|
-
},
|
|
424
|
-
metadata,
|
|
473
|
+
const transaction = combinedAction.buildTx(signatures);
|
|
474
|
+
return deepFreeze({
|
|
475
|
+
...transaction,
|
|
476
|
+
action: { ...transaction.action, type: "blueBorrow" },
|
|
425
477
|
});
|
|
426
478
|
},
|
|
427
479
|
};
|
|
428
480
|
}
|
|
429
481
|
/** {@inheritDoc BlueActions.repay} */
|
|
430
482
|
repay(params) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
483
|
+
return this.repayPrepared(this.parseRepayParams(params));
|
|
484
|
+
}
|
|
485
|
+
parseRepayParams(params) {
|
|
486
|
+
return {
|
|
487
|
+
...this.parseRepayWithdrawCollateralParams({
|
|
488
|
+
now: params.now,
|
|
489
|
+
...params,
|
|
490
|
+
collateralAssets: 0n,
|
|
491
|
+
}),
|
|
434
492
|
collateralAssets: 0n,
|
|
435
|
-
}
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
repayPrepared(parsed) {
|
|
496
|
+
const combinedAction = this.repayWithdrawCollateralPrepared(parsed);
|
|
436
497
|
return {
|
|
437
498
|
getRequirements: combinedAction.getRequirements,
|
|
438
499
|
buildTx: (signatures) => {
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const { repayAssets, repayShares, maxRepayAssets, nativeAmount, referralFeePct, referralFeeRecipient, deadline, } = combinedTransaction.action.args;
|
|
444
|
-
return blueRepay({
|
|
445
|
-
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
446
|
-
args: {
|
|
447
|
-
userAddress: params.userAddress,
|
|
448
|
-
repayAssets,
|
|
449
|
-
repayShares,
|
|
450
|
-
maxRepayAssets,
|
|
451
|
-
nativeAmount,
|
|
452
|
-
deadline,
|
|
453
|
-
referralFeePct,
|
|
454
|
-
referralFeeRecipient,
|
|
455
|
-
requirementSignature: token,
|
|
456
|
-
},
|
|
457
|
-
metadata,
|
|
500
|
+
const transaction = combinedAction.buildTx(signatures);
|
|
501
|
+
return deepFreeze({
|
|
502
|
+
...transaction,
|
|
503
|
+
action: { ...transaction.action, type: "blueRepay" },
|
|
458
504
|
});
|
|
459
505
|
},
|
|
460
506
|
};
|
|
461
507
|
}
|
|
462
508
|
/** {@inheritDoc BlueActions.withdrawCollateral} */
|
|
463
509
|
withdrawCollateral(params) {
|
|
464
|
-
|
|
510
|
+
return this.withdrawCollateralPrepared(this.parseWithdrawCollateralParams(params));
|
|
511
|
+
}
|
|
512
|
+
parseWithdrawCollateralParams(params) {
|
|
465
513
|
const { userAddress, positionData, collateralAssets, deadline, referralFeePct, referralFeeRecipient, } = params;
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
514
|
+
return {
|
|
515
|
+
...this.parseRepayWithdrawCollateralParams({
|
|
516
|
+
now: params.now,
|
|
517
|
+
userAddress,
|
|
518
|
+
positionData,
|
|
519
|
+
repayAssets: 0n,
|
|
520
|
+
collateralAssets,
|
|
521
|
+
deadline,
|
|
522
|
+
referralFeePct,
|
|
523
|
+
referralFeeRecipient,
|
|
524
|
+
}),
|
|
470
525
|
repayAssets: 0n,
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
526
|
+
repayShares: 0n,
|
|
527
|
+
maxRepayAssets: 0n,
|
|
528
|
+
hasRepay: false,
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
withdrawCollateralPrepared(parsed) {
|
|
532
|
+
const combinedAction = this.repayWithdrawCollateralPrepared(parsed);
|
|
476
533
|
return {
|
|
477
534
|
getRequirements: () => combinedAction.getRequirements(),
|
|
478
535
|
buildTx: (signatures) => {
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
userAddress,
|
|
486
|
-
collateralAssets: combinedArgs.collateralAssets,
|
|
487
|
-
maxLtv: combinedArgs.maxLtv,
|
|
488
|
-
deadline: combinedArgs.deadline,
|
|
489
|
-
referralFeePct: combinedArgs.referralFeePct,
|
|
490
|
-
referralFeeRecipient: combinedArgs.referralFeeRecipient,
|
|
491
|
-
authorizationSignature: authorization,
|
|
536
|
+
const transaction = combinedAction.buildTx(signatures);
|
|
537
|
+
return deepFreeze({
|
|
538
|
+
...transaction,
|
|
539
|
+
action: {
|
|
540
|
+
...transaction.action,
|
|
541
|
+
type: "blueWithdrawCollateral",
|
|
492
542
|
},
|
|
493
|
-
metadata,
|
|
494
543
|
});
|
|
495
544
|
},
|
|
496
545
|
};
|
|
497
546
|
}
|
|
498
547
|
/** {@inheritDoc BlueActions.repayWithdrawCollateral} */
|
|
499
548
|
repayWithdrawCollateral(params) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
const
|
|
504
|
-
this.
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
const referralFeePct = params.referralFeePct ?? 0n;
|
|
549
|
+
return this.repayWithdrawCollateralPrepared(this.parseRepayWithdrawCollateralParams(params));
|
|
550
|
+
}
|
|
551
|
+
parseRepayWithdrawCollateralParams(params) {
|
|
552
|
+
const { userAddress, positionData, collateralAssets, nativeAmount, deadline, } = params;
|
|
553
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
|
|
554
|
+
const createdAt = params.now ?? Time.timestamp();
|
|
555
|
+
const normalized = this.validateWriteCommon(params, createdAt);
|
|
508
556
|
const repayAssets = params.repayAssets ?? 0n;
|
|
509
557
|
const repayShares = params.repayShares ?? 0n;
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (repayAssets > 0n && repayShares > 0n) {
|
|
520
|
-
throw new MutuallyExclusiveRepayAmountsError(this.marketParams.id);
|
|
521
|
-
}
|
|
558
|
+
const lowerRepayAssets = parseNonnegative("repayAssets", repayAssets);
|
|
559
|
+
const lowerRepayShares = parseNonnegative("repayShares", repayShares);
|
|
560
|
+
const lowerCollateralAssets = parseNonnegative("collateralAssets", collateralAssets);
|
|
561
|
+
const mode = parseBlueRepayMode(this.parsedMarket, {
|
|
562
|
+
repayAssets,
|
|
563
|
+
repayShares,
|
|
564
|
+
collateralAssets,
|
|
565
|
+
});
|
|
566
|
+
const referralFeePct = normalized.referralFeePct;
|
|
522
567
|
const hasRepay = repayAssets > 0n || repayShares > 0n;
|
|
523
|
-
if (!hasRepay && collateralAssets === 0n) {
|
|
524
|
-
throw new NonPositiveInputError("repayAssets, repayShares, or collateralAssets", 0n);
|
|
525
|
-
}
|
|
526
568
|
if (positionData == null) {
|
|
527
|
-
throw new MissingAccrualPositionError(this.
|
|
569
|
+
throw new MissingAccrualPositionError(this.parsedMarket.id);
|
|
528
570
|
}
|
|
571
|
+
// Reject a snapshot for another user or market.
|
|
529
572
|
validateAccrualPosition({
|
|
530
573
|
positionData,
|
|
531
|
-
expectedMarketId: this.
|
|
574
|
+
expectedMarketId: this.parsedMarket.id,
|
|
532
575
|
expectedUser: userAddress,
|
|
533
576
|
});
|
|
534
|
-
const { simulatedRepayShares, accruedPosition, expectedRepayAssets } =
|
|
577
|
+
const { simulatedRepayShares, accruedPosition, expectedRepayAssets } = quoteBlueRepay({
|
|
578
|
+
marketId: this.parsedMarket.id,
|
|
535
579
|
positionData,
|
|
536
580
|
repayAssets,
|
|
537
581
|
repayShares,
|
|
538
582
|
deadline,
|
|
539
583
|
now: createdAt,
|
|
584
|
+
healthTimestamp: collateralAssets > 0n
|
|
585
|
+
? getBlueBundlesV1QuoteTimestamp({
|
|
586
|
+
lastUpdate: positionData.market.lastUpdate,
|
|
587
|
+
now: createdAt,
|
|
588
|
+
deadline,
|
|
589
|
+
})
|
|
590
|
+
: undefined,
|
|
540
591
|
});
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
const nativeValue =
|
|
592
|
+
const maxRepayAssets = expectedRepayAssets +
|
|
593
|
+
getBlueBundlesV1ReferralFeeAssets(expectedRepayAssets, referralFeePct);
|
|
594
|
+
const nativeValue = parseNativeFunding({
|
|
544
595
|
chainId: this.chainId,
|
|
545
|
-
token: this.
|
|
596
|
+
token: this.parsedMarket.loanToken,
|
|
546
597
|
fundedAmount: maxRepayAssets,
|
|
547
598
|
nativeAmount,
|
|
548
599
|
});
|
|
@@ -550,22 +601,52 @@ export class MorphoBlue {
|
|
|
550
601
|
const postRepayPosition = hasRepay
|
|
551
602
|
? accruedPosition.repay(repayAssets, simulatedRepayShares).position
|
|
552
603
|
: accruedPosition;
|
|
604
|
+
// Reject collateral withdrawal that would leave unsafe debt.
|
|
553
605
|
validatePositionHealthAfterWithdraw({
|
|
554
606
|
positionData: postRepayPosition,
|
|
555
607
|
withdrawAmount: collateralAssets,
|
|
556
|
-
lltv: this.
|
|
557
|
-
marketId: this.
|
|
608
|
+
lltv: this.parsedMarket.lltv,
|
|
609
|
+
marketId: this.parsedMarket.id,
|
|
558
610
|
});
|
|
559
611
|
}
|
|
612
|
+
const legs = {
|
|
613
|
+
...normalized,
|
|
614
|
+
chainId: this.chainId,
|
|
615
|
+
userAddress,
|
|
616
|
+
marketParams: this.parsedMarket,
|
|
617
|
+
now: params.now,
|
|
618
|
+
metadata,
|
|
619
|
+
repayAssets: parseUint256Max("repayAssets", lowerRepayAssets),
|
|
620
|
+
repayShares: parseUint256Max("repayShares", lowerRepayShares),
|
|
621
|
+
collateralAssets: parseUint256Max("collateralAssets", lowerCollateralAssets),
|
|
622
|
+
maxLtv: parseUint256("maxLtv", collateralAssets > 0n ? this.getMaxLtv() : maxUint256),
|
|
623
|
+
hasRepay,
|
|
624
|
+
minimumRepayAssets: repayAssets +
|
|
625
|
+
getBlueBundlesV1ReferralFeeAssets(repayAssets, referralFeePct),
|
|
626
|
+
};
|
|
627
|
+
const cap = parseBlueRepayCap(mode, parseUint256("maxRepayAssets", maxRepayAssets));
|
|
628
|
+
const coveredCap = parseBlueRepayCoverage(legs, cap);
|
|
629
|
+
const input = {
|
|
630
|
+
...legs,
|
|
631
|
+
maxRepayAssets: coveredCap,
|
|
632
|
+
value: nativeValue,
|
|
633
|
+
};
|
|
634
|
+
return input;
|
|
635
|
+
}
|
|
636
|
+
repayWithdrawCollateralPrepared(parsed) {
|
|
637
|
+
const { userAddress, collateralAssets, deadline, hasRepay, maxRepayAssets, value: nativeValue, marketParams, } = parsed;
|
|
560
638
|
return {
|
|
561
639
|
getRequirements: async (requirementsParams) => {
|
|
562
|
-
const
|
|
640
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
641
|
+
const now = parsed.now ?? Time.timestamp();
|
|
642
|
+
// Reject expiry before continuing this call.
|
|
563
643
|
this.validateDeadline(deadline, now);
|
|
564
|
-
|
|
644
|
+
const nativeOnly = nativeValue > 0n && collateralAssets === 0n;
|
|
645
|
+
await this.assertWriteTargets(chainCheck, nativeOnly);
|
|
565
646
|
const [tokenRequirements, authorizationRequirements] = await Promise.all([
|
|
566
647
|
hasRepay && nativeValue === 0n
|
|
567
|
-
? this.getTokenRequirements({
|
|
568
|
-
token:
|
|
648
|
+
? this.getTokenRequirements(chainCheck, {
|
|
649
|
+
token: marketParams.loanToken,
|
|
569
650
|
amount: maxRepayAssets,
|
|
570
651
|
userAddress,
|
|
571
652
|
deadline,
|
|
@@ -574,7 +655,7 @@ export class MorphoBlue {
|
|
|
574
655
|
})
|
|
575
656
|
: Promise.resolve([]),
|
|
576
657
|
collateralAssets > 0n
|
|
577
|
-
? this.getAuthorizationRequirements({
|
|
658
|
+
? this.getAuthorizationRequirements(chainCheck, {
|
|
578
659
|
userAddress,
|
|
579
660
|
deadline,
|
|
580
661
|
now,
|
|
@@ -588,95 +669,94 @@ export class MorphoBlue {
|
|
|
588
669
|
token: hasRepay && nativeValue === 0n,
|
|
589
670
|
authorization: collateralAssets > 0n,
|
|
590
671
|
});
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
:
|
|
594
|
-
|
|
595
|
-
throw new MaxRepayAssetsBelowRepayAssetsError(selectedMaxRepayAssets, maxRepayAssets);
|
|
596
|
-
}
|
|
597
|
-
return blueRepayWithdrawCollateral({
|
|
598
|
-
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
599
|
-
args: {
|
|
600
|
-
userAddress,
|
|
601
|
-
repayAssets,
|
|
602
|
-
repayShares,
|
|
603
|
-
maxRepayAssets: selectedMaxRepayAssets,
|
|
604
|
-
collateralAssets,
|
|
605
|
-
maxLtv: collateralAssets > 0n ? this.getMaxLtv() : maxUint256,
|
|
606
|
-
nativeAmount: nativeValue > 0n ? nativeValue : undefined,
|
|
607
|
-
deadline,
|
|
608
|
-
referralFeePct,
|
|
609
|
-
referralFeeRecipient,
|
|
610
|
-
requirementSignature: token,
|
|
611
|
-
authorizationSignature: authorization,
|
|
612
|
-
},
|
|
613
|
-
metadata,
|
|
672
|
+
return buildBlueRepayWithdrawCollateral(parsed, {
|
|
673
|
+
requirementSignature: token,
|
|
674
|
+
authorizationSignature: authorization,
|
|
675
|
+
signatureFunding: true,
|
|
614
676
|
});
|
|
615
677
|
},
|
|
616
678
|
};
|
|
617
679
|
}
|
|
618
680
|
/** {@inheritDoc BlueActions.supplyCollateralBorrow} */
|
|
619
681
|
supplyCollateralBorrow(params) {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
const
|
|
624
|
-
this.
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
throw new NegativeInputError("borrowAssets", borrowAssets);
|
|
630
|
-
}
|
|
682
|
+
return this.supplyCollateralBorrowPrepared(this.parseSupplyCollateralBorrowParams(params));
|
|
683
|
+
}
|
|
684
|
+
parseSupplyCollateralBorrowParams(params) {
|
|
685
|
+
const { userAddress, collateralAssets, borrowAssets, positionData } = params;
|
|
686
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
|
|
687
|
+
const createdAt = params.now ?? Time.timestamp();
|
|
688
|
+
const normalized = this.validateWriteCommon(params, createdAt);
|
|
689
|
+
const lowerCollateralAssets = parseNonnegative("collateralAssets", collateralAssets);
|
|
690
|
+
const lowerBorrowAssets = parseNonnegative("borrowAssets", borrowAssets);
|
|
631
691
|
if (collateralAssets === 0n && borrowAssets === 0n) {
|
|
632
692
|
throw new NonPositiveInputError("collateralAssets or borrowAssets", 0n);
|
|
633
693
|
}
|
|
634
|
-
const
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
const
|
|
641
|
-
if (reallocationPenaltyAssets > borrowAssets) {
|
|
642
|
-
throw new InputExceedsMaxError({
|
|
643
|
-
field: "reallocationPenaltyAssets",
|
|
644
|
-
value: reallocationPenaltyAssets,
|
|
645
|
-
max: borrowAssets,
|
|
646
|
-
});
|
|
647
|
-
}
|
|
694
|
+
const mode = parseBlueSupplyCollateralBorrowMode({
|
|
695
|
+
collateralAssets,
|
|
696
|
+
borrowAssets,
|
|
697
|
+
reallocations: [...(params.reallocations ?? [])],
|
|
698
|
+
maxPenalty: params.maxPenalty,
|
|
699
|
+
});
|
|
700
|
+
const allocations = parseBlueSupplyCollateralBorrowAllocations(this.parsedMarket, mode);
|
|
648
701
|
if (borrowAssets > 0n) {
|
|
649
702
|
if (positionData == null) {
|
|
650
|
-
throw new MissingAccrualPositionError(this.
|
|
703
|
+
throw new MissingAccrualPositionError(this.parsedMarket.id);
|
|
651
704
|
}
|
|
705
|
+
// Reject a snapshot for another user or market.
|
|
652
706
|
validateAccrualPosition({
|
|
653
707
|
positionData,
|
|
654
|
-
expectedMarketId: this.
|
|
708
|
+
expectedMarketId: this.parsedMarket.id,
|
|
655
709
|
expectedUser: userAddress,
|
|
656
710
|
});
|
|
711
|
+
// Reject resulting debt above the buffered LLTV.
|
|
657
712
|
validatePositionHealth({
|
|
658
|
-
positionData: positionData.accrueInterest(
|
|
713
|
+
positionData: positionData.accrueInterest(getBlueBundlesV1QuoteTimestamp({
|
|
714
|
+
lastUpdate: positionData.market.lastUpdate,
|
|
715
|
+
now: createdAt,
|
|
716
|
+
deadline: normalized.deadline,
|
|
717
|
+
})),
|
|
659
718
|
additionalCollateral: collateralAssets,
|
|
660
719
|
borrowAmount: borrowAssets,
|
|
661
|
-
marketId: this.
|
|
662
|
-
lltv: this.
|
|
720
|
+
marketId: this.parsedMarket.id,
|
|
721
|
+
lltv: this.parsedMarket.lltv,
|
|
663
722
|
});
|
|
664
723
|
}
|
|
665
|
-
const nativeValue =
|
|
724
|
+
const nativeValue = parseNativeFunding({
|
|
666
725
|
chainId: this.chainId,
|
|
667
|
-
token: this.
|
|
726
|
+
token: this.parsedMarket.collateralToken,
|
|
668
727
|
fundedAmount: collateralAssets,
|
|
669
|
-
nativeAmount,
|
|
728
|
+
nativeAmount: params.nativeAmount,
|
|
670
729
|
});
|
|
730
|
+
const input = {
|
|
731
|
+
...normalized,
|
|
732
|
+
chainId: this.chainId,
|
|
733
|
+
userAddress,
|
|
734
|
+
marketParams: this.parsedMarket,
|
|
735
|
+
now: params.now,
|
|
736
|
+
metadata,
|
|
737
|
+
publicAllocations: allocations.publicAllocations,
|
|
738
|
+
reallocationPenaltyAssets: allocations.penaltyAssets,
|
|
739
|
+
value: nativeValue,
|
|
740
|
+
collateralAssets: parseUint256Max("collateralAssets", lowerCollateralAssets),
|
|
741
|
+
borrowAssets: parseUint256Max("borrowAssets", lowerBorrowAssets),
|
|
742
|
+
maxLtv: parseUint256("maxLtv", borrowAssets > 0n ? this.getMaxLtv() : maxUint256),
|
|
743
|
+
};
|
|
744
|
+
return input;
|
|
745
|
+
}
|
|
746
|
+
supplyCollateralBorrowPrepared(parsed) {
|
|
747
|
+
const { userAddress, collateralAssets, borrowAssets, deadline, value: nativeValue, marketParams, } = parsed;
|
|
671
748
|
return {
|
|
672
749
|
getRequirements: async (requirementsParams) => {
|
|
673
|
-
const
|
|
750
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
751
|
+
const now = parsed.now ?? Time.timestamp();
|
|
752
|
+
// Reject expiry before continuing this call.
|
|
674
753
|
this.validateDeadline(deadline, now);
|
|
675
|
-
|
|
754
|
+
// Native-only funding has no token or authorization chain check.
|
|
755
|
+
await this.assertWriteTargets(chainCheck, nativeValue > 0n && borrowAssets === 0n);
|
|
676
756
|
const [tokenRequirements, authorizationRequirements] = await Promise.all([
|
|
677
757
|
collateralAssets > 0n && nativeValue === 0n
|
|
678
|
-
? this.getTokenRequirements({
|
|
679
|
-
token:
|
|
758
|
+
? this.getTokenRequirements(chainCheck, {
|
|
759
|
+
token: marketParams.collateralToken,
|
|
680
760
|
amount: collateralAssets,
|
|
681
761
|
userAddress,
|
|
682
762
|
deadline,
|
|
@@ -685,7 +765,7 @@ export class MorphoBlue {
|
|
|
685
765
|
})
|
|
686
766
|
: Promise.resolve([]),
|
|
687
767
|
borrowAssets > 0n
|
|
688
|
-
? this.getAuthorizationRequirements({
|
|
768
|
+
? this.getAuthorizationRequirements(chainCheck, {
|
|
689
769
|
userAddress,
|
|
690
770
|
deadline,
|
|
691
771
|
now,
|
|
@@ -699,75 +779,86 @@ export class MorphoBlue {
|
|
|
699
779
|
token: collateralAssets > 0n && nativeValue === 0n,
|
|
700
780
|
authorization: borrowAssets > 0n,
|
|
701
781
|
});
|
|
702
|
-
return
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
userAddress,
|
|
706
|
-
collateralAssets,
|
|
707
|
-
borrowAssets,
|
|
708
|
-
maxLtv: borrowAssets > 0n ? this.getMaxLtv() : maxUint256,
|
|
709
|
-
nativeAmount: nativeValue > 0n ? nativeValue : undefined,
|
|
710
|
-
reallocations,
|
|
711
|
-
deadline,
|
|
712
|
-
referralFeePct,
|
|
713
|
-
referralFeeRecipient,
|
|
714
|
-
requirementSignature: token,
|
|
715
|
-
authorizationSignature: authorization,
|
|
716
|
-
},
|
|
717
|
-
metadata,
|
|
782
|
+
return buildBlueSupplyCollateralBorrow(parsed, {
|
|
783
|
+
requirementSignature: token,
|
|
784
|
+
authorizationSignature: authorization,
|
|
718
785
|
});
|
|
719
786
|
},
|
|
720
787
|
};
|
|
721
788
|
}
|
|
722
789
|
/** {@inheritDoc BlueActions.refinance} */
|
|
723
790
|
refinance(params) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
const
|
|
728
|
-
this.
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
const referralFeePct =
|
|
791
|
+
return this.refinancePrepared(this.parseRefinanceParams(params));
|
|
792
|
+
}
|
|
793
|
+
parseRefinanceParams(params) {
|
|
794
|
+
const { userAddress, positionData, destination } = params;
|
|
795
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
|
|
796
|
+
const createdAt = params.now ?? Time.timestamp();
|
|
797
|
+
const normalized = this.validateWriteCommon(params, createdAt);
|
|
798
|
+
const destinationMarketParams = parseBlueMarket(destination.marketParams);
|
|
799
|
+
const referralFeePct = normalized.referralFeePct;
|
|
733
800
|
if (positionData == null) {
|
|
734
|
-
throw new MissingAccrualPositionError(this.
|
|
801
|
+
throw new MissingAccrualPositionError(this.parsedMarket.id);
|
|
735
802
|
}
|
|
803
|
+
// Reject a snapshot for another user or market.
|
|
736
804
|
validateAccrualPosition({
|
|
737
805
|
positionData,
|
|
738
|
-
expectedMarketId: this.
|
|
806
|
+
expectedMarketId: this.parsedMarket.id,
|
|
739
807
|
expectedUser: userAddress,
|
|
740
808
|
});
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
809
|
+
if (positionData.borrowShares <= 0n) {
|
|
810
|
+
throw new NonPositiveInputError("positionData.borrowShares", positionData.borrowShares);
|
|
811
|
+
}
|
|
812
|
+
const markets = parseBlueRefinanceMarkets({
|
|
813
|
+
sourceMarketParams: this.parsedMarket,
|
|
814
|
+
destinationMarketParams,
|
|
746
815
|
});
|
|
747
816
|
if (destination.positionData == null) {
|
|
748
|
-
throw new MissingAccrualPositionError(
|
|
817
|
+
throw new MissingAccrualPositionError(destinationMarketParams.id);
|
|
749
818
|
}
|
|
819
|
+
// Reject a snapshot for another user or market.
|
|
750
820
|
validateAccrualPosition({
|
|
751
821
|
positionData: destination.positionData,
|
|
752
|
-
expectedMarketId:
|
|
822
|
+
expectedMarketId: destinationMarketParams.id,
|
|
753
823
|
expectedUser: userAddress,
|
|
754
824
|
});
|
|
755
|
-
const
|
|
756
|
-
|
|
825
|
+
const allocations = parseBlueAllocations([...(params.reallocations ?? [])], {
|
|
826
|
+
marketParams: markets.destinationMarketParams,
|
|
827
|
+
maxPenalty: params.maxPenalty,
|
|
828
|
+
});
|
|
757
829
|
validateBlueRefinanceQuote({
|
|
758
|
-
destinationMarketParams
|
|
830
|
+
destinationMarketParams,
|
|
759
831
|
sourcePosition: positionData,
|
|
760
832
|
destinationPosition: destination.positionData,
|
|
761
|
-
|
|
833
|
+
penaltyAssets: allocations.penaltyAssets,
|
|
762
834
|
referralFeePct,
|
|
763
835
|
now: createdAt,
|
|
836
|
+
deadline: normalized.deadline,
|
|
764
837
|
});
|
|
838
|
+
const input = {
|
|
839
|
+
...markets,
|
|
840
|
+
...normalized,
|
|
841
|
+
chainId: this.chainId,
|
|
842
|
+
userAddress,
|
|
843
|
+
now: params.now,
|
|
844
|
+
metadata,
|
|
845
|
+
publicAllocations: allocations.publicAllocations,
|
|
846
|
+
reallocationPenaltyAssets: allocations.penaltyAssets,
|
|
847
|
+
maxLtv: parseUint256("maxLtv", this.getMaxLtv(destinationMarketParams)),
|
|
848
|
+
};
|
|
849
|
+
return input;
|
|
850
|
+
}
|
|
851
|
+
refinancePrepared(parsed) {
|
|
852
|
+
const { userAddress, deadline } = parsed;
|
|
765
853
|
return {
|
|
766
854
|
getRequirements: async () => {
|
|
767
|
-
const
|
|
855
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
856
|
+
const now = parsed.now ?? Time.timestamp();
|
|
857
|
+
// Reject expiry before continuing this call.
|
|
768
858
|
this.validateDeadline(deadline, now);
|
|
769
|
-
|
|
770
|
-
|
|
859
|
+
// Reject missing write targets before resolving requirements.
|
|
860
|
+
await this.assertWriteTargets(chainCheck);
|
|
861
|
+
return this.getAuthorizationRequirements(chainCheck, {
|
|
771
862
|
userAddress,
|
|
772
863
|
deadline,
|
|
773
864
|
now,
|
|
@@ -777,22 +868,8 @@ export class MorphoBlue {
|
|
|
777
868
|
const { authorization } = selectBlueBundlesV1RequirementSignatures(signatures, {
|
|
778
869
|
authorization: true,
|
|
779
870
|
});
|
|
780
|
-
return
|
|
781
|
-
|
|
782
|
-
chainId: this.chainId,
|
|
783
|
-
sourceMarketParams: this.marketParams,
|
|
784
|
-
destinationMarketParams: destination.marketParams,
|
|
785
|
-
},
|
|
786
|
-
args: {
|
|
787
|
-
userAddress,
|
|
788
|
-
maxLtv: this.getMaxLtv(destination.marketParams),
|
|
789
|
-
reallocations,
|
|
790
|
-
deadline,
|
|
791
|
-
referralFeePct,
|
|
792
|
-
referralFeeRecipient,
|
|
793
|
-
authorizationSignature: authorization,
|
|
794
|
-
},
|
|
795
|
-
metadata,
|
|
871
|
+
return buildBlueRefinance(parsed, {
|
|
872
|
+
authorizationSignature: authorization,
|
|
796
873
|
});
|
|
797
874
|
},
|
|
798
875
|
};
|
|
@@ -851,7 +928,8 @@ export class MorphoBlue {
|
|
|
851
928
|
* ```
|
|
852
929
|
*/
|
|
853
930
|
async getVaultV2BlueReallocationData({ vaultAddresses, block, }) {
|
|
854
|
-
|
|
931
|
+
// Confirm the RPC chain before prerequisite reads.
|
|
932
|
+
await createChainCheck(this.client.viemClient, this.chainId)();
|
|
855
933
|
const client = this.client.viemClient;
|
|
856
934
|
const fetchParams = {
|
|
857
935
|
blockNumber: block.number,
|
|
@@ -859,17 +937,17 @@ export class MorphoBlue {
|
|
|
859
937
|
deployless: this.client.options.supportDeployless,
|
|
860
938
|
};
|
|
861
939
|
const [targetMarket, vaultEntries, blueBalance] = await Promise.all([
|
|
862
|
-
fetchMarket(this.
|
|
940
|
+
fetchMarket(this.parsedMarket.id, client, fetchParams),
|
|
863
941
|
Promise.all(vaultAddresses.map(async (address) => {
|
|
864
942
|
const vault = await fetchAccrualVaultV2(address, client, fetchParams);
|
|
865
943
|
const publicAllocatorData = await fetchVaultV2BluePublicAllocatorData(vault, client, {
|
|
866
944
|
...fetchParams,
|
|
867
|
-
targetMarketParams: this.
|
|
945
|
+
targetMarketParams: new MarketParams(this.parsedMarket),
|
|
868
946
|
});
|
|
869
947
|
return { publicAllocatorData, vault };
|
|
870
948
|
})),
|
|
871
949
|
readContract(client, {
|
|
872
|
-
address: this.
|
|
950
|
+
address: this.parsedMarket.loanToken,
|
|
873
951
|
abi: erc20Abi,
|
|
874
952
|
functionName: "balanceOf",
|
|
875
953
|
args: [getChainAddresses(this.chainId).blue],
|
|
@@ -879,7 +957,7 @@ export class MorphoBlue {
|
|
|
879
957
|
return new VaultV2BlueReallocationData({
|
|
880
958
|
chainId: this.chainId,
|
|
881
959
|
timestamp: block.timestamp,
|
|
882
|
-
blueBalances: { [this.
|
|
960
|
+
blueBalances: { [this.parsedMarket.loanToken]: blueBalance },
|
|
883
961
|
markets: { [targetMarket.id]: targetMarket },
|
|
884
962
|
vaults: Object.fromEntries(vaultEntries.map(({ vault }) => [vault.address, vault])),
|
|
885
963
|
allocations: Object.fromEntries(vaultEntries.map(({ publicAllocatorData, vault }) => [
|
|
@@ -918,20 +996,28 @@ export class MorphoBlue {
|
|
|
918
996
|
* For `refinance`, compute the plan on the destination-market handle (for
|
|
919
997
|
* example, `client.morpho.blue(destination.marketParams, chainId)`), not the
|
|
920
998
|
* source-market handle. Pass the source position's `borrowAssets` accrued to
|
|
921
|
-
*
|
|
922
|
-
* `
|
|
999
|
+
* the resolved plan expiry (or the required action deadline for entity
|
|
1000
|
+
* `refinance`) as `operation.amount`. With
|
|
1001
|
+
* `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
|
|
1002
|
+
* `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
|
|
1003
|
+
* resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
|
|
1004
|
+
* `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
|
|
1005
|
+
* compatibility. The optional `operation.referralFeePct` is WAD-scaled.
|
|
923
1006
|
* The planner includes the referral fee and its own planned allocator-leg
|
|
924
1007
|
* penalties in destination debt. Refinance never uses vaults with a 100%
|
|
925
|
-
* penalty.
|
|
1008
|
+
* penalty. When executing the returned reallocations, pass the same explicit
|
|
1009
|
+
* maxPenalty to borrow, supplyCollateralBorrow, withdraw, or refinance.
|
|
926
1010
|
*
|
|
927
1011
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
928
1012
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
929
1013
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
1014
|
+
* @throws {InvalidBigIntInputError} when options.maxPenalty is supplied but is not a bigint.
|
|
930
1015
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
931
1016
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
932
1017
|
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
|
|
933
1018
|
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD, or a selected borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
|
|
934
1019
|
* @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
|
|
1020
|
+
* @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
|
|
935
1021
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
936
1022
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
937
1023
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -952,7 +1038,8 @@ export class MorphoBlue {
|
|
|
952
1038
|
* ```
|
|
953
1039
|
*/
|
|
954
1040
|
getVaultV2BlueReallocations({ reallocationData, options, }) {
|
|
1041
|
+
// Reject cross-chain inputs before continuing.
|
|
955
1042
|
validateChainId(reallocationData.chainId, this.chainId);
|
|
956
|
-
return reallocationData.computeVaultV2BlueReallocations(this.
|
|
1043
|
+
return reallocationData.computeVaultV2BlueReallocations(this.parsedMarket.id, options);
|
|
957
1044
|
}
|
|
958
1045
|
}
|