Uniswap: Decentralized liquidity

Moresh Kokane
Konkrete
Published in
8 min readDec 9, 2019

This article is written primarily for the benefit of the internal team at Konkrete. It is second in a series of explanatory articles, the first one explaining Compound can be found at

Elements sourced from both Uniswap and Compound’s architecture can be leveraged to build a more open and censorship resistant money market which can support any asset as collateral. We will expound on that thought in a future article.

But first a word on Asset characteristics.

At a very high level all assets have 3 key characteristics:

  1. Liquidity: which defines how easy is it to exchange with someone else in favor of cash or other assets. This is a function of how widespread the perception of their value is as well as the continuous availability of a large number of counterparties willing to accept that asset in exchange of other on demand.
  2. Risk: this is a measure of how quick the fundamental value inherent in the asset can deteriorate. While liquidity of an asset can improve (due to greater demand etc), risk is a fundamental property of an asset and it does not change due to different wrapping structures.
  3. Return, this is again a fundamental property. By return we mean long term averaged return and not a short term intraday movement.

These 3 attributes are often in conflict.

Cash has the highest liquidity, zero risk (unless you are in an erratic government led country like India which cancels bulk of the cash overnight or some high inflation country). However cash offers no increase in its value. A $100 note is still worth $100 if you hide it under a mattress for a year. It would not magically increase to $110.

Stocks have high liquidity, high return but come with high risk.

Real estate has low liquidity, strong returns and low risk.

Note that of the 3 properties, liquidity is the only property that can be improved. Liquidity as described earlier is a function of how widely the value of a particular asset is perceived and the ability of those people who perceive the value to execute on it.

Real estate is widely viewed to be valuable and safe. However the reason why it is not as liquid as cash or stocks because the amount required to transact it is quite high.

Another example is a term deposit or some sort of an investment which matures after a certain period of time. For eg: A real estate development project makes money only on completion of a process which can often stretch out for years. Investors coming in at the start can get a meaningful exit only after the construction is complete. In the interim that investment is not making any money.

However real estate development delivers high quality returns in a predictable fashion. The lumpiness in the quantum of money required to get started as well as when the returns come back makes it an investment that is not typically accessible to everyday folks.

Point being there are several investments which are safe and deliver high returns, but they are typically illiquid.

The question becomes how can we make them liquid?

The simple answer is to fractionalize them and then list them on some sort of a securities exchange and try and make a market in them.

This while plausible is quite cost and effort intensive and not always feasible.

A simpler solution would be to start with a large bag of cash which sits in reserve and when anyone who has invested in the asset wants to redeem it can access this liquidity pool.

Question becomes where can you get this large bag of cash which sits there in reserve.

One answer would be to work with a high networth investor who

a. Has the bag of cash and

b. Believes in the value of the asset for which he/she is offering liquidity.

For instance someone providing liquidity to a real estate development project needs to believe in the value of the asset. That way even if everyone took him up on the offer of exchanging cash for shares of the project, he should still be comfortable as holding the investment in the project will make him a high return.

For a liquidity provider it is just moving his investment from one asset to another, both of whom he is quite comfortable holding.

However such an investor would not be willing to provide this service for free. A way to compensate him for this provision of liquidity would be to pay a % fee everyone someone taps the liquidity. Any time someone wants to exchange their assets for cash, a % is paid to the liquidity provider.

However such big bags of money are hard to find and convince.

What if there was a way for many smaller investors to come together and provide this liquidity together?

Instead of sourcing and convincing one large investor to provide the liquidity, it would be much easier to get the same results if it was possible for many smaller ones to come together and create the liquidity pool. And any time someone taps into this liquidity pool, a fee is paid which is distributed prorated to all those who contributed to that pool.

This is exactly what Uniswap and Bancor do.

It is now possible to create liquid markets in all varieties of exotic assets by allowing liquidity providers to come together.

Note that there is no peer to peer exchange of assets. The function is more akin to balancing scales where assets are moved from one side to another.

The exchange rates between both of the sides become a function of the supply and demand.

