@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
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMidnightNativeFunding = exports.validateMidnightPositionBinding = exports.parseMidnightCollateral = exports.parseMidnightNativeCollateralAmount = exports.parseMidnightPositiveAmount = exports.parseMidnightAccount = exports.parseMidnightOwner = exports.parseMidnightAddress = exports.parseMidnightMarketInput = exports.parseMidnightMarketDeployment = exports.parseMidnightMarket = exports.parseMidnightUint128 = void 0;
|
|
4
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const index_js_1 = require("../types/index.js");
|
|
8
|
+
const encodeMidnightCalldata_js_1 = require("./encodeMidnightCalldata.js");
|
|
9
|
+
const validate_js_1 = require("./validate.js");
|
|
10
|
+
const validateMidnightAccount_js_1 = require("./validateMidnightAccount.js");
|
|
11
|
+
const validateMidnightBounds_js_1 = require("./validateMidnightBounds.js");
|
|
12
|
+
const validateMidnightMarket_js_1 = require("./validateMidnightMarket.js");
|
|
13
|
+
const validatePositiveInput_js_1 = require("./validatePositiveInput.js");
|
|
14
|
+
/** Checks the existing uint128 bound; the operation owns the field context. @internal */
|
|
15
|
+
const parseMidnightUint128 = (field, value) => {
|
|
16
|
+
// Enforce the storage bound before the operation uses the amount.
|
|
17
|
+
(0, validateMidnightBounds_js_1.validateMidnightUint128Field)(field, value);
|
|
18
|
+
return value;
|
|
19
|
+
};
|
|
20
|
+
exports.parseMidnightUint128 = parseMidnightUint128;
|
|
21
|
+
/** Owns and validates the ABI tuple instead of retaining caller-owned classes. @internal */
|
|
22
|
+
const parseMidnightMarket = (market, chainId) => (0, exports.parseMidnightMarketInput)((0, exports.parseMidnightMarketDeployment)(market, chainId));
|
|
23
|
+
exports.parseMidnightMarket = parseMidnightMarket;
|
|
24
|
+
/** Owns a market and checks deployment before operation-specific validation. @internal */
|
|
25
|
+
const parseMidnightMarketDeployment = (market, chainId) => {
|
|
26
|
+
// Preserve deployment errors before normalizing malformed raw market fields.
|
|
27
|
+
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market, chainId });
|
|
28
|
+
const struct = (0, morpho_ts_1.deepFreeze)(midnight_sdk_1.MarketUtils.toStruct(market));
|
|
29
|
+
return Object.freeze({ struct });
|
|
30
|
+
};
|
|
31
|
+
exports.parseMidnightMarketDeployment = parseMidnightMarketDeployment;
|
|
32
|
+
/** Completes the market ABI bound after mandatory operation checks. @internal */
|
|
33
|
+
const parseMidnightMarketInput = (market, input = "marketId") => Object.freeze({
|
|
34
|
+
...market,
|
|
35
|
+
id: (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)(input, () => midnight_sdk_1.MarketUtils.toId(market.struct)),
|
|
36
|
+
});
|
|
37
|
+
exports.parseMidnightMarketInput = parseMidnightMarketInput;
|
|
38
|
+
/** Checks address shape using Midnight's existing typed error. @internal */
|
|
39
|
+
const parseMidnightAddress = (field, value) => {
|
|
40
|
+
// Reject malformed addresses before comparisons or encoding.
|
|
41
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)(field, value);
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
exports.parseMidnightAddress = parseMidnightAddress;
|
|
45
|
+
/** Checks a shaped direct-call owner with the existing zero-owner error. @internal */
|
|
46
|
+
const parseMidnightOwner = (value) => {
|
|
47
|
+
if ((0, viem_1.isAddressEqual)(value, viem_1.zeroAddress)) {
|
|
48
|
+
throw new index_js_1.MidnightZeroOnBehalfError("onBehalf");
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
};
|
|
52
|
+
exports.parseMidnightOwner = parseMidnightOwner;
|
|
53
|
+
/** Checks an entity account using its established zero-account error. @internal */
|
|
54
|
+
const parseMidnightAccount = (field, value) => {
|
|
55
|
+
// Reject invalid accounts before preparing entity state.
|
|
56
|
+
(0, validateMidnightAccount_js_1.validateMidnightAccount)(field, value);
|
|
57
|
+
return value;
|
|
58
|
+
};
|
|
59
|
+
exports.parseMidnightAccount = parseMidnightAccount;
|
|
60
|
+
/** Checks a positive direct-call amount using the operation's error label. @internal */
|
|
61
|
+
const parseMidnightPositiveAmount = (field, value) => {
|
|
62
|
+
// Validation only; retain the canonical positivity guard before the uint128 bound.
|
|
63
|
+
(0, validatePositiveInput_js_1.validatePositiveInput)(field, value);
|
|
64
|
+
return (0, exports.parseMidnightUint128)(field, value);
|
|
65
|
+
};
|
|
66
|
+
exports.parseMidnightPositiveAmount = parseMidnightPositiveAmount;
|
|
67
|
+
/** Checks the collateral amount for standalone native supply. @internal */
|
|
68
|
+
const parseMidnightNativeCollateralAmount = (field, value) => {
|
|
69
|
+
if (typeof value !== "bigint") {
|
|
70
|
+
throw new index_js_1.InvalidBigIntInputError(field, value);
|
|
71
|
+
}
|
|
72
|
+
return (0, exports.parseMidnightPositiveAmount)(field, value);
|
|
73
|
+
};
|
|
74
|
+
exports.parseMidnightNativeCollateralAmount = parseMidnightNativeCollateralAmount;
|
|
75
|
+
/** Resolves a configured collateral before balance or approval calculations. @internal */
|
|
76
|
+
const parseMidnightCollateral = (market, index) => {
|
|
77
|
+
const collateral = midnight_sdk_1.MarketUtils.getCollateralByIndex(market.struct, index);
|
|
78
|
+
return Object.freeze({ index, token: collateral.token });
|
|
79
|
+
};
|
|
80
|
+
exports.parseMidnightCollateral = parseMidnightCollateral;
|
|
81
|
+
/** Checks snapshot ownership without treating it as permanent onchain proof. @internal */
|
|
82
|
+
const validateMidnightPositionBinding = (params) => {
|
|
83
|
+
if (params.positionData.marketId !== params.marketData.id) {
|
|
84
|
+
throw new index_js_1.MarketIdMismatchError(params.positionData.marketId, params.marketData.id);
|
|
85
|
+
}
|
|
86
|
+
// Reject a malformed address before viem compares it.
|
|
87
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("positionData.user", params.positionData.user);
|
|
88
|
+
if (!(0, viem_1.isAddressEqual)(params.positionData.user, params.accountAddress)) {
|
|
89
|
+
throw new index_js_1.AccrualPositionUserMismatchError(params.positionData.user, params.accountAddress);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
exports.validateMidnightPositionBinding = validateMidnightPositionBinding;
|
|
93
|
+
/** Checks partial native funding, retaining full-pull approval semantics. @internal */
|
|
94
|
+
const parseMidnightNativeFunding = (params) => Object.freeze((0, validate_js_1.validateMidnightNativeAmount)(params));
|
|
95
|
+
exports.parseMidnightNativeFunding = parseMidnightNativeFunding;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Tree, type TreeCreateRequest } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address, type Hex } from "viem";
|
|
3
|
+
/** Preserves maker and sell-receiver errors before the upstream tree constructor. @internal */
|
|
4
|
+
export declare const parseMidnightMakerTree: (params: {
|
|
5
|
+
readonly offers: Extract<TreeCreateRequest, {
|
|
6
|
+
readonly type: "priceV1";
|
|
7
|
+
}> | Extract<TreeCreateRequest, {
|
|
8
|
+
readonly type: "rateV1";
|
|
9
|
+
}> | Tree<"priceV1"> | Tree<"rateV1">;
|
|
10
|
+
readonly accountAddress: Address;
|
|
11
|
+
}) => Tree<"priceV1"> | Tree<"rateV1">;
|
|
12
|
+
/** Parses a maker tree once, preserving the opening/exit intent check order. @internal */
|
|
13
|
+
export declare const parseMidnightMakerIntent: (params: {
|
|
14
|
+
readonly offers: Parameters<typeof parseMidnightMakerTree>[0]["offers"];
|
|
15
|
+
readonly accountAddress: Address;
|
|
16
|
+
readonly side: "lend" | "borrow";
|
|
17
|
+
readonly reduceOnly: boolean;
|
|
18
|
+
}) => {
|
|
19
|
+
tree: Tree<"priceV1"> | Tree<"rateV1">;
|
|
20
|
+
reduceOnly: boolean;
|
|
21
|
+
accountAddress: `0x${string}`;
|
|
22
|
+
};
|
|
23
|
+
/** Parses state-independent maker publication bindings before any maker-state read. @internal */
|
|
24
|
+
export declare const parseMidnightMakerBinding: (params: {
|
|
25
|
+
readonly tree: Tree<"priceV1"> | Tree<"rateV1">;
|
|
26
|
+
readonly accountAddress: Address;
|
|
27
|
+
readonly chainId: number;
|
|
28
|
+
}) => {
|
|
29
|
+
tree: Tree<"priceV1"> | Tree<"rateV1">;
|
|
30
|
+
accountAddress: `0x${string}`;
|
|
31
|
+
ratifier: `0x${string}`;
|
|
32
|
+
ratifierType: "priceV1" | "rateV1";
|
|
33
|
+
};
|
|
34
|
+
/** Parses maker funding relationships without checking chain state or changing their timing. @internal */
|
|
35
|
+
export declare const parseMidnightMakerFundingBinding: (params: {
|
|
36
|
+
readonly tree: Tree<"priceV1"> | Tree<"rateV1">;
|
|
37
|
+
readonly loanToken: Address;
|
|
38
|
+
readonly callback?: {
|
|
39
|
+
readonly address: Address;
|
|
40
|
+
readonly data: Hex;
|
|
41
|
+
};
|
|
42
|
+
}) => {
|
|
43
|
+
loanToken: `0x${string}`;
|
|
44
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMidnightMakerFundingBinding = exports.parseMidnightMakerBinding = exports.parseMidnightMakerIntent = exports.parseMidnightMakerTree = void 0;
|
|
4
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const index_js_1 = require("../types/index.js");
|
|
8
|
+
const encodeMidnightCalldata_js_1 = require("./encodeMidnightCalldata.js");
|
|
9
|
+
const validateOfferSides_js_1 = require("./validateOfferSides.js");
|
|
10
|
+
/** Preserves maker and sell-receiver errors before the upstream tree constructor. @internal */
|
|
11
|
+
const parseMidnightMakerTree = (params) => {
|
|
12
|
+
const { offers, accountAddress } = params;
|
|
13
|
+
if (offers instanceof midnight_sdk_1.Tree) {
|
|
14
|
+
return offers;
|
|
15
|
+
}
|
|
16
|
+
return (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("offers", () => {
|
|
17
|
+
if ("root" in offers && "leaves" in offers) {
|
|
18
|
+
return midnight_sdk_1.Tree.from(offers);
|
|
19
|
+
}
|
|
20
|
+
for (const [index, { offer }] of offers.entries.entries()) {
|
|
21
|
+
if (!offer.buy && offer.receiverIfMakerIsSeller === viem_1.zeroAddress) {
|
|
22
|
+
if (!(0, viem_1.isAddressEqual)(offer.maker, accountAddress)) {
|
|
23
|
+
throw new index_js_1.MidnightOfferMakerMismatchError({
|
|
24
|
+
index,
|
|
25
|
+
expectedMaker: accountAddress,
|
|
26
|
+
actualMaker: offer.maker,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
throw new index_js_1.MidnightOfferSellerReceiverMismatchError({
|
|
30
|
+
index,
|
|
31
|
+
expectedReceiver: offer.maker,
|
|
32
|
+
actualReceiver: offer.receiverIfMakerIsSeller,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return midnight_sdk_1.Tree.from(offers);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
exports.parseMidnightMakerTree = parseMidnightMakerTree;
|
|
40
|
+
/** Parses a maker tree once, preserving the opening/exit intent check order. @internal */
|
|
41
|
+
const parseMidnightMakerIntent = (params) => {
|
|
42
|
+
const { side, reduceOnly } = params;
|
|
43
|
+
const tree = (0, exports.parseMidnightMakerTree)(params);
|
|
44
|
+
// Reject an exit's wrong side before checking its reduction flags.
|
|
45
|
+
if (reduceOnly) {
|
|
46
|
+
(0, validateOfferSides_js_1.validateOfferSides)(tree.offers, side === "lend");
|
|
47
|
+
}
|
|
48
|
+
tree.offers.forEach((offer, index) => {
|
|
49
|
+
if (reduceOnly && !offer.reduceOnly) {
|
|
50
|
+
throw new index_js_1.MidnightOfferNotReduceOnlyError({ index });
|
|
51
|
+
}
|
|
52
|
+
if (!reduceOnly && offer.reduceOnly) {
|
|
53
|
+
throw new index_js_1.MidnightOfferReduceOnlyError({ index });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
tree,
|
|
58
|
+
reduceOnly,
|
|
59
|
+
accountAddress: params.accountAddress,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.parseMidnightMakerIntent = parseMidnightMakerIntent;
|
|
63
|
+
/** Parses state-independent maker publication bindings before any maker-state read. @internal */
|
|
64
|
+
const parseMidnightMakerBinding = (params) => {
|
|
65
|
+
const { tree, chainId } = params;
|
|
66
|
+
const midnight = (0, morpho_ts_1.getChainAddress)(chainId, "midnight");
|
|
67
|
+
tree.offers.forEach((offer, index) => {
|
|
68
|
+
if (!(0, viem_1.isAddressEqual)(offer.maker, params.accountAddress)) {
|
|
69
|
+
throw new index_js_1.MidnightOfferMakerMismatchError({
|
|
70
|
+
index,
|
|
71
|
+
expectedMaker: params.accountAddress,
|
|
72
|
+
actualMaker: offer.maker,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (offer.continuousFeeCap !== 0n) {
|
|
76
|
+
throw new index_js_1.MidnightOfferContinuousFeeCapError({
|
|
77
|
+
index,
|
|
78
|
+
continuousFeeCap: offer.continuousFeeCap,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (!offer.buy &&
|
|
82
|
+
!(0, viem_1.isAddressEqual)(offer.receiverIfMakerIsSeller, offer.maker)) {
|
|
83
|
+
throw new index_js_1.MidnightOfferSellerReceiverMismatchError({
|
|
84
|
+
index,
|
|
85
|
+
expectedReceiver: offer.maker,
|
|
86
|
+
actualReceiver: offer.receiverIfMakerIsSeller,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const market = "params" in offer.market ? offer.market.params : offer.market;
|
|
90
|
+
if (market.chainId !== BigInt(chainId)) {
|
|
91
|
+
throw new index_js_1.MidnightOfferMarketChainMismatchError({
|
|
92
|
+
index,
|
|
93
|
+
expectedChainId: chainId,
|
|
94
|
+
actualChainId: market.chainId,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (!(0, viem_1.isAddressEqual)(market.midnight, midnight)) {
|
|
98
|
+
throw new index_js_1.MidnightOfferMarketAddressMismatchError({
|
|
99
|
+
index,
|
|
100
|
+
expectedMidnight: midnight,
|
|
101
|
+
actualMidnight: market.midnight,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const ratifierType = tree.type;
|
|
106
|
+
const ratifier = (0, morpho_ts_1.getChainAddress)(chainId, ratifierType === "priceV1" ? "priceRatifierV1" : "rateRatifierV1");
|
|
107
|
+
tree.offers.forEach((offer, index) => {
|
|
108
|
+
if (!(0, viem_1.isAddressEqual)(offer.ratifier, ratifier)) {
|
|
109
|
+
throw new index_js_1.MidnightOfferRatifierMismatchError({
|
|
110
|
+
index,
|
|
111
|
+
expectedRatifier: ratifier,
|
|
112
|
+
actualRatifier: offer.ratifier,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
tree,
|
|
118
|
+
accountAddress: params.accountAddress,
|
|
119
|
+
ratifier,
|
|
120
|
+
ratifierType,
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
exports.parseMidnightMakerBinding = parseMidnightMakerBinding;
|
|
124
|
+
/** Parses maker funding relationships without checking chain state or changing their timing. @internal */
|
|
125
|
+
const parseMidnightMakerFundingBinding = (params) => {
|
|
126
|
+
params.tree.offers.forEach((offer, index) => {
|
|
127
|
+
const market = "params" in offer.market ? offer.market.params : offer.market;
|
|
128
|
+
if (!(0, viem_1.isAddressEqual)(market.loanToken, params.loanToken)) {
|
|
129
|
+
throw new index_js_1.MidnightOfferMarketLoanTokenMismatchError({
|
|
130
|
+
index,
|
|
131
|
+
expectedLoanToken: params.loanToken,
|
|
132
|
+
actualLoanToken: market.loanToken,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (params.callback != null) {
|
|
136
|
+
if (!(0, viem_1.isAddressEqual)(offer.callback, params.callback.address)) {
|
|
137
|
+
throw new index_js_1.MidnightOfferCallbackMismatchError({
|
|
138
|
+
index,
|
|
139
|
+
expectedCallback: params.callback.address,
|
|
140
|
+
actualCallback: offer.callback,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (offer.callbackData.toLowerCase() !== params.callback.data.toLowerCase()) {
|
|
144
|
+
throw new index_js_1.MidnightOfferCallbackDataMismatchError({
|
|
145
|
+
index,
|
|
146
|
+
expectedCallbackData: params.callback.data,
|
|
147
|
+
actualCallbackData: offer.callbackData,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return { loanToken: params.loanToken };
|
|
153
|
+
};
|
|
154
|
+
exports.parseMidnightMakerFundingBinding = parseMidnightMakerFundingBinding;
|
|
@@ -20,7 +20,7 @@ export interface PreviewVaultV2ForceWithdrawParams {
|
|
|
20
20
|
* without `userAddress`.
|
|
21
21
|
*/
|
|
22
22
|
readonly feeProjectionTimestamp?: bigint;
|
|
23
|
-
/** Optional WAD-scaled referral fee percentage. Defaults to `0n`. */
|
|
23
|
+
/** Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`. */
|
|
24
24
|
readonly referralFeePct?: bigint;
|
|
25
25
|
/** Optional referral fee recipient. Required when `referralFeePct` is positive, as the entity
|
|
26
26
|
* enforces (`ReferralFeeRecipientMissingError`). When it equals `userAddress`, the fee is paid
|
|
@@ -78,7 +78,7 @@ export interface VaultV2ForceWithdrawPreview {
|
|
|
78
78
|
* `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
|
|
79
79
|
* more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
|
|
80
80
|
* keep the deadline itself within that horizon. Ignored without `userAddress`.
|
|
81
|
-
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
|
|
81
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`.
|
|
82
82
|
* @param params.referralFeeRecipient - Optional referral fee recipient. Required when
|
|
83
83
|
* `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
|
|
84
84
|
* When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
|
|
@@ -86,7 +86,7 @@ export interface VaultV2ForceWithdrawPreview {
|
|
|
86
86
|
* @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
|
|
87
87
|
* `adapter` override that is not the vault's sole adapter, an adapter that is not a
|
|
88
88
|
* MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
|
|
89
|
-
* `referralFeePct` outside `[0, WAD
|
|
89
|
+
* `referralFeePct` outside `[0, WAD / 10n]`, a positive `referralFeePct` without a non-zero
|
|
90
90
|
* `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
|
|
91
91
|
* whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
|
|
92
92
|
* exit whose realized share price rounds down to zero at the default slippage tolerance (which
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.previewVaultV2ForceWithdraw = previewVaultV2ForceWithdraw;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
|
+
const constant_js_1 = require("./constant.js");
|
|
6
7
|
const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
7
8
|
/**
|
|
8
9
|
* Previews what a Vault V2 force withdrawal delivers, without any RPC.
|
|
@@ -27,7 +28,7 @@ const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
|
27
28
|
* `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
|
|
28
29
|
* more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
|
|
29
30
|
* keep the deadline itself within that horizon. Ignored without `userAddress`.
|
|
30
|
-
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
|
|
31
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`.
|
|
31
32
|
* @param params.referralFeeRecipient - Optional referral fee recipient. Required when
|
|
32
33
|
* `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
|
|
33
34
|
* When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
|
|
@@ -35,7 +36,7 @@ const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
|
35
36
|
* @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
|
|
36
37
|
* `adapter` override that is not the vault's sole adapter, an adapter that is not a
|
|
37
38
|
* MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
|
|
38
|
-
* `referralFeePct` outside `[0, WAD
|
|
39
|
+
* `referralFeePct` outside `[0, WAD / 10n]`, a positive `referralFeePct` without a non-zero
|
|
39
40
|
* `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
|
|
40
41
|
* whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
|
|
41
42
|
* exit whose realized share price rounds down to zero at the default slippage tolerance (which
|
|
@@ -62,9 +63,7 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
62
63
|
if (requestedExitAssets <= 0n) {
|
|
63
64
|
return undefined;
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
// deliver — above `withdrawnAssets` for a negative fee, non-positive at or beyond WAD.
|
|
67
|
-
if (referralFeePct < 0n || referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
66
|
+
if (referralFeePct < 0n || referralFeePct > constant_js_1.MIDNIGHT_MAX_REFERRAL_FEE_PCT) {
|
|
68
67
|
return undefined;
|
|
69
68
|
}
|
|
70
69
|
if (referralFeePct > 0n &&
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
2
2
|
/** @internal Quotes repayment funding without projecting a position for health checks. */
|
|
3
3
|
export declare function quoteBlueRepayFunding(params: Parameters<typeof quoteBlueRepay>[0]): bigint;
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @internal Quotes repayment funding at the deadline independently of an optional withdrawal-health timestamp.
|
|
6
|
+
* Debt-free positions retain their snapshot without projecting market-wide interest.
|
|
7
|
+
*/
|
|
8
|
+
export declare function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, healthTimestamp, }: {
|
|
6
9
|
readonly positionData: AccrualPosition;
|
|
7
10
|
readonly marketId: MarketId;
|
|
8
11
|
readonly repayAssets: bigint;
|
|
9
12
|
readonly repayShares: bigint;
|
|
10
13
|
readonly deadline: bigint;
|
|
11
14
|
readonly now: bigint;
|
|
15
|
+
readonly healthTimestamp?: bigint;
|
|
12
16
|
}): {
|
|
13
17
|
simulatedRepayShares: bigint;
|
|
14
18
|
accruedPosition: AccrualPosition;
|
|
@@ -17,8 +17,11 @@ function quoteBlueRepayFunding(params) {
|
|
|
17
17
|
}
|
|
18
18
|
return params.repayAssets;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* @internal Quotes repayment funding at the deadline independently of an optional withdrawal-health timestamp.
|
|
22
|
+
* Debt-free positions retain their snapshot without projecting market-wide interest.
|
|
23
|
+
*/
|
|
24
|
+
function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, healthTimestamp, }) {
|
|
22
25
|
const saturatedRepay = repayShares === viem_1.maxUint256;
|
|
23
26
|
const simulatedRepayShares = saturatedRepay
|
|
24
27
|
? positionData.borrowShares
|
|
@@ -37,10 +40,20 @@ function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, dead
|
|
|
37
40
|
max: quoteHorizon,
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
|
-
const accrualTimestamp = repayShares > 0n ? deadline : quoteHorizon;
|
|
41
|
-
const accruedPosition = positionData.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const accrualTimestamp = healthTimestamp ?? (repayShares > 0n ? deadline : quoteHorizon);
|
|
44
|
+
const accruedPosition = positionData.borrowShares === 0n
|
|
45
|
+
? new blue_sdk_1.AccrualPosition(positionData, positionData.market)
|
|
46
|
+
: positionData.accrueInterest(accrualTimestamp);
|
|
47
|
+
if (repayAssets > 0n || simulatedRepayShares <= 0n) {
|
|
48
|
+
return {
|
|
49
|
+
simulatedRepayShares,
|
|
50
|
+
accruedPosition,
|
|
51
|
+
expectedRepayAssets: repayAssets,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const fundingPosition = accrualTimestamp === deadline
|
|
55
|
+
? accruedPosition
|
|
56
|
+
: positionData.accrueInterest(deadline);
|
|
57
|
+
const expectedRepayAssets = fundingPosition.market.toBorrowAssets(simulatedRepayShares, "Up");
|
|
45
58
|
return { simulatedRepayShares, accruedPosition, expectedRepayAssets };
|
|
46
59
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves an omitted reallocation penalty bound and validates its runtime type and range.
|
|
3
|
+
* @param value - Optional WAD-scaled penalty bound.
|
|
4
|
+
* @returns A bigint in [0, WAD], defaulting only undefined to zero.
|
|
5
|
+
* @throws {InvalidBigIntInputError} when a supplied bound is not a bigint.
|
|
6
|
+
* @throws {NegativeInputError} when the bound is negative.
|
|
7
|
+
* @throws {InputExceedsMaxError} when the bound exceeds WAD.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const resolveMaxPenalty: (value: unknown) => bigint;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveMaxPenalty = void 0;
|
|
4
|
+
const error_js_1 = require("../types/error.js");
|
|
5
|
+
const constant_js_1 = require("./constant.js");
|
|
6
|
+
/**
|
|
7
|
+
* Resolves an omitted reallocation penalty bound and validates its runtime type and range.
|
|
8
|
+
* @param value - Optional WAD-scaled penalty bound.
|
|
9
|
+
* @returns A bigint in [0, WAD], defaulting only undefined to zero.
|
|
10
|
+
* @throws {InvalidBigIntInputError} when a supplied bound is not a bigint.
|
|
11
|
+
* @throws {NegativeInputError} when the bound is negative.
|
|
12
|
+
* @throws {InputExceedsMaxError} when the bound exceeds WAD.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
const resolveMaxPenalty = (value) => {
|
|
16
|
+
const penalty = value === undefined ? constant_js_1.DEFAULT_MAX_REALLOCATION_PENALTY : value;
|
|
17
|
+
if (typeof penalty !== "bigint") {
|
|
18
|
+
throw new error_js_1.InvalidBigIntInputError("maxPenalty", penalty);
|
|
19
|
+
}
|
|
20
|
+
if (penalty < 0n) {
|
|
21
|
+
throw new error_js_1.NegativeInputError("maxPenalty", penalty);
|
|
22
|
+
}
|
|
23
|
+
if (penalty > constant_js_1.MAX_REALLOCATION_PENALTY) {
|
|
24
|
+
throw new error_js_1.InputExceedsMaxError({
|
|
25
|
+
field: "maxPenalty",
|
|
26
|
+
value: penalty,
|
|
27
|
+
max: constant_js_1.MAX_REALLOCATION_PENALTY,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return penalty;
|
|
31
|
+
};
|
|
32
|
+
exports.resolveMaxPenalty = resolveMaxPenalty;
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param params - Net target and WAD-scaled referral fee.
|
|
5
5
|
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
6
|
-
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`);
|
|
6
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); at most 10%.
|
|
7
7
|
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
8
8
|
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
9
9
|
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
10
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
10
11
|
* @example
|
|
11
12
|
* ```ts
|
|
12
13
|
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
@@ -3,15 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.grossFromNetAssets = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const index_js_1 = require("../types/index.js");
|
|
6
|
+
const validateMidnightBounds_js_1 = require("./validateMidnightBounds.js");
|
|
6
7
|
/**
|
|
7
8
|
* Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
|
|
8
9
|
*
|
|
9
10
|
* @param params - Net target and WAD-scaled referral fee.
|
|
10
11
|
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
11
|
-
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`);
|
|
12
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); at most 10%.
|
|
12
13
|
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
13
14
|
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
14
15
|
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
16
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
15
17
|
* @example
|
|
16
18
|
* ```ts
|
|
17
19
|
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
@@ -30,6 +32,8 @@ const grossFromNetAssets = (params) => {
|
|
|
30
32
|
if (params.referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
31
33
|
throw new index_js_1.ReferralFeePctExceededError(params.referralFeePct);
|
|
32
34
|
}
|
|
35
|
+
// Reject fees that the SDK's bundle builders would reject.
|
|
36
|
+
(0, validateMidnightBounds_js_1.validateMidnightReferralFeeCap)(params.referralFeePct);
|
|
33
37
|
return blue_sdk_1.MathLib.mulDivDown(params.netAssets, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD - params.referralFeePct);
|
|
34
38
|
};
|
|
35
39
|
exports.grossFromNetAssets = grossFromNetAssets;
|
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
import { type AccrualPosition, type MarketId, type MarketParams } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { type AccrualPosition, type InputMarketParams, type MarketId, type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Market as MidnightMarket, type MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import { type VaultV2BlueReallocation } from "../types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Rejects a reference time that is not a bigint, so a serialized timestamp fails with a typed
|
|
7
|
+
* error before any deadline arithmetic.
|
|
8
|
+
* @param now - Handle creation or plan preparation timestamp in Unix seconds.
|
|
9
|
+
* @returns Nothing when `now` is a bigint.
|
|
10
|
+
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateReferenceTime(now: bigint): void;
|
|
14
|
+
/**
|
|
15
|
+
* Rejects vault deposit accrual beyond seven days after the reference time.
|
|
16
|
+
* @param deadline - Execution deadline in Unix seconds.
|
|
17
|
+
* @param params - Reference time and public input field for validation errors.
|
|
18
|
+
* @param params.now - Handle creation or plan preparation timestamp in Unix seconds.
|
|
19
|
+
* @param params.field - Public input field to identify in validation errors.
|
|
20
|
+
* @returns Nothing when the deadline is within the maximum window.
|
|
21
|
+
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
22
|
+
* @throws {InputExceedsMaxError} when the deadline exceeds the seven-day window.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateVaultDepositDeadline(deadline: bigint, { now, field, }: {
|
|
26
|
+
now: bigint;
|
|
27
|
+
field?: "deadline" | "expiresAt";
|
|
28
|
+
}): void;
|
|
5
29
|
/**
|
|
6
30
|
* Rejects a `bigint` field that falls outside the unsigned 256-bit ABI range so a direct caller
|
|
7
31
|
* gets the SDK's typed error instead of viem's `IntegerOutOfRangeError` at encode time. `maxUint256`
|
|
@@ -24,7 +48,7 @@ export declare const validateUint256Field: (field: string, value: bigint) => voi
|
|
|
24
48
|
* @throws {MarketIdMismatchError} when `marketParams.id` differs from the derived id.
|
|
25
49
|
* @internal
|
|
26
50
|
*/
|
|
27
|
-
export declare const validateMarketParamsId: (marketParams: MarketParams) => void;
|
|
51
|
+
export declare const validateMarketParamsId: (marketParams: InputMarketParams & Pick<MarketParams, "id">) => void;
|
|
28
52
|
/**
|
|
29
53
|
* Rejects a deadline that no periphery can honour: the contracts read `0` as "unset" and the ABI
|
|
30
54
|
* slot is a `uint256`. Callers that also need the deadline to be in the future layer their own
|
|
@@ -39,11 +63,10 @@ export declare const validateMarketParamsId: (marketParams: MarketParams) => voi
|
|
|
39
63
|
export declare const validateDeadline: (deadline: bigint) => void;
|
|
40
64
|
/**
|
|
41
65
|
* Validates an optional referral fee and returns the pair every referral-fee-bearing periphery
|
|
42
|
-
* encodes.
|
|
43
|
-
* whose contracts apply the same `[0, WAD)` bound and both transfer the fee unconditionally.
|
|
66
|
+
* encodes. The SDK caps the fee at 10% even though the peripheries accept fees below WAD.
|
|
44
67
|
*
|
|
45
68
|
* @param params - Referral fee inputs.
|
|
46
|
-
* @param params.referralFeePct - Optional WAD-scaled fee share
|
|
69
|
+
* @param params.referralFeePct - Optional WAD-scaled fee share, at most 10%. Defaults to `0n`.
|
|
47
70
|
* @param params.referralFeeRecipient - Optional fee recipient. Defaults to the zero address, which
|
|
48
71
|
* is only valid alongside a zero `referralFeePct`.
|
|
49
72
|
* @returns The normalized `{ referralFeePct, referralFeeRecipient }` pair.
|
|
@@ -51,6 +74,7 @@ export declare const validateDeadline: (deadline: bigint) => void;
|
|
|
51
74
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD (the contracts reject
|
|
52
75
|
* it with `PctExceeded`); it extends `InputExceedsMaxError`, preserving that pattern-match.
|
|
53
76
|
* @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
|
|
77
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
54
78
|
* @internal
|
|
55
79
|
*/
|
|
56
80
|
export declare const validateReferralFee: (params: {
|
|
@@ -292,6 +316,7 @@ export declare const validateNativeAsset: (chainId: number, asset: Address) => v
|
|
|
292
316
|
* for the full pulled amount.
|
|
293
317
|
* @param params.pulls - Token pulls performed by the bundle action.
|
|
294
318
|
* @returns The transaction `value` and the `wrappedNative` contract argument.
|
|
319
|
+
* @throws {InvalidMidnightNativeAmountTypeError} when `nativeAmount` is supplied as a non-bigint.
|
|
295
320
|
* @throws {NegativeInputError} when `nativeAmount` is negative.
|
|
296
321
|
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
297
322
|
* @throws {MidnightCalldataEncodingError} when a pulled `token` is not a 20-byte hex address.
|
|
@@ -425,7 +450,10 @@ export declare const validateRepayShares: (params: {
|
|
|
425
450
|
marketId: MarketId;
|
|
426
451
|
}) => void;
|
|
427
452
|
/** @internal */
|
|
428
|
-
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, targetMarketId
|
|
453
|
+
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, { targetMarketId, maxPenalty, }: {
|
|
454
|
+
readonly targetMarketId: MarketId;
|
|
455
|
+
readonly maxPenalty?: bigint;
|
|
456
|
+
}) => void;
|
|
429
457
|
/**
|
|
430
458
|
* Validates that a slippage tolerance is within an acceptable range.
|
|
431
459
|
*
|