Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta #66

Merged
merged 34 commits into from
Dec 23, 2023
Merged

Beta #66

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d49a8e4
Added handling of the custom chains specified in the Hardhat config
KyrylR Dec 18, 2023
a978a56
Refactored the architecture and made it consistent.
KyrylR Dec 18, 2023
86dbdb0
Used spinner instead of console.log for network errors.
KyrylR Dec 18, 2023
1a594b3
Removed fixed TODO
KyrylR Dec 18, 2023
2110e37
Updated versions and CHANGELOG.md
KyrylR Dec 18, 2023
56b7c8a
Removed .only
KyrylR Dec 18, 2023
a374b49
Added `TransactionFieldsToSave` as a return value to the `sendNative`…
KyrylR Dec 19, 2023
98c21d0
Deleted auto generated files from tests
KyrylR Dec 19, 2023
b00b584
Migrated test fixture projects to TypeScript with updated configurati…
KyrylR Dec 19, 2023
c0ef81d
Created new fixture contracts for testing
KyrylR Dec 19, 2023
5c2b8be
Updated CHANGELOG.md
KyrylR Dec 19, 2023
7cbed08
Fixed a bug related to contract recovery when a custom name is used.
KyrylR Dec 21, 2023
fe4b240
Added .prettierignore
KyrylR Dec 21, 2023
d4f9759
Updated CHANGELOG.md
KyrylR Dec 21, 2023
6e296a4
Fixed bugs related to the recovery of contract names.
KyrylR Dec 21, 2023
245d75e
Updated packages versions
KyrylR Dec 21, 2023
59f099c
Revised the test infrastructure and architecture.
KyrylR Dec 21, 2023
7649e42
Removed Verifier from Migrator class
KyrylR Dec 21, 2023
9c72bc5
Removed redundant Hardhat Runtime Extensions
KyrylR Dec 21, 2023
2f5f452
Updated README.md
KyrylR Dec 21, 2023
0d168a4
Tested usage of the link function of the Truffle contract.
KyrylR Dec 21, 2023
03b71ec
Updated package-lock.json
KyrylR Dec 21, 2023
8a46ff0
Updated License and the Solidity compiler version
KyrylR Dec 22, 2023
b73fa22
Added comments for reset functions
KyrylR Dec 22, 2023
cb35598
Update README.md
KyrylR Dec 22, 2023
d873bb6
Updated README.md
KyrylR Dec 22, 2023
0d915f7
Update README.md
Arvolear Dec 22, 2023
35b8dcf
Update README.md
Arvolear Dec 22, 2023
39ac9c0
Update README.md
Arvolear Dec 22, 2023
9120786
Updated versions
KyrylR Dec 22, 2023
4e784f2
Updated README.md
KyrylR Dec 22, 2023
558137d
Updated README.md
KyrylR Dec 22, 2023
3787a1b
Update README.md
Arvolear Dec 22, 2023
2cbbb60
Update README.md
Arvolear Dec 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typechain-types
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## Version 2.0.0

* Removed redundant Hardhat Runtime Extensions.
* Removed Verifier from Migrator class.
* Revised the test infrastructure and architecture.
* Fixed bugs related to the recovery of contract names.
* Fixed a bug related to contract recovery when a custom name is used.
* Migrated test fixture projects to TypeScript, updating configurations and scripts.
Created new fixture contracts for testing and deleted auto-generated files.
* Added `TransactionFieldsToSave` as a return value to the `sendNative` function
* Added handling of the custom chains specified in the Hardhat config
* Refactored the architecture and made it consistent
* Used spinner instead of `console.log` for network errors

## Version 2.0.0-alpha.22

* Enforce the overwriting in ArtifactStorage in the case of bytecodeHash as a key
Expand Down
148 changes: 120 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

## What

