@snowmonster_defi/sdk
v1.0.3
Published
🚀 The most powerful DEX aggregator SDK on Avalanche by SnowMonster DeFi. Get the best swap rates across Trader Joe, Pangolin & more with a single API call. Features React hooks, TypeScript support, and partner fee sharing up to 0.50%.
Maintainers
Readme
@danaszova/avax-router-sdk
🚀 The Most Powerful DEX Aggregator SDK on Avalanche
Stop manually checking multiple DEXes. Get the best swap rate with a single API call.
What Problem Does This Solve?
Every DEX on Avalanche has different prices and liquidity. Finding the best swap rate means checking Trader Joe, Pangolin, and others manually. This SDK does it for you automatically - querying all DEXes in parallel and returning the best execution.
Result: Users get more tokens for their swaps. You earn partner fees. Everyone wins.
Installation
npm install @danaszova/avax-router-sdkQuick Start
30-Second Example (Copy & Paste)
import { AvaxRouter } from '@danaszova/avax-router-sdk';
const router = new AvaxRouter();
// Get the best quote across all DEXes
const quote = await router.getBestQuote({
tokenIn: 'AVAX',
tokenOut: 'USDC',
amountIn: '1.0',
});
console.log(`You get: ${quote.amountOutFormatted} USDC`);
console.log(`Best DEX: ${quote.bestDex}`);
console.log(`Savings: ${quote.savingsVsWorst}% vs worst route`);React Example
import { useQuote, useSwap } from '@danaszova/avax-router-sdk/react';
function SwapWidget() {
const { quote, loading } = useQuote({
tokenIn: 'AVAX',
tokenOut: 'USDC',
amountIn: '1.0',
});
const { swap } = useSwap();
if (loading) return <div>Finding best price...</div>;
return (
<div>
<h2>Best Price: {quote?.amountOutFormatted} USDC</h2>
<p>via {quote?.bestDex}</p>
<button onClick={() => swap(quote, signer)}>Swap</button>
</div>
);
}API Reference
Core SDK
new AvaxRouter(config?)
Create a new router instance.
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiUrl | string | Production API | Custom API endpoint |
| partnerId | string | - | Your partner ID for fee sharing |
| partnerAddress | string | - | Address to receive partner fees |
| partnerFeeBps | number | 0 | Partner fee in basis points (max: 50 = 0.50%) |
router.getBestQuote(params)
Get the best quote across all supported DEXes.
const quote = await router.getBestQuote({
tokenIn: 'AVAX', // Token symbol or address
tokenOut: 'USDC', // Token symbol or address
amountIn: '1.0', // Amount as string
slippagePercent: 0.5, // Optional, default 0.5%
});Returns:
{
amountOut: string; // Raw output amount
amountOutFormatted: string; // Human-readable amount
bestDex: string; // DEX with best price
route: string[]; // Swap route path
priceImpact: number; // Price impact %
savingsVsWorst: number; // Savings vs worst DEX
}router.getAllQuotes(params)
Get quotes from all DEXes for comparison.
const quotes = await router.getAllQuotes({
tokenIn: 'AVAX',
tokenOut: 'USDC',
amountIn: '1.0',
});
quotes.forEach(q => {
console.log(`${q.dex}: ${q.amountOutFormatted}`);
});router.swap(params, signer)
Execute a swap with the best route.
import { ethers } from 'ethers';
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const result = await router.swap({
tokenIn: 'AVAX',
tokenOut: 'USDC',
amountIn: '1.0',
slippagePercent: 0.5,
}, signer);
console.log(`TX: ${result.txHash}`);router.getSupportedTokens()
Get list of all supported tokens.
router.getSupportedDexes()
Get list of all supported DEXes.
React Hooks
useQuote(params)
React hook for fetching quotes with auto-refresh.
const {
quote, // Best quote
quotes, // All DEX quotes
loading, // Loading state
error, // Error object
refetch // Manual refetch function
} = useQuote({
tokenIn: 'AVAX',
tokenOut: 'USDC',
amountIn: '1.0',
autoFetch: true, // Auto-fetch on mount
refreshInterval: 10000, // Refresh every 10s
});useSwap(config?)
React hook for executing swaps.
const {
swap, // Execute swap function
txHash, // Transaction hash after swap
loading, // Loading state
error, // Error object
reset // Reset state
} = useSwap({
partnerId: 'your-id',
partnerFeeBps: 25,
});
// Execute
await swap({
tokenIn: 'AVAX',
tokenOut: 'USDC',
amountIn: '1.0',
}, signer);useTokenPrice(token)
Get real-time token price.
const { price, loading, error } = useTokenPrice('AVAX');useWallet()
Get wallet connection state.
const { address, isConnected, chainId } = useWallet();💰 Partner Fees (Monetize Your App!)
Earn up to 0.50% on every swap through your integration:
const router = new AvaxRouter({
partnerId: 'my-dapp',
partnerAddress: '0xYourAddress',
partnerFeeBps: 25, // 0.25% fee
});| Daily Volume | Your Fee (0.25%) | Monthly Earnings | |--------------|------------------|------------------| | $10,000 | $25/day | $750 | | $100,000 | $250/day | $7,500 | | $1,000,000 | $2,500/day | $75,000 |
Supported DEXes
| DEX | Type | Status | |-----|------|--------| | Trader Joe V1 | AMM | ✅ Live | | Trader Joe V2 | Liquidity Book | ✅ Live | | Pangolin | AMM | ✅ Live |
Token Addresses
import { AVALANCHE_TOKENS } from '@danaszova/avax-router-sdk';
AVALANCHE_TOKENS.AVAX; // Native
AVALANCHE_TOKENS.WAVAX; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7
AVALANCHE_TOKENS.USDC; // 0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E
AVALANCHE_TOKENS.USDT; // 0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7
AVALANCHE_TOKENS.JOE; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd
AVALANCHE_TOKENS.PNG; // 0x60781C2586D68229fde47564546784ab3fACA982TypeScript Support
Full TypeScript support with exported types:
import type {
Quote,
SwapParams,
SwapResult,
AvaxRouterConfig,
Token,
Dex,
UseQuoteOptions,
UseSwapOptions,
} from '@danaszova/avax-router-sdk';Bundle Size
| Format | Size | Gzipped | |--------|------|---------| | ESM | ~7KB | ~2.5KB | | CJS | ~8KB | ~2.8KB |
Tree-shakeable! Import only what you need.
Requirements
- Node.js >= 16
- React >= 18 (for React hooks)
- ethers >= 6 (for swap execution)
Framework Examples
Next.js App Router
// app/api/quote/route.ts
import { AvaxRouter } from '@danaszova/avax-router-sdk';
const router = new AvaxRouter();
export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const quote = await router.getBestQuote({
tokenIn: searchParams.get('from')!,
tokenOut: searchParams.get('to')!,
amountIn: searchParams.get('amount')!,
});
return Response.json(quote);
}wagmi/viem
import { useAccount, useWalletClient } from 'wagmi';
import { useQuote } from '@danaszova/avax-router-sdk/react';
function SwapComponent() {
const { data: walletClient } = useWalletClient();
const { quote } = useQuote({ tokenIn: 'AVAX', tokenOut: 'USDC', amountIn: '1' });
// Use walletClient to sign transactions
}License
MIT © AVAX Router Team
Built with ❤️ on Avalanche
