UNPKG

@dahlia-labs/token-utils

Version:

Token-related math and transaction utilities.

38 lines 1.14 kB
import { parseAmountFromString, TokenAmount as UTokenAmount, } from "@ubeswap/token-math"; export class TokenAmount extends UTokenAmount { // amount _must_ be raw, i.e. in the native representation constructor(token, amount) { super(token, amount); } new(token, amount) { // unsafe but nobody will be extending this anyway probably return new TokenAmount(token, amount); } /** * Parses a token amount from a decimal representation. * @param token * @param uiAmount * @returns */ static parse(token, uiAmount) { const prev = parseAmountFromString(token, uiAmount, ".", ","); return new TokenAmount(token, prev); } /** * String representation of this token amount. */ toString() { return `TokenAmount[Token=(${this.token.toString()}), amount=${this.toExact()}`; } /** * JSON representation of the token amount. */ toJSON() { return { ...super.toJSON(), _isTA: true, uiAmount: this.toExact(), }; } } //# sourceMappingURL=tokenAmount.js.map