Skip to content

Instantly share code, notes, and snippets.

@mudgen
Created July 23, 2021 20:48
Show Gist options
  • Select an option

  • Save mudgen/d8ee3cc0e0b5131a452457e7aeeb3bf6 to your computer and use it in GitHub Desktop.

Select an option

Save mudgen/d8ee3cc0e0b5131a452457e7aeeb3bf6 to your computer and use it in GitHub Desktop.
//LibAppStorage.sol
struct AppStorage {
uint256 secondVar;
uint256 firstVar;
uint256 lastVar;
...
}
library LibAppStorage {
function diamondStorage()
internal
pure
returns (AppStorage storage ds) {
assembly {
ds.slot := 0
}
}
function myLibraryFunction() internal {
AppStorage storage s = LibAppStorage.diamondStorage();
s.lastVar = s.firstVar + s.secondVar;
}
function myLibraryFunction2(AppStorage storage s) internal {
s.lastVar = s.firstVar + s.secondVar;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment