From 50cdb768380028c735a30563163bc2884250af77 Mon Sep 17 00:00:00 2001 From: Christophe Le Bars Date: Thu, 20 Apr 2023 14:34:29 +0200 Subject: [PATCH] serialization token chainId as Bigint --- src/index.js | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index 2faabe0..4bb3f10 100644 --- a/src/index.js +++ b/src/index.js @@ -67,6 +67,16 @@ export class Token { return expandToNDecimals(decimals)(number) } + toJSON() { + return { + ...this, + chainId: + typeof this.chainId === 'bigint' + ? this.chainId.toString() + : this.chainId + } + } + // if number is decimals newAmount(number, decimals) { if (number instanceof TokenAmount) { @@ -178,6 +188,7 @@ export class TokenAmount { } } } + add(any) { return toTokenAmount( this.number + toTokenAmount(any, this.token).number, @@ -185,26 +196,33 @@ export class TokenAmount { ) } - xadd(any) { - const other = toTokenAmount(any, this.token) - return this.token.newAmount(this.number + other.number) - } - sub(any) { - const other = toTokenAmount(any, this.token) - return this.token.newAmount(this.number - other.number) + return toTokenAmount( + this.number - toTokenAmount(any, this.token).number, + this.token + ) } mul(any) { - const other = toTokenAmount(any, this.token) - return this.token.newAmount(this.number * other.number) + return toTokenAmount( + this.number * toTokenAmount(any, this.token).number, + this.token + ) } div(any) { - const other = toTokenAmount(any, this.token) - return this.token.newAmount(this.number / other.number) + return toTokenAmount( + this.number / toTokenAmount(any, this.token).number, + this.token + ) } + lt(any) { + return this.number < toTokenAmount(any, this.token).number + } + lte(any) { + return this.number <= toTokenAmount(any, this.token).number + } eq(any) { return this.number === toTokenAmount(any, this.token).number }