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

optimism: uniswap pools dex balances #7271

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2

sources:
- name: uniswap_v3_optimism
tables:
- name: UniswapV3Factory_evt_PoolCreated
jeff-dude marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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,
evt_block_time AS creation_time
FROM
{{ source('uniswap_v3_optimism', 'UniswapV3Factory_evt_PoolCreated') }}
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
op_pools p
LEFT JOIN
filtered_balances b ON p.pool_address = b.pool_address
5 changes: 4 additions & 1 deletion sources/_subprojects_outputs/tokens/balances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ sources:
- name: tokens_scroll
tables:
- name: balances_daily_agg
- name: balances_daily_agg_base
- name: balances_daily_agg_base
- name: tokens_optimism
tables:
jeff-dude marked this conversation as resolved.
Show resolved Hide resolved
- name: balances_daily
Loading