Exploring Automated Market Makers on Rootstock: What You Need to Know

The Evolution of Decentralized Exchanges (DEXs)

What are DEXs

Decentralized exchanges, or DEXs, are marketplaces where users can trade assets directly with each other in a trustless, peer-to-peer manner without the need for a third party or intermediary to manage the transfer or custody of assets. In this system, users maintain full control over their funds while smart contracts facilitate the transfer and exchange of assets. Before DEXs, centralized exchanges (CEXs) were the norm. In CEXs, a central authority or intermediary conducts Know Your Customer (KYC) checks, holds custody of funds, and manages the transfer and exchange processes.

DEXs vs CEXs

With self-custody available on decentralized exchanges (DEXs), users can trade directly from their crypto wallets without needing to open an account with a central authority that holds their funds and facilitates exchanges. This allows users to trade anonymously without sharing personal information, and they do not have to pay the platform trading fees typically associated with centralized exchanges (CEXs).

In essence, DEXs offer enhanced privacy, security, and transparency compared to CEXs. In centralized exchanges, a central authority controls the private keys, which means that if the platform is compromised, users’ funds are at risk. Additionally, CEXs are subject to mandatory Know Your Customer (KYC) processes and other regulatory requirements, which can lead to limited access to funds, restrictions on trading activities, or even the potential shutdown of the platform.

The following table further illustrates the advantages of DEXs over CEXs:

Feature

DEX (Decentralized Exchange)

CEX (Centralized Exchange)

Control

You own your keys, you own your crypto. No middlemen.

The exchange holds your funds. If they shut down, so does your access.

Security

No single point of failure. No massive exchange hacks.

Prime targets for hackers. Billions lost in exchange breaches.

Privacy

Trade freely, no KYC, no surveillance.

Mandatory KYC, tracking, and government oversight.

Liquidity

Growing fast with innovative solutions like liquidity pools.

Deep order books, but at the cost of centralization.

Speed

Slightly slower due to blockchain confirmations but improving with L2 solutions.

Faster trades but relies on trust in a centralized system.

Fees

No hidden fees. You only pay for the network.

Exchange fees, withdrawal fees, and sometimes even deposit fees.

Ease of Use

Slight learning curve, but once set up, you’re in full control.

Simple to use, but at the cost of giving up control.

Regulation

Free from heavy-handed regulation. Truly global and permissionless.

Strict regulations, account freezes, and compliance burdens.

Asset Variety

Access to thousands of tokens, including new and innovative projects.

Limited listings, often favoring large-cap assets.

Censorship Resistance

No one can freeze your funds or stop your trades.

Governments, banks, and regulators can cut off access at any time.

DEX Models

Initially, decentralized exchanges (DEXs) tried to use a familiar order book model from traditional finance and centralized exchanges, which promised scalability and flexibility. An order book is a real-time record of open buy and sell orders in a market, where exchanges continuously update and match available orders for trading. However, DEXs faced challenges in implementing this model through blockchain smart contracts, which ultimately led to their struggles. The design of blockchain architecture did not support the way order books execute trades, as every buy and sell order had to be processed directly on-chain by smart contracts. This resulted in very high gas fees and slow transaction times, which could take hours or even days to complete. Furthermore, the lack of adequate liquidity during those early days meant that trade execution was often inefficient whenever there was a mismatch between buyers and sellers.

The main reason order book-based decentralized exchanges (DEXes) have struggled on smart contract blockchains like Ethereum and Binance Smart Chain (BSC) is due to fundamental technical limitations. Traditional exchanges depend on high-speed order execution, real-time updates, and low-latency matching, which require rapid transaction processing—something blockchain networks are not optimized for. Every action, from placing to canceling an order, must be recorded on-chain, which means users incur gas fees for each update, making frequent trading expensive. Additionally, limited block space can lead to congestion, hindering fast execution and resulting in frustrating delays. Early DEXs like EtherDelta tried to address these issues, but users had to manually place orders without centralized market makers to provide deep liquidity. This led to fragmented order books and unpredictable prices, resulting in high slippage and poor price discovery. The overall trading experience became slow, complex, and costly.

