@typesol/cli 0.48.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 +556 -1
- package/NOTICE +17 -1
- package/README.md +122 -43
- package/SECURITY.md +6 -0
- package/dist/compiler/analyze.d.ts +2 -0
- package/dist/compiler/analyze.js +7 -1
- package/dist/compiler/emit/base.d.ts +7 -4
- package/dist/compiler/emit/base.js +17 -5
- package/dist/compiler/emit/borsh.js +8 -8
- package/dist/compiler/emit/calls.d.ts +6 -0
- package/dist/compiler/emit/calls.js +110 -11
- 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 +15 -1
- package/dist/compiler/emit/function.js +12 -8
- package/dist/compiler/emit/program.js +10 -4
- 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 +20 -13
- package/dist/compiler/emit/views.js +1 -1
- package/dist/compiler/hints.js +3 -0
- 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.49.0.lock.json +1206 -0
- package/docker/deps/0.50.0.lock.json +1206 -0
- package/docs/architecture.md +3 -3
- package/docs/audit.md +33 -16
- package/docs/case-study-escrow.md +7 -5
- package/docs/case-study-jito-mev.md +14 -14
- package/docs/case-study-marginfi.md +142 -129
- package/docs/case-study-multisig.md +18 -5
- package/docs/case-study-raydium-amm.md +2 -1
- package/docs/case-study-raydium-clmm.md +44 -28
- package/docs/case-study-raydium-cp-swap.md +18 -18
- package/docs/case-study-spl-stake-pool.md +4 -3
- package/docs/cli.md +4 -3
- package/docs/language-accounts.md +21 -16
- package/docs/language-basics.md +4 -1
- package/docs/language-builtins.md +6 -2
- package/docs/language-cpi.md +34 -0
- package/docs/language-errors-events.md +1 -1
- package/docs/language-native.md +73 -7
- package/docs/language-statements.md +5 -3
- package/docs/language-types.md +13 -3
- package/docs/language.md +2 -2
- package/docs/mainnet.md +1 -1
- package/docs/runtime.md +25 -1
- package/docs/security-model.md +12 -4
- package/docs/stability.md +10 -4
- package/docs/testing.md +22 -6
- package/docs/troubleshooting.md +1 -1
- package/lib/typesol.d.ts +43 -3
- package/llms-full.txt +190 -51
- package/llms.txt +2 -1
- package/package.json +3 -3
- package/releases/0.48.0.json +847 -0
- package/releases/0.49.0.json +857 -0
- package/runtime/typesol_builtins.c +47 -2
- package/runtime/typesol_rt.h +131 -4
package/llms-full.txt
CHANGED
|
@@ -108,9 +108,9 @@ the same.
|
|
|
108
108
|
`typesol port` starts from your program's IDL; [docs/case-study-escrow.md](docs/case-study-escrow.md) follows one
|
|
109
109
|
program through the port.
|
|
110
110
|
- Real programs checked against their mainnet binaries: [Showcase](https://github.com/typesol-lang/typesol#showcase-ports-checked-against-mainnet), with a
|
|
111
|
-
case study each (Marginfi v2 in full: all 124 instructions,
|
|
112
|
-
order book, the same on 3,575 transactions down to its event bytes
|
|
113
|
-
lines).
|
|
111
|
+
case study each (Marginfi v2 in full: all 124 instructions, 2,321 transactions with the same outcomes, events and
|
|
112
|
+
account bytes; Phoenix v1, a native order book, the same on 3,575 transactions down to its event bytes and log lines;
|
|
113
|
+
Raydium AMM v4, a native program, down to its log lines).
|
|
114
114
|
- To mainnet (wallet, cost, deploy, IDL, verification): [docs/mainnet.md](docs/mainnet.md).
|
|
115
115
|
- With an AI coding agent: [docs/ai.md](docs/ai.md) (agent rules, [llms.txt](https://typesol.com/llms.txt), the MCP server).
|
|
116
116
|
|
|
@@ -177,9 +177,9 @@ The error codes are in [errors.md](errors.md); what a compiled program checks fo
|
|
|
177
177
|
- `?.` and `!` on anything but optional accounts, Options and a `find` on struct elements.
|
|
178
178
|
- Functions stored in a struct, chosen from a list by index, or returned from an instruction.
|
|
179
179
|
- A fused `map` to strings: store it, annotated.
|
|
180
|
-
- Floating point (by design).
|
|
181
180
|
|
|
182
|
-
They are rejected at compile time rather than half-supported.
|
|
181
|
+
They are rejected at compile time rather than half-supported. Floating-point arithmetic is not planned at all, by
|
|
182
|
+
design: an `f64` is carried only as its bits, in accounts and events ([f64](language-types.md#f64)).
|
|
183
183
|
|
|
184
184
|
## Index of the former sections
|
|
185
185
|
|
|
@@ -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
|
|
@@ -1553,7 +1567,7 @@ members`). A `switch` on a string is refused (`switch works on integers and enum
|
|
|
1553
1567
|
## Destructuring
|
|
1554
1568
|
|
|
1555
1569
|
```ts
|
|
1556
|
-
import { type Account, type Mut, type Pubkey, type u64 } from "typesol";
|
|
1570
|
+
import { type Account, type Mut, type Pubkey, type Signer, type u64, require } from "typesol";
|
|
1557
1571
|
|
|
1558
1572
|
export interface Point {
|
|
1559
1573
|
x: u64;
|
|
@@ -1566,7 +1580,8 @@ export interface Player {
|
|
|
1566
1580
|
score: u64;
|
|
1567
1581
|
}
|
|
1568
1582
|
|
|
1569
|
-
export function read(player: Account<Player>, out: Mut<Player>): void {
|
|
1583
|
+
export function read(signer: Signer, player: Account<Player>, out: Mut<Player>): void {
|
|
1584
|
+
require(out.owner === signer.key, "only the owner of out can overwrite it");
|
|
1570
1585
|
const { owner, pos: p } = player;
|
|
1571
1586
|
let { score } = player;
|
|
1572
1587
|
score += p.x;
|
|
@@ -2129,8 +2144,8 @@ export interface Log {
|
|
|
2129
2144
|
entries: u64;
|
|
2130
2145
|
}
|
|
2131
2146
|
|
|
2132
|
-
export function grow(
|
|
2133
|
-
realloc(log, size,
|
|
2147
|
+
export function grow(owner: Mut<Signer>, log: HasOne<Mut<Log>, "owner">, systemProgram: SystemProgram, size: u64): void {
|
|
2148
|
+
realloc(log, size, owner);
|
|
2134
2149
|
}
|
|
2135
2150
|
|
|
2136
2151
|
export function remove(owner: Mut<Signer>, log: HasOne<Mut<Log>, "owner">): void {
|
|
@@ -2138,19 +2153,21 @@ export function remove(owner: Mut<Signer>, log: HasOne<Mut<Log>, "owner">): void
|
|
|
2138
2153
|
}
|
|
2139
2154
|
```
|
|
2140
2155
|
|
|
2141
|
-
- `close(account, destination)` closes a program account: its lamports go to `destination` (another writable
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
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)).
|
|
2161
|
+
- Who may call them: `HasOne` above lets only the log's owner close it (the lamports of a closed account are value)
|
|
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
|
|
|
@@ -2339,7 +2359,7 @@ export function count(tally: Mut<Tally>): void {
|
|
|
2339
2359
|
`remainingAccounts()` gives the accounts passed after the declared ones, in order.
|
|
2340
2360
|
|
|
2341
2361
|
- `.length`, `.get(i)` (5104 past the end) → `key`, `owner`, `lamports` (writes check writability, 3006), `isSigner`,
|
|
2342
|
-
`isWritable`, the data length and data.
|
|
2362
|
+
`isWritable`, `executable`, the data length and data.
|
|
2343
2363
|
- `loadAccount<T>(acct)` / `loadAccountMut<T>(acct)` give checked struct views (owner, discriminator and size, as
|
|
2344
2364
|
`Account<T>` / `Mut<T>`), also of an `AccountInfo` parameter (Anchor's `AccountLoader::try_from` on an
|
|
2345
2365
|
`UncheckedAccount`).
|
|
@@ -2713,7 +2733,7 @@ it); a zero code fails with 5100.
|
|
|
2713
2733
|
- `require(cond, "message")` errors come after the highest code.
|
|
2714
2734
|
|
|
2715
2735
|
When the program fails, the logs show the error and the source line, `Error 6000 NotOwner (vault.ts:21)`, and
|
|
2716
|
-
TypeSOL's own failures say what failed, `TypeSOL: arithmetic overflow (vault.ts:
|
|
2736
|
+
TypeSOL's own failures say what failed, `TypeSOL: arithmetic overflow (vault.ts:44)`. Native ports can change or drop
|
|
2717
2737
|
that line ([log lines](language-native.md#log-lines-as-the-original-writes-them)).
|
|
2718
2738
|
|
|
2719
2739
|
## log
|
|
@@ -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
|
|
@@ -3872,7 +3936,7 @@ direct mapping), one that was only read (or written with the bytes it held) is f
|
|
|
3872
3936
|
`AccountInfo`s over one buffer.
|
|
3873
3937
|
|
|
3874
3938
|
- **By default** `loadRawMut` and `storeBorsh` check writability up front (3006), `loadRawMut` claims the account once
|
|
3875
|
-
and `storeBorsh` refuses an account passed more than once (2040, as a write to a remaining account's lamports). So a
|
|
3939
|
+
and `storeBorsh` refuses an account passed more than once (2040, as a write to a remaining account's lamports does without the flag). So a
|
|
3876
3940
|
port fails where the original succeeds (a read-only validator list that is only read; the list passed again as a
|
|
3877
3941
|
stake account, which the original skips by its address checks).
|
|
3878
3942
|
- **With the flag**, `loadRawMut`, `storeBorsh` and the BigVec writes through a `loadRawMut` view skip both, and both
|
|
@@ -3886,8 +3950,14 @@ direct mapping), one that was only read (or written with the bytes it held) is f
|
|
|
3886
3950
|
`loadRaw` of an account also loaded with `loadRawMut` (or written with `storeBorsh`) reads what was written, BigVec
|
|
3887
3951
|
pushes included. The flag only lifts the up-front checks (a second `loadRawMut` of one account, at the same position
|
|
3888
3952
|
or another, is 2040 without it).
|
|
3889
|
-
-
|
|
3890
|
-
|
|
3953
|
+
- A write to a remaining account's `.lamports` (`a.lamports = v`, `+=`, `-=`) is `**a.lamports.borrow_mut() = v`
|
|
3954
|
+
under the flag: no writability check (3006) and no refusal of an account passed more than once (2040). An account
|
|
3955
|
+
passed twice is one record, as Rust's two `AccountInfo`s share one `RefCell`, so a write through either position is
|
|
3956
|
+
read through the other; the runtime refuses a read-only account's change, or lamports created or destroyed, when the
|
|
3957
|
+
instruction ends (`ReadonlyLamportChange`, `UnbalancedInstruction`). Percolator's CloseSlab moves the slab's
|
|
3958
|
+
lamports to the admin this way while the admin (or the slab) is also named in an unused position.
|
|
3959
|
+
- `loadAccountMut`, CPI account metas and the checks of `Mut<…>` parameters stay as they are, and programs without the
|
|
3960
|
+
flag compile exactly as before.
|
|
3891
3961
|
|
|
3892
3962
|
### Inout places that may be one account
|
|
3893
3963
|
|
|
@@ -3913,9 +3983,26 @@ On remaining accounts and `AccountInfo` parameters:
|
|
|
3913
3983
|
lamports in the receiver; [`test/language/native-close.test.ts`](https://github.com/typesol-lang/typesol/blob/main/test/language/native-close.test.ts) compares it with Phoenix's own Tombstone).
|
|
3914
3984
|
- `assignOwner(account, owner)` is `AccountInfo::assign` (the runtime accepts it for a writable account of this program
|
|
3915
3985
|
whose data is empty or zeroed).
|
|
3916
|
-
- `
|
|
3917
|
-
|
|
3918
|
-
|
|
3986
|
+
- `zeroData(account, offset, length)` zeroes that range of the data, as a native program's `for b in
|
|
3987
|
+
data.iter_mut() { *b = 0; }`, which compiles to a memset: the memset syscall, about constant compute units whatever
|
|
3988
|
+
the length (Percolator clears its 1.5 MB slab this way at InitMarket and CloseSlab). Past the end of the data fails
|
|
3989
|
+
with 3003 and writes nothing; without `NATIVE_ACCOUNT_WRITES` the account must be writable (3006). It does not check
|
|
3990
|
+
the account's owner: check that it is this program's first (the runtime would fail the instruction after it returns,
|
|
3991
|
+
having changed another program's account). The length does not change, so views made before stay valid and read the
|
|
3992
|
+
zeros.
|
|
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.
|
|
3919
4006
|
- A view of the account made before either (`loadRawMutAt`, `rawArrayMutAt`, `rbTreeMutAt`, a node or a struct read
|
|
3920
4007
|
through one) is a compile error to use after it: its bounds were checked against the old length, so take the view
|
|
3921
4008
|
again.
|
|
@@ -3925,6 +4012,7 @@ On remaining accounts and `AccountInfo` parameters:
|
|
|
3925
4012
|
(`ReadonlyLamportChange`, `ExternalAccountLamportSpend`, `UnbalancedInstruction`, `ModifiedProgramId`), and plain
|
|
3926
4013
|
`AccountInfo` parameters are enough.
|
|
3927
4014
|
|
|
4015
|
+
|
|
3928
4016
|
## Errors and panics as the original reports them
|
|
3929
4017
|
|
|
3930
4018
|
```ts
|
|
@@ -3963,6 +4051,35 @@ export function entry(): void {
|
|
|
3963
4051
|
location)` log `panicked at '<message>', <location>` and then abort, so the runtime's last line is "SBF program
|
|
3964
4052
|
panicked" with no location, as that panic handler leaves it. `panic(null, …)` is refused there (the handler always
|
|
3965
4053
|
logs); without a location the TypeScript line and column are used. `PANIC_ON_OVERFLOW`'s panics abort too.
|
|
4054
|
+
- **Panics as solana-program 1.18 writes them.** `export const PANIC_STYLE = "solana-1.18"` (a program built with
|
|
4055
|
+
solana-program 1.18, whose rustc formats a panic as it has since 1.73: Percolator v12.20) makes `panic(message,
|
|
4056
|
+
location)` log one line, `panicked at <location>:` and the message after a newline, and then abort ("SBF program
|
|
4057
|
+
panicked"), as that panic handler does: `panicked at src/wide_math.rs:1554:30:\nmul_div_floor_u128: a*b overflow`.
|
|
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.
|
|
3966
4083
|
- **Overflow panics with Rust's message and location.** `panicsAt("src/quantities.rs:233:1", a + b)` is `a + b` whose
|
|
3967
4084
|
checked arithmetic panics as Rust's overflow checks do at that location ("attempt to add with overflow"; also
|
|
3968
4085
|
"attempt to subtract / multiply with overflow", "attempt to divide by zero", "attempt to calculate the remainder with
|
|
@@ -3978,7 +4095,8 @@ export function entry(): void {
|
|
|
3978
4095
|
quantities.rs, wherever the addition is written): give the port a helper, `function addQuoteLots(a: u64, b: u64):
|
|
3979
4096
|
u64 { return panicsAt(QUOTE_LOTS_ADD, a + b); }`.
|
|
3980
4097
|
- The bits `<<` loses, `**`, `mulDiv` / `mulDivCeil`, casts and u256 arithmetic keep TypeSOL's failures (Rust checks
|
|
3981
|
-
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.
|
|
3982
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.
|
|
3983
4101
|
|
|
3984
4102
|
## Log lines as the original writes them
|
|
@@ -3993,6 +4111,8 @@ export function entry(): void {
|
|
|
3993
4111
|
- `createProgramAddress(seeds, program)` is `Pubkey::create_program_address` (null for no address).
|
|
3994
4112
|
- `logComputeUnits()` is `sol_log_compute_units()`: the runtime writes "Program consumption: N units remaining" at that
|
|
3995
4113
|
point, as for the original (Phoenix's cancel and withdraw paths log it).
|
|
4114
|
+
- `log64(a, b, c, d, e)` is `sol_log_64(a, b, c, d, e)`: the runtime writes the five u64s as lowercase hex,
|
|
4115
|
+
`Program log: 0x174778, 0x3e8, 0x0, 0x0, 0x0` (Percolator logs the slab length it wants and the one it got this way).
|
|
3996
4116
|
|
|
3997
4117
|
## Byte strings built by hand
|
|
3998
4118
|
|
|
@@ -4056,7 +4176,7 @@ void instruction (Phoenix's Borsh `Vec<FIFOOrderId>` of the orders that rested,
|
|
|
4056
4176
|
|
|
4057
4177
|
<!-- Generated by scripts/language-builtins.ts from lib/typesol.d.ts; do not edit by hand. -->
|
|
4058
4178
|
|
|
4059
|
-
Every name `"typesol"` exports (
|
|
4179
|
+
Every name `"typesol"` exports (222 names, 235 declarations), grouped, with its declaration and the first sentence of its doc
|
|
4060
4180
|
comment in `lib/typesol.d.ts`. Each group links to the part of the [language guide](language.md) that explains it;
|
|
4061
4181
|
your editor shows the full doc comment on hover. Methods of account and program types (`systemProgram.transfer`,
|
|
4062
4182
|
`acct.create`, …) are described with their types in the guide.
|
|
@@ -4194,7 +4314,7 @@ Explained in [Accounts: Closing and resizing](language-accounts.md#closing-and-r
|
|
|
4194
4314
|
| --- | --- | --- |
|
|
4195
4315
|
| `close` | `function close(account: AccountMeta, destination: AccountMeta): void` | Close a program-owned account: move all lamports to `destination` and wipe it. |
|
|
4196
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. |
|
|
4197
|
-
| `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). |
|
|
4198
4318
|
|
|
4199
4319
|
## Accounts created by hand
|
|
4200
4320
|
|
|
@@ -4274,6 +4394,7 @@ Explained in [Calling other programs: invoke](language-cpi.md#invoke).
|
|
|
4274
4394
|
| `sighash` | `function sighash(name: string): Bytes` | The 8-byte Anchor instruction discriminator for `name` (sha256("global:<snake_case name>")[..8]). |
|
|
4275
4395
|
| `hex` | `function hex(literal: string): Bytes` | Bytes from a hex string literal, e.g. hex("0a0b"). |
|
|
4276
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()`. |
|
|
4277
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)`). |
|
|
4278
4399
|
| `InstructionAccountMeta` | `interface InstructionAccountMeta` | One account of an instruction built at run time (Rust's `AccountMeta`): any struct with these three fields. |
|
|
4279
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. |
|
|
@@ -4457,12 +4578,15 @@ Explained in [Porting a native program (advanced)](language-native.md).
|
|
|
4457
4578
|
| `RbEntry` | `interface RbEntry<K, V>` | A node of a RedBlackTree: its key (read-only), its value (in place) and its index in the tree's node array (1-based). |
|
|
4458
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). |
|
|
4459
4580
|
| `assignOwner` | `function assignOwner(account: RemainingAccount \| Mut<AccountInfo>, owner: Pubkey): void` | Set an account's owner in place (Rust's `AccountInfo::assign`). |
|
|
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. |
|
|
4460
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. |
|
|
4461
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). |
|
|
4462
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. |
|
|
4463
4586
|
| `abort` | `function abort(): never` | Stop the program as Rust's `abort` does on SBF (the allocator's out-of-memory error, `std::process::abort`): the runtime's `abort` syscall, which fails the instruction with ProgramFailedToComplete and logs "SBF program panicked" (no location, nothing else). |
|
|
4464
4587
|
| `logBase64` | `function logBase64(prefix: string, value: object): void` | Log `prefix` followed by the base64 (standard, padded) of a struct value's bytes, as a native program's `msg!("ray_log: {}", base64(bincode(log)))` does. |
|
|
4465
4588
|
| `logComputeUnits` | `function logComputeUnits(): void` | Log the compute units left (Rust's `sol_log_compute_units()`): the runtime writes "Program consumption: <N> units remaining", as the original's line, at the same place. |
|
|
4589
|
+
| `log64` | `function log64(a: u64, b: u64, c: u64, d: u64, e: u64): void` | Log five u64 values as Rust's `sol_log_64(a, b, c, d, e)` does: the runtime writes "Program log: 0x<a>, 0x<b>, 0x<c>, 0x<d>, 0x<e>" (lowercase hex, no padding). |
|
|
4466
4590
|
|
|
4467
4591
|
**Next:** [Glossary](glossary.md): the Solana and TypeSOL terms the guide uses.
|
|
4468
4592
|
|
|
@@ -4999,9 +5123,9 @@ error. Exit codes: **0** success, **1** failure (compile errors, failed deploy,
|
|
|
4999
5123
|
| Command | What it does |
|
|
5000
5124
|
| --- | --- |
|
|
5001
5125
|
| `typesol init [<dir>] [--name <program>] [--template counter\|vault\|escrow] [--no-agent-files]` | Create a project ([below](#typesol-init)). |
|
|
5002
|
-
| `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). |
|
|
5003
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. |
|
|
5004
|
-
| `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)). |
|
|
5005
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. |
|
|
5006
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). |
|
|
5007
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. |
|
|
@@ -5039,7 +5163,8 @@ process on stderr. `TYPESOL_TOOLCHAIN=strict` makes it an error everywhere, `war
|
|
|
5039
5163
|
`<name>` must be snake_case; by default it is derived from `<dir>` (`my-app` → `my_app`). The template picks the
|
|
5040
5164
|
program and its test: `counter` (default, a PDA counter per user), `vault` (SOL at a PDA: deposit, withdraw above
|
|
5041
5165
|
rent, close) or `escrow` (SPL tokens: make, take, refund, the offer PDA signing for its vault). `init` refuses to
|
|
5042
|
-
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
|
|
5043
5168
|
says whether the Agave CLI is missing or only its platform-tools (on Linux arm64, where there is no Agave CLI, the
|
|
5044
5169
|
commands that set up the platform-tools' `linux-aarch64` package).
|
|
5045
5170
|
|
|
@@ -5493,7 +5618,7 @@ an account you change is a `Mut<T>` parameter; the time is `now()`, not `Date.no
|
|
|
5493
5618
|
### A transaction fails with a custom error
|
|
5494
5619
|
|
|
5495
5620
|
See [errors.md](errors.md). Failures raised by the compiler's checks log their TypeScript location, e.g. `TypeSOL:
|
|
5496
|
-
arithmetic overflow (vault.ts:
|
|
5621
|
+
arithmetic overflow (vault.ts:44)`.
|
|
5497
5622
|
|
|
5498
5623
|
### "exceeded CUs meter" / "Computational budget exceeded"
|
|
5499
5624
|
|
|
@@ -5644,7 +5769,7 @@ You need Node.js 22.12 or later and the Agave CLI with platform-tools (see the R
|
|
|
5644
5769
|
toolchain is part of what you trust. Deploy with the one TypeSOL is tested with (Agave 3.1.10, platform-tools v1.52;
|
|
5645
5770
|
`typesol doctor` says whether yours is, and `typesol deploy --toolchain-strict` refuses another). The host does not
|
|
5646
5771
|
matter from 0.45.0 on: with the same TypeSOL and toolchain a program builds to the same bytes on macOS arm64, Linux
|
|
5647
|
-
arm64 and Linux x86_64 (measured over 76 programs for SBPF v0 and 14 for v1 and v2; up to 0.44.1 a program with
|
|
5772
|
+
arm64 and Linux x86_64 (measured with 0.45.0 over the 76 programs then in the sources for SBPF v0 and 14 for v1 and v2; up to 0.44.1 a program with
|
|
5648
5773
|
128-bit or signed division did not, [stability.md](stability.md#what-builds-the-same-bytes-where)). For a program others should be able to verify, build
|
|
5649
5774
|
it with `--docker` (step 2) all the same: a pinned linux/amd64 container that anyone can rebuild, so the whole
|
|
5650
5775
|
environment is one recipe. Keep
|
|
@@ -5847,7 +5972,7 @@ auditors, [SECURITY.md](../SECURITY.md) how to report a problem.
|
|
|
5847
5972
|
| --- | --- |
|
|
5848
5973
|
| The program's author | the program's logic: what it allows, to whom, for how much |
|
|
5849
5974
|
| TypeSOL (this repository) | that the binary does what the source and these guarantees say, and nothing an attacker can steer beyond it |
|
|
5850
|
-
| The toolchain | the TypeScript compiler API (parsing, types), Agave platform-tools (clang, lld), Node.js. The guarantees are tested with one platform-tools release (v1.52, from Agave 3.1.10); a build with another warns, or fails with `--toolchain-strict`, and `<name>.build.json` records which one built a binary and on which host. The compiler builtins (128-bit multiplication, division and shifts, signed 64-bit division) are TypeSOL's own (`runtime/typesol_builtins.c`), compiled with the program; nothing is linked from platform-tools' Rust libraries, whose layout differed by host package, so from 0.45.0 on the programs measured build to the same bytes on macOS arm64, Linux arm64 and Linux x86_64 ([stability.md](stability.md#what-builds-the-same-bytes-where): 76 programs for SBPF v0, 14 for v1 and v2). `--docker` builds pin the whole environment in one linux/amd64 container whose inputs are checked by digest, checksum and integrity (base images, release files, the TypeSOL tarball and every npm dependency) |
|
|
5975
|
+
| The toolchain | the TypeScript compiler API (parsing, types), Agave platform-tools (clang, lld), Node.js. The guarantees are tested with one platform-tools release (v1.52, from Agave 3.1.10); a build with another warns, or fails with `--toolchain-strict`, and `<name>.build.json` records which one built a binary and on which host. The compiler builtins (128-bit multiplication, division and shifts, signed 64-bit division) are TypeSOL's own (`runtime/typesol_builtins.c`), compiled with the program; nothing is linked from platform-tools' Rust libraries, whose layout differed by host package, so from 0.45.0 on the programs measured build to the same bytes on macOS arm64, Linux arm64 and Linux x86_64 ([stability.md](stability.md#what-builds-the-same-bytes-where): measured with 0.45.0 over the 76 programs then in the sources for SBPF v0, 14 for v1 and v2). `--docker` builds pin the whole environment in one linux/amd64 container whose inputs are checked by digest, checksum and integrity (base images, release files, the TypeSOL tarball and every npm dependency) |
|
|
5851
5976
|
| The Solana runtime | account ownership and signer flags as passed, the loader's account serialization, CPI privilege rules, sysvars |
|
|
5852
5977
|
|
|
5853
5978
|
Everything a transaction carries is attacker-controlled: the instruction data, which accounts are passed in which
|
|
@@ -5919,7 +6044,10 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
5919
6044
|
transaction did not pass that way and any signer the program's seeds do not cover. Only programs that store
|
|
5920
6045
|
instructions to run (a multisig, a DAO) need it; review who can write those values.
|
|
5921
6046
|
Return data is read only from the program named, at the expected size (5106).
|
|
5922
|
-
13. **Events.** `emitCpi` is accepted only from this program's event-authority PDA, signed (2002).
|
|
6047
|
+
13. **Events.** `emitCpi` is accepted only from this program's event-authority PDA, signed (2002). Under
|
|
6048
|
+
`EVENT_AUTHORITY_CHECK = "address"` (0.48.0) the event authority is checked by address among the constraints
|
|
6049
|
+
(2012) instead, and the self-program account is not checked at all: an instruction that emits fails in the runtime
|
|
6050
|
+
(MissingAccount) when this program is not among its accounts, as Anchor 1.x's does.
|
|
5923
6051
|
|
|
5924
6052
|
### When it ends
|
|
5925
6053
|
|
|
@@ -6014,8 +6142,13 @@ exposed to them.
|
|
|
6014
6142
|
The compiler and runtime have had internal security reviews, the latest of 0.44.0 (above); its findings are fixed in
|
|
6015
6143
|
0.44.1. It was an internal review, not an independent audit; it covered the token, Token-2022, Metaplex and Stake
|
|
6016
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
|
|
6017
|
-
wrappers for unusual argument shapes beyond reading them, the large ports on SBPF v1/v2, or Windows.
|
|
6018
|
-
|
|
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
|
|
6146
|
+
have had no security review. They add, among others, `runtime/typesol_builtins.c` (the
|
|
6147
|
+
compiler builtins as TypeSOL's own C, 0.45.0), `transferCheckedWithHook`, `EVENT_AUTHORITY_CHECK` and the reads of
|
|
6148
|
+
processed sibling instructions (0.48.0), `zeroData`, `log64`,
|
|
6149
|
+
`PANIC_STYLE = "solana-1.18"`, `executable` on remaining accounts and lamport writes on remaining accounts under
|
|
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).
|
|
6019
6152
|
|
|
6020
6153
|
<!-- docs/ai.md -->
|
|
6021
6154
|
|
|
@@ -6143,14 +6276,18 @@ Meant to stay as they are; a change before 1.0 would be a breaking change listed
|
|
|
6143
6276
|
|
|
6144
6277
|
## What builds the same bytes where
|
|
6145
6278
|
|
|
6146
|
-
From 0.45.0 on, the programs measured build to the same bytes on each host measured. Measured with
|
|
6279
|
+
From 0.45.0 on, the programs measured build to the same bytes on each host measured. Measured with 0.45.0's
|
|
6147
6280
|
compiler and platform-tools v1.52 on macOS arm64 (the platform-tools `osx-aarch64` package, native), Linux arm64 and
|
|
6148
6281
|
Linux x86_64 (the `linux-aarch64` and `linux-x86_64` packages, in containers; x86_64 is the `--docker` image; Linux
|
|
6149
6282
|
arm64 has no Agave CLI, so there the package is set up by hand with `TYPESOL_SBF_SDK`, as in
|
|
6150
6283
|
[troubleshooting.md](troubleshooting.md#linux-arm64-the-agave-installer-fails-with-a-404)): for
|
|
6151
|
-
SBPF v0 (the default), the 76 programs
|
|
6152
|
-
and `showcase/`); for SBPF v1 and v2, the 14 programs of `test/golden/binaries.json` (counter, vault,
|
|
6153
|
-
and the 10 below).
|
|
6284
|
+
SBPF v0 (the default), the 76 programs then in the sources (`scripts/release-manifest.ts`, every program under
|
|
6285
|
+
`examples/` and `showcase/`); for SBPF v1 and v2, the 14 programs of `test/golden/binaries.json` (counter, vault,
|
|
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).
|
|
6154
6291
|
|
|
6155
6292
|
| What | Same on the three hosts? |
|
|
6156
6293
|
| --- | --- |
|
|
@@ -6208,6 +6345,8 @@ Useful today, but may still change before 1.0 (each change listed in the CHANGEL
|
|
|
6208
6345
|
its panics in solana-program 1.14–1.17's format, `removeAt(index)` (what it gives for a node in no tree may change).
|
|
6209
6346
|
- `panic(null, location)` (no log line) and `abort()` (Rust's abort, "SBF program panicked") (0.42.0).
|
|
6210
6347
|
- Failures without a log line (0.43.0): `ERROR_LOG_PREFIX = null` / `PROGRAM_ERROR_LOG_PREFIX = null`.
|
|
6348
|
+
- `EVENT_AUTHORITY_CHECK = "address"` (0.48.0): `emitCpi`'s event authority checked by address, as Anchor 1.x's
|
|
6349
|
+
`#[event_cpi]` does, and the self-program account not checked (docs/security-model.md, guarantee 13).
|
|
6211
6350
|
- `findProgramAddressWithBump` (0.43.0), with `const [address, bump] = …` its only array destructuring.
|
|
6212
6351
|
- Plain type aliases (0.43.0): `type Price = u64`, replaced by the type they name.
|
|
6213
6352
|
- File-local structs (0.43.0): `interface Pair { … }` without `export`, for helpers and locals, out of the IDL.
|
package/llms.txt
CHANGED
|
@@ -38,4 +38,5 @@ The rules and the whole reference in one file: https://typesol.com/llms-full.txt
|
|
|
38
38
|
|
|
39
39
|
## Optional
|
|
40
40
|
|
|
41
|
-
- [Case studies](https://typesol.com/docs/case-study-marginfi/): mainnet programs (Marginfi v2, Phoenix v1, SPL Stake Pool, Raydium AMM v4, CLMM, CP-Swap, Jito) ported and checked against their binaries
|
|
41
|
+
- [Case studies](https://typesol.com/docs/case-study-marginfi/): mainnet programs (Marginfi v2, Phoenix v1, SPL Stake Pool, Raydium AMM v4, CLMM, CP-Swap, Jito MEV, coral-xyz/multisig) ported and checked against their binaries
|
|
42
|
+
- [Percolator v12.20 and Meteora DBC 0.2.2](https://github.com/typesol-lang/typesol/tree/main/showcase/mainnet): two more ports checked against their mainnet binaries, each described in its own README (Meteora's under Meteora's Non-commercial Licence)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typesol/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Compile a TypeScript
|
|
3
|
+
"version": "0.50.0",
|
|
4
|
+
"description": "Compile a TypeScript subset to Solana SBF programs (through C and the platform-tools clang), with an Anchor-compatible IDL.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"test": "vitest run",
|
|
70
70
|
"typesol": "node dist/cli.js",
|
|
71
71
|
"smoke": "node scripts/smoke.ts",
|
|
72
|
-
"fuzz": "FUZZ_RUNS=2000 FUZZ_STEPS=600 FUZZ_VERBOSE=1 vitest run test/verification/fuzz-arith.test.ts test/verification/fuzz-state.test.ts test/verification/fuzz-layout.test.ts test/verification/differential.test.ts showcase/test/fuzz-jito.test.ts showcase/test/fuzz-marginfi.test.ts showcase/test/phoenix-fuzz.test.ts --silent=false",
|
|
72
|
+
"fuzz": "FUZZ_RUNS=2000 FUZZ_STEPS=600 FUZZ_VERBOSE=1 vitest run test/verification/fuzz-arith.test.ts test/verification/fuzz-state.test.ts test/verification/fuzz-layout.test.ts test/verification/differential.test.ts showcase/test/fuzz-jito.test.ts showcase/test/fuzz-marginfi.test.ts showcase/test/phoenix-fuzz.test.ts showcase/test/percolator-fuzz.test.ts --silent=false",
|
|
73
73
|
"build:twins": "cd test/anchor-twins && cargo-build-sbf",
|
|
74
74
|
"prepack": "npm run build",
|
|
75
75
|
"fetch:programs": "bash scripts/fetch-programs.sh",
|