@morpho-org/morpho-sdk 2.1.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/lib/cjs/abis.d.ts +2816 -0
  2. package/lib/cjs/abis.js +1951 -0
  3. package/lib/cjs/actions/index.d.ts +3 -0
  4. package/lib/cjs/actions/marketV1/borrow.js +7 -10
  5. package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +2 -3
  6. package/lib/cjs/actions/marketV1/buildReallocationActions.js +1 -2
  7. package/lib/cjs/actions/marketV1/index.d.ts +2 -0
  8. package/lib/cjs/actions/marketV1/index.js +2 -0
  9. package/lib/cjs/actions/marketV1/repay.d.ts +2 -0
  10. package/lib/cjs/actions/marketV1/repay.js +7 -8
  11. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  12. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +9 -10
  13. package/lib/cjs/actions/marketV1/supply.d.ts +69 -0
  14. package/lib/cjs/actions/marketV1/supply.js +128 -0
  15. package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +3 -1
  16. package/lib/cjs/actions/marketV1/supplyCollateral.js +12 -13
  17. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +3 -1
  18. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +14 -15
  19. package/lib/cjs/actions/marketV1/withdraw.d.ts +83 -0
  20. package/lib/cjs/actions/marketV1/withdraw.js +110 -0
  21. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -2
  22. package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +1 -1
  23. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  24. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -0
  25. package/lib/cjs/actions/vaultV1/deposit.js +13 -14
  26. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -0
  27. package/lib/cjs/actions/vaultV1/migrateToV2.js +11 -9
  28. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -0
  29. package/lib/cjs/actions/vaultV2/deposit.js +13 -14
  30. package/lib/cjs/addresses.d.ts +2 -0
  31. package/lib/cjs/addresses.js +18 -0
  32. package/lib/cjs/augment/AccrualPosition.d.ts +9 -0
  33. package/lib/cjs/augment/AccrualPosition.js +8 -0
  34. package/lib/cjs/augment/AccrualVault.d.ts +8 -0
  35. package/lib/cjs/augment/AccrualVault.js +7 -0
  36. package/lib/cjs/augment/Holding.d.ts +8 -0
  37. package/lib/cjs/augment/Holding.js +7 -0
  38. package/lib/cjs/augment/Market.d.ts +8 -0
  39. package/lib/cjs/augment/Market.js +7 -0
  40. package/lib/cjs/augment/MarketParams.d.ts +8 -0
  41. package/lib/cjs/augment/MarketParams.js +7 -0
  42. package/lib/cjs/augment/Position.d.ts +8 -0
  43. package/lib/cjs/augment/Position.js +7 -0
  44. package/lib/cjs/augment/Token.d.ts +8 -0
  45. package/lib/cjs/augment/Token.js +7 -0
  46. package/lib/cjs/augment/User.d.ts +8 -0
  47. package/lib/cjs/augment/User.js +7 -0
  48. package/lib/cjs/augment/Vault.d.ts +8 -0
  49. package/lib/cjs/augment/Vault.js +7 -0
  50. package/lib/cjs/augment/VaultConfig.d.ts +8 -0
  51. package/lib/cjs/augment/VaultConfig.js +7 -0
  52. package/lib/cjs/augment/VaultMarketAllocation.d.ts +8 -0
  53. package/lib/cjs/augment/VaultMarketAllocation.js +7 -0
  54. package/lib/cjs/augment/VaultMarketConfig.d.ts +8 -0
  55. package/lib/cjs/augment/VaultMarketConfig.js +7 -0
  56. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  57. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +8 -0
  58. package/lib/cjs/augment/VaultUser.d.ts +8 -0
  59. package/lib/cjs/augment/VaultUser.js +7 -0
  60. package/lib/cjs/augment.d.ts +14 -0
  61. package/lib/cjs/augment.js +16 -0
  62. package/lib/cjs/bundler/actions.d.ts +637 -0
  63. package/lib/cjs/bundler/actions.js +1088 -0
  64. package/lib/cjs/bundler/index.d.ts +2 -0
  65. package/lib/cjs/bundler/index.js +18 -0
  66. package/lib/cjs/bundler/types.d.ts +200 -0
  67. package/lib/cjs/bundler/types.js +2 -0
  68. package/lib/cjs/constants.d.ts +3 -0
  69. package/lib/cjs/constants.js +32 -0
  70. package/lib/cjs/entities/index.d.ts +6 -3
  71. package/lib/cjs/entities/index.js +41 -17
  72. package/lib/cjs/entities/marketV1/marketV1.d.ts +161 -24
  73. package/lib/cjs/entities/marketV1/marketV1.js +166 -19
  74. package/lib/cjs/entities/reallocationData.d.ts +193 -0
  75. package/lib/cjs/entities/reallocationData.js +406 -0
  76. package/lib/cjs/errors.d.ts +2 -0
  77. package/lib/cjs/errors.js +18 -0
  78. package/lib/cjs/fetch.d.ts +1 -0
  79. package/lib/cjs/fetch.js +30 -0
  80. package/lib/cjs/format.d.ts +2 -0
  81. package/lib/cjs/format.js +22 -0
  82. package/lib/cjs/helpers/computeReallocations.d.ts +63 -12
  83. package/lib/cjs/helpers/computeReallocations.js +160 -41
  84. package/lib/cjs/helpers/constant.d.ts +17 -0
  85. package/lib/cjs/helpers/constant.js +30 -1
  86. package/lib/cjs/helpers/index.d.ts +3 -2
  87. package/lib/cjs/helpers/index.js +14 -2
  88. package/lib/cjs/helpers/slippage.d.ts +57 -0
  89. package/lib/cjs/helpers/slippage.js +82 -0
  90. package/lib/cjs/helpers/validate.d.ts +40 -7
  91. package/lib/cjs/helpers/validate.js +67 -12
  92. package/lib/cjs/index.d.ts +0 -1
  93. package/lib/cjs/index.js +0 -1
  94. package/lib/cjs/types/action.d.ts +27 -6
  95. package/lib/cjs/types/client.d.ts +1 -1
  96. package/lib/cjs/types/error.d.ts +155 -7
  97. package/lib/cjs/types/error.js +202 -11
  98. package/lib/cjs/types/sharedLiquidity.d.ts +43 -3
  99. package/lib/cjs/types.d.ts +3 -0
  100. package/lib/cjs/types.js +17 -0
  101. package/lib/cjs/utils.d.ts +9 -0
  102. package/lib/cjs/utils.js +65 -0
  103. package/lib/esm/abis.d.ts +2816 -0
  104. package/lib/esm/abis.js +1922 -0
  105. package/lib/esm/actions/index.d.ts +3 -0
  106. package/lib/esm/actions/marketV1/borrow.js +2 -5
  107. package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +2 -3
  108. package/lib/esm/actions/marketV1/buildReallocationActions.js +1 -2
  109. package/lib/esm/actions/marketV1/index.d.ts +2 -0
  110. package/lib/esm/actions/marketV1/index.js +2 -0
  111. package/lib/esm/actions/marketV1/repay.d.ts +2 -0
  112. package/lib/esm/actions/marketV1/repay.js +4 -5
  113. package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  114. package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +4 -5
  115. package/lib/esm/actions/marketV1/supply.d.ts +69 -0
  116. package/lib/esm/actions/marketV1/supply.js +124 -0
  117. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +3 -1
  118. package/lib/esm/actions/marketV1/supplyCollateral.js +7 -8
  119. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +3 -1
  120. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +7 -8
  121. package/lib/esm/actions/marketV1/withdraw.d.ts +83 -0
  122. package/lib/esm/actions/marketV1/withdraw.js +106 -0
  123. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +1 -1
  124. package/lib/esm/actions/requirements/getRequirementsAction.d.ts +1 -1
  125. package/lib/esm/actions/requirements/getRequirementsApproval.js +1 -1
  126. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -0
  127. package/lib/esm/actions/vaultV1/deposit.js +3 -4
  128. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -0
  129. package/lib/esm/actions/vaultV1/migrateToV2.js +3 -1
  130. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -0
  131. package/lib/esm/actions/vaultV2/deposit.js +3 -4
  132. package/lib/esm/addresses.d.ts +2 -0
  133. package/lib/esm/addresses.js +1 -0
  134. package/lib/esm/augment/AccrualPosition.d.ts +9 -0
  135. package/lib/esm/augment/AccrualPosition.js +5 -0
  136. package/lib/esm/augment/AccrualVault.d.ts +8 -0
  137. package/lib/esm/augment/AccrualVault.js +4 -0
  138. package/lib/esm/augment/Holding.d.ts +8 -0
  139. package/lib/esm/augment/Holding.js +4 -0
  140. package/lib/esm/augment/Market.d.ts +8 -0
  141. package/lib/esm/augment/Market.js +4 -0
  142. package/lib/esm/augment/MarketParams.d.ts +8 -0
  143. package/lib/esm/augment/MarketParams.js +4 -0
  144. package/lib/esm/augment/Position.d.ts +8 -0
  145. package/lib/esm/augment/Position.js +4 -0
  146. package/lib/esm/augment/Token.d.ts +8 -0
  147. package/lib/esm/augment/Token.js +4 -0
  148. package/lib/esm/augment/User.d.ts +8 -0
  149. package/lib/esm/augment/User.js +4 -0
  150. package/lib/esm/augment/Vault.d.ts +8 -0
  151. package/lib/esm/augment/Vault.js +4 -0
  152. package/lib/esm/augment/VaultConfig.d.ts +8 -0
  153. package/lib/esm/augment/VaultConfig.js +4 -0
  154. package/lib/esm/augment/VaultMarketAllocation.d.ts +8 -0
  155. package/lib/esm/augment/VaultMarketAllocation.js +4 -0
  156. package/lib/esm/augment/VaultMarketConfig.d.ts +8 -0
  157. package/lib/esm/augment/VaultMarketConfig.js +4 -0
  158. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  159. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +5 -0
  160. package/lib/esm/augment/VaultUser.d.ts +8 -0
  161. package/lib/esm/augment/VaultUser.js +4 -0
  162. package/lib/esm/augment.d.ts +14 -0
  163. package/lib/esm/augment.js +14 -0
  164. package/lib/esm/bundler/actions.d.ts +637 -0
  165. package/lib/esm/bundler/actions.js +1085 -0
  166. package/lib/esm/bundler/index.d.ts +2 -0
  167. package/lib/esm/bundler/index.js +2 -0
  168. package/lib/esm/bundler/types.d.ts +200 -0
  169. package/lib/esm/bundler/types.js +1 -0
  170. package/lib/esm/constants.d.ts +3 -0
  171. package/lib/esm/constants.js +3 -0
  172. package/lib/esm/entities/index.d.ts +6 -3
  173. package/lib/esm/entities/index.js +5 -3
  174. package/lib/esm/entities/marketV1/marketV1.d.ts +161 -24
  175. package/lib/esm/entities/marketV1/marketV1.js +170 -23
  176. package/lib/esm/entities/reallocationData.d.ts +193 -0
  177. package/lib/esm/entities/reallocationData.js +402 -0
  178. package/lib/esm/errors.d.ts +2 -0
  179. package/lib/esm/errors.js +1 -0
  180. package/lib/esm/fetch.d.ts +1 -0
  181. package/lib/esm/fetch.js +1 -0
  182. package/lib/esm/format.d.ts +2 -0
  183. package/lib/esm/format.js +1 -0
  184. package/lib/esm/helpers/computeReallocations.d.ts +63 -12
  185. package/lib/esm/helpers/computeReallocations.js +160 -41
  186. package/lib/esm/helpers/constant.d.ts +17 -0
  187. package/lib/esm/helpers/constant.js +30 -1
  188. package/lib/esm/helpers/index.d.ts +3 -2
  189. package/lib/esm/helpers/index.js +3 -2
  190. package/lib/esm/helpers/slippage.d.ts +57 -0
  191. package/lib/esm/helpers/slippage.js +80 -0
  192. package/lib/esm/helpers/validate.d.ts +40 -7
  193. package/lib/esm/helpers/validate.js +63 -11
  194. package/lib/esm/index.d.ts +0 -1
  195. package/lib/esm/index.js +0 -1
  196. package/lib/esm/types/action.d.ts +27 -6
  197. package/lib/esm/types/client.d.ts +1 -1
  198. package/lib/esm/types/error.d.ts +155 -7
  199. package/lib/esm/types/error.js +185 -9
  200. package/lib/esm/types/sharedLiquidity.d.ts +43 -3
  201. package/lib/esm/types.d.ts +3 -0
  202. package/lib/esm/types.js +1 -0
  203. package/lib/esm/utils.d.ts +9 -0
  204. package/lib/esm/utils.js +7 -0
  205. package/package.json +128 -17
  206. package/src/index.ts +0 -1
@@ -1,12 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateSlippageTolerance = exports.validateReallocations = exports.validateRepayParams = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeCollateral = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = void 0;
3
+ exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateReallocations = exports.validateRepayParams = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.compareMarketIds = void 0;
4
4
  exports.validateUserAddress = validateUserAddress;
5
5
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
8
  const index_js_1 = require("../types/index.js");
9
9
  const constant_js_1 = require("./constant.js");
10
+ /** @internal */
11
+ const compareMarketIds = (idA, idB) => {
12
+ const normalizedIdA = idA.toLowerCase();
13
+ const normalizedIdB = idB.toLowerCase();
14
+ if (normalizedIdA > normalizedIdB)
15
+ return 1;
16
+ if (normalizedIdA < normalizedIdB)
17
+ return -1;
18
+ return 0;
19
+ };
20
+ exports.compareMarketIds = compareMarketIds;
10
21
  /**
11
22
  * Asserts that the client has a connected account AND that it matches
12
23
  * the provided user address.
@@ -100,23 +111,25 @@ const validateChainId = (clientChainId, expectedChainId) => {
100
111
  };
101
112
  exports.validateChainId = validateChainId;
102
113
  /**
103
- * Validates that the given collateral token is the chain's wrapped native token.
104
- * Throws {@link ChainWNativeMissingError} if wNative is not configured for the chain.
105
- * Throws {@link NativeAmountOnNonWNativeCollateralError} if collateral is not wNative.
114
+ * Validates that the given asset is the chain's wrapped native token.
115
+ * Used by any action that may receive `nativeAmount` — the SDK wraps native
116
+ * into wNative, so the target asset must be wNative for the action to succeed.
106
117
  *
107
118
  * @param chainId - The chain to look up wNative on.
108
- * @param collateralToken - The market's collateral token address.
119
+ * @param asset - The asset address to check (collateral, loan, vault asset…).
120
+ * @throws {ChainWNativeMissingError} if wNative is not configured for the chain.
121
+ * @throws {NativeAmountOnNonWNativeAssetError} if the asset is not wNative.
109
122
  */
110
- const validateNativeCollateral = (chainId, collateralToken) => {
123
+ const validateNativeAsset = (chainId, asset) => {
111
124
  const { wNative } = (0, blue_sdk_1.getChainAddresses)(chainId);
112
125
  if (!(0, morpho_ts_1.isDefined)(wNative)) {
113
126
  throw new index_js_1.ChainWNativeMissingError(chainId);
114
127
  }
115
- if (!(0, viem_1.isAddressEqual)(collateralToken, wNative)) {
116
- throw new index_js_1.NativeAmountOnNonWNativeCollateralError(collateralToken, wNative);
128
+ if (!(0, viem_1.isAddressEqual)(asset, wNative)) {
129
+ throw new index_js_1.NativeAmountOnNonWNativeAssetError(asset, wNative);
117
130
  }
118
131
  };
119
- exports.validateNativeCollateral = validateNativeCollateral;
132
+ exports.validateNativeAsset = validateNativeAsset;
120
133
  /**
121
134
  * Validates that the resulting position stays within the safe LTV threshold
122
135
  * (LLTV minus buffer) after withdrawing collateral.
@@ -242,11 +255,12 @@ exports.validateRepayParams = validateRepayParams;
242
255
  * - `fee` must be non-negative.
243
256
  * - `withdrawals` must be non-empty.
244
257
  * - Every withdrawal `amount` must be strictly positive.
245
- * - No withdrawal may target `targetMarketId` (the borrow market).
258
+ * - No withdrawal may target `targetMarketId` (the operation's target market — the market being
259
+ * borrowed from for `borrow`, or being withdrawn from for `withdraw`).
246
260
  * - Withdrawal market IDs must be strictly ascending (required by `PublicAllocator.reallocateTo`).
247
261
  *
248
262
  * @param reallocations - The reallocations to validate.
249
- * @param targetMarketId - The ID of the market being borrowed from. No withdrawal may reference this market.
263
+ * @param targetMarketId - The ID of the operation's target market. No withdrawal may reference this market.
250
264
  */
251
265
  const validateReallocations = (reallocations, targetMarketId) => {
252
266
  for (const r of reallocations) {
@@ -264,7 +278,8 @@ const validateReallocations = (reallocations, targetMarketId) => {
264
278
  if (w.marketParams.id === targetMarketId) {
265
279
  throw new index_js_1.ReallocationWithdrawalOnTargetMarketError(r.vault, w.marketParams.id);
266
280
  }
267
- if (prevId !== undefined && w.marketParams.id <= prevId) {
281
+ if (prevId !== undefined &&
282
+ (0, exports.compareMarketIds)(w.marketParams.id, prevId) <= 0) {
268
283
  throw new index_js_1.UnsortedReallocationWithdrawalsError(r.vault, w.marketParams.id);
269
284
  }
270
285
  prevId = w.marketParams.id;
@@ -289,3 +304,43 @@ const validateSlippageTolerance = (slippageTolerance) => {
289
304
  }
290
305
  };
291
306
  exports.validateSlippageTolerance = validateSlippageTolerance;
307
+ /**
308
+ * Validates that the withdraw assets do not exceed the user's supplied assets in the market.
309
+ *
310
+ * @param params - Validation parameters.
311
+ * @param params.positionData - The current accrual position.
312
+ * @param params.withdrawAssets - The amount of assets to withdraw.
313
+ * @param params.marketId - The market identifier (for error messages).
314
+ * @throws {WithdrawExceedsSupplyError} when `withdrawAssets > positionData.supplyAssets`.
315
+ */
316
+ const validateWithdrawAmount = (params) => {
317
+ const { positionData, withdrawAssets, marketId } = params;
318
+ if (withdrawAssets > positionData.supplyAssets) {
319
+ throw new index_js_1.WithdrawExceedsSupplyError({
320
+ withdrawAmount: withdrawAssets,
321
+ available: positionData.supplyAssets,
322
+ market: marketId,
323
+ });
324
+ }
325
+ };
326
+ exports.validateWithdrawAmount = validateWithdrawAmount;
327
+ /**
328
+ * Validates that the withdraw shares do not exceed the user's owned supply shares in the market.
329
+ *
330
+ * @param params - Validation parameters.
331
+ * @param params.positionData - The current accrual position.
332
+ * @param params.withdrawShares - The amount of shares to withdraw.
333
+ * @param params.marketId - The market identifier (for error messages).
334
+ * @throws {WithdrawSharesExceedSupplyError} when `withdrawShares > positionData.supplyShares`.
335
+ */
336
+ const validateWithdrawShares = (params) => {
337
+ const { positionData, withdrawShares, marketId } = params;
338
+ if (withdrawShares > positionData.supplyShares) {
339
+ throw new index_js_1.WithdrawSharesExceedSupplyError({
340
+ withdrawShares,
341
+ supplyShares: positionData.supplyShares,
342
+ market: marketId,
343
+ });
344
+ }
345
+ };
346
+ exports.validateWithdrawShares = validateWithdrawShares;
@@ -1,5 +1,4 @@
1
1
  export * from "./actions/index.js";
2
2
  export * from "./client/index.js";
3
- export * from "./entities/index.js";
4
3
  export * from "./helpers/index.js";
5
4
  export * from "./types/index.js";
package/lib/cjs/index.js CHANGED
@@ -16,6 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./actions/index.js"), exports);
18
18
  __exportStar(require("./client/index.js"), exports);
19
- __exportStar(require("./entities/index.js"), exports);
20
19
  __exportStar(require("./helpers/index.js"), exports);
21
20
  __exportStar(require("./types/index.js"), exports);
@@ -81,6 +81,23 @@ export interface VaultV1MigrateToV2Action extends BaseAction<"vaultV1MigrateToV2
81
81
  recipient: Address;
82
82
  }> {
83
83
  }
84
+ export interface MarketV1SupplyAction extends BaseAction<"marketV1Supply", {
85
+ market: Hex;
86
+ amount: bigint;
87
+ onBehalf: Address;
88
+ maxSharePrice: bigint;
89
+ nativeAmount?: bigint;
90
+ }> {
91
+ }
92
+ export interface MarketV1WithdrawAction extends BaseAction<"marketV1Withdraw", {
93
+ market: Hex;
94
+ assets: bigint;
95
+ shares: bigint;
96
+ receiver: Address;
97
+ minSharePrice: bigint;
98
+ reallocationFee: bigint;
99
+ }> {
100
+ }
84
101
  export interface MarketV1SupplyCollateralAction extends BaseAction<"marketV1SupplyCollateral", {
85
102
  market: Hex;
86
103
  amount: bigint;
@@ -136,23 +153,27 @@ export interface MarketV1RepayWithdrawCollateralAction extends BaseAction<"marke
136
153
  }> {
137
154
  }
138
155
  /**
139
- * Enforces that exactly one repay amount source is provided.
156
+ * Enforces that exactly one of `assets` / `shares` is provided.
157
+ *
158
+ * - `assets`: operate on an exact asset amount.
159
+ * - `shares`: operate on an exact share count (typical for full position closes,
160
+ * immune to interest accrual between tx construction and execution).
140
161
  *
141
- * - `assets`: partial repay by exact asset amount.
142
- * - `shares`: full repay by exact share count (guarantees full debt repayment
143
- * regardless of interest accrued between tx construction and execution).
162
+ * Used by repay (asserts on borrow side) and withdraw (asserts on supply side).
144
163
  */
145
- export type RepayAmountArgs = {
164
+ export type AssetsOrSharesArgs = {
146
165
  assets: bigint;
147
166
  } | {
148
167
  shares: bigint;
149
168
  };
169
+ /** @deprecated Use {@link AssetsOrSharesArgs}. Kept as an alias for back-compat. */
170
+ export type RepayAmountArgs = AssetsOrSharesArgs;
150
171
  export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorization", {
151
172
  authorized: Address;
152
173
  isAuthorized: boolean;
153
174
  }> {
154
175
  }
155
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MorphoAuthorizationAction;
176
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | MarketV1SupplyAction | MarketV1WithdrawAction | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MorphoAuthorizationAction;
156
177
  export interface Transaction<TAction extends BaseAction = TransactionAction> {
157
178
  readonly to: Address;
158
179
  readonly value: bigint;
@@ -1,6 +1,6 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address, Client } from "viem";
3
- import type { MarketV1Actions, VaultV1Actions, VaultV2Actions } from "../entities/index.js";
3
+ import type { MarketV1Actions, VaultV1Actions, VaultV2Actions } from "../actions/index.js";
4
4
  import type { Metadata } from "./index.js";
5
5
  /**
6
6
  * Structural contract every concrete `MorphoClient` implementation satisfies. Carries the viem
@@ -1,5 +1,49 @@
1
- import type { MarketId } from "@morpho-org/blue-sdk";
1
+ import { type MarketId, UnknownDataError } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
+ /**
4
+ * Typed errors thrown while encoding supported Bundler3 actions.
5
+ *
6
+ * @remarks
7
+ * Import these classes through `@morpho-org/morpho-sdk` when handling
8
+ * failures from `BundlerAction`.
9
+ */
10
+ export declare namespace BundlerErrors {
11
+ /**
12
+ * Thrown when an action that requires an offchain signature is encoded before
13
+ * the signature has been attached.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
18
+ *
19
+ * if (error instanceof BundlerErrors.MissingSignature) {
20
+ * // Attach the missing permit or Permit2 signature, then encode again.
21
+ * }
22
+ * ```
23
+ */
24
+ class MissingSignature extends Error {
25
+ constructor();
26
+ }
27
+ /**
28
+ * Thrown when an action is unsupported on the requested chain.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
33
+ *
34
+ * if (error instanceof BundlerErrors.UnexpectedAction) {
35
+ * // Remove or replace the action for the selected chain.
36
+ * }
37
+ * ```
38
+ */
39
+ class UnexpectedAction extends Error {
40
+ /**
41
+ * @param type - Unsupported Bundler3 action discriminator or name.
42
+ * @param chainId - Chain where the action was requested.
43
+ */
44
+ constructor(type: string, chainId: number);
45
+ }
46
+ }
3
47
  /** Thrown when an asset amount is required to be positive but is zero or negative. */
4
48
  export declare class NonPositiveAssetAmountError extends Error {
5
49
  constructor(origin: Address);
@@ -84,10 +128,13 @@ export declare class NonPositiveBorrowAmountError extends Error {
84
128
  export declare class ZeroCollateralAmountError extends Error {
85
129
  constructor(market: string);
86
130
  }
87
- /** Thrown when a collateral supply uses `nativeAmount` but the collateral token is not the chain's wNative. */
88
- export declare class NativeAmountOnNonWNativeCollateralError extends Error {
89
- constructor(collateralToken: Address, wNative: Address);
131
+ /** Thrown when an action uses `nativeAmount` but the target asset is not the chain's wNative. */
132
+ export declare class NativeAmountOnNonWNativeAssetError extends Error {
133
+ constructor(asset: Address, wNative: Address);
90
134
  }
135
+ /** @deprecated Use {@link NativeAmountOnNonWNativeAssetError}. */
136
+ export declare const NativeAmountOnNonWNativeCollateralError: typeof NativeAmountOnNonWNativeAssetError;
137
+ export type NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeAssetError;
91
138
  /** Thrown when a borrow exceeds the LLTV-buffered safe maximum for the position. */
92
139
  export declare class BorrowExceedsSafeLtvError extends Error {
93
140
  constructor(borrowAmount: bigint, maxSafeBorrow: bigint);
@@ -116,7 +163,7 @@ export declare class EmptyReallocationWithdrawalsError extends Error {
116
163
  export declare class NonPositiveReallocationAmountError extends Error {
117
164
  constructor(vault: string, market: string);
118
165
  }
119
- /** Thrown when a reallocation withdrawal references the borrow target market (which would be a no-op or self-deal). */
166
+ /** Thrown when a reallocation withdrawal references the operation's target market (which would be a no-op or self-deal). */
120
167
  export declare class ReallocationWithdrawalOnTargetMarketError extends Error {
121
168
  constructor(vault: string, marketId: string);
122
169
  }
@@ -196,10 +243,16 @@ export declare class RepaySharesExceedDebtError extends Error {
196
243
  export declare class MissingPublicAllocatorConfigError extends Error {
197
244
  constructor(vault: string);
198
245
  }
246
+ /** Thrown when a reallocation attempts to use a disabled vault market. */
247
+ export declare class DisabledReallocationMarketError extends Error {
248
+ readonly vault: Address;
249
+ readonly marketId: MarketId;
250
+ constructor(vault: Address, marketId: MarketId);
251
+ }
199
252
  /**
200
253
  * Thrown when shared liquidity selected by `computeReallocations` cannot cover
201
- * the absolute borrow shortfall on the target market — the resulting
202
- * `morphoBorrow` would still revert onchain.
254
+ * the operation's absolute shortfall on the target market — the resulting
255
+ * `morphoBorrow` or `morphoWithdraw` would still revert onchain.
203
256
  *
204
257
  * Pattern-match on the class and inspect `params` to surface the gap to users.
205
258
  */
@@ -215,10 +268,105 @@ export declare class InsufficientSharedLiquidityError extends Error {
215
268
  readonly available: bigint;
216
269
  });
217
270
  }
271
+ /** Thrown when reallocation state does not contain a requested market. */
272
+ export declare class UnknownReallocationMarketError extends UnknownDataError {
273
+ readonly marketId: MarketId;
274
+ /**
275
+ * @param marketId - Missing market id.
276
+ */
277
+ constructor(marketId: MarketId);
278
+ }
279
+ /** Thrown when reallocation state does not contain a requested vault. */
280
+ export declare class UnknownReallocationVaultError extends UnknownDataError {
281
+ readonly vault: Address;
282
+ /**
283
+ * @param vault - Missing vault address.
284
+ */
285
+ constructor(vault: Address);
286
+ }
287
+ /** Thrown when reallocation state does not contain a requested vault-market config. */
288
+ export declare class UnknownReallocationVaultMarketConfigError extends UnknownDataError {
289
+ readonly vault: Address;
290
+ readonly marketId: MarketId;
291
+ /**
292
+ * @param vault - Vault address for the missing config.
293
+ * @param marketId - Market id for the missing config.
294
+ */
295
+ constructor(vault: Address, marketId: MarketId);
296
+ }
297
+ /** Thrown when reallocation state does not contain a requested market position. */
298
+ export declare class UnknownReallocationPositionError extends UnknownDataError {
299
+ readonly user: Address;
300
+ readonly marketId: MarketId;
301
+ /**
302
+ * @param user - Position owner address.
303
+ * @param marketId - Market id for the missing position.
304
+ */
305
+ constructor(user: Address, marketId: MarketId);
306
+ }
218
307
  /** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
219
308
  export declare class NonPositiveMinBorrowSharePriceError extends Error {
220
309
  constructor(market: string);
221
310
  }
311
+ /** Thrown when a market loan-asset supply amount is negative. */
312
+ export declare class NegativeSupplyAmountError extends Error {
313
+ constructor(market: string);
314
+ }
315
+ /** Thrown when a market loan-asset supply's `maxSharePrice` slippage bound is negative. */
316
+ export declare class NegativeSupplyMaxSharePriceError extends Error {
317
+ constructor(market: string);
318
+ }
319
+ /** Thrown when both `amount` and `nativeAmount` resolve to zero on a market loan-asset supply. */
320
+ export declare class ZeroSupplyAmountError extends Error {
321
+ constructor(market: string);
322
+ }
323
+ /** Thrown when a market loan-asset withdraw has both `assets` and `shares` zero, or either negative. */
324
+ export declare class NonPositiveWithdrawAmountError extends Error {
325
+ constructor(market: string);
326
+ }
327
+ /** Thrown when a market loan-asset withdraw's `minSharePrice` slippage bound is negative. */
328
+ export declare class NegativeWithdrawMinSharePriceError extends Error {
329
+ constructor(market: string);
330
+ }
331
+ /** Thrown when a loan-asset withdraw specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
332
+ export declare class MutuallyExclusiveWithdrawAmountsError extends Error {
333
+ constructor(market: string);
334
+ }
335
+ /** Thrown when a loan-asset withdraw in assets mode exceeds the user's supplied assets in the market. */
336
+ export declare class WithdrawExceedsSupplyError extends Error {
337
+ constructor(params: {
338
+ withdrawAmount: bigint;
339
+ available: bigint;
340
+ market: string;
341
+ });
342
+ }
343
+ /** Thrown when a loan-asset withdraw in shares mode exceeds the user's owned supply shares in the market. */
344
+ export declare class WithdrawSharesExceedSupplyError extends Error {
345
+ constructor(params: {
346
+ withdrawShares: bigint;
347
+ supplyShares: bigint;
348
+ market: string;
349
+ });
350
+ }
351
+ /**
352
+ * Thrown when `computeReallocations` is called with a withdraw `amount` greater
353
+ * than the target market's current `totalSupplyAssets` — the post-withdraw
354
+ * supply would be negative, making the on-chain `morphoWithdraw` revert
355
+ * regardless of any reallocation. Caught here so callers do not pay
356
+ * PublicAllocator fees on an unreachable operation.
357
+ */
358
+ export declare class ReallocationWithdrawExceedsMarketSupplyError extends Error {
359
+ readonly params: {
360
+ readonly marketId: MarketId;
361
+ readonly withdrawAmount: bigint;
362
+ readonly totalSupplyAssets: bigint;
363
+ };
364
+ constructor(params: {
365
+ readonly marketId: MarketId;
366
+ readonly withdrawAmount: bigint;
367
+ readonly totalSupplyAssets: bigint;
368
+ });
369
+ }
222
370
  /** Thrown when a vault migration's source vault asset differs from the target vault asset. */
223
371
  export declare class VaultAssetMismatchError extends Error {
224
372
  constructor(sourceAsset: Address, targetAsset: Address);