From e384ab9513d0535750111e02461120c0e48ea0d8 Mon Sep 17 00:00:00 2001 From: Ian Macalinao Date: Mon, 2 May 2022 13:48:26 -0500 Subject: [PATCH] build: upgrade all dependencies --- packages/token-utils/package.json | 2 +- packages/token-utils/src/price.ts | 38 +++++++--------------- packages/token-utils/src/tokenAmount.ts | 43 +++++++------------------ yarn.lock | 10 +++--- 4 files changed, 28 insertions(+), 65 deletions(-) diff --git a/packages/token-utils/package.json b/packages/token-utils/package.json index b77f266bd..c50b10029 100644 --- a/packages/token-utils/package.json +++ b/packages/token-utils/package.json @@ -18,7 +18,7 @@ "@saberhq/solana-contrib": "^1.12.72", "@solana/buffer-layout": "^4.0.0", "@solana/spl-token": "^0.1.8", - "@ubeswap/token-math": "^4.4.7", + "@ubeswap/token-math": "^4.4.8", "tiny-invariant": "^1.2.0", "tslib": "^2.4.0" }, diff --git a/packages/token-utils/src/price.ts b/packages/token-utils/src/price.ts index 6780843f9..58583fc86 100644 --- a/packages/token-utils/src/price.ts +++ b/packages/token-utils/src/price.ts @@ -1,9 +1,7 @@ import type { BigintIsh } from "@ubeswap/token-math"; import { Price as UPrice } from "@ubeswap/token-math"; -import invariant from "tiny-invariant"; import type { Token } from "./token"; -import { TokenAmount } from "./tokenAmount"; /** * A price of one token relative to another. @@ -25,32 +23,18 @@ export class Price extends UPrice { super(baseCurrency, quoteCurrency, denominator, numerator); } - override invert(): Price { - return new Price( - this.quoteCurrency, - this.baseCurrency, - this.numerator, - this.denominator - ); - } - - override multiply(other: Price): Price { - invariant( - this.quoteCurrency.equals(other.baseCurrency), - `multiply token mismatch: ${this.quoteCurrency.toString()} !== ${other.baseCurrency.toString()}` - ); - const fraction = super.asFraction.multiply(other); + new( + baseCurrency: Token, + quoteCurrency: Token, + denominator: BigintIsh, + numerator: BigintIsh + ): this { return new Price( - this.baseCurrency, - other.quoteCurrency, - fraction.denominator, - fraction.numerator - ); - } - - override quote(tokenAmount: TokenAmount): TokenAmount { - const amt = super.quote(tokenAmount); - return new TokenAmount(this.quoteCurrency, amt.raw); + baseCurrency, + quoteCurrency, + denominator, + numerator + ) as this; } static fromUPrice(price: UPrice): Price { diff --git a/packages/token-utils/src/tokenAmount.ts b/packages/token-utils/src/tokenAmount.ts index b86f6d1a0..00bd6f940 100644 --- a/packages/token-utils/src/tokenAmount.ts +++ b/packages/token-utils/src/tokenAmount.ts @@ -1,6 +1,7 @@ import { u64 } from "@solana/spl-token"; -import type { BigintIsh, NumberFormat, Percent } from "@ubeswap/token-math"; +import type { BigintIsh, NumberFormat } from "@ubeswap/token-math"; import { + parseAmountFromString, parseBigintIsh, TokenAmount as UTokenAmount, validateU64, @@ -9,22 +10,17 @@ import BN from "bn.js"; import type { Token } from "./token"; -export interface IFormatUint { - /** - * If specified, format this according to `toLocaleString` - */ - numberFormatOptions?: Intl.NumberFormatOptions; - /** - * Locale of the number - */ - locale?: string; -} +export { IFormatUint } from "@ubeswap/token-math"; export class TokenAmount extends UTokenAmount { // amount _must_ be raw, i.e. in the native representation constructor(token: Token, amount: BigintIsh) { - super(token, amount); - validateU64(this.raw); + super(token, amount, validateU64); + } + + new(token: Token, amount: BigintIsh): this { + // unsafe but nobody will be extending this anyway probably + return new TokenAmount(token, amount) as this; } /** @@ -34,25 +30,8 @@ export class TokenAmount extends UTokenAmount { * @returns */ static parse(token: Token, uiAmount: string): TokenAmount { - const prev = UTokenAmount.parseFromString(token, uiAmount); - return new TokenAmount(token, prev.raw); - } - - override add(other: TokenAmount): TokenAmount { - const result = super.add(other); - return new TokenAmount(this.token, result.raw); - } - override subtract(other: TokenAmount): TokenAmount { - const result = super.subtract(other); - return new TokenAmount(this.token, result.raw); - } - override multiplyBy(percent: Percent): TokenAmount { - const result = super.multiplyBy(percent); - return new TokenAmount(this.token, result.raw); - } - override reduceBy(percent: Percent): TokenAmount { - const result = super.reduceBy(percent); - return new TokenAmount(this.token, result.raw); + const prev = parseAmountFromString(token, uiAmount); + return new TokenAmount(token, prev); } /** diff --git a/yarn.lock b/yarn.lock index e60de15ea..b863ac06b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3284,7 +3284,7 @@ __metadata: "@solana/spl-token": ^0.1.8 "@solana/web3.js": ^1.41.3 "@types/bn.js": ^5.1.0 - "@ubeswap/token-math": ^4.4.7 + "@ubeswap/token-math": ^4.4.8 jsbi: ^4.3.0 tiny-invariant: ^1.2.0 tslib: ^2.4.0 @@ -4349,9 +4349,9 @@ __metadata: languageName: node linkType: hard -"@ubeswap/token-math@npm:^4.4.7": - version: 4.4.7 - resolution: "@ubeswap/token-math@npm:4.4.7" +"@ubeswap/token-math@npm:^4.4.8": + version: 4.4.8 + resolution: "@ubeswap/token-math@npm:4.4.8" dependencies: big.js: ^6.1.1 decimal.js-light: ^2.5.1 @@ -4361,7 +4361,7 @@ __metadata: peerDependencies: bn.js: ^5.2.0 jsbi: ^3 || ^4 - checksum: 3d6da02df49ca54d8b55f8c25e214be35f387eeb1d4be131d61b01b8027ede443163e4c8a19060d4b07b5f6b87c2503740374d95ad3abb6418def615fa1faae1 + checksum: cd4c456e25ed22757e869173e58f52b38a2a38062cf4a5518ecb9cbd5c8a3361683b3bdfb2914f03b1eb12a00190f057e627ab5e489a9374b614ce72f31214b3 languageName: node linkType: hard