Vault
The Vault module provides utilities for integrating CoW Protocol with Balancer Vault, enabling advanced trading features like internal balance usage and batch swaps.
Constants
VAULT_INTERFACE
A partial ABI interface for the Balancer Vault containing methods for manageUserBalance and batchSwap:
const VAULT_INTERFACE: Interface;
Key Addresses (Mainnet)
| Contract | Address |
|---|
| Balancer Vault | 0xBA12222222228d8Ba445958a75a0704d566BF2C8 |
| CoW Protocol Vault Relayer | 0xC92E8bdf79f0507f65a392b0ab4667716BFE0110 |
Functions
grantRequiredRoles
Grants necessary permissions to the CoW Protocol Vault Relayer.
async function grantRequiredRoles(
vault: Contract,
vaultRelayerAddress: string
): Promise<void>;
This function is intended to be called by the Balancer Vault admin, not by traders.
Balance Types
Users can configure token handling through three balance types:
| Type | Description | Gas Cost |
|---|
| ERC20 | Standard transfers requiring token approval | Standard |
| EXTERNAL | Leverages existing Vault approvals | Reduced |
| INTERNAL | Uses Vault internal balances | Lowest |
Example
import { ethers } from "ethers";
const provider = new ethers.providers.JsonRpcProvider("YOUR_RPC_URL");
// Balancer Vault on mainnet
const vaultAddress = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";
const vaultRelayer = "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110";
// Check internal balance
const vault = new ethers.Contract(vaultAddress, VAULT_INTERFACE, provider);
On networks where the Balancer Vault contract has a known compromised admin key (notably Ethereum mainnet, Gnosis Chain, Arbitrum, and Base), using INTERNAL or EXTERNAL balance types may expose users to risk. The CoW Protocol API rejects orders using these balance types on affected networks. Always use ERC20 balance type unless you have verified that the Balancer Vault on your target network is safe (e.g., Plasma, which uses a non-compromised deployment).
Internal balance operations have different gas cost characteristics than standard ERC20 transfers. Test thoroughly on testnets before using Vault integration in production.