Query editor
/* CTE totalDebtManagedPerAsset collects the latest update from calls to the function _onAdjustTroveInsideBatch() from each branch's TroveManager contract */with totalDebtManagedPerAsset as (SELECT 0 as aggrVal, call_block_time as last_update, asset,CASE WHEN strategy = 0x00000000001991cee928c561e37725816cbf73ba then 'summerstone'WHEN strategy = 0x000000000017d2a7b863e9ebbe6f9ab7255eb7c5 then 'summerstone'WHEN strategy = 0x0000000000704f94ce2fe636dab92677a9745dc3 then 'summerstone'WHEN strategy = 0x25bc0272217fb0fd7a2ff0d62cebe1aba15e4d91 then 'bolderCash'WHEN strategy = 0x50bc02c6c7124e6e1b8333b80a0416e504e2d044 then 'bolderCash'WHEN strategy = 0x75bc02022344159b7ef50a3ff5291dd2bc6918c7 then 'bolderCash'WHEN strategy = 0x25bc01fd5a01b1864a7dbaddb05bfed642340da2 then 'bolderCash'WHEN strategy = 0x50bc019abdb9951602bc4fe92947d3c15d5e45df then 'bolderCash'WHEN strategy = 0x75bc01bf1e21ed33915777c131b62bb13b5f2552 then 'bolderCash'WHEN strategy = 0x8869a6fb59a8df330f90d9fbf46ebfaff6d4bc14 then 'ARM'WHEN strategy = 0x1578ed833d986c1188d1a998aa5fecd418bef5da then 'private'WHEN strategy = 0xe707784292289be3aa0fb6f9d33d420291f98695 then 'trove0'ELSE 'unknown manager'END as manager,strategy,batchColl/1e18 as total_collateral,batchDebt/1e18 as total_debtFROM (SELECT ROW_NUMBER() OVER (PARTITION BY _batchAddress ORDER BY call_block_time DESC) as rn, call_block_time, 'reth' as asset, _batchAddress as strategy, _newBatchColl as batchColl, _newBatchDebt as batchDebtfrom liquity_v2_ethereum.trovemanager_reth_call_onadjusttroveinsidebatchWHERE call_success = trueUNION ALLSELECT ROW_NUMBER() OVER (PARTITION BY _batchAddress ORDER BY call_block_time DESC) as rn, call_block_time, 'wsteth' as asset, _batchAddress as strategy, _newBatchColl as batchColl, _newBatchDebt as batchDebtfrom liquity_v2_ethereum.trovemanager_wsteth_call_onadjusttroveinsidebatchWHERE call_success = trueUNION ALLSELECT ROW_NUMBER() OVER (PARTITION BY _batchAddress ORDER BY call_block_time DESC) as rn, call_block_time, 'weth' as asset, _batchAddress as strategy, _newBatchColl as batchColl, _newBatchDebt as batchDebtfrom liquity_v2_ethereum.trovemanager_weth_call_onadjusttroveinsidebatchWHERE call_success = true)WHERE rn = 1),debtUnderManagement as (SELECT *, sum(total_debt) OVER (PARTITION BY manager) as totalDebtUnderManagement, sum(total_debt) OVER (PARTITION BY aggrVal) as totalDebtManaged from totalDebtManagedPerAsset),managementFees as (SELECT _interestBatchManager, _annualManagementFee/1e18*100 as management_fee FROM liquity_v2_ethereum.trovemanager_wsteth_evt_batchupdatedgroup by 1,2UNION ALLSELECT _interestBatchManager, _annualManagementFee/1e18*100 as management_fee FROM liquity_v2_ethereum.trovemanager_weth_evt_batchupdatedgroup by 1,2UNION ALLSELECT _interestBatchManager, _annualManagementFee/1e18*100 as management_fee FROM liquity_v2_ethereum.trovemanager_reth_evt_batchupdatedgroup by 1,2