Skip to content

Commit 406bc43

Browse files
authored
Merge pull request #31 from maxnorm/docs/auto-generated-28
[DOCS] Auto-generated Docs Pages
2 parents 5dfdcff + d6012a5 commit 406bc43

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

+1108
-1215
lines changed

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

Lines changed: 31 additions & 40 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: "Manages roles and permissions within the diamond."
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+
Manages roles and permissions within the diamond.
2525
</DocSubtitle>
2626

2727
<Callout type="info" title="Key Features">
28-
- Hierarchical role administration: roles can have their own admin roles.
29-
- Batch operations for granting and revoking multiple roles efficiently.
30-
- Explicit error messages for unauthorized access attempts.
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.
3132
</Callout>
3233

3334
## Overview
3435

35-
The AccessControlFacet provides a robust role-based access control (RBAC) system for Compose diamonds. It enables granular permission management by defining roles, assigning them to accounts, and enforcing role requirements on function calls. This facet is crucial for securing administrative functions and controlling access to sensitive operations.
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.
3637

3738
---
3839

@@ -477,83 +478,73 @@ error AccessControlUnauthorizedSender(address _sender, address _account);
477478
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
478479
{`pragma solidity ^0.8.30;
479480
480-
import {DiamondABI} from "@compose/diamond-abi/DiamondABI.sol";
481-
import {DiamondInit ABI} from "@compose/diamond-init/DiamondInitABI.sol";
482-
import {DiamondCutFacet} from "@compose/diamond-cut/DiamondCutFacet.sol";
483-
import {AccessControlFacet} from "@compose/access-control/AccessControlFacet.sol";
481+
import {DiamondProxy, DiamondCut} from "@compose/diamond-proxy/contracts/DiamondProxy.sol";
482+
import {AccessControlFacet} from "@compose/diamond-proxy/contracts/facets/AccessControlFacet.sol";
484483
485-
// Example of granting a role
486-
contract Deployer {
487-
address immutable diamondAddress;
488-
489-
constructor(address _diamondAddress) {
490-
diamondAddress = _diamondAddress;
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(...);
491489
}
492490
493-
function grantAdminRole() external {
494-
bytes4 selector = AccessControlFacet.grantRole.selector;
495-
// Assuming DEFAULT_ADMIN_ROLE is 0x00...00
496-
bytes memory data = abi.encodeWithSelector(selector, bytes32(0), msg.sender);
497-
498-
// In a real deployment, this would be part of a DiamondCut
499-
// For demonstration, directly calling the facet via the diamond proxy
500-
diamondAddress.call(data);
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);
501495
}
502496
503-
function checkRole(address _account, bytes32 _role) public view returns (bool) {
504-
bytes4 selector = AccessControlFacet.hasRole.selector;
505-
bytes memory data = abi.encodeWithSelector(selector, _role, _account);
506-
(bool success, bytes memory result) = diamondAddress.staticcall(data);
507-
require(success, "checkRole failed");
508-
return abi.decode(result, (bool));
497+
function hasRootAccess(address _account) external view returns (bool) {
498+
AccessControlFacet accessControl = AccessControlFacet(address(this));
499+
return accessControl.hasRole(AccessControlFacet.DEFAULT_ADMIN_ROLE(), _account);
509500
}
510501
}`}
511502
</ExpandableCode>
512503

513504
## Best Practices
514505

515506
<Callout type="tip" title="Best Practice">
516-
- Initialize roles and their admins during diamond deployment using `DiamondInit`.
517-
- Grant roles to specific addresses or multisigs, avoiding broad grants to `address(0)`.
518-
- Use `requireRole` judiciously within other facets to protect sensitive functions.
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.
519510
</Callout>
520511

521512
## Security Considerations
522513

523514
<Callout type="warning" title="Security">
524-
Ensure that the caller of `setRoleAdmin`, `grantRole`, `revokeRole`, `grantRoleBatch`, and `revokeRoleBatch` is authorized by the role's admin. Be cautious when setting role admins to prevent privilege escalation. Reentrancy is not a direct concern for this facet's core logic, but ensure calling facets properly validate inputs before calling `requireRole`.
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.
525516
</Callout>
526517

