mirror of
https://github.com/FlipsideCrypto/base-models.git
synced 2026-02-06 17:56:55 +00:00
add cctp v1 v2 bridging
This commit is contained in:
parent
a661d2b028
commit
9c68e9dbf9
12
data/silver_bridge__cctp_chain_id_seed.csv
Normal file
12
data/silver_bridge__cctp_chain_id_seed.csv
Normal file
@ -0,0 +1,12 @@
|
||||
chain,domain
|
||||
ethereum,0
|
||||
avalanche,1
|
||||
optimism,2
|
||||
arbitrum,3
|
||||
noble,4
|
||||
solana,5
|
||||
base,6
|
||||
polygon pos,7
|
||||
sui,8
|
||||
aptos,9
|
||||
unichain,10
|
||||
|
@ -2,7 +2,7 @@
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ACROSS, AXELAR, CELER, CBRIDGE, DLN, DEBRIDGE, HOP, MESON, STARGATE, SYMBIOSIS, SYNAPSE, WORMHOLE',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ACROSS, AXELAR, CELER, CBRIDGE, DLN, DEBRIDGE, HOP, MESON, STARGATE, SYMBIOSIS, SYNAPSE, WORMHOLE, CCTP',
|
||||
'PURPOSE': 'BRIDGE' } } }
|
||||
) }}
|
||||
|
||||
|
||||
@ -0,0 +1,122 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
WITH base_evt AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
event_index,
|
||||
TRY_TO_NUMBER(utils.udf_hex_to_int(topic_1 :: STRING)) AS nonce,
|
||||
CONCAT('0x', SUBSTR(topic_2 :: STRING, 27, 40)) AS burn_token,
|
||||
CONCAT('0x', SUBSTR(topic_3 :: STRING, 27, 40)) AS depositor,
|
||||
regexp_SUBSTR_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [0] :: STRING)) AS burn_amount,
|
||||
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [2] :: STRING)) AS destination_domain,
|
||||
CASE
|
||||
WHEN destination_domain IN (
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
6,
|
||||
7,
|
||||
10
|
||||
) THEN CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) -- evm
|
||||
WHEN destination_domain = 5 THEN utils.udf_hex_to_base58(CONCAT('0x', segmented_data [1] :: STRING)) -- solana
|
||||
ELSE CONCAT(
|
||||
'0x',
|
||||
segmented_data [1] :: STRING
|
||||
) -- other non-evm chains
|
||||
END AS mint_recipient,
|
||||
CASE
|
||||
WHEN destination_domain IN (
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
6,
|
||||
7,
|
||||
10
|
||||
) THEN CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) -- evm
|
||||
WHEN destination_domain = 5 THEN utils.udf_hex_to_base58(CONCAT('0x', segmented_data [3] :: STRING)) -- solana
|
||||
ELSE CONCAT(
|
||||
'0x',
|
||||
segmented_data [3] :: STRING
|
||||
) -- other non-evm chains
|
||||
END AS destinationTokenMessenger,
|
||||
CASE
|
||||
WHEN destination_domain IN (
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
6,
|
||||
7,
|
||||
10
|
||||
) THEN CONCAT('0x', SUBSTR(segmented_data [4] :: STRING, 25, 40)) -- evm
|
||||
WHEN destination_domain = 5 THEN utils.udf_hex_to_base58(CONCAT('0x', segmented_data [4] :: STRING)) -- solana
|
||||
ELSE CONCAT(
|
||||
'0x',
|
||||
segmented_data [4] :: STRING
|
||||
) -- other non-evm chains
|
||||
END AS destination_caller,
|
||||
CONCAT(
|
||||
tx_hash,
|
||||
'-',
|
||||
event_index
|
||||
) AS _log_id,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address = '0x1682ae6375c4e4a97e4b583bc394c861a46d8962' -- base
|
||||
AND topic_0 = '0x2fa9ca894982930190727e75500a97d8dc500233a5065e0f3126c48fbe0343c0'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
event_index,
|
||||
contract_address AS bridge_address,
|
||||
'DepositForBurn' AS event_name,
|
||||
'circle-cctp' AS platform,
|
||||
depositor,
|
||||
depositor AS sender,
|
||||
origin_from_address AS receiver,
|
||||
mint_recipient AS destination_chain_receiver,
|
||||
chain AS destination_chain,
|
||||
destination_domain AS destination_chain_id,
|
||||
burn_token AS token_address,
|
||||
burn_amount AS amount_unadj,
|
||||
_log_id,
|
||||
e.modified_timestamp
|
||||
FROM
|
||||
base_evt e
|
||||
LEFT JOIN {{ ref('silver_bridge__cctp_chain_id_seed') }}
|
||||
d
|
||||
ON domain = destination_domain
|
||||
@ -0,0 +1,72 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_bridge__cctp_depositforburn
|
||||
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
|
||||
@ -0,0 +1,162 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
WITH base_evt AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_index,
|
||||
topic_0,
|
||||
event_name,
|
||||
event_removed,
|
||||
decoded_log,
|
||||
TRY_TO_NUMBER(
|
||||
decoded_log :nonce :: STRING
|
||||
) AS nonce,
|
||||
decoded_log :burnToken :: STRING AS burnToken,
|
||||
decoded_log :depositor :: STRING AS depositor,
|
||||
TRY_TO_NUMBER(
|
||||
decoded_log :amount :: STRING
|
||||
) AS amount,
|
||||
TRY_TO_NUMBER(
|
||||
decoded_log :destinationDomain :: STRING
|
||||
) AS destination_domain,
|
||||
CASE
|
||||
WHEN destination_domain IN (
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
6,
|
||||
7,
|
||||
10
|
||||
) THEN CONCAT(
|
||||
'0x',
|
||||
SUBSTR(
|
||||
decoded_log :mintRecipient :: STRING,
|
||||
25,
|
||||
40
|
||||
)
|
||||
) -- evm
|
||||
WHEN destination_domain = 5 THEN utils.udf_hex_to_base58(CONCAT('0x', decoded_log :mintRecipient :: STRING)) -- solana
|
||||
ELSE CONCAT(
|
||||
'0x',
|
||||
decoded_log :mintRecipient :: STRING
|
||||
) -- other non-evm chains
|
||||
END AS mint_recipient,
|
||||
CASE
|
||||
WHEN destination_domain IN (
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
6,
|
||||
7,
|
||||
10
|
||||
) THEN CONCAT(
|
||||
'0x',
|
||||
SUBSTR(
|
||||
decoded_log :destinationTokenMessenger :: STRING,
|
||||
25,
|
||||
40
|
||||
)
|
||||
) -- evm
|
||||
WHEN destination_domain = 5 THEN utils.udf_hex_to_base58(
|
||||
CONCAT(
|
||||
'0x',
|
||||
decoded_log :destinationTokenMessenger :: STRING
|
||||
)
|
||||
) -- solana
|
||||
ELSE CONCAT(
|
||||
'0x',
|
||||
decoded_log :destinationTokenMessenger :: STRING
|
||||
) -- other non-evm chains
|
||||
END AS destination_token_messenger,
|
||||
CASE
|
||||
WHEN destination_domain IN (
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
6,
|
||||
7,
|
||||
10
|
||||
) THEN CONCAT(
|
||||
'0x',
|
||||
SUBSTR(
|
||||
decoded_log :destinationCaller :: STRING,
|
||||
25,
|
||||
40
|
||||
)
|
||||
) -- evm
|
||||
WHEN destination_domain = 5 THEN utils.udf_hex_to_base58(
|
||||
CONCAT(
|
||||
'0x',
|
||||
decoded_log :destinationCaller :: STRING
|
||||
)
|
||||
) -- solana
|
||||
ELSE CONCAT(
|
||||
'0x',
|
||||
decoded_log :destinationCaller :: STRING
|
||||
) -- other non-evm chains
|
||||
END AS destination_caller,
|
||||
modified_timestamp,
|
||||
CONCAT(
|
||||
tx_hash,
|
||||
'-',
|
||||
event_index
|
||||
) AS _log_id
|
||||
FROM
|
||||
{{ ref('core__ez_decoded_event_logs') }}
|
||||
WHERE
|
||||
contract_address = '0x28b5a0e9c621a5badaa536219b3a228c8168cf5d'
|
||||
AND topic_0 = '0x0c8c1cbdc5190613ebd485511d4e2812cfa45eecb79d845893331fedad5130a5'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
tx_hash,
|
||||
event_index,
|
||||
topic_0,
|
||||
event_name,
|
||||
contract_address AS bridge_address,
|
||||
'circle-cctp-v2' AS platform,
|
||||
burnToken AS token_address,
|
||||
amount AS amount_unadj,
|
||||
depositor AS sender,
|
||||
origin_from_address AS receiver,
|
||||
mint_recipient AS destination_chain_receiver,
|
||||
destination_domain AS destination_chain_id,
|
||||
chain AS destination_chain,
|
||||
_log_id,
|
||||
modified_timestamp
|
||||
FROM
|
||||
base_evt
|
||||
LEFT JOIN {{ ref('silver_bridge__cctp_chain_id_seed') }}
|
||||
d
|
||||
ON domain = destination_domain
|
||||
@ -0,0 +1,70 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_bridge__cctp_v2_depositforburn
|
||||
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:
|
||||
- not_null
|
||||
@ -82,7 +82,6 @@ WHERE
|
||||
{% endif %}
|
||||
),
|
||||
allbridge_v2 AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
@ -478,6 +477,78 @@ WHERE
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cctp AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
tx_hash,
|
||||
event_index,
|
||||
bridge_address,
|
||||
event_name,
|
||||
platform,
|
||||
'v1' AS 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,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_bridge__cctp_depositforburn') }}
|
||||
|
||||
{% if is_incremental() and 'cctp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
cctp_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,
|
||||
'v2' AS 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,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_bridge__cctp_v2_depositforburn') }}
|
||||
|
||||
{% if is_incremental() and 'cctp_v2' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
all_protocols AS (
|
||||
SELECT
|
||||
*
|
||||
@ -543,6 +614,16 @@ all_protocols AS (
|
||||
*
|
||||
FROM
|
||||
wormhole
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
cctp
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
cctp_v2
|
||||
),
|
||||
complete_bridge_activity AS (
|
||||
SELECT
|
||||
@ -561,21 +642,33 @@ complete_bridge_activity AS (
|
||||
receiver,
|
||||
destination_chain_receiver,
|
||||
CASE
|
||||
WHEN CONCAT(platform, '-', version) IN (
|
||||
WHEN CONCAT(
|
||||
platform,
|
||||
'-',
|
||||
version
|
||||
) IN (
|
||||
'stargate-v1',
|
||||
'wormhole-v1',
|
||||
'meson-v1',
|
||||
'allbridge-v2'
|
||||
'allbridge-v2',
|
||||
'circle-cctp-v1',
|
||||
'circle-cctp-v2-v2'
|
||||
) THEN destination_chain_id :: STRING
|
||||
WHEN d.chain_id IS NULL THEN destination_chain_id :: STRING
|
||||
ELSE d.chain_id :: STRING
|
||||
END AS destination_chain_id,
|
||||
CASE
|
||||
WHEN CONCAT(platform, '-', version) IN (
|
||||
WHEN CONCAT(
|
||||
platform,
|
||||
'-',
|
||||
version
|
||||
) IN (
|
||||
'stargate-v1',
|
||||
'wormhole-v1',
|
||||
'meson-v1',
|
||||
'allbridge-v2'
|
||||
'allbridge-v2',
|
||||
'circle-cctp-v1',
|
||||
'circle-cctp-v2-v2'
|
||||
) THEN LOWER(destination_chain)
|
||||
WHEN d.chain IS NULL THEN LOWER(destination_chain)
|
||||
ELSE LOWER(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user