Swapping between tokens is always a direct path from tokenIn to tokenOut, as compared to other AMMs where users have to be routed through multistep paths. Furthermore, since Singularity maintains collateralization ratios for each pool, users may be able to even earn positive slippage when the pool is favorable to trade through.
We can break down a swap from tokenA to tokenB into two parts, swapping in tokenA (1) and swapping out tokenB (2) where:
- S_i is the slippage for tokenA
- S_j is the slippage for tokenB
- r is the collateralization ratio before the swap
- r’ is the collateralization ratio after the swap
Since tokenA is now being sent to the pool, the pool’s assets increase by the number of tokenA tokens being swapped in (amountA) while liabilities stays the same. This means slippage through part 1 is always positive. It will never be negative slippage since the pool can only get “healthier”.
- First, the slippage formula is applied (above).
- After slippage is applied, the final amountA is converted into USD value (usdAmountA) based on the oracle’s feed.
Since tokenB is now being sent out of the pool, the pool’s assets decrease by the number of tokens being swapped out (amountB) while liabilities stays the same. This means slippage through part 2 is always negative. It will never be positive slippage since the pool can only get “unhealthier”.
- First, usdAmountA is converted into the corresponding amount of B tokens (amountB) based on the oracle’s feed.
- Next, the slippage formula is applied (above).
- Lastly, the trading fee is applied (above).
- After all fees are applied, the final amountB is sent to the user, completing the trade.
Let’s say Bob wants to swap 1000 USDC to ETH. For part 1, assume the USDC pool has the following parameters:
- Assets = 8000
- Liabilities = 10000
- Base fee = 0.015% (stablecoin)
- Oracle price: $1/USDC
First, the slippage formula is applied.
Second, the trading fees are applied. Since USDC is a stablecoin, the trading fee is the base fee (0.015%). You can see this outlined below, integrated into the formula.
Lastly, newAmountA is converted into the USD equivalent.
Assume the ETH pool has the following parameters:
- Assets = 10
- Liabilities = 11
- Base fee = 0.015% (non-stablecoin)
- Oracle price = $3000/ETH
- Last updated time = 30 seconds ago
First, amount_usd is converted to the ETH equivalent.
Second, the slippage formula is applied.
Third, the trading fees are applied.
The swap from USDC to ETH is now complete, with Bob receiving 0.33328 ETH ($999.83) with 0.04% slippage.