balancer / balancer-v3-monorepo

GNU General Public License v3.0
37 stars 10 forks source link

Vary Weighted Pool weights and swap fees #822

Closed EndymionJkb closed 1 month ago

EndymionJkb commented 1 month ago

Description

In the direction of #813, this runs the basic Weighted Pool tests while fuzzing the weights between the minimum and maximum (also varying the swap fee for unbalanced adds).

It doesn't resolve #813, since that should really be another contract derived from LiquidityApproximationTest... but that test really deeply assumes equal weights/equal value, so it would be a fair bit of work to generalize it. The standard tests are much easier, and are a good first step. Perhaps the Mock introduced here can be reused there.

The fact that weights are immutable after deployment is really annoying for tests. To avoid deploying a new contract on every fuzz iteration, this PR introduces a WeightedPool mock that supports two tokens and has mutable weights. So you deploy it once at the beginning, and just set the weights on each iteration.

Since each test would change the state (balances, etc.), it uses snapshots to reset the state after each test runs. Both the weights and swap fee percentage are fuzzed; the swap fee percentage is only used in the last test.

Type of change

Checklist:

Issue Resolution