Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ hex = "0.4.3"
chrono = { version = "0.4.26", features = ["serde"] }

# Error handling
miette = "7.6.0"
thiserror = "1"

# Async & concurrency
Expand Down Expand Up @@ -80,8 +81,8 @@ approx = "0.5.1"
rstest = "0.23.0"
rstest_reuse = "0.7.0"
tracing-subscriber = { version = "0.3.17", default-features = false, features = [
"env-filter",
"fmt",
"env-filter",
"fmt",
] }
tempfile = "3.13.0"

Expand All @@ -103,7 +104,7 @@ tycho-execution = "0.118.0"
default = ["evm", "rfq"]
network_tests = []
evm = [
"dep:foundry-config", "dep:foundry-evm", "dep:revm", "dep:revm-inspectors", "dep:alloy",
"dep:foundry-config", "dep:foundry-evm", "dep:revm", "dep:revm-inspectors", "dep:alloy",
]
rfq = ["dep:reqwest", "dep:async-trait", "dep:tokio-tungstenite", "dep:async-stream", "dep:http", "dep:prost"]

Expand Down
62 changes: 62 additions & 0 deletions examples/rfq_quickstart/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use clap::{Args, Parser};
use miette::{miette, Result};
use tycho_common::models::Chain;

#[derive(Clone, Debug, Parser)]
pub struct RfqCommand {
#[command(flatten)]
pub swap_args: SwapArgs,
}

#[derive(Clone, Debug, Args, Default)]
pub struct SwapArgs {
#[arg(long)]
pub sell_token: Option<String>,
#[arg(long)]
pub buy_token: Option<String>,
#[arg(long, default_value_t = 10.0)]
pub sell_amount: f64,
/// The minimum TVL threshold for RFQ quotes in USD
#[arg(long, default_value_t = 1000.0)]
pub tvl_threshold: f64,
#[arg(long, default_value = "ethereum")]
pub chain: Chain,
}

impl SwapArgs {
fn parse_args(mut self) -> Result<Self> {
// By default, we request quotes for USDC to WETH on whatever chain we choose
if self.buy_token.is_none() {
self.buy_token = Some(match self.chain {
Chain::Ethereum => "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".to_string(),
Chain::Base => "0x4200000000000000000000000000000000000006".to_string(),
_ => {
return Err(miette!(
"RFQ quickstart does not yet support chain {chain}",
chain = self.chain
))
}
});
}
if self.sell_token.is_none() {
self.sell_token = Some(match self.chain {
Chain::Ethereum => "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".to_string(),
Chain::Base => "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913".to_string(),
_ => {
return Err(miette!(
"RFQ quickstart does not yet support chain {chain}",
chain = self.chain
))
}
});
}
Ok(self)
}
}

impl RfqCommand {
pub async fn parse_args(mut self) -> Result<Self> {
self.swap_args = self.swap_args.parse_args()?;
Ok(self)
}
}
26 changes: 26 additions & 0 deletions examples/rfq_quickstart/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::{env, env::VarError};

use miette::{miette, Result};

fn _get_env(var_name: &str) -> Result<Option<String>> {
match env::var(var_name) {
Ok(val) => {
Ok(Some(val))
},
Err(e) => match e {
VarError::NotPresent => Ok(None),
VarError::NotUnicode(_) => Err(miette!("The environment variable `{var_name}` cannot be decoded because it is not some valid Unicode")),
},
}
}

pub fn get_env(var_name: &str) -> Option<String> {
_get_env(var_name).ok().flatten()
}

pub fn get_env_with_default(var_name: &str, default_value: String) -> String {
_get_env(var_name)
.ok()
.flatten()
.unwrap_or(default_value)
}
Loading
Loading