Skip to content

Commit

Permalink
add USD volume to the aggregation so that it's possible to compare
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshchur committed Dec 23, 2024
1 parent 54780f0 commit ccb1370
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'],



Expand All @@ -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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,89 @@

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}}')

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
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}}')

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
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}}')

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
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}}')

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
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}}')

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
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}}')

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
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}}')

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
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}}')

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
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}}')

Expand All @@ -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
)
Expand All @@ -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
Expand Down
Loading

0 comments on commit ccb1370

Please sign in to comment.