Balancer v3: The Future of AMM Innovation

Beethoven X
Balancer Protocol
Published in
8 min read2 days ago

“The unveiling of the Balancer v3 codebase marks a pivotal moment in Balancer’s journey. We invite the developer community to innovate and collaborate on a foundation optimised for scalable AMM development.” — Fernando Martinelli

Three years ago, we launched Balancer v2, permissionless DeFi infrastructure to empower Automated Market Maker (AMM) innovation. While v2’s versatility has been a success, its unopinionated architecture has resulted in complex custom pools that inconsistently reimplement core design patterns, posing challenges for developers, integrators, and off-chain tooling.

Balancer v3’s architecture focuses on simplicity, flexibility, and extensibility at its core. The v3 vault more formally defines the requirements of a custom pool, allowing us to shift core design patterns out of the pool and into the vault. Additionally, we’ve implemented a “transient accounting” system leveraging EIP-1153, re-entrant pool lifecycle hooks to enable unprecedented flexibility, native support for yield-bearing tokens, 100% boosted pools, and a flexible router design pattern to facilitate complex interactions with the Balancer protocol.

As v3 approaches feature-completion, we are releasing the codebase to give the broader ecosystem an opportunity to provide feedback and make contributions before the code is frozen for audits. You can find the current state of Balancer v3 here, and the accompanying documentation here. As in v2, the v3 codebase will be licensed under GPL 3.0, reinforcing our dedication to transparency, collaboration, and the open-source community.

The Vault

First introduced in v2, the Vault presented a novel architectural design pattern, separating AMM logic from token management and accounting. It was a first-of-its-kind platform, creating a launchpad for teams to innovate with different AMM strategies, leveraging the security of the vault to manage low-level token transfers, balance accounting, and security checks.

To overcome many of the shortcomings of v2, the v3 vault provides a flexible but opinionated definition for Balancer liquidity pools. In doing so, many design patterns that repeatedly emerged in the development of custom pools on v2 have been shifted into the vault, ensuring consistency across all pools and removing sources of significant complexity from the pool contract. Key vault improvements include:

  • Decimal scaling — Managing tokens with variable decimals in fixed-point math is challenging and error-prone. Most v2 pools adopted a strategy of scaling token balances and input values to 18 decimals prior to performing invariant calculations. In v3, this is managed entirely by the vault.
  • Rate scaling — Balancer’s rate provider infrastructure and core pool framework has allowed us to position ourselves as the hub for yield-bearing liquidity. v3 abstracts the complexity of managing LSTs by moving all rate scaling into the vault, providing all pools with uniform rate-scaled balances and input values by default, ensuring that yield from yield-bearing tokens is not captured by arbitrage traders.
  • Liquidity invariant approximation — To facilitate an optimal UX, internally developed v2 pools supported unbalanced add and remove liquidity operations, allowing users to avoid situations where they end up with small amounts of dust in their wallets when joining a pool. While optimal, the implementation is non-trivial, and to date, no externally developed pools have managed to implement unbalanced liquidity operations. v3 introduces a novel approximation that provides broad support for all pool types that implement an invariant that grows proportionally to pool balances.
  • Transient accounting — While v2 provides a powerful, gas-efficient multi-hop swap that transfers only net balances, EIP-1153’s transient op-codes unlock a new, expressive design, the “Till” pattern. The v3 vault can efficiently enforce contract-level invariants in the scope of a callback, supporting design patterns that were previously not possible.
  • ERC20MultiToken — To ensure consistency of critical pool state, v3 shifts the management of pool tokens (BPTs) into the vault. This allows the system to ensure that both token balances and pool total supply are updated atomically, reducing the risk of read-only reentrancy attack vectors.
  • Natively queryable — v2 includes a built-in mechanism to query the exact outcome of batch swaps off-chain, queryBatchSwap. While extremely powerful, it does not support querying the operation chains (ie: swap + add) that are required for pools with nested BPTs. This has posed significant challenges for integrators and impacted the adoption of pools like B-auraBAL-STABLE. The addition of transient accounting and ERC20MultiToken provides an elegant solution for this problem, allowing v3 to natively support queries for any complex set of operations.
  • Swap fee management — The v2 architecture allowed the pool contract full flexibility in how it implemented its swap fee mechanism, resulting in inconsistent interfaces across various pool types, increasing complexity for both on and off-chain integrations. v3 standardizes swap fee implementation in the vault, while preserving full flexibility with dynamic fee hooks (see below).
  • Pool creator fee — v3 introduces a permissionless mechanism that allows external pool developers to earn a share of swap fees & yield as revenue, incentivizing the creation of successful custom AMMs.
  • Pool pause management — Most externally developed v2 pools implemented a custom strategy to disable swaps on their pools. Balancer has identified this as a core feature and the v3 vault supports pool pausing natively. The pool can define its pause window on registration, relying on the vault to enforce the time window and manage authentication.

Custom Pools & Reentrant Lifecycle Hooks

Balancer v3 remains a platform for AMM experimentation and innovation, allowing custom pools to iterate on existing or define entirely new swap invariants. With the v3 vault handling much of the responsibility that was previously delegated to the pool contract, internally developed pools are significantly less complex. By shifting core design patterns out of the pool and into the vault, we believe v3 strikes a better balance and produces a 10x improvement in pool developer experience (DX).

In addition to custom pools, we’ve introduced a hooks framework that allows developers to easily extend existing pool types at various key points throughout the pool’s lifecycle. While already present in v2, the v3 vault formalizes the definition of hooks and transient accounting enables secure vault reentrancy, unlocking an infinite design space.

To showcase the potential of hooks, we’ve put together some simple examples:

This is just the tip of the iceberg! We’re excited to see what the broader ecosystem can create.

100% Boosted Pools

First introduced in v2, Boosted Pools presented a novel solution focused on increasing the capital efficiency of passive liquidity providers (LPs). An alternative to concentrated liquidity (CL) positions that require active management, Boosted Pools deposit idle liquidity in a trusted third-party platform (like Aave or Yearn), providing passive LPs exposure to an additional layer of sustainable yield. While the first iteration of Boosted Pools was constrained by the v2 vault architecture, the introduction of ERC20MultiToken and transient accounting in v3 enables gas-efficient 100% Boosted Pools.

Boosted Pools in v3 will not require Balancer Pool Token (BPT) nesting. Instead, the yield bearing token (ie: Aave USDC), will be registered directly with the pool. To facilitate gas-efficient swaps to and from underlying tokens (ie: USDC), v3 introduces the concept of Buffers. A Buffer can be thought of as a simple two-token liquidity pool that holds a yield bearing token (waUSDC) and it’s underlying counterpart (USDC). Any swap through a Boosted Pool will pass through the corresponding Buffer(s), and if it holds enough liquidity to facilitate the swap, no external call is required. For larger swaps, the Buffer will trigger a wrap or unwrap with the third-party protocol and leverage the external call to rebalance itself. With minimal liquidity, Buffers should facilitate most swaps through Boosted Pools, providing LPs with 100% exposure to yield-bearing assets while offering gas-efficient swaps.

Build On v3

To support the development of products on v3, the Balancer DAO has undertaken the following initiatives:

  • Grants — The grants program will be offering up to 150k BAL over the next 6 months for projects new and old to build out implementations on Balancer v3. This new, developer-centric Balancer architecture makes building on Balancer easier than ever and we want to encourage more teams to see the possibilities and grow the ecosystem. Read more about this and apply here.
  • Hooks Bounty Program — Hooks bring rapid pool development and a vast new technological landscape for projects to play with on Balancer. To promote and encourage experimentation, Balancer Grants will be offering bounties for teams and contributors creating new hook developments on Balancer and progressing the best ones to an audit. Bounties will be offered through competitions and ongoing applications to the Grants Committee.

Balancer v3 continues to facilitate the creation of innovative products through its powerful and permissionless infrastructure. The simplification of custom pool development and the introduction of hooks reduce the development time and effort required, making it easier for developers to innovate and bring new products to market. By shifting core design patterns out of the pool and into the vault, Balancer v3 ensures consistency and flexibility, drastically improving the developer experience.

While the breadth of specific products that will emerge remains to be seen, it is up to the financial pioneers of our era to define the future landscape of DeFi. With the innovations introduced by Balancer v3, we aim to provide a robust and flexible foundation that empowers developers with the tools they need to push the boundaries of what’s possible.

--

--