- 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>
144 lines
4.7 KiB
Go
144 lines
4.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/fraktal/mev-beta/pkg/marketmanager"
|
|
)
|
|
|
|
func main() {
|
|
// Create a new market manager
|
|
config := &marketmanager.MarketManagerConfig{
|
|
VerificationWindow: 500 * time.Millisecond,
|
|
MaxMarkets: 1000,
|
|
}
|
|
|
|
manager := marketmanager.NewMarketManager(config)
|
|
|
|
// Create some sample markets
|
|
market1 := marketmanager.NewMarket(
|
|
common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984"), // Uniswap V3 Factory
|
|
common.HexToAddress("0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640"), // USDC/WETH 0.3% Pool
|
|
common.HexToAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"), // USDC
|
|
common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"), // WETH
|
|
3000, // 0.3% fee
|
|
"USDC_WETH",
|
|
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48_0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
"UniswapV3",
|
|
)
|
|
|
|
// Set price data for market1
|
|
market1.UpdatePriceData(
|
|
big.NewFloat(2000.0), // Price: 2000 USDC per WETH
|
|
big.NewInt(1000000000000000000), // Liquidity: 1 ETH
|
|
big.NewInt(2505414483750470000), // sqrtPriceX96
|
|
200000, // Tick
|
|
)
|
|
|
|
// Set metadata for market1
|
|
market1.UpdateMetadata(
|
|
time.Now().Unix(),
|
|
12345678,
|
|
common.HexToHash("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"),
|
|
marketmanager.StatusConfirmed,
|
|
)
|
|
|
|
// Create another market with a different price
|
|
market2 := marketmanager.NewMarket(
|
|
common.HexToAddress("0x1F98431c8aD98523631AE4a59f267346ea31F984"), // Uniswap V3 Factory
|
|
common.HexToAddress("0xC6962004f452bE9203591991D15f6b388e09E8D0"), // USDC/WETH 0.05% Pool
|
|
common.HexToAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"), // USDC
|
|
common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"), // WETH
|
|
500, // 0.05% fee
|
|
"USDC_WETH",
|
|
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48_0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
"UniswapV3",
|
|
)
|
|
|
|
// Set price data for market2 (slightly higher price)
|
|
market2.UpdatePriceData(
|
|
big.NewFloat(2010.0), // Price: 2010 USDC per WETH
|
|
big.NewInt(500000000000000000), // Liquidity: 0.5 ETH
|
|
big.NewInt(2511697847297280000), // sqrtPriceX96
|
|
200500, // Tick
|
|
)
|
|
|
|
// Set metadata for market2
|
|
market2.UpdateMetadata(
|
|
time.Now().Unix(),
|
|
12345679,
|
|
common.HexToHash("0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"),
|
|
marketmanager.StatusConfirmed,
|
|
)
|
|
|
|
// Add markets to manager
|
|
fmt.Println("Adding markets to manager...")
|
|
manager.AddMarket(market1)
|
|
manager.AddMarket(market2)
|
|
|
|
// Get markets by raw ticker
|
|
fmt.Println("\nGetting markets by raw ticker...")
|
|
markets, err := manager.GetMarketsByRawTicker("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48_0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
|
|
if err != nil {
|
|
fmt.Printf("Error getting markets: %v\n", err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Found %d markets for raw ticker\n", len(markets))
|
|
|
|
// Create arbitrage detector
|
|
minProfit := big.NewInt(10000000000000000) // 0.01 ETH minimum profit
|
|
minROI := 0.1 // 0.1% minimum ROI
|
|
detector := marketmanager.NewArbitrageDetector(minProfit, minROI)
|
|
|
|
// Detect arbitrage opportunities
|
|
fmt.Println("\nDetecting arbitrage opportunities...")
|
|
opportunities := detector.DetectArbitrageOpportunities(markets)
|
|
|
|
fmt.Printf("Found %d arbitrage opportunities\n", len(opportunities))
|
|
|
|
// Display opportunities
|
|
for i, opportunity := range opportunities {
|
|
fmt.Printf("\nOpportunity %d:\n", i+1)
|
|
fmt.Printf(" Path: %s -> %s\n", opportunity.Path[0], opportunity.Path[1])
|
|
fmt.Printf(" Input Amount: %s wei\n", opportunity.AmountIn.String())
|
|
fmt.Printf(" Profit: %s wei\n", opportunity.Profit.String())
|
|
fmt.Printf(" Gas Estimate: %s wei\n", opportunity.GasEstimate.String())
|
|
fmt.Printf(" ROI: %.2f%%\n", opportunity.ROI)
|
|
}
|
|
|
|
// Show market counts
|
|
fmt.Printf("\nTotal markets in manager: %d\n", manager.GetMarketCount())
|
|
fmt.Printf("Total unique raw tickers: %d\n", manager.GetRawTickerCount())
|
|
|
|
// Demonstrate market updates
|
|
fmt.Println("\nUpdating market price...")
|
|
market1.UpdatePriceData(
|
|
big.NewFloat(2005.0), // New price
|
|
market1.Liquidity, // Same liquidity
|
|
big.NewInt(2508556165523880000), // New sqrtPriceX96
|
|
200250, // New tick
|
|
)
|
|
|
|
err = manager.UpdateMarket(market1)
|
|
if err != nil {
|
|
fmt.Printf("Error updating market: %v\n", err)
|
|
return
|
|
}
|
|
|
|
fmt.Println("Market updated successfully")
|
|
|
|
// Get updated market
|
|
updatedMarket, err := manager.GetMarket(market1.RawTicker, market1.Key)
|
|
if err != nil {
|
|
fmt.Printf("Error getting updated market: %v\n", err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Updated market price: %s\n", updatedMarket.Price.Text('f', -1))
|
|
}
|