@swapkit/chainflip

Plugin implementing Chainflip support for broker and swap execution

Getting started

Installation

<pnpm|bun> add @swapkit/chainflip

Integration

Implementation with @swapkit/core

import { SwapKit } from '@swapkit/core'
import { ChainflipPlugin } from '@swapkit/chainflip'
import { keystoreWallet } from '@swapkit/wallet-keystore'

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

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

Methods

swap(params: GenericSwapParams): Promise<string>

Swaps assets over cross-chain Chainflip network. Used in combination of deposit address generated from ChainflipBroker

const params = {
  sellAsset: AssetValue.fromChainOrSignature(Chain.Ethereum),
  buyAsset: AssetValue.fromChainOrSignature(Chain.Bitcoin),
  recipientAddress, // generated deposit address from ChainflipBroker
}

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

ChainflipBroker

Usage

Used with ChainflipToolbox. Returns all necessary methods to implement your own chainflip broker that deliveres requests like deposit addresses

import { ChainflipBroker } from '@swapkit/chainflip'
import { ChainflipToolbox } from '@swapkit/toolbox-substrate'

...

registerAsBroker(address: string): Promise<string>


requestSwapDepositAddress(params: GenericSwapParams & { brokerCommissionBPS: number }): Promise<SwapDepositResponse>


fundStateChainAccount(chainAccount: string, amount: AssetValue, evmToolbox: EVMToolbox)): Promise<string>


withdrawFee(params: { feeAsset: AssetValue; recipient: string }): Promise<WithdrawFeeResponse>

Types

SwapDepositResponse

type SwapDepositResponse = {
  depositChannelId: string;
  depositAddress: string;
  srcChainExpiryBlock: number;
  sellAsset: AssetValue;
  buyAsset: AssetValue;
  recipient: string;
  brokerCommissionBPS: number;
};

WithdrawFeeResponse

type WithdrawFeeResponse = {
  egressId: string;
  egressAsset: string;
  egressAmount: string;
  egressFee: string;
  destinationAddress: string;
};

Last updated