mirror of
https://github.com/FlipsideCrypto/base-models.git
synced 2026-02-06 19:26:52 +00:00
AN-4486/add-new-higher-tvl-dexes (#166)
* add alien * fix liq pools * remove comment
This commit is contained in:
parent
b1c184ef9a
commit
e224bf4e3a
@ -0,0 +1,55 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'pool_address',
|
||||
tags = ['curated']
|
||||
) }}
|
||||
|
||||
WITH pool_creation 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 [0] :: STRING, 25, 40)) AS pool_address,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INT AS pool_id,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref ('silver__logs') }}
|
||||
WHERE
|
||||
contract_address = LOWER('0x3E84D913803b02A4a7f027165E8cA42C14C0FdE7')
|
||||
AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_index,
|
||||
token0,
|
||||
token1,
|
||||
pool_address,
|
||||
pool_id,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,23 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_dex__alienbase_pools
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- POOL_ADDRESS
|
||||
columns:
|
||||
- name: POOL_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN0
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN1
|
||||
tests:
|
||||
- not_null
|
||||
- name: _INSERTED_TIMESTAMP
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_LTZ
|
||||
- TIMESTAMP_NTZ
|
||||
118
models/silver/defi/dex/alienbase/silver_dex__alienbase_swaps.sql
Normal file
118
models/silver/defi/dex/alienbase/silver_dex__alienbase_swaps.sql
Normal file
@ -0,0 +1,118 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'block_number',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
WITH pools AS (
|
||||
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('silver_dex__alienbase_pools') }}
|
||||
),
|
||||
swaps_base AS (
|
||||
SELECT
|
||||
block_number,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER
|
||||
) AS amount0In,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
) AS amount1In,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER
|
||||
) AS amount0Out,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER
|
||||
) AS amount1Out,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to,
|
||||
token0,
|
||||
token1,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
INNER JOIN pools p
|
||||
ON p.pool_address = contract_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
tx_hash,
|
||||
event_index,
|
||||
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,
|
||||
'Swap' AS event_name,
|
||||
'alienbase' AS platform,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
swaps_base
|
||||
WHERE
|
||||
token_in <> token_out
|
||||
116
models/silver/defi/dex/alienbase/silver_dex__alienbase_swaps.yml
Normal file
116
models/silver/defi/dex/alienbase/silver_dex__alienbase_swaps.yml
Normal file
@ -0,0 +1,116 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_dex__alienbase_swaps
|
||||
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 2
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_LTZ
|
||||
- TIMESTAMP_NTZ
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: AMOUNT_IN_UNADJ
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- name: AMOUNT_IN
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- name: AMOUNT_OUT_UNADJ
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- name: AMOUNT_OUT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- name: TOKEN_IN
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
|
||||
- name: TOKEN_OUT
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: SYMBOL_IN
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
- name: SYMBOL_OUT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
- name: TX_TO
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- name: _LOG_ID
|
||||
tests:
|
||||
- not_null
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
tests:
|
||||
- not_null
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
|
||||
@ -171,6 +171,33 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
alienbase AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
NULL AS pool_name,
|
||||
token0,
|
||||
token1,
|
||||
'alienbase' AS platform,
|
||||
'v2' AS version,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__alienbase_pools') }}
|
||||
{% if is_incremental() and 'alienbase' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
dackieswap AS (
|
||||
SELECT
|
||||
block_number,
|
||||
@ -351,6 +378,11 @@ all_pools_standard AS (
|
||||
FROM
|
||||
uni_v2
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
alienbase
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
|
||||
@ -356,6 +356,58 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
alienbase_swaps AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
event_name,
|
||||
c1.decimals AS decimals_in,
|
||||
c1.symbol AS symbol_in,
|
||||
amount_in_unadj,
|
||||
CASE
|
||||
WHEN decimals_in IS NULL THEN amount_in_unadj
|
||||
ELSE (amount_in_unadj / pow(10, decimals_in))
|
||||
END AS amount_in,
|
||||
c2.decimals AS decimals_out,
|
||||
c2.symbol AS symbol_out,
|
||||
amount_out_unadj,
|
||||
CASE
|
||||
WHEN decimals_out IS NULL THEN amount_out_unadj
|
||||
ELSE (amount_out_unadj / pow(10, decimals_out))
|
||||
END AS amount_out,
|
||||
sender,
|
||||
tx_to,
|
||||
event_index,
|
||||
platform,
|
||||
'v1' AS version,
|
||||
token_in,
|
||||
token_out,
|
||||
NULL AS pool_name,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__alienbase_swaps') }}
|
||||
s
|
||||
LEFT JOIN contracts c1
|
||||
ON s.token_in = c1.address
|
||||
LEFT JOIN contracts c2
|
||||
ON s.token_out = c2.address
|
||||
|
||||
{% if is_incremental() and 'alienbase_swaps' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
sushi_swaps AS (
|
||||
SELECT
|
||||
block_number,
|
||||
@ -916,6 +968,36 @@ all_dex_standard AS (
|
||||
FROM
|
||||
univ2_swaps
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
pool_name,
|
||||
event_name,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
amount_in,
|
||||
amount_out,
|
||||
sender,
|
||||
tx_to,
|
||||
event_index,
|
||||
platform,
|
||||
version,
|
||||
token_in,
|
||||
token_out,
|
||||
symbol_in,
|
||||
symbol_out,
|
||||
decimals_in,
|
||||
decimals_out,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
alienbase_swaps
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user