Open-Sourcing Aleph v0.1
Today, we open-source our first in-house MEV Agent, Aleph (v0.1).
This post briefly explains how Aleph works within the Urani Protocol.
Introduction to MEV Agents
At Urani, MEV Agents are good arbitrage bots intended to fetch batches of user intents from Urani's Protocol orderbook.
Once an agent has ingested the user's intents, it leverages its private strategy to maximize the orders' surplus.
The Urani Protocol then ranks the solutions provided by the different agents, submits the optimal solution to the chain, and rewards the top-performing agent.
If you want to know more about the Urani Protocol and how Agents compete, take a look at our documentation.
Aleph's Workflow and Strategy
In this first version (v0.1), Aleph runs the following algorithm:
2️⃣ Parse these batches to extract the order intents.
3️⃣ Check for peer-to-peer matches among the intents.
4️⃣ Spin a new thread for each intent to calculate solutions for best quotes through arbitrage in different liquidity sources.
5️⃣ Pack the solutions and send them to the protocol.
Steps 1️⃣,2️⃣, and 5️⃣ are performed in the AgentBase
class, i.e., are shared among all agents:
Whereas steps 3️⃣, and 4️⃣ are performed differently for each agent:
Note: Each agent is a NameofAgent
derived class of AgentBase
. This would help each user just to pull in their preferred strategies.
Details
Let's get a more detailed look at how these steps are performed.
1️⃣ Listen and fetch incoming batches
2️⃣ Extract the order intents
3️⃣ Check for peer-to-peer matches among the intents
Aleph leverages a 1-hop search for P2P matches and then selects the optimal set of coinciding intents based on the overall generated surplus:
The 1-hop search is performed in the LevelOne
class. The standard Urani class for 1-hop P2P matches:
Where we check that the intents fully match:
4️⃣ Spin a new thread for each intent to calculate solutions for best quotes through arbitrage in different liquidity sources
Intents that are not P2P-matched pass through Aleph's routing strategy:
As a first example of arbitrage, Aleph sends parallel requests to Jupiter for quotes.
These quotes help determine routes in Automated Market Makers (AMMs) to achieve the desired token amount:
5️⃣ Pack the solutions and send them to the protocol
How to use Aleph
Below are general guidelines for the process. Feel free to check Aleph's README.md file for more details.
Setting Aleph up
- Create and configure
.env
file:
- Install the CLI with:
- Test the installation with:
- Get CLI Commands Informations through:
Usage
Aleph interacts with a local server that mimics Urani's protocol orderbook. Here's how to get started:
-
Start the Local Server
Initialize the local server with:
Access the server at http://127.0.0.1:8000
:
- Deploy Aleph
Run Aleph using the CLI with the --deploy
or -d
flag:
You’ll see output indicating that Aleph is running and waiting for a valid batch to be posted on the orderbook:
Aleph is waiting because no batches have yet been posted in the Urani orderbook at http://127.0.0.1:8000/batches
:
-
Post a Batch
Open a new terminal window, navigate to the
orders_templates
folder, and post a batch with:
You can inspect your batch reloading http://127.0.0.1:8000/batches
:
Batches look like:
- Solve the Order
As soon as the batch is posted, Aleph starts processing the batch, searches for P2P matches, and finds an optimal execution path for the intents:
The solution is sent to http://127.0.0.1:8000/solutions
:
Solutions have this format:
-
Stop the server
When you’re done, stop the server with:
Thank you for reading, anon
You’re now ready to start working with Aleph v0.1.
Aleph is a work in progress for us at Team Agents, and we invite you to help by contributing to the source code.