diff --git a/models/gold/core/core__dim_contract_abis.sql b/models/gold/core/core__dim_contract_abis.sql new file mode 100644 index 0000000..00bc10d --- /dev/null +++ b/models/gold/core/core__dim_contract_abis.sql @@ -0,0 +1,16 @@ +{{ config( + materialized = 'view', + persist_docs ={ "relation": true, + "columns": true } +) }} + +SELECT + contract_address, + DATA AS abi, + abi_source, + bytecode, + abis_id AS dim_contract_abis_id, + inserted_timestamp, + modified_timestamp +FROM + {{ ref('silver__abis') }} diff --git a/models/gold/core/core__dim_contract_abis.yml b/models/gold/core/core__dim_contract_abis.yml new file mode 100644 index 0000000..c745572 --- /dev/null +++ b/models/gold/core/core__dim_contract_abis.yml @@ -0,0 +1,19 @@ +version: 2 +models: + - name: core__dim_contract_abis + description: > + 'This table contains the contract ABIs that we have sourced from Polygonscan, the community, or bytecode matched. This table is the source of ABIs used in the `core__ez_decoded_event_logs` and `core__fact_decoded_event_logs` tables. + We first try to source ABIs from Polygonscan. If we cannot find an ABI on Polygonscan, we will rely on user submissions. To add a contract to this table, please visit [here](https://science.flipsidecrypto.xyz/abi-requestor/). + If we are unable to locate an ABI for a contract from Polygonscan or the community, we will try to find an ABI to use by matching the contract bytecode to a known contract bytecode we do have an ABI for.' + + columns: + - name: CONTRACT_ADDRESS + description: 'The address of the contract.' + - name: ABI + description: 'The JSON ABI for the contract.' + - name: ABI_SOURCE + description: 'The source of the ABI. This can be `Polygonscan`, `user_submitted`, or `bytecode_matched`.' + - name: BYTECODE + description: 'The deployed bytecode of the contract.' + + diff --git a/models/silver/abis/silver__abis.sql b/models/silver/abis/silver__abis.sql index cdf2148..0ecad79 100644 --- a/models/silver/abis/silver__abis.sql +++ b/models/silver/abis/silver__abis.sql @@ -1,6 +1,7 @@ {{ config ( materialized = "incremental", unique_key = "contract_address", + merge_exclude_columns = ["inserted_timestamp"], post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION on equality(contract_address)", tags = ['abis'] ) }} @@ -167,7 +168,13 @@ SELECT p.abi_source, p.discord_username, p.abi_hash, - created_contract_input AS bytecode + created_contract_input AS bytecode, + {{ dbt_utils.generate_surrogate_key( + ['contract_address'] + ) }} AS abis_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS _invocation_id FROM priority_abis p LEFT JOIN {{ ref('silver__created_contracts') }} diff --git a/models/silver/core/silver__decoded_logs2.sql b/models/silver/core/silver__decoded_logs2.sql index 74282b4..72ee068 100644 --- a/models/silver/core/silver__decoded_logs2.sql +++ b/models/silver/core/silver__decoded_logs2.sql @@ -4,6 +4,7 @@ unique_key = ['block_number', 'event_index'], cluster_by = "block_timestamp::date", incremental_predicates = ["dynamic_range", "block_number"], + merge_exclude_columns = ["inserted_timestamp"], post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION", tags = ['decoded_logs2'] ) }} @@ -207,7 +208,13 @@ SELECT DATA, event_removed, tx_status, - is_pending + is_pending, + {{ dbt_utils.generate_surrogate_key( + ['tx_hash','event_index'] + ) }} AS decoded_logs_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS _invocation_id FROM new_records @@ -232,7 +239,13 @@ SELECT DATA, event_removed, tx_status, - is_pending + is_pending, + {{ dbt_utils.generate_surrogate_key( + ['tx_hash','event_index'] + ) }} AS decoded_logs_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS _invocation_id FROM missing_data {% endif %}