Skip to content

Commit

Permalink
deploy: b7f68a8
Browse files Browse the repository at this point in the history
Tburm committed Nov 7, 2024
0 parents commit b44f6b9
Showing 4,045 changed files with 65,021 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Empty file added .nojekyll
Empty file.
1 change: 1 addition & 0 deletions catalog.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


with delegated as (
select distinct
block_timestamp,
account_id,
'Delegated' as account_action
from "analytics"."prod_raw_arbitrum_mainnet"."core_delegation_updated_arbitrum_mainnet"
),

withdrawn as (
select
block_timestamp,
account_id,
'Withdrawn' as account_action
from "analytics"."prod_raw_arbitrum_mainnet"."core_withdrawn_arbitrum_mainnet"
),

claimed as (
select
block_timestamp,
account_id,
'Claimed' as account_action
from "analytics"."prod_raw_arbitrum_mainnet"."core_rewards_claimed_arbitrum_mainnet"
),

combined as (
select * from delegated
union all
select * from withdrawn
union all
select * from claimed
)

select
block_timestamp,
account_action,
account_id
from combined
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
with delegation_changes as (
select
block_timestamp,
account_id,
pool_id,
collateral_type,

amount / 1e18

- LAG(
amount / 1e18
, 1, 0) over (
partition by
account_id,
pool_id,
collateral_type
order by
block_timestamp
) as change_in_amount
from
"analytics"."prod_raw_arbitrum_mainnet"."core_delegation_updated_arbitrum_mainnet"
),

cumulative_delegation as (
select
block_timestamp,
account_id,
pool_id,
collateral_type,
SUM(change_in_amount) over (
partition by
pool_id,
account_id,
collateral_type
order by
block_timestamp
) as cumulative_amount_delegated,
ROW_NUMBER() over (
partition by
pool_id,
account_id,
collateral_type
order by
block_timestamp desc
) as rn
from
delegation_changes
)

select
block_timestamp as ts,
pool_id,
collateral_type,
cumulative_amount_delegated as amount_delegated,
CAST(
account_id as text
) as account_id
from
cumulative_delegation
where
rn = 1
order by
block_timestamp,
collateral_type
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@


with delegation_updated as (
select
block_timestamp,
account_id,
amount
from "analytics"."prod_raw_arbitrum_mainnet"."core_delegation_updated_arbitrum_mainnet"
),

dim as (
select
d.block_date,
accounts_unique.account_id
from (
select
generate_series(
date_trunc('day', date('2023-12-15')),
date_trunc('day', current_date), '1 day'::interval
) as block_date
) as d
cross join (
select distinct account_id from delegation_updated
) as accounts_unique
),

stakers as (
select
dim.block_date,
dim.account_id,
case
when coalesce(last(delegation_updated.amount) over (
partition by dim.account_id
order by dim.block_date
rows between unbounded preceding and current row
), 0) = 0 then 0
else 1
end as is_staking
from dim
left join delegation_updated on
dim.block_date = date(delegation_updated.block_timestamp)
and dim.account_id = delegation_updated.account_id
)

select
block_date,
sum(is_staking) as nof_stakers_daily
from stakers
group by block_date
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@


with pnl_hourly as (
select
ts,
pool_id,
collateral_type,
collateral_value,
debt,
hourly_pnl,
hourly_issuance,
rewards_usd,
hourly_pnl_pct,
hourly_rewards_pct,
hourly_total_pct,
SUM(
COALESCE(
hourly_issuance,
0
)
) over (
partition by
pool_id,
collateral_type
order by
ts
) as cumulative_issuance,
SUM(
hourly_pnl
) over (
partition by
pool_id,
collateral_type
order by
ts
) as cumulative_pnl
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
),

avg_returns as (
select
ts,
pool_id,
collateral_type,
AVG(
hourly_pnl_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '24 HOURS' preceding
and current row
) as avg_24h_pnl_pct,
AVG(
hourly_pnl_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '7 DAYS' preceding
and current row
) as avg_7d_pnl_pct,
AVG(
hourly_pnl_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '28 DAYS' preceding
and current row
) as avg_28d_pnl_pct,
AVG(
hourly_rewards_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '24 HOURS' preceding
and current row
) as avg_24h_rewards_pct,
AVG(
hourly_rewards_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '7 DAYS' preceding
and current row
) as avg_7d_rewards_pct,
AVG(
hourly_rewards_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '28 DAYS' preceding
and current row
) as avg_28d_rewards_pct,
AVG(
hourly_total_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '24 HOURS' preceding
and current row
) as avg_24h_total_pct,
AVG(
hourly_total_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '7 DAYS' preceding
and current row
) as avg_7d_total_pct,
AVG(
hourly_total_pct
) over (
partition by
pool_id,
collateral_type
order by
ts
range between interval '28 DAYS' preceding
and current row
) as avg_28d_total_pct
from
pnl_hourly
),

