@typesol/cli 0.44.1 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +343 -0
- package/NOTICE +14 -1
- package/README.md +115 -26
- package/SECURITY.md +10 -8
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +9 -0
- package/dist/cli.js +226 -62
- package/dist/compiler/analyze.js +57 -6
- package/dist/compiler/diagnostics.d.ts +4 -3
- package/dist/compiler/diagnostics.js +10 -6
- package/dist/compiler/emit/base.d.ts +1 -1
- package/dist/compiler/emit/calls.js +18 -5
- package/dist/compiler/emit/cpi-core.d.ts +3 -1
- package/dist/compiler/emit/cpi-core.js +8 -4
- package/dist/compiler/emit/expressions.d.ts +14 -0
- package/dist/compiler/emit/expressions.js +52 -4
- package/dist/compiler/emit/shared.d.ts +8 -1
- package/dist/compiler/emit/shared.js +8 -1
- package/dist/compiler/emit/statements.d.ts +8 -3
- package/dist/compiler/emit/statements.js +68 -3
- package/dist/compiler/emit/storage.js +5 -1
- package/dist/compiler/hints.d.ts +7 -0
- package/dist/compiler/hints.js +58 -9
- package/dist/compiler/index.d.ts +56 -1
- package/dist/compiler/index.js +27 -3
- package/dist/compiler/model.js +3 -2
- package/dist/compiler/toolchain.d.ts +73 -2
- package/dist/compiler/toolchain.js +222 -17
- package/dist/node-version.d.ts +4 -0
- package/dist/node-version.js +12 -0
- package/dist/tools/docker.d.ts +183 -0
- package/dist/tools/docker.js +442 -0
- package/dist/tools/doctor.d.ts +44 -0
- package/dist/tools/doctor.js +108 -14
- package/dist/workspace.d.ts +11 -3
- package/dist/workspace.js +46 -9
- package/docker/Dockerfile +163 -0
- package/docker/deps/0.43.0.lock.json +1206 -0
- package/docker/deps/0.44.0.lock.json +1206 -0
- package/docker/deps/0.44.1.lock.json +1206 -0
- package/docker/deps/0.45.0.lock.json +1206 -0
- package/docker/deps/0.46.0.lock.json +1206 -0
- package/docs/ai.md +2 -1
- package/docs/architecture.md +18 -6
- package/docs/audit.md +15 -7
- package/docs/case-study-phoenix.md +1 -1
- package/docs/case-study-raydium-amm.md +1 -1
- package/docs/case-study-spl-stake-pool.md +1 -1
- package/docs/cli.md +71 -6
- package/docs/errors.md +22 -8
- package/docs/glossary.md +210 -0
- package/docs/language-accounts.md +499 -0
- package/docs/language-basics.md +389 -0
- package/docs/language-builtins.md +411 -0
- package/docs/language-chain.md +198 -0
- package/docs/language-cpi.md +470 -0
- package/docs/language-errors-events.md +184 -0
- package/docs/language-native.md +493 -0
- package/docs/language-pdas.md +198 -0
- package/docs/language-statements.md +620 -0
- package/docs/language-types.md +601 -0
- package/docs/language.md +190 -467
- package/docs/mainnet.md +103 -8
- package/docs/migrate-from-anchor.md +7 -6
- package/docs/security-model.md +4 -4
- package/docs/stability.md +64 -3
- package/docs/test-your-program.md +52 -15
- package/docs/testing.md +49 -2
- package/docs/troubleshooting.md +210 -42
- package/lib/typesol.d.ts +67 -22
- package/llms-full.txt +5084 -591
- package/llms.txt +12 -1
- package/package.json +4 -2
- package/releases/0.43.0.json +669 -0
- package/releases/0.44.0.json +672 -0
- package/releases/0.44.1.json +672 -0
- package/releases/0.45.0.json +732 -0
- package/runtime/LICENSE-compiler-builtins.txt +275 -0
- package/runtime/typesol_builtins.c +484 -0
- package/ts-plugin/index.js +16 -5
package/docs/language.md
CHANGED
|
@@ -1,476 +1,199 @@
|
|
|
1
1
|
# The TypeSOL language
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeSOL is a subset of TypeScript that compiles to Solana programs. A program is a `.ts` file: its exported functions
|
|
4
|
+
are instructions, its exported interfaces are account data, and its parameter types say which accounts are checked and
|
|
5
|
+
how. The TypeScript compiler type-checks it against `lib/typesol.d.ts`; TypeSOL then refuses what is outside the
|
|
6
|
+
language, lowers the rest to C and builds an SBF program with clang, and writes an Anchor-compatible IDL and a typed
|
|
7
|
+
client. Nothing runs on chain but the compiled code.
|
|
8
|
+
|
|
9
|
+
What differs from TypeScript, in short:
|
|
10
|
+
|
|
11
|
+
- Integers are bigints of a declared width (`u8` … `u128`, `i8` … `i128`, `1n` literals), and every arithmetic
|
|
12
|
+
operation is checked. There is no `number` and no floating point.
|
|
13
|
+
- Everything comes from `"typesol"`: no Node.js, no npm packages, no `console`, no `Math`.
|
|
14
|
+
- No `class`, `async`, `throw` or `try`: a failed `require` (or check, or overflow) ends the instruction and fails the
|
|
15
|
+
whole transaction, whose changes the runtime discards.
|
|
16
|
+
- Every type's layout is known when the program compiles. Locals and struct fields have a fixed size: strings in
|
|
17
|
+
accounts are `FixedString<N>`, lists are `FixedArray` or `FixedVec`. What varies in length is a `string` or `Vec`
|
|
18
|
+
argument (read in place from the instruction data), a `Vec` field (the account grows) and a string built at run time
|
|
19
|
+
(on the heap). There are no dynamic objects.
|
|
20
|
+
|
|
21
|
+
For a tour, start with the [README](../README.md); to port an Anchor program, [migrate from
|
|
22
|
+
Anchor](migrate-from-anchor.md). New to Solana? [Language basics](language-basics.md#solana-in-a-dozen-lines) starts
|
|
23
|
+
with the terms the guide uses.
|
|
24
|
+
|
|
25
|
+
## The guide
|
|
26
|
+
|
|
27
|
+
Read in order, or jump to what you need. Every example on these pages is a complete program that compiles, unless it
|
|
28
|
+
is marked as a fragment.
|
|
29
|
+
|
|
30
|
+
An example shows the construct its section is about. Unless the text says who may call an instruction, the example
|
|
31
|
+
does not check its caller, as a real program must: see [constraints](language-accounts.md#constraints) and
|
|
32
|
+
[signing as a PDA](language-pdas.md#signing-as-a-pda).
|
|
33
|
+
|
|
34
|
+
| Page | What it covers |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| [Language basics](language-basics.md) | Solana in a dozen lines, then what a program is: the file, imports, instructions, account data, helpers, constants, multiple files, what the compiler derives, stack and heap, limits and costs (rent, compute, transaction and account sizes) |
|
|
37
|
+
| [Types](language-types.md) | integers and checked arithmetic, casts, `u256`, booleans, `Pubkey`, strings, enums, data enums, structs, `Option`, lists, `f64`, heap values, with their bytes and limits |
|
|
38
|
+
| [Statements and functions](language-statements.md) | which TypeScript is TypeSOL: declarations, copies and references, control flow, destructuring, helpers, `Inout<T>`, closures, generics, and what is refused |
|
|
39
|
+
| [Accounts](language-accounts.md) | account parameters and the checks they emit, creating, closing and resizing accounts, constraints, optional accounts, account groups, remaining accounts, account layouts |
|
|
40
|
+
| [PDAs](language-pdas.md) | seeds, bumps, `Seeds<…>`, `requirePda`, deriving addresses, signing as a PDA, PDAs in the IDL |
|
|
41
|
+
| [Errors, logs, events and return values](language-errors-events.md) | `require`, error enums and codes, `log`, `emit`, `emitCpi`, return values |
|
|
42
|
+
| [Calling other programs](language-cpi.md) | the System, Token, Token-2022, Associated Token, Memo, Metaplex and Stake programs, typed calls from an IDL, `invoke`, `invokeInstruction`, transfer hooks |
|
|
43
|
+
| [Sysvars, hashes, signatures and oracles](language-chain.md) | the clock and other sysvars, hashing, signature checks, instruction introspection, Pyth, Switchboard, randomness |
|
|
44
|
+
| [Porting a native program](language-native.md) | advanced: the `@fallback` entry, raw account views, Borsh accounts, `BigVec`, the red-black tree, byte builders, Rust's panics and log lines |
|
|
45
|
+
| [Built-ins](language-builtins.md) | every name `"typesol"` exports, one line each, generated from `lib/typesol.d.ts` |
|
|
46
|
+
| [Glossary](glossary.md) | the Solana and TypeSOL terms the guide uses: account, owner, rent, PDA, CPI, IDL, compute units, … |
|
|
47
|
+
|
|
48
|
+
Then: [test your program](test-your-program.md) in LiteSVM, call it from [the generated client](client.md),
|
|
49
|
+
[deploy it](mainnet.md), and when something fails, [troubleshooting](troubleshooting.md).
|
|
50
|
+
|
|
51
|
+
The error codes are in [errors.md](errors.md); what a compiled program checks for you and what is left to you, in the
|
|
52
|
+
[security model](security-model.md).
|
|
53
|
+
|
|
54
|
+
## Not supported yet
|
|
55
|
+
|
|
56
|
+
- A struct holding a FixedVec that is both an argument and account data (its bytes differ there, and the IDL describes
|
|
57
|
+
a type one way): declare one for each.
|
|
58
|
+
- Growing an account by more than 10 KiB in one instruction (Solana's limit): realloc again in the next instruction.
|
|
59
|
+
- `?.` and `!` on anything but optional accounts, Options and a `find` on struct elements.
|
|
60
|
+
- Functions stored in a struct, chosen from a list by index, or returned from an instruction.
|
|
61
|
+
- A fused `map` to strings: store it, annotated.
|
|
62
|
+
- Floating point (by design).
|
|
63
|
+
|
|
64
|
+
They are rejected at compile time rather than half-supported.
|
|
65
|
+
|
|
66
|
+
## Index of the former sections
|
|
67
|
+
|
|
68
|
+
Where each part of the language is described, under the headings this page used to have.
|
|
4
69
|
|
|
5
|
-
|
|
70
|
+
### Types and statements
|
|
6
71
|
|
|
7
|
-
|
|
|
72
|
+
| Topic | Where |
|
|
8
73
|
| --- | --- |
|
|
9
|
-
|
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
|
71
|
-
| Docs | JSDoc on instructions, `@param`, structs, fields and data enums becomes `docs` in the IDL |
|
|
72
|
-
| Metaplex Core | `core: MplCoreProgram` — `createCollection`, `createAsset` (in a collection, PDA authorities via signerSeeds), `transferAsset`, `burnAsset` (`null` leaves an optional account out); plugins as a literal list after the uri (`[{ kind: "Royalties", basisPoints: 500n, creators: [{ address, percentage: 100n }] }, { kind: "PermanentFreezeDelegate", frozen: false, authority: studio.key }]`), and `addPlugin` / `updatePlugin` / `removePlugin(…, "FreezeDelegate")` with their `…CollectionPlugin` forms. Plugins: Royalties (with an optional `ruleSet: { programAllowList \| programDenyList: [...] }`), FreezeDelegate, BurnDelegate, TransferDelegate, UpdateDelegate, PermanentFreezeDelegate, Attributes, PermanentTransferDelegate, PermanentBurnDelegate, Edition, MasterEdition (collections: `maxSupply?`, `name?`, `uri?`), AddBlocker, ImmutableMetadata, VerifiedCreators, Autograph, BubblegumV2, FreezeExecute, PermanentFreezeExecute (Groups is kept by Core's group instructions); `authority` is `"owner"`, `"updateAuthority"`, `"none"` or a Pubkey; `coreAssetOwner(asset)`, `coreAssetCollection(asset)`. External plugin adapters: `addExternalPlugin` / `removeExternalPlugin` / `writeExternalPluginData` (and the Collection forms) with `{ kind: "AppData", dataAuthority, schema? }`, `{ kind: "Oracle", baseAddress, checks: [{ event: "transfer", canReject: true }], resultsOffset?, baseAddressConfig? }`, `{ kind: "LifecycleHook", hookedProgram, checks, extraAccounts?, dataAuthority?, schema? }` and the Linked forms; a key names one (`{ kind: "AppData", dataAuthority }`, `{ kind: "Oracle", address }`); data is a string, a `Vec<u8>` argument or `null` (Core currently answers lifecycle hooks with NotAvailable, 23) |
|
|
73
|
-
| Compressed NFTs | `bubblegum: BubblegumProgram` — V1 (trees on SPL Account Compression): `createTree`, `mint` (MintV1, no collection/creators), `mintToCollection` (MintToCollectionV1: into a verified Token Metadata collection), `transfer`, `burn`, `delegate` (the leaf owner or delegate signs; a PDA owner signs with the seeds). V2 (trees on mpl-account-compression with mpl-noop): `createTreeV2`, `mintV2(…, { name, symbol, uri, sellerFeeBasisPoints, creators?, isMutable? }, { collection, authority, cpiSigner }?)` (into a Core collection that has the `BubblegumV2` plugin), `transferV2`, `burnV2`, `delegateV2`, `freezeV2` / `thawV2`, `setNonTransferableV2`, `updateMetadataV2(…, currentMetadata, { name?, symbol?, uri?, creators?, … })`, `verifyCreatorV2` / `unverifyCreatorV2`, `setCollectionV2`. Each takes the leaf (`{ root, dataHash, creatorHash, assetDataHash?, flags?, nonce, index }`, or `{ root, assetDataHash?, flags?, nonce, index }` with the leaf's current metadata for the metadata instructions) and its proof as `remainingAccounts()` / `rest.slice(a)` |
|
|
74
|
-
|
|
75
|
-
## Account parameters and the checks they emit
|
|
76
|
-
|
|
77
|
-
| Parameter type | Checked before your code runs |
|
|
74
|
+
| instructions: exported functions, parameters, results | [Basics: Instructions](language-basics.md#instructions) |
|
|
75
|
+
| account data: exported interfaces, nesting | [Basics: Account data](language-basics.md#account-data) |
|
|
76
|
+
| integers, literals, checked operators, `++` `+=` … | [Types: Integers](language-types.md#integers) |
|
|
77
|
+
| `mulDiv`, `mulDivCeil`, `isqrt`, `min`, `max` | [Types: Integer helpers](language-types.md#integer-helpers) |
|
|
78
|
+
| casts (`u8(x)` …) | [Types: Casts](language-types.md#casts) |
|
|
79
|
+
| `u256` | [Types: u256](language-types.md#u256) |
|
|
80
|
+
| `boolean` | [Types: Booleans](language-types.md#booleans) |
|
|
81
|
+
| `Pubkey`, `Hash`, `pubkey("…")` constants | [Types: Pubkey and Hash](language-types.md#pubkey-and-hash) |
|
|
82
|
+
| `string`, `FixedString<N>` | [Types: Strings](language-types.md#strings) |
|
|
83
|
+
| strings built at run time, templates | [Types: Strings built at run time](language-types.md#strings-built-at-run-time) |
|
|
84
|
+
| unit enums | [Types: Enums](language-types.md#enums) |
|
|
85
|
+
| data enums | [Types: Data enums](language-types.md#data-enums) |
|
|
86
|
+
| structs, struct literals, struct values | [Types: Structs](language-types.md#structs) |
|
|
87
|
+
| file-local structs | [Types: File-local structs](language-types.md#file-local-structs) |
|
|
88
|
+
| struct, list and Option arguments | [Types: Struct arguments](language-types.md#struct-arguments) |
|
|
89
|
+
| `Option`, `??`, `?.`, `!`, options of structs and arrays | [Types: Option](language-types.md#option) |
|
|
90
|
+
| `FixedArray`, `fixedArray` locals | [Types: FixedArray](language-types.md#fixedarray) |
|
|
91
|
+
| `FixedVec`, local lists, `pushAll` | [Types: FixedVec](language-types.md#fixedvec) |
|
|
92
|
+
| `Vec` in account data and as arguments | [Types: Vec](language-types.md#vec) |
|
|
93
|
+
| list callbacks (`map`, `filter`, `find`, …) | [Types: List methods](language-types.md#list-methods) |
|
|
94
|
+
| `f64` | [Types: f64](language-types.md#f64) |
|
|
95
|
+
| the heap, `@heap`, `HEAP_SIZE_KIB` | [Types: Heap values](language-types.md#heap-values), [Basics: Memory](language-basics.md#memory-stack-and-heap) |
|
|
96
|
+
| `const` and `let`, copies and references | [Statements: Declarations](language-statements.md#declarations), [Copies and references](language-statements.md#copies-and-references) |
|
|
97
|
+
| destructuring | [Statements: Destructuring](language-statements.md#destructuring) |
|
|
98
|
+
| ternaries, evaluation order | [Statements: Expressions](language-statements.md#expressions) |
|
|
99
|
+
| loops | [Statements: Loops](language-statements.md#loops) |
|
|
100
|
+
| `switch` | [Statements: switch](language-statements.md#switch) |
|
|
101
|
+
| helpers, how arguments are passed, `@noinline` | [Statements: Helpers](language-statements.md#helpers) |
|
|
102
|
+
| `Inout<T>` parameters | [Statements: Inout parameters](language-statements.md#inout-parameters) |
|
|
103
|
+
| arrow functions and closures, functions as values | [Statements: Arrow functions and closures](language-statements.md#arrow-functions-and-closures) |
|
|
104
|
+
| functions as arguments | [Statements: Functions as arguments](language-statements.md#functions-as-arguments) |
|
|
105
|
+
| generic helpers | [Statements: Generic helpers](language-statements.md#generic-helpers) |
|
|
106
|
+
| top-level constants | [Basics: Constants](language-basics.md#constants) |
|
|
107
|
+
| type aliases | [Basics: Type aliases](language-basics.md#type-aliases) |
|
|
108
|
+
| multiple files | [Basics: Multiple files](language-basics.md#multiple-files) |
|
|
109
|
+
| JSDoc in the IDL | [Basics: What the compiler derives](language-basics.md#what-the-compiler-derives) |
|
|
110
|
+
| errors, `require`, error codes | [Errors: require](language-errors-events.md#require), [Error enums](language-errors-events.md#error-enums) |
|
|
111
|
+
| `log` | [Errors: log](language-errors-events.md#log) |
|
|
112
|
+
| `emit`, events | [Errors: Events](language-errors-events.md#events) |
|
|
113
|
+
| `emitCpi` | [Errors: Events through CPI](language-errors-events.md#events-through-cpi) |
|
|
114
|
+
| `@layout borsh` (Anchor's account bytes) | [Accounts: @layout borsh](language-accounts.md#anchors-account-bytes-layout-borsh) |
|
|
115
|
+
| `@repr`, `@serialization bytemuck` | [Accounts: Zero-copy types](language-accounts.md#zero-copy-types-as-anchors-idl-describes-them) |
|
|
116
|
+
| `@bytes`, `@idlName`, `key_` | [Accounts: Field names and bytes for the IDL](language-accounts.md#field-names-and-bytes-for-the-idl) |
|
|
117
|
+
| accounts created by hand, `initAccount` | [Accounts: Accounts created by hand](language-accounts.md#accounts-created-by-hand) |
|
|
118
|
+
| remaining accounts, `loadAccount` | [Accounts: Remaining accounts](language-accounts.md#remaining-accounts) |
|
|
119
|
+
| other programs' accounts, `readData`, `writeData` | [Accounts: Other programs' accounts](language-accounts.md#other-programs-accounts) |
|
|
120
|
+
| `realloc`, `resizeAccount` | [Accounts: Closing and resizing](language-accounts.md#closing-and-resizing) |
|
|
121
|
+
| sysvars | [Chain: Sysvars](language-chain.md#sysvars) |
|
|
122
|
+
| hashing, signatures, `findProgramAddress` | [Chain: Hashing](language-chain.md#hashing), [Signatures](language-chain.md#signatures), [PDAs: Deriving addresses](language-pdas.md#deriving-addresses-in-the-body) |
|
|
123
|
+
| oracles | [Chain: Oracles](language-chain.md#oracles) |
|
|
124
|
+
| randomness | [Chain: Randomness](language-chain.md#randomness) |
|
|
125
|
+
| Token-2022 extension reads | [CPI: Token-2022 extension reads](language-cpi.md#token-2022-extension-reads) |
|
|
126
|
+
| Metaplex Core | [CPI: Metaplex Core](language-cpi.md#metaplex-core) |
|
|
127
|
+
| compressed NFTs | [CPI: Compressed NFTs](language-cpi.md#compressed-nfts-bubblegum) |
|
|
128
|
+
| native Borsh accounts (`loadBorsh`) | [Native: Borsh accounts](language-native.md#borsh-accounts) |
|
|
129
|
+
| `BigVec` | [Native: BigVec](language-native.md#lists-over-the-rest-of-an-account-bigvec) |
|
|
130
|
+
| views at run-time offsets | [Native: Views at run-time offsets](language-native.md#views-at-run-time-offsets) |
|
|
131
|
+
| lib-sokoban's red-black tree | [Native: Red-black tree](language-native.md#lib-sokobans-red-black-tree) |
|
|
132
|
+
|
|
133
|
+
### Account parameters and the checks they emit
|
|
134
|
+
|
|
135
|
+
| Topic | Where |
|
|
78
136
|
| --- | --- |
|
|
79
|
-
|
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
|
|
|
84
|
-
|
|
|
85
|
-
|
|
|
86
|
-
| `
|
|
87
|
-
|
|
|
88
|
-
|
|
|
89
|
-
| `
|
|
90
|
-
|
|
|
91
|
-
| `
|
|
92
|
-
|
|
|
93
|
-
| `
|
|
94
|
-
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
|
99
|
-
|
|
|
100
|
-
| `
|
|
101
|
-
|
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
|
|
|
105
|
-
| `TokenInterface` | either token program |
|
|
106
|
-
| `AssociatedTokenProgram` | `create` / `createIdempotent` CPIs; `associatedTokenAddress(owner, mint, tokenProgram)` |
|
|
107
|
-
| `MemoProgram` | SPL Memo v2: `memoProgram.memo(text, [signers], signerSeeds?)`; each listed account signs (a PDA of this program with its seeds) |
|
|
108
|
-
| `TokenMetadataProgram` | Metaplex `createV3(...)` (CreateMetadataAccountV3), optionally with `{ creators: [{ address, verified, share }], collection: mint }` after `isMutable` (1–5 creators, shares adding up to 100; only the update authority, signing, can be `verified: true`; the collection is written unverified; `isCollection: true` makes the NFT a sized collection); `createMasterEditionV3(edition, mint, updateAuthority, mintAuthority, payer, metadata, tokenProgram, systemProgram, maxSupply \| null)`; `verifyCollection(authority, metadata, collectionMint, collectionMetadata, collectionMasterEdition, systemProgram, instructionsSysvar)` (Verify with CollectionV1); `updateMetadataAccountsV2(metadata, updateAuthority, data \| null, newUpdateAuthority \| null, primarySaleHappened \| null, isMutable \| null)` (`data` replaces the whole DataV2: `{ name, symbol, uri, sellerFeeBasisPoints, creators?, collection? }`; each null leaves that part); `burnV1(authority, metadata, edition \| null, mint, token, collectionMetadata \| null, systemProgram, instructionsSysvar, tokenProgram, amount)` (Burn: the holder signs and gets the rent back; the token account and edition close, the metadata is cleared to one byte); `metadataAddress(mint)`, `masterEditionAddress(mint)` |
|
|
109
|
-
| `StakeProgram` | `initialize(stake, rentSysvar, staker, withdrawer, lockup?)` (`lockup`: `{ unixTimestamp, epoch, custodian }`, none when left out), `authorize(stake, clockSysvar, authority, newAuthority, "staker" \| "withdrawer", custodian?)`, `delegate(stake, vote, clockSysvar, stakeHistorySysvar, stakeConfig, staker)`, `split(stake, splitStake, staker, lamports)`, `deactivate(stake, clockSysvar, staker)`, `withdraw(stake, to, clockSysvar, stakeHistorySysvar, withdrawer, lamports, custodian?)`, `merge(destination, source, clockSysvar, stakeHistorySysvar, staker)`, `getMinimumDelegation()` (a CPI, then the u64 the Stake program returns; fails as solana_program's `get_minimum_delegation` does); instruction tags and account lists as solana-stake-interface's builders; the sysvar and config accounts are parameters, as in anchor-spl's stake module, or `named(account, address)` (a native port): the instruction names `address` (`SysvarC1ock…`), as solana_program's builders do, and `account`, the slot's account, is what the runtime gets, as Rust's `invoke_signed(&ix, &[stake, clock_info, …])` passes it; the runtime looks the address up among the CPI's accounts only, so a slot holding another account fails the call (MissingAccount), as the original does, even when the sysvar is elsewhere in the transaction (`named` is valid only there); authorities and the lockup custodian sign (PDAs with signerSeeds, given last) |
|
|
110
|
-
| `InstructionsSysvar`, `PythPriceUpdate`, `SwitchboardFeed` | exact address (3008) / owner program + discriminator. `Address<InstructionsSysvar, "Sysvar1nstructions1111111111111111111111111">` checks the address as Anchor's `address = sysvar::instructions::ID` on an `UncheckedAccount` does (2012, with the constraints) |
|
|
111
|
-
| `InstructionsSysvar` (introspection) | `ixs.length`, `ixs.currentIndex()` (the top-level instruction being executed), `ixs.get(i)` → a `TransactionInstruction`: `programId`, `accountsLength`, `dataLength`, `accountKey(j)` / `accountIsSigner(j)` / `accountIsWritable(j)`, `readU8/U16/U32/U64/readPubkey(offset)` (little-endian), `is(program, "name")` (that program's instruction by its default Anchor discriminator, sha256("global:<name>"); an instruction with its own `@discriminator` is matched with `programId` and `readU64(0)` instead). Every read is bounds-checked (5104). It is the transaction author's data: require things of the transaction with it (a repay instruction after a flash loan), never treat it as proof |
|
|
112
|
-
| `Program<"Address…">` | exact program address + executable |
|
|
113
|
-
| `UncheckedProgram` | executable only — check `.key` yourself |
|
|
114
|
-
| `AccountInfo` / `Mut<AccountInfo>` | nothing (writable for `Mut`); `owner`, `executable` |
|
|
115
|
-
| `SystemAccount` / `Mut<SystemAccount>` | owned by the System Program, e.g. a wallet (Anchor `SystemAccount`, 3011) |
|
|
116
|
-
|
|
117
|
-
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).
|
|
118
|
-
|
|
119
|
-
Two writable parameters can never be the same account: aliasing is refused with error 2040 (also when a remaining
|
|
120
|
-
account written through `.lamports` or `loadAccountMut` is another account of the instruction). `Dup<Mut<T>>`
|
|
121
|
-
(Anchor's `dup`) lifts that for one parameter when both accounts are read and written in place (not created, closed
|
|
122
|
-
or `@layout borsh`; a close destination may be one, the rent reaching it through either): a write through either is
|
|
123
|
-
seen through the other, so read what you need before writing. A reference into one of them (`const e = a.entries.get(i)`)
|
|
124
|
-
cannot be used after a push, pop or clear through the other moved that data, as with one name (compile error); copy
|
|
125
|
-
the fields first. A remaining account
|
|
126
|
-
can be loaded with `loadAccountMut` once per instruction: loading the same one again (`rest.get(i)` and `rest.get(j)`
|
|
127
|
-
with `i == j`) is refused with 2040 too, since the two views would alias. So is a second `loadAccountMut` of one
|
|
128
|
-
`AccountInfo` parameter; two `Dup<…>` parameters that are one account may each be loaded (one array holding both ticks
|
|
129
|
-
of a position, as Raydium CLMM's tick arrays).
|
|
130
|
-
|
|
131
|
-
## Built-ins
|
|
132
|
-
|
|
133
|
-
- `systemProgram.transfer(from, to, lamports, signerSeeds?)` (`from` is a `Mut<Signer>`, or a system-owned PDA of this
|
|
134
|
-
program, a SOL vault, with its seeds), `systemProgram.createAccount(payer, account, lamports, space, owner, signerSeeds?)`
|
|
135
|
-
(the new account signs: a keypair `Mut<Signer>` or this program's PDA), `systemProgram.createPda(payer, account, space,
|
|
136
|
-
owner, seeds)` (Anchor's `init` with `seeds`, `space` and `owner = …` on an `UncheckedAccount`: a `Mut<AccountInfo>`
|
|
137
|
-
that must be this program's PDA for `seeds` (2006), created owned by `owner`, or topped up, allocated and assigned when
|
|
138
|
-
someone funded the address first; returns the bump, records the PDA in the IDL, and among the creates a body starts
|
|
139
|
-
with runs before the constraints), `rentExempt(space)`, `MINT_SIZE`, `TOKEN_ACCOUNT_SIZE`
|
|
140
|
-
- Token programs (`TokenProgram`, `Token2022Program`, `TokenInterface`) — pass `signerSeeds` (with the bump) when the authority is a PDA:
|
|
141
|
-
`transfer`, `transferChecked(from, mint, to, authority, amount)` (required by Token-2022 mints with fees/hooks), `mintTo` (the mint may be one this instruction just created), `burn`, `closeAccount` (a token account, or a Token-2022 mint with a close authority),
|
|
142
|
-
`approve(source, delegate, owner, amount)`, `revoke`, the checked forms `mintToChecked(mint, to, authority, amount)`,
|
|
143
|
-
`burnChecked(from, mint, authority, amount)` and `approveChecked(source, mint, delegate, owner, amount)` (the decimals
|
|
144
|
-
come from the mint), `setAuthority(target, current, AuthorityType.MintTokens, next | null)`,
|
|
145
|
-
`freezeAccount` / `thawAccount(account, mint, freezeAuthority)`, `syncNative(account)`, `initializeMint2(mint, decimals, mintAuthority, freezeAuthority | null)`,
|
|
146
|
-
`initializeAccount3(account, mint, owner)`, and on Token-2022 `initializeMetadata(mint, updateAuthority, mintAuthority, name, symbol, uri)` (metadata extension) and the extension initializers to call between `createAccount` and `initializeMint2` / `initializeAccount3`: `initializeTransferFeeConfig(mint, configAuthority | null, withdrawAuthority | null, basisPoints, maximumFee)`, `initializeMintCloseAuthority(mint, authority | null)`, `initializeNonTransferableMint(mint)`, `initializePermanentDelegate(mint, delegate)`, `initializeDefaultAccountState(mint, frozen)`, `initializeMetadataPointer` / `initializeGroupPointer` / `initializeGroupMemberPointer` / `initializeTransferHook(mint, authority | null, address | null)`, `initializeInterestBearingMint(mint, rateAuthority | null, rate)`, `initializeImmutableOwner(account)`; the extension instructions `updateDefaultAccountState(mint, freezeAuthority, frozen)`, `updateTransferHook(mint, authority, programId | null)`, `enableRequiredMemoTransfers` / `disableRequiredMemoTransfers(account, owner)`, `updateInterestRate(mint, rateAuthority, rate)`, `transferCheckedWithFee(from, mint, to, authority, amount, fee)`, `harvestWithheldTokensToMint(mint, remainingAccounts())`, `withdrawWithheldTokensFromMint(mint, destination, authority)`, `setTransferFee(mint, authority, basisPoints, maximumFee)`; and the Token Metadata interface `updateMetadataField(mint, updateAuthority, field, value)` ("name" / "symbol" / "uri" or any other key), `removeMetadataKey(mint, updateAuthority, key, idempotent)`, `updateMetadataAuthority(mint, updateAuthority, next | null)`, `emitMetadata(mint)`; and the Token Group interface: `initializeTokenGroup(group, mint, mintAuthority, updateAuthority | null, maxSize)` (a collection mint with a GroupPointer to itself; fund the rent for the group, which Token-2022 adds to the account), `initializeGroupMember(member, memberMint, memberMintAuthority, group, groupUpdateAuthority)`, `updateGroupMaxSize(group, authority, maxSize)`, `updateGroupAuthority(group, authority, next | null)`. Each takes optional signerSeeds
|
|
147
|
-
- `account.lamports` read/write on `Mut` accounts, `close(account, destination)` for program accounts (the destination
|
|
148
|
-
is another writable account; the account is not used after it in the function, except its `key`: compile errors, or
|
|
149
|
-
2040 at run time in a helper given one account twice)
|
|
150
|
-
- `requirePda(account, seeds, bump)`: any bump that gives a valid PDA passes, as with Anchor's `bump = expr`. Use a bump
|
|
151
|
-
stored when the account was created (or `Seeds<…>`); one taken from the instruction's arguments lets the caller pick
|
|
152
|
-
among up to 256 addresses for the same seeds
|
|
153
|
-
|
|
154
|
-
## Implementing another program's interface (transfer hooks)
|
|
155
|
-
|
|
156
|
-
`/** @discriminator spl-transfer-hook-interface:execute */` above an instruction replaces its Anchor discriminator with
|
|
157
|
-
sha256(preimage)[..8] (or `@discriminator 0x…` for raw bytes), so a TypeSOL program can be a Token-2022 transfer hook:
|
|
158
|
-
`execute(source, mint, destination, owner, extraMetas, ...extraAccounts, amount)` plus
|
|
159
|
-
`initExtraAccountMetas(payer, account, mint, systemProgram, extraAccounts?)` for the validation account (an
|
|
160
|
-
ExtraAccountMetaList). Extra accounts are listed as `{ address, isSigner?, isWritable? }` (a fixed address) or
|
|
161
|
-
`{ seeds: [...], program?, isSigner?, isWritable? }` (a PDA of this program, or with `program: i` of the program at account
|
|
162
|
-
index i), with seeds from string literals, `seedAccountKey(i)`, `seedAccountData(i, offset, length)` and
|
|
163
|
-
`seedInstructionData(offset, length)`; Token-2022 resolves and checks them on every transfer. The first extra account has
|
|
164
|
-
index 5. `updateExtraAccountMetas(...)` rewrites and resizes an existing list. See `test/fixtures/hook.ts` and the
|
|
165
|
-
transfer-hook ports.
|
|
166
|
-
|
|
167
|
-
## Calling other programs
|
|
168
|
-
|
|
169
|
-
```ts
|
|
170
|
-
export function relayIncrement(authority: Signer, counter: Mut<AccountInfo>, counterProgram: Program<"JD2v…99Y2">, by: u64): void {
|
|
171
|
-
invoke(counterProgram, [readonlySigner(authority), writable(counter)], [sighash("increment"), by]);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Sign for a PDA of this program: raw System transfer (u32 tag 2, u64 lamports) out of a treasury PDA.
|
|
175
|
-
export function payOut(admin: Signer, treasury: Mut<SystemAccount>, recipient: Mut<SystemAccount>, systemProgram: SystemProgram, amount: u64, bump: u8): void {
|
|
176
|
-
invoke(systemProgram, [writableSigner(treasury), writable(recipient)], [u32(2n), amount], ["treasury", admin.key, bump]);
|
|
177
|
-
}
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
- program: a `Program<"address">` (key and executable checked on entry), an `UncheckedProgram`, an
|
|
181
|
-
`Address<AccountInfo, "address">` (Anchor's `#[account(address = ID)]` on an `UncheckedAccount`: only the key is
|
|
182
|
-
checked, 2012), the system or a token program, or a remaining account.
|
|
183
|
-
- accounts: `readonly(x)`, `writable(x)`, `readonlySigner(x)`, `writableSigner(x)`. The compiler refuses `writable` on a
|
|
184
|
-
non-`Mut` parameter and a signer flag on an account that neither signed nor is covered by `signerSeeds`. An optional
|
|
185
|
-
account passed as it is (`readonly(x)` / `writable(x)` with `x: A | null`, no `!`) is left out of the list when it
|
|
186
|
-
was not passed, as Rust's `if let Some(x) = &self.x { accounts.push(…) }` does.
|
|
187
|
-
- data (Borsh): integers little-endian at their declared width (`u32(2n)` is 4 bytes, a bare `5n` is a u64), booleans,
|
|
188
|
-
Pubkeys, strings, Options, structs and FixedArrays (their fixed layout), data enums, `Vec` arguments,
|
|
189
|
-
`sighash("name")` (Anchor discriminator), `hex("0a0b")`. Up to 1024 bytes.
|
|
190
|
-
- `signerSeeds` (with the bump) signs for this program's PDA. When several PDAs sign one call, pass a list of seed
|
|
191
|
-
lists: `[["vault", owner.key, vaultBump], ["fees", feesBump]]` (at most 16).
|
|
192
|
-
- A seed list used more than once can be named: `const vault = signer(["vault", owner.key, bump])`, then pass `vault`
|
|
193
|
-
wherever signerSeeds go. One of two lists picked at run time: `const pool = indexed ? signer([…, index, bump]) :
|
|
194
|
-
signer([…, bump])`. A named list, and one given to a helper, holds its seeds as they were when it was written (JS
|
|
195
|
-
evaluates the array then): a field or local changed afterwards does not change what it signs for. A list written in
|
|
196
|
-
a call (`transfer(…, signer([…]))`, `create(payer, [...], space)`) holds them as they were when the list was read,
|
|
197
|
-
even when a later argument changes a seed.
|
|
198
|
-
- `bigEndian(x)` in a seed list: an integer's bytes most significant first (`["tick_array", pool.key, bigEndian(start)]`).
|
|
199
|
-
- After the call, `returnData<u64>(program)` reads what the callee returned, checking the size and that it came from `program`.
|
|
200
|
-
A struct is bound to a local, `const quote = returnData<Quote>(amm)`: a fixed layout of integers, booleans, Pubkeys,
|
|
201
|
-
unit enums and arrays is read as its bytes (bools and enums checked); a struct with Options, strings or Vecs is
|
|
202
|
-
declared `/** @layout borsh */` and Borsh-decoded. Bytes that are not exactly the struct fail with 5106.
|
|
203
|
-
|
|
204
|
-
A call decided at run time, such as one a multisig stored in account data, is `invokeInstruction` (Rust's
|
|
205
|
-
`invoke_signed(&Instruction { program_id, accounts, data }, infos, seeds)`):
|
|
206
|
-
|
|
207
|
-
```ts
|
|
208
|
-
invokeInstruction(transaction.programId, transaction.accounts, transaction.data, remainingAccounts(), [multisig.key, multisig.nonce]);
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
- the accounts are a list of structs with `pubkey`, `isSigner` and `isWritable` (a Vec or FixedVec in account data, a
|
|
212
|
-
Vec argument, a stored `map` result, or a local list built on the stack); the data a list of u8 (the same, the
|
|
213
|
-
instruction data or a slice of it).
|
|
214
|
-
- every account in the fourth argument (`remainingAccounts()` or a slice; in a helper, its `RemainingAccounts`
|
|
215
|
-
parameter or a slice of it) is handed to the runtime, which finds each meta's account there by key: one that is
|
|
216
|
-
missing fails the call, as under Rust (MissingAccount, "Instruction references an unknown account").
|
|
217
|
-
- so a native port builds the instruction as Rust's instruction builders do, in a helper too, with metas naming
|
|
218
|
-
accounts by key:
|
|
219
|
-
|
|
220
|
-
```ts
|
|
221
|
-
function transfer(rest: RemainingAccounts, data: InstructionBytes, to: Pubkey): void {
|
|
222
|
-
const metas: FixedVec<Meta, 2> = fixedVec([{ pubkey: rest.get(0n).key, isSigner: true, isWritable: true }]);
|
|
223
|
-
metas.push({ pubkey: to, isSigner: false, isWritable: true });
|
|
224
|
-
const ix: FixedVec<u8, 12> = fixedVec([2n, 0n, 0n, 0n]); // system_instruction::transfer
|
|
225
|
-
ix.pushAll(data.slice(1n, 9n)); // the lamports, as sent
|
|
226
|
-
invokeInstruction(rest.get(2n).key, metas, ix, rest);
|
|
227
|
-
}
|
|
228
|
-
```
|
|
229
|
-
- the runtime checks the privileges: a meta may be a signer or writable only as the transaction passed that account,
|
|
230
|
-
or as a PDA of this program the seeds (fifth argument) sign for. See `showcase/mainnet/multisig/multisig.ts`.
|
|
231
|
-
|
|
232
|
-
Typed calls from an IDL: `typesol cpi other.json --out other_cpi.ts` writes one helper per instruction
|
|
233
|
-
(`vaultDeposit(program, owner, vault, systemProgram, amount, seeds)`), with the account flags, discriminator and
|
|
234
|
-
argument encoding taken from the IDL (Anchor 0.30+ / 1.x, or TypeSOL's own). Call it with `signer([...seeds, bump])`
|
|
235
|
-
when a PDA of your program signs, or `signer([])`. Instructions whose arguments have no Borsh-identical TypeSOL type
|
|
236
|
-
(strings or Options inside structs, data-carrying enums) are listed and left out.
|
|
237
|
-
|
|
238
|
-
## PDAs in the IDL
|
|
239
|
-
|
|
240
|
-
When an instruction calls `x.create(payer, seeds)` or `requirePda(x, seeds, bump)` and every seed is a string literal,
|
|
241
|
-
an integer literal, an argument, `acct.key` or a scalar field of an account, the IDL entry for `x` gets Anchor `pda.seeds`
|
|
242
|
-
(`const` / `arg` / `account`), so Anchor and Codama clients derive the address themselves.
|
|
243
|
-
|
|
244
|
-
## Programs and sysvars passed as remaining accounts
|
|
245
|
-
|
|
246
|
-
A native program takes its programs and sysvars by position too. `programAt<P>(account)` checks a remaining account
|
|
247
|
-
(or an `AccountInfo` parameter) is that program, once, by its key, and gives it P's typed methods:
|
|
248
|
-
|
|
249
|
-
```ts
|
|
250
|
-
const rest = remainingAccounts();
|
|
251
|
-
const stake = programAt<StakeProgram>(rest.get(12n)); // ProgramError.IncorrectProgramId if it is another account
|
|
252
|
-
stake.split(rest.get(3n), rest.get(4n), rest.get(1n), lamports, [pool.key, "withdraw", bump]);
|
|
253
|
-
const minimum = stake.getMinimumDelegation();
|
|
254
|
-
programAt<TokenInterface>(rest.get(10n)).mintTo(rest.get(7n), rest.get(8n), rest.get(1n), amount, seeds);
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
- P is `StakeProgram`, `SystemProgram`, `TokenProgram`, `Token2022Program`, `TokenInterface` (either token program),
|
|
258
|
-
`AssociatedTokenProgram` or `MemoProgram`. Bind it with `const`, or call a method on it directly; pass it to a helper
|
|
259
|
-
that takes that program type.
|
|
260
|
-
- `sysvarAt<StakeHistorySysvar>(account)` does the same for the StakeHistory sysvar (ProgramError.InvalidArgument for
|
|
261
|
-
another account): `count`, `latestEpoch`, `has(epoch)`, `effective(epoch)` … as on a parameter (read its fields
|
|
262
|
-
through a `const` bound to it; methods also work on the call itself).
|
|
263
|
-
- Every typed CPI (System, SPL Token and Token-2022, ATA, Memo, Stake) takes, for each account, a declared parameter,
|
|
264
|
-
a remaining account (`rest.get(i)`, a local bound to one, a `RemainingAccount` helper parameter), a struct loaded
|
|
265
|
-
from one, or an `AccountInfo` parameter where a `TokenAccount` or `Mint` goes. Declared parameters keep their
|
|
266
|
-
compile-time checks (writable slots need `Mut<…>`, an authority without signerSeeds a `Signer`). A remaining account
|
|
267
|
-
is not checked by the compiler, and unlike `invoke` the typed calls add no runtime check of their own: the runtime
|
|
268
|
-
refuses a CPI that makes an account writable or a signer when the transaction did not (and no seeds sign for it),
|
|
269
|
-
and the called program checks the rest (a token account's mint and owner, a stake account's authorities).
|
|
270
|
-
- The cost is the key check (four 8-byte compares) and the call itself: within a few compute units of the same call
|
|
271
|
-
written with `invoke`, which checks only the executable flag (test/integrations/native-cpi.test.ts measures it).
|
|
272
|
-
|
|
273
|
-
## Porting a native program
|
|
274
|
-
|
|
275
|
-
A program written without Anchor (Raydium AMM v4, SPL programs) reads a tag byte and its arguments itself and takes its
|
|
276
|
-
accounts by position. TypeSOL ports one as it is (see `showcase/mainnet/raydium-amm` and `test/fixtures/native.ts`):
|
|
277
|
-
|
|
278
|
-
- One `/** @fallback */` entry: `const data = instructionData()` gives the bytes, with `data.readU8/U16/U32/U64/U128/
|
|
279
|
-
readPubkey(offset)` (little-endian, bounds-checked: 5104), and the list methods, `for … of`, `data.slice(a, b)`
|
|
280
|
-
(a view, 5104 out of range) and `out.pushAll(data.slice(a, b))` (a memcpy into a local FixedVec); a helper takes it as
|
|
281
|
-
an `InstructionBytes` parameter. `remainingAccounts()` gives the accounts by position.
|
|
282
|
-
- Calls to System, Token and Stake: `programAt<P>(acct)` and the typed methods, with remaining accounts (above), not
|
|
283
|
-
hand-encoded `invoke` data.
|
|
284
|
-
- Accounts without a discriminator: `loadRaw<T>(acct)` / `loadRawMut<T>(acct)` view one as a fixed-layout struct from
|
|
285
|
-
byte 0 (this program's, 3007; at least the struct's size, 3003; `loadRawMut`: writable, loaded once). Make the
|
|
286
|
-
original's own checks (an exact size, its error codes) before the load. A read-only view can be read where it is
|
|
287
|
-
made, `loadRaw<Header>(market).inner.b` or `loadRawAt<Prefix>(market, 576n).tick` (its checks made there); a
|
|
288
|
-
writable one claims its account once per instruction, so it is bound to a const first. The owner check of these views (and of
|
|
289
|
-
`loadRawAt`, `rawArrayAt`, `rbTreeAt` below) is made every time, but the last account found this program's passes
|
|
290
|
-
again with one pointer compare instead of 32 bytes until a CPI or an owner write (`assignOwner`, `closeRaw`,
|
|
291
|
-
`close`): helpers that each view the market again, and views in loops, pay about 3 compute units for it instead of
|
|
292
|
-
about 14. Structs are packed, as `#[repr(C, packed)]`.
|
|
293
|
-
- Borsh accounts without a discriminator (SPL Stake Pool's `StakePool`, read with `try_from_slice_unchecked` and
|
|
294
|
-
written with `serialize`): `const pool = loadBorsh<StakePool>(acct)` decodes the data from byte 0 into a local
|
|
295
|
-
struct (a copy: fields updated, Options narrowed and set to null or a value, data enums switched, copied, passed to
|
|
296
|
-
helpers), and `storeBorsh(acct, pool)` encodes it back from byte 0. As Rust: no owner check and no discriminator
|
|
297
|
-
(check the owner first, as the original does); bytes after the value are ignored when reading and left as they were
|
|
298
|
-
when writing (an Option that became None leaves its old bytes behind it); data too short, an Option tag or boolean
|
|
299
|
-
other than 0/1, an enum tag out of range, a String that is not UTF-8 or longer than its `FixedString<N>`, or an
|
|
300
|
-
account too small for the encoding fail with `ProgramError.BorshIoError`. `acct` is a remaining account, a
|
|
301
|
-
`RemainingAccount` helper parameter or an `AccountInfo` parameter (`Mut<AccountInfo>` for `storeBorsh`; a remaining
|
|
302
|
-
account must be writable, 3006). `T` may hold integers, booleans, Pubkeys, enums, FixedArrays, `FixedString<N>`,
|
|
303
|
-
`FixedVec<T, N>`, Options, data enums with fixed-size payloads and nested structs of those, with or without
|
|
304
|
-
`@layout borsh`; not `Vec<T>` or `string` (they would need the heap or a view). Each struct gets its own
|
|
305
|
-
straight-line decoder and encoder (no heap): about 280 CU to read a 611-byte `StakePool` and 610 CU to read and
|
|
306
|
-
write it back. The local lives on the stack (4 KiB per function).
|
|
307
|
-
- Lists over the rest of an account (SPL's `big_vec`): a struct ending in `BigVec<T>`, `const list =
|
|
308
|
-
loadRawMut<ValidatorList>(acct)`, then `list.validators.push(…)`, `.retain((v) => …)`, `.findIndex((v) => …)`,
|
|
309
|
-
`for (const v of list.validators.slice(skip, skip + len))` (`deserialize_mut_slice(skip, len)`). The load fails with
|
|
310
|
-
AccountDataTooSmall when the stored length does not fit, where the Rust would only panic on reaching such an element:
|
|
311
|
-
check the length first (`readData<u32>(acct, offset)`) where the original returns an error of its own before that.
|
|
312
|
-
- Parts at offsets the account's header gives: `loadRawAt<T>(acct, offset)` / `loadRawMutAt<T>(…)` for a struct,
|
|
313
|
-
`rawArrayAt<T>(acct, offset, capacity)` / `rawArrayMutAt<T>(…)` for a run-time number of elements, each bounds-checked
|
|
314
|
-
once when it is made (ProgramError::AccountDataTooSmall; `loadRaw`'s fixed size check stays 3003, the error of a
|
|
315
|
-
view whose size is known when the program is compiled), as Phoenix slices `&data[576..]` after checking the
|
|
316
|
-
account's size itself. `rbTreeAt(…).length` and `.capacity` read a tree made for the one read; anything else on a
|
|
317
|
-
tree or a raw array is done on a const bound to it. The checks a Rust original makes first (a size, its own error code) go before the view.
|
|
318
|
-
- lib-sokoban's trees (Phoenix's order books and trader seats): `rbTreeMutAt<K, V>(acct, offset, capacity, compare?)`,
|
|
319
|
-
every write the crate's own, so the account matches the original after every instruction:
|
|
320
|
-
|
|
321
|
-
```ts
|
|
322
|
-
/** Phoenix's FIFOOrderId Ord: a bid's sequence number is stored inverted (top bit set); bids descend, asks ascend. */
|
|
323
|
-
function orderCmp(a: FIFOOrderId, b: FIFOOrderId): i8 {
|
|
324
|
-
if (a.order_sequence_number >> 63n === 1n) {
|
|
325
|
-
// a bid (the left key's side decides): `other.cmp(self)`
|
|
326
|
-
if (a.price_in_ticks !== b.price_in_ticks) return b.price_in_ticks < a.price_in_ticks ? -1n : 1n;
|
|
327
|
-
return b.order_sequence_number < a.order_sequence_number ? -1n : b.order_sequence_number > a.order_sequence_number ? 1n : 0n;
|
|
328
|
-
}
|
|
329
|
-
if (a.price_in_ticks !== b.price_in_ticks) return a.price_in_ticks < b.price_in_ticks ? -1n : 1n;
|
|
330
|
-
return a.order_sequence_number < b.order_sequence_number ? -1n : a.order_sequence_number > b.order_sequence_number ? 1n : 0n;
|
|
331
|
-
}
|
|
332
|
-
const bids = rbTreeMutAt<FIFOOrderId, FIFORestingOrder>(market, 880n, n, orderCmp);
|
|
333
|
-
const best = bids.min(); // the best bid, or null
|
|
334
|
-
if (best !== null && best.value.num_base_lots > 0n) best.value.num_base_lots -= fill;
|
|
335
|
-
const index = traders.addrOf(trader); // a seat's node index, 0 when absent
|
|
336
|
-
// a cancel: find the order, check it, then remove that node (no second search)
|
|
337
|
-
const at = bids.addrOf(orderId);
|
|
338
|
-
if (at !== 0n && bids.nodeAt(at).value.trader_index === traderIndex) bids.removeAt(at);
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
The C runs sokoban's get_addr / _insert / _remove / rotations / allocator statement for statement, with the node
|
|
342
|
-
stride a constant (512 entries: get 166 CU, insert 493, remove 294, min 94; 4096: 215 / 595 / 355 / 112, against
|
|
343
|
-
300 / 604 / 497 / 191 and 384 / 742 / 618 / 225 for lib-sokoban built with cargo-build-sbf). sokoban's panics are
|
|
344
|
-
Rust panics in the original; the tree reproduces each as solana-program up to 1.17 reports one (Phoenix's build):
|
|
345
|
-
the log line `panicked at '<message>', <file>:<line>:<column>`, then the runtime's abort ("SBF program panicked",
|
|
346
|
-
ProgramFailedToComplete), with sokoban's messages and source lines as Phoenix's binary holds them (`src/…`):
|
|
347
|
-
`initialize()` on an allocator that is not all zero, "Cannot reinitialize NodeAllocator" (src/node_allocator.rs:249:13);
|
|
348
|
-
an empty tree's insert with no room (capacity 0, or a damaged allocator), "Buffer is full, size N" (:269:17); and on
|
|
349
|
-
damaged registers only, "Nodes are not connected" (src/red_black_tree.rs:429:13), "assertion failed:
|
|
350
|
-
self.is_root(parent)" (:503:17), "assertion failed: self.is_leaf(max_left)" (:598:17), a size going below zero
|
|
351
|
-
("attempt to subtract with overflow", src/node_allocator.rs:291:9). A node index outside 1..capacity, from `nodeAt`
|
|
352
|
-
or a damaged register, panics as Rust's `nodes[i - 1]` would ("index out of bounds: the len is N but the index is
|
|
353
|
-
I", src/node_allocator.rs:255:10; index 0, "attempt to subtract with overflow", :255:21: locations read from the
|
|
354
|
-
source, not from a binary), so a damaged tree never reads outside the account. A port makes the original's checks
|
|
355
|
-
in the original's order before the tree call, and these lines follow on their own. Iteration keeps its stack on the
|
|
356
|
-
program's stack (64 nodes, more than any red-black tree a u32 index can address holds on one path); a deeper,
|
|
357
|
-
damaged tree panics where the Rust's heap stack would grow. A walk costs about 34 compute units per node, a sum in
|
|
358
|
-
its body included (each node's index checked once, when the walk reaches it). A tree is a const of the function that makes it, not
|
|
359
|
-
a helper parameter (make it again in the helper from the account).
|
|
360
|
-
- Writes as the original makes them: `export const NATIVE_ACCOUNT_WRITES = true` (anywhere in the program; opt-in, for
|
|
361
|
-
native ports). A native program writes account data in place and the runtime judges afterwards: a read-only account
|
|
362
|
-
whose data actually changed fails the instruction (`ReadonlyDataModified`, or an access violation at the write under
|
|
363
|
-
account-data direct mapping), one that was only read (or written with the bytes it held) is fine, and an account
|
|
364
|
-
passed twice is two `AccountInfo`s over one buffer. By default
|
|
365
|
-
`loadRawMut` and `storeBorsh` check writability up front (3006), `loadRawMut` claims the account once and
|
|
366
|
-
`storeBorsh` refuses an account passed more than once (2040, as a write to a remaining account's lamports), so a
|
|
367
|
-
port fails where the original succeeds (a read-only validator list that is only read; the list passed again as a
|
|
368
|
-
stake account, which the original skips by its address checks). With the flag, `loadRawMut`, `storeBorsh` and the
|
|
369
|
-
BigVec writes through a `loadRawMut` view skip both, and both take a plain `AccountInfo` parameter (no `Mut<…>`
|
|
370
|
-
needed). Owner and size checks stay. **The trade-off:** a write to a read-only account is reported by the runtime at
|
|
371
|
-
the end, not at the write, and two loads of one account are two views of the same bytes (a write through one is
|
|
372
|
-
read through the other), where Rust's `RefCell` would fail a second `borrow_mut()` while the first is held (a panic,
|
|
373
|
-
or `AccountBorrowFailed` through `try_borrow_mut_data`). The original's own address and type checks normally refuse
|
|
374
|
-
such a pair before it is loaded (SPL Stake Pool's PDA checks); make them in the same order, before the load. Only
|
|
375
|
-
data writes are affected: with or without the flag every view reads the account's bytes in place, so a `loadRaw`
|
|
376
|
-
of an account also loaded with `loadRawMut` (or written with `storeBorsh`) reads what was written, BigVec pushes
|
|
377
|
-
included; the flag only lifts the up-front checks (a second `loadRawMut` of one account, at the same position or
|
|
378
|
-
another, is 2040 without it). `.lamports` on remaining accounts, `loadAccountMut`, CPI account metas and the checks of
|
|
379
|
-
`Mut<…>` parameters stay as they are, and programs without the flag compile exactly as before.
|
|
380
|
-
- Accounts closed, reassigned and resized by hand, on remaining accounts and `AccountInfo` parameters:
|
|
381
|
-
`closeRaw(account, receiver)` is what Phoenix's Tombstone writes, in its order: `receiver.lamports +=
|
|
382
|
-
account.lamports` (checked), `account.lamports = 0`, `assign(&system_program::id())`, `realloc(0, false)`. Unlike
|
|
383
|
-
`close` the data is not zeroed first (a realloc to 0 drops it, and the runtime then accepts the new owner), so it
|
|
384
|
-
costs a few compute units whatever the account's size, and the account ends as the original's does (gone, its
|
|
385
|
-
lamports in the receiver; test/language/native-close.test.ts compares it with Phoenix's own Tombstone).
|
|
386
|
-
`assignOwner(account, owner)` is `AccountInfo::assign` (the runtime accepts it for a writable account of this program
|
|
387
|
-
whose data is empty or zeroed), and `resizeAccount(account, size)` also takes a remaining account (`realloc(size,
|
|
388
|
-
true)`: new bytes zeroed, at most 10 KiB past the size it had when the instruction started, 3016; that size is the one
|
|
389
|
-
the entrypoint records in the account's record, as solana_program 1.14's does, only in programs that resize a
|
|
390
|
-
remaining account). A view of the account made before either (`loadRawMutAt`, `rawArrayMutAt`, `rbTreeMutAt`, a node
|
|
391
|
-
or a struct read through one) is a compile error to use after it: its bounds were checked against the old length, so
|
|
392
|
-
take the view again. Without `NATIVE_ACCOUNT_WRITES` the accounts are checked as other writes the compiler cannot see
|
|
393
|
-
are: writable (3006; a parameter must be `Mut<AccountInfo>`), passed once (2040), the closed or reassigned account
|
|
394
|
-
this program's (3007), and not closed into itself (2040). With it nothing is checked and the runtime judges, as for
|
|
395
|
-
the original (`ReadonlyLamportChange`, `ExternalAccountLamportSpend`, `UnbalancedInstruction`, `ModifiedProgramId`),
|
|
396
|
-
and plain `AccountInfo` parameters are enough.
|
|
397
|
-
- Errors as the original returns them: an error enum may start at code 0 (`/** @code 0 */`, Rust's
|
|
398
|
-
`ProgramError::Custom(0)`, returned as Solana's CUSTOM_ZERO); `require(c, ProgramError.InvalidInstructionData)` for a
|
|
399
|
-
built-in error; `panic(message, "program/src/lib.rs:12:5")` for a Rust panic (ProgramFailedToComplete, the runtime
|
|
400
|
-
reporting that location; `panic(null, "src/lib.rs:105:19")` logs no message, for an original whose panic handler
|
|
401
|
-
writes none, so only the runtime's "SBF program Panicked in src/lib.rs at 105:19" is left); `abort()` for Rust's
|
|
402
|
-
abort (the allocator's out-of-memory error: `log("Error: memory allocation failed, out of memory"); abort();`), the
|
|
403
|
-
runtime's `abort` syscall, which logs "SBF program panicked" with no location; `const PANIC_ON_OVERFLOW = true`
|
|
404
|
-
makes arithmetic overflow and division by zero panic as `checked_*().unwrap()` does instead of failing with 5100 /
|
|
405
|
-
5101.
|
|
406
|
-
- Panics as an older solana-program writes them: `export const PANIC_STYLE = "solana-1.14"` (a program built with
|
|
407
|
-
solana-program 1.14 to 1.17, whose rustc formats a panic before 1.73 did: Phoenix v1) makes `panic(message,
|
|
408
|
-
location)` log `panicked at '<message>', <location>` and then abort, so the runtime's last line is "SBF program
|
|
409
|
-
panicked" with no location, as that panic handler leaves it (`panic(null, …)` is refused there: the handler always
|
|
410
|
-
logs; without a location the TypeScript line and column are used). `PANIC_ON_OVERFLOW`'s panics abort too.
|
|
411
|
-
- Overflow panics with Rust's message and location: `panicsAt("src/quantities.rs:233:1", a + b)` is `a + b` whose
|
|
412
|
-
checked arithmetic panics as Rust's overflow checks do at that location ("attempt to add with overflow"; also
|
|
413
|
-
"attempt to subtract / multiply with overflow", "attempt to divide by zero", "attempt to calculate the remainder
|
|
414
|
-
with a divisor of zero", "attempt to negate with overflow", "attempt to divide with overflow" and "attempt to shift
|
|
415
|
-
left / right with overflow" for a shift amount past the width), logged as `panic` logs (`PANIC_STYLE` above, else
|
|
416
|
-
the message and sol_panic_ at the location), instead of failing with 5100 / 5101; with or without
|
|
417
|
-
`PANIC_ON_OVERFLOW`, which applies outside it. Rust reports the location of the expression the operator belongs
|
|
418
|
-
to, so the wrapper goes around that expression: only the operators written inside it take the location (not those
|
|
419
|
-
of the helpers it calls), an inner `panicsAt` gives its operators their own (`panicsAt(A, x + panicsAt(B, y * z))`),
|
|
420
|
-
and as a statement it takes an assignment, `panicsAt(LOC, total += fee);`. A Rust newtype's operator panics at its
|
|
421
|
-
`impl` (Phoenix's `QuoteLots + QuoteLots` at the macro line in quantities.rs, wherever the addition is written): give
|
|
422
|
-
the port a helper, `function addQuoteLots(a: u64, b: u64): u64 { return panicsAt(QUOTE_LOTS_ADD, a + b); }`. The
|
|
423
|
-
bits `<<` loses, `**`, `mulDiv` / `mulDivCeil`, casts and u256 arithmetic keep TypeSOL's failures (Rust checks them
|
|
424
|
-
differently, or with other messages).
|
|
425
|
-
test/language/rust-panics.test.ts checks the lines against the Phoenix binary's own panics.
|
|
426
|
-
- Log lines as the original writes them: `const ERROR_LOG_PREFIX = "AMM error: "` and `const PROGRAM_ERROR_LOG_PREFIX =
|
|
427
|
-
"Program error: "` replace the compiler's failure line with the entrypoint's (`msg!("AMM error: {}", e)`); `null`
|
|
428
|
-
logs no failure line at all, as a native program returns an error its own checks already explained (Phoenix): the
|
|
429
|
-
program's errors and codes its helpers return (`ERROR_LOG_PREFIX = null`), built-in ProgramErrors and `programAt`'s
|
|
430
|
-
check (`PROGRAM_ERROR_LOG_PREFIX = null`), each about 110 CU cheaper than a logged one (constraint errors and the
|
|
431
|
-
compiler's own checks still log);
|
|
432
|
-
`logBase64("ray_log: ", record)` logs a struct's bytes in base64 (a native `bincode` log record);
|
|
433
|
-
`createProgramAddress(seeds, program)` is `Pubkey::create_program_address` (null for no address);
|
|
434
|
-
`logComputeUnits()` is `sol_log_compute_units()`: the runtime writes "Program consumption: N units remaining" at
|
|
435
|
-
that point, as for the original (Phoenix's cancel and withdraw paths log it).
|
|
436
|
-
- Byte strings built by hand (instruction data for a self-CPI, a log record, return data) in a `FixedVec<u8, N>`, a
|
|
437
|
-
local list or one in account data: `buf.pushLE(x)` appends an integer's little-endian bytes at its width (u8 … u128,
|
|
438
|
-
i8 … i128; a literal needs one: `buf.pushLE<u16>(1n)` or `buf.pushLE(u16(1n))`), `buf.pushKey(key)` a Pubkey's 32
|
|
439
|
-
bytes, `buf.pushBorsh(value)` a value's Borsh encoding with the codecs `invoke`, events and `storeBorsh` use (a
|
|
440
|
-
struct, or an object literal given its type, `buf.pushBorsh<Header>({ … })`; a data enum, its tag then the variant's
|
|
441
|
-
fields; a FixedArray; a list, its u32 count then the elements; integers, booleans, Pubkeys, strings and Options; a
|
|
442
|
-
data-enum literal of a fixed-size variant costs what the same bytes cost with `pushLE`: its fields evaluated in
|
|
443
|
-
order, then one room check and a store of each),
|
|
444
|
-
`buf.setLE(offset, x)` (or `setLE<u16>(offset, x)`) overwrites bytes within the length, as Rust's
|
|
445
|
-
`data[a..b].copy_from_slice(…)`, and `buf.truncate(n)` keeps the first `n`. Past the room (or, for `setLE` and
|
|
446
|
-
`truncate`, past the length) fails with 5104 and the length does not move. Phoenix's event recorder, which the test
|
|
447
|
-
checks byte for byte against the Phoenix binary's batches:
|
|
448
|
-
|
|
449
|
-
```ts
|
|
450
|
-
const data: FixedVec<u8, 1280> = fixedVec([15n]); // PhoenixInstruction::Log
|
|
451
|
-
data.pushBorsh<PhoenixMarketEvent>({ kind: "Header", instruction, sequenceNumber, timestamp: now(), slot: currentSlot(), market, signer, totalEvents: 0n });
|
|
452
|
-
// … for each event, the batch sent first if it would not fit: data.pushBorsh<PhoenixMarketEvent>({ kind: "Fill", index, … });
|
|
453
|
-
data.setLE(91n, u16(batchSize)); // total_events of this batch
|
|
454
|
-
invokeInstruction(programId(), metas, data, rest, ["log", bump]);
|
|
455
|
-
data.truncate(93n); // back to the header
|
|
456
|
-
```
|
|
457
|
-
- Return data as the original sets it: `setReturnData(bytes)` is `set_return_data(&bytes)`, the bytes as they are, from
|
|
458
|
-
the `@fallback` entry, a helper or a void instruction (Phoenix's Borsh `Vec<FIFOOrderId>` of the orders that rested,
|
|
459
|
-
built in a local `FixedVec<u8, N>`). `bytes` is a list of u8: a local FixedVec, a Vec or FixedVec in account data, or
|
|
460
|
-
the instruction data or a slice of it. The last call wins and an empty list clears it; a CPI made afterwards replaces
|
|
461
|
-
it with the callee's (call it after the last CPI, as Rust must). More than 1024 bytes fails as the Rust call does: the
|
|
462
|
-
runtime refuses it ("Return data too large (1025 > 1024)"). An instruction that returns a value cannot call it (a
|
|
463
|
-
compile error: its return value is its return data); a helper it calls may, and the instruction's return value, set
|
|
464
|
-
last, replaces what the helper set.
|
|
137
|
+
| every account type and what it checks | [Accounts: Account parameters](language-accounts.md#account-parameters-and-the-checks-they-emit) |
|
|
138
|
+
| `Init`, `InitIfNeeded`, `create`, `space` | [Accounts: Creating accounts](language-accounts.md#creating-accounts) |
|
|
139
|
+
| `Zeroed<T>`, `Signed<Zeroed<T>>` | [Accounts: Zeroed accounts](language-accounts.md#zeroed-accounts) |
|
|
140
|
+
| `Migrate<From, To>` | [Accounts: Migrating an account](language-accounts.md#migrating-an-account) |
|
|
141
|
+
| constraints: `HasOne`, `Seeds`, `CloseTo`, `Address`, `Owner`, `Executable`, `Signed`, your own errors, `constraint(…)` | [Accounts: Constraints](language-accounts.md#constraints) |
|
|
142
|
+
| `Seeds<…>`, `"@name"`, bumps, `pdaBump` | [PDAs: Seeds constraints](language-pdas.md#seeds-constraints) |
|
|
143
|
+
| token accounts and mints, `TokenOf`, `MintOf`, `Ata` | [CPI: Token accounts and mints as parameters](language-cpi.md#token-accounts-and-mints-as-parameters) |
|
|
144
|
+
| `Init<Mint>`, `Init<TokenAccount>`, ATAs, mint extensions | [CPI: Creating mints and token accounts](language-cpi.md#creating-mints-and-token-accounts) |
|
|
145
|
+
| optional accounts | [Accounts: Optional accounts](language-accounts.md#optional-accounts) |
|
|
146
|
+
| account groups | [Accounts: Account groups](language-accounts.md#account-groups) |
|
|
147
|
+
| `ProgramData` | [Accounts: ProgramData](language-accounts.md#programdata) |
|
|
148
|
+
| the `@fallback` entry | [Native: The fallback entry](language-native.md#the-fallback-entry) |
|
|
149
|
+
| `InstructionsSysvar` introspection | [Chain: Instruction introspection](language-chain.md#instruction-introspection) |
|
|
150
|
+
| program and sysvar parameters | [Accounts: Account parameters](language-accounts.md#account-parameters-and-the-checks-they-emit) |
|
|
151
|
+
| `MAX_ACCOUNTS` | [Accounts: How many accounts](language-accounts.md#how-many-accounts) |
|
|
152
|
+
| two parameters, one account (2040), `Dup<…>` | [Accounts: Two parameters, one account](language-accounts.md#two-parameters-one-account) |
|
|
153
|
+
|
|
154
|
+
### Built-ins
|
|
155
|
+
|
|
156
|
+
| Topic | Where |
|
|
157
|
+
| --- | --- |
|
|
158
|
+
| `systemProgram.transfer`, `createAccount`, `createPda` | [CPI: The System Program](language-cpi.md#the-system-program) |
|
|
159
|
+
| token program methods | [CPI: Tokens](language-cpi.md#tokens) |
|
|
160
|
+
| `account.lamports`, `close` | [Accounts: Closing and resizing](language-accounts.md#closing-and-resizing) |
|
|
161
|
+
| `requirePda` | [PDAs: Checking a PDA in the body](language-pdas.md#checking-a-pda-in-the-body) |
|
|
162
|
+
| every exported name | [Built-ins](language-builtins.md) |
|
|
465
163
|
|
|
466
|
-
|
|
164
|
+
### Implementing another program's interface (transfer hooks)
|
|
467
165
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
166
|
+
See [Calling other programs: transfer hooks](language-cpi.md#implementing-another-programs-interface-transfer-hooks).
|
|
167
|
+
|
|
168
|
+
### Calling other programs
|
|
169
|
+
|
|
170
|
+
| Topic | Where |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `invoke`: program, accounts, data | [CPI: invoke](language-cpi.md#invoke) |
|
|
173
|
+
| signer seeds, `signer([…])` | [PDAs: Signing as a PDA](language-pdas.md#signing-as-a-pda) |
|
|
174
|
+
| `returnData` | [CPI: Return data](language-cpi.md#return-data) |
|
|
175
|
+
| `invokeInstruction` | [CPI: invokeInstruction](language-cpi.md#invokeinstruction) |
|
|
176
|
+
| `typesol cpi`: typed calls from an IDL | [CPI: Typed calls from an IDL](language-cpi.md#typed-calls-from-an-idl) |
|
|
177
|
+
| Associated Token, Memo, Token Metadata, Stake | [CPI: Associated Token, Memo, Metadata and Stake](language-cpi.md#associated-token-memo-metadata-and-stake) |
|
|
178
|
+
|
|
179
|
+
### PDAs in the IDL
|
|
180
|
+
|
|
181
|
+
See [PDAs: PDAs in the IDL](language-pdas.md#pdas-in-the-idl).
|
|
182
|
+
|
|
183
|
+
### Programs and sysvars passed as remaining accounts
|
|
184
|
+
|
|
185
|
+
See [Calling other programs: programs and sysvars passed as remaining
|
|
186
|
+
accounts](language-cpi.md#programs-and-sysvars-passed-as-remaining-accounts).
|
|
187
|
+
|
|
188
|
+
### Porting a native program
|
|
189
|
+
|
|
190
|
+
See [Porting a native program](language-native.md): the [fallback entry](language-native.md#the-fallback-entry),
|
|
191
|
+
[accounts without a discriminator](language-native.md#accounts-without-a-discriminator),
|
|
192
|
+
[writes as the original makes them](language-native.md#writes-as-the-original-makes-them) (`NATIVE_ACCOUNT_WRITES`),
|
|
193
|
+
[closing and resizing by hand](language-native.md#accounts-closed-reassigned-and-resized-by-hand),
|
|
194
|
+
[errors and panics](language-native.md#errors-and-panics-as-the-original-reports-them),
|
|
195
|
+
[log lines](language-native.md#log-lines-as-the-original-writes-them),
|
|
196
|
+
[byte strings](language-native.md#byte-strings-built-by-hand) and
|
|
197
|
+
[return data](language-native.md#return-data-as-the-original-sets-it).
|
|
474
198
|
|
|
475
|
-
|
|
476
|
-
`create_account` (which would fail).
|
|
199
|
+
**Next:** [Language basics](language-basics.md).
|