Introducing Streaming Swaps

Nine Realms
THORChain
Published in
5 min readJul 26, 2023

A new type of swap has been activated on THORChain — Streaming Swaps allowing patient swappers to get better price execution by splitting large transactions into sub-swaps.

Swappers will now have the choice between time-optimized or price-optimized swaps.

Documentation | Developer Documentation | ADR-010 | Explainer Video

What are Streaming Swaps?

Streaming Swaps break up one swap into multiple sub-swaps executed over a period of time.

Streaming swaps are similar to a Time Weighted Average Price (TWAP) trade, limited to a 24 hour period.

A user (or interface) can specify two additional parameters to make adjustments to the sub-swaps taking place across the time dimension:

1) Swap Interval — how much time to wait between sub-swaps
2) Swap Count — how many sub-swaps should be executed

Swap Interval

Specified in THORChain blocks, which are approximately 6 seconds. By allowing enough time for arbitrage between sub-swaps, pools can be constantly re-balanced. This allows capital demands to be met throughout, instead of after a swap.

Swap Count

A user or interface can specify how many sub-swaps the original swap amount should be broken in to. The more sub-swaps are performed, the smaller the swap size of each leg, minimizing slippage for each-sub swap.

If swap count is set to “0”, THORChain will automatically maximize the swap size to achieve the lowest liquidity fee allowed (5bps)

How does it work?

Streaming swaps work because they allow swappers access to the time domain when they swap. Previously, a swapper could only place a single swap in a moment of time, and all the liquidity needs of that swap had to be met in that moment. Arbitrage would restore the liquidity after the swap. With the ability to stream, the liquidity needs of the swap can be expanded across many moments, allowing arbitrage to “correct” the price during the swap. This leads to far better price execution.

THORChain can do this because it is a live state machine — it can persist state across time and act on it. This is in contrast with an EVM ledger, where the entire state change has to be done in a single block — trying to persist state across many blocks and act on it requires external input. With streaming swaps, THORChain is playing to its strengths.

Another way to think about streaming swaps is that they expand THORChain’s capital efficiency with no change to TVL. A streaming swap with a count of 10 makes the sub-swap/pool ratio 10 times better than the single large swap — the pool appears 10 times larger. A streaming swap with a count of 100 makes the pool appear 100 times larger.

Indeed, assuming a healthy market of arbitrage, with the BTC pool $20m deep and the ETH pool $10m deep, a single BTC<>ETH stream can be as large as $42m and still theoretically achieve a total of 5bps with price execution matched to 24hr volatility. (The swap would be streamed over 24hours in sub-swaps of $3k, 14400 times).

User Impact

Streaming swaps should make it more viable to execute larger trades on THORChain. Slip-based fees are an innovation that allows THORChain to protect itself from asset price manipulation, but are a point of friction to swappers that want to trade large amounts. As a result, the largest trades are pushed off THORChain and to centralized exchanges where they can pay the lowest fees.

With the move to streaming swaps, the largest swappers can pay as low as 5 basis points in liquidity fees to the protocol, making THORChain a much more attractive venue for the largest on-chain traders.

With streaming swaps, THORChain sets to achieve:

  • Swaps with real Layer 1 assets — including Bitcoin
  • Entirely transparent, on-chain, open source, & with no oracles or other 3rd party dependencies
  • With secured and highly liquid synthetic assets for faster finality
  • At the best price execution for almost any trade size

Protocol Impact

Presently, fees have surpassed block rewards, a testament to THORChain’s recent surge in activity. Streaming swaps might lead to an initial drop in protocol revenue due to liquidity fees being tied to slip. However, it’s anticipated that revenue will bounce back with greater volume in the long run. The introduction of streaming swaps is a strategic move to attract a larger demographic of users who typically trade over $100k. Securing this segment of the market is crucial for THORChain to become the leading swap route, surpassing CEX in terms of speed (a single on-chain tx), KYC procedures (none), and now, price execution.

As an example, a $1m 5BPS stream between ETH and BTC can be done in 33 minutes (333 * $3k swaps) — there is no way a new user can KYC on a CEX, deposit, do a $1m trade and withdraw in the first 33 minutes.

THORChain is capable of 5000 native transactions per block, which translates to 50 observed L1 transactions per 6 seconds (8 trades per second), or 720k swaps a day. Currently THORChain sees 1–2k L1 swaps a day, so the protocol can withstand a ~500x increase in L1 demand before needing a protocol update.

Price Protection Limits

THORChain’s price limit functionality is carried over to streaming swaps. If any sub-swap is below the specified price limit, that sub-swap will not be carried out, but the streaming swap will continue.

If there are failures, at the end of the streaming swap, the user will be sent two outbound transactions: One with the refunded assets from the failed sub-swaps and one with the successfully completed sub-swaps.

Price limits are entirely optional and a user may choose to trade without price limits to contain the risk of sub-swap failures

Additional Info

  • Streaming swaps are still subject to outbound delays, but the time used to complete all the sub-swaps also counts towards the outbound delay period.
  • Nodes can use mimir to set the minimum slippage fee that can be achieved using streaming swaps. To start, this will be set to 5 bps.
  • Streaming Swaps of Layer 1 assets (BTC, ETH, etc.) can only take place over a 24 hour period to maintain economic security
  • If a user specifies an interval/count that takes a streaming swap below 5 bps or longer than 24 hours, THORChain will reduce the sub-swap count to meet the minimum specifications.
  • Streaming Swaps of native THORChain assets can take place up to a period of 1 year. This includes RUNE, synthetic assets, and derived assets
Graphics courtesy of THORSwap

Community

To keep up to date, please monitor community channels, particularly Telegram and Twitter:

Website | Documentation | Twitter | Telegram Community | Telegram Alerts | Community Discord | Developer Discord | Explorer | Viewblock | Reddit | Github | Gitlab | Medium | Linktree | Thorcharts

--

--

Nine Realms
THORChain

Supporting the THORChain ecosystem through engineering, infrastructure, institutional liquidity, and integrations.