apr_calculations as (
select
pnl_hourly.ts,
pnl_hourly.pool_id,
pnl_hourly.collateral_type,
pnl_hourly.collateral_value,
pnl_hourly.debt,
pnl_hourly.hourly_pnl,
pnl_hourly.cumulative_pnl,
pnl_hourly.hourly_issuance,
pnl_hourly.cumulative_issuance,
pnl_hourly.rewards_usd,
pnl_hourly.hourly_pnl_pct,
pnl_hourly.hourly_rewards_pct,
-- total pnls
avg_returns.avg_24h_total_pct * 24 * 365 as apr_24h,
avg_returns.avg_7d_total_pct * 24 * 365 as apr_7d,
avg_returns.avg_28d_total_pct * 24 * 365 as apr_28d,
-- pool pnls
avg_returns.avg_24h_pnl_pct * 24 * 365 as apr_24h_pnl,
avg_returns.avg_7d_pnl_pct * 24 * 365 as apr_7d_pnl,
avg_returns.avg_28d_pnl_pct * 24 * 365 as apr_28d_pnl,
-- rewards pnls
avg_returns.avg_24h_rewards_pct * 24 * 365 as apr_24h_rewards,
avg_returns.avg_7d_rewards_pct * 24 * 365 as apr_7d_rewards,
avg_returns.avg_28d_rewards_pct * 24 * 365 as apr_28d_rewards
from
pnl_hourly
inner join avg_returns
on
pnl_hourly.ts = avg_returns.ts
and pnl_hourly.pool_id = avg_returns.pool_id
and pnl_hourly.collateral_type = avg_returns.collateral_type
),

apy_calculations as (
select
*,
(POWER(1 + apr_24h / 8760, 8760) - 1) as apy_24h,
(POWER(1 + apr_7d / 8760, 8760) - 1) as apy_7d,
(POWER(1 + apr_28d / 8760, 8760) - 1) as apy_28d,
(POWER(1 + apr_24h_pnl / 8760, 8760) - 1) as apy_24h_pnl,
(POWER(1 + apr_7d_pnl / 8760, 8760) - 1) as apy_7d_pnl,
(POWER(1 + apr_28d_pnl / 8760, 8760) - 1) as apy_28d_pnl,
(POWER(1 + apr_24h_rewards / 8760, 8760) - 1) as apy_24h_rewards,
(POWER(1 + apr_7d_rewards / 8760, 8760) - 1) as apy_7d_rewards,
(POWER(1 + apr_28d_rewards / 8760, 8760) - 1) as apy_28d_rewards
from
apr_calculations
)

select
ts,
pool_id,
collateral_type,
collateral_value,
debt,
hourly_issuance,
hourly_pnl,
cumulative_pnl,
cumulative_issuance,
rewards_usd,
hourly_pnl_pct,
hourly_rewards_pct,
apr_24h,
apy_24h,
apr_7d,
apy_7d,
apr_28d,
apy_28d,
apr_24h_pnl,
apy_24h_pnl,
apr_7d_pnl,
apy_7d_pnl,
apr_28d_pnl,
apy_28d_pnl,
apr_24h_rewards,
apy_24h_rewards,
apr_7d_rewards,
apy_7d_rewards,
apr_28d_rewards,
apy_28d_rewards
from
apy_calculations
order by
ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@


with pnl_hourly as (
select
ts,
pool_id,
collateral_type,
reward_token,
collateral_value,
rewards_usd,
hourly_rewards_pct
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_reward_arbitrum_mainnet"
),

avg_returns as (
select
ts,
pool_id,
collateral_type,
reward_token,
AVG(
hourly_rewards_pct
) over (
partition by
pool_id,
collateral_type,
reward_token
order by
ts
range between interval '24 HOURS' preceding
and current row
) as avg_24h_rewards_pct,
AVG(
hourly_rewards_pct
) over (
partition by
pool_id,
collateral_type,
reward_token
order by
ts
range between interval '7 DAYS' preceding
and current row
) as avg_7d_rewards_pct,
AVG(
hourly_rewards_pct
) over (
partition by
pool_id,
collateral_type,
reward_token
order by
ts
range between interval '28 DAYS' preceding
and current row
) as avg_28d_rewards_pct
from
pnl_hourly
),

