1- mod execution;
21mod metrics;
3- mod stream_processor;
42
53use std:: {
64 collections:: { HashMap , HashSet } ,
@@ -9,14 +7,7 @@ use std::{
97 time:: Duration ,
108} ;
119
12- use alloy:: {
13- eips:: BlockNumberOrTag ,
14- network:: Ethereum ,
15- primitives:: Address ,
16- providers:: { Provider , ProviderBuilder , RootProvider } ,
17- rpc:: types:: Block ,
18- } ;
19- use alloy_chains:: NamedChain ;
10+ use alloy:: { eips:: BlockNumberOrTag , primitives:: Address , providers:: Provider , rpc:: types:: Block } ;
2011use clap:: Parser ;
2112use dotenv:: dotenv;
2213use itertools:: Itertools ;
@@ -28,18 +19,13 @@ use tokio::sync::Semaphore;
2819use tracing:: { error, info, warn} ;
2920use tracing_subscriber:: EnvFilter ;
3021use tycho_common:: simulation:: protocol_sim:: ProtocolSim ;
31- use tycho_ethereum:: entrypoint_tracer:: {
32- allowance_slot_detector:: { AllowanceSlotDetectorConfig , EVMAllowanceSlotDetector } ,
33- balance_slot_detector:: { BalanceSlotDetectorConfig , EVMBalanceSlotDetector } ,
34- } ;
3522use tycho_simulation:: {
3623 protocol:: models:: ProtocolComponent ,
3724 rfq:: protocols:: hashflow:: { client:: HashflowClient , state:: HashflowState } ,
3825 tycho_common:: models:: Chain ,
3926 utils:: load_all_tokens,
4027} ;
41-
42- use crate :: {
28+ use tycho_test:: {
4329 execution:: {
4430 encoding:: encode_swap,
4531 models:: { TychoExecutionInput , TychoExecutionResult } ,
@@ -173,7 +159,7 @@ async fn run(cli: Cli) -> miette::Result<()> {
173159 let cli = Arc :: new ( cli) ;
174160 let chain = cli. chain ;
175161
176- let rpc_tools = RPCTools :: new ( & cli. rpc_url , & chain) . await ?;
162+ let rpc_tools = tycho_test :: RPCTools :: new ( & cli. rpc_url , & chain) . await ?;
177163
178164 // Load tokens from Tycho
179165 info ! ( %cli. tycho_url, "Loading tokens..." ) ;
@@ -247,7 +233,7 @@ async fn run(cli: Cli) -> miette::Result<()> {
247233async fn process_update (
248234 cli : Arc < Cli > ,
249235 chain : Chain ,
250- rpc_tools : RPCTools ,
236+ rpc_tools : tycho_test :: RPCTools ,
251237 tycho_state : Arc < RwLock < TychoState > > ,
252238 update : & StreamUpdate ,
253239) -> miette:: Result < ( ) > {
@@ -490,6 +476,7 @@ async fn process_update(
490476 block_execution_info. clone ( ) ,
491477 & block,
492478 cli. block_wait_time ,
479+ None ,
493480 )
494481 . await
495482 {
@@ -510,7 +497,7 @@ async fn process_update(
510497 }
511498 . clone ( ) ;
512499
513- let state = {
500+ let state_str = {
514501 let current_state = tycho_state
515502 . read ( )
516503 . map_err ( |e| miette ! ( "Failed to acquire read lock on Tycho state: {e}" ) ) ?;
@@ -519,18 +506,15 @@ async fn process_update(
519506 . states
520507 . get ( & execution_info. component_id )
521508 {
522- Some ( state) => state. clone ( ) ,
523- None => {
524- error ! ( id=%execution_info. component_id, "State not found in saved protocol states" ) ;
525- continue ;
526- }
509+ Some ( state) => format ! ( "{:?}" , state) ,
510+ None => "" . to_string ( ) ,
527511 }
528512 } ;
529513 ( n_reverts, n_failures) = process_execution_result (
530514 simulation_id,
531515 result,
532516 execution_info,
533- state ,
517+ state_str ,
534518 ( * block) . clone ( ) ,
535519 chain. id ( ) . to_string ( ) ,
536520 n_reverts,
@@ -691,11 +675,13 @@ async fn process_state(
691675 // Simulate execution amount out against the RPC
692676 let ( solution, transaction) = match encode_swap (
693677 & component,
694- Arc :: from ( state. clone_box ( ) ) ,
678+ Some ( Arc :: from ( state. clone_box ( ) ) ) ,
695679 token_in,
696680 token_out,
697681 amount_in. clone ( ) ,
698682 chain,
683+ None ,
684+ false ,
699685 ) {
700686 Ok ( res) => res,
701687 Err ( e) => {
@@ -740,7 +726,8 @@ fn process_execution_result(
740726 simulation_id : & String ,
741727 result : & TychoExecutionResult ,
742728 execution_info : TychoExecutionInput ,
743- state : Box < dyn ProtocolSim > ,
729+ state_str : String ,
730+
744731 block : Block ,
745732 chain_id : String ,
746733 mut n_reverts : i32 ,
@@ -775,7 +762,7 @@ fn process_execution_result(
775762
776763 info ! (
777764 event_type = "execution_slippage" ,
778- state = ?state ,
765+ state = ?state_str ,
779766 token_in = %execution_info. token_in,
780767 token_out = %execution_info. token_out,
781768 simulated_amount = %amount_out,
@@ -823,7 +810,7 @@ fn process_execution_result(
823810 error_message = %revert_reason,
824811 error_name = %error_name,
825812 error_category = %error_category,
826- state = ?state ,
813+ state = ?state_str ,
827814 token_in = %execution_info. token_in,
828815 token_out = %execution_info. token_out,
829816 tenderly_url = %tenderly_url,
@@ -889,49 +876,6 @@ fn categorize_error(error_name: &str) -> &'static str {
889876 }
890877}
891878
892- #[ derive( Clone ) ]
893- struct RPCTools {
894- rpc_url : String ,
895- provider : RootProvider < Ethereum > ,
896- evm_balance_slot_detector : Arc < EVMBalanceSlotDetector > ,
897- evm_allowance_slot_detector : Arc < EVMAllowanceSlotDetector > ,
898- }
899-
900- impl RPCTools {
901- pub async fn new ( rpc_url : & str , chain : & Chain ) -> miette:: Result < Self > {
902- let provider: RootProvider < Ethereum > = ProviderBuilder :: default ( )
903- . with_chain (
904- NamedChain :: try_from ( chain. id ( ) )
905- . into_diagnostic ( )
906- . wrap_err ( "Invalid chain" ) ?,
907- )
908- . connect ( rpc_url)
909- . await
910- . into_diagnostic ( )
911- . wrap_err ( "Failed to connect to provider" ) ?;
912- let evm_balance_slot_detector = Arc :: new (
913- EVMBalanceSlotDetector :: new ( BalanceSlotDetectorConfig {
914- rpc_url : rpc_url. to_string ( ) ,
915- ..Default :: default ( )
916- } )
917- . into_diagnostic ( ) ?,
918- ) ;
919- let evm_allowance_slot_detector = Arc :: new (
920- EVMAllowanceSlotDetector :: new ( AllowanceSlotDetectorConfig {
921- rpc_url : rpc_url. to_string ( ) ,
922- ..Default :: default ( )
923- } )
924- . into_diagnostic ( ) ?,
925- ) ;
926- Ok ( Self {
927- rpc_url : rpc_url. to_string ( ) ,
928- provider,
929- evm_balance_slot_detector,
930- evm_allowance_slot_detector,
931- } )
932- }
933- }
934-
935879/// Generate a unique simulation ID based on protocol system and state ID
936880fn generate_simulation_id ( protocol_system : & str , state_id : & str ) -> String {
937881 let random_number: u32 = rand:: random :: < u32 > ( ) % 90000 + 10000 ; // Range 10000-99999
0 commit comments