mirror of
https://github.com/FlipsideCrypto/near-models.git
synced 2026-02-06 11:26:52 +00:00
revise actions to receipts
This commit is contained in:
parent
f180c57071
commit
9aa668cc57
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = true
|
||||
secure = true,
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
|
||||
@ -7,13 +7,21 @@
|
||||
'PURPOSE': 'STAKING'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
with staking_actions as (
|
||||
select
|
||||
*
|
||||
from {{ ref('silver__staking_actions') }}
|
||||
from {{ ref('silver__staking_actions_s3') }}
|
||||
)
|
||||
|
||||
select * from staking_actions
|
||||
select
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
pool_address,
|
||||
tx_signer,
|
||||
stake_amount,
|
||||
action
|
||||
from staking_actions
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
'PURPOSE': 'STAKING'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
WITH staking_pools AS (
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = true
|
||||
secure = true,
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
WITH token_labels AS (
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
'PURPOSE': 'DEFI, SWAPS'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
WITH dex_swaps AS (
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
'PURPOSE': 'NFT'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
with mints as (
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = true
|
||||
secure = true,
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
WITH transactions AS (
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
secure = true
|
||||
) }}
|
||||
|
||||
WITH actions_events AS (
|
||||
WITH actions AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
@ -13,10 +13,11 @@ WITH actions_events AS (
|
||||
SELECT
|
||||
action_id,
|
||||
tx_hash,
|
||||
receipt_object_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
action_index,
|
||||
action_name,
|
||||
action_data
|
||||
FROM
|
||||
actions_events
|
||||
actions
|
||||
|
||||
@ -25,6 +25,15 @@ models:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: RECEIPT_OBJECT_ID
|
||||
description: "{{ doc('receipt_object_id')}}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id')}}"
|
||||
tests:
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = true
|
||||
secure = true,
|
||||
enabled = False
|
||||
) }}
|
||||
|
||||
WITH actions_events_addkey AS (
|
||||
|
||||
@ -3,7 +3,7 @@ version: 2
|
||||
models:
|
||||
- name: core__fact_actions_events_addkey
|
||||
description: |-
|
||||
This table extracts all AddKey events from actions and stores the argument data under action_data.
|
||||
Deprecating soon! Data is no longer updating. Please use the actions events table for AddKey type events
|
||||
|
||||
columns:
|
||||
- name: ACTION_ID
|
||||
|
||||
@ -3,7 +3,7 @@ version: 2
|
||||
models:
|
||||
- name: core__fact_actions_events_function_call
|
||||
description: |-
|
||||
This table extracts all FunctionCall events from actions and decodes the arguments for easy use.
|
||||
This table extracts all FunctionCall events from actions and decodes the arguments for easy use. If further nested arguments are encoded, the snowflake function `try_base64_decode_string()` will likely work.
|
||||
|
||||
columns:
|
||||
- name: ACTION_ID
|
||||
@ -69,8 +69,8 @@ models:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
- VARIANT
|
||||
- OBJECT
|
||||
|
||||
- name: DEPOSIT
|
||||
description: "{{ doc('deposit')}}"
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
'PURPOSE': 'PRICES'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
WITH oracle_prices AS (
|
||||
|
||||
@ -18,6 +18,8 @@ SELECT
|
||||
receipt_object_id,
|
||||
receipt_outcome_id,
|
||||
receiver_id,
|
||||
receipt_actions AS actions,
|
||||
execution_outcome AS outcome,
|
||||
gas_burnt,
|
||||
status_value,
|
||||
logs,
|
||||
|
||||
@ -44,7 +44,7 @@ models:
|
||||
tests:
|
||||
- not_null
|
||||
- unique:
|
||||
where: receipt_object_id not in ('FA9zcm7WkWxdjkub7WFiKkQdnnQrcEmBht94VFzXfkm1', '6QKTEHsLihDgVrdtWYbURA28zF29Xdw5dnfWbDVWHPv4')
|
||||
where: tx_hash != 'J4CZZQrZK6kYPVLkrdbTEpcqhUNZiRxktbMzHviqeGgf'
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
@ -58,7 +58,6 @@ models:
|
||||
column_type_list:
|
||||
- ARRAY
|
||||
- VARIANT
|
||||
- OBJECT
|
||||
|
||||
- name: RECEIVER_ID
|
||||
description: "{{ doc('receiver_id')}}"
|
||||
@ -69,6 +68,24 @@ models:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: ACTIONS
|
||||
description: "{{ doc('actions')}}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- OBJECT
|
||||
- VARIANT
|
||||
|
||||
- name: OUTCOME
|
||||
description: "{{ doc('outcome')}}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- OBJECT
|
||||
- VARIANT
|
||||
|
||||
- name: GAS_BURNT
|
||||
description: "{{ doc('gas_burnt')}}"
|
||||
tests:
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = true
|
||||
secure = true,
|
||||
tags = ['s3_curated']
|
||||
) }}
|
||||
|
||||
WITH transfers AS (
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{% docs action_id %}
|
||||
|
||||
The `action_id` as compiled from `tx_id` and `action_index`. This is unique for each record.
|
||||
The `action_id` as compiled from `tx_hash` or `receipt_id `and `action_index`. This is unique for each record. The primary hash depends on the source of the action, as both a transaction and a receipt can process actions.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
5
models/descriptions/action_source.md
Normal file
5
models/descriptions/action_source.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs action_source %}
|
||||
|
||||
The source object of the executed action, transaction or receipt.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/actions.md
Normal file
5
models/descriptions/actions.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs actions %}
|
||||
|
||||
The actions executed during the receipt or transaction processing.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/outcome.md
Normal file
5
models/descriptions/outcome.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs outcome %}
|
||||
|
||||
The outcome of the transaction, action, or receipt that was executed in the shard.
|
||||
|
||||
{% enddocs %}
|
||||
@ -3,7 +3,8 @@
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'action_id',
|
||||
cluster_by = ['block_timestamp::DATE', '_load_timestamp::DATE'],
|
||||
tags = ['curated', 's3_curated']
|
||||
tags = ['actions_s3'],
|
||||
enabled = False
|
||||
) }}
|
||||
|
||||
WITH action_events AS (
|
||||
@ -3,7 +3,7 @@ version: 2
|
||||
models:
|
||||
- name: silver__actions_events_addkey_s3
|
||||
description: |-
|
||||
This table extracts all AddKey events from actions and stores the argument data under action_data.
|
||||
Deprecting soon - no longer updating.
|
||||
|
||||
columns:
|
||||
- name: ACTION_ID
|
||||
@ -3,7 +3,7 @@
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['block_timestamp::DATE', '_load_timestamp::DATE'],
|
||||
unique_key = 'action_id',
|
||||
tags = ['curated', 's3_curated']
|
||||
tags = ['actions_s3']
|
||||
) }}
|
||||
|
||||
WITH action_events AS (
|
||||
@ -14,6 +14,7 @@ WITH action_events AS (
|
||||
{{ ref('silver__actions_events_s3') }}
|
||||
WHERE
|
||||
action_name = 'FunctionCall'
|
||||
|
||||
{% if target.name == 'manual_fix' or target.name == 'manual_fix_dev' %}
|
||||
AND {{ partition_load_manual('no_buffer') }}
|
||||
{% else %}
|
||||
@ -22,31 +23,38 @@ WITH action_events AS (
|
||||
),
|
||||
decoding AS (
|
||||
SELECT
|
||||
*,
|
||||
action_id,
|
||||
tx_hash,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
action_name,
|
||||
action_data :args AS args,
|
||||
COALESCE(TRY_PARSE_JSON(TRY_BASE64_DECODE_STRING(args)), TRY_BASE64_DECODE_STRING(args), args) AS args_decoded,
|
||||
COALESCE(TRY_PARSE_JSON(TRY_BASE64_DECODE_STRING(args)), args) AS args_decoded,
|
||||
action_data :deposit :: NUMBER AS deposit,
|
||||
action_data :gas :: NUMBER AS attached_gas,
|
||||
action_data :method_name :: STRING AS method_name
|
||||
action_data :method_name :: STRING AS method_name,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number
|
||||
FROM
|
||||
action_events),
|
||||
function_calls AS (
|
||||
SELECT
|
||||
action_id,
|
||||
tx_hash,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
action_name,
|
||||
method_name,
|
||||
args_decoded AS args,
|
||||
deposit,
|
||||
attached_gas,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number
|
||||
FROM
|
||||
decoding
|
||||
)
|
||||
action_events
|
||||
),
|
||||
function_calls AS (
|
||||
SELECT
|
||||
*
|
||||
action_id,
|
||||
tx_hash,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
action_name,
|
||||
method_name,
|
||||
args_decoded AS args,
|
||||
deposit,
|
||||
attached_gas,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number
|
||||
FROM
|
||||
function_calls
|
||||
decoding
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
function_calls
|
||||
79
models/silver/actions/silver__actions_events_s3.sql
Normal file
79
models/silver/actions/silver__actions_events_s3.sql
Normal file
@ -0,0 +1,79 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['block_timestamp::DATE', '_load_timestamp::DATE'],
|
||||
unique_key = 'action_id',
|
||||
tags = ['actions_s3']
|
||||
) }}
|
||||
|
||||
WITH receipts AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__streamline_receipts_final') }}
|
||||
|
||||
{% if target.name == 'manual_fix' or target.name == 'manual_fix_dev' %}
|
||||
WHERE
|
||||
{{ partition_load_manual('no_buffer') }}
|
||||
{% else %}
|
||||
WHERE
|
||||
{{ incremental_load_filter('_load_timestamp') }}
|
||||
{% endif %}
|
||||
),
|
||||
flatten_actions AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
receipt_object_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
chunk_hash,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number,
|
||||
receipt_actions,
|
||||
execution_outcome,
|
||||
VALUE AS action_object,
|
||||
INDEX AS action_index
|
||||
FROM
|
||||
receipts,
|
||||
LATERAL FLATTEN(
|
||||
input => receipt_actions :receipt :Action :actions
|
||||
)
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
receipt_object_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
chunk_hash,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number,
|
||||
this,
|
||||
key AS action_name,
|
||||
TRY_PARSE_JSON(VALUE) AS action_data,
|
||||
action_index
|
||||
FROM
|
||||
flatten_actions,
|
||||
LATERAL FLATTEN(
|
||||
input => action_object
|
||||
)
|
||||
)
|
||||
SELECT
|
||||
concat_ws(
|
||||
'-',
|
||||
receipt_object_id,
|
||||
action_index
|
||||
) AS action_id,
|
||||
chunk_hash,
|
||||
tx_hash,
|
||||
receipt_object_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
action_index,
|
||||
action_name,
|
||||
action_data,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number
|
||||
FROM
|
||||
FINAL
|
||||
@ -3,29 +3,60 @@ version: 2
|
||||
models:
|
||||
- name: silver__actions_events_s3
|
||||
description: |-
|
||||
This table extracts all action events from a transaction and stores the argument data under action_data.
|
||||
This table extracts all action events from a receipt and stores the argument data under action_data.
|
||||
|
||||
columns:
|
||||
- name: ACTION_ID
|
||||
description: "{{ doc('action_id')}}"
|
||||
tests:
|
||||
- unique:
|
||||
where: tx_hash != 'J4CZZQrZK6kYPVLkrdbTEpcqhUNZiRxktbMzHviqeGgf'
|
||||
- not_null
|
||||
|
||||
- name: CHUNK_HASH
|
||||
description: "{{ doc('chunk_hash')}}"
|
||||
tests:
|
||||
- not_null:
|
||||
where: "block_id not in (34691244, 34691277)"
|
||||
|
||||
- name: TX_HASH
|
||||
description: "{{ doc('tx_hash')}}"
|
||||
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: RECEIPT_OBJECT_ID
|
||||
description: "{{ doc('receipt_object_id')}}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id')}}"
|
||||
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: ACTION_INDEX
|
||||
description: "{{ doc('action_index')}}"
|
||||
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: ACTION_NAME
|
||||
description: "{{ doc('action_name')}}"
|
||||
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: ACTION_DATA
|
||||
description: "{{ doc('action_data')}}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- OBJECT
|
||||
- VARIANT
|
||||
|
||||
- name: _PARTITION_BY_BLOCK_NUMBER
|
||||
description: "{{ doc('_partition_by_block_number')}}"
|
||||
@ -1,80 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['block_timestamp::DATE', '_load_timestamp::DATE'],
|
||||
unique_key = 'action_id',
|
||||
tags = ['curated', 's3_curated']
|
||||
) }}
|
||||
|
||||
WITH txs AS (
|
||||
|
||||
SELECT
|
||||
block_id,
|
||||
block_hash,
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
nonce,
|
||||
signature,
|
||||
tx_receiver,
|
||||
tx_signer,
|
||||
tx,
|
||||
gas_used,
|
||||
transaction_fee,
|
||||
attached_gas,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number
|
||||
FROM
|
||||
{{ ref('silver__streamline_transactions_final') }}
|
||||
|
||||
{% if target.name == 'manual_fix' or target.name == 'manual_fix_dev' %}
|
||||
WHERE
|
||||
{{ partition_load_manual('no_buffer') }}
|
||||
{% else %}
|
||||
WHERE
|
||||
{{ incremental_load_filter('_load_timestamp') }}
|
||||
{% endif %}
|
||||
),
|
||||
actions AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
INDEX AS action_index,
|
||||
CASE
|
||||
WHEN VALUE LIKE '%CreateAccount%' THEN VALUE
|
||||
ELSE object_keys(VALUE) [0] :: STRING
|
||||
END AS action_name,
|
||||
CASE
|
||||
WHEN action_name = 'CreateAccount' THEN '{}'
|
||||
ELSE VALUE [action_name]
|
||||
END AS action_data,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number
|
||||
FROM
|
||||
txs,
|
||||
LATERAL FLATTEN(
|
||||
input => tx :actions
|
||||
)
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
concat_ws(
|
||||
'-',
|
||||
tx_hash,
|
||||
action_index
|
||||
) AS action_id,
|
||||
tx_hash,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
action_index,
|
||||
action_name,
|
||||
TRY_PARSE_JSON(action_data) AS action_data,
|
||||
_load_timestamp,
|
||||
_partition_by_block_number
|
||||
FROM
|
||||
actions
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
@ -35,6 +35,7 @@ models:
|
||||
tests:
|
||||
- not_null:
|
||||
where: "block_id not in (34691244, 34691277)"
|
||||
# these blocks have no chunks. Per explorer, no txs. Block includes chunks
|
||||
|
||||
- name: RECEIPT
|
||||
description: "{{ doc('receipt')}}"
|
||||
|
||||
@ -17,6 +17,9 @@ models:
|
||||
|
||||
- name: CHUNK_HASH
|
||||
description: "{{ doc('chunk_hash')}}"
|
||||
tests:
|
||||
- not_null:
|
||||
where: "block_id not in (34691244, 34691277)"
|
||||
|
||||
- name: RECEIPT_ACTIONS
|
||||
description: "{{ doc('receipt')}}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user