Skip to main content

JBPermissions

Git Source

Inherits: IJBPermissions

Stores permissions for all addresses and operators. Addresses can give permissions to any other address (i.e. an operator) to execute specific operations on their behalf.

State Variables​

WILDCARD_PROJECT_ID​

The project ID considered a wildcard, meaning it will grant permissions to all projects.

uint256 public constant override WILDCARD_PROJECT_ID = 0;

permissionsOf​

The permissions that an operator has been given by an account for a specific project.

An account can give an operator permissions that only pertain to a specific project ID.

There is no project with a ID of 0 – this ID is a wildcard which gives an operator permissions pertaining to all project IDs on an account's behalf. Use this with caution.

Permissions are stored in a packed uint256. Each of the 256 bits represents the on/off state of a permission. Applications can specify the significance of each permission ID.

mapping(address operator => mapping(address account => mapping(uint256 projectId => uint256))) public override
permissionsOf;

Functions​

hasPermission​

Check if an operator has a specific permission for a specific address and project ID.

function hasPermission(
address operator,
address account,
uint256 projectId,
uint256 permissionId,
bool includeRoot,
bool includeWildcardProjectId
)
public
view
override
returns (bool);

Parameters

NameTypeDescription
operatoraddressThe operator to check.
accountaddressThe account being operated on behalf of.
projectIduint256The project ID that the operator has permission to operate under. 0 represents all projects.
permissionIduint256The permission ID to check for.
includeRootboolA flag indicating if the return value should default to true if the operator has the ROOT permission.
includeWildcardProjectIdboolA flag indicating if the return value should return true if the operator has the specified permission on the wildcard project ID.

Returns

NameTypeDescription
<none>boolA flag indicating whether the operator has the specified permission.

hasPermissions​

Check if an operator has all of the specified permissions for a specific address and project ID.

function hasPermissions(
address operator,
address account,
uint256 projectId,
uint256[] calldata permissionIds,
bool includeRoot,
bool includeWildcardProjectId
)
external
view
override
returns (bool);

Parameters

NameTypeDescription
operatoraddressThe operator to check.
accountaddressThe account being operated on behalf of.
projectIduint256The project ID that the operator has permission to operate under. 0 represents all projects.
permissionIdsuint256[]An array of permission IDs to check for.
includeRootboolA flag indicating if the return value should default to true if the operator has the ROOT permission.
includeWildcardProjectIdboolA flag indicating if the return value should return true if the operator has the specified permission on the wildcard project ID.

Returns

NameTypeDescription
<none>boolA flag indicating whether the operator has all specified permissions.

_includesPermission​

Checks if a permission is included in a packed permissions data.

function _includesPermission(uint256 permissions, uint256 permissionId) internal pure returns (bool);

Parameters

NameTypeDescription
permissionsuint256The packed permissions to check.
permissionIduint256The ID of the permission to check for.

Returns

NameTypeDescription
<none>boolA flag indicating whether the permission is included.

_packedPermissions​

Converts an array of permission IDs to a packed uint256.

function _packedPermissions(uint8[] calldata permissionIds) internal pure returns (uint256 packed);

Parameters

NameTypeDescription
permissionIdsuint8[]The IDs of the permissions to pack.

Returns

NameTypeDescription
packeduint256The packed value.

setPermissionsFor​

Sets permissions for an operator.

Only an address can give permissions to or revoke permissions from its operators.

function setPermissionsFor(address account, JBPermissionsData calldata permissionsData) external override;

Parameters

NameTypeDescription
accountaddressThe account setting its operators' permissions.
permissionsDataJBPermissionsDataThe data which specifies the permissions the operator is being given.

Errors​

JBPermissions_CantSetRootPermissionForWildcardProject​

error JBPermissions_CantSetRootPermissionForWildcardProject();

JBPermissions_NoZeroPermission​

error JBPermissions_NoZeroPermission();

JBPermissions_PermissionIdOutOfBounds​

error JBPermissions_PermissionIdOutOfBounds(uint256 permissionId);

JBPermissions_Unauthorized​

error JBPermissions_Unauthorized();