New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@saberhq/spl-token

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saberhq/spl-token - npm Package Compare versions

Comparing version 0.1.1-beta.0 to 0.1.1-beta.1

8

dist/constants.js
import JSBI from "jsbi";
export const MAX_U64 = JSBI.BigInt("0xffffffffffffffff");
export const ZERO = JSBI.BigInt(0);
export const ONE = JSBI.BigInt(1);
export const TEN = JSBI.BigInt(10);
export var MAX_U64 = JSBI.BigInt("0xffffffffffffffff");
export var ZERO = JSBI.BigInt(0);
export var ONE = JSBI.BigInt(1);
export var TEN = JSBI.BigInt(10);
//# sourceMappingURL=constants.js.map

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

import { __extends } from "tslib";
import { Fraction } from "@ubeswap/token-math";

@@ -6,36 +7,50 @@ import invariant from "tiny-invariant";

import { makeDecimalMultiplier, parseBigintIsh } from "./utils";
export class Price extends Fraction {
var Price = /** @class */ (function (_super) {
__extends(Price, _super);
// denominator and numerator _must_ be raw, i.e. in the native representation
constructor(baseCurrency, quoteCurrency, denominator, numerator) {
super(parseBigintIsh(numerator), parseBigintIsh(denominator));
this.baseCurrency = baseCurrency;
this.quoteCurrency = quoteCurrency;
this.scalar = new Fraction(makeDecimalMultiplier(baseCurrency.decimals), makeDecimalMultiplier(quoteCurrency.decimals));
function Price(baseCurrency, quoteCurrency, denominator, numerator) {
var _this = _super.call(this, parseBigintIsh(numerator), parseBigintIsh(denominator)) || this;
_this.baseCurrency = baseCurrency;
_this.quoteCurrency = quoteCurrency;
_this.scalar = new Fraction(makeDecimalMultiplier(baseCurrency.decimals), makeDecimalMultiplier(quoteCurrency.decimals));
return _this;
}
get raw() {
return new Fraction(this.numerator, this.denominator);
}
get adjusted() {
return super.multiply(this.scalar);
}
invert() {
Object.defineProperty(Price.prototype, "raw", {
get: function () {
return new Fraction(this.numerator, this.denominator);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Price.prototype, "adjusted", {
get: function () {
return _super.prototype.multiply.call(this, this.scalar);
},
enumerable: false,
configurable: true
});
Price.prototype.invert = function () {
return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator);
}
multiply(other) {
};
Price.prototype.multiply = function (other) {
invariant(tokensEqual(this.quoteCurrency, other.baseCurrency), "TOKEN");
const fraction = super.multiply(other);
var fraction = _super.prototype.multiply.call(this, other);
return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
}
};
// performs floor division on overflow
quote(tokenAmount) {
Price.prototype.quote = function (tokenAmount) {
invariant(tokensEqual(tokenAmount.token, this.baseCurrency), "TOKEN");
return new TokenAmount(this.quoteCurrency, super.multiply(tokenAmount.raw).quotient);
}
toSignificant(significantDigits = 6, format, rounding) {
return new TokenAmount(this.quoteCurrency, _super.prototype.multiply.call(this, tokenAmount.raw).quotient);
};
Price.prototype.toSignificant = function (significantDigits, format, rounding) {
if (significantDigits === void 0) { significantDigits = 6; }
return this.adjusted.toSignificant(significantDigits, format, rounding);
}
toFixed(decimalPlaces = 4, format, rounding) {
};
Price.prototype.toFixed = function (decimalPlaces, format, rounding) {
if (decimalPlaces === void 0) { decimalPlaces = 4; }
return this.adjusted.toFixed(decimalPlaces, format, rounding);
}
}
};
return Price;
}(Fraction));
export { Price };
//# sourceMappingURL=price.js.map

@@ -0,8 +1,11 @@

import { __assign } from "tslib";
import { NATIVE_MINT } from "@solana/spl-token";
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
export const tokensEqual = (a, b) => a !== undefined &&
b !== undefined &&
a.mintAccount.equals(b.mintAccount) &&
a.network === b.network;
const sol = {
export var tokensEqual = function (a, b) {
return a !== undefined &&
b !== undefined &&
a.mintAccount.equals(b.mintAccount) &&
a.network === b.network;
};
var sol = {
tokenSymbol: "SOL",

@@ -17,12 +20,12 @@ tokenName: "Solana",

*/
export const makeTokenForAllNetworks = (token) => ({
"mainnet-beta": Object.assign(Object.assign({}, token), { network: "mainnet-beta" }),
devnet: Object.assign(Object.assign({}, token), { network: "devnet" }),
testnet: Object.assign(Object.assign({}, token), { network: "testnet" }),
localnet: Object.assign(Object.assign({}, token), { network: "localnet" }),
});
export var makeTokenForAllNetworks = function (token) { return ({
"mainnet-beta": __assign(__assign({}, token), { network: "mainnet-beta" }),
devnet: __assign(__assign({}, token), { network: "devnet" }),
testnet: __assign(__assign({}, token), { network: "testnet" }),
localnet: __assign(__assign({}, token), { network: "localnet" }),
}); };
/**
* Solana native token.
*/
export const SOL = makeTokenForAllNetworks(sol);
export var SOL = makeTokenForAllNetworks(sol);
//# sourceMappingURL=token.js.map

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

import { __extends } from "tslib";
import { u64 } from "@solana/spl-token";

@@ -10,9 +11,9 @@ import { Big, Fraction, Percent, Rounding, } from "@ubeswap/token-math";

export function validateU64(value) {
invariant(JSBI.greaterThanOrEqual(value, ZERO), `${value.toString()} must be greater than zero`);
invariant(JSBI.lessThanOrEqual(value, MAX_U64), `${value.toString()} overflows u64`);
invariant(JSBI.greaterThanOrEqual(value, ZERO), value.toString() + " must be greater than zero");
invariant(JSBI.lessThanOrEqual(value, MAX_U64), value.toString() + " overflows u64");
}
const stripTrailingZeroes = (num) => {
const [head, tail, ...rest] = num.split(".");
var stripTrailingZeroes = function (num) {
var _a = num.split("."), head = _a[0], tail = _a[1], rest = _a.slice(2);
if (rest.length > 0 || !head) {
console.warn(`Invalid number passed to stripTrailingZeroes: ${num}`);
console.warn("Invalid number passed to stripTrailingZeroes: " + num);
return num;

@@ -23,11 +24,14 @@ }

}
return `${head}.${tail.replace(/\.0+$/, "")}`;
return head + "." + tail.replace(/\.0+$/, "");
};
export class TokenAmount extends Fraction {
var TokenAmount = /** @class */ (function (_super) {
__extends(TokenAmount, _super);
// amount _must_ be raw, i.e. in the native representation
constructor(token, amount) {
const parsedAmount = parseBigintIsh(amount);
function TokenAmount(token, amount) {
var _this = this;
var parsedAmount = parseBigintIsh(amount);
validateU64(parsedAmount);
super(parsedAmount, makeDecimalMultiplier(token.decimals));
this.token = token;
_this = _super.call(this, parsedAmount, makeDecimalMultiplier(token.decimals)) || this;
_this.token = token;
return _this;
}

@@ -40,3 +44,3 @@ /**

*/
static parse(token, uiAmount) {
TokenAmount.parse = function (token, uiAmount) {
return new TokenAmount(token, JSBI.BigInt(new Decimal(uiAmount)

@@ -46,14 +50,23 @@ .times(new Decimal(10).pow(token.decimals))

.toString()));
}
get raw() {
return this.numerator;
}
toSignificant(significantDigits = 6, format, rounding = Rounding.ROUND_DOWN) {
return super.toSignificant(significantDigits, format, rounding);
}
toFixed(decimalPlaces = this.token.decimals, format, rounding = Rounding.ROUND_DOWN) {
};
Object.defineProperty(TokenAmount.prototype, "raw", {
get: function () {
return this.numerator;
},
enumerable: false,
configurable: true
});
TokenAmount.prototype.toSignificant = function (significantDigits, format, rounding) {
if (significantDigits === void 0) { significantDigits = 6; }
if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; }
return _super.prototype.toSignificant.call(this, significantDigits, format, rounding);
};
TokenAmount.prototype.toFixed = function (decimalPlaces, format, rounding) {
if (decimalPlaces === void 0) { decimalPlaces = this.token.decimals; }
if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; }
invariant(decimalPlaces <= this.token.decimals, "DECIMALS");
return super.toFixed(decimalPlaces, format, rounding);
}
toExact(format = { groupSeparator: "" }) {
return _super.prototype.toFixed.call(this, decimalPlaces, format, rounding);
};
TokenAmount.prototype.toExact = function (format) {
if (format === void 0) { format = { groupSeparator: "" }; }
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access

@@ -65,11 +78,11 @@ Big.DP = this.token.decimals;

.toFormat(format);
}
add(other) {
};
TokenAmount.prototype.add = function (other) {
invariant(tokensEqual(this.token, other.token), "TOKEN");
return new TokenAmount(this.token, JSBI.add(this.raw, other.raw));
}
subtract(other) {
};
TokenAmount.prototype.subtract = function (other) {
invariant(tokensEqual(this.token, other.token), "TOKEN");
return new TokenAmount(this.token, JSBI.subtract(this.raw, other.raw));
}
};
/**

@@ -80,7 +93,7 @@ * Gets this TokenAmount as a percentage of the other TokenAmount.

*/
divideByAmount(other) {
TokenAmount.prototype.divideByAmount = function (other) {
invariant(tokensEqual(this.token, other.token), "TOKEN");
const frac = this.divide(other);
var frac = this.divide(other);
return new Percent(frac.numerator, frac.denominator);
}
};
/**

@@ -91,6 +104,6 @@ * Gets this TokenAmount as a percentage of the other TokenAmount.

*/
divideBy(other) {
const frac = this.divide(other);
TokenAmount.prototype.divideBy = function (other) {
var frac = this.divide(other);
return new Percent(frac.numerator, frac.denominator);
}
};
/**

@@ -100,5 +113,5 @@ * Converts this to the raw u64 used by the SPL library

*/
toU64() {
TokenAmount.prototype.toU64 = function () {
return new u64(this.raw.toString());
}
};
/**

@@ -110,5 +123,5 @@ * Multiplies this token amount by a percent.

*/
multiplyBy(percent) {
TokenAmount.prototype.multiplyBy = function (percent) {
return new TokenAmount(this.token, percent.asFraction.multiply(this.raw).toFixed(0));
}
};
/**

@@ -120,5 +133,5 @@ * Reduces this token amount by a percent.

*/
reduceBy(percent) {
TokenAmount.prototype.reduceBy = function (percent) {
return this.multiplyBy(new Percent(1, 1).subtract(percent));
}
};
/**

@@ -129,10 +142,13 @@ * Formats this number using Intl.NumberFormatOptions

*/
format({ numberFormatOptions, locale } = {}) {
const asExactString = this.toFixed(this.token.decimals);
const asNumber = parseFloat(asExactString);
return `${numberFormatOptions !== undefined
TokenAmount.prototype.format = function (_a) {
var _b = _a === void 0 ? {} : _a, numberFormatOptions = _b.numberFormatOptions, locale = _b.locale;
var asExactString = this.toFixed(this.token.decimals);
var asNumber = parseFloat(asExactString);
return "" + (numberFormatOptions !== undefined
? asNumber.toLocaleString(locale, numberFormatOptions)
: stripTrailingZeroes(asExactString)}`;
}
}
: stripTrailingZeroes(asExactString));
};
return TokenAmount;
}(Fraction));
export { TokenAmount };
//# sourceMappingURL=tokenAmount.js.map

@@ -19,5 +19,5 @@ import { u64 } from "@solana/spl-token";

*/
export const makeDecimalMultiplier = (decimals) => {
export var makeDecimalMultiplier = function (decimals) {
return JSBI.exponentiate(TEN, JSBI.BigInt(decimals));
};
//# sourceMappingURL=utils.js.map
{
"name": "@saberhq/spl-token",
"version": "0.1.1-beta.0",
"version": "0.1.1-beta.1",
"repository": "git@github.com:saber-hq/use-solana.git",

@@ -13,3 +13,3 @@ "author": "Ian Macalinao <ian@saber.so>",

"dependencies": {
"@saberhq/solana": "^0.1.0-beta.11",
"@saberhq/solana": "^0.1.1-beta.1",
"@solana/spl-token": "^0.1.5",

@@ -35,3 +35,3 @@ "@solana/web3.js": "^1.18.0",

},
"gitHead": "50c60dd964ba78ed9b78ac058c3cba63bc3af74d"
"gitHead": "7341e6079710ca881cef8225173920223ab0c265"
}

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