Skip to content

Commit 0a16b82

Browse files
committed
Merge branch 'develop' into feature/poco-contracts-as-dependency
2 parents 6e806a4 + b3d33ee commit 0a16b82

File tree

10 files changed

+188
-126
lines changed

10 files changed

+188
-126
lines changed

.drone.yml

Lines changed: 27 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,52 @@
1-
# deploy DataProtector smart contract to prod, dev or staging
21
kind: pipeline
32
type: docker
4-
name: smart-contract deploy
3+
name: root checks
54

65
trigger:
76
event:
8-
- promote
9-
target:
10-
# deploy and verify the DataProtector contract with the dev deployer
11-
- smart-contract-deploy-dev
12-
# deploy and verify the DataProtector contract with the dev deployer and commit the staging environment update
13-
- smart-contract-deploy-staging
14-
# deploy and verify the DataProtector contract with the prod deployer and commit the prod environment update
15-
- smart-contract-deploy-prod
16-
branch:
17-
- develop
18-
- main
7+
- pull_request
198

209
steps:
21-
- name: install deps
22-
image: node:18.19
23-
pull: always
24-
commands:
25-
- cd packages/smart-contract
26-
- node -v
27-
- npm -v
28-
- npm ci
29-
30-
- name: check format
31-
image: node:18.19
32-
commands:
33-
- cd packages/smart-contract
34-
- npm run check-format
35-
36-
- name: check lint
37-
image: node:18.19
38-
commands:
39-
- cd packages/smart-contract
40-
- npm run lint
41-
42-
- name: compile smart contracts
43-
image: node:18.19
44-
commands:
45-
- cd packages/smart-contract
46-
- npm run compile
47-
48-
- name: test smart contracts
10+
- name: cat-drone-consider
4911
image: node:18.19
5012
commands:
51-
- cd packages/smart-contract
52-
- npm run test
53-
54-
- name: smart-contract dev/staging deployment
55-
image: node:18.19
56-
environment:
57-
WALLET_PRIVATE_KEY:
58-
from_secret: deployer-dev-privatekey
59-
commands:
60-
- cd packages/smart-contract
61-
- npm run deploy -- --network bellecour
62-
when:
63-
target:
64-
- smart-contract-deploy-staging
65-
- smart-contract-deploy-dev
66-
branch:
67-
- develop
13+
- cat .drone-consider
6814

