saving in place

This commit is contained in:
Krypto Kajun
2025-10-04 09:31:02 -05:00
parent 76c1b5cee1
commit f358f49aa9
295 changed files with 72071 additions and 17209 deletions

View File

@@ -169,6 +169,14 @@ func (pf *PriceFeed) GetBestArbitrageOpportunity(tokenA, tokenB common.Address,
// Gross profit
grossProfit := new(big.Float).Sub(revenue, tradeAmount)
// Validate that the profit calculation is reasonable
grossProfitFloat, _ := grossProfit.Float64()
tradeAmountFloat, _ := tradeAmount.Float64()
if grossProfitFloat > tradeAmountFloat*100 { // If profit is more than 100x the trade amount, it's unrealistic
pf.logger.Debug(fmt.Sprintf("Unrealistic arbitrage opportunity detected: tradeAmount=%s, grossProfit=%s", tradeAmount.String(), grossProfit.String()))
return nil // Reject this opportunity as unrealistic
}
return &ArbitrageRoute{
TokenA: tokenA,
TokenB: tokenB,
@@ -275,6 +283,12 @@ func (pf *PriceFeed) updatePriceFromDEX(ctx context.Context, tokenA, tokenB comm
mockPrice = big.NewFloat(1999.5)
}
// Validate that the price is reasonable (not extremely high or low)
if mockPrice.Cmp(big.NewFloat(0.000001)) < 0 || mockPrice.Cmp(big.NewFloat(10000000)) > 0 {
pf.logger.Debug(fmt.Sprintf("Invalid price detected for %s: %s, marking as invalid", dexName, mockPrice.String()))
mockPrice = big.NewFloat(1000.0) // Default to reasonable price
}
pf.priceCache[key] = &PriceData{
TokenA: tokenA,
TokenB: tokenB,

View File

@@ -187,10 +187,18 @@ func (spc *ProfitCalculator) AnalyzeSwapOpportunity(
opportunity.NetProfit = netProfit
// Calculate profit margin
if amountOut.Sign() > 0 {
if amountOut.Sign() > 0 && amountOut.Cmp(big.NewFloat(0)) != 0 {
profitMargin := new(big.Float).Quo(netProfit, amountOut)
profitMarginFloat, _ := profitMargin.Float64()
opportunity.ProfitMargin = profitMarginFloat
// Ensure the profit margin is reasonable and not extremely high
if profitMarginFloat > 1.0 { // 100% profit margin is unrealistic
opportunity.ProfitMargin = 0.0 // Set to 0 if profit margin is unrealistic
opportunity.IsExecutable = false
opportunity.RejectReason = "unrealistic profit margin"
opportunity.Confidence = 0.0
} else {
opportunity.ProfitMargin = profitMarginFloat
}
}
// Determine if executable (considering both profit and slippage risk)