apr_calculations as (
select
pnl_hourly.ts,
pnl_hourly.pool_id,
pnl_hourly.collateral_type,
pnl_hourly.reward_token,
pnl_hourly.collateral_value,
pnl_hourly.rewards_usd,
pnl_hourly.hourly_rewards_pct,
avg_returns.avg_24h_rewards_pct * 24 * 365 as apr_24h_rewards,
avg_returns.avg_7d_rewards_pct * 24 * 365 as apr_7d_rewards,
avg_returns.avg_28d_rewards_pct * 24 * 365 as apr_28d_rewards
from
pnl_hourly
inner join avg_returns
on
pnl_hourly.ts = avg_returns.ts
and pnl_hourly.pool_id = avg_returns.pool_id
and pnl_hourly.collateral_type = avg_returns.collateral_type
and pnl_hourly.reward_token = avg_returns.reward_token
),

apy_calculations as (
select
*,
(POWER(1 + apr_24h_rewards / 8760, 8760) - 1) as apy_24h_rewards,
(POWER(1 + apr_7d_rewards / 8760, 8760) - 1) as apy_7d_rewards,
(POWER(1 + apr_28d_rewards / 8760, 8760) - 1) as apy_28d_rewards
from
apr_calculations
)

select
ts,
pool_id,
collateral_type,
reward_token,
collateral_value,
rewards_usd,
hourly_rewards_pct,
apr_24h_rewards,
apy_24h_rewards,
apr_7d_rewards,
apy_7d_rewards,
apr_28d_rewards,
apy_28d_rewards
from
apy_calculations
order by
ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
with market_updated as (
select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
market_id,
net_issuance,
sender,
collateral_type,
credit_capacity,
token_amount
from
"analytics"."prod_raw_arbitrum_mainnet"."core_market_updated_arbitrum_mainnet"
)

select
id,
block_timestamp as ts,
transaction_hash,
event_name,
market_id,
collateral_type,

credit_capacity / 1e18
as credit_capacity,

net_issuance / 1e18
as net_issuance,

token_amount / 1e18
as token_amount
from
market_updated
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
with events as (
select
block_timestamp,

token_amount / 1e18
as token_amount,
collateral_type
from
"analytics"."prod_raw_arbitrum_mainnet"."core_deposited_arbitrum_mainnet"
union all
select
block_timestamp,
-
token_amount / 1e18
as token_amount,
collateral_type
from
"analytics"."prod_raw_arbitrum_mainnet"."core_withdrawn_arbitrum_mainnet"
),

ranked_events as (
select
*,
SUM(token_amount) over (
partition by collateral_type
order by
block_timestamp
rows between unbounded preceding
and current row
) as amount_deposited
from
events
)

select
block_timestamp as ts,
collateral_type,
amount_deposited
from
ranked_events
order by
block_timestamp,
collateral_type
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
with delegation_changes as (
select
block_timestamp,
account_id,
pool_id,
collateral_type,

amount / 1e18

- LAG(
amount / 1e18
, 1, 0) over (
partition by
account_id,
pool_id,
collateral_type
order by
block_timestamp
) as change_in_amount
from
"analytics"."prod_raw_arbitrum_mainnet"."core_delegation_updated_arbitrum_mainnet"
),

cumulative_delegation as (
select
block_timestamp,
pool_id,
collateral_type,
SUM(change_in_amount) over (
partition by
pool_id,
collateral_type
order by
block_timestamp
) as cumulative_amount_delegated
from
delegation_changes
)

select
block_timestamp as ts,
pool_id,
collateral_type,
cumulative_amount_delegated as amount_delegated
from
cumulative_delegation
order by
block_timestamp,
collateral_type
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
with base as (
select
pool_id as id,
block_timestamp as created_ts,
block_number,
owner
from
"analytics"."prod_raw_arbitrum_mainnet"."core_pool_created_arbitrum_mainnet"
)

select *
from
base
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
select
ts,
block_number,
pool_id,
collateral_type,
debt
from
"analytics"."prod_raw_arbitrum_mainnet"."core_vault_debt_arbitrum_mainnet"
order by
ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
with burns as (
select
block_timestamp as ts,
block_number,
transaction_hash,
pool_id,
collateral_type,
account_id,
-1 *
amount / 1e18
as amount
from
"analytics"."prod_raw_arbitrum_mainnet"."core_usd_burned_arbitrum_mainnet"
order by
block_timestamp desc
),

mints as (
select
block_timestamp as ts,
block_number,
transaction_hash,
pool_id,
collateral_type,
account_id,

amount / 1e18
as amount
from
"analytics"."prod_raw_arbitrum_mainnet"."core_usd_minted_arbitrum_mainnet"
order by
block_timestamp desc
)

