Skip to content

Commit bbb739c

Browse files
Le-Caigneczguesmi
andauthored
Feature/prepare deployment for avalanche and arbitrum (#429)
Co-authored-by: Zied Guesmi <[email protected]>
1 parent 53067c1 commit bbb739c

File tree

14 files changed

+113
-91
lines changed

14 files changed

+113
-91
lines changed

.drone.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ steps:
7373
from_secret: deployer-prod-privatekey
7474
commands:
7575
- cd packages/smart-contract
76-
- npm run deploy -- --network bellecour
76+
- npm run deploy -- --network bellecour --verify
7777
when:
7878
target:
7979
- smart-contract-deploy-prod
@@ -86,8 +86,11 @@ steps:
8686
ENV: prod
8787
commands:
8888
- cd environments
89-
- KEY=dataprotectorContractAddress VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/address) npm run update-env
90-
- KEY=dataprotectorStartBlock VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/block) npm run update-env
89+
- |
90+
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
91+
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
92+
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
93+
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
9194
- git add environments.json
9295
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
9396
when:
@@ -100,8 +103,11 @@ steps:
100103
ENV: staging
101104
commands:
102105
- cd environments
103-
- KEY=dataprotectorContractAddress VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/address) npm run update-env
104-
- KEY=dataprotectorStartBlock VALUE=$(cat ../packages/smart-contract/deployments/DataProtector/block) npm run update-env
106+
- |
107+
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
108+
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
109+
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
110+
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
105111
- git add environments.json
106112
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
107113
when:
@@ -120,12 +126,6 @@ steps:
120126
- smart-contract-deploy-prod
121127
- smart-contract-deploy-staging
122128

123-
- name: verify contract
124-
image: node:18.19
125-
commands:
126-
- cd packages/smart-contract
127-
- npm run verify -- --network bellecour $(cat deployments/DataProtector/address) $(cat deployments/DataProtector/args)
128-
129129
---
130130
# deploy sharing smart contract to prod, staging or dev
131131
kind: pipeline

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ node_modules
1414
.env
1515
*.log
1616
*.env
17-
18-
**/deployments

packages/smart-contract/.env.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ RPC_URL=
99

1010
## Mnemonic for the network
1111
MNEMONIC=
12+
13+
## Arbiscan API key to verify contracts
14+
ARBISCAN_API_KEY=

packages/smart-contract/.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
n# Hardhat files
1+
# Hardhat files
22
cache
33
artifacts
44

@@ -10,6 +10,5 @@ typechain-types
1010
coverage
1111
coverage.json
1212

13-
#smart contract
14-
.smart-contract-address
15-
.constructor-args-params
13+
# Deployment files
14+
**/deployments/chain-31337

packages/smart-contract/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
## Next
66

