@oydual31/more-vaults-sdk 0.2.9 → 0.3.1
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/README.md +25 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/{spokeRoutes-FgKCJQYa.d.cts → spokeRoutes-DK7cIW4z.d.cts} +4 -0
- package/dist/{spokeRoutes-FgKCJQYa.d.ts → spokeRoutes-DK7cIW4z.d.ts} +4 -0
- package/dist/viem/index.cjs +604 -5
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.d.cts +721 -3
- package/dist/viem/index.d.ts +721 -3
- package/dist/viem/index.js +587 -7
- package/dist/viem/index.js.map +1 -1
- package/package.json +1 -1
- package/src/viem/abis.ts +329 -0
- package/src/viem/curatorMulticall.ts +299 -0
- package/src/viem/curatorStatus.ts +255 -0
- package/src/viem/index.ts +34 -0
- package/src/viem/types.ts +79 -0
- package/src/viem/userHelpers.ts +22 -6
package/package.json
CHANGED
package/src/viem/abis.ts
CHANGED
|
@@ -451,6 +451,335 @@ export const OFT_ABI = [
|
|
|
451
451
|
},
|
|
452
452
|
] as const
|
|
453
453
|
|
|
454
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
455
|
+
// Curator Operations ABIs
|
|
456
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* MulticallFacet ABI — curator action submission and execution with timelock.
|
|
460
|
+
*/
|
|
461
|
+
export const MULTICALL_ABI = [
|
|
462
|
+
{
|
|
463
|
+
type: 'function',
|
|
464
|
+
name: 'submitActions',
|
|
465
|
+
inputs: [
|
|
466
|
+
{ name: 'actionsData', type: 'bytes[]' },
|
|
467
|
+
],
|
|
468
|
+
outputs: [{ name: 'nonce', type: 'uint256' }],
|
|
469
|
+
stateMutability: 'nonpayable',
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
type: 'function',
|
|
473
|
+
name: 'executeActions',
|
|
474
|
+
inputs: [
|
|
475
|
+
{ name: 'actionsNonce', type: 'uint256' },
|
|
476
|
+
],
|
|
477
|
+
outputs: [],
|
|
478
|
+
stateMutability: 'nonpayable',
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
type: 'function',
|
|
482
|
+
name: 'getPendingActions',
|
|
483
|
+
inputs: [
|
|
484
|
+
{ name: 'actionsNonce', type: 'uint256' },
|
|
485
|
+
],
|
|
486
|
+
outputs: [
|
|
487
|
+
{ name: 'actionsData', type: 'bytes[]' },
|
|
488
|
+
{ name: 'pendingUntil', type: 'uint256' },
|
|
489
|
+
],
|
|
490
|
+
stateMutability: 'view',
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
type: 'function',
|
|
494
|
+
name: 'getCurrentNonce',
|
|
495
|
+
inputs: [],
|
|
496
|
+
outputs: [{ name: '', type: 'uint256' }],
|
|
497
|
+
stateMutability: 'view',
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
type: 'function',
|
|
501
|
+
name: 'vetoActions',
|
|
502
|
+
inputs: [
|
|
503
|
+
{ name: 'actionsNonces', type: 'uint256[]' },
|
|
504
|
+
],
|
|
505
|
+
outputs: [],
|
|
506
|
+
stateMutability: 'nonpayable',
|
|
507
|
+
},
|
|
508
|
+
] as const
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* GenericDexFacet ABI — single and batch token swaps through any DEX aggregator.
|
|
512
|
+
*/
|
|
513
|
+
export const DEX_ABI = [
|
|
514
|
+
{
|
|
515
|
+
type: 'function',
|
|
516
|
+
name: 'executeSwap',
|
|
517
|
+
inputs: [
|
|
518
|
+
{
|
|
519
|
+
name: 'params',
|
|
520
|
+
type: 'tuple',
|
|
521
|
+
components: [
|
|
522
|
+
{ name: 'targetContract', type: 'address' },
|
|
523
|
+
{ name: 'tokenIn', type: 'address' },
|
|
524
|
+
{ name: 'tokenOut', type: 'address' },
|
|
525
|
+
{ name: 'maxAmountIn', type: 'uint256' },
|
|
526
|
+
{ name: 'minAmountOut', type: 'uint256' },
|
|
527
|
+
{ name: 'swapCallData', type: 'bytes' },
|
|
528
|
+
],
|
|
529
|
+
},
|
|
530
|
+
],
|
|
531
|
+
outputs: [{ name: 'amountOut', type: 'uint256' }],
|
|
532
|
+
stateMutability: 'nonpayable',
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
type: 'function',
|
|
536
|
+
name: 'executeBatchSwap',
|
|
537
|
+
inputs: [
|
|
538
|
+
{
|
|
539
|
+
name: 'params',
|
|
540
|
+
type: 'tuple',
|
|
541
|
+
components: [
|
|
542
|
+
{
|
|
543
|
+
name: 'swaps',
|
|
544
|
+
type: 'tuple[]',
|
|
545
|
+
components: [
|
|
546
|
+
{ name: 'targetContract', type: 'address' },
|
|
547
|
+
{ name: 'tokenIn', type: 'address' },
|
|
548
|
+
{ name: 'tokenOut', type: 'address' },
|
|
549
|
+
{ name: 'maxAmountIn', type: 'uint256' },
|
|
550
|
+
{ name: 'minAmountOut', type: 'uint256' },
|
|
551
|
+
{ name: 'swapCallData', type: 'bytes' },
|
|
552
|
+
],
|
|
553
|
+
},
|
|
554
|
+
],
|
|
555
|
+
},
|
|
556
|
+
],
|
|
557
|
+
outputs: [{ name: 'amountsOut', type: 'uint256[]' }],
|
|
558
|
+
stateMutability: 'nonpayable',
|
|
559
|
+
},
|
|
560
|
+
] as const
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* BridgeFacet ABI — curator bridging and cross-chain request initiation.
|
|
564
|
+
* (extends the existing BRIDGE_ABI with curator-specific functions)
|
|
565
|
+
*/
|
|
566
|
+
export const BRIDGE_FACET_ABI = [
|
|
567
|
+
{
|
|
568
|
+
type: 'function',
|
|
569
|
+
name: 'executeBridging',
|
|
570
|
+
inputs: [
|
|
571
|
+
{ name: 'adapter', type: 'address' },
|
|
572
|
+
{ name: 'token', type: 'address' },
|
|
573
|
+
{ name: 'amount', type: 'uint256' },
|
|
574
|
+
{ name: 'bridgeSpecificParams', type: 'bytes' },
|
|
575
|
+
],
|
|
576
|
+
outputs: [],
|
|
577
|
+
stateMutability: 'payable',
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
type: 'function',
|
|
581
|
+
name: 'initVaultActionRequest',
|
|
582
|
+
inputs: [
|
|
583
|
+
{ name: 'actionType', type: 'uint8' },
|
|
584
|
+
{ name: 'actionCallData', type: 'bytes' },
|
|
585
|
+
{ name: 'amountLimit', type: 'uint256' },
|
|
586
|
+
{ name: 'extraOptions', type: 'bytes' },
|
|
587
|
+
],
|
|
588
|
+
outputs: [{ name: 'guid', type: 'bytes32' }],
|
|
589
|
+
stateMutability: 'payable',
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
type: 'function',
|
|
593
|
+
name: 'executeRequest',
|
|
594
|
+
inputs: [
|
|
595
|
+
{ name: 'guid', type: 'bytes32' },
|
|
596
|
+
],
|
|
597
|
+
outputs: [],
|
|
598
|
+
stateMutability: 'nonpayable',
|
|
599
|
+
},
|
|
600
|
+
] as const
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* ERC7540Facet ABI — async deposit and redeem operations on ERC7540 vaults.
|
|
604
|
+
*/
|
|
605
|
+
export const ERC7540_FACET_ABI = [
|
|
606
|
+
{
|
|
607
|
+
type: 'function',
|
|
608
|
+
name: 'erc7540RequestDeposit',
|
|
609
|
+
inputs: [
|
|
610
|
+
{ name: 'vault', type: 'address' },
|
|
611
|
+
{ name: 'assets', type: 'uint256' },
|
|
612
|
+
],
|
|
613
|
+
outputs: [{ name: 'requestId', type: 'uint256' }],
|
|
614
|
+
stateMutability: 'nonpayable',
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
type: 'function',
|
|
618
|
+
name: 'erc7540RequestRedeem',
|
|
619
|
+
inputs: [
|
|
620
|
+
{ name: 'vault', type: 'address' },
|
|
621
|
+
{ name: 'shares', type: 'uint256' },
|
|
622
|
+
],
|
|
623
|
+
outputs: [{ name: 'requestId', type: 'uint256' }],
|
|
624
|
+
stateMutability: 'nonpayable',
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
type: 'function',
|
|
628
|
+
name: 'erc7540Deposit',
|
|
629
|
+
inputs: [
|
|
630
|
+
{ name: 'vault', type: 'address' },
|
|
631
|
+
{ name: 'assets', type: 'uint256' },
|
|
632
|
+
],
|
|
633
|
+
outputs: [{ name: 'shares', type: 'uint256' }],
|
|
634
|
+
stateMutability: 'nonpayable',
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
type: 'function',
|
|
638
|
+
name: 'erc7540Redeem',
|
|
639
|
+
inputs: [
|
|
640
|
+
{ name: 'vault', type: 'address' },
|
|
641
|
+
{ name: 'shares', type: 'uint256' },
|
|
642
|
+
],
|
|
643
|
+
outputs: [{ name: 'assets', type: 'uint256' }],
|
|
644
|
+
stateMutability: 'nonpayable',
|
|
645
|
+
},
|
|
646
|
+
] as const
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* ConfigurationFacet ABI — extended with curator-relevant read functions.
|
|
650
|
+
* Augments the existing CONFIG_ABI with additional getters needed by curator dashboard.
|
|
651
|
+
*/
|
|
652
|
+
export const CURATOR_CONFIG_ABI = [
|
|
653
|
+
{
|
|
654
|
+
type: 'function',
|
|
655
|
+
name: 'curator',
|
|
656
|
+
inputs: [],
|
|
657
|
+
outputs: [{ name: '', type: 'address' }],
|
|
658
|
+
stateMutability: 'view',
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
type: 'function',
|
|
662
|
+
name: 'timeLockPeriod',
|
|
663
|
+
inputs: [],
|
|
664
|
+
outputs: [{ name: '', type: 'uint256' }],
|
|
665
|
+
stateMutability: 'view',
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
type: 'function',
|
|
669
|
+
name: 'getAvailableAssets',
|
|
670
|
+
inputs: [],
|
|
671
|
+
outputs: [{ name: '', type: 'address[]' }],
|
|
672
|
+
stateMutability: 'view',
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
type: 'function',
|
|
676
|
+
name: 'getMaxSlippagePercent',
|
|
677
|
+
inputs: [],
|
|
678
|
+
outputs: [{ name: '', type: 'uint256' }],
|
|
679
|
+
stateMutability: 'view',
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
type: 'function',
|
|
683
|
+
name: 'getCrossChainAccountingManager',
|
|
684
|
+
inputs: [],
|
|
685
|
+
outputs: [{ name: '', type: 'address' }],
|
|
686
|
+
stateMutability: 'view',
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
type: 'function',
|
|
690
|
+
name: 'paused',
|
|
691
|
+
inputs: [],
|
|
692
|
+
outputs: [{ name: '', type: 'bool' }],
|
|
693
|
+
stateMutability: 'view',
|
|
694
|
+
},
|
|
695
|
+
] as const
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* LzAdapter ABI — fee quoting for bridge and LZ Read operations.
|
|
699
|
+
*/
|
|
700
|
+
export const LZ_ADAPTER_ABI = [
|
|
701
|
+
{
|
|
702
|
+
type: 'function',
|
|
703
|
+
name: 'quoteBridgeFee',
|
|
704
|
+
inputs: [
|
|
705
|
+
{ name: 'bridgeSpecificParams', type: 'bytes' },
|
|
706
|
+
],
|
|
707
|
+
outputs: [{ name: 'nativeFee', type: 'uint256' }],
|
|
708
|
+
stateMutability: 'view',
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
type: 'function',
|
|
712
|
+
name: 'quoteReadFee',
|
|
713
|
+
inputs: [
|
|
714
|
+
{ name: 'vaults', type: 'address[]' },
|
|
715
|
+
{ name: 'eids', type: 'uint32[]' },
|
|
716
|
+
{ name: '_extraOptions', type: 'bytes' },
|
|
717
|
+
],
|
|
718
|
+
outputs: [
|
|
719
|
+
{
|
|
720
|
+
name: 'fee',
|
|
721
|
+
type: 'tuple',
|
|
722
|
+
components: [
|
|
723
|
+
{ name: 'nativeFee', type: 'uint256' },
|
|
724
|
+
{ name: 'lzTokenFee', type: 'uint256' },
|
|
725
|
+
],
|
|
726
|
+
},
|
|
727
|
+
],
|
|
728
|
+
stateMutability: 'view',
|
|
729
|
+
},
|
|
730
|
+
] as const
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* ERC4626Facet ABI — synchronous deposit and redeem into whitelisted ERC-4626 vaults.
|
|
734
|
+
*/
|
|
735
|
+
export const ERC4626_FACET_ABI = [
|
|
736
|
+
{
|
|
737
|
+
type: 'function',
|
|
738
|
+
name: 'erc4626Deposit',
|
|
739
|
+
inputs: [
|
|
740
|
+
{ name: 'vault', type: 'address' },
|
|
741
|
+
{ name: 'assets', type: 'uint256' },
|
|
742
|
+
],
|
|
743
|
+
outputs: [{ name: 'shares', type: 'uint256' }],
|
|
744
|
+
stateMutability: 'nonpayable',
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
type: 'function',
|
|
748
|
+
name: 'erc4626Redeem',
|
|
749
|
+
inputs: [
|
|
750
|
+
{ name: 'vault', type: 'address' },
|
|
751
|
+
{ name: 'shares', type: 'uint256' },
|
|
752
|
+
],
|
|
753
|
+
outputs: [{ name: 'assets', type: 'uint256' }],
|
|
754
|
+
stateMutability: 'nonpayable',
|
|
755
|
+
},
|
|
756
|
+
] as const
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Vault analysis ABIs — per-vault whitelist and registry reads.
|
|
760
|
+
*/
|
|
761
|
+
export const VAULT_ANALYSIS_ABI = [
|
|
762
|
+
// Asset management reads
|
|
763
|
+
{ type: 'function', name: 'getAvailableAssets', inputs: [], outputs: [{ type: 'address[]' }], stateMutability: 'view' },
|
|
764
|
+
{ type: 'function', name: 'getDepositableAssets', inputs: [], outputs: [{ type: 'address[]' }], stateMutability: 'view' },
|
|
765
|
+
{ type: 'function', name: 'isAssetAvailable', inputs: [{ name: 'asset', type: 'address' }], outputs: [{ type: 'bool' }], stateMutability: 'view' },
|
|
766
|
+
{ type: 'function', name: 'isAssetDepositable', inputs: [{ name: 'asset', type: 'address' }], outputs: [{ type: 'bool' }], stateMutability: 'view' },
|
|
767
|
+
// Deposit whitelist
|
|
768
|
+
{ type: 'function', name: 'isDepositWhitelistEnabled', inputs: [], outputs: [{ type: 'bool' }], stateMutability: 'view' },
|
|
769
|
+
{ type: 'function', name: 'getAvailableToDeposit', inputs: [{ name: 'depositor', type: 'address' }], outputs: [{ type: 'uint256' }], stateMutability: 'view' },
|
|
770
|
+
// Registry
|
|
771
|
+
{ type: 'function', name: 'moreVaultsRegistry', inputs: [], outputs: [{ type: 'address' }], stateMutability: 'view' },
|
|
772
|
+
] as const
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* MoreVaultsRegistry ABI — global protocol and bridge whitelist checks.
|
|
776
|
+
*/
|
|
777
|
+
export const REGISTRY_ABI = [
|
|
778
|
+
{ type: 'function', name: 'isWhitelisted', inputs: [{ name: 'protocol', type: 'address' }], outputs: [{ type: 'bool' }], stateMutability: 'view' },
|
|
779
|
+
{ type: 'function', name: 'isBridgeAllowed', inputs: [{ name: 'bridge', type: 'address' }], outputs: [{ type: 'bool' }], stateMutability: 'view' },
|
|
780
|
+
{ type: 'function', name: 'getAllowedFacets', inputs: [], outputs: [{ type: 'address[]' }], stateMutability: 'view' },
|
|
781
|
+
] as const
|
|
782
|
+
|
|
454
783
|
/**
|
|
455
784
|
* Minimal LZ Endpoint V2 ABI for compose queue management.
|
|
456
785
|
* Used by the Stargate 2-TX flow to check compose status and execute pending composes.
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curator MulticallFacet write operations for the MoreVaults SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides typed helpers to submit, execute, and veto curator action batches
|
|
5
|
+
* on any MoreVaults diamond that has the MulticallFacet installed.
|
|
6
|
+
*
|
|
7
|
+
* All write functions use the simulate-then-write pattern:
|
|
8
|
+
* 1. `publicClient.simulateContract` — validates on-chain, catches reverts early
|
|
9
|
+
* 2. `walletClient.writeContract` — sends the actual transaction
|
|
10
|
+
*
|
|
11
|
+
* @module curatorMulticall
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
type Address,
|
|
16
|
+
type PublicClient,
|
|
17
|
+
type WalletClient,
|
|
18
|
+
encodeFunctionData,
|
|
19
|
+
getAddress,
|
|
20
|
+
} from 'viem'
|
|
21
|
+
import {
|
|
22
|
+
MULTICALL_ABI,
|
|
23
|
+
DEX_ABI,
|
|
24
|
+
ERC7540_FACET_ABI,
|
|
25
|
+
ERC4626_FACET_ABI,
|
|
26
|
+
} from './abis.js'
|
|
27
|
+
import type {
|
|
28
|
+
CuratorAction,
|
|
29
|
+
SubmitActionsResult,
|
|
30
|
+
} from './types.js'
|
|
31
|
+
|
|
32
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
33
|
+
// Encoding helpers
|
|
34
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Encode a single typed CuratorAction into raw calldata bytes suitable for
|
|
38
|
+
* passing into `submitActions(bytes[] actionsData)`.
|
|
39
|
+
*
|
|
40
|
+
* The encoded bytes are the full ABI-encoded function call (4-byte selector +
|
|
41
|
+
* arguments) targeting the vault diamond itself — the MulticallFacet will
|
|
42
|
+
* call `address(this).call(actionsData[i])` for each entry.
|
|
43
|
+
*
|
|
44
|
+
* @param action A discriminated-union CuratorAction describing what to do
|
|
45
|
+
* @returns ABI-encoded calldata bytes (`0x`-prefixed hex string)
|
|
46
|
+
*/
|
|
47
|
+
export function encodeCuratorAction(action: CuratorAction): `0x${string}` {
|
|
48
|
+
switch (action.type) {
|
|
49
|
+
case 'swap':
|
|
50
|
+
return encodeFunctionData({
|
|
51
|
+
abi: DEX_ABI,
|
|
52
|
+
functionName: 'executeSwap',
|
|
53
|
+
args: [
|
|
54
|
+
{
|
|
55
|
+
targetContract: getAddress(action.params.targetContract),
|
|
56
|
+
tokenIn: getAddress(action.params.tokenIn),
|
|
57
|
+
tokenOut: getAddress(action.params.tokenOut),
|
|
58
|
+
maxAmountIn: action.params.maxAmountIn,
|
|
59
|
+
minAmountOut: action.params.minAmountOut,
|
|
60
|
+
swapCallData: action.params.swapCallData,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
case 'batchSwap':
|
|
66
|
+
return encodeFunctionData({
|
|
67
|
+
abi: DEX_ABI,
|
|
68
|
+
functionName: 'executeBatchSwap',
|
|
69
|
+
args: [
|
|
70
|
+
{
|
|
71
|
+
swaps: action.params.swaps.map((s) => ({
|
|
72
|
+
targetContract: getAddress(s.targetContract),
|
|
73
|
+
tokenIn: getAddress(s.tokenIn),
|
|
74
|
+
tokenOut: getAddress(s.tokenOut),
|
|
75
|
+
maxAmountIn: s.maxAmountIn,
|
|
76
|
+
minAmountOut: s.minAmountOut,
|
|
77
|
+
swapCallData: s.swapCallData,
|
|
78
|
+
})),
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
case 'erc4626Deposit':
|
|
84
|
+
return encodeFunctionData({
|
|
85
|
+
abi: ERC4626_FACET_ABI,
|
|
86
|
+
functionName: 'erc4626Deposit',
|
|
87
|
+
args: [getAddress(action.vault), action.assets],
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
case 'erc4626Redeem':
|
|
91
|
+
return encodeFunctionData({
|
|
92
|
+
abi: ERC4626_FACET_ABI,
|
|
93
|
+
functionName: 'erc4626Redeem',
|
|
94
|
+
args: [getAddress(action.vault), action.shares],
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
case 'erc7540RequestDeposit':
|
|
98
|
+
return encodeFunctionData({
|
|
99
|
+
abi: ERC7540_FACET_ABI,
|
|
100
|
+
functionName: 'erc7540RequestDeposit',
|
|
101
|
+
args: [getAddress(action.vault), action.assets],
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
case 'erc7540Deposit':
|
|
105
|
+
return encodeFunctionData({
|
|
106
|
+
abi: ERC7540_FACET_ABI,
|
|
107
|
+
functionName: 'erc7540Deposit',
|
|
108
|
+
args: [getAddress(action.vault), action.assets],
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
case 'erc7540RequestRedeem':
|
|
112
|
+
return encodeFunctionData({
|
|
113
|
+
abi: ERC7540_FACET_ABI,
|
|
114
|
+
functionName: 'erc7540RequestRedeem',
|
|
115
|
+
args: [getAddress(action.vault), action.shares],
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
case 'erc7540Redeem':
|
|
119
|
+
return encodeFunctionData({
|
|
120
|
+
abi: ERC7540_FACET_ABI,
|
|
121
|
+
functionName: 'erc7540Redeem',
|
|
122
|
+
args: [getAddress(action.vault), action.shares],
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
default: {
|
|
126
|
+
// TypeScript exhaustiveness check — this branch is never reached at runtime
|
|
127
|
+
const _exhaustive: never = action
|
|
128
|
+
throw new Error(`[MoreVaults] Unknown CuratorAction type: ${(_exhaustive as any).type}`)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Encode an array of CuratorActions into a calldata array ready for
|
|
135
|
+
* `submitActions`.
|
|
136
|
+
*
|
|
137
|
+
* @param actions Array of typed CuratorAction objects
|
|
138
|
+
* @returns Array of ABI-encoded calldata hex strings
|
|
139
|
+
*/
|
|
140
|
+
export function buildCuratorBatch(actions: CuratorAction[]): `0x${string}`[] {
|
|
141
|
+
return actions.map(encodeCuratorAction)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
145
|
+
// Write operations
|
|
146
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Submit a batch of curator actions to the vault's MulticallFacet.
|
|
150
|
+
*
|
|
151
|
+
* When `timeLockPeriod == 0` the contract immediately executes the actions
|
|
152
|
+
* inside `submitActions` itself. When a timelock is configured the actions
|
|
153
|
+
* are queued and must be executed later with `executeActions`.
|
|
154
|
+
*
|
|
155
|
+
* Uses the simulate-then-write pattern: simulation runs first so any on-chain
|
|
156
|
+
* revert (wrong curator, bad selector, slippage limit, etc.) surfaces before
|
|
157
|
+
* any gas is spent on a failing transaction.
|
|
158
|
+
*
|
|
159
|
+
* After the write succeeds, the function reads `getCurrentNonce` to determine
|
|
160
|
+
* which nonce was assigned to this batch (nonce - 1 after the submit increments it).
|
|
161
|
+
*
|
|
162
|
+
* @param walletClient Wallet client with curator account attached
|
|
163
|
+
* @param publicClient Public client for reads and simulation
|
|
164
|
+
* @param vault Vault address (diamond proxy)
|
|
165
|
+
* @param actions Array of raw calldata bytes — use `buildCuratorBatch` to build
|
|
166
|
+
* @returns Transaction hash and the nonce assigned to this batch
|
|
167
|
+
* @throws If the caller is not the curator, or any action selector is
|
|
168
|
+
* not allowed, or any action would revert
|
|
169
|
+
*/
|
|
170
|
+
export async function submitActions(
|
|
171
|
+
walletClient: WalletClient,
|
|
172
|
+
publicClient: PublicClient,
|
|
173
|
+
vault: Address,
|
|
174
|
+
actions: `0x${string}`[],
|
|
175
|
+
): Promise<SubmitActionsResult> {
|
|
176
|
+
const account = walletClient.account!
|
|
177
|
+
const v = getAddress(vault)
|
|
178
|
+
|
|
179
|
+
// Simulate first — catches permission errors and reverts before spending gas
|
|
180
|
+
await publicClient.simulateContract({
|
|
181
|
+
address: v,
|
|
182
|
+
abi: MULTICALL_ABI,
|
|
183
|
+
functionName: 'submitActions',
|
|
184
|
+
args: [actions],
|
|
185
|
+
account: account.address,
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
const txHash = await walletClient.writeContract({
|
|
189
|
+
address: v,
|
|
190
|
+
abi: MULTICALL_ABI,
|
|
191
|
+
functionName: 'submitActions',
|
|
192
|
+
args: [actions],
|
|
193
|
+
account,
|
|
194
|
+
chain: walletClient.chain,
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
// Read the nonce that was assigned: the contract increments actionNonce after storing,
|
|
198
|
+
// so getCurrentNonce now returns (assignedNonce + 1). Subtract 1 to recover it.
|
|
199
|
+
const nextNonce = await publicClient.readContract({
|
|
200
|
+
address: v,
|
|
201
|
+
abi: MULTICALL_ABI,
|
|
202
|
+
functionName: 'getCurrentNonce',
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
const nonce = nextNonce - 1n
|
|
206
|
+
|
|
207
|
+
return { txHash, nonce }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Execute pending actions after their timelock period has expired.
|
|
212
|
+
*
|
|
213
|
+
* Can only be called when `block.timestamp >= pendingUntil`. The contract
|
|
214
|
+
* reverts with `ActionsStillPending` if the timelock has not expired.
|
|
215
|
+
*
|
|
216
|
+
* Caller must be the curator (or any address when timeLockPeriod == 0, since
|
|
217
|
+
* in that case `submitActions` auto-executes and there is nothing to execute here).
|
|
218
|
+
*
|
|
219
|
+
* Uses simulate-then-write to surface on-chain reverts early.
|
|
220
|
+
*
|
|
221
|
+
* @param walletClient Wallet client with curator account attached
|
|
222
|
+
* @param publicClient Public client for reads and simulation
|
|
223
|
+
* @param vault Vault address (diamond proxy)
|
|
224
|
+
* @param nonce The action batch nonce to execute
|
|
225
|
+
* @returns Transaction hash
|
|
226
|
+
*/
|
|
227
|
+
export async function executeActions(
|
|
228
|
+
walletClient: WalletClient,
|
|
229
|
+
publicClient: PublicClient,
|
|
230
|
+
vault: Address,
|
|
231
|
+
nonce: bigint,
|
|
232
|
+
): Promise<{ txHash: `0x${string}` }> {
|
|
233
|
+
const account = walletClient.account!
|
|
234
|
+
const v = getAddress(vault)
|
|
235
|
+
|
|
236
|
+
// Simulate to surface reverts (NoSuchActions, ActionsStillPending, slippage)
|
|
237
|
+
await publicClient.simulateContract({
|
|
238
|
+
address: v,
|
|
239
|
+
abi: MULTICALL_ABI,
|
|
240
|
+
functionName: 'executeActions',
|
|
241
|
+
args: [nonce],
|
|
242
|
+
account: account.address,
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
const txHash = await walletClient.writeContract({
|
|
246
|
+
address: v,
|
|
247
|
+
abi: MULTICALL_ABI,
|
|
248
|
+
functionName: 'executeActions',
|
|
249
|
+
args: [nonce],
|
|
250
|
+
account,
|
|
251
|
+
chain: walletClient.chain,
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
return { txHash }
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Guardian-only: cancel (veto) one or more pending action batches.
|
|
259
|
+
*
|
|
260
|
+
* Deletes the pending actions from storage, preventing them from ever being
|
|
261
|
+
* executed. Only the vault guardian can call this.
|
|
262
|
+
*
|
|
263
|
+
* Uses simulate-then-write to catch `NoSuchActions` and permission errors early.
|
|
264
|
+
*
|
|
265
|
+
* @param walletClient Wallet client with guardian account attached
|
|
266
|
+
* @param publicClient Public client for reads and simulation
|
|
267
|
+
* @param vault Vault address (diamond proxy)
|
|
268
|
+
* @param nonces Array of action nonces to cancel
|
|
269
|
+
* @returns Transaction hash
|
|
270
|
+
*/
|
|
271
|
+
export async function vetoActions(
|
|
272
|
+
walletClient: WalletClient,
|
|
273
|
+
publicClient: PublicClient,
|
|
274
|
+
vault: Address,
|
|
275
|
+
nonces: bigint[],
|
|
276
|
+
): Promise<{ txHash: `0x${string}` }> {
|
|
277
|
+
const account = walletClient.account!
|
|
278
|
+
const v = getAddress(vault)
|
|
279
|
+
|
|
280
|
+
// Simulate to catch NotGuardian, NoSuchActions, etc.
|
|
281
|
+
await publicClient.simulateContract({
|
|
282
|
+
address: v,
|
|
283
|
+
abi: MULTICALL_ABI,
|
|
284
|
+
functionName: 'vetoActions',
|
|
285
|
+
args: [nonces],
|
|
286
|
+
account: account.address,
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
const txHash = await walletClient.writeContract({
|
|
290
|
+
address: v,
|
|
291
|
+
abi: MULTICALL_ABI,
|
|
292
|
+
functionName: 'vetoActions',
|
|
293
|
+
args: [nonces],
|
|
294
|
+
account,
|
|
295
|
+
chain: walletClient.chain,
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
return { txHash }
|
|
299
|
+
}
|