CarmineOptions / derisk-research

MIT License
5 stars 17 forks source link

Add informative warning message when the selected lending protocol doesn't use the selected token #190

Open lukaspetrasek opened 1 day ago

lukaspetrasek commented 1 day ago

Steps:

0) Read our Contributor Guidelines and README. 1) Check out the current implementation of our streamlit dashboard, specifically the part that displays the main chart titled "Liquidable debt and the corresponding supply ...": https://github.com/CarmineOptions/derisk-research/blob/master/app.py#L319. The dashboard can be found here. 2) On the very top, users specify lending protocols and collateral and debt tokens. However, if the selected lending protocol doesn't accept the selected collateral token as collateral, or doesn't lend out the selected debt token, the dashboard crashes on a "KeyError" error. Run the dashboard locally and try it yourself. image 3) Handle such cases by showing an informative warning, e.g. "No liquidable debt for the collateral token and the debt token exists on the lending protocol.", and display the chart with data for the remaining protocols.

ShantelPeters commented 1 day ago

Hi

ooochoche commented 1 day ago

@lukaspetrasek, can I work on this? I have read through the guidelines and the README and also gone through the current implementation. I know exactly what needs to be done.

onlydustapp[bot] commented 1 day ago

Hi @ooochoche! Maintainers during the ODHack # 8.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

ooochoche commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

@lukaspetrasek

How I plan on tackling this issue

Can I work on this? I have read through the guidelines and the README and also gone through the current implementation. I know exactly what needs to be done.

Dprof-in-tech commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hello, i am Dprof-in-tech, an experienced Full Stack Blockchain Developer and I am excited to contribute my skills to this project in this ODHACK 8. With a strong background in Next.js, TypeScript, JavaScript, React, Node.js, Rust and Cairo, I've honed my technical skills across the blockchain development landscape.

My journey with OnlyDust began at Edition 2, and I've since made 34 contributions across 11 projects. This extensive experience on the platform has allowed me to develop a keen understanding of delivering high-quality solutions under tight deadlines. I bring a unique blend of technical prowess and user-centric design to every project, whether I'm crafting immersive 3D experiences or developing innovative smart contracts.

My track record demonstrates my ability to adapt quickly and contribute effectively to diverse challenges. I'm confident in my capacity to tackle new problems and drive innovation in the blockchain space. As we begin ODHACK 8, I'm eager to leverage my hackathon experience and technical skills to push the boundaries of what's possible in blockchain development.

Below is a link to my OnlyDust public profile. https://app.onlydust.com/u/Dprof-in-tech

How I plan on tackling this issue

Approach for Add informative warning message when the selected lending protocol doesn't use the selected token (#190):

I will read and understand the existing code: I will start by thoroughly going through the Contributor Guidelines and README to understand the project setup and best practices. Next, I will examine the current implementation of the Streamlit dashboard, specifically focusing on the code around the main chart titled "Liquidable debt and the corresponding supply" located in app.py around line 319.

I will identify how the dashboard processes user input when selecting a lending protocol, collateral tokens, and debt tokens to understand why a KeyError occurs.

I will replicate the issue locally: I will set up the project by following the instructions in the README and run the dashboard locally to reproduce the error where selecting an incompatible lending protocol and token pair causes the KeyError crash. This will help me identify the exact point of failure and the conditions that cause the error to arise.

I will implement error handling for unsupported tokens: Once I understand the failure point, I will introduce error handling in the part of the code where the dashboard checks for the existence of liquidable debt based on the selected lending protocol, collateral token, and debt token. Instead of letting the program crash with a KeyError, I will write conditional logic that checks if the selected protocol supports the given collateral or debt token.

If the tokens are not supported, I will display a user-friendly and informative warning message: "No liquidable debt for the collateral token and the debt token exists on the selected lending protocol." I will ensure the message includes the actual tokens and protocol the user selected for clarity.

I will ensure the remaining data displays properly: After showing the warning, I will update the chart to display data for the remaining valid protocols (i.e., protocols that do accept the tokens), so the user still gets useful information despite the mismatch.

I will handle this gracefully to avoid any further crashes or unhandled errors.

I will test the solution: I will thoroughly test the solution by selecting various combinations of lending protocols and tokens to ensure that the error handling works as expected.

Specifically, I will test: Supported protocol and token combinations. Unsupported protocol and token combinations to trigger the warning message. Scenarios where only the collateral or debt token is invalid. I will also ensure the chart refreshes and displays data for the remaining protocols in each case.

I will document the changes: I will update the project documentation to explain the new behavior, including the warning message and how it handles unsupported tokens. If there is a contributors' guide on error handling or messages, I will ensure my changes align with the project's standards.

I will submit the pull request and provide code coverage: I will write unit tests to cover the new error-handling logic and the warning message display, ensuring they pass and contribute to the overall code coverage. I will provide a screenshot of the updated test coverage, ensuring the coverage percentage aligns with the project's requirement (>=70%).

I will create a pull request following the project guidelines, ensuring my branch is rebased on the current master before submitting.

