Skip to content

Commit c053dd4

Browse files
authored
Merge pull request #34 from maxnorm/docs/auto-generated-31
[DOCS] Auto-generated Docs Pages
2 parents 20918ed + 7e106b7 commit c053dd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1095
-1078
lines changed

website/docs/library/access/AccessControl/AccessControlFacet.mdx

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ Manages role-based access control within a diamond.
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
28-
- Role-based access control (RBAC) implementation.
29-
- Supports granting and revoking roles for individual accounts and batches.
30-
- Allows for defining role administrators to manage role assignments.
31-
- Emits events for role changes for off-chain monitoring.
28+
- Role-based access control for granular permission management.
29+
- Support for batch granting and revoking roles.
30+
- Extensible with other access control facets like `AccessControlPausableFacet`.
3231
</Callout>
3332

3433
## Overview
3534

36-
The AccessControlFacet provides a robust framework for implementing role-based access control (RBAC) within a Compose diamond. It allows for granular permission management by defining roles, assigning them to accounts, and enforcing role requirements for function execution. This facet is crucial for securing sensitive operations and ensuring that only authorized entities can perform specific actions.
35+
The AccessControlFacet provides a robust role-based access control (RBAC) system for Compose diamonds. It allows for granular permission management by defining roles and assigning them to accounts. This facet is crucial for securing sensitive functions and orchestrating complex interactions by enforcing role requirements.
3736

3837
---
3938

@@ -478,58 +477,49 @@ error AccessControlUnauthorizedSender(address _sender, address _account);
478477
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
479478
{`pragma solidity ^0.8.30;
480479
481-
import { DiamondAccessControl } from "@compose/access/DiamondAccessControl";
482-
import { AccessControlFacet } from "@compose/access/AccessControl/AccessControlFacet";
483-
import { AccessControlStorage } from "@compose/access/AccessControl/AccessControlStorage";
480+
import {DiamondInit} from "@compose/diamond/DiamondInit.sol";
481+
import {DiamondCut} from "@compose/diamond/DiamondCut.sol";
482+
import {AccessControlFacet} from "@compose/access/AccessControl/AccessControlFacet.sol";
483+
import {Diamond} from "@compose/diamond/Diamond.sol";
484484
485-
contract MyDiamond is DiamondAccessControl {
486-
bytes32 constant ACCESS_CONTROL_STORAGE_POSITION = keccak256("compose.accesscontrol");
485+
contract DeployDiamondWithAccessControl is DiamondInit {
486+
// Define roles
487+
bytes32 constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
488+
bytes32 constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
487489
488-
// Example Role Definitions
489-
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
490-
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
490+
function deploy() external {
491+
// ... diamond deployment logic ...
491492
492-
constructor(address _diamondAdmin, address _owner) DiamondAccessControl(_diamondAdmin, _owner) {
493493
// Initialize AccessControlFacet
494-
AccessControlFacet acFacet = AccessControlFacet(address(this));
495-
acFacet.grantRole(ADMIN_ROLE, _diamondAdmin);
496-
acFacet.grantRole(ADMIN_ROLE, _owner);
497-
acFacet.grantRole(MINTER_ROLE, _owner);
498-
}
494+
AccessControlFacet accessControlFacet = AccessControlFacet(diamondAddress);
495+
accessControlFacet.grantRole(ADMIN_ROLE, msg.sender); // Grant admin role to deployer
496+
accessControlFacet.grantRole(OPERATOR_ROLE, address(this)); // Grant operator role to diamond itself
499497
500-
// Function to grant MINTER_ROLE to an address
501-
function grantMinterRole(address _account) external {
502-
AccessControlFacet acFacet = AccessControlFacet(address(this));
503-
acFacet.grantRole(MINTER_ROLE, _account);
498+
// ... other facet initializations ...
504499
}
505500
506-
// Function that requires MINTER_ROLE
507-
function mintTokens(address _to, uint256 _amount) external {
508-
AccessControlFacet acFacet = AccessControlFacet(address(this));
509-
acFacet.requireRole(MINTER_ROLE, msg.sender);
510-
// ... token minting logic ...
511-
}
501+
// Example of calling a protected function using requireRole
502+
function executeProtectedAction() external {
503+
AccessControlFacet accessControlFacet = AccessControlFacet(diamondAddress);
504+
accessControlFacet.requireRole(OPERATOR_ROLE, msg.sender);
512505
513-
// Function to get role admin
514-
function getAdminForRole(bytes32 _role) external view returns (bytes32) {
515-
AccessControlFacet acFacet = AccessControlFacet(address(this));
516-
return acFacet.getRoleAdmin(_role);
506+
// ... protected action logic ...
517507
}
518508
}`}
519509
</ExpandableCode>
520510

