Simple utility package extending ethers.js for better Web3 units
npm install web3-unitsethers.js with explicit ways to convert between unit types.
Wei class bundles all those types under one roof.
parseWei(value, decimals) is a wrapper around the toBn function in evm-bn, it will multiply value by 10 ^ decimals and return a Wei instance.
raw when passing the value to a smart contract call.
float when a floating point number is needed, rather than the raw integer.
display when the value is being shown on a UI.
evm-bn library to handle better conversion to BigNumbers from ethers.js.
parseFixedPointX64(value, decimals) will scale value up to decimals, then multiply it by 2^64, and return a FixedPointX64 instance.
parsePercentage(value: number | string) will accept a raw percent in decimal format and multiply it by 10 ^ 4 to construct and return a Percentage instance.
bps to return the Percentage formatted in basis points.
points to return the Percentage formatted in points.
float to return a floating point percentage in decimal format.
display to return a percentage in point format, with a fixed amount of decimals.
display can be edited with displayDecimals(x: number), it defaults to 2 otherwise.
block.timestamp returns a UNIX timestamp in seconds.
float to return the timestamp.
years to return the amount of years the amount of seconds is equal to.
seconds to return the amount of seconds represented.
Time.now to get a floored timestamp of Date.now(), in seconds.