- Added comprehensive bounds checking to prevent buffer overruns in multicall parsing - Implemented graduated validation system (Strict/Moderate/Permissive) to reduce false positives - Added LRU caching system for address validation with 10-minute TTL - Enhanced ABI decoder with missing Universal Router and Arbitrum-specific DEX signatures - Fixed duplicate function declarations and import conflicts across multiple files - Added error recovery mechanisms with multiple fallback strategies - Updated tests to handle new validation behavior for suspicious addresses - Fixed parser test expectations for improved validation system - Applied gofmt formatting fixes to ensure code style compliance - Fixed mutex copying issues in monitoring package by introducing MetricsSnapshot - Resolved critical security vulnerabilities in heuristic address extraction - Progress: Updated TODO audit from 10% to 35% complete 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
91 lines
2.8 KiB
Go
91 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/fraktal/mev-beta/tools/profitability-audit/internal"
|
|
)
|
|
|
|
func main() {
|
|
var (
|
|
exchange = flag.String("exchange", "", "Exchange to audit (uniswap_v2, uniswap_v3, curve, balancer, all)")
|
|
minProfitBP = flag.Float64("min-profit", 10.0, "Minimum profit threshold in basis points")
|
|
maxSlippage = flag.Float64("max-slippage", 50.0, "Maximum acceptable slippage in basis points")
|
|
scenarios = flag.String("scenarios", "default", "Test scenarios file (default, stress, production)")
|
|
outputDir = flag.String("output", "reports/profitability", "Output directory for reports")
|
|
verbose = flag.Bool("verbose", false, "Enable verbose output")
|
|
realtime = flag.Bool("realtime", false, "Enable real-time profit monitoring")
|
|
duration = flag.Duration("duration", 5*time.Minute, "Duration for real-time monitoring")
|
|
)
|
|
flag.Parse()
|
|
|
|
if *exchange == "" {
|
|
fmt.Println("Usage: profitability-audit -exchange <exchange> [options]")
|
|
flag.PrintDefaults()
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Create output directory
|
|
if err := os.MkdirAll(*outputDir, 0755); err != nil {
|
|
log.Fatalf("Failed to create output directory: %v", err)
|
|
}
|
|
|
|
// Initialize profitability auditor
|
|
auditor, err := internal.NewProfitabilityAuditor(&internal.Config{
|
|
MinProfitBP: *minProfitBP,
|
|
MaxSlippageBP: *maxSlippage,
|
|
OutputDir: *outputDir,
|
|
Verbose: *verbose,
|
|
ScenariosFile: *scenarios,
|
|
})
|
|
if err != nil {
|
|
log.Fatalf("Failed to initialize auditor: %v", err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
// Run profitability audit
|
|
if *realtime {
|
|
fmt.Printf("Starting real-time profitability monitoring for %v...\n", *duration)
|
|
if err := runRealtimeAudit(ctx, auditor, *exchange, *duration); err != nil {
|
|
log.Fatalf("Real-time audit failed: %v", err)
|
|
}
|
|
} else {
|
|
fmt.Printf("Running profitability audit for exchange: %s\n", *exchange)
|
|
if err := runStaticAudit(ctx, auditor, *exchange); err != nil {
|
|
log.Fatalf("Static audit failed: %v", err)
|
|
}
|
|
}
|
|
|
|
fmt.Printf("Audit complete. Reports saved to: %s\n", *outputDir)
|
|
}
|
|
|
|
func runStaticAudit(ctx context.Context, auditor *internal.ProfitabilityAuditor, exchange string) error {
|
|
if exchange == "all" {
|
|
exchanges := []string{"uniswap_v2", "uniswap_v3", "curve", "balancer"}
|
|
for _, ex := range exchanges {
|
|
if err := auditor.AuditExchange(ctx, ex); err != nil {
|
|
return fmt.Errorf("failed to audit %s: %w", ex, err)
|
|
}
|
|
}
|
|
} else {
|
|
if err := auditor.AuditExchange(ctx, exchange); err != nil {
|
|
return fmt.Errorf("failed to audit %s: %w", exchange, err)
|
|
}
|
|
}
|
|
|
|
return auditor.GenerateReport()
|
|
}
|
|
|
|
func runRealtimeAudit(ctx context.Context, auditor *internal.ProfitabilityAuditor, exchange string, duration time.Duration) error {
|
|
ctx, cancel := context.WithTimeout(ctx, duration)
|
|
defer cancel()
|
|
|
|
return auditor.MonitorRealTimeProfit(ctx, exchange)
|
|
}
|