Abstract


ProtoRev is a module that:

  1. Runs during the Posthandler (core trading execution) and Epoch Hook (keeper store updating)
  2. In the posthandler of a tx, checks if that tx swaps (has SwapExactAmountIn or SwapExactAmountOut as Msgs)
  3. If a tx swaps, generates routes related to the pool swapped against that may contain cyclic arbitrage opportunities after the user’s swap
  4. For each route, determines the optimal amount of the asset to swap in that results in maximum amount of the same asset out (profit)
  5. Compares profits and selects the route that generates the most profit and is greater than 0
  6. Mints the optimal amount of asset to swap in from the Bank module (as determined previously)
  7. Executes the MultiHopSwapExactAmountIn with the optimal input amount for the route
  8. Burns the same amount of asset previously minted to execute the swap
  9. 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