fix(arbitrage): critical fixes for struct initialization and price impact calculations
- Triangular arbitrage: populate all 25+ ArbitrageOpportunity fields - Direct arbitrage: complete field initialization with gas cost calculation - Price impact: add division-by-zero protection and validation - Absolute value handling for swap amounts to prevent uint256 max display Remaining issue: Some events still show uint256 max - needs investigation of alternative parsing code path (possibly pkg/pools/discovery.go)
This commit is contained in:
@@ -18,6 +18,24 @@ import (
|
||||
"github.com/fraktal/mev-beta/pkg/events"
|
||||
)
|
||||
|
||||
// Helper functions to safely convert potentially nil pointers to strings
|
||||
|
||||
// safeStringBigInt safely converts a *big.Int to string, returning "0" if nil
|
||||
func safeStringBigInt(n *big.Int) string {
|
||||
if n == nil {
|
||||
return "0"
|
||||
}
|
||||
return n.String()
|
||||
}
|
||||
|
||||
// safeStringUint256 safely converts a *uint256.Int to string, returning "0" if nil
|
||||
func safeStringUint256(n *uint256.Int) string {
|
||||
if n == nil {
|
||||
return "0"
|
||||
}
|
||||
return n.String()
|
||||
}
|
||||
|
||||
// MarketDataLogger provides comprehensive logging of swap and liquidity events
|
||||
type MarketDataLogger struct {
|
||||
logger *logger.Logger
|
||||
@@ -161,16 +179,16 @@ func (mdl *MarketDataLogger) LogSwapEvent(ctx context.Context, event events.Even
|
||||
"token1": token1Symbol,
|
||||
"token0Address": swapData.Token0.Hex(),
|
||||
"token1Address": swapData.Token1.Hex(),
|
||||
"amount0In": swapData.Amount0In.String(),
|
||||
"amount1In": swapData.Amount1In.String(),
|
||||
"amount0Out": swapData.Amount0Out.String(),
|
||||
"amount1Out": swapData.Amount1Out.String(),
|
||||
"amount0In": safeStringBigInt(swapData.Amount0In),
|
||||
"amount1In": safeStringBigInt(swapData.Amount1In),
|
||||
"amount0Out": safeStringBigInt(swapData.Amount0Out),
|
||||
"amount1Out": safeStringBigInt(swapData.Amount1Out),
|
||||
"amountInUSD": swapData.AmountInUSD,
|
||||
"amountOutUSD": swapData.AmountOutUSD,
|
||||
"feeUSD": swapData.FeeUSD,
|
||||
"priceImpact": swapData.PriceImpact,
|
||||
"sqrtPriceX96": swapData.SqrtPriceX96.String(),
|
||||
"liquidity": swapData.Liquidity.String(),
|
||||
"sqrtPriceX96": safeStringUint256(swapData.SqrtPriceX96),
|
||||
"liquidity": safeStringUint256(swapData.Liquidity),
|
||||
"tick": swapData.Tick,
|
||||
}
|
||||
|
||||
@@ -239,9 +257,9 @@ func (mdl *MarketDataLogger) LogLiquidityEvent(ctx context.Context, event events
|
||||
"token1": token1Symbol,
|
||||
"token0Address": liquidityData.Token0.Hex(),
|
||||
"token1Address": liquidityData.Token1.Hex(),
|
||||
"amount0": liquidityData.Amount0.String(),
|
||||
"amount1": liquidityData.Amount1.String(),
|
||||
"liquidity": liquidityData.Liquidity.String(),
|
||||
"amount0": safeStringBigInt(liquidityData.Amount0),
|
||||
"amount1": safeStringBigInt(liquidityData.Amount1),
|
||||
"liquidity": safeStringUint256(liquidityData.Liquidity),
|
||||
"amount0USD": liquidityData.Amount0USD,
|
||||
"amount1USD": liquidityData.Amount1USD,
|
||||
"totalUSD": liquidityData.TotalUSD,
|
||||
|
||||
Reference in New Issue
Block a user