mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 14:42:38 +03:00
fix: bigint errors fix: TS errors fix: gasLimit fetch fix: review comments fix: contracts errors chore: bump rc version fix: revert wrong fix fix: ts config fix: ts config fix: ts config feat: update signer
26 lines
756 B
TypeScript
26 lines
756 B
TypeScript
import { BigNumber } from "bignumber.js";
|
|
|
|
/**
|
|
* Converts denormalized ("human-readable") number to normalized ("machine-readable") number.
|
|
* @param input Any numeric value
|
|
* @param decimals Blockchain asset precision
|
|
* @param roundingMode Rounding mode
|
|
* @returns bigint
|
|
*/
|
|
export default function normalizeNumber(
|
|
input: BigNumber.Value,
|
|
decimals: BigNumber.Value,
|
|
roundingMode: BigNumber.RoundingMode
|
|
) {
|
|
const decimalsBN = new BigNumber(decimals);
|
|
if (!decimalsBN.isInteger())
|
|
throw new Error(`Decimals '${decimalsBN.toString()}' is not an integer`);
|
|
const inputBN = new BigNumber(input);
|
|
return BigInt(
|
|
inputBN
|
|
.multipliedBy(new BigNumber(10).pow(decimals))
|
|
.integerValue(roundingMode)
|
|
.toString()
|
|
);
|
|
}
|