npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cetusprotocol/cross-swap-sdk

v0.1.0

Published

SDK for cetus cross swap

Readme

Cetus CrossSwap SDK

A comprehensive TypeScript SDK for cross-chain bridging operations using multiple platforms including LiFi and Mayan. This SDK provides a unified interface for cross-chain token swaps across different blockchain networks.

Features

  • Multi-Platform Support: LiFi and Mayan integration
  • Multi-Chain Support: Sui, EVM chains (Polygon, Arbitrum, etc.), Solana, Bitcoin
  • Unified API: Single interface for different cross-chain platforms
  • Quote Estimation: Get detailed quotes before executing swaps
  • Balance Checking: Check token balances across chains

Installation

npm install @cetusprotocol/CrossSwap-sdk

Quick Start

Basic Setup

import { CetusCrossSwapSDK, CrossSwapPlatform } from '@cetusprotocol/CrossSwap-sdk'

// Create SDK instance
const sdk = CetusCrossSwapSDK.createSDK({ env: 'mainnet' })

Platform Configuration

The SDK supports two main platforms: LiFi and Mayan. Each platform has different configuration requirements.

LiFi Configuration

import { createWalletClient, http } from 'viem'
import { mnemonicToAccount } from 'viem/accounts'
import { polygon } from 'viem/chains'
import { KeypairWalletAdapter } from '@lifi/sdk'
import { Connection, Keypair } from '@solana/web3.js'
import { derivePath } from 'ed25519-hd-key'
import * as bip39 from 'bip39'
import bs58 from 'bs58'

// EVM Configuration
const evm_account = mnemonicToAccount(mnemonic)
const evm_client = createWalletClient({
  account: evm_account,
  chain: polygon,
  transport: http(),
})

// Solana Configuration
const seed = await bip39.mnemonicToSeed(solana_mnemonic)
const derivationPath = "m/44'/501'/0'/0'"
const derivedSeed = derivePath(derivationPath, seed.toString('hex')).key
const solana_keypair = Keypair.fromSeed(derivedSeed)
const privateKey = bs58.encode(solana_keypair.secretKey)

// Set LiFi configurations
sdk.setCrossSwapConfigs(CrossSwapPlatform.LI_FI, {
  evm: {
    wallet: evm_client,
  },
  solana: {
    wallet: new KeypairWalletAdapter(privateKey),
  },
  // Add other chain configurations as needed
})

Mayan Configuration

import { Wallet, JsonRpcProvider } from 'ethers'
import { Connection, Keypair } from '@solana/web3.js'
import { createSolanaSignerFromKeypair } from '@cetusprotocol/CrossSwap-sdk'

// EVM Configuration
const evm_signer = Wallet.fromPhrase(mnemonic, new JsonRpcProvider(rpcUrl))

// Solana Configuration
const solana_keypair = Keypair.fromSeed(derivedSeed)
const connection = new Connection(solana_chain.rpc_urls[0])
const signer = createSolanaSignerFromKeypair(solana_keypair)

// Set Mayan configurations
sdk.setCrossSwapConfigs(CrossSwapPlatform.MAYAN, {
  evm: {
    evm_signer: evm_signer,
  },
  solana: {
    signer: signer,
    connection: connection,
  },
})

Core Functionality

Getting Supported Chains and Tokens

// Get supported chains for a platform
const chains = sdk.getSupportedChains(CrossSwapPlatform.LI_FI)
console.log('Supported chains:', chains)

// Get supported tokens for specific chains
const tokenMap = await sdk.getSupportedTokens(CrossSwapPlatform.LI_FI, [ChainId.SOL_LI_FI])
console.log('Supported tokens:', tokenMap[ChainId.SOL_LI_FI])

// Get specific token information
const token = await sdk.getCrossSwapToken(
  CrossSwapPlatform.LI_FI,
  ChainId.SUI_LI_FI,
  '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
)

Estimating Quotes

import { ChainId } from '@cetusprotocol/CrossSwap-sdk'
import { toDecimalsAmount } from '@cetusprotocol/common-sdk'

// Estimate quote for cross-chain swap
const quote = await sdk.estimateQuote(CrossSwapPlatform.LI_FI, {
  amount: toDecimalsAmount('2', 9).toString(),
  from_token: '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI',
  to_token: '0x0000000000000000000000000000000000000000',
  from_chain_id: ChainId.SUI_LI_FI,
  to_chain_id: ChainId.POL,
  slippage: 0.05,
  lifi_configs: {
    from_address: 'your_sui_address',
    to_address: 'your_evm_address',
  },
})

