On chain ETH trading strategy agent deployed on starknet mainnet | Built using Giza SDK
The agent is designed to facilitate trading on the ETH/USDC pool using an AI-driven strategy. The goal is to optimize trades based on market conditions, leveraging machine learning models for prediction and decision-making.
- Giza CLI & SDK : For model training, ONNX conversion, cairo transpilation and deployment.
- Starknet Mainnet : Blockchain platform for deploying and executing contracts.
- PyTorch : Framework for building deep learning models.
- Python Libraries : Poetry for Python dependencies,Pandas, numpy, yFinance for historical data, scikit-learn for ML tooling.
- Model Enhancement : Model training with more historical price data to improve prediction accuracy.
- User Interface : Development of a user-friendly dashboard for monitoring and controlling agent and integrated wallets for trading.
- Dex Integrations and custom trading stragegies : Expanding support to other decentralised exchanges and feature for building custom on-chain trading strategies and deploy them from UI with single click.
Welcome to this step-by-step tutorial for on-chain price prediction strategy to assist in trading on the ETH/USDC pool. In this guide, we will walk through the entire process required to setup, deploy, and run a AI trading agent using the Giza stack. By the end of this tutorial, you will have a functional system capable of executing trades on-chain based on ML model predictions.
- Python 3.11 or later must be installed on your machine.
- Install
giza-sdk
to use Giza CLI and Giza agents:
pip install giza-sdk
Additional libraries:
pip install -U torch pandas
Create Giza Account
If you don't have one, create a Giza account here.
Environment Variables
Create a .env file in the project directory and populate it with the following variables: env
PRIVATE_KEY=
PUBLIC_KEY=
DRY_RUN=true # Set as true when testing Giza models locally
STARKNET_RPC_URL=https://free-rpc.nethermind.io/mainnet-juno
In this project, we are using a simple multi-layer perceptron to predict the next day's prices. After training the model, we need to compile it into the ONNX format, which will be used in the next step to transpile it into Cairo.
Training the Model :
The model will download the ETH/USDC prices, preprocess the data, train a simple neural network with Torch, and save the model in ONNX format.
Script: model_training.py.
Login to Giza CLI
giza users login
Create Giza Workspace
If you don't have a workspace, create one with:
giza workspaces create
Create Giza Model
giza models create --name price-pred-with-zkml --description "Price prediction with ZKML"
Note the model-id.
Transpile Model to Cairo
giza transpile --model-id <YOUR-MODEL-ID> --framework CAIRO <PATH-TO-YOUR-ONNX-MODEL> --output-path <YOUR-OUTPUT-PATH>
Deploy Endpoint
giza endpoints deploy --model-id <YOUR-MODEL-ID> --version-id <YOUR-VERSION-ID>
Next, we want to create a Giza Agent that executes the verifiable inference and interacts with the blockchain.
Create Agent
giza agents create --model-id <YOUR-MODEL-ID> --version-id <YOUR-VERSION-ID> --name <AGENT-NAME> --description <AGENT-DESCRIPTION>
Alternatively, if you have the endpoint-id:
giza agents create --endpoint-id <ENDPOINT-ID> --name <AGENT-NAME> --description <AGENT-DESCRIPTION>
- Fetch Price Data : Retrieve current price data for ETH from yFinance for past 60 days.
- Predict Prices : Use the deployed model to predict future prices based on above data.
Now we will use the giza-actions sdk to develop our AI Agent and execute trades on Starknet Mainnet. We need to implement the following steps:
- Load environment variables
- Create the AI Agent instance
- Run verifiable inference
- Get ETH prediction value.
- Buy/Sell ETH according to the predicted value.
Finally, we can execute our script with the desired parameters:
python action_agent.py --model-id <YOUR-MODEL-ID> --version-id <YOUR-VERSION-ID>
Deployed Giza Model (model-id : 784, version-id:1)
AI_Agent_Execution : USDC_InsufficientBalance
AI_Agent_Execution : BUY_ETH_WITH_USDC
Team AlphaDevs π
Harsh Tyagi Yashasvi Chaudhary
Harsh Tyagi Yashasvi Chaudhary
-
Feel free to reach out to the AlphaDevs team with any questions or issues.
-
We appreciate your interest in our project and welcome contributions and feature suggestions.