@morpho-org/bundler-sdk-viem 3.2.5 → 3.3.0-next.0
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 +70 -0
- package/lib/operations.d.ts +1 -1
- package/lib/operations.js +93 -32
- package/lib/types/operations.d.ts +22 -9
- package/lib/types/operations.js +18 -1
- package/package.json +13 -13
package/lib/actions.js
CHANGED
|
@@ -749,6 +749,76 @@ const encodeOperation = (operation, dataBefore, supportsSignature = true, index
|
|
|
749
749
|
});
|
|
750
750
|
break;
|
|
751
751
|
}
|
|
752
|
+
case "VaultV2_Deposit": {
|
|
753
|
+
const { assets = 0n, shares = 0n, onBehalf, slippage = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
|
|
754
|
+
// Accrue interest to calculate the expected share price.
|
|
755
|
+
const { vault } = dataBefore
|
|
756
|
+
.getAccrualVaultV2(operation.address)
|
|
757
|
+
.accrueInterest(dataBefore.block.timestamp);
|
|
758
|
+
if (shares === 0n) {
|
|
759
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), vault.toShares(assets));
|
|
760
|
+
actions.push({
|
|
761
|
+
type: "erc4626Deposit",
|
|
762
|
+
args: [
|
|
763
|
+
operation.address,
|
|
764
|
+
assets,
|
|
765
|
+
maxSharePrice,
|
|
766
|
+
onBehalf,
|
|
767
|
+
operation.skipRevert,
|
|
768
|
+
],
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(vault.toAssets(shares), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippage), shares);
|
|
773
|
+
actions.push({
|
|
774
|
+
type: "erc4626Mint",
|
|
775
|
+
args: [
|
|
776
|
+
operation.address,
|
|
777
|
+
shares,
|
|
778
|
+
maxSharePrice,
|
|
779
|
+
onBehalf,
|
|
780
|
+
operation.skipRevert,
|
|
781
|
+
],
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
case "VaultV2_Withdraw": {
|
|
787
|
+
const { assets = 0n, shares = 0n, onBehalf, receiver, slippage = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, } = operation.args;
|
|
788
|
+
// Accrue interest to calculate the expected share price.
|
|
789
|
+
const { vault } = dataBefore
|
|
790
|
+
.getAccrualVaultV2(operation.address)
|
|
791
|
+
.accrueInterest(dataBefore.block.timestamp);
|
|
792
|
+
if (shares === 0n) {
|
|
793
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivDown(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), vault.toShares(assets));
|
|
794
|
+
actions.push({
|
|
795
|
+
type: "erc4626Withdraw",
|
|
796
|
+
args: [
|
|
797
|
+
operation.address,
|
|
798
|
+
assets,
|
|
799
|
+
minSharePrice,
|
|
800
|
+
receiver,
|
|
801
|
+
onBehalf,
|
|
802
|
+
operation.skipRevert,
|
|
803
|
+
],
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
else {
|
|
807
|
+
const minSharePrice = blue_sdk_1.MathLib.mulDivDown(vault.toAssets(shares), blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippage), shares);
|
|
808
|
+
actions.push({
|
|
809
|
+
type: "erc4626Redeem",
|
|
810
|
+
args: [
|
|
811
|
+
operation.address,
|
|
812
|
+
shares,
|
|
813
|
+
minSharePrice,
|
|
814
|
+
receiver,
|
|
815
|
+
onBehalf,
|
|
816
|
+
operation.skipRevert,
|
|
817
|
+
],
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
752
822
|
}
|
|
753
823
|
return {
|
|
754
824
|
dataAfter,
|
package/lib/operations.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare const populateInputTransfer: ({ address, args: { amount, from } }
|
|
|
42
42
|
export declare const populateSubBundle: (inputOperation: InputBundlerOperation, data: MaybeDraft<SimulationState>, options?: BundlingOptions) => BundlerOperation[];
|
|
43
43
|
/**
|
|
44
44
|
* Merges unnecessary duplicate `Erc20_Approve`, `Erc20_Transfer` and `Erc20_Wrap`.
|
|
45
|
-
* Also redirects `Blue_Borrow|Withdraw|WithdrawCollateral` & `MetaMorpho_Withdraw` operations from the bundler to the receiver,
|
|
45
|
+
* Also redirects `Blue_Borrow|Withdraw|WithdrawCollateral` & `MetaMorpho_Withdraw` & `VaultV2_Withdraw` operations from the bundler to the receiver,
|
|
46
46
|
* as long as the tokens received (possibly ERC4626 shares) are not used afterwards in the bundle.
|
|
47
47
|
* For all the other remaining tokens, appends `Erc20_Transfer` operations to the bundle, from the bundler to the receiver.
|
|
48
48
|
* @param operations The bundle to optimize.
|
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,18 @@ 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
|
+
}
|
|
190
|
+
case "VaultV2_Deposit":
|
|
191
|
+
case "VaultV2_Withdraw": {
|
|
192
|
+
// Only if sender is owner otherwise the owner would be lost.
|
|
193
|
+
if (draft.args.onBehalf === sender)
|
|
194
|
+
draft.args.onBehalf = generalAdapter1;
|
|
195
|
+
}
|
|
187
196
|
}
|
|
188
197
|
// Redirect operation targets.
|
|
189
198
|
switch (draft.type) {
|
|
@@ -192,6 +201,7 @@ const populateSubBundle = (inputOperation, data, options = {}) => {
|
|
|
192
201
|
case "Blue_WithdrawCollateral":
|
|
193
202
|
draft.args.onBehalf = sender;
|
|
194
203
|
case "MetaMorpho_Withdraw":
|
|
204
|
+
case "VaultV2_Withdraw":
|
|
195
205
|
case "Paraswap_Buy":
|
|
196
206
|
case "Paraswap_Sell":
|
|
197
207
|
case "Blue_Paraswap_BuyDebt":
|
|
@@ -347,6 +357,8 @@ const populateSubBundle = (inputOperation, data, options = {}) => {
|
|
|
347
357
|
("shares" in mainOperation.args && mainOperation.args.shares === viem_1.maxUint256)) {
|
|
348
358
|
if (mainOperation.type === "MetaMorpho_Withdraw")
|
|
349
359
|
mainOperation.args.owner = generalAdapter1;
|
|
360
|
+
if (mainOperation.type === "VaultV2_Withdraw")
|
|
361
|
+
mainOperation.args.onBehalf = generalAdapter1;
|
|
350
362
|
return allOperations;
|
|
351
363
|
}
|
|
352
364
|
const requirementOperations = getRequirementOperations?.(requiredTokenAmounts) ?? [];
|
|
@@ -371,7 +383,7 @@ const populateSubBundle = (inputOperation, data, options = {}) => {
|
|
|
371
383
|
exports.populateSubBundle = populateSubBundle;
|
|
372
384
|
/**
|
|
373
385
|
* Merges unnecessary duplicate `Erc20_Approve`, `Erc20_Transfer` and `Erc20_Wrap`.
|
|
374
|
-
* Also redirects `Blue_Borrow|Withdraw|WithdrawCollateral` & `MetaMorpho_Withdraw` operations from the bundler to the receiver,
|
|
386
|
+
* Also redirects `Blue_Borrow|Withdraw|WithdrawCollateral` & `MetaMorpho_Withdraw` & `VaultV2_Withdraw` operations from the bundler to the receiver,
|
|
375
387
|
* as long as the tokens received (possibly ERC4626 shares) are not used afterwards in the bundle.
|
|
376
388
|
* For all the other remaining tokens, appends `Erc20_Transfer` operations to the bundle, from the bundler to the receiver.
|
|
377
389
|
* @param operations The bundle to optimize.
|
|
@@ -489,9 +501,20 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
489
501
|
let steps = (0, exports.simulateBundlerOperations)(operations, startData);
|
|
490
502
|
// Redirect MetaMorpho deposits.
|
|
491
503
|
operations.forEach((operation, index) => {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
504
|
+
switch (operation.type) {
|
|
505
|
+
case "MetaMorpho_Deposit": {
|
|
506
|
+
if (operation.args.owner !== generalAdapter1)
|
|
507
|
+
return;
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
case "VaultV2_Deposit": {
|
|
511
|
+
if (operation.args.onBehalf !== generalAdapter1)
|
|
512
|
+
return;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
default:
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
495
518
|
const token = operation.address;
|
|
496
519
|
// shares are not defined when depositing assets, so we rely on simulation steps.
|
|
497
520
|
const shares = steps[index + 1].getHolding(generalAdapter1, token).balance -
|
|
@@ -501,9 +524,12 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
501
524
|
.some((step) => step.getHolding(generalAdapter1, token).balance < shares))
|
|
502
525
|
// If the bundler's balance is at least once lower than assets, the bundler does need these assets.
|
|
503
526
|
return;
|
|
504
|
-
operation.
|
|
527
|
+
if (operation.type === "MetaMorpho_Deposit")
|
|
528
|
+
operation.args.owner = receiver;
|
|
529
|
+
if (operation.type === "VaultV2_Deposit")
|
|
530
|
+
operation.args.onBehalf = receiver;
|
|
505
531
|
});
|
|
506
|
-
// Redirect borrows, withdrawals &
|
|
532
|
+
// Redirect borrows, withdrawals, MetaMorpho withdrawals & Vault V2 withdrawals.
|
|
507
533
|
operations.forEach((operation, index) => {
|
|
508
534
|
let token;
|
|
509
535
|
switch (operation.type) {
|
|
@@ -517,6 +543,9 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
517
543
|
case "MetaMorpho_Withdraw":
|
|
518
544
|
token = startData.getVault(operation.address).asset;
|
|
519
545
|
break;
|
|
546
|
+
case "VaultV2_Withdraw":
|
|
547
|
+
token = startData.getVaultV2(operation.address).asset;
|
|
548
|
+
break;
|
|
520
549
|
default:
|
|
521
550
|
return;
|
|
522
551
|
}
|
|
@@ -534,9 +563,20 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
534
563
|
});
|
|
535
564
|
// Simplify Erc20_Transfer(sender = bundler, to = bundler) + MetaMorpho_Withdraw(owner = bundler) = MetaMorpho_Withdraw(owner = from).
|
|
536
565
|
operations.forEach((operation, index) => {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
566
|
+
switch (operation.type) {
|
|
567
|
+
case "MetaMorpho_Withdraw": {
|
|
568
|
+
if (operation.args.owner !== generalAdapter1)
|
|
569
|
+
return;
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
case "VaultV2_Withdraw": {
|
|
573
|
+
if (operation.args.onBehalf !== generalAdapter1)
|
|
574
|
+
return;
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
default:
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
540
580
|
// shares are not defined when using assets, so we rely on simulation steps.
|
|
541
581
|
const shares = steps[index].getHolding(generalAdapter1, operation.address).balance -
|
|
542
582
|
steps[index + 1].getHolding(generalAdapter1, operation.address).balance;
|
|
@@ -549,7 +589,10 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
549
589
|
return;
|
|
550
590
|
const inputTransfer = operations[inputTransferIndex];
|
|
551
591
|
inputTransfer.args.amount -= shares;
|
|
552
|
-
operation.
|
|
592
|
+
if (operation.type === "MetaMorpho_Withdraw")
|
|
593
|
+
operation.args.owner = inputTransfer.args.from;
|
|
594
|
+
if (operation.type === "VaultV2_Withdraw")
|
|
595
|
+
operation.args.onBehalf = inputTransfer.args.from;
|
|
553
596
|
});
|
|
554
597
|
// Filter out useless input transfers.
|
|
555
598
|
operations = operations.filter((operation, index) => {
|
|
@@ -570,7 +613,6 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
570
613
|
});
|
|
571
614
|
// Simulate without slippage to skim the bundler of all possible surplus of shares & assets.
|
|
572
615
|
steps = (0, exports.simulateBundlerOperations)(operations, startData, { slippage: 0n });
|
|
573
|
-
const lastStep = (0, morpho_ts_1.getLast)(steps);
|
|
574
616
|
const daiPermit = dai != null
|
|
575
617
|
? operations.find(
|
|
576
618
|
// There should exist only one dai permit operation in the bundle thanks to the first optimization step.
|
|
@@ -588,7 +630,7 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
588
630
|
});
|
|
589
631
|
// Unwrap requested remaining wrapped tokens.
|
|
590
632
|
const unwraps = [];
|
|
591
|
-
|
|
633
|
+
let endBundlerTokenData = (0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {};
|
|
592
634
|
unwrapTokens.forEach((wrappedToken) => {
|
|
593
635
|
const remaining = endBundlerTokenData[wrappedToken]?.balance ?? 0n;
|
|
594
636
|
if (remaining <= 5n)
|
|
@@ -607,30 +649,47 @@ const finalizeBundle = (operations, startData, receiver, unwrapTokens = new Set(
|
|
|
607
649
|
},
|
|
608
650
|
});
|
|
609
651
|
});
|
|
610
|
-
if (unwraps.length > 0)
|
|
652
|
+
if (unwraps.length > 0) {
|
|
611
653
|
steps = (0, exports.simulateBundlerOperations)(operations.concat(unwraps), startData, {
|
|
612
654
|
slippage: 0n,
|
|
613
655
|
});
|
|
656
|
+
endBundlerTokenData = (0, morpho_ts_1.getLast)(steps).holdings[generalAdapter1] ?? {};
|
|
657
|
+
}
|
|
614
658
|
// Skim any token expected to be left on the bundler.
|
|
615
659
|
const skims = [];
|
|
616
|
-
{
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
660
|
+
const startBundlerTokenData = steps[0].holdings[generalAdapter1] ?? {};
|
|
661
|
+
const uniqueSkimTokens = new Set((0, morpho_ts_1.entries)(endBundlerTokenData)
|
|
662
|
+
.filter(([token, holding]) => holding != null &&
|
|
663
|
+
holding.balance - (startBundlerTokenData[token]?.balance ?? 0n) > 5n)
|
|
664
|
+
.map(([address]) => address));
|
|
665
|
+
const pushCustomSkim = (operation) => {
|
|
666
|
+
// Paraswap does not guarantee that the amount effectively bought (resp. sold) corresponds to
|
|
667
|
+
// the requested amount to buy (resp. sell), so we force skim the possible surplus of bought (resp. sold) token.
|
|
668
|
+
switch (operation.type) {
|
|
669
|
+
case "Paraswap_Buy":
|
|
670
|
+
case "Paraswap_Sell":
|
|
671
|
+
uniqueSkimTokens.add(operation.address);
|
|
672
|
+
break;
|
|
673
|
+
case "Blue_Paraswap_BuyDebt":
|
|
674
|
+
uniqueSkimTokens.add(startData.getMarket(operation.args.id).params.loanToken);
|
|
675
|
+
break;
|
|
676
|
+
default:
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
if ("callback" in operation.args)
|
|
680
|
+
operation.args.callback?.forEach(pushCustomSkim);
|
|
681
|
+
};
|
|
682
|
+
operations.forEach(pushCustomSkim);
|
|
683
|
+
skims.push(...Array.from(uniqueSkimTokens, (address) => ({
|
|
684
|
+
type: "Erc20_Transfer",
|
|
685
|
+
address,
|
|
686
|
+
sender: generalAdapter1,
|
|
687
|
+
args: {
|
|
688
|
+
amount: viem_1.maxUint256,
|
|
689
|
+
from: generalAdapter1,
|
|
690
|
+
to: receiver,
|
|
691
|
+
},
|
|
692
|
+
})));
|
|
634
693
|
return operations.concat(unwraps, skims);
|
|
635
694
|
};
|
|
636
695
|
exports.finalizeBundle = finalizeBundle;
|
|
@@ -708,6 +767,8 @@ const getSimulatedBundlerOperation = (operation, { slippage } = {}) => {
|
|
|
708
767
|
case "Blue_Repay":
|
|
709
768
|
case "MetaMorpho_Deposit":
|
|
710
769
|
case "MetaMorpho_Withdraw":
|
|
770
|
+
case "VaultV2_Deposit":
|
|
771
|
+
case "VaultV2_Withdraw":
|
|
711
772
|
case "Paraswap_Buy":
|
|
712
773
|
case "Paraswap_Sell":
|
|
713
774
|
case "Blue_Paraswap_BuyDebt":
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BlueOperationArgs, CALLBACK_OPERATIONS, type CallbackOperationType, type Erc20OperationArgs, type MetaMorphoOperationArgs, type OperationArgs, type OperationType, type ParaswapOperationArgs, type WithOperationArgs } from "@morpho-org/simulation-sdk";
|
|
1
|
+
import { type BlueOperationArgs, CALLBACK_OPERATIONS, type CallbackOperationType, type Erc20OperationArgs, type MetaMorphoOperationArgs, type OperationArgs, type OperationType, type ParaswapOperationArgs, type VaultV2OperationArgs, type WithOperationArgs } from "@morpho-org/simulation-sdk";
|
|
2
2
|
import type { UnionOmit } from "viem";
|
|
3
3
|
export declare const BLUE_BUNDLER_OPERATIONS: readonly ["Blue_SetAuthorization", "Blue_Borrow", "Blue_Repay", "Blue_Supply", "Blue_SupplyCollateral", "Blue_Withdraw", "Blue_WithdrawCollateral", "Blue_FlashLoan", "Blue_Paraswap_BuyDebt"];
|
|
4
4
|
export type BlueBundlerOperationType = (typeof BLUE_BUNDLER_OPERATIONS)[number];
|
|
@@ -32,12 +32,18 @@ export type Erc20BundlerOperations = {
|
|
|
32
32
|
[OperationType in Erc20BundlerOperationType]: WithOperationArgs<OperationType, Erc20OperationArgs>;
|
|
33
33
|
};
|
|
34
34
|
export type Erc20BundlerOperation = Erc20BundlerOperations[Erc20BundlerOperationType];
|
|
35
|
-
export
|
|
35
|
+
export declare const VAULT_V2_BUNDLER_OPERATIONS: readonly ["VaultV2_Deposit", "VaultV2_Withdraw"];
|
|
36
|
+
export type VaultV2BundlerOperationType = (typeof VAULT_V2_BUNDLER_OPERATIONS)[number];
|
|
37
|
+
export type VaultV2BundlerOperations = {
|
|
38
|
+
[OperationType in VaultV2BundlerOperationType]: WithOperationArgs<OperationType, VaultV2OperationArgs>;
|
|
39
|
+
};
|
|
40
|
+
export type VaultV2BundlerOperation = VaultV2BundlerOperations[VaultV2BundlerOperationType];
|
|
41
|
+
export interface BundlerOperationArgs extends BlueOperationArgs, MetaMorphoOperationArgs, ParaswapOperationArgs, Erc20OperationArgs, VaultV2OperationArgs {
|
|
36
42
|
}
|
|
37
|
-
export type BundlerOperations = BlueBundlerOperations & MetaMorphoBundlerOperations & ParaswapBundlerOperations & Erc20BundlerOperations;
|
|
38
|
-
export type BundlerOperationType = BlueBundlerOperationType | MetaMorphoBundlerOperationType | ParaswapBundlerOperationType | Erc20BundlerOperationType;
|
|
39
|
-
export type BundlerOperation = BlueBundlerOperation | MetaMorphoBundlerOperation | ParaswapBundlerOperation | Erc20BundlerOperation;
|
|
40
|
-
export declare const BUNDLER_OPERATIONS: readonly ["Blue_SetAuthorization", "Blue_Borrow", "Blue_Repay", "Blue_Supply", "Blue_SupplyCollateral", "Blue_Withdraw", "Blue_WithdrawCollateral", "Blue_FlashLoan", "Blue_Paraswap_BuyDebt", "MetaMorpho_Deposit", "MetaMorpho_Withdraw", "MetaMorpho_PublicReallocate", "Erc20_Approve", "Erc20_Permit", "Erc20_Permit2", "Erc20_Transfer", "Erc20_Transfer2", "Erc20_Wrap", "Erc20_Unwrap"];
|
|
43
|
+
export type BundlerOperations = BlueBundlerOperations & MetaMorphoBundlerOperations & ParaswapBundlerOperations & Erc20BundlerOperations & VaultV2BundlerOperations;
|
|
44
|
+
export type BundlerOperationType = BlueBundlerOperationType | MetaMorphoBundlerOperationType | ParaswapBundlerOperationType | Erc20BundlerOperationType | VaultV2BundlerOperationType;
|
|
45
|
+
export type BundlerOperation = BlueBundlerOperation | MetaMorphoBundlerOperation | ParaswapBundlerOperation | Erc20BundlerOperation | VaultV2BundlerOperation;
|
|
46
|
+
export declare const BUNDLER_OPERATIONS: readonly ["Blue_SetAuthorization", "Blue_Borrow", "Blue_Repay", "Blue_Supply", "Blue_SupplyCollateral", "Blue_Withdraw", "Blue_WithdrawCollateral", "Blue_FlashLoan", "Blue_Paraswap_BuyDebt", "MetaMorpho_Deposit", "MetaMorpho_Withdraw", "MetaMorpho_PublicReallocate", "Erc20_Approve", "Erc20_Permit", "Erc20_Permit2", "Erc20_Transfer", "Erc20_Transfer2", "Erc20_Wrap", "Erc20_Unwrap", "VaultV2_Deposit", "VaultV2_Withdraw"];
|
|
41
47
|
export type CallbackBundlerOperationType = (typeof CALLBACK_OPERATIONS)[number];
|
|
42
48
|
export type CallbackBundlerOperations = Pick<BundlerOperations, CallbackBundlerOperationType>;
|
|
43
49
|
export type CallbackBundlerOperation = CallbackBundlerOperations[CallbackBundlerOperationType];
|
|
@@ -45,6 +51,7 @@ export declare const isBlueBundlerOperation: (operation: BundlerOperation) => op
|
|
|
45
51
|
export declare const isMetaMorphoBundlerOperation: (operation: BundlerOperation) => operation is MetaMorphoBundlerOperation;
|
|
46
52
|
export declare const isErc20BundlerOperation: (operation: BundlerOperation) => operation is Erc20BundlerOperation;
|
|
47
53
|
export declare const isCallbackBundlerOperation: (operation: BundlerOperation) => operation is CallbackBundlerOperation;
|
|
54
|
+
export declare const isVaultV2BundlerOperation: (operation: BundlerOperation) => operation is VaultV2BundlerOperation;
|
|
48
55
|
export declare const BLUE_INPUT_OPERATIONS: readonly ["Blue_SetAuthorization", "Blue_Borrow", "Blue_Repay", "Blue_Supply", "Blue_SupplyCollateral", "Blue_Withdraw", "Blue_WithdrawCollateral", "Blue_FlashLoan", "Blue_Paraswap_BuyDebt"];
|
|
49
56
|
export type BlueInputBundlerOperationType = (typeof BLUE_INPUT_OPERATIONS)[number];
|
|
50
57
|
export type BlueInputBundlerOperationArgs = Omit<OperationArgs, (typeof CALLBACK_OPERATIONS)[number]> & {
|
|
@@ -68,10 +75,13 @@ export type ParaswapInputBundlerOperation = BundlerOperations[ParaswapInputBundl
|
|
|
68
75
|
export declare const ERC20_INPUT_OPERATIONS: readonly ["Erc20_Approve", "Erc20_Permit", "Erc20_Permit2", "Erc20_Transfer", "Erc20_Transfer2", "Erc20_Wrap", "Erc20_Unwrap"];
|
|
69
76
|
export type Erc20InputBundlerOperationType = (typeof ERC20_INPUT_OPERATIONS)[number];
|
|
70
77
|
export type Erc20InputBundlerOperation = Erc20BundlerOperations[Erc20InputBundlerOperationType];
|
|
71
|
-
export
|
|
78
|
+
export declare const VAULT_V2_INPUT_OPERATIONS: readonly ["VaultV2_Deposit", "VaultV2_Withdraw"];
|
|
79
|
+
export type VaultV2InputBundlerOperationType = (typeof VAULT_V2_INPUT_OPERATIONS)[number];
|
|
80
|
+
export type VaultV2InputBundlerOperation = VaultV2BundlerOperations[VaultV2InputBundlerOperationType];
|
|
81
|
+
export interface InputBundlerOperationArgs extends BlueOperationArgs, MetaMorphoOperationArgs, ParaswapOperationArgs, Erc20OperationArgs, VaultV2OperationArgs {
|
|
72
82
|
}
|
|
73
|
-
export type InputBundlerOperationType = BlueInputBundlerOperationType | MetaMorphoInputBundlerOperationType | ParaswapInputBundlerOperationType | Erc20InputBundlerOperationType;
|
|
74
|
-
export type InputBundlerOperation = BlueInputBundlerOperation | MetaMorphoInputBundlerOperation | ParaswapInputBundlerOperation | Erc20InputBundlerOperation;
|
|
83
|
+
export type InputBundlerOperationType = BlueInputBundlerOperationType | MetaMorphoInputBundlerOperationType | ParaswapInputBundlerOperationType | Erc20InputBundlerOperationType | VaultV2InputBundlerOperationType;
|
|
84
|
+
export type InputBundlerOperation = BlueInputBundlerOperation | MetaMorphoInputBundlerOperation | ParaswapInputBundlerOperation | Erc20InputBundlerOperation | VaultV2InputBundlerOperation;
|
|
75
85
|
export declare const isBlueInputBundlerOperation: (operation: {
|
|
76
86
|
type: OperationType;
|
|
77
87
|
}) => operation is BlueInputBundlerOperation;
|
|
@@ -84,3 +94,6 @@ export declare const isErc20InputBundlerOperation: (operation: {
|
|
|
84
94
|
export declare const isParaswapInputBundlerOperation: (operation: {
|
|
85
95
|
type: OperationType;
|
|
86
96
|
}) => operation is ParaswapInputBundlerOperation;
|
|
97
|
+
export declare const isVaultV2InputBundlerOperation: (operation: {
|
|
98
|
+
type: OperationType;
|
|
99
|
+
}) => operation is VaultV2InputBundlerOperation;
|
package/lib/types/operations.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isParaswapInputBundlerOperation = exports.isErc20InputBundlerOperation = exports.isMetaMorphoInputBundlerOperation = exports.isBlueInputBundlerOperation = exports.ERC20_INPUT_OPERATIONS = exports.PARASWAP_INPUT_OPERATIONS = exports.METAMORPHO_INPUT_OPERATIONS = exports.BLUE_INPUT_OPERATIONS = exports.isCallbackBundlerOperation = exports.isErc20BundlerOperation = exports.isMetaMorphoBundlerOperation = exports.isBlueBundlerOperation = exports.BUNDLER_OPERATIONS = exports.ERC20_BUNDLER_OPERATIONS = exports.PARASWAP_BUNDLER_OPERATIONS = exports.METAMORPHO_BUNDLER_OPERATIONS = exports.BLUE_BUNDLER_OPERATIONS = void 0;
|
|
3
|
+
exports.isVaultV2InputBundlerOperation = exports.isParaswapInputBundlerOperation = exports.isErc20InputBundlerOperation = exports.isMetaMorphoInputBundlerOperation = exports.isBlueInputBundlerOperation = exports.VAULT_V2_INPUT_OPERATIONS = exports.ERC20_INPUT_OPERATIONS = exports.PARASWAP_INPUT_OPERATIONS = exports.METAMORPHO_INPUT_OPERATIONS = exports.BLUE_INPUT_OPERATIONS = exports.isVaultV2BundlerOperation = exports.isCallbackBundlerOperation = exports.isErc20BundlerOperation = exports.isMetaMorphoBundlerOperation = exports.isBlueBundlerOperation = exports.BUNDLER_OPERATIONS = exports.VAULT_V2_BUNDLER_OPERATIONS = exports.ERC20_BUNDLER_OPERATIONS = exports.PARASWAP_BUNDLER_OPERATIONS = exports.METAMORPHO_BUNDLER_OPERATIONS = exports.BLUE_BUNDLER_OPERATIONS = void 0;
|
|
4
4
|
const simulation_sdk_1 = require("@morpho-org/simulation-sdk");
|
|
5
5
|
exports.BLUE_BUNDLER_OPERATIONS = [
|
|
6
6
|
"Blue_SetAuthorization",
|
|
@@ -20,10 +20,15 @@ exports.METAMORPHO_BUNDLER_OPERATIONS = [
|
|
|
20
20
|
];
|
|
21
21
|
exports.PARASWAP_BUNDLER_OPERATIONS = simulation_sdk_1.PARASWAP_OPERATIONS;
|
|
22
22
|
exports.ERC20_BUNDLER_OPERATIONS = simulation_sdk_1.ERC20_OPERATIONS;
|
|
23
|
+
exports.VAULT_V2_BUNDLER_OPERATIONS = [
|
|
24
|
+
"VaultV2_Deposit",
|
|
25
|
+
"VaultV2_Withdraw",
|
|
26
|
+
];
|
|
23
27
|
exports.BUNDLER_OPERATIONS = [
|
|
24
28
|
...exports.BLUE_BUNDLER_OPERATIONS,
|
|
25
29
|
...exports.METAMORPHO_BUNDLER_OPERATIONS,
|
|
26
30
|
...exports.ERC20_BUNDLER_OPERATIONS,
|
|
31
|
+
...exports.VAULT_V2_BUNDLER_OPERATIONS,
|
|
27
32
|
];
|
|
28
33
|
const isBlueBundlerOperation = (operation) => {
|
|
29
34
|
return exports.BLUE_BUNDLER_OPERATIONS.includes(operation.type);
|
|
@@ -41,6 +46,10 @@ const isCallbackBundlerOperation = (operation) => {
|
|
|
41
46
|
return simulation_sdk_1.CALLBACK_OPERATIONS.includes(operation.type);
|
|
42
47
|
};
|
|
43
48
|
exports.isCallbackBundlerOperation = isCallbackBundlerOperation;
|
|
49
|
+
const isVaultV2BundlerOperation = (operation) => {
|
|
50
|
+
return exports.VAULT_V2_BUNDLER_OPERATIONS.includes(operation.type);
|
|
51
|
+
};
|
|
52
|
+
exports.isVaultV2BundlerOperation = isVaultV2BundlerOperation;
|
|
44
53
|
exports.BLUE_INPUT_OPERATIONS = exports.BLUE_BUNDLER_OPERATIONS;
|
|
45
54
|
exports.METAMORPHO_INPUT_OPERATIONS = [
|
|
46
55
|
"MetaMorpho_Deposit",
|
|
@@ -48,6 +57,10 @@ exports.METAMORPHO_INPUT_OPERATIONS = [
|
|
|
48
57
|
];
|
|
49
58
|
exports.PARASWAP_INPUT_OPERATIONS = exports.PARASWAP_BUNDLER_OPERATIONS;
|
|
50
59
|
exports.ERC20_INPUT_OPERATIONS = exports.ERC20_BUNDLER_OPERATIONS;
|
|
60
|
+
exports.VAULT_V2_INPUT_OPERATIONS = [
|
|
61
|
+
"VaultV2_Deposit",
|
|
62
|
+
"VaultV2_Withdraw",
|
|
63
|
+
];
|
|
51
64
|
const isBlueInputBundlerOperation = (operation) => {
|
|
52
65
|
return exports.BLUE_INPUT_OPERATIONS.includes(operation.type);
|
|
53
66
|
};
|
|
@@ -64,3 +77,7 @@ const isParaswapInputBundlerOperation = (operation) => {
|
|
|
64
77
|
return exports.PARASWAP_INPUT_OPERATIONS.includes(operation.type);
|
|
65
78
|
};
|
|
66
79
|
exports.isParaswapInputBundlerOperation = isParaswapInputBundlerOperation;
|
|
80
|
+
const isVaultV2InputBundlerOperation = (operation) => {
|
|
81
|
+
return exports.VAULT_V2_INPUT_OPERATIONS.includes(operation.type);
|
|
82
|
+
};
|
|
83
|
+
exports.isVaultV2InputBundlerOperation = isVaultV2InputBundlerOperation;
|
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.
|
|
4
|
+
"version": "3.3.0-next.0",
|
|
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/
|
|
23
|
-
"@morpho-org/
|
|
24
|
-
"@morpho-org/blue-sdk
|
|
25
|
-
"@morpho-org/
|
|
22
|
+
"@morpho-org/morpho-ts": "^2.4.1",
|
|
23
|
+
"@morpho-org/blue-sdk-viem": "^3.2.0-next.0",
|
|
24
|
+
"@morpho-org/blue-sdk": "^4.10.0-next.0",
|
|
25
|
+
"@morpho-org/simulation-sdk": "^3.2.0-next.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@tanstack/query-core": "^5.62.16",
|
|
@@ -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
|
|
38
|
-
"@morpho-org/
|
|
39
|
-
"@morpho-org/blue-sdk": "^4.4.0",
|
|
37
|
+
"@morpho-org/blue-sdk": "^4.10.0-next.0",
|
|
38
|
+
"@morpho-org/blue-sdk-viem": "^3.2.0-next.0",
|
|
40
39
|
"@morpho-org/morpho-ts": "^2.4.1",
|
|
41
|
-
"@morpho-org/
|
|
42
|
-
"@morpho-org/
|
|
43
|
-
"@morpho-org/simulation-sdk-wagmi": "^3.0.
|
|
44
|
-
"@morpho-org/test-wagmi": "^2.0.
|
|
40
|
+
"@morpho-org/morpho-test": "^2.4.1-next.0",
|
|
41
|
+
"@morpho-org/simulation-sdk": "^3.2.0-next.0",
|
|
42
|
+
"@morpho-org/simulation-sdk-wagmi": "^3.1.0-next.0",
|
|
43
|
+
"@morpho-org/test-wagmi": "^2.0.5-next.0",
|
|
44
|
+
"@morpho-org/test": "^2.1.6-next.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"prepublish": "$npm_execpath build",
|