@typesol/cli 0.44.1 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +343 -0
  2. package/NOTICE +14 -1
  3. package/README.md +115 -26
  4. package/SECURITY.md +10 -8
  5. package/dist/bin.d.ts +2 -0
  6. package/dist/bin.js +9 -0
  7. package/dist/cli.js +226 -62
  8. package/dist/compiler/analyze.js +57 -6
  9. package/dist/compiler/diagnostics.d.ts +4 -3
  10. package/dist/compiler/diagnostics.js +10 -6
  11. package/dist/compiler/emit/base.d.ts +1 -1
  12. package/dist/compiler/emit/calls.js +18 -5
  13. package/dist/compiler/emit/cpi-core.d.ts +3 -1
  14. package/dist/compiler/emit/cpi-core.js +8 -4
  15. package/dist/compiler/emit/expressions.d.ts +14 -0
  16. package/dist/compiler/emit/expressions.js +52 -4
  17. package/dist/compiler/emit/shared.d.ts +8 -1
  18. package/dist/compiler/emit/shared.js +8 -1
  19. package/dist/compiler/emit/statements.d.ts +8 -3
  20. package/dist/compiler/emit/statements.js +68 -3
  21. package/dist/compiler/emit/storage.js +5 -1
  22. package/dist/compiler/hints.d.ts +7 -0
  23. package/dist/compiler/hints.js +58 -9
  24. package/dist/compiler/index.d.ts +56 -1
  25. package/dist/compiler/index.js +27 -3
  26. package/dist/compiler/model.js +3 -2
  27. package/dist/compiler/toolchain.d.ts +73 -2
  28. package/dist/compiler/toolchain.js +222 -17
  29. package/dist/node-version.d.ts +4 -0
  30. package/dist/node-version.js +12 -0
  31. package/dist/tools/docker.d.ts +183 -0
  32. package/dist/tools/docker.js +442 -0
  33. package/dist/tools/doctor.d.ts +44 -0
  34. package/dist/tools/doctor.js +108 -14
  35. package/dist/workspace.d.ts +11 -3
  36. package/dist/workspace.js +46 -9
  37. package/docker/Dockerfile +163 -0
  38. package/docker/deps/0.43.0.lock.json +1206 -0
  39. package/docker/deps/0.44.0.lock.json +1206 -0
  40. package/docker/deps/0.44.1.lock.json +1206 -0
  41. package/docker/deps/0.45.0.lock.json +1206 -0
  42. package/docker/deps/0.46.0.lock.json +1206 -0
  43. package/docs/ai.md +2 -1
  44. package/docs/architecture.md +18 -6
  45. package/docs/audit.md +15 -7
  46. package/docs/case-study-phoenix.md +1 -1
  47. package/docs/case-study-raydium-amm.md +1 -1
  48. package/docs/case-study-spl-stake-pool.md +1 -1
  49. package/docs/cli.md +71 -6
  50. package/docs/errors.md +22 -8
  51. package/docs/glossary.md +210 -0
  52. package/docs/language-accounts.md +499 -0
  53. package/docs/language-basics.md +389 -0
  54. package/docs/language-builtins.md +411 -0
  55. package/docs/language-chain.md +198 -0
  56. package/docs/language-cpi.md +470 -0
  57. package/docs/language-errors-events.md +184 -0
  58. package/docs/language-native.md +493 -0
  59. package/docs/language-pdas.md +198 -0
  60. package/docs/language-statements.md +620 -0
  61. package/docs/language-types.md +601 -0
  62. package/docs/language.md +190 -467
  63. package/docs/mainnet.md +103 -8
  64. package/docs/migrate-from-anchor.md +7 -6
  65. package/docs/security-model.md +4 -4
  66. package/docs/stability.md +64 -3
  67. package/docs/test-your-program.md +52 -15
  68. package/docs/testing.md +49 -2
  69. package/docs/troubleshooting.md +210 -42
  70. package/lib/typesol.d.ts +67 -22
  71. package/llms-full.txt +5084 -591
  72. package/llms.txt +12 -1
  73. package/package.json +4 -2
  74. package/releases/0.43.0.json +669 -0
  75. package/releases/0.44.0.json +672 -0
  76. package/releases/0.44.1.json +672 -0
  77. package/releases/0.45.0.json +732 -0
  78. package/runtime/LICENSE-compiler-builtins.txt +275 -0
  79. package/runtime/typesol_builtins.c +484 -0
  80. package/ts-plugin/index.js +16 -5
@@ -1,57 +1,225 @@
1
1
  # Troubleshooting
2
2
 
