diff --git a/helper/eth/contracts/utils.ts b/helper/eth/contracts/utils.ts index 0644ef9..d7de43a 100644 --- a/helper/eth/contracts/utils.ts +++ b/helper/eth/contracts/utils.ts @@ -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), }; }; diff --git a/pages/api/[symbol]/circulating.ts b/pages/api/[symbol]/circulating.ts new file mode 100644 index 0000000..5848187 --- /dev/null +++ b/pages/api/[symbol]/circulating.ts @@ -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 +) { + 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); +}