Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

chore: migrate to dRPC #1138

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ PRIVATE_HYPERNATIVE_API_SECRET=xxx
PRIVATE_CURRENCYAPI_KEY=xxx

# For integration tests and rpc proxy routes (optional)
NEXT_PRIVATE_ALCHEMY_KEY=xxx
NEXT_PRIVATE_DRPC_KEY=xxx


3 changes: 2 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
env:
NEXT_PUBLIC_BALANCER_API_URL: https://api-v3.balancer.fi/graphql
NEXT_PUBLIC_WALLET_CONNECT_ID: ${{ secrets.NEXT_PUBLIC_WALLET_CONNECT_ID }}
NEXT_PRIVATE_ALCHEMY_KEY: ${{ secrets.PRIVATE_ALCHEMY_KEY }}
NEXT_PRIVATE_DRPC_KEY: ${{ secrets.PRIVATE_DRPC_KEY }}

jobs:
Expand Down Expand Up @@ -53,5 +52,7 @@ jobs:
uses: ./.github/actions/setup
- name: Set up foundry (includes anvil)
uses: foundry-rs/foundry-toolchain@v1
with:
cache: false
- name: Run integration tests
run: pnpm test:integration
32 changes: 14 additions & 18 deletions app/api/rpc/[chain]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ type Params = {
}
}

const ALCHEMY_KEY = process.env.NEXT_PRIVATE_ALCHEMY_KEY || ''
const DRPC_KEY = process.env.NEXT_PRIVATE_DRPC_KEY || ''
const dRpcUrl = (chainName: string) =>
`https://lb.drpc.org/ogrpc?network=${chainName}&dkey=${DRPC_KEY}`

const chainToRpcMap: Record<GqlChain, string | undefined> = {
[GqlChain.Mainnet]: `https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Arbitrum]: `https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Optimism]: `https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Base]: `https://base-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Polygon]: `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Avalanche]: `https://avax-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Fantom]: `https://fantom-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Sepolia]: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Fraxtal]: `https://frax-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Gnosis]: `https://lb.drpc.org/ogrpc?network=gnosis&dkey=${DRPC_KEY}`,
[GqlChain.Mode]: undefined,
[GqlChain.Zkevm]: `https://polygonzkevm-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`,
[GqlChain.Mainnet]: dRpcUrl('ethereum'),
[GqlChain.Arbitrum]: dRpcUrl('arbitrum'),
[GqlChain.Optimism]: dRpcUrl('optimism'),
[GqlChain.Base]: dRpcUrl('base'),
[GqlChain.Polygon]: dRpcUrl('polygon'),
[GqlChain.Avalanche]: dRpcUrl('avalanche'),
[GqlChain.Fantom]: dRpcUrl('fantom'),
[GqlChain.Sepolia]: dRpcUrl('sepolia'),
[GqlChain.Fraxtal]: dRpcUrl('fraxtal'),
[GqlChain.Gnosis]: dRpcUrl('gnosis'),
[GqlChain.Mode]: dRpcUrl('mode'),
[GqlChain.Zkevm]: dRpcUrl('polygon-zkevm'),
}

function getRpcUrl(chain: string) {
Expand All @@ -35,11 +36,6 @@ function getRpcUrl(chain: string) {
}

export async function POST(request: Request, { params: { chain } }: Params) {
if (!ALCHEMY_KEY) {
return new Response(JSON.stringify({ error: 'NEXT_PRIVATE_ALCHEMY_KEY is missing' }), {
status: 500,
})
}
if (!DRPC_KEY) {
return new Response(JSON.stringify({ error: 'NEXT_PRIVATE_DRPC_KEY is missing' }), {
status: 500,
Expand Down
13 changes: 8 additions & 5 deletions test/anvil/anvil-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,19 @@ export function getTestRpcSetup(networkName: NetworksWithFork) {
}

export function getForkUrl(network: NetworkSetup, verbose = false): string {
const privateAlchemyKey = process.env['NEXT_PRIVATE_ALCHEMY_KEY']
if (privateAlchemyKey) {
const privateKey = process.env['NEXT_PRIVATE_DRPC_KEY']
const dRpcUrl = (chainName: string) =>
`https://lb.drpc.org/ogrpc?network=${chainName}&dkey=${privateKey}`

if (privateKey) {
if (network.networkName === 'Ethereum') {
return `https://eth-mainnet.g.alchemy.com/v2/${privateAlchemyKey}`
return dRpcUrl('ethereum')
}
if (network.networkName === 'Polygon') {
return `https://polygon-mainnet.g.alchemy.com/v2/${privateAlchemyKey}`
return dRpcUrl('polygon')
}
if (network.networkName === 'Sepolia') {
return `https://eth-sepolia.g.alchemy.com/v2/${privateAlchemyKey}`
return dRpcUrl('sepolia')
}
}

Expand Down
Loading