Skip to content

Commit 607d51f

Browse files
authored
Merge pull request #32 from maxnorm/docs/auto-generated-29
[DOCS] Auto-generated Docs Pages
2 parents 8571a30 + 043f28b commit 607d51f

Some content is hidden

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

54 files changed

+1023
-1011
lines changed

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 2
33
title: "AccessControlFacet"
4-
description: "Manages roles and permissions within the diamond."
4+
description: "Manage roles and permissions within a diamond."
55
gitSource: "https://github.com/Perfect-Abstractions/Compose/tree/main/src/access/AccessControl/AccessControlFacet.sol"
66
---
77

@@ -21,19 +21,19 @@ 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 the diamond.
24+
Manage roles and permissions within a diamond.
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
28-
- Hierarchical role management with role admins.
29-
- Support for granting and revoking roles to individual accounts or in batches.
30-
- Built-in check functions (`hasRole`, `requireRole`) for easy permission verification.
31-
- Renounce role functionality for accounts to give up their own permissions.
28+
- Role-based access control (RBAC) for granular permissions.
29+
- Support for granting and revoking roles to/from accounts.
30+
- Batch operations for efficient role management of multiple accounts.
31+
- Default admin role for bootstrapping access control.
3232
</Callout>
3333

3434
## Overview
3535

36-
The AccessControlFacet provides a robust role-based access control (RBAC) system for Compose diamonds. It allows for granular permission management, enabling administrators to grant, revoke, and renounce roles for specific accounts. This facet is crucial for securing administrative functions and controlling access to sensitive operations within the diamond.
36+
The AccessControlFacet provides a robust role-based access control (RBAC) system. It allows defining roles, assigning them to accounts, and enforcing permissions based on these roles. This facet is crucial for orchestrating access to sensitive functions within a diamond, ensuring only authorized entities can perform specific actions.
3737

3838
---
3939

@@ -478,41 +478,42 @@ error AccessControlUnauthorizedSender(address _sender, address _account);
478478
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
479479
{`pragma solidity ^0.8.30;
480480
481-
import {DiamondProxy, DiamondCut} from "@compose/diamond-proxy/contracts/DiamondProxy.sol";
482-
import {AccessControlFacet} from "@compose/diamond-proxy/contracts/facets/AccessControlFacet.sol";
481+
import {DiamondLoupeFacet} from "@compose/diamond-loupe/contracts/DiamondLoupeFacet.sol";
482+
import {AccessControlFacet} from "@compose/access-control/contracts/AccessControlFacet.sol";
483483
484-
contract MyDiamond is DiamondProxy {
485-
function upgrade() external {
486-
// Assume diamondCut is already set up with the AccessControlFacet selector
487-
// and implementation address.
488-
// diamondCut.diamondCut(...);
484+
// Assume diamond is already deployed and functions are added
485+
contract Caller {
486+
address immutable DIAMOND_ADDRESS;
487+
488+
constructor(address _diamondAddress) {
489+
DIAMOND_ADDRESS = _diamondAddress;
489490
}
490491
491-
function grantAdminRole(address _account) external {
492-
AccessControlFacet accessControl = AccessControlFacet(address(this));
493-
bytes32 adminRole = accessControl.getRoleAdmin(AccessControlFacet.DEFAULT_ADMIN_ROLE());
494-
accessControl.grantRole(adminRole, _account);
492+
function grantAdminRole() external {
493+
AccessControlFacet accessControl = AccessControlFacet(DIAMOND_ADDRESS);
494+
bytes32 adminRole = accessControl.getRoleAdmin(AccessControlFacet.DEFAULT_ADMIN_ROLE);
495+
accessControl.grantRole(adminRole, address(this));
495496
}
496497
497-
function hasRootAccess(address _account) external view returns (bool) {
498-
AccessControlFacet accessControl = AccessControlFacet(address(this));
499-
return accessControl.hasRole(AccessControlFacet.DEFAULT_ADMIN_ROLE(), _account);
498+
function checkMyRole() external view {
499+
AccessControlFacet accessControl = AccessControlFacet(DIAMOND_ADDRESS);
500+
require(accessControl.hasRole(AccessControlFacet.DEFAULT_ADMIN_ROLE, msg.sender), "Caller: Not admin");
500501
}
501502
}`}
502503
</ExpandableCode>
503504

504505
## Best Practices
505506

