AN-5769-SailorFi (#102)

* init sailorfi models

* fix missing event_name on swap model + rm unnecessary deduplication on prev model (Jellyswap)

* add test + fix typos

* rm hardcoded ref + rename recipient -> `tx_to`
This commit is contained in:
stanley 2025-02-20 22:51:01 +07:00 committed by GitHub
parent d23407c5b7
commit 0e2fbdd42c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 233 additions and 5 deletions

View File

@ -0,0 +1,54 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'merge',
unique_key = 'sailorswap_pools_id',
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
{{ ref('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

View File

@ -0,0 +1,30 @@
version: 2
models:
- name: silver_evm_dex__sailorswap_pools
description: Records of pools created on the sailorswap platform.
columns:
- name: BLOCK_NUMBER
- name: BLOCK_TIMESTAMP
- name: tx_hash
- name: event_index
- name: contract_address
- name: token0
- name: token1
- name: pool_id
- name: pool_address
- name: sailorswap_pools_id
description: Unique identifier for the pool
tests:
- unique:
where: modified_timestamp > current_date -3
- not_null:
where: modified_timestamp > current_date -3

View File

@ -0,0 +1,80 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'merge',
unique_key = 'sailorswap_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,
'Swap' AS event_name,
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 tx_to,
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,
event_name,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address AS pool_address,
sender,
tx_to,
token0,
token1,
amount0,
amount1,
is_missing_pool,
{{ dbt_utils.generate_surrogate_key(
['tx_hash', 'event_index']
) }} AS sailorswap_swaps_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM swaps_base

View File

@ -0,0 +1,45 @@
version: 2
models:
- name: silver_evm_dex__sailorswap_swaps
description: Records of swaps that occurred on the sailorswap platform
columns:
- name: BLOCK_NUMBER
- name: BLOCK_TIMESTAMP
tests:
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 1
- name: tx_hash
- name: event_index
- name: event_name
- name: origin_function_signature
- name: origin_from_address
- name: origin_to_address
- name: contract_address
- name: pool_id
description: Identifier from sailorswap for the pool in which the swap occurred
- name: amount_in_unadj
- name: amount_out_unadj
- name: token_in
- name: token_out
- name: sailorswap_swaps_id
description: Unique identifier for the swap
tests:
- unique:
where: modified_timestamp > current_date -3
- not_null:
where: modified_timestamp > current_date -3

View File

@ -55,7 +55,8 @@ WHERE
event_index
ORDER BY
modified_timestamp DESC
) = 1 -- add other dexes
) = 1
-- add other dexes
UNION ALL
@ -81,10 +82,28 @@ WHERE
FROM
{{ ref('silver_evm_dex__jellyswap_swaps') }}
{% if is_incremental() and 'dragonswap' not in var('HEAL_MODELS') %}
WHERE
modified_timestamp >= '{{ max_mod_timestamp }}'
{% endif %}
UNION ALL
SELECT
'sailorswap' AS platform,
block_number,
block_timestamp,
tx_hash,
event_index,
event_name,
origin_function_signature,
origin_from_address,
origin_to_address,
pool_address AS contract_address,
tx_to,
sender,
ABS(amount0) AS amount_in_unadj,
ABS(amount1) AS amount_out_unadj,
token0 AS token_in,
token1 AS token_out,
sailorswap_swaps_id AS uk
FROM
{{ ref('silver_evm_dex__sailorswap_swaps') }}
)
{% if is_incremental() %},