kabu_backtest_runner/
flashbots_mock.rs

1use alloy_primitives::{B256, Bytes, U64};
2use serde::{Deserialize, Serialize};
3use wiremock::{
4    Mock, MockServer, ResponseTemplate,
5    matchers::{method, path},
6};
7
8#[derive(Debug, Deserialize)]
9pub struct BundleRequest {
10    #[allow(dead_code)]
11    pub jsonrpc: String,
12    #[allow(dead_code)]
13    pub id: u64,
14    #[allow(dead_code)]
15    pub method: String,
16    pub params: Vec<BundleParam>,
17}
18
19#[derive(Debug, Deserialize)]
20#[serde(rename_all = "camelCase")]
21pub struct BundleParam {
22    #[serde(rename = "txs")]
23    pub transactions: Vec<Bytes>,
24
25    #[allow(dead_code)]
26    #[serde(rename = "blockNumber")]
27    pub target_block: Option<U64>,
28    // dropped the rest of the fields
29}
30
31#[derive(Serialize)]
32#[serde(rename_all = "camelCase")]
33pub struct BundleResponse {
34    pub bundle_hash: Option<B256>,
35}
36
37#[derive(Serialize)]
38pub struct SendBundleResponse {
39    pub jsonrpc: String,
40    pub id: u64,
41    pub result: BundleResponse,
42}
43
44pub async fn mount_flashbots_mock(mock_server: &MockServer) {
45    let bundle_resp = SendBundleResponse { jsonrpc: "2.0".to_string(), id: 1, result: BundleResponse { bundle_hash: Some(B256::ZERO) } };
46
47    Mock::given(method("POST"))
48        .and(path("/"))
49        .respond_with(ResponseTemplate::new(200).set_body_json(&bundle_resp).append_header("content-type", "application/json"))
50        .mount(mock_server)
51        .await;
52}