mirror of
https://github.com/FlipsideCrypto/avalanche-models.git
synced 2026-02-06 12:56:59 +00:00
parent
3f1dc71d7c
commit
68eebe53e6
114
models/silver/defi/bridge/native/silver_bridge__native_v2.sql
Normal file
114
models/silver/defi/bridge/native/silver_bridge__native_v2.sql
Normal file
@ -0,0 +1,114 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver_bridge','defi','bridge','curated']
|
||||
) }}
|
||||
|
||||
WITH unwrap AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
contract_address AS bridge_address,
|
||||
contract_address AS token_address,
|
||||
'Unwrap' AS event_name,
|
||||
'avalanche_native_bridge' AS platform,
|
||||
'v2' AS version,
|
||||
regexp_SUBSTR_all(SUBSTR(DATA, 3), '.{64}') AS part,
|
||||
utils.udf_hex_to_int(
|
||||
part [0] :: STRING
|
||||
) :: INT AS amount_unadj,
|
||||
utils.udf_hex_to_int(
|
||||
part [1] :: STRING
|
||||
) :: STRING AS destination_chain_id,
|
||||
CONCAT(
|
||||
tx_hash,
|
||||
'-',
|
||||
event_index
|
||||
) AS _log_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
block_timestamp :: DATE >= '2022-01-01'
|
||||
AND topic_0 = '0x37a06799a3500428a773d00284aa706101f5ad94dae9ec37e1c3773aa54c3304'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
transfers AS (
|
||||
SELECT
|
||||
contract_address,
|
||||
tx_hash,
|
||||
from_address
|
||||
FROM
|
||||
{{ ref('core__ez_token_transfers') }}
|
||||
WHERE
|
||||
block_timestamp :: DATE >= '2022-01-01'
|
||||
AND to_address = '0x0000000000000000000000000000000000000000'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
qualify ROW_NUMBER() over (
|
||||
PARTITION BY tx_hash,
|
||||
contract_address,
|
||||
from_address
|
||||
ORDER BY
|
||||
event_index ASC
|
||||
) = 1
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
tx_hash,
|
||||
event_index,
|
||||
bridge_address,
|
||||
event_name,
|
||||
platform,
|
||||
version,
|
||||
from_address AS sender,
|
||||
from_address AS receiver,
|
||||
from_address AS destination_chain_receiver,
|
||||
destination_chain_id :: STRING AS destination_chain_id,
|
||||
IFF(
|
||||
token_address = '0x152b9d0fdc40c096757f570a51e494bd4b943e50',
|
||||
-- btc.b
|
||||
'bitcoin',
|
||||
'ethereum'
|
||||
) AS destination_chain,
|
||||
token_address,
|
||||
amount_unadj,
|
||||
_log_id,
|
||||
modified_timestamp,
|
||||
inserted_timestamp
|
||||
FROM
|
||||
unwrap
|
||||
INNER JOIN transfers USING (
|
||||
contract_address,
|
||||
tx_hash
|
||||
)
|
||||
@ -0,0 +1,72 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_bridge__native_v2
|
||||
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
|
||||
- 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:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_NAME
|
||||
tests:
|
||||
- not_null
|
||||
- name: BRIDGE_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: SENDER
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: RECEIVER
|
||||
tests:
|
||||
- not_null
|
||||
- name: DESTINATION_CHAIN_RECEIVER
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- DECIMAL
|
||||
- FLOAT
|
||||
- NUMBER
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
tests:
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
@ -333,6 +333,42 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
native_v2 AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
tx_hash,
|
||||
event_index,
|
||||
bridge_address,
|
||||
event_name,
|
||||
platform,
|
||||
version,
|
||||
sender,
|
||||
receiver,
|
||||
destination_chain_receiver,
|
||||
destination_chain_id :: STRING AS destination_chain_id,
|
||||
destination_chain,
|
||||
token_address,
|
||||
NULL AS token_symbol,
|
||||
amount_unadj,
|
||||
_log_id AS _id,
|
||||
inserted_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_bridge__native_v2') }}
|
||||
|
||||
{% if is_incremental() and 'native_v2' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
stargate AS (
|
||||
SELECT
|
||||
block_number,
|
||||
@ -703,6 +739,11 @@ all_protocols AS (
|
||||
FROM
|
||||
multichain
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
native_v2
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
@ -778,7 +819,8 @@ complete_bridge_activity AS (
|
||||
'circle-cctp-v2-v2',
|
||||
'chainlink-ccip-v1',
|
||||
'layerzero-v2',
|
||||
'stargate-v2'
|
||||
'stargate-v2',
|
||||
'avalanche_native_bridge-v2'
|
||||
) THEN destination_chain_id :: STRING
|
||||
WHEN d.chain_id IS NULL THEN destination_chain_id :: STRING
|
||||
ELSE d.chain_id :: STRING
|
||||
@ -797,7 +839,8 @@ complete_bridge_activity AS (
|
||||
'circle-cctp-v2-v2',
|
||||
'chainlink-ccip-v1',
|
||||
'layerzero-v2',
|
||||
'stargate-v2'
|
||||
'stargate-v2',
|
||||
'avalanche_native_bridge-v2'
|
||||
) THEN LOWER(destination_chain)
|
||||
WHEN d.chain IS NULL THEN LOWER(destination_chain)
|
||||
ELSE LOWER(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user