{"repo":"ccyanxyz/uniswap-arbitrage-analysis","free":true,"listed":false,"github":"https://github.com/ccyanxyz/uniswap-arbitrage-analysis","clone":"git clone https://github.com/ccyanxyz/uniswap-arbitrage-analysis.git","description":"Uniswap arbitrage problem analysis","language":"Python","stars":2120,"topics":["uniswap","arbitrage","defi","flashloan"],"license":null,"category":"blockchain-web3","readme_excerpt":"Uniswap Arbitrage Analysis See readme en.pdf 0.Foreword ​ Uniswap is the most popular dex with more than 11000 trading pairs and 2B dollars liquidity. Where there is a market, there are arbitrage opportunities. On uniswap we can trade coin A for coin D follow a given path, e.g. A- B- C- D, A and D can also be the same coin, which means, you can trade A for A follow a given path, and if you are lucky, you can get more A than the original input amount! So how do we find such a path and determine the optimal input amount for maximum profit? Here we go: 1.Arbitrage problem alalysis In order to perform an arbitrage, we need to figure out 2 things: How to find the best path: from A- ?- ?- ...- A How to find the optimal input amount? 1.1 Path finding Each coin is a vertex of a graph, and each trading pair is an edge in the graph, now the problem is how to find a circle in such a graph? This is a classic graph problem, we can use depth first search(DFS) to solve it, with DFS, we can also control the max path length, which is import for an arbitrage since longer path requires more gas! Here is a sample code: 1.2 Optimal input amount Let's do a little recap on the uniswap constant function market maker(CFMM) model, assume there is a trading pair for coin A and B, reserve for A is $R 0$, reserve for B is $R 1$, now we use ${\\Delta} a$ amount of A to trade for $\\Delta b$ amount of B, assume the fee is $1-r$, the following equation holds: $(R 0 + r\\Delta a)(R 1 - \\Delta b) = R 0R 1$ The e","default_branch":null,"files":null,"tree":[],"storefront":"/r/ccyanxyz","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/ccyanxyz/uniswap-arbitrage-analysis/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}