THORChain Features
THORChain provides advanced DeFi features beyond simple swaps. SwapKit includes full support for these features through the THORChain plugin.
Prerequisites
Section titled “Prerequisites”To use THORChain features, you need:
- A connected wallet with RUNE
- SwapKit initialized with the THORChain plugin (included by default)
import { function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit, enum Chain
Chain, enum FeeOption
FeeOption } from '@swapkit/sdk';
const const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit = function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit();
// Connect wallet for THORChain
await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
ARB?: DerivationPathArray | undefined;
AVAX?: DerivationPathArray | undefined;
... 21 more ...;
TRX?: DerivationPathArray | undefined;
} | undefined) => Promise<boolean>
connectKeystore([enum Chain
Chain.function (enum member) Chain.THORChain = "THOR"
THORChain], 'your mnemonic phrase');
Liquidity Operations
Section titled “Liquidity Operations”THORChain uses an asymmetric liquidity model where you can provide single-sided or dual-sided liquidity.
Add Liquidity
Section titled “Add Liquidity”Symmetrical Liquidity (RUNE + Asset)
Section titled “Symmetrical Liquidity (RUNE + Asset)”import { class AssetValue
AssetValue } from '@swapkit/sdk';
// Add ETH/RUNE liquidity
const const runeAmount: AssetValue
runeAmount = class AssetValue
AssetValue.AssetValue.from<{
asset: "THOR.RUNE";
value: number;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
asset: "THOR.RUNE";
value: number;
} & AssetValueFromParams): AssetValue
from({ asset: "THOR.RUNE"
asset: 'THOR.RUNE', value: number
value: 100 });
const const ethAmount: AssetValue
ethAmount = class AssetValue
AssetValue.AssetValue.from<{
asset: "ETH.ETH";
value: number;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
asset: "ETH.ETH";
value: number;
} & AssetValueFromParams): AssetValue
from({ asset: "ETH.ETH"
asset: 'ETH.ETH', value: number
value: 0.5 });
const const result: any
result = await Cannot find name 'swapKit'.swapKit.thorchain.addLiquidity({
baseAssetValue: AssetValue
baseAssetValue: const runeAmount: AssetValue
runeAmount, // RUNE amount
assetValue: AssetValue
assetValue: const ethAmount: AssetValue
ethAmount, // Asset amount
baseAssetAddr: any
baseAssetAddr: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.THORChain),
assetAddr: any
assetAddr: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.Ethereum),
mode: string
mode: 'sym' // Symmetrical mode
});
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('RUNE tx:', const result: any
result.baseAssetTx);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('ETH tx:', const result: any
result.assetTx);
Asymmetrical Liquidity (Single-Sided)
Section titled “Asymmetrical Liquidity (Single-Sided)”// Add RUNE-only liquidity
const const runeOnly: any
runeOnly = await Cannot find name 'swapKit'.swapKit.thorchain.addLiquidity({
baseAssetValue: any
baseAssetValue: Cannot find name 'runeAmount'.runeAmount,
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'BTC.BTC', value: number
value: 0 }), // Required but can be 0
baseAssetAddr: any
baseAssetAddr: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.THORChain),
mode: string
mode: 'baseAsset' // Use 'baseAsset' for RUNE-only
});
// Add asset-only liquidity (e.g., BTC only)
const const btcAmount: any
btcAmount = Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'BTC.BTC', value: number
value: 0.1 });
const const btcOnly: any
btcOnly = await Cannot find name 'swapKit'.swapKit.thorchain.addLiquidity({
baseAssetValue: any
baseAssetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'THOR.RUNE', value: number
value: 0 }), // Required but can be 0
assetValue: any
assetValue: const btcAmount: any
btcAmount,
assetAddr: any
assetAddr: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.Bitcoin),
mode: string
mode: 'asset' // Use 'asset' for asset-only
});
Create New Liquidity Position
Section titled “Create New Liquidity Position”For creating a new liquidity position (bootstrapping a pool):
const const result: any
result = await Cannot find name 'swapKit'.swapKit.thorchain.createLiquidity({
baseAssetValue: any
baseAssetValue: Cannot find name 'runeAmount'.runeAmount, // RUNE amount
assetValue: any
assetValue: Cannot find name 'ethAmount'.ethAmount // Asset amount
});
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('RUNE tx:', const result: any
result.baseAssetTx);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Asset tx:', const result: any
result.assetTx);
Add Liquidity Part
Section titled “Add Liquidity Part”For more granular control, you can add liquidity parts separately:
const const poolAddress: "BTC.BTC"
poolAddress = 'BTC.BTC'; // Pool identifier
await Cannot find name 'swapKit'.swapKit.thorchain.addLiquidityPart({
assetValue: any
assetValue: Cannot find name 'btcAmount'.btcAmount,
poolAddress: string
poolAddress,
address: any
address: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.Bitcoin), // Optional: for symmetric deposits
symmetric: boolean
symmetric: true
});
Withdraw Liquidity
Section titled “Withdraw Liquidity”// Withdraw 50% of liquidity position
const const withdrawTx: any
withdrawTx = await Cannot find name 'swapKit'.swapKit.thorchain.withdraw({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'BTC.BTC', value: number
value: 0 }), // Pool identifier
percent: number
percent: 50, // Withdraw 50%
from: string
from: 'sym', // From position type: 'sym' | 'baseAsset' | 'asset'
to: string
to: 'sym' // To asset type: 'sym' | 'baseAsset' | 'asset'
});
// Withdraw asymmetric RUNE position to symmetric
const const runeToSym: any
runeToSym = await Cannot find name 'swapKit'.swapKit.thorchain.withdraw({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'ETH.ETH', value: number
value: 0 }),
percent: number
percent: 100, // Withdraw 100%
from: string
from: 'baseAsset', // From RUNE-only position
to: string
to: 'sym' // To both RUNE and ETH
});
// Withdraw to specific asset only
const const toAssetOnly: any
toAssetOnly = await Cannot find name 'swapKit'.swapKit.thorchain.withdraw({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'BTC.BTC', value: number
value: 0 }),
percent: number
percent: 25, // Withdraw 25%
from: string
from: 'sym', // From symmetric position
to: string
to: 'asset' // Receive BTC only
});
Check Liquidity Position
Section titled “Check Liquidity Position”import { const SwapKitApi: {
mayachainMidgard: {
getLiquidityPositionRaw: (address: string) => Promise<MemberDetailsMayachain>;
getNameDetails: (name: string) => Promise<THORNameDetails>;
getNamesByAddress: (address: string) => Promise<...>;
getNamesByOwner: (address: string) => Promise<...>;
getLiquidityPosition: (address: string) => Promise<...>;
};
... 14 more ...;
getChainflipDepositChannel(body: BrokerDepositChannelParams): Promise<...>;
}
SwapKitApi } from '@swapkit/helpers/api';
const const thorAddress: any
thorAddress = Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.THORChain);
const const position: {
[x: string]: string | AssetValue | SwapKitNumber;
asset: AssetValue;
assetPending: AssetValue;
assetRegisteredAddress: string;
assetWithdrawn: AssetValue;
dateFirstAdded: string;
dateLastAdded: string;
poolShare: SwapKitNumber;
}[]
position = await const SwapKitApi: {
mayachainMidgard: {
getLiquidityPositionRaw: (address: string) => Promise<MemberDetailsMayachain>;
getNameDetails: (name: string) => Promise<THORNameDetails>;
getNamesByAddress: (address: string) => Promise<...>;
getNamesByOwner: (address: string) => Promise<...>;
getLiquidityPosition: (address: string) => Promise<...>;
};
... 14 more ...;
getChainflipDepositChannel(body: BrokerDepositChannelParams): Promise<...>;
}
SwapKitApi.thorchainMidgard: {
getLiquidityPositionRaw: (address: string) => Promise<MemberDetailsThorchain>;
getNameDetails: (name: string) => Promise<THORNameDetails>;
getNamesByAddress: (address: string) => Promise<...>;
getNamesByOwner: (address: string) => Promise<...>;
getLiquidityPosition: (address: string) => Promise<...>;
}
thorchainMidgard.getLiquidityPosition: (address: string) => Promise<{
[x: string]: string | AssetValue | SwapKitNumber;
asset: AssetValue;
assetPending: AssetValue;
assetRegisteredAddress: string;
assetWithdrawn: AssetValue;
dateFirstAdded: string;
dateLastAdded: string;
poolShare: SwapKitNumber;
}[]>
getLiquidityPosition(const thorAddress: any
thorAddress);
// Position details
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Pools:', const position: {
[x: string]: string | AssetValue | SwapKitNumber;
asset: AssetValue;
assetPending: AssetValue;
assetRegisteredAddress: string;
assetWithdrawn: AssetValue;
dateFirstAdded: string;
dateLastAdded: string;
poolShare: SwapKitNumber;
}[]
position.Property 'pools' does not exist on type '{ [x: string]: string | AssetValue | SwapKitNumber; asset: AssetValue; assetPending: AssetValue; assetRegisteredAddress: string; assetWithdrawn: AssetValue; dateFirstAdded: string; dateLastAdded: string; poolShare: SwapKitNumber; }[]'.pools);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Total value USD:', const position: {
[x: string]: string | AssetValue | SwapKitNumber;
asset: AssetValue;
assetPending: AssetValue;
assetRegisteredAddress: string;
assetWithdrawn: AssetValue;
dateFirstAdded: string;
dateLastAdded: string;
poolShare: SwapKitNumber;
}[]
position.Property 'totalValueUSD' does not exist on type '{ [x: string]: string | AssetValue | SwapKitNumber; asset: AssetValue; assetPending: AssetValue; assetRegisteredAddress: string; assetWithdrawn: AssetValue; dateFirstAdded: string; dateLastAdded: string; poolShare: SwapKitNumber; }[]'.totalValueUSD);
THORNames
Section titled “THORNames”THORNames are human-readable aliases for wallet addresses across all supported chains.
Register THORName
Section titled “Register THORName”// Register a new THORName
const const thorname: "myname"
thorname = 'myname';
const const years: 1
years = 1; // Registration period
// Check availability
const const details: any
details = await Cannot find name 'SwapKitApi'.SwapKitApi.thorchainMidgard.getTHORNameDetails(const thorname: "myname"
thorname);
if (const details: any
details.owner) {
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('THORName already taken');
A 'return' statement can only be used within a function body.return;
}
// Calculate registration fee (1 RUNE per year + network fee)
const const registrationFee: any
registrationFee = Cannot find name 'AssetValue'.AssetValue.from({
asset: string
asset: 'THOR.RUNE',
value: number
value: const years: 1
years + 0.02 // 1 RUNE/year + ~0.02 network fee
});
// Register the name
const const registerTx: any
registerTx = await Cannot find name 'swapKit'.swapKit.thorchain.registerName({
assetValue: any
assetValue: const registrationFee: any
registrationFee,
name: string
name: const thorname: "myname"
thorname,
chain: string
chain: 'THOR', // Chain identifier for the THORName
address: any
address: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.THORChain),
owner: any
owner: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.THORChain), // Optional: different owner
preferredAsset: string
preferredAsset: 'ETH.ETH' // Optional: set preferred asset
});
Set Preferred Asset
Section titled “Set Preferred Asset”Configure which asset you want to receive when someone sends to your THORName:
// Set preferred asset to USDC
const const preferredAsset: any
preferredAsset = Cannot find name 'AssetValue'.AssetValue.from({
asset: string
asset: 'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
value: number
value: 0
});
const const setPreferredTx: any
setPreferredTx = await Cannot find name 'swapKit'.swapKit.thorchain.registerPreferredAsset({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValueCannot find name 'Chain'. Did you mean 'Chai'?.from({ chain: any
chain: Chain.THORChain }), // Min RUNE for tx
name: any
name: Cannot find name 'thorname'.thorname,
ownerAddress: any
ownerAddress: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.THORChain),
payoutAddress: any
payoutAddress: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.Ethereum) // Where to receive USDC
});
Update THORName Aliases
Section titled “Update THORName Aliases”Set addresses for different chains:
// Update Bitcoin address for THORName
const const updateBtcTx: any
updateBtcTx = await Cannot find name 'swapKit'.swapKit.thorchain.registerName({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValueCannot find name 'Chain'. Did you mean 'Chai'?.from({ chain: any
chain: Chain.THORChain }), // Min RUNE for tx
name: any
name: Cannot find name 'thorname'.thorname,
chain: string
chain: 'BTC', // Chain identifier
address: any
address: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.Bitcoin),
owner: any
owner: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.THORChain)
});
// Update multiple chains
const const chainMap: {
[x: number]: string;
}
chainMap = {
[Cannot find name 'Chain'. Did you mean 'Chai'?Chain.Ethereum]: 'ETH',
[Cannot find name 'Chain'. Did you mean 'Chai'?Chain.Bitcoin]: 'BTC',
[Cannot find name 'Chain'.Chain.BinanceSmartChain]: 'BSC'
};
for (const [const chain: string
chain, const chainId: string
chainId] of var Object: ObjectConstructor
Provides functionality common to all JavaScript objects.Object.ObjectConstructor.entries<string>(o: {
[s: string]: string;
} | ArrayLike<string>): [string, string][] (+1 overload)
Returns an array of key/values of the enumerable own properties of an objectentries(const chainMap: {
[x: number]: string;
}
chainMap)) {
await Cannot find name 'swapKit'.swapKit.thorchain.registerName({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValueCannot find name 'Chain'..from({ chain: any
chain: Chain.THORChain }),
name: any
name: Cannot find name 'thorname'.thorname,
chain: string
chain: const chainId: string
chainId,
address: any
address: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'..getAddress(const chain: string
chain as Chain),
owner: any
owner: Cannot find name 'swapKit'.swapKitCannot find name 'Chain'..getAddress(Chain.THORChain)
});
}
Lookup THORName
Section titled “Lookup THORName”const const thornameDetails: any
thornameDetails = await Cannot find name 'SwapKitApi'.SwapKitApi.thorchainMidgard.getTHORNameDetails('thorswap');
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Owner:', const thornameDetails: any
thornameDetails.owner);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Preferred asset:', const thornameDetails: any
thornameDetails.preferredAsset);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Aliases:', const thornameDetails: any
thornameDetails.aliases);
// Get specific chain address
const const ethAddress: any
ethAddress = const thornameDetails: any
thornameDetails.aliases.find(Parameter 'a' implicitly has an 'any' type.a => a: any
a.chain === 'ETH')?.address;
Node Operations
Section titled “Node Operations”For node operators, SwapKit provides bond management functions.
Bond RUNE
Section titled “Bond RUNE”import { enum MemoType
MemoType } from '@swapkit/sdk';
const const bondAmount: any
bondAmount = Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'THOR.RUNE', value: number
value: 100000 });
const const nodeAddress: "thor1abc..."
nodeAddress = 'thor1abc...'; // Your node address
const const bondTx: any
bondTx = await Cannot find name 'swapKit'.swapKit.thorchain.nodeAction({
type: MemoType
type: enum MemoType
MemoType.function (enum member) MemoType.BOND = "BOND"
BOND,
assetValue: any
assetValue: const bondAmount: any
bondAmount,
address: string
address: const nodeAddress: "thor1abc..."
nodeAddress
});
Unbond and Leave
Section titled “Unbond and Leave”// Unbond specific amount
const const unbondTx: any
unbondTx = await Cannot find name 'swapKit'.swapKit.thorchain.nodeAction({
type: any
type: Cannot find name 'MemoType'.MemoType.UNBOND,
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'THOR.RUNE', value: number
value: 50000 }),
address: any
address: Cannot find name 'nodeAddress'.nodeAddress
});
// Leave (unbond all)
const const leaveTx: any
leaveTx = await Cannot find name 'swapKit'.swapKit.thorchain.nodeAction({
type: any
type: Cannot find name 'MemoType'.MemoType.LEAVE,
address: any
address: Cannot find name 'nodeAddress'.nodeAddress
});
Direct Deposit
Section titled “Direct Deposit”For advanced users, deposit directly to THORChain with custom memos:
// Direct deposit with custom memo
const const customDeposit: any
customDeposit = await Cannot find name 'swapKit'.swapKit.thorchain.deposit({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'BTC.BTC', value: number
value: 0.1 }),
recipient: string
recipient: '', // Empty for THORChain protocol deposits
memo: string
memo: 'SWAP:ETH.ETH:thor1...' // Custom memo for any THORChain action
});
// Deposit to specific pool
const const poolDeposit: any
poolDeposit = await Cannot find name 'swapKit'.swapKit.thorchain.depositToPool({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'ETH.ETH', value: number
value: 1 }),
memo: string
memo: 'ADD:ETH.ETH:thor1...',
feeOptionKey: any
feeOptionKey: Cannot find name 'FeeOption'. Did you mean 'Option'?FeeOption.Fast // Optional: Average, Fast, or Fastest
});
// Protocol deposit (simplified)
const const protocolDeposit: any
protocolDeposit = await Cannot find name 'swapKit'.swapKit.thorchain.depositToProtocol({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({ asset: string
asset: 'THOR.RUNE', value: number
value: 10 }),
memo: string
memo: 'BOND:thor1nodeaddress...'
});
Token Approvals
Section titled “Token Approvals”For EVM chains, THORChain requires token approvals before deposits:
// Check if token is approved
const const isApproved: any
isApproved = await Cannot find name 'swapKit'.swapKit.thorchain.isAssetValueApproved({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({
asset: string
asset: 'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
value: number
value: 1000
})
});
if (!const isApproved: any
isApproved) {
// Approve token for THORChain router
const const approveTx: any
approveTx = await Cannot find name 'swapKit'.swapKit.thorchain.approveAssetValue({
assetValue: any
assetValue: Cannot find name 'AssetValue'.AssetValue.from({
asset: string
asset: 'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
value: number
value: 1000
})
});
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Approval tx:', const approveTx: any
approveTx);
}
Maya Protocol
Section titled “Maya Protocol”Maya is a fork of THORChain with similar features. SwapKit supports Maya through the Maya plugin:
// Maya operations use the same interface
// Check Maya positions
const const mayaPosition: any
mayaPosition = await Cannot find name 'SwapKitApi'.SwapKitApi.mayachainMidgard.getLiquidityPosition(
Cannot find name 'swapKit'.swapKitCannot find name 'Chain'. Did you mean 'Chai'?.getAddress(Chain.Maya)
);
Chain Information
Section titled “Chain Information”Get inbound addresses and gas rates for any supported chain:
// Get inbound data for a specific chain
const const btcInbound: any
btcInbound = await Cannot find name 'swapKit'.swapKit.thorchainCannot find name 'Chain'. Did you mean 'chains'?.getInboundDataByChain(Chain.Bitcoin);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('BTC vault address:', const btcInbound: any
btcInbound.address);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('BTC router:', const btcInbound: any
btcInbound.router);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Gas rate:', const btcInbound: any
btcInbound.gas_rate);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Chain halted:', const btcInbound: any
btcInbound.halted);
// Check multiple chains
const const chains: any[]
chains = [Cannot find name 'Chain'. Did you mean 'chains'?ChainCannot find name 'Chain'. Did you mean 'chains'?Cannot find name 'Chain'. Did you mean 'chains'?.Ethereum, Chain.Bitcoin, Chain.BinanceSmartChain];
for (const const chain: any
chain of const chains: any[]
chains) {
const const inbound: any
inbound = await Cannot find name 'swapKit'.swapKit.thorchain.getInboundDataByChain(const chain: any
chain);
if (const inbound: any
inbound.halted) {
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log(`${const chain: any
chain} is currently halted`);
}
}
Best Practices
Section titled “Best Practices”1. Check Pool Status
Section titled “1. Check Pool Status”Before adding liquidity or making swaps:
const const pools: any
pools = await Cannot find name 'SwapKitApi'.SwapKitApi.thorchainMidgard.getPools();
const const btcPool: any
btcPool = const pools: any
pools.find(Parameter 'p' implicitly has an 'any' type.p => p: any
p.asset === 'BTC.BTC');
if (const btcPool: any
btcPool?.status !== 'Available') {
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Pool not available');
A 'return' statement can only be used within a function body.return;
}
2. Calculate Slippage
Section titled “2. Calculate Slippage”For large liquidity operations:
const const quote: any
quote = await Cannot find name 'SwapKitApi'.SwapKitApi.getSwapQuote({
sellAsset: string
sellAsset: 'THOR.RUNE',
sellAmount: string
sellAmount: '1000000000000', // Large amount
buyAsset: string
buyAsset: 'BTC.BTC',
// ... other params
});
const const slippage: any
slippage = const quote: any
quote.routes[0].fees.slippage;
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log(`Slippage: ${const slippage: any
slippage}%`);
3. Monitor Transaction Status
Section titled “3. Monitor Transaction Status”Track THORChain transactions:
const const txStatus: any
txStatus = await Cannot find name 'SwapKitApi'.SwapKitApi.getTrackerDetails({
txHash: string
txHash: 'ABCD...',
chain: string
chain: 'THOR'
});
if (const txStatus: any
txStatus.status === 'completed') {
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Transaction successful');
}
API Reference Summary
Section titled “API Reference Summary”Here’s a complete list of THORChain plugin methods:
Core Methods
Section titled “Core Methods”deposit()
- Direct deposit with custom parametersdepositToPool()
- Deposit to specific pool with memodepositToProtocol()
- Simplified protocol deposits
Liquidity Methods
Section titled “Liquidity Methods”addLiquidity()
- Add symmetric or asymmetric liquidityaddLiquidityPart()
- Add liquidity with granular controlcreateLiquidity()
- Bootstrap new liquidity poolswithdraw()
- Withdraw liquidity positions
THORName Methods
Section titled “THORName Methods”registerName()
- Register or update THORNamesregisterPreferredAsset()
- Set preferred payout asset
Node Methods
Section titled “Node Methods”nodeAction()
- Bond, unbond, or leave as node operator
Token Methods (EVM)
Section titled “Token Methods (EVM)”approveAssetValue()
- Approve tokens for routerisAssetValueApproved()
- Check approval status
Utility Methods
Section titled “Utility Methods”getInboundDataByChain()
- Get vault addresses and gas ratesswap()
- Execute swaps (used internally by SwapKit)
Next Steps
Section titled “Next Steps”- Explore Cross-Chain Swaps using THORChain
- Learn about Transaction Tracking
- Read the THORChain Documentation