mirror of
https://github.com/FlipsideCrypto/polygon-models.git
synced 2026-02-06 16:11:59 +00:00
* add * add * add * fix curve * add tests * overflow * custom tests --------- Co-authored-by: Austin <austin@flipsidecrypto.com>
45 lines
1.3 KiB
SQL
45 lines
1.3 KiB
SQL
{{ config (
|
|
materialized = "incremental",
|
|
unique_key = "created_contract_address",
|
|
merge_exclude_columns = ["inserted_timestamp"],
|
|
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(block_timestamp, tx_hash, created_contract_address, creator_address), SUBSTRING(created_contract_address, creator_address)",
|
|
tags = ['non_realtime']
|
|
) }}
|
|
|
|
SELECT
|
|
block_number,
|
|
block_timestamp,
|
|
tx_hash,
|
|
to_address AS created_contract_address,
|
|
from_address AS creator_address,
|
|
input AS created_contract_input,
|
|
modified_timestamp AS _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('core__fact_traces') }}
|
|
WHERE
|
|
TYPE ILIKE 'create%'
|
|
AND to_address IS NOT NULL
|
|
AND input IS NOT NULL
|
|
AND input != '0x'
|
|
AND tx_status = 'SUCCESS'
|
|
AND trace_status = 'SUCCESS'
|
|
|
|
{% if is_incremental() %}
|
|
AND _inserted_timestamp >= (
|
|
SELECT
|
|
MAX(_inserted_timestamp) - INTERVAL '24 hours'
|
|
FROM
|
|
{{ this }}
|
|
)
|
|
{% endif %}
|
|
|
|
qualify(ROW_NUMBER() over(PARTITION BY created_contract_address
|
|
ORDER BY
|
|
_inserted_timestamp DESC)) = 1
|