Recognizing the inefficiencies in the order book system, DEXs transitioned to Automated Market Makers (AMMs), which replaced order books with liquidity pools. The introduction of Uniswap in 2018 marked a significant shift, allowing users to trade directly against liquidity pools rather than wait for manual matching between buyers and sellers. This innovation enables users to swap assets within a liquidity pool without needing an order book. Platforms such as Uniswap and PancakeSwap eliminated the requirement for constant order updates by facilitating trades against a pool of assets rather than matching with another trader in real-time. This approach effectively addressed liquidity challenges and made transactions smoother, faster, and cheaper. The failure of early order book-based decentralized exchanges (DEXes) was not due to a lack of demand; instead, it stemmed from the fact that blockchain architecture, in its current form, is not designed to support the high-frequency trading seen in centralized markets.

The following table illustrates the distinctions between AMM and Order Book DEXes

Feature

Order Book DEXes

Automated Market Makers (AMMs)

Trading Mechanism

Matches buyers and sellers through an order book

Uses liquidity pools to facilitate trades

Speed & Efficiency

Slow, as each order update requires an on-chain transaction

Fast, as trades execute instantly against a pool

Gas Fees

High, since every order placement, update, or cancellation incurs a fee

Lower, as trades happen in a single transaction

Liquidity

Dependent on active traders and market makers

Provided by liquidity providers who earn fees for staking assets

Slippage

Low in deep markets but high in low-liquidity scenarios

Varies based on pool size; can be high in volatile markets

User Experience

Complex, requiring manual order placements and constant monitoring

Simple, allowing instant swaps with a fixed formula (e.g., Uniswap’s x * y = k)

Best Suited For

High-frequency traders, professional market makers

Retail traders, DeFi users, passive liquidity providers

Challenges

High gas costs, slow execution, and fragmented liquidity

Impermanent loss for liquidity providers, potential front-running

Examples

EtherDelta, Serum

Uniswap, PancakeSwap, Curve

The Significance of AMMs in Rootstock’s DeFi Landscape

AMMs can enhance decentralized trading and liquidity within the Rootstock (RSK) ecosystem. RSK is a Bitcoin sidechain that improves Bitcoin’s decentralized finance (DeFi) offerings by enabling Ethereum-compatible smart contracts while benefiting from Bitcoin’s security. Since Bitcoin does not natively support smart contracts, RSK expands its capabilities by integrating them. AMMs present a viable alternative to traditional order books, overcoming the scalability and liquidity challenges faced by early Ethereum DEXs. They create liquidity pools that facilitate smooth token swaps without requiring direct interactions between buyers and sellers.

By implementing AMMs on Rootstock, Bitcoin evolves from solely being a store of value to functioning as a transactional asset. Consequently, assets pegged to BTC can be utilized in yield farming and staking, showcasing some of the dynamic use cases in DeFi and blockchain technology.

Core Principles of AMMs: How They Work Under the Hood

Key Components of a DEX

Liquidity Pools: AMMs trade against a liquidity pool containing a diverse range of tokens, eliminating the need to match individual buyers and sellers. They also incentivize LPs, which enhances the decentralization of trading. This makes the trading process more convenient, easier, and faster.

Token Swaps: Token swaps involve the exchange of cryptocurrency through liquidity pools, where users deposit tokens to facilitate trading.

Fee Mechanics: DEXs usually charge transaction fees to incentivize liquidity providers and support the maintenance of the platforms. The liquidity provider fees are applied to each trade and are distributed among the liquidity providers. Additionally, protocol fees may be charged for governance and platform development. Gas fees are also incurred for the blockchain networks on which the DEX platforms operate.

Price Determination: Different mechanisms determine asset prices, and they are mostly calculated by certain mathematical formulas or pricing models of external oracles.

AMM Mechanism

We will look at the different AMM mechanisms and how they work, for instance, how some use mathematical formulas, such as the constant product formula (x * y = k), to determine asset prices.​

Constant Product Market Maker (CPMM): When a user exchanges one token for another, the product of the two token reserves must remain constant (x * y = k). It’s important to note that in the CPMM model, larger trades tend to incur worse rates due to slippage compared to smaller trades. This model is straightforward and efficient, and it is used by exchanges such as Uniswap v2.2.

Constant Mean Market Maker (CMMM): This is a generalized Constant Product Market Maker (CPMM) that supports multiple assets. Instead of relying on a constant product of token swaps like traditional CPMMs, it maintains a constant weighted geometric mean of asset reserves. This approach provides greater flexibility for portfolios and enables more efficient multi-asset trading. An example of this is found in Balancer, where liquidity providers can create pools with different weightings, such as 80% ETH and 20% DAI, rather than the standard 50/50 distribution.

Constant Sum Market Maker (CSMM): Whenever a user swaps one token for another, the total amount of the two token reserves must remain constant (x + y = k). Each trade occurs at a fixed price, which means there is no slippage. While this model is not practical for most real-world trading scenarios, it can be beneficial in specific cases, such as stablecoin pools where the assets are pegged to a stable value.

Constant Function Market Maker (CFMM): A theoretical framework consisting of a broad category of market makers, including CPMM, CMMM, CSMM, and others. It offers more sophistication in functionality but also introduces greater complexity.

Dynamic Automated Market Maker (DAMM): This model utilizes market conditions to dynamically adjust liquidity pool parameters. It can modify fees and ratios of token pool reserves based on volatility and volume. This approach is used in exchange models like DODO’s proactive market maker model.

Virtual Automated Market Maker: In VAMM, prices are determined through a virtual equation, eliminating the need for real liquidity pools. Transactions happen via profit and loss settlements instead of swapping actual assets. This approach is utilized by platforms like Perpetual Protocol.

Challenges in AMMs

Impermanent Loss: A decrease in the value of a token can occur for a liquidity provider (LP) during periods of high market volatility. This situation arises when the value you would have received from simply holding an asset is lower than the compensation you receive for allocating that token to a liquidity pool. To mitigate these losses, decentralized exchanges (DEXs) incentivize LPs with the trading fees collected on their platforms.

Slippage: The difference between the expected and actual execution price of a trade occurs due to changes in market conditions between the time the order is placed and when it is executed. This difference can be influenced by factors such as trade size and liquidity. To manage this risk, several decentralized exchanges (DEXs) implement a slippage tolerance parameter for trades against their liquidity pools. This parameter sets boundaries for the acceptable execution price of a trade, typically expressed as a percentage of the expected token price.

AMMs in the Context of Rootstock (RSK)

RSK Infrastructure

RSK, a Bitcoin sidechain, supports Automated Market Makers (AMMs) and enables seamless asset transfers between Bitcoin (BTC) and smart Bitcoin (RBTC) without incurring extra issuance costs. This mechanism ensures a direct peg and value correlation between the two tokens. Additionally, RSK utilizes proof-of-work consensus and merge-mining with Bitcoin, enhancing security and providing instant payment confirmations—an advantage over the Bitcoin network.

RSK Compatibility

RSK is compatible with the Ethereum Virtual Machine (EVM), which allows for seamless integration with Ethereum decentralized applications (dApps) and smart contracts. This compatibility makes it possible to transfer Ethereum-based AMMs to the RSK network, thereby extending their reach. Moreover, RSK can facilitate the transfer of BTC between the Bitcoin network and Ethereum-compatible blockchains. This feature helps leverage the liquidity provided by the Bitcoin base layer, enhances interoperability, and promotes the growth of the DeFi ecosystem.

RSK Token Standards

RSk has token bridges that allow you to transfer ERC-20 tokens to the RSK network and back. ERC-20 tokens are fungible tokens that can be exchanged on the Ethereum network. The native token on the RSK network is rBTC, which is pegged at a 1:1 ratio with Bitcoin. Additionally, there is a wrapped token called WRBTC, which is an ERC-20 token that represents rBTC. This allows WRBTC to participate in DeFi activities on various platforms and blockchains, enabling you to trade rBTC for other ERC-20 tokens.

Existing AMMs within the Rootstock Ecosystem

Some notable AMM Implementations on Rootstock include the following:

SushiSwap: SushiSwap is a leading decentralized exchange (DEX) that operates across multiple blockchains, including Rootstock. It allows traders and liquidity providers to participate in decentralized trading on more than 15 different chains. For more information on how to use SushiSwap on Rootstock, you can refer to the official RSK tutorial blog post, Rootstock x SushiSwap: Guide to Bridge, Swap, and LP Rootstock on Sushi.

Sovryn: A Bitcoin-native DeFi platform initially built on Rootstock, offering AMM-based trading, lending, and borrowing services. Users can trade, swap, stake, and provide liquidity. You can read more about the Sovryn implementation from the official ​Sovryn blog.

Security Considerations in Rootstock AMMs

Preventing front-running (MEV issues): Front-running occurs when validators or MEV bots insert their transactions ahead of pending ones, profiting at the expense of regular users. To combat this, decentralized exchanges (DEXs) should implement commit-reveal schemes. These schemes allow users to commit to an action without revealing the details until later, making it difficult for attackers to ascertain user actions. Additionally, DEXs should remain vigilant against automated bots and conduct regular smart contract audits to identify potential vulnerabilities that could expose their platforms to front-running attacks.

Ensuring liquidity security in BTC-bridged pools: RSK’s 2-way pegging mechanism, known as PowPeg, wraps Bitcoin (BTC) into a corresponding amount of RSK Bitcoin (rBTC). This process ensures that the total supply of BTC locked on the Bitcoin network is matched by an equal amount of rBTC on the RSK network, maintaining consistency across both networks. The PowPeg system is safeguarded by a federation of semi-trusted entities called pegnatories, who collectively oversee the locking and unlocking of BTC. To enhance security, RSK utilizes specialized hardware known as PowHSMs, which prevent pegnatories from manually signing transactions and protect access to private keys. Additionally, RSK employs the Armadillo system, which continuously monitors bridge activities for unusual patterns that might indicate security breaches or threats, allowing for prompt responses. RSK also conducts extensive audits of its smart contracts to further improve the platform’s security.

Handling smart contract risks: DEXs must consistently monitor for smart contract vulnerabilities in their AMM implementations. These vulnerabilities include but are not limited to unchecked external calls, integer overflow and underflow, and reentrancy attacks. To ensure security, DEXs should engage multiple reputable security firms for comprehensive smart contract audits and follow established best practices, such as the OWASP Smart Contract Top Ten. Additionally, they should utilize formal verification methods to confirm the accuracy of their smart contract code.

Conclusion

Decentralized exchanges (DEXs) are protocols that utilize automated market makers (AMMs) to facilitate trading through liquidity pools instead of traditional order books. DEXs operating on Rootstock function similarly to Ethereum-based DEXs, such as Uniswap, but benefit from the added security of the Bitcoin network. This allows for liquidity in Bitcoin decentralized finance (DeFi), providing users with secure, trustless, and non-custodial trading options at lower fees.

Developers can take advantage of RSK’s security, Bitcoin-backed liquidity, and compatibility with the Ethereum Virtual Machine (EVM) to create innovative AMM implementations. They can either port existing Ethereum AMMs or design new ones tailored for RSK. In doing so, they contribute to the expanding and scalable ecosystem of decentralized Bitcoin DeFi.

0
Subscribe to my newsletter

Read articles from Jekayin-Oluwa Olabemiwo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jekayin-Oluwa Olabemiwo
Jekayin-Oluwa Olabemiwo