521511
## Best Practices
522512

523513
<Callout type="tip" title="Best Practice">
524-
- Initialize roles and grant initial permissions during diamond deployment or upgrade initialization.
525-
- Define role hierarchies using `setRoleAdmin` to ensure proper administrative control.
526-
- Utilize `requireRole` within functions to enforce access control checks, reverting with specific errors if unauthorized.
514+
- Initialize roles and grant them to appropriate accounts during diamond deployment.
515+
- Use `grantRoleBatch` and `revokeRoleBatch` for efficient mass role management.
516+
- Define clear hierarchies for roles using `setRoleAdmin` to manage administrative privileges.
527517
</Callout>
528518

529519
## Security Considerations
530520

531521
<Callout type="warning" title="Security">
532-
Ensure that sensitive roles, such as `ADMIN_ROLE`, are only granted to trusted addresses. The `setRoleAdmin` function's access control is enforced by the current role administrator, preventing unauthorized changes to role hierarchies. Batch operations (`grantRoleBatch`, `revokeRoleBatch`) should be used cautiously to avoid unintended mass role modifications. Reentrancy is not a direct concern as functions operate on state and do not make external calls without proper checks.
522+
Ensure that role administration is properly secured. The `setRoleAdmin`, `grantRole`, and `revokeRole` functions require the caller to be the admin of the role. Reentrancy is mitigated as role modifications are atomic. Input validation is handled internally by the facet to prevent invalid role or account assignments.
533523
</Callout>
534524

535525
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -573,4 +563,4 @@ Ensure that sensitive roles, such as `ADMIN_ROLE`, are only granted to trusted a
573563
<WasThisHelpful pageId="AccessControlFacet" />
574564
</div>
575565

576-
<LastUpdated date="2025-12-30T15:37:57.431Z" />
566+
<LastUpdated date="2025-12-30T15:54:26.223Z" />

website/docs/library/access/AccessControl/AccessControlMod.mdx

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 1
33
title: "AccessControlMod"
4-
description: "Manages role-based access control for diamond operations."
4+
description: "Manages roles and permissions within a diamond."
55
gitSource: "https://github.com/Perfect-Abstractions/Compose/tree/main/src/access/AccessControl/AccessControlMod.sol"
66
---
77

@@ -21,14 +21,14 @@ import GradientText from '@site/src/components/ui/GradientText';
2121
import GradientButton from '@site/src/components/ui/GradientButton';
2222

2323
<DocSubtitle>
24-
Manages role-based access control for diamond operations.
24+
Manages roles and permissions within a diamond.
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
28-
- Role-based access control (RBAC) for granular permissions.
29-
- Functions for granting, revoking, and checking roles (`grantRole`, `revokeRole`, `hasRole`).
30-
- Built-in reversion with `AccessControlUnauthorizedAccount` error for unauthorized access attempts.
31-
- Supports setting administrative roles for managing other roles.
28+
- Permission management via roles assigned to accounts.
29+
- Ability to grant and revoke roles dynamically.
30+
- Built-in check for role existence with `hasRole`.
31+
- Revert mechanism for unauthorized access attempts via `requireRole`.
3232
</Callout>
3333

3434
<Callout type="info" title="Module Usage">
@@ -37,7 +37,7 @@ This module provides internal functions for use in your custom facets. Import it
3737

3838
## Overview
3939

40-
This module provides a robust role-based access control (RBAC) system, enabling granular permission management within your diamond. By composing this module, you can define roles and assign them to addresses, ensuring that only authorized accounts can execute sensitive functions. This enhances security and maintainability by centralizing access logic.
40+
The AccessControl module provides a robust system for managing roles and permissions, ensuring that only authorized accounts can perform specific actions. This is crucial for maintaining security and control within a Compose diamond by enabling granular access delegation and revocation.
4141

4242
---
4343

@@ -403,40 +403,47 @@ error AccessControlUnauthorizedAccount(address _account, bytes32 _role);
403403
{`pragma solidity ^0.8.30;
404404
405405
import { AccessControlMod } from "@compose/access/AccessControl/AccessControlMod";
406-
import { DiamondStorage } from "@compose/diamond/DiamondStorage";
406+
import { AccessControlStorage } from "@compose/access/AccessControl/AccessControlStorage";
407407
408408
contract MyFacet {
409409
AccessControlMod internal accessControl;
410410
411-
function initialize(DiamondStorage storage _diamondStorage) public {
412-
accessControl = AccessControlMod(_diamondStorage.getFacetAddress(keccak256("compose.accesscontrol")));
411+
// Assuming AccessControlMod is initialized and its storage slot is known
412+
constructor(address _diamondProxy) {
413+
// Fetch storage location from the diamond proxy
414+
address accessControlAddress = _diamondProxy; // Example: If AccessControlMod is a facet itself
415+
accessControl = AccessControlMod(accessControlAddress);
413416
}
414417
415-
bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
418+
function grantAdminRole(address _account) external {
419+
bytes32 adminRole = keccak256("AccessControl.ADMIN_ROLE"); // Example role
420+
accessControl.grantRole(adminRole, _account);
421+
}
416422
417-
function grantMyRole(address _account) external {
418-
accessControl.grantRole(MY_ROLE, _account);
423+
function checkAdminRole(address _account) view external returns (bool) {
424+
bytes32 adminRole = keccak256("AccessControl.ADMIN_ROLE"); // Example role
425+
return accessControl.hasRole(adminRole, _account);
419426
}
420427
421-
function doRestrictedAction() external {
422-
accessControl.requireRole(MY_ROLE, msg.sender);
423-
// ... perform restricted action
428+
function enforceAdminRole(address _account) view external {
429+
bytes32 adminRole = keccak256("AccessControl.ADMIN_ROLE"); // Example role
430+
accessControl.requireRole(adminRole, _account);
424431
}
425432
}`}
426433
</ExpandableCode>
427434

428435
## Best Practices
429436

430437
<Callout type="tip" title="Best Practice">
431-
- Define roles using `bytes32` constants and manage them consistently across facets.
432-
- Use `requireRole` within facet functions to enforce access control checks inline.
433-
- Leverage `setRoleAdmin` to manage role administration hierarchies for enhanced security.
438+
- Define roles using `bytes32` and `keccak256` for clarity and gas efficiency.
439+
- Use `requireRole` for immediate enforcement of permissions within functions.
440+
- Carefully manage the administration of roles using `setRoleAdmin` to prevent unintended privilege escalation.
434441
</Callout>
435442

436443
## Integration Notes
437444

438445
<Callout type="success" title="Shared Storage">
439-
The `AccessControlMod` is designed to be integrated into a Compose diamond using the diamond storage pattern. Its storage is located at the slot identified by `STORAGE_POSITION`, which is `keccak256("compose.accesscontrol")`. Facets can retrieve the `AccessControlMod` contract instance using `_diamondStorage.getFacetAddress(keccak256("compose.accesscontrol"))` and then interact with its functions. The `AccessControlStorage` struct is empty, indicating that the module manages its state internally or through a separate mechanism managed by the diamond's initialization process.
446+
The AccessControl module utilizes the diamond storage pattern, storing its state at a well-defined slot identified by `keccak256("compose.accesscontrol")`. Facets can access this state by calling the `getStorage()` function or directly interacting with the module's functions, which implicitly read from this storage slot. Ensure that the AccessControl module is correctly initialized and its storage slot is reserved to avoid conflicts with other modules.
440447
</Callout>
441448

