Skip to content
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
26 changes: 17 additions & 9 deletions apps/staking/src/app/api/stake-accounts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ const ResponseSchema = z.array(
}),
);

const stakingClient = new PythStakingClient({
connection: new Connection(
RPC ??
clusterApiUrl(
IS_MAINNET ? WalletAdapterNetwork.Mainnet : WalletAdapterNetwork.Devnet,
),
),
});

const isValidPublicKey = (publicKey: string) => {
try {
new PublicKey(publicKey);
Expand All @@ -43,6 +34,23 @@ const isValidPublicKey = (publicKey: string) => {
};

export async function GET(req: NextRequest) {
const stakingClient = new PythStakingClient({
connection: new Connection(
RPC ??
clusterApiUrl(
IS_MAINNET
? WalletAdapterNetwork.Mainnet
: WalletAdapterNetwork.Devnet,
),
{
httpHeaders: {
Origin: req.nextUrl.origin,
"User-Agent": req.headers.get("User-Agent") ?? "",
},
},
),
});

const owner = req.nextUrl.searchParams.get("owner");

if (owner === null || !isValidPublicKey(owner)) {
Expand Down
26 changes: 17 additions & 9 deletions apps/staking/src/app/api/supply/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ import { z } from "zod";

import { IS_MAINNET, RPC } from "../../../config/server";

const stakingClient = new PythStakingClient({
connection: new Connection(
RPC ??
clusterApiUrl(
IS_MAINNET ? WalletAdapterNetwork.Mainnet : WalletAdapterNetwork.Devnet,
),
),
});

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

export async function GET(req: NextRequest) {
const stakingClient = new PythStakingClient({
connection: new Connection(
RPC ??
clusterApiUrl(
IS_MAINNET
? WalletAdapterNetwork.Mainnet
: WalletAdapterNetwork.Devnet,
),
{
httpHeaders: {
Origin: req.nextUrl.origin,
"User-Agent": req.headers.get("User-Agent") ?? "",
},
},
),
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extract this to something shared so you can reduce the duplication?


const query = querySchema.safeParse(req.nextUrl.searchParams.get("q"));
if (!query.success) {
return Response.json(
Expand Down
Loading