Query editor
/* -------------------------------------------------------------------------------------------------------------------Pendle Market SY Balance Tracker By ChainGoal-------Produce a daily time-series of SY token balances that are held by each Pendle market on a specific blockchain.The result is commonly used to track TVL / liquidity for Pendle SY contracts.Backgroud-------External Yield Asset (e.g. stETH)│▼SY Contract (1 SY accrues underlying yield)│├───────────┐▼ ▼YT Contract PT Contract (1 SY ⇄ 1 YT + 1 PT, subject to rate)│ │└────┬──────┘▼Market (LP) Contract (PT/SY AMM)│▼LP TokensKey facts for TVL calculations:Only two contracts ever hold real SY:• the YT contract• the Market contractPT, YT and LP tokens are derivatives;they carry no underlying assets themselves.Therefore, counting SY balances in the YT and Market contracts is both necessary and sufficient to capturethe on-chain liquidity that locked in the Pendle protocol.Parameters----------{{chain}} – blockchain identifier{{start_date}} – first day (UTC) to include in the analysis.keep in mind that setting the param after the first transaction on the given chain might result in errors.------------------------------------------------------------------------------------------------------------------- */WITH sy_meta as (select pm.blockchain,pm.chain_id,pm.sy_address,pm.yt_address,pm.lp_address as market_address,erc20.symbol as sy_symbol,erc20.name as sy_name,erc20.decimals as sy_decimalsfrom tokens.erc20 erc20join (select blockchain, chain_id, sy_address, yt_address, lp_addressfrom dune.p_team.result_pendle_marketswhere blockchain = '{{chain}}') pmon erc20.contract_address = pm.sy_address and erc20.blockchain = pm.blockchain),