feat(token): add SafeTRC20.tryGetDecimals and adopt it in TRC4626/TRC20Wrapper - #166
Merged
Merged
Conversation
tryGetDecimals to SafeTRC20SafeTRC20.tryGetDecimals and adopt it in TRC4626/TRC20Wrapper
luiz-lvj
force-pushed
the
feat/safetrc20-try-get-decimals
branch
from
September 15, 2026 18:42
736812c to
212bcb0
Compare
…/`TRC20Wrapper` ## Summary Ports [OpenZeppelin/openzeppelin-contracts#6482](OpenZeppelin/openzeppelin-contracts#6482) from openzeppelin-contracts 5.7.0, in full (the `ITRC20` input-type follow-up #6486 is already folded in). - **`SafeTRC20.tryGetDecimals(token)`** staticcalls a token's `decimals()` and returns `(false, 0)` instead of reverting when it has no `decimals()`, reverts, or returns a value that doesn't fit in `uint8`. - **`TRC4626`** now reads the underlying asset's decimals through `tryGetDecimals` in the constructor, replacing the bespoke `_tryGetAssetDecimals` helper. - **`TRC20Wrapper.decimals()`** uses `tryGetDecimals` with a branchless `Math.ternary`, replacing the `try/catch`. The now-unused `LowLevelCall`/`Memory` (TRC4626) and `ITRC20Metadata` (TRC20Wrapper) imports are dropped, matching the v5.7.0 end state (upstream removed them in the follow-up #6562, whose only other change is a `forge lint` CI step that is N/A for this repo's solhint-based CI).
luiz-lvj
force-pushed
the
feat/safetrc20-try-get-decimals
branch
from
September 16, 2026 14:20
212bcb0 to
7cfd0ec
Compare
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.
Summary
Ports OpenZeppelin/openzeppelin-contracts#6482 from openzeppelin-contracts 5.7.0, in full (the
ITRC20input-type follow-up #6486 is already folded in).SafeTRC20.tryGetDecimals(token)staticcalls a token'sdecimals()and returns(false, 0)instead of reverting when it has nodecimals(), reverts, or returns a value that doesn't fit inuint8.TRC4626now reads the underlying asset's decimals throughtryGetDecimalsin the constructor, replacing the bespoke_tryGetAssetDecimalshelper.TRC20Wrapper.decimals()usestryGetDecimalswith a branchlessMath.ternary, replacing thetry/catch.The now-unused
LowLevelCall/Memory(TRC4626) andITRC20Metadata(TRC20Wrapper) imports are dropped, matching the v5.7.0 end state (upstream removed them in the follow-up #6562, whose only other change is aforge lintCI step that is N/A for this repo's solhint-based CI).