UNPKG

ttxd-alpha

Version:

An SDK for building applications on top of V2,V3 and Solana exchanges

137 lines (99 loc) • 5.83 kB
# TTXD-Alpha SDK [![npm version](https://img.shields.io/npm/v/@uniswap/v3-sdk/latest.svg)](https://www.npmjs.com/package/@uniswap/v3-sdk/v/latest) [![npm bundle size (scoped version)](https://img.shields.io/bundlephobia/minzip/@uniswap/v3-sdk/latest.svg)](https://bundlephobia.com/result?p=@uniswap/v3-sdk@latest) The latest version of the SDK is used in production in the DEX Interfaces, but it is considered Alpha testing software and may contain bugs or change significantly between patch versions. ## Features - **Multi-chain & multi-DEX support:** Currently supports Ethereum, BNB Chain, Polygon, and Base, with more chains coming soon. - **Modular architecture:** Add additional DEXes and blockchains without refactoring core logic. - **Lightweight:** Designed for high performance, the SDK offers minimal overhead. **Learn more about these features and how to use them in our Medium article:** šŸ“š Read our [Ultimate Guide to Cross-Chain](https://medium.com/@nischay.vaish/ultimate-guide-to-cross-chain-token-swapping-uniswap-v2-v3-raydium-solana-e9fa22695722) to learn about: This **ttxd-alpha** SDK provides a unified way to interact with **Uniswap V2**, **Uniswap V3**, **PancakeSwap**, **QuickSwap**, **SushiSwap**, and **Raydium V2** exchanges across multiple blockchains. With simple functions, you can swap tokens and manage liquidity seamlessly across **Ethereum, BSC, Polygon, Base**, and **Solana**. --- ## **Installation** Make sure you have **Node.js** installed. To install the SDK, run: ```bash npm install ttxd-alpha ``` ## Examples of Using the SDK ### 1. V2 Exchanges: Uniswap V2 This example demonstrates a swap on Uniswap V2, but the same code works for other V2 exchanges by simply changing the exchange name and chainId. ```bash import { swapV2 } from 'ttxd-alpha'; const provider = new ethers.providers.JsonRpcProvider('RPC URL'); // JsonRpcProvider instance const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider); // Wallet instance (async () => { await swapV2({ chainId: ChainId.Base, // Chain ID exchange: "uniswapv2", // Exchange name token1: new Token(), // Token to swap from token2: new Token(), // Token to swap to amount: '1000000', // 1 USDC (raw amount) provider, // Blockchain provider signer, // Transaction signer gasLimit, // Optional gas limit (default: 300,000) maxFeePerGas, // Optional max fee per gas (default: Dynamic per chain) maxPriorityFeePerGas, // Optional max priority fee per gas (default: Dynamic per chain) }); })(); ``` ### **Supported V2 Exchanges** | Exchange | Supported Networks | |-----------------|-----------------------------------| | "uniswapv2" | Ethereum, BSC, Polygon, Base | | "pancakeswapv2" | Ethereum, BSC, Base | | "quickswapv2" | Polygon | | "sushiswapv2" | Ethereum, BSC, Polygon | ### 2. V3 Exchanges: Uniswap V3 The following example demonstrates a swap using Uniswap V3. Similarly, it works for other V3 exchanges with minor changes. ```bash import { swapV3 } from 'ttxd-alpha'; const provider = new ethers.providers.JsonRpcProvider('RPC URL'); // JsonRpcProvider instance const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider); // Wallet instance (async () => { await swapV3({ chainId: ChainId.BASE, // Chain ID exchange: "uniswapv3", // Exchange name tokenIn: new Token(), // Token to swap from tokenOut: new Token(), // Token to swap to fee: 500, // Pool fee (default: 0.05%) amountIn: '1000000', // 1 USDC (raw amount) provider, // Blockchain provider signer, // Transaction signer gasLimit, // Optional gas limit (default: 300,000) maxFeePerGas, // Optional max fee per gas (default: Dynamic per chain) maxPriorityFeePerGas, // Optional max priority fee per gas (default: Dynamic per chain) }); })(); ``` ### **Supported V3 Exchanges** | Exchange | Supported Networks | |-----------------|-----------------------------------| | "uniswapv3" | Ethereum, BSC, Polygon, Base | | "pancakeswapv3" | BSC, Base | ### 3. Solana : Raydium V2 This example demonstrates a swap using Raydium V2 on Solana. Raydium works with Pool IDs, so you must provide a specific pool ID and amount for the swap. ```bash import { swapRaydium } from 'ttxd-alpha'; (async () => { const result = await swapRaydium({ poolId: 'AMM POOL_ID', // Example pool ID amountIn: 0.005, // Amount in SOL privateKey: 'YOUR_PRIVATE_KEY', // Wallet private key slippage: 0.01, // Optional | Default: 0.05 (5%) rpcUrl: 'https://api.mainnet-beta.solana.com', // Optional: Custom RPC URL | Default: Mainnet poolType: "amm", // Pool type: "amm" for AMM, "clmm" for CLMM priorityFeeSol: 0.0001, // Optional: Priority fee in SOL tipFeeSol: 0.00005 // Optional: Tip fee in SOL }); console.log(`Swap successful! Transaction ID: ${result.txId}`); })(); ``` **Supported Solana Exchanges** "raydiumv2" - Solana **New Feature: Swap Across Different Pool Types** - **AMM (Automated Market Maker)** - **CLMM (Concentrated Liquidity Market Maker)** ## License This project is licensed under the **MIT** License.