Starting with the basics. The typical DEX offers tokens at prices depending on what its pool holds. Usually, it doesn’t get price information from the outside. Arbitrage bots trade with it all day and that syncs the price with other markets. If the price in market A is higher, the bot takes tokens from market B and sells them to A making a profit.
If in a DEX pool BTC/ETH (50/50) the BTC price moves up slowly, the pool will sell its BTC and end up having mostly ETH, but at that point, the BTC it sold will be more valuable, so it will hold the less valuable token and liquidity providers will have impermanent loss. When the BTC price goes back down to the same spot, there will be no impermanent loss and the pool will have collected fees from all the trades.
In green, we show the amount of trades that happened in the pool. For each liquidity provider takes 0.024% (lp pool fee)
How much fees the pool makes depends a lot on how much arbitrage bots wait and how much they want to profit. In the example above, they wait for 2% price difference (after fees get applied). 4 swaps resulted in 8% profit for the bot and 0.96% for the pool.
If the arbitrage bot decided to charge less and traded for 0.1% profit, it would make a lot more transactions and get a lot less profit, while liquidity providers get the 8% profit in fees.
If the pool price doesn’t go too far away from other market prices and the bots wait for too much profit, this results in no trades at all.
The same price movement with a bot that works for less profit has resulted in a lot of fees for liquidity providers.
We started with BTC/ETH so I can illustrate another point. Both tokens in this pair have large markets and the DEX pool plays no significant role in their prices.
If you put token ABC in a pool ABC/ICP the price of ICP won’t be significantly affected by the pool too, but the price of ABC will. If this is the only market for it, the price depends on it 100%.
If there is only one market, there are no arbitrage opportunities and bots. However, a lot of coins get traded in multiple DEXes.
If ABC/ICP is on 3 dexes, equal TVL on all and someone trades on one with 3% price impact. This means the arbitrage bots will pick tokens from the other markets at lower prices for 0.3% fee and sell it higher, again being charged 0.3% fee.
Initially, the disbalance will look like this.
Once arbitrage is complete, ⅓ of the price difference will go to each of the other pools.
For a 3.43% price impact in this setup, the arbitrage bot takes 4.7 times more than liquidity providers.
Because the ABC/ICP DEX pools are the only markets they form the new ABC price. From what we have found, arbitrage bots on the ICP cash out their fees from the most liquid coin they can find, in this case, the ICP. This means they won’t be keeping any ABC and the ABC price will go down a bit every time arbitrage bots find an opportunity.
If there are 500 buys and 500 sells all for equal amounts with a high enough price impact, the price won’t stay the same, it will go down substantially. (If we only had one pool, it would stay the same)
If we keep going with equal buying and selling, the pools will eventually get near zero ICP in them and the price of ABC will be near zero as well.
In this case both traders swapping with high price impact and liquidity providers not concentrating the liquidity well enough while adding more markets results in a slow fall.
The negative effects get even bigger when the pools are with different tokens ABC/ICP and ABC/USD
Then you don’t even need human traders for this setup to go to zero, in the current system, the movement in ICP/USD will unbalance the prices when volatile, resulting in a lot of arbitrage. It will only work if one of the pools has a lot less value and doesn’t produce too many bad arbitrage opportunities.
Frontrunning is another problem that plagues DeFi. IC’s architecture is perfectly fine and shouldn’t result in any frontrunning with sandwich attacks, but a badly made DEX API causes it. Essentially it’s announcing publicly that someone will trade 6sec before they trade. This was promised to be fixed. In our estimations, it’s around ⅕ of the total bot profits.
How EVM based blockchains deal with these problems? Their network tokens are tickets to become validators and get profits from these rewards, calling them MEV (Miner Extracted Value) How much the network gets as fees and how much validators get from the MEV, probably is different on every chain, but this explains why there are so many of these blockchains.
If a block takes 15 seconds, this means the validator and their bots are probably going to get the maximum possible fees from their DEX pools. This isn’t exactly solving the problem and by far it looks like these contracts and a combination of them aren’t working well at all anywhere. They are leaking their liquidity into the network token. On ICP they aren’t.
How do we fix things:
If a price moves slowly, then it’s relatively easy for someone to make a good arbitrage bot that works with near-zero profit, converting all opportunities into lp fees. If there is a spike, however, the first bot that reacts can get the whole reward. Prices will usually spike from traders if there isn’t a lot of concentrated liquidity. But concentrated liquidity isn’t too good when you have pools with two different tokens, this will result in a lot of arbitrage.
We’ve made a new ICPCoins experimental stat named ‘Botfood’ and it attempts to record how many bad arbitrage opportunities are occurring. If pools produce too much arb profit, that profit gets added to the stat.
Changes in volatility, TVL, adding/removing pools, and concentrating liquidity will result in changes in Botfood. The less it is, the better.
It’s also possible to change the DEX algorithms slightly, so they reward LPs more.
If we reduce arbitrage bot profit % and increase frequency, the pools will work a lot better, and their fees could increase 3 times. That will get more providers. Users will be happier if they swap without too much price impact.
In our tests and experiments, we came to a ratio. The few arb bots profit ½ of what LPs make without risking almost anything. LPs provide 11 million $ in liquidity, taking risks. Arb bots have balances of around 500$ and their profit is guaranteed no matter if the price goes up or down.
The quicker solution imo, is for the ecosystem to get more bots that arbitrage quickly taking almost no fees. For handling spikes the solution could probably be solved inside the dex algorithms in combination with concentrated liquidity position management.
To make sure our numbers and analysis are correct and not imaginary and also to protect our pools, we made an arb bot. It works near zero profit. It was 80% written by AI as a quick side project. Done in a slapdash manner it ran for a week and generated 1417,5$ pool fees (Around a hundred $ for each dex and the rest for LPs) for ~25pools, profited overall ~30$, burned some cycles, and burned ~200$ in ledger fees. Helped us verify our Botfood stats. It only works with 10 coins out of thousands and only 2 dexes. Watching the other bots, I could say it’s doing 1/20 at most of the arbitrage right now. The other bots set to profit too much would have probably generated 100$ fees for these opportunities and taken the rest as profit.
We have been trying to get some standards for the DEXes, but it’s hard to do solo. None of the DEXes seem interested in standards so far.
DeFi standards for the IC will enable the creation of smart contracts using these dexes. Right now with their APIs it’s not possible to do almost anything interesting on-chain. That was our original goal. Now it turns out these standards would have also helped in making tools and diagnosing DeFi inefficiencies faster and fixing them as well. Additionally, they will allow more arb bots to make these contracts work better. AI trading bots operated by humans will need them as well.
Our goal with the upcoming ICPCoins v2 release is to address these issues and help the ecosystem become more efficient by providing useful information and tools.