@typesol/cli 0.27.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +3 -1
  3. package/dist/compiler/analyze.d.ts +5 -1
  4. package/dist/compiler/analyze.js +53 -15
  5. package/dist/compiler/emit/alias.d.ts +48 -0
  6. package/dist/compiler/emit/alias.js +166 -0
  7. package/dist/compiler/emit/base.d.ts +1 -0
  8. package/dist/compiler/emit/borsh.js +6 -3
  9. package/dist/compiler/emit/calls.js +23 -4
  10. package/dist/compiler/emit/cpi-core.d.ts +70 -0
  11. package/dist/compiler/emit/cpi-core.js +356 -0
  12. package/dist/compiler/emit/cpi.d.ts +10 -175
  13. package/dist/compiler/emit/cpi.js +71 -2716
  14. package/dist/compiler/emit/create.d.ts +39 -0
  15. package/dist/compiler/emit/create.js +548 -0
  16. package/dist/compiler/emit/function.d.ts +11 -2
  17. package/dist/compiler/emit/function.js +55 -12
  18. package/dist/compiler/emit/metaplex.d.ts +78 -0
  19. package/dist/compiler/emit/metaplex.js +1345 -0
  20. package/dist/compiler/emit/program.js +24 -4
  21. package/dist/compiler/emit/shared.d.ts +5 -1
  22. package/dist/compiler/emit/shared.js +11 -2
  23. package/dist/compiler/emit/statements.d.ts +0 -9
  24. package/dist/compiler/emit/statements.js +2 -53
  25. package/dist/compiler/emit/storage.d.ts +5 -20
  26. package/dist/compiler/emit/storage.js +55 -100
  27. package/dist/compiler/emit/token.d.ts +8 -0
  28. package/dist/compiler/emit/token.js +493 -0
  29. package/dist/compiler/idl.js +1 -1
  30. package/dist/compiler/model.d.ts +12 -2
  31. package/dist/compiler/model.js +7 -1
  32. package/dist/tools/portgen.js +3 -0
  33. package/docs/architecture.md +31 -2
  34. package/docs/audit.md +4 -2
  35. package/docs/case-study-multisig.md +169 -0
  36. package/docs/errors.md +6 -4
  37. package/docs/language.md +22 -6
  38. package/docs/migrate-from-anchor.md +7 -2
  39. package/docs/security-model.md +5 -1
  40. package/lib/typesol.d.ts +51 -7
  41. package/package.json +1 -1
  42. package/runtime/typesol_rt.h +93 -3
package/docs/audit.md CHANGED
@@ -13,8 +13,9 @@ In order of priority. Line counts at 0.25.0.
13
13
  | --- | --- | --- | ---: | --- |
14
14
  | 1 | C runtime | `runtime/typesol_rt.h` | 1,740 | 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
15
  | 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 584 | Which checks each account parameter gets, and their order |
16
- | 1 | Account data, Vecs and assignment | `src/compiler/emit/storage.ts`, `statements.ts`, `base.ts` | 2,296 | 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.ts` | 4,276 | Built-ins, remaining accounts, `invoke` and its account flags, signer seeds, token and Metaplex CPIs, account creation |
16
+ | 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 2,357 | 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` | 3,114 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
18
+ | 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,340 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
18
19
  | 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 1,512 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
19
20
  | 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 2,202 | What the language accepts; constraints and account types as parsed from the source |
20
21
  | 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,211 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
@@ -40,6 +41,7 @@ accepts. Areas where a bug would be most damaging, and where earlier internal re
40
41
  the Vecs that follow, `@layout borsh` accounts.
41
42
  - **Arithmetic**: every operator and cast at every width, compound assignment, `mulDiv`, rent.
42
43
  - **CPIs and signing**: signer-seed arrays (including their reuse across statements), account flags in `invoke`,
44
+ `invokeInstruction` (metas from data, the infos it hands over, `ts_alloc` of the meta array),
43
45
  account creation on pre-funded addresses, closing.
44
46
  - **The runtime's parsing**: instruction data, the serialized accounts, Token-2022 extension data, oracle accounts and
45
47
  the instructions sysvar.
