Skip to content

Instantly share code, notes, and snippets.

@mudgen
Created July 23, 2021 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mudgen/ec79627eda4b3f77d047697cb565796c to your computer and use it in GitHub Desktop.
Save mudgen/ec79627eda4b3f77d047697cb565796c 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;
}
}
contract Test {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment