Kana Labs
  • Getting Started
    • Welcome to Kana Labs
  • CROSS CHAIN SWAPS
    • AMM DEX Aggregator
  • INTEGRATE KANA WIDGET
    • Kana Widget
      • Install Widget
      • Configure Widget
      • Configure Aptos Keyless
  • Web3 Aggregator SDK
    • Web3 Aggregator SDK
      • Installation
      • SameChain
      • Cross Chain Swap
      • Aggregator API's
  • SPOT TRADING PLATFORM
    • Kana Trade
      • API Docs
  • PERPETUAL FUTURES
    • Kana Perps
      • Getting Started
        • Mint Tokens on Testnet
      • Breaking Down Kana Perps
        • Assets Supported
        • Order Types
        • Orderbook
        • Funding Rate
        • Leverage
        • Margin and Liquidation
        • Hedge Mode
          • Hedging a Short-Term 2-3% Price Decline
          • Dual Positioning for Flexible Profit-Taking
        • Trading Fees
      • API Docs
        • Installation Setup
        • Kana Perps Typescript REST API
        • Kana Perps Python Websocket API
        • Kana Perps Python REST API
        • Steps to place an order
        • Perps Contract Error Codes
        • Websocket Connection
        • Supported Markets
  • SPOT & PERP APIs
    • Trading APIs
      • Kana Trade API
      • Kana Perps API
        • Installation Setup
        • Example setup functions
        • Kana Perps Typescript REST API
        • Kana Perps Websocket API
        • Kana Perps Python Websocket API
        • Kana Perps Python REST API
        • Steps to place an order
  • PAYMASTER SERVICE
    • Kana Paymaster For Aptos and Supra
      • How it works?
      • How to Register?
      • Deposit Allowance
      • Manage Users
      • Paymaster SDK Tutorial (Typescript)
      • Paymaster API
      • Module & Function Whitelist
      • Subscription - Coming soon
      • FAQS
  • PERPETUAL OPTIONS
    • OPerps
  • Tokenomics & Governance
    • Kana Labs Tokenomics
  • REWARDS & REFERRAL PROGRAM
    • Rewards Program
      • Reward Program Season 1
      • Reward Program Season 2
      • How to Keep Track of Your Points?
      • Where to find the Missions Dashboard?
  • Referral Program
    • How to Generate Referral Link? (For the Referrer)
    • How to map your wallet to the invite IDs? (For the invited users)
Powered by GitBook
On this page
  • 1. CrossChainQuote
  • 2. Execute Cross Chain Transfer
  • 3. Execute Cross Chain Claim
  • 1 . POLYGON TO BSC
  • 1.1 . Initialising SDK
  • 1.2 . Getting Cross Chain Swap Quote
  • 1.3 . Executing Transfer Instruction
  • 1.4 . Execute Claim Instruction
  • 1.5 . Redeeming tokens in case of failure
  • 2 . APTOS TO SUI
  • 2.1 . Initialising SDK
  • 2.2 . Getting Cross Chain Swap Quote
  • 2.3 . Executing Transfer Instruction
  • 2.4 . Execute Claim Instruction
  • 2.5 . Redeeming tokens in case of failure
  • 3 . SOLANA TO APTOS
  • 3.1 . Initialising SDK
  • 3.2 . Getting Cross Chain Swap Quote
  • 3.3 . Executing Transfer Instruction
  • 3.4 . Execute Claim Instruction
  • 3.5 . Redeeming tokens in case of failure
  1. Web3 Aggregator SDK
  2. Web3 Aggregator SDK

Cross Chain Swap

1. CrossChainQuote

crossChainQuote = async (params: CrossChainSwapParams)

CrossChainSwapParams

Description

sourceToken

The source token to be swapped.

targetToken

The target token to receive after the swap.

sourceChain

The source network ID or chain for the swap.

targetChain

The target network ID or chain for the swap.

amountIn

The amount of source tokens to be swapped.

sourceSlippage

The allowed slippage percentage on the source chain.

targetSlippage

The allowed slippage percentage on the target chain.

options

(Optional) An object containing additional options.

2. Execute Cross Chain Transfer

executeTransfer = async (params: ExecuteCrossChainTransferParams)

CrossChainTransferParams

Description

sourceProvider

RPC Provider for source chain

sourceSigner

Source chain signer

quote

selected cross chain swap quote

sourceAddress

source chain user address

targetAddress

Target chain user address

targetSigner

target chain signer.

targetProvider

