Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delta-v2 fees on all chains (base, ethereum for now) #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% macro paraswap_delta_v2_fees(blockchain, weth) %}
-- to be called wrapped by "with"
protocols_fees_balances_raw_{{blockchain}} as (
select
destToken as fee_token,
prices.symbol as symbol,
prices.decimals as decimals,
prices.price as price,
sum(protocolFee) as combined_protocol_fee_wei -- vs partnerFee
from
paraswapdelta_{{ blockchain }}.ParaswapDeltav2_evt_OrderSettled as evt
left join prices.usd as prices on prices.blockchain = '{{ blockchain }}'
and prices.contract_address = (
CASE
WHEN destToken = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN {{ weth }}
ELSE destToken
END
)
-- would be good to have real time pricing, but there's a availability lag, so resorting to 10h-old price
and prices.minute = DATE_TRUNC('hour', CURRENT_TIMESTAMP - interval '10' HOUR )
group by
1,
2,
3,
4
), protocols_fees_balances_{{blockchain}} as (
select
fee_token,
symbol,
decimals,
price,
combined_protocol_fee_wei/pow(10,decimals) as combined_protocol_fee_unit,
price*combined_protocol_fee_wei/pow(10,decimals) as combined_usd_price
from
protocols_fees_balances_raw_{{blockchain}}

{% if is_incremental() %}
WHERE
{{ incremental_predicate('evt_block_time') }}
{% endif %}
)
{% endmacro %}


Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{ config(
schema='paraswap',
alias = 'delta_fees',
post_hook='{{ expose_spells(\'["ethereum","base"]\',
"project",
"paraswap",
\'["eptighte"]\') }}'
)
}}


-- https://dune.com/queries/4335045

{% set
config = [
('ethereum', '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
('base', '0x4200000000000000000000000000000000000006')
]
%}


with
{% for row in config %}
{% if not loop.first %}
,{% endif %}{{ paraswap_delta_v2_fees(row[0], row[1]) }}
{% endfor %}


{% for row in config %}
{% if not loop.first %}
union all
(
{% endif %}
select '{{ row[0] }}' as blockchain, * from protocols_fees_balances_{{ row[0] }}
{% if not loop.first %}
)
{% endif %}
{% endfor %}
Loading