@@ -0,0 +1,169 @@
1
+ # Case study: porting coral-xyz/multisig
2
+
3
+ This page ports a program that holds real authority on mainnet:
4
+ [coral-xyz/multisig](https://github.com/coral-xyz/multisig) (`programs/multisig/src/lib.rs`, Anchor 0.25, Apache-2.0),
5
+ deployed at `msigUdDBsR4zSUYqYEDrc1LcgtmuSDDM7KxpRUXNC6U`. The port is
6
+ [`examples/multisig.ts`](../examples/multisig.ts). Instead of a twin built for the occasion, it is checked against the
7
+ binary that runs on mainnet: [`test/examples/multisig.test.ts`](../test/examples/multisig.test.ts) runs both under the
8
+ same program id and compares every outcome and every account byte. See
9
+ [case-study-escrow.md](case-study-escrow.md) for a token program and [Migrate from Anchor](migrate-from-anchor.md) for
10
+ the general reference.
11
+
12
+ ## The program
13
+
14
+ A multisig executes arbitrary instructions once `threshold` of its owners approve them. Its PDA (`[multisig]`, bump
15
+ `multisig.nonce`) signs the instruction, so it can hold anything a key can: a program's upgrade authority, a mint
16
+ authority, a treasury.
17
+
18
+ - `create_multisig(owners, threshold, nonce)` initializes an account the client allocated in the same transaction.
19
+ - `create_transaction(pid, accs, data)` stores a proposed instruction; the proposer, an owner, approves it.
20
+ - `approve()` adds an owner's approval.
21
+ - `execute_transaction()` runs the stored instruction through a CPI signed by the PDA once enough owners approved.
22
+ - `set_owners(owners)`, `change_threshold(threshold)` and `set_owners_and_change_threshold(...)` change the multisig;
23
+ only its PDA can sign them, so they run as stored transactions the multisig executes on itself.
24
+
25
+ Upstream it is 337 lines of Rust; the port is 183 lines of TypeScript, comments included.
26
+
27
+ ## What it needed
28
+
29
+ The port needed seven features TypeSOL did not have. They are general features now, each with tests of its own
30
+ (`test/language/dynamic-cpi.test.ts`, `constraint.test.ts`, `borsh-vec.test.ts`):
31
+
32
+ | Anchor | TypeSOL | |
33
+ | --- | --- | --- |
34
+ | `invoke_signed(&ix, ctx.remaining_accounts, …)` with `ix` built from account data | `invokeInstruction(programId, metas, data, remainingAccounts(), seeds)` | A CPI decided at run time. Each meta is a struct with `pubkey`, `isSigner`, `isWritable`. The runtime finds each account among the infos by key and checks privileges, as it does for Rust. |
35
+ | `#[account(zero, signer)] multisig: Box<Account<'info, Multisig>>` | `Signed<Zeroed<Multisig>>` of a `/** @layout borsh */` struct | `Zeroed` now takes Borsh structs (they start empty and are written as Borsh on return). `Signed<…>` is Anchor's `signer` constraint (2002). `Zeroed` now reports an already-set discriminator first, with Anchor's 2013. |
36
+ | `seeds = [multisig.key().as_ref()], bump = multisig.nonce` | `Seeds<Signer, ["@multisig"], "@multisig.nonce">` | A bump stored in another account. |
37
+ | `pub owners: Vec<Pubkey>` in an `#[account]` | `owners: Vec<Pubkey>` in a `/** @layout borsh */` struct | Anchor's Vec: any field, held on the heap while the instruction runs, bounded only by the account when it is written back (3004). |
38
+ | `multisig.owners = owners` | the same | A `Vec` argument copied whole into a list in account data. |
39
+ | `#[account(constraint = multisig.owner_set_seqno == transaction.owner_set_seqno)]` | `constraint(multisig, multisig.ownerSetSeqno === transaction.ownerSetSeqno)` | Runs with the account's checks, so a transaction breaking several gets Anchor's code. |
40
+ | `TransactionAccount { pubkey, is_signer, is_writable }` | `interface TransactionAccount { pubkey; isSigner; isWritable }` | `isSigner` / `isWritable` were reserved field names everywhere; now only in structs held in an account, where they would shadow `acct.isSigner`. |
41
+
42
+ ## Side by side
43
+
44
+ The heart of the program, executing an approved transaction:
45
+
46
+ ```rust
47
+ pub fn execute_transaction(ctx: Context<ExecuteTransaction>) -> Result<()> {
48
+ if ctx.accounts.transaction.did_execute {
49
+ return Err(ErrorCode::AlreadyExecuted.into());
50
+ }
51
+ let sig_count = ctx.accounts.transaction.signers.iter().filter(|&did_sign| *did_sign).count() as u64;
52
+ if sig_count < ctx.accounts.multisig.threshold {
53
+ return Err(ErrorCode::NotEnoughSigners.into());
54
+ }
55
+ let mut ix: Instruction = (*ctx.accounts.transaction).deref().into();
56
+ ix.accounts = ix.accounts.iter().map(|acc| {
57
+ let mut acc = acc.clone();
58
+ if &acc.pubkey == ctx.accounts.multisig_signer.key {
59
+ acc.is_signer = true;
60
+ }
61
+ acc
62
+ }).collect();
63
+ let multisig_key = ctx.accounts.multisig.key();
64
+ let seeds = &[multisig_key.as_ref(), &[ctx.accounts.multisig.nonce]];
65
+ let signer = &[&seeds[..]];
66
+ let accounts = ctx.remaining_accounts;
67
+ solana_program::program::invoke_signed(&ix, accounts, signer)?;
68
+ ctx.accounts.transaction.did_execute = true;
69
+ Ok(())
70
+ }
71
+ ```
72
+
73
+ ```ts
74
+ export function executeTransaction(
75
+ multisig: Account<Multisig>,
76
+ multisigSigner: Seeds<AccountInfo, ["@multisig"], "@multisig.nonce">,
77
+ transaction: HasOne<Mut<Transaction>, "multisig">,
78
+ ): void {
79
+ constraint(multisig, multisig.ownerSetSeqno === transaction.ownerSetSeqno);
80
+ require(!transaction.didExecute, ErrorCode.AlreadyExecuted);
81
+ let sigCount = 0n;
82
+ for (const didSign of transaction.signers) if (didSign) sigCount++;
83
+ require(sigCount >= multisig.threshold, ErrorCode.NotEnoughSigners);
84
+ const metas: FixedVec<TransactionAccount, 32> = transaction.accounts.map((acc) => ({
85
+ pubkey: acc.pubkey,
86
+ isSigner: acc.isSigner || acc.pubkey === multisigSigner.key,
87
+ isWritable: acc.isWritable,
88
+ }));
89
+ invokeInstruction(transaction.programId, metas, transaction.data, remainingAccounts(), [multisig.key, multisig.nonce]);
90
+ transaction.didExecute = true;
91
+ }
92
+ ```
93
+
94
+ The `#[derive(Accounts)]` structs become parameter types, and Anchor's `constraint = …` becomes `constraint(…)` at
95
+ the start of the body: it runs with the multisig's checks, raising the same 2003. The error enum keeps its order and
96
+ messages, so the codes stay 6000–6008. Account and instruction names and the Borsh layout are the original's, so
97
+ existing clients and existing accounts work with the port unchanged.
98
+
99
+ ## How it was checked
100
+
101
+ `test/programs/coral_multisig.so` is the program dumped from mainnet on 2026-10-29 (sha256 in
102
+ [`test/programs/SOURCES.md`](../test/programs/SOURCES.md)). The test loads it into one LiteSVM and the port into
103
+ another, both at `msigUdDB…`, then sends each transaction to both. After each one it requires the same outcome (success,
104
+ or the same error down to the code) and the same lamports, owner and data bytes for every account involved.
105
+
106
+ There are 52 transactions:
107
+
108
+ - **The upstream test suite** (`tests/multisig.js`): create a 2-of-3 multisig, propose `set_owners`, approve, and
109
+ execute through the PDA. Then `Assert Unique Owners` (6008).
110
+ - **Every `create_multisig` refusal**: threshold 0 or above the owner count (6007), no owners, the account not signing
111
+ (2002), not rent-exempt (2005), owned by another program (3007), too small for the empty value (3003) or for the
112
+ owners (3004), already initialized (2013).
113
+ - **Proposals, approvals and executions**:
114
+ - a proposer or approver outside the owner set (6000);
115
+ - another multisig's transaction (2001);
116
+ - too few approvals (6002);
117
+ - a wrong PDA (2006);
118
+ - executing twice (6006);
119
+ - a changed owner set invalidating a proposal (2003), also when the proposal belongs to another multisig as well
120
+ (2003 under both: the constraint on `multisig` runs before the transaction's `has_one`);
121
+ - `set_owners` sent directly, which the PDA cannot sign (3010);
122
+ - a Transaction passed as a Multisig (3002);
123
+ - the target program missing from the remaining accounts (the runtime's error).
124
+ - **Self-calls through `execute_transaction`**:
125
+ - `change_threshold`;
126
+ - `set_owners` shrinking the owner set below the threshold, which drops the threshold;
127
+ - `set_owners_and_change_threshold`;
128
+ - a threshold too high, which fails inside the CPI and fails the whole execution with 6007.
129
+ - **A real payout**: the PDA sends 1.5 SOL through a System transfer. A stored meta claiming the recipient signed is
130
+ refused by the runtime under both programs.
131
+ - **An account larger than one transaction can fill**: a multisig with 40 owners in a 2,000-byte account, as the
132
+ original holds it after `set_owners` calls grew the set, proposed to, approved and executed under both.
133
+
134
+ ## Cost
135
+
136
+ These are compute units per transaction, original versus port, from that test. Each `execute` figure includes the
137
+ instruction it runs.
138
+
139
+ | Instruction | Anchor 0.25 (mainnet) | TypeSOL | |
140
+ | --- | ---: | ---: | ---: |
141
+ | `create_multisig` | 3,591 | 560 | −84% |
142
+ | `create_transaction` | 6,591 | 1,125 | −83% |
143
+ | `approve` | 5,515 | 1,175 | −79% |
144
+ | `execute_transaction` → `set_owners` | 15,227 | 4,313 | −72% |
145
+ | `execute_transaction` → `change_threshold` | 14,723 | 3,972 | −73% |
146
+ | `execute_transaction` → `set_owners_and_change_threshold` | 15,129 | 4,273 | −72% |
147
+ | `execute_transaction` → System transfer | 9,961 | 3,358 | −66% |
148
+
149
+ Refusals cost less too. For example, an already-initialized account costs 3,378 against 160, and a missing signature
150
+ 4,229 against 177. The binary is 526,688 bytes on mainnet and 29,984 bytes for the port, 18 times smaller. Deploying it
151
+ needs about 3.5 SOL less rent.
152
+
153
+ The original was built with Anchor 0.25; a rebuild with a current Anchor would cost less than the mainnet figures. The
154
+ escrow case study and the benchmarks compare against Anchor 1.x.
155
+
156
+ ## Where they differ
157
+
158
+ - **Accounts per stored instruction.** The port builds the signed metas in a list of 32 and keeps TypeSOL's default of
159
+ 32 accounts per instruction, so `execute_transaction` hands a stored instruction at most 29 remaining accounts. The
160
+ original takes as many as the runtime allows. `const MAX_ACCOUNTS = …n` (up to 255) and a larger list lift this for a
161
+ multisig that needs it.
162
+ - **Heap.** Both hold a Borsh account's lists on the heap (32 KiB by default) while the instruction runs. The port's
163
+ lists grow by doubling, as Rust's do, so both run out at about the same sizes: far beyond what these accounts hold.
164
+ - **Logs.** Error messages are logged in TypeSOL's words and the original's error names are not logged; codes are the
165
+ same.
166
+
167
+ Earlier versions of this port held its lists in `FixedVec`s with fixed capacities and checked the owner-set sequence
168
+ number in the body, after `has_one`. Both differences are gone: the lists are Anchor's `Vec`, bounded only by the account,
169
+ and `constraint(…)` runs where Anchor runs it.
package/docs/errors.md CHANGED
@@ -7,19 +7,21 @@ Framework errors use Anchor's numbers where Anchor has the same check, so client
7
7
  | 100 / 101 / 102 | instruction data missing / unknown instruction / malformed arguments (InstructionMissing / FallbackNotFound / DidNotDeserialize) |
8
8
  | 2000 | a `Mut<…>` / `Init<…>` account passed read-only (ConstraintMut) |
9
9
  | 2001 | HasOne constraint failed (ConstraintHasOne) |
10
- | 2002 | event authority did not sign (ConstraintSigner) |
10
+ | 2003 | a `constraint(acct, condition)` without its own error failed (ConstraintRaw) |
11
+ | 2002 | a `Signed<…>` account (or the event authority) did not sign (ConstraintSigner) |
11
12
  | 2004 | Owner constraint failed (ConstraintOwner) |
12
13
  | 2005 | Zeroed account is not rent-exempt (ConstraintRentExempt) |
13
14
  | 2006 | PDA seeds mismatch (ConstraintSeeds) |
14
15
  | 2007 | Executable constraint failed (ConstraintExecutable) |
15
16
  | 2009 | not the associated token account (ConstraintAssociated) |
16
17
  | 2012 | not the expected address (ConstraintAddress) |
18
+ | 2013 | a `Zeroed<…>` account whose discriminator is already set (ConstraintZero; checked before its owner, as under Anchor) |
17
19
  | 2014 / 2015 | token account mint / owner mismatch (ConstraintTokenMint / ConstraintTokenOwner) |
18
20
  | 2016 / 2017 / 2018 | mint authority / freeze authority / decimals mismatch (2018: an existing mint `createIfNeeded` found) |
19
21
  | 2021 / 2022 | token account / mint not owned by the token program `TokenOf` / `MintOf` names (ConstraintTokenTokenProgram / ConstraintMintTokenProgram) |
20
22
  | 2024–2039 | an existing mint `createIfNeeded` found lacks a Token-2022 extension it was given, or holds other keys in it: group pointer 2024–2026, group member pointer 2027–2029, metadata pointer 2030–2032, close authority 2033–2034, permanent delegate 2035–2036, transfer hook 2037–2039 (the first code of each: the extension is missing; the next: the authority / address differs) (ConstraintMint…Extension…) |
21
23
  | 2040 | the same account passed in two writable slots (ConstraintDuplicateMutableAccount) |
22
- | 3000 | account already exists / initialized (AccountDiscriminatorAlreadySet) |
24
+ | 3000 | account already exists (AccountDiscriminatorAlreadySet; an `Init` account) |
23
25
  | 3002 | discriminator mismatch (AccountDiscriminatorMismatch) |
24
26
  | 3003 | data too small, not an initialized token account / mint, a read past the end, or a `@layout borsh` account whose bytes are not a valid Borsh value (AccountDidNotDeserialize) |
25
27
  | 3004 | a `@layout borsh` account too small for the value it would now hold (AccountDidNotSerialize) |
@@ -42,7 +44,7 @@ Framework errors use Anchor's numbers where Anchor has the same check, so client
42
44
  | 5110 | out of heap building strings |
43
45
  | 5111 | oracle check failed (unverified, stale, wrong feed, no samples) |
44
46
  | 5112 | data enum is not the variant the code expected |
45
- | 5113 | more than 32 accounts in one instruction |
47
+ | 5113 | more accounts in one instruction (or one CPI) than the program takes: 32, or its `MAX_ACCOUNTS` |
46
48
  | 5114 | a function with a result ended without returning one |
47
49
  | 5115 | an optional account that was left out was used |
48
50
  | 6000+ | your error enums' members, in declaration order (imported files first), then one `RequireFailed<N>` error (code 6000 + N) per distinct `require(cond, "message")` string |
@@ -60,7 +62,7 @@ the order Anchor's generated code runs them, so a transaction gets the same code
60
62
  2. Two writable parameters naming one account (2040).
61
63
  3. The instruction's arguments (102).
62
64
  4. Each account in parameter order, its constraints in Anchor's order: seeds (2006), associated token account (owner
63
- 2015, then address 2009), `has_one` (2001), owner (2004), executable (2007), address (2012), then `TokenOf` /
65
+ 2015, then address 2009), `has_one` (2001), `constraint(…)` (2003 or its error), owner (2004), executable (2007), address (2012), then `TokenOf` /
64
66
  `MintOf` (2015, 2014, 2021 / 2016, 2017, 2022).
65
67
 
66
68
  Where TypeSOL's order differs, only a transaction that breaks two of these checks at once sees it:
package/docs/language.md CHANGED
@@ -25,10 +25,10 @@ The full reference. For a tour, start with the [README](../README.md).
25
25
  | Enums | `export enum Status { Pending, Approved }` — unit variants stored as the Borsh u8 index; `Status.Approved`, `===` |
26
26
  | Options | `best: Option<u64>` (or `u64 \| null`) — `null`, `=== null`, TypeScript narrowing; `===` between options or with a value follows JS (null equals null, empty never equals a value); empty use aborts (5108); `acct?.field` on an optional account and `x.home?.field` on an `Option<struct>` give an Option (empty when the account was left out / the option is empty), `a ?? b` takes b only when a is empty (b runs only then; the result is an Option when b can be null), `x!` is the value or aborts with 5108; `${opt}` prints the value or `null`. Borsh `option` in arguments/events, fixed `{ is_some, value }` in account data |
27
27
  | Vecs | `entries: Vec<Entry>` in account data, any number of them, declared anywhere: they are stored after the fixed-size fields in the order declared (so every other field keeps its offset; the IDL lists that order), and a push, pop or clear moves the Vecs after it (a reference into one of those cannot be used across it). In a `@layout borsh` struct a Vec is the last field (Anchor's order) — `get`, `set`, `push(v, payer)`, `pop()`, `clear()`, `.length`; the account is resized (realloc) and rent topped up by `payer`; `Vec<u64>` arguments are read-only views; `Vec<string>` arguments (Anchor's `Vec<String>`) are views of the instruction data, each checked as UTF-8 on entry (102), and go back out as Borsh through `invoke`; `pop()` of a Vec of structs works as a statement |
28
- | Anchor's account bytes | `/** @layout borsh */` on an account struct stores it as Anchor does (Borsh: a `FixedString<N>` is a String, a `FixedVec<T, N>` a Vec, an `Option` one byte when empty, and the fields after them move), so a TypeSOL program can take over accounts an Anchor program wrote and the IDL lists Anchor's own types. The instruction unpacks it into the usual fixed layout when it starts (bad bytes fail with 3003) and packs it back when it returns (3004 when the account is too small for the new value), so everything else works on it unchanged. Programs invoked from the body (CPIs) see the account's bytes as they were when the instruction started. Costs more compute than the fixed layout (the whole account is read and written each time; see the benchmarks); nested structs and list elements must be fixed-size (FixedString elements allowed). The same struct is Borsh as a whole instruction argument (checked like Borsh deserialization, UTF-8 included), as return data and as an event; as those (not as account data) it may also hold `string` fields and data enums carrying strings, Anchor's `String` and enums in argument structs (account data takes data enums without strings); not inside list or enum arguments, `Zeroed<T>`, `loadAccount` or a growable `Vec<T>` |
29
- | Fixed-capacity lists | `owners: FixedVec<Pubkey, 8>` — any field, any number of them, in nested structs too: a u32 length and room for N elements (always 4 + N × size bytes), the same `get`, `set`, `push(v)`, `pop()`, `clear()`, `.length` and `for … of`; `push` on a full one fails (5104); `acct.owners = fixedVec([a, b])` writes a whole one (unused slots zeroed). In account data, returned structs and events; as an argument (`ids: FixedVec<u64, 8>`) it is a Borsh Vec of at most N elements, read like a `Vec` argument (more fail with 102) |
28
+ | Anchor's account bytes | `/** @layout borsh */` on an account struct stores it as Anchor does (Borsh: a `FixedString<N>` is a String, a `FixedVec<T, N>` or `Vec<T>` a Vec, an `Option` one byte when empty, and the fields after them move), so a TypeSOL program can take over accounts an Anchor program wrote and the IDL lists Anchor's own types. The instruction unpacks it into the usual fixed layout when it starts (bad bytes fail with 3003) and packs it back when it returns (3004 when the account is too small for the new value), so everything else works on it unchanged. A `Vec<T>` field (any position; integers, booleans, Pubkeys, unit enums or fixed-size structs) is Anchor's own: held on the heap while the instruction runs, growing as Rust's Vec does, bounded only by the account when it is written back (3004); its elements move when it grows, so a reference into one cannot outlive a `push` or an assignment. `Init` of such a struct takes its space, `create(payer, seeds, space)`. Programs invoked from the body (CPIs) see the account's bytes as they were when the instruction started. Costs more compute than the fixed layout (the whole account is read and written each time; see the benchmarks); nested structs and list elements must be fixed-size (FixedString elements allowed). The same struct is Borsh as a whole instruction argument (checked like Borsh deserialization, UTF-8 included), as return data and as an event; as those (not as account data) it may also hold `string` fields and data enums carrying strings, Anchor's `String` and enums in argument structs (account data takes data enums without strings); not inside list or enum arguments or `loadAccount`, and a struct holding a `Vec<T>` is account data or a whole argument, not return data or an event |
29
+ | Fixed-capacity lists | `owners: FixedVec<Pubkey, 8>` — any field, any number of them, in nested structs too: a u32 length and room for N elements (always 4 + N × size bytes), the same `get`, `set`, `push(v)`, `pop()`, `clear()`, `.length` and `for … of`; `push` on a full one fails (5104); `acct.owners = fixedVec([a, b])` writes a whole one (unused slots zeroed), and `acct.owners = owners` copies a `Vec` argument (or another list of the same elements) into it, Anchor's `multisig.owners = owners` (more than N fail with 5104). In account data, returned structs and events; as an argument (`ids: FixedVec<u64, 8>`) it is a Borsh Vec of at most N elements, read like a `Vec` argument (more fail with 102) |
30
30
  | Struct arguments | `order: Order`, `ids: FixedArray<u8, 4>`, `orders: Vec<Order>` — fixed layouts, Borsh-identical, validated on entry (bools, enums, option tags, string lengths, enum tags; 102) and read-only. A struct holding a FixedVec that is only ever an argument is read as Anchor sends it (its FixedVec a Borsh Vec, as `@layout borsh`) |
31
- | Remaining accounts | `remainingAccounts()` — `.length`, `.get(i)` → `key`, `owner`, `lamports` (writes check writability), `isSigner`, `isWritable`; `loadAccount<T>` / `loadAccountMut<T>` give checked struct views; pass them to `invoke`, one at a time or spread: `...remainingAccounts()` (each with the flags it was passed with), `...readonly(rest)` / `...writable(rest)` (all with that role), `rest.slice(a, b)` for part of them; a CPI lists at most 32 accounts (5113) |
31
+ | Remaining accounts | `remainingAccounts()` — `.length`, `.get(i)` → `key`, `owner`, `lamports` (writes check writability), `isSigner`, `isWritable`; `loadAccount<T>` / `loadAccountMut<T>` give checked struct views; pass them to `invoke`, one at a time or spread: `...remainingAccounts()` (each with the flags it was passed with), `...readonly(rest)` / `...writable(rest)` (all with that role), `rest.slice(a, b)` for part of them; a CPI lists at most as many accounts as an instruction takes (5113) |
32
32
  | Struct literals | `book.entries.push({ who: who.key, amount, status: Status.Pending, note }, who)` — every field required |
33
33
  | Struct references | `const o = side === Side.Bid ? book.bids.get(i) : book.asks.get(i)` — aliases account data like a JS object reference (no copy); replacing the referenced place (`book.bids.set(i, …)`, `pop()`, `clear()`, `acct.p = …`) while the reference is still used afterwards is a compile error, because JS would keep the old object |
34
34
  | Other programs' accounts | `const pool = loadForeign<Pool>(account, AMM_PROGRAM)` — owner, `account:Pool` discriminator and size checked (3007 / 3002 / 3003); `readData<u64>(account, offset)` for raw little-endian reads (bounds-checked, 3003) |
@@ -66,7 +66,8 @@ The full reference. For a tour, start with the [README](../README.md).
66
66
  | `Account<T>` / `Mut<T>` | owned by this program, 8-byte discriminator matches, data large enough (and writable) |
67
67
  | `Init<T>` | writable; `create(payer, seeds)` derives the PDA, verifies it, funds rent, writes the discriminator (up to 10 KiB); `create(payer, null)` creates a new keypair account that signs the transaction instead (3010 if it did not; a signer in the IDL); a third argument is Anchor's `space = …` (discriminator included, at least 8 + the struct's size) |
68
68
  | `InitIfNeeded<T>` | `const created = acct.createIfNeeded(payer, seeds)` — creates once; afterwards re-derives the PDA and checks owner, discriminator and size (Anchor `init_if_needed`); `acct.pdaBump` after create. An existing account is used as it is: check the fields you rely on |
69
- | `HasOne<A, "owner">`, `Seeds<A, ["vault", "@owner"], "bump">`, `CloseTo<A, "owner">` | declarative constraints like Anchor's `has_one`, `seeds`/`bump` and `close`: checked before the body (2001 / 2006), close runs when the instruction succeeds; `"@name"` = account key or argument bytes, `"@acct.field"` = a Pubkey, integer or unit enum field of a struct account parameter (also the account's own: `["offer", "@maker", "@offer.id"]`), other strings are literals; recorded as `relations` / `pda` in the IDL. `acct.pdaBump` is the bump (Anchor `ctx.bumps.acct`): the stored field when one is named, else the canonical bump the check found — use it to sign as the PDA |
69
+ | `constraint(acct, condition, error?)` | Anchor's `constraint = condition @ error` on `acct`: statements at the very start of the body, run with that account's checks (after its `has_one`, before the next account), so a transaction breaking several checks gets Anchor's code; they read accounts and arguments; the default error is ConstraintRaw (2003) |
70
+ | `HasOne<A, "owner">`, `Seeds<A, ["vault", "@owner"], "bump">`, `CloseTo<A, "owner">` | declarative constraints like Anchor's `has_one`, `seeds`/`bump` and `close`: checked before the body (2001 / 2006), close runs when the instruction succeeds; `"@name"` = account key or argument bytes, `"@acct.field"` = a Pubkey, integer or unit enum field of a struct account parameter (also the account's own: `["offer", "@maker", "@offer.id"]`), other strings are literals; recorded as `relations` / `pda` in the IDL. a bump stored in another struct account is named `"@acct.field"` (Anchor `bump = multisig.nonce`); `acct.pdaBump` is the bump (Anchor `ctx.bumps.acct`): the stored field when one is named, else the canonical bump the check found — use it to sign as the PDA |
70
71
  | `HasOne<TokenAccount, "mint" \| "owner">`, `HasOne<Mint, "mintAuthority" \| "freezeAuthority">` | token constraints (2014 / 2015 / 2016 / 2017) against the parameter with that name; `TokenOf<TokenAccount, "mintParam", "authorityParam", "tokenProgramParam">` / `MintOf<Mint, "authorityParam", "freezeParam", "tokenProgramParam">` name the parameters, as Anchor's `token::mint = …` / `mint::authority = …` / `…::token_program = …` do (`never` leaves one out; the token program one: owned by that token program, 2021 / 2022) |
