-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support off-chain claim accounting via bucket events #185
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
55a738d
POC bucket events supporting off-chain claim accounting
neodaoist 66ccdda
idea: Add new event type for bucket being written into
neodaoist 6706c00
Normalize event ordering slightly
neodaoist 039b978
Replace dummy values with actual when emitting BucketAssignedExercise…
neodaoist bbd6e10
Lint
neodaoist 5c4e2eb
Tweak comment for clarity
neodaoist 655e0cc
Add claimId to BucketWrittenInto; Update topics
neodaoist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -450,8 +450,9 @@ contract OptionSettlementEngine is ERC1155, IOptionSettlementEngine { | |
// Add claim bucket indices. | ||
_addOrUpdateClaimIndex(optionTypeStates[optionKey], nextClaimKey, bucketIndex, amount); | ||
|
||
// Emit event about options written on a new claim. | ||
// Emit events about options written on a new claim. | ||
emit OptionsWritten(encodedOptionId, msg.sender, tokenId, amount); | ||
emit BucketWrittenInto(encodedOptionId, tokenId, bucketIndex, amount); | ||
|
||
// Transfer in the requisite underlying asset amount. | ||
SafeTransferLib.safeTransferFrom(ERC20(underlyingAsset), msg.sender, address(this), (rxAmount + fee)); | ||
|
@@ -478,8 +479,9 @@ contract OptionSettlementEngine is ERC1155, IOptionSettlementEngine { | |
// Add claim bucket indices. | ||
_addOrUpdateClaimIndex(optionTypeStates[optionKey], claimKey, bucketIndex, amount); | ||
|
||
// Emit event about options written on existing claim. | ||
// Emit events about options written on existing claim. | ||
emit OptionsWritten(encodedOptionId, msg.sender, tokenId, amount); | ||
emit BucketWrittenInto(encodedOptionId, tokenId, bucketIndex, amount); | ||
|
||
// Transfer in the requisite underlying asset amount. | ||
SafeTransferLib.safeTransferFrom(ERC20(underlyingAsset), msg.sender, address(this), (rxAmount + fee)); | ||
|
@@ -598,7 +600,7 @@ contract OptionSettlementEngine is ERC1155, IOptionSettlementEngine { | |
address underlyingAsset = optionRecord.underlyingAsset; | ||
|
||
// Assign exercise to writers. | ||
_assignExercise(optionTypeState, optionRecord, amount); | ||
_assignExercise(optionId, optionTypeState, optionRecord, amount); | ||
|
||
// Assess a fee (if fee switch enabled) and emit events. | ||
uint256 fee = 0; | ||
|
@@ -774,9 +776,12 @@ contract OptionSettlementEngine is ERC1155, IOptionSettlementEngine { | |
* another bucket, the buckets are iterated from oldest to newest. The pseudorandom | ||
* index seed is updated accordingly on the option type. | ||
*/ | ||
function _assignExercise(OptionTypeState storage optionTypeState, Option storage optionRecord, uint112 amount) | ||
private | ||
{ | ||
function _assignExercise( | ||
uint256 optionId, | ||
OptionTypeState storage optionTypeState, | ||
Option storage optionRecord, | ||
uint112 amount | ||
) private { | ||
// Setup pointers to buckets and buckets with collateral available for exercise. | ||
Bucket[] storage buckets = optionTypeState.bucketInfo.buckets; | ||
uint96[] storage unexercisedBucketIndices = optionTypeState.bucketInfo.unexercisedBucketIndices; | ||
|
@@ -791,7 +796,7 @@ contract OptionSettlementEngine is ERC1155, IOptionSettlementEngine { | |
uint112 amountAvailable = bucketInfo.amountWritten - bucketInfo.amountExercised; | ||
uint112 amountPresentlyExercised = 0; | ||
if (amountAvailable <= amount) { | ||
// Bucket is fully exercised/assigned | ||
// Bucket is fully exercised/assigned. | ||
amount -= amountAvailable; | ||
amountPresentlyExercised = amountAvailable; | ||
// Perform "swap and pop" index management. | ||
|
@@ -800,13 +805,16 @@ contract OptionSettlementEngine is ERC1155, IOptionSettlementEngine { | |
unexercisedBucketIndices[exerciseIndex] = overwrite; | ||
unexercisedBucketIndices.pop(); | ||
} else { | ||
// Bucket is partially exercised/assigned | ||
// Bucket is partially exercised/assigned. | ||
amountPresentlyExercised = amount; | ||
amount = 0; | ||
} | ||
bucketInfo.amountExercised += amountPresentlyExercised; | ||
|
||
emit BucketAssignedExercise(optionId, bucketIndex, amountPresentlyExercised); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe |
||
|
||
if (amount != 0) { | ||
// Get an additional bucket, because we still have options to exercise. | ||
exerciseIndex = (exerciseIndex + 1) % numUnexercisedBuckets; | ||
} | ||
} | ||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, with the entropy + weighting changes, it's likely that we can drop optionRecord from the function params.