Monitor Coinbase cbETH Mint/Burn (via Events)
Here is an example to monitor cbETH mint/burn events.
First, you import builtin ABIs for cbETH. (First fetch them by #sentio-add)
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
Updated 7 months ago