Query editor
-- -- -- https://stackoverflow.com/a/49030501SELECT(CASEWHEN row_number() OVER (ORDER BY SUM(pnl) DESC) = 1 THEN CONCAT('🥇', ' #1')WHEN row_number() OVER (ORDER BY SUM(pnl) DESC) = 2 THEN CONCAT('🥈', ' #2')WHEN row_number() OVER (ORDER BY SUM(pnl) DESC) = 3 THEN CONCAT('🥉', ' #3')when row_number() OVER (ORDER BY SUM(pnl) DESC) > 3 THEN format('#%d', row_number() OVER (ORDER BY SUM(pnl) DESC))END) as rankings, CONCAT('<a href=https://www.gmx.house/avalanche/account/', CAST(total_trader_pnls.account AS VARCHAR), ' target=_blank>',(CASEWHEN ens_lookup.name is not null then ens_lookup.namewhen total_trader_pnls.account = 0xe8c19db00287e3536075114b2576c70773e039bd THEN 'Andrew Kang (@Rewkang Twitter)'when total_trader_pnls.account = 0x284101246f8bb2a7e876a0b0feed776c8ea02474 THEN 'Func (@func_anon Twitter)'when total_trader_pnls.account = 0x9dbed1de02833275673fb87d37a40a6a1d424fcd THEN '420_Economics (@420_Economics Twitter)'WHEN total_trader_pnls.account = 0x1ea6a6085f2ce3e1f982684a28879761343ff4ce THEN 'Whitey McPaperson (@whitepapertrash Twitter)'ELSE CAST(total_trader_pnls.account AS VARCHAR)END), '</a>') as account, SUM(pnl) as total_pnl, MAX(block_time) as last_traded, MIN(block_time) as traded_sinceFROM (SELECT block_time, d_p.account, bytearray_to_int256(bytearray_substring(data, 1 + 32 * 6, 32))/1e30 - (closing_fee) as pnl, a_l.tx_hashFROM avalanche_c.logs as a_l join(SELECTbytearray_substring(data, 1, 32) as tx_key, bytearray_substring(data, 1 + 12 + 32, 20) as account, bytearray_to_uint256(bytearray_substring(data, 1 + 32 * 8, 32))/1e30 as closing_fee, tx_hashFROM avalanche_c.logsWHERE contract_address = 0x9ab2de34a33fb459b538c43f251eb825645e8595 and-- Method Signature for Decreasing/Closing Positiontopic0 = 0x93d75d64d1f84fc6f430a64fc578bdd4c1e090e90ea2d51773e626d19de56d30) as d_p on a_l.tx_hash = d_p.tx_hashWHERE contract_address = 0x9ab2de34a33fb459b538c43f251eb825645e8595 andtopic0 = 0x73af1d417d82c240fdb6d319b34ad884487c6bf2845d98980cc52ad9171cb455UNION ALLSELECTblock_time, bytearray_substring(data, 1 + 12 + 32, 20) as account-- NOT PNL this is the Fees, -bytearray_to_int256(bytearray_substring(data, 1 + 32 * 8, 32))/1e30 as pnl, tx_hashFROM avalanche_c.logsWHERE contract_address = 0x9ab2de34a33fb459b538c43f251eb825645e8595 and-- Opening Positiontopic0 = 0x2fe68525253654c21998f35787a8d0f361905ef647c854092430ab65f2f15022UNION ALLSELECT block_time, bytearray_substring(data, 1 + 12 + 32, 20) as account, -bytearray_to_int256(bytearray_substring(data, 1 + 32 * 6, 32))/1e30 - fees as pnl, a_l.tx_hashFROM avalanche_c.logs as a_l JOIN(SELECT tx_hash, bytearray_to_int256(bytearray_substring(data, 1 + 32, 32))/1e30 as feesFROM avalanche_c.logsWHERE topic0 = 0x5d0c0019d3d45fadeb74eff9d2c9924d146d000ac6bcf3c28bf0ac3c9baa011a