Query editor
-- This is a base query for monitoring balance changes on CoW Protocol---- The query collects all balance changes to the settlement contract. Those changes can come from-- - erc20 transfers-- - native transfers-- - chain specific event like deposits and withdrawals---- Parameters:-- {{start_time}} - the timestamp for which the analysis should start (inclusively)-- {{end_time}} - the timestamp for which the analysis should end (exclusively)-- {{blockchain}} - network to run the analysis on---- The columns of the result are:-- - block_time: time of settlement transaction-- - tx_hash: settlement transaction hash-- - token_address: address of token with a balance change. contract address for erc20 tokens,-- 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee for native token-- - sender: origin of transfers sending tokens to the settlement contract,-- 0x0000000000000000000000000000000000000000 for deposits/withdrawals-- - receiver: destination of transfer sending tokens from the settlement contract,-- 0x0000000000000000000000000000000000000000 for deposits/withdrawals-- - amount: value of the balance change in atoms of the token-- 1) data on all chains-- 1.1) erc20-- 1.2) native transfers-- 1.1) all the erc20 transfers to/from cow ammswith erc20_transfers as (selectevt_block_time as block_time,evt_tx_hash as tx_hash,contract_address as token_address,"from" as sender,to as receiver,value as amountfrom erc20_{{blockchain}}.evt_transferwhereevt_block_time >= cast('{{start_time}}' as timestamp) and evt_block_time < cast('{{end_time}}' as timestamp) -- partition columnand 0x9008d19f58aabd9ed0d60971565aa8510560ab41 in ("from", to)-- the conditions that follow are only needed for Lens, where for some reason the native token-- transfers, captured in the 0x000000000000000000000000000000000000800a address, are picked in-- the erc20_lens.evt_transfer table.-- As we are handling them later on in the same way as we do with all other chains, we decided to-- filter them out from this cteand (contract_address != 0x000000000000000000000000000000000000800a or '{{blockchain}}' != 'lens')),-- 1.2) all native token transfersnative_transfers as (selectblock_time,tx_hash,0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee as token_address,"from" as sender,to as receiver,value as amountfrom {{blockchain}}.traceswhereblock_time >= cast('{{start_time}}' as timestamp)