Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lublumev/c37c207f9184bf2820478b365fa9e84b to your computer and use it in GitHub Desktop.
Save lublumev/c37c207f9184bf2820478b365fa9e84b to your computer and use it in GitHub Desktop.

Deconstructing a $2.5M CEX-DEX Arbitrage Bot

Atomic MEV is becoming tougher in recent years as competition intensifies and more skilled teams enter the game. To stay competitive, teams integrate more exchanges and capture untouched arbitrage paths and order flow which is not always trivial, especially when dealing with cross-chain MEV or any non atomic arbitrage.

One common arbitrage is CEX-DEX arbitrage. I've noticed many on-chain bots but never dug deep into their performance until now.

I'll be looking at the bot 0x98C3d3183C4b8A650614ad179A1a98be0a8d6B8E, specifically the transaction 0x6f94aa47e74de8897979fdc3b6e541bb515be9c72f2a912cd548f98e2c11729a USUAL ETH Swap

Investigating the Trade

This token is listed on many exchanges, I'll focus on Binance since this is where this bot likely operates (we'll see that in a bit) USUAL Token Listings

We'll take a look at the price at the time of the swap on Binance: USUAL-USDT Price

What's so special about this swap? Nothing, it's just a very illiquid coin and has low volume which is makes it easier to research about CEX bot activity since we can only work with tick, order book and historical price data.

We can see a spike at 20:04:13 UTC which is 2 seconds after the swap occurred, which makes me believe it's this exact bot CEX leg execution. I've pulled the tick data from the Binance API for around that time and we can see it clearly:

timestamp agg_id price quantity first_trade_id last_trade_id is_buyer_maker
2025-06-21 20:04:09.131000 27948037 0.0655 170.3 51934682 51934682 True
2025-06-21 20:04:11.117000 27948038 0.0656 96.8 51934683 51934683 False
2025-06-21 20:04:13.391000 27948039 0.0656 23998.2 51934684 51934689 False
2025-06-21 20:04:13.391000 27948040 0.0657 96.8 51934690 51934690 False
2025-06-21 20:04:19.140000 27948041 0.0656 172.6 51934691 51934691 True

We can see there was a taker buy order for 23,998.2 of the token at 0.0656 USDT and then another one for 96.8 at 0.06567. These add up to 23,095 which is the exact amount traded on chain, making me believe that this was a simple Binance-Uniswap CEX-DEX arbitrage.

Profit?

Let's see how much this bot has made. First we need to pull ETHUSDT Binance tick data to see the USDT-ETH exchange rate, I'm really not sure if this is the correct trade but assuming it didn't get fragmented I've found a few ticks later the following trade: WETH-USDT Tick Data This aligns with the amount of eth swapped, it is also a taker order which fits arbitrage bots on wide spreads common with small coins on Uniswap.

  • #NOTE There is ~0.000046781 ETH missing here, I will assume the execution price is the same for the remainder (it's around 10 cents) since USDT-WETH is a very liquid market and it's negligible compared to the profit margin as we're about to see.

Approximating CEX Fees

I'm not sure how much taker fees this bot pays, but we can approximate it. I've downloaded the last 1,000 from ethplorer.io and extrapolated the volume per transaction which resulted in more than $150M monthly volume. This is a very rough calculation but it's good enough for now. Based on the Binance fee structure it results in a 0.0310% taker fee for USDT.

Summarizing the Trades

  • DEX leg: 24,095 USUAL -> 0.6643467809358965 ETH
  • DEX gas fees + bribe: 0.000885733612219919 ETH @ 2,384.57 ETH/USDT = -2.112093799691252 USDT
  • CEX leg:
    • Trade 1: Buy 23,998.2 USUAL @ 0.0656 USUAL/USDT = -1574.2819200000001 USDT
    • Trade 2: Buy 96.8 USUAL @ 0.0657 USUAL/USDT = -6.35976 USDT
    • Trade 3: Sell ~0.6643467809358965 ETH @ 2,384.57 ETH/USDT = +1584.1814034163108 USDT
  • CEX fees:
    • Trade 1: 23,998.2 * 0.000310 USUAL = 7.4394420000000006 USUAL @ 0.0656 USUAL/USDT = -0.4880273952000001 USDT
    • Trade 2: 96.8 * 0.000310 USUAL = 0.030008 USUAL @ 0.0657 USUAL/USDT = -0.0019715256 USDT
    • Trade 3: 0.6643467809358965 * 0.000310 ETH = 0.00034546032608666615 ETH @ 2,384.57 ETH/USDT = -0.49109623505905636 USDT

