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