Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Glossary

Constant Mean Formula (Balancer Pool)

An Automated Market Maker (AMM) invariant that maintains the weighted geometric mean of token reserves as constant, enabling pools with multiple assets and customizable weightings.
Chainscore © 2026
definition
DEFINITION

What is the Constant Mean Formula (Balancer Pool)?

The Constant Mean Formula is the mathematical invariant governing liquidity pools on the Balancer protocol, enabling the creation of automated market makers (AMMs) with multiple tokens and custom weightings.

The Constant Mean Formula is the core mathematical invariant that defines the relationship between the reserves of multiple tokens in a Balancer pool. It is a generalization of the simpler Constant Product Formula (x*y=k) used by protocols like Uniswap. Instead of a product, it maintains a weighted geometric mean of the token reserves, expressed as ∏ (B_i)^{w_i} = k, where B_i is the balance of token i, w_i is its normalized weight, and k is the invariant constant. This formula ensures that for any trade, the weighted geometric mean of the pool's reserves remains constant, determining the swap price based on the relative scarcity of tokens within the pool.

This generalized formula enables pools with custom token weightings, such as 80/20 or 50/30/20 distributions, which are not possible with a standard 50/50 pair. The weights (w_i) are critical as they represent the target proportion of the pool's value each token should hold. A token with a higher weight experiences less price impact when traded, making it behave more like a stable asset within the pool. This design allows Balancer pools to function not only as automated market makers (AMMs) but also as self-balancing, index-like portfolios where the pool automatically rebalances through arbitrage as market prices change.

A key property derived from the Constant Mean Formula is that the spot price for swapping token i for token j is given by (B_i / w_i) / (B_j / w_j). This shows that price is determined by the ratio of the token balances adjusted by their respective weights. When a trade occurs, the pool's invariant k is recalculated, and the new balances must satisfy the formula. This mechanism ensures the pool remains solvent and defines the slippage a trader will experience. The formula's flexibility is foundational to Balancer's Smart Order Router, which can split trades across multiple pools with different compositions to find the best execution price.

The Constant Mean Formula underpins several advanced DeFi use cases. Liquidity Bootstrapping Pools (LBPs) use dynamically changing weights to facilitate fair token distribution. Managed pools allow managers to adjust weights over time for portfolio strategies. Furthermore, the formula enables the creation of pools with up to eight tokens, supporting complex index funds or yield-bearing asset baskets directly on-chain. This mathematical model is what distinguishes Balancer from other AMMs, providing a powerful primitive for customizable on-chain liquidity and portfolio management.

how-it-works
BALANCER POOL MECHANICS

How the Constant Mean Formula Works

An explanation of the mathematical invariant that powers Balancer's automated market maker (AMM) pools, enabling liquidity pools with multiple tokens and customizable weights.

The Constant Mean Formula is the mathematical invariant governing Balancer pools, a generalization of the Constant Product Formula used by Uniswap. While Uniswap's x * y = k maintains a constant product for two assets, the Constant Mean Formula, expressed as ∏ (balance_i) ^ (weight_i) = k, maintains a constant weighted geometric mean for pools containing two or more tokens. Each token in the pool has a predefined weight_i (expressed as a percentage of the pool), which determines its influence on the invariant and, consequently, its price sensitivity within the pool.

This formula enables the creation of highly customizable liquidity pools. For example, a pool could be configured with three tokens weighted at 50% (e.g., ETH), 25% (e.g., DAI), and 25% (e.g., USDC). The invariant ensures that the product of each token's balance, raised to the power of its weight, remains constant before and after any trade. This design allows for pools that are not 50/50, creating opportunities for liquidity providers to express specific market views or for creating index-like funds where the pool itself acts as a tokenized basket.

The pricing mechanism is derived directly from the invariant. When a trader swaps Token A for Token B, the pool's smart contract calculates the required amount of Token B to give out such that the value of k is preserved. The spot price between any two tokens in the pool is determined by the ratio of their balances and weights: Price (A/B) = (Balance_B / Weight_B) / (Balance_A / Weight_A). This means price impact is lower for higher-weight tokens and increases as a token's balance deviates from its target weight.

A critical feature enabled by this formula is non-custodial portfolio management. Liquidity providers deposit assets according to the pool's predefined weights. As trades occur and arbitrageurs rebalance the pool, fee income is generated. Providers earn this trading fee proportional to their share of the pool, all while maintaining a passive, automatically rebalancing portfolio that adheres to the target asset allocation defined by the token weights.

key-features
BALANCER POOL MECHANICS

Key Features of the Constant Mean Formula

The Constant Mean Formula is the invariant function that governs the automated market maker (AMM) logic for Balancer's customizable liquidity pools. It generalizes the Constant Product Formula to allow for any number of assets and arbitrary, non-equal weights.

01

Generalized Invariant

The formula is expressed as ∏ (B_k)^{w_k} = k, where B_k is the balance of token k and w_k is its normalized weight (summing to 1). This invariant must hold for all trades, ensuring the weighted geometric mean of the token balances remains constant. It is a superset of other AMM models: a 50/50 two-token pool is the classic Constant Product Market Maker (CPMM), while a pool with equal weights for all tokens is a Constant Mean Market Maker (CMMM).

02

Customizable Asset Weights

Unlike fixed 50/50 pools, each asset in a Balancer pool is assigned a target weight (e.g., 80/20, 33/33/33). This allows pools to be optimized for specific use cases:

  • 80/20 Pools: For governance token/stablecoin pairs, where liquidity providers (LPs) maintain a higher exposure to the volatile asset.
  • Index Pools: To create token baskets that automatically rebalance as users trade against the pool, acting as a passive portfolio manager. The pool's smart contract enforces these weights through arbitrage incentives.
03

Multi-Asset Support

The formula natively supports pools with 2 to 8 assets. This enables complex, capital-efficient liquidity environments where a single pool can facilitate trades between multiple token pairs. For example, a pool containing WETH, USDC, and BAL allows direct swaps between any pairing (WETH/USDC, WETH/BAL, BAL/USDC) without routing through intermediate pools. This reduces slippage and fee costs for traders interacting with the pool's constituent assets.

04

Swaps & Price Impact

The spot price for a swap is derived from the ratio of the tokens' balances and their weights. The price impact of a trade is determined by how much it moves the pool away from its target weights. Key mechanics:

  • Arbitrage: Drives the pool back to its equilibrium weights, which align with external market prices.
  • Swap Fee: A percentage (e.g., 0.05%) is taken from the input amount of each trade and added to the pool's reserves, accruing value for LPs.
  • Formulaic Slippage: Larger trades cause greater price impact as they distort the invariant more significantly.
05

Liquidity Provision & Fees

Liquidity providers deposit assets in precise proportion to the pool's target weights. In return, they receive Balancer Pool Tokens (BPT), which represent their share of the pool. Fees are automatically reinvested into the pool, increasing the value of each BPT. The customizable weights allow LPs to express a specific investment thesis, such as holding a higher percentage of a governance token while earning fees on its trading volume.

06

Comparison to Other Invariants

