genlayer 0.12.4 → 0.12.5
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/.env.example +4 -0
- package/CHANGELOG.md +2 -0
- package/dist/index.js +406 -80
- package/esbuild.config.dev.js +1 -2
- package/esbuild.config.prod.js +1 -1
- package/eslint.config.js +2 -1
- package/package.json +5 -3
- package/src/commands/contracts/call.ts +16 -20
- package/src/commands/contracts/deploy.ts +107 -25
- package/src/commands/contracts/index.ts +14 -3
- package/src/commands/general/init.ts +0 -1
- package/src/commands/scaffold/index.ts +16 -0
- package/src/commands/scaffold/new.ts +34 -0
- package/src/index.ts +2 -0
- package/src/lib/actions/BaseAction.ts +6 -6
- package/src/lib/config/simulator.ts +2 -2
- package/templates/default/LICENSE +21 -0
- package/templates/default/README.md +101 -0
- package/templates/default/__init__.py +0 -0
- package/templates/default/app/.env.example +2 -0
- package/templates/default/app/.vscode/extensions.json +3 -0
- package/templates/default/app/README.md +5 -0
- package/templates/default/app/index.html +17 -0
- package/templates/default/app/package-lock.json +4920 -0
- package/templates/default/app/package.json +23 -0
- package/templates/default/app/postcss.config.js +6 -0
- package/templates/default/app/public/favicon.png +0 -0
- package/templates/default/app/src/App.vue +16 -0
- package/templates/default/app/src/components/Address.vue +38 -0
- package/templates/default/app/src/components/BetsScreen.vue +329 -0
- package/templates/default/app/src/logic/FootballBets.js +100 -0
- package/templates/default/app/src/main.js +5 -0
- package/templates/default/app/src/services/genlayer.js +19 -0
- package/templates/default/app/src/style.css +3 -0
- package/templates/default/app/tailwind.config.js +8 -0
- package/templates/default/app/vite.config.js +7 -0
- package/templates/default/config/__init__.py +0 -0
- package/templates/default/config/genlayer_config.py +14 -0
- package/templates/default/contracts/__init__.py +0 -0
- package/templates/default/contracts/football_bets.py +119 -0
- package/templates/default/deploy/deployScript.ts +31 -0
- package/templates/default/package-lock.json +3231 -0
- package/templates/default/package.json +7 -0
- package/templates/default/requirements.txt +6 -0
- package/templates/default/test/__init__.py +0 -0
- package/templates/default/test/football_bets_get_contract_schema_for_code.py +124 -0
- package/templates/default/test/test_football_bet_success_draw.py +108 -0
- package/templates/default/test/test_football_bet_success_win.py +106 -0
- package/templates/default/test/test_football_bet_unsuccess.py +107 -0
- package/templates/default/tools/__init__.py +0 -0
- package/templates/default/tools/accounts.py +5 -0
- package/templates/default/tools/calldata.py +224 -0
- package/templates/default/tools/request.py +134 -0
- package/templates/default/tools/response.py +52 -0
- package/templates/default/tools/structure.py +39 -0
- package/templates/default/tools/transactions.py +28 -0
- package/templates/default/tools/types.py +214 -0
- package/templates/default/tsconfig.json +7 -0
- package/tests/actions/call.test.ts +38 -76
- package/tests/actions/deploy.test.ts +200 -30
- package/tests/actions/new.test.ts +80 -0
- package/tests/commands/call.test.ts +6 -1
- package/tests/commands/deploy.test.ts +12 -1
- package/tests/commands/new.test.ts +68 -0
- package/tests/index.test.ts +4 -0
- package/vitest.config.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -9624,7 +9624,7 @@ var version3;
|
|
|
9624
9624
|
var init_version2 = __esm({
|
|
9625
9625
|
"node_modules/viem/_esm/errors/version.js"() {
|
|
9626
9626
|
"use strict";
|
|
9627
|
-
version3 = "2.23.
|
|
9627
|
+
version3 = "2.23.6";
|
|
9628
9628
|
}
|
|
9629
9629
|
});
|
|
9630
9630
|
|
|
@@ -16853,7 +16853,7 @@ var init_call = __esm({
|
|
|
16853
16853
|
import { program } from "commander";
|
|
16854
16854
|
|
|
16855
16855
|
// package.json
|
|
16856
|
-
var version = "0.12.
|
|
16856
|
+
var version = "0.12.5";
|
|
16857
16857
|
var package_default = {
|
|
16858
16858
|
name: "genlayer",
|
|
16859
16859
|
version,
|
|
@@ -16893,6 +16893,7 @@ var package_default = {
|
|
|
16893
16893
|
devDependencies: {
|
|
16894
16894
|
"@release-it/conventional-changelog": "^10.0.0",
|
|
16895
16895
|
"@types/dockerode": "^3.3.31",
|
|
16896
|
+
"@types/fs-extra": "^11.0.4",
|
|
16896
16897
|
"@types/inquirer": "^9.0.7",
|
|
16897
16898
|
"@types/node": "^22.0.0",
|
|
16898
16899
|
"@types/sinon": "^17.0.3",
|
|
@@ -16901,7 +16902,7 @@ var package_default = {
|
|
|
16901
16902
|
"@typescript-eslint/parser": "^8.0.0",
|
|
16902
16903
|
"@vitest/coverage-v8": "^2.1.4",
|
|
16903
16904
|
"cross-env": "^7.0.3",
|
|
16904
|
-
esbuild: "
|
|
16905
|
+
esbuild: ">=0.25.0",
|
|
16905
16906
|
eslint: "^9.0.0",
|
|
16906
16907
|
"eslint-config-prettier": "^10.0.0",
|
|
16907
16908
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
@@ -16918,7 +16919,8 @@ var package_default = {
|
|
|
16918
16919
|
dockerode: "^4.0.2",
|
|
16919
16920
|
dotenv: "^16.4.5",
|
|
16920
16921
|
ethers: "^6.13.4",
|
|
16921
|
-
"
|
|
16922
|
+
"fs-extra": "^11.3.0",
|
|
16923
|
+
"genlayer-js": "^0.9.0",
|
|
16922
16924
|
inquirer: "^12.0.0",
|
|
16923
16925
|
"node-fetch": "^3.0.0",
|
|
16924
16926
|
open: "^10.1.0",
|
|
@@ -16942,7 +16944,7 @@ var CLI_DESCRIPTION = "GenLayer CLI is a development environment for the GenLaye
|
|
|
16942
16944
|
import inquirer2 from "inquirer";
|
|
16943
16945
|
|
|
16944
16946
|
// src/lib/config/simulator.ts
|
|
16945
|
-
var localnetCompatibleVersion = "v0.
|
|
16947
|
+
var localnetCompatibleVersion = "v0.51.0";
|
|
16946
16948
|
var DEFAULT_JSON_RPC_URL = "http://localhost:4000/api";
|
|
16947
16949
|
var CONTAINERS_NAME_PREFIX = "/genlayer-";
|
|
16948
16950
|
var IMAGES_NAME_PREFIX = "yeagerai";
|
|
@@ -16966,7 +16968,7 @@ var STARTING_TIMEOUT_ATTEMPTS = 120;
|
|
|
16966
16968
|
var AI_PROVIDERS_CONFIG = {
|
|
16967
16969
|
ollama: {
|
|
16968
16970
|
name: "Ollama",
|
|
16969
|
-
hint: "(
|
|
16971
|
+
hint: "(By default, this will download and run a local instance of Llama 3)",
|
|
16970
16972
|
cliOptionValue: "ollama"
|
|
16971
16973
|
},
|
|
16972
16974
|
openai: {
|
|
@@ -19806,34 +19808,34 @@ var BaseAction = class extends ConfigFileManager {
|
|
|
19806
19808
|
log(message, data) {
|
|
19807
19809
|
console.log(source_default.white(`
|
|
19808
19810
|
${message}`));
|
|
19809
|
-
if (data) console.log(this.formatOutput(data));
|
|
19811
|
+
if (data !== void 0) console.log(this.formatOutput(data));
|
|
19810
19812
|
}
|
|
19811
19813
|
logSuccess(message, data) {
|
|
19812
19814
|
console.log(source_default.green(`
|
|
19813
19815
|
\u2714 ${message}`));
|
|
19814
|
-
if (data) console.log(source_default.green(this.formatOutput(data)));
|
|
19816
|
+
if (data !== void 0) console.log(source_default.green(this.formatOutput(data)));
|
|
19815
19817
|
}
|
|
19816
19818
|
logInfo(message, data) {
|
|
19817
19819
|
console.log(source_default.blue(`
|
|
19818
19820
|
\u2139 ${message}`));
|
|
19819
|
-
if (data) console.log(source_default.blue(this.formatOutput(data)));
|
|
19821
|
+
if (data !== void 0) console.log(source_default.blue(this.formatOutput(data)));
|
|
19820
19822
|
}
|
|
19821
19823
|
logWarning(message, data) {
|
|
19822
19824
|
console.log(source_default.yellow(`
|
|
19823
19825
|
\u26A0 ${message}`));
|
|
19824
|
-
if (data) console.log(source_default.yellow(this.formatOutput(data)));
|
|
19826
|
+
if (data !== void 0) console.log(source_default.yellow(this.formatOutput(data)));
|
|
19825
19827
|
}
|
|
19826
19828
|
logError(message, error) {
|
|
19827
19829
|
console.error(source_default.red(`
|
|
19828
19830
|
\u2716 ${message}`));
|
|
19829
|
-
if (error) console.error(source_default.red(this.formatOutput(error)));
|
|
19831
|
+
if (error !== void 0) console.error(source_default.red(this.formatOutput(error)));
|
|
19830
19832
|
}
|
|
19831
19833
|
startSpinner(message) {
|
|
19832
19834
|
this.spinner.text = source_default.blue(`${message}`);
|
|
19833
19835
|
this.spinner.start();
|
|
19834
19836
|
}
|
|
19835
19837
|
succeedSpinner(message, data) {
|
|
19836
|
-
if (data) this.log("Result:", data);
|
|
19838
|
+
if (data !== void 0) this.log("Result:", data);
|
|
19837
19839
|
this.spinner.succeed(source_default.green(message));
|
|
19838
19840
|
}
|
|
19839
19841
|
failSpinner(message, error) {
|
|
@@ -20726,7 +20728,6 @@ var InitAction = class extends BaseAction {
|
|
|
20726
20728
|
const llmProvidersAnswer = await inquirer2.prompt(llmQuestions);
|
|
20727
20729
|
const selectedLlmProviders = llmProvidersAnswer.selectedLlmProviders;
|
|
20728
20730
|
let defaultOllamaModel = this.getConfig().defaultOllamaModel;
|
|
20729
|
-
AI_PROVIDERS_CONFIG.ollama.hint = `(This will download and run a local instance of ${defaultOllamaModel})`;
|
|
20730
20731
|
const aiProvidersEnvVars = {};
|
|
20731
20732
|
const configurableAiProviders = selectedLlmProviders.filter(
|
|
20732
20733
|
(provider) => AI_PROVIDERS_CONFIG[provider].envVar
|
|
@@ -20954,6 +20955,7 @@ function initializeKeygenCommands(program2) {
|
|
|
20954
20955
|
|
|
20955
20956
|
// src/commands/contracts/deploy.ts
|
|
20956
20957
|
import fs9 from "fs";
|
|
20958
|
+
import path4 from "path";
|
|
20957
20959
|
|
|
20958
20960
|
// node_modules/genlayer-js/dist/chunk-MLKGABMK.js
|
|
20959
20961
|
var __defProp2 = Object.defineProperty;
|
|
@@ -27894,15 +27896,16 @@ init_encodeFunctionData();
|
|
|
27894
27896
|
init_toHex();
|
|
27895
27897
|
init_fromHex();
|
|
27896
27898
|
|
|
27897
|
-
// node_modules/genlayer-js/dist/chunk-
|
|
27899
|
+
// node_modules/genlayer-js/dist/chunk-WEXFFND6.js
|
|
27898
27900
|
var chains_exports = {};
|
|
27899
27901
|
__export2(chains_exports, {
|
|
27902
|
+
localnet: () => localnet,
|
|
27900
27903
|
simulator: () => simulator
|
|
27901
27904
|
});
|
|
27902
27905
|
var SIMULATOR_JSON_RPC_URL = "http://127.0.0.1:4000/api";
|
|
27903
|
-
var
|
|
27906
|
+
var localnet = defineChain({
|
|
27904
27907
|
id: 61999,
|
|
27905
|
-
name: "
|
|
27908
|
+
name: "Genlayer Localnet",
|
|
27906
27909
|
rpcUrls: {
|
|
27907
27910
|
default: {
|
|
27908
27911
|
http: [SIMULATOR_JSON_RPC_URL]
|
|
@@ -27924,8 +27927,33 @@ var simulator = defineChain({
|
|
|
27924
27927
|
defaultNumberOfInitialValidators: 5,
|
|
27925
27928
|
defaultConsensusMaxRotations: 3
|
|
27926
27929
|
});
|
|
27930
|
+
var SIMULATOR_JSON_RPC_URL2 = "http://127.0.0.1:4000/api";
|
|
27931
|
+
var simulator = defineChain({
|
|
27932
|
+
id: 61999,
|
|
27933
|
+
name: "GenLayer Simulator",
|
|
27934
|
+
rpcUrls: {
|
|
27935
|
+
default: {
|
|
27936
|
+
http: [SIMULATOR_JSON_RPC_URL2]
|
|
27937
|
+
}
|
|
27938
|
+
},
|
|
27939
|
+
nativeCurrency: {
|
|
27940
|
+
name: "GEN Token",
|
|
27941
|
+
symbol: "GEN",
|
|
27942
|
+
decimals: 18
|
|
27943
|
+
},
|
|
27944
|
+
blockExplorers: {
|
|
27945
|
+
default: {
|
|
27946
|
+
name: "GenLayer Explorer",
|
|
27947
|
+
url: SIMULATOR_JSON_RPC_URL2
|
|
27948
|
+
}
|
|
27949
|
+
},
|
|
27950
|
+
testnet: true,
|
|
27951
|
+
consensusMainContract: null,
|
|
27952
|
+
defaultNumberOfInitialValidators: 5,
|
|
27953
|
+
defaultConsensusMaxRotations: 3
|
|
27954
|
+
});
|
|
27927
27955
|
|
|
27928
|
-
// node_modules/genlayer-js/dist/chunk-
|
|
27956
|
+
// node_modules/genlayer-js/dist/chunk-K72OSU5N.js
|
|
27929
27957
|
var CalldataAddress = class {
|
|
27930
27958
|
constructor(addr) {
|
|
27931
27959
|
__publicField(this, "bytes");
|
|
@@ -27935,6 +27963,17 @@ var CalldataAddress = class {
|
|
|
27935
27963
|
this.bytes = addr;
|
|
27936
27964
|
}
|
|
27937
27965
|
};
|
|
27966
|
+
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
27967
|
+
TransactionStatus2["PENDING"] = "PENDING";
|
|
27968
|
+
TransactionStatus2["CANCELED"] = "CANCELED";
|
|
27969
|
+
TransactionStatus2["PROPOSING"] = "PROPOSING";
|
|
27970
|
+
TransactionStatus2["COMMITTING"] = "COMMITTING";
|
|
27971
|
+
TransactionStatus2["REVEALING"] = "REVEALING";
|
|
27972
|
+
TransactionStatus2["ACCEPTED"] = "ACCEPTED";
|
|
27973
|
+
TransactionStatus2["FINALIZED"] = "FINALIZED";
|
|
27974
|
+
TransactionStatus2["UNDETERMINED"] = "UNDETERMINED";
|
|
27975
|
+
return TransactionStatus2;
|
|
27976
|
+
})(TransactionStatus || {});
|
|
27938
27977
|
|
|
27939
27978
|
// node_modules/viem/_esm/accounts/generatePrivateKey.js
|
|
27940
27979
|
init_secp256k1();
|
|
@@ -28080,8 +28119,8 @@ function privateKeyToAccount(privateKey, options = {}) {
|
|
|
28080
28119
|
function accountActions(client) {
|
|
28081
28120
|
return {
|
|
28082
28121
|
fundAccount: async ({ address, amount }) => {
|
|
28083
|
-
if (client.chain?.id !==
|
|
28084
|
-
throw new Error("Client is not connected to the
|
|
28122
|
+
if (client.chain?.id !== localnet.id) {
|
|
28123
|
+
throw new Error("Client is not connected to the localnet");
|
|
28085
28124
|
}
|
|
28086
28125
|
return client.request({
|
|
28087
28126
|
method: "sim_fundAccount",
|
|
@@ -28488,18 +28527,18 @@ var overrideContractActions = (client) => {
|
|
|
28488
28527
|
return decode2(resultBinary);
|
|
28489
28528
|
};
|
|
28490
28529
|
client.writeContract = async (args) => {
|
|
28491
|
-
const { account, address, functionName, args: callArgs, kwargs, value = 0n, leaderOnly = false } = args;
|
|
28530
|
+
const { account, address, functionName, args: callArgs, kwargs, value = 0n, leaderOnly = false, consensusMaxRotations = client.chain.defaultConsensusMaxRotations } = args;
|
|
28492
28531
|
const data = [encode4(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
28493
28532
|
const serializedData = serialize(data);
|
|
28494
|
-
return _sendTransaction(address, serializedData, account || client.account, value);
|
|
28533
|
+
return _sendTransaction(address, serializedData, account || client.account, consensusMaxRotations, value);
|
|
28495
28534
|
};
|
|
28496
28535
|
client.deployContract = async (args) => {
|
|
28497
|
-
const { account, code, args: constructorArgs, kwargs, leaderOnly = false } = args;
|
|
28536
|
+
const { account, code, args: constructorArgs, kwargs, leaderOnly = false, consensusMaxRotations = client.chain.defaultConsensusMaxRotations } = args;
|
|
28498
28537
|
const data = [code, encode4(makeCalldataObject(void 0, constructorArgs, kwargs)), leaderOnly];
|
|
28499
28538
|
const serializedData = serialize(data);
|
|
28500
|
-
return _sendTransaction(zeroAddress, serializedData, account || client.account);
|
|
28539
|
+
return _sendTransaction(zeroAddress, serializedData, account || client.account, consensusMaxRotations);
|
|
28501
28540
|
};
|
|
28502
|
-
const _sendTransaction = async (recipient, data, senderAccount, value) => {
|
|
28541
|
+
const _sendTransaction = async (recipient, data, senderAccount, consensusMaxRotations, value) => {
|
|
28503
28542
|
if (!senderAccount) {
|
|
28504
28543
|
throw new Error(
|
|
28505
28544
|
"No account set. Configure the client with an account or pass an account to this function."
|
|
@@ -28517,7 +28556,7 @@ var overrideContractActions = (client) => {
|
|
|
28517
28556
|
senderAccount.address,
|
|
28518
28557
|
recipient,
|
|
28519
28558
|
client.chain.defaultNumberOfInitialValidators,
|
|
28520
|
-
|
|
28559
|
+
consensusMaxRotations,
|
|
28521
28560
|
data
|
|
28522
28561
|
]
|
|
28523
28562
|
});
|
|
@@ -28557,6 +28596,51 @@ var transactionsConfig = {
|
|
|
28557
28596
|
async function sleep2(ms) {
|
|
28558
28597
|
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
28559
28598
|
}
|
|
28599
|
+
var abi_exports = {};
|
|
28600
|
+
__export2(abi_exports, {
|
|
28601
|
+
calldata: () => calldata,
|
|
28602
|
+
transactions: () => transactions
|
|
28603
|
+
});
|
|
28604
|
+
var calldata = calldata_exports;
|
|
28605
|
+
var transactions = transactions_exports;
|
|
28606
|
+
function b64ToArray(b64) {
|
|
28607
|
+
return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
|
|
28608
|
+
}
|
|
28609
|
+
function calldataToUserFriendlyJson(cd) {
|
|
28610
|
+
return {
|
|
28611
|
+
raw: Array.from(cd),
|
|
28612
|
+
readable: calldata.toString(calldata.decode(cd))
|
|
28613
|
+
};
|
|
28614
|
+
}
|
|
28615
|
+
var RESULT_CODES = /* @__PURE__ */ new Map([
|
|
28616
|
+
[0, "return"],
|
|
28617
|
+
[1, "rollback"],
|
|
28618
|
+
[2, "contract_error"],
|
|
28619
|
+
[3, "error"],
|
|
28620
|
+
[4, "none"],
|
|
28621
|
+
[5, "no_leaders"]
|
|
28622
|
+
]);
|
|
28623
|
+
function resultToUserFriendlyJson(cd64) {
|
|
28624
|
+
const raw = b64ToArray(cd64);
|
|
28625
|
+
const code = RESULT_CODES.get(raw[0]);
|
|
28626
|
+
let status;
|
|
28627
|
+
let payload = null;
|
|
28628
|
+
if (code === void 0) {
|
|
28629
|
+
status = "<unknown>";
|
|
28630
|
+
} else {
|
|
28631
|
+
status = code;
|
|
28632
|
+
if ([1, 2].includes(raw[0])) {
|
|
28633
|
+
payload = new TextDecoder("utf-8").decode(raw.slice(1));
|
|
28634
|
+
} else if (raw[0] == 0) {
|
|
28635
|
+
payload = calldataToUserFriendlyJson(raw.slice(1));
|
|
28636
|
+
}
|
|
28637
|
+
}
|
|
28638
|
+
return {
|
|
28639
|
+
raw: cd64,
|
|
28640
|
+
status,
|
|
28641
|
+
payload
|
|
28642
|
+
};
|
|
28643
|
+
}
|
|
28560
28644
|
var transactionActions = (client) => ({
|
|
28561
28645
|
waitForTransactionReceipt: async ({
|
|
28562
28646
|
hash: hash2,
|
|
@@ -28569,7 +28653,7 @@ var transactionActions = (client) => ({
|
|
|
28569
28653
|
throw new Error("Transaction not found");
|
|
28570
28654
|
}
|
|
28571
28655
|
if (transaction.status === status || status === "ACCEPTED" && transaction.status === "FINALIZED") {
|
|
28572
|
-
return transaction;
|
|
28656
|
+
return _decodeTransaction(transaction);
|
|
28573
28657
|
}
|
|
28574
28658
|
if (retries === 0) {
|
|
28575
28659
|
throw new Error("Transaction status is not " + status);
|
|
@@ -28583,6 +28667,137 @@ var transactionActions = (client) => ({
|
|
|
28583
28667
|
});
|
|
28584
28668
|
}
|
|
28585
28669
|
});
|
|
28670
|
+
var _decodeTransaction = (tx) => {
|
|
28671
|
+
if (!tx.data) return tx;
|
|
28672
|
+
try {
|
|
28673
|
+
const leaderReceipt = tx.consensus_data?.leader_receipt;
|
|
28674
|
+
if (leaderReceipt) {
|
|
28675
|
+
if (leaderReceipt.result) {
|
|
28676
|
+
leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
|
|
28677
|
+
}
|
|
28678
|
+
if (leaderReceipt.calldata) {
|
|
28679
|
+
leaderReceipt.calldata = {
|
|
28680
|
+
base64: leaderReceipt.calldata,
|
|
28681
|
+
...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata))
|
|
28682
|
+
};
|
|
28683
|
+
}
|
|
28684
|
+
if (leaderReceipt.eq_outputs) {
|
|
28685
|
+
leaderReceipt.eq_outputs = Object.fromEntries(
|
|
28686
|
+
Object.entries(leaderReceipt.eq_outputs).map(([key, value]) => {
|
|
28687
|
+
const decodedValue = new TextDecoder().decode(b64ToArray(String(value)));
|
|
28688
|
+
return [key, resultToUserFriendlyJson(decodedValue)];
|
|
28689
|
+
})
|
|
28690
|
+
);
|
|
28691
|
+
}
|
|
28692
|
+
}
|
|
28693
|
+
if (tx.data.calldata) {
|
|
28694
|
+
tx.data.calldata = {
|
|
28695
|
+
base64: tx.data.calldata,
|
|
28696
|
+
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
28697
|
+
};
|
|
28698
|
+
}
|
|
28699
|
+
} catch (e2) {
|
|
28700
|
+
console.error("Error decoding transaction:", e2);
|
|
28701
|
+
}
|
|
28702
|
+
return tx;
|
|
28703
|
+
};
|
|
28704
|
+
var snapID = {
|
|
28705
|
+
local: "local:http://localhost:8081",
|
|
28706
|
+
npm: "npm:genlayer-wallet-plugin"
|
|
28707
|
+
};
|
|
28708
|
+
var networks = {
|
|
28709
|
+
localnet
|
|
28710
|
+
};
|
|
28711
|
+
var connect = async (client, network = "localnet", snapSource = "npm") => {
|
|
28712
|
+
if (!window.ethereum) {
|
|
28713
|
+
throw new Error("MetaMask is not installed.");
|
|
28714
|
+
}
|
|
28715
|
+
if (network === "testnet" || network === "mainnet") {
|
|
28716
|
+
throw new Error(`${network} is not available yet. Please use localnet.`);
|
|
28717
|
+
}
|
|
28718
|
+
const selectedNetwork = networks[network];
|
|
28719
|
+
if (!selectedNetwork) {
|
|
28720
|
+
throw new Error(`Network configuration for '${network}' is not available.`);
|
|
28721
|
+
}
|
|
28722
|
+
const chainIdHex = `0x${selectedNetwork.id.toString(16)}`;
|
|
28723
|
+
const chainParams = {
|
|
28724
|
+
chainId: chainIdHex,
|
|
28725
|
+
chainName: selectedNetwork.name,
|
|
28726
|
+
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
28727
|
+
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
28728
|
+
blockExplorerUrls: [selectedNetwork.blockExplorers?.default.url]
|
|
28729
|
+
};
|
|
28730
|
+
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
28731
|
+
if (currentChainId !== chainIdHex) {
|
|
28732
|
+
await window.ethereum.request({
|
|
28733
|
+
method: "wallet_addEthereumChain",
|
|
28734
|
+
params: [chainParams]
|
|
28735
|
+
});
|
|
28736
|
+
await window.ethereum.request({
|
|
28737
|
+
method: "wallet_switchEthereumChain",
|
|
28738
|
+
params: [{ chainId: chainIdHex }]
|
|
28739
|
+
});
|
|
28740
|
+
}
|
|
28741
|
+
const id = snapSource === "local" ? snapID.local : snapID.npm;
|
|
28742
|
+
const installedSnaps = await window.ethereum.request({ method: "wallet_getSnaps" });
|
|
28743
|
+
const isGenLayerSnapInstalled = Object.values(installedSnaps).some(
|
|
28744
|
+
(snap) => snap.id === id
|
|
28745
|
+
);
|
|
28746
|
+
if (!isGenLayerSnapInstalled) {
|
|
28747
|
+
await window.ethereum.request({
|
|
28748
|
+
method: "wallet_requestSnaps",
|
|
28749
|
+
params: {
|
|
28750
|
+
[id]: {}
|
|
28751
|
+
}
|
|
28752
|
+
});
|
|
28753
|
+
}
|
|
28754
|
+
client.chain = selectedNetwork;
|
|
28755
|
+
};
|
|
28756
|
+
var metamaskClient = async (snapSource = "npm") => {
|
|
28757
|
+
if (typeof window === "undefined" || !window.ethereum) {
|
|
28758
|
+
throw new Error("MetaMask is not installed.");
|
|
28759
|
+
}
|
|
28760
|
+
const isFlask = async () => {
|
|
28761
|
+
try {
|
|
28762
|
+
const clientVersion = await window.ethereum?.request({
|
|
28763
|
+
method: "web3_clientVersion"
|
|
28764
|
+
});
|
|
28765
|
+
return clientVersion?.includes("flask");
|
|
28766
|
+
} catch (error) {
|
|
28767
|
+
console.error("Error detecting Flask:", error);
|
|
28768
|
+
return false;
|
|
28769
|
+
}
|
|
28770
|
+
};
|
|
28771
|
+
const installedSnaps = async () => {
|
|
28772
|
+
try {
|
|
28773
|
+
return await window.ethereum?.request({
|
|
28774
|
+
method: "wallet_getSnaps"
|
|
28775
|
+
});
|
|
28776
|
+
} catch (error) {
|
|
28777
|
+
console.error("Error getting installed snaps:", error);
|
|
28778
|
+
return {};
|
|
28779
|
+
}
|
|
28780
|
+
};
|
|
28781
|
+
const isGenLayerSnapInstalled = async () => {
|
|
28782
|
+
const id = snapSource === "local" ? snapID.local : snapID.npm;
|
|
28783
|
+
const snaps = await installedSnaps();
|
|
28784
|
+
return Object.values(snaps).some((snap) => snap.id === id);
|
|
28785
|
+
};
|
|
28786
|
+
const flaskDetected = await isFlask();
|
|
28787
|
+
const snapsList = await installedSnaps();
|
|
28788
|
+
const genLayerSnapInstalled = await isGenLayerSnapInstalled();
|
|
28789
|
+
return {
|
|
28790
|
+
isFlask: flaskDetected,
|
|
28791
|
+
installedSnaps: snapsList,
|
|
28792
|
+
isGenLayerSnapInstalled: genLayerSnapInstalled
|
|
28793
|
+
};
|
|
28794
|
+
};
|
|
28795
|
+
function walletActions2(client) {
|
|
28796
|
+
return {
|
|
28797
|
+
connect: (network, snapSource) => connect(client, network, snapSource),
|
|
28798
|
+
metamaskClient: (snapSource = "npm") => metamaskClient(snapSource)
|
|
28799
|
+
};
|
|
28800
|
+
}
|
|
28586
28801
|
function chainActions(client) {
|
|
28587
28802
|
return {
|
|
28588
28803
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
@@ -28612,8 +28827,8 @@ function chainActions(client) {
|
|
|
28612
28827
|
}
|
|
28613
28828
|
};
|
|
28614
28829
|
}
|
|
28615
|
-
var createClient2 = (config = { chain:
|
|
28616
|
-
const chainConfig = config.chain ||
|
|
28830
|
+
var createClient2 = (config = { chain: localnet }) => {
|
|
28831
|
+
const chainConfig = config.chain || localnet;
|
|
28617
28832
|
if (config.endpoint) {
|
|
28618
28833
|
chainConfig.rpcUrls.default.http = [config.endpoint];
|
|
28619
28834
|
}
|
|
@@ -28657,7 +28872,7 @@ var createClient2 = (config = { chain: simulator }) => {
|
|
|
28657
28872
|
chain: chainConfig,
|
|
28658
28873
|
transport: custom(customTransport),
|
|
28659
28874
|
...config.account ? { account: config.account } : {}
|
|
28660
|
-
}).extend(publicActions).extend(walletActions).extend((client) => accountActions(client)).extend((client) => transactionActions(client)).extend((client) => contractActions(client)).extend((client) => chainActions(client));
|
|
28875
|
+
}).extend(publicActions).extend(walletActions).extend((client) => accountActions(client)).extend((client) => transactionActions(client)).extend((client) => contractActions(client)).extend((client) => chainActions(client)).extend((client) => walletActions2(client));
|
|
28661
28876
|
baseClient.initializeConsensusSmartContract().catch((error) => {
|
|
28662
28877
|
console.error("Failed to initialize consensus smart contract:", error);
|
|
28663
28878
|
});
|
|
@@ -28669,13 +28884,6 @@ var createAccount = (accountPrivateKey) => {
|
|
|
28669
28884
|
const account = privateKeyToAccount(privateKey);
|
|
28670
28885
|
return account;
|
|
28671
28886
|
};
|
|
28672
|
-
var abi_exports = {};
|
|
28673
|
-
__export2(abi_exports, {
|
|
28674
|
-
calldata: () => calldata,
|
|
28675
|
-
transactions: () => transactions
|
|
28676
|
-
});
|
|
28677
|
-
var calldata = calldata_exports;
|
|
28678
|
-
var transactions = transactions_exports;
|
|
28679
28887
|
|
|
28680
28888
|
// src/lib/accounts/getPrivateKey.ts
|
|
28681
28889
|
import fs8 from "fs";
|
|
@@ -28695,9 +28903,13 @@ function getPrivateKey() {
|
|
|
28695
28903
|
}
|
|
28696
28904
|
|
|
28697
28905
|
// src/commands/contracts/deploy.ts
|
|
28698
|
-
|
|
28906
|
+
import { pathToFileURL } from "url";
|
|
28907
|
+
import { buildSync } from "esbuild";
|
|
28908
|
+
var DeployAction = class extends BaseAction {
|
|
28699
28909
|
constructor() {
|
|
28910
|
+
super();
|
|
28700
28911
|
__publicField(this, "genlayerClient");
|
|
28912
|
+
__publicField(this, "deployDir", path4.resolve(process.cwd(), "deploy"));
|
|
28701
28913
|
this.genlayerClient = createClient2({
|
|
28702
28914
|
chain: simulator,
|
|
28703
28915
|
endpoint: process.env.VITE_JSON_RPC_SERVER_URL,
|
|
@@ -28710,41 +28922,113 @@ var DeployAction = class {
|
|
|
28710
28922
|
}
|
|
28711
28923
|
return fs9.readFileSync(contractPath, "utf-8");
|
|
28712
28924
|
}
|
|
28713
|
-
async
|
|
28714
|
-
const
|
|
28715
|
-
|
|
28716
|
-
|
|
28717
|
-
|
|
28925
|
+
async executeTsScript(filePath) {
|
|
28926
|
+
const outFile = filePath.replace(/\.ts$/, ".compiled.js");
|
|
28927
|
+
this.startSpinner(`Transpiling TypeScript file: ${filePath}`);
|
|
28928
|
+
try {
|
|
28929
|
+
buildSync({
|
|
28930
|
+
entryPoints: [filePath],
|
|
28931
|
+
outfile: outFile,
|
|
28932
|
+
bundle: false,
|
|
28933
|
+
platform: "node",
|
|
28934
|
+
format: "esm",
|
|
28935
|
+
target: "es2020",
|
|
28936
|
+
sourcemap: false
|
|
28937
|
+
});
|
|
28938
|
+
await this.executeJsScript(filePath, outFile);
|
|
28939
|
+
} catch (error) {
|
|
28940
|
+
this.failSpinner(`Error executing: ${filePath}`, error);
|
|
28941
|
+
} finally {
|
|
28942
|
+
fs9.unlinkSync(outFile);
|
|
28943
|
+
}
|
|
28944
|
+
}
|
|
28945
|
+
async executeJsScript(filePath, transpiledFilePath) {
|
|
28946
|
+
this.startSpinner(`Executing file: ${filePath}`);
|
|
28947
|
+
try {
|
|
28948
|
+
const module = await import(pathToFileURL(transpiledFilePath || filePath).href);
|
|
28949
|
+
if (!module.default || typeof module.default !== "function") {
|
|
28950
|
+
this.failSpinner(`No "default" function found in: ${filePath}`);
|
|
28951
|
+
return;
|
|
28952
|
+
}
|
|
28953
|
+
await module.default(this.genlayerClient);
|
|
28954
|
+
this.succeedSpinner(`Successfully executed: ${filePath}`);
|
|
28955
|
+
} catch (error) {
|
|
28956
|
+
this.failSpinner(`Error executing: ${filePath}`, error);
|
|
28718
28957
|
}
|
|
28719
|
-
|
|
28720
|
-
|
|
28958
|
+
}
|
|
28959
|
+
async deployScripts() {
|
|
28960
|
+
this.startSpinner("Searching for deploy scripts...");
|
|
28961
|
+
if (!fs9.existsSync(this.deployDir)) {
|
|
28962
|
+
this.failSpinner("No deploy folder found.");
|
|
28721
28963
|
return;
|
|
28722
28964
|
}
|
|
28723
|
-
const
|
|
28724
|
-
|
|
28725
|
-
|
|
28965
|
+
const files = fs9.readdirSync(this.deployDir).filter((file) => file.endsWith(".ts") || file.endsWith(".js")).sort((a, b) => {
|
|
28966
|
+
const numA = parseInt(a.split("_")[0]);
|
|
28967
|
+
const numB = parseInt(b.split("_")[0]);
|
|
28968
|
+
if (!isNaN(numA) && !isNaN(numB)) return numA - numB;
|
|
28969
|
+
if (!isNaN(numA)) return -1;
|
|
28970
|
+
if (!isNaN(numB)) return 1;
|
|
28971
|
+
return a.localeCompare(b);
|
|
28972
|
+
});
|
|
28973
|
+
if (files.length === 0) {
|
|
28974
|
+
this.failSpinner("No deploy scripts found.");
|
|
28726
28975
|
return;
|
|
28727
28976
|
}
|
|
28728
|
-
|
|
28729
|
-
|
|
28730
|
-
|
|
28731
|
-
|
|
28977
|
+
this.setSpinnerText(`Found ${files.length} deploy scripts. Executing...`);
|
|
28978
|
+
for (const file of files) {
|
|
28979
|
+
const filePath = path4.resolve(this.deployDir, file);
|
|
28980
|
+
this.setSpinnerText(`Executing script: ${filePath}`);
|
|
28981
|
+
try {
|
|
28982
|
+
if (file.endsWith(".ts")) {
|
|
28983
|
+
await this.executeTsScript(filePath);
|
|
28984
|
+
} else {
|
|
28985
|
+
await this.executeJsScript(filePath);
|
|
28986
|
+
}
|
|
28987
|
+
} catch (error) {
|
|
28988
|
+
this.failSpinner(`Error executing script: ${filePath}`, error);
|
|
28989
|
+
}
|
|
28990
|
+
}
|
|
28991
|
+
}
|
|
28992
|
+
async deploy(options) {
|
|
28732
28993
|
try {
|
|
28994
|
+
this.startSpinner("Setting up the deployment environment...");
|
|
28995
|
+
await this.genlayerClient.initializeConsensusSmartContract();
|
|
28996
|
+
if (!options.contract) {
|
|
28997
|
+
this.failSpinner("No contract specified for deployment.");
|
|
28998
|
+
return;
|
|
28999
|
+
}
|
|
29000
|
+
this.setSpinnerText("Reading contract code...");
|
|
29001
|
+
const contractCode = this.readContractCode(options.contract);
|
|
29002
|
+
if (!contractCode) {
|
|
29003
|
+
this.failSpinner("Contract code is empty.");
|
|
29004
|
+
return;
|
|
29005
|
+
}
|
|
29006
|
+
const leaderOnly = false;
|
|
29007
|
+
const deployParams = { code: contractCode, args: options.args, leaderOnly };
|
|
29008
|
+
this.setSpinnerText("Starting contract deployment...");
|
|
29009
|
+
this.log("Deployment Parameters:", deployParams);
|
|
28733
29010
|
const hash2 = await this.genlayerClient.deployContract(deployParams);
|
|
28734
|
-
const result = await this.genlayerClient.waitForTransactionReceipt({
|
|
28735
|
-
|
|
28736
|
-
|
|
28737
|
-
|
|
29011
|
+
const result = await this.genlayerClient.waitForTransactionReceipt({
|
|
29012
|
+
hash: hash2,
|
|
29013
|
+
retries: 15,
|
|
29014
|
+
interval: 2e3,
|
|
29015
|
+
status: TransactionStatus.ACCEPTED
|
|
29016
|
+
});
|
|
29017
|
+
this.log("Deployment Receipt:", result);
|
|
29018
|
+
this.succeedSpinner("Contract deployed successfully.", {
|
|
29019
|
+
"Transaction Hash": hash2,
|
|
29020
|
+
"Contract Address": result.data?.contract_address
|
|
29021
|
+
});
|
|
28738
29022
|
} catch (error) {
|
|
28739
|
-
|
|
28740
|
-
throw new Error("Contract deployment failed.");
|
|
29023
|
+
this.failSpinner("Error deploying contract", error);
|
|
28741
29024
|
}
|
|
28742
29025
|
}
|
|
28743
29026
|
};
|
|
28744
29027
|
|
|
28745
29028
|
// src/commands/contracts/call.ts
|
|
28746
|
-
var CallAction = class {
|
|
29029
|
+
var CallAction = class extends BaseAction {
|
|
28747
29030
|
constructor() {
|
|
29031
|
+
super();
|
|
28748
29032
|
__publicField(this, "genlayerClient");
|
|
28749
29033
|
this.genlayerClient = createClient2({
|
|
28750
29034
|
chain: simulator,
|
|
@@ -28757,23 +29041,18 @@ var CallAction = class {
|
|
|
28757
29041
|
method,
|
|
28758
29042
|
args
|
|
28759
29043
|
}) {
|
|
28760
|
-
|
|
29044
|
+
this.startSpinner(`Calling method ${method} on contract at ${contractAddress}...`);
|
|
28761
29045
|
const contractSchema = await this.genlayerClient.getContractSchema(contractAddress);
|
|
28762
29046
|
if (!contractSchema.methods.hasOwnProperty(method)) {
|
|
28763
|
-
|
|
28764
|
-
|
|
29047
|
+
this.failSpinner(`method ${method} not found.`);
|
|
29048
|
+
return;
|
|
28765
29049
|
}
|
|
28766
29050
|
const readonly = contractSchema.methods[method].readonly;
|
|
28767
|
-
|
|
28768
|
-
|
|
28769
|
-
|
|
28770
|
-
} else {
|
|
28771
|
-
await this.executeWrite(contractAddress, method, args);
|
|
28772
|
-
}
|
|
28773
|
-
} catch (error) {
|
|
28774
|
-
console.error("Error calling contract method:", error);
|
|
28775
|
-
throw error;
|
|
29051
|
+
if (readonly) {
|
|
29052
|
+
await this.executeRead(contractAddress, method, args);
|
|
29053
|
+
return;
|
|
28776
29054
|
}
|
|
29055
|
+
await this.executeWrite(contractAddress, method, args);
|
|
28777
29056
|
}
|
|
28778
29057
|
async executeRead(contractAddress, method, args) {
|
|
28779
29058
|
try {
|
|
@@ -28782,10 +29061,9 @@ var CallAction = class {
|
|
|
28782
29061
|
functionName: method,
|
|
28783
29062
|
args
|
|
28784
29063
|
});
|
|
28785
|
-
|
|
29064
|
+
this.succeedSpinner("Read operation successfully executed", result);
|
|
28786
29065
|
} catch (error) {
|
|
28787
|
-
|
|
28788
|
-
throw error;
|
|
29066
|
+
this.failSpinner("Error during read operation", error);
|
|
28789
29067
|
}
|
|
28790
29068
|
}
|
|
28791
29069
|
async executeWrite(contractAddress, method, args) {
|
|
@@ -28801,22 +29079,31 @@ var CallAction = class {
|
|
|
28801
29079
|
retries: 15,
|
|
28802
29080
|
interval: 2e3
|
|
28803
29081
|
});
|
|
28804
|
-
|
|
28805
|
-
|
|
29082
|
+
this.log("Write transaction hash:", hash2);
|
|
29083
|
+
this.succeedSpinner("Write operation successfully executed", result);
|
|
28806
29084
|
} catch (error) {
|
|
28807
|
-
|
|
28808
|
-
throw error;
|
|
29085
|
+
this.failSpinner("Error during write operation", error);
|
|
28809
29086
|
}
|
|
28810
29087
|
}
|
|
28811
29088
|
};
|
|
28812
29089
|
|
|
28813
29090
|
// src/commands/contracts/index.ts
|
|
29091
|
+
function parseArg(value, previous = []) {
|
|
29092
|
+
if (value === "true") return [...previous, true];
|
|
29093
|
+
if (value === "false") return [...previous, false];
|
|
29094
|
+
if (!isNaN(Number(value))) return [...previous, Number(value)];
|
|
29095
|
+
return [...previous, value];
|
|
29096
|
+
}
|
|
28814
29097
|
function initializeContractsCommands(program2) {
|
|
28815
|
-
program2.command("deploy").description("Deploy intelligent contracts").option("--contract <contractPath>", "Path to the smart contract to deploy").option("--args <args...>", "Positional arguments for the contract (space-separated, use quotes for multi-word arguments)", []).action(async (options) => {
|
|
29098
|
+
program2.command("deploy").description("Deploy intelligent contracts").option("--contract <contractPath>", "Path to the smart contract to deploy").option("--args <args...>", "Positional arguments for the contract (space-separated, use quotes for multi-word arguments)", parseArg, []).action(async (options) => {
|
|
28816
29099
|
const deployer = new DeployAction();
|
|
28817
|
-
|
|
29100
|
+
if (options.contract) {
|
|
29101
|
+
await deployer.deploy(options);
|
|
29102
|
+
} else {
|
|
29103
|
+
await deployer.deployScripts();
|
|
29104
|
+
}
|
|
28818
29105
|
});
|
|
28819
|
-
program2.command("call <contractAddress> <method>").description("Call a contract method").option("--args <args...>", "Positional arguments for the method (space-separated, use quotes for multi-word arguments)", []).action(async (contractAddress, method, options) => {
|
|
29106
|
+
program2.command("call <contractAddress> <method>").description("Call a contract method").option("--args <args...>", "Positional arguments for the method (space-separated, use quotes for multi-word arguments)", parseArg, []).action(async (contractAddress, method, options) => {
|
|
28820
29107
|
const caller = new CallAction();
|
|
28821
29108
|
await caller.call({ contractAddress, method, ...options });
|
|
28822
29109
|
});
|
|
@@ -29134,6 +29421,44 @@ function initializeUpdateCommands(program2) {
|
|
|
29134
29421
|
return program2;
|
|
29135
29422
|
}
|
|
29136
29423
|
|
|
29424
|
+
// src/commands/scaffold/new.ts
|
|
29425
|
+
import fs10 from "fs-extra";
|
|
29426
|
+
import path5 from "path";
|
|
29427
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
29428
|
+
var NewAction = class extends BaseAction {
|
|
29429
|
+
constructor() {
|
|
29430
|
+
super();
|
|
29431
|
+
__publicField(this, "templatePath");
|
|
29432
|
+
const __filename = fileURLToPath3(import.meta.url);
|
|
29433
|
+
const basePath = path5.resolve(path5.dirname(__filename), "..");
|
|
29434
|
+
this.templatePath = path5.join(basePath, "templates", "default");
|
|
29435
|
+
}
|
|
29436
|
+
async createProject(projectName, options) {
|
|
29437
|
+
const targetPath = path5.resolve(options.path, projectName);
|
|
29438
|
+
if (fs10.existsSync(targetPath) && !options.overwrite) {
|
|
29439
|
+
return this.failSpinner(
|
|
29440
|
+
`Project directory "${targetPath}" already exists. Use --overwrite to replace it.`
|
|
29441
|
+
);
|
|
29442
|
+
}
|
|
29443
|
+
this.startSpinner(`Creating new GenLayer project: ${projectName}`);
|
|
29444
|
+
try {
|
|
29445
|
+
fs10.copySync(this.templatePath, targetPath);
|
|
29446
|
+
this.succeedSpinner(`Project "${projectName}" created successfully at ${targetPath}`);
|
|
29447
|
+
} catch (error) {
|
|
29448
|
+
this.failSpinner(`Error creating project "${projectName}"`, error);
|
|
29449
|
+
}
|
|
29450
|
+
}
|
|
29451
|
+
};
|
|
29452
|
+
|
|
29453
|
+
// src/commands/scaffold/index.ts
|
|
29454
|
+
function initializeScaffoldCommands(program2) {
|
|
29455
|
+
program2.command("new <projectName>").description("Create a new GenLayer project using the default template").option("--path <directory>", "Specify the directory for the new project", ".").option("--overwrite", "Overwrite existing directory if it exists", false).action(async (projectName, options) => {
|
|
29456
|
+
const newProjectAction = new NewAction();
|
|
29457
|
+
await newProjectAction.createProject(projectName, options);
|
|
29458
|
+
});
|
|
29459
|
+
return program2;
|
|
29460
|
+
}
|
|
29461
|
+
|
|
29137
29462
|
// src/index.ts
|
|
29138
29463
|
function initializeCLI() {
|
|
29139
29464
|
program.version(version).description(CLI_DESCRIPTION);
|
|
@@ -29143,6 +29468,7 @@ function initializeCLI() {
|
|
|
29143
29468
|
initializeConfigCommands(program);
|
|
29144
29469
|
initializeUpdateCommands(program);
|
|
29145
29470
|
initializeValidatorCommands(program);
|
|
29471
|
+
initializeScaffoldCommands(program);
|
|
29146
29472
|
program.parse(process.argv);
|
|
29147
29473
|
}
|
|
29148
29474
|
initializeCLI();
|