@typesol/cli 0.28.0 → 0.30.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 (48) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +2 -2
  3. package/dist/cli.js +13 -20
  4. package/dist/compiler/analyze.d.ts +6 -2
  5. package/dist/compiler/analyze.js +57 -15
  6. package/dist/compiler/diagnostics.d.ts +2 -0
  7. package/dist/compiler/diagnostics.js +3 -2
  8. package/dist/compiler/emit/alias.d.ts +48 -0
  9. package/dist/compiler/emit/alias.js +166 -0
  10. package/dist/compiler/emit/borsh.js +6 -3
  11. package/dist/compiler/emit/calls.js +21 -4
  12. package/dist/compiler/emit/cpi-core.d.ts +70 -0
  13. package/dist/compiler/emit/cpi-core.js +356 -0
  14. package/dist/compiler/emit/cpi.d.ts +3 -177
  15. package/dist/compiler/emit/cpi.js +13 -2721
  16. package/dist/compiler/emit/create.d.ts +39 -0
  17. package/dist/compiler/emit/create.js +548 -0
  18. package/dist/compiler/emit/function.d.ts +11 -2
  19. package/dist/compiler/emit/function.js +42 -7
  20. package/dist/compiler/emit/metaplex.d.ts +78 -0
  21. package/dist/compiler/emit/metaplex.js +1345 -0
  22. package/dist/compiler/emit/program.js +24 -4
  23. package/dist/compiler/emit/shared.d.ts +7 -1
  24. package/dist/compiler/emit/shared.js +11 -2
  25. package/dist/compiler/emit/statements.d.ts +0 -9
  26. package/dist/compiler/emit/statements.js +2 -53
  27. package/dist/compiler/emit/storage.d.ts +5 -20
  28. package/dist/compiler/emit/storage.js +40 -106
  29. package/dist/compiler/emit/token.d.ts +8 -0
  30. package/dist/compiler/emit/token.js +493 -0
  31. package/dist/compiler/index.js +1 -1
  32. package/dist/compiler/model.d.ts +10 -2
  33. package/dist/compiler/model.js +7 -1
  34. package/dist/tools/portgen.js +3 -0
  35. package/dist/workspace.d.ts +1 -1
  36. package/dist/workspace.js +3 -1
  37. package/docs/architecture.md +30 -2
  38. package/docs/audit.md +3 -2
  39. package/docs/case-study-multisig.md +31 -29
  40. package/docs/cli.md +7 -4
  41. package/docs/errors.md +3 -2
  42. package/docs/language.md +4 -3
  43. package/docs/migrate-from-anchor.md +3 -3
  44. package/docs/security-model.md +1 -1
  45. package/lib/typesol.d.ts +17 -6
  46. package/package.json +1 -1
  47. package/runtime/typesol_rt.h +85 -1
  48. package/ts-plugin/index.js +75 -39
@@ -1,161 +1,7 @@
1
1
  import ts from "typescript";
