Skip to content

Agent Registry

AgentRegistry

version

string version

constructor

constructor(address forwarder) public

initialize

function initialize(address __manager, string __name, string __symbol) public

Initializer method, access point to initialize inheritance tree.

Name Type Description
__manager address address of AccessManager.
__name string ERC721 token name.
__symbol string ERC721 token symbol.

getAgentState

function getAgentState(uint256 agentId) public view returns (bool registered, address owner, uint256 agentVersion, string metadata, uint256[] chainIds, bool enabled, uint256 disabledFlags)

Gets all Agent state.

Name Type Description
agentId uint256 ERC721 token id of the agent.
Name Type Description
registered bool if agent exists.
owner address address.
agentVersion uint256 of the agent.
metadata string IPFS pointer.
chainIds uint256[] the agent wants to run in.
enabled bool true if staked over min and not disabled.
disabledFlags uint256 0 if not disabled, Permission that disabled the scnner otherwise.

_beforeAgentUpdate

function _beforeAgentUpdate(uint256 agentId, string newMetadata, uint256[] newChainIds) internal virtual

Inheritance disambiguation for hook fired befire agent update (and creation).

Name Type Description
agentId uint256 id of the agent.
newMetadata string IPFS pointer to agent's metadata
newChainIds uint256[] chain ids that the agent wants to scan

_agentUpdate

function _agentUpdate(uint256 agentId, string newMetadata, uint256[] newChainIds) internal virtual

Obligatory inheritance disambiguation for hook fired for agent update (and creation).

Name Type Description
agentId uint256 id of the agent.
newMetadata string IPFS pointer to agent's metadata
newChainIds uint256[] chain ids that the agent wants to scan

_msgSender

function _msgSender() internal view virtual returns (address sender)

Helper to get either msg msg.sender if not a meta transaction, signer of forwarder metatx if it is.

_msgData

function _msgData() internal view virtual returns (bytes)

Helper to get msg.data if not a meta transaction, forwarder data in metatx if it is.

__gap

uint256[50] __gap

AgentRegistryEnumerable

_allAgents

struct EnumerableSet.UintSet _allAgents

_chainAgents

mapping(uint256 => struct EnumerableSet.UintSet) _chainAgents

getAgentCount

function getAgentCount() public view returns (uint256)

Agent count.

Helper for external iteration.

Name Type Description
[0] uint256 total amount of registered agents.

getAgentByIndex

function getAgentByIndex(uint256 index) public view returns (uint256)

Agent id at index in _allAgents array.

Helper for external iteration.

Name Type Description
index uint256 of agent in _allAgents array.
Name Type Description
[0] uint256 agentId at index.

getAgentCountByChain

function getAgentCountByChain(uint256 chainId) public view returns (uint256)

Registered agent count by chainId.

Helper for external iteration.

Name Type Description
[0] uint256 agent total registered by chainId.

getAgentByChainAndIndex

function getAgentByChainAndIndex(uint256 chainId, uint256 index) public view returns (uint256)

Agent id at index, by chainId

Helper for external iteration.

Name Type Description
chainId uint256 where the agent was registered.
index uint256 of agent in _chainAgents[chainId] array.
Name Type Description
[0] uint256 agentId at index for that chainId.

_beforeAgentUpdate

function _beforeAgentUpdate(uint256 agentId, string newMetadata, uint256[] newChainIds) internal virtual

hook fired before agent creation or update.

stores agent in _allAgents if it wasn't there, manages agent arrays by chain.

Name Type Description
agentId uint256 ERC721 token id of the agent to be created or updated.
newMetadata string IPFS pointer to agent's metadata JSON.
newChainIds uint256[] ordered list of chainIds where the agent wants to run.

__gap

uint256[48] __gap

AgentRegistryMetadata

AgentMetadata

struct AgentMetadata {
  uint256 version;
  string metadata;
  uint256[] chainIds;
}

_agentMetadata

mapping(uint256 => struct AgentRegistryMetadata.AgentMetadata) _agentMetadata

_agentMetadataUniqueness

mapping(bytes32 => bool) _agentMetadataUniqueness

MetadataNotUnique

error MetadataNotUnique(bytes32 hash)

getAgent

function getAgent(uint256 agentId) public view returns (bool registered, address owner, uint256 agentVersion, string metadata, uint256[] chainIds)

Gets agent metadata, version and chain Ids.

Name Type Description
agentId uint256 ERC721 token id of the agent.
Name Type Description
registered bool if agent exists.
owner address address.
agentVersion uint256 of the agent.
metadata string IPFS pointer.
chainIds uint256[] the agent wants to run in.

_agentUpdate

function _agentUpdate(uint256 agentId, string newMetadata, uint256[] newChainIds) internal virtual

logic for agent update.

checks metadata uniqueness and updates agent metadata and version.

Name Type Description
agentId uint256 ERC721 token id of the agent to be created or updated.
newMetadata string IPFS pointer to agent's metadata JSON.
newChainIds uint256[] ordered list of chainIds where the agent wants to run.

__gap

uint256[48] __gap

