diff --git a/macros/models/_sector/dex/dex_liquidity.sql b/macros/models/_sector/dex/dex_liquidity.sql new file mode 100644 index 00000000000..052b70cdc40 --- /dev/null +++ b/macros/models/_sector/dex/dex_liquidity.sql @@ -0,0 +1,28 @@ +{% macro dex_liquidity( + blockchain = null + , pools_model = null + , balances_model = null + ) +%} + +SELECT + b.day, + p.blockchain, + p.project, + p.version, + p.pool, + b.token_address, + b.token_symbol, + b.balance, + b.balance_usd +FROM +{{ pools_model }} p +LEFT JOIN +{{ balances_model }} b + ON p.pool = b.address + AND b.token_standard = 'erc20' +{% if is_incremental() %} +WHERE {{ incremental_predicate('b.day') }} +{% endif %} + +{% endmacro %} \ No newline at end of file diff --git a/models/_sector/dex/liquidity/_schema.yml b/models/_sector/dex/liquidity/_schema.yml new file mode 100644 index 00000000000..724198e10d2 --- /dev/null +++ b/models/_sector/dex/liquidity/_schema.yml @@ -0,0 +1,32 @@ +version: 2 + +models: + - name: dex_liquidity_beta + meta: + blockchain: ethereum + sector: dex + contributors: Henrystats + config: + tags: [ 'dex', 'liquidity', 'beta' ] + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool + - token_address + columns: + - &blockchain + name: blockchain + description: "Blockchain which the DEX is deployed" + - &project + name: project + description: "Project name of the DEX" + - &version + name: version + description: "Version of the contract built and deployed by the DEX project" + - name: pool + - name: token_address + - name: token_symbol + - name: day + - name: balance + - name: balance_usd \ No newline at end of file diff --git a/models/_sector/dex/liquidity/chains/_schema.yml b/models/_sector/dex/liquidity/chains/_schema.yml new file mode 100644 index 00000000000..e21cb16fc4f --- /dev/null +++ b/models/_sector/dex/liquidity/chains/_schema.yml @@ -0,0 +1,32 @@ +version: 2 + +models: + - name: dex_ethereum_liquidity + meta: + blockchain: ethereum + sector: dex + contributors: Henrystats + config: + tags: [ 'dex', 'liquidity', 'beta' ] + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - pool + - token_address + columns: + - &blockchain + name: blockchain + description: "Blockchain which the DEX is deployed" + - &project + name: project + description: "Project name of the DEX" + - &version + name: version + description: "Version of the contract built and deployed by the DEX project" + - name: pool + - name: token_address + - name: token_symbol + - name: day + - name: balance + - name: balance_usd \ No newline at end of file diff --git a/models/_sector/dex/liquidity/chains/dex_ethereum_liquidity.sql b/models/_sector/dex/liquidity/chains/dex_ethereum_liquidity.sql new file mode 100644 index 00000000000..010fbd647eb --- /dev/null +++ b/models/_sector/dex/liquidity/chains/dex_ethereum_liquidity.sql @@ -0,0 +1,18 @@ +{{ config( + schema = 'dex_ethereum', + alias = 'liquidity', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'day', 'token_address'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.day')] + ) +}} + +{{ + dex_liquidity( + blockchain = 'ethereum' + , pools_model = ref('dex_ethereum_pools') + , balances_model = ref('tokens_ethereum_balances_daily') + ) +}} \ No newline at end of file diff --git a/models/_sector/dex/liquidity/dex_liquidity_beta.sql b/models/_sector/dex/liquidity/dex_liquidity_beta.sql new file mode 100644 index 00000000000..8bbe14b39c2 --- /dev/null +++ b/models/_sector/dex/liquidity/dex_liquidity_beta.sql @@ -0,0 +1,41 @@ +{{ config( + schema = 'dex' + , alias = 'liquidity_beta' + , materialized = 'incremental' + , unique_key = ['pool', 'token_address', 'day'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.day')] + ) +}} + +{% set base_models = [ + ref('dex_ethereum_liquidity') +] %} + +WITH base_union AS ( + SELECT * + FROM ( + {% for base_model in base_models %} + SELECT + day + , blockchain + , project + , version + , pool + , token_address + , token_symbol + , balance + , balance_usd + FROM + {{ base_model }} + {% if is_incremental() %} + WHERE + {{ incremental_predicate('day') }} + {% endif %} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) +) + +SELECT * FROM base_union \ No newline at end of file diff --git a/models/_sector/dex/pools/dex_pools_beta.sql b/models/_sector/dex/pools/dex_pools_beta.sql index faca48cbe86..87f20977a7c 100644 --- a/models/_sector/dex/pools/dex_pools_beta.sql +++ b/models/_sector/dex/pools/dex_pools_beta.sql @@ -1,7 +1,7 @@ {{ config( schema = 'dex' , alias = 'pools_beta' - , materialized = 'view' + , materialized = 'incremental' , unique_key = ['pool'] , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.creation_block_time')] )