Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrum Sepolia dashboards #50

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dashboard/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
Page(f"{PAGE_PREFIX}pages/Base_Mainnet.py", "Base Mainnet"),
Page(f"{PAGE_PREFIX}pages/Base_Sepolia.py", "Base Sepolia"),
]
arb_pages = [
Page(f"{PAGE_PREFIX}pages/Arbitrum_Sepolia.py", "Arbitrum Sepolia"),
]

# pages to show
pages_to_show = home_page + (op_pages if SHOW_OP else []) + base_pages
pages_to_show = home_page + (op_pages if SHOW_OP else []) + base_pages + arb_pages
show_pages(pages_to_show)
169 changes: 169 additions & 0 deletions dashboard/modules/arbitrum_sepolia/core_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import streamlit as st
import pandas as pd
from datetime import datetime, timedelta
from utils import get_connection
from utils import chart_bars, chart_lines, export_data

## set default filters
filters = {
"start_date": datetime.today().date() - timedelta(days=14),
"end_date": datetime.today().date() + timedelta(days=1),
"resolution": "28d",
}


## data
@st.cache_data(ttl=600)
def fetch_data(filters):
# get filters
start_date = filters["start_date"]
end_date = filters["end_date"]
resolution = filters["resolution"]

# initialize connection
db = get_connection()

# get account data
df_account_delegation = pd.read_sql_query(
f"""
SELECT * FROM arbitrum_sepolia.fct_core_account_delegation
WHERE ts >= '{start_date}' and ts <= '{end_date}'
""",
db,
)

df_apr = pd.read_sql_query(
f"""
SELECT
ts,
coalesce(tk.token_symbol, collateral_type) as collateral_type,
collateral_value,
debt,
hourly_pnl,
hourly_issuance,
cumulative_issuance,
cumulative_pnl,
apr_{resolution} as apr,
apr_{resolution}_pnl as apr_pnl,
apr_{resolution}_rewards as apr_rewards
FROM arbitrum_sepolia.fct_core_apr apr
LEFT JOIN arbitrum_sepolia.arbitrum_sepolia_tokens tk on lower(apr.collateral_type) = lower(tk.token_address)
WHERE ts >= '{start_date}' and ts <= '{end_date}'
and pool_id = 1
ORDER BY ts
""",
db,
)

db.close()

return {
"account_delegation": df_account_delegation,
"apr": df_apr,
}


def make_charts(data, filters):
resolution = filters["resolution"]
return {
"collateral": chart_lines(
data["apr"],
"ts",
["collateral_value"],
"Collateral",
"collateral_type",
),
"debt": chart_lines(
data["apr"],
"ts",
["debt"],
"Debt",
"collateral_type",
),
"hourly_issuance": chart_bars(
data["apr"],
"ts",
["hourly_issuance"],
"Hourly Issuance",
"collateral_type",
),
"issuance": chart_lines(
data["apr"],
"ts",
["cumulative_issuance"],
"Issuance",
"collateral_type",
),
"pnl": chart_lines(
data["apr"],
"ts",
["cumulative_pnl"],
"Pnl",
"collateral_type",
),
"hourly_pnl": chart_bars(
data["apr"],
"ts",
["hourly_pnl"],
"Hourly Pnl",
),
"apr": chart_lines(
data["apr"],
"ts",
"apr",
f"APR - {resolution} average",
y_format="%",
color="collateral_type",
),
}


def main():
## title
st.markdown("## V3 Core")

## inputs
with st.expander("Filters"):
filters["resolution"] = st.radio(
"Resolution",
["28d", "7d", "24h"],
)

filt_col1, filt_col2 = st.columns(2)
with filt_col1:
filters["start_date"] = st.date_input("Start", filters["start_date"])

with filt_col2:
filters["end_date"] = st.date_input("End", filters["end_date"])

data = fetch_data(filters)

## make the charts
charts = make_charts(data, filters)

## display
st.plotly_chart(charts["apr"], use_container_width=True)

col1, col2 = st.columns(2)
with col1:
st.plotly_chart(charts["collateral"], use_container_width=True)
st.plotly_chart(charts["hourly_pnl"], use_container_width=True)
st.plotly_chart(charts["hourly_issuance"], use_container_width=True)

