@5ive-tech/sdk 1.1.2
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 +279 -0
- package/dist/FiveSDK.d.ts +336 -0
- package/dist/FiveSDK.js +395 -0
- package/dist/accounts/index.d.ts +254 -0
- package/dist/accounts/index.js +543 -0
- package/dist/assets/vm/dummy.file +0 -0
- package/dist/assets/vm/five_vm_wasm.d.ts +762 -0
- package/dist/assets/vm/five_vm_wasm.js +3754 -0
- package/dist/assets/vm/five_vm_wasm_bg.js +3307 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm +0 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm.d.ts +247 -0
- package/dist/assets/vm/package.json +11 -0
- package/dist/bin/gen-types.d.ts +2 -0
- package/dist/bin/gen-types.js +35 -0
- package/dist/compiler/BytecodeCompiler.d.ts +83 -0
- package/dist/compiler/BytecodeCompiler.js +379 -0
- package/dist/config/ConfigManager.d.ts +13 -0
- package/dist/config/ConfigManager.js +27 -0
- package/dist/config/ProgramIdResolver.d.ts +62 -0
- package/dist/config/ProgramIdResolver.js +104 -0
- package/dist/crypto/index.d.ts +211 -0
- package/dist/crypto/index.js +451 -0
- package/dist/encoding/ParameterEncoder.d.ts +31 -0
- package/dist/encoding/ParameterEncoder.js +278 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +28 -0
- package/dist/lib/bytecode-encoder.d.ts +62 -0
- package/dist/lib/bytecode-encoder.js +281 -0
- package/dist/logging/index.d.ts +9 -0
- package/dist/logging/index.js +10 -0
- package/dist/metadata/index.d.ts +213 -0
- package/dist/metadata/index.js +296 -0
- package/dist/modules/accounts.d.ts +60 -0
- package/dist/modules/accounts.js +275 -0
- package/dist/modules/deploy.d.ts +90 -0
- package/dist/modules/deploy.js +1118 -0
- package/dist/modules/execute.d.ts +90 -0
- package/dist/modules/execute.js +649 -0
- package/dist/modules/fees.d.ts +14 -0
- package/dist/modules/fees.js +112 -0
- package/dist/modules/namespaces.d.ts +39 -0
- package/dist/modules/namespaces.js +190 -0
- package/dist/modules/state-diff.d.ts +35 -0
- package/dist/modules/state-diff.js +342 -0
- package/dist/modules/vm-state.d.ts +7 -0
- package/dist/modules/vm-state.js +44 -0
- package/dist/program/AccountResolver.d.ts +67 -0
- package/dist/program/AccountResolver.js +134 -0
- package/dist/program/BorshSchemaGenerator.d.ts +8 -0
- package/dist/program/BorshSchemaGenerator.js +57 -0
- package/dist/program/FiveProgram.d.ts +144 -0
- package/dist/program/FiveProgram.js +282 -0
- package/dist/program/FunctionBuilder.d.ts +114 -0
- package/dist/program/FunctionBuilder.js +347 -0
- package/dist/program/ProgramAccount.d.ts +38 -0
- package/dist/program/ProgramAccount.js +170 -0
- package/dist/program/TypeGenerator.d.ts +90 -0
- package/dist/program/TypeGenerator.js +195 -0
- package/dist/program/index.d.ts +24 -0
- package/dist/program/index.js +21 -0
- package/dist/project/config.d.ts +5 -0
- package/dist/project/config.js +33 -0
- package/dist/project/toml.d.ts +6 -0
- package/dist/project/toml.js +43 -0
- package/dist/project/workspace.d.ts +160 -0
- package/dist/project/workspace.js +73 -0
- package/dist/testing/AccountMetaGenerator.d.ts +121 -0
- package/dist/testing/AccountMetaGenerator.js +261 -0
- package/dist/testing/AccountTestFixture.d.ts +211 -0
- package/dist/testing/AccountTestFixture.js +530 -0
- package/dist/testing/OnChainAccountManager.d.ts +81 -0
- package/dist/testing/OnChainAccountManager.js +260 -0
- package/dist/testing/StateSerializer.d.ts +65 -0
- package/dist/testing/StateSerializer.js +330 -0
- package/dist/testing/TestDiscovery.d.ts +79 -0
- package/dist/testing/TestDiscovery.js +274 -0
- package/dist/testing/TestRunner.d.ts +117 -0
- package/dist/testing/TestRunner.js +346 -0
- package/dist/testing/index.d.ts +14 -0
- package/dist/testing/index.js +13 -0
- package/dist/types.d.ts +356 -0
- package/dist/types.js +32 -0
- package/dist/utils/abi.d.ts +31 -0
- package/dist/utils/abi.js +92 -0
- package/dist/utils/transaction.d.ts +5 -0
- package/dist/utils/transaction.js +48 -0
- package/dist/validation/InputValidator.d.ts +142 -0
- package/dist/validation/InputValidator.js +332 -0
- package/dist/validation/index.d.ts +4 -0
- package/dist/validation/index.js +4 -0
- package/dist/wasm/compiler/AbiLogic.d.ts +4 -0
- package/dist/wasm/compiler/AbiLogic.js +37 -0
- package/dist/wasm/compiler/AnalysisLogic.d.ts +6 -0
- package/dist/wasm/compiler/AnalysisLogic.js +61 -0
- package/dist/wasm/compiler/CompilationLogic.d.ts +10 -0
- package/dist/wasm/compiler/CompilationLogic.js +431 -0
- package/dist/wasm/compiler/FiveCompiler.d.ts +48 -0
- package/dist/wasm/compiler/FiveCompiler.js +183 -0
- package/dist/wasm/compiler/InfoLogic.d.ts +6 -0
- package/dist/wasm/compiler/InfoLogic.js +24 -0
- package/dist/wasm/compiler/OptimizationLogic.d.ts +2 -0
- package/dist/wasm/compiler/OptimizationLogic.js +13 -0
- package/dist/wasm/compiler/ValidationLogic.d.ts +7 -0
- package/dist/wasm/compiler/ValidationLogic.js +26 -0
- package/dist/wasm/compiler/index.d.ts +2 -0
- package/dist/wasm/compiler/index.js +2 -0
- package/dist/wasm/compiler/types.d.ts +8 -0
- package/dist/wasm/compiler/types.js +1 -0
- package/dist/wasm/compiler/utils.d.ts +8 -0
- package/dist/wasm/compiler/utils.js +75 -0
- package/dist/wasm/index.d.ts +9 -0
- package/dist/wasm/index.js +12 -0
- package/dist/wasm/instance.d.ts +1 -0
- package/dist/wasm/instance.js +26 -0
- package/dist/wasm/loader.d.ts +7 -0
- package/dist/wasm/loader.js +112 -0
- package/dist/wasm/vm.d.ts +33 -0
- package/dist/wasm/vm.js +250 -0
- package/package.json +59 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeGenerator - Generate TypeScript types from Five VM script ABI
|
|
3
|
+
*
|
|
4
|
+
* Creates type-safe interfaces for:
|
|
5
|
+
* - Function parameters (accounts and data)
|
|
6
|
+
* - Return types
|
|
7
|
+
* - Type-safe builder methods
|
|
8
|
+
*
|
|
9
|
+
* Example generated interface:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* export interface CounterProgram {
|
|
12
|
+
* initialize(params: {
|
|
13
|
+
* accounts: { counter: PublicKey | string; owner: PublicKey | string };
|
|
14
|
+
* }): FunctionBuilder;
|
|
15
|
+
*
|
|
16
|
+
* add_amount(params: {
|
|
17
|
+
* accounts: { counter: PublicKey | string; owner: PublicKey | string };
|
|
18
|
+
* args: { amount: number };
|
|
19
|
+
* }): FunctionBuilder;
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* TypeGenerator creates TypeScript interfaces from ABI
|
|
25
|
+
*/
|
|
26
|
+
export class TypeGenerator {
|
|
27
|
+
constructor(abi, options) {
|
|
28
|
+
this.abi = abi;
|
|
29
|
+
this.options = {
|
|
30
|
+
scriptName: abi.name || 'Program',
|
|
31
|
+
debug: false,
|
|
32
|
+
includeJSDoc: true,
|
|
33
|
+
...options,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Generate TypeScript interface definitions from ABI
|
|
38
|
+
*
|
|
39
|
+
* @returns TypeScript code as string
|
|
40
|
+
*/
|
|
41
|
+
generate() {
|
|
42
|
+
const lines = [];
|
|
43
|
+
// Header
|
|
44
|
+
lines.push('/**');
|
|
45
|
+
lines.push(` * Auto-generated types for ${this.options.scriptName} program`);
|
|
46
|
+
lines.push(' * Generated from ABI');
|
|
47
|
+
lines.push(' */');
|
|
48
|
+
lines.push('');
|
|
49
|
+
// Generate interface for each function
|
|
50
|
+
const interfaceName = this.generateInterfaceName(this.options.scriptName || 'Program');
|
|
51
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
52
|
+
for (const func of this.abi.functions) {
|
|
53
|
+
// Check both is_public and visibility properties
|
|
54
|
+
const isPublic = func.is_public !== false && func.visibility !== 'private';
|
|
55
|
+
if (isPublic) {
|
|
56
|
+
lines.push(this.generateFunctionSignature(func, 2));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
lines.push('}');
|
|
60
|
+
lines.push('');
|
|
61
|
+
// Generate parameter types for each function
|
|
62
|
+
for (const func of this.abi.functions) {
|
|
63
|
+
const isPublic = func.is_public !== false && func.visibility !== 'private';
|
|
64
|
+
if (isPublic) {
|
|
65
|
+
lines.push(...this.generateFunctionParameterType(func));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const result = lines.join('\n');
|
|
69
|
+
if (this.options.debug) {
|
|
70
|
+
console.log(`[TypeGenerator] Generated ${this.abi.functions.length} function types`);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Generate TypeScript function signature
|
|
76
|
+
*
|
|
77
|
+
* @param func - Function definition
|
|
78
|
+
* @param indent - Indentation level (spaces)
|
|
79
|
+
* @returns Lines of TypeScript code
|
|
80
|
+
*/
|
|
81
|
+
generateFunctionSignature(func, indent) {
|
|
82
|
+
const indentStr = ' '.repeat(indent);
|
|
83
|
+
const paramTypeName = `${this.capitalize(func.name)}Params`;
|
|
84
|
+
let signature = `${indentStr}${func.name}(params: ${paramTypeName}): FunctionBuilder;`;
|
|
85
|
+
if (this.options.includeJSDoc) {
|
|
86
|
+
const lines = [
|
|
87
|
+
`${indentStr}/**`,
|
|
88
|
+
`${indentStr} * Call ${func.name}()`,
|
|
89
|
+
`${indentStr} */`,
|
|
90
|
+
signature,
|
|
91
|
+
];
|
|
92
|
+
return lines.join('\n');
|
|
93
|
+
}
|
|
94
|
+
return signature;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Generate parameter type definitions for a function
|
|
98
|
+
*
|
|
99
|
+
* @param func - Function definition
|
|
100
|
+
* @returns Lines of TypeScript code
|
|
101
|
+
*/
|
|
102
|
+
generateFunctionParameterType(func) {
|
|
103
|
+
const lines = [];
|
|
104
|
+
const paramTypeName = `${this.capitalize(func.name)}Params`;
|
|
105
|
+
lines.push(`export interface ${paramTypeName} {`);
|
|
106
|
+
// Extract account and data parameters
|
|
107
|
+
const accountParams = func.parameters.filter((p) => p.is_account === true);
|
|
108
|
+
const dataParams = func.parameters.filter((p) => p.is_account !== true);
|
|
109
|
+
// Generate accounts object if there are account parameters
|
|
110
|
+
if (accountParams.length > 0) {
|
|
111
|
+
lines.push(' accounts: {');
|
|
112
|
+
for (const param of accountParams) {
|
|
113
|
+
lines.push(` ${param.name}: string | { toBase58(): string };`);
|
|
114
|
+
}
|
|
115
|
+
lines.push(' };');
|
|
116
|
+
}
|
|
117
|
+
// Generate args object if there are data parameters
|
|
118
|
+
if (dataParams.length > 0) {
|
|
119
|
+
lines.push(' args: {');
|
|
120
|
+
for (const param of dataParams) {
|
|
121
|
+
const typeStr = param.type || param.param_type || 'any';
|
|
122
|
+
const tsType = this.typeToTypeScript(typeStr);
|
|
123
|
+
lines.push(` ${param.name}: ${tsType};`);
|
|
124
|
+
}
|
|
125
|
+
lines.push(' };');
|
|
126
|
+
}
|
|
127
|
+
lines.push('}');
|
|
128
|
+
lines.push('');
|
|
129
|
+
return lines;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Convert Five VM type to TypeScript type
|
|
133
|
+
*
|
|
134
|
+
* @param fiveType - Five VM type string (e.g., "u64", "Account")
|
|
135
|
+
* @returns TypeScript type string
|
|
136
|
+
*/
|
|
137
|
+
typeToTypeScript(fiveType) {
|
|
138
|
+
const typeMap = {
|
|
139
|
+
u8: 'number',
|
|
140
|
+
u16: 'number',
|
|
141
|
+
u32: 'number',
|
|
142
|
+
u64: 'number | bigint',
|
|
143
|
+
u128: 'number | bigint',
|
|
144
|
+
i8: 'number',
|
|
145
|
+
i16: 'number',
|
|
146
|
+
i32: 'number',
|
|
147
|
+
i64: 'number | bigint',
|
|
148
|
+
i128: 'number | bigint',
|
|
149
|
+
f32: 'number',
|
|
150
|
+
f64: 'number',
|
|
151
|
+
bool: 'boolean',
|
|
152
|
+
string: 'string',
|
|
153
|
+
pubkey: 'string | { toBase58(): string }',
|
|
154
|
+
'pubkey[]': 'Array<string | { toBase58(): string }>',
|
|
155
|
+
'u8[]': 'Uint8Array | number[]',
|
|
156
|
+
'u64[]': 'Array<number | bigint>',
|
|
157
|
+
};
|
|
158
|
+
return typeMap[fiveType] || 'any';
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Generate interface name from script name
|
|
162
|
+
* E.g., "counter" → "CounterProgram"
|
|
163
|
+
*
|
|
164
|
+
* @param scriptName - Name of the script
|
|
165
|
+
* @returns Interface name
|
|
166
|
+
*/
|
|
167
|
+
generateInterfaceName(scriptName) {
|
|
168
|
+
const base = this.capitalize(scriptName);
|
|
169
|
+
return `${base}Program`;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Capitalize first letter
|
|
173
|
+
*
|
|
174
|
+
* @param str - String to capitalize
|
|
175
|
+
* @returns Capitalized string
|
|
176
|
+
*/
|
|
177
|
+
capitalize(str) {
|
|
178
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get the generated ABI as TypeScript AST (for advanced use)
|
|
182
|
+
*
|
|
183
|
+
* @returns Object representation of types
|
|
184
|
+
*/
|
|
185
|
+
getABIStructure() {
|
|
186
|
+
return {
|
|
187
|
+
programName: this.generateInterfaceName(this.options.scriptName || 'Program'),
|
|
188
|
+
functions: this.abi.functions.map((func) => ({
|
|
189
|
+
name: func.name,
|
|
190
|
+
parameters: func.parameters,
|
|
191
|
+
returnType: func.return_type,
|
|
192
|
+
})),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Five SDK Program Module
|
|
3
|
+
*
|
|
4
|
+
* High-level wrapper for Five VM scripts with Anchor-style ergonomics.
|
|
5
|
+
* Provides simple, type-safe API for building function calls.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { FiveProgram } from '@five-vm/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const program = FiveProgram.fromABI(scriptAccount, abi);
|
|
12
|
+
* const ix = await program
|
|
13
|
+
* .function('increment')
|
|
14
|
+
* .accounts({ counter: counter1, owner: user1 })
|
|
15
|
+
* .instruction();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export { FiveProgram } from './FiveProgram.js';
|
|
19
|
+
export type { FiveProgramOptions } from './FiveProgram.js';
|
|
20
|
+
export { FunctionBuilder } from './FunctionBuilder.js';
|
|
21
|
+
export { AccountResolver } from './AccountResolver.js';
|
|
22
|
+
export type { ResolvedSystemAccounts } from './AccountResolver.js';
|
|
23
|
+
export { TypeGenerator } from './TypeGenerator.js';
|
|
24
|
+
export type { TypeGeneratorOptions } from './TypeGenerator.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Five SDK Program Module
|
|
3
|
+
*
|
|
4
|
+
* High-level wrapper for Five VM scripts with Anchor-style ergonomics.
|
|
5
|
+
* Provides simple, type-safe API for building function calls.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { FiveProgram } from '@five-vm/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const program = FiveProgram.fromABI(scriptAccount, abi);
|
|
12
|
+
* const ix = await program
|
|
13
|
+
* .function('increment')
|
|
14
|
+
* .accounts({ counter: counter1, owner: user1 })
|
|
15
|
+
* .instruction();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export { FiveProgram } from './FiveProgram.js';
|
|
19
|
+
export { FunctionBuilder } from './FunctionBuilder.js';
|
|
20
|
+
export { AccountResolver } from './AccountResolver.js';
|
|
21
|
+
export { TypeGenerator } from './TypeGenerator.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a raw TOML object into a strict ProjectConfig.
|
|
3
|
+
*/
|
|
4
|
+
export function parseProjectConfig(parsedToml) {
|
|
5
|
+
const project = parsedToml.project ?? {};
|
|
6
|
+
const build = parsedToml.build ?? {};
|
|
7
|
+
const optimizations = parsedToml.optimizations ?? {};
|
|
8
|
+
const deploy = parsedToml.deploy ?? {};
|
|
9
|
+
const name = project.name ?? 'five-project';
|
|
10
|
+
const target = (project.target ?? 'vm');
|
|
11
|
+
return {
|
|
12
|
+
name,
|
|
13
|
+
version: project.version ?? '0.1.0',
|
|
14
|
+
description: project.description,
|
|
15
|
+
sourceDir: project.source_dir ?? 'src',
|
|
16
|
+
buildDir: project.build_dir ?? 'build',
|
|
17
|
+
target,
|
|
18
|
+
entryPoint: project.entry_point,
|
|
19
|
+
outputArtifactName: build.output_artifact_name ?? name,
|
|
20
|
+
cluster: deploy.cluster ?? deploy.network,
|
|
21
|
+
commitment: deploy.commitment,
|
|
22
|
+
rpcUrl: deploy.rpc_url,
|
|
23
|
+
programId: deploy.program_id,
|
|
24
|
+
keypairPath: deploy.keypair_path,
|
|
25
|
+
multiFileMode: build.multi_file_mode ?? false,
|
|
26
|
+
optimizations: {
|
|
27
|
+
enableCompression: optimizations.enable_compression ?? true,
|
|
28
|
+
enableConstraintOptimization: optimizations.enable_constraint_optimization ?? true,
|
|
29
|
+
optimizationLevel: 'production'
|
|
30
|
+
},
|
|
31
|
+
dependencies: []
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Minimal TOML parser supporting the fields used in five.toml.
|
|
4
|
+
* Handles sections, strings, booleans, and numbers.
|
|
5
|
+
* Platform-agnostic: Does not rely on Node.js 'fs'.
|
|
6
|
+
*/
|
|
7
|
+
export function parseToml(content) {
|
|
8
|
+
const result = {};
|
|
9
|
+
let current = result;
|
|
10
|
+
const lines = content.split(/\r?\n/);
|
|
11
|
+
for (const rawLine of lines) {
|
|
12
|
+
const line = rawLine.split('#')[0].trim();
|
|
13
|
+
if (!line)
|
|
14
|
+
continue;
|
|
15
|
+
const sectionMatch = line.match(/^\[(.+)\]$/);
|
|
16
|
+
if (sectionMatch) {
|
|
17
|
+
const sectionName = sectionMatch[1].trim();
|
|
18
|
+
result[sectionName] = result[sectionName] || {};
|
|
19
|
+
current = result[sectionName];
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const eq = line.indexOf('=');
|
|
23
|
+
if (eq === -1)
|
|
24
|
+
continue;
|
|
25
|
+
const key = line.slice(0, eq).trim();
|
|
26
|
+
const rawValue = line.slice(eq + 1).trim();
|
|
27
|
+
current[key] = parseTomlValue(rawValue);
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function parseTomlValue(raw) {
|
|
32
|
+
if ((raw.startsWith('"') && raw.endsWith('"')) || (raw.startsWith("'") && raw.endsWith("'"))) {
|
|
33
|
+
return raw.slice(1, -1);
|
|
34
|
+
}
|
|
35
|
+
if (raw === 'true')
|
|
36
|
+
return true;
|
|
37
|
+
if (raw === 'false')
|
|
38
|
+
return false;
|
|
39
|
+
const num = Number(raw);
|
|
40
|
+
if (!Number.isNaN(num))
|
|
41
|
+
return num;
|
|
42
|
+
return raw;
|
|
43
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace Configuration and Types
|
|
3
|
+
*
|
|
4
|
+
* Provides types and utilities for Five workspace support,
|
|
5
|
+
* enabling multi-package projects with cross-bytecode imports.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Dependency link type
|
|
9
|
+
* - inline: Merge into single bytecode (default)
|
|
10
|
+
* - external: Use CALL_EXTERNAL at runtime
|
|
11
|
+
*/
|
|
12
|
+
export type LinkType = 'inline' | 'external';
|
|
13
|
+
/**
|
|
14
|
+
* Root workspace configuration from five.toml [workspace] section
|
|
15
|
+
*/
|
|
16
|
+
export interface WorkspaceConfig {
|
|
17
|
+
/** Member package paths (supports globs like "packages/*") */
|
|
18
|
+
members: string[];
|
|
19
|
+
/** Paths to exclude from workspace */
|
|
20
|
+
exclude?: string[];
|
|
21
|
+
/** Default package settings inherited by members */
|
|
22
|
+
package?: WorkspacePackageDefaults;
|
|
23
|
+
/** Shared workspace dependencies */
|
|
24
|
+
dependencies?: Record<string, WorkspaceDependency>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Default settings that can be inherited by workspace members
|
|
28
|
+
*/
|
|
29
|
+
export interface WorkspacePackageDefaults {
|
|
30
|
+
version?: string;
|
|
31
|
+
authors?: string[];
|
|
32
|
+
edition?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Workspace-level dependency definition
|
|
36
|
+
*/
|
|
37
|
+
export interface WorkspaceDependency {
|
|
38
|
+
version?: string;
|
|
39
|
+
path?: string;
|
|
40
|
+
link?: LinkType;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Package manifest from member five.toml
|
|
44
|
+
*/
|
|
45
|
+
export interface PackageManifest {
|
|
46
|
+
package: PackageInfo;
|
|
47
|
+
build?: PackageBuildConfig;
|
|
48
|
+
dependencies?: Record<string, PackageDependency>;
|
|
49
|
+
deploy?: PackageDeployConfig;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Package metadata from [package] section
|
|
53
|
+
*/
|
|
54
|
+
export interface PackageInfo {
|
|
55
|
+
name: string;
|
|
56
|
+
version: string | {
|
|
57
|
+
workspace: boolean;
|
|
58
|
+
};
|
|
59
|
+
description?: string;
|
|
60
|
+
authors?: string[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Package build configuration from [build] section
|
|
64
|
+
*/
|
|
65
|
+
export interface PackageBuildConfig {
|
|
66
|
+
source_dir?: string;
|
|
67
|
+
entry_point?: string;
|
|
68
|
+
output?: string;
|
|
69
|
+
output_type?: 'bytecode_account' | 'library';
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Package dependency specification
|
|
73
|
+
*/
|
|
74
|
+
export interface PackageDependency {
|
|
75
|
+
version?: string;
|
|
76
|
+
path?: string;
|
|
77
|
+
/** Use workspace = true to inherit from workspace deps */
|
|
78
|
+
workspace?: boolean;
|
|
79
|
+
/** Link type: inline (merge) or external (CALL_EXTERNAL) */
|
|
80
|
+
link?: LinkType;
|
|
81
|
+
/** Explicit bytecode address (for deployed dependencies) */
|
|
82
|
+
address?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Package deployment configuration
|
|
86
|
+
*/
|
|
87
|
+
export interface PackageDeployConfig {
|
|
88
|
+
/** Deployed bytecode account address */
|
|
89
|
+
address?: string;
|
|
90
|
+
/** PDA seeds for deriving address */
|
|
91
|
+
pda_seeds?: string[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Lock file structure (five.lock)
|
|
95
|
+
*/
|
|
96
|
+
export interface LockFile {
|
|
97
|
+
version: number;
|
|
98
|
+
packages: LockEntry[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Individual package entry in lock file
|
|
102
|
+
*/
|
|
103
|
+
export interface LockEntry {
|
|
104
|
+
name: string;
|
|
105
|
+
version: string;
|
|
106
|
+
address: string;
|
|
107
|
+
bytecode_hash: string;
|
|
108
|
+
deployed_at?: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Resolved workspace state for IDE
|
|
112
|
+
*/
|
|
113
|
+
export interface WorkspaceState {
|
|
114
|
+
/** Root directory path */
|
|
115
|
+
root: string;
|
|
116
|
+
/** Member package paths */
|
|
117
|
+
members: string[];
|
|
118
|
+
/** Resolved package information */
|
|
119
|
+
packages: ResolvedPackage[];
|
|
120
|
+
/** Lock file data */
|
|
121
|
+
lockFile?: LockFile;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resolved package with dependency info
|
|
125
|
+
*/
|
|
126
|
+
export interface ResolvedPackage {
|
|
127
|
+
name: string;
|
|
128
|
+
path: string;
|
|
129
|
+
entryPoint?: string;
|
|
130
|
+
dependencies: ResolvedDependency[];
|
|
131
|
+
/** Bytecode if compiled */
|
|
132
|
+
bytecode?: Uint8Array;
|
|
133
|
+
/** Deployed address if available */
|
|
134
|
+
address?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Resolved dependency with link type
|
|
138
|
+
*/
|
|
139
|
+
export interface ResolvedDependency {
|
|
140
|
+
name: string;
|
|
141
|
+
link: LinkType;
|
|
142
|
+
path?: string;
|
|
143
|
+
address?: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parse workspace section from TOML
|
|
147
|
+
*/
|
|
148
|
+
export declare function parseWorkspaceConfig(toml: Record<string, any>): WorkspaceConfig | null;
|
|
149
|
+
/**
|
|
150
|
+
* Parse package manifest from TOML
|
|
151
|
+
*/
|
|
152
|
+
export declare function parsePackageManifest(toml: Record<string, any>): PackageManifest | null;
|
|
153
|
+
/**
|
|
154
|
+
* Determine build order from packages (topological sort)
|
|
155
|
+
*/
|
|
156
|
+
export declare function getBuildOrder(packages: ResolvedPackage[]): string[];
|
|
157
|
+
/**
|
|
158
|
+
* Check if a file map represents a workspace
|
|
159
|
+
*/
|
|
160
|
+
export declare function isWorkspace(files: Record<string, string>): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace Configuration and Types
|
|
3
|
+
*
|
|
4
|
+
* Provides types and utilities for Five workspace support,
|
|
5
|
+
* enabling multi-package projects with cross-bytecode imports.
|
|
6
|
+
*/
|
|
7
|
+
// ==================== Utilities ====================
|
|
8
|
+
/**
|
|
9
|
+
* Parse workspace section from TOML
|
|
10
|
+
*/
|
|
11
|
+
export function parseWorkspaceConfig(toml) {
|
|
12
|
+
const ws = toml.workspace;
|
|
13
|
+
if (!ws || !ws.members)
|
|
14
|
+
return null;
|
|
15
|
+
return {
|
|
16
|
+
members: ws.members,
|
|
17
|
+
exclude: ws.exclude,
|
|
18
|
+
package: ws.package,
|
|
19
|
+
dependencies: ws.dependencies,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parse package manifest from TOML
|
|
24
|
+
*/
|
|
25
|
+
export function parsePackageManifest(toml) {
|
|
26
|
+
const pkg = toml.package;
|
|
27
|
+
if (!pkg || !pkg.name)
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
package: {
|
|
31
|
+
name: pkg.name,
|
|
32
|
+
version: pkg.version || '0.1.0',
|
|
33
|
+
description: pkg.description,
|
|
34
|
+
authors: pkg.authors,
|
|
35
|
+
},
|
|
36
|
+
build: toml.build,
|
|
37
|
+
dependencies: toml.dependencies,
|
|
38
|
+
deploy: toml.deploy,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Determine build order from packages (topological sort)
|
|
43
|
+
*/
|
|
44
|
+
export function getBuildOrder(packages) {
|
|
45
|
+
const visited = new Set();
|
|
46
|
+
const order = [];
|
|
47
|
+
const packageMap = new Map(packages.map(p => [p.name, p]));
|
|
48
|
+
function visit(name) {
|
|
49
|
+
if (visited.has(name))
|
|
50
|
+
return;
|
|
51
|
+
visited.add(name);
|
|
52
|
+
const pkg = packageMap.get(name);
|
|
53
|
+
if (pkg) {
|
|
54
|
+
for (const dep of pkg.dependencies) {
|
|
55
|
+
visit(dep.name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
order.push(name);
|
|
59
|
+
}
|
|
60
|
+
for (const pkg of packages) {
|
|
61
|
+
visit(pkg.name);
|
|
62
|
+
}
|
|
63
|
+
return order;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if a file map represents a workspace
|
|
67
|
+
*/
|
|
68
|
+
export function isWorkspace(files) {
|
|
69
|
+
const rootToml = files['five.toml'];
|
|
70
|
+
if (!rootToml)
|
|
71
|
+
return false;
|
|
72
|
+
return rootToml.includes('[workspace]');
|
|
73
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Meta Generator for Five VM Testing
|
|
3
|
+
*
|
|
4
|
+
* Generates AccountMeta structures for testing account system scripts
|
|
5
|
+
* based on ABI requirements and constraint types (@signer, @mut, @init)
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Account constraint types from Five VM
|
|
9
|
+
*/
|
|
10
|
+
export interface AccountConstraints {
|
|
11
|
+
name: string;
|
|
12
|
+
writable: boolean;
|
|
13
|
+
signer: boolean;
|
|
14
|
+
init?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generated account metadata for testing
|
|
18
|
+
*/
|
|
19
|
+
export interface GeneratedAccountMeta {
|
|
20
|
+
pubkey: string;
|
|
21
|
+
isSigner: boolean;
|
|
22
|
+
isWritable: boolean;
|
|
23
|
+
keypair?: {
|
|
24
|
+
publicKey: string;
|
|
25
|
+
secretKey: Uint8Array;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Test account generation context
|
|
30
|
+
*/
|
|
31
|
+
export interface TestAccountContext {
|
|
32
|
+
script: string;
|
|
33
|
+
functionIndex: number;
|
|
34
|
+
accounts: GeneratedAccountMeta[];
|
|
35
|
+
stateData?: Map<string, any>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Account Meta Generator for Five VM test scripts
|
|
39
|
+
*/
|
|
40
|
+
export declare class AccountMetaGenerator {
|
|
41
|
+
private static accountCache;
|
|
42
|
+
private static stateDataCache;
|
|
43
|
+
/**
|
|
44
|
+
* Generate AccountMeta array from ABI function definition
|
|
45
|
+
*/
|
|
46
|
+
static generateAccountsForFunction(abi: any, functionName: string, options?: {
|
|
47
|
+
reuseAccounts?: boolean;
|
|
48
|
+
generateStateData?: boolean;
|
|
49
|
+
debug?: boolean;
|
|
50
|
+
}): Promise<TestAccountContext>;
|
|
51
|
+
/**
|
|
52
|
+
* Generate single AccountMeta from account specification
|
|
53
|
+
*/
|
|
54
|
+
private static generateAccountMeta;
|
|
55
|
+
/**
|
|
56
|
+
* Generate signer account with keypair
|
|
57
|
+
*/
|
|
58
|
+
private static generateSignerAccount;
|
|
59
|
+
/**
|
|
60
|
+
* Generate regular (non-signer) account
|
|
61
|
+
*/
|
|
62
|
+
private static generateRegularAccount;
|
|
63
|
+
/**
|
|
64
|
+
* Check if account is a state account that needs data
|
|
65
|
+
*/
|
|
66
|
+
private static isStateAccount;
|
|
67
|
+
/**
|
|
68
|
+
* Generate mock state data for state accounts
|
|
69
|
+
*/
|
|
70
|
+
private static generateStateData;
|
|
71
|
+
/**
|
|
72
|
+
* Format accounts for Five CLI execution
|
|
73
|
+
*/
|
|
74
|
+
static formatAccountsForCLI(context: TestAccountContext): {
|
|
75
|
+
accountsParam: string;
|
|
76
|
+
keypairsNeeded: Array<{
|
|
77
|
+
name: string;
|
|
78
|
+
keypair: any;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Generate accounts from .five file
|
|
83
|
+
*/
|
|
84
|
+
static generateFromFiveFile(fiveFilePath: string, functionName?: string, options?: {
|
|
85
|
+
reuseAccounts?: boolean;
|
|
86
|
+
generateStateData?: boolean;
|
|
87
|
+
debug?: boolean;
|
|
88
|
+
}): Promise<TestAccountContext>;
|
|
89
|
+
/**
|
|
90
|
+
* Clear account cache (useful for testing)
|
|
91
|
+
*/
|
|
92
|
+
static clearCache(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Get account cache statistics
|
|
95
|
+
*/
|
|
96
|
+
static getCacheStats(): {
|
|
97
|
+
accountsCached: number;
|
|
98
|
+
stateDataCached: number;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Utility functions for account management
|
|
103
|
+
*/
|
|
104
|
+
export declare class AccountTestUtils {
|
|
105
|
+
/**
|
|
106
|
+
* Create test accounts for common constraint patterns
|
|
107
|
+
*/
|
|
108
|
+
static createStandardTestAccounts(): Promise<{
|
|
109
|
+
payer: GeneratedAccountMeta;
|
|
110
|
+
authority: GeneratedAccountMeta;
|
|
111
|
+
state: GeneratedAccountMeta;
|
|
112
|
+
readonly: GeneratedAccountMeta;
|
|
113
|
+
}>;
|
|
114
|
+
/**
|
|
115
|
+
* Validate account constraints match requirements
|
|
116
|
+
*/
|
|
117
|
+
static validateAccountConstraints(accounts: GeneratedAccountMeta[], requirements: AccountConstraints[]): {
|
|
118
|
+
valid: boolean;
|
|
119
|
+
errors: string[];
|
|
120
|
+
};
|
|
121
|
+
}
|