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