From f0972ae6831d686b619e69ad268f4c5574b0e096 Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Fri, 27 Sep 2024 10:05:10 +0200 Subject: [PATCH 1/2] fix: use DRPC private url in gnosis --- .env.template | 1 + .github/workflows/checks.yml | 1 + app/api/rpc/[chain]/route.ts | 8 +++++++- lib/modules/web3/ChainConfig.tsx | 7 ++++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.env.template b/.env.template index 5d2af7054..a2a29bb54 100644 --- a/.env.template +++ b/.env.template @@ -11,5 +11,6 @@ PRIVATE_CURRENCYAPI_KEY=xxx # For integration tests and rpc proxy routes (optional) NEXT_PRIVATE_ALCHEMY_KEY=xxx +NEXT_PRIVATE_DRPC_KEY=xxx diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index e257e157d..163aaaac3 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -7,6 +7,7 @@ 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: Build: diff --git a/app/api/rpc/[chain]/route.ts b/app/api/rpc/[chain]/route.ts index 190a39ed3..176a30a1d 100644 --- a/app/api/rpc/[chain]/route.ts +++ b/app/api/rpc/[chain]/route.ts @@ -7,6 +7,7 @@ type Params = { } const ALCHEMY_KEY = process.env.NEXT_PRIVATE_ALCHEMY_KEY || '' +const DRPC_KEY = process.env.NEXT_PRIVATE_DRPC_KEY || '' const chainToRpcMap: Record = { [GqlChain.Mainnet]: `https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`, @@ -18,7 +19,7 @@ const chainToRpcMap: Record = { [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://gnosis-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}`, } @@ -39,6 +40,11 @@ export async function POST(request: Request, { params: { chain } }: Params) { status: 500, }) } + if (!DRPC_KEY) { + return new Response(JSON.stringify({ error: 'NEXT_PRIVATE_DRPC_KEY is missing' }), { + status: 500, + }) + } const rpcUrl = getRpcUrl(chain) const rpcBody = await request.json() diff --git a/lib/modules/web3/ChainConfig.tsx b/lib/modules/web3/ChainConfig.tsx index db2779b1e..3f08d7507 100644 --- a/lib/modules/web3/ChainConfig.tsx +++ b/lib/modules/web3/ChainConfig.tsx @@ -40,15 +40,16 @@ export const rpcFallbacks: Record = { } const baseUrl = getBaseUrl() -const getPrivateRpcUrl = (chain: GqlChain) => `${baseUrl}/api/rpc/${chain}` - +const getPrivateRpcUrl = (chain: GqlChain) => { + return `${baseUrl}/api/rpc/${chain}` +} export const rpcOverrides: Record = { [GqlChain.Mainnet]: getPrivateRpcUrl(GqlChain.Mainnet), [GqlChain.Arbitrum]: getPrivateRpcUrl(GqlChain.Arbitrum), [GqlChain.Base]: getPrivateRpcUrl(GqlChain.Base), [GqlChain.Avalanche]: getPrivateRpcUrl(GqlChain.Avalanche), [GqlChain.Fantom]: getPrivateRpcUrl(GqlChain.Fantom), - [GqlChain.Gnosis]: 'https://rpc.gnosischain.com', // Temporary fix until we fix an alchemy rpc url issue (Reverted incorrect sender) + [GqlChain.Gnosis]: getPrivateRpcUrl(GqlChain.Gnosis), [GqlChain.Optimism]: getPrivateRpcUrl(GqlChain.Optimism), [GqlChain.Polygon]: getPrivateRpcUrl(GqlChain.Polygon), [GqlChain.Zkevm]: getPrivateRpcUrl(GqlChain.Zkevm), From 3152713056def283c24ce67f276b1d22be72abe8 Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Fri, 27 Sep 2024 10:08:09 +0200 Subject: [PATCH 2/2] chore: remove braces --- lib/modules/web3/ChainConfig.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/modules/web3/ChainConfig.tsx b/lib/modules/web3/ChainConfig.tsx index 3f08d7507..22148f344 100644 --- a/lib/modules/web3/ChainConfig.tsx +++ b/lib/modules/web3/ChainConfig.tsx @@ -40,9 +40,8 @@ export const rpcFallbacks: Record = { } const baseUrl = getBaseUrl() -const getPrivateRpcUrl = (chain: GqlChain) => { - return `${baseUrl}/api/rpc/${chain}` -} +const getPrivateRpcUrl = (chain: GqlChain) => `${baseUrl}/api/rpc/${chain}` + export const rpcOverrides: Record = { [GqlChain.Mainnet]: getPrivateRpcUrl(GqlChain.Mainnet), [GqlChain.Arbitrum]: getPrivateRpcUrl(GqlChain.Arbitrum),