442449
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -474,4 +481,4 @@ The `AccessControlMod` is designed to be integrated into a Compose diamond using
474481
<WasThisHelpful pageId="AccessControlMod" />
475482
</div>
476483

477-
<LastUpdated date="2025-12-30T15:37:52.074Z" />
484+
<LastUpdated date="2025-12-30T15:54:22.483Z" />

website/docs/library/access/AccessControl/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Icon from '@site/src/components/ui/Icon';
2121
/>
2222
<DocCard
2323
title="AccessControlMod"
24-
description={"Manages role-based access control for diamond operations."}
24+
description={"Manages roles and permissions within a diamond."}
2525
href="/docs/library/access/AccessControl/AccessControlMod"
2626
icon={<Icon name="book" size={28} />}
2727
size="medium"

website/docs/library/access/AccessControlPausable/AccessControlPausableFacet.mdx

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 2
33
title: "AccessControlPausableFacet"
4-
description: "Manages role-based pausing and unpausing of operations."
4+
description: "Control role access and pause/unpause specific roles."
55
gitSource: "https://github.com/Perfect-Abstractions/Compose/tree/main/src/access/AccessControlPausable/AccessControlPausableFacet.sol"
66
---
77

@@ -21,19 +21,18 @@ import GradientText from '@site/src/components/ui/GradientText';
2121
import GradientButton from '@site/src/components/ui/GradientButton';
2222

2323
<DocSubtitle>
24-
Manages role-based pausing and unpausing of operations.
24+
Control role access and pause/unpause specific roles.
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
28-
- Role-specific pausing and unpausing of operations.
29-
- Integration with diamond's access control for administrative actions.
30-
- Emits `RolePaused` and `RoleUnpaused` events for state changes.
31-
- Reverts with specific errors for unauthorized access and paused roles.
28+
- Allows pausing and unpausing of specific roles, preventing execution of role-bound functions.
29+
- Integrates seamlessly with existing AccessControl mechanisms.
30+
- Provides view functions to check the current paused status of any role.
3231
</Callout>
3332

3433
## Overview
3534

36-
This facet provides granular control over role execution by allowing specific roles to be temporarily paused. It integrates with the diamond's access control system to ensure only authorized entities can manage pause states. This enables flexible operational control and emergency stops for critical functions.
35+
This facet provides granular control over role-based access, allowing specific roles to be temporarily paused. It integrates with the core AccessControl logic to enforce role permissions and adds a pausing mechanism for enhanced operational flexibility. Use this facet to manage temporary disruptions or maintenance periods for specific functionalities tied to roles.
3736

3837
---
3938

