THORSwap SwapKit
Playground
  • ⚠️Updated documentation
  • 🏡Getting Started
    • ❓FAQ
    • Terms of Service
  • ⚡Powered by SwapKit
  • 💰Monetization / Earn Fees
  • 🤝Partnership
  • SwapKit SDK
    • 1️⃣1️⃣ Install SwapKit SDK
    • 2️⃣2️⃣ Set up the SDK
    • 3️⃣3️⃣ Request Route & Execute Swap
    • 📦Packages
      • @swapkit/api
      • @swapkit/core
      • @swapkit/helpers
      • @swapkit/sdk
      • @swapkit/tokens
      • @swapkit/chainflip
      • @swapkit/thorchain
    • 👛Wallets
      • @swapkit/wallet-coinbase
      • @swapkit/wallet-evm-extensions
      • @swapkit/wallet-keepkey
      • @swapkit/wallet-keplr
      • @swapkit/wallet-keystore
      • @swapkit/wallet-ledger
      • @swapkit/wallet-okx
      • @swapkit/wallet-trezor
      • @swapkit/wallet-wc
      • @swapkit/wallet-xdefi
    • 🧰Toolboxes
      • @swapkit/toolbox-cosmos
      • @swapkit/toolbox-evm
      • @swapkit/toolbox-substrate
      • @swapkit/toolbox-utxo
  • SwapKit API
    • API Reference
      • Gas API
      • Lending API
      • Liquidity API
      • Quote API
      • THORName API
      • Token API
      • Token List API
      • Tracker API
      • Aggregator API
      • Resource Worker API
      • Full API Reference
    • ⚙️SwapKit API
      • Requesting supported Chains
      • Requesting supported Providers
      • Requesting a Quote
      • Requesting a Gas Price
      • Requesting to Add Liquidity
      • Requesting to Withdraw Liquidity
      • Request a transactions status
      • Lookup a Thorname
    • Advanced - Integrating SwapKit API
  • References
    • ✨Smart Contracts
Powered by GitBook
On this page
  • Getting started
  • Installation
  • Integration
  • Methods
  • swap(params: GenericSwapParams | SwapWithRouteParams): string
  • addLiquidity(params: AddLiquidityParams) => Promise<{ runeTx: string | void; assetTx: string | void; }>
  • addLiquidityPart(params: AddLiquidityPartParams) => Promise<string>
  • deposit(params: CoreTxParams & { router?: string; }) => Promise<string>
  • loan(params: LoanParams) => Promise<string>
  • savings(params: SavingsParams) => Promise<string>
  • withdraw(params: WithdrawParasm) => Promise<string>
  • registerThorname(params: RegisterTHORNameParams): string
  • createLiquidity({ runeAssetValue: AssetValue; assetValue: AssetValue }) => Promise<{ runeTx: string; assetTx: string }>
  • nodeAction(params: NodeActionParams): Promise<string>
  • getInboundDataByChain(chain: Chain): Promise<InboundAddressesItem>
  • approveAssetValue(params: ApproveParams): Promise<string | true>
  • isAssetValueApproved(params: ApproveParams): Promise<boolean>
  • Types
  • AddLiquidityPartParams
  • AddLiquidityParams
  • ApproveParams
  • CoreTxParams
  • LoanParams
  • NodeActionParams
  • SwapWithRouteParams
  • SavingParams
  • SwapWithRouteParams
  • RegisterTHORNameParams
  • WithdrawParams

Was this helpful?

Edit on GitHub
  1. SwapKit SDK
  2. Packages

@swapkit/thorchain

Plugin implementing Thorchain support for swaps, liquidity providing, network deposits, bonds, node management, THORNames management and more

Getting started

Installation

<pnpm|bun> add @swapkit/thorchain

Integration

Implementation with @swapkit/core

import { SwapKit } from '@swapkit/core'
import { ThorchainPlugin } from '@swapkit/thorchain'
import { keystoreWallet } from '@swapkit/wallet-keystore'

