Skip to content

Commit

Permalink
Merge branch 'main' into gravity-finance-polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-dude authored Dec 16, 2024
2 parents 6ab49ee + 39d698d commit 6df8880
Show file tree
Hide file tree
Showing 29 changed files with 777 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_automation.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PR automation

on:
pull_request:
pull_request_target:
types:
- opened
- ready_for_review
Expand Down
3 changes: 3 additions & 0 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{
config(
schema = 'swell_balances_ethereum',
alias = 'core_assets',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['day', 'wallet_address', 'token_address'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.day')],
post_hook='{{ expose_spells(\'["ethereum"]\',
"project",
"swell",
\'["maybeYonas"]\') }}'
)
}}

with
tokens as (
select * from (values
(0xf951E335afb289353dc249e82926178EaC7DEd78, 'swETH', 'Swell LRT'),
(0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0, 'rswETH', 'Swell LRT'),
(0x0a6E7Ba5042B38349e437ec6Db6214AEC7B35676, 'SWELL', 'Swell LRT'),
(0x358d94b5b2F147D741088803d932Acb566acB7B6, 'rSWELL', 'Swell LRT'),
(0x9Ed15383940CC380fAEF0a75edacE507cC775f22, 'earnETH', 'Swell LRT'),
(0x66E47E6957B85Cf62564610B76dD206BB04d831a, 'earnBTC', 'Swell LRT'),
(0x8DB2350D78aBc13f5673A411D4700BCF87864dDE, 'swBTC', 'Swell LRT')
) as t(
token_address,
symbol,
name
)
),
balances as (
{{
balances_incremental_subset_daily(
blockchain = 'ethereum',
token_list = 'tokens',
start_date = '2023-04-12'
)
}}
)

select
-- t.name,
b.blockchain,
b.day,
b.address as wallet_address,
b.token_symbol,
b.token_address,
b.token_standard,
b.token_id,
b.balance,
b.balance_usd,
b.last_updated,
b.next_update
from balances b
-- left join tokens t
-- on b.token_address = t.token_address
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: 2

models:
- name: swell_balances_ethereum_core_assets

meta:
blockchain: ethereum
project: swell
contributors: maybeYonas

config:
tags: ['swell', 'restaking', 'lrt', 'lst', 'vaults', 'balances']
description: "balances of swell asset holders"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- wallet_address
- token_address
- check_seed:
seed_file: ref('swell_balances_ethereum_core_assets_seed')
match_columns:
- blockchain
- day
- wallet_address
- token_address
check_columns:
- balance
- last_updated
columns:
- &blockchain
name: blockchain
description: "blockchain"
- &day
name: day
description: "date on which the token balance is logged"
- &wallet_address
name: wallet_address
description: "wallet address of the holder"
- &token_symbol
name: token_symbol
description: "token symbol"
- &token_address
name: token_address
description: "token address"
- &token_standard
name: token_standard
description: "standard of the token (erc20)"
- &token_id
name: token_id
description: "ID of the token"
- &balance
name: balance
description: "asset balance of the wallet"
- &balance_usd
name: balance_usd
description: "usd value of token balance of the wallet"
- &last_updated
name: last_updated
description: "UTC timestamp when balance was last updated"
- &next_update
name: next_update
description: "UTC timestamp when balance is next updated"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

