@morpho-org/morpho-sdk 9.6.0-next.0 → 9.7.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/MIGRATION-v6-to-v7.md +1 -1
- package/README.md +123 -3
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.js +39 -32
- package/lib/cjs/actions/midnight/cancelAndMake.js +20 -98
- package/lib/cjs/actions/midnight/index.d.ts +2 -0
- package/lib/cjs/actions/midnight/index.js +2 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +5 -6
- package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +39 -0
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +91 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +31 -32
- package/lib/cjs/actions/midnight/takeBorrow.js +24 -23
- package/lib/cjs/actions/midnight/takeLend.js +24 -23
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
- package/lib/cjs/actions/midnight/takeWithdraw.js +24 -23
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +104 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +7 -7
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +1 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/entities/index.d.ts +5 -5
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +77 -3
- package/lib/cjs/entities/midnight/midnight.js +174 -0
- package/lib/cjs/entities/midnight/types.d.ts +16 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +12 -46
- package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -0
- package/lib/cjs/entities/requirements/getErc2612Permit.js +60 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +3 -3
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +10 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -33
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +6 -7
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/deadShares.js +0 -2
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +1 -0
- package/lib/cjs/helpers/signAndVerifyTypedData.js +12 -5
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +129 -0
- package/lib/cjs/helpers/validateMidnightCollateralBatch.d.ts +15 -0
- package/lib/cjs/helpers/validateMidnightCollateralBatch.js +28 -0
- package/lib/cjs/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
- package/lib/cjs/helpers/validateMidnightCollateralSupplies.js +28 -0
- package/lib/cjs/helpers/validatePositiveInput.d.ts +10 -0
- package/lib/cjs/helpers/validatePositiveInput.js +18 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +18 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +5 -5
- package/lib/cjs/transactionPlan/approval.d.ts +2 -0
- package/lib/cjs/transactionPlan/approval.js +16 -0
- package/lib/cjs/transactionPlan/error.d.ts +145 -0
- package/lib/cjs/transactionPlan/error.js +186 -0
- package/lib/cjs/transactionPlan/getTokenPermit.d.ts +11 -0
- package/lib/cjs/transactionPlan/getTokenPermit.js +18 -0
- package/lib/cjs/transactionPlan/index.d.ts +9 -0
- package/lib/cjs/transactionPlan/index.js +24 -0
- package/lib/cjs/transactionPlan/intent.d.ts +51 -0
- package/lib/cjs/transactionPlan/intent.js +54 -0
- package/lib/cjs/transactionPlan/permit.d.ts +13 -0
- package/lib/cjs/transactionPlan/permit.js +145 -0
- package/lib/cjs/transactionPlan/plan.d.ts +99 -0
- package/lib/cjs/transactionPlan/plan.js +232 -0
- package/lib/cjs/transactionPlan/requirements.d.ts +44 -0
- package/lib/cjs/transactionPlan/requirements.js +79 -0
- package/lib/cjs/transactionPlan/serde.d.ts +33 -0
- package/lib/cjs/transactionPlan/serde.js +205 -0
- package/lib/cjs/transactionPlan/types.d.ts +91 -0
- package/lib/cjs/transactionPlan/types.js +2 -0
- package/lib/cjs/transactionPlan/validateActions.d.ts +8 -0
- package/lib/cjs/transactionPlan/validateActions.js +19 -0
- package/lib/cjs/transactionPlan/validation.d.ts +17 -0
- package/lib/cjs/transactionPlan/validation.js +70 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +81 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +211 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +77 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +190 -0
- package/lib/cjs/transactionPlan/version.d.ts +2 -0
- package/lib/cjs/transactionPlan/version.js +9 -0
- package/lib/cjs/types/action.d.ts +18 -3
- package/lib/cjs/types/error.d.ts +23 -2
- package/lib/cjs/types/error.js +45 -5
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.js +39 -32
- package/lib/esm/actions/midnight/cancelAndMake.js +25 -103
- package/lib/esm/actions/midnight/index.d.ts +2 -0
- package/lib/esm/actions/midnight/index.js +2 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +5 -6
- package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +39 -0
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +87 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -34
- package/lib/esm/actions/midnight/takeBorrow.js +25 -24
- package/lib/esm/actions/midnight/takeLend.js +25 -24
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
- package/lib/esm/actions/midnight/takeWithdraw.js +25 -24
- package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +100 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +8 -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/entities/index.d.ts +5 -5
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +77 -3
- package/lib/esm/entities/midnight/midnight.js +176 -2
- package/lib/esm/entities/midnight/types.d.ts +16 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +14 -48
- package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -0
- package/lib/esm/entities/requirements/getErc2612Permit.js +57 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +3 -3
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +10 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -33
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +1 -3
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +1 -0
- package/lib/esm/helpers/signAndVerifyTypedData.js +13 -6
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +124 -0
- package/lib/esm/helpers/validateMidnightCollateralBatch.d.ts +15 -0
- package/lib/esm/helpers/validateMidnightCollateralBatch.js +25 -0
- package/lib/esm/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
- package/lib/esm/helpers/validateMidnightCollateralSupplies.js +24 -0
- package/lib/esm/helpers/validatePositiveInput.d.ts +10 -0
- package/lib/esm/helpers/validatePositiveInput.js +14 -0
- package/lib/esm/index.d.ts +2 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/transactionPlan/approval.d.ts +2 -0
- package/lib/esm/transactionPlan/approval.js +13 -0
- package/lib/esm/transactionPlan/error.d.ts +145 -0
- package/lib/esm/transactionPlan/error.js +175 -0
- package/lib/esm/transactionPlan/getTokenPermit.d.ts +11 -0
- package/lib/esm/transactionPlan/getTokenPermit.js +15 -0
- package/lib/esm/transactionPlan/index.d.ts +9 -0
- package/lib/esm/transactionPlan/index.js +5 -0
- package/lib/esm/transactionPlan/intent.d.ts +51 -0
- package/lib/esm/transactionPlan/intent.js +51 -0
- package/lib/esm/transactionPlan/permit.d.ts +13 -0
- package/lib/esm/transactionPlan/permit.js +140 -0
- package/lib/esm/transactionPlan/plan.d.ts +99 -0
- package/lib/esm/transactionPlan/plan.js +226 -0
- package/lib/esm/transactionPlan/requirements.d.ts +44 -0
- package/lib/esm/transactionPlan/requirements.js +74 -0
- package/lib/esm/transactionPlan/serde.d.ts +33 -0
- package/lib/esm/transactionPlan/serde.js +201 -0
- package/lib/esm/transactionPlan/types.d.ts +91 -0
- package/lib/esm/transactionPlan/types.js +1 -0
- package/lib/esm/transactionPlan/validateActions.d.ts +8 -0
- package/lib/esm/transactionPlan/validateActions.js +16 -0
- package/lib/esm/transactionPlan/validation.d.ts +17 -0
- package/lib/esm/transactionPlan/validation.js +64 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +81 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.js +206 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +77 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +185 -0
- package/lib/esm/transactionPlan/version.d.ts +2 -0
- package/lib/esm/transactionPlan/version.js +6 -0
- package/lib/esm/types/action.d.ts +18 -3
- package/lib/esm/types/error.d.ts +23 -2
- package/lib/esm/types/error.js +40 -3
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +8 -7
package/lib/cjs/types/error.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DepositOwnerMismatchError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.UnsupportedMidnightAuthorizationTargetError = exports.UnsupportedErc20ApprovalSpenderError = exports.MissingClientPropertyError = exports.CryptoUnavailableError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.UnsupportedRequirementSignatureError = exports.UnexpectedRequirementSignatureError = exports.AmbiguousRequirementSignaturesError = exports.MaxRepayAssetsBelowRepayAssetsError = exports.ReallocationsRequireBorrowError = exports.UnsupportedAuthorizationOperatorError = exports.ReallocationLoanTokenMismatchError = exports.SameVaultMigrationError = exports.AmountAndSharesExclusiveError = exports.MixedBundlesFundingError = exports.MidnightReferralFeePctExceededError = exports.ReferralFeePctExceededError = exports.ReferralFeeRecipientMissingError = exports.NativeFundingAmountMismatchError = exports.NoUnusedPermit2NonceError = exports.Permit2SignatureTransferNonceAlreadyUsedError = exports.BundlesRequirementSignatureMismatchError = exports.BundlesPermitMismatchError = exports.VaultIsBlueFeeRecipientError = exports.VaultMorphoMismatchError = exports.InsufficientBlueBalanceForInKindRedeemError = exports.InKindRedeemCoverageError = exports.InKindRedeemZeroDeallocationError = exports.VaultV2ForceWithdrawFeeSharesExceedBurnError = exports.VaultV2ForceWithdrawSharePriceBelowFloorError = exports.VaultV2ForceWithdrawZeroSharePriceError = exports.VaultV2ForceWithdrawZeroWithdrawalError = exports.VaultV2ForceWithdrawCoverageError = exports.VaultV2UndecodableLiquidityDataError = exports.VaultV2UnsupportedLiquidityAdapterError = exports.VaultV2UnsupportedExitAdapterError = exports.AdapterNotPartOfVaultError = exports.VaultV2SingleAdapterRequiredError = exports.ExpiredDeadlineError = exports.EmptyMarketParamsListError = exports.InputExceedsMaxError = exports.NonPositiveInputError = exports.NegativeInputError = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.MidnightCalldataEncodingError = exports.MidnightZeroAccountError = exports.MissingContractCodeError = exports.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.BlueBuyCallbackUnauthorizedError = exports.BlueBuyCallbackOwnerMismatchError = exports.NotBlueBuyCallbackError = exports.InsufficientBlueLiquidityError = exports.EmptyBlueSupplyPositionError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.MidnightInvalidAccountAddressError = exports.InvalidMidnightHexInputError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferZeroSellerReceiverError = exports.MidnightTakeableOfferMarketMismatchError = exports.MissingDeadSharesDataError = exports.InsufficientDeadSharesError = exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = void 0;
|
|
4
|
+
exports.MidnightContractReceiverError = exports.MidnightZeroOnBehalfError = exports.MidnightZeroReceiverError = exports.MidnightRepayExceedsDebtError = exports.MidnightContinuousFeeAboveMaxError = exports.MidnightTakeTargetUnreachableError = exports.MidnightTakeableOffersNotFillableError = exports.UnboundedMidnightTakeInputError = exports.MidnightOfferSellerReceiverMismatchError = exports.MidnightOfferContinuousFeeCapError = exports.MidnightOfferMakerMismatchError = exports.MidnightOfferReduceOnlyError = exports.MidnightOfferSideMismatchError = exports.EmptyMidnightTakeableOffersError = exports.DuplicateMidnightGroupCancellationError = exports.DuplicateMidnightCollateralIndexError = exports.EmptyMidnightCollateralWithdrawalsError = exports.EmptyMidnightCollateralSuppliesError = exports.EmptyMidnightGroupCancellationsError = exports.ReallocationAdapterSupplySharesUnderflowError = exports.ReallocationAllocationUnderflowError = exports.UnknownReallocationAdapterError = exports.UnknownReallocationMarketPublicAllocatorConfigError = exports.UnknownReallocationActiveAdaptersError = exports.UnknownReallocationPublicAllocatorConfigError = exports.UnknownReallocationAllocationError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.RepaySharesExceedDebtError = exports.MalformedSignatureError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.MutuallyExclusiveRepayAmountsError = exports.InconsistentReallocationPenaltyError = exports.InvalidReallocationSourceTypeError = exports.InvalidReallocationAddressError = exports.InvalidVaultV2BlueReallocationShapeError = exports.ReallocationWithdrawalOnTargetMarketError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeAssetError = exports.VaultAddressMismatchError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DepositSpenderMismatchError = void 0;
|
|
5
|
+
exports.MidnightCalldataEncodingError = exports.MidnightZeroAccountError = exports.MissingContractCodeError = exports.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.BlueBuyCallbackUnauthorizedError = exports.BlueBuyCallbackOwnerMismatchError = exports.NotBlueBuyCallbackError = exports.InsufficientBlueLiquidityError = exports.EmptyBlueSupplyPositionError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.MidnightInvalidAccountAddressError = exports.InvalidMidnightHexInputError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferZeroSellerReceiverError = exports.MidnightTakeableOfferMarketMismatchError = exports.MissingDeadSharesDataError = exports.InsufficientDeadSharesError = exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = exports.MidnightOfferMarketAddressMismatchError = exports.MidnightOfferMarketChainMismatchError = exports.MidnightTakeDeadlineTooFarError = void 0;
|
|
6
6
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
7
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
8
8
|
const constant_js_1 = require("../helpers/constant.js");
|
|
@@ -1208,14 +1208,38 @@ class RepayExceedsDebtError extends Error {
|
|
|
1208
1208
|
}
|
|
1209
1209
|
}
|
|
1210
1210
|
exports.RepayExceedsDebtError = RepayExceedsDebtError;
|
|
1211
|
-
/** Thrown when EIP-712 signature verification fails
|
|
1211
|
+
/** Thrown when EIP-712 signature verification fails to recover the expected signer. */
|
|
1212
1212
|
class InvalidSignatureError extends Error {
|
|
1213
|
-
constructor() {
|
|
1214
|
-
super("Signature verification failed: the signed data does not match the expected signer address");
|
|
1213
|
+
constructor(options) {
|
|
1214
|
+
super("Signature verification failed: the signed data does not match the expected signer address", options);
|
|
1215
1215
|
this.name = "InvalidSignatureError";
|
|
1216
1216
|
}
|
|
1217
1217
|
}
|
|
1218
1218
|
exports.InvalidSignatureError = InvalidSignatureError;
|
|
1219
|
+
/** Thrown when signature recovery fails, with redacted diagnostics and the original error as `cause`. */
|
|
1220
|
+
class MalformedSignatureError extends InvalidSignatureError {
|
|
1221
|
+
/** JavaScript type returned by the wallet, without the signature value. */
|
|
1222
|
+
signatureType;
|
|
1223
|
+
/** Whether the returned value is an even-length hex string. */
|
|
1224
|
+
signatureIsHex;
|
|
1225
|
+
/** Signature byte length, when it is an even-length hex string. */
|
|
1226
|
+
signatureByteLength;
|
|
1227
|
+
constructor(params) {
|
|
1228
|
+
super({ cause: params.cause });
|
|
1229
|
+
this.name = "MalformedSignatureError";
|
|
1230
|
+
this.message =
|
|
1231
|
+
"Signature verification failed: the wallet returned a malformed signature. Check the wallet signing transport and sign the typed data again.";
|
|
1232
|
+
this.signatureType = typeof params.signature;
|
|
1233
|
+
this.signatureIsHex =
|
|
1234
|
+
typeof params.signature === "string" &&
|
|
1235
|
+
/^0x(?:[0-9a-fA-F]{2})*$/.test(params.signature);
|
|
1236
|
+
this.signatureByteLength =
|
|
1237
|
+
this.signatureIsHex && typeof params.signature === "string"
|
|
1238
|
+
? (params.signature.length - 2) / 2
|
|
1239
|
+
: undefined;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
exports.MalformedSignatureError = MalformedSignatureError;
|
|
1219
1243
|
/** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
|
|
1220
1244
|
class RepaySharesExceedDebtError extends Error {
|
|
1221
1245
|
constructor(params) {
|
|
@@ -1377,6 +1401,22 @@ class EmptyMidnightCollateralSuppliesError extends Error {
|
|
|
1377
1401
|
}
|
|
1378
1402
|
}
|
|
1379
1403
|
exports.EmptyMidnightCollateralSuppliesError = EmptyMidnightCollateralSuppliesError;
|
|
1404
|
+
/** Thrown when a direct Midnight collateral withdrawal batch is empty. */
|
|
1405
|
+
class EmptyMidnightCollateralWithdrawalsError extends Error {
|
|
1406
|
+
constructor() {
|
|
1407
|
+
super("Midnight collateral withdrawals cannot be empty. Pass at least one collateral withdrawal.");
|
|
1408
|
+
this.name = "EmptyMidnightCollateralWithdrawalsError";
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
exports.EmptyMidnightCollateralWithdrawalsError = EmptyMidnightCollateralWithdrawalsError;
|
|
1412
|
+
/** Thrown when a direct Midnight collateral batch repeats an index. */
|
|
1413
|
+
class DuplicateMidnightCollateralIndexError extends Error {
|
|
1414
|
+
constructor(collateralIndex) {
|
|
1415
|
+
super(`Midnight collateral batch repeats index "${collateralIndex}". Pass each collateral index once.`);
|
|
1416
|
+
this.name = "DuplicateMidnightCollateralIndexError";
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
exports.DuplicateMidnightCollateralIndexError = DuplicateMidnightCollateralIndexError;
|
|
1380
1420
|
/** Thrown when a Midnight batch cancellation lists the same offer group twice. */
|
|
1381
1421
|
class DuplicateMidnightGroupCancellationError extends Error {
|
|
1382
1422
|
constructor(params) {
|
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
|
-
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils,
|
|
6
|
+
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
7
7
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
8
8
|
export { EcrecoverRatifier as MidnightEcrecoverRatifier,
|
|
9
9
|
/** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
|
|
@@ -17,7 +17,7 @@ RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier
|
|
|
17
17
|
/** @deprecated Use MidnightSetterRatifier with a tagged tree. */
|
|
18
18
|
SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
|
|
19
19
|
export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
|
|
20
|
-
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys,
|
|
20
|
+
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|
|
21
21
|
export { validateClientChainId } from "./actions/requirements/validateClientChainId.js";
|
|
22
22
|
export { addTransactionMetadata } from "./helpers/metadata.js";
|
|
23
23
|
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./helpers/previewVaultV2ForceWithdraw.js";
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightSetterRatifier = exports.MidnightRatifierUtils = exports.MidnightRatifier = exports.MidnightRateRatifierV1Utils = exports.MidnightRateRatifierV1 = exports.MidnightPriceRatifierV1Utils = exports.MidnightPriceRatifierV1 = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.MidnightEcrecoverRatifier = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.isUndecodableResultError = exports.isTransportError = exports.isContractRevertError = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.catchRevertOnly = exports.VaultV2Utils = exports.
|
|
4
|
-
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateClientChainId = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.
|
|
3
|
+
exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightSetterRatifier = exports.MidnightRatifierUtils = exports.MidnightRatifier = exports.MidnightRateRatifierV1Utils = exports.MidnightRateRatifierV1 = exports.MidnightPriceRatifierV1Utils = exports.MidnightPriceRatifierV1 = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.MidnightEcrecoverRatifier = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.isUndecodableResultError = exports.isTransportError = exports.isContractRevertError = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.catchRevertOnly = exports.VaultV2Utils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.BlueSharesMath = exports.MathLib = exports.BlueMarketUtils = exports.getBlueDefaultPreLiquidationParams = exports.blueDefaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.BlueAdaptiveCurveIrmLib = void 0;
|
|
4
|
+
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateClientChainId = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = void 0;
|
|
5
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
Object.defineProperty(exports, "BlueAdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
|
|
7
7
|
Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "BlueSharesMath", { enumerable: true, get: functi
|
|
|
15
15
|
Object.defineProperty(exports, "VaultUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultUtils; } });
|
|
16
16
|
Object.defineProperty(exports, "VaultV2BlueMarketPublicAllocatorConfigUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BlueMarketPublicAllocatorConfigUtils; } });
|
|
17
17
|
Object.defineProperty(exports, "VaultV2BluePublicAllocatorConfigUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils; } });
|
|
18
|
-
Object.defineProperty(exports, "VaultV2MidnightAdapterUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MidnightAdapterUtils; } });
|
|
19
18
|
Object.defineProperty(exports, "VaultV2Utils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Utils; } });
|
|
20
19
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
21
20
|
Object.defineProperty(exports, "catchRevertOnly", { enumerable: true, get: function () { return blue_sdk_viem_1.catchRevertOnly; } });
|
|
@@ -77,7 +76,6 @@ Object.defineProperty(exports, "isDefined", { enumerable: true, get: function ()
|
|
|
77
76
|
Object.defineProperty(exports, "isNotNull", { enumerable: true, get: function () { return morpho_ts_1.isNotNull; } });
|
|
78
77
|
Object.defineProperty(exports, "isNotUndefined", { enumerable: true, get: function () { return morpho_ts_1.isNotUndefined; } });
|
|
79
78
|
Object.defineProperty(exports, "keys", { enumerable: true, get: function () { return morpho_ts_1.keys; } });
|
|
80
|
-
Object.defineProperty(exports, "MidnightPositionLib", { enumerable: true, get: function () { return morpho_ts_1.MidnightPositionLib; } });
|
|
81
79
|
Object.defineProperty(exports, "mergeEntries", { enumerable: true, get: function () { return morpho_ts_1.mergeEntries; } });
|
|
82
80
|
Object.defineProperty(exports, "retryPromiseLinearBackoff", { enumerable: true, get: function () { return morpho_ts_1.retryPromiseLinearBackoff; } });
|
|
83
81
|
Object.defineProperty(exports, "Time", { enumerable: true, get: function () { return morpho_ts_1.Time; } });
|
package/lib/esm/abis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi,
|
|
2
|
+
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
package/lib/esm/abis.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi,
|
|
2
|
+
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
@@ -85,8 +85,8 @@ export const blueRepayWithdrawCollateral = (params) => {
|
|
|
85
85
|
if (repayAssets > 0n && repayShares > 0n) {
|
|
86
86
|
throw new MutuallyExclusiveRepayAmountsError(marketParams.id);
|
|
87
87
|
}
|
|
88
|
-
const hasRepay = repayAssets
|
|
89
|
-
if (
|
|
88
|
+
const hasRepay = repayAssets + repayShares > 0n;
|
|
89
|
+
if (repayAssets + repayShares + collateralAssets === 0n) {
|
|
90
90
|
throw new NonPositiveInputError("repayAssets, repayShares, or collateralAssets", 0n);
|
|
91
91
|
}
|
|
92
92
|
if (hasRepay && maxRepayAssets === 0n) {
|
|
@@ -215,6 +215,15 @@ export const normalizeBundlesSignature = (serializedSignature, onInvalid = (deta
|
|
|
215
215
|
}
|
|
216
216
|
return { v: Number(normalizedV), r: parsed.r, s: parsed.s };
|
|
217
217
|
};
|
|
218
|
+
const validateBundlesPermitValue = (params) => {
|
|
219
|
+
if (params.actual !== params.expected) {
|
|
220
|
+
throw new BundlesPermitMismatchError({
|
|
221
|
+
field: params.field,
|
|
222
|
+
expected: String(params.expected),
|
|
223
|
+
actual: String(params.actual),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
};
|
|
218
227
|
/**
|
|
219
228
|
* Converts an optional vault-share ERC-2612 requirement into the ABI-ready Permit tuple.
|
|
220
229
|
*
|
|
@@ -246,10 +255,6 @@ export const getBundlesSharesPermit = (params) => {
|
|
|
246
255
|
const { requirementSignature } = params;
|
|
247
256
|
// Require a positive uint256 for the fallback permit deadline.
|
|
248
257
|
validateDeadline(params.deadline);
|
|
249
|
-
if (requirementSignature != null) {
|
|
250
|
-
// Require a positive uint256 for the signed permit deadline too.
|
|
251
|
-
validateDeadline(requirementSignature.args.deadline);
|
|
252
|
-
}
|
|
253
258
|
if (requirementSignature == null) {
|
|
254
259
|
return {
|
|
255
260
|
value: 0n,
|
|
@@ -260,6 +265,9 @@ export const getBundlesSharesPermit = (params) => {
|
|
|
260
265
|
s: zeroHash,
|
|
261
266
|
};
|
|
262
267
|
}
|
|
268
|
+
// Require a positive uint256 for the signed permit deadline too.
|
|
269
|
+
validateDeadline(requirementSignature.args.deadline);
|
|
270
|
+
const validatesOperation = params.owner != null || params.spender != null || params.amount != null;
|
|
263
271
|
if (requirementSignature.action.type !== "permit") {
|
|
264
272
|
throw new BundlesPermitMismatchError({
|
|
265
273
|
field: "type",
|
|
@@ -299,29 +307,26 @@ export const getBundlesSharesPermit = (params) => {
|
|
|
299
307
|
actual: String(requirementSignature.args.amount),
|
|
300
308
|
});
|
|
301
309
|
}
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
310
|
+
if (validatesOperation) {
|
|
311
|
+
// Validation only; checks signed values against their operation descriptors.
|
|
312
|
+
validateBundlesPermitValue({
|
|
305
313
|
field: "amount",
|
|
306
|
-
expected:
|
|
307
|
-
actual:
|
|
314
|
+
expected: requirementSignature.args.amount,
|
|
315
|
+
actual: requirementSignature.action.args.amount,
|
|
308
316
|
});
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
requirementSignature.action.args.deadline !==
|
|
312
|
-
requirementSignature.args.deadline) {
|
|
313
|
-
throw new BundlesPermitMismatchError({
|
|
317
|
+
// Validation only; checks the signed deadline against its operation descriptor.
|
|
318
|
+
validateBundlesPermitValue({
|
|
314
319
|
field: "deadline",
|
|
315
|
-
expected:
|
|
316
|
-
actual:
|
|
320
|
+
expected: requirementSignature.args.deadline,
|
|
321
|
+
actual: requirementSignature.action.args.deadline,
|
|
317
322
|
});
|
|
318
323
|
}
|
|
319
|
-
if (requirementSignature.action.args.nonce != null
|
|
320
|
-
|
|
321
|
-
|
|
324
|
+
if (requirementSignature.action.args.nonce != null) {
|
|
325
|
+
// Validation only; checks the optional operation nonce against the signed nonce.
|
|
326
|
+
validateBundlesPermitValue({
|
|
322
327
|
field: "nonce",
|
|
323
|
-
expected:
|
|
324
|
-
actual:
|
|
328
|
+
expected: requirementSignature.args.nonce,
|
|
329
|
+
actual: requirementSignature.action.args.nonce,
|
|
325
330
|
});
|
|
326
331
|
}
|
|
327
332
|
const signature = normalizeBundlesSignature(requirementSignature.args.signature);
|
|
@@ -349,7 +354,9 @@ export const getBundlesSharesPermit = (params) => {
|
|
|
349
354
|
* from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
|
|
350
355
|
*/
|
|
351
356
|
export const selectBundlesTokenRequirementSignature = (signatures, expected) => {
|
|
352
|
-
if (signatures == null
|
|
357
|
+
if (signatures == null)
|
|
358
|
+
return undefined;
|
|
359
|
+
if (signatures.length === 0)
|
|
353
360
|
return undefined;
|
|
354
361
|
const selected = signatures.filter((signature) => signature.action.type === "permit" ||
|
|
355
362
|
signature.action.type === "permit2SignatureTransfer");
|
|
@@ -372,24 +379,24 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
372
379
|
actual: action.args.spender,
|
|
373
380
|
});
|
|
374
381
|
}
|
|
375
|
-
|
|
376
|
-
|
|
382
|
+
const actualAmount = selectedSignature.args.amount !== expected.amount
|
|
383
|
+
? selectedSignature.args.amount
|
|
384
|
+
: action.args.amount;
|
|
385
|
+
if (actualAmount !== expected.amount) {
|
|
377
386
|
throw new BundlesPermitMismatchError({
|
|
378
387
|
field: "amount",
|
|
379
388
|
expected: String(expected.amount),
|
|
380
|
-
actual: String(
|
|
381
|
-
? selectedSignature.args.amount
|
|
382
|
-
: action.args.amount),
|
|
389
|
+
actual: String(actualAmount),
|
|
383
390
|
});
|
|
384
391
|
}
|
|
385
|
-
|
|
386
|
-
|
|
392
|
+
const actualDeadline = selectedSignature.args.deadline !== expected.deadline
|
|
393
|
+
? selectedSignature.args.deadline
|
|
394
|
+
: action.args.deadline;
|
|
395
|
+
if (actualDeadline !== expected.deadline) {
|
|
387
396
|
throw new BundlesPermitMismatchError({
|
|
388
397
|
field: "deadline",
|
|
389
398
|
expected: String(expected.deadline),
|
|
390
|
-
actual: String(
|
|
391
|
-
? selectedSignature.args.deadline
|
|
392
|
-
: action.args.deadline),
|
|
399
|
+
actual: String(actualDeadline),
|
|
393
400
|
});
|
|
394
401
|
}
|
|
395
402
|
if (action.args.nonce != null &&
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { deepFreeze, getChainAddress
|
|
3
|
-
import {
|
|
1
|
+
import { MarketUtils, midnightBundlesV2Abi } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { zeroAddress, zeroHash } from "viem";
|
|
4
4
|
import { encodeMidnightCalldata, encodeMidnightMarketId, } from "../../helpers/encodeMidnightCalldata.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
6
|
import { validateDeadline, validateMidnightNativeAmount, } from "../../helpers/validate.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
|
|
7
|
+
import { validateMidnightUint128Field } from "../../helpers/validateMidnightBounds.js";
|
|
8
|
+
import { normalizeMidnightCancelAndMakePublication, validateMidnightCancelAndMakePublication, } from "../../helpers/validateMidnightCancelAndMakePublication.js";
|
|
10
9
|
import { snapshotMidnightCancelAndMakeParams, validateMidnightPublication, } from "../../helpers/validateMidnightPublication.js";
|
|
11
|
-
import { DuplicateMidnightGroupCancellationError,
|
|
12
|
-
/** Blue market argument for `MidnightBundlesV2` calls that park no loan assets. */
|
|
13
|
-
const emptyBlueMarket = {
|
|
14
|
-
loanToken: zeroAddress,
|
|
15
|
-
collateralToken: zeroAddress,
|
|
16
|
-
oracle: zeroAddress,
|
|
17
|
-
irm: zeroAddress,
|
|
18
|
-
lltv: 0n,
|
|
19
|
-
};
|
|
10
|
+
import { DuplicateMidnightGroupCancellationError, EmptyMidnightGroupCancellationsError, } from "../../types/index.js";
|
|
20
11
|
/** Midnight market argument for `MidnightBundlesV2` calls that supply no collateral. */
|
|
21
12
|
const emptyMidnightMarket = {
|
|
22
13
|
chainId: 0n,
|
|
@@ -133,15 +124,8 @@ export const midnightCancelAndMake = (params) => {
|
|
|
133
124
|
const cancelledGroups = new Set();
|
|
134
125
|
for (const [index, { group, maxConsumed },] of snapshot.cancellations.entries()) {
|
|
135
126
|
const field = `cancellations[${index}].maxConsumed`;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (maxConsumed > maxUint128) {
|
|
139
|
-
throw new InputExceedsMaxError({
|
|
140
|
-
field,
|
|
141
|
-
value: maxConsumed,
|
|
142
|
-
max: maxUint128,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
127
|
+
// Validation only; enforces the cancellation ceiling uint128 range.
|
|
128
|
+
validateMidnightUint128Field(field, maxConsumed);
|
|
145
129
|
const key = group.toLowerCase();
|
|
146
130
|
if (cancelledGroups.has(key)) {
|
|
147
131
|
throw new DuplicateMidnightGroupCancellationError({ index, group });
|
|
@@ -155,54 +139,12 @@ export const midnightCancelAndMake = (params) => {
|
|
|
155
139
|
}
|
|
156
140
|
}
|
|
157
141
|
else {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
if (publication.groups.length === 0) {
|
|
165
|
-
throw new InvalidTreeError("Offer groups cannot be empty.");
|
|
166
|
-
}
|
|
167
|
-
const { priceRatifierV1, rateRatifierV1 } = getChainAddresses(snapshot.chainId);
|
|
168
|
-
const supportedTargets = [priceRatifierV1, rateRatifierV1].filter((target) => target != null);
|
|
169
|
-
validateMidnightAddress("publication.ratifier", publication.ratifier);
|
|
170
|
-
if (!supportedTargets.some((target) => isAddressEqual(publication.ratifier, target))) {
|
|
171
|
-
throw new UnsupportedMidnightAuthorizationTargetError({
|
|
172
|
-
authorized: publication.ratifier,
|
|
173
|
-
chainId: snapshot.chainId,
|
|
174
|
-
supportedTargets,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
for (const group of publication.groups) {
|
|
178
|
-
if (cancelledGroups.has(group.toLowerCase())) {
|
|
179
|
-
throw new MidnightReplacementGroupCancelledError({ group });
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (publication.blueSupply != null) {
|
|
183
|
-
if (publication.blueSupply.assets <= 0n) {
|
|
184
|
-
throw new NonPositiveInputError("blueSupply.assets", publication.blueSupply.assets);
|
|
185
|
-
}
|
|
186
|
-
validateMidnightUint128Field("blueSupply.assets", publication.blueSupply.assets);
|
|
187
|
-
}
|
|
188
|
-
if (publication.collateral != null) {
|
|
189
|
-
if (publication.collateral.supplies.length === 0) {
|
|
190
|
-
throw new EmptyMidnightCollateralSuppliesError();
|
|
191
|
-
}
|
|
192
|
-
validateMidnightMarket({
|
|
193
|
-
market: publication.collateral.market,
|
|
194
|
-
chainId: snapshot.chainId,
|
|
195
|
-
});
|
|
196
|
-
for (const [index, { collateralIndex, assets },] of publication.collateral.supplies.entries()) {
|
|
197
|
-
if (assets <= 0n) {
|
|
198
|
-
throw new NonPositiveInputError(`collateral.supplies[${index}].assets`, assets);
|
|
199
|
-
}
|
|
200
|
-
validateMidnightUint128Field(`collateral.supplies[${index}].assets`, assets);
|
|
201
|
-
// Throws UnknownCollateralIndexError when the index is not configured on the market.
|
|
202
|
-
MarketUtils.getCollateralByIndex(publication.collateral.market, collateralIndex);
|
|
203
|
-
}
|
|
204
|
-
validateMidnightCollateralSupplySums("collateral.supplies", publication.collateral.supplies);
|
|
205
|
-
}
|
|
142
|
+
// Validation only; checks publication content and funding inputs.
|
|
143
|
+
validateMidnightCancelAndMakePublication({
|
|
144
|
+
publication,
|
|
145
|
+
chainId: snapshot.chainId,
|
|
146
|
+
cancelledGroups,
|
|
147
|
+
});
|
|
206
148
|
}
|
|
207
149
|
const collateral = publication?.collateral;
|
|
208
150
|
const collateralPulls = collateral == null
|
|
@@ -230,28 +172,8 @@ export const midnightCancelAndMake = (params) => {
|
|
|
230
172
|
group,
|
|
231
173
|
maxConsumed,
|
|
232
174
|
}));
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
? undefined
|
|
236
|
-
: {
|
|
237
|
-
market: {
|
|
238
|
-
loanToken: publication.blueSupply.market.loanToken,
|
|
239
|
-
collateralToken: publication.blueSupply.market.collateralToken,
|
|
240
|
-
oracle: publication.blueSupply.market.oracle,
|
|
241
|
-
irm: publication.blueSupply.market.irm,
|
|
242
|
-
lltv: publication.blueSupply.market.lltv,
|
|
243
|
-
},
|
|
244
|
-
assets: publication.blueSupply.assets,
|
|
245
|
-
callbackSalt: publication.blueSupply.callbackSalt,
|
|
246
|
-
};
|
|
247
|
-
const signature = publication?.rootSignature ?? {
|
|
248
|
-
height: 0n,
|
|
249
|
-
nonce: 0n,
|
|
250
|
-
deadline: 0n,
|
|
251
|
-
v: 0,
|
|
252
|
-
r: zeroHash,
|
|
253
|
-
s: zeroHash,
|
|
254
|
-
};
|
|
175
|
+
const normalized = normalizeMidnightCancelAndMakePublication(publication);
|
|
176
|
+
const { supplies, blueSupply, signature } = normalized;
|
|
255
177
|
let tx = {
|
|
256
178
|
to: getChainAddress(snapshot.chainId, "midnightBundlesV2"),
|
|
257
179
|
value: nativeFunding.value,
|
|
@@ -259,15 +181,15 @@ export const midnightCancelAndMake = (params) => {
|
|
|
259
181
|
abi: midnightBundlesV2Abi,
|
|
260
182
|
functionName: "midnightBundlesV2CancelAndMake",
|
|
261
183
|
args: [
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
184
|
+
normalized.blueMarket, // blueMarket
|
|
185
|
+
normalized.assetsToPark, // assetsToPark
|
|
186
|
+
normalized.callbackSalt, // callbackSalt
|
|
265
187
|
publication?.collateral == null
|
|
266
188
|
? emptyMidnightMarket
|
|
267
189
|
: MarketUtils.toStruct(publication.collateral.market), // market
|
|
268
190
|
supplies, // collateralSupplies
|
|
269
|
-
|
|
270
|
-
|
|
191
|
+
normalized.ratifier, // ratifier
|
|
192
|
+
normalized.root, // newRoot
|
|
271
193
|
signature.height, // signatureHeight
|
|
272
194
|
signature.nonce, // signatureNonce
|
|
273
195
|
signature.deadline, // signatureDeadline
|
|
@@ -275,7 +197,7 @@ export const midnightCancelAndMake = (params) => {
|
|
|
275
197
|
signature.r, // r
|
|
276
198
|
signature.s, // s
|
|
277
199
|
cancellations, // groupsToCancel
|
|
278
|
-
|
|
200
|
+
normalized.payload, // payload
|
|
279
201
|
snapshot.deadline, // deadline
|
|
280
202
|
nativeFunding.wrappedNative, // wrappedNative
|
|
281
203
|
],
|
|
@@ -292,9 +214,9 @@ export const midnightCancelAndMake = (params) => {
|
|
|
292
214
|
market: publication?.collateral == null
|
|
293
215
|
? zeroHash
|
|
294
216
|
: encodeMidnightMarketId(publication.collateral.market),
|
|
295
|
-
ratifier:
|
|
296
|
-
root:
|
|
297
|
-
groups:
|
|
217
|
+
ratifier: normalized.ratifier,
|
|
218
|
+
root: normalized.root,
|
|
219
|
+
groups: normalized.groups,
|
|
298
220
|
cancellations,
|
|
299
221
|
collateralSupplies: supplies,
|
|
300
222
|
...(blueSupply && { blueSupply }),
|
|
@@ -3,6 +3,7 @@ export * from "./cancelAndMake.js";
|
|
|
3
3
|
export * from "./redeem.js";
|
|
4
4
|
export * from "./repayWithdrawCollateral.js";
|
|
5
5
|
export * from "./supplyCollateral.js";
|
|
6
|
+
export * from "./supplyCollateralBatch.js";
|
|
6
7
|
export * from "./supplyCollateralTakeBorrow.js";
|
|
7
8
|
export * from "./takeBorrow.js";
|
|
8
9
|
export * from "./takeLend.js";
|
|
@@ -10,3 +11,4 @@ export * from "./takeRepayWithdrawCollateral.js";
|
|
|
10
11
|
export * from "./takeWithdraw.js";
|
|
11
12
|
export * from "./types.js";
|
|
12
13
|
export * from "./withdrawCollateral.js";
|
|
14
|
+
export * from "./withdrawCollateralBatch.js";
|
|
@@ -3,6 +3,7 @@ export * from "./cancelAndMake.js";
|
|
|
3
3
|
export * from "./redeem.js";
|
|
4
4
|
export * from "./repayWithdrawCollateral.js";
|
|
5
5
|
export * from "./supplyCollateral.js";
|
|
6
|
+
export * from "./supplyCollateralBatch.js";
|
|
6
7
|
export * from "./supplyCollateralTakeBorrow.js";
|
|
7
8
|
export * from "./takeBorrow.js";
|
|
8
9
|
export * from "./takeLend.js";
|
|
@@ -10,3 +11,4 @@ export * from "./takeRepayWithdrawCollateral.js";
|
|
|
10
11
|
export * from "./takeWithdraw.js";
|
|
11
12
|
export * from "./types.js";
|
|
12
13
|
export * from "./withdrawCollateral.js";
|
|
14
|
+
export * from "./withdrawCollateralBatch.js";
|
|
@@ -7,6 +7,7 @@ import { validateDeadline, validateMidnightNativeAmount, validateUint256Field, }
|
|
|
7
7
|
import { validateMidnightAddress } from "../../helpers/validateMidnightAccount.js";
|
|
8
8
|
import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
|
|
9
9
|
import { validateMidnightReceiver } from "../../helpers/validateMidnightReceiver.js";
|
|
10
|
+
import { validatePositiveInput } from "../../helpers/validatePositiveInput.js";
|
|
10
11
|
import { InputExceedsMaxError, NonPositiveInputError, } from "../../types/index.js";
|
|
11
12
|
/**
|
|
12
13
|
* Encodes a reduce-only `MidnightBundlesV2` buy with no offers, so the sender's debt is repaid
|
|
@@ -76,9 +77,8 @@ export const midnightRepayWithdrawCollateral = (params) => {
|
|
|
76
77
|
throw new NonPositiveInputError("repay or withdraw amount", 0n);
|
|
77
78
|
}
|
|
78
79
|
if (repay.type === "full") {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
80
|
+
// Validation only; rejects non-positive amounts.
|
|
81
|
+
validatePositiveInput("repay.maxBuyerAssets", repay.maxBuyerAssets);
|
|
82
82
|
if (repay.maxBuyerAssets >= maxUint256) {
|
|
83
83
|
throw new InputExceedsMaxError({
|
|
84
84
|
field: "repay.maxBuyerAssets",
|
|
@@ -89,9 +89,8 @@ export const midnightRepayWithdrawCollateral = (params) => {
|
|
|
89
89
|
}
|
|
90
90
|
validateMidnightMarket({ market: params.market, chainId: params.chainId });
|
|
91
91
|
for (const [index, { collateralIndex, assets },] of params.collateralWithdrawals.entries()) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
92
|
+
// Validation only; rejects non-positive amounts.
|
|
93
|
+
validatePositiveInput(`collateralWithdrawals[${index}].assets`, assets);
|
|
95
94
|
validateUint256Field(`collateralWithdrawals[${index}].assets`, assets);
|
|
96
95
|
// Throws UnknownCollateralIndexError when the index is not configured on the market.
|
|
97
96
|
MarketUtils.getCollateralByIndex(params.market, collateralIndex);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type Metadata, type MidnightCollateralTransfer, type MidnightSupplyCollateralBatchAction, type Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for an atomic direct Midnight collateral supply batch. */
|
|
5
|
+
export interface MidnightSupplyCollateralBatchParams {
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly market: MarketInput;
|
|
8
|
+
readonly collateralSupplies: readonly MidnightCollateralTransfer[];
|
|
9
|
+
readonly onBehalf: Address;
|
|
10
|
+
readonly metadata?: Metadata;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Encodes ordered collateral supplies in one Midnight multicall, even for one entry.
|
|
14
|
+
* Duplicates are rejected: pass one entry per index, unlike bundle flows which sum them.
|
|
15
|
+
*
|
|
16
|
+
* @param params.chainId - Chain containing Midnight.
|
|
17
|
+
* @param params.market - Market receiving collateral.
|
|
18
|
+
* @param params.collateralSupplies - Nonempty ordered supplies, with unique collateral indexes.
|
|
19
|
+
* @param params.onBehalf - Account receiving collateral; this account or an authorized operator must send the transaction.
|
|
20
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
21
|
+
* @returns A deep-frozen transaction targeting Midnight.
|
|
22
|
+
* @throws {EmptyMidnightCollateralSuppliesError} when the list is empty.
|
|
23
|
+
* @throws {DuplicateMidnightCollateralIndexError} when an index repeats.
|
|
24
|
+
* @throws {NonPositiveInputError} when assets are not positive.
|
|
25
|
+
* @throws {InputExceedsMaxError} when assets exceed uint128.
|
|
26
|
+
* @throws {MidnightZeroOnBehalfError} when onBehalf is zero.
|
|
27
|
+
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
28
|
+
* @throws {MidnightMarketAddressMismatchError} when the deployment differs.
|
|
29
|
+
* @throws {UnknownCollateralIndexError} when an index is not configured.
|
|
30
|
+
* @throws {MidnightCalldataEncodingError} when an address or ABI input is malformed.
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const tx = midnightSupplyCollateralBatch({
|
|
34
|
+
* chainId: 8453, market: marketData.params, onBehalf: user,
|
|
35
|
+
* collateralSupplies: [{ collateralIndex: 0n, assets: 100n }],
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const midnightSupplyCollateralBatch: (params: MidnightSupplyCollateralBatchParams) => Readonly<Transaction<MidnightSupplyCollateralBatchAction>>;
|