@morpho-org/morpho-sdk 2.1.1 → 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 (188) 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 +1 -1
  17. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  18. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -0
  19. package/lib/cjs/actions/vaultV1/deposit.js +13 -14
  20. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -0
  21. package/lib/cjs/actions/vaultV1/migrateToV2.js +11 -9
  22. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -0
  23. package/lib/cjs/actions/vaultV2/deposit.js +13 -14
  24. package/lib/cjs/addresses.d.ts +2 -0
  25. package/lib/cjs/addresses.js +18 -0
  26. package/lib/cjs/augment/AccrualPosition.d.ts +9 -0
  27. package/lib/cjs/augment/AccrualPosition.js +8 -0
  28. package/lib/cjs/augment/AccrualVault.d.ts +8 -0
  29. package/lib/cjs/augment/AccrualVault.js +7 -0
  30. package/lib/cjs/augment/Holding.d.ts +8 -0
  31. package/lib/cjs/augment/Holding.js +7 -0
  32. package/lib/cjs/augment/Market.d.ts +8 -0
  33. package/lib/cjs/augment/Market.js +7 -0
  34. package/lib/cjs/augment/MarketParams.d.ts +8 -0
  35. package/lib/cjs/augment/MarketParams.js +7 -0
  36. package/lib/cjs/augment/Position.d.ts +8 -0
  37. package/lib/cjs/augment/Position.js +7 -0
  38. package/lib/cjs/augment/Token.d.ts +8 -0
  39. package/lib/cjs/augment/Token.js +7 -0
  40. package/lib/cjs/augment/User.d.ts +8 -0
  41. package/lib/cjs/augment/User.js +7 -0
  42. package/lib/cjs/augment/Vault.d.ts +8 -0
  43. package/lib/cjs/augment/Vault.js +7 -0
  44. package/lib/cjs/augment/VaultConfig.d.ts +8 -0
  45. package/lib/cjs/augment/VaultConfig.js +7 -0
  46. package/lib/cjs/augment/VaultMarketAllocation.d.ts +8 -0
  47. package/lib/cjs/augment/VaultMarketAllocation.js +7 -0
  48. package/lib/cjs/augment/VaultMarketConfig.d.ts +8 -0
  49. package/lib/cjs/augment/VaultMarketConfig.js +7 -0
  50. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  51. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +8 -0
  52. package/lib/cjs/augment/VaultUser.d.ts +8 -0
  53. package/lib/cjs/augment/VaultUser.js +7 -0
  54. package/lib/cjs/augment.d.ts +14 -0
  55. package/lib/cjs/augment.js +16 -0
  56. package/lib/cjs/bundler/actions.d.ts +555 -0
  57. package/lib/cjs/bundler/actions.js +953 -0
  58. package/lib/cjs/bundler/index.d.ts +2 -0
  59. package/lib/cjs/bundler/index.js +18 -0
  60. package/lib/cjs/bundler/types.d.ts +181 -0
  61. package/lib/cjs/bundler/types.js +2 -0
  62. package/lib/cjs/constants.d.ts +3 -0
  63. package/lib/cjs/constants.js +32 -0
  64. package/lib/cjs/entities/index.d.ts +6 -3
  65. package/lib/cjs/entities/index.js +41 -17
  66. package/lib/cjs/entities/marketV1/marketV1.d.ts +45 -11
  67. package/lib/cjs/entities/marketV1/marketV1.js +27 -12
  68. package/lib/cjs/entities/reallocationData.d.ts +193 -0
  69. package/lib/cjs/entities/reallocationData.js +406 -0
  70. package/lib/cjs/errors.d.ts +2 -0
  71. package/lib/cjs/errors.js +18 -0
  72. package/lib/cjs/fetch.d.ts +1 -0
  73. package/lib/cjs/fetch.js +30 -0
  74. package/lib/cjs/format.d.ts +2 -0
  75. package/lib/cjs/format.js +22 -0
  76. package/lib/cjs/helpers/computeReallocations.d.ts +48 -8
  77. package/lib/cjs/helpers/computeReallocations.js +120 -32
  78. package/lib/cjs/helpers/constant.d.ts +17 -0
  79. package/lib/cjs/helpers/constant.js +30 -1
  80. package/lib/cjs/helpers/index.d.ts +1 -0
  81. package/lib/cjs/helpers/index.js +9 -1
  82. package/lib/cjs/helpers/validate.d.ts +2 -0
  83. package/lib/cjs/helpers/validate.js +14 -2
  84. package/lib/cjs/index.d.ts +0 -1
  85. package/lib/cjs/index.js +0 -1
  86. package/lib/cjs/types/client.d.ts +1 -1
  87. package/lib/cjs/types/error.d.ts +87 -1
  88. package/lib/cjs/types/error.js +119 -1
  89. package/lib/cjs/types/sharedLiquidity.d.ts +43 -3
  90. package/lib/cjs/types.d.ts +3 -0
  91. package/lib/cjs/types.js +17 -0
  92. package/lib/cjs/utils.d.ts +9 -0
  93. package/lib/cjs/utils.js +65 -0
  94. package/lib/esm/abis.d.ts +2816 -0
  95. package/lib/esm/abis.js +1922 -0
  96. package/lib/esm/actions/index.d.ts +3 -0
  97. package/lib/esm/actions/marketV1/borrow.js +2 -5
  98. package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +2 -3
  99. package/lib/esm/actions/marketV1/buildReallocationActions.js +1 -2
  100. package/lib/esm/actions/marketV1/repay.d.ts +2 -0
  101. package/lib/esm/actions/marketV1/repay.js +4 -5
  102. package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  103. package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +4 -5
  104. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +2 -0
  105. package/lib/esm/actions/marketV1/supplyCollateral.js +4 -5
  106. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
  107. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +4 -5
  108. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +1 -1
  109. package/lib/esm/actions/requirements/getRequirementsAction.d.ts +1 -1
  110. package/lib/esm/actions/requirements/getRequirementsApproval.js +1 -1
  111. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -0
  112. package/lib/esm/actions/vaultV1/deposit.js +3 -4
  113. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -0
  114. package/lib/esm/actions/vaultV1/migrateToV2.js +3 -1
  115. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -0
  116. package/lib/esm/actions/vaultV2/deposit.js +3 -4
  117. package/lib/esm/addresses.d.ts +2 -0
  118. package/lib/esm/addresses.js +1 -0
  119. package/lib/esm/augment/AccrualPosition.d.ts +9 -0
  120. package/lib/esm/augment/AccrualPosition.js +5 -0
  121. package/lib/esm/augment/AccrualVault.d.ts +8 -0
  122. package/lib/esm/augment/AccrualVault.js +4 -0
  123. package/lib/esm/augment/Holding.d.ts +8 -0
  124. package/lib/esm/augment/Holding.js +4 -0
  125. package/lib/esm/augment/Market.d.ts +8 -0
  126. package/lib/esm/augment/Market.js +4 -0
  127. package/lib/esm/augment/MarketParams.d.ts +8 -0
  128. package/lib/esm/augment/MarketParams.js +4 -0
  129. package/lib/esm/augment/Position.d.ts +8 -0
  130. package/lib/esm/augment/Position.js +4 -0
  131. package/lib/esm/augment/Token.d.ts +8 -0
  132. package/lib/esm/augment/Token.js +4 -0
  133. package/lib/esm/augment/User.d.ts +8 -0
  134. package/lib/esm/augment/User.js +4 -0
  135. package/lib/esm/augment/Vault.d.ts +8 -0
  136. package/lib/esm/augment/Vault.js +4 -0
  137. package/lib/esm/augment/VaultConfig.d.ts +8 -0
  138. package/lib/esm/augment/VaultConfig.js +4 -0
  139. package/lib/esm/augment/VaultMarketAllocation.d.ts +8 -0
  140. package/lib/esm/augment/VaultMarketAllocation.js +4 -0
  141. package/lib/esm/augment/VaultMarketConfig.d.ts +8 -0
  142. package/lib/esm/augment/VaultMarketConfig.js +4 -0
  143. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  144. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +5 -0
  145. package/lib/esm/augment/VaultUser.d.ts +8 -0
  146. package/lib/esm/augment/VaultUser.js +4 -0
  147. package/lib/esm/augment.d.ts +14 -0
  148. package/lib/esm/augment.js +14 -0
  149. package/lib/esm/bundler/actions.d.ts +555 -0
  150. package/lib/esm/bundler/actions.js +950 -0
  151. package/lib/esm/bundler/index.d.ts +2 -0
  152. package/lib/esm/bundler/index.js +2 -0
  153. package/lib/esm/bundler/types.d.ts +181 -0
  154. package/lib/esm/bundler/types.js +1 -0
  155. package/lib/esm/constants.d.ts +3 -0
  156. package/lib/esm/constants.js +3 -0
  157. package/lib/esm/entities/index.d.ts +6 -3
  158. package/lib/esm/entities/index.js +5 -3
  159. package/lib/esm/entities/marketV1/marketV1.d.ts +45 -11
  160. package/lib/esm/entities/marketV1/marketV1.js +28 -13
  161. package/lib/esm/entities/reallocationData.d.ts +193 -0
  162. package/lib/esm/entities/reallocationData.js +402 -0
  163. package/lib/esm/errors.d.ts +2 -0
  164. package/lib/esm/errors.js +1 -0
  165. package/lib/esm/fetch.d.ts +1 -0
  166. package/lib/esm/fetch.js +1 -0
  167. package/lib/esm/format.d.ts +2 -0
  168. package/lib/esm/format.js +1 -0
  169. package/lib/esm/helpers/computeReallocations.d.ts +48 -8
  170. package/lib/esm/helpers/computeReallocations.js +119 -31
  171. package/lib/esm/helpers/constant.d.ts +17 -0
  172. package/lib/esm/helpers/constant.js +30 -1
  173. package/lib/esm/helpers/index.d.ts +1 -0
  174. package/lib/esm/helpers/index.js +1 -0
  175. package/lib/esm/helpers/validate.d.ts +2 -0
  176. package/lib/esm/helpers/validate.js +12 -1
  177. package/lib/esm/index.d.ts +0 -1
  178. package/lib/esm/index.js +0 -1
  179. package/lib/esm/types/client.d.ts +1 -1
  180. package/lib/esm/types/error.d.ts +87 -1
  181. package/lib/esm/types/error.js +112 -0
  182. package/lib/esm/types/sharedLiquidity.d.ts +43 -3
  183. package/lib/esm/types.d.ts +3 -0
  184. package/lib/esm/types.js +1 -0
  185. package/lib/esm/utils.d.ts +9 -0
  186. package/lib/esm/utils.js +7 -0
  187. package/package.json +118 -11
  188. package/src/index.ts +0 -1
