Skip to content

Commit

Permalink
chore(cli): update template contracts
Browse files Browse the repository at this point in the history
re #722


Former-commit-id: 895f9e1
  • Loading branch information
cedoor committed Mar 25, 2024
1 parent 8d8fb82 commit aa0c9ce
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ contract Feedback {

uint256 public groupId;

constructor(address semaphoreAddress, uint256 _groupId) {
constructor(address semaphoreAddress) {
semaphore = ISemaphore(semaphoreAddress);
groupId = _groupId;

semaphore.createGroup(groupId, address(this));
groupId = semaphore.createGroup();
}

function joinGroup(uint256 identityCommitment) external {
Expand Down
9 changes: 2 additions & 7 deletions packages/cli-template-contracts-hardhat/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { task, types } from "hardhat/config"

task("deploy", "Deploy a Feedback contract")
.addOptionalParam("semaphore", "Semaphore contract address", undefined, types.string)
.addOptionalParam("group", "Group id", "42", types.string)
.addOptionalParam("logs", "Print the logs", true, types.boolean)
.setAction(async ({ logs, semaphore: semaphoreAddress, group: groupId }, { ethers, run }) => {
.setAction(async ({ logs, semaphore: semaphoreAddress }, { ethers, run }) => {
if (!semaphoreAddress) {
const { semaphore } = await run("deploy:semaphore", {
logs
Expand All @@ -13,13 +12,9 @@ task("deploy", "Deploy a Feedback contract")
semaphoreAddress = await semaphore.getAddress()
}

if (!groupId) {
groupId = process.env.GROUP_ID
}

const FeedbackFactory = await ethers.getContractFactory("Feedback")

const feedbackContract = await FeedbackFactory.deploy(semaphoreAddress, groupId)
const feedbackContract = await FeedbackFactory.deploy(semaphoreAddress)

if (logs) {
console.info(`Feedback contract has been deployed to: ${await feedbackContract.getAddress()}`)
Expand Down
5 changes: 2 additions & 3 deletions packages/cli-template-contracts-hardhat/test/Feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { Feedback, ISemaphore } from "../typechain-types"

describe("Feedback", () => {
async function deployFeedbackFixture() {
const groupId = "42"

const { semaphore } = await run("deploy:semaphore", {
logs: false
})
Expand All @@ -19,10 +17,11 @@ describe("Feedback", () => {

const feedbackContract: Feedback = await run("deploy", {
logs: false,
group: groupId,
semaphore: await semaphoreContract.getAddress()
})

const groupId = await feedbackContract.groupId()

return { semaphoreContract, feedbackContract, groupId }
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-template-monorepo-ethers/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DEFAULT_NETWORK=localhost
DEFAULT_NETWORK=hardhat
ETHEREUM_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
REPORT_GAS=false
COINMARKETCAP_API_KEY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ contract Feedback {

uint256 public groupId;

constructor(address semaphoreAddress, uint256 _groupId) {
constructor(address semaphoreAddress) {
semaphore = ISemaphore(semaphoreAddress);
groupId = _groupId;

semaphore.createGroup(groupId, address(this));
groupId = semaphore.createGroup();
}

function joinGroup(uint256 identityCommitment) external {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dotenvConfig({ path: resolve(__dirname, "../../.env") })

const config: HardhatUserConfig = {
solidity: "0.8.23",
defaultNetwork: process.env.DEFAULT_NETWORK || "localhost",
defaultNetwork: process.env.DEFAULT_NETWORK || "hardhat",
networks: {
hardhat: {
chainId: 1337
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { task, types } from "hardhat/config"

task("deploy", "Deploy a Feedback contract")
.addOptionalParam("semaphore", "Semaphore contract address", undefined, types.string)
.addOptionalParam("group", "Group id", "42", types.string)
.addOptionalParam("logs", "Print the logs", true, types.boolean)
.setAction(async ({ logs, semaphore: semaphoreAddress, group: groupId }, { ethers, run }) => {
.setAction(async ({ logs, semaphore: semaphoreAddress }, { ethers, run }) => {
if (!semaphoreAddress) {
const { semaphore } = await run("deploy:semaphore", {
logs
Expand All @@ -13,13 +12,9 @@ task("deploy", "Deploy a Feedback contract")
semaphoreAddress = await semaphore.getAddress()
}

if (!groupId) {
groupId = process.env.GROUP_ID
}

const FeedbackFactory = await ethers.getContractFactory("Feedback")

const feedbackContract = await FeedbackFactory.deploy(semaphoreAddress, groupId)
const feedbackContract = await FeedbackFactory.deploy(semaphoreAddress)

if (logs) {
console.info(`Feedback contract has been deployed to: ${await feedbackContract.getAddress()}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { Feedback, ISemaphore } from "../typechain-types"

describe("Feedback", () => {
async function deployFeedbackFixture() {
const groupId = "42"

const { semaphore } = await run("deploy:semaphore", {
logs: false
})
Expand All @@ -19,10 +17,11 @@ describe("Feedback", () => {

const feedbackContract: Feedback = await run("deploy", {
logs: false,
group: groupId,
semaphore: await semaphoreContract.getAddress()
})

const groupId = await feedbackContract.groupId()

return { semaphoreContract, feedbackContract, groupId }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NEXT_PUBLIC_DEFAULT_NETWORK=localhost
NEXT_PUBLIC_FEEDBACK_CONTRACT_ADDRESS=0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9
NEXT_PUBLIC_SEMAPHORE_CONTRACT_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
NEXT_PUBLIC_GROUP_ID=42
NEXT_PUBLIC_GROUP_ID=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@semaphore-protocol/core": "4.0.0-beta.4",
"@semaphore-protocol/data": "4.0.0-beta.4",
"@semaphore-protocol/utils": "4.0.0-beta.4",
"ethers": "^6.11.1",
"next": "14.1.0",
"next-pwa": "^5.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function GroupsPage() {
setLoading(false)
}, [_identity])

const userHasJoined = useCallback((identity: Identity) => _users.includes(identity.commitment), [_users])
const userHasJoined = useCallback((identity: Identity) => _users.includes(identity.commitment.toString()), [_users])

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import LogsContext from "@/context/LogsContext"
import SemaphoreContext from "@/context/SemaphoreContext"
import useSemaphore from "@/hooks/useSemaphore"
import shortenString from "@/utils/shortenString"
import { SupportedNetwork } from "@semaphore-protocol/data"
import { SupportedNetwork } from "@semaphore-protocol/utils"
import { usePathname } from "next/navigation"
import { useEffect, useState } from "react"
import Link from "next/link"
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function PageContainer({
<div>{shortenString(process.env.NEXT_PUBLIC_FEEDBACK_CONTRACT_ADDRESS as string, [6, 4])}</div>
</a>
<a
href="https://github.com/semaphore-protocol/boilerplate"
href="https://github.com/semaphore-protocol/semaphore"
target="_blank"
rel="noreferrer noopener nofollow"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ethereumNetwork =
: process.env.NEXT_PUBLIC_DEFAULT_NETWORK

export default function useSemaphore(): SemaphoreContextType {
const [_users, setUsers] = useState<any[]>([])
const [_users, setUsers] = useState<string[]>([])
const [_feedback, setFeedback] = useState<string[]>([])

const refreshUsers = useCallback(async (): Promise<void> => {
Expand All @@ -19,7 +19,7 @@ export default function useSemaphore(): SemaphoreContextType {

const members = await semaphore.getGroupMembers(process.env.NEXT_PUBLIC_GROUP_ID as string)

setUsers(members.map((member) => member.toString()))
setUsers(members)
}, [])

const addUser = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-template-monorepo-subgraph/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DEFAULT_NETWORK=localhost
DEFAULT_NETWORK=hardhat
ETHEREUM_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
REPORT_GAS=false
COINMARKETCAP_API_KEY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ contract Feedback {

uint256 public groupId;

constructor(address semaphoreAddress, uint256 _groupId) {
constructor(address semaphoreAddress) {
semaphore = ISemaphore(semaphoreAddress);
groupId = _groupId;

semaphore.createGroup(groupId, address(this));
groupId = semaphore.createGroup();
}

function joinGroup(uint256 identityCommitment) external {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dotenvConfig({ path: resolve(__dirname, "../../.env") })

const config: HardhatUserConfig = {
solidity: "0.8.23",
defaultNetwork: process.env.DEFAULT_NETWORK || "localhost",
defaultNetwork: process.env.DEFAULT_NETWORK || "hardhat",
networks: {
hardhat: {
chainId: 1337
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { task, types } from "hardhat/config"

task("deploy", "Deploy a Feedback contract")
.addOptionalParam("semaphore", "Semaphore contract address", undefined, types.string)
.addOptionalParam("group", "Group id", "42", types.string)
.addOptionalParam("logs", "Print the logs", true, types.boolean)
.setAction(async ({ logs, semaphore: semaphoreAddress, group: groupId }, { ethers, run }) => {
.setAction(async ({ logs, semaphore: semaphoreAddress }, { ethers, run }) => {
if (!semaphoreAddress) {
const { semaphore } = await run("deploy:semaphore", {
logs
Expand All @@ -13,13 +12,9 @@ task("deploy", "Deploy a Feedback contract")
semaphoreAddress = await semaphore.getAddress()
}

if (!groupId) {
groupId = process.env.GROUP_ID
}

const FeedbackFactory = await ethers.getContractFactory("Feedback")

const feedbackContract = await FeedbackFactory.deploy(semaphoreAddress, groupId)
const feedbackContract = await FeedbackFactory.deploy(semaphoreAddress)

if (logs) {
console.info(`Feedback contract has been deployed to: ${await feedbackContract.getAddress()}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { Feedback, ISemaphore } from "../typechain-types"

describe("Feedback", () => {
async function deployFeedbackFixture() {
const groupId = "42"

const { semaphore } = await run("deploy:semaphore", {
logs: false
})
Expand All @@ -19,10 +17,11 @@ describe("Feedback", () => {

const feedbackContract: Feedback = await run("deploy", {
logs: false,
group: groupId,
semaphore: await semaphoreContract.getAddress()
})

const groupId = await feedbackContract.groupId()

return { semaphoreContract, feedbackContract, groupId }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NEXT_PUBLIC_DEFAULT_NETWORK=localhost
NEXT_PUBLIC_FEEDBACK_CONTRACT_ADDRESS=0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9
NEXT_PUBLIC_SEMAPHORE_CONTRACT_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
NEXT_PUBLIC_GROUP_ID=42
NEXT_PUBLIC_GROUP_ID=0
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@semaphore-protocol/core": "4.0.0-beta.4",
"@semaphore-protocol/data": "4.0.0-beta.4",
"@semaphore-protocol/utils": "4.0.0-beta.4",
"ethers": "^6.11.1",
"next": "14.1.0",
"next-pwa": "^5.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use client"

import Stepper from "@/components/Stepper"
import LogsContext from "@/context/LogsContext"
import SemaphoreContext from "@/context/SemaphoreContext"
import { Identity } from "@semaphore-protocol/core"
import { useRouter } from "next/navigation"
import { useCallback, useContext, useEffect, useState } from "react"
import Feedback from "../../../contract-artifacts/Feedback.json"
import Stepper from "@/components/Stepper"
import LogsContext from "@/context/LogsContext"
import SemaphoreContext from "@/context/SemaphoreContext"

export default function GroupsPage() {
const router = useRouter()
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function GroupsPage() {
setLoading(false)
}, [_identity])

const userHasJoined = useCallback((identity: Identity) => _users.includes(identity.commitment), [_users])
const userHasJoined = useCallback((identity: Identity) => _users.includes(identity.commitment.toString()), [_users])

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function PageContainer({
<div>{shortenString(process.env.NEXT_PUBLIC_FEEDBACK_CONTRACT_ADDRESS as string, [6, 4])}</div>
</a>
<a
href="https://github.com/semaphore-protocol/boilerplate"
href="https://github.com/semaphore-protocol/semaphore"
target="_blank"
rel="noreferrer noopener nofollow"
>
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1247bf70e3976f03369bfa231c9c09573776282c
40c5116424f96a0551e5a2c7a9e38f4ed2092871

0 comments on commit aa0c9ce

Please sign in to comment.