mirror of
https://github.com/FlipsideCrypto/near-models.git
synced 2026-02-06 11:26:52 +00:00
add silver epoch parsing model
This commit is contained in:
parent
3bbd23691c
commit
6389d8f689
5
models/descriptions/_epoch_id.md
Normal file
5
models/descriptions/_epoch_id.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs _epoch_id %}
|
||||
|
||||
An internal identifier for the epoch. This is a hashed representation of the pool_id and epoch number.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/epoch_number.md
Normal file
5
models/descriptions/epoch_number.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs epoch_number %}
|
||||
|
||||
The epoch number for this staking reward payout. Epoch increment in order every 43,200 blocks.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/reward_tokens.md
Normal file
5
models/descriptions/reward_tokens.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs reward_tokens %}
|
||||
|
||||
The total amount of tokens rewarded to the validator for this staking reward payout. Number is presented raw and not decimal adjusted in the fact table.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/total_staked_balance.md
Normal file
5
models/descriptions/total_staked_balance.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs total_staked_balance %}
|
||||
|
||||
The total staked NEAR at the time of the reward payout. Number is presented raw and not decimal adjusted in the fact table.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/total_staking_shares.md
Normal file
5
models/descriptions/total_staking_shares.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs total_staking_shares %}
|
||||
|
||||
Total staking shares that comprise the staked balance of the pool. Number is presented raw and not decimal adjusted in the fact table.
|
||||
|
||||
{% enddocs %}
|
||||
@ -18,6 +18,7 @@ WITH receipts AS (
|
||||
{% else %}
|
||||
{{ incremental_load_filter('_load_timestamp') }}
|
||||
{% endif %}
|
||||
AND receipt_succeeded
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
61
models/silver/curated/staking/silver__staking_epochs.sql
Normal file
61
models/silver/curated/staking/silver__staking_epochs.sql
Normal file
@ -0,0 +1,61 @@
|
||||
{{ config(
|
||||
materialized = 'table',
|
||||
unique_key = '_epoch_id',
|
||||
incremental_strategy = 'delete+insert',
|
||||
tags = ['curated'],
|
||||
cluster_by = ['block_id']
|
||||
) }}
|
||||
|
||||
WITH pool_events AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__pool_events') }}
|
||||
WHERE
|
||||
{% if var("MANUAL_FIX") %}
|
||||
{{ partition_load_manual('no_buffer') }}
|
||||
{% else %}
|
||||
{{ incremental_load_filter('_load_timestamp') }}
|
||||
{% endif %}
|
||||
AND LOG LIKE 'Epoch%'
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
receiver_id AS pool_id,
|
||||
SUBSTR(REGEXP_SUBSTR(LOG, 'Epoch [0-9]+'), 7) :: NUMBER AS epoch_number,
|
||||
REGEXP_SUBSTR(
|
||||
REGEXP_SUBSTR(
|
||||
LOG,
|
||||
'Contract received total rewards of [0-9]+'
|
||||
),
|
||||
'[0-9]+'
|
||||
) :: NUMBER AS reward_tokens,
|
||||
REGEXP_SUBSTR(
|
||||
REGEXP_SUBSTR(
|
||||
LOG,
|
||||
'New total staked balance is [0-9]+'
|
||||
),
|
||||
'[0-9]+'
|
||||
) :: NUMBER AS total_staked_balance,
|
||||
REGEXP_SUBSTR(
|
||||
REGEXP_SUBSTR(
|
||||
LOG,
|
||||
'Total number of shares [0-9]+'
|
||||
),
|
||||
'[0-9]+'
|
||||
) :: NUMBER AS total_staking_shares,
|
||||
LOG,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number,
|
||||
{{ dbt_utils.generate_surrogate_key(['pool_id', 'epoch_number']) }} AS _epoch_id
|
||||
FROM
|
||||
pool_events
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
77
models/silver/curated/staking/silver__staking_epochs.yml
Normal file
77
models/silver/curated/staking/silver__staking_epochs.yml
Normal file
@ -0,0 +1,77 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: silver__staking_epochs
|
||||
description: |-
|
||||
This table extracts epoch information for each pool from the logs of the reward receipts.
|
||||
Note, it appears that the epoch log is only recorded during an act of withdrawal or deposit by a delegator, anbd not on each epoch.
|
||||
|
||||
tests:
|
||||
- dbt_utils.recency:
|
||||
datepart: day
|
||||
field: block_timestamp
|
||||
interval: 1
|
||||
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
description: "{{ doc('tx_hash')}}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id')}}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: POOL_ID
|
||||
description: "{{ doc('pool_id')}}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: EPOCH_NUMBER
|
||||
description: "{{ doc('epoch_number')}}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_of_type:
|
||||
column_type: NUMBER
|
||||
|
||||
- name: REWARD_TOKENS
|
||||
description: "{{ doc('reward_tokens')}}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_of_type:
|
||||
column_type: NUMBER
|
||||
|
||||
- name: TOTAL_STAKED_BALANCE
|
||||
description: "{{ doc('total_staked_balance')}}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_of_type:
|
||||
column_type: NUMBER
|
||||
|
||||
- name: TOTAL_STAKING_SHARES
|
||||
description: "{{ doc('total_staking_shares')}}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_of_type:
|
||||
column_type: NUMBER
|
||||
|
||||
- name: LOG
|
||||
description: "{{ doc('log')}}"
|
||||
|
||||
- name: _LOAD_TIMESTAMP
|
||||
description: "{{ doc('_load_timestamp')}}"
|
||||
|
||||
- name: _PARTITION_BY_BLOCK_NUMBER
|
||||
description: "{{ doc('_partition_by_block_number')}}"
|
||||
|
||||
- name: _EPOCH_ID
|
||||
description: "{{ doc('_epoch_id')}}"
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
Loading…
Reference in New Issue
Block a user