@@ -1,25 +1,119 @@
1
1
  import { MarketUtils, MathLib } from "@morpho-org/blue-sdk";
2
- import { DEFAULT_SUPPLY_TARGET_UTILIZATION } from "@morpho-org/bundler-sdk-viem";
3
2
  import { InsufficientSharedLiquidityError, MissingPublicAllocatorConfigError, } from "../types/index.js";
3
+ import { DEFAULT_SUPPLY_TARGET_UTILIZATION } from "./constant.js";
4
+ import { compareMarketIds } from "./validate.js";
5
+ const groupWithdrawalsByVault = (withdrawals) => {
6
+ const groups = [];
7
+ const groupsByVault = new Map();
8
+ for (const [index, { vault, id, assets }] of withdrawals.entries()) {
9
+ if (assets <= 0n)
10
+ continue;
11
+ let group = groupsByVault.get(vault);
12
+ if (group == null) {
13
+ group = {
14
+ vault,
15
+ firstIndex: index,
16
+ totalAssets: 0n,
17
+ withdrawals: [],
18
+ };
19
+ groupsByVault.set(vault, group);
20
+ groups.push(group);
21
+ }
22
+ group.totalAssets += assets;
23
+ group.withdrawals.push({ id, assets });
24
+ }
25
+ return groups.sort((a, b) => {
26
+ if (a.totalAssets > b.totalAssets)
27
+ return -1;
28
+ if (a.totalAssets < b.totalAssets)
29
+ return 1;
30
+ return a.firstIndex - b.firstIndex;
31
+ });
32
+ };
33
+ const capVaultWithdrawals = (withdrawals, assets) => {
34
+ const cappedWithdrawals = [];
35
+ let remainingAssets = assets;
36
+ for (const withdrawal of withdrawals) {
37
+ const cappedAssets = MathLib.min(withdrawal.assets, remainingAssets);
38
+ if (cappedAssets <= 0n)
39
+ continue;
40
+ const existing = cappedWithdrawals.find((item) => item.id === withdrawal.id);
41
+ if (existing != null) {
42
+ existing.assets += cappedAssets;
43
+ }
44
+ else {
45
+ cappedWithdrawals.push({
46
+ id: withdrawal.id,
47
+ assets: cappedAssets,
48
+ });
49
+ }
50
+ remainingAssets -= cappedAssets;
51
+ if (remainingAssets === 0n)
52
+ break;
53
+ }
54
+ return cappedWithdrawals;
55
+ };
4
56
  /**
5
57
  * Computes vault reallocations for a borrow operation on a target market.
6
58
  *
7
- * Replicates the shared liquidity algorithm from `populateSubBundle` in
8
- * `@morpho-org/bundler-sdk-viem`. First attempts "friendly" reallocations
9
- * respecting withdrawal utilization targets, then falls back to aggressive
10
- * reallocations (100% withdrawal utilization) if liquidity is still insufficient.
59
+ * First attempts "friendly" reallocations respecting withdrawal utilization
60
+ * targets, then falls back to aggressive reallocations (100% withdrawal
61
+ * utilization) if liquidity is still insufficient.
11
62
  *
12
- * @param params.reallocationData - The simulation state containing market, vault, and position data.
63
+ * @remarks Pass `options.timestamp` from the same block used to fetch `reallocationData`; when omitted, market accrual falls back to the target market's `lastUpdate`, which can diverge from the source rows' fetch block. Per-market `maxWithdrawalUtilization` overrides apply only to phase 1; phase 2 forces 100% utilization on every source market.
64
+ * @param params.reallocationData - The local state containing market, vault, and position data.
13
65
  * @param params.marketId - The target market to reallocate liquidity into.
14
66
  * @param params.borrowAmount - The intended borrow amount (used to compute post-borrow utilization).
15
67
  * @param params.options - Optional reallocation computation options.
16
68
  * @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
17
- * @throws {InsufficientSharedLiquidityError} If shared liquidity cannot cover the borrow shortfall on the target market — preventing fee-bearing reallocations from being attached to a borrow that would still revert onchain.
69
+ * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the borrow shortfall on the target market — preventing fee-bearing reallocations from being attached to a borrow that would still revert onchain.
70
+ * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
71
+ * @example
72
+ * ```ts
73
+ * import { createPublicClient, http, parseUnits } from "viem";
74
+ * import { mainnet } from "viem/chains";
75
+ * import { markets, vaults } from "@morpho-org/morpho-test";
76
+ * import {
77
+ * computeReallocations,
78
+ * morphoViemExtension,
79
+ * } from "@morpho-org/morpho-sdk";
80
+ *
81
+ * const client = createPublicClient({
82
+ * chain: mainnet,
83
+ * transport: http(),
84
+ * }).extend(morphoViemExtension());
85
+ *
86
+ * const userAddress = "0x000000000000000000000000000000000000dEaD";
87
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
88
+ * const market = client.morpho.marketV1(marketParams, mainnet.id);
89
+ * const block = await client.getBlock();
90
+ * const reallocationData = await market.getReallocationData({
91
+ * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
92
+ * block: { number: block.number, timestamp: block.timestamp },
93
+ * });
94
+ * const borrowAmount = parseUnits("1000", 6);
95
+ * const reallocations = computeReallocations({
96
+ * reallocationData,
97
+ * marketId: marketParams.id,
98
+ * borrowAmount,
99
+ * options: { timestamp: block.timestamp },
100
+ * });
101
+ * const positionData = await market.getPositionData(userAddress);
102
+ * const borrow = market.borrow({
103
+ * userAddress,
104
+ * amount: borrowAmount,
105
+ * positionData,
106
+ * reallocations,
107
+ * });
108
+ * // borrow.buildTx() includes any required PublicAllocator reallocations.
109
+ * ```
18
110
  */
