Query editor
-- Polygon FX Markets: Cumulative TVL by Pool-- Tracks USD-denominated TVL for each frxUSD/FX pair on Polygon.-- Both token balances in each pool are converted to USD using prices.usd.-- frxUSD is treated as $1; FX token prices are looked up daily.WITH pool_tokens AS (SELECT * FROM (VALUES('BRZ/frxUSD', 0xdcb72c163de84618417bec9aef7ae32b5336d70e, 0x4eD141110F6EeeAbA9A1df36d8c26f684d2475Dc, 'BRZ'),('tGBP/frxUSD', 0xf5c83f5f7d3975726527feade0e51c6e5ecf7ba5, 0x27f6c8289550fCE67f6B50BeD1F519966aFE5287, 'tGBP'),('AUDF/frxUSD', 0xcb6dcbcb1da63acc01e6cc9804d0aee5a0dbb3ba, 0xd2a530170D71a9Cfe1651Fb468E2B98F7Ed7456b, 'AUDF'),('KRWQ/frxUSD', 0xbae895c43c3af0f76e8bed2af8d1063afce35f5d, 0x44C3950a6Ed303c863A6568EA18c1A01e504FFd2, 'KRWQ'),('IDRX/frxUSD', 0x4e89713e0a9971089447d2bee24b736f00672fea, 0x649a2DA7B28E0D54c13D5eFf95d3A660652742cC, 'IDRX')) AS t(pool_name, pool_address, fx_token, fx_symbol)),frxusd AS (SELECT 0x80Eede496655FB9047dd39d9f418d5483ED600df AS token_address),-- ==================== frxUSD BALANCE CHANGES ====================-- frxUSD flowing into/out of each pool-- No evt_block_time cutoff here: cumulative balance must include the pool's-- initial seed liquidity, which for some pools was added before 2026-04-01.-- Filtering here makes the running SUM start from zero rather than the real-- seed balance, which can push the tracked TVL negative after the first-- post-cutoff outflow.frxusd_balance_changes AS (SELECTpt.pool_name,DATE_TRUNC('day', t.evt_block_time) AS day,SUM(CASEWHEN t."to" = pt.pool_address THEN TRY_CAST(t.value AS DOUBLE) / 1e18WHEN t."from" = pt.pool_address THEN -TRY_CAST(t.value AS DOUBLE) / 1e18ELSE 0END) AS daily_changeFROM erc20_polygon.evt_Transfer AS tCROSS JOIN frxusd AS fINNER JOIN pool_tokens AS ptON t."to" = pt.pool_address OR t."from" = pt.pool_addressWHERE t.contract_address = f.token_addressGROUP BY 1, 2),-- ==================== FX TOKEN BALANCE CHANGES ====================-- FX tokens flowing into/out of each pool (raw values — decimal-adjusted later via prices.usd)-- Same no-cutoff reasoning as frxusd_balance_changes above.fx_balance_changes AS (SELECTpt.pool_name,pt.fx_token,pt.fx_symbol,DATE_TRUNC('day', t.evt_block_time) AS day,SUM(CASEWHEN t."to" = pt.pool_address THEN TRY_CAST(t.value AS DOUBLE)WHEN t."from" = pt.pool_address THEN -TRY_CAST(t.value AS DOUBLE)