-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Revenue] Add monthly DAO revenue query (#107)
* [Revenue] Add monthly DAO revenue query * some more comments for readability * top level query comments
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[sqlfluff] | ||
dialect = ansi | ||
exclude_rules = L046, RF02, RF06, CP02, ST10, LT14 | ||
exclude_rules = L046, RF02, RF06, CP02, ST10, LT14, RF05 | ||
max_line_length = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- This query returns the protocol fees (per type) that CoW DAO accrues per month | ||
|
||
with | ||
cow_fee as ( | ||
select | ||
date_trunc('month', block_date) as date_month, | ||
sum(f.protocol_fee * f.protocol_fee_native_price / pow(10, 18)) | ||
- coalesce(sum(case when f.partner_fee_recipient is not null then f.partner_fee * f.protocol_fee_native_price / pow(10, 18) end), 0) as total_protocol_fee_in_eth, | ||
-- partner fee is calculated based on 15% cut that goes to cow dao | ||
sum(case when f.partner_fee_recipient is not null then f.partner_fee * f.protocol_fee_native_price / pow(10, 18) end) as partner_fee_eth, | ||
sum(case when f.partner_fee_recipient is not null then f.partner_fee * f.protocol_fee_native_price / pow(10, 18) * cast(0.15 as double) end) as partner_fee_share | ||
from cow_protocol_ethereum.trades as t | ||
left join "query_4364122(blockchain='ethereum')" as f | ||
on | ||
t.order_uid = f.order_uid | ||
and t.tx_hash = f.tx_hash | ||
-- rough block around which the DAO started accruing fees | ||
and f.block_number > 19068880 | ||
and f.protocol_fee_native_price > 0 | ||
where | ||
t.block_number > 19068880 | ||
-- some orders report unrealistic fees due to incorrect native prices | ||
and t.order_uid not in (select order_uid from query_3639473) | ||
group by 1 | ||
), | ||
|
||
mev_fee as ( | ||
select | ||
date_trunc('month', call_block_time) as date_month, | ||
sum(t.due / 1e18 / 2) as mev_blocker_fee_cow | ||
from mev_blocker_ethereum.MevBlockerFeeTill_call_bill | ||
cross join unnest(due) as t (due) | ||
where | ||
call_success = true | ||
group by 1 | ||
) | ||
|
||
select | ||
c.date_month as "month", | ||
partner_fee_share, | ||
total_protocol_fee_in_eth, | ||
mev_blocker_fee_cow, | ||
coalesce(partner_fee_share, 0) + coalesce(total_protocol_fee_in_eth, 0) + coalesce(mev_blocker_fee_cow, 0) as total_cow_dao_fee | ||
from cow_fee as c | ||
left join mev_fee as m | ||
on c.date_month = m.date_month |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- This query returns the total protocol fees (per type) that CoW DAO accrued since inception | ||
|
||
select | ||
sum(partner_fee_share) as partner_fee_share, | ||
sum(total_protocol_fee_in_eth) as total_protocol_fee_in_eth, | ||
sum(mev_blocker_fee_cow) as mev_blocker_fee_cow, | ||
sum(partner_fee_share) + sum(total_protocol_fee_in_eth) + sum(mev_blocker_fee_cow) as total_cow_dao_fee | ||
from query_3700123 |