genlayer 0.33.1 → 0.34.1
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/dist/index.js +68 -31
- package/package.json +11 -2
- package/.eslintignore +0 -2
- package/.github/workflows/cli-docs.yml +0 -121
- package/.github/workflows/publish-beta.yml +0 -41
- package/.github/workflows/publish.yml +0 -43
- package/.github/workflows/validate-code.yml +0 -47
- package/.prettierignore +0 -19
- package/.prettierrc +0 -12
- package/.release-it.json +0 -64
- package/CHANGELOG.md +0 -419
- package/CLAUDE.md +0 -55
- package/CONTRIBUTING.md +0 -117
- package/docker-compose.yml +0 -154
- package/docs/delegator-guide.md +0 -203
- package/docs/validator-guide.md +0 -329
- package/esbuild.config.dev.js +0 -17
- package/esbuild.config.js +0 -22
- package/esbuild.config.prod.js +0 -17
- package/eslint.config.js +0 -60
- package/renovate.json +0 -22
- package/src/commands/account/create.ts +0 -29
- package/src/commands/account/export.ts +0 -106
- package/src/commands/account/import.ts +0 -135
- package/src/commands/account/index.ts +0 -126
- package/src/commands/account/list.ts +0 -34
- package/src/commands/account/lock.ts +0 -39
- package/src/commands/account/remove.ts +0 -30
- package/src/commands/account/send.ts +0 -156
- package/src/commands/account/show.ts +0 -74
- package/src/commands/account/unlock.ts +0 -51
- package/src/commands/account/use.ts +0 -21
- package/src/commands/config/getSetReset.ts +0 -51
- package/src/commands/config/index.ts +0 -30
- package/src/commands/contracts/call.ts +0 -39
- package/src/commands/contracts/code.ts +0 -33
- package/src/commands/contracts/deploy.ts +0 -157
- package/src/commands/contracts/index.ts +0 -86
- package/src/commands/contracts/schema.ts +0 -31
- package/src/commands/contracts/write.ts +0 -49
- package/src/commands/general/index.ts +0 -45
- package/src/commands/general/init.ts +0 -179
- package/src/commands/general/start.ts +0 -116
- package/src/commands/general/stop.ts +0 -26
- package/src/commands/localnet/index.ts +0 -100
- package/src/commands/localnet/validators.ts +0 -269
- package/src/commands/network/index.ts +0 -29
- package/src/commands/network/setNetwork.ts +0 -77
- package/src/commands/scaffold/index.ts +0 -16
- package/src/commands/scaffold/new.ts +0 -34
- package/src/commands/staking/StakingAction.ts +0 -267
- package/src/commands/staking/delegatorClaim.ts +0 -41
- package/src/commands/staking/delegatorExit.ts +0 -56
- package/src/commands/staking/delegatorJoin.ts +0 -44
- package/src/commands/staking/index.ts +0 -346
- package/src/commands/staking/setIdentity.ts +0 -78
- package/src/commands/staking/setOperator.ts +0 -46
- package/src/commands/staking/stakingInfo.ts +0 -584
- package/src/commands/staking/validatorClaim.ts +0 -43
- package/src/commands/staking/validatorDeposit.ts +0 -48
- package/src/commands/staking/validatorExit.ts +0 -63
- package/src/commands/staking/validatorHistory.ts +0 -298
- package/src/commands/staking/validatorJoin.ts +0 -47
- package/src/commands/staking/validatorPrime.ts +0 -73
- package/src/commands/staking/wizard.ts +0 -809
- package/src/commands/transactions/appeal.ts +0 -39
- package/src/commands/transactions/index.ts +0 -39
- package/src/commands/transactions/receipt.ts +0 -90
- package/src/commands/update/index.ts +0 -25
- package/src/commands/update/ollama.ts +0 -103
- package/src/lib/actions/BaseAction.ts +0 -295
- package/src/lib/clients/jsonRpcClient.ts +0 -41
- package/src/lib/clients/system.ts +0 -73
- package/src/lib/config/ConfigFileManager.ts +0 -194
- package/src/lib/config/KeychainManager.ts +0 -89
- package/src/lib/config/simulator.ts +0 -68
- package/src/lib/config/text.ts +0 -2
- package/src/lib/errors/missingRequirement.ts +0 -9
- package/src/lib/errors/versionRequired.ts +0 -9
- package/src/lib/interfaces/ISimulatorService.ts +0 -37
- package/src/lib/services/simulator.ts +0 -351
- package/src/types/node-fetch.d.ts +0 -1
- package/tests/actions/appeal.test.ts +0 -99
- package/tests/actions/call.test.ts +0 -94
- package/tests/actions/code.test.ts +0 -87
- package/tests/actions/create.test.ts +0 -65
- package/tests/actions/deploy.test.ts +0 -420
- package/tests/actions/getSetReset.test.ts +0 -88
- package/tests/actions/init.test.ts +0 -467
- package/tests/actions/lock.test.ts +0 -86
- package/tests/actions/new.test.ts +0 -80
- package/tests/actions/ollama.test.ts +0 -193
- package/tests/actions/receipt.test.ts +0 -261
- package/tests/actions/schema.test.ts +0 -94
- package/tests/actions/setNetwork.test.ts +0 -160
- package/tests/actions/staking.test.ts +0 -279
- package/tests/actions/start.test.ts +0 -235
- package/tests/actions/stop.test.ts +0 -77
- package/tests/actions/unlock.test.ts +0 -139
- package/tests/actions/validators.test.ts +0 -750
- package/tests/actions/write.test.ts +0 -102
- package/tests/commands/account.test.ts +0 -146
- package/tests/commands/appeal.test.ts +0 -58
- package/tests/commands/call.test.ts +0 -78
- package/tests/commands/code.test.ts +0 -69
- package/tests/commands/config.test.ts +0 -54
- package/tests/commands/deploy.test.ts +0 -83
- package/tests/commands/init.test.ts +0 -101
- package/tests/commands/localnet.test.ts +0 -131
- package/tests/commands/network.test.ts +0 -60
- package/tests/commands/new.test.ts +0 -68
- package/tests/commands/receipt.test.ts +0 -142
- package/tests/commands/schema.test.ts +0 -67
- package/tests/commands/staking.test.ts +0 -329
- package/tests/commands/stop.test.ts +0 -27
- package/tests/commands/up.test.ts +0 -105
- package/tests/commands/update.test.ts +0 -45
- package/tests/commands/write.test.ts +0 -76
- package/tests/index.test.ts +0 -56
- package/tests/libs/baseAction.test.ts +0 -516
- package/tests/libs/configFileManager.test.ts +0 -117
- package/tests/libs/jsonRpcClient.test.ts +0 -59
- package/tests/libs/keychainManager.test.ts +0 -156
- package/tests/libs/system.test.ts +0 -148
- package/tests/services/simulator.test.ts +0 -705
- package/tests/utils.ts +0 -13
- package/tsconfig.json +0 -120
- package/vitest.config.ts +0 -12
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {Command} from "commander";
|
|
2
|
-
import {DeployAction, DeployOptions, DeployScriptsOptions} from "./deploy";
|
|
3
|
-
import {CallAction, CallOptions} from "./call";
|
|
4
|
-
import {WriteAction, WriteOptions} from "./write";
|
|
5
|
-
import {SchemaAction, SchemaOptions} from "./schema";
|
|
6
|
-
import {CodeAction, CodeOptions} from "./code";
|
|
7
|
-
|
|
8
|
-
function parseArg(value: string, previous: any[] = []): any[] {
|
|
9
|
-
if (value === "true") return [...previous, true];
|
|
10
|
-
if (value === "false") return [...previous, false];
|
|
11
|
-
if (!isNaN(Number(value))) return [...previous, Number(value)];
|
|
12
|
-
return [...previous, value];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function initializeContractsCommands(program: Command) {
|
|
16
|
-
program
|
|
17
|
-
.command("deploy")
|
|
18
|
-
.description("Deploy intelligent contracts")
|
|
19
|
-
.option("--contract <contractPath>", "Path to the smart contract to deploy")
|
|
20
|
-
.option("--rpc <rpcUrl>", "RPC URL for the network")
|
|
21
|
-
.option(
|
|
22
|
-
"--args <args...>",
|
|
23
|
-
"Positional arguments for the contract (space-separated, use quotes for multi-word arguments)",
|
|
24
|
-
parseArg,
|
|
25
|
-
[],
|
|
26
|
-
)
|
|
27
|
-
.action(async (options: DeployOptions) => {
|
|
28
|
-
const deployer = new DeployAction();
|
|
29
|
-
if (options.contract) {
|
|
30
|
-
await deployer.deploy(options);
|
|
31
|
-
} else {
|
|
32
|
-
const deployScriptsOptions: DeployScriptsOptions = {rpc: options.rpc};
|
|
33
|
-
await deployer.deployScripts(deployScriptsOptions);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
program
|
|
38
|
-
.command("call <contractAddress> <method>")
|
|
39
|
-
.description("Call a contract method without sending a transaction or changing the state")
|
|
40
|
-
.option("--rpc <rpcUrl>", "RPC URL for the network")
|
|
41
|
-
.option(
|
|
42
|
-
"--args <args...>",
|
|
43
|
-
"Positional arguments for the method (space-separated, use quotes for multi-word arguments)",
|
|
44
|
-
parseArg,
|
|
45
|
-
[],
|
|
46
|
-
)
|
|
47
|
-
.action(async (contractAddress: string, method: string, options: CallOptions) => {
|
|
48
|
-
const callAction = new CallAction();
|
|
49
|
-
await callAction.call({contractAddress, method, ...options});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
program
|
|
53
|
-
.command("write <contractAddress> <method>")
|
|
54
|
-
.description("Sends a transaction to a contract method that modifies the state")
|
|
55
|
-
.option("--rpc <rpcUrl>", "RPC URL for the network")
|
|
56
|
-
.option(
|
|
57
|
-
"--args <args...>",
|
|
58
|
-
"Positional arguments for the method (space-separated, use quotes for multi-word arguments)",
|
|
59
|
-
parseArg,
|
|
60
|
-
[],
|
|
61
|
-
)
|
|
62
|
-
.action(async (contractAddress: string, method: string, options: WriteOptions) => {
|
|
63
|
-
const writeAction = new WriteAction();
|
|
64
|
-
await writeAction.write({contractAddress, method, ...options});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
program
|
|
68
|
-
.command("schema <contractAddress>")
|
|
69
|
-
.description("Get the schema for a deployed contract")
|
|
70
|
-
.option("--rpc <rpcUrl>", "RPC URL for the network")
|
|
71
|
-
.action(async (contractAddress: string, options: SchemaOptions) => {
|
|
72
|
-
const schemaAction = new SchemaAction();
|
|
73
|
-
await schemaAction.schema({contractAddress, ...options});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
program
|
|
77
|
-
.command("code <contractAddress>")
|
|
78
|
-
.description("Get the source for a deployed contract")
|
|
79
|
-
.option("--rpc <rpcUrl>", "RPC URL for the network")
|
|
80
|
-
.action(async (contractAddress: string, options: CodeOptions) => {
|
|
81
|
-
const codeAction = new CodeAction();
|
|
82
|
-
await codeAction.code({contractAddress, ...options});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
return program;
|
|
86
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
2
|
-
import type {Address} from "genlayer-js/types";
|
|
3
|
-
|
|
4
|
-
export interface SchemaOptions {
|
|
5
|
-
rpc?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class SchemaAction extends BaseAction {
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async schema({
|
|
14
|
-
contractAddress,
|
|
15
|
-
rpc,
|
|
16
|
-
}: {
|
|
17
|
-
contractAddress: string;
|
|
18
|
-
rpc?: string;
|
|
19
|
-
}): Promise<void> {
|
|
20
|
-
const client = await this.getClient(rpc, true);
|
|
21
|
-
await client.initializeConsensusSmartContract();
|
|
22
|
-
this.startSpinner(`Getting schema for contract at ${contractAddress}...`);
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const result = await client.getContractSchema(contractAddress as Address);
|
|
26
|
-
this.succeedSpinner("Contract schema retrieved successfully", result);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
this.failSpinner("Error retrieving contract schema", error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// import {simulator} from "genlayer-js/chains";
|
|
2
|
-
// import type {GenLayerClient} from "genlayer-js/types";
|
|
3
|
-
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
4
|
-
|
|
5
|
-
export interface WriteOptions {
|
|
6
|
-
args: any[];
|
|
7
|
-
rpc?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class WriteAction extends BaseAction {
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async write({
|
|
16
|
-
contractAddress,
|
|
17
|
-
method,
|
|
18
|
-
args,
|
|
19
|
-
rpc,
|
|
20
|
-
}: {
|
|
21
|
-
contractAddress: string;
|
|
22
|
-
method: string;
|
|
23
|
-
args: any[];
|
|
24
|
-
rpc?: string;
|
|
25
|
-
}): Promise<void> {
|
|
26
|
-
const client = await this.getClient(rpc);
|
|
27
|
-
await client.initializeConsensusSmartContract();
|
|
28
|
-
this.startSpinner(`Calling write method ${method} on contract at ${contractAddress}...`);
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const hash = await client.writeContract({
|
|
32
|
-
address: contractAddress as any,
|
|
33
|
-
functionName: method,
|
|
34
|
-
args,
|
|
35
|
-
value: 0n,
|
|
36
|
-
});
|
|
37
|
-
this.log("Write Transaction Hash:", hash);
|
|
38
|
-
|
|
39
|
-
const result = await client.waitForTransactionReceipt({
|
|
40
|
-
hash,
|
|
41
|
-
retries: 100,
|
|
42
|
-
interval: 5000,
|
|
43
|
-
});
|
|
44
|
-
this.succeedSpinner("Write operation successfully executed", result);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
this.failSpinner("Error during write operation", error);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
|
|
3
|
-
import simulatorService from "../../lib/services/simulator";
|
|
4
|
-
import { InitAction, InitActionOptions } from "./init";
|
|
5
|
-
import { StartAction, StartActionOptions } from "./start";
|
|
6
|
-
import {localnetCompatibleVersion} from "../../lib/config/simulator";
|
|
7
|
-
import {StopAction} from "./stop";
|
|
8
|
-
|
|
9
|
-
export function initializeGeneralCommands(program: Command) {
|
|
10
|
-
program
|
|
11
|
-
.command("init")
|
|
12
|
-
.description("Initialize the GenLayer Environment")
|
|
13
|
-
.option("--numValidators <numValidators>", "Number of validators", "5")
|
|
14
|
-
.option("--headless", "Headless mode", false)
|
|
15
|
-
.option("--reset-db", "Reset Database", false)
|
|
16
|
-
.option("--localnet-version <localnetVersion>", `Select a specific localnet version (minimum: ${localnetCompatibleVersion})`, localnetCompatibleVersion)
|
|
17
|
-
.option("--ollama", "Enable Ollama container", false)
|
|
18
|
-
.action(async (options: InitActionOptions) => {
|
|
19
|
-
const initAction = new InitAction();
|
|
20
|
-
await initAction.execute(options)
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
program
|
|
24
|
-
.command("up")
|
|
25
|
-
.description("Starts GenLayer's simulator")
|
|
26
|
-
.option("--reset-validators", "Remove all current validators and create new random ones", false)
|
|
27
|
-
.option("--numValidators <numValidators>", "Number of validators", "5")
|
|
28
|
-
.option("--headless", "Headless mode", false)
|
|
29
|
-
.option("--reset-db", "Reset Database", false)
|
|
30
|
-
.option("--ollama", "Enable Ollama container", false)
|
|
31
|
-
.action(async (options: StartActionOptions) => {
|
|
32
|
-
const startAction = new StartAction();
|
|
33
|
-
await startAction.execute(options);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
program
|
|
37
|
-
.command("stop")
|
|
38
|
-
.description("Stop all running localnet services.")
|
|
39
|
-
.action(async () => {
|
|
40
|
-
const stopAction = new StopAction();
|
|
41
|
-
await stopAction.stop();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return program;
|
|
45
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
import {DistinctQuestion} from "inquirer";
|
|
3
|
-
import {ISimulatorService} from "../../lib/interfaces/ISimulatorService";
|
|
4
|
-
import {AI_PROVIDERS_CONFIG, AiProviders, localnetCompatibleVersion} from "../../lib/config/simulator";
|
|
5
|
-
import {OllamaAction} from "../update/ollama";
|
|
6
|
-
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
7
|
-
import {SimulatorService} from "../../lib/services/simulator";
|
|
8
|
-
|
|
9
|
-
export interface InitActionOptions {
|
|
10
|
-
numValidators: number;
|
|
11
|
-
headless: boolean;
|
|
12
|
-
resetDb: boolean;
|
|
13
|
-
localnetVersion: string;
|
|
14
|
-
ollama: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getRequirementsErrorMessage({docker}: Record<string, boolean>): string {
|
|
18
|
-
if (!docker) {
|
|
19
|
-
return "Docker is not installed. Please install Docker and try again.\n";
|
|
20
|
-
}
|
|
21
|
-
return "";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getVersionErrorMessage({docker, node}: Record<string, string>): string {
|
|
25
|
-
let message = "";
|
|
26
|
-
|
|
27
|
-
if (docker) {
|
|
28
|
-
message += `Docker version ${docker} or higher is required. Please update Docker and try again.\n`;
|
|
29
|
-
}
|
|
30
|
-
if (node) {
|
|
31
|
-
message += `Node version ${node} or higher is required. Please update Node and try again.\n`;
|
|
32
|
-
}
|
|
33
|
-
return message;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class InitAction extends BaseAction {
|
|
37
|
-
private simulatorService: ISimulatorService;
|
|
38
|
-
constructor() {
|
|
39
|
-
super();
|
|
40
|
-
this.simulatorService = new SimulatorService();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public async execute(options: InitActionOptions): Promise<void> {
|
|
44
|
-
try {
|
|
45
|
-
this.simulatorService.setComposeOptions(options.headless, options.ollama);
|
|
46
|
-
let localnetVersion = options.localnetVersion;
|
|
47
|
-
if (localnetVersion !== "latest") {
|
|
48
|
-
localnetVersion = this.simulatorService.normalizeLocalnetVersion(localnetVersion);
|
|
49
|
-
|
|
50
|
-
if (this.simulatorService.compareVersions(localnetVersion, localnetCompatibleVersion) < 0) {
|
|
51
|
-
this.failSpinner(`Localnet version ${localnetVersion} is not supported. Minimum required version is ${localnetCompatibleVersion}. Please use a newer version.`);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.startSpinner("Checking CLI version...");
|
|
57
|
-
await this.simulatorService.checkCliVersion();
|
|
58
|
-
|
|
59
|
-
const isRunning = await this.simulatorService.isLocalnetRunning();
|
|
60
|
-
|
|
61
|
-
this.setSpinnerText("Checking installation requirements...");
|
|
62
|
-
const requirementsInstalled = await this.simulatorService.checkInstallRequirements();
|
|
63
|
-
const requirementErrorMessage = getRequirementsErrorMessage(requirementsInstalled);
|
|
64
|
-
if (requirementErrorMessage) {
|
|
65
|
-
this.failSpinner(requirementErrorMessage);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.setSpinnerText("Checking version requirements...");
|
|
70
|
-
const missingVersions = await this.simulatorService.checkVersionRequirements();
|
|
71
|
-
const versionErrorMessage = getVersionErrorMessage(missingVersions);
|
|
72
|
-
if (versionErrorMessage) {
|
|
73
|
-
this.failSpinner(versionErrorMessage);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this.stopSpinner();
|
|
77
|
-
|
|
78
|
-
const confirmMessage = isRunning
|
|
79
|
-
? `GenLayer Localnet is already running and this command is going to reset GenLayer docker images, containers and volumes, providers API Keys, and GenLayer database (accounts, transactions, validators and logs). Contract code (gpy files) will be kept. Do you want to continue?`
|
|
80
|
-
: `This command is going to reset GenLayer docker images, containers and volumes, providers API Keys, and GenLayer database (accounts, transactions, validators and logs). Contract code (gpy files) will be kept. Do you want to continue?`;
|
|
81
|
-
|
|
82
|
-
await this.confirmPrompt(confirmMessage);
|
|
83
|
-
|
|
84
|
-
this.logInfo(`Initializing GenLayer CLI with ${options.numValidators} validators`);
|
|
85
|
-
|
|
86
|
-
// Reset Docker containers, images, and volumes
|
|
87
|
-
this.startSpinner("Resetting Docker containers, images, and volumes...");
|
|
88
|
-
await this.simulatorService.resetDockerContainers();
|
|
89
|
-
await this.simulatorService.resetDockerImages();
|
|
90
|
-
await this.simulatorService.resetDockerVolumes();
|
|
91
|
-
this.stopSpinner();
|
|
92
|
-
|
|
93
|
-
const llmQuestions: DistinctQuestion[] = [
|
|
94
|
-
{
|
|
95
|
-
type: "checkbox",
|
|
96
|
-
name: "selectedLlmProviders",
|
|
97
|
-
message: "Select which LLM providers do you want to use:",
|
|
98
|
-
choices: this.simulatorService.getAiProvidersOptions(true, options.ollama ? [] : ["ollama"]),
|
|
99
|
-
validate: answer => (answer.length < 1 ? "You must choose at least one option." : true),
|
|
100
|
-
},
|
|
101
|
-
];
|
|
102
|
-
const llmProvidersAnswer = await inquirer.prompt(llmQuestions);
|
|
103
|
-
const selectedLlmProviders = llmProvidersAnswer.selectedLlmProviders as AiProviders[];
|
|
104
|
-
|
|
105
|
-
let defaultOllamaModel = this.getConfig().defaultOllamaModel;
|
|
106
|
-
const aiProvidersEnvVars: Record<string, string> = {};
|
|
107
|
-
const configurableAiProviders = selectedLlmProviders.filter(
|
|
108
|
-
(provider: AiProviders) => AI_PROVIDERS_CONFIG[provider].envVar,
|
|
109
|
-
);
|
|
110
|
-
for (const provider of configurableAiProviders) {
|
|
111
|
-
const providerConfig = AI_PROVIDERS_CONFIG[provider];
|
|
112
|
-
const keyQuestion: DistinctQuestion[] = [
|
|
113
|
-
{
|
|
114
|
-
type: "input",
|
|
115
|
-
name: providerConfig.cliOptionValue,
|
|
116
|
-
message: `Please enter your ${providerConfig.name} API Key:`,
|
|
117
|
-
validate: (value: string) =>
|
|
118
|
-
value.length ? true : `Please enter a valid API Key for ${providerConfig.name}.`,
|
|
119
|
-
},
|
|
120
|
-
];
|
|
121
|
-
const apiKeyAnswer = await inquirer.prompt(keyQuestion);
|
|
122
|
-
aiProvidersEnvVars[providerConfig.envVar!] = apiKeyAnswer[providerConfig.cliOptionValue];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
this.startSpinner("Configuring GenLayer Localnet environment...");
|
|
126
|
-
this.simulatorService.addConfigToEnvFile(aiProvidersEnvVars);
|
|
127
|
-
this.simulatorService.addConfigToEnvFile({LOCALNETVERSION: localnetVersion});
|
|
128
|
-
|
|
129
|
-
this.setSpinnerText("Running GenLayer Localnet...");
|
|
130
|
-
await this.simulatorService.runSimulator();
|
|
131
|
-
|
|
132
|
-
this.setSpinnerText("Waiting for localnet to be ready...");
|
|
133
|
-
const {initialized, errorCode, errorMessage} = await this.simulatorService.waitForSimulatorToBeReady();
|
|
134
|
-
if (!initialized) {
|
|
135
|
-
if (errorCode === "ERROR") {
|
|
136
|
-
this.failSpinner(`Unable to initialize the GenLayer Localnet: ${errorMessage}`);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (errorCode === "TIMEOUT") {
|
|
140
|
-
this.failSpinner(
|
|
141
|
-
"The localnet is taking too long to initialize. Please try again after the localnet is ready.",
|
|
142
|
-
);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
this.stopSpinner();
|
|
148
|
-
|
|
149
|
-
if (selectedLlmProviders.includes("ollama")) {
|
|
150
|
-
const ollamaAction = new OllamaAction();
|
|
151
|
-
if (!defaultOllamaModel) {
|
|
152
|
-
this.writeConfig("defaultOllamaModel", "llama3");
|
|
153
|
-
defaultOllamaModel = "llama3";
|
|
154
|
-
}
|
|
155
|
-
await ollamaAction.updateModel(defaultOllamaModel);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
this.startSpinner("Initializing validators...");
|
|
159
|
-
await this.simulatorService.deleteAllValidators();
|
|
160
|
-
await this.simulatorService.createRandomValidators(Number(options.numValidators), selectedLlmProviders);
|
|
161
|
-
|
|
162
|
-
if (options.resetDb) {
|
|
163
|
-
this.setSpinnerText("Cleaning database...");
|
|
164
|
-
await this.simulatorService.cleanDatabase();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
let successMessage = "GenLayer Localnet initialized successfully! ";
|
|
168
|
-
if (!options.headless) {
|
|
169
|
-
successMessage += `Go to ${this.simulatorService.getFrontendUrl()} in your browser to access it.`;
|
|
170
|
-
}
|
|
171
|
-
if (!options.headless) {
|
|
172
|
-
await this.simulatorService.openFrontend();
|
|
173
|
-
}
|
|
174
|
-
this.succeedSpinner(successMessage);
|
|
175
|
-
} catch (error) {
|
|
176
|
-
this.failSpinner("An error occurred during initialization.", error);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
import {ISimulatorService} from "../../lib/interfaces/ISimulatorService";
|
|
3
|
-
import {DistinctQuestion} from "inquirer";
|
|
4
|
-
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
5
|
-
import {SimulatorService} from "../../lib/services/simulator";
|
|
6
|
-
|
|
7
|
-
export interface StartActionOptions {
|
|
8
|
-
resetValidators: boolean;
|
|
9
|
-
numValidators: number;
|
|
10
|
-
headless: boolean;
|
|
11
|
-
resetDb: boolean;
|
|
12
|
-
ollama: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class StartAction extends BaseAction {
|
|
16
|
-
private simulatorService: ISimulatorService;
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
super();
|
|
20
|
-
this.simulatorService = new SimulatorService();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async execute(options: StartActionOptions) {
|
|
24
|
-
const {resetValidators, numValidators, headless, resetDb, ollama} = options;
|
|
25
|
-
|
|
26
|
-
this.simulatorService.setComposeOptions(headless, ollama);
|
|
27
|
-
this.startSpinner("Checking CLI version...");
|
|
28
|
-
await this.simulatorService.checkCliVersion();
|
|
29
|
-
|
|
30
|
-
const isRunning = await this.simulatorService.isLocalnetRunning();
|
|
31
|
-
if (isRunning) {
|
|
32
|
-
this.stopSpinner();
|
|
33
|
-
await this.confirmPrompt("GenLayer Localnet is already running. Do you want to proceed?");
|
|
34
|
-
this.startSpinner("Stopping Docker containers...");
|
|
35
|
-
await this.simulatorService.stopDockerContainers();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const restartValidatorsHintText = resetValidators
|
|
39
|
-
? `creating new ${numValidators} random validators`
|
|
40
|
-
: "keeping the existing validators";
|
|
41
|
-
this.setSpinnerText(`Starting GenLayer Localnet (${restartValidatorsHintText})...`);
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
await this.simulatorService.runSimulator();
|
|
45
|
-
} catch (error) {
|
|
46
|
-
this.failSpinner("Error starting the simulator", error);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
this.setSpinnerText("Waiting for the simulator to be ready...");
|
|
52
|
-
const {initialized, errorCode, errorMessage} = await this.simulatorService.waitForSimulatorToBeReady();
|
|
53
|
-
|
|
54
|
-
if (!initialized) {
|
|
55
|
-
if (errorCode === "ERROR") {
|
|
56
|
-
this.failSpinner("Unable to initialize the GenLayer simulator.", errorMessage);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (errorCode === "TIMEOUT") {
|
|
60
|
-
this.failSpinner("The simulator is taking too long to initialize. Please try again later.");
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
this.failSpinner("Error waiting for the simulator to be ready", error);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (resetDb) {
|
|
70
|
-
this.setSpinnerText("Resetting database...");
|
|
71
|
-
await this.simulatorService.cleanDatabase();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (resetValidators) {
|
|
75
|
-
this.setSpinnerText("Initializing validators...");
|
|
76
|
-
try {
|
|
77
|
-
await this.simulatorService.deleteAllValidators();
|
|
78
|
-
|
|
79
|
-
const questions: DistinctQuestion[] = [
|
|
80
|
-
{
|
|
81
|
-
type: "checkbox",
|
|
82
|
-
name: "selectedLlmProviders",
|
|
83
|
-
message: "Select which LLM providers do you want to use:",
|
|
84
|
-
choices: this.simulatorService.getAiProvidersOptions(false, ollama ? [] : ["ollama"]),
|
|
85
|
-
validate: answer => (answer.length < 1 ? "You must choose at least one option." : true),
|
|
86
|
-
},
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
const llmProvidersAnswer = await inquirer.prompt(questions);
|
|
90
|
-
await this.simulatorService.createRandomValidators(
|
|
91
|
-
numValidators,
|
|
92
|
-
llmProvidersAnswer.selectedLlmProviders,
|
|
93
|
-
);
|
|
94
|
-
} catch (error) {
|
|
95
|
-
this.failSpinner("Unable to initialize the validators", error);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let successMessage = "GenLayer simulator initialized successfully! ";
|
|
101
|
-
successMessage += headless
|
|
102
|
-
? ""
|
|
103
|
-
: `Go to ${this.simulatorService.getFrontendUrl()} in your browser to access it.`;
|
|
104
|
-
this.succeedSpinner(successMessage);
|
|
105
|
-
|
|
106
|
-
if (!headless) {
|
|
107
|
-
try {
|
|
108
|
-
this.startSpinner("Opening frontend...");
|
|
109
|
-
await this.simulatorService.openFrontend();
|
|
110
|
-
this.succeedSpinner("Frontend opened successfully");
|
|
111
|
-
} catch (error) {
|
|
112
|
-
this.failSpinner("Error opening the frontend", error);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { BaseAction } from "../../lib/actions/BaseAction";
|
|
2
|
-
import { SimulatorService } from "../../lib/services/simulator";
|
|
3
|
-
import { ISimulatorService } from "../../lib/interfaces/ISimulatorService";
|
|
4
|
-
|
|
5
|
-
export class StopAction extends BaseAction {
|
|
6
|
-
private simulatorService: ISimulatorService;
|
|
7
|
-
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
this.simulatorService = new SimulatorService();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public async stop(): Promise<void> {
|
|
14
|
-
try {
|
|
15
|
-
await this.confirmPrompt(
|
|
16
|
-
"Are you sure you want to stop all running GenLayer containers? This will halt all active processes."
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
this.startSpinner("Stopping Docker containers...");
|
|
20
|
-
await this.simulatorService.stopDockerContainers();
|
|
21
|
-
this.succeedSpinner("All running GenLayer containers have been successfully stopped.");
|
|
22
|
-
} catch (error) {
|
|
23
|
-
this.failSpinner("An error occurred while stopping the containers.", error);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { ValidatorsAction } from "./validators";
|
|
3
|
-
|
|
4
|
-
export function initializeValidatorCommands(program: Command) {
|
|
5
|
-
const validatorsAction = new ValidatorsAction();
|
|
6
|
-
|
|
7
|
-
const localnetCommand = program
|
|
8
|
-
.command("localnet")
|
|
9
|
-
.description("Manage localnet operations");
|
|
10
|
-
|
|
11
|
-
const validatorsCommand = localnetCommand
|
|
12
|
-
.command("validators")
|
|
13
|
-
.description("Manage localnet validators operations");
|
|
14
|
-
|
|
15
|
-
validatorsCommand
|
|
16
|
-
.command("get")
|
|
17
|
-
|
|
18
|
-
.description("Retrieve details of a specific validator or all validators")
|
|
19
|
-
.option("--address <validatorAddress>", "The address of the validator to retrieve (omit to retrieve all validators)")
|
|
20
|
-
.action(async (options) => {
|
|
21
|
-
await validatorsAction.getValidator({ address: options.address });
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
validatorsCommand
|
|
25
|
-
.command("delete")
|
|
26
|
-
.description("Delete a specific validator or all validators")
|
|
27
|
-
.option("--address <validatorAddress>", "The address of the validator to delete (omit to delete all validators)")
|
|
28
|
-
.action(async (options) => {
|
|
29
|
-
await validatorsAction.deleteValidator({ address: options.address });
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
validatorsCommand
|
|
33
|
-
.command("count")
|
|
34
|
-
.description("Count all validators")
|
|
35
|
-
.action(async () => {
|
|
36
|
-
await validatorsAction.countValidators();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
validatorsCommand
|
|
40
|
-
.command("update <validatorAddress>")
|
|
41
|
-
.description("Update a validator's details")
|
|
42
|
-
.option("--stake <stake>", "New stake for the validator")
|
|
43
|
-
.option("--provider <provider>", "New provider for the validator")
|
|
44
|
-
.option("--model <model>", "New model for the validator")
|
|
45
|
-
.option("--config <config>", "New JSON config for the validator")
|
|
46
|
-
.action(async (validatorAddress, options) => {
|
|
47
|
-
await validatorsAction.updateValidator({
|
|
48
|
-
address: validatorAddress,
|
|
49
|
-
stake: options.stake,
|
|
50
|
-
provider: options.provider,
|
|
51
|
-
model: options.model,
|
|
52
|
-
config: options.config,
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
validatorsCommand
|
|
57
|
-
.command("create-random")
|
|
58
|
-
.description("Create random validators")
|
|
59
|
-
.option("--count <count>", "Number of validators to create", "1") // Default to "1"
|
|
60
|
-
.option(
|
|
61
|
-
"--providers <providers...>",
|
|
62
|
-
"Space-separated list of provider names (e.g., openai ollama)",
|
|
63
|
-
[]
|
|
64
|
-
)
|
|
65
|
-
.option(
|
|
66
|
-
"--models <models...>",
|
|
67
|
-
"Space-separated list of model names (e.g., gpt-4 gpt-4o)",
|
|
68
|
-
[]
|
|
69
|
-
)
|
|
70
|
-
.action(async (options) => {
|
|
71
|
-
await validatorsAction.createRandomValidators({
|
|
72
|
-
count: options.count,
|
|
73
|
-
providers: options.providers,
|
|
74
|
-
models: options.models,
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
validatorsCommand
|
|
79
|
-
.command("create")
|
|
80
|
-
.description("Create a new validator")
|
|
81
|
-
.option("--stake <stake>", "Stake amount for the validator (default: 1)", "1")
|
|
82
|
-
.option(
|
|
83
|
-
"--config <config>",
|
|
84
|
-
`Optional JSON configuration for the validator (e.g., '{"max_tokens": 500, "temperature": 0.75}')`
|
|
85
|
-
)
|
|
86
|
-
.option("--provider <provider>", "Specify the provider for the validator")
|
|
87
|
-
.option("--model <model>", "Specify the model for the validator")
|
|
88
|
-
.action(async (options) => {
|
|
89
|
-
await validatorsAction.createValidator({
|
|
90
|
-
stake: options.stake,
|
|
91
|
-
config: options.config,
|
|
92
|
-
provider: options.provider,
|
|
93
|
-
model: options.model,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return program;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|