Skip to content

Commit

Permalink
build: upgrade all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
macalinao committed May 2, 2022
1 parent 3c3de3c commit e384ab9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 65 deletions.
2 changes: 1 addition & 1 deletion packages/token-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
38 changes: 11 additions & 27 deletions packages/token-utils/src/price.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,32 +23,18 @@ export class Price extends UPrice<Token> {
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<Token>): Price {
Expand Down
43 changes: 11 additions & 32 deletions packages/token-utils/src/tokenAmount.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<Token> {
// 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;
}

/**
Expand All @@ -34,25 +30,8 @@ export class TokenAmount extends UTokenAmount<Token> {
* @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);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -4361,7 +4361,7 @@ __metadata:
peerDependencies:
bn.js: ^5.2.0
jsbi: ^3 || ^4
checksum: 3d6da02df49ca54d8b55f8c25e214be35f387eeb1d4be131d61b01b8027ede443163e4c8a19060d4b07b5f6b87c2503740374d95ad3abb6418def615fa1faae1
checksum: cd4c456e25ed22757e869173e58f52b38a2a38062cf4a5518ecb9cbd5c8a3361683b3bdfb2914f03b1eb12a00190f057e627ab5e489a9374b614ce72f31214b3
languageName: node
linkType: hard

Expand Down

0 comments on commit e384ab9

Please sign in to comment.