- Published on
Blind Arbitrage With Off-Chain Bundles
- Authors
- Name
- merkle
- @merkle_mev
Off-chain bundles allow searchers and developers to leverage off-chain compute to build MEV and other strategies in a much more cost effective way. To learn more about off-chain bundles visit the official docs. For example contracts for the blind arbitrage project please refer to the off-chain-bundle-examples.
Off-chain bundles are MEV bundles with both regular signed transactions as well as off-chain transactions. Off-chain transactions are objects with necessary information for a whitelisted bundle signer to create a transaction that calls a function in a local simulation environment off-chain. The return bytes from this first function are used as calldata to construct a new transaction that is ultimately settled on-chain. With off-chain bundles, developers can separate code that is non-critical for execution and compute intensive into the off-chain transaction and only include critical execution in the on-chain transaction. This results in significant gas savings allowing for more innovation without worrying about Etheream gas costs.
One of the best example use cases of off-chain bundles is blind arbitrage. Blind transactions prevent searchers from determining optimal arbitrage calculations, arbitrage routes, etc during local simulation. This forces searchers to include much of their searching strategies in their deployed bot contracts. Not only is the execution of these strategies costly, but the deployment cost is also expensive. Let’s see how we can save on gas usage with off-chain bundles!
This blind arbitrage contracts have been adapted from the Flashbot’’s simple-blind-arbitrage repository. Let’s take a look at the layout of the contract. For full contract implementations please refer to the project repository.
pragma solidity ^0.8.19;
contract BlindBackrun {
function searchArbitrage(
address firstPairAddress,
address secondPairAddress,
uint percentageToPayToCoinbase,
address searcher
) external onlyOwner returns (bytes memory);
function executeArbitrage(
address firstPairAddress,
address secondPairAddress,
uint256 amountIn,
bool firstPairDataIsWETHZero,
uint256 firstPairAmountOut,
uint256 finalAmountOut,
uint256 profit,
uint256 profitToCoinbase,
uint256 profitToCaller,
address searcher
) external payable onlyOwner;
}
searchArbitrage
The off-chain transaction component of blind arbitrage. The most compute intensive part of blind arbitrage is finding the optimal swap amounts and routes. The search function takes in the pool addresses to use in the arbitrage as well as arguments for profit taking. This function is responsible for calculating the route direction of the swaps and optimal swap amounts. In this simulation, we can implement the swaps and determine the final profit calculation and fees required to pay without actually executing them. All the critical information can then be passed on to the on-chain settlement transaction through calldata for the settle function.
settleArbitrage
Since all critical information was already simulated in the search function, the only required compute in the settle function is to actually execute the functions that modify state. This includes executing the transfers, swaps, and withdrawals. Since the off-chain transaction is simulated at the index of the bundle in the block, the execution environment is guaranteed to be the exact same between off-chain and on-chain transactions. By limiting the compute of the settle function that gets committed to Ethereum, the gas cost of the entire transaction is limited to the compute in this function.
Gas Analysis
We profiled the on-chain transaction of an off-chain bundle compared to a regular transaction for blind arbitrage. Here is what we found:
- Regular backrun transaction: ~140,000 gas used
- executeFunction() of the off-chain transaction: ~80,000 gas used
We can save more than 40% of gas costs with off-chain compute! Note that the example contracts are not gas optimized to reduce on-chain gas fees further. The example contracts also only evaluate one pair of pre-determined pools. Evaluating higher dimensional routes and more pools, increases the compute required off-chain far more than the increased compute required on-chain, resulting in even more gas savings.
Blind arbitrage is only one example where off-chain bundles can be utilized by searchers and developers alike. Any compute intensive execution can be moved off-chain for additional gas savings. We hope to define further examples and help create new paradigms of developing transactions with off-chain bundles!
Please reach out to us on discord of you would like to get started with off-chain bundles or would like to discuss new ideas!