Skip to content

Commit

Permalink
feat: support deployment without hardhat
Browse files Browse the repository at this point in the history
- [x] Use signer for deployment
- [x] Use hardhat as a fallback
- [x] Compatibility fixes
  • Loading branch information
0xmad committed Apr 24, 2024
1 parent ab97591 commit dab5e2b
Show file tree
Hide file tree
Showing 32 changed files with 598 additions and 704 deletions.
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"commander": "^12.0.0",
"dotenv": "^16.4.5",
"ethers": "^6.12.0",
"hardhat": "^2.22.2",
"hardhat": "^2.22.3",
"maci-circuits": "^1.2.0",
"maci-contracts": "^1.2.0",
"maci-core": "^1.2.0",
Expand Down
1 change: 1 addition & 0 deletions cli/ts/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const deploy = async ({
// check if we have a signupGatekeeper already deployed or passed as arg
let signupGatekeeperContractAddress =
signupGatekeeperAddress || readContractAddress("SignUpGatekeeper", network?.name);

if (!signupGatekeeperContractAddress) {
const contract = await deployFreeForAllSignUpGatekeeper(signer, true);
signupGatekeeperContractAddress = await contract.getAddress();
Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@openzeppelin/contracts": "^5.0.2",
"circomlibjs": "^0.1.7",
"ethers": "^6.12.0",
"hardhat": "^2.22.2",
"hardhat": "^2.22.3",
"maci-circuits": "^1.2.0",
"maci-core": "^1.2.0",
"maci-crypto": "^1.2.0",
Expand Down
73 changes: 37 additions & 36 deletions contracts/tasks/deploy/maci/01-constantInitialVoiceCreditProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,40 @@ const storage = ContractStorage.getInstance();
*/
deployment
.deployTask("full:deploy-constant-initial-voice-credit-proxy", "Deploy constant initial voice credit proxy")
.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

const needDeploy = deployment.getDeployConfigField(EContracts.ConstantInitialVoiceCreditProxy, "deploy");

if (needDeploy === false) {
return;
}

const constantInitialVoiceCreditProxyContractAddress = storage.getAddress(
EContracts.ConstantInitialVoiceCreditProxy,
hre.network.name,
);

if (incremental && constantInitialVoiceCreditProxyContractAddress) {
return;
}

const amount =
deployment.getDeployConfigField<number | null>(EContracts.ConstantInitialVoiceCreditProxy, "amount") ??
DEFAULT_INITIAL_VOICE_CREDITS;

const constantInitialVoiceCreditProxyContract = await deployment.deployContract(
EContracts.ConstantInitialVoiceCreditProxy,
deployer,
amount.toString(),
);

await storage.register({
id: EContracts.ConstantInitialVoiceCreditProxy,
contract: constantInitialVoiceCreditProxyContract,
args: [amount.toString()],
network: hre.network.name,
});
});
.then((task) =>
task.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

const needDeploy = deployment.getDeployConfigField(EContracts.ConstantInitialVoiceCreditProxy, "deploy");

if (needDeploy === false) {
return;
}

const constantInitialVoiceCreditProxyContractAddress = storage.getAddress(
EContracts.ConstantInitialVoiceCreditProxy,
hre.network.name,
);

if (incremental && constantInitialVoiceCreditProxyContractAddress) {
return;
}

const amount =
deployment.getDeployConfigField<number | null>(EContracts.ConstantInitialVoiceCreditProxy, "amount") ??
DEFAULT_INITIAL_VOICE_CREDITS;

const constantInitialVoiceCreditProxyContract = await deployment.deployContract(
{ name: EContracts.ConstantInitialVoiceCreditProxy, signer: deployer },
amount.toString(),
);

await storage.register({
id: EContracts.ConstantInitialVoiceCreditProxy,
contract: constantInitialVoiceCreditProxyContract,
args: [amount.toString()],
network: hre.network.name,
});
}),
);
21 changes: 13 additions & 8 deletions contracts/tasks/deploy/maci/02-gatekeepers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ const storage = ContractStorage.getInstance();
/**
* Deploy step registration and task itself
*/
deployment
.deployTask("full:deploy-gatekeepers", "Deploy gatekeepers")
.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.deployTask("full:deploy-gatekeepers", "Deploy gatekeepers").then((task) =>
task.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

Expand All @@ -34,11 +33,14 @@ deployment
}

