Skip to content

fix(token): Match ERC20Wrapper decimals behavior to Solidity (#638) #640

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

Closed

Conversation

knelsondev
Copy link

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.

Updates the `decimals` method in `Erc20Wrapper` to align its behavior with the Solidity `ERC20Wrapper` implementation, as requested in issue #638.

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 valid uint8 value, that value is returned. If the call fails (e.g., the underlying token does not implement decimals or 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

  • Tests
  • Documentation
  • Changelog

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.
Copy link

netlify bot commented Apr 27, 2025

Deploy Preview for contracts-stylus canceled.

Name Link
🔨 Latest commit f3edcdb
🔍 Latest deploy log https://app.netlify.com/projects/contracts-stylus/deploys/68401ef008676e000815aa01

@knelsondev
Copy link
Author

hey @0xNeshi I have been working on it since I saw the issue raised, can you please review it and let me know.

@0xNeshi
Copy link
Collaborator

0xNeshi commented Apr 30, 2025

Thanks @knelsondev , we'll be reviewing the PR when we free up our backlog a bit

@knelsondev
Copy link
Author

Hi, @0xNeshi any update with this one?

Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Solidity implementation we do not have underlying_decimals in storage. Try to remove it.

@bidzyyys
Copy link
Collaborator

bidzyyys commented Jun 4, 2025

@knelsondev are you going to work on this PR?

@knelsondev
Copy link
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

@0xNeshi 0xNeshi closed this Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: ERC20Wrapper::decimals should match Solidity version
3 participants