mirror of
https://github.com/FlipsideCrypto/aptos-models.git
synced 2026-02-06 11:06:43 +00:00
gold model
This commit is contained in:
parent
8cbad416a9
commit
62c13565ed
25
models/gold/core/core__ez_balances.sql
Normal file
25
models/gold/core/core__ez_balances.sql
Normal file
@ -0,0 +1,25 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
tags = ['core']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
f.block_date,
|
||||
f.address,
|
||||
f.token_address,
|
||||
f.balance_unadj,
|
||||
f.balance,
|
||||
f.balance * p.price AS balance_usd,
|
||||
f.symbol,
|
||||
f.name,
|
||||
f.decimals,
|
||||
COALESCE(p.is_verified, FALSE) AS token_is_verified,
|
||||
f.frozen,
|
||||
f.fact_balances_id AS ez_balances_id,
|
||||
f.inserted_timestamp,
|
||||
f.modified_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_balances') }} f
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }} p
|
||||
ON LOWER(f.token_address) = LOWER(p.token_address)
|
||||
AND p.hour = f.block_date::TIMESTAMP
|
||||
43
models/gold/core/core__fact_balances.sql
Normal file
43
models/gold/core/core__fact_balances.sql
Normal file
@ -0,0 +1,43 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
tags = ['core']
|
||||
) }}
|
||||
|
||||
WITH balances_with_last_positive AS (
|
||||
SELECT
|
||||
block_date,
|
||||
address,
|
||||
token_address,
|
||||
post_balance,
|
||||
frozen,
|
||||
balances_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
LAST_VALUE(CASE WHEN post_balance > 0 THEN block_date END IGNORE NULLS) OVER (
|
||||
PARTITION BY address, token_address
|
||||
ORDER BY block_date
|
||||
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
|
||||
) AS last_positive_date
|
||||
FROM {{ ref('silver__balances') }}
|
||||
)
|
||||
|
||||
SELECT
|
||||
b.block_date,
|
||||
b.address,
|
||||
b.token_address,
|
||||
b.post_balance AS balance_unadj,
|
||||
b.post_balance / NULLIF(POW(10, COALESCE(t.decimals, 0)), 0) AS balance,
|
||||
COALESCE(t.symbol, NULL) AS symbol,
|
||||
t.name,
|
||||
t.decimals,
|
||||
b.frozen,
|
||||
b.balances_id AS fact_balances_id,
|
||||
b.inserted_timestamp,
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
balances_with_last_positive b
|
||||
LEFT JOIN {{ ref('core__dim_tokens') }} t
|
||||
ON LOWER(b.token_address) = LOWER(t.token_address)
|
||||
WHERE
|
||||
b.post_balance > 0
|
||||
OR (b.post_balance = 0 AND DATEDIFF('day', b.last_positive_date, b.block_date) <= 1) -- reducing 3d grace period for zero balances to only just 1d of 0's
|
||||
Loading…
Reference in New Issue
Block a user