Skip to content

Commit

Permalink
Merge pull request #431 from privacy-scaling-explorations/feat/sepolia
Browse files Browse the repository at this point in the history
Add Sepolia as default network
  • Loading branch information
vplasencia authored Mar 8, 2024
2 parents 21eab4c + c932eae commit 03549d0
Show file tree
Hide file tree
Showing 18 changed files with 226 additions and 96 deletions.
126 changes: 63 additions & 63 deletions apps/api/src/app/groups/groups.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BandadaContract, getBandadaContract, Network } from "@bandada/utils"
// import { BandadaContract, getBandadaContract, Network } from "@bandada/utils"
import { id } from "@ethersproject/hash"
import {
BadRequestException,
Expand All @@ -23,7 +23,7 @@ import { MerkleProof } from "./types"
@Injectable()
export class GroupsService {
private cachedGroups: Map<string, CachedGroup>
private bandadaContract: BandadaContract
// private bandadaContract: BandadaContract

constructor(
@InjectRepository(Group)
Expand All @@ -34,11 +34,11 @@ export class GroupsService {
private readonly invitesService: InvitesService
) {
this.cachedGroups = new Map()
this.bandadaContract = getBandadaContract(
process.env.ETHEREUM_NETWORK as Network,
process.env.BACKEND_PRIVATE_KEY as string,
process.env.INFURA_API_KEY as string
)
// this.bandadaContract = getBandadaContract(
// process.env.ETHEREUM_NETWORK as Network,
// process.env.BACKEND_PRIVATE_KEY as string,
// process.env.INFURA_API_KEY as string
// )
}

/**
Expand Down Expand Up @@ -697,24 +697,24 @@ export class GroupsService {
return fingerprints
}

private async _updateFingerprintDuration(
groupId: string,
duration: number
): Promise<void> {
try {
await this.bandadaContract.updateFingerprintDuration(
BigInt(groupId),
BigInt(duration)
)
Logger.log(
`GroupsService: group '${groupId}' fingerprint duration has been updated in the contract`
)
} catch {
Logger.log(
`GroupsService: failed to update fingerprint duration contract groups`
)
}
}
// private async _updateFingerprintDuration(
// groupId: string,
// duration: number
// ): Promise<void> {
// try {
// await this.bandadaContract.updateFingerprintDuration(
// BigInt(groupId),
// BigInt(duration)
// )
// Logger.log(
// `GroupsService: group '${groupId}' fingerprint duration has been updated in the contract`
// )
// } catch {
// Logger.log(
// `GroupsService: failed to update fingerprint duration contract groups`
// )
// }
// }

private async _cacheGroups() {
const groups = await this.getGroups()
Expand All @@ -739,42 +739,42 @@ export class GroupsService {
Logger.log(`GroupsService: ${groups.length} groups have been cached`)
}

/**
* If the off-chain groups roots don't match the contract's ones, it updates them.
*/
/* istanbul ignore next */
private async _syncContractGroups() {
const contractGroups = await this.bandadaContract.getGroups()
const fingerprints = new Set(
contractGroups.map(({ fingerprint }) => fingerprint.toString())
)

for (const [, group] of this.cachedGroups) {
if (!fingerprints.has(group.root.toString())) {
this._updateContractGroup(group)
}
}
}

/**
* Update the fingerprint of the group in the contract.
* @param group Off-chain group.
*/
/* istanbul ignore next */
private async _updateContractGroup(group: CachedGroup): Promise<void> {
try {
await this.bandadaContract.updateGroups([
{
id: BigInt(group.id),
fingerprint: BigInt(group.root)
}
])

Logger.log(
`GroupsService: group '${group.id}' has been updated in the contract`
)
} catch {
Logger.error(`GroupsService: failed to update contract groups`)
}
}
// /**
// * If the off-chain groups roots don't match the contract's ones, it updates them.
// */
// /* istanbul ignore next */
// private async _syncContractGroups() {
// const contractGroups = await this.bandadaContract.getGroups()
// const fingerprints = new Set(
// contractGroups.map(({ fingerprint }) => fingerprint.toString())
// )

// for (const [, group] of this.cachedGroups) {
// if (!fingerprints.has(group.root.toString())) {
// this._updateContractGroup(group)
// }
// }
// }

// /**
// * Update the fingerprint of the group in the contract.
// * @param group Off-chain group.
// */
// /* istanbul ignore next */
// private async _updateContractGroup(group: CachedGroup): Promise<void> {
// try {
// await this.bandadaContract.updateGroups([
// {
// id: BigInt(group.id),
// fingerprint: BigInt(group.root)
// }
// ])

// Logger.log(
// `GroupsService: group '${group.id}' has been updated in the contract`
// )
// } catch {
// Logger.error(`GroupsService: failed to update contract groups`)
// }
// }
}
2 changes: 1 addition & 1 deletion apps/contracts/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ yarn deploy:bandada
yarn deploy:bandada-semaphore
```

If you want to deploy contracts on Goerli or Arbitrum, remember to provide a valid private key and an Infura API in your `.env` file.
If you want to deploy contracts on Sepolia or Arbitrum, remember to provide a valid private key and an Infura API in your `.env` file.
6 changes: 3 additions & 3 deletions apps/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function getNetworks(): NetworksUserConfig {
chainId: 1337,
accounts
},
goerli: {
url: `https://goerli.infura.io/v3/${infuraApiKey}`,
chainId: 5,
sepolia: {
url: `https://sepolia.infura.io/v3/${infuraApiKey}`,
chainId: 11155111,
accounts
},
arbitrum: {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
VITE_API_URL=http://localhost:3000
VITE_CLIENT_URL=http://localhost:3002
VITE_CLIENT_INVITES_URL=http://localhost:3002?inviteCode=\
VITE_ETHEREUM_NETWORK=goerli
VITE_ETHEREUM_NETWORK=sepolia
VITE_GITHUB_CLIENT_ID=a83a8b014ef38270fb22
VITE_TWITTER_CLIENT_ID=NV82Mm85NWlSZ1llZkpLMl9vN3A6MTpjaQ
VITE_TWITTER_REDIRECT_URI=http://localhost:3001/credentials
2 changes: 1 addition & 1 deletion apps/dashboard/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
VITE_API_URL=https://api.bandada.pse.dev
VITE_CLIENT_URL=https://client.bandada.pse.dev
VITE_CLIENT_INVITES_URL=https://client.bandada.pse.dev?inviteCode=\
VITE_ETHEREUM_NETWORK=goerli
VITE_ETHEREUM_NETWORK=sepolia
VITE_GITHUB_CLIENT_ID=6ccd7b93e84260e353f9
VITE_TWITTER_CLIENT_ID=NV82Mm85NWlSZ1llZkpLMl9vN3A6MTpjaQ
VITE_TWITTER_REDIRECT_URI=https://bandada.pse.dev/credentials
2 changes: 1 addition & 1 deletion apps/dashboard/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
VITE_API_URL=https://api-staging.bandada.pse.dev
VITE_CLIENT_URL=https://client-staging.bandada.pse.dev
VITE_CLIENT_INVITES_URL=https://client-staging.bandada.pse.dev?inviteCode=\
VITE_ETHEREUM_NETWORK=goerli
VITE_ETHEREUM_NETWORK=sepolia
VITE_GITHUB_CLIENT_ID=6ccd7b93e84260e353f9
VITE_TWITTER_CLIENT_ID=NV82Mm85NWlSZ1llZkpLMl9vN3A6MTpjaQ
VITE_TWITTER_REDIRECT_URI=https://staging.bandada.pse.dev/credentials
35 changes: 35 additions & 0 deletions apps/dashboard/src/api/semaphoreAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,38 @@ export async function getGroup(groupId: string): Promise<Group | null> {
return null
}
}

/**
* It returns the Semaphore on-chain groups on Goerli for a specific admin.
* @param adminAddress The admin address.
* @returns The list of groups.
*/
export async function getGoerliGroups(
adminAddress: string
): Promise<Group[] | null> {
const goerliSubgraph = new SemaphoreSubgraph("goerli")

try {
const groups = await goerliSubgraph.getGroups({
members: true,
filters: { admin: adminAddress }
})

return groups.map((group) => {
const groupName = parseGroupName(group.id)

return {
id: group.id,
name: groupName,
treeDepth: group.merkleTree.depth,
members: group.members as string[],
admin: group.admin as string,
type: "on-chain"
}
})
} catch (error) {
console.error(error)

return null
}
}
4 changes: 2 additions & 2 deletions apps/dashboard/src/components/add-member-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ ${memberIds.join("\n")}
}

try {
const semaphore = getSemaphoreContract("goerli", signer as any)
const semaphore = getSemaphoreContract("sepolia", signer as any)

await semaphore.addMembers(group.name, memberIds)

setIsLoading(false)
onClose(memberIds)
} catch (error) {
alert(
"Some error occurred! Check if you're on Goerli network and the transaction is signed and completed"
"Some error occurred! Check if you're on Sepolia network and the transaction is signed and completed"
)

setIsLoading(false)
Expand Down
63 changes: 63 additions & 0 deletions apps/dashboard/src/components/goerli-group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
Box,
Icon,
IconButton,
Input,
InputGroup,
InputRightElement,
Text,
Tooltip,
useClipboard
} from "@chakra-ui/react"
import { FiCopy } from "react-icons/fi"

export type GoerliGroupCardProps = {
name: string
id: string
}

export default function GoerliGroupCard({
name,
id
}: GoerliGroupCardProps): JSX.Element {
const { hasCopied: hasCopiedGroupId, onCopy: onCopyGroupId } =
useClipboard(id)
return (
<Box>
<Text fontSize="20px">{name}</Text>

<InputGroup size="md" mt="10px">
<Input
pr="50px"
placeholder="Group ID"
value={id}
isDisabled
borderColor="balticSea.500"
_hover={{ borderColor: "balticSea.500" }}
/>

<InputRightElement mr="5px">
<Tooltip
label={hasCopiedGroupId ? "Copied!" : "Copy"}
closeOnClick={false}
hasArrow
>
<IconButton
variant="link"
aria-label="Copy Group id"
onClick={onCopyGroupId}
onMouseDown={(e) => e.preventDefault()}
icon={
<Icon
color="sunsetOrange.600"
boxSize="5"
as={FiCopy}
/>
}
/>
</Tooltip>
</InputRightElement>
</InputGroup>
</Box>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function FinalPreviewStep({
if (group.type === "on-chain" && signer) {
setLoading(true)
try {
const semaphore = getSemaphoreContract("goerli", signer as any)
const semaphore = getSemaphoreContract("sepolia", signer as any)
const admin = await signer.getAddress()

await semaphore.createGroup(group.name, group.treeDepth, admin)
Expand All @@ -35,7 +35,7 @@ export default function FinalPreviewStep({
} catch (error) {
setLoading(false)
alert(
"Some error occurred! Check if you're on Goerli network and the transaction is signed and completed"
"Some error occurred! Check if you're on Sepolia network and the transaction is signed and completed"
)

console.error(error)
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/context/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import React, { ReactNode, useEffect, useMemo, useState } from "react"
import { SiweMessage } from "siwe"
import { configureChains, createClient, WagmiConfig } from "wagmi"
import { goerli } from "wagmi/chains"
import { sepolia } from "wagmi/chains"
import { publicProvider } from "wagmi/providers/public"
import { getNonce, logOut, signIn } from "../api/bandadaAPI"
import useSessionData from "../hooks/use-session-data"
Expand Down Expand Up @@ -83,7 +83,7 @@ export function AuthContextProvider({ children }: { children: ReactNode }) {
)

const { chains, provider, webSocketProvider } = configureChains(
[goerli],
[sepolia],
[publicProvider()]
)

Expand Down
Loading

0 comments on commit 03549d0

Please sign in to comment.