seeds:
- name: swell_balances_ethereum_core_assets_seed
config:
column_types:
blockchain: varchar
day: timestamp
wallet_address: varbinary
token_address: varbinary
balance: double
last_updated: timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blockchain,day,wallet_address,token_address,balance,last_updated
ethereum,2024-08-13 00:00:00.000 UTC,0x4589Ef5d52a152C25Daa513cF43b1389Bd1f3C00,0xf951E335afb289353dc249e82926178EaC7DEd78,0.004752378895635013,2024-02-29 00:00:00.000 UTC
ethereum,2024-12-04 00:00:00.000 UTC,0xaf1ec97ea59e9052ee563e4265c39291c020e3dd,0x0a6e7ba5042b38349e437ec6db6214aec7b35676,1074.616281,2024-11-08 00:00:00.000 UTC
ethereum,2024-12-05 00:00:00.000 UTC,0x841ea52b74c94420a61d41ba790e710e1af8ee0a,0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0,0.050121577326075153,2024-11-24 00:00:00.000 UTC
ethereum,2024-08-13 00:00:00.000 UTC,0xfee2d4498085581dde097b9924e4e3544682d767,0x8db2350d78abc13f5673a411d4700bcf87864dde,0.04096165,2024-08-13 00:00:00.000 UTC
ethereum,2024-12-04 00:00:00.000 UTC,0xbdD5d655ad781FB9929BFe515EB4A50090444C21,0x9Ed15383940CC380fAEF0a75edacE507cC775f22,89.828941195874851394,2024-11-08 00:00:00.000 UTC
ethereum,2024-12-01 00:00:00.000 UTC,0x84a6a7c0674A3AA03e09c026600cb46181821f07,0x66E47E6957B85Cf62564610B76dD206BB04d831a,1,2024-11-25 00:00:00.000 UTC
ethereum,2024-12-04 00:00:00.000 UTC,0x22aA3f5D1daFfe1a9DF298e79a0CF2f98C1b92FF,0x358d94b5b2F147D741088803d932Acb566acB7B6,278707.960865665406065408,2024-12-02 00:00:00.000 UTC
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{
config(
schema = 'fluid_ethereum',
alias = 'pools',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['dex'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
post_hook='{{ expose_spells(blockchains = \'["ethereum"]\',
spell_type = "project",
spell_name = "fluid",
contributors = \'["maybeYonas", "pyor_xyz"]\') }}'
)
}}

