From 9ea95379adf03cb3ac9ab18bbc616001c881c384 Mon Sep 17 00:00:00 2001 From: neodaoist Date: Sat, 9 Sep 2023 16:47:45 +0300 Subject: [PATCH 1/6] Add initial impl of early redeem --- .solhint.json | 36 ++++++++--- src/TokenURIGenerator.sol | 1 + src/ValoremOptionsClearinghouse.sol | 9 +-- ...aloremOptionsClearinghouse-v1.1.unit.t.sol | 61 ++++++++++++++++++- test/ValoremOptionsClearinghouse.unit.t.sol | 20 +----- 5 files changed, 96 insertions(+), 31 deletions(-) diff --git a/.solhint.json b/.solhint.json index 2b5f85d..3a5be85 100644 --- a/.solhint.json +++ b/.solhint.json @@ -1,10 +1,28 @@ { - "extends": "solhint:recommended", - "rules": { - "compiler-version": ["error",">=0.8.0"], - "no-inline-assembly": ["off",">=0.8.0"], - "avoid-low-level-calls": ["off",">=0.8.0"], - "not-rely-on-time": ["off",">=0.8.0"], - "func-visibility": ["warn",{"ignoreConstructors":true}] - } -} + "extends": "solhint:recommended", + "rules": { + "compiler-version": [ + "error", + ">=0.8.0" + ], + "no-inline-assembly": [ + "off", + ">=0.8.0" + ], + "avoid-low-level-calls": [ + "off", + ">=0.8.0" + ], + "not-rely-on-time": [ + "off", + ">=0.8.0" + ], + "no-global-import": "off", + "func-visibility": [ + "warn", + { + "ignoreConstructors": true + } + ] + } +} \ No newline at end of file diff --git a/src/TokenURIGenerator.sol b/src/TokenURIGenerator.sol index 99a9807..b5ecba4 100644 --- a/src/TokenURIGenerator.sol +++ b/src/TokenURIGenerator.sol @@ -415,6 +415,7 @@ contract TokenURIGenerator is ITokenURIGenerator { buffer[i] = ALPHABET[value & 0xf]; value >>= 4; } + // solhint-disable custom-errors require(value == 0, "Strings: hex length insufficient"); return string(buffer); } diff --git a/src/ValoremOptionsClearinghouse.sol b/src/ValoremOptionsClearinghouse.sol index b6b6c1c..312401c 100644 --- a/src/ValoremOptionsClearinghouse.sol +++ b/src/ValoremOptionsClearinghouse.sol @@ -180,7 +180,7 @@ contract ValoremOptionsClearinghouse is ERC1155, IValoremOptionsClearinghouse { } /// @inheritdoc IValoremOptionsClearinghouse - function claim(uint256 claimId) external view returns (Claim memory claimInfo) { + function claim(uint256 claimId) public view returns (Claim memory claimInfo) { (uint160 optionKey, uint96 claimKey) = _decodeTokenId(claimId); if (!_isClaimInitialized(optionKey, claimKey)) { @@ -516,12 +516,13 @@ contract ValoremOptionsClearinghouse is ERC1155, IValoremOptionsClearinghouse { revert CallerDoesNotOwnClaimId(claimId); } - // Setup pointers to the option and info. + // Setup pointers to the option and claim info. OptionTypeState storage optionTypeState = optionTypeStates[optionKey]; Option memory optionRecord = optionTypeState.option; + Claim memory claimInfo = claim(claimId); // TODO can we combine this with Claim accounting below? - // Can't redeem until expiry. - if (optionRecord.expiryTimestamp > block.timestamp) { + // Can't redeem before expiry, unless Claim is fully assigned. + if (optionRecord.expiryTimestamp > block.timestamp && claimInfo.amountWritten > claimInfo.amountExercised) { revert ClaimTooSoon(claimId, optionRecord.expiryTimestamp); } diff --git a/test/ValoremOptionsClearinghouse-v1.1.unit.t.sol b/test/ValoremOptionsClearinghouse-v1.1.unit.t.sol index 10eef30..d4fed37 100644 --- a/test/ValoremOptionsClearinghouse-v1.1.unit.t.sol +++ b/test/ValoremOptionsClearinghouse-v1.1.unit.t.sol @@ -247,5 +247,64 @@ contract ValoremOptionsClearinghousev11UnitTest is BaseClearinghouseTest { // redeem() early //////////////////////////////////////////////////////////////*/ - // TODO + function test_redeem_whenBeforeExpiryAndClaimIsFullyAssigned() public { + vm.startPrank(ALICE); + uint256 claimId = engine.write(testOptionId, 10); + engine.safeTransferFrom(ALICE, BOB, testOptionId, 10, ""); + vm.stopPrank(); + + vm.warp(testExerciseTimestamp); + vm.prank(BOB); + engine.exercise(testOptionId, 10); + + // pre-redeem check + assertEq( + ERC20(testExerciseAsset).balanceOf(ALICE), STARTING_BALANCE, "Alice exercise asset balance, pre-redeem" + ); + + // vm.warp(testExpiryTimestamp); + vm.prank(ALICE); + engine.redeem(claimId); + + // post-redeem check + uint256 expectedPostRedeemBalance = STARTING_BALANCE + (testExerciseAmount * 10); + assertEq( + ERC20(testExerciseAsset).balanceOf(ALICE), + expectedPostRedeemBalance, + "Alice exercise asset balance, post-redeem" + ); + } + + function testRevert_redeem_whenBeforeExpiryAndClaimIsUnassigned() public { + vm.startPrank(ALICE); + uint256 claimId = engine.write(testOptionId, 2); + + vm.warp(testExpiryTimestamp - 1 seconds); + + vm.expectRevert( + abi.encodeWithSelector(IValoremOptionsClearinghouse.ClaimTooSoon.selector, claimId, testExpiryTimestamp) + ); + + engine.redeem(claimId); + vm.stopPrank(); + } + + function testRevert_redeem_whenBeforeExpiryAndClaimIsPartiallyAssigned() public { + vm.startPrank(ALICE); + uint256 claimId = engine.write(testOptionId, 2); + engine.safeTransferFrom(ALICE, BOB, testOptionId, 2, ""); + vm.stopPrank(); + + vm.warp(testExpiryTimestamp - 1 seconds); + + vm.prank(BOB); + engine.exercise(testOptionId, 1); + + vm.expectRevert( + abi.encodeWithSelector(IValoremOptionsClearinghouse.ClaimTooSoon.selector, claimId, testExpiryTimestamp) + ); + + vm.prank(ALICE); + engine.redeem(claimId); + } } diff --git a/test/ValoremOptionsClearinghouse.unit.t.sol b/test/ValoremOptionsClearinghouse.unit.t.sol index 0ce534c..603b645 100644 --- a/test/ValoremOptionsClearinghouse.unit.t.sol +++ b/test/ValoremOptionsClearinghouse.unit.t.sol @@ -751,7 +751,7 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest { // function redeem(uint256 claimId) external //////////////////////////////////////////////////////////////*/ - function test_redeem_whenUnexercised() public { + function test_redeem_whenUnassigned() public { uint112 amountWritten = 7; uint256 expectedUnderlyingAmount = testUnderlyingAmount * amountWritten; uint256 expectedUnderlyingFee = _calculateFee(expectedUnderlyingAmount); @@ -792,7 +792,7 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest { assertEq(DAILIKE.balanceOf(ALICE), STARTING_BALANCE, "Alice exercise post redeem"); // no change } - function test_redeem_whenPartiallyExercised() public { + function test_redeem_whenPartiallyAssigned() public { uint112 amountWritten = 7; uint112 amountExercised = 3; uint256 expectedUnderlyingFee = _calculateFee(testUnderlyingAmount); @@ -874,7 +874,7 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest { ); } - function test_redeem_whenFullyExercised() public { + function test_redeem_whenFullyAssigned() public { uint112 amountWritten = 7; uint112 amountExercised = 7; uint256 expectedUnderlyingFee = _calculateFee(testUnderlyingAmount); @@ -992,20 +992,6 @@ contract ValoremOptionsClearinghouseUnitTest is BaseClearinghouseTest { vm.stopPrank(); } - function testRevert_redeem_whenClaimTooSoon() public { - vm.startPrank(ALICE); - uint256 claimId = engine.write(testOptionId, 1); - - vm.warp(testExerciseTimestamp - 1 seconds); - - vm.expectRevert( - abi.encodeWithSelector(IValoremOptionsClearinghouse.ClaimTooSoon.selector, claimId, testExpiryTimestamp) - ); - - engine.redeem(claimId); - vm.stopPrank(); - } - /*////////////////////////////////////////////////////////////// // function exercise(uint256 optionId, uint112 amount) external //////////////////////////////////////////////////////////////*/ From 6eb37ad67796219e44faf2af873b308a07c57e42 Mon Sep 17 00:00:00 2001 From: neodaoist Date: Sat, 9 Sep 2023 16:56:22 +0300 Subject: [PATCH 2/6] Smol --- src/TokenURIGenerator.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TokenURIGenerator.sol b/src/TokenURIGenerator.sol index b5ecba4..3eb8e09 100644 --- a/src/TokenURIGenerator.sol +++ b/src/TokenURIGenerator.sol @@ -415,6 +415,7 @@ contract TokenURIGenerator is ITokenURIGenerator { buffer[i] = ALPHABET[value & 0xf]; value >>= 4; } + // solhint-disable custom-errors require(value == 0, "Strings: hex length insufficient"); return string(buffer); From 2424468710aa526fae91febb903e8a9ec029d2fc Mon Sep 17 00:00:00 2001 From: neodaoist Date: Tue, 12 Sep 2023 19:24:08 +0300 Subject: [PATCH 3/6] lint --- src/TokenURIGenerator.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TokenURIGenerator.sol b/src/TokenURIGenerator.sol index 3eb8e09..d5b7a45 100644 --- a/src/TokenURIGenerator.sol +++ b/src/TokenURIGenerator.sol @@ -415,7 +415,7 @@ contract TokenURIGenerator is ITokenURIGenerator { buffer[i] = ALPHABET[value & 0xf]; value >>= 4; } - + // solhint-disable custom-errors require(value == 0, "Strings: hex length insufficient"); return string(buffer); From 63ec13f5307137628a9a296975e6581583184acd Mon Sep 17 00:00:00 2001 From: neodaoist Date: Tue, 12 Sep 2023 19:25:56 +0300 Subject: [PATCH 4/6] snapshot --- .gas-snapshot | 107 ++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 210787b..898e28e 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,82 +1,85 @@ -ValoremOptionsClearinghouseFuzzTest:test_fuzzExercise(uint112,uint112) (runs: 256, μ: 363079, ~: 366353) +ValoremOptionsClearinghouseFuzzTest:test_fuzzExercise(uint112,uint112) (runs: 256, μ: 363675, ~: 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, μ: 9435521, ~: 9506149) +ValoremOptionsClearinghouseFuzzTest:test_fuzzWriteExerciseRedeem(uint32) (runs: 256, μ: 9524189, ~: 9614090) ValoremOptionsClearinghouseIntegrationTest:test_integrationAddOptionsToExistingClaim() (gas: 400435) -ValoremOptionsClearinghouseIntegrationTest:test_integrationDustHandling() (gas: 905028) +ValoremOptionsClearinghouseIntegrationTest:test_integrationDustHandling() (gas: 920361) 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: 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) -ValoremOptionsClearinghouseUnitTest:testRevert_construction_whenTokenURIGeneratorIsZeroAddress() (gas: 39981) -ValoremOptionsClearinghouseUnitTest:testRevert_exercise_whenCallerHasNotGrantedSufficientApprovalToengine() (gas: 584793) -ValoremOptionsClearinghouseUnitTest:testRevert_exercise_whenCallerHoldsInsufficientExerciseAsset() (gas: 582992) +ValoremOptionsClearinghouseInvariantTest:invariant_erc20_balances() (runs: 10, calls: 10000, reverts: 5019) +ValoremOptionsClearinghouseInvariantTest:invariant_options_written_match_claims() (runs: 10, calls: 10000, reverts: 4965) +ValoremOptionsClearinghouseInvariantTest:invariant_positions_accounting() (runs: 10, calls: 10000, reverts: 4922) +ValoremOptionsClearinghouseUnitTest:testRevert_acceptFeeTo_whenNotPendingFeeTo() (gas: 35301) +ValoremOptionsClearinghouseUnitTest:testRevert_claim_whenClaimDoesNotExist() (gas: 14648) +ValoremOptionsClearinghouseUnitTest:testRevert_construction_whenFeeToIsZeroAddress() (gas: 2055329) +ValoremOptionsClearinghouseUnitTest:testRevert_construction_whenTokenURIGeneratorIsZeroAddress() (gas: 39989) +ValoremOptionsClearinghouseUnitTest:testRevert_exercise_whenCallerHasNotGrantedSufficientApprovalToEngine() (gas: 584824) +ValoremOptionsClearinghouseUnitTest:testRevert_exercise_whenCallerHoldsInsufficientExerciseAsset() (gas: 582959) ValoremOptionsClearinghouseUnitTest:testRevert_exercise_whenCallerHoldsInsufficientOptions() (gas: 264635) ValoremOptionsClearinghouseUnitTest:testRevert_exercise_whenExerciseTooEarly() (gas: 268095) ValoremOptionsClearinghouseUnitTest:testRevert_exercise_whenExpiredOption() (gas: 267890) ValoremOptionsClearinghouseUnitTest:testRevert_exercise_whenInvalidOption() (gas: 254368) -ValoremOptionsClearinghouseUnitTest:testRevert_newOptionType_whenExerciseWindowTooShort() (gas: 23334) +ValoremOptionsClearinghouseUnitTest:testRevert_newOptionType_whenExerciseWindowTooShort() (gas: 23356) ValoremOptionsClearinghouseUnitTest:testRevert_newOptionType_whenExpiryWindowTooShort() (gas: 24821) -ValoremOptionsClearinghouseUnitTest:testRevert_newOptionType_whenInvalidAssets() (gas: 21521) +ValoremOptionsClearinghouseUnitTest:testRevert_newOptionType_whenInvalidAssets() (gas: 21454) ValoremOptionsClearinghouseUnitTest:testRevert_newOptionType_whenOptionsTypeExists() (gas: 26485) -ValoremOptionsClearinghouseUnitTest:testRevert_newOptionType_whenTotalSuppliesAreTooLowToExercise() (gas: 44348) -ValoremOptionsClearinghouseUnitTest:testRevert_option_whenOptionDoesNotExist() (gas: 12493) -ValoremOptionsClearinghouseUnitTest:testRevert_position_whenExpiredOption() (gas: 19238) -ValoremOptionsClearinghouseUnitTest:testRevert_position_whenTokenNotFound() (gas: 11847) -ValoremOptionsClearinghouseUnitTest:testRevert_redeem_whenCallerDoesNotOwnClaimId() (gas: 247148) -ValoremOptionsClearinghouseUnitTest:testRevert_redeem_whenClaimTooSoon() (gas: 260127) -ValoremOptionsClearinghouseUnitTest:testRevert_redeem_whenInvalidClaim() (gas: 9432) +ValoremOptionsClearinghouseUnitTest:testRevert_newOptionType_whenTotalSuppliesAreTooLowToExercise() (gas: 45213) +ValoremOptionsClearinghouseUnitTest:testRevert_option_whenOptionDoesNotExist() (gas: 13355) +ValoremOptionsClearinghouseUnitTest:testRevert_position_whenExpiredOption() (gas: 20053) +ValoremOptionsClearinghouseUnitTest:testRevert_position_whenTokenNotFound() (gas: 12705) +ValoremOptionsClearinghouseUnitTest:testRevert_redeem_whenCallerDoesNotOwnClaimId() (gas: 249313) +ValoremOptionsClearinghouseUnitTest:testRevert_redeem_whenInvalidClaim() (gas: 9520) ValoremOptionsClearinghouseUnitTest:testRevert_setFeeTo_whenNotCurrentFeeTo() (gas: 11919) ValoremOptionsClearinghouseUnitTest:testRevert_setFeeTo_whenZeroAddress() (gas: 11641) -ValoremOptionsClearinghouseUnitTest:testRevert_setFeesEnabled_whenNotFeeTo() (gas: 11843) -ValoremOptionsClearinghouseUnitTest:testRevert_setTokenURIGenerator_whenNotCurrentFeeTo() (gas: 11911) -ValoremOptionsClearinghouseUnitTest:testRevert_setTokenURIGenerator_whenZeroAddress() (gas: 11653) -ValoremOptionsClearinghouseUnitTest:testRevert_sweepFees_whenNotFeeTo() (gas: 16949) -ValoremOptionsClearinghouseUnitTest:testRevert_uri_whenTokenNotFound() (gas: 18686) -ValoremOptionsClearinghouseUnitTest:testRevert_write_whenAmountWrittenCannotBeZero() (gas: 10763) -ValoremOptionsClearinghouseUnitTest:testRevert_write_whenCallerDoesNotOwnClaimId() (gas: 261825) -ValoremOptionsClearinghouseUnitTest:testRevert_write_whenCallerHasNotGrantedSufficientApprovalToengine() (gas: 685646) -ValoremOptionsClearinghouseUnitTest:testRevert_write_whenCallerHoldsInsufficientExerciseAsset() (gas: 685705) -ValoremOptionsClearinghouseUnitTest:testRevert_write_whenExpiredOption() (gas: 16935) -ValoremOptionsClearinghouseUnitTest:testRevert_write_whenInvalidOption() (gas: 13604) -ValoremOptionsClearinghouseUnitTest:test_claim_whenWrittenMultiple() (gas: 383202) -ValoremOptionsClearinghouseUnitTest:test_claim_whenWrittenMultipleTimesOnMultipleClaims() (gas: 458203) -ValoremOptionsClearinghouseUnitTest:test_claim_whenWrittenOnce() (gas: 303666) -ValoremOptionsClearinghouseUnitTest:test_exercise() (gas: 384012) +ValoremOptionsClearinghouseUnitTest:testRevert_setFeesEnabled_whenNotFeeTo() (gas: 11821) +ValoremOptionsClearinghouseUnitTest:testRevert_setTokenURIGenerator_whenNotCurrentFeeTo() (gas: 11889) +ValoremOptionsClearinghouseUnitTest:testRevert_setTokenURIGenerator_whenZeroAddress() (gas: 11609) +ValoremOptionsClearinghouseUnitTest:testRevert_sweepFees_whenNotFeeTo() (gas: 16927) +ValoremOptionsClearinghouseUnitTest:testRevert_uri_whenTokenNotFound() (gas: 20262) +ValoremOptionsClearinghouseUnitTest:testRevert_write_whenAmountWrittenCannotBeZero() (gas: 10676) +ValoremOptionsClearinghouseUnitTest:testRevert_write_whenCallerDoesNotOwnClaimId() (gas: 261803) +ValoremOptionsClearinghouseUnitTest:testRevert_write_whenCallerHasNotGrantedSufficientApprovalToengine() (gas: 687624) +ValoremOptionsClearinghouseUnitTest:testRevert_write_whenCallerHoldsInsufficientExerciseAsset() (gas: 687659) +ValoremOptionsClearinghouseUnitTest:testRevert_write_whenExpiredOption() (gas: 16957) +ValoremOptionsClearinghouseUnitTest:testRevert_write_whenInvalidOption() (gas: 13626) +ValoremOptionsClearinghouseUnitTest:test_claim_whenWrittenMultiple() (gas: 387402) +ValoremOptionsClearinghouseUnitTest:test_claim_whenWrittenMultipleTimesOnMultipleClaims() (gas: 458225) +ValoremOptionsClearinghouseUnitTest:test_claim_whenWrittenOnce() (gas: 306556) +ValoremOptionsClearinghouseUnitTest:test_exercise() (gas: 383968) ValoremOptionsClearinghouseUnitTest:test_exercise_whenExercisingMultipleTimes() (gas: 425505) ValoremOptionsClearinghouseUnitTest:test_feeBalance_whenFeeOff() (gas: 267101) ValoremOptionsClearinghouseUnitTest:test_feeBalance_whenFeeOn() (gas: 323819) -ValoremOptionsClearinghouseUnitTest:test_feeBalance_whenMinimum() (gas: 401587) +ValoremOptionsClearinghouseUnitTest:test_feeBalance_whenMinimum() (gas: 401565) ValoremOptionsClearinghouseUnitTest:test_feeBps() (gas: 5644) -ValoremOptionsClearinghouseUnitTest:test_feeTo() (gas: 7781) +ValoremOptionsClearinghouseUnitTest:test_feeTo() (gas: 7737) ValoremOptionsClearinghouseUnitTest:test_feesEnabled() (gas: 7684) -ValoremOptionsClearinghouseUnitTest:test_newOptionType() (gas: 130017) -ValoremOptionsClearinghouseUnitTest:test_option_returnsOptionInfo() (gas: 25650) +ValoremOptionsClearinghouseUnitTest:test_newOptionType() (gas: 130083) +ValoremOptionsClearinghouseUnitTest:test_option_returnsOptionInfo() (gas: 25672) ValoremOptionsClearinghouseUnitTest:test_position_whenFullyExercisedClaim() (gas: 302781) -ValoremOptionsClearinghouseUnitTest:test_position_whenOption() (gas: 30855) -ValoremOptionsClearinghouseUnitTest:test_position_whenPartiallyExercisedClaim() (gas: 427836) +ValoremOptionsClearinghouseUnitTest:test_position_whenOption() (gas: 31743) +ValoremOptionsClearinghouseUnitTest:test_position_whenPartiallyExercisedClaim() (gas: 427858) ValoremOptionsClearinghouseUnitTest:test_position_whenUnexercisedClaim() (gas: 263939) -ValoremOptionsClearinghouseUnitTest:test_redeem_whenFullyExercised() (gas: 333102) -ValoremOptionsClearinghouseUnitTest:test_redeem_whenPartiallyExercised() (gas: 343924) -ValoremOptionsClearinghouseUnitTest:test_redeem_whenUnexercised() (gas: 235840) -ValoremOptionsClearinghouseUnitTest:test_setFeeToAndAcceptFeeTo() (gas: 29510) +ValoremOptionsClearinghouseUnitTest:test_redeem_whenFullyAssigned() (gas: 335329) +ValoremOptionsClearinghouseUnitTest:test_redeem_whenPartiallyAssigned() (gas: 346683) +ValoremOptionsClearinghouseUnitTest:test_redeem_whenUnassigned() (gas: 238600) +ValoremOptionsClearinghouseUnitTest:test_setFeeToAndAcceptFeeTo() (gas: 29546) ValoremOptionsClearinghouseUnitTest:test_setFeeToAndAcceptFeeTo_multipleTimes() (gas: 50411) -ValoremOptionsClearinghouseUnitTest:test_setFeesEnabled() (gas: 20514) +ValoremOptionsClearinghouseUnitTest:test_setFeesEnabled() (gas: 20581) ValoremOptionsClearinghouseUnitTest:test_setTokenURIGenerator() (gas: 2035989) -ValoremOptionsClearinghouseUnitTest:test_sweepFees() (gas: 376903) -ValoremOptionsClearinghouseUnitTest:test_sweepFees_whenNoFees() (gas: 53303) +ValoremOptionsClearinghouseUnitTest:test_sweepFees() (gas: 376859) +ValoremOptionsClearinghouseUnitTest:test_sweepFees_whenNoFees() (gas: 53259) ValoremOptionsClearinghouseUnitTest:test_tokenType_returnsClaim() (gas: 253539) ValoremOptionsClearinghouseUnitTest:test_tokenType_returnsNone() (gas: 7980) -ValoremOptionsClearinghouseUnitTest:test_tokenType_returnsOption() (gas: 10216) -ValoremOptionsClearinghouseUnitTest:test_tokenURIGenerator() (gas: 9963) +ValoremOptionsClearinghouseUnitTest:test_tokenType_returnsOption() (gas: 10128) +ValoremOptionsClearinghouseUnitTest:test_tokenURIGenerator() (gas: 9941) ValoremOptionsClearinghouseUnitTest:test_uri() (gas: 479483) ValoremOptionsClearinghouseUnitTest:test_write_whenExistingClaim() (gas: 301062) ValoremOptionsClearinghouseUnitTest:test_write_whenFeeOff() (gas: 259288) -ValoremOptionsClearinghouseUnitTest:test_write_whenNewClaim() (gas: 280712) \ No newline at end of file +ValoremOptionsClearinghouseUnitTest:test_write_whenNewClaim() (gas: 280534) +ValoremOptionsClearinghousev11UnitTest:testRevert_redeem_whenBeforeExpiryAndClaimIsPartiallyAssigned() (gas: 352537) +ValoremOptionsClearinghousev11UnitTest:testRevert_redeem_whenBeforeExpiryAndClaimIsUnassigned() (gas: 262772) +ValoremOptionsClearinghousev11UnitTest:test_claimAssignmentStatus() (gas: 394240) +ValoremOptionsClearinghousev11UnitTest:test_redeem_whenBeforeExpiryAndClaimIsFullyAssigned() (gas: 312642) \ No newline at end of file From 84fc1ea62bf46c329286d9c68f637ec2fd1eb102 Mon Sep 17 00:00:00 2001 From: neodaoist Date: Wed, 13 Sep 2023 17:58:48 +0300 Subject: [PATCH 5/6] Remove solpretty for time being --- .gas-snapshot | 2 +- ...aloremOptionsClearinghouse-v1.1.unit.t.sol | 39 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 898e28e..c519c4f 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -81,5 +81,5 @@ ValoremOptionsClearinghouseUnitTest:test_write_whenFeeOff() (gas: 259288) ValoremOptionsClearinghouseUnitTest:test_write_whenNewClaim() (gas: 280534) ValoremOptionsClearinghousev11UnitTest:testRevert_redeem_whenBeforeExpiryAndClaimIsPartiallyAssigned() (gas: 352537) ValoremOptionsClearinghousev11UnitTest:testRevert_redeem_whenBeforeExpiryAndClaimIsUnassigned() (gas: 262772) -ValoremOptionsClearinghousev11UnitTest:test_claimAssignmentStatus() (gas: 394240) +ValoremOptionsClearinghousev11UnitTest:test_claimAssignmentStatus() (gas: 342942) ValoremOptionsClearinghousev11UnitTest:test_redeem_whenBeforeExpiryAndClaimIsFullyAssigned() (gas: 312642) \ No newline at end of file diff --git a/test/ValoremOptionsClearinghouse-v1.1.unit.t.sol b/test/ValoremOptionsClearinghouse-v1.1.unit.t.sol index d4fed37..86c8c88 100644 --- a/test/ValoremOptionsClearinghouse-v1.1.unit.t.sol +++ b/test/ValoremOptionsClearinghouse-v1.1.unit.t.sol @@ -4,15 +4,12 @@ pragma solidity 0.8.16; import "solmate/utils/FixedPointMathLib.sol"; import "forge-std/Test.sol"; -import {pp, SolPretty} from "SolPretty/SolPretty.sol"; import {IERC20} from "forge-std/interfaces/IERC20.sol"; import "./utils/BaseClearinghouseTest.sol"; /// @notice Unit tests for ValoremOptionsClearinghouse v1.1.0 contract ValoremOptionsClearinghousev11UnitTest is BaseClearinghouseTest { - using SolPretty for string; - /*////////////////////////////////////////////////////////////// // Clearinghouse v1.1.0 //////////////////////////////////////////////////////////////*/ @@ -39,12 +36,12 @@ contract ValoremOptionsClearinghousev11UnitTest is BaseClearinghouseTest { assertEq(engine.feeBalance(testExerciseAsset), 0, "Fee balance exercise"); // no fee assessed on exercise asset during write() // Unassigned - IValoremOptionsClearinghouse.Claim memory unassigned = engine.claim(claimId); - emit log("Unassigned Claim ---------"); - emit log_named_string("amountWritten", pp(unassigned.amountWritten, 18, 0)); - emit log_named_string("amountExercised", pp(unassigned.amountExercised, 18, 0)); - uint256 assignmentPercentage = unassigned.amountExercised / unassigned.amountWritten; - emit log_named_uint("percentage", assignmentPercentage); + // IValoremOptionsClearinghouse.Claim memory unassigned = engine.claim(claimId); + // emit log("Unassigned Claim ---------"); + // emit log_named_string("amountWritten", pp(unassigned.amountWritten, 18, 0)); + // emit log_named_string("amountExercised", pp(unassigned.amountExercised, 18, 0)); + // uint256 assignmentPercentage = unassigned.amountExercised / unassigned.amountWritten; + // emit log_named_uint("percentage", assignmentPercentage); // if amountExercised == 0, claim is unassigned // Partially Assigned @@ -54,24 +51,24 @@ contract ValoremOptionsClearinghousev11UnitTest is BaseClearinghouseTest { vm.prank(BOB); engine.exercise(testOptionId, 1); - IValoremOptionsClearinghouse.Claim memory partiallyAssigned = engine.claim(claimId); - emit log("Partially Assigned Claim ---------"); - emit log_named_string("amountWritten", pp(partiallyAssigned.amountWritten, 18, 0)); - emit log_named_string("amountExercised", pp(partiallyAssigned.amountExercised, 18, 0)); - assignmentPercentage = partiallyAssigned.amountExercised / partiallyAssigned.amountWritten; - emit log_named_uint("percentage", assignmentPercentage); // TODO use scalar + // IValoremOptionsClearinghouse.Claim memory partiallyAssigned = engine.claim(claimId); + // emit log("Partially Assigned Claim ---------"); + // emit log_named_string("amountWritten", pp(partiallyAssigned.amountWritten, 18, 0)); + // emit log_named_string("amountExercised", pp(partiallyAssigned.amountExercised, 18, 0)); + // assignmentPercentage = partiallyAssigned.amountExercised / partiallyAssigned.amountWritten; + // emit log_named_uint("percentage", assignmentPercentage); // TODO use scalar // if amountExercised > 0 && amountWritten > amountExercised, claim is partially assigned // Fully Assigned vm.prank(BOB); engine.exercise(testOptionId, 4); - IValoremOptionsClearinghouse.Claim memory fullyAssigned = engine.claim(claimId); - emit log("Fully Assigned Claim ---------"); - emit log_named_string("amountWritten", pp(fullyAssigned.amountWritten, 18, 0)); - emit log_named_string("amountExercised", pp(fullyAssigned.amountExercised, 18, 0)); - assignmentPercentage = fullyAssigned.amountExercised / fullyAssigned.amountWritten; - emit log_named_uint("percentage", assignmentPercentage); + // IValoremOptionsClearinghouse.Claim memory fullyAssigned = engine.claim(claimId); + // emit log("Fully Assigned Claim ---------"); + // emit log_named_string("amountWritten", pp(fullyAssigned.amountWritten, 18, 0)); + // emit log_named_string("amountExercised", pp(fullyAssigned.amountExercised, 18, 0)); + // assignmentPercentage = fullyAssigned.amountExercised / fullyAssigned.amountWritten; + // emit log_named_uint("percentage", assignmentPercentage); // if amountWritten == amountExercised, claim is fully assigned } From da4e13eeb1bd480c129a1caa8432bce3fa6c2e64 Mon Sep 17 00:00:00 2001 From: neodaoist Date: Wed, 13 Sep 2023 18:00:59 +0300 Subject: [PATCH 6/6] Remove solpretty lib --- .gitmodules | 3 --- lib/SolPretty | 1 - 2 files changed, 4 deletions(-) delete mode 160000 lib/SolPretty diff --git a/.gitmodules b/.gitmodules index b617657..558b49a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "lib/solmate"] path = lib/solmate url = https://github.com/rari-capital/solmate -[submodule "lib/SolPretty"] - path = lib/SolPretty - url = https://github.com/devtooligan/SolPretty diff --git a/lib/SolPretty b/lib/SolPretty deleted file mode 160000 index 80f9820..0000000 --- a/lib/SolPretty +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 80f98208b71093dff25c0e203a1de1551267a10f