Liquidity Pool Cache

LiquidityPoolCache

This class manages retrieving information from up to date Thorchain Liquidity Pools

Parameters

  • midgard an instance of the midgard API (could be pointing to stagenet,testnet,mainnet)
  • expirePoolCacheMillis how long should the pools be cached before expiry (optional, default 6000)

getExchangeRate

Gets the exchange rate of the from asset in terms on the to asset

Parameters

  • from
  • to
  • asset cannot be RUNE.

Returns any Promise

getPoolForAsset

Gets the Liquidity Pool for a given Asset

Parameters

  • asset cannot be RUNE, since Rune is the other side of each pool.

Returns any Promise

getPools

Get all the Liquidity Pools currently cached. if the cache is expired, the pools wioll be re-fetched from midgard

Returns any Promise<Record<string, LiquidityPool»

refereshPoolCache

Refreshes the Pool Cache

NOTE: do not call refereshPoolCache() directly, call getPools() instead which will refresh the cache if it's expired

getExpectedSwapOutput

Calcuate the expected slip, output & swapFee given the current pool depths

swapFee - the amount of asset lost according to slip calculations slip - the percent (0-1) of original amount lost to slipfees output - the amount of asset expected from the swap *

Parameters

  • inputAmount CryptoAmount amount to swap from
  • destinationAsset destimation Asset to swap to

Returns any SwapOutput - swap output object - output - fee - slip

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