@@ -283,43 +282,59 @@ error AccessControlRolePaused(bytes32 _role);
283282
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
284283
{`pragma solidity ^0.8.30;
285284
286-
import { Diamond } from "@compose/core/Diamond.sol";
287-
import { AccessControlPausableFacet } from "@compose/access/AccessControlPausable/AccessControlPausableFacet.sol";
288-
import { AccessControlFacet } from "@compose/access/AccessControl/AccessControlFacet.sol";
285+
import { Diamond } from "@compose/diamond/Diamond";
286+
import { AccessControlPausableFacet } from "@compose/access/AccessControlPausable/AccessControlPausableFacet";
287+
import { AccessControlFacet } from "@compose/access/AccessControl/AccessControlFacet";
289288
290289
contract MyDiamond is Diamond {
291-
constructor(address _diamondAdmin, address[] memory _initFacets, bytes[] memory _initCalldata) Diamond(_diamondAdmin, _initFacets, _initCalldata) {}
290+
constructor(address _diamondAdmin) Diamond( _diamondAdmin) {
291+
// ... deployment logic ...
292+
}
292293
293-
function pauseMyRole() external {
294-
AccessControlPausableFacet(address(this)).pauseRole("MY_ROLE");
294+
function upgrade() public {
295+
// Example: Adding AccessControlPausableFacet
296+
address[] memory facetsToAdd = new address[](1);
297+
facetsToAdd[0] = address(new AccessControlPausableFacet());
298+
299+
bytes[] memory selectorsToAdd = new bytes[](3);
300+
selectorsToAdd[0] = AccessControlPausableFacet.pauseRole.selector;
301+
selectorsToAdd[1] = AccessControlPausableFacet.unpauseRole.selector;
302+
selectorsToAdd[2] = AccessControlPausableFacet.isRolePaused.selector;
303+
304+
facetCut(facetsToAdd, selectorsToAdd, new address[](0), new bytes[](0));
295305
}
296306
297-
function unpauseMyRole() external {
298-
AccessControlPausableFacet(address(this)).unpauseRole("MY_ROLE");
307+
function pauseMyRole() external {
308+
AccessControlPausableFacet pausableFacet = AccessControlPausableFacet(address(this));
309+
bytes32 myRole = keccak256("MY_ROLE");
310+
pausableFacet.pauseRole(myRole);
299311
}
300312
301-
function checkMyRolePauseStatus(bytes32 _role) external view returns (bool) {
302-
return AccessControlPausableFacet(address(this)).isRolePaused(_role);
313+
function unpauseMyRole() external {
314+
AccessControlPausableFacet pausableFacet = AccessControlPausableFacet(address(this));
315+
bytes32 myRole = keccak256("MY_ROLE");
316+
pausableFacet.unpauseRole(myRole);
303317
}
304318
305-
function requireMyRoleNotPaused(bytes32 _role, address _account) external view {
306-
AccessControlPausableFacet(address(this)).requireRoleNotPaused(_role, _account);
319+
function checkRoleStatus(bytes32 _role) external view returns (bool) {
320+
AccessControlPausableFacet pausableFacet = AccessControlPausableFacet(address(this));
321+
return pausableFacet.isRolePaused(_role);
307322
}
308323
}`}
309324
</ExpandableCode>
310325

311326
## Best Practices
312327

313328
<Callout type="tip" title="Best Practice">
314-
- Initialize the facet with appropriate role administrators during diamond deployment.
315-
- Use `pauseRole` and `unpauseRole` judiciously to manage operational states, ensuring the caller has the necessary administrative privileges.
316-
- Leverage `requireRoleNotPaused` within other facets to conditionally gate functionality based on the operational status of a role.
329+
- Initialize or upgrade the diamond to include this facet to enable role pausing capabilities.
330+
- Ensure the caller invoking `pauseRole` and `unpauseRole` has the necessary administrative privileges for the target role.
331+
- Leverage `requireRoleNotPaused` within other facets or contract logic to dynamically enforce pausing states.
317332
</Callout>
318333

319334
## Security Considerations
320335

321336
<Callout type="warning" title="Security">
322-
Ensure that the administrative role capable of pausing and unpausing is properly secured. The `requireRoleNotPaused` function should be integrated into any facet function that relies on a role's operational status to prevent execution when paused. Reentrancy is not a concern as the functions are read-only or perform state changes without external calls.
337+
The `pauseRole` and `unpauseRole` functions are restricted to the admin of the respective role, preventing unauthorized pausing. The `requireRoleNotPaused` function reverts with `AccessControlRolePaused` if the role is paused, ensuring that paused roles cannot be utilized. Ensure that any critical functions protected by roles properly call `requireRoleNotPaused` or equivalent logic to respect the paused state.
323338
</Callout>
324339

325340
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -345,4 +360,4 @@ Ensure that the administrative role capable of pausing and unpausing is properly
345360
<WasThisHelpful pageId="AccessControlPausableFacet" />
346361
</div>
347362

348-
<LastUpdated date="2025-12-30T15:37:32.160Z" />
363+
<LastUpdated date="2025-12-30T15:54:02.317Z" />

0 commit comments

Comments
 (0)