Skip to content

Commit

Permalink
Dex trades performance test: Join on block_date (#6320)
Browse files Browse the repository at this point in the history
* Join on block_date

* typo

* Add block_date to oneinch

* Add block_date to social trades

* Fix cast

* Fix

* Add back all chains

* Fix

* use correct column

* Correctly expose block_date

* Add block_date to oneinch ar

* Use correct column
  • Loading branch information
aalan3 authored Jul 5, 2024
1 parent 76d004e commit 163d1a9
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro
{% macro
oneinch_ar_handle_generic(
contract,
contract_data,
Expand All @@ -15,6 +15,7 @@
select
call_block_number as block_number
, call_block_time as block_time
, date(date_trunc('day', call_block_time)) as block_date
, call_tx_hash as tx_hash
, '{{ contract }}' as contract_name
, '{{ contract_data.version }}' as protocol_version
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro
{% macro
oneinch_ar_handle_unoswap(
contract,
contract_data,
Expand All @@ -16,6 +16,7 @@
select
block_number
, block_time
, date(date_trunc('day', block_time)) as block_date
, tx_hash
, '{{ contract }}' as contract_name
, '{{ contract_data.version }}' as protocol_version
Expand Down
19 changes: 10 additions & 9 deletions dex/macros/models/_project/oneinch/AR/oneinch_ar_macro.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{% macro
{% macro
oneinch_ar_macro(
blockchain
)
)
%}



{% set native = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' %}


with
with
-- pools tokens for unoswap lineage tokens parsing
pools_list as (
select
pool as pool_address
, tokens
from {{ ref('dex_raw_pools') }}
where
where
type in ('uniswap_compatible', 'curve_compatible')
and blockchain = '{{ blockchain }}'
group by 1, 2
Expand All @@ -25,7 +25,7 @@ pools_list as (

, calls as (
{% for contract, contract_data in oneinch_ar_cfg_contracts_macro().items() if blockchain in contract_data.blockchains %}

select * from (
with traces_cte as (
select
Expand All @@ -51,10 +51,10 @@ pools_list as (
{% endif %}
)


{% for method, method_data in contract_data.methods.items() if blockchain in method_data.get('blockchains', contract_data.blockchains) %} -- method-level blockchains override contract-level blockchains
{% if method_data.router_type in ['generic', 'clipper'] %}
{{
{{
oneinch_ar_handle_generic(
contract=contract,
contract_data=contract_data,
Expand All @@ -63,8 +63,8 @@ pools_list as (
blockchain=blockchain,
traces_cte=traces_cte,
start_date=contract_data['start'],
)
}}
)
}}
{% elif method_data.router_type in ['unoswap'] %}
{{
oneinch_ar_handle_unoswap(
Expand All @@ -90,6 +90,7 @@ select
blockchain
, block_number
, block_time
, block_date
, tx_hash
, tx_from
, tx_to
Expand Down
9 changes: 6 additions & 3 deletions dex/macros/models/_project/oneinch/LOP/oneinch_lop_macro.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% macro
{% macro
oneinch_lop_macro(
blockchain
)
)
%}


Expand All @@ -15,6 +15,7 @@ orders as (
blockchain
, call_block_number as block_number
, call_block_time as block_time
, date(date_trunc('day', call_block_time)) as block_date
, call_tx_hash as tx_hash
, '{{ contract }}' as contract_name
, '{{ contract_data['version'] }}' as protocol_version
Expand Down Expand Up @@ -68,7 +69,7 @@ orders as (
, call_type
from {{ ref('oneinch_' + blockchain + '_lop_raw_traces') }}
where
{% if is_incremental() %}
{% if is_incremental() %}
{{ incremental_predicate('block_time') }}
{% else %}
block_time >= timestamp '{{ contract_data['start'] }}'
Expand All @@ -84,6 +85,7 @@ select
blockchain
, block_number
, block_time
, block_date
, tx_hash
, tx_from
, tx_to
Expand Down Expand Up @@ -130,6 +132,7 @@ select
) as remains
, date_trunc('minute', block_time) as minute
, date(date_trunc('month', block_time)) as block_month

from (
{{
add_tx_columns(
Expand Down
2 changes: 1 addition & 1 deletion dex/models/trades/dex_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
, ref('dex_linea_base_trades')
, ref('dex_blast_base_trades')
] %}

with base_union as (
SELECT *
FROM
Expand Down
4 changes: 3 additions & 1 deletion macros/models/_sector/add_tx_columns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ select
{% endfor %}
from {{model_cte}} model
inner join {{source(blockchain, 'transactions')}} tx
on model.block_number = tx.block_number
on
model.block_date = tx.block_date
and model.block_number = tx.block_number
and model.tx_hash = tx.hash
{% if is_incremental() %}
and {{incremental_predicate('tx.block_time')}}
Expand Down
3 changes: 2 additions & 1 deletion macros/models/_sector/social/enrich_social_trades.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{% macro enrich_social_trades(base_trades) %}

SELECT
SELECT
t.blockchain AS blockchain
, CAST(date_trunc('month', t.block_time) AS date) AS block_month
, t.block_date
, t.block_time
, t.block_number
, t.project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

{% set cipher_start_date = '2023-09-20' %}

SELECT
SELECT
'arbitrum' AS blockchain
, evt_block_time AS block_time
, evt_block_number AS block_number
, cast(date_trunc('day', evt_block_time) as date) as block_date
, 'cipher' AS project
, trader
, subject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

{% set post_tech_start_date = '2023-08-30' %}

SELECT
SELECT
'arbitrum' AS blockchain
, evt_block_time AS block_time
, evt_block_number AS block_number
, cast(date_trunc('day', evt_block_time) as date) as block_date
, 'post_tech' AS project
, trader
, subject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ WITH base_union AS (
blockchain
, block_time
, block_number
, block_date
, project
, trader
, subject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ WITH base_union AS (
blockchain
, block_time
, block_number
, block_date
, project
, trader
, subject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

{% set stars_arena_start_date = '2023-09-20' %}

SELECT
SELECT
'avalanche_c' AS blockchain
, txs.block_time
, txs.block_number
, cast(date_trunc('day', txs.block_time) as date) as block_date
, 'stars_arena' AS project
, bytearray_ltrim(bytearray_substring(logs.data, 1, 32)) AS trader
, bytearray_ltrim(bytearray_substring(logs.data, 1 + 32, 32)) AS subject
Expand Down
3 changes: 2 additions & 1 deletion models/_sector/social/base/friend_tech_base_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

{% set friend_tech_start_date = '2023-08-10' %}

SELECT
SELECT
'base' AS blockchain
, evt_block_time AS block_time
, evt_block_number AS block_number
, cast(date_trunc('day', evt_block_time) as date) as block_date
, 'friend_tech' AS project
, trader
, subject
Expand Down
1 change: 1 addition & 0 deletions models/_sector/social/base/social_base_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ WITH base_union AS (
blockchain
, block_time
, block_number
, block_date
, project
, trader
, subject
Expand Down
3 changes: 2 additions & 1 deletion models/_sector/social/bnb/friend3_bnb_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

{% set friend3_start_date = '2023-09-20' %}

SELECT
SELECT
'bnb' AS blockchain
, evt_block_time AS block_time
, evt_block_number AS block_number
, cast(date_trunc('day', evt_block_time) as date) as block_date
, 'friend3' AS project
, trader
, subject
Expand Down
1 change: 1 addition & 0 deletions models/_sector/social/bnb/social_bnb_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ WITH base_union AS (
blockchain
, block_time
, block_number
, block_date
, project
, trader
, subject
Expand Down
3 changes: 2 additions & 1 deletion models/_sector/social/social_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ with base_union as (
SELECT *
FROM (
{% for chain_specific_model in chain_specific_models %}
SELECT
SELECT
blockchain
, block_time
, block_number
, block_date
, project
, trader
, subject
Expand Down

0 comments on commit 163d1a9

Please sign in to comment.