Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding CoW helper MVP #121

Merged
merged 45 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
699d9d7
feat: non-weighted tradeable order test
wei3erHase Jun 27, 2024
271e00a
fix: adding GetTradeableOrder library
wei3erHase Jun 27, 2024
48888e3
feat: adding weights to the math
wei3erHase Jun 27, 2024
28565f7
feat: variable weights
wei3erHase Jun 27, 2024
1a44f5e
feat: adding test for helper
wei3erHase Jul 8, 2024
8bf22dd
feat: adding support for weights
wei3erHase Jul 8, 2024
3683943
fix: fmt
wei3erHase Jul 8, 2024
9422865
fix: sending correct price vector
wei3erHase Jul 8, 2024
be1701d
fix: making helper return valid signature
wei3erHase Jul 8, 2024
24553ab
chore: merge dev
wei3erHase Jul 9, 2024
441d117
feat: deprecated weights in helper
wei3erHase Jul 9, 2024
5630797
feat: updated buyAmount as per aaf44a3
wei3erHase Jul 9, 2024
627d878
refactor: mv GetTradeableOrder to libraries dir
wei3erHase Jul 9, 2024
cb2fb52
fix: update comment on BCoWHelper
wei3erHase Jul 9, 2024
5207c18
fix: rm unused variable warning
wei3erHase Jul 9, 2024
6f76f85
feat: adding BTT test for BCoWHelper
wei3erHase Jul 9, 2024
de99df4
fix: linter warnings
wei3erHase Jul 9, 2024
bd64dca
fix: rm remanent line change
wei3erHase Jul 9, 2024
ac17f69
fix: rm unused lines
wei3erHase Jul 9, 2024
6a14084
fix: missing natspec
wei3erHase Jul 9, 2024
96f0302
fix: uncommenting assertion in test
wei3erHase Jul 9, 2024
e8c4d33
fix: missing natspec
wei3erHase Jul 9, 2024
22480c5
fix: safety checks comments
wei3erHase Jul 9, 2024
3e5bfea
feat: vendoring interface from cow-amm
wei3erHase Jul 9, 2024
68e8368
fix: lint run
wei3erHase Jul 9, 2024
5afd282
chore: merge dev
wei3erHase Jul 9, 2024
9390e64
chore: pull dev no-rebase
wei3erHase Jul 9, 2024
b1ba43a
fix: gas snapshot
wei3erHase Jul 9, 2024
9ec1c34
refactor: reordered helper flow and cleanup
wei3erHase Jul 10, 2024
05d6271
feat: vendoring GetTradeableOrder from cow-amm
wei3erHase Jul 11, 2024
9923fc0
feat: improving commitment expectation
wei3erHase Jul 11, 2024
8d72ff8
Merge branch 'dev' of https://github.com/defi-wonderland/balancer-v1-…
wei3erHase Jul 11, 2024
699996e
fix: typos in comments
wei3erHase Jul 11, 2024
1bec1fd
fix: overwriting sellAmount in order to avoid rounding issues (#154)
wei3erHase Jul 15, 2024
1ffda8b
chore: addressing contract changes from PR comments
wei3erHase Jul 16, 2024
063d3f6
chore: addressing comments in tests
wei3erHase Jul 16, 2024
471b0e6
chore: merge dev
wei3erHase Jul 16, 2024
e0de518
fix: adding helper mock
wei3erHase Jul 16, 2024
d0bba5c
fix: addressing comments from PR
wei3erHase Jul 16, 2024
d8c49e6
refactor: deprecate fuzzed integration valid order test in favour of …
wei3erHase Jul 16, 2024
abe6f00
feat: simplifying helper integration test
wei3erHase Jul 17, 2024
b2056be
feat: improving unit test for valid order
wei3erHase Jul 17, 2024
ffb1bc0
feat: adding call tokens expectation
wei3erHase Jul 18, 2024
7719c39
fix: branching different behaviours given skewness
wei3erHase Jul 22, 2024
7db4e8e
fix: adding comments on the skewness sign
wei3erHase Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions test/unit/BCoWHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract BCoWHelperTest is Test {
uint256[] priceVector = new uint256[](2);

uint256 constant VALID_WEIGHT = 1e18;
uint256 constant BASE = 1e18;

function setUp() external {
factory = new MockBCoWFactory(address(0), bytes32(0));
0xteddybear marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -159,26 +160,62 @@ contract BCoWHelperTest is Test {
assertEq(keccak256(validSig), keccak256(sig));
}

function test_OrderGivenAPriceVector(uint256 priceSkewness, uint256 balanceToken0, uint256 balanceToken1) external {
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)
uint256 base = 1e18;
priceSkewness = bound(priceSkewness, 0.5e18, 1.5e18);
vm.assume(priceSkewness != base); // avoids no-skewness revert
// avoids no-skewness revert
priceSkewness = bound(priceSkewness, BASE + 0.0001e18, 1.5e18);

balanceToken0 = bound(balanceToken0, 1e18, 1e36);
balanceToken1 = bound(balanceToken1, 1e18, 1e36);
balanceToken0 = bound(balanceToken0, 1e18, 1e27);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoiding overflows

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;
prices[1] = balanceToken0 * priceSkewness / BASE;

// it should return a valid pool order
(GPv2Order.Data memory ammOrder,,,) = helper.order(address(pool), prices);

assertEq(address(ammOrder.buyToken), priceSkewness > 1e18 ? tokens[0] : tokens[1]);
// it should buy token0
assertEq(address(ammOrder.buyToken), tokens[0]);

// it should return a valid pool order
// this call should not revert
pool.verify(ammOrder);
}

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 - 0.0001e18);

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;

// it should return a valid pool order
(GPv2Order.Data memory ammOrder,,,) = helper.order(address(pool), prices);

// it should buy token1
assertEq(address(ammOrder.buyToken), tokens[1]);

// it should return a valid pool order
// this call should not revert
pool.verify(ammOrder);
}
Expand Down
6 changes: 5 additions & 1 deletion test/unit/BCoWHelper.tree
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +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 vector
├── given a price skeweness to token1
│ ├── it should buy token0
│ └── it should return a valid pool order
└── given a price skeweness to token0
├── it should buy token1
└── it should return a valid pool order
Loading