-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add raw order data wrapper query #80
base: main
Are you sure you want to change the base?
Changes from all commits
44ab9e2
f8e89cb
02d705f
71353c7
a698c76
d0145b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[sqlfluff:templater:jinja:context] | ||
start_time='2024-08-01 12:00' | ||
end_time='2024-08-02 12:00' | ||
blockchain='ethereum' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
-- This query provides data related to rewards/payouts on a per batch auction level | ||
-- for all auctions that had at least one winner. | ||
-- Parameters: | ||
-- {{blockchain}}: the chain for which we want to retrieve batch data | ||
|
||
-- The output has the following columns: | ||
-- environment: varchar | ||
-- auction_id: integer | ||
-- block_number: integer | ||
-- order_uid: varbinary | ||
-- solver: varbinary | ||
-- quote_solver: varbinary | ||
-- tx_hash: varbinary | ||
-- surplus_fee: decimal(38, 0) | ||
-- protocol_fee: decimal(38, 0) | ||
-- protocol_fee_token: varbinary | ||
-- protocol_fee_native_price: decimal(38, 0) | ||
-- quote_sell_amount: decimal(38, 0) | ||
-- quote_buy_amount: decimal(38, 0) | ||
-- quote_gas_cost: decimal(38, 0) | ||
-- quote_sell_token_price: decimal(38, 0) | ||
-- partner_fee: decimal(38, 0) | ||
-- partner_fee_recipient: varbinary | ||
-- protocol_fee_kind: varchar | ||
|
||
with | ||
past_data_ethereum as ( | ||
select | ||
s.environment, | ||
-1 as auction_id, | ||
d.block_number, | ||
from_hex(d.order_uid) as order_uid, | ||
from_hex(d.solver) as solver, | ||
from_hex(d.data.quote_solver) as quote_solver, --noqa: RF01 | ||
from_hex(d.tx_hash) as tx_hash, | ||
cast(d.data.surplus_fee as decimal(38, 0)) as surplus_fee, --noqa: RF01 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there precedence for this number of decimals? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I run
I get an error So i decided to max it out, but didn't think this through much tbh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
cast(d.data.protocol_fee as decimal(38, 0)) as protocol_fee, --noqa: RF01 | ||
from_hex(d.data.protocol_fee_token) as protocol_fee_token, --noqa: RF01 | ||
cast(d.data.protocol_fee_native_price as decimal(38, 0)) as protocol_fee_native_price, --noqa: RF01 | ||
case | ||
when d.data.quote_sell_amount = 'None' then null --noqa: RF01 | ||
else cast(d.data.quote_sell_amount as decimal(38, 0)) --noqa: RF01 | ||
end as quote_sell_amount, | ||
case | ||
when d.data.quote_buy_amount = 'None' then null --noqa: RF01 | ||
else cast(d.data.quote_buy_amount as decimal(38, 0)) --noqa: RF01 | ||
end as quote_buy_amount, | ||
case | ||
when cast(d.data.quote_gas_cost as varchar) = 'NaN' then null --noqa: RF01 | ||
else cast(d.data.quote_gas_cost as decimal(38, 0)) --noqa: RF01 | ||
end as quote_gas_cost, | ||
case | ||
when cast(d.data.quote_sell_token_price as varchar) = 'NaN' then null --noqa: RF01 | ||
else cast(d.data.quote_sell_token_price as decimal(38, 0)) --noqa: RF01 | ||
end as quote_sell_token_price, | ||
cast(d.data.partner_fee as decimal(38, 0)) as partner_fee, --noqa: RF01 | ||
from_hex(d.data.partner_fee_recipient) as partner_fee_recipient, --noqa: RF01 | ||
d.data.protocol_fee_kind --noqa: RF01 | ||
from cowswap.raw_order_rewards as d inner join cow_protocol_ethereum.solvers as s on from_hex(d.solver) = s.address where d.block_number < 20866925 | ||
), | ||
|
||
past_data_gnosis as ( --noqa: ST03 | ||
-- data from Jan 23, 2024 till Sept 23, 2024, are present here | ||
select --noqa: ST06 | ||
s.environment, | ||
-1 as auction_id, | ||
d.block_number, | ||
d.order_uid, | ||
d.solver, | ||
d.quote_solver, | ||
d.tx_hash, | ||
cast(d.surplus_fee as decimal(38, 0)) as surplus_fee, | ||
cast(d.protocol_fee as decimal(38, 0)) as protocol_fee, | ||
d.protocol_fee_token, | ||
cast(d.protocol_fee_native_price as decimal(38, 0)) as protocol_fee_native_price, | ||
cast(d.quote_sell_amount as decimal(38, 0)) as quote_sell_amount, | ||
cast(d.quote_buy_amount as decimal(38, 0)) as quote_buy_amount, | ||
case | ||
when cast(d.quote_gas_cost as varchar) = 'NaN' then null | ||
else cast(d.quote_gas_cost as decimal(38, 0)) | ||
end as quote_gas_cost, | ||
case | ||
when cast(d.quote_sell_token_price as varchar) = 'NaN' then null | ||
else cast(d.quote_sell_token_price as decimal(38, 0)) | ||
end as quote_sell_token_price, | ||
cast(d.partner_fee as decimal(38, 0)) as partner_fee, | ||
d.partner_fee_recipient, | ||
d.protocol_fee_kind | ||
from dune.cowprotocol.dataset_cowswap_gnosis_raw_order_rewards as d inner join cow_protocol_gnosis.solvers as s on cast(d.solver as varchar) = cast(s.address as varchar) | ||
), | ||
|
||
past_data_arbitrum as ( --noqa: ST03 | ||
-- data till Sept 23, 2024, are present here | ||
select --noqa: ST06 | ||
s.environment, | ||
-1 as auction_id, | ||
d.block_number, | ||
d.order_uid, | ||
d.solver, | ||
d.quote_solver, | ||
d.tx_hash, | ||
cast(d.surplus_fee as decimal(38, 0)) as surplus_fee, | ||
cast(d.protocol_fee as decimal(38, 0)) as protocol_fee, | ||
d.protocol_fee_token, | ||
case | ||
when d.protocol_fee_native_price = 'inf' then null | ||
else cast(d.protocol_fee_native_price as decimal(38, 0)) | ||
end as protocol_fee_native_price, | ||
cast(d.quote_sell_amount as decimal(38, 0)) as quote_sell_amount, | ||
cast(d.quote_buy_amount as decimal(38, 0)) as quote_buy_amount, | ||
case | ||
when cast(d.quote_gas_cost as varchar) = 'NaN' then null | ||
else cast(d.quote_gas_cost as decimal(38, 0)) | ||
end as quote_gas_cost, | ||
case | ||
when cast(d.quote_sell_token_price as varchar) = 'NaN' then null | ||
else cast(d.quote_sell_token_price as decimal(38, 0)) | ||
end as quote_sell_token_price, | ||
cast(d.partner_fee as decimal(38, 0)) as partner_fee, | ||
d.partner_fee_recipient, | ||
d.protocol_fee_kind | ||
from dune.cowprotocol.dataset_cowswap_arbitrum_raw_order_rewards as d inner join cow_protocol_arbitrum.solvers as s on cast(d.solver as varchar) = cast(s.address as varchar) | ||
) | ||
|
||
select * | ||
from past_data_{{blockchain}} | ||
union all | ||
select | ||
environment, | ||
auction_id, | ||
block_number, | ||
order_uid, | ||
solver, | ||
quote_solver, | ||
tx_hash, | ||
cast(surplus_fee as decimal(38, 0)) as surplus_fee, | ||
cast(protocol_fee as decimal(38, 0)) as protocol_fee, | ||
protocol_fee_token, | ||
cast(protocol_fee_native_price as decimal(38, 0)) as protocol_fee_native_price, | ||
cast(quote_sell_amount as decimal(38, 0)) as quote_sell_amount, | ||
cast(quote_buy_amount as decimal(38, 0)) as quote_buy_amount, | ||
cast(quote_gas_cost as decimal(38, 0)) as quote_gas_cost, | ||
case | ||
when quote_sell_token_price = 'inf' then null | ||
else cast(quote_sell_token_price as decimal(38, 0)) | ||
end as quote_sell_token_price, | ||
cast(partner_fee as decimal(38, 0)) as partner_fee, | ||
partner_fee_recipient, | ||
protocol_fee_kind | ||
from dune.cowprotocol.dataset_order_data_{{blockchain}}_2024_10 | ||
union all | ||
select | ||
environment, | ||
auction_id, | ||
block_number, | ||
order_uid, | ||
solver, | ||
quote_solver, | ||
tx_hash, | ||
cast(surplus_fee as decimal(38, 0)) as surplus_fee, | ||
cast(protocol_fee as decimal(38, 0)) as protocol_fee, | ||
protocol_fee_token, | ||
cast(protocol_fee_native_price as decimal(38, 0)) as protocol_fee_native_price, | ||
cast(quote_sell_amount as decimal(38, 0)) as quote_sell_amount, | ||
cast(quote_buy_amount as decimal(38, 0)) as quote_buy_amount, | ||
cast(quote_gas_cost as decimal(38, 0)) as quote_gas_cost, | ||
case | ||
when quote_sell_token_price = 'inf' then null | ||
else cast(quote_sell_token_price as decimal(38, 0)) | ||
end as quote_sell_token_price, | ||
cast(partner_fee as decimal(38, 0)) as partner_fee, | ||
partner_fee_recipient, | ||
protocol_fee_kind | ||
from dune.cowprotocol.dataset_order_data_{{blockchain}}_2024_11 | ||
union all | ||
select | ||
environment, | ||
auction_id, | ||
block_number, | ||
order_uid, | ||
solver, | ||
quote_solver, | ||
tx_hash, | ||
cast(surplus_fee as decimal(38, 0)) as surplus_fee, | ||
cast(protocol_fee as decimal(38, 0)) as protocol_fee, | ||
protocol_fee_token, | ||
cast(protocol_fee_native_price as decimal(38, 0)) as protocol_fee_native_price, | ||
cast(quote_sell_amount as decimal(38, 0)) as quote_sell_amount, | ||
cast(quote_buy_amount as decimal(38, 0)) as quote_buy_amount, | ||
cast(quote_gas_cost as decimal(38, 0)) as quote_gas_cost, | ||
cast(quote_sell_token_price as decimal(38, 0)) as quote_sell_token_price, | ||
cast(partner_fee as decimal(38, 0)) as partner_fee, | ||
partner_fee_recipient, | ||
protocol_fee_kind | ||
from dune.cowprotocol.dataset_order_data_{{blockchain}}_2024_12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this encoded as
-1
and not justNull
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i see your point.... Will update it.