refactor: unify ERC20 storage slot discovery logic #10749
Merged
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.
Summary
Extracts duplicated access list handling code from
anvil_deal_erc20
andanvil_set_erc20_allowance
into a sharedfind_erc20_storage_slot
helper function.This is a follow-up cleanup to #10746 which introduced
anvil_set_erc20_allowance
.Changes
find_erc20_storage_slot
that encapsulates the slot-finding logicHow It Works
The helper function performs "storage slot discovery" for ERC20 tokens by:
This approach works with any ERC20 token regardless of its internal storage layout, avoiding the need to reverse-engineer Solidity mapping storage calculations.
Before/After
Before (duplicated in both functions):
After:
<!-- Original prompt that led to this refactoring:
Analyze anvil_deal_erc20 and anvil_set_erc20_allowance functions in crates/anvil/src/eth/api.rs in particular the code for acceslist handling (the for loop) which is mostly duplicated; try to unify this behaviour with a helper function for finding the slot
-->
🤖 Generated with Claude Code