Skip to content
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

added circulating page #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions helper/eth/contracts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ export const getGHSTSupply = async () => {

// totalSupply == circulating Supply
// need to readd subtracted burned amount
const totalSupply = mainnet.totalSupply.add(burned);
const totalSupply = mainnet.totalSupply;
const circulatingSupply = totalSupply.sub(burned);

return {
totalSupply: formatEther(totalSupply),
burned: formatEther(burned),
circulatingSupply: formatEther(totalSupply),
circulatingSupply: formatEther(circulatingSupply),
};
};
38 changes: 38 additions & 0 deletions pages/api/[symbol]/circulating.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { NextApiRequest, NextApiResponse } from "next";
import {
ALCHEMICA_CONTRACTS,
TokenSymbol,
} from "../../../helper/eth/contracts/constants";
import {
getGHSTSupply,
getSupplies,
} from "../../../helper/eth/contracts/utils";

type Data = {
symbol?: TokenSymbol;
name?: TokenSymbol;
error?: string;
};

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const { symbol }: Data = req.query;
if (typeof symbol != "string") {
return res
.status(400)
.json({ error: "Please provide Token name as string" });
}

const data =
symbol == TokenSymbol.GHST
? await getGHSTSupply()
: await getSupplies(ALCHEMICA_CONTRACTS[symbol]);

if (!data) {
return res.status(404).json({ error: "token not found" });
}

res.status(200).send(data.circulatingSupply);
}