Query editor
WITH flows AS (-- reuse daily net flow logicSELECTday,SUM(deposits - withdrawals) AS net_flowFROM (SELECTDATE_TRUNC('day', block_time) AS day,CAST(assets AS DECIMAL(38,0)) / 1e18 AS deposits,0 AS withdrawalsFROM TABLE(decode_evm_event(abi => '{"anonymous": false,"inputs": [{ "indexed": true, "name": "sender", "type": "address" },{ "indexed": true, "name": "onBehalf", "type": "address" },{ "indexed": false, "name": "assets", "type": "uint256" },{ "indexed": false, "name": "shares", "type": "uint256" }],"name": "Deposit","type": "event"}',input => TABLE(SELECT block_time, tx_hash, topic0, topic1, topic2, topic3, dataFROM megaeth.logsWHERE contract_address = 0x2eA493384F42d7Ea78564F3EF4C86986eAB4a890AND topic0 = 0xdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7)))UNION ALLSELECTDATE_TRUNC('day', block_time) AS day,0 AS deposits,CAST(assets AS DECIMAL(38,0)) / 1e18 AS withdrawalsFROM TABLE(decode_evm_event(abi => '{"anonymous": false,"inputs": [{ "indexed": true, "name": "sender", "type": "address" },{ "indexed": true, "name": "receiver", "type": "address" },{ "indexed": true, "name": "onBehalf", "type": "address" },{ "indexed": false, "name": "assets", "type": "uint256" },{ "indexed": false, "name": "shares", "type": "uint256" }],"name": "Withdraw","type": "event"}',input => TABLE(SELECT block_time, tx_hash, topic0, topic1, topic2, topic3, dataFROM megaeth.logsWHERE contract_address = 0x2eA493384F42d7Ea78564F3EF4C86986eAB4a890AND topic0 = 0xfbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db)