Query editor
/*-- @title: ENS - EnDAOment - Compound WETH V3 Strategy-- @description: Calculates accounting entries (deposits, withdrawals, interest accruals, and mark-to-market adjustments)for Compound v3 WETH positions held-- @author: Steakhouse Financial-- @notes: N/A-- @version:- 2.0 - 2024-03-07 - Improving performance & adding comments- 1.0 - 2023-12-04 - Initial release*/WITH comp_wallet_list AS (SELECT0x4f2083f5fbede34c2714affb3105539775f7fe64 AS wallet),comp_contract_address_list_ethereum AS (SELECT0xa17581a9e3356d9a858b789d68b4d866e593ae94 AS contract_address, --cWETHv3 on mainnet18 AS underlying_decimals,'WETH' AS token,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 AS token_address -- WETH on mainnet),comp_rates_raw_ethereum AS (-- Big thanks to @cryptokoryo for referenceSELECTb."from" AS wallet,a.contract_address,a.evt_block_time AS ts,a.evt_tx_hash AS hash,-(a.amount * 1e0) AS underlying,-(b.amount * 1e0) AS delta_ctokFROMcompound_v3_ethereum.cWETHv3_evt_Withdraw aLEFT JOIN compound_v3_ethereum.cWETHv3_evt_Transfer b ON a.evt_tx_hash = b.evt_tx_hashJOIN comp_contract_address_list_ethereum c ON a.contract_address = c.contract_addressWHERE b.to = 0x0000000000000000000000000000000000000000AND a.evt_index + 1 = b.evt_indexAND b.amount * 1e0 <> 0UNION ALLSELECTb.to AS wallet,a.contract_address,a.evt_block_time AS ts,a.evt_tx_hash AS hash,(a.amount * 1e0) AS underlying,(b.amount * 1e0) AS delta_ctokFROMcompound_v3_ethereum.cWETHv3_evt_Supply aLEFT JOIN compound_v3_ethereum.cWETHv3_evt_Transfer b ON a.evt_tx_hash = b.evt_tx_hashJOIN comp_contract_address_list_ethereum c ON a.contract_address = c.contract_addressWHERE b."from" = 0x0000000000000000000000000000000000000000AND a.evt_index + 1 = b.evt_indexAND b.amount * 1e0 <> 0),aprrate_ethereum AS (SELECTcall_block_time,max(supply_rates.contract_address) AS contract_address,max(output_0) * 1e-18 AS Rate,max(utilization) * 1e18 AS Util,