Skip to content
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

Create dex.liquidity spell #5585

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions macros/models/_sector/dex/dex_liquidity.sql
Original file line number Diff line number Diff line change
@@ -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 %}
32 changes: 32 additions & 0 deletions models/_sector/dex/liquidity/_schema.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions models/_sector/dex/liquidity/chains/_schema.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions models/_sector/dex/liquidity/chains/dex_ethereum_liquidity.sql
Original file line number Diff line number Diff line change
@@ -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')
)
}}
41 changes: 41 additions & 0 deletions models/_sector/dex/liquidity/dex_liquidity_beta.sql
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion models/_sector/dex/pools/dex_pools_beta.sql
Original file line number Diff line number Diff line change
@@ -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')]
)
Expand Down
Loading