1.0.0 • Published 1 month ago

@shogun-sdk/intents-sdk v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

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)

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

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

// 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

ChainChain IDStatus
Arbitrum42161✅ Supported
Optimism10✅ Supported
Base8453✅ Supported
Solana7565164✅ Supported
Sui101✅ Supported

Example Implementation

Here's a complete example of creating an order from Arbitrum to Solana:

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
    });

    console.log("Order submitted successfully:", response);
    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;
  }
}