Reference

Instructions

Every instruction of the Civitas program: its arguments, accounts in wire order, checks, effects, events and errors.

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.

InstructionSignsDiscriminator
charterprincipalf6cdb96ae78da650
depositfunderf223c68952e1f2b6
withdrawprincipalb712469c946da122
set_policyprincipal28850c9debca0284
freezeprincipalff5bcf54fbc2fe3f
unfreezeprincipal85a044fd50e8daf7
revokeprincipalaa171f2285ad5df2
list_serviceprincipal01d2dc615e0bce22
unlist_serviceprincipalb2ec0e07db2ca71b
settlesubmitteraf2ab957908366d4
initialize_configadmind07f1501c2bec446
update_configadmin1d9efcbf0a53db63

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.

Arguments
agent_keypubkeyrequired
The agent’s ed25519 public key.
card_hash[u8; 32]required
SHA-256 of the card JSON, as POST /v1/cards returns it.
card_uristringrequired
Where the card is served. Over 200 bytes fails with InvalidArgument.
policyPolicyrequired
The first policy. A zero period_seconds or an allowlist over eight keys fails with InvalidArgument.
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.
#AccountSWAddressWhat it is
0principalSWThe chartering wallet. Signs and pays rent for the agent and the vault.
1configPDA "config"The Config PDA.
2agentWPDA "agent", agent_keyThe Agent PDA for agent_key, created here. A key that was ever chartered fails here.
3vaultWPDA "vault", Agent PDAThe vault PDA, created here as an SPL token account.
4principal_ataWThe principal’s USDC associated token account. Must exist even when first_deposit is 0.
5usdc_mintThe settlement mint. Must equal config.usdc_mint.
6token_programTokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DAThe classic SPL Token program.
7system_program11111111111111111111111111111111The System program.
8instructionsSysvar1nstructions1111111111111111111111111The instructions sysvar, read to find the Ed25519 instruction with the agent key’s consent, placed just before this one.
9event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
10programThe Civitas program itself, for the event CPI.

Checks, in the order the program runs them:

  1. The card URI is at most 200 bytes and the policy is valid (InvalidArgument).
  2. The consent’s consent_expires_at is still ahead (ConsentExpired).
  3. The instruction just before is a single-signature Ed25519 instruction whose key is agent_key and whose message is the consent bytes for this principal, agent key, card hash and expiry (BadConsent).
  4. The agent account and the vault are created, and the first deposit moves. A key that was ever chartered fails here.

Emits Chartered, Deposited.

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.

Arguments
amountu64required
Base units. 0 fails with InvalidArgument.
#AccountSWAddressWhat it is
0funderSAny wallet. Signs.
1configPDA "config"The Config PDA.
2agentPDA "agent", agent_keyThe Agent PDA of the agent acted on.
3vaultWPDA "vault", Agent PDAThe agent’s vault.
4funder_ataWThe funder’s USDC associated token account.
5token_programTokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DAThe classic SPL Token program.
6event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
7programThe 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.

Arguments
amountu64required
Base units. 0 fails with InvalidArgument; more than the balance fails in SPL Token.
#AccountSWAddressWhat it is
0principalSThe agent’s principal. Signs.
1configPDA "config"The Config PDA.
2agentPDA "agent", agent_keyThe Agent PDA of the agent acted on.
3vaultWPDA "vault", Agent PDAThe agent’s vault.
4principal_ataWThe principal’s USDC associated token account.
5token_programTokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DAThe classic SPL Token program.
6event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
7programThe 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.

Arguments
policyPolicyrequired
The new policy, under the same rules as at charter.
#AccountSWAddressWhat it is
0principalSThe agent’s principal. Signs.
1agentWPDA "agent", agent_keyThe Agent PDA of the agent acted on.
2event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
3programThe Civitas program itself, for the event CPI.

Emits PolicySet.

Raises AgentRevoked.

freeze

Stops settlements from the agent from the next one on.

No arguments.

#AccountSWAddressWhat it is
0principalSThe agent’s principal. Signs.
1agentWPDA "agent", agent_keyThe Agent PDA of the agent acted on.
2event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
3programThe Civitas program itself, for the event CPI.

Emits Frozen.

