Under the Hood: Slippage Deep-dive 201

THORChain University
6 min readAug 10, 2023

--

With the advent of Streaming Swaps, let’s take a closer look at the fees and slippage when making a swap on THORChain. First, a recap on THORChain’s fees: there are inbound, outbound, affiliate and slippage fees. The first three are well-explained in our previous article. This article will deep-dive into the slippage component.

Part 1 — Continuous Liquidity Pool Slippage & Slip-Based Fees

The math behind THORChain’s Automated Market Maker (AMM) Continuous Liquidity Pools (CLP) is based on the Constant Product x*y=k design. (see official THORChain doc for reference: https://docs.thorchain.org/thorchain-finance/continuous-liquidity-pools)

In this design, when swappers make a swap via the LP, a [slippage] component is experienced as the swap travels the x*y=k curve. This slippage is inherent to the x*y=k design, and is the cost to pay for swappers to enjoy continuous available liquidity regardless of the price movement.

This slippage is not THORChain or node operators’ or even LP yield. Instead, it is the arbers who gain some of this slippage when they rebalance the pool. In other words, arbers are paid to bring information from external markets into THORChain.

THORChain will further levy a [slip-based fee], which is the yield that is shared between node operators and LPs. This fee is the component which is set to minimum 5 bps via Streaming Swaps. (1 bps — or bips — is equal to 0.01%)

The [slippage] and [slip-based fee] equations are as follows:

where:

x = inbound asset amount

X = inbound asset initial balance in the pool

Y = output asset initial balance in the pool

Example:

Let’s take an example of BTC @ $30,000 and RUNE @ $1 — a direct price conversion should give 30,000 RUNE for a 1 BTC swap.

Assuming the LP depth is 2000 BTC, the [slippage] is calculated to be 5 bps = 15 RUNE in this case.

Additionally, the [slip-based fee] is also calculated to be 5 bps = 15 RUNE.

Therefore, the actual output that the swapper receives is 30,000 — 15 — 15 = 29,970 RUNE; or 10 bps (30 RUNE) away from direct price conversion.

In the context of an actual Streaming Swap, where the sub-swaps are executed over a period of time, there is an additional market price movement component; as well as the efficiency of arbers to rebalance the pool while the Streaming Swap is on-going.

In the end, it is the combination of [x*y=k slippage] + the 5 bps [slip-based fee] + market price movement + efficiency of arbers which determines the actual price execution of a Streaming Swap. A real on-chain example is THORChain Treasury’s recent $756k BUSD to USDC Streaming Swap where final “total slippage” was around 1%: https://twitter.com/THORChain/status/1685076441409724416

Part 2 — Central Limit Order Book (CLOB)

We will now contrast THORChain’s fees & slippage against that of a Central Limit Order Book (CLOB) design. Most Centralized Exchanges (CEX) utilize a CLOB design. Here, there are makers who place limit orders, and takers who execute market orders. An example of an order book:

First, the “price” here is always the last executed price. For example, if the most recent transaction was at $7, then the CLOB will show the price as $7, even though the next swapper may not enjoy the same price, as we shall see later.

There is also the “spread”, which is the difference between the lowest price sell order vs the highest price buy order. In our example, the spread is $2 (8-6=2).

A swapper who insists on a specific price execution would need to place a limit order, and wait for an unknown period of time for takers to meet that price. For example, if a swapper wants to sell two units at $8, his sell order would be added to the CLOB, waiting for other parties willing to buy at that price:

On the other hand, a swapper who wants to execute a large market order may match against multiple limit orders at worsening price points (thus facing a kind of slippage). For example, let’s say another swapper wants to sell five units and does not have the patience to wait. So he executes a market sell, fulfilling the existing buy orders (one unit @ $6, three units at $5 and one unit at $4):

Even though the “price” was previously $7, this swapper only managed to sell for an average price of $5. And the new updated “price” of this CLOB is now $4 (i.e. the last transacted price).

Finally, the CEX itself would impose additional taker/maker fees, and eventually withdrawal fees when users decide to withdraw on-chain back to their own self-custodial wallets.

Hence,, in terms of total cost-to-use, it is not all that sound to compare THORChain directly to a CEX. It is probably more cogent to juxtapose solely THORChain’s Streaming Swaps feature to a market order on a CEX CLOB, as a limit order is not guaranteed to be fulfilled within a specific time period.

What is clear is that Streaming Swaps is a breakthrough development, offering much better potential price execution than before, while preserving the decentralized, permissionless and trust-minimized native cross-chain swaps that THORChain is known for.

Part 3 — THORSwap Swap UI

Now, let’s explore THORSwap’s Swap UI and understand how they show the fees and slippage. This is an example when trying to swap 50 BTC to ETH, using the “Price Optimized” (or Streaming Swaps) option:

Clicking on the “details” link next to “Network Fee” brings up the estimated inbound, outbound and affiliate (labeled as “Exchange”) fees:

Let’s now check the first screenshot again and look deeper at the “Minimum received after slippage”, which is showing 3.77% in this example:

This is a “minimum price limit” protection that you can change in the Setting (gear icon at the top right) -> Slippage Tolerance:

Changing the Slippage Tolerance to 0.5%, and now, the main swap screen shows the “Minimum received after slippage” to be 1.38%:

This 1.38% is neither just the [slippage] nor the [slip-based fee] we discussed in Part 1. Instead, it is the maximum “total slippage” allowed to protect you from excessive price movement.

For example, a BTC swap takes at least one BTC block confirmation before THORChain will register the swap instructions (maybe more, depending on inbound confirmation count requirements), and by then, prices could have shifted. Additionally, a large Streaming Swap may take up to 24 hours total duration, thus exposed to price movement during the whole duration.

So this 1.38% is Not what you Will definitely pay, but just the Max that you Might pay. If prices move beyond this limit during your swap execution, you will receive a refund instead (minus inbound, outbound and affiliate fees). For a Streaming Swap, it could be that some sub-swaps meet the limit, while some sub-swaps are beyond the limit. In this case, user will receive two outputs — a partial successful fulfillment as well as a partial refund.

The author acknowledges the helpful explanations from Leena on THORChain’s Developer Discord, which inspired this article.

Feel free to hop into the TC University Discord to chat about this, or any other THORChain questions that you may have.

Explore THORChain: Website, X, Telegram, Developer Discord.

Explore Maya Protocol, the first friendly fork of THORChain: Website, X, Discord, Telegram.

Decentralized, permissionless, non-custodial, trust-minimized, open-sourced, economic-secured, non-wrapped, native-to-native cross-chain swaps, savings and soon, lending!

--

--

THORChain University
THORChain University

Written by THORChain University

THORChain University aims to educate communtiy users on how to optimally engage with the @THORChain Network

No responses yet