506507
<Callout type="tip" title="Best Practice">
507-
- Ensure the `DEFAULT_ADMIN_ROLE` is granted to the initial deployer or multisig for diamond ownership.
508-
- Use role hierarchies by setting role admins appropriately to delegate permission management.
509-
- Batch role grants and revokes (`grantRoleBatch`, `revokeRoleBatch`) for gas efficiency when managing multiple accounts.
508+
- Initialize roles and grant initial permissions during diamond deployment or upgrade. Use `grantRole` for single assignments and `grantRoleBatch` for multiple accounts to the same role.
509+
- Define role hierarchies carefully using `setRoleAdmin` to ensure proper administrative control over role assignments.
510+
- Integrate `requireRole` checks directly within functions that require specific permissions, ensuring granular access control.
510511
</Callout>
511512

512513
## Security Considerations
513514

514515
<Callout type="warning" title="Security">
515-
Access control checks are enforced at the function level. Ensure that callers attempting to manage roles (grant, revoke, set admin) possess the necessary administrative privileges for the target role. Reentrancy is not a direct concern for role management functions, but ensure that any functions that *grant* roles do not have reentrancy vulnerabilities if they call external contracts. All role operations are protected against unauthorized callers via `AccessControlUnauthorizedAccount` and `AccessControlUnauthorizedSender` errors.
516+
Ensure that the caller is authorized before granting or revoking roles by checking their current role membership. Use `requireRole` to protect sensitive functions. Be mindful of gas costs for batch operations, especially with a large number of accounts. The `DEFAULT_ADMIN_ROLE` is critical for initial setup and should be managed securely.
516517
</Callout>
517518

518519
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -556,4 +557,4 @@ Access control checks are enforced at the function level. Ensure that callers at
556557
<WasThisHelpful pageId="AccessControlFacet" />
557558
</div>
558559

559-
<LastUpdated date="2025-12-30T14:41:02.648Z" />
560+
<LastUpdated date="2025-12-30T15:01:42.964Z" />

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 1
33
title: "AccessControlMod"
4-
description: "Manage roles and permissions within a diamond."
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,13 +21,13 @@ import GradientText from '@site/src/components/ui/GradientText';
2121
import GradientButton from '@site/src/components/ui/GradientButton';
2222

2323
<DocSubtitle>
24-
Manage roles and permissions within a diamond.
24+
Manages roles and permissions within a diamond.
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
2828
- Role-based access control for granular permission management.
29-
- Functions to grant, revoke, and check role assignments for accounts.
30-
- Ability to define and manage administrative roles for other roles.
29+
- Functions to grant, revoke, and check for role ownership.
30+
- Ability to set and change the administrative role for any given role.
3131
</Callout>
3232

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

3737
## Overview
3838

39-
The AccessControl module provides a robust system for managing roles and permissions within your Compose diamond. It allows you to define granular access levels for different accounts, ensuring that only authorized entities can perform sensitive operations. This module is crucial for building secure and auditable decentralized applications.
39+
The AccessControl module provides a robust system for managing roles and permissions within a Compose diamond. It allows for granular control over who can perform specific actions by assigning roles to accounts. This ensures secure and predictable execution of diamond functions by enforcing authorization checks.
4040

4141
---
4242

@@ -401,40 +401,39 @@ error AccessControlUnauthorizedAccount(address _account, bytes32 _role);
401401
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
402402
{`pragma solidity ^0.8.30;
403403
404-
import {IAccessControl} from "@compose-protocol/diamond-contracts/contracts/modules/accesscontrol/IAccessControl.sol";
404+
import {IAccessControl} from "@compose/contracts/modules/access/IAccessControl.sol";
405405
406-
contract MyFacet {
407-
IAccessControl immutable accessControl;
406+
contract AccessControlFacet {
407+
IAccessControl internal accessControl;
408408
409-
constructor(address _diamondProxy) {
410-
accessControl = IAccessControl(_diamondProxy);
409+
constructor(address _accessControlAddress) {
410+
accessControl = IAccessControl(_accessControlAddress);
411411
}
412412
413413
function grantAdminRole(address _account) external {
414-
bytes32 adminRole = accessControl.getStorage().DEFAULT_ADMIN_ROLE;
414+
address adminRole = accessControl.getStorage().DEFAULT_ADMIN_ROLE;
415415
accessControl.grantRole(adminRole, _account);
416416
}
417417
418-
function executeSensitiveAction() external {
419-
bytes32 sensitiveRole = keccak256("SENSITIVE_ROLE");
420-
accessControl.requireRole(sensitiveRole, msg.sender);
421-
// ... perform sensitive action ...
418+
function checkHasDefaultAdmin(address _account) external view returns (bool) {
419+
address adminRole = accessControl.getStorage().DEFAULT_ADMIN_ROLE;
420+
return accessControl.hasRole(adminRole, _account);
422421
}
423422
}`}
424423
</ExpandableCode>
425424

