Docs/Core concepts

AgentCap & limits

An AgentCap is the capability an agent's key holds to act on one treasury. It has key but not store, so the agent cannot transfer it to another address.

Limits#

Every AgentCap has one set of limits in its treasury.

LimitMeaning
per_txThe most one outflow may move.
per_dayThe most all outflows may move over the current hour and the 23 before it.
expires_at_msAfter this moment the cap does nothing.
recipientsUp to eight addresses a spend may pay.

Limits are valid only if per_tx is above zero and at most per_day, the expiry is in the future, and there are one to eight recipients.

Checks on every outflow#

An agent's outflow, whether a spend or a draw into a loan, runs these checks in this order:

  1. The cap belongs to this treasury. EWrongTreasury (1)
  2. The cap is not revoked. ECapRevoked (2)
  3. The cap has not expired. ECapExpired (3)
  4. The amount is above zero. EZeroAmount (8)
  5. The amount is within per_tx. EOverPerTx (4)
  6. The 24-hour total stays within per_day. EOverPerDay (5)
  7. For a spend, the recipient is on the list. ERecipientNotAllowed (6)
  8. The treasury holds enough. EInsufficientFunds (9)

Error codes are the abort codes of the treasury module.

Treasury and its two capsStatic diagram · Open full size ↗
Treasury and its two capsThe owner controls the treasury with the OwnerCap; an agent spends or draws with its AgentCap, and every outflow passes eight checks in order.OWNER DEVICEAGENT PROCESSmint_cap · set_limitsrevoke · withdrawspend · drawspenddrawfailsOwner walletsigns owner callsOwnerCapone per treasurycapAgentits own keyAgentCapkey, no storecapTreasury<T>fundslimits per agentmandates lender rulesborrow_mandatesconsents sealed roomsoffersshared objectEvery outflow is checked1 cap of this treasury (1)2 cap not revoked (2)3 cap not expired (3)4 amount above zero (8)5 within per_tx (4)6 24 h within per_day (5)7 recipient on the list (6)8 treasury holds enough (9)in this orderRecipient≤ 8 per capLoan or offerdrawRefusedabort (code)LEGENDOff-chain processOn-chain shared objectCapability (key)Move moduleRefused by the chainCall / transactionUSDC movesRefusal (abort)
Scroll sideways to see the whole diagram.
Each outflow through an AgentCap is checked against the limits above before any coin moves; a failed check aborts the whole transaction.Source: docs/concepts/treasury-and-ownercap.md · docs/concepts/agentcap-and-limits.md · docs/concepts/agent-boundaries.md · api/onchain/treasury.md

How hosted agents use limits#

  • A lender agent's cap may spend one unit per transaction and per day, payable only to its owner; it funds loans through its mandate, not through spending.
  • A borrower agent's two caps pay only the owner, and their limits are set from the borrowing form: the collateral plus spare SUI on one, and the most the loan can owe at repayment on the other. Adding collateral draws SUI through that cap, so the amount counts against its spent24h and can exhaust per_day for the rest of the window.

Lifecycle#

  • active — limits present and not expired.
  • expired — limits present, past expires_at_ms; the owner can extend it with set_limits.
  • revoked — limits removed by the owner; permanent for that cap, since limits can only be changed on a cap that still has them.