Degen Code

Degen Code

Share this post

Degen Code
Degen Code
Multi-Transaction Bundle Simulation With Anvil
Copy link
Facebook
Email
Notes
More

Multi-Transaction Bundle Simulation With Anvil

B|U|N|D|L|E|S|I|N|B|I|O

May 25, 2024
โˆ™ Paid
8

Share this post

Degen Code
Degen Code
Multi-Transaction Bundle Simulation With Anvil
Copy link
Facebook
Email
Notes
More
Share

Forking is such an important topic that I put it right after Accounts and Smart Contracts in the Blockchain Basics series.

Blockchain Basics โ€” Part III: Forking

Blockchain Basics โ€” Part III: Forking

BowTiedDevil
ยท
April 21, 2024
Read full story

My forking tool of choice is Anvil, part of the Foundry toolkit.

I have covered using Anvil to simulate bundles before, and I recommend reviewing Local Bundle Simulation where I developed the initial version of AnvilFork, which has since been merged into the degenbot repo.

Local Bundle Simulation with Anvil

Local Bundle Simulation with Anvil

BowTiedDevil
ยท
August 24, 2023
Read full story

I had two main drivers for building AnvilFork:

  • Performance โ€” For rapid testing, latency is a killer. Having a locally-available tool I wanted a locally-available, high performance tool for testing multi-transaction bundles.

  • Availability โ€” I wanted to stop relying on external services like Flashbots Relay and Tenderly for transaction simulation.

AnvilFork does both. I have used it exclusively for both testing and active simulation on live bots, and I continue to make improvements.

But one issue kept dogging me โ€” the gas usage values werenโ€™t right! Users in Discord reported similar findings.

I have discovered the fix, though to be honest I donโ€™t fully understand the cause. EVM opcodes and their gas use are deterministic, so there should be no difference between a transaction executed by geth, reth, Anvil, Hardhat, or some other EVM execution engine.

But we have to assume some variance in the accuracy of our tools, so letโ€™s continue marching forward. In this post we will launch a fork, execute a series of transactions using two methods, then compare their gas use and accuracy against the canonical chain.

Replaying A Bundle

To begin, take this multi-TX sandwich bundle that I saw on Etherscan:

  • TX 0: Pre-Swap Atomic Arbitrage

  • TX 1: Target Swap

  • TX 2: Post-Swap Atomic Arbitrage

This post is for paid subscribers

Already a paid subscriber? Sign in
ยฉ 2025 BowTiedDevil
Privacy โˆ™ Terms โˆ™ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More