426425
## Best Practices
427426

428427
<Callout type="tip" title="Best Practice">
429-
- Use `requireRole` for access control checks to ensure correct authorization before executing critical functions.
430-
- Define custom roles using `keccak256` for specific functionalities and manage their assignments and admin roles effectively.
431-
- Be mindful of role administration: ensure the `DEFAULT_ADMIN_ROLE` is secured and `setRoleAdmin` is used judiciously.
428+
- Use `requireRole` internally within facets to enforce access control checks before executing sensitive operations.
429+
- Ensure the `DEFAULT_ADMIN_ROLE` is appropriately managed, typically by the diamond's owner or a designated multi-sig.
430+
- When revoking roles, be mindful of potential cascading effects on dependent permissions.
432431
</Callout>
433432

434433
## Integration Notes
435434

436435
<Callout type="success" title="Shared Storage">
437-
The AccessControl module stores its state within the diamond's storage. Facets interact with it by calling its external functions via the diamond proxy address. Ensure the AccessControl facet is correctly initialized within the diamond's deployment process. Any changes to role assignments or admin roles made through this module are immediately reflected across all facets interacting with the diamond.
436+
The AccessControl module utilizes a dedicated storage slot within the diamond's state. Facets interacting with AccessControl should use the `IAccessControl` interface. Functions like `grantRole`, `revokeRole`, `hasRole`, `requireRole`, and `setRoleAdmin` operate on this shared storage. Changes made via this module are immediately visible to all facets.
438437
</Callout>
439438

440439
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -472,4 +471,4 @@ The AccessControl module stores its state within the diamond's storage. Facets i
472471
<WasThisHelpful pageId="AccessControlMod" />
473472
</div>
474473

475-
<LastUpdated date="2025-12-30T14:40:54.750Z" />
474+
<LastUpdated date="2025-12-30T15:01:38.426Z" />

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 roles and permissions within the diamond."}
17+
description={"Manage roles and permissions within a diamond."}
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={"Manage roles and permissions within a diamond."}
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: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
sidebar_position: 2
33
title: "AccessControlPausableFacet"
4-
description: "Manage roles and pausing functionality within a diamond."
4+
description: "Manage role pausing and access control within a diamond."
55
gitSource: "https://github.com/Perfect-Abstractions/Compose/tree/main/src/access/AccessControlPausable/AccessControlPausableFacet.sol"
66
---
77

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

2323
<DocSubtitle>
24-
Manage roles and pausing functionality within a diamond.
24+
Manage role pausing and access control within a diamond.
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
2828
- Role-specific pausing and unpausing capabilities.
29-
- Integration with existing diamond access control mechanisms.
30-
- Reverts with specific errors for unauthorized access or paused roles.
29+
- Integrates seamlessly with existing Access Control mechanisms.
30+
- Emits events for state changes, facilitating off-chain monitoring.
3131
</Callout>
3232

3333
## Overview
3434

35-
This facet provides granular control over role-based access and allows for the temporary pausing of specific roles. It integrates with the diamond's access control system, enabling administrators to pause operations for a role, preventing any account from utilizing it until unpaused. This enhances security and operational flexibility during critical events.
35+
This facet provides granular control over role execution by allowing specific roles to be temporarily paused. It integrates with the Access Control system, enabling administrators to halt operations for a role and resume them later. This is crucial for maintenance or emergency situations.
3636

3737
---
3838

