The Right Way of doing swaps in DEXes

Epsylon Finance
5 min readMar 15, 2022

--

We will explain the hidden cost of choosing the wrong DEX type for doing swaps. And what Epsylon does to mitigate it.

In a DEX, liquidity providers deposit their cryptocurrencies into liquidity pools. In return, they are rewarded with a share of the swap fees generated by the platform.

On Fantom we have the following main DEXes with their corresponding fees:

  • Curve 0.04%
  • Spooky Swap 0.2%
  • Spirit Swap 0.3%
  • Beethoven (variable fees) 0.1% stables
  • Solidly 0.01%

We can classify the previous DEXes according to their swap curve. Following these criteria, we can differentiate between Uniswap type (Spooky, Spirit and Solidly volatile pools) and Curve type (Curve) and Mixed DEXes, who use both curves depending on the pool (Balancer, Beethoven, Solidly).

A DEX curve is a representation of how liquidity is distributed among its reserves. In Uniswap it is exponential and in Curve, it is stable in the middle and exponential on the sides.

In the image below, we can appreciate the different model curves:

  • Uniswap → x*y = k
  • Curve (flat in the middle region) x + y = k
Graph 1: Curve vs Uniswap liquidity pool

We will set an example of swapping USDC — DAI on Uniswap and Curve to explain the differences.

Example: Uniswap vs Curve

Both pools are 50/50 balance in two stables USDC — DAI in units of currency. This means there are 50 units of USDC and 50 units of DAI each of them with $1 value. (To simplify, we won’t consider the impact of the swap fees).

50/50 balanced pool.

Jimmy and Ted are DeFi users who want DAI. They only have USDC. So they need to swap USDC for DAI. Jimmy decides to swap 25 units of USDC for DAI on Uniswap and Ted decides to swap the same amount on Curve.

Uniswap

Jimmy sells 25 units of USDC in Uniswap. In this case, Jimmy receives 16.7 DAI. By doing so, the pool gets unbalanced and the pool ends up in 75/33.3 balance USDC/DAI. Since the pool is no longer 50/50 the DAI is now $1.5 and the USDC $0.66.

The liquidity movement can be visualized in graph 2. The reserves on the pool move from 0 to point A.

Now, let’s go over the numbers really quick.

x * y = k

50 * 50 = 2500 = k

Jimmy Deposits 25 USDC into the pool, so now the pool has 75 USDC (50 USDC the pool had plus 25 from Jimmy).

x * y = k = 2500

(50 + 25) * y = 2500

y = 33.3 and Jimmy DAI swap → 50–33.3 = 16.7 DAI

Graph 2: Uniswap curve.

Simple visual explanation of what happened:

Uniswap Swap visualization.

Of course, this is an exaggeration for visualization purposes.

Curve

On the other hand, Ted sells 25 units of USDC on Curve, moving from 0 to point B. In this case, Joe receives 25 DAI (see formula below), and the pool will end in 75/25 balance USDC/DAI each of them with roundabout $1 value.

The liquidity movement can be visualized in graph 3. The reserves on the pool move from 0 to point B.

x + y = k

50 +50 = 100 = k

Ted Deposits 25 USDC in addition to the 50 USDC the pool has.

x + y = k = 100

(50 + 25) + y = 100

y = 25 and Jimmy DAI swap → 50–25 = 25 DAI

Graph 3: Curve curve.

Simple visual explanation of what happened:

Curve Swap visualization.

Conclusion

Jimmy chose Uniswap for his swap and got 16,7 DAI for his 25 USDC. As we all know, DAI is a stablecoin, so it is usually worth around 1$. Meaning the 16.7 DAI Jimmy got for his 25 USDC is worth 16.7$ in reality.

Jimmy by choosing the incorrect DEX took an $8.3 loss Because the global price of DAI is calculated using many exchanges, this swap will not impact DAI price and Joe’s DAI will be worth $16.7.

Ted, on the other hand, did a smart trade and got 25 DAI on Curve.

Why is this? This is because each DEX is used for different purposes. A curve-type pool is used for big stable swaps. You will have less slippage. For small swaps, it is also convenient as we have seen that the swap fees are lower.

For non-correlated assets, you need to use Uniswap (or Uniswap style AMM), since Curve swaps are not efficient with this type of asset. What makes Curve great for correlated assets, giving a more stable price even when the pools are unbalanced, prevents Curve from pricing correctly non-correlated assets.
Advice! When using Uniswap always check if the pool is balanced and if the price impact is not too high.

*Slippage refers to the difference between the expected price of a trade and the price at which the trade is executed.

How does Epsylon mitigate this issue?

We have several stable liquidity-providing strategies for different DEXes.

  • USDC-USDT in Spirit
  • USDC-MAI in Spooky
  • USDC-DAI in Beethoven
  • USDC-MIM in Solidex

In all of them, we make the swap in Curve or Solidly, reducing the slippage and the fees, thus the losses incurred by opening position are minimal.

We have a zap integrated inside the smart contract so the amounts swapped are the optimal ones. As the liquidity between stables generally needs to be provided 1:1, if we swap the 50% of USDC from the example above we receive 49850, so our amount invested will be 99.700, not 100.000. We need to swap slightly more of the 50% to not have any USDC left in the contract, after the fees.

In Epsylon we are capital efficient with the funds maximizing returns.

Always do your own research and be rigorous with the protocols where you invest.

Thanks for reading. And happy yield 🙂 👨🏻‍🌾

--

--

Responses (1)