Raises AgentRevoked.

unfreeze

Lets the agent settle again under its current policy.

No arguments.

#AccountSWAddressWhat it is
0principalSThe agent’s principal. Signs.
1agentWPDA "agent", agent_keyThe Agent PDA of the agent acted on.
2event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
3programThe 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.

#AccountSWAddressWhat it is
0principalSWThe agent’s principal. Signs and receives the vault’s rent.
1configPDA "config"The Config PDA.
2agentWPDA "agent", agent_keyThe Agent PDA of the agent acted on.
3vaultWPDA "vault", Agent PDAThe agent’s vault.
4principal_ataWThe principal’s USDC associated token account.
5serviceWPDA "service", Agent PDAThe Service PDA. Pass the canonical address even if the agent never listed one.
6token_programTokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DAThe classic SPL Token program.
7event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
8programThe 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.

Arguments
endpointstringrequired
The URL, 1 to 200 UTF-8 bytes. Outside that fails with InvalidArgument.
price_per_callu64required
Base units. 0 fails with InvalidArgument.
#AccountSWAddressWhat it is
0principalSWThe agent’s principal. Signs and pays rent on the first listing.
1agentPDA "agent", agent_keyThe Agent PDA of the agent acted on.
2serviceWPDA "service", Agent PDAThe Service PDA.
3system_program11111111111111111111111111111111The System program.
4event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
5programThe 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.

#AccountSWAddressWhat it is
0principalSThe agent’s principal. Signs.
1agentPDA "agent", agent_keyThe Agent PDA of the agent acted on.
2serviceWPDA "service", Agent PDAThe Service PDA. Must already exist.
3event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
4programThe 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.

Arguments
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, or FeeMismatch.
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.
#AccountSWAddressWhat it is
0submitterSWhoever 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.
1configPDA "config"The Config PDA.
2agentWPDA "agent", agent_keyThe payer’s Agent PDA.
3vaultWPDA "vault", Agent PDAThe payer’s vault.
4payee_agentThe canonical Agent PDA for payee, whether or not the payee is chartered.
5destinationWThe payee’s vault when it is chartered; otherwise its USDC associated token account.
6fee_ataWThe fee recipient’s USDC associated token account.
7instructionsSysvar1nstructions1111111111111111111111111The instructions sysvar, read to find the Ed25519 instruction placed just before this one.
8token_programTokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DAThe classic SPL Token program.
9event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
10programThe Civitas program itself, for the event CPI.

Checks, in the order the program runs them:

  1. The payer is not revoked (AgentRevoked) and not frozen (AgentFrozen).
  2. The policy has no expiry or it is still ahead (PolicyExpired).
  3. The authorization’s expires_at is still ahead (AuthorizationExpired).
  4. The amount is above zero and the vault is the payer’s USDC account.
  5. The instruction just before is a single-signature Ed25519 instruction whose key is the agent key and whose message is the authorization bytes (BadSignature).
  6. The signed fee is the one the config gives for this amount (FeeMismatch).
  7. The nonce is unused and no more than 255 below the highest settled (NonceReplayed).
  8. The payee is allowed (PayeeNotAllowed).
  9. Amount plus fee fits the per-call limit (OverPerCallLimit).
  10. After moving to the current period, the period’s spending plus this charge fits the cap (OverPeriodCap).
  11. The fee account and the destination are the expected accounts; a revoked payee fails with AgentRevoked.
  12. Both transfers run, the nonce is spent, and Settled is 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.

#AccountSWAddressWhat it is
0adminSWEDrnAyx4vti9u6RTgR9JnuMBRUSYdS2gvEfRS8aSeGx3The designated deployer. Signs and pays rent.
1configWPDA "config"The Config PDA, created here.
2usdc_mintThe settlement mint. Must have six decimals.
3system_program11111111111111111111111111111111The System program.
4event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
5programThe 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.

Arguments
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.
#AccountSWAddressWhat it is
0adminSThe Config admin. Signs.
1configWPDA "config"The Config PDA.
2event_authorityPDA "__event_authority"Anchor’s event authority PDA, used by emit_cpi!.
3programThe Civitas program itself, for the event CPI.

Emits ConfigUpdated.