@typesol/cli 0.49.0 → 0.50.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 +397 -0
- package/NOTICE +9 -0
- package/README.md +25 -8
- package/SECURITY.md +4 -3
- package/dist/compiler/analyze.d.ts +2 -0
- package/dist/compiler/analyze.js +7 -1
- package/dist/compiler/emit/base.d.ts +4 -3
- package/dist/compiler/emit/base.js +9 -3
- package/dist/compiler/emit/borsh.js +8 -8
- package/dist/compiler/emit/calls.d.ts +6 -0
- package/dist/compiler/emit/calls.js +71 -12
- package/dist/compiler/emit/cpi-core.js +3 -3
- package/dist/compiler/emit/cpi.js +2 -2
- package/dist/compiler/emit/expressions.d.ts +1 -0
- package/dist/compiler/emit/expressions.js +12 -0
- package/dist/compiler/emit/function.js +12 -8
- package/dist/compiler/emit/program.js +8 -2
- package/dist/compiler/emit/rbtree.js +1 -1
- package/dist/compiler/emit/shared.d.ts +12 -2
- package/dist/compiler/emit/shared.js +26 -6
- package/dist/compiler/emit/statements.d.ts +8 -1
- package/dist/compiler/emit/statements.js +53 -5
- package/dist/compiler/emit/storage.js +12 -10
- package/dist/compiler/emit/views.js +1 -1
- package/dist/compiler/index.d.ts +15 -1
- package/dist/compiler/index.js +50 -9
- package/dist/keys.d.ts +12 -1
- package/dist/keys.js +57 -7
- package/dist/workspace.d.ts +8 -0
- package/dist/workspace.js +90 -15
- package/docker/deps/0.50.0.lock.json +1206 -0
- package/docs/architecture.md +1 -1
- package/docs/audit.md +13 -12
- package/docs/case-study-jito-mev.md +14 -14
- package/docs/case-study-marginfi.md +127 -127
- package/docs/case-study-multisig.md +16 -4
- package/docs/case-study-raydium-clmm.md +44 -28
- package/docs/case-study-raydium-cp-swap.md +18 -18
- package/docs/cli.md +4 -3
- package/docs/language-accounts.md +16 -10
- package/docs/language-basics.md +4 -1
- package/docs/language-builtins.md +4 -2
- package/docs/language-cpi.md +34 -0
- package/docs/language-native.md +50 -4
- package/docs/language-statements.md +2 -1
- package/docs/language-types.md +13 -3
- package/docs/runtime.md +19 -2
- package/docs/security-model.md +4 -3
- package/docs/stability.md +5 -4
- package/docs/testing.md +6 -2
- package/lib/typesol.d.ts +25 -3
- package/llms-full.txt +136 -31
- package/package.json +1 -1
- package/releases/0.49.0.json +857 -0
- package/runtime/typesol_builtins.c +47 -2
- package/runtime/typesol_rt.h +129 -3
package/llms-full.txt
CHANGED
|
@@ -591,9 +591,12 @@ export function setup(config: Mut<Config>): void {
|
|
|
591
591
|
- Constants are inlined where they are used, and may be seeds; when a seed is a constant, the IDL records its value.
|
|
592
592
|
- A constant with an integer type is computed in that type, every step checked: `const X: u64 = 1n - 2n + 5n` is an
|
|
593
593
|
error (`1n - 2n is -1, which does not fit in u64`), and `const M: u8 = ~1n` is 254 (`~` within the width).
|
|
594
|
-
Division by zero, a negative exponent or a shift past the width are compile errors
|
|
594
|
+
Division by zero, a negative exponent or a shift past the width are compile errors, and so is a signed type's
|
|
595
|
+
minimum divided by or reduced modulo -1 (`const X: i8 = -128n % -1n`: the quotient does not fit, and at run time
|
|
596
|
+
that remainder fails with 5100 too), where JavaScript's bigint gives 0.
|
|
595
597
|
- An untyped integer constant is inlined as its value and takes the type of the place it is used in, as a literal
|
|
596
598
|
does: `const FEE = 30n` stores into a `u16` field, and `const FEE = 300n` into a `u8` one is `300 does not fit in u8`.
|
|
599
|
+
It is computed as a JavaScript bigint, without a width: `const R = -128n % -1n` is 0.
|
|
597
600
|
- Top-level `let` and `var` are refused: `top-level variables must be const literals`. A program has no global state
|
|
598
601
|
other than its accounts.
|
|
599
602
|
- A few names configure the compiler: `HEAP_SIZE_KIB` ([below](#memory-stack-and-heap)), `MAX_ACCOUNTS`
|
|
@@ -763,7 +766,9 @@ export function record(stats: Mut<Stats>, by: u64, change: i64): void {
|
|
|
763
766
|
u8; convert with u64(...) etc.` Comparisons (`<`, `<=`, `===`, …) need equal types too.
|
|
764
767
|
- **Every operation is checked.** `+ - * / % **` and their assignments (`+=` … `**=`) fail the instruction on
|
|
765
768
|
overflow (5100) or division by zero (5101); `**` with a negative exponent fails as well (JavaScript throws there).
|
|
766
|
-
Unlike JavaScript there are no silent wraps and no `Infinity`.
|
|
769
|
+
Unlike JavaScript there are no silent wraps and no `Infinity`. A signed type's minimum divided by -1 overflows, and
|
|
770
|
+
so does its remainder by -1 (`x % -1n` with an `i8` holding -128 fails with 5100, as Rust's checked `%` does, where
|
|
771
|
+
JavaScript gives 0); a typed constant computing it is a compile error ([constants](language-basics.md#constants)).
|
|
767
772
|
- **Bitwise operators.** `& | ^` work on equal types; `~` flips the bits within the type's width (`~1n` as a `u8` is
|
|
768
773
|
254). Both shifts fail (5100) when the amount is negative or not below the width (`x >> 64n` on a `u64`), and `<<`
|
|
769
774
|
also when bits would be lost; `>>` is arithmetic on signed types. Unlike JavaScript, where a bigint shift never
|
|
@@ -1013,8 +1018,16 @@ export function step(player: Mut<Player>, dx: u64): void {
|
|
|
1013
1018
|
order, back to back, with no padding.
|
|
1014
1019
|
- A struct literal names every field (`{ x, y: 2n }`); a missing or unknown field is an error. An object literal needs
|
|
1015
1020
|
a known struct type: a typed local (`const p: Point = { … }`), a field, a helper parameter, `emit<T>(…)`.
|
|
1016
|
-
- `a.home = b.home` copies the whole struct, as Rust and Anchor do; how `const` binds one is in
|
|
1017
|
-
|
|
1021
|
+
- `a.home = b.home` copies the whole struct, as Rust and Anchor do; how `const` binds one is in [copies and
|
|
1022
|
+
references](language-statements.md#copies-and-references). A copy between places reached through pointers (account
|
|
1023
|
+
data, a view, a helper's struct parameter) of 80 bytes or more is the memmove syscall (16 compute units up to 2,749
|
|
1024
|
+
bytes, one more per 250 bytes past that), as Rust's memcpy is; below, 8-byte loads and stores (26 units for 80
|
|
1025
|
+
bytes, 54 for 192). A copy into or out of a local of the function (a local copy, a helper's result, a struct literal
|
|
1026
|
+
built in a temporary) takes the syscall from 400 bytes, where clang stops unrolling the loads and stores (and about
|
|
1027
|
+
1 unit a byte is the loop's cost): below that the optimizer drops what nothing reads, which a call would prevent.
|
|
1028
|
+
The same holds wherever TypeSOL copies a whole value itself (Borsh fields, instruction arguments, a helper's copy of
|
|
1029
|
+
a struct argument, events), and a value it zeroes whole (`x.o = null` on an `Option<struct>`, a data-enum literal)
|
|
1030
|
+
takes the memset syscall from 192 bytes in account data and 600 in a local.
|
|
1018
1031
|
- A struct cannot contain itself.
|
|
1019
1032
|
|
|
1020
1033
|
### File-local structs
|
|
@@ -1432,7 +1445,8 @@ export function edit(shape: Mut<Shape>): void {
|
|
|
1432
1445
|
refused.
|
|
1433
1446
|
- **Evaluation order**: operands and arguments are read left to right, as in JavaScript, even when a later one changes
|
|
1434
1447
|
account data (`v.length + v.pop()`) or a local (`x + bump()` with a closure `bump` doing `x += 1n`, or a list
|
|
1435
|
-
callback writing it).
|
|
1448
|
+
callback writing it). Built-ins too: `log64(a.count, bump(a), 0n, 0n, 0n)` logs the count before the bump, and
|
|
1449
|
+
`require(a.count === n, codeOf(a))` tests the count before a helper computing the error code runs.
|
|
1436
1450
|
- **Ternaries** run only the chosen branch: `const fee = vip ? 0n : 30n`. Between accounts too:
|
|
1437
1451
|
`const source = ephemeral ? rest.get(5n) : reserve` picks a remaining account (`rest.get(i)`, a local or
|
|
1438
1452
|
`RemainingAccount` helper parameter bound to one) or an `AccountInfo` parameter, and the result goes wherever a
|
|
@@ -2139,18 +2153,21 @@ export function remove(owner: Mut<Signer>, log: HasOne<Mut<Log>, "owner">): void
|
|
|
2139
2153
|
}
|
|
2140
2154
|
```
|
|
2141
2155
|
|
|
2142
|
-
- `close(account, destination)` closes a program account: its lamports go to `destination` (another writable
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2156
|
+
- `close(account, destination)` closes a program account: its lamports go to `destination` (another writable account)
|
|
2157
|
+
and its data is zeroed (by the memset syscall when the account's type takes 64 bytes or more, by stores below). The
|
|
2158
|
+
account is not used after it in the function, except its `key` (compile errors, or 2040 at run time in a helper
|
|
2159
|
+
given one account twice). `CloseTo<A, "dest">` does the same when the instruction succeeds
|
|
2160
|
+
([constraints](#constraints)).
|
|
2146
2161
|
- Who may call them: `HasOne` above lets only the log's owner close it (the lamports of a closed account are value)
|
|
2147
2162
|
or resize it. Without that check anyone could pay to grow, or shrink, another user's account.
|
|
2148
2163
|
- `realloc(account, newSize, payer)` on a `Mut<Struct>`: growing charges the payer the extra rent (at most 10 KiB per
|
|
2149
|
-
instruction, 3016); shrinking keeps the lamports in the account; never below the struct.
|
|
2150
|
-
|
|
2164
|
+
instruction, 3016); shrinking keeps the lamports in the account; never below the struct (3016). For a `@layout borsh`
|
|
2165
|
+
struct that is its discriminator and smallest Borsh form (an empty `FixedString<64>` takes 4 bytes, not 68), the size
|
|
2166
|
+
its load accepts; the value written back when the instruction returns must still fit (3004). Refused on a struct
|
|
2167
|
+
with a growable `Vec` (its push / pop / clear size the account).
|
|
2151
2168
|
- `resizeAccount(account, newSize)` on a `Mut<AccountInfo>` of this program is Rust's `AccountInfo::resize`: the
|
|
2152
|
-
length only, new bytes zeroed
|
|
2153
|
-
(3016).
|
|
2169
|
+
length only, new bytes zeroed (64 or more by the memset syscall, as `realloc` zeroes them too), no rent moved (fund
|
|
2170
|
+
it first: `rentExempt(newSize)`), at most 10 KiB of growth (3016).
|
|
2154
2171
|
- An account grows at most 10 KiB per instruction, counted from its length when the instruction started (Solana's
|
|
2155
2172
|
limit): realloc again in the next instruction.
|
|
2156
2173
|
- `account.lamports` can be read on any account and written on a `Mut` one.
|
|
@@ -2213,7 +2230,8 @@ the body, in Anchor's order, and recorded in the IDL (`relations`, `pda`, `addre
|
|
|
2213
2230
|
among its types, not its accounts (an error named on such an `Owner` is not used: the load fails with 3007). Such a
|
|
2214
2231
|
struct may carry a shorter discriminator, `/** @discriminator 0x01 */` (1 to 8 bytes, as Anchor's
|
|
2215
2232
|
`discriminator = &[1]`; Solend's reserve), its fields then starting right after it; this program's own accounts
|
|
2216
|
-
keep 8.
|
|
2233
|
+
keep 8. A `@layout borsh` struct's Borsh bytes start there too, and the account must hold the discriminator and the
|
|
2234
|
+
struct's smallest Borsh form (3003).
|
|
2217
2235
|
- `Address<InstructionsSysvar, "Sysvar1nstructions1111111111111111111111111">` checks the address as Anchor's
|
|
2218
2236
|
`address = sysvar::instructions::ID` on an `UncheckedAccount` does (2012, with the constraints).
|
|
2219
2237
|
|
|
@@ -2246,7 +2264,9 @@ are compared too ([native programs](language-native.md#inout-places-that-may-be-
|
|
|
2246
2264
|
|
|
2247
2265
|
At most 32 accounts per instruction; more is refused with 5113. `export const MAX_ACCOUNTS = 128n` (up to 255; Anchor
|
|
2248
2266
|
takes what the runtime allows) raises it for programs that take many remaining accounts. The CPI scratch lists are
|
|
2249
|
-
then kept on the heap instead of the stack; programs that do not declare it compile exactly as before.
|
|
2267
|
+
then kept on the heap instead of the stack; programs that do not declare it compile exactly as before. 255 is also
|
|
2268
|
+
the runtime's limit: an instruction naming more accounts (repeats count) fails with MaxAccountsExceeded before any
|
|
2269
|
+
program runs.
|
|
2250
2270
|
|
|
2251
2271
|
## Optional accounts
|
|
2252
2272
|
|
|
@@ -3165,6 +3185,40 @@ Pubkeys, unit enums and arrays is read as its bytes (booleans and enums checked)
|
|
|
3165
3185
|
Vecs is declared `/** @layout borsh */` and Borsh-decoded. Bytes that are not exactly the struct fail with 5106. The
|
|
3166
3186
|
type argument is required.
|
|
3167
3187
|
|
|
3188
|
+
Return data of any length, checked by the program itself (Rust's `get_return_data()`, as a native program reads a
|
|
3189
|
+
reply of several records), is `getReturnData()`:
|
|
3190
|
+
|
|
3191
|
+
```ts
|
|
3192
|
+
import { getReturnData, instructionData, invoke, log, remainingAccounts, require, u8 } from "typesol";
|
|
3193
|
+
|
|
3194
|
+
export enum MatchError {
|
|
3195
|
+
/** @code 0 */
|
|
3196
|
+
NoReply = "NoReply",
|
|
3197
|
+
BadReply = "BadReply",
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
/** @fallback */
|
|
3201
|
+
export function entry(): void {
|
|
3202
|
+
const matcher = remainingAccounts().get(0n);
|
|
3203
|
+
const data = instructionData();
|
|
3204
|
+
const legs = data.readU64(0n);
|
|
3205
|
+
invoke(matcher, [], [u8(1n), legs]);
|
|
3206
|
+
const [from, reply] = getReturnData();
|
|
3207
|
+
// Rust's None: no return data (the runtime keeps no empty return data); `from` is then all zeros.
|
|
3208
|
+
require(reply.length > 0n, MatchError.NoReply);
|
|
3209
|
+
require(from === matcher.key && reply.length === legs * 64n, MatchError.BadReply);
|
|
3210
|
+
log(reply.readU64(8n));
|
|
3211
|
+
}
|
|
3212
|
+
```
|
|
3213
|
+
|
|
3214
|
+
- `from` is the program that set the return data (a Pubkey); `reply` its bytes, up to the runtime's 1,024, with the
|
|
3215
|
+
methods of instruction data (`length`, `get`, `readU8` … `readU128`, `readPubkey`, `slice`; 5104 past the end).
|
|
3216
|
+
- Nothing is checked and nothing fails: the program, the length and the contents are the caller's to check, with its
|
|
3217
|
+
own errors. It reads whatever the runtime holds: the last CPI's callee's return data, or what this instruction set
|
|
3218
|
+
with `setReturnData` after it.
|
|
3219
|
+
- Bound with `const [program, data] = …` where it is called (either name may be left out: `const [, data]`). The bytes
|
|
3220
|
+
are copied into 1 KiB of the calling function's stack frame.
|
|
3221
|
+
|
|
3168
3222
|
## invokeInstruction
|
|
3169
3223
|
|
|
3170
3224
|
A call decided at run time, such as one a multisig stored in account data, is `invokeInstruction` (Rust's
|
|
@@ -3773,6 +3827,16 @@ A native account whose parts start where its header says (Phoenix's market at by
|
|
|
3773
3827
|
after a helper that may close or resize one it is given: its bounds were checked against the old length, so it is a
|
|
3774
3828
|
compile error saying to take the view again.
|
|
3775
3829
|
|
|
3830
|
+
### Struct copies between views that overlap
|
|
3831
|
+
|
|
3832
|
+
Two views of one account at run-time offsets (`loadRawAt`, `loadRawMutAt`, an account passed twice under
|
|
3833
|
+
`NATIVE_ACCOUNT_WRITES`) can overlap, and `d.v = s.v` then copies between overlapping bytes. The destination ends with
|
|
3834
|
+
the source's old bytes, in either direction and at any size, as Rust's `copy_within` or a struct copied out and
|
|
3835
|
+
written back leaves it: below 80 bytes every byte is loaded before any is stored (a load and then a store per 8
|
|
3836
|
+
bytes), from 80 bytes the memmove syscall copies them. A copy through a local (`const c: T = s.v; d.v = c;`) and
|
|
3837
|
+
`copyData` give the same bytes
|
|
3838
|
+
([`test/language/bulk-copies.test.ts`](https://github.com/typesol-lang/typesol/blob/main/test/language/bulk-copies.test.ts)).
|
|
3839
|
+
|
|
3776
3840
|
## lib-sokoban's red-black tree
|
|
3777
3841
|
|
|
3778
3842
|
```ts
|
|
@@ -3926,9 +3990,19 @@ On remaining accounts and `AccountInfo` parameters:
|
|
|
3926
3990
|
the account's owner: check that it is this program's first (the runtime would fail the instruction after it returns,
|
|
3927
3991
|
having changed another program's account). The length does not change, so views made before stay valid and read the
|
|
3928
3992
|
zeros.
|
|
3929
|
-
- `
|
|
3930
|
-
|
|
3931
|
-
|
|
3993
|
+
- `copyData(account, from, to, length)` copies `length` bytes of the data from offset `from` to offset `to`, as a
|
|
3994
|
+
native program's `data.copy_within(from..from + length, to)` or a struct copied out and written back at another
|
|
3995
|
+
offset (a memcpy in Rust): the memmove syscall from 32 bytes, about constant compute units whatever the length (a
|
|
3996
|
+
whole-struct assignment `a.p = b.p` between views uses it too, from 80 bytes: [overlapping
|
|
3997
|
+
views](#struct-copies-between-views-that-overlap)). The ranges may overlap. A range past the end of the data fails
|
|
3998
|
+
with 3003 and copies nothing; without `NATIVE_ACCOUNT_WRITES` the account must be writable (3006). Like `zeroData`
|
|
3999
|
+
it does not check the owner, and views made before stay valid and read the copied bytes (Percolator v16's InitMarket
|
|
4000
|
+
copies asset 0's 424-byte oracle profile into every slot of the market this way;
|
|
4001
|
+
[`test/language/native-copy-data.test.ts`](https://github.com/typesol-lang/typesol/blob/main/test/language/native-copy-data.test.ts)).
|
|
4002
|
+
- `resizeAccount(account, size)` also takes a remaining account (`realloc(size, true)`: new bytes zeroed, 64 or more
|
|
4003
|
+
by the memset syscall as Rust's realloc zeroes them, fewer by stores; at most 10 KiB past the size it had when the
|
|
4004
|
+
instruction started, 3016). That size is the one the entrypoint records in the account's record, as solana_program
|
|
4005
|
+
1.14's does, only in programs that resize a remaining account.
|
|
3932
4006
|
- A view of the account made before either (`loadRawMutAt`, `rawArrayMutAt`, `rbTreeMutAt`, a node or a struct read
|
|
3933
4007
|
through one) is a compile error to use after it: its bounds were checked against the old length, so take the view
|
|
3934
4008
|
again.
|
|
@@ -3938,6 +4012,7 @@ On remaining accounts and `AccountInfo` parameters:
|
|
|
3938
4012
|
(`ReadonlyLamportChange`, `ExternalAccountLamportSpend`, `UnbalancedInstruction`, `ModifiedProgramId`), and plain
|
|
3939
4013
|
`AccountInfo` parameters are enough.
|
|
3940
4014
|
|
|
4015
|
+
|
|
3941
4016
|
## Errors and panics as the original reports them
|
|
3942
4017
|
|
|
3943
4018
|
```ts
|
|
@@ -3981,6 +4056,30 @@ export function entry(): void {
|
|
|
3981
4056
|
location)` log one line, `panicked at <location>:` and the message after a newline, and then abort ("SBF program
|
|
3982
4057
|
panicked"), as that panic handler does: `panicked at src/wide_math.rs:1554:30:\nmul_div_floor_u128: a*b overflow`.
|
|
3983
4058
|
As under "solana-1.14", a message is required and `PANIC_ON_OVERFLOW`'s panics abort.
|
|
4059
|
+
- **Panics as pinocchio's entrypoint writes them.** `export const PANIC_STYLE = "pinocchio"` (a program built with
|
|
4060
|
+
pinocchio's `entrypoint!`, whose `default_panic_handler!` hook runs under std: Percolator v16) makes `panic(message,
|
|
4061
|
+
location)` log two lines, the location's file exactly as Rust records it and then `** PANICKED **`, and abort ("SBF
|
|
4062
|
+
program panicked"):
|
|
4063
|
+
|
|
4064
|
+
```
|
|
4065
|
+
Program log: src/v16.rs
|
|
4066
|
+
Program log: ** PANICKED **
|
|
4067
|
+
Program <id> failed: SBF program panicked
|
|
4068
|
+
```
|
|
4069
|
+
|
|
4070
|
+
- The file is `Location::file()` verbatim: the path rustc was given, which cargo makes relative to the crate
|
|
4071
|
+
(`src/v16.rs`, `src/account_info.rs` inside solana-program) and which is the toolchain's absolute path for a panic
|
|
4072
|
+
inside the standard library that is not reported at its caller (Percolator v16's binary holds
|
|
4073
|
+
`/home/runner/work/platform-tools/platform-tools/out/rust/library/alloc/src/raw_vec/mod.rs`). Give it as the
|
|
4074
|
+
location, alone or with its line and column (`"src/v16.rs:812:9"`, logged as `src/v16.rs`), so the port's source
|
|
4075
|
+
keeps the original's place. Index, `unwrap`, `RefCell::borrow_mut` and `Vec::with_capacity`'s capacity panics are
|
|
4076
|
+
reported at their caller (`#[track_caller]`), so their file is the caller's.
|
|
4077
|
+
- No message is logged (the hook ignores it): the message may be `null` or a note for the reader. Without a
|
|
4078
|
+
location this source file's name is logged.
|
|
4079
|
+
- `panicsAt(location, expression)` logs its location's file the same way. `PANIC_ON_OVERFLOW` is refused with this
|
|
4080
|
+
style: its panics have no file; wrap the arithmetic in `panicsAt`.
|
|
4081
|
+
- Every panic site calls one shared helper (the two log calls and the abort), so a port with many panic sites stays
|
|
4082
|
+
small.
|
|
3984
4083
|
- **Overflow panics with Rust's message and location.** `panicsAt("src/quantities.rs:233:1", a + b)` is `a + b` whose
|
|
3985
4084
|
checked arithmetic panics as Rust's overflow checks do at that location ("attempt to add with overflow"; also
|
|
3986
4085
|
"attempt to subtract / multiply with overflow", "attempt to divide by zero", "attempt to calculate the remainder with
|
|
@@ -3996,7 +4095,8 @@ export function entry(): void {
|
|
|
3996
4095
|
quantities.rs, wherever the addition is written): give the port a helper, `function addQuoteLots(a: u64, b: u64):
|
|
3997
4096
|
u64 { return panicsAt(QUOTE_LOTS_ADD, a + b); }`.
|
|
3998
4097
|
- The bits `<<` loses, `**`, `mulDiv` / `mulDivCeil`, casts and u256 arithmetic keep TypeSOL's failures (Rust checks
|
|
3999
|
-
them differently, or with other messages)
|
|
4098
|
+
them differently, or with other messages): `panicsAt(LOC, a ** 2n)` fails with 5100 when the square overflows,
|
|
4099
|
+
while an operator in `**`'s operands (`(a + b) ** 2n`) still panics at the location.
|
|
4000
4100
|
- [`test/language/rust-panics.test.ts`](https://github.com/typesol-lang/typesol/blob/main/test/language/rust-panics.test.ts) checks the lines against the Phoenix binary's own panics.
|
|
4001
4101
|
|
|
4002
4102
|
## Log lines as the original writes them
|
|
@@ -4076,7 +4176,7 @@ void instruction (Phoenix's Borsh `Vec<FIFOOrderId>` of the orders that rested,
|
|
|
4076
4176
|
|
|
4077
4177
|
<!-- Generated by scripts/language-builtins.ts from lib/typesol.d.ts; do not edit by hand. -->
|
|
4078
4178
|
|
|
4079
|
-
Every name `"typesol"` exports (
|
|
4179
|
+
Every name `"typesol"` exports (222 names, 235 declarations), grouped, with its declaration and the first sentence of its doc
|
|
4080
4180
|
comment in `lib/typesol.d.ts`. Each group links to the part of the [language guide](language.md) that explains it;
|
|
4081
4181
|
your editor shows the full doc comment on hover. Methods of account and program types (`systemProgram.transfer`,
|
|
4082
4182
|
`acct.create`, …) are described with their types in the guide.
|
|
@@ -4214,7 +4314,7 @@ Explained in [Accounts: Closing and resizing](language-accounts.md#closing-and-r
|
|
|
4214
4314
|
| --- | --- | --- |
|
|
4215
4315
|
| `close` | `function close(account: AccountMeta, destination: AccountMeta): void` | Close a program-owned account: move all lamports to `destination` and wipe it. |
|
|
4216
4316
|
| `realloc` | `function realloc(account: AccountMeta, newSize: u64, payer: Mut<Signer>): void` | Resize an account of this program (Anchor `realloc`, struct accounts only): growing charges `payer` the extra rent (never the account's own lamports, which may be deposits); shrinking keeps every lamport in the account — move freed rent out yourself if your program allows it. |
|
|
4217
|
-
| `resizeAccount` | `function resizeAccount(account: RemainingAccount \| Mut<AccountInfo>, newSize: u64): void` | Resize a `Mut<AccountInfo>` or a remaining account of this program to `newSize` bytes (Rust's `AccountInfo::resize` / `realloc(newSize, true)`): the data length only, the new bytes zeroed. |
|
|
4317
|
+
| `resizeAccount` | `function resizeAccount(account: RemainingAccount \| Mut<AccountInfo>, newSize: u64): void` | Resize a `Mut<AccountInfo>` or a remaining account of this program to `newSize` bytes (Rust's `AccountInfo::resize` / `realloc(newSize, true)`): the data length only, the new bytes zeroed (64 or more by the memset syscall). |
|
|
4218
4318
|
|
|
4219
4319
|
## Accounts created by hand
|
|
4220
4320
|
|
|
@@ -4294,6 +4394,7 @@ Explained in [Calling other programs: invoke](language-cpi.md#invoke).
|
|
|
4294
4394
|
| `sighash` | `function sighash(name: string): Bytes` | The 8-byte Anchor instruction discriminator for `name` (sha256("global:<snake_case name>")[..8]). |
|
|
4295
4395
|
| `hex` | `function hex(literal: string): Bytes` | Bytes from a hex string literal, e.g. hex("0a0b"). |
|
|
4296
4396
|
| `returnData` | `function returnData<T>(program: AccountMeta): T` | Read the return data the last invoke() left behind, checking it came from `program` and has exactly the size of T: `const n = returnData<u64>(counterProgram)`. |
|
|
4397
|
+
| `getReturnData` | `function getReturnData(): [program: Pubkey, data: InstructionBytes]` | The return data as the runtime holds it, of any length and from any program (Rust's `get_return_data()`), for a port that checks it itself: `const [program, data] = getReturnData()`. |
|
|
4297
4398
|
| `invokeInstruction` | `function invokeInstruction(programId: Pubkey, accounts: IndexedList<InstructionAccountMeta>, data: IndexedList<u8>, infos: RemainingAccounts \| RemainingSlice, signerSeeds?: Seed[] \| SignerSeeds \| (Seed[] \| SignerSeeds)[]): void` | A CPI decided at run time, e.g. one stored in account data (Rust's `invoke_signed(&Instruction { program_id, accounts, data }, infos, seeds)`). |
|
|
4298
4399
|
| `InstructionAccountMeta` | `interface InstructionAccountMeta` | One account of an instruction built at run time (Rust's `AccountMeta`): any struct with these three fields. |
|
|
4299
4400
|
| `programAt` | `function programAt<P>(account: RemainingAccount \| AccountInfo): P` | A remaining account (or an AccountInfo parameter) as a typed program: `const stake = programAt<StakeProgram>(rest.get(12n))`, then `stake.split(…)`, `token.mintTo(…)`, `system.transfer(…)` as on a declared program parameter, and passed to helpers that take that program type. |
|
|
@@ -4478,6 +4579,7 @@ Explained in [Porting a native program (advanced)](language-native.md).
|
|
|
4478
4579
|
| `closeRaw` | `function closeRaw(account: RemainingAccount \| Mut<AccountInfo>, receiver: RemainingAccount \| Mut<AccountInfo>): void` | Close an account of this program as a native program does it by hand (Phoenix's Tombstone), in this order: `receiver.lamports += account.lamports`, `account.lamports = 0`, the owner set to the System Program, the data length set to 0 (`realloc(0, false)`: the bytes are not zeroed, the runtime drops them with the length). |
|
|
4479
4580
|
| `assignOwner` | `function assignOwner(account: RemainingAccount \| Mut<AccountInfo>, owner: Pubkey): void` | Set an account's owner in place (Rust's `AccountInfo::assign`). |
|
|
4480
4581
|
| `zeroData` | `function zeroData(account: RemainingAccount \| Mut<AccountInfo>, offset: u64, length: u64): void` | Zero `length` bytes of an account's data from `offset`, as a native program's `for b in data[offset..offset + length].iter_mut() { *b = 0; }` (a memset): the memset syscall, about constant compute units whatever the length. |
|
|
4582
|
+
| `copyData` | `function copyData(account: RemainingAccount \| Mut<AccountInfo>, from: u64, to: u64, length: u64): void` | Copy `length` bytes of an account's data from offset `from` to offset `to`, as a native program's `data.copy_within(from..from + length, to)` (or a struct copied out of the account and written back at another offset): the memmove syscall, about constant compute units whatever the length; the ranges may overlap. |
|
|
4481
4583
|
| `setReturnData` | `function setReturnData(bytes: IndexedList<u8>): void` | Set this instruction's return data to `bytes` as they are (Rust's `set_return_data(&bytes)`): a list of u8 such as a local `FixedVec<u8, N>`, a Vec or FixedVec in account data, or the instruction data or a slice of it. |
|
|
4482
4584
|
| `panic` | `function panic(message?: string \| null, location?: string): never` | Stop the program as a Rust `panic!` / `unwrap()` on `None` / `unreachable!()` does: the message is logged and the instruction fails with ProgramFailedToComplete (no error code). |
|
|
4483
4585
|
| `panicsAt` | `function panicsAt<T>(location: string, value: T): T` | `value`, with its checked arithmetic panicking as Rust's overflow checks do at `location` ("file:line:column", where the original's expression is): `panicsAt("src/quantities.rs:233:1", a + b)` logs "attempt to add with overflow" there (also "attempt to subtract / multiply with overflow", "attempt to divide by zero", "attempt to calculate the remainder with a divisor of zero", "attempt to negate with overflow", "attempt to divide with overflow", "attempt to shift left / right with overflow" for a shift amount past the width), as `panic` logs (see `PANIC_STYLE`), instead of failing with 5100 / 5101. |
|
|
@@ -5021,9 +5123,9 @@ error. Exit codes: **0** success, **1** failure (compile errors, failed deploy,
|
|
|
5021
5123
|
| Command | What it does |
|
|
5022
5124
|
| --- | --- |
|
|
5023
5125
|
| `typesol init [<dir>] [--name <program>] [--template counter\|vault\|escrow] [--no-agent-files]` | Create a project ([below](#typesol-init)). |
|
|
5024
|
-
| `typesol new <program> [--template counter\|vault\|escrow]` | In a project: add a program, `programs/<program>.ts` and `tests/<program>.test.ts` from the template, and its entry in `typesol.json`. Refuses to overwrite files or reuse a name. |
|
|
5126
|
+
| `typesol new <program> [--template counter\|vault\|escrow]` | In a project: add a program, `programs/<program>.ts` and `tests/<program>.test.ts` from the template, and its entry in `typesol.json`. Refuses to overwrite files or reuse a name, and to write through a symbolic link inside the project (a linked `programs/` or `tests/`, or a link where a new file goes). |
|
|
5025
5127
|
| `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools (and a `toolchain` row: the tested ones, or untested with both versions), the Solana CLI, Docker (optional: only `--docker` builds need it; it says when they run emulated), its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. The last line says what is ready (building and testing, or also deploying) and what the warnings concern. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
|
|
5026
|
-
| `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--toolchain-strict] [--docker [--typesol-version <v>] [--release-record <file>]] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json` (the TypeSOL, TypeScript, clang and platform-tools versions, the host, the SBPF version, each source's sha256 and the binary's). With platform-tools other than the tested ones it warns once; `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) refuses them. The first build creates `<out>/deploy/<name>-keypair.json` and records the address in `typesol.json`; later builds refuse a different keypair. Without the keypair (a fresh clone, CI) it builds at the recorded address and says so; only `deploy` needs the keypair. `--docker` builds in the pinned container instead ([below](#build---docker-and-verify---docker)). |
|
|
5128
|
+
| `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--toolchain-strict] [--docker [--typesol-version <v>] [--release-record <file>]] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json` (the TypeSOL, TypeScript, clang and platform-tools versions, the host, the SBPF version, each source's sha256 and the binary's). Each source's sha256 is that of the bytes the compiler read, and the build fails without a manifest when a source or the runtime changes while it runs (an editor saving a file mid-build), so a manifest never pairs a binary with sources that did not make it. With platform-tools other than the tested ones it warns once; `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) refuses them. The first build creates `<out>/deploy/<name>-keypair.json` and records the address in `typesol.json`; later builds refuse a different keypair. First builds may run at once (several programs, or several processes): the keypair is created exclusively (a process that loses the race uses the winner's key) and `typesol.json` is updated one process at a time and replaced whole, so each address is kept. Without the keypair (a fresh clone, CI) it builds at the recorded address and says so; only `deploy` needs the keypair. `--docker` builds in the pinned container instead ([below](#build---docker-and-verify---docker)). |
|
|
5027
5129
|
| `typesol build <file.ts> [--out <dir>] [--program-id <keypair.json>] [--sbpf …] [--profile] [--toolchain-strict] [--docker …] [--quiet]` | Outside a project (or a file that is not one of its programs): build that file. Its keypair is `--program-id`, which must exist, or `<out>/<name>-keypair.json`, created on the first build. A project program's `.ts` builds as that program. |
|
|
5028
5130
|
| `typesol check [<program>… \| <file.ts>] [--json] [--stdin \| --files]` | Type-check and validate without building. In a project, no argument checks every program (or those named) and exits 1 if any has errors. `--json` prints `{ ok, diagnostics: [{ file, line, column, message }] }`, always (a missing file or unreadable `--files` input is a diagnostic too, exit 1 or 2); `--stdin` checks the text given on stdin as that file (its imports come from disk); `--files` reads `{ "files": { "<absolute path>": "<text>", … } }` from stdin and checks with those texts instead of the disk (an editor's unsaved buffers). |
|
|
5029
5131
|
| `typesol clone [<address>…] [--url <rpc>] [--config <cli config>] [--out <dir>]` | Copy cluster accounts and programs for the tests (Anchor's `[test.validator.clone]`): each account to `<address>.json` (lamports, owner, data), each program to `<address>.so` (its ELF, from the ProgramData account for upgradeable programs), in `tests/accounts` (`"accounts"` in `typesol.json`) or `--out`. Without addresses it clones the project's `"clone"` list. `testProgram` loads that directory into its LiteSVM; commit it so the tests run offline. |
|
|
@@ -5061,7 +5163,8 @@ process on stderr. `TYPESOL_TOOLCHAIN=strict` makes it an error everywhere, `war
|
|
|
5061
5163
|
`<name>` must be snake_case; by default it is derived from `<dir>` (`my-app` → `my_app`). The template picks the
|
|
5062
5164
|
program and its test: `counter` (default, a PDA counter per user), `vault` (SOL at a PDA: deposit, withdraw above
|
|
5063
5165
|
rent, close) or `escrow` (SPL tokens: make, take, refund, the offer PDA signing for its vault). `init` refuses to
|
|
5064
|
-
overwrite files
|
|
5166
|
+
overwrite files, and to write through a symbolic link inside `<dir>` (a linked `.cursor/`, say, whose files would
|
|
5167
|
+
land wherever it points; `<dir>` itself may be a link). It warns, with the install commands, when the platform-tools that building needs are missing, and
|
|
5065
5168
|
says whether the Agave CLI is missing or only its platform-tools (on Linux arm64, where there is no Agave CLI, the
|
|
5066
5169
|
commands that set up the platform-tools' `linux-aarch64` package).
|
|
5067
5170
|
|
|
@@ -6039,12 +6142,13 @@ exposed to them.
|
|
|
6039
6142
|
The compiler and runtime have had internal security reviews, the latest of 0.44.0 (above); its findings are fixed in
|
|
6040
6143
|
0.44.1. It was an internal review, not an independent audit; it covered the token, Token-2022, Metaplex and Stake
|
|
6041
6144
|
wrappers, the oracles and SBPF v1/v2 builds of the examples that the review of 0.43.0 left out, but not the Metaplex
|
|
6042
|
-
wrappers for unusual argument shapes beyond reading them, the large ports on SBPF v1/v2, or Windows. 0.45.0 to 0.
|
|
6145
|
+
wrappers for unusual argument shapes beyond reading them, the large ports on SBPF v1/v2, or Windows. 0.45.0 to 0.50.0
|
|
6043
6146
|
have had no security review. They add, among others, `runtime/typesol_builtins.c` (the
|
|
6044
6147
|
compiler builtins as TypeSOL's own C, 0.45.0), `transferCheckedWithHook`, `EVENT_AUTHORITY_CHECK` and the reads of
|
|
6045
|
-
processed sibling instructions (0.48.0),
|
|
6148
|
+
processed sibling instructions (0.48.0), `zeroData`, `log64`,
|
|
6046
6149
|
`PANIC_STYLE = "solana-1.18"`, `executable` on remaining accounts and lamport writes on remaining accounts under
|
|
6047
|
-
`NATIVE_ACCOUNT_WRITES` (0.49.0)
|
|
6150
|
+
`NATIVE_ACCOUNT_WRITES` (0.49.0), and `copyData`, `getReturnData()`, `PANIC_STYLE = "pinocchio"` and whole values
|
|
6151
|
+
copied and zeroed by the memory syscalls (0.50.0). There has been no external audit: see [audit.md](audit.md).
|
|
6048
6152
|
|
|
6049
6153
|
<!-- docs/ai.md -->
|
|
6050
6154
|
|
|
@@ -6179,10 +6283,11 @@ arm64 has no Agave CLI, so there the package is set up by hand with `TYPESOL_SBF
|
|
|
6179
6283
|
[troubleshooting.md](troubleshooting.md#linux-arm64-the-agave-installer-fails-with-a-404)): for
|
|
6180
6284
|
SBPF v0 (the default), the 76 programs then in the sources (`scripts/release-manifest.ts`, every program under
|
|
6181
6285
|
`examples/` and `showcase/`); for SBPF v1 and v2, the 14 programs of `test/golden/binaries.json` (counter, vault,
|
|
6182
|
-
escrow, multisig and the 10 below). Programs added since were not measured on the three hosts, and
|
|
6183
|
-
divide 128-bit and wider integers, the Meteora DBC port (0.48.0; u128 and u256 division)
|
|
6184
|
-
(0.49.0; U256 and U512), are not in `test/golden/binaries.json`, so CI's
|
|
6185
|
-
(adding them needs the file regenerated in the `--docker` reference
|
|
6286
|
+
escrow, multisig and the 10 below). Programs added since were not measured on the three hosts, and three of them that
|
|
6287
|
+
divide 128-bit and wider integers, the Meteora DBC port (0.48.0; u128 and u256 division), the Percolator port
|
|
6288
|
+
(0.49.0; U256 and U512) and the Percolator v16 port (0.50.0; u256), are not in `test/golden/binaries.json`, so CI's
|
|
6289
|
+
cross-host check does not build them yet (adding them needs the file regenerated in the `--docker` reference
|
|
6290
|
+
environment).
|
|
6186
6291
|
|
|
6187
6292
|
| What | Same on the three hosts? |
|
|
6188
6293
|
| --- | --- |
|
package/package.json
CHANGED