Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to choose a custom network for deploying AddressesProvider contract #70

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const forkUrl = {
goerliStaging: NETWORKS_RPC_URL[EthereumNetwork.goerli],
mumbaiStaging: NETWORKS_RPC_URL[PolygonNetwork.mumbai],
gnosis: NETWORKS_RPC_URL[GnosisNetwork.gnosis],
customNetwork: process.env.RPC_URL,
};

const forking = FORK
Expand Down Expand Up @@ -126,6 +127,17 @@ const config: HardhatUserConfig = {
mumbaiStaging: getCommonNetworkConfig(PolygonNetwork.mumbai, 80001),
goerliTestnet: getCommonNetworkConfig(EthereumNetwork.goerli, 5),
mumbaiTestnet: getCommonNetworkConfig(PolygonNetwork.mumbai, 80001),
customNetwork: {
url: process.env.RPC_URL ?? '',
hardfork: HARDFORK,
chainId: parseInt(process.env.CHAIN_ID ?? '31337'),
accounts: {
mnemonic: MNEMONIC,
path: MNEMONIC_PATH,
initialIndex: 0,
count: 20,
},
},
gnosis: getCommonNetworkConfig(GnosisNetwork.gnosis, 100),
local: {
url: `http://${LOCAL_HOSTNAME}:${LOCAL_PORT}`,
Expand Down
33 changes: 24 additions & 9 deletions tasks/deploy-tasks/full/6-deploy-sismo-addresses-provider.task.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import { task } from 'hardhat/config';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployOptions } from '../utils';
import { deploymentsConfig } from '../deployments-config';
import { SISMO_ADDRESSES_PROVIDER_CONTRACT_ADDRESS } from '../deployments-config';
import { DeployedSismoAddressesProvider } from 'tasks/deploy-tasks/unit/core/deploy-sismo-addresses-provider.task';
import { AddressesProvider } from 'types';

export interface Deployed6 {
sismoAddressesProvider: AddressesProvider;
}

export const addressesProviderConfiguration = {
deployOptions: {
manualConfirm: process.env.MANUAL_CONFIRM === 'true',
log: true,
behindProxy: true,
proxyAdmin: process.env.PROXY_ADMIN,
},
sismoAddressesProvider: {
address: SISMO_ADDRESSES_PROVIDER_CONTRACT_ADDRESS,
owner: process.env.SISMO_ADDRESSES_PROVIDER_OWNER,
},
};

async function deploymentAction(
{ options }: { options: DeployOptions },
hre: HardhatRuntimeEnvironment
): Promise<Deployed6> {
const config = deploymentsConfig[process.env.FORK_NETWORK ?? hre.network.name];
// ZK Badges are deprecated, we only use SismoAddressesProvider for Sismo Connect
const config = addressesProviderConfiguration;

options = { ...config.deployOptions, ...options };

if (options.manualConfirm || options.log) {
Expand All @@ -23,13 +38,13 @@ async function deploymentAction(
// Deploy SismoAddressesProvider
const { sismoAddressesProvider } = (await hre.run('deploy-sismo-addresses-provider', {
owner: config.sismoAddressesProvider.owner,
badges: config.badges.address,
attestationsRegistry: config.attestationsRegistry.address,
front: config.front.address,
hydraS1AccountboundAttester: config.hydraS1AccountboundAttester.address,
commitmentMapperRegistry: config.commitmentMapper.address,
availableRootsRegistry: config.availableRootsRegistry.address,
hydraS1Verifier: config.hydraS1Verifier.address,
badges: '0x0000000000000000000000000000000000000000',
attestationsRegistry: '0x0000000000000000000000000000000000000000',
front: '0x0000000000000000000000000000000000000000',
hydraS1AccountboundAttester: '0x0000000000000000000000000000000000000000',
commitmentMapperRegistry: '0x0000000000000000000000000000000000000000',
availableRootsRegistry: '0x0000000000000000000000000000000000000000',
hydraS1Verifier: '0x0000000000000000000000000000000000000000',
options: { ...options, proxyAdmin: config.deployOptions.proxyAdmin },
})) as DeployedSismoAddressesProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
customDeployContract,
wrapCommonDeployOptions,
DeployOptions,
wrapAddressesProviderDeployOptions,
} from '../../utils';

import {
Expand All @@ -17,8 +18,8 @@ import {
TransparentUpgradeableProxy__factory,
} from '../../../../types';
import { utils } from 'ethers';
import { deploymentsConfig } from '../../../../tasks/deploy-tasks/deployments-config';
import { confirm } from '../../../../tasks/utils';
import { addressesProviderConfiguration } from '../../../../tasks/deploy-tasks/full/6-deploy-sismo-addresses-provider.task';

export interface DeploySismoAddressesProvider {
owner: string;
Expand Down Expand Up @@ -52,7 +53,7 @@ async function deploymentAction(
}: DeploySismoAddressesProvider,
hre: HardhatRuntimeEnvironment
): Promise<DeployedSismoAddressesProvider> {
const config = deploymentsConfig[hre.network.name];
const config = addressesProviderConfiguration;

const deployer = await getDeployer(hre);
const deploymentName = buildDeploymentName(CONTRACT_NAME, options?.deploymentNamePrefix);
Expand Down Expand Up @@ -253,9 +254,7 @@ async function deploymentAction(

if (options?.log) {
console.log(
`Transfer AddressesProvider ownership (${
deployer.address
}) from the deployer to the expected one (${options?.proxyAdmin!})`
`Transfer AddressesProvider ownership (${deployer.address}) from the deployer to the expected one (${owner})`
);
if (options?.manualConfirm) {
await confirm();
Expand All @@ -276,4 +275,4 @@ task('deploy-sismo-addresses-provider')
.addParam('availableRootsRegistry', 'Address of the availableRootsRegistry contract')
.addParam('commitmentMapperRegistry', 'Address of the commitmentMapperRegistry contract')
.addParam('hydraS1Verifier', 'Address of the hydraS1Verifier contract')
.setAction(wrapCommonDeployOptions(deploymentAction));
.setAction(wrapAddressesProviderDeployOptions(deploymentAction, addressesProviderConfiguration));
16 changes: 16 additions & 0 deletions tasks/deploy-tasks/utils/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,21 @@ export const wrapCommonDeployOptions = (action: Function) => {
};
};

export const wrapAddressesProviderDeployOptions = (action: Function, configuration: any) => {
return (args: any, hre: HardhatRuntimeEnvironment) => {
const config = configuration;
return action(
{
...args,
options: {
...config.deployOptions,
...args.options,
},
},
hre
);
};
};

export const buildDeploymentName = (contractName: string, prefix?: string) =>
prefix ? `${prefix}_${contractName}` : contractName;
1 change: 1 addition & 0 deletions test/unit/core/utils/sismo-addresses-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('Test Sismo Addresses Provider', () => {
hydraS1Verifier: hydraS1Verifier.address,
options: {
deploymentNamePrefix: 'firstDeployment',
proxyAdmin: deploymentsConfig[hre.network.name].deployOptions?.proxyAdmin,
},
}));
expect(sismoAddressesProvider.address).to.be.eql(addressesProviderContractAddress);
Expand Down
1 change: 1 addition & 0 deletions test/unit/zkdrop/zk-badgebound-erc721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('Test ZK Badgebound ERC721 Contract', async () => {
({ attestationsRegistry, hydraS1AccountboundAttester, badges, availableRootsRegistry } =
await deployCoreContracts(deployer, {
deploymentNamePrefix: 'zk-badgebound-erc721',
proxyAdmin: deploymentsConfig[hre.network.name].deployOptions.proxyAdmin,
}));

badgeId = (await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST()).add(
Expand Down
9 changes: 9 additions & 0 deletions utils/singletonFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ export const singletonFactory = {
'0xf8a88085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf383027126a0b23aa3a7cf3654c8f2dc3ce3c6d37ff504a726085f835a9f4d32d61e865e261ea017add99e70915725b41244e4feefc854f5c17da90f4e1ac6fb994040ae5af242',
address: '0xC4c11B14e9D876B031c1c7e05efE44088341f35B',
},
// scroll goerli
534353: {
gasPrice: 100000000000,
gasLimit: 100000,
signerAddress: '0xBa68986f673c9193BB79eA0d21990225d464bb5C',
transaction:
'0xf8a88085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf383104ec5a0ae1bbd559b87c3e9b9116af0178587620b6cdb0b69112c15fbcf92515c6a111da0272fc08470cc1a9ebe1e06e55d733dbf7c93f0bc0d78616b0582366e6b73277e',
address: '0xC4c11B14e9D876B031c1c7e05efE44088341f35B',
},
};