How to Use

Installation

yarn add @xchainjs/xchain-thorchain-amm

Peer Dependencies

You can visit the xchain-thorchain-amm package repository to get the updated peer dependencies by looking at the "peerDependencies" object in the "package.json" file.

Example

Swap from BNB -> RUNE

// Imports
import { AssetRuneNative, } from '@xchainjs/xchain-util'
import { assetAmount, assetFromString, assetToBase, Chain  } from '@xchainjs/xchain-util'
import { CryptoAmount, EstimateSwapParams, Wallet, Midgard, SwapEstimate, ThorchainAMM } from '@xchainjs/xchain-thorchain-amm'
import BigNumber from 'bignumber.js'

// Swap from BUSD to RUNE
const doSwap = async () => {
  let phrase = "phrase"
  const mainnetWallet = new Wallet(Network.Mainnet, phrase|| 'you forgot to set the phrase')
  const swapParams = {
    input: new CryptoAmount(assetToBase(assetAmount(1)), BUSD),
    destinationAsset: AssetRuneNative,
    destinationAddress: mainnetWallet.clients[Chain.THORChain].getAddress(),
    slipLimit: new BigNumber(0.03),
  }
  try {
    const outPutCanSwap = await thorchainQueryMainnet.estimateSwap(estimateSwapParams)
    print(outPutCanSwap)
    if (outPutCanSwap.txEstimate.canSwap) {
      const output = await mainetThorchainAmm.doSwap(mainnetWallet, estimateSwapParams)
      console.log(`Tx hash: ${output.hash},\n Tx url: ${output.url}\n WaitTime: ${output.waitTimeSeconds}`)
      expect(output).toBeTruthy()
    }
  } catch (error: any) {
    console.log(error.message)
  }
}

Last updated