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 16, 2024
2 parents 2668552 + 598b6ee commit b5e712c
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 374 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4890648
4899289
2 changes: 1 addition & 1 deletion .forge-snapshots/newBCoWPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4034907
4042925
2 changes: 1 addition & 1 deletion .forge-snapshots/newBFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4131877
4140477
2 changes: 1 addition & 1 deletion .forge-snapshots/newBPool.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3478592
3486610
2 changes: 1 addition & 1 deletion src/contracts/BConst.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract BConst {
/// @notice The minimum swap fee that can be set.
uint256 public constant MIN_FEE = BONE / 10 ** 6;
/// @notice The maximum swap fee that can be set.
uint256 public constant MAX_FEE = BONE / 10;
uint256 public constant MAX_FEE = BONE - MIN_FEE;
/// @notice The immutable exit fee percentage
uint256 public constant EXIT_FEE = 0;

Expand Down
28 changes: 18 additions & 10 deletions test/unit/BMath.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@ contract BMathTest is Test, BConst {
bMath.calcOutGivenIn(balanceIn, weightIn, balanceOut, weightOut, amountIn, _swapFee);
}

function test_CalcOutGivenInWhenSwapFeeEqualsBONE() external virtual {
uint256 _swapFee = BONE;

// it should return zero
uint256 _amountOut = bMath.calcOutGivenIn(balanceIn, weightIn, balanceOut, weightOut, amountIn, _swapFee);

assertEq(_amountOut, 0);
}

function test_CalcOutGivenInRevertWhen_TokenAmountInTooBig(uint256 _amountIn) external {
_amountIn = bound(_amountIn, type(uint256).max / (BONE - swapFee) + 1, type(uint256).max);

Expand Down Expand Up @@ -154,6 +145,15 @@ contract BMathTest is Test, BConst {
bMath.calcOutGivenIn(_balanceIn, weightIn, balanceOut, weightOut, amountIn, _swapFee);
}

function test_CalcOutGivenInWhenSwapFeeEqualsBONE() external virtual {
uint256 _swapFee = BONE;

// it should return zero
uint256 _amountOut = bMath.calcOutGivenIn(balanceIn, weightIn, balanceOut, weightOut, amountIn, _swapFee);

assertEq(_amountOut, 0);
}

function test_CalcOutGivenInWhenTokenWeightInIsZero() external virtual {
uint256 _weightIn = 0;

Expand Down Expand Up @@ -477,7 +477,7 @@ contract BMathTest is Test, BConst {
bMath.calcPoolInGivenSingleOut(_balanceOut, weightOut, poolSupply, totalWeight, amountOut, swapFee);
}

function test_CalcPoolInGivenSingleOutRevertWhen_SwapFeeIs1AndTokenWeightOutIsZero() external {
function test_CalcPoolInGivenSingleOutRevertWhen_SwapFeeEqualsBONEAndTokenWeightOutIsZero() external {
uint256 _swapFee = BONE;
uint256 _weightOut = 0;

Expand All @@ -488,6 +488,14 @@ contract BMathTest is Test, BConst {
bMath.calcPoolInGivenSingleOut(balanceOut, _weightOut, poolSupply, totalWeight, amountOut, _swapFee);
}

function test_CalcPoolInGivenSingleOutRevertWhen_SwapFeeGreaterThanBONE() external {
// it should revert
// subtraction underflow
vm.expectRevert(BNum.BNum_SubUnderflow.selector);

bMath.calcPoolInGivenSingleOut(balanceOut, weightOut, poolSupply, totalWeight, amountOut, BONE + 1);
}

function test_CalcPoolInGivenSingleOutWhenTokenAmountOutIsZero() external virtual {
uint256 _amountOut = 0;

Expand Down
20 changes: 11 additions & 9 deletions test/unit/BMath.tree
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ BMathTest::calcSpotPrice
│ └── it should revert // division by zero
├── when weighted token balance out is zero
│ └── it should revert // division by zero
├── when swapFee greater than BONE
├── when swap fee greater than BONE
│ └── it should revert // subtraction underflow
├── when swapFee equals BONE
├── when swap fee equals BONE
│ └── it should revert // division by zero
├── when swap fee is zero
│ └── it should return correct value
Expand All @@ -21,14 +21,14 @@ BMathTest::calcOutGivenIn
│ └── it should revert // division by zero
├── when swap fee greater than BONE
│ └── it should revert // subtraction underflow
├── when swap fee equals BONE
│ └── it should return zero
├── when token amount in too big
│ └── it should revert // ai * (1 - sf) > uint256 max
├── when token balance in and amount in are zero
│ └── it should revert // bi + (ai * (1 - swapFee)) = 0
│ └── it should revert // bi + (ai * (1 - sf)) = 0
├── when token balance in is zero and swap fee equals BONE
│ └── it should revert // bi + (ai * (1 - swapFee)) = 0
│ └── it should revert // bi + (ai * (1 - sf)) = 0
├── when swap fee equals BONE
│ └── it should return zero
├── when token weight in is zero
│ └── it should return zero
├── when token weights are equal
Expand All @@ -53,9 +53,9 @@ BMathTest::calcInGivenOut
│ └── it should revert // subtraction underflow
├── when token amount out equals token balance out
│ └── it should revert // division by zero
├── when swapFee greater than BONE
├── when swap fee greater than BONE
│ └── it should revert // subtraction underflow
├── when swapFee equals BONE
├── when swap fee equals BONE
│ └── it should revert // division by zero
├── when token weight out is zero
│ └── it should return zero
Expand Down Expand Up @@ -121,8 +121,10 @@ BMathTest::calcSingleOutGivenPoolIn
BMathTest::calcPoolInGivenSingleOut
├── when token balance out is zero
│ └── it should revert // subtraction underflow
├── when swap fee is 1 and token weight out is zero
├── when swap fee equals BONE and token weight out is zero
│ └── it should revert // division by zero
├── when swap fee greater than BONE
│ └── it should revert // subtraction underflow
├── when token amount out is zero
│ └── it should return zero
├── when pool supply is zero
Expand Down
Loading

0 comments on commit b5e712c

Please sign in to comment.