mirror of
https://github.com/FlipsideCrypto/polygon-models.git
synced 2026-02-06 16:56:44 +00:00
parent
f3cda8ad13
commit
3ee7dde2ff
@ -26,6 +26,7 @@ clean-targets: # directories to be removed by `dbt clean`
|
||||
|
||||
models:
|
||||
+copy_grants: true
|
||||
+on_schema_change: "append_new_columns"
|
||||
|
||||
tests:
|
||||
+store_failures: true # all tests
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
{% docs deprecation %}
|
||||
{% docs internal_column %}
|
||||
|
||||
Deprecating soon: Please migrate queries to `fact_decoded_event_logs`, `ez_decoded_event_logs` or use manual parsing of topics and data. The following columns will be deprecated on 4/3/23:
|
||||
Deprecated. This column is no longer used. Please remove from your query by Jan. 31 2024.
|
||||
|
||||
`Fact_event_logs` Columns:
|
||||
- `event_name`
|
||||
- `event_inputs`
|
||||
- `contract_name`
|
||||
|
||||
`Fact_transactions` Columns:
|
||||
- `tx_json`
|
||||
{% enddocs %}
|
||||
|
||||
{% docs amount_deprecation %}
|
||||
|
||||
This column is being deprecated for standardization purposes on Jan. 31 2024. Please use the equivalent column without the native asset prefix. For example, use `amount` instead of `matic_amount`.
|
||||
|
||||
{% enddocs %}
|
||||
17
models/doc_descriptions/general/export_columns.md
Normal file
17
models/doc_descriptions/general/export_columns.md
Normal file
@ -0,0 +1,17 @@
|
||||
{% docs pk %}
|
||||
|
||||
The unique identifier for each row in the table.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs inserted_timestamp %}
|
||||
|
||||
The utc timestamp at which the row was inserted into the table.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs modified_timestamp %}
|
||||
|
||||
The utc timestamp at which the row was last modified.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/doc_descriptions/nft/nft_intra_event_index.md
Normal file
5
models/doc_descriptions/nft/nft_intra_event_index.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs nft_intra_event_index %}
|
||||
|
||||
The order of events within a single event index. This is primarily used for ERC1155 NFT batch transfer events.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/doc_descriptions/traces/poly_traces_index.md
Normal file
5
models/doc_descriptions/traces/poly_traces_index.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs poly_trace_index %}
|
||||
|
||||
The index of the trace within the transaction.
|
||||
|
||||
{% enddocs %}
|
||||
@ -10,13 +10,27 @@ SELECT
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
intra_event_index,
|
||||
contract_address AS nft_address,
|
||||
project_name,
|
||||
from_address AS nft_from_address,
|
||||
to_address AS nft_to_address,
|
||||
tokenId,
|
||||
erc1155_value
|
||||
|
||||
erc1155_value,
|
||||
COALESCE (
|
||||
nft_transfers_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index','intra_event_index']
|
||||
) }}
|
||||
) AS ez_nft_mints_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__nft_transfers') }}
|
||||
WHERE
|
||||
|
||||
@ -24,3 +24,11 @@ models:
|
||||
description: 'The token ID of the NFT transfer.'
|
||||
- name: EVENT_INDEX
|
||||
description: 'The index of the NFT transfer within the transaction. This is used to ensure that multiple NFT transfers in a single transaction are not duplicated.'
|
||||
- name: INTRA_EVENT_INDEX
|
||||
description: '{{ doc("nft_intra_event_index") }}'
|
||||
- name: EZ_NFT_MINTS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -34,6 +34,20 @@ SELECT
|
||||
tx_fee_usd,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature
|
||||
origin_function_signature,
|
||||
COALESCE (
|
||||
complete_nft_sales_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index', 'nft_address','tokenId','platform_exchange_version']
|
||||
) }}
|
||||
) AS ez_nft_sales_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_nft_sales') }}
|
||||
|
||||
@ -10,6 +10,8 @@ models:
|
||||
description: '{{ doc("nft_blocktime") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("nft_tx_hash") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("nft_event_index") }}'
|
||||
- name: EVENT_TYPE
|
||||
description: '{{ doc("nft_event_type") }}'
|
||||
- name: PLATFORM_ADDRESS
|
||||
@ -64,3 +66,9 @@ models:
|
||||
description: '{{ doc("nft_origin_to") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: EZ_NFT_SALES_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -10,13 +10,28 @@ SELECT
|
||||
block_number,
|
||||
tx_hash,
|
||||
event_index,
|
||||
intra_event_index,
|
||||
event_type,
|
||||
contract_address AS nft_address,
|
||||
project_name,
|
||||
from_address AS nft_from_address,
|
||||
to_address AS nft_to_address,
|
||||
tokenId,
|
||||
erc1155_value
|
||||
erc1155_value,
|
||||
COALESCE (
|
||||
nft_transfers_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index','intra_event_index']
|
||||
) }}
|
||||
) AS ez_nft_transfers_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__nft_transfers') }}
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@ models:
|
||||
description: 'The block timestamp of the NFT transfer.'
|
||||
- name: TX_HASH
|
||||
description: 'The transaction hash of the NFT transfer. Please note this is not unique, as it is possible to have multiple NFT transfers in a single transaction.'
|
||||
- name: INTRA_EVENT_INDEX
|
||||
description: '{{ doc("nft_intra_event_index") }}'
|
||||
- name: EVENT_TYPE
|
||||
description: 'The type of NFT transfer. This can be either "mint" or "other".'
|
||||
- name: NFT_ADDRESS
|
||||
@ -26,3 +28,9 @@ models:
|
||||
description: 'The token ID of the NFT transfer.'
|
||||
- name: EVENT_INDEX
|
||||
description: 'The index of the NFT transfer within the transaction. This is used to ensure that multiple NFT transfers in a single transaction are not duplicated.'
|
||||
- name: EZ_NFT_TRANSFERS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -12,7 +12,15 @@ SELECT
|
||||
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.creator_address AS creator_address,
|
||||
COALESCE (
|
||||
c0.created_contracts_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['c0.created_contract_address']
|
||||
) }}
|
||||
) AS dim_contracts_id,
|
||||
GREATEST(COALESCE(c0.inserted_timestamp, '2000-01-01'), COALESCE(c1.inserted_timestamp, '2000-01-01')) AS inserted_timestamp,
|
||||
GREATEST(COALESCE(c0.modified_timestamp, '2000-01-01'), COALESCE(c1.modified_timestamp, '2000-01-01')) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__created_contracts') }}
|
||||
c0
|
||||
|
||||
@ -19,4 +19,10 @@ models:
|
||||
- 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'
|
||||
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") }}'
|
||||
@ -11,6 +11,20 @@ SELECT
|
||||
address_name,
|
||||
label_type,
|
||||
label_subtype,
|
||||
project_name
|
||||
project_name,
|
||||
COALESCE (
|
||||
labels_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['address']
|
||||
) }}
|
||||
) AS dim_labels_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__labels') }}
|
||||
|
||||
@ -52,4 +52,9 @@ models:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: DIM_LABELS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
|
||||
@ -20,7 +20,16 @@ SELECT
|
||||
topics,
|
||||
DATA,
|
||||
event_removed,
|
||||
tx_status
|
||||
tx_status,
|
||||
COALESCE (
|
||||
decoded_logs_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS ez_decoded_event_logs_id,
|
||||
GREATEST(COALESCE(l.inserted_timestamp, '2000-01-01'), COALESCE(C.inserted_timestamp, '2000-01-01')) AS inserted_timestamp,
|
||||
GREATEST(COALESCE(l.modified_timestamp, '2000-01-01'), COALESCE(C.modified_timestamp, '2000-01-01')) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__decoded_logs') }}
|
||||
LEFT JOIN {{ ref('silver__contracts') }} using (contract_address)
|
||||
l
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C USING (contract_address)
|
||||
|
||||
@ -56,4 +56,10 @@ models:
|
||||
- name: EVENT_REMOVED
|
||||
description: '{{ doc("poly_event_removed") }}'
|
||||
- name: TX_STATUS
|
||||
description: '{{ doc("poly_tx_status") }}'
|
||||
description: '{{ doc("poly_tx_status") }}'
|
||||
- name: EZ_DECODED_EVENT_LOGS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -1,106 +1,26 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'block_number',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
|
||||
tags = ['non_realtime','reorg'],
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true }
|
||||
) }}
|
||||
|
||||
WITH matic_base AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
identifier,
|
||||
from_address,
|
||||
to_address,
|
||||
matic_value,
|
||||
_call_id,
|
||||
_inserted_timestamp,
|
||||
matic_value_precise,
|
||||
matic_value_precise_raw,
|
||||
tx_position,
|
||||
trace_index
|
||||
FROM
|
||||
{{ ref('silver__traces') }}
|
||||
WHERE
|
||||
matic_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 '72 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__transactions') }}
|
||||
WHERE
|
||||
tx_hash IN (
|
||||
SELECT
|
||||
DISTINCT tx_hash
|
||||
FROM
|
||||
matic_base
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '72 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
A.tx_hash AS tx_hash,
|
||||
A.block_number AS block_number,
|
||||
A.block_timestamp AS block_timestamp,
|
||||
A.identifier AS identifier,
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
identifier,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.from_address AS matic_from_address,
|
||||
A.to_address AS matic_to_address,
|
||||
A.matic_value AS amount,
|
||||
A.matic_value_precise_raw AS amount_precise_raw,
|
||||
A.matic_value_precise AS amount_precise,
|
||||
ROUND(
|
||||
A.matic_value * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
from_address AS matic_from_address,
|
||||
to_address AS matic_to_address,
|
||||
amount,
|
||||
amount_precise_raw,
|
||||
amount_precise,
|
||||
amount_usd,
|
||||
_call_id,
|
||||
A._inserted_timestamp,
|
||||
_inserted_timestamp,
|
||||
tx_position,
|
||||
trace_index
|
||||
FROM
|
||||
matic_base A
|
||||
LEFT JOIN {{ ref('silver__hourly_prices_priority') }}
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = HOUR
|
||||
AND token_address = '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
|
||||
JOIN tx_table USING (
|
||||
tx_hash,
|
||||
block_number
|
||||
)
|
||||
{{ ref('silver__native_transfers') }}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: core__ez_matic_transfers
|
||||
description: '{{ doc("poly_ez_eth_transfers_table_doc") }}'
|
||||
description: 'Deprecating soon! Migrate to `core.ez_native_transfers` by Jan. 31 2024.'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
|
||||
38
models/gold/core/core__ez_native_transfers.sql
Normal file
38
models/gold/core/core__ez_native_transfers.sql
Normal file
@ -0,0 +1,38 @@
|
||||
{{ 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,
|
||||
COALESCE (
|
||||
native_transfers_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'trace_index']
|
||||
) }}
|
||||
) AS ez_native_transfers_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__native_transfers') }}
|
||||
42
models/gold/core/core__ez_native_transfers.yml
Normal file
42
models/gold/core/core__ez_native_transfers.yml
Normal file
@ -0,0 +1,42 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: core__ez_native_transfers
|
||||
description: '{{ doc("poly_ez_eth_transfers_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("poly_transfer_tx_hash") }}'
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("poly_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("poly_block_timestamp") }}'
|
||||
- name: TX_POSITION
|
||||
description: '{{ doc("poly_tx_position") }}'
|
||||
- name: TRACE_INDEX
|
||||
description: '{{ doc("poly_trace_index") }}'
|
||||
- name: IDENTIFIER
|
||||
description: '{{ doc("poly_traces_identifier") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("poly_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("poly_origin_to") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("poly_origin_sig") }}'
|
||||
- name: FROM_ADDRESS
|
||||
description: '{{ doc("poly_transfer_from_address") }}'
|
||||
- name: TO_ADDRESS
|
||||
description: '{{ doc("poly_transfer_to_address") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("poly_eth_amount") }}'
|
||||
- name: AMOUNT_PRECISE_RAW
|
||||
description: '{{ doc("precise_amount_unadjusted") }}'
|
||||
- name: AMOUNT_PRECISE
|
||||
description: '{{ doc("precise_amount_adjusted") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("poly_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") }}'
|
||||
@ -26,6 +26,20 @@ SELECT
|
||||
has_decimal,
|
||||
has_price,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
_inserted_timestamp,
|
||||
COALESCE (
|
||||
transfers_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS ez_token_transfers_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__transfers') }}
|
||||
|
||||
@ -47,4 +47,12 @@ models:
|
||||
- name: HAS_PRICE
|
||||
description: '{{ doc("poly_transfer_has_price") }}'
|
||||
- name: _LOG_ID
|
||||
description: '{{ doc("poly_log_id_transfers") }}'
|
||||
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") }}'
|
||||
@ -7,8 +7,8 @@
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
'mainnet' as network,
|
||||
'polygon' as blockchain,
|
||||
'mainnet' AS network,
|
||||
'polygon' AS blockchain,
|
||||
tx_count,
|
||||
difficulty,
|
||||
total_difficulty,
|
||||
@ -20,7 +20,7 @@ SELECT
|
||||
receipts_root,
|
||||
sha3_uncles,
|
||||
SIZE,
|
||||
uncles as uncle_blocks,
|
||||
uncles AS uncle_blocks,
|
||||
OBJECT_CONSTRUCT(
|
||||
'baseFeePerGas',
|
||||
base_fee_per_gas,
|
||||
@ -60,7 +60,34 @@ SELECT
|
||||
transactions_root,
|
||||
'uncles',
|
||||
uncles
|
||||
) AS block_header_json
|
||||
) AS block_header_json,
|
||||
COALESCE (
|
||||
blocks_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['a.block_number']
|
||||
) }}
|
||||
) AS fact_blocks_id,
|
||||
GREATEST(
|
||||
COALESCE(
|
||||
A.inserted_timestamp,
|
||||
'2000-01-01'
|
||||
),
|
||||
COALESCE(
|
||||
d.inserted_timestamp,
|
||||
'2000-01-01'
|
||||
)
|
||||
) AS inserted_timestamp,
|
||||
GREATEST(
|
||||
COALESCE(
|
||||
A.modified_timestamp,
|
||||
'2000-01-01'
|
||||
),
|
||||
COALESCE(
|
||||
d.modified_timestamp,
|
||||
'2000-01-01'
|
||||
)
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__blocks') }}
|
||||
LEFT JOIN {{ ref('silver__tx_count') }} USING (block_number)
|
||||
{{ ref('silver__blocks') }} A
|
||||
LEFT JOIN {{ ref('silver__tx_count') }}
|
||||
d USING (block_number)
|
||||
|
||||
@ -37,4 +37,10 @@ models:
|
||||
- name: UNCLE_BLOCKS
|
||||
description: '{{ doc("poly_uncle_blocks") }}'
|
||||
- name: BLOCK_HEADER_JSON
|
||||
description: '{{ doc("poly_block_header_json") }}'
|
||||
description: '{{ doc("poly_block_header_json") }}'
|
||||
- name: FACT_BLOCKS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -12,6 +12,20 @@ SELECT
|
||||
contract_address,
|
||||
event_name,
|
||||
decoded_flat AS decoded_log,
|
||||
decoded_data AS full_decoded_log
|
||||
decoded_data AS full_decoded_log,
|
||||
COALESCE (
|
||||
decoded_logs_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS fact_decoded_event_logs_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__decoded_logs') }}
|
||||
|
||||
@ -42,3 +42,9 @@ models:
|
||||
description: 'The flattened decoded log, where the keys are the names of the event parameters, and the values are the values of the event parameters.'
|
||||
- name: FULL_DECODED_LOG
|
||||
description: 'The full decoded log, including the event name, the event parameters, and the data type of the event parameters.'
|
||||
- name: FACT_DECODED_EVENT_LOGS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -17,6 +17,20 @@ SELECT
|
||||
DATA,
|
||||
event_removed,
|
||||
tx_status,
|
||||
_log_id
|
||||
_log_id,
|
||||
COALESCE (
|
||||
logs_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS fact_event_logs_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
|
||||
@ -21,7 +21,7 @@ models:
|
||||
- name: EVENT_REMOVED
|
||||
description: '{{ doc("poly_event_removed") }}'
|
||||
- name: _LOG_ID
|
||||
description: '{{ doc("poly_log_id_events") }}'
|
||||
description: '{{ doc("internal_column") }}'
|
||||
- name: TX_STATUS
|
||||
description: '{{ doc("poly_tx_status") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
@ -30,3 +30,9 @@ models:
|
||||
description: '{{ doc("poly_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("poly_origin_to") }}'
|
||||
- name: FACT_EVENT_LOGS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -17,6 +17,20 @@ SELECT
|
||||
to_address,
|
||||
raw_amount,
|
||||
raw_amount_precise,
|
||||
_log_id
|
||||
_log_id,
|
||||
COALESCE (
|
||||
transfers_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }}
|
||||
) AS fact_token_transfers_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__transfers') }}
|
||||
|
||||
@ -29,4 +29,10 @@ models:
|
||||
- name: RAW_AMOUNT_PRECISE
|
||||
description: '{{ doc("poly_transfer_raw_amount_precise") }}'
|
||||
- name: _LOG_ID
|
||||
description: '{{ doc("poly_log_id_transfers") }}'
|
||||
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") }}'
|
||||
@ -10,9 +10,9 @@ SELECT
|
||||
block_timestamp,
|
||||
from_address,
|
||||
to_address,
|
||||
matic_value,
|
||||
matic_value_precise_raw,
|
||||
matic_value_precise,
|
||||
matic_value AS VALUE,
|
||||
matic_value_precise_raw AS value_precise_raw,
|
||||
matic_value_precise AS value_precise,
|
||||
gas,
|
||||
gas_used,
|
||||
input,
|
||||
@ -24,6 +24,23 @@ SELECT
|
||||
sub_traces,
|
||||
trace_status,
|
||||
error_reason,
|
||||
trace_index
|
||||
trace_index,
|
||||
COALESCE (
|
||||
traces_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'trace_index']
|
||||
) }}
|
||||
) AS fact_traces_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp,
|
||||
matic_value,
|
||||
matic_value_precise_raw,
|
||||
matic_value_precise
|
||||
FROM
|
||||
{{ ref('silver__traces') }}
|
||||
|
||||
@ -15,10 +15,16 @@ models:
|
||||
- name: TO_ADDRESS
|
||||
description: '{{ doc("poly_traces_to") }}'
|
||||
- name: MATIC_VALUE
|
||||
description: '{{ doc("poly_traces_value") }}'
|
||||
description: '{{ doc("amount_deprecation") }}'
|
||||
- name: MATIC_VALUE_PRECISE_RAW
|
||||
description: '{{ doc("precise_amount_unadjusted") }}'
|
||||
description: '{{ doc("amount_deprecation") }}'
|
||||
- name: MATIC_VALUE_PRECISE
|
||||
description: '{{ doc("amount_deprecation") }}'
|
||||
- name: VALUE
|
||||
description: '{{ doc("poly_traces_value") }}'
|
||||
- name: VALUE_PRECISE_RAW
|
||||
description: '{{ doc("precise_amount_unadjusted") }}'
|
||||
- name: VALUE_PRECISE
|
||||
description: '{{ doc("precise_amount_adjusted") }}'
|
||||
- name: GAS
|
||||
description: '{{ doc("poly_traces_gas") }}'
|
||||
@ -44,7 +50,9 @@ models:
|
||||
description: The reason for the trace failure, if any.
|
||||
- name: TRACE_INDEX
|
||||
description: The index of the trace within the transaction.
|
||||
|
||||
|
||||
|
||||
|
||||
- name: FACT_TRACES_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -14,8 +14,11 @@ SELECT
|
||||
origin_function_signature,
|
||||
from_address,
|
||||
to_address,
|
||||
VALUE AS matic_value,
|
||||
VALUE,
|
||||
value_precise_raw,
|
||||
value_precise,
|
||||
tx_fee,
|
||||
tx_fee_precise,
|
||||
gas_price,
|
||||
gas AS gas_limit,
|
||||
gas_used,
|
||||
@ -29,6 +32,23 @@ SELECT
|
||||
s,
|
||||
v,
|
||||
tx_type,
|
||||
chain_id
|
||||
chain_id,
|
||||
COALESCE (
|
||||
transactions_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash']
|
||||
) }}
|
||||
) AS fact_transactions_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp,
|
||||
VALUE AS matic_value,
|
||||
value_precise_raw AS matic_value_precise_raw,
|
||||
value_precise AS matic_value_precise
|
||||
FROM
|
||||
{{ ref('silver__transactions') }}
|
||||
|
||||
@ -21,9 +21,21 @@ models:
|
||||
- name: TO_ADDRESS
|
||||
description: '{{ doc("poly_to_address") }}'
|
||||
- name: MATIC_VALUE
|
||||
description: '{{ doc("amount_deprecation") }}'
|
||||
- name: MATIC_VALUE_PRECISE_RAW
|
||||
description: '{{ doc("amount_deprecation") }}'
|
||||
- name: MATIC_VALUE_PRECISE
|
||||
description: '{{ doc("amount_deprecation") }}'
|
||||
- name: VALUE
|
||||
description: '{{ doc("poly_value") }}'
|
||||
- name: VALUE_PRECISE_RAW
|
||||
description: '{{ doc("precise_amount_unadjusted") }}'
|
||||
- name: VALUE_PRECISE
|
||||
description: '{{ doc("precise_amount_adjusted") }}'
|
||||
- name: TX_FEE
|
||||
description: '{{ doc("poly_tx_fee") }}'
|
||||
description: '{{ doc("poly_tx_fee") }}'
|
||||
- name: TX_FEE_PRECISE
|
||||
description: '{{ doc("tx_fee_precise") }}'
|
||||
- name: GAS_PRICE
|
||||
description: '{{ doc("poly_tx_gas_price") }}'
|
||||
- name: GAS_LIMIT
|
||||
@ -53,4 +65,10 @@ models:
|
||||
- name: s
|
||||
description: The s value of the transaction signature.
|
||||
- name: v
|
||||
description: The v value of the transaction signature.
|
||||
description: The v value of the transaction signature.
|
||||
- name: FACT_TRANSACTIONS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -22,6 +22,20 @@ SELECT
|
||||
pool_name,
|
||||
tokens,
|
||||
symbols,
|
||||
decimals
|
||||
decimals,
|
||||
COALESCE (
|
||||
complete_dex_liquidity_pools_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['block_number','platform','version']
|
||||
) }}
|
||||
) AS dim_dex_liquidity_pools_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__complete_dex_liquidity_pools') }}
|
||||
@ -23,4 +23,10 @@ models:
|
||||
- name: SYMBOLS
|
||||
description: '{{ doc("eth_dex_lp_symbols") }}'
|
||||
- name: DECIMALS
|
||||
description: '{{ doc("eth_dex_lp_decimals") }}'
|
||||
description: '{{ doc("eth_dex_lp_decimals") }}'
|
||||
- name: DIM_DEX_LIQUIDITY_POOLS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -36,5 +36,19 @@ SELECT
|
||||
token_out,
|
||||
symbol_in,
|
||||
symbol_out,
|
||||
_log_id
|
||||
_log_id,
|
||||
COALESCE (
|
||||
complete_dex_swaps_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }}
|
||||
) AS ez_dex_swaps_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM {{ ref('silver_dex__complete_dex_swaps') }}
|
||||
@ -39,7 +39,7 @@ models:
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("poly_event_index") }}'
|
||||
- name: _LOG_ID
|
||||
description: '{{ doc("poly_log_id_events") }}'
|
||||
description: '{{ doc("internal_column") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("poly_tx_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
@ -50,5 +50,10 @@ models:
|
||||
description: '{{ doc("eth_dex_swaps_amount_in_unadj") }}'
|
||||
- name: AMOUNT_OUT_UNADJ
|
||||
description: '{{ doc("eth_dex_swaps_amount_out_unadj") }}'
|
||||
|
||||
- name: EZ_DEX_SWAPS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
|
||||
|
||||
@ -10,6 +10,20 @@ SELECT
|
||||
symbol,
|
||||
NAME,
|
||||
decimals,
|
||||
provider
|
||||
provider,
|
||||
COALESCE (
|
||||
asset_metadata_all_providers_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['token_address','symbol','id','provider']
|
||||
) }}
|
||||
) AS dim_asset_metadata_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__asset_metadata_all_providers') }}
|
||||
{{ ref('silver__asset_metadata_all_providers') }}
|
||||
|
||||
@ -23,3 +23,9 @@ models:
|
||||
description: The specific address representing the asset in a specific platform.
|
||||
- name: DECIMALS
|
||||
description: The number of decimal places the token needs adjusted where token values exist.
|
||||
- name: DIM_ASSET_METADATA_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -9,6 +9,20 @@ SELECT
|
||||
id,
|
||||
symbol,
|
||||
NAME,
|
||||
decimals
|
||||
decimals,
|
||||
COALESCE (
|
||||
asset_metadata_priority_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['token_address']
|
||||
) }}
|
||||
) AS ez_asset_metadata_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__asset_metadata_priority') }}
|
||||
{{ ref('silver__asset_metadata_priority') }}
|
||||
|
||||
@ -18,3 +18,9 @@ models:
|
||||
description: The specific address representing the asset in a specific platform.
|
||||
- name: DECIMALS
|
||||
description: The number of decimal places the token needs adjusted where token values exist.
|
||||
- name: EZ_ASSET_METADATA_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -10,6 +10,20 @@ SELECT
|
||||
symbol,
|
||||
decimals,
|
||||
price,
|
||||
is_imputed
|
||||
is_imputed,
|
||||
COALESCE (
|
||||
hourly_prices_priority_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['token_address', 'hour']
|
||||
) }}
|
||||
) AS ez_hourly_token_prices_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__hourly_prices_priority') }}
|
||||
|
||||
@ -20,4 +20,10 @@ models:
|
||||
- name: PRICE
|
||||
description: Closing price of the recorded hour in USD
|
||||
- name: IS_IMPUTED
|
||||
description: Whether the price was imputed from an earlier record (generally used for low trade volume tokens)
|
||||
description: Whether the price was imputed from an earlier record (generally used for low trade volume tokens)
|
||||
- name: EZ_HOURLY_TOKEN_PRICES_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -9,6 +9,20 @@ SELECT
|
||||
token_address,
|
||||
price,
|
||||
is_imputed,
|
||||
provider
|
||||
provider,
|
||||
COALESCE (
|
||||
hourly_prices_all_providers_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['token_address', 'hour', 'provider']
|
||||
) }}
|
||||
) AS fact_hourly_token_prices_id,
|
||||
COALESCE(
|
||||
inserted_timestamp,
|
||||
'2000-01-01'
|
||||
) AS inserted_timestamp,
|
||||
COALESCE(
|
||||
modified_timestamp,
|
||||
'2000-01-01'
|
||||
) AS modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__hourly_prices_all_providers') }}
|
||||
|
||||
@ -13,4 +13,10 @@ models:
|
||||
- name: PRICE
|
||||
description: Closing price of the recorded hour in USD
|
||||
- name: IS_IMPUTED
|
||||
description: Whether the price was imputed from an earlier record (generally used for low trade volume tokens)
|
||||
description: Whether the price was imputed from an earlier record (generally used for low trade volume tokens)
|
||||
- name: FACT_HOURLY_TOKEN_PRICES_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
@ -12,6 +12,7 @@ WITH nft_base_models AS (
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_type,
|
||||
platform_address,
|
||||
platform_name,
|
||||
@ -53,6 +54,7 @@ SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_type,
|
||||
platform_address,
|
||||
platform_name,
|
||||
@ -94,6 +96,7 @@ SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_type,
|
||||
platform_address,
|
||||
platform_name,
|
||||
@ -189,6 +192,7 @@ final_base AS (
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_type,
|
||||
platform_address,
|
||||
CASE
|
||||
@ -352,6 +356,7 @@ label_fill_sales AS (
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_type,
|
||||
platform_address,
|
||||
platform_name,
|
||||
@ -399,6 +404,30 @@ label_fill_sales AS (
|
||||
WHERE
|
||||
t.project_name IS NULL
|
||||
AND C.token_name IS NOT NULL
|
||||
),
|
||||
blocks_fill AS (
|
||||
SELECT
|
||||
* exclude (
|
||||
complete_nft_sales_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_invocation_id
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
WHERE
|
||||
block_number IN (
|
||||
SELECT
|
||||
block_number
|
||||
FROM
|
||||
label_fill_sales
|
||||
)
|
||||
AND nft_log_id NOT IN (
|
||||
SELECT
|
||||
nft_log_id
|
||||
FROM
|
||||
label_fill_sales
|
||||
)
|
||||
)
|
||||
{% endif %},
|
||||
final_joins AS (
|
||||
@ -408,17 +437,23 @@ final_joins AS (
|
||||
final_base
|
||||
|
||||
{% if is_incremental() %}
|
||||
UNION
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
label_fill_sales
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
blocks_fill
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_type,
|
||||
platform_address,
|
||||
platform_name,
|
||||
@ -454,7 +489,13 @@ SELECT
|
||||
nft_log_id,
|
||||
input_data,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index', 'nft_address','tokenId','platform_exchange_version']
|
||||
) }} AS complete_nft_sales_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
final_joins qualify(ROW_NUMBER() over(PARTITION BY nft_log_id
|
||||
ORDER BY
|
||||
|
||||
@ -28,6 +28,9 @@ models:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -39,9 +39,9 @@ WITH base AS (
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND TO_TIMESTAMP_NTZ(_inserted_timestamp) >= (
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -354,7 +354,12 @@ fill_transfers AS (
|
||||
),
|
||||
blocks_fill AS (
|
||||
SELECT
|
||||
*
|
||||
* exclude (
|
||||
nft_transfers_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_invocation_id
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
WHERE
|
||||
@ -448,7 +453,13 @@ SELECT
|
||||
event_type,
|
||||
token_transfer_type,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index','intra_event_index']
|
||||
) }} AS nft_transfers_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
final_base qualify ROW_NUMBER() over (
|
||||
PARTITION BY _log_id
|
||||
|
||||
@ -3,7 +3,9 @@
|
||||
materialized = 'incremental',
|
||||
unique_key = "block_number",
|
||||
cluster_by = "block_timestamp::date",
|
||||
tags = ['non_realtime']
|
||||
tags = ['non_realtime'],
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
full_refresh = false
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
@ -45,7 +47,13 @@ SELECT
|
||||
) :: INT AS total_difficulty,
|
||||
DATA :transactionsRoot :: STRING AS transactions_root,
|
||||
DATA :uncles AS uncles,
|
||||
_inserted_timestamp -- need a txs column and block_header_json column(do we though?)
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['block_number']
|
||||
) }} AS blocks_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
|
||||
{% if is_incremental() %}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = 'contract_address',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
@ -89,7 +90,13 @@ token_names AS (
|
||||
token_name,
|
||||
TRY_TO_NUMBER(token_decimals) AS token_decimals,
|
||||
token_symbol,
|
||||
_inserted_timestamp
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['c1.contract_address']
|
||||
) }} AS contracts_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
contracts c1
|
||||
LEFT JOIN token_names
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config (
|
||||
materialized = "incremental",
|
||||
unique_key = "created_contract_address",
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
@ -11,7 +12,13 @@ SELECT
|
||||
to_address AS created_contract_address,
|
||||
from_address AS creator_address,
|
||||
input AS created_contract_input,
|
||||
_inserted_timestamp
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['to_address']
|
||||
) }} AS created_contracts_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('silver__traces') }}
|
||||
WHERE
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
tags = ['decoded_logs','reorg']
|
||||
) }}
|
||||
|
||||
|
||||
WITH base_data AS (
|
||||
|
||||
SELECT
|
||||
@ -199,7 +198,7 @@ SELECT
|
||||
tx_status,
|
||||
is_pending,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS decoded_logs_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
@ -230,7 +229,7 @@ SELECT
|
||||
tx_status,
|
||||
is_pending,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS decoded_logs_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
|
||||
@ -176,7 +176,13 @@ FROM
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS logs_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over (PARTITION BY block_number, event_index
|
||||
ORDER BY
|
||||
|
||||
110
models/silver/core/silver__native_transfers.sql
Normal file
110
models/silver/core/silver__native_transfers.sql
Normal file
@ -0,0 +1,110 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'block_number',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
|
||||
tags = ['core','non_realtime','reorg']
|
||||
) }}
|
||||
|
||||
WITH matic_base AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
identifier,
|
||||
from_address,
|
||||
to_address,
|
||||
matic_value,
|
||||
_call_id,
|
||||
_inserted_timestamp,
|
||||
matic_value_precise_raw,
|
||||
matic_value_precise,
|
||||
tx_position,
|
||||
trace_index
|
||||
FROM
|
||||
{{ ref('silver__traces') }}
|
||||
WHERE
|
||||
matic_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 '72 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__transactions') }}
|
||||
WHERE
|
||||
tx_hash IN (
|
||||
SELECT
|
||||
DISTINCT tx_hash
|
||||
FROM
|
||||
matic_base
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '72 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,
|
||||
matic_value AS amount,
|
||||
matic_value_precise_raw AS amount_precise_raw,
|
||||
matic_value_precise AS amount_precise,
|
||||
ROUND(
|
||||
matic_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
|
||||
matic_base A
|
||||
LEFT JOIN {{ ref('silver__hourly_prices_priority') }}
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = HOUR
|
||||
AND token_address = '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
|
||||
JOIN tx_table USING (
|
||||
tx_hash,
|
||||
block_number
|
||||
)
|
||||
@ -405,7 +405,13 @@ SELECT
|
||||
is_pending,
|
||||
_call_id,
|
||||
_inserted_timestamp,
|
||||
matic_value_precise_raw
|
||||
matic_value_precise_raw,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'trace_index']
|
||||
) }} AS traces_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY block_number, tx_position, trace_index
|
||||
ORDER BY
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
unique_key = "block_number",
|
||||
cluster_by = "block_timestamp::date, _inserted_timestamp::date",
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
|
||||
full_refresh = false,
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
@ -89,11 +88,14 @@ base_tx AS (
|
||||
A.data :v :: STRING AS v,
|
||||
utils.udf_hex_to_int(
|
||||
A.data :value :: STRING
|
||||
) / pow(
|
||||
10,
|
||||
) AS value_precise_raw,
|
||||
utils.udf_decimal_adjust(
|
||||
value_precise_raw,
|
||||
18
|
||||
) :: FLOAT AS VALUE,
|
||||
A._INSERTED_TIMESTAMP
|
||||
) AS value_precise,
|
||||
value_precise :: FLOAT AS VALUE,
|
||||
A._INSERTED_TIMESTAMP,
|
||||
A.data
|
||||
FROM
|
||||
base A
|
||||
),
|
||||
@ -117,6 +119,8 @@ new_records AS (
|
||||
t.position,
|
||||
t.type,
|
||||
t.v,
|
||||
t.value_precise_raw,
|
||||
t.value_precise,
|
||||
t.value,
|
||||
block_timestamp,
|
||||
CASE
|
||||
@ -129,14 +133,19 @@ new_records AS (
|
||||
tx_status,
|
||||
cumulative_gas_used,
|
||||
effective_gas_price,
|
||||
(
|
||||
gas_price * r.gas_used
|
||||
) / pow(
|
||||
10,
|
||||
9
|
||||
utils.udf_decimal_adjust(
|
||||
utils.udf_hex_to_int(
|
||||
t.data :gasPrice :: STRING
|
||||
) :: bigint * r.gas_used,
|
||||
18
|
||||
) AS tx_fee_precise,
|
||||
COALESCE(
|
||||
tx_fee_precise :: FLOAT,
|
||||
0
|
||||
) AS tx_fee,
|
||||
r.type AS tx_type,
|
||||
t._inserted_timestamp
|
||||
t._inserted_timestamp,
|
||||
t.data
|
||||
FROM
|
||||
base_tx t
|
||||
LEFT OUTER JOIN {{ ref('silver__blocks') }}
|
||||
@ -178,6 +187,8 @@ missing_data AS (
|
||||
t.position,
|
||||
t.type,
|
||||
t.v,
|
||||
t.value_precise_raw,
|
||||
t.value_precise,
|
||||
t.value,
|
||||
b.block_timestamp,
|
||||
FALSE AS is_pending,
|
||||
@ -186,18 +197,23 @@ missing_data AS (
|
||||
r.tx_status,
|
||||
r.cumulative_gas_used,
|
||||
r.effective_gas_price,
|
||||
(
|
||||
t.gas_price * r.gas_used
|
||||
) / pow(
|
||||
10,
|
||||
9
|
||||
utils.udf_decimal_adjust(
|
||||
utils.udf_hex_to_int(
|
||||
t.data :gasPrice :: STRING
|
||||
) :: bigint * r.gas_used,
|
||||
18
|
||||
) AS tx_fee_precise_heal,
|
||||
COALESCE(
|
||||
tx_fee_precise_heal :: FLOAT,
|
||||
0
|
||||
) AS tx_fee,
|
||||
r.type AS tx_type,
|
||||
GREATEST(
|
||||
t._inserted_timestamp,
|
||||
b._inserted_timestamp,
|
||||
r._inserted_timestamp
|
||||
) AS _inserted_timestamp
|
||||
) AS _inserted_timestamp,
|
||||
t.data
|
||||
FROM
|
||||
{{ this }}
|
||||
t
|
||||
@ -233,6 +249,8 @@ FINAL AS (
|
||||
TYPE,
|
||||
v,
|
||||
VALUE,
|
||||
value_precise_raw,
|
||||
value_precise,
|
||||
block_timestamp,
|
||||
is_pending,
|
||||
gas_used,
|
||||
@ -241,8 +259,10 @@ FINAL AS (
|
||||
cumulative_gas_used,
|
||||
effective_gas_price,
|
||||
tx_fee,
|
||||
tx_fee_precise,
|
||||
tx_type,
|
||||
_inserted_timestamp
|
||||
_inserted_timestamp,
|
||||
DATA
|
||||
FROM
|
||||
new_records
|
||||
|
||||
@ -268,6 +288,8 @@ SELECT
|
||||
TYPE,
|
||||
v,
|
||||
VALUE,
|
||||
value_precise_raw,
|
||||
value_precise,
|
||||
block_timestamp,
|
||||
is_pending,
|
||||
gas_used,
|
||||
@ -276,14 +298,22 @@ SELECT
|
||||
cumulative_gas_used,
|
||||
effective_gas_price,
|
||||
tx_fee,
|
||||
tx_fee_precise_heal AS tx_fee_precise,
|
||||
tx_type,
|
||||
_inserted_timestamp
|
||||
_inserted_timestamp,
|
||||
DATA
|
||||
FROM
|
||||
missing_data
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash']
|
||||
) }} AS transactions_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL
|
||||
WHERE
|
||||
|
||||
@ -239,7 +239,13 @@ heal_model AS (
|
||||
has_decimal,
|
||||
has_price,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
_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
|
||||
|
||||
@ -269,7 +275,13 @@ SELECT
|
||||
has_decimal,
|
||||
has_price,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
_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
|
||||
heal_model
|
||||
{% endif %}
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "block_number",
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
MIN(_inserted_timestamp) AS _inserted_timestamp,
|
||||
COUNT(*) AS tx_count
|
||||
FROM
|
||||
{{ ref('silver__transactions') }}
|
||||
WITH base AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
MIN(_inserted_timestamp) AS _inserted_timestamp,
|
||||
COUNT(*) AS tx_count
|
||||
FROM
|
||||
{{ ref('silver__transactions') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
@ -22,3 +25,14 @@ WHERE
|
||||
{% endif %}
|
||||
GROUP BY
|
||||
block_number
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['block_number']
|
||||
) }} AS tx_count_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
base
|
||||
|
||||
@ -16,10 +16,8 @@ WITH contracts AS (
|
||||
FROM
|
||||
{{ ref('silver__contracts') }}
|
||||
),
|
||||
|
||||
balancer AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -38,8 +36,9 @@ SELECT
|
||||
token5,
|
||||
token6,
|
||||
token7
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__balancer_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -50,10 +49,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
curve AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -64,16 +61,49 @@ SELECT
|
||||
'v1' AS version,
|
||||
_call_id AS _id,
|
||||
_inserted_timestamp,
|
||||
MAX(CASE WHEN token_num = 1 THEN token_address END) AS token0,
|
||||
MAX(CASE WHEN token_num = 2 THEN token_address END) AS token1,
|
||||
MAX(CASE WHEN token_num = 3 THEN token_address END) AS token2,
|
||||
MAX(CASE WHEN token_num = 4 THEN token_address END) AS token3,
|
||||
MAX(CASE WHEN token_num = 5 THEN token_address END) AS token4,
|
||||
MAX(CASE WHEN token_num = 6 THEN token_address END) AS token5,
|
||||
MAX(CASE WHEN token_num = 7 THEN token_address END) AS token6,
|
||||
MAX(CASE WHEN token_num = 8 THEN token_address END) AS token7
|
||||
FROM
|
||||
MAX(
|
||||
CASE
|
||||
WHEN token_num = 1 THEN token_address
|
||||
END
|
||||
) AS token0,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN token_num = 2 THEN token_address
|
||||
END
|
||||
) AS token1,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN token_num = 3 THEN token_address
|
||||
END
|
||||
) AS token2,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN token_num = 4 THEN token_address
|
||||
END
|
||||
) AS token3,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN token_num = 5 THEN token_address
|
||||
END
|
||||
) AS token4,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN token_num = 6 THEN token_address
|
||||
END
|
||||
) AS token5,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN token_num = 7 THEN token_address
|
||||
END
|
||||
) AS token6,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN token_num = 8 THEN token_address
|
||||
END
|
||||
) AS token7
|
||||
FROM
|
||||
{{ ref('silver_dex__curve_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -83,12 +113,11 @@ WHERE
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
GROUP BY all
|
||||
GROUP BY
|
||||
ALL
|
||||
),
|
||||
|
||||
dodo_v1 AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -101,8 +130,9 @@ SELECT
|
||||
'v1' AS version,
|
||||
_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__dodo_v1_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -113,10 +143,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
dodo_v2 AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -129,23 +157,22 @@ SELECT
|
||||
'v2' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__dodo_v2_pools') }}
|
||||
WHERE token0 IS NOT NULL
|
||||
WHERE
|
||||
token0 IS NOT NULL
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
frax AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -158,8 +185,9 @@ SELECT
|
||||
'v1' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__fraxswap_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -170,10 +198,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
kyberswap_v1_dynamic AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -186,8 +212,9 @@ SELECT
|
||||
'v1-dynamic' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__kyberswap_v1_dynamic_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -198,10 +225,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
kyberswap_v1_static AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -214,8 +239,9 @@ SELECT
|
||||
'v1-static' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__kyberswap_v1_static_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -226,10 +252,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
kyberswap_v2_elastic AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -243,8 +267,9 @@ SELECT
|
||||
'v2' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__kyberswap_v2_elastic_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -255,10 +280,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
quickswap_v2 AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -271,8 +294,9 @@ SELECT
|
||||
'v2' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__quickswap_v2_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -283,10 +307,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
quickswap_v3 AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -299,8 +321,9 @@ SELECT
|
||||
'v3' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__quickswap_v3_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -311,10 +334,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
sushi AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -327,8 +348,9 @@ SELECT
|
||||
'v1' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__sushi_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -339,10 +361,8 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
uni_v3 AS (
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
created_block AS block_number,
|
||||
created_time AS block_timestamp,
|
||||
created_tx_hash AS tx_hash,
|
||||
@ -356,8 +376,9 @@ SELECT
|
||||
'v3' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
FROM
|
||||
{{ ref('silver_dex__univ3_pools') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
@ -368,161 +389,335 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
all_pools_standard AS (
|
||||
SELECT *
|
||||
FROM dodo_v1
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM dodo_v2
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM frax
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM kyberswap_v1_dynamic
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM kyberswap_v1_static
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM quickswap_v2
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM quickswap_v3
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM sushi
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
dodo_v1
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
dodo_v2
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
frax
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
kyberswap_v1_dynamic
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
kyberswap_v1_static
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
quickswap_v2
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
quickswap_v3
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sushi
|
||||
),
|
||||
|
||||
all_pools_v3 AS (
|
||||
SELECT *
|
||||
FROM uni_v3
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM kyberswap_v2_elastic
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
uni_v3
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
kyberswap_v2_elastic
|
||||
),
|
||||
|
||||
all_pools_other AS (
|
||||
SELECT *
|
||||
FROM balancer
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM curve
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
balancer
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
curve
|
||||
),
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
CASE
|
||||
WHEN pool_name IS NULL
|
||||
THEN CONCAT(
|
||||
COALESCE(c0.symbol,CONCAT(SUBSTRING(token0, 1, 5),'...',SUBSTRING(token0, 39, 42))),
|
||||
'-',
|
||||
COALESCE(c1.symbol,CONCAT(SUBSTRING(token1, 1, 5),'...',SUBSTRING(token1, 39, 42)))
|
||||
)
|
||||
ELSE pool_name
|
||||
END AS pool_name,
|
||||
OBJECT_CONSTRUCT('token0',token0,'token1',token1) AS tokens,
|
||||
OBJECT_CONSTRUCT('token0',c0.symbol,'token1',c1.symbol) AS symbols,
|
||||
OBJECT_CONSTRUCT('token0',c0.decimals,'token1',c1.decimals) AS decimals,
|
||||
platform,
|
||||
version,
|
||||
_id,
|
||||
p._inserted_timestamp
|
||||
FROM all_pools_standard p
|
||||
LEFT JOIN contracts c0
|
||||
ON c0.address = p.token0
|
||||
LEFT JOIN contracts c1
|
||||
ON c1.address = p.token1
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
CASE
|
||||
WHEN platform = 'kyberswap-v2'
|
||||
THEN CONCAT(COALESCE(c0.symbol,CONCAT(SUBSTRING(token0, 1, 5),'...',SUBSTRING(token0, 39, 42))),'-',COALESCE(c1.symbol,CONCAT(SUBSTRING(token1, 1, 5),'...',SUBSTRING(token1, 39, 42))),' ',COALESCE(fee,0),' ',COALESCE(tick_spacing,0))
|
||||
WHEN platform = 'uniswap-v3'
|
||||
THEN CONCAT(COALESCE(c0.symbol,CONCAT(SUBSTRING(token0, 1, 5),'...',SUBSTRING(token0, 39, 42))),'-',COALESCE(c1.symbol,CONCAT(SUBSTRING(token1, 1, 5),'...',SUBSTRING(token1, 39, 42))),' ',COALESCE(fee,0),' ',COALESCE(tick_spacing,0),' UNI-V3 LP')
|
||||
END AS pool_name,
|
||||
OBJECT_CONSTRUCT('token0',token0,'token1',token1) AS tokens,
|
||||
OBJECT_CONSTRUCT('token0',c0.symbol,'token1',c1.symbol) AS symbols,
|
||||
OBJECT_CONSTRUCT('token0',c0.decimals,'token1',c1.decimals) AS decimals,
|
||||
platform,
|
||||
version,
|
||||
_id,
|
||||
p._inserted_timestamp
|
||||
FROM all_pools_v3 p
|
||||
LEFT JOIN contracts c0
|
||||
ON c0.address = p.token0
|
||||
LEFT JOIN contracts c1
|
||||
ON c1.address = p.token1
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
CASE
|
||||
WHEN pool_name IS NULL
|
||||
THEN CONCAT(
|
||||
COALESCE(c0.symbol, SUBSTRING(token0, 1, 5) || '...' || SUBSTRING(token0, 39, 42)),
|
||||
CASE WHEN token1 IS NOT NULL THEN '-' || COALESCE(c1.symbol, SUBSTRING(token1, 1, 5) || '...' || SUBSTRING(token1, 39, 42)) ELSE '' END,
|
||||
CASE WHEN token2 IS NOT NULL THEN '-' || COALESCE(c2.symbol, SUBSTRING(token2, 1, 5) || '...' || SUBSTRING(token2, 39, 42)) ELSE '' END,
|
||||
CASE WHEN token3 IS NOT NULL THEN '-' || COALESCE(c3.symbol, SUBSTRING(token3, 1, 5) || '...' || SUBSTRING(token3, 39, 42)) ELSE '' END,
|
||||
CASE WHEN token4 IS NOT NULL THEN '-' || COALESCE(c4.symbol, SUBSTRING(token4, 1, 5) || '...' || SUBSTRING(token4, 39, 42)) ELSE '' END,
|
||||
CASE WHEN token5 IS NOT NULL THEN '-' || COALESCE(c5.symbol, SUBSTRING(token5, 1, 5) || '...' || SUBSTRING(token5, 39, 42)) ELSE '' END,
|
||||
CASE WHEN token6 IS NOT NULL THEN '-' || COALESCE(c6.symbol, SUBSTRING(token6, 1, 5) || '...' || SUBSTRING(token6, 39, 42)) ELSE '' END,
|
||||
CASE WHEN token7 IS NOT NULL THEN '-' || COALESCE(c7.symbol, SUBSTRING(token7, 1, 5) || '...' || SUBSTRING(token7, 39, 42)) ELSE '' END
|
||||
)
|
||||
ELSE pool_name
|
||||
END AS pool_name,
|
||||
OBJECT_CONSTRUCT('token0', token0, 'token1', token1, 'token2', token2, 'token3', token3, 'token4', token4, 'token5', token5, 'token6', token6, 'token7', token7) AS tokens,
|
||||
OBJECT_CONSTRUCT('token0', c0.symbol, 'token1', c1.symbol, 'token2', c2.symbol, 'token3', c3.symbol, 'token4', c4.symbol, 'token5', c5.symbol, 'token6', c6.symbol, 'token7', c7.symbol) AS symbols,
|
||||
OBJECT_CONSTRUCT('token0', c0.decimals, 'token1', c1.decimals, 'token2', c2.decimals, 'token3', c3.decimals, 'token4', c4.decimals, 'token5', c5.decimals, 'token6', c6.decimals, 'token7', c7.decimals) AS decimals,
|
||||
platform,
|
||||
version,
|
||||
_id,
|
||||
p._inserted_timestamp
|
||||
FROM all_pools_other p
|
||||
LEFT JOIN contracts c0
|
||||
ON c0.address = p.token0
|
||||
LEFT JOIN contracts c1
|
||||
ON c1.address = p.token1
|
||||
LEFT JOIN contracts c2
|
||||
ON c2.address = p.token2
|
||||
LEFT JOIN contracts c3
|
||||
ON c3.address = p.token3
|
||||
LEFT JOIN contracts c4
|
||||
ON c4.address = p.token4
|
||||
LEFT JOIN contracts c5
|
||||
ON c5.address = p.token5
|
||||
LEFT JOIN contracts c6
|
||||
ON c6.address = p.token6
|
||||
LEFT JOIN contracts c7
|
||||
ON c7.address = p.token7
|
||||
)
|
||||
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
platform,
|
||||
version,
|
||||
contract_address,
|
||||
pool_address,
|
||||
pool_name,
|
||||
tokens,
|
||||
symbols,
|
||||
decimals,
|
||||
CASE
|
||||
WHEN pool_name IS NULL THEN CONCAT(
|
||||
COALESCE(
|
||||
c0.symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
)
|
||||
)
|
||||
ELSE pool_name
|
||||
END AS pool_name,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
token0,
|
||||
'token1',
|
||||
token1
|
||||
) AS tokens,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.symbol,
|
||||
'token1',
|
||||
c1.symbol
|
||||
) AS symbols,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.decimals,
|
||||
'token1',
|
||||
c1.decimals
|
||||
) AS decimals,
|
||||
platform,
|
||||
version,
|
||||
_id,
|
||||
_inserted_timestamp
|
||||
FROM FINAL
|
||||
p._inserted_timestamp
|
||||
FROM
|
||||
all_pools_standard p
|
||||
LEFT JOIN contracts c0
|
||||
ON c0.address = p.token0
|
||||
LEFT JOIN contracts c1
|
||||
ON c1.address = p.token1
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
CASE
|
||||
WHEN platform = 'kyberswap-v2' THEN CONCAT(
|
||||
COALESCE(
|
||||
c0.symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
fee,
|
||||
0
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
tick_spacing,
|
||||
0
|
||||
)
|
||||
)
|
||||
WHEN platform = 'uniswap-v3' THEN CONCAT(
|
||||
COALESCE(
|
||||
c0.symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
fee,
|
||||
0
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
tick_spacing,
|
||||
0
|
||||
),
|
||||
' UNI-V3 LP'
|
||||
)
|
||||
END AS pool_name,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
token0,
|
||||
'token1',
|
||||
token1
|
||||
) AS tokens,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.symbol,
|
||||
'token1',
|
||||
c1.symbol
|
||||
) AS symbols,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.decimals,
|
||||
'token1',
|
||||
c1.decimals
|
||||
) AS decimals,
|
||||
platform,
|
||||
version,
|
||||
_id,
|
||||
p._inserted_timestamp
|
||||
FROM
|
||||
all_pools_v3 p
|
||||
LEFT JOIN contracts c0
|
||||
ON c0.address = p.token0
|
||||
LEFT JOIN contracts c1
|
||||
ON c1.address = p.token1
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
CASE
|
||||
WHEN pool_name IS NULL THEN CONCAT(
|
||||
COALESCE(c0.symbol, SUBSTRING(token0, 1, 5) || '...' || SUBSTRING(token0, 39, 42)),
|
||||
CASE
|
||||
WHEN token1 IS NOT NULL THEN '-' || COALESCE(c1.symbol, SUBSTRING(token1, 1, 5) || '...' || SUBSTRING(token1, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token2 IS NOT NULL THEN '-' || COALESCE(c2.symbol, SUBSTRING(token2, 1, 5) || '...' || SUBSTRING(token2, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token3 IS NOT NULL THEN '-' || COALESCE(c3.symbol, SUBSTRING(token3, 1, 5) || '...' || SUBSTRING(token3, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token4 IS NOT NULL THEN '-' || COALESCE(c4.symbol, SUBSTRING(token4, 1, 5) || '...' || SUBSTRING(token4, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token5 IS NOT NULL THEN '-' || COALESCE(c5.symbol, SUBSTRING(token5, 1, 5) || '...' || SUBSTRING(token5, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token6 IS NOT NULL THEN '-' || COALESCE(c6.symbol, SUBSTRING(token6, 1, 5) || '...' || SUBSTRING(token6, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token7 IS NOT NULL THEN '-' || COALESCE(c7.symbol, SUBSTRING(token7, 1, 5) || '...' || SUBSTRING(token7, 39, 42))
|
||||
ELSE ''
|
||||
END
|
||||
)
|
||||
ELSE pool_name
|
||||
END AS pool_name,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
token0,
|
||||
'token1',
|
||||
token1,
|
||||
'token2',
|
||||
token2,
|
||||
'token3',
|
||||
token3,
|
||||
'token4',
|
||||
token4,
|
||||
'token5',
|
||||
token5,
|
||||
'token6',
|
||||
token6,
|
||||
'token7',
|
||||
token7
|
||||
) AS tokens,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.symbol,
|
||||
'token1',
|
||||
c1.symbol,
|
||||
'token2',
|
||||
c2.symbol,
|
||||
'token3',
|
||||
c3.symbol,
|
||||
'token4',
|
||||
c4.symbol,
|
||||
'token5',
|
||||
c5.symbol,
|
||||
'token6',
|
||||
c6.symbol,
|
||||
'token7',
|
||||
c7.symbol
|
||||
) AS symbols,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.decimals,
|
||||
'token1',
|
||||
c1.decimals,
|
||||
'token2',
|
||||
c2.decimals,
|
||||
'token3',
|
||||
c3.decimals,
|
||||
'token4',
|
||||
c4.decimals,
|
||||
'token5',
|
||||
c5.decimals,
|
||||
'token6',
|
||||
c6.decimals,
|
||||
'token7',
|
||||
c7.decimals
|
||||
) AS decimals,
|
||||
platform,
|
||||
version,
|
||||
_id,
|
||||
p._inserted_timestamp
|
||||
FROM
|
||||
all_pools_other p
|
||||
LEFT JOIN contracts c0
|
||||
ON c0.address = p.token0
|
||||
LEFT JOIN contracts c1
|
||||
ON c1.address = p.token1
|
||||
LEFT JOIN contracts c2
|
||||
ON c2.address = p.token2
|
||||
LEFT JOIN contracts c3
|
||||
ON c3.address = p.token3
|
||||
LEFT JOIN contracts c4
|
||||
ON c4.address = p.token4
|
||||
LEFT JOIN contracts c5
|
||||
ON c5.address = p.token5
|
||||
LEFT JOIN contracts c6
|
||||
ON c6.address = p.token6
|
||||
LEFT JOIN contracts c7
|
||||
ON c7.address = p.token7
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
platform,
|
||||
version,
|
||||
contract_address,
|
||||
pool_address,
|
||||
pool_name,
|
||||
tokens,
|
||||
symbols,
|
||||
decimals,
|
||||
_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['block_number','platform','version']
|
||||
) }} AS complete_dex_liquidity_pools_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL
|
||||
|
||||
@ -500,13 +500,25 @@ hashflow_swaps AS (
|
||||
token_out,
|
||||
CONCAT(
|
||||
LEAST(
|
||||
COALESCE(symbol_in, CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))),
|
||||
COALESCE(symbol_out, CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)))
|
||||
COALESCE(
|
||||
symbol_in,
|
||||
CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))
|
||||
),
|
||||
COALESCE(
|
||||
symbol_out,
|
||||
CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42))
|
||||
)
|
||||
),
|
||||
'-',
|
||||
GREATEST(
|
||||
COALESCE(symbol_in, CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))),
|
||||
COALESCE(symbol_out, CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)))
|
||||
COALESCE(
|
||||
symbol_in,
|
||||
CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))
|
||||
),
|
||||
COALESCE(
|
||||
symbol_out,
|
||||
CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42))
|
||||
)
|
||||
)
|
||||
) AS pool_name,
|
||||
_log_id,
|
||||
@ -562,13 +574,25 @@ hashflow_v3_swaps AS (
|
||||
token_out,
|
||||
CONCAT(
|
||||
LEAST(
|
||||
COALESCE(symbol_in, CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))),
|
||||
COALESCE(symbol_out, CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)))
|
||||
COALESCE(
|
||||
symbol_in,
|
||||
CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))
|
||||
),
|
||||
COALESCE(
|
||||
symbol_out,
|
||||
CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42))
|
||||
)
|
||||
),
|
||||
'-',
|
||||
GREATEST(
|
||||
COALESCE(symbol_in, CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))),
|
||||
COALESCE(symbol_out, CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)))
|
||||
COALESCE(
|
||||
symbol_in,
|
||||
CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))
|
||||
),
|
||||
COALESCE(
|
||||
symbol_out,
|
||||
CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42))
|
||||
)
|
||||
)
|
||||
) AS pool_name,
|
||||
_log_id,
|
||||
@ -1123,7 +1147,7 @@ all_dex_standard AS (
|
||||
FROM
|
||||
hashflow_swaps
|
||||
UNION ALL
|
||||
SELECT
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
@ -1555,7 +1579,13 @@ SELECT
|
||||
symbol_in,
|
||||
symbol_out,
|
||||
f._log_id,
|
||||
f._inserted_timestamp
|
||||
f._inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['f.tx_hash','f.event_index']
|
||||
) }} AS complete_dex_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL f
|
||||
LEFT JOIN {{ ref('silver_dex__complete_dex_liquidity_pools') }}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = 'address',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
@ -13,7 +14,13 @@ SELECT
|
||||
label_type,
|
||||
label_subtype,
|
||||
address_name,
|
||||
project_name
|
||||
project_name,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['address']
|
||||
) }} AS labels_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('bronze__labels') }}
|
||||
WHERE
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = ['token_address','symbol','id','provider'],
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
@ -14,7 +15,13 @@ SELECT
|
||||
token_name AS NAME,
|
||||
token_decimals AS decimals,
|
||||
provider,
|
||||
p._inserted_timestamp
|
||||
p._inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['token_address','symbol','id','provider']
|
||||
) }} AS asset_metadata_all_providers_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('bronze__asset_metadata_all_providers') }}
|
||||
p
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = 'token_address',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
@ -11,14 +12,20 @@ SELECT
|
||||
C.token_symbol,
|
||||
p.symbol
|
||||
) AS symbol,
|
||||
C.token_name AS name,
|
||||
C.token_name AS NAME,
|
||||
C.token_decimals AS decimals,
|
||||
p.provider,
|
||||
CASE
|
||||
WHEN p.provider = 'coingecko' THEN 1
|
||||
WHEN p.provider = 'coinmarketcap' THEN 2
|
||||
END AS priority,
|
||||
p._inserted_timestamp
|
||||
p._inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['p.token_address']
|
||||
) }} AS asset_metadata_priority_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('bronze__asset_metadata_priority') }}
|
||||
p
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = ['token_address', 'hour', 'provider'],
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
@ -10,7 +11,13 @@ SELECT
|
||||
provider,
|
||||
price,
|
||||
is_imputed,
|
||||
_inserted_timestamp
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['token_address', 'hour', 'provider']
|
||||
) }} AS hourly_prices_all_providers_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('bronze__hourly_prices_all_providers') }}
|
||||
WHERE
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = ['token_address', 'hour'],
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['non_realtime']
|
||||
) }}
|
||||
|
||||
@ -14,7 +15,13 @@ SELECT
|
||||
C.token_symbol,
|
||||
m.symbol
|
||||
) AS symbol,
|
||||
C.token_decimals AS decimals
|
||||
C.token_decimals AS decimals,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['p.token_address', 'p.hour']
|
||||
) }} AS hourly_prices_priority_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('bronze__hourly_prices_priority') }}
|
||||
p
|
||||
|
||||
Loading…
Reference in New Issue
Block a user