@morpho-org/bundler-sdk-viem 4.0.1 → 4.1.0-next.1
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 +27 -10
- package/package.json +8 -8
package/lib/operations.js
CHANGED
|
@@ -45,6 +45,7 @@ const populateInputTransfer = ({ address, args: { amount, from } }, data, { hasS
|
|
|
45
45
|
// Try using simple permit.
|
|
46
46
|
const useSimplePermit = erc2612Nonce != null &&
|
|
47
47
|
(data.tryGetVault(address) != null || // MetaMorpho vaults implement EIP-2612.
|
|
48
|
+
data.tryGetVaultV2(address) != null || // Vaults V2 implement EIP-2612.
|
|
48
49
|
hasSimplePermit);
|
|
49
50
|
const useSimpleTransfer = permit2 == null ||
|
|
50
51
|
// Token is permissioned and Permit2 may not be authorized so Permit2 cannot be used.
|
|
@@ -180,10 +181,12 @@ const populateSubBundle = (inputOperation, data, options = {}) => {
|
|
|
180
181
|
if (isErc20Wrapper)
|
|
181
182
|
break;
|
|
182
183
|
case "MetaMorpho_Deposit":
|
|
183
|
-
case "MetaMorpho_Withdraw":
|
|
184
|
+
case "MetaMorpho_Withdraw": {
|
|
184
185
|
// Only if sender is owner otherwise the owner would be lost.
|
|
185
186
|
if (draft.args.owner === sender)
|
|
186
187
|
draft.args.owner = generalAdapter1;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
187
190
|
}
|
|
188
191
|
// Redirect operation targets.
|
|
189
192
|
switch (draft.type) {
|
|
@@ -489,9 +492,15 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
489
492
|
let steps = (0, exports.simulateBundlerOperations)(operations, startData);
|
|
490
493
|
// Redirect MetaMorpho deposits.
|
|
491
494
|
operations.forEach((operation, index) => {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
+
switch (operation.type) {
|
|
496
|
+
case "MetaMorpho_Deposit": {
|
|
497
|
+
if (operation.args.owner !== generalAdapter1)
|
|
498
|
+
return;
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
default:
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
495
504
|
const token = operation.address;
|
|
496
505
|
// shares are not defined when depositing assets, so we rely on simulation steps.
|
|
497
506
|
const shares = steps[index + 1].getHolding(generalAdapter1, token).balance -
|
|
@@ -501,9 +510,10 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
501
510
|
.some((step) => step.getHolding(generalAdapter1, token).balance < shares))
|
|
502
511
|
// If the bundler's balance is at least once lower than assets, the bundler does need these assets.
|
|
503
512
|
return;
|
|
504
|
-
operation.
|
|
513
|
+
if (operation.type === "MetaMorpho_Deposit")
|
|
514
|
+
operation.args.owner = receiver;
|
|
505
515
|
});
|
|
506
|
-
// Redirect borrows, withdrawals &
|
|
516
|
+
// Redirect borrows, withdrawals, MetaMorpho withdrawals & Vault V2 withdrawals.
|
|
507
517
|
operations.forEach((operation, index) => {
|
|
508
518
|
let token;
|
|
509
519
|
switch (operation.type) {
|
|
@@ -534,9 +544,15 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
534
544
|
});
|
|
535
545
|
// Simplify Erc20_Transfer(sender = bundler, to = bundler) + MetaMorpho_Withdraw(owner = bundler) = MetaMorpho_Withdraw(owner = from).
|
|
536
546
|
operations.forEach((operation, index) => {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
547
|
+
switch (operation.type) {
|
|
548
|
+
case "MetaMorpho_Withdraw": {
|
|
549
|
+
if (operation.args.owner !== generalAdapter1)
|
|
550
|
+
return;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
default:
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
540
556
|
// shares are not defined when using assets, so we rely on simulation steps.
|
|
541
557
|
const shares = steps[index].getHolding(generalAdapter1, operation.address).balance -
|
|
542
558
|
steps[index + 1].getHolding(generalAdapter1, operation.address).balance;
|
|
@@ -549,7 +565,8 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
549
565
|
return;
|
|
550
566
|
const inputTransfer = operations[inputTransferIndex];
|
|
551
567
|
inputTransfer.args.amount -= shares;
|
|
552
|
-
operation.
|
|
568
|
+
if (operation.type === "MetaMorpho_Withdraw")
|
|
569
|
+
operation.args.owner = inputTransfer.args.from;
|
|
553
570
|
});
|
|
554
571
|
// Filter out useless input transfers.
|
|
555
572
|
operations = operations.filter((operation, index) => {
|
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": "4.0.1",
|
|
4
|
+
"version": "4.1.0-next.1",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"viem": "^2.0.0",
|
|
22
|
-
"@morpho-org/blue-sdk": "^5.
|
|
23
|
-
"@morpho-org/blue-sdk-viem": "^4.0.
|
|
22
|
+
"@morpho-org/blue-sdk": "^5.3.0-next.2",
|
|
23
|
+
"@morpho-org/blue-sdk-viem": "^4.1.0-next.5",
|
|
24
24
|
"@morpho-org/morpho-ts": "^2.4.3",
|
|
25
25
|
"@morpho-org/simulation-sdk": "^3.1.3"
|
|
26
26
|
},
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
"@types/lodash": "^4.17.12",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
34
|
"typescript": "^5.7.2",
|
|
35
|
-
"viem": "^2.
|
|
35
|
+
"viem": "^2.33.3",
|
|
36
36
|
"vitest": "^3.0.5",
|
|
37
|
+
"@morpho-org/blue-sdk": "^5.3.0-next.2",
|
|
38
|
+
"@morpho-org/blue-sdk-viem": "^4.1.0-next.5",
|
|
37
39
|
"@morpho-org/morpho-test": "^2.4.0",
|
|
38
|
-
"@morpho-org/blue-sdk": "^5.2.0",
|
|
39
|
-
"@morpho-org/blue-sdk-viem": "^4.0.0",
|
|
40
40
|
"@morpho-org/morpho-ts": "^2.4.3",
|
|
41
41
|
"@morpho-org/simulation-sdk": "^3.1.3",
|
|
42
42
|
"@morpho-org/simulation-sdk-wagmi": "^3.0.3",
|
|
43
|
-
"@morpho-org/test
|
|
44
|
-
"@morpho-org/test": "^2.
|
|
43
|
+
"@morpho-org/test": "^2.6.0",
|
|
44
|
+
"@morpho-org/test-wagmi": "^2.0.4"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"prepublish": "$npm_execpath build",
|