Sealed
Readonly
assetCreates a new Amount using the rate: Amount<C>
as conversion factor.
The new Amount will have the Asset of the rate
parameter.
Create the Fiat equivalent of an Ether Amount given the ETH-FIAT rate:
const etherAmount = Amount.ether('1'); // Amount<Ether>
const fiatAsset = fiat({ name: 'US Dollar', symbol: 'USD' }); // Fiat
const rate = Amount.fiat(fiatAsset, '0.0006'); // Amount<Fiat>
const fiatAmount = etherAmount.convert(rate); // Amount<Fiat>
Quotient of an Amount and a scalar divisor.
a new Amount that is the quotient of this Amount and the divisor
parameter.
Equality check for Amounts of the same Asset.
true
if this Amount is equal to the amount
parameter.
Greater than check for Amounts of the same Asset.
true
if this Amount is greater than the amount
parameter.
Greater than or equal check for Amounts of the same Asset.
true
if this Amount is greater than or equal to the amount
parameter.
Less than check for Amounts of the same Asset.
true
if this Amount is less than the amount
parameter.
Less than or equal check for Amounts of the same Asset.
true
if this Amount is less than or equal to the amount
parameter.
Product of an Amount and a scalar factor.
a new Amount that is the product of this Amount and the factor
parameter.
Experimental
Converts the internal value as BigDecimal truncated at the Asset max precision.
Use this as your last resource, you should favour the use of Amount arithmetic methods to have a guarantee maximum precision.
Use at your own risk.
Formats the Amount value using fixed-point notation.
Optionally you can specify the number of decimals to return.
the internal value as string
truncated at this Amount Asset max precision.
Formats the Amount value to its maximum precision using a fixed-point notation.
Optionally you can specify the number of significant digits to approximate the value to.
the internal value as string
truncated at this Amount Asset max precision.
Diagnostic method to inspect the internal value.
a string representation of the Amount value and Asset symbol.
Static
erc20Static
etherStatic
fiatStatic
matic
Amount is a value object representing an amount of given Asset.
Remarks
Amount hides all the complexity of dealing with the specific precision constraints of different assets. It offers a consistent interface to perform arithmetic operations on amounts.
Amount is immutable. All arithmetic operations return a new Amount instance.