🛠️Utility Functions

In this section, we will go over some of the essential utility functions used in the TokenSupply app. These functions facilitate tasks like fetching token supply data and calculating supply balances.

getTotalSupplyAcrossNetworks

getTotalSupplyAcrossNetworks is a utility function that retrieves the total token supply across all supported networks. It takes a NetworkConfigurations object as its input and returns an object containing the total supply as well as a breakdown of the supply for each network.

Example usage:

import { getNetworkConfigurations, getTotalSupplyAcrossNetworks } from './src/getSupplyAcrossNetworks';

async function fetchTotalSupply() {
  const networks = await getNetworkConfigurations();
  const totalSupplyData = await getTotalSupplyAcrossNetworks(networks);
  console.log(totalSupplyData);
}

fetchTotalSupply();

getNonCirculatingSupplyBalances

getNonCirculatingSupplyBalances is a utility function that fetches the non-circulating token supply balances for each specified address. It returns an array of NonCirculatingSupplyBalance objects, each containing the name, address, and token balance for a specific non-circulating supply address.

Example usage:

import { getNonCirculatingSupplyBalances } from './src/getSupplyAcrossNetworks';

async function fetchNonCirculatingBalances() {
  const nonCirculatingSupplyBalances = await getNonCirculatingSupplyBalances();
  console.log
  (nonCirculatingSupplyBalances); 
}
  
fetchNonCirculatingBalances();

calculateCirculatingSupply

calculateCirculatingSupply is a utility function that computes the circulating token supply by subtracting the non-circulating supply from the total token supply. It takes the total supply and non-circulating supply balances as inputs and returns the circulating supply as a BigNumber.

Example usage:

import { getTotalSupplyAcrossNetworks, getNonCirculatingSupplyBalances, calculateCirculatingSupply } from './src/getSupplyAcrossNetworks';
import { getNetworkConfigurations } from './src/config';

async function fetchCirculatingSupply() {
  const networks = await getNetworkConfigurations();
  const totalSupplyData = await getTotalSupplyAcrossNetworks(networks);
  const nonCirculatingSupplyBalances = await getNonCirculatingSupplyBalances();
  const circulatingSupply = calculateCirculatingSupply(totalSupplyData.total, nonCirculatingSupplyBalances.balances);
  console.log(circulatingSupply.toString());
}

fetchCirculatingSupply();

These utility functions provide a foundation for the TokenSupply app, enabling the retrieval and calculation of token supply data. Understanding how these functions work and how they interact with the app's architecture will help you extend and customize the TokenSupply app to suit your specific use case.

Last updated