> ## Documentation Index
> Fetch the complete documentation index at: https://omo-89a50a4e.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Setter

> Explains the Agent Setter contract's role in managing authorized agents for Omo Beacon Vaults

> [tab] Core Concepts
>
> # Agent Setter
>
> The Agent Setter is a crucial component of the Omo Protocol, responsible for managing the whitelist of agents that can interact with Omo Beacon Vaults. This contract ensures that only authorized agents can execute strategies within the ecosystem by allowing them to call onlyAgent functions within the Omo Beacon Vault contract. These whitelisted agents are entrusted with handling users' principal capital, interacting with the DeFi ecosystem on their behalf, and returning the users' funds when they request to redeem their assets.
>
> ## Key Features
>
> > [accordion] Whitelisting Mechanism
> >
> > The primary function of the Agent Setter is to maintain a whitelist of agent addresses. It provides:
> >
> > * A secure and efficient process for managing authorized agents
> > * A mapping to store the whitelist status of each agent
> > * Quick verification of an agent's authorization status
>
> > [accordion] Access Control
> >
> > The Agent Setter implements strict access control measures:
> >
> > * Only the contract owner can add or remove agents from the whitelist
> > * Ownership-based access control is implemented through the Owned contract
> > * Provides a robust and standardized ownership mechanism
>
> > [accordion] Smart Contract Functions
> >
> > The Agent Setter contract offers a set of functions for managing the agent whitelist:
> >
> > * addAgent and removeAgent for individual agent management
> > * addManyAgents and removeManyAgents for bulk operations
> > * Gas-efficient design for cost-effective management as the number of agents grows
>
> > [accordion] Event Emission
> >
> > To ensure transparency and enable off-chain tracking, the contract emits events:
> >
> > * AgentAdded event when a new agent is added to the whitelist
> > * AgentRemoved event when an agent is removed from the whitelist
> > * Events include the address of the affected agent for easy monitoring and auditing
>
> > [accordion] Integration with Omo Beacon Vault
> >
> > The Agent Setter plays a crucial role in the Omo Beacon Vault ecosystem:
> >
> > * Omo Beacon Vault contracts reference an instance of the Agent Setter
> > * Used to verify the authorization status of agents attempting to execute sensitive operations
> > * Ensures only whitelisted agents can perform critical actions within the vaults
> > * Maintains the security and integrity of the Omo Protocol ecosystem

> [tab] Advanced
>
> # AgentSetter.sol
>
> ## Overview
>
> AgentSetter is a crucial component of the OmoVault ecosystem, responsible for managing the whitelist of authorized agents who can process asynchronous deposit and redeem requests. It implements a role-based access control system and provides functionality to add, remove, and query agent status.
>
> ## Key Components
>
> ### State Variables
>
> 1. `mapping(address => bool) private _agents`: This mapping stores the whitelist status of agent addresses. The key is the agent address, and the value is a boolean indicating the whitelist status (true for whitelisted, false otherwise).
>
> 2. `uint256 private _agentCount`: This variable tracks the total number of whitelisted agents.
>
> ### Access Control
>
> The contract utilizes OpenZeppelin's `AccessControl` for role-based permissions. It defines two roles:
>
> 1. `AGENT_ADMIN_ROLE`: This role allows adding and removing agents.
> 2. `DEFAULT_ADMIN_ROLE`: This is the highest level of access, which can grant and revoke other roles.
>
> ### Events
>
> 1. `AgentAdded(address indexed agent)`: This event is emitted when a new agent is added to the whitelist.
>
> 2. `AgentRemoved(address indexed agent)`: This event is emitted when an agent is removed from the whitelist.
>
> ### Custom Errors
>
> 1. `AgentAlreadyWhitelisted(address agent)`: This error is thrown when attempting to add an already whitelisted agent.
>
> 2. `AgentNotWhitelisted(address agent)`: This error is thrown when attempting to remove a non-whitelisted agent.
>
> 3. `MaxAgentsReached()`: This error is thrown when attempting to add an agent beyond the maximum limit.
>
> ## Functions
>
> ### Constructor
>
> ```solidity theme={null}
> constructor(uint256 maxAgents_)
> ```
>
> | Name | Type | Description |
> | - | - | - |
> | maxAgents\_ | uint256 | The maximum number of agents allowed to whitelist |
>
> The constructor initializes the contract with a maximum number of allowed agents and sets the `msg.sender` as the default admin.
>
> ### addAgent
>
> ```solidity theme={null}
> function addAgent(address agent) external onlyRole(AGENT_ADMIN_ROLE)
> ```
>
> | Name | Type | Description |
> | - | - | - |
> | agent | address | The address of the agent to whitelist |
>
> This function adds a new agent to the whitelist. The caller must have `AGENT_ADMIN_ROLE`. The agent must not already be whitelisted, and the total agent count must be below the maximum limit. The function emits an `AgentAdded` event upon successful addition.
>
> ### removeAgent
>
> ```solidity theme={null}
> function removeAgent(address agent) external onlyRole(AGENT_ADMIN_ROLE)
> ```
>
> | Name | Type | Description |
> | - | - | - |
> | agent | address | The address of the agent to be removed |
>
> This function removes an agent from the whitelist. The caller must have `AGENT_ADMIN_ROLE`, and the agent must be currently whitelisted. The function emits an `AgentRemoved` event upon successful removal.
>
> ### isAgent
>
> ```solidity theme={null}
> function isAgent(address account) public view returns (bool)
> ```
>
> | Name | Type | Description |
> | - | - | - |
> | account | address | The address to check for agent status |
>
> This function checks if an address is a whitelisted agent. It returns `true` if the address is whitelisted, and `false` otherwise.
>
> ### getAgentCount
>
> ```solidity theme={null}
> function getAgentCount() external view returns (uint256)
> ```
>
> This function returns the current number of whitelisted agents.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.