Cyclic Arbitrage in Decentralized Exchanges
Cyclic Arbitrage in Decentralized Exchanges
Cyclic Arbitrage in Decentralized Exchanges
shows an example of cyclic arbitrage happened on October cyclic arbitrage, with the theoretical analysis of the arbi-
30, 2020. trage model, the measurement of exploitable arbitrage op-
portunities, the measurement of exploited cyclic arbitrage,
and the measurement of cyclic arbitrage implementations.
Second, we provide the measurement of state-of-the-art in
terms of (cyclic) arbitrages in DEXes. Finally, we reveal that
blockchain technology enables users to explore more trading
strategies. Further studies in DEXes may provide us with
novel understandings of user behaviors in financial markets.
blockchain ecosystem incentives the emergence of on-chain market segmentation among different countries and sug-
financial systems, i.e., Decentralized Finance (DeFi). DeFi ap- gested that capital controls are the main reasons for market
plications are smart contracts deployed on Ethereum, which segmentation. Nan and Kaizoji [34] studied the potential
support sophisticated financial services, such as borrowing triangular arbitrage with Bitcoin, Euro and U.S. dollar and
and lending [27], asset exchanges [7], leverage trading [1], analyzed market data with a bivariate GARCH model. Never-
as well as novel applications such as flash loans [40]. theless, previous studies have only investigated exploitable
Decentralized exchanges (DEXes) are one of the finan- arbitrage opportunities in CEXes, and none of them have
cial infrastructures of the blockchain ecosystem. Compared measured exploited arbitrages in the market. Meanwhile,
to centralized exchanges (CEXes), DEXes do not involve the arbitrage strategy they studied has many constraints
any centralized operators. Users do not need to transfer to be implemented in markets, such as cross-border capital
their assets to the operator before conducting market op- controls and instantaneous transfers between CEXes.
erations [22]. In contrast, they send on-chain transactions Recently, DEXes have attracted attention worldwide as
to DEXes smart contracts to place orders while they keep an emerging alternative of CEXes for exchanging cryptocur-
control of their assets during the entire process. DEXes sup- rencies. Daian et al. [13, 14] have analyzed the fundamental
port mutual trades among different cryptocurrencies. The weakness of DEXes: slow (on-chain) trading. Since transac-
prevalent DEX mechanisms operate through so-called au- tions are broadcast in the Ethereum network, adversaries
tomated market makers (AMM), which aggregate liquidity can observe profitable transactions before they are executed
(i.e., cryptocurrencies) within liquidity pools contributed and place their own orders with higher fees to front-run the
by liquidity providers. Traders can exchange cryptocurren- target victim. Front-running attackers bring threats to the
cies with the liquidity pool and pay commission fees to the market and system stability. Arbitrageurs optimize network
liquidity providers. For example, when traders want to ex- latency aggressively and conduct priority gas auctions to
change cryptocurrency 𝐴 for 𝐵, they can call a smart contract front-run profitable trades [28], which results in excessive
function that transfers 𝐴 from the traders’ accounts to the transaction fees affecting normal users in blockchain ecosys-
liquidity pool between 𝐴 and 𝐵. The liquidity pool then sends tems. Moreover, because of the high miner-extractable value,
𝐵 to the traders’ account. The exchange process does not fee-based forking attacks and time-bandit attacks are created
involve the participation of any other traders. The exchange and bring systemic consensus-layer vulnerabilities. Zhou et
rate between 𝐴 and 𝐵 is determined by transparently prede- al. [45] and Torres et al. [18] studied sandwiching attacks, i.e.,
fined functions encoded in the DEX smart contract. combinations of front and back-running, in DEXes. When
The constant product function is one of the most widely observing a victim transaction, attackers place one order just
used pricing mechanism. Assume a trader want to exchange before it (front-run) and place an order just after it (back-run)
𝛿𝑎 of 𝐴 for 𝐵 token and the liquidity of 𝐴 and 𝐵 are 𝑎 and 𝑏, to benefit themselves through the variance of the exchange
respectively. The following equation always hold during the rates. Qin et al. [39] quantified the revenue of arbitrages in
transaction: 𝑎 · 𝑏 = (𝑎 + 𝛿𝑎 · 𝑟 1 ) · (𝑏 − 𝛿𝑟𝑏2 ), where 𝑟 1 and 𝑟 2 DEXes. However, this work lacks a systematic analysis of
denote the commission fee in asset 𝐴 and 𝐵 respectively. In arbitrage behavior and only measures the exploited arbitrage
Uniswap [7], 𝑟 1 = 0.997 and 𝑟 2 = 1, which indicates that the opportunities of 144 cryptocurrencies.
commission fee is equal to 0.3% · 𝛿𝑎 . The remaining liquidity Compared to previous studies, our work fills the follow-
·𝑟 2 ·𝑏 ·𝛿𝑎
in the pool equals to (𝑎 + 𝛿𝑎 , 𝑏 − 𝑟 1𝑎+𝑟 1 ·𝛿𝑎
). ing two research gaps to provide a more comprehensive
understanding of cyclic arbitrage. First, we do not only con-
sider potential arbitrage opportunities in the market but also
compare with exploited arbitrage opportunities. Second, we
2.3 Arbitrage in Cryptocurrency Markets examine different implementations of arbitrage strategies
Research on arbitrage in cryptocurrencies is still in its begin- in DEXes and discuss how smart contract technology could
ning. Previous studies focus on either theoretical analysis help traders to mitigate the financial loss from the price
of the behavior of miners and traders in blockchain sys- impact.
tems [9, 16, 17, 24–26, 30, 32, 35, 41, 42], or the influence
of cryptocurrencies as a potential payment and transaction 3 CYCLIC ARBITRAGE MODEL
mechanism in financial markets [8, 11, 15, 21, 23, 36]. In this section, we propose a theoretical framework of cyclic
Some recent studies [10, 20, 31, 34, 37] have noted the arbitrage, and then examine the profitability and the optimal
prices discrepancies of cryptocurrencies in CEXes. Makarov revenue of cyclic arbitrage in CPMM.
and Schoar [31] studied price deviations and potential ar-
bitrage opportunities of Bitcoin, Ethereum, and Ripple for Arbitrage model: A cyclic transaction between 𝑛 tokens
34 CEXes across 19 countries. They observed significant 𝐴1, 𝐴2, . . . , 𝐴𝑛 is a sequence of 𝑛 trades:
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer
Trade 1: Exchange 𝛿 1 of 𝐴1 with 𝛿 2 of 𝐴2 . Algorithm 1 Compute the equivalent liquidity of the cycle
Trade 2: Exchange 𝛿 2 of 𝐴2 with 𝛿 3 of 𝐴3 . 1: ′ ←𝑎
𝑎 1,𝑛 1,2
... ′ ←𝑎
2: 𝑎𝑛,1 2,1
Trade 𝑛: Exchange 𝛿𝑛 of 𝐴𝑛 with 𝛿 1′ of 𝐴1 . 3: for 𝑖 from 2 to ′𝑛 − 1 do
′ ← 𝑎 1,𝑛 ·𝑎𝑖,𝑖+1
Note that the output of Trade 𝑖 exactly equals to the input 4: 𝑎 1,𝑛 𝑎𝑖,𝑖+1 +𝑟 1 ·𝑟 2 ·𝑎′𝑛,1
of Trade 𝑖 + 1, while the revenue of the cyclic transaction is ′ ←
′ ·𝑎
𝑟 1 ·𝑟 2 ·𝑎𝑛,1 𝑖+1,𝑖
differences between the output of Trade 𝑛 and the input of 5: 𝑎𝑛,1 ′
𝑎𝑖,𝑖+1 +𝑟 1 ·𝑟 2 ·𝑎𝑛,1
Trade 1, i.e., 𝛿 1′ − 𝛿 1 . 6: end for
As we state in the introduction, the exchange rates be-
tween different token pairs may not be synchronized per-
√
fectly. However, it is not clear under which conditions that 𝑜𝑝 𝑟 1 ·𝑟 2 ·𝑎′ ·𝑎−𝑎
through 𝐴1 → 𝐴2 → . . . → 𝐴𝑛 → 𝐴1 as 𝛿𝑎 = 𝑟1 ,
exploitable arbitrage opportunities exist in the market as 𝑎′ ·𝑎𝑛,1 𝑟 1 ·𝑟 2 ·𝑎 1,𝑛 ·𝑎′
users also need to pay the commission fee for each trade. where 𝑎 = 𝑎𝑛,1 +𝑟
1,𝑛
′
1 ·𝑟 2 ·𝑎𝑛,1
and 𝑎 ′ = 𝑎𝑛,1 +𝑟 1 ·𝑟 2 ·𝑎𝑛,1
′ . We refer read-
𝑛,1
Therefore, we analyze the profitability and the optimal trad- ers to Appendix B for a detailed analysis.
ing strategy of a cyclic arbitrage in CPMM.
4 CYCLIC ARBITRAGE OPPORTUNITIES
Profitability conditions: Assume we have three tokens 𝐴1, 𝐴2,
and 𝐴3 , and three liquidity pools between three tokens. We From Algorithm 1, we can infer that only the amounts of re-
denote 𝑎𝑖,𝑗 as the amount of reserved 𝐴𝑖 in the liquidity pool served tokens in liquidity pools and the trading direction are
with token 𝐴 𝑗 . Then, the revenue of trading 𝛿 1 of token 𝐴1 needed for determining the optimal trading strategies. When
through the cycle 𝐴1 → 𝐴2 → 𝐴3 → 𝐴1 is an Ethereum block is published, the updated information
𝑟 12 ·𝑟 22 ·𝑎 2,1 ·𝑎 3,2 ·𝑎 1,3 of liquidity pools is available to all traders. Therefore, with
𝑟 1 ·𝑟 2 ·
𝑎 2,3 ·𝑎 3,1 +𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,1 +𝑟 12 ·𝑟 22 ·𝑎 2,1 ·𝑎 3,2
𝛿 1′ − 𝛿1 = ( 𝑎 1,2 ·𝑎 2,3 ·𝑎 3,1 − 1) · 𝛿 1 . our theoretical model, we are able to investigate exploitable
+𝑟 1 ·𝛿 1 cyclic arbitrage opportunities in DEXes. We choose Uniswap
𝑎 2,3 ·𝑎 3,1 +𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,1 +𝑟 12 ·𝑟 22 ·𝑎 2,1 ·𝑎 3,2
Traders can benefit from the cyclic transaction only if V2 as the example for the empirical analysis because Uniswap
the revenue, i.e., 𝛿 1′ − 𝛿 1 , is larger than 0. We generalize the V2 has the longest operation time, the most active traders,
profitability conditions for 𝑛 tokens in Theorem 1. In gen- and the most liquidity pools among all DEXes [2, 6].
eral words, only if the arbitrage index, i.e., the product of 𝑛
exchange rates along the cycle, is larger than the commis- Data collection: Every market operation on Uniswap is
sion fees paid in the 𝑛 pools, there exists exploitable cyclic recorded on Ethereum blocks. We launch go-ethereum, an
arbitrage opportunity. Ethereum client, on our server to collect data from block
10000835 (when Uniswap V2 has been deployed, 4th May
Theorem 1 (cf. Appendix A). For a given cycle 𝐴1 → 2020) to block 12244144 (15th April 2021). We observe that
𝐴2 → . . . → 𝐴𝑛 → 𝐴1 with 𝑛 tokens, there exists an arbitrage a Sync event is recorded in the blockchain receipt when a
opportunity for the cyclic transaction if the product of exchange market operation happens on Uniswap, and the event in-
𝑎 ·𝑎 3,2 ·...·𝑎 1,𝑛
rates 𝑎2,1
1,2 ·𝑎 2,3 ·...·𝑎𝑛,1
> 𝑟 𝑛1·𝑟 𝑛 , where 𝑎𝑖,𝑗 denotes the liquidity of cludes the liquidity of tokens in the pool after the market
1 2
token 𝐴𝑖 in the liquidity pool with token 𝐴 𝑗 . Meanwhile, the operation. Therefore, by collecting all Sync events, we are
arbitrage cannot benefit from the reversed direction 𝐴1 → able to recover the market states of all liquidity pools on
𝐴𝑛 → . . . → 𝐴2 → 𝐴1 for cyclic transactions. Uniswap V2 over time. More preciously, we build a dataset
that includes the liquidity reserved in all liquidity pools on
Optimal trading strategy: In addition to noticing whether Uniswap V2 after the execution of transactions in each block.
there are exploitable cyclic arbitrage opportunities in mar-
kets with Theorem 1, it is also important for traders to find Profitable opportunities: With such a dataset, we find prof-
a proper trading strategy to maximize the revenue. It is intu- itable cycles in the market and compute the optimal trading
itive that if the derivative of the revenue function to the initial input of each exploitable cyclic transaction and the corre-
trading amount is zero, then we acquire the optimal revenue. sponding revenue. We consider exploitable cyclic arbitrage
We design an algorithm to compute the optimal trading vol- opportunities within the cycles with length three that in-
ume of a cyclic arbitrage (cf. Algorithm 1). If we exchange 𝛿 1 volve ETH. As more than 80% liquidity pools in Uniswap V2
of 𝐴1 through the cycle to obtain 𝛿𝑛 of 𝐴𝑛 , we can equate this are between ETH and another cryptocurrency [43], we infer
behavior as exchanging 𝛿 1 of 𝐴1 in another liquidity pool that we provide a reasonable lower bound for estimating the
between 𝐴1 and 𝐴𝑛 where the amount of reserved tokens of exploitable opportunities.
𝐴1 and 𝐴𝑛 are 𝑎 1,𝑛′ and 𝑎 ′ respectively. We then further com- Because most Ethereum transactions pay more than 0.0001
𝑛,1
pute the optimal trading volume for the cyclic transaction ETH as gas fee to miners, we count the number of cycles that
Cyclic Arbitrage in DEXes Conference’17, July 2017, Washington, DC, USA
2 The basic gas consumption of a Uniswap transaction is higher than 100,000 Data collection: For each successful exchange between
and the gas price is always higher than 1 GWei (10−9 ETH per gas). two tokens, a Swap event will be recorded in the blockchain
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer
4,000
3,000 103
Number of Transactions
102
2,000 101
100
1,000
10−1
payment system. Bank of Finland Research Discussion Paper 27 (2017). [43] Ye Wang, Lioba Heimbach, and Roger Wattenhofer. 2021. Behavior
[24] Aggelos Kiayias, Elias Koutsoupias, Maria Kyropoulou, and Yiannis of Liquidity Providers in Decentralized Exchanges. arXiv preprint
Tselekounis. 2016. Blockchain mining games. In Proceedings of the arXiv:2105.13822 (2021).
2016 ACM Conference on Economics and Computation. 365–382. [44] Gavin Wood et al. 2014. Ethereum: A secure decentralised generalised
[25] Elias Koutsoupias, Philip Lazos, Foluso Ogunlana, and Paolo Serafino. transaction ledger. Ethereum project yellow paper 151, 2014 (2014),
2019. Blockchain mining games with pay forward. In The World Wide 1–32.
Web Conference. 917–927. [45] Liyi Zhou, Kaihua Qin, Christof Ferreira Torres, Duc V Le, and Arthur
[26] Yujin Kwon, Dohyun Kim, Yunmok Son, Eugene Vasserman, and Yong- Gervais. 2021. High-frequency trading on decentralized on-chain
dae Kim. 2017. Be selfish and avoid dilemmas: Fork after withholding exchanges. In 2021 IEEE Symposium on Security and Privacy (SP). IEEE,
(faw) attacks on bitcoin. In Proceedings of the 2017 ACM SIGSAC Con- 428–445.
ference on Computer and Communications Security. 195–209.
[27] Robert Leshner and Geoffrey Hayes. 2019. Compound Finance
Whitepaper.
[28] Michael Lewis. 2014. Flash boys: a Wall Street revolt. WW Norton &
Company.
[29] Bowen Liu, Pawel Szalachowski, and Jianying Zhou. 2020. A first look
into defi oracles. arXiv preprint arXiv:2005.04377 (2020).
[30] Hanqing Liu, Na Ruan, Rongtian Du, and Weijia Jia. 2018. On the strat-
egy and behavior of bitcoin mining with n-attackers. In Proceedings of
the 2018 on Asia Conference on Computer and Communications Security.
357–368.
[31] Igor Makarov and Antoinette Schoar. 2020. Trading and arbitrage in
cryptocurrency markets. Journal of Financial Economics 135, 2 (2020),
293–319.
[32] Francisco J Marmolejo-Cossío, Eric Brigham, Benjamin Sela, and
Jonathan Katz. 2019. Competing (semi-) selfish miners in Bitcoin.
In Proceedings of the 1st ACM Conference on Advances in Financial
Technologies. 89–109.
[33] Frank McCormick. 1979. Covered interest arbitrage: unexploited prof-
its? Comment. Journal of Political Economy 87, 2 (1979), 411–417.
[34] Zheng Nan and Taisei Kaizoji. 2019. Bitcoin-based triangular arbitrage
with the Euro/US dollar as a foreign futures hedge: modeling with
a bivariate GARCH model. Quantitative Finance and Economics 3, 2
(2019), 347–365.
[35] Kartik Nayak, Srijan Kumar, Andrew Miller, and Elaine Shi. 2016.
Stubborn mining: Generalizing selfish mining and combining with
an eclipse attack. In 2016 IEEE European Symposium on Security and
Privacy (EuroS&P). IEEE, 305–320.
[36] Emiliano Pagnotta and Andrea Buraschi. 2018. An equilibrium valu-
ation of bitcoin and decentralized network assets. Available at SSRN
3142022 (2018).
[37] Lukáš Pichl, Zheng Nan, and Taisei Kaizoji. 2020. Time series analysis
of ether cryptocurrency prices: Efficiency, predictability, and arbitrage
on exchange rates. In Advanced studies of financial technologies and
cryptocurrency markets. Springer, 183–196.
[38] Kaihua Qin, Liyi Zhou, Yaroslav Afonin, Ludovico Lazzaretti, and
Arthur Gervais. 2021. CeFi vs. DeFi–Comparing Centralized to Decen-
tralized Finance. arXiv preprint arXiv:2106.08157 (2021).
[39] Kaihua Qin, Liyi Zhou, and Arthur Gervais. 2021. Quantifying
Blockchain Extractable Value: How dark is the forest? arXiv preprint
arXiv:2101.05511 (2021).
[40] Kaihua Qin, Liyi Zhou, Benjamin Livshits, and Arthur Gervais. 2021.
Attacking the DeFi Ecosystem with Flash Loans for Fun and Profit. In
International Conference on Financial Cryptography and Data Security.
Springer.
[41] Geoffrey Ramseyer, Ashish Goel, and David Mazieres. [n. d.]. Scaling
On-Chain Asset Exchanges via Arrow-Debreu Exchange Markets. ([n.
d.]).
[42] Ayelet Sapirshtein, Yonatan Sompolinsky, and Aviv Zohar. 2016. Opti-
mal selfish mining strategies in bitcoin. In International Conference on
Financial Cryptography and Data Security. Springer, 515–532.
Cyclic Arbitrage in DEXes Conference’17, July 2017, Washington, DC, USA
Proof. We can observe that the transaction through 𝐴1 ⇌ 𝜕𝑈𝐴1𝐴2𝐴𝑛 𝐴1 𝑟 1𝑛 · 𝑟 2𝑛 · 𝑎 1,𝑛 · 𝑎 2,1 · . . . · 𝑎𝑛,𝑛−1
= −1 (3)
𝐴2 and 𝐴2 ⇌ 𝐴3 is equivalent to an exchange of 𝛿 1 through 𝜕𝛿 1 𝛿 1 =0 𝑎 1,2 · 𝑎 2,3 · . . . · 𝑎𝑛,1
𝑎 1,2 ·𝑎 2,3
liquidity pool 𝐴1′ ⇌ 𝐴3′ , where 𝑎 1,3′ = ′
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 , and 𝑎 3,1 =
𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2
If arbitrageurs can make profit in this trading direction,
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 . then,
We prove this lemma by induction. We first show it is
correct when 𝑛 = 3. 𝜕𝑈𝐴1𝐴2𝐴𝑛 𝐴1
We take the utility function of a cyclic transaction of three 0<
𝜕𝛿 1 𝛿 1 =0
tokens and compute the first deviation of the function, (4)
1 𝑎 1,𝑛 · 𝑎 2,1 · . . . · 𝑎𝑛,𝑛−1
<
𝑟 1𝑛 · 𝑟 2𝑛 𝑎 1,2 · 𝑎 2,3 · . . . · 𝑎𝑛,1
,
𝑟 1𝑛 ·𝑟 2𝑛 ·𝑎 1,2 ·𝑎 2,3 ·...·𝑎𝑛,1
𝜕𝑈𝐴1𝐴2𝐴3𝐴1 𝑟 13 · 𝑟 23· 𝑎 1,3 · 𝑏 2,1 · 𝑏 3,2 which implies that 𝑎 1,𝑛 ·𝑎 2,1 ·...·𝑎𝑛,𝑛−1 < 1,
= −1 (1)
𝜕𝛿 1 𝛿 1 =0 𝑎 1,2 · 𝑎 2,3 · 𝑏 3,1 then
𝜕𝑈𝐴1 𝐴𝑛 𝐴2 𝐴1
< 0.
𝜕𝛿 1
𝛿 1 =0
By computing the second derivative of 𝑈𝐴1𝐴𝑛 𝐴2𝐴1 , we know
𝜕2 +
For 𝑛 ≥ 3, the inductive hypothesis is that the equation is that 𝜕𝛿 2 𝑈𝐴1 𝐴𝑛 𝐴2 𝐴1 is negative for all 𝛿 1 ∈ 𝑅 . 𝑈𝐴1 𝐴𝑛 𝐴2 𝐴1 is a
1
true for 𝑛: monotone decreasing function in its domain, and the max-
𝜕𝑈 𝑟 1𝑛 ·𝑟 2𝑛 ·𝑎 1,𝑛 ·𝑎 2,1 ·...·𝑎𝑛,𝑛−1 imum value of 𝑈𝐴1𝐴𝑛 𝐴2𝐴1 is 0 at 𝛿 1 = 0. Therefore, there is
𝜕𝛿 1 = 𝑎 1,2 ·𝑎 2,3 ·...·𝑎𝑛,1 − 1.
𝛿 1 =0 no opportunity for arbitrage through the reversed direction
The inductive step is to prove the equation for 𝑛 + 1: 𝐴1 → 𝐴𝑛 → . . . → 𝐴2 → 𝐴1 for cyclic transactions.
If we exchange 𝛿 1 through 𝐴1 ⇌ 𝐴2 pool to get 𝛿 2 , and Arbitrageurs cannot benefit from trading 𝛿 1 through 𝐴1 →
obtain 𝛿 3 from 𝐴2 ⇌ 𝐴3 by trading 𝛿 2 right after, these two 𝐴𝑛 → . . . → 𝐴2 → 𝐴1 , sequentially. Therefore, arbitrageurs
atomic transactions can is equivalent to a single transaction have at most one direction to benefit themselves with cyclic
𝑎 1,2 ·𝑎 2,3
with 𝛿 1 in a virtual pool 𝐴1′ ⇌ 𝐴3′ , where 𝑎 1,3
′ =
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 , transactions.
′ = 𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2 .
and 𝑎 3,1 □
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1
We assume that the statement is correct for any 𝑛-path
cyclic transaction. Consider a cyclic transaction through a B OPTIMAL TRADE VOLUME
𝑛 + 1-path 𝐴1 → 𝐴2 → . . . → 𝐴𝑛 → 𝐴𝑛+1 → 𝐴1 , which We start from a simple case where cyclic transactions happen
is equivalent to a 𝑛-path cyclic transaction through 𝐴1′ → in a cycle of token 𝐴1 , 𝐴2 , and 𝐴3 . We denote 𝑎𝑖,𝑗 as the
𝐴3′ → . . . → 𝐴𝑛+1 → 𝐴1′ , where the first deviation of the liquidity of token 𝐴𝑖 in the liquidity pool with token 𝐴 𝑗 . If
utility function at 𝛿 1 = 0 is, we directly exchange 𝐴3 with 𝛿 1 of 𝐴1 , then we receive the
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer
𝑟 ·𝑟 ·𝑎 ·𝛿
output amount of 𝐴3 , 𝛿 3 = 1𝑎1,32+𝑟3,1
1 ·𝛿 1
1
. If we take token 𝐴2
as an intermediate, then the output amount of 𝐴3 is 𝛿 3′ = 𝜕𝑈𝐴1𝐴2𝐴3𝐴1 𝑟 1 · 𝑟 2 · 𝑎 ′ · (𝑎 + 𝑟 1 · 𝛿 1 ) − 𝑟 1 · (𝑟 1 · 𝑟 2 · 𝑎 ′ · 𝛿 1 )
𝑟 12 ·𝑟 22 ·𝑎 2,1 ·𝑎 3,2 ·𝛿 1
= −1
. 𝜕𝛿𝑎 (𝑎 + 𝑟 1 · 𝛿 1 ) 2
𝑎 1,2 ·𝑎 2,3 +𝑟 1 ·𝛿 1 ·(𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 )
Compare 𝛿 3 and 𝛿 3′ , 𝛿 3′ can be written in the format as 𝜕𝑈𝐴1𝐴2𝐴3𝐴1 𝑟 1 · 𝑟 2 · 𝑎 ′ · 𝑎
= −1
𝑟 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2
𝑟 1 ·𝑟 2 · 𝑎1 +𝑟 ·𝑟 ·𝑎 ·𝛿 1 𝜕𝛿𝑎 (𝑎 + 𝑟 1 · 𝛿 1 ) 2
𝛿 3′ = 2,3 1 2 2,1
𝑎 1,2 ·𝑎 2,3 . Therefore, this transaction through (6)
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 +𝑟 1 ·𝛿 1
𝜕𝑈𝐴1 𝐴2 𝐴3 𝐴1
two pools can be considered as a transaction through an To maximize the utilize, we have 𝜕𝛿 1 = 0, therefore,
equivalent pool of 𝐴1 and 𝐴3 where the liquidity of 𝐴1 is
′ = 𝑎 1,2 ·𝑎 2,3 ′ 𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2
𝑎 1,3 𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 and the liquidity of 𝐴3 is 𝑎 3,1 = 𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 . 𝑟1 · 𝑟2 · 𝑎′ · 𝑎
Then, we can rewrite the utility function of a cyclic trans- −1=0
(𝑎 + 𝑟 1 · 𝛿 1 ) 2
action in 𝐴1 → 𝐴2 → 𝐴3 → 𝐴1 with input 𝛿 1 as
𝑟 1 · 𝑟 2 · 𝑎 ′ · 𝑎 = (𝑎 + 𝑟 1 · 𝛿 1 ) 2 (7)
√ ′
𝑟1 · 𝑟2 ·
𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2 𝑟1 · 𝑟2 · 𝑎 · 𝑎 − 𝑎
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 · 𝛿1 =
𝑈𝐴1 𝐴2 𝐴3 𝐴1 = ( 𝑎 1,2 ·𝑎 2,3 − 1) · 𝛿 1 (5) 𝑟1
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 + 𝑟 1 · 𝛿1
We can find the equivalent pool of transactions for longer
𝑎′1,3 ·𝑎 3,1 𝑟 1 ·𝑟 2 ·𝑎 1,3 ·𝑎′3,1
Let us denote 𝑎 = 𝑎 3,1 +𝑟 1 ·𝑟 2 ·𝑎′3,1 and 𝑎 ′ = 𝑎 3,1 +𝑟 1 ·𝑟 2 ·𝑎′3,1
paths between any pair of tokens iteratively as in the first
step of computing pools equivalent to 𝐴1 ⇌ 𝐴2 and 𝐴2 ⇌ 𝐴3
and then determine the optimal input of the cyclic transac-
tion.