const swapKitClient = SwapKit({
    wallets: { ...keystoreWallet },
    plugins: { ...ThorchainPlugin },
});

const txHash = await swapKitClient.swap({ pluginName: "thorchain", ...params })
// or
const txHash = await swapKitClient.thorchain.swap(params)

Methods

const { routes } = await SwapKitApi.getSwapQuote(...)

const txHash = await swapKitClient.thorchain.swap(routes[0])

Performs two transactions to deposit RUNE and asset to THORChain Liquidity Pool

import { AssetValue, Chain } from '@swapkit/helpers'

const runeAssetValue = AssetValue.fromChainOrSignature(Chain.THORChain, 100)
const btcAssetValue = AssetValue.fromChainOrSignature(Chain.Bitcoin, 0.01)

const {
 runeTx,
 assetTx,
} = swapKitClient.thorchain.addLiquidity({
  // runeAddr: used when can't connect both chain at once (use addLiquidityPart)
  runeAssetValue,
  assetValue: btcAssetValue,
  mode: "sym"
})

Performs transaction to deposit RUNE or asset to THORChain Liquidity Pool

import { AssetValue, Chain } from '@swapkit/helpers'

const runeAssetValue = AssetValue.fromChainOrSignature(Chain.THORChain, 100)
const btcAssetValue = AssetValue.fromChainOrSignature(Chain.Bitcoin, 0.01)
const runeAddress = swapKitClient.getAddress(Chain.THORChain)
const btcAddress = swapKitClient.getAddress(Chain.Bitcoin)

const runeTx = swapKitClient.thorchain.addLiquidityPart({ 
  address: btcAddress,
  assetValue: runeAssetValue
  poolAddress: btcAssetValue.toString()
  symmetric: true,
})

const btcTx = swapKitClient.thorchain.addLiquidityPart({ 
  address: runeAddress,
  assetValue: btcAssetValue
  poolAddress: btcAssetValue.toString()
  symmetric: true,
})

Performs deposit to THORChain pool transaction. Can use custom memo.

const depositTxHash = swapKitClient.thorchain.deposit({
  assetValue,
  recipient,
  memo: customDepositMemo, // Create LP Pool, do custom swap, deposit for memoless
})

Performs transaction to open or close loan.

const repayQuote = await SwapKitApi.getRepayQuote(...)

const txid = await swapkitClient.thorchain.loan({
    type: 'close',
    memo: repayQuote?.memo,
    assetValue: repayAsset.set(amount),
    minAmount: repayAsset.set(expectedAmount),
});

Performs transaction to deposit or withdraw provided asset from THORChain Savers

const btcAsset = AssetValue.fromChainOrSignature(Chain.Bitcoin, 1)

const saverVaultDepositTx = await swapkitClient.thorchain.savings({ 
    assetValue,
    type: 'add',
});

Performs transaction to register, extend THORName

const ethAddress = swapKitClient.thorchain.withdraw({
    assetValue: poolAsset,
    percent: "50",
    from: "sym",
    to: "rune",
})

Performs transaction to register, extend THORName

const txHash = swapKitClient.thorchain.registerThorname({
    assetValue: AssetValue.fromChainOrSignature(Chain.THORChain, amount),
    address, 
    owner, 
    name: "tnsNameToRegister", 
    chain: Chain.Bitcoin, // Chain to assign - only when already registered
})

Performs 2 transactions to create new THORChain Liquidity Pool

const { runeTx, assetTx } = await swapKitClient.thorchain.createLiquidity({
  runeAssetValue: runeAssetAmount,
  assetValue: poolAssetAmount,
});

Performs deposit to protocol with convenient method wrapping and structuring proper memo

const bondTxHash = await swapKitClient.nodeAction({
  type: "bond",
  assetValue: AssetValue.fromChainOrSignature(Chain.THORChain, 500_000)
})

Returns inbound info of given chain

const ethInboundInfo = await swapKitClient.getInboundDataByChain(Chain.Ethereum)

