Skip to content
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

feat: normalize native token decimals #100

Merged
merged 76 commits into from
Jul 3, 2024
Merged

feat: normalize native token decimals #100

merged 76 commits into from
Jul 3, 2024

Conversation

gzeoneth
Copy link
Member

@gzeoneth gzeoneth commented Dec 11, 2023

Was #65 but have decimal stored in bridge instead of inbox & outbox, also rebased the PR on main for fast-track release.

There is a scenario where custom fee token has number of decimals different than 18. That's not ideal because a lot of tooling assumes that native currency (on child chain) is using 18 decimals. For that reason we do a normalization, and de-normalization, when depositing and withdrawing native asset through native bridge.

Ie. let's say deposit amount is 752.

  • if token has 16 decimals normalized amount which is going to be minted on child chain is 75200
  • if token has 20 decimals normalized amount is 7
  • if token uses no decimals normalized amount is 752*10^18

When withdrawing, opposite process is done. There can be loss of precision, due to the fact that we have to round down amount to the nearest supported value.

We also add 2 requirements on the custom fee token in order to avoid overflow:

  • fee token can use at most 36 decimals (enforced at inbox/outbox initialization)
  • max amount that can be bridged is type(uint256).max / 10**18 which is ~1.1*10^59 tokens

Also use safeApprove in ERC20Inbox.init to support token like USDT that does not return data on approve

@cla-bot cla-bot bot added the s label Dec 11, 2023
@gvladika gvladika changed the base branch from main to develop May 15, 2024 08:27
src/rollup/RollupCreator.sol Dismissed Show dismissed Hide dismissed
@gzeoneth gzeoneth requested a review from yahgwai July 3, 2024 12:02
Copy link
Contributor

@gvladika gvladika left a comment

Choose a reason for hiding this comment

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

lgtm

@gzeoneth gzeoneth merged commit 2e90a05 into develop Jul 3, 2024
12 of 14 checks passed
@gzeoneth gzeoneth deleted the g-handle-decimals branch July 3, 2024 13:17
@gzeoneth gzeoneth mentioned this pull request Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants