Query editor
-- This a fact table on logOperate where all supply and borrowing transactions passes through this function-- dim_product_gold: https://dune.com/queries/4182301-- bitwise decoding taken from: https://dune.com/queries/4119818with decode_logoperate as (selectblock_time, tx_hash, tx_from, tx_to, index as event_index, varbinary_ltrim(topic1) as product_address -- can be a vault or ftoken address, varbinary_ltrim(topic2) as asset_address, bytearray_to_int256(bytearray_substring(data,1,32)) as supply_amount, bytearray_to_int256(bytearray_substring(data,33,32)) as borrow_amount, bytearray_ltrim(bytearray_substring(data, 65, 32)) as withdraw_to, bytearray_ltrim(bytearray_substring(data, 97, 32)) as borrow_toFROM arbitrum.logswhere contract_address = 0x52Aa899454998Be5b000Ad077a46Bbe360F4e497and block_time >= timestamp '2024-02-16'and (topic0 = 0x4d93b232a24e82b284ced7461bf4deacffe66759d5c24513e6f29e571ad78d15)-- or topic0=0xeAbBfca72F8a8bf14C4ac59e69ECB2eB69F0811C)-- and topic0=0xfef64760e30a41b9d5ba7dd65ff7236a61d89ed8b44c67a29e84db1a67513a1c)selectblock_time, tx_hash, tx_from as from_address, tx_to, event_index, product_address, asset_address, supply_amount, borrow_amount, withdraw_to, borrow_to, sum(supply_amount) over (order by block_time asc, event_index asc) as rolling_supply_amount, sum(borrow_amount) over (order by block_time asc, event_index asc) as rolling_borrow_amountfromdecode_logoperate -- 0xbd96e3a4d78d4f1d629b8710fc6c375b64fad6f87d84033d6ede4bc041d2f541where product_address = 0xBFADEA65591235f38809076e14803Ac84AcF3F97order by block_time desc, event_index desc