This article is derived from a chapter in the free eBook explaining DeFi technologies:
DeFi Demystified | An Introduction To Decentralized Finance
In late 2017 all the tokens were on Ethereum and it made sense that someone would eventually build a decentralised digital asset exchange. The first popular one was called IDEX and it followed the principles of a standard exchange order book and matching engine. In 2018 the game changed, perhaps forever, with the release of Uniswap. Uniswap’s automated market maker grew quickly to become one of the backbones of DeFi.
How Automated Market Makers Work
An automated market maker works differently to an orderbook based exchange. It uses a pair of assets in a pool which are deposited by a liquidity provider. A trader can then trade one asset within the pool for the other paying a fee. The price will fluctuate with demand along a liquidity curve.
For example a liquidity pool might have ETH as the base asset and an ERC20 Token as the traded asset. Price is calculated along a curve dependent on the quantity of assets in the pool. If someone starts buying the ERC20 token with ETH it pushes the price up as more ETH is added and the ERC20 tokens are removed from the pool.
Liquidity provider (LP) tokens act like a receipt for the funds deposited and they will automatically be sent to the same address that deposited the funds. LP tokens can be transferred and can often be staked on DeFi platforms in return for staking rewards.
2nd November 2018
Every now and again someone comes along that just simplifies things down to their fundamentals. This is what Haden Adams did when he launched the Uniswap platform. Rather than rely on a clunky order book Hayden had devised a swapping protocol where investors would send equal values of assets to a smart contract. The assets were put into a liquidity pool where users could then trade between them paying a fee to the liquidity provider.
If someone swapped some ETH for a new token then the price would go up along a predefined curve. If they sold some of the token back to ETH the price would drop back down again to balance the pool.
It was ingenious in its simplicity and enabled investors in ETH and ERC20 tokens to gain a yield on their holdings.
It wasn’t all roses though as Uniswap liquidity providers flirted with the risk of impermanent loss. This was the effect of one asset increasing in value beyond the other which would mean the liquidity providers would be left with more of the lower value asset in the pool. Impermanent loss was very much a permanent problem if the asset never returned to it’s previous valuation. When a liquidity provider deposits funds to an automated market maker they receive fees in exchange for accepting the risk of impermanent loss.
In theory there’s no reason for the price in a liquidity pool to follow the price on a centralized exchange however in practice any differences are quickly arbitraged away. In crypto markets arbitrage is big business. Networks of bots will scour centralized and decentralized exchanges looking for mispricings between assets. Arbitrage can be as simple as buying an asset on one exchange and hedging the position by selling on another or it can be more complex such as when triangular arbitrage exposes three way price discrepancies.
Arbitrage bots play a important role for automated market makers to keep their prices in line with centralized exchanges.
The Sushi Saga
5th September 2020
Uniswap liquidity providers send their tokens to a smart contract and in return get LP tokens as a kind of receipt and IOU for the liquidity position.
A developer going by the pseudonym Chef Nomi had forked Uniswap’s open source code and created a copycat version of it called Sushiswap. Sushi tokens were distributed to users who staked Uniswap LP tokens on the platform. Chef Nomi used the LP tokens in a vampire attack to drain liquidity from Uniswap and put it on Sushiswap.
The plan worked and Sushiswap grew in what became known as the first billion dollar heist. At one point it held more liquidity in terms of TVL than Uniswap.
Smart contracts can contain funds locked within the contract itself. The smart contract address owns the funds until a user redeems them. The TVL or total value locked within a smart contract or protocol is often expressed in USD terms.
Chef Nomi wasn’t satisfied with his success and in a moment of madness dumped the entire development fund of SUSHI tokens on the open market through centralised exchanges such as Binance and FTX. The token value instantly dropped 70% and claims of carrying out what would later be referred to as a rug pull “for the good of the community” were met with disdain from the community.
The following day, perhaps after sobering up and a few death threats, Chef Nomi transferred funds and ownership control to the CEO of FTX Sam Bankman-Fried who set up multisignature wallets for the funds.
Multisignature wallets enable multiple entities to safely control access to funds. A multisig is another form of smart contract that states how many signatures are required to distribute funds and which accounts have signatory rights.
Sushiswap recovered and while it still played No.2 to Uniswap on May 19th 2021 it had a record day with trading volumes nearly hitting three billion US dollars.
Today the vast majority of decentralized trading now takes place on automated market makers like Uniswap and Sushiswap.
DEX Aggregators
With multiple decentralized exchanges to choose from, how can a user be sure they are getting the best price for their token swap on any one single exchange? This is where decentralized exchange aggregators such as 1inch exchange come in.
A user will connect to a DEX aggregator and put in the details of the transaction they want to carry out. The aggregator will then scan all available markets and more complex triangular transaction routes to calculate the optimal strategy for carrying out the swap. This can on occasion provide a better price for the trade.
Soon to be released 1inch V2 looks set to bring back limit order technology to bring us full circle to where IDEX first began.
This article is derived from a chapter in the free eBook explaining DeFi technologies:
DeFi Demystified | An Introduction To Decentralized Finance