Understanding THORChain: A Beginner's Guide

taek - Aug 23 - - Dev Community

Understanding THORChain: A Beginner's Guide

Welcome to this introductory guide on THORChain! In this article, i’ll explore THORChain at a code level, focusing on its fundamental concepts, functionalities, and key components. My goal is to understand and explain THORChain through hands-on research and practical insights.

Understanding THORChain: A Beginner's Guide

Table of Contents

  1. Introduction

    • Purpose of This Guide
    • Who This Guide Is For
  2. What is THORChain?

    • Overview
    • Key Features
  3. What is RUNE?

    • Roles and Functions
  4. How Swapping Works

    • Step-by-Step Swap Process
    • Internal Mechanics
  5. Services Offered by THORChain

    • Swapping
    • Savings
    • Lending
    • Liquidity Pools (LPs)
  6. Roles and Participants

    • Liquidity Providers
    • Swappers
    • Traders
    • Node Operators
  7. Liquidity Providers

    • Handling Blocks with No Swap Fees
    • Source of Rewards without Swap Transactions
    • Sustainability of the Network Reserve
    • Typical Ratios and Average Rewards
  8. Swappers

    • Purpose of the Swap Formula
    • Derivation and Explanation of the Formula
  9. Traders

    • Arbitrage Opportunities and Market Discrepancies
  10. Node Operators

    • Role and Function of THORNodes

Goal

The goal of this guide is to provide a comprehensive understanding of THORChain at a technical level. This includes:

  1. Understanding the Core Concepts: Read and comprehend THORChain's documentation to grasp its fundamental principles and functionality.
  2. Exploring Key Components: Dive into how THORChain facilitates cross-chain swaps, the role of RUNE, and the mechanics behind its services.
  3. Analyzing Swap Mechanics: Examine the formula used for asset swaps, its purpose, and the mathematical derivation behind it.
  4. Evaluating Network Operations: Assess the roles of liquidity providers, traders, and node operators, and understand how THORChain maintains liquidity and ensures fair trading.

By setting these goals, the guide aims to enhance your knowledge of THORChain, enabling you to better understand its operation and participate effectively in its ecosystem.

What is THORChain?

THORChain is a cross-chain decentralized protocol that enables native swaps between different blockchains. Operating as an independent Layer 1 cross-chain decentralized exchange (DEX), THORChain facilitates asset exchanges across various blockchains without requiring custody of the assets. It serves as the backend for many user interfaces, providing a decentralized exchange platform for diverse blockchain assets.

What is RUNE?

RUNE plays several critical roles in THORChain:

  • Settlement Asset: It is used to settle transactions and trades.
  • Network Security: RUNE is essential for maintaining the security of the network.
  • Governance: RUNE holders can participate in governance decisions.
  • Incentives: It provides rewards and incentives for liquidity providers and participants.

How Swapping Works

Here’s a brief overview of the asset swapping process on THORChain:

  1. Request: A user wants to swap BTC for ETH.
  2. Send: The user sends BTC to THORChain. The gas fees for inbound transactions are paid in RUNE, and outbound fees are in BTC.
  3. Receive: ETH is sent to the user from one of THORChain's vaults. Internally, the system uses the BTC:RUNE and RUNE:ETH pools for the swap. The inbound gas fee is paid in BTC, while the outbound fee is in ETH, meaning the user does not need to hold RUNE.

Services Offered

THORChain provides several key services:

  1. Swapping: Exchange assets across different blockchains.
  2. Savings: Deposit assets to earn interest.
  3. Lending: Over-collateralized lending in any native asset.
  4. Liquidity Pools (LPs): Provide liquidity to earn rewards.

Roles (Participants)

  1. Liquidity Providers: Supply assets to liquidity pools and earn rewards.
  2. Swappers: Users who exchange assets.
  3. Traders: Monitor pools and profit from arbitrage opportunities.
  4. Node Operators: Maintain the THORChain network and facilitate cross-chain swaps.

Liquidity Providers

Q: What happens when there is a block with no swap fees on THORChain?

A: A block with no swap fees occurs when there are no swap transactions. In this case, rewards are distributed based on the liquidity depth in each pool rather than swap fees.

Q: Where do the rewards come from if there are no swap transactions?

A: Rewards come from THORChain’s reserve if no swap transactions occur. The reserve ensures that liquidity providers are compensated even without collected swap fees.

Q: Is there a risk of the network reserve being depleted? How does THORChain ensure sustainability?

A: To prevent reserve depletion and ensure sustainability, THORChain uses dynamic fee adjustments, reserve replenishment through new RUNE issuance, transaction fees, and regular reserve evaluations.

Q: What is the typical ratio of blocks with swap fees to those without? What are the average rewards per block?

A: The ratio varies with network activity. For example, if 70% of 1,000 blocks have swap fees and 30% do not, rewards are based on the collected fees and reserve distributions, leading to an estimated average reward per block. This can vary depending on network conditions.

Swappers

Purpose and Derivation of the Swap Formula in THORChain

Purpose of the Formula

The formula ( y = \frac{xYX}{(x+X)^2} ) calculates the output asset ( y ) during a swap, aiming to minimize slippage. Slippage occurs when the trade price deviates due to the trade size relative to the available liquidity. This formula helps ensure large trades do not significantly alter the price, maintaining a fair trading price.

Derivation Process

  1. Basic Concept of Slippage and Liquidity Pools:

    • Slippage is the difference between the expected and actual trade price, which increases with lower liquidity.
    • Liquidity pools facilitate swaps at fair prices based on current asset balances.
  2. Traditional Constant Product Model:

    • In this model, the product ( XY = k ) remains constant. This can lead to significant slippage for large trades due to non-linear changes in the exchange rate.
  3. Adjusting for Reduced Slippage:

    • The formula adjusts the exchange ratio to account for current asset balances and swap amounts: [ y = \frac{xYX}{(x+X)^2} ]
    • As ( x ) increases, the impact on ( y ) becomes less drastic, reducing slippage.
  4. Explanation of the Formula:

    • The denominator ((x + X)^2) ensures that larger input amounts cause less drastic changes in the output amount ( y ), minimizing slippage and stabilizing the trade price.
  5. Outcome of the Derivation:

    • This formula offers a stable output amount for swaps, particularly for large transactions, by dynamically adjusting the exchange rate based on liquidity.

Traders

Traders exploit price discrepancies between THORChain and external markets. For instance, if the BTC:RUNE ratio is 20:1 on THORChain but 16:1 on external markets, RUNE may be undervalued on THORChain. Traders can buy cheap RUNE on THORChain and sell it at a profit elsewhere by swapping BTC into the pool and selling the RUNE on external markets.

Node Operators

THORNodes support the THORChain network, with an intended initial count of 120 nodes. Each node comprises multiple independent servers, all working together to create a cross-chain swapping network.


This guide provides a foundation for understanding THORChain, its functionalities, and the mechanisms behind its asset swapping processes. Stay tuned for more detailed explorations in future articles!

. .
Terabox Video Player