If you've placed a trade on a DEX and noticed that you received less than expected when it was finalized, chances are you've been front runned. What is front running – and how can you avoid it?
Though this is sometimes down to simple bad luck, more often than not it’s caused by a so-called front runner – i.e. a person that exploits the way transactions are ordered within a block to extract profit from another trader (hereon described as ‘the target’).
Briefly, it involves placing a large buy order and then a large sell order before ordering these in the next block through a so-called priority gas auction (PGA). The front runner’s buy order is ordered before the target’s buy order, and the front runner’s sell order is ordered after it – thereby siphoning some value from the target.
The goal here is to buy a large number of tokens at a low price, before selling them to the target at a slightly higher price while simultaneously exiting the position. When done right, this can lead to almost risk-free profits for the front runner.
Now, before you think you might be able to do it manually, think again. Front runners bots typically operate on a millisecond-scale timeframe. They can read a transaction from the mempool, calculate the optimum transaction size, configure the transactions and then execute them within a fraction of a second. It’s simply not possible to compete while operating manually.
Strategy 1: Avoid Low Liquidity Pools
Low liquidity pools are a front runner’s dream. After all, there’s less chance of competition among other front runners, and less chance that their transaction could be disrupted by a large order that suddenly changes the pool weighting before they enter.
If at all possible, you should avoid low liquidity pools to minimize the odds of being targeted by a front runner.
Strategy 2: Set Low Slippage
Most DEXs allow you to set a maximum slippage tolerance. This is the maximum deviation from the expected return that you will allow – such as 0.5%.
If, for example, you expected a return of 1,000 USDT for your order, then you might receive as low as 995 USDT if your slippage is set to 0.5%. But this deviation can be far greater if you set a higher slippage tolerance.
To avoid front runners, keep your maximum slippage low – somewhere around 0.5% - 2%. The larger your order, the lower you will want to keep your slippage. Front runners love high slippage and large orders!
Strategy 3: Overpay on Gas
Slow transactions give the front runners more time to formulate an order to successfully siphon value from your trade. By underpaying on gas, odds are your transaction will be queued for longer, giving front runners more time to work.
This step is doubly important if you intend to place a large value order – since there is a strong chance you will be targeted.
Strategy 4: Place a Smaller Order
Front runners generally need to risk a lot to win a little. But beyond this, there are also minimum thresholds they need to respect in order to turn a profit – since they must take into consideration the gas fees on both entering and exiting the market, as well as the amount lost as the trading fee.
Since the average transaction fee is currently around $25 a pop for major Ethereum-based AMMs like Balancer, SushiSwap and Uniswap, and two transactions are required to front-run, you can be fairly sure you won’t be targeted if your trade would result in less than $50 profit for the front runner.
The best way to accomplish this is by placing a low value order. Odds are, if you’re trading with sums under $1,000, then odds are you’re safe – that is, unless gas prices decrease considerably and reduce their profitability threshold.
Will Front Running Still Exist on Ethereum 2.0?
Keep these in mind the next time you trade on a DEX to avoid front runners!