Skip to content

sh4dex/Swapping-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swapping App

License: MIT Solidity Foundry Test Coverage

Overview

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.

Features

  • 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

Contract Architecture

Swap Interaction Diagram

SwapApp.sol

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

Supported Networks

  • Sepolia Testnet: Router at 0xeE567Fe1712Faf6149d80dA1E6934E354124CfE3
  • Arbitrum One: Router at 0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24

Installation

# Clone the repository
git clone <repository-url>
cd Swapping-App

# Install dependencies
forge install

# Build the project
forge build

Testing

Run Tests with Sepolia Fork

# 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

Code Coverage

# Generate coverage report with Sepolia fork
forge coverage --fork-url https://ethereum-sepolia-rpc.publicnode.com

Current 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) |
╰-----------------+---------------+---------------+---------------+---------------╯

Dependencies

  • OpenZeppelin Contracts: ERC20 token interface and SafeERC20 utilities
  • Uniswap V2 Router: Decentralized exchange routing

Security Considerations

  • Slippage Protection: Always set an appropriate amountOutMin to 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

Project Structure

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please ensure:

  • All tests pass
  • Code coverage remains at 100%
  • Follow Solidity best practices
  • Add tests for new functionality

Contact

For questions or support, please open an issue on the GitHub repository.

About

Swapping application using uniswap v2 router 02 implementation for tokens swaps across ERC-20 tokens by wrapping/unwrapping it

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors