Query editor
/*-- @title: ENS - Accounting - Swaps-- @description: Provides swaps by categorizing transactions by target wallets and tokens, adjusting for token rates, andpreparing financial records for both swap transactions and reward token accounting.-- @author: Steakhouse Financial-- @notes: N/A-- @version:- 1.0 - 2023-06-01 - Initial release- 2.0 - 2024-03-08 - Improving performance & adding comments- 3.0 - 2024-04-05 - Fixed up swaps for aggregator trades, so it correctly maps wallet balance changes- 4.0 - 2024-04-05 - Fixed swaps incorrectly mapped to the wrong LSD tokens as stETH- 5.0 - 2024-04-26 - Fixed Kind Asset Swaps for Balancer Trades- 6.0 - 2024-09-19 - Add SWISE token- 7.0 - 2024-11-29 - Add RPL token- 8.0 - 2025-01-23 - Fix cowswap fetch swaps for DAO wallet- 9.0 - 2025-02-12 - Incorporate twap safe transactions for cowswap- 10.0 - 2025-06-01 - Add USDS token- 11.0 - 2025-07-11 - Add osETH token-> Add ETHx token- 12.0 - 2026-01-07 - Add sUSDS token- 13.0 - 2026-04-05 - Add FLUID token- 14.0 - 2026-04-08 - Utilise the rETH events directly from the contracts since the namespace table is not working (prior to Feb 2026)-> Add USDT-> Split rate for bought and sold rate in the rate_adjustments-> Remove stETH from the exclusion list of swaps_prices CTE-> Split sUSDS dollar figure- 15.0 - 2026-06-01 - Add eETH token- 16.0 - 2026-07-21 - Add GHO- 17.0 - 2026-11-04 - Add syrupUSDC, syrupUSDT- 18.0 - 2026-11-28 - Add weETH swaps*/WITH-- generates a list of target wallets and their names-- e.g.: 0x4f2083f5fbede34c2714affb3105539775f7fe64 | ENS: EnDAOmentswaps_wallets AS (SELECT * FROM (VALUES(0xfe89cc7abb2c4183683ab71653c4cdc9b02d44b7, 'ENS: DAO Wallet'), (0xcf60916b6cb4753f58533808fa610fcbd4098ec0, 'ENS: Gnosis Safe'), (0x911143d946ba5d467bfc476491fdb235fef4d667, 'ENS: Multisig'), (0x4f2083f5fbede34c2714affb3105539775f7fe64, 'ENS: EnDAOment'), (0x02D61347e5c6EA5604f3f814C5b5498421cEBdEB, 'ENS: TWAP Safe')) AS t(wallet, name)UNION ALLSELECTcontract_address AS wallet,'ENS: Registrar Controller ' || TRY_CAST(ROW_NUMBER() OVER (ORDER BY min_ts) AS VARCHAR) AS nameFROM (SELECT contract_address, MIN(evt_block_time) AS min_ts FROM ens.view_registrations GROUP BY 1) AS sub),-- generates a list of target tokens and their symbol, decimals, divisor and whether they are reward tokens-- e.g.: 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 | USDC | 6 | 1000000 | 0swaps_tokens AS (SELECTcontract_address,symbol,decimals,POWER(10, decimals) AS divisor,