Skip to content

Add support for custom units#302

Merged
kclowes merged 11 commits into
ethereum:mainfrom
Roman505050:main
Apr 14, 2025
Merged

Add support for custom units#302
kclowes merged 11 commits into
ethereum:mainfrom
Roman505050:main

Conversation

@Roman505050

@Roman505050 Roman505050 commented Mar 28, 2025

Copy link
Copy Markdown
Contributor

What was wrong?

The addition of integer support allows for more flexibility when handling units with varying decimal places. Tokens on blockchains often use different precisions (e.g., 6, 18 decimals), and using integers to specify these decimal places ensures accurate conversions. This enhancement improves handling of token values with varying decimal precision.

How was it fixed?

Support for integer-based unit values was added. This allows specifying the number of decimal places directly as an integer (e.g., from_wei(123456789, 6)), ensuring accurate conversions and improving flexibility in handling tokens with different decimal precisions.

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

image

@kclowes kclowes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I'd rather see this as a new function instead of co-opting to/from_wei. Are you up for making that change instead?

@Roman505050

Copy link
Copy Markdown
Contributor Author

I think I'd rather see this as a new function instead of co-opting to/from_wei. Are you up for making that change instead?

Yes, of course. I will soon make these change in PR.

@kclowes

kclowes commented Apr 3, 2025

Copy link
Copy Markdown
Contributor

Thank you!

@Roman505050

Roman505050 commented Apr 3, 2025

Copy link
Copy Markdown
Contributor Author

I created auxiliary private functions (_from_wei, _to_wei) as I use in the following functions, because the logic was very similar. I also thought about a clear name for the new functions and decided to stop at from/to_wei_decimals. I decided to choose “decimals” because it comes more from the ERC-20 standard, where such a name is often used. Maybe you have some ideas?

@Roman505050 Roman505050 requested a review from kclowes April 3, 2025 17:01

@fselmo fselmo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm. Thanks @Roman505050 👍🏼

@kclowes

kclowes commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

I decided to choose “decimals” because it comes more from the ERC-20 standard, where such a name is often used. Maybe you have some ideas?

I like that name. Thanks for the PR @Roman505050!

@kclowes kclowes merged commit b8f5b85 into ethereum:main Apr 14, 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.

3 participants