mirror of
https://github.com/FlipsideCrypto/solana-models.git
synced 2026-02-06 14:26:55 +00:00
Stake account states (#627)
* add streamline stake accounts states * add job to run snapshot
This commit is contained in:
parent
65582557b5
commit
9562fd5ace
45
.github/workflows/dbt_run_streamline_stake_accounts_snapshot.yml
vendored
Normal file
45
.github/workflows/dbt_run_streamline_stake_accounts_snapshot.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: dbt_run_streamline_stake_accounts_snapshot
|
||||
run-name: dbt_run_streamline_stake_accounts_snapshot
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Runs 01:22 daily (see https://crontab.guru)
|
||||
- cron: '22 1 * * *'
|
||||
|
||||
env:
|
||||
DBT_PROFILES_DIR: "${{ vars.DBT_PROFILES_DIR }}"
|
||||
|
||||
ACCOUNT: "${{ vars.ACCOUNT }}"
|
||||
ROLE: "${{ vars.ROLE }}"
|
||||
USER: "${{ vars.USER }}"
|
||||
PASSWORD: "${{ secrets.PASSWORD }}"
|
||||
REGION: "${{ vars.REGION }}"
|
||||
DATABASE: "${{ vars.DATABASE }}"
|
||||
WAREHOUSE: "${{ vars.WAREHOUSE }}"
|
||||
SCHEMA: "${{ vars.SCHEMA }}"
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}
|
||||
|
||||
jobs:
|
||||
run_dbt_jobs:
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: workflow_prod
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "${{ vars.PYTHON_VERSION }}"
|
||||
cache: "pip"
|
||||
|
||||
- name: install dependencies
|
||||
run: |
|
||||
pip install -r requirements.txt
|
||||
dbt deps
|
||||
- name: Run DBT Jobs
|
||||
run: |
|
||||
dbt build -s "solana_models,tag:streamline_stake_accounts"
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
{{ config(
|
||||
materialized = 'table',
|
||||
unique_key = ['account_address'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['streamline_stake_accounts']
|
||||
) }}
|
||||
|
||||
{% set stake_program_address = 'Stake11111111111111111111111111111111111111' %}
|
||||
|
||||
WITH base_stake_account_events AS (
|
||||
/*
|
||||
This first select is a very special case...
|
||||
It seems this account's creation / delegation event is listed as "FAILED" on very old blocks (646291, 646008)
|
||||
and there are no subsequent successful creation / delegations
|
||||
I can't find another case of this but looking on explorers the data is the same...
|
||||
It has an active delegation but the creation/delegation event is from a failed TX
|
||||
The code below is to manually include this one account so that it is marked as `is_active=TRUE`
|
||||
*/
|
||||
SELECT
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
index,
|
||||
-1 AS inner_index,
|
||||
event_type,
|
||||
CASE
|
||||
WHEN event_type = 'merge' THEN
|
||||
instruction:parsed:info:source::string
|
||||
WHEN event_type = 'split' THEN
|
||||
instruction:parsed:info:newSplitAccount::string
|
||||
ELSE
|
||||
instruction:parsed:info:stakeAccount::string
|
||||
END AS account_address,
|
||||
FROM
|
||||
{{ ref('silver__events') }}
|
||||
WHERE
|
||||
program_id = '{{ stake_program_address }}'
|
||||
AND instruction:parsed:info:stakeAccount::string = '7BUrMkGxj7weJQLZf8yNLSQUUA1uWxwr6tkMx4wn9pzn'
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
index,
|
||||
-1 AS inner_index,
|
||||
event_type,
|
||||
CASE
|
||||
WHEN event_type = 'merge' THEN
|
||||
instruction:parsed:info:source::string
|
||||
WHEN event_type = 'split' THEN
|
||||
instruction:parsed:info:newSplitAccount::string
|
||||
ELSE
|
||||
instruction:parsed:info:stakeAccount::string
|
||||
END AS account_address,
|
||||
FROM
|
||||
{{ ref('silver__events') }}
|
||||
WHERE
|
||||
program_id = '{{ stake_program_address }}'
|
||||
AND succeeded
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
e.index,
|
||||
i.index AS inner_index,
|
||||
i.value:parsed:type::string AS inner_event_type,
|
||||
CASE
|
||||
WHEN inner_event_type = 'merge' THEN
|
||||
i.value:parsed:info:source::string
|
||||
WHEN inner_event_type = 'split' THEN
|
||||
i.value:parsed:info:newSplitAccount::string
|
||||
ELSE
|
||||
i.value:parsed:info:stakeAccount::string
|
||||
END AS account_address,
|
||||
FROM
|
||||
{{ ref('silver__events') }} e
|
||||
JOIN
|
||||
TABLE(flatten(e.inner_instruction:instructions)) i
|
||||
WHERE
|
||||
array_contains('{{ stake_program_address }}'::variant, inner_instruction_program_ids)
|
||||
AND i.value :programId :: STRING = '{{ stake_program_address }}'
|
||||
AND succeeded
|
||||
)
|
||||
SELECT
|
||||
block_id,
|
||||
block_timestamp,
|
||||
account_address,
|
||||
event_type NOT IN ('deactivate','deactivateDelinquent','merge') AS is_active,
|
||||
event_type = 'delegate' AS is_delegated,
|
||||
FROM
|
||||
base_stake_account_events
|
||||
WHERE
|
||||
event_type IN ('initialize','delegate','deactivate','deactivateDelinquent','split','merge')
|
||||
QUALIFY
|
||||
row_number() OVER (PARTITION BY account_address ORDER BY block_id DESC, index DESC, inner_index DESC) = 1
|
||||
@ -0,0 +1,27 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: streamline__stake_account_states
|
||||
description: >
|
||||
The purpose of this model is to feed into a streamline view to request current account data for all "current" accounts owned by the stake program
|
||||
This model is an APPROXIMATION of current stake account states. All stake program owned accounts are included + maybe some that are not owned by the program anymore.
|
||||
There is also a likelihood that a small percentage of accounts listed as `IS_ACTIVE=TRUE` is not actually active.
|
||||
These caveats should be accounted for downstream after retrieving the data from the node.
|
||||
columns:
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
- name: ACCOUNT_ADDRESS
|
||||
description: Stake account address we want to retrieve account info for
|
||||
tests:
|
||||
- not_null
|
||||
- name: IS_ACTIVE
|
||||
description: Whether the stake account is currently active
|
||||
tests:
|
||||
- not_null
|
||||
- name: IS_DELEGATED
|
||||
description: Whether the stake account is currently delegated
|
||||
tests:
|
||||
- not_null
|
||||
Loading…
Reference in New Issue
Block a user