Skip to content

WIP: Two new cheatcodes to enable Forge scripts to send Flashbots bundles#4948

Closed
ape-dev-cs wants to merge 7 commits intofoundry-rs:masterfrom
ape-dev-cs:feat/send-bundle
Closed

WIP: Two new cheatcodes to enable Forge scripts to send Flashbots bundles#4948
ape-dev-cs wants to merge 7 commits intofoundry-rs:masterfrom
ape-dev-cs:feat/send-bundle

Conversation

@ape-dev-cs
Copy link
Contributor

@ape-dev-cs ape-dev-cs commented May 15, 2023

Motivation

I wanted to be able to easily send flashbots bundles within forge scripts for use-cases involving transactions that cannot hit public mempools for security reasons (e.g. MEV-able transactions, whitehat rescues, etc).

Solution

Two new cheatcodes, vm.startBundle(target_block_number, gas_price) and vm.stopBundle(), which allow users to send flashbots bundles in foundry scripts, for example like this:

vm.startBroadcast(ACCOUNT_1);
vm.startBundle(uint64(block.number + 3), 100 gwei);
address(0xFDA4C65985934043412fdFAbf3F11552b9A6932D).call{value: 0.1 ether, gas: 21000}("");
// more transactions / deployments / etc
vm.stopBundle();
vm.stopBroadcast();

This is a draft PR as this is a work in progress, and I'm also very new to Rust, so may not have built this optimally. I'd like to get feedback and code review from the community if possible.

Copy link
Contributor

@devanoneth devanoneth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small comments for now but so excited to see this!

cli/Cargo.toml Outdated
# eth
ethers = { workspace = true, features = ["rustls"] }
solang-parser = "=0.2.4"
ethers-flashbots = { git = "https://github.com/onbjerg/ethers-flashbots" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should tie it to a specific version e.g. 0.13.0.

})
.collect::<Result<Vec<_>>>()?;

trace!(target: "script", "sequence: {:#?}", &sequence);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it's best to either:

  1. remove this trace and just keep the full transactions trace on L90 or
  2. remove the trace on L90 and add a trace for flashbots_sequence here.


let client = FlashbotsMiddleware::new(
provider.clone(),
Url::parse("https://relay.flashbots.net")?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably also support the goerli flashbots relay, even though it can be annoying to get a tx in there, people might want to test against that.

pub additional_contracts: Vec<AdditionalContract>,
pub is_fixed_gas_limit: bool,
pub bundle_block: Option<U64>,
pub bundle_gas: Option<U256>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be overkill, but I do think having the bundle details in a separate struct and then wrapped in one Option would be nicer because it seems they are both always checked together and also both must always be present.

pub struct BroadcastableTransaction {
pub rpc: Option<RpcUrl>,
pub bundle_block: Option<U64>,
pub bundle_gas: Option<U256>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here re having bundle details in one struct.

@zerosnacks zerosnacks added the A-private-transactions Area: private transactions label Jun 26, 2024
@zerosnacks
Copy link
Member

zerosnacks commented Jul 26, 2024

Leaving this PR open as I would like to see native support (tracking here: #4947) for private transactions but it will likely be better to start from scratch given the update to Alloy, deprecation of ethers-flashbots, updates to cheatcodes + the changing landscape of block building and the prominence of L2s with trusted sequencers.

Related PR: #4931 introduces the broadcastRawTransaction cheatcode which could be useful in this context

Related Alloy Flashbots support: https://github.com/leruaa/alloy-mev

@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 31, 2024
@zerosnacks
Copy link
Member

zerosnacks commented Jul 31, 2024

Still supportive but given the required changes I think it makes sense that we go back to the drawing board before proceeding, leaving #4947 open to cover the request

@zerosnacks zerosnacks closed this Jul 31, 2024
@zerosnacks zerosnacks removed this from the v1.0.0 milestone Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-private-transactions Area: private transactions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants