Open-Sourcing Aleph v0.1

Cover Image for Open-Sourcing Aleph v0.1
by Team Agents
by Team Agents

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:


1️⃣ Listen and fetch for incoming batches.
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

  1. Create and configure .env file:

  1. Install the CLI with:
root@localhost:~$ make install

  1. Test the installation with:
root@localhost:~$ poetry run pytest

  1. Get CLI Commands Informations through:
root@localhost:~$ poetry run mcli -h


Usage


Aleph interacts with a local server that mimics Urani's protocol orderbook. Here's how to get started:

  1. Start the Local Server

    Initialize the local server with:

root@localhost:~$ poetry run start_server

Access the server at http://127.0.0.1:8000:


  1. Deploy Aleph

Run Aleph using the CLI with the --deploy or -d flag:

root@localhost:~$ poetry run mcli -d aleph

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:


  1. Post a Batch

    Open a new terminal window, navigate to the orders_templates folder, and post a batch with:

root@localhost:~$ curl -X POST "http://127.0.0.1:8000/batches" -H "Content-Type: application/json" -d @example_batch.json

You can inspect your batch reloading http://127.0.0.1:8000/batches:

Batches look like:


  1. 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:


  1. Stop the server

    When you’re done, stop the server with:

root@localhost:~$ poetry run stop_server



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.