@@ -282,55 +282,47 @@ error AccessControlRolePaused(bytes32 _role);
282282
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
283283
{`pragma solidity ^0.8.30;
284284
285-
import {IDiamondCut} from "@compose/diamond/contracts/interfaces/IDiamondCut.sol";
286-
import {AccessControlPausableFacet} from "@compose/access-control/contracts/AccessControlPausableFacet.sol";
285+
import {IAccessControl} from "@compose/contracts/src/interfaces/IAccessControl.sol";
286+
import {IAccessControlPausable} from "@compose/contracts/src/interfaces/IAccessControlPausable.sol";
287+
import {DiamondProxy} from "@compose/contracts/src/DiamondProxy.sol";
287288
288-
contract Deployer {
289-
address diamondAddress;
289+
contract Example {
290+
DiamondProxy public diamondProxy;
291+
IAccessControlPausable private accessControlPausableFacet;
290292
291-
function deployDiamond() public {
292-
// ... diamond deployment logic ...
293-
diamondAddress = address(0xYourDiamondAddress);
293+
constructor(address _diamondProxyAddress) {
294+
diamondProxy = DiamondProxy(_diamondProxyAddress);
295+
accessControlPausableFacet = IAccessControlPausable(address(diamondProxy));
294296
}
295297
296-
function addAccessControlPausableFacet() public {
297-
bytes memory facet = abi.encodeCall(AccessControlPausableFacet.init, ());
298-
IDiamondCut(diamondAddress).diamondCut(
299-
IDiamondCut.FacetCut[](
300-
{
301-
facetAddress: address(new AccessControlPausableFacet()),
302-
action: IDiamondCut.Action.ADD,
303-
functionSelectors:
304-
AccessControlPausableFacet.getFunctionSelectors()
305-
}
306-
),
307-
address(0), // Clear fallback
308-
bytes("") // Init data
309-
);
298+
function pauseMyRole() public {
299+
// Assuming 'MY_ROLE' is a defined role and the caller is its admin
300+
bytes32 MY_ROLE = keccak256("MY_ROLE");
301+
accessControlPausableFacet.pauseRole(MY_ROLE);
310302
}
311303
312-
function pauseMyRole() public {
313-
address accessControlPausableFacetAddress = diamondAddress; // Assuming facet is cut to the diamond proxy
314-
bytes4 selector = AccessControlPausableFacet.pauseRole.selector;
315-
// Assuming 'MY_ROLE_ID' is a valid role identifier
316-
(bool success, bytes memory data) = accessControlPausableFacetAddress.call(abi.encodeWithSelector(selector, MY_ROLE_ID));
317-
require(success, "Failed to pause role");
304+
function unpauseMyRole() public {
305+
bytes32 MY_ROLE = keccak256("MY_ROLE");
306+
accessControlPausableFacet.unpauseRole(MY_ROLE);
307+
}
308+
309+
function checkRolePaused(bytes32 role) public view returns (bool) {
310+
return accessControlPausableFacet.isRolePaused(role);
318311
}
319312
}`}
320313
</ExpandableCode>
321314

322315
## Best Practices
323316

324317
<Callout type="tip" title="Best Practice">
325-
- Ensure the `AccessControlPausableFacet` is added to the diamond using `diamondCut` with the correct selectors.
326-
- Call `pauseRole` and `unpauseRole` only with valid role identifiers.
327-
- Implement `requireRoleNotPaused` within functions that should be protected by role pausing.
318+
- Ensure the caller has the necessary administrative role before attempting to pause or unpause another role.
319+
- Utilize `requireRoleNotPaused` within other facets to enforce the paused state of roles before executing sensitive operations.
328320
</Callout>
329321

330322
## Security Considerations
331323

332324
<Callout type="warning" title="Security">
333-
Access to `pauseRole` and `unpauseRole` is restricted to the admin of the specific role. The `requireRoleNotPaused` function ensures that operations tied to a role cannot be executed when that role is paused, preventing unintended actions. Ensure role administration is correctly configured to prevent unauthorized pausing or unpausing.
325+
Access to `pauseRole` and `unpauseRole` is restricted to the administrator of the specific role, preventing unauthorized pausing. The `requireRoleNotPaused` function ensures that operations tied to a role are blocked if that role is paused, preventing unintended executions during maintenance or emergencies. Reentrancy is not a direct concern for the pause/unpause functions themselves, but dependent operations in other facets must be carefully audited.
334326
</Callout>
335327

336328
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
@@ -356,4 +348,4 @@ Access to `pauseRole` and `unpauseRole` is restricted to the admin of the specif
356348
<WasThisHelpful pageId="AccessControlPausableFacet" />
357349
</div>
358350

359-
<LastUpdated date="2025-12-30T14:40:33.125Z" />
351+
<LastUpdated date="2025-12-30T15:01:13.999Z" />

0 commit comments

Comments
 (0)