A production-ready example demonstrating how to execute token swaps on Base Camp testnet using the SummitX Smart Router.
- π Optimal Route Finding - Automatically finds the best swap routes across V2, V3, and Stable pools
- π° Multi-Pool Aggregation - Splits trades across multiple pools for better prices
- π‘οΈ Slippage Protection - Built-in slippage tolerance to protect against price movements
- β‘ Gas Optimization - Efficient routing to minimize transaction costs
- π Multi-Hop Support - Swaps through intermediate tokens when direct routes aren't available
- Node.js 18+ and npm/yarn
- A wallet with:
- CAMP tokens for gas fees
- Tokens to swap (USDC, T12ETH, etc.)
- Private key for transaction signing
# Clone the repository
git clone https://github.com/summitx-finance/summitx-example.git
cd summitx-swap-example
# Install dependencies
npm install
# or
yarn install- Copy the example environment file:
cp .env.example .env- Add your private key to
.env:
PRIVATE_KEY=0x... # Your wallet private key
Run the swap example:
npm run swap
# or
yarn swapThis will execute a swap of 10 USDC to T12ETH on Base Camp testnet.
Edit the configuration in src/execute-swap-example.ts:
const SWAP_CONFIG = {
inputToken: baseCampTestnetTokens.usdc, // Token to swap from
outputToken: baseCampTestnetTokens.t12eth, // Token to swap to
inputAmount: "10", // Amount to swap
slippagePercent: 1.0, // 1% slippage tolerance
}- USDC - USD Coin (6 decimals)
- T12ETH - Test ETH with 12 decimals
- WCAMP - Wrapped CAMP
- SUMMIT - Summit Token
- USDT - Tether USD
const quoter = new TokenQuoter({
rpcUrl: "your-rpc-url",
slippageTolerance: 1.0,
maxHops: 3, // Maximum intermediate tokens
maxSplits: 3, // Maximum route splits
})- Get Quote: Finds optimal swap routes using the SummitX Smart Router
- Check Approval: Ensures the router can spend your tokens
- Execute Swap: Sends the swap transaction with slippage protection
- Verify Results: Confirms the swap and checks final balances
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SummitX Smart Router Swap Example
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[SUCCESS] Wallet connected: 0x742d35Cc6634C0532925a3b844Bc9e7595f1234
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Step 2: Checking Token Balances
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[INFO] USDC Balance: 1000.0
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Step 3: Getting Swap Quote
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[SUCCESS] Quote received:
{
"input": "10 USDC",
"expectedOutput": "8.234567 T12ETH",
"minimumOutput": "8.151223 T12ETH",
"priceImpact": "0.23%",
"route": ["(100% [USDC-T12ETH V3 0.3% 0x...])"]
}
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Step 6: Executing Swap
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[INFO] Swap transaction sent: 0x123...abc
[SUCCESS] Swap completed successfully! π
const quoter = new TokenQuoter(options)
// Get a swap quote
const quote = await quoter.getQuote(
inputToken, // Token to swap from
outputToken, // Token to swap to
amount, // Amount as string
tradeType, // EXACT_INPUT or EXACT_OUTPUT
adjustForGas // Include gas costs in quote
)// Build swap transaction
const { calldata, value } = SwapRouter.swapCallParameters(
trade, // Trade object from quoter
{
slippageTolerance, // Percent object
recipient, // Receiver address
deadlineOrPreviousBlockhash // Expiry time
}
)Currently configured for Base Camp testnet. To use other networks:
- Update chain configuration in the example
- Change router addresses
- Update token addresses
- Ensure you have enough tokens to swap
- Check you have CAMP for gas fees
- Verify liquidity exists for your token pair
- Try a smaller amount
- Check token addresses are correct
- Increase slippage tolerance
- Check gas price settings
- Verify token approvals
src/
βββ execute-swap-example.ts # Main swap example
βββ quoter/
β βββ token-quoter.ts # Quote fetching logic
βββ config/
β βββ base-testnet.ts # Network configuration
βββ utils/
βββ logger.ts # Logging utilities
npm run typecheck # Type checking
npm run lint # Lintingnpm run build- Never expose private keys in code
- Always verify token addresses
- Use appropriate slippage settings
- Monitor for sandwich attacks
- Test with small amounts first
MIT License - see LICENSE file for details
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request
- Discord: Join our community
- Twitter: @summitxfinance
- Email: bruce@summitx.finance