AgentRegistryEnable

AgentRegistry methods and state handling disabling and enabling agents, and recognizing stake changes that might disable an agent. NOTE: This contract was deployed before StakeAwareUpgradeable was created, so __StakeAwareUpgradeable_init is not called.

Permission

enum Permission {
  ADMIN,
  OWNER,
  length
}

_disabled

mapping(uint256 => struct BitMaps.BitMap) _disabled

AgentEnabled

event AgentEnabled(uint256 agentId, bool enabled, enum AgentRegistryEnable.Permission permission, bool value)

isEnabled

function isEnabled(uint256 agentId) public view virtual returns (bool)

Check if agent is enabled

Name Type Description
agentId uint256 ERC721 token id of the agent.
Name Type Description
[0] bool true if the agent exist, has not been disabled, and is staked over minimum Returns false if otherwise

enableAgent

function enableAgent(uint256 agentId, enum AgentRegistryEnable.Permission permission) public virtual

Enable an agent if sender has correct permission and the agent is staked over minimum stake.

agents can be disabled by ADMIN or OWNER.

Name Type Description
agentId uint256 ERC721 token id of the agent.
permission enum AgentRegistryEnable.Permission the sender claims to have to enable the agent.

disableAgent

function disableAgent(uint256 agentId, enum AgentRegistryEnable.Permission permission) public virtual

Disable an agent if sender has correct permission.

agents can be disabled by ADMIN or OWNER.

Name Type Description
agentId uint256 ERC721 token id of the agent.
permission enum AgentRegistryEnable.Permission the sender claims to have to enable the agent.

getDisableFlags

function getDisableFlags(uint256 agentId) public view returns (uint256)

Get the disabled flags for an agentId.

Permission (uint8) is used for indexing, so we don't need to loop. If not disabled, all flags will be 0.

Name Type Description
agentId uint256 ERC721 token id of the agent.
Name Type Description
[0] uint256 uint256 containing the byte flags.

_hasPermission

function _hasPermission(uint256 agentId, enum AgentRegistryEnable.Permission permission) internal view returns (bool)

Permission check.

it does not uses AccessManager since it is agent specific

Name Type Description
agentId uint256 ERC721 token id of the agent.
permission enum AgentRegistryEnable.Permission the sender claims to have to enable the agent.
Name Type Description
[0] bool true if: permission.ADMIN and _msgSender is ADMIN_ROLE, Permission.OWNER and owner of agentId, false otherwise.

_enable

function _enable(uint256 agentId, enum AgentRegistryEnable.Permission permission, bool enable) internal

Internal methods for enabling the agent.

fires hook _before and _after enable within the inheritance tree.

Name Type Description
agentId uint256 ERC721 token id of the agent.
permission enum AgentRegistryEnable.Permission the sender claims to have to enable the agent.
enable bool true if enabling, false if disabling.

_beforeAgentEnable

function _beforeAgentEnable(uint256 agentId, enum AgentRegistryEnable.Permission permission, bool value) internal virtual

Hook _before agent enable

does nothing in this contract

Name Type Description
agentId uint256 ERC721 token id of the agent.
permission enum AgentRegistryEnable.Permission the sender claims to have to enable the agent.
value bool true if enabling, false if disabling.

_agentEnable

function _agentEnable(uint256 agentId, enum AgentRegistryEnable.Permission permission, bool value) internal virtual

Logic for enabling agents, sets flag corresponding to permission.

does nothing in this contract

Name Type Description
agentId uint256 ERC721 token id of the agent.
permission enum AgentRegistryEnable.Permission the sender claims to have to enable the agent.
value bool true if enabling, false if disabling.

_afterAgentEnable

function _afterAgentEnable(uint256 agentId, enum AgentRegistryEnable.Permission permission, bool value) internal virtual

Hook _after agent enable

emits Router hook

Name Type Description
agentId uint256 ERC721 token id of the agent.
permission enum AgentRegistryEnable.Permission the sender claims to have to enable the agent.
value bool true if enabling, false if disabling.

_msgSender

function _msgSender() internal view virtual returns (address sender)

Obligatory inheritance dismambiguation of ForwardedContext's _msgSender()

Name Type Description
sender address msg.sender if not a meta transaction, signer of forwarder metatx if it is.

_msgData

function _msgData() internal view virtual returns (bytes)

Obligatory inheritance dismambiguation of ForwardedContext's _msgSender()

Name Type Description
[0] bytes sender msg.data if not a meta transaction, forwarder data in metatx if it is.

__gap

uint256[49] __gap

AgentRegistryCore

_stakeThreshold

struct IStakeSubject.StakeThreshold _stakeThreshold

frontRunningDelay

uint256 frontRunningDelay

AgentCommitted

event AgentCommitted(bytes32 commit)

AgentUpdated

event AgentUpdated(uint256 agentId, address by, string metadata, uint256[] chainIds)

StakeThresholdChanged

event StakeThresholdChanged(uint256 min, uint256 max, bool activated)

FrontRunningDelaySet

event FrontRunningDelaySet(uint256 delay)

