diff --git a/.forge-snapshots/newBCoWFactory.snap b/.forge-snapshots/newBCoWFactory.snap new file mode 100644 index 00000000..5f4e5d08 --- /dev/null +++ b/.forge-snapshots/newBCoWFactory.snap @@ -0,0 +1 @@ +4890648 \ No newline at end of file diff --git a/.forge-snapshots/newBCoWPool.snap b/.forge-snapshots/newBCoWPool.snap new file mode 100644 index 00000000..5c3c9e3f --- /dev/null +++ b/.forge-snapshots/newBCoWPool.snap @@ -0,0 +1 @@ +4034907 \ No newline at end of file diff --git a/.forge-snapshots/newBFactory.snap b/.forge-snapshots/newBFactory.snap index 95e984ca..d28ec6cf 100644 --- a/.forge-snapshots/newBFactory.snap +++ b/.forge-snapshots/newBFactory.snap @@ -1 +1 @@ -4130621 \ No newline at end of file +4131877 \ No newline at end of file diff --git a/.forge-snapshots/newBPool.snap b/.forge-snapshots/newBPool.snap index 0f67b99b..e4fc526d 100644 --- a/.forge-snapshots/newBPool.snap +++ b/.forge-snapshots/newBPool.snap @@ -1 +1 @@ -3477592 \ No newline at end of file +3478592 \ No newline at end of file diff --git a/.forge-snapshots/swapExactAmountIn.snap b/.forge-snapshots/swapExactAmountIn.snap index 6273edbd..ec541304 100644 --- a/.forge-snapshots/swapExactAmountIn.snap +++ b/.forge-snapshots/swapExactAmountIn.snap @@ -1 +1 @@ -104914 \ No newline at end of file +104920 \ No newline at end of file diff --git a/.forge-snapshots/swapExactAmountInInverse.snap b/.forge-snapshots/swapExactAmountInInverse.snap index e2f5743c..004cff8a 100644 --- a/.forge-snapshots/swapExactAmountInInverse.snap +++ b/.forge-snapshots/swapExactAmountInInverse.snap @@ -1 +1 @@ -114583 \ No newline at end of file +114589 \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b0cee1d..fb56bc60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,20 +18,20 @@ jobs: - uses: actions/checkout@v3 - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 + uses: foundry-rs/foundry-toolchain@v1.2.0 with: version: nightly - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 20.x cache: 'yarn' - name: Install dependencies run: yarn --frozen-lockfile --network-concurrency 1 - - name: Precompile using 0.8.14 and via-ir=false + - name: Precompile contracts run: yarn build - name: Run tests @@ -45,20 +45,20 @@ jobs: - uses: actions/checkout@v3 - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 + uses: foundry-rs/foundry-toolchain@v1.2.0 with: version: nightly - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 20.x cache: 'yarn' - name: Install dependencies run: yarn --frozen-lockfile --network-concurrency 1 - - name: Precompile using 0.8.14 and via-ir=false + - name: Precompile contracts run: yarn build - name: Run tests @@ -77,14 +77,14 @@ jobs: - uses: wagoid/commitlint-github-action@v5 - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 + uses: foundry-rs/foundry-toolchain@v1.2.0 with: version: nightly - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 20.x cache: 'yarn' - name: Install bulloak diff --git a/src/contracts/BPool.sol b/src/contracts/BPool.sol index 2af48596..7db5cc73 100644 --- a/src/contracts/BPool.sol +++ b/src/contracts/BPool.sol @@ -280,8 +280,6 @@ contract BPool is BToken, BMath, IBPool { _pullUnderlying(tokenIn, msg.sender, tokenAmountIn); _pushUnderlying(tokenOut, msg.sender, tokenAmountOut); - - return (tokenAmountOut, spotPriceAfter); } /// @inheritdoc IBPool @@ -339,8 +337,6 @@ contract BPool is BToken, BMath, IBPool { _pullUnderlying(tokenIn, msg.sender, tokenAmountIn); _pushUnderlying(tokenOut, msg.sender, tokenAmountOut); - - return (tokenAmountIn, spotPriceAfter); } /// @inheritdoc IBPool @@ -370,8 +366,6 @@ contract BPool is BToken, BMath, IBPool { _mintPoolShare(poolAmountOut); _pushPoolShare(msg.sender, poolAmountOut); _pullUnderlying(tokenIn, msg.sender, tokenAmountIn); - - return poolAmountOut; } /// @inheritdoc IBPool @@ -405,8 +399,6 @@ contract BPool is BToken, BMath, IBPool { _mintPoolShare(poolAmountOut); _pushPoolShare(msg.sender, poolAmountOut); _pullUnderlying(tokenIn, msg.sender, tokenAmountIn); - - return tokenAmountIn; } /// @inheritdoc IBPool @@ -440,8 +432,6 @@ contract BPool is BToken, BMath, IBPool { _burnPoolShare(bsub(poolAmountIn, exitFee)); _pushPoolShare(FACTORY, exitFee); _pushUnderlying(tokenOut, msg.sender, tokenAmountOut); - - return tokenAmountOut; } /// @inheritdoc IBPool @@ -477,12 +467,10 @@ contract BPool is BToken, BMath, IBPool { _burnPoolShare(bsub(poolAmountIn, exitFee)); _pushPoolShare(FACTORY, exitFee); _pushUnderlying(tokenOut, msg.sender, tokenAmountOut); - - return poolAmountIn; } /// @inheritdoc IBPool - function getSpotPrice(address tokenIn, address tokenOut) external view _viewlock_ returns (uint256 spotPrice) { + function getSpotPrice(address tokenIn, address tokenOut) external view _viewlock_ returns (uint256) { if (!_records[tokenIn].bound) { revert BPool_TokenNotBound(); } @@ -492,19 +480,17 @@ contract BPool is BToken, BMath, IBPool { Record storage inRecord = _records[tokenIn]; Record storage outRecord = _records[tokenOut]; - spotPrice = calcSpotPrice( + return calcSpotPrice( IERC20(tokenIn).balanceOf(address(this)), inRecord.denorm, IERC20(tokenOut).balanceOf(address(this)), outRecord.denorm, _swapFee ); - - return spotPrice; } /// @inheritdoc IBPool - function getSpotPriceSansFee(address tokenIn, address tokenOut) external view _viewlock_ returns (uint256 spotPrice) { + function getSpotPriceSansFee(address tokenIn, address tokenOut) external view _viewlock_ returns (uint256) { if (!_records[tokenIn].bound) { revert BPool_TokenNotBound(); } @@ -514,15 +500,13 @@ contract BPool is BToken, BMath, IBPool { Record storage inRecord = _records[tokenIn]; Record storage outRecord = _records[tokenOut]; - spotPrice = calcSpotPrice( + return calcSpotPrice( IERC20(tokenIn).balanceOf(address(this)), inRecord.denorm, IERC20(tokenOut).balanceOf(address(this)), outRecord.denorm, 0 ); - - return spotPrice; } /// @inheritdoc IBPool @@ -531,8 +515,8 @@ contract BPool is BToken, BMath, IBPool { } /// @inheritdoc IBPool - function isBound(address t) external view returns (bool) { - return _records[t].bound; + function isBound(address token) external view returns (bool) { + return _records[token].bound; } /// @inheritdoc IBPool @@ -541,12 +525,12 @@ contract BPool is BToken, BMath, IBPool { } /// @inheritdoc IBPool - function getCurrentTokens() external view _viewlock_ returns (address[] memory tokens) { + function getCurrentTokens() external view _viewlock_ returns (address[] memory) { return _tokens; } /// @inheritdoc IBPool - function getFinalTokens() external view _viewlock_ _finalized_ returns (address[] memory tokens) { + function getFinalTokens() external view _viewlock_ _finalized_ returns (address[] memory) { return _tokens; } diff --git a/src/contracts/BToken.sol b/src/contracts/BToken.sol index 0491b17d..157a4440 100644 --- a/src/contracts/BToken.sol +++ b/src/contracts/BToken.sol @@ -18,7 +18,7 @@ contract BToken is ERC20 { */ function increaseApproval(address spender, uint256 amount) external returns (bool success) { _approve(msg.sender, spender, allowance(msg.sender, spender) + amount); - return true; + success = true; } /** @@ -34,7 +34,7 @@ contract BToken is ERC20 { } else { _approve(msg.sender, spender, oldValue - amount); } - return true; + success = true; } /** diff --git a/test/integration/DeploymentGas.t.sol b/test/integration/DeploymentGas.t.sol index e2b32d95..d4604024 100644 --- a/test/integration/DeploymentGas.t.sol +++ b/test/integration/DeploymentGas.t.sol @@ -1,27 +1,48 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; +import {BCoWFactory} from 'contracts/BCoWFactory.sol'; import {BFactory} from 'contracts/BFactory.sol'; import {GasSnapshot} from 'forge-gas-snapshot/GasSnapshot.sol'; import {Test} from 'forge-std/Test.sol'; +contract MockSolutionSettler { + address public vaultRelayer; + bytes32 public domainSeparator; +} + contract DeploymentIntegrationGasTest is Test, GasSnapshot { - BFactory public factory; + BFactory public bFactory; + BCoWFactory public bCowFactory; + address solutionSettler; + address deployer = makeAddr('deployer'); function setUp() public { - factory = new BFactory(); + vm.startPrank(deployer); + bFactory = new BFactory(); + + solutionSettler = address(new MockSolutionSettler()); + bCowFactory = new BCoWFactory(solutionSettler, bytes32('appData')); } function testFactoryDeployment() public { snapStart('newBFactory'); new BFactory(); snapEnd(); + + snapStart('newBCoWFactory'); + new BCoWFactory(solutionSettler, bytes32('appData')); + snapEnd(); } - function testDeployment() public { + function testPoolDeployment() public { snapStart('newBPool'); - factory.newBPool(); + bFactory.newBPool(); + snapEnd(); + + snapStart('newBCoWPool'); + bCowFactory.newBPool(); snapEnd(); } } diff --git a/test/manual-smock/MockBCoWPool.sol b/test/manual-smock/MockBCoWPool.sol index de851269..5ce2c703 100644 --- a/test/manual-smock/MockBCoWPool.sol +++ b/test/manual-smock/MockBCoWPool.sol @@ -226,17 +226,19 @@ contract MockBCoWPool is BCoWPool, Test { ); } - function mock_call_getSpotPrice(address tokenIn, address tokenOut, uint256 spotPrice) public { + function mock_call_getSpotPrice(address tokenIn, address tokenOut, uint256 _returnParam0) public { vm.mockCall( - address(this), abi.encodeWithSignature('getSpotPrice(address,address)', tokenIn, tokenOut), abi.encode(spotPrice) + address(this), + abi.encodeWithSignature('getSpotPrice(address,address)', tokenIn, tokenOut), + abi.encode(_returnParam0) ); } - function mock_call_getSpotPriceSansFee(address tokenIn, address tokenOut, uint256 spotPrice) public { + function mock_call_getSpotPriceSansFee(address tokenIn, address tokenOut, uint256 _returnParam0) public { vm.mockCall( address(this), abi.encodeWithSignature('getSpotPriceSansFee(address,address)', tokenIn, tokenOut), - abi.encode(spotPrice) + abi.encode(_returnParam0) ); } @@ -244,20 +246,20 @@ contract MockBCoWPool is BCoWPool, Test { vm.mockCall(address(this), abi.encodeWithSignature('isFinalized()'), abi.encode(_returnParam0)); } - function mock_call_isBound(address t, bool _returnParam0) public { - vm.mockCall(address(this), abi.encodeWithSignature('isBound(address)', t), abi.encode(_returnParam0)); + function mock_call_isBound(address token, bool _returnParam0) public { + vm.mockCall(address(this), abi.encodeWithSignature('isBound(address)', token), abi.encode(_returnParam0)); } function mock_call_getNumTokens(uint256 _returnParam0) public { vm.mockCall(address(this), abi.encodeWithSignature('getNumTokens()'), abi.encode(_returnParam0)); } - function mock_call_getCurrentTokens(address[] memory tokens) public { - vm.mockCall(address(this), abi.encodeWithSignature('getCurrentTokens()'), abi.encode(tokens)); + function mock_call_getCurrentTokens(address[] memory _returnParam0) public { + vm.mockCall(address(this), abi.encodeWithSignature('getCurrentTokens()'), abi.encode(_returnParam0)); } - function mock_call_getFinalTokens(address[] memory tokens) public { - vm.mockCall(address(this), abi.encodeWithSignature('getFinalTokens()'), abi.encode(tokens)); + function mock_call_getFinalTokens(address[] memory _returnParam0) public { + vm.mockCall(address(this), abi.encodeWithSignature('getFinalTokens()'), abi.encode(_returnParam0)); } function mock_call_getDenormalizedWeight(address token, uint256 _returnParam0) public { diff --git a/test/smock/MockBPool.sol b/test/smock/MockBPool.sol index a4eb6d08..4bb4ef49 100644 --- a/test/smock/MockBPool.sol +++ b/test/smock/MockBPool.sol @@ -191,17 +191,19 @@ contract MockBPool is BPool, Test { ); } - function mock_call_getSpotPrice(address tokenIn, address tokenOut, uint256 spotPrice) public { + function mock_call_getSpotPrice(address tokenIn, address tokenOut, uint256 _returnParam0) public { vm.mockCall( - address(this), abi.encodeWithSignature('getSpotPrice(address,address)', tokenIn, tokenOut), abi.encode(spotPrice) + address(this), + abi.encodeWithSignature('getSpotPrice(address,address)', tokenIn, tokenOut), + abi.encode(_returnParam0) ); } - function mock_call_getSpotPriceSansFee(address tokenIn, address tokenOut, uint256 spotPrice) public { + function mock_call_getSpotPriceSansFee(address tokenIn, address tokenOut, uint256 _returnParam0) public { vm.mockCall( address(this), abi.encodeWithSignature('getSpotPriceSansFee(address,address)', tokenIn, tokenOut), - abi.encode(spotPrice) + abi.encode(_returnParam0) ); } @@ -209,20 +211,20 @@ contract MockBPool is BPool, Test { vm.mockCall(address(this), abi.encodeWithSignature('isFinalized()'), abi.encode(_returnParam0)); } - function mock_call_isBound(address t, bool _returnParam0) public { - vm.mockCall(address(this), abi.encodeWithSignature('isBound(address)', t), abi.encode(_returnParam0)); + function mock_call_isBound(address token, bool _returnParam0) public { + vm.mockCall(address(this), abi.encodeWithSignature('isBound(address)', token), abi.encode(_returnParam0)); } function mock_call_getNumTokens(uint256 _returnParam0) public { vm.mockCall(address(this), abi.encodeWithSignature('getNumTokens()'), abi.encode(_returnParam0)); } - function mock_call_getCurrentTokens(address[] memory tokens) public { - vm.mockCall(address(this), abi.encodeWithSignature('getCurrentTokens()'), abi.encode(tokens)); + function mock_call_getCurrentTokens(address[] memory _returnParam0) public { + vm.mockCall(address(this), abi.encodeWithSignature('getCurrentTokens()'), abi.encode(_returnParam0)); } - function mock_call_getFinalTokens(address[] memory tokens) public { - vm.mockCall(address(this), abi.encodeWithSignature('getFinalTokens()'), abi.encode(tokens)); + function mock_call_getFinalTokens(address[] memory _returnParam0) public { + vm.mockCall(address(this), abi.encodeWithSignature('getFinalTokens()'), abi.encode(_returnParam0)); } function mock_call_getDenormalizedWeight(address token, uint256 _returnParam0) public {