Skip to content

Token Gated Role Authorizer

Rahul Saxena edited this page Aug 14, 2023 · 3 revisions

File: TokenGatedRoleAuthorizer.sol

Things to know

  1. This Module expands on the RoleAuthorizer by adding the possibility to set a role as "Token-Gated"
  2. Instead of whitelisting a user address, the whitelisted addresses will correspond to a token address, and on authorization the contract will check on ownership of one of the specified tokens.

Modifiers

1. onlyEmptyRole

modifier onlyEmptyRole(bytes32 roleId)

Checks that the role is empty or not.

2. onlyTokenGated

modifier onlyTokenGated(bytes32 roleId)

Checks whether the given roleId is token gated or not.

3. validThreshold

modifier validThreshold(uint threshold)

Checks that the threshold is non-zero. Since base ERC721 does not have a total/max supply, we can only enforce that the value should be non-zero.

View Functions

1. isAuthorized

function isAuthorized(address who) external view returns (bool);

Returns if an address is authorized to perform a specific action.

Parameters

  1. address who: The adress to be checked.

2. hasTokenRole

 function hasTokenRole(bytes32 role, address who) external returns (bool);

Checks if an account qualifies for a token-gated role.

Parameters

  1. bytes32 role: The role to be checked
  2. address who: The account to be checked

3. getThresholdValue

function getThresholdValue(bytes32 roleId, address token)
        external
        returns (uint);

Returns the threshold amount necessary to qualify for a given token role.

Parameters

  1. bytes32 roleId: The role to be checked on
  2. address token: The token to check the threshold for

Write Functions

1. makeRoleTokenGatedFromModule

function makeRoleTokenGatedFromModule(uint8 role) external;

Sets up a token-gated empty role. This function is only callable by an active Module for itself. Admin should use setTokenGated(). Calling this function does not specify which token to use for gating. That has to be done with grantTokenFromModule().

Parameters

  1. uint8 role: The role to be made token-gated

2. grantTokenRoleFromModule

function grantTokenRoleFromModule(uint8 role, address token, uint threshold)
        external;

One-step setup for Modules to create a token-gated role and set its threshold.

Parameters

  1. uint8 role: The role to be made token-gated
  2. address token: The token for which the threshold will be set
  3. uint threshold: The minimum balance of the token required to qualify for the role

3. setTokenGated

function setTokenGated(bytes32 role, bool to) external;

Sets if a role is token-gated or not. Admin access for rescue purposes. If the role has active members. they need to be revoked first.

Parameters

  1. bytes32 role: The ID of the role to be modified
  2. bool to: The new value to be set

4. setThreshold

function setThreshold(bytes32 roleId, address token, uint threshold)
        external;

Sets the minimum threshold for a token-gated role. This function does not validate the threshold. It is technically possible to set a threshold above the total supply of the token.

Parameters

  1. bytes32 roleId: The ID of the role to be modified
  2. address token: The token for which to be threshold
  3. uint threshold: The user will need to have at least this number to qualify for the role