Skip to content

Commit

Permalink
Merge pull request #28 from propeller-heads/tl/create-tycho-demo
Browse files Browse the repository at this point in the history
feat: create simple solver for tycho demo
  • Loading branch information
dianacarvalho1 authored Nov 4, 2024
2 parents 0e3930d + 3722316 commit c81489d
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 12 deletions.
62 changes: 55 additions & 7 deletions Cargo.lock

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

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = "0.32.0"
edition = "2021"

[workspace]
members = ["protosim_py"]
members = ["protosim_py", "tutorial"]

[dependencies]
ethabi = "13.0"
ethabi = "13.0"
ethers = "2.0.13"
serde_json = "1.0.105"
serde = { version = "1.0", features = ["rc"] }
Expand All @@ -28,8 +28,8 @@ uuid = { version = "1.4.1", features = [
] }
num-traits = "0.2.17"
dotenv = "0.15.0"
tycho-core = { git = "ssh://github.com/propeller-heads/tycho-indexer.git", package = "tycho-core", tag = "0.34.0" }
tycho-client = { git = "ssh://github.com/propeller-heads/tycho-indexer.git", package = "tycho-client", tag = "0.34.0" }
tycho-core = { git = "ssh://github.com/propeller-heads/tycho-indexer.git", package = "tycho-core", tag = "0.41.0" }
tycho-client = { git = "ssh://github.com/propeller-heads/tycho-indexer.git", package = "tycho-client", tag = "0.41.0" }
foundry-config = { git = "https://github.com/foundry-rs/foundry", rev = "2544793" }
foundry-evm = { git = "https://github.com/foundry-rs/foundry", rev = "2544793" }
revm-inspectors = { version = "0.5", features = ["serde"] }
Expand All @@ -47,7 +47,6 @@ tracing-subscriber = { version = "0.3.17", default-features = false, features =
"fmt",
] }
tempfile = "3.13.0"

[features]
default = []
network_tests = []
Expand Down
19 changes: 19 additions & 0 deletions tutorial/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "tutorial"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "tutorial"
path = "src/main.rs"

[dependencies]
protosim = { path = ".." }
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = "0.3"
ethers = "2.0.13"
clap = { version = "4.5.3", features = ["derive"] }
anyhow = "1.0.79"
tycho-core = { git = "ssh://github.com/propeller-heads/tycho-indexer.git", package = "tycho-core", tag = "0.41.0" }
tycho-client = { git = "ssh://github.com/propeller-heads/tycho-indexer.git", package = "tycho-client", tag = "0.41.0" }
2 changes: 2 additions & 0 deletions tutorial/src/data_feed/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod state;
pub mod tycho;
36 changes: 36 additions & 0 deletions tutorial/src/data_feed/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Message structs for state updates
//!
//! A BlockState typically groups changes together based on the latency of the data source,
//! for example, on the Ethereum network, a BlockState is emitted every block and contains
//! all the changes from that block.
use std::collections::HashMap;

use ethers::types::H160;

use protosim::protocol::{models::ProtocolComponent, state::ProtocolSim};

#[derive(Debug)]
pub struct BlockState {
pub time: u64,
/// The current state of all pools
pub states: HashMap<H160, Box<dyn ProtocolSim>>,
/// The new pairs that were added in this block
pub new_pairs: HashMap<H160, ProtocolComponent>,
/// The pairs that were removed in this block
pub removed_pairs: HashMap<H160, ProtocolComponent>,
}

impl BlockState {
pub fn new(
time: u64,
states: HashMap<H160, Box<dyn ProtocolSim>>,
new_pairs: HashMap<H160, ProtocolComponent>,
) -> Self {
BlockState { time, states, new_pairs, removed_pairs: HashMap::new() }
}

pub fn set_removed_pairs(mut self, pairs: HashMap<H160, ProtocolComponent>) -> Self {
self.removed_pairs = pairs;
self
}
}
Loading

0 comments on commit c81489d

Please sign in to comment.