@morpho-org/morpho-sdk 9.1.0-next.0 → 9.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 (154) hide show
  1. package/README.md +7 -1
  2. package/lib/cjs/abis.d.ts +2 -2
  3. package/lib/cjs/abis.js +3 -5
  4. package/lib/cjs/actions/blue/borrow.d.ts +1 -0
  5. package/lib/cjs/actions/blue/borrow.js +1 -0
  6. package/lib/cjs/actions/blue/refinance.d.ts +1 -0
  7. package/lib/cjs/actions/blue/refinance.js +3 -0
  8. package/lib/cjs/actions/blue/repay.d.ts +1 -0
  9. package/lib/cjs/actions/blue/repay.js +1 -0
  10. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -0
  12. package/lib/cjs/actions/blue/supply.d.ts +1 -0
  13. package/lib/cjs/actions/blue/supply.js +2 -0
  14. package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -0
  15. package/lib/cjs/actions/blue/supplyCollateral.js +1 -0
  16. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  17. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +2 -0
  18. package/lib/cjs/actions/blue/withdraw.d.ts +1 -0
  19. package/lib/cjs/actions/blue/withdraw.js +2 -0
  20. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -0
  21. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -0
  22. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  23. package/lib/cjs/actions/midnight/takeLend.js +1 -0
  24. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  25. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  26. package/lib/cjs/blue/abis.d.ts +1 -1
  27. package/lib/cjs/blue/abis.js +1 -5
  28. package/lib/cjs/blue/constants.d.ts +1 -1
  29. package/lib/cjs/blue/constants.js +2 -1
  30. package/lib/cjs/blue/entities.d.ts +4 -4
  31. package/lib/cjs/blue/entities.js +1 -3
  32. package/lib/cjs/blue/errors.d.ts +2 -2
  33. package/lib/cjs/blue/errors.js +2 -5
  34. package/lib/cjs/blue/fetch.d.ts +2 -2
  35. package/lib/cjs/blue/fetch.js +1 -3
  36. package/lib/cjs/blue/utils.d.ts +1 -1
  37. package/lib/cjs/blue/utils.js +1 -2
  38. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  39. package/lib/cjs/client/morphoViemExtension.js +1 -7
  40. package/lib/cjs/constants.d.ts +2 -2
  41. package/lib/cjs/constants.js +4 -1
  42. package/lib/cjs/entities/blue/blue.d.ts +112 -21
  43. package/lib/cjs/entities/blue/blue.js +58 -6
  44. package/lib/cjs/entities/index.d.ts +4 -4
  45. package/lib/cjs/entities/index.js +1 -3
  46. package/lib/cjs/entities/midnight/midnight.d.ts +9 -6
  47. package/lib/cjs/entities/midnight/midnight.js +12 -9
  48. package/lib/cjs/entities/midnight/types.d.ts +8 -1
  49. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +8 -0
  50. package/lib/cjs/entities/vaultV1/vaultV1.js +5 -0
  51. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -34
  52. package/lib/cjs/entities/vaultV2/vaultV2.js +12 -38
  53. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +77 -19
  54. package/lib/cjs/entities/vaultV2BlueReallocationData.js +376 -80
  55. package/lib/cjs/errors.d.ts +4 -4
  56. package/lib/cjs/errors.js +6 -10
  57. package/lib/cjs/fetch.d.ts +2 -2
  58. package/lib/cjs/fetch.js +1 -3
  59. package/lib/cjs/helpers/constant.d.ts +7 -0
  60. package/lib/cjs/helpers/constant.js +8 -1
  61. package/lib/cjs/helpers/deadShares.d.ts +82 -0
  62. package/lib/cjs/helpers/deadShares.js +200 -0
  63. package/lib/cjs/helpers/index.d.ts +2 -1
  64. package/lib/cjs/helpers/index.js +7 -1
  65. package/lib/cjs/helpers/validate.d.ts +11 -1
  66. package/lib/cjs/helpers/validate.js +17 -1
  67. package/lib/cjs/helpers/validateTakeableOffers.d.ts +4 -2
  68. package/lib/cjs/helpers/validateTakeableOffers.js +12 -1
  69. package/lib/cjs/midnight/abis.d.ts +1 -1
  70. package/lib/cjs/midnight/abis.js +3 -1
  71. package/lib/cjs/midnight/errors.d.ts +1 -2
  72. package/lib/cjs/midnight/errors.js +4 -5
  73. package/lib/cjs/types/error.d.ts +60 -5
  74. package/lib/cjs/types/error.js +68 -6
  75. package/lib/cjs/types/sharedLiquidity.d.ts +31 -11
  76. package/lib/cjs/utils.d.ts +2 -2
  77. package/lib/cjs/utils.js +2 -4
  78. package/lib/esm/abis.d.ts +2 -2
  79. package/lib/esm/abis.js +2 -2
  80. package/lib/esm/actions/blue/borrow.d.ts +1 -0
  81. package/lib/esm/actions/blue/borrow.js +1 -0
  82. package/lib/esm/actions/blue/refinance.d.ts +1 -0
  83. package/lib/esm/actions/blue/refinance.js +4 -1
  84. package/lib/esm/actions/blue/repay.d.ts +1 -0
  85. package/lib/esm/actions/blue/repay.js +1 -0
  86. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  87. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -1
  88. package/lib/esm/actions/blue/supply.d.ts +1 -0
  89. package/lib/esm/actions/blue/supply.js +3 -1
  90. package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -0
  91. package/lib/esm/actions/blue/supplyCollateral.js +1 -0
  92. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  93. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -1
  94. package/lib/esm/actions/blue/withdraw.d.ts +1 -0
  95. package/lib/esm/actions/blue/withdraw.js +3 -1
  96. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -0
  97. package/lib/esm/actions/blue/withdrawCollateral.js +1 -0
  98. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  99. package/lib/esm/actions/midnight/takeLend.js +1 -0
  100. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  101. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  102. package/lib/esm/blue/abis.d.ts +1 -1
  103. package/lib/esm/blue/abis.js +1 -1
  104. package/lib/esm/blue/constants.d.ts +1 -1
  105. package/lib/esm/blue/constants.js +1 -1
  106. package/lib/esm/blue/entities.d.ts +4 -4
  107. package/lib/esm/blue/entities.js +2 -2
  108. package/lib/esm/blue/errors.d.ts +2 -2
  109. package/lib/esm/blue/errors.js +2 -2
  110. package/lib/esm/blue/fetch.d.ts +2 -2
  111. package/lib/esm/blue/fetch.js +2 -2
  112. package/lib/esm/blue/utils.d.ts +1 -1
  113. package/lib/esm/blue/utils.js +1 -1
  114. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  115. package/lib/esm/client/morphoViemExtension.js +1 -7
  116. package/lib/esm/constants.d.ts +2 -2
  117. package/lib/esm/constants.js +2 -2
  118. package/lib/esm/entities/blue/blue.d.ts +112 -21
  119. package/lib/esm/entities/blue/blue.js +60 -8
  120. package/lib/esm/entities/index.d.ts +4 -4
  121. package/lib/esm/entities/index.js +2 -2
  122. package/lib/esm/entities/midnight/midnight.d.ts +9 -6
  123. package/lib/esm/entities/midnight/midnight.js +13 -10
  124. package/lib/esm/entities/midnight/types.d.ts +8 -1
  125. package/lib/esm/entities/vaultV1/vaultV1.d.ts +8 -0
  126. package/lib/esm/entities/vaultV1/vaultV1.js +5 -0
  127. package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -34
  128. package/lib/esm/entities/vaultV2/vaultV2.js +13 -39
  129. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +77 -19
  130. package/lib/esm/entities/vaultV2BlueReallocationData.js +377 -81
  131. package/lib/esm/errors.d.ts +4 -4
  132. package/lib/esm/errors.js +4 -4
  133. package/lib/esm/fetch.d.ts +2 -2
  134. package/lib/esm/fetch.js +2 -2
  135. package/lib/esm/helpers/constant.d.ts +7 -0
  136. package/lib/esm/helpers/constant.js +7 -0
  137. package/lib/esm/helpers/deadShares.d.ts +82 -0
  138. package/lib/esm/helpers/deadShares.js +195 -0
  139. package/lib/esm/helpers/index.d.ts +2 -1
  140. package/lib/esm/helpers/index.js +2 -1
  141. package/lib/esm/helpers/validate.d.ts +11 -1
  142. package/lib/esm/helpers/validate.js +15 -0
  143. package/lib/esm/helpers/validateTakeableOffers.d.ts +4 -2
  144. package/lib/esm/helpers/validateTakeableOffers.js +13 -2
  145. package/lib/esm/midnight/abis.d.ts +1 -1
  146. package/lib/esm/midnight/abis.js +1 -1
  147. package/lib/esm/midnight/errors.d.ts +1 -2
  148. package/lib/esm/midnight/errors.js +1 -2
  149. package/lib/esm/types/error.d.ts +60 -5
  150. package/lib/esm/types/error.js +64 -5
  151. package/lib/esm/types/sharedLiquidity.d.ts +31 -11
  152. package/lib/esm/utils.d.ts +2 -2
  153. package/lib/esm/utils.js +2 -2
  154. package/package.json +9 -8
