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

Bundle "segmentAmounts", "segmentExponents" and "segmentMilestones" into a single array of structs #223

Closed
PaulRBerg opened this issue Dec 30, 2022 · 0 comments

Comments

@PaulRBerg
Copy link
Member

It is true that it is not currently possible to copy an in-memory array to storage:

This means that we can't simply assign the segments function argument in a declarative way. If we do that, we would get the following error:

UnimplementedFeatureError: Copying of type struct Segment memory[] memory to storage not yet supported.

However, there is a solution, and that is to iterate over the in-memory array elements and use the push function to push each element, one-by-one, to the storage array:

ProStream storage stream = _streams[streamId];
// other assignments of struct properties
uint256 segmentCount = args.segments.length;
for (uint256 i = 0; i < segmentCount; ++i) {
    stream.segments.push(args.segments[i]);
}

There are several benefits in switching to an array of structs:

  1. Fewer function arguments, which helps with alleviating the StackTooDeep problem (re Segment[] array, comptroller, protocol and operator fees, structified parameters, via IR, PRBMath types, major tests refactor #220).
  2. Nicer, more encapsulated, less verbose API; segments is more succinct than segmentAmounts, segmentExponents, and segmentMilestones.
  3. Fewer errors to check in the checkCreateProArgs function, because we no longer have to ensure that the segment arrays are equal.
    • Consequently, fewer tests to write.
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

No branches or pull requests

1 participant