Skip to content

Commit

Permalink
chore: v1.4.0 release (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase authored Aug 5, 2024
2 parents 4289bb8 + 01e8f91 commit 04c915d
Show file tree
Hide file tree
Showing 71 changed files with 2,705 additions and 1,369 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/exitPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
174743
174820
2 changes: 1 addition & 1 deletion .forge-snapshots/joinPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
138985
138974
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4899289
4360005
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4042925
3442739
2 changes: 1 addition & 1 deletion .forge-snapshots/newBFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4140477
3564561
2 changes: 1 addition & 1 deletion .forge-snapshots/newBPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3486610
2845617
2 changes: 1 addition & 1 deletion .forge-snapshots/settlementCoWSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
215793
215771
2 changes: 1 addition & 1 deletion .forge-snapshots/settlementCoWSwapInverse.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
225641
225619
2 changes: 1 addition & 1 deletion .forge-snapshots/swapExactAmountIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
104920
104964
2 changes: 1 addition & 1 deletion .forge-snapshots/swapExactAmountInInverse.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114589
114787
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ broadcast/*/*/*

# Out dir
out

# echidna corpuses
**/corpuses/*
**/crytic-export/*
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ yarn test # run the tests
- 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` and `exitswap` methods (avoid single-token math precision issues)

## Features on BCoWPool (added via inheritance to BPool)
- Immutably stores CoW Protocol's `SolutionSettler` and `VaultRelayer` addresses at deployment
Expand All @@ -49,8 +50,9 @@ yarn test # run the tests

## Creating a Pool
- Create a new pool by calling the corresponding pool factory:
- `IBFactory.newBPool()` for regular Balancer `BPool`s
- `IBCoWFactory.newBPool()` for Balancer `BCoWPool`s, compatible with CoW Protocol
- `IBFactory.newBPool(name, symbol)` for regular Balancer `BPool`s
- `IBCoWFactory.newBPool(name, symbol)` for Balancer `BCoWPool`s, compatible with CoW Protocol
> Being `name` and `symbol` 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)
Expand All @@ -60,14 +62,14 @@ yarn test # run the tests

# Deployments
Ethereum Mainnet:
- BCoWFactory: [0x5AC134DAC7070eFeE8b1C5e3fD0B353922ceD843](https://etherscan.io/address/0x5AC134DAC7070eFeE8b1C5e3fD0B353922ceD843)
- BCoWHelper: [0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624](https://etherscan.io/address/0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624)
- BCoWFactory: [0xf76c421bAb7df8548604E60deCCcE50477C10462](https://etherscan.io/address/0xf76c421bAb7df8548604E60deCCcE50477C10462)
- BCoWHelper: [0x3FF0041A614A9E6Bf392cbB961C97DA214E9CB31](https://etherscan.io/address/0x3FF0041A614A9E6Bf392cbB961C97DA214E9CB31)

Ethereum Sepolia:
- BCoWFactory: [0xf3916A8567DdC51a60208B35AC542F5226f46773](https://sepolia.etherscan.io/address/0xf3916A8567DdC51a60208B35AC542F5226f46773)
- BCoWHelper: [0x55DDf396886C85e443E0B5A8E42CAA3939E4Cf50](https://sepolia.etherscan.io/address/0x55DDf396886C85e443E0B5A8E42CAA3939E4Cf50)
- BCoWPool: [0x60048091401F27117C3DFb8136c1ec550D949B12](https://sepolia.etherscan.io/address/0x60048091401F27117C3DFb8136c1ec550D949B12)
- BCoWFactory: [0x1E3D76AC2BB67a2D7e8395d3A624b30AA9056DF9](https://sepolia.etherscan.io/address/0x1E3D76AC2BB67a2D7e8395d3A624b30AA9056DF9)
- BCoWHelper: [0xf5CEd4769ce2c90dfE0084320a0abfB9d99FB91D](https://sepolia.etherscan.io/address/0xf5CEd4769ce2c90dfE0084320a0abfB9d99FB91D)
- BCoWPool: [0xE4aBfDa4E8c02fcAfC34981daFAeb426AA4186e6](https://sepolia.etherscan.io/address/0xE4aBfDa4E8c02fcAfC34981daFAeb426AA4186e6)

Gnosis Mainnet:
- BCoWFactory: [0xaD0447be7BDC80cf2e6DA20B13599E5dc859b667](https://gnosisscan.io/address/0xaD0447be7BDC80cf2e6DA20B13599E5dc859b667)
- BCoWHelper: [0x21Ac2E4115429EcE4b5FE79409fCC48EB6315Ccc](https://gnosisscan.io/address/0x21Ac2E4115429EcE4b5FE79409fCC48EB6315Ccc)
- BCoWFactory: [0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624](https://gnosisscan.io/address/0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624)
- BCoWHelper: [0x198B6F66dE03540a164ADCA4eC5db2789Fbd4751](https://gnosisscan.io/address/0x198B6F66dE03540a164ADCA4eC5db2789Fbd4751)
3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}]
# 2018: function can be view, so far only caused by mocks
# 2394: solc insists on reporting on every transient storage use
# 5574, 3860: bytecode size limit, so far only caused by test contracts
ignored_error_codes = [2018, 2394, 5574, 3860]
# 1878: Some imports don't have the license identifier
ignored_error_codes = [2018, 2394, 5574, 3860, 1878]
deny_warnings = true

[profile.optimized]
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "balancer-cow-amm",
"version": "1.0.0",
"version": "1.4.0",
"private": true,
"description": "Balancer CoW AMM",
"homepage": "https://github.com/balancer/cow-amm#readme",
Expand All @@ -16,12 +16,9 @@
"build": "forge build",
"build:optimized": "FOUNDRY_PROFILE=optimized forge build",
"coverage": "forge coverage --match-path 'test/unit/**'",
"deploy:bcowfactory:gnosis": "forge script DeployBCoWFactory -vvvvv --rpc-url $GNOSIS_RPC --broadcast --chain gnosis --private-key $GNOSIS_DEPLOYER_PK --verify",
"deploy:bcowfactory:mainnet": "forge script DeployBCoWFactory -vvvvv --rpc-url $MAINNET_RPC --broadcast --chain mainnet --private-key $MAINNET_DEPLOYER_PK --verify",
"deploy:bcowfactory:testnet": "forge script DeployBCoWFactory -vvvvv --rpc-url $SEPOLIA_RPC --broadcast --chain sepolia --private-key $SEPOLIA_DEPLOYER_PK --verify",
"deploy:bfactory:gnosis": "forge script DeployBFactory -vvvvv --rpc-url $GNOSIS_RPC --broadcast --chain gnosis --private-key $GNOSIS_DEPLOYER_PK --verify",
"deploy:bfactory:mainnet": "forge script DeployBFactory -vvvvv --rpc-url $MAINNET_RPC --broadcast --chain mainnet --private-key $MAINNET_DEPLOYER_PK --verify",
"deploy:bfactory:testnet": "forge script DeployBFactory -vvvvv --rpc-url $SEPOLIA_RPC --broadcast --chain sepolia --private-key $SEPOLIA_DEPLOYER_PK --verify",
"deploy:gnosis": "forge script DeployBCoWFactory -vvvvv --rpc-url $GNOSIS_RPC --broadcast --chain gnosis --private-key $GNOSIS_DEPLOYER_PK --verify",
"deploy:mainnet": "forge script DeployBCoWFactory -vvvvv --rpc-url $MAINNET_RPC --broadcast --chain mainnet --private-key $MAINNET_DEPLOYER_PK --verify",
"deploy:testnet": "forge script DeployBCoWFactory -vvvvv --rpc-url $SEPOLIA_RPC --broadcast --chain sepolia --private-key $SEPOLIA_DEPLOYER_PK --verify",
"lint:bulloak": "find test/unit -name '*.tree' | xargs bulloak check",
"lint:check": "solhint 'src/**/*.sol' 'test/**/*.sol' 'script/**/*.sol' && forge fmt --check",
"lint:fix": "solhint --fix 'src/**/*.sol' 'test/**/*.sol' 'script/**/*.sol' && sort-package-json && forge fmt",
Expand All @@ -32,9 +29,10 @@
"script:testnet": "forge script TestnetScript -vvvvv --rpc-url $SEPOLIA_RPC --broadcast --chain sepolia --private-key $SEPOLIA_DEPLOYER_PK --verify",
"smock": "smock-foundry --contracts src/contracts",
"test": "yarn test:integration && yarn test:unit",
"test:echidna": "find test/invariants/fuzz -regex '.*\\.t\\.sol$' |cut -d '/' -f 4 | cut -d . -f 1 |xargs -I{} echidna test/invariants/fuzz/{}.t.sol --contract Fuzz{} --config test/invariants/fuzz/{}.yaml",
"test:integration": "forge test --ffi --match-path 'test/integration/**' -vvv --isolate",
"test:local": "FOUNDRY_FUZZ_RUNS=100 forge test -vvv",
"test:scaffold": "bulloak check --fix test/unit/*.tree && forge fmt",
"test:scaffold": "bulloak check --fix test/unit/**/*.tree && forge fmt",
"test:unit": "forge test --match-path 'test/unit/**' -vvv",
"test:unit:deep": "FOUNDRY_FUZZ_RUNS=5000 yarn test:unit"
},
Expand All @@ -45,6 +43,7 @@
},
"dependencies": {
"@cowprotocol/contracts": "github:cowprotocol/contracts.git#a10f40788a",
"@crytic/properties": "https://github.com/crytic/properties.git",
"@openzeppelin/contracts": "5.0.2",
"composable-cow": "github:cowprotocol/composable-cow.git#24d556b",
"cow-amm": "github:cowprotocol/cow-amm.git#6566128",
Expand All @@ -56,7 +55,8 @@
"@defi-wonderland/natspec-smells": "1.1.3",
"@defi-wonderland/smock-foundry": "1.5.0",
"forge-gas-snapshot": "github:marktoda/forge-gas-snapshot#9161f7c",
"forge-std": "github:foundry-rs/forge-std#5475f85",
"forge-std": "github:foundry-rs/forge-std#1.8.2",
"halmos-cheatcodes": "github:a16z/halmos-cheatcodes#c0d8655",
"husky": ">=8",
"lint-staged": ">=10",
"solhint-community": "4.0.0",
Expand Down
2 changes: 2 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ cowprotocol/=node_modules/@cowprotocol/contracts/src/
@composable-cow/=node_modules/composable-cow/
@cow-amm/=node_modules/cow-amm/src
lib/openzeppelin/=node_modules/@openzeppelin
halmos-cheatcodes=node_modules/halmos-cheatcodes
@crytic/=node_modules/@crytic/

contracts/=src/contracts
interfaces/=src/interfaces
Expand Down
12 changes: 6 additions & 6 deletions script/Registry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ abstract contract Registry is Params {
constructor(uint256 chainId) Params(chainId) {
if (chainId == 1) {
// Ethereum Mainnet
bCoWFactory = BCoWFactory(0x5AC134DAC7070eFeE8b1C5e3fD0B353922ceD843);
bCoWHelper = BCoWHelper(0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624);
bCoWFactory = BCoWFactory(0xf76c421bAb7df8548604E60deCCcE50477C10462);
bCoWHelper = BCoWHelper(0x3FF0041A614A9E6Bf392cbB961C97DA214E9CB31);
} else if (chainId == 100) {
// Gnosis Mainnet
bCoWFactory = BCoWFactory(0xaD0447be7BDC80cf2e6DA20B13599E5dc859b667);
bCoWHelper = BCoWHelper(0x21Ac2E4115429EcE4b5FE79409fCC48EB6315Ccc);
bCoWFactory = BCoWFactory(0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624);
bCoWHelper = BCoWHelper(0x198B6F66dE03540a164ADCA4eC5db2789Fbd4751);
} else if (chainId == 11_155_111) {
// Ethereum Sepolia [Testnet]
bCoWFactory = BCoWFactory(0xf3916A8567DdC51a60208B35AC542F5226f46773);
bCoWHelper = BCoWHelper(0x55DDf396886C85e443E0B5A8E42CAA3939E4Cf50);
bCoWFactory = BCoWFactory(0x1E3D76AC2BB67a2D7e8395d3A624b30AA9056DF9);
bCoWHelper = BCoWHelper(0xf5CEd4769ce2c90dfE0084320a0abfB9d99FB91D);
} else {
revert('Registry: unknown chain ID');
}
Expand Down
5 changes: 4 additions & 1 deletion script/Script.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ contract TestnetScript is BaseScript {
IFaucet(_SEPOLIA_FAUCET).drip(_SEPOLIA_DAI_TOKEN);
IFaucet(_SEPOLIA_FAUCET).drip(_SEPOLIA_USDC_TOKEN);

IBPool bPool = bCoWFactory.newBPool();
string memory name = 'Balancer CoWAMM Pool';
string memory symbol = 'BPT';

IBPool bPool = bCoWFactory.newBPool(name, symbol);

IERC20(_SEPOLIA_BAL_TOKEN).approve(address(bPool), type(uint256).max);
IERC20(_SEPOLIA_DAI_TOKEN).approve(address(bPool), type(uint256).max);
Expand Down
6 changes: 4 additions & 2 deletions src/contracts/BCoWFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ contract BCoWFactory is BFactory, IBCoWFactory {

/**
* @dev Deploys a BCoWPool instead of a regular BPool.
* @param name The name of the Pool ERC20 token
* @param symbol The symbol of the Pool ERC20 token
* @return bCoWPool The deployed BCoWPool
*/
function _newBPool() internal virtual override returns (IBPool bCoWPool) {
bCoWPool = new BCoWPool(SOLUTION_SETTLER, APP_DATA);
function _newBPool(string memory name, string memory symbol) internal virtual override returns (IBPool bCoWPool) {
bCoWPool = new BCoWPool(SOLUTION_SETTLER, APP_DATA, name, symbol);
}
}
15 changes: 12 additions & 3 deletions src/contracts/BCoWPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {BPool} from './BPool.sol';
import {GPv2Order} from '@cowprotocol/libraries/GPv2Order.sol';
import {IERC1271} from '@openzeppelin/contracts/interfaces/IERC1271.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

import {IBCoWFactory} from 'interfaces/IBCoWFactory.sol';
import {IBCoWPool} from 'interfaces/IBCoWPool.sol';
Expand All @@ -33,6 +34,7 @@ import {ISettlement} from 'interfaces/ISettlement.sol';
*/
contract BCoWPool is IERC1271, IBCoWPool, BPool, BCoWConst {
using GPv2Order for GPv2Order.Data;
using SafeERC20 for IERC20;

/// @inheritdoc IBCoWPool
address public immutable VAULT_RELAYER;
Expand All @@ -46,7 +48,14 @@ contract BCoWPool is IERC1271, IBCoWPool, BPool, BCoWConst {
/// @inheritdoc IBCoWPool
bytes32 public immutable APP_DATA;

constructor(address cowSolutionSettler, bytes32 appData) BPool() {
constructor(
address cowSolutionSettler,
bytes32 appData,
// solhint-disable-next-line no-unused-vars
string memory name,
// solhint-disable-next-line no-unused-vars
string memory symbol
) BPool(name, symbol) {
SOLUTION_SETTLER = ISettlement(cowSolutionSettler);
SOLUTION_SETTLER_DOMAIN_SEPARATOR = ISettlement(cowSolutionSettler).domainSeparator();
VAULT_RELAYER = ISettlement(cowSolutionSettler).vaultRelayer();
Expand Down Expand Up @@ -136,10 +145,10 @@ contract BCoWPool is IERC1271, IBCoWPool, BPool, BCoWConst {
* @dev Grants infinite approval to the vault relayer for all tokens in the
* pool after the finalization of the setup. Also emits COWAMMPoolCreated() event.
*/
function _afterFinalize() internal override {
function _afterFinalize() internal virtual override {
uint256 tokensLength = _tokens.length;
for (uint256 i; i < tokensLength; i++) {
IERC20(_tokens[i]).approve(VAULT_RELAYER, type(uint256).max);
IERC20(_tokens[i]).forceApprove(VAULT_RELAYER, type(uint256).max);
}

// Make the factory emit the event, to be easily indexed by off-chain agents
Expand Down
12 changes: 7 additions & 5 deletions src/contracts/BFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ contract BFactory is IBFactory {
}

/// @inheritdoc IBFactory
function newBPool() external returns (IBPool bPool) {
bPool = _newBPool();
function newBPool(string memory name, string memory symbol) external returns (IBPool bPool) {
bPool = _newBPool(name, symbol);
_isBPool[address(bPool)] = true;
emit LOG_NEW_POOL(msg.sender, address(bPool));
bPool.setController(msg.sender);
Expand All @@ -42,7 +42,7 @@ contract BFactory is IBFactory {
}

/// @inheritdoc IBFactory
function collect(IBPool bPool) external {
function collect(IBPool bPool) external virtual {
if (msg.sender != _bDao) {
revert BFactory_NotBDao();
}
Expand All @@ -62,10 +62,12 @@ contract BFactory is IBFactory {

/**
* @notice Deploys a new BPool.
* @param name The name of the Pool ERC20 token
* @param symbol The symbol of the Pool ERC20 token
* @dev Internal function to allow overriding in derived contracts.
* @return bPool The deployed BPool
*/
function _newBPool() internal virtual returns (IBPool bPool) {
bPool = new BPool();
function _newBPool(string memory name, string memory symbol) internal virtual returns (IBPool bPool) {
bPool = new BPool(name, symbol);
}
}
Loading

0 comments on commit 04c915d

Please sign in to comment.