#ethereum #arbitrage #sandwich #rust

bin+lib subway-rs

A Highly Optimized Sandwich Bot Built with Pure Rust and Huff

7 releases (4 breaking)

0.5.2 Dec 3, 2022
0.5.1 Nov 3, 2022
0.4.0 Nov 3, 2022
0.3.0 Oct 19, 2022
0.1.0 Oct 19, 2022

#2 in #arbitrage

47 downloads per month

MIT license

1.5MB
789 lines

bot • ci license

A Highly Optimized Sandwich Bot Built with Pure Rust and Huff.

Note

Test in prod something Zuck Gobble Fast lose all your ETH i accidentally broke it

Usage

Required Preparation:

  1. Install rust if it's not already installed.
  2. Deploy a sandwich contract from the contracts directory, or re-use an existing one.
  3. Create a .env file and set the required variables, referencing the below environment variables. (NOTE: we've added .env and .env.prod to the .gitignore file, so you don't accidentally commit your secrets to the repo. All other secret commits are on you. Exercise caution.)

Warning

Some providers do NOT support all the RPC methods used by the bot.

For instance, it is not possible to use infura to listen to pending transactions because eth_newPendingTransactionFilter is not supported.

RPC_URL=http://127.0.0.1:8545
RPC_URL_WSS=ws://127.0.0.1:8545
PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000001
FLASHBOTS_AUTH_KEY=0000000000000000000000000000000000000000000000000000000000000002
SANDWICH_CONTRACT=0x0000000000000000000000000000000000000000

Then, you can simply run the bot with:

cargo run --bin subway --release

And you should be good to go!

Library Usage

To use as a library, add subway-rs as a dependency in your Cargo.toml:

[dependencies]
subway-rs = "0.5.0"

Benchmarks

To run benchmarks, simply run:

cargo bench

Individual benches can be run by supplying the --bench flag to cargo with the benchmark name. (e.g. cargo bench --bench utils)

Blueprint

.
├─ src
│  ├─ lib.rs — Exported modules with a re-exported prelude.
│  ├─ main.rs — The main bot binary.
│  ├─ numeric.rs — Refactored functions for numeric operations.
│  ├─ relayer.rs — Wrappers for network requests.
│  ├─ telemetry.rs — Telemetry for verbose logging.
│  ├─ uniswap.rs — Uniswap library.
│  └─ utils.rs — Common utilities.
└─ tests
   └─ Tests so exhaustive, it'll knock your (uni)-socks off

Credits

Dependencies

~27–45MB
~733K SLoC