Byte32 Decoding
Decode amountsIn or amountsOut from the Swap event
amountsIn or amountsOut from the Swap eventfunction decodeAmounts(amounts: Bytes): [bigint, bigint] {
/**
* Decodes the amounts bytes input as 2 integers.
*
* @param amounts - amounts to decode.
* @return tuple of BigInts with the values decoded.
*/
// Convert amounts to a BigInt
const amountsBigInt = BigInt(`0x${Buffer.from(amounts).toString('hex')}`);
// Read the right 128 bits of the 256 bits
const amountsX = amountsBigInt & ((BigInt(2) ** BigInt(128)) - BigInt(1));
// Read the left 128 bits of the 256 bits
const amountsY = amountsBigInt >> BigInt(128);
return [amountsX, amountsY];
}Decode totalFees and protocolFees from Swap Event
totalFees and protocolFees from Swap EventLast updated