Interpreting Swap / LP events

Let's look into Swap/Liquidity Provision(=yield farming) example transactions to decode what happened!

Vault contract in Linea : here

both swap and LPing emits the same topic0,

Swap(address indexed pool, address indexed user, bytes32[] tokenRef, int128[] delta).

  • topic0: 0xbaec78ca3218aba6fc32d82b79acdd1a47663d7b8da46e0c00947206d08f2071

  • zip(tokenRef, delta) indicates the tokens and their amounts.

Example 1 : Swap

You could know these from the Logs above.

{
    pool: 0xe2c67a9b15e9e7ff8a9cb0dfb8fee5609923e5db,
    user: 0xd466896b200c616de9b9d08e40e912f4f401edfa,
    tokenRef: [
      000000000000000000000000176211869CA2B568F2A7D4EE941E073A821EE1FF, // address of USDC
      0xEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE, // this represents ETH
    ],
    delta: [
      -1736669, // amount of USDC, negative because the user received USDC.
      1107379247714709, // amount of ETH, positive because the user paid ETH.
    ]
  }
  • You should interpret sign(+ or -) in target pool's perspective. Negetive for USDC since USDC are removed from the pool and positive for ETH since it is added to the pool. See here for the details : How to interact with VELOCORE

Example 2 : Adding liquidity

//If tokenRef address is the pool address, it means you are exchanging with LP token
// Exchange with LP token means you are adding or removing liquidity!
const isLP = (event) => event.tokenRef.contains(event.pool)
{
    pool: 0xf3e3ec2861850dfa6ba3f52a271f499afffb8087,
    user: 0x1234561fed41dd2d867a038bbdb857f291864225,
    tokenRef: [
      0x000000000000000000000000CC22F6AA610D1B2A0E89EF228079CB3E1831B1D1, // address of LVC
      0x000000000000000000000000F3E3EC2861850DFA6BA3F52A271F499AFFFB8087, // address of the lp token, deducible as it equals the pool address
      0xEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE, // this represents ETH
    ],
    delta: [
      1000000000000000000, // amount of LVC, positive because the user paid LVC
      -2000673813932133, // amount of the lp token, negative because the user received lp token
      4002695726920, // amount of ETH, positive because the user paid ETH
    ]
  }

Last updated