Skip to content

Commit

Permalink
extract all paraswap entities macro
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshchur committed Dec 11, 2024
1 parent 23aa541 commit ef48d9c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% macro paraswap_all_entities() %}
{%
set date_to = "timestamp '{{date_to}}'"
%}
{%
set date_from = "timestamp '{{date_from}}'"
%}

{%
set delta_configs = [
['ethereum', 'delta-v1-single', 'paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap', 'contract_address', 'call_block_time', 'call_tx_hash', null],
['ethereum', 'delta-v1-batch', 'paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap', 'contract_address', 'call_block_time', 'call_tx_hash', null],

['ethereum', 'delta-v2', 'paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled', 'contract_address', 'evt_block_time', 'evt_tx_hash', null],
['base', 'delta-v2', 'paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled', 'contract_address', 'evt_block_time', 'evt_tx_hash', null],

['ethereum', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='ethereum'"],

['polygon', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='polygon'"],
['bnb', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='bnb'"],
['arbitrum', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='arbitrum'"],
['avalanche_c', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='avalanche_c'"],
['fantom', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='fantom'"],
['optimism', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='optimism'"],
['base', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='base'"],




]

%}
with entities as (
{% for blockchain, entity, table, contract_field_name, time_field_name, hash_field_name, conditional in delta_configs %}
select '{{ entity }}' as entity, '{{ blockchain }}' as blockchain, {{contract_field_name}} as contract_address, {{time_field_name}} as block_time, {{hash_field_name}} as tx_hash from {{ table }}
where
({{time_field_name}} BETWEEN {{date_from}} AND {{date_to}})
{% if conditional %}
AND {{ conditional }}
{% endif %}
{% if not loop.last %} union all {% endif %}
{% endfor %}
)
{% endmacro %}
45 changes: 2 additions & 43 deletions dbt_subprojects/dex/models/_projects/paraswap/stats.sql
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
-- NB: this is a generated query, do not edit it directly, instead edit the template and re-generate the query
-- hydrate the generated ouput here: https://dune.com/queries/4403433
{%
set date_to = "timestamp '{{date_to}}'"
%}
{%
set date_from = "timestamp '{{date_from}}'"
%}

{%
set delta_configs = [
['ethereum', 'delta-v1-single', 'paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap', 'contract_address', 'call_block_time', 'call_tx_hash', null],
['ethereum', 'delta-v1-batch', 'paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap', 'contract_address', 'call_block_time', 'call_tx_hash', null],

['ethereum', 'delta-v2', 'paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled', 'contract_address', 'evt_block_time', 'evt_tx_hash', null],
['base', 'delta-v2', 'paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled', 'contract_address', 'evt_block_time', 'evt_tx_hash', null],

['ethereum', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='ethereum'"],

['polygon', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='polygon'"],
['bnb', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='bnb'"],
['arbitrum', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='arbitrum'"],
['avalanche_c', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='avalanche_c'"],
['fantom', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='fantom'"],
['optimism', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='optimism'"],
['base', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='base'"],




]

%}
with entities as (
{% for blockchain, entity, table, contract_field_name, time_field_name, hash_field_name, conditional in delta_configs %}
select '{{ entity }}' as entity, '{{ blockchain }}' as blockchain, {{contract_field_name}} as contract_address, {{time_field_name}} as block_time, {{hash_field_name}} as tx_hash from {{ table }}
where
({{time_field_name}} BETWEEN {{date_from}} AND {{date_to}})
{% if conditional %}
AND {{ conditional }}
{% endif %}
{% if not loop.last %} union all {% endif %}
{% endfor %}
),
ordered_entities as (
{{ paraswap_all_entities() }}
,ordered_entities as (
select
entity, blockchain, contract_address, block_time, tx_hash
from entities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@





with entities as (

Expand Down Expand Up @@ -94,8 +95,9 @@ with entities as (



),
ordered_entities as (
)

,ordered_entities as (
select
entity, blockchain, contract_address, block_time, tx_hash
from entities
Expand Down

0 comments on commit ef48d9c

Please sign in to comment.