Looking For Swap Arbitrage
Q42. Let’s see if we can find any wallets profiting from arbitrage on the Algorand DEXes. We specifically want to see if anyone is conducting arbitrage with USDT or USDC, Asset ID 31566704 or 312769. The period we will want to look at is From January 1st 2022 to current. We will want to grab wallets swapping USDC or USDT to another asset then their next swap being back out of that other asset(with the same amount of it) back to USDT or USDC in their next transaction. If we find a wallets conducting this behavior, let’s look if they end up with more USDT or USDC they started with in the initial swap. If we find users doing this, let's look at the top 10 wallets successfully earning more USDT or USDC. What assets do we see them swapping for when they commit this arbitrage? Show and explain your methodology if we don't see this arbitrage occurring.
Introduction
Arbitrage trades involve taking advantage of a temporary asset price difference between different markets. In crypto trading, due to the nature of centralized (CEX) and decentralized (DEX) exchanges, this can happen for various reasons.
For CEXes, the assets are priced with the last matching buy/sell order from the order books. Differences in trading volume, supply or demand or CEX characteristics like withdrawal processes can mean assets are trading at different prices in time.
DEXes rely on liquidity pools instead of order books to set assets prices. For each trading pair on offer, a liquidity pool needs to be created and liquidity providers deposit both assets in the pool expecting a return from the exchange fees. These fees are paid by the swappers, users exchanging one of the assets in the pair for the other. Due to liquidity pools size, supply and demand and other characteristics, price inefficiencies can also be found in DEXes.
Arbitrage traders will take advantage of this real markets inefficiencies and will execute trades to gain some profits. Once enough traders recognize the inefficiency and execute the arbitrage, price should tend to equalize, closing the difference and the arbitrage opportunity for the slow traders.
There are multiple arbitrage strategies, for this analysis I will explore a simple one involving a swap from stablecoins USDC or USDT for a different asset and back to USDC or USDT in less than a minute. Let's find out how profitable this strategy really is!
Methodology
A series of CTE's is used to organize the data in the algorand.swaps
table to find out these arbitrage swaps.
The first one, ALLSWAPS
will filter all swaps since January 1st, 2022 and order the data by swapper and date.
Next, ALLSWAPS
will be populated with the information from the next trade using lead(fecha_1) over (partition by swapper order by fecha_1) as fecha_2
for each variable of interest. That way, I achieve a ADDNEXTSWAP
table where for each transaction (x_1) made, information of the next transaction (x_2) is also contained within the same row.
Finally, ARBITRAGE
table is created using ADDNEXTSWAP
as input and adding the constraints to find out the arbitrage transactions following the bounty instructions:
-
from_id_2 = to_id_1
to select the same swapped for asset in the first tx as the origin of the second tx -
from_amount_2 = to_amount_1
to select the same swapped for amount in the first tx as the origin of the second tx -
from_id_1 IN (31566704, 312769)
to select only swaps from USDT or USDC -
to_id_2 = from_id_1
to select the same asset swapped back to in the second tx -
swap_time <= 60
to select trades happening in less than a minute from each other to differentiate arbitrage trades to usual swaps where price appreciation over time is the main gain driver
Following the structure described above, a total of 3 independant queries where made to organize the transactions identified as trades in different ways to answer the bounty questions.
Figure 2. shows the top 10 swappers by total gains. As we can see, only one address in the list uses USDT for arbitrage gaining almost 1.5 USDT. The same address is much more profitable with USDC arbitraging, totalling 36 USDC of gains as the Top 2. Top 1 address gained just over 100 USDC from his arbitrage trades. Top 3 and 4 make around 10 USDC gains with their strategy while the rest just barely break even (1-2 USDC gains).
Figure 3. shows the top 10 addresses again, visualizing the correlation between total gain and number of swaps. The two top most profitable addresses have 4 swaps, showing that a successful arbitrage strategy is not correlated with number of swaps.
Figure 4. shows the number of arbitrage swaps by traded pair and DEX. The traded pair is swaped once, and a second time in reverse order.
USDT-ALGO and USDC-ALGO in Tinyman are the most common arbitrage swaps taking place 168 and 75 times respectively. USDC-STBL in Algofi is the third most common swap taking place 69 times, followed by USDC-USDT (64) and USDT-USDC (49) in Tinyman. USDC-BOARD was traded in Tinyman 15 times. USDT-USDC and USDC-USDT was traded in PactFi 14 times each. All other pairs are traded 3 times (USDC-Opulous and USDC-Yieldly) or less.
Figure 5. shows the number of swaps by traded pair and gains. Only USDC-ALGO in Tinyman and USDC-STBL in AlgoFi are profitable taking all trades into account. Most trading pair are slightly below break-even point (<-0.5 loss) and the rest of them make considerable losses taking all swaps into account. USDT-ALGO in Tinyman lost almost 200 USDT in total.
Conclusions
From the data, it is clear that arbitrage trading is only profitable for a small group of traders which mainly take advantage of the inefficiencies between USDC-ALGO and USDC-STBL in Tinyman and Algofi respectively. The vast majority of trades are not profitable. I guess this can be due to fees eating up the profit or that the arbitrage opportunity window is really small and when the trades are finally executed the price has change and is no longer in profit.
This analysis only considered arbitrage using USDC and USDT in 4 Algorand DEXes.All arbitrage transactions found happen in the same DEX, so it is also logical to think that arbitrage opportunities there are limited compared to other arbitrage strategies involving more complex transactions, like arbitrage between CEX or with more than 2 swaps.
Acknowledgement
Thanks to TheLaughingMan#3062 for the discussion in Discord since I was getting a lot of errors on my SQL code due to my inexperience with LEAD/LAG functions. I have learnt a new way of querying data by ordering tables with subsequent table operations to get the data in the right format. A very powerful method!
Figure 6. shows the top 10 addresses in terms of % profit and total gain by arbitrage pair. Most trades yield a profit between 0.1% and 1.5% but the top address has a profit of over 13%. It looks that this trader is the only one to take full advantage of the inefficiencies in price that all are looking for. Most of the traders end up in loss.