From 4741e628b8ab00079565a3e075cc7acc2cc08b39 Mon Sep 17 00:00:00 2001 From: Diana Carvalho Date: Wed, 19 Feb 2025 11:00:02 +0000 Subject: [PATCH] chore: Simplify tycho-encode Don't have a cli as a lib. Move that directly inside tycho-encode.rs for simplicity --- don't change below this line --- ENG-4246 Took 29 minutes --- src/bin/lib/cli.rs | 56 ------------------------------------ src/bin/tycho-encode.rs | 64 +++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 64 deletions(-) delete mode 100644 src/bin/lib/cli.rs diff --git a/src/bin/lib/cli.rs b/src/bin/lib/cli.rs deleted file mode 100644 index df08f07..0000000 --- a/src/bin/lib/cli.rs +++ /dev/null @@ -1,56 +0,0 @@ -pub use clap::Parser; -use clap::Subcommand; - -#[derive(Parser)] -/// Encode swap transactions for the Tycho router -/// -/// Reads a JSON object from stdin with the following structure: -/// ```json -/// { -/// "sender": "0x...", -/// "receiver": "0x...", -/// "given_token": "0x...", -/// "given_amount": "123...", -/// "checked_token": "0x...", -/// "exact_out": false, -/// "slippage": 0.01, -/// "expected_amount": "123...", -/// "checked_amount": "123...", -/// "swaps": [{ -/// "component": { -/// "id": "...", -/// "protocol_system": "...", -/// "protocol_type_name": "...", -/// "chain": "ethereum", -/// "tokens": ["0x..."], -/// "contract_ids": ["0x..."], -/// "static_attributes": {"key": "0x..."} -/// }, -/// "token_in": "0x...", -/// "token_out": "0x...", -/// "split": 0.0 -/// }], -/// "router_address": "0x..." -/// } -/// ``` -#[command(author, version, about, long_about = None)] -pub struct Cli { - #[command(subcommand)] - pub command: Commands, -} - -#[derive(Subcommand)] -pub enum Commands { - /// Use the Tycho router encoding strategy - TychoRouter { - #[arg(short, long)] - config_path: Option, - #[arg(short, long)] - swapper_pk: String, - }, - /// Use the direct execution encoding strategy - DirectExecution { - #[arg(short, long)] - config_path: Option, - }, -} diff --git a/src/bin/tycho-encode.rs b/src/bin/tycho-encode.rs index c706d4b..0949b8d 100644 --- a/src/bin/tycho-encode.rs +++ b/src/bin/tycho-encode.rs @@ -1,18 +1,66 @@ use std::io::{self, Read}; -use clap::Parser; +use clap::{Parser, Subcommand}; use serde_json::Value; use tycho_core::dto::Chain; -use tycho_execution::encoding::{models::Solution, tycho_encoder::TychoEncoder}; +use tycho_execution::encoding::{ + errors::EncodingError, evm::encoder_builder::EVMEncoderBuilder, models::Solution, + tycho_encoder::TychoEncoder, +}; -mod lib { - pub mod cli; +#[derive(Parser)] +/// Encode swap transactions for the Tycho router +/// +/// Reads a JSON object from stdin with the following structure: +/// ```json +/// { +/// "sender": "0x...", +/// "receiver": "0x...", +/// "given_token": "0x...", +/// "given_amount": "123...", +/// "checked_token": "0x...", +/// "exact_out": false, +/// "slippage": 0.01, +/// "expected_amount": "123...", +/// "checked_amount": "123...", +/// "swaps": [{ +/// "component": { +/// "id": "...", +/// "protocol_system": "...", +/// "protocol_type_name": "...", +/// "chain": "ethereum", +/// "tokens": ["0x..."], +/// "contract_ids": ["0x..."], +/// "static_attributes": {"key": "0x..."} +/// }, +/// "token_in": "0x...", +/// "token_out": "0x...", +/// "split": 0.0 +/// }], +/// "router_address": "0x..." +/// } +/// ``` +#[command(author, version, about, long_about = None)] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, } -use lib::cli::Cli; -use tycho_execution::encoding::{errors::EncodingError, evm::encoder_builder::EVMEncoderBuilder}; - -use crate::lib::cli::Commands; +#[derive(Subcommand)] +pub enum Commands { + /// Use the Tycho router encoding strategy + TychoRouter { + #[arg(short, long)] + config_path: Option, + #[arg(short, long)] + swapper_pk: String, + }, + /// Use the direct execution encoding strategy + DirectExecution { + #[arg(short, long)] + config_path: Option, + }, +} fn main() -> Result<(), Box> { let cli = Cli::parse();