Skip to content

Commit

Permalink
Add ability to accept Overrides as second parameter (#55)
Browse files Browse the repository at this point in the history
* Added ability to accept Overrides as second parameter

* Updated versions and CHANGELOG.md

* Updated README

* Updated naming

* refactor

---------

Co-authored-by: Artem Chystiakov <[email protected]>
  • Loading branch information
KyrylR and Arvolear authored Nov 2, 2023
1 parent aaa4adf commit 51da17b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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.

<!-- The user can also define which verification errors are irrelevant and have to be ignored using the `skipVerificationErrors` parameter. By default, the `already verified` error is omitted. -->

## 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.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/deployer/Deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ export class Deployer {

public async deploy<T, A = T, I = any>(
contract: Instance<A, I> | (T extends Truffle.Contract<I> ? T : never),
args: TypedArgs<A> = [] as TypedArgs<A>,
argsOrParameters: OverridesAndLibs | TypedArgs<A> = [] as TypedArgs<A>,
parameters: OverridesAndLibs = {},
): Promise<I> {
const adapter = this._resolveAdapter(contract);

const minimalContract = await adapter.fromInstance(contract, parameters);

const contractAddress = await minimalContract.deploy(args, parameters);
if (!Array.isArray(argsOrParameters)) {
parameters = argsOrParameters;
argsOrParameters = [] as TypedArgs<A>;
}

const contractAddress = await minimalContract.deploy(argsOrParameters as TypedArgs<A>, parameters);

return adapter.toInstance(contract, contractAddress, parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

0 comments on commit 51da17b

Please sign in to comment.