-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bridges of Bungee = {contract: SocketGateway, event: SocketBridge} (#…
…7255) * Add Odos on Arbitrum to dex_aggregator * Change to WETH address on Arbitrum * Add sources of Odos on Arbitrum * Add odos/arbitrum seeds * Change data type * Add bridges of LiFi across chains * replace tests which is deprecated * fix name error of avalanche source * add index to unique test * fix concat issue * fix unique test of the main model * try to fix unique key * use surrogate key for data tests * use generate_surrogate_key inside the models * fix and remove redundant schema properties * data_tests * move generate_surrogate_key to schema.yml * 1. create macro lifi_extract_bridge_data_macro.sql and apply it in the models 2. update the models' config 3. flip materialization strategy * data_ again * fix naming of the main model * replace avalanche with avalanche_c * avalanche_c again * 1. add block_date column to the macro to use it in the add_tx_columns macro 2. update model of avalanche_c * rename columns to use add_tx_columns macro * remove evt_ * a few minor changes * add amount_usd column * data_tests again * map native token to wrapped token to avoid null price data * update the main model and schema * move type conversion from models to macro * fix source name * varbinary type doesn't need single quotes * correct collumn name * add post_hook * feat: add bungee bridges * create macro and models for each chain * add macro for bungee bridges * chore: ignore raw.sql * add amount_usd to bungee models * remove syntax error * add bungee sources * add post hook for bungee bridges * change eth address on the chains * change the main model * remove endfor * add for loop --------- Co-authored-by: Huang Geyang <Sukebeta@outlook.com> Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com>
- Loading branch information
1 parent
92948fd
commit bf8b448
Showing
19 changed files
with
916 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
dbt_subprojects/daily_spellbook/macros/project/bungee/bungee_SocketBridge_macro.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% macro bungee_SocketBridge(blockchain) %} | ||
|
||
select | ||
contract_address, | ||
evt_tx_hash, | ||
evt_index, | ||
evt_block_time, | ||
evt_block_number, | ||
amount, | ||
token, | ||
toChainId, | ||
bridgeName, | ||
sender, | ||
receiver, | ||
metadata, | ||
'{{ blockchain }}' as source_chain, | ||
{{ dbt_utils.generate_surrogate_key(['evt_tx_hash', 'evt_index']) }} as transfer_id | ||
from {{ source('socket_v2_' ~ blockchain, 'SocketGateway_evt_SocketBridge') }} | ||
{% if is_incremental() %} | ||
where {{ incremental_predicate('evt_block_time') }} | ||
{% endif %} | ||
|
||
{% endmacro %} |
42 changes: 42 additions & 0 deletions
42
dbt_subprojects/daily_spellbook/models/_projects/bungee/arbitrum/bungee_arbitrum_bridges.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ | ||
config( | ||
schema = 'bungee_arbitrum', | ||
alias = 'bridges', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['transfer_id'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] | ||
) | ||
}} | ||
|
||
with source_data as ( | ||
{{ bungee_SocketBridge('arbitrum') }} | ||
), | ||
|
||
tokens_mapped as ( | ||
select | ||
*, | ||
case | ||
when token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- WETH on Arbitrum | ||
else token | ||
end as token_adjusted | ||
from source_data | ||
), | ||
|
||
price_data as ( | ||
select | ||
tokens_mapped.*, | ||
p.price * amount / power(10, p.decimals) as amount_usd | ||
from tokens_mapped | ||
left join {{ source('prices', 'usd') }} p | ||
on p.contract_address = tokens_mapped.token_adjusted | ||
and p.blockchain = 'arbitrum' | ||
and p.minute = date_trunc('minute', tokens_mapped.evt_block_time) | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('p.minute') }} | ||
{% endif %} | ||
) | ||
|
||
select * from price_data |
42 changes: 42 additions & 0 deletions
42
...ojects/daily_spellbook/models/_projects/bungee/avalanche_c/bungee_avalanche_c_bridges.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ | ||
config( | ||
schema = 'bungee_avalanche_c', | ||
alias = 'bridges', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['transfer_id'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] | ||
) | ||
}} | ||
|
||
with source_data as ( | ||
{{ bungee_SocketBridge('avalanche_c') }} | ||
), | ||
|
||
tokens_mapped as ( | ||
select | ||
*, | ||
case | ||
when token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
then 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 -- WAVAX | ||
else token | ||
end as token_adjusted | ||
from source_data | ||
), | ||
|
||
price_data as ( | ||
select | ||
tokens_mapped.*, | ||
p.price * amount / power(10, p.decimals) as amount_usd | ||
from tokens_mapped | ||
left join {{ source('prices', 'usd') }} p | ||
on p.contract_address = tokens_mapped.token_adjusted | ||
and p.blockchain = 'avalanche_c' | ||
and p.minute = date_trunc('minute', tokens_mapped.evt_block_time) | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('p.minute') }} | ||
{% endif %} | ||
) | ||
|
||
select * from price_data |
42 changes: 42 additions & 0 deletions
42
dbt_subprojects/daily_spellbook/models/_projects/bungee/base/bungee_base_bridges.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ | ||
config( | ||
schema = 'bungee_base', | ||
alias = 'bridges', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['transfer_id'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] | ||
) | ||
}} | ||
|
||
with source_data as ( | ||
{{ bungee_SocketBridge('base') }} | ||
), | ||
|
||
tokens_mapped as ( | ||
select | ||
*, | ||
case | ||
when token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
then 0x4200000000000000000000000000000000000006 -- WETH on Base | ||
else token | ||
end as token_adjusted | ||
from source_data | ||
), | ||
|
||
price_data as ( | ||
select | ||
tokens_mapped.*, | ||
p.price * amount / power(10, p.decimals) as amount_usd | ||
from tokens_mapped | ||
left join {{ source('prices', 'usd') }} p | ||
on p.contract_address = tokens_mapped.token_adjusted | ||
and p.blockchain = 'base' | ||
and p.minute = date_trunc('minute', tokens_mapped.evt_block_time) | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('p.minute') }} | ||
{% endif %} | ||
) | ||
|
||
select * from price_data |
42 changes: 42 additions & 0 deletions
42
dbt_subprojects/daily_spellbook/models/_projects/bungee/blast/bungee_blast_bridges.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ | ||
config( | ||
schema = 'bungee_blast', | ||
alias = 'bridges', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['transfer_id'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] | ||
) | ||
}} | ||
|
||
with source_data as ( | ||
{{ bungee_SocketBridge('blast') }} | ||
), | ||
|
||
tokens_mapped as ( | ||
select | ||
*, | ||
case | ||
when token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
then 0x4300000000000000000000000000000000000004 -- WETH on Blast | ||
else token | ||
end as token_adjusted | ||
from source_data | ||
), | ||
|
||
price_data as ( | ||
select | ||
tokens_mapped.*, | ||
p.price * amount / power(10, p.decimals) as amount_usd | ||
from tokens_mapped | ||
left join {{ source('prices', 'usd') }} p | ||
on p.contract_address = tokens_mapped.token_adjusted | ||
and p.blockchain = 'blast' | ||
and p.minute = date_trunc('minute', tokens_mapped.evt_block_time) | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('p.minute') }} | ||
{% endif %} | ||
) | ||
|
||
select * from price_data |
42 changes: 42 additions & 0 deletions
42
dbt_subprojects/daily_spellbook/models/_projects/bungee/bnb/bungee_bnb_bridges.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ | ||
config( | ||
schema = 'bungee_bnb', | ||
alias = 'bridges', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['transfer_id'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] | ||
) | ||
}} | ||
|
||
with source_data as ( | ||
{{ bungee_SocketBridge('bnb') }} | ||
), | ||
|
||
tokens_mapped as ( | ||
select | ||
*, | ||
case | ||
when token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
then 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c -- WBNB | ||
else token | ||
end as token_adjusted | ||
from source_data | ||
), | ||
|
||
price_data as ( | ||
select | ||
tokens_mapped.*, | ||
p.price * amount / power(10, p.decimals) as amount_usd | ||
from tokens_mapped | ||
left join {{ source('prices', 'usd') }} p | ||
on p.contract_address = tokens_mapped.token_adjusted | ||
and p.blockchain = 'bnb' | ||
and p.minute = date_trunc('minute', tokens_mapped.evt_block_time) | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('p.minute') }} | ||
{% endif %} | ||
) | ||
|
||
select * from price_data |
46 changes: 46 additions & 0 deletions
46
dbt_subprojects/daily_spellbook/models/_projects/bungee/bungee_bridges.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{{ | ||
config( | ||
schema = 'bungee', | ||
alias = 'bridges', | ||
materialized = 'view', | ||
post_hook = '{{ expose_spells(\'[ | ||
"ethereum", "zkevm", "scroll", "blast", "linea", "mantle", "optimism", | ||
"gnosis", "arbitrum", "zksync", "base", "bnb", "polygon", | ||
"avalanche_c", "fantom" | ||
]\', | ||
"project", "bungee", \'["lequangphu"]\') }}' | ||
) | ||
}} | ||
|
||
{% set chains = [ | ||
'ethereum', 'zkevm', 'scroll', 'blast', 'linea', 'mantle', 'optimism', | ||
'gnosis', 'arbitrum', 'zksync', 'base', 'bnb', 'polygon', | ||
'avalanche_c', 'fantom' | ||
] %} | ||
|
||
with bungee_bridges as ( | ||
{% for chain in chains %} | ||
select | ||
contract_address, | ||
evt_tx_hash, | ||
evt_index, | ||
evt_block_time, | ||
evt_block_number, | ||
amount, | ||
token, | ||
toChainId, | ||
bridgeName, | ||
sender, | ||
receiver, | ||
metadata, | ||
source_chain, | ||
transfer_id | ||
from {{ ref( 'bungee_' ~ chain ~ '_bridges' ) }} | ||
{% if not loop.last %} | ||
union all | ||
{% endif %} | ||
{% endfor %} | ||
) | ||
|
||
select * | ||
from bungee_bridges |
42 changes: 42 additions & 0 deletions
42
dbt_subprojects/daily_spellbook/models/_projects/bungee/ethereum/bungee_ethereum_bridges.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ | ||
config( | ||
schema = 'bungee_ethereum', | ||
alias = 'bridges', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['transfer_id'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] | ||
) | ||
}} | ||
|
||
with source_data as ( | ||
{{ bungee_SocketBridge('ethereum') }} | ||
), | ||
|
||
tokens_mapped as ( | ||
select | ||
*, | ||
case | ||
when token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -- WETH | ||
else token | ||
end as token_adjusted | ||
from source_data | ||
), | ||
|
||
price_data as ( | ||
select | ||
tokens_mapped.*, | ||
p.price * amount / power(10, p.decimals) as amount_usd | ||
from tokens_mapped | ||
left join {{ source('prices', 'usd') }} p | ||
on p.contract_address = tokens_mapped.token_adjusted | ||
and p.blockchain = 'ethereum' | ||
and p.minute = date_trunc('minute', tokens_mapped.evt_block_time) | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('p.minute') }} | ||
{% endif %} | ||
) | ||
|
||
select * from price_data |
42 changes: 42 additions & 0 deletions
42
dbt_subprojects/daily_spellbook/models/_projects/bungee/fantom/bungee_fantom_bridges.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{ | ||
config( | ||
schema = 'bungee_fantom', | ||
alias = 'bridges', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['transfer_id'], | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.evt_block_time')] | ||
) | ||
}} | ||
|
||
with source_data as ( | ||
{{ bungee_SocketBridge('fantom') }} | ||
), | ||
|
||
tokens_mapped as ( | ||
select | ||
*, | ||
case | ||
when token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
then 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 -- WFTM | ||
else token | ||
end as token_adjusted | ||
from source_data | ||
), | ||
|
||
price_data as ( | ||
select | ||
tokens_mapped.*, | ||
p.price * amount / power(10, p.decimals) as amount_usd | ||
from tokens_mapped | ||
left join {{ source('prices', 'usd') }} p | ||
on p.contract_address = tokens_mapped.token_adjusted | ||
and p.blockchain = 'fantom' | ||
and p.minute = date_trunc('minute', tokens_mapped.evt_block_time) | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('p.minute') }} | ||
{% endif %} | ||
) | ||
|
||
select * from price_data |
Oops, something went wrong.