Query editor
WITH RECURSIVE hierarchy(_from, _to, route, hierarchy_level, call_tx_hash, call_block_number) AS (SELECT e._from, e._to, cast(e._to as varchar) || ' <- ' || cast(e._from as varchar) as route, 1 AS hierarchy_level, e.call_tx_hash, e.call_block_numberFROM equalizer_exchange_fantom.VotingEscrow_call_merge eINNER JOIN fantom.transactions Txs ON call_tx_hash = Txs.hashWHERE Txs.block_number = call_block_number AND Txs.success = true AND call_success = trueUNION ALLSELECT e._from, hi._to, hi.route || ' <- ' || cast(e._from as varchar) AS route, hierarchy_level + 1 AS hierarchy_level, e.call_tx_hash, e.call_block_numberFROM hierarchy hiINNER JOIN equalizer_exchange_fantom.VotingEscrow_call_merge e ON hi._from = e._to and call_success = true and hierarchy_level < 5),allMerges(_to, _from, route) AS (SELECT hi._to, hi._from, hi.route FROM hierarchy hiINNER JOIN (SELECT _from, MAX(hierarchy_level) AS hierarchy_level FROM hierarchy GROUP BY _from) jON hi._from = j._from AND hi.hierarchy_level = j.hierarchy_levelINNER JOIN fantom.transactions Txs ON hi.call_tx_hash = Txs.hash WHERE Txs.block_number = hi.call_block_number AND Txs.success = true),allLocks(veNFT, EQUAL, unlock, lock) as (SELECT veNFT, EQUAL, unlock, lockFROM(SELECT output_0 as veNFT, cast(_value as double)/1e18 as EQUAL,from_unixtime(to_unixtime(call_block_time) + cast(_lock_duration as double)) as unlock,cast(_lock_duration as double)/604800 as lockFROM equalizer_exchange_fantom.VotingEscrow_call_create_lock_forWHERE call_success = trueUNION ALLSELECT output_0 as veNFT, cast(_value as double)/1e18 as EQUAL,from_unixtime(to_unixtime(call_block_time) + cast(_lock_duration as double)) as unlock,cast(_lock_duration as double)/604800 as lockFROM equalizer_exchange_fantom.VotingEscrow_call_create_lockWHERE call_success = trueUNION ALLSELECT _tokenId as veNFT, null as EQUAL,from_unixtime(to_unixtime(call_block_time) + cast(_lock_duration as double)) as unlock,cast(_lock_duration as double)/604800 as lockFROM equalizer_exchange_fantom.VotingEscrow_call_increase_unlock_timeWHERE call_success = trueUNION ALLSELECT _tokenId as veNFT, cast(_value as double)/1e18 as EQUAL, null as unlock, null as lockFROM equalizer_exchange_fantom.VotingEscrow_call_increase_amount_forWHERE call_success = trueUNION ALLSELECT _tokenId as veNFT, cast(_value as double)/1e18 as EQUAL, null as unlock, null as lockFROM equalizer_exchange_fantom.VotingEscrow_call_increase_amountWHERE call_success = trueUNION ALLSELECT tokenId as veNFT, -cast(value as double)/1e18 as EQUAL, null as unlock, null as lockFROM equalizer_exchange_fantom.VotingEscrow_evt_Withdraw)),T(veNFT, EQUAL, unlock, lock) AS (SELECT * FROM (SELECT j.veNFT, j.EQUAL, j.unlock, al.lock FROM allLocks al