new protocol (#77)

This commit is contained in:
drethereum 2024-10-16 11:43:20 -06:00 committed by GitHub
parent b46c0040fd
commit 3353b1538c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 419 additions and 4 deletions

View File

@ -1,5 +1,5 @@
{% docs eth_dex_lp_table_doc %}
This table contains details on decentralized exchange (DEX) liquidity pools (LP) on the base blockchain, including the tokens, symbols and decimals within each pool alongside the following protocols: BLADESWAP, BLASTERSWAP, RING, SUSHI, and THRUSTER.
This table contains details on decentralized exchange (DEX) liquidity pools (LP) on the base blockchain, including the tokens, symbols and decimals within each pool alongside the following protocols: BLADESWAP, BLASTERSWAP, FENIX, RING, SUSHI, and THRUSTER.
{% enddocs %}

View File

@ -1,6 +1,6 @@
{% docs eth_ez_dex_swaps_table_doc %}
This table currently contains swap events from the ```fact_event_logs``` table for AMBIENT, BLADESWAP, BLASTERSWAP, RING, SUSHI, and THRUSTER. along with other helpful columns including an amount USD where possible. Other dexes coming soon!
This table currently contains swap events from the ```fact_event_logs``` table for AMBIENT, BLADESWAP, BLASTERSWAP, FENIX, RING, SUSHI, and THRUSTER. along with other helpful columns including an amount USD where possible. Other dexes coming soon!
Note: A rule has been put in place to null out the amount_USD if that number is too divergent between amount_in_USD and amount_out_usd. This can happen for swaps of less liquid tokens during very high fluctuation of price.
{% enddocs %}

View File

@ -2,7 +2,7 @@
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'BLADESWAP, BLASTERSWAP, RING, SUSHI, THRUSTER',
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'BLADESWAP, BLASTERSWAP, FENIX, RING, SUSHI, THRUSTER',
'PURPOSE': 'DEX, LIQUIDITY, POOLS, LP, SWAPS',} } }
) }}

View File

@ -2,7 +2,7 @@
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'AMBIENT, BLADESWAP, BLASTERSWAP, RING, SUSHI, THRUSTER',
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'AMBIENT, BLADESWAP, BLASTERSWAP, FENIX, RING, SUSHI, THRUSTER',
'PURPOSE': 'DEX, SWAPS',
} } }
) }}

View File

