Query editor
-- works only for univ3 ZRO-ETH (or ZRO-WETH) positions on arbitrum after position is closed.-- for all practical purpose, ETH and WETH are interchangeable in univ3 pools. I'll use ETH because it's shorter.-- ZRO decimals: 18-- WETH decimals: 18-- ETH gas calc: (t.effective_gas_price * t.gas_used)/1e18with add_liquidity as (select tokenId, evt_tx_hash, evt_block_time,-cast(amount1 as double)/1e18 as amount_eth, -- negative cuz token left wallet-cast(amount0 as double)/1e18 as amount_zrofrom uniswap_v3_arbitrum.NonfungiblePositionManager_evt_IncreaseLiquiditywhere tokenId = cast({{Arbitrum UniV3 ZRO-ETH LP NFT id}} as uint256) -- NFT id),remove_liquidity as (select tokenId, evt_tx_hash, evt_block_time,cast(amount1 as double)/1e18 as amount_eth, -- positive cuz token returned to walletcast(amount0 as double)/1e18 as amount_zrofrom uniswap_v3_arbitrum.NonfungiblePositionManager_evt_DecreaseLiquiditywhere tokenId = cast({{Arbitrum UniV3 ZRO-ETH LP NFT id}} as uint256) -- NFT id),add_n_remove_liquidity as (select a.*,-- add gas column(t.effective_gas_price * t.gas_used)/1e18 as gas_ethfrom (select * from add_liquidityUNIONselect * from remove_liquidity) aleft join arbitrum.transactions t on t.hash = a.evt_tx_hash),claim_fees_helper as (select tokenId, evt_tx_hash, evt_block_time,cast(amount1 as double)/1e18 as amount_eth, -- positive cuz receice fee tokenscast(amount0 as double)/1e18 as amount_zrofrom uniswap_v3_arbitrum.NonfungiblePositionManager_evt_Collectwhere tokenId = cast({{Arbitrum UniV3 ZRO-ETH LP NFT id}} as uint256) -- NFT id),claim_fees as (select c.tokenId, c.evt_tx_hash, c.evt_block_time,-- remove double counting from liquidity removal, which auto-collects feesc.amount_eth - COALESCE(a.amount_eth, 0) as amount_eth,c.amount_zro - COALESCE(a.amount_zro, 0) as amount_zro,(t.effective_gas_price * t.gas_used)/1e18 - COALESCE(a.gas_eth, 0) as gas_ethfrom claim_fees_helper cleft join add_n_remove_liquidity a on a.evt_tx_hash = c.evt_tx_hashleft join arbitrum.transactions t on t.hash = c.evt_tx_hash),tot_lp as (select tokenId as nft_id,min(evt_block_time) as open_datetime,max(evt_block_time) as close_datetime,sum(if(amount_zro < 0, amount_zro, 0)) as sent_zro,sum(if(amount_eth < 0, amount_eth, 0)) as sent_eth,sum(if(amount_zro > 0, amount_zro, 0)) as withdrawn_zro,sum(if(amount_eth > 0, amount_eth, 0)) as withdrawn_eth,sum(gas_eth) as lp_gas_ethfrom add_n_remove_liquiditygroup by 1