11#![ feature( slice_flatten) ]
2-
32use std:: io;
4- use std:: sync:: Arc ;
53
64use aligned_sdk:: core:: types:: {
75 AlignedVerificationData , Network , PriceEstimate , ProvingSystemId , VerificationData ,
86} ;
9- use aligned_sdk:: sdk:: { estimate_fee , get_payment_service_address } ;
7+ use aligned_sdk:: sdk:: { deposit_to_aligned , estimate_fee } ;
108use aligned_sdk:: sdk:: { get_next_nonce, submit_and_wait_verification} ;
119use clap:: Parser ;
1210use dialoguer:: Confirm ;
@@ -18,11 +16,8 @@ use sp1_sdk::{ProverClient, SP1Stdin};
1816
1917abigen ! ( VerifierContract , "VerifierContract.json" , ) ;
2018
21- const BATCHER_URL : & str = "wss://batcher.alignedlayer.com" ;
2219const ELF : & [ u8 ] = include_bytes ! ( "../../program/elf/riscv32im-succinct-zkvm-elf" ) ;
2320
24- const NETWORK : Network = Network :: Holesky ;
25-
2621#[ derive( Parser , Debug ) ]
2722#[ command( version, about, long_about = None ) ]
2823struct Args {
@@ -34,6 +29,10 @@ struct Args {
3429 default_value = "https://ethereum-holesky-rpc.publicnode.com"
3530 ) ]
3631 rpc_url : String ,
32+ #[ arg( short, long, default_value = "wss://batcher.alignedlayer.com" ) ]
33+ batcher_url : String ,
34+ #[ arg( short, long, default_value = "holesky" ) ]
35+ network : Network ,
3736 #[ arg( short, long) ]
3837 verifier_contract_address : H160 ,
3938}
@@ -48,20 +47,27 @@ async fn main() {
4847 let keystore_password = rpassword:: prompt_password ( "Enter keystore password: " )
4948 . expect ( "Failed to read keystore password" ) ;
5049
51- let wallet = LocalWallet :: decrypt_keystore ( args. keystore_path , & keystore_password)
52- . expect ( "Failed to decrypt keystore" )
53- . with_chain_id ( 17000u64 ) ;
54-
5550 let provider =
5651 Provider :: < Http > :: try_from ( rpc_url. as_str ( ) ) . expect ( "Failed to connect to provider" ) ;
5752
58- let signer = Arc :: new ( SignerMiddleware :: new ( provider. clone ( ) , wallet. clone ( ) ) ) ;
53+ let chain_id = provider
54+ . get_chainid ( )
55+ . await
56+ . expect ( "Failed to get chain_id" ) ;
57+
58+ let wallet = LocalWallet :: decrypt_keystore ( args. keystore_path , & keystore_password)
59+ . expect ( "Failed to decrypt keystore" )
60+ . with_chain_id ( chain_id. as_u64 ( ) ) ;
61+
62+ let signer = SignerMiddleware :: new ( provider. clone ( ) , wallet. clone ( ) ) ;
5963
6064 if Confirm :: with_theme ( & dialoguer:: theme:: ColorfulTheme :: default ( ) )
6165 . with_prompt ( "Do you want to deposit 0.004eth in Aligned ?\n If you already deposited Ethereum to Aligned before, this is not needed" )
6266 . interact ( )
6367 . expect ( "Failed to read user input" ) {
64- deposit_to_batcher ( wallet. address ( ) , signer. clone ( ) ) . await . expect ( "Failed to pay for proof submission" ) ;
68+
69+ deposit_to_aligned ( U256 :: from ( 4000000000000000u128 ) , signer. clone ( ) , args. network ) . await
70+ . expect ( "Failed to pay for proof submission" ) ;
6571 }
6672
6773 // Generate proof.
@@ -114,7 +120,7 @@ async fn main() {
114120 pub_input : None ,
115121 } ;
116122
117- let max_fee = estimate_fee ( & rpc_url, PriceEstimate :: Default )
123+ let max_fee = estimate_fee ( & rpc_url, PriceEstimate :: Instant )
118124 . await
119125 . expect ( "failed to fetch gas price from the blockchain" ) ;
120126
@@ -126,14 +132,16 @@ async fn main() {
126132 . expect ( "Failed to read user input" )
127133 { return ; }
128134
129- let nonce = get_next_nonce ( & rpc_url, wallet. address ( ) , NETWORK )
135+ let nonce = get_next_nonce ( & rpc_url, wallet. address ( ) , args . network )
130136 . await
131137 . expect ( "Failed to get next nonce" ) ;
132138
139+ println ! ( "Submitting your proof..." ) ;
140+
133141 let aligned_verification_data = submit_and_wait_verification (
134- BATCHER_URL ,
142+ & args . batcher_url ,
135143 & rpc_url,
136- NETWORK ,
144+ args . network ,
137145 & verification_data,
138146 max_fee,
139147 wallet. clone ( ) ,
@@ -143,9 +151,10 @@ async fn main() {
143151 . unwrap ( ) ;
144152
145153 println ! (
146- "Proof submitted and verified successfully on batch {}, claiming prize... " ,
154+ "Proof submitted and verified successfully on batch {}" ,
147155 hex:: encode( aligned_verification_data. batch_merkle_root)
148156 ) ;
157+ println ! ( "Claiming NFT prize..." ) ;
149158
150159 claim_nft_with_verified_proof (
151160 & aligned_verification_data,
@@ -193,43 +202,12 @@ fn read_answer() -> char {
193202 }
194203}
195204
196- async fn deposit_to_batcher (
197- from : Address ,
198- signer : Arc < SignerMiddleware < Provider < Http > , LocalWallet > > ,
199- ) -> anyhow:: Result < ( ) > {
200- let addr = get_payment_service_address ( NETWORK ) ;
201-
202- let tx = TransactionRequest :: new ( )
203- . from ( from)
204- . to ( addr)
205- . value ( 4000000000000000u128 ) ;
206-
207- match signer
208- . send_transaction ( tx, None )
209- . await
210- . map_err ( |e| anyhow:: anyhow!( "Failed to send tx {}" , e) ) ?
211- . await
212- . map_err ( |e| anyhow:: anyhow!( "Failed to submit tx {}" , e) ) ?
213- {
214- Some ( receipt) => {
215- println ! (
216- "Payment sent. Transaction hash: {:x}" ,
217- receipt. transaction_hash
218- ) ;
219- Ok ( ( ) )
220- }
221- None => {
222- anyhow:: bail!( "Payment failed" ) ;
223- }
224- }
225- }
226-
227205async fn claim_nft_with_verified_proof (
228206 aligned_verification_data : & AlignedVerificationData ,
229- signer : Arc < SignerMiddleware < Provider < Http > , LocalWallet > > ,
207+ signer : SignerMiddleware < Provider < Http > , LocalWallet > ,
230208 verifier_contract_addr : & Address ,
231209) -> anyhow:: Result < ( ) > {
232- let verifier_contract = VerifierContract :: new ( * verifier_contract_addr, signer) ;
210+ let verifier_contract = VerifierContract :: new ( * verifier_contract_addr, signer. into ( ) ) ;
233211
234212 let index_in_batch = U256 :: from ( aligned_verification_data. index_in_batch ) ;
235213 let merkle_path = Bytes :: from (
0 commit comments