A policy bounds what one agent may spend. The principal sets it at charter and can replace it at any moment. The program checks it inside settle, so nothing the agent signs can get past it: an authorization over the limit is refused on chain, and the vault doesn't move.
The fields
The API takes a policy in this shape. Amounts are USDC base units as decimal strings, so 1 USDC is "1000000".
perCallu64 stringrequired- Most the vault may lose on one settlement, amount and fee together.
perPeriodu64 stringrequired- Most the vault may lose in one period, amount and fee together.
periodSecondsintegerrequired- The period's length in seconds. At least 1.
counterpartiesaddress[] | nullrequirednulllets the agent pay anyone. A list of up to 8 keys lets it pay only those. An empty list lets it pay no one.expiryISO 8601 | nullrequired- From this time on, every settlement is refused.
nullfor never.
On chain the same fields are max_per_call, max_per_period, period_seconds, counterparties and expires_at, described on Program accounts.
The fee counts
Each settlement takes the amount and the protocol fee from the vault, and the per-call limit and the period cap both count the two together. A call priced at 5,000 base units carries a fee of 500, so it needs a per-call limit of at least 5,500. With a limit of 5,499 the program refuses it with OverPerCallLimit.
Periods
perPeriod applies to fixed periods of periodSeconds, counted from the moment the agent was chartered. An agent chartered at 12:00:00 UTC with a period of 86,400 seconds has periods that start at 12:00:00 UTC every day. When a settlement comes after the stored period has ended, the program moves the period start forward to the period that holds it and resets the spending to zero. The program keeps the current period's start and spending in the agent account, and each settlement reports the spending after it as spentInPeriod.
Versions
Every policy has a version: 1 at charter, and one more each time the principal sets a new policy. Each settlement records the version it ran under, so any payment traces back to the limits its principal had set at that moment. GET /v1/agents/{key} returns the current policy and every earlier version with the time it took effect.
A new policy keeps the spending already counted in the current period. If the new policy changes periodSeconds, the periods are counted again at the new length from the charter time.
Refusals
When a settlement breaks the policy, the program refuses it with a named error and nothing moves.
| Error | The settlement |
|---|---|
OverPerCallLimit | costs more than perCall, amount and fee together |
OverPeriodCap | would take this period's spending over perPeriod |
PayeeNotAllowed | pays a key that isn't on the list |
PolicyExpired | comes at or after expiry |
The program also refuses a frozen or revoked agent, an expired authorization, a bad signature and a replayed nonce. All nine errors, and the order the program checks them in, are on Errors and under settle.