While there are markets on Uniswap are for assets that already have liquidity on a wide variety of centralized and decentralized exchanges, the real promise of Uniswap is to enable liquidity in illiquid assets in a censorship resistant manner. As long as someone believes in the value of an asset, he can choose to become a liquidity provider for it and make money doing that via fees.

When someone chooses to become a liquidity provider on Uniswap they have to offer up equal amounts of the asset in question and ETH. ETH serves as a base medium on Uniswap. So instead of having an exchange market pair between every single asset (which would lead to a crazy number of combinations), each asset can be translated to ETH first and then from ETH it can be translated to the other asset.

Let's consider an example, and this is straight from the Uniswap whitepaper which can be found here

10 ETH and 500 OMG (ERC20) are deposited into a smart contract by liquidity providers. An invariant (constant) is automatically set such that ETH_pool * OMG_pool = invariant.

ETH_pool = 10

OMG_pool = 500

invariant = 10 * 500 = 5000

An OMG buyer sends 1 ETH to the contract. A 0.25% fee (this has since changed to .3%) is taken out for the liquidity providers, and the remaining 0.9975 ETH is added to ETH_pool. Next, the invariant is divided by the new amount of ETH in the liquidity pool to determine the new size of OMG_pool. The remaining OMG is sent to the buyer.

Buyer sends: 1 ETH

Fee = 1 ETH / 500 = 0.0025 ETH

ETH_pool = 10 + 1–0.0025 = 10.9975

OMG_pool = 5000/10.9975 = 454.65

Buyer receives: 500–454.65 = 45.35 OMG

The fee is now added back into the liquidity pool, which acts as a payout to liquidity providers that is collected when liquidity is removed from the market. Since the fee is added after price calculation, the invariant increases slightly with every trade, making the system profitable for liquidity providers. In fact, what the invariant really represents is ETH_pool * OMG_pool at the end of the previous trade.

ETH_pool = 10.9975 + 0.0025 = 11

OMG_pool = 454.65

new invariant = 11 * 454.65 = 5,001.15

In this case the buyer received a rate of 45.35 OMG/ETH. However the price has shifted. If another buyer makes a trade in the same direction, they will get a slightly worse rate of OMG/ETH. However, if a buyer makes a trade in the opposite direction they will get a slightly better ETH/OMG rate.

1 ETH in
44.5 OMG out
Rate = 45.35 OMG/ETH

Purchases that are large relative to the total size of the liquidity pools will cause price slippage (change of price before you actually execute the trade). In an active market, arbitrage will ensure that the price will not shift too far from that of other exchanges. If the price on Uniswap is different than what you would get on some other market, there is an opportunity to make a profit and someone will end up doing it and bring the rates back in balance with the wider market.

When someone contributes to a liquidity pool, they get a token back representing their share of the pool. These are colloquially called pool tokens and they are unique for each pair. So for an ETH DAI pair there will be one pool token and an ETH OMG pair there will be another token and so on. Each representing the token holders share of the pool.

When someone uses the liquidity pool they have to pay a fee which goes back into the pool and is technically a property of all the pool token holders who contributed to providing this liquidity. As the pool keeps growing due to the fees that it accumulates so does the value of the pool tokens that represent ownership of the pool.

When someone decides to withdraw from the liquidity pool, they give back their pool tokens and get back their share of the pool. Note that because of the varying redemption requests, the pool may have shifted in favour of one side or another making the ratios of the constituents different than from when the liquidity provider contributed to the pool.

For eg a liquidity provider may have stumped up 1 ETH and 100 DAI and by the time he withdraws the pool reflects a ratio of .9 ETH and 110 DAI which is what he gets back. The overall value he gets to withdraw is the same, except the ratio in which it is distributed across the asset pair may end up varying. As long as the liquidity provider is comfortable with it he can essentially rent his asset pairs and make some money doing it.

Decentralized liquidity pools have been available with Bancor and others using similar mechanics. Uniswap is unique as it takes a censorship resistant approach to this and does not prevent anyone from creating their own markets and liquidity pools as long as the technical interfaces are met.

--

--