fix(uniswap): correct slot0() ABI unpacking to enable pool data fetching

- Changed from UnpackIntoInterface to Unpack() method which returns values directly
- Added empty response check for V2 pools (no slot0 function)
- Improved error messages with byte counts and pool type detection
- This fix unblocks pool data fetching which was preventing arbitrage detection

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Krypto Kajun
2025-10-25 06:46:23 -05:00
parent 76d8b250de
commit fcf141c8ea

View File

@@ -170,16 +170,20 @@ func (p *UniswapV3Pool) callSlot0(ctx context.Context) (*Slot0Data, error) {
return nil, fmt.Errorf("failed to call slot0: %w", err)
}
// Unpack the result
var unpacked []interface{}
err = p.abi.UnpackIntoInterface(&unpacked, "slot0", result)
// CRITICAL FIX: Check for empty response (indicates V2 pool or invalid contract)
if len(result) == 0 {
return nil, fmt.Errorf("empty response from slot0 call - pool %s may be V2 (no slot0 function) or invalid contract", p.address.Hex())
}
// CRITICAL FIX: Use Unpack() method which returns values directly, not UnpackIntoInterface
unpacked, err := p.abi.Unpack("slot0", result)
if err != nil {
return nil, fmt.Errorf("failed to unpack slot0 result: %w", err)
return nil, fmt.Errorf("failed to unpack slot0 result (got %d bytes): %w", len(result), err)
}
// Ensure we have the expected number of return values
if len(unpacked) < 7 {
return nil, fmt.Errorf("unexpected number of return values from slot0: got %d, expected 7", len(unpacked))
return nil, fmt.Errorf("unexpected number of return values from slot0: got %d, expected 7 (pool may not be UniswapV3)", len(unpacked))
}
// Convert the unpacked values