@typesol/cli 0.39.0 → 0.41.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 +74 -0
- package/README.md +29 -23
- package/dist/ai.d.ts +10 -0
- package/dist/ai.js +43 -0
- package/dist/cli.js +52 -4
- package/dist/compiler/analyze.js +13 -7
- package/dist/compiler/diagnostics.d.ts +2 -0
- package/dist/compiler/emit/base.d.ts +2 -1
- package/dist/compiler/emit/calls.d.ts +5 -0
- package/dist/compiler/emit/calls.js +173 -5
- package/dist/compiler/emit/expressions.d.ts +6 -0
- package/dist/compiler/emit/expressions.js +95 -2
- package/dist/compiler/emit/program.js +12 -0
- package/dist/compiler/emit/shared.d.ts +10 -0
- package/dist/compiler/emit/statements.d.ts +20 -1
- package/dist/compiler/emit/statements.js +177 -7
- package/dist/compiler/hints.d.ts +5 -0
- package/dist/compiler/hints.js +88 -0
- package/dist/compiler/index.d.ts +3 -0
- package/dist/compiler/index.js +6 -1
- package/dist/tools/mcp.d.ts +11 -0
- package/dist/tools/mcp.js +208 -0
- package/dist/workspace.js +8 -0
- package/docs/ai.md +52 -0
- package/docs/audit.md +16 -14
- package/docs/case-study-marginfi.md +2 -2
- package/docs/case-study-raydium-amm.md +80 -0
- package/docs/case-study-raydium-cp-swap.md +77 -41
- package/docs/language.md +27 -7
- package/docs/stability.md +56 -0
- package/docs/testing.md +6 -5
- package/docs/troubleshooting.md +6 -0
- package/lib/typesol.d.ts +73 -2
- package/llms-full.txt +1195 -0
- package/llms.txt +30 -0
- package/package.json +4 -2
- package/runtime/typesol_rt.h +47 -0
- package/ts-plugin/index.js +24 -1
package/docs/ai.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Writing TypeSOL with an AI agent
|
|
2
|
+
|
|
3
|
+
TypeSOL is TypeScript, which AI coding agents write well, but a subset of it: a model's ordinary habits (`1` for an
|
|
4
|
+
integer, `console.log`, `throw`, `xs[i]`) are refused. Four things close that gap.
|
|
5
|
+
|
|
6
|
+
## The rules in the project
|
|
7
|
+
|
|
8
|
+
`typesol init` writes the rules an agent needs into the project:
|
|
9
|
+
|
|
10
|
+
| File | Read by |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| `AGENTS.md` | Codex, Cursor, Zed, Aider and other agents that read AGENTS.md |
|
|
13
|
+
| `CLAUDE.md` (`@AGENTS.md`) | Claude Code |
|
|
14
|
+
| `.cursor/rules/typesol.mdc` | Cursor (always applied to `programs/` and `tests/`) |
|
|
15
|
+
|
|
16
|
+
They say what ordinary TypeScript habits break (bigint integers, imports from `"typesol"`, no `throw` / `async` /
|
|
17
|
+
`class`, `Mut<T>` for an account that changes, `.get(i)` / `.set(i, v)` on lists) and how to check and test. Keep your
|
|
18
|
+
own project notes below them in AGENTS.md.
|
|
19
|
+
|
|
20
|
+
## llms.txt
|
|
21
|
+
|
|
22
|
+
[typesol.com/llms.txt](https://typesol.com/llms.txt) is the index of the docs for models
|
|
23
|
+
([llmstxt.org](https://llmstxt.org)); [llms-full.txt](https://typesol.com/llms-full.txt) is the rules, the quick start
|
|
24
|
+
and the reference (language, errors, tests, CLI, client, porting from Anchor, troubleshooting, mainnet, security model)
|
|
25
|
+
in one file, to paste into a chat or give to a model as context. Both also ship in the npm package
|
|
26
|
+
(`node_modules/typesol/llms-full.txt`).
|
|
27
|
+
|
|
28
|
+
## Errors an agent can fix by itself
|
|
29
|
+
|
|
30
|
+
`typesol check --json` prints `{ "ok": false, "diagnostics": [...] }`; each diagnostic has `file`, `line`, `column`,
|
|
31
|
+
`length`, `message` and, for the usual mistakes, `hint`: what to write instead ("integers (u64, u32, i64 …) are bigint
|
|
32
|
+
in TypeSOL: write 1n, not 1, and take u64, not number"). An agent can loop on check → edit → check without building.
|
|
33
|
+
|
|
34
|
+
## The MCP server
|
|
35
|
+
|
|
36
|
+
`typesol mcp` serves the [Model Context Protocol](https://modelcontextprotocol.io) on stdio. `typesol init` writes
|
|
37
|
+
`.mcp.json` (Claude Code) and `.cursor/mcp.json` (Cursor) that start it with `npx typesol mcp`. Other clients take the
|
|
38
|
+
same command:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{ "mcpServers": { "typesol": { "command": "npx", "args": ["typesol", "mcp"] } } }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
| Tool | What it does |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `check` | type-checks a program (`file`, or `source` text) and returns the diagnostics with their hints |
|
|
47
|
+
| `idl` | the Anchor-compatible IDL the program compiles to |
|
|
48
|
+
| `docs` | searches the docs and returns the best-matching sections |
|
|
49
|
+
| `rules` | the rules above |
|
|
50
|
+
|
|
51
|
+
Building and testing stay in the shell (`npm test`, `npx typesol build`): they need the platform-tools and write
|
|
52
|
+
files, which an agent should do in the open.
|
package/docs/audit.md
CHANGED
|
@@ -7,21 +7,21 @@ with TypeSOL are out of scope; their authors audit them.
|
|
|
7
7
|
|
|
8
8
|
## Scope
|
|
9
9
|
|
|
10
|
-
In order of priority. Line counts at 0.
|
|
10
|
+
In order of priority. Line counts at 0.40.0 (November 2026).
|
|
11
11
|
|
|
12
12
|
| Priority | Component | Files | Lines | Why |
|
|
13
13
|
| --- | --- | --- | ---: | --- |
|
|
14
|
-
| 1 | C runtime | `runtime/typesol_rt.h` | 2,
|
|
15
|
-
| 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` |
|
|
16
|
-
| 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 2,
|
|
17
|
-
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` |
|
|
14
|
+
| 1 | C runtime | `runtime/typesol_rt.h` | 2,510 | In every program: input parsing, account checks, checked arithmetic, PDAs, system and token CPIs, account creation, resizing and closing, oracles, signature checks, the heap |
|
|
15
|
+
| 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 870 | Which checks each account parameter gets, and their order |
|
|
16
|
+
| 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 2,802 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
|
|
17
|
+
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 4,084 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
|
|
18
18
|
| 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,454 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
|
|
19
|
-
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 1,
|
|
20
|
-
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 2,
|
|
21
|
-
| 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,
|
|
19
|
+
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 1,820 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
|
|
20
|
+
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 2,930 | What the language accepts; constraints and account types as parsed from the source |
|
|
21
|
+
| 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,316 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
|
|
22
22
|
| 3 | Build and tooling | `src/compiler/toolchain.ts`, `src/cli.ts`, `src/workspace.ts`, `src/tools/` | | Build flags, deploy and verification commands |
|
|
23
23
|
|
|
24
|
-
The language surface is `lib/typesol.d.ts` (2,
|
|
24
|
+
The language surface is `lib/typesol.d.ts` (2,163 lines): every type and built-in a program can use, with its
|
|
25
25
|
documented behavior. [docs/language.md](language.md) is the reference; [docs/architecture.md](architecture.md) maps
|
|
26
26
|
the code, [docs/runtime.md](runtime.md) the runtime's conventions.
|
|
27
27
|
|
|
@@ -49,11 +49,13 @@ accepts. Areas where a bug would be most damaging, and where earlier internal re
|
|
|
49
49
|
## Earlier reviews
|
|
50
50
|
|
|
51
51
|
Internal reviews, by the maintainers, in October 2026. Their findings and fixes are in the CHANGELOG. The releases
|
|
52
|
-
after 0.25.0 (0.26.0 to 0.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
after 0.25.0 (0.26.0 to 0.40.0) have had no review of this kind yet; they add, among others, `u256`, big-endian seeds
|
|
53
|
+
and accounts loaded in the body (0.37.0), stored bumps in nested fields and error members without messages (0.38.0),
|
|
54
|
+
`@code`, `@repr` / `@serialization`, `@bytes` / `@idlName`, `f64`, Options inside Options in arguments and events,
|
|
55
|
+
loop-scoped `loadAccountMut` with `Dup<T>`, account resizing and raw writes, `systemProgram.createPda` (0.39.0), and
|
|
56
|
+
the native-program surface: `loadRaw` / `loadRawMut` (accounts without a discriminator), instruction data readers,
|
|
57
|
+
error code 0, built-in ProgramErrors, `panic`, `PANIC_ON_OVERFLOW` (0.40.0). An external review should include them;
|
|
58
|
+
the native-program surface first, since it skips the account checks Anchor-style parameters get.
|
|
57
59
|
|
|
58
60
|
- **0.25.0** (runtime and emitted checks): two Medium issues fixed, a remaining account loaded mutably twice through
|
|
59
61
|
the same slot, and a Vec element written after its right side resized the Vec; plus a token program ambiguity,
|
|
@@ -6,7 +6,7 @@ mainnet as `MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA` (version 0.1.12 in its
|
|
|
6
6
|
456093551), not a rebuild.
|
|
7
7
|
|
|
8
8
|
Marginfi is large: 124 instructions, 12 zero-copy accounts, 255 errors, and its amounts, prices and rates in I80F48
|
|
9
|
-
fixed point.
|
|
9
|
+
fixed point. All 124 are ported, in five parts, each checked against the binary before the next:
|
|
10
10
|
|
|
11
11
|
| Part | What | Status |
|
|
12
12
|
| --- | --- | --- |
|
|
@@ -14,7 +14,7 @@ fixed point. The port comes in parts, each checked before the next:
|
|
|
14
14
|
| 2 | Group and bank administration, interest; accounts, deposits, repayments and fees | done |
|
|
15
15
|
| 3 | Oracles, the risk engine, withdrawals and borrows | done |
|
|
16
16
|
| 4 | Liquidation and bankruptcy | done |
|
|
17
|
-
| 5 | The rest: flash loans, administration, orders, staked SOL, the integrations |
|
|
17
|
+
| 5 | The rest: flash loans, administration, orders, staked SOL, the integrations | done |
|
|
18
18
|
|
|
19
19
|
The files are in [`showcase/mainnet/marginfi`](https://github.com/typesol-lang/typesol/tree/main/showcase/mainnet/marginfi):
|
|
20
20
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Case study: Raydium AMM v4
|
|
2
|
+
|
|
3
|
+
This page ports [Raydium AMM v4](https://github.com/raydium-io/raydium-amm), Raydium's original constant-product AMM,
|
|
4
|
+
from `program/src` at d26944b (Apache-2.0). The port is checked against the binary that runs on mainnet as
|
|
5
|
+
`675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8` (deployed in slot 445763204, dumped in slot 466115597), not a rebuild.
|
|
6
|
+
|
|
7
|
+
Unlike the other ports here, AMM v4 is a native program: no Anchor. Its entrypoint reads a tag byte and the arguments
|
|
8
|
+
after it, takes its accounts by position (a swap accepts 17 or 18 of them, the v2 swaps 8), keeps its accounts as
|
|
9
|
+
`#[repr(C, packed)]` structs with no discriminator, and fails with built-in program errors and panics as often as with
|
|
10
|
+
its own errors. The port keeps all of that.
|
|
11
|
+
|
|
12
|
+
| File | Holds |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| [`raydium_amm.ts`](../showcase/mainnet/raydium-amm/raydium_amm.ts) | the entrypoint (one `@fallback` over `instructionData()` and `remainingAccounts()`), every instruction, the token and system CPIs, the P&L calculation |
|
|
15
|
+
| [`state.ts`](../showcase/mainnet/raydium-amm/state.ts) | AmmInfo (752 bytes), TargetOrders, AmmConfig, Fees, the ray_log records, the 61 errors (codes 0–60) |
|
|
16
|
+
| [`math.ts`](../showcase/mainnet/raydium-amm/math.ts) | decimal normalization, the constant-product amounts, the exchange rates, with the original's panics at their places |
|
|
17
|
+
|
|
18
|
+
## What is ported
|
|
19
|
+
|
|
20
|
+
All of it. The live instructions: Initialize2 (tag 1, both its 19- and 21-account forms), Deposit (3, 11 or 14–15
|
|
21
|
+
accounts, the optional minimum), Withdraw (4, 11 or 20–23 accounts, the optional minimums), SetParams (6: status, state,
|
|
22
|
+
fees, open time), WithdrawPnl (7), SwapBaseIn / SwapBaseOut (9 / 11, 17 or 18 accounts), CreateConfigAccount (14),
|
|
23
|
+
UpdateConfigAccount (15), SwapBaseInV2 / SwapBaseOutV2 (16 / 17, 8 accounts) and WithdrawExcessLamports (18). The
|
|
24
|
+
retired ones (0, 2, 5, 8, 10, 12, 13) panic with `not implemented` at the original's source location, as it does.
|
|
25
|
+
The order book (OpenBook) was removed upstream in July 2026; its accounts are still accepted where the original
|
|
26
|
+
accepts them, and ignored.
|
|
27
|
+
|
|
28
|
+
## What it needed
|
|
29
|
+
|
|
30
|
+
TypeSOL gained what a native program needs (docs/language.md, "Porting a native program"):
|
|
31
|
+
|
|
32
|
+
- `loadRaw<T>` / `loadRawMut<T>`: accounts with no discriminator, read from byte 0. The port makes the original's own
|
|
33
|
+
checks first (owner, an exact size, its error codes), then loads.
|
|
34
|
+
- `instructionData().readU64(offset)` and the other little-endian readers, for the hand-packed arguments (optional
|
|
35
|
+
ones are present when enough bytes follow).
|
|
36
|
+
- Errors from code 0 (returned as Solana's CUSTOM_ZERO, as `ProgramError::Custom(0)` is), `ProgramError.X` for the
|
|
37
|
+
built-in errors (`NotEnoughAccountKeys`, `InvalidInstructionData`, `InsufficientFunds`), `panic(message, location)`
|
|
38
|
+
and `PANIC_ON_OVERFLOW` for `unwrap()` and checked arithmetic, `ERROR_LOG_PREFIX` / `PROGRAM_ERROR_LOG_PREFIX` for the
|
|
39
|
+
entrypoint's "AMM error: …" / "Program error: …" lines.
|
|
40
|
+
- `logBase64` for the ray_log records (bincode of a packed struct, base64), `createProgramAddress` for the authority
|
|
41
|
+
derived from the stored nonce, and `isqrt` of a u256 (the P&L uses U256).
|
|
42
|
+
|
|
43
|
+
## How it is checked
|
|
44
|
+
|
|
45
|
+
`showcase/test/raydium-amm.test.ts` runs the mainnet binary and the port in two LiteSVMs under the same program id
|
|
46
|
+
and clock. Raydium's three fixed keys (its admin, the pool fee destination and the lamports collector) are swapped for
|
|
47
|
+
test keys in both, in the original where its code loads them (lddw immediates) and in the port's source, so the admin
|
|
48
|
+
instructions run too. Every transaction must give the same outcome, the same bytes in every account it touches and
|
|
49
|
+
the same log lines: the ray_log records, the original's messages ("initialize2: …", "withdrawpnl …", mismatch lines),
|
|
50
|
+
the entrypoint's error lines and, for panics, the message and the source location the runtime reports.
|
|
51
|
+
|
|
52
|
+
Covered: pool creation in both forms (open now and later), swaps in both directions, base in and base out, in all three
|
|
53
|
+
account forms; refusals (slippage, more than held, zero, the whole pool out, wrong account counts, short data, a vault
|
|
54
|
+
as the user's account, a wrong token program); deposits on either side with and without the minimum, withdrawals with
|
|
55
|
+
and without minimums, amounts past u64; status, state, fees and open time changes and their refusals; the P&L taken by
|
|
56
|
+
the P&L owner after the pool grew; config creation and updates; the retired tags; excess lamports; and a random mix of
|
|
57
|
+
swaps, deposits and withdrawals (`FUZZ_SEED`, `FUZZ_STEPS`). 484 transactions in all at 400 fuzz steps.
|
|
58
|
+
|
|
59
|
+
## Differences
|
|
60
|
+
|
|
61
|
+
None found in outcomes, account bytes or log lines. Two things are outside what the test compares:
|
|
62
|
+
|
|
63
|
+
- **Compute-unit lines** ("consumed N of M compute units") differ, by design (see below).
|
|
64
|
+
- **Overflow panics the inputs cannot reach.** The original's `checked_*().unwrap()` sites that user input can reach
|
|
65
|
+
(a base-out swap for the whole side or more, an exchange rate past u64, a zero total) panic in the port with the
|
|
66
|
+
original's message and location. Arithmetic that cannot overflow for any input (u64 by u64 products in u128, for
|
|
67
|
+
instance) still panics there under `PANIC_ON_OVERFLOW`, but with an empty location.
|
|
68
|
+
|
|
69
|
+
## Cost
|
|
70
|
+
|
|
71
|
+
| | original | TypeSOL | |
|
|
72
|
+
| --- | ---: | ---: | ---: |
|
|
73
|
+
| swap base in (v2) | 15,222 | 6,597 | 43% |
|
|
74
|
+
| swap base out (v2) | 15,894 | 6,800 | 43% |
|
|
75
|
+
| swap base in (17 accounts) | 16,317 | 6,875 | 42% |
|
|
76
|
+
| deposit | 44,406 | 16,544 | 37% |
|
|
77
|
+
| withdraw | 45,278 | 16,045 | 35% |
|
|
78
|
+
| initialize2 | 107,403 | 62,158 | 58% |
|
|
79
|
+
|
|
80
|
+
The binary is 147,536 bytes against the original's 308,616.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Case study: Raydium CP-Swap
|
|
2
2
|
|
|
3
|
-
This page ports
|
|
3
|
+
This page ports a production AMM, every instruction of it: [Raydium CP-Swap](https://github.com/raydium-io/raydium-cp-swap)
|
|
4
4
|
(`programs/cp-swap`, Anchor 1.0.2, Apache-2.0). It is deployed on mainnet at
|
|
5
5
|
`CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C`. The port is [`showcase/mainnet/raydium-cp-swap/`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/raydium-cp-swap)
|
|
6
6
|
(`state.ts`, `curve.ts`, `raydium_cp_swap.ts`). As with [coral-xyz/multisig](case-study-multisig.md), it is checked
|
|
@@ -8,32 +8,24 @@ against the binary that runs on mainnet, not a rebuild.
|
|
|
8
8
|
|
|
9
9
|
## What is ported
|
|
10
10
|
|
|
11
|
-
The port covers
|
|
11
|
+
The port covers all 21 of the original's instructions:
|
|
12
12
|
|
|
13
|
-
- `initialize`,
|
|
13
|
+
- pool creation: `initialize`, `initialize_v2` (the same without the rent sysvar, choosing the creator fee) and
|
|
14
|
+
`initialize_with_permission` (for a payer Raydium authorized, on behalf of another creator, with the creator fee on);
|
|
14
15
|
- the four trading instructions: `swap_base_input`, `swap_base_output`, `deposit` and `withdraw`;
|
|
15
|
-
- `collect_protocol_fee` and
|
|
16
|
-
|
|
16
|
+
- the fees: `collect_protocol_fee`, `collect_fund_fee`, `collect_creator_fee` and
|
|
17
|
+
`collect_creator_fee_permissionless`;
|
|
18
|
+
- the admin instructions: `create_amm_config`, `update_amm_config`, `update_pool_status`, `create_permission_pda`,
|
|
19
|
+
`close_permission_pda`, `create_creator_fee_share`, `close_creator_fee_share`, `create_support_mint_associated`,
|
|
20
|
+
`close_support_mint_associated` and `collect_excess_lamports`.
|
|
17
21
|
|
|
18
22
|
The port keeps the original's account layouts:
|
|
19
23
|
|
|
20
|
-
- `AmmConfig`
|
|
24
|
+
- `AmmConfig`, `Permission`, `CreatorFeeShare` and `SupportMintAssociated` are Borsh accounts of fixed size.
|
|
21
25
|
- `PoolState` and `ObservationState` are zero-copy `#[repr(C, packed)]` structs, which is TypeSOL's fixed layout.
|
|
22
26
|
|
|
23
|
-
It also keeps the original's names, argument order and error codes, and emits the same events
|
|
24
|
-
`LpChangeEvent`). Existing pools, clients and indexers work with it unchanged.
|
|
25
|
-
|
|
26
|
-
These are not ported yet:
|
|
27
|
-
|
|
28
|
-
- **`initialize_with_permission`.** It is `initialize` for a creator the admin authorized, with the creator fee on.
|
|
29
|
-
- **The creator-fee instructions**: `collect_creator_fee`, `collect_creator_fee_permissionless`,
|
|
30
|
-
`create_creator_fee_share` and `close_creator_fee_share`.
|
|
31
|
-
- **The permission instructions**: `create_permission_pda` and `close_permission_pda`.
|
|
32
|
-
- **The support-mint instructions**: `create_support_mint_associated` and `close_support_mint_associated`.
|
|
33
|
-
- **`collect_excess_lamports`.**
|
|
34
|
-
|
|
35
|
-
The pool logic these depend on is in the port (fee booking, the creator-fee split in the swap math, tested below with
|
|
36
|
-
the creator fee on), so a pool the original created and configured is traded the same way.
|
|
27
|
+
It also keeps the original's names, account order, argument order and error codes, and emits the same events
|
|
28
|
+
(`SwapEvent`, `LpChangeEvent`). Existing pools, clients and indexers work with it unchanged.
|
|
37
29
|
|
|
38
30
|
## What it needed
|
|
39
31
|
|
|
@@ -56,6 +48,10 @@ Four Token-2022 reads were added to the compiler for this port (`test/integratio
|
|
|
56
48
|
- `transferFeeBasisPoints(mint)` and `transferFeeMaximum(mint)`: the fee in force this epoch.
|
|
57
49
|
- `extensionsWithin(account, [types])`: the original's list of mint extensions a pool accepts.
|
|
58
50
|
|
|
51
|
+
The instructions added later needed none: `Ata<InitIfNeeded<…>>` for the creator's token accounts, `CloseTo` for the
|
|
52
|
+
closing instructions, `readData` to read a token account as `StateWithExtensions::unpack` does, and `invoke` for the
|
|
53
|
+
token instructions Anchor has no wrapper for (`WithdrawExcessLamports`, `SyncNative`, `UnwrapLamports`).
|
|
54
|
+
|
|
59
55
|
The rest uses features TypeSOL already had:
|
|
60
56
|
|
|
61
57
|
- `constraint(…)`, for Anchor's `address = pool_state.load()?.amm_config` and `constraint = …` in Anchor's order;
|
|
@@ -66,21 +62,24 @@ The rest uses features TypeSOL already had:
|
|
|
66
62
|
## How it was checked
|
|
67
63
|
|
|
68
64
|
[`showcase/test/raydium-cp-swap.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/raydium-cp-swap.test.ts) loads the binary dumped from
|
|
69
|
-
mainnet on 2026-
|
|
65
|
+
mainnet on 2026-11-07 (deployed at slot 463522946 on 2026-10-31; sha256 in [`test/programs/SOURCES.md`](https://github.com/typesol-lang/typesol/blob/main/test/programs/SOURCES.md)) into one
|
|
70
66
|
LiteSVM and the port into another. Both use the same program id and the same clock.
|
|
71
67
|
|
|
72
68
|
**Setup.**
|
|
73
69
|
|
|
74
70
|
- Mints and token accounts are made by the same SPL Token / Token-2022 instructions in both.
|
|
75
|
-
-
|
|
76
|
-
|
|
71
|
+
- Raydium's five signing keys (the admin, and the owners of permissions, fee shares, supported mints and excess
|
|
72
|
+
lamports) are replaced by test keys in both: in the original, at each place its code loads one (four 64-bit
|
|
73
|
+
immediates); in the port, in its source. The admin instructions then run in both.
|
|
74
|
+
- Pools for trading (an `AmmConfig`, a pool's `PoolState` and its `ObservationState`) are written in both as the
|
|
75
|
+
original lays them out, so each test starts from the state it needs.
|
|
77
76
|
|
|
78
77
|
**Comparison.** For each transaction, the test requires the same outcome (success, or the same error down to the
|
|
79
78
|
code), the same lamports, owner and data for every account involved, and the same events byte for byte.
|
|
80
79
|
|
|
81
|
-
There are
|
|
80
|
+
There are 136 transactions:
|
|
82
81
|
|
|
83
|
-
- **Pool creation.**
|
|
82
|
+
- **Pool creation.** With `initialize`, these cases are covered:
|
|
84
83
|
- a pool at its PDA, at a signing keypair, and at a pre-funded address;
|
|
85
84
|
- a pool with the creation fee, paid in wrapped SOL;
|
|
86
85
|
- a pool of Token-2022 fee mints;
|
|
@@ -90,12 +89,26 @@ There are 70 transactions:
|
|
|
90
89
|
- an unsupported extension (6007);
|
|
91
90
|
- a disabled config (6000);
|
|
92
91
|
- too little liquidity (6009).
|
|
92
|
+
|
|
93
|
+
`initialize_v2` with the creator fee off and on in each of its three modes, and its refusals.
|
|
94
|
+
`initialize_with_permission` without a permission (3007), with another payer's (2006), and with one.
|
|
93
95
|
- **Swaps.** Both directions, by input and by output; the observation ring advancing as the clock moves; slippage
|
|
94
96
|
(6005); zero amounts.
|
|
95
97
|
- **Liquidity.** Deposit, a partial withdrawal, slippage both ways, withdrawing more LP than held, zero.
|
|
96
98
|
- **Fees.** Protocol and fund fees collected by their owners after trading, and refused for anyone else (6001).
|
|
97
99
|
- **Creator fees.** Pools with the creator fee on at 0.05%, taken from the input token, only token_0, or only
|
|
98
|
-
token_1: swaps both ways, by input and by output, booking the fee on the right side.
|
|
100
|
+
token_1: swaps both ways, by input and by output, booking the fee on the right side. Collected by the creator (its
|
|
101
|
+
token accounts created on the way) at the config's share, again with nothing owed (6014), with the creator's own
|
|
102
|
+
share, by anyone with the permissionless form, at the config's share again after the share is closed, for SPL Token
|
|
103
|
+
and Token-2022 fee mints; a share above 100% (6003); anyone but the creator (2012).
|
|
104
|
+
- **Permissions, fee shares, supported mints.** Each created and closed by Raydium's keys and refused for anyone else
|
|
105
|
+
(6001, 6000); a fee share above 100% (6003); a permission created twice; a supported-mint entry for an SPL Token
|
|
106
|
+
mint (6000). A Token-2022 mint with a permanent delegate is refused for a pool (6007) until it is listed and the
|
|
107
|
+
entry passed, and again without the entry.
|
|
108
|
+
- **Excess lamports.** Swept from the pool and its observation account (rent kept), from an SPL Token and a Token-2022
|
|
109
|
+
vault and the LP mint (`WithdrawExcessLamports`), from wrapped SOL held by the pool authority (`SyncNative`, then
|
|
110
|
+
`UnwrapLamports` of exactly the difference); a trader's account (the token program's OwnerMismatch, 4); anyone but
|
|
111
|
+
the two keys (6001).
|
|
99
112
|
- **The price oracle.** A new point, a second swap within 15 seconds (added to the current point), and a ring at its
|
|
100
113
|
last slot whose cumulative price is 10 below `u128::MAX`: the next point wraps to slot 0 and the sum wraps around.
|
|
101
114
|
- **Token-2022.** A pool of two transfer-fee mints (1.5% and 0.37%): swaps both ways and by output, deposit and
|
|
@@ -107,28 +120,45 @@ There are 70 transactions:
|
|
|
107
120
|
- Swaps or deposits on a pool whose status disables them (6000).
|
|
108
121
|
- The admin instructions sent by anyone but the admin (2012, 6001).
|
|
109
122
|
|
|
123
|
+
**Fuzzing.** A random sequence (`FUZZ_SEED` reproduces one, `CP_FUZZ_STEPS` lengthens it; 120 steps by default) runs
|
|
124
|
+
in two pools, one of SPL Token mints and one of Token-2022 mints with random transfer fees, each with the creator fee
|
|
125
|
+
on in a random mode at a random rate and protocol share: swaps both ways by input and by output with random amounts
|
|
126
|
+
and slippage limits, deposits, withdrawals, creator fee collections (by the creator and permissionless), protocol and
|
|
127
|
+
fund fee collections, and the clock moving on. Every step must give the same outcome, account bytes and events as the
|
|
128
|
+
original. Runs of 600 steps on several seeds found one difference, now fixed: an exact-output swap for the whole
|
|
129
|
+
vault or more panics in the original (`checked_sub(..).unwrap()`, `checked_ceil_div(..).unwrap()`), where the port
|
|
130
|
+
failed with 5100; it panics now at the original's location. These fuzz transactions are not in the 136 above.
|
|
131
|
+
|
|
110
132
|
## Cost
|
|
111
133
|
|
|
112
134
|
Compute units per transaction, mainnet original against the port, from that test:
|
|
113
135
|
|
|
114
136
|
| Instruction | Raydium (mainnet) | TypeSOL | |
|
|
115
137
|
| --- | ---: | ---: | ---: |
|
|
116
|
-
| `initialize` | 83,
|
|
117
|
-
| `initialize`, Token-2022 transfer fees |
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
138
|
+
| `initialize` | 83,559 | 39,878 | −52% |
|
|
139
|
+
| `initialize`, Token-2022 transfer fees | 93,047 | 53,834 | −42% |
|
|
140
|
+
| `initialize_v2`, creator fee on | 86,286 | 41,760 | −52% |
|
|
141
|
+
| `initialize_with_permission` | 98,221 | 43,358 | −56% |
|
|
142
|
+
| `swap_base_input` | 24,162 | 5,734 | −76% |
|
|
143
|
+
| `swap_base_output` | 24,591 | 5,989 | −76% |
|
|
144
|
+
| `deposit` | 25,007 | 6,194 | −75% |
|
|
145
|
+
| `withdraw` | 25,214 | 6,203 | −75% |
|
|
122
146
|
| `collect_protocol_fee` | 20,205 | 4,189 | −79% |
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
147
|
+
| `collect_creator_fee`, creating the creator's two token accounts | 61,644 | 34,014 | −45% |
|
|
148
|
+
| `collect_creator_fee_permissionless` | 28,165 | 5,887 | −79% |
|
|
149
|
+
| `create_permission_pda` | 10,525 | 2,291 | −78% |
|
|
150
|
+
| `create_creator_fee_share` | 8,421 | 2,067 | −75% |
|
|
151
|
+
| `create_support_mint_associated` | 7,837 | 2,012 | −74% |
|
|
152
|
+
| `close_creator_fee_share` | 5,169 | 767 | −85% |
|
|
153
|
+
| `collect_excess_lamports`, wrapped SOL | 10,798 | 3,764 | −65% |
|
|
154
|
+
| `swap_base_input`, Token-2022 transfer fees | 31,339 | 12,082 | −61% |
|
|
155
|
+
| `swap_base_output`, Token-2022 transfer fees | 32,508 | 14,097 | −57% |
|
|
156
|
+
| `deposit`, Token-2022 transfer fees | 33,203 | 14,478 | −56% |
|
|
126
157
|
|
|
127
158
|
The Token-2022 rows include the token program's own work, which is the same in both. Refusals cost far less. For
|
|
128
|
-
example, a swap through the wrong config costs 17,
|
|
159
|
+
example, a swap through the wrong config costs 17,193 against 1,656.
|
|
129
160
|
|
|
130
|
-
On size, the port's binary is
|
|
131
|
-
14 instructions not ported here, so the size ratio overstates the gain for the same feature set.
|
|
161
|
+
On size, the port's binary is 214,944 bytes and the deployed original is 749,848 bytes, for the same 21 instructions.
|
|
132
162
|
|
|
133
163
|
Pool creation is mostly the token programs' and the System Program's own work (account creation, initialization,
|
|
134
164
|
transfers), which costs the same in both. The difference is the program's part. Its cost also varies from run to run
|
|
@@ -141,12 +171,18 @@ when the values fit, and an instruction reads the Clock once. Together they took
|
|
|
141
171
|
|
|
142
172
|
- **Panics.** Where the original calls `unwrap()` or `assert!`, it aborts with `ProgramFailedToComplete`. The port
|
|
143
173
|
fails with a numbered error instead:
|
|
144
|
-
-
|
|
145
|
-
- a division by zero, 5101: the price of an empty side, or an exact-output swap for exactly what the vault holds;
|
|
174
|
+
- a division by zero, 5101: the price of an empty side;
|
|
146
175
|
- invalid input, 6003: a fee rate out of range in the admin instructions, which only the admin can reach.
|
|
176
|
+
- an overflow adding to the destination's lamports in `collect_excess_lamports`, 5100 where the original returns
|
|
177
|
+
`ArithmeticOverflow`: no account holds that many lamports.
|
|
147
178
|
|
|
148
|
-
The swaps and liquidity instructions reach none of these with the amounts a pool can hold.
|
|
179
|
+
The swaps and liquidity instructions reach none of these with the amounts a pool can hold. An exact-output swap for
|
|
180
|
+
the whole vault or more, which a trader can send, panics as the original does (fuzzing found it).
|
|
149
181
|
- **Check order on double faults.** Account checks run in Anchor's order, so a transaction breaking one check gets the
|
|
150
182
|
same code. The port keeps the pool's `address = …` and `token::…` constraints as `constraint(…)` calls in Anchor's
|
|
151
183
|
order. A transaction that breaks a token check and an account-type check at once can still be reported differently.
|
|
184
|
+
- **Token accounts in `collect_excess_lamports`.** The original reads a remaining account as a token account with
|
|
185
|
+
`StateWithExtensions::unpack`, which also walks the Token-2022 extension list. The port checks the size, the
|
|
186
|
+
account type byte, the state and the option tags, not the extension list: a Token-2022 account the token program
|
|
187
|
+
wrote always has a valid one.
|
|
152
188
|
- **Logs.** Error messages are TypeSOL's. Codes and events are the original's.
|
package/docs/language.md
CHANGED
|
@@ -49,9 +49,9 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
49
49
|
| Multiple files | `import { Side, min } from "./math"` — structs, enums, constants and helpers can live in other files; only the entry file's exported functions are instructions; names are program-wide, so imports from TypeSOL files cannot be renamed; error codes number imported files first |
|
|
50
50
|
| Loops | `for (let i = 0n; i < n; i++)`, `while`, `do … while`, `for (const x of list)` over a `Vec` or `FixedArray` (each `x` is what `list.get(i)` gives: a value, or a reference into account data for structs; the length is read again every step, as in JS), `break`, `continue` — bounded by the compute budget. Remaining accounts are iterated by index |
|
|
51
51
|
| Helpers | non-exported functions (and every function of an imported file): take values, structs, Vec arguments, `SignerSeeds`, remaining accounts (`RemainingAccount`, or the list: `RemainingAccounts`) and accounts the instruction already checked (`Signer`, `AccountInfo`/`AccountMeta`, `Mut<T>`, token accounts, programs); return `void`, a scalar, a `string`, a function (see below) or a fixed-size struct (`function at(x: u64, y: u64): Point { return { x, y }; }`: the caller gets its own copy, to bind, store with `acct.home = at(…)` / `arr.set(i, at(…))` or read as `at(…).x`); no recursion. A helper that takes a struct account as `Mut<T>` can grow its Vec (`push(value, payer)`: the account's size at instruction entry is passed along) |
|
|
52
|
-
| Arrow functions and closures | `const fee = (x: u64): u64 => x / 100n` (or `const f = function (…) {…}`) at the top level or inside a function. One that reads or writes the enclosing function's variables (a closure: `let total = 0n; const add = (v: u64): void => { total += v; }`) is expanded where it is called: its names mean what they meant where it was declared, struct parameters are references, `return` leaves the closure; it cannot call itself. One that captures nothing becomes a helper. Parameter types may be left out on closures (taken from the arguments). Functions are values where they can be expanded: `const h = g` names the same function, and a function that returns one (`function adder(n: u64): (x: u64) => u64 { return (x) => x + n; }`) makes a closure where it is called (`const add5 = adder(5n)`, or `adder(5n)(x)`) |
|
|
52
|
+
| Arrow functions and closures | `const fee = (x: u64): u64 => x / 100n` (or `const f = function (…) {…}`) at the top level or inside a function. One that reads or writes the enclosing function's variables (a closure: `let total = 0n; const add = (v: u64): void => { total += v; }`) is expanded where it is called: its names mean what they meant where it was declared, struct parameters are references, `return` leaves the closure; it cannot call itself. One that captures nothing becomes a helper. Parameter types may be left out on closures (taken from the arguments). Functions are values where they can be expanded: `const h = g` names the same function, and a function that returns one (`function adder(n: u64): (x: u64) => u64 { return (x) => x + n; }`) makes a closure where it is called (`const add5 = adder(5n)`, or `adder(5n)(x)`). A function can be chosen at run time between named ones, `const g = k === 1n ? dbl : inc` (the condition is read once, there; a call runs only the chosen one), and a list of named functions can be run in turn, `for (const f of [dbl, inc]) total += f(x)` (unrolled; `continue` and `break` work) |
|
|
53
53
|
| Functions as arguments | a helper may take a function parameter (`function applyTwice(f: (x: u64) => u64, v: u64): u64`): it is compiled once per named function passed (a helper or a local function that captures nothing). An arrow written at the call works too (`applyTwice((x) => x * 3n, v)`: its types come from the parameter) when it reads none of the function's variables. Given a closure (one that reads them), the helper is expanded where it is called instead, like a closure, so it runs where the closure can (its type parameters bound from the call, its accounts the caller's) |
|
|
54
|
-
| List callbacks | on a `Vec`, `FixedArray`, `FixedVec` or `Vec` argument: `forEach`, `some`, `every`, `find` (an Option of the element; scalar elements), `findIndex` (i64, -1 when absent), `reduce(fn, initial)`, `includes(value)`, `indexOf(value)` (i64), `map` and `filter`. The arrow written at the call is expanded into a loop (elements as `list.get(i)` gives them, structs by reference) and may read and write the function's variables. A `map` / `filter` chain used right away (`xs.filter(f).map(g).reduce(h, 0n)`, `.length`, `for … of`) is one loop that stores nothing; callbacks after a filter get the index among the elements it let through. Stored (`const ys = xs.filter(f)`), it is a FixedVec on the stack as big as the list it starts from; from a `Vec`, give the size: `const ys: FixedVec<u64, 16> = …` (at most 2 KiB; one element more aborts with 5104). `map` gives integers, booleans, Pubkeys or enums; stored with a `FixedVec<Struct, N>` or `FixedVec<FixedString<N>, M>` annotation it gives structs (`(o) => ({ qty: o.qty })`) or text |
|
|
54
|
+
| List callbacks | on a `Vec`, `FixedArray`, `FixedVec` or `Vec` argument: `forEach`, `some`, `every`, `find` (an Option of the element; scalar elements; on struct elements read a field with `xs.find(f)!.qty`, which aborts with 5108 when nothing matched, or `xs.find(f)?.qty`, an Option), `findIndex` (i64, -1 when absent), `reduce(fn, initial)`, `includes(value)`, `indexOf(value)` (i64), `map` and `filter`. The arrow written at the call is expanded into a loop (elements as `list.get(i)` gives them, structs by reference) and may read and write the function's variables. A `map` / `filter` chain used right away (`xs.filter(f).map(g).reduce(h, 0n)`, `.length`, `for … of`) is one loop that stores nothing; callbacks after a filter get the index among the elements it let through. Stored (`const ys = xs.filter(f)`), it is a FixedVec on the stack as big as the list it starts from; from a `Vec`, give the size: `const ys: FixedVec<u64, 16> = …` (at most 2 KiB; one element more aborts with 5104). `map` gives integers, booleans, Pubkeys or enums; stored with a `FixedVec<Struct, N>` or `FixedVec<FixedString<N>, M>` annotation it gives structs (`(o) => ({ qty: o.qty })`) or text, and inside a chain it gives structs when the callback names its struct, `xs.map((o): Scored => ({ … })).filter(…).reduce(…)` (one struct per element, nothing stored) |
|
|
55
55
|
| Generic helpers | `function max<T extends bigint>(a: T, b: T): T` — compiled once per set of types it is called with (`max(a, b)` with u64 arguments, or `max<u128>(x, 1n)` when only literals tell); a type parameter stands for an integer, boolean, Pubkey, enum or fixed-size struct (`pick<Point>(…)`, or from struct arguments; a struct `T` is copied like any struct value). Each instance is checked like any helper; one that is never called is not compiled (TypeScript still type-checks it). Arithmetic on `T` is a `bigint` to TypeScript: `return (a + b) as T` (`as` names a type the value already has; it never converts) |
|
|
56
56
|
| Evaluation order | operands and arguments are read left to right, as in JS, even when a later one changes account data (`v.length + v.pop()`) |
|
|
57
57
|
| `++` `--` `+=` `-=` `*=` `/=` `%=` `&=` `\|=` `^=` `<<=` `>>=` | all checked |
|
|
@@ -212,13 +212,33 @@ When an instruction calls `x.create(payer, seeds)` or `requirePda(x, seeds, bump
|
|
|
212
212
|
an integer literal, an argument, `acct.key` or a scalar field of an account, the IDL entry for `x` gets Anchor `pda.seeds`
|
|
213
213
|
(`const` / `arg` / `account`), so Anchor and Codama clients derive the address themselves.
|
|
214
214
|
|
|
215
|
+
## Porting a native program
|
|
216
|
+
|
|
217
|
+
A program written without Anchor (Raydium AMM v4, SPL programs) reads a tag byte and its arguments itself and takes its
|
|
218
|
+
accounts by position. TypeSOL ports one as it is (see `showcase/mainnet/raydium-amm` and `test/fixtures/native.ts`):
|
|
219
|
+
|
|
220
|
+
- One `/** @fallback */` entry: `const data = instructionData()` gives the bytes, with `data.readU8/U16/U32/U64/U128/
|
|
221
|
+
readPubkey(offset)` (little-endian, bounds-checked: 5104); `remainingAccounts()` gives the accounts by position.
|
|
222
|
+
- Accounts without a discriminator: `loadRaw<T>(acct)` / `loadRawMut<T>(acct)` view one as a fixed-layout struct from
|
|
223
|
+
byte 0 (this program's, 3007; at least the struct's size, 3003; `loadRawMut`: writable, loaded once). Make the
|
|
224
|
+
original's own checks (an exact size, its error codes) before the load. Structs are packed, as `#[repr(C, packed)]`.
|
|
225
|
+
- Errors as the original returns them: an error enum may start at code 0 (`/** @code 0 */`, Rust's
|
|
226
|
+
`ProgramError::Custom(0)`, returned as Solana's CUSTOM_ZERO); `require(c, ProgramError.InvalidInstructionData)` for a
|
|
227
|
+
built-in error; `panic(message, "program/src/lib.rs:12:5")` for a Rust panic (ProgramFailedToComplete, the runtime
|
|
228
|
+
reporting that location); `const PANIC_ON_OVERFLOW = true` makes arithmetic overflow and division by zero panic as
|
|
229
|
+
`checked_*().unwrap()` does instead of failing with 5100 / 5101.
|
|
230
|
+
- Log lines as the original writes them: `const ERROR_LOG_PREFIX = "AMM error: "` and `const PROGRAM_ERROR_LOG_PREFIX =
|
|
231
|
+
"Program error: "` replace the compiler's failure line with the entrypoint's (`msg!("AMM error: {}", e)`);
|
|
232
|
+
`logBase64("ray_log: ", record)` logs a struct's bytes in base64 (a native `bincode` log record);
|
|
233
|
+
`createProgramAddress(seeds, program)` is `Pubkey::create_program_address` (null for no address).
|
|
234
|
+
|
|
215
235
|
## Not supported yet
|
|
216
236
|
|
|
217
|
-
A struct holding a FixedVec that is both an argument and account data (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
a
|
|
221
|
-
(by design).
|
|
237
|
+
A struct holding a FixedVec that is both an argument and account data (its bytes differ there, and the IDL describes a
|
|
238
|
+
type one way: declare one for each), growing an account by more than 10 KiB in one instruction (Solana's limit: realloc
|
|
239
|
+
again in the next instruction), `?.` and `!` on anything but optional accounts, Options and a `find` on struct elements,
|
|
240
|
+
functions stored in a struct, chosen from a list by index or returned from an instruction, a fused `map` to strings
|
|
241
|
+
(store it, annotated), floating point (by design).
|
|
222
242
|
They are rejected at compile time rather than half-supported.
|
|
223
243
|
|
|
224
244
|
`Init.create` handles a PDA address someone pre-funded: it tops up rent, then allocates and assigns instead of
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Stability and the road to 1.0
|
|
2
|
+
|
|
3
|
+
TypeSOL is pre-1.0. Until 1.0, a minor release (0.x → 0.y) may change the language, the account and IDL layout of
|
|
4
|
+
generated programs and error codes, and says so in the CHANGELOG ([versioning
|
|
5
|
+
policy](https://github.com/typesol-lang/.github/blob/main/VERSIONING.md)). This page says what 1.0 will promise, which
|
|
6
|
+
parts are already meant to stay as they are, and what has to be settled first.
|
|
7
|
+
|
|
8
|
+
## What 1.0 will promise
|
|
9
|
+
|
|
10
|
+
From 1.0 on, within a major version:
|
|
11
|
+
|
|
12
|
+
- **Sources keep compiling.** A program that compiles with 1.x compiles with every later 1.y, to a program with the same
|
|
13
|
+
account layouts, IDL, instruction and account discriminators and error codes. New releases add; they do not take away.
|
|
14
|
+
- **Binaries are reproducible and only change for a reason.** A release that changes the binary of a program that uses
|
|
15
|
+
none of its new features says so, with the release manifest's diff (`binary-diff.txt`) as the evidence.
|
|
16
|
+
- **The checks stay.** No check a program gets from its parameter types (owner, discriminator, signer, writability,
|
|
17
|
+
aliasing, checked arithmetic, constraints) is removed or weakened.
|
|
18
|
+
- **The tools keep their interfaces**: `typesol build`, `test` (via `typesol/testing`), `check --json`, `deploy`,
|
|
19
|
+
`verify`, `idl`, the typed client, and `typesol.json`.
|
|
20
|
+
|
|
21
|
+
## Stable already
|
|
22
|
+
|
|
23
|
+
Meant to stay as they are; a change before 1.0 would be a breaking change listed as one:
|
|
24
|
+
|
|
25
|
+
- Types: the integers (`u8` … `u128`, `i8` … `i128`), `boolean`, `Pubkey`, `Hash`, structs, `FixedArray`, `FixedVec`,
|
|
26
|
+
`Vec`, `FixedString`, `Option`, unit and data enums, `u256` in computation.
|
|
27
|
+
- Account parameters and their checks: `Signer`, `Account<T>`, `Mut<T>`, `Init<T>`, `InitIfNeeded<T>`, `Zeroed<T>`,
|
|
28
|
+
optional accounts, token accounts and mints, programs, sysvars, account groups; the constraints (`HasOne`, `Seeds`,
|
|
29
|
+
`CloseTo`, `Ata`, `Address`, `Owner`, `Executable`).
|
|
30
|
+
- Errors and events: error enums and their codes, `require`, `AnchorError`, `emit`, `emitCpi`.
|
|
31
|
+
- CPIs: System, SPL Token, Token-2022, Associated Token, Memo, generic `invoke` with PDA signing.
|
|
32
|
+
- Layouts: account data (Anchor's discriminator and fixed or `@layout borsh` layout), the IDL, the client.
|
|
33
|
+
|
|
34
|
+
## Experimental
|
|
35
|
+
|
|
36
|
+
Useful today, but may still change before 1.0 (each change listed in the CHANGELOG):
|
|
37
|
+
|
|
38
|
+
- The native-program surface (0.40.0): `loadRaw` / `loadRawMut`, the instruction data readers, error code 0,
|
|
39
|
+
`ProgramError`, `panic`, `PANIC_ON_OVERFLOW`, `ERROR_LOG_PREFIX` / `PROGRAM_ERROR_LOG_PREFIX`, `logBase64`,
|
|
40
|
+
`createProgramAddress`.
|
|
41
|
+
- Metaplex CPIs (Token Metadata, Core, Bubblegum), oracles (Pyth, Switchboard), the Stake program.
|
|
42
|
+
- Functions chosen at run time and lists of functions, closures returned from functions.
|
|
43
|
+
- Tools: `typesol port`, `clone`, `profile`, `cpi`, the editor plugin, the MCP server and the agent files `init`
|
|
44
|
+
writes, the SBPF v1 and v2 targets.
|
|
45
|
+
|
|
46
|
+
## Before 1.0
|
|
47
|
+
|
|
48
|
+
- **An external audit** of the compiler and runtime ([audit package](audit.md)), its findings fixed and published.
|
|
49
|
+
- **Settle the open edges**, each either supported or refused with a clear error:
|
|
50
|
+
- a struct holding a FixedVec as both an argument and account data (two layouts, one IDL type);
|
|
51
|
+
- helpers that take a writable struct which is not an account (a `loadRaw` view, a local), now refused;
|
|
52
|
+
- `require` with an error code computed at run time that is 0: fails as an overflow (5100) today, where a native
|
|
53
|
+
program returns CUSTOM_ZERO;
|
|
54
|
+
- which experimental parts above become stable, and which stay outside the 1.0 promise.
|
|
55
|
+
- **A release candidate** (1.0.0-rc) used for the showcase ports and the templates, with no breaking change between it
|
|
56
|
+
and 1.0.0.
|
package/docs/testing.md
CHANGED
|
@@ -21,16 +21,17 @@ Compute-unit and binary-size comparisons with Anchor, native Rust and Pinocchio
|
|
|
21
21
|
|
|
22
22
|
## Reproducing a release
|
|
23
23
|
|
|
24
|
-
From
|
|
25
|
-
`scripts/release-manifest.ts` from the
|
|
24
|
+
From 0.39.0 on, each release's GitHub Release carries its manifest, `typesol-<version>-manifest.json`, attached by
|
|
25
|
+
hand after the npm publish (written by `scripts/release-manifest.ts` from the tag's sources; the scripts need Node 22.18
|
|
26
|
+
or later):
|
|
26
27
|
|
|
27
28
|
- the compiler and toolchain versions (clang, platform-tools, Node, TypeScript, the runtime header's sha256);
|
|
28
29
|
- the sha256 of the SBF binary, IDL and C that every program under `examples/` and `showcase/program-examples/` builds to;
|
|
29
30
|
- the sha256 of the reference binaries the differential tests run against (`test/programs/`);
|
|
30
31
|
- a hash of the test corpus.
|
|
31
32
|
|
|
32
|
-
It also carries the previous release's sources built by the previous package and by this one,
|
|
33
|
-
|
|
33
|
+
It also carries `binary-diff.txt`: the previous release's sources built by the previous package and by this one,
|
|
34
|
+
compared program by program. That is the check behind a changelog line such as "programs that use none of these compile to the
|
|
34
35
|
same binaries". To redo it, or to compare other versions:
|
|
35
36
|
|
|
36
37
|
```sh
|
|
@@ -42,6 +43,6 @@ node scripts/release-manifest.ts --compiler /tmp/b/node_modules/@typesol/cli --s
|
|
|
42
43
|
node scripts/release-manifest.ts --diff a.json b.json
|
|
43
44
|
```
|
|
44
45
|
|
|
45
|
-
For 0.37.0 → 0.38.0 (run by hand before
|
|
46
|
+
For 0.37.0 → 0.38.0 (run by hand before release manifests existed): all 67 programs of the 0.37.0 sources build to
|
|
46
47
|
the same binary and IDL with both packages.
|
|
47
48
|
|
package/docs/troubleshooting.md
CHANGED
|
@@ -17,6 +17,12 @@ printed commands yourself.
|
|
|
17
17
|
Restore it from your backup. Without it you cannot upgrade the deployed program; removing `"address"` from
|
|
18
18
|
`typesol.json` gives the program a new address.
|
|
19
19
|
|
|
20
|
+
**A build error you don't recognize** — the compiler adds a `hint:` line under TypeScript's message where TypeScript's
|
|
21
|
+
own advice points the wrong way for a program. The usual ones: integers are `bigint` (`1n`, `u64` parameters, not
|
|
22
|
+
`number`); `require`, `log`, `min`, `max` and `fixedArray` are imported from `"typesol"`; arrays are read with `.get(i)`
|
|
23
|
+
and written with `.set(i, v)`; an account you change is a `Mut<T>` parameter; there is no `async`, `try`, `throw` or
|
|
24
|
+
`class`. The full list of what the subset covers is in [language.md](language.md).
|
|
25
|
+
|
|
20
26
|
**A transaction fails with a custom error** — see [errors.md](errors.md). Failures raised by the
|
|
21
27
|
compiler's checks log their TypeScript location, e.g. `TypeSOL: arithmetic overflow (vault.ts:42)`.
|
|
22
28
|
|