Abstract
Constant function market makers (CFMMs) such as Uniswap have facilitated trillions of dollars of digital asset trades and have billions of dollars of liquidity. One natural question is how to optimally route trades across a network of CFMMs in order to ensure the largest possible utility (as specified by a user). We present an efficient algorithm, based on a decomposition method, to solve the problem of optimally executing an order across a network of decentralized exchanges. The decomposition method, as a side effect, makes it simple to incorporate more complicated CFMMs, or even include ‘aggregate CFMMs’ (such as Uniswap v3), into the routing problem. Numerical results show significant performance improvements of this method, tested on realistic networks of CFMMs, when compared against an off-the-shelf commercial solver.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
References
Adams, H., Zinsmeister, N., Salem, M., Keefer, R., Robinson, D.: Uniswap V3 Core (2021). https://uniswap.org/whitepaper-v3.pdf
Angeris, G., Agrawal, A., Evans, A., Chitra, T., Boyd, S.: Constant Function market makers: multi-asset trades via convex optimization. In: Tran, D.A., Thai, M.T., Krishnamachari, B. (eds.) Handbook on Blockchain. Springer Optimization and Its Applications, vol. 194, pp. 415–444. Springer, Cham (2022). https://doi.org/10.1007/978-3-031-07535-3_13
Angeris, G., Chitra, T.: Improved price Oracles: constant function market makers. In: Proceedings of the 2nd ACM Conference on Advances in Financial Technologies, pp. 80–91. ACM (2020). https://doi.org/10.1145/3419614.3423251
Angeris, G., Chitra, T., Evans, A.: When does the tail wag the dog? Curvature and market making. Cryptoecon. Syst. 2(1) (2022)
Angeris, G., Evans, A., Chitra, T., Boyd, S.: Optimal routing for constant function market makers. In: Proceedings of the 23rd ACM Conference on Economics and Computation, pp. 115–128 (2022)
Angeris, G., Kao, H.T., Chiang, R., Noyes, C., Chitra, T.: An analysis of uniswap markets. Cryptoecon. Syst. (2020). https://doi.org/10.21428/58320208.c9738e64. https://cryptoeconomicsystems.pubpub.org/pub/angeris-uniswap-analysis
ApS, M.: MOSEK Optimizer API for Python 9.1.5. https://docs.mosek.com/9.1/pythonapi/index.html
Bertsekas, D.: Nonlinear Programming, 3rd edn. Athena Scientific (2016)
Bezanson, J., Edelman, A., Karpinski, S., Shah, V.: Julia: A fresh approach to numerical computing. SIAM Rev. 59(1), 65–98 (2017). https://doi.org/10.1137/141000671
Boyd, S., Vandenberghe, L.: Convex Optimization, 1st edn. Cambridge University Press (2004)
Byrd, R.H., Lu, P., Nocedal, J., Zhu, C.: A limited memory algorithm for bound constrained optimization. SIAM J. Sci. Comput. 16(5), 1190–1208 (1995)
Coey, C., Kapelevich, L., Vielma, J.P.: Solving natural conic formulations with Hypatia.jl (2021)
Danos, V., Khalloufi, H.E., Prat, J.: Global order routing on exchange networks. In: Bernhard, M., et al. (eds.) FC 2021. LNCS, vol. 12676, pp. 207–226. Springer, Heidelberg (2021). https://doi.org/10.1007/978-3-662-63958-0_19
Dantzig, G.B., Wolfe, P.: Decomposition principle for linear programs. Oper. Res. 8(1), 101–111 (1960)
Dunning, I., Huchette, J., Lubin, M.: JuMP: a modeling language for mathematical optimization. SIAM Rev. 59(2), 295–320 (2017). https://doi.org/10.1137/15M1020575. https://epubs.siam.org/doi/10.1137/15M1020575
Egorov, M.: StableSwap - efficient mechanism for Stablecoin liquidity, p. 6. https://www.curve.fi/stableswap-paper.pdf
Legat, B., Dowson, O., Garcia, J., Lubin, M.: MathOptInterface: a data structure for mathematical optimization problems (2021). https://doi.org/10.1287/ijoc.2021.1067. http://pubsonline.informs.org/doi/10.1287/ijoc.2021.1067
Martinelli, F., Mushegian, N.: Balancer: a non-custodial portfolio manager, liquidity provider, and price sensor (2019)
Morales, J.L., Nocedal, J.: Remark on “algorithm 778: L-BFGS-B: Fortran subroutines for large-scale bound constrained optimization”. ACM Trans. Math. Softw. (TOMS) 38(1), 1–4 (2011)
O’Donoghue, B., Chu, E., Parikh, N., Boyd, S.: Conic optimization via operator splitting and homogeneous self-dual embedding. J. Optim. Theor. Appl. 169(3), 1042–1068 (2016). https://doi.org/10.1007/s10957-016-0892-3
Revels, J., Lubin, M., Papamarkou, T.: Forward-mode automatic differentiation in Julia. arXiv arXiv:1607.07892 [cs.MS] (2016)
Wang, Y., Chen, Y., Wu, H., Zhou, L., Deng, S., Wattenhofer, R.: Cyclic arbitrage in decentralized exchanges. In: Companion Proceedings of the Web Conference 2022, Virtual Event, Lyon France, April 2022, pp. 12–19. ACM (2022). https://doi.org/10.1145/3487553.3524201
Zhang, Y., Chen, X., Park, D.: Formal specification of constant product (xy = k) market maker model and implementation (2018)
Zhu, C., Byrd, R.H., Lu, P., Nocedal, J.: Algorithm 778: L-BFGS-B: Fortran subroutines for large-scale bound-constrained optimization. ACM Trans. Math. Softw. (TOMS) 23(4), 550–560 (1997)
Acknowledgements
We thank Francesco Iannelli and Jiahao Song for contributing to the package’s documentation and the Financial Cryptography 2023 reviewers for helpful comments on this paper.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
A Closed Form Solutions
A Closed Form Solutions
Here, we cover some of the special cases where it is possible to analytically write down the solutions to the arbitrage problems presented previously.
Geometric Mean Trading Function. Some of the most popular swap markets, for example, Uniswap v2 and most Balancer pools, which total over $2B in reserves, are geometric mean markets (5) with \(n=2\). This trading function can be written as
where \(0 < w < 1\) is a fixed parameter. This very common trading function admits a closed-form solution to the arbitrage problem (8). Using (12), we can write
where \(\eta = w/(1-w)\). (A similar equation holds for \(f_2\).) Using (15) and (16), and defining
we have that \(\delta _1^\star = \max \{\delta _1, 0\}\) is an optimal point for (14). Note that when we take \(w = 1/2\) then \(\eta = 1\) and we recover the optimal arbitrage for Uniswap given in [6, App. A].
Bounded Liquidity Variation. The bounded liquidity variation (4) of the product trading function satisfies the definition of bounded liquidity given in §4.1, whenever \(\alpha , \beta > 0\). We can write the forward exchange function for the bounded liquidity product function (4), using (12), as
The ‘min’ here comes from the definition of a CFMM: it will not accept trades which pay out more than the available reserves. The maximum amount that a user can trade with this market, which we will write as \(\delta _1^-\), is when \(f_1(\delta _1^-) = R_2\), i.e.,
(Note that this can also be derived by taking \(f_1(\delta _1) = R_2\) in (12) with the invariant (4).) This means that
is the minimum supported price for asset 1. As before, a similar derivation yields the case for asset 2. Writing \(k=(R_1+ \alpha )(R_2 + \beta )\), we see that we only need to solve (14) if the price \(\nu _1/\nu _2\) is in the active interval (17),
Otherwise, we know one of the two ‘boundary’ solutions, \(\delta _1^-\) or \(\delta _2^-\), suffices.
Rights and permissions
Copyright information
© 2024 International Financial Cryptography Association
About this paper
Cite this paper
Diamandis, T., Resnick, M., Chitra, T., Angeris, G. (2024). An Efficient Algorithm for Optimal Routing Through Constant Function Market Makers. In: Baldimtsi, F., Cachin, C. (eds) Financial Cryptography and Data Security. FC 2023. Lecture Notes in Computer Science, vol 13951. Springer, Cham. https://doi.org/10.1007/978-3-031-47751-5_8
Download citation
DOI: https://doi.org/10.1007/978-3-031-47751-5_8
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-47750-8
Online ISBN: 978-3-031-47751-5
eBook Packages: Computer ScienceComputer Science (R0)