@saberhq/spl-token
Advanced tools
Comparing version 0.1.0-beta.7 to 0.1.0-beta.8
@@ -111,2 +111,21 @@ 'use strict'; | ||
} | ||
var stripTrailingZeroes = function stripTrailingZeroes(num) { | ||
var _num$split = num.split("."), | ||
head = _num$split[0], | ||
tail = _num$split[1], | ||
rest = _num$split.slice(2); | ||
if (rest.length > 0 || !head) { | ||
console.warn("Invalid number passed to stripTrailingZeroes: " + num); | ||
return num; | ||
} | ||
if (!tail) { | ||
return num; | ||
} | ||
return head + "." + tail.replace(/\.0+$/, ""); | ||
}; | ||
var TokenAmount = /*#__PURE__*/function (_Fraction) { | ||
@@ -240,2 +259,18 @@ _inheritsLoose(TokenAmount, _Fraction); | ||
return this.multiplyBy(new tokenMath.Percent(1, 1).subtract(percent)); | ||
} | ||
/** | ||
* Formats this number using Intl.NumberFormatOptions | ||
* @param param0 | ||
* @returns | ||
*/ | ||
; | ||
_proto.format = function format(_temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
numberFormatOptions = _ref.numberFormatOptions, | ||
locale = _ref.locale; | ||
var asExactString = this.toFixed(this.token.decimals); | ||
var asNumber = parseFloat(asExactString); | ||
return "" + (numberFormatOptions !== undefined ? asNumber.toLocaleString(locale, numberFormatOptions) : stripTrailingZeroes(asExactString)); | ||
}; | ||
@@ -242,0 +277,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=t(require("jsbi")),n=require("@ubeswap/token-math"),r=t(require("tiny-invariant")),i=require("@solana/spl-token"),o=require("@solana/web3.js"),u=t(require("decimal.js")),a=t(require("bn.js")),s=e.BigInt("0xffffffffffffffff"),c=e.BigInt(0),l=e.BigInt(1),f=e.BigInt(10);function d(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function p(t,e,n){return e&&d(t.prototype,e),n&&d(t,n),t}function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function y(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,(Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var m=function(t,e){return void 0!==t&&void 0!==e&&t.mintAccount.equals(e.mintAccount)&&t.cluster===e.cluster},v={tokenSymbol:"SOL",tokenName:"Solana",icon:"https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png",mintAccount:i.NATIVE_MINT,decimals:Math.log10(o.LAMPORTS_PER_SOL)},g={"mainnet-beta":h({},v,{cluster:"mainnet-beta"}),devnet:h({},v,{cluster:"devnet"}),testnet:h({},v,{cluster:"testnet"})};function w(t){return t instanceof e?t:e.BigInt("bigint"==typeof t||t instanceof i.u64||t instanceof a?t.toString():t)}var b=function(t){return e.exponentiate(f,e.BigInt(t))};function k(t){e.greaterThanOrEqual(t,c)||r(!1),e.lessThanOrEqual(t,s)||r(!1)}var q=function(t){function o(e,n){var r,i=w(n);return k(i),(r=t.call(this,i,b(e.decimals))||this).token=void 0,r.token=e,r}y(o,t),o.parse=function(t,n){return new o(t,e.BigInt(new u(n).times(new u(10).pow(t.decimals)).floor().toString()))};var a=o.prototype;return a.toSignificant=function(e,r,i){return void 0===e&&(e=6),void 0===i&&(i=n.Rounding.ROUND_DOWN),t.prototype.toSignificant.call(this,e,r,i)},a.toFixed=function(e,i,o){return void 0===e&&(e=this.token.decimals),void 0===o&&(o=n.Rounding.ROUND_DOWN),e<=this.token.decimals||r(!1),t.prototype.toFixed.call(this,e,i,o)},a.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),n.Big.DP=this.token.decimals,new n.Big(this.numerator).div(this.denominator.toString()).toFormat(t)},a.add=function(t){return m(this.token,t.token)||r(!1),new o(this.token,e.add(this.raw,t.raw))},a.subtract=function(t){return m(this.token,t.token)||r(!1),new o(this.token,e.subtract(this.raw,t.raw))},a.divideByAmount=function(t){m(this.token,t.token)||r(!1);var e=this.divide(t);return new n.Percent(e.numerator,e.denominator)},a.divideBy=function(t){var e=this.divide(t);return new n.Percent(e.numerator,e.denominator)},a.toU64=function(){return new i.u64(this.raw.toString())},a.multiplyBy=function(t){return new o(this.token,t.asFraction.multiply(this.raw).toFixed(0))},a.reduceBy=function(t){return this.multiplyBy(new n.Percent(1,1).subtract(t))},p(o,[{key:"raw",get:function(){return this.numerator}}]),o}(n.Fraction),x=function(t){function e(e,r,i,o){var u;return(u=t.call(this,w(o),w(i))||this).baseCurrency=void 0,u.quoteCurrency=void 0,u.scalar=void 0,u.baseCurrency=e,u.quoteCurrency=r,u.scalar=new n.Fraction(b(e.decimals),b(r.decimals)),u}y(e,t);var i=e.prototype;return i.invert=function(){return new e(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},i.multiply=function(n){m(this.quoteCurrency,n.baseCurrency)||r(!1);var i=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,i.denominator,i.numerator)},i.quote=function(e){return m(e.token,this.baseCurrency)||r(!1),new q(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient)},i.toSignificant=function(t,e,n){return void 0===t&&(t=6),this.adjusted.toSignificant(t,e,n)},i.toFixed=function(t,e,n){return void 0===t&&(t=4),this.adjusted.toFixed(t,e,n)},p(e,[{key:"raw",get:function(){return new n.Fraction(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(n.Fraction);exports.MAX_U64=s,exports.ONE=l,exports.Price=x,exports.SOL=g,exports.TEN=f,exports.TokenAmount=q,exports.ZERO=c,exports.makeDecimalMultiplier=b,exports.parseBigintIsh=w,exports.tokensEqual=m,exports.validateU64=k; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=t(require("jsbi")),n=require("@ubeswap/token-math"),r=t(require("tiny-invariant")),i=require("@solana/spl-token"),o=require("@solana/web3.js"),a=t(require("decimal.js")),u=t(require("bn.js")),s=e.BigInt("0xffffffffffffffff"),c=e.BigInt(0),l=e.BigInt(1),f=e.BigInt(10);function d(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function p(t,e,n){return e&&d(t.prototype,e),n&&d(t,n),t}function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function m(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,(Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var y=function(t,e){return void 0!==t&&void 0!==e&&t.mintAccount.equals(e.mintAccount)&&t.cluster===e.cluster},v={tokenSymbol:"SOL",tokenName:"Solana",icon:"https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png",mintAccount:i.NATIVE_MINT,decimals:Math.log10(o.LAMPORTS_PER_SOL)},g={"mainnet-beta":h({},v,{cluster:"mainnet-beta"}),devnet:h({},v,{cluster:"devnet"}),testnet:h({},v,{cluster:"testnet"})};function w(t){return t instanceof e?t:e.BigInt("bigint"==typeof t||t instanceof i.u64||t instanceof u?t.toString():t)}var b=function(t){return e.exponentiate(f,e.BigInt(t))};function k(t){e.greaterThanOrEqual(t,c)||r(!1),e.lessThanOrEqual(t,s)||r(!1)}var x=function(t){function o(e,n){var r,i=w(n);return k(i),(r=t.call(this,i,b(e.decimals))||this).token=void 0,r.token=e,r}m(o,t),o.parse=function(t,n){return new o(t,e.BigInt(new a(n).times(new a(10).pow(t.decimals)).floor().toString()))};var u=o.prototype;return u.toSignificant=function(e,r,i){return void 0===e&&(e=6),void 0===i&&(i=n.Rounding.ROUND_DOWN),t.prototype.toSignificant.call(this,e,r,i)},u.toFixed=function(e,i,o){return void 0===e&&(e=this.token.decimals),void 0===o&&(o=n.Rounding.ROUND_DOWN),e<=this.token.decimals||r(!1),t.prototype.toFixed.call(this,e,i,o)},u.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),n.Big.DP=this.token.decimals,new n.Big(this.numerator).div(this.denominator.toString()).toFormat(t)},u.add=function(t){return y(this.token,t.token)||r(!1),new o(this.token,e.add(this.raw,t.raw))},u.subtract=function(t){return y(this.token,t.token)||r(!1),new o(this.token,e.subtract(this.raw,t.raw))},u.divideByAmount=function(t){y(this.token,t.token)||r(!1);var e=this.divide(t);return new n.Percent(e.numerator,e.denominator)},u.divideBy=function(t){var e=this.divide(t);return new n.Percent(e.numerator,e.denominator)},u.toU64=function(){return new i.u64(this.raw.toString())},u.multiplyBy=function(t){return new o(this.token,t.asFraction.multiply(this.raw).toFixed(0))},u.reduceBy=function(t){return this.multiplyBy(new n.Percent(1,1).subtract(t))},u.format=function(t){var e,n,r,i,o=void 0===t?{}:t,a=o.numberFormatOptions,u=o.locale,s=this.toFixed(this.token.decimals),c=parseFloat(s);return""+(void 0!==a?c.toLocaleString(u,a):(r=(n=(e=s).split("."))[0],i=n[1],n.slice(2).length>0||!r?(console.warn("Invalid number passed to stripTrailingZeroes: "+e),e):i?r+"."+i.replace(/\.0+$/,""):e))},p(o,[{key:"raw",get:function(){return this.numerator}}]),o}(n.Fraction),O=function(t){function e(e,r,i,o){var a;return(a=t.call(this,w(o),w(i))||this).baseCurrency=void 0,a.quoteCurrency=void 0,a.scalar=void 0,a.baseCurrency=e,a.quoteCurrency=r,a.scalar=new n.Fraction(b(e.decimals),b(r.decimals)),a}m(e,t);var i=e.prototype;return i.invert=function(){return new e(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},i.multiply=function(n){y(this.quoteCurrency,n.baseCurrency)||r(!1);var i=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,i.denominator,i.numerator)},i.quote=function(e){return y(e.token,this.baseCurrency)||r(!1),new x(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient)},i.toSignificant=function(t,e,n){return void 0===t&&(t=6),this.adjusted.toSignificant(t,e,n)},i.toFixed=function(t,e,n){return void 0===t&&(t=4),this.adjusted.toFixed(t,e,n)},p(e,[{key:"raw",get:function(){return new n.Fraction(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(n.Fraction);exports.MAX_U64=s,exports.ONE=l,exports.Price=O,exports.SOL=g,exports.TEN=f,exports.TokenAmount=x,exports.ZERO=c,exports.makeDecimalMultiplier=b,exports.parseBigintIsh=w,exports.tokensEqual=y,exports.validateU64=k; | ||
//# sourceMappingURL=spl-token.cjs.production.min.js.map |
@@ -107,2 +107,21 @@ import JSBI from 'jsbi'; | ||
} | ||
var stripTrailingZeroes = function stripTrailingZeroes(num) { | ||
var _num$split = num.split("."), | ||
head = _num$split[0], | ||
tail = _num$split[1], | ||
rest = _num$split.slice(2); | ||
if (rest.length > 0 || !head) { | ||
console.warn("Invalid number passed to stripTrailingZeroes: " + num); | ||
return num; | ||
} | ||
if (!tail) { | ||
return num; | ||
} | ||
return head + "." + tail.replace(/\.0+$/, ""); | ||
}; | ||
var TokenAmount = /*#__PURE__*/function (_Fraction) { | ||
@@ -236,2 +255,18 @@ _inheritsLoose(TokenAmount, _Fraction); | ||
return this.multiplyBy(new Percent(1, 1).subtract(percent)); | ||
} | ||
/** | ||
* Formats this number using Intl.NumberFormatOptions | ||
* @param param0 | ||
* @returns | ||
*/ | ||
; | ||
_proto.format = function format(_temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
numberFormatOptions = _ref.numberFormatOptions, | ||
locale = _ref.locale; | ||
var asExactString = this.toFixed(this.token.decimals); | ||
var asNumber = parseFloat(asExactString); | ||
return "" + (numberFormatOptions !== undefined ? asNumber.toLocaleString(locale, numberFormatOptions) : stripTrailingZeroes(asExactString)); | ||
}; | ||
@@ -238,0 +273,0 @@ |
@@ -7,2 +7,12 @@ import { u64 } from "@solana/spl-token"; | ||
export declare function validateU64(value: JSBI): void; | ||
export interface IFormatUint { | ||
/** | ||
* If specified, format this according to `toLocaleString` | ||
*/ | ||
numberFormatOptions?: Intl.NumberFormatOptions; | ||
/** | ||
* Locale of the number | ||
*/ | ||
locale?: string; | ||
} | ||
export declare class TokenAmount extends Fraction { | ||
@@ -55,2 +65,8 @@ readonly token: Token; | ||
reduceBy(percent: Percent): TokenAmount; | ||
/** | ||
* Formats this number using Intl.NumberFormatOptions | ||
* @param param0 | ||
* @returns | ||
*/ | ||
format({ numberFormatOptions, locale }?: IFormatUint): string; | ||
} |
{ | ||
"name": "@saberhq/spl-token", | ||
"version": "0.1.0-beta.7", | ||
"version": "0.1.0-beta.8", | ||
"repository": "git@github.com:saber-hq/use-solana.git", | ||
@@ -40,3 +40,3 @@ "author": "Ian Macalinao <ian@saber.so>", | ||
}, | ||
"gitHead": "a5108b3067225f0097dc63ca2912754d5a580f3a" | ||
"gitHead": "9339ac1701c9b332e7b4a8a798b6a11d722d5c4a" | ||
} |
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
83584
752