@ardier16/q-js-sdk
Version:
Typescript Library to interact with Q System Contracts
83 lines (82 loc) • 3.65 kB
TypeScript
/// <reference types="bn.js" />
/**
* Allows to use handy unit conversions.
* @module unit-converter
*/
import { BigNumber } from 'bignumber.js';
/**
* Helps with converting numbers
*/
export declare class UnitConverter {
private readonly SECONDS_IN_A_YEAR;
private readonly FRACTION_PRECISION;
/**
* Returns the given input number as BigNumber object (as defined by bignumber.js library)
* @memberof UnitConverter
*/
toBigNumber: (value: string | number) => BigNumber;
/**
* Returns the given BigNumber object (as defined by bignumber.js library) to a string that can be passed to any system smart contract.
* @memberof UnitConverter
*/
fromBigNumber: (value: BigNumber) => string;
/**
* @deprecated
* @memberof UnitConverter use bignumber.js for any calculation, e.g. `toBigNumber(toFraction(1))`
*/
readonly ONE_AS_FRACTION: import("bn.js");
/**
* Converts date format to timestamp.
* @param date Date object to convert to timestamp.
* @returns Timestamp.
*/
toTimestamp(date: Date): string;
/**
* Converts timestamp to date format.
* @param timestamp Timestamp to convert to date.
* @returns Date object.
*/
fromTimestamp(timestamp: string): Date;
/**
* Convert APY to ratePerSecond format.
* @param annualPercentageYield Specifies annual percentage yield NOT as onchain fraction, i.e. 5% = 0.05 or '0.05'.
* @returns rate per second in onchain fraction precision as string, e.g. the output for toRatePerSecond(0.05) returns '1547125982881430000'.
*/
toRatePerSecond(annualPercentageYield: number | string): string;
/**
* Convert ratePerSecond format to APY.
* @param ratePerSecond Specifies the rate per second in onchain fraction precision as string
* @returns Annual percentage yield NOT as onchain fraction
*/
fromRatePerSecond(ratePerSecond: string): string;
/**
* Gets the integer representation of the given number with a specifed shift of decimal places.
* Example: toSmallestUnit(0.054, 8) => '5400000'
* @param decimal Decimal number to convert.
* @param digitShift The number of decimal places to apply in the integer representation
* @returns the given number - shifted by the given decimal places - as string
*/
toSmallestUnit(decimal: number | string, digitShift: number): string;
/**
* Converts the integer representation with a specifed shift of decimal places to a decimal number.
* Example: fromSmallestUnit( '5400000', 8) => '0.054'
* @param smallestUnitStr The number represented in smallest units.
* @param digitShift The number of decimal places of the integer representation
* @returns the smallest unit amount - shifted by the given decimal places - as string
*/
fromSmallestUnit(smallestUnitStr: string, digitShift: number): string;
/**
* Converts decimal to 10**27 precision format.
* @param decimal Decimal to convert.
* @param isPercentage If true, then the input is interpreted as percentage, i.e. 10.5% is passed as 10.5 instead of 0.105
* @returns decimal in system precision format.
*/
toFraction(decimal: number | string, isPercentage?: boolean): string;
/**
* Converts 10**27 precision format to decimal.
* @param fraction System precision format value.
* @param asPercentage If true, then the output is represented as percentage, i.e. 10.5% is returned as 10.5 instead of 0.105
* @returns Regular decimal.
*/
fromFraction(fractionStr: string, asPercentage?: boolean): string;
}