Skip to content

Commit

Permalink
Add privateKey param to deploy-zksync:libraries task
Browse files Browse the repository at this point in the history
  • Loading branch information
Mimi TxFusion committed Aug 30, 2023
1 parent 0efd264 commit 93bab56
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/hardhat-zksync-deploy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { TASK_DEPLOY_ZKSYNC, TASK_DEPLOY_ZKSYNC_LIBRARIES } from './task-names';
import './type-extensions';
import { zkSyncDeploy, zkSyncLibraryDeploy } from './task-actions';
import { int } from 'hardhat/internal/core/params/argumentTypes';
import { int, string } from 'hardhat/internal/core/params/argumentTypes';

export * from './deployer';

Expand All @@ -17,6 +17,7 @@ task(TASK_DEPLOY_ZKSYNC, 'Runs the deploy scripts for zkSync network')
.setAction(zkSyncDeploy);

task(TASK_DEPLOY_ZKSYNC_LIBRARIES, 'Runs the library deploy for zkSync network')
.addOptionalParam('privateKey', 'Private key of the account that will deploy the libraries', undefined, string)
.addOptionalParam('accountNumber', 'Network account index', 0, int)
.addOptionalParam('externalConfigObjectPath', 'Config file imported in hardhat config file that represent HardhatUserConfig type variable', undefined)
.addFlag('noAutoPopulateConfig', 'Flag to disable auto population of config file')
Expand Down
33 changes: 21 additions & 12 deletions packages/hardhat-zksync-deploy/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ async function runScript(hre: HardhatRuntimeEnvironment, script: string) {
await deployFn(hre);
}

export async function deployLibraries(hre: HardhatRuntimeEnvironment,
export async function deployLibraries(
hre: HardhatRuntimeEnvironment,
privateKey: string,
accountNumber: number,
externalConfigObjectPath: string,
noAutoPopulateConfig: boolean,
compileAllContracts: boolean) {

const wallet = getWallet(hre, accountNumber);
compileAllContracts: boolean
) {
const wallet = getWallet(hre, privateKey, accountNumber);
const deployer = new Deployer(hre, wallet);

const libraryInfos = getLibraryInfos(hre);
Expand All @@ -107,11 +109,13 @@ export async function deployLibraries(hre: HardhatRuntimeEnvironment,
}
}

async function deployLibrary(hre: HardhatRuntimeEnvironment,
async function deployLibrary(
hre: HardhatRuntimeEnvironment,
deployer: Deployer,
missingLibrary: MissingLibrary,
missingLibraries: MissingLibrary[],
allDeployedLibraries: ContractInfo[]): Promise<ContractInfo> {
allDeployedLibraries: ContractInfo[]
): Promise<ContractInfo> {
const deployedLibrary = allDeployedLibraries
.find(deployedLibrary => generateFullQuailfiedNameString(missingLibrary)
.includes(generateFullQuailfiedNameString(deployedLibrary.contractFQN))
Expand Down Expand Up @@ -162,27 +166,32 @@ function findDependentLibraries(dependentLibraries: string[], missingLibraries:
});
}

async function deployOneLibrary(deployer: Deployer,
async function deployOneLibrary(
deployer: Deployer,
contractFQN: ContractFullQualifiedName,
allDeployedLibraries: ContractInfo[]): Promise<ContractInfo> {
allDeployedLibraries: ContractInfo[]
): Promise<ContractInfo> {
const artifact = await deployer.loadArtifact(generateFullQuailfiedNameString(contractFQN));

console.info(chalk.yellow(`Deploying ${contractFQN.contractName} .....`));
console.info(chalk.yellow(`Deploying ${generateFullQuailfiedNameString(contractFQN)} .....`));
const contract = await deployer.deploy(artifact, []);
console.info(chalk.green(`Deployed ${contractFQN.contractName} at ${contract.address}`));
console.info(chalk.green(`Deployed ${generateFullQuailfiedNameString(contractFQN)} at ${contract.address}`));

const contractInfo = {
contractFQN,
address: contract.address
};

allDeployedLibraries.push(contractInfo);
return contractInfo;
}

async function compileAndDeploy(hre: HardhatRuntimeEnvironment,
async function compileAndDeploy(
hre: HardhatRuntimeEnvironment,
deployer: Deployer,
contractFQN: ContractFullQualifiedName,
allDeployedLibraries: ContractInfo[]): Promise<ContractInfo> {
allDeployedLibraries: ContractInfo[]
): Promise<ContractInfo> {
await compileContracts(hre, [contractFQN.contractPath]);

return await deployOneLibrary(deployer, contractFQN, allDeployedLibraries);
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-zksync-deploy/src/task-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export async function zkSyncDeploy(taskArgs: TaskArguments, hre: HardhatRuntimeE
}

export async function zkSyncLibraryDeploy(taskArgs: TaskArguments, hre: HardhatRuntimeEnvironment) {
await deployLibraries(hre, taskArgs.accountNumber, taskArgs.externalConfigObjectPath, taskArgs.noAutoPopulateConfig, taskArgs.compileAllContracts);
await deployLibraries(hre, taskArgs.privateKey, taskArgs.accountNumber, taskArgs.externalConfigObjectPath, taskArgs.noAutoPopulateConfig, taskArgs.compileAllContracts);
}
6 changes: 5 additions & 1 deletion packages/hardhat-zksync-deploy/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export async function compileContracts(hre: HardhatRuntimeEnvironment, contracts
await hre.run('compile', { force: true });
}

export function getWallet(hre: HardhatRuntimeEnvironment, accountNumber: number) {
export function getWallet(hre: HardhatRuntimeEnvironment, privateKey: string, accountNumber: number) {
if (privateKey) {
return new Wallet(privateKey);
}

const accounts = hre.network.config.accounts;

if(!accounts) {
Expand Down
3 changes: 2 additions & 1 deletion packages/hardhat-zksync-solc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"chalk": "4.1.2",
"dockerode": "^3.3.4",
"fs-extra": "^11.1.1",
"semver": "^7.5.1"
"semver": "^7.5.1",
"proper-lockfile": "^4.1.2"
},
"devDependencies": {
"@types/chai": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-zksync-solc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ subtask(
const zksolcConfig: ZkSolcConfig = (global as any).hre.config.zksolc;

if (zksolcConfig.settings.areLibrariesMissing) {
console.info(chalk.blue(MISSING_LIBRARIES_NOTICE));
console.info(chalk.yellow(MISSING_LIBRARIES_NOTICE));
console.info(chalk.red(COMPILE_AND_DEPLOY_LIBRARIES_INSTRUCTIONS));
} else {
let count = 0;
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@
chalk "4.1.2"
dockerode "^3.3.4"
fs-extra "^11.1.1"
proper-lockfile "^4.1.2"
semver "^7.5.1"

"@matterlabs/hardhat-zksync-upgradable@link:packages/hardhat-zksync-upgradable":
Expand Down

0 comments on commit 93bab56

Please sign in to comment.