-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sol decoding * allbridge_v2 * qualify * inner
- Loading branch information
1 parent
3ffd029
commit ee09b95
Showing
5 changed files
with
303 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
161 changes: 161 additions & 0 deletions
161
models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
69 changes: 69 additions & 0 deletions
69
models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters