Skip to main content

Kernel

Git Source

Main contract that acts as a central component registry for the protocol.

The kernel manages modules and policies. The kernel is mutated via predefined Actions,

which are input from any address assigned as the executor. The executor can be changed as needed.

State Variables

executor

Address that is able to initiate Actions in the kernel. Can be assigned to a multisig or governance contract.

address public executor;

allKeycodes

Array of all modules currently installed.

Keycode[] public allKeycodes;

getModuleForKeycode

Mapping of module address to keycode.

mapping(Keycode => Module) public getModuleForKeycode;

getKeycodeForModule

Mapping of keycode to module address.

mapping(Module => Keycode) public getKeycodeForModule;

moduleDependents

Mapping of a keycode to all of its policy dependents. Used to efficiently reconfigure policy dependencies.

mapping(Keycode => Policy[]) public moduleDependents;

getDependentIndex

Helper for module dependent arrays. Prevents the need to loop through array.

mapping(Keycode => mapping(Policy => uint256)) public getDependentIndex;

modulePermissions

Module <> Policy Permissions.

Keycode -> Policy -> Function Selector -> bool for permission

mapping(Keycode => mapping(Policy => mapping(bytes4 => bool))) public modulePermissions;

activePolicies

List of all active policies

Policy[] public activePolicies;

getPolicyIndex

Helper to get active policy quickly. Prevents need to loop through array.

mapping(Policy => uint256) public getPolicyIndex;

Functions

constructor

constructor();

onlyExecutor

Modifier to check if caller is the executor.

modifier onlyExecutor();

isPolicyActive

function isPolicyActive(Policy policy_) public view returns (bool);

executeAction

Main kernel function. Initiates state changes to kernel depending on Action passed in.

function executeAction(Actions action_, address target_) external onlyExecutor;

_installModule

function _installModule(Module newModule_) internal;

_upgradeModule

function _upgradeModule(Module newModule_) internal;

_activatePolicy

function _activatePolicy(Policy policy_) internal;

_deactivatePolicy

function _deactivatePolicy(Policy policy_) internal;

_migrateKernel

All functionality will move to the new kernel. WARNING: ACTION WILL BRICK THIS KERNEL.

New kernel must add in all of the modules and policies via executeAction.

NOTE: Data does not get cleared from this kernel.

function _migrateKernel(Kernel newKernel_) internal;

_reconfigurePolicies

function _reconfigurePolicies(Keycode keycode_) internal;

_setPolicyPermissions

function _setPolicyPermissions(
Policy policy_,
Permissions[] memory requests_,
bool grant_
) internal;

_pruneFromDependents

function _pruneFromDependents(Policy policy_) internal;

Events

PermissionsUpdated

event PermissionsUpdated(
Keycode indexed keycode_, Policy indexed policy_, bytes4 funcSelector_, bool granted_
);

ActionExecuted

event ActionExecuted(Actions indexed action_, address indexed target_);

Errors

Kernel_OnlyExecutor

error Kernel_OnlyExecutor(address caller_);

Kernel_ModuleAlreadyInstalled

error Kernel_ModuleAlreadyInstalled(Keycode module_);

Kernel_InvalidModuleUpgrade

error Kernel_InvalidModuleUpgrade(Keycode module_);

Kernel_PolicyAlreadyActivated

error Kernel_PolicyAlreadyActivated(address policy_);

Kernel_PolicyNotActivated

error Kernel_PolicyNotActivated(address policy_);