mirror of
https://github.com/FlipsideCrypto/sei-models.git
synced 2026-02-06 16:06:52 +00:00
parent
9a6ac07aa5
commit
230d999140
29
models/bronze/prices/bronze__complete_native_prices.sql
Normal file
29
models/bronze/prices/bronze__complete_native_prices.sql
Normal file
@ -0,0 +1,29 @@
|
||||
{{ config (
|
||||
materialized = 'view'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
HOUR,
|
||||
asset_id,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
price,
|
||||
blockchain,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
provider,
|
||||
source,
|
||||
_inserted_timestamp,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
complete_native_prices_id,
|
||||
_invocation_id
|
||||
FROM
|
||||
{{ source(
|
||||
'crosschain_silver',
|
||||
'complete_native_prices'
|
||||
) }}
|
||||
WHERE
|
||||
blockchain = 'sei'
|
||||
AND symbol = 'SEI'
|
||||
53
models/evm/bronze/api_udf/bronze_evm_api__contract_abis.sql
Normal file
53
models/evm/bronze/api_udf/bronze_evm_api__contract_abis.sql
Normal file
@ -0,0 +1,53 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "contract_address",
|
||||
full_refresh = false,
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH base AS (
|
||||
|
||||
SELECT
|
||||
contract_address
|
||||
FROM
|
||||
{{ ref('silver_evm__relevant_contracts') }}
|
||||
WHERE
|
||||
total_interaction_count >= 100
|
||||
|
||||
{% if is_incremental() %}
|
||||
EXCEPT
|
||||
SELECT
|
||||
contract_address
|
||||
FROM
|
||||
{{ this }}
|
||||
{% endif %}
|
||||
LIMIT
|
||||
50
|
||||
), row_nos AS (
|
||||
SELECT
|
||||
contract_address,
|
||||
ROW_NUMBER() over (
|
||||
ORDER BY
|
||||
contract_address
|
||||
) AS row_no
|
||||
FROM
|
||||
base
|
||||
),
|
||||
batched AS ({% for item in range(51) %}
|
||||
SELECT
|
||||
rn.contract_address, CONCAT('https://seitrace.com/pacific-1/api/v2/smart-contracts/', contract_address) AS url, IFNULL(live.udf_api(url) :data :abi, ARRAY_CONSTRUCT('ABI unavailable')) AS abi_data, SYSDATE() AS _inserted_timestamp
|
||||
FROM
|
||||
row_nos rn
|
||||
WHERE
|
||||
row_no = {{ item }}
|
||||
|
||||
{% if not loop.last %}
|
||||
UNION ALL
|
||||
{% endif %}
|
||||
{% endfor %})
|
||||
SELECT
|
||||
contract_address,
|
||||
abi_data,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
batched
|
||||
22
models/evm/bronze/api_udf/bronze_evm_api__contract_abis.yml
Normal file
22
models/evm/bronze/api_udf/bronze_evm_api__contract_abis.yml
Normal file
@ -0,0 +1,22 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: bronze_evm_api__contract_abis
|
||||
|
||||
columns:
|
||||
- name: _INSERTED_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: CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- VARCHAR
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: "^(0x)[0-9a-fA-F]{40}$"
|
||||
5
models/evm/descriptions/transfers/sei_eth_amount.md
Normal file
5
models/evm/descriptions/transfers/sei_eth_amount.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs sei_amount %}
|
||||
|
||||
sei value transferred.
|
||||
|
||||
{% enddocs %}
|
||||
6
models/evm/descriptions/transfers/sei_eth_amount_usd.md
Normal file
6
models/evm/descriptions/transfers/sei_eth_amount_usd.md
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
{% docs sei_eth_amount_usd %}
|
||||
|
||||
sei value transferred, in USD.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_ez_eth_transfers_table_doc %}
|
||||
|
||||
This table contains all native SEI transfers, including equivalent USD amounts. The origin addresses correspond to the to and from addresses from the `fact_transactions` table. The `identifier` and `tx_hash` columns relate this table back to `fact_traces`, which contains more details on the transfers.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_ez_transfer_table_doc %}
|
||||
|
||||
This table will contain all events in the ```fact_token_transfers table```, along with joined columns such as token price, symbol, and decimals where possible that allow for easier analysis of token transfer events. Please note Native SEI transfers are not included here.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_log_id_transfers %}
|
||||
|
||||
This is the primary key for this table. This is a concatenation of the transaction hash and the event index at which the transfer event occurred. This field can be used to find more details on the event within the ```fact_event_logs``` table.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/evm/descriptions/transfers/sei_origin_to.md
Normal file
5
models/evm/descriptions/transfers/sei_origin_to.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs sei_eth_origin_to %}
|
||||
|
||||
The to address at the transaction level.
|
||||
|
||||
{% enddocs %}
|
||||
11
models/evm/descriptions/transfers/sei_transfer_amount.md
Normal file
11
models/evm/descriptions/transfers/sei_transfer_amount.md
Normal file
@ -0,0 +1,11 @@
|
||||
{% docs sei_transfer_amount %}
|
||||
|
||||
The decimal transformed amount for this token. Tokens without a decimal adjustment will be nulled out here.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs sei_transfer_amount_precise %}
|
||||
|
||||
The decimal transformed amount for this token returned as a string to preserve precision. Tokens without a decimal adjustment will be nulled out here.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_amount_usd %}
|
||||
|
||||
The amount in US dollars for this transfer at the time of the transfer. Tokens without a decimal adjustment or price will be nulled out here.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_contract_address %}
|
||||
|
||||
Contract address of the token being transferred.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_from_address %}
|
||||
|
||||
The sending address of this transfer.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_has_decimal %}
|
||||
|
||||
Whether or not our contracts model contains the necessary decimal adjustment for this token.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_has_price %}
|
||||
|
||||
Whether or not our prices model contains this hourly token price.
|
||||
|
||||
{% enddocs %}
|
||||
11
models/evm/descriptions/transfers/sei_transfer_raw_amount.md
Normal file
11
models/evm/descriptions/transfers/sei_transfer_raw_amount.md
Normal file
@ -0,0 +1,11 @@
|
||||
{% docs sei_transfer_raw_amount %}
|
||||
|
||||
The amount of tokens transferred. This value is not decimal adjusted.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs sei_transfer_raw_amount_precise %}
|
||||
|
||||
The amount of tokens transferred returned as a string to preserve precision. This value is not decimal adjusted.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_table_doc %}
|
||||
|
||||
This table contains events on the Avalanche Blockchain with an event name of 'Transfer'. The contract address is the token transferred, and the raw amount field is the amount of tokens transferred. Please note this amount is not decimal adjusted. Decimal adjustments for a token address can be found in ```dim_contracts```. This table will not contain transfers of native ETH.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_to_address %}
|
||||
|
||||
The receiving address of this transfer. This can be a contract address.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_token_price %}
|
||||
|
||||
The price, if available, for this token at the transfer time.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,5 @@
|
||||
{% docs sei_transfer_tx_hash %}
|
||||
|
||||
Transaction hash is a unique 66-character identifier that is generated when a transaction is executed. This will not be unique in this table as a transaction could include multiple transfer events.
|
||||
|
||||
{% enddocs %}
|
||||
34
models/evm/gold/core/core_evm__dim_contracts.sql
Normal file
34
models/evm/gold/core/core_evm__dim_contracts.sql
Normal file
@ -0,0 +1,34 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
c0.created_contract_address AS address,
|
||||
c1.token_symbol AS symbol,
|
||||
c1.token_name AS NAME,
|
||||
c1.token_decimals AS decimals,
|
||||
c0.block_number AS created_block_number,
|
||||
c0.block_timestamp AS created_block_timestamp,
|
||||
c0.tx_hash AS created_tx_hash,
|
||||
c0.creator_address AS creator_address,
|
||||
c0.created_contracts_id AS dim_contracts_id,
|
||||
GREATEST(
|
||||
c0.inserted_timestamp,
|
||||
c1.inserted_timestamp
|
||||
) AS inserted_timestamp,
|
||||
GREATEST(
|
||||
c0.modified_timestamp,
|
||||
c1.modified_timestamp
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver_evm__created_contracts') }}
|
||||
c0
|
||||
LEFT JOIN {{ ref('silver_evm__contracts') }}
|
||||
c1
|
||||
ON LOWER(
|
||||
c0.created_contract_address
|
||||
) = LOWER(
|
||||
c1.contract_address
|
||||
)
|
||||
28
models/evm/gold/core/core_evm__dim_contracts.yml
Normal file
28
models/evm/gold/core/core_evm__dim_contracts.yml
Normal file
@ -0,0 +1,28 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: core_evm__dim_contracts
|
||||
description: This table contains all the contracts that are deployed on SEI EVM along with their on-chain metadata.
|
||||
|
||||
columns:
|
||||
- name: ADDRESS
|
||||
description: 'The address of the contract.'
|
||||
- name: SYMBOL
|
||||
description: 'The symbol of the contract.'
|
||||
- name: NAME
|
||||
description: 'The name of the contract.'
|
||||
- name: DECIMALS
|
||||
description: 'The number of decimals used to adjust amount for this contract.'
|
||||
- name: CREATED_BLOCK_NUMBER
|
||||
description: 'The block number when the contract was created'
|
||||
- name: CREATED_BLOCK_TIMESTAMP
|
||||
description: 'The block timestamp when the contract was created'
|
||||
- name: CREATED_TX_HASH
|
||||
description: 'The transaction hash when the contract was created'
|
||||
- name: CREATOR_ADDRESS
|
||||
description: 'The address of the creator of the contract'
|
||||
- name: DIM_CONTRACTS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
27
models/evm/gold/core/core_evm__ez_native_transfers.sql
Normal file
27
models/evm/gold/core/core_evm__ez_native_transfers.sql
Normal file
@ -0,0 +1,27 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_position,
|
||||
trace_index,
|
||||
identifier,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
from_address,
|
||||
to_address,
|
||||
amount,
|
||||
amount_precise_raw,
|
||||
amount_precise,
|
||||
amount_usd,
|
||||
native_transfers_id AS ez_native_transfers_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver_evm__native_transfers') }}
|
||||
42
models/evm/gold/core/core_evm__ez_native_transfers.yml
Normal file
42
models/evm/gold/core/core_evm__ez_native_transfers.yml
Normal file
@ -0,0 +1,42 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: core_evm__ez_native_transfers
|
||||
description: '{{ doc("sei_ez_eth_transfers_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("sei_transfer_tx_hash") }}'
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("sei_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("sei_block_timestamp") }}'
|
||||
- name: TX_POSITION
|
||||
description: '{{ doc("sei_tx_position") }}'
|
||||
- name: TRACE_INDEX
|
||||
description: '{{ doc("sei_trace_index") }}'
|
||||
- name: IDENTIFIER
|
||||
description: '{{ doc("sei_traces_identifier") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("sei_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("sei_origin_to") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("sei_origin_sig") }}'
|
||||
- name: FROM_ADDRESS
|
||||
description: '{{ doc("sei_transfer_from_address") }}'
|
||||
- name: TO_ADDRESS
|
||||
description: '{{ doc("sei_transfer_to_address") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("sei_amount") }}'
|
||||
- name: AMOUNT_PRECISE_RAW
|
||||
description: '{{ doc("precise_amount_unadjusted") }}'
|
||||
- name: AMOUNT_PRECISE
|
||||
description: '{{ doc("precise_amount_adjusted") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("sei_eth_amount_usd") }}'
|
||||
- name: EZ_NATIVE_TRANSFERS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
31
models/evm/gold/core/core_evm__ez_token_transfers.sql
Normal file
31
models/evm/gold/core/core_evm__ez_token_transfers.sql
Normal file
@ -0,0 +1,31 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
from_address,
|
||||
to_address,
|
||||
raw_amount_precise,
|
||||
raw_amount,
|
||||
amount_precise,
|
||||
amount,
|
||||
decimals,
|
||||
symbol,
|
||||
has_decimal,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
transfers_id AS ez_token_transfers_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver_evm__transfers') }}
|
||||
50
models/evm/gold/core/core_evm__ez_token_transfers.yml
Normal file
50
models/evm/gold/core/core_evm__ez_token_transfers.yml
Normal file
@ -0,0 +1,50 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: core_evm__ez_token_transfers
|
||||
description: '{{ doc("sei_transfer_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("sei_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("sei_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("sei_transfer_tx_hash") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("sei_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("sei_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("sei_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("sei_origin_to") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("sei_transfer_contract_address") }}'
|
||||
- name: FROM_ADDRESS
|
||||
description: '{{ doc("sei_transfer_from_address") }}'
|
||||
- name: TO_ADDRESS
|
||||
description: '{{ doc("sei_transfer_to_address") }}'
|
||||
- name: RAW_AMOUNT_PRECISE
|
||||
description: '{{ doc("sei_transfer_raw_amount_precise") }}'
|
||||
- name: RAW_AMOUNT
|
||||
description: '{{ doc("sei_transfer_raw_amount") }}'
|
||||
- name: AMOUNT_PRECISE
|
||||
description: '{{ doc("sei_transfer_amount_precise") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("sei_transfer_amount") }}'
|
||||
- name: DECIMALS
|
||||
description: '{{ doc("sei_decimals") }}'
|
||||
- name: SYMBOL
|
||||
description: '{{ doc("sei_symbol") }}'
|
||||
- name: HAS_DECIMAL
|
||||
description: '{{ doc("sei_transfer_has_decimal") }}'
|
||||
- name: _LOG_ID
|
||||
description: '{{ doc("internal_column") }}'
|
||||
- name: _INSERTED_TIMESTAMP
|
||||
description: '{{ doc("internal_column") }}'
|
||||
- name: EZ_TOKEN_TRANSFERS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
25
models/evm/gold/core/core_evm__fact_token_transfers.sql
Normal file
25
models/evm/gold/core/core_evm__fact_token_transfers.sql
Normal file
@ -0,0 +1,25 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
from_address,
|
||||
to_address,
|
||||
raw_amount,
|
||||
raw_amount_precise,
|
||||
_log_id,
|
||||
transfers_id AS fact_token_transfers_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver_evm__transfers') }}
|
||||
38
models/evm/gold/core/core_evm__fact_token_transfers.yml
Normal file
38
models/evm/gold/core/core_evm__fact_token_transfers.yml
Normal file
@ -0,0 +1,38 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: core_evm__fact_token_transfers
|
||||
description: '{{ doc("sei_transfer_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("sei_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("sei_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("sei_transfer_tx_hash") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("sei_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("sei_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("sei_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("sei_origin_to") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("sei_transfer_contract_address") }}'
|
||||
- name: FROM_ADDRESS
|
||||
description: '{{ doc("sei_transfer_from_address") }}'
|
||||
- name: TO_ADDRESS
|
||||
description: '{{ doc("sei_transfer_to_address") }}'
|
||||
- name: RAW_AMOUNT
|
||||
description: '{{ doc("sei_transfer_raw_amount") }}'
|
||||
- name: RAW_AMOUNT_PRECISE
|
||||
description: '{{ doc("sei_transfer_raw_amount_precise") }}'
|
||||
- name: _LOG_ID
|
||||
description: '{{ doc("internal_column") }}'
|
||||
- name: FACT_TOKEN_TRANSFERS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -2,7 +2,7 @@
|
||||
materialized = "incremental",
|
||||
unique_key = "created_contract_address",
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['recent_evm_test']
|
||||
tags = ['recent_evm_test','core']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
|
||||
109
models/evm/silver/core/silver_evm__native_transfers.sql
Normal file
109
models/evm/silver/core/silver_evm__native_transfers.sql
Normal file
@ -0,0 +1,109 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'block_number',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['core']
|
||||
) }}
|
||||
|
||||
WITH base AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
from_address,
|
||||
to_address,
|
||||
VALUE,
|
||||
identifier,
|
||||
_call_id,
|
||||
input,
|
||||
_INSERTED_TIMESTAMP,
|
||||
value_precise_raw,
|
||||
value_precise,
|
||||
tx_position,
|
||||
trace_index
|
||||
FROM
|
||||
{{ ref('silver_evm__traces') }}
|
||||
WHERE
|
||||
VALUE > 0
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND trace_status = 'SUCCESS'
|
||||
AND TYPE NOT IN (
|
||||
'DELEGATECALL',
|
||||
'STATICCALL'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
tx_table AS (
|
||||
SELECT
|
||||
block_number,
|
||||
tx_hash,
|
||||
from_address AS origin_from_address,
|
||||
to_address AS origin_to_address,
|
||||
origin_function_signature
|
||||
FROM
|
||||
{{ ref('silver_evm__transactions') }}
|
||||
WHERE
|
||||
tx_hash IN (
|
||||
SELECT
|
||||
DISTINCT tx_hash
|
||||
FROM
|
||||
base
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash AS tx_hash,
|
||||
block_number AS block_number,
|
||||
block_timestamp AS block_timestamp,
|
||||
identifier AS identifier,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
from_address,
|
||||
to_address,
|
||||
VALUE AS amount,
|
||||
value_precise_raw AS amount_precise_raw,
|
||||
value_precise AS amount_precise,
|
||||
ROUND(
|
||||
VALUE * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
_call_id,
|
||||
_inserted_timestamp,
|
||||
tx_position,
|
||||
trace_index,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'trace_index']
|
||||
) }} AS native_transfers_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
base A
|
||||
LEFT JOIN {{ ref('silver__complete_native_prices') }}
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = HOUR
|
||||
JOIN tx_table USING (
|
||||
tx_hash,
|
||||
block_number
|
||||
)
|
||||
109
models/evm/silver/core/silver_evm__transfers.sql
Normal file
109
models/evm/silver/core/silver_evm__transfers.sql
Normal file
@ -0,0 +1,109 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE', '_inserted_timestamp::DATE'],
|
||||
tags = ['core']
|
||||
) }}
|
||||
|
||||
WITH logs AS (
|
||||
|
||||
SELECT
|
||||
_log_id,
|
||||
block_number,
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address :: STRING AS contract_address,
|
||||
CONCAT('0x', SUBSTR(topics [1], 27, 40)) :: STRING AS from_address,
|
||||
CONCAT('0x', SUBSTR(topics [2], 27, 40)) :: STRING AS to_address,
|
||||
utils.udf_hex_to_int(SUBSTR(DATA, 3, 64)) AS raw_amount_precise,
|
||||
raw_amount_precise :: FLOAT AS raw_amount,
|
||||
event_index,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_evm__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
token_transfers AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
t.contract_address,
|
||||
from_address,
|
||||
to_address,
|
||||
raw_amount_precise,
|
||||
raw_amount,
|
||||
IFF(
|
||||
C.token_decimals IS NOT NULL,
|
||||
utils.udf_decimal_adjust(
|
||||
raw_amount_precise,
|
||||
C.token_decimals
|
||||
),
|
||||
NULL
|
||||
) AS amount_precise,
|
||||
amount_precise :: FLOAT AS amount,
|
||||
C.token_decimals AS decimals,
|
||||
C.token_symbol AS symbol,
|
||||
CASE
|
||||
WHEN C.token_decimals IS NULL THEN 'false'
|
||||
ELSE 'true'
|
||||
END AS has_decimal,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
logs t
|
||||
LEFT JOIN {{ ref('silver_evm__contracts') }} C USING (contract_address)
|
||||
WHERE
|
||||
raw_amount IS NOT NULL
|
||||
AND to_address IS NOT NULL
|
||||
AND from_address IS NOT NULL
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
from_address,
|
||||
to_address,
|
||||
raw_amount_precise,
|
||||
raw_amount,
|
||||
amount_precise,
|
||||
amount,
|
||||
decimals,
|
||||
symbol,
|
||||
has_decimal,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS transfers_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
token_transfers
|
||||
40
models/silver/price/silver__complete_native_prices.sql
Normal file
40
models/silver/price/silver__complete_native_prices.sql
Normal file
@ -0,0 +1,40 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'complete_native_prices_id',
|
||||
tags = ['core']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
HOUR,
|
||||
asset_id,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
price,
|
||||
blockchain,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
provider,
|
||||
source,
|
||||
_inserted_timestamp,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
complete_native_prices_id,
|
||||
_invocation_id
|
||||
FROM
|
||||
{{ ref(
|
||||
'bronze__complete_native_prices'
|
||||
) }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
modified_timestamp
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
37
models/silver/price/silver__complete_native_prices.yml
Normal file
37
models/silver/price/silver__complete_native_prices.yml
Normal file
@ -0,0 +1,37 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_native_prices
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- HOUR
|
||||
- SYMBOL
|
||||
|
||||
columns:
|
||||
- name: HOUR
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROVIDER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PRICE
|
||||
tests:
|
||||
- not_null
|
||||
- name: IS_IMPUTED
|
||||
tests:
|
||||
- not_null
|
||||
- name: _INSERTED_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPLETE_NATIVE_PRICES_ID
|
||||
tests:
|
||||
- unique
|
||||
@ -29,6 +29,8 @@ sources:
|
||||
- name: hourly_prices_coin_gecko
|
||||
- name: number_sequence
|
||||
- name: labels_combined
|
||||
- name: complete_native_asset_metadata
|
||||
- name: complete_native_prices
|
||||
- name: bronze_streamline
|
||||
database: streamline
|
||||
schema: |
|
||||
|
||||
Loading…
Reference in New Issue
Block a user