This resulted in a profit of 0.44653446076018594 USDT.

#NOTE This is still a rough estimate, for example if we used a 0.052% fee for the Binance leg we would have gotten a $0.2 loss. It's also possible that the bot is at an even higher fee tier assuming they make more transaction or have other CEX-CEX/DEX arbitrage going on multiple accounts.

Key Takeaways

There are a few interesting things we can infer from this trade.

First, the bot fixes an illiquid market Uniswap which has a ~$100,000 24h Volume, to a liquid market Binance which has ~$4,400,000 24h Volume. It is also triggered by a price change on the illiquid market to execute the trade as can be seen in the pool token transfers: Uniswap USUAL Pool ERC20 Transfers Which caused a spike as we can see on DEX screener (I didn't bother checking the actual pool liquidity/price but we can assume it caused an imbalance): USUAL WETH Dex Screener I haven't checked if the tx on block 22755096 was seen on the mempool, maybe you can beat this bot by bundling the DEX leg with the mempool tx and backrun it?

Time and Optimizations

The bot took 2.391 seconds to react, this is really slow, you could easily monitor this bot and frontrun it on Binance to make a few quick bucks, definitely a nice stat arb/scalping strategy to look into if you have good infrastructure.

This bot can be beaten by improving the calldata, this is not a good execution if you want to stay competitive, looks like this bot takes 120,000 to 160,000 gas per Uniswap V2 swap and even more for V3, this is can be reduced to 100,000 easily. Just looking at the calldata we can see there is room for improvement:

0x49c36c0700000000000000000000000014154c15fc0fd3f91de557a1b6fdd2059972cd0b00000000000000000000000000000000000000000000051a314c1737fd1c000000000000000000000000000000000000000000bd4b3bf79312e000000000000000000000000000000000000000000000000000bdb3f5ff4b6d680000000000000000000000000000000000000000000000000000000000000000000000000000

Also they used solidity over huff or assembly as we can see in the contract bytecode (the 0x60806040 solidity memory setup opcodes): Bot Contract Bytecode

Does this all matter? Yes and no. I've looked into this bot a little in the past and have seen interesting ties to a specific builder, I'm not sure at all and don't want to spread misinformation but this bot may have a relationship with a builder which makes the gas optimizations less important.

Summary

I'm no quant and I might have missed some things here, but even though the DEX execution is not optimal the bot operators know what they are doing. The on-chain backrun signal works well and they are able to land many arbs compared to other CEX-DEX bots, no to mention they have ~$2.5 million in capital on a single ethereum wallet which is quite a lot even for a mev bot.

Another interesting thing to look at would be the order book at the time of the trade, looks like the bot waits for a backrun signal and checks the order book on Binance to see if there is a profitable market order it can take. Perhaps market makers could benefit from such data on-chain to adjust their positions since they have the latency advantage. The bot also assumes the USDT-WETH pair is liquid enough and indeed $1,500 worth of ETH has little to no price impact which makes the triangular arb simpler to calculate.

So how would one implement this bot?

  1. Run an Ethereum node.
  2. Write a simple contract that allows executing a Uniswap trade (you can even use the router directly if you don't need to be competitive or want to do the same on other DEXs).
  3. Wait for a signal, this can be a mempool tx or a block tx that cause a large price change (you can model historical price changes for various tokens and set different thresholds, or search all of them it's only ~3 swaps per seconds on average).
  4. Compare the price with the order book for said pair on Binance or any other CEX of your choice (bonus points if you have adapters for all exchanges), forming a triangular arbitrage.
  5. Manage your inventory, unfortunately I'm not familiar with how to do this efficiently (I'm not a quant) so you need to do some research on your own.
  6. Profit? no. It may look simple, but it isn't. These teams are highly skilled and likely running far more sophisticated strategies than covered here. That said, this gives you a solid foundation in CEX-DEX arbitrage. The same strategy can work on various chains and CEXs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment