Query editor
/*-- @title: Monitoring stuff-- @author: Steakhouse Financial-- @description: Detects potential issues in Steakhouse's accounting queries for Sky-- @notes: All checks on accounting data are done for D-1 to prevent data changes during the current day-- @refs:-- ilk params: https://docs.google.com/spreadsheets/d/1giHwSFYSlZJQGhhejiYWJwXhscQKTKCXdtsp6ZX7yHs/edit?gid=1434793311#gid=1434793311-- coa : https://docs.google.com/spreadsheets/d/15831d6VrtodvmPv83fFO7H7uvhDhBsnJlCetvHbQdjE/edit?gid=0#gid=0-- @version:- 1.0 - 2024-10-25 - Initial version- 2.0 - 2024-10-30 - Added field 'target_assets_ilk' for [check-06] against ALM queries- 3.0 - 2025-12-06 - In check-06, changed <target_assets_ilk> to <target_assets>, given idle amounts are now in null ilk*/withtolerance as (select 1 as TOLERANCE -- discrepancy threshold for accounting mismatches (1 dai)),bs as (select*,abs(target_assets - (target_liabs + target_equity)) as target_netfrom (selectsum(if(cast(code as varchar) like '1%', dai_value, 0)) as target_assets,sum(if(cast(code as varchar) like '1%' and ilk is not null, dai_value, 0)) as target_assets_ilk,sum(if(cast(code as varchar) like '2%', dai_value, 0)) as target_liabs,sum(if(cast(code as varchar) like '3%', dai_value, 0)) as target_equity,sum(if(cast(code as varchar) like '31%', dai_value, 0)) as target_surplus,max(ts) as max_datefrom dune.steakhouse.result_sky_accountingwhere dt < current_date)),-- check-01: missing ilks in paramsilk_params as (select distinct ilk from dune.steakhouse.dataset_sky_ilks_params),ilk_source as (select distinct from_utf8(bytearray_rtrim(ilk)) as ilkfrom (select distinct(i) as ilk from maker_ethereum.vat_call_frobunion allselect distinct(ilk) from maker_ethereum.spot_call_fileunion allselect distinct(ilk) from maker_ethereum.jug_call_file)),ilk_check as (select'⚠️ [check-01] ilk missing in params dataset ' as "error check",ilk as valuefrom (select s.ilkfrom ilk_source sleft join ilk_params p on s.ilk = p.ilkwhere s.ilk is not null -- @dev: there are null ilks from source tablesand p.ilk is null)),