@morpho-org/bundler-sdk-viem 3.1.2 → 3.1.4
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 +20 -10
- package/lib/operations.js +4 -6
- package/package.json +9 -9
package/lib/actions.js
CHANGED
|
@@ -428,7 +428,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
428
428
|
const market = dataBefore
|
|
429
429
|
.getMarket(id)
|
|
430
430
|
.accrueInterest(dataBefore.block.timestamp);
|
|
431
|
-
const
|
|
431
|
+
const { assets: suppliedAssets, shares: suppliedShares } = market.supply(assets, shares);
|
|
432
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(suppliedAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), suppliedShares);
|
|
432
433
|
actions.push({
|
|
433
434
|
type: "morphoSupply",
|
|
434
435
|
args: [
|
|
@@ -449,7 +450,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
449
450
|
const market = dataBefore
|
|
450
451
|
.getMarket(id)
|
|
451
452
|
.accrueInterest(dataBefore.block.timestamp);
|
|
452
|
-
const
|
|
453
|
+
const { assets: withdrawnAssets, shares: withdrawnShares } = market.withdraw(assets, shares);
|
|
454
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivUp(withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), withdrawnShares);
|
|
453
455
|
actions.push({
|
|
454
456
|
type: "morphoWithdraw",
|
|
455
457
|
args: [
|
|
@@ -469,7 +471,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
469
471
|
const market = dataBefore
|
|
470
472
|
.getMarket(id)
|
|
471
473
|
.accrueInterest(dataBefore.block.timestamp);
|
|
472
|
-
const
|
|
474
|
+
const { assets: borrowedAssets, shares: borrowedShares } = market.borrow(assets, shares);
|
|
475
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivUp(borrowedAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), borrowedShares);
|
|
473
476
|
actions.push({
|
|
474
477
|
type: "morphoBorrow",
|
|
475
478
|
args: [
|
|
@@ -489,7 +492,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
489
492
|
const market = dataBefore
|
|
490
493
|
.getMarket(id)
|
|
491
494
|
.accrueInterest(dataBefore.block.timestamp);
|
|
492
|
-
const
|
|
495
|
+
const { assets: repaidAssets, shares: repaidShares } = market.repay(assets, shares);
|
|
496
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(repaidAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), repaidShares);
|
|
493
497
|
actions.push({
|
|
494
498
|
type: "morphoRepay",
|
|
495
499
|
args: [
|
|
@@ -549,17 +553,20 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
549
553
|
const vault = dataBefore
|
|
550
554
|
.getAccrualVault(address)
|
|
551
555
|
.accrueInterest(dataBefore.block.timestamp);
|
|
552
|
-
|
|
553
|
-
|
|
556
|
+
if (shares === 0n) {
|
|
557
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), vault.toShares(assets));
|
|
554
558
|
actions.push({
|
|
555
559
|
type: "erc4626Deposit",
|
|
556
560
|
args: [address, assets, maxSharePrice, owner, operation.skipRevert],
|
|
557
561
|
});
|
|
558
|
-
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(vault.toAssets(shares), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), shares);
|
|
559
565
|
actions.push({
|
|
560
566
|
type: "erc4626Mint",
|
|
561
567
|
args: [address, shares, maxSharePrice, owner, operation.skipRevert],
|
|
562
568
|
});
|
|
569
|
+
}
|
|
563
570
|
break;
|
|
564
571
|
}
|
|
565
572
|
case "MetaMorpho_Withdraw": {
|
|
@@ -568,8 +575,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
568
575
|
const vault = dataBefore
|
|
569
576
|
.getAccrualVault(address)
|
|
570
577
|
.accrueInterest(dataBefore.block.timestamp);
|
|
571
|
-
|
|
572
|
-
|
|
578
|
+
if (shares === 0n) {
|
|
579
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), vault.toShares(assets));
|
|
573
580
|
actions.push({
|
|
574
581
|
type: "erc4626Withdraw",
|
|
575
582
|
args: [
|
|
@@ -581,7 +588,9 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
581
588
|
operation.skipRevert,
|
|
582
589
|
],
|
|
583
590
|
});
|
|
584
|
-
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivUp(vault.toAssets(shares), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), shares);
|
|
585
594
|
actions.push({
|
|
586
595
|
type: "erc4626Redeem",
|
|
587
596
|
args: [
|
|
@@ -593,6 +602,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
593
602
|
operation.skipRevert,
|
|
594
603
|
],
|
|
595
604
|
});
|
|
605
|
+
}
|
|
596
606
|
break;
|
|
597
607
|
}
|
|
598
608
|
case "MetaMorpho_PublicReallocate": {
|
package/lib/operations.js
CHANGED
|
@@ -624,13 +624,11 @@ const simulateRequiredTokenAmounts = (operations, data) => {
|
|
|
624
624
|
});
|
|
625
625
|
// Simulate the operations to calculate the required token amounts.
|
|
626
626
|
const steps = (0, simulation_sdk_1.simulateOperations)(operations, virtualBundlerData);
|
|
627
|
-
return (0, morpho_ts_1.entries)((0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {})
|
|
628
|
-
.map(([token, holding]) => ({
|
|
629
|
-
token,
|
|
627
|
+
return ((0, morpho_ts_1.entries)((0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {})
|
|
630
628
|
// Safe cast because the holding was transformed to a VirtualHolding.
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
.filter(({ required }) => required > 0n);
|
|
629
|
+
.filter((entry) => entry[1] != null)
|
|
630
|
+
.map(([token, { required }]) => ({ token, required }))
|
|
631
|
+
.filter(({ required }) => required > 0n));
|
|
634
632
|
};
|
|
635
633
|
exports.simulateRequiredTokenAmounts = simulateRequiredTokenAmounts;
|
|
636
634
|
const getSimulatedBundlerOperation = (operation, { slippage } = {}) => {
|
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.1.
|
|
4
|
+
"version": "3.1.4",
|
|
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": "^3.
|
|
23
|
-
"@morpho-org/
|
|
22
|
+
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
23
|
+
"@morpho-org/morpho-ts": "^2.3.0",
|
|
24
24
|
"@morpho-org/simulation-sdk": "^3.0.1",
|
|
25
|
-
"@morpho-org/
|
|
25
|
+
"@morpho-org/blue-sdk": "^3.0.9"
|
|
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": "^3.0.
|
|
38
|
-
"@morpho-org/blue-sdk-viem": "^3.
|
|
39
|
-
"@morpho-org/morpho-ts": "^2.3.0",
|
|
37
|
+
"@morpho-org/blue-sdk": "^3.0.9",
|
|
38
|
+
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
40
39
|
"@morpho-org/morpho-test": "^2.3.0",
|
|
41
40
|
"@morpho-org/simulation-sdk": "^3.0.1",
|
|
41
|
+
"@morpho-org/morpho-ts": "^2.3.0",
|
|
42
42
|
"@morpho-org/simulation-sdk-wagmi": "^3.0.1",
|
|
43
|
-
"@morpho-org/test
|
|
44
|
-
"@morpho-org/test": "^2.
|
|
43
|
+
"@morpho-org/test": "^2.1.3",
|
|
44
|
+
"@morpho-org/test-wagmi": "^2.0.4"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"prepublish": "$npm_execpath build",
|