select *
from
burns
union all
select *
from
mints
order by
ts desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
with dim as (
select
m.pool_id,
m.collateral_type,
generate_series(
date_trunc('hour', min(t.ts)),
date_trunc('hour', max(t.ts)),
'1 hour'::interval
) as ts
from
(
select ts
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
) as t
cross join (
select distinct
pool_id,
collateral_type
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
) as m
group by
m.pool_id,
m.collateral_type
),

max_debt_block as (
select
pool_id,
collateral_type,
date_trunc(
'hour',
ts
) as "hour",
max(block_number) as max_block_number
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
group by
date_trunc(
'hour',
ts
),
pool_id,
collateral_type
),

filt_issuance as (
select
i.pool_id,
i.collateral_type,
i.amount,
case
when
i.block_number <= d.max_block_number
or d.max_block_number is null then i.ts
else i.ts + interval '1 hour'
end as ts
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
as i
left join max_debt_block as d
on date_trunc(
'hour',
i.ts
) = d.hour
and i.pool_id = d.pool_id
and lower(
i.collateral_type
) = lower(
d.collateral_type
)
where
i.block_number <= (
select
max(
max_block_number
) as b
from
max_debt_block
)
),

issuance as (
select
date_trunc(
'hour',
ts
) as ts,
pool_id,
collateral_type,
sum(amount) as hourly_issuance
from
filt_issuance
group by
date_trunc(
'hour',
ts
),
pool_id,
collateral_type
)

select
dim.ts,
dim.pool_id,
dim.collateral_type,
coalesce(
i.hourly_issuance,
0
) as hourly_issuance
from
dim
left join issuance as i
on
dim.pool_id = i.pool_id
and lower(
dim.collateral_type
) = lower(
i.collateral_type
)
and dim.ts = i.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@


with dim as (
select
p.pool_id,
p.collateral_type,
generate_series(
date_trunc('hour', min(t.ts)),
date_trunc('hour', max(t.ts)),
'1 hour'::INTERVAL
) as ts
from
(
select ts
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
) as t
cross join (
select distinct
pool_id,
collateral_type
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
) as p
group by
p.pool_id,
p.collateral_type
),

issuance as (
select
ts,
pool_id,
collateral_type,
hourly_issuance
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_hourly_arbitrum_mainnet"
),

debt as (
select distinct
pool_id,
collateral_type,
date_trunc(
'hour',
ts
) as ts,
last_value(debt) over (
partition by date_trunc('hour', ts), pool_id, collateral_type
order by
ts
rows between unbounded preceding
and unbounded following
) as debt
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
),

collateral as (
select distinct
pool_id,
collateral_type,
date_trunc(
'hour',
ts
) as ts,
last_value(collateral_value) over (
partition by date_trunc('hour', ts), pool_id, collateral_type
order by
ts
rows between unbounded preceding
and unbounded following
) as collateral_value
from
"analytics"."prod_raw_arbitrum_mainnet"."core_vault_collateral_arbitrum_mainnet"
where
pool_id = 1
),

ffill as (
select
dim.ts,
dim.pool_id,
dim.collateral_type,
coalesce(
last(debt) over (
partition by dim.collateral_type, dim.pool_id
order by dim.ts
rows between unbounded preceding and current row
),
0
) as debt,
coalesce(
last(collateral_value) over (
partition by dim.collateral_type, dim.pool_id
order by dim.ts
rows between unbounded preceding and current row
),
0
) as collateral_value
from
dim
left join debt
on
dim.ts = debt.ts
and dim.pool_id = debt.pool_id
and dim.collateral_type = debt.collateral_type
left join collateral
on
dim.ts = collateral.ts
and dim.pool_id = collateral.pool_id
and dim.collateral_type = collateral.collateral_type
),

hourly_pnl as (
select
ts,
pool_id,
collateral_type,
collateral_value,
debt,
coalesce(lag(debt) over (
partition by pool_id, collateral_type
order by
ts
) - debt, 0) as hourly_pnl
from
ffill
),

hourly_rewards as (
select
ts,
pool_id,
collateral_type,
rewards_usd
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_hourly_arbitrum_mainnet"
),

hourly_returns as (
select
pnl.ts,
pnl.pool_id,
pnl.collateral_type,
pnl.collateral_value,
pnl.debt,
coalesce(
iss.hourly_issuance,
0
) as hourly_issuance,
pnl.hourly_pnl + coalesce(
iss.hourly_issuance,
0
) as hourly_pnl,
coalesce(
rewards.rewards_usd,
0
) as rewards_usd,
case
when pnl.collateral_value = 0 then 0
else coalesce(
rewards.rewards_usd,
0
) / pnl.collateral_value
end as hourly_rewards_pct,
case
when pnl.collateral_value = 0 then 0
else
(coalesce(iss.hourly_issuance, 0) + pnl.hourly_pnl)
/ pnl.collateral_value
end as hourly_pnl_pct,
case
when pnl.collateral_value = 0 then 0
else
(
coalesce(rewards.rewards_usd, 0)
+ pnl.hourly_pnl
+ coalesce(iss.hourly_issuance, 0)
)
/ pnl.collateral_value
end as hourly_total_pct
from
hourly_pnl as pnl
left join hourly_rewards as rewards
on
pnl.ts = rewards.ts
and pnl.pool_id = rewards.pool_id
and lower(pnl.collateral_type) = lower(rewards.collateral_type)
left join issuance as iss
on
pnl.ts = iss.ts
and pnl.pool_id = iss.pool_id
and lower(
pnl.collateral_type
) = lower(
iss.collateral_type
)
)

select
ts,
pool_id,
collateral_type,
collateral_value,
debt,
hourly_issuance,
hourly_pnl,
rewards_usd,
hourly_pnl_pct,
hourly_rewards_pct,
hourly_total_pct
from
hourly_returns
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@


with dim as (

select
t.ts,
t.pool_id,
t.collateral_type,
t.collateral_value,
p.token_symbol as reward_token
from
(
select
ts,
collateral_type,
pool_id,
collateral_value
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
group by
ts,
collateral_type,
pool_id,
collateral_value
) as t
cross join (
select distinct token_symbol
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
) as p
group by
t.ts,
t.pool_id,
t.collateral_type,
t.collateral_value,
p.token_symbol
),

reward_hourly_token as (
select
ts,
pool_id,
collateral_type,
token_symbol as reward_token,
SUM(
rewards_usd
) as rewards_usd
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
group by
ts,
pool_id,
collateral_type,
token_symbol
)

select
dim.ts,
dim.pool_id,
dim.collateral_type,
dim.collateral_value,
dim.reward_token,
COALESCE(
reward_hourly_token.rewards_usd,
0
) as rewards_usd,
case
when dim.collateral_value = 0 then 0
else COALESCE(
reward_hourly_token.rewards_usd,
0
) / dim.collateral_value
end as hourly_rewards_pct
from
dim
left join reward_hourly_token
on
dim.ts = reward_hourly_token.ts
and dim.pool_id = reward_hourly_token.pool_id
and LOWER(dim.collateral_type)
= LOWER(reward_hourly_token.collateral_type)
and dim.reward_token = reward_hourly_token.reward_token
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
with rewards_distributed as (
select
block_timestamp as ts,
CAST(
pool_id as INTEGER
) as pool_id,
collateral_type,
distributor,

amount / 1e18
as amount,
TO_TIMESTAMP("start") as ts_start,
"duration"
from
"analytics"."prod_raw_arbitrum_mainnet"."core_rewards_distributed_arbitrum_mainnet"
),

distributors as (
select
CAST(distributor_address as TEXT) as distributor_address,
CAST(token_symbol as TEXT) as token_symbol
from
"analytics"."prod_seeds"."arbitrum_mainnet_reward_distributors"
)

select
rd.ts,
rd.pool_id,
rd.collateral_type,
rd.distributor,
distributors.token_symbol,
rd.amount,
rd.ts_start,
rd.duration
from
rewards_distributed as rd
inner join distributors on rd.distributor = distributors.distributor_address
order by
rd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
with token_hourly as (
select
ts,
pool_id,
collateral_type,
rewards_usd
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
)

select
ts,
pool_id,
collateral_type,
SUM(rewards_usd) as rewards_usd
from
token_hourly
group by
ts,
pool_id,
collateral_type
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
with dim as (
select
m.pool_id,
m.collateral_type,
generate_series(
date_trunc('hour', min(t.min_ts)),
date_trunc('hour', max(t.max_ts)),
'1 hour'::INTERVAL
) as ts
from
(
select
min(ts_start) as min_ts,
max(
ts_start + "duration" * '1 second'::INTERVAL
) as max_ts
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
) as t
cross join (
select distinct
pool_id,
collateral_type
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
) as m
group by
m.pool_id,
m.collateral_type
),

rewards_distributed as (
select
ts,
pool_id,
collateral_type,
distributor,
token_symbol,
amount,
ts_start,
"duration"
from
"analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
),

hourly_distributions as (
select
dim.ts,
dim.pool_id,
dim.collateral_type,
r.distributor,
r.token_symbol,
r.amount,
r.ts_start,
r."duration",
row_number() over (
partition by
dim.ts,
dim.pool_id,
dim.collateral_type,
r.distributor
order by
r.ts_start desc
) as distributor_index
from
dim
left join rewards_distributed as r
on
dim.pool_id = r.pool_id
and lower(
dim.collateral_type
) = lower(
r.collateral_type
)
and dim.ts + '1 hour'::INTERVAL >= r.ts_start
and dim.ts < r.ts_start + r."duration" * '1 second'::INTERVAL
where
r."duration" > 0
),

streamed_rewards as (
select
d.ts,
d.pool_id,
d.collateral_type,
d.distributor,
d.token_symbol,
-- get the amount of time distributed this hour
-- use the smaller of those two intervals
-- convert the interval to a number of hours
-- multiply the result by the hourly amount to get the amount distributed this hour
(
extract(
epoch
from
least(
d."duration" / 3600 * '1 hour'::INTERVAL,
least(
d.ts + '1 hour'::INTERVAL - greatest(
d.ts,
d.ts_start
),
least(
d.ts_start + d."duration" * '1 second'::INTERVAL,
d.ts + '1 hour'::INTERVAL
) - d.ts
)
)
) / 3600
) * d.amount / (
d."duration" / 3600
) as amount
from
hourly_distributions as d
where
d.distributor_index = 1
),

instant_rewards as (
select
date_trunc(
'hour',
ts
) as ts,
pool_id,
collateral_type,
distributor,
token_symbol,
amount
from
rewards_distributed
where
"duration" = 0
),

combined as (
select
combo.ts,
combo.pool_id,
combo.collateral_type,
combo.distributor,
combo.token_symbol,
combo.amount,
p.price
from
(
select
ts,
pool_id,
collateral_type,
distributor,
token_symbol,
amount
from
streamed_rewards
union all
select
ts,
pool_id,
collateral_type,
distributor,
token_symbol,
amount
from
instant_rewards
) as combo
left join "analytics"."prod_arbitrum_mainnet"."fct_prices_hourly_arbitrum_mainnet" as p
on
combo.token_symbol = p.market_symbol
and combo.ts = p.ts
)

select
ts,
pool_id,
collateral_type,
distributor,
token_symbol,
sum(amount) as amount,
sum(
amount * price
) as rewards_usd
from
combined
group by
ts,
pool_id,
collateral_type,
distributor,
token_symbol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@




with all_values as (

select
account_action as value_field,
count(*) as n_records

from "analytics"."prod_arbitrum_mainnet"."fct_core_account_activity_arbitrum_mainnet"
group by account_action

)

select *
from all_values
where value_field not in (
'Delegated','Withdrawn','Claimed'
)


Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@




with all_values as (

select
event_name as value_field,
count(*) as n_records

from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
group by event_name

)

select *
from all_values
where value_field not in (
'MarketCollateralWithdrawn','MarketCollateralDeposited','MarketUsdWithdrawn','MarketUsdDeposited'
)


Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_delegation_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not hourly_rewards_pct >= 0
-- records with a value <= max_value are permitted. The `not` flips this to find records that don't meet the rule.
or not hourly_rewards_pct <= 1
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not hourly_pnl_pct >= -1
-- records with a value <= max_value are permitted. The `not` flips this to find records that don't meet the rule.
or not hourly_pnl_pct <= 1
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_pool_delegation_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not rewards_usd >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not market_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_pools_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_delegation_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not amount_delegated >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not collateral_value >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not hourly_rewards_pct >= 0
-- records with a value <= max_value are permitted. The `not` flips this to find records that don't meet the rule.
or not hourly_rewards_pct <= 1
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not collateral_value >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not amount >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not pool_id >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not amount >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not rewards_usd >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not hourly_pnl_pct >= -1
-- records with a value <= max_value are permitted. The `not` flips this to find records that don't meet the rule.
or not hourly_pnl_pct <= 1
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not rewards_usd >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


with meet_condition as(
select *
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
),

validation_errors as (
select *
from meet_condition
where
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds
1 = 2
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule.
or not rewards_usd >= 0
)

