Skip to content

Commit ee6b2bf

Browse files
committed
chore: add cmc decimal representation
1 parent add1428 commit ee6b2bf

File tree

1 file changed

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

1 file changed

+12
-2
lines changed

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

Lines changed: 12 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,17 @@ 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
41+
? tokensToString(circulatingSupply)
42+
: Number(circulatingSupply)
43+
);
3844
} else {
3945
const pythMint = await stakingClient.getPythTokenMint();
40-
return Response.json(Number(pythMint.supply));
46+
return Response.json(
47+
asDecimal
48+
? tokensToString(pythMint.supply)
49+
: Number(pythMint.supply)
50+
);
4151
}
4252
}

0 commit comments

Comments
 (0)