@morpho-org/bundler-sdk-viem 3.2.0-next.0 → 3.2.0-next.2
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 +28 -11
- package/lib/operations.js +18 -2
- package/package.json +11 -11
package/lib/actions.js
CHANGED
|
@@ -179,7 +179,14 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
179
179
|
const action = isDai
|
|
180
180
|
? {
|
|
181
181
|
type: "permitDai",
|
|
182
|
-
args: [
|
|
182
|
+
args: [
|
|
183
|
+
sender,
|
|
184
|
+
nonce,
|
|
185
|
+
deadline,
|
|
186
|
+
amount > 0n,
|
|
187
|
+
null,
|
|
188
|
+
operation.skipRevert,
|
|
189
|
+
],
|
|
183
190
|
}
|
|
184
191
|
: {
|
|
185
192
|
type: "permit",
|
|
@@ -437,7 +444,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
437
444
|
const market = dataBefore
|
|
438
445
|
.getMarket(id)
|
|
439
446
|
.accrueInterest(dataBefore.block.timestamp);
|
|
440
|
-
const
|
|
447
|
+
const { assets: suppliedAssets, shares: suppliedShares } = market.supply(assets, shares);
|
|
448
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(suppliedAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), suppliedShares);
|
|
441
449
|
actions.push({
|
|
442
450
|
type: "morphoSupply",
|
|
443
451
|
args: [
|
|
@@ -458,7 +466,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
458
466
|
const market = dataBefore
|
|
459
467
|
.getMarket(id)
|
|
460
468
|
.accrueInterest(dataBefore.block.timestamp);
|
|
461
|
-
const
|
|
469
|
+
const { assets: withdrawnAssets, shares: withdrawnShares } = market.withdraw(assets, shares);
|
|
470
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivUp(withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), withdrawnShares);
|
|
462
471
|
actions.push({
|
|
463
472
|
type: "morphoWithdraw",
|
|
464
473
|
args: [
|
|
@@ -478,7 +487,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
478
487
|
const market = dataBefore
|
|
479
488
|
.getMarket(id)
|
|
480
489
|
.accrueInterest(dataBefore.block.timestamp);
|
|
481
|
-
const
|
|
490
|
+
const { assets: borrowedAssets, shares: borrowedShares } = market.borrow(assets, shares);
|
|
491
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivUp(borrowedAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), borrowedShares);
|
|
482
492
|
actions.push({
|
|
483
493
|
type: "morphoBorrow",
|
|
484
494
|
args: [
|
|
@@ -498,7 +508,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
498
508
|
const market = dataBefore
|
|
499
509
|
.getMarket(id)
|
|
500
510
|
.accrueInterest(dataBefore.block.timestamp);
|
|
501
|
-
const
|
|
511
|
+
const { assets: repaidAssets, shares: repaidShares } = market.repay(assets, shares);
|
|
512
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(repaidAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), repaidShares);
|
|
502
513
|
actions.push({
|
|
503
514
|
type: "morphoRepay",
|
|
504
515
|
args: [
|
|
@@ -558,8 +569,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
558
569
|
const vault = dataBefore
|
|
559
570
|
.getAccrualVault(operation.address)
|
|
560
571
|
.accrueInterest(dataBefore.block.timestamp);
|
|
561
|
-
|
|
562
|
-
|
|
572
|
+
if (shares === 0n) {
|
|
573
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), vault.toShares(assets));
|
|
563
574
|
actions.push({
|
|
564
575
|
type: "erc4626Deposit",
|
|
565
576
|
args: [
|
|
@@ -570,7 +581,9 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
570
581
|
operation.skipRevert,
|
|
571
582
|
],
|
|
572
583
|
});
|
|
573
|
-
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(vault.toAssets(shares), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), shares);
|
|
574
587
|
actions.push({
|
|
575
588
|
type: "erc4626Mint",
|
|
576
589
|
args: [
|
|
@@ -581,6 +594,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
581
594
|
operation.skipRevert,
|
|
582
595
|
],
|
|
583
596
|
});
|
|
597
|
+
}
|
|
584
598
|
break;
|
|
585
599
|
}
|
|
586
600
|
case "MetaMorpho_Withdraw": {
|
|
@@ -589,8 +603,8 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
589
603
|
const vault = dataBefore
|
|
590
604
|
.getAccrualVault(operation.address)
|
|
591
605
|
.accrueInterest(dataBefore.block.timestamp);
|
|
592
|
-
|
|
593
|
-
|
|
606
|
+
if (shares === 0n) {
|
|
607
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), vault.toShares(assets));
|
|
594
608
|
actions.push({
|
|
595
609
|
type: "erc4626Withdraw",
|
|
596
610
|
args: [
|
|
@@ -602,7 +616,9 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
602
616
|
operation.skipRevert,
|
|
603
617
|
],
|
|
604
618
|
});
|
|
605
|
-
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivUp(vault.toAssets(shares), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), shares);
|
|
606
622
|
actions.push({
|
|
607
623
|
type: "erc4626Redeem",
|
|
608
624
|
args: [
|
|
@@ -614,6 +630,7 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
614
630
|
operation.skipRevert,
|
|
615
631
|
],
|
|
616
632
|
});
|
|
633
|
+
}
|
|
617
634
|
break;
|
|
618
635
|
}
|
|
619
636
|
case "MetaMorpho_PublicReallocate": {
|
package/lib/operations.js
CHANGED
|
@@ -358,7 +358,7 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
358
358
|
const nbOperations = operations.length;
|
|
359
359
|
if (nbOperations === 0)
|
|
360
360
|
return operations;
|
|
361
|
-
const { bundler3: { bundler3, generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(startData.chainId);
|
|
361
|
+
const { bundler3: { bundler3, generalAdapter1 }, dai, } = (0, blue_sdk_1.getChainAddresses)(startData.chainId);
|
|
362
362
|
if ((0, viem_1.isAddressEqual)(receiver, bundler3) ||
|
|
363
363
|
(0, viem_1.isAddressEqual)(receiver, generalAdapter1))
|
|
364
364
|
throw Error(`receiver is bundler`);
|
|
@@ -541,9 +541,25 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
541
541
|
});
|
|
542
542
|
// Simulate without slippage to skim the bundler of all possible surplus of shares & assets.
|
|
543
543
|
steps = (0, exports.simulateBundlerOperations)(operations, startData, { slippage: 0n });
|
|
544
|
+
const lastStep = (0, morpho_ts_1.getLast)(steps);
|
|
545
|
+
const daiPermit = dai != null
|
|
546
|
+
? operations.find(
|
|
547
|
+
// There should exist only one dai permit operation in the bundle thanks to the first optimization step.
|
|
548
|
+
(operation) => operation.type === "Erc20_Permit" && operation.address === dai)
|
|
549
|
+
: undefined;
|
|
550
|
+
// If the bundle approves dai, reset the dai allowance at the end of the bundle.
|
|
551
|
+
if (daiPermit != null)
|
|
552
|
+
operations.push({
|
|
553
|
+
...daiPermit,
|
|
554
|
+
args: {
|
|
555
|
+
amount: 0n,
|
|
556
|
+
spender: daiPermit.args.spender,
|
|
557
|
+
nonce: daiPermit.args.nonce + 1n,
|
|
558
|
+
},
|
|
559
|
+
});
|
|
544
560
|
// Unwrap requested remaining wrapped tokens.
|
|
545
561
|
const unwraps = [];
|
|
546
|
-
const endBundlerTokenData =
|
|
562
|
+
const endBundlerTokenData = lastStep.holdings[generalAdapter1] ?? {};
|
|
547
563
|
unwrapTokens.forEach((wrappedToken) => {
|
|
548
564
|
const remaining = endBundlerTokenData[wrappedToken]?.balance ?? 0n;
|
|
549
565
|
if (remaining <= 5n)
|
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.0-next.
|
|
4
|
+
"version": "3.2.0-next.2",
|
|
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": "^
|
|
23
|
-
"@morpho-org/
|
|
24
|
-
"@morpho-org/
|
|
25
|
-
"@morpho-org/simulation-sdk": "^3.1.0-next.
|
|
22
|
+
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
23
|
+
"@morpho-org/morpho-ts": "^2.3.0",
|
|
24
|
+
"@morpho-org/blue-sdk": "^4.0.0-next.2",
|
|
25
|
+
"@morpho-org/simulation-sdk": "^3.1.0-next.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@tanstack/query-core": "^5.62.16",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"typescript": "^5.7.2",
|
|
35
35
|
"viem": "^2.23.0",
|
|
36
36
|
"vitest": "^3.0.5",
|
|
37
|
-
"@morpho-org/blue-sdk": "^4.0.0-next.
|
|
38
|
-
"@morpho-org/blue-sdk-viem": "^3.0.0",
|
|
39
|
-
"@morpho-org/morpho-ts": "^2.4.0-next.0",
|
|
40
|
-
"@morpho-org/simulation-sdk": "^3.1.0-next.0",
|
|
37
|
+
"@morpho-org/blue-sdk": "^4.0.0-next.2",
|
|
41
38
|
"@morpho-org/morpho-test": "^2.3.0",
|
|
42
|
-
"@morpho-org/
|
|
43
|
-
"@morpho-org/
|
|
39
|
+
"@morpho-org/morpho-ts": "^2.3.0",
|
|
40
|
+
"@morpho-org/simulation-sdk": "^3.1.0-next.1",
|
|
41
|
+
"@morpho-org/blue-sdk-viem": "^3.1.1",
|
|
42
|
+
"@morpho-org/simulation-sdk-wagmi": "^3.0.1",
|
|
43
|
+
"@morpho-org/test": "^2.1.3",
|
|
44
44
|
"@morpho-org/test-wagmi": "^2.0.4"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|