71
72
  | `Ata<TokenAccount, "owner", "mint">` | the account is the associated token account of those parameters (2009; ATA `pda` in the IDL) |
72
73
  | `Ata<Init<TokenAccount>, "owner", "mint">`, `Ata<InitIfNeeded<TokenAccount>, "owner", "mint">` | Anchor `init` / `init_if_needed` with `associated_token::…`: `acct.create(payer)` creates the ATA (fails if it exists); `const created = acct.createIfNeeded(payer)` creates it only when missing, otherwise checks it is that ATA (2009). Then it is a `TokenAccount` of that mint and owner (2014 / 2015). Needs `AssociatedTokenProgram`, `SystemProgram` and a token program parameter; call it at the top level before using the account |
@@ -77,7 +78,8 @@ The full reference. For a tour, start with the [README](../README.md).
77
78
  | `ProgramData` | this program's ProgramData (address derived from the program id, upgradeable-loader owner and state checked); `upgradeAuthority`, `deploySlot` — gate admin setup on `programData.upgradeAuthority === admin.key` |
78
79
  | `EventAuthority`, `SelfProgram` | Anchor's `["__event_authority"]` PDA, and this program's own address, for `emitCpi` |
79
80
  | `Migrate<From, To>` | Anchor 1.0's `Migration`: an existing `From` account (owner, discriminator, size) rewritten as `To` by `acct.migrate(payer, value)`, a top-level statement the instruction must reach. `acct.from` (read-only) before it, `acct.to` after; the value is built in full before the rewrite, so it may read `acct.from`. Resized to `To` (the payer tops up rent when it grows, at most 10 KiB; shrinking keeps the lamports; growing needs `SystemProgram`). Fixed-layout structs without growable Vecs; no constraints yet; the account cannot be passed to a helper (use `acct.to` fields in the instruction). An account already migrated fails with 3002. Keep the old struct under a new name with its discriminator: `/** @discriminator account:Counter */ interface CounterV1 { … }` |
