Skip to main content

LSP6Utils

Standard Specifications
Solidity implementation

LSP6 Utility library.

LSP6Utils is a library of utility functions that can be used to retrieve, check and set LSP6 permissions stored under the ERC725Y storage of a smart contract. Based on the LSP6 Key Manager standard.

Internal Methods​

Any method labeled as internal serves as utility function within the contract. They can be used when writing solidity contracts that inherit from this contract. These methods can be extended or modified by overriding their internal behavior to suit specific needs.

Internal functions cannot be called externally, whether from other smart contracts, dApp interfaces, or backend services. Their restricted accessibility ensures that they remain exclusively available within the context of the current contract, promoting controlled and encapsulated usage of these internal utilities.

getPermissionsFor​

info

If the raw value fetched from the ERC725Y storage of target is not 32 bytes long, this is considered like "no permissions are set" and will return 32 x 0x00 bytes as bytes32(0).

function getPermissionsFor(contract IERC725Y target, address caller) internal view returns (bytes32);

Read the permissions of a caller on an ERC725Y target contract.

Parameters​

NameTypeDescription
targetcontract IERC725YAn IERC725Y contract where to read the permissions.
calleraddressThe controller address to read the permissions from.

Returns​

NameTypeDescription
0bytes32A bytes32 BitArray containing the permissions of a controller address.

getAllowedCallsFor​

function getAllowedCallsFor(contract IERC725Y target, address from) internal view returns (bytes);

getAllowedERC725YDataKeysFor​

function getAllowedERC725YDataKeysFor(contract IERC725Y target, address caller) internal view returns (bytes);

Read the Allowed ERC725Y data keys of a caller on an ERC725Y target contract.

Parameters​

NameTypeDescription
targetcontract IERC725YAn IERC725Y contract where to read the permissions.
calleraddressThe controller address to read the permissions from.

Returns​

NameTypeDescription
0bytesAn abi-encoded array of allowed ERC725 data keys that the controller address is allowed to interact with.

hasPermission​

function hasPermission(
bytes32 controllerPermissions,
bytes32 permissionToCheck
) internal pure returns (bool);

Compare the permissions controllerPermissions of a controller address to check if they includes the permissions permissionToCheck.

Parameters​

NameTypeDescription
controllerPermissionsbytes32The permissions of an address.
permissionToCheckbytes32The permissions to check if the controller has under its controllerPermissions.

Returns​

NameTypeDescription
0booltrue if controllerPermissions includes permissionToCheck, false otherwise.

isCompactBytesArrayOfAllowedCalls​

function isCompactBytesArrayOfAllowedCalls(
bytes allowedCallsCompacted
) internal pure returns (bool);

Same as LSP2Utils.isCompactBytesArray with the additional requirement that each element must be 32 bytes long.

Parameters​

NameTypeDescription
allowedCallsCompactedbytesA compact bytes array of tuples (bytes4,address,bytes4,bytes4) to check (defined as (bytes4,address,bytes4,bytes4)[CompactBytesArray] in LSP6).

Returns​

NameTypeDescription
0booltrue if the value passed is a valid compact bytes array of bytes32 AllowedCalls elements, false otherwise.

isCompactBytesArrayOfAllowedERC725YDataKeys​

function isCompactBytesArrayOfAllowedERC725YDataKeys(
bytes allowedERC725YDataKeysCompacted
) internal pure returns (bool);

Same as LSP2Utils.isCompactBytesArray with the additional requirement that each element must be from 1 to 32 bytes long.

Parameters​

NameTypeDescription
allowedERC725YDataKeysCompactedbytesa compact bytes array of ERC725Y data Keys (full bytes32 data keys or bytesN prefix) to check (defined as bytes[CompactBytesArray]).

Returns​

NameTypeDescription
0booltrue if the value passed is a valid compact bytes array of bytes32 Allowed ERC725Y data keys, false otherwise.

setDataViaKeyManager​

function setDataViaKeyManager(
address keyManagerAddress,
bytes32[] keys,
bytes[] values
) internal nonpayable returns (bytes result);

Use the setData(bytes32[],bytes[]) function via the KeyManager on the target contract.

Parameters​

NameTypeDescription
keyManagerAddressaddressThe address of the KeyManager.
keysbytes32[]The array of bytes32[] data keys.
valuesbytes[]The array of bytes[] data values.

combinePermissions​

function combinePermissions(
bytes32[] permissions
) internal pure returns (bytes32);

Combine multiple permissions into a single bytes32. Make sure that the sum of the values of the input array is less than `2^256-1 to avoid overflow.

Parameters​

NameTypeDescription
permissionsbytes32[]The array of permissions to combine.

Returns​

NameTypeDescription
0bytes32A bytes32 value containing the combined permissions.

generateNewPermissionsKeys​

function generateNewPermissionsKeys(contract IERC725Y account, address controller, bytes32 permissions) internal view returns (bytes32[] keys, bytes[] values);

Generate a new set of 3 x LSP6 permission data keys to add a new controller on account.

Parameters​

NameTypeDescription
accountcontract IERC725YThe ERC725Y contract to add the controller into (used to fetch the LSP6Permissions[] length).
controlleraddressThe address of the controller to grant permissions to.
permissionsbytes32The BitArray of permissions to grant to the controller.

Returns​

NameTypeDescription
keysbytes32[]An array of 3 x data keys containing:
valuesbytes[]An array of 3 x data values containing:

getPermissionName​

function getPermissionName(bytes32 permission) internal pure returns (string);

Returns the name of the permission as a string.

Parameters​

NameTypeDescription
permissionbytes32The low-level bytes32 permission as a BitArray to get the permission name from.

Returns​

NameTypeDescription
0stringThe string name of the bytes32 permission value.