@morpho-org/bundler-sdk-viem 3.0.0-next.17 → 3.0.0-next.18
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.
- package/lib/operations.js +14 -11
- package/package.json +6 -6
package/lib/operations.js
CHANGED
|
@@ -216,29 +216,32 @@ export const populateSubBundle = (inputOperation, data, options = {}) => {
|
|
|
216
216
|
? MathLib.MAX_UINT_160
|
|
217
217
|
: MathLib.wDivDown(newTotalBorrowAssets, supplyTargetUtilization) -
|
|
218
218
|
newTotalSupplyAssets;
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
if (
|
|
222
|
-
|
|
219
|
+
const { withdrawals, data: friendlyReallocationData } = data.getMarketPublicReallocations(market.id, publicAllocatorOptions);
|
|
220
|
+
const friendlyReallocationMarket = friendlyReallocationData.getMarket(market.id);
|
|
221
|
+
if (friendlyReallocationMarket.totalBorrowAssets + borrowedAssets >
|
|
222
|
+
friendlyReallocationMarket.totalSupplyAssets - withdrawnAssets) {
|
|
223
223
|
// If the "friendly" reallocations are not enough, we fully withdraw from every market.
|
|
224
224
|
requiredAssets = newTotalBorrowAssets - newTotalSupplyAssets;
|
|
225
|
-
|
|
225
|
+
withdrawals.push(...friendlyReallocationData.getMarketPublicReallocations(market.id, {
|
|
226
226
|
...publicAllocatorOptions,
|
|
227
227
|
defaultMaxWithdrawalUtilization: MathLib.WAD,
|
|
228
228
|
maxWithdrawalUtilization: {},
|
|
229
|
-
}));
|
|
229
|
+
}).withdrawals);
|
|
230
230
|
}
|
|
231
231
|
for (const { vault, ...withdrawal } of withdrawals) {
|
|
232
232
|
const vaultReallocations = (reallocations[vault] ??= []);
|
|
233
|
-
|
|
233
|
+
const vaultMarketReallocation = vaultReallocations.find((item) => item.id === withdrawal.id);
|
|
234
|
+
const reallocatedAssets = MathLib.min(withdrawal.assets, requiredAssets);
|
|
235
|
+
if (vaultMarketReallocation != null)
|
|
236
|
+
vaultMarketReallocation.assets += reallocatedAssets;
|
|
237
|
+
else
|
|
234
238
|
vaultReallocations.push({
|
|
235
239
|
...withdrawal,
|
|
236
|
-
assets:
|
|
240
|
+
assets: reallocatedAssets,
|
|
237
241
|
});
|
|
242
|
+
requiredAssets -= reallocatedAssets;
|
|
243
|
+
if (requiredAssets === 0n)
|
|
238
244
|
break;
|
|
239
|
-
}
|
|
240
|
-
requiredAssets -= withdrawal.assets;
|
|
241
|
-
vaultReallocations.push(withdrawal);
|
|
242
245
|
}
|
|
243
246
|
// TODO: we know there are no unwrap native in the middle
|
|
244
247
|
// of the bundle so we are certain we need to add an input transfer.
|
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": "3.0.0-next.
|
|
4
|
+
"version": "3.0.0-next.18",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"viem": "^2.0.0",
|
|
23
23
|
"@morpho-org/blue-sdk": "^2.3.2",
|
|
24
|
-
"@morpho-org/simulation-sdk": "^3.0.0-next.6",
|
|
25
24
|
"@morpho-org/blue-sdk-viem": "^2.2.2",
|
|
26
|
-
"@morpho-org/morpho-ts": "^2.2.0"
|
|
25
|
+
"@morpho-org/morpho-ts": "^2.2.0",
|
|
26
|
+
"@morpho-org/simulation-sdk": "^2.1.4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@tanstack/query-core": "^5.62.16",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"@morpho-org/blue-sdk": "^2.3.2",
|
|
39
39
|
"@morpho-org/morpho-test": "^2.2.1",
|
|
40
40
|
"@morpho-org/morpho-ts": "^2.2.0",
|
|
41
|
-
"@morpho-org/simulation-sdk": "^3.0.0-next.6",
|
|
42
41
|
"@morpho-org/blue-sdk-viem": "^2.2.2",
|
|
42
|
+
"@morpho-org/simulation-sdk": "^2.1.4",
|
|
43
43
|
"@morpho-org/simulation-sdk-wagmi": "^2.0.5",
|
|
44
|
-
"@morpho-org/test": "^2.
|
|
45
|
-
"@morpho-org/test
|
|
44
|
+
"@morpho-org/test-wagmi": "^2.0.4",
|
|
45
|
+
"@morpho-org/test": "^2.1.2-next.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"prepublish": "$npm_execpath build",
|