Skip to content

Commit ceb7645

Browse files
feat(sharing): Deploy DPS contract using Github action (#443)
Co-authored-by: GitHub Actions Bot <github-actions[bot]@users.noreply.github.com>
1 parent 50c6c98 commit ceb7645

File tree

7 files changed

+173
-51
lines changed

7 files changed

+173
-51
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Sharing Smart Contract - Deployment
2+
3+
on:
4+
workflow_dispatch: # Manual trigger
5+
inputs:
6+
network:
7+
description: 'Network'
8+
required: true
9+
type: choice
10+
options:
11+
- hardhat
12+
- avalancheFujiTestnet
13+
- arbitrumSepolia
14+
- bellecour
15+
default: 'hardhat'
16+
environment:
17+
description: 'Environment'
18+
required: true
19+
type: choice
20+
options:
21+
- testnets
22+
- mainnets
23+
default: 'testnets'
24+
25+
jobs:
26+
27+
# Validate deployment network and environment.
28+
validate:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
# On Github, the environment `mainnets` is restricted to
36+
# the main branch. Here we check that it's only used with
37+
# mainnet networks.
38+
- name: Validate mainnet deployment
39+
run: |
40+
if [[ "${{ inputs.environment }}" == "mainnets" && "${{ inputs.network }}" != "bellecour" ]]; then
41+
echo "::error::mainnets environment can only be used with mainnet networks."
42+
exit 1
43+
fi
44+
echo "Deploying to network '${{ inputs.network }}' with environment '${{ inputs.environment }}'."
45+
46+
# Build and test before deploying.
47+
ci:
48+
needs: validate
49+
uses: ./.github/workflows/sharing-smart-contracts-reusable.yml
50+
with:
51+
node-version: 18
52+
53+
# Deploy and verify contract.
54+
deploy:
55+
needs: ci
56+
runs-on: ubuntu-latest
57+
permissions:
58+
contents: write # Required to commit deployment files.
59+
environment: ${{ inputs.environment }}
60+
steps:
61+
- name: Set environment variables
62+
id: set-env
63+
run: |
64+
echo "PRIVATE_KEY=${{ secrets.PRIVATE_KEY }}" >> $GITHUB_ENV
65+
66+
if [ "${{ inputs.network }}" == "arbitrumSepolia" ]; then
67+
echo "POCO_ADDRESS=0x14B465079537655E1662F012e99EBa3863c8B9E0" >> $GITHUB_ENV
68+
echo "DATASET_REGISTRY_ADDRESS=0x3441A0C9FE488c51fcABa2bAAA048720f4D4F72D" >> $GITHUB_ENV
69+
echo "ARBISCAN_API_KEY=${{ secrets.ARBISCAN_API_KEY }}" >> $GITHUB_ENV
70+
fi
71+
72+
- uses: actions/checkout@v4
73+
with:
74+
fetch-depth: 0
75+
76+
- uses: actions/setup-node@v4
77+
with:
78+
node-version: 18
79+
80+
- name: Install dependencies
81+
working-directory: packages/sharing-smart-contract
82+
run: npm ci
83+
84+
- name: Install Foundry
85+
uses: foundry-rs/foundry-toolchain@v1
86+
with:
87+
version: stable
88+
cache: true
89+
90+
- name: Deploy contracts
91+
working-directory: packages/sharing-smart-contract
92+
run: npm run deploy -- --network ${{ inputs.network }}
93+
94+
- name: Save deployment artifacts
95+
if: inputs.network != 'hardhat'
96+
uses: stefanzweifel/git-auto-commit-action@v5
97+
with:
98+
commit_message: 'chore: save deployment artifacts for ${{ inputs.network }} (${{ inputs.environment }}, ${{ github.run_id }})'
99+
file_pattern: 'packages/sharing-smart-contract/ignition/deployments/* packages/sharing-smart-contract/.openzeppelin/*'
100+
commit_user_name: 'GitHub Actions Bot'
101+
commit_user_email: 'github-actions[bot]@users.noreply.github.com'
102+
commit_author: 'GitHub Actions Bot <github-actions[bot]@users.noreply.github.com>'
103+
104+
# TODO
105+
- name: Verify contracts
106+
working-directory: packages/sharing-smart-contract
107+
run: echo "Verify contracts" # npm run verify:ignition -- <deploymentId>

.github/workflows/sharing-smart-contracts-reusable.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build-and-test:
1414
runs-on: ubuntu-latest
1515
permissions:
16-
contents: write
16+
security-events: write # Required for SARIF upload.
1717

1818
steps:
1919
- uses: actions/checkout@v4
@@ -23,14 +23,10 @@ jobs:
2323
- uses: actions/setup-node@v4
2424
with:
2525
node-version: ${{ inputs.node-version }}
26-
# cache: 'npm' # Cache dependencies
2726

2827
- name: Install Dependencies
2928
working-directory: packages/sharing-smart-contract
30-
run: |
31-
node -v
32-
npm -v
33-
npm ci
29+
run: npm ci
3430

3531
- name: Install Foundry
3632
uses: foundry-rs/foundry-toolchain@v1

packages/sharing-smart-contract/.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ RPC_URL=
1515

1616
## Mnemonic for the network
1717
MNEMONIC=
18+
19+
ETHERSCAN_API_KEY=

packages/sharing-smart-contract/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Hardhat files
22
cache
33
artifacts
4+
!ignition/deployments/**/artifacts
45

56
# TypeChain files
67
typechain
Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,96 @@
11
# Sharing Smart Contracts
22

3-
Brief description of your project.
4-
5-
## Table of Contents
6-
7-
- [Installation](#installation)
8-
- [Scripts](#scripts)
9-
- [Compile](#compile)
10-
- [Verify](#verify)
11-
- [Deploy (Production)](#deploy-production)
12-
- [Deploy (Test)](#deploy-test)
13-
- [Run Tests](#run-tests)
14-
- [Generate UML Diagrams](#generate-uml-diagrams)
3+
Note: all of the following commands should be executed inside `packages/sharing-smart-contract`.
154

165
## Installation
176

18-
Describe the steps to install the project dependencies.
19-
207
```bash
218
npm ci
229
```
2310

24-
## Scripts
25-
26-
### Compile
11+
## Build
2712

2813
To clean and compile the project:
2914

3015
```bash
3116
npm run compile
3217
```
3318

34-
### Verify
19+
### Test
3520

36-
To verify the contracts:
21+
Start a local Hardhat node that, by default, forks Bellecour network:
3722

3823
```bash
39-
npm run verify
24+
npx hardhat node
4025
```
4126

42-
### Deployment
43-
44-
To deploy the contracts on a local hardhat network, run:
27+
Open a new terminal and run :
4528

4629
```bash
47-
npm run deploy # [-- --network <localhost>] if using an external local node.
30+
npm run test -- --network localhost
4831
```
4932

50-
To deploy the project on a live network, two options are available:
51-
1. Triggering the dedicated Github Action workflow (recommended).
52-
2. Or adding a private key locally and running:
33+
## Deployment
34+
35+
To deploy contracts, set up a private key in `.env` file and run:
36+
5337
```bash
5438
npm run deploy -- --network <name>
5539
```
5640

57-
#### Note:
58-
* Deployment on chains that support CreateX factory will deploy contracts
59-
using `create2` strategy.
60-
* Github Actions workflow should be used for production deployments.
41+
**Note**: Deployment on chains that support CreateX factory will deploy contracts using `create2` strategy.
42+
43+
### Mainnets deployment
6144

45+
Deploying on any mainnet must happen through the dedicated Github action.
46+
The action can be triggered from Github UI or using Github CLI:
6247

63-
### Run Tests
48+
```sh
49+
gh workflow run 'Sharing Smart Contract - Deployment' \
50+
-f environment=<name> \ # testnets | mainnets
51+
-f network=<name>
52+
# [ --ref <branch name> ]
53+
```
6454

65-
To deploy the project on the test network - localhost.
66-
You need first to start a local hardhat node which will be a fork of bellecour network :
55+
The output should be something like:
56+
57+
```
58+
✓ Created workflow_dispatch event for sharing-smart-contract-deploy.yml at feature/sharing-deployment-with-actions
59+
```
60+
61+
Then check the execution on [Github](https://github.com/iExecBlockchainComputing/dataprotector-sdk/actions/workflows/sharing-smart-contract-deploy.yml).
62+
63+
### Testnets deployments
64+
65+
It is **highly recommended** to use Github Actions to deploy on live testnets, especially for "final" versions that are going to be used by other services.
66+
67+
It is ok to deploy manually on testnets in dev mode. In that case use random create2 salts to not interfere with the configured salt.
68+
69+
### Verification
70+
71+
First, set up the target explorer API key in `.env` file.
72+
73+
1. To verify contracts that are deployed using Hardhat Ignition, run:
6774

6875
```bash
69-
npx hardhat node
76+
# Get deployment id using:
77+
npx hardhat ignition deployments
78+
79+
# Verify
80+
npm run verify:ignition -- <deploymentId> # e.g. chain-421614
7081
```
7182

72-
Open a new terminal and run :
83+
**Note**: contracts deployed using Github Actions are automatically verified.
84+
85+
2. To verify any contract, run
7386

7487
```bash
75-
npm run test
88+
npm run verify -- <address> --network <name>
7689
```
7790

78-
⚠️ Even if, the default network in the hardhat config is the local bellecour fork node. The tests will be run on a a simple snap hardhat node. That is why we need to specify the localhost network for the test which corresponds to the fork node of bellecour.
91+
## Docs and diagrams
7992

80-
### Generate UML Diagrams
93+
#### UML Diagrams
8194

8295
To generate UML diagrams for smart contracts (storage + class):
8396

@@ -93,14 +106,14 @@ To convert Solidity files to storage UML diagrams:
93106
npm run sol-to-uml
94107
```
95108

96-
#### Storage to Diagrams
109+
#### Storage to diagrams
97110

98111
To convert Solidity files to class UML diagrams:
99112

100113
```bash
101114
npm run storage-to-diagrams
102115
```
103116

104-
#### Issue
117+
#### Issues
105118

106119
Do not use a more recent version of hardhat than the current one (2.20.1). Cf issue : <https://github.com/NomicFoundation/hardhat/issues/4974>

packages/sharing-smart-contract/hardhat.config.cjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ module.exports = {
7272
// to verify smart-contract on Blockscout
7373
etherscan: {
7474
apiKey: {
75-
bellecour: 'abc',
75+
bellecour: 'nothing', // a non-empty string is needed by the plugin.
76+
avalancheFujiTestnet: 'nothing', // a non-empty string is needed by the plugin.
77+
arbitrumSepolia: process.env.ETHERSCAN_API_KEY || '',
7678
},
7779
customChains: [
7880
{
@@ -86,7 +88,7 @@ module.exports = {
8688
],
8789
},
8890
sourcify: {
89-
enabled: false,
91+
enabled: true,
9092
},
9193
// contract sizer
9294
contractSizer: {
@@ -109,7 +111,7 @@ module.exports = {
109111
ignition: {
110112
strategyConfig: {
111113
create2: {
112-
salt: "0x0000000000000000000000000000000000000000000000000000000000000000",
114+
salt: "0x5FD8F2C3DFCF36E174AC91A44AE6CAEBDDA012EFED601736E2C20A11A56CF537",
113115
},
114116
},
115117
},

packages/sharing-smart-contract/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"clean": "hardhat clean",
1010
"compile": "hardhat clean && hardhat compile && npm run artifact-to-abis",
11+
"verify:ignition": "hardhat ignition verify --include-unrelated-contracts",
1112
"verify": "hardhat verify",
1213
"deploy": "hardhat run scripts/deploy.js",
1314
"update-env": "hardhat run ./scripts/updateEnv.js",
@@ -57,4 +58,4 @@
5758
"iexec": "^8.15.0",
5859
"rimraf": "^6.0.1"
5960
}
60-
}
61+
}

0 commit comments

Comments
 (0)