Estimated timeline: Start Date: Immediately upon assignment. Estimated Completion Date: 2 days from the start date (ETA: 2 days).

Jayse007 commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I would like to take this task, this task will be delivered within 4 days (26, september, 2024-30, september, 2024). My name is Shawon James. I am a programmer who specializes in Python. I have been using Python for over 7 years. I have a very strong understanding of the language, its fundamentals and some of the more complicated things. I use python to solve problems (sometimes with the use of popular algorithms), automation of tasks, web scraping, backend development, data analysis.

How I plan on tackling this issue

I would make use of the "try, except" keywords that Python provides to catch the error. The try block would be used to check for the error. The except block would be used to handle the raised error or exception which is a Key error. In the except block the message "No liquidable debt for the collateral token and the " will be returned to the user, of course the variables will be replaced with its values.

danielcdz commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hello, I'm Daniel Calderón! I'm a passionate software engineer with over 3 years of experience, actively contributing to open-source projects through OnlyDust. I’m also a community moderator at Dojo Coding, where I help new developers get started with blockchain development. Over the past few months, I've contributed to several Starknet projects, including cairo-vm-go by Nethermind. Currently, I’m a Cairo developer at ByteBuilders, working on ByteBeasts, a fully on-chain RPG game built using the Dojo Engine framework. My expertise spans full-stack development, with a focus on backend, frontend, and smart contract development in blockchain ecosystems.

I'm a returning contributor! I solved 2 issues of this project in the past, the last one couple of weeks ago, so I have good context of the code base and how to solve the issue!

How I plan on tackling this issue

To solve this I will follow your suggestions to avoid having that specific error and show a warning instead.

I can get this task done in 2 days

josephchimebuka commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hello @lukaspetrasek I am Joseph I am a frontend developer and blockchain developer and I am also an active contributor here on only dust here is my profile https://app.onlydust.com/u/josephchimebuka. This is my first time to contribute to this repo ill appreciate the opportunity to contribute

How I plan on tackling this issue

To solve this issue the steps and guidelines to follow to solve the error have already being outlined I will follow them before submitting a PR.

thesledge04 commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Approach to Fix the Issue:

  1. Understand the Current Implementation: Code Review: Start by reviewing the current implementation, especially the section in app.py that handles the selection of lending protocols, collateral tokens, and debt tokens. Specifically, check the logic where the app fetches data for these tokens and lending protocols. Error Location: The crash occurs due to a KeyError when the selected combination of collateral and debt tokens is not available in the chosen lending protocol. This means the app tries to access a key that doesn't exist in the dictionary or data structure. Code location:

    Example location: https://github.com/CarmineOptions/derisk-research/blob/master/app.py#L319

  2. Modify the Code to Catch the KeyError: Add a Try-Except Block: In the relevant section where the KeyError occurs (likely during data lookup), I would add a try-except block to catch this error gracefully and prevent the app from crashing. Example: liquidable_debt = data[lending_protocol][collateral_token][debt_token] Example Code (after): try: liquidable_debt = data[lending_protocol][collateral_token][debt_token] except KeyError: st.warning(f"No liquidable debt for the {collateral_token} collateral token and the {debt_token} debt token exists on the {lending_protocol} lending protocol.")

    Handle what to show next: e.g., showing data for the remaining protocols

  3. Display Informative Warning: When the KeyError is caught, display an informative warning message for the user, so they understand that the selected combination is invalid.

The warning will inform the user that the selected lending protocol doesn't accept the chosen collateral token or debt token. Example Warning: st.warning(f"No liquidable debt for the {collateral_token} collateral token and the {debt_token} debt token exists on the {lending_protocol} lending protocol.")

  1. Continue Displaying the Chart with Valid Data: After showing the warning, display the chart using the remaining valid data for other lending protocols.

Filter Valid Data: I would iterate over the remaining protocols and display the chart for combinations where valid data exists. This ensures the dashboard remains functional and provides the user with as much relevant information as possible. Example: valid_protocols = [protocol for protocol in data if data[protocol].get(collateral_token) and data[protocol].get(debt_token)]

for protocol in valid_protocols: st.write(f"Displaying data for {protocol}...")

Display chart code here

  1. Test the Changes Locally: Run the Dashboard Locally: After making the changes, run the dashboard locally and select various combinations of lending protocols, collateral tokens, and debt tokens. Test Invalid Combinations: Ensure the app handles invalid combinations gracefully by showing warnings without crashing. Test Valid Combinations: Ensure that for valid combinations, the dashboard works as expected, showing the correct chart.

I have experience with Python and building interactive applications using Streamlit. This allows me to modify the Streamlit dashboard efficiently, ensuring smooth error handling and user experience. Familiarity with data-driven dashboards allows me to ensure that the app can gracefully recover from missing data and continue providing valuable insights. Error Handling and Debugging:

I have experience identifying and fixing bugs like KeyError in Python applications. This skill allows me to implement robust error handling, preventing crashes, and improving application stability. User Experience Focus:

