@typesol/cli 0.42.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +350 -0
- package/NOTICE +71 -0
- package/README.md +35 -18
- package/SECURITY.md +32 -5
- package/dist/ai.d.ts +1 -1
- package/dist/ai.js +5 -5
- package/dist/cli.js +196 -72
- package/dist/compiler/analyze.js +447 -12
- package/dist/compiler/diagnostics.d.ts +1 -0
- package/dist/compiler/diagnostics.js +13 -0
- package/dist/compiler/emit/alias.d.ts +45 -1
- package/dist/compiler/emit/alias.js +143 -6
- package/dist/compiler/emit/base.d.ts +28 -1
- package/dist/compiler/emit/base.js +77 -9
- package/dist/compiler/emit/borsh.js +11 -5
- package/dist/compiler/emit/calls.d.ts +80 -0
- package/dist/compiler/emit/calls.js +612 -54
- package/dist/compiler/emit/cpi-core.d.ts +23 -4
- package/dist/compiler/emit/cpi-core.js +261 -12
- package/dist/compiler/emit/cpi.js +8 -2
- package/dist/compiler/emit/create.js +3 -0
- package/dist/compiler/emit/expressions.js +44 -8
- package/dist/compiler/emit/function.js +10 -0
- package/dist/compiler/emit/program.js +30 -1
- package/dist/compiler/emit/rbtree.d.ts +7 -0
- package/dist/compiler/emit/rbtree.js +142 -0
- package/dist/compiler/emit/shared.d.ts +25 -0
- package/dist/compiler/emit/shared.js +45 -4
- package/dist/compiler/emit/statements.d.ts +27 -1
- package/dist/compiler/emit/statements.js +305 -23
- package/dist/compiler/emit/storage.d.ts +25 -2
- package/dist/compiler/emit/storage.js +116 -64
- package/dist/compiler/emit/token.js +2 -2
- package/dist/compiler/emit/views.d.ts +60 -0
- package/dist/compiler/emit/views.js +523 -0
- package/dist/compiler/idl.js +2 -1
- package/dist/compiler/index.d.ts +15 -1
- package/dist/compiler/index.js +40 -3
- package/dist/compiler/model.d.ts +65 -4
- package/dist/compiler/model.js +14 -0
- package/dist/compiler/toolchain.d.ts +56 -1
- package/dist/compiler/toolchain.js +246 -12
- package/dist/testing-stake.d.ts +2 -1
- package/dist/testing-stake.js +2 -1
- package/dist/testing.js +6 -4
- package/dist/tools/clientgen.d.ts +15 -0
- package/dist/tools/clientgen.js +173 -7
- package/dist/tools/cpigen.d.ts +0 -15
- package/dist/tools/cpigen.js +19 -8
- package/dist/tools/doctor.d.ts +17 -2
- package/dist/tools/doctor.js +64 -4
- package/dist/tools/portgen.js +43 -18
- package/dist/workspace.d.ts +20 -0
- package/dist/workspace.js +173 -6
- package/docs/ai.md +10 -5
- package/docs/architecture.md +10 -3
- package/docs/audit.md +63 -17
- package/docs/case-study-escrow.md +1 -1
- package/docs/case-study-phoenix.md +226 -0
- package/docs/case-study-raydium-amm.md +3 -3
- package/docs/case-study-spl-stake-pool.md +5 -5
- package/docs/cli.md +17 -8
- package/docs/client.md +11 -3
- package/docs/errors.md +1 -1
- package/docs/language.md +148 -12
- package/docs/mainnet.md +21 -10
- package/docs/migrate-from-anchor.md +3 -1
- package/docs/runtime.md +12 -2
- package/docs/security-model.md +38 -6
- package/docs/stability.md +42 -4
- package/docs/testing.md +25 -0
- package/docs/troubleshooting.md +17 -2
- package/lib/typesol.d.ts +221 -4
- package/llms-full.txt +336 -65
- package/llms.txt +2 -2
- package/package.json +4 -2
- package/runtime/typesol_rt.h +429 -13
- package/test/programs/LICENSE-Apache-2.0.txt +201 -0
package/docs/stability.md
CHANGED
|
@@ -11,8 +11,9 @@ From 1.0 on, within a major version:
|
|
|
11
11
|
|
|
12
12
|
- **Sources keep compiling.** A program that compiles with 1.x compiles with every later 1.y, to a program with the same
|
|
13
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.**
|
|
15
|
-
|
|
14
|
+
- **Binaries are reproducible and only change for a reason.** With the same TypeSOL release and the toolchain it is
|
|
15
|
+
tested with, a source builds to the same bytes. A release that changes the binary of a program that uses none of
|
|
16
|
+
its new features says so, with the release manifest's diff (`binary-diff.txt`) as the evidence.
|
|
16
17
|
- **The checks stay.** No check a program gets from its parameter types (owner, discriminator, signer, writability,
|
|
17
18
|
aliasing, checked arithmetic, constraints) is removed or weakened.
|
|
18
19
|
- **The tools keep their interfaces**: `typesol build`, `test` (via `typesol/testing`), `check --json`, `deploy`,
|
|
@@ -31,6 +32,24 @@ Meant to stay as they are; a change before 1.0 would be a breaking change listed
|
|
|
31
32
|
- CPIs: System, SPL Token, Token-2022, Associated Token, Memo, generic `invoke` with PDA signing.
|
|
32
33
|
- Layouts: account data (Anchor's discriminator and fixed or `@layout borsh` layout), the IDL, the client.
|
|
33
34
|
|
|
35
|
+
## What a release gives you now
|
|
36
|
+
|
|
37
|
+
- **The npm package is the one that was checked.** From 0.43.0 on, `releases/<version>.json` in the repository holds
|
|
38
|
+
the published tarball's shasum and integrity and every file's sha256, packed from a clean export of the release tag
|
|
39
|
+
after install, build and lint. `npm pack` is reproducible here, so anyone can pack the tag again and compare, or
|
|
40
|
+
compare the registry with `node scripts/release-check.ts <version> --verify --registry`
|
|
41
|
+
([docs/testing.md](testing.md#the-npm-tarball)).
|
|
42
|
+
- **The tests cover one toolchain.** Each release declares the Agave and platform-tools it is tested with
|
|
43
|
+
(`TESTED_TOOLCHAIN`, exported from `typesol/compiler`; Agave 3.1.10 and platform-tools v1.52 now). A binary built with
|
|
44
|
+
another clang is outside what the tests cover: `typesol build` and `deploy` warn once, `--toolchain-strict` (or
|
|
45
|
+
`TYPESOL_TOOLCHAIN=strict`) refuses it, and `typesol doctor` shows which one is active.
|
|
46
|
+
- **A build says what made it.** `<name>.build.json` records the TypeSOL, TypeScript, clang and platform-tools versions,
|
|
47
|
+
the host, the SBPF version and the sha256 of every source and of the binary. `typesol verify` uses it to say, on a
|
|
48
|
+
mismatch, whether the toolchains differ. A program on chain records none of this: keep the file with the deployment.
|
|
49
|
+
- **Fixes come as patches of the latest minor.** From 0.44.0 on, a release that only fixes soundness or security
|
|
50
|
+
defects is a patch (0.44.1, …) with no new language surface, and its notes carry the binary diff against the
|
|
51
|
+
previous release ([SECURITY.md](../SECURITY.md#fix-releases)). Older minors are not maintained.
|
|
52
|
+
|
|
34
53
|
## Experimental
|
|
35
54
|
|
|
36
55
|
Useful today, but may still change before 1.0 (each change listed in the CHANGELOG):
|
|
@@ -40,13 +59,33 @@ Useful today, but may still change before 1.0 (each change listed in the CHANGEL
|
|
|
40
59
|
`createProgramAddress`.
|
|
41
60
|
- `loadBorsh` / `storeBorsh` (0.42.0): a native program's Borsh accounts read into a local struct and written back.
|
|
42
61
|
- `BigVec<T>` (0.42.0): SPL's `big_vec`, a list over the rest of a native account.
|
|
62
|
+
- Views at run-time offsets (0.43.0): `loadRawAt` / `loadRawMutAt`, `rawArrayAt` / `rawArrayMutAt`; a read-only
|
|
63
|
+
view read where it is made (`loadRaw<T>(a).field`, `rbTreeAt(…).length`), and the owner check's cache the views share.
|
|
64
|
+
- The built-in RedBlackTree (0.43.0): `rbTreeAt` / `rbTreeMutAt`, lib-sokoban 0.3's byte layout and algorithms,
|
|
65
|
+
its panics in solana-program 1.14–1.17's format, `removeAt(index)` (what it gives for a node in no tree may change).
|
|
43
66
|
- `panic(null, location)` (no log line) and `abort()` (Rust's abort, "SBF program panicked") (0.42.0).
|
|
67
|
+
- Failures without a log line (0.43.0): `ERROR_LOG_PREFIX = null` / `PROGRAM_ERROR_LOG_PREFIX = null`.
|
|
68
|
+
- `findProgramAddressWithBump` (0.43.0), with `const [address, bump] = …` its only array destructuring.
|
|
69
|
+
- Plain type aliases (0.43.0): `type Price = u64`, replaced by the type they name.
|
|
70
|
+
- File-local structs (0.43.0): `interface Pair { … }` without `export`, for helpers and locals, out of the IDL.
|
|
71
|
+
- Constant expressions (0.43.0): top-level integer constants folded from literals and earlier constants, a typed
|
|
72
|
+
one computed in its type.
|
|
73
|
+
- Comma-separated `for` updates and initializers (0.43.0).
|
|
74
|
+
- Stack room (0.43.0): `/** @noinline */` helpers and `/** @heap */` locals.
|
|
44
75
|
- Local `FixedVec` / `FixedArray` lists of structs, `FixedVec.pushAll`, the instruction data as a list (`slice`,
|
|
45
|
-
`InstructionBytes` helper parameters), `invokeInstruction` in helpers (0.42.0)
|
|
76
|
+
`InstructionBytes` helper parameters), `invokeInstruction` in helpers (0.42.0); local FixedVecs given for read-only
|
|
77
|
+
`FixedVec<T, N>` / `Vec<T>` helper parameters (0.43.0).
|
|
46
78
|
- `epochRewards()` and `EpochRewards` (0.42.0): the EpochRewards sysvar through its syscall.
|
|
47
79
|
- `NATIVE_ACCOUNT_WRITES` (0.42.0): opt-in native write semantics for `loadRawMut`, `storeBorsh` and BigVec writes
|
|
48
80
|
(writability and aliasing left to the runtime). It drops checks a program would otherwise get, so it stays outside
|
|
49
81
|
"the checks stay" promise above: it only applies to programs that declare it.
|
|
82
|
+
- `Inout<T>` helper parameters (0.43.0): a helper that changes a struct, FixedArray or FixedVec of the caller's
|
|
83
|
+
that is not an account (a local, a `loadBorsh` local, a field of a `loadRawMut` view, a list element), with the
|
|
84
|
+
aliasing rules at each call. It settles the open edge of helpers taking a writable struct that is not an account,
|
|
85
|
+
which were refused; the rules (what counts as overlapping, which places may move) may still be refined.
|
|
86
|
+
- For native ports (0.43.0): `setReturnData` and `logComputeUnits` in a native entry; `closeRaw`, `assignOwner`
|
|
87
|
+
and `resizeAccount` on remaining accounts; the byte builders of `FixedVec<u8, N>` (`pushLE`, `pushKey`, `pushBorsh`,
|
|
88
|
+
`setLE`, `truncate`); `PANIC_STYLE = "solana-1.14"` and `panicsAt(location, expression)`.
|
|
50
89
|
- Metaplex CPIs (Token Metadata, Core, Bubblegum), oracles (Pyth, Switchboard), the Stake program.
|
|
51
90
|
- `programAt<P>` / `sysvarAt<S>` and remaining accounts in the typed CPIs (System, Token, ATA, Memo, Stake); a ternary
|
|
52
91
|
between remaining accounts and `AccountInfo` parameters (0.42.0).
|
|
@@ -61,7 +100,6 @@ Useful today, but may still change before 1.0 (each change listed in the CHANGEL
|
|
|
61
100
|
- **An external audit** of the compiler and runtime ([audit package](audit.md)), its findings fixed and published.
|
|
62
101
|
- **Settle the open edges**, each either supported or refused with a clear error:
|
|
63
102
|
- a struct holding a FixedVec as both an argument and account data (two layouts, one IDL type);
|
|
64
|
-
- helpers that take a writable struct which is not an account (a `loadRaw` view, a local), now refused;
|
|
65
103
|
- `require` with an error code computed at run time that is 0: fails as an overflow (5100) today, where a native
|
|
66
104
|
program returns CUSTOM_ZERO;
|
|
67
105
|
- which experimental parts above become stable, and which stay outside the 1.0 promise.
|
package/docs/testing.md
CHANGED
|
@@ -13,6 +13,9 @@ run prints its seed; reproduce with `FUZZ_SEED=<n>`, widen with `FUZZ_RUNS` / `F
|
|
|
13
13
|
| `showcase/test/fuzz-jito.test.ts` | Jito's tip payment, tip distribution and priority fee distribution as deployed on mainnet | random sequences of tips, receiver and builder changes, accounts opened over epochs, roots uploaded, Merkle claims (wrong amounts, proofs and signers among them), closes and config changes, with at most one injected fault per transaction: the same outcome, account bytes, events and log lines as the original after every step; keys, amounts and choices all come from the seed |
|
|
14
14
|
| `showcase/test/fuzz-marginfi.test.ts` | Marginfi v2 as deployed on mainnet | random sequences of bank creation (random weights, curves and fees, most valid, some broken one way), configuration (operational states, curves, liquidation fees, the circuit breaker's switch and settings, frozen banks), accruals over balances written into both at every scale and clock jumps up to a year, limits, pauses, wrong signers: the same outcome, account bytes and events as the original after every step; inputs the original panics on (a negative fee rate) must fail in the port too |
|
|
15
15
|
| the `fuzz:` case of `showcase/test/raydium-clmm.test.ts` | Raydium CLMM as deployed on mainnet | random swaps (both ways, exact in and out, price limits, thresholds), positions opened at random ranges, and liquidity added and taken out (over the position's own, under slippage limits): the same outcome, account bytes and events as the original after every step; choices and amounts come from the seed (`CLMM_FUZZ_STEPS` lengthens it), keys are fresh each run; each transaction may use 1.4M compute units, so a swap the original needs more than 200,000 for still runs to its end |
|
|
16
|
+
| `showcase/test/spl-stake-pool-fuzz.test.ts` | SPL Stake Pool as deployed on mainnet | a random walk over many epochs: validators added and removed, deposits, withdrawals, stake increased and decreased, rewards and tips at each epoch boundary, some steps wrong on purpose; every step gives the same outcome, logs and account bytes as the original, and every account the walk knows is compared after each epoch and every 25 steps; choices and amounts come from the seed (`STAKE_POOL_FUZZ_STEPS` lengthens it, `STAKE_POOL_FUZZ_SWEEP=1` compares every account after each step), keys are fresh each run |
|
|
17
|
+
| `showcase/test/phoenix-fuzz.test.ts` | Phoenix v1 as deployed on mainnet, and a balance model | a random walk over two order books (512/128 and 4096/8321, each started nearly full): every kind of order, reductions and cancels, seats, evictions, fee collection, status changes, a moving clock and invalid packets; every step gives the same outcome, logs, inner instructions, return data and account bytes as the original, and after each step every trader's locked and free lots plus the uncollected fees equal what the vaults hold; choices and every key come from the seed, CI walks seeds 1, 2 and 3 (300 steps on each market) and requires minimum counts of fills, evictions, expiries and fees (`PHOENIX_FUZZ_STEPS` changes the length) |
|
|
18
|
+
| `test/verification/rbtree-trace.test.ts` | lib-sokoban 0.3.0 itself (`test/verification/rbtree/oracle`, a Rust program that records traces) | the built-in RedBlackTree replays 21,650 recorded operations (capacities 1 to 4096; u64 keys, Phoenix's order ids with their comparator, Pubkey keys), one a transaction: after each the tree's bytes (root, allocator, every node, freed ones included) hash as the crate's did and the operation returns what the crate's returned; a second pass replays every `remove(key)` as `removeAt(addrOf(key))`; `RBTREE_TRACES=<file>` replays another set |
|
|
16
19
|
| `test/verification/differential.test.ts` | Anchor twins in `test/anchor-twins` | identical transactions to TypeSOL and Anchor programs: same outcomes, same account contents, same wallet and token balances after every step |
|
|
17
20
|
| `showcase/test/porting/ports-*.test.ts` | the Anchor programs of solana-developers/program-examples and their tests | TypeSOL rewrites under `showcase/program-examples/` run the originals' flows and failure paths with the same outcomes, error codes and balances ([showcase/program-examples/README.md](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md)) |
|
|
18
21
|
|
|
@@ -65,3 +68,25 @@ node scripts/release-manifest.ts --diff a.json b.json
|
|
|
65
68
|
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
|
|
66
69
|
the same binary and IDL with both packages.
|
|
67
70
|
|
|
71
|
+
### The npm tarball
|
|
72
|
+
|
|
73
|
+
From 0.43.0 on, `releases/<version>.json` in the repository describes the package on npm: the tag and its commit, the
|
|
74
|
+
tarball's size, sha1 shasum and sha512 integrity (the registry's `dist.shasum` and `dist.integrity`), and the sha256
|
|
75
|
+
of every file in it. `scripts/release-check.ts` writes it from a clean export of the tag (`git archive`: install with
|
|
76
|
+
the lockfile, build, lint, check the version and the CHANGELOG section, `npm pack`), and the maintainer publishes the
|
|
77
|
+
tarball it produced, by hand ([CONTRIBUTING.md](https://github.com/typesol-lang/typesol/blob/main/CONTRIBUTING.md#releasing)). To check a release yourself:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
node scripts/release-check.ts 0.43.0 # pack the tag again: git diff releases/ shows what moved
|
|
81
|
+
node scripts/release-check.ts 0.43.0 --verify --registry # the registry's hashes against the record
|
|
82
|
+
npm pack @typesol/cli@0.43.0 --pack-destination /tmp/pub
|
|
83
|
+
node scripts/release-check.ts 0.43.0 --verify --tarball /tmp/pub/typesol-cli-0.43.0.tgz # file by file
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`npm pack` is reproducible here: two clean exports of v0.43.0 packed to the same bytes, and to the published tarball
|
|
87
|
+
(shasum `10c2883bf3a01fcb16a86c1dbbbb696e1e962b2c`, with Node 25.9.0, pnpm 11.9.0 and npm 11.12.1). npm writes every
|
|
88
|
+
entry with a fixed date and mode, in a fixed order; what can still change the bytes is another npm (its tar headers)
|
|
89
|
+
or another Node (its zlib compresses the archive). The record also keeps the uncompressed archive's sha256 and each
|
|
90
|
+
file's, which compare across those, and `--verify --tarball` says which files differ, if any. 0.42.0 and earlier
|
|
91
|
+
were published from a maintainer's checkout without a record.
|
|
92
|
+
|
package/docs/troubleshooting.md
CHANGED
|
@@ -6,6 +6,18 @@ and next to `cargo-build-sbf` on PATH; set `TYPESOL_SBF_SDK` to a `platform-tool
|
|
|
6
6
|
|
|
7
7
|
**"platform-tools missing" / "no SBPF v2 libraries"** — `cargo-build-sbf --force-tools-install`.
|
|
8
8
|
|
|
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.
|
|
15
|
+
|
|
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.
|
|
20
|
+
|
|
9
21
|
**Windows** — not tested; use WSL2 with the Linux Agave CLI.
|
|
10
22
|
|
|
11
23
|
**Node errors such as `ERR_UNKNOWN_FILE_EXTENSION` or `ERR_REQUIRE_ESM`** — use Node.js 22.12 or newer.
|
|
@@ -37,6 +49,9 @@ uses. Publishing works on mainnet-beta. The error shows the failing transaction'
|
|
|
37
49
|
SBPF v0 (the default) every function gets a fixed 4 KiB stack frame, and going past it corrupts memory, so the build
|
|
38
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
|
|
39
51
|
locals (`const q: Big = acct.big`) are the usual cause: bind them without a type (`const q = acct.big`, a reference
|
|
40
|
-
into the account data)
|
|
41
|
-
locals
|
|
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).
|
|
42
57
|
|
package/lib/typesol.d.ts
CHANGED
|
@@ -124,6 +124,12 @@ export interface Vec<T> extends ListMethods<T> {
|
|
|
124
124
|
* grows one `push` at a time, so calling it on a Vec is a compile error.
|
|
125
125
|
*/
|
|
126
126
|
pushAll(items: IndexedList<T>): void;
|
|
127
|
+
/** A `FixedVec<u8, N>`'s byte builders (declared here for the same reason; a compile error on a Vec). */
|
|
128
|
+
pushLE<I extends bigint = bigint>(this: Vec<u8>, value: I): void;
|
|
129
|
+
pushKey(this: Vec<u8>, key: Pubkey): void;
|
|
130
|
+
pushBorsh<V = unknown>(this: Vec<u8>, value: V): void;
|
|
131
|
+
setLE<I extends bigint = bigint>(this: Vec<u8>, offset: u64, value: I): void;
|
|
132
|
+
truncate(this: Vec<u8>, length: u64): void;
|
|
127
133
|
/** Remove and return the last element, shrinking the account. */
|
|
128
134
|
pop(): T;
|
|
129
135
|
/** Remove every element, shrinking the account. */
|
|
@@ -150,6 +156,28 @@ export interface FixedVec<T, N extends number> extends ListMethods<T> {
|
|
|
150
156
|
pushAll(items: IndexedList<T>): void;
|
|
151
157
|
pop(): T;
|
|
152
158
|
clear(): void;
|
|
159
|
+
/**
|
|
160
|
+
* A `FixedVec<u8, N>` as a byte buffer: append an integer's little-endian bytes at its width (`buf.pushLE(count)`
|
|
161
|
+
* with `count: u16`; a literal needs one: `buf.pushLE<u16>(1n)` or `buf.pushLE(u16(1n))`). Every byte builder
|
|
162
|
+
* fails (5104) and appends nothing when the bytes do not fit in the room left.
|
|
163
|
+
*/
|
|
164
|
+
pushLE<I extends bigint = bigint>(this: FixedVec<u8, N>, value: I): void;
|
|
165
|
+
/** Append a Pubkey's 32 bytes. */
|
|
166
|
+
pushKey(this: FixedVec<u8, N>, key: Pubkey): void;
|
|
167
|
+
/**
|
|
168
|
+
* Append a value's Borsh encoding, as invoke data, events and storeBorsh encode it: a struct (an object literal
|
|
169
|
+
* takes its type: `buf.pushBorsh<Header>({ … })`), a data enum (a tag byte, then the variant's fields), a
|
|
170
|
+
* FixedArray, a list (u32 count, then the elements), an integer at its width, a boolean, a Pubkey, a string or an
|
|
171
|
+
* Option.
|
|
172
|
+
*/
|
|
173
|
+
pushBorsh<V = unknown>(this: FixedVec<u8, N>, value: V): void;
|
|
174
|
+
/**
|
|
175
|
+
* Overwrite the integer at byte `offset` with `value`'s little-endian bytes (`buf.setLE<u16>(91n, count)`): within the
|
|
176
|
+
* length, 5104 past it, as Rust's `data[a..b].copy_from_slice(…)` panics there.
|
|
177
|
+
*/
|
|
178
|
+
setLE<I extends bigint = bigint>(this: FixedVec<u8, N>, offset: u64, value: I): void;
|
|
179
|
+
/** Keep the first `length` bytes (5104 when `length` is past the current length). */
|
|
180
|
+
truncate(this: FixedVec<u8, N>, length: u64): void;
|
|
153
181
|
[Symbol.iterator](): Iterator<T>;
|
|
154
182
|
readonly __capacity?: N;
|
|
155
183
|
}
|
|
@@ -256,6 +284,125 @@ export declare function loadAccountMut<T>(account: RemainingAccount | AccountInf
|
|
|
256
284
|
*/
|
|
257
285
|
export declare function loadRaw<T>(account: RemainingAccount | AccountInfo): Account<T>;
|
|
258
286
|
export declare function loadRawMut<T>(account: RemainingAccount | AccountInfo): Mut<T>;
|
|
287
|
+
/**
|
|
288
|
+
* `loadRaw` / `loadRawMut` at a byte offset known only at run time (a native account whose parts start where its header
|
|
289
|
+
* says: Phoenix's market at byte 576). Owned by this program (3007); `offset + size(T)` within the data, checked once
|
|
290
|
+
* here (ProgramError::AccountDataTooSmall); `loadRawMutAt` writable and claimed as `loadRawMut` is (2040; neither with
|
|
291
|
+
* `NATIVE_ACCOUNT_WRITES`). Bind it with const: `const market = loadRawMutAt<FifoMarket>(acct, 576n)`. A view (this one,
|
|
292
|
+
* `rawArrayAt`, `rbTreeAt` and what is read through them) is not used after `closeRaw` or `resizeAccount` of an account
|
|
293
|
+
* it may view, since its bounds were checked against the old length: take it again after (a compile error says so).
|
|
294
|
+
*/
|
|
295
|
+
export declare function loadRawAt<T>(account: RemainingAccount | AccountInfo, offset: u64): Account<T>;
|
|
296
|
+
export declare function loadRawMutAt<T>(account: RemainingAccount | AccountInfo, offset: u64): Mut<T>;
|
|
297
|
+
/**
|
|
298
|
+
* `capacity` elements of a fixed-size type packed in place from a run-time byte offset, the count known only at run
|
|
299
|
+
* time (a slab sized by its header). Bounds checked once when it is made (`offset + capacity × size(T)` within the
|
|
300
|
+
* data, overflow included: ProgramError::AccountDataTooSmall), then `get` / `set` check the index against the count
|
|
301
|
+
* (5104). Elements are references into the account (structs) or values. `.length` is the capacity.
|
|
302
|
+
*/
|
|
303
|
+
export interface RawArray<T> extends ListMethods<T> {
|
|
304
|
+
readonly length: u64;
|
|
305
|
+
get(index: bigint): T;
|
|
306
|
+
set(index: bigint, value: T): void;
|
|
307
|
+
[Symbol.iterator](): Iterator<T>;
|
|
308
|
+
}
|
|
309
|
+
/** A RawArray of a read-only view (`rawArrayAt`): elements are read, not written. */
|
|
310
|
+
export interface ReadonlyRawArray<T> extends ListMethods<T> {
|
|
311
|
+
readonly length: u64;
|
|
312
|
+
get(index: bigint): Readonly<T>;
|
|
313
|
+
[Symbol.iterator](): Iterator<Readonly<T>>;
|
|
314
|
+
}
|
|
315
|
+
/** `const slab = rawArrayMutAt<Order>(acct, offset, capacity)`: see RawArray. */
|
|
316
|
+
export declare function rawArrayAt<T>(account: RemainingAccount | AccountInfo, offset: u64, capacity: u64): ReadonlyRawArray<T>;
|
|
317
|
+
export declare function rawArrayMutAt<T>(account: RemainingAccount | AccountInfo, offset: u64, capacity: u64): RawArray<T>;
|
|
318
|
+
|
|
319
|
+
/** A node of a RedBlackTree: its key (read-only), its value (in place) and its index in the tree's node array (1-based). */
|
|
320
|
+
export interface RbEntry<K, V> {
|
|
321
|
+
readonly key: Readonly<K>;
|
|
322
|
+
value: V;
|
|
323
|
+
readonly index: u32;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* lib-sokoban 0.3's `RedBlackTree<K, V, N>` in account data, byte for byte (Phoenix's order books and trader seats):
|
|
327
|
+
* at the offset, root u32, padding, the allocator (size u64, bump index u32, free list head u32), then `capacity` nodes
|
|
328
|
+
* of 16 register bytes + K + V, 1-based. Every operation makes the writes sokoban makes, so a port's account bytes
|
|
329
|
+
* match the original's after every instruction (freed nodes keep their key and value bytes; the free list is LIFO).
|
|
330
|
+
* Keys are ordered by the comparator given to `rbTreeMutAt`, called as `compare(searchedKey, nodeKey)`, or by default
|
|
331
|
+
* as Rust derives Ord (fields in order, integers by value, Pubkeys by their bytes).
|
|
332
|
+
*/
|
|
333
|
+
export interface RedBlackTree<K, V> {
|
|
334
|
+
/** The number of keys (sokoban's `len()`). */
|
|
335
|
+
readonly length: u64;
|
|
336
|
+
/** The number of nodes it was made with (sokoban's `capacity()`, its `N`). */
|
|
337
|
+
readonly capacity: u64;
|
|
338
|
+
/** NodeAllocator::initialize on zeroed bytes; anything else panics "Cannot reinitialize NodeAllocator", as sokoban. */
|
|
339
|
+
initialize(): void;
|
|
340
|
+
/** The value stored for `key`, in place (a reference: writes go to the tree), or null. */
|
|
341
|
+
get(key: K): V | null;
|
|
342
|
+
/**
|
|
343
|
+
* Insert, or replace the value of an equal key (keeping its node). The node index, or null when a new key finds the
|
|
344
|
+
* tree full (nothing written); a tree that is empty takes the key without that check, as sokoban's does.
|
|
345
|
+
* References into the tree's nodes (`get`, `min`, entries, however bound: `c ? t.min() : t.max()`, `t.get(k)!`)
|
|
346
|
+
* cannot be used after an insert (a freed node may be reused).
|
|
347
|
+
*/
|
|
348
|
+
insert(key: K, value: V): u32 | null;
|
|
349
|
+
/** Remove `key`: its value (a struct in place in the freed node, which keeps its bytes until reused), or null. */
|
|
350
|
+
remove(key: K): V | null;
|
|
351
|
+
/**
|
|
352
|
+
* Remove the node at `index` (from `addrOf`, a node of `min` / `max` / `get`'s entry or a walk): the same writes as
|
|
353
|
+
* `remove(node.key)`, without searching the tree again. Its value, or null for index 0 or a node that holds no key
|
|
354
|
+
* (a freed one); past the capacity panics as `nodeAt` does.
|
|
355
|
+
*/
|
|
356
|
+
removeAt(index: u32): V | null;
|
|
357
|
+
/** The node with the smallest key (sokoban's get_min_index), or null when empty. */
|
|
358
|
+
min(): RbEntry<K, V> | null;
|
|
359
|
+
/** The node with the largest key, or null. */
|
|
360
|
+
max(): RbEntry<K, V> | null;
|
|
361
|
+
/** The index of the node holding `key` (sokoban's get_addr), 0 when absent. */
|
|
362
|
+
addrOf(key: K): u32;
|
|
363
|
+
/** Node `index` as stored (sokoban's get_node), whether or not it holds a key; 0 or past the capacity panics as Rust's indexing. */
|
|
364
|
+
nodeAt(index: u32): RbEntry<K, V>;
|
|
365
|
+
/** `for (const e of tree.reversed())`: from the largest key down. */
|
|
366
|
+
reversed(): Iterable<RbEntry<K, V>>;
|
|
367
|
+
/**
|
|
368
|
+
* `for (const e of tree)`: from the smallest key up, `break` and `continue` as in any loop. The body may change values
|
|
369
|
+
* but not insert, remove or initialize on this tree or on any tree view of an account that may be this one (another
|
|
370
|
+
* view of the same tree), nor call a helper that takes accounts and makes an `rbTreeMutAt` view.
|
|
371
|
+
*/
|
|
372
|
+
[Symbol.iterator](): Iterator<RbEntry<K, V>>;
|
|
373
|
+
}
|
|
374
|
+
/** A RedBlackTree of a read-only view (`rbTreeAt`): read, never changed. */
|
|
375
|
+
export interface ReadonlyRedBlackTree<K, V> {
|
|
376
|
+
readonly length: u64;
|
|
377
|
+
readonly capacity: u64;
|
|
378
|
+
get(key: K): Readonly<V> | null;
|
|
379
|
+
min(): Readonly<RbEntry<K, Readonly<V>>> | null;
|
|
380
|
+
max(): Readonly<RbEntry<K, Readonly<V>>> | null;
|
|
381
|
+
addrOf(key: K): u32;
|
|
382
|
+
nodeAt(index: u32): Readonly<RbEntry<K, Readonly<V>>>;
|
|
383
|
+
reversed(): Iterable<Readonly<RbEntry<K, Readonly<V>>>>;
|
|
384
|
+
[Symbol.iterator](): Iterator<Readonly<RbEntry<K, Readonly<V>>>>;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* lib-sokoban 0.3's RedBlackTree<K, V, capacity> at a run-time byte offset (see RedBlackTree): owned by this program
|
|
388
|
+
* (3007), its 32 + capacity × (16 + size(K) + size(V)) bytes within the data (ProgramError::AccountDataTooSmall),
|
|
389
|
+
* `rbTreeMutAt` writable and claimed as `loadRawMut` is. `compare`, a function of the program `(a: K, b: K) => i8`
|
|
390
|
+
* (negative: a first; any signed integer type, an unsigned result is refused as it could never say "less"), orders the keys; it is called as compare(searchedKey, nodeKey), so an order that depends on the
|
|
391
|
+
* left key (Phoenix's FIFOOrderId: bids descending, asks ascending, by the sequence number's top bit) works as in
|
|
392
|
+
* Rust. Without it, keys are ordered as Rust's derived Ord orders them.
|
|
393
|
+
*/
|
|
394
|
+
export declare function rbTreeAt<K, V>(
|
|
395
|
+
account: RemainingAccount | AccountInfo,
|
|
396
|
+
offset: u64,
|
|
397
|
+
capacity: u64,
|
|
398
|
+
compare?: (a: K, b: K) => bigint,
|
|
399
|
+
): ReadonlyRedBlackTree<K, V>;
|
|
400
|
+
export declare function rbTreeMutAt<K, V>(
|
|
401
|
+
account: RemainingAccount | AccountInfo,
|
|
402
|
+
offset: u64,
|
|
403
|
+
capacity: u64,
|
|
404
|
+
compare?: (a: K, b: K) => bigint,
|
|
405
|
+
): RedBlackTree<K, V>;
|
|
259
406
|
/**
|
|
260
407
|
* A native program's Borsh account, as Rust's `try_from_slice_unchecked::<T>(&data)` reads it: the data from byte 0
|
|
261
408
|
* decoded into a local `T` (a copy; write it back with `storeBorsh`). No owner check and no discriminator; bytes after
|
|
@@ -717,6 +864,12 @@ export declare function createProgramAddress(seeds: Seed[], program: Pubkey): Pu
|
|
|
717
864
|
export declare function logBase64(prefix: string, value: object): void;
|
|
718
865
|
/** The bump of that canonical program address (`Pubkey::find_program_address(seeds, program).1`), to sign with it. */
|
|
719
866
|
export declare function findProgramAddressBump(seeds: Seed[], program: Pubkey): u8;
|
|
867
|
+
/**
|
|
868
|
+
* The canonical program address and its bump from one search (Rust's `let (address, bump) =
|
|
869
|
+
* Pubkey::find_program_address(seeds, program)`), where `findProgramAddress` and `findProgramAddressBump` would search
|
|
870
|
+
* twice: bind both, `const [address, bump] = findProgramAddressWithBump(["seat", market, trader], PHOENIX_ID)`.
|
|
871
|
+
*/
|
|
872
|
+
export declare function findProgramAddressWithBump(seeds: Seed[], program: Pubkey): [address: Pubkey, bump: u8];
|
|
720
873
|
/** This program's address (`crate::ID`). */
|
|
721
874
|
export declare function programId(): Pubkey;
|
|
722
875
|
/**
|
|
@@ -820,11 +973,30 @@ export declare const AuthorityType: {
|
|
|
820
973
|
*/
|
|
821
974
|
export declare function realloc(account: AccountMeta, newSize: u64, payer: Mut<Signer>): void;
|
|
822
975
|
/**
|
|
823
|
-
* Resize a `Mut<AccountInfo>` of this program to `newSize` bytes (Rust's `AccountInfo::resize`
|
|
824
|
-
* the new bytes zeroed. No rent moves: fund the account first
|
|
825
|
-
* left short. At most 10 KiB past its size when the
|
|
976
|
+
* Resize a `Mut<AccountInfo>` or a remaining account of this program to `newSize` bytes (Rust's `AccountInfo::resize` /
|
|
977
|
+
* `realloc(newSize, true)`): the data length only, the new bytes zeroed. No rent moves: fund the account first
|
|
978
|
+
* (`rentExempt(newSize)`), the runtime refuses an account left short. At most 10 KiB past its size when the
|
|
979
|
+
* instruction started (3016). A remaining account must be writable (3006) unless the program declares
|
|
980
|
+
* `NATIVE_ACCOUNT_WRITES`, which also lets an `AccountInfo` parameter be resized without `Mut<…>`. A view of the
|
|
981
|
+
* account made before (`loadRawMutAt`, `rbTreeMutAt` …) is not used after it: take the view again.
|
|
826
982
|
*/
|
|
827
|
-
export declare function resizeAccount(account: Mut<AccountInfo>, newSize: u64): void;
|
|
983
|
+
export declare function resizeAccount(account: RemainingAccount | Mut<AccountInfo>, newSize: u64): void;
|
|
984
|
+
/**
|
|
985
|
+
* Close an account of this program as a native program does it by hand (Phoenix's Tombstone), in this order:
|
|
986
|
+
* `receiver.lamports += account.lamports`, `account.lamports = 0`, the owner set to the System Program, the data length
|
|
987
|
+
* set to 0 (`realloc(0, false)`: the bytes are not zeroed, the runtime drops them with the length). Unlike `close` it
|
|
988
|
+
* takes remaining accounts and `AccountInfo` parameters and leaves the data unwiped. Both accounts are checked writable
|
|
989
|
+
* (3006; `Mut<AccountInfo>` parameters) and passed once (2040), the account owned by this program (3007) and not the
|
|
990
|
+
* receiver itself; with `NATIVE_ACCOUNT_WRITES` nothing is checked and the runtime judges the result, as for the
|
|
991
|
+
* original. A view of the account made before is not used after it.
|
|
992
|
+
*/
|
|
993
|
+
export declare function closeRaw(account: RemainingAccount | Mut<AccountInfo>, receiver: RemainingAccount | Mut<AccountInfo>): void;
|
|
994
|
+
/**
|
|
995
|
+
* Set an account's owner in place (Rust's `AccountInfo::assign`). The runtime accepts the change, at the end of the
|
|
996
|
+
* instruction or at the next CPI, only for a writable account of this program whose data is empty or zeroed. Checked
|
|
997
|
+
* as `closeRaw` checks its account (writable, passed once, this program's), or not at all under `NATIVE_ACCOUNT_WRITES`.
|
|
998
|
+
*/
|
|
999
|
+
export declare function assignOwner(account: RemainingAccount | Mut<AccountInfo>, owner: Pubkey): void;
|
|
828
1000
|
|
|
829
1001
|
/**
|
|
830
1002
|
* Token-2022 extensions of a mint (any account works; legacy SPL Token mints have none).
|
|
@@ -895,6 +1067,20 @@ export type Account<T> = Readonly<T> & AccountMeta;
|
|
|
895
1067
|
*/
|
|
896
1068
|
export type Mut<T, E = never> = T & AccountMeta;
|
|
897
1069
|
|
|
1070
|
+
/**
|
|
1071
|
+
* A helper parameter the helper may change in place (Rust's `&mut T`): `function addEvent(rec: Inout<Recorder>, e:
|
|
1072
|
+
* Event): void`. The helper gets the caller's place itself, not a copy, and the caller sees its writes after the call,
|
|
1073
|
+
* as JS shares an object passed to a function. `T` is a fixed-size struct, a `FixedArray<T, N>` or a `FixedVec<T, N>`
|
|
1074
|
+
* (whose `push`, `pop` and `clear` the caller sees too). The caller passes a writable place: a local struct or list,
|
|
1075
|
+
* a `loadBorsh` local, a field of a `Mut<T>` account or of a `loadRawMut` view, a list element (`book.levels.get(i)`)
|
|
1076
|
+
* or another `Inout` parameter. Two arguments of one call may not overlap: places that may be the same bytes only at
|
|
1077
|
+
* run time (two `Dup` accounts, a writable and a read-only account, two native views under `NATIVE_ACCOUNT_WRITES`) are
|
|
1078
|
+
* compared before the call, an Inout one with every other argument passed in place (2040 when they overlap). Other
|
|
1079
|
+
* struct parameters stay read-only.
|
|
1080
|
+
* Integers are values in JS too: return the new value, or wrap it in a struct.
|
|
1081
|
+
*/
|
|
1082
|
+
export type Inout<T> = T;
|
|
1083
|
+
|
|
898
1084
|
/** A PDA seed: a string, a Pubkey, a Hash (its 32 bytes), an integer (at its width) or a unit enum value (one byte). */
|
|
899
1085
|
export type Seed = string | Pubkey | Hash | bigint | number;
|
|
900
1086
|
|
|
@@ -2232,8 +2418,22 @@ export declare enum ProgramError {
|
|
|
2232
2418
|
* `location` ("program/src/instruction.rs:482:17") is the place the runtime reports, as the original's panic gives it;
|
|
2233
2419
|
* by default this source line. A `null` message logs nothing, for a program whose panic handler writes no line of its
|
|
2234
2420
|
* own: `panic(null, "src/lib.rs:105:19")` leaves only the runtime's "SBF program Panicked in src/lib.rs at 105:19".
|
|
2421
|
+
* Under `export const PANIC_STYLE = "solana-1.14"` (a program built with solana-program 1.14 to 1.17) it logs
|
|
2422
|
+
* `panicked at '<message>', <location>` and aborts, so the runtime reports "SBF program panicked", as that panic
|
|
2423
|
+
* handler does; a message is then required.
|
|
2235
2424
|
*/
|
|
2236
2425
|
export declare function panic(message?: string | null, location?: string): never;
|
|
2426
|
+
/**
|
|
2427
|
+
* `value`, with its checked arithmetic panicking as Rust's overflow checks do at `location` ("file:line:column", where
|
|
2428
|
+
* the original's expression is): `panicsAt("src/quantities.rs:233:1", a + b)` logs "attempt to add with overflow"
|
|
2429
|
+
* there (also "attempt to subtract / multiply with overflow", "attempt to divide by zero", "attempt to calculate the
|
|
2430
|
+
* remainder with a divisor of zero", "attempt to negate with overflow", "attempt to divide with overflow", "attempt to
|
|
2431
|
+
* shift left / right with overflow" for a shift amount past the width), as `panic` logs (see `PANIC_STYLE`), instead
|
|
2432
|
+
* of failing with 5100 / 5101. Only the operators written inside it, not the helpers it calls; u256 arithmetic, `**`,
|
|
2433
|
+
* `mulDiv`, casts and the bits `<<` loses keep TypeSOL's failures (Rust checks them otherwise, or with other messages); an inner `panicsAt`
|
|
2434
|
+
* gives its own operators their own location. As a statement it takes an assignment: `panicsAt(loc, total += fee);`.
|
|
2435
|
+
*/
|
|
2436
|
+
export declare function panicsAt<T>(location: string, value: T): T;
|
|
2237
2437
|
/**
|
|
2238
2438
|
* Stop the program as Rust's `abort` does on SBF (the allocator's out-of-memory error, `std::process::abort`): the
|
|
2239
2439
|
* runtime's `abort` syscall, which fails the instruction with ProgramFailedToComplete and logs "SBF program panicked"
|
|
@@ -2299,6 +2499,23 @@ export declare function emit<T>(event: T): void;
|
|
|
2299
2499
|
*/
|
|
2300
2500
|
export declare function returnData<T extends bigint | boolean | Pubkey | Hash | object>(program: AccountMeta): T;
|
|
2301
2501
|
|
|
2502
|
+
/**
|
|
2503
|
+
* Set this instruction's return data to `bytes` as they are (Rust's `set_return_data(&bytes)`): a list of u8 such as a
|
|
2504
|
+
* local `FixedVec<u8, N>`, a Vec or FixedVec in account data, or the instruction data or a slice of it. For a native
|
|
2505
|
+
* port's `@fallback` entry and helpers (`set_return_data(order_ids.try_to_vec()?.as_ref())`), and void instructions.
|
|
2506
|
+
* The last call wins, and a CPI made afterwards replaces it with the callee's (call it after the last CPI, as Rust
|
|
2507
|
+
* must). More than 1024 bytes fails as Rust's call does: the runtime refuses it ("Return data too large").
|
|
2508
|
+
* An instruction that returns a value cannot call it (its return value is its return data); a helper it calls may, and
|
|
2509
|
+
* the instruction's return value, set last, replaces what the helper set.
|
|
2510
|
+
*/
|
|
2511
|
+
export declare function setReturnData(bytes: IndexedList<u8>): void;
|
|
2512
|
+
|
|
2513
|
+
/**
|
|
2514
|
+
* Log the compute units left (Rust's `sol_log_compute_units()`): the runtime writes "Program consumption: <N> units
|
|
2515
|
+
* remaining", as the original's line, at the same place.
|
|
2516
|
+
*/
|
|
2517
|
+
export declare function logComputeUnits(): void;
|
|
2518
|
+
|
|
2302
2519
|
/**
|
|
2303
2520
|
* Verify `account.key` is the PDA for `seeds` + `bump` under this program. Any bump that gives a PDA passes (Anchor's
|
|
2304
2521
|
* `bump = expr`): use a stored bump, not one from the arguments, or the caller picks among up to 256 addresses.
|