usn silver and core ez models

This commit is contained in:
Geewynn 2022-07-29 00:53:08 +01:00
parent 649a6dd88a
commit 2dcb5d8570
8 changed files with 333 additions and 0 deletions

View File

@ -0,0 +1,23 @@
{{ config(
materialized = 'view',
secure = true
) }}
WITH transactions AS (
SELECT
*
FROM
{{ ref('silver__usn') }}
)
SELECT
block_timestamp,
block_id,
method_names,
tx_hash,
tx_receiver,
tx_signer,
old_owner,
new_owner,
amount
FROM transactions

View File

@ -0,0 +1,90 @@
version: 2
models:
- name: core__ez_usn
description: |-
This table records all the usn transaction in the near db
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
columns:
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- TIMESTAMP_NTZ
- name: BLOCK_ID
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: METHOD_NAMES
description: "{{ doc('method_names')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: TX_HASH
description: "{{ doc('tx_hash')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: TX_RECEIVER
description: "{{ doc('tx_receiver')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: TX_SIGNER
description: "{{ doc('tx_signer')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: OLD_OWNER
description: "{{ doc('old_owner')}}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: NEW_OWNER
description: "{{ doc('new_owner')}}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: AMOUNT
description: "{{ doc('amount')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT

View File

@ -0,0 +1,5 @@
{% docs amount %}
The amount of tokens transferred
{% enddocs %}

View File

@ -0,0 +1,6 @@
{% docs method_names %}
The function that is being called for the transaction
can be ft_transfer_call, ft_transfer or withdraw
{% enddocs %}

View File

@ -0,0 +1,5 @@
{% docs new_owner %}
The address that receives the token.
{% enddocs %}

View File

@ -0,0 +1,6 @@
{% docs old_owner %}
The previous owner of the token.
Can also be the address signing the transaction
{% enddocs %}

View File

@ -0,0 +1,108 @@
{{ config(
materialized = 'incremental',
unique_key = 'tx_hash',
incremental_strategy = 'delete+insert',
cluster_by = ['block_timestamp::DATE', '_inserted_timestamp::DATE'],
) }}
WITH txs AS (
SELECT
*
FROM
{{ ref('silver__transactions') }}
WHERE
{{ incremental_load_filter('_inserted_timestamp') }}
),
usn_tx AS (
SELECT
block_id,
tx_hash,
block_timestamp,
tx_receiver,
tx_signer,
tx: actions[0]: FunctionCall: method_name :: STRING AS method_names,
tx: receipt[0] :: VARIANT AS receipts,
tx: receipt[0]: outcome: logs :: VARIANT AS events,
_ingested_at,
_inserted_timestamp
FROM txs
where tx_receiver = 'usn'
),
usn_method_call AS (
SELECT
block_id,
tx_hash,
block_timestamp,
tx_receiver,
tx_signer,
method_names,
events,
_ingested_at,
_inserted_timestamp
FROM usn_tx
where method_names='ft_transfer_call' or method_names='ft_transfer' or method_names='withdraw'
),
parse_event AS (
SELECT
block_id,
tx_hash,
block_timestamp,
tx_receiver,
tx_signer,
method_names,
flatten_events.value AS events,
_ingested_at,
_inserted_timestamp
FROM usn_method_call,
lateral flatten(input => usn_method_call.events) AS flatten_events
),
extract_events AS (
SELECT
block_id,
tx_hash,
block_timestamp,
tx_receiver,
tx_signer,
method_names,
substr(events, 12, 1000) AS event_string,
_ingested_at,
_inserted_timestamp
FROM parse_event
),
extract_data AS (
SELECT
method_names,
block_id,
tx_hash,
block_timestamp,
tx_receiver,
tx_signer,
parse_json(event_string) AS event_data,
_ingested_at,
_inserted_timestamp
FROM extract_events
),
final AS (
SELECT
block_timestamp,
block_id,
method_names,
tx_hash,
tx_receiver,
tx_signer,
event_data: data[0]: old_owner_id::string AS old_owner,
event_data: data[0]: new_owner_id::string AS new_owner,
event_data: data[0]: amount::integer AS amount,
_ingested_at,
_inserted_timestamp
FROM extract_data
)
SELECT * FROM final

View File

@ -0,0 +1,90 @@
version: 2
models:
- name: silver__usn
description: |-
This table records all the usn transaction in the near db
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
columns:
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- TIMESTAMP_NTZ
- name: BLOCK_ID
description: "{{ doc('block_id')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT
- name: METHOD_NAMES
description: "{{ doc('method_names')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: TX_HASH
description: "{{ doc('tx_hash')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: TX_RECEIVER
description: "{{ doc('tx_receiver')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: TX_SIGNER
description: "{{ doc('tx_signer')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: OLD_OWNER
description: "{{ doc('old_owner')}}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: NEW_OWNER
description: "{{ doc('new_owner')}}"
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- STRING
- VARCHAR
- name: AMOUNT
description: "{{ doc('amount')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- NUMBER
- FLOAT