Byte32 Decoding
function 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, "hex").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];
}Last updated