@morpho-org/morpho-sdk 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/MIGRATION-v5-to-v6.md +1 -1
  2. package/README.md +1 -1
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +3 -1
  5. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +16 -5
  6. package/lib/cjs/actions/vaultV2/forceWithdraw.js +16 -5
  7. package/lib/cjs/constants.d.ts +1 -1
  8. package/lib/cjs/constants.js +4 -1
  9. package/lib/cjs/entities/blue/blue.d.ts +28 -0
  10. package/lib/cjs/entities/blue/blue.js +1 -0
  11. package/lib/cjs/entities/index.d.ts +1 -1
  12. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -2
  13. package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
  14. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +35 -11
  15. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
  16. package/lib/cjs/errors.d.ts +1 -1
  17. package/lib/cjs/errors.js +8 -1
  18. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +10 -6
  19. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -6
  20. package/lib/cjs/helpers/slippage.d.ts +3 -2
  21. package/lib/cjs/helpers/slippage.js +3 -2
  22. package/lib/cjs/helpers/validate.d.ts +40 -0
  23. package/lib/cjs/helpers/validate.js +40 -0
  24. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +94 -59
  25. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +94 -59
  26. package/lib/cjs/midnight/abis.d.ts +1 -1
  27. package/lib/cjs/midnight/abis.js +3 -1
  28. package/lib/cjs/midnight/constants.d.ts +1 -1
  29. package/lib/cjs/midnight/constants.js +4 -1
  30. package/lib/cjs/midnight/entities.d.ts +1 -1
  31. package/lib/cjs/midnight/errors.d.ts +1 -1
  32. package/lib/cjs/midnight/errors.js +7 -1
  33. package/lib/cjs/midnight/types.d.ts +1 -1
  34. package/lib/cjs/midnight/utils.d.ts +11 -1
  35. package/lib/cjs/midnight/utils.js +13 -1
  36. package/lib/cjs/types/action.d.ts +34 -0
  37. package/lib/cjs/types/action.js +10 -0
  38. package/lib/cjs/types.d.ts +1 -1
  39. package/lib/cjs/utils.d.ts +11 -1
  40. package/lib/cjs/utils.js +14 -2
  41. package/lib/esm/abis.d.ts +1 -1
  42. package/lib/esm/abis.js +1 -1
  43. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +16 -5
  44. package/lib/esm/actions/vaultV2/forceWithdraw.js +16 -5
  45. package/lib/esm/constants.d.ts +1 -1
  46. package/lib/esm/constants.js +1 -1
  47. package/lib/esm/entities/blue/blue.d.ts +28 -0
  48. package/lib/esm/entities/blue/blue.js +1 -0
  49. package/lib/esm/entities/index.d.ts +1 -1
  50. package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -2
  51. package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
  52. package/lib/esm/entities/vaultV2/vaultV2.d.ts +35 -11
  53. package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
  54. package/lib/esm/errors.d.ts +1 -1
  55. package/lib/esm/errors.js +1 -1
  56. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +10 -6
  57. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -6
  58. package/lib/esm/helpers/slippage.d.ts +3 -2
  59. package/lib/esm/helpers/slippage.js +3 -2
  60. package/lib/esm/helpers/validate.d.ts +40 -0
  61. package/lib/esm/helpers/validate.js +40 -0
  62. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +94 -59
  63. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +94 -59
  64. package/lib/esm/midnight/abis.d.ts +1 -1
  65. package/lib/esm/midnight/abis.js +1 -1
  66. package/lib/esm/midnight/constants.d.ts +1 -1
  67. package/lib/esm/midnight/constants.js +1 -1
  68. package/lib/esm/midnight/entities.d.ts +1 -1
  69. package/lib/esm/midnight/errors.d.ts +1 -1
  70. package/lib/esm/midnight/errors.js +1 -1
  71. package/lib/esm/midnight/types.d.ts +1 -1
  72. package/lib/esm/midnight/utils.d.ts +11 -1
  73. package/lib/esm/midnight/utils.js +11 -1
  74. package/lib/esm/types/action.d.ts +34 -0
  75. package/lib/esm/types/action.js +10 -0
  76. package/lib/esm/types.d.ts +1 -1
  77. package/lib/esm/utils.d.ts +11 -1
  78. package/lib/esm/utils.js +11 -1
  79. package/package.json +4 -4
