diff --git a/.gas-snapshot b/.gas-snapshot index 1e5d889..210787b 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,7 +1,7 @@ -ValoremOptionsClearinghouseFuzzTest:test_fuzzExercise(uint112,uint112) (runs: 256, μ: 363675, ~: 366353) +ValoremOptionsClearinghouseFuzzTest:test_fuzzExercise(uint112,uint112) (runs: 256, μ: 363079, ~: 366353) ValoremOptionsClearinghouseFuzzTest:test_fuzzNewOptionType(uint96,uint96,uint40,uint40) (runs: 256, μ: 130922, ~: 130922) ValoremOptionsClearinghouseFuzzTest:test_fuzzWrite(uint112) (runs: 256, μ: 284216, ~: 284216) -ValoremOptionsClearinghouseFuzzTest:test_fuzzWriteExerciseRedeem(uint32) (runs: 256, μ: 9368028, ~: 9506149) +ValoremOptionsClearinghouseFuzzTest:test_fuzzWriteExerciseRedeem(uint32) (runs: 256, μ: 9435521, ~: 9506149) ValoremOptionsClearinghouseIntegrationTest:test_integrationAddOptionsToExistingClaim() (gas: 400435) ValoremOptionsClearinghouseIntegrationTest:test_integrationDustHandling() (gas: 905028) ValoremOptionsClearinghouseIntegrationTest:test_integrationFairAssignment() (gas: 603589) @@ -9,9 +9,9 @@ ValoremOptionsClearinghouseIntegrationTest:test_integrationRandomAssignment() (g ValoremOptionsClearinghouseIntegrationTest:test_integrationSweepFeesWhenFeesAccruedForExercise() (gas: 1418985) ValoremOptionsClearinghouseIntegrationTest:test_integrationSweepFeesWhenFeesAccruedForWrite() (gas: 1343568) ValoremOptionsClearinghouseIntegrationTest:test_integrationWriteExerciseAddBuckets() (gas: 1062312) -ValoremOptionsClearinghouseInvariantTest:invariant_erc20_balances() (runs: 10, calls: 10000, reverts: 5031) -ValoremOptionsClearinghouseInvariantTest:invariant_options_written_match_claims() (runs: 10, calls: 10000, reverts: 4975) -ValoremOptionsClearinghouseInvariantTest:invariant_positions_accounting() (runs: 10, calls: 10000, reverts: 4978) +ValoremOptionsClearinghouseInvariantTest:invariant_erc20_balances() (runs: 10, calls: 10000, reverts: 5042) +ValoremOptionsClearinghouseInvariantTest:invariant_options_written_match_claims() (runs: 10, calls: 10000, reverts: 4917) +ValoremOptionsClearinghouseInvariantTest:invariant_positions_accounting() (runs: 10, calls: 10000, reverts: 5034) ValoremOptionsClearinghouseUnitTest:testRevert_acceptFeeTo_whenNotPendingFeeTo() (gas: 35323) ValoremOptionsClearinghouseUnitTest:testRevert_claim_whenClaimDoesNotExist() (gas: 13769) ValoremOptionsClearinghouseUnitTest:testRevert_construction_whenFeeToIsZeroAddress() (gas: 2055299) @@ -70,8 +70,8 @@ ValoremOptionsClearinghouseUnitTest:test_setFeeToAndAcceptFeeTo() (gas: 29510) ValoremOptionsClearinghouseUnitTest:test_setFeeToAndAcceptFeeTo_multipleTimes() (gas: 50411) ValoremOptionsClearinghouseUnitTest:test_setFeesEnabled() (gas: 20514) ValoremOptionsClearinghouseUnitTest:test_setTokenURIGenerator() (gas: 2035989) -ValoremOptionsClearinghouseUnitTest:test_sweepFees() (gas: 370606) -ValoremOptionsClearinghouseUnitTest:test_sweepFees_whenNoFees() (gas: 45569) +ValoremOptionsClearinghouseUnitTest:test_sweepFees() (gas: 376903) +ValoremOptionsClearinghouseUnitTest:test_sweepFees_whenNoFees() (gas: 53303) ValoremOptionsClearinghouseUnitTest:test_tokenType_returnsClaim() (gas: 253539) ValoremOptionsClearinghouseUnitTest:test_tokenType_returnsNone() (gas: 7980) ValoremOptionsClearinghouseUnitTest:test_tokenType_returnsOption() (gas: 10216) diff --git a/src/ValoremOptionsClearinghouse.sol b/src/ValoremOptionsClearinghouse.sol index 39fd542..1178933 100644 --- a/src/ValoremOptionsClearinghouse.sol +++ b/src/ValoremOptionsClearinghouse.sol @@ -101,7 +101,7 @@ contract ValoremOptionsClearinghouse is ERC1155, IValoremOptionsClearinghouse { /// @inheritdoc IValoremOptionsClearinghouse // solhint-disable-next-line const-name-snakecase - uint8 public constant feeBps = 5; + uint8 public constant feeBps = 15; /*////////////////////////////////////////////////////////////// // State Variables - Private diff --git a/test/ValoremOptionsClearinghouse.unit.t.sol b/test/ValoremOptionsClearinghouse.unit.t.sol index 1944a27..8b66d51 100644 --- a/test/ValoremOptionsClearinghouse.unit.t.sol +++ b/test/ValoremOptionsClearinghouse.unit.t.sol @@ -358,7 +358,7 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest { //////////////////////////////////////////////////////////////*/ function test_feeBps() public { - assertEq(engine.feeBps(), 5); + assertEq(engine.feeBps(), 15); } /*////////////////////////////////////////////////////////////// @@ -1463,6 +1463,9 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest { assertEq(WETHLIKE.balanceOf(FEE_TO), 0); assertEq(DAILIKE.balanceOf(FEE_TO), 0); assertEq(USDCLIKE.balanceOf(FEE_TO), 0); + assertEq(engine.feeBalance(address(WETHLIKE)), 0); + assertEq(engine.feeBalance(address(DAILIKE)), 0); + assertEq(engine.feeBalance(address(USDCLIKE)), 0); address[] memory tokens = new address[](3); tokens[0] = address(WETHLIKE); @@ -1476,6 +1479,9 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest { assertEq(WETHLIKE.balanceOf(FEE_TO), 0); assertEq(DAILIKE.balanceOf(FEE_TO), 0); assertEq(USDCLIKE.balanceOf(FEE_TO), 0); + assertEq(engine.feeBalance(address(WETHLIKE)), 0); + assertEq(engine.feeBalance(address(DAILIKE)), 0); + assertEq(engine.feeBalance(address(USDCLIKE)), 0); } function test_sweepFees() public { @@ -1489,22 +1495,33 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest { engine.exercise(testOptionId, 10); vm.stopPrank(); - uint256 wethFee = _calculateFee(10 * testUnderlyingAmount); - uint256 daiFee = _calculateFee(10 * testExerciseAmount); + uint256 underlyingFee = _calculateFee(10 * testUnderlyingAmount); + uint256 exerciseFee = _calculateFee(10 * testExerciseAmount); // Precondition checks - assertEq(WETHLIKE.balanceOf(FEE_TO), 0); - assertEq(DAILIKE.balanceOf(FEE_TO), 0); + assertEq(WETHLIKE.balanceOf(FEE_TO), 0, "feeTo underlying balance before sweep"); + assertEq(DAILIKE.balanceOf(FEE_TO), 0, "feeTo exercise balance before sweep"); + assertEq( + engine.feeBalance(address(WETHLIKE)), underlyingFee, "clearinghouse underlying fee balance before sweep" + ); + assertEq(engine.feeBalance(address(DAILIKE)), exerciseFee, "clearinghouse exercise fee balance before sweep"); - emit FeeSwept(testUnderlyingAsset, FEE_TO, wethFee); - emit FeeSwept(testExerciseAsset, FEE_TO, daiFee); + // Event log assertions -- 1 dust left in fee balance as gas optimization + vm.expectEmit(true, true, true, true); + emit FeeSwept(address(WETHLIKE), FEE_TO, underlyingFee - 1); + vm.expectEmit(true, true, true, true); + emit FeeSwept(address(DAILIKE), FEE_TO, exerciseFee - 1); vm.prank(FEE_TO); engine.sweepFees(tokens); - // Balance assertions -- with tolerance of 1 wei for loss of precision - assertApproxEqAbs(WETHLIKE.balanceOf(FEE_TO), wethFee, 1, "FeeTo underlying balance"); - assertApproxEqAbs(DAILIKE.balanceOf(FEE_TO), daiFee, 1, "FeeTo exercise balance"); + // Balance assertions -- ditto + assertEq(WETHLIKE.balanceOf(FEE_TO), underlyingFee - 1, "feeTo underlying balance after sweep"); + assertEq(DAILIKE.balanceOf(FEE_TO), exerciseFee - 1, "feeTo exercise balance after sweep"); + + // Fee assertions -- ditto + assertEq(engine.feeBalance(address(WETHLIKE)), 1, "clearinghouse underlying fee balance after sweep"); + assertEq(engine.feeBalance(address(DAILIKE)), 1, "clearinghouse exercise fee balance after sweep"); } function testRevert_sweepFees_whenNotFeeTo() public {