-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade transfers_enrich macro and benchmark prices.hour #7077
Draft
Hosuke
wants to merge
22
commits into
duneanalytics:main
Choose a base branch
from
Hosuke:1031-tokens-transfers-upgrade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1dfd939
Implement transfers_enrich_beta
Hosuke da878da
Fix macro
Hosuke ae591b3
Fix ref
Hosuke ebd855c
Benchmark in a smaller scale
Hosuke b73f848
Fix date
Hosuke da839bf
Extend time coverage
Hosuke 9000667
Update time coverage
Hosuke 15c77b9
Merge branch 'main' into 1031-tokens-transfers-upgrade
Hosuke 1427cbb
Simplify join
Hosuke 2fbde77
Merge branch '1031-tokens-transfers-upgrade' of ssh://github.com/Hosu…
Hosuke 41cc976
Benchmark ethereum with 20 days data
Hosuke b27fbbc
Fix alias
Hosuke 00c0c9f
Fix alias
Hosuke da6fdca
Change coverage period
Hosuke a1396af
Change coverage period
Hosuke ad330a6
Change coverage period
Hosuke 8da373d
Refactor benchmark date
Hosuke ebc1554
Recover orignal transfers
Hosuke 6843eb9
Revert "Recover orignal transfers"
Hosuke 4cb64c8
Reapply "Recover orignal transfers"
Hosuke 63193c6
Try another period
Hosuke 5e0217e
Try another period
Hosuke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
dbt_subprojects/tokens/macros/transfers/transfers_enrich_beta.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
{% macro transfers_enrich_beta( | ||
base_transfers = null | ||
, tokens_erc20_model = null | ||
, prices_model = null | ||
, evms_info_model = null | ||
, transfers_start_date = '2000-01-01' | ||
, transfers_end_date = '9999-12-31' | ||
, blockchain = null | ||
, usd_amount_threshold = 25000000000 | ||
) | ||
%} | ||
|
||
WITH base_transfers as ( | ||
SELECT | ||
* | ||
FROM | ||
{{ base_transfers }} | ||
WHERE | ||
block_date BETWEEN DATE '{{ transfers_start_date }}' AND DATE '{{ transfers_end_date }}' | ||
{% if is_incremental() %} | ||
AND {{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
) | ||
, prices AS ( | ||
SELECT | ||
timestamp | ||
, blockchain | ||
, contract_address | ||
, decimals | ||
, symbol | ||
, price | ||
FROM | ||
{{ prices_model }} | ||
WHERE | ||
timestamp BETWEEN TIMESTAMP '{{ transfers_start_date }}' AND TIMESTAMP '{{ transfers_end_date }}' | ||
{% if is_incremental() %} | ||
AND {{ incremental_predicate('timestamp') }} | ||
{% endif %} | ||
) | ||
, transfers as ( | ||
SELECT | ||
t.unique_key | ||
, t.blockchain | ||
, t.block_month | ||
, t.block_date | ||
, t.block_time | ||
, date_trunc('hour', t.block_time) AS block_hour | ||
, t.block_number | ||
, t.tx_hash | ||
, t.evt_index | ||
, t.trace_address | ||
, t.token_standard | ||
, t.tx_from | ||
, t.tx_to | ||
, t.tx_index | ||
, t."from" | ||
, t.to | ||
, t.contract_address | ||
, {{case_when_token_standard('evms_info.native_token_symbol', 'tokens_erc20.symbol', 'NULL')}} AS symbol | ||
, t.amount_raw | ||
, {{case_when_token_standard('t.amount_raw / power(10, 18)', 't.amount_raw / power(10, tokens_erc20.decimals)', 'cast(t.amount_raw as double)')}} AS amount | ||
, prices.price AS price_usd | ||
, {{case_when_token_standard('(t.amount_raw / power(10, 18)) * prices.price', | ||
'(t.amount_raw / power(10, tokens_erc20.decimals)) * prices.price', | ||
'NULL')}} AS amount_usd | ||
FROM | ||
base_transfers as t | ||
INNER JOIN | ||
{{ evms_info_model }} as evms_info | ||
ON evms_info.blockchain = t.blockchain | ||
LEFT JOIN | ||
{{ tokens_erc20_model }} as tokens_erc20 | ||
ON tokens_erc20.blockchain = t.blockchain | ||
AND tokens_erc20.contract_address = t.contract_address | ||
LEFT JOIN | ||
prices | ||
ON date_trunc('hour', t.block_time) = prices.timestamp | ||
AND CASE | ||
WHEN t.token_standard = 'native' | ||
THEN | ||
prices.blockchain IS NULL | ||
AND prices.contract_address IS NULL | ||
AND evms_info.native_token_symbol = prices.symbol | ||
ELSE | ||
prices.blockchain = '{{ blockchain }}' | ||
AND t.contract_address = prices.contract_address | ||
END | ||
) | ||
SELECT | ||
unique_key | ||
, blockchain | ||
, block_month | ||
, block_date | ||
, block_time | ||
, block_number | ||
, tx_hash | ||
, evt_index | ||
, trace_address | ||
, token_standard | ||
, tx_from | ||
, tx_to | ||
, tx_index | ||
, "from" | ||
, to | ||
, contract_address | ||
, symbol | ||
, amount_raw | ||
, amount | ||
, price_usd | ||
, CASE | ||
WHEN amount_usd >= {{ usd_amount_threshold }} | ||
THEN CAST(NULL as double) | ||
ELSE amount_usd -- Select only transfers where USD amount is less than the threshold | ||
END AS amount_usd | ||
FROM | ||
transfers | ||
{%- endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
dbt_subprojects/tokens/models/transfers_and_balances/blast/tokens_blast_transfers_beta.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{config( | ||
schema = 'tokens_blast', | ||
alias = 'transfers_beta', | ||
partition_by = ['block_month'], | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['block_date','unique_key'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')], | ||
post_hook='{{ expose_spells(\'["blast"]\', | ||
"sector", | ||
"tokens", | ||
\'["aalan3", "jeff-dude", "hildobby"]\') }}' | ||
) | ||
}} | ||
|
||
{{ | ||
transfers_enrich_beta( | ||
base_transfers = ref('tokens_blast_base_transfers') | ||
, tokens_erc20_model = source('tokens', 'erc20') | ||
, prices_model = ref('prices_hour') | ||
, evms_info_model = source('evms','info') | ||
, transfers_start_date = '2024-10-01' | ||
, transfers_end_date = '2024-10-10' | ||
, blockchain = 'blast' | ||
) | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...projects/tokens/models/transfers_and_balances/ethereum/tokens_ethereum_transfers_beta.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{config( | ||
schema = 'tokens_ethereum', | ||
alias = 'transfers_beta', | ||
partition_by = ['block_month'], | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['block_date','unique_key'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')], | ||
post_hook='{{ expose_spells(\'["ethereum"]\', | ||
"sector", | ||
"tokens", | ||
\'["aalan3", "jeff-dude"]\') }}' | ||
) | ||
}} | ||
|
||
{{ | ||
transfers_enrich_beta( | ||
base_transfers = ref('tokens_ethereum_base_transfers') | ||
, tokens_erc20_model = source('tokens', 'erc20') | ||
, prices_model = ref('prices_hour') | ||
, evms_info_model = source('evms','info') | ||
, transfers_start_date = '2024-10-01' | ||
, transfers_end_date = '2024-10-02' | ||
, blockchain = 'ethereum' | ||
) | ||
}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
transfers_end_date
param for benchmark and testing.