7+
### Added
8+
9+
- Support for Arbitrum and Avalanche Fuji testnets (#429).
10+
11+
### Changed
12+
13+
- Integrated Hardhat Ignition for CREATE2 deployment using the CreateX factory for new chain deployments (#429).
14+
715
### Changed
816

917
- update blockscout url

packages/smart-contract/README.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
1-
#Contract Name: DataProtector
1+
# Contract Name: DataProtector
22

3-
####Description:
4-
This contract is use to attach schema on the dataset and publish it as an event.
3+
## Description
54

6-
#####Contract deployed Address:
5+
The `DataProtector` contract is designed to attach schemas to datasets and publish them as events.
76

8-
```bash
9-
0x3a4Ab33F3D605e75b6D00A32A0Fa55C3628F6A59
7+
## Deploying the Contract
8+
9+
To deploy the contract, run the following command:
10+
11+
```sh
12+
npm run deploy -- --network avalancheFuji
13+
```
14+
15+
If no network is specified, the local Hardhat network will be used by default.
16+
17+
**Note:** This deployment uses the `createX` factory through Hardhat Ignition. To modify the deployment address, update the `salt` value in the `hardhat.config.json` file.
18+
19+
## Verifying the Contract
20+
21+
To verify the contract during deployment, include the `--verify` option in the deployment command:
22+
23+
```sh
24+
npm run deploy -- --network avalancheFuji --verify
25+
```
26+
27+
If the contract has already been deployed, you can verify it separately using the following command:
28+
29+
```sh
30+
npx hardhat ignition verify chain-43113
1031
```
32+
33+
This ensures the contract's source code is verified on the blockchain explorer for the specified network.
34+
35+
## Deployed Contract Address
36+
37+
Refer to the `../../environments/environments.json` file to find the deployed contract address for the respective environment.

packages/smart-contract/config/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const envSchema = z.object({
2424

2525
// Mnemonic de déploiement ou interaction réseau
2626
MNEMONIC: z.string().min(1, 'MNEMONIC cannot be empty').optional().or(z.literal('')),
27+
28+
// Arbiscan API key
29+
ARBISCAN_API_KEY: z.string().optional().or(z.literal('')),
2730
});
2831

2932
export const env = envSchema.parse(process.env);

packages/smart-contract/hardhat.config.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ import { env } from './config/env';
44

55
const privateKey = env.WALLET_PRIVATE_KEY;
66

7+
// Avalanche Fuji specific configuration
8+
const fujiBaseConfig = {
9+
blockGasLimit: 8_000_000,
10+
chainId: 43113,
11+
};
12+
13+
// Arbitrum Sepolia specific configuration
14+
const arbitrumSepoliaBaseConfig = {
15+
blockGasLimit: 30_000_000, // Arbitrum has higher block gas limits
16+
chainId: 421614,
17+
};
18+
719
const config: HardhatUserConfig = {
820
networks: {
921
hardhat: {
@@ -18,6 +30,18 @@ const config: HardhatUserConfig = {
1830
gasPrice: 0,
1931
accounts: privateKey ? [privateKey] : [],
2032
},
33+
// Add Fuji as a network
34+
avalancheFuji: {
35+
url: env.RPC_URL || 'https://api.avax-test.network/ext/bc/C/rpc',
36+
accounts: privateKey ? [privateKey] : [],
37+
...fujiBaseConfig,
38+
},
39+
// Add Arbitrum Sepolia as a network
40+
arbitrumSepolia: {
41+
url: env.RPC_URL || 'https://sepolia-rollup.arbitrum.io/rpc',
42+
accounts: privateKey ? [privateKey] : [],
43+
...arbitrumSepoliaBaseConfig,
44+
},
2145
// poco-chain native config
2246
'dev-native': {
2347
chainId: 65535,
@@ -31,7 +55,9 @@ const config: HardhatUserConfig = {
3155
//to verify contract on Blockscout
3256
etherscan: {
3357
apiKey: {
34-
bellecour: 'abc',
58+
bellecour: 'nothing', // a non-empty string is needed by the plugin.
59+
avalancheFuji: 'nothing', // a non-empty string is needed by the plugin.
60+
arbitrumSepolia: env.ARBISCAN_API_KEY || '',
3561
},
3662
customChains: [
3763
{
@@ -44,9 +70,17 @@ const config: HardhatUserConfig = {
4470
},
4571
],
4672
},
73+
// Create2 deployments: it use crateX factory to deploy the contract
74+
ignition: {
75+
strategyConfig: {
76+
create2: {
77+
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
78+
},
79+
},
80+
},
4781
//compiler version
4882
solidity: {
49-
version: '0.8.19',
83+
version: '0.8.29',
5084
settings: {
5185
optimizer: {
5286
enabled: true,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
2+
import { DATASET_REGISTRY_ADDRESS as defaultDatasetRegistryAddress } from '../../config/config';
3+
import { env } from '../../config/env';
4+
5+
export default buildModule('DataProtectorModule', (m) => {
6+
// Get registry address from environment or default
7+
const datasetRegistryAddress = env.DATASET_REGISTRY_ADDRESS || defaultDatasetRegistryAddress;
8+
9+
// Deploy DataProtector with the registry address as constructor argument
10+
const dataProtector = m.contract('DataProtector', [datasetRegistryAddress]);
11+
12+
// Return the deployed contract
13+
return { dataProtector };
14+
});

packages/smart-contract/package-lock.json

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)