Skip to content

Conversation

@2PykeETH
Copy link

PR Description

Summary

This PR introduces the new TestArbitrage contract under src/onchain/, designed for on-chain arbitrage testing with enhanced logging, error handling, and simulation features.
It integrates security best practices (OpenZeppelin) and configurable testing utilities, enabling robust testing before deploying production arbitrage strategies.


🔄 Changes Made

1. File Additions

  • Created src/onchain/TestArbitrage.sol
  • Updated FlashArbitrage.sol license identifier to MIT for consistency

2. Imports

  • Balancer V2 Vault Interfaces
    • IVault, IFlashLoanRecipient for flash loan execution
  • Uniswap V3 Router
    • ISwapRouter for DEX operations
  • OpenZeppelin Security Modules
    • ReentrancyGuard, Ownable, Pausable for safety and access control

3. NatSpec Documentation

  • Added contract-level docstrings:
    • Testing features (detailed logging, simulation, gas tracking, profit validation)
    • Security features (reentrancy protection, pausability, safe transfers)
    • Custom tags for clarity: @custom:testing, @custom:security

4. Contract Inheritance

  • Inherits from:
    • IFlashLoanRecipient (to support Balancer flash loans)
    • ReentrancyGuard (reentrancy protection)
    • Ownable (admin/owner access)
    • Pausable (emergency stop control)

5. Constant Variables

  • VAULT → Balancer V2 Vault address (mainnet)
  • MAX_BPS → 10000 basis points (100%)
  • MIN_PROFIT_BPS → 10 (0.1% profit threshold)
  • MAX_SLIPPAGE_BPS → 500 (5% slippage tolerance)
  • GAS_BUFFER → 100,000 (reserved gas buffer for swaps)

All constants include NatSpec for clarity.

6. Constructor

  • Initializes contract with:
    • profitRecipient = msg.sender
    • Deployer authorized as initial trader
    • stats.lastTradeTimestamp = block.timestamp
  • Emits ConfigurationUpdated event for deployment auditability

📂 Files Modified

  • Added: src/onchain/TestArbitrage.sol (81 LOC)
  • Updated: src/FlashArbitrage.sol → updated SPDX license identifier

🎯 Motivation

  • Provides a safe testing environment for arbitrage logic before production deployment.
  • Enhances observability via detailed events and structured error handling.
  • Ensures security best practices with layered protection mechanisms.
  • Offers a configurable test harness to simulate diverse trading scenarios.

✅ Next Steps

  • Implement flash loan execution logic inside receiveFlashLoan.
  • Add profit calculation, slippage checks, and event emissions.
  • Extend with swap simulations via Uniswap V3 router.
  • Write unit and integration tests for test scenarios.

This contract serves as the foundation for developing, testing, and validating on-chain arbitrage strategies safely before production deployment.

@DianaRicee DianaRicee self-requested a review September 28, 2025 18:59
@DianaRicee DianaRicee added documentation Improvements or additions to documentation enhancement New feature or request labels Sep 28, 2025
@DianaRicee DianaRicee merged commit 751e18c into FlashArb-AI:main Sep 28, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants