Query editor
WITH current_balance AS (-- First, calculate the current balance by summing all INs and subtracting all OUTsSELECTSUM(CASE-- If your contract is the recipient, it's a positive amountWHEN "to" = 0x1D3F8fcfE508D7031c242E213B27FbE432f52c67 THEN CAST(value AS DOUBLE)-- If your contract is the sender, it's a negative amountELSE -CAST(value AS DOUBLE)END) / 1e8 AS amount -- Apply 8 decimals for CBBTCFROMerc20_base.evt_TransferWHEREcontract_address = 0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf -- Filter for ONLY the CBBTC tokenAND ("to" = 0x1D3F8fcfE508D7031c242E213B27FbE432f52c67 -- Transfers TO your contractOR "from" = 0x1D3F8fcfE508D7031c242E213B27FbE432f52c67 -- Transfers FROM your contract))-- Now, join with the price table to get the USD valueSELECTb.amount AS "Current CBBTC Balance",b.amount * p.price AS "Current USD Value"FROMcurrent_balance bLEFT JOINprices.usd_latest p ON p.contract_address = 0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf AND p.blockchain = 'base'