Skip to content

Commit

Permalink
fix: aggregate fee deposits by tx for all chains
Browse files Browse the repository at this point in the history
  • Loading branch information
whalehunting committed Dec 1, 2024
1 parent 4d32e8e commit 3d2667f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ with
(to = {{ fee_recipient_1 }} or to = {{ fee_recipient_2 }})
and block_time >= timestamp '{{project_start_date}}'
and value > 0

),
aggregated_fee_deposits as (
select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address
from fee_deposits
group by evt_tx_hash, fee_token_address
)
select distinct
block_time,
Expand Down Expand Up @@ -137,8 +141,7 @@ from bot_trades
join
highest_event_index_for_each_trade
on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash
/* Left Outer Join to support 0 fee trades */
left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join
{{ source('prices', 'usd') }}
on (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ with
{% else %}
and block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
aggregated_fee_deposits as (
select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address
from fee_deposits
group by evt_tx_hash, fee_token_address
)
select distinct
block_time,
Expand Down Expand Up @@ -138,8 +143,7 @@ from bot_trades
join
highest_event_index_for_each_trade
on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash
/* Left Outer Join to support 0 fee trades */
left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join
{{ source('prices', 'usd') }}
on (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ with
{% else %}
and block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
aggregated_fee_deposits as (
select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address
from fee_deposits
group by evt_tx_hash, fee_token_address
)
select distinct
block_time,
Expand Down Expand Up @@ -142,8 +147,7 @@ from bot_trades
join
highest_event_index_for_each_trade
on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash
/* Left Outer Join to support 0 fee trades */
left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join
{{ source('prices', 'usd') }}
on (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ with
{% else %}
and block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
aggregated_fee_deposits as (
select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address
from fee_deposits
group by evt_tx_hash, fee_token_address
)
select distinct
block_time,
Expand Down Expand Up @@ -138,7 +143,7 @@ join
highest_event_index_for_each_trade
on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash
/* Left Outer Join to support 0 fee trades */
left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join
{{ source('prices', 'usd') }}
on (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ with
{% else %}
and block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
aggregated_fee_deposits as (
select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address
from fee_deposits
group by evt_tx_hash, fee_token_address
)
select distinct
block_time,
Expand Down Expand Up @@ -145,7 +150,7 @@ join
highest_event_index_for_each_trade
on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash
/* Left Outer Join to support 0 fee trades */
left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join
{{ source('prices', 'usd') }}
on (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ with
{% else %}
and block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
aggregated_fee_deposits as (
select evt_tx_hash, sum(fee_token_amount) as fee_token_amount, fee_token_address
from fee_deposits
group by evt_tx_hash, fee_token_address
)


select distinct
block_time,
date_trunc('day', block_time) as block_date,
Expand Down Expand Up @@ -145,7 +148,7 @@ join
highest_event_index_for_each_trade
on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash
/* Left Outer Join to support 0 fee trades */
left join fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join aggregated_fee_deposits as fee_deposits on bot_trades.tx_hash = fee_deposits.evt_tx_hash
left join
{{ source('prices', 'usd') }}
on (
Expand Down

0 comments on commit 3d2667f

Please sign in to comment.