From 15170f83b2a1bd68c35ccd1a7069549f93ded62b Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Thu, 2 Nov 2023 18:48:48 +0200 Subject: [PATCH 1/5] Added ability to accept Overrides as second parameter --- src/deployer/Deployer.ts | 11 +++++++++-- .../hardhat-project-minimal-ethers/deploy/1_deploy.ts | 8 ++++---- .../deploy/1_deploy.ts | 9 +++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/deployer/Deployer.ts b/src/deployer/Deployer.ts index ce93cd18..a39ca194 100644 --- a/src/deployer/Deployer.ts +++ b/src/deployer/Deployer.ts @@ -27,14 +27,21 @@ export class Deployer { public async deploy( contract: Instance | (T extends Truffle.Contract ? T : never), - args: TypedArgs = [] as TypedArgs, + args: TypedArgs | OverridesAndLibs = {}, parameters: OverridesAndLibs = {}, ): Promise { const adapter = this._resolveAdapter(contract); const minimalContract = await adapter.fromInstance(contract, parameters); - const contractAddress = await minimalContract.deploy(args, parameters); + let contractAddress: string; + if (args instanceof Array) { + contractAddress = await minimalContract.deploy(args, parameters); + } else if (args instanceof Object) { + contractAddress = await minimalContract.deploy([], args); + } else { + contractAddress = await minimalContract.deploy([], {}); + } return adapter.toInstance(contract, contractAddress, parameters); } diff --git a/test/fixture-projects/hardhat-project-minimal-ethers/deploy/1_deploy.ts b/test/fixture-projects/hardhat-project-minimal-ethers/deploy/1_deploy.ts index 98f02a3a..a17e5426 100644 --- a/test/fixture-projects/hardhat-project-minimal-ethers/deploy/1_deploy.ts +++ b/test/fixture-projects/hardhat-project-minimal-ethers/deploy/1_deploy.ts @@ -4,9 +4,9 @@ import { Deployer } from "../../../../src/deployer/Deployer"; export = async (deployer: Deployer) => { const ContractWithConstructorArguments = await getContractFactory("ContractWithConstructorArguments"); - // let contract = await deployer.deploy(ContractWithConstructorArguments, ["hello"], { - // gasLimit: 1000000, - // }); + let contract = await deployer.deploy(ContractWithConstructorArguments, ["hello"], { + gasLimit: 1000000, + }); - // await contract.name(); + await contract.name(); }; diff --git a/test/fixture-projects/hardhat-project-minimal-typechain-truffle/deploy/1_deploy.ts b/test/fixture-projects/hardhat-project-minimal-typechain-truffle/deploy/1_deploy.ts index 9d81b879..f0aca40c 100644 --- a/test/fixture-projects/hardhat-project-minimal-typechain-truffle/deploy/1_deploy.ts +++ b/test/fixture-projects/hardhat-project-minimal-typechain-truffle/deploy/1_deploy.ts @@ -3,8 +3,9 @@ import { Deployer } from "../../../../src/deployer/Deployer"; const ContractWithConstructorArguments = artifacts.require("ContractWithConstructorArguments"); export = async (deployer: Deployer) => { - // let contract = await deployer.deploy(ContractWithConstructorArguments, ["hello"], { - // gasLimit: 1000000, - // }); - // await contract.name(); + let contract = await deployer.deploy(ContractWithConstructorArguments, ["hello"], { + gasLimit: 1000000, + }); + + await contract.name(); }; From 3723ccd0cf59941951523c1200559982278d3f06 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Thu, 2 Nov 2023 18:49:47 +0200 Subject: [PATCH 2/5] Updated versions and CHANGELOG.md --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46f905dc..40c103b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 2.0.0-alpha.12 + +* Added ability to accept Overrides as second parameter to the `deploy` function. + ## Version 2.0.0-alpha.11 * Initially, the fully qualified name is used to retrieve a contract from the Transaction Storage. diff --git a/package.json b/package.json index 8471734d..28b48897 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/hardhat-migrate", - "version": "2.0.0-alpha.11", + "version": "2.0.0-alpha.12", "description": "Automatic deployment and verification of smart contracts", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", From ef06788458c84a00cc85bf90c85d08a10fd4dcd2 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Thu, 2 Nov 2023 18:56:10 +0200 Subject: [PATCH 3/5] Updated README --- README.md | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c3dc0cd3..e962b724 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ You can set your own migrations and deploy the contracts to the network you want #### With only parameter ```console -npx hardhat migrate --network goerli --verify --only 2 +npx hardhat migrate --network sepolia --verify --only 2 ``` In this case, only the migration that begins with digit 2 will be applied. The plugin will also try to automatically verify the deployed contracts. @@ -127,13 +127,7 @@ In this case, migrations 1 through 2 (both) will be applied without the automati > _This plugin has a `migrate:verify` task, to learn how to use it, see the example project._ -#### You can manually verify contracts - -```console -npx hardhat verify --network goerli DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1" -``` - -Other examples of manual contract verification can be found here [@nomicfoundation/hardhat-verify](https://www.npmjs.com/package/@nomicfoundation/hardhat-verify) --> +--> ## How it works @@ -146,7 +140,7 @@ The plugin includes the following packages to perform the deployment and verific The core of this plugin is migration files, you can specify the migration route that suits you best. -You can find an example of migration files in the sample project. +[//]: # (You can find an example of migration files in the sample project.) ### Migration Lifecycle @@ -166,21 +160,12 @@ Under the hood, it uses `ContractFactory` from [@ethers](https://www.npmjs.com/p Returns the deployed contract instance. -- **Link function** - -Used for backward compatibility with Truffle migrations. - -The link function of the `TruffleContract` class from the [@nomiclabs/hardhat-truffle5](https://www.npmjs.com/package/@nomiclabs/hardhat-truffle5) -package is used to link external libraries to a contract. - ### Verifier For a list of parameters that affect the verification process, see [Parameter Explanation](https://github.com/dl-solarity/hardhat-migrate#parameter-explanation). If verification fails, the `attempts` parameter indicates how many additional requests will be made before the migration process is terminated. - - ## Known limitations - This plugin, as well as the [Hardhat Toolbox](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-toolbox) plugin, use the [@nomicfoundation/hardhat-verify](https://www.npmjs.com/package/@nomicfoundation/hardhat-verify) plugin internally, so both of these plugins cannot be imported at the same time. A quick fix is to manually import the needed plugins that ToolBox imports. From c0901192816b3877710a25572c51294ea2fe0ce8 Mon Sep 17 00:00:00 2001 From: Kyryl R Date: Thu, 2 Nov 2023 18:57:19 +0200 Subject: [PATCH 4/5] Updated naming --- src/deployer/Deployer.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/deployer/Deployer.ts b/src/deployer/Deployer.ts index a39ca194..a4327f8e 100644 --- a/src/deployer/Deployer.ts +++ b/src/deployer/Deployer.ts @@ -27,7 +27,7 @@ export class Deployer { public async deploy( contract: Instance | (T extends Truffle.Contract ? T : never), - args: TypedArgs | OverridesAndLibs = {}, + argsOrParameters: TypedArgs | OverridesAndLibs = {}, parameters: OverridesAndLibs = {}, ): Promise { const adapter = this._resolveAdapter(contract); @@ -35,10 +35,10 @@ export class Deployer { const minimalContract = await adapter.fromInstance(contract, parameters); let contractAddress: string; - if (args instanceof Array) { - contractAddress = await minimalContract.deploy(args, parameters); - } else if (args instanceof Object) { - contractAddress = await minimalContract.deploy([], args); + if (argsOrParameters instanceof Array) { + contractAddress = await minimalContract.deploy(argsOrParameters, parameters); + } else if (argsOrParameters instanceof Object) { + contractAddress = await minimalContract.deploy([], argsOrParameters); } else { contractAddress = await minimalContract.deploy([], {}); } From a70802dcb795847c1547a12e77edbf6d665db947 Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Thu, 2 Nov 2023 19:31:00 +0200 Subject: [PATCH 5/5] refactor --- package-lock.json | 4 ++-- src/deployer/Deployer.ts | 15 ++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6d3274fb..d4e1c872 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@solarity/hardhat-migrate", - "version": "2.0.0-alpha.6", + "version": "2.0.0-alpha.12", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@solarity/hardhat-migrate", - "version": "2.0.0-alpha.6", + "version": "2.0.0-alpha.12", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/src/deployer/Deployer.ts b/src/deployer/Deployer.ts index a4327f8e..8eaa00ba 100644 --- a/src/deployer/Deployer.ts +++ b/src/deployer/Deployer.ts @@ -27,22 +27,19 @@ export class Deployer { public async deploy( contract: Instance | (T extends Truffle.Contract ? T : never), - argsOrParameters: TypedArgs | OverridesAndLibs = {}, + argsOrParameters: OverridesAndLibs | TypedArgs = [] as TypedArgs, parameters: OverridesAndLibs = {}, ): Promise { const adapter = this._resolveAdapter(contract); - const minimalContract = await adapter.fromInstance(contract, parameters); - let contractAddress: string; - if (argsOrParameters instanceof Array) { - contractAddress = await minimalContract.deploy(argsOrParameters, parameters); - } else if (argsOrParameters instanceof Object) { - contractAddress = await minimalContract.deploy([], argsOrParameters); - } else { - contractAddress = await minimalContract.deploy([], {}); + if (!Array.isArray(argsOrParameters)) { + parameters = argsOrParameters; + argsOrParameters = [] as TypedArgs; } + const contractAddress = await minimalContract.deploy(argsOrParameters as TypedArgs, parameters); + return adapter.toInstance(contract, contractAddress, parameters); }