From 530e6773d314a9551b00c05d0698913eda850e73 Mon Sep 17 00:00:00 2001 From: Eric Laurello Date: Thu, 22 May 2025 10:32:06 -0400 Subject: [PATCH] Upgrade decoding ABIs --- ...e_evm_api__flowscan_verified_contracts.sql | 173 ++++++++++++++++++ ...e_evm_api__flowscan_verified_contracts.yml | 11 ++ .../streamline__contract_abis_realtime.sql | 18 +- 3 files changed, 196 insertions(+), 6 deletions(-) create mode 100644 models/evm/bronze/bronze_evm_api__flowscan_verified_contracts.sql create mode 100644 models/evm/bronze/bronze_evm_api__flowscan_verified_contracts.yml diff --git a/models/evm/bronze/bronze_evm_api__flowscan_verified_contracts.sql b/models/evm/bronze/bronze_evm_api__flowscan_verified_contracts.sql new file mode 100644 index 0000000..77d9bab --- /dev/null +++ b/models/evm/bronze/bronze_evm_api__flowscan_verified_contracts.sql @@ -0,0 +1,173 @@ +{{ config( + materialized = 'incremental', + unique_key = "contract_address", + full_refresh = false, + tags = ['evm'] +) }} + +WITH level1 AS ( + + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts/' + ) :data AS DATA +), +level2 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level1 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +level3 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level2 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +level4 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level3 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +level5 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level4 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +level6 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level5 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +level7 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level6 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +level8 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level7 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +level9 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level8 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +level10 AS ( + SELECT + {{ target.database }}.live.udf_api( + 'https://evm.flowscan.io/api/v2/smart-contracts?hash=' || DATA :next_page_params: "hash" :: STRING + ) :data AS DATA + FROM + level9 + WHERE + DATA :next_page_params: "hash" :: STRING IS NOT NULL +), +ua AS ( + SELECT + DATA + FROM + level1 + UNION ALL + SELECT + DATA + FROM + level2 + UNION ALL + SELECT + DATA + FROM + level3 + UNION ALL + SELECT + DATA + FROM + level4 + UNION ALL + SELECT + DATA + FROM + level5 + UNION ALL + SELECT + DATA + FROM + level6 + UNION ALL + SELECT + DATA + FROM + level7 + UNION ALL + SELECT + DATA + FROM + level8 + UNION ALL + SELECT + DATA + FROM + level9 + UNION ALL + SELECT + DATA + FROM + level10 +) +SELECT + VALUE AS DATA, + VALUE :address :hash :: STRING AS contract_address, + VALUE :address :implementations AS implementations, + VALUE :address :is_contract :: BOOLEAN AS is_contract, + VALUE :address :is_verified :: BOOLEAN AS is_verified, + VALUE :address :name :: STRING AS NAME, + VALUE :address :private_tags AS private_tags, + VALUE :verified_at :: datetime AS verified_at, + {{ dbt_utils.generate_surrogate_key(['contract_address']) }} AS flowscan_verified_contracts_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS _invocation_id +FROM + ua, + LATERAL FLATTEN( + input => DATA :items + ) diff --git a/models/evm/bronze/bronze_evm_api__flowscan_verified_contracts.yml b/models/evm/bronze/bronze_evm_api__flowscan_verified_contracts.yml new file mode 100644 index 0000000..dad0eb2 --- /dev/null +++ b/models/evm/bronze/bronze_evm_api__flowscan_verified_contracts.yml @@ -0,0 +1,11 @@ +version: 2 +models: + - name: bronze_evm_api__flowscan_verified_contracts + + columns: + - name: MODIFIED_TIMESTAMP + tests: + - not_null + - dbt_expectations.expect_row_values_to_have_recent_data: + datepart: day + interval: 1 diff --git a/models/evm/streamline/core/flowscan/streamline__contract_abis_realtime.sql b/models/evm/streamline/core/flowscan/streamline__contract_abis_realtime.sql index 33ab8b7..25449e6 100644 --- a/models/evm/streamline/core/flowscan/streamline__contract_abis_realtime.sql +++ b/models/evm/streamline/core/flowscan/streamline__contract_abis_realtime.sql @@ -10,19 +10,25 @@ "sql_source": "{{this.identifier}}" } ) ) }} -with verified_contracts as ( - select address_hash AS contract_address from {{ ref('seeds__evm_verified_contracts') }} + +WITH verified_contracts AS ( + + SELECT + contract_address + FROM + {{ ref('bronze_evm_api__flowscan_verified_contracts') }} EXCEPT - select contract_address from {{ ref('streamline__complete_contract_abis') }} + SELECT + contract_address + FROM + {{ ref('streamline__complete_contract_abis') }} ) SELECT contract_address, DATE_PART('EPOCH', SYSDATE()) :: INTEGER AS partition_key, {{ target.database }}.live.udf_api( 'GET', - 'https://evm.flowscan.io/api/v2/smart-contracts/' || contract_address, - {}, - {} + 'https://evm.flowscan.io/api/v2/smart-contracts/' || contract_address,{},{} ) AS request FROM verified_contracts