Skip to content

Commit

Permalink
deploy: 3b37679
Browse files Browse the repository at this point in the history
  • Loading branch information
Tburm committed Jul 30, 2024
0 parents commit 0498f96
Show file tree
Hide file tree
Showing 2,812 changed files with 43,806 additions and 0 deletions.
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,58 @@
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,
CAST(
account_id AS text
) AS account_id,
pool_id,
collateral_type,
cumulative_amount_delegated AS amount_delegated
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,207 @@
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 AS ts,
pnl_hourly.pool_id AS pool_id,
pnl_hourly.collateral_type AS collateral_type,
pnl_hourly.collateral_value AS collateral_value,
pnl_hourly.debt AS debt,
pnl_hourly.hourly_pnl AS hourly_pnl,
pnl_hourly.cumulative_pnl AS cumulative_pnl,
pnl_hourly.hourly_issuance AS hourly_issuance,
pnl_hourly.cumulative_issuance AS cumulative_issuance,
pnl_hourly.rewards_usd AS rewards_usd,
pnl_hourly.hourly_pnl_pct AS hourly_pnl_pct,
pnl_hourly.hourly_rewards_pct AS 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
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,98 @@
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 AS ts,
pnl_hourly.pool_id AS pool_id,
pnl_hourly.collateral_type AS collateral_type,
pnl_hourly.reward_token AS reward_token,
pnl_hourly.collateral_value AS collateral_value,
pnl_hourly.rewards_usd AS rewards_usd,
pnl_hourly.hourly_rewards_pct AS 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
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
Loading

0 comments on commit 0498f96

Please sign in to comment.