Skip to Content
DevelopersRolesContract reference

Contract reference: Roles Modifier

This page lists the public interface of the Roles Modifier v2 (mastercopy 2.1.1). Source: packages/evm in the zodiac-modifier-roles repository. Solidity 0.8.21.

Setup

constructor(address _owner, address _avatar, address _target) function setUp(bytes memory initParams) public initializer

initParams decodes as (address owner, address avatar, address target). The Module Proxy Factory calls setUp when it deploys the proxy. Emits RolesModSetup.

Owner functions: members and defaults

FunctionDescription
assignRoles(address module, bytes32[] roleKeys, bool[] memberOf)Add (true) or remove (false) the address for each role key. Emits AssignRoles.
setDefaultRole(address module, bytes32 roleKey)Set the role that execTransactionFromModule uses for this address. Emits SetDefaultRole.

Owner functions: permissions

FunctionDescription
allowTarget(bytes32 roleKey, address targetAddress, ExecutionOptions options)Allow all calls to the target. Clearance becomes Target.
scopeTarget(bytes32 roleKey, address targetAddress)Allow only listed functions on the target. Clearance becomes Function.
revokeTarget(bytes32 roleKey, address targetAddress)Remove all access to the target.
allowFunction(bytes32 roleKey, address targetAddress, bytes4 selector, ExecutionOptions options)Allow one function with any parameters.
scopeFunction(bytes32 roleKey, address targetAddress, bytes4 selector, ConditionFlat[] conditions, ExecutionOptions options)Allow one function under a condition tree. The tree arrives as a flat array in breadth-first order.
revokeFunction(bytes32 roleKey, address targetAddress, bytes4 selector)Remove the function permission.
setAllowance(bytes32 key, uint128 balance, uint128 maxRefill, uint128 refill, uint64 period, uint64 timestamp)Create or update an allowance. maxRefill = 0 means no ceiling. timestamp = 0 means now.
setTransactionUnwrapper(address to, bytes4 selector, ITransactionUnwrapper adapter)Register or clear (address zero) an unwrapper for one target and selector. Emits SetUnwrapAdapter.

The Integrity periphery contract validates every condition tree that scopeFunction receives. Malformed trees revert.

Execution functions

FunctionAccessDescription
execTransactionWithRole(address to, uint256 value, bytes data, Operation operation, bytes32 roleKey, bool shouldRevert)Role membersExecute under the named role. Returns success.
execTransactionWithRoleReturnData(...)Role membersThe same, and also returns the inner return data.
execTransactionFromModule(address to, uint256 value, bytes data, Operation operation)Enabled modulesExecute under the caller’s default role.
execTransactionFromModuleReturnData(...)Enabled modulesThe same, and also returns the inner return data.

With shouldRevert = true, a failed inner call reverts with ModuleTransactionFailed().

Module management (from the Modifier base)

enableModule(address), disableModule(address prev, address), isModuleEnabled(address), getModulesPaginated(address start, uint256 pageSize), and setAvatar / setTarget / transferOwnership from the ownable base. All owner-gated except the views.

Role membership is the authorization for execution. assignRoles is enough — a member does not also need enableModule. The execution functions authorize through the role key: execTransactionWithRole uses the named role, and execTransactionFromModule uses defaultRoles[msg.sender].

Public state

GetterReturns
avatar()The account that holds the assets.
target()The address that receives the forwarded calls.
owner()The admin of this Roles Modifier.
defaultRoles(address)The default role key of an address.
unwrappers(bytes32)The unwrapper adapter for a packed (target, selector) key.

Full role configurations (targets, conditions, allowances, members) are indexed by the subgraph. Endpoint: https://gnosisguild.squids.live/roles:production/api/graphql. Query rolesModifier(id: "<chainPrefix>:<address>") for one instance, or rolesModifiers(avatar: $address) for all instances of a Safe.

Enums

enum Operation { Call, DelegateCall } enum ExecutionOptions { None, Send, DelegateCall, Both } enum Clearance { None, Target, Function } enum ParameterType { None, Static, Dynamic, Tuple, Array, Calldata, AbiEncoded }

Operators and status codes: see Conditions and Execution.

Events

event RolesModSetup(address indexed initiator, address indexed owner, address indexed avatar, address target); event AssignRoles(address module, bytes32[] roleKeys, bool[] memberOf); event SetDefaultRole(address module, bytes32 defaultRoleKey); event AllowTarget(bytes32 roleKey, address targetAddress, ExecutionOptions options); event RevokeTarget(bytes32 roleKey, address targetAddress); event ScopeTarget(bytes32 roleKey, address targetAddress); event AllowFunction(bytes32 roleKey, address targetAddress, bytes4 selector, ExecutionOptions options); event RevokeFunction(bytes32 roleKey, address targetAddress, bytes4 selector); event ScopeFunction(bytes32 roleKey, address targetAddress, bytes4 selector, ConditionFlat[] conditions, ExecutionOptions options); event SetAllowance(bytes32 key, uint128 balance, uint128 maxRefill, uint128 refill, uint64 period, uint64 timestamp); event SetUnwrapAdapter(address to, bytes4 selector, ITransactionUnwrapper adapter);

Errors

ErrorSource
ArraysDifferentLength()assignRoles with mismatched array sizes.
ModuleTransactionFailed()The inner call failed with shouldRevert = true.
NoMembership()The sender does not hold the role.
ConditionViolation(Status, bytes32)A permission check failed. See Execution.
NotAuthorized(address)The caller is not an enabled module (module entry points).
Last updated on