Skip to content

Commit

Permalink
Merge branch 'main' into zz/python-sim/make-price-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
zizou0x authored Feb 14, 2025
2 parents 574847d + ec87789 commit 59fd6d9
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 34 deletions.
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tycho-simulation"
version = "0.73.0"
version = "0.74.3"
edition = "2021"

[workspace]
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions examples/price_printer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions examples/quickstart/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Vec<Token>> = HashMap::new();

let mut protocol_stream = ProtocolStreamBuilder::new(&tycho_url, Chain::Ethereum)
Expand Down
4 changes: 2 additions & 2 deletions src/evm/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
10 changes: 8 additions & 2 deletions src/evm/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ impl TychoStreamDecoder {
.collect::<Vec<_>>();

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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/evm/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/evm/protocol/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) mod uniswap;
pub mod uniswap;

use alloy_primitives::Address;
use tycho_core::Bytes;
Expand Down
2 changes: 1 addition & 1 deletion src/evm/protocol/utils/uniswap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
52 changes: 40 additions & 12 deletions src/protocol/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,50 @@ pub struct ProtocolComponent {

impl ProtocolComponent {
#[allow(deprecated)]
pub fn new(mut tokens: Vec<Token>, 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<Token>,
contract_ids: Vec<Bytes>,
static_attributes: HashMap<String, Bytes>,
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<Token>,
) -> 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<ProtocolComponent> for tycho_core::dto::ProtocolComponent {
Expand Down
27 changes: 26 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use tracing::info;
use tycho_client::{rpc::RPCClient, HttpRPCClient};
use tycho_core::{dto::Chain, Bytes};

Expand Down Expand Up @@ -36,19 +37,43 @@ pub fn hexstring_to_vec(hexstring: &str) -> Result<Vec<u8>, 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<i32>,
max_days_since_last_trade: Option<u64>,
) -> HashMap<Bytes, Token> {
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()
Expand Down
2 changes: 1 addition & 1 deletion tycho_simulation_py/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tycho_simulation_py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 59fd6d9

Please sign in to comment.