Rpc provider for target chain.

3. Execute Cross Chain Claim

executeClaim = async (params: ExecuteCrossChainClaimParams)

CrossChainSwapParams

Description

txHash

Transaction hash of the tranfer transaction in source chain

sourceProvider

RPC Provider for source chain

targetProvider

Rpc provider for target chain.

targetSigner

target chain signer.

quote

selected cross chain swap quote

sourceAddress

source chain user address

targetAddress

Target chain user address

A CrossChain swap consists of three steps

  1. Getting Swap Quotes: This step involves obtaining quotes for the selected chains and tokens.

  1. Executing Transfer Instruction: In this phase, tokens are transferred across chains using a bridge to reach the selected destination chain.

  1. Executing Claim Instruction: After the tokens have been successfully bridged to the destination chain, this step allows users to claim their tokens. It's worth noting that bridges utilizing a relayer may not require this specific claim step.

What if the claim fails ?

In the event of a failure, users can redeem their tokens that were transferred via the bridge. Kanalabs exclusively transfers native stable coins / wrapped stable coins via the bridge. Therefore, users have the option to redeem their tokens and manually initiate the swap on the destination chain."

1 . POLYGON TO BSC

1.1 . Initialising SDK

const polygonRpc = process.env.ETH_NODE_URI_POLYGON as string;
const polygonProvider = ethers.getDefaultProvider(polygonRpc);
const polygonSigner = new ethers.Wallet(privateKey, polygonProvider);

const bscRpc = process.env.ETH_NODE_URI_BSC as string;
const bscProvider = ethers.getDefaultProvider(bscRpc);
const bscSigner = new ethers.Wallet(privateKey, bscProvider);

const crossChainAggregator = new SwapAggregator(Environment.production);

1.2 . Getting Cross Chain Swap Quote

const quotes = await crossChainAggregator.crossChainQuote({
  apiKey: APIKEY,
  sourceToken: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
  targetToken: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
  sourceChain: NetworkId.polygon,
  targetChain: NetworkId.bsc,
  amountIn: utils.parseUnits('0.01', 18).toString(),
  sourceSlippage: 0.1,
  targetSlippage: 0.1,
});

const optimalQuote = quotes.data[0];

1.3 . Executing Transfer Instruction

const transfer = await crossChainAggregator.executeTransfer({
  apiKey: APIKEY,
  quote: optimalQuote,
  sourceAddress: polygonSigner.getAddress() as string,
  targetAddress: bscSigner.getAddress() as string,
  sourceProvider: polygonProvider as providers.BaseProvider,
  sourceSigner: polygonSigner as EvmSignerType,
});

For Bridges using relayers there is no need to execute claim Instruction

1.4 . Execute Claim Instruction

const claim = await crossChainAggregator.executeClaim({
  apiKey: APIKEY,
  txHash: transfer.txHash,
  sourceProvider: polygonProvider as providers.BaseProvider,
  targetProvider: bscProvider as providers.BaseProvider,
  targetSigner: bscSigner as EvmSignerType,
  quote: optimalQuote,
  sourceAddress: polygonSigner.getAddress() as string,
  targetAddress: bscSigner.getAddress() as string,
});

1.5 . Redeeming tokens in case of failure

const redeem = await crossChainAggregator.redeem({
  apiKey: APIKEY,
  sourceChain: NetworkId.polygon,
  targetChain: NetworkId.bsc,
  sourceProvider: polygonProvider as providers.BaseProvider,
  targetProvider: bscProvider as providers.BaseProvider,
  targetSigner: bscSigner as EvmSignerType,
  SourceHash: transfer.txHash,
  targetAddress: bscSigner.getAddress() as string,
  BridgeId: BridgeId.wormhole,
});

2 . APTOS TO SUI

2.1 . Initialising SDK

