Skip to content

Commit

Permalink
optimism: uniswap pools balances (duneanalytics#7434)
Browse files Browse the repository at this point in the history
* added optimism: uniswap pools dex balances

* update sql file

* Update _schema.yml

* update files

* Resolved merge conflicts in _schema.yml

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* updated sql file

* Update uniswap_pools_optimism_balances.sql

* updated sql file

* updated sql file

* updated sql file

* updated sql file
  • Loading branch information
Jason4276 authored Jan 17, 2025
1 parent a54015f commit de9c7a0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
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','pools']
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,47 @@
{{
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_addresses as (
select
pool as address,
token0,
token1,
0x4200000000000000000000000000000000000042 as token_address,
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 (
{{ balances_incremental_subset_daily(
blockchain='optimism',
start_date='2021-11-11',
address_token_list = 'op_addresses'
) }}
)

select
p.address as pool_address,
p.token0 as token0,
p.token1 as token1,
p.fee_tier,
p.creation_time,
coalesce(b.balance, 0) as op_balance,
coalesce(b.day, current_date) as snapshot_day
from
filtered_balances b
left join
op_addresses p on b.address = p.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: pools
- name: sushi_optimism
tables:
- name: ConstantProductPool_evt_Swap
Expand Down

0 comments on commit de9c7a0

Please sign in to comment.