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

Add SafeCast for all possible uintX types #3159

Closed
k06a opened this issue Feb 1, 2022 · 4 comments · Fixed by #3245
Closed

Add SafeCast for all possible uintX types #3159

k06a opened this issue Feb 1, 2022 · 4 comments · Fixed by #3245
Assignees
Milestone

Comments

@k06a
Copy link
Contributor

k06a commented Feb 1, 2022

🧐 Motivation
These methods are required when optimizing and tightly packing storage variables. We often use uint40 or uint48 for time and uint216/uint208 for the rest slot value, uint112 or uint96 (presented) for storing token amounts etc

@Amxx Amxx self-assigned this Feb 2, 2022
@Amxx
Copy link
Collaborator

Amxx commented Feb 2, 2022

Hello @k06a and thanks for the suggestion

The casting contract contains a lot of code repetition. Ideally, we would have generics (c++ templates) supported by solidity ... but we don't live in that world. So we wait for requests, and we add them one at a time, which we probably both agree is not the right way to do.

IMO, these contracts should be generated procedurally, just like I did in this repo a few years ago (https://github.com/Amxx/SolStruct). @frangio would you be open to that idea?

@frangio
Copy link
Contributor

frangio commented Feb 2, 2022

Yes as long as they are all tested. What would that look like? Do we write a script and then commit the resulting Solidity file to the repository?

If we add all of the 32 functions we may want to review the documentation approach. Having virtually the same docstring for all 32 functions just adds noise.

@frangio
Copy link
Contributor

frangio commented Feb 2, 2022

Just took a look at SolStruct. I wouldn't follow this approach, it's too custom. I think either we use solpp or we just write a simple JavaScript program to generate the code (without using templates).

@Amxx
Copy link
Collaborator

Amxx commented Feb 2, 2022

Yes, I would have gone for a JS generator. SolStruct was just an example of procedural generation.

@frangio frangio mentioned this issue Feb 2, 2022
1 task
@frangio frangio added this to the 4.7 milestone Mar 21, 2022
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 a pull request may close this issue.

3 participants