@morpho-org/morpho-sdk 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) 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/repay.d.ts +2 -0
  8. package/lib/cjs/actions/marketV1/repay.js +7 -8
  9. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  10. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +9 -10
  11. package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +2 -0
  12. package/lib/cjs/actions/marketV1/supplyCollateral.js +11 -12
  13. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
  14. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +13 -14
  15. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -2
  16. package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +28 -4
  17. package/lib/cjs/actions/requirements/getRequirementsAction.js +28 -4
  18. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  19. package/lib/cjs/actions/requirements/index.d.ts +1 -0
  20. package/lib/cjs/actions/requirements/index.js +1 -0
  21. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -0
  22. package/lib/cjs/actions/vaultV1/deposit.js +13 -14
  23. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -0
  24. package/lib/cjs/actions/vaultV1/migrateToV2.js +11 -9
  25. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -0
  26. package/lib/cjs/actions/vaultV2/deposit.js +13 -14
  27. package/lib/cjs/addresses.d.ts +2 -0
  28. package/lib/cjs/addresses.js +18 -0
  29. package/lib/cjs/augment/AccrualPosition.d.ts +9 -0
  30. package/lib/cjs/augment/AccrualPosition.js +8 -0
  31. package/lib/cjs/augment/AccrualVault.d.ts +8 -0
  32. package/lib/cjs/augment/AccrualVault.js +7 -0
  33. package/lib/cjs/augment/Holding.d.ts +8 -0
  34. package/lib/cjs/augment/Holding.js +7 -0
  35. package/lib/cjs/augment/Market.d.ts +8 -0
  36. package/lib/cjs/augment/Market.js +7 -0
  37. package/lib/cjs/augment/MarketParams.d.ts +8 -0
  38. package/lib/cjs/augment/MarketParams.js +7 -0
  39. package/lib/cjs/augment/Position.d.ts +8 -0
  40. package/lib/cjs/augment/Position.js +7 -0
  41. package/lib/cjs/augment/Token.d.ts +8 -0
  42. package/lib/cjs/augment/Token.js +7 -0
  43. package/lib/cjs/augment/User.d.ts +8 -0
  44. package/lib/cjs/augment/User.js +7 -0
  45. package/lib/cjs/augment/Vault.d.ts +8 -0
  46. package/lib/cjs/augment/Vault.js +7 -0
  47. package/lib/cjs/augment/VaultConfig.d.ts +8 -0
  48. package/lib/cjs/augment/VaultConfig.js +7 -0
  49. package/lib/cjs/augment/VaultMarketAllocation.d.ts +8 -0
  50. package/lib/cjs/augment/VaultMarketAllocation.js +7 -0
  51. package/lib/cjs/augment/VaultMarketConfig.d.ts +8 -0
  52. package/lib/cjs/augment/VaultMarketConfig.js +7 -0
  53. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  54. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +8 -0
  55. package/lib/cjs/augment/VaultUser.d.ts +8 -0
  56. package/lib/cjs/augment/VaultUser.js +7 -0
  57. package/lib/cjs/augment.d.ts +14 -0
  58. package/lib/cjs/augment.js +16 -0
  59. package/lib/cjs/bundler/actions.d.ts +555 -0
  60. package/lib/cjs/bundler/actions.js +953 -0
  61. package/lib/cjs/bundler/index.d.ts +2 -0
  62. package/lib/cjs/bundler/index.js +18 -0
  63. package/lib/cjs/bundler/types.d.ts +181 -0
  64. package/lib/cjs/bundler/types.js +2 -0
  65. package/lib/cjs/constants.d.ts +3 -0
  66. package/lib/cjs/constants.js +32 -0
  67. package/lib/cjs/entities/index.d.ts +6 -3
  68. package/lib/cjs/entities/index.js +41 -17
  69. package/lib/cjs/entities/marketV1/marketV1.d.ts +45 -11
  70. package/lib/cjs/entities/marketV1/marketV1.js +45 -23
  71. package/lib/cjs/entities/reallocationData.d.ts +193 -0
  72. package/lib/cjs/entities/reallocationData.js +406 -0
  73. package/lib/cjs/entities/vaultV1/vaultV1.js +6 -2
  74. package/lib/cjs/entities/vaultV2/vaultV2.js +6 -1
  75. package/lib/cjs/errors.d.ts +2 -0
  76. package/lib/cjs/errors.js +18 -0
  77. package/lib/cjs/fetch.d.ts +1 -0
  78. package/lib/cjs/fetch.js +30 -0
  79. package/lib/cjs/format.d.ts +2 -0
  80. package/lib/cjs/format.js +22 -0
  81. package/lib/cjs/helpers/computeReallocations.d.ts +48 -8
  82. package/lib/cjs/helpers/computeReallocations.js +120 -32
  83. package/lib/cjs/helpers/constant.d.ts +17 -0
  84. package/lib/cjs/helpers/constant.js +30 -1
  85. package/lib/cjs/helpers/index.d.ts +1 -0
  86. package/lib/cjs/helpers/index.js +9 -1
  87. package/lib/cjs/helpers/metadata.d.ts +10 -0
  88. package/lib/cjs/helpers/metadata.js +20 -1
  89. package/lib/cjs/helpers/validate.d.ts +2 -0
  90. package/lib/cjs/helpers/validate.js +14 -2
  91. package/lib/cjs/index.d.ts +0 -1
  92. package/lib/cjs/index.js +0 -1
  93. package/lib/cjs/types/client.d.ts +1 -1
  94. package/lib/cjs/types/error.d.ts +91 -1
  95. package/lib/cjs/types/error.js +126 -1
  96. package/lib/cjs/types/sharedLiquidity.d.ts +43 -3
  97. package/lib/cjs/types.d.ts +3 -0
  98. package/lib/cjs/types.js +17 -0
  99. package/lib/cjs/utils.d.ts +9 -0
  100. package/lib/cjs/utils.js +65 -0
  101. package/lib/esm/abis.d.ts +2816 -0
  102. package/lib/esm/abis.js +1922 -0
  103. package/lib/esm/actions/index.d.ts +3 -0
  104. package/lib/esm/actions/marketV1/borrow.js +2 -5
  105. package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +2 -3
  106. package/lib/esm/actions/marketV1/buildReallocationActions.js +1 -2
  107. package/lib/esm/actions/marketV1/repay.d.ts +2 -0
  108. package/lib/esm/actions/marketV1/repay.js +4 -5
  109. package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  110. package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +4 -5
  111. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +2 -0
  112. package/lib/esm/actions/marketV1/supplyCollateral.js +4 -5
  113. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
  114. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +4 -5
  115. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +1 -1
  116. package/lib/esm/actions/requirements/getRequirementsAction.d.ts +28 -4
  117. package/lib/esm/actions/requirements/getRequirementsAction.js +29 -5
  118. package/lib/esm/actions/requirements/getRequirementsApproval.js +1 -1
  119. package/lib/esm/actions/requirements/index.d.ts +1 -0
  120. package/lib/esm/actions/requirements/index.js +1 -0
  121. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -0
  122. package/lib/esm/actions/vaultV1/deposit.js +3 -4
  123. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -0
  124. package/lib/esm/actions/vaultV1/migrateToV2.js +3 -1
  125. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -0
  126. package/lib/esm/actions/vaultV2/deposit.js +3 -4
  127. package/lib/esm/addresses.d.ts +2 -0
  128. package/lib/esm/addresses.js +1 -0
  129. package/lib/esm/augment/AccrualPosition.d.ts +9 -0
  130. package/lib/esm/augment/AccrualPosition.js +5 -0
  131. package/lib/esm/augment/AccrualVault.d.ts +8 -0
  132. package/lib/esm/augment/AccrualVault.js +4 -0
  133. package/lib/esm/augment/Holding.d.ts +8 -0
  134. package/lib/esm/augment/Holding.js +4 -0
  135. package/lib/esm/augment/Market.d.ts +8 -0
  136. package/lib/esm/augment/Market.js +4 -0
  137. package/lib/esm/augment/MarketParams.d.ts +8 -0
  138. package/lib/esm/augment/MarketParams.js +4 -0
  139. package/lib/esm/augment/Position.d.ts +8 -0
  140. package/lib/esm/augment/Position.js +4 -0
  141. package/lib/esm/augment/Token.d.ts +8 -0
  142. package/lib/esm/augment/Token.js +4 -0
  143. package/lib/esm/augment/User.d.ts +8 -0
  144. package/lib/esm/augment/User.js +4 -0
  145. package/lib/esm/augment/Vault.d.ts +8 -0
  146. package/lib/esm/augment/Vault.js +4 -0
  147. package/lib/esm/augment/VaultConfig.d.ts +8 -0
  148. package/lib/esm/augment/VaultConfig.js +4 -0
  149. package/lib/esm/augment/VaultMarketAllocation.d.ts +8 -0
  150. package/lib/esm/augment/VaultMarketAllocation.js +4 -0
  151. package/lib/esm/augment/VaultMarketConfig.d.ts +8 -0
  152. package/lib/esm/augment/VaultMarketConfig.js +4 -0
  153. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  154. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +5 -0
  155. package/lib/esm/augment/VaultUser.d.ts +8 -0
  156. package/lib/esm/augment/VaultUser.js +4 -0
  157. package/lib/esm/augment.d.ts +14 -0
  158. package/lib/esm/augment.js +14 -0
  159. package/lib/esm/bundler/actions.d.ts +555 -0
  160. package/lib/esm/bundler/actions.js +950 -0
  161. package/lib/esm/bundler/index.d.ts +2 -0
  162. package/lib/esm/bundler/index.js +2 -0
  163. package/lib/esm/bundler/types.d.ts +181 -0
  164. package/lib/esm/bundler/types.js +1 -0
  165. package/lib/esm/constants.d.ts +3 -0
  166. package/lib/esm/constants.js +3 -0
  167. package/lib/esm/entities/index.d.ts +6 -3
  168. package/lib/esm/entities/index.js +5 -3
  169. package/lib/esm/entities/marketV1/marketV1.d.ts +45 -11
  170. package/lib/esm/entities/marketV1/marketV1.js +46 -24
  171. package/lib/esm/entities/reallocationData.d.ts +193 -0
  172. package/lib/esm/entities/reallocationData.js +402 -0
  173. package/lib/esm/entities/vaultV1/vaultV1.js +6 -2
  174. package/lib/esm/entities/vaultV2/vaultV2.js +6 -1
  175. package/lib/esm/errors.d.ts +2 -0
  176. package/lib/esm/errors.js +1 -0
  177. package/lib/esm/fetch.d.ts +1 -0
  178. package/lib/esm/fetch.js +1 -0
  179. package/lib/esm/format.d.ts +2 -0
  180. package/lib/esm/format.js +1 -0
  181. package/lib/esm/helpers/computeReallocations.d.ts +48 -8
  182. package/lib/esm/helpers/computeReallocations.js +119 -31
  183. package/lib/esm/helpers/constant.d.ts +17 -0
  184. package/lib/esm/helpers/constant.js +30 -1
  185. package/lib/esm/helpers/index.d.ts +1 -0
  186. package/lib/esm/helpers/index.js +1 -0
  187. package/lib/esm/helpers/metadata.d.ts +10 -0
  188. package/lib/esm/helpers/metadata.js +20 -1
  189. package/lib/esm/helpers/validate.d.ts +2 -0
  190. package/lib/esm/helpers/validate.js +12 -1
  191. package/lib/esm/index.d.ts +0 -1
  192. package/lib/esm/index.js +0 -1
  193. package/lib/esm/types/client.d.ts +1 -1
  194. package/lib/esm/types/error.d.ts +91 -1
  195. package/lib/esm/types/error.js +118 -0
  196. package/lib/esm/types/sharedLiquidity.d.ts +43 -3
  197. package/lib/esm/types.d.ts +3 -0
  198. package/lib/esm/types.js +1 -0
  199. package/lib/esm/utils.d.ts +9 -0
  200. package/lib/esm/utils.js +7 -0
  201. package/package.json +121 -14
  202. package/src/index.ts +0 -1
