Skip to content

Commit

Permalink
AN-5679/dln-sol-addr (#297)
Browse files Browse the repository at this point in the history
* sol decoding

* allbridge_v2

* qualify

* inner
  • Loading branch information
drethereum authored Jan 13, 2025
1 parent 3ffd029 commit ee09b95
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 14 deletions.
12 changes: 12 additions & 0 deletions data/silver_bridge__allbridge_chain_id_seed.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
chain,chain_id
ethereum,1
bsc,2
tron,3
solana,4
polygon,5
arbitrum,6
stellar,7
avalanche,8
base,9
optimism,10
celo,11
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{{ 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_function_signature,
origin_from_address,
origin_to_address,
contract_address,
'allbridge' AS platform,
event_index,
'TokensSent' AS event_name,
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 amount,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [2] :: STRING)) AS destinationChainId,
origin_from_address AS sender,
origin_from_address AS recipient,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) AS nonce,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [5] :: STRING)) AS messenger,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash,
'-',
event_index
) AS _log_id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] = '0x9cd6008e8d4ebd34fd9d022278fec7f95d133780ecc1a0dea459fae3e9675390' --TokensSent
AND contract_address = '0x9068e1c28941d0a680197cc03be8afe27ccaeea9' --Allbridge
AND tx_succeeded

{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
lp_evt AS (
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address,
event_index,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS sender,
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS token,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [2] :: STRING)) AS amount,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [3] :: STRING)) AS vUsdAmount,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) AS fee,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash,
'-',
event_index
) AS _log_id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] = '0xa930da1d3f27a25892307dd59cec52dd9b881661a0f20364757f83a0da2f6873' --SwappedToVUsd
AND contract_address IN (
'0x2d2f460d7a1e7a4fcc4ddab599451480728b5784',
--USDT LP
'0xe827352a0552ffc835c181ab5bf1d7794038ec9f' --USDC LP
)
AND tx_hash IN (
SELECT
tx_hash
FROM
base_evt
)
AND tx_succeeded

{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
s.block_number,
s.block_timestamp,
s.tx_hash,
s.origin_function_signature,
s.origin_from_address,
s.origin_to_address,
s.contract_address AS bridge_address,
s.event_index,
s.event_name,
s.platform,
lp.amount,
lp.token AS token_address,
s.sender,
s.recipient AS receiver,
C.chain AS destination_chain,
s.destinationChainId AS destination_chain_id,
CASE
WHEN C.chain = 'solana' THEN utils.udf_hex_to_base58(CONCAT('0x', s.segmented_data [1] :: STRING))
WHEN C.chain = 'stellar' THEN s.segmented_data [1] :: STRING
ELSE CONCAT(
'0x',
SUBSTR(
s.segmented_data [1] :: STRING,
25,
40
)
)
END AS destination_chain_receiver,
CASE
WHEN C.chain = 'solana' THEN utils.udf_hex_to_base58(CONCAT('0x', s.segmented_data [3] :: STRING))
WHEN C.chain = 'stellar' THEN s.segmented_data [3] :: STRING
ELSE CONCAT(
'0x',
SUBSTR(
s.segmented_data [3] :: STRING,
25,
40
)
)
END AS destination_chain_token,
s.tx_succeeded,
s._log_id,
s._inserted_timestamp
FROM
base_evt s
INNER JOIN lp_evt lp
ON s.tx_hash = lp.tx_hash
AND s.block_number = lp.block_number
LEFT JOIN {{ ref('silver_bridge__allbridge_chain_id_seed') }} C
ON s.destinationChainId = C.chain_id qualify(ROW_NUMBER() over (PARTITION BY s._log_id
ORDER BY
s._inserted_timestamp DESC)) = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: 2
models:
- name: silver_bridge__allbridge_tokens_sent
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
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: DESTINATION_CHAIN_RECEIVER
tests:
- not_null
- name: AMOUNT
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]+
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ WITH base_evt AS (
event_index,
topics [0] :: STRING AS topic_0,
event_name,
DATA,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(segmented_data [24] :: STRING, 1, 40)) AS token_address,
decoded_flat :"affiliateFee" :: STRING AS affiliateFee,
decoded_flat :"metadata" :: STRING AS metadata,
TRY_TO_NUMBER(
Expand All @@ -42,7 +45,7 @@ WITH base_evt AS (
) AS makerOrderNonce,
decoded_flat :"order" :"makerSrc" :: STRING AS makerSrc,
decoded_flat :"order" :"orderAuthorityAddressDst" :: STRING AS orderAuthorityAddressDst,
decoded_flat :"order" :"receiverDst" :: STRING AS receiverDst,
CONCAT('0x', LEFT(segmented_data [28] :: STRING, 40)) AS receiverDst,
TRY_TO_NUMBER(
decoded_flat :"order" :"takeAmount" :: STRING
) AS takeAmount,
Expand All @@ -60,9 +63,6 @@ WITH base_evt AS (
decoded_flat,
event_removed,
tx_status,
DATA,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(segmented_data [24] :: STRING, 1, 40)) AS token_address,
_log_id,
_inserted_timestamp
FROM
Expand Down Expand Up @@ -97,8 +97,11 @@ SELECT
contract_address AS bridge_address,
NAME AS platform,
origin_from_address AS sender,
sender AS receiver,
receiver AS destination_chain_receiver,
receiverDst AS receiver,
CASE
WHEN takeChainId :: STRING = '7565164' THEN utils.udf_hex_to_base58(CONCAT('0x', segmented_data [28] :: STRING))
ELSE receiverDst
END AS destination_chain_receiver,
giveAmount AS amount,
takeChainId AS destination_chain_id,
CASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ WHERE
)
{% endif %}
),
allbridge_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 AS amount_unadj,
_log_id AS _id,
_inserted_timestamp
FROM
{{ ref('silver_bridge__allbridge_tokens_sent') }}

{% if is_incremental() and 'allbridge_v2' not in var('HEAL_MODELS') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
{% endif %}
),
axelar AS (
SELECT
block_number,
Expand Down Expand Up @@ -447,6 +484,11 @@ all_protocols AS (
FROM
allbridge
UNION ALL
SELECT
*
FROM
allbridge_v2
UNION ALL
SELECT
*
FROM
Expand Down Expand Up @@ -519,19 +561,21 @@ complete_bridge_activity AS (
receiver,
destination_chain_receiver,
CASE
WHEN platform IN (
'stargate',
'wormhole',
'meson'
WHEN CONCAT(platform, '-', version) IN (
'stargate-v1',
'wormhole-v1',
'meson-v1',
'allbridge-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 platform IN (
'stargate',
'wormhole',
'meson'
WHEN CONCAT(platform, '-', version) IN (
'stargate-v1',
'wormhole-v1',
'meson-v1',
'allbridge-v2'
) THEN LOWER(destination_chain)
WHEN d.chain IS NULL THEN LOWER(destination_chain)
ELSE LOWER(
Expand Down

0 comments on commit ee09b95

Please sign in to comment.