Discover more from Harmony’s Newsletter
Introducing "Swap": A Uniswap v3 Fork on Harmony
Expanding DeFi Opportunities for Users
Swap, a Uniswap v3 fork, is now live and powered by Protofire, a key developer to the Harmony ecosystem. This project is a progression of decentralized finance (DeFi) on the Harmony network by combining a seamless user experience with an automated market protocol.
Swap leverages Uniswap v3’s technology in the Harmony ecosystem enabling users to benefit from concentrated liquidity and capital efficiency, while harnessing low fees and fast transactions.
Protofire will provide ongoing developer support, reinforcing their track record of strong collaboration with the Harmony blockchain with projects such as the Multisig Wallet.
Exploring Uniswap's Tech Aspects
Uniswap, a global powerhouse among decentralized exchanges (DEXs), offers users a fast and secure protocol not only to generate revenue by participating in liquidity pools but also to effortlessly swap their tokens. Unlike centralized exchanges, Uniswap relies on liquidity pools to fulfill orders, instead of depending on institutional market makers. Liquidity providers supply liquidity to the exchange by adding pairs of tokens, and anyone can offer their assets as liquidity and earn a percentage of the collected fees.
Uniswap v1 was first deployed on the Ethereum mainnet in November 2018 with around $30,000 in liquidity. Uniswap v2 was released in May 2020, becoming one of the most forked projects in the blockchain space. With over $2.7B in total value locked (TVL) across hundreds of forks, Uniswap v2 proved to be a robust platform for individuals and institutions. In May 2021, Uniswap v3 launched on the Ethereum mainnet, introducing a new and innovative set of features. The Uniswap v3 BUSL license expired on April 1, 2023, triggering a new wave of forks that utilize the potent new protocol. With some modifications detailed in this article, Swap aims to provide a new way for users to use and exchange their tokens.
Before delving into Uniswap v3, let's first examine the evolution of Uniswap through its iterations to better understand the innovations that have led us to this point.
Uniswap v1, which launched on Ethereum in 2018, introduced the Automated Market Maker (AMM) model. In this model, Liquidity Providers (LPs) invest in trading pairs in Liquidity Pools, guided by a mathematical formula. Uniswap v1 used the Constant Product Market Maker formula (x*y=k) to maintain the ratios in liquidity pools. LPs would contribute liquidity in a way that did not change the constant, which meant users had to be mindful of the total amount of funds locked to avoid price slippage. Uniswap v1 supported only ETH/ERC20 pairs, necessitating multiple swaps for tokens not paired with ETH. LPs received LP tokens proportional to their contribution, which they could trade or redeem. Uniswap v1 imposed a 0.30% trading fee, which was distributed to LPs in the form of shares from the liquidity reserve.
Uniswap v2 introduced ERC20/ERC20 trading pairs, utilizing wrapped ETH (WETH) to facilitate this. Previously, to trade from USDT to SHIB, one might have needed a USDT/ETH transaction followed by an ETH/SHIB transaction. With the innovative possibility of adding any ERC20/ERC20 pairing, such as USDT/SHIB, the popularity of Uniswap v2 quickly skyrocketed, making it one of the most popular DEXs in the world.
Uniswap v2 also introduced flash swaps as the integral feature powering all swaps. In this feature, contracts are able to send tokens out before ensuring that the correct amount of tokens have been put in. The atomicity of the Ethereum network guarantees that the entire transaction can be reverted if the contract does not receive the expected number of tokens.
Uniswap v3 introduced many new innovations for liquidity providers. A core feature of Uniswap v3 is concentrated liquidity, which deviates from the previous approach of evenly distributing liquidity across an infinite price range. Instead, liquidity can be strategically allocated within specific price ranges to enhance its utilization. This shift aims to optimize the efficiency of liquidity deployment and mitigate the issue of significant portions of liquidity remaining unused across various pools. Liquidity providers can now concentrate their capital within whatever range they predict will maximize their profits.
In a traditional centralized exchange, buying and selling are usually facilitated by institutional market makers who provide the buy and sell prices for the tradable assets they hold. Instead of relying on these market makers, Uniswap utilizes liquidity pools to fulfill orders. This approach carries several advantages that mirror the general benefits of decentralization, including continuous availability, automation, a low barrier to entry, transparency, trustlessness, and more. Anyone can become a liquidity provider by allowing their assets to be used in liquidity pools. Liquidity providers contribute pairs of tokens to a smart contract (e.g., a 1ETH/ONE pair), and instead of the liquidity provider determining the buy/sell prices, these are determined according to the Constant-Product Rule: 𝜑=R₁*R₂
where R₁ and R₂ represent the reserver balances for the pair, and 𝜑 must remain unchanged.
Core Contracts and Deployer
The core smart contracts dictate the liquidity pools, the swap mechanisms, and more. These are conveniently deployable via a deploy script created by Uniswap. Some modifications were made to accommodate ONE as the base pair rather than ETH.
Uniswap has also provided an interface under the GPL license that is utilized on the main Uniswap website. Connections to the Harmony network were added and resources point to Harmony specific documentation.
Uniswap relies on multiple subgraphs to index and organize the data from contracts. Swap subgraphs are deployed as The Graph hosted services. The Graph natively supports subgraphs for the Harmony network. The subgraph for Swap is viewable here.
Uniswap developed a smart order router to calculate the most efficient route to execute a swap. Often, executing a swap against a single pool may not be the most cost optimal option for the swap. As each pool can set their own price bands, fees, and available liquidity, a user executing a swap may find it most price optimal to spread their transaction across multiple pools.
Uniswap Universal Router allows partial trades, split trades, and more as detailed in their README.