Skip to content

Commit cd8dfae

Browse files
authored
Merge pull request #37 from maxnorm/docs/auto-generated-34
[DOCS] Auto-generated Docs Pages
2 parents dc61776 + 02f755a commit cd8dfae

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

+1476
-1140
lines changed

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

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 2
33
title: "AccessControlFacet"
4-
description: "Manages role-based access control within a diamond."
4+
description: "Role-based access control for diamond contracts"
55
gitSource: "https://github.com/Perfect-Abstractions/Compose/tree/main/src/access/AccessControl/AccessControlFacet.sol"
66
---
77

@@ -21,18 +21,19 @@ 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 within a diamond.
24+
Role-based access control for diamond contracts
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
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`.
28+
- Exposes external functions for role management and permission checking.
29+
- Integrates with diamond storage for persistent role data.
30+
- Supports batch operations for granting and revoking roles to multiple accounts.
31+
- Provides functions to check role membership and enforce role requirements.
3132
</Callout>
3233

3334
## Overview
3435

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.
36+
This facet implements role-based access control for Compose diamonds. It exposes external functions to manage roles and permissions, interacting with diamond storage. Developers add this facet to enforce access control policies across their diamond's functionality.
3637

3738
---
3839

@@ -472,54 +473,55 @@ error AccessControlUnauthorizedSender(address _sender, address _account);
472473
</Accordion>
473474
</AccordionGroup>
474475

476+
<!-- Usage Example section commented out for now -->
477+
<!--
475478
## Usage Example
476479

477480
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
478-
{`pragma solidity ^0.8.30;
481+
{`pragma solidity >=0.8.30;
479482
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";
483+
import { IDiamond } from "@compose/diamond/IDiamond.sol";
484+
import { AccessControlFacet } from "@compose/access/AccessControl/AccessControlFacet.sol";
484485
485-
contract DeployDiamondWithAccessControl is DiamondInit {
486-
// Define roles
487-
bytes32 constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
488-
bytes32 constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
486+
contract DiamondUser {
487+
address immutable diamondAddress;
489488
490-
function deploy() external {
491-
// ... diamond deployment logic ...
489+
constructor(address _diamondAddress) {
490+
diamondAddress = _diamondAddress;
491+
}
492492
493-
// Initialize AccessControlFacet
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
493+
function grantAdminRole(address _admin) external {
494+
IDiamond(diamondAddress).grantRole(AccessControlFacet.AccessControl.DEFAULT_ADMIN_ROLE(), _admin);
495+
}
497496
498-
// ... other facet initializations ...
497+
function checkAdminRole(address _account) external view returns (bool) {
498+
return IDiamond(diamondAddress).hasRole(AccessControlFacet.AccessControl.DEFAULT_ADMIN_ROLE(), _account);
499499
}
500500
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);
501+
function setRoleAdmin(bytes32 _role, bytes32 _adminRole) external {
502+
IDiamond(diamondAddress).setRoleAdmin(_role, _adminRole);
503+
}
505504
506-
// ... protected action logic ...
505+
function grantUserRole(bytes32 _role, address _user) external {
506+
IDiamond(diamondAddress).grantRole(_role, _user);
507507
}
508508
}`}
509509
</ExpandableCode>
510+
-->
510511

511512
## Best Practices
512513

513514
<Callout type="tip" title="Best Practice">
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.
515+
- Initialize role administration and grant initial roles during diamond deployment.
516+
- Use `grantRole` and `revokeRole` for individual account management.
517+
- Utilize `grantRoleBatch` and `revokeRoleBatch` for efficient management of multiple accounts.
518+
- Ensure that roles are properly defined and their admin roles are set to manage permissions effectively.
517519
</Callout>
518520

519521
## Security Considerations
520522

521523
<Callout type="warning" title="Security">
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.
524+
All state-changing functions (`setRoleAdmin`, `grantRole`, `revokeRole`, `grantRoleBatch`, `revokeRoleBatch`, `renounceRole`) require caller authorization, typically controlled by the role's admin role. The `requireRole` function reverts with `AccessControlUnauthorizedAccount` if the caller lacks the specified role. `renounceRole` reverts with `AccessControlUnauthorizedSender` if the caller is not the account attempting to renounce the role. Follow standard Solidity security practices for input validation.
523525
</Callout>
524526

525527
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -563,4 +565,4 @@ Ensure that role administration is properly secured. The `setRoleAdmin`, `grantR
563565
<WasThisHelpful pageId="AccessControlFacet" />
564566
</div>
565567

566-
<LastUpdated date="2025-12-30T15:54:26.223Z" />
568+
<LastUpdated date="2025-12-30T17:27:36.331Z" />

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 1
33
title: "AccessControlMod"
4-
description: "Manages roles and permissions within a diamond."
4+
description: "Manage roles and permissions across diamond facets"
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 roles and permissions within a diamond.
24+
Manage roles and permissions across diamond facets
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
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`.
28+
- Internal functions for facet integration.
29+
- Uses diamond storage pattern for shared state management.
30+
- No external dependencies, promoting composability.
31+
- Emits events for role changes, aiding off-chain monitoring.
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-
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.
40+
This module provides internal functions for managing role-based access control within a diamond proxy. Facets can import and use these functions to grant, revoke, and check roles using shared diamond storage. This ensures consistent access control logic across all facets that depend on this module.
4141

