Tracking Pool Balances

The LBPair contract emits DepositedToBins and WithdrawnFromBins events when users add or remove liquidity from the market.

We track the user balances in LBPairs by parsing these events.

  • Liquidity is deposited/withdrawn into multiple Bins, for which the Bin Ids are returned in array uint256[] ids.

  • Token amounts deposited/withdrawn are tracked by amounts, which is a of tuple [amountX, amountY] encoded into byte32.

  • The arrays amounts[] and ids[] correspond to the token amounts and Bin Ids of each corresponding Bin.

  • See Byte32 Decoding for more details.

DepositedToBins

    // ILBPair.sol
    event DepositedToBins(
      address indexed sender, 
      address indexed to, 
      uint256[] ids, 
      bytes32[] amounts
    );

WithdrawnFromBins

    // ILBPair.sol
    event WithdrawnFromBins(
      address indexed sender, 
      address indexed to, 
      uint256[] ids, 
      bytes32[] amounts
    );

Example Handler

Last updated