@givelotus/compiler 0.0.0-stage → 0.2.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/README.md +331 -2
- package/artifact-v2.schema.json +58 -0
- package/artifact.schema.json +19 -0
- package/dist/ast.d.ts +292 -0
- package/dist/ast.js +150 -0
- package/dist/bindings.d.ts +6 -0
- package/dist/bindings.js +134 -0
- package/dist/call-runtime.d.ts +84 -0
- package/dist/call-runtime.js +249 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +22 -0
- package/dist/compiler.d.ts +79 -0
- package/dist/compiler.js +125 -0
- package/dist/diagnostics.d.ts +163 -0
- package/dist/diagnostics.js +498 -0
- package/dist/ecash.d.ts +41 -0
- package/dist/ecash.js +190 -0
- package/dist/fees.d.ts +164 -0
- package/dist/fees.js +208 -0
- package/dist/fixture-cli.d.ts +2 -0
- package/dist/fixture-cli.js +41 -0
- package/dist/fixtures.d.ts +68 -0
- package/dist/fixtures.js +46 -0
- package/dist/forth-ir.d.ts +73 -0
- package/dist/forth-ir.js +147 -0
- package/dist/generic-cli.d.ts +2 -0
- package/dist/generic-cli.js +140 -0
- package/dist/generic.d.ts +48 -0
- package/dist/generic.js +2566 -0
- package/dist/lints.d.ts +8 -0
- package/dist/lints.js +204 -0
- package/dist/names.d.ts +1 -0
- package/dist/names.js +7 -0
- package/dist/opcodes.d.ts +154 -0
- package/dist/opcodes.js +162 -0
- package/dist/optimizer.d.ts +58 -0
- package/dist/optimizer.js +786 -0
- package/dist/package-fetch-cli.d.ts +2 -0
- package/dist/package-fetch-cli.js +17 -0
- package/dist/package-lock-cli.d.ts +2 -0
- package/dist/package-lock-cli.js +28 -0
- package/dist/package-sources.d.ts +82 -0
- package/dist/package-sources.js +785 -0
- package/dist/package-update-cli.d.ts +2 -0
- package/dist/package-update-cli.js +20 -0
- package/dist/packages.d.ts +231 -0
- package/dist/packages.js +1324 -0
- package/dist/parser.d.ts +32 -0
- package/dist/parser.js +575 -0
- package/dist/policy.d.ts +83 -0
- package/dist/policy.js +207 -0
- package/dist/runtime.d.ts +58 -0
- package/dist/runtime.js +126 -0
- package/dist/scheduler.d.ts +38 -0
- package/dist/scheduler.js +76 -0
- package/dist/semantic-ir.d.ts +76 -0
- package/dist/semantic-ir.js +231 -0
- package/dist/std.d.ts +27 -0
- package/dist/std.js +282 -0
- package/dist/target-compiler.d.ts +9 -0
- package/dist/target-compiler.js +139 -0
- package/dist/targets.d.ts +53 -0
- package/dist/targets.js +67 -0
- package/dist/token-cli.d.ts +2 -0
- package/dist/token-cli.js +82 -0
- package/dist/token-metadata.d.ts +43 -0
- package/dist/token-metadata.js +166 -0
- package/dist/toml-subset.d.ts +19 -0
- package/dist/toml-subset.js +81 -0
- package/dist/transaction-runtime.d.ts +182 -0
- package/dist/transaction-runtime.js +646 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +3 -0
- package/dist/vm-cost.d.ts +11 -0
- package/dist/vm-cost.js +541 -0
- package/package.json +74 -4
- package/policy-artifact.schema.json +20 -0
- package/std/custody/arbiter-escrow.lotus +20 -0
- package/std/custody/htlc.lotus +15 -0
- package/std/custody/multisig-2of3.lotus +13 -0
- package/std/custody/single-owner-wallet.lotus +9 -0
- package/std/custody/vault-with-recovery.lotus +14 -0
- package/std/defi/amm-pool-v2.lotus +97 -0
- package/std/defi/indexed-limit-order.lotus +37 -0
- package/std/nft/nft-collection.lotus +51 -0
- package/std/nft/royalty-transfer-rules.lotus +38 -0
- package/std/nft/unique-nft.lotus +30 -0
- package/std/tokens/capped-supply-token.lotus +76 -0
- package/std/tokens/fixed-supply-token.lotus +29 -0
- package/std/tokens/lrc20.lotus +26 -0
- package/std/tokens/standard-transfer-rules.lotus +15 -0
- package/std/tokens/stateful-token-merge.lotus +132 -0
- package/std/tokens/upgradable-token-rules.lotus +70 -0
- package/std/tokens/voucher-mint-token.lotus +31 -0
- package/std-pkg/lotus.toml +9 -0
- package/std-pkg/src/lrc20.lotus +38 -0
- package/std-pkg/src/stateful_token.lotus +131 -0
- package/std-pkg/src/upgradable.lotus +68 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/** Parser/validation safety ceilings, not target execution or consensus limits. */
|
|
2
|
+
export const SEMANTIC_IR_LIMITS = Object.freeze({ maxBytes: 8192, maxDepth: 64, maxNodes: 8192, maxArgs: 256 });
|
|
3
|
+
class InvalidSemanticIR extends Error {
|
|
4
|
+
diagnostic;
|
|
5
|
+
constructor(diagnostic) {
|
|
6
|
+
super(diagnostic.message);
|
|
7
|
+
this.diagnostic = diagnostic;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function record(value) {
|
|
11
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
12
|
+
return false;
|
|
13
|
+
const proto = Object.getPrototypeOf(value);
|
|
14
|
+
return (proto === null || proto === Object.prototype) && Object.getOwnPropertySymbols(value).length === 0
|
|
15
|
+
&& Object.values(Object.getOwnPropertyDescriptors(value)).every(descriptor => Object.hasOwn(descriptor, 'value'));
|
|
16
|
+
}
|
|
17
|
+
function validSpan(value) {
|
|
18
|
+
return record(value) && Object.keys(value).every(key => ['start', 'end', 'file'].includes(key))
|
|
19
|
+
&& Number.isSafeInteger(value.start) && Number.isSafeInteger(value.end)
|
|
20
|
+
&& value.start >= 0 && value.end >= value.start
|
|
21
|
+
&& (value.file === undefined || typeof value.file === 'string');
|
|
22
|
+
}
|
|
23
|
+
function copySpan(value) {
|
|
24
|
+
return value.file === undefined ? { start: value.start, end: value.end } : { start: value.start, end: value.end, file: value.file };
|
|
25
|
+
}
|
|
26
|
+
function fail(code, message, value) {
|
|
27
|
+
const span = record(value) && validSpan(value.span) ? copySpan(value.span) : undefined;
|
|
28
|
+
throw new InvalidSemanticIR({ code: `semantic-ir-${code}`, message, ...(span ? { span } : {}) });
|
|
29
|
+
}
|
|
30
|
+
function shape(value, fields, context) {
|
|
31
|
+
if (!record(value))
|
|
32
|
+
fail('shape', `${context} must be a plain object`, value);
|
|
33
|
+
const extra = Object.keys(value).find(key => !fields.includes(key));
|
|
34
|
+
if (extra !== undefined)
|
|
35
|
+
fail('shape', `unsupported ${context} field ${extra}`, value);
|
|
36
|
+
for (const field of fields)
|
|
37
|
+
if (!Object.hasOwn(value, field))
|
|
38
|
+
fail('shape', `${context} is missing ${field}`, value);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function span(value) {
|
|
42
|
+
if (!validSpan(value.span))
|
|
43
|
+
fail('span', 'span requires nonnegative safe UTF-8 byte offsets start <= end and optional file', value);
|
|
44
|
+
return copySpan(value.span);
|
|
45
|
+
}
|
|
46
|
+
function name(value, context, at) {
|
|
47
|
+
if (typeof value !== 'string' || !/^[A-Za-z_][A-Za-z_0-9]*$/.test(value))
|
|
48
|
+
fail('name', `${context} must be an identifier`, at);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
function denseArray(value, context) {
|
|
52
|
+
if (Object.getOwnPropertySymbols(value).length || Object.keys(value).some(key => !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= value.length))
|
|
53
|
+
fail('shape', `${context} must contain only array entries`);
|
|
54
|
+
for (let i = 0; i < value.length; i++) {
|
|
55
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(i));
|
|
56
|
+
if (!descriptor || !Object.hasOwn(descriptor, 'value'))
|
|
57
|
+
fail('shape', `${context} must be dense and contain no accessors`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function semanticType(value, at) {
|
|
61
|
+
if (!record(value))
|
|
62
|
+
fail('type', 'argument type must be bytes or bool', at);
|
|
63
|
+
if (value.kind === 'bool') {
|
|
64
|
+
shape(value, ['kind'], 'Boolean type');
|
|
65
|
+
return { kind: 'bool' };
|
|
66
|
+
}
|
|
67
|
+
if (value.kind === 'bytes') {
|
|
68
|
+
shape(value, ['kind', 'length'], 'byte type');
|
|
69
|
+
if (!Number.isSafeInteger(value.length) || value.length < 0 || value.length > SEMANTIC_IR_LIMITS.maxBytes)
|
|
70
|
+
fail('type', `exact byte length must be 0..${SEMANTIC_IR_LIMITS.maxBytes}`, at);
|
|
71
|
+
return { kind: 'bytes', length: value.length };
|
|
72
|
+
}
|
|
73
|
+
fail('unsupported', 'only portable bytes and bool types are supported; integers, signatures and reflection require a chain-specific IR', at);
|
|
74
|
+
}
|
|
75
|
+
function sameType(left, right) {
|
|
76
|
+
return left.kind === right.kind && (left.kind !== 'bytes' || right.kind === 'bytes' && left.length === right.length);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validate imported IR before backend selection. Fail closed on unknown constructs.
|
|
80
|
+
* The returned tree and spans are detached copies; capability occurrences retain
|
|
81
|
+
* source order and are not deduplicated. Equal requires matching exact byte widths
|
|
82
|
+
* (or two Bools); byte padding and Boolean/numeric coercion are never implicit.
|
|
83
|
+
* This checks semantics/shape only, not target support, stack bounds or execution.
|
|
84
|
+
*/
|
|
85
|
+
export function validateSemanticProgram(input) {
|
|
86
|
+
const requirements = [];
|
|
87
|
+
const args = new Map();
|
|
88
|
+
const active = new Set();
|
|
89
|
+
let nodes = 0;
|
|
90
|
+
const requireCapability = (capability, at) => {
|
|
91
|
+
requirements.push({ capability, span: copySpan(at) });
|
|
92
|
+
};
|
|
93
|
+
const typed = (type, at) => {
|
|
94
|
+
requireCapability(type.kind, at);
|
|
95
|
+
return type;
|
|
96
|
+
};
|
|
97
|
+
const visit = (value, depth) => {
|
|
98
|
+
if (depth > SEMANTIC_IR_LIMITS.maxDepth)
|
|
99
|
+
fail('limit', `IR nesting exceeds ${SEMANTIC_IR_LIMITS.maxDepth}`, value);
|
|
100
|
+
if (++nodes > SEMANTIC_IR_LIMITS.maxNodes)
|
|
101
|
+
fail('limit', `IR node budget exceeds ${SEMANTIC_IR_LIMITS.maxNodes}`, value);
|
|
102
|
+
if (value !== null && typeof value === 'object') {
|
|
103
|
+
if (active.has(value))
|
|
104
|
+
fail('cycle', 'cyclic IR is unsupported', value);
|
|
105
|
+
active.add(value);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const expression = (value, depth) => {
|
|
109
|
+
visit(value, depth);
|
|
110
|
+
if (!record(value))
|
|
111
|
+
fail('shape', 'expression must be a plain object', value);
|
|
112
|
+
let node, type;
|
|
113
|
+
const at = span(value);
|
|
114
|
+
switch (value.kind) {
|
|
115
|
+
case 'bytes': {
|
|
116
|
+
shape(value, ['kind', 'hex', 'span'], 'byte constant');
|
|
117
|
+
if (typeof value.hex !== 'string' || value.hex.length > SEMANTIC_IR_LIMITS.maxBytes * 2 || !/^(?:[0-9a-f]{2})*$/.test(value.hex))
|
|
118
|
+
fail('constant', `byte constant must be lowercase even-length hex of at most ${SEMANTIC_IR_LIMITS.maxBytes} bytes`, value);
|
|
119
|
+
node = { kind: 'bytes', hex: value.hex, span: at };
|
|
120
|
+
type = { kind: 'bytes', length: value.hex.length / 2 };
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case 'bool':
|
|
124
|
+
shape(value, ['kind', 'value', 'span'], 'Boolean constant');
|
|
125
|
+
if (typeof value.value !== 'boolean')
|
|
126
|
+
fail('constant', 'Boolean constant must be true or false', value);
|
|
127
|
+
node = { kind: 'bool', value: value.value, span: at };
|
|
128
|
+
type = { kind: 'bool' };
|
|
129
|
+
break;
|
|
130
|
+
case 'arg': {
|
|
131
|
+
shape(value, ['kind', 'name', 'span'], 'argument reference');
|
|
132
|
+
const arg = name(value.name, 'argument reference', value), found = args.get(arg);
|
|
133
|
+
if (!found)
|
|
134
|
+
fail('argument', `unbound argument ${arg}`, value);
|
|
135
|
+
node = { kind: 'arg', name: arg, span: at };
|
|
136
|
+
type = { ...found };
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case 'sha256':
|
|
140
|
+
case 'hash256': {
|
|
141
|
+
shape(value, ['kind', 'value', 'span'], 'hash expression');
|
|
142
|
+
const operand = expression(value.value, depth + 1);
|
|
143
|
+
if (operand.type.kind !== 'bytes')
|
|
144
|
+
fail('type', `${value.kind} requires bytes`, value);
|
|
145
|
+
node = { kind: value.kind, value: operand.node, span: at };
|
|
146
|
+
type = { kind: 'bytes', length: 32 };
|
|
147
|
+
requireCapability(value.kind, at);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 'equal': {
|
|
151
|
+
shape(value, ['kind', 'left', 'right', 'span'], 'equality expression');
|
|
152
|
+
const left = expression(value.left, depth + 1), right = expression(value.right, depth + 1);
|
|
153
|
+
if (!sameType(left.type, right.type))
|
|
154
|
+
fail('type', 'equal requires two Bools or byte values of the same exact length', value);
|
|
155
|
+
node = { kind: 'equal', left: left.node, right: right.node, span: at };
|
|
156
|
+
type = { kind: 'bool' };
|
|
157
|
+
requireCapability('byte-equality', at);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
default: fail('unsupported', `unsupported portable expression ${typeof value.kind === 'string' ? value.kind : typeof value.kind}; chain-specific integer, signature and reflection operations are unavailable`, value);
|
|
161
|
+
}
|
|
162
|
+
typed(type, at);
|
|
163
|
+
active.delete(value);
|
|
164
|
+
return { node, type };
|
|
165
|
+
};
|
|
166
|
+
const statements = (value, depth) => {
|
|
167
|
+
if (!Array.isArray(value))
|
|
168
|
+
fail('shape', 'statement body must be an array');
|
|
169
|
+
if (value.length > SEMANTIC_IR_LIMITS.maxNodes)
|
|
170
|
+
fail('limit', 'statement array exceeds IR node budget');
|
|
171
|
+
denseArray(value, 'statement array');
|
|
172
|
+
return value.map(raw => {
|
|
173
|
+
visit(raw, depth);
|
|
174
|
+
if (!record(raw))
|
|
175
|
+
fail('shape', 'statement must be a plain object', raw);
|
|
176
|
+
const at = span(raw);
|
|
177
|
+
let result;
|
|
178
|
+
if (raw.kind === 'require') {
|
|
179
|
+
shape(raw, ['kind', 'condition', 'span'], 'require statement');
|
|
180
|
+
const condition = expression(raw.condition, depth + 1);
|
|
181
|
+
if (condition.type.kind !== 'bool')
|
|
182
|
+
fail('type', 'require condition must be Bool', raw);
|
|
183
|
+
requireCapability('require', at);
|
|
184
|
+
result = { kind: 'require', condition: condition.node, span: at };
|
|
185
|
+
}
|
|
186
|
+
else if (raw.kind === 'if') {
|
|
187
|
+
shape(raw, ['kind', 'condition', 'then', 'otherwise', 'span'], 'if statement');
|
|
188
|
+
const condition = expression(raw.condition, depth + 1);
|
|
189
|
+
if (condition.type.kind !== 'bool')
|
|
190
|
+
fail('type', 'if condition must be Bool', raw);
|
|
191
|
+
requireCapability('if', at);
|
|
192
|
+
result = { kind: 'if', condition: condition.node, then: statements(raw.then, depth + 1), otherwise: statements(raw.otherwise, depth + 1), span: at };
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
fail('unsupported', `unsupported portable statement ${typeof raw.kind === 'string' ? raw.kind : typeof raw.kind}; chain-specific invocation, loops and reflection are unavailable`, raw);
|
|
196
|
+
active.delete(raw);
|
|
197
|
+
return result;
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
try {
|
|
201
|
+
const raw = shape(input, ['schema', 'entrypoint', 'args', 'body', 'span'], 'semantic program');
|
|
202
|
+
if (raw.schema !== 'lotus/semantic-ir/1')
|
|
203
|
+
fail('schema', 'unsupported semantic IR schema', raw);
|
|
204
|
+
const at = span(raw), entrypoint = name(raw.entrypoint, 'entrypoint', raw);
|
|
205
|
+
visit(raw, 0);
|
|
206
|
+
if (!Array.isArray(raw.args))
|
|
207
|
+
fail('shape', 'args must be an array', raw);
|
|
208
|
+
if (raw.args.length > SEMANTIC_IR_LIMITS.maxArgs)
|
|
209
|
+
fail('limit', `argument count exceeds ${SEMANTIC_IR_LIMITS.maxArgs}`, raw);
|
|
210
|
+
denseArray(raw.args, 'argument array');
|
|
211
|
+
const declarations = raw.args.map(arg => {
|
|
212
|
+
visit(arg, 1);
|
|
213
|
+
const item = shape(arg, ['name', 'type', 'span'], 'argument declaration'), location = span(item);
|
|
214
|
+
const identifier = name(item.name, 'argument name', item);
|
|
215
|
+
if (args.has(identifier))
|
|
216
|
+
fail('argument', `duplicate argument ${identifier}`, item);
|
|
217
|
+
const type = semanticType(item.type, item);
|
|
218
|
+
args.set(identifier, type);
|
|
219
|
+
typed(type, location);
|
|
220
|
+
active.delete(item);
|
|
221
|
+
return { name: identifier, type, span: location };
|
|
222
|
+
});
|
|
223
|
+
const program = { schema: 'lotus/semantic-ir/1', entrypoint, args: declarations, body: statements(raw.body, 1), span: at };
|
|
224
|
+
return { ok: true, program, requirements };
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (error instanceof InvalidSemanticIR)
|
|
228
|
+
return { ok: false, diagnostics: [error.diagnostic] };
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
package/dist/std.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type BoundValue, type ContractArtifact } from './generic.js';
|
|
2
|
+
import type { Diagnostic } from './diagnostics.js';
|
|
3
|
+
export type StandardContractCategory = 'tokens' | 'nft' | 'custody' | 'defi';
|
|
4
|
+
export type StandardContractSpec = {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly contract: string;
|
|
7
|
+
readonly kind: 'contract' | 'token';
|
|
8
|
+
readonly category: StandardContractCategory;
|
|
9
|
+
readonly file: string;
|
|
10
|
+
readonly summary: string;
|
|
11
|
+
readonly walletBadge: string;
|
|
12
|
+
/** Human-readable method action templates for wallet signing prompts. */
|
|
13
|
+
readonly actions: Readonly<Record<string, string>>;
|
|
14
|
+
/** For zero-parameter universal templates, the fixed well-known MAST BranchRoot. */
|
|
15
|
+
readonly universalRoot?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Universal BranchRoot of StandardTransferRules (zero-parameter, zero-freeze, zero-tax). */
|
|
18
|
+
export declare const UNIVERSAL_STANDARD_TRANSFER_RULES_ROOT = "985e7562c70c1577cd7acdd208c0dfa36683860e0ed1931ed77574866389dbdc";
|
|
19
|
+
export declare const STANDARD_CONTRACTS: readonly StandardContractSpec[];
|
|
20
|
+
export declare function getStandardContract(id: string): StandardContractSpec | undefined;
|
|
21
|
+
export declare function readStandardContractSource(id: string): string;
|
|
22
|
+
export declare function compileStandardContract(id: string, bindings?: Record<string, BoundValue>): {
|
|
23
|
+
spec: StandardContractSpec;
|
|
24
|
+
artifact: ContractArtifact;
|
|
25
|
+
warnings: Diagnostic[];
|
|
26
|
+
};
|
|
27
|
+
export declare function identifyStandardTemplate(rootHex: string): StandardContractSpec | undefined;
|
package/dist/std.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 95/5 Canonical Standard Contract Library for Lotus (`@givelotus/compiler/std`).
|
|
3
|
+
*
|
|
4
|
+
* Pre-distributed, pragma-pinned standard templates with deterministic MAST BranchRoots
|
|
5
|
+
* and human-readable wallet/exchange intent metadata.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { compileContract, lintContract } from './generic.js';
|
|
11
|
+
const STD_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', 'std');
|
|
12
|
+
/** Universal BranchRoot of StandardTransferRules (zero-parameter, zero-freeze, zero-tax). */
|
|
13
|
+
export const UNIVERSAL_STANDARD_TRANSFER_RULES_ROOT = '985e7562c70c1577cd7acdd208c0dfa36683860e0ed1931ed77574866389dbdc';
|
|
14
|
+
export const STANDARD_CONTRACTS = Object.freeze([
|
|
15
|
+
// Fungible Tokens
|
|
16
|
+
{
|
|
17
|
+
id: 'std/tokens/standard-transfer-rules',
|
|
18
|
+
contract: 'StandardTransferRules',
|
|
19
|
+
kind: 'contract',
|
|
20
|
+
category: 'tokens',
|
|
21
|
+
file: 'tokens/standard-transfer-rules.lotus',
|
|
22
|
+
summary: 'Universal zero-freeze, zero-blacklist, zero-tax token transfer rules.',
|
|
23
|
+
walletBadge: 'Standard Token · No Freeze Controls (Verified on-chain)',
|
|
24
|
+
actions: { transfer: 'Transfer token while preserving standard no-freeze transfer rules' },
|
|
25
|
+
universalRoot: UNIVERSAL_STANDARD_TRANSFER_RULES_ROOT,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'std/tokens/fixed-supply-token',
|
|
29
|
+
contract: 'FixedSupplyToken',
|
|
30
|
+
kind: 'token',
|
|
31
|
+
category: 'tokens',
|
|
32
|
+
file: 'tokens/fixed-supply-token.lotus',
|
|
33
|
+
summary: 'One-shot fixed-supply fungible token bound to a single creator seed outpoint.',
|
|
34
|
+
walletBadge: 'Fixed Supply · One-Shot Genesis Mint',
|
|
35
|
+
actions: { issue: 'Mint the full fixed supply once by spending the genesis seed coin' },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'std/tokens/supply-controller',
|
|
39
|
+
contract: 'SupplyController',
|
|
40
|
+
kind: 'contract',
|
|
41
|
+
category: 'tokens',
|
|
42
|
+
file: 'tokens/capped-supply-token.lotus',
|
|
43
|
+
summary: 'HAS_STATE capped-supply mint controller with irreversible lock_mint.',
|
|
44
|
+
walletBadge: 'Capped Supply Controller',
|
|
45
|
+
actions: {
|
|
46
|
+
mint: 'Authorize minting up to max_supply and advance stateful issued counter',
|
|
47
|
+
lock_mint: 'Permanently lock future token minting (irreversible)',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'std/tokens/capped-supply-token',
|
|
52
|
+
contract: 'CappedSupplyToken',
|
|
53
|
+
kind: 'token',
|
|
54
|
+
category: 'tokens',
|
|
55
|
+
file: 'tokens/capped-supply-token.lotus',
|
|
56
|
+
summary: 'Capped-supply fungible token gated by a SupplyController authority coin.',
|
|
57
|
+
walletBadge: 'Capped Supply Token',
|
|
58
|
+
actions: { issue: 'Mint new tokens authorized by the SupplyController' },
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'std/tokens/voucher-mint-token',
|
|
62
|
+
contract: 'VoucherMintToken',
|
|
63
|
+
kind: 'token',
|
|
64
|
+
category: 'tokens',
|
|
65
|
+
file: 'tokens/voucher-mint-token.lotus',
|
|
66
|
+
summary: 'Outpoint-bound signed voucher mint token (parallel single-use mint codes).',
|
|
67
|
+
walletBadge: 'Issuer-Authorized Voucher Token',
|
|
68
|
+
actions: { mint_with_voucher: 'Mint tokens using an issuer-signed outpoint-bound voucher' },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'std/tokens/lrc20',
|
|
72
|
+
contract: 'MetadataFungibleToken',
|
|
73
|
+
kind: 'token',
|
|
74
|
+
category: 'tokens',
|
|
75
|
+
file: 'tokens/lrc20.lotus',
|
|
76
|
+
summary: 'Standard LRC-20 fungible token with immutable BLAKE3 metadata commitment.',
|
|
77
|
+
walletBadge: 'LRC-20 Fungible Token (Verified Metadata)',
|
|
78
|
+
actions: { issue: 'Mint LRC-20 tokens committed to canonical metadata hash' },
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'std/tokens/stateful-token-rules',
|
|
82
|
+
contract: 'StatefulTokenRules',
|
|
83
|
+
kind: 'contract',
|
|
84
|
+
category: 'tokens',
|
|
85
|
+
file: 'tokens/stateful-token-merge.lotus',
|
|
86
|
+
summary: 'Stateful token rules supporting transfer, 1-to-2 split, and 2-to-1 UTXO merge.',
|
|
87
|
+
walletBadge: 'Stateful Fungible Token (Split & Merge)',
|
|
88
|
+
actions: {
|
|
89
|
+
transfer: 'Transfer stateful token preserving state commitment',
|
|
90
|
+
split: 'Split stateful token conserving value and additive weight',
|
|
91
|
+
merge: 'Merge two stateful token UTXOs summing weight and preserving max lock',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'std/tokens/stateful-token',
|
|
96
|
+
contract: 'StatefulToken',
|
|
97
|
+
kind: 'token',
|
|
98
|
+
category: 'tokens',
|
|
99
|
+
file: 'tokens/stateful-token-merge.lotus',
|
|
100
|
+
summary: 'Mint tree for StatefulTokenRules initializing per-UTXO TokenState.',
|
|
101
|
+
walletBadge: 'Stateful Fungible Token Mint',
|
|
102
|
+
actions: { issue: 'Mint stateful tokens with initial weight and lock height' },
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: 'std/tokens/upgradable-rules',
|
|
106
|
+
contract: 'UpgradableRules',
|
|
107
|
+
kind: 'contract',
|
|
108
|
+
category: 'tokens',
|
|
109
|
+
file: 'tokens/upgradable-token-rules.lotus',
|
|
110
|
+
summary: 'In-place upgradable token rules migrated asynchronously via governance checkdatasig.',
|
|
111
|
+
walletBadge: 'Upgradable Token Rules (Governance Migration)',
|
|
112
|
+
actions: {
|
|
113
|
+
transfer: 'Transfer token preserving current rules contract',
|
|
114
|
+
upgrade_contract: 'Migrate token UTXOs in-place to governance-signed new rules root',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: 'std/tokens/upgradable-token',
|
|
119
|
+
contract: 'UpgradableToken',
|
|
120
|
+
kind: 'token',
|
|
121
|
+
category: 'tokens',
|
|
122
|
+
file: 'tokens/upgradable-token-rules.lotus',
|
|
123
|
+
summary: 'Mint tree for in-place upgradable tokens bound to initial_rules.',
|
|
124
|
+
walletBadge: 'Upgradable Token Mint',
|
|
125
|
+
actions: { issue: 'Mint tokens bound to the initial upgradable rules contract' },
|
|
126
|
+
},
|
|
127
|
+
// NFTs & Collections
|
|
128
|
+
{
|
|
129
|
+
id: 'std/nft/unique-nft',
|
|
130
|
+
contract: 'UniqueNFT',
|
|
131
|
+
kind: 'token',
|
|
132
|
+
category: 'nft',
|
|
133
|
+
file: 'nft/unique-nft.lotus',
|
|
134
|
+
summary: 'Unique 1-of-1 NFT with immutable metadata commitment hash.',
|
|
135
|
+
walletBadge: 'Unique 1-of-1 NFT',
|
|
136
|
+
actions: { mint: 'Mint unique 1-of-1 NFT with committed metadata hash' },
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: 'std/nft/collection-authority',
|
|
140
|
+
contract: 'NFTCollectionAuthority',
|
|
141
|
+
kind: 'contract',
|
|
142
|
+
category: 'nft',
|
|
143
|
+
file: 'nft/nft-collection.lotus',
|
|
144
|
+
summary: 'HAS_STATE bounded NFT collection authority tracking minted item count.',
|
|
145
|
+
walletBadge: 'NFT Collection Authority',
|
|
146
|
+
actions: { mint_next: 'Authorize minting the next NFT in the collection' },
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: 'std/nft/collection-mint',
|
|
150
|
+
contract: 'NFTCollectionMint',
|
|
151
|
+
kind: 'token',
|
|
152
|
+
category: 'nft',
|
|
153
|
+
file: 'nft/nft-collection.lotus',
|
|
154
|
+
summary: 'NFT collection token mint enforcing value == 1 per item.',
|
|
155
|
+
walletBadge: 'NFT Collection Item',
|
|
156
|
+
actions: { mint_item: 'Mint a single collection NFT (value = 1)' },
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: 'std/nft/royalty-transfer-rules',
|
|
160
|
+
contract: 'RoyaltyTransferRules',
|
|
161
|
+
kind: 'contract',
|
|
162
|
+
category: 'nft',
|
|
163
|
+
file: 'nft/royalty-transfer-rules.lotus',
|
|
164
|
+
summary: 'Royalty-bearing transfer rules requiring creator royalty output or exemption sig.',
|
|
165
|
+
walletBadge: 'Royalty Transfer Rules (Non-Standard)',
|
|
166
|
+
actions: {
|
|
167
|
+
transfer_with_royalty: 'Transfer token while paying creator royalty in XPI',
|
|
168
|
+
creator_exempt_transfer: 'Transfer token with creator royalty exemption signature',
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
// Core Money, Custody & Escrow
|
|
172
|
+
{
|
|
173
|
+
id: 'std/custody/single-owner-wallet',
|
|
174
|
+
contract: 'SingleOwnerWallet',
|
|
175
|
+
kind: 'contract',
|
|
176
|
+
category: 'custody',
|
|
177
|
+
file: 'custody/single-owner-wallet.lotus',
|
|
178
|
+
summary: 'Standard single-key BIP-340 Schnorr wallet branch.',
|
|
179
|
+
walletBadge: 'Single-Owner Wallet',
|
|
180
|
+
actions: { spend: 'Spend coins with owner signature' },
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: 'std/custody/multisig-2of3',
|
|
184
|
+
contract: 'Multisig2of3',
|
|
185
|
+
kind: 'contract',
|
|
186
|
+
category: 'custody',
|
|
187
|
+
file: 'custody/multisig-2of3.lotus',
|
|
188
|
+
summary: '2-of-3 threshold Schnorr multisig with BIP-340 abstain support.',
|
|
189
|
+
walletBadge: '2-of-3 Multisig',
|
|
190
|
+
actions: { spend: 'Spend coins with at least 2 of 3 signer signatures' },
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
id: 'std/custody/vault-with-recovery',
|
|
194
|
+
contract: 'VaultWithRecovery',
|
|
195
|
+
kind: 'contract',
|
|
196
|
+
category: 'custody',
|
|
197
|
+
file: 'custody/vault-with-recovery.lotus',
|
|
198
|
+
summary: 'Owner spend with time-locked guardian recovery.',
|
|
199
|
+
walletBadge: 'Recovery Vault',
|
|
200
|
+
actions: {
|
|
201
|
+
spend: 'Spend vault coins with owner signature',
|
|
202
|
+
recover: 'Recover vault coins with guardian signature after lock height',
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
id: 'std/custody/htlc',
|
|
207
|
+
contract: 'HTLC',
|
|
208
|
+
kind: 'contract',
|
|
209
|
+
category: 'custody',
|
|
210
|
+
file: 'custody/htlc.lotus',
|
|
211
|
+
summary: 'Hash Time-Locked Contract for trustless cross-chain atomic swaps.',
|
|
212
|
+
walletBadge: 'Atomic Swap HTLC',
|
|
213
|
+
actions: {
|
|
214
|
+
claim: 'Claim HTLC coins by revealing SHA-256 preimage with recipient signature',
|
|
215
|
+
refund: 'Refund HTLC coins after timeout height with refund signature',
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: 'std/custody/arbiter-escrow',
|
|
220
|
+
contract: 'ArbiterEscrow',
|
|
221
|
+
kind: 'contract',
|
|
222
|
+
category: 'custody',
|
|
223
|
+
file: 'custody/arbiter-escrow.lotus',
|
|
224
|
+
summary: '2-of-3 buyer/seller/arbiter escrow with timeout refund.',
|
|
225
|
+
walletBadge: 'Arbiter Escrow',
|
|
226
|
+
actions: {
|
|
227
|
+
release: 'Release escrow with buyer and seller signatures',
|
|
228
|
+
arbitrate: 'Resolve escrow dispute with arbiter and one party signature',
|
|
229
|
+
timeout_refund: 'Refund buyer after escrow timeout height',
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
// DeFi Primitives
|
|
233
|
+
{
|
|
234
|
+
id: 'std/defi/indexed-limit-order',
|
|
235
|
+
contract: 'IndexedLimitOrder',
|
|
236
|
+
kind: 'contract',
|
|
237
|
+
category: 'defi',
|
|
238
|
+
file: 'defi/indexed-limit-order.lotus',
|
|
239
|
+
summary: '0x-style partial-fill limit order with indexed injective payouts.',
|
|
240
|
+
walletBadge: 'Partial-Fill Limit Order',
|
|
241
|
+
actions: {
|
|
242
|
+
fill: 'Fill limit order (full or partial) paying maker at output 2*i',
|
|
243
|
+
cancel: 'Cancel open limit order and reclaim remaining funds',
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: 'std/defi/amm-pool-v2',
|
|
248
|
+
contract: 'AmmPoolV2',
|
|
249
|
+
kind: 'contract',
|
|
250
|
+
category: 'defi',
|
|
251
|
+
file: 'defi/amm-pool-v2.lotus',
|
|
252
|
+
summary: 'Profile B constant-product AMM using HAS_STATE, MUL128_WIDE, and SQRT.',
|
|
253
|
+
walletBadge: 'Constant-Product AMM (Zero Admin Keys)',
|
|
254
|
+
actions: {
|
|
255
|
+
first_deposit: 'Initialize AMM pool reserves and mint initial LP shares',
|
|
256
|
+
swap_0_for_1: 'Swap asset 0 for asset 1 preserving 256-bit constant-product invariant',
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
]);
|
|
260
|
+
export function getStandardContract(id) {
|
|
261
|
+
return STANDARD_CONTRACTS.find(spec => spec.id === id);
|
|
262
|
+
}
|
|
263
|
+
export function readStandardContractSource(id) {
|
|
264
|
+
const spec = getStandardContract(id);
|
|
265
|
+
if (!spec)
|
|
266
|
+
throw new Error(`unknown standard contract ${id}`);
|
|
267
|
+
return readFileSync(join(STD_ROOT, spec.file), 'utf8');
|
|
268
|
+
}
|
|
269
|
+
export function compileStandardContract(id, bindings = {}) {
|
|
270
|
+
const spec = getStandardContract(id);
|
|
271
|
+
if (!spec)
|
|
272
|
+
throw new Error(`unknown standard contract ${id}`);
|
|
273
|
+
const source = readStandardContractSource(id);
|
|
274
|
+
const compileOpts = { contract: spec.contract, bindings: { [spec.contract]: bindings } };
|
|
275
|
+
const artifact = compileContract(source, compileOpts, `std/${spec.file}`);
|
|
276
|
+
const warnings = lintContract(source, compileOpts, `std/${spec.file}`);
|
|
277
|
+
return { spec, artifact, warnings };
|
|
278
|
+
}
|
|
279
|
+
export function identifyStandardTemplate(rootHex) {
|
|
280
|
+
const normalized = rootHex.toLowerCase();
|
|
281
|
+
return STANDARD_CONTRACTS.find(spec => spec.universalRoot === normalized);
|
|
282
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Source target selection. eCash emits a direct script, never a Lotus policy. */
|
|
2
|
+
import { type CompileOptions, type ContractArtifact } from './generic.js';
|
|
3
|
+
import { type EcashArtifact } from './ecash.js';
|
|
4
|
+
export type TargetCompileOptions = Omit<CompileOptions, 'target'> & {
|
|
5
|
+
target?: string;
|
|
6
|
+
method?: string;
|
|
7
|
+
};
|
|
8
|
+
export type TargetArtifact = ContractArtifact | EcashArtifact;
|
|
9
|
+
export declare function compileTargetContract(source: string, options: TargetCompileOptions, file?: string): TargetArtifact;
|