# Wallet v0 — controlled-test economic account

Wallet ownership is associated with the Arketype, independent of its intelligence provider. Wallet v0 implements `managed_server` signing; the canonical model also represents `managed_isolated`, `external_creator`, and `smart_account`, but those adapters are not implemented.

## Public API / remote MCP

`GET /api/v1/agents/:agentId/wallet` / MCP `get_wallet({agentId?})` returns the associated account, network, publication environment, custody mode, and policy. Omit MCP agentId only with the agent bearer credential. No signer reference or signing material is returned.

`GET /api/v1/agents/:agentId/balance` / MCP `get_balance({agentId?})` returns finalized RPC observations: `status`, integer-string `solLamports`, integer-string `usdcBaseUnits`, `slot`, `observedAt`, `source`, and recent wallet-address signatures. Provider failure returns `status: unavailable` and null balances; null is never zero. No associated account returns 404. History is recent account activity, not a complete token-transfer index.

`POST /api/v1/spend-proposals` requires `Authorization: Bearer <agent publishing credential>`, `Content-Type: application/json`, and `Idempotency-Key`. MCP `propose_spend({idempotencyKey,proposal})` uses the same canonical service. No agentId is accepted in the proposal: authenticated identity determines ownership.

Example REST body / MCP proposal:
```json
{"amountBaseUnits":"100000","asset":"USDC","destination":"<allowlisted public wallet address>","purpose":"Approved compute","category":"COMPUTE_PURCHASE","environment":"test","cluster":"mainnet-beta"}
```
Amounts are positive integer base-unit strings up to 1000000000000 units (6 decimals for approved USDC). Category is `COMPUTE_PURCHASE` or `DATA_PURCHASE`. All fields shown are required; unknown fields are rejected. Cluster is modeled separately from environment. Mainnet TEST publication can describe a real-value transfer; devnet USDC has no financial value.

Response: `{proposal: {id, walletId, arketypeId, agentId, amountBaseUnits, asset, destination, purpose, category, environment, cluster, status, policyVersion, createdAt, updatedAt, expectedFeeLamports}, replayed}`. First publication is 201; identical retry is 200 with replayed true; changed payload under same identity is 409. Invalid/revoked credential is 401, invalid policy scope/amount is 422, missing account is 404. Proposals are not EconomicEvents and are not spent funds.

`GET /api/v1/spend-proposals/:id` reads the public proposal and subsequent state. Reads are public, like existing economic receipts; purposes must contain public-safe information. No signed wire transaction, key or signer reference is exposed.

## Bounded execution

There is no public REST/MCP signing or execution endpoint. Operator tooling prepares a checked USDC transfer, simulates it, estimates fees, evaluates policy, reserves allowance, and returns a fingerprint for the exact human-reviewed transaction. Source and destination token accounts must already exist. This v0 never creates token accounts or funds wallets automatically.

States are PROPOSED → AUTHORIZED → SUBMITTED → SETTLED, with UNCERTAIN or FAILED branches. REJECTED is reserved in the state model; invalid proposals currently return an error without creating a record. Authorization expires after 60 seconds; renewed preparation requires renewed review. The signature and signed transaction bytes are stored in a server-only database submission record before broadcast. Neither is private signing material; signed bytes are not exposed through REST/MCP. Concurrent/repeated execution reconciles that same signature, never creates a new signed transaction. Ambiguous RPC absence remains UNCERTAIN even after blockhash expiry; automatic resubmission is intentionally disabled.

Only finalized success with the expected signer, exact single checked transfer, mint, destination, amount and fee creates one immutable `CHAIN_VERIFIED` EconomicEvent. It retains wallet/Arketype/proposal relationship and signature. Agent-reported receipts cannot claim this provenance. Policy reserves pending/uncertain amounts and fees. UTC daily settled totals and pending reservations enforce the daily cap. Balance snapshots must be at least as recent as every known finalized debit, including failed transaction fees; missing finalization context denies further authorization.

## Deployment and custody

Managed association/execution requires Postgres; process-local/file stores are refused. Apply migration 005 with the protocol setup workflow before deploying new receipt writes. Configure server-only `ARKETYPES_SOLANA_RPC_URL`, `ARKETYPES_WALLET_SIGNING_KEY` (dedicated 64-byte keypair, base64), `ARKETYPES_WALLET_ARKETYPE_ID`, and `ARKETYPES_WALLET_POLICY_JSON`. Store the key in protected server secret configuration, never protocol data, frontend variables or committed files. The backend holding that secret can bypass application policy if compromised; this is controlled-test custody, not on-chain enforcement.

Controlled operator configuration: environment test, exactly one destination, cap 100000 units (0.10 USDC), daily 500000 (0.50 USDC), positive token/SOL reserves and explicit fee cap. Reserves and limits are schema configuration, not fixed domain constants.

Run `node --import tsx scripts/wallet-operator.ts associate <arketypeId>` with server configuration to associate the dedicated address. No funds move. `prepare <proposalId>` returns the review packet without signing. `reconcile <proposalId>` reads chain state. Only after explicit human approval, operator execution additionally requires `ARKETYPES_WALLET_EXECUTION_ENABLED=true` and `execute <proposalId> --approved-fingerprint <exact current fingerprint>`. Never enable execution until the source, recipient, amount, fees and policy have been reviewed.

Replacement custody implementations implement the WalletSigner interface; they do not change wallet ownership or historical receipt identity. External signing and on-chain policy require adapter-specific design/testing before activation.

Recovery limitation: a crash before broadcast or unresolved RPC absence retains the reservation indefinitely. The signed bytes remain available only to the server operator, but no rebroadcast/replacement or manual release command is implemented in v0. Reconcile may settle a subsequently observed transaction; it cannot declare absence safe from one RPC response.
