Query editor
WITHover_accruals AS (-- grab all DistributedBorrowerComp and DistributedSupplierComp events for affected ctokens-- after proposal 62 was implementedSELECT-- topic2 (Dune starts counting at 1 instead of 0) is the address to which COMP is accruing'0' || SUBSTRING((substring(topic3,13,20))::VARCHAR,2) AS address-- the first non-indexed parameter is the amount of COMP added to compAccrued, dune_user_generated.bytea2numeric(substring(data,1,32)) AS over_accrued_raw, (dune_user_generated.bytea2numeric(substring(data,1,32))) / 1e18::NUMERIC AS over_accruedFROM ethereum.logsWHERE-- just DistributedBorrowerComp or DistributedSupplierComp events(topic1 = '\x1fc3ecc087d8d2d15e23d0032af5a47059c3892d003d8e139fdcb6bb327c99a6'::BYTEA -- DistributedBorrowerComp(address,address,uint256,uint256)OR topic1 = '\x2caecd17d02f56fa897705dcc740da2d237c373f70686f4e0d9bd3bf0400ea7a'::BYTEA -- DistributedSupplierComp(address,address,uint256,uint256))-- topic1 (Dune starts counting at 1 instead of 0) is the address of the cToken for which Comp is accruingAND substring(topic2,13,20) IN ('\x4b0181102a0112a2ef11abee5563bb4a3176c9d7'::BYTEA -- cSUSHI, '\x95b4ef2869ebd94beb4eee400a99824bf5dc325b'::BYTEA -- cMKR, '\x80a2ae356fc9ef4305676f7a3e2ed04e12c33946'::BYTEA -- cYFI, '\xe65cdb6479bac1e22340e4e755fae7e509ecd06c'::BYTEA -- cAAVE, '\x12392f67bdf24fae0af363c24ac620a2f67dad86'::BYTEA -- cTUSD, '\xf5dce57282a584d2746faf1593d3121fcac444dc'::BYTEA -- cSAI)-- after proposal 62 went liveAND block_number >= (13322798)-- emitted from the comptroller contractAND contract_address = '\x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B'), affected_accounts AS (-- aggregate to the address levelSELECTaddress, SUM(over_accrued_raw) AS over_accrued_raw, SUM(over_accrued) AS over_accruedFROM over_accrualsGROUP BY 1HAVING SUM(over_accrued) > 0ORDER BY SUM(over_accrued_raw) DESC)-- check against the proposal data-- the proposal data was pushed into a table here https://dune.xyz/queries/202222SELECTCOALESCE(aa.address, i.address) AS address, aa.over_accrued_raw AS check_value, i.over_accrued AS proposal_value, aa.over_accrued_raw = i.over_accrued AS checkFROM affected_accounts aaFULL JOIN dune_user_generated.proposal_65_input i ON lower(i.address) = lower(aa.address)ORDER BY check_value DESC;