Events & Chart Integration

All events are emitted from Vault(=Router) contract.

CA references : zkSyncEra , Linea

Vault interface file link

SwapFacet implementation link

Example event logs :

ETH->USDC swap scan link

Add liquidity ETH+USDC scan link

magic deposit USD+=>USDC-ETH LP scan link (includes swap & staking)

Note that swap operation event includes swap, veVC conversion, and LP deposit/withdrawal. cf) Operation types

Swap

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

Whenever a user exchanges tokens with a pool, Swap event gets emitted.

  • pool

  • user is the user interacting with the pool.

  • tokenRef

    • Token: Velocore V2 supports not only ERC20 but also ERC721, ERC1155, and native tokens. Tokens are represented as a wrapped bytes32 (Token), specifically:

      • 1 byte of token type

        • 0x00: ERC20

        • 0x01: erc721

        • 0x02: erc1155

      • 11 bytes of token id:

        • always 0 for ERC20

        • nft id or token id for ERC721 and erc1155

        • token ids greater than 2^88 - 1 is unsupported

      • 20 bytes of token address

      • native token is represented as 0xeeeee...eeeee.

  • delta is the list of balance changes as the result of the interaction, in the same order as tokenRef

    • it is positive when pool received the token from the user (i.e. the user sold the token)

    • it is negative when user received the token from the pool (i.e. the user bought the token)

Swapis emitted both for LP deposit/withdrawal and simple swaps. The difference is that LP deposit/withdrawal event includes the LP token (having the same address as pool in the event), which represents that the user received/burned the LP token, whreas simple swaps dont.

function isSwap(pool, user, tokenRef, delta) {
    return (
        does any element of tokenRef has _pool_ as its last 20 bytes?
    );
}

Examples

  1. Pure swap event (Token<>ETH or Token<>Token)

Swap(
    pool: 0x42D106c4A1d0Bc5C482c11853A3868d807A3781d,
    user: 0x1234561fEd41DD2D867a038bBdB857f291864225,
    tokenRef: [
        "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
        "0x0000000000000000000000003355df6D4c9C3035724Fd0e3914dE96A5a83aaf4"
    ],
    delta: [
        100000000,
        -102301045
    ]
)

the event above tells that a user (0x1234561fEd41DD2D867a038bBdB857f291864225) interacted with the USDC/ETH pool (0x42D106c4A1d0Bc5C482c11853A3868d807A3781d, selling 100000000 wei of ethereum (0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee) for 102301045 wei of USDC (ERC20:0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4).

Price, Volume, trader's info could be drawn directly from above example.

  1. LP related event (add/remove LP, magic deposit)

Swap(
    pool: 0x42D106c4A1d0Bc5C482c11853A3868d807A3781d,
    user: 0x1234561fEd41DD2D867a038bBdB857f291864225,
    tokenRef: [
        "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
        "0x0000000000000000000000003355df6D4c9C3035724Fd0e3914dE96A5a83aaf4",
        "0x00000000000000000000000042D106c4A1d0Bc5C482c11853A3868d807A3781d",
    ],
    delta: [
        101240000,
        102301045,
        -100000000
    ]
)

the event above tells that a user (0x1234561fEd41DD2D867a038bBdB857f291864225) interacted with the USDC/ETH pool (0x42D106c4A1d0Bc5C482c11853A3868d807A3781d, depositing 101240000 wei of ethereum (0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee) and 102301045 wei of USDC (ERC20: 0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4), and received 100000000 wei of the LP token (42D106c4A1d0Bc5C482c11853A3868d807A3781d) in exchange.

Since unbalanced LP deposit(magic deposit) is possible, ratio here can't be used as a price feed unlike simple swap.

We recommend only using pure swap for price feed updates and chart volume data for easy integration. If the tokenRef contains an LP address, you can catch the event separately as an add/remove LP event and do not need to calculate the swap volume. This is because the swap volume generated by this will usually be a very small fraction of the total.

  1. Removing LP using Magic withdrawal ( ETH-USDC LP -> ETH )

Swap(
    pool: 0x42D106c4A1d0Bc5C482c11853A3868d807A3781d,
    user: 0x1234561fEd41DD2D867a038bBdB857f291864225,
    tokenRef: [
        "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
        "0x00000000000000000000000042D106c4A1d0Bc5C482c11853A3868d807A3781d",
    ],
    delta: [
        -202301045,
        100000000
    ]
)

the event above tells that a user (0x1234561fEd41DD2D867a038bBdB857f291864225) interacted with the USDC/ETH pool (0x42D106c4A1d0Bc5C482c11853A3868d807A3781d, returning 100000000 wei of the LP token (42D106c4A1d0Bc5C482c11853A3868d807A3781d), and receiving 202301045 wei of ethereum (0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee) in exchange.

Same as above, you could exactly calculate the swap volume using the fee generated, but that would require a reserve query. We'd recommend ignoring the swap volume here and just considering it as an LP related transaction when integrating to the chart.

Vote

event Vote(IGauge indexed pool, address indexed user, int256 voteDelta);

whenever a user votes or claims bribe, Vote gets emitted.

voteDelta is positive when the user adds vote, and negative when user decreases vote.

voteDelta can be 0, which means that the user just claimed the bribe.

Last updated