Accounts are in wire order. S marks a signer and W a writable account. Every instruction ends with Anchor’s event authority and the program itself, which emit_cpi! needs. Associated token accounts must exist when used. Programs that refuse return the errors named under each instruction; Anchor’s own constraint errors, SPL Token’s errors and InvalidArgument keep their usual codes.
| Instruction | Signs | Discriminator |
|---|---|---|
charter | principal | f6cdb96ae78da650 |
deposit | funder | f223c68952e1f2b6 |
withdraw | principal | b712469c946da122 |
set_policy | principal | 28850c9debca0284 |
freeze | principal | ff5bcf54fbc2fe3f |
unfreeze | principal | 85a044fd50e8daf7 |
revoke | principal | aa171f2285ad5df2 |
list_service | principal | 01d2dc615e0bce22 |
unlist_service | principal | b2ec0e07db2ca71b |
settle | submitter | af2ab957908366d4 |
initialize_config | admin | d07f1501c2bec446 |
update_config | admin | 1d9efcbf0a53db63 |
charter
Creates the Agent account with policy version 1, initializes its vault and moves the first deposit from the principal’s USDC account, all in one instruction. The agent key consents first: an Ed25519 instruction just before charter carries its signature over the consent bytes. The agent key signs no transaction, so its holder can sign the consent apart and hand it over.
agent_keypubkeyrequired- The agent’s ed25519 public key.
card_hash[u8; 32]required- SHA-256 of the card JSON, as
POST /v1/cardsreturns it. card_uristringrequired- Where the card is served. Over 200 bytes fails with
InvalidArgument. policyPolicyrequired- The first policy. A zero
period_secondsor an allowlist over eight keys fails withInvalidArgument. first_depositu64required- USDC moved from the principal into the vault, in base units. May be 0.
consent_expires_ati64required- Unix seconds the agent key signed as its consent’s expiry. At or after it,
ConsentExpired.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | principal | S | W | The chartering wallet. Signs and pays rent for the agent and the vault. | |
| 1 | config | PDA "config" | The Config PDA. | ||
| 2 | agent | W | PDA "agent", agent_key | The Agent PDA for agent_key, created here. A key that was ever chartered fails here. | |
| 3 | vault | W | PDA "vault", Agent PDA | The vault PDA, created here as an SPL token account. | |
| 4 | principal_ata | W | The principal’s USDC associated token account. Must exist even when first_deposit is 0. | ||
| 5 | usdc_mint | The settlement mint. Must equal config.usdc_mint. | |||
| 6 | token_program | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | The classic SPL Token program. | ||
| 7 | system_program | 11111111111111111111111111111111 | The System program. | ||
| 8 | instructions | Sysvar1nstructions1111111111111111111111111 | The instructions sysvar, read to find the Ed25519 instruction with the agent key’s consent, placed just before this one. | ||
| 9 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 10 | program | The Civitas program itself, for the event CPI. |
Checks, in the order the program runs them:
- The card URI is at most 200 bytes and the policy is valid (
InvalidArgument). - The consent’s
consent_expires_atis still ahead (ConsentExpired). - The instruction just before is a single-signature Ed25519 instruction whose key is
agent_keyand whose message is the consent bytes for this principal, agent key, card hash and expiry (BadConsent). - The agent account and the vault are created, and the first deposit moves. A key that was ever chartered fails here.
Raises ConsentExpired, BadConsent.
deposit
Moves USDC into a vault from any wallet’s USDC account. The Deposited event names the funder, which the filter reads as a funding link.
amountu64required- Base units. 0 fails with
InvalidArgument.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | funder | S | Any wallet. Signs. | ||
| 1 | config | PDA "config" | The Config PDA. | ||
| 2 | agent | PDA "agent", agent_key | The Agent PDA of the agent acted on. | ||
| 3 | vault | W | PDA "vault", Agent PDA | The agent’s vault. | |
| 4 | funder_ata | W | The funder’s USDC associated token account. | ||
| 5 | token_program | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | The classic SPL Token program. | ||
| 6 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 7 | program | The Civitas program itself, for the event CPI. |
Emits Deposited.
Raises AgentRevoked.
withdraw
Moves USDC from the vault to the principal. Works while the agent is frozen.
amountu64required- Base units. 0 fails with
InvalidArgument; more than the balance fails in SPL Token.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | principal | S | The agent’s principal. Signs. | ||
| 1 | config | PDA "config" | The Config PDA. | ||
| 2 | agent | PDA "agent", agent_key | The Agent PDA of the agent acted on. | ||
| 3 | vault | W | PDA "vault", Agent PDA | The agent’s vault. | |
| 4 | principal_ata | W | The principal’s USDC associated token account. | ||
| 5 | token_program | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | The classic SPL Token program. | ||
| 6 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 7 | program | The Civitas program itself, for the event CPI. |
Emits Withdrawn.
Raises AgentRevoked.
set_policy
Replaces the policy and adds 1 to its version. Spending already counted in the current period is kept, and periods are counted again at the new period_seconds from created_at.
policyPolicyrequired- The new policy, under the same rules as at charter.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | principal | S | The agent’s principal. Signs. | ||
| 1 | agent | W | PDA "agent", agent_key | The Agent PDA of the agent acted on. | |
| 2 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 3 | program | The Civitas program itself, for the event CPI. |
Emits PolicySet.
Raises AgentRevoked.
freeze
Stops settlements from the agent from the next one on.
No arguments.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | principal | S | The agent’s principal. Signs. | ||
| 1 | agent | W | PDA "agent", agent_key | The Agent PDA of the agent acted on. | |
| 2 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 3 | program | The Civitas program itself, for the event CPI. |
Emits Frozen.
Raises AgentRevoked.
unfreeze
Lets the agent settle again under its current policy.
No arguments.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | principal | S | The agent’s principal. Signs. | ||
| 1 | agent | W | PDA "agent", agent_key | The Agent PDA of the agent acted on. | |
| 2 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 3 | program | The Civitas program itself, for the event CPI. |
Emits Unfrozen.
Raises AgentRevoked.
revoke
Returns the whole vault to the principal, closes the vault (its rent goes to the principal), unlists the service if it is listed, and marks the agent revoked. Nothing can undo it.
No arguments.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | principal | S | W | The agent’s principal. Signs and receives the vault’s rent. | |
| 1 | config | PDA "config" | The Config PDA. | ||
| 2 | agent | W | PDA "agent", agent_key | The Agent PDA of the agent acted on. | |
| 3 | vault | W | PDA "vault", Agent PDA | The agent’s vault. | |
| 4 | principal_ata | W | The principal’s USDC associated token account. | ||
| 5 | service | W | PDA "service", Agent PDA | The Service PDA. Pass the canonical address even if the agent never listed one. | |
| 6 | token_program | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | The classic SPL Token program. | ||
| 7 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 8 | program | The Civitas program itself, for the event CPI. |
Emits Revoked, ServiceUnlisted.
Raises AgentRevoked.
list_service
Lists the agent’s endpoint and price per call, or updates an existing listing. The first listing creates the Service account at the principal’s expense.
endpointstringrequired- The URL, 1 to 200 UTF-8 bytes. Outside that fails with
InvalidArgument. price_per_callu64required- Base units. 0 fails with
InvalidArgument.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | principal | S | W | The agent’s principal. Signs and pays rent on the first listing. | |
| 1 | agent | PDA "agent", agent_key | The Agent PDA of the agent acted on. | ||
| 2 | service | W | PDA "service", Agent PDA | The Service PDA. | |
| 3 | system_program | 11111111111111111111111111111111 | The System program. | ||
| 4 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 5 | program | The Civitas program itself, for the event CPI. |
Emits ServiceListed.
Raises AgentRevoked.
unlist_service
Takes the listing out of the catalog. The Service account stays, so listing again updates it.
No arguments.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | principal | S | The agent’s principal. Signs. | ||
| 1 | agent | PDA "agent", agent_key | The Agent PDA of the agent acted on. | ||
| 2 | service | W | PDA "service", Agent PDA | The Service PDA. Must already exist. | |
| 3 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 4 | program | The Civitas program itself, for the event CPI. |
Emits ServiceUnlisted.
Raises AgentRevoked.
settle
Moves one call’s payment from the payer’s vault to the payee and the fee to the fee recipient, after checking the agent’s signed authorization, its nonce and every policy limit. The service submits it and pays the network fee.
payeepubkeyrequired- The key being paid. When it is a chartered agent the USDC lands in its vault; otherwise in the payee’s USDC associated token account.
amountu64required- Base units paid to the payee. 0 fails with
InvalidArgument. feeu64required- The protocol fee the agent signed for. It must equal the fee the config gives for
amount, orFeeMismatch. nonceu64required- The payer’s replay nonce, chosen by the agent.
call_id[u8; 32]required- The 32-byte call ID from the 402 quote.
expires_ati64required- Unix seconds from which the authorization no longer settles.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | submitter | S | Whoever submits the settlement. Signs and pays the network fee. In @civitas/service it is a key of the service’s own, separate from the payee. | ||
| 1 | config | PDA "config" | The Config PDA. | ||
| 2 | agent | W | PDA "agent", agent_key | The payer’s Agent PDA. | |
| 3 | vault | W | PDA "vault", Agent PDA | The payer’s vault. | |
| 4 | payee_agent | The canonical Agent PDA for payee, whether or not the payee is chartered. | |||
| 5 | destination | W | The payee’s vault when it is chartered; otherwise its USDC associated token account. | ||
| 6 | fee_ata | W | The fee recipient’s USDC associated token account. | ||
| 7 | instructions | Sysvar1nstructions1111111111111111111111111 | The instructions sysvar, read to find the Ed25519 instruction placed just before this one. | ||
| 8 | token_program | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | The classic SPL Token program. | ||
| 9 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 10 | program | The Civitas program itself, for the event CPI. |
Checks, in the order the program runs them:
- The payer is not revoked (
AgentRevoked) and not frozen (AgentFrozen). - The policy has no expiry or it is still ahead (
PolicyExpired). - The authorization’s
expires_atis still ahead (AuthorizationExpired). - The amount is above zero and the vault is the payer’s USDC account.
- The instruction just before is a single-signature Ed25519 instruction whose key is the agent key and whose message is the authorization bytes (
BadSignature). - The signed fee is the one the config gives for this amount (
FeeMismatch). - The nonce is unused and no more than 255 below the highest settled (
NonceReplayed). - The payee is allowed (
PayeeNotAllowed). - Amount plus fee fits the per-call limit (
OverPerCallLimit). - After moving to the current period, the period’s spending plus this charge fits the cap (
OverPeriodCap). - The fee account and the destination are the expected accounts; a revoked payee fails with
AgentRevoked. - Both transfers run, the nonce is spent, and
Settledis emitted. A failed check leaves nothing changed.
Emits Settled.
Raises AgentRevoked, AgentFrozen, PolicyExpired, AuthorizationExpired, BadSignature, FeeMismatch, NonceReplayed, PayeeNotAllowed, OverPerCallLimit, OverPeriodCap.
initialize_config
Creates the Config account once. Only the designated deployer can call it. It sets the fee to 25 bps with a floor of 500 base units and the launch wallet as fee recipient, and binds the USDC mint for good.
No arguments.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | admin | S | W | EDrnAyx4vti9u6RTgR9JnuMBRUSYdS2gvEfRS8aSeGx3 | The designated deployer. Signs and pays rent. |
| 1 | config | W | PDA "config" | The Config PDA, created here. | |
| 2 | usdc_mint | The settlement mint. Must have six decimals. | |||
| 3 | system_program | 11111111111111111111111111111111 | The System program. | ||
| 4 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 5 | program | The Civitas program itself, for the event CPI. |
Emits ConfigUpdated.
update_config
Changes the fee terms and the fee recipient. The mint can’t change, so existing vaults stay valid.
fee_bpsu16required- New fee in basis points. Above 10,000 fails with
InvalidArgument. fee_flooru64required- New floor in base units.
fee_recipientpubkeyrequired- Wallet whose USDC associated token account receives fees from the next settlement on. Its ATA must exist before then.
| # | Account | S | W | Address | What it is |
|---|---|---|---|---|---|
| 0 | admin | S | The Config admin. Signs. | ||
| 1 | config | W | PDA "config" | The Config PDA. | |
| 2 | event_authority | PDA "__event_authority" | Anchor’s event authority PDA, used by emit_cpi!. | ||
| 3 | program | The Civitas program itself, for the event CPI. |
Emits ConfigUpdated.