@morpho-org/bundler-sdk-viem 3.2.4 → 3.2.6
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 +6 -6
- package/lib/operations.js +37 -21
- package/package.json +9 -9
package/lib/actions.js
CHANGED
|
@@ -427,7 +427,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
427
427
|
.getMarket(id)
|
|
428
428
|
.accrueInterest(dataBefore.block.timestamp);
|
|
429
429
|
const { assets: withdrawnAssets, shares: withdrawnShares } = market.withdraw(assets, shares);
|
|
430
|
-
const minSharePrice = blue_sdk_1.MathLib.
|
|
430
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivDown(withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), withdrawnShares);
|
|
431
431
|
actions.push({
|
|
432
432
|
type: "morphoWithdraw",
|
|
433
433
|
args: [
|
|
@@ -448,7 +448,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
448
448
|
.getMarket(id)
|
|
449
449
|
.accrueInterest(dataBefore.block.timestamp);
|
|
450
450
|
const { assets: borrowedAssets, shares: borrowedShares } = market.borrow(assets, shares);
|
|
451
|
-
const minSharePrice = blue_sdk_1.MathLib.
|
|
451
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivDown(borrowedAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), borrowedShares);
|
|
452
452
|
actions.push({
|
|
453
453
|
type: "morphoBorrow",
|
|
454
454
|
args: [
|
|
@@ -530,7 +530,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
530
530
|
.getAccrualVault(operation.address)
|
|
531
531
|
.accrueInterest(dataBefore.block.timestamp);
|
|
532
532
|
if (shares === 0n) {
|
|
533
|
-
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), vault.toShares(assets));
|
|
533
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), vault.toShares(assets, "Down"));
|
|
534
534
|
actions.push({
|
|
535
535
|
type: "erc4626Deposit",
|
|
536
536
|
args: [
|
|
@@ -543,7 +543,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
543
543
|
});
|
|
544
544
|
}
|
|
545
545
|
else {
|
|
546
|
-
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(vault.toAssets(shares), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), shares);
|
|
546
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(vault.toAssets(shares, "Up"), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), shares);
|
|
547
547
|
actions.push({
|
|
548
548
|
type: "erc4626Mint",
|
|
549
549
|
args: [
|
|
@@ -564,7 +564,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
564
564
|
.getAccrualVault(operation.address)
|
|
565
565
|
.accrueInterest(dataBefore.block.timestamp);
|
|
566
566
|
if (shares === 0n) {
|
|
567
|
-
const minSharePrice = blue_sdk_1.MathLib.mulDivDown(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), vault.toShares(assets));
|
|
567
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivDown(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), vault.toShares(assets, "Up"));
|
|
568
568
|
actions.push({
|
|
569
569
|
type: "erc4626Withdraw",
|
|
570
570
|
args: [
|
|
@@ -578,7 +578,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
578
578
|
});
|
|
579
579
|
}
|
|
580
580
|
else {
|
|
581
|
-
const minSharePrice = blue_sdk_1.MathLib.mulDivDown(vault.toAssets(shares), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), shares);
|
|
581
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivDown(vault.toAssets(shares, "Down"), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), shares);
|
|
582
582
|
actions.push({
|
|
583
583
|
type: "erc4626Redeem",
|
|
584
584
|
args: [
|
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.6",
|
|
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.4.0",
|
|
23
22
|
"@morpho-org/morpho-ts": "^2.4.1",
|
|
24
|
-
"@morpho-org/
|
|
25
|
-
"@morpho-org/blue-sdk
|
|
23
|
+
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
24
|
+
"@morpho-org/blue-sdk": "^4.4.0",
|
|
25
|
+
"@morpho-org/simulation-sdk": "^3.1.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@tanstack/query-core": "^5.62.16",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"typescript": "^5.7.2",
|
|
35
35
|
"viem": "^2.23.0",
|
|
36
36
|
"vitest": "^3.0.5",
|
|
37
|
-
"@morpho-org/blue-sdk": "^4.4.0",
|
|
38
37
|
"@morpho-org/morpho-test": "^2.3.0",
|
|
39
|
-
"@morpho-org/blue-sdk
|
|
38
|
+
"@morpho-org/blue-sdk": "^4.4.0",
|
|
40
39
|
"@morpho-org/morpho-ts": "^2.4.1",
|
|
41
|
-
"@morpho-org/
|
|
40
|
+
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
41
|
+
"@morpho-org/simulation-sdk": "^3.1.2",
|
|
42
|
+
"@morpho-org/simulation-sdk-wagmi": "^3.0.2",
|
|
42
43
|
"@morpho-org/test": "^2.1.4",
|
|
43
|
-
"@morpho-org/test-wagmi": "^2.0.4"
|
|
44
|
-
"@morpho-org/simulation-sdk-wagmi": "^3.0.2"
|
|
44
|
+
"@morpho-org/test-wagmi": "^2.0.4"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"prepublish": "$npm_execpath build",
|