@typesol/cli 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +227 -0
- package/README.md +64 -17
- package/SECURITY.md +9 -7
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +9 -0
- package/dist/cli.js +33 -15
- package/dist/compiler/analyze.js +57 -6
- package/dist/compiler/diagnostics.d.ts +4 -3
- package/dist/compiler/diagnostics.js +10 -6
- package/dist/compiler/emit/base.d.ts +1 -1
- package/dist/compiler/emit/calls.js +18 -5
- package/dist/compiler/emit/cpi-core.d.ts +3 -1
- package/dist/compiler/emit/cpi-core.js +8 -4
- package/dist/compiler/emit/expressions.d.ts +14 -0
- package/dist/compiler/emit/expressions.js +52 -4
- package/dist/compiler/emit/shared.d.ts +8 -1
- package/dist/compiler/emit/shared.js +8 -1
- package/dist/compiler/emit/statements.d.ts +8 -3
- package/dist/compiler/emit/statements.js +68 -3
- package/dist/compiler/emit/storage.js +5 -1
- package/dist/compiler/hints.d.ts +7 -0
- package/dist/compiler/hints.js +58 -9
- package/dist/compiler/index.d.ts +5 -0
- package/dist/compiler/index.js +10 -1
- package/dist/compiler/model.js +3 -2
- package/dist/compiler/toolchain.d.ts +50 -2
- package/dist/compiler/toolchain.js +96 -11
- package/dist/node-version.d.ts +4 -0
- package/dist/node-version.js +12 -0
- package/dist/tools/doctor.d.ts +41 -0
- package/dist/tools/doctor.js +96 -14
- package/dist/workspace.d.ts +9 -2
- package/dist/workspace.js +13 -3
- package/docker/deps/0.46.0.lock.json +1206 -0
- package/docs/ai.md +2 -1
- package/docs/architecture.md +7 -3
- package/docs/audit.md +6 -6
- package/docs/case-study-phoenix.md +1 -1
- package/docs/case-study-raydium-amm.md +1 -1
- package/docs/case-study-spl-stake-pool.md +1 -1
- package/docs/cli.md +42 -4
- package/docs/errors.md +22 -8
- package/docs/glossary.md +210 -0
- package/docs/language-accounts.md +499 -0
- package/docs/language-basics.md +389 -0
- package/docs/language-builtins.md +411 -0
- package/docs/language-chain.md +198 -0
- package/docs/language-cpi.md +470 -0
- package/docs/language-errors-events.md +184 -0
- package/docs/language-native.md +493 -0
- package/docs/language-pdas.md +198 -0
- package/docs/language-statements.md +620 -0
- package/docs/language-types.md +601 -0
- package/docs/language.md +190 -467
- package/docs/mainnet.md +18 -3
- package/docs/migrate-from-anchor.md +7 -6
- package/docs/security-model.md +3 -3
- package/docs/stability.md +3 -1
- package/docs/test-your-program.md +52 -15
- package/docs/troubleshooting.md +222 -100
- package/lib/typesol.d.ts +67 -22
- package/llms-full.txt +4915 -634
- package/llms.txt +12 -1
- package/package.json +2 -2
- package/releases/0.45.0.json +732 -0
- package/ts-plugin/index.js +16 -5
package/docs/ai.md
CHANGED
|
@@ -15,7 +15,8 @@ integer, `console.log`, `throw`, `xs[i]`) are refused. Four things close that ga
|
|
|
15
15
|
|
|
16
16
|
They say what ordinary TypeScript habits break (bigint integers, imports from `"typesol"`, no `throw` / `async` /
|
|
17
17
|
`class`, `Mut<T>` for an account that changes, `.get(i)` / `.set(i, v)` on lists) and how to check and test. Keep your
|
|
18
|
-
own project notes below them in AGENTS.md.
|
|
18
|
+
own project notes below them in AGENTS.md. `typesol init --no-agent-files` leaves these files and the MCP
|
|
19
|
+
configuration below out.
|
|
19
20
|
|
|
20
21
|
## llms.txt
|
|
21
22
|
|
package/docs/architecture.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Architecture
|
|
2
2
|
|
|
3
3
|
This document is for people changing TypeSOL itself. To write programs with it, read the [README](../README.md) and
|
|
4
|
-
the [language
|
|
4
|
+
the [language guide](language.md).
|
|
5
5
|
|
|
6
6
|
## Pipeline
|
|
7
7
|
|
|
@@ -34,7 +34,7 @@ program.so + program.build.json (manifest: versions, sha256 of sources and binar
|
|
|
34
34
|
| `test/` | The compiler's test suite (`pnpm test:core`), by subject: `language/`, `security/`, `examples/`, `integrations/` (token, Metaplex, oracle and other CPIs), `client/`, `cli/`, `verification/` (differential and fuzz tests). Shared: `harness.ts` and the `*-helpers.ts`, `fixtures/` (programs the tests compile), `golden/` (pinned generated C and clients, and what 14 programs build to in the build container: SBPF v0, and v1 and v2 for four of them), `programs/` (third-party program binaries, see its SOURCES.md), `anchor-twins/` (below) |
|
|
35
35
|
| `showcase/` | Ports, apart from the compiler's own tests (`pnpm test:showcase`, its own CI job): `mainnet/` (Phoenix v1, SPL Stake Pool, Raydium AMM v4, CP-Swap and CLMM, Jito's MEV programs, Marginfi, coral-xyz/multisig, each checked against the binary on mainnet), `program-examples/` (TypeSOL rewrites of solana-developers/program-examples), `test/` (their differential tests, fuzzers, helpers and fixtures; `porting/` for the program-examples) |
|
|
36
36
|
| `test/anchor-twins/` | Anchor twins of the counter, vault and escrow examples, for the differential tests (`pnpm build:twins`) and the zero-copy client test; the benchmarks themselves are in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) |
|
|
37
|
-
| `scripts/` | `smoke.ts`, `localnet.sh` and `localnet-fixtures.ts` (a local validator run), `fetch-programs.sh` (third-party binaries), `readme-bench.ts` (the README numbers), `codegen-snapshot.ts` (the generated C and IDL of every program, to diff a refactor), `release-manifest.ts` (a release's binary, IDL and toolchain hashes; the cross-host check against `test/golden/binaries.json`) |
|
|
37
|
+
| `scripts/` | `smoke.ts`, `localnet.sh` and `localnet-fixtures.ts` (a local validator run), `fetch-programs.sh` (third-party binaries), `readme-bench.ts` (the README numbers), `codegen-snapshot.ts` (the generated C and IDL of every program, to diff a refactor), `release-manifest.ts` (a release's binary, IDL and toolchain hashes; the cross-host check against `test/golden/binaries.json`), `language-builtins.ts` (`docs/language-builtins.md`, generated from `lib/typesol.d.ts`; `--check` in CI) |
|
|
38
38
|
| `docker/` | The Dockerfile of the `--docker` build container |
|
|
39
39
|
| `releases/` | Each release's npm tarball record (`scripts/release-check.ts`); shipped, so `--docker` can check the tarball it installs |
|
|
40
40
|
| `docs/` | User and contributor documentation (also published on typesol.com) |
|
|
@@ -70,6 +70,7 @@ program.so + program.build.json (manifest: versions, sha256 of sources and binar
|
|
|
70
70
|
| `src/tools/profile.ts` | Turns `--profile` logs into compute units per source line. |
|
|
71
71
|
| `src/tools/docker.ts` | `build --docker` / `verify --docker`: the TypeSOL version and its release record (the package's, a file, or fetched from the repository), the image from `docker/Dockerfile` (built when missing), the locked-down container run, the container's identity in the manifest. |
|
|
72
72
|
| `docker/Dockerfile` | The pinned build environment (linux/amd64, platform-tools v1.52, a recorded TypeSOL tarball); shipped in the package with `releases/`. |
|
|
73
|
+
| `src/bin.ts` | The `typesol` command: checks the Node.js version (`src/node-version.ts`, no imports) before it loads `src/cli.ts`. |
|
|
73
74
|
| `src/cli.ts` | Command parsing. Every command has strict options, `--help`, and exit codes 0 (success), 1 (failure), 2 (usage error) and 3 (verify mismatch). |
|
|
74
75
|
|
|
75
76
|
## The emitter
|
|
@@ -165,7 +166,9 @@ These invariants are easy to break. Each one has tests.
|
|
|
165
166
|
so that callers can wrap it in `TS_TRY`.
|
|
166
167
|
4. Add an execution test that compiles a fixture under `test/fixtures/` and runs it in LiteSVM. Add a diagnostics
|
|
167
168
|
case in `test/language/diagnostics.test.ts` for each misuse you reject.
|
|
168
|
-
5. Document it in `docs/language
|
|
169
|
+
5. Document it in the language guide page it belongs to (`docs/language-*.md`, with an example the guide's test
|
|
170
|
+
compiles), run `node scripts/language-builtins.ts` to list it in `docs/language-builtins.md`, and add a line to
|
|
171
|
+
`CHANGELOG.md`.
|
|
169
172
|
|
|
170
173
|
### Add an account constraint
|
|
171
174
|
|
|
@@ -200,6 +203,7 @@ the change. The sha256 values in the `*.build.json` manifests must not change.
|
|
|
200
203
|
| --- | --- |
|
|
201
204
|
| `test/<subject>/<feature>.test.ts` | Execution tests. Each compiles fixtures and runs them in LiteSVM through `test/harness.ts`. |
|
|
202
205
|
| `test/language/diagnostics.test.ts` | Every rejected construct, plus the golden C. |
|
|
206
|
+
| `test/language/docs-examples.test.ts` | Every example of the language guide (`docs/language*.md`) compiles, its refused constructs are refused with the quoted message, and links into the docs land on a heading. |
|
|
203
207
|
| `test/security/hardening.test.ts`, `test/security/regressions.test.ts` | Attacks and edge cases that once failed. Keep each as a negative test. |
|
|
204
208
|
| `test/verification/fuzz-*.test.ts`, `test/verification/differential.test.ts` | Randomized checks against BigInt, a TypeScript state model, and the Anchor twins in `test/anchor-twins`. See [testing.md](testing.md). |
|
|
205
209
|
| `test/verification/rbtree-trace.test.ts` | The RedBlackTree replaying traces lib-sokoban 0.3 itself recorded (`test/verification/rbtree/`, rebuilt by its `regenerate.sh` with a small Rust oracle the tests do not need), bytes compared after every operation. |
|
package/docs/audit.md
CHANGED
|
@@ -7,22 +7,22 @@ with TypeSOL are out of scope; their authors audit them.
|
|
|
7
7
|
|
|
8
8
|
## Scope
|
|
9
9
|
|
|
10
|
-
In order of priority. Line counts at 0.
|
|
10
|
+
In order of priority. Line counts at 0.45.0 (November 2026).
|
|
11
11
|
|
|
12
12
|
| Priority | Component | Files | Lines | Why |
|
|
13
13
|
| --- | --- | --- | ---: | --- |
|
|
14
14
|
| 1 | C runtime | `runtime/typesol_rt.h` | 2,998 | In every program: input parsing, account checks, checked arithmetic, PDAs, system and token CPIs, account creation, resizing and closing, oracles, signature checks, the heap |
|
|
15
15
|
| 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 876 | Which checks each account parameter gets, and their order |
|
|
16
|
-
| 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 3,
|
|
17
|
-
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,
|
|
16
|
+
| 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 3,867 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
|
|
17
|
+
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,711 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
|
|
18
18
|
| 1 | Raw views and the red-black tree | `src/compiler/emit/views.ts`, `rbtree.ts` | 655 | Accounts read without a discriminator at run-time offsets (`loadRaw`, `loadRawAt`, `rawArrayAt`, `BigVec`), their bounds, and the red-black tree's node indexes (`rbTreeAt`) |
|
|
19
19
|
| 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,465 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
|
|
20
|
-
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 2,
|
|
21
|
-
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 3,
|
|
20
|
+
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 2,168 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
|
|
21
|
+
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 3,545 | What the language accepts; constraints and account types as parsed from the source |
|
|
22
22
|
| 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,460 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
|
|
23
23
|
| 3 | Build and tooling | `src/compiler/toolchain.ts`, `src/cli.ts`, `src/workspace.ts`, `src/tools/` | | Build flags, deploy and verification commands |
|
|
24
24
|
|
|
25
|
-
The language surface is `lib/typesol.d.ts` (2,
|
|
25
|
+
The language surface is `lib/typesol.d.ts` (2,626 lines): every type and built-in a program can use, with its
|
|
26
26
|
documented behavior. [docs/language.md](language.md) is the reference; [docs/architecture.md](architecture.md) maps
|
|
27
27
|
the code, [docs/runtime.md](runtime.md) the runtime's conventions.
|
|
28
28
|
|
|
@@ -42,7 +42,7 @@ zero-padding retries, the market's statuses down to Tombstone, and the events by
|
|
|
42
42
|
|
|
43
43
|
## What it needed
|
|
44
44
|
|
|
45
|
-
TypeSOL gained these features for it (
|
|
45
|
+
TypeSOL gained these features for it ([Porting a native program](language-native.md)); programs that use none of them
|
|
46
46
|
compile to the same C as before:
|
|
47
47
|
|
|
48
48
|
- **lib-sokoban's RedBlackTree** over account bytes, `rbTreeAt` / `rbTreeMutAt`: `get`, `insert`, `remove`, `min`,
|
|
@@ -27,7 +27,7 @@ accepts them, and ignored.
|
|
|
27
27
|
|
|
28
28
|
## What it needed
|
|
29
29
|
|
|
30
|
-
TypeSOL gained what a native program needs (
|
|
30
|
+
TypeSOL gained what a native program needs ([Porting a native program](language-native.md)):
|
|
31
31
|
|
|
32
32
|
- `loadRaw<T>` / `loadRawMut<T>`: accounts with no discriminator, read from byte 0. The port makes the original's own
|
|
33
33
|
checks first (owner, an exact size, its error codes), then loads.
|
|
@@ -34,7 +34,7 @@ Redelegate, which the deployed program refuses ("will not be enabled"), as the p
|
|
|
34
34
|
|
|
35
35
|
## What it needed
|
|
36
36
|
|
|
37
|
-
TypeSOL gained these features for it (
|
|
37
|
+
TypeSOL gained these features for it ([Porting a native program](language-native.md); every other program compiles
|
|
38
38
|
to the same C as before):
|
|
39
39
|
|
|
40
40
|
- `loadBorsh<T>` / `storeBorsh`: a Borsh account without a discriminator, read into a local struct and written back
|
package/docs/cli.md
CHANGED
|
@@ -6,21 +6,21 @@ error. Exit codes: **0** success, **1** failure (compile errors, failed deploy,
|
|
|
6
6
|
|
|
7
7
|
| Command | What it does |
|
|
8
8
|
| --- | --- |
|
|
9
|
-
| `typesol init [<dir>] [--name <program>] [--template counter\|vault\|escrow]` | Create a project
|
|
9
|
+
| `typesol init [<dir>] [--name <program>] [--template counter\|vault\|escrow] [--no-agent-files]` | Create a project ([below](#typesol-init)). |
|
|
10
10
|
| `typesol new <program> [--template counter\|vault\|escrow]` | In a project: add a program, `programs/<program>.ts` and `tests/<program>.test.ts` from the template, and its entry in `typesol.json`. Refuses to overwrite files or reuse a name. |
|
|
11
|
-
| `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools (and a `toolchain` row: the tested ones, or untested with both versions), the Solana CLI, Docker (optional: only `--docker` builds need it; it says when they run emulated), its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
|
|
11
|
+
| `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools (and a `toolchain` row: the tested ones, or untested with both versions), the Solana CLI, Docker (optional: only `--docker` builds need it; it says when they run emulated), its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. The last line says what is ready (building and testing, or also deploying) and what the warnings concern. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
|
|
12
12
|
| `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--toolchain-strict] [--docker [--typesol-version <v>] [--release-record <file>]] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json` (the TypeSOL, TypeScript, clang and platform-tools versions, the host, the SBPF version, each source's sha256 and the binary's). With platform-tools other than the tested ones it warns once; `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) refuses them. The first build creates `<out>/deploy/<name>-keypair.json` and records the address in `typesol.json`; later builds refuse a different keypair. Without the keypair (a fresh clone, CI) it builds at the recorded address and says so; only `deploy` needs the keypair. `--docker` builds in the pinned container instead ([below](#build---docker-and-verify---docker)). |
|
|
13
13
|
| `typesol build <file.ts> [--out <dir>] [--program-id <keypair.json>] [--sbpf …] [--profile] [--toolchain-strict] [--docker …] [--quiet]` | Outside a project (or a file that is not one of its programs): build that file. Its keypair is `--program-id`, which must exist, or `<out>/<name>-keypair.json`, created on the first build. A project program's `.ts` builds as that program. |
|
|
14
14
|
| `typesol check [<program>… \| <file.ts>] [--json] [--stdin \| --files]` | Type-check and validate without building. In a project, no argument checks every program (or those named) and exits 1 if any has errors. `--json` prints `{ ok, diagnostics: [{ file, line, column, message }] }`, always (a missing file or unreadable `--files` input is a diagnostic too, exit 1 or 2); `--stdin` checks the text given on stdin as that file (its imports come from disk); `--files` reads `{ "files": { "<absolute path>": "<text>", … } }` from stdin and checks with those texts instead of the disk (an editor's unsaved buffers). |
|
|
15
15
|
| `typesol clone [<address>…] [--url <rpc>] [--config <cli config>] [--out <dir>]` | Copy cluster accounts and programs for the tests (Anchor's `[test.validator.clone]`): each account to `<address>.json` (lamports, owner, data), each program to `<address>.so` (its ELF, from the ProgramData account for upgradeable programs), in `tests/accounts` (`"accounts"` in `typesol.json`) or `--out`. Without addresses it clones the project's `"clone"` list. `testProgram` loads that directory into its LiteSVM; commit it so the tests run offline. |
|
|
16
16
|
| `typesol emit-c <file.ts> [--out <file.c>] [--profile]` | Print or write the generated C. |
|
|
17
17
|
| `typesol mcp` | Serve the Model Context Protocol on stdio for AI coding agents: tools to check a program (errors with hints), read its IDL, search the docs and read the rules a TypeSOL program follows. The `.mcp.json` / `.cursor/mcp.json` that `init` writes start it as `npx --no-install typesol mcp` (the project's own copy); see [ai.md](ai.md). |
|
|
18
|
-
| `typesol deploy [<program>…] [--url <rpc>] [--keypair <payer.json>] [--config <cli config>] [--dry-run] [--sbpf …] [--toolchain-strict]` | Build (`--toolchain-strict` as for `build`), then `solana program deploy --use-rpc` at the program keypair's address. Deploying again upgrades (the payer must be the upgrade authority). `--dry-run` builds and prints the commands. It needs a cluster, `--url` or `json_rpc_url` in the Solana CLI config: it never falls back to the CLI's default. Before sending anything it prints the cluster's host and the payer, checks that the RPC answers and that the payer holds enough for the rent (about twice the binary's on a first deploy, while the buffer exists), and says what to do if not (start `solana-test-validator`, `solana airdrop` on devnet or a local validator). Needs `solana` on PATH. |
|
|
18
|
+
| `typesol deploy [<program>…] [--url <rpc>] [--keypair <payer.json>] [--config <cli config>] [--dry-run] [--sbpf …] [--toolchain-strict]` | Build (`--toolchain-strict` as for `build`), then `solana program deploy --use-rpc` at the program keypair's address. Deploying again upgrades (the payer must be the upgrade authority). `--dry-run` builds and prints the commands. It needs a cluster, `--url` or `json_rpc_url` in the Solana CLI config: it never falls back to the CLI's default. Before sending anything it checks that the payer keypair exists (if not, it stops with `solana-keygen new`), prints the cluster's host and the payer, checks that the RPC answers and that the payer holds enough for the rent (about twice the binary's on a first deploy, while the buffer exists), and says what to do if not (start `solana-test-validator`, `solana airdrop` on devnet or a local validator). Needs `solana` on PATH. |
|
|
19
19
|
| `typesol idl publish [<program>…] [--url <rpc>] [--keypair <authority.json>] [--config <cli config>] [--non-canonical]` | Compile (the binary is not rebuilt), then write each IDL to the Program Metadata program (seed `idl`). Canonical IDLs must be signed by the upgrade authority. Defaults come from the Solana CLI config (`~/.config/solana/cli/config.yml`); it prints the cluster's host and the payer before sending. |
|
|
20
20
|
| `typesol cpi <idl.json> [--out <file.ts>] [--prefix <name>] [--address <base58>]` | Generate TypeSOL helpers that call another program from its IDL. Unsupported instructions are listed on stderr. |
|
|
21
21
|
| `typesol port <idl.json> [--out <file.ts>]` | A TypeSOL program skeleton from an Anchor IDL (0.30+/1.x), to port an Anchor program: account structs, enums, errors, events and one function per instruction with its accounts and arguments, each body `require(false, …NotPorted)` until written. Instruction discriminators (an explicit `@discriminator` when the name derives another), account names and error codes are kept, so existing clients keep working where the layouts match; notes on stderr list where they do not (Borsh `String`/`Option` in account data, a `Vec` that is not the last field). Error codes that skip ahead are kept with `@code`, and zero-copy types keep their IDL `repr`, `serialization` and field names (`@repr`, `@serialization`, `@idlName`). |
|
|
22
22
|
| `typesol client <idl.json> [--out <file.ts>] [--address <base58>]`, `typesol client --address <program id> [--url <rpc>] [--config <cli config>] [--out <file.ts>]` | Generate a typed TypeScript client on `@solana/kit` from an Anchor IDL (0.30+/1.x or TypeSOL); the IDL is validated first, and what the client leaves out is printed as notes. Without a file, the IDL is read from the chain: the canonical Program Metadata IDL, else Anchor's IDL account. See [client.md](client.md). |
|
|
23
|
-
| `typesol verify <program\|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>] [--sbpf …] [--manifest <name.build.json>] [--docker …]` | Rebuild and compare with what is deployed
|
|
23
|
+
| `typesol verify <program\|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>] [--sbpf …] [--manifest <name.build.json>] [--docker …]` | Rebuild and compare with what is deployed ([below](#typesol-verify)). |
|
|
24
24
|
| `typesol profile <logs.txt\|-> [--program <id>]` | Compute units per TypeScript line from the logs of a `--profile` build's transaction (exit 1 when the logs have no markers). |
|
|
25
25
|
| `typesol help <command>` | Same as `typesol <command> --help`. |
|
|
26
26
|
| `typesol --version` | Print the version. |
|
|
@@ -33,6 +33,44 @@ Builds (`build`, `deploy`, `verify`, `typesol/testing`) compare the active clang
|
|
|
33
33
|
with (`TESTED_TOOLCHAIN` in `typesol/compiler`: Agave 3.1.10, platform-tools v1.52): another one gets one warning per
|
|
34
34
|
process on stderr. `TYPESOL_TOOLCHAIN=strict` makes it an error everywhere, `warn` is the default.
|
|
35
35
|
|
|
36
|
+
## typesol init
|
|
37
|
+
|
|
38
|
+
`typesol init [<dir>] [--name <program>] [--template counter|vault|escrow] [--no-agent-files]` creates a project:
|
|
39
|
+
|
|
40
|
+
- `typesol.json`, `programs/<name>.ts`, `tests/<name>.test.ts` (LiteSVM), `package.json`, `tsconfig.json`,
|
|
41
|
+
`programs/tsconfig.json` (with the editor plugin), `.vscode/settings.json` (the workspace TypeScript, so the plugin
|
|
42
|
+
loads) and `.gitignore`;
|
|
43
|
+
- the rules for AI coding agents (`AGENTS.md`, `CLAUDE.md` importing it, `.cursor/rules/typesol.mdc`) and the MCP
|
|
44
|
+
server configuration (`.mcp.json`, `.cursor/mcp.json`; see [ai.md](ai.md)). `--no-agent-files` leaves them out
|
|
45
|
+
(`AGENTS.md`, `CLAUDE.md`, `.cursor/`, `.mcp.json`); otherwise `init` lists them after the files it created.
|
|
46
|
+
|
|
47
|
+
`<name>` must be snake_case; by default it is derived from `<dir>` (`my-app` → `my_app`). The template picks the
|
|
48
|
+
program and its test: `counter` (default, a PDA counter per user), `vault` (SOL at a PDA: deposit, withdraw above
|
|
49
|
+
rent, close) or `escrow` (SPL tokens: make, take, refund, the offer PDA signing for its vault). `init` refuses to
|
|
50
|
+
overwrite files. It warns, with the install commands, when the platform-tools that building needs are missing, and
|
|
51
|
+
says whether the Agave CLI is missing or only its platform-tools (on Linux arm64, where there is no Agave CLI, the
|
|
52
|
+
commands that set up the platform-tools' `linux-aarch64` package).
|
|
53
|
+
|
|
54
|
+
## typesol verify
|
|
55
|
+
|
|
56
|
+
`typesol verify <program|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>]
|
|
57
|
+
[--sbpf …] [--manifest <name.build.json>] [--docker …]` rebuilds the program and compares it with what is deployed.
|
|
58
|
+
|
|
59
|
+
- **Without a `.so`** it reads the program from the cluster (`--url`, cluster monikers such as `mainnet-beta` included,
|
|
60
|
+
else the Solana CLI config) at `--address` or the address `typesol.json` records, under any loader (v2, upgradeable
|
|
61
|
+
v3, v4). It prints the upgrade authority (or that the program is immutable) and the last deploy slot, and compares
|
|
62
|
+
the IDL published with `typesol idl publish` (a published IDL that differs is a mismatch).
|
|
63
|
+
- **With a `.so`** (e.g. from `solana program dump`) it compares with that file.
|
|
64
|
+
- Trailing zero padding is ignored; the SBPF version is read from the deployed ELF unless `--sbpf` is given.
|
|
65
|
+
- **On a mismatch** it prints the rebuild's toolchain (clang, platform-tools, host, TypeSOL) and the deployed build's
|
|
66
|
+
when a build manifest's binary hash is the deployed bytes' (`--manifest`, `<deployed>.build.json` next to a given
|
|
67
|
+
`.so`, or the local build's), and what differs; otherwise it says the deployed side's toolchain is unknown (a
|
|
68
|
+
program on chain records none). A host difference alone is named as such; it counts only between builds of 0.44.1
|
|
69
|
+
or earlier, whose programs with 128-bit or signed division linked platform-tools' compiler-builtins (laid out
|
|
70
|
+
differently by each host package).
|
|
71
|
+
- `--docker` rebuilds in the pinned container and, on a match, prints what was verified
|
|
72
|
+
([below](#build---docker-and-verify---docker)).
|
|
73
|
+
|
|
36
74
|
## build --docker and verify --docker
|
|
37
75
|
|
|
38
76
|
`--docker` builds in a container made on your machine from `docker/Dockerfile` (shipped in the package): linux/amd64
|
package/docs/errors.md
CHANGED
|
@@ -52,9 +52,11 @@ Framework errors use Anchor's numbers where Anchor has the same check, so client
|
|
|
52
52
|
| 5115 | an optional account that was left out was used |
|
|
53
53
|
| 6000+ | your error enums' members, in declaration order (imported files first), then one `RequireFailed<N>` error (code 6000 + N, after the highest code) per distinct `require(cond, "message")` string |
|
|
54
54
|
|
|
55
|
+
A token account or mint parameter fails with 3012 for an empty system account (never created, or closed), 3007 for an account of another program, 3003 for a token program's account that is not an initialized token account (or mint) of its length.
|
|
56
|
+
|
|
55
57
|
A member's string is its message (the IDL's `msg`); `X = ""` leaves the message out, as an Anchor variant without
|
|
56
58
|
`#[msg]`. `/** @code 6200 */` before a member gives it that code, and the members after it continue from there (Anchor's
|
|
57
|
-
`Variant = 200`); codes only go up. `require(cond, "message")` errors come after the highest code.
|
|
59
|
+
`Variant = 200`); codes only go up. The tag goes on its own line above the member. `require(cond, "message")` errors come after the highest code.
|
|
58
60
|
|
|
59
61
|
Any of Anchor's own codes can be raised directly: `require(cond, AnchorError.RequireKeysEqViolated)` fails with 2502,
|
|
60
62
|
as `require_keys_eq!` does.
|
|
@@ -67,11 +69,13 @@ reported as it is (use one of your errors' codes, so clients can decode it); a z
|
|
|
67
69
|
## Which error a transaction gets
|
|
68
70
|
|
|
69
71
|
A transaction can break several checks; it fails with the first. Within each account's constraints the checks run in
|
|
70
|
-
the order Anchor's generated code runs them, so a transaction gets the same code under both
|
|
72
|
+
the order Anchor's generated code runs them, so a transaction that breaks one check gets the same code under both, and
|
|
73
|
+
one that breaks several gets it too except in the cases listed after the steps:
|
|
71
74
|
|
|
72
|
-
1. The account count (3005), then each account in parameter order: its type, signer (3010), `Mut` (2000)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
1. The account count (3005), then each account in parameter order: its type, signer (3010), `Mut` (2000); for a
|
|
76
|
+
program account, initialized (3012 for an empty system account), owner (3007), size (3003, the discriminator's 8
|
|
77
|
+
bytes included), then discriminator (3002); a zero-copy one as Anchor's AccountLoader: 3007 / 3001 / 3002, then
|
|
78
|
+
3003; a token account or mint; a program address.
|
|
75
79
|
2. Two writable parameters naming one account (2040).
|
|
76
80
|
3. The instruction's arguments (102).
|
|
77
81
|
4. Each account in parameter order, its constraints in Anchor's order: seeds (2006), associated token account (owner
|
|
@@ -81,9 +85,19 @@ the order Anchor's generated code runs them, so a transaction gets the same code
|
|
|
81
85
|
Where TypeSOL's order differs, only a transaction that breaks two of these checks at once sees it:
|
|
82
86
|
|
|
83
87
|
- Anchor decodes the arguments first, and checks `mut` with the constraints (after seeds and the associated token
|
|
84
|
-
account). TypeSOL
|
|
88
|
+
account). TypeSOL decodes the arguments later, after every account's type (step 3), and checks `mut` earlier, with
|
|
89
|
+
the account's type (step 1), which keeps binaries smaller. An instruction with an [account
|
|
90
|
+
group](language-accounts.md#account-groups) decodes its arguments first, as Anchor does, then checks each account in
|
|
91
|
+
order, a group's constraints right after the group's accounts and the other constraints last.
|
|
85
92
|
- Too few accounts fails with 3005 before any account is checked; Anchor fails on the first account it cannot find.
|
|
86
|
-
-
|
|
87
|
-
|
|
93
|
+
- A program account's size is checked before its discriminator; Anchor's `Account::try_from` reads the discriminator
|
|
94
|
+
first (3001 when there are fewer than 8 bytes, 3002 when it differs) and then decodes the data (3003). So an account
|
|
95
|
+
of this program with another discriminator and fewer bytes than the struct fails with 3003 here and 3002 under
|
|
96
|
+
Anchor, and one with fewer than 8 bytes of data with 3003 here and 3001 under Anchor.
|
|
97
|
+
- Accounts created by the statements a body starts with (`acct.create(…)`, `createIfNeeded(…)`, `createPda(…)`,
|
|
98
|
+
after its `constraint(…)` lines) are created after steps 1 to 3 and before the constraints of step 4, as Anchor
|
|
99
|
+
creates `init` accounts before checking the other accounts' constraints ([creating
|
|
100
|
+
accounts](language-accounts.md#creating-accounts)). A create written after other statements runs where it is, after
|
|
101
|
+
every check, and so do all creates in an instruction with an account group.
|
|
88
102
|
- TypeSOL refuses any two writable parameters naming one account (2040) unless one is `Dup<…>`, where Anchor only compares program and token
|
|
89
103
|
accounts: a signer passed as two writable parameters fails with 2040 here and later, or not at all, under Anchor.
|
package/docs/glossary.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Glossary
|
|
2
|
+
|
|
3
|
+
The Solana and TypeSOL terms the [language guide](language.md) uses, one paragraph each, with the page that uses them
|
|
4
|
+
most. Solana's own documentation covers the chain in depth: [solana.com/docs/core](https://solana.com/docs/core).
|
|
5
|
+
|
|
6
|
+
## Account
|
|
7
|
+
|
|
8
|
+
A record on the chain at a 32-byte address: a balance in lamports, bytes of data, an owner program and an executable
|
|
9
|
+
flag. Programs keep all their state in accounts. See [accounts](language-accounts.md).
|
|
10
|
+
|
|
11
|
+
## Owner
|
|
12
|
+
|
|
13
|
+
The word has three meanings in the guide:
|
|
14
|
+
|
|
15
|
+
- **An account's owner** is the program it belongs to. Only the owner can change the account's data or take lamports
|
|
16
|
+
from it; any program can add lamports to an account the transaction made writable. A new account belongs to the
|
|
17
|
+
System Program until it is assigned to another. See
|
|
18
|
+
[accounts](language-accounts.md#account-parameters-and-the-checks-they-emit).
|
|
19
|
+
- **A token account's `owner` field** is the wallet or PDA allowed to move its tokens (its authority), while the
|
|
20
|
+
account itself belongs to the token program. See [tokens](language-cpi.md#tokens).
|
|
21
|
+
- **An `owner` field of your own structs** is whatever the program makes of it, usually the key allowed to act on the
|
|
22
|
+
account, checked with `HasOne<…, "owner">` or `require`. See [constraints](language-accounts.md#constraints).
|
|
23
|
+
|
|
24
|
+
## Lamports
|
|
25
|
+
|
|
26
|
+
The unit of SOL: 1 SOL is 1,000,000,000 lamports. `account.lamports` is an account's balance, a `u64`.
|
|
27
|
+
|
|
28
|
+
## Rent
|
|
29
|
+
|
|
30
|
+
An account must hold a minimum balance proportional to its size to stay on chain, the rent-exempt minimum:
|
|
31
|
+
(128 + data bytes) × 6,960 lamports at the time of writing. `create` funds it from the payer, `rentExempt(space)`
|
|
32
|
+
computes it, and closing the account returns it. See [creating accounts](language-accounts.md#creating-accounts).
|
|
33
|
+
|
|
34
|
+
## Discriminator
|
|
35
|
+
|
|
36
|
+
The first 8 bytes of an account of a TypeSOL or Anchor program (sha256("account:<Name>")[..8]), which say which struct
|
|
37
|
+
it holds, and of an instruction's data (sha256("global:<name>")[..8]), which say which instruction it calls. See
|
|
38
|
+
[account data](language-basics.md#account-data) and [instructions](language-basics.md#instructions).
|
|
39
|
+
|
|
40
|
+
## Keypair account
|
|
41
|
+
|
|
42
|
+
An account whose address is the public key of a keypair made for it, as opposed to a [PDA](#pda): the keypair signs
|
|
43
|
+
the transaction that creates it, and afterwards nobody needs it. `create(payer, null)` makes one. See [creating
|
|
44
|
+
accounts](language-accounts.md#creating-accounts).
|
|
45
|
+
|
|
46
|
+
## PDA
|
|
47
|
+
|
|
48
|
+
A program derived address: an address derived from seeds and a program id that has no private key, so only that
|
|
49
|
+
program can sign for it, in its calls to other programs. Programs keep accounts at PDAs so that their addresses can be
|
|
50
|
+
derived again. See [PDAs](language-pdas.md).
|
|
51
|
+
|
|
52
|
+
## Seeds
|
|
53
|
+
|
|
54
|
+
The byte strings a PDA is derived from (`["vault", owner.key]`): at most 15 of them, plus the bump, each at most 32
|
|
55
|
+
bytes. See [seeds](language-pdas.md#seeds).
|
|
56
|
+
|
|
57
|
+
## Bump
|
|
58
|
+
|
|
59
|
+
The one byte added to a PDA's seeds so that the derived address has no private key. The canonical bump is the
|
|
60
|
+
highest that works; it is found by trying 255, 254, … and is usually stored in the account. See [PDAs](language-pdas.md).
|
|
61
|
+
|
|
62
|
+
## Signer
|
|
63
|
+
|
|
64
|
+
An account whose private key signed the transaction (a wallet), or a PDA of the calling program in a call it signs
|
|
65
|
+
for. A `Signer` parameter checks it. See [accounts](language-accounts.md#account-parameters-and-the-checks-they-emit).
|
|
66
|
+
|
|
67
|
+
## Authority
|
|
68
|
+
|
|
69
|
+
An account allowed to do something to another: a mint's mint authority, a token account's owner, a program's
|
|
70
|
+
[upgrade authority](#programdata-and-upgrade-authority), a program's own admin key. It acts by signing, as a wallet or
|
|
71
|
+
as a PDA with signer seeds. See [tokens](language-cpi.md#tokens).
|
|
72
|
+
|
|
73
|
+
## Payer
|
|
74
|
+
|
|
75
|
+
The account that pays: the fee payer, the transaction's first signer, pays its fees; the payer an instruction names
|
|
76
|
+
(`create(payer, …)`) pays the rent of the accounts it creates, so it must sign and be writable (`Mut<Signer>`). See
|
|
77
|
+
[creating accounts](language-accounts.md#creating-accounts).
|
|
78
|
+
|
|
79
|
+
## Writable
|
|
80
|
+
|
|
81
|
+
Marked writable by the transaction, so its data or lamports may change. A `Mut<…>` parameter checks it.
|
|
82
|
+
|
|
83
|
+
## Instruction
|
|
84
|
+
|
|
85
|
+
A call to one program: the program id, the accounts it reads or writes and its data. A TypeSOL instruction is an
|
|
86
|
+
exported function. See [instructions](language-basics.md#instructions).
|
|
87
|
+
|
|
88
|
+
## Transaction
|
|
89
|
+
|
|
90
|
+
One or more instructions sent together with their signatures, at most 1,232 bytes at the time of writing. It is
|
|
91
|
+
atomic: when any instruction fails, the whole transaction fails, its changes are discarded and the fee is still paid.
|
|
92
|
+
|
|
93
|
+
## Remaining accounts
|
|
94
|
+
|
|
95
|
+
The accounts a client passes after those an instruction declares, read by position with `remainingAccounts()`
|
|
96
|
+
(Anchor's `ctx.remaining_accounts`), for lists whose length is known only at run time. See [remaining
|
|
97
|
+
accounts](language-accounts.md#remaining-accounts).
|
|
98
|
+
|
|
99
|
+
## Return data
|
|
100
|
+
|
|
101
|
+
Up to 1,024 bytes an instruction leaves for its caller: another program reads them after the call, and a client from
|
|
102
|
+
the transaction's simulation or metadata. A TypeSOL instruction that returns a value sends it this way. See [return
|
|
103
|
+
values](language-errors-events.md#return-values).
|
|
104
|
+
|
|
105
|
+
## Program id
|
|
106
|
+
|
|
107
|
+
A program's address. `programId()` gives it in the program; `typesol.json` records it for each program of a project.
|
|
108
|
+
|
|
109
|
+
## ProgramData and upgrade authority
|
|
110
|
+
|
|
111
|
+
An upgradeable program (the BPF upgradeable loader's, which `solana program deploy` uses) is two accounts: the program
|
|
112
|
+
account at the program id, which points to a ProgramData account derived from it, and that ProgramData account, which
|
|
113
|
+
holds the code, the slot of the last deploy and the upgrade authority. The upgrade authority is the key that may
|
|
114
|
+
replace the code; `solana program set-upgrade-authority … --final` removes it, and the program can then never change.
|
|
115
|
+
`typesol verify` prints it, and a `ProgramData` parameter reads it, to let only the deployer set a program up. See
|
|
116
|
+
[ProgramData](language-accounts.md#programdata) and [deploy to mainnet](mainnet.md).
|
|
117
|
+
|
|
118
|
+
## System Program
|
|
119
|
+
|
|
120
|
+
The built-in program that creates accounts, assigns them to an owner and moves lamports out of the accounts it owns
|
|
121
|
+
(wallets). See [the System Program](language-cpi.md#the-system-program).
|
|
122
|
+
|
|
123
|
+
## CPI
|
|
124
|
+
|
|
125
|
+
A cross-program invocation: one program calling another during an instruction, passing it accounts and, for PDAs,
|
|
126
|
+
signer seeds. See [calling other programs](language-cpi.md).
|
|
127
|
+
|
|
128
|
+
## Slot and epoch
|
|
129
|
+
|
|
130
|
+
A slot is the time a validator has to produce a block, about 400 ms; an epoch is a run of slots (432,000 on mainnet,
|
|
131
|
+
about two days) after which stake activates or deactivates and rewards are paid. `currentSlot()` and `currentEpoch()`
|
|
132
|
+
read them from the Clock. See [sysvars](language-chain.md#sysvars).
|
|
133
|
+
|
|
134
|
+
## Cluster
|
|
135
|
+
|
|
136
|
+
A network of validators running one Solana chain: mainnet-beta (real SOL), devnet (free SOL for testing), testnet, or a
|
|
137
|
+
local validator on your machine (`solana-test-validator`, often called localnet). Commands that send transactions take
|
|
138
|
+
the cluster's RPC URL (`--url`). See [deploy to mainnet](mainnet.md).
|
|
139
|
+
|
|
140
|
+
## Sysvar
|
|
141
|
+
|
|
142
|
+
An account at a fixed address that holds cluster state: the clock, rent, the epoch schedule and others. See
|
|
143
|
+
[sysvars](language-chain.md#sysvars).
|
|
144
|
+
|
|
145
|
+
## Syscall
|
|
146
|
+
|
|
147
|
+
A function the runtime provides to programs: logging, hashing, signature recovery, reading sysvars, deriving PDAs,
|
|
148
|
+
calling other programs. A program calls it as a function; its cost is in compute units. See
|
|
149
|
+
[sysvars](language-chain.md#sysvars).
|
|
150
|
+
|
|
151
|
+
## Precompile
|
|
152
|
+
|
|
153
|
+
A native program that verifies signatures (Ed25519, secp256k1, secp256r1) given in an instruction of its own. The
|
|
154
|
+
runtime runs it before the transaction's programs and rejects the transaction if a signature is wrong, so a program
|
|
155
|
+
only needs to find that instruction in the transaction, through the Instructions sysvar. See
|
|
156
|
+
[signatures](language-chain.md#signatures).
|
|
157
|
+
|
|
158
|
+
## Mint and token account
|
|
159
|
+
|
|
160
|
+
An SPL Token mint describes a token (its supply, decimals and mint authority); a token account holds an amount of one
|
|
161
|
+
mint for an owner, its authority. Both belong to the SPL Token or Token-2022 program. See
|
|
162
|
+
[tokens](language-cpi.md#tokens).
|
|
163
|
+
|
|
164
|
+
## Associated token account
|
|
165
|
+
|
|
166
|
+
The token account at the address the Associated Token Account program derives from a wallet, the token program and a
|
|
167
|
+
mint: the one token account per wallet and mint that wallets and clients use by default. `Ata<…>` checks or creates
|
|
168
|
+
one. See [token accounts and mints as
|
|
169
|
+
parameters](language-cpi.md#token-accounts-and-mints-as-parameters).
|
|
170
|
+
|
|
171
|
+
## Borsh
|
|
172
|
+
|
|
173
|
+
The binary encoding Anchor uses for instruction arguments, events and its account data: integers little-endian,
|
|
174
|
+
strings and vectors with a u32 length first. See [types](language-types.md).
|
|
175
|
+
|
|
176
|
+
## Zero-copy
|
|
177
|
+
|
|
178
|
+
An account read in place, its bytes used as the struct, instead of being decoded into a copy (Anchor's
|
|
179
|
+
`#[account(zero_copy)]` and `AccountLoader`, with bytemuck). TypeSOL reads every fixed-layout account in place;
|
|
180
|
+
`@serialization bytemuck` makes the IDL describe a struct as zero-copy, and such an account is checked as Anchor's
|
|
181
|
+
`AccountLoader` checks it. See [zero-copy types](language-accounts.md#zero-copy-types-as-anchors-idl-describes-them).
|
|
182
|
+
|
|
183
|
+
## Anchor
|
|
184
|
+
|
|
185
|
+
The most used Rust framework for Solana programs: its macros generate each instruction's account checks
|
|
186
|
+
(`#[derive(Accounts)]`), account discriminators, error codes and an IDL. TypeSOL follows its conventions (the same
|
|
187
|
+
discriminators, error numbers and IDL format), so Anchor clients and tools work with TypeSOL programs, and the guide
|
|
188
|
+
names the Anchor equivalent of each feature for readers who know it. Knowing Anchor is not needed. See [migrate from
|
|
189
|
+
Anchor](migrate-from-anchor.md).
|
|
190
|
+
|
|
191
|
+
## IDL
|
|
192
|
+
|
|
193
|
+
A JSON description of a program's instructions, accounts, types, events and errors, from which clients encode calls
|
|
194
|
+
and decode accounts. A TypeSOL build writes one in Anchor's format. See [what the compiler
|
|
195
|
+
derives](language-basics.md#what-the-compiler-derives).
|
|
196
|
+
|
|
197
|
+
## SBF
|
|
198
|
+
|
|
199
|
+
Solana's bytecode, which programs are compiled to. TypeSOL lowers a program to C and builds it with the platform-tools'
|
|
200
|
+
clang.
|
|
201
|
+
|
|
202
|
+
## Compute units
|
|
203
|
+
|
|
204
|
+
What an instruction's work is measured in. A transaction gets 200,000 per instruction by default and at most 1,400,000
|
|
205
|
+
at the time of writing; past its budget it fails. `typesol profile` shows where a program spends them. See [limits and
|
|
206
|
+
costs](language-basics.md#limits-and-costs).
|
|
207
|
+
|
|
208
|
+
## Next
|
|
209
|
+
|
|
210
|
+
[The language guide](language.md).
|