3
- **"Solana SBF SDK not found"** — install the Agave CLI (https://docs.anza.xyz/cli/install) and run
4
- `cargo-build-sbf --version` once. TypeSOL looks in `~/.local/share/solana/install/active_release/bin/platform-tools-sdk/sbf`
5
- and next to `cargo-build-sbf` on PATH; set `TYPESOL_SBF_SDK` to a `platform-tools-sdk/sbf` directory otherwise.
3
+ Grouped by when they happen; within each group, the problems a first run meets come first.
6
4
 
7
- **"platform-tools missing" / "no SBPF v2 libraries"** — `cargo-build-sbf --force-tools-install`.
5
+ ## Install
8
6
 
9
- **"warning: this build uses clang … TypeSOL is tested with clang 20.1.7-rust-dev …"** — the active platform-tools are
10
- not the ones the release is tested with (platform-tools v1.52, from Agave 3.1.10). The build goes on, but the C TypeSOL
11
- generates is only checked against that clang: another one can compile it to other bytes, and what the C relies on
12
- includes backend details (how the SBF backend passes struct arguments was behind a defect fixed after 0.43.0). Install the tested ones with
13
- `cargo-build-sbf --install-only --force-tools-install --tools-version v1.52`; `typesol doctor` shows which are active.
14
- In CI, `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) turns the warning into an error.
7
+ ### `TypeSOL needs Node.js 22.12 or later`
15
8
 
16
- **`typesol verify` says MISMATCH** — first make sure the same sources (imports included), TypeSOL version and SBPF
17
- version are used. Then the toolchain: verify prints the rebuild's clang and platform-tools, and the deployed build's
18
- when a `<name>.build.json` describes the deployed bytes (`--manifest <file>`, one next to a given `.so`, or the local
19
- build's). A program on chain carries no such record, so keep the build manifest of every deployment.
9
+ The CLI checks the Node.js version before anything else. On an older one, `npm install` can fail inside npm and the
10
+ tests with `Map.groupBy is not a function`; install a current Node.js (https://nodejs.org, or `nvm install 22`).
20
11
 
21
- **Windows** — not tested; use WSL2 with the Linux Agave CLI.
12
+ ### `npm error 404 … typesol - Not found`
22
13
 
23
- **Node errors such as `ERR_UNKNOWN_FILE_EXTENSION` or `ERR_REQUIRE_ESM`** — use Node.js 22.12 or newer.
14
+ `npx --no-install typesol` ran outside a project, or before `npm install` in it: `typesol` is the name projects install
15
+ the package under, not a package on npm. Run `npx @typesol/cli …` there, or `npm install` in the project first.
24
16
 
25
- **"`solana` was not found on PATH"** (deploy) — install the Agave CLI, or use `typesol deploy --dry-run` and run the
26
- printed commands yourself.
17
+ ### "the Agave CLI is not installed" (formerly "Solana SBF SDK not found")
27
18
 
28
- **"… is missing, but typesol.json records …"** — the program keypair under `target/deploy/` was deleted or replaced.
29
- Restore it from your backup. Without it you cannot upgrade the deployed program; removing `"address"` from
30
- `typesol.json` gives the program a new address.
19
+ Install it and its platform-tools as in the README's [Quick start](../README.md#quick-start):
31
20
 
32
- **A build error you don't recognize** — the compiler adds a `hint:` line under TypeScript's message where TypeScript's
33
- own advice points the wrong way for a program. The usual ones: integers are `bigint` (`1n`, `u64` parameters, not
34
- `number`); `require`, `log`, `min`, `max` and `fixedArray` are imported from `"typesol"`; arrays are read with `.get(i)`
35
- and written with `.set(i, v)`; an account you change is a `Mut<T>` parameter; there is no `async`, `try`, `throw` or
36
- `class`. The full list of what the subset covers is in [language.md](language.md).
21
+ ```sh
22
+ sh -c "$(curl -sSfL https://release.anza.xyz/v3.1.10/install)"
23
+ # The installer adds this line to ~/.profile for new shells, and this shell needs it now:
24
+ export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
25
+ # Once: this downloads the platform-tools, about 0.5 GB and up to 1.6 GB unpacked, and prints nothing for a minute or two:
26
+ cargo-build-sbf --install-only --force-tools-install --tools-version v1.52
27
+ ```
37
28
 
38
- **A transaction fails with a custom error** — see [errors.md](errors.md). Failures raised by the
39
- compiler's checks log their TypeScript location, e.g. `TypeSOL: arithmetic overflow (vault.ts:42)`.
29
+ TypeSOL looks in `~/.local/share/solana/install/active_release/bin/platform-tools-sdk/sbf` and next to
30
+ `cargo-build-sbf` on PATH; set `TYPESOL_SBF_SDK` to a `platform-tools-sdk/sbf` directory otherwise. On Linux arm64 see
31
+ [Linux arm64: the Agave installer fails with a 404](#linux-arm64-the-agave-installer-fails-with-a-404).
40
32
 
41
- **Heap errors (5110) building strings** — strings are allocated on a 32 KiB heap and never freed. Build less text,
42
- or declare `const HEAP_SIZE_KIB = 64n` and add a ComputeBudget `requestHeapFrame` instruction to the transaction.
33
+ ### `cargo-build-sbf: command not found` right after installing
43
34
 
44
- **`typesol idl publish` fails on a local validator with "invalid instruction data"** — the System Program of
45
- `solana-test-validator` (Agave 3.1 included) rejects a System instruction that the current Program Metadata program
46
- uses. Publishing works on mainnet-beta. The error shows the failing transaction's last log lines.
35
+ The Agave installer adds its `bin` directory to `PATH` in `~/.profile`, which only new login shells read. In the same
36
+ shell, run `export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"`.
47
37
 
48
- **"instruction X (with the helpers inlined into it) needs N bytes of stack; SBPF v0 gives each function 4096"** — under
49
- SBPF v0 (the default) every function gets a fixed 4 KiB stack frame, and going past it corrupts memory, so the build
50
- refuses it. SBPF v1 and v2 (`--sbpf v1` / `v2`) grow frames dynamically, so this limit does not apply there. Large structs and arrays copied into typed
51
- locals (`const q: Big = acct.big`) are the usual cause: bind them without a type (`const q = acct.big`, a reference
52
- into the account data). The message lists the biggest locals (clang's frame layout: a local's name and the source
53
- line near it; the locals of an inlined helper show as unnamed, with the helpers' locals that may be them). Helpers are
54
- often inlined into their instruction, so their locals count toward its frame: mark one `/** @noinline */` to give it a
55
- 4 KiB frame of its own (a few compute units per call), or declare a large local list or struct of an instruction
56
- `/** @heap */` to keep it on the heap (about 18 CU for the allocation).
38
+ ### "the Agave CLI is installed, but not its platform-tools" (formerly "platform-tools missing") / "no SBPF v2 libraries"
57
39
 
40
+ `cargo-build-sbf --install-only --force-tools-install --tools-version v1.52`. Neither `cargo-build-sbf --version` (it
41
+ downloads nothing) nor `cargo-build-sbf --force-tools-install` alone (it needs Cargo and a Cargo project) installs them.
42
+
43
+ ### Linux arm64: the Agave installer fails with a 404
44
+
45
+ Anza publishes no Agave CLI for Linux arm64 (`agave-install-init-aarch64-unknown-linux-gnu` is not there), but
46
+ platform-tools has a `linux-aarch64` package. With it and the SDK's C files from the x86_64 release (headers and
47
+ linker script, as the `--docker` image takes them), `typesol build` and LiteSVM tests work; `typesol doctor` prints
48
+ these commands there (they need `curl` and `bzip2`):
49
+
50
+ ```sh
51
+ mkdir -p "$HOME/.local/share/typesol-sdk/sbf/dependencies/platform-tools"
52
+ # About 215 MB, for the C headers and linker script of the SDK only:
53
+ curl -sSfL https://github.com/anza-xyz/agave/releases/download/v3.1.10/solana-release-x86_64-unknown-linux-gnu.tar.bz2 | tar -xj -C "$HOME/.local/share/typesol-sdk" --strip-components=3 solana-release/bin/platform-tools-sdk/sbf/c
54
+ # About 515 MB, 1.6 GB unpacked, and quiet for a minute or two:
55
+ curl -sSfL https://github.com/anza-xyz/platform-tools/releases/download/v1.52/platform-tools-linux-aarch64.tar.bz2 | tar -xj -C "$HOME/.local/share/typesol-sdk/sbf/dependencies/platform-tools"
56
+ touch "$HOME/.local/share/typesol-sdk/sbf/dependencies/platform-tools-v1.52.md"
57
+ # Add this line to ~/.profile too, for new shells:
58
+ export TYPESOL_SBF_SDK="$HOME/.local/share/typesol-sdk/sbf"
59
+ ```
60
+
61
+ Deploying needs the Solana CLI: deploy from macOS or Linux x86_64, or build the Agave CLI from source
62
+ (https://docs.anza.xyz/cli/install). `build --docker` (linux/amd64, emulated) works on any host with Docker.
63
+
64
+ ### Windows
65
+
66
+ Not tested; use WSL2 with the Linux Agave CLI.
67
+
68
+ ### Node errors such as `ERR_UNKNOWN_FILE_EXTENSION` or `ERR_REQUIRE_ESM`
69
+
70
+ Use Node.js 22.12 or newer.
71
+
72
+ ### "warning: this build uses clang … TypeSOL is tested with clang 20.1.7-rust-dev …"
73
+
74
+ The active platform-tools are not the ones the release is tested with (platform-tools v1.52, from Agave 3.1.10). The
75
+ build goes on, but the C TypeSOL generates is only checked against that clang: another one can compile it to other
76
+ bytes, and what the C relies on includes backend details (how the SBF backend passes struct arguments was behind a
77
+ defect fixed after 0.43.0). Install the tested ones with `cargo-build-sbf --install-only --force-tools-install
78
+ --tools-version v1.52`; `typesol doctor` shows which are active. In CI, `--toolchain-strict` (or
79
+ `TYPESOL_TOOLCHAIN=strict`) turns the warning into an error.
80
+
81
+ ## Writing and running a program
82
+
83
+ ### A build error you don't recognize
84
+
85
+ The compiler adds a `hint:` line under TypeScript's message where TypeScript's own advice points the wrong way for a
86
+ program (and for a global a program does not have, such as `console` or `process`, says so in place of TypeScript's
87
+ advice to add a library). The usual ones: integers are `bigint` (`1n`, `u64` parameters, not `number`); `require`,
88
+ `log`, `min`, `max`, `fixedArray`, the types (`Signer`, `Mut`, …) and the integer casts are imported from `"typesol"` (a
89
+ cast such as `u64(x)` without `type`: `import { u64 }`); arrays are read with `.get(i)` and written with `.set(i, v)`;
90
+ an account you change is a `Mut<T>` parameter; the time is `now()`, not `Date.now()`; there is no `async`, `try`,
91
+ `throw` or `class`. The full list of what the subset covers is in [language.md](language.md).
92
+
93
+ ### A transaction fails with a custom error
94
+
95
+ See [errors.md](errors.md). Failures raised by the compiler's checks log their TypeScript location, e.g. `TypeSOL:
96
+ arithmetic overflow (vault.ts:42)`.
97
+
98
+ ### "exceeded CUs meter" / "Computational budget exceeded"
99
+
100
+ The transaction ran out of compute units: by default each instruction gets 200,000, and the logs end with `Program
101
+ <id> consumed 200000 of 200000 compute units` and `… failed: exceeded CUs meter at BPF instruction …`. Ask for more,
102
+ up to 1,400,000 per transaction, with a ComputeBudget `SetComputeUnitLimit` instruction placed before the others
103
+ (`getSetComputeUnitLimitInstruction({ units })` from `@solana-program/compute-budget`, or the bytes `[2, units as a
104
+ u32 little-endian]` to `ComputeBudget111111111111111111111111111111`). The generated client's `sendInstructions` and
105
+ the testing library's `t.send(payer, ...ixs)` send the instructions they are given, so pass it first:
106
+ `t.send(alice, setLimit, t.ix(…))`. To spend less, find the costly lines with `typesol build --profile` and `typesol
107
+ profile` ([limits and costs](language-basics.md#limits-and-costs)).
108
+
109
+ ### `Transaction size … exceeds limit of 1232 bytes` / "transaction too large"
110
+
111
+ A transaction is at most 1,232 bytes, signatures, account addresses and instruction data included. Kit refuses to send
112
+ a larger one (the first message), and an RPC node refuses it too. Split the work into several transactions, pass
113
+ fewer accounts, or send large data in chunks into an account the program reads; with many accounts, a version 0
114
+ transaction with an address lookup table costs one byte per account instead of 32 (kit's
115
+ `compressTransactionMessageUsingAddressLookupTables`) ([limits and costs](language-basics.md#limits-and-costs)).
116
+
117
+ ### Heap errors (5110) building strings
118
+
119
+ Strings are allocated on a 32 KiB heap and never freed. Build less text, or declare `const HEAP_SIZE_KIB = 64n` and add
120
+ a ComputeBudget `requestHeapFrame` instruction to the transaction.
121
+
122
+ ### "instruction X (with the helpers inlined into it) needs N bytes of stack; SBPF v0 gives each function 4096"
123
+
124
+ Under SBPF v0 (the default) every function gets a fixed 4 KiB stack frame, and going past it corrupts memory, so the
125
+ build refuses it. SBPF v1 and v2 (`--sbpf v1` / `v2`) grow frames dynamically, so this limit does not apply there. Large
126
+ structs and arrays copied into typed locals (`const q: Big = acct.big`) are the usual cause: bind them without a type
127
+ (`const q = acct.big`, a reference into the account data). The message lists the biggest locals (clang's frame layout: a
128
+ local's name and the source line near it; the locals of an inlined helper show as unnamed, with the helpers' locals that
129
+ may be them). Helpers are often inlined into their instruction, so their locals count toward its frame: mark one `/**
130
+ @noinline */` to give it a 4 KiB frame of its own (a few compute units per call), or declare a large local list or
131
+ struct of an instruction `/** @heap */` to keep it on the heap (about 18 CU for the allocation).
132
+
133
+ ### "… is missing, but typesol.json records …"
134
+
135
+ The program keypair under `target/deploy/` was deleted or replaced. Restore it from your backup. Without it you cannot
136
+ upgrade the deployed program; removing `"address"` from `typesol.json` gives the program a new address.
137
+
138
+ ## Deploy
139
+
140
+ ### `no payer keypair at ~/.config/solana/id.json` (deploy)
141
+
142
+ `solana-keygen new` creates it (or pass `--keypair <file>`); fund it on devnet with `solana airdrop 2 --url devnet`.
143
+ Nothing is sent before it exists.
144
+
145
+ ### "`solana` was not found on PATH" (deploy)
146
+
147
+ Install the Agave CLI, or use `typesol deploy --dry-run` and run the printed commands yourself.
148
+
149
+ ### `typesol idl publish` fails on a local validator with "invalid instruction data"
150
+
151
+ The System Program of `solana-test-validator` (Agave 3.1 included) rejects a System instruction that the current Program
152
+ Metadata program uses. The error shows the failing transaction's last log lines. No option fixes it locally: the System
153
+ Program is part of the validator. Publish where the Program Metadata program is deployed, mainnet-beta or devnet
154
+ (`npx --no-install typesol idl publish --url devnet`; [publish the IDL](mainnet.md#5-publish-the-idl)); against a local
155
+ validator, clients read the IDL file the build writes (`target/<name>/<name>.json`, [client.md](client.md)).
156
+
157
+ ## Verify and `--docker`
158
+
159
+ ### `typesol verify` says MISMATCH
160
+
161
+ First make sure the same sources (imports included), TypeSOL version and SBPF version are used. Then the toolchain:
162
+ verify prints the rebuild's clang and platform-tools, and the deployed build's when a `<name>.build.json` describes the
163
+ deployed bytes (`--manifest <file>`, one next to a given `.so`, or the local build's). A program on chain carries no
164
+ such record, so keep the build manifest of every deployment.
165
+
166
+ ### `--docker needs Docker: docker is not installed` / `the Docker daemon is not running`
167
+
168
+ `build --docker` and `verify --docker` run in a container: install Docker, or start Docker Desktop (or `sudo systemctl
169
+ start docker`). `typesol doctor` has a `docker` row. Nothing is built without it; drop `--docker` to build with your own
170
+ platform-tools.
171
+
172
+ ### `docker build of typesol-build:… failed`
173
+
174
+ The first `--docker` build makes the image, which needs the network: the base images from Docker Hub, the Agave and
175
+ platform-tools release files from GitHub, the TypeSOL tarball from npm. A `checksum` error means a downloaded file is
176
+ not the one the Dockerfile pins (retry; if it persists, report it). `typesol tarball check: integrity …` means the
177
+ tarball npm served is not the one `releases/<version>.json` records: do not use that version until it is explained.
178
+ `typesol dependency lock: …` means the lock does not describe the package's dependencies or names a package without a
179
+ registry integrity; an `EINTEGRITY` error from `npm ci` means a downloaded dependency is not the one the lock records:
180
+ the same.
181
+
182
+ ### `the local image typesol-build:… was not built from this release record and dependency lock`
183
+
184
+ An image of that tag exists, made from a record or lock with other values (it names them). Two records of one version
185
+ disagree, so find out which is right before going on; to build from the one given now, `docker image rm` the tag and run
186
+ again.
187
+
188
+ ### `no dependency lock for TypeSOL <version>`
189
+
190
+ Neither this package nor that version's tarball has `docker/deps/<version>.lock.json`: use a later `@typesol/cli`, which
191
+ ships the locks of the versions before it. On arm64 machines the image is linux/amd64 and runs emulated: Docker Desktop
192
+ provides the x86_64 emulation (QEMU or Rosetta); other Docker installs may need `binfmt` for amd64.
193
+
194
+ ### `no release record for TypeSOL <version>` / `could not fetch the release record`
195
+
196
+ The container installs only versions whose tarball has a record: the package's own, or `releases/<version>.json` on the
197
+ repository's main branch, which `--docker` fetches for a release newer than the package. Offline (or behind a proxy that
198
+ blocks raw.githubusercontent.com), pass the record yourself with `--release-record releases/<version>.json` from a
199
+ checkout, or choose a version the package records with `--typesol-version`. HTTP 404 means the repository has no record
200
+ for that version: check that it is a released version. 0.42.0 and earlier have no record.
201
+
202
+ ### `this project installs typesol X …, but this is typesol Y`
203
+
204
+ A `typesol` other than the project's ran `--docker`. Run the project's own (`npx --no-install typesol …`), or say which
205
+ version to use with `--typesol-version`.
206
+
207
+ ### `the container build failed … the container sees only <dir>`
208
+
209
+ The compiler's error is printed above it. The container mounts only the project root (or a single file's directory): an
210
+ import from outside it is missing there.
211
+
212
+ ### `verify` says `differs host`
213
+
214
+ The same TypeSOL (0.44.1 or earlier) and toolchain built the two sides on different hosts. That may be the cause if the
215
+ program has 128-bit or signed division: those versions linked platform-tools' compiler-builtins, which each host package
216
+ lays out differently. Rebuild on the deployed side's kind of host (or with `--docker`, if the deployed build was one).
217
+ From 0.45.0 on the host is not a difference between macOS arm64, Linux arm64 and Linux x86_64 (the hosts measured);
218
+ `differs host (not measured)` means one side was built on another host.
219
+
220
+ ### A 0.44.x program with division, deployed from macOS or Linux arm64, does not match `verify --docker`
221
+
222
+ 0.44.0 and 0.44.1 linked platform-tools' compiler-builtins, so a program that calls 128-bit or signed division built to
223
+ other bytes on each host package; the container is linux/amd64 and gives the Linux x86_64 bytes. What verifies it is a
224
+ 0.44.x install (the version in its `.build.json`) on the same kind of host as the one that built it, without `--docker`:
225
+ `npx @typesol/cli@0.44.1 verify …` on macOS arm64 for a build made there.
package/lib/typesol.d.ts CHANGED
@@ -14,10 +14,15 @@
14
14
  * ~ flips the bits within the type's width.
15
15
  */
16
16
 
17
+ /** Unsigned 8-bit integer (a `bigint` to TypeScript); literals are written `1n`. */
17
18
  export type u8 = bigint;
19
+ /** Unsigned 16-bit integer (a `bigint` to TypeScript); literals are written `1n`. */
18
20
  export type u16 = bigint;
21
+ /** Unsigned 32-bit integer (a `bigint` to TypeScript); literals are written `1n`. */
19
22
  export type u32 = bigint;
23
+ /** Unsigned 64-bit integer (a `bigint` to TypeScript); literals are written `1n`. */
20
24
  export type u64 = bigint;
25
+ /** Unsigned 128-bit integer (a `bigint` to TypeScript); literals are written `1n`. */
21
26
  export type u128 = bigint;
22
27
  /**
23
28
  * 256-bit unsigned integers for computation (sqrt-price and liquidity math): locals, helper parameters and results,
@@ -25,10 +30,15 @@ export type u128 = bigint;
25
30
  * (the IDL has no 256-bit integer).
26
31
  */
27
32
  export type u256 = bigint;
33
+ /** Signed 8-bit integer, two's complement (a `bigint` to TypeScript). */
28
34
  export type i8 = bigint;
35
+ /** Signed 16-bit integer, two's complement (a `bigint` to TypeScript). */
29
36
  export type i16 = bigint;
37
+ /** Signed 32-bit integer, two's complement (a `bigint` to TypeScript). */
30
38
  export type i32 = bigint;
39
+ /** Signed 64-bit integer, two's complement (a `bigint` to TypeScript). */
31
40
  export type i64 = bigint;
41
+ /** Signed 128-bit integer, two's complement (a `bigint` to TypeScript). */
32
42
  export type i128 = bigint;
33
43
 
34
44
  /** A 32-byte Solana address. Compare with `===`, `!==` or `.equals()`. */
@@ -103,7 +113,8 @@ export declare function byteLength(value: string): u64;
103
113
  export type Option<T> = T | null;
104
114
 
105
115
  /**
106
- * A growable list. As an account struct field it is stored Borsh-style (u32 length + elements) and the account is
116
+ * A list whose length varies: as account data the account grows with it; as an argument it is a read-only view.
117
+ * As an account struct field it is stored Borsh-style (u32 length + elements) and the account is
107
118
  * resized as it grows. An account may have any number of them, declared anywhere: they are stored after the
108
119
  * fixed-size fields, in the order declared. In a `@layout borsh` struct it is Anchor's `Vec<T>`: anywhere among the
109
120
  * fields, held on the heap while the instruction runs, and bounded only by the account when it is written back
@@ -246,6 +257,7 @@ export interface RemainingAccounts extends Iterable<CpiAccount> {
246
257
  export interface RemainingSlice extends Iterable<CpiAccount> {
247
258
  readonly __remainingSlice: void;
248
259
  }
260
+ /** The accounts passed after the declared ones, in order (see RemainingAccounts). */
249
261
  export declare function remainingAccounts(): RemainingAccounts;
250
262
 
251
263
  /**
@@ -275,6 +287,7 @@ export declare function sysvarAt<S extends StakeHistorySysvar>(account: Remainin
275
287
  * `.lamports`), and passes to a helper that takes `Account<T>` / `Mut<T>`.
276
288
  */
277
289
  export declare function loadAccount<T>(account: RemainingAccount | AccountInfo): Account<T>;
290
+ /** `loadAccount` for writing: also writable, and loaded mutably once per instruction (2040). */
278
291
  export declare function loadAccountMut<T>(account: RemainingAccount | AccountInfo): Mut<T>;
279
292
  /**
280
293
  * A native (non-Anchor) program's own account as a fixed-layout struct, as a `#[repr(C)]` type's `load_checked` /
@@ -283,6 +296,7 @@ export declare function loadAccountMut<T>(account: RemainingAccount | AccountInf
283
296
  * mutably twice in the instruction (2040). Bind it with const: `const amm = loadRawMut<AmmInfo>(ammInfo)`.
284
297
  */
285
298
  export declare function loadRaw<T>(account: RemainingAccount | AccountInfo): Account<T>;
299
+ /** `loadRaw` for writing: also writable and loaded mutably once per instruction (2040). */
286
300
  export declare function loadRawMut<T>(account: RemainingAccount | AccountInfo): Mut<T>;
287
301
  /**
288
302
  * `loadRaw` / `loadRawMut` at a byte offset known only at run time (a native account whose parts start where its header
@@ -293,6 +307,7 @@ export declare function loadRawMut<T>(account: RemainingAccount | AccountInfo):
293
307
  * it may view, since its bounds were checked against the old length: take it again after (a compile error says so).
294
308
  */
295
309
  export declare function loadRawAt<T>(account: RemainingAccount | AccountInfo, offset: u64): Account<T>;
310
+ /** `loadRawAt` for writing: writable and claimed as `loadRawMut` is. */
296
311
  export declare function loadRawMutAt<T>(account: RemainingAccount | AccountInfo, offset: u64): Mut<T>;
297
312
  /**
298
313
  * `capacity` elements of a fixed-size type packed in place from a run-time byte offset, the count known only at run
@@ -312,8 +327,9 @@ export interface ReadonlyRawArray<T> extends ListMethods<T> {
312
327
  get(index: bigint): Readonly<T>;
313
328
  [Symbol.iterator](): Iterator<Readonly<T>>;
314
329
  }
315
- /** `const slab = rawArrayMutAt<Order>(acct, offset, capacity)`: see RawArray. */
330
+ /** A read-only view of `capacity` elements of `T` at `offset` in an account (see RawArray); `rawArrayMutAt` writes. */
316
331
  export declare function rawArrayAt<T>(account: RemainingAccount | AccountInfo, offset: u64, capacity: u64): ReadonlyRawArray<T>;
332
+ /** `rawArrayAt` for writing: elements set in place (see RawArray). */
317
333
  export declare function rawArrayMutAt<T>(account: RemainingAccount | AccountInfo, offset: u64, capacity: u64): RawArray<T>;
318
334
 
319
335
  /** A node of a RedBlackTree: its key (read-only), its value (in place) and its index in the tree's node array (1-based). */
@@ -397,6 +413,7 @@ export declare function rbTreeAt<K, V>(
397
413
  capacity: u64,
398
414
  compare?: (a: K, b: K) => bigint,
399
415
  ): ReadonlyRedBlackTree<K, V>;
416
+ /** `rbTreeAt` for writing: insert, remove and initialize with lib-sokoban's own writes (see RedBlackTree). */
400
417
  export declare function rbTreeMutAt<K, V>(
401
418
  account: RemainingAccount | AccountInfo,
402
419
  offset: u64,
@@ -432,7 +449,8 @@ export declare function sha256(...parts: (string | Pubkey | Hash | bigint | bool
432
449
  export declare function keccak256(...parts: (string | Pubkey | Hash | bigint | boolean)[]): Hash;
433
450
 
434
451
  /**
435
- * Verify a Merkle proof (keccak256, sorted pairs: the OpenZeppelin convention most airdrop tools use).
452
+ * Whether `proof` places `leaf` under `root` (keccak256, sorted pairs: the OpenZeppelin convention most airdrop tools
453
+ * use). It does not fail by itself: write `require(merkleVerify(…), error)`; a call whose result is unused is refused.
436
454
  * `proof` must be a `Vec<Hash>` instruction argument. Leaves and inner nodes hash alike: build the leaf in the program
437
455
  * as OpenZeppelin does, `keccak256(keccak256(data))`, never take it from the arguments (an inner node would pass).
438
456
  */
@@ -477,15 +495,17 @@ export interface TransactionInstruction {
477
495
  export declare function stackHeight(): u64;
478
496
 
479
497
  /**
480
- * True when this transaction contains an Ed25519 precompile instruction that verified `message`
481
- * signed by `signer` (offsets inside the precompile's own data). The client adds that instruction;
498
+ * Whether this transaction contains an Ed25519 precompile instruction that verified `message`
499
+ * signed by `signer` (offsets inside the precompile's own data). It does not fail by itself: write
500
+ * `require(verifyEd25519(…), error)`; a call whose result is unused is refused. The client adds that instruction;
482
501
  * the runtime rejects the transaction if the signature is wrong.
483
502
  */
484
503
  export declare function verifyEd25519(instructions: InstructionsSysvar, signer: Pubkey, message: string | Hash | Pubkey): boolean;
485
504
 
486
505
  /**
487
- * Recover the secp256k1 signer of `hash` from (r, s, recoveryId) and compare it with an Ethereum
488
- * address given left-padded to 32 bytes (12 zero bytes + 20 address bytes). High-s signatures are refused.
506
+ * Whether the secp256k1 signer of `hash`, recovered from (r, s, recoveryId), is an Ethereum address given
507
+ * left-padded to 32 bytes (12 zero bytes + 20 address bytes). High-s signatures are refused. It does not fail by
508
+ * itself: write `require(verifySecp256k1(…), error)`; a call whose result is unused is refused.
489
509
  * `hash` must be computed in the program — `keccak256(...)` of the message or `ethMessageHash(message)` — because
490
510
  * a signature can be made up for an arbitrary hash; the compiler rejects anything else.
491
511
  */
@@ -844,12 +864,12 @@ export interface TokenMetadataProgram extends AccountMeta {
844
864
  }
845
865
  /** The Metaplex master edition address of a mint (PDA ["metadata", program, mint, "edition"]). */
846
866
  export declare function masterEditionAddress(mint: Pubkey): Pubkey;
847
- /** The canonical program address of `seeds` under `program` (Rust `Pubkey::find_program_address(seeds, program).0`). */
848
867
  /**
849
868
  * An integer seed with its bytes most significant first (Rust's `x.to_be_bytes()`), inside a seeds list:
850
869
  * `["tick_array", pool.key, bigEndian(startIndex)]`. In `Seeds<…>` write `"@startIndex:be"`.
851
870
  */
852
871
  export declare function bigEndian(value: bigint): Seed;
872
+ /** The canonical program address of `seeds` under `program` (Rust `Pubkey::find_program_address(seeds, program).0`). */
853
873
  export declare function findProgramAddress(seeds: Seed[], program: Pubkey): Pubkey;
854
874
  /**
855
875
  * `Pubkey::create_program_address(seeds, program)`: the address of these seeds with the bump given as the last seed,
@@ -912,9 +932,11 @@ export declare function updateExtraAccountMetas(
912
932
  systemProgram: SystemProgram,
913
933
  extraAccounts?: ExtraAccountMeta[],
914
934
  ): void;
935
+ /** One extra account of a transfer hook's ExtraAccountMetaList: a fixed address, or a PDA from seeds (see initExtraAccountMetas). */
915
936
  export type ExtraAccountMeta =
916
937
  | { address: Pubkey; isSigner?: boolean; isWritable?: boolean }
917
938
  | { seeds: (string | ExtraAccountSeed)[]; program?: bigint; isSigner?: boolean; isWritable?: boolean };
939
+ /** A seed of an extra account resolved by Token-2022 at transfer time (seedAccountKey, seedAccountData, seedInstructionData). */
918
940
  export interface ExtraAccountSeed {
919
941
  readonly __extraSeed: void;
920
942
  }
@@ -948,7 +970,8 @@ export declare function pubkey(base58: string): Pubkey;
948
970
  export type Address<A, Base58 extends string, E = never> = A & { readonly __address?: [Base58, E] };
949
971
 
950
972
  /**
951
- * Token constraints, checked before your code runs:
973
+ * `Ata<A, "owner", "mint">`: the account must be the associated token account of those parameters (2009).
974
+ * It is one of the token constraints, checked before your code runs:
952
975
  * - `HasOne<TokenAccount, "mint" | "owner">`: the token account's mint / owner is the key of the parameter with that name (2014 / 2015).
953
976
  * - `HasOne<Mint, "mintAuthority" | "freezeAuthority">`: the mint's authority is that parameter's key (2016 / 2017).
954
977
  * - `Ata<TokenAccount, "owner", "mint">`: the account is the associated token account of those parameters (2009).
@@ -999,8 +1022,8 @@ export declare function closeRaw(account: RemainingAccount | Mut<AccountInfo>, r
999
1022
  export declare function assignOwner(account: RemainingAccount | Mut<AccountInfo>, owner: Pubkey): void;
1000
1023
 
1001
1024
  /**
1002
- * Token-2022 extensions of a mint (any account works; legacy SPL Token mints have none).
1003
- * transferFee: the fee withheld when `amount` is sent now (TransferFeeConfig for the current epoch; 0 without it).
1025
+ * The fee withheld when `amount` is sent now: the mint's Token-2022 TransferFeeConfig for the current epoch, 0 without
1026
+ * it. Like the other extension readers it takes any account (legacy SPL Token mints have no extensions).
1004
1027
  */
1005
1028
  export declare function transferFee(mint: AccountMeta | RemainingAccount, amount: u64): u64;
1006
1029
  /**
@@ -1036,8 +1059,9 @@ export declare function hasExtension(account: AccountMeta | RemainingAccount, ex
1036
1059
 
1037
1060
  /** Rent-exempt minimum balance for an account of `space` bytes. */
1038
1061
  export declare function rentExempt(space: u64): u64;
1039
- /** SPL Token account and mint sizes, for systemProgram.createAccount. */
1062
+ /** SPL Token's token account size, 165 bytes, for systemProgram.createAccount. */
1040
1063
  export declare const TOKEN_ACCOUNT_SIZE: u64;
1064
+ /** SPL Token's mint size, 82 bytes. */
1041
1065
  export declare const MINT_SIZE: u64;
1042
1066
 
1043
1067
  /** The account must have signed the transaction. Wrap in `Mut<Signer>` to spend its lamports. */
@@ -1058,11 +1082,11 @@ export interface AccountInfo extends AccountMeta {
1058
1082
  readonly executable: boolean;
1059
1083
  }
1060
1084
 
1061
- /** A program-owned account holding struct `T`. Owner and discriminator are checked. */
1085
+ /** An account owned by this program holding struct `T`. Owner, size and discriminator are checked. */
1062
1086
  export type Account<T> = Readonly<T> & AccountMeta;
1063
1087
 
1064
1088
  /**
1065
- * Like `Account<T>` but writable. Also usable as `Mut<Signer>`, `Mut<AccountInfo>`, `Mut<TokenAccount>`. A second
1089
+ * A writable account: `Mut<T>` is `Account<T>` whose fields may be written. Also usable as `Mut<Signer>`, `Mut<AccountInfo>`, `Mut<TokenAccount>`. A second
1066
1090
  * argument fails with one of your errors when the account is not writable (Anchor's `mut @ ErrorCode.X`; else 2000).
1067
1091
  */
1068
1092
  export type Mut<T, E = never> = T & AccountMeta;
@@ -1092,6 +1116,7 @@ export type Seed = string | Pubkey | Hash | bigint | number;
1092
1116
  export interface SignerSeeds {
1093
1117
  readonly __signer_seeds: void;
1094
1118
  }
1119
+ /** Name one PDA signature's seeds (with the bump) for CPIs and helpers: `const vault = signer(["vault", owner.key, bump])`. */
1095
1120
  export declare function signer(seeds: Seed[]): SignerSeeds;
1096
1121
 
1097
1122
  /**
@@ -1155,7 +1180,8 @@ export type InitIfNeeded<T> = T extends TokenAccount
1155
1180
  };
1156
1181
 
1157
1182
  /**
1158
- * Declarative constraints, checked before your code runs (like Anchor's account attributes):
1183
+ * `HasOne<A, "field">`: the struct's `field` must be the key of the parameter with that name (Anchor's `has_one`; 2001).
1184
+ * It is one of the declarative constraints, checked before your code runs (like Anchor's account attributes):
1159
1185
  * - `HasOne<Mut<Vault>, "owner">`: vault.owner must be the key of the parameter named `owner` (union for several).
1160
1186
  * - `Seeds<Mut<Vault>, ["vault", "@owner"], "bump">`: the account must be the PDA of these seeds; "@name" is an
1161
1187
  * account parameter (its key) or an argument (its bytes), "@acct.field" a Pubkey, integer or unit enum field of a struct
@@ -1210,6 +1236,11 @@ export interface Migrate<From, To> extends AccountMeta {
1210
1236
  readonly to: To;
1211
1237
  migrate(payer: Mut<Signer>, value: To): void;
1212
1238
  }
1239
+ /**
1240
+ * The account is this program's PDA for the seeds (Anchor's `seeds = […], bump`; 2006): `"@name"` is an account's key or
1241
+ * an argument's bytes, `"@acct.field"` a field, other strings literals. `Bump` names a stored bump field, `ProgramId`
1242
+ * another program to derive under.
1243
+ */
1213
1244
  export type Seeds<A, Names extends readonly string[], Bump extends string = never, ProgramId extends string = never> = A & {
1214
1245
  readonly __seeds?: [Names, Bump, ProgramId];
1215
1246
  /** The PDA's bump (Anchor `ctx.bumps.<account>`): the stored bump field when one is named, else the canonical bump found. */
@@ -1284,6 +1315,7 @@ export type CorePlugin = (
1284
1315
  | { kind: "FreezeExecute"; frozen: boolean }
1285
1316
  | { kind: "PermanentFreezeExecute"; frozen: boolean }
1286
1317
  ) & { authority?: CorePluginAuthority };
1318
+ /** The name of a Metaplex Core plugin, as `removePlugin` and the plugin readers take it. */
1287
1319
  export type CorePluginKind = CorePlugin["kind"] | "Groups";
1288
1320
  /** When a Core lifecycle event reaches an external plugin, and what the plugin may do about it. */
1289
1321
  export interface CoreLifecycleCheck {
@@ -1869,15 +1901,19 @@ export interface CompressedLeaf {
1869
1901
  index: u32;
1870
1902
  }
1871
1903
 
1872
- /** The current slot and epoch (Clock sysvar). */
1904
+ /** The current slot (Clock sysvar). */
1873
1905
  export declare function currentSlot(): u64;
1906
+ /** The current epoch (Clock sysvar). */
1874
1907
  export declare function currentEpoch(): u64;
1875
1908
  /** The Unix time the current epoch started at (Clock.epoch_start_timestamp). */
1876
1909
  export declare function epochStartTimestamp(): i64;
1877
- /** The EpochSchedule sysvar: slots per epoch (after warmup), whether epochs warm up, and where normal epochs start. */
1910
+ /** The number of slots in an epoch after warmup (EpochSchedule sysvar). */
1878
1911
  export declare function slotsPerEpoch(): u64;
1912
+ /** Whether epochs warm up (EpochSchedule sysvar). */
1879
1913
  export declare function epochWarmup(): boolean;
1914
+ /** The first epoch after warmup (EpochSchedule sysvar). */
1880
1915
  export declare function firstNormalEpoch(): u64;
1916
+ /** The first slot after warmup (EpochSchedule sysvar). */
1881
1917
  export declare function firstNormalSlot(): u64;
1882
1918
  /** The LastRestartSlot sysvar: the last slot the cluster restarted at (0 if never). */
1883
1919
  export declare function lastRestartSlot(): u64;
@@ -1903,9 +1939,10 @@ export interface EpochRewards {
1903
1939
  * needed). Native programs refuse stake operations while `epochRewards().active`.
1904
1940
  */
1905
1941
  export declare function epochRewards(): EpochRewards;
1942
+ /** Close the account into the parameter `Destination` when the instruction succeeds (Anchor's `close = destination`). */
1906
1943
  export type CloseTo<A, Destination extends string> = A & { readonly __closeTo?: Destination };
1907
1944
 
1908
- /** A program-owned account that this instruction creates as a PDA. */
1945
+ /** An account this instruction creates: at a PDA of this program, or, with `null` seeds, a new keypair account that signs. */
1909
1946
  export type Init<T> = T extends TokenAccount
1910
1947
  ? T & {
1911
1948
  /**
@@ -2222,14 +2259,18 @@ export interface CpiAccount {
2222
2259
  readonly __cpi_account: void;
2223
2260
  }
2224
2261
  /**
2225
- * An optional account (`A | null`) passed as it is, without `!`: left out of the CPI's list when it was not passed
2262
+ * A read-only entry of `invoke`'s account list: an account, or remaining accounts spread (`...readonly(rest)`). An
2263
+ * optional account (`A | null`) passed as it is, without `!`, is left out of the CPI's list when it was not passed
2226
2264
  * (Rust's `if let Some(a) = &self.a { accounts.push(a) }`, as for `with_remaining_accounts`).
2227
2265
  */
2228
2266
  export declare function readonly(account: AccountMeta | RemainingAccount | null): CpiAccount;
2229
2267
  export declare function readonly(accounts: RemainingAccounts | RemainingSlice): Iterable<CpiAccount>;
2268
+ /** A writable account entry for `invoke` (the parameter must be `Mut<…>`); an optional account as for `readonly`. */
2230
2269
  export declare function writable(account: AccountMeta | RemainingAccount | null): CpiAccount;
2231
2270
  export declare function writable(accounts: RemainingAccounts | RemainingSlice): Iterable<CpiAccount>;
2271
+ /** A read-only signer entry for `invoke`: the account signed, or signerSeeds sign for it. */
2232
2272
  export declare function readonlySigner(account: AccountMeta | RemainingAccount): CpiAccount;
2273
+ /** A writable signer entry for `invoke`: the account signed, or signerSeeds sign for it. */
2233
2274
  export declare function writableSigner(account: AccountMeta | RemainingAccount): CpiAccount;
2234
2275
 
2235
2276
  /** Raw bytes for instruction data. */
@@ -2250,7 +2291,7 @@ export declare function hex(literal: string): Bytes;
2250
2291
  export type CpiData = bigint | boolean | Pubkey | Hash | string | null | Bytes | object | number;
2251
2292
 
2252
2293
  /**
2253
- * Cross-program invocation. Pass `signerSeeds` (with the bump) to sign for a PDA of this program;
2294
+ * Call any program (a cross-program invocation) with an account list and instruction data. Pass `signerSeeds` (with the bump) to sign for a PDA of this program;
2254
2295
  * that PDA can then be marked readonlySigner()/writableSigner().
2255
2296
  */
2256
2297
  export declare function invoke(
@@ -2481,7 +2522,7 @@ export interface InstructionBytes extends IndexedList<u8>, ListMethods<u8> {
2481
2522
  readPubkey(offset: u64): Pubkey;
2482
2523
  }
2483
2524
 
2484
- /** Write a string, integer or pubkey to the program log. */
2525
+ /** Write a string, integer, Pubkey or Hash to the program log (a Pubkey or Hash as base58). */
2485
2526
  export declare function log(value: string | bigint | Pubkey | Hash): void;
2486
2527
 
2487
2528
  /**
@@ -2548,7 +2589,7 @@ export declare function i128(value: bigint): i128;
2548
2589
  export declare function mulDiv(a: u64, b: u64, c: u64): u64;
2549
2590
  /** ceil(a * b / c), like mulDiv. */
2550
2591
  export declare function mulDivCeil(a: u64, b: u64, c: u64): u64;
2551
- /** floor(sqrt(x)) for unsigned integers up to u128. */
2592
+ /** floor(sqrt(x)) for unsigned integers (u8 … u256). */
2552
2593
  export declare function isqrt<T extends bigint>(x: T): T;
2553
2594
 
2554
2595
  /**
@@ -2557,9 +2598,13 @@ export declare function isqrt<T extends bigint>(x: T): T;
2557
2598
  * Marginfi's events report I80F48 amounts, and read the bits back with `f64Bits`.
2558
2599
  */
2559
2600
  export type f64 = bigint & { readonly __f64: unique symbol };
2601
+ /** An f64 from its IEEE 754 bits, computed with integers. */
2560
2602
  export declare function f64FromBits(bits: u64): f64;
2603
+ /** An f64's IEEE 754 bits. */
2561
2604
  export declare function f64Bits(value: f64): u64;
2605
+ /** The smaller of two integers of one type. */
2562
2606
  export declare function min<T extends bigint>(a: T, b: T): T;
2607
+ /** The larger of two integers of one type. */
2563
2608
  export declare function max<T extends bigint>(a: T, b: T): T;
2564
2609
 
2565
2610
  /**