Status: superseded for alpha — see [ADR-0015](../adr/0015-usdt-custodial-settlement.md), issue [33](33-settlement-loop.md)/[34](34-forfeiture-penalty.md). ADR-0015 replaces the on-chain Anchor stake/registry/settlement contracts below with a custodial USDT treasury + off-chain ledger, and explicitly targets **Solana devnet** (with a mock-USDT SPL mint) rather than the "testnet, never devnet" rule stated here — see [ADR-0016](../adr/0016-alpha-scope-and-known-limitations.md) for the alpha scope this fits into.

# 06 — Solana stake + settlement contracts

## What to build

Deploy and integrate the Solana smart contracts that make node staking, client payment, and token reward settlement trustless. All development and testing targets **Solana testnet** — never devnet or mainnet during development, to avoid real costs.

Three contracts are needed:

**Registry contract**: records stake balances, strike counts, and ban status per wallet. The gateway and tracker read from this contract to exclude banned wallets from route selection.

**Payment contract**: clients pre-fund an API key account with SOL or USDC. The gateway records per-request compute attribution (which node served which layer range, for how many tokens).

**Settlement contract**: called once per epoch. Debits client accounts proportional to compute consumed. Credits node operator wallets with our native token proportional to layers served. Distributes a validator reward share.

The `packages/contracts` package provides Python wrappers for reading and writing to all three contracts. The gateway uses these wrappers to check stake before routing to a node and to record attribution after each request.

## Acceptance criteria

- [ ] All contracts deploy successfully to Solana testnet
- [ ] A node can submit a stake transaction and have its balance reflected in the registry contract
- [ ] A client can fund an API key account with testnet SOL
- [ ] After a completed inference session, compute attribution is recorded on-chain with correct node/layer attribution
- [ ] The epoch settlement transaction correctly distributes token rewards to node operators and deducts client balances
- [ ] The gateway refuses to route to a node whose stake balance is below the minimum threshold
- [ ] All contract interactions in tests run against a local Solana test validator (via `solana-test-validator`) — no live testnet required for CI
- [ ] A `.env.testnet` config points to Solana testnet RPC for manual end-to-end testing

## Blocked by

- `03-tracker-registration-and-routing.md`
