hardhat-forta
Version:
Forta Agent Hardhat Plugin
126 lines • 5.19 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("hardhat/config");
const path_1 = __importDefault(require("path"));
const shelljs_1 = __importDefault(require("shelljs"));
const forta_cli_1 = require("./forta-cli");
const agents_1 = require("./forta-cli/agents");
const templates_1 = require("./templates");
require("./type-extensions");
const TASK_PREFIX = "forta";
(0, config_1.extendConfig)((config, userConfig) => {
var _a;
const contextPath = (_a = userConfig.forta) === null || _a === void 0 ? void 0 : _a.contextPath;
let normalizedPath;
if (!contextPath) {
normalizedPath = path_1.default.join(config.paths.root, "agents");
}
else {
if (path_1.default.isAbsolute(contextPath)) {
normalizedPath = contextPath;
}
else {
normalizedPath = path_1.default.normalize(path_1.default.join(config.paths.root, contextPath));
}
}
config.forta = {
contextPath: normalizedPath,
};
});
// Init Task
(0, config_1.task)(`${TASK_PREFIX}:init`)
.setDescription("Initialize a sample Forta Agent project")
.addFlag("typescript", "Initialize as Typescript project")
.addFlag("python", "Initialize as Python project")
.setAction(async (taskArgs, { config }) => {
await (0, forta_cli_1.executeFortaAgentCliCommand)("init", Object.assign({ contextPath: config.forta.contextPath }, taskArgs));
});
// Init Template Task
(0, config_1.task)(`${TASK_PREFIX}:init:template`)
.setDescription("Initialize a Forta Agent project from a template")
.setAction(async (_, { config }) => {
try {
await (0, templates_1.generateAgents)(config.forta.contextPath);
}
catch (err) {
console.error(`Error while initializing agent: ${err}`);
}
});
// Run Task
(0, config_1.task)(`${TASK_PREFIX}:run`)
.setDescription("Run a Forta Agent with blockchain data")
.addOptionalParam("tx", "Run with the specified transaction hash")
.addOptionalParam("block", "Run with the specified block hash/number")
.addOptionalParam("range", "Run with the specified block range (e.g. 15..20)")
.addOptionalParam("file", "Run with the specified json file")
.addFlag("prod", "Run a server listening for events from a Forta Scanner")
.addOptionalParam("configFile", "Specify a config file", "forta.config.json")
.addFlag("nocache", "Disables writing to the cache (but reads are still enabled)")
.setAction(async (taskArgs, { config }) => {
await (0, forta_cli_1.executeFortaAgentCliCommand)("run", {
contextPath: await (0, agents_1.chooseAgent)(config.forta.contextPath),
tx: taskArgs.tx,
block: taskArgs.block,
range: taskArgs.range,
file: taskArgs.file,
prod: taskArgs.prod,
config: taskArgs.configFile,
nocache: taskArgs.nocache,
});
});
// Test Task
(0, config_1.task)(`${TASK_PREFIX}:test`)
.setDescription("Run unit tests for a Forta Agent")
.setAction(async (_, { config }) => {
const contextPath = await (0, agents_1.chooseAgent)(config.forta.contextPath);
shelljs_1.default.cd(contextPath);
shelljs_1.default.exec("npm test");
});
// Publish Task
(0, config_1.task)(`${TASK_PREFIX}:publish`)
.setDescription("Publish a Forta Agent to the network")
.addOptionalParam("configFile", "Specify a config file", "forta.config.json")
.setAction(async (taskArgs, { config }) => {
await (0, forta_cli_1.executeFortaAgentCliCommand)("publish", {
contextPath: await (0, agents_1.chooseAgent)(config.forta.contextPath),
config: taskArgs.configFile,
});
});
// Push Task
(0, config_1.task)(`${TASK_PREFIX}:push`)
.setDescription("Push a Forta Agent image to the repository")
.addOptionalParam("configFile", "Specify a config file", "forta.config.json")
.setAction(async (taskArgs, { config }) => {
await (0, forta_cli_1.executeFortaAgentCliCommand)("push", {
contextPath: await (0, agents_1.chooseAgent)(config.forta.contextPath),
config: taskArgs.configFile,
});
});
// Disable Task
(0, config_1.task)(`${TASK_PREFIX}:disable`)
.setDescription("Disable a Forta Agent")
.setAction(async (_, { config }) => {
await (0, forta_cli_1.executeFortaAgentCliCommand)("disable", {
contextPath: await (0, agents_1.chooseAgent)(config.forta.contextPath),
});
});
// Enable Task
(0, config_1.task)(`${TASK_PREFIX}:enable`)
.setDescription("Enable a Forta Agent")
.setAction(async (_, { config }) => {
await (0, forta_cli_1.executeFortaAgentCliCommand)("enable", {
contextPath: await (0, agents_1.chooseAgent)(config.forta.contextPath),
});
});
// Keyfile Task
(0, config_1.task)(`${TASK_PREFIX}:keyfile`)
.setDescription("Print out keyfile information")
.setAction(async (_, { config }) => {
await (0, forta_cli_1.executeFortaAgentCliCommand)("keyfile", {
contextPath: config.forta.contextPath,
});
});
//# sourceMappingURL=index.js.map