diff --git a/dbt_subprojects/daily_spellbook/models/_sector/dex/pools/optimism/uniswap/_schema.yml b/dbt_subprojects/daily_spellbook/models/_sector/dex/pools/optimism/uniswap/_schema.yml new file mode 100644 index 00000000000..6a6c1b7af21 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_sector/dex/pools/optimism/uniswap/_schema.yml @@ -0,0 +1,17 @@ +version: 2 + +models: + - name: uniswap_pools_optimism_balances + description: "Tracks OP token balances in Uniswap pools on Optimism." + meta: + blockchain: optimism + sector: DEX + project: uniswap + contributors: jason + config: + tags: ['optimism', 'op_token', 'balances', 'uniswap'] + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_address + - snapshot_day \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_sector/dex/pools/optimism/uniswap/uniswap_pools_optimism_balances.sql b/dbt_subprojects/daily_spellbook/models/_sector/dex/pools/optimism/uniswap/uniswap_pools_optimism_balances.sql new file mode 100644 index 00000000000..19e7e4ae624 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_sector/dex/pools/optimism/uniswap/uniswap_pools_optimism_balances.sql @@ -0,0 +1,52 @@ +{{ + config( + schema = 'uniswap_pools_optimism', + alias = 'balances', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool_address', 'snapshot_day'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.snapshot_day')] + ) +}} + +WITH op_pools AS ( + SELECT + pool AS pool_address, + token0, + token1, + fee AS fee_tier, + creation_block_time AS creation_time + FROM + {{ source('uniswap_v3_optimism', 'pools') }} + WHERE + (token0 = 0x4200000000000000000000000000000000000042 + OR token1 = 0x4200000000000000000000000000000000000042) +), +filtered_balances AS ( + SELECT + address AS pool_address, + balance AS op_balance, + day AS snapshot_day + FROM + {{ source('tokens_optimism', 'balances_daily') }} + WHERE + token_address = 0x4200000000000000000000000000000000000042 + {% if is_incremental() %} + and {{ incremental_predicate('day') }} + {% else %} + and day >= date '2021-11-11' --first pool initiated + {% endif %} +) +SELECT + p.pool_address, + p.token0, + p.token1, + p.fee_tier, + p.creation_time, + COALESCE(b.op_balance, 0) AS op_balance, + COALESCE(b.snapshot_day, CURRENT_DATE) AS snapshot_day +FROM + filtered_balances b +RIGHT JOIN + op_pools p ON p.pool_address = b.pool_address diff --git a/sources/_subprojects_outputs/dex/_sources.yml b/sources/_subprojects_outputs/dex/_sources.yml index 1d1d25769a6..1a980e82bae 100644 --- a/sources/_subprojects_outputs/dex/_sources.yml +++ b/sources/_subprojects_outputs/dex/_sources.yml @@ -71,6 +71,7 @@ sources: - name: uniswap_v3_optimism tables: - name: ovm1_pool_mapping + - name: pools - name: cow_protocol_ethereum tables: - name: trades diff --git a/sources/_subprojects_outputs/tokens/balances.yml b/sources/_subprojects_outputs/tokens/balances.yml index dc994a80daa..3c8f8f46e79 100644 --- a/sources/_subprojects_outputs/tokens/balances.yml +++ b/sources/_subprojects_outputs/tokens/balances.yml @@ -8,6 +8,7 @@ sources: tables: - name: balances_daily_agg - name: balances_daily_agg_base + - name: balances_daily - name: tokens_polygon tables: - name: balances_daily_agg