Completed clean root directory structure: - Root now contains only: .git, .env, docs/, orig/ - Moved all remaining files and directories to orig/: - Config files (.claude, .dockerignore, .drone.yml, etc.) - All .env variants (except active .env) - Git config (.gitconfig, .github, .gitignore, etc.) - Tool configs (.golangci.yml, .revive.toml, etc.) - Documentation (*.md files, @prompts) - Build files (Dockerfiles, Makefile, go.mod, go.sum) - Docker compose files - All source directories (scripts, tests, tools, etc.) - Runtime directories (logs, monitoring, reports) - Dependency files (node_modules, lib, cache) - Special files (--delete) - Removed empty runtime directories (bin/, data/) V2 structure is now clean: - docs/planning/ - V2 planning documents - orig/ - Complete V1 codebase preserved - .env - Active environment config (not in git) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
307 lines
10 KiB
Go
307 lines
10 KiB
Go
package main
|
||
|
||
import (
|
||
"fmt"
|
||
"math"
|
||
)
|
||
|
||
// ProfitabilityCalculator performs detailed MEV bot profitability analysis
|
||
type ProfitabilityCalculator struct {
|
||
// Market parameters
|
||
dailyArbitrageVolume float64 // USD
|
||
averageOpportunitySize float64 // USD
|
||
marketSharePercentage float64 // 0-100
|
||
successRate float64 // 0-1
|
||
averageProfitMargin float64 // 0-1
|
||
|
||
// Cost parameters
|
||
gasPerTransaction float64 // USD
|
||
infrastructureCostMonthly float64 // USD
|
||
developmentCostMonthly float64 // USD
|
||
capitalRequirement float64 // USD
|
||
|
||
// Competition parameters
|
||
competitionLevel float64 // 0-1 (0 = no competition, 1 = intense)
|
||
gasPremiumFactor float64 // Gas multiplier due to competition
|
||
|
||
// Risk parameters
|
||
maxDailyLoss float64 // USD
|
||
slippageImpact float64 // 0-1
|
||
failureRate float64 // 0-1
|
||
}
|
||
|
||
// ProfitabilityResults contains the results of profitability analysis
|
||
type ProfitabilityResults struct {
|
||
// Revenue metrics
|
||
DailyOpportunities int
|
||
DailyGrossRevenue float64
|
||
DailyNetRevenue float64
|
||
MonthlyNetProfit float64
|
||
AnnualNetProfit float64
|
||
|
||
// Cost metrics
|
||
DailyGasCosts float64
|
||
MonthlyOperatingCosts float64
|
||
AnnualOperatingCosts float64
|
||
|
||
// Performance metrics
|
||
ROIPercentage float64
|
||
BreakEvenDays int
|
||
ProfitPerTrade float64
|
||
|
||
// Risk metrics
|
||
MaxDrawdownDaily float64
|
||
WorstCaseScenario float64
|
||
ProfitabilityScore float64 // 0-100
|
||
}
|
||
|
||
// NewProfitabilityCalculator creates a calculator with Arbitrum L2 defaults
|
||
func NewProfitabilityCalculator() *ProfitabilityCalculator {
|
||
return &ProfitabilityCalculator{
|
||
// Realistic Arbitrum market estimates
|
||
dailyArbitrageVolume: 2000000, // $2M daily arbitrage volume
|
||
averageOpportunitySize: 100, // $100 average opportunity
|
||
marketSharePercentage: 1.0, // 1% market capture (realistic)
|
||
successRate: 0.75, // 75% success rate
|
||
averageProfitMargin: 0.015, // 1.5% average profit margin
|
||
|
||
// Arbitrum L2 cost structure (much lower than Ethereum)
|
||
gasPerTransaction: 0.25, // $0.25 average gas per transaction
|
||
infrastructureCostMonthly: 800, // $800/month infrastructure
|
||
developmentCostMonthly: 3000, // $3000/month development equivalent
|
||
capitalRequirement: 5000, // $5000 working capital
|
||
|
||
// Competition assumptions
|
||
competitionLevel: 0.6, // Moderate competition
|
||
gasPremiumFactor: 1.2, // 20% gas premium for priority
|
||
|
||
// Risk parameters
|
||
maxDailyLoss: 500, // $500 max daily loss
|
||
slippageImpact: 0.002, // 0.2% slippage impact
|
||
failureRate: 0.15, // 15% transaction failure rate
|
||
}
|
||
}
|
||
|
||
// CalculateProfitability performs comprehensive profitability analysis
|
||
func (pc *ProfitabilityCalculator) CalculateProfitability() *ProfitabilityResults {
|
||
// Calculate daily opportunities
|
||
marketValue := pc.dailyArbitrageVolume * (pc.marketSharePercentage / 100)
|
||
dailyOpportunities := int(marketValue / pc.averageOpportunitySize)
|
||
|
||
// Calculate successful trades
|
||
successfulTrades := float64(dailyOpportunities) * pc.successRate
|
||
|
||
// Calculate gross revenue
|
||
grossProfitPerTrade := pc.averageOpportunitySize * pc.averageProfitMargin
|
||
dailyGrossRevenue := successfulTrades * grossProfitPerTrade
|
||
|
||
// Apply competition impact
|
||
competitionReduction := pc.competitionLevel * 0.3 // 30% max reduction
|
||
dailyGrossRevenue *= (1 - competitionReduction)
|
||
|
||
// Apply slippage impact
|
||
dailyGrossRevenue *= (1 - pc.slippageImpact)
|
||
|
||
// Calculate costs
|
||
dailyGasCosts := successfulTrades * pc.gasPerTransaction * pc.gasPremiumFactor
|
||
|
||
// Add failed transaction costs
|
||
failedTrades := float64(dailyOpportunities) * pc.failureRate
|
||
dailyGasCosts += failedTrades * pc.gasPerTransaction * 0.5 // Partial gas on failure
|
||
|
||
// Calculate net revenue
|
||
dailyNetRevenue := dailyGrossRevenue - dailyGasCosts
|
||
|
||
// Monthly calculations
|
||
monthlyGrossRevenue := dailyGrossRevenue * 30
|
||
monthlyGasCosts := dailyGasCosts * 30
|
||
monthlyOperatingCosts := monthlyGasCosts + pc.infrastructureCostMonthly + pc.developmentCostMonthly
|
||
monthlyNetProfit := monthlyGrossRevenue - monthlyOperatingCosts
|
||
|
||
// Annual calculations
|
||
annualNetProfit := monthlyNetProfit * 12
|
||
annualOperatingCosts := monthlyOperatingCosts * 12
|
||
|
||
// ROI calculation
|
||
roiPercentage := (annualNetProfit / pc.capitalRequirement) * 100
|
||
|
||
// Break-even calculation
|
||
breakEvenDays := int(pc.capitalRequirement / math.Max(dailyNetRevenue, 1))
|
||
|
||
// Profit per trade
|
||
profitPerTrade := dailyNetRevenue / successfulTrades
|
||
|
||
// Risk calculations
|
||
maxDrawdownDaily := math.Min(pc.maxDailyLoss, dailyNetRevenue*0.5)
|
||
worstCaseScenario := monthlyNetProfit * 0.3 // 70% reduction scenario
|
||
|
||
// Profitability score (0-100)
|
||
profitabilityScore := pc.calculateProfitabilityScore(roiPercentage, float64(breakEvenDays), profitPerTrade)
|
||
|
||
return &ProfitabilityResults{
|
||
DailyOpportunities: dailyOpportunities,
|
||
DailyGrossRevenue: dailyGrossRevenue,
|
||
DailyNetRevenue: dailyNetRevenue,
|
||
MonthlyNetProfit: monthlyNetProfit,
|
||
AnnualNetProfit: annualNetProfit,
|
||
DailyGasCosts: dailyGasCosts,
|
||
MonthlyOperatingCosts: monthlyOperatingCosts,
|
||
AnnualOperatingCosts: annualOperatingCosts,
|
||
ROIPercentage: roiPercentage,
|
||
BreakEvenDays: breakEvenDays,
|
||
ProfitPerTrade: profitPerTrade,
|
||
MaxDrawdownDaily: maxDrawdownDaily,
|
||
WorstCaseScenario: worstCaseScenario,
|
||
ProfitabilityScore: profitabilityScore,
|
||
}
|
||
}
|
||
|
||
// calculateProfitabilityScore creates a composite score for profitability
|
||
func (pc *ProfitabilityCalculator) calculateProfitabilityScore(roi, breakEven float64, profitPerTrade float64) float64 {
|
||
// ROI component (0-40 points)
|
||
roiScore := math.Min(roi/10, 40) // 10% ROI = 1 point, capped at 40
|
||
|
||
// Break-even component (0-30 points)
|
||
breakEvenScore := math.Max(30-(breakEven/2), 0) // Faster break-even = higher score
|
||
|
||
// Profit per trade component (0-30 points)
|
||
profitScore := math.Min(profitPerTrade*3, 30) // $10 per trade = 30 points
|
||
|
||
return roiScore + breakEvenScore + profitScore
|
||
}
|
||
|
||
// RunScenarioAnalysis runs multiple scenarios for sensitivity analysis
|
||
func (pc *ProfitabilityCalculator) RunScenarioAnalysis() map[string]*ProfitabilityResults {
|
||
scenarios := make(map[string]*ProfitabilityResults)
|
||
|
||
// Store original values
|
||
originalSuccess := pc.successRate
|
||
originalCompetition := pc.competitionLevel
|
||
originalMarketShare := pc.marketSharePercentage
|
||
|
||
// Conservative scenario
|
||
pc.successRate = 0.65
|
||
pc.competitionLevel = 0.8
|
||
pc.marketSharePercentage = 1.5
|
||
scenarios["Conservative"] = pc.CalculateProfitability()
|
||
|
||
// Moderate scenario
|
||
pc.successRate = 0.75
|
||
pc.competitionLevel = 0.6
|
||
pc.marketSharePercentage = 2.5
|
||
scenarios["Moderate"] = pc.CalculateProfitability()
|
||
|
||
// Optimistic scenario
|
||
pc.successRate = 0.85
|
||
pc.competitionLevel = 0.4
|
||
pc.marketSharePercentage = 4.0
|
||
scenarios["Optimistic"] = pc.CalculateProfitability()
|
||
|
||
// Restore original values
|
||
pc.successRate = originalSuccess
|
||
pc.competitionLevel = originalCompetition
|
||
pc.marketSharePercentage = originalMarketShare
|
||
|
||
return scenarios
|
||
}
|
||
|
||
// PrintDetailedReport prints a comprehensive profitability report
|
||
func PrintDetailedReport(results *ProfitabilityResults, scenario string) {
|
||
fmt.Printf("\n=== %s SCENARIO PROFITABILITY REPORT ===\n", scenario)
|
||
fmt.Printf("📊 REVENUE METRICS:\n")
|
||
fmt.Printf(" Daily Opportunities: %d\n", results.DailyOpportunities)
|
||
fmt.Printf(" Daily Gross Revenue: $%.2f\n", results.DailyGrossRevenue)
|
||
fmt.Printf(" Daily Net Revenue: $%.2f\n", results.DailyNetRevenue)
|
||
fmt.Printf(" Monthly Net Profit: $%.2f\n", results.MonthlyNetProfit)
|
||
fmt.Printf(" Annual Net Profit: $%.2f\n", results.AnnualNetProfit)
|
||
|
||
fmt.Printf("\n💸 COST METRICS:\n")
|
||
fmt.Printf(" Daily Gas Costs: $%.2f\n", results.DailyGasCosts)
|
||
fmt.Printf(" Monthly Operating Costs: $%.2f\n", results.MonthlyOperatingCosts)
|
||
fmt.Printf(" Annual Operating Costs: $%.2f\n", results.AnnualOperatingCosts)
|
||
|
||
fmt.Printf("\n📈 PERFORMANCE METRICS:\n")
|
||
fmt.Printf(" ROI Percentage: %.1f%%\n", results.ROIPercentage)
|
||
fmt.Printf(" Break-even Days: %d\n", results.BreakEvenDays)
|
||
fmt.Printf(" Profit per Trade: $%.2f\n", results.ProfitPerTrade)
|
||
|
||
fmt.Printf("\n⚠️ RISK METRICS:\n")
|
||
fmt.Printf(" Max Daily Drawdown: $%.2f\n", results.MaxDrawdownDaily)
|
||
fmt.Printf(" Worst Case Monthly: $%.2f\n", results.WorstCaseScenario)
|
||
fmt.Printf(" Profitability Score: %.1f/100\n", results.ProfitabilityScore)
|
||
}
|
||
|
||
// GetProfitabilityGrade returns a letter grade based on profitability score
|
||
func GetProfitabilityGrade(score float64) string {
|
||
switch {
|
||
case score >= 90:
|
||
return "A+ (Exceptional)"
|
||
case score >= 80:
|
||
return "A (Excellent)"
|
||
case score >= 70:
|
||
return "B+ (Very Good)"
|
||
case score >= 60:
|
||
return "B (Good)"
|
||
case score >= 50:
|
||
return "C+ (Fair)"
|
||
case score >= 40:
|
||
return "C (Marginal)"
|
||
default:
|
||
return "D (Poor)"
|
||
}
|
||
}
|
||
|
||
func main() {
|
||
fmt.Println("🏦 MEV Bot Profitability Calculator")
|
||
fmt.Println("=====================================")
|
||
|
||
calculator := NewProfitabilityCalculator()
|
||
|
||
// Run base scenario
|
||
fmt.Println("\n🎯 BASE SCENARIO ANALYSIS:")
|
||
baseResults := calculator.CalculateProfitability()
|
||
PrintDetailedReport(baseResults, "BASE")
|
||
|
||
// Run scenario analysis
|
||
fmt.Println("\n🔄 SCENARIO SENSITIVITY ANALYSIS:")
|
||
scenarios := calculator.RunScenarioAnalysis()
|
||
|
||
for scenario, results := range scenarios {
|
||
PrintDetailedReport(results, scenario)
|
||
fmt.Printf(" Profitability Grade: %s\n", GetProfitabilityGrade(results.ProfitabilityScore))
|
||
}
|
||
|
||
// Summary comparison
|
||
fmt.Println("\n📋 SCENARIO COMPARISON SUMMARY:")
|
||
fmt.Println("Scenario | Annual Profit | ROI | Break-even | Grade")
|
||
fmt.Println("------------- | ------------- | ------ | ---------- | -----")
|
||
|
||
for scenario, results := range scenarios {
|
||
fmt.Printf("%-13s | $%11.0f | %5.1f%% | %8d d | %s\n",
|
||
scenario,
|
||
results.AnnualNetProfit,
|
||
results.ROIPercentage,
|
||
results.BreakEvenDays,
|
||
GetProfitabilityGrade(results.ProfitabilityScore))
|
||
}
|
||
|
||
// Investment recommendation
|
||
fmt.Println("\n💡 INVESTMENT RECOMMENDATION:")
|
||
avgROI := (scenarios["Conservative"].ROIPercentage +
|
||
scenarios["Moderate"].ROIPercentage +
|
||
scenarios["Optimistic"].ROIPercentage) / 3
|
||
|
||
if avgROI > 200 {
|
||
fmt.Println("🟢 HIGHLY RECOMMENDED - Exceptional returns with manageable risk")
|
||
} else if avgROI > 100 {
|
||
fmt.Println("🟡 RECOMMENDED - Good returns, monitor competition carefully")
|
||
} else if avgROI > 50 {
|
||
fmt.Println("🟠 PROCEED WITH CAUTION - Moderate returns, higher risk")
|
||
} else {
|
||
fmt.Println("🔴 NOT RECOMMENDED - Returns too low for risk level")
|
||
}
|
||
|
||
fmt.Printf("\nAverage ROI across scenarios: %.1f%%\n", avgROI)
|
||
fmt.Printf("Risk-adjusted recommendation: Deploy with conservative parameters\n")
|
||
}
|