Socket
Book a DemoInstallSign in
Socket

dd_cross_swap_sdk

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dd_cross_swap_sdk

SDK for cetus cross swap

0.0.0-experimental-20250623164255
latest
npmnpm
Version published
Weekly downloads
16
77.78%
Maintainers
1
Weekly downloads
 
Created
Source

Cetus Bridge SDK

A TypeScript SDK for cross-chain bridging operations using various platforms like Mayan and LiFi.

Installation

npm install @cetusprotocol/bridge-sdk

Quick Start

Basic Setup

import { CetusBridgeSDK, BridgePlatform } from '@cetusprotocol/bridge-sdk'

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

Configuration

EVM Configuration

import { Wallet, JsonRpcProvider } from 'ethers'

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

sdk.mayanConfigs = {
  evm: {
    evm_signer,
  },
}

Solana Configuration

You can configure Solana in several ways depending on your use case:

Option 1: Using Wallet Adapter (Recommended for DApps)

import { Connection } from '@solana/web3.js'
import { useWallet } from '@solana/wallet-adapter-react'
import { createSolanaSignerFromWallet } from '@cetusprotocol/bridge-sdk'

// In your React component
const { signTransaction } = useWallet()
const connection = new Connection(rpcUrl)

// Create signer from wallet adapter
const signer = createSolanaSignerFromWallet({ signTransaction })

sdk.mayanConfigs = {
  solana: {
    signer,
    connection,
  },
}

Option 2: Using Keypair Helper (For Testing)

import { Keypair, Connection } from '@solana/web3.js'
import * as bip39 from 'bip39'
import { derivePath } from 'ed25519-hd-key'
import { createSolanaSignerFromKeypair } from '@cetusprotocol/bridge-sdk'

// Create keypair from mnemonic (only for testing!)
const seed = await bip39.mnemonicToSeed(mnemonic)
const derivationPath = "m/44'/501'/0'/0'"
const derivedSeed = derivePath(derivationPath, seed.toString('hex')).key
const keypair = Keypair.fromSeed(derivedSeed)

// Create connection
const connection = new Connection(rpcUrl)

// Create signer from keypair
const signer = createSolanaSignerFromKeypair(keypair)

sdk.mayanConfigs = {
  solana: {
    signer,
    connection,
  },
}

Option 3: Custom Signer Function

import { Connection } from '@solana/web3.js'
import { SolanaTransactionSigner } from '@mayanfinance/swap-sdk'

const connection = new Connection(rpcUrl)

// Create custom signer function
const signer: SolanaTransactionSigner = async (trx) => {
  // Your custom signing logic
  // This could be calling a hardware wallet, wallet extension, etc.
  return trx
}

sdk.mayanConfigs = {
  solana: {
    signer,
    connection,
  },
}

Usage Examples

Get Supported Chains

const chains = sdk.getSupportedChains(BridgePlatform.MAYAN)
console.log('Supported chains:', chains)

Get Supported Tokens

const tokens = await sdk.getSupportedTokens(BridgePlatform.MAYAN, [ChainId.ETH])
console.log('Supported tokens:', tokens)

Estimate Quote

const quote = await sdk.estimateQuote(BridgePlatform.MAYAN, {
  amount: '1000000000', // 1 SUI (9 decimals)
  from_token: '0x2::sui::SUI',
  to_token: '0x0000000000000000000000000000000000000000', // ETH
  from_chain_id: ChainId.SUI_MAYAN,
  to_chain_id: ChainId.ETH,
})
console.log('Quote:', quote)

Build Bridge Swap

const swapResult = await sdk.buildBridgeSwapResult({
  quote,
  swap_wallet_address: 'your_wallet_address',
  destination_address: 'destination_address',
})

// Execute the swap based on the chain
if (swapResult.sui) {
  // Execute SUI transaction
  const result = await sdk.FullClient.executeTx(keypair, swapResult.sui, true)
} else if (swapResult.evm) {
  // Execute EVM transaction
  const tx = await evm_signer.sendTransaction(swapResult.evm)
} else if (swapResult.solana) {
  // Solana transaction is already executed by the SDK
  console.log('Solana signature:', swapResult.solana.signature)
}

Supported Platforms

  • Mayan: Cross-chain bridging with support for EVM, Solana, and Sui chains
  • LiFi: EVM-based cross-chain bridging

Supported Chains

Mayan Platform

  • EVM Chains: Ethereum, BSC, Polygon, Arbitrum, Optimism, Base, etc.
  • Solana
  • Sui

LiFi Platform

  • EVM Chains: Ethereum, BSC, Polygon, Arbitrum, Optimism, etc.

Complete DApp Example

Here's a complete example of how to use the Bridge SDK in a React DApp:

import React, { useEffect, useState } from 'react'
import { useWallet } from '@solana/wallet-adapter-react'
import { useConnection } from '@solana/wallet-adapter-react'
import { CetusBridgeSDK, BridgePlatform, ChainId } from '@cetusprotocol/bridge-sdk'
import { createSolanaSignerFromWallet } from '@cetusprotocol/bridge-sdk'

function BridgeComponent() {
  const { signTransaction } = useWallet()
  const { connection } = useConnection()
  const [sdk, setSdk] = useState<CetusBridgeSDK | null>(null)
  const [quote, setQuote] = useState(null)

  useEffect(() => {
    // Initialize SDK
    const bridgeSdk = CetusBridgeSDK.createSDK({ env: 'mainnet' })
    
    // Configure Solana if wallet is connected
    if (signTransaction) {
      const signer = createSolanaSignerFromWallet({ signTransaction })
      bridgeSdk.mayanConfigs = {
        solana: {
          signer,
          connection,
        },
      }
    }
    
    setSdk(bridgeSdk)
  }, [signTransaction, connection])

  const getQuote = async () => {
    if (!sdk) return

    try {
      const quoteResult = await sdk.estimateQuote(BridgePlatform.MAYAN, {
        amount: '1000000000', // 1 SUI
        from_token: '0x2::sui::SUI',
        to_token: '0x0000000000000000000000000000000000000000', // ETH
        from_chain_id: ChainId.SUI_MAYAN,
        to_chain_id: ChainId.ETH,
      })
      
      setQuote(quoteResult)
    } catch (error) {
      console.error('Failed to get quote:', error)
    }
  }

  const executeSwap = async () => {
    if (!sdk || !quote) return

    try {
      const swapResult = await sdk.buildBridgeSwapResult({
        quote,
        swap_wallet_address: 'your_wallet_address',
        destination_address: 'destination_address',
      })

      if (swapResult.solana) {
        console.log('Solana swap executed:', swapResult.solana.signature)
      }
    } catch (error) {
      console.error('Failed to execute swap:', error)
    }
  }

  return (
    <div>
      <button onClick={getQuote}>Get Quote</button>
      {quote && (
        <div>
          <p>Quote received!</p>
          <button onClick={executeSwap}>Execute Swap</button>
        </div>
      )}
    </div>
  )
}

Error Handling

The SDK provides comprehensive error handling with specific error codes and messages. All errors are wrapped in a standardized format for easy handling.

Contributing

Please read our contributing guidelines before submitting pull requests.

License

This project is licensed under the MIT License.

FAQs

Package last updated on 23 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.