Abstract
ProtoRev is a module that:
- Runs during the Posthandler (core trading execution) and Epoch Hook (keeper store updating)
- In the posthandler of a tx, checks if that tx swaps (has SwapExactAmountIn or SwapExactAmountOut as Msgs)
- If a tx swaps, generates routes related to the pool swapped against that may contain cyclic arbitrage opportunities after the user’s swap
- For each route, determines the optimal amount of the asset to swap in that results in maximum amount of the same asset out (profit)
- Compares profits and selects the route that generates the most profit and is greater than 0
- Mints the optimal amount of asset to swap in from the Bank module (as determined previously)
- Executes the MultiHopSwapExactAmountIn with the optimal input amount for the route
- Burns the same amount of asset previously minted to execute the swap
- Redistributes the profit captured back to the Osmosis ecosystem based on Governance.
For ecosystem context about the purpose of the module, please see the ProtoRev governance proposal discussion: https://gov.osmosis.zone/discussion/7078-skip-x-osmosis-proposal-to-capture-mev-as-protocol-revenue-on-chain
Concepts
Cyclic Arbitrage
Cyclic arbitrage is a series of swaps that results in more of the same asset that was initially swapped in. An example of this is as follows:
Assume there exists three pools with the following asset pairs:
1. A/B
2. B/C
3. C/A