new transactions

This commit is contained in:
sam 2024-11-07 15:42:47 +08:00
parent 76ea43e608
commit 28d6daf096
8 changed files with 87 additions and 58 deletions

5
makefile Normal file
View File

@ -0,0 +1,5 @@
refresh_package:
rm -f package-lock.yml
dbt clean
dbt deps

View File

@ -7,27 +7,38 @@
SELECT
A.block_number AS block_number,
block_timestamp,
block_hash,
tx_hash,
nonce,
POSITION,
origin_function_signature,
from_address,
to_address,
origin_function_signature,
VALUE,
value_precise_raw,
value_precise,
tx_fee,
tx_fee_precise,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
-- new column
tx_type,
-- new column
nonce,
POSITION AS tx_position,
-- new column
input_data,
gas_price,
effective_gas_price,
gas AS gas_limit,
gas_used,
gas AS gas_limit,
cumulative_gas_used,
effective_gas_price,
max_fee_per_gas,
max_priority_fee_per_gas,
l1_gas_price,
l1_gas_used,
l1_fee_scalar,
l1_fee,
l1_fee_precise,
l1_fee,
OBJECT_CONSTRUCT(
'l1_state_batch_index',
state_batch_index,
@ -36,26 +47,26 @@ SELECT
'l1_state_root_tx_hash',
state_tx_hash
) AS l1_submission_details,
cumulative_gas_used,
max_fee_per_gas,
max_priority_fee_per_gas,
input_data,
tx_status AS status,
-- remove this later
r,
s,
v,
COALESCE (
transactions_id,
{{ dbt_utils.generate_surrogate_key(
['tx_hash']
) }}
) AS fact_transactions_id,
GREATEST(COALESCE(A.inserted_timestamp, '2000-01-01'), COALESCE(b.inserted_timestamp, '2000-01-01')) AS inserted_timestamp,
transactions_id AS fact_transactions_id,
{# GREATEST(COALESCE(A.inserted_timestamp, '2000-01-01'), COALESCE(b.inserted_timestamp, '2000-01-01')) AS inserted_timestamp,
GREATEST(COALESCE(A.modified_timestamp, '2000-01-01'), COALESCE(b.modified_timestamp, '2000-01-01')) AS modified_timestamp,
#}
A.inserted_timestamp,
A.modified_timestamp,
tx_status AS status,
--deprecate
POSITION,
-- deprecate
deposit_nonce,
deposit_receipt_version
-- deprecate
deposit_receipt_version -- deprecate
FROM
{{ ref('silver__transactions') }} A
LEFT JOIN {{ ref('silver__state_hashes') }}
-- remove this join later
b
ON A.block_number = b.block_number

View File

@ -13,7 +13,7 @@ SELECT
to_address AS created_contract_address,
from_address AS creator_address,
input AS created_contract_input,
_inserted_timestamp,
modified_timestamp AS inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(
['to_address']
) }} AS created_contracts_id,
@ -21,14 +21,13 @@ SELECT
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
{{ ref('silver__traces') }}
{{ ref('core__fact_traces') }}
WHERE
TYPE ILIKE 'create%'
AND to_address IS NOT NULL
AND input IS NOT NULL
AND input != '0x'
AND tx_status = 'SUCCESS'
AND trace_status = 'SUCCESS'
AND input != '0x' {# AND tx_succeeded
AND trace_succeeded #}
{% if is_incremental() %}
AND _inserted_timestamp >= (
@ -63,4 +62,4 @@ FROM
{% if is_incremental() %}
WHERE
1 = 2
{% endif %}
{% endif %}

View File

@ -16,6 +16,7 @@ WITH base AS (
from_address AS origin_from_address,
to_address AS origin_to_address,
tx_status,
{# position AS tx_position, --new column #}
logs,
_inserted_timestamp
FROM
@ -39,6 +40,7 @@ flat_logs AS (
origin_from_address,
origin_to_address,
tx_status,
{# tx_position, #}
VALUE :address :: STRING AS contract_address,
VALUE :blockHash :: STRING AS block_hash,
VALUE :data :: STRING AS DATA,
@ -63,6 +65,7 @@ new_records AS (
l.origin_to_address,
txs.origin_function_signature,
l.tx_status,
{# l.tx_position, #}
l.contract_address,
l.block_hash,
l.data,
@ -107,6 +110,7 @@ missing_data AS (
t.origin_to_address,
txs.origin_function_signature,
t.tx_status,
{# t.tx_position, #}
t.contract_address,
t.block_hash,
t.data,
@ -140,6 +144,7 @@ FINAL AS (
origin_to_address,
origin_function_signature,
tx_status,
{# tx_position, #}
contract_address,
block_hash,
DATA,
@ -162,6 +167,7 @@ SELECT
origin_to_address,
origin_function_signature,
tx_status,
{# tx_position, #}
contract_address,
block_hash,
DATA,

View File

@ -16,19 +16,30 @@ WITH eth_base AS (
identifier,
from_address,
to_address,
eth_value,
_call_id,
_inserted_timestamp,
eth_value_precise_raw,
eth_value_precise,
tx_position,
VALUE,
concat_ws(
'_',
block_number,
--tx_position,
CONCAT(
TYPE,
'-',
trace_address
)
) AS _call_id,
modified_timestamp AS _inserted_timestamp,
value_precise_raw,
value_precise,
--tx_position,
trace_index
FROM
{{ ref('silver__traces') }}
{{ ref('core__fact_traces') }}
WHERE
eth_value > 0
VALUE > 0
AND tx_status = 'SUCCESS'
AND trace_status = 'SUCCESS'
AND trace_status = 'SUCCESS' -- need to delete
{# and tx_succeeded
AND trace_succeeded #} -- add in later
AND TYPE NOT IN (
'DELEGATECALL',
'STATICCALL'
@ -51,7 +62,7 @@ tx_table AS (
to_address AS origin_to_address,
origin_function_signature
FROM
{{ ref('silver__transactions') }}
{{ ref('core__fact_transactions') }}
WHERE
tx_hash IN (
SELECT
@ -61,7 +72,7 @@ tx_table AS (
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
AND modified_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '72 hours'
FROM
@ -79,11 +90,11 @@ SELECT
origin_function_signature,
from_address,
to_address,
eth_value AS amount,
eth_value_precise_raw AS amount_precise_raw,
eth_value_precise AS amount_precise,
VALUE AS amount,
value_precise_raw AS amount_precise_raw,
value_precise AS amount_precise,
ROUND(
eth_value * price,
VALUE * price,
2
) AS amount_usd,
_call_id,
@ -98,7 +109,8 @@ SELECT
'{{ invocation_id }}' AS _invocation_id
FROM
eth_base A
LEFT JOIN {{ ref('silver__complete_token_prices') }} p
LEFT JOIN {{ ref('silver__complete_token_prices') }}
p
ON DATE_TRUNC(
'hour',
A.block_timestamp

View File

@ -10,14 +10,14 @@ WITH emitted_events AS (
SELECT
contract_address,
COUNT(*) AS event_count,
MAX(_inserted_timestamp) AS max_inserted_timestamp_logs,
MAX(modified_timestamp) AS max_inserted_timestamp_logs,
MAX(block_number) AS latest_event_block
FROM
{{ ref('silver__logs') }}
{{ ref('core__fact_event_logs') }}
{% if is_incremental() %}
WHERE
_inserted_timestamp > (
modified_timestamp > (
SELECT
MAX(max_inserted_timestamp_logs)
FROM
@ -29,25 +29,21 @@ GROUP BY
),
function_calls AS (
SELECT
IFF(
TYPE = 'DELEGATECALL',
from_address,
to_address
) AS contract_address,
to_address AS contract_address,
COUNT(*) AS function_call_count,
MAX(_inserted_timestamp) AS max_inserted_timestamp_traces,
MAX(modified_timestamp) AS max_inserted_timestamp_traces,
MAX(block_number) AS latest_call_block
FROM
{{ ref('silver__traces') }}
{{ ref('core__fact_traces') }}
WHERE
tx_status = 'SUCCESS'
AND trace_status = 'SUCCESS'
1 = 1 {# tx_succeeded
AND trace_succeeded #}
AND to_address IS NOT NULL
AND input IS NOT NULL
AND input <> '0x'
{% if is_incremental() %}
AND _inserted_timestamp > (
AND modified_timestamp > (
SELECT
MAX(max_inserted_timestamp_traces)
FROM

View File

@ -10,9 +10,9 @@ packages:
- package: get-select/dbt_snowflake_query_tags
version: 2.5.0
- git: https://github.com/FlipsideCrypto/fsc-evm.git
revision: 9326ce6c0b1a8fb7dbd9eb8c3f22a32628ff7883
revision: ec6adae14ab4060ad4a553fb7f32d7e57693996d
- package: calogica/dbt_date
version: 0.7.2
- git: https://github.com/FlipsideCrypto/livequery-models.git
revision: b024188be4e9c6bc00ed77797ebdc92d351d620e
sha1_hash: 33a323ebe67678ba663438f7b6a41ab7451ae3b6
sha1_hash: 622a679ecf98e6ebf3c904241902ce5328c77e52

View File

@ -10,4 +10,4 @@ packages:
- package: get-select/dbt_snowflake_query_tags
version: [">=2.0.0", "<3.0.0"]
- git: https://github.com/FlipsideCrypto/fsc-evm.git
revision: v1.3.0
revision: v1.5.0