if (!skipDeployFreeForAllGatekeeper) {
const freeFroAllGatekeeperContract = await deployment.deployContract(EContracts.FreeForAllGatekeeper, deployer);
const freeForAllGatekeeperContract = await deployment.deployContract({
name: EContracts.FreeForAllGatekeeper,
signer: deployer,
});

await storage.register({
id: EContracts.FreeForAllGatekeeper,
contract: freeFroAllGatekeeperContract,
contract: freeForAllGatekeeperContract,
args: [],
network: hre.network.name,
});
Expand All @@ -54,8 +56,10 @@ deployment
const attester = deployment.getDeployConfigField<string>(EContracts.EASGatekeeper, "attester", true);

const easGatekeeperContract = await deployment.deployContract(
EContracts.EASGatekeeper,
deployer,
{
name: EContracts.EASGatekeeper,
signer: deployer,
},
easAddress,
attester,
encodedSchema,
Expand All @@ -68,4 +72,5 @@ deployment
network: hre.network.name,
});
}
});
}),
);
10 changes: 5 additions & 5 deletions contracts/tasks/deploy/maci/03-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const storage = ContractStorage.getInstance();
/**
* Deploy step registration and task itself
*/
deployment
.deployTask("full:deploy-verifier", "Deploy verifier")
.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.deployTask("full:deploy-verifier", "Deploy verifier").then((task) =>
task.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

Expand All @@ -20,12 +19,13 @@ deployment
return;
}

const verifierContract = await deployment.deployContract(EContracts.Verifier, deployer);
const verifierContract = await deployment.deployContract({ name: EContracts.Verifier, signer: deployer });

await storage.register({
id: EContracts.Verifier,
contract: verifierContract,
args: [],
network: hre.network.name,
});
});
}),
);
10 changes: 5 additions & 5 deletions contracts/tasks/deploy/maci/04-topupCredit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const storage = ContractStorage.getInstance();
/**
* Deploy step registration and task itself
*/
deployment
.deployTask("full:deploy-topup-credit", "Deploy topup credit")
.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.deployTask("full:deploy-topup-credit", "Deploy topup credit").then((task) =>
task.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

Expand All @@ -20,12 +19,13 @@ deployment
return;
}

const topupCreditContract = await deployment.deployContract(EContracts.TopupCredit, deployer);
const topupCreditContract = await deployment.deployContract({ name: EContracts.TopupCredit, signer: deployer });

await storage.register({
id: EContracts.TopupCredit,
contract: topupCreditContract,
args: [],
network: hre.network.name,
});
});
}),
);
16 changes: 8 additions & 8 deletions contracts/tasks/deploy/maci/05-poseidon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const storage = ContractStorage.getInstance();
/**
* Deploy step registration and task itself
*/
deployment
.deployTask("full:deploy-poseidon", "Deploy poseidon contracts")
.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.deployTask("full:deploy-poseidon", "Deploy poseidon contracts").then((task) =>
task.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

Expand All @@ -29,10 +28,10 @@ deployment
return;
}

const PoseidonT3Contract = await deployment.deployContract(EContracts.PoseidonT3, deployer);
const PoseidonT4Contract = await deployment.deployContract(EContracts.PoseidonT4, deployer);
const PoseidonT5Contract = await deployment.deployContract(EContracts.PoseidonT5, deployer);
const PoseidonT6Contract = await deployment.deployContract(EContracts.PoseidonT6, deployer);
const PoseidonT3Contract = await deployment.deployContract({ name: EContracts.PoseidonT3, signer: deployer });
const PoseidonT4Contract = await deployment.deployContract({ name: EContracts.PoseidonT4, signer: deployer });
const PoseidonT5Contract = await deployment.deployContract({ name: EContracts.PoseidonT5, signer: deployer });
const PoseidonT6Contract = await deployment.deployContract({ name: EContracts.PoseidonT6, signer: deployer });

await Promise.all([
storage.register({
Expand Down Expand Up @@ -60,4 +59,5 @@ deployment
network: hre.network.name,
}),
]);
});
}),
);
25 changes: 13 additions & 12 deletions contracts/tasks/deploy/maci/06-pollFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const storage = ContractStorage.getInstance();
/**
* Deploy step registration and task itself
*/
deployment
.deployTask("full:deploy-poll-factory", "Deploy poll factory")
.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.deployTask("full:deploy-poll-factory", "Deploy poll factory").then((task) =>
task.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

Expand All @@ -25,14 +24,15 @@ deployment
const poseidonT5ContractAddress = storage.mustGetAddress(EContracts.PoseidonT5, hre.network.name);
const poseidonT6ContractAddress = storage.mustGetAddress(EContracts.PoseidonT6, hre.network.name);

const linkedPollFactoryContract = await deployment.linkPoseidonLibraries(
EContracts.PollFactory,
poseidonT3ContractAddress,
poseidonT4ContractAddress,
poseidonT5ContractAddress,
poseidonT6ContractAddress,
deployer,
);
const linkedPollFactoryContract = await hre.ethers.getContractFactory(EContracts.PollFactory, {
signer: deployer,
libraries: {
PoseidonT3: poseidonT3ContractAddress,
PoseidonT4: poseidonT4ContractAddress,
PoseidonT5: poseidonT5ContractAddress,
PoseidonT6: poseidonT6ContractAddress,
},
});

const pollFactoryContract = await deployment.deployContractWithLinkedLibraries(linkedPollFactoryContract);

Expand All @@ -42,4 +42,5 @@ deployment
args: [],
network: hre.network.name,
});
});
}),
);
24 changes: 14 additions & 10 deletions contracts/tasks/deploy/maci/07-messageProcessorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const storage = ContractStorage.getInstance();
/**
* Deploy step registration and task itself
*/
deployment
.deployTask("full:deploy-message-processor-factory", "Deploy message processor factory")
.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.deployTask("full:deploy-message-processor-factory", "Deploy message processor factory").then((task) =>
task.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

Expand All @@ -28,13 +27,17 @@ deployment
const poseidonT5ContractAddress = storage.mustGetAddress(EContracts.PoseidonT5, hre.network.name);
const poseidonT6ContractAddress = storage.mustGetAddress(EContracts.PoseidonT6, hre.network.name);

const linkedMessageProcessorFactoryContract = await deployment.linkPoseidonLibraries(
const linkedMessageProcessorFactoryContract = await hre.ethers.getContractFactory(
EContracts.MessageProcessorFactory,
poseidonT3ContractAddress,
poseidonT4ContractAddress,
poseidonT5ContractAddress,
poseidonT6ContractAddress,
deployer,
{
signer: deployer,
libraries: {
PoseidonT3: poseidonT3ContractAddress,
PoseidonT4: poseidonT4ContractAddress,
PoseidonT5: poseidonT5ContractAddress,
PoseidonT6: poseidonT6ContractAddress,
},
},
);

const messageProcessorFactoryContract = await deployment.deployContractWithLinkedLibraries(
Expand All @@ -47,4 +50,5 @@ deployment
args: [],
network: hre.network.name,
});
});
}),
);
25 changes: 13 additions & 12 deletions contracts/tasks/deploy/maci/08-tallyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const storage = ContractStorage.getInstance();
/**
* Deploy step registration and task itself
*/
deployment
.deployTask("full:deploy-tally-factory", "Deploy tally factory")
.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.deployTask("full:deploy-tally-factory", "Deploy tally factory").then((task) =>
task.setAction(async ({ incremental }: IDeployParams, hre) => {
deployment.setHre(hre);
const deployer = await deployment.getDeployer();

Expand All @@ -25,14 +24,15 @@ deployment
const poseidonT5ContractAddress = storage.mustGetAddress(EContracts.PoseidonT5, hre.network.name);
const poseidonT6ContractAddress = storage.mustGetAddress(EContracts.PoseidonT6, hre.network.name);

const linkedTallyFactoryContract = await deployment.linkPoseidonLibraries(
EContracts.TallyFactory,
poseidonT3ContractAddress,
poseidonT4ContractAddress,
poseidonT5ContractAddress,
poseidonT6ContractAddress,
deployer,
);
const linkedTallyFactoryContract = await hre.ethers.getContractFactory(EContracts.TallyFactory, {
signer: deployer,
libraries: {
PoseidonT3: poseidonT3ContractAddress,
PoseidonT4: poseidonT4ContractAddress,
PoseidonT5: poseidonT5ContractAddress,
PoseidonT6: poseidonT6ContractAddress,
},
});

const tallyFactoryContract = await deployment.deployContractWithLinkedLibraries(linkedTallyFactoryContract);

Expand All @@ -42,4 +42,5 @@ deployment
args: [],
network: hre.network.name,
});
});
}),
);
Loading

0 comments on commit dab5e2b

Please sign in to comment.