@morpho-org/bundler-sdk-viem 2.1.4-next.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/operations.js +14 -2
  2. package/package.json +13 -13
package/lib/operations.js CHANGED
@@ -209,12 +209,24 @@ export const populateSubBundle = (inputOperation, data, options = {}) => {
209
209
  }) > supplyTargetUtilization) {
210
210
  // Liquidity is insufficient: trigger a public reallocation and try to have a resulting utilization as low as possible, above the target.
211
211
  // Solve: newTotalBorrowAssets / (newTotalSupplyAssets + reallocatedAssets) = supplyTargetUtilization
212
- // Worst case is: there is not enough withdrawals available to fill reallocatedAssets, so utilization is above supplyTargetUtilization.
212
+ // We first try to find public reallocations that respect every markets targets.
213
+ // If this is not enough, the first market to be pushed above target is the supply market. Then we fully withdraw from every market.
213
214
  let requiredAssets = supplyTargetUtilization === 0n
214
215
  ? MathLib.MAX_UINT_160
215
216
  : MathLib.wDivDown(newTotalBorrowAssets, supplyTargetUtilization) -
216
217
  newTotalSupplyAssets;
217
- const { withdrawals } = data.getMarketPublicReallocations(market.id, publicAllocatorOptions);
218
+ let { withdrawals, data: simulationStatePostFriendlyReallocation } = data.getMarketPublicReallocations(market.id, publicAllocatorOptions);
219
+ const marketPostFriendlyReallocation = simulationStatePostFriendlyReallocation.getMarket(market.id);
220
+ if (marketPostFriendlyReallocation.totalBorrowAssets + borrowedAssets >
221
+ marketPostFriendlyReallocation.totalSupplyAssets - withdrawnAssets) {
222
+ // If the "friendly" reallocations are not enough, we fully withdraw from every market.
223
+ requiredAssets = newTotalBorrowAssets - newTotalSupplyAssets;
224
+ ({ withdrawals } = data.getMarketPublicReallocations(market.id, {
225
+ ...publicAllocatorOptions,
226
+ defaultMaxWithdrawalUtilization: MathLib.WAD,
227
+ maxWithdrawalUtilization: {},
228
+ }));
229
+ }
218
230
  for (const { vault, ...withdrawal } of withdrawals) {
219
231
  const vaultReallocations = (reallocations[vault] ??= []);
220
232
  if (withdrawal.assets > requiredAssets) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/bundler-sdk-viem",
3
3
  "description": "Viem-based extension of `@morpho-org/simulation-sdk` that exports utilities to transform simple interactions on Morpho (such as `Blue_Borrow`) and Morpho Vaults (such as `MetaMorpho_Deposit`) into the required bundles (with ERC20 approvals, transfers, etc) to submit to the bundler onchain.",
4
- "version": "2.1.4-next.0",
4
+ "version": "2.2.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"
@@ -20,10 +20,10 @@
20
20
  ],
21
21
  "peerDependencies": {
22
22
  "viem": "^2.0.0",
23
- "@morpho-org/blue-sdk-viem": "^2.2.2-next.1",
24
- "@morpho-org/blue-sdk": "^2.3.1-next.1",
25
- "@morpho-org/morpho-ts": "^2.0.2-next.1",
26
- "@morpho-org/simulation-sdk": "^2.1.3-next.1"
23
+ "@morpho-org/blue-sdk-viem": "^2.2.2",
24
+ "@morpho-org/simulation-sdk": "^2.1.3",
25
+ "@morpho-org/blue-sdk": "^2.3.1",
26
+ "@morpho-org/morpho-ts": "^2.1.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@tanstack/query-core": "^5.62.16",
@@ -35,14 +35,14 @@
35
35
  "typescript": "^5.7.2",
36
36
  "viem": "^2.23.0",
37
37
  "vitest": "^3.0.5",
38
- "@morpho-org/blue-sdk": "^2.3.1-next.1",
39
- "@morpho-org/blue-sdk-viem": "^2.2.2-next.1",
40
- "@morpho-org/morpho-test": "^2.2.1-next.1",
41
- "@morpho-org/morpho-ts": "^2.0.2-next.1",
42
- "@morpho-org/simulation-sdk": "^2.1.3-next.1",
43
- "@morpho-org/test": "^2.0.6-next.1",
44
- "@morpho-org/simulation-sdk-wagmi": "^2.0.5-next.1",
45
- "@morpho-org/test-wagmi": "^2.0.4-next.1"
38
+ "@morpho-org/blue-sdk": "^2.3.1",
39
+ "@morpho-org/blue-sdk-viem": "^2.2.2",
40
+ "@morpho-org/morpho-test": "^2.2.1",
41
+ "@morpho-org/morpho-ts": "^2.1.0",
42
+ "@morpho-org/simulation-sdk": "^2.1.3",
43
+ "@morpho-org/simulation-sdk-wagmi": "^2.0.5",
44
+ "@morpho-org/test": "^2.0.6",
45
+ "@morpho-org/test-wagmi": "^2.0.4"
46
46
  },
47
47
  "scripts": {
48
48
  "prepublish": "$npm_execpath build",