Class: TokenCalculations
Calculates to and from units for a token based on decimals
Hierarchyβ
TokenCalculations
β³
Token
Constructorsβ
constructorβ
β’ new TokenCalculations(decimals
, displayedDecimals
): TokenCalculations
Parametersβ
Name | Type | Description |
---|---|---|
decimals | number | Number of decimals used by the token. |
displayedDecimals | number | - |
Returnsβ
Defined inβ
@mangrovedao/mangrove.js/src/token.ts:64
Propertiesβ
decimalsβ
β’ decimals: number
Number of decimals used by the token.
Defined inβ
@mangrovedao/mangrove.js/src/token.ts:65
displayedDecimalsβ
β’ displayedDecimals: number
Defined inβ
@mangrovedao/mangrove.js/src/token.ts:66
Methodsβ
fromUnitsβ
βΈ fromUnits(amount
): Big
Convert base/quote from internal amount to public amount.
Uses each token's decimals
parameter.
Parametersβ
Name | Type |
---|---|
amount | string | number | BigNumber |
Returnsβ
Big
Example
const usdc = await mgv.token("USDC");
token.fromUnits("1e7") // 10
const dai = await mgv.token("DAI")
market.fromUnits("1e18") // 1
Defined inβ
@mangrovedao/mangrove.js/src/token.ts:81
toUnitsβ
βΈ toUnits(amount
): BigNumber
Convert base/quote from public amount to internal contract amount.
Uses each token's decimals
parameter.
If bq
is "base"
, will convert the base, the quote otherwise.
Parametersβ
Name | Type |
---|---|
amount | BigSource |
Returnsβ
BigNumber
Example
const usdc = await mgv.token("USDC");
token.toUnits(10) // 10e7 as ethers.BigNumber
const dai = await mgv.token("DAI")
market.toUnits(1) // 1e18 as ethers.BigNumber
Defined inβ
@mangrovedao/mangrove.js/src/token.ts:98
toFixedβ
βΈ toFixed(amount
, decimals?
): string
Convert human-readable amounts to a string with the given number of decimal places. Defaults to the token's decimals places.
Parametersβ
Name | Type |
---|---|
amount | BigSource |
decimals? | number |
Returnsβ
string
Example
token.toFixed("10.123"); // "10.12"
token.toFixed(token.fromUnits("1e7"));
Defined inβ
@mangrovedao/mangrove.js/src/token.ts:112
roundβ
βΈ round(amount
): Big
Rounds an amount according to the token's decimals.
Parametersβ
Name | Type | Description |
---|---|---|
amount | Big | The amount to round. |
Returnsβ
Big
The rounded amount.
Defined inβ
@mangrovedao/mangrove.js/src/token.ts:123