Query editor
-- Ethereum Trade USDC v3; full history through the last completed UTC day.-- Units are raw integers. This reconstructs cash, shares, and principal.-- Expected liquidity and accrued interest require additional accounting.with prev as (select * from table(previous.query.result(schema => descriptor(day date, cash_delta_raw int256, supply_delta_raw int256,principal_delta_raw int256, available_raw int256, supply_raw int256,borrowed_principal_raw int256)))), checkpoint as (select coalesce(max(day) - interval '7' day, date '2023-01-01') cutofffrom prev), events as (select cast(block_time as date) day, contract_address, topic0, topic1, topic2,cast(varbinary_to_uint256(varbinary_substring(data, 1, 32)) as int256) amountfrom ethereum.logswhere block_date >= (select cutoff from checkpoint)and block_date < current_dateand block_time >= cast((select cutoff from checkpoint) as timestamp)and block_time < cast(current_date as timestamp)and ((contract_address = 0xda00000035fef4082f78def6a8903bee419fbf8eand topic0 in (0x312a5e5e1079f5dda4e95dbbd0b908b291fd5b992ef22073643ab691572c5b52,0x2fe77b1c99aca6b022b8efc6e3e8dd1b48b30748709339b65c50ef3263443e09,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef))or (contract_address = 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48and topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efand (topic1 = 0x000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8eor topic2 = 0x000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e)))), recent as (select day,sum(case when contract_address = 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48then (case when topic2 = 0x000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e then amount else int256 '0' end)- (case when topic1 = 0x000000000000000000000000da00000035fef4082f78def6a8903bee419fbf8e then amount else int256 '0' end)else int256 '0' end) cash_delta_raw,sum(case when contract_address = 0xda00000035fef4082f78def6a8903bee419fbf8eand topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efthen (case when topic1 = 0x0000000000000000000000000000000000000000000000000000000000000000 then amount else int256 '0' end)- (case when topic2 = 0x0000000000000000000000000000000000000000000000000000000000000000 then amount else int256 '0' end)else int256 '0' end) supply_delta_raw,sum(case topic0when 0x312a5e5e1079f5dda4e95dbbd0b908b291fd5b992ef22073643ab691572c5b52 then amountwhen 0x2fe77b1c99aca6b022b8efc6e3e8dd1b48b30748709339b65c50ef3263443e09 then -amountelse int256 '0' end) principal_delta_rawfrom eventsgroup by day), daily as (select day, cash_delta_raw, supply_delta_raw, principal_delta_rawfrom prev where day < (select cutoff from checkpoint)union allselect day, cash_delta_raw, supply_delta_raw, principal_delta_raw from recent), calendar as (select day from unnest(sequence(date '2023-12-18', current_date - interval '1' day, interval '1' day)) as s(day))select c.day,coalesce(d.cash_delta_raw, int256 '0') cash_delta_raw,coalesce(d.supply_delta_raw, int256 '0') supply_delta_raw,