Decoding from custom ABIs

Sentio already has a list of built-in ABIs. However, you would still need to provide your own ABI so Sentio can generate type safe methods for you to write elegant processor code.

Here we use a Uniswap example to demonstrate how to do this. Assuming we want to monitor the DAI/USDC Uniswap pool. You could use #sentio-add to fetch the ABI automatically (we got it from etherscan).

ℹ️

If your ABI is not available from etherscan, you could manually copy the JSON data and put it into your directory abi/eth

Then you run:

yarn sentio build

It will generate all the types under src/types.

Then you can write functions using modern IDEs like IntelliJ or VSCode. It will show auto-complete on the method OnEventSwap (which corresponds to the event in the contract).

UniswapProcessor.bind({address: '0x5777d92f208679db4b9778590fa3cab3ac9e2168'})
    .onEventSwap(
        async function (event: SwapEvent, ctx: UniswapContext) {
            ctx.meter.Gauge('dai_usdc_amount0').record(Math.abs(Number(event.args.amount0.toBigInt())))
            ctx.meter.Gauge('dai_usdc_amount1').record(Math.abs(Number(event.args.amount1.toBigInt())))
        }
    )