@@ -19,11 +19,13 @@ pub use cartridge::vrf::{
1919use katana_chain_spec:: ChainSpec ;
2020use katana_genesis:: allocation:: GenesisAccountAlloc ;
2121use katana_genesis:: constant:: { DEFAULT_ETH_FEE_TOKEN_ADDRESS , DEFAULT_STRK_FEE_TOKEN_ADDRESS } ;
22+ use katana_node:: config:: paymaster:: PaymasterConfig ;
2223#[ cfg( feature = "vrf" ) ]
2324use katana_node:: config:: paymaster:: VrfConfig ;
25+ use katana_node:: config:: Config ;
2426pub use katana_paymaster:: {
25- format_felt, wait_for_paymaster_ready, PaymasterConfig , PaymasterConfigBuilder ,
26- PaymasterSidecar , PaymasterSidecarProcess ,
27+ format_felt, wait_for_paymaster_ready, PaymasterService , PaymasterServiceConfig ,
28+ PaymasterServiceConfigBuilder , PaymasterSidecarProcess ,
2729} ;
2830use katana_primitives:: chain:: ChainId ;
2931use katana_primitives:: { ContractAddress , Felt } ;
@@ -92,7 +94,6 @@ pub fn build_vrf_config(
9294/// Result of bootstrapping sidecars.
9395#[ derive( Debug , Default ) ]
9496pub struct BootstrapResult {
95- pub paymaster : Option < PaymasterBootstrapInfo > ,
9697 #[ cfg( feature = "vrf" ) ]
9798 pub vrf : Option < VrfBootstrapResult > ,
9899}
@@ -120,7 +121,6 @@ pub struct PaymasterBootstrapInfo {
120121
121122/// Configuration for bootstrapping sidecars.
122123pub struct BootstrapConfig {
123- pub paymaster : Option < PaymasterBootstrapInput > ,
124124 #[ cfg( feature = "vrf" ) ]
125125 pub vrf : Option < VrfBootstrapConfig > ,
126126 #[ allow( dead_code) ]
@@ -139,17 +139,9 @@ pub struct PaymasterBootstrapInput {
139139/// Bootstrap sidecars by deploying necessary contracts and preparing configuration.
140140///
141141/// This must be called after the node is launched but before sidecars are started.
142- pub async fn bootstrap_sidecars (
143- config : & BootstrapConfig ,
144- chain_spec : & ChainSpec ,
145- ) -> Result < BootstrapResult > {
142+ pub async fn bootstrap_sidecars ( config : & BootstrapConfig ) -> Result < BootstrapResult > {
146143 let mut result = BootstrapResult :: default ( ) ;
147144
148- if let Some ( paymaster_input) = & config. paymaster {
149- let bootstrap = bootstrap_paymaster_from_genesis ( paymaster_input, chain_spec) . await ?;
150- result. paymaster = Some ( bootstrap) ;
151- }
152-
153145 #[ cfg( feature = "vrf" ) ]
154146 if let Some ( vrf_cfg) = & config. vrf {
155147 let bootstrap = bootstrap_vrf ( vrf_cfg) . await ?;
@@ -159,48 +151,35 @@ pub async fn bootstrap_sidecars(
159151 Ok ( result)
160152}
161153
162- /// Bootstrap the paymaster using genesis accounts from the backend.
163- ///
164- /// Always uses accounts 0, 1, 2 from genesis for relayer, gas tank, and estimate account.
165- async fn bootstrap_paymaster_from_genesis (
166- input : & PaymasterBootstrapInput ,
167- chain_spec : & ChainSpec ,
168- ) -> Result < PaymasterBootstrapInfo > {
169- // Extract account info from genesis - always use accounts 0, 1, 2
170- let ( relayer_address, relayer_private_key) = prefunded_account ( chain_spec, 0 ) ?;
171- let ( gas_tank_address, gas_tank_private_key) = prefunded_account ( chain_spec, 1 ) ?;
172- let ( estimate_account_address, estimate_account_private_key) =
173- prefunded_account ( chain_spec, 2 ) ?;
174-
175- // Build config without on-chain validation (accounts are from genesis)
176- let config = PaymasterConfigBuilder :: new ( )
177- . rpc_url ( input. rpc_url . clone ( ) )
178- . port ( 0 ) // Port not needed for bootstrap
179- . api_key ( String :: new ( ) )
180- . relayer ( relayer_address, relayer_private_key)
181- . gas_tank ( gas_tank_address, gas_tank_private_key)
182- . estimate_account ( estimate_account_address, estimate_account_private_key)
183- . tokens ( DEFAULT_ETH_FEE_TOKEN_ADDRESS , DEFAULT_STRK_FEE_TOKEN_ADDRESS )
184- . build_unchecked ( ) ?;
185-
186- // Create sidecar and bootstrap (deploys forwarder and gets chain_id)
187- let mut sidecar = PaymasterSidecar :: new ( config) ;
188- let forwarder_address = sidecar. bootstrap ( ) . await ?;
189-
190- // Extract chain_id (set during bootstrap)
191- let chain_id =
192- sidecar. get_chain_id ( ) . ok_or_else ( || anyhow ! ( "chain_id not set after bootstrap" ) ) ?;
193-
194- Ok ( PaymasterBootstrapInfo {
195- relayer_address,
196- relayer_private_key,
197- gas_tank_address,
198- gas_tank_private_key,
199- estimate_account_address,
200- estimate_account_private_key,
201- forwarder_address,
202- chain_id,
203- } )
154+ pub async fn bootstrap_paymaster (
155+ options : & PaymasterOptions ,
156+ paymaster_url : Url ,
157+ rpc_url : Url ,
158+ chain : & ChainSpec ,
159+ ) -> Result < PaymasterService > {
160+ let ( relayer_addr, relayer_pk) = prefunded_account ( chain, 0 ) ?;
161+ let ( gas_tank_addr, gas_tank_pk) = prefunded_account ( chain, 1 ) ?;
162+ let ( estimate_account_addr, estimate_account_pk) = prefunded_account ( chain, 2 ) ?;
163+
164+ let port = paymaster_url. port ( ) . unwrap ( ) ;
165+
166+ let mut builder = PaymasterServiceConfigBuilder :: new ( )
167+ . rpc_url ( rpc_url)
168+ . port ( port)
169+ . api_key ( DEFAULT_PAYMASTER_API_KEY )
170+ . relayer ( relayer_addr, relayer_pk)
171+ . gas_tank ( gas_tank_addr, gas_tank_pk)
172+ . estimate_account ( estimate_account_addr, estimate_account_pk)
173+ . tokens ( DEFAULT_ETH_FEE_TOKEN_ADDRESS , DEFAULT_STRK_FEE_TOKEN_ADDRESS ) ;
174+
175+ if let Some ( bin) = & options. bin {
176+ builder = builder. program_path ( bin. clone ( ) ) ;
177+ }
178+
179+ let mut paymaster = PaymasterService :: new ( builder. build ( ) . await ?) ;
180+ paymaster. bootstrap ( ) . await ?;
181+
182+ Ok ( paymaster)
204183}
205184
206185fn prefunded_account ( chain_spec : & ChainSpec , index : u16 ) -> Result < ( ContractAddress , Felt ) > {
@@ -276,7 +255,6 @@ impl Drop for SidecarProcesses {
276255
277256/// Configuration for starting sidecars.
278257pub struct SidecarStartConfig < ' a > {
279- pub paymaster : Option < PaymasterStartConfig < ' a > > ,
280258 #[ cfg( feature = "vrf" ) ]
281259 pub vrf : Option < VrfStartConfig < ' a > > ,
282260}
@@ -309,7 +287,7 @@ pub async fn start_sidecars(
309287 ( & config. paymaster , bootstrap. paymaster . as_ref ( ) )
310288 {
311289 // Build config using the builder pattern (unchecked since accounts are from genesis)
312- let mut builder = PaymasterConfigBuilder :: new ( )
290+ let mut builder = PaymasterServiceConfigBuilder :: new ( )
313291 . rpc_url ( paymaster_cfg. rpc_url . clone ( ) )
314292 . port ( paymaster_cfg. port )
315293 . api_key ( paymaster_cfg. api_key . clone ( ) )
@@ -335,7 +313,7 @@ pub async fn start_sidecars(
335313 let paymaster_config = builder. build_unchecked ( ) ?;
336314
337315 // Create sidecar with forwarder and chain_id from bootstrap
338- let sidecar = PaymasterSidecar :: new ( paymaster_config)
316+ let sidecar = PaymasterService :: new ( paymaster_config)
339317 . forwarder ( paymaster_bootstrap. forwarder_address )
340318 . chain_id ( paymaster_bootstrap. chain_id ) ;
341319
@@ -412,14 +390,13 @@ pub async fn bootstrap_and_start_sidecars(
412390 } ;
413391
414392 let bootstrap_config = BootstrapConfig {
415- paymaster : paymaster_sidecar. map ( |_| PaymasterBootstrapInput { rpc_url : rpc_url. clone ( ) } ) ,
416393 #[ cfg( feature = "vrf" ) ]
417394 vrf : vrf_bootstrap_config,
418395 fee_enabled,
419396 } ;
420397
421398 // Bootstrap contracts
422- let bootstrap = bootstrap_sidecars ( & bootstrap_config, chain_spec ) . await ?;
399+ let bootstrap = bootstrap_sidecars ( & bootstrap_config) . await ?;
423400
424401 // Build sidecar start config
425402 let paymaster_start_config = paymaster_sidecar. map ( |info| PaymasterStartConfig {
@@ -434,7 +411,6 @@ pub async fn bootstrap_and_start_sidecars(
434411 vrf_sidecar. map ( |info| VrfStartConfig { options : vrf_options, port : info. port } ) ;
435412
436413 let start_config = SidecarStartConfig {
437- paymaster : paymaster_start_config,
438414 #[ cfg( feature = "vrf" ) ]
439415 vrf : vrf_config,
440416 } ;
0 commit comments