select *
from validation_errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select account_action
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_activity_arbitrum_mainnet"
where account_action is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select block_timestamp
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_activity_arbitrum_mainnet"
where block_timestamp is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select account_id
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_activity_arbitrum_mainnet"
where account_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_delegation_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select account_id
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_delegation_arbitrum_mainnet"
where account_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select amount_delegated
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_delegation_arbitrum_mainnet"
where amount_delegated is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_delegation_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_core_account_delegation_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select block_date
from "analytics"."prod_arbitrum_mainnet"."fct_core_active_stakers_daily_arbitrum_mainnet"
where block_date is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select apr_24h
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where apr_24h is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select apr_28d
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where apr_28d is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select apr_7d
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where apr_7d is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select apy_24h
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where apy_24h is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select apy_28d
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where apy_28d is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select apy_7d
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where apy_7d is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_value
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where collateral_value is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select cumulative_issuance
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where cumulative_issuance is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select cumulative_pnl
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where cumulative_pnl is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select debt
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where debt is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_issuance
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where hourly_issuance is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_pnl
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where hourly_pnl is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_pnl_pct
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where hourly_pnl_pct is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_rewards_pct
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where hourly_rewards_pct is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select rewards_usd
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where rewards_usd is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_core_apr_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select transaction_hash
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where transaction_hash is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select credit_capacity
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where credit_capacity is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select event_name
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where event_name is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select id
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select market_id
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where market_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select net_issuance
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where net_issuance is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select token_amount
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where token_amount is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_core_pool_collateral_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select amount_deposited
from "analytics"."prod_arbitrum_mainnet"."fct_core_pool_collateral_arbitrum_mainnet"
where amount_deposited is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_core_pool_collateral_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_core_pool_delegation_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_core_pool_delegation_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_core_pool_delegation_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select block_number
from "analytics"."prod_arbitrum_mainnet"."fct_core_pools_arbitrum_mainnet"
where block_number is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select created_ts
from "analytics"."prod_arbitrum_mainnet"."fct_core_pools_arbitrum_mainnet"
where created_ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select id
from "analytics"."prod_arbitrum_mainnet"."fct_core_pools_arbitrum_mainnet"
where id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select owner
from "analytics"."prod_arbitrum_mainnet"."fct_core_pools_arbitrum_mainnet"
where owner is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select block_number
from "analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
where block_number is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select debt
from "analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
where debt is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_pool_debt_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select account_id
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
where account_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select amount
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
where amount is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select block_number
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
where block_number is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select transaction_hash
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
where transaction_hash is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_hourly_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_issuance
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_hourly_arbitrum_mainnet"
where hourly_issuance is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_hourly_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_pool_issuance_hourly_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_rewards_pct
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where hourly_rewards_pct is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_value
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where collateral_value is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select debt
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where debt is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_issuance
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where hourly_issuance is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_pnl
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where hourly_pnl is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_pnl_pct
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where hourly_pnl_pct is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select hourly_total_pct
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where hourly_total_pct is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select rewards_usd
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where rewards_usd is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_pool_pnl_hourly_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select amount
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
where amount is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select distributor
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
where distributor is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select token_symbol
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
where token_symbol is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_hourly_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_hourly_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select rewards_usd
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_hourly_arbitrum_mainnet"
where rewards_usd is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_hourly_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select token_symbol
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
where token_symbol is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select collateral_type
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
where collateral_type is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select distributor
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
where distributor is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select rewards_usd
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
where rewards_usd is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select amount
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
where amount is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select pool_id
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
where pool_id is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@






select ts
from "analytics"."prod_arbitrum_mainnet"."fct_pool_rewards_token_hourly_arbitrum_mainnet"
where ts is null


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@




select
id as unique_field,
count(*) as n_records

from "analytics"."prod_arbitrum_mainnet"."fct_core_market_updated_arbitrum_mainnet"
where id is not null
group by id
having count(*) > 1


Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@


with active_accounts as (
select distinct
date_trunc('day', ts) as activity_date,
account_id
from "analytics"."prod_arbitrum_mainnet"."fct_perp_trades_arbitrum_mainnet"
),

date_range as (
select
generate_series(
date(min(activity_date)),
date(max(activity_date)),
interval '1 day'
)::date as activity_date
from active_accounts
),

active_accounts_daily as (
select
date_range.activity_date,
count(distinct active_accounts.account_id) as active_accounts
from date_range
left join active_accounts
on date_range.activity_date = active_accounts.activity_date
group by date_range.activity_date
),

active_accounts_monthly as (
select
date_range.activity_date,
count(distinct active_accounts.account_id) as active_accounts
from date_range
left join active_accounts
on
date_range.activity_date - interval '27 days'
<= active_accounts.activity_date
and date_range.activity_date >= active_accounts.activity_date
group by date_range.activity_date
),

new_accounts as (
select
min(activity_date) as start_date,
account_id
from active_accounts
group by account_id
),

new_accounts_daily as (
select
date_range.activity_date,
count(new_accounts.account_id) as new_accounts
from date_range
left join new_accounts
on date_range.activity_date = new_accounts.start_date
group by date_range.activity_date, new_accounts.start_date
),

new_accounts_monthly as (
select distinct
activity_date,
sum(new_accounts) over (
order by activity_date
range between interval '27 days' preceding and current row
) as new_accounts
from new_accounts_daily
)

