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 std::io::{self, Read};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::{Parser, Subcommand};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tycho_core::dto::Chain;
|
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 {
|
#[derive(Parser)]
|
||||||
pub mod cli;
|
/// 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;
|
#[derive(Subcommand)]
|
||||||
use tycho_execution::encoding::{errors::EncodingError, evm::encoder_builder::EVMEncoderBuilder};
|
pub enum Commands {
|
||||||
|
/// Use the Tycho router encoding strategy
|
||||||
use crate::lib::cli::Commands;
|
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>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|||||||
Reference in New Issue
Block a user