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,velodrome, curve, solidly,openxswap pools dexes balances #7588

Merged
merged 9 commits into from
Feb 3, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
version: 2

models:
- name: uniswap_pools_optimism_balances
description: "Tracks OP token balances in Uniswap pools on Optimism."
- name: dex_pools_optimism_balances
description: "Tracks OP token balances in DEX pools on Optimism."
meta:
blockchain: optimism
sector: DEX
project: uniswap
contributors: jason
config:
tags: ['optimism', 'op_token', 'balances', 'uniswap','pools']
tags: ['optimism', 'op_token', 'balances','pools']
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- pool_address
- snapshot_day
- snapshot_day
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{{
config(
schema = 'dex_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 uniswap_v3_op_addresses AS (
SELECT
pool AS address,
token0,
token1,
0x4200000000000000000000000000000000000042 AS token_address,
creation_block_time AS creation_time,
'uniswap' AS protocol_name,
'3' AS version
FROM
{{ source('uniswap_v3_optimism', 'pools') }}
WHERE
(token0 = 0x4200000000000000000000000000000000000042
OR token1 = 0x4200000000000000000000000000000000000042)
{% if is_incremental() %}
AND {{ incremental_predicate('creation_block_time') }}
{% endif %}
),

uniswap_v2_op_addresses AS (
SELECT
pair AS address,
token0,
token1,
0x4200000000000000000000000000000000000042 AS token_address,
evt_block_time AS creation_time,
'uniswap' AS protocol_name,
'2' AS version
FROM
{{ source('uniswap_v2_optimism', 'UniswapV2Factory_evt_PairCreated') }}
WHERE
(token0 = 0x4200000000000000000000000000000000000042
OR token1 = 0x4200000000000000000000000000000000000042)
{% if is_incremental() %}
AND {{ incremental_predicate('evt_block_time') }}
{% endif %}
),

velodrome_v2_op_addresses AS (
SELECT
pool AS address,
token0,
token1,
0x4200000000000000000000000000000000000042 AS token_address,
evt_block_time AS creation_time,
'velodrome' AS protocol_name,
'2' AS version
FROM
{{ source('velodrome_v2_optimism', 'PoolFactory_evt_PoolCreated') }}
WHERE
(token0 = 0x4200000000000000000000000000000000000042
OR token1 = 0x4200000000000000000000000000000000000042)
{% if is_incremental() %}
AND {{ incremental_predicate('evt_block_time') }}
{% endif %}
),

velodrome_v2_cl_op_addresses AS (
SELECT
pool AS address,
token0,
token1,
0x4200000000000000000000000000000000000042 AS token_address,
evt_block_time AS creation_time,
'velodrome' AS protocol_name,
'2' AS version
FROM
{{ source('velodrome_v2_optimism', 'CLFactory_evt_PoolCreated') }}
WHERE
(token0 = 0x4200000000000000000000000000000000000042
OR token1 = 0x4200000000000000000000000000000000000042)
{% if is_incremental() %}
AND {{ incremental_predicate('evt_block_time') }}
{% endif %}
),

velodrome_v1_op_addresses AS (
SELECT
pair AS address,
token0,
token1,
0x4200000000000000000000000000000000000042 AS token_address,
evt_block_time AS creation_time,
'velodrome' AS protocol_name,
'1' AS version
FROM
{{ source('velodrome_optimism', 'PairFactory_evt_PairCreated') }}
WHERE
(token0 = 0x4200000000000000000000000000000000000042
OR token1 = 0x4200000000000000000000000000000000000042)
{% if is_incremental() %}
AND {{ incremental_predicate('evt_block_time') }}
{% endif %}
),

solidly_v3_op_addresses AS (
SELECT
pool AS address,
token0,
token1,
0x4200000000000000000000000000000000000042 AS token_address,
evt_block_time AS creation_time,
'solidly' AS protocol_name,
'3' AS version
FROM
{{ source('solidly_v3_optimism', 'SolidlyV3Factory_evt_PoolCreated') }}
WHERE
(token0 = 0x4200000000000000000000000000000000000042
OR token1 = 0x4200000000000000000000000000000000000042)
{% if is_incremental() %}
AND {{ incremental_predicate('evt_block_time') }}
{% endif %}
),

openxswap_v1_op_addresses AS (
SELECT
pair AS address,
token0,
token1,
0x4200000000000000000000000000000000000042 AS token_address,
evt_block_time AS creation_time,
'openxswap' AS protocol_name,
'1' AS version
FROM
{{ source('openxswap_optimism', 'UniswapV2Factory_evt_PairCreated') }}
WHERE
(token0 = 0x4200000000000000000000000000000000000042
OR token1 = 0x4200000000000000000000000000000000000042)
{% if is_incremental() %}
AND {{ incremental_predicate('evt_block_time') }}
{% endif %}
),

curve_op_addresses AS (
SELECT
pool AS address,
NULL AS token0,
NULL AS token1,
0x4200000000000000000000000000000000000042 AS token_address,
NULL AS creation_time,
'curve' AS protocol_name,
'1' AS version
FROM
{{ source('curve_optimism', 'pools') }}
WHERE
token = 0x4200000000000000000000000000000000000042
),

op_addresses AS (
SELECT * FROM uniswap_v3_op_addresses
UNION ALL
SELECT * FROM uniswap_v2_op_addresses
UNION ALL
SELECT * FROM velodrome_v2_op_addresses
UNION ALL
SELECT * FROM velodrome_v2_cl_op_addresses
UNION ALL
SELECT * FROM velodrome_v1_op_addresses
UNION ALL
SELECT * FROM solidly_v3_op_addresses
UNION ALL
SELECT * FROM openxswap_v1_op_addresses
UNION ALL
SELECT * FROM curve_op_addresses
),

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,
p.token1,
p.token_address AS token,
p.creation_time,
p.protocol_name,
p.version,
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
WHERE
COALESCE(b.balance, 0) > 100

This file was deleted.

6 changes: 5 additions & 1 deletion sources/_sector/dex/trades/optimism/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ sources:
- name: openxswap_optimism
tables:
- name: Aggregator_evt_Swap
- name: UniswapV2Factory_evt_PairCreated
- name: openocean_v2_optimism
tables:
- name: OpenOceanExchangeProxy_evt_Swapped
Expand Down Expand Up @@ -101,6 +102,9 @@ sources:
- name: swaap_v2_optimism
tables:
- name: Vault_evt_Swap
- name: curve_optimism
tables:
- name: pools
- name: timeswap_v2_optimism
tables:
- name: TimeswapV2Option_evt_Swap
Expand All @@ -109,4 +113,4 @@ sources:
- name: SwapFlashLoan_evt_TokenSwap
- name: bridgers_optimism
tables:
- name: Bridgers_evt_Swap
- name: Bridgers_evt_Swap