@@ -35,20 +35,41 @@ impl FlashbotsConfig {
35
35
}
36
36
}
37
37
38
- /// A wrapper over a `Provider` that adds Flashbots MEV bundle helpers .
38
+ /// A basic provider for common Flashbots Relay endpoints .
39
39
#[ derive( Debug ) ]
40
40
pub struct Flashbots {
41
41
/// The base URL for the Flashbots API.
42
42
pub relay_url : url:: Url ,
43
43
44
44
/// Signer is loaded once at startup.
45
45
signer : LocalOrAws ,
46
+
47
+ /// The reqwest client to use for requests.
48
+ client : reqwest:: Client ,
46
49
}
47
50
48
51
impl 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
+ }
52
73
}
53
74
54
75
/// Sends a bundle via `mev_sendBundle`.
@@ -63,7 +84,7 @@ impl Flashbots {
63
84
Ok ( ( ) )
64
85
}
65
86
66
- /// Fetches the bundle status by hash
87
+ /// Fetch the bundle status by hash.
67
88
pub async fn bundle_status (
68
89
& self ,
69
90
hash : EthBundleHash ,
@@ -77,7 +98,8 @@ impl Flashbots {
77
98
Ok ( ( ) )
78
99
}
79
100
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.
81
103
async fn raw_call < Params : RpcSend , Payload : RpcRecv > (
82
104
& self ,
83
105
method : & str ,
@@ -93,8 +115,8 @@ impl Flashbots {
93
115
94
116
let value = self . compute_signature ( & body_bz) . await ?;
95
117
96
- let client = reqwest :: Client :: new ( ) ;
97
- let resp = client
118
+ let resp = self
119
+ . client
98
120
. post ( self . relay_url . as_str ( ) )
99
121
. header ( CONTENT_TYPE , "application/json" )
100
122
. header ( "X-Flashbots-Signature" , value)
@@ -112,7 +134,8 @@ impl Flashbots {
112
134
}
113
135
}
114
136
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
116
139
async fn compute_signature ( & self , body_bz : & [ u8 ] ) -> Result < String , eyre:: Error > {
117
140
let payload = keccak256 ( body_bz) . to_string ( ) ;
118
141
let signature = self . signer . sign_message ( payload. as_ref ( ) ) . await ?;
0 commit comments