@typesol/cli 0.38.0 → 0.40.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 (61) hide show
  1. package/CHANGELOG.md +373 -2
  2. package/README.md +43 -26
  3. package/SECURITY.md +1 -1
  4. package/dist/cli.js +37 -3
  5. package/dist/compiler/analyze.d.ts +6 -11
  6. package/dist/compiler/analyze.js +331 -34
  7. package/dist/compiler/emit/alias.js +3 -2
  8. package/dist/compiler/emit/base.d.ts +7 -1
  9. package/dist/compiler/emit/base.js +2 -0
  10. package/dist/compiler/emit/borsh.js +63 -2
  11. package/dist/compiler/emit/calls.d.ts +14 -1
  12. package/dist/compiler/emit/calls.js +311 -21
  13. package/dist/compiler/emit/cpi-core.js +17 -5
  14. package/dist/compiler/emit/cpi.js +81 -27
  15. package/dist/compiler/emit/create.d.ts +7 -0
  16. package/dist/compiler/emit/create.js +27 -0
  17. package/dist/compiler/emit/expressions.d.ts +6 -0
  18. package/dist/compiler/emit/expressions.js +102 -6
  19. package/dist/compiler/emit/function.d.ts +7 -0
  20. package/dist/compiler/emit/function.js +164 -29
  21. package/dist/compiler/emit/program.js +27 -2
  22. package/dist/compiler/emit/shared.d.ts +15 -5
  23. package/dist/compiler/emit/shared.js +5 -0
  24. package/dist/compiler/emit/statements.d.ts +28 -1
  25. package/dist/compiler/emit/statements.js +270 -13
  26. package/dist/compiler/emit/storage.d.ts +10 -1
  27. package/dist/compiler/emit/storage.js +50 -11
  28. package/dist/compiler/hints.d.ts +5 -0
  29. package/dist/compiler/hints.js +88 -0
  30. package/dist/compiler/idl.d.ts +1 -1
  31. package/dist/compiler/idl.js +42 -11
  32. package/dist/compiler/index.d.ts +3 -0
  33. package/dist/compiler/index.js +6 -1
  34. package/dist/compiler/model.d.ts +47 -10
  35. package/dist/compiler/model.js +14 -4
  36. package/dist/testing.js +8 -0
  37. package/dist/tools/clientgen.js +10 -1
  38. package/dist/tools/portgen.d.ts +6 -0
  39. package/dist/tools/portgen.js +68 -17
  40. package/docs/architecture.md +5 -4
  41. package/docs/audit.md +31 -19
  42. package/docs/case-study-escrow.md +5 -5
  43. package/docs/case-study-jito-mev.md +9 -5
  44. package/docs/case-study-marginfi.md +797 -0
  45. package/docs/case-study-multisig.md +3 -3
  46. package/docs/case-study-raydium-amm.md +80 -0
  47. package/docs/case-study-raydium-clmm.md +44 -33
  48. package/docs/case-study-raydium-cp-swap.md +3 -3
  49. package/docs/cli.md +5 -5
  50. package/docs/client.md +1 -1
  51. package/docs/errors.md +13 -5
  52. package/docs/language.md +65 -32
  53. package/docs/migrate-from-anchor.md +4 -1
  54. package/docs/runtime.md +1 -1
  55. package/docs/security-model.md +2 -1
  56. package/docs/testing.md +34 -1
  57. package/docs/troubleshooting.md +6 -0
  58. package/lib/typesol.d.ts +118 -10
  59. package/package.json +9 -7
  60. package/runtime/typesol_rt.h +158 -17
  61. package/ts-plugin/index.js +24 -1
package/CHANGELOG.md CHANGED
@@ -1,11 +1,382 @@
1
1
  # Changelog
2
2
 
3
- TypeSOL follows the organization's [versioning policy](https://github.com/typesol/.github/blob/main/VERSIONING.md)
3
+ TypeSOL follows the organization's [versioning policy](https://github.com/typesol-lang/.github/blob/main/VERSIONING.md)
4
4
  (compiler specifics in CONTRIBUTING.md): until 1.0, a minor version may change the language, the IDL layout or error
