export function handleDepositedToBins(event: DepositedToBins): void {
// We can get the tokenX and tokenY from the LBPair
const lbPair = LBPair.load(event.address.toHexString())
const tokenX = lbPair.tokenX
const tokenY = lbPair.tokenY
// get user
const user = User.load(event.to.toHexString())
// get amounts
const amounts = event.params.amounts
let amountX = 0
let amountY = 0
for (let i=0; i < amounts.length; i++) {
const _amounts = amounts[i]
// NOTE: reverse bytes to convert to big endianness
amounts.reverse()
const _amountX = decodeX(_amounts)
const _amountY = decodeY(_amounts)
amountX += _amountX
amountY += _amountY
}
}
// Assemblyscript API
// https://thegraph.com/docs/en/developing/assemblyscript-api/
function decodeX(packedAmounts: Bytes): BigInt {
// Read the right 128 bits of the 256 bits
return BigInt.fromUnsignedBytes(packedAmounts).bitAnd(BigInt.fromI32(2).pow(128).minus(BigInt.fromI32(1)))
}
function decodeY(packedAmounts: Bytes): BigInt {
// Read the left 128 bits of the 256 bits
return BigInt.fromUnsignedBytes(packedAmounts).rightShift(128)
}