feat: Add TestArbitrage Contract for On-Chain Testing with Security & Testing Utilities #144
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Description
Summary
This PR introduces the new
TestArbitragecontract undersrc/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
src/onchain/TestArbitrage.solFlashArbitrage.sollicense identifier to MIT for consistency2. Imports
IVault,IFlashLoanRecipientfor flash loan executionISwapRouterfor DEX operationsReentrancyGuard,Ownable,Pausablefor safety and access control3. NatSpec Documentation
@custom:testing,@custom:security4. Contract Inheritance
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
profitRecipient = msg.senderstats.lastTradeTimestamp = block.timestampConfigurationUpdatedevent for deployment auditability📂 Files Modified
src/onchain/TestArbitrage.sol(81 LOC)src/FlashArbitrage.sol→ updated SPDX license identifier🎯 Motivation
✅ Next Steps
receiveFlashLoan.This contract serves as the foundation for developing, testing, and validating on-chain arbitrage strategies safely before production deployment.