Performs approval transaction or returns true if given asset doesn't need approval

const txHash = await swapKitClient.approveAssetValue({
  assetValue: assetToApprove, 
  contractAddress
})

Checks if given asset needs approval. Additionally validates provided amount against approved contract spending.

const isAssetApproved = await swapKitClient.isAssetValueApproved({
  assetValue: assetToApprove, 
  contractAddress
})

Types

AddLiquidityPartParams

type AddLiquidityPartParams = {
  assetValue: AssetValue;
  address?: string;
  poolAddress: string;
  symmetric: boolean;
};

AddLiquidityParams

type AddLiquidityParams = {
  runeAssetValue: AssetValue;
  assetValue: AssetValue;
  isPendingSymmAsset?: boolean;
  runeAddr?: string;
  assetAddr?: string;
  mode?: "sym" | "rune" | "asset";
}

ApproveParams

type ApproveParams = {
  assetValue: AssetValue;
  contractAddress?: string;
};

CoreTxParams

type CoreTxParams = {
  assetValue: AssetValue;
  recipient: string;
  memo?: string;
  feeOptionKey?: FeeOption;
  feeRate?: number;
  data?: string;
  from?: string;
  expiration?: number;
};

LoanParams

 type LoanParams = {
  assetValue: AssetValue;
  memo?: string;
  minAmount: AssetValue;
  type: "open" | "close";
};

NodeActionParams

type NodeActionParams = { address: string } & (
  | { type: "bond" | "unbond"; assetValue: AssetValue }
  | { type: "leave"; assetValue?: undefined }
);

SwapWithRouteParams

type SwapWithRouteParams = {
  recipient: string;
  route: QuoteRoute | QuoteRouteV2;
  feeOptionKey?: FeeOption;
  quoteId?: string;
  streamSwap?: boolean;
}

SavingParams

type SavingsParams = { assetValue: AssetValue; memo?: string } & (
  | { type: "add"; percent?: undefined }
  | { type: "withdraw"; percent: number }
);

SwapWithRouteParams

type SwapWithRouteParams = {
  recipient: string;
  route: QuoteRoute | QuoteRouteV2;
  feeOptionKey?: FeeOption;
  quoteId?: string;
  streamSwap?: boolean;
}

RegisterTHORNameParams

type RegisterTHORNameParams = {
  assetValue: AssetValue
  name: string;
  chain: string;
  address: string;
  owner?: string;
  preferredAsset?: string;
  expiryBlock?: string;
};

WithdrawParams

type WithdrawParams = {
  assetValue: AssetValue;
  from: "sym" | "rune" | "asset";
  memo?: string;
  percent: number;
  to: "sym" | "rune" | "asset";
};

Previous@swapkit/chainflipNextWallets

Last updated 1 year ago

Was this helpful?

swap(params: | ): string

Swaps assets over cross-chain Thorchain network. Used with routes returned from

addLiquidity(params: ) => Promise<{ runeTx: string | void; assetTx: string | void; }>

addLiquidityPart(params: ) => Promise<string>

deposit(params: & { router?: string; }) => Promise<string>

loan(params: ) => Promise<string>

savings(params: ) => Promise<string>

withdraw(params: ) => Promise<string>

registerThorname(params: ): string

createLiquidity({ runeAssetValue: ; assetValue: }) => Promise<{ runeTx: string; assetTx: string }>

nodeAction(params: ): Promise<string>

getInboundDataByChain(chain: ): Promise<>

approveAssetValue(params: ): Promise<string | true>

isAssetValueApproved(params: ): Promise<boolean>

📦
AddLiquidityParams
AddLiquidityPartParams
CoreTxParams
LoanParams
SavingsParams
WithdrawParasm
RegisterTHORNameParams
NodeActionParams
ApproveParams
ApproveParams
SwapWithRouteParams
GenericSwapParams
AssetValue
AssetValue
Chain
SwapKitApi.getSwapQuote
InboundAddressesItem