misc tweaks

This commit is contained in:
drethereum 2024-12-11 12:43:44 -07:00
parent f5b1975d24
commit 8a08e710c8
11 changed files with 861 additions and 92 deletions

View File

@ -0,0 +1,98 @@
destination_chain,standard_destination_chain
acala,acala
algorand,algorand
aptos,aptos
arbitrum,arbitrum
arbitrum nova,arbitrum nova
arbitrum one,arbitrum
archway,archway
astar,astar
aurora,aurora
aurora mainnet,aurora
avalanche,avalanche
avalanche c-chain,avalanche
base,base
bnb,bsc
bnb chain,bsc
bnb smart chain mainnet,bsc
boba bnb mainnet,boba
boba network,boba
bsc,bsc
canto,canto
carbon,carbon
celo,celo
celo mainnet,celo
coinweb,coinweb
conflux,conflux
conflux espace,conflux
crab network,crab
crescent,crescent
cronos mainnet,cronos
crypto chain,crypto
dfk chain,dfk
dogechain mainnet,dogechain
eos,eos
ethereum,ethereum
ethereum mainnet,ethereum
evmos,evmos
fantom,fantom
fantom opera,fantom
filecoin,filecoin
fuse,fuse
gnosis,gnosis
harmony mainnet shard 0,harmony
huobi eco chain mainnet,huobi eco
injective,injective
juno,juno
karura,karura
kava,kava
klaytn,klaytn
klaytn mainnet cypress,klaytn
kujira,kujira
linea,linea
manta,manta
mantle,mantle
metis,metis
metis andromeda mainnet,metis
moonbeam,moonbeam
moonriver,moonriver
nautilus,nautilus
near,near
neutron,neutron
oasis,oasis
okxchain mainnet,okxchain
ontology mainnet,ontology
op mainnet,optimism
opbnb,opbnb
optimism,optimism
osmosis,osmosis
polygon,polygon
polygon mainnet,polygon
polygon pos,polygon
polygon zkevm,polygon zkevm
ronin,ronin
scroll,scroll
secret-snip,secret
sei,sei
skale europa,skale europa
skale nebula,skale nebula
solana,solana
stargaze,stargaze
starknet,starknet
sui,sui
telos evm mainnet,telos
terra,terra
terra-2,terra2
terra2,terra2
tezos,tezos
tron,tron
umee,umee
waves,waves
xpla,xpla
xrpl,xrpl
zkfair,zkfair
zksync era,zksync era
zksync era mainnet,zksync era
zksync lite,zksync lite
zora,zora
zzz,zzz
1 destination_chain standard_destination_chain
2 acala acala
3 algorand algorand
4 aptos aptos
5 arbitrum arbitrum
6 arbitrum nova arbitrum nova
7 arbitrum one arbitrum
8 archway archway
9 astar astar
10 aurora aurora
11 aurora mainnet aurora
12 avalanche avalanche
13 avalanche c-chain avalanche
14 base base
15 bnb bsc
16 bnb chain bsc
17 bnb smart chain mainnet bsc
18 boba bnb mainnet boba
19 boba network boba
20 bsc bsc
21 canto canto
22 carbon carbon
23 celo celo
24 celo mainnet celo
25 coinweb coinweb
26 conflux conflux
27 conflux espace conflux
28 crab network crab
29 crescent crescent
30 cronos mainnet cronos
31 crypto chain crypto
32 dfk chain dfk
33 dogechain mainnet dogechain
34 eos eos
35 ethereum ethereum
36 ethereum mainnet ethereum
37 evmos evmos
38 fantom fantom
39 fantom opera fantom
40 filecoin filecoin
41 fuse fuse
42 gnosis gnosis
43 harmony mainnet shard 0 harmony
44 huobi eco chain mainnet huobi eco
45 injective injective
46 juno juno
47 karura karura
48 kava kava
49 klaytn klaytn
50 klaytn mainnet cypress klaytn
51 kujira kujira
52 linea linea
53 manta manta
54 mantle mantle
55 metis metis
56 metis andromeda mainnet metis
57 moonbeam moonbeam
58 moonriver moonriver
59 nautilus nautilus
60 near near
61 neutron neutron
62 oasis oasis
63 okxchain mainnet okxchain
64 ontology mainnet ontology
65 op mainnet optimism
66 opbnb opbnb
67 optimism optimism
68 osmosis osmosis
69 polygon polygon
70 polygon mainnet polygon
71 polygon pos polygon
72 polygon zkevm polygon zkevm
73 ronin ronin
74 scroll scroll
75 secret-snip secret
76 sei sei
77 skale europa skale europa
78 skale nebula skale nebula
79 solana solana
80 stargaze stargaze
81 starknet starknet
82 sui sui
83 telos evm mainnet telos
84 terra terra
85 terra-2 terra2
86 terra2 terra2
87 tezos tezos
88 tron tron
89 umee umee
90 waves waves
91 xpla xpla
92 xrpl xrpl
93 zkfair zkfair
94 zksync era zksync era
95 zksync era mainnet zksync era
96 zksync lite zksync lite
97 zora zora
98 zzz zzz

View File

@ -1,6 +1,6 @@
{% docs evm_bridge_table_doc %}
A convenience table that aggregates bridge activity from event_logs, traces and transfers, including bridge deposits and transfers sent from the following protocols: ACROSS, AXELAR, CELER, CBRIDGE, DLN, DEBRIDGE, HOP, MESON, STARGATE, SYMBIOSIS, SYNAPSE, WORMHOLE along with other helpful columns, including an amount USD where available. Note, this table only includes records for the protocols listed above with live, onchain bridge activity and may not represent the complete bridging picture.
A convenience table that aggregates bridge activity from event_logs, traces and transfers, including bridge deposits and transfers sent from the following protocols: AXELAR, HYPERLANE, ORBITER, SYMBIOSIS, SYNAPSE along with other helpful columns, including an amount USD where available. Note, this table only includes records for the protocols listed above with live, onchain bridge activity and may not represent the complete bridging picture.
{% enddocs %}

View File

@ -0,0 +1,51 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta ={
'database_tags':{
'table':{
'PROTOCOL': 'AXELAR, HYPERLANE, ORBITER, SYMBIOSIS, SYNAPSE',
'PURPOSE': 'BRIDGE'
} } }
) }}
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
event_index,
bridge_address,
event_name,
platform,
sender,
receiver,
destination_chain_receiver,
COALESCE(
standard_destination_chain,
b.destination_chain
) AS destination_chain,
destination_chain_id,
token_address,
token_symbol,
amount_unadj,
amount,
ROUND(
CASE
WHEN amount_usd < 1e+15 THEN amount_usd
ELSE NULL
END,
2
) AS amount_usd,
complete_bridge_activity_id AS ez_bridge_activity_id,
inserted_timestamp,
modified_timestamp
FROM
{{ ref('silver_bridge__complete_bridge_activity') }}
b
LEFT JOIN {{ ref('silver_bridge__standard_dst_chain_seed') }} C
ON b.destination_chain = C.destination_chain

View File

@ -0,0 +1,54 @@
version: 2
models:
- name: defi__ez_bridge_activity
description: '{{ doc("evm_bridge_table_doc") }}'
columns:
- name: BLOCK_NUMBER
description: '{{ doc("blast_block_number") }}'
- name: BLOCK_TIMESTAMP
description: '{{ doc("blast_block_timestamp") }}'
- name: TX_HASH
description: '{{ doc("blast_logs_tx_hash") }}'
- name: CONTRACT_ADDRESS
description: '{{ doc("blast_logs_contract_address") }}'
- name: EVENT_NAME
description: '{{ doc("blast_event_name") }}'
- name: EVENT_INDEX
description: '{{ doc("blast_event_index") }}'
- name: ORIGIN_FUNCTION_SIGNATURE
description: '{{ doc("nft_origin_sig") }}'
- name: ORIGIN_FROM_ADDRESS
description: '{{ doc("evm_bridge_origin_from") }}'
- name: ORIGIN_TO_ADDRESS
description: '{{ doc("blast_origin_from") }}'
- name: PLATFORM
description: '{{ doc("evm_bridge_platform") }}'
- name: SENDER
description: '{{ doc("evm_bridge_sender") }}'
- name: RECEIVER
description: '{{ doc("evm_bridge_receiver") }}'
- name: DESTINATION_CHAIN_RECEIVER
description: '{{ doc("evm_bridge_destination_chain_receiver") }}'
- name: DESTINATION_CHAIN
description: '{{ doc("evm_bridge_destination_chain") }}'
- name: DESTINATION_CHAIN_ID
description: '{{ doc("evm_bridge_destination_chain_id") }}'
- name: BRIDGE_ADDRESS
description: '{{ doc("evm_bridge_address") }}'
- name: TOKEN_ADDRESS
description: '{{ doc("evm_bridge_token_address") }}'
- name: TOKEN_SYMBOL
description: '{{ doc("evm_bridge_token_symbol") }}'
- name: AMOUNT_UNADJ
description: '{{ doc("evm_bridge_amount_unadj") }}'
- name: AMOUNT
description: '{{ doc("evm_bridge_amount") }}'
- name: AMOUNT_USD
description: '{{ doc("evm_bridge_amount_usd") }}'
- name: EZ_BRIDGE_ACTIVITY_ID
description: '{{ doc("pk") }}'
- name: INSERTED_TIMESTAMP
description: '{{ doc("inserted_timestamp") }}'
- name: MODIFIED_TIMESTAMP
description: '{{ doc("modified_timestamp") }}'

View File

@ -20,7 +20,7 @@ WITH base_evt AS (
event_index,
topics [0] :: STRING AS topic_0,
event_name,
decoded_flat AS decoded_log,
decoded_log,
TRY_TO_NUMBER(
decoded_log :"amount" :: STRING
) AS amount,
@ -36,7 +36,7 @@ WITH base_evt AS (
decoded_log,
event_removed,
CASE
WHEN tx_status = 'success' THEN TRUE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
@ -75,7 +75,7 @@ native_gas_paid AS (
event_index,
topics [0] :: STRING AS topic_0,
event_name,
decoded_flat AS decoded_log,
decoded_log,
TRY_TO_NUMBER(
decoded_log :"amount" :: STRING
) AS amount,
@ -93,7 +93,7 @@ native_gas_paid AS (
decoded_log,
event_removed,
CASE
WHEN tx_status = 'success' THEN TRUE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(

View File

@ -6,29 +6,8 @@
tags = ['curated','reorg']
) }}
WITH hyperlane_assets AS (
WITH dispatch AS (
SELECT
DISTINCT contract_address
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING IN (
'0xd229aacb94204188fe8042965fa6b269c62dc5818b21238779ab64bdd17efeec',
-- SentTransferRemote
'0xba20947a325f450d232530e5f5fce293e7963499d5309a07cee84a269f2f15a6' -- ReceivedTransferRemote
)
{% if is_incremental() %}
AND contract_address NOT IN (
SELECT
DISTINCT contract_address
FROM
{{ this }}
)
{% endif %}
),
dispatch AS (
SELECT
block_number,
block_timestamp,
@ -46,7 +25,7 @@ dispatch AS (
-- dst bridge token address, not recipient address
DATA,
CASE
WHEN tx_status = 'success' THEN TRUE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
@ -80,7 +59,7 @@ dispatch_id AS (
event_index,
topics [1] :: STRING AS messageId,
CASE
WHEN tx_status = 'success' THEN TRUE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
@ -118,7 +97,7 @@ gas_payment AS (
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [0] :: STRING)) AS gasAmount,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [1] :: STRING)) AS payment,
CASE
WHEN tx_status = 'success' THEN TRUE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
@ -131,7 +110,7 @@ gas_payment AS (
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] = '0x65695c3748edae85a24cc2c60b299b31f463050bc259150d2e5802ec8d11720a'
AND contract_address = ('0xB3fCcD379ad66CED0c91028520C64226611A48c9')
AND contract_address = LOWER('0xB3fCcD379ad66CED0c91028520C64226611A48c9')
AND tx_succeeded
{% if is_incremental() %}
@ -151,11 +130,11 @@ sent_transfer_remote AS (
tx_hash,
event_index,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS destination,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS receipient,
-- actual receipient
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS recipient,
-- actual recipient
TRY_TO_NUMBER(utils.udf_hex_to_int(DATA :: STRING)) AS amount,
CASE
WHEN tx_status = 'success' THEN TRUE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
@ -168,12 +147,6 @@ sent_transfer_remote AS (
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING = '0xd229aacb94204188fe8042965fa6b269c62dc5818b21238779ab64bdd17efeec'
AND contract_address IN (
SELECT
*
FROM
hyperlane_assets
)
AND tx_succeeded
{% if is_incremental() %}
@ -186,9 +159,8 @@ AND modified_timestamp >= (
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
-- this can be replaced by a 1 contract read of contracts in the hyperlane_asset (hyperlane_asset contracts have a wrappedtoken function)
token_transfer AS (
-- this matches tx_hash with each token's burn tx. this works since each contract only handles 1 token.
-- this matches tx_hash with each token's burn tx. this works since each contract only handles 1 token, but can be replaced by a 1 contract read of contracts in the hyperlane_asset (hyperlane_asset contracts have a wrappedtoken function)
SELECT
tx_hash,
contract_address AS token_address
@ -211,26 +183,28 @@ SELECT
origin_to_address,
tx_hash,
event_index,
contract_address,
contract_address AS bridge_address,
'Dispatch' AS event_name,
event_removed,
tx_succeeded,
-- from dispatch
sender,
-- src bridge token
receipient AS destination_chain_receiver,
recipient AS destination_chain_receiver,
-- dst bridge token
destination AS destinationChainId,
destination AS destination_chain_id,
-- from dispatch_id
messageId,
messageId AS message_id,
-- from gas_payment
gasAmount,
gasAmount AS gas_amount,
payment,
-- from sent_transfer_remote
receipient AS receiver,
recipient AS receiver,
-- actual receiver address
amount -- from token_transfer
amount,
-- from token_transfer
token_address,
'hyperlane' AS platform,
_log_id,
modified_timestamp
FROM
@ -238,3 +212,4 @@ FROM
INNER JOIN dispatch_id USING(tx_hash)
INNER JOIN gas_payment USING(tx_hash)
INNER JOIN token_transfer USING(tx_hash)
INNER JOIN sent_transfer_remote USING(tx_hash)

View File

@ -22,12 +22,12 @@ WITH bridge_router AS (
origin_to_address AS to_address,
origin_from_address AS from_address,
origin_from_address AS depositor,
TRY_TO_NUMBER(RIGHT(utils.udf_hex_to_int(DATA :: STRING), 4)) AS destinationChainId,
TRY_TO_NUMBER(utils.udf_hex_to_int(DATA :: STRING) * pow(10, -18)) AS amount,
RIGHT(utils.udf_hex_to_int(DATA :: STRING), 4) AS destinationChainId,
TRY_TO_NUMBER(utils.udf_hex_to_int(DATA :: STRING)) AS amount,
origin_from_address AS receipient,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS bridge_address,
CASE
WHEN tx_status = 'success' THEN TRUE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
@ -69,13 +69,11 @@ bridge_native AS (
et.to_address,
et.from_address,
et.from_address AS depositor,
TRY_TO_NUMBER(
RIGHT(
amount_precise_raw,
4
)
RIGHT(
amount_precise_raw,
4
) AS destinationChainId,
amount,
amount_precise_raw,
et.from_address AS receipient,
et.to_address AS bridge_address,
native_transfers_id,
@ -112,14 +110,13 @@ bridge_combined AS (
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
event_index,
event_name,
to_address,
from_address,
depositor,
destinationChainId AS orbiter_chain_id,
amount,
amount AS amount_unadj,
receipient,
bridge_address,
tx_succeeded,
@ -135,14 +132,13 @@ bridge_combined AS (
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
NULL AS event_index,
NULL AS event_name,
to_address,
from_address,
depositor,
destinationChainId AS orbiter_chain_id,
amount,
amount_precise_raw AS amount_unadj,
receipient,
bridge_address,
TRUE AS tx_succeeded,
@ -158,17 +154,16 @@ SELECT
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
event_index,
event_name,
to_address,
from_address,
depositor,
depositor AS sender,
orbiter_chain_id,
s.chainid AS destination_chain_id,
s.name AS destination_chain,
amount,
receipient,
amount_unadj,
receipient AS receiver,
receipient AS destination_chain_receiver,
bridge_address,
'orbiter finance' AS platform,
@ -179,5 +174,6 @@ SELECT
modified_timestamp
FROM
bridge_combined b
LEFT JOIN {{ ref('silver_bridge__orbiter_bridge_seed') }} s
LEFT JOIN {{ ref('silver_bridge__orbiter_bridge_seed') }}
s
ON b.orbiter_chain_id :: STRING = s.identificationcode :: STRING

View File

@ -0,0 +1,509 @@
-- depends_on: {{ ref('silver__complete_token_prices') }}
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = ['block_number','platform','version'],
cluster_by = ['block_timestamp::DATE','platform'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_from_address, origin_to_address, origin_function_signature, bridge_address, sender, receiver, destination_chain_receiver, destination_chain_id, destination_chain, token_address, token_symbol), SUBSTRING(origin_function_signature, bridge_address, sender, receiver, destination_chain_receiver, destination_chain, token_address, token_symbol)",
tags = ['curated','reorg','heal']
) }}
WITH axelar 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,
NULL AS destination_chain_id,
destination_chain,
token_address,
token_symbol,
amount AS amount_unadj,
_log_id AS _id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('silver_bridge__axelar_contractcallwithtoken') }}
{% if is_incremental() and 'axelar' not in var('HEAL_MODELS') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
{% endif %}
),
hyperlane 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,
NULL AS destination_chain,
token_address,
NULL AS token_symbol,
amount AS amount_unadj,
_log_id AS _id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('silver_bridge__hyperlane_bridge') }}
{% if is_incremental() and 'hyperlane' not in var('HEAL_MODELS') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
{% endif %}
),
orbiter 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,
_id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('silver_bridge__orbiter_bridgerequest') }}
{% if is_incremental() and 'orbiter' not in var('HEAL_MODELS') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
{% endif %}
),
symbiosis 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,
NULL AS destination_chain,
token_address,
NULL AS token_symbol,
amount AS amount_unadj,
_log_id AS _id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('silver_bridge__symbiosis_synthesizerequest') }}
{% if is_incremental() and 'symbiosis' not in var('HEAL_MODELS') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
{% endif %}
),
synapse 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,
NULL AS destination_chain,
token_address,
NULL AS token_symbol,
amount AS amount_unadj,
_log_id AS _id,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('silver_bridge__synapse_tokenredeem') }}
{% if is_incremental() and 'synapse' not in var('HEAL_MODELS') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
{% endif %}
),
all_protocols AS (
SELECT
*
FROM
axelar
UNION ALL
SELECT
*
FROM
hyperlane
UNION ALL
SELECT
*
FROM
orbiter
UNION ALL
SELECT
*
FROM
symbiosis
UNION ALL
SELECT
*
FROM
synapse
),
complete_bridge_activity 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,
CASE
WHEN platform IN (
'orbiter'
) 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 (
'orbiter'
) THEN LOWER(destination_chain)
WHEN d.chain IS NULL THEN LOWER(destination_chain)
ELSE LOWER(
d.chain
)
END AS destination_chain,
b.token_address,
CASE
WHEN platform = 'axelar' THEN COALESCE(
C.token_symbol,
b.token_symbol
)
ELSE C.token_symbol
END AS token_symbol,
C.token_decimals AS token_decimals,
amount_unadj,
CASE
WHEN C.token_decimals IS NOT NULL THEN (amount_unadj / pow(10, C.token_decimals))
ELSE amount_unadj
END AS amount,
CASE
WHEN C.token_decimals IS NOT NULL THEN ROUND(
amount * p.price,
2
)
ELSE NULL
END AS amount_usd,
_id,
b._inserted_timestamp
FROM
all_protocols b
LEFT JOIN {{ ref('silver__contracts') }} C
ON b.token_address = C.contract_address
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
p
ON b.token_address = p.token_address
AND DATE_TRUNC(
'hour',
block_timestamp
) = p.hour
LEFT JOIN {{ source(
'external_gold_defillama',
'dim_chains'
) }}
d
ON d.chain_id :: STRING = b.destination_chain_id :: STRING
OR LOWER(
d.chain
) = LOWER(
b.destination_chain
)
),
{% if is_incremental() and var(
'HEAL_MODEL'
) %}
heal_model 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,
destination_chain,
t0.token_address,
C.token_symbol AS token_symbol,
C.token_decimals AS token_decimals,
amount_unadj,
CASE
WHEN C.token_decimals IS NOT NULL THEN (amount_unadj / pow(10, C.token_decimals))
ELSE amount_unadj
END AS amount_heal,
CASE
WHEN C.token_decimals IS NOT NULL THEN amount_heal * p.price
ELSE NULL
END AS amount_usd_heal,
_id,
t0._inserted_timestamp
FROM
{{ this }}
t0
LEFT JOIN {{ ref('silver__contracts') }} C
ON t0.token_address = C.contract_address
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
p
ON t0.token_address = p.token_address
AND DATE_TRUNC(
'hour',
block_timestamp
) = p.hour
WHERE
CONCAT(
t0.block_number,
'-',
t0.platform,
'-',
t0.version
) IN (
SELECT
CONCAT(
t1.block_number,
'-',
t1.platform,
'-',
t1.version
)
FROM
{{ this }}
t1
WHERE
t1.token_decimals IS NULL
AND t1._inserted_timestamp < (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
AND EXISTS (
SELECT
1
FROM
{{ ref('silver__contracts') }} C
WHERE
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
AND C.token_decimals IS NOT NULL
AND C.contract_address = t1.token_address)
GROUP BY
1
)
OR CONCAT(
t0.block_number,
'-',
t0.platform,
'-',
t0.version
) IN (
SELECT
CONCAT(
t2.block_number,
'-',
t2.platform,
'-',
t2.version
)
FROM
{{ this }}
t2
WHERE
t2.amount_usd IS NULL
AND t2._inserted_timestamp < (
SELECT
MAX(
_inserted_timestamp
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
AND EXISTS (
SELECT
1
FROM
{{ ref('silver__complete_token_prices') }}
p
WHERE
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
AND p.price IS NOT NULL
AND p.token_address = t2.token_address
AND p.hour = DATE_TRUNC(
'hour',
t2.block_timestamp
)
)
GROUP BY
1
)
),
{% endif %}
FINAL AS (
SELECT
*
FROM
complete_bridge_activity
{% if is_incremental() and var(
'HEAL_MODEL'
) %}
UNION ALL
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,
destination_chain,
token_address,
token_symbol,
token_decimals,
amount_unadj,
amount_heal AS amount,
amount_usd_heal AS amount_usd,
_id,
_inserted_timestamp
FROM
heal_model
{% endif %}
)
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,
destination_chain,
token_address,
token_symbol,
token_decimals,
amount_unadj,
amount,
amount_usd,
_id,
_inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(
['_id']
) }} AS complete_bridge_activity_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
FINAL
WHERE
destination_chain <> 'blast' qualify (ROW_NUMBER() over (PARTITION BY _id
ORDER BY
_inserted_timestamp DESC)) = 1

