Balancer CoW AMM is an automated portfolio manager, liquidity provider, and price sensor, that allows swaps to be executed via the CoW Protocol.
Balancer is based on an N-dimensional invariant surface which is a generalization of the constant product formula described by Vitalik Buterin and proven viable by the popular Uniswap dapp.
Most users will want to consume the ABI definitions for BPool, BCoWPool, BFactory and BCoWFactory.
This project follows the standard Foundry project structure.
yarn build # build artifacts to `out/`
yarn test # run the tests
Changes on BPool from Balancer V1
- Migrated to Foundry project structure
- Implementation of interfaces with Natspec documentation
- Replaced
require(cond, 'STRING')
forif(!cond) revert CustomError()
- Bumped Solidity version from
0.5.12
to0.8.25
(required for transient storage)- Added explicit
unchecked
blocks toBNum
operations (to avoid Solidity overflow checks)
- Added explicit
- Deprecated
Record.balance
storage (in favour ofERC20.balanceOf(address(this))
) - Deprecated
gulp
method (not needed since reading ERC20 balances) - Deprecated manageable pools:
- Deprecated
isPublicSwap
mechanism (for pools to be swapped before being finalized) - Deprecated
rebind
method (in favour ofbind + unbind + bind
) - Deprecated exit fee on
unbind
(since the pool is not supposed to have collected any fees)
- Deprecated
- Deprecated
BBaseToken
(in favour of OpenZeppelinERC20
implementation) - Deprecated
BColor
andBBronze
(unused contracts) - Deprecated
Migrations
contract (not needed) - Added an
_afterFinalize
hook (to be called at the end of the finalize routine) - Implemented reentrancy locks using transient storage.
- Deprecated
joinswap
andexitswap
methods (avoid single-token math precision issues)
- Immutably stores CoW Protocol's
SolutionSettler
andVaultRelayer
addresses at deployment - Immutably stores Cow Protocol's a Domain Separator at deployment (to avoid replay attacks)
- Immutably stores Cow Protocol's
GPv2Order.appData
to be allowed to swap - Gives infinite ERC20 approval to the CoW Protocol's
VaultRelayer
contract at finalization time. - Implements IERC1271
isValidSignature
method to allow for validating intentions of swaps - Implements a
commit
method to avoid multiple swaps from conflicting with each other.- This is stored in the same transient storage slot as reentrancy locks in order to prevent calls to swap/join functions within a settlement execution or vice versa.
- It's an error to override a commitment since that could be used to clear reentrancy locks. Commitments can only be cleared by ending a transaction.
- Validates the
GPv2Order
requirements before allowing the swap
- Added a
logBCoWPool
to log the finalization of BCoWPool contracts, to be called by a child pool.
- Create a new pool by calling the corresponding pool factory:
IBFactory.newBPool(name, symbol)
for regular BalancerBPool
sIBCoWFactory.newBPool(name, symbol)
for BalancerBCoWPool
s, compatible with CoW ProtocolBeing
name
andsymbol
strings with the desired name and symbol of the pool's ERC20 LP token
- Give ERC20 allowance to the pool by calling
IERC20.approve(pool, amount)
- Bind tokens one by one by calling
IBPool.bind(token, amount, weight)
- The amount represents the initial balance of the token in the pool (pulled from the caller's balance)
- The weight represents the intended distribution of value between the tokens in the pool
- Modify the pool's swap fee by calling
IBPool.setSwapFee(fee)
- Finalize the pool by calling
IBPool.finalize()
Ethereum Mainnet:
- BCoWFactory: 0xf76c421bAb7df8548604E60deCCcE50477C10462
- BCoWHelper: 0x3FF0041A614A9E6Bf392cbB961C97DA214E9CB31
Ethereum Sepolia:
- BCoWFactory: 0x1E3D76AC2BB67a2D7e8395d3A624b30AA9056DF9
- BCoWHelper: 0xf5CEd4769ce2c90dfE0084320a0abfB9d99FB91D
- BCoWPool: 0xE4aBfDa4E8c02fcAfC34981daFAeb426AA4186e6
Gnosis Mainnet:
- BCoWFactory: 0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624
- BCoWHelper: 0x198B6F66dE03540a164ADCA4eC5db2789Fbd4751