access-manager.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const { time } = require('@openzeppelin/test-helpers');
  2. const { MAX_UINT64 } = require('./constants');
  3. const { artifacts } = require('hardhat');
  4. function buildBaseRoles() {
  5. const roles = {
  6. ADMIN: {
  7. id: web3.utils.toBN(0),
  8. },
  9. SOME_ADMIN: {
  10. id: web3.utils.toBN(17),
  11. },
  12. SOME_GUARDIAN: {
  13. id: web3.utils.toBN(35),
  14. },
  15. SOME: {
  16. id: web3.utils.toBN(42),
  17. },
  18. PUBLIC: {
  19. id: MAX_UINT64,
  20. },
  21. };
  22. // Names
  23. Object.entries(roles).forEach(([name, role]) => (role.name = name));
  24. // Defaults
  25. for (const role of Object.keys(roles)) {
  26. roles[role].admin = roles.ADMIN;
  27. roles[role].guardian = roles.ADMIN;
  28. }
  29. // Admins
  30. roles.SOME.admin = roles.SOME_ADMIN;
  31. // Guardians
  32. roles.SOME.guardian = roles.SOME_GUARDIAN;
  33. return roles;
  34. }
  35. const formatAccess = access => [access[0], access[1].toString()];
  36. const MINSETBACK = time.duration.days(5);
  37. const EXPIRATION = time.duration.weeks(1);
  38. let EXECUTION_ID_STORAGE_SLOT = 3n;
  39. let CONSUMING_SCHEDULE_STORAGE_SLOT = 0n;
  40. try {
  41. // Try to get the artifact paths, will throw if it doesn't exist
  42. artifacts._getArtifactPathSync('AccessManagerUpgradeable');
  43. artifacts._getArtifactPathSync('AccessManagedUpgradeable');
  44. // ERC-7201 namespace location for AccessManager
  45. EXECUTION_ID_STORAGE_SLOT += 0x40c6c8c28789853c7efd823ab20824bbd71718a8a5915e855f6f288c9a26ad00n;
  46. // ERC-7201 namespace location for AccessManaged
  47. CONSUMING_SCHEDULE_STORAGE_SLOT += 0xf3177357ab46d8af007ab3fdb9af81da189e1068fefdc0073dca88a2cab40a00n;
  48. } catch (_) {
  49. // eslint-disable-next-line no-empty
  50. }
  51. module.exports = {
  52. buildBaseRoles,
  53. formatAccess,
  54. MINSETBACK,
  55. EXPIRATION,
  56. EXECUTION_ID_STORAGE_SLOT,
  57. CONSUMING_SCHEDULE_STORAGE_SLOT,
  58. };