Query editor
-- works only for univ3 ETH-USDC (or WETH-USDC) 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.-- WETH decimals: 18-- USDC decimals: 6-- ETH gas calc: (t.effective_gas_price * t.gas_used)/1e18with add_liquidity as (select tokenId, evt_tx_hash, evt_block_time,-cast(amount0 as double)/1e18 as amount0, -- negative cuz token left wallet-cast(amount1 as double)/1e6 as amount1from uniswap_v3_arbitrum.NonfungiblePositionManager_evt_IncreaseLiquiditywhere tokenId = cast({{Arbitrum UniV3 ETH-USDC LP NFT id}} as uint256) -- NFT id),remove_liquidity as (select tokenId, evt_tx_hash, evt_block_time,cast(amount0 as double)/1e18 as amount0, -- positive cuz token returned to walletcast(amount1 as double)/1e6 as amount1from uniswap_v3_arbitrum.NonfungiblePositionManager_evt_DecreaseLiquiditywhere tokenId = cast({{Arbitrum UniV3 ETH-USDC 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(amount0 as double)/1e18 as amount0, -- positive cuz receice fee tokenscast(amount1 as double)/1e6 as amount1from uniswap_v3_arbitrum.NonfungiblePositionManager_evt_Collectwhere tokenId = cast({{Arbitrum UniV3 ETH-USDC 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.amount0 - COALESCE(a.amount0, 0) as amount0,c.amount1 - COALESCE(a.amount1, 0) as amount1,(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(amount0 < 0, amount0, 0)) as sent_eth,sum(if(amount1 < 0, amount1, 0)) as sent_usdc,sum(if(amount0 > 0, amount0, 0)) as withdrawn_eth,sum(if(amount1 > 0, amount1, 0)) as withdrawn_usdc,sum(gas_eth) as lp_gas_ethfrom add_n_remove_liquiditygroup by 1