The ICON Defi Guide: Part 4 — Automated Market Makers: Unifi and ICONPOOL
If you’re reading this, it’s likely you’ve used a cryptocurrency exchange such as Binance or Coinbase before.
Those two and others like them are centralized exchanges. You sign up for an account with them and can connect your bank account. You deposit an asset (either crypto or fiat) into the exchange, place an order on an orderbook to buy an asset, and then can withdraw the asset you just bought.
Of course, throughout this process, you’ve sent the exchange some cryptocurrency, meaning they are the ones who are holding it. That means it can either be hacked and your asset can be stolen, or it means the exchange can decide not to give you your asset, for whatever reason they (or their government) wish.
These are obviously not ideal scenarios. The first major exchange hack was on Mt. Gox, which had 850,000 bitcoins belonging to customers stolen by hackers in 2014.
Since then, there have been a number of smaller hacks of exchanges or other issues that show centralized exchanges may not be the best custodians of your funds.
Enter the Automated Market Maker
If you’re reading this, it’s also likely that you’ve heard of Uniswap, which was the first major “automated market maker” to exist.
To understand what an automated market maker (AMM) is, let’s first start by describing how a traditional exchange works.
An exchange like Binance essentially collects a list of individual sell orders and buy orders and lists each one. Each order has a quantity available for sale and a price. Theoretically, someone who wishes to make a trade can look through this list and select which order is most appealing to them, if any. Of course, a buyer will usually select the sell order with the lowest price available, where the seller will select the buy order with the highest price available.
In liquid markets (those with a lot of buyers and sellers), the lowest buy price and highest sell price are typically very close to one another. In addition, a single sale or purchase shouldn’t change the price by a great deal (again, assuming adequate liquidity).
The “market price” of the asset is whatever the price of the most recent order that was executed.
Now, as mentioned, most exchanges that operate like this are centralized. However, it is possible to build and launch a decentralized exchange. Historically, however, the difficulties that often come with utilizing a decentralized exchange interface have led to less use. And less use means less liquidity, meaning it’s not very attractive for buyers and sellers, since the spread between prices is likely significant, and a single purchase can often move the price a great deal.
That ultimately became the problem AMMs were trying to solve: how to provide the liquidity of a centralized exchange while operating in a decentralized manner.
So what how does an AMM operate differently?
Rather than a list of buy and sell orders, an AMM instead is made up of what are called “liquidity pools.”
Instead of trading occurring between buyers and sellers placing individual orders, those who trade on AMMs are instead doing so against these liquidity pools. When you want to trade on an exchange with an ICX/ETH pair, it means you’re seeing a list of all the ETH holders who want to buy/sell ICX or vice versa.
With a liquidity pool, instead of the ICX/ETH pair showing a list of orders, it instead is comprised of two pools: an ICX pool, and an ETH pool. A liquidity pool is created when anyone with those two tokens and access to the internet deposits assets into the pools. But those who provide liquidity must do so equally (based on value, not quantity) across both pairs, meaning they must have some ETH and some ICX.
But then how is the price determined?
AMMs use what is called a “constant product formula,” which may sound confusing, but really isn’t.
The formula is typically expressed as:
x * y = k
(This isn’t important to remember, especially if you hate math.)
The “k” represents the constant balance of assets. Let’s take our ETH/ICX pair as an example. Each time some ETH is purchased, the supply of ETH in the pool goes down a bit, while the supply of ICX goes up a bit (because the ETH was sold for ICX).
As a result of this, the price will adjust, making ETH a bit more expensive and ICX a bit cheaper. When the price deviates away from the market price (as determined by the price on other exchanges), there’s an incentive to buy ICX (since it’s “cheaper”), meaning ICX gets added to the pool and ETH removed, returning the pools back to balance.
Now, there are situations in which large trades can have what’s called “slippage”, meaning the trade itself will cause the price to move enough to where the price of the first token being bought/sold is significantly different than the price of the last token bought/sold.
In other words, let’s say the ICX/ETH pools were relatively small, but I wanted to buy a lot of ICX. Let’s pretend each ICX is worth 1 ETH at the moment (hey, we can dream). If I have a large purchase order, the actual price I may end up paying for all that ICX could end up being 1.02 ETH. This would be a slippage of 2%.
If you’re not making a large trade, or if the pools are large enough, slippage is usually not much of an issue, but it is something to be made aware of. (Traditional exchanges also typically have slippage as well.)
It’s also important to point out that AMMs, just like traditional exchanges, do have modest transaction fees for each trade.
If you’re still unclear about how AMMs work, I encourage you to watch the following explainer video from DeFi Weekly:
Now, you may be wondering, why would I want to provide liquidity? Aren’t I just locking up my tokens for no reason?
That’s where LP (liquidity provider) tokens come in. LP tokens are a generic term for the tokens that a protocol mints to compensate and incentivize individuals to provide liquidity to pools.
Typically speaking, LP tokens provide holders with governance rights in the protocol, as well as a share of the transaction fees generated.
If you’ve ever heard the term “yield farming”, this is one of the ways you can “farm”. Oftentimes, new AMMs would offer LP tokens that were trading at incredibly high values, meaning people would provide liquidity to those pools solely in order to earn those high-value LP tokens. We’ll go more into how this created some problems in a later chapter, but it felt worth pointing out here where this term partly derives from.
If you decide you want to serve as a liquidity provider in order to earn LP tokens on a given platform, it’s important you learn about impermanent loss (also referred to as “divergent loss”), which is one of the risks faced by those who provide liquidity on any AMM.
For an understanble explainer of this concept, I strongly encourage you to watch this Finematics video providing an overview of impermanent loss:
As a helpful guide, here’s how much of an impermanent loss a given price change within a pair relative to if an LP had simply held their tokens (as opposed to depositing them into a pool).
a 1.25x price change results in a 0.6% loss relative to HODL
a 1.50x price change results in a 2.0% loss relative to HODL
a 1.75x price change results in a 3.8% loss relative to HODL
a 2x price change results in a 5.7% loss relative to HODL
a 3x price change results in a 13.4% loss relative to HODL
a 4x price change results in a 20.0% loss relative to HODL
a 5x price change results in a 25.5% loss relative to HODL
This is another reason why LP tokens exist: as a way to compensate liquidity providers for the potential impermanent loss they may face.
For some reading on eliminating impermanent loss, I’d recommend this article from Token Tuesdays.
ICONPOOL is technically the first AMM to be developed on the ICON network. Like most other AMMs, users are able to provide liquidity and, in exchange, receive an LP token, giving them a share of the 0.3% transaction fee (on each transaction) that ICONPOOL charges.
To get better aquainted with how to use ICONPOOL, I recommend this tutorial by P-Rep ICONPLUS:
uTrade (Unifi Protocol)
The other AMM currently operating on ICON is called uTrade, and is powered by the Unifi Protocol. On the surface, it operates like a typical AMM.
However, there are a couple features that make uTrade a bit different.
First and foremost, while there is a uTrade operating on ICON, uTrade also operates on several other blockchains such as Tron, Harmony, Ontology, and others.
In addition, Unifi (and uTrade) was spearheaded by Sesameseed, a separate project that has developed a token called SEED, which also exists on the same blockchains as Unifi.
For a helpful video explaining what SEED is, watch this one put together by Harmony:
Sesameseed serves as a node operator on all these chains, including ICON. The rewards they collect go into a giant pool, and anyone who owns SEED can redeem it for a pro-rated portion of that pool.
Because SEED exists on multiple chains, Sesameseed has developed a mechanism to easily swap SEED from one chain to another with just the click of a button.
What this means is that it’s possible to trade ICX for SEED on ICON, swap your SEED for the SEED that’s on the Tron network, for example, and then buy Tron. Since the value of SEED is the same on all the blockchains it operates on, uTrade, via Unifi, generates an easy mechanism to trade ICX for assets on Unifi’s other chains.
However, this is just an added feature. ICONists can still gain a lot of value from utilizing Unifi solely on ICON to trade IRC-2 assets.
The other (somewhat) unique feature of Unifi is it’s LP token, which is called “UP.”
Just like any other AMM, you can receive UP for serving as a liquidity provider. The amount of UP you receive is based on what % of the pool you are providing liquidity for (for instance, if your liquidity is responsible for a large portion of the overall liquidity in that pair, you’ll receive more UP) along with the volume of transactions occurring on that pair.
So the ideal pair to provide liquidity for is one where there may not be a lot of others willing to provide liquidity, but that generates a lot of trades. And if you’re concerned about impermanent loss, then it would be even better to select a pool with minimal price volatility.
So just what do your UP tokens get you?
Over time, as each transaction on uTrade is made, a small ICX fee gets deposited into a fund. Each UP holder has the rights to redeem their UP for a pro-rata share of that fund.
As an added twist, the rate of the amount of UP that gets minted over time decreases. Meaning your UP becomes more valuable not only because it gives you a slice of an ever-growing basket of ICX, but because the number of others eligible to a share of that same basket will grow at a slower and slower rate. So it’s ideal to hold UP for as long as you can.
Here’s a tutorial from ICONPLUS on how to use uTrade:
If you’d like to learn even more about Unifi and uTrade, be sure to read my article ‘Unifi Protocol: A Bridge Between ICON and the DeFi Economy’.
As was the case with platforms such as Omm and Balanced, there is always a smart contract risk when dealing with DeFi, meaning you are technically sending your tokens to a smart contract you don’t control. Thus far, both uTrade and ICONPOOL have operated without any apparent smart contract issues or vulnerabilities, but the risk always exists.
In addition, there is also the risk of impermanent loss, as explained above.
Another risk that has plagued other AMMs like Uniswap is something called a “rug pull,” which is a term you may have heard before. So what’s a rug pull?
Let’s pretend I’m a developer who has just launched a new token. Similar to the ICO scams from 2017, the token itself in this example is fairly useless. Prior to launch, the developer builds a lot of hype for the token on Telegram and other channels.
The developer then provides the vast majority of the initial liquidity for the token on Uniswap. Let’s pretend the token is called SCAM and is trading against ETH. Because the developer created the token, they likely own the vast majority of SCAM.
Let’s pretend they deposit 10 ETH and 1,000 SCAM into the ETH/SCAM liquidity pool. They then announce the token is available for trading, and tout that it can bring a 10x gain.
Buyers — who don’t want to miss the next 10x! — then rush in to trade their ETH for SCAM. This causes the price of SCAM to go up. Wow, it may actually 10x! So more people rush in. At this point, because so many have bought SCAM, the pool might now be 50 ETH and 250 SCAM.
So what happens now? The developer — being the vast-majority liquidity provider, simply withdraws all their liquidity — aka, pulling the rug. Instead of having only 10 ETH, they now have 50. Sure, they have a lot less SCAM, but since the developer knows it was a worthless token, they don’t care about the “impermanent loss” they’ve suffered. They just turned 10 ETH into 50.
Many perceive “rug pulls” as a condemnation of DeFI as a whole. But the key to avoiding a rug pull is to avoid scammy tokens. It’s also probably a good idea to avoid liquidity pools where a single individual (or small group) is responsible for the vast majority of liquidity.
For a helpful video explaining rug pulls, watch below:
With AMMs, we now have a way to trade assets for other assets in a decentralized manner.
Perhaps we want to take the BALN assets we’ve earned on Balanced and help provide liquidity to a BALN/ICX pool on ICONPOOL.
Or perhaps we want to serve as an LP for an ICX/OMM pool on uTrade.
Or maybe we noticed the price of BALN is a bit lower on ICONPOOL as compared to uTrade, so we buy BALN on one and sell on the other. In this case, we’ve made a bit of profit, but also helped the market by ensuring a consistent market price.
One of the most common metaphors for DeFi is “legos”, meaning that each component may look a bit different, but you can usually fit them together in a way that creates something new entirely. Based on the descriptions above, you’re probably starting to see how many possibilities emerge. We’ll go into greater depth in a later chapter about all the ways you can utilize these legos, but first we’ll learn a bit about further maximizing the return you can get on your capital.
If you’d like to ask questions about DeFi, discuss strategies, or just have a general discussion, please join us in the ICON DeFi Discussion group I’ve created on Telegram to supplement this guide and build a vibrant DeFi community around ICON.