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

Commit fe5044e

Browse files
authored
chore: migrate to dRPC (#1138)
* chore: migrate to dRPC * chore: disable foundry cache in GHA
1 parent c0f1936 commit fe5044e

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

.env.template

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ PRIVATE_HYPERNATIVE_API_SECRET=xxx
1010
PRIVATE_CURRENCYAPI_KEY=xxx
1111

1212
# For integration tests and rpc proxy routes (optional)
13-
NEXT_PRIVATE_ALCHEMY_KEY=xxx
1413
NEXT_PRIVATE_DRPC_KEY=xxx
1514

1615

.github/workflows/checks.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
env:
77
NEXT_PUBLIC_BALANCER_API_URL: https://api-v3.balancer.fi/graphql
88
NEXT_PUBLIC_WALLET_CONNECT_ID: ${{ secrets.NEXT_PUBLIC_WALLET_CONNECT_ID }}
9-
NEXT_PRIVATE_ALCHEMY_KEY: ${{ secrets.PRIVATE_ALCHEMY_KEY }}
109
NEXT_PRIVATE_DRPC_KEY: ${{ secrets.PRIVATE_DRPC_KEY }}
1110

1211
jobs:
@@ -53,5 +52,7 @@ jobs:
5352
uses: ./.github/actions/setup
5453
- name: Set up foundry (includes anvil)
5554
uses: foundry-rs/foundry-toolchain@v1
55+
with:
56+
cache: false
5657
- name: Run integration tests
5758
run: pnpm test:integration

app/api/rpc/[chain]/route.ts

+14-18
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ type Params = {
66
}
77
}
88

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

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

2728
function getRpcUrl(chain: string) {
@@ -35,11 +36,6 @@ function getRpcUrl(chain: string) {
3536
}
3637

3738
export async function POST(request: Request, { params: { chain } }: Params) {
38-
if (!ALCHEMY_KEY) {
39-
return new Response(JSON.stringify({ error: 'NEXT_PRIVATE_ALCHEMY_KEY is missing' }), {
40-
status: 500,
41-
})
42-
}
4339
if (!DRPC_KEY) {
4440
return new Response(JSON.stringify({ error: 'NEXT_PRIVATE_DRPC_KEY is missing' }), {
4541
status: 500,

test/anvil/anvil-setup.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,19 @@ export function getTestRpcSetup(networkName: NetworksWithFork) {
8484
}
8585

8686
export function getForkUrl(network: NetworkSetup, verbose = false): string {
87-
const privateAlchemyKey = process.env['NEXT_PRIVATE_ALCHEMY_KEY']
88-
if (privateAlchemyKey) {
87+
const privateKey = process.env['NEXT_PRIVATE_DRPC_KEY']
88+
const dRpcUrl = (chainName: string) =>
89+
`https://lb.drpc.org/ogrpc?network=${chainName}&dkey=${privateKey}`
90+
91+
if (privateKey) {
8992
if (network.networkName === 'Ethereum') {
90-
return `https://eth-mainnet.g.alchemy.com/v2/${privateAlchemyKey}`
93+
return dRpcUrl('ethereum')
9194
}
9295
if (network.networkName === 'Polygon') {
93-
return `https://polygon-mainnet.g.alchemy.com/v2/${privateAlchemyKey}`
96+
return dRpcUrl('polygon')
9497
}
9598
if (network.networkName === 'Sepolia') {
96-
return `https://eth-sepolia.g.alchemy.com/v2/${privateAlchemyKey}`
99+
return dRpcUrl('sepolia')
97100
}
98101
}
99102

0 commit comments

Comments
 (0)