@morpho-org/bundler-sdk-viem 3.2.5 → 3.2.7
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/actions.js +5 -1
- package/lib/operations.js +37 -21
- package/package.json +9 -9
package/lib/actions.js
CHANGED
|
@@ -210,7 +210,11 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
210
210
|
break;
|
|
211
211
|
}
|
|
212
212
|
// Simple permit is not supported, fallback to standard approval.
|
|
213
|
-
|
|
213
|
+
// Ignore zero permits used to reset allowances at the end of a bundle
|
|
214
|
+
// when the signer does not support signatures, as they cannot be bundled.
|
|
215
|
+
// Currently only used by DAI-specific permit which does not support specific amounts.
|
|
216
|
+
if (amount > 0n)
|
|
217
|
+
requirements.txs.push(...encodeErc20Approval(operation.address, spender, amount, dataBefore));
|
|
214
218
|
break;
|
|
215
219
|
}
|
|
216
220
|
case "Erc20_Permit2": {
|
package/lib/operations.js
CHANGED
|
@@ -570,7 +570,6 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
570
570
|
});
|
|
571
571
|
// Simulate without slippage to skim the bundler of all possible surplus of shares & assets.
|
|
572
572
|
steps = (0, exports.simulateBundlerOperations)(operations, startData, { slippage: 0n });
|
|
573
|
-
const lastStep = (0, morpho_ts_1.getLast)(steps);
|
|
574
573
|
const daiPermit = dai != null
|
|
575
574
|
? operations.find(
|
|
576
575
|
// There should exist only one dai permit operation in the bundle thanks to the first optimization step.
|
|
@@ -588,7 +587,7 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
588
587
|
});
|
|
589
588
|
// Unwrap requested remaining wrapped tokens.
|
|
590
589
|
const unwraps = [];
|
|
591
|
-
|
|
590
|
+
let endBundlerTokenData = (0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {};
|
|
592
591
|
unwrapTokens.forEach((wrappedToken) => {
|
|
593
592
|
const remaining = endBundlerTokenData[wrappedToken]?.balance ?? 0n;
|
|
594
593
|
if (remaining <= 5n)
|
|
@@ -607,30 +606,47 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
607
606
|
},
|
|
608
607
|
});
|
|
609
608
|
});
|
|
610
|
-
if (unwraps.length > 0)
|
|
609
|
+
if (unwraps.length > 0) {
|
|
611
610
|
steps = (0, exports.simulateBundlerOperations)(operations.concat(unwraps), startData, {
|
|
612
611
|
slippage: 0n,
|
|
613
612
|
});
|
|
613
|
+
endBundlerTokenData = (0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {};
|
|
614
|
+
}
|
|
614
615
|
// Skim any token expected to be left on the bundler.
|
|
615
616
|
const skims = [];
|
|
616
|
-
{
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
617
|
+
const startBundlerTokenData = steps[0].holdings[generalAdapter1] ?? {};
|
|
618
|
+
const uniqueSkimTokens = new Set((0, morpho_ts_1.entries)(endBundlerTokenData)
|
|
619
|
+
.filter(([token, holding]) => holding != null &&
|
|
620
|
+
holding.balance - (startBundlerTokenData[token]?.balance ?? 0n) > 5n)
|
|
621
|
+
.map(([address]) => address));
|
|
622
|
+
const pushCustomSkim = (operation) => {
|
|
623
|
+
// Paraswap does not guarantee that the amount effectively bought (resp. sold) corresponds to
|
|
624
|
+
// the requested amount to buy (resp. sell), so we force skim the possible surplus of bought (resp. sold) token.
|
|
625
|
+
switch (operation.type) {
|
|
626
|
+
case "Paraswap_Buy":
|
|
627
|
+
case "Paraswap_Sell":
|
|
628
|
+
uniqueSkimTokens.add(operation.address);
|
|
629
|
+
break;
|
|
630
|
+
case "Blue_Paraswap_BuyDebt":
|
|
631
|
+
uniqueSkimTokens.add(startData.getMarket(operation.args.id).params.loanToken);
|
|
632
|
+
break;
|
|
633
|
+
default:
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
if ("callback" in operation.args)
|
|
637
|
+
operation.args.callback?.forEach(pushCustomSkim);
|
|
638
|
+
};
|
|
639
|
+
operations.forEach(pushCustomSkim);
|
|
640
|
+
skims.push(...Array.from(uniqueSkimTokens, (address) => ({
|
|
641
|
+
type: "Erc20_Transfer",
|
|
642
|
+
address,
|
|
643
|
+
sender: generalAdapter1,
|
|
644
|
+
args: {
|
|
645
|
+
amount: viem_1.maxUint256,
|
|
646
|
+
from: generalAdapter1,
|
|
647
|
+
to: receiver,
|
|
648
|
+
},
|
|
649
|
+
})));
|
|
634
650
|
return operations.concat(unwraps, skims);
|
|
635
651
|
};
|
|
636
652
|
exports.finalizeBundle = finalizeBundle;
|
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.2.
|
|
4
|
+
"version": "3.2.7",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
],
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"viem": "^2.0.0",
|
|
22
|
-
"@morpho-org/blue-sdk": "^4.
|
|
23
|
-
"@morpho-org/simulation-sdk": "^3.1.2",
|
|
22
|
+
"@morpho-org/blue-sdk": "^4.9.0",
|
|
24
23
|
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
25
|
-
"@morpho-org/morpho-ts": "^2.4.1"
|
|
24
|
+
"@morpho-org/morpho-ts": "^2.4.1",
|
|
25
|
+
"@morpho-org/simulation-sdk": "^3.1.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@tanstack/query-core": "^5.62.16",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"viem": "^2.23.0",
|
|
36
36
|
"vitest": "^3.0.5",
|
|
37
37
|
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
38
|
-
"@morpho-org/
|
|
39
|
-
"@morpho-org/blue-sdk": "^4.4.0",
|
|
38
|
+
"@morpho-org/blue-sdk": "^4.9.0",
|
|
40
39
|
"@morpho-org/morpho-ts": "^2.4.1",
|
|
41
|
-
"@morpho-org/
|
|
42
|
-
"@morpho-org/
|
|
43
|
-
"@morpho-org/simulation-sdk-wagmi": "^3.0.
|
|
40
|
+
"@morpho-org/morpho-test": "^2.4.0",
|
|
41
|
+
"@morpho-org/simulation-sdk": "^3.1.3",
|
|
42
|
+
"@morpho-org/simulation-sdk-wagmi": "^3.0.3",
|
|
43
|
+
"@morpho-org/test": "^2.1.5",
|
|
44
44
|
"@morpho-org/test-wagmi": "^2.0.4"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|