Query editor
WITH-- Get latest pool state with USD valuespool_state_latest AS (SELECTtotal_pt,total_sy,total_lp,liquidity_usd,total_tvl_usd,timestampFROM (SELECTCAST(json_extract_scalar(result, '$.totalPt') AS DOUBLE) as total_pt,CAST(json_extract_scalar(result, '$.totalSy') AS DOUBLE) as total_sy,CAST(json_extract_scalar(result, '$.totalLp') AS DOUBLE) as total_lp,CAST(json_extract_scalar(result, '$.liquidity.usd') AS DOUBLE) as liquidity_usd,CAST(json_extract_scalar(result, '$.totalTvl.usd') AS DOUBLE) as total_tvl_usd,from_iso8601_timestamp(json_extract_scalar(result, '$.timestamp')) as timestampFROM (SELECT http_get('https://api-v2.pendle.finance/core/v2/1/markets/0x56649da435f9a9a57ee9c4c06b728e4ba84fcc6b/history?time_frame=hour') as response)CROSS JOIN UNNEST(CAST(json_extract(json_parse(response), '$.results') AS ARRAY(json))) AS t(result)ORDER BY timestamp DESCLIMIT 1)),-- Calculate current LP token price in USDlp_price AS (SELECTliquidity_usd / total_lp as price_per_lpFROM pool_state_latest),-- Define LP token info - ADD NEW POOLS HEREL (name, contract) AS (VALUES('LP-mFARM (10-Dec-25)', 0x56649da435f9a9a57ee9c4c06b728e4ba84fcc6b)-- FUTURE POOLS - Uncomment and update when new LP-mFARM pools launch:-- ,('LP-mFARM (31-Mar-26)', 0x_NEW_ADDRESS_HERE_1)-- ,('LP-mFARM (30-Jun-26)', 0x_NEW_ADDRESS_HERE_2)-- ,('LP-mFARM (25-Sep-26)', 0x_NEW_ADDRESS_HERE_3)-- ,('LP-mFARM (31-Dec-26)', 0x_NEW_ADDRESS_HERE_4)),-- Get all transfers (mints and burns)X AS (SELECT evt_block_time, "from" as user, "to" as pool, value/1e18 as amount, contract_addressFROM erc20_ethereum.evt_transferUNION ALLSELECT evt_block_time, "to" as user, "from" as pool, -value/1e18 as amount, contract_addressFROM erc20_ethereum.evt_transfer),-- Calculate daily net flows (using 0x0 address for mints/burns)A AS (SELECT