UNPKG

@robertprp/intents-sdk

Version:

Shogun Network Intent-based cross-chain swaps SDK

123 lines (101 loc) 4.17 kB
# Intents SDK for Cross-Chain Swaps A TypeScript SDK for facilitating cross-chain token swaps across multiple blockchain ecosystems. This SDK helps developers easily integrate with Intents Protocol to enable seamless cross-chain transfers and swaps. ## Installation (To be defined and published) ```bash npm install @shogun-sdk/intents-sdk pnpm install @shogun-sdk/intents-sdk yarn add @shogun-sdk/intents-sdk ``` ## Architecture The SDK uses a modular architecture with chain-specific implementations: - `EVMSDK`: Implementation for Ethereum Virtual Machine chains - `SolanaSDK`: Implementation for Solana blockchain - `SuiSDK`: Implementation for Sui blockchain ## Usage ### Basic Usage ```typescript import { ChainID, EVMSDK, SolanaSDK, SuiSDK } from "@shogun-sdk/intents-sdk"; // For EVM chains (Arbitrum, Optimism, Base) const evmSdk = new EVMSDK({ chainId: ChainID.Arbitrum, privateKey: '0x...', // Your private key rpcProviderUrl: 'https://arbitrum-mainnet.public.blastapi.io', // Optional: Default RPC will be used if not provided }); // For Solana const solanaSdk = new SolanaSDK({ privateKey: '...', // Your private key commitment: 'finalized', // Or 'confirmed' rpcProviderUrl: 'https://api.mainnet-beta.solana.com', // Optional }); // For Sui const suiSdk = new SuiSDK({ privateKey: '...', // Your private key }); ``` ### Creating and Submitting Orders ```typescript // Create and prepare a cross-chain order const preparedOrder = await sdk.createOrder({ sourceChainId: ChainID.Arbitrum, sourceTokenAddress: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', sourceTokenAmount: BigInt(12000), destinationChainId: ChainID.Solana, destinationTokenAddress: 'So11111111111111111111111111111111111111112', destinationTokenMinAmount: BigInt(10000), destinationAddress: '3Kiz4oBXpR9YuPNsVfvE5XnNzgwjrM9m2CbRzyyEVkpQ', minStablecoinAmount: BigInt(11000), deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now }); // Or Send the order to the auctioneer const response = await sdk.createAndSendOrder({ sourceChainId: ChainID.Arbitrum, sourceTokenAddress: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', sourceTokenAmount: BigInt(12000), destinationChainId: ChainID.Solana, destinationTokenAddress: 'So11111111111111111111111111111111111111112', destinationTokenMinAmount: BigInt(10000), destinationAddress: '3Kiz4oBXpR9YuPNsVfvE5XnNzgwjrM9m2CbRzyyEVkpQ', minStablecoinAmount: BigInt(11000), deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now }); ``` ## Supported Chains | Chain | Chain ID | Status | |-------|----------|--------| | Arbitrum | 42161 | ✅ Supported | | Optimism | 10 | ✅ Supported | | Base | 8453 | ✅ Supported | | Solana | 7565164 | ✅ Supported | | Sui | 101 | ✅ Supported | ## Example Implementation Here's a complete example of creating an order from Arbitrum to Solana: ```typescript import { ChainID, EVMSDK, ValidationError } from "@shogun-sdk/intents-sdk"; async function createCrossChainOrder() { try { const sdk = new EVMSDK({ chainId: ChainID.Arbitrum, privateKey: process.env.PRIVATE_KEY as `0x${string}`, }); const response = await sdk.createAndSendOrder({ sourceChainId: ChainID.Arbitrum, sourceTokenAddress: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', // USDT on Arbitrum sourceTokenAmount: BigInt(10_000_000), // 10 USDT with 6 decimals destinationChainId: ChainID.Solana, destinationTokenAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', // USDT on Solana destinationTokenMinAmount: BigInt(9_500_000), // 9.5 USDT minimum to receive destinationAddress: '3Kiz4oBXpR9YuPNsVfvE5XnNzgwjrM9m2CbRzyyEVkpQ', // Solana destination address minStablecoinAmount: BigInt(9_800_000), // Minimum stablecoin amount for protocol deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now }); return response; } catch (error) { if (error instanceof ValidationError) { console.error("Invalid order parameters:", error.message); } else { console.error("Failed to create and send order:", error); } throw error; } } ```