onlyOwnerOf

modifier onlyOwnerOf(uint256 agentId)

Checks sender (or metatx signer) is owner of the agent token.

Name Type Description
agentId uint256 ERC721 token id of the agent.

onlySorted

modifier onlySorted(uint256[] array)

Checks if array of uint256 is sorted from lower (index 0) to higher (array.length -1)

Name Type Description
array uint256[] to check

prepareAgent

function prepareAgent(bytes32 commit) public

Save commit representing an agent to prevent frontrunning of their creation

Name Type Description
commit bytes32 keccak256 hash of the agent creation's parameters

registerAgent

function registerAgent(uint256 agentId, string metadata, uint256[] chainIds) public

Agent registration method. Mints an ERC721 token with the agent id for the sender and stores metadata.

Agent Ids are generated through the Forta Bot SDK (by hashing UUIDs) so the agentId collision risk is minimized. Fires _before and _after hooks within the inheritance tree. If front run protection is enabled (disabled by default), it will check if the keccak256 hash of the parameters has been committed in prepareAgent(bytes32).

Name Type Description
agentId uint256 ERC721 token id of the agent to be created.
metadata string IPFS pointer to agent's metadata JSON.
chainIds uint256[] ordered list of chainIds where the agent wants to run.

createAgent

function createAgent(uint256 agentId, address, string metadata, uint256[] chainIds) external

Create agent method with old signature for backwards compatibility. Owner parameter is ignore in favour of sender. This method is deprecated and it will be removed in future versions of AgentRegistryCore

isRegistered

function isRegistered(uint256 agentId) public view returns (bool)

Checks if the agentId has been minted.

Name Type Description
agentId uint256 ERC721 token id of the agent.
Name Type Description
[0] bool true if agentId exists, false otherwise.

updateAgent

function updateAgent(uint256 agentId, string metadata, uint256[] chainIds) public

Updates parameters of an agentId (metadata, image, chain IDs...) if called by the agent owner.

fires _before and _after hooks within the inheritance tree.

Name Type Description
agentId uint256 ERC721 token id of the agent to be updated.
metadata string IPFS pointer to agent's metadata JSON.
chainIds uint256[] ordered list of chainIds where the agent wants to run.

setStakeThreshold

function setStakeThreshold(struct IStakeSubject.StakeThreshold newStakeThreshold) external

StakeThreshold setter, common to all Agents. Restricted to AGENT_ADMIN_ROLE, emits StakeThresholdChanged

getStakeThreshold

function getStakeThreshold(uint256) public view returns (struct IStakeSubject.StakeThreshold)

stake threshold common for all agents

_isStakeActivated

function _isStakeActivated() internal view returns (bool)

_isStakedOverMin

function _isStakedOverMin(uint256 subject) internal view returns (bool)

Checks if agent is staked over minimum stake

Name Type Description
subject uint256 agentId
Name Type Description
[0] bool true if agent is staked over the minimum threshold and is, or staking is not enabled (stakeController = 0 or activated = false ). false otherwise

setFrontRunningDelay

function setFrontRunningDelay(uint256 delay) external

allows AGENT_ADMIN_ROLE to activate frontrunning protection for agents

Name Type Description
delay uint256 in seconds

_beforeAgentUpdate

function _beforeAgentUpdate(uint256 agentId, string newMetadata, uint256[] newChainIds) internal virtual

hook fired before agent creation or update.

does nothing in this contract.

Name Type Description
agentId uint256 ERC721 token id of the agent to be created or updated.
newMetadata string IPFS pointer to agent's metadata JSON.
newChainIds uint256[] ordered list of chainIds where the agent wants to run.

_agentUpdate

function _agentUpdate(uint256 agentId, string newMetadata, uint256[] newChainIds) internal virtual

logic for agent update.

emits AgentUpdated, will be extended by child contracts.

Name Type Description
agentId uint256 ERC721 token id of the agent to be created or updated.
newMetadata string IPFS pointer to agent's metadata JSON.
newChainIds uint256[] ordered list of chainIds where the agent wants to run.

_afterAgentUpdate

function _afterAgentUpdate(uint256 agentId, string newMetadata, uint256[] newChainIds) internal virtual

hook fired after agent creation or update.

emits Router hook.

Name Type Description
agentId uint256 ERC721 token id of the agent to be created or updated.
newMetadata string IPFS pointer to agent's metadata JSON.
newChainIds uint256[] ordered list of chainIds where the agent wants to run.

_msgSender

function _msgSender() internal view virtual returns (address sender)

Obligatory inheritance dismambiguation of ForwardedContext's _msgSender()

Name Type Description
sender address msg.sender if not a meta transaction, signer of forwarder metatx if it is.

_msgData

function _msgData() internal view virtual returns (bytes)

Obligatory inheritance dismambiguation of ForwardedContext's _msgSender()

Name Type Description
[0] bytes sender msg.data if not a meta transaction, forwarder data in metatx if it is.

ownerOf

function ownerOf(uint256 subject) public view virtual returns (address)

__gap

uint256[41] __gap