{% set weth_address = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' %}

with
decoded_events as (
select
block_time,
block_number,
index as evt_index,
tx_hash,
contract_address as factory,
substr(topic1, 13) as dex,
substr(topic2, 13) as supplyToken,
substr(topic3, 13) as borrowToken,
bytearray_to_uint256(data) as dexId
from {{ source('ethereum', 'logs')}}
where topic0 = 0x3fecd5f7aca6136a20a999e7d11ff5dcea4bd675cb125f93ccd7d53f98ec57e4
-- DexT1Deployed -> sample tx: https://etherscan.io/tx/0xabf5c0e676e69de941c283400d7ac5f47b17a09d870f225b5240522f95da501c#eventlog
and block_number > 20776998
{% if is_incremental() %}
and {{ incremental_predicate('block_time') }}
{% endif %}
)

select
'ethereum' as blockchain,
'fluid' as project,
'1' as version,
block_time,
block_number,
evt_index,
tx_hash,
factory,
dex,
case supplyToken when 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then {{weth_address}} else supplyToken end as supply_token,
case borrowToken when 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then {{weth_address}} else borrowToken end as borrow_token,
dexId as dex_id
from decoded_events
54 changes: 54 additions & 0 deletions dbt_subprojects/dex/models/_projects/fluid/ethereum/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: 2

models:
- name: fluid_v1_ethereum_pools
meta:
blockchain: ethereum
sector: dex
project: fluid
contributor: maybeYonas
config:
tags: ['ethereum', 'trades', 'fluid', 'dex']
description: "fluid pools"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- dex
columns:
- &blockchain
name: blockchain
description: "blockchain where the pool is deployed"
- &project
name: project
description: "project name"
- &version
name: version
description: "project version"
- &block_time
name: block_time
description: "utc block timestamp when the pool is deployed"
- &block_number
name: block_number
description: "block number at which the pool is deployed"
- &evt_index
name: evt_index
description: "index of log emitted"
- &tx_hash
name: tx_hash
description: "hash of tx in which pool is deployed"
- &factory
name: factory
description: "factory contract deploying the pool"
- &dex
name: dex
description: "pool contract address"
- &supply_token
name: supply_token
description: "supply token"
- &borrow_token
name: borrow_token
description: "borrow token"
- &dex_id
name: dex_id
description: "nonce unique to factory and pool"

Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,25 @@ with
{% else %} and call_block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
openocean_aggregator_trades as (
select evt_block_time as block_time, evt_tx_hash as tx_hash
from {{ source('openocean_v2_ethereum', 'OpenOceanExchangeProxy_evt_Swapped') }}
where
referrer = {{ treasury_fee_wallet_2 }}
{% if is_incremental() %}
and {{ incremental_predicate('evt_block_time') }}
{% else %} and evt_block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
trade_transactions as (
select block_time, address, null as tx_hash
from bot_contracts
union all
select block_time, null as address, tx_hash
from oneinch_aggregator_trades
union all
select block_time, null as address, tx_hash
from openocean_aggregator_trades
),
bot_trades as (
select
Expand Down
1 change: 1 addition & 0 deletions dbt_subprojects/dex/models/dex_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,5 @@ FROM (VALUES
, ('jetswap', 'JetSwap', 'Direct', 'Jetfuelfinance')
, ('levinswap', 'Levinswap', 'Direct', 'levinswap')
, ('gravity_finance', 'GravityFinance', 'Direct', 'Gravity_Finance')
, ('fluid', 'Fluid DEX', 'Direct', '0xfluid')
) AS temp_table (project, name, marketplace_type, x_username)
19 changes: 19 additions & 0 deletions dbt_subprojects/dex/models/trades/ethereum/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,22 @@ models:
combination_of_columns:
- tx_hash
- evt_index

- name: fluid_v1_ethereum_base_trades
meta:
blockchain: ethereum
sector: dex
project: fluid
contributors: maybeYonas, pyor_xyz
config:
tags: ["ethereum", "dex", "trades", "fluid"]
description: "fluid dex ethereum base trades"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('fluid_ethereum_base_trades_seed')
filter:
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
, ref('swaap_v2_ethereum_base_trades')
, ref('valantis_hot_ethereum_base_trades')
, ref('xchange_v2_ethereum_base_trades')
, ref('fluid_v1_ethereum_base_trades')
] %}

WITH base_union AS (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{
config(
schema = 'fluid_v1_ethereum',
alias = 'base_trades',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'evt_index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

with
decoded_events as (
select
'1' as version,
t.evt_block_number as block_number,
t.evt_block_time as block_time,
t.to as taker,
cast(null as varbinary) as maker,
t.amountOut as token_bought_amount_raw,
t.amountIn as token_sold_amount_raw,
case when swap0to1
then p.borrow_token
else p.supply_token
end as token_bought_address,
case when not(swap0to1)
then p.borrow_token
else p.supply_token
end as token_sold_address,
t.contract_address as project_contract_address,
t.evt_tx_hash as tx_hash,
t.evt_index
from {{ source('fluid_ethereum', 'FluidDexT1_evt_Swap') }} t
inner join {{ ref('fluid_v1_ethereum_pools') }} p
on t.contract_address = p.dex
{% if is_incremental() %}
where {{ incremental_predicate('t.evt_block_time') }}
{% endif %}
)


SELECT
'ethereum' as blockchain,
'fluid' as project,
dexs.version,
cast(date_trunc('month', dexs.block_time) as date) as block_month,
cast(date_trunc('day', dexs.block_time) as date) as block_date,
dexs.block_time,
dexs.block_number,
dexs.token_bought_amount_raw,
dexs.token_sold_amount_raw,
dexs.token_bought_address,
dexs.token_sold_address,
dexs.taker,
dexs.maker,
dexs.project_contract_address,
dexs.tx_hash,
dexs.evt_index
FROM decoded_events dexs
Loading

0 comments on commit 6df8880

Please sign in to comment.