Skip to content

Commit

Permalink
Merge pull request #213 from valorem-labs-inc/neo/val-561-update-fees…
Browse files Browse the repository at this point in the history
…-for-clear
  • Loading branch information
neodaoist authored Aug 14, 2023
2 parents 6d14ebc + 364bf81 commit 3c3aea6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
14 changes: 7 additions & 7 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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)
ValoremOptionsClearinghouseIntegrationTest:test_integrationRandomAssignment() (gas: 906223)
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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/ValoremOptionsClearinghouse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 27 additions & 10 deletions test/ValoremOptionsClearinghouse.unit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest {
//////////////////////////////////////////////////////////////*/

function test_feeBps() public {
assertEq(engine.feeBps(), 5);
assertEq(engine.feeBps(), 15);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 3c3aea6

Please sign in to comment.