mirror of
https://github.com/FlipsideCrypto/polygon-models.git
synced 2026-02-06 11:06:46 +00:00
* vars * tx success * bridge heal * typo * cte name * lps heal * var format * heal logic * dex swaps heal * column names * round in gold
126 lines
2.7 KiB
SQL
126 lines
2.7 KiB
SQL
{{ config(
|
|
materialized = 'incremental',
|
|
incremental_strategy = 'delete+insert',
|
|
unique_key = "block_number",
|
|
tags = ['curated']
|
|
) }}
|
|
|
|
WITH base_contracts AS (
|
|
|
|
SELECT
|
|
tx_hash,
|
|
block_number,
|
|
block_timestamp,
|
|
from_address,
|
|
to_address AS contract_address,
|
|
_call_id,
|
|
_inserted_timestamp
|
|
FROM
|
|
{{ ref('silver__traces') }}
|
|
WHERE
|
|
from_address = LOWER('0x808d7c71ad2ba3FA531b068a2417C63106BC0949')
|
|
AND TYPE ILIKE 'create%'
|
|
AND tx_status = 'SUCCESS'
|
|
AND trace_status = 'SUCCESS'
|
|
|
|
{% if is_incremental() %}
|
|
AND _inserted_timestamp >= (
|
|
SELECT
|
|
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
|
FROM
|
|
{{ this }}
|
|
)
|
|
AND to_address NOT IN (
|
|
SELECT
|
|
DISTINCT pool_address
|
|
FROM
|
|
{{ this }}
|
|
)
|
|
{% endif %}
|
|
),
|
|
function_sigs AS (
|
|
SELECT
|
|
'0xfc0c546a' AS function_sig,
|
|
'token' AS function_name
|
|
),
|
|
inputs AS (
|
|
SELECT
|
|
contract_address,
|
|
block_number,
|
|
function_sig,
|
|
function_name,
|
|
0 AS function_input,
|
|
CONCAT(
|
|
function_sig,
|
|
LPAD(
|
|
function_input,
|
|
64,
|
|
0
|
|
)
|
|
) AS DATA
|
|
FROM
|
|
base_contracts
|
|
JOIN function_sigs
|
|
ON 1 = 1
|
|
),
|
|
contract_reads AS (
|
|
SELECT
|
|
contract_address,
|
|
block_number,
|
|
function_sig,
|
|
function_name,
|
|
function_input,
|
|
DATA,
|
|
utils.udf_json_rpc_call(
|
|
'eth_call',
|
|
[{ 'to': contract_address, 'from': null, 'data': data }, utils.udf_int_to_hex(block_number) ]
|
|
) AS rpc_request,
|
|
live.udf_api(
|
|
node_url,
|
|
rpc_request
|
|
) AS read_output,
|
|
SYSDATE() AS _inserted_timestamp
|
|
FROM
|
|
inputs
|
|
JOIN {{ source(
|
|
'streamline_crosschain',
|
|
'node_mapping'
|
|
) }}
|
|
ON 1 = 1
|
|
AND chain = 'polygon'
|
|
),
|
|
reads_flat AS (
|
|
SELECT
|
|
read_output,
|
|
read_output :data :id :: STRING AS read_id,
|
|
read_output :data :result :: STRING AS read_result,
|
|
SPLIT(
|
|
read_id,
|
|
'-'
|
|
) AS read_id_object,
|
|
function_sig,
|
|
function_name,
|
|
function_input,
|
|
DATA,
|
|
contract_address,
|
|
block_number,
|
|
_inserted_timestamp
|
|
FROM
|
|
contract_reads
|
|
)
|
|
SELECT
|
|
read_output,
|
|
read_id,
|
|
read_result,
|
|
read_id_object,
|
|
function_sig,
|
|
function_name,
|
|
function_input,
|
|
DATA,
|
|
block_number,
|
|
contract_address AS pool_address,
|
|
CONCAT('0x', SUBSTR(read_result, 27, 40)) AS token_address,
|
|
_inserted_timestamp
|
|
FROM
|
|
reads_flat
|