select
dr.activity_date as ts,
dau.active_accounts as dau,
mau.active_accounts as mau,
new_accounts_daily.new_accounts as new_accounts_daily,
new_accounts_monthly.new_accounts as new_accounts_monthly
from date_range as dr
left join active_accounts_daily as dau
on dr.activity_date = dau.activity_date
left join active_accounts_monthly as mau
on dr.activity_date = mau.activity_date
left join new_accounts_daily
on dr.activity_date = new_accounts_daily.activity_date
left join new_accounts_monthly
on dr.activity_date = new_accounts_monthly.activity_date
order by ts desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
with arbitrum as (
select
block_timestamp as created_ts,
"owner",
CAST(
account_id as VARCHAR
) as id
from
"analytics"."prod_raw_arbitrum_mainnet"."perp_account_created_arbitrum_mainnet"
)

select *
from
arbitrum
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
with synths as (
select
synth_market_id as collateral_id,
synth_token_address
from
"analytics"."prod_raw_arbitrum_mainnet"."spot_synth_registered_arbitrum_mainnet"
),

transfers as (
select
cm.block_number,
cm.block_timestamp as ts,
cm.transaction_hash,
cm.collateral_id,
synths.synth_token_address,
CAST(cm.account_id as text) as account_id,

cm.amount_delta / 1e18
as amount_delta
from
"analytics"."prod_raw_arbitrum_mainnet"."perp_collateral_modified_arbitrum_mainnet" as cm
inner join synths
on cm.collateral_id = synths.collateral_id
),

liq_tx as (
select distinct
transaction_hash,
CAST(account_id as text) as account_id
from
"analytics"."prod_raw_arbitrum_mainnet"."perp_account_liquidation_attempt_arbitrum_mainnet"
),

distributors as (
select
CAST(rd.distributor_address as text) as distributor_address,
CAST(rd.token_symbol as text) as token_symbol,
rd.synth_token_address,
synths.collateral_id
from
"analytics"."prod_seeds"."arbitrum_mainnet_reward_distributors" as rd
inner join synths
on rd.synth_token_address = synths.synth_token_address
),

liquidations as (
select
rd.block_number,
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,
distributors.collateral_id
from
"analytics"."prod_raw_arbitrum_mainnet"."core_rewards_distributed_arbitrum_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
events.ts,
events.transaction_hash,
events.event_type,
events.collateral_id,
events.synth_token_address,
synths.synth_symbol,
events.account_id,
prices.price,
events.amount_delta,
SUM(events.amount_delta) over (
partition by events.account_id, events.collateral_id
order by events.ts
) as account_balance,
SUM(events.amount_delta) over (
partition by events.collateral_id
order by events.ts
) as total_balance
from (
select
transfers.ts,
transfers.transaction_hash,
transfers.collateral_id,
transfers.synth_token_address,
transfers.account_id,
transfers.amount_delta,
'transfer' as event_type
from
transfers
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
liquidations
) as events
inner join "analytics"."prod_seeds"."arbitrum_mainnet_synths" as synths
on events.collateral_id = synths.synth_market_id
left join "analytics"."prod_arbitrum_mainnet"."fct_prices_hourly_arbitrum_mainnet" as prices
on
synths.token_symbol = prices.market_symbol
and DATE_TRUNC('hour', events.ts) = prices.ts
)

select
net_transfers.ts,
net_transfers.transaction_hash,
net_transfers.event_type,
net_transfers.collateral_id,
net_transfers.synth_token_address,
net_transfers.synth_symbol,
net_transfers.account_id,
net_transfers.price,
net_transfers.amount_delta,
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.total_balance,
net_transfers.total_balance * net_transfers.price as total_balance_usd
from
net_transfers
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
select
cm.id,
cm.block_timestamp,
cm.account_id,
cm.block_number,
cm.transaction_hash,
cm.contract,
cm.event_name,
synths.synth_symbol,
cm.collateral_id as synth_market_id,
synths.synth_token_address,
cm.sender,

cm.amount_delta / 1e18
as amount_delta
from
"analytics"."prod_raw_arbitrum_mainnet"."perp_collateral_modified_arbitrum_mainnet"
as cm
inner join "analytics"."prod_seeds"."arbitrum_mainnet_synths" as synths
on cm.collateral_id = synths.synth_market_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
select
id,
block_timestamp,
block_number,
transaction_hash,
contract,
event_name,
account_id,

interest / 1e18
as interest
from
"analytics"."prod_raw_arbitrum_mainnet"."perp_interest_charged_arbitrum_mainnet"
Loading

0 comments on commit b44f6b9

Please sign in to comment.