Skip to content

Commit

Permalink
Add eth mainnet models
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-snx committed Jan 8, 2025
1 parent 511d632 commit 76463b1
Show file tree
Hide file tree
Showing 21 changed files with 1,417 additions and 0 deletions.
5 changes: 5 additions & 0 deletions transformers/synthetix/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,10 @@ models:
mainnet:
+tags: "base_mainnet"
+schema: core_base_mainnet
eth:
+enabled: "{{ target.name != 'prod-op' }}"
mainnet:
+tags: "eth_mainnet"
+schema: core_eth_mainnet
seeds:
+schema: seeds
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
with indexer_blocks as (
select
timestamp as ts,
CAST(
number as INTEGER
) as block_number
from
{{ source(
'raw_eth_mainnet',
'synthetix_block'
) }}
),

parquet_blocks as (
select
FROM_UNIXTIME(timestamp) as ts,
CAST(
block_number as INTEGER
) as block_number
from
{{ source(
'raw_eth_mainnet',
'blocks_parquet'
) }}
),

combined_blocks as (
select *
from
indexer_blocks

union all
select *
from
parquet_blocks
)

select
block_number,
MIN(ts) as ts
from
combined_blocks
group by
block_number
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
with core_account_created as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'account_created') }} -- noqa
)

select
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
id,
cast(account_id as UInt128) as account_id,
owner
from core_account_created
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with core_account_created as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'legacy_market_proxy', 'account_migrated') }} -- noqa
)

select
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
id,
staker,
cast(account_id as UInt128) as account_id,
cast(collateral_amount as UInt256) as collateral_amount,
cast(debt_amount as UInt256) as debt_amount
from core_account_created
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
with delegation_updated as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'delegation_updated') }} -- noqa
)

select
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
id,
sender,
cast(account_id as UInt128) as account_id,
cast(pool_id as UInt128) as pool_id,
collateral_type,
cast(amount as UInt256) as amount,
cast(leverage as UInt256) as leverage
from
delegation_updated
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with core_deposited as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'deposited') }} -- noqa
)

select
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
id,
sender,
cast(account_id as UInt128) as account_id,
collateral_type,
cast(token_amount as UInt256) as token_amount
from core_deposited
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
with core_liquidation as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'liquidation') }} -- noqa
)

select
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
id,
sender,
liquidation_data,
cast(account_id as UInt128) as account_id,
cast(pool_id as UInt128) as pool_id,
collateral_type,
cast(liquidate_as_account_id as UInt128) as liquidate_as_account_id
from core_liquidation
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
with core_market_registered as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'market_registered') }} -- noqa
)

select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
sender,
market,
cast(market_id as UInt128) as market_id
from core_market_registered
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
with events as (
select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
sender,
collateral_type,
cast(market_id as UInt128) as market_id,
cast(net_issuance as Int128) as net_issuance,
cast(
deposited_collateral_value as UInt256
) as deposited_collateral_value,
cast(credit_capacity as Int128) as credit_capacity,
cast(token_amount as UInt256) as token_amount
from
(
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'market_collateral_deposited') }} -- noqa
) as collateral_deposited -- noqa: AL05
union all
select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
sender,
collateral_type,
cast(market_id as UInt128) as market_id,
cast(net_issuance as Int128) as net_issuance,
cast(
deposited_collateral_value as UInt256
) as deposited_collateral_value,
cast(credit_capacity as Int128) as credit_capacity,
cast(token_amount as UInt256) as token_amount
from
(
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'market_collateral_withdrawn') }} -- noqa
) as collateral_withdrawn -- noqa: AL05
union all
select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
target as sender,
'USD' as collateral_type,
cast(market_id as UInt128) as market_id,
cast(net_issuance as Int128) as net_issuance,
cast(
deposited_collateral_value as UInt256
) as deposited_collateral_value,
cast(credit_capacity as Int128) as credit_capacity,
cast(amount as UInt256) as token_amount
from
(
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'market_usd_deposited') }} -- noqa
) as usd_deposited -- noqa: AL05
union all
select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
target as sender,
'USD' as collateral_type,
cast(market_id as UInt128) as market_id,
cast(net_issuance as Int128) as net_issuance,
cast(
deposited_collateral_value as UInt256
) as deposited_collateral_value,
cast(credit_capacity as Int128) as credit_capacity,
cast(amount as UInt256) as token_amount
from
(
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'market_usd_withdrawn') }} -- noqa
) as usd_withdrawn -- noqa: AL05
)

select *
from
events
order by
block_timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
with core_pool_created as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'pool_created') }} -- noqa
)

select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
sender,
owner,
cast(pool_id as UInt128) as pool_id
from core_pool_created
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
with core_rewards_claimed as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'rewards_claimed') }} -- noqa
)

select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
cast(account_id as UInt128) as account_id,
cast(pool_id as UInt128) as pool_id,
collateral_type,
distributor,
cast(amount as UInt256) as amount
from core_rewards_claimed
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
with core_rewards_distributed as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'rewards_distributed') }} -- noqa
)

select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
cast(pool_id as UInt128) as pool_id,
collateral_type,
distributor,
cast(amount as UInt256) as amount,
cast(start as UInt256) as start, -- noqa
cast(duration as UInt256) as duration
from core_rewards_distributed
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
with core_usd_burned as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'usd_burned') }} -- noqa
)

select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
sender,
cast(account_id as UInt128) as account_id,
cast(pool_id as UInt128) as pool_id,
collateral_type,
cast(amount as UInt256) as amount
from core_usd_burned
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
with core_usd_minted as (
{{ get_event_data('eth', 'mainnet', 'synthetix', 'core_proxy', 'usd_minted') }} -- noqa
)

select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
sender,
cast(account_id as UInt128) as account_id,
cast(pool_id as UInt128) as pool_id,
collateral_type,
cast(amount as UInt256) as amount
from core_usd_minted
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
with base as (
select
block_number,
contract_address,
chain_id,
cast(pool_id as Int128) as pool_id,
collateral_type,
cast(
amount as UInt256
) as amount,
cast(
value as UInt256
) as collateral_value
from
{{ source(
'raw_eth_mainnet',
'get_vault_collateral'
) }}
where
amount is not null
)

select
from_unixtime(blocks.timestamp) as ts,
cast(
blocks.block_number as integer
) as block_number,
base.contract_address,
base.pool_id,
base.collateral_type,
{{ convert_wei('base.amount') }} as amount,
{{ convert_wei('base.collateral_value') }} as collateral_value
from
base
inner join {{ source('raw_eth_mainnet', 'blocks_parquet') }} as blocks
on base.block_number = blocks.block_number
Loading

0 comments on commit 76463b1

Please sign in to comment.