Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
56ca934
Remove result proxy address from sharing contract
zguesmi May 6, 2025
e1de79b
Add cleanup todos
zguesmi May 6, 2025
6696d42
Update changelog
zguesmi May 6, 2025
ca5bd50
Update abis
zguesmi May 6, 2025
a11ae61
Merge branch 'develop' into feature/deprecated-result-proxy-config
zguesmi May 6, 2025
08a92dd
Add upgrade unit test
zguesmi May 6, 2025
519e9c0
Format
zguesmi May 6, 2025
32028df
Fix linting error
zguesmi May 6, 2025
2813cc8
Clean
zguesmi May 6, 2025
826b1cd
Clean
zguesmi May 6, 2025
c501af8
Include review
zguesmi May 6, 2025
8dac743
Add PR number to changelog
zguesmi May 6, 2025
0c2f2e7
Fix tests on the CI
zguesmi May 6, 2025
32fd0e5
Run tests on hardhat network (forked)
zguesmi May 6, 2025
ad9ff43
Fix CI
zguesmi May 12, 2025
25ebadb
Debug CI
zguesmi May 12, 2025
14c94f1
Debug CI
zguesmi May 12, 2025
62f0d1e
Debug CI
zguesmi May 12, 2025
25f7d1f
Remove debugging flags
zguesmi May 12, 2025
74e1c91
Clean
zguesmi May 12, 2025
65e07fe
Debug upgrade tests on CI
zguesmi May 12, 2025
7afc0af
Debug upgrade tests on CI
zguesmi May 12, 2025
ae4f26e
Remove upgrade tests as it interferes with local-fork script
zguesmi May 12, 2025
e330b35
Revert naming changes
zguesmi May 12, 2025
af797bd
Run tests on hardhat fork
zguesmi May 12, 2025
2760952
Debug upgrade tests on CI
zguesmi May 12, 2025
c2e94d6
Merge branch 'develop' into feature/hardhat-ignition
zguesmi May 13, 2025
df06547
Install HH dep compiler
zguesmi May 13, 2025
64e5c1e
Compile transparent proxy to create artifact
zguesmi May 13, 2025
64822c9
Create ESM and Commonjs flavor of config and env files
zguesmi May 13, 2025
d9f50e3
Add ignition module to deploy contracts
zguesmi May 13, 2025
eaace5c
Remove old deployment file
zguesmi May 13, 2025
35307ba
Update README
zguesmi May 13, 2025
e7393c7
Add create2 strategy to ignition config
zguesmi May 13, 2025
c47f370
Add new chains config
zguesmi May 13, 2025
6c64506
Clean
zguesmi May 13, 2025
d7f31d6
Fix deployment
zguesmi May 14, 2025
5513328
Clean
zguesmi May 14, 2025
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
2 changes: 1 addition & 1 deletion packages/sharing-smart-contract/.env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# wallet used for transactions
WALLET_PRIVATE_KEY=...
PRIVATE_KEY=...

# environment to use for configuration (prod/staging). The default is prod.
ENV=...
Expand Down
25 changes: 11 additions & 14 deletions packages/sharing-smart-contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,26 @@ To verify the contracts:
npm run verify
```

### Deploy (Production)
### Deployment

To deploy the project on the production network - bellecour.
⚠️ Be sure before deploying on bellecour
To deploy the contracts on a local hardhat network, run:

```bash
npm run script:prod
npm run deploy # [-- --network <localhost>] if using an external local node.
```

### Deploy (Test)

To deploy the project on the test network - localhost.
You need first to start a local hardhat node which will be a fork of bellecour network :

To deploy the project on a live network, two options are available:
1. Triggering the dedicated Github Action workflow (recommended).
2. Or adding a private key locally and running:
```bash
npx hardhat node
npm run deploy -- --network <name>
```

Open a new terminal and run :
#### Note:
* Deployment on chains that support CreateX factory will deploy contracts
using `create2` strategy.
* Github Actions workflow should be used for production deployments.

```bash
npm run script:test
```

### Run Tests

Expand Down
8 changes: 8 additions & 0 deletions packages/sharing-smart-contract/config/config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Hardhat Ignition does not support ESM modules, so we use CommonJS syntax.
// TODO refactor this to use ESM syntax when Hardhat Ignition supports it.

module.exports = {
POCO_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f',
DATASET_REGISTRY_ADDRESS: '0x799DAa22654128d0C64d5b79eac9283008158730',
APP_REGISTRY_ADDRESS: '0xB1C52075b276f87b1834919167312221d50c9D16',
};
9 changes: 5 additions & 4 deletions packages/sharing-smart-contract/config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const SMART_CONTRACT_ADDRESS_FILE = '.smart-contract-address';
export const POCO_ADDRESS = '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f';
export const DATASET_REGISTRY_ADDRESS = '0x799DAa22654128d0C64d5b79eac9283008158730';
export const APP_REGISTRY_ADDRESS = '0xB1C52075b276f87b1834919167312221d50c9D16';
import config from './config.cjs';

export const POCO_ADDRESS = config.POCO_ADDRESS;
export const DATASET_REGISTRY_ADDRESS = config.DATASET_REGISTRY_ADDRESS;
export const APP_REGISTRY_ADDRESS = config.APP_REGISTRY_ADDRESS;
51 changes: 51 additions & 0 deletions packages/sharing-smart-contract/config/env.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Hardhat Ignition does not support ESM modules, so we use CommonJS syntax.
// TODO refactor this to use ESM syntax when Hardhat Ignition supports it.

require('dotenv/config.js');
const { z } = require('zod');

const addressRegex = /(^|\b)(0x)?[0-9a-fA-F]{40}(\b|$)/;
const privateKeyRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;

const envSchema = z.object({
// Private key of the wallet used for transactions
PRIVATE_KEY: z
.string()
.regex(privateKeyRegex, 'Invalid private key format')
.optional()
.or(z.literal('')),

// environment to use for configuration (prod/staging)
ENV: z.enum(['prod', 'staging'], 'ENV must be either "prod" or "staging"').default('prod'),

// Address of the PoCo contract
POCO_ADDRESS: z
.string()
.regex(addressRegex, 'Invalid Ethereum address format')
.optional()
.or(z.literal('')),

// Address of the DatasetRegistry
DATASET_REGISTRY_ADDRESS: z
.string()
.regex(addressRegex, 'Invalid Ethereum address format')
.optional()
.or(z.literal('')),

// URL of the RPC used for network connection
RPC_URL: z.string().url('RPC_URL must be a valid URL').optional().or(z.literal('')),

// Mnemonic for deployment or network interaction
MNEMONIC: z.string().min(1, 'MNEMONIC cannot be empty').optional().or(z.literal('')),

FUJI_RPC_URL: z.string().url('FUJI_RPC_URL must be a valid URL').optional(),

ARBITRUM_SEPOLIA_RPC_URL: z
.string()
.url('ARBITRUM_SEPOLIA_RPC_URL must be a valid URL')
.optional(),
});

module.exports = {
env: envSchema.parse(process.env),
};
40 changes: 2 additions & 38 deletions packages/sharing-smart-contract/config/env.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
import 'dotenv/config.js';
import { z } from 'zod';
import _env from './env.cjs';

const addressRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
const privateKeyRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;

const envSchema = z.object({
// Private key of the wallet used for transactions
WALLET_PRIVATE_KEY: z
.string()
.regex(privateKeyRegex, 'Invalid private key format')
.optional()
.or(z.literal('')),

// environment to use for configuration (prod/staging)
ENV: z.enum(['prod', 'staging'], 'ENV must be either "prod" or "staging"').default('prod'),

// Address of the PoCo contract
POCO_ADDRESS: z
.string()
.regex(addressRegex, 'Invalid Ethereum address format')
.optional()
.or(z.literal('')),

// Address of the DatasetRegistry
DATASET_REGISTRY_ADDRESS: z
.string()
.regex(addressRegex, 'Invalid Ethereum address format')
.optional()
.or(z.literal('')),

// URL of the RPC used for network connection
RPC_URL: z.string().url('RPC_URL must be a valid URL').optional().or(z.literal('')),

// Mnemonic for deployment or network interaction
MNEMONIC: z.string().min(1, 'MNEMONIC cannot be empty').optional().or(z.literal('')),
});

export const env = envSchema.parse(process.env);
export const env = _env.env;
41 changes: 36 additions & 5 deletions packages/sharing-smart-contract/hardhat.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ require('@nomicfoundation/hardhat-toolbox');
require('@openzeppelin/hardhat-upgrades');
require('hardhat-contract-sizer');
require('@openzeppelin/hardhat-upgrades');
require('dotenv').config();
require('hardhat-dependency-compiler');
const env = require('./config/env.cjs');

const { WALLET_PRIVATE_KEY } = process.env;
// TODO format

const bellecourBase = {
gasPrice: 0,
Expand Down Expand Up @@ -34,14 +35,32 @@ module.exports = {
bellecour: {
...bellecourBase,
url: 'https://bellecour.iex.ec',
accounts: WALLET_PRIVATE_KEY ? [WALLET_PRIVATE_KEY] : [],
accounts: env.PRIVATE_KEY ? [env.PRIVATE_KEY] : [],
},
avalancheFujiTestnet: {
chainId: 43113,
url: env.FUJI_RPC_URL || 'https://api.avax-test.network/ext/bc/C/rpc',
accounts: [
env.PRIVATE_KEY ||
'0x0000000000000000000000000000000000000000000000000000000000000000',
],
blockGasLimit: 8_000_000,
},
arbitrumSepolia: {
chainId: 421614,
url: env.ARBITRUM_SEPOLIA_RPC_URL || 'https://sepolia-rollup.arbitrum.io/rpc',
accounts: [
process.env.PRIVATE_KEY ||
'0x0000000000000000000000000000000000000000000000000000000000000000',
],
blockGasLimit: 30_000_000,
},
// poco-chain native config
'dev-native': {
chainId: 65535,
url: process.env.RPC_URL ?? 'http://localhost:8545',
url: env.RPC_URL ?? 'http://localhost:8545',
accounts: {
mnemonic: process.env.MNEMONIC ?? '',
mnemonic: env.MNEMONIC ?? '',
},
gasPrice: 0,
},
Expand Down Expand Up @@ -87,4 +106,16 @@ module.exports = {
},
},
},
ignition: {
strategyConfig: {
create2: {
salt: "0x0000000000000000000000000000000000000000000000000000000000000000",
},
},
},
dependencyCompiler: {
paths: [
'@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol',
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { buildModule } = require('@nomicfoundation/hardhat-ignition/modules');

const {
DATASET_REGISTRY_ADDRESS: defaultDatasetRegistryAddress,
POCO_ADDRESS: defaultPocoAddress,
} = require('../../config/config.cjs');
const { env } = require('../../config/env.cjs');

// Hardhat Ignition does not support ESM yet.

// @ts-ignore
module.exports = buildModule('DataProtectorSharingModule', (m) => {
const proxyAdminOwner = m.getAccount(0);
const pocoAddress = env.POCO_ADDRESS || defaultPocoAddress;
const datasetRegistryAddress = env.DATASET_REGISTRY_ADDRESS || defaultDatasetRegistryAddress;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can keep the logs ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignition modules do not support console.log, actions are automatically logged by Hardhat, cf logs in the PR description.

// Whitelist
const addOnlyAppWhitelistRegistryImpl = m.contract('AddOnlyAppWhitelistRegistry', [], {
id: 'AddOnlyAppWhitelistRegistryImpl',
});
const addOnlyAppWhitelistRegistryProxy = m.contract(
'TransparentUpgradeableProxy',
[
addOnlyAppWhitelistRegistryImpl,
proxyAdminOwner,
'0x', // No initialization data.
],
{
id: 'AddOnlyAppWhitelistRegistryProxy',
},
);
const addOnlyAppWhitelistRegistry = m.contractAt(
'AddOnlyAppWhitelistRegistry',
addOnlyAppWhitelistRegistryProxy,
);

// DPS
const dataProtectorSharingImpl = m.contract(
'DataProtectorSharing',
[pocoAddress, datasetRegistryAddress, addOnlyAppWhitelistRegistryProxy],
{
id: 'DataProtectorSharingImpl',
},
);
const dataProtectorSharingProxy = m.contract(
'TransparentUpgradeableProxy',
[
dataProtectorSharingImpl,
proxyAdminOwner,
'0x', // No initialization data.
],
{
id: 'DataProtectorSharingProxy',
},
);
const dataProtectorSharing = m.contractAt('DataProtectorSharing', dataProtectorSharingProxy);

return { addOnlyAppWhitelistRegistry, dataProtectorSharing };
});
14 changes: 14 additions & 0 deletions packages/sharing-smart-contract/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/sharing-smart-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean": "hardhat clean",
"compile": "hardhat clean && hardhat compile && npm run artifact-to-abis",
"verify": "hardhat verify",
"deploy": "npm run compile && hardhat run ./scripts/deploy.js",
"deploy": "hardhat ignition deploy ignition/modules/DataProtectorSharingModule.cts --strategy create2",
"update-env": "hardhat run ./scripts/updateEnv.js",
"upgrade": "hardhat run ./scripts/upgrade.js",
"upgrade-local-fork": "mkdir -p .openzeppelin/local-fork && cp -r .openzeppelin/prod/. .openzeppelin/local-fork && MANIFEST_DEFAULT_DIR=.openzeppelin/local-fork ENV=prod hardhat run ./scripts/upgrade-local-fork.js",
Expand Down Expand Up @@ -41,6 +41,7 @@
"eslint-plugin-import": "^2.31.0",
"hardhat": "^2.23.0",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-dependency-compiler": "^1.2.1",
"prettier": "^3.3.3",
"prettier-plugin-organize-imports": "^4.0.0",
"prettier-plugin-solidity": "^1.4.1",
Expand Down
Loading
Loading