AMMs and liquidity pools on rhino.fi: A technical deep dive

Automated market makers and liquidity pools can be confusing - so we're going to give you as much information as we can.

rhino.fi’s automated market makers (AMMs) allow users to trade 24/7 without the need for a conventional trading partner. These automated systems replace traditional market makers, allowing liquidity to be provided by the community itself.

Here’s an overview of how AMMs work on rhino.fi and their role in our larger offering:

The essentials: what is an AMM and how do we apply the model?

Like most AMMs in DeFi, our model is based on pre-filled liquidity pools.

Each pool contains a pair of tokens (such as USDT and ETH, or ETH and DVF) which are essentially traded against one another. The AMM, an algorithm, continually readjusts the relative price of the two tokens in response to trading activity.

To determine the pricing curve of each token, AMMs use a range of different mathematical equations. At its simplest, the price of each token will rise when it’s bought and fall when it’s sold.

In DeFi, AMMs and liquidity pools have four specific benefits:

  1. Users trade directly into the pools, so there’s no need for a trading partner. Users can trade at any time of the day, even when conventional markets are shut.
  2. Users can earn rewards for holding specific tokens, and markets are created for them.
  3. Supply and demand is matched quickly, in a way that is not always possible with conventional order-book trading.
  4. The pools are filled by ordinary users rather than conventional financial institutions, which means rewards are shared around the community and there’s no need for faceless intermediaries.

How AMMs and liquidity pools look to rhino.fi traders

Traders have the same experience when using our AMM programme as executing any other swap.

So if they want to trade DVF for ETH (both tokens we offer in our liquidity pools), all they need to do is click the ‘Swap’ button in the left-hand corner to access our trading interface. Our automated market making system does the rest in the back-end.

AMMs and liquidity pools are a crucial part of the rhino.fi service

How AMMs and liquidity pools love to liquidity providers

To become a liquidity provider, users need to visit the ‘Pools’ tab on the left side of the page. Once there, they can select a pool to deposit funds into. 

Liquidity providers can only contribute to pools by providing token pairs of equal value. 

This doesn’t mean the same amount of each token, but rather a ratio that corresponds to the pool’s holdings. For example, if a pool holds 1,000 DVF and 1 ETH, participants will need to supply 1,000 DVF for every 1 ETH. 

When tokens are deposited, liquidity providers receive the LP token, which represents their share of the pool. This token can be traded on DEXs and earn further rewards for providing liquidity.

What makes rhino.fi’s AMMs unique

To enable AMMs, rhino.fi has developed smart contracts based on UniSwap V2. These contracts operate on Layer 1 and are dedicated to synchronizing token balances between Layer 2 and Layer 1. Trading is disabled on these contracts, serving solely as a means of balance synchronisation.

Typically, these contracts allow anyone to create a market by depositing two tokens. However, rhino.fi currently disables this feature to maintain control over market creation.

LP token minting occurs periodically on Layer 1 in batches. The synchronization between StarkEx and the Layer 1 contract utilises a feature called L1 Orders, introduced in StarkEx version three. L1 Orders facilitate periodic synchronization between Layer 1 and Layer 2.

This synchronisation ensures that tokens from Layer 2 are sent to Layer 1, and the corresponding LP tokens are minted according to the AMM map. It guarantees that LP tokens represent genuine shares of the pool, preventing the creation of LP tokens out of thin air. This process is handled atomically and instantaneously.

When trading begins, rhino.fi switches the AMM contracts to Layer 2 mode, meaning assets cannot be traded on Layer 1. Transactions must take place off-chain.

An exception to this is emergency withdrawals. In the event of rhino.fi or StarkEx being offline, liquidity providers can use an emergency withdrawal feature to retrieve their funds from the Layer 1 contract using their LP tokens.

The pricing mechanism behind rhino.fi’s AMMs and liquidity pools

rhino.fi currently employs a pricing mechanism based on the classic UniSwap curve. However, the implementation of the L1 contract allows for the addition of different pricing mechanisms in the future, such as those tailored for stablecoin pools, simply by adjusting the code.

Trusted or Custodial Elements

The entire AMM process on rhino.fi is self-custodial for both traders and liquidity providers, relying on user signatures.

When users trade against the AMM, they sign a form specifying their desired token, the acceptable price, and the maximum allowable slippage. They receive the requested asset if the swap meets the specified terms; otherwise, the swap does not occur, and they retain their original token. This guarantee mirrors that of any other trading market on rhino.fi.

Similarly, when liquidity providers deposit assets into the pool, they receive the correct amount of LP tokens. In cases where a deposit fails due to significant changes in the token ratio during the deposit process, the original assets are returned in the correct ratio.

While rhino.fi theoretically has the ability to deny user requests to swap, burn, or mint tokens due to the Layer 2 nature of the platform, a feature is being developed to address this. It will enable users to express their desire to burn LP tokens on Layer 1, similar to the guarantees offered by the StarkEx contract itself, compelling the contract to release all funds. More information will be provided in the future.

Risk Factors

Trading and providing liquidity in AMMs carry similar risks to any contract that controls users’ funds, including the risk of hacks.

rhino.fi takes extensive precautions to minimize these risks, implementing thorough internal audits and undergoing regular external audits from leading blockchain security experts such as PeckShield. Unnecessary changes are avoided whenever possible.

Another risk factor applicable to all AMM pools in DeFi is “impermanent loss.” This term refers to the opportunity cost resulting from significant changes in token value on the open market.

Liquidity pools and AMMs create an isolated ecosystem, where token prices are solely influenced by trading within the pool. The algorithm does not consider external information. As a result, token prices may experience more substantial increases on regular DeFi exchanges compared to AMM pools.

Arbitrage traders may take advantage of the difference in value by buying tokens from the AMM pool. This reduces the supply of that token compared to the other asset in the pool.

When liquidity providers want to withdraw, they receive a proportionate amount of tokens based on the available supply at that time. They may end up with more of the ‘less valuable’ token and less of the ‘more valuable’ one because arbitrage traders bought the higher-value token from the pool and sold the lower-value one.

As a result, liquidity providers might have been better off holding both assets instead of depositing them into the pool because they now have a relatively smaller quantity of the more valuable token.

This loss is called impermanent because it is theoretical and only becomes permanent if the user chooses to exit the pool. Trading fees earned through LP tokens can help offset these losses, but it’s not guaranteed.

For further discussion on our AMM and liquidity pool process or any other aspect of rhino.fi’s technology, please reach out to us on Twitter or Discord.

Latest Posts

X Layer – bridge fee free for 2 weeks

X Layer, the new chain launched by the team at OKX, is finally here. We are delighted to announce that our bridge will be fee free for the first 2 weeks, allowing our users to get into this ecosystem in the fastest and cheapest way possible.

Read Article

rhino.fi is delighted to announce that our bridge now supports inEVM. Supporting this new Layer2 rollup marks the first steps towards full integration with the Cosmos ecosystem.

Read Article

Earn 19% APY on your stablecoins