Struct ethers_flashbots::BundleRequest
source · pub struct BundleRequest { /* private fields */ }Expand description
A bundle that can be submitted to a Flashbots relay.
The bundle can include your own transactions and transactions from the mempool.
Additionally, this bundle can be simulated through a relay if simulation
parameters are provided using BundleRequest::set_simulation_block and
BundleRequest::set_simulation_timestamp.
Please note that some parameters are required, and submitting a bundle without them will get it rejected pre-flight. The required parameters include:
- At least one transaction (
BundleRequest::push_transaction) - A target block (
BundleRequest::set_block)
Implementations§
source§impl BundleRequest
impl BundleRequest
sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty bundle request.
Examples found in repository?
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
async fn send_raw_transaction<'a>(
&'a self,
tx: Bytes,
) -> Result<PendingTransaction<'a, Self::Provider>, Self::Error> {
let tx_hash = keccak256(&tx);
// Get the latest block
let latest_block = self
.inner
.get_block(BlockNumber::Latest)
.await
.map_err(FlashbotsMiddlewareError::MiddlewareError)?
.expect("The latest block is pending (this should not happen)");
// Construct the bundle, assuming that the target block is the
// next block.
let bundle = BundleRequest::new().push_transaction(tx.clone()).set_block(
latest_block
.number
.expect("The latest block is pending (this should not happen)")
+ 1,
);
self.send_bundle(&bundle).await?;
Ok(PendingTransaction::new(tx_hash.into(), self.provider())
.interval(self.provider().get_interval()))
}sourcepub fn push_transaction<T: Into<BundleTransaction>>(self, tx: T) -> Self
pub fn push_transaction<T: Into<BundleTransaction>>(self, tx: T) -> Self
Adds a transaction to the bundle request.
Transactions added to the bundle can either be novel transactions, i.e. transactions that you have crafted, or they can be from one of the mempool APIs.
Examples found in repository?
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
async fn send_raw_transaction<'a>(
&'a self,
tx: Bytes,
) -> Result<PendingTransaction<'a, Self::Provider>, Self::Error> {
let tx_hash = keccak256(&tx);
// Get the latest block
let latest_block = self
.inner
.get_block(BlockNumber::Latest)
.await
.map_err(FlashbotsMiddlewareError::MiddlewareError)?
.expect("The latest block is pending (this should not happen)");
// Construct the bundle, assuming that the target block is the
// next block.
let bundle = BundleRequest::new().push_transaction(tx.clone()).set_block(
latest_block
.number
.expect("The latest block is pending (this should not happen)")
+ 1,
);
self.send_bundle(&bundle).await?;
Ok(PendingTransaction::new(tx_hash.into(), self.provider())
.interval(self.provider().get_interval()))
}sourcepub fn push_revertible_transaction<T: Into<BundleTransaction>>(
self,
tx: T
) -> Self
pub fn push_revertible_transaction<T: Into<BundleTransaction>>(
self,
tx: T
) -> Self
Adds a revertible transaction to the bundle request.
This differs from BundleRequest::push_transaction in that the bundle will still be
considered valid if the transaction reverts.
sourcepub fn transactions(&self) -> &Vec<BundleTransaction> ⓘ
pub fn transactions(&self) -> &Vec<BundleTransaction> ⓘ
Get a reference to the transactions currently in the bundle request.
sourcepub fn transaction_hashes(&self) -> Vec<TxHash> ⓘ
pub fn transaction_hashes(&self) -> Vec<TxHash> ⓘ
Get a list of transaction hashes in the bundle request.
Examples found in repository?
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
pub async fn send_bundle(
&self,
bundle: &BundleRequest,
) -> Result<PendingBundle<'_, <Self as Middleware>::Provider>, FlashbotsMiddlewareError<M, S>>
{
// The target block must be set
bundle
.block()
.ok_or(FlashbotsMiddlewareError::MissingParameters)?;
// `min_timestamp` and `max_timestamp` must both either be unset or set.
if bundle.min_timestamp().xor(bundle.max_timestamp()).is_some() {
return Err(FlashbotsMiddlewareError::MissingParameters);
}
let response: SendBundleResponse = self
.relay
.request("eth_sendBundle", [bundle])
.await
.map_err(FlashbotsMiddlewareError::RelayError)?;
Ok(PendingBundle::new(
response.bundle_hash,
bundle.block().unwrap(),
bundle.transaction_hashes(),
self.provider(),
))
}sourcepub fn block(&self) -> Option<U64>
pub fn block(&self) -> Option<U64>
Get the target block (if any).
Examples found in repository?
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
pub async fn simulate_bundle(
&self,
bundle: &BundleRequest,
) -> Result<SimulatedBundle, FlashbotsMiddlewareError<M, S>> {
bundle
.block()
.and(bundle.simulation_block())
.and(bundle.simulation_timestamp())
.ok_or(FlashbotsMiddlewareError::MissingParameters)?;
self.simulation_relay
.as_ref()
.unwrap_or(&self.relay)
.request("eth_callBundle", [bundle])
.await
.map_err(FlashbotsMiddlewareError::RelayError)
}
/// Send a bundle to the relayer.
///
/// See [`eth_sendBundle`][fb_sendBundle] for more information.
///
/// [fb_sendBundle]: https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint#eth_sendbundle
pub async fn send_bundle(
&self,
bundle: &BundleRequest,
) -> Result<PendingBundle<'_, <Self as Middleware>::Provider>, FlashbotsMiddlewareError<M, S>>
{
// The target block must be set
bundle
.block()
.ok_or(FlashbotsMiddlewareError::MissingParameters)?;
// `min_timestamp` and `max_timestamp` must both either be unset or set.
if bundle.min_timestamp().xor(bundle.max_timestamp()).is_some() {
return Err(FlashbotsMiddlewareError::MissingParameters);
}
let response: SendBundleResponse = self
.relay
.request("eth_sendBundle", [bundle])
.await
.map_err(FlashbotsMiddlewareError::RelayError)?;
Ok(PendingBundle::new(
response.bundle_hash,
bundle.block().unwrap(),
bundle.transaction_hashes(),
self.provider(),
))
}sourcepub fn set_block(self, block: U64) -> Self
pub fn set_block(self, block: U64) -> Self
Set the target block of the bundle.
Examples found in repository?
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
async fn send_raw_transaction<'a>(
&'a self,
tx: Bytes,
) -> Result<PendingTransaction<'a, Self::Provider>, Self::Error> {
let tx_hash = keccak256(&tx);
// Get the latest block
let latest_block = self
.inner
.get_block(BlockNumber::Latest)
.await
.map_err(FlashbotsMiddlewareError::MiddlewareError)?
.expect("The latest block is pending (this should not happen)");
// Construct the bundle, assuming that the target block is the
// next block.
let bundle = BundleRequest::new().push_transaction(tx.clone()).set_block(
latest_block
.number
.expect("The latest block is pending (this should not happen)")
+ 1,
);
self.send_bundle(&bundle).await?;
Ok(PendingTransaction::new(tx_hash.into(), self.provider())
.interval(self.provider().get_interval()))
}sourcepub fn simulation_block(&self) -> Option<U64>
pub fn simulation_block(&self) -> Option<U64>
Get the block that determines the state for bundle simulation (if any).
See eth_callBundle in the Flashbots documentation
for more information on bundle simulations.
Examples found in repository?
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
pub async fn simulate_bundle(
&self,
bundle: &BundleRequest,
) -> Result<SimulatedBundle, FlashbotsMiddlewareError<M, S>> {
bundle
.block()
.and(bundle.simulation_block())
.and(bundle.simulation_timestamp())
.ok_or(FlashbotsMiddlewareError::MissingParameters)?;
self.simulation_relay
.as_ref()
.unwrap_or(&self.relay)
.request("eth_callBundle", [bundle])
.await
.map_err(FlashbotsMiddlewareError::RelayError)
}sourcepub fn set_simulation_block(self, block: U64) -> Self
pub fn set_simulation_block(self, block: U64) -> Self
Set the block that determines the state for bundle simulation.
sourcepub fn simulation_timestamp(&self) -> Option<u64>
pub fn simulation_timestamp(&self) -> Option<u64>
Get the UNIX timestamp used for bundle simulation (if any).
See eth_callBundle in the Flashbots documentation
for more information on bundle simulations.
Examples found in repository?
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
pub async fn simulate_bundle(
&self,
bundle: &BundleRequest,
) -> Result<SimulatedBundle, FlashbotsMiddlewareError<M, S>> {
bundle
.block()
.and(bundle.simulation_block())
.and(bundle.simulation_timestamp())
.ok_or(FlashbotsMiddlewareError::MissingParameters)?;
self.simulation_relay
.as_ref()
.unwrap_or(&self.relay)
.request("eth_callBundle", [bundle])
.await
.map_err(FlashbotsMiddlewareError::RelayError)
}sourcepub fn set_simulation_timestamp(self, timestamp: u64) -> Self
pub fn set_simulation_timestamp(self, timestamp: u64) -> Self
Set the UNIX timestamp used for bundle simulation.
sourcepub fn simulation_basefee(&self) -> Option<u64>
pub fn simulation_basefee(&self) -> Option<u64>
Get the base gas fee for bundle simulation (if any).
See eth_callBundle in the Flashbots documentation
for more information on bundle simulations.
sourcepub fn set_simulation_basefee(self, basefee: u64) -> Self
pub fn set_simulation_basefee(self, basefee: u64) -> Self
Set the base gas fee for bundle simulation (if any). Optional: will default to a value chosen by the node if not specified.
sourcepub fn min_timestamp(&self) -> Option<u64>
pub fn min_timestamp(&self) -> Option<u64>
Get the minimum timestamp for which this bundle is valid (if any), in seconds since the UNIX epoch.
Examples found in repository?
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
pub async fn send_bundle(
&self,
bundle: &BundleRequest,
) -> Result<PendingBundle<'_, <Self as Middleware>::Provider>, FlashbotsMiddlewareError<M, S>>
{
// The target block must be set
bundle
.block()
.ok_or(FlashbotsMiddlewareError::MissingParameters)?;
// `min_timestamp` and `max_timestamp` must both either be unset or set.
if bundle.min_timestamp().xor(bundle.max_timestamp()).is_some() {
return Err(FlashbotsMiddlewareError::MissingParameters);
}
let response: SendBundleResponse = self
.relay
.request("eth_sendBundle", [bundle])
.await
.map_err(FlashbotsMiddlewareError::RelayError)?;
Ok(PendingBundle::new(
response.bundle_hash,
bundle.block().unwrap(),
bundle.transaction_hashes(),
self.provider(),
))
}sourcepub fn set_min_timestamp(self, timestamp: u64) -> Self
pub fn set_min_timestamp(self, timestamp: u64) -> Self
Set the minimum timestamp for which this bundle is valid (if any), in seconds since the UNIX epoch.
sourcepub fn max_timestamp(&self) -> Option<u64>
pub fn max_timestamp(&self) -> Option<u64>
Get the maximum timestamp for which this bundle is valid (if any), in seconds since the UNIX epoch.
Examples found in repository?
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
pub async fn send_bundle(
&self,
bundle: &BundleRequest,
) -> Result<PendingBundle<'_, <Self as Middleware>::Provider>, FlashbotsMiddlewareError<M, S>>
{
// The target block must be set
bundle
.block()
.ok_or(FlashbotsMiddlewareError::MissingParameters)?;
// `min_timestamp` and `max_timestamp` must both either be unset or set.
if bundle.min_timestamp().xor(bundle.max_timestamp()).is_some() {
return Err(FlashbotsMiddlewareError::MissingParameters);
}
let response: SendBundleResponse = self
.relay
.request("eth_sendBundle", [bundle])
.await
.map_err(FlashbotsMiddlewareError::RelayError)?;
Ok(PendingBundle::new(
response.bundle_hash,
bundle.block().unwrap(),
bundle.transaction_hashes(),
self.provider(),
))
}sourcepub fn set_max_timestamp(self, timestamp: u64) -> Self
pub fn set_max_timestamp(self, timestamp: u64) -> Self
Set the maximum timestamp for which this bundle is valid (if any), in seconds since the UNIX epoch.
Trait Implementations§
source§impl Clone for BundleRequest
impl Clone for BundleRequest
source§fn clone(&self) -> BundleRequest
fn clone(&self) -> BundleRequest
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more