I am looking at a transaction's data:
Swap (index_topic_1 address sender, index_topic_2 address recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick)
and the hex data is:
0xffffffffffffffffffffffffffffffffffffffffffffffe653efdc88fa14d9d000000000000000000000000000000000000000000000001c574ce6000000000000000000000000000000000000000000000000011ad1d847f2d99bd6b83ba95c0000000000000000000000000000000000000000000000023b32292becc65a2200000000000000000000000000000000000000000000000000000000000007c8
I am trying to decode the arguments.
Decoding a positive integer is easy:
# remove the 0x
data = data[2:]
# decode the 64 char
amount1 = int(data[64:128], base=16)
assert amount1 == 522799489731071574016`
But I am failing to create a function that will decode the negative amount0 from bytes_amount0 = int(data[0:64], base=16).
I need a function that can decode both positive and negative int256 as I don't know in advance which is positive and which is negative.