diff --git a/CHANGELOG.md b/CHANGELOG.md index 5baffb66..fd8b7a39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,36 @@ +## [0.74.3](https://github.com/propeller-heads/tycho-simulation/compare/0.74.2...0.74.3) (2025-02-13) + + +### Bug Fixes + +* dummy commit to trigger release of tycho dependency update ([7514713](https://github.com/propeller-heads/tycho-simulation/commit/7514713a1159826ba49c3ff52761e5a244ad4e8f)) + +## [0.74.2](https://github.com/propeller-heads/tycho-simulation/compare/0.74.1...0.74.2) (2025-02-10) + + +### Bug Fixes + +* Create a ProtocolComponent::new() that doesn't depend on tycho-core ([8f44f08](https://github.com/propeller-heads/tycho-simulation/commit/8f44f08025fe574ce80c10fea87d9ddbd909add6)) + +## [0.74.1](https://github.com/propeller-heads/tycho-simulation/compare/0.74.0...0.74.1) (2025-02-10) + + +### Bug Fixes + +* make TickList public ([82a6062](https://github.com/propeller-heads/tycho-simulation/commit/82a60628feecb88f0fe26996eba7f8d7363c1028)) + +## [0.74.0](https://github.com/propeller-heads/tycho-simulation/compare/0.73.0...0.74.0) (2025-02-10) + + +### Features + +* add filter args to load_all_tokens ([b1a76a8](https://github.com/propeller-heads/tycho-simulation/commit/b1a76a862714a6e33c1cb0a51b38796cab9c150c)) + + +### Bug Fixes + +* improve load_all_tokens arg names ([cfc4f51](https://github.com/propeller-heads/tycho-simulation/commit/cfc4f5193d595b6ec079886f949d8d1ef8a14df6)) + ## [0.73.0](https://github.com/propeller-heads/tycho-simulation/compare/0.72.0...0.73.0) (2025-02-06) diff --git a/Cargo.lock b/Cargo.lock index 29781b41..3ece0939 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ dependencies = [ [[package]] name = "_tycho_simulation_py" -version = "0.73.0" +version = "0.74.3" dependencies = [ "alloy", "num-bigint", @@ -7071,8 +7071,8 @@ dependencies = [ [[package]] name = "tycho-client" -version = "0.55.2" -source = "git+https://github.com/propeller-heads/tycho-indexer.git?tag=0.55.2#dfa50d5e318253001938655a49aa3e05f958d89e" +version = "0.56.5" +source = "git+https://github.com/propeller-heads/tycho-indexer.git?tag=0.56.5#2af8c1a5a61c5479eab5f7903b69943efa61e2c8" dependencies = [ "anyhow", "async-trait", @@ -7097,8 +7097,8 @@ dependencies = [ [[package]] name = "tycho-core" -version = "0.55.2" -source = "git+https://github.com/propeller-heads/tycho-indexer.git?tag=0.55.2#dfa50d5e318253001938655a49aa3e05f958d89e" +version = "0.56.5" +source = "git+https://github.com/propeller-heads/tycho-indexer.git?tag=0.56.5#2af8c1a5a61c5479eab5f7903b69943efa61e2c8" dependencies = [ "anyhow", "async-trait", @@ -7120,7 +7120,7 @@ dependencies = [ [[package]] name = "tycho-simulation" -version = "0.73.0" +version = "0.74.3" dependencies = [ "alloy", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index 890a4611..6073acb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tycho-simulation" -version = "0.73.0" +version = "0.74.3" edition = "2021" [workspace] @@ -38,8 +38,8 @@ mini-moka = "0.10" lazy_static = "1.4.0" # Tycho dependencies -tycho-core = { git = "https://github.com/propeller-heads/tycho-indexer.git", package = "tycho-core", tag = "0.55.2" } -tycho-client = { git = "https://github.com/propeller-heads/tycho-indexer.git", package = "tycho-client", tag = "0.55.2" } +tycho-core = { git = "https://github.com/propeller-heads/tycho-indexer.git", package = "tycho-core", tag = "0.56.5" } +tycho-client = { git = "https://github.com/propeller-heads/tycho-indexer.git", package = "tycho-client", tag = "0.56.5" } # EVM dependencies foundry-config = { git = "https://github.com/foundry-rs/foundry", rev = "57bb12e", optional = true } diff --git a/examples/price_printer/main.rs b/examples/price_printer/main.rs index 6d75f649..eff2ba02 100644 --- a/examples/price_printer/main.rs +++ b/examples/price_printer/main.rs @@ -58,6 +58,8 @@ async fn main() { false, Some(tycho_api_key.as_str()), Chain::Ethereum, + None, + None, ) .await; let tvl_filter = ComponentFilter::with_tvl_range(cli.tvl_threshold, cli.tvl_threshold); diff --git a/examples/quickstart/main.rs b/examples/quickstart/main.rs index d63bb598..e0e40a9f 100644 --- a/examples/quickstart/main.rs +++ b/examples/quickstart/main.rs @@ -36,9 +36,15 @@ async fn main() { let tvl_threshold = 10_000.0; let tvl_filter = ComponentFilter::with_tvl_range(tvl_threshold, tvl_threshold); - let all_tokens = - load_all_tokens(tycho_url.as_str(), false, Some(tycho_api_key.as_str()), Chain::Ethereum) - .await; + let all_tokens = load_all_tokens( + tycho_url.as_str(), + false, + Some(tycho_api_key.as_str()), + Chain::Ethereum, + None, + None, + ) + .await; let mut pairs: HashMap> = HashMap::new(); let mut protocol_stream = ProtocolStreamBuilder::new(&tycho_url, Chain::Ethereum) diff --git a/src/evm/account_storage.rs b/src/evm/account_storage.rs index dfa12a5d..f61a871d 100644 --- a/src/evm/account_storage.rs +++ b/src/evm/account_storage.rs @@ -229,9 +229,9 @@ impl AccountStorage { #[cfg(test)] mod tests { - use std::{collections::HashMap, error::Error, str::FromStr}; + use std::{error::Error, str::FromStr}; - use revm::primitives::{AccountInfo, Address, KECCAK_EMPTY, U256}; + use revm::primitives::{AccountInfo, KECCAK_EMPTY}; use super::*; use crate::evm::account_storage::{Account, AccountStorage}; diff --git a/src/evm/decoder.rs b/src/evm/decoder.rs index 3d7c3aaa..d2d427ad 100644 --- a/src/evm/decoder.rs +++ b/src/evm/decoder.rs @@ -215,7 +215,10 @@ impl TychoStreamDecoder { .collect::>(); if tokens.len() == comp.tokens.len() { - Some((id.clone(), ProtocolComponent::new(tokens, comp.clone()))) + Some(( + id.clone(), + ProtocolComponent::from_with_tokens(comp.clone(), tokens), + )) } else { // We may reach this point if the removed component // contained low quality tokens, in this case the component @@ -274,7 +277,10 @@ impl TychoStreamDecoder { } new_pairs.insert( id.clone(), - ProtocolComponent::new(component_tokens, snapshot.component.clone()), + ProtocolComponent::from_with_tokens( + snapshot.component.clone(), + component_tokens, + ), ); // Construct state from snapshot diff --git a/src/evm/protocol/mod.rs b/src/evm/protocol/mod.rs index 4f809ee1..532972cb 100644 --- a/src/evm/protocol/mod.rs +++ b/src/evm/protocol/mod.rs @@ -4,5 +4,5 @@ pub mod u256_num; pub mod uniswap_v2; pub mod uniswap_v3; pub mod uniswap_v4; -pub(crate) mod utils; +pub mod utils; pub mod vm; diff --git a/src/evm/protocol/utils/mod.rs b/src/evm/protocol/utils/mod.rs index e4ad2ebd..50dc7827 100644 --- a/src/evm/protocol/utils/mod.rs +++ b/src/evm/protocol/utils/mod.rs @@ -1,4 +1,4 @@ -pub(crate) mod uniswap; +pub mod uniswap; use alloy_primitives::Address; use tycho_core::Bytes; diff --git a/src/evm/protocol/utils/uniswap/mod.rs b/src/evm/protocol/utils/uniswap/mod.rs index b6634d48..f6072133 100644 --- a/src/evm/protocol/utils/uniswap/mod.rs +++ b/src/evm/protocol/utils/uniswap/mod.rs @@ -5,7 +5,7 @@ pub(crate) mod liquidity_math; mod solidity_math; pub(crate) mod sqrt_price_math; pub(crate) mod swap_math; -pub(crate) mod tick_list; +pub mod tick_list; pub(crate) mod tick_math; #[derive(Debug)] diff --git a/src/protocol/models.rs b/src/protocol/models.rs index d5f32c9c..cc13e1b2 100644 --- a/src/protocol/models.rs +++ b/src/protocol/models.rs @@ -57,22 +57,50 @@ pub struct ProtocolComponent { impl ProtocolComponent { #[allow(deprecated)] - pub fn new(mut tokens: Vec, core_model: tycho_core::dto::ProtocolComponent) -> Self { - tokens.sort_unstable_by_key(|t| t.address.clone()); - let id = Bytes::from(core_model.id.as_str()); + #[allow(clippy::too_many_arguments)] + pub fn new( + id: Bytes, + protocol_system: String, + protocol_type_name: String, + chain: Chain, + tokens: Vec, + contract_ids: Vec, + static_attributes: HashMap, + creation_tx: Bytes, + created_at: NaiveDateTime, + ) -> Self { ProtocolComponent { - id: id.clone(), - address: id, + address: Default::default(), + id, tokens, - protocol_system: core_model.protocol_system, - protocol_type_name: core_model.protocol_type_name, - chain: core_model.chain, - contract_ids: core_model.contract_ids, - static_attributes: core_model.static_attributes, - creation_tx: core_model.creation_tx, - created_at: core_model.created_at, + protocol_system, + protocol_type_name, + chain, + contract_ids, + static_attributes, + creation_tx, + created_at, } } + + pub fn from_with_tokens( + core_model: tycho_core::dto::ProtocolComponent, + mut tokens: Vec, + ) -> Self { + tokens.sort_unstable_by_key(|t| t.address.clone()); + let id = Bytes::from(core_model.id.as_str()); + ProtocolComponent::new( + id.clone(), + core_model.protocol_system, + core_model.protocol_type_name, + core_model.chain, + tokens, + core_model.contract_ids, + core_model.static_attributes, + core_model.creation_tx, + core_model.created_at, + ) + } } impl From for tycho_core::dto::ProtocolComponent { diff --git a/src/utils.rs b/src/utils.rs index 1e8782fb..9786dab7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use tracing::info; use tycho_client::{rpc::RPCClient, HttpRPCClient}; use tycho_core::{dto::Chain, Bytes}; @@ -36,19 +37,43 @@ pub fn hexstring_to_vec(hexstring: &str) -> Result, SimulationError> { } /// Loads all tokens from Tycho and returns them as a Hashmap of address->Token. +/// +/// # Arguments +/// +/// * `tycho_url` - The URL of the Tycho RPC (do not include the url prefix e.g. 'https://'). +/// * `no_tls` - Whether to use HTTP instead of HTTPS. +/// * `auth_key` - The API key to use for authentication. +/// * `chain` - The chain to load tokens from. +/// * `min_quality` - The minimum quality of tokens to load. Defaults to 100 if not provided. +/// * `max_days_since_last_trade` - The max number of days since the token was last traded. Defaults +/// are chain specific and applied if not provided. pub async fn load_all_tokens( tycho_url: &str, no_tls: bool, auth_key: Option<&str>, chain: Chain, + min_quality: Option, + max_days_since_last_trade: Option, ) -> HashMap { + info!("Loading tokens from Tycho..."); let rpc_url = if no_tls { format!("http://{tycho_url}") } else { format!("https://{tycho_url}") }; let rpc_client = HttpRPCClient::new(rpc_url.as_str(), auth_key).unwrap(); + // Chain specific defaults for special case chains. Otherwise defaults to 42 days. + let default_min_days = HashMap::from([(Chain::Base, 10_u64)]); + #[allow(clippy::mutable_key_type)] rpc_client - .get_all_tokens(chain, Some(100), Some(42), 3_000) + .get_all_tokens( + chain, + min_quality.or(Some(100)), + max_days_since_last_trade.or(default_min_days + .get(&chain) + .or(Some(&42)) + .copied()), + 3_000, + ) .await .expect("Unable to load tokens") .into_iter() diff --git a/tycho_simulation_py/Cargo.toml b/tycho_simulation_py/Cargo.toml index 2de8d2e1..02540e86 100644 --- a/tycho_simulation_py/Cargo.toml +++ b/tycho_simulation_py/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "_tycho_simulation_py" -version = "0.73.0" +version = "0.74.3" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tycho_simulation_py/pyproject.toml b/tycho_simulation_py/pyproject.toml index a3a5c4e3..6896e00c 100644 --- a/tycho_simulation_py/pyproject.toml +++ b/tycho_simulation_py/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "tycho-simulation-py" -version = "0.73.0" +version = "0.74.3" requires-python = ">=3.7" classifiers = [ "Programming Language :: Rust",