A smart contract application that enables secure token swapping using the Uniswap V2 Router on EVM-compatible blockchains. The contract provides a streamlined interface for executing token swaps with automatic liquidity pool detection and slippage protection.
- Token Swapping: Execute direct token-to-token swaps via Uniswap V2 Router
- Multi-hop Support: Support for complex swap paths with multiple token intermediaries
- Slippage Protection: Built-in minimum output amount validation to protect against price fluctuations
- Safe Token Handling: Uses OpenZeppelin's SafeERC20 for secure token transfers
- Event Emission: Comprehensive event logging for swap transactions
- Flexible Routing: Configure custom router addresses for different blockchain networks
The main contract that handles token swap execution through Uniswap V2 Router.
Key Functions:
swapTokens()- Execute a swap with specified token path, amount, and minimum output
Events:
SwapTokens()- Emitted when a successful swap is executed
- Sepolia Testnet: Router at
0xeE567Fe1712Faf6149d80dA1E6934E354124CfE3 - Arbitrum One: Router at
0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24
# Clone the repository
git clone <repository-url>
cd Swapping-App
# Install dependencies
forge install
# Build the project
forge build# Run all tests with Sepolia testnet fork
forge test --fork-url https://ethereum-sepolia-rpc.publicnode.com -vvv
# Run specific test
forge test --fork-url https://ethereum-sepolia-rpc.publicnode.com --match-test testSwapTokensProperly -vvv# Generate coverage report with Sepolia fork
forge coverage --fork-url https://ethereum-sepolia-rpc.publicnode.comCurrent Coverage:
╭-----------------+---------------+---------------+---------------+---------------╮
| File | % Lines | % Statements | % Branches | % Funcs |
+=================================================================================+
| src/SwapApp.sol | 100.00% (7/7) | 100.00% (6/6) | 100.00% (0/0) | 100.00% (2/2) |
|-----------------+---------------+---------------+---------------+---------------|
| Total | 100.00% (7/7) | 100.00% (6/6) | 100.00% (0/0) | 100.00% (2/2) |
╰-----------------+---------------+---------------+---------------+---------------╯
- OpenZeppelin Contracts: ERC20 token interface and SafeERC20 utilities
- Uniswap V2 Router: Decentralized exchange routing
- Slippage Protection: Always set an appropriate
amountOutMinto prevent sandwich attacks - Deadline Validation: Include transaction deadline to prevent expired transactions
- Liquidity Verification: Ensure adequate liquidity exists in swap pools before execution
- SafeERC20: All token operations use safe transfer wrappers
Swapping-App/
├── src/
│ ├── SwapApp.sol # Main swap contract
│ └── interfaces/
│ └── IV2Router02.sol # Uniswap V2 Router interface
├── test/
│ └── SwapApp.t.sol # Test suite
├── lib/ # External dependencies
├── foundry.toml # Foundry configuration
└── README.md # This file
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please ensure:
- All tests pass
- Code coverage remains at 100%
- Follow Solidity best practices
- Add tests for new functionality
For questions or support, please open an issue on the GitHub repository.
