diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/arbitrum/chain_swap_arbitrum_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/arbitrum/chain_swap_arbitrum_trades.sql index c83e6121cf0..39282b3cb89 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/arbitrum/chain_swap_arbitrum_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/arbitrum/chain_swap_arbitrum_trades.sql @@ -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, @@ -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 ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql index d66064471be..a6e49911fec 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/avalanche_c/chain_swap_avalanche_c_trades.sql @@ -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, @@ -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 ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/base/chain_swap_base_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/base/chain_swap_base_trades.sql index 32ba14c0fb4..dfcd843f938 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/base/chain_swap_base_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/base/chain_swap_base_trades.sql @@ -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, @@ -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 ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/bnb/chain_swap_bnb_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/bnb/chain_swap_bnb_trades.sql index ab069893eaf..88be46fa170 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/bnb/chain_swap_bnb_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/bnb/chain_swap_bnb_trades.sql @@ -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, @@ -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 ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/optimism/chain_swap_optimism_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/optimism/chain_swap_optimism_trades.sql index db7bb3f0001..20aafd357c0 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/optimism/chain_swap_optimism_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/optimism/chain_swap_optimism_trades.sql @@ -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, @@ -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 ( diff --git a/dbt_subprojects/daily_spellbook/models/chainswap/polygon/chain_swap_polygon_trades.sql b/dbt_subprojects/daily_spellbook/models/chainswap/polygon/chain_swap_polygon_trades.sql index 01556b7a6bf..1d8f6d17e90 100644 --- a/dbt_subprojects/daily_spellbook/models/chainswap/polygon/chain_swap_polygon_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/chainswap/polygon/chain_swap_polygon_trades.sql @@ -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, @@ -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 (