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

mv poolBalances to regular mapping and array #708

Merged
merged 12 commits into from
Jul 5, 2024

Conversation

elshan-eth
Copy link
Contributor

Description

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests have 100% code coverage
  • The base branch is either main, or there's a description of how to merge

Issue Resolution

Copy link

openzeppelin-code bot commented Jul 1, 2024

mv poolBalances to regular mapping and array

Generated at commit: 301c3017947f2458a0418b5441cdf60f1494f435

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
2
2
0
11
37
52
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

@elshan-eth elshan-eth marked this pull request as ready for review July 1, 2024 17:26
@elshan-eth elshan-eth requested review from jubeira, EndymionJkb and joaobrunoah and removed request for jubeira July 1, 2024 17:26
Copy link
Contributor

@joaobrunoah joaobrunoah left a comment

Choose a reason for hiding this comment

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

I see that it improves swaps when there are fees, which is cool!
I just left a suggestion, but it looks great!

Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

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

Odd that it seems to make the bytecode go up? (Maybe they were stale somehow?)

Some comments on the errors - and style conventions.

pkg/vault/contracts/VaultExtension.sol Outdated Show resolved Hide resolved
pkg/interfaces/contracts/vault/IVaultErrors.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/VaultExtension.sol Show resolved Hide resolved
pkg/vault/contracts/VaultExtension.sol Show resolved Hide resolved
pkg/vault/contracts/VaultExtension.sol Show resolved Hide resolved
@EndymionJkb
Copy link
Collaborator

Maybe title this "Move..." We don't need to save bytecode in PR titles :)

Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

Nicely done @elshan-eth, looks great! The optimizoooor badge is totally yours :)

I'll do one more pass after the remaining comments are addressed. I'd like to take a look at the existing tests to double check that we're not modifying functions that are lacking tests.

pkg/vault/contracts/VaultExtension.sol Outdated Show resolved Hide resolved
elshan-eth and others added 2 commits July 4, 2024 20:10
Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

Great job @elshan-eth !

I have a few comments, mostly minor, that I'd like to see addressed before proceeding.

Otherwise looks great; good gas savings and very sound idea! Thanks for pushing it :)

pkg/interfaces/contracts/vault/IVaultErrors.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/VaultExtension.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/VaultExtension.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/VaultExtension.sol Outdated Show resolved Hide resolved
@@ -75,7 +75,8 @@ contract VaultStorage {
// Pool -> (token -> PackedTokenBalance): structure containing the current raw and "last live" scaled balances.
// Last live balances are used for yield fee computation, and since these have rates applied, they are stored
// as scaled 18-decimal FP values. Each value takes up half the storage slot (i.e., 128 bits).
mapping(address => EnumerableMap.IERC20ToBytes32Map) internal _poolTokenBalances;
mapping(address => mapping(uint256 => bytes32)) internal _poolTokenBalances;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking it'd make sense to use a custom type instead of bytes32 here (e.g. PackedBalances)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can do this in another PR because it seems like a big change for this PR. Is it ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed!

pkg/vault/contracts/test/VaultMock.sol Show resolved Hide resolved
Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

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

Looks good to go once comments are addressed (type abbreviations, error handling, etc.)

Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

Nice! Looking good; just a few minor comments now that we've changed the approach with _findTokenIndex that might save a few bytes.

pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/Vault.sol Outdated Show resolved Hide resolved
Comment on lines 323 to 326

/// @dev Token not found in the token array.
error TokenNotFound(IERC20 token);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd reuse TokenNotRegistered (maybe adding the token argument)

pkg/vault/contracts/VaultCommon.sol Outdated Show resolved Hide resolved
pkg/vault/contracts/VaultCommon.sol Outdated Show resolved Hide resolved
@jubeira jubeira merged commit ea3f5cb into main Jul 5, 2024
12 checks passed
@jubeira jubeira deleted the remove-enumerable-map-for-pool-balances branch July 5, 2024 21:11
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.

4 participants