Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dahlia-labs/token-utils

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dahlia-labs/token-utils - npm Package Compare versions

Comparing version 0.3.5 to 0.4.0

5

dist/cjs/price.d.ts
import type { BigintIsh } from "@ubeswap/token-math";
import { Price as UPrice } from "@ubeswap/token-math";
import type { Token } from "./token";
import { TokenAmount } from "./tokenAmount";
/**

@@ -17,7 +16,5 @@ * A price of one token relative to another.

constructor(baseCurrency: Token, quoteCurrency: Token, denominator: BigintIsh, numerator: BigintIsh);
invert(): Price;
multiply(other: Price): Price;
quote(tokenAmount: TokenAmount): TokenAmount;
new(baseCurrency: Token, quoteCurrency: Token, denominator: BigintIsh, numerator: BigintIsh): this;
static fromUPrice(price: UPrice<Token>): Price;
}
//# sourceMappingURL=price.d.ts.map

16

dist/cjs/price.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Price = void 0;
const tslib_1 = require("tslib");
const token_math_1 = require("@ubeswap/token-math");
const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
const tokenAmount_1 = require("./tokenAmount");
/**

@@ -22,14 +19,5 @@ * A price of one token relative to another.

}
invert() {
return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator);
new(baseCurrency, quoteCurrency, denominator, numerator) {
return new Price(baseCurrency, quoteCurrency, denominator, numerator);
}
multiply(other) {
(0, tiny_invariant_1.default)(this.quoteCurrency.equals(other.baseCurrency), `multiply token mismatch: ${this.quoteCurrency.toString()} !== ${other.baseCurrency.toString()}`);
const fraction = super.asFraction.multiply(other);
return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
}
quote(tokenAmount) {
const amt = super.quote(tokenAmount);
return new tokenAmount_1.TokenAmount(this.quoteCurrency, amt.raw);
}
static fromUPrice(price) {

@@ -36,0 +24,0 @@ return new Price(price.baseCurrency, price.quoteCurrency, price.denominator, price.numerator);

@@ -1,2 +0,2 @@

import type { BigintIsh, NumberFormat, Percent } from "@ubeswap/token-math";
import type { BigintIsh, NumberFormat } from "@ubeswap/token-math";
import { TokenAmount as UTokenAmount } from "@ubeswap/token-math";

@@ -16,2 +16,3 @@ import type { Token } from "./token";

constructor(token: Token, amount: BigintIsh);
new(token: Token, amount: BigintIsh): this;
/**

@@ -24,6 +25,2 @@ * Parses a token amount from a decimal representation.

static parse(token: Token, uiAmount: string): TokenAmount;
add(other: TokenAmount): TokenAmount;
subtract(other: TokenAmount): TokenAmount;
multiplyBy(percent: Percent): TokenAmount;
reduceBy(percent: Percent): TokenAmount;
/**

@@ -30,0 +27,0 @@ * Formats the token amount with units and decimal adjustment, e.g. "100.42 SOL"

@@ -10,2 +10,6 @@ "use strict";

}
new(token, amount) {
// unsafe but nobody will be extending this anyway probably
return new TokenAmount(token, amount);
}
/**

@@ -18,21 +22,5 @@ * Parses a token amount from a decimal representation.

static parse(token, uiAmount) {
const prev = token_math_1.TokenAmount.parseFromString(token, uiAmount);
return new TokenAmount(token, prev.raw);
const prev = (0, token_math_1.parseAmountFromString)(token, uiAmount);
return new TokenAmount(token, prev);
}
add(other) {
const result = super.add(other);
return new TokenAmount(this.token, result.raw);
}
subtract(other) {
const result = super.subtract(other);
return new TokenAmount(this.token, result.raw);
}
multiplyBy(percent) {
const result = super.multiplyBy(percent);
return new TokenAmount(this.token, result.raw);
}
reduceBy(percent) {
const result = super.reduceBy(percent);
return new TokenAmount(this.token, result.raw);
}
/**

@@ -39,0 +27,0 @@ * Formats the token amount with units and decimal adjustment, e.g. "100.42 SOL"

import type { BigintIsh } from "@ubeswap/token-math";
import { Price as UPrice } from "@ubeswap/token-math";
import type { Token } from "./token";
import { TokenAmount } from "./tokenAmount";
/**

@@ -17,7 +16,5 @@ * A price of one token relative to another.

constructor(baseCurrency: Token, quoteCurrency: Token, denominator: BigintIsh, numerator: BigintIsh);
invert(): Price;
multiply(other: Price): Price;
quote(tokenAmount: TokenAmount): TokenAmount;
new(baseCurrency: Token, quoteCurrency: Token, denominator: BigintIsh, numerator: BigintIsh): this;
static fromUPrice(price: UPrice<Token>): Price;
}
//# sourceMappingURL=price.d.ts.map
import { Price as UPrice } from "@ubeswap/token-math";
import invariant from "tiny-invariant";
import { TokenAmount } from "./tokenAmount";
/**

@@ -18,14 +16,5 @@ * A price of one token relative to another.

}
invert() {
return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator);
new(baseCurrency, quoteCurrency, denominator, numerator) {
return new Price(baseCurrency, quoteCurrency, denominator, numerator);
}
multiply(other) {
invariant(this.quoteCurrency.equals(other.baseCurrency), `multiply token mismatch: ${this.quoteCurrency.toString()} !== ${other.baseCurrency.toString()}`);
const fraction = super.asFraction.multiply(other);
return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
}
quote(tokenAmount) {
const amt = super.quote(tokenAmount);
return new TokenAmount(this.quoteCurrency, amt.raw);
}
static fromUPrice(price) {

@@ -32,0 +21,0 @@ return new Price(price.baseCurrency, price.quoteCurrency, price.denominator, price.numerator);

@@ -1,2 +0,2 @@

import type { BigintIsh, NumberFormat, Percent } from "@ubeswap/token-math";
import type { BigintIsh, NumberFormat } from "@ubeswap/token-math";
import { TokenAmount as UTokenAmount } from "@ubeswap/token-math";

@@ -16,2 +16,3 @@ import type { Token } from "./token";

constructor(token: Token, amount: BigintIsh);
new(token: Token, amount: BigintIsh): this;
/**

@@ -24,6 +25,2 @@ * Parses a token amount from a decimal representation.

static parse(token: Token, uiAmount: string): TokenAmount;
add(other: TokenAmount): TokenAmount;
subtract(other: TokenAmount): TokenAmount;
multiplyBy(percent: Percent): TokenAmount;
reduceBy(percent: Percent): TokenAmount;
/**

@@ -30,0 +27,0 @@ * Formats the token amount with units and decimal adjustment, e.g. "100.42 SOL"

@@ -1,2 +0,2 @@

import { TokenAmount as UTokenAmount } from "@ubeswap/token-math";
import { parseAmountFromString, TokenAmount as UTokenAmount, } from "@ubeswap/token-math";
export class TokenAmount extends UTokenAmount {

@@ -7,2 +7,6 @@ // amount _must_ be raw, i.e. in the native representation

}
new(token, amount) {
// unsafe but nobody will be extending this anyway probably
return new TokenAmount(token, amount);
}
/**

@@ -15,21 +19,5 @@ * Parses a token amount from a decimal representation.

static parse(token, uiAmount) {
const prev = UTokenAmount.parseFromString(token, uiAmount);
return new TokenAmount(token, prev.raw);
const prev = parseAmountFromString(token, uiAmount);
return new TokenAmount(token, prev);
}
add(other) {
const result = super.add(other);
return new TokenAmount(this.token, result.raw);
}
subtract(other) {
const result = super.subtract(other);
return new TokenAmount(this.token, result.raw);
}
multiplyBy(percent) {
const result = super.multiplyBy(percent);
return new TokenAmount(this.token, result.raw);
}
reduceBy(percent) {
const result = super.reduceBy(percent);
return new TokenAmount(this.token, result.raw);
}
/**

@@ -36,0 +24,0 @@ * Formats the token amount with units and decimal adjustment, e.g. "100.42 SOL"

{
"name": "@dahlia-labs/token-utils",
"description": "Token-related math and transaction utilities.",
"version": "0.3.5",
"version": "0.4.0",
"repository": {

@@ -23,6 +23,6 @@ "type": "git",

"dependencies": {
"@dahlia-labs/celo-contrib": "^0.3.5",
"@ubeswap/token-math": "^4.4.6",
"@dahlia-labs/celo-contrib": "^0.4.0",
"@ubeswap/token-math": "^5.0.0",
"tiny-invariant": "^1.2.0",
"tslib": "^2.3.1"
"tslib": "^2.4.0"
},

@@ -36,5 +36,5 @@ "main": "dist/cjs/index.js",

"devDependencies": {
"@saberhq/tsconfig": "^1.12.61",
"@saberhq/tsconfig": "^1.13.0",
"@types/bn.js": "^5.1.0",
"jsbi": "^4.2.1"
"jsbi": "^4.3.0"
},

@@ -53,3 +53,3 @@ "peerDependencies": {

"homepage": "https://github.com/DahliaLabs/dahlia-common#readme",
"gitHead": "ceebca8f1be9a2c0ef81eb050ec76c64b77c4527"
"gitHead": "d3fc8a6033741b9eecdc245983c5dadea197ff40"
}
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";

@@ -28,30 +26,16 @@ /**

override invert(): Price {
new(
baseCurrency: Token,
quoteCurrency: Token,
denominator: BigintIsh,
numerator: BigintIsh
): this {
return new Price(
this.quoteCurrency,
this.baseCurrency,
this.numerator,
this.denominator
);
baseCurrency,
quoteCurrency,
denominator,
numerator
) as this;
}
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);
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);
}
static fromUPrice(price: UPrice<Token>): Price {

@@ -58,0 +42,0 @@ return new Price(

@@ -1,3 +0,6 @@

import type { BigintIsh, NumberFormat, Percent } from "@ubeswap/token-math";
import { TokenAmount as UTokenAmount } from "@ubeswap/token-math";
import type { BigintIsh, NumberFormat } from "@ubeswap/token-math";
import {
parseAmountFromString,
TokenAmount as UTokenAmount,
} from "@ubeswap/token-math";

@@ -23,2 +26,7 @@ import type { Token } from "./token";

new(token: Token, amount: BigintIsh): this {
// unsafe but nobody will be extending this anyway probably
return new TokenAmount(token, amount) as this;
}
/**

@@ -31,23 +39,6 @@ * Parses a token amount from a decimal representation.

static parse(token: Token, uiAmount: string): TokenAmount {
const prev = UTokenAmount.parseFromString(token, uiAmount);
return new TokenAmount(token, prev.raw);
const prev = parseAmountFromString(token, uiAmount);
return new TokenAmount(token, prev);
}
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);
}
/**

@@ -54,0 +45,0 @@ * Formats the token amount with units and decimal adjustment, e.g. "100.42 SOL"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc