Swap / DEX·EVM
Balancer
Composable AMM with custom pool types: Weighted, Stable, ComposableStable, Boosted (rehypothecated to Aave/Morpho/etc.), Gyroscope CLPs, and (in V3) hooks-based custom pools. Singleton Vault architecture handles all swaps and liquidity.
- 01weighted index pools (80/20 etc.)
- 02stable + LST pools (wstETH/ETH, rETH/ETH)
- 03Boosted Pools (idle liquidity earns base APR via Aave)
- 04custom pools via V3 hooks
- pnpm add @balancer/sdk viem
| Variable | Scope | Description |
|---|---|---|
| NEXT_PUBLIC_BALANCER_VAULT_V2 | Client | Balancer V2 Vault (singleton) on every supported chain: 0xBA12222222228d8Ba445958a75a0704d566BF2C8. |
| NEXT_PUBLIC_BALANCER_VAULT_V3 | Client | Balancer V3 Vault on Ethereum mainnet, Arbitrum, Optimism, Base: 0xbA1333333333a1BA1108E8412f11850A5C319bA9. |
| RPC_URL | Server | EVM RPC for the target chain. |
Integrate Balancer. Use `@balancer/sdk`: `const balancer = new BalancerApi(apiUrl, chainId);` then `balancer.sorSwapPaths.fetchSorSwapPaths({ tokenIn, tokenOut, swapKind, swapAmount, useProtocolVersion: 3 })` returns the optimal route across V2 + V3. Build a swap with `new Swap({ chainId, paths, swapKind })` and `swap.buildCall({ slippage, deadline, sender, recipient, wethIsEth })` — submit returned `to/data/value`. For raw V2 calls go through the Vault: `Vault.swap(SingleSwap, FundManagement, limit, deadline)` or `batchSwap(...)`. Add liquidity in V3: `Router.addLiquidityProportional(pool, exactAmountsIn, minBptOut, wethIsEth, userData)`. Boosted Pools (V3) auto-rehypothecate idle liquidity to ERC-4626 yield sources (Aave aTokens, Morpho vaults) so LPs earn swap fees + base lending APR.
- ⚑All approvals go to the singleton Vault (V2: 0xBA12..., V3: 0xbA13...) — NOT to individual pools. Approving a pool address has no effect.
- ⚑Pool composability matters: ComposableStable pools include the BPT itself as one of the tokens (so `getPoolTokens` returns N+1 tokens). Naive iterators that loop all tokens will mis-compute proportional liquidity.
- ⚑Boosted Pools rehypothecate to Aave/Morpho — LP risk includes lending-protocol bad debt + ERC-4626 wrapper risk on top of normal IL.
- ⚑April 2024 Renzo ezETH depeg blew through Balancer's ezETH/wETH Composable pool because the rate provider lagged the actual ezETH/ETH rate — verify rate provider freshness for any LST/LRT pool you list.
- ⚑V3 introduces 'hooks' — custom logic on swap/add/remove. A malicious or buggy hook can DoS or front-run the pool. UI MUST surface which hook a pool uses and whether it is allowlisted.
- ⚑swap fee, weights, and rate scaling are pool-specific; do not assume Uniswap V2-style x*y=k math for any Balancer pool.
- ⚑veBAL gauge weights, BAL emissions, and bribes (Aura, Hidden Hand) sit on top of base swap-fee APR — quoting LP APR without gauge incentives is misleading for stETH/rETH/LRT pools.