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 22 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-beta.1

* 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
112 changes: 99 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,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 @@ -136,25 +133,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 Lifecycle
### Migration Sample

Below is a sample migration file:

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

import { GovToken__factory } from "../typechain-types";

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(),
]);
};
```

The migration files are sorted by the first digit in the file name and run one after the other in ascending order.
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. Define all relevant constants as 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.

Parameters: `from`, `to`, `only` and `skip` affect the selection of the migration files.
### Migration Lifecycle

Migration files are executed in ascending order, sorted by the first digit in the file name.
KyrylR marked this conversation as resolved.
Show resolved Hide resolved
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)**:

Returns the deployed contract instance, inferring types and enhancing functionalities for comfortable interaction.

---

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

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.

- **deploy()**
#### Truffle native functions

Under the hood, it uses `ContractFactory` from [@ethers](https://www.npmjs.com/package/ethers) to deploy the contracts.
Most of the functions exposed by the Truffle contract, which directly impact or create the Truffle Contract Instance, are not supported.

- **deployed()**
The following function is supported:
- link

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

### Transactions

Expand Down Expand Up @@ -197,3 +282,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. Instead, it is necessary to use the `deployer.deploy()` method.
Loading