11use {
2- crate :: command:: BridgeArgs ,
2+ crate :: command:: BurnArgs ,
33 alloy_primitives:: Address ,
44 anyhow:: { Ok , Result } ,
55 clap:: Parser ,
66 nitrogen_circle_message_transmitter_v2_encoder:: {
77 ID as MESSAGE_TRANSMITTER_PROGRAM_ID ,
88 helpers:: { receive_message_helpers, reclaim_event_account_helpers} ,
9- instructions:: reclaim_event_account,
10- types:: ReclaimEventAccountParams ,
119 } ,
1210 nitrogen_circle_token_messenger_minter_v2_encoder:: {
1311 ID as TOKEN_MINTER_PROGRAM_ID ,
2523 BlockHashCacheProvider ,
2624 LookupTableCacheProvider ,
2725 SimpleCacheProvider ,
28- SolanaRpcProvider ,
29- TraceNativeProvider ,
26+ SolanaRpcProviderNative ,
27+ TraceRpcNativeProvider ,
3028 TransactionBuilder ,
3129 } ,
3230 std:: { env, time:: Duration } ,
@@ -50,10 +48,7 @@ async fn fetch_attestation(
5048 attestation:: get_attestation_with_retry ( sig, chain) . await
5149}
5250
53- async fn reclaim < T : SolanaRpcProvider + AsRef < RpcClient > + Send + Sync > (
54- rpc : & T ,
55- owner : Keypair ,
56- ) -> Result < ( ) > {
51+ async fn reclaim < T : SolanaRpcProviderNative > ( rpc : & T , owner : Keypair ) -> Result < ( ) > {
5752 let reclaim_accounts =
5853 reclaim_event_account_helpers:: find_claimable_accounts ( & owner. pubkey ( ) , rpc) . await ?;
5954 info ! ( "reclaim accounts {reclaim_accounts}" ) ;
@@ -74,20 +69,9 @@ async fn reclaim<T: SolanaRpcProvider + AsRef<RpcClient> + Send + Sync>(
7469 tracing:: warn!( "Skipping account with no signature" ) ;
7570 continue ;
7671 }
77- let sig = account. signature . unwrap_or_default ( ) ;
72+ let sig = account. signature . clone ( ) . unwrap ( ) ;
7873 let ( attest, message) = fetch_attestation ( sig, None ) . await ?;
79- let reclaim_account = reclaim_event_account (
80- ReclaimEventAccountParams :: builder ( )
81- . attestation ( attest)
82- . destination_message ( message)
83- . build ( ) ,
84- ) ;
85- let reclaim_tx = TransactionBuilder :: from (
86- reclaim_account
87- . accounts ( owner. pubkey ( ) , account. address )
88- . instruction ( ) ,
89- ) ;
90-
74+ let reclaim_tx: TransactionBuilder = account. instruction ( ( attest, message) ) . into ( ) ;
9175 let reclaim_tx = match ( units, fee) {
9276 ( Some ( units) , Some ( fee) ) => {
9377 reclaim_tx. prepend_compute_budget_instructions ( units, fee) ?
@@ -155,12 +139,14 @@ fn get_keypair() -> Result<Keypair> {
155139}
156140
157141#[ allow( unused_variables) ]
158- async fn evm_sol ( args : BridgeArgs , owner : Keypair , rpc : TraceNativeProvider ) -> Result < ( ) > {
142+ async fn evm_sol < T : SolanaRpcProviderNative > ( args : BurnArgs , owner : Keypair , rpc : T ) -> Result < ( ) > {
159143 info ! ( "TBD sending to sol" ) ;
160144 Ok ( ( ) )
161145}
162146
163- async fn sol_evm ( args : BridgeArgs , owner : Keypair , rpc : TraceNativeProvider ) -> Result < ( ) > {
147+ async fn sol_evm < T : SolanaRpcProviderNative > ( args : BurnArgs , owner : Keypair , rpc : T ) -> Result < ( ) > {
148+ let span = tracing:: info_span!( "sol_evm" , args =? args) ;
149+ let _g = span. enter ( ) ;
164150 info ! ( "burning..." ) ;
165151 let message_sent_event_account = Keypair :: new ( ) ;
166152 let evm_addr: Address = Address :: parse_checksummed ( args. destination , None ) ?;
@@ -211,6 +197,30 @@ async fn sol_evm(args: BridgeArgs, owner: Keypair, rpc: TraceNativeProvider) ->
211197 Ok ( ( ) )
212198}
213199
200+ fn cached_rpc ( rpc : RpcClient ) -> impl SolanaRpcProviderNative {
201+ let rpc: TraceRpcNativeProvider = rpc. into ( ) ;
202+ let hash_cache = BlockHashCacheProvider :: new ( rpc. clone ( ) , Duration :: from_secs ( 30 ) ) ;
203+ let lookup_cache = LookupTableCacheProvider :: builder ( )
204+ . inner ( rpc. clone ( ) )
205+ . lookup_cache (
206+ soly:: Cache :: builder ( )
207+ . time_to_live ( Duration :: from_secs ( 86400 ) )
208+ . build ( ) ,
209+ )
210+ . negative_cache (
211+ soly:: Cache :: builder ( )
212+ . time_to_live ( Duration :: from_secs ( 600 ) )
213+ . build ( ) ,
214+ )
215+ . build ( ) ;
216+
217+ SimpleCacheProvider :: builder ( )
218+ . inner ( rpc. clone ( ) )
219+ . blockhash_cache ( hash_cache. into ( ) )
220+ . lookup_cache ( lookup_cache. into ( ) )
221+ . build ( )
222+ }
223+
214224#[ allow( clippy:: expect_fun_call) ]
215225#[ tokio:: main]
216226pub async fn main ( ) -> Result < ( ) > {
@@ -228,37 +238,19 @@ pub async fn main() -> Result<()> {
228238
229239 let url = env:: var ( "RPC_URL" ) . expect ( "RPC_URL is not set" ) ;
230240 info ! ( "using RPC {url}" ) ;
231- let rpc: TraceNativeProvider =
232- RpcClient :: new_with_commitment ( url, CommitmentConfig :: finalized ( ) ) . into ( ) ;
241+ let rpc = cached_rpc ( RpcClient :: new_with_commitment (
242+ url,
243+ CommitmentConfig :: finalized ( ) ,
244+ ) ) ;
233245 match cli. command {
234- command:: Commands :: Bridge ( args) => {
246+ command:: Commands :: Burn ( args) => {
235247 if !args. to_sol {
236248 sol_evm ( args, owner, rpc) . await
237249 } else {
238250 evm_sol ( args, owner, rpc) . await
239251 }
240252 }
241253 command:: Commands :: Reclaim => {
242- let hash_cache = BlockHashCacheProvider :: new ( rpc. clone ( ) , Duration :: from_secs ( 30 ) ) ;
243- let lookup_cache = LookupTableCacheProvider :: builder ( )
244- . inner ( rpc. clone ( ) )
245- . lookup_cache (
246- soly:: Cache :: builder ( )
247- . time_to_live ( Duration :: from_secs ( 86400 ) )
248- . build ( ) ,
249- )
250- . negative_cache (
251- soly:: Cache :: builder ( )
252- . time_to_live ( Duration :: from_secs ( 600 ) )
253- . build ( ) ,
254- )
255- . build ( ) ;
256-
257- let rpc = SimpleCacheProvider :: builder ( )
258- . inner ( rpc. clone ( ) )
259- . blockhash_cache ( hash_cache. into ( ) )
260- . lookup_cache ( lookup_cache. into ( ) )
261- . build ( ) ;
262254 reclaim ( & rpc, owner) . await ?;
263255 Ok ( ( ) )
264256 }
0 commit comments