@@ -51,6 +51,7 @@ export interface BlueWithdrawParams {
51
51
  * @param params.metadata - Optional transaction metadata.
52
52
  * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawAction>>` whose `to` address is
53
53
  * BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
54
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
54
55
  * @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
55
56
  * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
56
57
  * @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
@@ -1,6 +1,6 @@
1
1
  import { encodeFunctionData } from "viem";
2
2
  import { blueBundlesV1Abi } from "../../abis.js";
3
- import { validateUint256Field } from "../../helpers/validate.js";
3
+ import { validateMarketParamsId, validateUint256Field, } from "../../helpers/validate.js";
4
4
  import { InputExceedsMaxError, MutuallyExclusiveWithdrawAmountsError, NonPositiveInputError, } from "../../types/index.js";
5
5
  import { getBundlesReferralFeeAssets } from "../bundles/common.js";
6
6
  import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1SignedAuthorization, normalizeBlueBundlesV1CommonParams, } from "./common.js";
@@ -25,6 +25,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
25
25
  * @param params.metadata - Optional transaction metadata.
26
26
  * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawAction>>` whose `to` address is
27
27
  * BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
28
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
28
29
  * @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
29
30
  * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
30
31
  * @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
@@ -63,6 +64,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
63
64
  */
64
65
  export const blueWithdraw = (params) => {
65
66
  const { chainId, marketParams } = params.market;
67
+ validateMarketParamsId(marketParams);
66
68
  const { userAddress, withdrawAssets, withdrawShares, authorizationSignature, } = params.args;
67
69
  validateUint256Field("withdrawAssets", withdrawAssets);
68
70
  validateUint256Field("withdrawShares", withdrawShares);
@@ -47,6 +47,7 @@ export interface BlueWithdrawCollateralParams {
47
47
  * @param params.metadata - Optional transaction metadata.
48
48
  * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawCollateralAction>>` whose calldata
49
49
  * invokes the combined BlueBundlesV1 entrypoint with a zero repay leg.
50
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
50
51
  * @throws {NegativeInputError} when collateral, LTV, or fee is negative.
51
52
  * @throws {NonPositiveInputError} when collateral or deadline is not positive.
52
53
  * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
@@ -19,6 +19,7 @@ import { blueRepayWithdrawCollateral } from "./repayWithdrawCollateral.js";
19
19
  * @param params.metadata - Optional transaction metadata.
20
20
  * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawCollateralAction>>` whose calldata
21
21
  * invokes the combined BlueBundlesV1 entrypoint with a zero repay leg.
22
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
22
23
  * @throws {NegativeInputError} when collateral, LTV, or fee is negative.
23
24
  * @throws {NonPositiveInputError} when collateral or deadline is not positive.
24
25
  * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
@@ -51,6 +51,7 @@ export interface MidnightTakeLendParams extends MidnightReferralFeeParams {
51
51
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
52
52
  * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
53
53
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
54
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
54
55
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or `deadline` is not positive.
55
56
  * @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`,
56
57
  * `referralFeePct` or `nativeAmount` is negative.
@@ -40,6 +40,7 @@ import { NonPositiveInputError, UnboundedMidnightTakeInputError, } from "../../t
40
40
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
41
41
  * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
42
42
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
43
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
43
44
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or `deadline` is not positive.
44
45
  * @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`,
45
46
  * `referralFeePct` or `nativeAmount` is negative.
@@ -70,6 +70,7 @@ export interface MidnightTakeRepayWithdrawCollateralParams extends MidnightRefer
70
70
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
71
71
  * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
72
72
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
73
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
73
74
  * @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
74
75
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets`, a
75
76
  * withdrawal amount or `deadline` is not positive.
@@ -52,6 +52,7 @@ import { NonPositiveInputError, UnboundedMidnightTakeInputError, } from "../../t
52
52
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
53
53
  * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
54
54
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
55
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
55
56
  * @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
56
57
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets`, a
57
58
  * withdrawal amount or `deadline` is not positive.
@@ -1,5 +1,5 @@
1
1
  export { marketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
2
+ export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
3
3
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
4
  preLiquidationAbi,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
@@ -1,5 +1,5 @@
1
1
  export { marketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
2
+ export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
3
3
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
4
  preLiquidationAbi,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
@@ -1 +1 @@
1
- export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
1
+ export { DEAD_ADDRESS, DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
@@ -1 +1 @@
1
- export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
1
+ export { DEAD_ADDRESS, DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
@@ -1,10 +1,10 @@
1
- export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MidnightAdapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition,
1
+ export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  IPreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MidnightAdapter, IVaultV2MidnightAdapterAccrualMarket, IVaultV2MidnightAdapterCollateralParams, IVaultV2MidnightAdapterMarket, IVaultV2MidnightAdapterMarketData, IVaultV2MidnightAdapterMarketState, IVaultV2MidnightAdapterPosition, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultV2MidnightAdapterAccrualMarket, VaultV2MidnightAdapterMarketData, } from "@morpho-org/blue-sdk";
6
- export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position,
5
+ IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
6
+ export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position,
7
7
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
8
8
  PreLiquidationParams,
9
9
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
10
- PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MidnightAdapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
10
+ PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
@@ -1,5 +1,5 @@
1
- export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position,
1
+ export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  PreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MidnightAdapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
5
+ PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
@@ -1,4 +1,4 @@
1
- export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, InvalidPositionAccrualStateError, InvalidPositionLossFactorError, InvalidVaultV2MidnightAdapterMarketsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
1
+ export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
4
+ export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
@@ -1,4 +1,4 @@
1
- export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, InvalidPositionAccrualStateError, InvalidPositionLossFactorError, InvalidVaultV2MidnightAdapterMarketsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
1
+ export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
4
+ export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
@@ -1,5 +1,5 @@
1
- export { fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket, fetchMarketParams, fetchPosition,
1
+ export { fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket, fetchMarketParams, fetchPosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition, fetchToken, fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition, fetchToken, fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
@@ -1,5 +1,5 @@
1
- export { fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket, fetchMarketParams, fetchPosition,
1
+ export { fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket, fetchMarketParams, fetchPosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition, fetchToken, fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition, fetchToken, fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
@@ -3,5 +3,5 @@ export { AdaptiveCurveIrmLib, CapacityLimitReason,
3
3
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
4
  defaultPreLiquidationParamsRegistry,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
- getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2MidnightAdapterUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
6
+ getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
7
7
  export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
@@ -2,5 +2,5 @@ export { AdaptiveCurveIrmLib, CapacityLimitReason,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  defaultPreLiquidationParamsRegistry,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2MidnightAdapterUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
5
+ getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
6
6
  export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
@@ -1,5 +1,5 @@
1
1
  import type { Client } from "viem";
2
- import { type Metadata, type MorphoClientType } from "../types/index.js";
2
+ import type { Metadata, MorphoClientType } from "../types/index.js";
3
3
  /**
4
4
  * Returns a viem `extend(...)` function that adds a stateless `morpho` namespace to a viem client.
5
5
  * The namespace rides on top of the same client (one transport / chain / account) and exposes the
@@ -1,7 +1,5 @@
1
- import { MarketUtils } from "@morpho-org/blue-sdk";
2
1
  import { deepFreeze } from "@morpho-org/morpho-ts";
3
2
  import { MorphoBlue, MorphoMidnight, MorphoVaultV1, MorphoVaultV2, } from "../entities/index.js";
4
- import { MarketIdMismatchError, } from "../types/index.js";
5
3
  /**
6
4
  * Builds the stateless `morpho` namespace exposed on an extended viem client. Wraps the supplied
7
5
  * viem `Client` plus a frozen options bag and exposes factory methods for the protocol entities.
@@ -27,11 +25,7 @@ function createMorphoNamespace(viemClient, options) {
27
25
  return new MorphoVaultV2(namespace, vault, chainId);
28
26
  },
29
27
  blue(marketParams, chainId) {
30
- const derivedId = MarketUtils.getMarketId(marketParams);
31
- // Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
32
- if (marketParams.id !== derivedId) {
33
- throw new MarketIdMismatchError(marketParams.id, derivedId);
34
- }
28
+ // The constructor rejects one-time/hardcoded/agent-written market params whose id does not hash from the tuple.
35
29
  return new MorphoBlue(namespace, marketParams, chainId);
36
30
  },
37
31
  midnight(chainId) {
@@ -1,4 +1,4 @@
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";
1
+ export { DEAD_ADDRESS, 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
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
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, 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, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./helpers/constant.js";
4
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, 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, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./helpers/constant.js";
@@ -1,4 +1,4 @@
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";
1
+ export { DEAD_ADDRESS, 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
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
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, 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, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./helpers/constant.js";
4
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, 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, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./helpers/constant.js";
@@ -9,6 +9,10 @@ type VaultV2BlueReallocationsParams = {
9
9
  readonly operation?: {
10
10
  readonly type: "borrow" | "withdraw";
11
11
  readonly amount: bigint;
12
+ } | {
13
+ readonly type: "refinance";
14
+ readonly amount: bigint;
15
+ readonly referralFeePct?: bigint;
12
16
  };
13
17
  };
14
18
  };
@@ -146,6 +150,8 @@ export interface BlueActions {
146
150
  * share-price bound or `slippageTolerance`.
147
151
  *
148
152
  * @param params.userAddress - User funding and receiving the supply position.
153
+ * @param params.marketData - Snapshot of this market from `getMarketData()` (or `fetchMarket` in
154
+ * `@morpho-org/blue-sdk-viem`), used to check its dead deposit before building.
149
155
  * @param params.assets - Gross loan-token assets funded before the referral fee.
150
156
  * @param params.nativeAmount - Optional full native funding; must equal `assets` and requires wNative.
151
157
  * @param params.deadline - Final call deadline in Unix seconds.
@@ -173,6 +179,9 @@ export interface BlueActions {
173
179
  * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when a signature cannot be encoded safely.
174
180
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
175
181
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
182
+ * @throws {MarketIdMismatchError} when `marketData` belongs to another market.
183
+ * @throws {MissingDeadSharesDataError} when `marketData` has no `deadSupplyShares`.
184
+ * @throws {InsufficientDeadSharesError} when the market holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
176
185
  * @throws {UnknownTokenError} from `getRequirements()` when the funded token's `decimals()` is unusable.
177
186
  * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
178
187
  * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
@@ -194,6 +203,7 @@ export interface BlueActions {
194
203
  * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
195
204
  * const action = market.supply({
196
205
  * userAddress,
206
+ * marketData: await market.getMarketData(),
197
207
  * assets: 1_000_000n,
198
208
  * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
199
209
  * });
@@ -202,14 +212,29 @@ export interface BlueActions {
202
212
  * // tx satisfies Readonly<Transaction<BlueSupplyAction>>
203
213
  * ```
204
214
  */
205
- supply: (params: {
206
- readonly userAddress: Address;
207
- readonly assets: bigint;
208
- readonly nativeAmount?: bigint;
209
- readonly deadline: bigint;
210
- readonly referralFeePct?: bigint;
211
- readonly referralFeeRecipient?: Address;
212
- }) => ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
215
+ supply: {
216
+ (params: {
217
+ readonly userAddress: Address;
218
+ readonly marketData: Market;
219
+ readonly assets: bigint;
220
+ readonly nativeAmount?: bigint;
221
+ readonly deadline: bigint;
222
+ readonly referralFeePct?: bigint;
223
+ readonly referralFeeRecipient?: Address;
224
+ }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
225
+ /**
226
+ * @deprecated Pass `marketData` from `getMarketData()` to check the dead deposit.
227
+ * Snapshot-free supply is unprotected and will be removed in the next major after one minor.
228
+ */
229
+ (params: {
230
+ readonly userAddress: Address;
231
+ readonly assets: bigint;
232
+ readonly nativeAmount?: bigint;
233
+ readonly deadline: bigint;
234
+ readonly referralFeePct?: bigint;
235
+ readonly referralFeeRecipient?: Address;
236
+ }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
237
+ };
213
238
  /**
214
239
  * Prepares a direct BlueBundlesV1 loan-asset withdrawal by assets or shares.
215
240
  *
@@ -764,7 +789,7 @@ export interface BlueActions {
764
789
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
765
790
  * @throws {UnsupportedBlueMarketIrmError} when positive source or destination debt requires an unsupported IRM projection.
766
791
  * @throws {MissingAccrualPositionError} when either position snapshot is absent at runtime.
767
- * @throws {MarketIdMismatchError} when a position snapshot belongs to another market.
792
+ * @throws {MarketIdMismatchError} when `destination.marketParams.id` does not hash from its tuple fields, or a position snapshot belongs to another market.
768
793
  * @throws {AccrualPositionUserMismatchError} when a position snapshot belongs to another user.
769
794
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
770
795
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
@@ -842,10 +867,20 @@ export interface BlueActions {
842
867
  *
843
868
  * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
844
869
  * vault's BluePublicAllocator permissions and allocation caps at one block.
870
+ * The snapshot keeps the fetched block's timestamp as its default planning time.
871
+ * It always records Blue's loan-token balance in `blueBalances` at that
872
+ * block, so balance-based rejection applies to plans from this fetcher.
873
+ * Sizing has zero margin over that snapshot balance; activity on other Blue
874
+ * markets with the same loan token can make a plan revert. Refetch close to
875
+ * submission; there is no balance-buffer option.
876
+ * Hand-built data without a balance uses summed snapshot-market liquidity
877
+ * only to size plans and may add about the penalty in extra paid assets.
845
878
  *
846
879
  * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
847
880
  * @param params.block.number - Block number used for every RPC read.
848
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
881
+ * @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
882
+ * planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
883
+ * `lastUpdate`. An explicit `options.timestamp` is used as given.
849
884
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
850
885
  * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
851
886
  * chain via `eth_chainId`.
@@ -878,14 +913,28 @@ export interface BlueActions {
878
913
  * persist across every leg of a plan. Operation plans keep
879
914
  * `allocatorCapHeadroom` (1% of the cap by default) free under each target
880
915
  * BluePublicAllocator cap unless the operation shortfall needs it.
916
+ * With an explicit `blueBalances` value, plans are rejected when Blue cannot
917
+ * fund the penalty flash loan, an earlier market-sourced withdrawal, or the
918
+ * final transfer. A missing balance uses summed snapshot-market liquidity
919
+ * only to size plans and may make them larger; it cannot cause a balance-based
920
+ * rejection.
921
+ * For `refinance`, compute the plan on the destination-market handle (for
922
+ * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
923
+ * source-market handle. Pass the source position's `borrowAssets` accrued to
924
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
925
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
926
+ * The planner includes the referral fee and its own planned allocator-leg
927
+ * penalties in destination debt. Refinance never uses vaults with a 100%
928
+ * penalty.
881
929
  *
882
930
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
883
931
  * @param params.options - Optional allocator discovery controls and operation to support.
884
932
  * @returns Action-ready reallocations and their post-simulation state.
885
933
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
886
934
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
887
- * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
888
- * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
935
+ * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
936
+ * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD, or a selected borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
937
+ * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
889
938
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
890
939
  * @throws {UnknownReallocationMarketError} when a required market is absent.
891
940
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -895,7 +944,7 @@ export interface BlueActions {
895
944
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
896
945
  * @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
897
946
  * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
898
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
947
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the operation shortfall or refinance penalties, or an explicit Blue balance cannot fund a required transfer.
899
948
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
900
949
  * @example
901
950
  * ```ts
@@ -915,6 +964,14 @@ export declare class MorphoBlue implements BlueActions {
915
964
  private readonly client;
916
965
  readonly marketParams: MarketParams;
917
966
  private readonly chainId;
967
+ /**
968
+ * Binds `client` to the market described by `marketParams` on `chainId`.
969
+ *
970
+ * @param client - Morpho client used for reads and requirement lookups.
971
+ * @param marketParams - Market params whose `id` must hash from their five tuple fields.
972
+ * @param chainId - Chain the market lives on.
973
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
974
+ */
918
975
  constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
919
976
  private validateDeadline;
920
977
  private validateWriteCommon;
@@ -937,15 +994,25 @@ export declare class MorphoBlue implements BlueActions {
937
994
  /** {@inheritDoc BlueActions.supply} */
938
995
  supply(params: {
939
996
  readonly userAddress: Address;
997
+ readonly marketData: Market;
940
998
  readonly assets: bigint;
941
999
  readonly nativeAmount?: bigint;
942
1000
  readonly deadline: bigint;
943
1001
  readonly referralFeePct?: bigint;
944
1002
  readonly referralFeeRecipient?: Address;
945
- }): {
946
- getRequirements: (requirementsParams?: BlueTokenRequirementsParams) => Promise<readonly ActionRequirement[]>;
947
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../types/action.js").Transaction<BlueSupplyAction>>;
948
- };
1003
+ }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1004
+ /**
1005
+ * @deprecated Pass `marketData` from `getMarketData()` to check the dead deposit.
1006
+ * Snapshot-free supply is unprotected and will be removed in the next major after one minor.
1007
+ */
1008
+ supply(params: {
1009
+ readonly userAddress: Address;
1010
+ readonly assets: bigint;
1011
+ readonly nativeAmount?: bigint;
1012
+ readonly deadline: bigint;
1013
+ readonly referralFeePct?: bigint;
1014
+ readonly referralFeeRecipient?: Address;
1015
+ }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
949
1016
  /** {@inheritDoc BlueActions.withdraw} */
950
1017
  withdraw(params: {
951
1018
  readonly userAddress: Address;
@@ -1059,10 +1126,20 @@ export declare class MorphoBlue implements BlueActions {
1059
1126
  *
1060
1127
  * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
1061
1128
  * vault's BluePublicAllocator permissions and allocation caps at one block.
1129
+ * The snapshot keeps the fetched block's timestamp as its default planning time.
1130
+ * It always records Blue's loan-token balance in `blueBalances` at that
1131
+ * block, so balance-based rejection applies to plans from this fetcher.
1132
+ * Sizing has zero margin over that snapshot balance; activity on other Blue
1133
+ * markets with the same loan token can make a plan revert. Refetch close to
1134
+ * submission; there is no balance-buffer option.
1135
+ * Hand-built data without a balance uses summed snapshot-market liquidity
1136
+ * only to size plans and may add about the penalty in extra paid assets.
1062
1137
  *
1063
1138
  * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
1064
1139
  * @param params.block.number - Block number used for every RPC read.
1065
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
1140
+ * @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
1141
+ * planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
1142
+ * `lastUpdate`. An explicit `options.timestamp` is used as given.
1066
1143
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
1067
1144
  * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
1068
1145
  * chain via `eth_chainId`.
@@ -1114,14 +1191,28 @@ export declare class MorphoBlue implements BlueActions {
1114
1191
  * persist across every leg of a plan. Operation plans keep
1115
1192
  * `allocatorCapHeadroom` (1% of the cap by default) free under each target
1116
1193
  * BluePublicAllocator cap unless the operation shortfall needs it.
1194
+ * With an explicit `blueBalances` value, plans are rejected when Blue cannot
1195
+ * fund the penalty flash loan, an earlier market-sourced withdrawal, or the
1196
+ * final transfer. A missing balance uses summed snapshot-market liquidity
1197
+ * only to size plans and may make them larger; it cannot cause a balance-based
1198
+ * rejection.
1199
+ * For `refinance`, compute the plan on the destination-market handle (for
1200
+ * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
1201
+ * source-market handle. Pass the source position's `borrowAssets` accrued to
1202
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
1203
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
1204
+ * The planner includes the referral fee and its own planned allocator-leg
1205
+ * penalties in destination debt. Refinance never uses vaults with a 100%
1206
+ * penalty.
1117
1207
  *
1118
1208
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
1119
1209
  * @param params.options - Optional allocator discovery controls and operation to support.
1120
1210
  * @returns Action-ready reallocations and their post-simulation state.
1121
1211
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
1122
1212
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1123
- * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
1124
- * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
1213
+ * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
1214
+ * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD, or a selected borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
1215
+ * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
1125
1216
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
1126
1217
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1127
1218
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1131,7 +1222,7 @@ export declare class MorphoBlue implements BlueActions {
1131
1222
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
1132
1223
  * @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
1133
1224
  * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
1134
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
1225
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the operation shortfall or refinance penalties, or an explicit Blue balance cannot fund a required transfer.
1135
1226
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
1136
1227
  * @example
1137
1228
  * ```ts