From fcf141c8ea99cfb1b6fc2a751e21916603a14ca7 Mon Sep 17 00:00:00 2001 From: Krypto Kajun Date: Sat, 25 Oct 2025 06:46:23 -0500 Subject: [PATCH] fix(uniswap): correct slot0() ABI unpacking to enable pool data fetching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- pkg/uniswap/contracts.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/uniswap/contracts.go b/pkg/uniswap/contracts.go index 36faabd..289e64a 100644 --- a/pkg/uniswap/contracts.go +++ b/pkg/uniswap/contracts.go @@ -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