@@ -46,6 +46,16 @@ function isRequirementSignature(requirement) {
46
46
  *
47
47
  * @param signature - The signed requirement to test.
48
48
  * @returns `true` when `signature.action.type` is `"permit"`.
49
+ * @example
50
+ * ```ts
51
+ * import {
52
+ * isPermitSignature,
53
+ * type RequirementSignature,
54
+ * } from "@morpho-org/morpho-sdk";
55
+ *
56
+ * const getPermitDeadline = (signature: RequirementSignature): bigint | undefined =>
57
+ * isPermitSignature(signature) ? signature.args.deadline : undefined;
58
+ * ```
49
59
  */
50
60
  function isPermitSignature(signature) {
51
61
  return signature.action.type === "permit";
@@ -1,5 +1,5 @@
1
1
  export type { BigIntish, CollateralAllocation, Eip712Field, Erc20AllowanceRecipient, Failable, Fetchable, InputMarketParams as BlueInputMarketParams, Loadable, MarketId as BlueMarketId, MaxBorrowOptions as BlueMaxBorrowOptions, MaxPositionCapacities as BlueMaxPositionCapacities, MaxWithdrawCollateralOptions as BlueMaxWithdrawCollateralOptions, Pending, } from "@morpho-org/blue-sdk";
2
2
  export type { AuthorizationArgs as BlueAuthorizationTypedDataArgs, DeploylessFetchParameters as BlueDeploylessFetchParameters, FetchParameters as BlueFetchParameters, InputAllocation as BlueInputAllocation, MetaMorphoCall as BlueMetaMorphoCall, Permit2PermitArgs, Permit2TransferFromArgs, PermitArgs as PermitTypedDataArgs, } from "@morpho-org/blue-sdk-viem";
3
- export type { BuildFixedRateOfferChainParams as MidnightBuildFixedRateOfferChainParams, DecodedEcrecoverRatifierData as MidnightDecodedEcrecoverRatifierData, DecodedSetterRatifierData as MidnightDecodedSetterRatifierData, DeploylessFetchParameters as MidnightDeploylessFetchParameters, EcrecoverRatificationTypedData as MidnightEcrecoverRatificationTypedData, EcrecoverRatifierDataDigestParams as MidnightEcrecoverRatifierDataDigestParams, EcrecoverRatifierDataParams as MidnightEcrecoverRatifierDataParams, EcrecoverRatifierDataVerificationParams as MidnightEcrecoverRatifierDataVerificationParams, EcrecoverRatifierRatifyParams as MidnightEcrecoverRatifierRatifyParams, EcrecoverRatifierRootDigestParams as MidnightEcrecoverRatifierRootDigestParams, EcrecoverRatifierTypedDataParams as MidnightEcrecoverRatifierTypedDataParams, EcrecoverSignatureInput as MidnightEcrecoverSignatureInput, FixedRateOfferChainLeg as MidnightFixedRateOfferChainLeg, GetRatifierInfoParams as MidnightGetRatifierInfoParams, MidnightCallParameters, MidnightFetchParams, RatifierInfo as MidnightRatifierInfo, SetterRatifierDataParams as MidnightSetterRatifierDataParams, SetterRatifierDataVerificationParams as MidnightSetterRatifierDataVerificationParams, VerifiedEcrecoverRatifierData as MidnightVerifiedEcrecoverRatifierData, } from "@morpho-org/midnight-sdk";
3
+ export type { BuildFixedRateOfferChainParams as MidnightBuildFixedRateOfferChainParams, DecodedEcrecoverRatifierData as MidnightDecodedEcrecoverRatifierData, DecodedPriceRatifierV1Data as MidnightDecodedPriceRatifierV1Data, DecodedRateRatifierV1Data as MidnightDecodedRateRatifierV1Data, DecodedSetterRatifierData as MidnightDecodedSetterRatifierData, DeploylessFetchParameters as MidnightDeploylessFetchParameters, EcrecoverRatificationTypedData as MidnightEcrecoverRatificationTypedData, EcrecoverRatifierDataDigestParams as MidnightEcrecoverRatifierDataDigestParams, EcrecoverRatifierDataParams as MidnightEcrecoverRatifierDataParams, EcrecoverRatifierDataRequest as MidnightEcrecoverRatifierDataRequest, EcrecoverRatifierDataVerificationParams as MidnightEcrecoverRatifierDataVerificationParams, EcrecoverRatifierRatifyParams as MidnightEcrecoverRatifierRatifyParams, EcrecoverRatifierRatifyRequest as MidnightEcrecoverRatifierRatifyRequest, EcrecoverRatifierRootDigestParams as MidnightEcrecoverRatifierRootDigestParams, EcrecoverRatifierSignRequest as MidnightEcrecoverRatifierSignRequest, EcrecoverRatifierTypedDataParams as MidnightEcrecoverRatifierTypedDataParams, EcrecoverRatifierTypedDataRequest as MidnightEcrecoverRatifierTypedDataRequest, EcrecoverSignatureInput as MidnightEcrecoverSignatureInput, FixedRateOfferChainLeg as MidnightFixedRateOfferChainLeg, GetRatifierInfoParams as MidnightGetRatifierInfoParams, MidnightCallParameters, MidnightFetchParams, PriceRatifierV1Leaf as MidnightPriceRatifierV1Leaf, PriceRatifierV1LeafStruct as MidnightPriceRatifierV1LeafStruct, PriceRatifierV1TreeDescriptor as MidnightPriceRatifierV1TreeDescriptor, PriceRatifierV1TreeInput as MidnightPriceRatifierV1TreeInput, RateRatifierV1Leaf as MidnightRateRatifierV1Leaf, RateRatifierV1LeafStruct as MidnightRateRatifierV1LeafStruct, RateRatifierV1TreeDescriptor as MidnightRateRatifierV1TreeDescriptor, RateRatifierV1TreeInput as MidnightRateRatifierV1TreeInput, RatifierInfo as MidnightRatifierInfo, SetterRatifierDataParams as MidnightSetterRatifierDataParams, SetterRatifierDataRequest as MidnightSetterRatifierDataRequest, SetterRatifierDataVerificationParams as MidnightSetterRatifierDataVerificationParams, SetterRatifierRatifyRequest as MidnightSetterRatifierRatifyRequest, VerifiedEcrecoverRatifierData as MidnightVerifiedEcrecoverRatifierData, } from "@morpho-org/midnight-sdk";
4
4
  export type { ChainMetadata } from "@morpho-org/morpho-ts";
5
5
  export * from "./types/index.js";
@@ -5,7 +5,17 @@ defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
6
  getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
7
7
  export { decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
8
- export { EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils, MarketUtils as MidnightMarketUtils, OfferChainUtils as MidnightOfferChainUtils, OfferUtils as MidnightOfferUtils, Payload as MidnightPayload, PositionUtils as MidnightPositionUtils, RatifierUtils as MidnightRatifierUtils, SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
8
+ export { EcrecoverRatifier as MidnightEcrecoverRatifier,
9
+ /** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
10
+ EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils, MarketUtils as MidnightMarketUtils, OfferChainUtils as MidnightOfferChainUtils, OfferUtils as MidnightOfferUtils, Payload as MidnightPayload, PositionUtils as MidnightPositionUtils, PriceRatifierV1 as MidnightPriceRatifierV1,
11
+ /** @deprecated Use MidnightPriceRatifierV1. */
12
+ PriceRatifierV1Utils as MidnightPriceRatifierV1Utils, RateRatifierV1 as MidnightRateRatifierV1,
13
+ /** @deprecated Use MidnightRateRatifierV1. */
14
+ RateRatifierV1Utils as MidnightRateRatifierV1Utils, Ratifier as MidnightRatifier,
15
+ /** @deprecated Use MidnightRatifier. */
16
+ RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier,
17
+ /** @deprecated Use MidnightSetterRatifier with a tagged tree. */
18
+ SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
9
19
  export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
10
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";
11
21
  export { addTransactionMetadata } from "./helpers/metadata.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.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightRatifierUtils = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = 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.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = void 0;
3
+ exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = 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.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = 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.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 = 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; } });
@@ -30,6 +30,8 @@ Object.defineProperty(exports, "safeGetAddress", { enumerable: true, get: functi
30
30
  Object.defineProperty(exports, "safeParseNumber", { enumerable: true, get: function () { return blue_sdk_viem_1.safeParseNumber; } });
31
31
  Object.defineProperty(exports, "safeParseUnits", { enumerable: true, get: function () { return blue_sdk_viem_1.safeParseUnits; } });
32
32
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
33
+ Object.defineProperty(exports, "MidnightEcrecoverRatifier", { enumerable: true, get: function () { return midnight_sdk_1.EcrecoverRatifier; } });
34
+ /** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
33
35
  Object.defineProperty(exports, "MidnightEcrecoverRatifierUtils", { enumerable: true, get: function () { return midnight_sdk_1.EcrecoverRatifierUtils; } });
34
36
  Object.defineProperty(exports, "eip712Digest", { enumerable: true, get: function () { return midnight_sdk_1.eip712Digest; } });
35
37
  Object.defineProperty(exports, "MidnightGroupUtils", { enumerable: true, get: function () { return midnight_sdk_1.GroupUtils; } });
@@ -38,7 +40,17 @@ Object.defineProperty(exports, "MidnightOfferChainUtils", { enumerable: true, ge
38
40
  Object.defineProperty(exports, "MidnightOfferUtils", { enumerable: true, get: function () { return midnight_sdk_1.OfferUtils; } });
39
41
  Object.defineProperty(exports, "MidnightPayload", { enumerable: true, get: function () { return midnight_sdk_1.Payload; } });
40
42
  Object.defineProperty(exports, "MidnightPositionUtils", { enumerable: true, get: function () { return midnight_sdk_1.PositionUtils; } });
43
+ Object.defineProperty(exports, "MidnightPriceRatifierV1", { enumerable: true, get: function () { return midnight_sdk_1.PriceRatifierV1; } });
44
+ /** @deprecated Use MidnightPriceRatifierV1. */
45
+ Object.defineProperty(exports, "MidnightPriceRatifierV1Utils", { enumerable: true, get: function () { return midnight_sdk_1.PriceRatifierV1Utils; } });
46
+ Object.defineProperty(exports, "MidnightRateRatifierV1", { enumerable: true, get: function () { return midnight_sdk_1.RateRatifierV1; } });
47
+ /** @deprecated Use MidnightRateRatifierV1. */
48
+ Object.defineProperty(exports, "MidnightRateRatifierV1Utils", { enumerable: true, get: function () { return midnight_sdk_1.RateRatifierV1Utils; } });
49
+ Object.defineProperty(exports, "MidnightRatifier", { enumerable: true, get: function () { return midnight_sdk_1.Ratifier; } });
50
+ /** @deprecated Use MidnightRatifier. */
41
51
  Object.defineProperty(exports, "MidnightRatifierUtils", { enumerable: true, get: function () { return midnight_sdk_1.RatifierUtils; } });
52
+ Object.defineProperty(exports, "MidnightSetterRatifier", { enumerable: true, get: function () { return midnight_sdk_1.SetterRatifier; } });
53
+ /** @deprecated Use MidnightSetterRatifier with a tagged tree. */
42
54
  Object.defineProperty(exports, "MidnightSetterRatifierUtils", { enumerable: true, get: function () { return midnight_sdk_1.SetterRatifierUtils; } });
43
55
  Object.defineProperty(exports, "MidnightTakeAmountsLib", { enumerable: true, get: function () { return midnight_sdk_1.TakeAmountsLib; } });
44
56
  Object.defineProperty(exports, "MidnightTickLib", { enumerable: true, get: function () { return midnight_sdk_1.TickLib; } });
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, midnightBundlesAbi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
7
+ export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, 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, midnightBundlesAbi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
7
+ export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, 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
  {
@@ -67,12 +67,23 @@ export interface VaultV2ForceWithdrawParams {
67
67
  * @example
68
68
  * ```ts
69
69
  * import { vaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
70
+ * import type { Address } from "viem";
71
+ * import { mainnet } from "viem/chains";
70
72
  *
71
- * const tx = vaultV2ForceWithdraw({
72
- * vault: { chainId: 1, address: vault },
73
- * args: { adapter, exitAssets: 1_000_000n, minSharePriceE27, userAddress, deadline },
74
- * });
75
- * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
73
+ * export function buildForceWithdraw(
74
+ * vault: Address,
75
+ * adapter: Address,
76
+ * minSharePriceE27: bigint,
77
+ * userAddress: Address,
78
+ * deadline: bigint,
79
+ * ) {
80
+ * const tx = vaultV2ForceWithdraw({
81
+ * vault: { chainId: mainnet.id, address: vault },
82
+ * args: { adapter, exitAssets: 1_000_000n, minSharePriceE27, userAddress, deadline },
83
+ * });
84
+ * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
85
+ * return tx;
86
+ * }
76
87
  * ```
77
88
  */
78
89
  export declare const vaultV2ForceWithdraw: ({ vault, args, metadata, }: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
@@ -54,12 +54,23 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
54
54
  * @example
55
55
  * ```ts
56
56
  * import { vaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
57
+ * import type { Address } from "viem";
58
+ * import { mainnet } from "viem/chains";
57
59
  *
58
- * const tx = vaultV2ForceWithdraw({
59
- * vault: { chainId: 1, address: vault },
60
- * args: { adapter, exitAssets: 1_000_000n, minSharePriceE27, userAddress, deadline },
61
- * });
62
- * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
60
+ * export function buildForceWithdraw(
61
+ * vault: Address,
62
+ * adapter: Address,
63
+ * minSharePriceE27: bigint,
64
+ * userAddress: Address,
65
+ * deadline: bigint,
66
+ * ) {
67
+ * const tx = vaultV2ForceWithdraw({
68
+ * vault: { chainId: mainnet.id, address: vault },
69
+ * args: { adapter, exitAssets: 1_000_000n, minSharePriceE27, userAddress, deadline },
70
+ * });
71
+ * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
72
+ * return tx;
73
+ * }
63
74
  * ```
64
75
  */
65
76
  export const vaultV2ForceWithdraw = ({ vault, args, metadata, }) => {
@@ -1,4 +1,4 @@
1
1
  export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType, } from "@morpho-org/blue-sdk";
2
- export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
2
+ export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, MAX_TREE_HEIGHT as MIDNIGHT_MAX_TREE_HEIGHT, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, RATE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
3
3
  export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
4
4
  export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
@@ -1,4 +1,4 @@
1
1
  export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType, } from "@morpho-org/blue-sdk";
2
- export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
2
+ export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, MAX_TREE_HEIGHT as MIDNIGHT_MAX_TREE_HEIGHT, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, RATE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
3
3
  export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
4
4
  export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
@@ -24,12 +24,26 @@ export interface BlueTokenRequirementsParams {
24
24
  */
25
25
  readonly approvalAmount?: bigint;
26
26
  }
27
+ /** Action surface for Morpho Blue reads and writes; writes route through BlueBundlesV1. */
27
28
  export interface BlueActions {
28
29
  /**
29
30
  * Fetches the latest market data with accrued interest.
30
31
  *
31
32
  * @param parameters - Optional fetch parameters (block number, state overrides).
32
33
  * @returns Market state including total supply/borrow assets and shares.
34
+ * @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
35
+ * @example
36
+ * ```ts
37
+ * import { markets } from "@morpho-org/morpho-test";
38
+ * import { createPublicClient, http } from "viem";
39
+ * import { mainnet } from "viem/chains";
40
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
41
+ *
42
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
43
+ * .extend(morphoViemExtension());
44
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
45
+ * const marketData = await market.getMarketData();
46
+ * ```
33
47
  */
34
48
  getMarketData: (parameters?: FetchParameters) => Promise<Market>;
35
49
  /**
@@ -38,6 +52,19 @@ export interface BlueActions {
38
52
  * @param userAddress - The user whose position to fetch.
39
53
  * @param parameters - Optional fetch parameters (block number, state overrides).
40
54
  * @returns Accrual position with health metrics (maxBorrowAssets, ltv, isHealthy).
55
+ * @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
56
+ * @example
57
+ * ```ts
58
+ * import { markets } from "@morpho-org/morpho-test";
59
+ * import { createPublicClient, http, zeroAddress } from "viem";
60
+ * import { mainnet } from "viem/chains";
61
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
62
+ *
63
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
64
+ * .extend(morphoViemExtension());
65
+ * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
66
+ * const position = await market.getPositionData(zeroAddress);
67
+ * ```
41
68
  */
42
69
  getPositionData: (userAddress: Address, parameters?: FetchParameters) => Promise<AccrualPosition>;
43
70
  /**
@@ -819,6 +846,7 @@ export interface BlueActions {
819
846
  readonly data: VaultV2BlueReallocationData;
820
847
  };
821
848
  }
849
+ /** Binds a viem client to a Morpho Blue market's action builders. */
822
850
  export declare class MorphoBlue implements BlueActions {
823
851
  private readonly client;
824
852
  readonly marketParams: MarketParams;
@@ -8,6 +8,7 @@ import { DEFAULT_LLTV_BUFFER, validateAccrualPosition, validateChainId, validate
8
8
  import { ExpiredDeadlineError, InputExceedsMaxError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, ReallocationsRequireBorrowError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
9
9
  import { getBundlesTokenRequirements } from "../requirements/index.js";
10
10
  import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
11
+ /** Binds a viem client to a Morpho Blue market's action builders. */
11
12
  export class MorphoBlue {
12
13
  client;
13
14
  marketParams;
@@ -8,7 +8,7 @@ export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, A
8
8
  PreLiquidationParams as BluePreLiquidationParams,
9
9
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
10
10
  PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
11
- export type { BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, RatifierTreeInput as MidnightRatifierTreeInput, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeDescriptor as MidnightTreeDescriptor, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, } from "@morpho-org/midnight-sdk";
11
+ export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnapshot, BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, EcrecoverTreeCreateRequest as MidnightEcrecoverTreeCreateRequest, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, PriceRatifierV1TreeCreateRequest as MidnightPriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest as MidnightRateRatifierV1TreeCreateRequest, RatifierKind as MidnightRatifierKind, RatifierTreeInput as MidnightRatifierTreeInput, RatifierTypes as MidnightRatifierTypes, SetterTreeCreateRequest as MidnightSetterTreeCreateRequest, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeCreateRequest as MidnightTreeCreateRequest, TreeData as MidnightTreeData, TreeDescriptor as MidnightTreeDescriptor, TreeEntry as MidnightTreeEntry, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, TreeSnapshot as MidnightTreeSnapshot, TypedRatifierTreeInput as MidnightTypedRatifierTreeInput, TypedTreeMempoolValidateParams as MidnightTypedTreeMempoolValidateParams, } from "@morpho-org/midnight-sdk";
12
12
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
13
13
  export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
14
14
  export { MorphoBlue } from "./blue/index.js";
@@ -3,13 +3,19 @@ import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
5
  import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type MorphoClientType, type RequirementSignature, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
6
+ /** Action surface for Vault V1 reads and writes; writes route through VaultBundlesV1 and VaultExitBundlesV1. */
6
7
  export interface VaultV1Actions {
7
8
  /**
8
9
  * Fetches direct onchain vault and allocation state without applying virtual interest.
9
10
  *
10
- * @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
11
- * @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The requested vault state.
11
+ * Reads the Vault V1 state through `fetchAccrualVault` on the entity's client.
12
+ *
13
+ * @param parameters - Optional viem fetch parameters (block number, block tag, state override).
14
+ * @returns The hydrated `AccrualVault` snapshot.
12
15
  * @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
16
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
17
+ * @throws {UnknownBlueFactory} when the configured chain has no MetaMorpho factory.
18
+ * @throws {UnknownBlueOfFactory} when the vault is not a MetaMorpho vault from the configured factory.
13
19
  */
14
20
  getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
15
21
  /**
@@ -414,6 +420,7 @@ export interface VaultV1Actions {
414
420
  readonly deadline?: bigint;
415
421
  } & VaultV1MigrateToV2AmountArgs) => ActionOutput<VaultV1MigrateToV2Action, readonly RequirementSignature[], undefined>;
416
422
  }
423
+ /** Binds a viem client to a Vault V1 (MetaMorpho) vault's action builders. */
417
424
  export declare class MorphoVaultV1 implements VaultV1Actions {
418
425
  private readonly client;
419
426
  private readonly vault;
@@ -10,6 +10,7 @@ import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } fro
10
10
  import { AmountAndSharesExclusiveError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
11
11
  import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
12
12
  import { getBundlesTokenRequirements } from "../requirements/index.js";
13
+ /** Binds a viem client to a Vault V1 (MetaMorpho) vault's action builders. */
13
14
  export class MorphoVaultV1 {
14
15
  client;
15
16
  vault;
@@ -3,15 +3,24 @@ import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
5
  import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type Deallocation, type MorphoClientType, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2InKindRedeemAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
6
+ /**
7
+ * Action surface for Vault V2 reads and writes; writes route through VaultBundlesV1 and
8
+ * VaultExitBundlesV1, except `forceRedeem`, which uses the vault's native multicall.
9
+ */
6
10
  export interface VaultV2Actions {
7
11
  /**
8
- * Fetches the latest vault data.
12
+ * Fetches the latest accrual snapshot of the vault.
9
13
  *
10
- * This function fetches the latest vault data from the blockchain.
11
- * @param {FetchParameters} [parameters] - The parameters for the fetch operation.
14
+ * Reads the Vault V2 state through `fetchAccrualVaultV2` on the entity's client.
12
15
  *
13
- * @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>} The latest vault data.
16
+ * @param parameters - Optional viem fetch parameters (block number, block tag, state override).
17
+ * @returns The hydrated `AccrualVaultV2` snapshot.
14
18
  * @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
19
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
20
+ * @throws {UnknownBlueFactory} when the configured chain has no VaultV2 factory.
21
+ * @throws {UnknownBlueOfFactory} when the vault is not a VaultV2 from the configured factory.
22
+ * @throws {UnsupportedBlueVaultV2AdapterError} when the vault or one of its adapters uses an
23
+ * unsupported adapter class.
15
24
  */
16
25
  getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
17
26
  /**
@@ -463,13 +472,27 @@ export interface VaultV2Actions {
463
472
  * asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated
464
473
  * amounts to account for share-price drift between submission and execution.
465
474
  *
466
- * @param {Object} params - The force redeem parameters.
467
- * @param {readonly Deallocation[]} params.deallocations - The typed list of deallocations to perform.
468
- * @param {Object} params.redeem - The redeem parameters applied after deallocations.
469
- * @param {bigint} params.redeem.shares - The amount of shares to redeem.
470
- * @param {Address} params.userAddress - User address (penalty source and redeem recipient).
471
- * @returns {Object} The result object.
472
- * @returns {Readonly<Transaction<VaultV2ForceRedeemAction>>} returns.buildTx The prepared multicall transaction.
475
+ * @param params.deallocations - Typed list of `forceDeallocate` calls to perform before the redeem.
476
+ * @param params.redeem.shares - Amount of vault shares to redeem after the deallocations.
477
+ * @param params.userAddress - Account that pays the deallocation penalties and receives the redeemed assets.
478
+ * @returns An object whose `buildTx()` returns a deep-frozen `Transaction<VaultV2ForceRedeemAction>`
479
+ * encoding the vault `multicall`.
480
+ * @throws {ChainIdMismatchError} when the connected client targets another chain or has no chain.
481
+ * @throws {EmptyDeallocationsError} from `buildTx()` when `deallocations` is empty.
482
+ * @throws {NonPositiveInputError} from `buildTx()` when `redeem.shares <= 0n` or any deallocation
483
+ * amount is non-positive.
484
+ * @example
485
+ * ```ts
486
+ * const vault = client.morpho.vaultV2(vaultAddress, 1);
487
+ * const tx = vault
488
+ * .forceRedeem({
489
+ * deallocations: [{ adapter, marketParams, amount: 1_000_000n }],
490
+ * redeem: { shares: 500_000n },
491
+ * userAddress,
492
+ * })
493
+ * .buildTx();
494
+ * // tx satisfies Readonly<Transaction<VaultV2ForceRedeemAction>>
495
+ * ```
473
496
  */
474
497
  forceRedeem: (params: {
475
498
  deallocations: readonly Deallocation[];
@@ -481,6 +504,7 @@ export interface VaultV2Actions {
481
504
  buildTx: () => Readonly<Transaction<VaultV2ForceRedeemAction>>;
482
505
  };
483
506
  }
507
+ /** Binds a viem client to a Vault V2 vault's action builders. */
484
508
  export declare class MorphoVaultV2 implements VaultV2Actions {
485
509
  private readonly client;
486
510
  private readonly vault;
@@ -13,6 +13,7 @@ import { getBundlesTokenRequirements } from "../requirements/index.js";
13
13
  // Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
14
14
  // accrual model stays well-defined inside it.
15
15
  const VAULT_V2_FEE_PROJECTION_HORIZON = Time.s.from.y(1n);
16
+ /** Binds a viem client to a Vault V2 vault's action builders. */
16
17
  export class MorphoVaultV2 {
17
18
  client;
18
19
  vault;
@@ -2,6 +2,6 @@ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as I
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
4
  export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
6
  export type { ErrorClass } from "@morpho-org/morpho-ts";
7
7
  export { _try, DivisionByZeroError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
package/lib/esm/errors.js CHANGED
@@ -2,5 +2,5 @@ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as I
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
4
  export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
6
  export { _try, DivisionByZeroError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
@@ -94,14 +94,18 @@ export interface VaultV2ForceWithdrawPreview {
94
94
  * floor cannot fit `uint256`.
95
95
  * @example
96
96
  * ```ts
97
+ * import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
97
98
  * import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
98
99
  *
99
- * const preview = previewVaultV2ForceWithdraw(vaultData, {
100
- * requestedExitAssets: 1_000_000n,
101
- * timestamp: block.timestamp,
102
- * });
103
- * // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
104
- * // preview?.netAssets is what the user receives
100
+ * export function preview(vaultData: AccrualVaultV2, timestamp: bigint) {
101
+ * const preview = previewVaultV2ForceWithdraw(vaultData, {
102
+ * requestedExitAssets: 1_000_000n,
103
+ * timestamp,
104
+ * });
105
+ * // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
106
+ * // preview?.netAssets is what the user receives
107
+ * return preview;
108
+ * }
105
109
  * ```
106
110
  */
107
111
  export declare function previewVaultV2ForceWithdraw(vaultData: AccrualVaultV2, params: PreviewVaultV2ForceWithdrawParams): VaultV2ForceWithdrawPreview | undefined;
@@ -40,14 +40,18 @@ import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdraw
40
40
  * floor cannot fit `uint256`.
41
41
  * @example
42
42
  * ```ts
43
+ * import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
43
44
  * import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
44
45
  *
45
- * const preview = previewVaultV2ForceWithdraw(vaultData, {
46
- * requestedExitAssets: 1_000_000n,
47
- * timestamp: block.timestamp,
48
- * });
49
- * // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
50
- * // preview?.netAssets is what the user receives
46
+ * export function preview(vaultData: AccrualVaultV2, timestamp: bigint) {
47
+ * const preview = previewVaultV2ForceWithdraw(vaultData, {
48
+ * requestedExitAssets: 1_000_000n,
49
+ * timestamp,
50
+ * });
51
+ * // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
52
+ * // preview?.netAssets is what the user receives
53
+ * return preview;
54
+ * }
51
55
  * ```
52
56
  */
53
57
  export function previewVaultV2ForceWithdraw(vaultData, params) {
@@ -32,10 +32,11 @@ import { type AccrualVault, AccrualVaultV2 } from "@morpho-org/blue-sdk";
32
32
  * @example
33
33
  * ```ts
34
34
  * import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
35
+ * import { DEFAULT_SLIPPAGE_TOLERANCE } from "@morpho-org/morpho-sdk/constants";
35
36
  *
36
37
  * const minSharePriceE27 = computeMinForceWithdrawSharePrice({
37
- * withdrawnAssets: plan.withdrawnAssets,
38
- * sharesBurnt,
38
+ * withdrawnAssets: 1_000_000n,
39
+ * sharesBurnt: 900_000n,
39
40
  * slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
40
41
  * });
41
42
  * ```
@@ -35,10 +35,11 @@ import { validateSlippageTolerance } from "./validate.js";
35
35
  * @example
36
36
  * ```ts
37
37
  * import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
38
+ * import { DEFAULT_SLIPPAGE_TOLERANCE } from "@morpho-org/morpho-sdk/constants";
38
39
  *
39
40
  * const minSharePriceE27 = computeMinForceWithdrawSharePrice({
40
- * withdrawnAssets: plan.withdrawnAssets,
41
- * sharesBurnt,
41
+ * withdrawnAssets: 1_000_000n,
42
+ * sharesBurnt: 900_000n,
42
43
  * slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
43
44
  * });
44
45
  * ```
@@ -176,6 +176,31 @@ export declare const validateNativeVaultAsset: (chainId: number, vaultAsset: Add
176
176
  * @param params.withdrawAmount - Amount of collateral being withdrawn.
177
177
  * @param params.lltv - The market's liquidation LTV.
178
178
  * @param params.marketId - The market identifier (for error messages).
179
+ * @returns `void` when the post-withdraw position stays within the safe LTV threshold.
180
+ * @throws {MarketIdMismatchError} when `positionData.marketId` differs from `marketId`.
181
+ * @throws {WithdrawExceedsCollateralError} when `withdrawAmount` exceeds the position's collateral.
182
+ * @throws {MissingMarketPriceError} when the position carries debt but the market has no oracle price.
183
+ * @throws {WithdrawMakesPositionUnhealthyError} when the remaining collateral cannot cover the debt
184
+ * at LLTV minus `DEFAULT_LLTV_BUFFER`.
185
+ * @example
186
+ * ```ts
187
+ * import type { AccrualPosition, MarketId } from "@morpho-org/blue-sdk";
188
+ * import { validatePositionHealthAfterWithdraw } from "@morpho-org/morpho-sdk";
189
+ *
190
+ * export function assertSafeWithdraw(
191
+ * positionData: AccrualPosition,
192
+ * withdrawAmount: bigint,
193
+ * lltv: bigint,
194
+ * marketId: MarketId,
195
+ * ): void {
196
+ * validatePositionHealthAfterWithdraw({
197
+ * positionData,
198
+ * withdrawAmount,
199
+ * lltv,
200
+ * marketId,
201
+ * });
202
+ * }
203
+ * ```
179
204
  */
180
205
  export declare const validatePositionHealthAfterWithdraw: (params: {
181
206
  positionData: AccrualPosition;
@@ -203,6 +228,21 @@ export declare const validateRepayAmount: (params: {
203
228
  * @param params.positionData - The current accrual position.
204
229
  * @param params.repayShares - The amount of shares to repay.
205
230
  * @param params.marketId - The market identifier (for error messages).
231
+ * @returns `void` when `repayShares` does not exceed the position's borrow shares.
232
+ * @throws {RepaySharesExceedDebtError} when `repayShares` exceeds the position's borrow shares.
233
+ * @example
234
+ * ```ts
235
+ * import type { AccrualPosition, MarketId } from "@morpho-org/blue-sdk";
236
+ * import { validateRepayShares } from "@morpho-org/morpho-sdk";
237
+ *
238
+ * export function assertRepayable(
239
+ * positionData: AccrualPosition,
240
+ * repayShares: bigint,
241
+ * marketId: MarketId,
242
+ * ): void {
243
+ * validateRepayShares({ positionData, repayShares, marketId });
244
+ * }
245
+ * ```
206
246
  */
207
247
  export declare const validateRepayShares: (params: {
208
248
  positionData: AccrualPosition;