mirror of
https://github.com/FlipsideCrypto/sei-models.git
synced 2026-02-06 17:56:43 +00:00
init sailorfi models
This commit is contained in:
parent
bdcc6f94e4
commit
f3cc9791fb
@ -0,0 +1,54 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'pool_address',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH pools_created AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '[a-f0-9]{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics[1] :: STRING, 27, 40)) AS token0,
|
||||
CONCAT('0x', SUBSTR(topics[2] :: STRING, 27, 40)) AS token1,
|
||||
CONCAT('0x', SUBSTR(segmented_data[1] :: STRING, 25, 40)) AS pool_address,
|
||||
FROM
|
||||
sei.silver_evm.logs
|
||||
WHERE
|
||||
contract_address = LOWER('0xA51136931fdd3875902618bF6B3abe38Ab2D703b') -- SailorSwapFactory
|
||||
AND topics[0] :: STRING = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' -- PairCreated
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
token0,
|
||||
token1,
|
||||
pool_address,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address']
|
||||
) }} AS sailorswap_pools_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
pools_created qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||
ORDER BY
|
||||
block_timestamp DESC)) = 1
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'sailor_swaps_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH pools AS (
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM {{ ref('silver_evm_dex__sailorswap_pools') }}
|
||||
),
|
||||
swaps_base AS (
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
l.origin_function_signature,
|
||||
l.origin_from_address,
|
||||
l.origin_to_address,
|
||||
l.contract_address,
|
||||
CONCAT('0x', SUBSTR(topics[1] :: STRING, 27, 40)) AS sender,
|
||||
CONCAT('0x', SUBSTR(topics[2] :: STRING, 27, 40)) AS recipient,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}')[0] :: STRING
|
||||
) :: FLOAT AS amount0,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}')[1] :: STRING
|
||||
) :: FLOAT AS amount1,
|
||||
p.token0,
|
||||
p.token1,
|
||||
CASE WHEN p.pool_address IS NULL THEN TRUE ELSE FALSE END AS is_missing_pool
|
||||
FROM {{ ref('silver_evm__logs') }} l
|
||||
JOIN pools p
|
||||
ON LOWER(p.pool_address) = LOWER(l.contract_address)
|
||||
WHERE
|
||||
topics[0] :: STRING = '0x19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address AS pool_address,
|
||||
sender,
|
||||
recipient,
|
||||
token0,
|
||||
token1,
|
||||
amount0,
|
||||
amount1,
|
||||
is_missing_pool,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS sailor_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM swaps_base
|
||||
Loading…
Reference in New Issue
Block a user