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

Create an id lib function for memory or storage variables #144

Closed
MerlinEgalite opened this issue Jul 18, 2023 · 8 comments · Fixed by #152
Closed

Create an id lib function for memory or storage variables #144

MerlinEgalite opened this issue Jul 18, 2023 · 8 comments · Fixed by #152
Assignees
Labels

Comments

@MerlinEgalite
Copy link
Contributor

MerlinEgalite commented Jul 18, 2023

          Updating the test suite to use `toId` would have been a small change & small improvement. This refactoring looks great as is.

Originally posted by @Rubilmax in #134 (review)

The id helper function cannot be used for storage or memory variable.

Aave did the same in their libraries.

@Rubilmax
Copy link
Collaborator

Anything that gives integrators (including us in our test suite) the ability to mimick the behavior of the id function on Market storage/memory structs is fine for me. I have no requirement on the naming or location of it (a priori).

@QGarchery
Copy link
Contributor

I agree that this is something that should be provided, and we could batch similar requests:

@MerlinEgalite MerlinEgalite self-assigned this Jul 18, 2023
@MathisGD
Copy link
Contributor

  • supply balances and borrow balances, as it is done in the tests here at the moment

at the moment there is no consensus on this one (#3)

@MathisGD
Copy link
Contributor

By the way, have we thought about asking for the market in memory directly in Blue ?

@MathisGD
Copy link
Contributor

By the way, have we thought about asking for the market in memory directly in Blue ?

I just gave it a try, it seems to not increase the gas cost so maybe we are better of doing this

@Rubilmax
Copy link
Collaborator

Rubilmax commented Jul 19, 2023

I just gave it a try, it seems to not increase the gas cost so maybe we are better of doing this

This highlights that it's mostly a syntax thing, so I'm ok with this. (I understand that under specific conditions, calldata & memory wouldn't be equivalent in gas cost, but here it is - most likely because of optimization at compilation).

This answers where we'd store an id function that converts a memory Market struct into its id. But it doesn't solve the issue for the storage Market structs: we either need another function, or another library.

Note that overloading the id function in the same library, so we can use it both on memory, calldata and/or storage Market struct, doesn't work. Using both functions wouldn't compile for example (solidity 0.20.0). I believe the first defined function takes precedence over the second.

@MerlinEgalite
Copy link
Contributor Author

MerlinEgalite commented Jul 19, 2023

Note that there is a more notable difference between calldata and memory on L2s that we must check as well

@MathisGD
Copy link
Contributor

This answers where we'd store an id function that converts a memory Market struct into its id. But it doesn't solve the issue for the storage Market structs: we either need another function, or another library.

Indeed. And same for calldata actually. But storage and calldata can easily be stored in memory. This is a bit annoying to write dead code.. but not a huge deal neither.

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 a pull request may close this issue.

4 participants