This repository implements the business logic for an AI-powered agent that interacts with a Bonding Curve Contract to manage token purchases. The system uses an AI agent to validate user prompts and make decisions on token swaps, based on user interaction and the contract's state.
Integration with Bonding Curve Contract:
- Connects to the Bonding Curve contract.
Prompt Message Validation:
- Ensures message integrity by hashing the user's message and comparing it with the pre-hashed message from the transaction.
ETH-Based Chat Sessions:
- Creates a unique chat session for each Ethereum address.
- Users must convince the AI agent to approve token purchases based on their ETH balance in the contract.
AI-Driven Swap Decisions:
- Sends the user's last message to a language model (LLM) for evaluation.
- Receives the LLM's decision (approve or reject) through function calls.
Transaction Processing:
- If approved by the LLM, the system executes the transaction and sends the result to the frontend.
Chat History Management: - All chat sessions are stored in a Redis database for tracking and future references.
-
Contract Integration: Connects with the Bonding Curve smart contract to validate ETH balances and process transactions.
-
Message Hashing: Ensures message authenticity using cryptographic hashing.
-
AI Decision Making:
-
Submits user messages to an LLM.
-
Processes and interprets LLM's responses to determine the course of action.
-
-
Transaction Execution: Automates token swaps upon approval and communicates the outcome to the frontend.
-
Redis Chat History: Stores every user's chat session for a seamless and persistent experience.
-
Rust 1.8.0
-
Redis database
-
Environment configuration files (.env)
-
Clone the repository:
git clone https://github.com/northern05/ai-agent.git cd ai-agent
-
Configure your environment:
- Add necessary credentials and configurations in the
.envs/.dev
file.
- Add necessary credentials and configurations in the
-
Initialization:
-
The system connects to the Bonding Curve contract upon startup.
-
A Redis database is initialized to store chat histories.
-
-
User Interaction:
-
Users initiate a chat session by sending a message.
-
The system hashes the message and validates it against the pre-hashed message from the contract.
-
-
AI Validation:
-
The user’s message is sent to the LLM for evaluation.
-
The AI agent decides whether to approve or reject the token purchase based on the user’s message and ETH balance.
-
-
Transaction Execution:
-
If the LLM approves, the system executes the token swap transaction and sends the details to the frontend.
-
If rejected, the user is informed with the AI’s reasoning.
-
-
Data Storage:
- All chat histories are saved in the Redis database for reference.
-
identifyPool
Description: Fetch address of a given pool address from a Raydium URL or an exact pool address or token address to identify if this pair pool exists on Raydium.
Properties (params used):
pool_or_token_address
Description: Fetch token address or pool address or pool address from Raydium url.
-
retrieveCurrentPortfolio
Description: Retrieve information about the current agent's portfolio, including the tokens it holds.
-
retrieveBuyExplanation
Description: Retrieve explanation why you bought specific meme token.
Properties:
-
pool_address
Description: Retrieve the pool address of token pair, but first call retrieveCurrentPortfolio to identify the pool address by name.
-
-
retrievePnlInformation
Description: Retrieve profit and loss (PnL) statistics based on the user's requested action.
Properties:
-
action
Description: Specify the action to retrieve statistics related to profit and loss (PnL) or agent performance.
Enum:
total_pnl
- information about total pay and losses
total_profit_shared
- information about total shared profit between users
maximum_pnl
- information about the most profitable trade
minimum_pnl
- information about the most losses trade
average_pnl
- information about the average PNL of agent trading
count_of_trades
- information about how many trades agent has closed
-
Shilling is not allowed, but this function call is used to identify the pool by filtering the prompt to fix a bug that causes duplication of logic and incorrect data fetching.
-
identifyPool
Description: Fetch address of a given pool address from a Raydium URL or an exact pool address or token address to identify if this pair pool exists on Raydium.
Properties (params used):
pool_or_token_address
Description: Fetch token address or pool address or pool address from Raydium url.
-
analyzeCallIdentifyPool
Description: Analyze user message if there address of token to call identifyPool function.
Properties:
-
is_function_call
Description: Boolean value to check if user message contains address or pool address or link.
-
user_message
Description: User message to analyze.
-
-
approveShilling
Description: Approve buying meme token from Raydium explanation.
Properties:
-
explanation
Description: Explanation for why you decide to buy token meme that user provided from Raydium.
-
poolAddress
Description: Extract the poolAddress of pair provided in analytic data (which you previously called in the function fetch_pool_data from your message history)
-
-
rejectShilling
Description: Reject buying meme token from Raydium and provide explanation.
Properties:
-
explanation
Description: Explanation for why you decide to buy token meme that user provided from Raydium.
-
poolAddress
Description: Extract the poolAddress of pair provided in analytic data (which you previously called in the function fetch_pool_data from your message history)
-
-
fetch_pool_data
Description: Fetch analytics data for a given token address.
Properties:
-
token_address
Description: The address of the pool to fetch data for.
-
-
generatePostInTwitter
Description: Generate text and post in twitter account.
Properties:
-
data
Description: Data provided to generate post in twitter account.
-
-
Blockchain Integration: Interacts with Ethereum smart contracts.
-
Redis: Stores chat histories for efficient retrieval and persistence.
-
LLM (Language Model): Processes user messages and makes decisions.
-
Rust: Core programming language.
-
Fork the repository.
-
Create a new branch:
git checkout -b feature-name
-
Commit your changes:
git commit -m 'Add some feature'
-
Push to the branch:
git push origin feature-name
-
Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or issues, please contact the repository owner via the TG: @yezhovanton