Mean Finance


We've already explained how positions work, and how they create an intention to swap tokens. Now, all positions need to have their swaps executed. Since doing them separately would be very expensive in terms of gas, Mean Finance aggregates all positions in a pair that can be swapped together.
For instance, going back to our DAI/WETH pair example, all daily positions will be executed together. Regardless of whether they are from DAI to WETH or vice versa, they will all be executed in one transaction.
Now, let's assume this is the pair's situation:
  • Need to swap 100 DAI in total for WETH
  • Need to swap 300 WETH in total for DAI
  • Oracle says 1 DAI = 1 WETH
We can see that the pair needs 200 DAI, and it has 200 extra WETH. We will ask that whoever executes the swap, provides the missing DAI, and in return we will reward them with the extra WETH.


As we said before, positions are not executed by their owners. Instead, they are executed by market makers or "swappers".
These swappers have two roles:
  • Execute swaps
  • Provide liquidity needed for those swaps


In order to encourage swappers to provide the needed liquidity and spend gas in executing swaps, we've come up with the following incentives:
  1. 1.
    Since the Mean Finance pairs use Uniswap V3's TWAPs, there is a potential arbitrage opportunity against Uniswap V3 pools' current prices, or other DEXes
  2. 2.
    When executing the swap, we will send the reward (in the previous example it was 200 WETH) optimistically, similarly to flash swaps
  3. 3.
    We will also allow swappers to borrow the pair's entire liquidity during the swap, for free, similarly to flash loans
  4. 4.
    We will share a portion of the swap's protocol fees with the swapper. In particular, we will require that they return 99.4% of the needed tokens. For instance in the previous example, instead of sending 200 DAI, they would need to send only 198.8 DAI. That way, they would get 200 WETH for 198.8 DAI.


Let's see how all incentives would work in action. Let's assume that:
  • There are 3000 DAI on the pair
  • There are 1000 WETH on the pair
  • Swap to execute looks like this:
    • Need to swap 100 DAI in total for WETH
    • Need to swap 300 WETH in total for DAI
    • Oracle says 1 DAI = 1 WETH
So, assuming that the swapper asks for 1000 DAI as loan, when the swap is executed:
  • The pair will send 1000 DAI to the swapper
  • The pair will send 200 WETH to the swapper
  • The pair will call whatever contract the swapper specifies
  • The pair will expect to have 1198.8 DAI returned
    • The borrowed 1000 DAI + the 198.8 DAI, in exchange for the 200 WETH
  • The pair will send to the protocol treasury:
    • 0.6 DAI
    • 0.6 WETH

Changes in balances

+ 198.2
- 198.8
+ 0.6
- 200.6
+ 200
+ 0.6
Last modified 3mo ago