AN-5312/blast-bridging (#89)

* synapse

* WIP bridge models

* orbiter and synapse

* misc tweaks

* across

* layerzero temp

* tweaks

* docs

* model updates

* orbiter seed
This commit is contained in:
drethereum 2024-12-16 15:57:46 -07:00 committed by GitHub
parent f29db2ed0c
commit 43c9cc5168
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 2720 additions and 1 deletions

View File

@ -0,0 +1,94 @@
chain,eid
Ape, 30312
Arbitrum, 30110
Arbitrum Nova, 30175
Astar, 30210
Astar zkEVM, 30257
Avalanche, 30106
Base, 30184
Bevm, 30317
Binance Smart Chain, 30102
Bitlayer, 30314
Blast, 30243
Bob, 30279
Canto, 30159
Celo, 30125
Codex, 30323
Conflux eSpace, 30212
Core Blockchain, 30153
Cyber, 30283
DOS Chain, 30149
DeFi Kingdoms, 30115
Degen, 30267
Dexalot Subnet, 30118
Dm2verse, 30315
EBI, 30282
Edu, 30328
Ethereum, 30101
Etherlink, 30292
Fantom, 30112
Flare, 30295
Fraxtal, 30255
Fuse, 30138
Gnosis, 30145
Gravity, 30294
Harmony, 30116
Hedera, 30316
Hemi, 30329
Homeverse, 30265
Horizen EON, 30215
Hubble, 30182
Iota, 30284
Japan Open Chain, 30285
Kaia, 30150
Kava, 30177
Lightlink, 30309
Linea, 30183
Lisk, 30321
Loot, 30197
Lyra, 30311
Manta, 30217
Mantle, 30181
Masa, 30263
Meritcircle, 30198
Merlin, 30266
Meter, 30176
Metis, 30151
Mode, 30260
Moonbeam, 30126
Moonriver, 30167
Morph, 30322
Near Aurora, 30211
OKXChain, 30155
Optimism, 30111
Orderly, 30213
Peaq, 30302
Polygon, 30109
Polygon zkEVM, 30158
Rari Chain, 30235
Reya, 30313
Sanko, 30278
Scroll, 30214
Sei, 30280
Shimmer, 30230
Skale, 30273
Solana, 30168
Superposition, 30327
Taiko, 30290
TelosEVM, 30199
Tenet, 30173
Tiltyard, 30238
Tron, 30420
Viction, 30196
Worldchain, 30319
X Layer, 30274
XChain, 30291
XPLA, 30216
Xai, 30236
Zircuit, 30303
Zora, 30195
inEVM, 30234
opBNB, 30202
re.al, 30237
zkLink, 30301
zkSync Era, 30165
1 chain eid
2 Ape 30312
3 Arbitrum 30110
4 Arbitrum Nova 30175
5 Astar 30210
6 Astar zkEVM 30257
7 Avalanche 30106
8 Base 30184
9 Bevm 30317
10 Binance Smart Chain 30102
11 Bitlayer 30314
12 Blast 30243
13 Bob 30279
14 Canto 30159
15 Celo 30125
16 Codex 30323
17 Conflux eSpace 30212
18 Core Blockchain 30153
19 Cyber 30283
20 DOS Chain 30149
21 DeFi Kingdoms 30115
22 Degen 30267
23 Dexalot Subnet 30118
24 Dm2verse 30315
25 EBI 30282
26 Edu 30328
27 Ethereum 30101
28 Etherlink 30292
29 Fantom 30112
30 Flare 30295
31 Fraxtal 30255
32 Fuse 30138
33 Gnosis 30145
34 Gravity 30294
35 Harmony 30116
36 Hedera 30316
37 Hemi 30329
38 Homeverse 30265
39 Horizen EON 30215
40 Hubble 30182
41 Iota 30284
42 Japan Open Chain 30285
43 Kaia 30150
44 Kava 30177
45 Lightlink 30309
46 Linea 30183
47 Lisk 30321
48 Loot 30197
49 Lyra 30311
50 Manta 30217
51 Mantle 30181
52 Masa 30263
53 Meritcircle 30198
54 Merlin 30266
55 Meter 30176
56 Metis 30151
57 Mode 30260
58 Moonbeam 30126
59 Moonriver 30167
60 Morph 30322
61 Near Aurora 30211
62 OKXChain 30155
63 Optimism 30111
64 Orderly 30213
65 Peaq 30302
66 Polygon 30109
67 Polygon zkEVM 30158
68 Rari Chain 30235
69 Reya 30313
70 Sanko 30278
71 Scroll 30214
72 Sei 30280
73 Shimmer 30230
74 Skale 30273
75 Solana 30168
76 Superposition 30327
77 Taiko 30290
78 TelosEVM 30199
79 Tenet 30173
80 Tiltyard 30238
81 Tron 30420
82 Viction 30196
83 Worldchain 30319
84 X Layer 30274
85 XChain 30291
86 XPLA 30216
87 Xai 30236
88 Zircuit 30303
89 Zora 30195
90 inEVM 30234
91 opBNB 30202
92 re.al 30237
93 zkLink 30301
94 zkSync Era 30165

View File

@ -0,0 +1,52 @@
name,chainid,identificationcode
ethereum,1,9001
arbitrum,42161,9002
zksync_lite,zksync,9003
starknet,SN_MAIN,9004
polygon,137,9006
optimism,10,9007
immutable_x,immutableX,9008
loopring,loopring,9009
metis,1088,9010
zkspace,ZKSpace,9012
zksynce_era,324,9014
bsc,56,9015
arbitrum_nova,42170,9016
polygon_zkevm,1101,9017
scroll,534352,9019
taiko,167000,9020
base,8453,9021
linea,59144,9023
mantle,5000,9024
opbnb,204,9025
x_layer,196,9027
zora,7777777,9030
manta,169,9031
kroma,255,9036
zkfair,42766,9038
blast,81457,9040
zetachain,7000,9041
b2_network,223,9046
mode,34443,9047
zklink_nova,810180,9048
solana,SOLANA_MAIN,9051
morph,2818,9052
proof_of_play_apex,70700,9053
merlin,4200,9054
bevm,11501,9055
ton,TON,9056
bob,60808,9057
core_blockchain,1116,9058
bitlayer,200901,9059
bouncebit,6001,9064
eclipse,ECLIPSE_MAIN,9065
optopia,62050,9066
cyber,7560,9067
mint,185,9068
tron,728126428,9079
matchain,698,9084
lisk,1135,9086
redstone,690,9087
kaia,8217,9089
fuel,FUEL_MAIN,9094
worldchain,480,9095
1 name chainid identificationcode
2 ethereum 1 9001
3 arbitrum 42161 9002
4 zksync_lite zksync 9003
5 starknet SN_MAIN 9004
6 polygon 137 9006
7 optimism 10 9007
8 immutable_x immutableX 9008
9 loopring loopring 9009
10 metis 1088 9010
11 zkspace ZKSpace 9012
12 zksynce_era 324 9014
13 bsc 56 9015
14 arbitrum_nova 42170 9016
15 polygon_zkevm 1101 9017
16 scroll 534352 9019
17 taiko 167000 9020
18 base 8453 9021
19 linea 59144 9023
20 mantle 5000 9024
21 opbnb 204 9025
22 x_layer 196 9027
23 zora 7777777 9030
24 manta 169 9031
25 kroma 255 9036
26 zkfair 42766 9038
27 blast 81457 9040
28 zetachain 7000 9041
29 b2_network 223 9046
30 mode 34443 9047
31 zklink_nova 810180 9048
32 solana SOLANA_MAIN 9051
33 morph 2818 9052
34 proof_of_play_apex 70700 9053
35 merlin 4200 9054
36 bevm 11501 9055
37 ton TON 9056
38 bob 60808 9057
39 core_blockchain 1116 9058
40 bitlayer 200901 9059
41 bouncebit 6001 9064
42 eclipse ECLIPSE_MAIN 9065
43 optopia 62050 9066
44 cyber 7560 9067
45 mint 185 9068
46 tron 728126428 9079
47 matchain 698 9084
48 lisk 1135 9086
49 redstone 690 9087
50 kaia 8217 9089
51 fuel FUEL_MAIN 9094
52 worldchain 480 9095

View File

@ -0,0 +1,139 @@
destination_chain,standard_destination_chain
acala,acala
algorand,algorand
aptos,aptos
arbitrum,arbitrum
arbitrum nova,arbitrum nova
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
bob,boba
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
core blockchain mainnet,core
crab network,crab
crescent,crescent
cronos mainnet,cronos
crypto chain,crypto
cyber,cyber
cyber mainnet,cyber
dfk chain,dfk
dogechain mainnet,dogechain
eos,eos
endurance smart chain mainnet,endurance smart chain
ethereum,ethereum
ethereum mainnet,ethereum
everclear mainnet,everclear
evmos,evmos
fantom,fantom
fantom opera,fantom
filecoin,filecoin
flare mainnet,flare
fraxchain mainnet,fraxchain
fuse,fuse
fuse mainnet,fuse
gnosis,gnosis
gravity,gravity
gravity alpha mainnet,gravity
harmony mainnet shard 0,harmony
huobi eco chain mainnet,huobi eco
inevm,inevm
inevm mainnet,inevm
injective,injective
immutable,immutable x
immutable_x,immutable x
juno,juno
karura,karura
kava,kava
klaytn,klaytn
klaytn mainnet cypress,klaytn
kujira,kujira
linea,linea
lukso mainnet,lukso
manta,manta
manta pacific mainnet,manta
mantle,mantle
metis,metis
metis andromeda mainnet,metis
mint,mint
mint mainnet,mint
moonbeam,moonbeam
moonriver,moonriver
nautilus,nautilus
near,near
neutron,neutron
oasis,oasis
okbchain mainnet,okbchain
okxchain mainnet,okxchain
ontology mainnet,ontology
op mainnet,optimism
opbnb,opbnb
optimism,optimism
osmosis,osmosis
orderly mainnet,orderly
polygon,polygon
polygon mainnet,polygon
polygon pos,polygon
polygon zkevm,polygon zkevm
polygon_zkevm,polygon zkevm
proof of play - apex,proof of play apex
proof_of_play_apex,proof of play apex
ronin,ronin
scroll,scroll
secret-snip,secret
sei,sei
sei network,sei
skale europa,skale europa
skale nebula,skale nebula
solana,solana
stargaze,stargaze
starknet,starknet
sui,sui
taiko,taiko
taiko mainnet,taiko
telos evm mainnet,telos
terra,terra
terra-2,terra2
terra2,terra2
tezos,tezos
tron,tron
umee,umee
waves,waves
world chain,worldchain
worldchain,worldchain
xpla,xpla
xrpl,xrpl
x layer,x layer
x_layer,x layer
zkfair,zkfair
zetachain,zetachain
zetachain mainnet,zetachain
zircuit,zircuit
zircuit mainnet,zircuit
zklink_nova,zklink nova
zksync era,zksync era
zksync era mainnet,zksync era
zksynce_era,zksync era
zksync lite,zksync lite
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_nova arbitrum nova
8 arbitrum one arbitrum
9 archway archway
10 astar astar
11 aurora aurora
12 aurora mainnet aurora
13 avalanche avalanche
14 avalanche c-chain avalanche
15 base base
16 bnb bsc
17 bnb chain bsc
18 bnb smart chain mainnet bsc
19 bob boba
20 boba bnb mainnet boba
21 boba network boba
22 bsc bsc
23 canto canto
24 carbon carbon
25 celo celo
26 celo mainnet celo
27 coinweb coinweb
28 conflux conflux
29 conflux espace conflux
30 core blockchain mainnet core
31 crab network crab
32 crescent crescent
33 cronos mainnet cronos
34 crypto chain crypto
35 cyber cyber
36 cyber mainnet cyber
37 dfk chain dfk
38 dogechain mainnet dogechain
39 eos eos
40 endurance smart chain mainnet endurance smart chain
41 ethereum ethereum
42 ethereum mainnet ethereum
43 everclear mainnet everclear
44 evmos evmos
45 fantom fantom
46 fantom opera fantom
47 filecoin filecoin
48 flare mainnet flare
49 fraxchain mainnet fraxchain
50 fuse fuse
51 fuse mainnet fuse
52 gnosis gnosis
53 gravity gravity
54 gravity alpha mainnet gravity
55 harmony mainnet shard 0 harmony
56 huobi eco chain mainnet huobi eco
57 inevm inevm
58 inevm mainnet inevm
59 injective injective
60 immutable immutable x
61 immutable_x immutable x
62 juno juno
63 karura karura
64 kava kava
65 klaytn klaytn
66 klaytn mainnet cypress klaytn
67 kujira kujira
68 linea linea
69 lukso mainnet lukso
70 manta manta
71 manta pacific mainnet manta
72 mantle mantle
73 metis metis
74 metis andromeda mainnet metis
75 mint mint
76 mint mainnet mint
77 moonbeam moonbeam
78 moonriver moonriver
79 nautilus nautilus
80 near near
81 neutron neutron
82 oasis oasis
83 okbchain mainnet okbchain
84 okxchain mainnet okxchain
85 ontology mainnet ontology
86 op mainnet optimism
87 opbnb opbnb
88 optimism optimism
89 osmosis osmosis
90 orderly mainnet orderly
91 polygon polygon
92 polygon mainnet polygon
93 polygon pos polygon
94 polygon zkevm polygon zkevm
95 polygon_zkevm polygon zkevm
96 proof of play - apex proof of play apex
97 proof_of_play_apex proof of play apex
98 ronin ronin
99 scroll scroll
100 secret-snip secret
101 sei sei
102 sei network sei
103 skale europa skale europa
104 skale nebula skale nebula
105 solana solana
106 stargaze stargaze
107 starknet starknet
108 sui sui
109 taiko taiko
110 taiko mainnet taiko
111 telos evm mainnet telos
112 terra terra
113 terra-2 terra2
114 terra2 terra2
115 tezos tezos
116 tron tron
117 umee umee
118 waves waves
119 world chain worldchain
120 worldchain worldchain
121 xpla xpla
122 xrpl xrpl
123 x layer x layer
124 x_layer x layer
125 zkfair zkfair
126 zetachain zetachain
127 zetachain mainnet zetachain
128 zircuit zircuit
129 zircuit mainnet zircuit
130 zklink_nova zklink nova
131 zksync era zksync era
132 zksync era mainnet zksync era
133 zksynce_era zksync era
134 zksync lite zksync lite
135 zksync_lite zksync lite
136 zora zora
137 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: ACROSS, AXELAR, HYPERLANE, LAYERZERO, 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

@ -44,6 +44,7 @@ There is more information on how to use dbt docs in the last section of this doc
### DeFi Tables (blast.defi)
- [ez_dex_swaps](https://flipsidecrypto.github.io/blast-models/#!/model/model.blast_models.defi__ez_dex_swaps)
- [dim_dex_liquidity_pools](https://flipsidecrypto.github.io/blast-models/#!/model/model.blast_models.defi__dim_dex_liquidity_pools)
- [ez_bridge_activity](https://flipsidecrypto.github.io/blast-models/#!/model/model.blast_models.defi__ez_bridge_activity)
### Stats Tables (blast.stats)
- [ez_core_metrics_hourly](https://flipsidecrypto.github.io/blast-models/#!/model/model.blast_models.stats__ez_core_metrics_hourly)

View File

@ -0,0 +1,51 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta ={
'database_tags':{
'table':{
'PROTOCOL': 'ACROSS, AXELAR, HYPERLANE, LAYERZERO, 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

@ -0,0 +1,108 @@
{{ 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,
'across-v3' AS NAME,
topics,
DATA,
event_index,
event_name,
utils.udf_hex_to_int(
topics [1] :: STRING
) AS destinationChainId,
utils.udf_hex_to_int(
topics [2] :: STRING
) AS depositId,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS depositor,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS inputToken,
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS outputToken,
TRY_TO_NUMBER(utils.udf_hex_to_int(
segmented_data [2] :: STRING
)) AS inputAmount,
TRY_TO_NUMBER(utils.udf_hex_to_int(
segmented_data [3] :: STRING
)) AS outputAmount,
utils.udf_hex_to_int(
segmented_data [4] :: STRING
) AS quotedTimestamp,
utils.udf_hex_to_int(
segmented_data [5] :: STRING
) AS fillDeadline,
utils.udf_hex_to_int(
segmented_data [6] :: STRING
) AS exclusivityDeadline,
CONCAT('0x', SUBSTR(segmented_data [7] :: STRING, 25, 40)) AS recipient,
CONCAT('0x', SUBSTR(segmented_data [8] :: STRING, 25, 40)) AS exclusiveRelayer,
segmented_data [9] :: STRING AS message,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__ez_decoded_event_logs') }}
WHERE
topics [0] :: STRING = '0xa123dc29aebf7d0c3322c8eeb5b999e859f39937950ed31056532713d0de396f'
AND contract_address = '0x2d509190ed0172ba588407d4c2df918f955cc6e1'
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,
topics,
event_name,
tx_succeeded,
contract_address AS bridge_address,
NAME AS platform,
depositor AS sender,
recipient AS receiver,
recipient AS destination_chain_receiver,
destinationChainId AS destination_chain_id,
inputAmount AS amount,
inputToken AS token_address,
depositId AS deposit_id,
message,
exclusiveRelayer AS exclusive_relayer,
exclusivityDeadline AS exclusivity_deadline,
fillDeadline AS fill_deadline,
outputAmount AS output_amount,
outputToken AS output_token,
_log_id,
modified_timestamp
FROM
base_evt

View File

@ -0,0 +1,72 @@
version: 2
models:
- name: silver_bridge__across_v3fundsdeposited
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
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
- 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]+

View File

@ -0,0 +1,239 @@
{{ 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,
'axelar' AS NAME,
event_index,
topics [0] :: STRING AS topic_0,
event_name,
decoded_log,
TRY_TO_NUMBER(
decoded_log :"amount" :: STRING
) AS amount,
decoded_log :"destinationChain" :: STRING AS destinationChain,
LOWER(
decoded_log :"destinationContractAddress" :: STRING
) AS destinationContractAddress,
decoded_log :"payload" :: STRING AS payload,
origin_from_address AS recipient,
decoded_log :"payloadHash" :: STRING AS payloadHash,
decoded_log :"sender" :: STRING AS sender,
decoded_log :"symbol" :: STRING AS symbol,
decoded_log,
event_removed,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__ez_decoded_event_logs') }}
WHERE
topics [0] :: STRING = '0x7e50569d26be643bda7757722291ec66b1be66d8283474ae3fab5a98f878a7a2'
AND contract_address = LOWER('0xe432150cce91c13a887f7D836923d5597adD8E31')
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 %}
),
native_gas_paid AS (
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address,
'axelar' AS NAME,
event_index,
topics [0] :: STRING AS topic_0,
event_name,
decoded_log,
TRY_TO_NUMBER(
decoded_log :"amount" :: STRING
) AS amount,
decoded_log :"destinationChain" :: STRING AS destinationChain,
LOWER(
decoded_log :"destinationAddress" :: STRING
) AS destinationAddress,
TRY_TO_NUMBER(
decoded_log :"gasFeeAmount" :: STRING
) AS gasFeeAmount,
decoded_log :"payloadHash" :: STRING AS payloadHash,
decoded_log :"refundAddress" :: STRING AS refundAddress,
decoded_log :"sourceAddress" :: STRING AS sourceAddress,
decoded_log :"symbol" :: STRING AS symbol,
decoded_log,
event_removed,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__ez_decoded_event_logs') }}
WHERE
topics [0] :: STRING = '0x999d431b58761213cf53af96262b67a069cbd963499fd8effd1e21556217b841'
AND contract_address = '0x2d5d7d31f671f86c782533cc367f14109a082712'
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 %}
),
transfers AS (
SELECT
block_number,
tx_hash,
event_index,
contract_address AS token_address,
_log_id,
_inserted_timestamp
FROM
{{ ref('silver__transfers') }}
WHERE
from_address = '0x492751ec3c57141deb205ec2da8bfcb410738630'
AND to_address IN (
LOWER('0xe432150cce91c13a887f7D836923d5597adD8E31'),
'0x0000000000000000000000000000000000000000'
)
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT
MAX(modified_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
),
FINAL AS (
SELECT
b.block_number,
b.block_timestamp,
b.origin_function_signature,
b.origin_from_address,
b.origin_to_address,
b.tx_hash,
b.event_index,
b.topic_0,
b.event_name,
b.event_removed,
b.tx_succeeded,
b.contract_address AS bridge_address,
b.name AS platform,
b.origin_from_address AS sender,
CASE
WHEN b.recipient = '0x0000000000000000000000000000000000000000' THEN refundAddress
ELSE b.recipient
END AS receiver,
CASE
WHEN LOWER(
b.destinationChain
) = 'avalanche' THEN 'avalanche c-chain'
WHEN LOWER(
b.destinationChain
) = 'binance' THEN 'bnb smart chain mainnet'
WHEN LOWER(
b.destinationChain
) = 'celo' THEN 'celo mainnet'
WHEN LOWER(
b.destinationChain
) = 'ethereum' THEN 'ethereum mainnet'
WHEN LOWER(
b.destinationChain
) = 'fantom' THEN 'fantom opera'
WHEN LOWER(
b.destinationChain
) = 'polygon' THEN 'polygon mainnet'
ELSE LOWER(
b.destinationChain
)
END AS destination_chain,
b.destinationContractAddress AS destination_contract_address,
CASE
WHEN destination_chain IN (
'arbitrum',
'avalanche c-chain',
'base',
'bnb smart chain mainnet',
'celo mainnet',
'centrifuge',
'ethereum mainnet',
'fantom opera',
'filecoin',
'fraxtal',
'immutable',
'kava',
'linea',
'mantle',
'moonbeam',
'neutron',
'optimism',
'osmosis',
'polygon mainnet',
'scroll'
) THEN receiver
ELSE destination_contract_address
END AS destination_chain_receiver,
b.amount,
b.payload,
b.payloadHash AS payload_hash,
b.symbol AS token_symbol,
t.token_address,
b._log_id,
b.modified_timestamp
FROM
base_evt b
INNER JOIN transfers t
ON b.block_number = t.block_number
AND b.tx_hash = t.tx_hash
LEFT JOIN native_gas_paid n
ON n.block_number = b.block_number
AND n.tx_hash = b.tx_hash
)
SELECT
*
FROM
FINAL qualify (ROW_NUMBER() over (PARTITION BY _log_id
ORDER BY
modified_timestamp DESC)) = 1

View File

@ -0,0 +1,72 @@
version: 2
models:
- name: silver_bridge__axelar_contractcallwithtoken
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
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
- 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]+

View File

@ -0,0 +1,207 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['curated','reorg']
) }}
WITH dispatch AS (
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
event_removed,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS src_bridge_token,
-- src bridge token address, not user address
TRY_TO_NUMBER(utils.udf_hex_to_int(topics [2] :: STRING)) AS destination,
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS dst_bridge_token,
-- dst bridge token address, not recipient address
DATA,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING = '0x769f711d20c679153d382254f59892613b58a97cc876b249134ac25c80f9c814'
AND contract_address = LOWER('0x3a867fCfFeC2B790970eeBDC9023E75B0a172aa7')
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 %}
),
dispatch_id AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
topics [1] :: STRING AS messageId,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING = '0x788dbc1b7152732178210e7f4d9d010ef016f9eafbe66786bd7169f56e0c353a'
AND contract_address = LOWER('0x3a867fCfFeC2B790970eeBDC9023E75B0a172aa7')
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 %}
),
gas_payment AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
topics [1] :: STRING AS messageId,
TRY_TO_NUMBER(utils.udf_hex_to_int(topics [2] :: STRING)) AS destinationDomain,
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 gasAmount,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [1] :: STRING)) AS payment,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] = '0x65695c3748edae85a24cc2c60b299b31f463050bc259150d2e5802ec8d11720a'
AND contract_address = LOWER('0xB3fCcD379ad66CED0c91028520C64226611A48c9')
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 %}
),
sent_transfer_remote AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS destination,
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
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING = '0xd229aacb94204188fe8042965fa6b269c62dc5818b21238779ab64bdd17efeec'
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 %}
),
token_transfer AS (
-- 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
FROM
{{ ref('silver__transfers') }}
WHERE
tx_hash IN (
SELECT
tx_hash
FROM
sent_transfer_remote
)
AND to_address = '0x0000000000000000000000000000000000000000'
)
SELECT
block_number,
block_timestamp,
origin_function_signature,
origin_from_address,
origin_to_address,
tx_hash,
event_index,
contract_address AS bridge_address,
'Dispatch' AS event_name,
event_removed,
tx_succeeded,
recipient AS destination_chain_receiver,
destination AS destination_chain_id,
messageId :: STRING AS message_id,
gasAmount AS gas_amount,
payment,
origin_from_address AS sender,
recipient AS receiver,
amount,
token_address,
'hyperlane' AS platform,
_log_id,
modified_timestamp
FROM
dispatch
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

