\noindent Agorata is an implementation of the idealized economic agent, or, specifically, an aggregator of smart contracts. It combines one or more contracts proposed by the members of the network in a deal which can be evaluated as profitable for Agorata with low risks. Using this approach, Agorata can provide infrastructure for loans, flashloans, bets, derivatives, bridging between chains, and many more financial instruments.
\indent There is a variety of standard financial organizations that provide their capital for some simple purely financial deals: banks, brokers, gambling institutions, betting institutions and many more. Most of them have their own DeFi counterparts, as well as some services that are only possible on the blockchain --- for example, flashloans.
All of these organizations can be generalized to an economic agent that has a utility function and who takes the deal if and only if it is the most beneficial in terms of this function. These particular implementations, however, only consider a very limited subset of deals. Also, all of them work only with purely financial deals which include not more than 3 parties\footnote{An example of such a deal with three parties is a stanard deal on a financial market.}, including the financial organization.
Technologies of decentralization and smart contracts in particular provide the foundation for a much more fundamental entity --- one which goes far beyond standard simple templated purely-financial deals. Instead, this entity can be the implementation of the general economic agent. It can analyze deal proposals and combine them into a very complex deal, which it will evaluate and participate in. As a result, this entity can serve as a liquidity provider, loan broker, a service for finding a counterparty. It is worth noticing that as the blockchain technologies spread into multiple fields (not only financial), a service like that can become much more versatile and participate in deals including various assets (domain names, art, computational resources are the examples of what can be possible now, future applications will go much further).
The goal of this whitepaper is to present such an entity --- Agorata.
A deal proposal is made by the user in the form of a smart contract. A smart contract is considered as an entity with which other entities (users, smart contracts) can interact via messages\footnote{The message concept used here is from The Open Network (TON). A message can include tokens, commands, information, code.}.
For a state of the contract we can determine the messages that can be sent to the contract and for each of them --- the response messages and the next state. The deal is represented as a tree with states as leafs and actions (messages) as edges. Depending on the actions, the deal has a total outcome --- the number of tokens that were gained/spent by the agent.
Each action (message) has parameters $\theta$, including:
\begin{enumerate}
\item$t$ --- the time at which the message is sent.
\item$s$ --- the sender of the message.
\item tokens sent with the message.
\item any other possible information.
\end{enumerate}
The parameter space for each action can be constrained --- the smart contract can reject some of the messages. For instance, this can lead to the entire space consisting of a single element (the contract rejects everything except for one specific message, e.g. a specific person sending a specific amount of tokens).
The main parameters of the state are the financial outcomes for the smart contracts.
Given these parameters, the value function $V((x_{i}), (t_{i}))$ (or $V(S)$) can be determined. It takes the sequence of values $(x_{i}, t_{i})$, where $x_{i}$ are the incoming/outcoming tokens from the agent.
The agent considers the worst case of the deal from the perspective of game theory: the best (from the perspective of the value function) actions of the agent and the ``worst'' actions of the counteragents.
This sequence of events is the run through the value function in order to make a decision.
The algorithm starts at the node $S_{0}$, then considers all the possible actions (including the abscence of one) and calls the algorithm at $S_{0i}$. If there is any action of the counteragent that makes the contract non-profitable for the agent, the deal is considered non-profitable. If there is no possible action and the state includes profit for the agent, the deal is considered acceptable.
In the previous section of the article we specified how the decisions are made. One of the most important parts of the process is finding out whether there exists any action that makes the deal profitable or unprofitable. It is also important to know which actions the agent should make to maximize its output. How do we do that?
The state parameters are represented as functions of action parameters expressed in a formal language. This allows to make all the decision based on mathematically proven algorithms.