Query editor
-- =====================================================================-- 07 - VAULT ACTIONS: one row per user action (Deposit / Withdraw) on every client vault-- =====================================================================-- Event-level companion to 01_vault_metrics_daily.sql: the SAME registry,-- the SAME per-chain log scan and the SAME unit model, but instead of-- aggregating per day it returns every single action:---- action = 'Deposit' ERC-4626 Deposit (topic0 0xdcbc1c05...) user enters-- action = 'Withdraw' ERC-4626 Withdraw (topic0 0xfbde797d...) user exits---- USER ACTIONS ONLY. Harvested (protocol yield accrual + fee-share mint)-- is deliberately NOT a row here: it moves no user principal. Fee /-- harvest accounting lives in 01_vault_metrics_daily.sql. Harvest fee-- mints still flow into `vault_shares_after` (they are share Transfers-- from 0x0), so the post-action supply stays exact.---- Per row: who (sender / receiver / owner), what (assets + shares, signed-- so deposits are +, withdrawals -), worth (USD at that day's price), the-- implied underlying-per-share of that exact event, the vault's share-- supply + TVL right AFTER the action, and per-vault running cumulatives-- (deposits / withdrawals / net flow).---- Unit model (verified on-chain per vault, 2026-07-24/25 - see 01):-- * Deposit/Withdraw `assets` are in FINAL UNDERLYING units-- (USDC/EURC/WETH/...). amount = raw / 10^und_dec.-- * Supply at each log = running sum of share mint/burn Transfers ordered-- by (block_number, log_index). The mint/burn Transfer PRECEDES its-- Deposit/Withdraw event in the same tx (verified), so the supply read-- at an action row is the post-action supply.---- Event layouts (raw `data` words are 32 bytes, 1-indexed offsets):-- Deposit (sender idx, owner idx, assets, shares)-- topic1 = sender, topic2 = owner, data[1]=assets data[33]=shares-- Withdraw(sender idx, receiver idx, owner idx, assets, shares)-- topic1 = sender, topic2 = receiver, topic3 = owner, data[1]=assets data[33]=shares---- `user_address` = the economic owner: Deposit.owner (receives the shares),-- Withdraw.owner (whose shares are burned).---- Cost: same scan shape as 01 (same addresses, same block_date filters,-- prices.day) minus the Harvested topic. If 01 is materialized, this one should be too; it returns-- one row per event (tens of thousands), so trim with the commented-- WHERE filters at the bottom when embedding in a dashboard table.---- Keep in sync with 01: when a vault is added there, add it to the-- registry AND to that chain's contract_address IN (...) list here.-- =====================================================================WITHvaults AS (-- ================= VAULT REGISTRY =================-- One row per client vault (OAV). Verified on-chain 2026-07-24/25:-- * vault = the client ERC-4626 vault proxy. Emits Deposit/Withdraw/Harvested.-- * IMPORTANT: event amounts (Deposit/Withdraw `assets`, Harvested `totalUnderlying`)-- are denominated in the FINAL UNDERLYING (USDC/EURC/WETH/...), NOT in the vault-- asset() token. Verified per-vault by comparing event ratios against on-chain-- totalAssets/totalSupply across all chains.-- * intermediate/int_symbol = informational: the receipt token the vault allocates into.-- share_dec = the vault share token decimals (== intermediate decimals, verified).-- * price_* = where to read the USD price in prices.day (USDG on Robinhood Chain has-- no feed -> Ethereum USDG token). price_group fallback: usd->1.0, eur->EURC, mkt->none.