2
- import { type AccountParam, type IdlSeed, type ValueType } from "../model.js";
3
- import { type Value } from "./shared.js";
4
- import { CallEmitter } from "./calls.js";
5
- /** One piece of a Metaplex instruction's Borsh data: fixed bytes, or a value lowered and serialized in source order. */
6
- type MplField = {
7
- bytes: number[];
8
- } | {
9
- value: ts.Expression;
10
- type: ValueType;
11
- } | {
12
- c: string;
13
- n: string;
14
- };
15
- /**
16
- * Other programs: PDAs and seeds, account creation, System/Token/ATA/Metaplex CPIs, generic invoke, Borsh
17
- * serialization and events.
18
- */
19
- export declare abstract class CpiEmitter extends CallEmitter {
20
- /**
21
- * Lower a seeds array literal into a `SolSignerSeed[]` with `extra` spare slots. Also describes
22
- * the seeds in Anchor IDL terms when every element is a constant, an argument or an account path.
23
- */
24
- protected seeds(node: ts.Expression, extra: number): {
25
- name: string;
26
- count: number;
27
- idl: IdlSeed[] | undefined;
28
- };
29
- protected describeSeed(el: ts.Expression): IdlSeed | undefined;
30
- protected recordPda(account: AccountParam, idl: IdlSeed[] | undefined): void;
31
- protected create(node: ts.CallExpression, target: AccountParam, topLevel: boolean, ifNeeded?: boolean): Value;
32
- /**
33
- * `vault.create(payer, seeds | null, mint, authority)` on `Init<TokenAccount>` and `mint.create(payer, seeds | null,
34
- * decimals, authority, freezeAuthority | null)` on `Init<Mint>` (Anchor's `init` with `token::` / `mint::`
35
- * constraints): a PDA of this program (or, with `null`, a new keypair account that signs), created owned by the
36
- * instruction's token program and initialized. `createIfNeeded` on `InitIfNeeded<…>` does that unless the account
37
- * exists, and then checks it is that PDA, owned by the token program, and has that mint and owner / those
38
- * authorities and decimals (Anchor's init_if_needed checks). create returns the bump (0 for a keypair),
39
- * createIfNeeded whether it created the account.
40
- */
41
- protected createToken(node: ts.CallExpression, target: AccountParam, topLevel: boolean): Value;
42
- /**
43
- * The extensions in `mint.create(…, { … })` (Anchor's `extensions::…` constraints): their values are evaluated now,
44
- * in source order; the returned lines (each extension's Token-2022 initializer, mint writable, before
45
- * InitializeMint2) run after the account is created, sized for exactly these extensions.
46
- */
47
- protected mintExtensions(lit: ts.ObjectLiteralExpression, tp: string, acct: string, ifNeeded?: boolean): {
48
- space: number;
49
- lines: string[];
50
- checks: string[];
51
- };
52
- /**
53
- * `ata.create(payer)` / `ata.createIfNeeded(payer)` on `Ata<Init|InitIfNeeded<TokenAccount>, "owner", "mint">`
54
- * (Anchor's `init` / `init_if_needed` with `associated_token::…`). create always calls the ATA program's Create, which
55
- * fails if the account exists. createIfNeeded calls it only when the account is still a System account (Anchor's
56
- * test) and otherwise checks that the existing account is that ATA. Either way the account is then checked as an
57
- * initialized token account of that mint and owner, and is a TokenAccount from here on.
58
- */
59
- protected createAta(node: ts.CallExpression, target: AccountParam, topLevel: boolean): Value | undefined;
60
- protected systemTransfer(node: ts.CallExpression): undefined;
61
- /** systemProgram.createAccount(payer, account, lamports, space, owner, signerSeeds?) */
62
- protected createAccount(node: ts.CallExpression, system: AccountParam): undefined;
63
- /**
64
- * Emit a CPI to the program account `program` with these metas (account, writable, signer), and then (`tail`) a range
65
- * of the remaining accounts, read-only (a Merkle proof).
66
- */
67
- protected cpi(program: string, metas: [string, boolean, boolean][], buf: string, len: string, seeds: {
68
- name: string;
69
- count: number | string;
70
- }, tail?: {
71
- from: string;
72
- to: string;
73
- asPassed?: boolean;
74
- }): void;
75
- protected signerSeeds(node: ts.Expression | undefined, authority: AccountParam, at: ts.Node): {
76
- name: string;
77
- count: number | string;
78
- };
79
- /** Seeds to sign a CPI with: an array literal, or a helper's SignerSeeds parameter. */
80
- protected signingSeeds(node: ts.Expression): {
81
- name: string;
82
- count: number | string;
83
- };
84
- protected tokenOp(node: ts.CallExpression, program: AccountParam, method: string): undefined;
85
- protected ataOp(node: ts.CallExpression, program: AccountParam, method: string): undefined;
86
- protected metadataOp(node: ts.CallExpression, program: AccountParam, method: string): undefined;
87
- /** CreateMasterEditionV3 (17) and Verify (52) with VerificationArgs::CollectionV1. */
88
- protected metadataCollectionOp(node: ts.CallExpression, program: AccountParam, method: string): undefined;
89
- /**
90
- * One account of a Metaplex CPI: an account parameter, or `null` for an optional account left out
91
- * (Metaplex programs take their own id in its place).
92
- */
93
- protected mplMeta(n: ts.Expression, program: AccountParam, what: string, writable: boolean, signer: boolean): [string, boolean, boolean];
94
- /** Borsh fields into a fresh buffer: raw bytes ("u8:N" style) or lowered values. */
95
- protected mplData(at: ts.Node, max: number, fields: MplField[]): {
96
- buf: string;
97
- len: string;
98
- };
99
- /**
100
- * Borsh of one Metaplex Core plugin literal (`{ kind: "FreezeDelegate", frozen: true, authority?: … }`): the Plugin
101
- * enum, then (`withAuthority`) the Option<PluginAuthority> that CreateV1's PluginAuthorityPair and AddPluginV1 take.
102
- */
103
- protected corePlugin(n: ts.Expression, withAuthority: boolean): MplField[];
104
- /** CreateV1 / CreateCollectionV1 plugins: Option<Vec<PluginAuthorityPair>>. */
105
- protected corePluginList(n: ts.Expression | undefined): MplField[];
106
- /**
107
- * Metaplex Core: assets and collections (with plugins), plugins and external plugin adapters added, updated, written
108
- * and removed, transfer and burn. Each method is a row of CORE_OPS below: its accounts in order, its data.
109
- */
110
- protected coreOp(node: ts.CallExpression, core: AccountParam, method: string): undefined;
111
- /**
112
- * Core instructions: `args` fixed arguments (then an optional plugin list when `plugins`, then optional signer
113
- * seeds), accounts in order (`[argument, label, writable, signer]`, or "self": the Core program, Core's "none" for an
114
- * optional account), at most `max` bytes of data.
115
- */
116
- private coreOps;
117
- /** The fields of a Core object literal (`{ kind: "AppData", … }`) by name. */
118
- private coreProps;
119
- /** PluginAuthority: "none" | "owner" | "updateAuthority" (literals), or an address. */
120
- private coreAuthority;
121
- private coreOption;
122
- private coreSchema;
123
- /** Vec<(HookableLifecycleEvent, ExternalCheckResult)>: `[{ event: "transfer", canReject: true }, …]`. */
124
- private coreChecks;
125
- /** ExtraAccount: `{ kind: "address", address, isSigner?, isWritable? }` or a preconfigured one (`{ kind: "owner" }`, …). */
126
- private coreExtraAccount;
127
- /**
128
- * ExternalPluginAdapterInitInfo from a literal: `{ kind: "AppData", dataAuthority, schema? }`, `{ kind: "Oracle",
129
- * baseAddress, checks, resultsOffset?, baseAddressConfig? }`, `{ kind: "LifecycleHook", hookedProgram, checks,
130
- * extraAccounts?, dataAuthority?, schema? }` and the Linked forms (collections); `authority?` is the plugin's own.
131
- */
132
- protected coreExternalPlugin(n: ts.Expression): MplField[];
133
- /** ExternalPluginAdapterKey: `{ kind: "AppData", dataAuthority }`, `{ kind: "Oracle", address }`, `{ kind: "LifecycleHook", address }`, … */
134
- protected coreExternalKey(n: ts.Expression): MplField[];
135
- /** The data written: Option<Vec<u8>> from a string, a Vec<u8> argument, or null (clears it). */
136
- protected coreExternalData(n: ts.Expression): MplField[];
137
- /** PluginType (u8) from a kind string literal: removePlugin(…, "FreezeDelegate"). */
138
- protected corePluginType(n: ts.Expression): MplField;
139
- /** Bubblegum (compressed NFTs on SPL account compression): createTree, mint (MintV1, no collection, no creators). */
140
- protected bubblegumOp(node: ts.CallExpression, bg: AccountParam, method: string): undefined;
141
- /** Bubblegum V2 (trees on mpl-account-compression with mpl-noop; optional Metaplex Core collections). */
142
- protected bubblegumV2(node: ts.CallExpression, bg: AccountParam, method: string): undefined;
143
- /** Object literal properties by name, refusing others. */
144
- protected literalProps(o: ts.ObjectLiteralExpression, allowed: string[], what: string): Map<string, ts.Expression>;
145
- /** Vec<Creator> (address, verified, share) from a literal list; shares add up to 100 when literal. */
146
- protected bubblegumCreators(creators: ts.Expression | undefined): MplField[];
147
- /** UpdateArgs: every field optional (left out or null: unchanged). */
148
- protected bubblegumUpdateArgs(n: ts.Expression): MplField[];
149
- /** `acct.key` of an account parameter, as an expression to serialize. */
150
- protected keyOf(n: ts.Expression): ts.Expression;
151
- /**
152
- * `remainingAccounts()` (or a const bound to it): every remaining account; `rest.slice(a, b?)`: indexes a..b of them
153
- * (both checked against the count, 5104). C expressions for the range, relative to the first remaining account.
154
- */
155
- protected remainingRange(node: ts.Expression): {
156
- from: string;
157
- to: string;
158
- } | undefined;
2
+ import { MetaplexEmitter } from "./metaplex.js";
3
+ /** Generic CPIs (`invoke`, `invokeInstruction`) and events (`emit`, `emitCpi`). */
4
+ export declare abstract class CpiEmitter extends MetaplexEmitter {
159
5
  protected invoke(node: ts.CallExpression): undefined;
160
6
  /**
161
7
  * `invokeInstruction(programId, metas, data, infos, signerSeeds?)`: a CPI decided at run time (Rust's
@@ -166,21 +12,6 @@ export declare abstract class CpiEmitter extends CallEmitter {
166
12
  * writable as the transaction passed it, or a PDA of this program that `signerSeeds` sign for.
167
13
  */
168
14
  protected invokeInstruction(node: ts.CallExpression): undefined;
169
- /**
170
- * A byte buffer written front to back. Its C declaration is patched in afterwards so it is
171
- * exactly as large as the fixed content, and only falls back to `max` when strings make it dynamic.
172
- */
173
- protected byteBuffer(prefix: string, max: number, errorCode: string, what: string): {
174
- buf: string;
175
- len: string;
176
- put: (src: string, n: string, bytes?: number) => void;
177
- finish: (at: ts.Node) => void;
178
- };
179
- /** Append a value's Borsh encoding through `put(srcPointer, byteCount)`. */
180
- protected serialize(v: Value, node: ts.Node, put: (src: string, n: string, bytes?: number) => void): void;
181
- /** Borsh-encode a data-enum place: the tag byte, then the active variant's fields. */
182
- protected serializeDataEnum(node: ts.Expression, name: string, put: (src: string, n: string, bytes?: number) => void): void;
183
- protected serializeDataEnumLv(lv: string, name: string, put: (src: string, n: string, bytes?: number) => void): void;
184
15
  protected emitEvent(node: ts.CallExpression, cpi?: {
185
16
  authority: string;
186
17
  program: string;
@@ -189,9 +20,4 @@ export declare abstract class CpiEmitter extends CallEmitter {
189
20
  private emitBorshEvent;
190
21
  /** Discriminator + `body`, logged (emit) or self-invoked (emitCpi). */
191
22
  private sendEvent;
192
- /** Structs reachable through the fields of struct `name` (not including itself unless it recurses). */
193
- protected nestedStructs(name: string): Set<string>;
194
- /** Structs whose IDL description is the fixed layout: account data, arguments, and everything nested in them. */
195
- protected fixedLayoutStructs(): Set<string>;
196
23
  }
197
- export {};