This plugin helps you deploy and automatically verify the source code for your Solidity contracts on [Etherscan](https://etherscan.io)-based explorers and explorers compatible with its API like [Blockscout](https://www.blockscout.com/).
This plugin helps you deploy and verify the source code for your Solidity contracts through the specification of migrations. With sleek UX, the plugin enables users to:

This is a fairly simple and rather straightforward Hardhat plugin:

- For deployment, it uses [@ethers](https://www.npmjs.com/package/ethers).

- For verification, it uses [@nomicfoundation/hardhat-verify](https://www.npmjs.com/package/@nomicfoundation/hardhat-verify).
- Specify custom smart contracts deployment rules and configuration via [@ethers](https://www.npmjs.com/package/ethers).
- Relax from the source code verification hassle due to seamless integration with [@nomicfoundation/hardhat-verify](https://www.npmjs.com/package/@nomicfoundation/hardhat-verify).
- Enjoy full Typechain support for `Ethers-v6`, `Ethers-v5`, and `Truffle`.
- Leverage the "migration recovery mode" that automatically syncs up the deployment to the last failed transaction.
- Observe the real-time status of transactions being executed.
- Benefit from "reconnection spinner" if the network goes down during the deployment.
- Simplify the `libraries` usage via auto-linking mechanics.
- And much more.

## Installation

Expand All @@ -32,9 +35,8 @@ Or, if you are using TypeScript, add this to your `hardhat.config.ts`:
import "@solarity/hardhat-migrate";
```

> **Important**.

See [How it works](https://github.com/dl-solarity/hardhat-migrate#how-it-works) for further information.
> [!NOTE]
> See [How it works](https://github.com/dl-solarity/hardhat-migrate#how-it-works) for further information.

## Naming convention

Expand All @@ -50,7 +52,8 @@ It is also **mandatory** to specify the naming convention for migrations such as
- `migrate` task, which allows you to deploy and automatically verify contracts.
- `migrate:verify` task, which helps you verify already deployed contracts.

> :warning: **Hardhat Config**: Make sure they are follow the docs from `@nomicfoundation/hardhat-verify`.
> [!WARNING]
> **Hardhat Config**: Make sure they are follow the docs from `@nomicfoundation/hardhat-verify`.

Do not import `@solarity/hardhat-migrate` and `@nomicfoundation/hardhat-verify`, `@nomicfoundation/hardhat-ethers` together, the etherscan plugin is already included in the migrate plugin.

Expand All @@ -62,10 +65,7 @@ npx hardhat help migrate

## Environment extensions

This plugin extends the Hardhat Runtime Environment by adding the following fields:

- `deployer` - The deployer object that is used to deploy contracts.
- `verifier` - The verifier object that is used to verify contracts.
This plugin does not extend the Hardhat Runtime Environment.

## Usage

Expand Down Expand Up @@ -97,7 +97,7 @@ module.exports = {
- `only` : The number of the migration that will be applied. **Overrides from and to parameters.**
- `skip`: The number of migration to skip. **Overrides only parameter.**
- `wait` : The number of confirmations to wait for after the transaction is mined.
- `verify` : The flag indicating whether the contracts should be verified.
- `verify` : The flag indicating whether the contracts have to be verified after all migrations.
- `verifyParallel` : The size of the batch for verification.
- `verifyAttempts` : The number of attempts to verify the contract.
- `pathToMigrations` : The path to the folder with the specified migrations.
Expand All @@ -111,15 +111,17 @@ You can set your own migrations and deploy the contracts to the network you want

#### With only parameter

```console
```bash
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.
In this case, only the migration that begins with digit 2 will be applied.

The plugin will also attempt to automatically verify the deployed contracts after all migrations are complete.

#### Or with from/to parameters

```console
```bash
npx hardhat migrate --network sepolia --from 1 --to 2
```

Expand All @@ -136,25 +138,113 @@ 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.)
### Migration Sample

### Migration Lifecycle
Below is a sample migration file (1_simple.migration.ts):

```ts
import { Deployer, Reporter } from "@solarity/hardhat-migrate";

The migration files are sorted by the first digit in the file name and run one after the other in ascending order.
import { GovToken__factory } from "../typechain-types";

Parameters: `from`, `to`, `only` and `skip` affect the selection of the migration files.
const TOKEN_OWNER = "0x1E3953B6ee74461169A3E346060AE27bD0B5bF2B";

export = async (deployer: Deployer) => {
const govToken = await deployer.deploy(GovToken__factory, ["Token", "TKN"]);

const transferOwnershipTx = (await (await govToken.transferOwnership(TOKEN_OWNER)).wait())!;

await Reporter.reportTransactionByHash(
transferOwnershipTx.hash,
"Transfer Ownership of Governance Token to Token Owner",
);

Reporter.reportContracts([
`Governance Token ${await govToken.name()} (${await govToken.symbol()}) Address`,
await govToken.getAddress(),
]);
};
```

This example illustrates the basic principles of how migrations operate:

1. The core component is the `Deployer` object, which acts as a wrapper for the [@ethers](https://www.npmjs.com/package/ethers)
library, facilitating the deployment and processing of contracts.
2. The `Reporter` class, a static entity, logs intermediary information into the console.
3. It is required to import contract factories, or, in the case of Truffle, the necessary Truffle Contract Instance that need to be deployed.
4. All relevant constants can be defined if necessary.
5. The migration file's main body grants access to the deployer object, allowing for contract deployment and supporting
recovery from failures in previous migration runs.
6. Standard transaction-sending processes are used without special wrappers.
7. The migration concludes with the `Reporter` class summarizing the migration details.

### Migration Lifecycle

Migration files are executed in ascending order, sorted by the ordinal file number (the number in the file name).
Parameters such as `from`, `to`, `only`, and `skip` influence the selection of migration files.

### Deployer

Deployer contains the following functionality:
The Deployer offers several functionalities:

---

- **deploy(contractInstance, argsOrParameters, parameters)**:

Utilizes `ContractFactory` from [@ethers](https://www.npmjs.com/package/ethers) to deploy contracts, inferring types and providing enhanced functionalities like transaction recovery and reporting. It also stores deployment transaction data for later contract verification.

---

- **deployed(contractInstance, contractIdentifier)**:

- **deploy()**
Returns the deployed contract instance, inferring types and enhancing functionalities for comfortable interaction.

Under the hood, it uses `ContractFactory` from [@ethers](https://www.npmjs.com/package/ethers) to deploy the contracts.
---

- **deployed()**
- **sendNative(to, value, name <- optional)**:

Returns the deployed contract instance.
Facilitates sending native assets to a specified address, primarily for the recovery process.

---

- **getSigner(from <- optional)**:

Retrieves an ethers signer for use in migrations.

---

- **getChainId()**:

Identifies the current chain ID for the deployment.

### Reporter

The Reporter, a static class, provides functionalities like:

---

- **reportTransactionByHash(hash, name <- optional)**:

Retrieves and displays transaction receipts with standard formatting.

---

- **reportContracts(...contracts: [string, string][])**:

Displays a list of contract names and addresses in a table format.

---

The usage of these functionalities is demonstrated in the sample migration file above.

#### Truffle native functions

Most of the functions exposed by the Truffle contract, which directly impact or create the Truffle Contract Instance, are not supported.

The following function is supported:
- link

For a usage example, see the deployment scripts in the fixture project created to test how plugins work with Truffle.

### Transactions

Expand All @@ -164,7 +254,8 @@ This feature varies depending on the framework used.
#### Ethers.js Usage:

In Ethers.js, you can specify the transaction name using the `customData` field within the overrides.
A special field, `txName`, is dedicated for this purpose.
A special field, `txName`, is dedicated for this purpose.

Here’s an example of how to set a transaction name using Ethers.js:

```javascript
Expand Down Expand Up @@ -197,3 +288,4 @@ If verification fails, the `attempts` parameter indicates how many additional re

- 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.
- Adding, removing, moving or renaming new contracts to the hardhat project or reorganizing the directory structure of contracts after deployment may alter the resulting bytecode in some solc versions. See this [Solidity issue](https://github.com/ethereum/solidity/issues/9573) for further information.
- This plugin does not function properly with native Truffle methods, such as in `contract.deployed()`, unless otherwise specified above at the instance level. For example, instead of using `contract.deployed()`, it is necessary to use the `deployer.deploy()` method.
Loading