Skip to content

Commit

Permalink
Added COIN_DECIMALS variable
Browse files Browse the repository at this point in the history
  • Loading branch information
zenodeapp committed Dec 12, 2023
1 parent 3857908 commit 968bb33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PORT=3000
API_ENDPOINT=https://api.network
COIN_DENOM=uatom
COIN_DENOM=uatom
COIN_DECIMALS=6
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require("dotenv").config();
const app = express();
const API = process.env.API_ENDPOINT;
const PORT = process.env.PORT || 3000;
const DIVIDE_BY = `1e${process.env.COIN_DECIMALS || 1}`;

async function fetchData(endpoint) {
try {
Expand All @@ -20,15 +21,15 @@ async function fetchTotalSupply() {
const data = await fetchData(
`/cosmos/bank/v1beta1/supply/${process.env.COIN_DENOM}`
);
return data.amount.amount;
return data.amount.amount / DIVIDE_BY;
}

async function fetchCirculatingSupply() {
const communityPool = (
await fetchData("/cosmos/distribution/v1beta1/community_pool")
).pool[0].amount;
const totalSupply = await fetchTotalSupply();
return totalSupply - communityPool;
return totalSupply - communityPool / DIVIDE_BY;
}

app.get("/total-supply", async (_, res) => {
Expand Down

0 comments on commit 968bb33

Please sign in to comment.