-
Notifications
You must be signed in to change notification settings - Fork 31
Utility lib #162
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
base: main
Are you sure you want to change the base?
Utility lib #162
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #162 +/- ##
==========================================
- Coverage 98.39% 98.30% -0.10%
==========================================
Files 41 42 +1
Lines 1809 1824 +15
Branches 99 102 +3
==========================================
+ Hits 1780 1793 +13
- Misses 29 31 +2
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
src/utility/UtilityLib.sol
Outdated
|
|
||
| /// @notice Returns the users balance only if reentrancy protection is not active on the Compact. This eliminates in flight balances before the ERC6909 tokens were burned. | ||
| /// @dev Only if eip-1153 (transient storage) is not available. | ||
| function settledBalanceOf_nonTransient(address owner, uint256 id) internal view returns (uint256 amount) { |
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.
for this one, if we want to go try-hard on it we could derive the balance slot and use the batch extsload function to get both values in one call
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.
I like it! Not sure how much more efficient this will be though? it will at least lead to higher revert costs, since both values will be read from storage not knowing, if we even need the balance.
0age
left a comment
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.
looking good! left some comments, the major thing i think this is still missing is a helper function for handling the case where tstore isn't supported yet but may become supported, and probably also a helper that makes it dead-simple for integrators (basically giving them a "settledBalanceOf" function that will select the appropriate function under the hood)
effectively, you'd have:
- logic in the constructor to check if tstore is supported (which already has a helper implemented) and if so just assign the current settledBalanceOf as the balance check fn from the get-go
- logic in the alternative balance check contract to handle cases where tstore got activated at a later point; I feel like the most straightforward move here is to just read both the tstore slot and the sstore slot and if either is set to revert (IMHO you'd be hard-pressed to find a chain that doesn't support tstore yet where execution isn't dirt-cheap)
Added the UtilityLib:
settledBalanceOfto retrieve an ERC6909 balance from the compact. The function reverts in case the compacts reentrancy guard is active.