Skip to content

Commit 2aba30b

Browse files
feat: Update full test to use tycho-test
- It uses the index command of tycho indexer to sync the protocol until now and then stream the live updates - Connects to the stream and processes updates - Calculates spot prices, limits and get amount out using Tycho Simulation - It simulates execution using RPC batched RPC requests - Uses router and executor overwrites (so that the executor doesn't need to be deployed) - It batches the simulations in smaller chunks. The requests are really big because of the overwrites Other changes: - Using ProtocolStreamBuilder in the state registry instead of TychoStreamDecoder. Then in the ranged test we are just extracting the decoder from the ProtocolStreamBuilder (hacky but it works) - In the full test we need to keep track of the ProtocolComponents to simulate in multiple blocks - Changed get_current_block to get_block(block_number) #time 7h 5m #time 8m
1 parent 0ef631c commit 2aba30b

File tree

8 files changed

+853
-368
lines changed

8 files changed

+853
-368
lines changed

protocol-testing/Cargo.lock

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

protocol-testing/Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ glob = "0.3.0"
88
miette = { version = "7.6.0", features = ["fancy"] }
99
# Logging & Tracing
1010
tracing = "0.1.37"
11-
tycho-simulation = { git = "https://github.com/propeller-heads/tycho-simulation.git", tag = "0.196.4", features = ["evm"] }
12-
tycho-test = { git = "https://github.com/propeller-heads/tycho-simulation.git", tag = "0.196.4" }
13-
tycho-execution = ">=0.134.0"
11+
tycho-simulation = { path = "../../tycho-simulation", features = ["evm"] }
12+
tycho-test = { path = "../../tycho-simulation/tycho-test" }
13+
tycho-execution = { path = "../../tycho-execution" }
1414
num-bigint = "0.4"
1515
num-traits = "0.2"
1616
num-rational = "0.4.2"
1717
# EVM dependencies
1818
alloy = { version = "1.0.30", features = ["arbitrary", "json", "dyn-abi", "sol-types", "contract", "provider-http", "providers", "signer-local", "rpc-types-eth", "rpc-types-trace"] }
1919
reqwest = { version = "0.12", features = ["json"] }
2020
tokio = { version = "1", features = ["full"] }
21+
futures = "0.3"
2122
serde_json = "1.0.140"
2223
clap = "4.5.31"
2324
figment = { version = "0.10.19", features = ["yaml"] }
2425
serde = { version = "1.0.218", features = ["derive"] }
2526
hex = "0.4.3"
2627
tracing-subscriber = "0.3.19"
2728
postgres = "0.19.10"
29+
tokio-postgres = "0.7"
2830
serde_yaml = "0.9.34"
2931
dotenv = "0.15.0"
3032
async-trait = "0.1.87"
@@ -33,4 +35,5 @@ similar = "2.7.0"
3335
termsize = "0.1.9"
3436
itertools = "0.14.0"
3537
tokio-retry2 = { version = "0.6.0", features = ["jitter"] }
36-
regex = "1.11.1"
38+
regex = "1.11.1"
39+
tempfile = "3.8.1"

protocol-testing/src/main.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum TestSubcommand {
3131
Range(RangeTestCommand),
3232
}
3333

34-
/// Run a test from a specific initial block to the latest block
34+
/// Run continuous sync test from a specific initial block
3535
#[derive(Args)]
3636
pub struct FullTestCommand {
3737
#[command(flatten)]
@@ -42,22 +42,13 @@ pub struct FullTestCommand {
4242
/// configuration.
4343
#[arg(long)]
4444
initial_block: Option<u64>,
45-
46-
/// Stop the test at this block number.
47-
/// If not provided, it will use the latest block of the chain at the time of running the
48-
/// command.
49-
#[arg(long)]
50-
stop_block: Option<u64>,
5145
}
5246

5347
impl FullTestCommand {
5448
fn run(self) -> miette::Result<()> {
5549
let args = self.common_args;
5650
TestRunner::new(
57-
TestType::Full(TestTypeFull {
58-
initial_block: self.initial_block,
59-
stop_block: self.stop_block,
60-
}),
51+
TestType::Full(TestTypeFull { initial_block: self.initial_block }),
6152
args.root_path()?,
6253
args.chain,
6354
args.package,

protocol-testing/src/rpc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ impl RPCProvider {
8383
.and_then(|block_opt| block_opt.ok_or_else(|| miette::miette!("Block not found")))
8484
}
8585

86-
pub async fn get_current_block(&self) -> miette::Result<Block> {
87-
info!("Fetching current block...");
86+
pub async fn get_block(&self, block_number: BlockNumberOrTag) -> miette::Result<Block> {
87+
info!("Fetching block {:?}...", block_number.as_number());
8888
let provider = ProviderBuilder::new().connect_http(self.url.clone());
8989
provider
90-
.get_block_by_number(BlockNumberOrTag::Latest)
90+
.get_block_by_number(block_number)
9191
.await
9292
.into_diagnostic()
93-
.wrap_err("Failed to fetch current block")
93+
.wrap_err(format!("Failed to fetch block {:?}", block_number))
9494
.and_then(|block_opt| block_opt.ok_or_else(|| miette::miette!("Block not found")))
9595
}
9696
}
Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,60 @@
11
use tycho_simulation::{
22
evm::{
3-
decoder::TychoStreamDecoder,
43
engine_db::tycho_db::PreCachedDB,
54
protocol::{
65
ekubo::state::EkuboState, pancakeswap_v2::state::PancakeswapV2State,
76
uniswap_v2::state::UniswapV2State, uniswap_v3::state::UniswapV3State,
87
vm::state::EVMPoolState,
98
},
9+
stream::ProtocolStreamBuilder,
1010
},
1111
protocol::models::DecoderContext,
12-
tycho_client::feed::BlockHeader,
12+
tycho_client::feed::component_tracker::ComponentFilter,
1313
};
1414

1515
/// Register decoder based on protocol system. Defaults to EVMPoolState.
1616
/// To add a new protocol, just add a case to the match statement.
17-
pub fn register_decoder_for_protocol(
18-
decoder: &mut TychoStreamDecoder<BlockHeader>,
17+
pub fn register_protocol(
18+
stream_builder: ProtocolStreamBuilder,
1919
protocol_system: &str,
2020
decoder_context: DecoderContext,
21-
) -> miette::Result<()> {
22-
match protocol_system {
23-
"uniswap_v2" | "sushiswap_v2" => {
24-
decoder
25-
.register_decoder_with_context::<UniswapV2State>(protocol_system, decoder_context);
26-
}
27-
"pancakeswap_v2" => {
28-
decoder.register_decoder_with_context::<PancakeswapV2State>(
21+
) -> miette::Result<ProtocolStreamBuilder> {
22+
let tvl_filter = ComponentFilter::with_tvl_range(100.0, 100.0);
23+
let stream_builder = match protocol_system {
24+
"uniswap_v2" | "sushiswap_v2" => stream_builder
25+
.exchange_with_decoder_context::<UniswapV2State>(
2926
protocol_system,
27+
tvl_filter,
28+
None,
3029
decoder_context,
31-
);
32-
}
33-
"uniswap_v3" | "pancakeswap_v3" => {
34-
decoder
35-
.register_decoder_with_context::<UniswapV3State>(protocol_system, decoder_context);
36-
}
37-
"ekubo_v2" => {
38-
decoder.register_decoder_with_context::<EkuboState>(protocol_system, decoder_context);
39-
}
40-
// Default to EVMPoolState for all other protocols
41-
_ => {
42-
decoder.register_decoder_with_context::<EVMPoolState<PreCachedDB>>(
30+
),
31+
"pancakeswap_v2" => stream_builder.exchange_with_decoder_context::<PancakeswapV2State>(
32+
protocol_system,
33+
tvl_filter,
34+
None,
35+
decoder_context,
36+
),
37+
"uniswap_v3" | "pancakeswap_v3" => stream_builder
38+
.exchange_with_decoder_context::<UniswapV3State>(
4339
protocol_system,
40+
tvl_filter,
41+
None,
4442
decoder_context,
45-
);
46-
}
47-
}
43+
),
44+
"ekubo_v2" => stream_builder.exchange_with_decoder_context::<EkuboState>(
45+
protocol_system,
46+
tvl_filter,
47+
None,
48+
decoder_context,
49+
),
50+
// Default to EVMPoolState for all other protocols
51+
_ => stream_builder.exchange_with_decoder_context::<EVMPoolState<PreCachedDB>>(
52+
protocol_system,
53+
tvl_filter,
54+
None,
55+
decoder_context,
56+
),
57+
};
4858

49-
Ok(())
59+
Ok(stream_builder)
5060
}

0 commit comments

Comments
 (0)