Skip to content

Commit

Permalink
abi upgrade (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinFlipside authored Mar 6, 2024
1 parent 6d515ab commit 2b574d7
Show file tree
Hide file tree
Showing 8 changed files with 665 additions and 189 deletions.
23 changes: 14 additions & 9 deletions models/bronze/api_udf/_retry_abis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@ WITH retry AS (

SELECT
contract_address,
MAX(block_number) AS block_number,
COUNT(*) AS events
GREATEST(
latest_call_block,
latest_event_block
) AS block_number,
total_interaction_count
FROM
{{ ref("silver__logs") }}
l
{{ ref("silver__relevant_contracts") }}
r
LEFT JOIN {{ source(
'gnosis_silver',
'verified_abis'
) }}
v USING (contract_address)
WHERE
l.block_timestamp >= CURRENT_DATE - INTERVAL '30 days' -- recent activity
r.total_interaction_count >= 250 -- high interaction count
AND GREATEST(
max_inserted_timestamp_logs,
max_inserted_timestamp_traces
) >= CURRENT_DATE - INTERVAL '30 days' -- recent activity
AND v.contract_address IS NULL -- no verified abi
AND l.contract_address NOT IN (
AND r.contract_address NOT IN (
SELECT
contract_address
FROM
Expand All @@ -31,10 +38,8 @@ WITH retry AS (
_inserted_timestamp >= CURRENT_DATE - INTERVAL '30 days' -- this won't let us retry the same contract within 30 days
AND abi_data :data :result :: STRING <> 'Max rate limit reached'
)
GROUP BY
contract_address
ORDER BY
events DESC
total_interaction_count DESC
LIMIT
25
), FINAL AS (
Expand Down
4 changes: 3 additions & 1 deletion models/bronze/api_udf/bronze_api__contract_abis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ WITH base AS (
SELECT
contract_address
FROM
{{ ref('silver__relevant_abi_contracts') }}
{{ ref('silver__relevant_contracts') }}
WHERE
total_interaction_count >= 100

{% if is_incremental() %}
EXCEPT
Expand Down
19 changes: 11 additions & 8 deletions models/bronze/api_udf/bronze_api__token_reads.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ WITH base AS (

SELECT
contract_address,
latest_block
latest_event_block AS latest_block
FROM
{{ ref('silver__relevant_contracts') }}
WHERE
total_event_count >= 25

{% if is_incremental() %}
WHERE
contract_address NOT IN (
SELECT
contract_address
FROM
{{ this }}
)
AND contract_address NOT IN (
SELECT
contract_address
FROM
{{ this }}
)
{% endif %}
ORDER BY
total_event_count DESC
LIMIT
500
), function_sigs AS (
Expand Down
91 changes: 60 additions & 31 deletions models/silver/ABIs/silver__complete_event_abis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,67 @@
tags = ['abis']
) }}

WITH proxies AS (
WITH new_abis AS (

SELECT
created_block,
proxy_created_block,
contract_address,
proxy_address,
start_block,
_id,
_inserted_timestamp
DISTINCT contract_address
FROM
{{ ref('silver__flat_event_abis') }}

{% if is_incremental() %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
proxies AS (
SELECT
p0.created_block,
p0.proxy_created_block,
p0.contract_address,
p0.proxy_address,
p0.start_block,
p0._id,
p0._inserted_timestamp
FROM
{{ ref('silver__proxies') }}
p0
JOIN new_abis na0
ON p0.contract_address = na0.contract_address
UNION
SELECT
p1.created_block,
p1.proxy_created_block,
p1.contract_address,
p1.proxy_address,
p1.start_block,
p1._id,
p1._inserted_timestamp
FROM
{{ ref('silver__proxies') }}
p1
JOIN new_abis na1
ON p1.proxy_address = na1.contract_address
),
all_relevant_contracts AS (
SELECT
DISTINCT contract_address
FROM
proxies
UNION
SELECT
DISTINCT proxy_address AS contract_address
FROM
proxies
UNION
SELECT
contract_address
FROM
new_abis
),
flat_abis AS (
SELECT
Expand All @@ -32,27 +81,7 @@ flat_abis AS (
_inserted_timestamp
FROM
{{ ref('silver__flat_event_abis') }}

{% if is_incremental() %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '24 hours'
FROM
{{ this }}
)
OR contract_address IN (
SELECT
DISTINCT contract_address AS contract_address
FROM
proxies
UNION ALL
SELECT
DISTINCT proxy_address AS contract_address
FROM
proxies
)
{% endif %}
JOIN all_relevant_contracts USING (contract_address)
),
base AS (
SELECT
Expand Down Expand Up @@ -152,8 +181,8 @@ new_records AS (
ORDER BY
priority ASC,
_inserted_timestamp DESC,
proxy_created_block DESC NULLS LAST,
proxy_inserted_timestamp DESC NULLS LAST
proxy_created_block DESC nulls last,
proxy_inserted_timestamp DESC nulls last
) = 1
)
SELECT
Expand Down
29 changes: 0 additions & 29 deletions models/silver/ABIs/silver__relevant_abi_contracts.sql

This file was deleted.

7 changes: 0 additions & 7 deletions models/silver/ABIs/silver__relevant_abi_contracts.yml

This file was deleted.

Loading

0 comments on commit 2b574d7

Please sign in to comment.