@typesol/cli 0.42.0 → 0.44.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +350 -0
  2. package/NOTICE +71 -0
  3. package/README.md +35 -18
  4. package/SECURITY.md +32 -5
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.js +5 -5
  7. package/dist/cli.js +196 -72
  8. package/dist/compiler/analyze.js +447 -12
  9. package/dist/compiler/diagnostics.d.ts +1 -0
  10. package/dist/compiler/diagnostics.js +13 -0
  11. package/dist/compiler/emit/alias.d.ts +45 -1
  12. package/dist/compiler/emit/alias.js +143 -6
  13. package/dist/compiler/emit/base.d.ts +28 -1
  14. package/dist/compiler/emit/base.js +77 -9
  15. package/dist/compiler/emit/borsh.js +11 -5
  16. package/dist/compiler/emit/calls.d.ts +80 -0
  17. package/dist/compiler/emit/calls.js +612 -54
  18. package/dist/compiler/emit/cpi-core.d.ts +23 -4
  19. package/dist/compiler/emit/cpi-core.js +261 -12
  20. package/dist/compiler/emit/cpi.js +8 -2
  21. package/dist/compiler/emit/create.js +3 -0
  22. package/dist/compiler/emit/expressions.js +44 -8
  23. package/dist/compiler/emit/function.js +10 -0
  24. package/dist/compiler/emit/program.js +30 -1
  25. package/dist/compiler/emit/rbtree.d.ts +7 -0
  26. package/dist/compiler/emit/rbtree.js +142 -0
  27. package/dist/compiler/emit/shared.d.ts +25 -0
  28. package/dist/compiler/emit/shared.js +45 -4
  29. package/dist/compiler/emit/statements.d.ts +27 -1
  30. package/dist/compiler/emit/statements.js +305 -23
  31. package/dist/compiler/emit/storage.d.ts +25 -2
  32. package/dist/compiler/emit/storage.js +116 -64
  33. package/dist/compiler/emit/token.js +2 -2
  34. package/dist/compiler/emit/views.d.ts +60 -0
  35. package/dist/compiler/emit/views.js +523 -0
  36. package/dist/compiler/idl.js +2 -1
  37. package/dist/compiler/index.d.ts +15 -1
  38. package/dist/compiler/index.js +40 -3
  39. package/dist/compiler/model.d.ts +65 -4
  40. package/dist/compiler/model.js +14 -0
  41. package/dist/compiler/toolchain.d.ts +56 -1
  42. package/dist/compiler/toolchain.js +246 -12
  43. package/dist/testing-stake.d.ts +2 -1
  44. package/dist/testing-stake.js +2 -1
  45. package/dist/testing.js +6 -4
  46. package/dist/tools/clientgen.d.ts +15 -0
  47. package/dist/tools/clientgen.js +173 -7
  48. package/dist/tools/cpigen.d.ts +0 -15
  49. package/dist/tools/cpigen.js +19 -8
  50. package/dist/tools/doctor.d.ts +17 -2
  51. package/dist/tools/doctor.js +64 -4
  52. package/dist/tools/portgen.js +43 -18
  53. package/dist/workspace.d.ts +20 -0
  54. package/dist/workspace.js +173 -6
  55. package/docs/ai.md +10 -5
  56. package/docs/architecture.md +10 -3
  57. package/docs/audit.md +63 -17
  58. package/docs/case-study-escrow.md +1 -1
  59. package/docs/case-study-phoenix.md +226 -0
  60. package/docs/case-study-raydium-amm.md +3 -3
  61. package/docs/case-study-spl-stake-pool.md +5 -5
  62. package/docs/cli.md +17 -8
  63. package/docs/client.md +11 -3
  64. package/docs/errors.md +1 -1
  65. package/docs/language.md +148 -12
  66. package/docs/mainnet.md +21 -10
  67. package/docs/migrate-from-anchor.md +3 -1
  68. package/docs/runtime.md +12 -2
  69. package/docs/security-model.md +38 -6
  70. package/docs/stability.md +42 -4
  71. package/docs/testing.md +25 -0
  72. package/docs/troubleshooting.md +17 -2
  73. package/lib/typesol.d.ts +221 -4
  74. package/llms-full.txt +336 -65
  75. package/llms.txt +2 -2
  76. package/package.json +4 -2
  77. package/runtime/typesol_rt.h +429 -13
  78. package/test/programs/LICENSE-Apache-2.0.txt +201 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,356 @@ codes, and says so here.
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 0.44.0 — 2026-11-11
10
+
11
+ Fixes from an internal review of 0.43.0, and the means to check a release. A helper's Pubkey, Option, string or u256
12
+ argument was not a copy when the helper was not inlined, so a check on a value the helper had just overwritten could
13
+ pass; a named seed list read its seeds when the CPI ran; the stale-reference rule was skipped for account-group fields
14
+ and loaded accounts; the Borsh decoder's length checks could wrap. **Programs built with 0.43.0 or earlier should be
15
+ rebuilt and redeployed** (docs/security-model.md says how to tell whether a program was exposed). New: the npm tarball
16
+ is packed from a clean export of the tag and recorded in `releases/`, the tested toolchain is declared and another one
17
+ warns, and fix-only releases come as patches from here on (SECURITY.md). Of the 76 programs of the 0.43.0 sources, 35
18
+ compile to the same binary as in 0.43.0 and 41 to a different one.
19
+
20
+ - Fixed: a Pubkey, Option, string or u256 argument of a helper was not a copy. The SBF backend passes such a value as a
21
+ pointer to the caller's object, so a helper that was not inlined and wrote that object (`rotate(v, v.admin, caller)`
22
+ with `v.admin = v.pending` inside) then read its own write through the parameter: a check on the old value passed on
23
+ the new one. Whether it happened depended on inlining. The value now arrives by pointer, to a copy taken at the call
24
+ whenever the helper can write (it takes accounts, remaining accounts or `Inout` places) and the value is not out of
25
+ its reach (a local, an instruction argument, an account's key, the program id)
26
+ (test/language/helper-copies.test.ts, inlined and `@noinline`).
27
+ - Fixed: a seed list bound to a name (`const s = signer(["vault", st.count, bump])`), given to a helper, or written
28
+ beside an argument with side effects read its seeds when the CPI ran, so after `st.count += 1n` the program signed
29
+ for another PDA than the one the source names. The seeds are copied where the list is written
30
+ (test/language/pda-signers.test.ts).
31
+ - Fixed: the rule that a reference into an account is not used after a helper that may move its data was skipped when
32
+ the account reached the helper as an account-group field (`grow(g.pool, g.payer)`) or as one loaded with
33
+ `loadAccountMut`; such a program compiled and wrote through the stale reference. Both are refused like a plain
34
+ parameter (test/security/aliasing.test.ts).
35
+ - Fixed: the Borsh decoder's length checks subtracted before comparing, so for an `Option` of a struct that itself
36
+ holds an Option (or a Vec of such structs) a short buffer wrapped the subtraction and the read went past the end
37
+ (up to the struct's size, read only). The checks no longer subtract, and a nested struct's smallest size is checked
38
+ after its tag and for each element; `ts_alloc`, string appends and the stake history reader are written the same
39
+ way (test/language/borsh-nested.test.ts).
40
+ - Fixed: a local read before a closure or list callback that changes it kept the new value (`x += bump()`,
41
+ `two(x, bump())`); it keeps the value it had when read, as the left-to-right order promises
42
+ (test/language/closures.test.ts). A string that views text inside an `Inout` place is copied for the helper that
43
+ takes the place (test/language/inout.test.ts).
44
+ - Fixed: `close()`. Closing an account into itself is a compile error (`CloseTo<…, "self">`, `close(a, a)`), and 2040
45
+ at run time in a helper whose two accounts may be one; `Dup<…>` is refused on an account the body closes; using an
46
+ account after `close()` in the same instruction (its writes were dropped) is a compile error, its `.key` aside
47
+ (test/security/dup.test.ts, test/language/diagnostics.test.ts).
48
+ - Language: `min` / `max`, `switch` and list indexes take a `u256`; a `u256` shift amount or exponent is a compile
49
+ error (it was a C build failure); `x <<= n` and `x >>= n` take an amount of its own integer type, as `<<` does;
50
+ `Ata<Init<TokenAccount>, "@acct.field", …>.create` is a compile error naming the form instead of C that does not
51
+ build (test/language/pow.test.ts, test/language/diagnostics.test.ts).
52
+ - Of the 76 programs of the 0.43.0 sources, 35 compile to the same binary as in 0.43.0 and 41 to a different one:
53
+ those with a helper that takes a Pubkey, Option, string or u256 (the parameter is a pointer now). counter, vault and
54
+ escrow are among the 35. Measured against 0.43.0, the changed example programs move by at most 22 compute units
55
+ either way, and no compared transaction of a port costs more than the original's.
56
+ - Docs: docs/security-model.md says what creation over an existing account returns (the System Program's custom 0;
57
+ 3000 is `initAccount<T>`), and docs/runtime.md names the cases that abort (`PANIC_ON_OVERFLOW`, `PANIC_STYLE`, a
58
+ RedBlackTree whose bytes are inconsistent).
59
+ - CLI: generated `.mcp.json` / `.cursor/mcp.json`, the agent rules, hints and docs run the project's own copy with
60
+ `npx --no-install typesol …` (or `npx @typesol/cli …` outside a project): plain `npx typesol` outside an installed
61
+ project asks the registry for a package of that name, which does not exist. docs/migrate-from-anchor.md installs
62
+ before running `port`.
63
+ - typesol/testing: `testProgram` reuses an up-to-date build (same sources, runtime, TypeSOL, TypeScript and clang
64
+ versions), and builds of one program from parallel test workers wait for each other
65
+ (`<out>/<name>/.typesol-build.lock`, taken over when its process is gone or after 15 minutes) instead of writing
66
+ over each other's files.
67
+ - CLI: `typesol cpi` and `typesol port` check the IDL as `typesol client` does (identifiers, base58 addresses, byte
68
+ lists) and keep IDL text inside escaped comments. A pre-0.30 Anchor IDL gets "run `anchor idl convert`" in all
69
+ three, and a null or non-object IDL or a missing `instructions` list is refused with a message.
70
+ - Client: a type that holds itself through a Vec or an Option (`enum Shape { Rec { kids: Vec<Shape> } }`) gets a lazy
71
+ codec; building it overflowed the stack. `u256` / `i256` are supported (bigint, 32 bytes LE), and
72
+ `Option<Option<T>>` is `Option<T> | null` so Some(None) round-trips; one level more is left out with a note.
73
+ - CLI: `clone`, `client --address`, `verify` and `idl publish` time out RPC requests (30 s, `TYPESOL_RPC_TIMEOUT`) and
74
+ report the host and cause as `doctor` / `deploy` do. `deploy` refuses to run without `--url` or a configured
75
+ `json_rpc_url`, and `deploy` / `idl publish` print the cluster and payer before sending. A `--config` that does not
76
+ exist is a usage error in `deploy --dry-run` and `doctor` too.
77
+ - CLI: `check --json` prints JSON for every outcome (a missing file, bad `--files` input). Printed `cd` and deploy
78
+ hints quote paths. `build file.ts --program-id <missing>` explains instead of failing with ENOENT.
79
+ - Docs: docs/cli.md lists `typesol mcp` and every file `init` writes. docs/mainnet.md's counter size and rent are
80
+ measured (11,400 bytes, about 0.080 SOL at 0.43.0). Case studies link to showcase sources on GitHub. docs/client.md
81
+ describes which PDA seeds are filled in. docs/audit.md's figures come from `scripts/audit-stats.ts` (checked by the
82
+ tests), its unreviewed range runs to 0.43.0, and macOS CI is on demand.
83
+ - Tests: the Phoenix and Stake Pool diff helpers compare account bytes without copying them twice or building hex
84
+ strings unless they differ (phoenix-upstream peak RSS 1.53 GB → 0.77 GB), and the per-order market copies left in
85
+ phoenix-cancel and phoenix-upstream are hoisted.
86
+ - Licences: NOTICE records the third-party code the package ships (lib-sokoban's red-black tree in the runtime
87
+ header, MIT; SPL's big_vec layout and the Stake interface's activation function, Apache-2.0) and the Phoenix and
88
+ SPL Stake Pool ports, and ships in the package with the Apache-2.0 text. Every showcase/mainnet file names its
89
+ source and licence.
90
+ - CI: a program binary whose sha256 differs from test/programs/SOURCES.md fails the fetch step (Token Metadata is
91
+ fetched from mainnet, the build the record names; Bubblegum's record is the build devnet runs now). All fetch-only
92
+ binaries are cached, keyed on SOURCES.md. `CI_REQUIRE_ALL` turns a suite skipped for a missing binary into a
93
+ failure (test/binaries.ts).
94
+ - Docs: docs/testing.md lists the SPL Stake Pool and Phoenix random walks and the red-black tree's trace replay
95
+ against lib-sokoban among the checks against an independent oracle.
96
+ - Releases: `scripts/release-check.ts <version>` packs the npm tarball from a clean `git archive` of the tag (frozen
97
+ install, build, lint, the version and CHANGELOG section checked; `--tests` adds the suite) and writes
98
+ `releases/<version>.json`: the commit, the tarball's shasum and integrity as the registry reports them, and each
99
+ file's sha256. The maintainer publishes that tarball (`npm publish <file>.tgz`) instead of a folder with
100
+ `--ignore-scripts`, and `--verify --registry` compares the registry with the record afterwards. `npm pack` is
101
+ reproducible: two clean packs of v0.43.0 and the published 0.43.0 are the same bytes (shasum 10c2883b…), recorded
102
+ in releases/0.43.0.json (CONTRIBUTING.md, docs/testing.md).
103
+ - Toolchain: the toolchain the release is tested with is declared in one place (`TESTED_TOOLCHAIN`, exported from
104
+ `typesol/compiler`: Agave 3.1.10, platform-tools v1.52, its clang 20.1.7 version line). A build with another clang
105
+ (`build`, `deploy`, `verify`, `typesol/testing`, a reused up-to-date build too) prints one warning per process naming
106
+ both and saying its binaries are not covered by the tests; `--toolchain-strict` on `build` and `deploy`, or
107
+ `TYPESOL_TOOLCHAIN=strict` anywhere, makes it an error. `typesol doctor` has a `toolchain` row (tested, or untested
108
+ with both versions; an error under strict), and its install hint is Agave 3.1.10 instead of "stable". CI runs
109
+ `doctor` under strict, so the tests run on the declared toolchain (test/cli/toolchain.test.ts).
110
+ - Build manifests: `<name>.build.json` records `platformTools` (from the SDK's `platform-tools-<version>.md` marker
111
+ and its link into the cache, when they agree) and `host` (`os`, `arch`) beside `clang`. A manifest without `host`
112
+ (from 0.43.0 or earlier) makes the up-to-date check rebuild once instead of reusing the build; a different
113
+ platform-tools or host rebuilds too. `scripts/release-manifest.ts` takes the platform-tools version from the same
114
+ place (its path pattern found none).
115
+ - CLI: `typesol verify` on a mismatch prints the rebuild's toolchain (clang, platform-tools, host, TypeSOL) and the
116
+ deployed build's when a build manifest's binary hash is the deployed bytes' (`--manifest <file>`, `<name>.build.json`
117
+ next to a given `.so`, or the local build's), and which of them differ. A program on chain records no toolchain, so
118
+ without such a manifest it says the deployed side is unknown and names the local manifest as describing another
119
+ binary.
120
+ - Docs: the README's quick start installs the tested Agave and platform-tools exactly; docs/mainnet.md has "the
121
+ toolchain you deploy with" (keep the build manifest with the deployment; `verify` needs the same toolchain);
122
+ docs/troubleshooting.md explains the warning and verify mismatches; docs/cli.md lists the new flags and rows.
123
+ - Docs: docs/audit.md and docs/security-model.md record the internal review of 0.43.0 (2026-11-11): the defects above,
124
+ what it covered (compiler semantics probes, the runtime and generated C, the tooling) and what it did not (the
125
+ Metaplex and token CPI wrappers' emitters, oracles, SBPF v1/v2 builds, Windows); programs built with 0.43.0 or
126
+ earlier should be rebuilt, and docs/security-model.md says how to tell whether a program was exposed to the helper
127
+ argument defect. SECURITY.md and CONTRIBUTING.md add the fix-release rule (from 0.44.0 on, a release that only
128
+ fixes soundness or security defects is a patch of the latest minor, with no new language surface and the binary
129
+ diff in its notes; older minors are not maintained). docs/stability.md lists what a release gives today: the
130
+ checked tarball, the tested toolchain, the build record, fix releases.
131
+
132
+ ## 0.43.0 — 2026-11-11
133
+
134
+ Phoenix v1 ported in full, Ellipsis Labs' on-chain limit order book and a native program, from the commit a
135
+ reproducible build proves is the mainnet binary, and checked against that binary on 3,575 transactions and a seeded
136
+ random walk over two order books. The compiler gained what it needed: views at run-time offsets (`loadRawAt`,
137
+ `rawArrayAt`), a built-in red-black tree in lib-sokoban 0.3's byte layout (`rbTreeAt`), `Inout<T>` helper parameters,
138
+ byte builders on `FixedVec<u8, N>`, return data and compute-unit logs in native entries, `closeRaw`, Rust 1.14's panic
139
+ lines (`panicsAt`), constant expressions, type aliases and file-local structs. Of the 74 programs of the 0.42.0 sources,
140
+ 68 compile to the same binary as in 0.42.0; Marginfi, multisig, Raydium AMM v4, Raydium CLMM, SPL Stake Pool and
141
+ favorites compile to a different one (the "Faster" entries below).
142
+
143
+ - Examples: showcase/mainnet/phoenix, a port of Phoenix v1 (Ellipsis Labs' on-chain limit order book at PhoeNiXZ8…, a
144
+ native program, all 28 instructions), from the commit a reproducible build proves is the mainnet binary (c16694d,
145
+ relicensed under MIT with its sources unchanged), checked against that binary on 3,575 transactions in five files
146
+ (the original's 50 test functions mapped: 11 covered, 37 added as differential cases, 2 not applicable) and a random
147
+ walk over two order books with a balance oracle, with the same outcomes, log lines, event batches, return data and
148
+ account bytes; 13–61% of the original's compute units (up to 86% at the heap limits, with hundreds of account
149
+ entries or a forwarding program's CPI; a PostOnly order 6,452 against 20,577, a swap of 30 fills 26,344 against
150
+ 61,313, cancelling 512 orders 434,446 against 760,087), 256,360 bytes against 1,344,472. Phoenix's 32 KiB bump heap
151
+ is counted (showcase/mainnet/phoenix/heap.ts): each allocation is charged where the Rust makes it, so a transaction
152
+ that fills the heap (many account entries, a CPI's larger instruction data) aborts at the same allocation, after the
153
+ same log lines and batches; phoenix-limits.test.ts (162 transactions) compares both sides of each boundary, through
154
+ a forwarding caller program where a CPI is needed. What Phoenix formats only when it fails is not charged, the one
155
+ documented difference. A multiple-order packet passed through a CPI is decoded whatever its length, divisions by a
156
+ zero tick size or base lot size panic at Rust's locations, and the clock's timestamp wraps as `as u64`. Its events
157
+ are appended by `pushBorsh` of their literals: in the port, whose batch is an `Inout` parameter, a Reduce event costs
158
+ 47 CU less than the six `pushLE` calls it replaced (one room check instead of six; the 19 against 16 below is a local
159
+ buffer). docs/case-study-phoenix.md.
160
+ - Tests: the Phoenix files keep every compared transaction's compute units and fail unless the port uses fewer on
161
+ every one that succeeds (2,390 of the 3,575) and each compares exactly its expected count; the upstream cases pin
162
+ every refusal to the original's error and message and make the original tests' own assertions on chain. The random
163
+ walk draws its choices and keys from fixed seeds (1, 2 and 3, 300 steps on each market: 1,801 transactions), so a
164
+ seed reproduces it, and requires minimum counts of fills, evictions, expiries and fees decoded from the events. The
165
+ lib-sokoban traces are 21,650 operations (seeds 1–3, five key shapes, capacities 1 to 4096, fill and drain cycles).
166
+ - Language: a top-level integer constant may be an expression over literals and constants declared before it (in its
167
+ file or an imported one): `const EVENT_ROOM = 1280n - 34n`, `const ASKS_AT: u64 = BIDS_AT + 2n * BOOK`, with
168
+ `+ - * / % ** & | ^ << >>`, unary `-` and `~`. It is folded when the program is compiled and inlined like a literal.
169
+ A typed constant is computed in its type, as Rust computes `const X: u64 = …`: every step must fit (`1n - 2n + 5n`
170
+ as a u64 is an error naming the step); division by zero, a negative exponent and a shift past the width are compile
171
+ errors too. Only literals were accepted (test/language/port-syntax.test.ts).
172
+ - Language: a struct that is not exported (`interface Pair { … }`) is its file's own: helpers take, return and change
173
+ it (`Inout<Pair>`), locals hold it, and the IDL leaves it out. It failed with "structs must be exported" and a
174
+ misleading second error about the helper's return type. Used where the IDL describes it (account data, an
175
+ instruction's arguments or result, an event, an exported struct's field, a data enum's variant), it is one error
176
+ naming the use and the fix, `export interface Pair` (test/language/port-syntax.test.ts). A non-exported account group
177
+ is refused as before, with its own message.
178
+ - Language: a read-only native view can be read where it is made: `loadRaw<Header>(market).inner.b`,
179
+ `loadRawAt<Prefix>(market, 576n).tick` and `rbTreeAt<K, V>(…).length` / `.capacity` ("unsupported property access"
180
+ and "bind … to a const first" before). A writable view (`loadRawMut`, `loadRawMutAt`) is still bound first, now
181
+ with the reason: it claims its account once per instruction (test/language/port-syntax.test.ts).
182
+ - Language: a local list may hold 2 KiB of elements, its FixedVec length word aside: `const ids: FixedVec<u32, 512> =
183
+ fixedVec([])` (2,052 bytes, Phoenix's collected order ids) was refused. A frame that then overflows is still reported
184
+ by the frame check, which names the biggest locals; the refusal of a bigger list now gives the element bytes and, on
185
+ a declaration, the `/** @heap */` remedy (test/language/port-syntax.test.ts).
186
+ - Language: comma-separated updates in a `for` loop, `for (let i = 0n, j = n; i < j; i++, j--)`, run in order after
187
+ each pass (`continue` included), and so do comma-separated assignments in its initializer; they were refused ("this
188
+ expression has no effect"). A comma anywhere else still is (test/language/port-syntax.test.ts).
189
+ - Faster: `buf.pushBorsh<DataEnum>({ kind: "Reduce", … })`, a data-enum literal of a fixed-size variant, builds only
190
+ that variant: its fields evaluated in source order into locals, then one room check, the tag and a store of each
191
+ field at its offset (a variant holding a struct or FixedArray: one temporary of exactly its bytes and one copy). It
192
+ zeroed, filled and copied the whole enum (92 bytes for Phoenix's PhoenixMarketEvent), then wrote the tag and the
193
+ variant behind a switch on it: Phoenix's 35-byte Reduce event 54 → 19 CU against 16 for the same bytes by `pushLE`
194
+ (test/language/phx-costs.test.ts, which also checks every field kind's bytes). Changes the generated C of programs
195
+ that push data-enum literals (Phoenix, test/fixtures/byte-builders.ts), whose tests pass unchanged.
196
+ - Faster: a read-only struct, FixedArray or data-enum argument of a helper that also takes accounts is copied at the
197
+ call only when it may be account data (a field of a view or of a loaded account), which the helper's writes could
198
+ change. A struct parameter of a helper that itself takes accounts, an instruction's struct argument and return data
199
+ are now passed in place like the caller's other owned structs (locals, helper results): they arrived as copies and
200
+ no account write reaches them. Phoenix's book helpers now take their MarketShape as a plain struct, where they took
201
+ it as `Inout<T>` only to avoid the copy (test/language/phx-costs.test.ts: 97.6 → 43.3 CU per call of a helper
202
+ passing it on, test/language/helper-copies.test.ts). Changes the generated C of SPL Stake Pool, Marginfi and Raydium
203
+ CLMM (a copy fewer at such calls), whose tests pass unchanged.
204
+ - Faster: the owner check of native account views (`loadRaw` / `loadRawMut`, `loadRawAt`, `rawArrayAt`, `rbTreeAt` and
205
+ their Mut forms) remembers the last account it found this program's, until a CPI or an owner write (`assignOwner`,
206
+ `closeRaw`, `close`) forgets it: the same account passes again with a pointer compare instead of a 32-byte one.
207
+ Phoenix's helpers each view the market again, often in loops that write it, where clang could not drop the
208
+ repeated compare (test/language/phx-costs.test.ts: a view per pass of a writing loop 21 → 15 CU, two views 35 → 21,
209
+ a helper call taking the market 54 → 43). A view after the account changed hands still fails with 3007
210
+ (test/language/owner-cache.test.ts: after assignOwner, closeRaw and a self-CPI that assigns it). Only programs that
211
+ make such views carry the cache (`TS_OWNER_CACHE`, a pointer in TsParams); their generated C changes (SPL Stake
212
+ Pool, Raydium AMM v4, Phoenix and the test fixtures that use views), and their tests pass unchanged.
213
+ - Faster: a RedBlackTree walk (`for (const e of tree)`, `tree.reversed()`) checks each node's index against the
214
+ capacity once, when it steps onto the node, instead of three times, and keeps its stack by pointer: 59 → 40 CU per
215
+ node for a walk summing a field of a 400-order book (test/language/phx-costs.test.ts; 18 CU less per node read-only).
216
+ The same panics at the same points on a damaged tree (an index past the capacity, a cycle filling the stack; both
217
+ now tested). Changes the generated C of programs that walk a tree (Phoenix, test/fixtures/rbtree.ts and
218
+ rbtree-api.ts).
219
+ - New: `tree.removeAt(index)` on a RedBlackTree removes the node at that index (from `addrOf`, or a node's `.index`
220
+ from `min` / `max` / a walk) with exactly the writes `remove(node.key)` makes, without searching the tree a second
221
+ time: Phoenix's cancel finds the order, checks whose it is, then removes it (691 → 547 CU in
222
+ test/language/phx-costs.test.ts). It gives the removed value, or null for index 0 or a node in no tree (a freed one,
223
+ which is left as it is); past the capacity it panics as `nodeAt` does. The lib-sokoban trace replay runs a second
224
+ time with every `remove(key)` as `removeAt(addrOf(key))`, and the bytes after each operation are still the crate's
225
+ (test/verification/rbtree-trace.test.ts).
226
+ - New: room beyond one 4 KiB stack frame. `/** @noinline */` on a helper keeps it a C function of its own, so its
227
+ locals get their own frame instead of the instruction's it would be inlined into (3 to 5 CU per call);
228
+ `/** @heap */` on an instruction's list or struct local keeps it on the heap (one allocation per declaration,
229
+ reused by a loop; 17 to 19 CU). A native port's entry holding a 1,284-byte log buffer could not also build a second
230
+ one, or the order ids after its recorder's last CPI (test/fixtures/frames.ts: 4,672 bytes inlined). The frame-size
231
+ error now lists the biggest locals from clang's frame layout (names and the source line near each; unnamed slots
232
+ with the locals of the helpers inlined there) and names both remedies (test/language/stack-limit.test.ts).
233
+ - Language: plain type aliases, `type Price = u64` (or `Pubkey`, a struct, `FixedVec<u8, 32>`, `Point | null`, another
234
+ alias), replaced by the type they name wherever they are used, so layouts and the IDL are the type's own; exported
235
+ or not, imported from other files (the aliased type keeps its own file's import names). Every `type X = …` was taken
236
+ for a data enum, and a union of named types (`type Event = Fill | Place`) failed with "each variant is an object
237
+ type"; it now says to list the variants as object types or alias one type. Generic aliases and `null` among a data
238
+ enum's variants are refused with what to write instead (test/language/aliases.test.ts).
239
+ - New: `const [address, bump] = findProgramAddressWithBump(seeds, program)`, Rust's `let (address, bump) =
240
+ Pubkey::find_program_address(…)`: the canonical address and its bump from one search, where `findProgramAddress`
241
+ and `findProgramAddressBump` searched twice (453 to 2,118 CU saved in test/language/pda-derivation.test.ts,
242
+ depending on how many bumps the search tries). `[, bump]` keeps only the bump; any other use is a compile error
243
+ showing the form.
244
+ - Language: a read-only `FixedVec<T, N>` (or `Vec<T>`) helper parameter takes the caller's own lists, as the language
245
+ reference said helpers do: a local FixedVec, a FixedVec field of a local struct or of account data, passed as a view
246
+ of its elements by pointer (nothing copied; a list in account data is copied first when the helper also takes
247
+ accounts, as a struct argument is). It was refused ("expected a Vec<u8> instruction argument"), so ports wrote the
248
+ helper with `Inout<T>`. A list with room for more than N elements is refused with the parameter to declare, and a
249
+ list given for an `Inout` parameter of the same call too (test/language/list-params.test.ts).
250
+ - Faster: a local `FixedVec` is set up in about constant compute units. `fixedVec([])` of 1280 bytes zeroed the list
251
+ twice (1,436 CU in test/language/fixedvec-setup.test.ts, now 152 with the rest of the instruction); `fixedVec([15n])`
252
+ also built and copied a temporary (3,216 → 155); a FixedVec field in a struct literal zeroed and copied a temporary,
253
+ doubling the stack (2,571 → 153). The free slots are now zeroed once, by the memset syscall from 128 bytes
254
+ (`ts_memzero_bulk`), and the elements are written in place; `list = fixedVec([…])` still builds in a temporary (its
255
+ elements may read the old list) but zeroes and copies it with the syscalls. The free slots stay zero, since a list's
256
+ whole layout is copied into account data and events. Changes the generated C of programs with local FixedVecs
257
+ (Phoenix, SPL Stake Pool, Marginfi, coral multisig, favorites and seven test fixtures), whose tests pass unchanged.
258
+ - New: `const ERROR_LOG_PREFIX = null` / `const PROGRAM_ERROR_LOG_PREFIX = null`: failures return their error and log
259
+ nothing, as a native program's do when its own checks already logged (Phoenix). `ERROR_LOG_PREFIX = null` covers
260
+ `require(…, MyError.X)` and codes computed at run time, `PROGRAM_ERROR_LOG_PREFIX = null` built-in ProgramErrors
261
+ (`require(…, ProgramError.X)`, `loadBorsh`, views) and `programAt` / `sysvarAt`. With `""` a failure still logged
262
+ "Program log: " plus the message; now it costs 105 to 124 CU less (test/language/quiet-errors.test.ts). Only these
263
+ two constants may be `null`. Programs that do not use it compile to the same C.
264
+ - Language: `Inout<T>` helper parameters, Rust's `&mut T`. `function addEvent(rec: Inout<Recorder>, e: Event): void`
265
+ gets the caller's place itself (a pointer, never a copy) and may change it; the caller sees the writes after the
266
+ call, as JS shares an object passed to a function. `T` is a fixed-size struct, `FixedArray<T, N>` or
267
+ `FixedVec<T, N>` (`push` / `pop` / `clear` included); the argument is a writable place: a local struct or list, a
268
+ `loadBorsh` local, a field of a `Mut<T>` account or of a `loadRawMut` view, a list element, another `Inout`
269
+ parameter. Until now helpers could only change accounts (`Mut<T>`), so ports inlined their mutating helpers (an
270
+ order book's matching engine and event recorder cannot sensibly be inlined). At each call no other argument may
271
+ share storage with an Inout one (two elements of one list count as one place), an element of a Vec or BigVec is
272
+ refused when the call may move it, and a reference into the place read after the call is refused; places that may
273
+ be one account only at run time (two `Dup` accounts, two `loadRawMut` views under `NATIVE_ACCOUNT_WRITES`) are
274
+ compared before the call (2040). Integers, Pubkeys, strings and Options are refused with a hint (JS copies values
275
+ too: return the new one, or keep it in a struct). About the compute units of the same code written inline
276
+ (test/language/inout.test.ts). Writing to a read-only helper parameter now says to declare it `Inout<T>`.
277
+ docs/language.md (`Inout<T>` parameters), docs/stability.md (Experimental; the open edge of helpers taking a
278
+ writable struct that is not an account is settled). Programs that do not use it compile to the same C.
279
+ - New: `loadRawAt<T>(acct, offset)` / `loadRawMutAt<T>(…)`, a native account's struct at a byte offset known at run
280
+ time, and `rawArrayAt<T>(acct, offset, capacity)` / `rawArrayMutAt<T>(…)`, a run-time number of elements in place
281
+ (`get`, `set`, `.length`, `for … of`, the list methods). Bounds checked once when made (ProgramError::AccountDataTooSmall,
282
+ overflow included); owner, writability and claim as `loadRaw` / `loadRawMut`.
283
+ - New: `rbTreeAt<K, V>(acct, offset, capacity, compare?)` / `rbTreeMutAt`, lib-sokoban 0.3's `RedBlackTree<K, V, N>`
284
+ over account bytes, byte for byte (Phoenix's order books and seats): `get`, `insert`, `remove`, `min`, `max`,
285
+ `addrOf`, `nodeAt`, `initialize`, `length`, `capacity`, `for … of` and `reversed()`. A comparator function orders
286
+ the keys (called as `compare(searched, node)`), or Rust's derived order. Replayed against the crate itself with
287
+ identical bytes after every operation: the committed test's 21,650 recorded operations (seeds 1–3, capacities 1 to
288
+ 4096, strides 32, 64 and 144; test/verification/rbtree/regenerate.sh), and, with the previous trace generator, a
289
+ one-off run of 1,020,000 (capacities 1 to 512). sokoban's panics are logged as solana-program up to 1.17 logs a
290
+ panic, with sokoban's messages and locations. Faster than the crate built with cargo-build-sbf at 4,096 entries
291
+ (get 215 CU against 384, insert 595 / 742, remove 355 / 618).
292
+ - Native entries set their own return data and log compute units: `setReturnData(bytes)` (Rust's `set_return_data`,
293
+ from a list of u8: a local `FixedVec<u8, N>`, account data, the instruction data or a slice) in a `@fallback` entry,
294
+ its helpers and void instructions, and `logComputeUnits()` (`sol_log_compute_units`, the runtime's "Program
295
+ consumption: N units remaining"), which were only emitted under `--profile`. An instruction that returns a value
296
+ refuses `setReturnData` (its return value is its return data). Checked against the lines the Phoenix v1 binary
297
+ writes.
298
+ - Native account lifecycle on remaining accounts and `AccountInfo` parameters: `closeRaw(account, receiver)` (Phoenix's
299
+ Tombstone: lamports to the receiver, owner to the System Program, length to 0, in that order and without zeroing the
300
+ data, ending as Phoenix's own Tombstone ends), `assignOwner(account, owner)` (`AccountInfo::assign`), and
301
+ `resizeAccount` on remaining accounts (the 10 KiB growth limit against the size the entrypoint records when the
302
+ instruction starts, as solana_program 1.14 records it). Checked writable, passed once and owned by this program, or
303
+ left to the runtime under `NATIVE_ACCOUNT_WRITES`.
304
+ - Byte builders on `FixedVec<u8, N>` (a local list or one in account data), for byte strings a native program builds by
305
+ hand: `pushLE(x)` (an integer at its width), `pushKey(key)`, `pushBorsh(value)` (Borsh, with the codecs `invoke`,
306
+ events and `storeBorsh` use; object literals take their type, `pushBorsh<Header>({ … })`), `setLE(offset, x)` and
307
+ `truncate(n)`, each bounds-checked (5104) with the length moved only when everything fit. Phoenix's event recorder
308
+ written with them sends the same batches, byte for byte, as the Phoenix binary.
309
+ - Rust panics as solana-program 1.14 to 1.17 leave them: `export const PANIC_STYLE = "solana-1.14"` makes `panic(message,
310
+ location)` log `panicked at '<message>', <location>` and abort ("SBF program panicked"), and `PANIC_ON_OVERFLOW`'s
311
+ panics abort too; `panicsAt(location, expression)` makes the expression's checked arithmetic panic with Rust's
312
+ messages ("attempt to add with overflow", "attempt to divide by zero", …) at the original's location instead of
313
+ failing with 5100 / 5101, in either style. Checked line for line against the Phoenix v1 binary's panics (its
314
+ entrypoint's assertion, and its overflow and remainder checks in initialize.rs and quantities.rs).
315
+ - Fixed: a tree comparator returning an unsigned integer (`function cmp(a: u64, b: u64): u8`) was accepted and could
316
+ never report "less", so every search went one way and the tree was silently out of order. It is a compile error
317
+ naming the type; a comparator returns a signed integer (test/language/rbtree.test.ts).
318
+ - Fixed: two writable views of one account's bytes through `loadRawMutAt`, `rawArrayMutAt` or `rbTreeMutAt` passed as
319
+ two `Inout` arguments under `NATIVE_ACCOUNT_WRITES` were not compared at run time (only `loadRawMut` views were), so
320
+ overlapping places reached the helper. They are compared before the call as `loadRawMut` views are: 2040 when they
321
+ overlap (test/language/inout.test.ts, test/fixtures/inout-views.ts).
322
+ - Fixed: an `Inout` argument was compared at run time only with other `Inout` arguments, so a read-only argument that
323
+ is the same bytes (`h(a.s, b.s)` with two `Dup` accounts that are one, a place of a writable account beside a
324
+ read-only account that is the same, two native views) changed under the helper as it wrote. Every argument passed
325
+ in place is now compared with the `Inout` one when their roots may be one account (2040 when they overlap); calls
326
+ whose arguments cannot alias, and arguments copied for the call, are not compared, so no existing program changed
327
+ (test/language/inout.test.ts, test/fixtures/inout-share.ts).
328
+ - Fixed: a tree node bound any other way than directly (`const e = c ? t.min() : t.max()`, `const v = t.get(k)!`)
329
+ escaped the rule that a reference into a tree is not used after an `insert`; it compiled and could read a reused
330
+ node. It refers to the tree like the direct form (`"e" still refers to t`), and binding one with `let` is refused
331
+ (test/language/rbtree.test.ts).
332
+ - Fixed: a typed constant kept the value folded without its type, so `const T: u8 = ~1n` failed with "-2 does not fit
333
+ in u8" although `~` within a u8 is 254. The value is the one folded in its type, and an untyped constant using it
334
+ gets that value; out-of-range results are still refused (test/language/port-syntax.test.ts).
335
+ - Fixed: a problem with an aliased type (`export type Buf = BigVec<u64>` used as an argument in another file) was
336
+ reported at the alias's declaration, once, instead of where it is used. Each use now gets its own report at the use
337
+ (test/language/aliases.test.ts).
338
+ - Fixed: a view made before `closeRaw` or `resizeAccount` of its account (`const v = t.get(1n)!`, a `rawArrayMutAt`)
339
+ could still be used after it, its bounds checked against the old length, so writes landed past the new end and reads
340
+ were stale. Using one after either, or after a helper that may close or resize an account it is given, is a compile
341
+ error saying to take the view again (test/language/raw-views.test.ts).
342
+ - Fixed: the rule that a `for … of` over a tree may not change its structure was kept per variable, so another view
343
+ of the same tree (`const t2 = rbTreeMutAt(…same account and offset…)`) could remove from it during the walk. It is
344
+ kept per account: no tree view of an account that may be the walked one's may insert, remove or initialize in the
345
+ loop, nor may a helper that takes accounts and makes an `rbTreeMutAt` view be called there
346
+ (test/language/rbtree.test.ts).
347
+ - Language: a reference into a local `FixedVec` (`const e = xs.get(0n)`) read after the element is replaced
348
+ (`xs.set(0n, { … })`, `pop`, `clear`) is refused as one into account data is (`"e" still refers to xs[]`); before, a
349
+ local FixedVec's elements had no storage path and the read compiled, seeing the new value where JS keeps the old
350
+ object (test/language/fixedvec.test.ts). Such messages also name a `@heap` list as the source does (they printed its C
351
+ name).
352
+ - Diagnostics: a node size that is not a multiple of 8 with a scalar value (`rbTreeMutAt<u64, u32>`) says to make the
353
+ value a struct with padding fields, not to add padding to `u32`; the stack-frame report after an overflowing build
354
+ reads clang's remarks without the 1 MiB output limit, which cut them short on large programs
355
+ (test/language/rbtree.test.ts).
356
+ - Programs that use none of the new features above compile to the same C as before; the "Faster" entries name the
357
+ programs whose generated C they change.
358
+
9
359
  ## 0.42.0 — 2026-11-09
10
360
 
11
361
  SPL Stake Pool ported in full, the native program behind most liquid staking tokens, from the tag a reproducible build
package/NOTICE ADDED
@@ -0,0 +1,71 @@
1
+ TypeSOL
2
+ Copyright (c) 2026 TypeSOL contributors. Licensed under the MIT License (LICENSE).
3
+
4
+ Third-party code in the published @typesol/cli package
5
+ --------------------------------------------------------
6
+
7
+ The package ships this NOTICE and the Apache License 2.0 text (test/programs/LICENSE-Apache-2.0.txt).
8
+
9
+ - runtime/typesol_rt.h, the RedBlackTree section (ts_rbt_*): a statement-for-statement port of the red-black tree and
10
+ node allocator of lib-sokoban 0.3.0 (https://github.com/jarry-xiao/sokoban, src/red_black_tree.rs and
11
+ src/node_allocator.rs). lib-sokoban is offered under "MIT OR Apache-2.0"; TypeSOL uses it under the MIT License:
12
+
13
+ MIT License
14
+
15
+ Copyright (c) 2022 Jarry Xiao
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of this software and associated documentation files (the "Software"), to deal
19
+ in the Software without restriction, including without limitation the rights
20
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ copies of the Software, and to permit persons to whom the Software is
22
+ furnished to do so, subject to the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be included in all
25
+ copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ SOFTWARE.
34
+
35
+ - runtime/typesol_rt.h, the BigVec section (ts_bigvec_*), and the BigVec<T> layout the compiler gives account data:
36
+ they follow SPL Stake Pool's big_vec.rs (solana-program/stake-pool, program/src/big_vec.rs; earlier in
37
+ solana-labs/solana-program-library), licensed under the Apache License, Version 2.0. Changes: rewritten in C and
38
+ TypeScript.
39
+
40
+ - dist/testing-stake.js (src/testing-stake.ts), stakeActivation: a port of Delegation::stake_activating_and_deactivating_v2
41
+ of solana-stake-interface 4.3.0 (https://github.com/solana-program/stake, interface crate), Copyright Anza
42
+ Maintainers. Licence: Apache-2.0 (the crate's Cargo metadata for 4.3.0; text in test/programs/LICENSE-Apache-2.0.txt). Changes: rewritten in TypeScript (BigInt arithmetic with the original's u128 saturation).
43
+
44
+ Third-party material in this repository only (not in the published package)
45
+ ------------------------------------------------------------------------------
46
+
47
+ - test/programs/: program binaries dumped from Solana clusters. The ones kept in the repository are Apache-2.0:
48
+ SPL Account Compression and SPL Noop (solana-labs/solana-program-library), Program Metadata
49
+ (solana-program/program-metadata), coral-xyz/multisig, Raydium CP-Swap, Raydium CLMM and Raydium AMM v4 (raydium-io), Jito's tip
50
+ payment, tip distribution and priority fee distribution programs (jito-foundation/jito-programs), marginfi v2
51
+ (mrgnlabs/marginfi-v2), Solend's token-lending (solendprotocol/solana-program-library) and SPL Stake Pool
52
+ (solana-program/stake-pool); and, under the MIT licence, Phoenix v1 (Ellipsis-Labs/phoenix-v1). The licence texts are test/programs/LICENSE-Apache-2.0.txt and
53
+ test/programs/LICENSE-MIT-phoenix-v1.txt; each binary's source, program id
54
+ and sha256 are in test/programs/SOURCES.md.
55
+ marginfi v2's Drift v2 test build (drift-labs/protocol-v2) is Apache-2.0 too and kept.
56
+ The Metaplex programs, under the Metaplex(TM) NFT Open Source License 1.0, Kamino's lending and farms programs and
57
+ JupLend's lending, liquidity and rewards programs, under the Business Source License 1.1, and Drift's Merkle
58
+ distributor, under the GNU GPL 3.0, are not kept here: scripts/fetch-programs.sh downloads them.
59
+ - showcase/test/fixtures/marginfi/: Marginfi v2's on-chain IDL and three of its mainnet accounts (mrgnlabs/marginfi-v2,
60
+ Apache-2.0), and I80F48 vectors written with the fixed crate (MIT or Apache-2.0).
61
+ - showcase/test/fixtures/kamino/: the IDLs of Kamino's lending (1.25.0) and farms programs, the interface descriptions
62
+ as mrgnlabs/marginfi-v2 keeps them in idls-complete/ (Apache-2.0); the programs are not here (see above).
63
+ - showcase/test/fixtures/drift/, showcase/test/fixtures/juplend/: the IDLs of Drift v2 and of JupLend's lending,
64
+ liquidity and rewards rate model programs, as mrgnlabs/marginfi-v2 keeps them in idls-complete/ (Apache-2.0).
65
+ - showcase/test/fixtures/clmm/: Raydium CLMM's on-chain IDL and the accounts of one mainnet pool (raydium-io/raydium-clmm,
66
+ Apache-2.0).
67
+ - showcase/mainnet/: TypeSOL ports of mainnet programs, which follow their originals' source: Raydium CP-Swap, CLMM
68
+ and AMM v4, Jito's MEV programs, marginfi v2, coral-xyz/multisig and SPL Stake Pool (Apache-2.0), and Phoenix v1
69
+ (MIT, Copyright Ellipsis Labs). Every file says which program it ports and under which licence in its first line.
70
+ - showcase/program-examples/: ports of solana-developers/program-examples (MIT, Copyright Solana Foundation; the
71
+ licence text is in showcase/program-examples/README.md).
package/README.md CHANGED
@@ -141,27 +141,41 @@ transactions to both and compares the results.
141
141
 
142
142
  ## Quick start
143
143
 
144
- You need Node.js 22.12 or later and the Agave CLI (`sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"`).
145
- Run `cargo-build-sbf --version` once; this downloads the platform-tools that TypeSOL compiles with. Rust is not needed.
144
+ You need Node.js 22.12 or later and the Agave CLI with its platform-tools, which hold the clang TypeSOL compiles with.
145
+ Rust is not needed. TypeSOL is tested with **Agave 3.1.10 and platform-tools v1.52** (clang 20.1.7); to install exactly
146
+ those:
147
+
148
+ ```sh
149
+ sh -c "$(curl -sSfL https://release.anza.xyz/v3.1.10/install)"
150
+ cargo-build-sbf --install-only --force-tools-install --tools-version v1.52
151
+ ```
152
+
153
+ Other versions work, but their binaries are not covered by the project's tests: `typesol build` warns once when the
154
+ clang is another one (`--toolchain-strict` or `TYPESOL_TOOLCHAIN=strict` makes that an error), and every build records
155
+ its clang, platform-tools and host in `<name>.build.json`.
146
156
 
147
157
  ```sh
148
158
  npx @typesol/cli init my-app --name counter # typesol.json, programs/counter.ts, tests/counter.test.ts, tsconfig
149
159
  cd my-app && npm install
150
160
  npm test # builds the program and runs it in LiteSVM, an in-process Solana runtime
151
- npx typesol build # target/counter/{counter.so, counter.json (IDL), counter.client.ts, counter.build.json}
161
+ npx --no-install typesol build # target/counter/{counter.so, counter.json (IDL), counter.client.ts, counter.build.json}
152
162
  ```
153
163
 
154
- `npx typesol doctor` checks all of this (Node.js, platform-tools, Solana CLI, keypair, RPC) and prints the command
155
- that fixes anything missing. To deploy, on devnet:
164
+ `npx --no-install typesol doctor` checks all of this (Node.js, platform-tools and whether they are the tested ones, Solana CLI, keypair, RPC) and prints the command
165
+ that fixes anything missing. Inside a project, `npx --no-install typesol …` (or `npm run build`, `npm run deploy`) runs the
166
+ project's own copy; outside one, use `npx @typesol/cli …`. Plain `npx typesol` is not TypeSOL: `typesol` is not the npm
167
+ package's name, so where the project's copy is not installed npx would fetch whatever package has that name.
168
+
169
+ To deploy, on devnet:
156
170
 
157
171
  ```sh
158
172
  solana-keygen new # once, if you have no keypair (~/.config/solana/id.json)
159
173
  solana airdrop 2 --url devnet # test SOL for the rent (rate-limited: https://faucet.solana.com also works)
160
- npx typesol deploy --url devnet
174
+ npx --no-install typesol deploy --url devnet
161
175
  ```
162
176
 
163
177
  or on a local validator: `solana-test-validator` in another terminal, `solana airdrop 5 --url localhost`, then
164
- `npx typesol deploy --url localhost`. `deploy` checks the RPC and the payer's balance before sending anything.
178
+ `npx --no-install typesol deploy --url localhost`. `deploy` checks the RPC and the payer's balance before sending anything.
165
179
 
166
180
  `--template vault` or `--template escrow` starts from a SOL vault or an SPL token escrow instead of the counter, each
167
181
  with a passing LiteSVM test.
@@ -185,8 +199,9 @@ If the build refuses something, the error points at the line and, for the usual
185
199
  `typesol port` starts from your program's IDL; [docs/case-study-escrow.md](docs/case-study-escrow.md) follows one
186
200
  program through the port.
187
201
  - Real programs checked against their mainnet binaries: [Showcase](#showcase-ports-checked-against-mainnet), with a
188
- case study each (Marginfi v2 in full: all 124 instructions, the same on 2,081 transactions; Raydium AMM v4, a native
189
- program, down to its log lines).
202
+ case study each (Marginfi v2 in full: all 124 instructions, the same on 2,081 transactions; Phoenix v1, a native
203
+ order book, the same on 3,575 transactions down to its event bytes; Raydium AMM v4, a native program, down to its log
204
+ lines).
190
205
  - To mainnet (wallet, cost, deploy, IDL, verification): [docs/mainnet.md](docs/mainnet.md).
191
206
  - With an AI coding agent: [docs/ai.md](docs/ai.md) (agent rules, [llms.txt](https://typesol.com/llms.txt), the MCP server).
192
207
 
@@ -215,11 +230,12 @@ Runtime failures point back to your source: `Error 6000 Unauthorized (counter.ts
215
230
  | --- | --- |
216
231
  | **Accounts** | `Signer`, `Account<T>`, `Mut<T>`, `Init<T>`, `InitIfNeeded<T>` (PDAs or keypair accounts, with Anchor's `space`; mints, token accounts and associated token accounts), `Zeroed<T>` (up to 10 MiB), optional accounts (`A \| null`), token accounts and mints, `SystemAccount`, programs, sysvars, and account groups (Anchor's composite accounts) |
217
232
  | **Constraints** | `HasOne`, `Seeds` (also from account fields and under another program; `pdaBump` like `ctx.bumps`), `CloseTo`, `Ata`, `Address`, `Owner`, `Executable`. They are checked before the body runs and recorded in the IDL, and take your own error as Anchor's `@ ErrorCode.X` does |
218
- | **Data** | `u8`…`u128`, `i8`…`i128`, `u256` (for computation), `f64` (as its bits, in events and accounts), `boolean`, `Pubkey`, `Hash`, nested structs, `FixedArray`, `FixedString`, `Option`, unit enums, data enums (discriminated unions), `Vec` that resizes its account, `FixedVec` lists anywhere, and Anchor's own byte layout (`@layout borsh`) to take over existing Anchor accounts and to pass, return and emit structs with String / Vec / Option fields as Anchor does |
219
- | **Control flow** | `if`, `for`, `for … of`, `while`, `switch` (with narrowing on data enums), ternaries, `??`, destructuring, helper functions (returning structs too, arrow functions, closures, function arguments, generics, functions chosen at run time), list callbacks (`some`, `find`, `reduce`, …, with `map` / `filter` chains that store nothing) across multiple files |
233
+ | **Data** | `u8`…`u128`, `i8`…`i128`, `u256` (for computation), `f64` (as its bits, in events and accounts), `boolean`, `Pubkey`, `Hash`, nested structs, `FixedArray`, `FixedString`, `Option`, unit enums, data enums (discriminated unions), type aliases (`type Price = u64`), `Vec` that resizes its account, `FixedVec` lists anywhere, and Anchor's own byte layout (`@layout borsh`) to take over existing Anchor accounts and to pass, return and emit structs with String / Vec / Option fields as Anchor does |
234
+ | **Control flow** | `if`, `for`, `for … of`, `while`, `switch` (with narrowing on data enums), ternaries, `??`, destructuring, helper functions (returning structs too, changing the caller's structs and lists through `Inout<T>`, arrow functions, closures, function arguments, generics, functions chosen at run time), list callbacks (`some`, `find`, `reduce`, …, with `map` / `filter` chains that store nothing) across multiple files |
220
235
  | **CPIs** | System, SPL Token, Token-2022 (including extension reads, metadata and token groups), ATA, Memo, Stake, Metaplex Token Metadata, Core, Bubblegum. Generic `invoke` with PDA signing (one or several PDAs per call), return data, and typed bindings generated from any Anchor IDL (`typesol cpi`) |
221
236
  | **Events** | `emit` (log-based) and `emitCpi` (Anchor `emit_cpi!`, through a self-CPI) |
222
237
  | **Crypto & oracles** | `sha256`, `keccak256`, Merkle proofs, Ed25519 and secp256k1 signature checks, Pyth pull oracle, Switchboard feeds and verifiable randomness |
238
+ | **Native programs** | a `@fallback` entry over the raw instruction data and accounts by position, Borsh accounts (`loadBorsh`), views of account bytes in place (also at offsets known only at run time) and lib-sokoban's red-black tree over them, byte builders (`pushLE`, `pushBorsh`, …), return data, `closeRaw`, and Rust's panics and overflow messages at the original's source locations |
223
239
  | **Interfaces** | custom discriminators (`@discriminator`), so a TypeSOL program can be a Token-2022 transfer hook, with extra accounts (ExtraAccountMetaList) |
224
240
 
225
241
  The full reference, with every type, check and built-in, is in [docs/language.md](docs/language.md).
@@ -266,16 +282,16 @@ toolchain and records them with every result:
266
282
  <!-- bench:table -->
267
283
  | Instruction | TypeSOL | Pinocchio 0.10 | Native Rust | Anchor 1.0.2 |
268
284
  | --- | ---: | ---: | ---: | ---: |
269
- | counter.initialize | **1,857** | 3,186 | 4,601 | 6,573 |
285
+ | counter.initialize | **1,856** | 3,186 | 4,601 | 6,573 |
270
286
  | counter.increment | **110** | 113 | 857 | 2,323 |
271
- | vault.open | **1,874** | 3,185 | 4,613 | 6,627 |
287
+ | vault.open | **1,875** | 3,185 | 4,613 | 6,627 |
272
288
  | vault.deposit | **1,314** | 1,377 | 2,832 | 4,355 |
273
289
  | vault.withdraw | **315** | 370 | 1,176 | 3,628 |
274
290
  | vault.shut | **161** | 167 | 950 | 2,024 |
275
- | escrow.make | **3,596** | 6,179 | 9,240 | 13,304 |
291
+ | escrow.make | **3,595** | 6,179 | 9,240 | 13,304 |
276
292
  | escrow.take | **4,019** | 4,051 | 8,500 | 14,365 |
277
293
  | escrow.refund | **2,696** | 2,769 | 5,695 | 8,449 |
278
- | binary, counter / vault / escrow | 11.1 / 14.1 / 21.4 KB | 19.6 / 22.9 / 29.4 KB | 27.9 / 35.0 / 46.5 KB | 145.2 / 158.9 / 190.7 KB |
294
+ | binary, counter / vault / escrow | 11.1 / 14.1 / 21.5 KB | 19.6 / 22.9 / 29.4 KB | 27.9 / 35.0 / 46.5 KB | 145.2 / 158.9 / 190.7 KB |
279
295
  <!-- /bench:table -->
280
296
 
281
297
  `initialize`, `open` and `make` include the PDA bump search. TypeSOL hashes PDA candidates with the sha256 and
@@ -341,10 +357,10 @@ Details are in [docs/testing.md](docs/testing.md).
341
357
 
342
358
  ### Showcase: ports checked against mainnet
343
359
 
344
- [`showcase/`](showcase) holds programs ported from Anchor and checked against the binaries deployed on mainnet (same
345
- outcomes, account bytes and events; [`showcase/test`](showcase/test)), and the ports of all 46
360
+ [`showcase/`](showcase) holds Anchor and native programs ported and checked against the binaries deployed on mainnet
361
+ (same outcomes, account bytes and events; [`showcase/test`](showcase/test)), and the ports of all 46
346
362
  [solana-developers/program-examples](showcase/program-examples/README.md).
347
- Case studies: [Marginfi v2](docs/case-study-marginfi.md), [SPL Stake Pool](docs/case-study-spl-stake-pool.md), [Raydium AMM v4](docs/case-study-raydium-amm.md), [Raydium CLMM](docs/case-study-raydium-clmm.md),
363
+ Case studies: [Marginfi v2](docs/case-study-marginfi.md), [Phoenix v1](docs/case-study-phoenix.md), [SPL Stake Pool](docs/case-study-spl-stake-pool.md), [Raydium AMM v4](docs/case-study-raydium-amm.md), [Raydium CLMM](docs/case-study-raydium-clmm.md),
348
364
  [Raydium CP-Swap](docs/case-study-raydium-cp-swap.md), [Jito MEV](docs/case-study-jito-mev.md),
349
365
  [coral-xyz/multisig](docs/case-study-multisig.md), [an Anchor escrow](docs/case-study-escrow.md).
350
366
 
@@ -354,6 +370,7 @@ Case studies: [Marginfi v2](docs/case-study-marginfi.md), [SPL Stake Pool](docs/
354
370
  | [`raydium-clmm/`](showcase/mainnet/raydium-clmm) | Raydium CLMM in full: concentrated-liquidity positions as NFTs, swaps and multi-hop routes across tick arrays, limit orders, rewards, dynamic fees, u256 math |
355
371
  | [`jito-mev/`](showcase/mainnet/jito-mev) | Jito's tip payment, tip distribution and priority fee distribution: tips paid out per leader, Merkle-proof claims, epochs and expiry |
356
372
  | [`marginfi/`](showcase/mainnet/marginfi) | Marginfi v2 in full, all 124 instructions: I80F48 fixed-point arithmetic, zero-copy accounts, oracles (Pyth, Switchboard, staked SOL, Scope, venue exchange rates), the risk engine, liquidation and bankruptcy, flash loans, orders, rebalances, and the Solend, Kamino, Drift and JupLend banks |
373
+ | [`phoenix/`](showcase/mainnet/phoenix) | Phoenix v1, Ellipsis Labs' on-chain limit order book and a native program, in full, all 28 instructions: price-time matching over lib-sokoban red-black trees in one market account, every order type, self-trade behaviours, time in force, eviction, cancels, seats and fees, its events as Log self-CPIs byte for byte |
357
374
  | [`spl-stake-pool/`](showcase/mainnet/spl-stake-pool) | SPL Stake Pool in full, all 27 instructions, a native program and the one behind most liquid staking tokens: pools of stake across up to 20,000 validators, SOL and stake deposits and withdrawals, rebalancing over epochs, fees and authorities, token metadata |
358
375
  | [`raydium-amm/`](showcase/mainnet/raydium-amm) | Raydium AMM v4, the original constant-product AMM and a native (non-Anchor) program, in full: pool creation, deposits and withdrawals, the v1 and v2 swaps, P&L and administration, down to its log records and panics |
359
376
  | [`multisig.ts`](showcase/mainnet/multisig/multisig.ts) | coral-xyz/multisig: stored instructions run with `invokeInstruction`, a PDA signing, Anchor's Borsh accounts |
package/SECURITY.md CHANGED
@@ -4,11 +4,38 @@ TypeSOL generates programs that hold funds. Treat it accordingly.
4
4
 
5
5
  ## Status
6
6
 
7
- - The compiler, runtime and tooling have been through internal security reviews. Every release is covered by execution
8
- tests, differential tests against Anchor, and randomized tests. **TypeSOL has not been audited by an independent
9
- firm.** Do not put significant value behind programs built with it until an external audit of the compiler and
10
- runtime is published, and audit your own programs as you would any Solana program.
11
- - Only the latest 0.x release receives security fixes.
7
+ - The compiler, runtime and tooling have been through internal security reviews by the maintainers. The latest, of
8
+ 0.43.0 on 2026-11-11, found defects in the compiler (one of them can break an authorization check in a helper) and
9
+ in the tooling; they are fixed in 0.44.0. **Rebuild and redeploy programs built with 0.43.0 or
10
+ earlier once it is out**; [docs/security-model.md](docs/security-model.md#review-of-0430-2026-11-11) says how to tell
11
+ whether a program was exposed, and [docs/audit.md](docs/audit.md#earlier-reviews) what that review did and did not
12
+ cover. Every release is covered by execution tests, differential tests against Anchor, and randomized tests.
13
+ **TypeSOL has not been audited by an independent firm.** Do not put significant value behind programs built with it
14
+ until an external audit of the compiler and runtime is published, and audit your own programs as you would any
15
+ Solana program.
16
+ - The tests cover binaries built with the toolchain a release declares as tested (Agave 3.1.10, platform-tools v1.52
17
+ for this one). `typesol build` warns about another one, `--toolchain-strict` refuses it, and each build records its
18
+ toolchain in `<name>.build.json`: keep that file with every deployment.
19
+ - From 0.43.0 on, `releases/<version>.json` records the published npm tarball (its shasum, integrity and every file's
20
+ sha256), packed from a clean export of the release tag; `node scripts/release-check.ts <version> --verify --registry`
21
+ compares it with the registry.
22
+ - Only the latest 0.x release receives security fixes, as fix releases (below).
23
+
24
+ ## Fix releases
25
+
26
+ From 0.44.0 on, a release that only fixes soundness or security defects is published as a patch of the latest minor
27
+ release (0.44.0 → 0.44.1), so a team can take the fix without taking new features:
28
+
29
+ - it adds no language surface (nothing new in `lib/typesol.d.ts`, no construct accepted that was refused) and changes
30
+ no account layout, IDL or error code beyond what the fix itself needs;
31
+ - a program it refuses or builds to another binary is one the defect touches, and the CHANGELOG says which;
32
+ - its release notes carry the binary diff against the previous release (the previous release's sources built by both
33
+ packages, `binary-diff.txt`; see [docs/testing.md](docs/testing.md#reproducing-a-release)), so a team can see whether
34
+ their program's binary changes.
35
+
36
+ Fixes go to the latest minor only; older minors are not maintained. A fix that needs a language or layout change
37
+ comes in the next minor. 0.44.0 itself is a minor release: besides the fixes from the 0.43.0 review it has behaviour
38
+ changes (new compile errors, `deploy` refusing to run without a cluster).
12
39
  - What a compiled program can rely on is specified in [docs/security-model.md](docs/security-model.md); the package
13
40
  for an external audit is [docs/audit.md](docs/audit.md).
14
41