Phase 4 adds the managed codegen surface for Anchor IDLs, Codama clients, and frontend hooks.
| Path | Owner | Command |
|---|---|---|
codama.json |
sunscreen | sunscreen generate clients, chain build, chain serve |
clients/idl/*.json |
sunscreen | sunscreen generate idl, sunscreen generate frontend-hooks |
clients/js/src/generated/ |
Codama | sunscreen generate clients |
app/src/generated/sunscreen/idl.ts |
sunscreen | sunscreen generate frontend-hooks |
app/src/generated/sunscreen/core.ts |
sunscreen | sunscreen generate frontend-hooks |
app/src/generated/sunscreen/react.ts |
sunscreen | sunscreen generate frontend-hooks for React frontends, or `--target react |
app/src/generated/sunscreen/solid.ts |
sunscreen | `sunscreen generate frontend-hooks --target solid |
app/src/generated/sunscreen/index.ts |
sunscreen | sunscreen generate frontend-hooks |
These files are fully generated and are overwritten only when the rendered bytes change. They do not use Rust marker comments; markers remain a Rust scaffolding contract documented in markers.md.
Copies built Anchor IDLs from target/idl/*.json into clients/idl/*.json using deterministic pretty JSON. Run sunscreen chain build first when the Anchor IDL does not exist yet.
Options:
--program <NAME>exports one program IDL.--out-dir <DIR>changes the workspace-relative output directory. The default isclients/idl.
Writes codama.json and runs:
pnpm exec codama run --all --config codama.json
The managed config currently defines the JavaScript renderer:
{
"idl": "target/idl/<program>.json",
"before": [],
"scripts": {
"js": {
"from": "@codama/renderers-js",
"args": ["clients/js/src/generated"]
}
}
}If target/idl already contains an IDL, sunscreen uses that file stem. Otherwise it falls back to the first program in sunscreen.yml, or to --program <NAME>.
Exports IDLs if needed, then emits framework-agnostic IDL/core TypeScript plus TanStack React Query and Solid Query wrappers.
Options:
--program <NAME>generates hooks for one program.--frontend-path <DIR>writes hooks into an explicit frontend root. This is required for workspaces created with--frontend none.--target all|react|solidselects hook files. For scaffolded Next.js and Vite React frontends, the default isreact; pass--target solidor--target allonly when the app installs Solid Query dependencies.
The generated core.ts includes createSurfpoolRpc() with the local endpoint http://127.0.0.1:8899, plus getProgramAccounts() for local Surfpool/test-validator reads. Instruction mutations are generated from IDL instruction names and argument lists; callers provide the transaction executor so wallet/client policy remains application-owned.
All sunscreen-owned codegen files use byte-for-byte write guards. A second run with the same IDL and options reports an empty changed_files list under --json and does not rewrite files.
Normal CI covers:
tests/codegen_codama.rsfor stablecodama.jsonrendering.tests/generate.rsfor CLI idempotency, Codama subprocess arguments, frontend hook shape, and--frontend noneerror handling.- Runtime pipeline tests for the shared Codama wrapper used by
chain buildandchain serve.
The real Next.js typecheck is available as an ignored/gated test:
SUNSCREEN_FRONTEND_COMPILE_TESTS=1 cargo test --test generate generated_frontend_hooks_typecheck_vanilla_next_project_when_dependencies_are_installed -- --ignored