-
Notifications
You must be signed in to change notification settings - Fork 47
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
<poc> Example of option 1 #213
Open
ChefMist
wants to merge
4
commits into
main
Choose a base branch
from
feat/hexen-r7-option-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -1 +1 @@ | ||
178130 | ||
178365 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
311254 | ||
311512 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
170145 | ||
170380 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
410336 | ||
410594 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
23287 | ||
23406 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap
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 |
---|---|---|
@@ -1 +1 @@ | ||
133892 | ||
134080 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
142717 | ||
142975 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
289683 | ||
291375 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
127065 | ||
127253 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
968475 | ||
970797 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
327787 | ||
330109 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
337511 | ||
337769 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
140062 | ||
140320 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap
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 |
---|---|---|
@@ -1 +1 @@ | ||
304550 | ||
304808 |
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 |
---|---|---|
|
@@ -48,6 +48,7 @@ library BinPool { | |
error BinPool__NoLiquidityToReceiveFees(); | ||
/// @dev if swap exactIn, x for y, unspecifiedToken = token y. if swap x for exact out y, unspecified token is x | ||
error BinPool__InsufficientAmountUnSpecified(); | ||
error BinPool__BelowMinimumShare(uint256 balanceShare); | ||
|
||
/// @dev The state of a pool | ||
struct State { | ||
|
@@ -66,6 +67,9 @@ library BinPool { | |
mapping(bytes32 => bytes32) level2; | ||
} | ||
|
||
/// @dev when liquidity is removed, ensure there is either greater than min_share or 0 liquidity left | ||
uint256 constant MINIMUM_SHARE = 1e9; | ||
|
||
function initialize(State storage self, uint24 activeId, uint24 protocolFee, uint24 lpFee) internal { | ||
/// An initialized pool will not have activeId: 0 | ||
if (self.slot0.activeId() != 0) revert PoolAlreadyInitialized(); | ||
|
@@ -464,12 +468,26 @@ library BinPool { | |
function _subShare(State storage self, address owner, uint24 binId, bytes32 salt, uint256 shares) internal { | ||
self.positions.get(owner, binId, salt).subShare(shares); | ||
self.shareOfBin[binId] -= shares; | ||
|
||
/// @dev Ensure bin total share is either 0 or greater than minimum share | ||
uint256 balanceShare = self.shareOfBin[binId]; | ||
if (balanceShare > 0 && balanceShare < MINIMUM_SHARE) { | ||
revert BinPool__BelowMinimumShare(balanceShare); | ||
} | ||
} | ||
|
||
/// @notice Add share to user's position and update total share supply of bin | ||
function _addShare(State storage self, address owner, uint24 binId, bytes32 salt, uint256 shares) internal { | ||
self.positions.get(owner, binId, salt).addShare(shares); | ||
self.shareOfBin[binId] += shares; | ||
|
||
/// @dev Ensure bin total share is either 0 or greater than minimum share | ||
/// <WIP> to discuss if we want to enforce this -- otherwise user can potentially add below 1e9 liquidity | ||
/// but can't withdraw if there's no other lp to help push the min share up | ||
uint256 balanceShare = self.shareOfBin[binId]; | ||
if (balanceShare > 0 && balanceShare < MINIMUM_SHARE) { | ||
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. [wip] if this option is taken, to discuss if we want this check. |
||
revert BinPool__BelowMinimumShare(balanceShare); | ||
} | ||
} | ||
|
||
/// @notice Enable bin id for a pool | ||
|
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
Oops, something went wrong.
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.
only concern is that user maybe will always get revert when try to withdraw all , if left shares of bin is below MINIMUM_SHARE.
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.
nice, this would be a con of this approach
So example would be:
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.
per discussion with Snoopy, might worth to consider to limit from the perspective of user position instead of the whole bin.