Query editor
/* ---------------------------------------------------------------------------------------------------------------Pendle Revenue Tracker By Chain and Token-----------------------------------------------------------------------Goal-------Compute Pendle’s protocol revenue by each chain and token.Revenue refers the total fees collected by protocol here.Background-------Pendle's protocol generates various types of revenue. Mainly,• YT Fees Revenue• AMM Swap Fees Revenue (80% of AMM Swap Fees)• Limit Order Swap Fees Revenue• Other Fees Revenue, distributed via airdropsYT Fees and Swap Fees make up the Primary Fees. You can also get logs of these fees through on-chain events.A quick way to calculate Primary Fees is by tracing every ERC-20 transfer that lands in the treasury wallet on agiven blockchain.• YT Fees are transferred from YT contracts to the treasury in two forms: SY and Reward Tokens• 80% of AMM Swap Fees are sent as SY from the LP contract (AMM) to the treasury• Limit Order Swap Fees are also sent as SY from the limit router to the treasuryOther Fees come from points negotiated by the team (i.e. points from YT fees).It’s not easy to track this directly.Instead, we calculate it by looking at the non-USDT assets transferred from the pendle funded wallets to the Airdrop Distribution contract (specifically used to forward USDT and other fees).Keep in mind that our current calculation logic theoretically might double-count reward tokens moving from the treasury to airdrop tokens.However, this hasn't happened for now, as the tokens distributed via airdrop don’t overlap with the reward tokens.Parameters----------{{chain}} – blockchain identifier{{chain_id}} – numeric blockchain identifier{{start_date}} – first date (UTC) to scan for fees{{treasury_address}} – Pendle’s treasury wallet on the target chain{{airdrop_dist_address}} – router that relays Other fees to vePENDLE holder{{limit_router_address}} – limit-order router contract------------------------------------------------------------------------------------------------------------- */WITH approx_wallets_funded_by_pendle_deployer AS (SELECT DISTINCT"to" AS pendle_funded_walletFROM {{chain}}.transactionsWHERE "from" = 0x1fccc097db89a86bfc474a1028f93958295b1fb7AND success = trueAND value > 0GROUP BY "to"), revenue_inflows AS (SELECTevt_block_time,contract_address as token_address,"from" as source_address,"to" as target_address,value as raw_amountfrom erc20_{{chain}}.evt_transferwhere evt_block_time > date '{{start_date}}'and "to" in ({{treasury_address}}, {{airdrop_dist_address}})),revenue_inflows_daily AS (