@@ -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);
@@ -52,6 +96,10 @@ export declare class DepositAmountMismatchError extends Error {
52
96
  export declare class DepositAssetMismatchError extends Error {
53
97
  constructor(depositAsset: Address, signatureAsset: Address);
54
98
  }
99
+ /** Thrown when a `permit2` requirement signature is missing the `expiration` field. */
100
+ export declare class Permit2ExpirationMissingError extends Error {
101
+ constructor();
102
+ }
55
103
  /** Thrown when a vault deposit uses `nativeAmount` but the vault asset is not the chain's wNative. */
56
104
  export declare class NativeAmountOnNonWNativeVaultError extends Error {
57
105
  constructor(vaultAsset: Address, wNative: Address);
@@ -192,6 +240,12 @@ export declare class RepaySharesExceedDebtError extends Error {
192
240
  export declare class MissingPublicAllocatorConfigError extends Error {
193
241
  constructor(vault: string);
194
242
  }
243
+ /** Thrown when a reallocation attempts to use a disabled vault market. */
244
+ export declare class DisabledReallocationMarketError extends Error {
245
+ readonly vault: Address;
246
+ readonly marketId: MarketId;
247
+ constructor(vault: Address, marketId: MarketId);
248
+ }
195
249
  /**
196
250
  * Thrown when shared liquidity selected by `computeReallocations` cannot cover
197
251
  * the absolute borrow shortfall on the target market — the resulting
@@ -211,6 +265,42 @@ export declare class InsufficientSharedLiquidityError extends Error {
211
265
  readonly available: bigint;
212
266
  });
213
267
  }
268
+ /** Thrown when reallocation state does not contain a requested market. */
269
+ export declare class UnknownReallocationMarketError extends UnknownDataError {
270
+ readonly marketId: MarketId;
271
+ /**
272
+ * @param marketId - Missing market id.
273
+ */
274
+ constructor(marketId: MarketId);
275
+ }
276
+ /** Thrown when reallocation state does not contain a requested vault. */
277
+ export declare class UnknownReallocationVaultError extends UnknownDataError {
278
+ readonly vault: Address;
279
+ /**
280
+ * @param vault - Missing vault address.
281
+ */
282
+ constructor(vault: Address);
283
+ }
284
+ /** Thrown when reallocation state does not contain a requested vault-market config. */
285
+ export declare class UnknownReallocationVaultMarketConfigError extends UnknownDataError {
286
+ readonly vault: Address;
287
+ readonly marketId: MarketId;
288
+ /**
289
+ * @param vault - Vault address for the missing config.
290
+ * @param marketId - Market id for the missing config.
291
+ */
292
+ constructor(vault: Address, marketId: MarketId);
293
+ }
294
+ /** Thrown when reallocation state does not contain a requested market position. */
295
+ export declare class UnknownReallocationPositionError extends UnknownDataError {
296
+ readonly user: Address;
297
+ readonly marketId: MarketId;
298
+ /**
299
+ * @param user - Position owner address.
300
+ * @param marketId - Market id for the missing position.
301
+ */
302
+ constructor(user: Address, marketId: MarketId);
303
+ }
214
304
  /** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
215
305
  export declare class NonPositiveMinBorrowSharePriceError extends Error {
216
306
  constructor(market: string);
@@ -1,6 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.NonPositiveMinBorrowSharePriceError = exports.InsufficientSharedLiquidityError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = void 0;
3
+ exports.UnknownReallocationVaultMarketConfigError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.DisabledReallocationMarketError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.Permit2ExpirationMissingError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = exports.BundlerErrors = void 0;
4
+ exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.NonPositiveMinBorrowSharePriceError = exports.UnknownReallocationPositionError = void 0;
5
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
6
+ /**
7
+ * Typed errors thrown while encoding supported Bundler3 actions.
8
+ *
9
+ * @remarks
10
+ * Import these classes through `@morpho-org/morpho-sdk` when handling
11
+ * failures from `BundlerAction`.
12
+ */
13
+ var BundlerErrors;
14
+ (function (BundlerErrors) {
15
+ /**
16
+ * Thrown when an action that requires an offchain signature is encoded before
17
+ * the signature has been attached.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
22
+ *
23
+ * if (error instanceof BundlerErrors.MissingSignature) {
24
+ * // Attach the missing permit or Permit2 signature, then encode again.
25
+ * }
26
+ * ```
27
+ */
28
+ class MissingSignature extends Error {
29
+ constructor() {
30
+ super("missing signature");
31
+ }
32
+ }
33
+ BundlerErrors.MissingSignature = MissingSignature;
34
+ /**
35
+ * Thrown when an action is unsupported on the requested chain.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
40
+ *
41
+ * if (error instanceof BundlerErrors.UnexpectedAction) {
42
+ * // Remove or replace the action for the selected chain.
43
+ * }
44
+ * ```
45
+ */
46
+ class UnexpectedAction extends Error {
47
+ /**
48
+ * @param type - Unsupported Bundler3 action discriminator or name.
49
+ * @param chainId - Chain where the action was requested.
50
+ */
51
+ constructor(type, chainId) {
52
+ super(`unexpected action "${type}" on chain "${chainId}"`);
53
+ }
54
+ }
55
+ BundlerErrors.UnexpectedAction = UnexpectedAction;
56
+ })(BundlerErrors || (exports.BundlerErrors = BundlerErrors = {}));
4
57
  /** Thrown when an asset amount is required to be positive but is zero or negative. */
5
58
  class NonPositiveAssetAmountError extends Error {
6
59
  constructor(origin) {
@@ -92,6 +145,13 @@ class DepositAssetMismatchError extends Error {
92
145
  }
93
146
  }
94
147
  exports.DepositAssetMismatchError = DepositAssetMismatchError;
148
+ /** Thrown when a `permit2` requirement signature is missing the `expiration` field. */
149
+ class Permit2ExpirationMissingError extends Error {
150
+ constructor() {
151
+ super('Requirement signature with action.type === "permit2" must include args.expiration. Re-sign using the permit2 flow.');
152
+ }
153
+ }
154
+ exports.Permit2ExpirationMissingError = Permit2ExpirationMissingError;
95
155
  /** Thrown when a vault deposit uses `nativeAmount` but the vault asset is not the chain's wNative. */
96
156
  class NativeAmountOnNonWNativeVaultError extends Error {
97
157
  constructor(vaultAsset, wNative) {
@@ -302,6 +362,17 @@ class MissingPublicAllocatorConfigError extends Error {
302
362
  }
303
363
  }
304
364
  exports.MissingPublicAllocatorConfigError = MissingPublicAllocatorConfigError;
365
+ /** Thrown when a reallocation attempts to use a disabled vault market. */
366
+ class DisabledReallocationMarketError extends Error {
367
+ vault;
368
+ marketId;
369
+ constructor(vault, marketId) {
370
+ super(`Vault ${vault} has disabled market ${marketId}. Remove it from reallocations or re-enable the market before reallocating.`);
371
+ this.vault = vault;
372
+ this.marketId = marketId;
373
+ }
374
+ }
375
+ exports.DisabledReallocationMarketError = DisabledReallocationMarketError;
305
376
  /**
306
377
  * Thrown when shared liquidity selected by `computeReallocations` cannot cover
307
378
  * the absolute borrow shortfall on the target market — the resulting
@@ -317,6 +388,60 @@ class InsufficientSharedLiquidityError extends Error {
317
388
  }
318
389
  }
319
390
  exports.InsufficientSharedLiquidityError = InsufficientSharedLiquidityError;
391
+ /** Thrown when reallocation state does not contain a requested market. */
392
+ class UnknownReallocationMarketError extends blue_sdk_1.UnknownDataError {
393
+ marketId;
394
+ /**
395
+ * @param marketId - Missing market id.
396
+ */
397
+ constructor(marketId) {
398
+ super(`unknown reallocation market "${marketId}"`);
399
+ this.marketId = marketId;
400
+ }
401
+ }
402
+ exports.UnknownReallocationMarketError = UnknownReallocationMarketError;
403
+ /** Thrown when reallocation state does not contain a requested vault. */
404
+ class UnknownReallocationVaultError extends blue_sdk_1.UnknownDataError {
405
+ vault;
406
+ /**
407
+ * @param vault - Missing vault address.
408
+ */
409
+ constructor(vault) {
410
+ super(`unknown reallocation vault "${vault}"`);
411
+ this.vault = vault;
412
+ }
413
+ }
414
+ exports.UnknownReallocationVaultError = UnknownReallocationVaultError;
415
+ /** Thrown when reallocation state does not contain a requested vault-market config. */
416
+ class UnknownReallocationVaultMarketConfigError extends blue_sdk_1.UnknownDataError {
417
+ vault;
418
+ marketId;
419
+ /**
420
+ * @param vault - Vault address for the missing config.
421
+ * @param marketId - Market id for the missing config.
422
+ */
423
+ constructor(vault, marketId) {
424
+ super(`unknown reallocation config for vault "${vault}" on market "${marketId}"`);
425
+ this.vault = vault;
426
+ this.marketId = marketId;
427
+ }
428
+ }
429
+ exports.UnknownReallocationVaultMarketConfigError = UnknownReallocationVaultMarketConfigError;
430
+ /** Thrown when reallocation state does not contain a requested market position. */
431
+ class UnknownReallocationPositionError extends blue_sdk_1.UnknownDataError {
432
+ user;
433
+ marketId;
434
+ /**
435
+ * @param user - Position owner address.
436
+ * @param marketId - Market id for the missing position.
437
+ */
438
+ constructor(user, marketId) {
439
+ super(`unknown reallocation position of "${user}" on market "${marketId}"`);
440
+ this.user = user;
441
+ this.marketId = marketId;
442
+ }
443
+ }
444
+ exports.UnknownReallocationPositionError = UnknownReallocationPositionError;
320
445
  /** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
321
446
  class NonPositiveMinBorrowSharePriceError extends Error {
322
447
  constructor(market) {
@@ -1,9 +1,49 @@
1
- import type { MarketId, MarketParams } from "@morpho-org/blue-sdk";
2
- import type { PublicAllocatorOptions } from "@morpho-org/simulation-sdk";
1
+ import type { BigIntish, MarketId, MarketParams } from "@morpho-org/blue-sdk";
3
2
  import type { Address } from "viem";
3
+ /**
4
+ * Options controlling public allocator withdrawal discovery.
5
+ */
6
+ export interface PublicAllocatorOptions {
7
+ /** Whether public allocator reallocation discovery is enabled. */
8
+ readonly enabled?: boolean;
9
+ /**
10
+ * Timestamp at which market interest and public allocator pending caps are evaluated.
11
+ * Defaults to the target market's last update timestamp.
12
+ */
13
+ readonly timestamp?: BigIntish;
14
+ /**
15
+ * Vaults to consider for reallocation. They must have enabled the PublicAllocator.
16
+ * Defaults to all vaults present in the reallocation data.
17
+ */
18
+ readonly reallocatableVaults?: readonly Address[];
19
+ /**
20
+ * The maximum utilization each source market may reach when withdrawing
21
+ * shared liquidity, scaled by WAD.
22
+ */
23
+ readonly maxWithdrawalUtilization?: Readonly<Record<MarketId, bigint | undefined>>;
24
+ /**
25
+ * The default maximum utilization source markets may reach when withdrawing
26
+ * shared liquidity, scaled by WAD.
27
+ * @default 92% (920000000000000000n)
28
+ */
29
+ readonly defaultMaxWithdrawalUtilization?: bigint;
30
+ }
31
+ /**
32
+ * A computed source-market withdrawal before it is grouped by vault.
33
+ */
34
+ export interface PublicReallocation {
35
+ /** Source market id to withdraw from. */
36
+ readonly id: MarketId;
37
+ /** Vault that can perform the public allocator reallocation. */
38
+ readonly vault: Address;
39
+ /** Assets to withdraw from the source market. */
40
+ readonly assets: bigint;
41
+ }
4
42
  /** A single withdrawal from a source market within a vault reallocation. */
5
43
  export interface ReallocationWithdrawal {
44
+ /** Source market parameters to pass to the public allocator. */
6
45
  readonly marketParams: MarketParams;
46
+ /** Asset amount to withdraw from the source market. */
7
47
  readonly amount: bigint;
8
48
  }
9
49
  /**
@@ -31,7 +71,7 @@ export interface ReallocationComputeOptions extends PublicAllocatorOptions {
31
71
  * is triggered (scaled by WAD). Overrides `defaultSupplyTargetUtilization`
32
72
  * for the specified market.
33
73
  */
34
- readonly supplyTargetUtilization?: Record<MarketId, bigint | undefined>;
74
+ readonly supplyTargetUtilization?: Readonly<Record<MarketId, bigint | undefined>>;
35
75
  /**
36
76
  * The default target utilization above which the shared liquidity algorithm
37
77
  * is triggered (scaled by WAD).
@@ -0,0 +1,3 @@
1
+ export type { BigIntish, ChainMetadata, CollateralAllocation, Eip712Field, Erc20AllowanceRecipient, Failable, Fetchable, InputMarketParams, IPermit2Allowance, Loadable, MarketId, MaxBorrowOptions, MaxPositionCapacities, MaxWithdrawCollateralOptions, Pending, Permit2Allowance, } from "@morpho-org/blue-sdk";
2
+ export type { DeploylessFetchParameters, FetchParameters, } from "@morpho-org/blue-sdk-viem";
3
+ export * from "./types/index.js";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types/index.js"), exports);
@@ -0,0 +1,9 @@
1
+ export type { CapacityLimit, RoundingDirection } from "@morpho-org/blue-sdk";
2
+ export { AdaptiveCurveIrmLib, CapacityLimitReason, MarketUtils, MathLib, SharesMath, VaultUtils, } from "@morpho-org/blue-sdk";
3
+ export { decodeBytes32String, getAuthorizationTypedData, getDaiPermitTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
4
+ export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, WithId, WithIndex, } from "@morpho-org/morpho-ts";
5
+ export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
6
+ export { computeReallocations } from "./helpers/computeReallocations.js";
7
+ export { addTransactionMetadata } from "./helpers/metadata.js";
8
+ export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./helpers/slippage.js";
9
+ export { validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayParams, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./helpers/validate.js";
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeCollateral = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinBorrowSharePrice = exports.computeMaxRepaySharePrice = exports.addTransactionMetadata = exports.computeReallocations = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getDaiPermitTypedData = exports.getAuthorizationTypedData = exports.decodeBytes32String = exports.VaultUtils = exports.SharesMath = exports.MathLib = exports.MarketUtils = exports.CapacityLimitReason = exports.AdaptiveCurveIrmLib = void 0;
4
+ exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayParams = void 0;
5
+ var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
+ Object.defineProperty(exports, "AdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
7
+ Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
8
+ Object.defineProperty(exports, "MarketUtils", { enumerable: true, get: function () { return blue_sdk_1.MarketUtils; } });
9
+ Object.defineProperty(exports, "MathLib", { enumerable: true, get: function () { return blue_sdk_1.MathLib; } });
10
+ Object.defineProperty(exports, "SharesMath", { enumerable: true, get: function () { return blue_sdk_1.SharesMath; } });
11
+ Object.defineProperty(exports, "VaultUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultUtils; } });
12
+ var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
13
+ Object.defineProperty(exports, "decodeBytes32String", { enumerable: true, get: function () { return blue_sdk_viem_1.decodeBytes32String; } });
14
+ Object.defineProperty(exports, "getAuthorizationTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getAuthorizationTypedData; } });
15
+ Object.defineProperty(exports, "getDaiPermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getDaiPermitTypedData; } });
16
+ Object.defineProperty(exports, "getPermit2PermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermit2PermitTypedData; } });
17
+ Object.defineProperty(exports, "getPermit2TransferFromTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermit2TransferFromTypedData; } });
18
+ Object.defineProperty(exports, "getPermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermitTypedData; } });
19
+ Object.defineProperty(exports, "optionalBoolean", { enumerable: true, get: function () { return blue_sdk_viem_1.optionalBoolean; } });
20
+ Object.defineProperty(exports, "readContractRestructured", { enumerable: true, get: function () { return blue_sdk_viem_1.readContractRestructured; } });
21
+ Object.defineProperty(exports, "restructure", { enumerable: true, get: function () { return blue_sdk_viem_1.restructure; } });
22
+ Object.defineProperty(exports, "safeGetAddress", { enumerable: true, get: function () { return blue_sdk_viem_1.safeGetAddress; } });
23
+ Object.defineProperty(exports, "safeParseNumber", { enumerable: true, get: function () { return blue_sdk_viem_1.safeParseNumber; } });
24
+ Object.defineProperty(exports, "safeParseUnits", { enumerable: true, get: function () { return blue_sdk_viem_1.safeParseUnits; } });
25
+ var morpho_ts_1 = require("@morpho-org/morpho-ts");
26
+ Object.defineProperty(exports, "bigIntComparator", { enumerable: true, get: function () { return morpho_ts_1.bigIntComparator; } });
27
+ Object.defineProperty(exports, "createGetValue", { enumerable: true, get: function () { return morpho_ts_1.createGetValue; } });
28
+ Object.defineProperty(exports, "createHasValue", { enumerable: true, get: function () { return morpho_ts_1.createHasValue; } });
29
+ Object.defineProperty(exports, "deepFreeze", { enumerable: true, get: function () { return morpho_ts_1.deepFreeze; } });
30
+ Object.defineProperty(exports, "entries", { enumerable: true, get: function () { return morpho_ts_1.entries; } });
31
+ Object.defineProperty(exports, "filterDefined", { enumerable: true, get: function () { return morpho_ts_1.filterDefined; } });
32
+ Object.defineProperty(exports, "fromEntries", { enumerable: true, get: function () { return morpho_ts_1.fromEntries; } });
33
+ Object.defineProperty(exports, "getLast", { enumerable: true, get: function () { return morpho_ts_1.getLast; } });
34
+ Object.defineProperty(exports, "getLastDefined", { enumerable: true, get: function () { return morpho_ts_1.getLastDefined; } });
35
+ Object.defineProperty(exports, "getSubdomainBaseUrl", { enumerable: true, get: function () { return morpho_ts_1.getSubdomainBaseUrl; } });
36
+ Object.defineProperty(exports, "getValue", { enumerable: true, get: function () { return morpho_ts_1.getValue; } });
37
+ Object.defineProperty(exports, "hasValue", { enumerable: true, get: function () { return morpho_ts_1.hasValue; } });
38
+ Object.defineProperty(exports, "isDefined", { enumerable: true, get: function () { return morpho_ts_1.isDefined; } });
39
+ Object.defineProperty(exports, "isNotNull", { enumerable: true, get: function () { return morpho_ts_1.isNotNull; } });
40
+ Object.defineProperty(exports, "isNotUndefined", { enumerable: true, get: function () { return morpho_ts_1.isNotUndefined; } });
41
+ Object.defineProperty(exports, "keys", { enumerable: true, get: function () { return morpho_ts_1.keys; } });
42
+ Object.defineProperty(exports, "mergeEntries", { enumerable: true, get: function () { return morpho_ts_1.mergeEntries; } });
43
+ Object.defineProperty(exports, "retryPromiseLinearBackoff", { enumerable: true, get: function () { return morpho_ts_1.retryPromiseLinearBackoff; } });
44
+ Object.defineProperty(exports, "Time", { enumerable: true, get: function () { return morpho_ts_1.Time; } });
45
+ Object.defineProperty(exports, "transformValue", { enumerable: true, get: function () { return morpho_ts_1.transformValue; } });
46
+ Object.defineProperty(exports, "values", { enumerable: true, get: function () { return morpho_ts_1.values; } });
47
+ var computeReallocations_js_1 = require("./helpers/computeReallocations.js");
48
+ Object.defineProperty(exports, "computeReallocations", { enumerable: true, get: function () { return computeReallocations_js_1.computeReallocations; } });
49
+ var metadata_js_1 = require("./helpers/metadata.js");
50
+ Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return metadata_js_1.addTransactionMetadata; } });
51
+ var slippage_js_1 = require("./helpers/slippage.js");
52
+ Object.defineProperty(exports, "computeMaxRepaySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxRepaySharePrice; } });
53
+ Object.defineProperty(exports, "computeMinBorrowSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinBorrowSharePrice; } });
54
+ var validate_js_1 = require("./helpers/validate.js");
55
+ Object.defineProperty(exports, "validateAccrualPosition", { enumerable: true, get: function () { return validate_js_1.validateAccrualPosition; } });
56
+ Object.defineProperty(exports, "validateChainId", { enumerable: true, get: function () { return validate_js_1.validateChainId; } });
57
+ Object.defineProperty(exports, "validateNativeCollateral", { enumerable: true, get: function () { return validate_js_1.validateNativeCollateral; } });
58
+ Object.defineProperty(exports, "validatePositionHealth", { enumerable: true, get: function () { return validate_js_1.validatePositionHealth; } });
59
+ Object.defineProperty(exports, "validatePositionHealthAfterWithdraw", { enumerable: true, get: function () { return validate_js_1.validatePositionHealthAfterWithdraw; } });
60
+ Object.defineProperty(exports, "validateReallocations", { enumerable: true, get: function () { return validate_js_1.validateReallocations; } });
61
+ Object.defineProperty(exports, "validateRepayAmount", { enumerable: true, get: function () { return validate_js_1.validateRepayAmount; } });
62
+ Object.defineProperty(exports, "validateRepayParams", { enumerable: true, get: function () { return validate_js_1.validateRepayParams; } });
63
+ Object.defineProperty(exports, "validateRepayShares", { enumerable: true, get: function () { return validate_js_1.validateRepayShares; } });
64
+ Object.defineProperty(exports, "validateSlippageTolerance", { enumerable: true, get: function () { return validate_js_1.validateSlippageTolerance; } });
65
+ Object.defineProperty(exports, "validateUserAddress", { enumerable: true, get: function () { return validate_js_1.validateUserAddress; } });