diff --git a/package.json b/package.json index 73f96df..682574b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "author": "PSE", "scripts": { "build": "pnpm --recursive --sort run build", - "dev:server": "pnpm --filter backend run dev", + "dev:server": "pnpm --filter backend run dev:optimism-sepolia", "start:interface": "pnpm --filter interface run start", "dev:interface": "pnpm --filter interface run dev" }, diff --git a/packages/backend/package.json b/packages/backend/package.json index 17a6abe..f61e867 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "build": "tsc", - "dev": "ts-node-dev src/index.ts" + "dev:optimism": "ts-node-dev src/index.ts --network optimism", + "dev:optimism-sepolia": "ts-node-dev src/index.ts --network optimism-sepolia" }, "keywords": [], "author": "", diff --git a/packages/backend/src/account.ts b/packages/backend/src/account.ts index 352474f..5dcdf43 100644 --- a/packages/backend/src/account.ts +++ b/packages/backend/src/account.ts @@ -1,20 +1,22 @@ import { createPublicClient, createWalletClient, http} from 'viem' import { privateKeyToAccount } from 'viem/accounts' -import { optimismSepolia } from "viem/chains" import { PRIVATE_KEY } from './constants' +import getNetwork from './getNetwork'; // create an account from the private key export const account = privateKeyToAccount(PRIVATE_KEY) +const chain = getNetwork(); + // a public client for reading data export const publicClient = createPublicClient({ - chain: optimismSepolia, + chain, transport: http() }) // a wallet client for signing transactions export const walletClient = createWalletClient({ account, - chain: optimismSepolia, + chain, transport: http() }) diff --git a/packages/backend/src/constants.ts b/packages/backend/src/constants.ts index 2f20d61..32a8d4d 100644 --- a/packages/backend/src/constants.ts +++ b/packages/backend/src/constants.ts @@ -1,10 +1,7 @@ import dotenv from 'dotenv' dotenv.config() -export const HATS_ADDRESS = "0x3bc1A0Ad72417f2d411118085256fC53CBdDd137" -export const SEMAPHORE_ADDRESS = "0x71B93f8b0583f4033FAA1EE47d448B572933cefe" export const HAT_ID = process.env.HAT_ID || "0" -export const CHAIN_ID = "11155420" export const PRIVATE_KEY = process.env.ETH_PRIVATE_KEY && process.env.ETH_PRIVATE_KEY.startsWith("0x") ? process.env.ETH_PRIVATE_KEY as `0x${string}` : `0x${process.env.ETH_PRIVATE_KEY}` as `0x${string}` export const PORT = Number.parseInt(process.env.PORT!) || 3001 export const BIND_IP = process.env.BIND_IP || "0.0.0.0" diff --git a/packages/backend/src/getNetwork.ts b/packages/backend/src/getNetwork.ts new file mode 100644 index 0000000..b0488da --- /dev/null +++ b/packages/backend/src/getNetwork.ts @@ -0,0 +1,16 @@ +import { optimism, optimismSepolia } from "viem/chains"; +import dotenv from "dotenv"; +dotenv.config(); + +export default function getNetwork() { + const network = process.argv[3]; + + switch (network) { + case "optimism": + return optimism; + case "optimism-sepolia": + return optimismSepolia; + default: + return optimismSepolia; + } +} diff --git a/packages/backend/src/hats.ts b/packages/backend/src/hats.ts index f74912d..b506df5 100644 --- a/packages/backend/src/hats.ts +++ b/packages/backend/src/hats.ts @@ -1,13 +1,13 @@ import { HatsClient } from '@hatsprotocol/sdk-v1-core' import { type PublicClient } from 'viem' -import { optimismSepolia } from "viem/chains" import { publicClient, walletClient } from './account' +import getNetwork from './getNetwork' /** * Create a write-enabled hats client */ export const hatsClient = new HatsClient({ - chainId: optimismSepolia.id, + chainId: getNetwork().id, publicClient: publicClient as unknown as PublicClient, walletClient, }) diff --git a/packages/interface/src/config.ts b/packages/interface/src/config.ts index 69bd50c..3cb828a 100644 --- a/packages/interface/src/config.ts +++ b/packages/interface/src/config.ts @@ -46,11 +46,13 @@ const easSchemaRegistryContractAddresses = { // Hats contract addresses for each chain const hatsContractAddresses = { + optimism: "0x3bc1A0Ad72417f2d411118085256fC53CBdDd137", optimismSepolia: "0x3bc1A0Ad72417f2d411118085256fC53CBdDd137", }; // Semaphore contract addresses for each chain const semaphoreContractAddresses = { + optimism: process.env.NEXT_PUBLIC_SEMAPHORE_CONTRACT_ADDRESS!, optimismSepolia: process.env.NEXT_PUBLIC_SEMAPHORE_CONTRACT_ADDRESS!, }; @@ -73,6 +75,8 @@ export const semaphoreEthersChain = (): string => { */ export const getRPCURL = (): string | undefined => { switch (process.env.NEXT_PUBLIC_CHAIN_NAME) { + case "optimism": + return `https://opt-mainnet.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_ID!}`; case "optimismSepolia": return `https://opt-sepolia.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_ID!}`; default: @@ -86,6 +90,8 @@ export const getRPCURL = (): string | undefined => { */ export const getPimlicoRPCURL = (): string | undefined => { switch (process.env.NEXT_PUBLIC_CHAIN_NAME) { + case "optimism": + return `https://api.pimlico.io/v2/optimism/rpc?apikey=${process.env.NEXT_PUBLIC_PIMLICO_API_KEY}`; case "optimismSepolia": return `https://api.pimlico.io/v2/optimism-sepolia/rpc?apikey=${process.env.NEXT_PUBLIC_PIMLICO_API_KEY}`; default: