🧟‍♀️

Wombat vs Curve

Feb 6, 2023

Introduction

Currently, most of AMMs such as Uniswap, Curve,.. Use Constant Product Market Maker ( CPMM - x*y=k) formulas. Furthermore, Curve has an invariant made for stableswaping algorithm.
The formula is listed below for Stableswap invariant for many tokens
notion image
 
For example, if n = 2 ( 2 tokens in pool), the formula becomes:
 
More details, Let’s assume that there is a pool:
Contains 2 tokens choose A=10. Total token reserves in the pool this 60 (D=60), the pool is balanced when the reserves = (30, 30). We have the graph that visualize the formula : https://www.desmos.com/calculator/q0fqrb5byj . The elements of the graph are defined as follows:
x-axis = price of token x
y-axis = price of token y
Equilibrium Line (Red): x+y = K ( K=60)
Uniswap or CPMM Invariant Line (Black): xy=3030=900
Curve or Stableswap Invariant Line (Blue)
 
notion image
 
Compare to CPMM’s invariant, Curve or stableswap’s invariant has better performance. It reaches the constant line sonner and overlaps with the line longer.

Wombat’s design

Following Womat’s whitepaper, to solve some issues that Curve faces, Wombat design a new Stableswap 2.0 algorithm to aim to:
  • Make the algorithm more gas efficient
  • Allow single-sided liquidity provision
  • Get rid of the same-liquidity constraint for assets in the same pool.
 
Wombat introduces a new algorithm that can achieve a similar result as Curve’s stableswap invariant but using coverage ratio:
notion image

Wombat vs Curve

 
  1. Find D
  • In Curve, solving with pool 2 token, is quite easy but with multiple tokens/pool, it becomes an nth-degree polynomial.
    • For example with n=4, the formula is defined:
=> We have 5th-degree polynomial:
=> With this polynomial, we only find approximate D by using Newton’s method with Complexity depends on Tolerance or total Iterations that we want to run ( normally complexity ~O(n) )
  • In Wombat, it’s simple to solve: . To find D, we only need O(1)
=> In theory, With this part, Wombat contracts will require less gas fee than Curve, because it requires less computation than Curve.
 
  1. Swap
In swapping, we get an example: we swap x2’ token 2 for x1’ token 1. This problem is going to require us to find the value x1’
 
  • Curve, we still assume n = 4 :
=>
Get
b =
c =
We have
 
  • Wombat, similar to Curve, we have:
=>
Get a = 1
b =
c =
We have
 
=> In theory, to get amount of exchange token in both Curve & Wombat has same complexity. We have code’s simulation: https://github.com/narutomanchester/wombat_curve/blob/main/get_exchange_amount.py
 
  1. Price Rate
 
notion image
 
Green line: Curve / Blue line: Wombat
With above graph, we can see price range/slippage of Womabt closer with CSMM than Curve
 
  1. Deposit/Withdraw
 
We will only check Deposit here in this report.
 
  • In Curve, the idea here is quite simple. Curve allows adding liquidity with a number of coins < total coins of the pool. For example: for pool 4 tokens, Curve allow us to add 1,2,3 token with no need to require 4
    • For the cases if we add less tokens than the total number of coins of the pool, we need to recalculate the invariant D. For example:
    • Before adding new liqudity, we have D0 with the current amount of list coins: amount_coins_0
    • After adding, we have temporary invariant D1 with the current new amount of list coins: amount_coins_1. Amount_coins_1 is defined as:
      • amount_coins_1[i] = amount_coins_0[i] + add_liq_token[i]
    • Then, we need to recalculate D and we have D2 by recalculating new amount_coins_2. basically, if we add liq with number_of_adding_coins < total_coins_in_pool, we will get more fee
      • amount_coins_2[i] = amount_coins_1[i] - abs(D1 * amount_coins_1[i] / D0) * BASE_FEE - amount_coins_1[i])
         
  • In Wombat, it not easy like Curve, more changeling problems, because Wombat use coverage ratio so to avoid arbitrage attack. Therefore, it’s a more complex solution and not natural as in Curve ( we need to recalculate r*, r[i], L[i], D, A[i])
    • Normally, the coverage ratio r[i] of token i is the health of the token i. The bigger r the better. But for the pool, to measure the health of the pool, we have a global equilibrium coverage ratio r*. It defined:
      •  
    • Then, we need to recalculate r*, r[i], L[i], D, A[i] by fomula:
      • Firstly, we call new_A_diff, new_L_diff is the change of asset and the liability ( new_A_diff > 0, new_L_diff > 0)
      • New global equilibrium coverage ratio is defined:
        • $newR^=\frac {newLdiff + \sum L_kr^} {newLdiff + \sum L_k}$
      • is defined:
      • We also need to recal r for each token (r[i]):
        • , with
      • Finally, recalculate A[i]:
        •  
⇒ With 2 above alogrithms, Curve’s deposit formula is quite easy ( easy to understand, easy to apply as well) with O(n) complexity (for deposit algorithm just require O(1) but find_D require O(n) ) , on the other hand Wombat’s formula is quite complex when applying also complexity is O(n) with this algorithm

Conclusion

Comparasion between 2 algorithms
With above explaintations, each of algorithms have advantages and draw back. Let’s make a table to compare:
notion image
⇒ With Wombat’s formula, we can have better performance, but with more complex algorithm, it require us for more testing.