Skip to content

Commit

Permalink
Merge pull request #2168 from cprussin/use-separate-rpc-url-for-backe…
Browse files Browse the repository at this point in the history
…nd-requests

chore(staking): use a separate rpc URL for api routes
  • Loading branch information
cprussin authored Dec 4, 2024
2 parents 9c49daf + 283ec6c commit 1ca8d79
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
12 changes: 3 additions & 9 deletions apps/staking/src/app/api/v1/cmc/supply/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ import { clusterApiUrl, Connection } from "@solana/web3.js";
import type { NextRequest } from "next/server";
import { z } from "zod";

import { MAINNET_RPC } from "../../../../../config/server";
import { MAINNET_API_RPC } from "../../../../../config/server";

const querySchema = z.enum(["totalSupply", "circulatingSupply"]);

export async function GET(req: NextRequest) {
const isMainnet = req.nextUrl.searchParams.get("devnet") !== "true";
const stakingClient = new PythStakingClient({
connection: new Connection(
isMainnet && MAINNET_RPC !== undefined
? MAINNET_RPC
isMainnet && MAINNET_API_RPC !== undefined
? MAINNET_API_RPC
: clusterApiUrl(WalletAdapterNetwork.Devnet),
{
httpHeaders: {
Origin: req.nextUrl.origin,
"User-Agent": req.headers.get("User-Agent") ?? "",
},
},
),
});

Expand Down
12 changes: 3 additions & 9 deletions apps/staking/src/app/api/v1/locked_accounts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js";
import type { NextRequest } from "next/server";
import { z } from "zod";

import { MAINNET_RPC } from "../../../../config/server";
import { MAINNET_API_RPC } from "../../../../config/server";
import { tokensToString } from "../../../../tokens";

const UnlockScheduleSchema = z.object({
Expand Down Expand Up @@ -38,15 +38,9 @@ export async function GET(req: NextRequest) {
const isMainnet = req.nextUrl.searchParams.get("devnet") !== "true";
const stakingClient = new PythStakingClient({
connection: new Connection(
isMainnet && MAINNET_RPC !== undefined
? MAINNET_RPC
isMainnet && MAINNET_API_RPC !== undefined
? MAINNET_API_RPC
: clusterApiUrl(WalletAdapterNetwork.Devnet),
{
httpHeaders: {
Origin: req.nextUrl.origin,
"User-Agent": req.headers.get("User-Agent") ?? "",
},
},
),
});

Expand Down
2 changes: 2 additions & 0 deletions apps/staking/src/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const WALLETCONNECT_PROJECT_ID = demandInProduction(
"WALLETCONNECT_PROJECT_ID",
);
export const MAINNET_RPC = process.env.MAINNET_RPC;
export const MAINNET_API_RPC =
process.env.MAINNET_API_RPC ?? process.env.MAINNET_RPC;
export const PYTHNET_RPC = getOr("PYTHNET_RPC", "https://pythnet.rpcpool.com");
export const HERMES_URL = getOr("HERMES_URL", "https://hermes.pyth.network");
export const BLOCKED_REGIONS = transformOr("BLOCKED_REGIONS", fromCsv, []);
Expand Down
1 change: 1 addition & 0 deletions apps/staking/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"WALLETCONNECT_PROJECT_ID",
"PROXYCHECK_API_KEY",
"MAINNET_RPC",
"MAINNET_API_RPC",
"BLOCKED_REGIONS",
"AMPLITUDE_API_KEY",
"GOOGLE_ANALYTICS_ID"
Expand Down

0 comments on commit 1ca8d79

Please sign in to comment.