In a Sauce program, swap withGeneralized AMM with weighted pools, single Vault architecture, and flash loans. Supports custom pool types (weighted, stable, linear, composable stable) and multi-token pools with up to 8 tokens per pool.@sauce/router’s function for the venue (uniswapV2,uniswapV3,uniswapV4,curve,balancerV2, …; Slipstream, PancakeSwap V3 and Algebra pools throughuniswapV3), with a minimum output and, where the pool takes one, a price limit (the@sauce/routerreference; several pools under one limit, the distributed swap).
What it offers
- swap: Execute a single swap through the Vault specifying pool ID and assets
- addLiquidity: Join a pool by depositing tokens via the Vault
- removeLiquidity: Exit a pool by withdrawing tokens via the Vault
Notes
- Single Vault contract holds ALL pool liquidity (same address
0xBA12...on every chain) - Pools are identified by
bytes32 poolId, NOT by contract address - The Vault model means tokens only need to be approved to ONE contract for all Balancer pools
- Weighted pools: custom token weights (e.g., 80/20 ETH/USDC); Stable pools: pegged assets; Linear pools: wrapping yield-bearing tokens
batchSwapis gas-efficient for multi-hop trades since tokens only move between Vault internal accounts- Flash loans from Balancer Vault are zero-fee when the swap route stays within Balancer pools
- Internal balances: users can keep tokens in the Vault to save gas on repeated trades
userDataencoding varies by pool type - check Balancer docs for the specific pool’s join/exit types- Use Balancer for multi-token pools (3+ tokens), weighted index exposure, or flash loans
- From a Pot program,
@sauce/routerswaps through the Vault directly:balancerV2(vault, tokenIn, tokenOut, amountIn, poolId, minOut, recipient)approves the Vault for exactlyamountInand callsswap(GIVEN_IN, internal balances off) withminOutas its limit, returning the amount out; the allowance ends at zero.tryBalancerV2catches a failed swap, resets the approval and returns0. ThebalancerV2Swapaction is the same call
Its names in a program
On Ethereum,BalancerV2 is a namespace: its contracts need no import.
Deployments
ABI
BalancerV2VaultABI
import BalancerV2VaultABI from "./protocols/balancer-v2/BalancerV2VaultABI.json"; Speaks for: vault.
swap((bytes32 poolId, uint8 kind, address assetIn, address assetOut, uint256 amount, bytes userData) singleSwap, (address sender, bool fromInternalBalance, address recipient, bool toInternalBalance) funds, uint256 limit, uint256 deadline) payable returns (uint256 amountCalculated)batchSwap(uint8 kind, (bytes32 poolId, uint256 assetInIndex, uint256 assetOutIndex, uint256 amount, bytes userData)[] swaps, address[] assets, (address sender, bool fromInternalBalance, address recipient, bool toInternalBalance) funds, int256[] limits, uint256 deadline) payable returns (int256[] assetDeltas)joinPool(bytes32 poolId, address sender, address recipient, (address[] assets, uint256[] maxAmountsIn, bytes userData, bool fromInternalBalance) request) payableexitPool(bytes32 poolId, address sender, address recipient, (address[] assets, uint256[] minAmountsOut, bytes userData, bool toInternalBalance) request)flashLoan(address recipient, address[] tokens, uint256[] amounts, bytes userData)getPoolTokens(bytes32 poolId) view returns (address[] tokens, uint256[] balances, uint256 lastChangeBlock)
Next steps
- Protocols: the other protocols, by what they do.
- Protocols and tokens: calling a contract by its namespace, or through its ABI.
- Glossary: the words these pages use, in plain terms.
