mirror of
https://github.com/FlipsideCrypto/sei-models.git
synced 2026-02-06 18:46:46 +00:00
tags and remove legacy models
This commit is contained in:
parent
b4bf8676ef
commit
d6cd651c7f
2
.github/workflows/dbt_test_evm_recent.yml
vendored
2
.github/workflows/dbt_test_evm_recent.yml
vendored
@ -45,7 +45,7 @@ jobs:
|
||||
dbt deps
|
||||
- name: Run DBT Jobs
|
||||
run: |
|
||||
dbt test -m models/bronze/core "sei_models,tag:recent_evm_test"
|
||||
dbt test -m models/bronze/core "sei_models,tag:recent_evm_test" "sei_models,tag:curated"
|
||||
|
||||
notify-failure:
|
||||
needs: [run_dbt_jobs]
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'pool_address',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH created_pools AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
decoded_log :token0 :: STRING AS token0,
|
||||
decoded_log :token1 :: STRING AS token1,
|
||||
decoded_log :pair :: STRING AS pool_address,
|
||||
decoded_log :length :: INT AS pool_id
|
||||
FROM
|
||||
{{ ref ('core_evm__ez_decoded_event_logs') }}
|
||||
WHERE
|
||||
tx_succeeded
|
||||
AND contract_address = LOWER('0x71f6b49ae1558357bbb5a6074f1143c46cbca03d') --DragonswapFactory
|
||||
AND event_name = '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,
|
||||
pool_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address']
|
||||
) }} AS dragonswap_pools_v1_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
created_pools qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||
ORDER BY
|
||||
block_timestamp DESC)) = 1
|
||||
@ -1,61 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'pool_address',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH created_pools AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{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,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
)
|
||||
) AS pool_id,
|
||||
FROM
|
||||
{{ ref ('core_evm__fact_event_logs') }}
|
||||
WHERE
|
||||
tx_status = 'SUCCESS'
|
||||
AND contract_address = LOWER('0x179d9a5592bc77050796f7be28058c51ca575df4') --DragonswapFactoryV2
|
||||
AND topics [0] :: STRING = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118'
|
||||
|
||||
{% 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,
|
||||
pool_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address']
|
||||
) }} AS dragonswap_pools_v2_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
created_pools qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||
ORDER BY
|
||||
block_timestamp DESC)) = 1
|
||||
@ -1,62 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
tx_to,
|
||||
sender,
|
||||
ABS(amount_in_unadj) AS amount_in_unadj,
|
||||
ABS(amount_out_unadj) AS amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
dragonswap_swaps_decoded_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_invocation_id
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_swaps_decoded') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
tx_to,
|
||||
sender,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN amount1_unadj
|
||||
ELSE amount0_unadj
|
||||
END AS amount_in_unadj,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN ABS(amount0_unadj)
|
||||
ELSE ABS(amount1_unadj)
|
||||
END AS amount_out_unadj,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN token1
|
||||
ELSE token0
|
||||
END AS token_in,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN token0
|
||||
ELSE token1
|
||||
END AS token_out,
|
||||
dragonswap_swaps_undecoded_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_invocation_id
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_swaps_undecoded') }}
|
||||
@ -1,38 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_evm_dex__dragonswap_swaps_combined
|
||||
description: Records of swaps that occurred on the dragonswap 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: tx_to
|
||||
|
||||
- name: sender
|
||||
|
||||
- name: amount_in_unadj
|
||||
|
||||
- name: amount_out_unadj
|
||||
|
||||
- name: token_in
|
||||
|
||||
- name: token_out
|
||||
|
||||
@ -1,113 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'dragonswap_swaps_decoded_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__dragonswap_pools_v1') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_pools_v2') }}
|
||||
),
|
||||
swaps_base AS (
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
l.event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
decoded_log: amount0In :: bigint AS amount0In,
|
||||
decoded_log: amount1In :: bigint AS amount1In,
|
||||
decoded_log: amount0Out :: bigint AS amount0Out,
|
||||
decoded_log: amount1Out :: bigint AS amount1Out,
|
||||
decoded_log :sender :: STRING AS sender,
|
||||
decoded_log :to :: STRING AS tx_to,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('core_evm__ez_decoded_event_logs') }}
|
||||
l
|
||||
INNER JOIN pools p
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
event_name = 'Swap'
|
||||
AND tx_succeeded
|
||||
|
||||
{% 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,
|
||||
sender,
|
||||
tx_to,
|
||||
amount0In,
|
||||
amount1In,
|
||||
amount0Out,
|
||||
amount1Out,
|
||||
token0,
|
||||
token1,
|
||||
CASE
|
||||
WHEN amount0In <> 0
|
||||
AND amount1In <> 0
|
||||
AND amount0Out <> 0 THEN amount1In
|
||||
WHEN amount0In <> 0 THEN amount0In
|
||||
WHEN amount1In <> 0 THEN amount1In
|
||||
END AS amount_in_unadj,
|
||||
CASE
|
||||
WHEN amount0Out <> 0 THEN amount0Out
|
||||
WHEN amount1Out <> 0 THEN amount1Out
|
||||
END AS amount_out_unadj,
|
||||
CASE
|
||||
WHEN amount0In <> 0
|
||||
AND amount1In <> 0
|
||||
AND amount0Out <> 0 THEN token1
|
||||
WHEN amount0In <> 0 THEN token0
|
||||
WHEN amount1In <> 0 THEN token1
|
||||
END AS token_in,
|
||||
CASE
|
||||
WHEN amount0Out <> 0 THEN token0
|
||||
WHEN amount1Out <> 0 THEN token1
|
||||
END AS token_out,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS dragonswap_swaps_decoded_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
swaps_base
|
||||
WHERE
|
||||
token_in <> token_out
|
||||
@ -1,96 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'dragonswap_swaps_undecoded_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__dragonswap_pools_v1') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_pools_v2') }}
|
||||
),
|
||||
swaps_base AS (
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
NULL AS event_name,
|
||||
l.origin_function_signature,
|
||||
l.origin_from_address,
|
||||
l.origin_to_address,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
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',
|
||||
segmented_data [0] :: STRING
|
||||
) :: FLOAT AS amount0_unadj,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [1] :: STRING
|
||||
) :: FLOAT AS amount1_unadj,
|
||||
token0,
|
||||
token1,
|
||||
pool_address
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
l
|
||||
INNER JOIN pools p
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
l.block_timestamp :: DATE >= '2024-01-01'
|
||||
AND topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67'
|
||||
AND tx_succeeded
|
||||
|
||||
{% 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,
|
||||
pool_address,
|
||||
tx_to,
|
||||
sender,
|
||||
token0,
|
||||
token1,
|
||||
amount0_unadj,
|
||||
amount1_unadj,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS dragonswap_swaps_undecoded_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
swaps_base
|
||||
@ -1,55 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'jellyswap_pools_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
created_pools AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
topics[1]::STRING as pool_id,
|
||||
SUBSTR(topics[1]::STRING, 1, 42) as pool_address,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver_evm__logs') }}
|
||||
WHERE
|
||||
topics[0]::STRING = '0x3c13bc30b8e878c53fd2a36b679409c073afd75950be43d8858768e956fbc20e' -- PoolRegistered
|
||||
AND contract_address = '0xfb43069f6d0473b85686a85f4ce4fc1fd8f00875' -- Vault contract
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes' AS max_inserted_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
pool_id,
|
||||
pool_address,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address']
|
||||
) }} AS jellyswap_pools_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM created_pools
|
||||
QUALIFY ROW_NUMBER() OVER (
|
||||
PARTITION BY pool_address
|
||||
ORDER BY block_timestamp DESC
|
||||
) = 1
|
||||
@ -1,32 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_evm_dex__jellyswap_pools
|
||||
description: Records of pools created on the jellyswap platform.
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
|
||||
- name: tx_hash
|
||||
|
||||
- name: event_index
|
||||
|
||||
- name: contract_address
|
||||
|
||||
- name: pool_id
|
||||
|
||||
- name: pool_address
|
||||
|
||||
- name: jellyswap_pools_id
|
||||
description: Unique identifier for the pool
|
||||
tests:
|
||||
- unique:
|
||||
where: modified_timestamp > current_date -3
|
||||
- not_null:
|
||||
where: modified_timestamp > current_date -3
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'jellyswap_swaps_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH 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,
|
||||
topics[1]::STRING as pool_id,
|
||||
p.pool_address,
|
||||
CONCAT('0x', SUBSTR(topics[2]::STRING, 27, 40)) as token_in,
|
||||
CONCAT('0x', SUBSTR(topics[3]::STRING, 27, 40)) as token_out,
|
||||
regexp_substr_all(SUBSTR(data, 3, len(data)), '.{64}') AS segmented_data,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data[0]::STRING
|
||||
) as amount_in_raw,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data[1]::STRING
|
||||
) as amount_out_raw,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_evm__logs') }} l
|
||||
JOIN
|
||||
{{ ref('silver_evm_dex__jellyswap_pools') }} p
|
||||
ON l.topics[1]::STRING = p.pool_id
|
||||
WHERE
|
||||
topics[0]::STRING = '0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0a8dd37b1840b9e0b207b' -- Swap event
|
||||
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,
|
||||
pool_address,
|
||||
pool_id,
|
||||
token_in,
|
||||
token_out,
|
||||
amount_in_raw as amount_in_unadj,
|
||||
amount_out_raw as amount_out_unadj,
|
||||
{{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS jellyswap_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
swaps_base
|
||||
@ -1,45 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_evm_dex__jellyswap_swaps
|
||||
description: Records of swaps that occurred on the jellyswap 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 Jellyswap for the pool in which the swap occurred
|
||||
|
||||
- name: amount_in_unadj
|
||||
|
||||
- name: amount_out_unadj
|
||||
|
||||
- name: token_in
|
||||
|
||||
- name: token_out
|
||||
|
||||
- name: jellyswap_swaps_id
|
||||
description: Unique identifier for the swap
|
||||
tests:
|
||||
- unique:
|
||||
where: modified_timestamp > current_date -3
|
||||
- not_null:
|
||||
where: modified_timestamp > current_date -3
|
||||
@ -1,54 +0,0 @@
|
||||
{{ 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
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
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
|
||||
@ -1,80 +0,0 @@
|
||||
{{ 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
|
||||
@ -1,45 +0,0 @@
|
||||
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
|
||||
@ -1,308 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'swaps_combined_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['modified_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
{% if execute %}
|
||||
|
||||
{% if is_incremental() %}
|
||||
-- get the max modified_timestamp from the target table
|
||||
{% set max_m_query %}
|
||||
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '{{ var("LOOKBACK", "30 minutes") }}' AS modified_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
|
||||
{% endset %}
|
||||
{% set max_mod_timestamp = run_query(max_m_query).columns [0].values() [0] %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
WITH inc AS (
|
||||
SELECT
|
||||
'dragonswap' AS platform,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
tx_to,
|
||||
sender,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
dragonswap_swaps_decoded_id AS uk
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_swaps_combined') }}
|
||||
|
||||
{% if is_incremental() and 'dragonswap' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
{% endif %}
|
||||
|
||||
qualify ROW_NUMBER() over (
|
||||
PARTITION BY tx_hash,
|
||||
event_index
|
||||
ORDER BY
|
||||
modified_timestamp DESC
|
||||
) = 1
|
||||
-- add other dexes
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
'jellyswap' 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,
|
||||
null AS tx_to,
|
||||
null AS sender,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
jellyswap_swaps_id AS uk
|
||||
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__jellyswap_swaps') }}
|
||||
|
||||
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() %},
|
||||
mod_price AS (
|
||||
SELECT
|
||||
token_address,
|
||||
HOUR,
|
||||
price
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
),
|
||||
mod_decimal AS (
|
||||
SELECT
|
||||
contract_address,
|
||||
token_decimals,
|
||||
token_symbol
|
||||
FROM
|
||||
{{ ref('silver_evm__contracts') }}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
),
|
||||
mod_map AS (
|
||||
SELECT
|
||||
evm_address,
|
||||
sei_address
|
||||
FROM
|
||||
{{ ref('core__dim_address_mapping') }}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
)
|
||||
{% endif %},
|
||||
fin AS (
|
||||
SELECT
|
||||
A.block_number AS block_id,
|
||||
A.block_timestamp,
|
||||
A.tx_hash AS tx_id,
|
||||
'evm' AS originated_from,
|
||||
A.platform,
|
||||
d.sei_address AS swapper,
|
||||
A.origin_from_address,
|
||||
A.contract_address AS pool_address,
|
||||
A.amount_in_unadj,
|
||||
CASE
|
||||
WHEN c_in.token_decimals IS NOT NULL THEN (amount_in_unadj / pow(10, c_in.token_decimals))
|
||||
END AS amount_in,
|
||||
CASE
|
||||
WHEN c_in.token_decimals IS NOT NULL THEN amount_in * b_in.price
|
||||
END AS amount_in_usd,
|
||||
A.amount_out_unadj,
|
||||
CASE
|
||||
WHEN c_out.token_decimals IS NOT NULL THEN (amount_out_unadj / pow(10, c_out.token_decimals))
|
||||
END AS amount_out,
|
||||
CASE
|
||||
WHEN c_out.token_decimals IS NOT NULL THEN amount_out * b_out.price
|
||||
END AS amount_out_usd,
|
||||
A.token_in,
|
||||
c_in.token_symbol AS symbol_in,
|
||||
A.token_out,
|
||||
c_out.token_symbol AS symbol_out,
|
||||
A.origin_function_signature,
|
||||
A.event_index AS INDEX,
|
||||
A.origin_to_address,
|
||||
A.sender,
|
||||
A.tx_to,
|
||||
A.event_name,
|
||||
uk AS swaps_combined_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
inc A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
b_in
|
||||
ON A.token_in = b_in.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = b_in.hour
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
b_out
|
||||
ON A.token_out = b_out.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = b_out.hour
|
||||
LEFT JOIN {{ ref('silver_evm__contracts') }}
|
||||
c_in
|
||||
ON A.token_in = c_in.contract_address
|
||||
LEFT JOIN {{ ref('silver_evm__contracts') }}
|
||||
c_out
|
||||
ON A.token_out = c_out.contract_address
|
||||
LEFT JOIN {{ ref('core__dim_address_mapping') }}
|
||||
d
|
||||
ON A.origin_from_address = d.evm_address
|
||||
|
||||
{% if is_incremental() %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
A.block_id,
|
||||
A.block_timestamp,
|
||||
A.tx_id,
|
||||
A.originated_from,
|
||||
A.platform,
|
||||
COALESCE(
|
||||
A.swapper,
|
||||
d.sei_address
|
||||
) AS swapper,
|
||||
A.origin_from_address,
|
||||
A.pool_address,
|
||||
A.amount_in_unadj,
|
||||
COALESCE(
|
||||
A.amount_in,
|
||||
CASE
|
||||
WHEN c_in.token_decimals IS NOT NULL THEN (A.amount_in_unadj / pow(10, c_in.token_decimals))
|
||||
END
|
||||
) AS amount_in,
|
||||
COALESCE(
|
||||
A.amount_in_usd,
|
||||
CASE
|
||||
WHEN c_in.token_decimals IS NOT NULL THEN (A.amount_in_unadj / pow(10, c_in.token_decimals)) * b_in.price
|
||||
END
|
||||
) AS amount_in_usd,
|
||||
A.amount_out_unadj,
|
||||
COALESCE(
|
||||
A.amount_out,
|
||||
CASE
|
||||
WHEN c_out.token_decimals IS NOT NULL THEN (A.amount_out_unadj / pow(10, c_in.token_decimals))
|
||||
END
|
||||
) AS amount_out,
|
||||
COALESCE(
|
||||
A.amount_out_usd,
|
||||
CASE
|
||||
WHEN c_out.token_decimals IS NOT NULL THEN (A.amount_out_unadj / pow(10, c_in.token_decimals)) * b_out.price
|
||||
END
|
||||
) AS amount_out_usd,
|
||||
A.token_in,
|
||||
COALESCE(
|
||||
A.symbol_in,
|
||||
c_in.token_symbol
|
||||
) AS symbol_in,
|
||||
A.token_out,
|
||||
COALESCE(
|
||||
A.symbol_out,
|
||||
c_out.token_symbol
|
||||
) AS symbol_out,
|
||||
A.origin_function_signature,
|
||||
A.index,
|
||||
A.origin_to_address,
|
||||
A.sender,
|
||||
A.tx_to,
|
||||
A.event_name,
|
||||
A.swaps_combined_id,
|
||||
A.inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ this }} A
|
||||
LEFT JOIN mod_price b_in
|
||||
ON A.token_in = b_in.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = b_in.hour
|
||||
LEFT JOIN mod_price b_out
|
||||
ON A.token_out = b_out.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = b_out.hour
|
||||
LEFT JOIN mod_decimal c_in
|
||||
ON A.token_in = c_in.contract_address
|
||||
LEFT JOIN mod_decimal c_out
|
||||
ON A.token_out = c_out.contract_address
|
||||
LEFT JOIN mod_map d
|
||||
ON A.origin_from_address = d.evm_address
|
||||
WHERE
|
||||
(
|
||||
A.amount_in IS NULL
|
||||
OR A.amount_in_usd IS NULL
|
||||
OR A.amount_out IS NULL
|
||||
OR A.amount_out_usd IS NULL
|
||||
OR A.symbol_in IS NULL
|
||||
OR A.symbol_out IS NULL
|
||||
OR A.swapper IS NULL
|
||||
)
|
||||
AND (
|
||||
b_in.price IS NOT NULL
|
||||
OR b_out.price IS NOT NULL
|
||||
OR c_in.token_decimals IS NOT NULL
|
||||
OR c_out.token_decimals IS NOT NULL
|
||||
OR d.sei_address IS NOT NULL
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
fin qualify(ROW_NUMBER() over (PARTITION BY swaps_combined_id
|
||||
ORDER BY
|
||||
inserted_timestamp DESC) = 1)
|
||||
Loading…
Reference in New Issue
Block a user