@morpho-org/morpho-sdk 6.5.0 → 7.0.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 +291 -0
- package/README.md +26 -12
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +3 -2
- package/lib/cjs/actions/bundles/common.d.ts +9 -5
- package/lib/cjs/actions/bundles/common.js +22 -13
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
- package/lib/cjs/actions/midnight/authorization.js +3 -2
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
- package/lib/cjs/actions/midnight/index.d.ts +3 -3
- package/lib/cjs/actions/midnight/index.js +3 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
- package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
- package/lib/cjs/actions/midnight/takeLend.js +111 -54
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
- package/lib/cjs/actions/midnight/types.d.ts +7 -26
- package/lib/cjs/actions/midnight/types.js +0 -13
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/midnight/index.js +0 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +3 -1
- package/lib/cjs/entities/blue/blue.d.ts +10 -6
- package/lib/cjs/entities/blue/blue.js +5 -3
- package/lib/cjs/entities/index.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
- package/lib/cjs/entities/midnight/midnight.js +981 -509
- package/lib/cjs/entities/midnight/types.d.ts +142 -60
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
- package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -3
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +119 -43
- package/lib/cjs/helpers/callback.d.ts +54 -0
- package/lib/cjs/helpers/callback.js +73 -0
- package/lib/cjs/helpers/constant.d.ts +10 -0
- package/lib/cjs/helpers/constant.js +11 -1
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +7 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/cjs/helpers/utilization.d.ts +13 -0
- package/lib/cjs/helpers/utilization.js +26 -1
- package/lib/cjs/helpers/validate.d.ts +43 -2
- package/lib/cjs/helpers/validate.js +60 -3
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +3 -2
- package/lib/cjs/midnight/types.d.ts +1 -1
- package/lib/cjs/types/action.d.ts +117 -89
- package/lib/cjs/types/action.js +1 -19
- package/lib/cjs/types/error.d.ts +126 -40
- package/lib/cjs/types/error.js +154 -49
- package/lib/cjs/types/sharedLiquidity.d.ts +17 -0
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +9 -5
- package/lib/esm/actions/bundles/common.js +22 -13
- package/lib/esm/actions/midnight/authorization.d.ts +3 -2
- package/lib/esm/actions/midnight/authorization.js +3 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
- package/lib/esm/actions/midnight/index.d.ts +3 -3
- package/lib/esm/actions/midnight/index.js +3 -3
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
- package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/esm/actions/midnight/takeBorrow.js +98 -57
- package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
- package/lib/esm/actions/midnight/takeLend.js +114 -57
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
- package/lib/esm/actions/midnight/types.d.ts +7 -26
- package/lib/esm/actions/midnight/types.js +1 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/esm/actions/requirements/midnight/index.js +0 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +10 -6
- package/lib/esm/entities/blue/blue.js +5 -3
- package/lib/esm/entities/index.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +582 -108
- package/lib/esm/entities/midnight/midnight.js +987 -515
- package/lib/esm/entities/midnight/types.d.ts +142 -60
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
- package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.js +120 -44
- package/lib/esm/helpers/callback.d.ts +54 -0
- package/lib/esm/helpers/callback.js +68 -0
- package/lib/esm/helpers/constant.d.ts +10 -0
- package/lib/esm/helpers/constant.js +10 -0
- package/lib/esm/helpers/index.d.ts +3 -2
- package/lib/esm/helpers/index.js +3 -2
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/esm/helpers/utilization.d.ts +13 -0
- package/lib/esm/helpers/utilization.js +25 -1
- package/lib/esm/helpers/validate.d.ts +43 -2
- package/lib/esm/helpers/validate.js +58 -2
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/esm/helpers/validateRequirementSpender.js +4 -5
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/types.d.ts +1 -1
- package/lib/esm/types/action.d.ts +117 -89
- package/lib/esm/types/action.js +1 -18
- package/lib/esm/types/error.d.ts +126 -40
- package/lib/esm/types/error.js +135 -38
- package/lib/esm/types/sharedLiquidity.d.ts +17 -0
- package/package.json +9 -8
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
- package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/esm/actions/midnight/cancelOffer.js +0 -69
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
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.ApprovalAmountLessThanSpendAmountError = 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.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.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = void 0;
|
|
4
|
+
exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = exports.MidnightOfferMarketAddressMismatchError = exports.MidnightOfferMarketChainMismatchError = exports.MidnightTakeDeadlineTooFarError = exports.MidnightZeroReceiverError = exports.UnboundedMidnightTakeInputError = exports.MidnightOfferSellerReceiverMismatchError = exports.MidnightOfferContinuousFeeCapError = exports.MidnightOfferMakerMismatchError = exports.MidnightOfferReduceOnlyError = exports.MidnightOfferSideMismatchError = exports.EmptyMidnightTakeableOffersError = exports.DuplicateMidnightGroupCancellationError = 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.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.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferMarketMismatchError = void 0;
|
|
6
6
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
7
|
/**
|
|
8
8
|
* Thrown when a morpho-sdk input that must be non-negative is negative.
|
|
@@ -584,7 +584,8 @@ class BundlesPermitMismatchError extends Error {
|
|
|
584
584
|
/**
|
|
585
585
|
* @param params - Permit mismatch values used to explain the rejection.
|
|
586
586
|
* @param params.field - Permit field that does not match the exit.
|
|
587
|
-
* @param params.expected - Value required by the exit.
|
|
587
|
+
* @param params.expected - Value required by the exit. For `field: "amount"` on an
|
|
588
|
+
* operation that accepts a range of permit amounts, an inclusive `"[min, max]"` range.
|
|
588
589
|
* @param params.actual - Value supplied by the signature.
|
|
589
590
|
* @param params.cause - Original parser failure when signature decoding is wrapped.
|
|
590
591
|
*/
|
|
@@ -883,18 +884,14 @@ exports.ApprovalAmountLessThanSpendAmountError = ApprovalAmountLessThanSpendAmou
|
|
|
883
884
|
/** Thrown when a requirement encoder targets an unsupported spender. */
|
|
884
885
|
class UnsupportedErc20ApprovalSpenderError extends Error {
|
|
885
886
|
constructor(params) {
|
|
886
|
-
const supported = (params.supportedSpenders ?? [
|
|
887
|
-
params.permit2,
|
|
888
|
-
params.midnight,
|
|
889
|
-
params.midnightBundles,
|
|
890
|
-
])
|
|
887
|
+
const supported = (params.supportedSpenders ?? [params.permit2, params.midnight])
|
|
891
888
|
.filter((address) => address != null)
|
|
892
889
|
.join('", "');
|
|
893
890
|
super(`Requirement spender "${params.spender}" is not supported on chain "${params.chainId}". Use "${supported}".`);
|
|
894
891
|
}
|
|
895
892
|
}
|
|
896
893
|
exports.UnsupportedErc20ApprovalSpenderError = UnsupportedErc20ApprovalSpenderError;
|
|
897
|
-
/** Thrown when a Midnight authorization requirement
|
|
894
|
+
/** Thrown when a Midnight authorization target (a requirement operator, or the ratifier that `midnightCancelAndMake` activates and MidnightBundlesV2 authorizes) is not registered for the chain. */
|
|
898
895
|
class UnsupportedMidnightAuthorizationTargetError extends Error {
|
|
899
896
|
constructor(params) {
|
|
900
897
|
super(`Midnight authorization target "${params.authorized}" is not supported on chain "${params.chainId}". Use "${params.supportedTargets.join('", "')}".`);
|
|
@@ -1294,13 +1291,27 @@ class ReallocationAdapterSupplySharesUnderflowError extends Error {
|
|
|
1294
1291
|
}
|
|
1295
1292
|
}
|
|
1296
1293
|
exports.ReallocationAdapterSupplySharesUnderflowError = ReallocationAdapterSupplySharesUnderflowError;
|
|
1297
|
-
/** Thrown when a Midnight
|
|
1298
|
-
class
|
|
1294
|
+
/** Thrown when a Midnight batch cancellation has no offer groups. */
|
|
1295
|
+
class EmptyMidnightGroupCancellationsError extends Error {
|
|
1296
|
+
constructor() {
|
|
1297
|
+
super("Midnight group cancellations cannot be empty. Pass at least one offer group to cancel.");
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
exports.EmptyMidnightGroupCancellationsError = EmptyMidnightGroupCancellationsError;
|
|
1301
|
+
/** Thrown when a Midnight flow passes a collateral market with no collateral supplies. */
|
|
1302
|
+
class EmptyMidnightCollateralSuppliesError extends Error {
|
|
1303
|
+
constructor() {
|
|
1304
|
+
super("Midnight collateral supplies cannot be empty. Pass at least one collateral supply, or use `makeBorrow` to publish without collateral.");
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
exports.EmptyMidnightCollateralSuppliesError = EmptyMidnightCollateralSuppliesError;
|
|
1308
|
+
/** Thrown when a Midnight batch cancellation lists the same offer group twice. */
|
|
1309
|
+
class DuplicateMidnightGroupCancellationError extends Error {
|
|
1299
1310
|
constructor(params) {
|
|
1300
|
-
super(`Midnight
|
|
1311
|
+
super(`Midnight group cancellation "${params.index}" repeats group "${params.group}". Pass each offer group once.`);
|
|
1301
1312
|
}
|
|
1302
1313
|
}
|
|
1303
|
-
exports.
|
|
1314
|
+
exports.DuplicateMidnightGroupCancellationError = DuplicateMidnightGroupCancellationError;
|
|
1304
1315
|
/** Thrown when a Midnight flow needs at least one takeable offer. */
|
|
1305
1316
|
class EmptyMidnightTakeableOffersError extends Error {
|
|
1306
1317
|
constructor() {
|
|
@@ -1315,6 +1326,13 @@ class MidnightOfferSideMismatchError extends Error {
|
|
|
1315
1326
|
}
|
|
1316
1327
|
}
|
|
1317
1328
|
exports.MidnightOfferSideMismatchError = MidnightOfferSideMismatchError;
|
|
1329
|
+
/** Thrown when a Midnight maker method that is not a limit exit receives a reduce-only offer. */
|
|
1330
|
+
class MidnightOfferReduceOnlyError extends Error {
|
|
1331
|
+
constructor(params) {
|
|
1332
|
+
super(`Midnight offer "${params.index}" is reduce-only. Rebuild the offer with reduceOnly=false; reduce-only exits need a dedicated exit flow.`);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
exports.MidnightOfferReduceOnlyError = MidnightOfferReduceOnlyError;
|
|
1318
1336
|
/** Thrown when a Midnight maker offer belongs to a different account than the action flow. */
|
|
1319
1337
|
class MidnightOfferMakerMismatchError extends Error {
|
|
1320
1338
|
constructor(params) {
|
|
@@ -1322,6 +1340,93 @@ class MidnightOfferMakerMismatchError extends Error {
|
|
|
1322
1340
|
}
|
|
1323
1341
|
}
|
|
1324
1342
|
exports.MidnightOfferMakerMismatchError = MidnightOfferMakerMismatchError;
|
|
1343
|
+
/** Thrown when a Midnight maker offer sets a nonzero continuous fee cap. */
|
|
1344
|
+
class MidnightOfferContinuousFeeCapError extends Error {
|
|
1345
|
+
/** Offer index in the maker tree. */
|
|
1346
|
+
index;
|
|
1347
|
+
/** Continuous fee cap supplied on the offer. */
|
|
1348
|
+
continuousFeeCap;
|
|
1349
|
+
/**
|
|
1350
|
+
* @param params - Offer index and rejected fee cap.
|
|
1351
|
+
* @param params.index - Offer index in the maker tree.
|
|
1352
|
+
* @param params.continuousFeeCap - Continuous fee cap supplied on the offer.
|
|
1353
|
+
*/
|
|
1354
|
+
constructor(params) {
|
|
1355
|
+
super(`Midnight offer "${params.index}" has continuous fee cap "${params.continuousFeeCap}". Maker offers must use 0n; rebuild the offer with its fee cap set to zero.`);
|
|
1356
|
+
this.index = params.index;
|
|
1357
|
+
this.continuousFeeCap = params.continuousFeeCap;
|
|
1358
|
+
this.name = "MidnightOfferContinuousFeeCapError";
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
exports.MidnightOfferContinuousFeeCapError = MidnightOfferContinuousFeeCapError;
|
|
1362
|
+
/** Thrown when a Midnight sell offer routes its seller proceeds to another address. */
|
|
1363
|
+
class MidnightOfferSellerReceiverMismatchError extends Error {
|
|
1364
|
+
/** Offer index in the maker tree. */
|
|
1365
|
+
index;
|
|
1366
|
+
/** Offer maker, which must receive seller proceeds. */
|
|
1367
|
+
expectedReceiver;
|
|
1368
|
+
/** Seller receiver supplied on the offer. */
|
|
1369
|
+
actualReceiver;
|
|
1370
|
+
/**
|
|
1371
|
+
* @param params - Offer index and expected and actual seller receivers.
|
|
1372
|
+
* @param params.index - Offer index in the maker tree.
|
|
1373
|
+
* @param params.expectedReceiver - Offer maker, which must receive seller proceeds.
|
|
1374
|
+
* @param params.actualReceiver - Seller receiver supplied on the offer.
|
|
1375
|
+
*/
|
|
1376
|
+
constructor(params) {
|
|
1377
|
+
super(`Midnight sell offer "${params.index}" routes seller proceeds to "${params.actualReceiver}", expected its maker "${params.expectedReceiver}". Set receiverIfMakerIsSeller to the maker address.`);
|
|
1378
|
+
this.index = params.index;
|
|
1379
|
+
this.expectedReceiver = params.expectedReceiver;
|
|
1380
|
+
this.actualReceiver = params.actualReceiver;
|
|
1381
|
+
this.name = "MidnightOfferSellerReceiverMismatchError";
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
exports.MidnightOfferSellerReceiverMismatchError = MidnightOfferSellerReceiverMismatchError;
|
|
1385
|
+
/** Thrown when a Midnight taker flow uses an unbounded target or deadline. */
|
|
1386
|
+
class UnboundedMidnightTakeInputError extends Error {
|
|
1387
|
+
field;
|
|
1388
|
+
/**
|
|
1389
|
+
* @param field - Target or deadline input set to `maxUint256`.
|
|
1390
|
+
*/
|
|
1391
|
+
constructor(field) {
|
|
1392
|
+
super(`Midnight "${field}" cannot be maxUint256. Provide an explicit bounded value.`);
|
|
1393
|
+
this.field = field;
|
|
1394
|
+
this.name = "UnboundedMidnightTakeInputError";
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
exports.UnboundedMidnightTakeInputError = UnboundedMidnightTakeInputError;
|
|
1398
|
+
/** Thrown when a Midnight taker flow uses a zero address as its receiver. */
|
|
1399
|
+
class MidnightZeroReceiverError extends Error {
|
|
1400
|
+
field;
|
|
1401
|
+
/**
|
|
1402
|
+
* @param field - Receiver field containing the zero address.
|
|
1403
|
+
*/
|
|
1404
|
+
constructor(field) {
|
|
1405
|
+
super(`Midnight "${field}" cannot be the zero address. Provide a valid recipient.`);
|
|
1406
|
+
this.field = field;
|
|
1407
|
+
this.name = "MidnightZeroReceiverError";
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
exports.MidnightZeroReceiverError = MidnightZeroReceiverError;
|
|
1411
|
+
/** Thrown when a Midnight take deadline is more than one hour from the current time. */
|
|
1412
|
+
class MidnightTakeDeadlineTooFarError extends Error {
|
|
1413
|
+
/** Deadline supplied by the caller. */
|
|
1414
|
+
deadline;
|
|
1415
|
+
/** Accepted maximum deadline. */
|
|
1416
|
+
maxDeadline;
|
|
1417
|
+
/**
|
|
1418
|
+
* @param params - Supplied deadline and accepted maximum.
|
|
1419
|
+
* @param params.deadline - Deadline supplied by the caller.
|
|
1420
|
+
* @param params.maxDeadline - Latest accepted deadline.
|
|
1421
|
+
*/
|
|
1422
|
+
constructor(params) {
|
|
1423
|
+
super(`Midnight take deadline "${params.deadline}" is later than the one-hour limit "${params.maxDeadline}". Choose a deadline within the next hour.`);
|
|
1424
|
+
this.deadline = params.deadline;
|
|
1425
|
+
this.maxDeadline = params.maxDeadline;
|
|
1426
|
+
this.name = "MidnightTakeDeadlineTooFarError";
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
exports.MidnightTakeDeadlineTooFarError = MidnightTakeDeadlineTooFarError;
|
|
1325
1430
|
/** Thrown when a Midnight maker offer targets a different chain than the action flow. */
|
|
1326
1431
|
class MidnightOfferMarketChainMismatchError extends Error {
|
|
1327
1432
|
constructor(params) {
|
|
@@ -1350,62 +1455,55 @@ class MidnightOfferMarketLoanTokenMismatchError extends Error {
|
|
|
1350
1455
|
}
|
|
1351
1456
|
}
|
|
1352
1457
|
exports.MidnightOfferMarketLoanTokenMismatchError = MidnightOfferMarketLoanTokenMismatchError;
|
|
1353
|
-
/** Thrown when a
|
|
1354
|
-
class
|
|
1458
|
+
/** Thrown when a Blue-funded Midnight lend offer does not use the maker's derived `BlueBuyCallback`. */
|
|
1459
|
+
class MidnightOfferCallbackMismatchError extends Error {
|
|
1355
1460
|
constructor(params) {
|
|
1356
|
-
super(`Midnight
|
|
1461
|
+
super(`Midnight offer "${params.index}" uses callback "${params.actualCallback}", expected the maker's BlueBuyCallback "${params.expectedCallback}". Rebuild the offer with the derived callback.`);
|
|
1357
1462
|
}
|
|
1358
1463
|
}
|
|
1359
|
-
exports.
|
|
1360
|
-
/** Thrown when a Midnight offer
|
|
1361
|
-
class
|
|
1464
|
+
exports.MidnightOfferCallbackMismatchError = MidnightOfferCallbackMismatchError;
|
|
1465
|
+
/** Thrown when a Blue-funded Midnight lend offer's callback data is not the ABI-encoded Blue market. */
|
|
1466
|
+
class MidnightOfferCallbackDataMismatchError extends Error {
|
|
1362
1467
|
constructor(params) {
|
|
1363
|
-
super(`Midnight offer
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
exports.UnknownMidnightRatifierError = UnknownMidnightRatifierError;
|
|
1367
|
-
/** Thrown when a Midnight Ecrecover maker flow builds the submit transaction before signing. */
|
|
1368
|
-
class MissingMidnightOfferRootSignatureError extends Error {
|
|
1369
|
-
constructor() {
|
|
1370
|
-
super("Midnight offer root signature is missing. Sign the offer-root requirement before building the submit transaction.");
|
|
1468
|
+
super(`Midnight offer "${params.index}" uses callback data "${params.actualCallbackData}", expected "${params.expectedCallbackData}". Set the callback data to the ABI-encoded Blue market the assets are parked in.`);
|
|
1371
1469
|
}
|
|
1372
1470
|
}
|
|
1373
|
-
exports.
|
|
1374
|
-
/** Thrown when
|
|
1375
|
-
class
|
|
1471
|
+
exports.MidnightOfferCallbackDataMismatchError = MidnightOfferCallbackDataMismatchError;
|
|
1472
|
+
/** Thrown when loan assets would be parked in a Morpho Blue market with no existing supply. */
|
|
1473
|
+
class EmptyBlueParkingMarketError extends Error {
|
|
1376
1474
|
constructor(params) {
|
|
1377
|
-
super(`
|
|
1475
|
+
super(`Morpho Blue market "${params.marketId}" has no supply shares. Parking assets in an empty market is exposed to supply-share-price inflation; choose a market with existing supply.`);
|
|
1378
1476
|
}
|
|
1379
1477
|
}
|
|
1380
|
-
exports.
|
|
1381
|
-
/** Thrown when
|
|
1382
|
-
class
|
|
1478
|
+
exports.EmptyBlueParkingMarketError = EmptyBlueParkingMarketError;
|
|
1479
|
+
/** Thrown when parked assets would mint no Morpho Blue supply shares. */
|
|
1480
|
+
class ZeroBlueParkingSharesError extends Error {
|
|
1383
1481
|
constructor(params) {
|
|
1384
|
-
super(`
|
|
1482
|
+
super(`Supplying "${params.assets}" assets to Morpho Blue market "${params.marketId}" mints zero supply shares at its current share price; park more assets or choose another market.`);
|
|
1385
1483
|
}
|
|
1386
1484
|
}
|
|
1387
|
-
exports.
|
|
1388
|
-
/** Thrown when a Midnight offer
|
|
1389
|
-
class
|
|
1485
|
+
exports.ZeroBlueParkingSharesError = ZeroBlueParkingSharesError;
|
|
1486
|
+
/** Thrown when a quoted Midnight takeable offer belongs to a different market than the requested flow. */
|
|
1487
|
+
class MidnightTakeableOfferMarketMismatchError extends Error {
|
|
1390
1488
|
constructor(params) {
|
|
1391
|
-
super(`Midnight offer
|
|
1489
|
+
super(`Midnight takeable offer "${params.index}" belongs to market "${params.actualMarket}", expected "${params.expectedMarket}". Refresh the quote and try again.`);
|
|
1392
1490
|
}
|
|
1393
1491
|
}
|
|
1394
|
-
exports.
|
|
1395
|
-
/** Thrown when a Midnight offer
|
|
1396
|
-
class
|
|
1492
|
+
exports.MidnightTakeableOfferMarketMismatchError = MidnightTakeableOfferMarketMismatchError;
|
|
1493
|
+
/** Thrown when a Midnight offer's ratifier does not match its tree's ratifier route. */
|
|
1494
|
+
class MidnightOfferRatifierMismatchError extends Error {
|
|
1397
1495
|
constructor(params) {
|
|
1398
|
-
super(`Midnight offer
|
|
1496
|
+
super(`Midnight offer "${params.index}" uses ratifier "${params.actualRatifier}", expected "${params.expectedRatifier}" for its tree type. Rebuild the offer with the tree's ratifier.`);
|
|
1399
1497
|
}
|
|
1400
1498
|
}
|
|
1401
|
-
exports.
|
|
1402
|
-
/** Thrown when a Midnight
|
|
1403
|
-
class
|
|
1404
|
-
constructor() {
|
|
1405
|
-
super(
|
|
1499
|
+
exports.MidnightOfferRatifierMismatchError = MidnightOfferRatifierMismatchError;
|
|
1500
|
+
/** Thrown when a Midnight repost cancels a group it also publishes. */
|
|
1501
|
+
class MidnightReplacementGroupCancelledError extends Error {
|
|
1502
|
+
constructor(params) {
|
|
1503
|
+
super(`Midnight offer group "${params.group}" is both published and cancelled. Give replacement offers a fresh group.`);
|
|
1406
1504
|
}
|
|
1407
1505
|
}
|
|
1408
|
-
exports.
|
|
1506
|
+
exports.MidnightReplacementGroupCancelledError = MidnightReplacementGroupCancelledError;
|
|
1409
1507
|
/** Thrown when a Midnight redeem flow finds no credit units for the user. */
|
|
1410
1508
|
class NoMidnightCreditToRedeemError extends Error {
|
|
1411
1509
|
constructor(market) {
|
|
@@ -1484,3 +1582,10 @@ class RefinanceTokenMismatchError extends Error {
|
|
|
1484
1582
|
}
|
|
1485
1583
|
}
|
|
1486
1584
|
exports.RefinanceTokenMismatchError = RefinanceTokenMismatchError;
|
|
1585
|
+
/** Thrown when a maker limit-exit offer can increase or open a position. */
|
|
1586
|
+
class MidnightOfferNotReduceOnlyError extends Error {
|
|
1587
|
+
constructor(params) {
|
|
1588
|
+
super(`Midnight exit offer "${params.index}" must have reduceOnly=true. Rebuild the offer tree for the exit intent.`);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
exports.MidnightOfferNotReduceOnlyError = MidnightOfferNotReduceOnlyError;
|
|
@@ -24,6 +24,23 @@ export interface VaultV2BluePublicAllocatorOptions {
|
|
|
24
24
|
* @default DEFAULT_CAP_ACCRUAL_BUFFER (2h)
|
|
25
25
|
*/
|
|
26
26
|
readonly capAccrualBuffer?: BigIntish;
|
|
27
|
+
/**
|
|
28
|
+
* Share of each target-market BluePublicAllocator cap, scaled by WAD, that
|
|
29
|
+
* operation planning keeps free. When a reallocation toward the utilization
|
|
30
|
+
* target would come within this headroom of the cap, the plan is reduced to
|
|
31
|
+
* the larger of the operation's absolute shortfall and what vaults below
|
|
32
|
+
* their cap were already moving. A plan of only the shortfall leaves the
|
|
33
|
+
* market fully utilized, so a competing borrow or withdraw landing first can
|
|
34
|
+
* still make it revert. If the shortfall cannot be covered while keeping the
|
|
35
|
+
* headroom, the plan uses the full cap, first for the shortfall only and
|
|
36
|
+
* then toward the utilization target if that is still short.
|
|
37
|
+
* Discovery plans, `getPublicReallocationLiquidity` and
|
|
38
|
+
* `getAvailableLiquidityToUtilization` ignore it and use the full cap.
|
|
39
|
+
* Must not exceed WAD (100%). Set to `0n` to disable.
|
|
40
|
+
*
|
|
41
|
+
* @default DEFAULT_ALLOCATOR_CAP_HEADROOM (1%)
|
|
42
|
+
*/
|
|
43
|
+
readonly allocatorCapHeadroom?: bigint;
|
|
27
44
|
/**
|
|
28
45
|
* Vault V2 addresses to consider. Arrays, readonly arrays, sets, and other
|
|
29
46
|
* iterables are accepted. Defaults to every vault in the reallocation data.
|
package/lib/esm/abis.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi,
|
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
6
|
preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
|
|
7
|
-
export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi,
|
|
7
|
+
export { blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
8
8
|
/** ABI for the VaultExitBundlesV1 periphery contract. */
|
|
9
9
|
export declare const vaultExitBundlesV1Abi: readonly [{
|
|
10
10
|
readonly type: "constructor";
|
package/lib/esm/abis.js
CHANGED
|
@@ -4,7 +4,7 @@ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi,
|
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
6
|
preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
|
|
7
|
-
export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi,
|
|
7
|
+
export { blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
8
8
|
/** ABI for the VaultExitBundlesV1 periphery contract. */
|
|
9
9
|
export const vaultExitBundlesV1Abi = [
|
|
10
10
|
{
|
|
@@ -203,18 +203,22 @@ export declare const selectBundlesTokenRequirementSignature: (signatures: readon
|
|
|
203
203
|
* @internal
|
|
204
204
|
*
|
|
205
205
|
* @param signatures - Signatures passed to the operation's `buildTx` function.
|
|
206
|
-
* @param expected - Immutable spender, amount, and deadline required by the operation.
|
|
206
|
+
* @param expected - Immutable spender, amount bounds, and deadline required by the operation.
|
|
207
207
|
* @param expected.spender - Fixed bundles contract the permit must authorize.
|
|
208
|
-
* @param expected.amount -
|
|
208
|
+
* @param expected.amount - Minimum share allowance the permit must cover.
|
|
209
|
+
* @param expected.maxAmount - Optional inclusive share allowance ceiling; defaults to
|
|
210
|
+
* `expected.amount`, which accepts only an exact match.
|
|
209
211
|
* @param expected.deadline - Deadline the permit must carry.
|
|
210
212
|
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
211
|
-
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612
|
|
212
|
-
*
|
|
213
|
-
*
|
|
213
|
+
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, its spender or
|
|
214
|
+
* deadline differ from the operation's, its signed amount differs from its action's amount, or
|
|
215
|
+
* its amount is outside `[expected.amount, expected.maxAmount ?? expected.amount]`.
|
|
216
|
+
* The nonce is not checked here: it is onchain state the vault's `permit` verifies at execution.
|
|
214
217
|
*/
|
|
215
218
|
export declare const selectBundlesSharesPermitSignature: (signatures: readonly RequirementSignature[] | undefined, expected: {
|
|
216
219
|
readonly spender: Address;
|
|
217
220
|
readonly amount: bigint;
|
|
221
|
+
readonly maxAmount?: bigint;
|
|
218
222
|
readonly deadline: bigint;
|
|
219
223
|
}) => Erc2612RequirementSignature | undefined;
|
|
220
224
|
/** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
|
|
@@ -356,11 +356,7 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
356
356
|
if (selected.length !== signatures.length) {
|
|
357
357
|
const unexpected = signatures.find((signature) => signature.action.type !== "permit" &&
|
|
358
358
|
signature.action.type !== "permit2SignatureTransfer");
|
|
359
|
-
throw new UnexpectedRequirementSignatureError(unexpected?.action.type === "authorization"
|
|
360
|
-
? "authorization"
|
|
361
|
-
: unexpected?.action.type === "midnightOfferRootSignature"
|
|
362
|
-
? "midnightOfferRootSignature"
|
|
363
|
-
: "permit");
|
|
359
|
+
throw new UnexpectedRequirementSignatureError(unexpected?.action.type === "authorization" ? "authorization" : "permit");
|
|
364
360
|
}
|
|
365
361
|
if (selected.length > 1) {
|
|
366
362
|
throw new AmbiguousRequirementSignaturesError("permit", selected.length);
|
|
@@ -412,14 +408,17 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
412
408
|
* @internal
|
|
413
409
|
*
|
|
414
410
|
* @param signatures - Signatures passed to the operation's `buildTx` function.
|
|
415
|
-
* @param expected - Immutable spender, amount, and deadline required by the operation.
|
|
411
|
+
* @param expected - Immutable spender, amount bounds, and deadline required by the operation.
|
|
416
412
|
* @param expected.spender - Fixed bundles contract the permit must authorize.
|
|
417
|
-
* @param expected.amount -
|
|
413
|
+
* @param expected.amount - Minimum share allowance the permit must cover.
|
|
414
|
+
* @param expected.maxAmount - Optional inclusive share allowance ceiling; defaults to
|
|
415
|
+
* `expected.amount`, which accepts only an exact match.
|
|
418
416
|
* @param expected.deadline - Deadline the permit must carry.
|
|
419
417
|
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
420
|
-
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612
|
|
421
|
-
*
|
|
422
|
-
*
|
|
418
|
+
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, its spender or
|
|
419
|
+
* deadline differ from the operation's, its signed amount differs from its action's amount, or
|
|
420
|
+
* its amount is outside `[expected.amount, expected.maxAmount ?? expected.amount]`.
|
|
421
|
+
* The nonce is not checked here: it is onchain state the vault's `permit` verifies at execution.
|
|
423
422
|
*/
|
|
424
423
|
export const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
425
424
|
const { permit } = selectRequirementSignatures(signatures, { permit: true });
|
|
@@ -440,11 +439,21 @@ export const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
|
440
439
|
actual: action.args.spender,
|
|
441
440
|
});
|
|
442
441
|
}
|
|
443
|
-
|
|
444
|
-
|
|
442
|
+
const maxAmount = expected.maxAmount ?? expected.amount;
|
|
443
|
+
const expectedAmount = expected.maxAmount == null || expected.maxAmount === expected.amount
|
|
444
|
+
? String(expected.amount)
|
|
445
|
+
: `[${expected.amount}, ${expected.maxAmount}]`;
|
|
446
|
+
if (permit.args.amount !== action.args.amount) {
|
|
445
447
|
throw new BundlesPermitMismatchError({
|
|
446
448
|
field: "amount",
|
|
447
|
-
expected: String(
|
|
449
|
+
expected: String(action.args.amount),
|
|
450
|
+
actual: String(permit.args.amount),
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
if (permit.args.amount < expected.amount || permit.args.amount > maxAmount) {
|
|
454
|
+
throw new BundlesPermitMismatchError({
|
|
455
|
+
field: "amount",
|
|
456
|
+
expected: expectedAmount,
|
|
448
457
|
actual: String(permit.args.amount),
|
|
449
458
|
});
|
|
450
459
|
}
|
|
@@ -9,7 +9,8 @@ export interface MidnightSetIsAuthorizedParams {
|
|
|
9
9
|
readonly metadata?: Metadata;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Encodes `Midnight.setIsAuthorized
|
|
12
|
+
* Encodes `Midnight.setIsAuthorized`. Grants target MidnightBundlesV2;
|
|
13
|
+
* revocations accept any operator.
|
|
13
14
|
*
|
|
14
15
|
* Prefer requirement helpers or entity `getRequirements()` in app flows; they
|
|
15
16
|
* read `isAuthorized` first and return this transaction only when needed. Use
|
|
@@ -29,7 +30,7 @@ export interface MidnightSetIsAuthorizedParams {
|
|
|
29
30
|
*
|
|
30
31
|
* const tx = midnightSetIsAuthorized({
|
|
31
32
|
* chainId: 8453,
|
|
32
|
-
* authorized:
|
|
33
|
+
* authorized: midnightBundlesV2,
|
|
33
34
|
* onBehalf: user,
|
|
34
35
|
* });
|
|
35
36
|
* ```
|
|
@@ -4,7 +4,8 @@ import { encodeFunctionData } from "viem";
|
|
|
4
4
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
5
|
import { validateMidnightAuthorizationTarget } from "../../helpers/validateMidnightAuthorizationTarget.js";
|
|
6
6
|
/**
|
|
7
|
-
* Encodes `Midnight.setIsAuthorized
|
|
7
|
+
* Encodes `Midnight.setIsAuthorized`. Grants target MidnightBundlesV2;
|
|
8
|
+
* revocations accept any operator.
|
|
8
9
|
*
|
|
9
10
|
* Prefer requirement helpers or entity `getRequirements()` in app flows; they
|
|
10
11
|
* read `isAuthorized` first and return this transaction only when needed. Use
|
|
@@ -24,7 +25,7 @@ import { validateMidnightAuthorizationTarget } from "../../helpers/validateMidni
|
|
|
24
25
|
*
|
|
25
26
|
* const tx = midnightSetIsAuthorized({
|
|
26
27
|
* chainId: 8453,
|
|
27
|
-
* authorized:
|
|
28
|
+
* authorized: midnightBundlesV2,
|
|
28
29
|
* onBehalf: user,
|
|
29
30
|
* });
|
|
30
31
|
* ```
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address, type Hex } from "viem";
|
|
3
|
+
import { type Metadata, type MidnightBlueSupply, type MidnightCancelAndMakeAction, type MidnightCollateralTransfer, type MidnightGroupCancellation, type Transaction } from "../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Delegated root-activation signature passed to the ratifier's `setIsRootRatifiedWithSig`.
|
|
6
|
+
* Omit it to activate the root directly with `setIsRootRatified`.
|
|
7
|
+
*/
|
|
8
|
+
export interface MidnightRootActivationSignature {
|
|
9
|
+
/** Tree height committed by the signature. */
|
|
10
|
+
readonly height: bigint;
|
|
11
|
+
/** Ratifier signature nonce. */
|
|
12
|
+
readonly nonce: bigint;
|
|
13
|
+
/** Signature deadline timestamp, independent of the bundle deadline. */
|
|
14
|
+
readonly deadline: bigint;
|
|
15
|
+
readonly v: number;
|
|
16
|
+
readonly r: Hex;
|
|
17
|
+
readonly s: Hex;
|
|
18
|
+
}
|
|
19
|
+
/** Collateral supplied for the maker before root activation; every offer must target `market`. */
|
|
20
|
+
export interface MidnightMakeBorrowCollateral {
|
|
21
|
+
readonly market: MarketInput;
|
|
22
|
+
readonly supplies: readonly MidnightCollateralTransfer[];
|
|
23
|
+
}
|
|
24
|
+
/** Offer root activated and published by a Midnight Bundles V2 maker bundle. */
|
|
25
|
+
export interface MidnightOfferPublication {
|
|
26
|
+
/**
|
|
27
|
+
* The chain's registered `priceRatifierV1` or `rateRatifierV1`, which activates `root`.
|
|
28
|
+
* MidnightBundlesV2 authorizes it over the maker's whole Midnight account.
|
|
29
|
+
*/
|
|
30
|
+
readonly ratifier: Address;
|
|
31
|
+
/** Offer tree root to activate. */
|
|
32
|
+
readonly root: Hex;
|
|
33
|
+
/** Distinct offer groups contained in `root`. */
|
|
34
|
+
readonly groups: readonly Hex[];
|
|
35
|
+
/** Encoded offer payload for `root`, published to the Midnight log. */
|
|
36
|
+
readonly payload: Hex;
|
|
37
|
+
/** Optional delegated root-activation signature. */
|
|
38
|
+
readonly rootSignature?: MidnightRootActivationSignature;
|
|
39
|
+
/** Optional loan assets parked on Morpho Blue for the maker; share-price slippage is not checked. */
|
|
40
|
+
readonly blueSupply?: MidnightBlueSupply;
|
|
41
|
+
/** Optional collateral supplied to `market` for the maker before activation. */
|
|
42
|
+
readonly collateral?: MidnightMakeBorrowCollateral;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parameters for encoding a Midnight Bundles V2 maker bundle: an offer publication or repost, or,
|
|
46
|
+
* without a publication, a cancellation of offer groups only.
|
|
47
|
+
*/
|
|
48
|
+
export interface MidnightCancelAndMakeParams {
|
|
49
|
+
/** Chain id used to resolve `MidnightBundlesV2`. */
|
|
50
|
+
readonly chainId: number;
|
|
51
|
+
/** Offer groups to cancel, each with its largest accepted consumption. Empty for a new publication. */
|
|
52
|
+
readonly cancellations: readonly MidnightGroupCancellation[];
|
|
53
|
+
/** Bundle execution deadline timestamp. Pass `maxUint256` explicitly for no expiry. */
|
|
54
|
+
readonly deadline: bigint;
|
|
55
|
+
/**
|
|
56
|
+
* Optional native ETH sent as `value`; the bundle wraps it into the chain's wNative and transfers
|
|
57
|
+
* it to `msg.sender` before pulling. It may cover part or all of the maximum wNative amount this
|
|
58
|
+
* call can pull, but not more. Any wrapped native not pulled stays in the sender's wallet as
|
|
59
|
+
* wNative. The wNative approval to `MidnightBundlesV2` is still required for the full pulled amount.
|
|
60
|
+
*/
|
|
61
|
+
readonly nativeAmount?: bigint;
|
|
62
|
+
/** Optional analytics metadata appended to calldata. */
|
|
63
|
+
readonly metadata?: Metadata;
|
|
64
|
+
/** Offers to publish after the cancellations. Omit to cancel offer groups only. */
|
|
65
|
+
readonly publication?: MidnightOfferPublication;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
|
|
69
|
+
* groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
|
|
70
|
+
* `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
|
|
71
|
+
* Without `publication`, it only cancels groups (`cancelOffers` uses this).
|
|
72
|
+
* Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
|
|
73
|
+
*
|
|
74
|
+
* The contract does not check that `payload` matches `root`; callers must derive both from the
|
|
75
|
+
* same tree. Prefer `client.morpho.midnight(chainId).makeLend(...)`,
|
|
76
|
+
* `makeBorrow(...)`, `supplyCollateralMakeBorrow(...)`, or `supplyBlueMakeLend(...)`, which derive
|
|
77
|
+
* the tree data and resolve the requirements for each flow; `supplyBlueMakeLend` also runs the
|
|
78
|
+
* Blue parking checks (callback, callbackData, empty-market and zero-share guards) that this builder
|
|
79
|
+
* skips.
|
|
80
|
+
*
|
|
81
|
+
* @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
|
|
82
|
+
* @param params.cancellations - Offer groups to cancel and their consumption ceilings.
|
|
83
|
+
* @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
|
|
84
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
85
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
|
|
86
|
+
* maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
|
|
87
|
+
* the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
|
|
88
|
+
* for the full pulled amount.
|
|
89
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
90
|
+
* @param params.publication - Offers to publish after the cancellations; omit for cancellation only.
|
|
91
|
+
* @param params.publication.ratifier - The chain's registered `priceRatifierV1` or `rateRatifierV1`,
|
|
92
|
+
* which activates the offer root.
|
|
93
|
+
* @param params.publication.root - Offer tree root to activate.
|
|
94
|
+
* @param params.publication.groups - Distinct offer groups contained in the root.
|
|
95
|
+
* @param params.publication.payload - Encoded offer payload published to the Midnight log.
|
|
96
|
+
* @param params.publication.rootSignature - Optional delegated root-activation signature; omitted, all fields are zero.
|
|
97
|
+
* @param params.publication.rootSignature.height - Tree height committed by the signature.
|
|
98
|
+
* @param params.publication.rootSignature.nonce - Ratifier signature nonce.
|
|
99
|
+
* @param params.publication.rootSignature.deadline - Signature deadline timestamp, independent of the bundle `deadline`.
|
|
100
|
+
* @param params.publication.rootSignature.v - Signature recovery id.
|
|
101
|
+
* @param params.publication.rootSignature.r - Signature `r` component.
|
|
102
|
+
* @param params.publication.rootSignature.s - Signature `s` component.
|
|
103
|
+
* @param params.publication.blueSupply - Optional loan assets to supply on Blue for the maker's `BlueBuyCallback`.
|
|
104
|
+
* @param params.publication.blueSupply.market - Blue market receiving the loan assets.
|
|
105
|
+
* @param params.publication.blueSupply.assets - Loan assets pulled from `msg.sender` and supplied on Blue; must be positive.
|
|
106
|
+
* @param params.publication.blueSupply.callbackSalt - Salt selecting the maker's `BlueBuyCallback`.
|
|
107
|
+
* @param params.publication.collateral - Optional collateral to supply on `collateral.market` for `msg.sender`.
|
|
108
|
+
* @param params.publication.collateral.market - Midnight market receiving the collateral; every offer must target it.
|
|
109
|
+
* @param params.publication.collateral.supplies - Collateral index and assets per supply; must not be empty.
|
|
110
|
+
* @returns Deep-frozen transaction targeting `MidnightBundlesV2`.
|
|
111
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
112
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
113
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when the ratifier is not the chain's registered `priceRatifierV1` or `rateRatifierV1`.
|
|
114
|
+
* @throws {EmptyMidnightGroupCancellationsError} when nothing is published and no groups are cancelled.
|
|
115
|
+
* @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
|
|
116
|
+
* @throws {InvalidTreeError} when `root` is zero, or `payload` or `groups` is empty.
|
|
117
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
118
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
119
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
120
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling or `nativeAmount` is negative.
|
|
121
|
+
* @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128`, or `deadline` or a collateral supply amount exceeds `uint256`, or `nativeAmount` exceeds the maximum wNative pull, including zero when no wNative is pulled.
|
|
122
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
123
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when configured token pulls contain no wNative token.
|
|
124
|
+
* @throws {ChainIdMismatchError} when the collateral market targets another chain.
|
|
125
|
+
* @throws {MidnightMarketAddressMismatchError} when the collateral market targets another Midnight deployment.
|
|
126
|
+
* @throws {UnknownCollateralIndexError} when a collateral index is not configured on the market.
|
|
127
|
+
* @throws {NonPositiveInputError} when a collateral supply amount is non-positive.
|
|
128
|
+
* @throws {NonPositiveInputError} when `blueSupply.assets` is non-positive.
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
132
|
+
* import { maxUint256, type Hex } from "viem";
|
|
133
|
+
* import { midnightCancelAndMake } from "@morpho-org/morpho-sdk";
|
|
134
|
+
*
|
|
135
|
+
* const rateRatifierV1 = getChainAddress(8453, "rateRatifierV1");
|
|
136
|
+
* declare const root: Hex;
|
|
137
|
+
* declare const group: Hex;
|
|
138
|
+
* declare const payload: Hex;
|
|
139
|
+
* declare const previousGroup: Hex;
|
|
140
|
+
* const tx = midnightCancelAndMake({
|
|
141
|
+
* chainId: 8453,
|
|
142
|
+
* cancellations: [{ group: previousGroup, maxConsumed: 0n }],
|
|
143
|
+
* deadline: maxUint256,
|
|
144
|
+
* publication: {
|
|
145
|
+
* ratifier: rateRatifierV1,
|
|
146
|
+
* root,
|
|
147
|
+
* groups: [group],
|
|
148
|
+
* payload,
|
|
149
|
+
* },
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare const midnightCancelAndMake: (params: MidnightCancelAndMakeParams) => Readonly<Transaction<MidnightCancelAndMakeAction>>;
|