@morpho-org/morpho-sdk 6.0.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) 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/blue/errors.d.ts +1 -1
  8. package/lib/cjs/blue/errors.js +2 -1
  9. package/lib/cjs/constants.d.ts +1 -1
  10. package/lib/cjs/constants.js +4 -1
  11. package/lib/cjs/entities/blue/blue.d.ts +28 -0
  12. package/lib/cjs/entities/blue/blue.js +1 -0
  13. package/lib/cjs/entities/index.d.ts +1 -1
  14. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +1 -0
  15. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -2
  16. package/lib/cjs/entities/vaultV1/vaultV1.js +2 -0
  17. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +35 -11
  18. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
  19. package/lib/cjs/errors.d.ts +2 -2
  20. package/lib/cjs/errors.js +9 -1
  21. package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
  22. package/lib/cjs/helpers/encodeDeallocation.js +1 -0
  23. package/lib/cjs/helpers/metadata.d.ts +13 -0
  24. package/lib/cjs/helpers/metadata.js +13 -0
  25. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +10 -6
  26. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -6
  27. package/lib/cjs/helpers/slippage.d.ts +3 -2
  28. package/lib/cjs/helpers/slippage.js +3 -2
  29. package/lib/cjs/helpers/validate.d.ts +40 -2
  30. package/lib/cjs/helpers/validate.js +42 -3
  31. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +94 -59
  32. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +94 -59
  33. package/lib/cjs/midnight/abis.d.ts +1 -1
  34. package/lib/cjs/midnight/abis.js +3 -1
  35. package/lib/cjs/midnight/constants.d.ts +1 -1
  36. package/lib/cjs/midnight/constants.js +4 -1
  37. package/lib/cjs/midnight/entities.d.ts +1 -1
  38. package/lib/cjs/midnight/errors.d.ts +1 -1
  39. package/lib/cjs/midnight/errors.js +7 -1
  40. package/lib/cjs/midnight/types.d.ts +1 -1
  41. package/lib/cjs/midnight/utils.d.ts +11 -1
  42. package/lib/cjs/midnight/utils.js +13 -1
  43. package/lib/cjs/types/action.d.ts +34 -0
  44. package/lib/cjs/types/action.js +10 -0
  45. package/lib/cjs/types/data.d.ts +3 -0
  46. package/lib/cjs/types/entity.d.ts +3 -0
  47. package/lib/cjs/types/metadata.d.ts +6 -0
  48. package/lib/cjs/types.d.ts +1 -1
  49. package/lib/cjs/utils.d.ts +11 -1
  50. package/lib/cjs/utils.js +14 -2
  51. package/lib/esm/abis.d.ts +1 -1
  52. package/lib/esm/abis.js +1 -1
  53. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +16 -5
  54. package/lib/esm/actions/vaultV2/forceWithdraw.js +16 -5
  55. package/lib/esm/blue/errors.d.ts +1 -1
  56. package/lib/esm/blue/errors.js +1 -1
  57. package/lib/esm/constants.d.ts +1 -1
  58. package/lib/esm/constants.js +1 -1
  59. package/lib/esm/entities/blue/blue.d.ts +28 -0
  60. package/lib/esm/entities/blue/blue.js +1 -0
  61. package/lib/esm/entities/index.d.ts +1 -1
  62. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +1 -0
  63. package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -2
  64. package/lib/esm/entities/vaultV1/vaultV1.js +2 -0
  65. package/lib/esm/entities/vaultV2/vaultV2.d.ts +35 -11
  66. package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
  67. package/lib/esm/errors.d.ts +2 -2
  68. package/lib/esm/errors.js +2 -2
  69. package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
  70. package/lib/esm/helpers/encodeDeallocation.js +1 -0
  71. package/lib/esm/helpers/metadata.d.ts +13 -0
  72. package/lib/esm/helpers/metadata.js +13 -0
  73. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +10 -6
  74. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -6
  75. package/lib/esm/helpers/slippage.d.ts +3 -2
  76. package/lib/esm/helpers/slippage.js +3 -2
  77. package/lib/esm/helpers/validate.d.ts +40 -2
  78. package/lib/esm/helpers/validate.js +41 -1
  79. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +94 -59
  80. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +94 -59
  81. package/lib/esm/midnight/abis.d.ts +1 -1
  82. package/lib/esm/midnight/abis.js +1 -1
  83. package/lib/esm/midnight/constants.d.ts +1 -1
  84. package/lib/esm/midnight/constants.js +1 -1
  85. package/lib/esm/midnight/entities.d.ts +1 -1
  86. package/lib/esm/midnight/errors.d.ts +1 -1
  87. package/lib/esm/midnight/errors.js +1 -1
  88. package/lib/esm/midnight/types.d.ts +1 -1
  89. package/lib/esm/midnight/utils.d.ts +11 -1
  90. package/lib/esm/midnight/utils.js +11 -1
  91. package/lib/esm/types/action.d.ts +34 -0
  92. package/lib/esm/types/action.js +10 -0
  93. package/lib/esm/types/data.d.ts +3 -0
  94. package/lib/esm/types/entity.d.ts +3 -0
  95. package/lib/esm/types/metadata.d.ts +6 -0
  96. package/lib/esm/types.d.ts +1 -1
  97. package/lib/esm/utils.d.ts +11 -1
  98. package/lib/esm/utils.js +11 -1
  99. package/package.json +7 -7