View File

@ -0,0 +1,81 @@
version: 2
models:
- name: silver_bridge__complete_bridge_activity
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _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:
where: VERSION <> 'v1-native' AND PLATFORM NOT IN ('wormhole','meson')
- name: EVENT_NAME
tests:
- not_null:
where: VERSION <> 'v1-native' AND PLATFORM NOT IN ('wormhole','meson')
- name: BRIDGE_ADDRESS
tests:
- not_null
- dbt_expectations.expect_column_values_to_match_regex:
regex: 0[xX][0-9a-fA-F]+
- name: DESTINATION_CHAIN
- name: DESTINATION_CHAIN_RECEIVER
tests:
- not_null
- name: PLATFORM
- not_null
- name: VERSION
- not_null
- 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: 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: _INSERTED_TIMESTAMP
tests:
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3

View File

@ -20,28 +20,32 @@ WITH base_evt AS (
event_index,
topics [0] :: STRING AS topic_0,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
'SynthesizeRequest' as event_name,
TRY_TO_NUMBER(utils.udf_hex_to_int(
segmented_data[2] :"amount" :: STRING
)) AS amount,
TRY_TO_NUMBER(utils.udf_hex_to_int(
topics[2] :"chainID" :: STRING
)) AS chainID,
concat('0x', substr(topics[1] :: STRING, 27, 40)) AS from_address,
segmented_data[0] :: STRING AS id,
concat('0x', substr(topics[3] :: STRING, 27, 40)) AS revertableAddress,
concat('0x', substr(segmented_data[1] :: STRING, 25, 40)) AS to_address,
segmented_data[3] :: STRING AS token,
'SynthesizeRequest' AS event_name,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
segmented_data [2] :: STRING
)
) AS amount,
TRY_TO_NUMBER(
utils.udf_hex_to_int(
topics [2] :: STRING
)
) AS chainID,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS from_address,
segmented_data [0] :: STRING AS id,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS revertableAddress,
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS to_address,
segmented_data [3] :: STRING AS token,
CASE
WHEN tx_status = 'success' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash,
'-',
event_index
) AS _log_id,
modified_timestamp
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash,
'-',
event_index
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE

View File

@ -17,6 +17,7 @@ WITH base_evt AS (
tx_hash,
contract_address,
event_index,
topics,
topics [0] :: STRING AS topic_0,
topics [1] :: STRING AS topic_1,
topics [2] :: STRING AS topic_2,
@ -24,7 +25,7 @@ WITH base_evt AS (
DATA,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CASE
WHEN tx_status = 'success' THEN TRUE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
@ -76,7 +77,7 @@ redeem_swap AS (
WHEN topic_0 = '0x91f25e9be0134ec851830e0e76dc71e06f9dade75a9b84e9524071dbbc319425' THEN 'TokenRedeemAndSwap'
WHEN topic_0 = '0x79c15604b92ef54d3f61f0c40caab8857927ca3d5092367163b4562c1699eb5f' THEN 'TokenDepositAndSwap'
END AS event_name,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS to_address,
CONCAT('0x', SUBSTR(topic_1, 27, 40)) AS to_address,
segmented_data,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [0] :: STRING)) AS chainId,
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS token,
@ -111,7 +112,7 @@ redeem_remove AS (
contract_address,
event_index,
'TokenRedeemAndRemove' AS event_name,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS to_address,
CONCAT('0x', SUBSTR(topic_1, 27, 40)) AS to_address,
segmented_data,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [0] :: STRING)) AS chainId,
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS token,
@ -144,7 +145,7 @@ redeem_only AS (
WHEN topic_0 = '0xda5273705dbef4bf1b902a131c2eac086b7e1476a8ab0cb4da08af1fe1bd8e3b' THEN 'TokenDeposit'
WHEN topic_0 = '0x8e57e8c5fea426159af69d47eda6c5052c7605c9f70967cf749d4aa55b70b499' THEN 'TokenRedeemV2'
END AS event_name,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS to_address,
CONCAT('0x', SUBSTR(topic_1, 27, 40)) AS to_address,
segmented_data,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [0] :: STRING)) AS chainId,
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS token,