I focus on creating user-friendly applications, ensuring that error messages are informative and that the app remains functional even when part of the data is missing or invalid. My background helps me design solutions that keep users informed and the application responsive, even in the presence of incomplete data.

How I plan on tackling this issue

Step-by-Step Approach:

  1. Review the Current Code (Dashboard Implementation): Start by reviewing the code at the indicated line L319 in app.py, where the chart is generated and where the dashboard is crashing due to unsupported token combinations.

Link to the code:

GitHub app.py Line 319 Focus on the part of the code that fetches the lending protocol, collateral token, and debt token combinations.

  1. Handle the KeyError Gracefully: The dashboard crashes because a KeyError is raised when an unsupported combination is queried. Instead of allowing the KeyError to crash the app, handle it using a try-except block or a conditional check.

Check for Valid Combinations: Before attempting to plot the chart, ensure that the selected lending protocol supports the chosen collateral and debt tokens. Example: try:

Attempt to fetch data for the selected protocol and tokens

data = get_liquidable_debt_data(protocol, collateral_token, debt_token)
# If no KeyError is raised, proceed to plot the chart
plot_chart(data)

except KeyError:

Handle the case where the combination is invalid

st.warning(f"No liquidable debt for the {collateral_token} collateral token "
           f"and the {debt_token} debt token exists on the {protocol} protocol.")
  1. Check Token Support Before Chart Generation: Instead of waiting for a KeyError, preemptively check if the selected protocol supports the given tokens before generating the chart. You can do this by creating a function that checks whether the selected protocol contains the tokens in its dataset.

Example: def check_token_support(protocol, collateral_token, debt_token, data): if protocol not in data or \ collateral_token not in data[protocol]['collateral'] or \ debt_token not in data[protocol]['debt']: return False return True Apply Before Chart Creation: Use this function to check the combination before proceeding with chart creation.

if check_token_support(protocol, collateral_token, debt_token, data):

Proceed with chart generation

plot_chart(data)

else:

Display warning and skip the chart for this combination

st.warning(f"No liquidable debt for the {collateral_token} collateral token "
           f"and the {debt_token} debt token exists on the {protocol} protocol.")
  1. Handle Remaining Protocols: In case multiple protocols are selected, and some combinations are invalid, we should still generate the chart for valid combinations.

Loop Through Protocols: If a user selects multiple protocols, check each protocol individually and generate the chart only for those that support the selected tokens. Example: for protocol in selected_protocols: if check_token_support(protocol, collateral_token, debt_token, data): plot_chart_for_protocol(protocol, data) else: st.warning(f"No liquidable debt for {collateral_token} and {debt_token} on {protocol}.")

  1. Test the Dashboard Locally: Run Locally: After implementing these changes, run the Streamlit dashboard locally to test different combinations of protocols, collateral tokens, and debt tokens. Test Edge Cases: Test combinations that exist and should show valid data. Test combinations that don’t exist and ensure the warning message appears without crashing the app. Ensure the chart is generated for valid protocols even if some are skipped.
  2. Improve User Experience with Error Messaging: Clear Warning Messages: Ensure the warning message is clear and user-friendly, indicating which combination is invalid and why. UI Enhancements: You can also add color-coded messages (e.g., red or orange for warnings) to make it more noticeable for users. Example: st.warning(f"⚠️ No liquidable debt for {collateral_token} and {debt_token} on {protocol}.")
gregemax commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have a strong background in Python and experience with dashboard development using Streamlit. My expertise in error handling and user experience will allow me to effectively implement the informative warning system, ensuring the dashboard provides helpful feedback instead of crashing

How I plan on tackling this issue

I would first replicate the KeyError issue by running the dashboard locally. Then, I’d implement a check to verify if the selected lending protocol supports the chosen tokens. If not, I’d display an informative warning message and ensure the chart still loads data for other protocols. Finally, I’d test the implementation for robustness

MullerTheScientist commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a full-stack developer with experience in QA testing and languages like Python, Cairo, Solidity, React, and JavaScript.

How I plan on tackling this issue

i will Identify Protocol and Token Combinations Create a mapping of supported lending protocols and their corresponding tokens: Use a data structure (e.g., JSON, database) Update the mapping as new protocols and tokens are added, Validate Protocol-Token Combination Check if the selected protocol and token are compatible Use the mapping from Step 1 Return a boolean indicating compatibility

Kaminar-i commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

hello i am a frontend dev and blockchain developer please can i work on this issue :) and would love to be a contributor

How I plan on tackling this issue

please assign me and i'll get to work

onlydustapp[bot] commented 1 day ago

The maintainer lukaspetrasek has assigned Dprof-in-tech to this issue via OnlyDust Platform. Good luck!

lukaspetrasek commented 1 day ago

Hi everyone, assigning @Dprof-in-tech!

@Dprof-in-tech Let me know if everything is clear. If you have any questions, please ask here. What is you TG handler please? 🙏🏼

Consider joining our TG group. See also our contributor guidelines.