@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,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.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 = void 0;
3
+ 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.NativeAmountOnNonWNativeAssetError = 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.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.NegativeWithdrawMinSharePriceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = 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) {
@@ -148,13 +201,15 @@ class ZeroCollateralAmountError extends Error {
148
201
  }
149
202
  }
150
203
  exports.ZeroCollateralAmountError = ZeroCollateralAmountError;
151
- /** Thrown when a collateral supply uses `nativeAmount` but the collateral token is not the chain's wNative. */
152
- class NativeAmountOnNonWNativeCollateralError extends Error {
153
- constructor(collateralToken, wNative) {
154
- super(`Cannot use nativeAmount: collateral token ${collateralToken} is not the wrapped native token ${wNative}`);
204
+ /** Thrown when an action uses `nativeAmount` but the target asset is not the chain's wNative. */
205
+ class NativeAmountOnNonWNativeAssetError extends Error {
206
+ constructor(asset, wNative) {
207
+ super(`Cannot use nativeAmount: asset ${asset} is not the wrapped native token ${wNative}`);
155
208
  }
156
209
  }
157
- exports.NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeCollateralError;
210
+ exports.NativeAmountOnNonWNativeAssetError = NativeAmountOnNonWNativeAssetError;
211
+ /** @deprecated Use {@link NativeAmountOnNonWNativeAssetError}. */
212
+ exports.NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeAssetError;
158
213
  /** Thrown when a borrow exceeds the LLTV-buffered safe maximum for the position. */
159
214
  class BorrowExceedsSafeLtvError extends Error {
160
215
  constructor(borrowAmount, maxSafeBorrow) {
@@ -204,10 +259,10 @@ class NonPositiveReallocationAmountError extends Error {
204
259
  }
205
260
  }
206
261
  exports.NonPositiveReallocationAmountError = NonPositiveReallocationAmountError;
207
- /** Thrown when a reallocation withdrawal references the borrow target market (which would be a no-op or self-deal). */
262
+ /** Thrown when a reallocation withdrawal references the operation's target market (which would be a no-op or self-deal). */
208
263
  class ReallocationWithdrawalOnTargetMarketError extends Error {
209
264
  constructor(vault, marketId) {
210
- super(`Reallocation withdrawal cannot include the borrow target market ${marketId} for vault ${vault}.`);
265
+ super(`Reallocation withdrawal cannot include the target market ${marketId} for vault ${vault}.`);
211
266
  }
212
267
  }
213
268
  exports.ReallocationWithdrawalOnTargetMarketError = ReallocationWithdrawalOnTargetMarketError;
@@ -309,21 +364,86 @@ class MissingPublicAllocatorConfigError extends Error {
309
364
  }
310
365
  }
311
366
  exports.MissingPublicAllocatorConfigError = MissingPublicAllocatorConfigError;
367
+ /** Thrown when a reallocation attempts to use a disabled vault market. */
368
+ class DisabledReallocationMarketError extends Error {
369
+ vault;
370
+ marketId;
371
+ constructor(vault, marketId) {
372
+ super(`Vault ${vault} has disabled market ${marketId}. Remove it from reallocations or re-enable the market before reallocating.`);
373
+ this.vault = vault;
374
+ this.marketId = marketId;
375
+ }
376
+ }
377
+ exports.DisabledReallocationMarketError = DisabledReallocationMarketError;
312
378
  /**
313
379
  * Thrown when shared liquidity selected by `computeReallocations` cannot cover
314
- * the absolute borrow shortfall on the target market — the resulting
315
- * `morphoBorrow` would still revert onchain.
380
+ * the operation's absolute shortfall on the target market — the resulting
381
+ * `morphoBorrow` or `morphoWithdraw` would still revert onchain.
316
382
  *
317
383
  * Pattern-match on the class and inspect `params` to surface the gap to users.
318
384
  */
319
385
  class InsufficientSharedLiquidityError extends Error {
320
386
  params;
321
387
  constructor(params) {
322
- super(`Shared liquidity is insufficient to cover the borrow on market ${params.marketId}: shortfall "${params.shortfall}", available "${params.available}". Reduce the borrow amount or wait for additional vault liquidity.`);
388
+ super(`Shared liquidity is insufficient on market ${params.marketId}: shortfall "${params.shortfall}", available "${params.available}". Reduce the operation amount or wait for additional vault liquidity.`);
323
389
  this.params = params;
324
390
  }
325
391
  }
326
392
  exports.InsufficientSharedLiquidityError = InsufficientSharedLiquidityError;
393
+ /** Thrown when reallocation state does not contain a requested market. */
394
+ class UnknownReallocationMarketError extends blue_sdk_1.UnknownDataError {
395
+ marketId;
396
+ /**
397
+ * @param marketId - Missing market id.
398
+ */
399
+ constructor(marketId) {
400
+ super(`unknown reallocation market "${marketId}"`);
401
+ this.marketId = marketId;
402
+ }
403
+ }
404
+ exports.UnknownReallocationMarketError = UnknownReallocationMarketError;
405
+ /** Thrown when reallocation state does not contain a requested vault. */
406
+ class UnknownReallocationVaultError extends blue_sdk_1.UnknownDataError {
407
+ vault;
408
+ /**
409
+ * @param vault - Missing vault address.
410
+ */
411
+ constructor(vault) {
412
+ super(`unknown reallocation vault "${vault}"`);
413
+ this.vault = vault;
414
+ }
415
+ }
416
+ exports.UnknownReallocationVaultError = UnknownReallocationVaultError;
417
+ /** Thrown when reallocation state does not contain a requested vault-market config. */
418
+ class UnknownReallocationVaultMarketConfigError extends blue_sdk_1.UnknownDataError {
419
+ vault;
420
+ marketId;
421
+ /**
422
+ * @param vault - Vault address for the missing config.
423
+ * @param marketId - Market id for the missing config.
424
+ */
425
+ constructor(vault, marketId) {
426
+ super(`unknown reallocation config for vault "${vault}" on market "${marketId}"`);
427
+ this.vault = vault;
428
+ this.marketId = marketId;
429
+ }
430
+ }
431
+ exports.UnknownReallocationVaultMarketConfigError = UnknownReallocationVaultMarketConfigError;
432
+ /** Thrown when reallocation state does not contain a requested market position. */
433
+ class UnknownReallocationPositionError extends blue_sdk_1.UnknownDataError {
434
+ user;
435
+ marketId;
436
+ /**
437
+ * @param user - Position owner address.
438
+ * @param marketId - Market id for the missing position.
439
+ */
440
+ constructor(user, marketId) {
441
+ super(`unknown reallocation position of "${user}" on market "${marketId}"`);
442
+ this.user = user;
443
+ this.marketId = marketId;
444
+ }
445
+ }
446
+ exports.UnknownReallocationPositionError = UnknownReallocationPositionError;
327
447
  /** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
328
448
  class NonPositiveMinBorrowSharePriceError extends Error {
329
449
  constructor(market) {
@@ -331,6 +451,77 @@ class NonPositiveMinBorrowSharePriceError extends Error {
331
451
  }
332
452
  }
333
453
  exports.NonPositiveMinBorrowSharePriceError = NonPositiveMinBorrowSharePriceError;
454
+ /** Thrown when a market loan-asset supply amount is negative. */
455
+ class NegativeSupplyAmountError extends Error {
456
+ constructor(market) {
457
+ super(`Supply amount must be non-negative for market: ${market}`);
458
+ }
459
+ }
460
+ exports.NegativeSupplyAmountError = NegativeSupplyAmountError;
461
+ /** Thrown when a market loan-asset supply's `maxSharePrice` slippage bound is negative. */
462
+ class NegativeSupplyMaxSharePriceError extends Error {
463
+ constructor(market) {
464
+ super(`Max share price must be non-negative for market: ${market}`);
465
+ }
466
+ }
467
+ exports.NegativeSupplyMaxSharePriceError = NegativeSupplyMaxSharePriceError;
468
+ /** Thrown when both `amount` and `nativeAmount` resolve to zero on a market loan-asset supply. */
469
+ class ZeroSupplyAmountError extends Error {
470
+ constructor(market) {
471
+ super(`Total supply amount must be positive for market: ${market}. Both amount and nativeAmount are zero.`);
472
+ }
473
+ }
474
+ exports.ZeroSupplyAmountError = ZeroSupplyAmountError;
475
+ /** Thrown when a market loan-asset withdraw has both `assets` and `shares` zero, or either negative. */
476
+ class NonPositiveWithdrawAmountError extends Error {
477
+ constructor(market) {
478
+ super(`Withdraw amount must be positive for market: ${market}`);
479
+ }
480
+ }
481
+ exports.NonPositiveWithdrawAmountError = NonPositiveWithdrawAmountError;
482
+ /** Thrown when a market loan-asset withdraw's `minSharePrice` slippage bound is negative. */
483
+ class NegativeWithdrawMinSharePriceError extends Error {
484
+ constructor(market) {
485
+ super(`Min share price must be non-negative for market: ${market}`);
486
+ }
487
+ }
488
+ exports.NegativeWithdrawMinSharePriceError = NegativeWithdrawMinSharePriceError;
489
+ /** Thrown when a loan-asset withdraw specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
490
+ class MutuallyExclusiveWithdrawAmountsError extends Error {
491
+ constructor(market) {
492
+ super(`Exactly one of assets or shares must be non-zero for market: ${market}. Both were provided.`);
493
+ }
494
+ }
495
+ exports.MutuallyExclusiveWithdrawAmountsError = MutuallyExclusiveWithdrawAmountsError;
496
+ /** Thrown when a loan-asset withdraw in assets mode exceeds the user's supplied assets in the market. */
497
+ class WithdrawExceedsSupplyError extends Error {
498
+ constructor(params) {
499
+ super(`Withdraw amount ${params.withdrawAmount} exceeds available supply ${params.available} for market: ${params.market}. Reduce withdraw amount.`);
500
+ }
501
+ }
502
+ exports.WithdrawExceedsSupplyError = WithdrawExceedsSupplyError;
503
+ /** Thrown when a loan-asset withdraw in shares mode exceeds the user's owned supply shares in the market. */
504
+ class WithdrawSharesExceedSupplyError extends Error {
505
+ constructor(params) {
506
+ super(`Withdraw shares ${params.withdrawShares} exceed owned supply shares ${params.supplyShares} for market: ${params.market}. Reduce withdraw shares.`);
507
+ }
508
+ }
509
+ exports.WithdrawSharesExceedSupplyError = WithdrawSharesExceedSupplyError;
510
+ /**
511
+ * Thrown when `computeReallocations` is called with a withdraw `amount` greater
512
+ * than the target market's current `totalSupplyAssets` — the post-withdraw
513
+ * supply would be negative, making the on-chain `morphoWithdraw` revert
514
+ * regardless of any reallocation. Caught here so callers do not pay
515
+ * PublicAllocator fees on an unreachable operation.
516
+ */
517
+ class ReallocationWithdrawExceedsMarketSupplyError extends Error {
518
+ params;
519
+ constructor(params) {
520
+ super(`Withdraw amount "${params.withdrawAmount}" exceeds market total supply "${params.totalSupplyAssets}" on market ${params.marketId}. Reduce the withdraw amount.`);
521
+ this.params = params;
522
+ }
523
+ }
524
+ exports.ReallocationWithdrawExceedsMarketSupplyError = ReallocationWithdrawExceedsMarketSupplyError;
334
525
  /** Thrown when a vault migration's source vault asset differs from the target vault asset. */
335
526
  class VaultAssetMismatchError extends Error {
336
527
  constructor(sourceAsset, targetAsset) {
@@ -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, validateNativeAsset, 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.validateNativeAsset = 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, "validateNativeAsset", { enumerable: true, get: function () { return validate_js_1.validateNativeAsset; } });
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; } });