@@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/btcsuite/btcutil/bech32"
12
12
"github.com/ethereum/go-ethereum/common"
13
+ "github.com/holiman/uint256"
13
14
"github.com/mr-tron/base58"
14
15
"github.com/spf13/pflag"
15
16
"github.com/tendermint/tendermint/libs/rand"
@@ -60,6 +61,16 @@ var ibcUpdateChannelChainChainId *string
60
61
var recoverChainIdEvmChainId * string
61
62
var recoverChainIdNewChainId * string
62
63
64
+ var accountantModifyBalanceModule * string
65
+ var accountantModifyBalanceTargetChainId * string
66
+ var accountantModifyBalanceSequence * string
67
+ var accountantModifyBalanceChainId * string
68
+ var accountantModifyBalanceTokenChainId * string
69
+ var accountantModifyBalanceTokenAddress * string
70
+ var accountantModifyBalanceAction * string
71
+ var accountantModifyBalanceAmount * string
72
+ var accountantModifyBalanceReason * string
73
+
63
74
var governanceContractAddress * string
64
75
var governanceTargetAddress * string
65
76
var governanceTargetChain * string
@@ -177,6 +188,21 @@ func init() {
177
188
AdminClientRecoverChainIdCmd .Flags ().AddFlagSet (moduleFlagSet )
178
189
TemplateCmd .AddCommand (AdminClientRecoverChainIdCmd )
179
190
191
+ // flags for the accountant-modify-balance command
192
+ accountantModifyBalanceFlagSet := pflag .NewFlagSet ("accountant-modify-balance" , pflag .ExitOnError )
193
+ accountantModifyBalanceModule = accountantModifyBalanceFlagSet .String ("module" , "GlobalAccountant" , "Module identifier of the accountant" )
194
+ accountantModifyBalanceTargetChainId = accountantModifyBalanceFlagSet .String ("target-chain-id" , "" , "ID of the chain to receive this modification" )
195
+ accountantModifyBalanceSequence = accountantModifyBalanceFlagSet .String ("sequence" , "" , "The sequence number of this modification. Each modification must be uniquely identifiable just by its sequence number" )
196
+ accountantModifyBalanceChainId = accountantModifyBalanceFlagSet .String ("chain-id" , "" , "Chain ID of the account to be modified" )
197
+ accountantModifyBalanceTokenChainId = accountantModifyBalanceFlagSet .String ("token-chain-id" , "" , "Chain ID of the native chain for the token" )
198
+ accountantModifyBalanceTokenAddress = accountantModifyBalanceFlagSet .String ("token-address" , "" , "Address of the token on its native chain, hex string encoded" )
199
+ accountantModifyBalanceAction = accountantModifyBalanceFlagSet .String ("action" , "" , "Kind of modification to be made (1 = add, 2 = sub)" )
200
+ accountantModifyBalanceAmount = accountantModifyBalanceFlagSet .String ("amount" , "" , `Amount to be modified (decimal formatted string indicating the"raw" amount, not adjusted by the decimals of the token` )
201
+ accountantModifyBalanceReason = accountantModifyBalanceFlagSet .String ("reason" , "" , "human-readable reason for the modification" )
202
+ AdminClientAccountantModifyBalanceCmd .Flags ().AddFlagSet (accountantModifyBalanceFlagSet )
203
+ AdminClientAccountantModifyBalanceCmd .Flags ().AddFlagSet (moduleFlagSet )
204
+ TemplateCmd .AddCommand (AdminClientAccountantModifyBalanceCmd )
205
+
180
206
// flags for general-purpose governance call command
181
207
generalPurposeGovernanceFlagSet := pflag .NewFlagSet ("general-purpose-governance" , pflag .ExitOnError )
182
208
governanceContractAddress = generalPurposeGovernanceFlagSet .String ("governance-contract" , "" , "Governance contract address" )
@@ -226,6 +252,12 @@ var AdminClientRecoverChainIdCmd = &cobra.Command{
226
252
Run : runRecoverChainIdTemplate ,
227
253
}
228
254
255
+ var AdminClientAccountantModifyBalanceCmd = & cobra.Command {
256
+ Use : "accountant-modify-balance" ,
257
+ Short : "Generate an empty accountant modify balance template at specified path" ,
258
+ Run : runAccountantModifyBalanceTemplate ,
259
+ }
260
+
229
261
var AdminClientCircleIntegrationUpdateWormholeFinalityCmd = & cobra.Command {
230
262
Use : "circle-integration-update-wormhole-finality" ,
231
263
Short : "Generate an empty circle integration update wormhole finality template at specified path" ,
@@ -348,7 +380,7 @@ func runGuardianSetTemplate(cmd *cobra.Command, args []string) {
348
380
349
381
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
350
382
if err != nil {
351
- panic ( err )
383
+ log . Fatal ( "failed to marshal request: " , err )
352
384
}
353
385
fmt .Print (string (b ))
354
386
}
@@ -381,7 +413,7 @@ func runContractUpgradeTemplate(cmd *cobra.Command, args []string) {
381
413
382
414
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
383
415
if err != nil {
384
- panic ( err )
416
+ log . Fatal ( "failed to marshal request: " , err )
385
417
}
386
418
fmt .Print (string (b ))
387
419
}
@@ -414,7 +446,7 @@ func runTokenBridgeRegisterChainTemplate(cmd *cobra.Command, args []string) {
414
446
415
447
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
416
448
if err != nil {
417
- panic ( err )
449
+ log . Fatal ( "failed to marshal request: " , err )
418
450
}
419
451
fmt .Print (string (b ))
420
452
}
@@ -448,7 +480,7 @@ func runTokenBridgeUpgradeContractTemplate(cmd *cobra.Command, args []string) {
448
480
449
481
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
450
482
if err != nil {
451
- panic ( err )
483
+ log . Fatal ( "failed to marshal request: " , err )
452
484
}
453
485
fmt .Print (string (b ))
454
486
}
@@ -490,7 +522,104 @@ func runRecoverChainIdTemplate(cmd *cobra.Command, args []string) {
490
522
491
523
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
492
524
if err != nil {
493
- panic (err )
525
+ log .Fatal ("failed to marshal request: " , err )
526
+ }
527
+ fmt .Print (string (b ))
528
+ }
529
+
530
+ func runAccountantModifyBalanceTemplate (cmd * cobra.Command , args []string ) {
531
+ if * accountantModifyBalanceModule == "" {
532
+ log .Fatal ("--module must be specified." )
533
+ }
534
+ if * accountantModifyBalanceTargetChainId == "" {
535
+ log .Fatal ("--target-chain-id must be specified." )
536
+ }
537
+ targetChainID , err := parseChainID (* accountantModifyBalanceTargetChainId )
538
+ if err != nil {
539
+ log .Fatal ("failed to parse target chain id: " , err )
540
+ }
541
+ if * accountantModifyBalanceSequence == "" {
542
+ log .Fatal ("--sequence must be specified" )
543
+ }
544
+ sequence , err := strconv .ParseUint (* accountantModifyBalanceSequence , 10 , 64 )
545
+ if err != nil {
546
+ log .Fatal ("failed to parse sequence as uint64: " , err )
547
+ }
548
+ if * accountantModifyBalanceChainId == "" {
549
+ log .Fatal ("--chain-id must be specified." )
550
+ }
551
+ chainID , err := parseChainID (* accountantModifyBalanceChainId )
552
+ if err != nil {
553
+ log .Fatal ("failed to parse chain id: " , err )
554
+ }
555
+ if * accountantModifyBalanceTokenChainId == "" {
556
+ log .Fatal ("--token-chain-id must be specified." )
557
+ }
558
+ tokenChainID , err := parseChainID (* accountantModifyBalanceTokenChainId )
559
+ if err != nil {
560
+ log .Fatal ("failed to parse token chain id: " , err )
561
+ }
562
+ if * accountantModifyBalanceTokenAddress == "" {
563
+ log .Fatal ("--token-address must be specified." )
564
+ }
565
+ tokenAddress , err := parseAddress (* accountantModifyBalanceTokenAddress )
566
+ if err != nil {
567
+ log .Fatal ("failed to parse token address: " , err )
568
+ }
569
+ if * accountantModifyBalanceAction == "" {
570
+ log .Fatal ("--action must be specified" )
571
+ }
572
+ action , err := strconv .ParseUint (* accountantModifyBalanceAction , 10 , 8 )
573
+ if err != nil {
574
+ log .Fatal ("failed to parse modification action as uint8: " , err )
575
+ }
576
+ if action != uint64 (nodev1 .ModificationKind_MODIFICATION_KIND_ADD ) && action != uint64 (nodev1 .ModificationKind_MODIFICATION_KIND_SUBTRACT ) {
577
+ log .Fatal ("invalid modification action, must be 1 (add) or 2 (subtract)" )
578
+ }
579
+ if * accountantModifyBalanceAmount == "" {
580
+ log .Fatal ("--amount must be specified." )
581
+ }
582
+ amount_big := big .NewInt (0 )
583
+ amount_big , ok := amount_big .SetString (* accountantModifyBalanceAmount , 10 )
584
+ if ! ok {
585
+ log .Fatal ("failed to parse amount" )
586
+ }
587
+ _ , overflow := uint256 .FromBig (amount_big )
588
+ if overflow {
589
+ log .Fatal ("amount overflowed uint256" )
590
+ }
591
+ if * accountantModifyBalanceReason == "" {
592
+ log .Fatal ("--reason must be specified." )
593
+ }
594
+ if len (* accountantModifyBalanceReason ) > vaa .AccountantModifyBalanceReasonLength {
595
+ log .Fatalf ("reason is too long, can be at most %d bytes" , vaa .AccountantModifyBalanceReasonLength )
596
+ }
597
+ m := & nodev1.InjectGovernanceVAARequest {
598
+ CurrentSetIndex : uint32 (* templateGuardianIndex ),
599
+ Messages : []* nodev1.GovernanceMessage {
600
+ {
601
+ Sequence : rand .Uint64 (),
602
+ Nonce : rand .Uint32 (),
603
+ Payload : & nodev1.GovernanceMessage_AccountantModifyBalance {
604
+ AccountantModifyBalance : & nodev1.AccountantModifyBalance {
605
+ Module : * accountantModifyBalanceModule ,
606
+ TargetChainId : uint32 (targetChainID ),
607
+ Sequence : uint64 (sequence ),
608
+ ChainId : uint32 (chainID ),
609
+ TokenChain : uint32 (tokenChainID ),
610
+ TokenAddress : tokenAddress ,
611
+ Kind : nodev1 .ModificationKind (action ),
612
+ Amount : * accountantModifyBalanceAmount ,
613
+ Reason : * accountantModifyBalanceReason ,
614
+ },
615
+ },
616
+ },
617
+ },
618
+ }
619
+
620
+ b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
621
+ if err != nil {
622
+ log .Fatal ("failed to marshal request: " , err )
494
623
}
495
624
fmt .Print (string (b ))
496
625
}
@@ -529,7 +658,7 @@ func runCircleIntegrationUpdateWormholeFinalityTemplate(cmd *cobra.Command, args
529
658
530
659
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
531
660
if err != nil {
532
- panic ( err )
661
+ log . Fatal ( "failed to marshal request: " , err )
533
662
}
534
663
fmt .Print (string (b ))
535
664
}
@@ -584,7 +713,7 @@ func runCircleIntegrationRegisterEmitterAndDomainTemplate(cmd *cobra.Command, ar
584
713
585
714
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
586
715
if err != nil {
587
- panic ( err )
716
+ log . Fatal ( "failed to marshal request: " , err )
588
717
}
589
718
fmt .Print (string (b ))
590
719
}
@@ -623,7 +752,7 @@ func runCircleIntegrationUpgradeContractImplementationTemplate(cmd *cobra.Comman
623
752
624
753
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
625
754
if err != nil {
626
- panic ( err )
755
+ log . Fatal ( "failed to marshal request: " , err )
627
756
}
628
757
fmt .Print (string (b ))
629
758
}
@@ -661,7 +790,7 @@ func runWormchainStoreCodeTemplate(cmd *cobra.Command, args []string) {
661
790
662
791
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
663
792
if err != nil {
664
- panic ( err )
793
+ log . Fatal ( "failed to marshal request: " , err )
665
794
}
666
795
fmt .Print (string (b ))
667
796
}
@@ -700,7 +829,7 @@ func runWormchainInstantiateContractTemplate(cmd *cobra.Command, args []string)
700
829
701
830
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
702
831
if err != nil {
703
- panic ( err )
832
+ log . Fatal ( "failed to marshal request: " , err )
704
833
}
705
834
fmt .Print (string (b ))
706
835
}
@@ -739,7 +868,7 @@ func runWormchainMigrateContractTemplate(cmd *cobra.Command, args []string) {
739
868
740
869
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
741
870
if err != nil {
742
- panic ( err )
871
+ log . Fatal ( "failed to marshal request: " , err )
743
872
}
744
873
fmt .Print (string (b ))
745
874
}
@@ -783,7 +912,7 @@ func runWormchainWasmInstantiateAllowlistTemplate(action nodev1.WormchainWasmIns
783
912
784
913
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
785
914
if err != nil {
786
- panic ( err )
915
+ log . Fatal ( "failed to marshal request: " , err )
787
916
}
788
917
fmt .Print (string (b ))
789
918
}
@@ -820,7 +949,7 @@ func runGatewayScheduleUpgradeTemplate(cmd *cobra.Command, args []string) {
820
949
821
950
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
822
951
if err != nil {
823
- panic ( err )
952
+ log . Fatal ( "failed to marshal request: " , err )
824
953
}
825
954
fmt .Print (string (b ))
826
955
}
@@ -839,7 +968,7 @@ func runGatewayCancelUpgradeTemplate(cmd *cobra.Command, args []string) {
839
968
840
969
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
841
970
if err != nil {
842
- panic ( err )
971
+ log . Fatal ( "failed to marshal request: " , err )
843
972
}
844
973
fmt .Print (string (b ))
845
974
}
@@ -866,7 +995,7 @@ func runGatewayIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args []
866
995
867
996
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
868
997
if err != nil {
869
- panic ( err )
998
+ log . Fatal ( "failed to marshal request: " , err )
870
999
}
871
1000
fmt .Print (string (b ))
872
1001
}
@@ -923,7 +1052,7 @@ func runIbcUpdateChannelChainTemplate(module nodev1.IbcUpdateChannelChainModule)
923
1052
924
1053
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
925
1054
if err != nil {
926
- panic ( err )
1055
+ log . Fatal ( "failed to marshal request: " , err )
927
1056
}
928
1057
fmt .Print (string (b ))
929
1058
@@ -957,7 +1086,7 @@ func runWormholeRelayerSetDefaultDeliveryProviderTemplate(cmd *cobra.Command, ar
957
1086
958
1087
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
959
1088
if err != nil {
960
- panic ( err )
1089
+ log . Fatal ( "failed to marshal request: " , err )
961
1090
}
962
1091
fmt .Print (string (b ))
963
1092
}
@@ -1008,7 +1137,7 @@ func runGeneralPurposeGovernanceEvmCallTemplate(cmd *cobra.Command, args []strin
1008
1137
1009
1138
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
1010
1139
if err != nil {
1011
- panic ( err )
1140
+ log . Fatal ( "failed to marshal request: " , err )
1012
1141
}
1013
1142
fmt .Print (string (b ))
1014
1143
}
@@ -1051,7 +1180,7 @@ func runGeneralPurposeGovernanceSolanaCallTemplate(cmd *cobra.Command, args []st
1051
1180
1052
1181
b , err := prototext.MarshalOptions {Multiline : true }.Marshal (m )
1053
1182
if err != nil {
1054
- panic ( err )
1183
+ log . Fatal ( "failed to marshal request: " , err )
1055
1184
}
1056
1185
fmt .Print (string (b ))
1057
1186
}
@@ -1097,10 +1226,10 @@ func parseChainID(name string) (vaa.ChainID, error) {
1097
1226
return s , nil
1098
1227
}
1099
1228
1100
- // parse as uint32
1101
- i , err := strconv .ParseUint (name , 10 , 32 )
1229
+ // parse as uint16
1230
+ i , err := strconv .ParseUint (name , 10 , 16 )
1102
1231
if err != nil {
1103
- return 0 , fmt .Errorf ("failed to parse as name or uint32 : %v" , err )
1232
+ return 0 , fmt .Errorf ("failed to parse as name or uint16 : %v" , err )
1104
1233
}
1105
1234
1106
1235
return vaa .ChainID (i ), nil
0 commit comments