hardhat-gasless-deployer
Version:
Hardhat Plugin for deploying contracts using GSN
56 lines • 2.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-explicit-any */
require("@nomicfoundation/hardhat-ethers");
const config_1 = require("hardhat/config");
const plugins_1 = require("hardhat/plugins");
const config_2 = require("./config");
const constants_1 = require("./constants");
const deployer_1 = require("./deployer");
const networks_1 = require("./networks");
require("./type-extensions");
const utils_1 = require("./utils");
(0, config_1.extendConfig)(config_2.hHGaslessDeployerConfigExtender);
(0, config_1.task)("gaslessDeploy", "Deploy contract using GSN").setAction(async (_, hre) => {
// verify network
await hre.run(constants_1.VERIFY_NETWORK_SUB_TASK);
// TODO: add extra config verification here
// compile contracts
await hre.run(constants_1.COMPILE);
// load contract ABI
let contract;
if (hre.config.hHGaslessDeployer.contract) {
contract = await hre.ethers.getContractFactory(hre.config.hHGaslessDeployer.contract);
}
else {
throw new plugins_1.NomicLabsHardhatPluginError(constants_1.PLUGIN_NAME, `Contract doesn't exist!`);
}
// get initcode
const initcode = !hre.config.hHGaslessDeployer
.initArgsPath
? await contract.getDeployTransaction()
: await (0, utils_1.loadInitCode)(hre, contract, hre.config.hHGaslessDeployer.initArgsPath);
const [deployer] = await hre.ethers.getSigners();
// This factory needs to be deployed only once along
// with the paymaster in order to execute gasless
// deployments for future contracts.
const factory = new deployer_1.Deployer(hre, deployer);
await factory.deployAndInitFactoryAndPaymaster(hre);
const salt = hre.config.hHGaslessDeployer.salt
? hre.config.hHGaslessDeployer.salt
: (0, utils_1.randomSalt)();
// deploy target contract
const target = await factory.deployTargetContract(hre, salt, initcode);
console.log(`Target contract "${hre.config.hHGaslessDeployer.contract}" has been deployed @ ${JSON.stringify(target.contractAddress)}`);
});
(0, config_1.subtask)(constants_1.VERIFY_NETWORK_SUB_TASK).setAction(async (_, hre) => {
var _a, _b;
const network = (_b = (_a = hre === null || hre === void 0 ? void 0 : hre.config) === null || _a === void 0 ? void 0 : _a.hHGaslessDeployer) === null || _b === void 0 ? void 0 : _b.network;
if (network != undefined) {
if (!networks_1.networks.includes(network)) {
throw new plugins_1.NomicLabsHardhatPluginError(constants_1.PLUGIN_NAME, `${network} is not supported. The currently supported networks are
${networks_1.networks}.`);
}
}
});
//# sourceMappingURL=index.js.map