80
- | `Zeroed<T>` | large accounts (up to 10 MiB) the client allocated with System `CreateAccount`: owned by this program, big enough, rent-exempt, discriminator still zero — then initialized; like Anchor's zero-copy `zero` |
81
+ | `Zeroed<T>` | accounts (up to 10 MiB) the client allocated with System `CreateAccount`, Anchor's `zero`: discriminator still zero (2013, checked first as under Anchor), owned by this program, big enough, rent-exempt — then initialized. A `@layout borsh` struct starts empty and is written as Borsh when the instruction returns |
82
+ | `Signed<A>` | the account must sign the transaction (Anchor's `signer` constraint, 2002), e.g. `Signed<Zeroed<Multisig>>` for an account the client creates with a fresh keypair; the IDL marks it a signer |
81
83
  | `Init<Mint>`, `InitIfNeeded<Mint>` | Anchor `init` / `init_if_needed` with `mint::decimals` / `mint::authority` / `mint::freeze_authority`: `const bump = mint.create(payer, ["mint", payer.key], 6n, authority, freezeAuthority \| null)` creates the mint at that PDA of this program, or with `null` seeds as a new keypair account that signs (3010 if it did not), under the instruction's token program (its only token program parameter, or one passed as the last argument of `create` / `createIfNeeded`; plus `SystemProgram`). Token-2022 extensions (Anchor's `extensions::…`) go after the freeze authority: `mint.create(payer, null, 6n, authority, null, { metadataPointer: { authority, metadataAddress: mint.key }, transferHook: { authority, programId }, closeAuthority, permanentDelegate, nonTransferable: true, defaultAccountState: true, interestBearing: { rateAuthority, rate }, transferFee: { configAuthority, withdrawAuthority, basisPoints, maximumFee }, groupPointer, groupMemberPointer })` sizes the mint for them and initializes each before InitializeMint2. With `createIfNeeded` an existing mint must carry groupPointer / groupMemberPointer / metadataPointer / closeAuthority / permanentDelegate / transferHook with those keys (Anchor's 2024–2039); extensions not listed are not looked at, so an existing mint may carry others (a permanent delegate, say). `createIfNeeded(…)` returns whether it created it; an existing one must be that PDA and have those decimals and authorities (2018 / 2016 / 2017) |
82
84
  | `Init<TokenAccount>`, `InitIfNeeded<TokenAccount>` (no `Ata<…>`) | Anchor `init` / `init_if_needed` with `token::mint` / `token::authority`: `vault.create(payer, ["vault", mint.key], mint, authority)` (the authority may be `vault.key` itself) creates a token account at that PDA (or a keypair account with `null`), sized for the mint's extensions under Token-2022. `createIfNeeded` checks an existing one has that mint and owner (2014 / 2015), not its delegate or close authority (as Anchor) |
83
85
  | `TokenAccount` / `Mut<TokenAccount>` | owned by SPL Token or Token-2022 (extensions allowed, multisig accounts refused), initialized; `mint`, `owner`, `amount`, `delegate`, `delegatedAmount`, `isFrozen`, `isNative`, `closeAuthority`, `tokenProgram` |
@@ -93,7 +95,7 @@ The full reference. For a tour, start with the [README](../README.md).
93
95
  | `AccountInfo` / `Mut<AccountInfo>` | nothing (writable for `Mut`); `owner`, `executable` |
94
96
  | `SystemAccount` / `Mut<SystemAccount>` | owned by the System Program, e.g. a wallet (Anchor `SystemAccount`, 3011) |
95
97
 
96
- Every account exposes `key`, `lamports`, `dataLen`, `isSigner`, `isWritable`. At most 32 accounts per instruction (more is refused, 5113).
98
+ Every account exposes `key`, `lamports`, `dataLen`, `isSigner`, `isWritable`. At most 32 accounts per instruction (more is refused, 5113); `export const MAX_ACCOUNTS = 128n` (up to 255, Anchor takes what the runtime allows) raises it for programs that take many remaining accounts, keeping the CPI scratch lists on the heap instead of the stack (programs that do not declare it compile exactly as before).
97
99
 
98
100
  Two writable parameters can never be the same account: aliasing is refused with error 2040 (also when a remaining
99
101
  account written through `.lamports` or `loadAccountMut` is another account of the instruction). `Dup<Mut<T>>`
@@ -151,6 +153,20 @@ export function payOut(admin: Signer, treasury: Mut<SystemAccount>, recipient: M
151
153
  - `signerSeeds` (with the bump) signs for this program's PDA.
152
154
  - After the call, `returnData<u64>(program)` reads what the callee returned, checking the size and that it came from `program`.
153
155
 
156
+ A call decided at run time, such as one a multisig stored in account data, is `invokeInstruction` (Rust's
157
+ `invoke_signed(&Instruction { program_id, accounts, data }, infos, seeds)`):
158
+
159
+ ```ts
160
+ invokeInstruction(transaction.programId, transaction.accounts, transaction.data, remainingAccounts(), [multisig.key, multisig.nonce]);
161
+ ```
162
+
163
+ - the accounts are a list of structs with `pubkey`, `isSigner` and `isWritable` (a Vec or FixedVec in account data, a
164
+ Vec argument, or a stored `map` result); the data a list of u8.
165
+ - every account in the fourth argument (`remainingAccounts()` or a slice) is handed to the runtime, which finds each
166
+ meta's account there by key: one that is missing fails the call, as under Rust.
167
+ - the runtime checks the privileges: a meta may be a signer or writable only as the transaction passed that account,
168
+ or as a PDA of this program the seeds (fifth argument) sign for. See `examples/multisig.ts`.
169
+
154
170
  Typed calls from an IDL: `typesol cpi other.json --out other_cpi.ts` writes one helper per instruction
155
171
  (`vaultDeposit(program, owner, vault, systemProgram, amount, seeds)`), with the account flags, discriminator and
156
172
  argument encoding taken from the IDL (Anchor 0.30+ / 1.x, or TypeSOL's own). Call it with `signer([...seeds, bump])`
@@ -41,7 +41,7 @@ and error codes. Its notes (on stderr) list what an existing Anchor client would
41
41
  | `close = destination` | `CloseTo<Mut<T>, "destination">`, or `close(acct, destination)` in the body |
42
42
  | `address = ADMIN` | `Address<AccountInfo, "Admin1111…">` |
43
43
  | `owner = program`, `executable` | `Owner<A, "…">`, `Executable<A>` |
44
- | `constraint = expr @ MyError::X` | `require(expr, MyError.X)` at the start of the body |
44
+ | `constraint = expr @ MyError::X` (or without an error: 2003) | `constraint(acct, expr, MyError.X)` (or `constraint(acct, expr)`) at the start of the body: it runs with `acct`'s checks, where Anchor runs it |
45
45
  | `realloc = n, realloc::payer = p` | `realloc(acct, n, p)` |
46
46
  | `Option<Account<'info, T>>` | `Mut<T> \| null` (the client passes the program id to leave it out) |
47
47
  | `UncheckedAccount` / `AccountInfo` | `AccountInfo` / `Mut<AccountInfo>`: check what you rely on yourself |
@@ -49,6 +49,9 @@ and error codes. Its notes (on stderr) list what an existing Anchor client would
49
49
  | `Migration<'info, From, To>` | `Migrate<From, To>`, then `acct.migrate(payer, value)`; the old struct keeps its on-chain discriminator with `/** @discriminator account:<OldName> */` |
50
50
  | `#[account(discriminator = …)]` | `/** @discriminator <preimage or 0x8 bytes> */` on the struct |
51
51
  | `AccountLoader<T>` with `#[account(zero)]` | `Zeroed<T>` (TypeSOL reads every account in place: no copy to avoid) |
52
+ | `Account<T>` with `#[account(zero)]` (Borsh) | `Zeroed<T>` of a `/** @layout borsh */` struct |
53
+ | `#[account(signer)]` on a non-`Signer` account | `Signed<A>`, e.g. `Signed<Zeroed<Multisig>>` |
54
+ | `seeds = [multisig.key().as_ref()], bump = multisig.nonce` | `Seeds<A, ["@multisig"], "@multisig.nonce">` |
52
55
  | `Program<'info, System>` | `SystemProgram` |
53
56
  | `Program<'info, Token>` / `Token2022` / `Interface<'info, TokenInterface>` | `TokenProgram` / `Token2022Program` / `TokenInterface` |
54
57
  | `Account<'info, TokenAccount>` / `Account<'info, Mint>` (`InterfaceAccount`) | `TokenAccount` / `Mint` (`Mut<…>` when written) |
@@ -71,7 +74,7 @@ and error codes. Its notes (on stderr) list what an existing Anchor client would
71
74
  | `u8` … `u128`, `i8` … `i128`, `bool`, `Pubkey` | `u8` … `u128`, `i8` … `i128`, `boolean`, `Pubkey` |
72
75
  | `[T; N]` | `FixedArray<T, N>` |
73
76
  | `String` with `#[max_len(n)]` | `FixedString<N>`: a u32 length and N bytes, always N bytes long |
74
- | `Vec<T>` with `#[max_len(n)]` | `Vec<T>` (any number, declared anywhere, stored after the fixed-size fields; it grows with `push(v, payer)`), or `FixedVec<T, n>`: a u32 length and room for n, always 4 + n × size bytes |
77
+ | `Vec<T>` with `#[max_len(n)]` | `Vec<T>` (any number, declared anywhere, stored after the fixed-size fields; it grows with `push(v, payer)`), or `FixedVec<T, n>`: a u32 length and room for n, always 4 + n × size bytes; in a `@layout borsh` struct, `Vec<T>` is Anchor's own, bounded only by the account |
75
78
  | `Option<T>` | `Option<T>`: fixed size (1 + size of T) |
76
79
  | `#[derive(AnchorSerialize…)] enum` | `export enum` (unit variants) or a data enum `type A = { kind: "X"; … } \| …` |
77
80
 
@@ -108,6 +111,8 @@ Anchor instruction that takes or returns a struct with `String` / `Vec` / `Optio
108
111
  | `system_program::transfer(CpiContext::new(…), lamports)` | `systemProgram.transfer(from, to, lamports)` |
109
112
  | `token::transfer_checked(CpiContext::new_with_signer(…, seeds), amount, decimals)` | `tokenProgram.transferChecked(from, mint, to, authority, amount, ["seed", key, bump])` |
110
113
  | `invoke_signed(&ix, &accounts, &[seeds])` | `invoke(program, [writable(a), readonly(b)], [data…], seeds)` |
114
+ | `invoke_signed(&Instruction { program_id, accounts, data }, ctx.remaining_accounts, …)` built at run time | `invokeInstruction(programId, metas, data, remainingAccounts(), seeds)` |
115
+ | `multisig.owners = owners` (a `Vec` argument into account data) | the same |
111
116
  | `declare_program!(other)` / CPI to another Anchor program | `typesol cpi other.json` generates typed helpers |
112
117
  | `for x in v.iter()` | `for (const x of v)` |
113
118
  | `v.iter().any(\|x\| …)`, `.all`, `.position`, `.find`, `.fold(init, …)`, `.contains(&x)` | `v.some((x) => …)`, `every`, `findIndex`, `find`, `reduce((acc, x) => …, init)`, `includes(x)` |
@@ -24,7 +24,7 @@ Each holds for every instruction of every program the compiler accepts. A break
24
24
 
25
25
  ### Before the body runs
26
26
 
27
- 1. **Account count.** Fewer accounts than parameters fail (3005); more than 32 in total fail before parsing (5113).
27
+ 1. **Account count.** Fewer accounts than parameters fail (3005); more than the program takes (32, or its `MAX_ACCOUNTS`) fail before parsing (5113).
28
28
  2. **Account types.** Each parameter is checked for what its type says: `Signer` signed (3010); `Mut<…>` writable
29
29
  (2000); a program account (`Account<T>`, `Mut<T>`) owned by this program (3007), initialized (3012), with `T`'s
30
30
  discriminator (3002) and at least its size (3003); `TokenAccount` / `Mint` owned by SPL Token or Token-2022 and an
@@ -65,6 +65,10 @@ Each holds for every instruction of every program the compiler accepts. A break
65
65
  12. **CPIs.** A program signs only for its own PDAs (the runtime enforces it; the seeds are those written in the
66
66
  source). `invoke` marks an account writable or signer only when the parameter is `Mut` / `Signer` or the program
67
67
  signs for it; remaining accounts keep the flags they were passed with, or are checked for the role requested.
68
+ `invokeInstruction` is the exception by design: its program, account flags and data come from values (stored in
69
+ account data or passed in), so the compiler cannot check them; the runtime does, refusing any account the
70
+ transaction did not pass that way and any signer the program's seeds do not cover. Only programs that store
71
+ instructions to run (a multisig, a DAO) need it; review who can write those values.
68
72
  Return data is read only from the program named, at the expected size (5106).
69
73
  13. **Events.** `emitCpi` is accepted only from this program's event-authority PDA, signed (2002).
70
74
 
package/lib/typesol.d.ts CHANGED
@@ -97,15 +97,20 @@ export type Option<T> = T | null;
97
97
  /**
98
98
  * A growable list. As an account struct field it is stored Borsh-style (u32 length + elements) and the account is
99
99
  * resized as it grows. An account may have any number of them, declared anywhere: they are stored after the
100
- * fixed-size fields, in the order declared (in a `@layout borsh` struct, a Vec must be the last field). As an
101
- * instruction argument it is a read-only view.
100
+ * fixed-size fields, in the order declared. In a `@layout borsh` struct it is Anchor's `Vec<T>`: anywhere among the
101
+ * fields, held on the heap while the instruction runs, and bounded only by the account when it is written back
102
+ * (3004). As an instruction argument it is a read-only view.
102
103
  */
103
104
  export interface Vec<T> extends ListMethods<T> {
104
105
  readonly length: u64;
105
106
  get(index: bigint): T;
106
107
  set(index: bigint, value: T): void;
107
- /** Append, growing the account by one element; `payer` tops up rent when needed. */
108
- push(value: T, payer: Mut<Signer>): void;
108
+ /**
109
+ * Append. In account data the account grows by one element and `payer` (required there) tops up rent; in a
110
+ * `@layout borsh` struct the list grows on the heap and takes no payer (the account must hold it when it is written
111
+ * back: 3004, as under Anchor).
112
+ */
113
+ push(value: T, payer?: Mut<Signer>): void;
109
114
  /** Remove and return the last element, shrinking the account. */
110
115
  pop(): T;
111
116
  /** Remove every element, shrinking the account. */
@@ -636,6 +641,11 @@ export type MintOf<A, AuthorityParam extends string, FreezeAuthorityParam extend
636
641
  * what you need before writing. Not for accounts that are created, closed, a close destination or `@layout borsh`.
637
642
  */
638
643
  export type Dup<A> = A & { readonly __dup?: true };
644
+ /**
645
+ * The account must sign the transaction (Anchor's `signer` constraint on an account that is not a `Signer`; 2002), e.g.
646
+ * `Signed<Zeroed<Multisig>>` for an account the client creates with a fresh keypair in the same transaction.
647
+ */
648
+ export type Signed<A> = A & { readonly __signed?: true };
639
649
  /**
640
650
  * Anchor 1.0's `Migration<From, To>`: an existing `From` account (owner, discriminator and size checked) that this
641
651
  * instruction rewrites as `To` with `acct.migrate(payer, value)`, a top-level statement every path must reach. Read
@@ -1379,9 +1389,10 @@ export type Init<T> = T extends TokenAccount
1379
1389
  };
1380
1390
 
1381
1391
  /**
1382
- * A large account (over 10 KiB, up to 10 MiB) the client already allocated with System CreateAccount,
1383
- * owned by this program and still zeroed. Owner, size, rent exemption and emptiness are checked, then
1384
- * the discriminator is written: from here on it is a `Mut<T>`. Same idea as Anchor's zero-copy `zero`.
1392
+ * An account the client already allocated with System CreateAccount (any size up to 10 MiB; over 10 KiB a program
1393
+ * cannot create it itself), owned by this program and still zeroed: Anchor's `zero`. Emptiness (2013), owner, size and
1394
+ * rent exemption are checked, then the discriminator is written: from here on it is a `Mut<T>`. A `@layout borsh`
1395
+ * struct starts empty (lists and strings empty, Options None) and is written as Borsh when the instruction returns.
1385
1396
  */
1386
1397
  export type Zeroed<T> = T & AccountMeta;
1387
1398
 
@@ -1610,6 +1621,32 @@ export declare function invoke(
1610
1621
  signerSeeds?: Seed[] | SignerSeeds,
1611
1622
  ): void;
1612
1623
 
1624
+ /** One account of an instruction built at run time (Rust's `AccountMeta`): any struct with these three fields. */
1625
+ export interface InstructionAccountMeta {
1626
+ readonly pubkey: Pubkey;
1627
+ readonly isSigner: boolean;
1628
+ readonly isWritable: boolean;
1629
+ }
1630
+ /** A list read by index: a Vec or FixedVec in account data, a Vec argument, or a stored local list. */
1631
+ export interface IndexedList<T> {
1632
+ readonly length: u64;
1633
+ get(index: bigint): T;
1634
+ }
1635
+ /**
1636
+ * A CPI decided at run time, e.g. one stored in account data (Rust's `invoke_signed(&Instruction { program_id,
1637
+ * accounts, data }, infos, seeds)`). Every account in `infos` (`remainingAccounts()` or a slice of it) is handed to the
1638
+ * runtime, which finds each meta's account there by key: one that is missing fails the CPI, as under Rust. A meta may
1639
+ * be a signer or writable only as the transaction passed that account, or as a PDA of this program `signerSeeds` sign
1640
+ * for (`signer([multisig.key, multisig.nonce])`).
1641
+ */
1642
+ export declare function invokeInstruction(
1643
+ programId: Pubkey,
1644
+ accounts: IndexedList<InstructionAccountMeta>,
1645
+ data: IndexedList<u8>,
1646
+ infos: RemainingAccounts | RemainingSlice,
1647
+ signerSeeds?: Seed[] | SignerSeeds,
1648
+ ): void;
1649
+
1613
1650
  /**
1614
1651
  * Anchor's own error codes (anchor-lang `ErrorCode`): `require(condition, AnchorError.AccountDidNotDeserialize)` fails
1615
1652
  * with that code, as `require!(condition, ErrorCode::AccountDidNotDeserialize)` does. Not listed in the IDL's errors.
@@ -1699,6 +1736,13 @@ export declare enum AnchorError {
1699
1736
  * 6000 + N, numbered after the program's error enums and listed in the IDL.
1700
1737
  */
1701
1738
  export declare function require(condition: boolean, error: string | AnchorError): asserts condition;
1739
+ /**
1740
+ * Anchor's `constraint = condition @ error` on `account`. Written at the start of an instruction's body (before any
1741
+ * other statement), it runs with that account's checks, after its has_one and before its owner check, so a transaction
1742
+ * that breaks several checks fails with the same code as under Anchor. It may read every account and argument. The
1743
+ * default error is `AnchorError.ConstraintRaw` (2003); `error` is an error-enum member, an `AnchorError` or a string.
1744
+ */
1745
+ export declare function constraint(account: AccountMeta | RemainingAccount | null, condition: boolean, error?: string | AnchorError): void;
1702
1746
 
1703
1747
  /** Write a string, integer or pubkey to the program log. */
1704
1748
  export declare function log(value: string | bigint | Pubkey | Hash): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typesol/cli",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "description": "Compile a TypeScript-syntax language directly to Solana SBF programs.",
5
5
  "type": "module",
6
6
  "license": "MIT",