Monitor Coinbase cbETH Mint/Burn (via Events)

Here is an example to monitor cbETH mint/burn events.

import { MintEvent, BurnEvent, StakedTokenV1Context, StakedTokenV1Processor } 
from "./types/eth/stakedtokenv1.js"

Then you write the simple callback that is triggered on different event (generated by Sentio).

  • Mint

  • Burn

Thus the corresponding code is:

const mintEventHandler = async function(event: MintEvent, ctx: StakedTokenV1Context) {
  const tokenInfo = await token.getERC20TokenInfo(ctx.contract.address)
  const amount = event.args.amount.scaleDown(tokenInfo.decimal)
  mint.record(ctx, amount, {fromHandler: "event", token: tokenInfo.symbol})
  mintAcc.add(ctx, amount, {fromHandler: "event", token: tokenInfo.symbol})
}

const burnEventHandler = async function(event: BurnEvent, ctx: StakedTokenV1Context) {
  const tokenInfo = await token.getERC20TokenInfo(ctx.contract.address)
  const amount = event.args.amount.scaleDown(tokenInfo.decimal)
  burn.record(ctx, amount, {token: tokenInfo.symbol})
  burnAcc.add(ctx, amount, {token: tokenInfo.symbol})
}

StakedTokenV1Processor.bind({address: CBETH_PROXY})
  .onEventMint(mintEventHandler)
  .onEventBurn(burnEventHandler)

See the full guide of writing filters, see Handlers and Filters

See this repo for full implementation. To learn how to view metrics from the UI, go View Metrics

Last updated