@@ -32,7 +32,7 @@ use tycho_execution::encoding::{
3232 errors:: EncodingError ,
3333 evm:: { approvals:: permit2:: PermitSingle , encoder_builders:: TychoRouterEncoderBuilder } ,
3434 models,
35- models:: { EncodedSolution , Solution , Swap , Transaction , UserTransferType } ,
35+ models:: { EncodedSolution , Solution , SwapBuilder , Transaction , UserTransferType } ,
3636} ;
3737use tycho_simulation:: {
3838 evm:: {
@@ -73,15 +73,15 @@ struct Cli {
7373 #[ arg( long, default_value = FAKE_PK ) ]
7474 swapper_pk : String ,
7575 #[ arg( long, default_value = "ethereum" ) ]
76- chain : String ,
76+ chain : Chain ,
7777}
7878
7979impl Cli {
8080 fn with_defaults ( mut self ) -> Self {
8181 // By default, we swap a small amount of USDC to WETH on whatever chain we choose
8282
8383 if self . buy_token . is_none ( ) {
84- self . buy_token = Some ( match self . chain . as_str ( ) {
84+ self . buy_token = Some ( match self . chain . to_string ( ) . as_str ( ) {
8585 "ethereum" => "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" . to_string ( ) ,
8686 "base" => "0x4200000000000000000000000000000000000006" . to_string ( ) ,
8787 "unichain" => "0x4200000000000000000000000000000000000006" . to_string ( ) ,
@@ -90,7 +90,7 @@ impl Cli {
9090 }
9191
9292 if self . sell_token . is_none ( ) {
93- self . sell_token = Some ( match self . chain . as_str ( ) {
93+ self . sell_token = Some ( match self . chain . to_string ( ) . as_str ( ) {
9494 "ethereum" => "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" . to_string ( ) ,
9595 "base" => "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" . to_string ( ) ,
9696 "unichain" => "0x078d782b760474a361dda0af3839290b0ef57ad6" . to_string ( ) ,
@@ -111,8 +111,7 @@ async fn main() {
111111
112112 let cli = Cli :: parse ( ) . with_defaults ( ) ;
113113
114- let chain = Chain :: from_str ( & cli. chain )
115- . unwrap_or_else ( |_| panic ! ( "Unknown chain {chain}" , chain = cli. chain) ) ;
114+ let chain = cli. chain ;
116115
117116 let tycho_url = env:: var ( "TYCHO_URL" ) . unwrap_or_else ( |_| {
118117 get_default_url ( & chain)
@@ -236,10 +235,8 @@ async fn main() {
236235 )
237236 . expect ( "Failed to private key signer" ) ;
238237 let tx_signer = EthereumWallet :: from ( wallet. clone ( ) ) ;
239- let named_chain =
240- NamedChain :: from_str ( & cli. chain . replace ( "ethereum" , "mainnet" ) ) . expect ( "Invalid chain" ) ;
241238 let provider = ProviderBuilder :: default ( )
242- . with_chain ( named_chain )
239+ . with_chain ( NamedChain :: try_from ( chain . id ( ) ) . expect ( "Invalid chain" ) )
243240 . wallet ( tx_signer. clone ( ) )
244241 . connect ( & env:: var ( "RPC_URL" ) . expect ( "RPC_URL env var not set" ) )
245242 . await
@@ -288,7 +285,7 @@ async fn main() {
288285 . clone ( ) ;
289286
290287 let tx = encode_tycho_router_call (
291- named_chain . into ( ) ,
288+ chain . id ( ) ,
292289 encoded_solution. clone ( ) ,
293290 & solution,
294291 chain. native_token ( ) . address ,
@@ -381,7 +378,7 @@ async fn main() {
381378 wallet. address ( ) ,
382379 Address :: from_slice ( & sell_token_address) ,
383380 tx. clone ( ) ,
384- named_chain as u64 ,
381+ chain . id ( ) ,
385382 )
386383 . await ;
387384
@@ -434,7 +431,7 @@ async fn main() {
434431 wallet. address ( ) ,
435432 & sell_token_address,
436433 tx. clone ( ) ,
437- named_chain as u64 ,
434+ chain . id ( ) ,
438435 )
439436 . await
440437 {
@@ -478,7 +475,7 @@ async fn main() {
478475 wallet. address ( ) ,
479476 & sell_token_address,
480477 tx,
481- named_chain as u64 ,
478+ chain . id ( ) ,
482479 )
483480 . await
484481 {
@@ -608,16 +605,8 @@ fn create_solution(
608605 expected_amount : BigUint ,
609606) -> Solution < ' static > {
610607 // Prepare data to encode. First we need to create a swap object
611- let simple_swap = Swap :: new (
612- component,
613- sell_token. address . clone ( ) ,
614- buy_token. address . clone ( ) ,
615- // Split defines the fraction of the amount to be swapped. A value of 0 indicates 100% of
616- // the amount or the total remaining balance.
617- 0f64 ,
618- None ,
619- None ,
620- ) ;
608+ let simple_swap =
609+ SwapBuilder :: new ( component, sell_token. address . clone ( ) , buy_token. address . clone ( ) ) . build ( ) ;
621610
622611 // Compute a minimum amount out
623612 //
0 commit comments