The Constant Mean Formula is part of a family of AMM invariants:

  • Constant Product (x*y=k): Used by Uniswap V2. A special case of Balancer's formula with two assets at 50/50 weights.
  • Constant Sum (x+y=k): Used by stablecoin pools (like Curve's StableSwap). Provides zero slippage at pegs but can be drained if the peg breaks.
  • Hybrid Invariants: Protocols like Curve combine constant sum and constant product for low-slippage stablecoin swaps, which is a different approach than Balancer's generalized mean.
mathematical-formula
MATHEMATICAL FORMULA AND DERIVATION

Constant Mean Formula (Balancer Pool)

The Constant Mean Formula is the core invariant governing the automated market maker (AMM) logic of a Balancer liquidity pool, generalizing the constant product formula to support multiple tokens with arbitrary, customizable weights.

The Constant Mean Formula is defined as ∏ᵢ Bᵢ^wᵢ = k, where Bᵢ is the balance of token i in the pool, wᵢ is its normalized weight (where ∑ᵢ wᵢ = 1), and k is the invariant constant. This formula ensures that the weighted geometric mean of the token balances remains constant before and after any trade, deposit, or withdrawal. Unlike the simpler Constant Product Market Maker (CPMM) used by Uniswap V2, which assumes equal 50/50 weights for two assets, Balancer's formula allows for pools with 2 to 8 tokens, each assigned a specific weight (e.g., 80/20 or 33/33/34).

The derivation stems from the principle of preserving a value-weighted portfolio. When a trader swaps token A for token B, the pool adjusts the balances to maintain the invariant k. The spot price between any two tokens, say token i and token j, is derived from the formula as Price(i,j) = (B_j / w_j) / (B_i / w_i). This shows that the price is proportional to the ratio of the token balances divided by their respective weights. A higher weight for a token makes its price in the pool less sensitive to changes in its balance, effectively creating a deeper liquidity band for that asset.

In practice, the formula enables customizable pool architectures. A common example is an 80/20 BAL/WETH pool, where the BAL token is weighted at 80% and WETH at 20%. This means the pool aims to consistently hold a value ratio of 80% BAL and 20% WETH. Liquidity providers deposit assets according to these weights, and arbitrageurs correct price deviations. The invariant k increases when liquidity is deposited (minting new pool tokens) and decreases when liquidity is withdrawn (burning pool tokens), ensuring the value of the liquidity pool shares is directly tied to the underlying assets.

examples
CONSTANT MEAN FORMULA

Examples and Use Cases

The Constant Mean Formula powers customizable liquidity pools where asset weights can be set to any non-zero value. These use cases demonstrate its flexibility beyond the standard 50/50 AMM model.

INVARIANT FORMULA ANALYSIS

Comparison with Other AMM Invariants

A technical comparison of the Constant Mean (Balancer) invariant against the Constant Product (Uniswap v2) and StableSwap (Curve) formulas, highlighting core mathematical and liquidity properties.

Invariant PropertyConstant Mean (Balancer)Constant Product (Uniswap v2)StableSwap (Curve)

Core Formula

∏(token_balance^weight) = k

x * y = k

(x + y) + (x * y) = k (simplified)

Primary Use Case

Custom multi-asset pools, index funds

Volatile asset pairs (e.g., ETH/DAI)

Stablecoin/pegged asset pairs

Number of Assets Supported

2 to 8 (configurable)

2 (fixed)

2+ (commonly 2-4)

Customizable Weights

Price Impact for Stable Assets

Low (with balanced weights)

High

Extremely Low

Impermanent Loss Profile

Configurable via weights

High for volatile pairs

Very Low for pegged assets

Liquidity Concentration

Uniform across full range

Uniform across full range

Concentrated near 1:1 peg

Fee Structure Applicability

Dynamic, weight-based

Uniform

Uniform

ecosystem-usage
CONSTANT MEAN FORMULA (BALANCER POOL)

Ecosystem Usage and Protocols

The Constant Mean Formula is the foundational invariant powering Balancer's Automated Market Maker (AMM) pools, enabling liquidity pools with multiple tokens and customizable weights.

01

Core Invariant

The Constant Mean Formula is the mathematical rule that defines the relationship between token balances in a Balancer pool. Unlike Uniswap's constant product formula (x*y=k), it generalizes to any number of tokens with arbitrary weights. The invariant is: ∏ (Balanceᵢ)^Weightᵢ = k, where the product of each token's balance raised to its weight remains constant. This allows for pools with more than two assets and non-50/50 weightings.

02

Customizable Pool Weights

A key innovation is the ability to assign a weight (e.g., 80/20, 50/30/20) to each token in the pool. This weight determines the pool's target composition and influences price impact. For example, an 80/20 WBTC/WETH pool will be less sensitive to trades in the higher-weighted asset (WBTC), creating a different trading curve than a standard 50/50 pool. Weights are set by the pool creator and can be static or managed by smart contracts.

03

Multi-Token Liquidity Pools

The formula natively supports pools with 2 to 8 tokens. This enables complex, capital-efficient liquidity provision for correlated assets, such as a stablecoin pool (DAI, USDC, USDT) or an index-like pool of DeFi governance tokens. Liquidity providers (LPs) deposit all tokens in the pool's target weight proportions, earning fees from all trading pairs within the single pool.

04

Price Impact & Trading

The spot price between any two tokens in the pool is derived from their balances and weights. Price impact for a trade is calculated based on how much the trade moves the balances away from their weighted targets. The formula ensures that the pool always has liquidity for all its tokens, but trades that significantly imbalance the pool face higher slippage, incentivizing arbitrageurs to restore the target weights.

05

Protocol Fees & Value Accrual

Balancer pools can charge a swap fee (e.g., 0.05% to 1%) on every trade, which is distributed proportionally to LPs. Additionally, protocol fees can be enabled, diverting a portion of the swap fee to the Balancer DAO treasury. For Boosted Pools that hold yield-bearing tokens (like Aave aTokens), the formula interacts with the underlying yield, allowing LPs to earn both trading fees and underlying yield.

06

Smart Order Routing & Vault

Trades are executed via the Balancer Vault, which holds all pool assets. The Smart Order Router splits a single trade across multiple pools to find the best execution price. For instance, a swap from DAI to BAL might route through a DAI/WETH pool and then a WETH/BAL pool, or directly through a multi-token pool containing all three assets, optimizing for lowest price impact.

security-considerations
CONSTANT MEAN FORMULA

Security and Economic Considerations

While the Constant Mean Formula provides flexible liquidity, its design introduces unique security and economic dynamics that must be managed by pool creators and LPs.

01

Impermanent Loss Asymmetry

Unlike a Constant Product Market Maker (CPMM) where IL is symmetrical, a Balancer pool's IL profile is weighted by token proportions. In an 80/20 pool, the token with the higher weight experiences amplified IL relative to the lower-weight token during price divergence. This creates a non-linear risk profile that LPs must model.

  • Example: In an 80/20 ETH/DAI pool, a 2x ETH price increase causes ~3.6% IL for the ETH side but only ~0.9% for the DAI side.
02

Pool Creator Responsibilities & Fees

The entity deploying a Balancer pool controls critical parameters that define its security and incentive structure:

  • Swap Fee: Set by the creator, this percentage is taken from each trade and distributed to LPs. It must balance attracting volume with LP profitability.
  • Protocol vs. Pool Fees: Balancer v2 introduces a protocol fee (set by governance) that can be taken from the swap fee, creating a two-tier fee structure.
  • Weight Updates: Creators can propose gradual weight updates (subject to timelocks) to rebalance the pool's strategy, which is a governance and economic action.
03

Economic Attack Vectors

Custom weightings can make pools targets for specific economic attacks.

  • Weight Manipulation: An attacker could execute large swaps to temporarily skew weights far from their equilibrium, creating arbitrage opportunities at the expense of LPs, especially in low-liquidity pools.
  • Flash Loan Exploits: The formula's predictability can be combined with flash loans to manipulate prices across multiple pools in a single transaction, although Balancer v2's asset management reduces this risk.
  • Pool Drain via Donation: As with any AMM, donating large amounts of a single token to skew the ratio can be used to drain value (see donation attacks).
04

Liquidity Concentration Risk

The ability to create pools with high concentrations (e.g., 95/5) introduces concentrated risk:

  • Capital Efficiency vs. Risk: High-weight assets are extremely capital efficient for swaps but expose LPs to massive IL if that asset's price moves.
  • Oracle Reliability: Pools often serve as price oracles. A pool with 95% weight in one asset provides a less robust, more manipulable price feed for the minority asset.
  • Exit Liquidity: For the low-weight token, the pool provides very little exit liquidity, making large sells highly impactful.
05

Smart Contract & Upgrade Risks

Balancer's implementation adds layers of complexity that must be audited and trusted.

  • Vault Architecture (v2): All pool assets are held in a single, central Vault contract. A critical bug in this contract jeopardizes all pools.
  • Governance Control: Key parameters, including protocol fees and the whitelist for liquidity gauges (for token emissions), are controlled by Balancer Governance (BAL) token holders.
  • Timelocks & Pauses: Administrative functions are typically behind timelocks, and pools can be paused by governance in an emergency.
06

Value Accrual for LPs

The economic model for LP profitability depends on multiple, sometimes competing, flows:

  • Swap Fees: The primary source of yield, proportional to trading volume and the pool's fee setting.
  • BAL Liquidity Mining: Pools may be eligible for BAL token emissions, distributing governance tokens as incentive. Emissions are directed via liquidity gauges.
  • Protocol Fee Drag: The protocol fee (if activated) is a direct deduction from LP swap fee earnings.
  • Tokenomics of Underlying Assets: In pools containing rebasing or fee-generating tokens (e.g., staked assets), LPs may also accrue additional native rewards.
CONSTANT MEAN FORMULA

Frequently Asked Questions (FAQ)

The Constant Mean Formula is the mathematical foundation for Balancer's Automated Market Maker (AMM) pools. This FAQ addresses common technical questions about its function, properties, and applications.

The Constant Mean Formula is the invariant function that governs pricing and reserves in a Balancer pool, generalizing the Constant Product Formula (x*y=k) to support multiple tokens with customizable weights. It works by maintaining a constant weighted geometric mean of the pool's token reserves, expressed as ∏ (B_i)^{w_i} = k, where B_i is the balance of token i and w_i is its normalized weight. This invariant ensures that any trade or liquidity change alters the reserves in a predictable, non-linear way, with price impact increasing as a token's reserve decreases relative to its weight. The formula allows for pools with 2 to 8 tokens, each assigned a weight (e.g., 80/20 or 50/25/25) that influences its price sensitivity and fee distribution.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected Directly to Engineering Team