Skip to content

Commit a7104a8

Browse files
guibescoscprussin
authored andcommitted
chore: add cmc decimal representation
1 parent 9e33560 commit a7104a8

File tree

1 file changed

+8
-2
lines changed
  • apps/staking/src/app/api/v1/cmc/supply

1 file changed

+8
-2
lines changed

apps/staking/src/app/api/v1/cmc/supply/route.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import type { NextRequest } from "next/server";
55
import { z } from "zod";
66

77
import { MAINNET_API_RPC } from "../../../../../config/server";
8+
import { tokensToString } from "../../../../../tokens";
89

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

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

3537
if (q === "circulatingSupply") {
3638
const circulatingSupply = await stakingClient.getCirculatingSupply();
37-
return Response.json(Number(circulatingSupply));
39+
return Response.json(
40+
asDecimal ? tokensToString(circulatingSupply) : Number(circulatingSupply),
41+
);
3842
} else {
3943
const pythMint = await stakingClient.getPythTokenMint();
40-
return Response.json(Number(pythMint.supply));
44+
return Response.json(
45+
asDecimal ? tokensToString(pythMint.supply) : Number(pythMint.supply),
46+
);
4147
}
4248
}

0 commit comments

Comments
 (0)