Skip to content

Commit

Permalink
chore: add cmc decimal representation
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos authored and cprussin committed Jan 22, 2025
1 parent 9e33560 commit a7104a8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apps/staking/src/app/api/v1/cmc/supply/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import type { NextRequest } from "next/server";
import { z } from "zod";

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

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

export async function GET(req: NextRequest) {
const isMainnet = req.nextUrl.searchParams.get("devnet") !== "true";
const asDecimal = req.nextUrl.searchParams.get("as_decimal") === "true";
const stakingClient = new PythStakingClient({
connection: new Connection(
isMainnet && MAINNET_API_RPC !== undefined
Expand All @@ -34,9 +36,13 @@ export async function GET(req: NextRequest) {

if (q === "circulatingSupply") {
const circulatingSupply = await stakingClient.getCirculatingSupply();
return Response.json(Number(circulatingSupply));
return Response.json(
asDecimal ? tokensToString(circulatingSupply) : Number(circulatingSupply),
);
} else {
const pythMint = await stakingClient.getPythTokenMint();
return Response.json(Number(pythMint.supply));
return Response.json(
asDecimal ? tokensToString(pythMint.supply) : Number(pythMint.supply),
);
}
}

0 comments on commit a7104a8

Please sign in to comment.