use existing daily staked supply model instead

This commit is contained in:
Jack Forgash 2023-12-01 11:44:15 -07:00
parent 26389d2aff
commit 0c5e3c6807
4 changed files with 48 additions and 23 deletions

1
.user.yml Normal file
View File

@ -0,0 +1 @@
id: 334b0b0d-f6fd-4045-bc01-391daabe59e2

View File

@ -51,16 +51,29 @@ daily_locked_and_staked_supply AS (
),
daily_staked_supply AS (
SELECT
*
date_day AS utc_date,
balance AS total_staked_supply
FROM
{{ ref('silver__atlas_supply_daily_staked_supply') }}
{{ ref('silver__pool_balance_daily') }}
),
daily_total_supply AS (
SELECT
end_time :: DATE AS utc_date,
total_near_supply
FROM
{{ ref('silver__atlas_supply_epochs') }}
qualify ROW_NUMBER() over (
PARTITION BY end_time :: DATE
ORDER BY
end_time DESC
) = 1
),
daily_supply_stats AS (
SELECT
s.utc_date,
s.total_supply,
ts.total_supply,
s.total_staked_supply,
s.total_supply - s.total_staked_supply AS total_nonstaked_supply,
ts.total_supply - s.total_staked_supply AS total_nonstaked_supply,
ls.total_locked_supply,
ls.locked_and_staked_supply,
GREATEST(
@ -78,6 +91,8 @@ daily_supply_stats AS (
daily_staked_supply AS s
LEFT JOIN daily_locked_and_staked_supply AS ls
ON ls.utc_date = s.utc_date
LEFT JOIN daily_total_supply AS ts
ON ts.utc_date = s.utc_date
),
output AS (
SELECT

View File

@ -3,9 +3,17 @@
cluster_by = ["utc_date"],
unique_key = "atlas_daily_staked_supply_id",
merge_exclude_columns = ["inserted_timestamp"],
tags = ['atlas', 'atlas_supply']
tags = ['atlas', 'atlas_supply'],
enabled = False
) }}
{#
Note - seems like a more complicated way to get to the result in silver__pool_balances(_daily). Both look for logs that emit the updated staked total,
but this query is calculating extra proposer and epoch stats and not using them.
Unnecessary compute, possibly from a separate analytical process.
The numbers do seem to differ, but individual pool balances in my silver table match near-staking exactly.
#}
WITH receipts AS (
SELECT
@ -27,18 +35,26 @@ WHERE
),
function_call AS (
SELECT
*
distinct tx_hash
FROM
{{ ref('silver__actions_events_function_call_s3') }}
WHERE
method_name IN (
'ping',
'stake',
'unstake',
'stake_all',
'unstake_all',
'deposit_and_stake'
)
{% if is_incremental() %}
WHERE
_inserted_timestamp :: DATE >= (
SELECT
MAX(utc_date) - INTERVAL '2 days'
FROM
{{ this }}
)
AND _inserted_timestamp :: DATE >= (
SELECT
MAX(utc_date) - INTERVAL '2 days'
FROM
{{ this }}
)
{% endif %}
),
blocks AS (
@ -96,15 +112,6 @@ staking_actions AS (
tx_hash
FROM
function_call
WHERE
method_name IN (
'ping',
'stake',
'unstake',
'stake_all',
'unstake_all',
'deposit_and_stake'
)
)
AND LEFT(
l.value :: STRING,
@ -115,7 +122,8 @@ staking_actions AS (
ORDER BY
block_timestamp DESC
) = 1
),
)
,
proposals AS (
SELECT
b.block_id,

View File

@ -6,6 +6,7 @@ near:
account: "{{ env_var('SF_ACCOUNT') }}"
# User/password auth
user: "{{ env_var('SF_USERNAME') }}"
authenticator: externalbrowser
password: "{{ env_var('SF_PASSWORD') }}"
role: "{{ env_var('SF_ROLE') }}"
schema: "{{ env_var('SF_SCHEMA') }}"