An Explainer of Hexagon’s Pools

Hexagon Finance
Hexagon Finance
Published in
12 min readApr 14, 2022

What is a DEX?

A Decentralized exchange (DEX) is a type of cryptocurrency exchange that allows for direct transactions to take place online securely without the need for an intermediary on a distributed ledger.

In this sense, they are completely different from centralized exchanges, which rely on the use of a middle man or third party to conduct transactions. Buyers and sellers alike trust this middle man to handle their assets. Decentralized exchanges, on the other hand, cut out the middleman, generating what is often regarded as a “trustless” environment.

Binance, Coinbase, and Kraken are some of the largest centralized exchanges out there, while Uniswap, Balancer, Trader Joe, and Hexagon are decentralized exchanges, built on various public chains.

What are Liquidity Pools and AMMs?

A liquidity pool is a smart contract that accumulates tokens to provide liquidity. (In trading, liquidity is essential as it affects how quickly and seamlessly an asset can be bought or sold.) They enable users to buy and sell crypto on decentralized exchanges without the need for centralized market makers.

In their stead, liquidity pools underpin automated market makers (AMMs), which allow digital assets to be traded in an automatic and permissionless manner through DEXes. In other words, market makers are essentially liquidity providers.

An AMM is an underlying protocol used by decentralized exchanges with an autonomous trading mechanism. You could think of an automated market maker as a robot that’s always willing to quote you a price among different assets. In the AMM protocol, you do not need another trader to make a trade. Instead, you can trade with a smart contract. So trades are peer-to-contract and not peer-to-peer.

Hexagon Finance’s Liquidity Pools

Liquidity pools are the fundamental building blocks of Hexagon Finance, as they define how traders can swap between tokens on the platform.

What makes Hexagon Finance pools unique from other protocols is their limitless flexibility. While other exchanges have pools with constrained parameters, Hexagon Finance can accommodate pools of any composition and underlying math, thanks to the Balancer v2 mechanisms.

Weighted Pools

The algorithms in the Weighted Pools are the generalization of the better-known Uniswap’s XY=K model. Before we go deeper into the Weighted Pools’ mechanisms, let’s take a closer look at the XY=K model.

Uniswap’s XYK model

The XYK model is the best-known and most widely applied AMM mechanism in DeFi. Uniswap, SushiSwap, Pancakeswap, and Trader Joe, all rely on the XYK model, which currently has 232 forks according to Defillama.

The XYK Model is also called the “x∗y=k market maker.” The idea is that you have a contract that holds x coins of token X and y coins of token Y, and always maintains the invariant that x∗y=k for some constant k. The value of the token X and token Y always stays the same, or the pool has 50/50 shares for both tokens. The changes in the number of tokens will change the price.

Weighted Math in Weighted Pools

The Invariant

Weighted Math equation is a generalization of the x∗y=k constant product formula. It accounts for cases with no less than 2 tokens in a pool, as well as weightings that are not an even split.

Please note that the weights are those of the equivalent value of the tokens in the weighted pools, not the number of tokens.

The weighted pool’s AMM is defined by a function of the pool’s balances and weights, constraining V to a constant (‘Invariant V’).‌

Where t ranges over the tokens in the pool; Bt is the balance of the token in the pool; Wt​ is the weight of the tokens, such that the sum of all normalized weights is 1.

If you take a closer look at Uniswap’s model, it is actually a special case of the equation above, when t=2 and W1=W2=50%; which can be translated to

Based on this value function, Hexagon Finance allows users to create pools with up to eight assets, user-defined weights, and customizable swap fees.

Several examples:

Token Price

Though a weighted pool may have multiple tokens in its composition, swaps in these pools occur between only two token assets, which means one is trading one cryptoasset for another in the pool, like a trading pair. Like in the ‘25/25/25/25 AVAX/ETH/LUNA/UST’ pool above, one may pay ETH for AVAX in the same pool.

Unlike the pricing mechanism in Uniswap, the weighted pool considers the token weights when defining the spot price of a swap.

No matter what exchanges are carried out, the share of the value of each token in the pool remains constant.

For a deeper understanding of the math involved, please refer to the docs here.

An Example of how weights may affect the pool contributions

Assuming AVAX price is 100 UST, we may create two pools, containing 20,000 USD (1UST=1USD) liquidity respectively, but with different weights.

As you may notice, the pool with higher weights in AVAX requires heavier contributions in AVAX, and vice versa.

How trades affect the pool and the price

Due to the weight differences, pools have different slippage when users make the same transactions in pools with varied weights. Let’s follow the example above with the three AVAX/UST pools. (Supposing there are no transaction costs.)

Note:

  • The pool invariant stays unchanged before and after the trade.
  • ‘No. of AVAX’ is reduced by 1 AVAX due to the purchase of the user.
  • ‘Price of AVAX for the trade’ is the UST the user pays for this 1 AVAX purchase, translated into the increase of UST in the pool.
  • ‘Price of AVAX for the trade’ is the price of AVAX determined by the pool compositions after the trade.

From the table above, we may notice that though the three weighted pools have the same initial liquidity, the slippage tend to vary. The 50/50 pool has the smallest slippage. Pools with highly biased weights may lead to higher price slippage.

Impermanent Loss

Impermanent loss is the loss suffered by liquidity providers in AMM liquidity pools. It happens when you provide liquidity to a pool, and the price of your deposited assets changes. The bigger this change is, the more you are exposed to impermanent loss. But if the price shifts back to the point when you make the deposit, the loss will disappear. Therefore, we call this loss “impermanent.”

Impermanent loss is the difference in value between holding a set of assets and providing liquidity for those same assets.

Following the example above, a user is holding 100% of the three pools. But the market price of AVAX goes to 110 UST.

For pools that more heavily weigh one token over another, there is less impermanent loss.

Impermanent Loss Simulator:

https://www.coingecko.com/en/impermanent-loss-calculator;

https://baller.netlify.app/;

https://decentyields.com/impermanent-loss-calculator.

Arbitraging

With few exceptions, assets traded in Hexagon pools are also traded on external markets, such as centralized exchanges or other DEXes. Naturally, prices may end up being somehow different in each market.

This price spread between a Hexagon pool and an external market opens up a profit opportunity for arbitrage trades. Anybody can buy an asset on a Hexagon Pool and sell it at a profit on an external market. These arbitrage trades are an important service for Hexagon and a source of profit for liquidity providers.

Stable Pools

Overview

Stable Pools are designed specifically for assets that are expected to consistently trade at near parity, such as different varieties of stablecoins or synthetics. Stable Pools use stable math (based on Stable Swap, popularized by Curve) which amplifies liquidity around a certain price to increase capital efficiency for swapping between similar assets, and allows for significantly larger trades before encountering substantial price impact. Stable Pools’ traders may enjoy tighter spreads and lower price impact.

Stable Math in Stable Pools

Stable Math is designed to allow for swaps between any assets that have the same price, or are “pegged” to the same asset. The most common examples are stablecoins that track US Dollars (UST, USDT, USDC), and assets that track the price of Bitcoin (WBTC, renBTC, sBTC). Prices are determined by the pool balance, the amplification parameters, and amounts of the tokens that are being swapped.

In an ideal scenario, it would make sense to simply allow 1-to-1 trades for these assets; this would be a constant sum curve. In a worst case scenario where one or more of these assets loses their peg and their value diverges, it would make sense to enforce trade rules for uncorrelated assets; this would be a constant product curve, such as the one outlined in weighted math.

Since most real-life cases do not fall in either the ideal or disaster category, the stable math curve combines the constant sum and constant product curves and is designed to facilitate approximately 1-to-1 trades that incur large price changes only when token balances differ greatly. The amplification parameter, A, defines the degree to which the stable math curve approximates the constant product curve (when A=0), or the constant sum curve (when A→∞)

where xi represents the balance of the token in the pool.

Stableswap invariant is a combination of the above two and offers a much lower price slippage than Uniswap for stable coin pools. It is given by:

A is the amplification coefficient and D is the invariant.. Please note that unlike with weighted math, the assets in the stable pools must have the same weights. For example, if a stable pool contains 5 assets, any asset in the pool must have a 20% share.

The figure above is a simplified version of the stable pool, containing two assets. The stableswap invariant is a combination of the constant sum and constant product invariant. Check here to see the impact of different parameters on the stableswap invariant curve.

The lower the amplification coefficient is, the closer to the constant product model the curve will be, as in Uniswap. Normally, trades will have relatively more significant slippages.

The higher the amplification coefficient is, the closer to the straight line the curve is, which is the case in the linear invariant. Normally, trades will have lower slippage. But when one token’s market price deviates from the peg, it will lead to a massive change in the pool’s composition.

We will not go too deep into the math behind stable pools. If you are interested in understanding how the trades affect the pool’s price and slippages, please refer to the study here and here.

Metastable Pools

MetaStable pools are an extension of stable pools that contain tokens with known exchange rates. MetaStable pools use stable math in conjunction with such known exchange rates. They are great for tokens with highly correlated, but not pegged, prices.

Correlated but non-pegged tokens are often (but not always) base tokens and their derivatives. For example, AVAX/SAVAX (Staked AVAX on Benqi Liquid Staking) have a very strong correlation. SAVAX allows users to earn validating rewards from the P-Chain without running a full node or locking up AVAX on a validating node and appreciates relative to AVAX.

Liquidity Bootstrapping Pools (LBPs)

Liquidity Bootstrapping Pools (LBPs) are pools that can dynamically change token weighting (e.g 1/99 to 99/1 for TokenA/TokenB). LBPs use weighted math with time-dependent weights. The start and end weights, as well as the time are selected by the pool owner, who also has the power to pause swaps.

LBPs’ primary use cases are to distribute tokens, mostly for newly launched projects.

Hexagon Finance is partnering with Copper Launch to provide an open and user-friendly way to participate in LBP auctions.

For a deeper understanding of LBP, please check out the explainer here.

LBPs were conceived with the following key considerations in mind

  • A team should be able to build liquidity without large amounts of upfront capital
  • A team should be able to create a treasury to fit their desired risk profile and funding goals
  • The distribution of tokens and liquidity provision should be decoupled from token price changes. In other words, as opposed to bonding curves, tokens should be distributed even if their unit price stays constant.

Key Features

  • Price discovery. The price of the token starts relatively high and drops based on a pre-configured price decay curve that can be resisted by buying pressure from LBP participants. Anyone can buy into or sell out of the LBP freely at any time, so price truly regulates itself.
  • Open and permissionless participation. There are no whitelists, hard caps, or listing requirements. There is no minimum or maximum allocation. LBP participants choose how much they want to buy.
  • Fair distribution. LBPs flip the first-come-first-serve launch model on its head. It’s no longer a race where the first bot in or the transaction with the highest gas fee wins. Get your token into the hands of as many people as possible in a fair way that disincentivizes front-runners and whales getting better rates than smaller participants.
  • Capital efficiency. The initial price of the project’s token in the LBP can be magnified by up to 99 times relative to the collateral deposited along with it. Additionally, the collateral can be fully retrieved at the end of the LBP unless the project’s tokens already exist outside of the LBP, in which case someone could decide to sell into the LBP.

Boosted Pools

Overview

Boosted Pools put idle liquidity into yield-bearing strategies without compromising the core functionality of a liquidity pool.

These pools are designed to facilitate trades between stablecoins while simultaneously forwarding much of the pool’s liquidity to external protocols. These versions of stable pools do not directly hold the stablecoins themselves, but rather hold the pool tokens related to linear pools, which maintain proper balances of TOKEN and aTOKEN, as in the case of interoperating with AAVE.

Key features

  • Boosted Pools are designed to allow for greater capital efficiency, deeper liquidity, and increased yields for liquidity providers.
  • For traders, boosted pools are a cheaper entry/exit into lending protocols like Aave.
  • Boosted pools will enable access to other lending protocols beyond Aave, increasing the opportunity for LPs to gain exposure to a wide variety of yield increases.

How do they work?

Linear Pools

Linear Pools are the base component of boosted pools. They use Linear Math to facilitate trades between two tokens at a known exchange rate. They also use a positive/negative fee mechanism to incentivize arbitrageurs to maintain a desired ratio between the two tokens.

Phantom Pool Tokens (“Phantom BPT”)

One of the key features that make trades through Boosted Pools so simple is the use of Phantom BPT. Normally when a liquidity provider joins/exits a pool, the pool mints/burns pool tokens as needed. This is gas-intensive and requires users to execute a join or exit.

In pools that use Phantom BPT, however, all pool tokens are minted at the time of pool creation and are held by the pool itself. With Phantom BPT, Liquidity Providers use a swap (or more likely a batchSwap) to trade to or from a pool token to join or exit, respectively.

The Hexagon’s boosted pools are going to be fully integrated with our second platform, an AAVE-type lending protocol. This will bring a boosted yield for Hexagon users.

Other Pools

‘What makes Balancer Pools unique from those of other protocols is their limitless flexibility’. Thanks to the Balancer’s model, Hexagon will be able to accommodate pools of any composition and underlying math, allowing for anyone to develop their own pool type, opening the door for customized pricing functions in trading pools.

In turn, this may open the doors to infinite possibilities in building liquidity pools, both for transactions tailored to different types of tokens, but also for portfolio management, using linear pools, managed pools, and custom pools.

For more information, please join our official community groups for further discussion.

References:

Balancer Whitepaper

Balancer V2 documentation

https://twitter.com/BalancerLabs/status/1511023925567782915

Curve StableSwap: A Comprehensive Mathematical Guide

StableSwap — efficient mechanism for Stablecoin liquidity

Understanding StableSwap (Curve)

What is a Liquidity Bootstrapping Pool (LBP)?

--

--