Skip to content

feat(token): add SafeTRC20.tryGetDecimals and adopt it in TRC4626/TRC20Wrapper - #166

Merged
luiz-lvj merged 1 commit into
masterfrom
feat/safetrc20-try-get-decimals
Sep 16, 2026
Merged

luiz-lvj merged 1 commit into
masterfrom
feat/safetrc20-try-get-decimals

Conversation

@luiz-lvj

@luiz-lvj luiz-lvj commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Ports 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
luiz-lvj requested a review from pepebndc September 15, 2026 17:52
@luiz-lvj luiz-lvj changed the title feat(token): add tryGetDecimals to SafeTRC20 feat(token): add SafeTRC20.tryGetDecimals and adopt it in TRC4626/TRC20Wrapper Sep 15, 2026
@luiz-lvj
luiz-lvj force-pushed the feat/safetrc20-try-get-decimals branch from 736812c to 212bcb0 Compare September 15, 2026 18:42

@pepebndc pepebndc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

…/`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
luiz-lvj force-pushed the feat/safetrc20-try-get-decimals branch from 212bcb0 to 7cfd0ec Compare September 16, 2026 14:20
@luiz-lvj
luiz-lvj merged commit e3b48b0 into master Sep 16, 2026
18 checks passed
@luiz-lvj
luiz-lvj deleted the feat/safetrc20-try-get-decimals branch September 16, 2026 15:05
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.

2 participants