namespaced-storage.js 583 B

12345678910111213141516171819202122
  1. const { ethers, artifacts } = require('hardhat');
  2. const { erc7201slot } = require('./erc1967');
  3. function namespaceId(contractName) {
  4. return `openzeppelin.storage.${contractName}`;
  5. }
  6. function namespaceSlot(contractName, offset) {
  7. try {
  8. // Try to get the artifact paths, will throw if it doesn't exist
  9. artifacts._getArtifactPathSync(`${contractName}Upgradeable`);
  10. return offset + ethers.toBigInt(erc7201slot(namespaceId(contractName)));
  11. } catch (_) {
  12. return offset;
  13. }
  14. }
  15. module.exports = {
  16. namespaceSlot,
  17. namespaceLocation: erc7201slot,
  18. namespaceId,
  19. };