From 02addb4c2c13cca016839290d9e3b2b5c156eb21 Mon Sep 17 00:00:00 2001 From: San Yong <22216004+SanYongxie@users.noreply.github.com> Date: Tue, 15 Apr 2025 09:36:03 +0800 Subject: [PATCH] AN-5863/ccip-bridging (#328) * initial commit * update complete and gold tables --- data/silver_bridge__ccip_chain_seed.csv | 75 +++++++++ models/gold/defi/defi__ez_bridge_activity.sql | 2 +- .../silver_bridge__ccip_send_requested.sql | 146 ++++++++++++++++++ .../silver_bridge__ccip_send_requested.yml | 70 +++++++++ ...ilver_bridge__complete_bridge_activity.sql | 47 +++++- 5 files changed, 337 insertions(+), 3 deletions(-) create mode 100644 data/silver_bridge__ccip_chain_seed.csv create mode 100644 models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.sql create mode 100644 models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.yml diff --git a/data/silver_bridge__ccip_chain_seed.csv b/data/silver_bridge__ccip_chain_seed.csv new file mode 100644 index 0000000..a3c6554 --- /dev/null +++ b/data/silver_bridge__ccip_chain_seed.csv @@ -0,0 +1,75 @@ +chain_name,chain_selector +apechain,14894068710063348487 +arbitrum,4949039107694359620 +l3x,3162193654116181371 +treasure,1010349088906777999 +areon,1939936305787790600 +astar-zkevm,1540201334317828111 +avalanche,6433500567565415381 +dexalot,5463201557265485081 +base,15971525489660198786 +berachain,1294465214383781161 +bsc,11344663589394136015 +opbnb,465944652040885897 +bitcichain,4874388048629246000 +bitlayer,7937294810946806131 +bittorrent,3776006016387883143 +blast,4411394078118774322 +bob,3849287863852499584 +botanix,4560701533377838164 +bsquared,5406759801798337480 +celo,1346049177634351622 +coinex_smart_chain,1761333065194157300 +core,1224752112135636129 +corn,9043146809313071210 +cronos,1456215246176062136 +cronos-zkevm,8788096068760390840 +ethereum,5009297550715157269 +fantom,3768048213127883732 +filecoin,4561443241176882990 +fraxtal,1462016016387883143 +gnosis,465200170687744372 +hashkey,7613811247471741961 +hedera,3229138320728879060 +immutable-zkevm,1237925231416731909 +ink,3461204551265785888 +kava,7550000543357438061 +kroma,3719320017875267166 +moonriver,1355020143337428062 +lens,5608378062013572713 +linea,4627098889531055414 +mantle,1556008542357238666 +merlin,241851231317828981 +metis,8805746078405598895 +mind,11690709103138290329 +mode,7264351850409363825 +morph,18164309074156128038 +near,2039744413822257700 +neonlink,8239338020728974000 +optimism,3734403246176062136 +plume,3208172210661564830 +astar-polkadot,6422105447186081193 +centrifuge,8175830712062617656 +darwinia,8866418665544333000 +moonbeam,1252863800116739621 +polygon,4051577828743386545 +polygon-zkevm,4348158687435793198 +private-testnet-mica,4489326297382772450 +ronin,6916147374840168594 +rootstock,11964252391146578476 +scroll,13204309965629103672 +sei,9027416829622342829 +shibarium,3993510008929295315 +soneium,12505351618335765396 +sonic,1673871237479749969 +taiko,16468599424800719238 +telos-evm,1477345371608778000 +treasure,5214452172935136222 +unichain,1923510103922296319 +velas,374210358663784372 +wemix,5142893604156789321 +worldchain,2049429975587534727 +xlayer,3016212468291539606 +zircuit,17198166215261833993 +zklink_nova,4350319965322101699 +zksync,1562403441176082196 \ No newline at end of file diff --git a/models/gold/defi/defi__ez_bridge_activity.sql b/models/gold/defi/defi__ez_bridge_activity.sql index f7803e6..2875e72 100644 --- a/models/gold/defi/defi__ez_bridge_activity.sql +++ b/models/gold/defi/defi__ez_bridge_activity.sql @@ -5,7 +5,7 @@ meta ={ 'database_tags':{ 'table':{ - 'PROTOCOL': 'ALLBRIDGE, AXELAR, CELER, CBRIDGE, DLN, DEBRIDGE, EYWA, MESON, STARGATE, SYMBIOSIS, SYNAPSE, WORMHOLE', + 'PROTOCOL': 'ALLBRIDGE, AXELAR, CELER, CBRIDGE, DLN, DEBRIDGE, EYWA, MESON, STARGATE, SYMBIOSIS, SYNAPSE, WORMHOLE, CCIP', 'PURPOSE': 'BRIDGE' } } } ) }} diff --git a/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.sql b/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.sql new file mode 100644 index 0000000..7ee6d9f --- /dev/null +++ b/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.sql @@ -0,0 +1,146 @@ +{{ config( + materialized = 'incremental', + incremental_strategy = 'delete+insert', + unique_key = "block_number", + cluster_by = ['block_timestamp::DATE'], + tags = ['curated','reorg'] +) }} + +WITH on_ramp_set AS ( + + SELECT + block_timestamp, + tx_hash, + event_name, + TRY_TO_NUMBER( + decoded_log :destChainSelector :: STRING + ) AS destChainSelector, + chain_name, + decoded_log :onRamp :: STRING AS onRampAddress, + modified_timestamp + FROM + {{ ref('core__ez_decoded_event_logs') }} + INNER JOIN {{ ref('silver_bridge__ccip_chain_seed') }} + ON destChainSelector = chain_selector + WHERE + contract_address = LOWER('0x34B03Cb9086d7D758AC55af71584F81A598759FE') -- ccip router + AND topic_0 = '0x1f7d0ec248b80e5c0dde0ee531c4fc8fdb6ce9a2b3d90f560c74acd6a7202f23' -- onrampset + AND tx_succeeded + AND event_removed = FALSE + +{% if is_incremental() %} +AND modified_timestamp >= ( + SELECT + MAX(modified_timestamp) - INTERVAL '12 hours' + FROM + {{ this }} +) +AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' +{% endif %} +), +ccip_sent AS ( + SELECT + l.block_number, + l.block_timestamp, + l.tx_hash, + l.origin_function_signature, + l.origin_from_address, + l.origin_to_address, + contract_address, + l.event_name, + l.event_index, + regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, + CONCAT( + '0x', + segmented_data [13] :: STRING + ) AS message_id, + l.decoded_log, + decoded_log :message :feeToken :: STRING AS fee_token, + TRY_TO_NUMBER( + decoded_log :message :feeTokenAmount :: STRING + ) AS fee_token_amount, + TRY_TO_NUMBER( + decoded_log :message :gasLimit :: STRING + ) AS gas_limit, + TRY_TO_NUMBER( + decoded_log :message :nonce :: STRING + ) AS nonce, + decoded_log :message :receiver :: STRING AS receiver, + decoded_log :message :sender :: STRING AS sender, + TRY_TO_NUMBER( + decoded_log :message :sequenceNumber :: STRING + ) AS sequence_number, + TRY_TO_NUMBER( + decoded_log :message :sourceChainSelector :: STRING + ) AS source_chain_selector, + destChainSelector AS dest_chain_selector, + chain_name, + decoded_log :message :tokenAmounts AS token_amounts, + ARRAY_SIZE( + decoded_log :message :tokenAmounts + ) AS token_amounts_count, + CONCAT( + l.tx_hash :: STRING, + '-', + event_index :: STRING + ) AS _log_id, + l.modified_timestamp + FROM + {{ ref('core__ez_decoded_event_logs') }} + l + INNER JOIN on_ramp_set + ON onRampAddress = contract_address + WHERE + topic_0 = '0xd0c3c799bf9e2639de44391e7f524d229b2b55f5b1ea94b2bf7da42f7243dddd' -- CCIPSendRequested + AND tx_succeeded + AND event_removed = FALSE + +{% if is_incremental() %} +AND l.modified_timestamp >= ( + SELECT + MAX(modified_timestamp) - INTERVAL '12 hours' + FROM + {{ this }} +) +AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' +{% endif %} +) +SELECT + C.block_number, + C.block_timestamp, + C.origin_function_signature, + C.origin_from_address, + C.origin_to_address, + C.tx_hash, + C.event_name, + C.event_index, + 'chainlink-ccip' AS platform, + 'v1' AS version, + C.contract_address AS bridge_address, + C.message_id, + C.nonce, + C.receiver, + C.sender, + C.receiver AS destination_chain_receiver, + C.sequence_number, + C.source_chain_selector, + C.dest_chain_selector AS destination_chain_id, + C.chain_name AS destination_chain, + C.gas_limit, + C.fee_token, + -- Divide the fee evenly by the number of tokens in the array + C.fee_token_amount / C.token_amounts_count AS fee_token_amount_per_token, + C.token_amounts_count, + TRY_TO_NUMBER( + tokens.value :amount :: STRING + ) AS amount_unadj, + tokens.value :token :: STRING AS token_address, + C._log_id, + C.modified_timestamp +FROM + ccip_sent C, + LATERAL FLATTEN( + input => C.token_amounts + ) AS tokens +WHERE + token_amounts_count > 0 \ No newline at end of file diff --git a/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.yml b/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.yml new file mode 100644 index 0000000..1c4635a --- /dev/null +++ b/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.yml @@ -0,0 +1,70 @@ +version: 2 +models: + - name: silver_bridge__ccip_send_requested + 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 \ No newline at end of file diff --git a/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql b/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql index 5ad3d9f..cd9a9b8 100644 --- a/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql +++ b/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql @@ -153,6 +153,42 @@ WHERE ) {% endif %} ), +ccip 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__ccip_send_requested') }} + + {% if is_incremental() and 'ccip' not in var('HEAL_MODELS') %} + WHERE + _inserted_timestamp >= ( + SELECT + MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' + FROM + {{ this }} + ) + {% endif %} + ), dln_debridge AS ( SELECT block_number, @@ -462,6 +498,11 @@ all_protocols AS ( FROM celer_cbridge UNION ALL + SELECT + * + FROM + ccip + UNION ALL SELECT * FROM @@ -527,7 +568,8 @@ complete_bridge_activity AS ( 'stargate-v1', 'wormhole-v1', 'meson-v1', - 'allbridge-v2' + 'allbridge-v2', + 'chainlink-ccip-v1' ) THEN destination_chain_id :: STRING WHEN d.chain_id IS NULL THEN destination_chain_id :: STRING ELSE d.chain_id :: STRING @@ -541,7 +583,8 @@ complete_bridge_activity AS ( 'stargate-v1', 'wormhole-v1', 'meson-v1', - 'allbridge-v2' + 'allbridge-v2', + 'chainlink-ccip-v1' ) THEN LOWER(destination_chain) WHEN d.chain IS NULL THEN LOWER(destination_chain) ELSE LOWER(