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 9 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,53 @@
{{
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
2 changes: 2 additions & 0 deletions sources/_sector/dex/trades/optimism/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: 2

sources:
- name: uniswap_v3_optimism
tables:
- name: UniswapV3Factory_evt_PoolCreated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm second guessing myself a bit now, after seeing this moved here. since uniswap_v3_optimism schema is called out but no tables specifically, i think it already accounts for all tables under that schema automatically. i'm afraid if we add this table specifically, it could break other models that relied on the auto assignment of all tables under that schema.

last check, can you remove this table completely (i.e. lines 5 & 6), and just let it run with only the schema there? would like to see if CI is able to run fine in that setup.

also do help me confirm if you are sticking with this decoded table vs. switching to the other spell of pools mentioned.

Copy link
Contributor Author

@Jason4276 Jason4276 Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your guidance! I’ve decided to switch to using the uniswap_optimism_pools spell instead of the decoded table. This approach aligns better with the existing structure and ensures consistency across models.

I also ran CI without adding the table explicitly under sources, relying only on the schema, but an error occurred. Could you advise on what steps I should take next? Should I re-add the table explicitly, or is there another setup I should consider?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a bit confused. you mention moving to uniswap_optimism_pools spell as a source, but still see the old decoded table in the PR now?

you will need to list spell as a source here:
https://github.com/duneanalytics/spellbook/blob/main/sources/_subprojects_outputs/dex/_sources.yml

then update your model to read from source('uniswap_optimism,' 'pools')

- name: sushi_optimism
tables:
- name: ConstantProductPool_evt_Swap
Expand Down
1 change: 1 addition & 0 deletions sources/_subprojects_outputs/tokens/balances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading