Skip to content

Commit

Permalink
serialization token chainId as Bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
clbrge committed Apr 20, 2023
1 parent 1dbaaeb commit 50cdb76
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -178,33 +188,41 @@ export class TokenAmount {
}
}
}

add(any) {
return toTokenAmount(
this.number + toTokenAmount(any, this.token).number,
this.token
)
}

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
}
Expand Down

0 comments on commit 50cdb76

Please sign in to comment.