with col2:
st.plotly_chart(charts["debt"], use_container_width=True)
st.plotly_chart(charts["pnl"], use_container_width=True)
st.plotly_chart(charts["issuance"], use_container_width=True)

st.markdown("## Top Delegators")
st.dataframe(
data["account_delegation"]
.sort_values("amount_delegated", ascending=False)
.head(25)
)

## export
exports = [{"title": export, "df": data[export]} for export in data.keys()]
with st.expander("Exports"):
for export in exports:
export_data(export["title"], export["df"])
147 changes: 147 additions & 0 deletions dashboard/modules/arbitrum_sepolia/spot_markets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import streamlit as st
import pandas as pd
import sqlite3
import plotly.express as px
from datetime import datetime, timedelta
from utils import get_connection
from utils import chart_bars, chart_lines, export_data

## set default filters
filters = {
"start_date": datetime.today().date() - timedelta(days=14),
"end_date": datetime.today().date() + timedelta(days=1),
}


## data
@st.cache_data(ttl=600)
def fetch_data(settings):
# get filters
start_date = filters["start_date"]
end_date = filters["end_date"]

# initialize connection
db = get_connection()

# get account data
df_wrapper = pd.read_sql_query(
f"""
SELECT
ts,
block_number,
tx_hash,
synth_market_id,
amount_wrapped
FROM arbitrum_sepolia.fct_spot_wrapper
WHERE ts >= '{start_date}' and ts <= '{end_date}'
""",
db,
)

df_atomics = pd.read_sql_query(
f"""
SELECT
ts,
block_number,
tx_hash,
synth_market_id,
amount,
price
FROM arbitrum_sepolia.fct_spot_atomics
WHERE ts >= '{start_date}' and ts <= '{end_date}'
""",
db,
)

df_synth_supply = pd.read_sql_query(
f"""
SELECT
ts,
synth_market_id,
supply
FROM arbitrum_sepolia.fct_synth_supply
WHERE ts >= '{start_date}' and ts <= '{end_date}'
""",
db,
)

db.close()

return {
"synth_supply": df_synth_supply,
"wrapper": df_wrapper,
"atomics": df_atomics,
}


def make_charts(data):
return {
"supply": chart_lines(
data["synth_supply"],
"ts",
["supply"],
"Synth Supply",
"synth_market_id",
),
}


def main():
## title
st.markdown(
"""
## V3 Spot Market
"""
)

## inputs
with st.expander("Filters") as expander:
# date filter
filt_col1, filt_col2 = st.columns(2)
with filt_col1:
filters["start_date"] = st.date_input("Start", filters["start_date"])

with filt_col2:
filters["end_date"] = st.date_input("End", filters["end_date"])

## fetch the data
data = fetch_data(filters)

## make the charts
charts = make_charts(data)

## display

st.plotly_chart(charts["supply"], use_container_width=True)

# Wrapper table
st.markdown(
"""
### Wrapper
"""
)

st.dataframe(
data["wrapper"].sort_values("ts", ascending=False),
use_container_width=True,
hide_index=True,
)

# Atomics table
st.markdown(
"""
### Atomic Transactions
"""
)

st.dataframe(
data["atomics"].sort_values("ts", ascending=False),
use_container_width=True,
hide_index=True,
)

## export
exports = [{"title": export, "df": data[export]} for export in data.keys()]
with st.expander("Exports"):
for export in exports:
export_data(export["title"], export["df"])
20 changes: 20 additions & 0 deletions dashboard/pages/Arbitrum_Sepolia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import streamlit as st
from modules.arbitrum_sepolia import (
core_stats,
spot_markets,
)

st.set_page_config(page_title="Arbitrum Sepolia", layout="wide")


pages = {
"Core Stats": core_stats.main,
"Spot Markets": spot_markets.main,
}
state_page = None
state_page = st.sidebar.radio(
":large_blue_circle: :test_tube: Arbitrum Sepolia",
tuple(pages.keys()),
index=tuple(pages.keys()).index(state_page) if state_page else 0,
)
pages[state_page]()