feat: update cli params and docs

This commit is contained in:
royvardhan
2025-02-06 20:55:27 +05:30
parent 535384393b
commit 32c3bd2220
4 changed files with 37 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
pub use clap::Parser;
pub const DEFAULT_ROUTER_ADDRESS: &str = "0xaa820C29648D5EA543d712cC928377Bd7206a0E7";
pub const DEFAULT_CONFIG_PATH: &str = "src/encoding/config/executor_addresses.json";
#[derive(Parser)]
/// Encode swap transactions for the Tycho router
@@ -40,6 +41,10 @@ pub struct Cli {
pub router_address: String,
/// Private key for signing approvals (required when direct_execution is false)
#[arg(short, long)]
#[arg(short)]
pub private_key: Option<String>,
/// Path to the executor addresses configuration file
#[arg(short, default_value = DEFAULT_CONFIG_PATH)]
pub config_path: String,
}

View File

@@ -19,8 +19,6 @@ mod lib {
use lib::cli::Cli;
const DEFAULT_EXECUTORS_FILE_PATH: &str = "src/encoding/config/executor_addresses.json";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();
@@ -35,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
// Encode the solution
let encoded = encode_swaps(&buffer, &cli.router_address, cli.private_key)?;
let encoded = encode_swaps(&buffer, &cli.router_address, &cli.config_path, cli.private_key)?;
// Output the encoded result as JSON to stdout
println!(
@@ -50,12 +48,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
fn encode_swaps(
input: &str,
router_address: &str,
config_path: &str,
private_key: Option<String>,
) -> Result<Value, Box<dyn std::error::Error>> {
let solution: Solution = serde_json::from_str(input)?;
let strategy_selector =
EVMStrategyEncoderRegistry::new(Chain::Ethereum, DEFAULT_EXECUTORS_FILE_PATH, private_key)?;
EVMStrategyEncoderRegistry::new(Chain::Ethereum, config_path, private_key)?;
let encoder = EVMTychoEncoder::new(strategy_selector, router_address.to_string())?;
let transactions = encoder.encode_router_calldata(vec![solution])?;