@ -0,0 +1,72 @@
version: 2
models:
- name: silver_bridge__hyperlane_bridge
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
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
- 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]+

View File

@ -0,0 +1,174 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['curated','reorg']
) }}
WITH oft_asset_contract_creation AS (
SELECT
block_number,
block_timestamp,
tx_hash,
from_address AS oft_address,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CASE
WHEN trace_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS trace_succeeded,
modified_timestamp
FROM
{{ ref('core__fact_traces') }}
WHERE
TYPE = 'CALL'
AND LEFT(
input,
10
) = '0xca5eb5e1'
AND to_address = '0x1a44076050125825900e736c501f859c50fe728c' -- layerzero v2
AND tx_succeeded
AND trace_succeeded
{% if is_incremental() %}
AND modified_timestamp >= (
SELECT
MAX(modified_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
qualify ROW_NUMBER() over (
PARTITION BY oft_address
ORDER BY
block_timestamp DESC
) = 1
),
oft_asset_base_token AS (
SELECT
block_number,
block_timestamp,
tx_hash,
from_address AS wrap_address,
to_address AS underlying_address,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CASE
WHEN trace_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS trace_succeeded,
modified_timestamp
FROM
{{ ref('core__fact_traces') }}
WHERE
tx_hash IN (
SELECT
tx_hash
FROM
oft_asset_contract_creation
)
AND TYPE = 'STATICCALL'
AND input = '0x313ce567' qualify ROW_NUMBER() over (
PARTITION BY tx_hash
ORDER BY
trace_index ASC
) = 1
),
oft_asset AS (
SELECT
oft_address,
underlying_address
FROM
oft_asset_contract_creation t1
LEFT JOIN oft_asset_base_token t2
ON t1.tx_hash = t2.tx_hash
AND oft_address = wrap_address
),
oft_sent AS (
-- bridging transactions
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address,
event_index,
'OFTSent' AS event_name,
'layerzero-v2' AS platform,
oft_address,
underlying_address,
SUBSTR(
topics [1] :: STRING,
2,
64
) AS guid,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS from_address,
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 dstEid,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [1] :: STRING)) AS amountSentLD,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [2] :: STRING)) AS amountReceivedLD,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
e
INNER JOIN oft_asset
ON oft_address = contract_address
WHERE
topics [0] = '0x85496b760a4b7f8d66384b9df21b381f5d1b1e79f229a47aaf4c232edc2fe59a'
{% if is_incremental() %}
AND e.modified_timestamp >= (
SELECT
MAX(modified_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
AND e.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
'0x1a44076050125825900e736c501f859c50fe728c' AS bridge_address,
event_index,
event_name,
platform,
from_address AS sender,
from_address AS receiver,
from_address AS destination_chain_receiver,
amountSentLD AS amount,
b.dstEid AS destination_chain_id,
LOWER(
s.chain :: STRING
) AS destination_chain,
COALESCE(
underlying_address,
oft_address
) AS token_address,
oft_address,
_log_id,
modified_timestamp
FROM
oft_sent b
INNER JOIN {{ ref('silver_bridge__layerzero_bridge_seed') }}
s
ON b.dstEid :: STRING = s.eid :: STRING

View File

@ -0,0 +1,72 @@
version: 2
models:
- name: silver_bridge__layerzero_bridge_v2
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
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
- 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]+

View File

@ -0,0 +1,86 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
cluster_by = ['block_timestamp::DATE'],
tags = ['curated','reorg']
) }}
WITH bridge_native AS (
-- for direct native eth transfers
SELECT
et.block_number,
et.block_timestamp,
et.tx_hash,
tx.from_address AS origin_from_address,
tx.to_address AS origin_to_address,
tx.origin_function_signature,
et.to_address,
et.from_address,
origin_from_address AS depositor,
RIGHT(
amount_precise_raw,
4
) AS destinationChainId,
amount_precise_raw :: INTEGER AS amount_unadj,
origin_from_address AS recipient,
et.to_address AS bridge_address,
trace_index,
native_transfers_id,
et.modified_timestamp
FROM
{{ ref('silver__native_transfers') }}
et
INNER JOIN {{ ref('silver__transactions') }}
tx
ON et.block_number = tx.block_number
AND et.tx_hash = tx.tx_hash
WHERE
et.to_address IN (
'0xe4edb277e41dc89ab076a1f049f4a3efa700bce8',
'0xee73323912a4e3772b74ed0ca1595a152b0ef282',
'0x80c67432656d59144ceff962e8faf8926599bcf8',
'0x3bdb03ad7363152dfbc185ee23ebc93f0cf93fd1'
)
{% if is_incremental() %}
AND et.modified_timestamp >= (
SELECT
MAX(modified_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
AND et.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
{% endif %}
)
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
trace_index AS event_index,
NULL AS event_name,
to_address,
from_address,
depositor AS sender,
b.destinationChainId AS orbiter_chain_id,
s.chainid AS destination_chain_id,
s.name AS destination_chain,
amount_unadj,
recipient AS receiver,
recipient AS destination_chain_receiver,
bridge_address,
TRUE AS tx_succeeded,
'orbiter' AS platform,
'0x4300000000000000000000000000000000000004' AS token_address,
--weth contract address
native_transfers_id AS _id,
modified_timestamp
FROM
bridge_native b
LEFT JOIN {{ ref('silver_bridge__orbiter_bridge_seed') }}
s
ON b.destinationChainId :: STRING = s.identificationcode :: STRING

View File

@ -0,0 +1,66 @@
version: 2
models:
- name: silver_bridge__orbiter_bridgerequest
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- _ID
columns:
- name: BLOCK_NUMBER
tests:
- not_null
- name: BLOCK_TIMESTAMP
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
- 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: 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_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]+

View File

@ -0,0 +1,593 @@
-- 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 across_v3 AS (
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
event_index,
bridge_address,
event_name,
platform,
'v3' 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__across_v3fundsdeposited') }}
{% if is_incremental() and 'across_v3' 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,
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 %}
),
layerzero_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,
modified_timestamp AS _inserted_timestamp
FROM
{{ ref('silver_bridge__layerzero_bridge_v2') }}
{% if is_incremental() and 'layerzero_v2' 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
across_v3
UNION ALL
SELECT
*
FROM
axelar
UNION ALL
SELECT
*
FROM
hyperlane
UNION ALL
SELECT
*
FROM
layerzero_v2
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',
'layerzero-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 (
'orbiter',
'layerzero-v2'
) 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: PLATFORM NOT IN ('orbiter')
- name: EVENT_NAME
tests:
- not_null:
where: PLATFORM NOT IN ('orbiter')
- 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

@ -0,0 +1,90 @@
{{ 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,
'symbiosis' AS NAME,
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] :: 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,
CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS token,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
topics [0] :: STRING = '0x31325fe0a1a2e6a5b1e41572156ba5b4e94f0fae7e7f63ec21e9b5ce1e4b3eab'
AND contract_address = '0x5aa5f7f84ed0e5db0a4a85c3947ea16b53352fd4'
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,
tx_succeeded,
contract_address AS bridge_address,
NAME AS platform,
from_address AS sender,
to_address AS receiver,
receiver AS destination_chain_receiver,
amount,
chainID AS destination_chain_id,
id,
revertableAddress AS revertable_address,
token AS token_address,
_log_id,
modified_timestamp
FROM
base_evt

View File

@ -0,0 +1,72 @@
version: 2
models:
- name: silver_bridge__symbiosis_synthesizerequest
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
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
- 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]+

View File

@ -0,0 +1,252 @@
{{ 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_from_address,
origin_to_address,
origin_function_signature,
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,
topics [3] :: STRING AS topic_3,
DATA,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CASE
WHEN tx_status = 'SUCCESS' THEN TRUE
ELSE FALSE
END AS tx_succeeded,
CONCAT(
tx_hash :: STRING,
'-',
event_index :: STRING
) AS _log_id,
modified_timestamp
FROM
{{ ref('core__fact_event_logs') }}
WHERE
contract_address = '0x55769baf6ec39b3bf4aae948eb890ea33307ef3c'
AND topic_0 IN (
'0x91f25e9be0134ec851830e0e76dc71e06f9dade75a9b84e9524071dbbc319425',
-- TokenRedeemAndSwap
'0x79c15604b92ef54d3f61f0c40caab8857927ca3d5092367163b4562c1699eb5f',
-- TokenDepositAndSwap
'0x9a7024cde1920aa50cdde09ca396229e8c4d530d5cfdc6233590def70a94408c',
-- TokenRedeemAndRemove
'0xdc5bad4651c5fbe9977a696aadc65996c468cde1448dd468ec0d83bf61c4b57c',
-- TokenRedeem
'0xda5273705dbef4bf1b902a131c2eac086b7e1476a8ab0cb4da08af1fe1bd8e3b',
-- TokenDeposit
'0x8e57e8c5fea426159af69d47eda6c5052c7605c9f70967cf749d4aa55b70b499' -- TokenRedeemV2 (terra specific)
)
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 %}
),
redeem_swap AS (
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
event_index,
CASE
WHEN topic_0 = '0x91f25e9be0134ec851830e0e76dc71e06f9dade75a9b84e9524071dbbc319425' THEN 'TokenRedeemAndSwap'
WHEN topic_0 = '0x79c15604b92ef54d3f61f0c40caab8857927ca3d5092367163b4562c1699eb5f' THEN 'TokenDepositAndSwap'
END AS event_name,
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,
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 tokenIndexFrom,
-- source chain token index
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) AS tokenIndexTo,
-- dst chain token index
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [5] :: STRING)) AS minDy,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [6] :: STRING)) AS deadline,
-- timestamp
tx_succeeded,
_log_id,
modified_timestamp
FROM
base_evt
WHERE
topic_0 IN (
'0x91f25e9be0134ec851830e0e76dc71e06f9dade75a9b84e9524071dbbc319425',
-- TokenRedeemAndSwap
'0x79c15604b92ef54d3f61f0c40caab8857927ca3d5092367163b4562c1699eb5f' -- TokenDepositAndSwap
)
),
redeem_remove AS (
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
event_index,
'TokenRedeemAndRemove' AS event_name,
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,
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 swapTokenIndex,
-- dst chain token index
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) AS swapMinAmount,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [5] :: STRING)) AS swapDeadline,
-- timestamp
tx_succeeded,
_log_id,
modified_timestamp
FROM
base_evt
WHERE
topic_0 = '0x9a7024cde1920aa50cdde09ca396229e8c4d530d5cfdc6233590def70a94408c' -- TokenRedeemAndRemove
),
redeem_only AS (
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
event_index,
CASE
WHEN topic_0 = '0xdc5bad4651c5fbe9977a696aadc65996c468cde1448dd468ec0d83bf61c4b57c' THEN 'TokenRedeem'
WHEN topic_0 = '0xda5273705dbef4bf1b902a131c2eac086b7e1476a8ab0cb4da08af1fe1bd8e3b' THEN 'TokenDeposit'
WHEN topic_0 = '0x8e57e8c5fea426159af69d47eda6c5052c7605c9f70967cf749d4aa55b70b499' THEN 'TokenRedeemV2'
END AS event_name,
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,
TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [2] :: STRING)) AS amount,
tx_succeeded,
_log_id,
modified_timestamp
FROM
base_evt
WHERE
topic_0 IN (
'0xdc5bad4651c5fbe9977a696aadc65996c468cde1448dd468ec0d83bf61c4b57c',
-- TokenRedeem
'0xda5273705dbef4bf1b902a131c2eac086b7e1476a8ab0cb4da08af1fe1bd8e3b',
-- TokenDeposit
'0x8e57e8c5fea426159af69d47eda6c5052c7605c9f70967cf749d4aa55b70b499' -- TokenRedeemV2 (terra specific)
)
),
all_evts AS (
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
event_index,
event_name,
to_address,
segmented_data,
chainId,
token,
amount,
tx_succeeded,
_log_id,
modified_timestamp
FROM
redeem_swap
UNION ALL
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
event_index,
event_name,
to_address,
segmented_data,
chainId,
token,
amount,
tx_succeeded,
_log_id,
modified_timestamp
FROM
redeem_remove
UNION ALL
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
contract_address,
event_index,
event_name,
to_address,
segmented_data,
chainId,
token,
amount,
tx_succeeded,
_log_id,
modified_timestamp
FROM
redeem_only
)
SELECT
block_number,
block_timestamp,
origin_from_address,
origin_to_address,
origin_function_signature,
tx_hash,
event_index,
event_name,
contract_address AS bridge_address,
origin_from_address AS sender,
to_address AS receiver,
receiver AS destination_chain_receiver,
chainId AS destination_chain_id,
token AS token_address,
amount,
tx_succeeded,
'synapse' AS platform,
_log_id,
modified_timestamp
FROM
all_evts

View File

@ -0,0 +1,72 @@
version: 2
models:
- name: silver_bridge__synapse_tokenredeem
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
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
- 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]+