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