A script that fetches financial metrics from the Aave using The Graph API and generates insights through an AI assistant
Project Title:Aave Protocol Data Fetcher and Insight Generator
Introduction
This project is a Node.js application designed to fetch financial metrics from the Aave protocol using The Graph's API and generate insightful analyses through an AI assistant. By leveraging GraphQL queries and AI-driven insights, the application provides a streamlined way to access, process, and interpret complex financial data from one of the leading decentralized finance (DeFi) platforms.
Project Objectives
- Data Retrieval: Seamlessly extract key financial metrics from the Aave protocol.
- Data Processing: Format and prepare the fetched data for analysis.
- Insight Generation: Utilize an AI assistant to analyze the data and provide actionable insights.
- Automation:Create an end-to-end solution that minimizes manual intervention.
Key Features
1. GraphQL Data Fetching:
- Targeted Metrics: The application retrieves the following financial metrics:
- Daily Flashloan Volume (USD): `dailyFlashloanUSD`
- Daily Deposit Volume (USD): `dailyDepositUSD`
- Daily Borrow Volume (USD): `dailyBorrowUSD`
- Daily Liquidation Volume (USD): `dailyLiquidateUSD`
- Daily Protocol Side Revenue (USD): `dailyProtocolSideRevenueUSD`
- Daily Total Revenue (USD): `dailyTotalRevenueUSD`
- API Endpoint: Utilizes The Graph's API endpoint for the Aave V2 protocol on Ethereum:
```
https://api.thegraph.com/subgraphs/name/messari/aave-v2-ethereum
```
2. Data Processing and Formatting:
- Readable Output:Converts raw data into a human-readable string format.
- Structured Presentation: Organizes data points for each metric to facilitate easy analysis.
3. AI-Powered Insights:
- AI Assistant Integration: Sends the formatted data to an AI assistant API endpoint:
```
https://llama.us.gaianet.network/v1/chat/completions
```
- Custom Prompts: Crafts a prompt that includes the data and requests insights.
- Insight Generation: Receives and displays analytical insights from the AI assistant.
4. Error Handling and Logging:
- Robust Error Management: Catches and logs errors during data fetching and insight generation.
- User Feedback: Provides console outputs to inform the user of the application's status.
Technologies Used
- Node.js: JavaScript runtime for building the application.
- Axios: Promise-based HTTP client for making API requests.
- GraphQL: Query language for fetching data from APIs.
- JavaScript (ES6+): Programming language used for scripting.
---
Project Structure
- `fetchAaveData()` Function:
- Purpose: Fetches financial metrics from the Aave protocol.
- Process:
- Constructs a GraphQL query with the required metrics.
- Sends a POST request to The Graph's API endpoint.
- Extracts and returns the financial metrics from the response.
- `fetchLlamaInsights(data)` Function:
- Purpose: Sends the fetched data to an AI assistant to obtain insights.
- Process:
- Formats the data into a readable string.
- Crafts a prompt incorporating the data.
- Sends a POST request to the AI assistant's API endpoint.
- Retrieves and returns the assistant's insights.
- `runApp()` Function:
- Purpose: Orchestrates the data fetching and insight generation processes.
- Process:
- Calls `fetchAaveData()` to retrieve data.
- Passes the data to `fetchLlamaInsights()` to get insights.
- Outputs the insights to the console.
Potential Use Cases
- DeFi Analysts:
- Gain a deeper understanding of Aave's financial performance.
- Monitor key metrics for research and reporting.
- Investors and Traders:
- Identify trends in lending and borrowing activities.
- Make informed investment decisions based on protocol revenues and user activity.
- Developers and Data Scientists:
- Use the script as a foundation for building more complex analytics tools.
- Integrate additional data sources or machine learning models.
-Educators and Students:
- Learn about interacting with blockchain data using GraphQL and The Graph.
- Explore the application of AI in analyzing financial data.
Technical Considerations
- API Rate Limits:
- Be mindful of any rate limits imposed by The Graph's API and the AI assistant's API.
- Error Handling:
- The script includes basic error handling but can be enhanced to cover more edge cases.
- Data Accuracy:
- Ensure that the data returned from the APIs is accurate and up-to-date.
- Security:
- Avoid hardcoding any sensitive information like API keys.
- Use environment variables or secure credential management practices.
Conclusion
This project offers a powerful yet accessible way to interact with the Aave protocol's financial data. By automating the data retrieval process and leveraging AI for analysis, users can focus on interpreting insights rather than managing data pipelines. Whether you're involved in the DeFi space professionally or out of personal interest, this tool can enhance your understanding of protocol dynamics and support data-driven decision-making.
By the end of the hackathon, I transformed an initial concept into a functional application that bridges DeFi data retrieval with AI-driven insights. The project successfully fetches financial metrics from the Aave protocol and provides automated analysis, making complex data accessible to users. This experience allowed me to enhance my skills in API integration, data processing, and AI interaction within a short period.The progress achieved lays a solid foundation for future improvements, such as incorporating data visualization, expanding to other protocols or developing a friendly interface