Capabilities Bitmask
Agent capabilities are encoded as au64 bitmask. Each bit position represents
a DeFi skill the agent is authorized to perform:
| Flag | Bit | Value | Description |
|---|---|---|---|
CAP_TRADE | 0 | 1 | Spot token swaps |
CAP_PERPS | 1 | 2 | Perpetual position management |
CAP_LEND | 2 | 4 | Lending and borrowing |
CAP_YIELD | 3 | 8 | Yield farming strategies |
CAP_OPTIONS | 4 | 16 | Options trading |
CAP_TIMEBOOST | 5 | 32 | Express lane bidding |
CAP_RWA | 6 | 64 | Real-world asset stock trading |
CAP_TRADE | CAP_PERPS | CAP_LEND (value 7) can swap, manage perps, and
lend — but cannot bid for express lane access or trade RWA stocks.
Storage Layout
uint256 values starting at 0. Each agent
maps to an owner address, a capabilities bitmask, a revenue share in basis
points, a reputation score, and an active flag.
Public Methods
register(capabilities, revenue_share_bps) -> Result<U256>
register(capabilities, revenue_share_bps) -> Result<U256>
update(agent_id, capabilities, revenue_share_bps) -> Result<bool>
update(agent_id, capabilities, revenue_share_bps) -> Result<bool>
deactivate(agent_id) -> bool
deactivate(agent_id) -> bool
Deactivate an agent. Callable by the owner or the governance address.
- Returns
trueon success,falseif unauthorized. - Emits
AgentDeactivated(agentId).
update_reputation(agent_id, new_score) -> bool
update_reputation(agent_id, new_score) -> bool
Set a new reputation score for an agent. Governance only.
- Returns
trueon success,falseif the caller is not governance. - Emits
ReputationUpdated(agentId, newScore).
get_agent(agent_id) -> (Address, U256, U256, U256, bool)
get_agent(agent_id) -> (Address, U256, U256, U256, bool)
Read an agent’s full record.Returns
(owner, capabilities, revenue_share_bps, reputation, active).has_capability(agent_id, cap_flag) -> bool
has_capability(agent_id, cap_flag) -> bool
Check whether an agent has a specific capability flag set.
total_agents() -> U256
total_agents() -> U256
Returns the total number of agents ever registered (including deactivated).
set_governance(new_governance) -> bool
set_governance(new_governance) -> bool
Set the governance address. If governance is currently
address(0), any
caller can set it (one-time bootstrap). After that, only the current
governance address can transfer governance.Events
| Event | Indexed Fields | Data Fields |
|---|---|---|
AgentRegistered | owner, agentId | capabilities |
AgentUpdated | agentId | capabilities, revenueShareBps |
AgentDeactivated | agentId | — |
ReputationUpdated | agentId | newScore |
Governance Model
The contract has a singlegovernance address with two exclusive powers:
- Deactivate any agent — acts as a safety valve if an agent is misbehaving.
- Update reputation scores — only governance can write to the
reputationmapping.
address(0). The first call to
set_governance bootstraps it. After that, only the current governance address
can transfer the role.
Test Coverage
The contract has 10 tests covering:- Agent registration and auto-increment IDs
- Capability bitmask checking
- Owner-only update enforcement
- Non-owner update rejection
- Deactivation by owner and governance
- Governance reputation updates (authorized and unauthorized)
- Revenue share boundary validation (max 10,000, above-max rejection)
- Multi-agent registration with distinct owners