console.log('Quote:', quote)

Executing Cross-Chain Swaps

LiFi Swaps

// Execute LiFi swap
const executedRoute = await sdk.executeSwapQuoteFromLiFi(
  {
    quote: quote.quotes[0],
    swap_wallet_address: 'your_sui_address',
    destination_address: 'your_evm_address',
  },
  {
    updateRouteHook(route) {
      console.log('Route updated:', route)
    },
  }
)

Mayan Swaps

// Build swap payload for Mayan
const payload = await sdk.buildCrossSwapResult({
  quote: quote.quotes[0],
  swap_wallet_address: 'your_sui_address',
  destination_address: 'your_evm_address',
})

// Execute the swap
if (payload.sui) {
  const result = await sdk.FullClient.executeTx(keypair, payload.sui, true)
  console.log('Swap executed:', result)
}

if (payload.evm) {
  console.log(`View transaction: https://explorer.mayan.finance/swap/${payload.evm.hash}`)
}

Checking Token Balances

// Get token balances for a wallet
const tokens = await sdk.getSupportedTokens(CrossSwapPlatform.MAYAN, [ChainId.SOL_MAYAN])
const balances = await sdk.getOwnerTokenBalances(
  CrossSwapPlatform.MAYAN,
  '3kTFG1MTm2VG4DHeNpqby7EkMqCWF2eeetxnKU9pG5x4',
  tokens[ChainId.SOL_MAYAN]
)
console.log('Token balances:', balances)

Supported Chains

LiFi Platform

  • EVM Chains: Ethereum, Polygon, Arbitrum, Optimism, BSC, Avalanche, and more
  • Solana: Native Solana support
  • Sui: Native Sui support
  • Bitcoin: BTC support

Mayan Platform

  • EVM Chains: Ethereum, Polygon, Arbitrum, Optimism, and more
  • Solana: Native Solana support
  • Sui: Native Sui support

Advanced Configuration

SDK Options

const sdk = CetusCrossSwapSDK.createSDK({
  env: 'mainnet',
  mayan: {
    referrer_addresses: {
      solana: 'your_solana_address',
      sui: 'your_sui_address',
      evm: 'your_evm_address',
    },
    referrer_bps: 30, // 0.3% referrer fee (max: 50 bps)
  },
  lifi: {
    integrator: 'your_integrator_id',
    api_key: 'your_api_key', // Optional
    referrer_bps: 30, // 0.3% referrer fee
  },
})

Examples

Complete Cross-Chain Swap Example

import { CetusCrossSwapSDK, CrossSwapPlatform, ChainId } from '@cetusprotocol/CrossSwap-sdk'
import { toDecimalsAmount } from '@cetusprotocol/common-sdk'

async function performCrossChainSwap() {
  // Initialize SDK
  const sdk = CetusCrossSwapSDK.createSDK({ env: 'mainnet' })
  
  // Configure platforms (setup your wallets first)
  // ... wallet configuration code ...
  
  // Estimate quote
  const quote = await sdk.estimateQuote(CrossSwapPlatform.LI_FI, {
    amount: toDecimalsAmount('1', 9).toString(),
    from_token: '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI',
    to_token: '0x0000000000000000000000000000000000000000',
    from_chain_id: ChainId.SUI_LI_FI,
    to_chain_id: ChainId.POL,
    slippage: 0.05,
    lifi_configs: {
      from_address: 'your_sui_address',
      to_address: 'your_polygon_address',
    },
  })
  
  if (quote.error) {
    console.error('Quote error:', quote.error)
    return
  }
  
  // Execute swap
  const result = await sdk.executeSwapQuoteFromLiFi({
    quote: quote.quotes[0],
    swap_wallet_address: 'your_sui_address',
    destination_address: 'your_polygon_address',
  })
  
  console.log('Swap completed:', result)
}

Platform Documentation

For more detailed information about the supported cross-chain platforms:

More About Cetus

Use the following links to learn more about Cetus:

Learn more about working with Cetus in the Cetus Documentation.

Join the Cetus community on Cetus Discord.

License

MIT