From 93b2f93956db6660f506bb98046893036e8d5c6f Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:23:25 +0000 Subject: [PATCH 01/13] stats query (for verifying) --- .../dex/models/_projects/paraswap/stats.sql | 32 ++++++++++++++++ .../dex/models/_projects/paraswap/stats.sql | 37 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 dbt_subprojects/dex/models/_projects/paraswap/stats.sql create mode 100644 dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql diff --git a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql new file mode 100644 index 00000000000..f6edf03f988 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql @@ -0,0 +1,32 @@ +{% +set date_to = "DATE_TRUNC('day', CURRENT_TIMESTAMP)" +%} +{% +set date_from = "DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day" +%} + +{% +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'"], + + + + +] + +%} + {% 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}}, {{time_field_name}}, {{hash_field_name}} 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 %} diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql new file mode 100644 index 00000000000..924de72425d --- /dev/null +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql @@ -0,0 +1,37 @@ + + + + + + select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address, call_block_time, call_tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap + where + (call_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + union all + + select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address, call_block_time, call_tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap + where + (call_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + union all + + select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address, evt_block_time, evt_tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled + where + (evt_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + union all + + select 'delta-v2' as entity, 'base' as blockchain, contract_address, evt_block_time, evt_tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled + where + (evt_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + union all + + select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address, block_time, tx_hash from dex_aggregator.trades + where + (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + AND project='paraswap' + + + \ No newline at end of file From 4a723b03851d7655630c924cb8824429db729dac Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:34:28 +0000 Subject: [PATCH 02/13] fix stats queries (for data cross verification) --- .../dex/models/_projects/paraswap/stats.sql | 18 ++++- .../dex/models/_projects/paraswap/stats.sql | 76 +++++++++++++++++-- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql index f6edf03f988..b003657f4a2 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql @@ -13,7 +13,15 @@ set delta_configs = [ ['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'"], + ['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'"], @@ -21,8 +29,9 @@ set delta_configs = [ ] %} +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}}, {{time_field_name}}, {{hash_field_name}} from {{ table }} + select '{{ entity }}' as entity, '{{ blockchain }}' as blockchain, {{contract_field_name}} as contract_address, {{time_field_name}}, {{hash_field_name}} from {{ table }} where ({{time_field_name}} BETWEEN {{date_from}} AND {{date_to}}) {% if conditional %} @@ -30,3 +39,8 @@ set delta_configs = [ {% endif %} {% if not loop.last %} union all {% endif %} {% endfor %} +) +select blockchain, entity, contract_address, count(*) as qty +from entities +group by 1,2,3 +order by qty desc diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql index 924de72425d..df21ca12333 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql @@ -2,36 +2,98 @@ +with entities as ( - select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address, call_block_time, call_tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap + select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time, call_tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap where (call_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) union all - select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address, call_block_time, call_tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap + select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time, call_tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap where (call_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) union all - select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address, evt_block_time, evt_tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled + select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time, evt_tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled where (evt_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) union all - select 'delta-v2' as entity, 'base' as blockchain, contract_address, evt_block_time, evt_tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled + select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time, evt_tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled where (evt_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) union all - select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) - AND project='paraswap' + AND project='paraswap' and blockchain='ethereum' + + union all + + select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + where + (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + AND project='paraswap' and blockchain='polygon' + + union all + + select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + where + (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + AND project='paraswap' and blockchain='bnb' + + union all + + select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + where + (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + AND project='paraswap' and blockchain='arbitrum' + + union all + + select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + where + (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + AND project='paraswap' and blockchain='avalanche_c' + + union all + + select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + where + (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + AND project='paraswap' and blockchain='fantom' + + union all + + select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + where + (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + AND project='paraswap' and blockchain='optimism' + + union all + + select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + where + (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + + AND project='paraswap' and blockchain='base' - \ No newline at end of file + +) +select blockchain, entity, contract_address, count(*) as qty +from entities +group by 1,2,3 +order by qty desc \ No newline at end of file From 6814d97eadc3ad740b29d0022145e44735f4a5e3 Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:38:33 +0000 Subject: [PATCH 03/13] introduce check summing (hacky) --- .../dex/models/_projects/paraswap/stats.sql | 14 +++++--- .../dex/models/_projects/paraswap/stats.sql | 34 +++++++++++-------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql index b003657f4a2..fe0895dfb13 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql @@ -31,7 +31,7 @@ set delta_configs = [ %} 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}}, {{hash_field_name}} from {{ table }} + 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 %} @@ -39,8 +39,14 @@ with entities as ( {% endif %} {% if not loop.last %} union all {% endif %} {% endfor %} +), +ordered_entities as ( + select + entity, blockchain, contract_address, block_time, tx_hash + from entities + order by block_time, tx_hash ) -select blockchain, entity, contract_address, count(*) as qty -from entities +select blockchain, entity, contract_address, count(*) as qty, sum(varbinary_to_decimal(from_hex(substring(to_hex(tx_hash),1,0+8)))) as txhash_checksum +from ordered_entities group by 1,2,3 -order by qty desc +order by qty desc \ No newline at end of file diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql index df21ca12333..482134be06e 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql @@ -4,31 +4,31 @@ with entities as ( - select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time, call_tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap + select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap where (call_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) union all - select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time, call_tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap + select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap where (call_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) union all - select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time, evt_tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled + select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled where (evt_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) union all - select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time, evt_tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled + select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled where (evt_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) union all - select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) @@ -36,7 +36,7 @@ with entities as ( union all - select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) @@ -44,7 +44,7 @@ with entities as ( union all - select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) @@ -52,7 +52,7 @@ with entities as ( union all - select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) @@ -60,7 +60,7 @@ with entities as ( union all - select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) @@ -68,7 +68,7 @@ with entities as ( union all - select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) @@ -76,7 +76,7 @@ with entities as ( union all - select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) @@ -84,7 +84,7 @@ with entities as ( union all - select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time, tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) @@ -92,8 +92,14 @@ with entities as ( +), +ordered_entities as ( + select + entity, blockchain, contract_address, block_time, tx_hash + from entities + order by block_time, tx_hash ) -select blockchain, entity, contract_address, count(*) as qty -from entities +select blockchain, entity, contract_address, count(*) as qty, sum(varbinary_to_decimal(from_hex(substring(to_hex(tx_hash),1,0+8)))) as txhash_checksum +from ordered_entities group by 1,2,3 order by qty desc \ No newline at end of file From 4c70e11b8eaa538024f2b832d36f3f15127dd9b4 Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:47:20 +0000 Subject: [PATCH 04/13] annotate --- dbt_subprojects/dex/models/_projects/paraswap/stats.sql | 2 ++ .../dex/target/compiled/dex/models/_projects/paraswap/stats.sql | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql index fe0895dfb13..d08fda3c906 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql @@ -1,3 +1,5 @@ +-- 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 = "DATE_TRUNC('day', CURRENT_TIMESTAMP)" %} diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql index 482134be06e..2788e88a267 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql @@ -1,3 +1,5 @@ +-- 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 From f1d7cefae98ba226e55e48a60bff9ace969f23b6 Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:51:17 +0000 Subject: [PATCH 05/13] annotate --- dbt_subprojects/dex/models/_projects/paraswap/stats.sql | 8 +++++++- .../compiled/dex/models/_projects/paraswap/stats.sql | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql index d08fda3c906..df7a1e43aa2 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql @@ -48,7 +48,13 @@ ordered_entities as ( from entities order by block_time, tx_hash ) -select blockchain, entity, contract_address, count(*) as qty, sum(varbinary_to_decimal(from_hex(substring(to_hex(tx_hash),1,0+8)))) as txhash_checksum +select + blockchain, + entity, + contract_address, + count(*) as qty, + -- a rubbish but tolerable way to get the checksum of the txhash. Is consistent with internal counterparty query though + sum(varbinary_to_decimal(from_hex(substring(to_hex(tx_hash),1,0+8)))) as txhash_checksum from ordered_entities group by 1,2,3 order by qty desc \ No newline at end of file diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql index 2788e88a267..65afebaa462 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql @@ -101,7 +101,13 @@ ordered_entities as ( from entities order by block_time, tx_hash ) -select blockchain, entity, contract_address, count(*) as qty, sum(varbinary_to_decimal(from_hex(substring(to_hex(tx_hash),1,0+8)))) as txhash_checksum +select + blockchain, + entity, + contract_address, + count(*) as qty, + -- a rubbish but tolerable way to get the checksum of the txhash. Is consistent with internal counterparty query though + sum(varbinary_to_decimal(from_hex(substring(to_hex(tx_hash),1,0+8)))) as txhash_checksum from ordered_entities group by 1,2,3 order by qty desc \ No newline at end of file From 23aa541a6454b5a2550faab909847c42ddb6263c Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:19:44 +0000 Subject: [PATCH 06/13] paramterized date --- .../dex/models/_projects/paraswap/stats.sql | 4 ++-- .../dex/models/_projects/paraswap/stats.sql | 24 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql index df7a1e43aa2..ae929cd4100 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql @@ -1,10 +1,10 @@ -- 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 = "DATE_TRUNC('day', CURRENT_TIMESTAMP)" +set date_to = "timestamp '{{date_to}}'" %} {% -set date_from = "DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day" +set date_from = "timestamp '{{date_from}}'" %} {% diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql index 65afebaa462..f57fcd3e111 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql @@ -8,31 +8,31 @@ with entities as ( select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap where - (call_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (call_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap where - (call_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (call_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled where - (evt_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled where - (evt_block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where - (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') AND project='paraswap' and blockchain='ethereum' @@ -40,7 +40,7 @@ with entities as ( select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where - (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') AND project='paraswap' and blockchain='polygon' @@ -48,7 +48,7 @@ with entities as ( select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where - (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') AND project='paraswap' and blockchain='bnb' @@ -56,7 +56,7 @@ with entities as ( select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where - (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') AND project='paraswap' and blockchain='arbitrum' @@ -64,7 +64,7 @@ with entities as ( select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where - (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') AND project='paraswap' and blockchain='avalanche_c' @@ -72,7 +72,7 @@ with entities as ( select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where - (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') AND project='paraswap' and blockchain='fantom' @@ -80,7 +80,7 @@ with entities as ( select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where - (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') AND project='paraswap' and blockchain='optimism' @@ -88,7 +88,7 @@ with entities as ( select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades where - (block_time BETWEEN DATE_TRUNC('day', CURRENT_TIMESTAMP) - INTERVAL '1' day AND DATE_TRUNC('day', CURRENT_TIMESTAMP)) + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') AND project='paraswap' and blockchain='base' From ef48d9c62c68228b0d43f03eb3510996dcc24ac9 Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Wed, 11 Dec 2024 05:59:39 +0000 Subject: [PATCH 07/13] extract all paraswap entities macro --- .../models/_project/paraswap/all-entities.sql | 44 ++++++++++++++++++ .../dex/models/_projects/paraswap/stats.sql | 45 +------------------ .../dex/models/_projects/paraswap/stats.sql | 6 ++- 3 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql diff --git a/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql b/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql new file mode 100644 index 00000000000..5c8ef50fa3b --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql @@ -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 %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql index ae929cd4100..c32777ec838 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/models/_projects/paraswap/stats.sql @@ -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 diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql index f57fcd3e111..7a8ae59866a 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql @@ -3,6 +3,7 @@ + with entities as ( @@ -94,8 +95,9 @@ with entities as ( -), -ordered_entities as ( +) + +,ordered_entities as ( select entity, blockchain, contract_address, block_time, tx_hash from entities From 7658a62b0efd2536055398dc083f154fc8fd1058 Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Wed, 11 Dec 2024 06:02:56 +0000 Subject: [PATCH 08/13] rename --- .../_projects/paraswap/{stats.sql => all-entities-aggregated.sql} | 0 .../_projects/paraswap/{stats.sql => all-entities-aggregated.sql} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename dbt_subprojects/dex/models/_projects/paraswap/{stats.sql => all-entities-aggregated.sql} (100%) rename dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/{stats.sql => all-entities-aggregated.sql} (100%) diff --git a/dbt_subprojects/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/models/_projects/paraswap/all-entities-aggregated.sql similarity index 100% rename from dbt_subprojects/dex/models/_projects/paraswap/stats.sql rename to dbt_subprojects/dex/models/_projects/paraswap/all-entities-aggregated.sql diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql similarity index 100% rename from dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/stats.sql rename to dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql From 3928229e769fd33ef0275d283dcd3c3b71af23f8 Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Wed, 11 Dec 2024 06:24:09 +0000 Subject: [PATCH 09/13] add all-entities-details --- .../paraswap/all-entities-details.sql | 10 ++ .../paraswap/all-entities-details.sql | 106 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 dbt_subprojects/dex/models/_projects/paraswap/all-entities-details.sql create mode 100644 dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql diff --git a/dbt_subprojects/dex/models/_projects/paraswap/all-entities-details.sql b/dbt_subprojects/dex/models/_projects/paraswap/all-entities-details.sql new file mode 100644 index 00000000000..80ee0ff2e8e --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/paraswap/all-entities-details.sql @@ -0,0 +1,10 @@ +-- 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/4407620 +{% set blockchain_var = "{{blockchain}}" %} +{% set contract_address_var = "{{contract_address}}" %} +{{ paraswap_all_entities() }} +select + entity, blockchain, contract_address, block_time, tx_hash +from entities +where blockchain = '{{blockchain_var}}' and contract_address = {{contract_address_var}} +order by block_time, tx_hash diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql new file mode 100644 index 00000000000..a1484ac3e70 --- /dev/null +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql @@ -0,0 +1,106 @@ +-- 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/4407620 + + + + + + + +with entities as ( + + select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap + where + (call_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + union all + + select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap + where + (call_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + union all + + select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled + where + (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + union all + + select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled + where + (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + union all + + select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + where + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + AND project='paraswap' and blockchain='ethereum' + + union all + + select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + where + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + AND project='paraswap' and blockchain='polygon' + + union all + + select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + where + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + AND project='paraswap' and blockchain='bnb' + + union all + + select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + where + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + AND project='paraswap' and blockchain='arbitrum' + + union all + + select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + where + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + AND project='paraswap' and blockchain='avalanche_c' + + union all + + select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + where + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + AND project='paraswap' and blockchain='fantom' + + union all + + select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + where + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + AND project='paraswap' and blockchain='optimism' + + union all + + select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + where + (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + + AND project='paraswap' and blockchain='base' + + + +) + +select + entity, blockchain, contract_address, block_time, tx_hash +from entities +where blockchain = '{{blockchain}}' and contract_address = {{contract_address}} +order by block_time, tx_hash \ No newline at end of file From 6d85cf5b8b0a59978ae774d257de4191554673bd Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:23:51 +0000 Subject: [PATCH 10/13] stabilize sorting (to compare against internal) --- .../dex/models/_projects/paraswap/all-entities-details.sql | 2 +- .../dex/models/_projects/paraswap/all-entities-details.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/paraswap/all-entities-details.sql b/dbt_subprojects/dex/models/_projects/paraswap/all-entities-details.sql index 80ee0ff2e8e..d6493bc611c 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/all-entities-details.sql +++ b/dbt_subprojects/dex/models/_projects/paraswap/all-entities-details.sql @@ -7,4 +7,4 @@ select entity, blockchain, contract_address, block_time, tx_hash from entities where blockchain = '{{blockchain_var}}' and contract_address = {{contract_address_var}} -order by block_time, tx_hash +order by block_time desc, tx_hash diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql index a1484ac3e70..46173d8520c 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql @@ -103,4 +103,4 @@ select entity, blockchain, contract_address, block_time, tx_hash from entities where blockchain = '{{blockchain}}' and contract_address = {{contract_address}} -order by block_time, tx_hash \ No newline at end of file +order by block_time desc, tx_hash \ No newline at end of file From b4ca1caf7dadfd388015ae2080ccad0dafdcd839 Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:32:09 +0000 Subject: [PATCH 11/13] paraswap all entities query: exclude stage txs --- .../dex/macros/models/_project/paraswap/all-entities.sql | 4 ++-- .../dex/models/_projects/paraswap/all-entities-aggregated.sql | 2 ++ .../dex/models/_projects/paraswap/all-entities-details.sql | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql b/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql index 5c8ef50fa3b..6bb1b202c2f 100644 --- a/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql +++ b/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql @@ -5,14 +5,14 @@ set date_to = "timestamp '{{date_to}}'" {% set date_from = "timestamp '{{date_from}}'" %} - +{# 0xace5ae3de4baffc4a45028659c5ee330764e4f53 is testing agent address on staging #} {% 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], + ['base', 'delta-v2', 'paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled', 'contract_address', 'evt_block_time', 'evt_tx_hash', 'evt_tx_from <> 0xace5ae3de4baffc4a45028659c5ee330764e4f53'], ['ethereum', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='ethereum'"], diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql index 7a8ae59866a..7afabd647e6 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql @@ -29,6 +29,8 @@ with entities as ( where (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + AND evt_tx_from <> 0xace5ae3de4baffc4a45028659c5ee330764e4f53 + union all select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql index 46173d8520c..10ee9214d65 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql @@ -31,6 +31,8 @@ with entities as ( where (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') + AND evt_tx_from <> 0xace5ae3de4baffc4a45028659c5ee330764e4f53 + union all select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades From 54780f0a6af82b0e18820e31155c856c692c0bd7 Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Sun, 22 Dec 2024 16:41:00 +0000 Subject: [PATCH 12/13] add paraswap delta v1 orders models -- both single_swap and safe_settle_batch_swap --- .../delta/v1/safe_settle_batch_swap.sql | 97 ++++++ .../paraswap/delta/v1/settle_swap.sql | 95 ++++++ .../_projects/paraswap/ethereum/_schema.yml | 58 ++++ .../paraswap_delta_v1_ethereum_trades.sql | 172 ++++++++++ .../paraswap_delta_v1_ethereum_trades.sql | 323 ++++++++++++++++++ 5 files changed, 745 insertions(+) create mode 100644 dbt_subprojects/dex/macros/models/_project/paraswap/delta/v1/safe_settle_batch_swap.sql create mode 100644 dbt_subprojects/dex/macros/models/_project/paraswap/delta/v1/settle_swap.sql create mode 100644 dbt_subprojects/dex/models/_projects/paraswap/ethereum/paraswap_delta_v1_ethereum_trades.sql create mode 100644 dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/ethereum/paraswap_delta_v1_ethereum_trades.sql diff --git a/dbt_subprojects/dex/macros/models/_project/paraswap/delta/v1/safe_settle_batch_swap.sql b/dbt_subprojects/dex/macros/models/_project/paraswap/delta/v1/safe_settle_batch_swap.sql new file mode 100644 index 00000000000..58b602a0ee6 --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/paraswap/delta/v1/safe_settle_batch_swap.sql @@ -0,0 +1,97 @@ +-- ref dbt_subprojects/dex/macros/models/_project/paraswap/v6/paraswap_v6_trades_master.sql +{% macro delta_safe_settle_batch_swap(blockchain) %} +safe_settle_batch_swap_ExpandedOrders AS ( + SELECT + call_trace_address, + call_block_time, + call_block_number, + call_tx_hash, + output_successfulOrders, + JSON_EXTRACT(data, '$.ordersData') AS parsed_orders, + contract_address + FROM paraswapdelta_{{blockchain}}.ParaswapDeltav1_call_safeSettleBatchSwap + where call_success = true + {% if is_incremental() %} + AND {{ incremental_predicate('call_block_time') }} + {% endif %} +), safe_settle_batch_swap_parsedOrderItems AS ( + SELECT + index, + JSON_ARRAY_GET(parsed_orders, index) AS parsed_order_data, + * + FROM safe_settle_batch_swap_ExpandedOrders + CROSS JOIN UNNEST(SEQUENCE(0, CARDINALITY(output_successfulOrders) - 1)) AS t(index) + WHERE + output_successfulOrders[index + 1] +), safe_settle_batch_swap_parsedOrdersWithSig AS ( + SELECT + JSON_EXTRACT_SCALAR(parsed_order_data, '$.feeAmount') AS feeAmount, + JSON_EXTRACT(parsed_order_data, '$.orderWithSig') AS orderWithSig, + JSON_EXTRACT(parsed_order_data, '$.calldataToExecute') AS calldataToExecute, + * + FROM safe_settle_batch_swap_parsedOrderItems +), safe_settle_batch_swap_unparsedOrders AS ( + SELECT + JSON_EXTRACT(JSON_PARSE(TRY_CAST(orderWithSig AS VARCHAR)), '$.order') AS "order", + JSON_EXTRACT(JSON_PARSE(TRY_CAST(orderWithSig AS VARCHAR)), '$.signature') AS signature, + * + FROM safe_settle_batch_swap_parsedOrdersWithSig +), safe_settle_batch_swap_parsedOrders AS ( + SELECT + from_hex(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.owner')) AS "order_owner", + FROM_HEX(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.srcToken')) AS "src_token", + FROM_HEX(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.destToken')) AS "dest_token", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.srcAmount') AS "src_amount", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.destAmount') AS "dest_amount", + * + FROM safe_settle_batch_swap_unparsedOrders +), safe_settle_batch_swap_withUSDs AS ( + SELECT + CASE + WHEN dest_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE dest_token + END AS dest_token_for_joining, + CASE + WHEN src_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE src_token + END AS src_token_for_joining, + * + FROM safe_settle_batch_swap_parsedOrders +), delta_v1_safe_settle_batch_swap_model as ( +SELECT + w.*, + w.dest_token AS fee_token, + CAST(s.price AS DECIMAL(38,18)) AS src_token_price_usd, + CAST(d.price AS DECIMAL(38,18)) AS dest_token_price_usd, + COALESCE( + d.price * CAST (w.feeAmount AS uint256) / POWER(10, d.decimals), + -- src cost + + (s.price * CAST (w.src_amount AS uint256) / POWER(10, s.decimals)) + * CAST (w.feeAmount AS uint256) / CAST (w.dest_amount AS uint256) + + ) AS gas_fee_usd, + s.price * CAST (w.src_amount AS uint256) / POWER(10, s.decimals) AS src_token_order_usd, + d.price * CAST (w.dest_amount AS uint256) / POWER(10, d.decimals) AS dest_token_order_usd + +FROM safe_settle_batch_swap_withUSDs w +LEFT JOIN prices.usd d + ON d.blockchain = '{{blockchain}}' + AND d.minute > TIMESTAMP '2024-06-01' + {% if is_incremental() %} + AND {{ incremental_predicate('d.minute') }} + {% endif %} + AND d.contract_address = w.dest_token_for_joining + AND d.minute = DATE_TRUNC('minute', w.call_block_time) +LEFT JOIN prices.usd s + ON s.blockchain = '{{blockchain}}' + AND s.minute > TIMESTAMP '2024-06-01' + {% if is_incremental() %} + AND {{ incremental_predicate('s.minute') }} + {% endif %} + AND s.contract_address = w.src_token_for_joining + AND s.minute = DATE_TRUNC('minute', w.call_block_time) +ORDER BY + CARDINALITY(w.output_successfulOrders) +) +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/paraswap/delta/v1/settle_swap.sql b/dbt_subprojects/dex/macros/models/_project/paraswap/delta/v1/settle_swap.sql new file mode 100644 index 00000000000..7723f55dd89 --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/paraswap/delta/v1/settle_swap.sql @@ -0,0 +1,95 @@ +{% +-- ref: dbt_subprojects/dex/macros/models/_project/paraswap/v6/paraswap_v6_trades_master.sql +%} +{% macro delta_settle_swap(blockchain) %} +settle_swap_withParsedOrderData AS ( + SELECT + call_trace_address, + call_block_time, + call_block_number, + call_tx_hash, + JSON_EXTRACT(data, '$.orderData') AS parsed_order_data, + contract_address + FROM + paraswapdelta_{{blockchain}}.ParaswapDeltav1_call_settleSwap + where call_success = true + {% if is_incremental() %} + AND {{ incremental_predicate('call_block_time') }} + {% endif %} +), +settle_swap_parsedOrderWithSig AS ( + SELECT + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST(parsed_order_data AS VARCHAR)), '$.feeAmount') AS feeAmount, + JSON_EXTRACT(JSON_PARSE(TRY_CAST(parsed_order_data AS VARCHAR)), '$.orderWithSig') AS orderWithSig, + JSON_EXTRACT(JSON_PARSE(TRY_CAST(parsed_order_data AS VARCHAR)), '$.calldataToExecute') AS calldataToExecute, + * + FROM + settle_swap_withParsedOrderData +), +settle_swap_unparsedOrders AS ( + SELECT + JSON_EXTRACT(JSON_PARSE(TRY_CAST(orderWithSig AS VARCHAR)), '$.order') AS "order", + JSON_EXTRACT(JSON_PARSE(TRY_CAST(orderWithSig AS VARCHAR)), '$.signature') AS signature, + * + FROM settle_swap_parsedOrderWithSig +), +settle_swap_parsedOrders AS ( + SELECT + from_hex(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.owner')) AS "order_owner", + FROM_HEX(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.srcToken')) AS "src_token", + FROM_HEX(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.destToken')) AS "dest_token", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.srcAmount') AS "src_amount", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.destAmount') AS "dest_amount", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.permit') AS "permit", + * + FROM settle_swap_unparsedOrders +), +settle_swap_withUSDs AS ( + SELECT + CASE + WHEN dest_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE dest_token + END AS dest_token_for_joining, + CASE + WHEN src_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE src_token + END AS src_token_for_joining, + * + FROM settle_swap_parsedOrders +), delta_v1_settle_swap_model as ( +SELECT + w.*, + w.dest_token AS fee_token, + CAST(s.price AS DECIMAL(38,18)) AS src_token_price_usd, + CAST(d.price AS DECIMAL(38,18)) AS dest_token_price_usd, + COALESCE( + d.price * CAST (w.feeAmount AS uint256) / POWER(10, d.decimals), + -- src cost + + (s.price * CAST (w.src_amount AS uint256) / POWER(10, s.decimals)) + * CAST (w.feeAmount AS uint256) / CAST (w.dest_amount AS uint256), + 0 + + ) AS gas_fee_usd, + s.price * CAST (w.src_amount AS uint256) / POWER(10, s.decimals) AS src_token_order_usd, + d.price * CAST (w.dest_amount AS uint256) / POWER(10, d.decimals) AS dest_token_order_usd + +FROM settle_swap_withUSDs w +LEFT JOIN prices.usd d + ON d.blockchain = '{{blockchain}}' + AND d.minute > TIMESTAMP '2024-06-01' + {% if is_incremental() %} + AND {{ incremental_predicate('d.minute') }} + {% endif %} + AND d.contract_address = w.dest_token_for_joining + AND d.minute = DATE_TRUNC('minute', w.call_block_time) +LEFT JOIN prices.usd s + ON s.blockchain = '{{blockchain}}' + AND s.minute > TIMESTAMP '2024-06-01' + {% if is_incremental() %} + AND {{ incremental_predicate('s.minute') }} + {% endif %} + AND s.contract_address = w.src_token_for_joining + AND s.minute = DATE_TRUNC('minute', w.call_block_time) +) +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/paraswap/ethereum/_schema.yml b/dbt_subprojects/dex/models/_projects/paraswap/ethereum/_schema.yml index 312e8c69a76..c4b687e0ec5 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/ethereum/_schema.yml +++ b/dbt_subprojects/dex/models/_projects/paraswap/ethereum/_schema.yml @@ -234,6 +234,64 @@ models: - *trace_address - *evt_index + + - name: paraswap_delta_v1_ethereum_trades + description: "Paraswap Delta V1 trades" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - method + - call_tx_hash + - call_trace_address + columns: + - name: method + description: "Call Method" + - name: call_trace_address + description: "Call Trace Address" + - name: call_block_number + description: "Call Block Number" + - name: call_block_time + description: "Call Block Time" + - name: call_tx_hash + description: "Call Transaction Hash" + - name: fee_amount + description: "Fee Amount" + - name: order_with_sig + description: "Order with Signature" + - name: calldata_to_execute + description: "Calldata to Execute" + - name: order + description: "Order" + - name: signature + description: "Signature" + - name: order_owner + description: "Order Owner" + - name: src_token + description: "Source Token" + - name: dest_token + description: "Destination Token" + - name: src_amount + description: "Source Amount" + - name: dest_amount + description: "Destination Amount" + - name: src_token_for_joining + description: "Source Token for Joining" + - name: dest_token_for_joining + description: "Destination Token for Joining" + - name: fee_token + description: "Fee Token" + - name: src_token_price_usd + description: "Source Token Price (USD)" + - name: dest_token_price_usd + description: "Destination Token Price (USD)" + - name: gas_fee_usd + description: "Gas Fee (USD)" + - name: src_token_order_usd + description: "Source Token Order Value (USD)" + - name: dest_token_order_usd + description: "Destination Token Order Value (USD)" + - name: contract_address + description: "Contract Address" - name: paraswap_v6_ethereum_trades_decoded description: "Paraswap V6 trades decoded" diff --git a/dbt_subprojects/dex/models/_projects/paraswap/ethereum/paraswap_delta_v1_ethereum_trades.sql b/dbt_subprojects/dex/models/_projects/paraswap/ethereum/paraswap_delta_v1_ethereum_trades.sql new file mode 100644 index 00000000000..c84f0cb2a53 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/paraswap/ethereum/paraswap_delta_v1_ethereum_trades.sql @@ -0,0 +1,172 @@ +-- ref dbt_subprojects/dex/models/_projects/paraswap/ethereum/paraswap_v6_ethereum_trades.sql +-- ref dbt_subprojects/dex/models/_projects/paraswap/ethereum/paraswap_v6_ethereum_trades_decoded.sql +{{ config( + schema = 'paraswap_delta_v1_ethereum', + alias = 'trades', + + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.call_block_time')], + unique_key = ['method', 'call_tx_hash', 'call_trace_address'], + post_hook='{{ expose_spells(blockchains = \'["ethereum"]\', + spell_type = "project", + spell_name = "paraswap_delta_v1", + contributors = \'["eptighte"]\') }}' + ) +}} + +{% set project_start_date = '2024-05-01' %} + +with +{{ delta_settle_swap('ethereum') }} +,{{ delta_safe_settle_batch_swap('ethereum') }} +select + 'delta_v1_settle_swap_model' as method, + call_trace_address, + call_block_number, + call_block_time, + call_tx_hash, + -- parsed_order_data, + feeAmount as fee_amount, + orderWithSig as order_with_sig, + calldataToExecute as calldata_to_execute, + "order", + signature, + order_owner, + src_token, + dest_token, + src_amount, + dest_amount, + src_token_for_joining, + dest_token_for_joining, + fee_token, + src_token_price_usd, + dest_token_price_usd, + gas_fee_usd, + src_token_order_usd, + dest_token_order_usd, + contract_address + from delta_v1_settle_swap_model +union all +select + 'delta_v1_safe_settle_batch_swap_model' as method, + call_trace_address, + call_block_number, + call_block_time, + call_tx_hash, + -- parsed_order_data, + feeAmount as fee_amount, + orderWithSig as order_with_sig, + calldataToExecute as calldata_to_execute, + "order", + signature, + order_owner, + src_token, + dest_token, + src_amount, + dest_amount, + src_token_for_joining, + dest_token_for_joining, + fee_token, + src_token_price_usd, + dest_token_price_usd, + gas_fee_usd, + src_token_order_usd, + dest_token_order_usd, + contract_address +from delta_v1_safe_settle_batch_swap_model + +-- with dexs AS ( +-- SELECT +-- blockTime AS block_time, +-- blockNumber AS block_number, +-- from_hex(beneficiary) AS taker, +-- null AS maker, -- TODO: can parse from traces +-- receivedAmount AS token_bought_amount_raw, +-- fromAmount AS token_sold_amount_raw, +-- CAST(NULL AS double) AS amount_usd, +-- method, +-- CASE +-- WHEN from_hex(destToken) = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +-- THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -- WETH +-- ELSE from_hex(destToken) +-- END AS token_bought_address, +-- CASE +-- WHEN from_hex(srcToken) = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +-- THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -- WETH +-- ELSE from_hex(srcToken) +-- END AS token_sold_address, +-- projectContractAddress as project_contract_address, +-- txHash AS tx_hash, +-- callTraceAddress AS trace_address, +-- CAST(-1 as integer) AS evt_index +-- FROM {{ ref('paraswap_v6_ethereum_trades_decoded') }} +-- {% if is_incremental() %} +-- WHERE {{ incremental_predicate('blockTime') }} +-- {% endif %} +-- ) +-- SELECT 'ethereum' AS blockchain, +-- 'paraswap' AS project, +-- '6' AS version, +-- cast(date_trunc('day', d.block_time) as date) as block_date, +-- cast(date_trunc('month', d.block_time) as date) as block_month, +-- d.block_time, +-- method, +-- e1.symbol AS token_bought_symbol, +-- e2.symbol AS token_sold_symbol, +-- CASE +-- WHEN lower(e1.symbol) > lower(e2.symbol) THEN concat(e2.symbol, '-', e1.symbol) +-- ELSE concat(e1.symbol, '-', e2.symbol) +-- END AS token_pair, +-- d.token_bought_amount_raw / power(10, e1.decimals) AS token_bought_amount, +-- d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount, +-- d.token_bought_amount_raw, +-- d.token_sold_amount_raw, +-- coalesce( +-- d.amount_usd +-- ,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price +-- ,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price +-- ) AS amount_usd, +-- d.token_bought_address, +-- d.token_sold_address, +-- coalesce(d.taker, tx."from") AS taker, +-- coalesce(d.maker, tx."from") as maker, +-- d.project_contract_address, +-- d.tx_hash, +-- tx."from" AS tx_from, +-- tx.to AS tx_to, +-- d.trace_address, +-- d.evt_index +-- FROM dexs d +-- INNER JOIN {{ source('ethereum', 'transactions') }} tx ON d.tx_hash = tx.hash +-- AND d.block_number = tx.block_number +-- {% if not is_incremental() %} +-- AND tx.block_time >= TIMESTAMP '{{project_start_date}}' +-- {% endif %} +-- {% if is_incremental() %} +-- AND {{ incremental_predicate('tx.block_time') }} +-- {% endif %} +-- LEFT JOIN {{ source('tokens', 'erc20') }} e1 ON e1.contract_address = d.token_bought_address +-- AND e1.blockchain = 'ethereum' +-- LEFT JOIN {{ source('tokens', 'erc20') }} e2 ON e2.contract_address = d.token_sold_address +-- AND e2.blockchain = 'ethereum' +-- LEFT JOIN {{ source('prices', 'usd') }} p1 ON p1.minute = date_trunc('minute', d.block_time) +-- AND p1.contract_address = d.token_bought_address +-- AND p1.blockchain = 'ethereum' +-- {% if not is_incremental() %} +-- AND p1.minute >= TIMESTAMP '{{project_start_date}}' +-- {% endif %} +-- {% if is_incremental() %} +-- AND {{ incremental_predicate('p1.minute') }} +-- {% endif %} +-- LEFT JOIN {{ source('prices', 'usd') }} p2 ON p2.minute = date_trunc('minute', d.block_time) +-- AND p2.contract_address = d.token_sold_address +-- AND p2.blockchain = 'ethereum' +-- {% if not is_incremental() %} +-- AND p2.minute >= TIMESTAMP '{{project_start_date}}' +-- {% endif %} +-- {% if is_incremental() %} +-- AND {{ incremental_predicate('p2.minute') }} +-- {% endif %} diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/ethereum/paraswap_delta_v1_ethereum_trades.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/ethereum/paraswap_delta_v1_ethereum_trades.sql new file mode 100644 index 00000000000..2cde3dfccc7 --- /dev/null +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/ethereum/paraswap_delta_v1_ethereum_trades.sql @@ -0,0 +1,323 @@ +-- ref dbt_subprojects/dex/models/_projects/paraswap/ethereum/paraswap_v6_ethereum_trades.sql +-- ref dbt_subprojects/dex/models/_projects/paraswap/ethereum/paraswap_v6_ethereum_trades_decoded.sql + + + + +with + +settle_swap_withParsedOrderData AS ( + SELECT + call_trace_address, + call_block_time, + call_block_number, + call_tx_hash, + JSON_EXTRACT(data, '$.orderData') AS parsed_order_data, + contract_address + FROM + paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap + where call_success = true + +), +settle_swap_parsedOrderWithSig AS ( + SELECT + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST(parsed_order_data AS VARCHAR)), '$.feeAmount') AS feeAmount, + JSON_EXTRACT(JSON_PARSE(TRY_CAST(parsed_order_data AS VARCHAR)), '$.orderWithSig') AS orderWithSig, + JSON_EXTRACT(JSON_PARSE(TRY_CAST(parsed_order_data AS VARCHAR)), '$.calldataToExecute') AS calldataToExecute, + * + FROM + settle_swap_withParsedOrderData +), +settle_swap_unparsedOrders AS ( + SELECT + JSON_EXTRACT(JSON_PARSE(TRY_CAST(orderWithSig AS VARCHAR)), '$.order') AS "order", + JSON_EXTRACT(JSON_PARSE(TRY_CAST(orderWithSig AS VARCHAR)), '$.signature') AS signature, + * + FROM settle_swap_parsedOrderWithSig +), +settle_swap_parsedOrders AS ( + SELECT + from_hex(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.owner')) AS "order_owner", + FROM_HEX(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.srcToken')) AS "src_token", + FROM_HEX(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.destToken')) AS "dest_token", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.srcAmount') AS "src_amount", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.destAmount') AS "dest_amount", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.permit') AS "permit", + * + FROM settle_swap_unparsedOrders +), +settle_swap_withUSDs AS ( + SELECT + CASE + WHEN dest_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE dest_token + END AS dest_token_for_joining, + CASE + WHEN src_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE src_token + END AS src_token_for_joining, + * + FROM settle_swap_parsedOrders +), delta_v1_settle_swap_model as ( +SELECT + w.*, + w.dest_token AS fee_token, + CAST(s.price AS DECIMAL(38,18)) AS src_token_price_usd, + CAST(d.price AS DECIMAL(38,18)) AS dest_token_price_usd, + COALESCE( + d.price * CAST (w.feeAmount AS uint256) / POWER(10, d.decimals), + -- src cost + + (s.price * CAST (w.src_amount AS uint256) / POWER(10, s.decimals)) + * CAST (w.feeAmount AS uint256) / CAST (w.dest_amount AS uint256), + 0 + + ) AS gas_fee_usd, + s.price * CAST (w.src_amount AS uint256) / POWER(10, s.decimals) AS src_token_order_usd, + d.price * CAST (w.dest_amount AS uint256) / POWER(10, d.decimals) AS dest_token_order_usd + +FROM settle_swap_withUSDs w +LEFT JOIN prices.usd d + ON d.blockchain = 'ethereum' + AND d.minute > TIMESTAMP '2024-06-01' + + AND d.contract_address = w.dest_token_for_joining + AND d.minute = DATE_TRUNC('minute', w.call_block_time) +LEFT JOIN prices.usd s + ON s.blockchain = 'ethereum' + AND s.minute > TIMESTAMP '2024-06-01' + + AND s.contract_address = w.src_token_for_joining + AND s.minute = DATE_TRUNC('minute', w.call_block_time) +) + +, +safe_settle_batch_swap_ExpandedOrders AS ( + SELECT + call_trace_address, + call_block_time, + call_block_number, + call_tx_hash, + output_successfulOrders, + JSON_EXTRACT(data, '$.ordersData') AS parsed_orders, + contract_address + FROM paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap + where call_success = true + +), safe_settle_batch_swap_parsedOrderItems AS ( + SELECT + index, + JSON_ARRAY_GET(parsed_orders, index) AS parsed_order_data, + * + FROM safe_settle_batch_swap_ExpandedOrders + CROSS JOIN UNNEST(SEQUENCE(0, CARDINALITY(output_successfulOrders) - 1)) AS t(index) + WHERE + output_successfulOrders[index + 1] +), safe_settle_batch_swap_parsedOrdersWithSig AS ( + SELECT + JSON_EXTRACT_SCALAR(parsed_order_data, '$.feeAmount') AS feeAmount, + JSON_EXTRACT(parsed_order_data, '$.orderWithSig') AS orderWithSig, + JSON_EXTRACT(parsed_order_data, '$.calldataToExecute') AS calldataToExecute, + * + FROM safe_settle_batch_swap_parsedOrderItems +), safe_settle_batch_swap_unparsedOrders AS ( + SELECT + JSON_EXTRACT(JSON_PARSE(TRY_CAST(orderWithSig AS VARCHAR)), '$.order') AS "order", + JSON_EXTRACT(JSON_PARSE(TRY_CAST(orderWithSig AS VARCHAR)), '$.signature') AS signature, + * + FROM safe_settle_batch_swap_parsedOrdersWithSig +), safe_settle_batch_swap_parsedOrders AS ( + SELECT + from_hex(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.owner')) AS "order_owner", + FROM_HEX(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.srcToken')) AS "src_token", + FROM_HEX(JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.destToken')) AS "dest_token", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.srcAmount') AS "src_amount", + JSON_EXTRACT_SCALAR(JSON_PARSE(TRY_CAST("order" AS VARCHAR)), '$.destAmount') AS "dest_amount", + * + FROM safe_settle_batch_swap_unparsedOrders +), safe_settle_batch_swap_withUSDs AS ( + SELECT + CASE + WHEN dest_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE dest_token + END AS dest_token_for_joining, + CASE + WHEN src_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 + ELSE src_token + END AS src_token_for_joining, + * + FROM safe_settle_batch_swap_parsedOrders +), delta_v1_safe_settle_batch_swap_model as ( +SELECT + w.*, + w.dest_token AS fee_token, + CAST(s.price AS DECIMAL(38,18)) AS src_token_price_usd, + CAST(d.price AS DECIMAL(38,18)) AS dest_token_price_usd, + COALESCE( + d.price * CAST (w.feeAmount AS uint256) / POWER(10, d.decimals), + -- src cost + + (s.price * CAST (w.src_amount AS uint256) / POWER(10, s.decimals)) + * CAST (w.feeAmount AS uint256) / CAST (w.dest_amount AS uint256) + + ) AS gas_fee_usd, + s.price * CAST (w.src_amount AS uint256) / POWER(10, s.decimals) AS src_token_order_usd, + d.price * CAST (w.dest_amount AS uint256) / POWER(10, d.decimals) AS dest_token_order_usd + +FROM safe_settle_batch_swap_withUSDs w +LEFT JOIN prices.usd d + ON d.blockchain = 'ethereum' + AND d.minute > TIMESTAMP '2024-06-01' + + AND d.contract_address = w.dest_token_for_joining + AND d.minute = DATE_TRUNC('minute', w.call_block_time) +LEFT JOIN prices.usd s + ON s.blockchain = 'ethereum' + AND s.minute > TIMESTAMP '2024-06-01' + + AND s.contract_address = w.src_token_for_joining + AND s.minute = DATE_TRUNC('minute', w.call_block_time) +ORDER BY + CARDINALITY(w.output_successfulOrders) +) + +select + 'delta_v1_settle_swap_model' as method, + call_trace_address, + call_block_number, + call_block_time, + call_tx_hash, + -- parsed_order_data, + feeAmount as fee_amount, + orderWithSig as order_with_sig, + calldataToExecute as calldata_to_execute, + "order", + signature, + order_owner, + src_token, + dest_token, + src_amount, + dest_amount, + src_token_for_joining, + dest_token_for_joining, + fee_token, + src_token_price_usd, + dest_token_price_usd, + gas_fee_usd, + src_token_order_usd, + dest_token_order_usd, + contract_address + from delta_v1_settle_swap_model +union all +select + 'delta_v1_safe_settle_batch_swap_model' as method, + call_trace_address, + call_block_number, + call_block_time, + call_tx_hash, + -- parsed_order_data, + feeAmount as fee_amount, + orderWithSig as order_with_sig, + calldataToExecute as calldata_to_execute, + "order", + signature, + order_owner, + src_token, + dest_token, + src_amount, + dest_amount, + src_token_for_joining, + dest_token_for_joining, + fee_token, + src_token_price_usd, + dest_token_price_usd, + gas_fee_usd, + src_token_order_usd, + dest_token_order_usd, + contract_address +from delta_v1_safe_settle_batch_swap_model + +-- with dexs AS ( +-- SELECT +-- blockTime AS block_time, +-- blockNumber AS block_number, +-- from_hex(beneficiary) AS taker, +-- null AS maker, -- TODO: can parse from traces +-- receivedAmount AS token_bought_amount_raw, +-- fromAmount AS token_sold_amount_raw, +-- CAST(NULL AS double) AS amount_usd, +-- method, +-- CASE +-- WHEN from_hex(destToken) = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +-- THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -- WETH +-- ELSE from_hex(destToken) +-- END AS token_bought_address, +-- CASE +-- WHEN from_hex(srcToken) = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +-- THEN 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -- WETH +-- ELSE from_hex(srcToken) +-- END AS token_sold_address, +-- projectContractAddress as project_contract_address, +-- txHash AS tx_hash, +-- callTraceAddress AS trace_address, +-- CAST(-1 as integer) AS evt_index +-- FROM paraswap_v6_ethereum.trades_decoded +-- +-- ) +-- SELECT 'ethereum' AS blockchain, +-- 'paraswap' AS project, +-- '6' AS version, +-- cast(date_trunc('day', d.block_time) as date) as block_date, +-- cast(date_trunc('month', d.block_time) as date) as block_month, +-- d.block_time, +-- method, +-- e1.symbol AS token_bought_symbol, +-- e2.symbol AS token_sold_symbol, +-- CASE +-- WHEN lower(e1.symbol) > lower(e2.symbol) THEN concat(e2.symbol, '-', e1.symbol) +-- ELSE concat(e1.symbol, '-', e2.symbol) +-- END AS token_pair, +-- d.token_bought_amount_raw / power(10, e1.decimals) AS token_bought_amount, +-- d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount, +-- d.token_bought_amount_raw, +-- d.token_sold_amount_raw, +-- coalesce( +-- d.amount_usd +-- ,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price +-- ,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price +-- ) AS amount_usd, +-- d.token_bought_address, +-- d.token_sold_address, +-- coalesce(d.taker, tx."from") AS taker, +-- coalesce(d.maker, tx."from") as maker, +-- d.project_contract_address, +-- d.tx_hash, +-- tx."from" AS tx_from, +-- tx.to AS tx_to, +-- d.trace_address, +-- d.evt_index +-- FROM dexs d +-- INNER JOIN delta_prod.ethereum.transactions tx ON d.tx_hash = tx.hash +-- AND d.block_number = tx.block_number +-- +-- AND tx.block_time >= TIMESTAMP '2024-05-01' +-- +-- +-- LEFT JOIN delta_prod.tokens.erc20 e1 ON e1.contract_address = d.token_bought_address +-- AND e1.blockchain = 'ethereum' +-- LEFT JOIN delta_prod.tokens.erc20 e2 ON e2.contract_address = d.token_sold_address +-- AND e2.blockchain = 'ethereum' +-- LEFT JOIN delta_prod.prices.usd p1 ON p1.minute = date_trunc('minute', d.block_time) +-- AND p1.contract_address = d.token_bought_address +-- AND p1.blockchain = 'ethereum' +-- +-- AND p1.minute >= TIMESTAMP '2024-05-01' +-- +-- +-- LEFT JOIN delta_prod.prices.usd p2 ON p2.minute = date_trunc('minute', d.block_time) +-- AND p2.contract_address = d.token_sold_address +-- AND p2.blockchain = 'ethereum' +-- +-- AND p2.minute >= TIMESTAMP '2024-05-01' +-- +-- \ No newline at end of file From ccb1370c3018d880e79970f1a54288994045be2f Mon Sep 17 00:00:00 2001 From: alexshchur <60445720+alexshchur@users.noreply.github.com> Date: Mon, 23 Dec 2024 08:57:49 +0000 Subject: [PATCH 13/13] add USD volume to the aggregation so that it's possible to compare --- .../models/_project/paraswap/all-entities.sql | 28 +++++++++---------- .../paraswap/all-entities-aggregated.sql | 3 +- .../paraswap/all-entities-aggregated.sql | 27 +++++++++--------- .../paraswap/all-entities-details.sql | 24 ++++++++-------- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql b/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql index 6bb1b202c2f..02f1fd3c4bc 100644 --- a/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql +++ b/dbt_subprojects/dex/macros/models/_project/paraswap/all-entities.sql @@ -8,21 +8,21 @@ set date_from = "timestamp '{{date_from}}'" {# 0xace5ae3de4baffc4a45028659c5ee330764e4f53 is testing agent address on staging #} {% 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-v1-single', 'paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap', 'contract_address', 'call_block_time', 'call_tx_hash', null, '0'], + ['ethereum', 'delta-v1-batch', 'paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap', 'contract_address', 'call_block_time', 'call_tx_hash', null, '0'], - ['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', 'evt_tx_from <> 0xace5ae3de4baffc4a45028659c5ee330764e4f53'], + ['ethereum', 'delta-v2', 'paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled', 'contract_address', 'evt_block_time', 'evt_tx_hash', null, '0'], + ['base', 'delta-v2', 'paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled', 'contract_address', 'evt_block_time', 'evt_tx_hash', 'evt_tx_from <> 0xace5ae3de4baffc4a45028659c5ee330764e4f53', '0'], - ['ethereum', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='ethereum'"], + ['ethereum', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='ethereum'", 'amount_usd'], - ['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'"], + ['polygon', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='polygon'", 'amount_usd'], + ['bnb', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='bnb'", 'amount_usd'], + ['arbitrum', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='arbitrum'", 'amount_usd'], + ['avalanche_c', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='avalanche_c'", 'amount_usd'], + ['fantom', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='fantom'", 'amount_usd'], + ['optimism', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='optimism'", 'amount_usd'], + ['base', 'augustus', 'dex_aggregator.trades', 'project_contract_address', 'block_time', 'tx_hash', "project='paraswap' and blockchain='base'", 'amount_usd'], @@ -31,8 +31,8 @@ set delta_configs = [ %} 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 }} + {% for blockchain, entity, table, contract_field_name, time_field_name, hash_field_name, conditional, usd_value_expression 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, {{usd_value_expression}} as usd_value from {{ table }} where ({{time_field_name}} BETWEEN {{date_from}} AND {{date_to}}) {% if conditional %} diff --git a/dbt_subprojects/dex/models/_projects/paraswap/all-entities-aggregated.sql b/dbt_subprojects/dex/models/_projects/paraswap/all-entities-aggregated.sql index c32777ec838..1c2257888e0 100644 --- a/dbt_subprojects/dex/models/_projects/paraswap/all-entities-aggregated.sql +++ b/dbt_subprojects/dex/models/_projects/paraswap/all-entities-aggregated.sql @@ -3,7 +3,7 @@ {{ paraswap_all_entities() }} ,ordered_entities as ( select - entity, blockchain, contract_address, block_time, tx_hash + entity, blockchain, contract_address, block_time, tx_hash, usd_value from entities order by block_time, tx_hash ) @@ -12,6 +12,7 @@ select entity, contract_address, count(*) as qty, + sum(usd_value) as usd_volume, -- a rubbish but tolerable way to get the checksum of the txhash. Is consistent with internal counterparty query though sum(varbinary_to_decimal(from_hex(substring(to_hex(tx_hash),1,0+8)))) as txhash_checksum from ordered_entities diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql index 7afabd647e6..1f1ea5dfa18 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-aggregated.sql @@ -7,25 +7,25 @@ with entities as ( - select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap + select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash, 0 as usd_value from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap where (call_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all - select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap + select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash, 0 as usd_value from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap where (call_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all - select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled + select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash, 0 as usd_value from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled where (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all - select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled + select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash, 0 as usd_value from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled where (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -33,7 +33,7 @@ with entities as ( union all - select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -41,7 +41,7 @@ with entities as ( union all - select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -49,7 +49,7 @@ with entities as ( union all - select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -57,7 +57,7 @@ with entities as ( union all - select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -65,7 +65,7 @@ with entities as ( union all - select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -73,7 +73,7 @@ with entities as ( union all - select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -81,7 +81,7 @@ with entities as ( union all - select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -89,7 +89,7 @@ with entities as ( union all - select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -101,7 +101,7 @@ with entities as ( ,ordered_entities as ( select - entity, blockchain, contract_address, block_time, tx_hash + entity, blockchain, contract_address, block_time, tx_hash, usd_value from entities order by block_time, tx_hash ) @@ -110,6 +110,7 @@ select entity, contract_address, count(*) as qty, + sum(usd_value) as usd_volume, -- a rubbish but tolerable way to get the checksum of the txhash. Is consistent with internal counterparty query though sum(varbinary_to_decimal(from_hex(substring(to_hex(tx_hash),1,0+8)))) as txhash_checksum from ordered_entities diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql index 10ee9214d65..b701b9fa2f5 100644 --- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql +++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/all-entities-details.sql @@ -9,25 +9,25 @@ with entities as ( - select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap + select 'delta-v1-single' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash, 0 as usd_value from paraswapdelta_ethereum.ParaswapDeltav1_call_settleSwap where (call_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all - select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap + select 'delta-v1-batch' as entity, 'ethereum' as blockchain, contract_address as contract_address, call_block_time as block_time, call_tx_hash as tx_hash, 0 as usd_value from paraswapdelta_ethereum.ParaswapDeltav1_call_safeSettleBatchSwap where (call_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all - select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled + select 'delta-v2' as entity, 'ethereum' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash, 0 as usd_value from paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled where (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') union all - select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled + select 'delta-v2' as entity, 'base' as blockchain, contract_address as contract_address, evt_block_time as block_time, evt_tx_hash as tx_hash, 0 as usd_value from paraswapdelta_base.ParaswapDeltav2_evt_OrderSettled where (evt_block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -35,7 +35,7 @@ with entities as ( union all - select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'ethereum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -43,7 +43,7 @@ with entities as ( union all - select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'polygon' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -51,7 +51,7 @@ with entities as ( union all - select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'bnb' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -59,7 +59,7 @@ with entities as ( union all - select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'arbitrum' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -67,7 +67,7 @@ with entities as ( union all - select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'avalanche_c' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -75,7 +75,7 @@ with entities as ( union all - select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'fantom' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -83,7 +83,7 @@ with entities as ( union all - select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'optimism' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}') @@ -91,7 +91,7 @@ with entities as ( union all - select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash from dex_aggregator.trades + select 'augustus' as entity, 'base' as blockchain, project_contract_address as contract_address, block_time as block_time, tx_hash as tx_hash, amount_usd as usd_value from dex_aggregator.trades where (block_time BETWEEN timestamp '{{date_from}}' AND timestamp '{{date_to}}')