From e679c3b50db4be8fa1a55dd3228d2ecd6a78bc49 Mon Sep 17 00:00:00 2001 From: Marcin Ciarka Date: Fri, 31 Jan 2025 14:33:23 +0100 Subject: [PATCH 1/2] Remove temporary mainnet RPC and subgraph environment variables --- .env.template | 2 -- .../earn-protocol/app/api/rpcGateway/route.ts | 7 ++-- .../server-handlers/position-history/index.ts | 34 +++++++++++-------- apps/earn-protocol/docker/Dockerfile | 4 --- turbo.json | 2 -- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/.env.template b/.env.template index 3453fdeecb..65e249eea0 100644 --- a/.env.template +++ b/.env.template @@ -20,8 +20,6 @@ MIXPANEL_LOG= MIXPANEL_ENV= MIXPANEL_KEY= NEXT_PUBLIC_MIXPANEL_KEY= -TEMPORARY_MAINNET_SUBGRAPH= -TEMPORARY_MAINNET_RPC= # disables the swap widget (empty component) to speed up dev NEXT_PUBLIC_SWAP_WIDGET_ONBOARDING_HIDDEN= # disables all but metamask wallets to speed up dev diff --git a/apps/earn-protocol/app/api/rpcGateway/route.ts b/apps/earn-protocol/app/api/rpcGateway/route.ts index ba781958dd..eb83ed82eb 100644 --- a/apps/earn-protocol/app/api/rpcGateway/route.ts +++ b/apps/earn-protocol/app/api/rpcGateway/route.ts @@ -1,4 +1,4 @@ -import { NetworkNames } from '@summerfi/app-types' +import { type NetworkNames } from '@summerfi/app-types' import { type NextRequest, NextResponse } from 'next/server' import { REVALIDATION_TIMES } from '@/constants/revalidations' @@ -17,10 +17,7 @@ export async function POST(req: NextRequest) { } const networkName = networkQuery.toString() as NetworkNames - const rpcGatewayUrl = - networkName === NetworkNames.ethereumMainnet && process.env.TEMPORARY_MAINNET_RPC - ? process.env.TEMPORARY_MAINNET_RPC - : await getRpcGatewayUrl(networkName) + const rpcGatewayUrl = await getRpcGatewayUrl(networkName) if (!rpcGatewayUrl) { return NextResponse.json({ error: 'Invalid network or RPC Config is missing' }, { status: 400 }) diff --git a/apps/earn-protocol/app/server-handlers/position-history/index.ts b/apps/earn-protocol/app/server-handlers/position-history/index.ts index 25e724e35c..587d9024e5 100644 --- a/apps/earn-protocol/app/server-handlers/position-history/index.ts +++ b/apps/earn-protocol/app/server-handlers/position-history/index.ts @@ -29,24 +29,28 @@ export async function getPositionHistory({ network, address, vault }: GetPositio }, }) + const subgraphsMap = process.env.NEXT_PUBLIC_IS_PRE_LAUNCH_VERSION + ? { + [SDKNetwork.Mainnet]: `${process.env.SUBGRAPH_BASE}/summer-protocol/version/1.0.0-test-deployment/api`, + [SDKNetwork.Base]: `${process.env.SUBGRAPH_BASE}/summer-protocol-base/version/1.0.0-test-deployment/api`, + [SDKNetwork.ArbitrumOne]: `${process.env.SUBGRAPH_BASE}/summer-protocol-arbitrum/version/1.0.0-test-deployment/api`, + } + : { + [SDKNetwork.Mainnet]: `${process.env.SUBGRAPH_BASE}/summer-protocol`, + [SDKNetwork.Base]: `${process.env.SUBGRAPH_BASE}/summer-protocol-base`, + [SDKNetwork.ArbitrumOne]: `${process.env.SUBGRAPH_BASE}/summer-protocol-arbitrum`, + } + const clients = { - [SDKNetwork.Mainnet]: new GraphQLClient( - process.env.TEMPORARY_MAINNET_SUBGRAPH - ? process.env.TEMPORARY_MAINNET_SUBGRAPH - : `${process.env.SUBGRAPH_BASE}/summer-protocol`, - { - fetch: customFetchCache, - }, - ), - [SDKNetwork.Base]: new GraphQLClient(`${process.env.SUBGRAPH_BASE}/summer-protocol-base`, { + [SDKNetwork.Mainnet]: new GraphQLClient(subgraphsMap[SDKNetwork.Mainnet], { + fetch: customFetchCache, + }), + [SDKNetwork.Base]: new GraphQLClient(subgraphsMap[SDKNetwork.Base], { + fetch: customFetchCache, + }), + [SDKNetwork.ArbitrumOne]: new GraphQLClient(subgraphsMap[SDKNetwork.ArbitrumOne], { fetch: customFetchCache, }), - [SDKNetwork.ArbitrumOne]: new GraphQLClient( - `${process.env.SUBGRAPH_BASE}/summer-protocol-arbitrum`, - { - fetch: customFetchCache, - }, - ), } const isProperNetwork = (net: string): net is keyof typeof clients => net in clients diff --git a/apps/earn-protocol/docker/Dockerfile b/apps/earn-protocol/docker/Dockerfile index 8850aab34f..7faf6fcf24 100644 --- a/apps/earn-protocol/docker/Dockerfile +++ b/apps/earn-protocol/docker/Dockerfile @@ -16,8 +16,6 @@ ARG FUNCTIONS_API_URL \ CONFIG_URL_RAYS \ EARN_MIXPANEL_KEY \ SUBGRAPH_BASE \ - TEMPORARY_MAINNET_SUBGRAPH \ - TEMPORARY_MAINNET_RPC \ NEXT_PUBLIC_EARN_MIXPANEL_KEY \ SDK_API_URL \ ACCOUNT_KIT_API_KEY \ @@ -48,8 +46,6 @@ ENV FUNCTIONS_API_URL=$FUNCTIONS_API_URL \ CONFIG_URL_RAYS=$CONFIG_URL_RAYS \ EARN_MIXPANEL_KEY=$EARN_MIXPANEL_KEY \ SUBGRAPH_BASE=$SUBGRAPH_BASE \ - TEMPORARY_MAINNET_SUBGRAPH=$TEMPORARY_MAINNET_SUBGRAPH \ - TEMPORARY_MAINNET_RPC=$TEMPORARY_MAINNET_RPC \ NEXT_PUBLIC_EARN_MIXPANEL_KEY=$NEXT_PUBLIC_EARN_MIXPANEL_KEY \ SDK_API_URL=$SDK_API_URL \ ACCOUNT_KIT_API_KEY=$ACCOUNT_KIT_API_KEY \ diff --git a/turbo.json b/turbo.json index aca77a6442..4d3fa46ebe 100644 --- a/turbo.json +++ b/turbo.json @@ -3,8 +3,6 @@ "globalDependencies": ["**/.env.*local"], "globalEnv": [ "SUBGRAPH_BASE", - "TEMPORARY_MAINNET_SUBGRAPH", - "TEMPORARY_MAINNET_RPC", "DEBANK_API_KEY", "DEBANK_API_URL", "RPC_GATEWAY", From 00a9889d431e86c117755d1ed697097f4bcad31b Mon Sep 17 00:00:00 2001 From: Marcin Ciarka Date: Fri, 31 Jan 2025 14:43:43 +0100 Subject: [PATCH 2/2] Refactor getPositionHistory to streamline subgraph client initialization and improve network validation --- .../server-handlers/position-history/index.ts | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/apps/earn-protocol/app/server-handlers/position-history/index.ts b/apps/earn-protocol/app/server-handlers/position-history/index.ts index 587d9024e5..d40a4afe32 100644 --- a/apps/earn-protocol/app/server-handlers/position-history/index.ts +++ b/apps/earn-protocol/app/server-handlers/position-history/index.ts @@ -31,35 +31,25 @@ export async function getPositionHistory({ network, address, vault }: GetPositio const subgraphsMap = process.env.NEXT_PUBLIC_IS_PRE_LAUNCH_VERSION ? { - [SDKNetwork.Mainnet]: `${process.env.SUBGRAPH_BASE}/summer-protocol/version/1.0.0-test-deployment/api`, - [SDKNetwork.Base]: `${process.env.SUBGRAPH_BASE}/summer-protocol-base/version/1.0.0-test-deployment/api`, - [SDKNetwork.ArbitrumOne]: `${process.env.SUBGRAPH_BASE}/summer-protocol-arbitrum/version/1.0.0-test-deployment/api`, - } - : { [SDKNetwork.Mainnet]: `${process.env.SUBGRAPH_BASE}/summer-protocol`, [SDKNetwork.Base]: `${process.env.SUBGRAPH_BASE}/summer-protocol-base`, [SDKNetwork.ArbitrumOne]: `${process.env.SUBGRAPH_BASE}/summer-protocol-arbitrum`, } + : { + [SDKNetwork.Mainnet]: `${process.env.SUBGRAPH_BASE}/summer-protocol/version/1.0.0-test-deployment/api`, + [SDKNetwork.Base]: `${process.env.SUBGRAPH_BASE}/summer-protocol-base/version/1.0.0-test-deployment/api`, + [SDKNetwork.ArbitrumOne]: `${process.env.SUBGRAPH_BASE}/summer-protocol-arbitrum/version/1.0.0-test-deployment/api`, + } - const clients = { - [SDKNetwork.Mainnet]: new GraphQLClient(subgraphsMap[SDKNetwork.Mainnet], { - fetch: customFetchCache, - }), - [SDKNetwork.Base]: new GraphQLClient(subgraphsMap[SDKNetwork.Base], { - fetch: customFetchCache, - }), - [SDKNetwork.ArbitrumOne]: new GraphQLClient(subgraphsMap[SDKNetwork.ArbitrumOne], { - fetch: customFetchCache, - }), - } - - const isProperNetwork = (net: string): net is keyof typeof clients => net in clients + const isProperNetwork = (net: string): net is keyof typeof subgraphsMap => net in subgraphsMap if (!isProperNetwork(network)) { throw new Error(`getPositionHistory: No endpoint found for network: ${network}`) } - const networkGraphQlClient = clients[network as keyof typeof clients] + const networkGraphQlClient = new GraphQLClient(subgraphsMap[SDKNetwork.ArbitrumOne], { + fetch: customFetchCache, + }) const request = await networkGraphQlClient.request( GetPositionHistoryDocument, {