Query editor
WITH instructions AS (SELECT*, row_number() over (partition by tx_id order by outer_instruction_index asc, COALESCE(inner_instruction_index,0) asc) as log_indexFROM solana.instruction_callsWHERE executing_account = 'PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu'AND (bytearray_substring(data,1+8,8) = 0xf5715534d6bb9984 -- IncreasePositionOR bytearray_substring(data,1+8,8) = 0x409c2b4a6d83107f -- DecreasePositionOR bytearray_substring(data,1+8,8) = 0x68452084d423bf2f -- LiquidatePosition)AND tx_success = trueAND block_time >= DATE_TRUNC('day', NOW() - INTERVAL '700' day)), positions AS (-- IncreasePosition(SELECT'increase_position' AS label, bytearray_to_bigint(bytearray_reverse(bytearray_substring(data,1+291,8))) / 1000000.0 as size_usd, log_index, block_slot, block_time, tx_id, tx_signerFROM instructionsWHERE bytearray_substring(data,1+8,8) = 0xf5715534d6bb9984)UNION-- DecreasePosition(SELECT'decrease_position' AS label, bytearray_to_bigint(bytearray_reverse(bytearray_substring(data,1+292,8))) / 1000000.0 AS size_usd, log_index, block_slot, block_time, tx_id, tx_signerFROM instructionsWHERE bytearray_substring(data,1+8,8) = 0x409c2b4a6d83107f)UNION-- LiquidatePosition(SELECT'liquidate_position' AS label, bytearray_to_bigint(bytearray_reverse(bytearray_substring(data,1+177,8))) / 1000000.0 AS size_usd, log_index, block_slot, block_time, tx_id, tx_signerFROM instructionsWHERE bytearray_substring(data,1+8,8) = 0x68452084d423bf2f))SELECTSUM(size_usd) AS volume, DATE_TRUNC('day', block_time) AS day