Skip to content

Commit 8350779

Browse files
authored
Merge pull request #423 from propeller-heads/ag/5134-compression-support-tycho-client
feat: add support for compression in Tycho RPC client
2 parents 93af391 + 72b4403 commit 8350779

File tree

8 files changed

+66
-23
lines changed

8 files changed

+66
-23
lines changed

Cargo.lock

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ dotenv = "0.15.0"
3737
itertools = "0.10.5"
3838

3939
# Tycho dependencies
40-
tycho-client = ">=0.91.0"
41-
tycho-common = ">=0.91.0"
42-
tycho-ethereum = { version = ">=0.91.0", features = ["onchain_data"] }
40+
tycho-client = ">=0.109.0"
41+
tycho-common = ">=0.109.0"
42+
tycho-ethereum = { version = ">=0.109.0", features = ["onchain_data"] }
4343
tycho-execution = ">=0.129.1"
4444

4545
# EVM dependencies

examples/price_printer/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ async fn main() {
112112
tycho_url.as_str(),
113113
false,
114114
Some(tycho_api_key.as_str()),
115+
true,
115116
chain,
116117
None,
117118
None,

examples/quickstart/main.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,17 @@ async fn main() {
120120
let swapper_pk = env::var("PRIVATE_KEY").ok();
121121

122122
println!("Loading tokens from Tycho... {url}", url = tycho_url.as_str());
123-
let all_tokens =
124-
load_all_tokens(tycho_url.as_str(), false, Some(tycho_api_key.as_str()), chain, None, None)
125-
.await
126-
.expect("Failed to load tokens");
123+
let all_tokens = load_all_tokens(
124+
tycho_url.as_str(),
125+
false,
126+
Some(tycho_api_key.as_str()),
127+
true,
128+
chain,
129+
None,
130+
None,
131+
)
132+
.await
133+
.expect("Failed to load tokens");
127134
println!("Tokens loaded: {num}", num = all_tokens.len());
128135

129136
let sell_token_address = Bytes::from_str(

examples/rfq_quickstart/main.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,17 @@ async fn main() {
118118
}
119119

120120
println!("Loading tokens from Tycho... {url}", url = tycho_url.as_str());
121-
let all_tokens =
122-
load_all_tokens(tycho_url.as_str(), false, Some(tycho_api_key.as_str()), chain, None, None)
123-
.await
124-
.expect("Failed to load tokens");
121+
let all_tokens = load_all_tokens(
122+
tycho_url.as_str(),
123+
false,
124+
Some(tycho_api_key.as_str()),
125+
true,
126+
chain,
127+
None,
128+
None,
129+
)
130+
.await
131+
.expect("Failed to load tokens");
125132
println!("Tokens loaded: {num}", num = all_tokens.len());
126133

127134
let sell_token_address = Bytes::from_str(

src/evm/stream.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
//! "tycho-beta.propellerheads.xyz",
7272
//! false,
7373
//! Some("sampletoken"),
74+
//! true,
7475
//! Chain::Ethereum,
7576
//! None,
7677
//! None,
@@ -288,6 +289,14 @@ impl ProtocolStreamBuilder {
288289
self
289290
}
290291

292+
/// Disable compression for the connection.
293+
pub fn disable_compression(mut self) -> Self {
294+
self.stream_builder = self
295+
.stream_builder
296+
.disable_compression();
297+
self
298+
}
299+
291300
/// Sets the stream end policy.
292301
///
293302
/// Controls when the stream should stop based on synchronizer states.

src/utils.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::collections::HashMap;
22

33
use tracing::info;
4-
use tycho_client::{rpc::RPCClient, HttpRPCClient, RPCError};
4+
use tycho_client::{
5+
rpc::{HttpRPCClientOptions, RPCClient},
6+
HttpRPCClient, RPCError,
7+
};
58
use tycho_common::{
69
models::{token::Token, Chain},
710
simulation::errors::SimulationError,
@@ -59,14 +62,20 @@ pub async fn load_all_tokens(
5962
tycho_url: &str,
6063
no_tls: bool,
6164
auth_key: Option<&str>,
65+
compression: bool,
6266
chain: Chain,
6367
min_quality: Option<i32>,
6468
max_days_since_last_trade: Option<u64>,
6569
) -> Result<HashMap<Bytes, Token>, SimulationError> {
6670
info!("Loading tokens from Tycho...");
6771
let rpc_url =
6872
if no_tls { format!("http://{tycho_url}") } else { format!("https://{tycho_url}") };
69-
let rpc_client = HttpRPCClient::new(rpc_url.as_str(), auth_key)
73+
74+
let rpc_options = HttpRPCClientOptions::new()
75+
.with_auth_key(auth_key.map(|s| s.to_string()))
76+
.with_compression(compression);
77+
78+
let rpc_client = HttpRPCClient::new(rpc_url.as_str(), rpc_options)
7079
.map_err(|err| map_rpc_error(err, "Failed to create Tycho RPC client"))?;
7180

7281
// Chain specific defaults for special case chains. Otherwise defaults to 42 days.

tycho-integration-test/src/main.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,17 @@ async fn run(cli: Cli) -> miette::Result<()> {
163163

164164
// Load tokens from Tycho
165165
info!(%cli.tycho_url, "Loading tokens...");
166-
let all_tokens =
167-
load_all_tokens(&cli.tycho_url, false, Some(cli.tycho_api_key.as_str()), chain, None, None)
168-
.await
169-
.map_err(|e| miette!("Failed to load tokens: {e:?}"))?;
166+
let all_tokens = load_all_tokens(
167+
&cli.tycho_url,
168+
false,
169+
Some(cli.tycho_api_key.as_str()),
170+
true,
171+
chain,
172+
None,
173+
None,
174+
)
175+
.await
176+
.map_err(|e| miette!("Failed to load tokens: {e:?}"))?;
170177
info!(%cli.tycho_url, "Loaded tokens");
171178

172179
// Run streams in background tasks

0 commit comments

Comments
 (0)