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: curve pools balances #7407

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{
config(
schema = 'curve_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 DISTINCT
CAST(pool AS varchar) AS pool_address
FROM {{ source('curve_optimism', 'pools') }}
WHERE token = 0x4200000000000000000000000000000042
),

filtered_balances AS (
SELECT
CAST(address AS varchar) AS pool_address,
balance AS op_balance,
day AS snapshot_day
FROM {{ source('tokens_optimism', 'balances_daily') }}
WHERE token_address = 0x4200000000000000000000000000000042
{% if is_incremental() %}
AND {{ incremental_predicate('day') }}
{% else %}
-- AND day >= date '2021-11-11'
-- {% endif %}
)

SELECT
p.pool_address,
'curve' as protocol_name,
'v1' as protocol_version,
b.snapshot_day,
COALESCE(b.op_balance, 0) as op_balance
FROM op_pools p
LEFT JOIN filtered_balances b
ON p.pool_address = b.pool_address
WHERE COALESCE(b.op_balance, 0) > 0
3 changes: 3 additions & 0 deletions sources/_subprojects_outputs/dex/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ sources:
- name: beethoven_x
tables:
- name: trades
- name: curve_optimism
tables:
- name: pools
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