Skip to content

Commit

Permalink
support op mainnet (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding authored Sep 4, 2024
1 parent 69bed39 commit dc3f1d9
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
8 changes: 5 additions & 3 deletions packages/backend/src/account.ts
Original file line number Diff line number Diff line change
@@ -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()
})
3 changes: 0 additions & 3 deletions packages/backend/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
16 changes: 16 additions & 0 deletions packages/backend/src/getNetwork.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/hats.ts
Original file line number Diff line number Diff line change
@@ -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,
})
6 changes: 6 additions & 0 deletions packages/interface/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
};

Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit dc3f1d9

Please sign in to comment.