mirror of
https://github.com/FlipsideCrypto/aptos-models.git
synced 2026-02-06 11:06:43 +00:00
add tapp, rename hyperion
This commit is contained in:
parent
fd708384af
commit
52ff6b5c51
@ -1,7 +1,7 @@
|
||||
{% docs defi__fact_dex_swaps %}
|
||||
|
||||
## Description
|
||||
This table records all raw on-chain DEX swap events on Aptos for protocols including animeswap, auxexchange, batswap, cellana, cetus, hippo, liquidswap, pancake, sushi, thala, and tsunami. It provides the unadjusted, protocol-level swap data, including token addresses, amounts, and swapper addresses, without any decimal adjustment, token symbol enrichment, or price attribution.
|
||||
This table records all raw on-chain DEX swap events on Aptos for protocols including animeswap, auxexchange, batswap, cellana, cetus, hippo, liquidswap, pancake, sushi, thala, tsunami, hyperion and tapp exchange. It provides the unadjusted, protocol-level swap data, including token addresses, amounts, and swapper addresses, without any decimal adjustment, token symbol enrichment, or price attribution.
|
||||
|
||||
## Key Use Cases
|
||||
- Analyzing DEX trading activity and protocol market share
|
||||
|
||||
@ -16,8 +16,9 @@
|
||||
('thala', ref('silver__dex_swaps_thala')),
|
||||
('thala', ref('silver__dex_swaps_thala_v0')),
|
||||
('tsunami', ref('silver__dex_swaps_tsunami')),
|
||||
('hyperfluid', ref('silver__dex_swaps_hyperfluid')),
|
||||
('thala', ref('silver__dex_swaps_thala_v2'))
|
||||
('hyperion', ref('silver__dex_swaps_hyperfluid')),
|
||||
('thala', ref('silver__dex_swaps_thala_v2')),
|
||||
('tapp', ref('silver__dex_swaps_tapp'))
|
||||
|
||||
]
|
||||
%}
|
||||
|
||||
133
models/silver/defi/dex/silver__dex_swaps_tapp.sql
Normal file
133
models/silver/defi/dex/silver__dex_swaps_tapp.sql
Normal file
@ -0,0 +1,133 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "dex_swaps_tapp_id",
|
||||
incremental_strategy = 'merge',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['modified_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
{% if execute %}
|
||||
|
||||
{% if is_incremental() %}
|
||||
{% set max_mod_query %}
|
||||
|
||||
SELECT
|
||||
MAX(modified_timestamp) modified_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
|
||||
{% endset %}
|
||||
{% set max_mod = run_query(max_mod_query) [0] [0] %}
|
||||
{% if not max_mod or max_mod == 'None' %}
|
||||
{% set max_mod = '2099-01-01' %}
|
||||
{% endif %}
|
||||
|
||||
{% set min_block_date_query %}
|
||||
SELECT
|
||||
MIN(
|
||||
block_timestamp :: DATE
|
||||
)
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
MIN(block_timestamp) block_timestamp
|
||||
FROM
|
||||
{{ ref('silver__transactions') }} A
|
||||
WHERE
|
||||
modified_timestamp >= '{{max_mod}}'
|
||||
UNION ALL
|
||||
SELECT
|
||||
MIN(block_timestamp) block_timestamp
|
||||
FROM
|
||||
{{ ref('silver__events') }} A
|
||||
WHERE
|
||||
modified_timestamp >= '{{max_mod}}'
|
||||
) {% endset %}
|
||||
{% set min_bd = run_query(min_block_date_query) [0] [0] %}
|
||||
{% if not min_bd or min_bd == 'None' %}
|
||||
{% set min_bd = '2099-01-01' %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
WITH tx AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_timestamp,
|
||||
sender,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref(
|
||||
'silver__transactions'
|
||||
) }}
|
||||
WHERE
|
||||
success
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND block_timestamp :: DATE >= '{{min_bd}}'
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2025-06-11'
|
||||
{% endif %}
|
||||
),
|
||||
evnts AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
version,
|
||||
tx_hash,
|
||||
event_index,
|
||||
payload_function,
|
||||
event_address,
|
||||
event_resource,
|
||||
event_data,
|
||||
event_type,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref(
|
||||
'silver__events'
|
||||
) }}
|
||||
WHERE
|
||||
event_address = '0x487e905f899ccb6d46fdaec56ba1e0c4cf119862a16c409904b8c78fab1f5e8a'
|
||||
AND event_module = 'router'
|
||||
AND event_resource = 'Swapped'
|
||||
AND success
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND block_timestamp :: DATE >= '{{min_bd}}'
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2025-06-11'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
version,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_address,
|
||||
b.sender AS swapper,
|
||||
event_data:assets[event_data:asset_in_index::int]::string as token_in,
|
||||
event_data:assets[event_data:asset_out_index::int]::string as token_out,
|
||||
event_data:amount_in::int as amount_in_unadj,
|
||||
event_data:amount_out::int as amount_out_unadj,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS dex_swaps_tapp_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
evnts A
|
||||
JOIN tx b USING(
|
||||
tx_hash,
|
||||
block_timestamp
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
GREATEST(
|
||||
A.modified_timestamp,
|
||||
b.modified_timestamp
|
||||
) >= '{{max_mod}}'
|
||||
{% endif %}
|
||||
Loading…
Reference in New Issue
Block a user