527518
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
528519
<RelatedDocs
529520
items={[
530521
{
531522
title: "AccessControlMod",
532-
href: "/docs/library/access/AccessControl",
523+
href: "/docs/library/access/AccessControl/AccessControlMod",
533524
description: "Module used by AccessControlFacet",
534525
icon: "📦"
535526
},
536527
{
537528
title: "OwnerTwoStepsFacet",
538-
href: "/docs/library/access/OwnerTwoSteps",
529+
href: "/docs/library/access/OwnerTwoSteps/OwnerTwoStepsFacet",
539530
description: "Related facet in access",
540531
icon: "💎"
541532
},
542533
{
543534
title: "AccessControlPausableFacet",
544-
href: "/docs/library/access/AccessControlPausable",
535+
href: "/docs/library/access/AccessControlPausable/AccessControlPausableFacet",
545536
description: "Related facet in access",
546537
icon: "💎"
547538
},
548539
{
549540
title: "AccessControlTemporalFacet",
550-
href: "/docs/library/access/AccessControlTemporal",
541+
href: "/docs/library/access/AccessControlTemporal/AccessControlTemporalFacet",
551542
description: "Related facet in access",
552543
icon: "💎"
553544
},
554545
{
555546
title: "OwnerFacet",
556-
href: "/docs/library/access/Owner",
547+
href: "/docs/library/access/Owner/OwnerFacet",
557548
description: "Related facet in access",
558549
icon: "💎"
559550
}
@@ -565,4 +556,4 @@ Ensure that the caller of `setRoleAdmin`, `grantRole`, `revokeRole`, `grantRoleB
565556
<WasThisHelpful pageId="AccessControlFacet" />
566557
</div>
567558

568-
<LastUpdated date="2025-12-28T04:47:31.466Z" />
559+
<LastUpdated date="2025-12-30T14:41:02.648Z" />

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ Manage roles and permissions within a diamond.
2626

2727
<Callout type="info" title="Key Features">
2828
- Role-based access control for granular permission management.
29-
- Functions to grant, revoke, and check for role ownership (`grantRole`, `revokeRole`, `hasRole`).
30-
- Support for setting and changing the administrative role for any given role (`setRoleAdmin`).
31-
- Built-in reversion with `AccessControlUnauthorizedAccount` for unauthorized access attempts.
29+
- Functions to grant, revoke, and check role assignments for accounts.
30+
- Ability to define and manage administrative roles for other roles.
3231
</Callout>
3332

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

3837
## Overview
3938

40-
The AccessControl module provides a robust system for managing roles and permissions within a Compose diamond. It allows for granular control over which accounts can perform specific actions by assigning them roles. This is crucial for maintaining security and ensuring that only authorized entities can interact with sensitive functions.
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.
4140

4241
---
4342

@@ -402,66 +401,66 @@ error AccessControlUnauthorizedAccount(address _account, bytes32 _role);
402401
<ExpandableCode language="solidity" maxLines={20} title="Example Implementation">
403402
{`pragma solidity ^0.8.30;
404403
405-
import {IAccessControlMod} from "@compose-protocol/diamond-contracts/contracts/modules/access/AccessControlMod.sol";
404+
import {IAccessControl} from "@compose-protocol/diamond-contracts/contracts/modules/accesscontrol/IAccessControl.sol";
406405
407406
contract MyFacet {
408-
IAccessControlMod internal accessControl;
407+
IAccessControl immutable accessControl;
409408
410-
function initialize(address accessControlAddress) external {
411-
accessControl = IAccessControlMod(accessControlAddress);
409+
constructor(address _diamondProxy) {
410+
accessControl = IAccessControl(_diamondProxy);
412411
}
413412
414-
function grantAdminRoleToUser(address user) external {
413+
function grantAdminRole(address _account) external {
415414
bytes32 adminRole = accessControl.getStorage().DEFAULT_ADMIN_ROLE;
416-
accessControl.grantRole(adminRole, user);
415+
accessControl.grantRole(adminRole, _account);
417416
}
418417
419-
function performAdminAction() external {
420-
bytes32 adminRole = accessControl.getStorage().DEFAULT_ADMIN_ROLE;
421-
accessControl.requireRole(adminRole);
422-
// Perform admin action
418+
function executeSensitiveAction() external {
419+
bytes32 sensitiveRole = keccak256("SENSITIVE_ROLE");
420+
accessControl.requireRole(sensitiveRole, msg.sender);
421+
// ... perform sensitive action ...
423422
}
424423
}`}
425424
</ExpandableCode>
426425

427426
## Best Practices
428427

429428
<Callout type="tip" title="Best Practice">
430-
- Use `requireRole` to enforce access control checks directly within facet functions, reverting with `AccessControlUnauthorizedAccount` on failure.
431-
- Define custom roles and manage their admin roles using `setRoleAdmin` to maintain a clear hierarchy and control over role assignments.
432-
- Ensure the AccessControl module is initialized with appropriate default admin roles during diamond deployment.
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.
433432
</Callout>
434433

435434
## Integration Notes
436435

437436
<Callout type="success" title="Shared Storage">
438-
The AccessControl module stores its state within the diamond's storage. Facets interact with this module via its interface. The `getStorage()` function provides direct access to the module's internal storage struct, which contains mappings for roles, role admins, and account role assignments. Any changes made to role assignments or admin roles through the AccessControl module's functions are immediately reflected and accessible to all facets interacting with the diamond.
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.
439438
</Callout>
440439

441440
<div style={{marginTop: "3rem", paddingTop: "2rem", borderTop: "1px solid var(--ifm-color-emphasis-200)"}}>
442441
<RelatedDocs
443442
items={[
444443
{
445444
title: "OwnerTwoStepsMod",
446-
href: "/docs/library/access/OwnerTwoSteps",
445+
href: "/docs/library/access/OwnerTwoSteps/OwnerTwoStepsMod",
447446
description: "Related module in access",
448447
icon: "📦"
449448
},
450449
{
451450
title: "AccessControlPausableMod",
452-
href: "/docs/library/access/AccessControlPausable",
451+
href: "/docs/library/access/AccessControlPausable/AccessControlPausableMod",
453452
description: "Related module in access",
454453
icon: "📦"
455454
},
456455
{
457456
title: "AccessControlTemporalMod",
458-
href: "/docs/library/access/AccessControlTemporal",
457+
href: "/docs/library/access/AccessControlTemporal/AccessControlTemporalMod",
459458
description: "Related module in access",
460459
icon: "📦"
461460
},
462461
{
463462
title: "OwnerMod",
464-
href: "/docs/library/access/Owner",
463+
href: "/docs/library/access/Owner/OwnerMod",
465464
description: "Related module in access",
466465
icon: "📦"
467466
}
@@ -473,4 +472,4 @@ The AccessControl module stores its state within the diamond's storage. Facets i
473472
<WasThisHelpful pageId="AccessControlMod" />
474473
</div>
475474

476-
<LastUpdated date="2025-12-28T04:47:27.236Z" />
475+
<LastUpdated date="2025-12-30T14:40:54.750Z" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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={"Manages roles and permissions within the diamond."}
1818
href="/docs/library/access/AccessControl/AccessControlFacet"
1919
icon={<Icon name="book" size={28} />}
2020
size="medium"

0 commit comments

Comments
 (0)