Skip to content

Commit

Permalink
feat: adding erc20 name and symbol to constructor (#182)
Browse files Browse the repository at this point in the history
* feat: adding erc20 name and symbol to constructor

* fix: added natspec params
  • Loading branch information
wei3erHase authored Jul 31, 2024
1 parent 3087ec0 commit f1fe830
Show file tree
Hide file tree
Showing 30 changed files with 117 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4200675
4314884
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3397437
3401020
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"test": "yarn test:integration && yarn test:unit",
"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
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);
}
}
9 changes: 8 additions & 1 deletion src/contracts/BCoWPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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
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
6 changes: 4 additions & 2 deletions test/unit/BCoWFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ contract BCoWFactoryTest is Test {
address public factoryDeployer = makeAddr('factoryDeployer');
address public solutionSettler = makeAddr('solutionSettler');
bytes32 public appData = bytes32('appData');
string constant ERC20_NAME = 'Balancer Pool Token';
string constant ERC20_SYMBOL = 'BPT';

MockBCoWFactory factory;

Expand All @@ -37,10 +39,10 @@ contract BCoWFactoryTest is Test {

function test__newBPoolWhenCalled() external {
vm.prank(address(factory));
bytes memory _expectedCode = address(new BCoWPool(solutionSettler, appData)).code; // NOTE: uses nonce 1
bytes memory _expectedCode = address(new BCoWPool(solutionSettler, appData, ERC20_NAME, ERC20_SYMBOL)).code; // NOTE: uses nonce 1
address _futurePool = vm.computeCreateAddress(address(factory), 2);

IBCoWPool _newPool = IBCoWPool(address(factory.call__newBPool()));
IBCoWPool _newPool = IBCoWPool(address(factory.call__newBPool(ERC20_NAME, ERC20_SYMBOL)));
assertEq(address(_newPool), _futurePool);
// it should set the new BCoWPool solution settler
assertEq(address(_newPool.SOLUTION_SETTLER()), solutionSettler);
Expand Down
4 changes: 3 additions & 1 deletion test/unit/BCoWHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ contract BCoWHelperTest is Test {

uint256 constant VALID_WEIGHT = 1e18;
uint256 constant BASE = 1e18;
string constant ERC20_NAME = 'Balancer Pool Token';
string constant ERC20_SYMBOL = 'BPT';

function setUp() external {
factory = new MockBCoWFactory(address(0), bytes32(0));
Expand All @@ -39,7 +41,7 @@ contract BCoWHelperTest is Test {
vm.mockCall(
solutionSettler, abi.encodePacked(ISettlement.vaultRelayer.selector), abi.encode(makeAddr('vaultRelayer'))
);
pool = new MockBCoWPool(makeAddr('solutionSettler'), bytes32(0));
pool = new MockBCoWPool(makeAddr('solutionSettler'), bytes32(0), ERC20_NAME, ERC20_SYMBOL);

// creating a valid pool setup
factory.mock_call_isBPool(address(pool), true);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BCoWPool/BCoWPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract BCoWPool is BCoWPoolBase {
vm.expectCall(_settler, abi.encodePacked(ISettlement.domainSeparator.selector));
// it should query the solution settler for the vault relayer
vm.expectCall(_settler, abi.encodePacked(ISettlement.vaultRelayer.selector));
MockBCoWPool pool = new MockBCoWPool(_settler, _appData);
MockBCoWPool pool = new MockBCoWPool(_settler, _appData, ERC20_NAME, ERC20_SYMBOL);
// it should set the solution settler
assertEq(address(pool.SOLUTION_SETTLER()), _settler);
// it should set the domain separator
Expand Down
4 changes: 2 additions & 2 deletions test/unit/BCoWPool/BCoWPool.tree
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BCoWPool::Constructor
BCoWPool::constructor
└── when called
├── it should set the solution settler
├── it should query the solution settler for the domain separator
Expand All @@ -16,7 +16,7 @@ BCoWPool::_afterFinalize
└── when factorys logBCoWPool reverts
└── it emits a COWAMMPoolCreated event

BCoWPool::Commit
BCoWPool::commit
├── when reentrancy lock is set
│ └──it should revert
├── when sender is not solution settler
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BCoWPool/BCoWPoolBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ contract BCoWPoolBase is BPoolBase, BCoWConst, BNum {
super.setUp();
vm.mockCall(cowSolutionSettler, abi.encodePacked(ISettlement.domainSeparator.selector), abi.encode(domainSeparator));
vm.mockCall(cowSolutionSettler, abi.encodePacked(ISettlement.vaultRelayer.selector), abi.encode(vaultRelayer));
bCoWPool = new MockBCoWPool(cowSolutionSettler, appData);
bCoWPool = new MockBCoWPool(cowSolutionSettler, appData, ERC20_NAME, ERC20_SYMBOL);
}
}
Loading

0 comments on commit f1fe830

Please sign in to comment.