Skip to content

Commit

Permalink
Merge branch 'master' into mum-can-we-have-fuzzing
Browse files Browse the repository at this point in the history
* master:
  Add some random fuzz tests (#1782)
  docs: typos and readability (#1784)
  refactor: rename WeightCompression to ValueCompression (#1783)
  Update `_startGradualWeightChange` to return updated pool state (#1779)
  feat: automatically renormalize weight sum on gradual weight change (#1768)
  Inline `getSwapEnabled()` inside swap hooks (#1778)
  refactor: remove unused constants (#1781)
  style: rearrange functions (#1777)
  • Loading branch information
TomAFrench committed Sep 16, 2022
2 parents 812ec0f + 0d62d62 commit 4cc8101
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 464 deletions.
36 changes: 36 additions & 0 deletions pkg/pool-utils/test/foundry/ProtocolFees.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;

import "forge-std/Test.sol";

import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol";

import "../../contracts/protocol-fees/ProtocolFees.sol";

contract ProtocolFeesTest is Test {
function testNoPercentage(uint128 totalSupply) external {
assertEq(ProtocolFees.bptForPoolOwnershipPercentage(totalSupply, 0), 0);
}

function testNoSupply(uint64 expectedOwnershipPercentage) external {
vm.assume(expectedOwnershipPercentage < 1e18);
assertEq(ProtocolFees.bptForPoolOwnershipPercentage(0, expectedOwnershipPercentage), 0);
}

function testPostOwnershipPercentage(uint128 totalSupply, uint64 expectedOwnershipPercentage) external {
vm.assume(totalSupply > 1e6);
vm.assume(expectedOwnershipPercentage < 1e18);
uint256 fees = ProtocolFees.bptForPoolOwnershipPercentage(totalSupply, expectedOwnershipPercentage);

// Ownership of the fees should result in overall Pool ownership at least as large as the expected one (it may
// be lower due to rounding errors that favor the other LPs).
uint256 actualOwnershipPercentage = FixedPoint.divDown(fees, fees + totalSupply);
assertLe(actualOwnershipPercentage, expectedOwnershipPercentage);

// If we minted just one more token, the recipient of the fees would have ownership of the Pool no smaller than
// the expected value (potentially equal in extreme rounding cases), meaning we're not rounding down
// excessively.
uint256 largerActualOwnershipPercentage = FixedPoint.divDown((fees + 1), (fees + 1) + totalSupply);
assertGe(largerActualOwnershipPercentage, expectedOwnershipPercentage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "@balancer-labs/v2-solidity-utils/contracts/helpers/WordCodec.sol";
import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol";

import "../lib/GradualValueChange.sol";
import "../lib/WeightCompression.sol";
import "../lib/ValueCompression.sol";

import "../BaseWeightedPool.sol";

Expand All @@ -34,7 +34,7 @@ contract LiquidityBootstrappingPool is BaseWeightedPool, ReentrancyGuard {

using FixedPoint for uint256;
using WordCodec for bytes32;
using WeightCompression for uint256;
using ValueCompression for uint256;

// LBPs often involve only two tokens - we support up to four since we're able to pack the entire config in a single
// storage slot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol";
* All values are 18 decimal fixed-point numbers, so heavier compression (fewer bits)
* results in fewer decimals.
*/
library WeightCompression {
library ValueCompression {
/**
* @dev Compress a 256 bit value into `bitLength` bits.
* To compress a value down to n bits, you first "normalize" it over the full input range.
Expand Down
Loading

0 comments on commit 4cc8101

Please sign in to comment.