Query editor
with redeem_tx as(SELECT block_time,tx_hash, tx_from AS address, varbinary_to_uint256(bytearray_substring(data,1,32))/1e18 as amount, 'redeem' as tx_typefrom ethereum.logsWHERE contract_address=0x35D8949372D46B7a3D5A56006AE77B215fc69bC0 AND topic0 IN (0x9b6e6ec489721a801f766aaa8e65020f7410bbb32dcf12be0160c0c86a72b6ed)UNION ALLSELECT block_time,tx_hash, tx_from AS address, varbinary_to_uint256(bytearray_substring(data,1,32))/1e18 as amount, 'redeem' as tx_typefrom ethereum.logsWHERE contract_address=0x35D8949372D46B7a3D5A56006AE77B215fc69bC0 AND topic0 IN (0x5dc2bb8ffcb5d122a24ce4bc2f0b5e89616fb1cd8a437a7275001e5ed28a44c2)AND tx_to=0x35d8949372d46b7a3d5a56006ae77b215fc69bc0),deposit_tx as (SELECTblock_time,tx_hash,varbinary_ltrim(topic2) AS address,varbinary_to_uint256(bytearray_substring(data,1,32))/1e18 as amount,'deposit' as tx_typeFROMethereum.logsWHERE-- Replace with the token contract you're interested incontract_address = 0x35D8949372D46B7a3D5A56006AE77B215fc69bC0-- ERC-20 Transfer event signature hashAND topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef-- topic2 is the `to` address (recipient)AND topic2 IS NOT NULL),transactions as (select * from redeem_tx UNION ALL select * from deposit_tx),arb_tx as (SELECTr.tx_hash AS redeem_id,r.block_time AS redeem_time,d.tx_hash AS deposit_id,d.block_time AS deposit_time,r.address,r.amount AS redeem_amount,d.amount AS deposit_amountFROMtransactions rJOINtransactions dON r.address = d.addressAND d.tx_type = 'deposit'AND r.tx_type = 'redeem'AND r.block_time >= d.block_timeAND r.block_time <= d.block_time + INTERVAL '10' minuteAND d.amount>=r.amountORDER BYr.address,r.block_time),distinct_redeem_tx as (select distinct redeem_id, redeem_amount, addressfrom arb_tx)