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.
| Limit | Meaning |
|---|---|
| per_tx | The most one outflow may move. |
| per_day | The most all outflows may move over the current hour and the 23 before it. |
| expires_at_ms | After this moment the cap does nothing. |
| recipients | Up 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:
- The cap belongs to this treasury.
EWrongTreasury(1) - The cap is not revoked.
ECapRevoked(2) - The cap has not expired.
ECapExpired(3) - The amount is above zero.
EZeroAmount(8) - The amount is within
per_tx.EOverPerTx(4) - The 24-hour total stays within
per_day.EOverPerDay(5) - For a spend, the recipient is on the list.
ERecipientNotAllowed(6) - 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 ↗
Scroll sideways to see the whole diagram.
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
spent24hand can exhaustper_dayfor the rest of the window.
Lifecycle#
- active — limits present and not expired.
- expired — limits present, past
expires_at_ms; the owner can extend it withset_limits. - revoked — limits removed by the owner; permanent for that cap, since limits can only be changed on a cap that still has them.