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

Latest balances EVM models #7618

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
29 changes: 29 additions & 0 deletions dbt_subprojects/tokens/macros/balances/balances_latest.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{%- macro balances_latest(balances) %}

select
{{dbt_utils.generate_surrogate_key(['address', 'token_address', 'token_standard', "token_id"])}} as unique_key,
blockchain,
address,
token_address,
token_standard,
token_symbol,
token_id,
collection_name,
max(block_number) as block_number_latest,
max(block_time) as block_time_latest,
max_by(balance_raw, block_number) as balance_raw_latest,
max_by(balance, block_number) as balance_latest
from {{balances}}
where
{{ incremental_predicate('block_time') }}
-- for testing
and block_time > timestamp '2025-01-27 00:00:00.000 +0000'
group by
blockchain,
address,
token_address,
token_standard,
token_symbol,
token_id,
collection_name
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,25 @@ models:
- name: symbol
- name: decimals
- name: collection_name

- name: tokens_ethereum_balances_latest
meta:
blockchain: ethereum
sector: tokens
contributors: et-dynamic
config:
tags: ['tokens','balances', 'ethereum']
description: "Most recent token balances enriched"
columns:
- name: unique_key
- name: blockchain
- name: address
- name: token_address
- name: token_standard
- name: token_symbol
- name: token_id
- name: collection_name
- name: block_number_latest
- name: block_time_latest
- name: balance_raw_latest
- name: balance_latest
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{config(
schema = 'tokens_ethereum',
alias = 'balances_latest',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['unique_key'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
post_hook='{{ expose_spells(\'["ethereum"]\',
"sector",
"balances_latest",
\'["et-dynamic"]\') }}'
)
}}

{{
balances_latest(
balances = ref('tokens_ethereum_balances'),
)
}}
Loading