@ -0,0 +1,162 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = 'pool_address',
cluster_by = ['block_timestamp::DATE'],
tags = ['curated']
) }}
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,
LOWER(CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40))) AS token0_address,
LOWER(CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))) AS token1_address,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address,
_log_id,
_inserted_timestamp
FROM
{{ ref('silver__logs') }}
WHERE
topics [0] :: STRING = '0x91ccaa7a278130b65168c3a0c8d3bcae84cf5e43704342bd3ec0b59e59c036db'
AND contract_address = '0x7a44cd060afc1b6f4c80a2b9b37f4473e74e25df' --Fenix Finance : Algebra Factory
AND tx_status = 'SUCCESS'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
pool_info AS (
SELECT
contract_address,
topics [0] :: STRING AS topics_0,
topics [1] :: STRING AS topics_1,
topics [2] :: STRING AS topics_2,
topics [3] :: STRING AS topics_3,
DATA,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
_log_id,
_inserted_timestamp
FROM
{{ ref('silver__logs') }}
WHERE
topics [0] :: STRING IN (
'0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95',
'0x598b9f043c813aa6be3426ca60d1c65d17256312890be5118dab55b0775ebe2a',
'0x01413b1d5d4c359e9a0daa7909ecda165f6e8c51fe2ff529d74b22a5a7c02645'
)
AND tx_status = 'SUCCESS'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
initial_info AS (
SELECT
contract_address,
segmented_data,
utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [0] :: STRING)) :: FLOAT AS init_price,
utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [1] :: STRING)) :: FLOAT AS init_tick,
pow(
1.0001,
init_tick
) AS init_price_1_0_unadj,
_log_id,
_inserted_timestamp
FROM
pool_info
WHERE
topics_0 = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95'
),
fee_info AS (
SELECT
contract_address,
segmented_data,
utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [0] :: STRING)) :: FLOAT AS fee,
_log_id,
_inserted_timestamp
FROM
pool_info
WHERE
topics_0 = '0x598b9f043c813aa6be3426ca60d1c65d17256312890be5118dab55b0775ebe2a'
),
tickspacing_info AS (
SELECT
contract_address,
segmented_data,
utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [0] :: STRING)) :: FLOAT AS tick_spacing,
_log_id,
_inserted_timestamp
FROM
pool_info
WHERE
topics_0 = '0x01413b1d5d4c359e9a0daa7909ecda165f6e8c51fe2ff529d74b22a5a7c02645'
),
FINAL AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
p.contract_address,
token0_address,
token1_address,
fee :: INTEGER AS fee,
(
fee / 10000
) :: FLOAT AS fee_percent,
tick_spacing,
pool_address,
COALESCE(
init_tick,
0
) AS init_tick,
p._log_id,
p._inserted_timestamp
FROM
created_pools p
LEFT JOIN initial_info i
ON p.pool_address = i.contract_address
LEFT JOIN fee_info f
ON p.pool_address = f.contract_address
LEFT JOIN tickspacing_info t
ON p.pool_address = t.contract_address
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
contract_address,
token0_address,
token1_address,
fee,
fee_percent,
tick_spacing,
pool_address,
init_tick,
_log_id,
_inserted_timestamp
FROM
FINAL qualify(ROW_NUMBER() over(PARTITION BY pool_address
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -0,0 +1,23 @@
version: 2
models:
- name: silver_dex__fenix_pools_v3
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- POOL_ADDRESS
columns:
- name: BLOCK_NUMBER
tests:
- not_null
- name: POOL_ADDRESS
tests:
- not_null
- name: TOKEN0_ADDRESS
tests:
- not_null
- name: TOKEN1_ADDRESS
tests:
- not_null

View File

@ -0,0 +1,97 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = 'block_number',
cluster_by = ['block_timestamp::DATE'],
tags = ['curated','reorg']
) }}
WITH 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,
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 recipient,
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,
utils.udf_hex_to_int(
's2c',
segmented_data [2] :: STRING
) :: FLOAT AS sqrtPriceX96,
utils.udf_hex_to_int(
's2c',
segmented_data [3] :: STRING
) :: FLOAT AS liquidity,
utils.udf_hex_to_int(
's2c',
segmented_data [4] :: STRING
) :: FLOAT AS tick,
token0_address,
token1_address,
pool_address,
tick_spacing,
fee,
l._log_id,
l._inserted_timestamp
FROM
{{ ref('silver__logs') }}
l
INNER JOIN {{ ref('silver_dex__fenix_pools_v3') }}
p
ON p.pool_address = l.contract_address
WHERE
l.block_timestamp :: DATE >= '2024-01-01'
AND topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67'
AND tx_status = 'SUCCESS'
{% if is_incremental() %}
AND l._inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address,
pool_address,
recipient,
sender,
fee,
tick,
tick_spacing,
liquidity,
token0_address,
token1_address,
amount0_unadj,
amount1_unadj,
_log_id,
_inserted_timestamp
FROM
swaps_base qualify(ROW_NUMBER() over(PARTITION BY _log_id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -0,0 +1,38 @@
version: 2
models:
- name: silver_dex__fenix_swaps_v3
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _LOG_ID
columns:
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 1
- name: POOL_ADDRESS
tests:
- not_null
- name: RECIPIENT
tests:
- not_null
- name: SENDER
tests:
- not_null
- name: TOKEN0_ADDRESS
tests:
- not_null
- name: TOKEN1_ADDRESS
tests:
- not_null
- name: AMOUNT0_UNADJ
tests:
- not_null
- name: AMOUNT1_UNADJ
tests:
- not_null

View File

@ -157,6 +157,41 @@ WHERE
)
{% endif %}
),
fenix_v3 AS (
SELECT
block_number,
block_timestamp,
tx_hash,
contract_address,
pool_address,
NULL AS pool_name,
fee,
tick_spacing,
token0_address AS token0,
token1_address AS token1,
NULL AS token2,
NULL AS token3,
NULL AS token4,
NULL AS token5,
NULL AS token6,
NULL AS token7,
'fenix-v3' AS platform,
'v3' AS version,
_log_id AS _id,
_inserted_timestamp
FROM
{{ ref('silver_dex__fenix_pools_v3') }}
{% if is_incremental() and 'fenix_v3' not in var('HEAL_MODELS') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
{% endif %}
),
ring AS (
SELECT
block_number,
@ -388,6 +423,11 @@ all_pools AS (
FROM
blaster_v3
UNION ALL
SELECT
*
FROM
fenix_v3
UNION ALL
SELECT
*
FROM
@ -431,6 +471,7 @@ complete_lps AS (
AND platform IN (
'bladeswap-v3',
'blasterswap-v3',
'fenix-v3',
'ring-v3',
'sushiswap-v3',
'thruster-v3'
@ -457,6 +498,7 @@ complete_lps AS (
CASE
WHEN platform = 'bladeswap-v3' THEN ' BLP'
WHEN platform = 'blasterswap-v3' THEN ' BLP'
WHEN platform = 'fenix-v3' THEN ' FLP'
WHEN platform = 'ring-v3' THEN ' RLP'
WHEN platform = 'sushiswap-v3' THEN ' SLP'
WHEN platform = 'thruster-v3' THEN ' TLP'
@ -578,6 +620,7 @@ heal_model AS (
AND platform IN (
'bladeswap-v3',
'blasterswap-v3',
'fenix-v3',
'ring-v3',
'sushiswap-v3',
'thruster-v3'
@ -604,6 +647,7 @@ heal_model AS (
CASE
WHEN platform = 'bladeswap-v3' THEN ' BLP'
WHEN platform = 'blasterswap-v3' THEN ' BLP'
WHEN platform = 'fenix-v3' THEN ' FLP'
WHEN platform = 'ring-v3' THEN ' RLP'
WHEN platform = 'sushiswap-v3' THEN ' SLP'
WHEN platform = 'thruster-v3' THEN ' TLP'

View File

@ -203,6 +203,52 @@ WHERE
)
{% endif %}
),
fenix_v3 AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_function_signature,
origin_from_address,
origin_to_address,
pool_address AS contract_address,
'Swap' AS event_name,
CASE
WHEN amount0_unadj > 0 THEN ABS(amount0_unadj)
ELSE ABS(amount1_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 token0_address
ELSE token1_address
END AS token_in,
CASE
WHEN amount0_unadj < 0 THEN token0_address
ELSE token1_address
END AS token_out,
sender,
recipient AS tx_to,
'fenix-v3' AS platform,
'v3' AS version,
_log_id,
_inserted_timestamp
FROM
{{ ref('silver_dex__fenix_swaps_v3') }}
{% if is_incremental() and 'fenix_v3' not in var('HEAL_MODELS') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
{% endif %}
),
ring AS (
SELECT
block_number,
@ -469,6 +515,11 @@ all_dex AS (
FROM
blaster_v3
UNION ALL
SELECT
*
FROM
fenix_v3
UNION ALL
SELECT
*
FROM