Query editor
WITH RECURSIVEtoken_flow(evt_tx_hash, "from", "to", raw_value, depth, contract_address, evt_block_time) AS (-- Initial transfers from the GMX contractSELECT DISTINCTt.evt_tx_hash,t."from",t."to",t.value AS raw_value,1 AS depth,t.contract_address,t.evt_block_timeFROM erc20_arbitrum.evt_Transfer AS tWHEREt.contract_address = 0x912CE59144191C1204E64559FE8253a0e49E6548AND t."from" = 0xa079c6b032133b95cf8b3d273d27eeb6b110a469AND t.evt_block_time >= TIMESTAMP '2023-11-15'UNION ALL-- Subsequent transfers from new addresses, avoiding loopsSELECT DISTINCTt.evt_tx_hash,t."from",t."to",t.value as raw_value,tf.depth + 1 as depth,t.contract_address,t.evt_block_timeFROM erc20_arbitrum.evt_Transfer AS tJOIN token_flow AS tf ON t."from" = tf."to" AND t.evt_tx_hash != tf.evt_tx_hashAND t.evt_block_time > tf.evt_block_timeWHEREt.contract_address = 0x912CE59144191C1204E64559FE8253a0e49E6548and t."from" != 0x5ca1ea5549e4e7cb64ae35225e11865d2572b3f9AND tf.depth < 2 -- Adjust depth as needed),ranked_transfers(evt_tx_hash, "from", "to", raw_value, depth, contract_address, evt_block_time) AS (SELECT DISTINCTtf.evt_tx_hash,tf."from",tf."to",tf.raw_value,tf.depth,tf.contract_address,tf.evt_block_time--ROW_NUMBER() OVER (PARTITION BY tf.depth ORDER BY tf.raw_value DESC) AS rnFROM token_flow tf)SELECTdate--, rn, "from", "to", depth, tokensfrom (SELECTevt_block_time as date--, rn, "from"