mirror of
https://github.com/FlipsideCrypto/sei-models.git
synced 2026-02-06 15:21:52 +00:00
An 5724 jellyverse (#97)
* initial commit add Jellyverse DEX to existing Sei models * add jellyswap pool list * add swaps model + upd pools model * add yml + fix model config * FINAL fixed inc logic + integrate combined swaps * add tests + removed modified timestamp cte * rm last update cte
This commit is contained in:
parent
bf32c7ffc9
commit
bdcc6f94e4
@ -0,0 +1,55 @@
|
||||
{{ 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
|
||||
@ -0,0 +1,32 @@
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
{{ 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
|
||||
@ -0,0 +1,45 @@
|
||||
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
|
||||
@ -50,12 +50,41 @@ 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
|
||||
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') }}
|
||||
|
||||
{% if is_incremental() and 'dragonswap' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
{% if is_incremental() %},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user