@@ -1,7 +1,7 @@
1
1
  export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
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
- 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";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, 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, 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
@@ -1,6 +1,6 @@
1
1
  export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
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
- 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";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, 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, 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";
@@ -7,5 +7,6 @@ import { type Deallocation } from "../types/index.js";
7
7
  * @param onBehalf - The address from which the penalty is taken (share owner).
8
8
  * @returns The ABI-encoded calldata for `VaultV2.forceDeallocate`.
9
9
  * @throws {NonPositiveInputError} when `deallocation.amount <= 0n`.
10
+ * @internal
10
11
  */
11
12
  export declare function encodeForceDeallocateCall(deallocation: Deallocation, onBehalf: Address): Hex;
@@ -21,6 +21,7 @@ function encodeDeallocateData(deallocation) {
21
21
  * @param onBehalf - The address from which the penalty is taken (share owner).
22
22
  * @returns The ABI-encoded calldata for `VaultV2.forceDeallocate`.
23
23
  * @throws {NonPositiveInputError} when `deallocation.amount <= 0n`.
24
+ * @internal
24
25
  */
25
26
  export function encodeForceDeallocateCall(deallocation, onBehalf) {
26
27
  if (deallocation.amount <= 0n) {
@@ -29,6 +29,19 @@ import type { Metadata } from "../types/index.js";
29
29
  * @returns The same `tx` object when `data` is missing, an empty string, or
30
30
  * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
31
  * with `data` containing any appended metadata. The input is never mutated.
32
+ * @example
33
+ * ```ts
34
+ * import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
35
+ * import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
36
+ * import type { Address, Hex } from "viem";
37
+ * import { mainnet } from "viem/chains";
38
+ *
39
+ * const { blue } = getChainAddresses(mainnet.id);
40
+ * const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
41
+ * const result: { to: Address; value: bigint; data: Hex } =
42
+ * addTransactionMetadata(tx, { origin: "deadbeef", timestamp: true });
43
+ * // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
44
+ * ```
32
45
  */
33
46
  export declare function addTransactionMetadata(tx: {
34
47
  data: Hex;
@@ -29,6 +29,19 @@ import { concatHex, isHex, numberToHex } from "viem";
29
29
  * @returns The same `tx` object when `data` is missing, an empty string, or
30
30
  * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
31
  * with `data` containing any appended metadata. The input is never mutated.
32
+ * @example
33
+ * ```ts
34
+ * import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
35
+ * import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
36
+ * import type { Address, Hex } from "viem";
37
+ * import { mainnet } from "viem/chains";
38
+ *
39
+ * const { blue } = getChainAddresses(mainnet.id);
40
+ * const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
41
+ * const result: { to: Address; value: bigint; data: Hex } =
42
+ * addTransactionMetadata(tx, { origin: "deadbeef", timestamp: true });
43
+ * // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
44
+ * ```
32
45
  */
33
46
  export function addTransactionMetadata(tx, metadata) {
34
47
  const { data, ..._tx } = tx;
@@ -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
  * ```
@@ -2,8 +2,6 @@ import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
2
2
  import type { MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
3
3
  import { type Address } from "viem";
4
4
  import { type VaultV2BlueReallocation } from "../types/index.js";
5
- /** @internal */
6
- export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0 | 1;
7
5
  /**
8
6
  * Rejects a `bigint` field that falls outside the unsigned 256-bit ABI range so a direct caller
9
7
  * gets the SDK's typed error instead of viem's `IntegerOutOfRangeError` at encode time. `maxUint256`
@@ -176,6 +174,31 @@ export declare const validateNativeVaultAsset: (chainId: number, vaultAsset: Add
176
174
  * @param params.withdrawAmount - Amount of collateral being withdrawn.
177
175
  * @param params.lltv - The market's liquidation LTV.
178
176
  * @param params.marketId - The market identifier (for error messages).
177
+ * @returns `void` when the post-withdraw position stays within the safe LTV threshold.
178
+ * @throws {MarketIdMismatchError} when `positionData.marketId` differs from `marketId`.
179
+ * @throws {WithdrawExceedsCollateralError} when `withdrawAmount` exceeds the position's collateral.
180
+ * @throws {MissingMarketPriceError} when the position carries debt but the market has no oracle price.
181
+ * @throws {WithdrawMakesPositionUnhealthyError} when the remaining collateral cannot cover the debt
182
+ * at LLTV minus `DEFAULT_LLTV_BUFFER`.
183
+ * @example
184
+ * ```ts
185
+ * import type { AccrualPosition, MarketId } from "@morpho-org/blue-sdk";
186
+ * import { validatePositionHealthAfterWithdraw } from "@morpho-org/morpho-sdk";
187
+ *
188
+ * export function assertSafeWithdraw(
189
+ * positionData: AccrualPosition,
190
+ * withdrawAmount: bigint,
191
+ * lltv: bigint,
192
+ * marketId: MarketId,
193
+ * ): void {
194
+ * validatePositionHealthAfterWithdraw({
195
+ * positionData,
196
+ * withdrawAmount,
197
+ * lltv,
198
+ * marketId,
199
+ * });
200
+ * }
201
+ * ```
179
202
  */
180
203
  export declare const validatePositionHealthAfterWithdraw: (params: {
181
204
  positionData: AccrualPosition;
@@ -203,6 +226,21 @@ export declare const validateRepayAmount: (params: {
203
226
  * @param params.positionData - The current accrual position.
204
227
  * @param params.repayShares - The amount of shares to repay.
205
228
  * @param params.marketId - The market identifier (for error messages).
229
+ * @returns `void` when `repayShares` does not exceed the position's borrow shares.
230
+ * @throws {RepaySharesExceedDebtError} when `repayShares` exceeds the position's borrow shares.
231
+ * @example
232
+ * ```ts
233
+ * import type { AccrualPosition, MarketId } from "@morpho-org/blue-sdk";
234
+ * import { validateRepayShares } from "@morpho-org/morpho-sdk";
235
+ *
236
+ * export function assertRepayable(
237
+ * positionData: AccrualPosition,
238
+ * repayShares: bigint,
239
+ * marketId: MarketId,
240
+ * ): void {
241
+ * validateRepayShares({ positionData, repayShares, marketId });
242
+ * }
243
+ * ```
206
244
  */
207
245
  export declare const validateRepayShares: (params: {
208
246
  positionData: AccrualPosition;
@@ -4,7 +4,7 @@ import { isAddress, isAddressEqual, maxUint128, maxUint256, zeroAddress, } from
4
4
  import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, InconsistentReallocationPenaltyError, InputExceedsMaxError, InvalidReallocationAddressError, InvalidReallocationSourceTypeError, InvalidVaultV2BlueReallocationShapeError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, ReallocationWithdrawalOnTargetMarketError, ReferralFeePctExceededError, ReferralFeeRecipientMissingError, RepayExceedsDebtError, RepaySharesExceedDebtError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
5
5
  import { DEFAULT_LLTV_BUFFER, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, } from "./constant.js";
6
6
  /** @internal */
7
- export const compareMarketIds = (idA, idB) => {
7
+ const compareMarketIds = (idA, idB) => {
8
8
  const normalizedIdA = idA.toLowerCase();
9
9
  const normalizedIdB = idB.toLowerCase();
10
10
  if (normalizedIdA > normalizedIdB)
@@ -249,6 +249,31 @@ export const validateNativeVaultAsset = (chainId, vaultAsset) => {
249
249
  * @param params.withdrawAmount - Amount of collateral being withdrawn.
250
250
  * @param params.lltv - The market's liquidation LTV.
251
251
  * @param params.marketId - The market identifier (for error messages).
252
+ * @returns `void` when the post-withdraw position stays within the safe LTV threshold.
253
+ * @throws {MarketIdMismatchError} when `positionData.marketId` differs from `marketId`.
254
+ * @throws {WithdrawExceedsCollateralError} when `withdrawAmount` exceeds the position's collateral.
255
+ * @throws {MissingMarketPriceError} when the position carries debt but the market has no oracle price.
256
+ * @throws {WithdrawMakesPositionUnhealthyError} when the remaining collateral cannot cover the debt
257
+ * at LLTV minus `DEFAULT_LLTV_BUFFER`.
258
+ * @example
259
+ * ```ts
260
+ * import type { AccrualPosition, MarketId } from "@morpho-org/blue-sdk";
261
+ * import { validatePositionHealthAfterWithdraw } from "@morpho-org/morpho-sdk";
262
+ *
263
+ * export function assertSafeWithdraw(
264
+ * positionData: AccrualPosition,
265
+ * withdrawAmount: bigint,
266
+ * lltv: bigint,
267
+ * marketId: MarketId,
268
+ * ): void {
269
+ * validatePositionHealthAfterWithdraw({
270
+ * positionData,
271
+ * withdrawAmount,
272
+ * lltv,
273
+ * marketId,
274
+ * });
275
+ * }
276
+ * ```
252
277
  */
253
278
  export const validatePositionHealthAfterWithdraw = (params) => {
254
279
  const { positionData, withdrawAmount, lltv, marketId } = params;
@@ -307,6 +332,21 @@ export const validateRepayAmount = (params) => {
307
332
  * @param params.positionData - The current accrual position.
308
333
  * @param params.repayShares - The amount of shares to repay.
309
334
  * @param params.marketId - The market identifier (for error messages).
335
+ * @returns `void` when `repayShares` does not exceed the position's borrow shares.
336
+ * @throws {RepaySharesExceedDebtError} when `repayShares` exceeds the position's borrow shares.
337
+ * @example
338
+ * ```ts
339
+ * import type { AccrualPosition, MarketId } from "@morpho-org/blue-sdk";
340
+ * import { validateRepayShares } from "@morpho-org/morpho-sdk";
341
+ *
342
+ * export function assertRepayable(
343
+ * positionData: AccrualPosition,
344
+ * repayShares: bigint,
345
+ * marketId: MarketId,
346
+ * ): void {
347
+ * validateRepayShares({ positionData, repayShares, marketId });
348
+ * }
349
+ * ```
310
350
  */
311
351
  export const validateRepayShares = (params) => {
312
352
  const { positionData, repayShares, marketId } = params;
@@ -51,11 +51,15 @@ export type VaultV2ForceWithdrawEligibility = {
51
51
  * describing which precondition failed.
52
52
  * @example
53
53
  * ```ts
54
+ * import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
54
55
  * import { resolveVaultV2ForceWithdrawEligibility } from "@morpho-org/morpho-sdk";
55
56
  *
56
- * const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData);
57
- * if (eligibility.type === "eligible") {
58
- * console.log(eligibility.adapter.address, eligibility.liquidityMarketId);
57
+ * export function checkEligibility(vaultData: AccrualVaultV2) {
58
+ * const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData);
59
+ * if (eligibility.type === "eligible") {
60
+ * console.log(eligibility.adapter.address, eligibility.liquidityMarketId);
61
+ * }
62
+ * return eligibility;
59
63
  * }
60
64
  * ```
61
65
  */
@@ -76,13 +80,21 @@ export declare function resolveVaultV2ForceWithdrawEligibility(vaultData: Accrua
76
80
  * owner is not a fee recipient.
77
81
  * @example
78
82
  * ```ts
83
+ * import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
79
84
  * import { computeVaultV2ForceWithdrawFeeSharesMinted } from "@morpho-org/morpho-sdk";
85
+ * import type { Address } from "viem";
80
86
  *
81
- * const feeShares = computeVaultV2ForceWithdrawFeeSharesMinted({
82
- * vaultData,
83
- * owner,
84
- * timestamp,
85
- * });
87
+ * export function feeShares(
88
+ * vaultData: AccrualVaultV2,
89
+ * owner: Address,
90
+ * timestamp: bigint,
91
+ * ) {
92
+ * return computeVaultV2ForceWithdrawFeeSharesMinted({
93
+ * vaultData,
94
+ * owner,
95
+ * timestamp,
96
+ * });
97
+ * }
86
98
  * ```
87
99
  */
88
100
  export declare function computeVaultV2ForceWithdrawFeeSharesMinted(params: {
@@ -155,21 +167,24 @@ export interface VaultV2ForceWithdrawPlan {
155
167
  * @throws {NonPositiveInputError} when `exitAssets` is not positive.
156
168
  * @example
157
169
  * ```ts
170
+ * import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
158
171
  * import {
159
172
  * computeVaultV2ForceWithdrawPlan,
160
173
  * resolveVaultV2ForceWithdrawEligibility,
161
174
  * } from "@morpho-org/morpho-sdk";
162
175
  *
163
- * const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData);
164
- * if (eligibility.type === "eligible") {
176
+ * export function planExit(vaultData: AccrualVaultV2, timestamp: bigint) {
177
+ * const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData);
178
+ * if (eligibility.type !== "eligible") return undefined;
165
179
  * const plan = computeVaultV2ForceWithdrawPlan({
166
180
  * vaultData,
167
181
  * adapter: eligibility.adapter,
168
182
  * liquidityMarketId: eligibility.liquidityMarketId,
169
183
  * exitAssets: 1_000_000n,
170
- * timestamp: 1_800_000_000n,
184
+ * timestamp,
171
185
  * });
172
186
  * // plan.withdrawnAssets is what the user receives before the referral fee
187
+ * return plan;
173
188
  * }
174
189
  * ```
175
190
  */
@@ -224,55 +239,69 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
224
239
  * @returns An upper bound, in vault shares, of what the exit burns.
225
240
  * @example
226
241
  * ```ts
227
- * import { MathLib } from "@morpho-org/blue-sdk";
242
+ * import { MathLib, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
228
243
  * import {
229
244
  * computeVaultV2ForceWithdrawFeeSharesMinted,
230
245
  * computeVaultV2ForceWithdrawSharesBurnt,
246
+ * type VaultV2ForceWithdrawPlan,
231
247
  * } from "@morpho-org/morpho-sdk";
248
+ * import { type Address, maxUint256 } from "viem";
232
249
  *
233
- * const { vault: nowVaultData } = vaultData.accrueInterest(now);
234
- * const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
235
- * vaultData,
236
- * deadlineVaultData: vaultData,
237
- * plan,
238
- * });
239
- * const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
240
- * vaultData: nowVaultData,
241
- * deadlineVaultData: nowVaultData,
242
- * plan,
243
- * });
244
- * const feeSharesNow = computeVaultV2ForceWithdrawFeeSharesMinted({
245
- * vaultData,
246
- * owner,
247
- * timestamp: now,
248
- * });
249
- * const sharesBurntForFloor = MathLib.max(
250
- * sharesBurntRaw,
251
- * sharesBurntNow - feeSharesNow,
252
- * );
253
- * const allowanceSharePriceE27 = MathLib.max(
254
- * MathLib.min(
255
- * MathLib.mulDivDown(
256
- * minSharePriceE27,
257
- * MathLib.WAD - slippageTolerance,
258
- * MathLib.WAD,
250
+ * export function requiredShareAllowance(
251
+ * vaultData: AccrualVaultV2,
252
+ * plan: VaultV2ForceWithdrawPlan,
253
+ * owner: Address,
254
+ * now: bigint,
255
+ * deadline: bigint,
256
+ * exitAssets: bigint,
257
+ * minSharePriceE27: bigint,
258
+ * slippageTolerance: bigint,
259
+ * ) {
260
+ * const { vault: nowVaultData } = vaultData.accrueInterest(now);
261
+ * const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
262
+ * vaultData,
263
+ * deadlineVaultData: vaultData,
264
+ * plan,
265
+ * });
266
+ * const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
267
+ * vaultData: nowVaultData,
268
+ * deadlineVaultData: nowVaultData,
269
+ * plan,
270
+ * });
271
+ * const feeSharesNow = computeVaultV2ForceWithdrawFeeSharesMinted({
272
+ * vaultData,
273
+ * owner,
274
+ * timestamp: now,
275
+ * });
276
+ * const sharesBurntForFloor = MathLib.max(
277
+ * sharesBurntRaw,
278
+ * sharesBurntNow - feeSharesNow,
279
+ * );
280
+ * const allowanceSharePriceE27 = MathLib.max(
281
+ * MathLib.min(
282
+ * MathLib.mulDivDown(
283
+ * minSharePriceE27,
284
+ * MathLib.WAD - slippageTolerance,
285
+ * MathLib.WAD,
286
+ * ),
287
+ * minSharePriceE27 - 1n,
259
288
  * ),
260
- * minSharePriceE27 - 1n,
261
- * ),
262
- * 1n,
263
- * );
264
- * const requiredShareAllowance = MathLib.min(
265
- * MathLib.max(
266
- * MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27),
267
- * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n,
268
- * ) +
269
- * computeVaultV2ForceWithdrawFeeSharesMinted({
270
- * vaultData,
271
- * owner,
272
- * timestamp: deadline,
273
- * }),
274
- * maxUint256,
275
- * );
289
+ * 1n,
290
+ * );
291
+ * const requiredShareAllowance = MathLib.min(
292
+ * MathLib.max(
293
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27),
294
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n,
295
+ * ) +
296
+ * computeVaultV2ForceWithdrawFeeSharesMinted({
297
+ * vaultData,
298
+ * owner,
299
+ * timestamp: deadline,
300
+ * }),
301
+ * maxUint256,
302
+ * );
303
+ * return requiredShareAllowance;
304
+ * }
276
305
  * ```
277
306
  */
278
307
  export declare function computeVaultV2ForceWithdrawSharesBurnt(params: {
@@ -293,12 +322,18 @@ export declare function computeVaultV2ForceWithdrawSharesBurnt(params: {
293
322
  * @returns A lower bound, in vault shares, of the burn measured by the contract.
294
323
  * @example
295
324
  * ```ts
296
- * import { computeVaultV2ForceWithdrawMinSharesBurnt } from "@morpho-org/morpho-sdk";
325
+ * import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
326
+ * import {
327
+ * computeVaultV2ForceWithdrawMinSharesBurnt,
328
+ * type VaultV2ForceWithdrawPlan,
329
+ * } from "@morpho-org/morpho-sdk";
297
330
  *
298
- * const minSharesBurnt = computeVaultV2ForceWithdrawMinSharesBurnt({
299
- * vaultData,
300
- * plan,
301
- * });
331
+ * export function minSharesBurnt(
332
+ * vaultData: AccrualVaultV2,
333
+ * plan: VaultV2ForceWithdrawPlan,
334
+ * ) {
335
+ * return computeVaultV2ForceWithdrawMinSharesBurnt({ vaultData, plan });
336
+ * }
302
337
  * ```
303
338
  */
304
339
  export declare function computeVaultV2ForceWithdrawMinSharesBurnt(params: {