@@ -4,10 +4,10 @@ import { dirname } from "node:path";
44import { exit } from "node:process" ;
55
66import { Command } from "commander" ;
7- import type { Abi } from "viem" ;
7+ import type { Abi , Chain } from "viem" ;
88import { createPublicClient , createWalletClient , http , isAddress , parseAbi , parseAbiItem , parseEther , toHex } from "viem" ;
99import { privateKeyToAccount } from "viem/accounts" ;
10- import { foundry , baseSepolia } from "viem/chains" ;
10+ import { base , foundry , baseSepolia } from "viem/chains" ;
1111import { DopplerSDK } from "@whetstone-research/doppler-sdk/evm" ;
1212
1313import { importAbi } from "@/utils/importAbi.js" ;
@@ -44,6 +44,11 @@ const ENABLE_MARKET_COMMAND = process.env.ENABLE_MARKET_COMMAND ? tr
4444const RIK_ROYALTY_SPLITTER_ADDRESS = process . env . RIK_ROYALTY_SPLITTER_ADDRESS ;
4545const RIK_LAUNCHER_ADDRESS = process . env . RIK_LAUNCHER_ADDRESS ;
4646
47+ type ClientsOptions = {
48+ readonly chain ?: Chain ;
49+ readonly rpcUrl ? : string ;
50+ } ;
51+
4752const abi = loadAbi ( ) ;
4853const RIKLauncherAbi = parseAbi ( [
4954 "function launch(uint256 repoId, (uint256 initialSupply, uint256 numTokensToSell, address numeraire, address tokenFactory, bytes tokenFactoryData, address governanceFactory, bytes governanceFactoryData, address poolInitializer, bytes poolInitializerData, address liquidityMigrator, bytes liquidityMigratorData, address integrator, bytes32 salt) p) returns (address asset)" ,
@@ -83,7 +88,10 @@ function addB20Command(program: Command): void {
8388 . argument ( "<amount>" , "fcf amount to wrap" )
8489 . option ( "--wrapper <addr>" , "deployed FCFWrapper address" )
8590 . action ( async ( amount : string , opts : { wrapper ?: string } ) => {
86- const { account, publicClient, walletClient } = clients ( ) ;
91+ const { account, publicClient, walletClient } = clients ( {
92+ chain : base ,
93+ rpcUrl : process . env . B20_RPC_URL ?? process . env . BASE_MAINNET_RPC_URL ?? "https://mainnet.base.org" ,
94+ } ) ;
8795 const wrapperAddress = resolveFcfWrapperAddress ( opts . wrapper ) ;
8896 try {
8997 const result = await wrapB20 ( { amount, wrapperAddress, account, publicClient, walletClient } ) ;
@@ -98,7 +106,10 @@ function addB20Command(program: Command): void {
98106 . argument ( "<amount>" , "wrapped B20 amount to unwrap" )
99107 . option ( "--wrapper <addr>" , "deployed FCFWrapper address" )
100108 . action ( async ( amount : string , opts : { wrapper ?: string } ) => {
101- const { account, publicClient, walletClient } = clients ( ) ;
109+ const { account, publicClient, walletClient } = clients ( {
110+ chain : base ,
111+ rpcUrl : process . env . B20_RPC_URL ?? process . env . BASE_MAINNET_RPC_URL ?? "https://mainnet.base.org" ,
112+ } ) ;
102113 const wrapperAddress = resolveFcfWrapperAddress ( opts . wrapper ) ;
103114 try {
104115 const result = await unwrapB20 ( { amount, wrapperAddress, account, publicClient, walletClient } ) ;
@@ -120,9 +131,9 @@ function addMarketCommand(program: Command): void {
120131 if ( ! RIK_ROYALTY_SPLITTER_ADDRESS ) die ( "Missing RIK_ROYALTY_SPLITTER_ADDRESS" ) ;
121132 if ( ! RIK_LAUNCHER_ADDRESS ) die ( "Missing RIK_ROYALTY_SPLITTER_ADDRESS" ) ;
122133
123- const { account, publicClient, walletClient } = clients ( ) ;
134+ const { account, publicClient, walletClient, chain } = clients ( ) ;
124135 let doppler : DopplerSDK | null = null ;
125- try { doppler = new DopplerSDK ( { publicClient, walletClient, chainId : baseSepolia . id } ) ; } catch ( err ) { die ( err ) ; }
136+ try { doppler = new DopplerSDK ( { publicClient, walletClient, chainId : chain . id } ) ; } catch ( err ) { die ( err ) ; }
126137 if ( ! doppler ) die ( "Failed to initialize doppler sdk" ) ;
127138
128139 // NOTE: share token config is hardcoded right now
@@ -409,19 +420,24 @@ function addGithubVarsCommand(program: Command): void {
409420 } ) ;
410421}
411422
412- function clients ( ) {
423+ function clients ( options : ClientsOptions = { } ) {
413424 const privateKey = ( ( ) => {
414425 let key ;
415426 if ( process . env . PRIVATE_KEY ) key = process . env . PRIVATE_KEY as `0x${ string } ` ;
416427 else try { const wallet = getLocalWallet ( ) ; key = wallet . privateKey ; } catch ( err ) { die ( err ) } ;
417428 return key ;
418429 } ) ( ) ;
419- const rpcUrl = process . env . RPC_URL ?? "https://sepolia.base.org" ;
420- const chain = rpcUrl . includes ( "sepolia" ) ? baseSepolia : foundry ;
430+ const rpcUrl = options . rpcUrl ?? process . env . RPC_URL ?? "https://sepolia.base.org" ;
431+ const chain = options . chain ?? (
432+ rpcUrl . includes ( "mainnet.base.org" ) ? base :
433+ rpcUrl . includes ( "sepolia" ) ? baseSepolia :
434+ foundry
435+ ) ;
421436 const account = privateKeyToAccount ( privateKey ) ;
422437
423438 return {
424439 account ,
440+ chain ,
425441 publicClient : createPublicClient ( { chain, transport : http ( rpcUrl ) } ) ,
426442 walletClient : createWalletClient ( { account, chain, transport : http ( rpcUrl ) } ) ,
427443 } ;
0 commit comments