
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
dd_cross_swap_sdk
Advanced tools
A TypeScript SDK for cross-chain bridging operations using various platforms like Mayan and LiFi.
npm install @cetusprotocol/bridge-sdk
import { CetusBridgeSDK, BridgePlatform } from '@cetusprotocol/bridge-sdk'
// Create SDK instance
const sdk = CetusBridgeSDK.createSDK({ env: 'mainnet' })
import { Wallet, JsonRpcProvider } from 'ethers'
const evm_signer = Wallet.fromPhrase(mnemonic, new JsonRpcProvider(rpcUrl))
sdk.mayanConfigs = {
evm: {
evm_signer,
},
}
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,
},
}
const chains = sdk.getSupportedChains(BridgePlatform.MAYAN)
console.log('Supported chains:', chains)
const tokens = await sdk.getSupportedTokens(BridgePlatform.MAYAN, [ChainId.ETH])
console.log('Supported tokens:', tokens)
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)
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)
}
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>
)
}
The SDK provides comprehensive error handling with specific error codes and messages. All errors are wrapped in a standardized format for easy handling.
Please read our contributing guidelines before submitting pull requests.
This project is licensed under the MIT License.
FAQs
SDK for cetus cross swap
The npm package dd_cross_swap_sdk receives a total of 15 weekly downloads. As such, dd_cross_swap_sdk popularity was classified as not popular.
We found that dd_cross_swap_sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.