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

feat: use mapping instead of array for oracle observations #221

Merged
merged 5 commits into from
Jan 23, 2024

Conversation

xenide
Copy link
Contributor

@xenide xenide commented Jan 22, 2024

Motivation

  • inspiration came from balancer as they use a mapping to simulate an array
  • UniV3 still uses an array of size 65535 (one less than uint16.max)
  • since our use case is the same, always knowing the index, I thought it'd be more efficient to use a mapping over an array
  • Arrays would make sense if each element is smaller than a word

Solution

  • it is indeed more gas efficient. Will upload the snapshot after the previous PR is merged
  • also tested with uint16 as the input type instead of uint256. But the gas changes are a mixed bag. Therefore not proceeding with that change

@xenide xenide changed the title feat: use mapping over array feat: use mapping instead of array for oracle observations Jan 22, 2024
Copy link
Contributor

@OliverNChalk OliverNChalk left a comment

Choose a reason for hiding this comment

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

approved assuming it's cheaper

@xenide xenide force-pushed the feat/use-mapping-over-array branch from f7784a2 to 89ba783 Compare January 23, 2024 01:17
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c066d02) 68.21% compared to head (f292008) 68.21%.

❗ Current head f292008 differs from pull request most recent head 99cf211. Consider uploading reports for the commit 99cf211 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #221   +/-   ##
=======================================
  Coverage   68.21%   68.21%           
=======================================
  Files          12       12           
  Lines         623      623           
=======================================
  Hits          425      425           
  Misses        198      198           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -924,7 +924,7 @@ contract StablePairTest is BaseTest {
bytes32 lEncoded = bytes32(abi.encodePacked(lLastInvariantAmp, lLastInvariant));
// hardcoding the slot for now as there is no way to access it publicly
// this will break when we change the storage layout
vm.store(address(_stablePair), bytes32(uint256(65_553)), lEncoded);
vm.store(address(_stablePair), bytes32(uint256(18)), lEncoded);
Copy link
Contributor Author

@xenide xenide Jan 23, 2024

Choose a reason for hiding this comment

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

had to change the storage slot as the storage layout has changed cuz we're no longer using an array for _observations

@xenide xenide force-pushed the feat/use-mapping-over-array branch 2 times, most recently from f292008 to 96520d1 Compare January 23, 2024 06:17
@xenide xenide force-pushed the feat/use-mapping-over-array branch from 96520d1 to 99cf211 Compare January 23, 2024 06:23
@xenide xenide marked this pull request as ready for review January 23, 2024 06:30
@xenide xenide merged commit 5fe192e into dev Jan 23, 2024
8 of 9 checks passed
@xenide xenide deleted the feat/use-mapping-over-array branch January 23, 2024 06:31
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.

2 participants