Skip to content

Commit

Permalink
Merge branch 'Add-New-Event-Models-for-GMX-v2-(next-iteration)' of ht…
Browse files Browse the repository at this point in the history
…tps://github.com/AIDataMaster/spellbook into Add-New-Event-Models-for-GMX-v2-(next-iteration)
  • Loading branch information
AIDataMaster committed Dec 19, 2024
2 parents 67a0dc5 + 2099d14 commit a741f31
Show file tree
Hide file tree
Showing 123 changed files with 3,350 additions and 460 deletions.
23 changes: 23 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"dbt: daily":
- changed-files:
- any-glob-to-any-file: 'dbt_subprojects/daily_spellbook/**'

"dbt: dex":
- changed-files:
- any-glob-to-any-file: 'dbt_subprojects/dex/**'

"dbt: hourly":
- changed-files:
- any-glob-to-any-file: 'dbt_subprojects/hourly_spellbook/**'

"dbt: nft":
- changed-files:
- any-glob-to-any-file: 'dbt_subprojects/nft/**'

"dbt: solana":
- changed-files:
- any-glob-to-any-file: 'dbt_subprojects/solana/**'

"dbt: tokens":
- changed-files:
- any-glob-to-any-file: 'dbt_subprojects/tokens/**'
46 changes: 46 additions & 0 deletions .github/workflows/pr_automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: PR automation

on:
pull_request_target:
types:
- opened
- ready_for_review
- converted_to_draft
- synchronize
- labeled

permissions:
pull-requests: write
contents: write

jobs:
pr-automation:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.number }}
steps:
- name: Mark new PR as Draft
if: (github.event.action == 'opened' && github.event.pull_request.draft == false)
run: gh pr ready "$NUMBER" --undo

- name: Set labels on Open
if: github.event.action == 'opened'
run: gh pr edit "$NUMBER" --add-label "WIP"

- name: Set labels on Draft
if: github.event.action == 'converted_to_draft'
run: gh pr edit "$NUMBER" --add-label "WIP" --remove-label "ready-for-review"

- name: Set labels on ready-for-review
if: github.event.action == 'ready_for_review'
run: gh pr edit "$NUMBER" --add-label "ready-for-review" --remove-label "WIP"

- name: Add subproject labels
if: contains('synchronize,opened,reopened', github.event.action)
uses: actions/labeler@v5
with:
sync-labels: true


15 changes: 11 additions & 4 deletions dbt_macros/shared/balances_incremental_subset_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

@NOTICE this macro constructs the address level token balances table for given input table
@NOTICE aka, you give lists of tokens and/or address, it generates table with daily balances of the address-token pair

@WARN this macro has a dependancy on erc20.tokens.
@WARN if your token is not in the default list, manually add it via spellbook/dbt_subprojects/tokens/models/tokens/<chain>/tokens_<chain>_erc20.sql

@PARAM blockchain -- blockchain name
@PARAM address_list -- must have an address column, can be none if only filtering on tokens
Expand Down Expand Up @@ -149,14 +152,18 @@ from(
{% endif %}

) b
left join {{source('prices','usd')}} p
on (token_standard = 'erc20'
left join {{source('prices','usd_daily')}} p
on 1=1
{% if is_incremental() %}
and {{ incremental_predicate('p.day') }}
{% endif %}
and ((token_standard = 'erc20'
and p.blockchain = '{{blockchain}}'
and b.token_address = p.contract_address
and b.day = p.minute)
and b.day = p.day)
or (token_standard = 'native'
and p.blockchain is null
and p.contract_address is null
and p.symbol = (select native_token_symbol from {{source('evms','info')}} where blockchain = '{{blockchain}}')
and b.day = p.minute)
and b.day = p.day))
{% endmacro %}
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
Expand Up @@ -79,7 +79,7 @@
, ('0xbf1fc29668e5f5eaa819948599c9ac1b1e03e75f', 'true', 'Cone' , 'ConeRouter01' , ['bnb'])
, ('0x11984dc4465481512eb5b777e44061c158cf2259', 'true', 'Connext' , 'ConnextDiamond' , ['polygon'])
, ('0xee9dec2712cce65174b561151701bf54b99c24c8', 'true', 'Connext' , 'ConnextDiamond' , ['arbitrum'])
, ('0x9008d19f58aabd9ed0d60971565aa8510560ab41', 'true', 'CoWSwap' , 'GPv2Settlement' , ['ethereum','gnosis','arbitrum'])
, ('0x9008d19f58aabd9ed0d60971565aa8510560ab41', 'true', 'CoWSwap' , 'GPv2Settlement' , ['ethereum','gnosis','arbitrum','base'])
, ('0xfa43de785dd3cd0ef3dae0dd2b8be3f1b5112d1a', 'true', 'CrossCurve' , 'UnifiedRouterV2v1' , ['ethereum','bnb','polygon','gnosis','arbitrum','avalanche_c','optimism','base','fantom'])
, ('0xa2a786ff9148f7c88ee93372db8cbe9e94585c74', 'true', 'CrossCurve' , 'UnifiedRouterV2v5' , ['ethereum','bnb','polygon','gnosis','arbitrum','avalanche_c','optimism','base','fantom','blast','linea','mantle'])
, ('0xe7db62c7960183895190274f26925388db4a3be4', 'true', 'CrossCurve' , 'UnifiedRouterV2' , ['ethereum','bnb','polygon','gnosis','arbitrum','avalanche_c','optimism','base','fantom'])
Expand Down
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
Loading

0 comments on commit a741f31

Please sign in to comment.