Skip to content

BUG: encode negative int16 wrong format #13

@guotie

Description

@guotie

When I read a uniswap v3 pool liquidity with TickLens contract, I encounter error:

My Code:

func TestTickLens(t *testing.T) {
	// Uniswap V3 pool ETH/USDC on base mainnet
	poolAddr := "0xd0b53D9277642d899DF5C87A3966A349A798F224"
	poolTickLensABI := defiabi.MustParseJSON([]byte(`[{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"int16","name":"tickBitmapIndex","type":"int16"}],"name":"getPopulatedTicksInWord","outputs":[{"components":[{"internalType":"int24","name":"tick","type":"int24"},{"internalType":"int128","name":"liquidityNet","type":"int128"},{"internalType":"uint128","name":"liquidityGross","type":"uint128"}],"internalType":"struct ITickLens.PopulatedTick[]","name":"populatedTicks","type":"tuple[]"}],"stateMutability":"view","type":"function"}]`))

	calldata := poolTickLensABI.Methods["getPopulatedTicksInWord"].MustEncodeArgs(poolAddr, -100)
	queryAddr := "0x0CdeE061c75D43c82520eD998C23ac2991c9ac6d" // Uniswap V3 TickLens contract address on base mainnet

	uri := "https://mainnet.base.org"
	tr, err := transport.NewHTTP(transport.HTTPOptions{URL: uri})
	assert.Nil(t, err)

	// Create a JSON-RPC client.
	client, err := rpc.NewClient(rpc.WithTransport(tr))
	assert.Nil(t, err)

	// Prepare a call.
	call := types.NewCall().
		SetTo(types.MustAddressFromHex(queryAddr)).
		SetInput(calldata)

	// 351fb478
	// 000000000000000000000000d0b53d9277642d899df5c87a3966a349a798f224
	// 000000000000000000000000000000000000000000000000000000000000ff9c
	println(hex.EncodeToString(calldata))

	// Call method.
	b, _, err := client.Call(context.Background(), call, types.LatestBlockNumber)
	if err != nil {
		panic(err)
	}
	_ = b
}

returns:

panic: RPC error: -32000 execution reverted

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions