Skip to content

Commit

Permalink
chore: merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
0xteddybear committed Jul 15, 2024
2 parents a134e2c + 4a4f8d3 commit 2668552
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 62 deletions.
1 change: 1 addition & 0 deletions .forge-snapshots/newBCoWFactory.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4890648
1 change: 1 addition & 0 deletions .forge-snapshots/newBCoWPool.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4034907
2 changes: 1 addition & 1 deletion .forge-snapshots/newBFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4130621
4131877
2 changes: 1 addition & 1 deletion .forge-snapshots/newBPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3477592
3478592
2 changes: 1 addition & 1 deletion .forge-snapshots/swapExactAmountIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
104914
104920
2 changes: 1 addition & 1 deletion .forge-snapshots/swapExactAmountInInverse.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114583
114589
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
32 changes: 8 additions & 24 deletions src/contracts/BPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/contracts/BToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -34,7 +34,7 @@ contract BToken is ERC20 {
} else {
_approve(msg.sender, spender, oldValue - amount);
}
return true;
success = true;
}

/**
Expand Down
29 changes: 25 additions & 4 deletions test/integration/DeploymentGas.t.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
22 changes: 12 additions & 10 deletions test/manual-smock/MockBCoWPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,38 +226,40 @@ 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)
);
}

function mock_call_isFinalized(bool _returnParam0) public {
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 {
Expand Down
22 changes: 12 additions & 10 deletions test/smock/MockBPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,38 +191,40 @@ 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)
);
}

function mock_call_isFinalized(bool _returnParam0) public {
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 {
Expand Down

0 comments on commit 2668552

Please sign in to comment.