mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 11:06:45 +00:00
An 1779/ez token transfers (#49)
* Token transfers model and tests * logic to include transfers only * Ez token transfers and tests * Silver incremental model and core view * Incremental adds and date change
This commit is contained in:
parent
123d690227
commit
417f5df20d
18
models/core/core__ez_token_transfers.sql
Normal file
18
models/core/core__ez_token_transfers.sql
Normal file
@ -0,0 +1,18 @@
|
||||
{{ config(
|
||||
materialized = 'view'
|
||||
) }}
|
||||
|
||||
|
||||
SELECT
|
||||
block_height,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
sender,
|
||||
recipient,
|
||||
token_contract,
|
||||
amount,
|
||||
tx_succeeded
|
||||
FROM
|
||||
{{ ref('silver__token_transfers') }}
|
||||
WHERE
|
||||
block_timestamp::date >= '2022-04-20'
|
||||
82
models/core/core__ez_token_transfers.yml
Normal file
82
models/core/core__ez_token_transfers.yml
Normal file
@ -0,0 +1,82 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: core__ez_token_transfers
|
||||
description: |-
|
||||
This table records all token transfers on the FLOW blockchain.
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- tx_id
|
||||
- sender
|
||||
- recipient
|
||||
- token_contract
|
||||
|
||||
columns:
|
||||
- name: tx_id
|
||||
description: "{{ doc('tx_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: block_timestamp
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
|
||||
- name: block_height
|
||||
description: "{{ doc('block_height') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
|
||||
- name: sender
|
||||
description: "{{ doc('sender') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: recipient
|
||||
description: "{{ doc('recipient') }}"
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: token_contract
|
||||
description: "{{ doc('token_contract') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- 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
|
||||
|
||||
- name: tx_succeeded
|
||||
description: "{{ doc('tx_succeeded') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- BOOLEAN
|
||||
5
models/descriptions/recipient.md
Normal file
5
models/descriptions/recipient.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs recipient %}
|
||||
|
||||
Address receiving the transferred token.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/sender.md
Normal file
5
models/descriptions/sender.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs sender %}
|
||||
|
||||
Address sending the transferred token.
|
||||
|
||||
{% enddocs %}
|
||||
119
models/silver/silver__token_transfers.sql
Normal file
119
models/silver/silver__token_transfers.sql
Normal file
@ -0,0 +1,119 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::date'],
|
||||
unique_key = "CONCAT_WS('-', tx_id, sender, recipient, token_contract)"
|
||||
) }}
|
||||
|
||||
WITH transfers AS (
|
||||
|
||||
SELECT
|
||||
_inserted_timestamp,
|
||||
tx_id,
|
||||
COUNT(event_type) AS event_count,
|
||||
MAX(event_index + 1) AS max_index
|
||||
FROM
|
||||
{{ ref('silver__events_final') }}
|
||||
WHERE
|
||||
event_type IN ('TokensDeposited', 'TokensWithdrawn', 'FeesDeducted')
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
GROUP BY
|
||||
_inserted_timestamp, tx_id
|
||||
HAVING
|
||||
event_count = max_index
|
||||
),
|
||||
|
||||
|
||||
|
||||
withdraws AS (
|
||||
|
||||
SELECT
|
||||
block_height,
|
||||
_inserted_timestamp,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
event_data:from::STRING AS sender,
|
||||
event_contract AS token_contract,
|
||||
event_data:amount::FLOAT AS amount,
|
||||
tx_succeeded
|
||||
FROM
|
||||
{{ ref('silver__events_final') }}
|
||||
WHERE
|
||||
tx_id IN (SELECT tx_id FROM transfers)
|
||||
AND
|
||||
event_type = 'TokensWithdrawn'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
GROUP BY
|
||||
block_height, _inserted_timestamp, block_timestamp, tx_id, sender, token_contract, amount, tx_succeeded
|
||||
|
||||
),
|
||||
|
||||
deposits AS (
|
||||
|
||||
SELECT
|
||||
tx_id,
|
||||
_inserted_timestamp,
|
||||
event_data:to::STRING AS recipient,
|
||||
event_contract AS token_contract,
|
||||
event_data:amount::FLOAT AS amount
|
||||
FROM
|
||||
{{ ref('silver__events_final') }}
|
||||
WHERE
|
||||
tx_id IN (SELECT tx_id FROM transfers)
|
||||
AND
|
||||
event_type = 'TokensDeposited'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
GROUP BY
|
||||
tx_id, _inserted_timestamp, recipient, token_contract, amount
|
||||
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_height,
|
||||
w._inserted_timestamp AS _inserted_timestamp,
|
||||
block_timestamp,
|
||||
w.tx_id,
|
||||
sender,
|
||||
recipient,
|
||||
w.token_contract,
|
||||
SUM(COALESCE(d.amount, w.amount)) AS amount,
|
||||
tx_succeeded
|
||||
FROM
|
||||
withdraws w
|
||||
LEFT JOIN
|
||||
deposits d
|
||||
ON w.tx_id = d.tx_id
|
||||
AND w.token_contract = d.token_contract
|
||||
AND w.amount = d.amount
|
||||
WHERE sender IS NOT NULL
|
||||
GROUP BY
|
||||
block_height, w._inserted_timestamp, block_timestamp, w.tx_id, sender, recipient, w.token_contract, tx_succeeded
|
||||
82
models/silver/silver__token_transfers.yml
Normal file
82
models/silver/silver__token_transfers.yml
Normal file
@ -0,0 +1,82 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: silver__token_transfers
|
||||
description: |-
|
||||
This table records all token transfers on the FLOW blockchain.
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- tx_id
|
||||
- sender
|
||||
- recipient
|
||||
- token_contract
|
||||
|
||||
columns:
|
||||
- name: tx_id
|
||||
description: "{{ doc('tx_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: block_timestamp
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
|
||||
- name: block_height
|
||||
description: "{{ doc('block_height') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
|
||||
- name: sender
|
||||
description: "{{ doc('sender') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: recipient
|
||||
description: "{{ doc('recipient') }}"
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: token_contract
|
||||
description: "{{ doc('token_contract') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- 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
|
||||
|
||||
- name: tx_succeeded
|
||||
description: "{{ doc('tx_succeeded') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- BOOLEAN
|
||||
Loading…
Reference in New Issue
Block a user