Query editor
/* ============================================================================Ink — LP fee APR on the canonical pools (7d and 30d average)----------------------------------------------------------------------------fee APR = (window fees / window days * 365) / pool TVLfees = swap volume x pool fee rateTVL = the pool contract's token balances, priced in USDMethod notes- Fee tiers are read from each pool's fee() (1e6 units), verified on chain2026-09-22. Velodrome pools are absent from dex.pools so there is nothingto join to; Uniswap v3 tiers agree with dex.pools.- Balances come from balances_ink.stg_latest, validated to 6 decimals againsteth_call balanceOf at the same block. Do NOT rebuild these fromtokens.transfers: cumulating ~3M double-typed rows per pool loses enoughprecision to move TVL by 15-35%.- Only the pools' own canonical assets are counted; these addresses receiveunsolicited memecoin airdrops that would otherwise pollute TVL.- Velodrome CL caveat: swap fees accrue to *unstaked* LPs. Liquidity staked ina gauge earns XVELO emissions instead, and its share of fees goes to voters.Read this as pool-level fee yield (the comparable GeckoTerminal/DefiLlamanumber), not the realised return of a staked position.========================================================================== */WITH canon (pool, label, dex, fee_1e6) AS (VALUES(0x31826a86cd62c6fa12a0a8441ec4c8bcfee8a453, 'USDG/USDT0', 'Velodrome CL', 200),(0x62c92624b8583156fc9345a7a0ed8a1f6a9ad848, 'USDC/USDT0', 'Velodrome CL', 200),(0x68ea2123ce20514127b07378773f617491e290cc, 'GHO/USDT0', 'Velodrome CL', 200),(0xac7fc3e9b9d3377a90650fe62b858ff56bd841c9, 'WETH/USDT0', 'Velodrome CL', 2000),(0xdcf119db83668e8724474dc05f6507cc7430120f, 'kBTC/USDT0', 'Velodrome CL', 2000),(0xedafd349bdac6baaefc13d06b3aa2db779534656, 'kBTC/WETH', 'Velodrome CL', 2000),(0xcc7c17cc1e74016fccd8ef413ca811595f76c67a, 'USDC/WETH', 'Velodrome CL', 2000),(0xa304a3ed0df1f8d797b281c4f12bc3eefa49adaf, 'USDG/WETH', 'Velodrome CL', 1800),(0xad95f3af523d83f00679764dbefb07ddce15d1e1, 'USDG/kBTC', 'Velodrome CL', 1800),(0x356667da30c89cc36c65d394500424d5eba8731c, 'WETH/USDT0', 'Uniswap v3', 3000),(0x6ab98b2e11a3cadb7021c390b9011b6a7c03cdfe, 'kBTC/USDT0', 'Uniswap v3', 3000)),vol AS (SELECT project_contract_address AS pool,sum(amount_usd) AS vol_30d,sum(CASE WHEN block_time >= now() - INTERVAL '7' day THEN amount_usd ELSE 0 END) AS vol_7d,count(*) AS trades_30dFROM dex.tradesWHERE blockchain = 'ink'AND block_time >= now() - INTERVAL '30' dayAND amount_usd BETWEEN 0 AND 1e9AND project_contract_address IN (SELECT pool FROM canon)GROUP BY 1),px AS ( -- oracle feed, else observed transfer price, else stable pegSELECT b.token_address AS token,coalesce(f.price, o.px,CASE WHEN b.token_symbol IN ('USDC','USD₮0','USDG','oUSDT','GHO','USDC.e','USDT')THEN 1 END) AS pxFROM (SELECT DISTINCT token_address, token_symbol FROM balances_ink.stg_latest) bLEFT JOIN (SELECT contract_address, price FROM prices.latest WHERE blockchain = 'ink') fON f.contract_address = b.token_addressLEFT JOIN (SELECT contract_address, approx_percentile(price_usd, 0.5) AS pxFROM tokens.transfersWHERE blockchain = 'ink' AND block_time >= now() - INTERVAL '2' day AND price_usd > 0GROUP BY 1) o