@typesol/cli 0.47.0 → 0.48.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/docs/audit.md CHANGED
@@ -7,14 +7,14 @@ with TypeSOL are out of scope; their authors audit them.
7
7
 
8
8
  ## Scope
9
9
 
10
- In order of priority. Line counts at 0.45.0 (November 2026).
10
+ In order of priority. Line counts at 0.48.0 (November 2026).
11
11
 
12
12
  | Priority | Component | Files | Lines | Why |
13
13
  | --- | --- | --- | ---: | --- |
14
- | 1 | C runtime | `runtime/typesol_rt.h` | 2,998 | In every program: input parsing, account checks, checked arithmetic, PDAs, system and token CPIs, account creation, resizing and closing, oracles, signature checks, the heap |
15
- | 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 876 | Which checks each account parameter gets, and their order |
16
- | 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 3,867 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
17
- | 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,711 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
14
+ | 1 | C runtime | `runtime/typesol_rt.h` | 3,272 | In every program: input parsing, account checks, checked arithmetic, PDAs, system and token CPIs, account creation, resizing and closing, oracles, signature checks, the heap |
15
+ | 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 886 | Which checks each account parameter gets, and their order |
16
+ | 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 4,017 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
17
+ | 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,746 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
18
18
  | 1 | Raw views and the red-black tree | `src/compiler/emit/views.ts`, `rbtree.ts` | 655 | Accounts read without a discriminator at run-time offsets (`loadRaw`, `loadRawAt`, `rawArrayAt`, `BigVec`), their bounds, and the red-black tree's node indexes (`rbTreeAt`) |
19
19
  | 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,465 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
20
20
  | 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 2,168 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
@@ -22,7 +22,7 @@ In order of priority. Line counts at 0.45.0 (November 2026).
22
22
  | 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,460 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
23
23
  | 3 | Build and tooling | `src/compiler/toolchain.ts`, `src/cli.ts`, `src/workspace.ts`, `src/tools/` | | Build flags, deploy and verification commands |
24
24
 
25
- The language surface is `lib/typesol.d.ts` (2,626 lines): every type and built-in a program can use, with its
25
+ The language surface is `lib/typesol.d.ts` (2,653 lines): every type and built-in a program can use, with its
26
26
  documented behavior. [docs/language.md](language.md) is the reference; [docs/architecture.md](architecture.md) maps
27
27
  the code, [docs/runtime.md](runtime.md) the runtime's conventions.
28
28
 
