@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
|
@@ -2,31 +2,25 @@ import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, Token, } from "@morpho-org/b
|
|
|
2
2
|
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, Time, } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { isAddressEqual } from "viem";
|
|
5
|
-
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams as parseBundlesCommon, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
6
|
+
import { createChainCheck, } from "../../actions/requirements/chainCheck.js";
|
|
7
|
+
import { buildVaultV1Deposit, } from "../../actions/vaultV1/deposit.js";
|
|
8
|
+
import { buildVaultV1InKindRedeem, } from "../../actions/vaultV1/inKindRedeem.js";
|
|
9
|
+
import { buildVaultV1MigrateToV2, } from "../../actions/vaultV1/migrateToV2.js";
|
|
10
|
+
import { buildVaultV1Redeem, } from "../../actions/vaultV1/redeem.js";
|
|
11
|
+
import { buildVaultV1Withdraw, } from "../../actions/vaultV1/withdraw.js";
|
|
8
12
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
13
|
import { resolveTransactionMetadata } from "../../helpers/metadata.js";
|
|
10
|
-
import {
|
|
14
|
+
import { parseUint256 } from "../../helpers/parse.js";
|
|
15
|
+
import { validateNativeVaultAsset, validateReferenceTime, validateVaultDepositDeadline, } from "../../helpers/validate.js";
|
|
11
16
|
import { AmountAndSharesExclusiveError, ExpiredDeadlineError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
12
17
|
import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
|
|
13
|
-
import {
|
|
18
|
+
import { getParsedBundlesTokenRequirements, parseGetBundlesTokenRequirements, } from "../requirements/getBundlesTokenRequirements.js";
|
|
19
|
+
import { getParsedVaultBundlesSharesRequirements, parseVaultBundlesSharesRequirements, } from "../requirements/getVaultBundlesSharesRequirements.js";
|
|
14
20
|
import { getVaultV1InKindRedeemRequirements } from "../requirements/getVaultV1InKindRedeemRequirements.js";
|
|
15
|
-
import {
|
|
21
|
+
import { validateNativeRequirements } from "../requirements/validateNativeRequirements.js";
|
|
16
22
|
import { computeVaultV1InKindRedeemQuote } from "./inKindRedeemQuote.js";
|
|
17
23
|
import { computeVaultV1MigrateToV2Quote } from "./migrateToV2Quote.js";
|
|
18
|
-
function getMigrationAmounts(params) {
|
|
19
|
-
const assets = "assets" in params ? params.assets : undefined;
|
|
20
|
-
const shares = "shares" in params ? params.shares : undefined;
|
|
21
|
-
if ((assets == null) === (shares == null)) {
|
|
22
|
-
throw new AmountAndSharesExclusiveError();
|
|
23
|
-
}
|
|
24
|
-
const selectedAmount = assets ?? shares ?? 0n;
|
|
25
|
-
if (selectedAmount <= 0n) {
|
|
26
|
-
throw new NonPositiveInputError(assets == null ? "shares" : "assets", selectedAmount);
|
|
27
|
-
}
|
|
28
|
-
return { assets, shares };
|
|
29
|
-
}
|
|
30
24
|
/** Binds a viem client to a Vault V1 (MetaMorpho) vault's action builders. */
|
|
31
25
|
export class MorphoVaultV1 {
|
|
32
26
|
client;
|
|
@@ -39,7 +33,10 @@ export class MorphoVaultV1 {
|
|
|
39
33
|
this.chainId = chainId;
|
|
40
34
|
}
|
|
41
35
|
async getData(parameters) {
|
|
42
|
-
|
|
36
|
+
return this.getDataWithChainCheck(createChainCheck(this.client.viemClient, this.chainId), parameters);
|
|
37
|
+
}
|
|
38
|
+
async getDataWithChainCheck(chainCheck, parameters) {
|
|
39
|
+
await chainCheck();
|
|
43
40
|
return fetchAccrualVault(this.vault, this.client.viemClient, {
|
|
44
41
|
...parameters,
|
|
45
42
|
deployless: this.client.options.supportDeployless,
|
|
@@ -53,16 +50,20 @@ export class MorphoVaultV1 {
|
|
|
53
50
|
*
|
|
54
51
|
* @param roles - Registry labels to resolve and check.
|
|
55
52
|
*/
|
|
56
|
-
async assertWriteTargets(roles) {
|
|
53
|
+
async assertWriteTargets(roles, chainCheck) {
|
|
57
54
|
const targets = [];
|
|
58
55
|
for (const role of roles) {
|
|
59
56
|
const address = getChainAddress(this.chainId, role);
|
|
60
57
|
targets.push({ role, address });
|
|
61
58
|
}
|
|
62
|
-
await assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets);
|
|
59
|
+
await assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets, chainCheck);
|
|
63
60
|
}
|
|
64
61
|
/** {@inheritDoc VaultV1Actions.deposit} */
|
|
65
62
|
deposit(params) {
|
|
63
|
+
return this.buildDeposit(this.parseDeposit(params));
|
|
64
|
+
}
|
|
65
|
+
/** Owns the complete raw deposit boundary, including snapshot-derived price protection. */
|
|
66
|
+
parseDeposit(params) {
|
|
66
67
|
const suppliedNow = params.now;
|
|
67
68
|
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
68
69
|
const { userAddress, vaultData } = params;
|
|
@@ -72,23 +73,26 @@ export class MorphoVaultV1 {
|
|
|
72
73
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
73
74
|
}
|
|
74
75
|
const createdAt = suppliedNow ?? Time.timestamp();
|
|
76
|
+
// Reject a non-bigint clock before deriving the default deadline.
|
|
77
|
+
validateReferenceTime(createdAt);
|
|
75
78
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
76
79
|
if (deadline <= createdAt) {
|
|
77
80
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
78
81
|
}
|
|
79
|
-
const common =
|
|
82
|
+
const common = parseBundlesCommon({
|
|
80
83
|
deadline,
|
|
81
84
|
referralFeePct: params.referralFeePct,
|
|
82
85
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
83
86
|
});
|
|
84
87
|
const funding = resolveBundlesFunding(params);
|
|
85
|
-
//
|
|
86
|
-
|
|
88
|
+
// Enforce ABI and native-asset bounds at the constructor, before lazy requirements.
|
|
89
|
+
parseUint256(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
|
|
87
90
|
if (funding.value > 0n) {
|
|
88
|
-
// The native path must target the chain's registered wrapped-native asset.
|
|
89
91
|
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
90
92
|
}
|
|
91
93
|
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
94
|
+
// Bound forward accrual before deriving the deposit price protection.
|
|
95
|
+
validateVaultDepositDeadline(deadline, { now: createdAt });
|
|
92
96
|
const maxSharePrice = computeVaultMaxSharePrice({
|
|
93
97
|
vaultData,
|
|
94
98
|
deadline,
|
|
@@ -96,35 +100,69 @@ export class MorphoVaultV1 {
|
|
|
96
100
|
slippageTolerance: params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE,
|
|
97
101
|
});
|
|
98
102
|
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
103
|
+
if (maxSharePrice <= 0n) {
|
|
104
|
+
throw new NonPositiveInputError("maxSharePrice", maxSharePrice);
|
|
105
|
+
}
|
|
106
|
+
// A computed price must still fit the contract's ABI.
|
|
107
|
+
parseUint256("maxSharePrice", maxSharePrice);
|
|
108
|
+
const parsed = {
|
|
109
|
+
vault: { chainId: this.chainId, address: this.vault, asset: vaultAsset },
|
|
110
|
+
userAddress,
|
|
111
|
+
funding,
|
|
112
|
+
maxSharePrice,
|
|
113
|
+
common,
|
|
114
|
+
metadata,
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
suppliedNow,
|
|
118
|
+
parsed,
|
|
119
|
+
spender,
|
|
120
|
+
vaultAsset,
|
|
121
|
+
userAddress,
|
|
122
|
+
funding,
|
|
123
|
+
deadline,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
buildDeposit(input) {
|
|
127
|
+
const { parsed, spender, vaultAsset, userAddress, funding, deadline } = input;
|
|
99
128
|
let pendingRequirements;
|
|
100
129
|
return Object.freeze({
|
|
101
130
|
getRequirements: async (requirementOptions) => {
|
|
102
|
-
const now = suppliedNow ?? Time.timestamp();
|
|
131
|
+
const now = input.suppliedNow ?? Time.timestamp();
|
|
103
132
|
if (deadline <= now) {
|
|
104
133
|
throw new ExpiredDeadlineError(deadline, now);
|
|
105
134
|
}
|
|
135
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
136
|
+
if (funding.value > 0n) {
|
|
137
|
+
// Native funding skips the token resolver's chain validation.
|
|
138
|
+
await validateNativeRequirements(this.client.viemClient, {
|
|
139
|
+
chainId: this.chainId,
|
|
140
|
+
chainCheck,
|
|
141
|
+
assertWriteTargets: () => this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck),
|
|
142
|
+
});
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
|
|
146
|
+
const tokenInput = parseGetBundlesTokenRequirements(this.client.viemClient, {
|
|
147
|
+
token: vaultAsset,
|
|
148
|
+
spender,
|
|
149
|
+
amount: funding.assets,
|
|
150
|
+
owner: userAddress,
|
|
151
|
+
chainId: this.chainId,
|
|
152
|
+
deadline,
|
|
153
|
+
supportSignature: this.client.options.supportSignature,
|
|
154
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
155
|
+
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
156
|
+
now,
|
|
157
|
+
});
|
|
158
|
+
// Check each non-no-op invocation before sharing an in-flight state read.
|
|
159
|
+
if (tokenInput.amount > 0n) {
|
|
160
|
+
await chainCheck();
|
|
161
|
+
}
|
|
106
162
|
if (pendingRequirements != null) {
|
|
107
163
|
return await pendingRequirements;
|
|
108
164
|
}
|
|
109
|
-
|
|
110
|
-
// allowance/nonce reads.
|
|
111
|
-
const pending = (async () => {
|
|
112
|
-
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
113
|
-
return funding.value > 0n
|
|
114
|
-
? []
|
|
115
|
-
: getBundlesTokenRequirements(this.client.viemClient, {
|
|
116
|
-
token: vaultAsset,
|
|
117
|
-
spender,
|
|
118
|
-
amount: funding.assets,
|
|
119
|
-
owner: userAddress,
|
|
120
|
-
chainId: this.chainId,
|
|
121
|
-
deadline,
|
|
122
|
-
supportSignature: this.client.options.supportSignature,
|
|
123
|
-
supportDeployless: this.client.options.supportDeployless,
|
|
124
|
-
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
125
|
-
now,
|
|
126
|
-
});
|
|
127
|
-
})();
|
|
165
|
+
const pending = getParsedBundlesTokenRequirements({ viemClient: this.client.viemClient, chainCheck }, tokenInput);
|
|
128
166
|
pendingRequirements = pending;
|
|
129
167
|
try {
|
|
130
168
|
return await pending;
|
|
@@ -139,29 +177,14 @@ export class MorphoVaultV1 {
|
|
|
139
177
|
buildTx: (signatures) => {
|
|
140
178
|
// The pure deposit action rejects a token signature supplied alongside native funding.
|
|
141
179
|
const requirementSignature = selectBundlesTokenRequirementSignature(signatures, { spender, amount: funding.assets, deadline });
|
|
142
|
-
return
|
|
143
|
-
vault: {
|
|
144
|
-
chainId: this.chainId,
|
|
145
|
-
address: this.vault,
|
|
146
|
-
asset: vaultAsset,
|
|
147
|
-
},
|
|
148
|
-
args: {
|
|
149
|
-
...(funding.value > 0n
|
|
150
|
-
? { nativeAmount: funding.assets }
|
|
151
|
-
: { amount: funding.assets }),
|
|
152
|
-
maxSharePrice,
|
|
153
|
-
userAddress,
|
|
154
|
-
requirementSignature,
|
|
155
|
-
referralFeePct: common.referralFeePct,
|
|
156
|
-
referralFeeRecipient: common.referralFeeRecipient,
|
|
157
|
-
deadline,
|
|
158
|
-
},
|
|
159
|
-
metadata,
|
|
160
|
-
});
|
|
180
|
+
return buildVaultV1Deposit(parsed, { requirementSignature });
|
|
161
181
|
},
|
|
162
182
|
});
|
|
163
183
|
}
|
|
164
184
|
withdraw(params) {
|
|
185
|
+
return this.buildWithdraw(this.parseWithdraw(params));
|
|
186
|
+
}
|
|
187
|
+
parseWithdraw(params) {
|
|
165
188
|
const suppliedNow = params.now;
|
|
166
189
|
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
167
190
|
const { amount, userAddress, vaultData } = params;
|
|
@@ -173,13 +196,13 @@ export class MorphoVaultV1 {
|
|
|
173
196
|
throw new NonPositiveInputError("amount", amount);
|
|
174
197
|
}
|
|
175
198
|
// Reject values outside the ABI range before resolving any requirements.
|
|
176
|
-
|
|
199
|
+
const parsedAmount = parseUint256("amount", amount);
|
|
177
200
|
const createdAt = suppliedNow ?? Time.timestamp();
|
|
178
201
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
179
202
|
if (deadline <= createdAt) {
|
|
180
203
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
181
204
|
}
|
|
182
|
-
const common =
|
|
205
|
+
const common = parseBundlesCommon({
|
|
183
206
|
deadline,
|
|
184
207
|
referralFeePct: params.referralFeePct,
|
|
185
208
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
@@ -194,15 +217,34 @@ export class MorphoVaultV1 {
|
|
|
194
217
|
assets: amount,
|
|
195
218
|
slippageTolerance,
|
|
196
219
|
});
|
|
220
|
+
const parsed = {
|
|
221
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
222
|
+
args: { amount: parsedAmount, userAddress, ...common },
|
|
223
|
+
common,
|
|
224
|
+
metadata,
|
|
225
|
+
};
|
|
226
|
+
return {
|
|
227
|
+
suppliedNow,
|
|
228
|
+
parsed,
|
|
229
|
+
spender,
|
|
230
|
+
vaultData,
|
|
231
|
+
userAddress,
|
|
232
|
+
requiredShareAllowance,
|
|
233
|
+
deadline,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
buildWithdraw(input) {
|
|
237
|
+
const { parsed, spender, vaultData, userAddress, requiredShareAllowance, deadline, } = input;
|
|
197
238
|
return Object.freeze({
|
|
198
239
|
getRequirements: async () => {
|
|
199
|
-
const now = suppliedNow ?? Time.timestamp();
|
|
240
|
+
const now = input.suppliedNow ?? Time.timestamp();
|
|
200
241
|
if (deadline <= now) {
|
|
201
242
|
throw new ExpiredDeadlineError(deadline, now);
|
|
202
243
|
}
|
|
203
|
-
|
|
244
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
245
|
+
await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
|
|
204
246
|
// Re-read the live share allowance on every call instead of caching the resolved requirements.
|
|
205
|
-
return
|
|
247
|
+
return getParsedVaultBundlesSharesRequirements({ viemClient: this.client.viemClient, chainCheck }, parseVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
206
248
|
vaultData,
|
|
207
249
|
version: "vaultV1",
|
|
208
250
|
owner: userAddress,
|
|
@@ -211,7 +253,7 @@ export class MorphoVaultV1 {
|
|
|
211
253
|
deadline,
|
|
212
254
|
supportSignature: this.client.options.supportSignature,
|
|
213
255
|
now,
|
|
214
|
-
});
|
|
256
|
+
}));
|
|
215
257
|
},
|
|
216
258
|
buildTx: (signatures) => {
|
|
217
259
|
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
@@ -219,23 +261,15 @@ export class MorphoVaultV1 {
|
|
|
219
261
|
amount: requiredShareAllowance,
|
|
220
262
|
deadline,
|
|
221
263
|
});
|
|
222
|
-
return
|
|
223
|
-
vault: { chainId: this.chainId, address: this.vault },
|
|
224
|
-
args: {
|
|
225
|
-
amount,
|
|
226
|
-
userAddress,
|
|
227
|
-
requirementSignature: permit,
|
|
228
|
-
referralFeePct: common.referralFeePct,
|
|
229
|
-
referralFeeRecipient: common.referralFeeRecipient,
|
|
230
|
-
deadline,
|
|
231
|
-
},
|
|
232
|
-
metadata,
|
|
233
|
-
});
|
|
264
|
+
return buildVaultV1Withdraw(parsed, { requirementSignature: permit });
|
|
234
265
|
},
|
|
235
266
|
});
|
|
236
267
|
}
|
|
237
268
|
/** {@inheritDoc VaultV1Actions.redeem} */
|
|
238
269
|
redeem(params) {
|
|
270
|
+
return this.buildRedeem(this.parseRedeem(params));
|
|
271
|
+
}
|
|
272
|
+
parseRedeem(params) {
|
|
239
273
|
const suppliedNow = params.now;
|
|
240
274
|
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
241
275
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
@@ -248,21 +282,32 @@ export class MorphoVaultV1 {
|
|
|
248
282
|
if (deadline <= createdAt) {
|
|
249
283
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
250
284
|
}
|
|
251
|
-
const common =
|
|
285
|
+
const common = parseBundlesCommon({
|
|
252
286
|
deadline,
|
|
253
287
|
referralFeePct: params.referralFeePct,
|
|
254
288
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
255
289
|
});
|
|
256
290
|
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
291
|
+
const parsed = {
|
|
292
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
293
|
+
args: { shares: parseUint256("shares", shares), userAddress, ...common },
|
|
294
|
+
common,
|
|
295
|
+
metadata,
|
|
296
|
+
};
|
|
297
|
+
return { suppliedNow, parsed, spender, shares, userAddress, deadline };
|
|
298
|
+
}
|
|
299
|
+
buildRedeem(input) {
|
|
300
|
+
const { parsed, spender, shares, userAddress, deadline } = input;
|
|
257
301
|
return Object.freeze({
|
|
258
302
|
getRequirements: async () => {
|
|
259
|
-
const now = suppliedNow ?? Time.timestamp();
|
|
303
|
+
const now = input.suppliedNow ?? Time.timestamp();
|
|
260
304
|
if (deadline <= now) {
|
|
261
305
|
throw new ExpiredDeadlineError(deadline, now);
|
|
262
306
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
307
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
308
|
+
await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
|
|
309
|
+
return getParsedVaultBundlesSharesRequirements({ viemClient: this.client.viemClient, chainCheck }, parseVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
310
|
+
vaultData: await this.getDataWithChainCheck(chainCheck),
|
|
266
311
|
version: "vaultV1",
|
|
267
312
|
owner: userAddress,
|
|
268
313
|
chainId: this.chainId,
|
|
@@ -270,7 +315,7 @@ export class MorphoVaultV1 {
|
|
|
270
315
|
deadline,
|
|
271
316
|
supportSignature: this.client.options.supportSignature,
|
|
272
317
|
now,
|
|
273
|
-
});
|
|
318
|
+
}));
|
|
274
319
|
},
|
|
275
320
|
buildTx: (signatures) => {
|
|
276
321
|
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
@@ -278,26 +323,16 @@ export class MorphoVaultV1 {
|
|
|
278
323
|
amount: shares,
|
|
279
324
|
deadline,
|
|
280
325
|
});
|
|
281
|
-
return
|
|
282
|
-
vault: { chainId: this.chainId, address: this.vault },
|
|
283
|
-
args: {
|
|
284
|
-
shares,
|
|
285
|
-
userAddress,
|
|
286
|
-
requirementSignature: permit,
|
|
287
|
-
referralFeePct: common.referralFeePct,
|
|
288
|
-
referralFeeRecipient: common.referralFeeRecipient,
|
|
289
|
-
deadline,
|
|
290
|
-
},
|
|
291
|
-
metadata,
|
|
292
|
-
});
|
|
326
|
+
return buildVaultV1Redeem(parsed, { requirementSignature: permit });
|
|
293
327
|
},
|
|
294
328
|
});
|
|
295
329
|
}
|
|
296
330
|
/** {@inheritDoc VaultV1Actions.inKindRedeem} */
|
|
297
331
|
inKindRedeem(params) {
|
|
298
|
-
|
|
332
|
+
return this.buildInKindRedeem(this.parseInKindRedeem(params));
|
|
333
|
+
}
|
|
334
|
+
parseInKindRedeem({ now: suppliedNow, amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
|
|
299
335
|
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
300
|
-
const { amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, } = params;
|
|
301
336
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
302
337
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
303
338
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
@@ -310,6 +345,29 @@ export class MorphoVaultV1 {
|
|
|
310
345
|
now: suppliedNow ?? Time.timestamp(),
|
|
311
346
|
chainId: this.chainId,
|
|
312
347
|
});
|
|
348
|
+
const parsed = {
|
|
349
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
350
|
+
args: {
|
|
351
|
+
amount,
|
|
352
|
+
marketParamsList: marketParamsListSnapshot,
|
|
353
|
+
userAddress,
|
|
354
|
+
deadline,
|
|
355
|
+
},
|
|
356
|
+
metadata,
|
|
357
|
+
};
|
|
358
|
+
return {
|
|
359
|
+
suppliedNow,
|
|
360
|
+
parsed,
|
|
361
|
+
deadline,
|
|
362
|
+
userAddress,
|
|
363
|
+
vaultData,
|
|
364
|
+
vaultExitBundlesV1,
|
|
365
|
+
amount,
|
|
366
|
+
requiredShareAllowance,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
buildInKindRedeem(input) {
|
|
370
|
+
const { parsed, deadline, userAddress, vaultData, vaultExitBundlesV1, amount, requiredShareAllowance, } = input;
|
|
313
371
|
return {
|
|
314
372
|
getRequirements: () => getVaultV1InKindRedeemRequirements(this.client.viemClient, {
|
|
315
373
|
vaultData,
|
|
@@ -320,7 +378,7 @@ export class MorphoVaultV1 {
|
|
|
320
378
|
requiredShareAllowance,
|
|
321
379
|
supportSignature: this.client.options.supportSignature,
|
|
322
380
|
amount,
|
|
323
|
-
now: suppliedNow,
|
|
381
|
+
now: input.suppliedNow,
|
|
324
382
|
}),
|
|
325
383
|
buildTx: (signatures) => {
|
|
326
384
|
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
@@ -328,22 +386,17 @@ export class MorphoVaultV1 {
|
|
|
328
386
|
amount: requiredShareAllowance,
|
|
329
387
|
deadline,
|
|
330
388
|
});
|
|
331
|
-
return
|
|
332
|
-
|
|
333
|
-
args: {
|
|
334
|
-
amount,
|
|
335
|
-
marketParamsList: marketParamsListSnapshot,
|
|
336
|
-
userAddress,
|
|
337
|
-
deadline,
|
|
338
|
-
requirementSignature: permit,
|
|
339
|
-
},
|
|
340
|
-
metadata,
|
|
389
|
+
return buildVaultV1InKindRedeem(parsed, {
|
|
390
|
+
requirementSignature: permit,
|
|
341
391
|
});
|
|
342
392
|
},
|
|
343
393
|
};
|
|
344
394
|
}
|
|
345
395
|
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
346
396
|
migrateToV2(params) {
|
|
397
|
+
return this.buildMigrateToV2(this.parseMigrateToV2(params));
|
|
398
|
+
}
|
|
399
|
+
parseMigrateToV2(params) {
|
|
347
400
|
const suppliedNow = params.now;
|
|
348
401
|
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
349
402
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
@@ -356,26 +409,38 @@ export class MorphoVaultV1 {
|
|
|
356
409
|
if (isAddressEqual(this.vault, params.targetVault.address)) {
|
|
357
410
|
throw new SameVaultMigrationError(this.vault);
|
|
358
411
|
}
|
|
359
|
-
const
|
|
412
|
+
const assets = "assets" in params ? params.assets : undefined;
|
|
413
|
+
const shares = "shares" in params ? params.shares : undefined;
|
|
414
|
+
if ((assets == null) === (shares == null)) {
|
|
415
|
+
throw new AmountAndSharesExclusiveError();
|
|
416
|
+
}
|
|
417
|
+
const selected = assets ?? shares ?? 0n;
|
|
418
|
+
if (selected <= 0n) {
|
|
419
|
+
throw new NonPositiveInputError(assets == null ? "shares" : "assets", selected);
|
|
420
|
+
}
|
|
360
421
|
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
361
422
|
validateSlippageTolerance(slippageTolerance);
|
|
362
423
|
const createdAt = suppliedNow ?? Time.timestamp();
|
|
424
|
+
// Reject a non-bigint clock before deriving the default deadline.
|
|
425
|
+
validateReferenceTime(createdAt);
|
|
363
426
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
364
427
|
if (deadline <= createdAt) {
|
|
365
428
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
366
429
|
}
|
|
367
|
-
const common =
|
|
430
|
+
const common = parseBundlesCommon({
|
|
368
431
|
deadline,
|
|
369
432
|
referralFeePct: params.referralFeePct,
|
|
370
433
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
371
434
|
});
|
|
435
|
+
// Only the destination receives a deposit; the source vault is an exit.
|
|
436
|
+
// V1 redeem accrues market interest and performance fees before converting shares.
|
|
372
437
|
const { maxSharePriceVaultV2, requiredShareAllowance } = computeVaultV1MigrateToV2Quote({
|
|
373
438
|
sourceVault: params.sourceVault,
|
|
374
439
|
targetVault: params.targetVault,
|
|
375
|
-
...(assets == null ? { shares:
|
|
440
|
+
...(assets == null ? { shares: selected } : { assets: selected }),
|
|
376
441
|
referralFeePct: common.referralFeePct,
|
|
377
|
-
deadline,
|
|
378
442
|
slippageTolerance,
|
|
443
|
+
deadline,
|
|
379
444
|
now: createdAt,
|
|
380
445
|
});
|
|
381
446
|
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
@@ -394,15 +459,41 @@ export class MorphoVaultV1 {
|
|
|
394
459
|
extensions: [...domain.extensions],
|
|
395
460
|
}),
|
|
396
461
|
});
|
|
462
|
+
if (maxSharePriceVaultV2 <= 0n) {
|
|
463
|
+
throw new NonPositiveInputError("maxSharePriceVaultV2", maxSharePriceVaultV2);
|
|
464
|
+
}
|
|
465
|
+
// Preserve destination positivity before the source and destination ABI bounds.
|
|
466
|
+
parseUint256(assets == null ? "shares" : "assets", selected);
|
|
467
|
+
parseUint256("maxSharePriceVaultV2", maxSharePriceVaultV2);
|
|
468
|
+
const parsed = {
|
|
469
|
+
vault: { chainId: this.chainId, address: this.vault, asset: sourceAsset },
|
|
470
|
+
args: { targetVault: targetAddress, targetAsset, userAddress, ...common },
|
|
471
|
+
bounds: { assets, shares, maxSharePriceVaultV2 },
|
|
472
|
+
common,
|
|
473
|
+
metadata,
|
|
474
|
+
};
|
|
475
|
+
return {
|
|
476
|
+
suppliedNow,
|
|
477
|
+
parsed,
|
|
478
|
+
deadline,
|
|
479
|
+
sourceToken,
|
|
480
|
+
userAddress,
|
|
481
|
+
requiredShareAllowance,
|
|
482
|
+
spender,
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
buildMigrateToV2(input) {
|
|
486
|
+
const { parsed, deadline, sourceToken, userAddress, requiredShareAllowance, spender, } = input;
|
|
397
487
|
return Object.freeze({
|
|
398
488
|
getRequirements: async () => {
|
|
399
|
-
const now = suppliedNow ?? Time.timestamp();
|
|
489
|
+
const now = input.suppliedNow ?? Time.timestamp();
|
|
400
490
|
if (deadline <= now) {
|
|
401
491
|
throw new ExpiredDeadlineError(deadline, now);
|
|
402
492
|
}
|
|
403
|
-
|
|
493
|
+
const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
|
|
494
|
+
await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
|
|
404
495
|
// Re-read the live share allowance on every call instead of caching the resolved requirements.
|
|
405
|
-
return
|
|
496
|
+
return getParsedVaultBundlesSharesRequirements({ viemClient: this.client.viemClient, chainCheck }, parseVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
406
497
|
vaultData: sourceToken,
|
|
407
498
|
version: "vaultV1",
|
|
408
499
|
owner: userAddress,
|
|
@@ -411,7 +502,7 @@ export class MorphoVaultV1 {
|
|
|
411
502
|
deadline,
|
|
412
503
|
supportSignature: this.client.options.supportSignature,
|
|
413
504
|
now,
|
|
414
|
-
});
|
|
505
|
+
}));
|
|
415
506
|
},
|
|
416
507
|
buildTx: (signatures) => {
|
|
417
508
|
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
@@ -419,24 +510,8 @@ export class MorphoVaultV1 {
|
|
|
419
510
|
amount: requiredShareAllowance,
|
|
420
511
|
deadline,
|
|
421
512
|
});
|
|
422
|
-
return
|
|
423
|
-
|
|
424
|
-
chainId: this.chainId,
|
|
425
|
-
address: this.vault,
|
|
426
|
-
asset: sourceAsset,
|
|
427
|
-
},
|
|
428
|
-
args: {
|
|
429
|
-
targetVault: targetAddress,
|
|
430
|
-
targetAsset,
|
|
431
|
-
...(assets == null ? { shares: shares ?? 0n } : { assets }),
|
|
432
|
-
maxSharePriceVaultV2,
|
|
433
|
-
userAddress,
|
|
434
|
-
requirementSignature: permit,
|
|
435
|
-
referralFeePct: common.referralFeePct,
|
|
436
|
-
referralFeeRecipient: common.referralFeeRecipient,
|
|
437
|
-
deadline,
|
|
438
|
-
},
|
|
439
|
-
metadata,
|
|
513
|
+
return buildVaultV1MigrateToV2(parsed, {
|
|
514
|
+
requirementSignature: permit,
|
|
440
515
|
});
|
|
441
516
|
},
|
|
442
517
|
});
|
|
@@ -22,4 +22,8 @@ export declare function computeVaultV2ForceWithdrawQuote({ exitAssets, vaultData
|
|
|
22
22
|
adapter: `0x${string}`;
|
|
23
23
|
minSharePriceE27: bigint;
|
|
24
24
|
requiredShareAllowance: bigint;
|
|
25
|
+
referral: {
|
|
26
|
+
readonly referralFeePct: bigint;
|
|
27
|
+
readonly referralFeeRecipient: Address;
|
|
28
|
+
};
|
|
25
29
|
};
|
|
@@ -2,7 +2,8 @@ import { DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { _try, Time } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { computeMinForceWithdrawSharePrice, computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, MAX_SLIPPAGE_TOLERANCE, resolveVaultV2ForceWithdrawEligibility, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { parseReferralFee } from "../../helpers/parse.js";
|
|
6
|
+
import { validateDeadline, validateUint256Field, } from "../../helpers/validate.js";
|
|
6
7
|
import { AdapterNotPartOfVaultError, ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, VaultV2ForceWithdrawCoverageError, VaultV2ForceWithdrawFeeSharesExceedBurnError, VaultV2ForceWithdrawSharePriceBelowFloorError, VaultV2ForceWithdrawZeroSharePriceError, VaultV2ForceWithdrawZeroWithdrawalError, VaultV2SingleAdapterRequiredError, VaultV2UndecodableLiquidityDataError, VaultV2UnsupportedExitAdapterError, VaultV2UnsupportedLiquidityAdapterError, } from "../../types/index.js";
|
|
7
8
|
const VAULT_V2_FEE_PROJECTION_HORIZON = Time.s.from.y(1n);
|
|
8
9
|
/** Resolves the supported adapter or reports the existing eligibility error. @internal */
|
|
@@ -62,9 +63,7 @@ export function computeVaultV2ForceWithdrawQuote({ exitAssets, vaultData, userAd
|
|
|
62
63
|
}
|
|
63
64
|
validateUint256Field("exitAssets", exitAssets);
|
|
64
65
|
validateSlippageTolerance(slippageTolerance);
|
|
65
|
-
|
|
66
|
-
// again on the encode path so a direct action caller gets the same guarantees.
|
|
67
|
-
validateReferralFee({ referralFeePct, referralFeeRecipient });
|
|
66
|
+
const referral = parseReferralFee({ referralFeePct, referralFeeRecipient });
|
|
68
67
|
if (minSharePriceE27Override != null) {
|
|
69
68
|
// An unbounded override reopens the exact hole this path closes: the contract reads
|
|
70
69
|
// `minSharePriceE27 == 0` as "no bound".
|
|
@@ -182,5 +181,11 @@ export function computeVaultV2ForceWithdrawQuote({ exitAssets, vaultData, userAd
|
|
|
182
181
|
// shares minted by the first withdrawal and enough headroom for the configured tolerance.
|
|
183
182
|
const allowanceSharePriceE27 = MathLib.max(MathLib.min(MathLib.mulDivDown(minSharePriceE27, MathLib.WAD - slippageTolerance, MathLib.WAD), minSharePriceE27 - 1n), 1n);
|
|
184
183
|
const requiredShareAllowance = MathLib.min(MathLib.max(MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27), MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n) + feeSharesProjected, maxUint256);
|
|
185
|
-
return {
|
|
184
|
+
return {
|
|
185
|
+
deadline,
|
|
186
|
+
adapter,
|
|
187
|
+
minSharePriceE27,
|
|
188
|
+
requiredShareAllowance,
|
|
189
|
+
referral,
|
|
190
|
+
};
|
|
186
191
|
}
|
|
@@ -16,13 +16,13 @@ export declare function computeVaultV2InKindRedeemQuote({ amount, marketParamsLi
|
|
|
16
16
|
}): {
|
|
17
17
|
deadline: bigint;
|
|
18
18
|
adapter: `0x${string}`;
|
|
19
|
-
marketParamsListSnapshot: {
|
|
19
|
+
marketParamsListSnapshot: readonly Readonly<{
|
|
20
20
|
loanToken: `0x${string}`;
|
|
21
21
|
collateralToken: `0x${string}`;
|
|
22
22
|
oracle: `0x${string}`;
|
|
23
23
|
irm: `0x${string}`;
|
|
24
24
|
lltv: bigint;
|
|
25
|
-
}[];
|
|
25
|
+
}>[];
|
|
26
26
|
requiredShareAllowance: bigint;
|
|
27
27
|
peak: bigint;
|
|
28
28
|
};
|
|
@@ -12,13 +12,7 @@ export function computeVaultV2InKindRedeemQuote({ amount, marketParamsList, vaul
|
|
|
12
12
|
if (amount <= 0n) {
|
|
13
13
|
throw new NonPositiveInputError("amount", amount);
|
|
14
14
|
}
|
|
15
|
-
const marketParamsListSnapshot = marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => ({
|
|
16
|
-
loanToken,
|
|
17
|
-
collateralToken,
|
|
18
|
-
oracle,
|
|
19
|
-
irm,
|
|
20
|
-
lltv,
|
|
21
|
-
}));
|
|
15
|
+
const marketParamsListSnapshot = Object.freeze(marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => Object.freeze({ loanToken, collateralToken, oracle, irm, lltv })));
|
|
22
16
|
const marketIdListSnapshot = marketParamsListSnapshot.map((marketParams) => MarketUtils.getMarketId(marketParams));
|
|
23
17
|
const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
|
|
24
18
|
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|