4242
---
4343

@@ -397,53 +397,53 @@ error AccessControlUnauthorizedAccount(address _account, bytes32 _role);
397397
</Accordion>
398398
</AccordionGroup>
399399

400+
<!-- Usage Example section commented out for now -->
401+
<!--
400402
## Usage Example
401403

402404
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
403405
{`pragma solidity ^0.8.30;
404406
405-
import { AccessControlMod } from "@compose/access/AccessControl/AccessControlMod";
406-
import { AccessControlStorage } from "@compose/access/AccessControl/AccessControlStorage";
407+
import {AccessControlMod, AccessControlStorage} from "@compose/access/AccessControl/AccessControlMod";
407408
408-
contract MyFacet {
409+
contract MyAccessFacet {
409410
AccessControlMod internal accessControl;
410411
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);
412+
// Assuming AccessControlMod is deployed and its storage is initialized
413+
function initialize(address _accessControlModAddress) external {
414+
accessControl = AccessControlMod(_accessControlModAddress);
416415
}
417416
418417
function grantAdminRole(address _account) external {
419-
bytes32 adminRole = keccak256("AccessControl.ADMIN_ROLE"); // Example role
418+
bytes32 adminRole = keccak256("COMPOSE_ADMIN_ROLE");
420419
accessControl.grantRole(adminRole, _account);
421420
}
422421
423-
function checkAdminRole(address _account) view external returns (bool) {
424-
bytes32 adminRole = keccak256("AccessControl.ADMIN_ROLE"); // Example role
422+
function checkIfAdmin(address _account) external view returns (bool) {
423+
bytes32 adminRole = keccak256("COMPOSE_ADMIN_ROLE");
425424
return accessControl.hasRole(adminRole, _account);
426425
}
427426
428-
function enforceAdminRole(address _account) view external {
429-
bytes32 adminRole = keccak256("AccessControl.ADMIN_ROLE"); // Example role
427+
function enforceAdminRole(address _account) external view {
428+
bytes32 adminRole = keccak256("COMPOSE_ADMIN_ROLE");
430429
accessControl.requireRole(adminRole, _account);
431430
}
432431
}`}
433432
</ExpandableCode>
433+
-->
434434

435435
## Best Practices
436436

437437
<Callout type="tip" title="Best Practice">
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.
438+
- Call `requireRole` to enforce access control checks before executing sensitive operations.
439+
- Ensure the diamond's storage layout is compatible with the `AccessControlStorage` struct.
440+
- Handle `AccessControlUnauthorizedAccount` errors to provide clear feedback to users.
441441
</Callout>
442442

443443
## Integration Notes
444444

445445
<Callout type="success" title="Shared Storage">
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.
446+
This module utilizes diamond storage at the slot identified by `keccak256("compose.accesscontrol")`. All functions operate on the `AccessControlStorage` struct, which is implicitly managed by the diamond storage pattern. Changes to roles made through this module are immediately visible to all facets that access the same storage slot.
447447
</Callout>
448448

449449
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -481,4 +481,4 @@ The AccessControl module utilizes the diamond storage pattern, storing its state
481481
<WasThisHelpful pageId="AccessControlMod" />
482482
</div>
483483

484-
<LastUpdated date="2025-12-30T15:54:22.483Z" />
484+
<LastUpdated date="2025-12-30T17:27:32.246Z" />

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import Icon from '@site/src/components/ui/Icon';
1414
<DocCardGrid columns={2}>
1515
<DocCard
1616
title="AccessControlFacet"
17-
description={"Manages role-based access control within a diamond."}
17+
description={"Role-based access control for diamond contracts"}
1818
href="/docs/library/access/AccessControl/AccessControlFacet"
1919
icon={<Icon name="book" size={28} />}
2020
size="medium"
2121
/>
2222
<DocCard
2323
title="AccessControlMod"
24-
description={"Manages roles and permissions within a diamond."}
24+
description={"Manage roles and permissions across diamond facets"}
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: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 2
33
title: "AccessControlPausableFacet"
4-
description: "Control role access and pause/unpause specific roles."
4+
description: "Manages role pausing and unpausing within a diamond"
55
gitSource: "https://github.com/Perfect-Abstractions/Compose/tree/main/src/access/AccessControlPausable/AccessControlPausableFacet.sol"
66
---
77

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

