Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research Thorchain #20

Closed
Kirqkas opened this issue Jan 9, 2025 · 2 comments
Closed

Research Thorchain #20

Kirqkas opened this issue Jan 9, 2025 · 2 comments
Assignees

Comments

@Kirqkas
Copy link
Collaborator

Kirqkas commented Jan 9, 2025

No description provided.

@radkomih radkomih assigned radkomih and Mihail-Genchev and unassigned radkomih Jan 9, 2025
@Mihail-Genchev
Copy link
Collaborator

THORChain Research

THORChain does not have a TESTNET.

THORChain relies on two main APIs:

  • Midgard – provides indexed blockchain data and analytics.
  • Thornode – communicates directly with THORChain nodes.

Additionally, there is an xchainJS library that abstracts away THORChain and individual blockchain complexities, offering an easy-to-use API for developers.


Packages Overview

1. Thorchain-query

Responsible for retrieving THORChain-related information and performing various estimates.

Examples:

  • Provides swap estimation (slip, fees, outputs, etc.)
  • Validates swap inputs
  • Offers inbound vault addresses
  • Advises if swaps are possible or not

2. Thorchain-amm

Facilitates actions such as swaps, adding and removing liquidity. It wraps xchainJS clients and streamlines operations on THORChain.


Chain Clients

These clients handle specific blockchains:

  • avax
  • bitcoin
  • bitcoincash
  • cosmos
  • doge
  • ethereum
  • litecoin
  • mayachain
  • thorchain

DO SINGLE SWAP PROCESS FLOW in xchainJS

Needed input: amount, decimals, fromAsset,toAsset, toChain

  1. Construct swap params

swapParams: QuoteSwapParams = {
fromAsset,
amount,
destinationAddress,
toleranceBps: 1000 // optional.
}

  1. Check if it can swap.
    estimateSwap(swapParams)

    1. ValidateSwap()
      1.1 check destination Address is valid.
      1.2 Check if it is a swap from non trade asset or non Rune asset to trade asset (Invariant)
      1.3 Check if it is a swap from trade asset to non trade asset or non Rune asset. (Invariant)
      1.4 Check if affiliateAddress is valid THOR address. (if affiliateAddress provided)
      1.5 Check affiliateBps (if provided)
      1.6 Check streamingInterval (if it is a streaming swap)
      1.7 Check streamingQuantity (if it is a streaming swap)
      1.8 Check if fromAsset is ERC20, check if router is approved to spend.
    2. Make estimate via thorchainQuery.quoteSwap()
      2.1 Validate Amount
      2.2 Fetch quote
      2.3 Parses quote
  2. IF canSwap == true, do the swap:
    doSwap(swapParams)

    1. call thorchainQuery.quoteSwap(), to get txDetails
    2. execute swap using THORChain action
    3. ThorchainAction.makeAction({wallet: this.wallet, assetAmount, memo, recipient})
  3. Sending of tx to the source asset network. (Stepping inside 3.3)
    makeAction(actionParams)

    1. Non EVM case
      1. Check if protocol is BFT chain:

        • wallet.transfer({
          asset,
          amount,
          recipient,
          memo,

        })

        • return hash of tx
      2. If not, get feeRates ( wallet.getFeeRates() )

      3. wallet.transfer({
        asset,
        amount,
        recipient,
        memo,
        feeRate
        })

      4. return hash of tx

    2. EVM case
      1. get inboundDetails by thorchainQuery
      2. check if is ERC20 , if it is check summed contract address
      3. calculate expiration
      4. construct deposit params [recipient, checkSummedContractAddress, assetAmount, memo, expiration]
      5. construct unsignedTX
      6. call wallet.transfer({
        asset,
        amount,
        recipient: router address,
        gasPrice,
        isMemoEncoded: true,
        gasLimit,
        })
      7. return hash of tx

@RaghavSood
Copy link
Collaborator

The existing apps use the ninerealms API to access thorchain data: https://github.com/vultisig/vultisig-android/blob/7af83f1f3a180989a4dc2d898ad703b600dae175/data/src/main/kotlin/com/vultisig/wallet/data/api/ThorChainApi.kt

Might be easier to continue with that for consistency with the existing flow as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants