-
Notifications
You must be signed in to change notification settings - Fork 198
/
deploy-semaphore.ts
60 lines (49 loc) · 2.35 KB
/
deploy-semaphore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { task, types } from "hardhat/config"
/**
* Defines a Hardhat task to deploy the Semaphore contract.
* This task handles the deployment of dependent contracts like SemaphoreVerifier and PoseidonT3 if not provided.
*/
task("deploy:semaphore", "Deploy a Semaphore contract")
.addOptionalParam<boolean>("semaphoreVerifier", "SemaphoreVerifier contract address", undefined, types.string)
.addOptionalParam<boolean>("poseidon", "Poseidon library address", undefined, types.string)
.addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
.setAction(
async (
{ logs, semaphoreVerifier: semaphoreVerifierAddress, poseidon: poseidonAddress },
{ ethers }
): Promise<any> => {
// Deploy SemaphoreVerifier if not provided.
if (!semaphoreVerifierAddress) {
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier")
const semaphoreVerifier = await SemaphoreVerifierFactory.deploy()
semaphoreVerifierAddress = await semaphoreVerifier.getAddress()
if (logs) {
console.info(`SemaphoreVerifier contract has been deployed to: ${semaphoreVerifierAddress}`)
}
}
// Deploy PoseidonT3 if not provided.
if (!poseidonAddress) {
const PoseidonT3Factory = await ethers.getContractFactory("PoseidonT3")
const poseidonT3 = await PoseidonT3Factory.deploy()
poseidonAddress = await poseidonT3.getAddress()
if (logs) {
console.info(`Poseidon library has been deployed to: ${poseidonAddress}`)
}
}
// Deploy the Semaphore contract with the necessary library.
const SemaphoreFactory = await ethers.getContractFactory("Semaphore", {
libraries: {
PoseidonT3: poseidonAddress
}
})
const semaphore = await SemaphoreFactory.deploy(semaphoreVerifierAddress)
if (logs) {
console.info(`Semaphore contract has been deployed to: ${await semaphore.getAddress()}`)
}
return {
semaphore,
semaphoreVerifierAddress,
poseidonAddress
}
}
)