flashbots/
lib.rs

1//! A Flashbots API client for Rust.
2//!
3//! ## Structure
4//!
5//! The crate is segmented by Flashbots components:
6//!
7//! - [Flashbots Auction](crate::auction)
8//! - [Flashbots Protect](crate::protect)
9//! - [Flashbots Blocks](crate::blocks)
10//!
11//! Additionally, a set of helpers for simulating bundles and transactions can be found in the [simulation](crate::simulation) module.
12//!
13//! ## Examples
14//!
15//! ### Flashbots Auction
16//!
17//! ### Flashbots Protect
18//!
19//! ### Flashbots Blocks
20//!
21//! ## Ethers Middleware
22//!
23//! For an [`ethers`](ethers) middleware leveraging this crate, refer to [`ethers-flashbots`](ethers-flashbots).
24
25/// Core types.
26pub mod types {
27    pub type BlockNumber = ethers_core::types::U64;
28}
29
30/// Simulation types and helpers.
31pub mod simulation {
32    use crate::types::BlockNumber;
33
34    pub struct SimulationParameters {
35        state_block_number: BlockNumber,
36        timestamp: usize,
37    }
38
39    pub enum SimulationError {
40        MaxFeePerGasTooLow,
41    }
42}
43
44/// Flashbots Auction
45pub mod auction {
46    use crate::types::BlockNumber;
47    use ethers_core::types::Bytes;
48    use ethers_core::types::TxHash;
49    use uuid::Uuid;
50
51    pub struct Bundle {
52        transactions: Vec<Bytes>,
53        block_number: BlockNumber,
54        min_timestamp: Option<usize>,
55        max_timestamp: Option<usize>,
56        reverting_tx_hashes: Vec<TxHash>,
57        replacement_uuid: Option<Uuid>,
58    }
59
60    pub struct CachedBundle {
61        bundle_id: Uuid,
62        transactions: Vec<Bytes>,
63    }
64
65    pub mod stats {
66        pub struct User {}
67        pub struct Bundle {}
68    }
69}
70
71/// Flashbots Protect
72pub mod protect {
73    use crate::simulation::SimulationError;
74    use crate::types::BlockNumber;
75    use ethers_core::types::Transaction;
76    use ethers_core::types::TxHash;
77
78    pub struct Preferences {
79        fast: bool,
80    }
81
82    pub struct PrivateTransaction<T> {
83        transaction: T,
84        max_block_number: BlockNumber,
85        preferences: Preferences,
86    }
87
88    pub enum Status {
89        Pending,
90        Included,
91        Failed,
92        Cancelled,
93        Unknown,
94    }
95
96    pub struct TransactionStatus {
97        status: Status,
98        hash: TxHash,
99        max_block_number: BlockNumber,
100        transaction: Transaction,
101        fast_mode: bool,
102        seen_in_mempool: bool,
103        simulation_error: SimulationError,
104    }
105}
106
107/// Flashbots Blocks
108pub mod blocks {
109    use crate::types::BlockNumber;
110    use ethers_core::types::{Address, TxHash, U256};
111
112    pub struct Transaction {
113        transaction_hash: TxHash,
114        tx_index: U256,
115        bundle_index: U256,
116        block_number: BlockNumber,
117        eoa_address: Address,
118        to_address: Address,
119        gas_used: U256,
120        gas_price: U256,
121        fee_recipient_eth_diff: U256,
122        eth_sent_to_fee_recipient: U256,
123    }
124
125    pub struct Block {
126        block_number: BlockNumber,
127        fee_recipient: Address,
128        fee_recipient_eth_diff: U256,
129        eth_sent_to_fee_recipient: U256,
130        gas_used: U256,
131        gas_price: U256,
132        transactions: Vec<Transaction>,
133    }
134}
135
136#[cfg(test)]
137mod tests {
138    #[test]
139    fn it_works() {
140        let result = 2 + 2;
141        assert_eq!(result, 4);
142    }
143}