TLDR:
- Constant Product Markets (CPMs) have a number of helpful properties (such as optimal arbitrage and bounded deviation from reference price) that can be represented by convex equations.
- The researchers’ analytical modeling (agent-based simulation) reinforces these mathematical properties, implying that under certain conditions CPMs can be robust price oracles.
- Constant Mean Markets share a majority of these properties of CPMs.
Core Research Question
- Are Constant Product Markets stable and can the mathematical properties of these markets be represented with convex equations?
Citation
Background
- Constant Product Markets (CPMs) are markets where the product of the reserves of the two assets in a liquidity pool remains relatively constant.
- Constant Mean Markets (CMMs) are a generalization of CPMs where the geometric mean of the reserves is kept constant.
- Automated Market Makers (AMMs) (eg. Uniswap) are generally constant product markets that implement pools of asset pairs with which users can trade or add/remove liquidity.
- A Liquidity Provider (LPs) is a user that deposits proportional amounts of two tokens into a pool of liquidity in an AMM.
- An Arbitrage Opportunity is defined here as a situation where trading some amount of a loaned asset for some amount of a second asset and then returning the original loaned amount will yield a net positive result for the trader.
- The Optimal Arbitrage problem is the problem of finding a mathematical solution for maximal profit from these arbitrage opportunities.
- Trading Risk Functions are cost functions which could cause a trader to fail to close an arbitrage opportunity, and are composed of multiple factors: noisy information, front-running, trading delays, etc.
- Cost of Manipulation represents risk, transaction, and other costs incurred by an actor seeking to manipulate prices on the system.
- Convex Optimization Problems are problems where the solutions are subject to the constraints of convex functions. In particular, there is one globally optimal solution and if a local optimum is found, it is also the global optimum. This means solutions to these problems are generally simple or easy to implement.
Summary
- For Uniswap and CPMs more broadly, the researchers present formulas for optimal arbitrage and bounds on deviation from reference market price and on manipulation costs using simple mathematical equations.
- They also present formulas showing how many of these properties generalize to CMMs.
- They run a multi-agent simulation of users interacting with the Uniswap contract while varying market parameters to show that the system can be stable under a variety of conditions and that, in practice, the properties presented should hold.
- The researchers conclude that these properties do hold, can be represented by convex formulas, and, assuming some liquidity conditions, Uniswap can be a robust price oracle for smart contracts.
Method
- This research paper outlines a study of Constant Product Markets (Uniswap) and Constant Mean Markets using two approaches: 1) formal mathematical analysis and 2) an analytical simulation to confirm the results.
- Formal Analysis
- Optimal Arbitrage
- The optimal arbitrage problem in the infinitely liquid market case is not obviously convex, but the researchers re-wrote it such that it is more obviously convex, and then used that to derive an analytical form for optimal trade amounts.
- No-Arbitrage Conditions
- The researchers differentiated the constant-product market formula and applied basic algebra to discover bounds on the deviation of Uniswap market price versus external reference price.
- Optimal Arbitrage
- Risk Models
- The researchers wrote out the optimal arbitrage formula and then added in an example risk function based on marginal price after a trade, which happens to be convex in order to show how risk functions can be convex.
- Other Properties of CPMs
- Using simple transformations of the aforementioned formulas as well as some basic calculus and algebra, the researchers demonstrate a few other mathematical properties of CPMs via formal analysis.
- Extensions to Constant Mean Markets
- The researchers relax equality constraints and perform algebraic substitutions in a number of the Constant Product Market formulas to produce a new set that apply to Constant Mean Markets, in order to show which properties carry over to CMMs.
- Simulation
- To verify the results of these mathematical formulas, the team constructed an agent-based simulation using the Gauntlet DSL on a simulated ETH blockchain using Python bindings.
- The simulation was run for a predetermined number of time steps. At each step, the environment state variables were updated. The researchers also included policies on when new agents were added to the environment.
- They then calculated the utility of actions for those agents to determine what actions they would execute (i.e. their transactions).
- They defined three classes of agents used in the simulation: 1) arbitrageurs, 2) Liquidity Providers, and 3) traders.
- Arbitrageurs in this model try to maximize their profit by trading between Uniswap and an external reference market using the modified marginal pricing function with ‘cost of risk’ taken into account.
Results
- Formal Results
- Optimal Arbitrage problems for CPMs are convex problems.
- Assuming No-Arbitrage, Uniswap prices should deviate by at most a factor of (1 - transaction fee), suggesting that the larger the trade fees, the larger the gap between the reference price and the Uniswap market price.
- Risk Models
- There are many factors which could cause an agent to fail to close an arbitrage opportunity, including noisy information, front-running, and trading delays.
- An agent may not always want to perform a trade for the exact solution the researchers identify for the optimal arbitrage problem, and this discrepancy can be represented by a ‘cost of risk’ function (which is convex and non-decreasing)
- Other Properties of CPMs:
- Increasing product constant: for every trade the product constant is non-decreasing (and if transaction fee is > 0 then it is strictly increasing)
- Splitting trades is more expensive: When transaction fee > 0, it will be more profitable to trade between two tokens in a single trade than it is in two subsequent trades that add up to the same amount. This implies that, when a reference market is infinitely liquid, an arbitrageur cannot do better by visualizing several trading steps ahead than by simply solving the Optimal Arbitrage Problem and executing that trade.
- No depletion property: It is impossible to completely deplete the reserves of two tokens in Uniswap by just trading those tokens. The researchers show that the total reserve is always bounded from below by applying the arithmetic-geometric mean inequality.
- Increasing liquidity with increasing reserves: the more reserves there are, the less any one trade will cost. The marginal cost of a Uniswap trade is strictly decreasing as reserves are increasing, assuming the Uniswap market price stays constant.
- Cost of manipulations: In the no-fee case with an infinitely liquid reference market, there is a lower bound to the cost of manipulating the price of a CPM for each time period (e.g. the time for a block to be mined). This extends to the case with fees as well. Further, this cost of manipulation scales linearly with reserves, which is another reason why large reserved pools are important.
- LP Returns: In the no fee case, the researchers produce a formula for computing the portfolio value of the Uniswap contract. Since this return depends only on the relative ratio of the sizes of the reserves of the two tokens, the result holds even when LPs add or remove tokens from the reserves, although in practice, the price is likely to be more unstable if reserves are smaller.
- Extension to Constant Mean Markets
- Constant Mean Markets have their own optimal arbitrage problem solution.
- Nearly all the conditions and properties of Constant Product Markets also hold for Constant Mean Markets in a similar form.
- However, it is not clear that there exists a closed-form solution for the no-arbitrage conditions outlined for CPMs that also applies to CMMs.
- Simulation Results
- Agent-Based Simulation of Uniswap Markets
- The researchers’ results suggest the theoretical results above hold in practice under a wide variety of market conditions.
- Arbitrage Bounds
- The researchers show that even in the presence of outside noise (e.g. random noise) or changes in reserves due to rational LPs, the marginal Uniswap price stays within predicted no-arbitrage bounds.
- Initial LP Returns
- The researchers recorded the performance of initial LPs relative to a portfolio comprised of coins A and B, and found that in almost all simulations, initial LPs end up having negative utility over most varying conditions. They only have positive expected value when the mean market return is close to zero.
- Agent-Based Simulation of Uniswap Markets
Discussion & Key Takeaways
- Constant Product Markets have properties that can be solved with convex formulas such as:
- a calculable optimal arbitrage opportunity
- bounds on difference between internal and external asset price
- convex trade risk formulas, increasing product constant
- splitting trades is less efficient
- reserves are largely non-depletive
- they have lower-bounded costs of manipulation
- returns can be theoretically computed.
- The researchers conclude that their analytical modeling (agent-based simulations) confirms these theoretical properties, implying that CPMs (under certain conditions) are robust price oracles.
Implications & Follow-ups
- Many of the properties applicable to CPMs are transferable to Constant Mean Markets via generalization. The researcher identified this as an interesting avenue of exploration for future work.
Applicability
- CPMs are implemented in a number of live Decentralized Finance applications, most notably Uniswap.
- Other products like Celo are mentioned by the researchers as they use the CPM as a DEX oracle.
- The researchers later built on this work in future papers, including “Why stake when you can borrow?”