Guild Oracle.
Base contract to check an address's accesses, roles, admin/owner status on Guild.xyz via a Chainlink oracle.
Inherit from this contract to have easy access to Guild's access check.
mapping(bytes32 => struct GuildOracle.RequestParams) requests
The request parameters mapped to the requestIds.
uint256 oracleFee
The amount of tokens to forward to the oracle with every request.
bytes32 jobId
The id of the job to run on the oracle.
constructor(
address linkToken,
address oracleAddress,
bytes32 jobId_,
uint256 oracleFee_
)
Sets the oracle's details.
Name | Type | Description |
---|---|---|
linkToken |
address | The address of the Chainlink token. |
oracleAddress |
address | The address of the oracle processing the requests. |
jobId_ |
bytes32 | The id of the job to run on the oracle. |
oracleFee_ |
uint256 | The amount of tokens to forward to the oracle with every request. |
function requestGuildRoleAccessCheck(
address addressToCheck,
uint256 roleId,
uint256 guildId,
bytes4 callbackFn,
bytes args
) internal
Sends a request to the oracle querying if the user has access to a certain role on Guild.
The user may not actually hold the role.
Name | Type | Description |
---|---|---|
addressToCheck |
address | The address of the user. |
roleId |
uint256 | The roleId that has to be checked. |
guildId |
uint256 | The id of the guild the rewarded role is in. |
callbackFn |
bytes4 | The identifier of the function the oracle should call when fulfilling the request. |
args |
bytes | Any additional function arguments in an abi encoded form. |
function requestGuildRoleCheck(
address addressToCheck,
uint256 roleId,
bytes4 callbackFn,
bytes args
) internal
Sends a request to the oracle querying if the user has obtained a certain role on Guild.
Name | Type | Description |
---|---|---|
addressToCheck |
address | The address of the user. |
roleId |
uint256 | The id of the role that needs to be checked. |
callbackFn |
bytes4 | The identifier of the function the oracle should call when fulfilling the request. |
args |
bytes | Any additional function arguments in an abi encoded form. |
function requestGuildJoinCheck(
address addressToCheck,
uint256 guildId,
bytes4 callbackFn,
bytes args
) internal
Sends a request to the oracle querying if the user has joined a certain guild.
Name | Type | Description |
---|---|---|
addressToCheck |
address | The address of the user. |
guildId |
uint256 | The id of the guild that needs to be checked. |
callbackFn |
bytes4 | The identifier of the function the oracle should call when fulfilling the request. |
args |
bytes | Any additional function arguments in an abi encoded form. |
function requestGuildAdminCheck(
address addressToCheck,
uint256 guildId,
bytes4 callbackFn,
bytes args
) internal
Sends a request to the oracle querying if the user is an admin of a certain guild.
Name | Type | Description |
---|---|---|
addressToCheck |
address | The address of the user. |
guildId |
uint256 | The id of the guild that needs to be checked. |
callbackFn |
bytes4 | The identifier of the function the oracle should call when fulfilling the request. |
args |
bytes | Any additional function arguments in an abi encoded form. |
function requestGuildOwnerCheck(
address addressToCheck,
uint256 guildId,
bytes4 callbackFn,
bytes args
) internal
Sends a request to the oracle querying if the user is the owner of a certain guild.
Name | Type | Description |
---|---|---|
addressToCheck |
address | The address of the user. |
guildId |
uint256 | The id of the guild that needs to be checked. |
callbackFn |
bytes4 | The identifier of the function the oracle should call when fulfilling the request. |
args |
bytes | Any additional function arguments in an abi encoded form. |
modifier checkResponse(bytes32 requestId, uint256 access)
Processes the data returned by the Chainlink node.
Name | Type | Description |
---|---|---|
requestId | bytes32 | The id of the request. |
access | uint256 | The value returned by the oracle. |
event HasAccess(
address userAddress
)
Event emitted when an address is successfully verified to have a role.
Name | Type | Description |
---|---|---|
userAddress |
address | The address of the queried user. |
error NoAccess(address userAddress)
Error thrown when an address doesn't have the needed role.
Name | Type | Description |
---|---|---|
userAddress | address | The address of the queried user. |
error AccessCheckFailed(address userAddress)
Error thrown when a role check failed due to an unavailable server or invalid return data.
Name | Type | Description |
---|---|---|
userAddress | address | The address of the queried user. |
enum Access {
NO_ACCESS,
ACCESS,
CHECK_FAILED
}
struct RequestParams {
address userAddress;
bytes args;
}