Skip to content

Commit

Permalink
Merge branch 'main' into auto-labels-and-draft
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-dude authored Dec 13, 2024
2 parents 55212f3 + 4774a18 commit 74115a3
Show file tree
Hide file tree
Showing 60 changed files with 2,069 additions and 50 deletions.
2 changes: 1 addition & 1 deletion dbt_subprojects/daily_spellbook/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Daily Spellbook

This is a DBT sub project for the the main models of Spellbook that runs on a daily candence
This is a DBT sub project for the the main models of Spellbook that runs on a daily candence.
3 changes: 3 additions & 0 deletions dbt_subprojects/daily_spellbook/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ quoting:
# profile: "spellbook-poc-tokens"
profile: "spellbook-local"

flags:
require_certificate_validation: true

vars:
DBT_ENV_CUSTOM_ENV_S3_BUCKET: "{{ env_var('DBT_ENV_CUSTOM_ENV_S3_BUCKET', 'local') }}"
DBT_ENV_INCREMENTAL_TIME: "{{ env_var('DBT_ENV_INCREMENTAL_TIME', '3') }}"
Expand Down
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 %}
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
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
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
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
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
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
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
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
Loading

0 comments on commit 74115a3

Please sign in to comment.