2323
<DocSubtitle>
24-
Control role access and pause/unpause specific roles.
24+
Manages role pausing and unpausing within a diamond
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
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.
28+
- Exposes external functions for pausing and unpausing specific roles.
29+
- Emits `RolePaused` and `RoleUnpaused` events for state changes.
30+
- Reverts with `AccessControlUnauthorizedAccount` if caller lacks permission to pause/unpause.
31+
- Reverts with `AccessControlRolePaused` when a paused role is accessed.
3132
</Callout>
3233

3334
## Overview
3435

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.
36+
This facet implements role-based pausing and unpausing for diamond functionality. It exposes external functions to control role states, ensuring operations can be temporarily halted or resumed. Developers integrate this facet to add granular control over role permissions within a diamond.
3637

3738
---
3839

@@ -277,64 +278,55 @@ error AccessControlRolePaused(bytes32 _role);
277278
</Accordion>
278279
</AccordionGroup>
279280

281+
<!-- Usage Example section commented out for now -->
282+
<!--
280283
## Usage Example
281284

282285
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
283-
{`pragma solidity ^0.8.30;
286+
{`pragma solidity >=0.8.30;
284287
285-
import { Diamond } from "@compose/diamond/Diamond";
288+
import { IDiamond } from "@compose/diamond/IDiamond";
286289
import { AccessControlPausableFacet } from "@compose/access/AccessControlPausable/AccessControlPausableFacet";
287-
import { AccessControlFacet } from "@compose/access/AccessControl/AccessControlFacet";
288290
289-
contract MyDiamond is Diamond {
290-
constructor(address _diamondAdmin) Diamond( _diamondAdmin) {
291-
// ... deployment logic ...
292-
}
293-
294-
function upgrade() public {
295-
// Example: Adding AccessControlPausableFacet
296-
address[] memory facetsToAdd = new address[](1);
297-
facetsToAdd[0] = address(new AccessControlPausableFacet());
291+
contract DiamondConsumer {
292+
address public immutable diamondAddress;
293+
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
298294
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;
295+
constructor(address _diamondAddress) {
296+
diamondAddress = _diamondAddress;
297+
}
303298
304-
facetCut(facetsToAdd, selectorsToAdd, new address[](0), new bytes[](0));
299+
function pauseAdminRole() external {
300+
IDiamond(diamondAddress).pauseRole(ADMIN_ROLE);
305301
}
306302
307-
function pauseMyRole() external {
308-
AccessControlPausableFacet pausableFacet = AccessControlPausableFacet(address(this));
309-
bytes32 myRole = keccak256("MY_ROLE");
310-
pausableFacet.pauseRole(myRole);
303+
function unpauseAdminRole() external {
304+
IDiamond(diamondAddress).unpauseRole(ADMIN_ROLE);
311305
}
312306
313-
function unpauseMyRole() external {
314-
AccessControlPausableFacet pausableFacet = AccessControlPausableFacet(address(this));
315-
bytes32 myRole = keccak256("MY_ROLE");
316-
pausableFacet.unpauseRole(myRole);
307+
function checkAdminRoleStatus(address _account) external view returns (bool) {
308+
return IDiamond(diamondAddress).isRolePaused(ADMIN_ROLE);
317309
}
318310
319-
function checkRoleStatus(bytes32 _role) external view returns (bool) {
320-
AccessControlPausableFacet pausableFacet = AccessControlPausableFacet(address(this));
321-
return pausableFacet.isRolePaused(_role);
311+
function enforceAdminRoleNotPaused(address _account) external view {
312+
IDiamond(diamondAddress).requireRoleNotPaused(ADMIN_ROLE, _account);
322313
}
323314
}`}
324315
</ExpandableCode>
316+
-->
325317

326318
## Best Practices
327319

328320
<Callout type="tip" title="Best Practice">
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.
321+
- Initialize roles and their pausing status during diamond deployment.
322+
- Enforce `requireRoleNotPaused` checks on sensitive external or internal functions.
323+
- Grant pausing capabilities only to authorized administrative roles.
332324
</Callout>
333325

334326
## Security Considerations
335327

336328
<Callout type="warning" title="Security">
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.
329+
All state-changing functions (`pauseRole`, `unpauseRole`) are protected by implicit access control checks handled by the diamond proxy's dispatch mechanism and the facet's internal logic, ensuring only authorized accounts can modify role pause states. The `requireRoleNotPaused` function includes checks for both account role membership and role pause status, reverting with appropriate errors (`AccessControlUnauthorizedAccount`, `AccessControlRolePaused`) to prevent unauthorized or paused role usage.
338330
</Callout>
339331

340332
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -360,4 +352,4 @@ The `pauseRole` and `unpauseRole` functions are restricted to the admin of the r
360352
<WasThisHelpful pageId="AccessControlPausableFacet" />
361353
</div>
362354

363-
<LastUpdated date="2025-12-30T15:54:02.317Z" />
355+
<LastUpdated date="2025-12-30T17:27:10.923Z" />

0 commit comments

Comments
 (0)