@alexkeating/common-utilities
Version:
Our **Common Utilities** package is a set of helper tools and utilities that are used throughout our libraries and apps. This includes things like our constants, types that are commonly shared across packages, and various utilities and helper functions.
27 lines • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.memberUsdValueShare = exports.memberTokenBalanceShare = exports.nowInSeconds = exports.votingPowerPercentage = void 0;
const ethers_1 = require("ethers");
const votingPowerPercentage = (daoTotalShares, memberShares) => {
const perc = (Number(ethers_1.ethers.utils.formatEther(memberShares)) /
Number(ethers_1.ethers.utils.formatEther(daoTotalShares))) *
100;
return Math.round(perc * 100) / 100;
};
exports.votingPowerPercentage = votingPowerPercentage;
const nowInSeconds = () => new Date().getTime() / 1000;
exports.nowInSeconds = nowInSeconds;
const memberTokenBalanceShare = (tokenBalance, daoTotalShares, memberShares, decimals = 18) => {
const ratio = Number(ethers_1.ethers.utils.formatEther(memberShares)) /
Number(ethers_1.ethers.utils.formatEther(daoTotalShares));
const memberSharesWei = Number(tokenBalance) * ratio;
return memberSharesWei / Math.pow(10, Number(decimals));
};
exports.memberTokenBalanceShare = memberTokenBalanceShare;
const memberUsdValueShare = (usdValue, daoTotalShares, memberShares) => {
const ratio = Number(ethers_1.ethers.utils.formatEther(memberShares)) /
Number(ethers_1.ethers.utils.formatEther(daoTotalShares));
return Number(usdValue) * ratio;
};
exports.memberUsdValueShare = memberUsdValueShare;
//# sourceMappingURL=general.js.map