ππΌ Agent Aleph is Urani's in-house arbitrage agent written in Python. Although the private version of Aleph is private for the Urani Protocol, this template brings its basic proprieties to the public.
1οΈβ£ Listen for incoming batches: Aleph fetches the orders from the Urani's orderbook;
2οΈβ£ Parse these batches to extract the order intents;
3οΈβ£ Check for peer-to-peer matches among the intents: naive 1-hop search, partial fills are not supported at this time;
4οΈβ£ Spin a new thread for each intent with no P2P match to calculate solutions for best quotes through arbitrage in different AMMs;
5οΈβ£ Pack the solutions and send them to the protocol.
For this particular release, we bring an example of Aleph sending quote requests to Jupiter to obtain the optimal route for each intent. Future versions will expand routing algorithms and fetch AMMs from different venues.
Aleph's source code is structured as the following:
main.py
: The entry point when running the command line.agents/
: Contains the main classes for the "bots". Also, the entry point for running the agent.solana/
: Contains an extensive wrapper for operations on the Solana blockchain.orders/
: Contains the classes to process intents and batches.liquidity/
: Contains wrapper classes for liquidity venues on the Solana blockchain.p2p/
: Contains algorithms and optimizations for off-chain peer-to-peer matches.protocol_server/
: Contains the API for the local server that mimick the Urani protocol.oracles/
: Contain wrapper for price discovery.utils/
: Contains several helper classes and methods for network operations, mathematics, system procedures, oracles, etc.
src
βββ main.py
βββ agents
β βββ aleph.py
β βββ base.py
β βββ main.py
βββ liquidity
β βββ base.py
β βββ cexes
β βββ jupiter.py
βββ oracles
β βββ dexscreener.py
β βββ helius.py
β βββ pyth.py
βββ orders
β βββ batch.py
β βββ intent.py
β βββ quote.py
β βββ solution.py
βββ p2p
β βββ level_one.py
βββ protocol_server
β βββ _server.py
β βββ orderbook
β βββ server.log
β βββ server_utils.py
β βββ static
β βββ templates
βββ sol
β βββ accounts.py
β βββ base.py
β βββ blocks.py
β βββ transactions.py
βββ utils
βββ config.py
βββ logging.py
βββ maths.py
βββ network.py
βββ system.py
Create a .env
file :
cp .env.example .env
vim .env
Fill in the following information:
Parameter | Description | Default |
---|---|---|
WALLET_PRIVATE_KEY |
Your private key for signing. | - |
HELIUS_API_KEY |
Your helius api key | - |
LOG_LEVEL |
The level of logging you desire. | info |
RPC_HTTPS |
The RPC HTTP URL to connect. | https://api.mainnet-beta.solana.com/ |
Install the program cli:
make install
You can test the installation with:
poetry run pytest
====================================================================== test session starts =======================================================================
platform darwin -- Python 3.12.4, pytest-8.3.2, pluggy-1.5.0
rootdir: XXX
configfile: pyproject.toml
plugins: order-1.2.1, anyio-4.4.0, ordering-0.6
collected 7 items
tests/test_cli.py .... [ 57%]
tests/test_server.py .. [ 85%]
tests/test_aleph.py . [100%]
======================================================================= 7 passed in 16.25s =======================================================================
You can get information on the CLI commands by running:
poetry run mcli -h
88 88 8b,dPPYba, ,adPPYYba, 8b,dPPYba, 88
88 88 88P' "Y8 "" `Y8 88P' `"8a 88
88 88 88 ,adPPPPP88 88 88 88
"8a, ,a88 88 88, ,88 88 88 88
`"YbbdP'Y8 88 `"8bbdP"Y8 88 88 88
Aleph CLI: Urani MEV Agent.
options:
-h, --help show this help message and exit
-s Print info on the Solana blockchain.
-a [AGENT], --agents [AGENT]
Print info on the available agents or on specific [AGENT]
-d [AGENT], --deploy [AGENT]
Deploy a specific [AGENT].
-l Print info on liquidity sources.
-o Print info on the Oracles.
This first version of Aleph interacts with a local-server initialized by the user that mimics the Urani Protocol.
Start a local server:
poetry run start_server
This server can be visited at:
http://127.0.0.1:8000/
Once the server is running, you can deploy Aleph by running the CLI, adding the flag --deploy
or -d
and the string aleph
:
poetry run mcli -d aleph
# OR
poetry run python ./src/main.py -d aleph
This will output:
88 88 8b,dPPYba, ,adPPYYba, 8b,dPPYba, 88
88 88 88P' "Y8 "" `Y8 88P' `"8a 88
88 88 88 ,adPPPPP88 88 88 88
"8a, ,a88 88 88, ,88 88 88 88
`"YbbdP'Y8 88 `"8bbdP"Y8 88 88 88
Loading environment variables...
πΉ Deploying Agent Aleph ...
Aleph is the first Urani MEV in-house agent.
.Version: v0.1
.Language: Python
.Routing algorithm: Jupiter
.P2P matches: Naive 1-hop
.Partial fill: No
.Ring trades: No
--> Check the README to learn more about Aleph <--
πΉ Starting Agent Aleph...
πΉ Aleph is running...
πΉ Fetching current batch from http://127.0.0.1:8000/batches
β³ Aleph is waiting for a valid batch ...
This means Aleph is waiting for a batch to be posted in the orderbook.
To post a valid batch in the orderbook, open a new terminal window and go into the folder orders_templates
.
Post post the order_example.json
via:
curl -X POST "http://127.0.0.1:8000/batches" -H "Content-Type: application/json" -d @example_batch.json
Now look what Aleph does:
88 88 8b,dPPYba, ,adPPYYba, 8b,dPPYba, 88
88 88 88P' "Y8 "" `Y8 88P' `"8a 88
88 88 88 ,adPPPPP88 88 88 88
"8a, ,a88 88 88, ,88 88 88 88
`"YbbdP'Y8 88 `"8bbdP"Y8 88 88 88
Loading environment variables...
πΉ Deploying Agent Aleph ...
Aleph is the first Urani MEV in-house agent.
.Version: v0.1
.Language: Python
.Routing algorithm: Jupiter
.P2P matches: Naive 1-hop
.Partial fill: No
.Ring trades: No
--> Check the README to learn more about Aleph <--
πΉ Starting Agent Aleph...
πΉ Aleph is running...
πΉ Fetching current batch from http://127.0.0.1:8000/batches
β³ Aleph is waiting for a valid batch ...
πΉ Aleph found a valid batch ...
π€ Aleph is solving the order...
βοΈ Searching for p2p matches ...
π€ Found p2p matches.
βοΈ Searching optimal execution path for 2 intents ...
π€ Sending solutions to http://127.0.0.1:8000/solutions
πΉ Agent Aleph has finished
You can check the solutions by visiting: http://127.0.0.1:8000/solutions
.
If you want to try with another batch, modify the template orders_templates/order_example.json
as you wish and post it to the orderbook.
This will override the last batch.
Then run again Aleph.
When you are finished, stop the server with:
poetry run stop_server
This project is distributed under the Apache 2.0 license.
You are welcome to contribute. See the guidelines here.