@@ -278,7 +278,8 @@ export function setup(config: Mut<Config>): void {
278
278
  other than its accounts.
279
279
  - A few names configure the compiler: `HEAP_SIZE_KIB` ([below](#memory-stack-and-heap)), `MAX_ACCOUNTS`
280
280
  ([accounts](language-accounts.md#how-many-accounts)), `NATIVE_ACCOUNT_WRITES`, `PANIC_ON_OVERFLOW`, `PANIC_STYLE`,
281
- `ERROR_LOG_PREFIX`, `PROGRAM_ERROR_LOG_PREFIX` ([native programs](language-native.md)).
281
+ `ERROR_LOG_PREFIX`, `PROGRAM_ERROR_LOG_PREFIX` ([native programs](language-native.md)), `EVENT_AUTHORITY_CHECK`
282
+ ([events through CPI](language-errors-events.md#events-through-cpi)).
282
283
 
283
284
  ## Type aliases
284
285
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  <!-- Generated by scripts/language-builtins.ts from lib/typesol.d.ts; do not edit by hand. -->
4
4
 
5
- Every name `"typesol"` exports (216 names, 229 declarations), grouped, with its declaration and the first sentence of its doc
5
+ Every name `"typesol"` exports (218 names, 231 declarations), grouped, with its declaration and the first sentence of its doc
6
6
  comment in `lib/typesol.d.ts`. Each group links to the part of the [language guide](language.md) that explains it;
7
7
  your editor shows the full doc comment on hover. Methods of account and program types (`systemProgram.transfer`,
8
8
  `acct.create`, …) are described with their types in the guide.
@@ -346,6 +346,8 @@ Explained in [Sysvars, hashes, signatures and oracles: Sysvars](language-chain.m
346
346
  | `SlotHashesSysvar` | `interface SlotHashesSysvar` | The SlotHashes sysvar (`SysvarS1otHashes…`), read as an account: it is too large for the sysvar syscalls (Anchor's `Sysvar<SlotHashes>` cannot load it either). |
347
347
  | `StakeHistorySysvar` | `interface StakeHistorySysvar` | The StakeHistory sysvar (`SysvarStakeHistory…`), read as an account: the cluster's stake per recent epoch (up to 512, newest first), as the Stake program uses it for warmup and cooldown. |
348
348
  | `stackHeight` | `function stackHeight(): u64` | How deep in cross-program calls this program runs: 1 when the transaction calls it directly, more when another program invoked it. |
349
+ | `processedSiblingInstructionCount` | `function processedSiblingInstructionCount(): u64` | How many instructions the caller of this program has already invoked at this program's stack height (its processed siblings), or, when the transaction calls this program directly, how many top-level instructions ran before this one (Rust's `get_processed_sibling_instruction(i)` until it returns None). |
350
+ | `processedSiblingInstruction` | `function processedSiblingInstruction(index: u64): TransactionInstruction` | Processed sibling instruction `index` (0 the latest), as Rust's `get_processed_sibling_instruction(index)` reads it with the `sol_get_processed_sibling_instruction` syscall: its program id, accounts and data, as a TransactionInstruction. 5104 when there is none at that index. |
349
351
 
350
352
  ## Hashes, signatures and introspection
351
353
 
@@ -81,7 +81,14 @@ export function commit(c: Mut<Commit>, owner: Pubkey, text: string, n: u64): voi
81
81
  themselves. Unlike a check such as `HasOne`, nothing happens when the answer is false: wrap them in
82
82
  `require(…, error)`. The compiler refuses a call used as a statement, one that is the
83
83
  condition of an `if` with an empty body and no `else` or an empty one, and one whose result is kept in a local the function never
84
- reads. It does not catch a helper that returns the result and is itself called as a statement.
84
+ reads. The same goes for a call of a helper that returns such a result: one with a `return` that gives the result of
85
+ one of the three or of another such helper, directly, combined with `&&`, `||`, `!` or `?:`, or through a local of
86
+ the helper that nothing but its returns reads (`the result of checkProof is discarded, so nothing is checked: it
87
+ returns the result of merkleVerify; write require(checkProof(…), error)`). A helper that acts on the result itself
88
+ (requires it, reads it outside a `return`) is not one. Not caught: a result stored in an account field, a struct or an
89
+ Option, compared (`=== true`) or passed to another function that ignores it, a helper that branches on the result and
90
+ returns literals (`if (!ok) { return false; } return true;`), and a helper that returns what a function passed to it
91
+ returns (a function parameter is not followed).
85
92
 
86
93
  ```ts
87
94
  import { type Account, type Hash, type Init, type InstructionsSysvar, type Mut, type Pubkey, type Signer, type SystemProgram, type u8, type u64, type Vec, keccak256, merkleVerify, require, verifyEd25519, verifySecp256k1 } from "typesol";
@@ -130,6 +137,11 @@ export function approved(drop: Account<Drop>, ixs: InstructionsSysvar, who: Pubk
130
137
  `is(program, "name")` (that program's instruction by its default Anchor discriminator, sha256("global:<name>"); an
131
138
  instruction with its own `@discriminator` is matched with `programId` and `readU64(0)` instead).
132
139
  - Every read is bounds-checked (5104).
140
+ - `processedSiblingInstructionCount()` and `processedSiblingInstruction(i)` (a `TransactionInstruction`, 5104 past
141
+ the last) read the instructions already processed at this program's stack height, with the
142
+ `sol_get_processed_sibling_instruction` syscall as Rust's `get_processed_sibling_instruction` reads it: under a
143
+ caller, the instructions that caller already invoked (index 0 the latest); at the top level, the transaction's
144
+ earlier instructions. With `stackHeight()`, a program can refuse to run twice under one caller.
133
145
  - It is the transaction author's data: require things of the transaction with it (a repay instruction after a flash
134
146
  loan), never treat it as proof.
135
147
 
@@ -54,6 +54,7 @@ Pass signer seeds (with the bump) as the last argument when the authority is a P
54
54
  | Methods | Notes |
55
55
  | --- | --- |
56
56
  | `transfer`, `transferChecked(from, mint, to, authority, amount)` | Token-2022 mints with fees or hooks require `transferChecked` |
57
+ | `transferCheckedWithHook(from, mint, to, authority, amount, hookAccounts)` | `transferChecked` for a mint with a transfer hook: [the hook's extra accounts](#calling-a-transfer-hook-mint) resolved among `hookAccounts` |
57
58
  | `mintTo`, `mintToChecked(mint, to, authority, amount)` | the mint may be one this instruction just created |
58
59
  | `burn`, `burnChecked(from, mint, authority, amount)` | |
59
60
  | `approve(source, delegate, owner, amount)`, `approveChecked(source, mint, delegate, owner, amount)`, `revoke` | the checked forms take the decimals from the mint |
@@ -467,4 +468,29 @@ ExtraAccountMetaList).
467
468
  - Inside the hook, `isTransferring(source)` says whether Token-2022 is transferring from it.
468
469
  - See [`test/fixtures/hook.ts`](https://github.com/typesol-lang/typesol/blob/main/test/fixtures/hook.ts) and the transfer-hook ports.
469
470
 
471
+ ### Calling a transfer hook mint
472
+
473
+ A program that moves a hooked mint's tokens by CPI must pass Token-2022 the hook's extra accounts, the validation
474
+ account and the hook program after the four of TransferChecked. `tokenProgram.transferCheckedWithHook(from, mint, to,
475
+ authority, amount, hookAccounts, signerSeeds?)` builds that call as Rust's
476
+ `spl_transfer_hook_interface::onchain::add_extra_accounts_for_execute_cpi` does: `hookAccounts` (`remainingAccounts()`
477
+ or `rest.slice(a, b)`) must hold the hook program and, when the transfer needs it, the validation account and every
478
+ extra account, in any order. Each extra account is resolved from the list (a fixed address, a PDA of the hook or of
479
+ another program from literal, instruction-data, account-key and account-data seeds, or a key read from an account's
480
+ data), against the execute instruction's accounts (source, mint, destination, authority, the validation account, then
481
+ the extra accounts already resolved), made read-only where every earlier mention of it is, and never a signer. The
482
+ refusals are the Rust crates' and their codes: the hook program missing (TransferHookError::IncorrectAccount,
483
+ 2110272652), an extra account missing (AccountResolutionError::IncorrectAccount, 2724315840; the other
484
+ AccountResolutionError codes for bad seeds), no list in the validation account (TlvError::TypeNotFound, 1202666432), a
485
+ malformed one (InvalidAccountData, InvalidArgument, or 1 for a list shorter than its count). Without the validation
486
+ account among `hookAccounts` only the hook program is added; a mint without a hook gets a plain `transferChecked`.
487
+
488
+ ```ts
489
+ import { type Mint, type Mut, type Signer, type TokenAccount, type TokenInterface, type u64, remainingAccounts } from "typesol";
490
+
491
+ export function pay(from: Mut<TokenAccount>, mint: Mint, to: Mut<TokenAccount>, owner: Signer, tokenProgram: TokenInterface, amount: u64): void {
492
+ tokenProgram.transferCheckedWithHook(from, mint, to, owner, amount, remainingAccounts());
493
+ }
494
+ ```
495
+
470
496
  **Next:** [Sysvars, hashes, signatures and oracles](language-chain.md).
@@ -124,6 +124,9 @@ export function deposit(owner: Signer, pool: Mut<Pool>, amount: u64, tags: Vec<u
124
124
  when empty.
125
125
  - An event is at most 1024 bytes (5107).
126
126
 
127
+ In a test, `t.events(res)` gives a transaction's events decoded, `emitCpi`'s too
128
+ ([asserting events](test-your-program.md#events)).
129
+
127
130
  ### Events through CPI
128
131
 
129
132
  ```ts
@@ -148,6 +151,18 @@ instruction) instead of the logs. The instruction takes `eventAuthority:
148
151
  EventAuthority` (Anchor's `["__event_authority"]` PDA) and `self: SelfProgram` parameters, and the program accepts
149
152
  Anchor's event instruction (2002 when the event authority did not sign it, 2006 when it is not that PDA).
150
153
 
154
+ By default the two accounts are checked when the instruction's accounts load: the event authority by its seeds (2006)
155
+ and `self` against this program's address (3008). Anchor 1.x's `#[event_cpi]` checks them differently, and
156
+ `export const EVENT_AUTHORITY_CHECK = "address"` does as it does, for ports of Anchor 1.x programs:
157
+
158
+ - the event authority is compared with the PDA's address among the constraints, in account order after the accounts
159
+ load and the `create`s run (ConstraintAddress, 2012);
160
+ - the `self` account is not checked: the self-CPI names this program's id whatever account was passed there. An
161
+ instruction that emits nothing then accepts any account in that slot; one that emits fails in the runtime
162
+ (MissingAccount) when this program is not among its accounts, as Anchor's `emit_cpi!` does.
163
+
164
+ Programs without the constant build as before.
165
+
151
166
  ## Return values
152
167
 
153
168
  ```ts
@@ -614,6 +614,7 @@ may gain a hint line.
614
614
  | an unused proof or signature check | `merkleVerify(leaf, proof, root);` | the result of merkleVerify is discarded, so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
615
615
  | a proof check in an empty `if` | `if (merkleVerify(leaf, proof, root)) {}` | the result of merkleVerify is not acted on: the if around it has an empty body, so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
616
616
  | a proof check kept in a local never read | `const ok = merkleVerify(leaf, proof, root);` (`ok` unused) | the result of merkleVerify is never read (ok is not used), so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
617
+ | an unused helper that returns a check | `checkProof(leaf, proof, root);` (`checkProof` returns `merkleVerify(…)`) | the result of checkProof is discarded, so nothing is checked: it returns the result of merkleVerify; write require(checkProof(…), error) |
617
618
  | a `@code` tag outside a doc comment | `export enum E { A = "a", /* @code 6100 */ B = "b" }` | this @code tag is not read: only a doc comment (/** … */) is, not a /* … */ comment; write /** @code … */ above B |
618
619
  | a `@code` tag after other code on its line | `export enum E { A = "a", /** @code 6100 */ B = "b" }` | this @code tag is not read: other code comes before it on its line; put /** @code … */ on its own line above B |
619
620
 
@@ -34,7 +34,13 @@ instruction that takes the bump as an argument (prefer a stored bump:
34
34
  constants, arguments or other accounts' keys (`t.ix("initialize", {}, { authority: alice })` derives `counter`). Pass a keypair for an account that
35
35
  signs, an address otherwise, and `null` to leave an optional account out.
36
36
  - **Arguments as plain values:** bigints or numbers for integers, address strings for Pubkeys, `null` for an empty
37
- Option, objects for structs (camelCase or snake_case fields), arrays for Vecs.
37
+ Option, objects for structs (camelCase or snake_case fields), arrays for Vecs, `{ Variant: { field: value } }` for a
38
+ data enum (a unit enum also as its index or variant name). Every argument and every field of a struct or variant
39
+ must be given, except an Option, which left out is None. A missing one is an error that names it and lists the
40
+ instruction's arguments (`set: argument "amount" is missing (it takes amount, cap, frame, shape; …)`,
41
+ `set(frame).origin.y is missing (Point has x, y; …)`), and so is a key that names no argument or field
42
+ (`set has no argument "amonut" (it takes amount, cap, frame, shape)`), so a misspelt name is never sent as zeros
43
+ or as None.
38
44
  - **Remaining accounts:** `[{ address, writable?, signer? }]`, where `signer` is the account's `KeyPairSigner` (it then
39
45
  signs as a signer account; `writable` defaults to false).
40
46
 
@@ -66,8 +72,9 @@ looks like one.
66
72
  | --- | --- |
67
73
  | `t.ok(res)` | the successful result, or throws with the error, its name (`NotAdmin`) and the program's logs |
68
74
  | `t.errorCode(res)` | the custom error code of a failed transaction: 6000 + the member's index in your error enum, or a framework code ([errors.md](errors.md)) |
69
- | `t.account(type, address)` | the account decoded by its IDL type (bigints, address strings), or `null` once closed. TypeSOL fixed layouts come back as their IDL structs: a `FixedString<N>` as `{ len, bytes }`, a `FixedVec<T, N>` as `{ len, items }` (the generated client gives strings and arrays) |
75
+ | `t.account(type, address)` | the account decoded by its IDL type (bigints, address strings), or `null` once closed. A `FixedString<N>` comes back as a string and a fixed-layout Option as its value or `null`; a `FixedVec<T, N>` as its IDL struct `{ len, items }` (the generated client gives an array) |
70
76
  | `t.returned(instruction, res)` | the instruction's return data: an integer, boolean, Pubkey or struct |
77
+ | `t.events(res)` | the events the transaction emitted, decoded, in order: `[{ name, data }]` ([events](#events)) |
71
78
  | `t.balance(address)` | lamports |
72
79
  | `t.errorName(code)` | the name of an error code: your program's, TypeSOL's or Anchor's |
73
80
  | `t.connection` | `{ rpc, rpcSubscriptions }` answered by this LiteSVM, for the generated client: `counter.sendInstructions(t.connection, alice, [ix])`, `counter.accounts.Counter.fetch(t.connection.rpc, address)`, views, `resolve`, `watch` and `watchEvents` (as on a cluster: `watch` yields when a later transaction changes the account, not at once; `watchEvents` gets transactions sent after it subscribed, failed ones included in the stream and skipped by the client) |
@@ -88,6 +95,38 @@ expect(t.errorName(t.errorCode(res))).toBe("TooMuch");
88
95
  `t.errorCode` throws when the transaction succeeded or failed without a custom code (a runtime error such as missing
89
96
  signatures), so the test fails then too.
90
97
 
98
+ ### Events
99
+
100
+ `t.events(res)` decodes the events of a successful transaction (it throws as `t.ok` does when it failed), in the
101
+ order the program emitted them: `emit`'s `Program data:` log lines and `emitCpi`'s self-CPIs alike, only this
102
+ program's. Each is `{ name, data }`, the fields as `t.account` gives them (bigints, address strings, a `FixedString`
103
+ as a string).
104
+
105
+ For a program that emits
106
+
107
+ ```ts
108
+ export interface Deposited {
109
+ owner: Pubkey;
110
+ amount: u64;
111
+ memo: string;
112
+ referrer: Option<Pubkey>;
113
+ }
114
+
115
+ export function deposit(owner: Signer, amount: u64): void {
116
+ emit<Deposited>({ owner: owner.key, amount, memo: "thanks", referrer: null });
117
+ }
118
+ ```
119
+
120
+ a test asserts
121
+
122
+ ```ts
123
+ const res = await t.send(alice, t.ix("deposit", { amount: 5n }, { owner: alice }));
124
+ expect(t.events(res)).toEqual([{ name: "Deposited", data: { owner: alice.address, amount: 5n, memo: "thanks", referrer: null } }]);
125
+ ```
126
+
127
+ Log lines past the runtime's log limit are cut off, and the events in them with them. See [events](language-errors-events.md#events) for
128
+ what a program can emit.
129
+
91
130
  ## Tokens and time
92
131
 
93
132
  | Helper | Does |
@@ -110,8 +149,8 @@ program you loaded yourself, and `svmConnection(svm)` the RPC pair alone (for an
110
149
  program loaded). Transactions sent through it run at once; `getProgramAccounts` (`fetchAll`) sees the accounts those
111
150
  transactions named, plus any you `track(...)`.
112
151
 
113
- The module needs `litesvm`, which `typesol init` adds to `devDependencies`. It encodes arguments and decodes accounts
114
- and return data from the IDL with its own Borsh coder, so Anchor's TypeScript package is not needed.
152
+ The module needs `litesvm`, which `typesol init` adds to `devDependencies`. It encodes arguments and decodes accounts,
153
+ return data and events from the IDL with its own Borsh coder, so Anchor's TypeScript package is not needed.
115
154
 
116
155
  ## Epochs and staking
117
156
 
package/lib/typesol.d.ts CHANGED
@@ -493,6 +493,18 @@ export interface TransactionInstruction {
493
493
  * program invoked it. `require(stackHeight() === 1n, …)` refuses CPI callers.
494
494
  */
495
495
  export declare function stackHeight(): u64;
496
+ /**
497
+ * How many instructions the caller of this program has already invoked at this program's stack height (its processed
498
+ * siblings), or, when the transaction calls this program directly, how many top-level instructions ran before this one
499
+ * (Rust's `get_processed_sibling_instruction(i)` until it returns None).
500
+ */
501
+ export declare function processedSiblingInstructionCount(): u64;
502
+ /**
503
+ * Processed sibling instruction `index` (0 the latest), as Rust's `get_processed_sibling_instruction(index)` reads it
504
+ * with the `sol_get_processed_sibling_instruction` syscall: its program id, accounts and data, as a
505
+ * TransactionInstruction. 5104 when there is none at that index.
506
+ */
507
+ export declare function processedSiblingInstruction(index: u64): TransactionInstruction;
496
508
 
497
509
  /**
498
510
  * Whether this transaction contains an Ed25519 precompile instruction that verified `message`
@@ -2083,6 +2095,21 @@ type MintArg = Mint | AccountInfo | RemainingAccount;
2083
2095
  interface TokenOps {
2084
2096
  transfer(from: TokenAccountArg, to: TokenAccountArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
2085
2097
  transferChecked(from: TokenAccountArg, mint: MintArg, to: TokenAccountArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
2098
+ /**
2099
+ * transferChecked for a Token-2022 mint with a transfer hook: the hook's extra accounts are resolved from its
2100
+ * validation account (["extra-account-metas", mint] of the hook program) among `hookAccounts` and appended, then the
2101
+ * validation account and the hook program, as spl-transfer-hook-interface's `add_extra_accounts_for_execute_cpi`
2102
+ * does (its refusals and error codes included). Without a hook program on the mint, a plain transferChecked.
2103
+ */
2104
+ transferCheckedWithHook(
2105
+ from: TokenAccountArg,
2106
+ mint: MintArg,
2107
+ to: TokenAccountArg,
2108
+ authority: AccountMeta,
2109
+ amount: u64,
2110
+ hookAccounts: RemainingAccounts | RemainingSlice,
2111
+ signerSeeds?: Seed[] | SignerSeeds,
2112
+ ): void;
2086
2113
  /** `mint`: a Mut<Mint>, or a mint this instruction created and initialized (Mut<Signer> / Mut<AccountInfo>). */
2087
2114
  /** `to`: a Mut<TokenAccount>, or a Mut<AccountInfo> token account this instruction created (e.g. with `ata.create`). */
2088
2115
  mintTo(mint: MintArg | AccountMeta, to: TokenAccountArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
package/llms-full.txt CHANGED
@@ -598,7 +598,8 @@ export function setup(config: Mut<Config>): void {
598
598
  other than its accounts.
599
599
  - A few names configure the compiler: `HEAP_SIZE_KIB` ([below](#memory-stack-and-heap)), `MAX_ACCOUNTS`
600
600
  ([accounts](language-accounts.md#how-many-accounts)), `NATIVE_ACCOUNT_WRITES`, `PANIC_ON_OVERFLOW`, `PANIC_STYLE`,
601
- `ERROR_LOG_PREFIX`, `PROGRAM_ERROR_LOG_PREFIX` ([native programs](language-native.md)).
601
+ `ERROR_LOG_PREFIX`, `PROGRAM_ERROR_LOG_PREFIX` ([native programs](language-native.md)), `EVENT_AUTHORITY_CHECK`
602
+ ([events through CPI](language-errors-events.md#events-through-cpi)).
602
603
 
603
604
  ## Type aliases
604
605
 
@@ -1930,6 +1931,7 @@ may gain a hint line.
1930
1931
  | an unused proof or signature check | `merkleVerify(leaf, proof, root);` | the result of merkleVerify is discarded, so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
1931
1932
  | a proof check in an empty `if` | `if (merkleVerify(leaf, proof, root)) {}` | the result of merkleVerify is not acted on: the if around it has an empty body, so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
1932
1933
  | a proof check kept in a local never read | `const ok = merkleVerify(leaf, proof, root);` (`ok` unused) | the result of merkleVerify is never read (ok is not used), so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
1934
+ | an unused helper that returns a check | `checkProof(leaf, proof, root);` (`checkProof` returns `merkleVerify(…)`) | the result of checkProof is discarded, so nothing is checked: it returns the result of merkleVerify; write require(checkProof(…), error) |
1933
1935
  | a `@code` tag outside a doc comment | `export enum E { A = "a", /* @code 6100 */ B = "b" }` | this @code tag is not read: only a doc comment (/** … */) is, not a /* … */ comment; write /** @code … */ above B |
1934
1936
  | a `@code` tag after other code on its line | `export enum E { A = "a", /** @code 6100 */ B = "b" }` | this @code tag is not read: other code comes before it on its line; put /** @code … */ on its own line above B |
1935
1937
 
@@ -2766,6 +2768,9 @@ export function deposit(owner: Signer, pool: Mut<Pool>, amount: u64, tags: Vec<u
2766
2768
  when empty.
2767
2769
  - An event is at most 1024 bytes (5107).
2768
2770
 
2771
+ In a test, `t.events(res)` gives a transaction's events decoded, `emitCpi`'s too
2772
+ ([asserting events](test-your-program.md#events)).
2773
+
2769
2774
  ### Events through CPI
2770
2775
 
2771
2776
  ```ts
@@ -2790,6 +2795,18 @@ instruction) instead of the logs. The instruction takes `eventAuthority:
2790
2795
  EventAuthority` (Anchor's `["__event_authority"]` PDA) and `self: SelfProgram` parameters, and the program accepts
2791
2796
  Anchor's event instruction (2002 when the event authority did not sign it, 2006 when it is not that PDA).
2792
2797
 
2798
+ By default the two accounts are checked when the instruction's accounts load: the event authority by its seeds (2006)
2799
+ and `self` against this program's address (3008). Anchor 1.x's `#[event_cpi]` checks them differently, and
2800
+ `export const EVENT_AUTHORITY_CHECK = "address"` does as it does, for ports of Anchor 1.x programs:
2801
+
2802
+ - the event authority is compared with the PDA's address among the constraints, in account order after the accounts
2803
+ load and the `create`s run (ConstraintAddress, 2012);
2804
+ - the `self` account is not checked: the self-CPI names this program's id whatever account was passed there. An
2805
+ instruction that emits nothing then accepts any account in that slot; one that emits fails in the runtime
2806
+ (MissingAccount) when this program is not among its accounts, as Anchor's `emit_cpi!` does.
2807
+
2808
+ Programs without the constant build as before.
2809
+
2793
2810
  ## Return values
2794
2811
 
2795
2812
  ```ts
@@ -2883,6 +2900,7 @@ Pass signer seeds (with the bump) as the last argument when the authority is a P
2883
2900
  | Methods | Notes |
2884
2901
  | --- | --- |
2885
2902
  | `transfer`, `transferChecked(from, mint, to, authority, amount)` | Token-2022 mints with fees or hooks require `transferChecked` |
2903
+ | `transferCheckedWithHook(from, mint, to, authority, amount, hookAccounts)` | `transferChecked` for a mint with a transfer hook: [the hook's extra accounts](#calling-a-transfer-hook-mint) resolved among `hookAccounts` |
2886
2904
  | `mintTo`, `mintToChecked(mint, to, authority, amount)` | the mint may be one this instruction just created |
2887
2905
  | `burn`, `burnChecked(from, mint, authority, amount)` | |
2888
2906
  | `approve(source, delegate, owner, amount)`, `approveChecked(source, mint, delegate, owner, amount)`, `revoke` | the checked forms take the decimals from the mint |
@@ -3296,6 +3314,31 @@ ExtraAccountMetaList).
3296
3314
  - Inside the hook, `isTransferring(source)` says whether Token-2022 is transferring from it.
3297
3315
  - See [`test/fixtures/hook.ts`](https://github.com/typesol-lang/typesol/blob/main/test/fixtures/hook.ts) and the transfer-hook ports.
3298
3316
 
3317
+ ### Calling a transfer hook mint
3318
+
3319
+ A program that moves a hooked mint's tokens by CPI must pass Token-2022 the hook's extra accounts, the validation
3320
+ account and the hook program after the four of TransferChecked. `tokenProgram.transferCheckedWithHook(from, mint, to,
3321
+ authority, amount, hookAccounts, signerSeeds?)` builds that call as Rust's
3322
+ `spl_transfer_hook_interface::onchain::add_extra_accounts_for_execute_cpi` does: `hookAccounts` (`remainingAccounts()`
3323
+ or `rest.slice(a, b)`) must hold the hook program and, when the transfer needs it, the validation account and every
3324
+ extra account, in any order. Each extra account is resolved from the list (a fixed address, a PDA of the hook or of
3325
+ another program from literal, instruction-data, account-key and account-data seeds, or a key read from an account's
3326
+ data), against the execute instruction's accounts (source, mint, destination, authority, the validation account, then
3327
+ the extra accounts already resolved), made read-only where every earlier mention of it is, and never a signer. The
3328
+ refusals are the Rust crates' and their codes: the hook program missing (TransferHookError::IncorrectAccount,
3329
+ 2110272652), an extra account missing (AccountResolutionError::IncorrectAccount, 2724315840; the other
3330
+ AccountResolutionError codes for bad seeds), no list in the validation account (TlvError::TypeNotFound, 1202666432), a
3331
+ malformed one (InvalidAccountData, InvalidArgument, or 1 for a list shorter than its count). Without the validation
3332
+ account among `hookAccounts` only the hook program is added; a mint without a hook gets a plain `transferChecked`.
3333
+
3334
+ ```ts
3335
+ import { type Mint, type Mut, type Signer, type TokenAccount, type TokenInterface, type u64, remainingAccounts } from "typesol";
3336
+
3337
+ export function pay(from: Mut<TokenAccount>, mint: Mint, to: Mut<TokenAccount>, owner: Signer, tokenProgram: TokenInterface, amount: u64): void {
3338
+ tokenProgram.transferCheckedWithHook(from, mint, to, owner, amount, remainingAccounts());
3339
+ }
3340
+ ```
3341
+
3299
3342
  **Next:** [Sysvars, hashes, signatures and oracles](language-chain.md).
3300
3343
 
3301
3344
  <!-- docs/language-chain.md -->
@@ -3383,7 +3426,14 @@ export function commit(c: Mut<Commit>, owner: Pubkey, text: string, n: u64): voi
3383
3426
  themselves. Unlike a check such as `HasOne`, nothing happens when the answer is false: wrap them in
3384
3427
  `require(…, error)`. The compiler refuses a call used as a statement, one that is the
3385
3428
  condition of an `if` with an empty body and no `else` or an empty one, and one whose result is kept in a local the function never
3386
- reads. It does not catch a helper that returns the result and is itself called as a statement.
3429
+ reads. The same goes for a call of a helper that returns such a result: one with a `return` that gives the result of
3430
+ one of the three or of another such helper, directly, combined with `&&`, `||`, `!` or `?:`, or through a local of
3431
+ the helper that nothing but its returns reads (`the result of checkProof is discarded, so nothing is checked: it
3432
+ returns the result of merkleVerify; write require(checkProof(…), error)`). A helper that acts on the result itself
3433
+ (requires it, reads it outside a `return`) is not one. Not caught: a result stored in an account field, a struct or an
3434
+ Option, compared (`=== true`) or passed to another function that ignores it, a helper that branches on the result and
3435
+ returns literals (`if (!ok) { return false; } return true;`), and a helper that returns what a function passed to it
3436
+ returns (a function parameter is not followed).
3387
3437
 
3388
3438
  ```ts
3389
3439
  import { type Account, type Hash, type Init, type InstructionsSysvar, type Mut, type Pubkey, type Signer, type SystemProgram, type u8, type u64, type Vec, keccak256, merkleVerify, require, verifyEd25519, verifySecp256k1 } from "typesol";
@@ -3432,6 +3482,11 @@ export function approved(drop: Account<Drop>, ixs: InstructionsSysvar, who: Pubk
3432
3482
  `is(program, "name")` (that program's instruction by its default Anchor discriminator, sha256("global:<name>"); an
3433
3483
  instruction with its own `@discriminator` is matched with `programId` and `readU64(0)` instead).
3434
3484
  - Every read is bounds-checked (5104).
3485
+ - `processedSiblingInstructionCount()` and `processedSiblingInstruction(i)` (a `TransactionInstruction`, 5104 past
3486
+ the last) read the instructions already processed at this program's stack height, with the
3487
+ `sol_get_processed_sibling_instruction` syscall as Rust's `get_processed_sibling_instruction` reads it: under a
3488
+ caller, the instructions that caller already invoked (index 0 the latest); at the top level, the transaction's
3489
+ earlier instructions. With `stackHeight()`, a program can refuse to run twice under one caller.
3435
3490
  - It is the transaction author's data: require things of the transaction with it (a repay instruction after a flash
3436
3491
  loan), never treat it as proof.
3437
3492
 
@@ -4001,7 +4056,7 @@ void instruction (Phoenix's Borsh `Vec<FIFOOrderId>` of the orders that rested,
4001
4056
 
4002
4057
  <!-- Generated by scripts/language-builtins.ts from lib/typesol.d.ts; do not edit by hand. -->
4003
4058
 
4004
- Every name `"typesol"` exports (216 names, 229 declarations), grouped, with its declaration and the first sentence of its doc
4059
+ Every name `"typesol"` exports (218 names, 231 declarations), grouped, with its declaration and the first sentence of its doc
4005
4060
  comment in `lib/typesol.d.ts`. Each group links to the part of the [language guide](language.md) that explains it;
4006
4061
  your editor shows the full doc comment on hover. Methods of account and program types (`systemProgram.transfer`,
4007
4062
  `acct.create`, …) are described with their types in the guide.
@@ -4345,6 +4400,8 @@ Explained in [Sysvars, hashes, signatures and oracles: Sysvars](language-chain.m
4345
4400
  | `SlotHashesSysvar` | `interface SlotHashesSysvar` | The SlotHashes sysvar (`SysvarS1otHashes…`), read as an account: it is too large for the sysvar syscalls (Anchor's `Sysvar<SlotHashes>` cannot load it either). |
4346
4401
  | `StakeHistorySysvar` | `interface StakeHistorySysvar` | The StakeHistory sysvar (`SysvarStakeHistory…`), read as an account: the cluster's stake per recent epoch (up to 512, newest first), as the Stake program uses it for warmup and cooldown. |
4347
4402
  | `stackHeight` | `function stackHeight(): u64` | How deep in cross-program calls this program runs: 1 when the transaction calls it directly, more when another program invoked it. |
4403
+ | `processedSiblingInstructionCount` | `function processedSiblingInstructionCount(): u64` | How many instructions the caller of this program has already invoked at this program's stack height (its processed siblings), or, when the transaction calls this program directly, how many top-level instructions ran before this one (Rust's `get_processed_sibling_instruction(i)` until it returns None). |
4404
+ | `processedSiblingInstruction` | `function processedSiblingInstruction(index: u64): TransactionInstruction` | Processed sibling instruction `index` (0 the latest), as Rust's `get_processed_sibling_instruction(index)` reads it with the `sol_get_processed_sibling_instruction` syscall: its program id, accounts and data, as a TransactionInstruction. 5104 when there is none at that index. |
4348
4405
 
4349
4406
  ## Hashes, signatures and introspection
4350
4407
 
@@ -4766,7 +4823,13 @@ instruction that takes the bump as an argument (prefer a stored bump:
4766
4823
  constants, arguments or other accounts' keys (`t.ix("initialize", {}, { authority: alice })` derives `counter`). Pass a keypair for an account that
4767
4824
  signs, an address otherwise, and `null` to leave an optional account out.
4768
4825
  - **Arguments as plain values:** bigints or numbers for integers, address strings for Pubkeys, `null` for an empty
4769
- Option, objects for structs (camelCase or snake_case fields), arrays for Vecs.
4826
+ Option, objects for structs (camelCase or snake_case fields), arrays for Vecs, `{ Variant: { field: value } }` for a
4827
+ data enum (a unit enum also as its index or variant name). Every argument and every field of a struct or variant
4828
+ must be given, except an Option, which left out is None. A missing one is an error that names it and lists the
4829
+ instruction's arguments (`set: argument "amount" is missing (it takes amount, cap, frame, shape; …)`,
4830
+ `set(frame).origin.y is missing (Point has x, y; …)`), and so is a key that names no argument or field
4831
+ (`set has no argument "amonut" (it takes amount, cap, frame, shape)`), so a misspelt name is never sent as zeros
4832
+ or as None.
4770
4833
  - **Remaining accounts:** `[{ address, writable?, signer? }]`, where `signer` is the account's `KeyPairSigner` (it then
4771
4834
  signs as a signer account; `writable` defaults to false).
4772
4835
 
@@ -4798,8 +4861,9 @@ looks like one.
4798
4861
  | --- | --- |
4799
4862
  | `t.ok(res)` | the successful result, or throws with the error, its name (`NotAdmin`) and the program's logs |
4800
4863
  | `t.errorCode(res)` | the custom error code of a failed transaction: 6000 + the member's index in your error enum, or a framework code ([errors.md](errors.md)) |
4801
- | `t.account(type, address)` | the account decoded by its IDL type (bigints, address strings), or `null` once closed. TypeSOL fixed layouts come back as their IDL structs: a `FixedString<N>` as `{ len, bytes }`, a `FixedVec<T, N>` as `{ len, items }` (the generated client gives strings and arrays) |
4864
+ | `t.account(type, address)` | the account decoded by its IDL type (bigints, address strings), or `null` once closed. A `FixedString<N>` comes back as a string and a fixed-layout Option as its value or `null`; a `FixedVec<T, N>` as its IDL struct `{ len, items }` (the generated client gives an array) |
4802
4865
  | `t.returned(instruction, res)` | the instruction's return data: an integer, boolean, Pubkey or struct |
4866
+ | `t.events(res)` | the events the transaction emitted, decoded, in order: `[{ name, data }]` ([events](#events)) |
4803
4867
  | `t.balance(address)` | lamports |
4804
4868
  | `t.errorName(code)` | the name of an error code: your program's, TypeSOL's or Anchor's |
4805
4869
  | `t.connection` | `{ rpc, rpcSubscriptions }` answered by this LiteSVM, for the generated client: `counter.sendInstructions(t.connection, alice, [ix])`, `counter.accounts.Counter.fetch(t.connection.rpc, address)`, views, `resolve`, `watch` and `watchEvents` (as on a cluster: `watch` yields when a later transaction changes the account, not at once; `watchEvents` gets transactions sent after it subscribed, failed ones included in the stream and skipped by the client) |
@@ -4820,6 +4884,38 @@ expect(t.errorName(t.errorCode(res))).toBe("TooMuch");
4820
4884
  `t.errorCode` throws when the transaction succeeded or failed without a custom code (a runtime error such as missing
4821
4885
  signatures), so the test fails then too.
4822
4886
 
4887
+ ### Events
4888
+
4889
+ `t.events(res)` decodes the events of a successful transaction (it throws as `t.ok` does when it failed), in the
4890
+ order the program emitted them: `emit`'s `Program data:` log lines and `emitCpi`'s self-CPIs alike, only this
4891
+ program's. Each is `{ name, data }`, the fields as `t.account` gives them (bigints, address strings, a `FixedString`
4892
+ as a string).
4893
+
4894
+ For a program that emits
4895
+
4896
+ ```ts
4897
+ export interface Deposited {
4898
+ owner: Pubkey;
4899
+ amount: u64;
4900
+ memo: string;
4901
+ referrer: Option<Pubkey>;
4902
+ }
4903
+
4904
+ export function deposit(owner: Signer, amount: u64): void {
4905
+ emit<Deposited>({ owner: owner.key, amount, memo: "thanks", referrer: null });
4906
+ }
4907
+ ```
4908
+
4909
+ a test asserts
4910
+
4911
+ ```ts
4912
+ const res = await t.send(alice, t.ix("deposit", { amount: 5n }, { owner: alice }));
4913
+ expect(t.events(res)).toEqual([{ name: "Deposited", data: { owner: alice.address, amount: 5n, memo: "thanks", referrer: null } }]);
4914
+ ```
4915
+
4916
+ Log lines past the runtime's log limit are cut off, and the events in them with them. See [events](language-errors-events.md#events) for
4917
+ what a program can emit.
4918
+
4823
4919
  ## Tokens and time
4824
4920
 
4825
4921
  | Helper | Does |
@@ -4842,8 +4938,8 @@ program you loaded yourself, and `svmConnection(svm)` the RPC pair alone (for an
4842
4938
  program loaded). Transactions sent through it run at once; `getProgramAccounts` (`fetchAll`) sees the accounts those
4843
4939
  transactions named, plus any you `track(...)`.
4844
4940
 
4845
- The module needs `litesvm`, which `typesol init` adds to `devDependencies`. It encodes arguments and decodes accounts
4846
- and return data from the IDL with its own Borsh coder, so Anchor's TypeScript package is not needed.
4941
+ The module needs `litesvm`, which `typesol init` adds to `devDependencies`. It encodes arguments and decodes accounts,
4942
+ return data and events from the IDL with its own Borsh coder, so Anchor's TypeScript package is not needed.
4847
4943
 
4848
4944
  ## Epochs and staking
4849
4945
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typesol/cli",
3
- "version": "0.47.0",
3
+ "version": "0.48.0",
4
4
  "description": "Compile a TypeScript-syntax language directly to Solana SBF programs.",
5
5
  "type": "module",
6
6
  "license": "MIT",