@givelotus/compiler 0.0.0-stage → 0.1.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 (87) hide show
  1. package/README.md +331 -2
  2. package/artifact-v2.schema.json +58 -0
  3. package/artifact.schema.json +19 -0
  4. package/dist/ast.d.ts +292 -0
  5. package/dist/ast.js +150 -0
  6. package/dist/bindings.d.ts +6 -0
  7. package/dist/bindings.js +134 -0
  8. package/dist/call-runtime.d.ts +84 -0
  9. package/dist/call-runtime.js +249 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +22 -0
  12. package/dist/compiler.d.ts +79 -0
  13. package/dist/compiler.js +125 -0
  14. package/dist/diagnostics.d.ts +163 -0
  15. package/dist/diagnostics.js +498 -0
  16. package/dist/ecash.d.ts +41 -0
  17. package/dist/ecash.js +190 -0
  18. package/dist/fees.d.ts +164 -0
  19. package/dist/fees.js +208 -0
  20. package/dist/fixture-cli.d.ts +2 -0
  21. package/dist/fixture-cli.js +41 -0
  22. package/dist/fixtures.d.ts +68 -0
  23. package/dist/fixtures.js +46 -0
  24. package/dist/forth-ir.d.ts +73 -0
  25. package/dist/forth-ir.js +147 -0
  26. package/dist/generic-cli.d.ts +2 -0
  27. package/dist/generic-cli.js +140 -0
  28. package/dist/generic.d.ts +48 -0
  29. package/dist/generic.js +2566 -0
  30. package/dist/lints.d.ts +8 -0
  31. package/dist/lints.js +204 -0
  32. package/dist/names.d.ts +1 -0
  33. package/dist/names.js +7 -0
  34. package/dist/opcodes.d.ts +154 -0
  35. package/dist/opcodes.js +162 -0
  36. package/dist/optimizer.d.ts +58 -0
  37. package/dist/optimizer.js +786 -0
  38. package/dist/package-fetch-cli.d.ts +2 -0
  39. package/dist/package-fetch-cli.js +17 -0
  40. package/dist/package-lock-cli.d.ts +2 -0
  41. package/dist/package-lock-cli.js +28 -0
  42. package/dist/package-sources.d.ts +82 -0
  43. package/dist/package-sources.js +785 -0
  44. package/dist/package-update-cli.d.ts +2 -0
  45. package/dist/package-update-cli.js +20 -0
  46. package/dist/packages.d.ts +231 -0
  47. package/dist/packages.js +1307 -0
  48. package/dist/parser.d.ts +32 -0
  49. package/dist/parser.js +575 -0
  50. package/dist/policy.d.ts +83 -0
  51. package/dist/policy.js +207 -0
  52. package/dist/runtime.d.ts +58 -0
  53. package/dist/runtime.js +126 -0
  54. package/dist/scheduler.d.ts +38 -0
  55. package/dist/scheduler.js +76 -0
  56. package/dist/semantic-ir.d.ts +76 -0
  57. package/dist/semantic-ir.js +231 -0
  58. package/dist/std.d.ts +27 -0
  59. package/dist/std.js +225 -0
  60. package/dist/target-compiler.d.ts +9 -0
  61. package/dist/target-compiler.js +139 -0
  62. package/dist/targets.d.ts +53 -0
  63. package/dist/targets.js +67 -0
  64. package/dist/toml-subset.d.ts +19 -0
  65. package/dist/toml-subset.js +81 -0
  66. package/dist/transaction-runtime.d.ts +182 -0
  67. package/dist/transaction-runtime.js +646 -0
  68. package/dist/version.d.ts +3 -0
  69. package/dist/version.js +3 -0
  70. package/dist/vm-cost.d.ts +11 -0
  71. package/dist/vm-cost.js +541 -0
  72. package/package.json +71 -4
  73. package/policy-artifact.schema.json +20 -0
  74. package/std/custody/arbiter-escrow.lotus +20 -0
  75. package/std/custody/htlc.lotus +15 -0
  76. package/std/custody/multisig-2of3.lotus +13 -0
  77. package/std/custody/single-owner-wallet.lotus +9 -0
  78. package/std/custody/vault-with-recovery.lotus +14 -0
  79. package/std/defi/amm-pool-v2.lotus +97 -0
  80. package/std/defi/indexed-limit-order.lotus +37 -0
  81. package/std/nft/nft-collection.lotus +51 -0
  82. package/std/nft/royalty-transfer-rules.lotus +38 -0
  83. package/std/nft/unique-nft.lotus +30 -0
  84. package/std/tokens/capped-supply-token.lotus +76 -0
  85. package/std/tokens/fixed-supply-token.lotus +29 -0
  86. package/std/tokens/standard-transfer-rules.lotus +15 -0
  87. package/std/tokens/voucher-mint-token.lotus +31 -0
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Resolve one root module dependency that may name a branch or a `^`/`~` range,
4
+ * rewrite that manifest entry to an exact tag or commit, then fetch.
5
+ */
6
+ import { join } from 'node:path';
7
+ import { updatePackages } from './package-sources.js';
8
+ try {
9
+ const args = process.argv.slice(2);
10
+ const vendor = args.includes('--vendor');
11
+ const positional = args.filter(arg => !arg.startsWith('--'));
12
+ if (positional.length !== 2 || args.length !== positional.length + (vendor ? 1 : 0))
13
+ throw new Error('usage: lotus-package-update DIR SPEC [--vendor]');
14
+ updatePackages(positional[0], positional[1], { vendor });
15
+ process.stdout.write(`wrote ${join(positional[0], 'lotus.lock')}\n`);
16
+ }
17
+ catch (err) {
18
+ process.stderr.write(`${err.message}\n`);
19
+ process.exitCode = 1;
20
+ }
@@ -0,0 +1,231 @@
1
+ import { type Span } from './compiler.js';
2
+ import { CompileError, SourceManager } from './diagnostics.js';
3
+ import { type BoundValue, type CompileOptions, type CompilerEdition, type ContractArtifact, type LanguageVersion, type OptimizerVersion, type SchedulerEvent } from './generic.js';
4
+ import { type FetchOptions } from './package-sources.js';
5
+ export { COMPILER_NAME, COMPILER_VERSION } from './version.js';
6
+ export declare const MANIFEST_FILE = "lotus.toml";
7
+ export declare const LOCK_FILE = "lotus.lock";
8
+ export declare const LOCK_SCHEMA = "lotus/package-lock/1";
9
+ export declare const BUILD_GRAPH_SCHEMA = "lotus/build-graph/1";
10
+ export type PackageLimits = {
11
+ maxPackages: number;
12
+ maxModules: number;
13
+ maxImportDepth: number;
14
+ maxImportBindings: number;
15
+ maxSourceBytes: number;
16
+ };
17
+ export declare const DEFAULT_PACKAGE_LIMITS: PackageLimits;
18
+ export type PackageErrorCode = 'manifest' | 'path-escape' | 'symlink-escape' | 'path-collision' | 'undeclared-file' | 'missing-module' | 'lock-missing' | 'lock-mismatch' | 'lock-stale' | 'version-conflict' | 'package-cycle' | 'parse' | 'unknown-alias' | 'not-exported' | 'missing-symbol' | 'instance' | 'root-cycle' | 'visibility' | 'duplicate-name' | 'import-cycle' | 'declaration-only' | 'limit' | 'branch' | 'unfetched' | 'locator' | 'fetch';
19
+ /** Diagnostic with a project-relative file and an optional UTF-8 byte span (`file:start..end: message [code]`). */
20
+ export declare class PackageError extends Error {
21
+ readonly code: PackageErrorCode;
22
+ readonly detail: string;
23
+ readonly file?: string | undefined;
24
+ readonly span?: Span | undefined;
25
+ constructor(code: PackageErrorCode, detail: string, file?: string | undefined, span?: Span | undefined);
26
+ }
27
+ /** CLI view of a package error. The library still throws `PackageError` with its own code. */
28
+ export declare function packageCompileError(error: PackageError, sources?: SourceManager): CompileError;
29
+ export type Manifest = {
30
+ name: string;
31
+ version: string;
32
+ kind: 'library' | 'contract';
33
+ source: string;
34
+ modules: string[];
35
+ exports: string[];
36
+ entry?: string;
37
+ edition?: CompilerEdition;
38
+ optimizer?: OptimizerVersion;
39
+ /** alias -> `name@version` or `module@selector` */ dependencies: Map<string, string>;
40
+ /** Root-only locators. Short names are project-relative paths; other hosts are git URLs. */ sources: Map<string, string>;
41
+ /** Root-only module-path replacements (relative path or git locator). Never inherited. */ replace: Map<string, string>;
42
+ };
43
+ export type PackageFile = {
44
+ path: string;
45
+ digest: Uint8Array;
46
+ content: Uint8Array;
47
+ };
48
+ export type PackageInfo = {
49
+ id: string;
50
+ manifest: Manifest;
51
+ root: string;
52
+ manifestFile: string;
53
+ files: PackageFile[];
54
+ treeDigest: Uint8Array;
55
+ isRoot: boolean;
56
+ /** Git/replace packages record the selected tag (`vX.Y.Z`) or commit. Path packages omit it. */ selectedVersion?: string;
57
+ };
58
+ type LockPackage = {
59
+ name: string;
60
+ version: string;
61
+ locator: {
62
+ kind: 'path';
63
+ path: string;
64
+ };
65
+ root: string;
66
+ dependencies: Record<string, string>;
67
+ files: {
68
+ path: string;
69
+ digest: string;
70
+ }[];
71
+ treeDigest: string;
72
+ };
73
+ export type LockFile = {
74
+ schema: typeof LOCK_SCHEMA;
75
+ root: {
76
+ name: string;
77
+ version: string;
78
+ edition?: CompilerEdition;
79
+ optimizer?: OptimizerVersion;
80
+ dependencies: Record<string, string>;
81
+ };
82
+ packages: LockPackage[];
83
+ };
84
+ export type BuildGraph = {
85
+ schema: typeof BUILD_GRAPH_SCHEMA;
86
+ interfaceVersion?: 'lotus/module-interface/lc1';
87
+ instances?: {
88
+ name: string;
89
+ template: string;
90
+ bindings: ContractArtifact['bindings'];
91
+ root: string;
92
+ }[];
93
+ compiler: {
94
+ name: string;
95
+ version: string;
96
+ profile: 'optimized' | 'unoptimized';
97
+ edition?: CompilerEdition;
98
+ optimizerVersion?: OptimizerVersion;
99
+ };
100
+ target: string;
101
+ root: {
102
+ package: string;
103
+ module: string;
104
+ };
105
+ lockDigest: string;
106
+ packages: {
107
+ id: string;
108
+ name: string;
109
+ version: string;
110
+ root: string;
111
+ treeDigest: string;
112
+ dependencies: Record<string, string>;
113
+ }[];
114
+ modules: {
115
+ id: string;
116
+ package: string;
117
+ path: string;
118
+ file: string;
119
+ sourceDigest: string;
120
+ interfaceDigest: string;
121
+ exports: {
122
+ name: string;
123
+ signature: string;
124
+ digest: string;
125
+ }[];
126
+ imports: string[];
127
+ }[];
128
+ digest: string;
129
+ };
130
+ /** Explicit compile-time references, never state reads or deployment actions. */
131
+ export type ProgramBinding = BoundValue | {
132
+ root: string;
133
+ } | {
134
+ leaf: string;
135
+ };
136
+ export type ProgramInstance = {
137
+ template: string;
138
+ bindings: Record<string, ProgramBinding>;
139
+ };
140
+ export type PackageCompileOptions = Omit<CompileOptions, 'bindings'> & {
141
+ bindings: Record<string, Record<string, ProgramBinding>>;
142
+ /** LC1 only. Templates resolve in the entry module's import namespace. */
143
+ instances?: Record<string, ProgramInstance>;
144
+ limits?: Partial<PackageLimits>;
145
+ };
146
+ export type PackageBuild = {
147
+ artifact: ContractArtifact;
148
+ trace: SchedulerEvent[];
149
+ parses: Record<string, number>;
150
+ };
151
+ /** Project/package-relative path: no absolute paths, traversal, empty or `.` segments, backslashes. */
152
+ export declare function relPath(value: string, what: string, file: string): string;
153
+ export declare function parseManifest(text: string, file: string): Manifest;
154
+ export declare function scanPackage(project: string, locator: string, isRoot: boolean, budget: {
155
+ bytes: number;
156
+ limit: number;
157
+ }): PackageInfo;
158
+ export type Workspace = {
159
+ project: string;
160
+ root: PackageInfo;
161
+ packages: Map<string, PackageInfo>;
162
+ lockText: string;
163
+ /** Selected git packages by module path. Absent for a path-only graph so lock bytes stay schema 1. */ modules?: Map<string, PackageInfo>;
164
+ };
165
+ export declare function resolveWorkspace(projectDir: string, limits: PackageLimits, online?: FetchOptions): Workspace;
166
+ /** Compute the canonical lock text from local files only (no network). */
167
+ export declare function generateLock(projectDir: string, limits?: Partial<PackageLimits>): string;
168
+ /** Rewrite `lotus.lock` from local files. Returns the written text. */
169
+ export declare function updateLock(projectDir: string, limits?: Partial<PackageLimits>): string;
170
+ export declare function compilePackage(projectDir: string, options: PackageCompileOptions): Promise<PackageBuild>;
171
+ export declare const SPEND_BUNDLE_SCHEMA: "lotus/spend-bundle/1";
172
+ export type SpendBundleSourceFile = {
173
+ path: string;
174
+ content: string;
175
+ digest: string;
176
+ };
177
+ export type SpendBundle = {
178
+ schema: typeof SPEND_BUNDLE_SCHEMA;
179
+ contract: string;
180
+ kind: 'contract' | 'token';
181
+ edition: CompilerEdition;
182
+ optimizerVersion: OptimizerVersion;
183
+ languageVersion: LanguageVersion;
184
+ entryFile: string;
185
+ sources: SpendBundleSourceFile[];
186
+ bindings: Record<string, Record<string, BoundValue>>;
187
+ expectedRoot: string;
188
+ expectedMethods: {
189
+ name: string;
190
+ leaf: string;
191
+ scriptHex: string;
192
+ proof: string[];
193
+ }[];
194
+ bundleDigest: string;
195
+ };
196
+ export type SpendBundleOptions = {
197
+ edition?: CompilerEdition;
198
+ optimizerVersion?: OptimizerVersion;
199
+ optimize?: boolean;
200
+ languageVersion?: LanguageVersion;
201
+ bindings?: Record<string, Record<string, BoundValue>>;
202
+ entryFile?: string;
203
+ };
204
+ export type SpendBundleVerification = {
205
+ ok: boolean;
206
+ contractRoot: string;
207
+ recomputedRoot?: string;
208
+ matchesRoot: boolean;
209
+ matchesMethods: boolean;
210
+ edition: CompilerEdition;
211
+ optimizerVersion: OptimizerVersion;
212
+ artifact?: ContractArtifact;
213
+ error?: string;
214
+ };
215
+ /**
216
+ * Package canonical `.lotus` source files, compiler `edition`, `optimizerVersion`, constructor
217
+ * `bindings`, and expected `BranchRoot` + leaf commitments into a self-contained `SpendBundle`
218
+ * so covenant UTXOs remain permanently spendable and reproducible across compiler upgrades.
219
+ */
220
+ export declare function createSpendBundle(artifact: ContractArtifact, sources: string | Record<string, string> | readonly {
221
+ path: string;
222
+ content: string;
223
+ }[], options?: SpendBundleOptions): SpendBundle;
224
+ /**
225
+ * Verify that a `SpendBundle` has intact BLAKE3 source/bundle digests and that recompiling its
226
+ * sources under the pinned `edition` and `optimizerVersion` reproduces the exact byte-for-byte
227
+ * method leaf scripts, Merkle proofs, and 32-byte `BranchRoot`.
228
+ */
229
+ export declare function verifySpendBundleReproducibility(bundle: SpendBundle): SpendBundleVerification;
230
+ export declare const verifyBranchRootReproducibility: typeof verifySpendBundleReproducibility;
231
+ export declare function assertSpendBundleReproducibility(bundle: SpendBundle): ContractArtifact;