const suiProvider = new JsonRpcProvider(new SuiConnection({ fullnode: 'SUI RPC 
const aptosConfig = new AptosConfig({ network: Network.MAINNET });
const aptosProvider = new Aptos(aptosConfig)

const suiSigner = new RawSigner(Ed25519Keypair.deriveKeypair(process.env.SUIMNEMONICS || ''), suiProvider);
const aptosSigner = Account.fromPrivateKey({
  privateKey: new Ed25519PrivateKey(process.env.APTOS_PRIVATEKEY || ''),
  address:  AccountAddress.from(process.env.APTOS_ADDRESS || ''),
  legacy: true,
});

const crossChainAggregator = new SwapAggregator(Environment.production);

2.2 . Getting Cross Chain Swap Quote

const crossChainQuotes = await crossChainAggregator.crossChainQuote({
  apiKey: APIKEY,
  sourceToken,
  targetToken,
  sourceChain: NetworkId.aptos,
  targetChain: NetworkId.sui,
  amountIn: '100000',
  sourceSlippage: 0.1,
  targetSlippage: 0.1,
});
const optimalRoute = crossChainQuotes.data[0];

2.3 . Executing Transfer Instruction

const transfer = await crossChainAggregator.executeTransfer({
  apiKey: APIKEY,
  sourceProvider: aptosProvider,
  sourceAddress: aptosSigner.accountAddress.toString(),
  sourceSigner: aptosSigner,
  quote: optimalRoute,
  targetAddress: await suiSigner.getAddress(),
});

For Bridges using relayers there is no need to execute claim Instruction

2.4 . Execute Claim Instruction

const claim = await crossChainAggregator.executeClaim({
  apiKey: APIKEY,
  txHash: transfer.txHash,
  sourceProvider: aptosProvider,
  targetProvider: suiProvider,
  targetSigner: suiSigner,
  quote: optimalRoute,
  sourceAddress: aptosSigner.accountAddress.toString(),
  targetAddress: await suiSigner.getAddress(),
});

2.5 . Redeeming tokens in case of failure

const redeem = await crossChainAggregator.redeem({
  apiKey: APIKEY,
  sourceChain: NetworkId.aptos,
  targetChain: NetworkId.sui,
  sourceProvider: aptosProvider,
  targetProvider: suiProvider,
  targetSigner: suiSigner,
  SourceHash: transfer.txHash,
  targetAddress: await suiSigner.getAddress(),
  BridgeId: BridgeId.wormhole,
});

3 . SOLANA TO APTOS

3.1 . Initialising SDK

const solanaProvider = new Connection('SOLANA RPC NODE);
const solanaSigner = Keypair.fromSecretKey(bs58.decode(process.env.SOLANAPAYER || ''));
const aptosConfig = new AptosConfig({ network: Network.MAINNET });
const aptosProvider = new Aptos(aptosConfig)

const aptosSigner = Account.fromPrivateKey({
  privateKey: new Ed25519PrivateKey(process.env.APTOS_PRIVATEKEY || ''),
  address:  AccountAddress.from(process.env.APTOS_ADDRESS || ''),
  legacy: true,
});

const crossChainAggregator = new SwapAggregator(Environment.production);

3.2 . Getting Cross Chain Swap Quote

const crossChainQuotes = await crossChainAggregator.crossChainQuote({
  apiKey: APIKEY,
  'So11111111111111111111111111111111111111112',
  '0x1::aptos_coin::AptosCoin',
  sourceChain: NetworkId.solana,
  targetChain: NetworkId.aptos,
  amountIn: '100000',
  sourceSlippage: 0.5,
  targetSlippage: 0.1,
});
const optimalRoute = crossChainQuotes.data[0];

3.3 . Executing Transfer Instruction

const transfer = await crossChainAggregator.executeTransfer({
  apiKey: APIKEY,
  sourceProvider: solanaProvider,
  sourceAddress: solanaSigner.publicKey.toString(),
  sourceSigner: solanaSigner,
  quote: optimalRoute,
  targetAddress: aptosSigner.accountAddress.toString(),
});

For Bridges using relayers there is no need to execute claim Instruction

3.4 . Execute Claim Instruction

const claim = await crossChainAggregator.executeClaim({
  apiKey: APIKEY,
  txHash: transfer.txHash,
  sourceProvider: solanaProvider,
  targetProvider: aptosProvider,
  targetSigner: aptosSigner,
  quote: optimalRoute,
  sourceAddress: solanaSigner.publicKey.toString(),
  targetAddress: aptosSigner.accountAddress.toString(),
});

3.5 . Redeeming tokens in case of failure

const redeem = await crossChainAggregator.redeem({
  apiKey: APIKEY,
  sourceChain: NetworkId.solana,
  targetChain: NetworkId.aptos,
  sourceProvider: solanaProvider,
  targetProvider: aptosProvider,
  targetSigner: aptosSigner,
  SourceHash: transfer.txHash,
  targetAddress: aptosSigner.accountAddress.toString(),
  BridgeId: BridgeId.wormhole,
});
PreviousSameChainNextAggregator API's

Last updated 11 months ago