@typesol/cli 0.47.0 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +299 -0
- package/NOTICE +17 -0
- package/README.md +106 -37
- package/SECURITY.md +5 -0
- package/dist/compiler/emit/base.d.ts +12 -4
- package/dist/compiler/emit/base.js +19 -5
- package/dist/compiler/emit/calls.js +59 -1
- package/dist/compiler/emit/cpi.js +3 -1
- package/dist/compiler/emit/expressions.js +3 -1
- package/dist/compiler/emit/function.js +7 -2
- package/dist/compiler/emit/program.js +9 -4
- package/dist/compiler/emit/statements.d.ts +29 -2
- package/dist/compiler/emit/statements.js +149 -6
- package/dist/compiler/emit/storage.js +8 -3
- package/dist/compiler/emit/token.js +18 -1
- package/dist/compiler/hints.js +3 -0
- package/dist/compiler/toolchain.js +1 -0
- package/dist/idl-coder.d.ts +21 -2
- package/dist/idl-coder.js +42 -4
- package/dist/testing.d.ts +14 -3
- package/dist/testing.js +87 -17
- package/docker/deps/0.48.0.lock.json +1206 -0
- package/docker/deps/0.49.0.lock.json +1206 -0
- package/docs/architecture.md +2 -2
- package/docs/audit.md +31 -15
- package/docs/case-study-escrow.md +7 -5
- package/docs/case-study-marginfi.md +15 -2
- package/docs/case-study-multisig.md +2 -1
- package/docs/case-study-raydium-amm.md +2 -1
- package/docs/case-study-spl-stake-pool.md +4 -3
- package/docs/language-accounts.md +5 -6
- package/docs/language-basics.md +2 -1
- package/docs/language-builtins.md +5 -1
- package/docs/language-chain.md +13 -1
- package/docs/language-cpi.md +26 -0
- package/docs/language-errors-events.md +16 -1
- package/docs/language-native.md +23 -3
- package/docs/language-statements.md +4 -2
- package/docs/language.md +2 -2
- package/docs/mainnet.md +1 -1
- package/docs/runtime.md +7 -0
- package/docs/security-model.md +11 -4
- package/docs/stability.md +9 -4
- package/docs/test-your-program.md +43 -4
- package/docs/testing.md +16 -4
- package/docs/troubleshooting.md +1 -1
- package/lib/typesol.d.ts +46 -1
- package/llms-full.txt +164 -34
- package/llms.txt +2 -1
- package/package.json +3 -3
- package/releases/0.47.0.json +837 -0
- package/releases/0.48.0.json +847 -0
- package/runtime/typesol_rt.h +276 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,305 @@ codes, and says so here.
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
## 0.49.0 — 2026-11-16
|
|
10
|
+
|
|
11
|
+
A minor release: it adds a port of Percolator v12.20 (all 27 instructions, compared with the immutable mainnet build)
|
|
12
|
+
and the built-ins it needed (`log64`, `zeroData`, `PANIC_STYLE = "solana-1.18"`, `executable` on a remaining account),
|
|
13
|
+
changes lamport writes on remaining accounts under `NATIVE_ACCOUNT_WRITES`, and fixes two example programs
|
|
14
|
+
(`examples/airdrop.ts`, `examples/minter.ts`) that let any caller take an authority. Programs that compiled with 0.48.0
|
|
15
|
+
and still compile build to the same bytes, except those two examples, whose sources changed.
|
|
16
|
+
|
|
17
|
+
- Changed: under `NATIVE_ACCOUNT_WRITES`, a write to a remaining account's `.lamports` is a native program's
|
|
18
|
+
`**a.lamports.borrow_mut() = v`: no writability check (3006) and no refusal of an account passed more than once
|
|
19
|
+
(2040); an account passed twice is one record, and the runtime judges the change when the instruction ends. Programs
|
|
20
|
+
without the flag build as before, and so does every program in the golden manifest
|
|
21
|
+
(test/language/native-lamports.test.ts; docs/language-native.md).
|
|
22
|
+
- Showcase, Percolator: mutation fuzzers against the mainnet binary (`showcase/test/percolator-mutate-*.test.ts`):
|
|
23
|
+
the account list, the instruction data, the environment (several instructions per transaction, a relay at stack
|
|
24
|
+
height 2, low compute-unit limits, Clock and oracle extremes) and the slab's every field, from valid transactions of
|
|
25
|
+
all 27 instructions in eleven market states, each compared byte for byte; and the failure sites a review found
|
|
26
|
+
without a test, reached on purpose (`percolator-sites.test.ts`). Four differences they found are fixed, each kept as
|
|
27
|
+
a named case (`percolator-regressions.test.ts`): CloseSlab with the slab or the admin again in its unused fifth
|
|
28
|
+
position (the port failed with 2040, the original succeeds), a matcher shrinking its context below 64 bytes during
|
|
29
|
+
TradeCpi (InvalidAccountData before any field is read), a TradeCpi tail long enough to exhaust the original's 32 KiB
|
|
30
|
+
heap before the matcher call (the allocator's "out of memory" and abort, now reproduced from the same byte count),
|
|
31
|
+
and the funding rate of a config only patching can make (`i128::clamp`'s assertion panic and `saturating_mul`).
|
|
32
|
+
SetOraclePriceCap changes the config in place (on a Hyperp market it had cost about as much as the original's).
|
|
33
|
+
- Showcase, Percolator: the compute-unit tables re-measured on the current build (363,392 bytes): on the same
|
|
34
|
+
transactions every instruction's mean and largest figure is the earlier build's or lower (SetOraclePriceCap 606 on
|
|
35
|
+
average, from 1,696), each keeper crank of the account-count table costs one unit more, and all stay below the
|
|
36
|
+
original. New differential tests: TradeCpi's tail with signers and writable accounts as the matcher sees them, the
|
|
37
|
+
per-side cap on active positions with real trades, the ADL edges (K without headroom, precision exhausted, a crank
|
|
38
|
+
stopping on a pending reset; the first two only on a slab written in, as no instruction reaches them), and TradeCpi's
|
|
39
|
+
path after the matcher call on nearly full heaps, through a test matcher that takes any tail. One difference found
|
|
40
|
+
and pinned: a panic after the call where the original's heap can no longer hold the formatted panic line (a tail at
|
|
41
|
+
the last length or two the heap holds and a slab written in) logs the allocator's out-of-memory error in the
|
|
42
|
+
original and the panic line in the port; the outcome and every account are the same.
|
|
43
|
+
- Showcase, Percolator: mutation testing of the differential tests. 196 hand-chosen mutants of the port's source (every
|
|
44
|
+
file, 63 in rarely-run paths such as ADL, bad debt past insurance, the resolved wind-down, Hyperp and Chainlink), each
|
|
45
|
+
rebuilt and run against the sixteen test files: 140 killed as the tests stood, 22 equivalent (the reasons in
|
|
46
|
+
the port README), 34 gaps, each now covered by a new differential test in the fitting file and killed (boundaries hit
|
|
47
|
+
exactly, such as the margins, the catch-up envelopes, the deviation band and the deposit cap, and states only a
|
|
48
|
+
written slab has). The new tests found no difference from the mainnet binary. The default run's count now covers all
|
|
49
|
+
sixteen files: 139,185 compared transactions, 33,590 successful under both.
|
|
50
|
+
|
|
51
|
+
- Changed: an account of another type passed where a remaining account or an `AccountInfo` is taken (`programAt`,
|
|
52
|
+
`sysvarAt`, `zeroData`) is now refused by TypeScript (a `RemainingAccount` has `executable`), with the hint "pass a
|
|
53
|
+
remaining account (remainingAccounts().get(i)) or an AccountInfo parameter; a declared parameter of a program or
|
|
54
|
+
sysvar type is used as it is"; the compiler's own message said the same before.
|
|
55
|
+
- Added: `log64(a, b, c, d, e)`, Rust's `sol_log_64` (the runtime writes the five u64s as lowercase hex on one line);
|
|
56
|
+
`zeroData(account, offset, length)`, a memset of account data by the syscall, as a native program's
|
|
57
|
+
`for b in data.iter_mut() { *b = 0 }` compiles (about constant compute units for 1.5 MB); and
|
|
58
|
+
`PANIC_STYLE = "solana-1.18"`, panics logged as solana-program 1.18's handler logs them since rustc 1.73
|
|
59
|
+
(`panicked at <file>:<line>:<col>:` and the message on the next line, then abort). The lines are checked against
|
|
60
|
+
Percolator v12.20's mainnet binary (test/language/native-log64-zero.test.ts; docs/language-native.md). Existing
|
|
61
|
+
programs build to the same bytes.
|
|
62
|
+
- Showcase: the first stage of a port of Percolator v12.20, `showcase/mainnet/percolator/` (Apache-2.0; educational,
|
|
63
|
+
not audited, not for real funds, as the original says), the immutable mainnet program
|
|
64
|
+
`BCGNFw6vDinWTF9AybAbi8vr69gx5nk5w8o2vEWgpsiw` built from aeyakovenko/percolator-prog `06f86fb` and the engine
|
|
65
|
+
aeyakovenko/percolator `3f55f87` (sha256 `502088e9…cc93`, 395,368 bytes; fetched by `scripts/fetch-programs.sh`, not
|
|
66
|
+
kept here). This stage has 15 of its 27 instructions (market creation and configuration, the authorities, account
|
|
67
|
+
creation, deposits, withdrawals, settles, closes on live markets, reclaims, insurance top-ups, fee credits, CloseSlab)
|
|
68
|
+
and the foundation the rest builds on: the 1,525,624-byte slab byte for byte (u128 aligned to 8, as the SBF binary
|
|
69
|
+
lays it out), the engine's 256-bit arithmetic, the oracle readers, accrual, warm-up and fees. Each transaction goes to
|
|
70
|
+
the port and to the mainnet binary, which must agree on outcome, error code, log lines, inner instructions, return
|
|
71
|
+
data and every account's bytes, in five test files and a seeded fuzz of account sequences (README there).
|
|
72
|
+
- Added: `executable` on a remaining account (`rest.get(i).executable`, Rust's `AccountInfo::executable`), as a native
|
|
73
|
+
program checks a program passed among its accounts before calling it (test/language/remaining-executable.test.ts;
|
|
74
|
+
docs/language-accounts.md). Existing programs build to the same bytes.
|
|
75
|
+
- Showcase: the second stage of the Percolator v12.20 port: TradeNoCpi, TradeCpi and ConvertReleasedPnl (18 of 27
|
|
76
|
+
instructions), with the engine's trade (trade PnL, positions attached at the side's indices, the open-interest
|
|
77
|
+
decomposition, trading fees, the margin rules, warm-up of trade profit) and the conversion of released PnL with its
|
|
78
|
+
haircut. TradeCpi calls a matcher: no build of the author's is deployed for v12.20, so the tests run a TypeSOL port of
|
|
79
|
+
aeyakovenko/percolator-match 199b139 (Apache-2.0, a test fixture) under both the mainnet binary and the port. Tests
|
|
80
|
+
that wrote positions into the slab now trade; a fuzz of trade sequences between many users and LPs runs against the
|
|
81
|
+
binary. The port spends fewer compute units than the original on every successful transaction measured, SettleAccount
|
|
82
|
+
included (it no longer copies the 400-byte config twice where nothing reads it in between, and zeroes its instruction
|
|
83
|
+
context with the memset syscall). verify_token_program now checks the token program is executable, as the original
|
|
84
|
+
does.
|
|
85
|
+
- Showcase: the third stage of the Percolator v12.20 port: KeeperCrank, LiquidateAtOracle and CatchupAccrue (21 of 27
|
|
86
|
+
instructions), with the engine's liquidation (full close and the crank's exact partial, the liquidation fee, bad
|
|
87
|
+
debt), `enqueue_adl` (insurance first, then the loss written into the opposite side's K, A shrunk pro rata, drain-only
|
|
88
|
+
sides, side resets with stale accounts settled at the frozen indices), the crank's candidate handling and hint
|
|
89
|
+
validation, the maintenance-fee sweep with its cursor and dust reclaim, the crank reward and the risk buffer's upkeep,
|
|
90
|
+
and complete and partial catch-ups of the market clock. Tests that wrote drain-only and reset-pending sides, a flat
|
|
91
|
+
account with a loss past its capital and the sweep's fee debt into the slab now reach them with liquidations and
|
|
92
|
+
cranks; a second fuzz walk (leveraged trades, crashes, liquidations, cranks) socialises losses and runs side resets
|
|
93
|
+
to their end against the binary. KeeperCrank's compute units are measured at 2 to 4,096 accounts: the port completes
|
|
94
|
+
every crank the original does within the same limit, and 64 liquidations in one crank, which exceed the original's
|
|
95
|
+
1.4M units, in about 660,000. The port spends fewer compute units than the original on every successful transaction
|
|
96
|
+
measured (18,713 in the two fuzz walks).
|
|
97
|
+
- Showcase: the fourth stage completes the Percolator v12.20 port (27 of 27 instructions): ResolveMarket,
|
|
98
|
+
ResolvePermissionless, ForceCloseResolved, AdminForceCloseAccount, CloseAccount's resolved arm, WithdrawInsurance and
|
|
99
|
+
WithdrawInsuranceLimited, with the engine's resolution (the ordinary arm with its catch-up and deviation band, the
|
|
100
|
+
degenerate arm at the last price for a dead oracle, a silent Hyperp mark or the hard timeout, terminal K deltas kept
|
|
101
|
+
apart from K, every position stale under a new epoch), the reconciliation of resolved accounts, terminal readiness,
|
|
102
|
+
the payout haircut snapshot and the terminal close (fee debt forgiven, the surplus swept into insurance), and the
|
|
103
|
+
bounded insurance withdrawals (bps cap, 10-unit floor, cooldown). Tests that wrote a resolved market into the slab
|
|
104
|
+
now resolve it, and CloseSlab's insurance and stranded-token cases come from real instructions; only states no
|
|
105
|
+
instruction can make are still written in (README there). Both fuzz walks now end each market's life: resolution by
|
|
106
|
+
the admin or by anyone, every account closed out in random order, the insurance withdrawn, the slab closed, and the
|
|
107
|
+
vault and every token account compared at the end (80 full life cycles in a 40-seed run of each walk). The port spends fewer compute units than
|
|
108
|
+
the original on every successful transaction measured (20,225 in the two fuzz walks) and its binary is
|
|
109
|
+
360,248 bytes against 395,368 (363,392 bytes after the later fixes).
|
|
110
|
+
- Showcase: the Percolator author's own LiteSVM test suite (aeyakovenko/percolator-prog `06f86fb`, engine `3f55f87`)
|
|
111
|
+
run unchanged against the mainnet binary and against the TypeSOL port: 660 tests pass and 11 are ignored under both,
|
|
112
|
+
with the same outcome for every test (609 of them run the program; the rest test the Rust crates on the host); the
|
|
113
|
+
11 ignored ones, run too, also agree (4 pass, 7 fail at the same assertions). The TradeCpi tests use the TypeSOL
|
|
114
|
+
matcher fixture under both. `scripts/percolator-author-suite.sh` reproduces it (host build only, downloads nothing);
|
|
115
|
+
counts per file and the author's compute-unit benchmark in the port README.
|
|
116
|
+
- Showcase: the Percolator port's checks made stricter, and what they found. Every test now fails a successful
|
|
117
|
+
transaction with a Percolator instruction at the top level unless the port used fewer compute units than the
|
|
118
|
+
original (the differential harness asserts it for every test file, the keeper-crank measurements included; only the
|
|
119
|
+
matcher's own Init and SPL Token transfers, identified by program id, are exempt). A new fuzz walk runs whole market
|
|
120
|
+
life cycles on Chainlink feeds, inverted markets, Pyth feeds at other exponents with the confidence at its limit, and
|
|
121
|
+
Hyperp markets (40 life cycles in a 10-seed run, no divergence). A test matcher logs the slab as it stands during
|
|
122
|
+
TradeCpi's call (the same in both). Two
|
|
123
|
+
divergences found and fixed in the port: the slab passed again where the original holds its mutable borrow across an
|
|
124
|
+
SPL Token call (a user or admin signing with the slab's keypair, or the slab as CloseSlab's vault authority) failed
|
|
125
|
+
the original with AccountBorrowFailed and succeeded in the port; and the trade's per-side position cap, which the
|
|
126
|
+
original counts in i64, gave another error for counts of 2^63 and more (a patched slab only). One difference on a
|
|
127
|
+
patched slab remains and is pinned in a test (a free-list index past the 4,096 slots: Rust's bounds-check panic
|
|
128
|
+
against TypeSOL's). `scripts/percolator-author-suite.sh` now fails on a test file that does not build or run, on
|
|
129
|
+
totals other than the recorded 671 / 660 / 0 / 11, and on test names that differ between the two runs.
|
|
130
|
+
|
|
131
|
+
- Fixed: `examples/airdrop.ts` let the admin of any pot award points to any `Member`: anyone could set up a pot of
|
|
132
|
+
their own and pass other pots' members to `award`. A member now records its pot (`Member.pot`, PDA
|
|
133
|
+
`["member", pot, owner]`, `join` takes the pot), and `award` refuses a member of another pot (`WrongPot`, 6002).
|
|
134
|
+
- Fixed: `examples/minter.ts` let anyone set up the config of any mint, choosing its admin and cap, for example before
|
|
135
|
+
the mint's owner did. `setup` now takes the mint's current mint authority as the signer (`HasOne<Mut<Mint>,
|
|
136
|
+
"mintAuthority">`, 2016), makes it the admin and moves the mint authority to the config PDA in the same instruction,
|
|
137
|
+
with the token program as a new account. Both examples' binaries and IDLs change; neither is in
|
|
138
|
+
`test/golden/binaries.json`. Tests: test/examples/airdrop.test.ts, test/examples/minter.test.ts (the attacks fail,
|
|
139
|
+
the honest paths work).
|
|
140
|
+
- Docs: the `grow` example of docs/language-accounts.md let anyone resize another user's account; it now takes the
|
|
141
|
+
log's owner (`HasOne`).
|
|
142
|
+
- Docs: claims narrowed to what the tests and benchmarks show. The ports: the same outcome, events, return data and
|
|
143
|
+
account bytes on every compared transaction, and the same error codes and log lines except where each case study
|
|
144
|
+
says (Anchor error-message text, panics reported as numbered errors, Marginfi's informational `msg!` lines, CLMM's
|
|
145
|
+
reward-mint order); Phoenix, Raydium AMM v4, SPL Stake Pool and Percolator match every log line. Compute units:
|
|
146
|
+
fewer than native Rust on every instruction measured, fewer than Pinocchio on counter, vault and escrow, and more
|
|
147
|
+
than Pinocchio on 13 of the 26 instructions of the official examples (a sentence `scripts/readme-bench.ts` now
|
|
148
|
+
writes from `official`). Review status: 0.45.0 to 0.48.0 and the unreleased work have had no security review (README,
|
|
149
|
+
SECURITY.md, docs/audit.md, docs/security-model.md), `runtime/typesol_builtins.c` is in the audit scope table and in
|
|
150
|
+
docs/runtime.md, and `EVENT_AUTHORITY_CHECK` is listed as experimental and in the `emitCpi` guarantee. Transaction
|
|
151
|
+
counts are what a default run compares, with breakdowns per file: Marginfi 2,321 (it said 2,081), Raydium AMM v4 144
|
|
152
|
+
with 60 random steps (it said 484, at 400 steps), SPL Stake Pool 2,107 in five files (it said six), coral-xyz/multisig
|
|
153
|
+
55 (it said 52), Percolator 139,185 in its sixteen files, 3,711 of them in its fixed-seed walks and 128,320 from its
|
|
154
|
+
mutation fuzzers (it said 6,028, the first ten files). The cross-host measurement is the one made with
|
|
155
|
+
0.45.0 over the 76 programs of its sources; Meteora DBC and Percolator are not in `test/golden/binaries.json`. Also:
|
|
156
|
+
every fuzzer and how it is seeded (docs/testing.md, docs/audit.md), the manifest's `showcase/mainnet` programs and the
|
|
157
|
+
release record's `"tests"` field, what `pnpm fetch:programs` fetches, the mainnet escrow as a benchmark record and
|
|
158
|
+
what its make_offer spends in the ATA program, the escrow case study's figures from the 0.48.0 run, the licence of the
|
|
159
|
+
Meteora port's tests and fixtures, and `llms.txt` listing every port. The destructuring example of
|
|
160
|
+
docs/language-statements.md let anyone overwrite another player's account; it now requires its owner's signature.
|
|
161
|
+
- Showcase: `showcase/mainnet/meteora-dbc/README.md` describes the finished port (released in stages in 0.48.0): Meteora
|
|
162
|
+
Dynamic Bonding Curve 0.2.2, all 35 instructions, with its migrations into DAMM v1 and DAMM v2, checked against the
|
|
163
|
+
mainnet binary on outcome, error code, account bytes, inner instructions, events and return data (log text and
|
|
164
|
+
compute units not compared). The port, its tests (`showcase/test/meteora-dbc*.ts`) and their fixtures
|
|
165
|
+
(`showcase/test/fixtures/meteora-dbc/`) are under Meteora's Non-commercial Licence (NOTICE), which README.md and
|
|
166
|
+
LICENSE now say.
|
|
167
|
+
|
|
168
|
+
## 0.48.0 — 2026-11-14
|
|
169
|
+
|
|
170
|
+
A minor release: it adds three built-ins (`transferCheckedWithHook`, the processed sibling instructions,
|
|
171
|
+
`EVENT_AUTHORITY_CHECK`), refuses an unused result of a helper that returns a proof or signature check, and makes
|
|
172
|
+
`typesol/testing` refuse missing and misspelt arguments and decode events itself. Programs that compiled with 0.47.0
|
|
173
|
+
and still compile build to the same bytes.
|
|
174
|
+
|
|
175
|
+
- Added: `export const EVENT_AUTHORITY_CHECK = "address"` checks `emitCpi`'s accounts as Anchor 1.x's `#[event_cpi]`
|
|
176
|
+
does: the event authority by address among the constraints (ConstraintAddress, 2012, after the accounts load and the
|
|
177
|
+
creates run) instead of by seeds when it loads (2006), and the `SelfProgram` account not at all (the self-CPI names
|
|
178
|
+
this program's id; an instruction that emits then fails in the runtime, MissingAccount, when this program is not among
|
|
179
|
+
its accounts, as Anchor's does). Programs without the constant build to the same bytes: the 76 programs of
|
|
180
|
+
`scripts/release-manifest.ts` other than the new port build identically with and without this change
|
|
181
|
+
(test/language/event-authority-check.test.ts; docs/language-errors-events.md).
|
|
182
|
+
- Added: `tokenProgram.transferCheckedWithHook(from, mint, to, authority, amount, hookAccounts, signerSeeds?)`, a
|
|
183
|
+
TransferChecked by CPI of a Token-2022 mint with a transfer hook: the hook's extra accounts are resolved among
|
|
184
|
+
`hookAccounts` (the remaining accounts or a slice of them) and appended with the validation account and the hook
|
|
185
|
+
program, as spl-transfer-hook-interface 2.1's `add_extra_accounts_for_execute_cpi` (with spl-tlv-account-resolution
|
|
186
|
+
0.11) does on chain: every kind of extra account meta, the de-escalation of writable flags, and the same refusals and
|
|
187
|
+
error codes. A mint without a hook gets a plain TransferChecked (test/language/transfer-hook-cpi.test.ts;
|
|
188
|
+
showcase/test/meteora-dbc-hook.test.ts compares it with Meteora's Rust program; docs/language-cpi.md). Existing
|
|
189
|
+
programs build to the same bytes (the 76 programs of `scripts/release-manifest.ts` other than the Meteora port).
|
|
190
|
+
- Added: `processedSiblingInstructionCount()` and `processedSiblingInstruction(i)`, the instructions already processed
|
|
191
|
+
at the program's stack height (the `sol_get_processed_sibling_instruction` syscall, as Rust's
|
|
192
|
+
`get_processed_sibling_instruction` reads it), each a `TransactionInstruction` (test/language/sibling-instructions.test.ts;
|
|
193
|
+
docs/language-chain.md). Existing programs build to the same bytes.
|
|
194
|
+
- Showcase: the first stage of a port of Meteora's Dynamic Bonding Curve 0.2.2 (MeteoraAg/dynamic-bonding-curve @
|
|
195
|
+
91e696e), `showcase/mainnet/meteora-dbc/`. It is subject to Meteora's Non-commercial Licence, not to this
|
|
196
|
+
repository's MIT licence (LICENSE.md and README.md there, and NOTICE), and is not in the published package. This
|
|
197
|
+
stage has 9 of the program's 35 instructions (operator accounts, the legacy claim fee operator, token badges, partner
|
|
198
|
+
metadata, `create_config`, `create_config2`, `create_config_with_transfer_hook`), all 87 errors, the account layouts,
|
|
199
|
+
the 29 events, and the curve, fee scheduler, dynamic fee, vesting and migration-handler math that config creation
|
|
200
|
+
uses. Checked against the program deployed on mainnet at `dbcij3LWUppWqq96dh6gJWwBifmcGfLSB5D4DuSMaqN` (deployed in
|
|
201
|
+
slot 457,502,600; the dump cut at the ELF's end has sha256
|
|
202
|
+
`c9f45da65b0c87ca76c1ed5ad0d1ef2ead7c3392e8e41f194d50296820a22bb9`; fetched by `scripts/fetch-programs.sh`, not
|
|
203
|
+
kept here), with its two admin keys patched to test keys in both: `showcase/test/meteora-dbc.test.ts` sends 163
|
|
204
|
+
transactions (57 succeed, the others are refused with 47 distinct errors) and `meteora-dbc-fuzz.test.ts` 200 random
|
|
205
|
+
config parameter sets per run, each to both programs, which must give the same outcome and error code, the same
|
|
206
|
+
account bytes, the same events (the self-CPIs' instruction data, all inner instructions compared) and the same return
|
|
207
|
+
data. Not checked or different: log lines (Anchor's error messages, the original's "Math error thrown at …" lines),
|
|
208
|
+
compute units, the IDL (the config events' ConfigParameters is described field by field, the metadata Strings as
|
|
209
|
+
bytes), a read-only `payer` (ConstraintMut 2000 here, PrivilegeEscalation in the original), and a `curve` argument of
|
|
210
|
+
more than 24 points (102 here; a transaction carries at most 23).
|
|
211
|
+
The second stage adds 9 more: `swap` and `swap2` (ExactIn, PartialFill, ExactOut) with the swap math, the dynamic
|
|
212
|
+
fee's volatility tracker and the rate limiter of configs made before 0.2.1, the partner's and creator's trading fee
|
|
213
|
+
claims, both pool creation fee claims, `claim_protocol_fee2` (its signer, the protocol fee program's authority PDA,
|
|
214
|
+
patched to a test key in both), `transfer_pool_creator` and `create_virtual_pool_metadata`.
|
|
215
|
+
`showcase/test/meteora-dbc-swap.test.ts` checks them against the same binary on pools written into both ledgers as
|
|
216
|
+
pool creation leaves them (pool creation is not ported yet): every mode in both directions, referrals, slippage,
|
|
217
|
+
account refusals, the rate limiter's single-swap guard, and a random swap sequence per pool (fee schedulers, dynamic
|
|
218
|
+
fee, rate limiter, Token-2022 transfer fees on either mint) to the migration threshold (1,900+ swaps over three
|
|
219
|
+
seeds, all the same). `initialize_virtual_pool_with_spl_token` follows (its Metaplex CPIs checked against Token
|
|
220
|
+
Metadata as deployed on mainnet, sha256 `31f0a627dba051a938de650464e55cc5397a4be0fd496929c1f9cf02fe5e9011`):
|
|
221
|
+
`meteora-dbc-pool.test.ts` makes pools with each token authority option, a creation fee, a fixed supply and slot
|
|
222
|
+
activation, and the first swap at the minimum fee in the pool's creation transaction; the swap tests and fuzz now
|
|
223
|
+
swap on pools made by it (pools are written only for a Token-2022 base, a TransferHookPool or a rate limiter).
|
|
224
|
+
`meteora-dbc-mainnet.test.ts` swaps on two pools read from mainnet (an SPL and a Token-2022 base) to the end of
|
|
225
|
+
their curves. `initialize_virtual_pool_with_token2022` and `initialize_virtual_pool_with_token2022_transfer_hook`
|
|
226
|
+
follow (the base mint's MetadataPointer, transfer fee and transfer hook extensions and its metadata in the mint, as
|
|
227
|
+
the original creates them): `meteora-dbc-pool2022.test.ts` makes pools with each token authority option (the mint
|
|
228
|
+
authority kept under a transfer hook config), each base transfer fee option, a Token-2022 quote, a creation fee,
|
|
229
|
+
slot activation and addresses funded before creation, and checks their refusals, with a small transfer hook program
|
|
230
|
+
(`showcase/test/fixtures/meteora-dbc/hook.ts`) loaded in both; the swap tests now swap only on pools made by the
|
|
231
|
+
three pool creation instructions (written only under a rate limiter config). Then `swap2_with_transfer_hook`,
|
|
232
|
+
`claim_trading_fee2` and `claim_creator_trading_fee2`, the base mint's transfers carrying the hook's extra accounts
|
|
233
|
+
(`transferCheckedWithHook`): `meteora-dbc-hook.test.ts` swaps, pays referrals and claims fees on TransferHookPools
|
|
234
|
+
with each kind of extra account meta, revokes the hook at completion, and checks the slices' and the resolver's
|
|
235
|
+
refusals (malformed lists and seeds included) against the binary. The `slices` argument holds at most 64 entries
|
|
236
|
+
here (102 beyond). A swap by CPI under an active rate limiter reads the processed sibling instructions, as the
|
|
237
|
+
original does (checked against the binary through a small calling program,
|
|
238
|
+
`showcase/test/fixtures/meteora-dbc/relay.ts`). The third stage adds 7 more (31 of 35): `partner_withdraw_surplus`,
|
|
239
|
+
`creator_withdraw_surplus`, `withdraw_migration_fee`, `withdraw_leftover`, `create_locker` (the locker's
|
|
240
|
+
`create_vesting_escrow_v2` by CPI), the deprecated `migration_damm_v2_create_metadata` and `migration_damm_v2` (DAMM
|
|
241
|
+
v2's pool creation on a static or dynamic config, the second position by `add_liquidity` or, with a transfer fee, by
|
|
242
|
+
`split_position2`, permanent and vested locks, the position NFTs' owners, the base mint's transfer fee authority and
|
|
243
|
+
the burn, the pool authority's rent lent and paid back). `showcase/test/meteora-dbc-migration.test.ts` and
|
|
244
|
+
`meteora-dbc-migration-fuzz.test.ts` drive pools to the threshold by swaps and graduate them on both programs, which
|
|
245
|
+
call DAMM v2 (`cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG`, sha256 `ca7a3262…5a67`) and the locker
|
|
246
|
+
(`LocpQgucEQHbqNABEYvBvwoxCPsSbG91A1QaQhQQqjn`, sha256 `0ba6f4f5…abed`) as deployed on mainnet (fetched by
|
|
247
|
+
`scripts/fetch-programs.sh`, not kept here) on DAMM v2's seven migration configs read from mainnet
|
|
248
|
+
(`showcase/test/fixtures/meteora-dbc/damm-v2/`): every progress state, each fee option, customizable pools (collect
|
|
249
|
+
fee modes, dynamic fee, fee time and market cap schedulers, compounding), partner and creator liquidity splits with
|
|
250
|
+
permanent locks and vesting, SPL and Token-2022 bases and quotes, base and quote transfer fees with each migrated fee
|
|
251
|
+
authority option, a transfer hook pool, fixed supplies (the burn and the leftover), legacy configs, each DAMM v2
|
|
252
|
+
config check and the refusals; the fuzz graduates random configs with the withdrawals in a random order. The fourth
|
|
253
|
+
stage completes the port (35 of 35): the DAMM v1 migration, deprecated for new configs but still taken by pools of
|
|
254
|
+
configs made before 0.2.1: `migration_meteora_damm_create_metadata`, `migrate_meteora_damm` (DAMM v1's
|
|
255
|
+
`initialize_permissionless_constant_product_pool_with_config2` under flash rent, the burn, the partner's and
|
|
256
|
+
creator's LP split), `migrate_meteora_damm_lock_lp_token` (DAMM v1's `lock` into the owner's lock escrow) and
|
|
257
|
+
`migrate_meteora_damm_claim_lp_token`. `showcase/test/meteora-dbc-migration-v1.test.ts` checks them on both programs,
|
|
258
|
+
which call DAMM v1 (`Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB`, upgraded in slot 468,782,174 on 2026-11-13,
|
|
259
|
+
sha256 `ea4e6581…7f58`) and the dynamic vault (`24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi`, sha256
|
|
260
|
+
`a3c23d24…fdcb`) as deployed on mainnet (fetched by `scripts/fetch-programs.sh`, not kept here; their licences are
|
|
261
|
+
not established) on DAMM v1's six migration configs and the wrapped SOL vault read from mainnet
|
|
262
|
+
(`showcase/test/fixtures/meteora-dbc/damm-v1/`), with configs made for DAMM v2 and their migration option rewritten
|
|
263
|
+
to DAMM v1 in both ledgers: every progress state, each fee option with its config and another, the customizable
|
|
264
|
+
option, each DAMM v1 config check, partner and creator LP splits locked and claimed in different orders, a
|
|
265
|
+
self-partnered creator, vested shares (which DAMM v1 leaves with the pool authority), Token-2022 on either side
|
|
266
|
+
(refused, 3007, by both), a transfer hook pool (refused), wrapped SOL in its mainnet vault, fixed supplies, a payer
|
|
267
|
+
short of the rent, `transfer_pool_creator` after a DAMM v1 migration, and the account refusals; the migration fuzz
|
|
268
|
+
now takes the DAMM v1 or the DAMM v2 path at random, locking and claiming the LP among the other steps. The binary is
|
|
269
|
+
identified as 0.2.2 by its instruction names, error messages and source paths; it was not rebuilt. The README of
|
|
270
|
+
`showcase/mainnet/meteora-dbc/` lists what is compared, what differs and what is not verified.
|
|
271
|
+
- Changed: `typesol/testing`'s `t.ix` refuses an argument left out or misspelt. An argument missing from the arguments
|
|
272
|
+
object was encoded as zeros when its size is fixed (as Anchor's coder does), so a misspelt argument name sent
|
|
273
|
+
zeros and a misspelt `Option` argument sent None; the same for a field left out of a struct argument or of a data
|
|
274
|
+
enum variant, at any depth, and for a variant that has fields named without them (`{ Box: {} }`). Each is now an
|
|
275
|
+
error naming the instruction and the argument and listing the instruction's arguments (`set: argument "amount" is
|
|
276
|
+
missing (it takes amount, cap, frame, shape; only an Option may be left out)`), or naming the field's path and the
|
|
277
|
+
struct's fields (`set(frame).origin.y is missing (Point has x, y; only an Option may be left out)`). An `Option`
|
|
278
|
+
may still be left out (None). A key that names no argument or field, in its IDL (snake_case) or camelCase
|
|
279
|
+
spelling, was ignored and is now an error too (`set has no argument "amonut" (it takes amount, cap, frame, shape)`,
|
|
280
|
+
`set(frame) has no field "scael" (Frame has origin, scale)`). `null` for an argument or field that is not an
|
|
281
|
+
`Option` was encoded as 0 for an integer of up to 32 bits and as false for a bool; it is now an error
|
|
282
|
+
(`set(amount) is null, but it is a u64, not an Option`). No test of the repository passed a missing or unknown key.
|
|
283
|
+
- Added: `t.events(res)` in `typesol/testing`: the events a successful transaction emitted, decoded from the IDL, in
|
|
284
|
+
the order the program emitted them (`[{ name, data }]`, values as `t.account` gives them): `emit`'s `Program data:`
|
|
285
|
+
log lines while this program runs, and `emitCpi`'s self-CPIs, which it finds in the transaction's inner
|
|
286
|
+
instructions. It needs no other package; decoding events in a test took `t.coder.events.decode(…)` on each log line,
|
|
287
|
+
which needs `@anchor-lang/core`, and did not see `emitCpi` events. `t.coder` does not change. TypeSOL's Borsh coder
|
|
288
|
+
decodes events as Anchor's `coder.events.decode` does (test/client/idl-coder.test.ts compares the two on random
|
|
289
|
+
values for every program with events, and on a wrong discriminator, which both decode as null).
|
|
290
|
+
- Changed, now refused: a call of a helper that returns the result of `merkleVerify`, `verifyEd25519` or
|
|
291
|
+
`verifySecp256k1` whose result decides nothing. 0.46.0 refused such a call of the three themselves (as a statement,
|
|
292
|
+
as the condition of an `if` with an empty body, kept in a local never read) but compiled the same through a helper,
|
|
293
|
+
which dropped the result and checked nothing. A helper (a function, a const arrow or function expression, a generic
|
|
294
|
+
one, a closure) returns a check when one of its `return`s gives the result of one of the three or of another such
|
|
295
|
+
helper, directly, in parentheses or under `as`, combined with `&&`, `||`, `!` or `?:`, or through a local of the
|
|
296
|
+
helper that nothing but its returns reads. Its call is held to the same three rules, the message naming the helper
|
|
297
|
+
and the built-in: "the result of checkProof is discarded, so nothing is checked: it returns the result of
|
|
298
|
+
merkleVerify; write require(checkProof(…), error)", "the result of signed is not acted on: the if around it has an
|
|
299
|
+
empty body, so nothing is checked: it returns the result of verifyEd25519; …", "the result of checkProof is never
|
|
300
|
+
read (ok is not used), so nothing is checked: …". A helper that requires the result itself, or reads it anywhere
|
|
301
|
+
but in a `return`, does not return a check, and neither does one returning an unrelated boolean. Still not caught: a
|
|
302
|
+
result stored in an account field, a struct or an Option, compared (`=== true`) or passed to a function that ignores
|
|
303
|
+
it; a helper that branches on the result and returns literals (`if (!ok) { return false; } return true;`); and a
|
|
304
|
+
helper that returns what a function passed to it returns. No program of the repository is refused: the 76 build to
|
|
305
|
+
the same binaries and IDLs as with 0.47.0 (test/language/diagnostics.test.ts; a row in the refused-constructs table
|
|
306
|
+
of docs/language-statements.md; docs/language-chain.md).
|
|
307
|
+
|
|
9
308
|
## 0.47.0 — 2026-11-13
|
|
10
309
|
|
|
11
310
|
A minor release: it removes an optional peer dependency (`@anchor-lang/core`) and changes what `t.coder` of
|
package/NOTICE
CHANGED
|
@@ -80,5 +80,22 @@ Third-party material in this repository only (not in the published package)
|
|
|
80
80
|
- showcase/mainnet/: TypeSOL ports of mainnet programs, which follow their originals' source: Raydium CP-Swap, CLMM
|
|
81
81
|
and AMM v4, Jito's MEV programs, marginfi v2, coral-xyz/multisig and SPL Stake Pool (Apache-2.0), and Phoenix v1
|
|
82
82
|
(MIT, Copyright Ellipsis Labs). Every file says which program it ports and under which licence in its first line.
|
|
83
|
+
- showcase/mainnet/meteora-dbc/: a TypeSOL port of Meteora's Dynamic Bonding Curve (MeteoraAg/dynamic-bonding-curve,
|
|
84
|
+
release 0.2.2, commit 91e696e), with its tests showcase/test/meteora-dbc*.ts and the mainnet accounts of two of its
|
|
85
|
+
pools, the seven DAMM v2 migration configs, the six DAMM v1 migration configs and the wrapped SOL dynamic vault those
|
|
86
|
+
tests read (showcase/test/fixtures/meteora-dbc/; DAMM v2 is under the Meteora Non-commercial Licence too, the licences
|
|
87
|
+
of DAMM v1 and the dynamic vault are not established). It is not under this repository's MIT
|
|
88
|
+
licence: it is subject to Meteora's Non-commercial Licence, whose text is showcase/mainnet/meteora-dbc/LICENSE.md.
|
|
89
|
+
Required Notice: All underlying software code is subject to the licence set out at https://github.com/MeteoraAg/dynamic-bonding-curve
|
|
90
|
+
The program's mainnet binary is not kept here either, nor are those of DAMM v2, the locker, DAMM v1 and the dynamic
|
|
91
|
+
vault its migrations call:
|
|
92
|
+
scripts/fetch-programs.sh downloads them (test/programs/SOURCES.md).
|
|
93
|
+
- showcase/mainnet/percolator/: a TypeSOL port of Percolator v12.20, the program aeyakovenko/percolator-prog
|
|
94
|
+
(commit 06f86fb) with its risk engine aeyakovenko/percolator (commit 3f55f87), Copyright Anatoly Yakovenko,
|
|
95
|
+
Apache-2.0 (the licence text is test/programs/LICENSE-Apache-2.0.txt), with its tests showcase/test/percolator*.ts.
|
|
96
|
+
Changes: rewritten in TypeSOL. The original's own warning stands for the port: an educational research project, not
|
|
97
|
+
audited, not for use with real funds. Its mainnet binary is not kept here: scripts/fetch-programs.sh downloads it
|
|
98
|
+
(test/programs/SOURCES.md). showcase/mainnet/percolator/matcher/ is a TypeSOL port of the matcher TradeCpi calls,
|
|
99
|
+
aeyakovenko/percolator-match (commit 199b139), Copyright Anatoly Yakovenko, Apache-2.0, kept as a test fixture.
|
|
83
100
|
- showcase/program-examples/: ports of solana-developers/program-examples (MIT, Copyright Solana Foundation; the
|
|
84
101
|
licence text is in showcase/program-examples/README.md).
|
package/README.md
CHANGED
|
@@ -32,17 +32,22 @@ clients read TypeSOL programs unchanged.
|
|
|
32
32
|
- Every arithmetic operation is checked.
|
|
33
33
|
- Account owner, discriminator, signer, writability and aliasing checks are generated from your parameter types.
|
|
34
34
|
- Constraints follow Anchor's rules and use Anchor's error codes.
|
|
35
|
-
- **Small and fast.** In the
|
|
36
|
-
about 10× smaller, and fewer compute units than native Rust and hand-tuned Pinocchio on every
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
- **Small and fast.** In the counter, vault and escrow benchmarks below, TypeSOL uses 5–32% of Anchor's compute units,
|
|
36
|
+
with binaries about 10× smaller, and fewer compute units than native Rust and hand-tuned Pinocchio on every
|
|
37
|
+
instruction. On 17 official example programs it uses fewer than Anchor and native Rust on every instruction, and
|
|
38
|
+
more than their Pinocchio versions on 13 of the 26 ([Numbers](#numbers)). On mainnet the results differ by
|
|
39
|
+
instruction; see [the mainnet table](#on-mainnet).
|
|
40
|
+
- **Checked against mainnet.** Nine ports of deployed programs (eleven programs: Jito MEV's row is three), among them
|
|
41
|
+
Marginfi v2, Phoenix v1 and SPL Stake Pool, run beside the original binaries: the same outcomes, events, return data
|
|
42
|
+
and account bytes on thousands of transactions, and the same error codes and log lines but for the exceptions each
|
|
43
|
+
case study lists, for fewer compute units ([the ports](#ported-and-checked-against-mainnet-binaries)).
|
|
41
44
|
- **Verifiable.** `typesol verify` reads a deployed program from the cluster and checks it, and the IDL published on
|
|
42
|
-
chain, against its source. Every release records
|
|
43
|
-
|
|
45
|
+
chain, against its source. Every release records its npm tarball in `releases/<version>.json` ([releases/](releases)),
|
|
46
|
+
and the hashes of every program it builds in its GitHub Release's `typesol-<version>-manifest.json`
|
|
47
|
+
([docs/testing.md](docs/testing.md#reproducing-a-release)).
|
|
44
48
|
The same source, TypeSOL version and toolchain build to the same bytes on macOS arm64, Linux arm64 and Linux x86_64
|
|
45
|
-
(measured: all 76 programs
|
|
49
|
+
(measured with 0.45.0: all 76 programs then in the sources for SBPF v0, 14 of them for v1 and v2; programs added
|
|
50
|
+
since, the Meteora DBC and Percolator ports among them, were not in that measurement; Linux arm64 with the platform-tools
|
|
46
51
|
`linux-aarch64` package set up as in [Requirements](#requirements), since there is no Agave CLI for it;
|
|
47
52
|
[docs/stability.md](docs/stability.md#what-builds-the-same-bytes-where)).
|
|
48
53
|
`typesol build --docker` builds in a pinned linux/amd64 container that anyone can rebuild from the Dockerfile, and
|
|
@@ -65,28 +70,53 @@ Node.js and the Solana toolchain are in place ([Quick start](#quick-start), [Req
|
|
|
65
70
|
## Ported and checked against mainnet binaries
|
|
66
71
|
|
|
67
72
|
Each port is the whole program, written in TypeSOL from the original's source. Its tests send every transaction to
|
|
68
|
-
the port and to the binary deployed on mainnet, both in LiteSVM, and require the same outcome,
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
the port and to the binary deployed on mainnet, both in LiteSVM, and require the same outcome, events, return data and
|
|
74
|
+
bytes in every account the transaction names, and the same error code and log lines, with the exceptions each case
|
|
75
|
+
study lists. Of those, the kinds that recur:
|
|
76
|
+
|
|
77
|
+
- **Error-message text.** The Anchor ports log their errors in TypeSOL's words, with Anchor's codes; Jito's also leaves
|
|
78
|
+
out Anchor's `Instruction: …` lines.
|
|
79
|
+
- **Panics.** Where the original panics, Marginfi, Raydium CLMM, Raydium CP-Swap and Jito MEV fail with a numbered
|
|
80
|
+
error, and Marginfi also answers a few runtime errors that carry no code (`AccountBorrowFailed`, `BorshIoError`)
|
|
81
|
+
with numbered ones; the tests require that both fail.
|
|
82
|
+
- **Informational logs.** Marginfi writes only the original's `WARN` lines, of about 160 `msg!` lines.
|
|
83
|
+
- **Raydium CLMM's reward mints**, kept in the order added, so `OperationState`'s bytes differ when two or more are
|
|
84
|
+
listed.
|
|
85
|
+
- **Compute.** A Percolator keeper crank that exceeds the compute budget in the original completes in the port.
|
|
86
|
+
|
|
87
|
+
Phoenix v1, Raydium AMM v4, SPL Stake Pool and Percolator match every log line of the compared transactions, panics
|
|
88
|
+
included, except the runtime's compute-unit lines. The port must also use fewer compute units on every transaction that succeeds. A case study for
|
|
89
|
+
each (for Percolator, the port's README) says what was compared and what was not.
|
|
71
90
|
|
|
72
91
|
| Program | Kind | Instructions | Transactions compared |
|
|
73
92
|
| --- | --- | ---: | ---: |
|
|
74
|
-
| [Marginfi v2](docs/case-study-marginfi.md) | Anchor, lending | 124 | 2,
|
|
93
|
+
| [Marginfi v2](docs/case-study-marginfi.md) | Anchor, lending | 124 | 2,321 |
|
|
75
94
|
| [Phoenix v1](docs/case-study-phoenix.md) | native, limit order book | 28 | 3,575 |
|
|
76
95
|
| [SPL Stake Pool](docs/case-study-spl-stake-pool.md) | native, liquid staking | 27 | 2,107 |
|
|
77
96
|
| [Raydium CLMM](docs/case-study-raydium-clmm.md) | Anchor, concentrated liquidity | 37 | 302 |
|
|
78
97
|
| [Raydium CP-Swap](docs/case-study-raydium-cp-swap.md) | Anchor, constant product | 21 | 136 |
|
|
79
|
-
| [Raydium AMM v4](docs/case-study-raydium-amm.md) | native, constant product | all |
|
|
98
|
+
| [Raydium AMM v4](docs/case-study-raydium-amm.md) | native, constant product | all | 144 (60 random steps) |
|
|
80
99
|
| [Jito MEV](docs/case-study-jito-mev.md) | Anchor, three programs | 24 | 150 |
|
|
81
|
-
| [
|
|
82
|
-
|
|
83
|
-
|
|
100
|
+
| [Percolator v12.20](showcase/mainnet/percolator) | native, perpetuals risk engine | 27 | 139,185 (132,031 random or mutated: 3,711 in random walks on fixed seeds, 128,320 from the mutation fuzzers) |
|
|
101
|
+
| [coral-xyz/multisig](docs/case-study-multisig.md) | Anchor | all | 55 |
|
|
102
|
+
|
|
103
|
+
A tenth port is held to a narrower comparison and is not counted above:
|
|
104
|
+
[Meteora Dynamic Bonding Curve 0.2.2](showcase/mainnet/meteora-dbc) (Anchor, launchpad, all 35 instructions, with its
|
|
105
|
+
migrations into DAMM v1 and DAMM v2). Outcomes, error codes, account bytes, inner instructions (its events are
|
|
106
|
+
self-CPIs) and return data are compared as for the ports above, with the exceptions its README lists; of the log only
|
|
107
|
+
the events' `Program data:` lines are compared, not the rest of its text, and compute units are not compared. The
|
|
108
|
+
port, its tests (`showcase/test/meteora-dbc*.ts`) and their fixtures (`showcase/test/fixtures/meteora-dbc/`) are under
|
|
109
|
+
Meteora's Non-commercial Licence, not this repository's (see [NOTICE](NOTICE)).
|
|
110
|
+
|
|
111
|
+
Each count is what a default test run compares, with the fetch-only binaries present (`pnpm fetch:programs`). Random
|
|
112
|
+
walks, with fixed or printed seeds, run on top of the other ports' counts ([docs/testing.md](docs/testing.md)); the
|
|
113
|
+
multisig port has none. The
|
|
84
114
|
sources are in [`showcase/mainnet`](showcase/mainnet), and where each original binary comes from is recorded in
|
|
85
115
|
[test/programs/SOURCES.md](test/programs/SOURCES.md).
|
|
86
116
|
|
|
87
117
|
## At a glance
|
|
88
118
|
|
|
89
|
-
**`counter.ts`**: a complete program, 23 lines. (`typesol init` writes it with one more instruction, a read-only
|
|
119
|
+
**`counter.ts`**: a complete program, 23 non-blank lines. (`typesol init` writes it with one more instruction, a read-only
|
|
90
120
|
`assertAtLeast`.)
|
|
91
121
|
|
|
92
122
|
```ts
|
|
@@ -120,7 +150,7 @@ export function increment(authority: Signer, counter: Mut<Counter>, by: u64): vo
|
|
|
120
150
|
```
|
|
121
151
|
|
|
122
152
|
<details>
|
|
123
|
-
<summary><b>The same program in Anchor</b>: 44 lines of Rust</summary>
|
|
153
|
+
<summary><b>The same program in Anchor</b>: 44 non-blank lines of Rust</summary>
|
|
124
154
|
|
|
125
155
|
```rust
|
|
126
156
|
#[program]
|
|
@@ -258,9 +288,9 @@ the same.
|
|
|
258
288
|
`typesol port` starts from your program's IDL; [docs/case-study-escrow.md](docs/case-study-escrow.md) follows one
|
|
259
289
|
program through the port.
|
|
260
290
|
- Real programs checked against their mainnet binaries: [Showcase](https://github.com/typesol-lang/typesol#showcase-ports-checked-against-mainnet), with a
|
|
261
|
-
case study each (Marginfi v2 in full: all 124 instructions,
|
|
262
|
-
order book, the same on 3,575 transactions down to its event bytes
|
|
263
|
-
lines).
|
|
291
|
+
case study each (Marginfi v2 in full: all 124 instructions, 2,321 transactions with the same outcomes, events and
|
|
292
|
+
account bytes; Phoenix v1, a native order book, the same on 3,575 transactions down to its event bytes and log lines;
|
|
293
|
+
Raydium AMM v4, a native program, down to its log lines).
|
|
264
294
|
- To mainnet (wallet, cost, deploy, IDL, verification): [docs/mainnet.md](docs/mainnet.md).
|
|
265
295
|
- With an AI coding agent: [docs/ai.md](docs/ai.md) (agent rules, [llms.txt](https://typesol.com/llms.txt), the MCP server).
|
|
266
296
|
|
|
@@ -281,7 +311,7 @@ counter.ts ─▶ tsc typecheck ─▶ subset check ─▶ C + typesol_rt.h ─
|
|
|
281
311
|
`--sbpf`).
|
|
282
312
|
|
|
283
313
|
Runtime failures point back to your source: `Error 6000 Unauthorized (counter.ts:25)`, or
|
|
284
|
-
`TypeSOL: arithmetic overflow (vault.ts:
|
|
314
|
+
`TypeSOL: arithmetic overflow (vault.ts:44)`.
|
|
285
315
|
|
|
286
316
|
## What you can write
|
|
287
317
|
|
|
@@ -361,14 +391,36 @@ CPI account records only for the accounts a call lists. It uses fewer compute un
|
|
|
361
391
|
instruction here, while also refusing duplicate writable accounts as Anchor does. Fewer compute
|
|
362
392
|
units are not a safety claim. The differential tests also run the escrow against its Anchor twin ([docs/testing.md](docs/testing.md)).
|
|
363
393
|
|
|
394
|
+
These three programs' Pinocchio versions were written for this comparison.
|
|
395
|
+
|
|
396
|
+
<!-- bench:official -->
|
|
397
|
+
On the official examples, 17 programs of solana-developers/program-examples@de09019 that this project did not write (26 instructions, `official.ts` in the benchmarks repository), TypeSOL uses fewer compute units than Anchor on 26 of 26 instructions and than native Rust on 26 of 26, and more than Pinocchio on 13 of 26.
|
|
398
|
+
<!-- /bench:official -->
|
|
399
|
+
|
|
400
|
+
Those Pinocchio versions often do less: favorites, close-account and
|
|
401
|
+
program-derived-addresses take the PDA bump from the client instead of searching for it on chain, and pda-rent-payer
|
|
402
|
+
checks the client's bump instead of finding the canonical one; program-derived-addresses' increment checks neither the
|
|
403
|
+
address nor the owner of the account it writes; transfer-sol checks neither that the recipient is a System account nor
|
|
404
|
+
that the paying account of `transfer_sol_with_program` belongs to the program. The notes for each program, and every
|
|
405
|
+
figure, are in the benchmarks' `results.json` (`official`).
|
|
406
|
+
|
|
364
407
|
### On mainnet
|
|
365
408
|
|
|
366
409
|
The official escrow ([tokens/escrow](https://github.com/solana-developers/program-examples/tree/de090195e4de698e150572c4f886c333323a64a5/tokens/escrow)),
|
|
367
410
|
deployed to Solana mainnet-beta in all four versions and called with the same mints, amounts and accounts, one
|
|
368
411
|
instruction per transaction. The TypeSOL program was upgraded in place to 0.25.0 on 2026-10-29; the others are as first
|
|
369
412
|
deployed on 2026-10-27. Each figure is the compute units of that transaction, linked to Solscan; the lowest per row is
|
|
370
|
-
in bold. The
|
|
371
|
-
|
|
413
|
+
in bold. The TypeSOL program was checked against its source with `typesol verify` (it is the 0.25.0 build, not the
|
|
414
|
+
current release) and its IDL is published on chain with `typesol idl publish`; the Pinocchio, native Rust and Anchor
|
|
415
|
+
programs are the benchmarks' builds, and this record does not check them byte for byte against those builds.
|
|
416
|
+
|
|
417
|
+
These four programs are a benchmark record, not a service: the maintainers' own keys made every offer and took or
|
|
418
|
+
refunded each one in the runs recorded, so no offer is open and they hold no one's tokens. The TypeSOL one predates
|
|
419
|
+
the defects fixed in 0.44.0 and 0.44.1 (see [Status](#status)); its source,
|
|
420
|
+
[`showcase/program-examples/tokens/escrow.ts`](showcase/program-examples/tokens/escrow.ts) (the same at 0.25.0, then
|
|
421
|
+
`test/ports/tokens/escrow.ts`), uses none of the constructs those defects need: no helper functions, closures,
|
|
422
|
+
`Dup<…>` or loaded accounts, seed lists written in place at each call, token wrapper arguments that are plain reads,
|
|
423
|
+
and no `transferFee` or `updateExtraAccountMetas`.
|
|
372
424
|
|
|
373
425
|
| Transaction | TypeSOL | Pinocchio | Native Rust | Anchor |
|
|
374
426
|
| --- | ---: | ---: | ---: | ---: |
|
|
@@ -379,26 +431,33 @@ program's IDL is published on chain with `typesol idl publish`.
|
|
|
379
431
|
| escrow program's own part, 4 transactions | **28,118** | 36,956 | 93,273 | 102,926 |
|
|
380
432
|
| program | [65ybkcg6…](https://solscan.io/account/65ybkcg6mQa9t5EuHtirRdvf2qAu12qRiK6wYBbGk16P) | [FrQwq3iU…](https://solscan.io/account/FrQwq3iUa8ZkWEne1y27webXTAyLgH4Hj6t986t6VS2G) | [5pnmi1Md…](https://solscan.io/account/5pnmi1MdxzXKmgX7ooRSE212rzZK8rb7nNpRTSMqP8V1) | [EG7M3sLL…](https://solscan.io/account/EG7M3sLLwB7MhmtzwYsaxbhZaFDbshL9hmVK79bQVyVq) |
|
|
381
433
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
434
|
+
In make_offer the Associated Token Account program creates the vault: 13,480 to 22,480 CU of the make_offers above
|
|
435
|
+
(13,585 to 22,585 with the token transfer after it). That is most of the TypeSOL and Pinocchio make_offers (67–77%)
|
|
436
|
+
and about a third to a half of the native Rust and Anchor ones (35–46%), whose own part is larger (15,543 to 29,043
|
|
437
|
+
CU). The ATA program searches for the vault address's bump itself at 1,500 CU a try, and every offer has its own
|
|
438
|
+
vault, so that part depends on the offer (13,510 CU for both of Anchor's, 13,480 and 22,480 for TypeSOL's); programs
|
|
439
|
+
that check the vault's address re-derive it, so take_offer and refund_offer can vary with it too. The escrow
|
|
440
|
+
program's own part is steadier: TypeSOL's make_offer spent 6,620 CU of its own on both offers. The Pinocchio version takes the offer PDA's bump from the client instead of
|
|
387
441
|
searching for it. Mainnet figures differ from the LiteSVM means above. Every run, including the one before the
|
|
388
442
|
upgrade, is in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) (`results/`).
|
|
389
443
|
|
|
390
444
|
## How it is tested
|
|
391
445
|
|
|
392
|
-
- **Execution tests.**
|
|
393
|
-
|
|
394
|
-
-
|
|
446
|
+
- **Execution tests.** Programs that use each language feature are compiled and run in LiteSVM (`test/language/`,
|
|
447
|
+
`test/examples/`, `test/integrations/`, `test/security/`), and every complete example of the language guide must
|
|
448
|
+
compile (`test/language/docs-examples.test.ts`).
|
|
449
|
+
- **Diagnostics tests.** Refused constructs are tested with the message they get (`test/language/diagnostics.test.ts`,
|
|
450
|
+
and every row of the guide's "What is refused" table).
|
|
451
|
+
- **Golden tests.** The generated C of the counter and the generated clients of two programs are compared with golden
|
|
452
|
+
output (`test/golden/`), and CI rebuilds 14 programs on Linux x86_64 to the bytes the reference container gives
|
|
453
|
+
(`test/golden/binaries.json`).
|
|
395
454
|
- **Randomized tests** against independent oracles:
|
|
396
455
|
- Arithmetic at every integer width is checked against BigInt.
|
|
397
456
|
- Stateful vault, escrow and ledger runs are checked against a TypeScript model.
|
|
398
457
|
- Differential runs send the same transactions to TypeSOL and to the Anchor twins and compare outcomes, account
|
|
399
458
|
contents and balances.
|
|
400
|
-
- **Ports against mainnet binaries.** The
|
|
401
|
-
transaction, and random walks over them compare every step.
|
|
459
|
+
- **Ports against mainnet binaries.** The nine ports above run beside the deployed originals, transaction by
|
|
460
|
+
transaction, and random walks over eight of them (all but multisig), and over Meteora DBC, compare every step.
|
|
402
461
|
- **Localnet smoke test.** A script deploys every example to a local validator and drives it end to end; it is run
|
|
403
462
|
by hand, not in CI.
|
|
404
463
|
|
|
@@ -411,7 +470,7 @@ Details are in [docs/testing.md](docs/testing.md).
|
|
|
411
470
|
| [`counter.ts`](examples/counter.ts) | PDA init, authority check |
|
|
412
471
|
| [`vault.ts`](examples/vault.ts) | System CPI, direct lamport moves, rent floor, close |
|
|
413
472
|
| [`escrow.ts`](examples/escrow.ts) | SPL Token CPIs signed by a PDA, atomic swap, refund |
|
|
414
|
-
| [`minter.ts`](examples/minter.ts) | capped issuer over SPL Token and Token-2022 |
|
|
473
|
+
| [`minter.ts`](examples/minter.ts) | capped issuer over SPL Token and Token-2022, set up by the mint's authority |
|
|
415
474
|
| [`ledgerbook.ts`](examples/ledgerbook.ts) | enums, Options, a Vec that grows and shrinks its account |
|
|
416
475
|
| [`airdrop.ts`](examples/airdrop.ts) | remaining accounts, batch payouts, `loadAccountMut` |
|
|
417
476
|
| [`relay.ts`](examples/relay.ts), [`caller.ts`](examples/caller.ts) | generic `invoke`, PDA-signed transfers, return data |
|
|
@@ -436,6 +495,8 @@ Case studies: [Marginfi v2](docs/case-study-marginfi.md), [Phoenix v1](docs/case
|
|
|
436
495
|
| [`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 |
|
|
437
496
|
| [`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 |
|
|
438
497
|
| [`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 |
|
|
498
|
+
| [`meteora-dbc/`](showcase/mainnet/meteora-dbc) | Meteora Dynamic Bonding Curve 0.2.2 in full, all 35 instructions: configs, pool creation on SPL Token and Token-2022 (transfer fees and hooks), the three swap modes, fee schedulers and the rate limiter, fee claims, the locker, and the migrations into DAMM v1 and DAMM v2. Under Meteora's Non-commercial Licence (its own `LICENSE.md`); log text and compute units are not compared |
|
|
499
|
+
| [`percolator/`](showcase/mainnet/percolator) | Percolator v12.20, Anatoly Yakovenko's perpetuals risk engine and its native program, in full, all 27 instructions, against the immutable mainnet build: one 1.5 MB slab of 4,096 accounts, U256 and U512 arithmetic, trades through matcher programs, funding, liquidation, the keeper crank with pro-rata loss socialisation and side resets, resolution and teardown. The author's own suite gives the same outcome on every test under both binaries (660 passed). Upstream is educational and not audited |
|
|
439
500
|
| [`multisig.ts`](showcase/mainnet/multisig/multisig.ts) | coral-xyz/multisig: stored instructions run with `invokeInstruction`, a PDA signing, Anchor's Borsh accounts |
|
|
440
501
|
|
|
441
502
|
## Status
|
|
@@ -447,6 +508,11 @@ change.
|
|
|
447
508
|
The two latest, of 0.43.0 and 0.44.0 in November 2026, found defects that made a program that compiled behave
|
|
448
509
|
differently from its source; each is fixed with a test, and [docs/audit.md](docs/audit.md) lists them, what the
|
|
449
510
|
reviews covered and what they did not. Programs built before 0.44.1 should be rebuilt.
|
|
511
|
+
- 0.45.0 to 0.49.0 have had no security review. They add, among others,
|
|
512
|
+
`runtime/typesol_builtins.c` (the compiler builtins as TypeSOL's own C, 0.45.0), `transferCheckedWithHook`,
|
|
513
|
+
`EVENT_AUTHORITY_CHECK` and the reads of processed sibling instructions (0.48.0), and `zeroData`, `log64`,
|
|
514
|
+
`PANIC_STYLE = "solana-1.18"`, `executable` on remaining accounts and lamport writes on remaining accounts under
|
|
515
|
+
`NATIVE_ACCOUNT_WRITES` (0.49.0).
|
|
450
516
|
- From 0.44.0 on, a release that only fixes defects is a patch with no new language surface and a binary diff in its
|
|
451
517
|
notes ([SECURITY.md](SECURITY.md#fix-releases)), and the npm tarball is the one packed from the tag and recorded
|
|
452
518
|
in [releases/](releases).
|
|
@@ -495,6 +561,9 @@ built-in, a constraint or an error code. Then read [CONTRIBUTING.md](CONTRIBUTIN
|
|
|
495
561
|
|
|
496
562
|
## License
|
|
497
563
|
|
|
498
|
-
[MIT](LICENSE)
|
|
564
|
+
[MIT](LICENSE), except the Meteora Dynamic Bonding Curve port: `showcase/mainnet/meteora-dbc/`, its tests
|
|
565
|
+
`showcase/test/meteora-dbc*.ts` and their fixtures `showcase/test/fixtures/meteora-dbc/` are subject to the Meteora
|
|
566
|
+
Non-commercial Licence ([its text](showcase/mainnet/meteora-dbc/LICENSE.md), [NOTICE](NOTICE)), and none of them is in
|
|
567
|
+
the npm package. The runtime and `typesol/testing` include code ported from MIT and Apache-2.0 projects, and the tests
|
|
499
568
|
use third-party program binaries and data that are not in the npm package: see [NOTICE](NOTICE) and
|
|
500
569
|
[test/programs/SOURCES.md](test/programs/SOURCES.md).
|