fix(token): Match ERC20Wrapper decimals behavior to Solidity (#638)#640
Closed
knelsondev wants to merge 3 commits intoOpenZeppelin:mainfrom
Closed
fix(token): Match ERC20Wrapper decimals behavior to Solidity (#638)#640knelsondev wants to merge 3 commits intoOpenZeppelin:mainfrom
knelsondev wants to merge 3 commits intoOpenZeppelin:mainfrom
Conversation
Updated the `decimals` method in `Erc20Wrapper` to attempt a call to the underlying token's `decimals()` function using a fixed selector. If the call fails or returns unexpected data, it falls back to the wrapper's stored decimals. This improves the robustness of the decimals retrieval process.
✅ Deploy Preview for contracts-stylus canceled.
|
Author
|
hey @0xNeshi I have been working on it since I saw the issue raised, can you please review it and let me know. |
Collaborator
|
Thanks @knelsondev , we'll be reviewing the PR when we free up our backlog a bit |
Author
|
Hi, @0xNeshi any update with this one? |
bidzyyys
reviewed
May 27, 2025
Collaborator
|
@knelsondev are you going to work on this PR? |
Author
|
@bidzyyys Hey. I'm really sorry, I've been very busy with work lately. So if you want you can work on this here and push on this PR |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Updated the
Updates the `decimals` method in `Erc20Wrapper` to align its behavior with the Solidity `ERC20Wrapper` implementation, as requested in issue #638.decimalsmethod inErc20Wrapperto attempt a call to the underlying token'sdecimals()function using a fixed selector. If the call fails or returns unexpected data, it falls back to the wrapper's stored decimals. This improves the robustness of the decimals retrieval process.The method now first attempts to call the
decimals()function on the underlying token contract using the standard selector (0x313ce567). If this external call succeeds and returns a validuint8value, that value is returned. If the call fails (e.g., the underlying token does not implementdecimalsor the call reverts) or returns improperly formatted data, the method falls back to returning the wrapper contract's own configured decimals value (underlying_decimals).This ensures parity with the reference OpenZeppelin Solidity contracts and improves compatibility.
Resolves #638
PR Checklist