Skip to content

Commit

Permalink
Feat/output logging (#33)
Browse files Browse the repository at this point in the history
* add simple logger plugin & update readme
  • Loading branch information
killroy192 authored Mar 26, 2024
1 parent 1a3b375 commit 029849c
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 554 deletions.
73 changes: 43 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# hardhat-sol-bundler

Build, update and redeploy smart contracts with hardhat with one config.
Hardhat plugin for declarative smart contract deployments and redeployments.

## Features

Expand All @@ -14,20 +14,27 @@ Build, update and redeploy smart contracts with hardhat with one config.

run `npm install --save-dev @dgma/hardhat-sol-bundler`

in addition, the next peer dependencies should be installed:

- "ethers": "^6.11.1",
- "hardhat": "^2.22.2"
- "@nomicfoundation/hardhat-ethers" // no need if you use @nomicfoundation/hardhat-toolbox

## Usage

1. Create deployment config in hardhat.config for the specific network:

```ts
import { type HardhatUserConfig } from "hardhat/config";
// no need @nomicfoundation/hardhat-ethers if you use @nomicfoundation/hardhat-toolbox
import "@nomicfoundation/hardhat-ethers";
import { dynamicAddress } from "@dgma/hardhat-sol-bundler";
import { Logging } from "@dgma/hardhat-sol-bundler/plugins/Logging";

const config: HardhatUserConfig = {
networks: {
hardhat: {
deployment: {
plugins: [Logging], // will log the deployment result
config: {
TestLibrary: {},
TestContractOne: {
Expand All @@ -39,15 +46,6 @@ const config: HardhatUserConfig = {
},
},
},
TestContractTwo: {
contractName: "TestContract",
args: ["hello two"],
options: {
libs: {
TestLibrary: dynamicAddress("TestLibrary"),
},
},
},
},
},
},
Expand All @@ -57,9 +55,9 @@ const config: HardhatUserConfig = {
export default config;
```

`contractName` property is optional and only needed if configuration contract key is not the same as contract name
`contractName` property is optional and only needed if the configuration contract key is not the same as the contract name

**note**: dependant contract must be located above
**note**: the dependant contract must be located above

2. Run task:

Expand All @@ -73,42 +71,57 @@ npx hardhat deploy-bundle --no-compile true

## Configuration

- To deploy only modified contracts, add `lockFile` property to deployment:
To keep deployment results and deploy only modified contracts, add the `lockFile` property to deployment:

```ts
const deployment = {
config.deployment = {
lockFile: "deployment-lock.json",
config: {
// contracts..
},
};
```

- To deploy contract as a proxy:
To deploy contracts as a proxy:

```ts
import { SupportedProxies } from "@dgma/hardhat-sol-bundler";

const deployment = {
config.deployment = {
lockFile: "deployment-lock.json",
config: {
TestContract: {
proxy: {
type: SupportedProxies.CUSTOM
}
}
type: SupportedProxies.CUSTOM,
},
},
},
};
```

## Plugins

Simple deployment result logging:

```ts
import { Logging } from "@dgma/hardhat-sol-bundler/plugins/Logging";

config.deployment = {
plugins: [Logging],
config: {
// contracts..
},
};
```

- To verify deployed contracts during runtime:
Verify deployed contracts:

```ts
// no need @nomicfoundation/hardhat-verify if you use @nomicfoundation/hardhat-toolbox
import "@nomicfoundation/hardhat-verify";
import { VerifyPlugin } from "@dgma/hardhat-sol-bundler/plugins/Verify";

const deployment = {
config.deployment = {
plugins: [VerifyPlugin],
// set a config level verification
verify: true,
Expand All @@ -125,25 +138,25 @@ const deployment = {

## Hooks

The library can be easily extended with custom plugins by adding them to `deployment.plugins` list. A simple example of the plugin can be found in `plugins/Verify.ts`.
The library can be easily extended with custom plugins by adding them to `deployment.plugins` list. A simple example of the plugins can be found in `plugins/*`.

During deployment, sol-bundler can execute additional logic implemented as lifecycle hooks:

```
BEFORE_CONTEXT_INITIALIZATION - fires once, before deployment runtime context creation;
BEFORE_DEPLOYMENT - fires once, after deployment runtime context creation and before deployment logic initiation;
BEFORE_DEPENDENCY_RESOLUTION - fires for each contract in config, before resolving dynamically contract dependencies (arguments and libraries);
BEFORE_DEPENDENCY_RESOLUTION - fires for each contract in the config, before resolving dynamically contract dependencies (arguments and libraries);
BEFORE_CONTRACT_BUILD - fires for each contract in config, before creating contract factory;
AFTER_CONTRACT_BUILD - fires for each contract in config, after creating contract factory;
BEFORE_CONTRACT_BUILD - fires for each contract in the config, before creating contract factory;
AFTER_CONTRACT_BUILD - fires for each contract in the config, after creating contract factory;
BEFORE_CONTRACT_DEPLOY - fires for each contract in config, before contract deployment;
AFTER_DEPLOYMENT - fires for each contract in config, after contract deployment;
BEFORE_CONTRACT_DEPLOY - fires for each contract in the config, before contract deployment;
AFTER_CONTRACT_DEPLOY - fires for each contract in the config, after contract deployment;
AFTER_CONTEXT_SERIALIZATION: "AFTER_CONTEXT_SERIALIZATION" - fires for each contract in config, after deployment runtime context serialization (preparation for storing output into lock file);
AFTER_CONTEXT_SERIALIZATION: "AFTER_CONTEXT_SERIALIZATION" - fires for each contract in the config, after deployment runtime context serialization (preparation for storing output into lock file);
AFTER_CONTRACT_DEPLOY - fires once, after all contracts deployment;
AFTER_DEPLOYMENT - fires once, after all contracts deployment;
```

## Deployment output
Expand Down
22 changes: 11 additions & 11 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,46 @@ const config: HardhatUserConfig = {
deployment: {
plugins: [VerifyPlugin],
config: {
TestLibrary: {},
TestTransparentUpgradable: {
LenLibrary: {},
MockTransparentUpgradable: {
proxy: {
type: SupportedProxies.TRANSPARENT,
unsafeAllow: ["external-library-linking"],
},
args: ["hello"],
options: {
libs: {
TestLibrary: dynamicAddress("TestLibrary"),
LenLibrary: dynamicAddress("LenLibrary"),
},
},
},
testUUPSUpgradable: {
MockUUPSUpgradable: {
proxy: {
type: SupportedProxies.UUPS,
unsafeAllow: ["external-library-linking"],
},
args: ["hello"],
options: {
libs: {
TestLibrary: dynamicAddress("TestLibrary"),
LenLibrary: dynamicAddress("LenLibrary"),
},
},
},
TestContractFirst: {
contractName: "TestContract",
MockContractFirst: {
contractName: "MockContract",
args: ["hello", parseEther("0.1")],
options: {
libs: {
TestLibrary: dynamicAddress("TestLibrary"),
LenLibrary: dynamicAddress("LenLibrary"),
},
},
},
TestContractSecond: {
contractName: "TestContract",
MockContractSecond: {
contractName: "MockContract",
args: ["hello", parseEther("0.2")],
options: {
libs: {
TestLibrary: dynamicAddress("TestLibrary"),
LenLibrary: dynamicAddress("LenLibrary"),
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions integration/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ describe("main", () => {
it("should deploy contracts based on config file", async () => {
const { ctx, deployedContracts } = await solBundler(hre);
expect(deployedContracts).to.eql([
"TestLibrary",
"TestTransparentUpgradable",
"testUUPSUpgradable",
"TestContractFirst",
"TestContractSecond",
"LenLibrary",
"MockTransparentUpgradable",
"MockUUPSUpgradable",
"MockContractFirst",
"MockContractSecond",
]);
expect(Object.keys(ctx)).to.eql(deployedContracts);
});
Expand Down
Loading

0 comments on commit 029849c

Please sign in to comment.