-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into mum-can-we-have-fuzzing
* 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
Showing
9 changed files
with
637 additions
and
464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.