69-
- name: smart-contract prod deployment
15+
- name: check-sdk-abi
7016
image: node:18.19
71-
environment:
72-
WALLET_PRIVATE_KEY:
73-
from_secret: deployer-prod-privatekey
7417
commands:
75-
- cd packages/smart-contract
76-
- npm run deploy -- --network bellecour --verify
77-
when:
78-
target:
79-
- smart-contract-deploy-prod
80-
branch:
81-
- main
18+
- cd packages/sdk
19+
- npm run refresh-abis
20+
- |
21+
if [ -n "$(git diff --name-only)" ]; then
22+
echo "ABIs not up-to-date in packages/sdk, need to run 'npm run refresh-abis'"
23+
exit 1
24+
fi
8225
83-
- name: update prod env
26+
- name: check-subgraph-abi
8427
image: node:18.19
85-
environment:
86-
ENV: prod
8728
commands:
88-
- cd environments
29+
- cd packages/subgraph
30+
- npm run refresh-abis
8931
- |
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
94-
- git add environments.json
95-
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
96-
when:
97-
target:
98-
- smart-contract-deploy-prod
32+
if [ -n "$(git diff --name-only)" ]; then
33+
echo "ABIs not up-to-date in packages/subgraph, need to run 'npm run refresh-abis'"
34+
exit 1
35+
fi
9936
100-
- name: update staging env
37+
- name: check-dapp-abi
10138
image: node:18.19
102-
environment:
103-
ENV: staging
10439
commands:
105-
- cd environments
40+
- cd packages/protected-data-delivery-dapp/deployment
41+
- npm run refresh-abis
10642
- |
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
111-
- git add environments.json
112-
- git commit -m "$DRONE_DEPLOY_TO deployment $DRONE_BUILD_NUMBER $DRONE_COMMIT" --author="drone-product <[email protected]>"
113-
when:
114-
target:
115-
- smart-contract-deploy-staging
116-
117-
- name: git-push
118-
image: appleboy/drone-git-push
119-
settings:
120-
remote: ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git
121-
branch: update-env-${DRONE_BUILD_NUMBER}
122-
ssh_key:
123-
from_secret: ssh-key-team-product-github-push
124-
when:
125-
target:
126-
- smart-contract-deploy-prod
127-
- smart-contract-deploy-staging
43+
if [ -n "$(git diff --name-only)" ]; then
44+
echo "ABIs not up-to-date in protected-data-delivery-dapp/abis, need to run 'npm run refresh-abis'"
45+
exit 1
46+
fi
12847
12948
---
49+
13050
# deploy sharing smart contract to prod, staging or dev
13151
kind: pipeline
13252
type: docker
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Smart Contract Deploy
2+
3+
on:
4+
workflow_dispatch: # Manually trigger the workflow OR trigger with tags or releases ?
5+
inputs:
6+
target:
7+
description: "Deployment target (smart-contract-deploy-dev, smart-contract-deploy-staging, smart-contract-deploy-prod)"
8+
required: true
9+
type: choice
10+
options:
11+
- smart-contract-deploy-dev
12+
- smart-contract-deploy-staging
13+
- smart-contract-deploy-prod
14+
default: smart-contract-deploy-dev
15+
16+
jobs:
17+
deploy:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: '18'
25+
26+
- name: Install dependencies
27+
working-directory: packages/smart-contract
28+
run: |
29+
node -v
30+
npm -v
31+
npm ci
32+
33+
- name: Check code format
34+
working-directory: packages/smart-contract
35+
run: npm run check-format
36+
37+
- name: Run lint
38+
working-directory: packages/smart-contract
39+
run: npm run lint
40+
41+
- name: Compile smart contracts
42+
working-directory: packages/smart-contract
43+
run: npm run compile
44+
45+
- name: Run tests
46+
working-directory: packages/smart-contract
47+
run: npm run test
48+
49+
- name: Deploy to dev/staging
50+
if: ${{ (github.event.inputs.target == 'smart-contract-deploy-dev' || github.event.inputs.target == 'smart-contract-deploy-staging') && startsWith(github.ref, 'refs/heads/develop') }}
51+
working-directory: packages/smart-contract
52+
env:
53+
WALLET_PRIVATE_KEY: ${{ secrets.DEPLOYER_DEV_PRIVATEKEY }}
54+
run: npm run deploy -- --network bellecour
55+
56+
- name: Deploy to prod
57+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' && github.ref == 'refs/heads/main' }}
58+
working-directory: packages/smart-contract
59+
env:
60+
WALLET_PRIVATE_KEY: ${{ secrets.DEPLOYER_PROD_PRIVATEKEY }}
61+
run: npm run deploy -- --network bellecour
62+
63+
- name: Update production environment
64+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' }}
65+
working-directory: environments
66+
run: |
67+
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
68+
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.jsonl)
69+
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
70+
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
71+
git add environments.json
72+
git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>"
73+
74+
- name: Update staging environment
75+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-staging' }}
76+
working-directory: environments
77+
run: |
78+
ADDRESS=$(jq -r '.contractAddress' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
79+
BLOCK=$(jq -r '.blockNumber' ../packages/smart-contract/ignition/deployments/chain-134/journal.json)
80+
KEY=dataprotectorContractAddress VALUE=$ADDRESS npm run update-env
81+
KEY=dataprotectorStartBlock VALUE=$BLOCK npm run update-env
82+
git add environments.json
83+
git commit -m "Deployment ${{ github.event.inputs.target }} run ${{ github.run_number }} commit ${{ github.sha }}" --author="drone-product <[email protected]>"
84+
85+
- name: Git push environment update
86+
if: ${{ github.event.inputs.target == 'smart-contract-deploy-prod' || github.event.inputs.target == 'smart-contract-deploy-staging' }}
87+
run: |
88+
git push ssh://[email protected]/iExecBlockchainComputing/dataprotector-sdk.git update-env-${{ github.run_number }}
89+
env:
90+
# Configure the SSH key to secrets GitHub
91+
SSH_KEY: ${{ secrets.SSH_KEY_TEAM_PRODUCT_GITHUB_PUSH }}
92+
shell: bash
93+
94+
- name: Verify contract
95+
working-directory: packages/smart-contract
96+
run: npm run verify -- --network bellecour $(cat deployments/DataProtector/address) $(cat deployments/DataProtector/args)
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# wallet used for transactions
22
WALLET_PRIVATE_KEY=...
33

4-
# environment to use for configuration (prod/staging)
4+
# environment to use for configuration (prod/staging). The default is prod.
55
ENV=...
66

77
# IExec PoCo contract address override (deploy script only)
88
POCO_ADDRESS=...
99

1010
# DatasetRegistry contract address override (deploy script only)
1111
DATASET_REGISTRY_ADDRESS=...
12+
13+
## RPC URL for the network
14+
RPC_URL=
15+
16+
## Mnemonic for the network
17+
MNEMONIC=
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'dotenv/config.js';
2+
import { z } from 'zod';
3+
4+
const addressRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
5+
const privateKeyRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
6+
7+
const envSchema = z.object({
8+
// Private key of the wallet used for transactions
9+
WALLET_PRIVATE_KEY: z
10+
.string()
11+
.regex(privateKeyRegex, 'Invalid private key format')
12+
.optional()
13+
.or(z.literal('')),
14+
15+
// environment to use for configuration (prod/staging)
16+
ENV: z.enum(['prod', 'staging'], 'ENV must be either "prod" or "staging"').default('prod'),
17+
18+
// Address of the PoCo contract
19+
POCO_ADDRESS: z
20+
.string()
21+
.regex(addressRegex, 'Invalid Ethereum address format')
22+
.optional()
23+
.or(z.literal('')),
24+
25+
// Address of the DatasetRegistry
26+
DATASET_REGISTRY_ADDRESS: z
27+
.string()
28+
.regex(addressRegex, 'Invalid Ethereum address format')
29+
.optional()
30+
.or(z.literal('')),
31+
32+
// URL of the RPC used for network connection
33+
RPC_URL: z.string().url('RPC_URL must be a valid URL').optional().or(z.literal('')),
34+
35+
// Mnemonic for deployment or network interaction
36+
MNEMONIC: z.string().min(1, 'MNEMONIC cannot be empty').optional().or(z.literal('')),
37+
});
38+
39+
export const env = envSchema.parse(process.env);

packages/sharing-smart-contract/scripts/deploy.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
DATASET_REGISTRY_ADDRESS as defaultDatasetRegistryAddress,
55
POCO_ADDRESS as defaultPocoAddress,
66
} from '../config/config.js';
7+
import { env } from '../config/env.js';
78
import { saveDeployment } from '../utils/utils.js';
89