19
111
  export const computeReallocations = ({ reallocationData: data, marketId, borrowAmount, options, }) => {
20
112
  if (options?.enabled === false)
21
113
  return [];
22
- const market = data.getMarket(marketId).accrueInterest(data.block.timestamp);
114
+ // ReallocationData does not retain the fetch block; pass that block timestamp
115
+ // to compute against the same accrued state, otherwise Market defaults to lastUpdate.
116
+ const market = data.getMarket(marketId).accrueInterest(options?.timestamp);
23
117
  const newTotalBorrowAssets = market.totalBorrowAssets + borrowAmount;
24
118
  const newTotalSupplyAssets = market.totalSupplyAssets;
25
119
  const supplyTargetUtilization = options?.supplyTargetUtilization?.[market.params.id] ??
@@ -55,27 +149,20 @@ export const computeReallocations = ({ reallocationData: data, marketId, borrowA
55
149
  const absoluteShortfall = newTotalBorrowAssets > newTotalSupplyAssets
56
150
  ? newTotalBorrowAssets - newTotalSupplyAssets
57
151
  : 0n;
58
- // Group withdrawals by vault, capping total at requiredAssets.
59
- const reallocationsMap = {};
152
+ const reallocations = [];
60
153
  let totalReallocated = 0n;
61
- for (const { vault, ...withdrawal } of withdrawals) {
62
- const vaultReallocations = (reallocationsMap[vault] ??= []);
63
- const existing = vaultReallocations.find((item) => item.id === withdrawal.id);
64
- const reallocatedAssets = MathLib.min(withdrawal.assets, requiredAssets);
154
+ let remainingRequiredAssets = requiredAssets;
155
+ for (const group of groupWithdrawalsByVault(withdrawals)) {
156
+ const reallocatedAssets = MathLib.min(group.totalAssets, remainingRequiredAssets);
65
157
  if (reallocatedAssets <= 0n)
66
158
  continue;
67
- if (existing != null) {
68
- existing.assets += reallocatedAssets;
69
- }
70
- else {
71
- vaultReallocations.push({
72
- ...withdrawal,
73
- assets: reallocatedAssets,
74
- });
75
- }
76
- requiredAssets -= reallocatedAssets;
159
+ reallocations.push({
160
+ vault: group.vault,
161
+ withdrawals: capVaultWithdrawals(group.withdrawals, reallocatedAssets),
162
+ });
163
+ remainingRequiredAssets -= reallocatedAssets;
77
164
  totalReallocated += reallocatedAssets;
78
- if (requiredAssets === 0n)
165
+ if (remainingRequiredAssets === 0n)
79
166
  break;
80
167
  }
81
168
  // Refuse fee-bearing partial plans for an unreachable borrow.
@@ -87,10 +174,10 @@ export const computeReallocations = ({ reallocationData: data, marketId, borrowA
87
174
  });
88
175
  }
89
176
  // Transform into VaultReallocation[] format.
90
- return Object.entries(reallocationsMap)
91
- .filter(([, vaultWithdrawals]) => vaultWithdrawals.length > 0)
92
- .map(([vault, vaultWithdrawals]) => ({
93
- vault: vault,
177
+ return reallocations
178
+ .filter(({ withdrawals: vaultWithdrawals }) => vaultWithdrawals.length > 0)
179
+ .map(({ vault, withdrawals: vaultWithdrawals }) => ({
180
+ vault,
94
181
  fee: (() => {
95
182
  const config = data.getVault(vault).publicAllocatorConfig;
96
183
  if (config == null) {
@@ -99,8 +186,9 @@ export const computeReallocations = ({ reallocationData: data, marketId, borrowA
99
186
  return config.fee;
100
187
  })(),
101
188
  withdrawals: vaultWithdrawals
102
- // Reallocation withdrawals must be sorted by market id in ascending order.
103
- .sort(({ id: idA }, { id: idB }) => idA > idB ? 1 : idA < idB ? -1 : 0)
189
+ // Reallocation withdrawals must be sorted by market id in ascending
190
+ // order. Normalize first because `MarketId` can be mixed-case hex.
191
+ .sort(({ id: idA }, { id: idB }) => compareMarketIds(idA, idB))
104
192
  .map(({ id, assets }) => ({
105
193
  marketParams: data.getMarket(id).params,
106
194
  amount: assets,
@@ -1,6 +1,23 @@
1
+ import { type Address } from "viem";
1
2
  /** Maximum slippage tolerance: 10% */
2
3
  export declare const MAX_SLIPPAGE_TOLERANCE: bigint;
3
4
  /** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
4
5
  export declare const DEFAULT_LLTV_BUFFER: bigint;
5
6
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
6
7
  export declare const MAX_ABSOLUTE_SHARE_PRICE: bigint;
8
+ /**
9
+ * The default maximum utilization allowed to reach when withdrawing shared liquidity.
10
+ */
11
+ export declare const DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = 920000000000000000n;
12
+ /**
13
+ * The default target utilization above which shared liquidity reallocations are triggered.
14
+ */
15
+ export declare const DEFAULT_SUPPLY_TARGET_UTILIZATION = 905000000000000000n;
16
+ /**
17
+ * Tokens that require setting allowance from zero before changing approval.
18
+ */
19
+ export declare const APPROVE_ONLY_ONCE_TOKENS: Partial<Record<number, Address[]>>;
20
+ /**
21
+ * Token-specific maximum approval amounts for tokens that cannot use uint256 max.
22
+ */
23
+ export declare const MAX_TOKEN_APPROVALS: Partial<Record<number, Record<Address, bigint>>>;
@@ -1,7 +1,36 @@
1
- import { MathLib } from "@morpho-org/blue-sdk";
1
+ import { ChainId, MathLib } from "@morpho-org/blue-sdk";
2
+ import { maxUint96 } from "viem";
2
3
  /** Maximum slippage tolerance: 10% */
3
4
  export const MAX_SLIPPAGE_TOLERANCE = MathLib.WAD / 10n;
4
5
  /** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
5
6
  export const DEFAULT_LLTV_BUFFER = MathLib.WAD / 200n;
6
7
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
7
8
  export const MAX_ABSOLUTE_SHARE_PRICE = 100n * MathLib.RAY;
9
+ /**
10
+ * The default maximum utilization allowed to reach when withdrawing shared liquidity.
11
+ */
12
+ export const DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = 920000000000000000n;
13
+ /**
14
+ * The default target utilization above which shared liquidity reallocations are triggered.
15
+ */
16
+ export const DEFAULT_SUPPLY_TARGET_UTILIZATION = 905000000000000000n;
17
+ /**
18
+ * Tokens that require setting allowance from zero before changing approval.
19
+ */
20
+ export const APPROVE_ONLY_ONCE_TOKENS = {
21
+ [ChainId.EthMainnet]: [
22
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT
23
+ "0xD533a949740bb3306d119CC777fa900bA034cd52", // CRV
24
+ ],
25
+ };
26
+ /**
27
+ * Token-specific maximum approval amounts for tokens that cannot use uint256 max.
28
+ */
29
+ export const MAX_TOKEN_APPROVALS = {
30
+ [ChainId.EthMainnet]: {
31
+ "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984": maxUint96, // UNI
32
+ "0xfAbA6f8e4a5E8Ab82F62fe7C39859FA577269BE3": maxUint96, // ONDO
33
+ "0xc00e94Cb662C3520282E6f5717214004A7f26888": maxUint96, // COMP
34
+ "0x6f40d4A6237C257fff2dB00FA0510DeEECd303eb": maxUint96, // FLUID
35
+ },
36
+ };
@@ -1,4 +1,5 @@
1
1
  export { computeReallocations } from "./computeReallocations.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
2
3
  export { addTransactionMetadata } from "./metadata.js";
3
4
  export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./slippage.js";
4
5
  export { validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayParams, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./validate.js";
@@ -1,4 +1,5 @@
1
1
  export { computeReallocations } from "./computeReallocations.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
2
3
  export { addTransactionMetadata } from "./metadata.js";
3
4
  export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./slippage.js";
4
5
  export { validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayParams, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./validate.js";
@@ -1,6 +1,8 @@
1
1
  import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
2
2
  import { type Address } from "viem";
3
3
  import { type VaultReallocation } from "../types/index.js";
4
+ /** @internal */
5
+ export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => 0 | 1 | -1;
4
6
  /**
5
7
  * Asserts that the client has a connected account AND that it matches
6
8
  * the provided user address.
@@ -3,6 +3,16 @@ import { isDefined } from "@morpho-org/morpho-ts";
3
3
  import { isAddressEqual } from "viem";
4
4
  import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, MutuallyExclusiveRepayAmountsError, NativeAmountOnNonWNativeCollateralError, NegativeReallocationFeeError, NegativeSlippageToleranceError, NonPositiveReallocationAmountError, NonPositiveRepayAmountError, NonPositiveRepayMaxSharePriceError, NonPositiveTransferAmountError, ReallocationWithdrawalOnTargetMarketError, RepayExceedsDebtError, RepaySharesExceedDebtError, TransferAmountNotEqualToAssetsError, UnsortedReallocationWithdrawalsError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, } from "../types/index.js";
5
5
  import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE } from "./constant.js";
6
+ /** @internal */
7
+ export const compareMarketIds = (idA, idB) => {
8
+ const normalizedIdA = idA.toLowerCase();
9
+ const normalizedIdB = idB.toLowerCase();
10
+ if (normalizedIdA > normalizedIdB)
11
+ return 1;
12
+ if (normalizedIdA < normalizedIdB)
13
+ return -1;
14
+ return 0;
15
+ };
6
16
  /**
7
17
  * Asserts that the client has a connected account AND that it matches
8
18
  * the provided user address.
@@ -252,7 +262,8 @@ export const validateReallocations = (reallocations, targetMarketId) => {
252
262
  if (w.marketParams.id === targetMarketId) {
253
263
  throw new ReallocationWithdrawalOnTargetMarketError(r.vault, w.marketParams.id);
254
264
  }
255
- if (prevId !== undefined && w.marketParams.id <= prevId) {
265
+ if (prevId !== undefined &&
266
+ compareMarketIds(w.marketParams.id, prevId) <= 0) {
256
267
  throw new UnsortedReallocationWithdrawalsError(r.vault, w.marketParams.id);
257
268
  }
258
269
  prevId = w.marketParams.id;
@@ -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/esm/index.js CHANGED
@@ -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";
@@ -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);
@@ -196,6 +240,12 @@ export declare class RepaySharesExceedDebtError extends Error {
196
240
  export declare class MissingPublicAllocatorConfigError extends Error {
197
241
  constructor(vault: string);
198
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
+ }
199
249
  /**
200
250
  * Thrown when shared liquidity selected by `computeReallocations` cannot cover
201
251
  * the absolute borrow shortfall on the target market — the resulting
@@ -215,6 +265,42 @@ export declare class InsufficientSharedLiquidityError extends Error {
215
265
  readonly available: bigint;
216
266
  });
217
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
+ }
218
304
  /** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
219
305
  export declare class NonPositiveMinBorrowSharePriceError extends Error {
220
306
  constructor(market: string);
@@ -1,3 +1,55 @@
1
+ import { UnknownDataError } from "@morpho-org/blue-sdk";
2
+ /**
3
+ * Typed errors thrown while encoding supported Bundler3 actions.
4
+ *
5
+ * @remarks
6
+ * Import these classes through `@morpho-org/morpho-sdk` when handling
7
+ * failures from `BundlerAction`.
8
+ */
9
+ export var BundlerErrors;
10
+ (function (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
+ super("missing signature");
27
+ }
28
+ }
29
+ BundlerErrors.MissingSignature = MissingSignature;
30
+ /**
31
+ * Thrown when an action is unsupported on the requested chain.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
36
+ *
37
+ * if (error instanceof BundlerErrors.UnexpectedAction) {
38
+ * // Remove or replace the action for the selected chain.
39
+ * }
40
+ * ```
41
+ */
42
+ class UnexpectedAction extends Error {
43
+ /**
44
+ * @param type - Unsupported Bundler3 action discriminator or name.
45
+ * @param chainId - Chain where the action was requested.
46
+ */
47
+ constructor(type, chainId) {
48
+ super(`unexpected action "${type}" on chain "${chainId}"`);
49
+ }
50
+ }
51
+ BundlerErrors.UnexpectedAction = UnexpectedAction;
52
+ })(BundlerErrors || (BundlerErrors = {}));
1
53
  /** Thrown when an asset amount is required to be positive but is zero or negative. */
2
54
  export class NonPositiveAssetAmountError extends Error {
3
55
  constructor(origin) {
@@ -262,6 +314,16 @@ export class MissingPublicAllocatorConfigError extends Error {
262
314
  super(`Vault ${vault} has no public allocator configured but was selected for reallocation`);
263
315
  }
264
316
  }
317
+ /** Thrown when a reallocation attempts to use a disabled vault market. */
318
+ export class DisabledReallocationMarketError extends Error {
319
+ vault;
320
+ marketId;
321
+ constructor(vault, marketId) {
322
+ super(`Vault ${vault} has disabled market ${marketId}. Remove it from reallocations or re-enable the market before reallocating.`);
323
+ this.vault = vault;
324
+ this.marketId = marketId;
325
+ }
326
+ }
265
327
  /**
266
328
  * Thrown when shared liquidity selected by `computeReallocations` cannot cover
267
329
  * the absolute borrow shortfall on the target market — the resulting
@@ -276,6 +338,56 @@ export class InsufficientSharedLiquidityError extends Error {
276
338
  this.params = params;
277
339
  }
278
340
  }
341
+ /** Thrown when reallocation state does not contain a requested market. */
342
+ export class UnknownReallocationMarketError extends UnknownDataError {
343
+ marketId;
344
+ /**
345
+ * @param marketId - Missing market id.
346
+ */
347
+ constructor(marketId) {
348
+ super(`unknown reallocation market "${marketId}"`);
349
+ this.marketId = marketId;
350
+ }
351
+ }
352
+ /** Thrown when reallocation state does not contain a requested vault. */
353
+ export class UnknownReallocationVaultError extends UnknownDataError {
354
+ vault;
355
+ /**
356
+ * @param vault - Missing vault address.
357
+ */
358
+ constructor(vault) {
359
+ super(`unknown reallocation vault "${vault}"`);
360
+ this.vault = vault;
361
+ }
362
+ }
363
+ /** Thrown when reallocation state does not contain a requested vault-market config. */
364
+ export class UnknownReallocationVaultMarketConfigError extends UnknownDataError {
365
+ vault;
366
+ marketId;
367
+ /**
368
+ * @param vault - Vault address for the missing config.
369
+ * @param marketId - Market id for the missing config.
370
+ */
371
+ constructor(vault, marketId) {
372
+ super(`unknown reallocation config for vault "${vault}" on market "${marketId}"`);
373
+ this.vault = vault;
374
+ this.marketId = marketId;
375
+ }
376
+ }
377
+ /** Thrown when reallocation state does not contain a requested market position. */
378
+ export class UnknownReallocationPositionError extends UnknownDataError {
379
+ user;
380
+ marketId;
381
+ /**
382
+ * @param user - Position owner address.
383
+ * @param marketId - Market id for the missing position.
384
+ */
385
+ constructor(user, marketId) {
386
+ super(`unknown reallocation position of "${user}" on market "${marketId}"`);
387
+ this.user = user;
388
+ this.marketId = marketId;
389
+ }
390
+ }
279
391
  /** Thrown when a market borrow's `minSharePrice` slippage bound is negative. */
280
392
  export class NonPositiveMinBorrowSharePriceError extends Error {
281
393
  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 @@
1
+ export * from "./types/index.js";
@@ -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,7 @@
1
+ export { AdaptiveCurveIrmLib, CapacityLimitReason, MarketUtils, MathLib, SharesMath, VaultUtils, } from "@morpho-org/blue-sdk";
2
+ export { decodeBytes32String, getAuthorizationTypedData, getDaiPermitTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
3
+ 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";
4
+ export { computeReallocations } from "./helpers/computeReallocations.js";
5
+ export { addTransactionMetadata } from "./helpers/metadata.js";
6
+ export { computeMaxRepaySharePrice, computeMinBorrowSharePrice, } from "./helpers/slippage.js";
7
+ export { validateAccrualPosition, validateChainId, validateNativeCollateral, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayParams, validateRepayShares, validateSlippageTolerance, validateUserAddress, } from "./helpers/validate.js";