Skip to main content
Version: V5

Arbitraging Yield Liquidations

Tutorial: 💸 Creating an Arbitrage Swapping bot


PoolTogether V5 continuously liquidates all yield for POOL tokens and deposits them into a Prize Pool. Liquidation sells yield at a slight discount for POOL, creating an arbitrage opportunity.

Liquidation Pairs are the mechanism by which yield is liquidated. Each PoolTogether Vault will have one or more associated Liquidation Pairs. A Liquidation Pair is like a Uniswap pair, but it only supports swaps in a single direction.

Liquidation Pairs are immutable contracts that are created by the Liquidation Pair Factory.

Arbitrage Steps

To arbitrage yield, you would follow these steps:

  1. Find the Liquidation Pair you wish to arb.
  2. Compute the current available liquidity and the POOL cost
  3. If liquidity is available at a sufficient discount and profitable to you, execute a swap

Find the Liquidation Pair

You can list the Liquidation Pairs on-chain by using the Liquidation Pair Factory contract. The contract tracks all created pairs, making it easy to determine whether a pair is legitimate, and to enumerate all pairs.

Realistically, however, bots will want to index and track the Liquidation Pairs off-chain. We'll leave that up to implementors.

Getting the Total Count of Liquidation Pairs

To get the count of the number of Liquidation Pairs, you can call totalPairs() on the Liquidation Pair Factory.

Retrieving the address of the Nth Liquidation Pair

Liquidation Pair addresses can be accessed using the allPairs(uint index) function on the Liquidation Pair Factory.

Checking Whether an Address was created by the Factory

You can check whether an address is a Liquidation Pair created by the factory using the deployedPairs(address pair) function on the Liquidation Pair Factory. It returns true if the given address is a Liquidation Pair created by the factory.

Compute the Available Liquidity

The Liquidation Pair will have a limited amount of yield available.

Compute how much yield is available using the maxAmountOut() function on the Liquidation Pair. This function returns the maximum number of tokens you can swap out.

You could also check the profitability of a swap by calling the Liquidation Router's swapExactAmountOut() statically (no state change), and get the return value.

Note: swapExactAmountOut() exists on both the LiquidationPair contracts and the LiquidationRouter, however for your swaps to be successful you will need to run it on the LiquidationRouter.

Execute a Swap

If a swap is profitable, then you can execute the swap using the Liquidation Router. The Router provides only swapExactAmountOut() which allows the caller to define the expected number of output tokens.

Reference Implementation

To see code examples, a reference implementation of an arbitrage bot created by Generation Software is available on GitHub: