Skip to content

Commit

Permalink
Merge pull request #218 from valorem-labs-inc/neo/val-869-early-redem…
Browse files Browse the repository at this point in the history
…ption-of-fully-assigned-claims

Early redemption of fully assigned Claims
  • Loading branch information
neodaoist authored Sep 13, 2023
2 parents 067d6f8 + da4e13e commit 73f1522
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 99 deletions.
107 changes: 55 additions & 52 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -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)
ValoremOptionsClearinghouseUnitTest:test_write_whenNewClaim() (gas: 280534)
ValoremOptionsClearinghousev11UnitTest:testRevert_redeem_whenBeforeExpiryAndClaimIsPartiallyAssigned() (gas: 352537)
ValoremOptionsClearinghousev11UnitTest:testRevert_redeem_whenBeforeExpiryAndClaimIsUnassigned() (gas: 262772)
ValoremOptionsClearinghousev11UnitTest:test_claimAssignmentStatus() (gas: 342942)
ValoremOptionsClearinghousev11UnitTest:test_redeem_whenBeforeExpiryAndClaimIsFullyAssigned() (gas: 312642)
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion lib/SolPretty
Submodule SolPretty deleted from 80f982
9 changes: 5 additions & 4 deletions src/ValoremOptionsClearinghouse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}

Expand Down
Loading

0 comments on commit 73f1522

Please sign in to comment.