910
const { ethers, upgrades } = hre;
@@ -13,13 +14,11 @@ async function main() {
1314
const [deployer] = await ethers.getSigners();
1415
console.log('Deploying contracts with the account:', deployer.address);
1516

16-
const {
17-
POCO_ADDRESS = defaultPocoAddress,
18-
DATASET_REGISTRY_ADDRESS = defaultDatasetRegistryAddress,
19-
} = process.env;
17+
const pocoAddress = env.POCO_ADDRESS || defaultPocoAddress;
18+
const datasetRegistryAddress = env.DATASET_REGISTRY_ADDRESS || defaultDatasetRegistryAddress;
2019

21-
console.log(`Using poco at ${POCO_ADDRESS}`);
22-
console.log(`Using dataset registry at ${DATASET_REGISTRY_ADDRESS}`);
20+
console.log(`Using poco at ${pocoAddress}`);
21+
console.log(`Using dataset registry at ${datasetRegistryAddress}`);
2322

2423
const AddOnlyAppWhitelistRegistryFactory = await ethers.getContractFactory(
2524
'AddOnlyAppWhitelistRegistry',
@@ -47,8 +46,8 @@ async function main() {
4746
const DataProtectorSharingFactory = await ethers.getContractFactory('DataProtectorSharing');
4847

4948
const dataProtectorSharingConstructorArgs = [
50-
DATASET_REGISTRY_ADDRESS,
51-
POCO_ADDRESS,
49+
datasetRegistryAddress,
50+
pocoAddress,
5251
addOnlyAppWhitelistRegistryAddress,
5352
];
5453
const dataProtectorSharingContract = await upgrades.deployProxy(DataProtectorSharingFactory, {

packages/sharing-smart-contract/scripts/fillCollection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* eslint-disable no-await-in-loop */
44
import { getEnvironment } from '@iexec/dataprotector-environments';
55
import pkg from 'hardhat';
6+
import { env } from '../config/env.js';
67
import { createAppFor } from './singleFunction/app.js';
78
import { createDatasetFor } from './singleFunction/dataset.js';
89
import { createWorkerpool, createWorkerpoolOrder } from './singleFunction/workerpool.js';
@@ -13,7 +14,7 @@ const { ethers } = pkg;
1314
const rpcURL = pkg.network.config.url;
1415

1516
async function main() {
16-
const { ENV } = process.env;
17+
const { ENV } = env;
1718
console.log(`using ENV: ${ENV}`);
1819
const { dataprotectorSharingContractAddress } = getEnvironment(ENV);
1920

packages/sharing-smart-contract/scripts/updateEnv.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-console */
22
import { getEnvironment } from '@iexec/dataprotector-environments';
33
import pkg from 'hardhat';
4-
4+
import { env } from '../config/env.js';
55
const { ethers } = pkg;
66

77
async function main() {
8-
const { ENV } = process.env;
8+
const { ENV } = env;
99
console.log(`using ENV: ${ENV}`);
1010
const { dataprotectorSharingContractAddress, resultProxyUrl } = getEnvironment(ENV);
1111

packages/sharing-smart-contract/scripts/upgrade-local-fork.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import { getEnvironment } from '@iexec/dataprotector-environments';
33
import hre from 'hardhat';
44
import { DATASET_REGISTRY_ADDRESS, POCO_ADDRESS } from '../config/config.js';
5+
import { env } from '../config/env.js';
56
import { impersonate, stopImpersonate } from './singleFunction/utils.js';
6-
77
const { ethers, upgrades } = hre;
88

99
async function main() {
10-
const { ENV } = process.env;
10+
const { ENV } = env;
1111
console.log(`using ENV: ${ENV}`);
1212

1313
const rpcUrl = hre.network.config.url;

0 commit comments

Comments
 (0)