Query editor
withdays AS (with days_seq as (SELECT sequence((select DATE '2023-06-20' as day), date_trunc('day', cast(now() as timestamp)), interval '1' day) as day)SELECTdays.dayFROM days_seqCROSS JOIN unnest(day) as days(day))-- get all lp nft tokens for our pools, Pair_evt_Mints = New NFT Mints (have corresponding NFT transfers) + Liquidity Increases for existing NFTs (do not have corresponding NFT Transfers), lp_token_ids as (SELECTb.tokenId, p.token0 -- VNX token contract addressFROM uniswap_v3_ethereum.Pair_evt_Mint aINNER JOIN uniswap_v3_ethereum.NonfungiblePositionManager_evt_Transfer b ON a.evt_tx_hash = b.evt_tx_hashLEFT JOIN uniswap_v3_ethereum.Factory_evt_PoolCreated p ON p.pool=a.contract_addressWHEREa.contract_address=0xD40a97Bf2157D9A3Ee85e7459C06A9Cd3b4Bd99b -- USDC/VEURor a.contract_address=0x5a0ad2bb7444ac2e195999e4dd956a4842958a10 -- USDC/VCHFor a.contract_address=0x344e8c1885ceed6b124c46614827a0ee83a5c53f -- USDC/VNXAUor a.contract_address=0x200E5DdD1aD474c9A3Af3A77CBDE453B6778656D -- VEUR/ETHor a.contract_address=0x80d21876cc9e11f1d000b4DEe9C73aA1bAC31919 -- VCHF/ETH)-- get the history of all lp nft owners changes, owners_gap_days AS (SELECTt.tokenId, t.evt_block_time as time, LEAD(t.evt_block_time, 1, now()) over (partition by tokenId order by evt_block_time) as next_time, t.toFROM uniswap_v3_ethereum.NonfungiblePositionManager_evt_Transfer twhere t.tokenId in (select tokenId from lp_token_ids))/* , owners_all_days AS (SELECTtokenId, d.day as day, time, to as addressFROM owners_gap_days gINNER JOIN days d ON cast(g.time as DATE) <= d.dayAND d.day < cast(g.next_time as DATE)ORDER BY 1, 2)*/--- get all liquidity increases and their source addresses using the history of all lp nft owner changes, inc_liq_txs AS (SELECTo.tokenId, i.evt_block_time as time, o.next_time