Skip to content

Commit

Permalink
lint models
Browse files Browse the repository at this point in the history
  • Loading branch information
Tburm committed Nov 26, 2024
1 parent 30afde6 commit 36ad20d
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -1,71 +1,77 @@
WITH synths AS (
SELECT
synth_market_id AS collateral_id,
with synths as (
select
synth_market_id as collateral_id,
synth_token_address
FROM
from
{{ ref('spot_synth_registered_base_mainnet') }}
),
transfers AS (
SELECT

transfers as (
select
cm.block_number,
cm.block_timestamp AS ts,
cm.block_timestamp as ts,
cm.transaction_hash,
cm.collateral_id,
synths.synth_token_address,
CAST(
cm.account_id AS text
) AS account_id,
{{ convert_wei('cm.amount_delta') }} AS amount_delta
FROM
{{ ref('perp_collateral_modified_base_mainnet') }} AS cm
INNER JOIN synths
ON cm.collateral_id = synths.collateral_id
cm.account_id as text
) as account_id,
{{ convert_wei('cm.amount_delta') }} as amount_delta
from
{{ ref('perp_collateral_modified_base_mainnet') }} as cm
inner join synths
on cm.collateral_id = synths.collateral_id
),
liq_tx AS (
SELECT
DISTINCT transaction_hash,

liq_tx as (
select distinct
transaction_hash,
CAST(
account_id AS text
) AS account_id
FROM
account_id as text
) as account_id
from
{{ ref('perp_account_liquidation_attempt_base_mainnet') }}
),
distributors AS (
SELECT

distributors as (
select
CAST(
rd.distributor_address AS text
) AS distributor_address,
rd.distributor_address as text
) as distributor_address,
CAST(
rd.token_symbol AS text
) AS token_symbol,
rd.token_symbol as text
) as token_symbol,
rd.synth_token_address,
synths.collateral_id
FROM
{{ ref('base_mainnet_reward_distributors') }} AS rd
INNER JOIN synths
ON rd.synth_token_address = synths.synth_token_address
from
{{ ref('base_mainnet_reward_distributors') }} as rd
inner join synths
on rd.synth_token_address = synths.synth_token_address
),
liquidations AS (
SELECT

liquidations as (
select
rd.block_number,
rd.block_timestamp AS ts,- rd.amount / 1e18 AS amount_delta,
rd.block_timestamp as ts,
-rd.amount / 1e18 as amount_delta,
liq_tx.transaction_hash,
rd.collateral_type,
distributors.token_symbol,
distributors.synth_token_address,
CAST(
liq_tx.account_id AS text
) AS account_id,
liq_tx.account_id as text
) as account_id,
distributors.collateral_id
FROM
{{ ref('core_rewards_distributed_base_mainnet') }} AS rd
INNER JOIN liq_tx
ON rd.transaction_hash = liq_tx.transaction_hash
INNER JOIN distributors
ON rd.distributor = distributors.distributor_address
from
{{ ref('core_rewards_distributed_base_mainnet') }} as rd
inner join liq_tx
on rd.transaction_hash = liq_tx.transaction_hash
inner join distributors
on rd.distributor = distributors.distributor_address
),
net_transfers AS (
SELECT

net_transfers as (
select
events.ts,
events.transaction_hash,
events.event_type,
Expand All @@ -78,52 +84,55 @@ net_transfers AS (
SUM(
events.amount_delta
) over (
PARTITION BY events.account_id,
events.collateral_id
ORDER BY
partition by
events.account_id,
events.collateral_id
order by
events.ts
) AS account_balance,
) as account_balance,
SUM(
events.amount_delta
) over (
PARTITION BY events.collateral_id
ORDER BY
partition by events.collateral_id
order by
events.ts
) AS total_balance
FROM
) as total_balance
from
(
SELECT
select
transfers.ts,
transfers.transaction_hash,
transfers.collateral_id,
transfers.synth_token_address,
transfers.account_id,
transfers.amount_delta,
'transfer' AS event_type
FROM
'transfer' as event_type
from
transfers
UNION ALL
SELECT
union all
select
liquidations.ts,
liquidations.transaction_hash,
liquidations.collateral_id,
liquidations.synth_token_address,
liquidations.account_id,
liquidations.amount_delta,
'liquidation' AS event_type
FROM
'liquidation' as event_type
from
liquidations
) AS events
INNER JOIN {{ ref('base_mainnet_synths') }} AS synths
ON events.collateral_id = synths.synth_market_id
LEFT JOIN {{ ref('fct_prices_hourly_base_mainnet') }} AS prices
ON synths.token_symbol = prices.market_symbol
AND DATE_TRUNC(
'hour',
events.ts
) = prices.ts
) as events
inner join {{ ref('base_mainnet_synths') }} as synths
on events.collateral_id = synths.synth_market_id
left join {{ ref('fct_prices_hourly_base_mainnet') }} as prices
on
synths.token_symbol = prices.market_symbol
and DATE_TRUNC(
'hour',
events.ts
) = prices.ts
)
SELECT

select
net_transfers.ts,
net_transfers.transaction_hash,
net_transfers.event_type,
Expand All @@ -133,10 +142,10 @@ SELECT
net_transfers.account_id,
net_transfers.price,
net_transfers.amount_delta,
net_transfers.amount_delta * net_transfers.price AS amount_delta_usd,
net_transfers.amount_delta * net_transfers.price as amount_delta_usd,
net_transfers.account_balance,
net_transfers.account_balance * net_transfers.price AS account_balance_usd,
net_transfers.account_balance * net_transfers.price as account_balance_usd,
net_transfers.total_balance,
net_transfers.total_balance * net_transfers.price AS total_balance_usd
FROM
net_transfers.total_balance * net_transfers.price as total_balance_usd
from
net_transfers
Loading

0 comments on commit 36ad20d

Please sign in to comment.