-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Introduce dex_aggregator_base_trades #6653
Merged
jeff-dude
merged 16 commits into
duneanalytics:main
from
Hosuke:dex-aggregator-refactor-dev
Sep 16, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7bf5417
Introduce dex_aggregator_base_trades
Hosuke 1d38612
Fix typo
Hosuke 6d3c2b9
Refactor lifi_trades
Hosuke e2ab4af
Add lifi to base_trades
Hosuke b2660e1
Merge branch 'dex-aggregator-refactor-dev' of ssh://github.com/Hosuke…
Hosuke 9be4fcd
Fix config blocks
Hosuke 19969a5
Fix typo
Hosuke f46a237
Fix typo
Hosuke 85944be
Merge branch 'main' into dex-aggregator-refactor-dev
Hosuke 78e564e
Apply suggestions from code review
Hosuke 33520b2
Draft enrich_dex_aggregator_trades macro
Hosuke 3572efa
Remove 5 columns
Hosuke 1a7f641
Remove 5 columns
Hosuke 48ff5cd
Merge branch 'main' into dex-aggregator-refactor-dev
Hosuke b255160
Recover add_tx_columns
Hosuke cced5ae
Merge branch 'main' into dex-aggregator-refactor-dev
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
99 changes: 99 additions & 0 deletions
99
dbt_subprojects/dex/macros/models/enrich_dex_aggregator_trades.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,99 @@ | ||
{% macro enrich_dex_aggregator_trades( | ||
base_trades = null | ||
, filter = null | ||
, tokens_erc20_model = null | ||
) | ||
%} | ||
|
||
WITH base_trades as ( | ||
SELECT | ||
* | ||
FROM | ||
{{ base_trades }} | ||
WHERE | ||
{{ filter }} | ||
{% if is_incremental() %} | ||
AND | ||
{{ incremental_predicate('block_time') }} | ||
{% endif %} | ||
) | ||
|
||
, enrichments AS ( | ||
SELECT | ||
base_trades.blockchain | ||
, base_trades.project | ||
, base_trades.version | ||
, base_trades.block_month | ||
, base_trades.block_date | ||
, base_trades.block_time | ||
-- , base_trades.block_number -- temporary missing | ||
, erc20_bought.symbol AS token_bought_symbol | ||
, erc20_sold.symbol AS token_sold_symbol | ||
, case | ||
when lower(erc20_bought.symbol) > lower(erc20_sold.symbol) then concat(erc20_sold.symbol, '-', erc20_bought.symbol) | ||
else concat(erc20_bought.symbol, '-', erc20_sold.symbol) | ||
end AS token_pair | ||
, base_trades.token_bought_amount_raw / power(10, erc20_bought.decimals) AS token_bought_amount | ||
, base_trades.token_sold_amount_raw / power(10, erc20_sold.decimals) AS token_sold_amount | ||
, base_trades.token_bought_amount_raw | ||
, base_trades.token_sold_amount_raw | ||
, base_trades.token_bought_address | ||
, base_trades.token_sold_address | ||
, coalesce(base_trades.taker, base_trades.tx_from) AS taker | ||
, base_trades.maker | ||
, base_trades.project_contract_address | ||
, base_trades.tx_hash | ||
, base_trades.tx_from | ||
, base_trades.tx_to | ||
, base_trades.trace_address | ||
, base_trades.evt_index | ||
FROM | ||
base_trades | ||
LEFT JOIN | ||
{{ tokens_erc20_model }} as erc20_bought | ||
ON erc20_bought.contract_address = base_trades.token_bought_address | ||
AND erc20_bought.blockchain = base_trades.blockchain | ||
LEFT JOIN | ||
{{ tokens_erc20_model }} as erc20_sold | ||
ON erc20_sold.contract_address = base_trades.token_sold_address | ||
AND erc20_sold.blockchain = base_trades.blockchain | ||
) | ||
|
||
, enrichments_with_prices AS ( | ||
{{ | ||
add_amount_usd( | ||
trades_cte = 'enrichments' | ||
) | ||
}} | ||
) | ||
|
||
SELECT | ||
blockchain | ||
, project | ||
, version | ||
, block_month | ||
, block_date | ||
, block_time | ||
-- , block_number | ||
, token_bought_symbol | ||
, token_sold_symbol | ||
, token_pair | ||
, token_bought_amount | ||
, token_sold_amount | ||
, token_bought_amount_raw | ||
, token_sold_amount_raw | ||
, amount_usd | ||
, token_bought_address | ||
, token_sold_address | ||
, taker | ||
, maker | ||
, project_contract_address | ||
, tx_hash | ||
, tx_from | ||
, tx_to | ||
, trace_address | ||
, evt_index | ||
FROM | ||
enrichments_with_prices | ||
|
||
{% 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
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
40 changes: 40 additions & 0 deletions
40
dbt_subprojects/dex/models/_projects/lifi/lifi_base_trades.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,40 @@ | ||
{{ config( | ||
schema = 'lifi', | ||
alias = 'base_trades' | ||
) | ||
}} | ||
|
||
{% set lifi_models = [ | ||
ref('lifi_fantom_base_trades') | ||
, ref('lifi_optimism_base_trades') | ||
] %} | ||
|
||
|
||
SELECT * | ||
FROM ( | ||
{% for dex_model in lifi_models %} | ||
SELECT | ||
blockchain, | ||
project, | ||
version, | ||
block_month, | ||
block_date, | ||
block_time, | ||
token_bought_amount_raw, | ||
token_sold_amount_raw, | ||
token_bought_address, | ||
token_sold_address, | ||
taker, | ||
maker, | ||
project_contract_address, | ||
tx_hash, | ||
tx_from, | ||
tx_to, | ||
trace_address, --ensure field is explicitly cast as array<bigint> in base models | ||
evt_index | ||
FROM {{ dex_model }} | ||
{% if not loop.last %} | ||
UNION ALL | ||
{% endif %} | ||
{% endfor %} | ||
) |
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 |
---|---|---|
@@ -1,50 +1,13 @@ | ||
{{ config( | ||
schema = 'lifi', | ||
alias = 'trades', | ||
post_hook='{{ expose_spells(\'["fantom", "optimism"]\', | ||
"project", | ||
"lifi", | ||
\'["Henrystats"]\') }}' | ||
post_hook='{{ expose_spells(blockchains = \'["fantom", "optimism"]\', | ||
spell_type = "project", | ||
spell_name = "lifi", | ||
contributors = \'["Henrystats", "hosuke"]\') }}' | ||
) | ||
}} | ||
|
||
{% set lifi_models = [ | ||
ref('lifi_fantom_trades') | ||
,ref('lifi_optimism_trades') | ||
] %} | ||
|
||
|
||
SELECT * | ||
FROM ( | ||
{% for dex_model in lifi_models %} | ||
SELECT | ||
blockchain, | ||
project, | ||
version, | ||
block_month, | ||
block_date, | ||
block_time, | ||
token_bought_symbol, | ||
token_sold_symbol, | ||
token_pair, | ||
token_bought_amount, | ||
token_sold_amount, | ||
token_bought_amount_raw, | ||
token_sold_amount_raw, | ||
amount_usd, | ||
token_bought_address, | ||
token_sold_address, | ||
taker, | ||
maker, | ||
project_contract_address, | ||
tx_hash, | ||
tx_from, | ||
tx_to, | ||
trace_address, --ensure field is explicitly cast as array<bigint> in base models | ||
evt_index | ||
FROM {{ dex_model }} | ||
{% if not loop.last %} | ||
UNION ALL | ||
{% endif %} | ||
{% endfor %} | ||
) | ||
FROM {{ ref('dex_aggregator_trades') }} | ||
WHERE project = 'lifi' |
Oops, something went wrong.
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.
block_number
may be supported in future.