The Math Behind BAMM Lending

Samuel McCulloch
Samuel McCulloch
Dec 7, 2023
The Math Behind BAMM Lending

The hottest thing this month for Frax has been BAMM or Borrow AMM, which has seen pretty much everyone in DeFi tweeting about it.

BAMM is revolutionary, in that it will change the on-chain meta for providing liquidity. In this article, we’re going to break down the BAMM mechanics based on what we know so far. Nothing official has been posted yet, but we’ve confirmed some details with the Frax dev team

Ok lets go over some AMM math. Uniswap v2 AMM’s work on the following formula

x*y=k

Here's a breakdown of the formula:

  • (x) and (y) represent the quantity of two different tokens in a liquidity pool. For instance, in a ETH/FRAX pool, (x) could be the amount of ETH, and (y) the amount of FRAX.

  • (k) is a constant value. Once the pool is created, the product of (x) and (y) must always equal (k). The value of (k) changes only when liquidity is added to or removed from the pool.

How it works

The ratio of (x) to (y) determines the price of one token in terms of the other. If there's more of token (x) in the pool, its price in terms of (y) decreases, and vice versa.

When a trade is made (for instance, swapping ETH for FRAX), the amount of ETH in the pool (x) increases, and the amount of DAI (y) decreases. The product (x \times y) must still equal (k). This change in balance automatically shifts the price, according to supply and demand dynamics.

Lets go through an example trade of a liquidity pool with 1,000 ETH and $2,000,000 FRAX. The initial price of ETH is set at $2,000.

Let's say someone wants to buy 10 ETH from this pool. Here's how the assets are added or subtracted from the pool after this trade:

  • Initial State:

    • ETH in Pool: 1,000 ETH
    • FRAX in Pool: $2,000,000
  • Trade Execution:

    • ETH Bought by Trader: 10 ETH
  • Final State:

    • ETH in Pool: 1,010 ETH (1,000 + 10)
    • FRAX in Pool: Approximately $1,980,198

The trader pays approximately $19,802 FRAX to buy 10 ETH. This payment is calculated based on the constant product formula (x * y = k), ensuring that the product of the quantities of ETH and FRAX in the pool remains constant.

After the trade, the pool has more ETH and less FRAX, which adjusts the price of ETH relative to FRAX within the pool. This change can also create arbitrage opportunities as the pool price may now differ from the market price.

Virtualizing the AMM

The biggest issue with AMM's is that the assets deposited into a vanilla AMM are locked, and cannot be used for trading purposes other than swaps. The assumption a trader is making by placing funds in the AMM is that the swap fees will outpace simply holding the assets over time. Unfortunately, research has shown that because AMM's can't shift transaction fees, their returns suffer against other market making strategies. Only a fraction of the LP is ever used at one time for swaps, even during periods of high volatility.

A solution to this problem is to allow a portion of the liquidity to be removed, and while virtualizing the swap curve. Balancer was one of the first projects to implement this with its Boosted Pools which "boost" the pool with external protocols like Aave, where they accrue additional yield (e.g., lending fees). This integration essentially virtualizes the liquidity by making it productive even when not directly engaged in swaps.

By virtualizing the AMM curve, Boosted Pools can offer deeper liquidity than what is immediately apparent in the pool itself. The assets deposited in external protocols contribute to the pool's liquidity, but they also earn yield independently. According to Balancer, in their stableswap pools, which enable swaps between stablecoins, only 10% of the total amount of the pool is ever used. This means that the other 90% of assets are essentially under utilized.

Enter BAMM

BAMM is an evolution of the virtualized AMM, where instead of allowing a single participant to determine where the idle liquidity is used, it creates a dual sided lending market for both assets in the LP.

Returning to the example above of the ETH/FRAX pool, if only 20% of the assets are ever needed to be swapped, it means that 800 ETH and 1.6m FRAX are available for use by traders.

To demonstrate how someone would use the Borrow AMM (BAMM) with a pool of 1000 ETH and 2,000,000 FRAX (where 1 ETH is priced at $2,000), let's go through a step-by-step example. In this scenario, a user wants to leverage their ETH holdings.

Initial Pool State:

  • ETH in Pool: 1000 ETH
  • FRAX in Pool: 2,000,000 FRAX
  • Price of 1 ETH: $2,000

The constant ( k ) for this AMM pool is calculated as:
k = ETH in Pool * FRAX in Pool = 1000 * 2,000,000 = 2,000,000,000

User's Action:

  • The user decides to leverage their ETH by using it as collateral in the BAMM.
  • Assume the user wants to use 100 ETH (worth $200,000) for this purpose.

Breakdown of the Process:

  1. User's Deposit:

    • User deposits 100 ETH as BAMM collateral, they now can borrow up to a maximum LTV, which for this case will be 80%.
  2. Borrowing FRAX:

    • The user is able to borrow 160,000 FRAX against their 1 ETH from the pool, with a max LTV of 80%.
    • 160,000 FRAX is removed from the LP, leaving 1,840,000 FRAX remaining.
    • The ETH/FRAX LP now has a usage rate of 8%. Interest rates are determined by the total usage rate for all loans issued from the BAMM pool LP, similar to Fraxlend. As usage goes up, interest rates will adjust upwards.
  3. ETH price up:

    • ETH price rises to $2,469.14
    • ETH in Pool: 900 ETH
    • FRAX in Pool: Approximately 2,222,222 FRAX virtual, actual 2,062,222 FRAX custodied in the ETH pool.
    • The ETH collateral deposited for BAMM will also rise, now able to borrow a maximum of 197,531.20 FRAX
    • Usage rate for the total amount of loans decreases to 7.2%
  4. ETH price down:

    • ETH price drops to $1,652.89.
    • ETH in Pool: 1100 ETH
    • FRAX in Pool: Approximately 1,818,182 FRAX virtual, actual 1,652,893 FRAX custodied in the ETH pool.
    • LTV for the loan is now above 80%, the ETH would be soft liquidated to cover the debt. If the price of ETH rises, the FRAX can be used to re-collateralize, potentially allowing the user to reclaim a portion of their ETH collateral.
    • Additionally, the usage rate for total loans rises to 9.9%.

Debt is denominated in LP tokens and calculated as the sqrt(X*Y). sqrt(K) for short. You are solvent as long as the sqrt(K) of your collateral is higher that the sqrt(K) of your debt.

Liquidations

Frax has said that they will use soft liquidations to repay any debt positions with high enough LTV. While we don't have any specifics, the mechanics of the soft liquidation seem similar to setting up a single sided range on Uni V3. So long as you are outside the range, you asset remains in your denominated collateral. However, as the trade starts to move against you, your collateral enters the soft liquidation range and its slowly converted into the borrowed currency. If the trade moves back in your favor, you will buy back your original assets. If the trade keeps going against you, eventually you come to the end of the range and you are liquidated.

Managing the Interest Rate for BAMM

The interest rate for BAMM will most likely be determined based on a linear interest rate similar to the one used for Fraxlend, which has 4 parameters that determine the interest rate:

  • Minimum Rate: Rate when Utilization is 0%
  • Vertex Rate: Rate when utilization is equal to vertex utilization (i.e when the two slopes meet)
  • Vertex Utilization: The Utilization % where the two slopes meet
  • Maximum Rate: Rate when Utilization is 100%

Additionally, there will need to be a parameter which sets the maximum borrow percentage for a pool. Referring the Balancer picture above, it has a MBP of 80%. The Frax DAO will set the parameters for each pool, with volatile pools having a lower MBP and stable swap pools higher.

Time-Weighted Variable Interest Rate

Another factor for the BAMM interest rate will be how fast it changes per time period based on utilization rate. The picture above is from Fraxlend, and it shows that at 100% utilization, interest rates rise by 200% every 4 hours. The Time-Weighted Variable Interest Rate has 4 parameters:

  • Minimum Rate: Minimum Rate to which interest can fall
  • Target Utilization Range: The Utilization Range where the interest rate does not adjust, it is considered in equilibrium with the market expectations.
  • Maximum Rate: Maximum Rate to which interest can rise
  • Interest Rate Half-Life: The time it takes for the interest to halve when Utilization is 0%. This is the speed at which the interest rate adjusts.

Putting It All Together

BAMM is going to revolutionize how we view AMM's. Instead of just siloing assets for swaps, its deployment will create a brand new source of revenue for LPs. One of the big knocks on AMM's since they launched is that they don't generate enough revenue to compete with CEX based CLOB market making, where market makers can dynamically adjust spreads based on volatility and other market factors. The additional revenues from BAMM could add significant revenues for on-chain LPs, allowing AMM's to compete better against CEX CLOB's.

By virtualizing the swap curve, BAMM will open up a host of new trading strategies and yield opportunities. Traders will now be able to consolidate their lending positions into AMM's rather than single sided collateral provision. Liquidity will deepen on-chain as a result, leading to tighter swap markets and depth.

With BAMM exclusively launching on Fraxchain in 2024, we might witness a massive influx of assets that want to take advantage of this new liquidity lending system. Frax is once again at the forefront of DeFi tech.


More from Flywheel

View More

Subscribe and join the Flywheel family

Always Free. Never Spam.

Harness the power of the flywheel.

Not financial advice. Flywheel content is strictly educational and is not investment advice or a solicitation to buy or sell any assets or to make any financial decisions.

Flywheel and affiliates are not liable for any investment losses or damages resulting from your reliance on any information provided.

2023 ©️ Flywheelpod Inc. All rights reserved.