Skip to content

Commit

Permalink
Merge pull request #433 from CarmineOptions/feat/update-update-data-m…
Browse files Browse the repository at this point in the history
…ethod

add ZkLendDataInitializer
  • Loading branch information
djeck1432 authored Feb 6, 2025
2 parents f80cb7c + 37a5b03 commit 8c31c18
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/sdk_app_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v4
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
poetry run pytest --junitxml=results.xml
- name: Upload Test Results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: test-results
path: ./apps/sdk/results.xml
4 changes: 2 additions & 2 deletions .github/workflows/wep_app_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v4
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
run: poetry run pytest --junitxml=results.xml

- name: Upload Test Results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: test-results
path: ./apps/web_app/results.xml
40 changes: 20 additions & 20 deletions apps/dashboard_app/charts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class Dashboard:
]

def __init__(
self,
state: State,
general_stats: dict,
supply_stats: dict,
collateral_stats: dict,
debt_stats: dict,
utilization_stats: dict,
self,
state: State | None = None,
general_stats: dict | None = None,
supply_stats: dict | None = None,
collateral_stats: dict | None = None,
debt_stats: dict | None = None,
utilization_stats: dict | None = None,
):
"""
Initialize the dashboard.
Expand Down Expand Up @@ -196,16 +196,16 @@ def load_loans_with_low_health_factor_chart(self):
st.dataframe(
loans_data[
(
loans_data[CommonValues.health_factor.value] > 0
loans_data[CommonValues.health_factor.value] > 0
) # TODO: debug the negative HFs
& loans_data[CommonValues.debt_usd.value].between(
debt_usd_lower_bound, debt_usd_upper_bound
)
]
]
.sort_values(CommonValues.health_factor.value)
.iloc[:20],
use_container_width=True,
)
)

def load_top_loans_chart(self):
"""
Expand All @@ -229,31 +229,31 @@ def load_top_loans_chart(self):
st.dataframe(
loans_data[
(
loans_data[CommonValues.health_factor.value] > 1
loans_data[CommonValues.health_factor.value] > 1
) # TODO: debug the negative HFs
& (
loans_data[CommonValues.standardized_health_factor.value]
!= float("inf")
loans_data[CommonValues.standardized_health_factor.value]
!= float("inf")
)
]
]
.sort_values(CommonValues.collateral_usd.value, ascending=False)
.iloc[:20],
use_container_width=True,
)
)
with col2:
st.subheader("Sorted by debt")
st.dataframe(
loans_data[
(loans_data[CommonValues.health_factor.value] > 1)
& (
loans_data[CommonValues.standardized_health_factor.value]
!= float("inf")
loans_data[CommonValues.standardized_health_factor.value]
!= float("inf")
) # TODO: debug the negative HFs
]
]
.sort_values(CommonValues.debt_usd.value, ascending=False)
.iloc[:20],
use_container_width=True,
)
)

def load_detail_loan_chart(self):
"""
Expand Down Expand Up @@ -387,7 +387,7 @@ def load_comparison_lending_protocols_chart(self):

# TODO: add last update functionality

def _plot_chart(self, token: str, stats_type: str) -> plotly.express.Data:
def _plot_chart(self, token: str, stats_type: str) -> plotly.express.data:
"""
Returns a ploted figure.
:return plotly.express.Data: Figure.
Expand Down
25 changes: 16 additions & 9 deletions apps/dashboard_app/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@

from charts.main import Dashboard
from helpers.load_data import DashboardDataHandler
from streamlit_autorefresh import st_autorefresh
from data_handler.celery_app.celery_conf import CRONTAB_TIME

ONE_MINUTE_IN_MILISECONDS = 60000
REFRESH_TIME = ONE_MINUTE_IN_MILISECONDS * int(CRONTAB_TIME)

if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

dashboard = Dashboard() # (`st.set_page_config` in `Dashboard` must be called once)
# Set up autorefresh data config
st_autorefresh(interval=REFRESH_TIME, key="datarefresh")

dashboard_data_handler = DashboardDataHandler()
(
zklend_state,
general_stats,
supply_stats,
collateral_stats,
debt_stats,
utilization_stats,
) = dashboard_data_handler.load_data()
(dashboard.state,
dashboard.general_stats,
dashboard.supply_stats,
dashboard.collateral_stats,
dashboard.debt_stats,
dashboard.utilization_stats) = dashboard_data_handler.load_data()

dashboard = Dashboard(zklend_state, general_stats, supply_stats, collateral_stats, debt_stats, utilization_stats)
dashboard.run()
5 changes: 4 additions & 1 deletion apps/dashboard_app/helpers/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from starknet_py.cairo.felt import decode_shortstring

AMMS = ["10kSwap", "MySwap", "SithSwap", "JediSwap"]
kSTRK = "0x045cd05ee2caaac3459b87e5e2480099d201be2f62243f839f00e10dde7f500c"


def float_range(start: float, stop: float, step: float) -> Iterator[float]:
Expand Down Expand Up @@ -96,8 +97,10 @@ def get_prices(token_decimals: dict[str, int]) -> dict[str, float]:
tokens_info = response.json()

# Create a map of token addresses to token information, applying add_leading_zeros conditionally
# TODO: Add kSTRK token later
# FIXME: Remove `if` condition once kSTRK token will be added
token_info_map = {
add_leading_zeros(token["address"]): token for token in tokens_info
add_leading_zeros(token["address"]): token for token in tokens_info if add_leading_zeros(token["address"]) != kSTRK
}

prices = {}
Expand Down
Loading

0 comments on commit 8c31c18

Please sign in to comment.