Query editor
WITH-- retrieve amount of respective tokens (reserve0 and reserve1) in relevant LPbase_sync AS (SELECTcontract_address, date_trunc('week', evt_block_time) AS _week, date_trunc('day', evt_block_time) AS _day, date_trunc('minute', evt_block_time) AS _minute, reserve0, reserve1FROM aerodrome_base.Pool_evt_SyncWHERE evt_block_time < now() - interval '60' minuteAND evt_block_time > now() - interval '365' dayAND contract_address IN (0xB37642E87613d8569Fd8Ec80888eA6c63684E79e -- WETH/KLIMA LP, 0x958682eC6282BC7E939FA8Ba9397805C214c3A09 -- USDC/KLIMA LP, 0xDA1a472eb7b27933BAA4EB985392db51f6799eee -- CHAR/KLIMA LP, 0x6e2f9520919bd95889b27E0B2f735ac7ED149837 -- BCT/KLIMA LP, 0x77e09a5043820820390904357463BfB739a76104 -- BCT/USDC LP-- , 0xf597b0EE3D51Dab24c213199E02E1b7ab9d7B5e7 -- AERO/KLIMA LP, 0x6CD89bc86E4a418f7f11e453384904B4493C4077 -- cbBTC/KLIMA LP)ORDER BY 1, 2, 3),-- creates a list that numbers the transactions, partitioned by address then day, in order by minute in desc, which ensures that the last sync of the day is ranked 1 for each contract address on each daybase_sync_order AS (SELECTcontract_address, _week, _day, _minute, reserve0, reserve1, row_number() OVER (partition BY contract_address, date_trunc('day', _day) ORDER BY _minute DESC) AS list_numberFROM base_syncWHERE _week IS NOT NULL AND _minute IS NOT NULLORDER BY 1, 2, 3),-- filter results to show only those with list_number=1, which returns balance of reserve0 and reserve1 tokens at the last sync of the daybase_listed AS (SELECT contract_address, _week, _day, _minute, reserve0, reserve1FROM base_sync_orderWHERE list_number = 1),-- custom erc20 info treatmentcustom_erc20 AS (SELECT 1 AS list_order, 0x0000000000000000000000000000000000000000 AS contract_address, 'symbol' AS symbol, 0 AS decimalsUNION SELECT 2, 0xdcefd8c8fcc492630b943abcab3429f12ea9fea2, 'KLIMA', 18UNION SELECT 3, 0x4200000000000000000000000000000000000006, 'WETH', 18UNION SELECT 4, 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913, 'USDC', 18UNION SELECT 5, 0x20b048fA035D5763685D695e66aDF62c5D9F5055, 'CHAR', 18