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
This commit is contained in:
@@ -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<String>,
|
||||
#[arg(short, long)]
|
||||
swapper_pk: String,
|
||||
},
|
||||
/// Use the direct execution encoding strategy
|
||||
DirectExecution {
|
||||
#[arg(short, long)]
|
||||
config_path: Option<String>,
|
||||
},
|
||||
}
|
||||
@@ -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<String>,
|
||||
#[arg(short, long)]
|
||||
swapper_pk: String,
|
||||
},
|
||||
/// Use the direct execution encoding strategy
|
||||
DirectExecution {
|
||||
#[arg(short, long)]
|
||||
config_path: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
Reference in New Issue
Block a user