5
5
  codes, and says so here.
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 0.40.0 — 2026-11-06
10
+
11
+ Raydium AMM v4 ported in full, a native (non-Anchor) program, and checked against its mainnet binary down to its log
12
+ lines and panics. The compiler gained what a native program needs: accounts without a discriminator, the instruction
13
+ data read by offset, errors from code 0, built-in program errors, panics with a location, and the entrypoint's log
14
+ lines. Also: functions chosen at run time, `find(…)!.field` / `?.field` on struct lists, struct maps inside chains, and
15
+ hints under the errors newcomers meet first, in the CLI and the editor. Programs that use none of the new features
16
+ compile to the same C as in 0.39.0.
17
+
18
+ - Examples: showcase/mainnet/raydium-amm, a port of Raydium AMM v4 (the native program at 675kPX9M…, all of its
19
+ instructions: Initialize2, deposits, withdrawals, the v1 and v2 swaps base in and base out, P&L, parameters, the
20
+ config, excess lamports), checked against the mainnet binary (test/programs/raydium_amm_v4.so) on 484 transactions,
21
+ fuzzed: the same outcomes, account bytes and log lines, ray_log records and the original's panics included; swaps
22
+ take 41–44% of the original's compute units, deposits and withdrawals 35–37%. See docs/case-study-raydium-amm.md.
23
+ - New (native programs; docs/language.md "Porting a native program"): `loadRaw<T>` / `loadRawMut<T>` for accounts
24
+ without a discriminator; `readU8/U16/U32/U64/U128/readPubkey(offset)` on `instructionData()`; error enums from code 0
25
+ (returned as CUSTOM_ZERO); `require(c, ProgramError.X)` for Solana's built-in errors; `panic(message, location?)`;
26
+ `PANIC_ON_OVERFLOW`, `ERROR_LOG_PREFIX` and `PROGRAM_ERROR_LOG_PREFIX` program constants; `createProgramAddress`;
27
+ `logBase64(prefix, struct)`.
28
+ - Fixed: `isqrt` of a u256 (it generated C that did not compile).
29
+ - New: a function chosen at run time, `const g = k === 1n ? dbl : inc; g(x)` (the condition read once; only the chosen
30
+ function runs), and a list of functions run in turn, `for (const f of [dbl, inc]) …` (unrolled; `continue` and `break`
31
+ work).
32
+ - New: `xs.find(f)!.field` and `xs.find(f)?.field` on lists of structs (located with findIndex, read in place; `!` aborts
33
+ with 5108 when nothing matched, `?.` gives an Option).
34
+ - New: `map` to structs inside a chain when the callback names the struct, `xs.map((o): Scored => ({ … })).filter(…)
35
+ .reduce(…)`: one struct per element, nothing stored.
36
+ - Hints: comparing an integer with a number (`k === 1`) points at `1n`. `.length` on something that is not a list says
37
+ what it is instead of asking for byteLength; the FixedVec argument/account refusal says why (two byte layouts, one IDL
38
+ type).
39
+ - Docs: the README's quick start ends with a first change to make and a short "where next" list (it was one long
40
+ paragraph); the showcase lists Marginfi v2 as complete and links every case study.
41
+ - Editor: the plugin (`typesol/ts-plugin`) adds the same hints under TypeScript's errors in a program's files, once the
42
+ in-process compiler has loaded, so VS Code shows what to write instead too.
43
+ - CLI: `typesol init` names the other starters (`--template vault`, `--template escrow`) after the next steps.
44
+ - CLI: build errors show the path relative to the working directory and the source line with the problem marked.
45
+ `--json` and the compiler API keep their fields (a hint is a line of the message).
46
+ - New: hints for the errors newcomers meet first, under TypeScript's message: a number where a u64 is (`1n`), `Math.max`
47
+ (`min` / `max`), `console.log` (`log`), a missing `typesol` import, `async`, writing an account that is not `Mut<T>`,
48
+ `xs[i]` (`.get` / `.set`). Refused syntax is named in TypeScript's words ("classes are not supported: …") instead of
49
+ the compiler's internal node names, and `require` with a template string says what its error can be.
50
+ - Docs: Marginfi's case study lists part 5 as done (all 124 instructions); troubleshooting points to the hints.
51
+ - Releases: `scripts/release-manifest.ts` builds the program-examples ports of sources up to 0.38.0 (`test/ports/`; a
52
+ 0.38.0 tree listed only 18 programs). docs/testing.md and CONTRIBUTING describe the manifest and binary diff as attached
53
+ by hand.
54
+
55
+ ## 0.39.0 — 2026-11-06
56
+
57
+ Marginfi v2 ported in full: all 124 instructions, checked against the mainnet binary on 2,081 transactions with the
58
+ same outcomes, account bytes, events and IDL. The compiler gained what it needed: `Option` struct and `Vec`
59
+ arguments, `f64` fields, hashes as PDA seeds, account resizing and raw writes, `systemProgram.createPda`, and Anchor's
60
+ order and error codes for `init` and zero-copy accounts. The ports moved to `showcase/`. The repository now lives at
61
+ github.com/typesol-lang, and releases are published by hand (no workflow publishes).
62
+
63
+ Upgrading: the IDL writes `Vec<u8>` arguments and account fields as `bytes`, as Anchor does, so an Anchor client
64
+ passes a Buffer for them (the bytes on the wire are unchanged). Accounts created at the start of an instruction now
65
+ run before the other accounts' constraints, and zero-copy accounts are checked in `AccountLoader`'s order, so a
66
+ transaction that breaks several checks can fail with a different error code; programs with such creates or zero-copy
67
+ accounts compile differently (see "Changed" below).
68
+
69
+ - Project: no scheduled or publishing automation in the repository: npm releases are published by hand from a
70
+ maintainer's machine (the release workflow is gone), the macOS suite runs on demand only, and Dependabot no longer
71
+ opens weekly pull requests.
72
+ - Examples: Marginfi's rebalances across Kamino, Drift and JupLend banks, each leg priced at the venue's supply rate
73
+ (klend's curve and reward emissions at the chain's measured slot pace, Drift's curve less its insurance factor,
74
+ JupLend's liquidity-layer rate and Lending rewards), amounts through the venues' exchange rates, deposit room capped
75
+ by the venue's own. Against the binary on mainnet: 2,081 transactions (with the fixes and tests below).
76
+ - Fixed (examples): a classic liquidation by Marginfi's risk admin flags both accounts as the original does, so their
77
+ Exponent PT banks are priced through a vault emergency there too.
78
+ - New: `systemProgram.createPda(payer, account, space, owner, seeds)`, Anchor's `init` with `owner = …` on an
79
+ `UncheckedAccount`: another program's account at this program's PDA, created (or, over an address someone funded
80
+ first, topped up, allocated and assigned) before the instruction's constraints, the PDA recorded in the IDL.
81
+ - Examples: Marginfi's I80F48 magnitudes widen to u256 once (their sum stays in u128) and a float's bit length is
82
+ found by halving, not bit by bit: a classic liquidation takes 7% fewer compute units (130,448 → 121,210 on the
83
+ test's partial liquidation; 38% under the original's).
84
+ - Tests: a `TYPESOL_PROFILE=1` build's VM has no 1.4M compute limit and keeps every log line, so `typesol profile`
85
+ sees a whole Marginfi liquidation (its markers took it past both before).
86
+ - Examples: more of Marginfi's venue paths against the binary: Kamino and Solend deposits and withdrawals of disabled,
87
+ frozen and paused accounts, Kamino's receivership, deleverage, group outflow limit and deleverage day's limit branches
88
+ and its bank's `has_one` accounts, and the risk admin deleveraging an Exponent PT through a vault emergency.
89
+ (`*DepositFailed` / `*WithdrawFailed` guard against a venue that moves other amounts than asked; the venues' own
90
+ programs never do, so they stay untested.)
91
+ - New: an optional account in `invoke`'s list, as it is (`readonly(x)` with `x: A | null`), is left out when it was not
92
+ passed (Rust's `if let Some(..)` pushes).
93
+ - Fixed: a `constraint(acct, …)` that mentions another, optional account runs when that account is missing (it was
94
+ skipped, so `x === null` checks never failed); only `acct` itself being optional and missing skips it. Declared
95
+ constraints (`HasOne` and the like) still run only when the optional accounts they name were passed.
96
+ - Fixed (examples): Marginfi's `drift_withdraw` refuses a withdrawal from a Drift user with admin deposits when the
97
+ reward accounts are missing (6321), as the original does, and passes any combination of the six optional reward
98
+ accounts on to Drift (the port refused all but some).
99
+ - Fixed (examples): Marginfi's `solend_init_obligation` initializes an obligation address someone funded first (Anchor's
100
+ `init` tops the rent up, allocates and assigns), and creates it before all its other checks, as the original does. The
101
+ Solend fuzz holds every transaction to the original's error code; a withdrawal with a debt, where the original fails
102
+ borrowing the bank (AccountBorrowFailed), must fail with the port's error 12.
103
+ - New: `epochStartTimestamp()`, when the current epoch began (the Clock's `epoch_start_timestamp`).
104
+ - Examples: Marginfi's pricing, every oracle setup: staked SOL (a single pool's stake per LST, before and after its
105
+ on-ramp), mSOL (Marinade's rate) and LSTs (an SPL or Sanctum stake pool's), Scope entries, Exponent PTs (linear to
106
+ par, capped by redemption, emergency mode honoured except where the original prices through it), and fixed venue
107
+ prices, each also inside Kamino and JupLend banks where the original has that kind. Setting a fixed venue price
108
+ checks the venue's account. Against the binary on mainnet: 1,936 transactions.
109
+ - Examples: Marginfi's Drift and JupLend banks (`lending_pool_add_bank_drift`, `drift_init_user`, `drift_deposit`,
110
+ `drift_withdraw`, `drift_harvest_reward`, `drift_claim_bad_debt`, `lending_pool_add_bank_juplend`,
111
+ `juplend_init_position`, `juplend_deposit`, `juplend_withdraw`) over Drift v2, Drift's bad-debt Merkle distributor
112
+ and JupLend's lending, liquidity and rewards programs, and their pricing: the feed times the spot market's
113
+ cumulative deposit interest or the Lending's token exchange price. All 124 of Marginfi's instructions are now ported
114
+ (pricing fixed venue banks and venue rebalance legs still stop in the port).
115
+ Against the binary on mainnet: 1,798 transactions, the same IDL for all 124. The venue tests now hold a refused
116
+ transaction to the original's error code, not only to failing.
117
+ - New: `Owner<Account<T>, "…">` is another program's struct account (Anchor's `Account` / `AccountLoader` of a
118
+ `declare_program!` type): loaded with that program as its owner (3007), `HasOne` and fields as for this program's.
119
+ - New: such a struct may have a discriminator of 1 to 8 bytes (`/** @discriminator 0x01 */`, as Anchor's
120
+ `discriminator = &[1]`), its fields starting right after it.
121
+ - Fixed (examples): Marginfi's Solend, Kamino and Drift banks load the venues' accounts as the original's
122
+ `AccountLoader`s do, before any constraint (a foreign account is 3007, not the bank's `has_one` error); setting a
123
+ venue bank's oracle checks its reserve, spot market or Lending again; a Drift scaled balance past u64 is 4102 and a
124
+ Drift deposit limit past I80F48 6004, as in the original. The venue tests now fuzz deposits, withdrawals, borrows,
125
+ repayments and the venues' rates against the original (FUZZ_SEED, FUZZ_STEPS).
126
+ - New: an `Address<AccountInfo, "…">` parameter may be `invoke`'s program (Anchor's `address = ID` on an
127
+ `UncheckedAccount`; the key alone is checked, 2012).
128
+ - Examples: Marginfi's Solend and Kamino banks (`lending_pool_add_bank_solend`, `solend_init_obligation`,
129
+ `solend_deposit`, `solend_withdraw`, `lending_pool_add_bank_kamino`, `kamino_init_obligation`, `kamino_deposit`,
130
+ `kamino_withdraw`, `propagate_kamino_market_emergency`, `kamino_harvest_reward`) over Solend's, klend's and kfarms'
131
+ mainnet programs, and their pricing: the Pyth or Switchboard feed times the reserve's exchange rate in the risk
132
+ engine, the price cache keeping the rate as its multiplier, the circuit breaker watching the multiplied price, a
133
+ Kamino emergency taking the collateral's Initial value. Against the binary on mainnet: 1,601 transactions, the
134
+ same IDL for all 114 ported instructions.
135
+ - New: `Ata<TokenAccount, "@acct.field", "mint">`, the associated token account of a Pubkey stored in a struct
136
+ account; the IDL names the account, as Anchor's does for `acct.load()?.field`.
137
+ - Fixed: an instruction that reads the Clock (`now()`, `currentSlot()`, `currentEpoch()`) in a `constraint(…)` and
138
+ again in its body failed to compile (the Clock cache was declared twice, or after the constraint that used it).
139
+ - Examples: Marginfi's staked SOL (`init_staked_settings`, `edit_staked_settings`, `propagate_staked_settings`,
140
+ `disable_staked_oracles`, `enable_staked_oracle_onramp`, `lending_pool_add_bank_permissionless`,
141
+ `lending_pool_backfill_staked_bank_validator_vote_account`) and `lending_pool_configure_bank_oracle_scope`. Against
142
+ the binary on mainnet: 1,440 transactions, the same IDL for all 104 ported instructions.
143
+ - New: `writeData<T>(account, offset, value)`, a little-endian write into a `Mut<AccountInfo>` of this program
144
+ (bounds-checked); `resizeAccount(account, newSize)`, Rust's `AccountInfo::resize` (the length only, new bytes
145
+ zeroed, no rent moved, at most 10 KiB of growth).
146
+ - `Dup<…>` may name the twin of a close destination (a keeper settling its own record): duplicates share one record,
147
+ so the rent reaches it either way. The closed account itself is still refused as a twin.
148
+ - Examples: Marginfi's rebalance execution (`marginfi_account_start_rebalance`, `end_rebalance`,
149
+ `settle_rebalance_tip`, native banks), account resizing (`lending_pool_resize_group_account`,
150
+ `lending_pool_resize_bank_account`, `resize_global_fee_state`) and the monitor archive
151
+ (`monitor_archive_initialize`, `monitor_archive_upsert_batch`). Against the binary on mainnet: 1,396 transactions,
152
+ the same IDL for all 96 ported instructions.
153
+ - Fixed: an event's fields go out in the order declared, as Anchor's Borsh sends them (a `Vec<T>` field went last,
154
+ after the fixed-size fields as account data stores it), and the IDL lists them so.
155
+ - Examples: Marginfi's rebalance orders, kept: `marginfi_account_place_rebalance_order`, `update_rebalance_order`,
156
+ `close_rebalance_order`, `top_up_rebalance_fee_pool`, `withdraw_rebalance_fee_pool`. Against the binary on mainnet:
157
+ 1,314 transactions, the same IDL for all 88 ported instructions.
158
+ - Examples: Marginfi's order execution, `marginfi_account_start_execute_order` and
159
+ `marginfi_account_end_execute_order` (a sandwich: the executor withdraws and repays in between). Against the binary
160
+ on mainnet: 1,265 transactions, the same IDL for all 83 ported instructions.
161
+ - New: `Option<Vec<T>>` event fields (given `null`, such an argument or a list), and a nested struct written as a
162
+ literal in an event goes out as Borsh (its Options one byte when empty), as Anchor emits Marginfi's
163
+ `SetKeeperCloseFlagsEvent`.
164
+ - New: a `Hash` is a PDA seed (its 32 bytes).
165
+ - Examples: Marginfi's orders, placed and closed: `marginfi_account_place_order`, `marginfi_account_close_order`,
166
+ `marginfi_account_set_keeper_close_flags`, `marginfi_account_keeper_close_order`. Against the binary on mainnet:
167
+ 1,221 transactions, the same IDL for all 81 ported instructions.
168
+ - New: `Option<Vec<T>>` instruction arguments (or `Vec<T> | null`, or of a FixedVec; Anchor's `Option<Vec<u8>>`): a
169
+ tag byte, then the Vec when Some; `x !== null` before reading it as a list or passing it to a helper that takes the
170
+ list.
171
+ - IDL: `Vec<u8>` arguments and account fields are `bytes`, as Anchor writes them (were `{ vec: "u8" }`; the bytes on
172
+ the wire are the same, but an Anchor client now wants a Buffer for them).
173
+ - Examples: Marginfi's bank metadata (`init_bank_metadata`, `write_bank_metadata`, `write_bank_metadata_pre_init`) and
174
+ `lending_pool_clone_bank` (which panics in the mainnet build, as the original does). Against the binary on mainnet:
175
+ 1,170 transactions, the same IDL for all 77 ported instructions.
176
+ - Faster: a struct a function holds itself (a literal, or what a helper returned) passes to a helper that takes
177
+ accounts in place instead of being copied first (only account data can change under a helper); a struct literal
178
+ fills a new `const` directly instead of a temporary; `fixedArray<T, N>(fill)` may be a struct field's value in a
179
+ literal. Programs with struct literals build to different binaries: here raydium-clmm and marginfi (a Marginfi
180
+ withdrawal 2,700 compute units fewer, a health pulse of an empty account 3,400).
181
+ - New: `/** @bytes */` on a FixedArray of integers: the IDL shows each as its bytes (Marginfi's
182
+ `HealthCache.prices: [[u8; 8]; 16]`, written as 16 u64s instead of 128 bytes).
183
+ - Repository: `pnpm test:core` no longer runs the showcase tests too (a path filter of `test` matched
184
+ `showcase/test`); CI's compiler and showcase jobs now split the suite between them.
185
+ - Examples: Marginfi's bank administration, part three: `lending_pool_emissions_deposit` (refusing fee and hook
186
+ mints, as the original does), `lending_pool_init_same_asset_emode_registry` and
187
+ `lending_pool_set_bank_same_asset_emode_eligibility`. Against the binary on mainnet: 1,140 transactions, the same IDL
188
+ for all 73 ported instructions.
189
+ - Examples: Marginfi's bank administration, part two: `lending_pool_configure_bank_gov`,
190
+ `lending_pool_collect_bank_premium_fees`, `super_admin_deposit` and `super_admin_withdraw` (which panic in the
191
+ mainnet build, as the original does). Against the binary on mainnet: 1,084 transactions, the same IDL for all 70
192
+ ported instructions.
193
+ - Examples: Marginfi's bank administration, part one: `lending_pool_configure_bank_emode`, `lending_pool_clone_emode`,
194
+ `lending_pool_configure_bank_premium`, `lending_pool_clear_circuit_breaker`, `lending_pool_backfill_bank_is_t22_flag`
195
+ and `lending_pool_close_bank`. Against the binary on mainnet: 1,061 transactions, the same IDL for all 66 ported
196
+ instructions. 45–96% fewer compute units.
197
+ - New: instruction arguments of type `Option<S>` (or `S | null`) for a fixed-size struct S, as Anchor's
198
+ `Option<WrappedI80F48>`: Borsh (a tag byte, then S when Some), validated on entry like struct arguments (102),
199
+ `{ option: { defined } }` in the IDL, read after `x !== null`. Helpers still take the struct itself.
200
+ - Examples: Marginfi's group and fee state administration: `config_group_fee`, `edit_global_fee_state`,
201
+ `edit_fee_state_premium`, the panic pause (`panic_pause`, `panic_unpause`, `panic_unpause_permissionless`),
202
+ `marginfi_group_set_governance_admin`, `marginfi_group_configure_gov`, `configure_bank_rate_limits`,
203
+ `configure_group_rate_limits`, `update_group_rate_limiter` and `lending_pool_configure_group_premium`. Against the
204
+ binary on mainnet: 1,024 transactions, the same IDL for all 60 ported instructions. 68–97% fewer compute units.
205
+ - Examples: Marginfi's account administration: `marginfi_account_set_freeze`,
206
+ `marginfi_account_update_emissions_destination_account`, `sync_indexer_flags`, `transfer_to_new_account`,
207
+ `transfer_to_new_account_pda` and `admin_close_account`. Against the binary on mainnet: 955 transactions, the same IDL
208
+ for all 48 ported instructions. 38–86% fewer compute units.
209
+ - Examples: Marginfi's flash loans, the start of part 5 of the port: `lending_account_start_flashloan` (the end
210
+ instruction found through the Instructions sysvar) and `lending_account_end_flashloan` (the deferred health check,
211
+ premium rates and the breaker's gate). Against the binary on mainnet: 915 transactions, the same IDL for all 42
212
+ ported instructions; the fuzzer runs flash loans too. 40–52% fewer compute units.
213
+ - Examples: Marginfi decodes its rates' u32 encodings in 64-bit arithmetic (no 128-bit division): accrual 45–73%
214
+ fewer compute units than the original (was 39–73%), 1,000–4,000 fewer on liquidations and bank configuration. The
215
+ receivership and deleverage tests now send the banks in the order the instructions between start and end leave
216
+ them, so their successful cases succeed on every run; the costs in docs/case-study-marginfi.md are re-measured
217
+ (receiverships 30–40% fewer, not 29–45%).
218
+ - Examples: Marginfi's deleverage, which completes part 4 of the port: `start_deleverage` and `end_deleverage` (the
219
+ risk admin's receivership, any account, health may not fall), `configure_deleverage_withdrawal_limit`,
220
+ `update_deleverage_withdrawals`, `lending_pool_force_tokenless_repay_complete` and `purge_deleverage_balance`.
221
+ Against the binary on mainnet: 890 transactions, the same IDL for all 40 ported instructions; the fuzzer
222
+ deleverages too.
223
+ - Examples: Marginfi's receivership liquidation (part 4 of the port): `start_liquidation` and `end_liquidation`, the
224
+ account's health and its banks' prices locked at the start and its health at those prices at the end (the premium
225
+ cap, a close-out under $5, the tag's growing premium, the record's entries, the flat SOL fee), the transaction's
226
+ instructions checked as the original checks them. Against the binary on mainnet: 847 transactions, the same IDL for
227
+ all 34 ported instructions; the fuzzer runs receiverships too. 29–45% fewer compute units on receivership
228
+ transactions.
229
+ - Examples: Marginfi's classic liquidation (part 4 of the port): `lending_account_liquidate`, the liquidatee's
230
+ collateral taken at a discount for its debt, the insurance fund's cut sent from the liability bank's vault, the
231
+ liquidatee's tag after it, the liquidator's health over its own accounts and its premium seeded, a halted bank left
232
+ to the admins, Token-2022. Against the binary on mainnet: 803 transactions, the same IDL for all 32 ported
233
+ instructions; the fuzzer liquidates too. 34–39% fewer compute units on liquidations.
234
+ - Examples: Marginfi's liquidation records and bankruptcy, the start of part 4 of the port:
235
+ `marginfi_account_init_liq_record`, `marginfi_account_tag_liq_record` (a liquidatable account tagged, the health
236
+ cache from the Maintenance pass), `marginfi_account_close_liq_record` and `lending_pool_handle_bankruptcy` (the
237
+ insurance vault first, Token-2022 fees included, the rest socialized, a bank killed when nothing is left). Against
238
+ the binary on mainnet: 736 transactions, the same IDL for all 31 ported instructions; the fuzzer tags and settles
239
+ bankruptcies too. 44–52% fewer compute units on bankruptcies, 45% on a tag.
240
+ - Examples: Marginfi's borrows and health pulses, which completes part 3 of the port: `lending_account_borrow`
241
+ (origination fees, the premium check, rate limits after health) and `lending_account_pulse_health` (three passes
242
+ keeping what each gets to, the indexer flags, the event with the cache). Against the binary on mainnet: 687
243
+ transactions, the same IDL for all 27 ported instructions; the fuzzer borrows and pulses too, and its keys now come
244
+ from its seed, so `FUZZ_SEED` reproduces a run exactly. 41–47% fewer compute units on borrows, 15–64% on pulses.
245
+
246
+ - New: helpers take the remaining accounts as a list. A `RemainingAccounts` parameter (`remainingAccounts()` at the
247
+ call) gives the helper `.length` and `.get(i)` over the same accounts, to read, load or pass on to another helper,
248
+ as a risk engine walks one [bank, oracle] group per position.
249
+ - Examples: Marginfi's withdrawals and risk engine (part 3, docs/case-study-marginfi.md): withdrawals of part or all
250
+ of a deposit, with the account's Initial health over Pyth, Switchboard and fixed prices (oracle errors recorded or
251
+ failing as the original's, e-mode and same-asset e-mode, the isolated tier, the deposit cap's discount), premium
252
+ projection and rate snapshots, the circuit breaker's gate, the liquidation tag, rate limits, receivership,
253
+ deleverage and Token-2022. Against the binary on mainnet: 177 new transactions (595 in all, an account with 16
254
+ positions among them), the same IDL for all
255
+ 25 ported instructions, and the random runs withdraw through the risk engine; 33–84% fewer compute units on the
256
+ withdrawals that succeed. The fuzzer found how the original records an undecodable oracle's error in the health
257
+ cache (0, the variant's index, not 6000).
258
+ - Fixed (Marginfi example): the oracle port below had made I80F48 products cost more (an accrual 26,983 compute units
259
+ instead of 25,296): with three functions multiplying 256-bit values, clang stopped inlining the multiplication.
260
+ The checked and wrapping products now hand everything that cannot overflow to the plain one.
261
+
262
+ - New: helpers take remaining accounts. A `RemainingAccount` parameter (`remainingAccounts().get(i)` at the call)
263
+ gives the helper the account's key, owner, lamports and data length, `readData` at any offset, and `loadAccount` /
264
+ `loadAccountMut` of a struct; a read-only view sees what the instruction already wrote through the same account, and
265
+ a `loadAccountMut` claims the account for the rest of the instruction (a second one fails with 2040).
266
+ - New: `require(condition, code)` with a `u32` code computed at run time fails with that code (a helper that returns
267
+ its error as a value, as Rust's `?` passes one on: `require(r.err === 0n, r.err)`); a zero code fails with 5100.
268
+ - Examples: Marginfi's oracles (part 3 of the port, docs/case-study-marginfi.md): pointing a bank at a Pyth push or
269
+ Switchboard pull feed, fixed prices, and the price cache pulse with the circuit breaker (tiers, escalation, the long
270
+ window, breaking a bank). Against the binary on mainnet: 174 new transactions over Pyth and Switchboard accounts
271
+ written byte for byte, the same IDL for all 24 ported instructions, and the random runs set oracles and pulse prices
272
+ through the breaker; 47–84% fewer compute units on the ones that succeed.
273
+
274
+ - Repository: the ports moved out of `examples/` and `test/` into `showcase/`: `showcase/mainnet/` (Raydium CP-Swap
275
+ and CLMM, Jito's MEV programs, Marginfi, coral-xyz/multisig), `showcase/program-examples/` (was `test/ports/`) and
276
+ `showcase/test/` (their tests, fuzzers, helpers and fixtures). `examples/` keeps the small programs the templates
277
+ come from. CI runs the compiler's tests (`pnpm test:core`) and the showcase (`pnpm test:showcase`) as separate jobs.
278
+ The release manifest and the codegen snapshot read both layouts, so older tags still build.
279
+
280
+ - Faster: `u256` multiplication (and so I80F48 products, `mulDiv`) multiplies only the 32-bit limbs that are not
281
+ zero: two 88-bit values take 9 products instead of 64. A Marginfi I80F48 product went from about 700 to about 380
282
+ compute units, and an interest accrual from 30,292 to 25,296 (against the original's 41,642); across Marginfi's
283
+ successful transactions the port now uses 36–97% fewer compute units than the original (24–97% before). Programs that use
284
+ `u256` or `mulDiv` build to different binaries: here examples/raydium-clmm and marginfi.
285
+ - New: a narrowed `Option` of a struct or fixed array (`args.inner !== null` before it) passes straight to a helper
286
+ that takes the struct or array.
287
+
288
+ - Examples: Marginfi's repayments and fees, which completes part 2 of the port (docs/case-study-marginfi.md):
289
+ repayments in part (the premium settled first) and in full (rounded up, the balance closed), tokenless repayments by
290
+ the risk admin, collecting a bank's fees, and the admin and permissionless withdrawals from its fee and insurance
291
+ vaults. Against the binary on mainnet: 244 transactions (63 new) with the same outcome, account bytes and events, the
292
+ same IDL for all 21 ported instructions, and the random runs repay and move fees too; 24–97% fewer compute units on
293
+ the ones that succeed.
294
+ - Changed: a token account or mint parameter that is an empty system account (never created) fails with
295
+ AccountNotInitialized (3012), as Anchor's `Account` / `InterfaceAccount` checks it, before the owner check (3007).
296
+
297
+ - Examples: Marginfi's accounts and deposits (part 2 of the port, docs/case-study-marginfi.md): opening accounts as
298
+ keypairs and PDAs, deposits (SPL Token, and Token-2022 with the transfer fee added), closing balances and accounts.
299
+ Against the binary on mainnet: the same outcome, account bytes and events on 181 transactions now (66 new), the same
300
+ IDL for all 16 ported instructions, and the random runs cover them; 27–97% fewer compute units on the ones that
301
+ succeed.
302
+ - Faster: Pubkeys and hashes are ordered eight bytes at a time (`a.compare(b)`, the Merkle proof check). A Marginfi
303
+ balance close, which sorts the account's balances, went from 6,610 to 1,865 compute units. Programs that compare
304
+ keys or hashes build to different binaries: here examples/raydium-cp-swap, raydium-clmm, jito-mev's two
305
+ distribution programs and marginfi.
306
+ - New: an Option argument with a default as a seed, `tag ?? 7n`, is recorded in the IDL as Anchor records
307
+ `tag.unwrap_or(7)`, and `typesol client` and `typesol/testing` derive such PDAs. Fix: `typesol client` refused an IDL
308
+ with such a seed (Marginfi's on-chain one).
309
+
310
+ - Examples: Marginfi's group and bank administration (part 2 of the port, docs/case-study-marginfi.md): eleven
311
+ instructions, from the fee state and groups to adding banks (SPL Token and Token-2022, with or without a seed),
312
+ configuring them (operational states, curves, liquidation fees, the circuit breaker, e-mode checks, frozen banks)
313
+ and accruing interest with the group's, insurance and program fees. Checked against the binary on mainnet
314
+ (test/programs/marginfi_v2.so): the same outcome, account bytes and events on 115 transactions, and on random runs
315
+ (`test/verification/fuzz-marginfi.test.ts`); 27–97% fewer compute units on the ones that succeed.
316
+ - Changed: the creates an instruction's body starts with now run before the other accounts' constraints, as Anchor
317
+ creates `init` accounts first. A transaction that breaks both fails with Anchor's code (Marginfi's fuzzer found one:
318
+ adding a bank at a taken address, signed by someone else). Programs that start with a create and have other
319
+ constraints compile differently: here examples/raydium-cp-swap, raydium-clmm, jito-mev's two distribution programs
320
+ and eleven ports under test/ports/tokens; their tests against the mainnet binaries pass as before.
321
+ - Changed: accounts of a zero-copy type (`@serialization bytemuck`) are checked as Anchor's `AccountLoader` checks
322
+ them: the owner first (3007, also for an account never created, where `Account<T>` gives 3012), then a
323
+ discriminator to read (3001, new) and match (3002), then the size (3003). No other program here has such an account,
324
+ so only examples/marginfi compiles differently from this.
325
+ - New: `Address<InstructionsSysvar, "Sysvar1nstructions1111111111111111111111111">` checks the sysvar's address as
326
+ Anchor's `address = …` constraint does (2012, in constraint order) instead of 3008; another address there is a
327
+ compile error.
328
+
329
+ - Repository: a NOTICE for the third-party material the tests use (Apache-2.0 program binaries in test/programs, with
330
+ the licence text, and the Marginfi and Raydium fixtures); a test that every committed binary is the one SOURCES.md
331
+ records (sha256); `scripts/fetch-programs.sh` reports fetched binaries whose hash differs.
332
+ - New: `f64`, a 64-bit float held as its IEEE bits, for event and account fields (`f64FromBits`, `f64Bits`; the IDL
333
+ says `f64`). No float arithmetic.
334
+ - New: `Option<FixedArray<T, N>>` fields (Anchor's `Option<[u16; 3]>`), readable after narrowing with `.get(i)` or
335
+ copied whole into a `FixedArray` field.
336
+ - New: structs holding Options at any depth (Anchor's `BankConfigOpt`, an `Option<InterestRateConfigOpt>` inside it)
337
+ are Borsh where they travel: in instruction arguments, and in `@layout borsh` events and accounts that hold them.
338
+ Their C layout stays fixed; the IDL describes them as Anchor's. Programs without such structs compile as before.
339
+ - `typesol port`: f64 fields, Borsh events for headers holding Options, data-enum `repr`; Marginfi's whole on-chain
340
+ IDL ports with every type and instruction argument as on chain, apart from seven instructions whose arguments are
341
+ an Option of a struct, an array, bytes or a Vec (not supported yet).
342
+ - Fix: a `Vec<FixedArray<T, N>>` argument (Anchor's `Vec<[u8; 32]>` proof) no longer fails in code generation.
343
+ - The repr(C) offset check applies to bytemuck zero-copy types and what they hold, not to repr(C) structs that only
344
+ travel as Borsh.
345
+
346
+ - Releases: each GitHub Release gets a manifest (`scripts/release-manifest.ts`): compiler and toolchain versions, the
347
+ sha256 of every example's and port's binary, IDL and C, the reference binaries and the test corpus. It also gets the
348
+ previous release's sources built by both packages, with their diff, so "the same binaries" can be checked and
349
+ redone by anyone (docs/testing.md). 0.37.0 → 0.38.0, checked by hand: all 67 programs of the 0.37.0 sources build to
350
+ the same binary and IDL.
351
+ - Examples: examples/marginfi begins a port of Marginfi v2 (mrgnlabs/marginfi-v2 @ c5d440f6, Apache-2.0; on mainnet
352
+ as MFv2hWf3… with the same 124 instructions, version 0.1.12 in its on-chain IDL). This first part has no
353
+ instructions yet: its 255 errors (from the on-chain IDL), its I80F48 fixed-point arithmetic and its 12 zero-copy
354
+ accounts with the 32 types they hold. The arithmetic gives the bits the `fixed` crate (1.28.0) gives, checked
355
+ against vectors that crate wrote (test/fixtures/marginfi/i80f48-oracle) and on random values. The accounts read
356
+ mainnet's group, a bank and the fee state as Anchor decodes them, and the IDL describes all 44 types as the
357
+ on-chain IDL does.
358
+ - New: `/** @code 6200 */` on an error enum member gives it that code, the members after it continuing from there
359
+ (Anchor's `Variant = 200`). `require("…")` errors come after the highest code. `typesol port` keeps an IDL's codes
360
+ this way.
361
+ - New: `/** @repr c */` (`packed`, `align N`; `@repr rust` on enums) and `/** @serialization bytemuck */` put an Anchor
362
+ zero-copy type's repr and serialization in the IDL. An unpacked `@repr c` struct must have its fields where C puts
363
+ them; a field that C would pad is a compile error.
364
+ - New: `/** @bytes */` on an integer field shows it in the IDL as `[u8; N]` (an `i128` for Marginfi's
365
+ `WrappedI80F48 { value: [u8; 16] }`); `/** @idlName _pad0 */` names a field in the IDL where the source cannot (a
366
+ leading underscore); a `key_` or `lamports_` field is `key` / `lamports` in the IDL. `typesol port` writes these
367
+ tags from the IDL, so a ported zero-copy account's IDL is the original's.
368
+ - New: a `loadAccountMut` view declared in a loop body ends with its iteration, so a later iteration may load the
369
+ same account again. `loadAccountMut<Dup<T>>` there also lets a remaining account be passed more than once, one view
370
+ at a time (without `Dup<…>` a repeat is still refused, 2040). Raydium CLMM's `swap_router_base_in` uses it: routes
371
+ back through a pool now run as on mainnet (two more transactions in its differential test). Only programs with
372
+ `loadAccountMut` in a loop compile differently (here examples/airdrop.ts and examples/raydium-clmm).
373
+
374
+ - Tests: random transactions against the mainnet binaries. `test/verification/fuzz-jito.test.ts` drives Jito's three
375
+ MEV programs and their ports through random tips, receiver and builder changes, epochs, roots, Merkle claims and
376
+ closes (with injected faults); Raydium CLMM's differential test adds a random run of swaps, positions and liquidity
377
+ changes. Every step must match the original (outcome, account bytes, events, log lines), with a new seed on every
378
+ run, CI's included (`FUZZ_SEED` reproduces one).
379
+
9
380
  ## 0.38.0 — 2026-11-01
10
381
 
11
382
  Raydium CLMM ported in full, and Jito's three MEV programs ported, each checked against its mainnet binary. The
@@ -21,7 +392,7 @@ same binaries as in 0.37.0.
21
392
  bytes and events, 33–84% fewer compute units.
22
393
  - Examples: examples/jito-mev, ports of Jito's three MEV programs (tip payment, tip distribution, priority fee
23
394
  distribution; all 24 instructions), checked against the mainnet binaries (test/programs/jito_*.so) on 150
24
- transactions: the same outcomes, account bytes, events and log lines, with 58–95% fewer compute units. The tip
395
+ transactions: the same outcomes, account bytes, events and log lines, with 58–79% fewer compute units (up to 95% on refused calls). The tip
25
396
  payment port follows the binary on mainnet, which is the program of Jito's #143 (no `claim_tips`). See
26
397
  docs/case-study-jito-mev.md.
27
398
  - New: a `Seeds<…>` bump stored in a struct field of another account, `"@config.bumps.vault"` (Anchor's
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <h3 align="center">Write Solana programs in TypeScript. Ship native SBF.</h3>
6
6
 
7
7
  <p align="center">
8
- <a href="https://github.com/typesol/typesol/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/typesol/typesol/actions/workflows/ci.yml/badge.svg?branch=main"></a>
8
+ <a href="https://github.com/typesol-lang/typesol/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/typesol-lang/typesol/actions/workflows/ci.yml/badge.svg?branch=main"></a>
9
9
  <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-3178C6"></a>
10
10
  <a href="https://www.npmjs.com/package/@typesol/cli"><img alt="npm version" src="https://img.shields.io/npm/v/@typesol/cli"></a>
11
11
  <img alt="Target: Solana SBF" src="https://img.shields.io/badge/target-Solana%20SBF-14F195">
@@ -173,18 +173,21 @@ existing project: `npm install -D typesol@npm:@typesol/cli`.
173
173
  Deploying again upgrades the program in place. Keep `target/deploy/<name>-keypair.json`: that keypair is your
174
174
  program's address.
175
175
 
176
- Coming from Anchor: [docs/migrate-from-anchor.md](docs/migrate-from-anchor.md) maps every construct, `typesol port`
177
- starts from your program's IDL, and [docs/case-study-escrow.md](docs/case-study-escrow.md) follows one complete Anchor
178
- program through the port; [docs/case-study-multisig.md](docs/case-study-multisig.md) ports coral-xyz/multisig and
179
- checks it against the binary deployed on mainnet (same outcomes and account bytes; 66–84% fewer compute units), and
180
- [docs/case-study-raydium-cp-swap.md](docs/case-study-raydium-cp-swap.md) does the same for Raydium CP-Swap's swaps and liquidity
181
- (pool creation included: same outcomes, account bytes and events on 70 transactions; 45–79% fewer compute units), and
182
- [docs/case-study-raydium-clmm.md](docs/case-study-raydium-clmm.md) for all 37 instructions of Raydium CLMM
183
- (pools, positions, swaps and routes, limit orders, rewards, admin: the same on 300 transactions; 33–84% fewer
184
- compute units), and [docs/case-study-jito-mev.md](docs/case-study-jito-mev.md) for Jito's three MEV programs (tip
185
- payment, tip distribution with Merkle claims, priority fee distribution: the same on 150 transactions; 58–95% fewer
186
- compute units). Tests use `typesol/testing` (accounts by name, plain values; [docs/test-your-program.md](docs/test-your-program.md)). To go to
187
- mainnet (wallet, cost, deploy, IDL, verification), follow [docs/mainnet.md](docs/mainnet.md).
176
+ **Your first change.** Open `programs/counter.ts`, add an instruction (say `decrement`, with
177
+ `require(counter.count >= 1n, …)` before `counter.count -= 1n`), call it from `tests/counter.test.ts` and run `npm test`.
178
+ If the build refuses something, the error points at the line and, for the usual first mistakes (`1` instead of `1n`,
179
+ `console.log`, a missing import, `async`), adds a `hint:` with what to write instead; your editor shows the same.
180
+
181
+ **Where next**
182
+ - The language, every type and built-in: [docs/language.md](docs/language.md).
183
+ - Tests with `typesol/testing` (accounts by name, plain values): [docs/test-your-program.md](docs/test-your-program.md).
184
+ - Coming from Anchor: [docs/migrate-from-anchor.md](docs/migrate-from-anchor.md) maps every construct, and
185
+ `typesol port` starts from your program's IDL; [docs/case-study-escrow.md](docs/case-study-escrow.md) follows one
186
+ program through the port.
187
+ - 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).
190
+ - To mainnet (wallet, cost, deploy, IDL, verification): [docs/mainnet.md](docs/mainnet.md).
188
191
 
189
192
  ## How it works
190
193
 
@@ -196,7 +199,7 @@ counter.ts ─▶ tsc typecheck ─▶ subset check ─▶ C + typesol_rt.h ─
196
199
  1. **Typecheck.** The TypeScript compiler checks your code against [`lib/typesol.d.ts`](lib/typesol.d.ts), which
197
200
  declares every TypeSOL type and built-in.
198
201
  2. **Subset check.** TypeSOL rejects anything outside the language (floats, classes, `any`, foreign imports)
199
- with a `file:line:col` diagnostic. Nothing is half-supported.
202
+ with a `file:line:col` diagnostic, and a hint for the usual first mistakes. Nothing is half-supported.
200
203
  3. **Lower.** Instruction bodies become C. Account validation, checked arithmetic, Borsh encoding and CPI plumbing
201
204
  come from [`runtime/typesol_rt.h`](runtime/typesol_rt.h).
202
205
  4. **Build.** The Agave platform-tools `clang` and `ld.lld` produce the `.so` (SBPF v0 by default; v1 and v2 with
@@ -211,8 +214,8 @@ Runtime failures point back to your source: `Error 6000 Unauthorized (counter.ts
211
214
  | --- | --- |
212
215
  | **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) |
213
216
  | **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 |
214
- | **Data** | `u8`…`u128`, `i8`…`i128`, `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 |
215
- | **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), list callbacks (`some`, `find`, `reduce`, …) across multiple files |
217
+ | **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 |
218
+ | **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 |
216
219
  | **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`) |
217
220
  | **Events** | `emit` (log-based) and `emitCpi` (Anchor `emit_cpi!`, through a self-CPI) |
218
221
  | **Crypto & oracles** | `sha256`, `keccak256`, Merkle proofs, Ed25519 and secp256k1 signature checks, Pyth pull oracle, Switchboard feeds and verifiable randomness |
@@ -255,7 +258,7 @@ Subpath exports: `typesol/compiler`, `typesol/workspace`, `typesol/cpi`, `typeso
255
258
  The same counter, vault and escrow programs, written four ways. All four use the same instruction encoding, account
256
259
  layout and checks. They get identical transactions in LiteSVM and must end in identical account state. The table
257
260
  shows mean compute units per call (generated by `scripts/readme-bench.ts` from the benchmark run). The programs,
258
- scenarios and harness are in [typesol/benchmarks](https://github.com/typesol/benchmarks), which pins the compiler and
261
+ scenarios and harness are in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks), which pins the compiler and
259
262
  toolchain and records them with every result:
260
263
 
261
264
  <!-- bench:table -->
@@ -286,7 +289,7 @@ The official escrow ([tokens/escrow](https://github.com/solana-developers/progra
286
289
  deployed to Solana mainnet-beta in all four versions and called with the same mints, amounts and accounts, one
287
290
  instruction per transaction. The TypeSOL program was upgraded in place to 0.25.0 on 2026-10-29; the others are as first
288
291
  deployed on 2026-10-27. Each figure is the compute units of that transaction, linked to Solscan; the lowest per row is
289
- in bold. The deployed programs match these builds byte for byte (`typesol verify` for TypeSOL), and the TypeSOL
292
+ in bold. The deployed programs match their builds byte for byte (`typesol verify` for TypeSOL; that is the 0.25.0 build, not the current release), and the TypeSOL
290
293
  program's IDL is published on chain with `typesol idl publish`.
291
294
 
292
295
  | Transaction | TypeSOL | Pinocchio | Native Rust | Anchor |
@@ -304,7 +307,7 @@ version (13,585 to 22,585 CU of the make_offers above); programs that check the
304
307
  take_offer and refund_offer vary with it too. The escrow program's own part is steadier: TypeSOL's make_offer spent
305
308
  6,620 CU of its own on both offers. The Pinocchio version takes the offer PDA's bump from the client instead of
306
309
  searching for it. Mainnet figures differ from the LiteSVM means above. Every run, including the one before the
307
- upgrade, is in [typesol/benchmarks](https://github.com/typesol/benchmarks) (`results/`).
310
+ upgrade, is in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) (`results/`).
308
311
 
309
312
  ## How it is tested
310
313
 
@@ -333,15 +336,29 @@ Details are in [docs/testing.md](docs/testing.md).
333
336
  | [`relay.ts`](examples/relay.ts), [`caller.ts`](examples/caller.ts) | generic `invoke`, PDA-signed transfers, return data |
334
337
  | [`profiles.ts`](examples/profiles.ts) | nested structs, FixedString, events |
335
338
  | [`orderbook/`](examples/orderbook) | a three-file, 28 KiB zero-copy limit order book |
336
- | [`raydium-cp-swap/`](examples/raydium-cp-swap) | Raydium CP-Swap's trading core: constant-product swaps, LP deposits and withdrawals, Token-2022 transfer fees, a price oracle |
337
- | [`raydium-clmm/`](examples/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 |
338
- | [`jito-mev/`](examples/jito-mev) | Jito's tip payment, tip distribution and priority fee distribution: tips paid out per leader, Merkle-proof claims, epochs and expiry |
339
- | [`multisig.ts`](examples/multisig.ts) | coral-xyz/multisig: stored instructions run with `invokeInstruction`, a PDA signing, Anchor's Borsh accounts |
339
+
340
+ ### Showcase: ports checked against mainnet
341
+
342
+ [`showcase/`](showcase) holds programs ported from Anchor and checked against the binaries deployed on mainnet (same
343
+ outcomes, account bytes and events; [`showcase/test`](showcase/test)), and the ports of all 46
344
+ [solana-developers/program-examples](showcase/program-examples/README.md).
345
+ Case studies: [Marginfi v2](docs/case-study-marginfi.md), [Raydium AMM v4](docs/case-study-raydium-amm.md), [Raydium CLMM](docs/case-study-raydium-clmm.md),
346
+ [Raydium CP-Swap](docs/case-study-raydium-cp-swap.md), [Jito MEV](docs/case-study-jito-mev.md),
347
+ [coral-xyz/multisig](docs/case-study-multisig.md), [an Anchor escrow](docs/case-study-escrow.md).
348
+
349
+ | | |
350
+ | --- | --- |
351
+ | [`raydium-cp-swap/`](showcase/mainnet/raydium-cp-swap) | Raydium CP-Swap's trading core: constant-product swaps, LP deposits and withdrawals, Token-2022 transfer fees, a price oracle |
352
+ | [`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 |
353
+ | [`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 |
354
+ | [`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 |
355
+ | [`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 |
356
+ | [`multisig.ts`](showcase/mainnet/multisig/multisig.ts) | coral-xyz/multisig: stored instructions run with `invokeInstruction`, a PDA signing, Anchor's Borsh accounts |
340
357
 
341
358
  ## Status
342
359
 
343
360
  **TypeSOL is pre-1.0.** Releases follow the organization's
344
- [versioning policy](https://github.com/typesol/.github/blob/main/VERSIONING.md); [CHANGELOG.md](CHANGELOG.md) lists every
361
+ [versioning policy](https://github.com/typesol-lang/.github/blob/main/VERSIONING.md); [CHANGELOG.md](CHANGELOG.md) lists every
345
362
  change.
346
363
  - The compiler, runtime and tooling have been through internal security reviews and are covered by the tests above.
347
364
  - They have **not been audited by an independent firm**. Do not put significant value behind programs built with
@@ -370,5 +387,5 @@ built-in, a constraint or an error code. Then read [CONTRIBUTING.md](CONTRIBUTIN
370
387
 
371
388
  ## License
372
389
 
373
- [MIT](LICENSE). Third-party program binaries used by the tests are listed with their licenses in
374
- [test/programs/SOURCES.md](test/programs/SOURCES.md).
390
+ [MIT](LICENSE). The tests also use third-party program binaries and data, none of it in the npm package: see
391
+ [NOTICE](NOTICE) and [test/programs/SOURCES.md](test/programs/SOURCES.md).
package/SECURITY.md CHANGED
@@ -15,7 +15,7 @@ TypeSOL generates programs that hold funds. Treat it accordingly.
15
15
  ## Reporting a vulnerability
16
16
 
17
17
  Please report privately, not in a public issue: use the **"Report a vulnerability"** button on
18
- https://github.com/typesol/typesol/security (GitHub private vulnerability reporting). Include a minimal TypeSOL program and the steps that show the problem.
18
+ https://github.com/typesol-lang/typesol/security (GitHub private vulnerability reporting). Include a minimal TypeSOL program and the steps that show the problem.
19
19
  We aim to acknowledge reports within 3 days and to ship a fix or mitigation for confirmed issues as fast as
20
20
  their severity requires, with credit unless you prefer otherwise.
21
21
 
package/dist/cli.js CHANGED
@@ -99,7 +99,8 @@ const COMMANDS = {
99
99
  (rel === "." ? "" : ` cd ${rel}\n`) +
100
100
  ` npm install\n` +
101
101
  ` npm test # builds ${name} and runs its test in LiteSVM, a Solana runtime in-process\n` +
102
- ` npx typesol doctor # checks the toolchain, keypair and RPC before a deploy`);
102
+ ` npx typesol doctor # checks the toolchain, keypair and RPC before a deploy` +
103
+ (template === "counter" ? `\n\n other starters: typesol init <dir> --template vault (SOL at a PDA) or --template escrow (SPL token escrow)` : ""));
103
104
  return 0;
104
105
  },
105
106
  },
@@ -178,7 +179,7 @@ const COMMANDS = {
178
179
  throw e;
179
180
  diagnostics.push(...e.diagnostics);
180
181
  if (!v.json)
181
- console.error(`${name}:\n${e.message}`);
182
+ console.error(`${name}:\n${showDiagnostics(e.diagnostics)}`);
182
183
  }
183
184
  }
184
185
  if (v.json)
@@ -552,6 +553,39 @@ const USAGE = `Usage:\n${Object.values(COMMANDS)
552
553
  function log(s) {
553
554
  console.log(s);
554
555
  }
556
+ /**
557
+ * Diagnostics for a terminal: the path relative to the working directory, the source line with the problem marked, and
558
+ * the rest of the message (a hint, TypeScript's details) under it. `--json` and CompileError.message keep the plain form.
559
+ */
560
+ function showDiagnostics(diagnostics, sources) {
561
+ const cache = new Map();
562
+ const linesOf = (file) => {
563
+ if (!cache.has(file)) {
564
+ let text = sources?.get(file);
565
+ if (text === undefined && existsSync(file))
566
+ text = readFileSync(file, "utf8");
567
+ cache.set(file, text?.split(/\r?\n/));
568
+ }
569
+ return cache.get(file);
570
+ };
571
+ return diagnostics
572
+ .map((d) => {
573
+ const rel = path.relative(process.cwd(), d.file);
574
+ const shown = rel && !rel.startsWith("..") && !path.isAbsolute(rel) ? rel : d.file;
575
+ const [first, ...rest] = d.message.split("\n");
576
+ const out = [`${shown}:${d.line}:${d.column} - error: ${first}`];
577
+ const src = linesOf(d.file)?.[d.line - 1];
578
+ if (src !== undefined) {
579
+ const gutter = String(d.line);
580
+ const width = Math.max(1, Math.min(d.length ?? 1, src.length - (d.column - 1)));
581
+ out.push(` ${gutter} | ${src}`, ` ${" ".repeat(gutter.length)} | ${" ".repeat(Math.max(0, d.column - 1))}${"^".repeat(width)}`);
582
+ }
583
+ for (const r of rest)
584
+ out.push(` ${r}`);
585
+ return out.join("\n");
586
+ })
587
+ .join("\n\n");
588
+ }
555
589
  function mustExist(file) {
556
590
  if (!existsSync(file))
557
591
  throw new UsageError(`${file} does not exist`);
@@ -645,7 +679,7 @@ try {
645
679
  }
646
680
  catch (e) {
647
681
  if (e instanceof CompileError) {
648
- console.error(e.message);
682
+ console.error(showDiagnostics(e.diagnostics));
649
683
  console.error(`\n${e.diagnostics.length} error(s)`);
650
684
  }
651
685
  else