Skip to content

chore(staking): use a separate rpc URL for api routes #2168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
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
Loading