Monitor totalSupply of cbETH (via Interval)

Here is an example to monitor total Supply of cbETH.

const blockHandler = async function(_:any, ctx: StakedTokenV1Context) {
  const tokenInfo = await token.getERC20TokenInfo(ctx.contract.address)
  const totalSupply = (await ctx.contract.totalSupply()).scaleDown(tokenInfo.decimal)
  ctx.meter.Gauge("total_supply").record(totalSupply, {token: tokenInfo.symbol})
}

StakedTokenV1Processor.bind({address: CBETH_PROXY})
  .onBlockInterval(blockHandler)

You could also write it using Time Interval instead of block

StakedTokenV1Processor.bind({address: CBETH_PROXY})
    .onTimeInterval(blockHandler)

Here, you could see

  • The totalSupply can be accessed by calling ctx.contract.totalSupply()

  • You can submit the metric total_supply typed Gauge by calling ctx.meter.Gauge("total_supply").record(totalSupply, {token: tokenInfo.symbol})

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

Last updated