Thorchain Query

ThorchainQuery

THORChain Class for interacting with THORChain. Recommended main class to use for swapping with THORChain Has access to Midgard and THORNode data

Parameters

  • thorchainCache an instance of the ThorchainCache (could be pointing to stagenet,testnet,mainnet) (optional, default defaultCache)
  • chainAttributes atrributes used to calculate waitTime & conf counting (optional, default chain_defaults_1.DefaultChainAttributes)

estimateSwap

Provides a swap estimate for the given swap detail. Will check the params for errors before trying to get the estimate. Uses current pool data, works out inbound and outboud fee, affiliate fees and works out the expected wait time for the swap (in and out)

Parameters

  • params Object amount to swap
    • params.input
    • params.destinationAsset
    • params.destinationAddress
    • params.affiliateAddress (optional, default '')
    • params.interfaceID (optional, default 999)
    • params.affiliateFeePercent (optional, default 0)
    • params.slipLimit

Returns any The SwapEstimate

isValidSwap

Basic Checks for swap information

Parameters

  • params

calcSwapEstimate

Does the calculations for the swap. Used by estimateSwap

Parameters

  • params
  • sourceInboundDetails
  • destinationInboundDetails
  • sourcePool
  • destinationPool

constructSwapMemo

Parameters

  • params swap object

Returns any constructed memo string

getSwapEstimateErrors

Looks for errors or issues within swap prams before doing the swap.

Parameters

  • params
  • estimate
  • sourceInboundDetails
  • destinationInboundDetails
  • sourcePool
  • destinationPool

checkCoverFees

Parameters

  • params
  • estimate

getFeesIn

Convenience method to convert TotalFees to a different CryptoAmount

TotalFees are always calculated and returned in RUNE, this method can be used to show the equivalent fees in another Asset Type

Parameters

  • fees : TotalFees - the fees you want to convert
  • asset : Asset - the asset you want the fees converted to

Returns any TotalFees in asset

convert

Returns the exchange of a CryptoAmount to a different Asset

Ex. convert(input:100 BUSD, outAsset: BTC) -> 0.0001234 BTC

Parameters

  • input amount/asset to convert to outAsset
  • outAsset
  • ouAsset the Asset you want to convert to

Returns any CryptoAmount of input

confCounting

Finds the required confCount required for an inbound or outbound Tx to THORChain. Estimate based on Midgard data only.

Finds the gas asset of the given asset (e.g. BUSD is on BNB), finds the value of asset in Gas Asset then finds the required confirmation count. ConfCount is then times by 6 seconds.

Parameters

  • inbound : CryptoAmount - amount/asset of the outbound amount.

Returns any time in seconds before a Tx is confirmed by THORChain

outboundDelay

Works out how long an outbound Tx will be held by THORChain before sending.

Parameters

  • outboundAmount : CryptoAmount being sent.

Returns any required delay in seconds

checkTx

For a given in Tx Hash (as returned by THORChainAMM.DoSwap()), finds the status of any THORChain transaction This function should be polled.

Parameters

  • inboundTxHash needed to determine transactions stage
  • sourceChain extra parameter

Returns any object tx status

checkTxDefined

Stage 1

Parameters

  • txStatus
  • sourceChain

checkObservedOnly

Stage 2, THORNode has seen it. See if observed only (conf counting) or it has been processed by THORChain

Parameters

  • txStatus
  • scheduledQueueItem
  • observed_tx
  • sourceChain

checkOutboundQueue

Stage 3

Parameters

  • txStatus
  • scheduledQueueItem
  • lastBlockHeight
  • txData
  • scheduledQueue

checkOutboundTx

Stage 4

Parameters

  • txStatus
  • scheduledQueueItem
  • lastBlockHeight

estimateAddLP

Estimates a liquidity position for given crypto amount value, both asymmetrical and symetrical

Parameters

  • params parameters needed for a estimated liquidity position

Returns any type object EstimateLP

checkLiquidityPosition

Parameters

  • asset
  • assetOrRuneAddress
  • null-null Asset for lp
  • address address used for Lp

Returns any Type Object liquidityPosition

getPoolRatios

Do not send assetNativeRune, There is no pool for it.

Parameters

  • asset asset required to find the pool

Returns any object type ratios

estimateWithdrawLP

Parameters

  • params

getDustValues

// can this become a quried constant? added to inbound_addresses or something

Parameters

  • asset asset needed to retrieve dust values

Returns any object type dust values