Skip to content

Commit 1647eca

Browse files
committed
feat(utils): add deployed contracts to utils package
re #715
1 parent 00f0551 commit 1647eca

File tree

21 files changed

+93
-76
lines changed

21 files changed

+93
-76
lines changed

apps/docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@docusaurus/core": "3.1.1",
1717
"@docusaurus/preset-classic": "3.1.1",
1818
"@mdx-js/react": "^3.0.0",
19+
"@semaphore-protocol/utils": "4.0.0-beta.4",
1920
"@svgr/webpack": "^5.5.0",
2021
"clsx": "^1.2.1",
2122
"docusaurus-plugin-sass": "^0.2.5",

apps/docs/src/components/DeployedContracts.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { deployedContracts } from "@semaphore-protocol/utils"
12
import Heading from "@theme/Heading"
2-
import { useEffect, useState } from "react"
33

44
function capitalizeFirstLetter(s: string): string {
55
return s.charAt(0).toUpperCase() + s.slice(1)
@@ -23,17 +23,6 @@ function getEtherscanLink(network: string): string {
2323
}
2424

2525
export default function DeployedContracts() {
26-
const [deployedContracts, setDeployedContracts] = useState<any[]>([])
27-
28-
useEffect(() => {
29-
fetch(
30-
"https://raw.githubusercontent.com/semaphore-protocol/semaphore/main/packages/contracts/deployed-contracts.json"
31-
)
32-
.then((response) => response.json())
33-
.catch(() => [])
34-
.then(setDeployedContracts)
35-
}, [])
36-
3726
return (
3827
<div>
3928
{deployedContracts.map(({ network, contracts }) => (

packages/cli/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GroupResponse, SemaphoreEthers, SemaphoreSubgraph } from "@semaphore-protocol/data"
2-
import supportedNetworks from "@semaphore-protocol/utils/supported-networks"
2+
import { supportedNetworks } from "@semaphore-protocol/utils/networks"
33
import chalk from "chalk"
44
import { program } from "commander"
55
import decompress from "decompress"

packages/contracts/deployed-contracts.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
},
1313
{
1414
"name": "Semaphore",
15-
"address": "0x5B8e7cC7bAC61A4b952d472b67056B2f260ba6dc"
15+
"address": "0x5B8e7cC7bAC61A4b952d472b67056B2f260ba6dc",
16+
"startBlock": 5150903
1617
}
1718
]
1819
}

packages/contracts/hardhat.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "@nomicfoundation/hardhat-chai-matchers"
22
import "@nomicfoundation/hardhat-ethers"
33
import "@nomicfoundation/hardhat-verify"
44
import "@openzeppelin/hardhat-upgrades"
5+
import { SupportedNetwork } from "@semaphore-protocol/utils"
56
import "@typechain/hardhat"
67
import { config as dotenvConfig } from "dotenv"
78
import "hardhat-gas-reporter"
@@ -22,7 +23,7 @@ function getNetworks(): NetworksUserConfig {
2223
const infuraApiKey = process.env.INFURA_API_KEY
2324
const accounts = [`0x${process.env.BACKEND_PRIVATE_KEY}`]
2425

25-
return {
26+
const networks: Record<SupportedNetwork, any> = {
2627
sepolia: {
2728
url: `https://sepolia.infura.io/v3/${infuraApiKey}`,
2829
chainId: 11155111,
@@ -49,6 +50,8 @@ function getNetworks(): NetworksUserConfig {
4950
accounts
5051
}
5152
}
53+
54+
return networks
5255
}
5356

5457
const hardhatConfig: HardhatUserConfig = {

packages/contracts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@nomicfoundation/hardhat-verify": "^2.0.0",
2222
"@openzeppelin/hardhat-upgrades": "^3.0.4",
2323
"@semaphore-protocol/core": "workspace:packages/core",
24+
"@semaphore-protocol/utils": "workspace:packages/utils",
2425
"@typechain/ethers-v6": "^0.5.0",
2526
"@typechain/hardhat": "^9.0.0",
2627
"@types/chai": "^4.2.0",

packages/contracts/scripts/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
import { SupportedNetwork, supportedNetworks } from "@semaphore-protocol/utils"
12
import { readFileSync, writeFileSync } from "fs"
23

34
export type NetworkDeployedContracts = {
45
name: "Semaphore" | "SemaphoreVerifier" | "PoseidonT3"
56
address: string
7+
startBlock?: number
68
}[]
79

810
export type DeployedContracts = {
911
network: string
1012
contracts: NetworkDeployedContracts
1113
}[]
1214

13-
const supportedNetworks = ["sepolia", "arbitrum", "mumbai", "optimism-sepolia", "arbitrum-sepolia"]
14-
1515
export function getDeployedContracts(): DeployedContracts {
1616
return JSON.parse(readFileSync(`./deployed-contracts.json`, "utf8"))
1717
}
@@ -38,7 +38,7 @@ export function getDeployedContractAddress(network: string, contractName: string
3838
return semaphoreAddress.address
3939
}
4040

41-
export function saveDeployedContracts(contracts: NetworkDeployedContracts, network?: string) {
41+
export function saveDeployedContracts(contracts: NetworkDeployedContracts, network?: SupportedNetwork) {
4242
if (network && supportedNetworks.includes(network)) {
4343
const deployedContracts = getDeployedContracts() as DeployedContracts
4444

packages/contracts/tasks/deploy.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SupportedNetwork } from "@semaphore-protocol/utils"
12
import { task, types } from "hardhat/config"
23
import { saveDeployedContracts } from "../scripts/utils"
34
import { deployContract } from "./utils"
@@ -51,6 +52,8 @@ task("deploy", "Deploy a Semaphore contract")
5152
console.info(`Semaphore contract has been deployed to: ${semaphoreAddress}`)
5253
}
5354

55+
const deploymentTransaction = semaphore.deploymentTransaction()
56+
5457
saveDeployedContracts(
5558
[
5659
{
@@ -63,10 +66,14 @@ task("deploy", "Deploy a Semaphore contract")
6366
},
6467
{
6568
name: "Semaphore",
66-
address: semaphoreAddress
69+
address: semaphoreAddress,
70+
startBlock:
71+
deploymentTransaction && deploymentTransaction.blockNumber
72+
? deploymentTransaction.blockNumber
73+
: undefined
6774
}
6875
],
69-
hardhatArguments.network
76+
hardhatArguments.network as SupportedNetwork
7077
)
7178

7279
return {

packages/contracts/tasks/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ export async function deployContract(
1111

1212
if (network !== undefined && network !== "hardhat" && network !== "localhost") {
1313
contract = await defender.deployContract(contractFactory, args, { salt: process.env.CREATE2_SALT })
14-
15-
await contract.waitForDeployment()
1614
} else {
1715
contract = await contractFactory.deploy(...args)
1816
}
1917

20-
return contract
18+
return contract.waitForDeployment()
2119
}

packages/data/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"rollup-plugin-cleanup": "^3.2.1"
3838
},
3939
"dependencies": {
40+
"@semaphore-protocol/utils": "4.0.0-beta.4",
4041
"axios": "1.6.6",
4142
"ethers": "6.11.0"
4243
}

0 commit comments

Comments
 (0)