11import { SupportedNetwork } from "@semaphore-protocol/utils"
22import { task , types } from "hardhat/config"
3- import { saveDeployedContracts } from "../scripts/utils"
3+ import { deploy , saveDeployedContracts } from "../scripts/utils"
44
55task ( "deploy" , "Deploy a Semaphore contract" )
66 . addOptionalParam < boolean > ( "verifier" , "Verifier contract address" , undefined , types . string )
@@ -14,44 +14,32 @@ task("deploy", "Deploy a Semaphore contract")
1414 const startBlock = await ethers . provider . getBlockNumber ( )
1515
1616 if ( ! semaphoreVerifierAddress ) {
17- const VerifierFactory = await ethers . getContractFactory ( `SemaphoreVerifier` )
18-
19- const verifier = await VerifierFactory . deploy ( )
20-
21- await verifier . waitForDeployment ( )
22-
23- semaphoreVerifierAddress = await verifier . getAddress ( )
17+ semaphoreVerifierAddress = await deploy ( ethers , "SemaphoreVerifier" , hardhatArguments . network )
2418
2519 if ( logs ) {
2620 console . info ( `SemaphoreVerifier contract has been deployed to: ${ semaphoreVerifierAddress } ` )
2721 }
2822 }
2923
3024 if ( ! poseidonT3Address ) {
31- const PoseidonT3Factory = await ethers . getContractFactory ( "PoseidonT3" )
32-
33- const poseidonT3 = await PoseidonT3Factory . deploy ( )
34-
35- await poseidonT3 . waitForDeployment ( )
36-
37- poseidonT3Address = await poseidonT3 . getAddress ( )
25+ poseidonT3Address = await deploy ( ethers , "PoseidonT3" , hardhatArguments . network )
3826
3927 if ( logs ) {
4028 console . info ( `PoseidonT3 library has been deployed to: ${ poseidonT3Address } ` )
4129 }
4230 }
4331
44- const SemaphoreFactory = await ethers . getContractFactory ( "Semaphore" , {
45- libraries : {
46- PoseidonT3 : poseidonT3Address
32+ const semaphoreAddress = await deploy (
33+ ethers ,
34+ "Semaphore" ,
35+ hardhatArguments . network ,
36+ [ semaphoreVerifierAddress ] ,
37+ {
38+ libraries : {
39+ PoseidonT3 : poseidonT3Address
40+ }
4741 }
48- } )
49-
50- const semaphore = await SemaphoreFactory . deploy ( semaphoreVerifierAddress )
51-
52- await semaphore . waitForDeployment ( )
53-
54- const semaphoreAddress = await semaphore . getAddress ( )
42+ )
5543
5644 if ( logs ) {
5745 console . info ( `Semaphore contract has been deployed to: ${ semaphoreAddress } ` )
@@ -79,7 +67,7 @@ task("deploy", "Deploy a Semaphore contract")
7967 )
8068
8169 return {
82- semaphore,
70+ semaphore : await ethers . getContractAt ( "Semaphore" , semaphoreAddress ) ,
8371 verifierAddress : semaphoreVerifierAddress ,
8472 poseidonAddress : poseidonT3Address
8573 }
0 commit comments