Skip to content

Commit

Permalink
fix tokenamount toJSON return type
Browse files Browse the repository at this point in the history
  • Loading branch information
macalinao committed Jun 5, 2022
1 parent 7522d54 commit 4d342bc
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/token-utils/src/tokenAmount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { u64 } from "@solana/spl-token";
import type { BigintIsh } from "@ubeswap/token-math";
import type { BigintIsh, FractionObject } from "@ubeswap/token-math";
import {
parseAmountFromString,
parseBigintIsh,
Expand All @@ -12,6 +12,21 @@ import type { Token } from "./token.js";

export type { IFormatUint } from "@ubeswap/token-math";

export interface TokenAmountObject extends FractionObject {
/**
* Discriminator to show this is a token amount.
*/
_isTA: true;
/**
* Mint of the token.
*/
mint: string;
/**
* Amount of tokens in string representation.
*/
uiAmount: string;
}

export class TokenAmount extends UTokenAmount<Token> {
// amount _must_ be raw, i.e. in the native representation
constructor(token: Token, amount: BigintIsh) {
Expand Down Expand Up @@ -56,21 +71,9 @@ export class TokenAmount extends UTokenAmount<Token> {
/**
* JSON representation of the token amount.
*/
toJSON(): {
/**
* Discriminator to show this is a token amount.
*/
_isTA: true;
/**
* Mint of the token.
*/
mint: string;
/**
* Amount of tokens in string representation.
*/
uiAmount: string;
} {
override toJSON(): TokenAmountObject {
return {
...super.toJSON(),
_isTA: true,
mint: this.token.address,
uiAmount: this.toExact(),
Expand Down

0 comments on commit 4d342bc

Please sign in to comment.