This documentation provides details on the various pieces of the MEV agent code.
- mev_project_interface: to know more about how the main function to process the user request given the venues and the JSON file storing such information.
- classes: to know more about the classes employed in the project and how they work, get a look at
- Read the User intent and store the information of the required transaction in the order object;
- Read the Venues and store them in a list of venue objects;
- Create a market oject representing the non-directed graph. The edges are the coins present in the liquidity pools, whereas the edges are the venues. Edges store information about the venue and the liquidity of each token. Moreover, we endow each edge with a price function. Before using such a price function, however, we will need to assess the direction of the exchange of coins in the pool;
- Create a MEV agent agent object. This object then reads the
orderintent and themarketgraph; - From the
orderintent and themarketgraph,agentdetermines the connected token pairs that allow performing the user requested trade; - The agent creates the directed multi-graph connecting the requested sell token
Ato the requested buy tokenB. This is stored inagent.strategy; - The agent now creates a set of paths, each of which is a list of the edges (i.e. the venues) that need to be visited along a simple path connecting
AwithB. The price function of the edge now can be determined since the direction of token swap is known; - Having the list of simple paths to walk, the agent runs
optimize_strategy(). This procedure creates a vectorxof dimensionNwhich is the number of simple paths connectingAtoB. Defines the surplus function and the constraint functions. The surplus function is built in such a way thatagentpropagates the i-thxcomponent through the i-th path and obtaines the i-th component of the boughtbvector. The surplus is then obtained with the standard formulaΓ(x) = sum(b(x)) - sum(x)/π. The surplus is optimized thanks to scipy.minimize. - The optimal
xmaximizing the surplus under the constrained defined by theorderis then used to updatevenueinformation and to compute the coin conservation error.