Skip to content

Commit

Permalink
refactor(hardhat): update hardhat pkg tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Jan 12, 2024
1 parent c8da0dc commit b162ae6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 91 deletions.
1 change: 0 additions & 1 deletion packages/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"dependencies": {
"@nomiclabs/hardhat-ethers": "^2.1.1",
"@semaphore-protocol/contracts": "3.15.2",
"circomlibjs": "^0.1.7",
"ethers": "^5.7.1",
"hardhat-dependency-compiler": "^1.1.3"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import "./tasks/deploy-semaphore-verifier"

extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
config.dependencyCompiler.paths = [
"@semaphore-protocol/contracts/base/Pairing.sol",
"@semaphore-protocol/contracts/base/SemaphoreVerifier.sol",
"@semaphore-protocol/contracts/Semaphore.sol"
"@semaphore-protocol/contracts/Semaphore.sol",
"poseidon-solidity/PoseidonT3.sol"
]

if (userConfig.dependencyCompiler?.paths) {
Expand Down
25 changes: 3 additions & 22 deletions packages/hardhat/src/tasks/deploy-semaphore-verifier.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
import { task, types } from "hardhat/config"

task("deploy:semaphore-verifier", "Deploy a SemaphoreVerifier contract")
.addOptionalParam<boolean>("pairing", "Pairing library address", undefined, types.string)
.addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
.setAction(async ({ logs, pairing: pairingAddress }, { ethers }): Promise<any> => {
if (!pairingAddress) {
const PairingFactory = await ethers.getContractFactory("Pairing")
const pairing = await PairingFactory.deploy()

await pairing.deployed()

if (logs) {
console.info(`Pairing library has been deployed to: ${pairing.address}`)
}

pairingAddress = pairing.address
}

const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier", {
libraries: {
Pairing: pairingAddress
}
})
.setAction(async ({ logs }, { ethers }): Promise<any> => {
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier")

const semaphoreVerifier = await SemaphoreVerifierFactory.deploy()

Expand All @@ -32,7 +14,6 @@ task("deploy:semaphore-verifier", "Deploy a SemaphoreVerifier contract")
}

return {
semaphoreVerifier,
pairingAddress
semaphoreVerifier
}
})
75 changes: 10 additions & 65 deletions packages/hardhat/src/tasks/deploy-semaphore.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,16 @@
import { poseidonContract } from "circomlibjs"
import { task, types } from "hardhat/config"

task("deploy:semaphore", "Deploy a Semaphore contract")
.addOptionalParam<boolean>("pairing", "Pairing library address", undefined, types.string)
.addOptionalParam<boolean>("semaphoreVerifier", "SemaphoreVerifier contract address", undefined, types.string)
.addOptionalParam<boolean>("poseidon", "Poseidon library address", undefined, types.string)
.addOptionalParam<boolean>(
"incrementalBinaryTree",
"IncrementalBinaryTree library address",
undefined,
types.string
)
.addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
.setAction(
async (
{
logs,
pairing: pairingAddress,
semaphoreVerifier: semaphoreVerifierAddress,
poseidon: poseidonAddress,
incrementalBinaryTree: incrementalBinaryTreeAddress
},
{ logs, semaphoreVerifier: semaphoreVerifierAddress, poseidon: poseidonAddress },
{ ethers }
): Promise<any> => {
if (!semaphoreVerifierAddress) {
if (!pairingAddress) {
const PairingFactory = await ethers.getContractFactory("Pairing")
const pairing = await PairingFactory.deploy()

await pairing.deployed()

if (logs) {
console.info(`Pairing library has been deployed to: ${pairing.address}`)
}

pairingAddress = pairing.address
}

const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier", {
libraries: {
Pairing: pairingAddress
}
})
const SemaphoreVerifierFactory = await ethers.getContractFactory("SemaphoreVerifier")

const semaphoreVerifier = await SemaphoreVerifierFactory.deploy()

Expand All @@ -54,44 +23,22 @@ task("deploy:semaphore", "Deploy a Semaphore contract")
semaphoreVerifierAddress = semaphoreVerifier.address
}

if (!incrementalBinaryTreeAddress) {
if (!poseidonAddress) {
const poseidonABI = poseidonContract.generateABI(2)
const poseidonBytecode = poseidonContract.createCode(2)

const [signer] = await ethers.getSigners()

const PoseidonFactory = new ethers.ContractFactory(poseidonABI, poseidonBytecode, signer)
const poseidon = await PoseidonFactory.deploy()

await poseidon.deployed()

if (logs) {
console.info(`Poseidon library has been deployed to: ${poseidon.address}`)
}

poseidonAddress = poseidon.address
}

const IncrementalBinaryTreeFactory = await ethers.getContractFactory("IncrementalBinaryTree", {
libraries: {
PoseidonT3: poseidonAddress
}
})
const incrementalBinaryTree = await IncrementalBinaryTreeFactory.deploy()
if (!poseidonAddress) {
const PoseidonT3Factory = await ethers.getContractFactory("PoseidonT3")
const poseidonT3 = await PoseidonT3Factory.deploy()

await incrementalBinaryTree.deployed()
await poseidonT3.deployed()

if (logs) {
console.info(`IncrementalBinaryTree library has been deployed to: ${incrementalBinaryTree.address}`)
console.info(`Poseidon library has been deployed to: ${poseidonT3.address}`)
}

incrementalBinaryTreeAddress = incrementalBinaryTree.address
poseidonAddress = poseidonT3.address
}

const SemaphoreFactory = await ethers.getContractFactory("Semaphore", {
libraries: {
IncrementalBinaryTree: incrementalBinaryTreeAddress
PoseidonT3: poseidonAddress
}
})

Expand All @@ -105,10 +52,8 @@ task("deploy:semaphore", "Deploy a Semaphore contract")

return {
semaphore,
pairingAddress,
semaphoreVerifierAddress,
poseidonAddress,
incrementalBinaryTreeAddress
poseidonAddress
}
}
)
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8451,7 +8451,6 @@ __metadata:
dependencies:
"@nomiclabs/hardhat-ethers": ^2.1.1
"@semaphore-protocol/contracts": 3.15.2
circomlibjs: ^0.1.7
ethers: ^5.7.1
hardhat: ^2.0.0
hardhat-dependency-compiler: ^1.1.3
Expand Down

0 comments on commit b162ae6

Please sign in to comment.