Skip to content

Commit

Permalink
Merge branch 'dev' into feat/fuzz-symb-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase authored Aug 1, 2024
2 parents df49eb9 + cee8050 commit 7bbb6cc
Show file tree
Hide file tree
Showing 32 changed files with 180 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4200675
4360005
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3397437
3442739
2 changes: 1 addition & 1 deletion .forge-snapshots/newBFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3442127
3564561
2 changes: 1 addition & 1 deletion .forge-snapshots/newBPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2841995
2845617
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ yarn test # run the tests

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

Ethereum Sepolia:
- BCoWFactory: [0xF3F089AF5FaAF8784B445593B3bd8A514EaA3433 ](https://sepolia.etherscan.io/address/0xF3F089AF5FaAF8784B445593B3bd8A514EaA3433 )
- BCoWHelper: [0x07E7E9e3f4E715Ef1434b7f865fedBCE82Dd41Ba](https://sepolia.etherscan.io/address/0x07E7E9e3f4E715Ef1434b7f865fedBCE82Dd41Ba)
- BCoWPool: [0x4Cc911897fFCC5553627d454533D944F1D78CBdE](https://sepolia.etherscan.io/address/0x4Cc911897fFCC5553627d454533D944F1D78CBdE)
- 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: [0x7573B99BC09c11Dc0427fb9c6662bc603E008304](https://gnosisscan.io/address/0x7573B99BC09c11Dc0427fb9c6662bc603E008304)
- BCoWHelper: [0x85315994492E88D6faCd3B0E3585c68A4720627e](https://gnosisscan.io/address/0x85315994492E88D6faCd3B0E3585c68A4720627e)
- BCoWFactory: [0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624](https://gnosisscan.io/address/0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624)
- BCoWHelper: [0x198B6F66dE03540a164ADCA4eC5db2789Fbd4751](https://gnosisscan.io/address/0x198B6F66dE03540a164ADCA4eC5db2789Fbd4751)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"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 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(0x23fcC2166F991B8946D195de53745E1b804C91B7);
bCoWHelper = BCoWHelper(0x5F6e7D3ef6e9aedD21C107BF8faA610f1215C730);
bCoWFactory = BCoWFactory(0xf76c421bAb7df8548604E60deCCcE50477C10462);
bCoWHelper = BCoWHelper(0x3FF0041A614A9E6Bf392cbB961C97DA214E9CB31);
} else if (chainId == 100) {
// Gnosis Mainnet
bCoWFactory = BCoWFactory(0x7573B99BC09c11Dc0427fb9c6662bc603E008304);
bCoWHelper = BCoWHelper(0x85315994492E88D6faCd3B0E3585c68A4720627e);
bCoWFactory = BCoWFactory(0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624);
bCoWHelper = BCoWHelper(0x198B6F66dE03540a164ADCA4eC5db2789Fbd4751);
} else if (chainId == 11_155_111) {
// Ethereum Sepolia [Testnet]
bCoWFactory = BCoWFactory(0xF3F089AF5FaAF8784B445593B3bd8A514EaA3433);
bCoWHelper = BCoWHelper(0x07E7E9e3f4E715Ef1434b7f865fedBCE82Dd41Ba);
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);
}
}
13 changes: 11 additions & 2 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 @@ -139,7 +148,7 @@ contract BCoWPool is IERC1271, IBCoWPool, BPool, BCoWConst {
function _afterFinalize() internal 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
10 changes: 6 additions & 4 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 Down Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion src/contracts/BPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ contract BPool is BToken, BMath, IBPool {
_;
}

constructor() {
// solhint-disable-next-line no-unused-vars
constructor(string memory name, string memory symbol) BToken(name, symbol) {
_controller = msg.sender;
FACTORY = msg.sender;
_swapFee = MIN_FEE;
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/BToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';
* @notice Balancer Pool Token base contract, providing ERC20 functionality.
*/
contract BToken is ERC20 {
constructor() ERC20('Balancer Pool Token', 'BPT') {}
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}

/**
* @notice Increase the allowance of the spender.
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/IBFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ interface IBFactory {

/**
* @notice Creates a new BPool, assigning the caller as the pool controller
* @param name The name of the Pool ERC20 token
* @param symbol The symbol of the Pool ERC20 token
* @return bPool The new BPool
*/
function newBPool() external returns (IBPool bPool);
function newBPool(string memory name, string memory symbol) external returns (IBPool bPool);

/**
* @notice Sets the BDao address in the factory
Expand Down
7 changes: 5 additions & 2 deletions test/integration/BCoWHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ contract BCoWHelperIntegrationTest is Test {
uint256 constant SKEWENESS_RATIO = 95; // -5% skewness
uint256 constant EXPECTED_FINAL_SPOT_PRICE = INITIAL_SPOT_PRICE * 100 / SKEWENESS_RATIO;

string constant ERC20_NAME = 'Balancer Pool Token';
string constant ERC20_SYMBOL = 'BPT';

function setUp() public {
vm.createSelectFork('mainnet', 20_012_063);

Expand All @@ -61,8 +64,8 @@ contract BCoWHelperIntegrationTest is Test {
deal(address(WETH), lp, type(uint256).max, false);

vm.startPrank(lp);
basicPool = ammFactory.newBPool();
weightedPool = ammFactory.newBPool();
basicPool = ammFactory.newBPool(ERC20_NAME, ERC20_SYMBOL);
weightedPool = ammFactory.newBPool(ERC20_NAME, ERC20_SYMBOL);

DAI.approve(address(basicPool), type(uint256).max);
WETH.approve(address(basicPool), type(uint256).max);
Expand Down
5 changes: 4 additions & 1 deletion test/integration/BPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ abstract contract BPoolIntegrationTest is Test, GasSnapshot {
uint256 public constant WETH_OUT_AMOUNT = 94_049_266_814_811_022; // 0.094 ETH
uint256 public constant DAI_OUT_AMOUNT_INVERSE = 94_183_552_501_642_552_000; // 94.1 DAI

string constant ERC20_NAME = 'Balancer Pool Token';
string constant ERC20_SYMBOL = 'BPT';

function setUp() public virtual {
vm.createSelectFork('mainnet', 20_012_063);

factory = _deployFactory();

vm.startPrank(lp);
pool = factory.newBPool();
pool = factory.newBPool(ERC20_NAME, ERC20_SYMBOL);

deal(address(dai), lp, DAI_LP_AMOUNT);
deal(address(weth), lp, WETH_LP_AMOUNT);
Expand Down
7 changes: 5 additions & 2 deletions test/integration/DeploymentGas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ contract DeploymentIntegrationGasTest is Test, GasSnapshot {
address solutionSettler;
address deployer = makeAddr('deployer');

string constant ERC20_NAME = 'Balancer Pool Token';
string constant ERC20_SYMBOL = 'BPT';

function setUp() public {
vm.startPrank(deployer);
bFactory = new BFactory();
Expand All @@ -38,11 +41,11 @@ contract DeploymentIntegrationGasTest is Test, GasSnapshot {

function testPoolDeployment() public {
snapStart('newBPool');
bFactory.newBPool();
bFactory.newBPool(ERC20_NAME, ERC20_SYMBOL);
snapEnd();

snapStart('newBCoWPool');
bCowFactory.newBPool();
bCowFactory.newBPool(ERC20_NAME, ERC20_SYMBOL);
snapEnd();
}
}
23 changes: 12 additions & 11 deletions test/manual-smock/MockBCoWFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,24 @@ contract MockBCoWFactory is BCoWFactory, Test {
vm.mockCall(address(this), abi.encodeWithSignature('logBCoWPool()'), abi.encode());
}

function mock_call__newBPool(IBPool bCoWPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('_newBPool()'), abi.encode(bCoWPool));
function mock_call__newBPool(string memory name, string memory symbol, IBPool bCoWPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('_newBPool(string,string)', name, symbol), abi.encode(bCoWPool));
}

function _newBPool() internal override returns (IBPool bCoWPool) {
(bool _success, bytes memory _data) = address(this).call(abi.encodeWithSignature('_newBPool()'));
function _newBPool(string memory name, string memory symbol) internal override returns (IBPool bCoWPool) {
(bool _success, bytes memory _data) =
address(this).call(abi.encodeWithSignature('_newBPool(string,string)', name, symbol));

if (_success) return abi.decode(_data, (IBPool));
else return super._newBPool();
else return super._newBPool(name, symbol);
}

function call__newBPool() public returns (IBPool bCoWPool) {
return _newBPool();
function call__newBPool(string memory name, string memory symbol) public returns (IBPool bCoWPool) {
return _newBPool(name, symbol);
}

function expectCall__newBPool() public {
vm.expectCall(address(this), abi.encodeWithSignature('_newBPool()'));
function expectCall__newBPool(string memory name, string memory symbol) public {
vm.expectCall(address(this), abi.encodeWithSignature('_newBPool(string,string)', name, symbol));
}

// MockBFactory methods
Expand All @@ -57,8 +58,8 @@ contract MockBCoWFactory is BCoWFactory, Test {
return _bDao;
}

function mock_call_newBPool(IBPool bPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('newBPool()'), abi.encode(bPool));
function mock_call_newBPool(string memory name, string memory symbol, IBPool bPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('newBPool(string,string)', name, symbol), abi.encode(bPool));
}

function mock_call_setBDao(address bDao) public {
Expand Down
7 changes: 6 additions & 1 deletion test/manual-smock/MockBCoWPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ contract MockBCoWPool is BCoWPool, Test {
}

/// MockBCoWPool mock methods
constructor(address cowSolutionSettler, bytes32 appData) BCoWPool(cowSolutionSettler, appData) {}
constructor(
address cowSolutionSettler,
bytes32 appData,
string memory name,
string memory symbol
) BCoWPool(cowSolutionSettler, appData, name, symbol) {}

function mock_call_commit(bytes32 orderHash) public {
vm.mockCall(address(this), abi.encodeWithSignature('commit(bytes32)', orderHash), abi.encode());
Expand Down
23 changes: 12 additions & 11 deletions test/smock/MockBFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ contract MockBFactory is BFactory, Test {

constructor() BFactory() {}

function mock_call_newBPool(IBPool bPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('newBPool()'), abi.encode(bPool));
function mock_call_newBPool(string memory name, string memory symbol, IBPool bPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('newBPool(string,string)', name, symbol), abi.encode(bPool));
}

function mock_call_setBDao(address bDao) public {
Expand All @@ -43,22 +43,23 @@ contract MockBFactory is BFactory, Test {
vm.mockCall(address(this), abi.encodeWithSignature('getBDao()'), abi.encode(_returnParam0));
}

function mock_call__newBPool(IBPool bPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('_newBPool()'), abi.encode(bPool));
function mock_call__newBPool(string memory name, string memory symbol, IBPool bPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('_newBPool(string,string)', name, symbol), abi.encode(bPool));
}

function _newBPool() internal override returns (IBPool bPool) {
(bool _success, bytes memory _data) = address(this).call(abi.encodeWithSignature('_newBPool()'));
function _newBPool(string memory name, string memory symbol) internal override returns (IBPool bPool) {
(bool _success, bytes memory _data) =
address(this).call(abi.encodeWithSignature('_newBPool(string,string)', name, symbol));

if (_success) return abi.decode(_data, (IBPool));
else return super._newBPool();
else return super._newBPool(name, symbol);
}

function call__newBPool() public returns (IBPool bPool) {
return _newBPool();
function call__newBPool(string memory name, string memory symbol) public returns (IBPool bPool) {
return _newBPool(name, symbol);
}

function expectCall__newBPool() public {
vm.expectCall(address(this), abi.encodeWithSignature('_newBPool()'));
function expectCall__newBPool(string memory name, string memory symbol) public {
vm.expectCall(address(this), abi.encodeWithSignature('_newBPool(string,string)', name, symbol));
}
}
2 changes: 1 addition & 1 deletion test/smock/MockBPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract MockBPool is BPool, Test {
return _totalWeight;
}

constructor() BPool() {}
constructor(string memory name, string memory symbol) BPool(name, symbol) {}

function mock_call_setSwapFee(uint256 swapFee) public {
vm.mockCall(address(this), abi.encodeWithSignature('setSwapFee(uint256)', swapFee), abi.encode());
Expand Down
2 changes: 1 addition & 1 deletion test/smock/MockBToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {BToken, ERC20} from '../../src/contracts/BToken.sol';
import {Test} from 'forge-std/Test.sol';

contract MockBToken is BToken, Test {
constructor() BToken() {}
constructor(string memory name, string memory symbol) BToken(name, symbol) {}

function mock_call_increaseApproval(address spender, uint256 amount, bool success) public {
vm.mockCall(
Expand Down
Loading

0 comments on commit 7bbb6cc

Please sign in to comment.