1+ import 'dotenv/config' ;
12import axios from 'axios' ;
2- import { Command , Option } from 'commander' ;
3- import { ConfigUrl } from "./constants" ;
4- import { RawConfig } from "@buildwithsygma/sygma-sdk-core" ;
3+ import { ethers } from 'ethers' ;
4+ import { Command , Option } from 'commander' ;
5+ import { SharedConfig } from "./constants" ;
6+ import { getWalletsForDifferentProviders , deriveWalletsFromMnemonic , sendPauseTransactions } from "./utils" ;
7+ import { RawConfig , Domain } from '@buildwithsygma/sygma-sdk-core' ;
58
69const program = new Command ( ) ;
7- console . log ( "pero" ) ;
810
911program
1012 . name ( "pause-bridge" )
1113 . description ( "Pauses all bridge instances across all networks" )
12- . argument ( "<string>" , "mnemonic or private key of the wallet" )
14+ . version ( "0.0.1" )
15+
16+ program
17+ . command ( "pause" )
1318 . addOption (
14- new Option ( '--environment , -e ' , 'Environment on which to pause bridge instances' )
19+ new Option ( '-e , --environment <environment> ' , 'Environment on which to pause bridge instances' )
1520 . choices ( [ 'devnet' , 'testnet' , 'mainnet' ] )
1621 )
17- . action ( async ( mnemonic : string , environment : keyof typeof ConfigUrl ) => {
22+ . addOption (
23+ new Option ( '-pk, --private-key <privateKey>' , 'Private key to use for signing transactions' )
24+ )
25+ . addOption (
26+ new Option ( '-m, --mnemonic <mnemonic>' , 'Mnemonic to use for signing transactions' ) . conflicts ( 'private-key' )
27+ )
28+ . action ( async ( configs : any ) => {
1829 try {
19- console . log ( "pero" ) ;
20- const response = await axios . get ( ConfigUrl [ environment ] ) as unknown as RawConfig ;
21- console . log ( response )
30+ const network : keyof typeof SharedConfig = configs . environment ;
31+ const {
32+ privateKey,
33+ mnemonic
34+ } = configs ;
35+
36+ const {
37+ data
38+ } = await axios . get ( SharedConfig [ network ] ) as unknown as { data : RawConfig } ;
39+
40+ const networks : Array < Domain > = data . domains . filter ( ( network : Domain ) => network . name === "ethereum" ) ; // just evms for now
41+
42+ let wallets : Array < ethers . Wallet | ethers . HDNodeWallet > = [ ] ;
43+
44+ if ( mnemonic ) {
45+ wallets = await deriveWalletsFromMnemonic ( mnemonic , networks ) ;
46+ } else if ( privateKey ) {
47+ wallets = await getWalletsForDifferentProviders ( privateKey , networks ) ;
48+ } else {
49+ throw new Error ( 'Either mnemonic or private key must be provided' ) ;
50+ }
51+
52+ await sendPauseTransactions ( networks , wallets ) ;
53+
2254 } catch ( err ) {
2355 if ( err instanceof Error ) {
2456 throw new Error ( `Failed to fetch shared config because of: ${ err . message } ` ) ;
@@ -27,3 +59,5 @@ program
2759 }
2860 }
2961 } )
62+
63+ program . parse ( process . argv ) ;
0 commit comments