@@ -35,20 +35,41 @@ impl FlashbotsConfig {
3535 }
3636}
3737
38- /// A wrapper over a `Provider` that adds Flashbots MEV bundle helpers .
38+ /// A basic provider for common Flashbots Relay endpoints .
3939#[ derive( Debug ) ]
4040pub struct Flashbots {
4141 /// The base URL for the Flashbots API.
4242 pub relay_url : url:: Url ,
4343
4444 /// Signer is loaded once at startup.
4545 signer : LocalOrAws ,
46+
47+ /// The reqwest client to use for requests.
48+ client : reqwest:: Client ,
4649}
4750
4851impl Flashbots {
49- /// Wraps a provider with the URL and returns a new `FlashbotsProvider`.
50- pub const fn new ( relay_url : url:: Url , signer : LocalOrAws ) -> Self {
51- Self { relay_url, signer }
52+ /// Instantiate a new provider from the URL and signer.
53+ pub fn new ( relay_url : url:: Url , signer : LocalOrAws ) -> Self {
54+ Self {
55+ relay_url,
56+ client : Default :: default ( ) ,
57+ signer,
58+ }
59+ }
60+
61+ /// Instantiate a new provider from the URL and signer, with a specific
62+ /// Reqwest client.
63+ pub const fn new_with_client (
64+ relay_url : url:: Url ,
65+ signer : LocalOrAws ,
66+ client : reqwest:: Client ,
67+ ) -> Self {
68+ Self {
69+ relay_url,
70+ client,
71+ signer,
72+ }
5273 }
5374
5475 /// Sends a bundle via `mev_sendBundle`.
@@ -63,7 +84,7 @@ impl Flashbots {
6384 Ok ( ( ) )
6485 }
6586
66- /// Fetches the bundle status by hash
87+ /// Fetch the bundle status by hash.
6788 pub async fn bundle_status (
6889 & self ,
6990 hash : EthBundleHash ,
@@ -77,7 +98,8 @@ impl Flashbots {
7798 Ok ( ( ) )
7899 }
79100
80- /// Makes a raw JSON-RPC call with the Flashbots signature header to the method with the given params.
101+ /// Make a raw JSON-RPC call with the Flashbots signature header to the
102+ /// method with the given params.
81103 async fn raw_call < Params : RpcSend , Payload : RpcRecv > (
82104 & self ,
83105 method : & str ,
@@ -93,8 +115,8 @@ impl Flashbots {
93115
94116 let value = self . compute_signature ( & body_bz) . await ?;
95117
96- let client = reqwest :: Client :: new ( ) ;
97- let resp = client
118+ let resp = self
119+ . client
98120 . post ( self . relay_url . as_str ( ) )
99121 . header ( CONTENT_TYPE , "application/json" )
100122 . header ( "X-Flashbots-Signature" , value)
@@ -112,7 +134,8 @@ impl Flashbots {
112134 }
113135 }
114136
115- /// Builds an EIP-191 signature for the given body bytes.
137+ /// Builds an EIP-191 signature for the given body bytes. This signature is
138+ /// used to authenticate to the relay API via a header
116139 async fn compute_signature ( & self , body_bz : & [ u8 ] ) -> Result < String , eyre:: Error > {
117140 let payload = keccak256 ( body_bz) . to_string ( ) ;
118141 let signature = self . signer . sign_message ( payload. as_ref ( ) ) . await ?;
0 commit comments