Balancer
Balancer V2
Balancer V2
  • Protocol Overview
  • Developer Docs
  • Products
    • The Vault
      • Flash Loans
    • Balancer Pools
      • Weighted Pools
      • Composable Stable Pools
      • Liquidity Bootstrapping Pools (LBPs)
      • Managed Pools
        • Asset Managers
      • Boosted Pools
      • Custom Pools
    • Smart Order Router
    • Balancer CoW Protocol
    • Oracles (deprecated)
  • Concepts
    • Math
      • Weighted Math
      • Stable Math
    • Fees
  • Ecosystem
    • Governance
      • Governance Process
        • RFC/Proposal Forum Post Template
      • BAL Governance Token
      • Snapshot
      • Multisig
        • Other DAO Multisigs
      • Governable Protocol Fees
      • Emergency subDAO
    • Community
      • Ballers
      • Delegation
      • Grants
    • veBAL and Gauges
      • veBAL
        • How veBAL Works
        • How To Use veBAL
        • How veBAL Boosting Works
          • Working Supply
          • Calculating My Boost
          • Minimum veBAL for Max Boost
        • BIP19 and Yield Bearing Tokens
      • Gauges
        • How Gauges Work
        • How To Use Gauges
  • Security
    • Audits
    • Bug Bounties
    • Emergency Pause
    • Token Compatibility
    • Balancer x Certora Accelerator
  • Getting Started
    • FAQs
      • Swapping
      • Liquidity
      • Liquidity Mining with the veBAL and Gauge System
      • Liquidity Mining (Legacy)
      • Fees
      • Governance
      • The Vault
      • Pools and LBPs
      • Asset Managers
      • Oracles
      • About Balancer Protocol and Labs
      • V2 in a Nutshell
      • V1 ➝ V2 Migration
    • Walkthroughs
      • Trade
      • Invest
    • Contribution Guide
  • Community
    • Discord
    • Forums
    • Medium
    • Dune Analytics
  • Developers (Deprecated)
    • !!! DEPRECATED !!! ⛔
    • Guides
      • Pool Verification
    • Smart Order Router V2
    • GitHub
Powered by GitBook
On this page
  • Overview
  • Invariant

Was this helpful?

  1. Concepts
  2. Math

Stable Math

PreviousWeighted MathNextFees

Last updated 3 years ago

Was this helpful?

Overview

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 (DAI, USDT, USDC), and assets that track the price of Bitcoin (WBTC, renBTC, sBTC). Prices are determined by the pool balances, the amplification parameter, 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 in Weighted Math.

Since most cases are neither ideal nor disasters, 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, AAA, defines the degree to which the Stable Math curve approximates the Constant Product curve (when A=0A=0A=0), or the Constant Sum curve (when A→∞A\rightarrow \inftyA→∞).

For more stable math formulas, .

Invariant

Where:

Since the Stable Math equation is quite complex, determining the invariant, DDD, is typically done iteratively. For an example of how to do this, please refer to .

A⋅nn⋅∑xi+D=A⋅D⋅nn+Dn+1nn⋅∏xiA \cdot n^n \cdot \sum{x_i} +D = A \cdot D \cdot n^n + { \frac{D^{n+1}}{{n}^{n}\cdot \prod{x_i} } }A⋅nn⋅∑xi​+D=A⋅D⋅nn+nn⋅∏xi​Dn+1​

nnn is the number of tokens

xix_ixi​ is is balance of token iii

AAA is the amplification parameter

this function
check out the Developer Docs
StableSwap approaches Constant Product as A->0 and Constant Sum as A->∞