Query editor
/*-- @title: ENS - EnDAOment - COMP V3 USDC Strategy-- @description: Calculates the accounting entries (deposits, withdrawals, and interest accruals) with the Compound V3 USDC lending market.-- @author: Steakhouse Financial-- @notes: N/A-- @version:- 2.0 - 2024-03-07 - Added comment header- 1.0 - 2023-11-23 - Initial release*/WITH comp_wallet_list AS (SELECT0x4f2083f5fbede34c2714affb3105539775f7fe64 AS wallet),comp_contract_address_list_ethereum AS (SELECT0xc3d688B66703497DAA19211EEdff47f25384cdc3 AS contract_address, --cUSDCv36 AS underlying_decimals,'USDC' AS token,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 AS token_address -- USDC),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.Comet_evt_Withdraw aLEFT JOIN compound_v3_ethereum.Comet_evt_Transfer bON a.evt_tx_hash = b.evt_tx_hashJOIN comp_contract_address_list_ethereum cON 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.Comet_evt_Supply aLEFT JOIN compound_v3_ethereum.Comet_evt_Transfer bON a.evt_tx_hash = b.evt_tx_hashJOIN comp_contract_address_list_ethereum cON 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,