-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce dex_aggregator_base_trades (#6653)
* Introduce dex_aggregator_base_trades * Fix typo * Refactor lifi_trades * Add lifi to base_trades * Fix config blocks * Fix typo * Fix typo * Apply suggestions from code review Co-authored-by: jeff-dude <[email protected]> * Draft enrich_dex_aggregator_trades macro * Remove 5 columns * Remove 5 columns * Recover add_tx_columns --------- Co-authored-by: jeff-dude <[email protected]>
- Loading branch information
Showing
13 changed files
with
368 additions
and
224 deletions.
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.