Skip to content

Commit

Permalink
fix: adding comments on the skewness sign
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 22, 2024
1 parent 7719c39 commit 7db4e8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions test/unit/BCoWHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,21 @@ contract BCoWHelperTest is Test {
assertEq(keccak256(validSig), keccak256(sig));
}

function test_OrderGivenAPriceSkewenessToToken0(
function test_OrderGivenAPriceSkewenessToToken1(
uint256 priceSkewness,
uint256 balanceToken0,
uint256 balanceToken1
) external {
// skew the price by max 50% (more could result in reverts bc of max swap ratio)
// avoids no-skewness revert
priceSkewness = bound(priceSkewness, BASE + 1, 1.5e18);
priceSkewness = bound(priceSkewness, BASE + 0.0001e18, 1.5e18);

balanceToken0 = bound(balanceToken0, 1e18, 1e36);
balanceToken1 = bound(balanceToken1, 1e18, 1e36);
balanceToken0 = bound(balanceToken0, 1e18, 1e27);
balanceToken1 = bound(balanceToken1, 1e18, 1e27);
vm.mockCall(tokens[0], abi.encodePacked(IERC20.balanceOf.selector), abi.encode(balanceToken0));
vm.mockCall(tokens[1], abi.encodePacked(IERC20.balanceOf.selector), abi.encode(balanceToken1));

// NOTE: the price of token 1 is increased by the skeweness
uint256[] memory prices = new uint256[](2);
prices[0] = balanceToken1;
prices[1] = balanceToken0 * priceSkewness / BASE;
Expand All @@ -189,20 +190,21 @@ contract BCoWHelperTest is Test {
pool.verify(ammOrder);
}

function test_OrderGivenAPriceSkewenessToToken1(
function test_OrderGivenAPriceSkewenessToToken0(
uint256 priceSkewness,
uint256 balanceToken0,
uint256 balanceToken1
) external {
// skew the price by max 50% (more could result in reverts bc of max swap ratio)
// avoids no-skewness revert
priceSkewness = bound(priceSkewness, 0.5e18, BASE - 1);
priceSkewness = bound(priceSkewness, 0.5e18, BASE - 0.0001e18);

balanceToken0 = bound(balanceToken0, 1e18, 1e36);
balanceToken1 = bound(balanceToken1, 1e18, 1e36);
balanceToken0 = bound(balanceToken0, 1e18, 1e27);
balanceToken1 = bound(balanceToken1, 1e18, 1e27);
vm.mockCall(tokens[0], abi.encodePacked(IERC20.balanceOf.selector), abi.encode(balanceToken0));
vm.mockCall(tokens[1], abi.encodePacked(IERC20.balanceOf.selector), abi.encode(balanceToken1));

// NOTE: the price of token 1 is decrease by the skeweness
uint256[] memory prices = new uint256[](2);
prices[0] = balanceToken1;
prices[1] = balanceToken0 * priceSkewness / BASE;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/BCoWHelper.tree
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ BCoWHelperTest::order
│ ├── it should return a commit pre-interaction
│ ├── it should return an empty post-interaction
│ └── it should return a valid signature
├── given a price skeweness to token0
├── given a price skeweness to token1
│ ├── it should buy token0
│ └── it should return a valid pool order
└── given a price skeweness to token1
└── given a price skeweness to token0
├── it should buy token1
└── it should return a valid pool order

0 comments on commit 7db4e8e

Please sign in to comment.