@uniswap/sdk-core
Advanced tools
Comparing version 1.0.11 to 2.0.0
@@ -1,23 +0,3 @@ | ||
/** | ||
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens. | ||
* | ||
* The only instance of the base class `Currency` is Ether. | ||
*/ | ||
export declare class Currency { | ||
readonly decimals: number; | ||
readonly symbol?: string; | ||
readonly name?: string; | ||
/** | ||
* The only instance of the base class `Currency`. | ||
*/ | ||
static readonly ETHER: Currency; | ||
/** | ||
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`. | ||
* @param decimals decimals of the currency | ||
* @param symbol symbol of the currency | ||
* @param name of the currency | ||
*/ | ||
protected constructor(decimals: number, symbol?: string, name?: string); | ||
} | ||
declare const ETHER: Currency; | ||
export { ETHER }; | ||
import { Ether } from './ether'; | ||
import { Token } from './token'; | ||
export declare type Currency = Ether | Token; |
export * from './token'; | ||
export * from './currency'; | ||
export * from './ether'; | ||
export * from './fractions'; |
import { ChainId } from '../constants'; | ||
import { Currency } from './currency'; | ||
import { BaseCurrency } from './baseCurrency'; | ||
/** | ||
* Represents an ERC20 token with a unique address and some metadata. | ||
*/ | ||
export declare class Token extends Currency { | ||
export declare class Token extends BaseCurrency { | ||
readonly isEther: false; | ||
readonly isToken: true; | ||
readonly chainId: ChainId | number; | ||
@@ -23,8 +25,4 @@ readonly address: string; | ||
} | ||
/** | ||
* Compares two currencies for equality | ||
*/ | ||
export declare function currencyEquals(currencyA: Currency, currencyB: Currency): boolean; | ||
export declare const WETH9: { | ||
[chainId in ChainId]: Token; | ||
}; |
@@ -9,6 +9,6 @@ 'use strict'; | ||
var invariant = _interopDefault(require('tiny-invariant')); | ||
var address = require('@ethersproject/address'); | ||
var _Decimal = _interopDefault(require('decimal.js-light')); | ||
var _Big = _interopDefault(require('big.js')); | ||
var toFormat = _interopDefault(require('toformat')); | ||
var address = require('@ethersproject/address'); | ||
@@ -59,2 +59,15 @@ (function (ChainId) { | ||
/** | ||
* Validates an address and returns the parsed (checksummed) version of that address | ||
* @param address the unchecksummed hex address | ||
*/ | ||
function validateAndParseAddress(address$1) { | ||
try { | ||
return address.getAddress(address$1); | ||
} catch (error) { | ||
throw new Error(address$1 + " is not a valid address."); | ||
} | ||
} | ||
/** | ||
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens. | ||
@@ -65,3 +78,3 @@ * | ||
var Currency = | ||
var BaseCurrency = | ||
/** | ||
@@ -73,4 +86,4 @@ * Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`. | ||
*/ | ||
function Currency(decimals, symbol, name) { | ||
!(decimals < 255) ? invariant(false, 'DECIMALS') : void 0; | ||
function BaseCurrency(decimals, symbol, name) { | ||
!(decimals >= 0 && decimals < 255 && Number.isInteger(decimals)) ? invariant(false, 'DECIMALS') : void 0; | ||
this.decimals = decimals; | ||
@@ -80,9 +93,3 @@ this.symbol = symbol; | ||
}; | ||
/** | ||
* The only instance of the base class `Currency`. | ||
*/ | ||
Currency.ETHER = /*#__PURE__*/new Currency(18, 'ETH', 'Ether'); | ||
var ETHER = Currency.ETHER; | ||
var _WETH; | ||
@@ -93,4 +100,4 @@ /** | ||
var Token = /*#__PURE__*/function (_Currency) { | ||
_inheritsLoose(Token, _Currency); | ||
var Token = /*#__PURE__*/function (_BaseCurrency) { | ||
_inheritsLoose(Token, _BaseCurrency); | ||
@@ -100,6 +107,7 @@ function Token(chainId, address, decimals, symbol, name) { | ||
_this = _Currency.call(this, decimals, symbol, name) || this; | ||
!(address.length === 42 && address.slice(0, 2) === '0x') ? invariant(false, 'ADDRESS') : void 0; | ||
_this = _BaseCurrency.call(this, decimals, symbol, name) || this; | ||
_this.isEther = false; | ||
_this.isToken = true; | ||
_this.chainId = chainId; | ||
_this.address = address; | ||
_this.address = validateAndParseAddress(address); | ||
return _this; | ||
@@ -138,19 +146,25 @@ } | ||
return Token; | ||
}(Currency); | ||
}(BaseCurrency); | ||
var WETH9 = (_WETH = {}, _WETH[exports.ChainId.MAINNET] = /*#__PURE__*/new Token(exports.ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH9', 'Wrapped Ether'), _WETH[exports.ChainId.ROPSTEN] = /*#__PURE__*/new Token(exports.ChainId.ROPSTEN, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[exports.ChainId.RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.RINKEBY, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[exports.ChainId.GÖRLI] = /*#__PURE__*/new Token(exports.ChainId.GÖRLI, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH9', 'Wrapped Ether'), _WETH[exports.ChainId.KOVAN] = /*#__PURE__*/new Token(exports.ChainId.KOVAN, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH9', 'Wrapped Ether'), _WETH); | ||
var Ether = /*#__PURE__*/function (_BaseCurrency) { | ||
_inheritsLoose(Ether, _BaseCurrency); | ||
function Ether() { | ||
var _this; | ||
_this = _BaseCurrency.apply(this, arguments) || this; | ||
_this.isEther = true; | ||
_this.isToken = false; | ||
return _this; | ||
} | ||
return Ether; | ||
}(BaseCurrency); | ||
/** | ||
* Compares two currencies for equality | ||
* The only instance of the base class `Currency`. | ||
*/ | ||
function currencyEquals(currencyA, currencyB) { | ||
if (currencyA instanceof Token && currencyB instanceof Token) { | ||
return currencyA.equals(currencyB); | ||
} else if (currencyA instanceof Token) { | ||
return false; | ||
} else if (currencyB instanceof Token) { | ||
return false; | ||
} else { | ||
return currencyA === currencyB; | ||
} | ||
} | ||
var WETH9 = (_WETH = {}, _WETH[exports.ChainId.MAINNET] = /*#__PURE__*/new Token(exports.ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH9', 'Wrapped Ether'), _WETH[exports.ChainId.ROPSTEN] = /*#__PURE__*/new Token(exports.ChainId.ROPSTEN, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[exports.ChainId.RINKEBY] = /*#__PURE__*/new Token(exports.ChainId.RINKEBY, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[exports.ChainId.GÖRLI] = /*#__PURE__*/new Token(exports.ChainId.GÖRLI, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH9', 'Wrapped Ether'), _WETH[exports.ChainId.KOVAN] = /*#__PURE__*/new Token(exports.ChainId.KOVAN, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH9', 'Wrapped Ether'), _WETH); | ||
Ether.ETHER = /*#__PURE__*/new Ether(18, 'ETH', 'Ether'); | ||
var ETHER = Ether.ETHER; | ||
@@ -310,2 +324,81 @@ var _toSignificantRoundin, _toFixedRounding; | ||
// `maxSize` by removing the last item | ||
function sortedInsert(items, add, maxSize, comparator) { | ||
!(maxSize > 0) ? invariant(false, 'MAX_SIZE_ZERO') : void 0; // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize | ||
!(items.length <= maxSize) ? invariant(false, 'ITEMS_SIZE') : void 0; // short circuit first item add | ||
if (items.length === 0) { | ||
items.push(add); | ||
return null; | ||
} else { | ||
var isFull = items.length === maxSize; // short circuit if full and the additional item does not come before the last item | ||
if (isFull && comparator(items[items.length - 1], add) <= 0) { | ||
return add; | ||
} | ||
var lo = 0, | ||
hi = items.length; | ||
while (lo < hi) { | ||
var mid = lo + hi >>> 1; | ||
if (comparator(items[mid], add) <= 0) { | ||
lo = mid + 1; | ||
} else { | ||
hi = mid; | ||
} | ||
} | ||
items.splice(lo, 0, add); | ||
return isFull ? items.pop() : null; | ||
} | ||
} | ||
var MAX_SAFE_INTEGER = /*#__PURE__*/JSBI.BigInt(Number.MAX_SAFE_INTEGER); | ||
var ZERO = /*#__PURE__*/JSBI.BigInt(0); | ||
var ONE = /*#__PURE__*/JSBI.BigInt(1); | ||
var TWO = /*#__PURE__*/JSBI.BigInt(2); | ||
/** | ||
* Computes floor(sqrt(value)) | ||
* @param value the value for which to compute the square root, rounded down | ||
*/ | ||
function sqrt(value) { | ||
!JSBI.greaterThanOrEqual(value, ZERO) ? invariant(false, 'NEGATIVE') : void 0; // rely on built in sqrt if possible | ||
if (JSBI.lessThan(value, MAX_SAFE_INTEGER)) { | ||
return JSBI.BigInt(Math.floor(Math.sqrt(JSBI.toNumber(value)))); | ||
} | ||
var z; | ||
var x; | ||
z = value; | ||
x = JSBI.add(JSBI.divide(value, TWO), ONE); | ||
while (JSBI.lessThan(x, z)) { | ||
z = x; | ||
x = JSBI.divide(JSBI.add(JSBI.divide(value, x), x), TWO); | ||
} | ||
return z; | ||
} | ||
/** | ||
* Compares two currencies for equality | ||
*/ | ||
function currencyEquals(currencyA, currencyB) { | ||
if (currencyA.isToken && currencyB.isToken) { | ||
return currencyA.equals(currencyB); | ||
} else if (currencyA.isToken) { | ||
return false; | ||
} else if (currencyB.isToken) { | ||
return false; | ||
} else { | ||
return currencyA.isEther === currencyB.isEther; | ||
} | ||
} | ||
var Big$1 = /*#__PURE__*/toFormat(_Big); | ||
@@ -491,82 +584,5 @@ | ||
// `maxSize` by removing the last item | ||
function sortedInsert(items, add, maxSize, comparator) { | ||
!(maxSize > 0) ? invariant(false, 'MAX_SIZE_ZERO') : void 0; // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize | ||
!(items.length <= maxSize) ? invariant(false, 'ITEMS_SIZE') : void 0; // short circuit first item add | ||
if (items.length === 0) { | ||
items.push(add); | ||
return null; | ||
} else { | ||
var isFull = items.length === maxSize; // short circuit if full and the additional item does not come before the last item | ||
if (isFull && comparator(items[items.length - 1], add) <= 0) { | ||
return add; | ||
} | ||
var lo = 0, | ||
hi = items.length; | ||
while (lo < hi) { | ||
var mid = lo + hi >>> 1; | ||
if (comparator(items[mid], add) <= 0) { | ||
lo = mid + 1; | ||
} else { | ||
hi = mid; | ||
} | ||
} | ||
items.splice(lo, 0, add); | ||
return isFull ? items.pop() : null; | ||
} | ||
} | ||
/** | ||
* Validates an address and returns the parsed (checksummed) version of that address | ||
* @param address the unchecksummed hex address | ||
*/ | ||
function validateAndParseAddress(address$1) { | ||
try { | ||
return address.getAddress(address$1); | ||
} catch (error) { | ||
throw new Error(address$1 + " is not a valid address."); | ||
} | ||
} | ||
var MAX_SAFE_INTEGER = /*#__PURE__*/JSBI.BigInt(Number.MAX_SAFE_INTEGER); | ||
var ZERO = /*#__PURE__*/JSBI.BigInt(0); | ||
var ONE = /*#__PURE__*/JSBI.BigInt(1); | ||
var TWO = /*#__PURE__*/JSBI.BigInt(2); | ||
/** | ||
* Computes floor(sqrt(value)) | ||
* @param value the value for which to compute the square root, rounded down | ||
*/ | ||
function sqrt(value) { | ||
!JSBI.greaterThanOrEqual(value, ZERO) ? invariant(false, 'NEGATIVE') : void 0; // rely on built in sqrt if possible | ||
if (JSBI.lessThan(value, MAX_SAFE_INTEGER)) { | ||
return JSBI.BigInt(Math.floor(Math.sqrt(JSBI.toNumber(value)))); | ||
} | ||
var z; | ||
var x; | ||
z = value; | ||
x = JSBI.add(JSBI.divide(value, TWO), ONE); | ||
while (JSBI.lessThan(x, z)) { | ||
z = x; | ||
x = JSBI.divide(JSBI.add(JSBI.divide(value, x), x), TWO); | ||
} | ||
return z; | ||
} | ||
exports.Currency = Currency; | ||
exports.CurrencyAmount = CurrencyAmount; | ||
exports.ETHER = ETHER; | ||
exports.Ether = Ether; | ||
exports.Fraction = Fraction; | ||
@@ -573,0 +589,0 @@ exports.MaxUint256 = MaxUint256; |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var n,r,e,i=t(require("jsbi")),o=t(require("tiny-invariant")),a=t(require("decimal.js-light")),u=t(require("big.js")),s=t(require("toformat")),d=require("@ethersproject/address");(n=exports.ChainId||(exports.ChainId={}))[n.MAINNET=1]="MAINNET",n[n.ROPSTEN=3]="ROPSTEN",n[n.RINKEBY=4]="RINKEBY",n[n["GÖRLI"]=5]="GÖRLI",n[n.KOVAN=42]="KOVAN",(r=exports.TradeType||(exports.TradeType={}))[r.EXACT_INPUT=0]="EXACT_INPUT",r[r.EXACT_OUTPUT=1]="EXACT_OUTPUT",(e=exports.Rounding||(exports.Rounding={}))[e.ROUND_DOWN=0]="ROUND_DOWN",e[e.ROUND_HALF_UP=1]="ROUND_HALF_UP",e[e.ROUND_UP=2]="ROUND_UP";var c=i.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function f(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}function h(t,n,r){return n&&f(t.prototype,n),r&&f(t,r),t}function p(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}var l,m=function(t,n,r){t<255||o(!1),this.decimals=t,this.symbol=n,this.name=r},y=m.ETHER=new m(18,"ETH","Ether"),g=function(t){function n(n,r,e,i,a){var u;return u=t.call(this,e,i,a)||this,(42!==r.length||"0x"!==r.slice(0,2))&&o(!1),u.chainId=n,u.address=r,u}p(n,t);var r=n.prototype;return r.equals=function(t){return this===t||this.chainId===t.chainId&&this.address===t.address},r.sortsBefore=function(t){return this.chainId!==t.chainId&&o(!1),this.address===t.address&&o(!1),this.address.toLowerCase()<t.address.toLowerCase()},n}(m);function x(t,n){return t instanceof g&&n instanceof g?t.equals(n):!(t instanceof g||n instanceof g||t!==n)}var I,v,N=((l={})[exports.ChainId.MAINNET]=new g(exports.ChainId.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH9","Wrapped Ether"),l[exports.ChainId.ROPSTEN]=new g(exports.ChainId.ROPSTEN,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH9","Wrapped Ether"),l[exports.ChainId.RINKEBY]=new g(exports.ChainId.RINKEBY,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH9","Wrapped Ether"),l[exports.ChainId.GÖRLI]=new g(exports.ChainId.GÖRLI,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH9","Wrapped Ether"),l[exports.ChainId.KOVAN]=new g(exports.ChainId.KOVAN,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH9","Wrapped Ether"),l),w=s(a),R=s(u),E=((I={})[exports.Rounding.ROUND_DOWN]=w.ROUND_DOWN,I[exports.Rounding.ROUND_HALF_UP]=w.ROUND_HALF_UP,I[exports.Rounding.ROUND_UP]=w.ROUND_UP,I),T=((v={})[exports.Rounding.ROUND_DOWN]=0,v[exports.Rounding.ROUND_HALF_UP]=1,v[exports.Rounding.ROUND_UP]=3,v),O=function(){function t(t,n){void 0===n&&(n=i.BigInt(1)),this.numerator=i.BigInt(t),this.denominator=i.BigInt(n)}var n=t.prototype;return n.invert=function(){return new t(this.denominator,this.numerator)},n.add=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.equal(this.denominator,r.denominator)?new t(i.add(this.numerator,r.numerator),this.denominator):new t(i.add(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator)),i.multiply(this.denominator,r.denominator))},n.subtract=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.equal(this.denominator,r.denominator)?new t(i.subtract(this.numerator,r.numerator),this.denominator):new t(i.subtract(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator)),i.multiply(this.denominator,r.denominator))},n.lessThan=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.lessThan(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator))},n.equalTo=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.equal(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator))},n.greaterThan=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.greaterThan(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator))},n.multiply=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return new t(i.multiply(this.numerator,r.numerator),i.multiply(this.denominator,r.denominator))},n.divide=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return new t(i.multiply(this.numerator,r.denominator),i.multiply(this.denominator,r.numerator))},n.toSignificant=function(t,n,r){void 0===n&&(n={groupSeparator:""}),void 0===r&&(r=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||o(!1),t>0||o(!1),w.set({precision:t+1,rounding:E[r]});var e=new w(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return e.toFormat(e.decimalPlaces(),n)},n.toFixed=function(t,n,r){return void 0===n&&(n={groupSeparator:""}),void 0===r&&(r=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||o(!1),t>=0||o(!1),R.DP=t,R.RM=T[r],new R(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)},h(t,[{key:"quotient",get:function(){return i.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(i.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),C=new O(i.BigInt(100)),U=function(t){function n(){return t.apply(this,arguments)||this}p(n,t);var r=n.prototype;return r.toSignificant=function(t,n,r){return void 0===t&&(t=5),this.multiply(C).toSignificant(t,n,r)},r.toFixed=function(t,n,r){return void 0===t&&(t=2),this.multiply(C).toFixed(t,n,r)},n}(O),_=s(u),A=function(t){function n(n,r){var e,a=i.BigInt(r);return i.lessThanOrEqual(a,c)||o(!1),(e=t.call(this,a,i.exponentiate(i.BigInt(10),i.BigInt(n.decimals)))||this).currency=n,e}p(n,t),n.ether=function(t){return new n(y,t)};var r=n.prototype;return r.add=function(t){return x(this.currency,t.currency)||o(!1),new n(this.currency,i.add(this.raw,t.raw))},r.subtract=function(t){return x(this.currency,t.currency)||o(!1),new n(this.currency,i.subtract(this.raw,t.raw))},r.toSignificant=function(n,r,e){return void 0===n&&(n=6),void 0===e&&(e=exports.Rounding.ROUND_DOWN),t.prototype.toSignificant.call(this,n,r,e)},r.toFixed=function(n,r,e){return void 0===n&&(n=this.currency.decimals),void 0===e&&(e=exports.Rounding.ROUND_DOWN),n<=this.currency.decimals||o(!1),t.prototype.toFixed.call(this,n,r,e)},r.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),_.DP=this.currency.decimals,new _(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},h(n,[{key:"raw",get:function(){return this.numerator}}]),n}(O),B=function(t){function n(n,r){var e;return(e=t.call(this,n,r)||this).token=n,e}p(n,t);var r=n.prototype;return r.add=function(t){return this.token.equals(t.token)||o(!1),new n(this.token,i.add(this.raw,t.raw))},r.subtract=function(t){return this.token.equals(t.token)||o(!1),new n(this.token,i.subtract(this.raw,t.raw))},n}(A),D=function(t){function n(n,r,e,o){var a;return(a=t.call(this,o,e)||this).baseCurrency=n,a.quoteCurrency=r,a.scalar=new O(i.exponentiate(i.BigInt(10),i.BigInt(n.decimals)),i.exponentiate(i.BigInt(10),i.BigInt(r.decimals))),a}p(n,t);var r=n.prototype;return r.invert=function(){return new n(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},r.multiply=function(r){x(this.quoteCurrency,r.baseCurrency)||o(!1);var e=t.prototype.multiply.call(this,r);return new n(this.baseCurrency,r.quoteCurrency,e.denominator,e.numerator)},r.quote=function(n){return x(n.currency,this.baseCurrency)||o(!1),this.quoteCurrency instanceof g?new B(this.quoteCurrency,t.prototype.multiply.call(this,n.raw).quotient):A.ether(t.prototype.multiply.call(this,n.raw).quotient)},r.toSignificant=function(t,n,r){return void 0===t&&(t=6),this.adjusted.toSignificant(t,n,r)},r.toFixed=function(t,n,r){return void 0===t&&(t=4),this.adjusted.toFixed(t,n,r)},h(n,[{key:"raw",get:function(){return new O(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),n}(O),b=i.BigInt(Number.MAX_SAFE_INTEGER),q=i.BigInt(0),F=i.BigInt(1),P=i.BigInt(2);exports.Currency=m,exports.CurrencyAmount=A,exports.ETHER=y,exports.Fraction=O,exports.MaxUint256=c,exports.Percent=U,exports.Price=D,exports.Token=g,exports.TokenAmount=B,exports.WETH9=N,exports.currencyEquals=x,exports.sortedInsert=function(t,n,r,e){if(r>0||o(!1),t.length<=r||o(!1),0===t.length)return t.push(n),null;var i=t.length===r;if(i&&e(t[t.length-1],n)<=0)return n;for(var a=0,u=t.length;a<u;){var s=a+u>>>1;e(t[s],n)<=0?a=s+1:u=s}return t.splice(a,0,n),i?t.pop():null},exports.sqrt=function(t){if(i.greaterThanOrEqual(t,q)||o(!1),i.lessThan(t,b))return i.BigInt(Math.floor(Math.sqrt(i.toNumber(t))));var n,r;for(n=t,r=i.add(i.divide(t,P),F);i.lessThan(r,n);)n=r,r=i.divide(i.add(i.divide(t,r),r),P);return n},exports.validateAndParseAddress=function(t){try{return d.getAddress(t)}catch(n){throw new Error(t+" is not a valid address.")}}; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var n,r,e,i=t(require("jsbi")),o=t(require("tiny-invariant")),a=require("@ethersproject/address"),u=t(require("decimal.js-light")),s=t(require("big.js")),d=t(require("toformat"));(n=exports.ChainId||(exports.ChainId={}))[n.MAINNET=1]="MAINNET",n[n.ROPSTEN=3]="ROPSTEN",n[n.RINKEBY=4]="RINKEBY",n[n["GÖRLI"]=5]="GÖRLI",n[n.KOVAN=42]="KOVAN",(r=exports.TradeType||(exports.TradeType={}))[r.EXACT_INPUT=0]="EXACT_INPUT",r[r.EXACT_OUTPUT=1]="EXACT_OUTPUT",(e=exports.Rounding||(exports.Rounding={}))[e.ROUND_DOWN=0]="ROUND_DOWN",e[e.ROUND_HALF_UP=1]="ROUND_HALF_UP",e[e.ROUND_UP=2]="ROUND_UP";var c=i.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function f(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}function h(t,n,r){return n&&f(t.prototype,n),r&&f(t,r),t}function p(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}function l(t){try{return a.getAddress(t)}catch(n){throw new Error(t+" is not a valid address.")}}var m,y=function(t,n,r){t>=0&&t<255&&Number.isInteger(t)||o(!1),this.decimals=t,this.symbol=n,this.name=r},g=function(t){function n(n,r,e,i,o){var a;return(a=t.call(this,e,i,o)||this).isEther=!1,a.isToken=!0,a.chainId=n,a.address=l(r),a}p(n,t);var r=n.prototype;return r.equals=function(t){return this===t||this.chainId===t.chainId&&this.address===t.address},r.sortsBefore=function(t){return this.chainId!==t.chainId&&o(!1),this.address===t.address&&o(!1),this.address.toLowerCase()<t.address.toLowerCase()},n}(y),v=((m={})[exports.ChainId.MAINNET]=new g(exports.ChainId.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH9","Wrapped Ether"),m[exports.ChainId.ROPSTEN]=new g(exports.ChainId.ROPSTEN,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH9","Wrapped Ether"),m[exports.ChainId.RINKEBY]=new g(exports.ChainId.RINKEBY,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH9","Wrapped Ether"),m[exports.ChainId.GÖRLI]=new g(exports.ChainId.GÖRLI,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH9","Wrapped Ether"),m[exports.ChainId.KOVAN]=new g(exports.ChainId.KOVAN,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH9","Wrapped Ether"),m),I=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).isEther=!0,n.isToken=!1,n}return p(n,t),n}(y);I.ETHER=new I(18,"ETH","Ether");var x,N,E=I.ETHER,w=d(u),T=d(s),R=((x={})[exports.Rounding.ROUND_DOWN]=w.ROUND_DOWN,x[exports.Rounding.ROUND_HALF_UP]=w.ROUND_HALF_UP,x[exports.Rounding.ROUND_UP]=w.ROUND_UP,x),O=((N={})[exports.Rounding.ROUND_DOWN]=0,N[exports.Rounding.ROUND_HALF_UP]=1,N[exports.Rounding.ROUND_UP]=3,N),U=function(){function t(t,n){void 0===n&&(n=i.BigInt(1)),this.numerator=i.BigInt(t),this.denominator=i.BigInt(n)}var n=t.prototype;return n.invert=function(){return new t(this.denominator,this.numerator)},n.add=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.equal(this.denominator,r.denominator)?new t(i.add(this.numerator,r.numerator),this.denominator):new t(i.add(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator)),i.multiply(this.denominator,r.denominator))},n.subtract=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.equal(this.denominator,r.denominator)?new t(i.subtract(this.numerator,r.numerator),this.denominator):new t(i.subtract(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator)),i.multiply(this.denominator,r.denominator))},n.lessThan=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.lessThan(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator))},n.equalTo=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.equal(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator))},n.greaterThan=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return i.greaterThan(i.multiply(this.numerator,r.denominator),i.multiply(r.numerator,this.denominator))},n.multiply=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return new t(i.multiply(this.numerator,r.numerator),i.multiply(this.denominator,r.denominator))},n.divide=function(n){var r=n instanceof t?n:new t(i.BigInt(n));return new t(i.multiply(this.numerator,r.denominator),i.multiply(this.denominator,r.numerator))},n.toSignificant=function(t,n,r){void 0===n&&(n={groupSeparator:""}),void 0===r&&(r=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||o(!1),t>0||o(!1),w.set({precision:t+1,rounding:R[r]});var e=new w(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return e.toFormat(e.decimalPlaces(),n)},n.toFixed=function(t,n,r){return void 0===n&&(n={groupSeparator:""}),void 0===r&&(r=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||o(!1),t>=0||o(!1),T.DP=t,T.RM=O[r],new T(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)},h(t,[{key:"quotient",get:function(){return i.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(i.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),_=new U(i.BigInt(100)),C=function(t){function n(){return t.apply(this,arguments)||this}p(n,t);var r=n.prototype;return r.toSignificant=function(t,n,r){return void 0===t&&(t=5),this.multiply(_).toSignificant(t,n,r)},r.toFixed=function(t,n,r){return void 0===t&&(t=2),this.multiply(_).toFixed(t,n,r)},n}(U),A=i.BigInt(Number.MAX_SAFE_INTEGER),B=i.BigInt(0),D=i.BigInt(1),b=i.BigInt(2);function q(t,n){return t.isToken&&n.isToken?t.equals(n):!t.isToken&&!n.isToken&&t.isEther===n.isEther}var F=d(s),P=function(t){function n(n,r){var e,a=i.BigInt(r);return i.lessThanOrEqual(a,c)||o(!1),(e=t.call(this,a,i.exponentiate(i.BigInt(10),i.BigInt(n.decimals)))||this).currency=n,e}p(n,t),n.ether=function(t){return new n(E,t)};var r=n.prototype;return r.add=function(t){return q(this.currency,t.currency)||o(!1),new n(this.currency,i.add(this.raw,t.raw))},r.subtract=function(t){return q(this.currency,t.currency)||o(!1),new n(this.currency,i.subtract(this.raw,t.raw))},r.toSignificant=function(n,r,e){return void 0===n&&(n=6),void 0===e&&(e=exports.Rounding.ROUND_DOWN),t.prototype.toSignificant.call(this,n,r,e)},r.toFixed=function(n,r,e){return void 0===n&&(n=this.currency.decimals),void 0===e&&(e=exports.Rounding.ROUND_DOWN),n<=this.currency.decimals||o(!1),t.prototype.toFixed.call(this,n,r,e)},r.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),F.DP=this.currency.decimals,new F(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},h(n,[{key:"raw",get:function(){return this.numerator}}]),n}(U),S=function(t){function n(n,r){var e;return(e=t.call(this,n,r)||this).token=n,e}p(n,t);var r=n.prototype;return r.add=function(t){return this.token.equals(t.token)||o(!1),new n(this.token,i.add(this.raw,t.raw))},r.subtract=function(t){return this.token.equals(t.token)||o(!1),new n(this.token,i.subtract(this.raw,t.raw))},n}(P),k=function(t){function n(n,r,e,o){var a;return(a=t.call(this,o,e)||this).baseCurrency=n,a.quoteCurrency=r,a.scalar=new U(i.exponentiate(i.BigInt(10),i.BigInt(n.decimals)),i.exponentiate(i.BigInt(10),i.BigInt(r.decimals))),a}p(n,t);var r=n.prototype;return r.invert=function(){return new n(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},r.multiply=function(r){q(this.quoteCurrency,r.baseCurrency)||o(!1);var e=t.prototype.multiply.call(this,r);return new n(this.baseCurrency,r.quoteCurrency,e.denominator,e.numerator)},r.quote=function(n){return q(n.currency,this.baseCurrency)||o(!1),this.quoteCurrency instanceof g?new S(this.quoteCurrency,t.prototype.multiply.call(this,n.raw).quotient):P.ether(t.prototype.multiply.call(this,n.raw).quotient)},r.toSignificant=function(t,n,r){return void 0===t&&(t=6),this.adjusted.toSignificant(t,n,r)},r.toFixed=function(t,n,r){return void 0===t&&(t=4),this.adjusted.toFixed(t,n,r)},h(n,[{key:"raw",get:function(){return new U(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),n}(U);exports.CurrencyAmount=P,exports.ETHER=E,exports.Ether=I,exports.Fraction=U,exports.MaxUint256=c,exports.Percent=C,exports.Price=k,exports.Token=g,exports.TokenAmount=S,exports.WETH9=v,exports.currencyEquals=q,exports.sortedInsert=function(t,n,r,e){if(r>0||o(!1),t.length<=r||o(!1),0===t.length)return t.push(n),null;var i=t.length===r;if(i&&e(t[t.length-1],n)<=0)return n;for(var a=0,u=t.length;a<u;){var s=a+u>>>1;e(t[s],n)<=0?a=s+1:u=s}return t.splice(a,0,n),i?t.pop():null},exports.sqrt=function(t){if(i.greaterThanOrEqual(t,B)||o(!1),i.lessThan(t,A))return i.BigInt(Math.floor(Math.sqrt(i.toNumber(t))));var n,r;for(n=t,r=i.add(i.divide(t,b),D);i.lessThan(r,n);)n=r,r=i.divide(i.add(i.divide(t,r),r),b);return n},exports.validateAndParseAddress=l; | ||
//# sourceMappingURL=sdk-core.cjs.production.min.js.map |
import JSBI from 'jsbi'; | ||
import invariant from 'tiny-invariant'; | ||
import { getAddress } from '@ethersproject/address'; | ||
import _Decimal from 'decimal.js-light'; | ||
import _Big from 'big.js'; | ||
import toFormat from 'toformat'; | ||
import { getAddress } from '@ethersproject/address'; | ||
@@ -58,2 +58,15 @@ var ChainId; | ||
/** | ||
* Validates an address and returns the parsed (checksummed) version of that address | ||
* @param address the unchecksummed hex address | ||
*/ | ||
function validateAndParseAddress(address) { | ||
try { | ||
return getAddress(address); | ||
} catch (error) { | ||
throw new Error(address + " is not a valid address."); | ||
} | ||
} | ||
/** | ||
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens. | ||
@@ -64,3 +77,3 @@ * | ||
var Currency = | ||
var BaseCurrency = | ||
/** | ||
@@ -72,4 +85,4 @@ * Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`. | ||
*/ | ||
function Currency(decimals, symbol, name) { | ||
!(decimals < 255) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DECIMALS') : invariant(false) : void 0; | ||
function BaseCurrency(decimals, symbol, name) { | ||
!(decimals >= 0 && decimals < 255 && Number.isInteger(decimals)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DECIMALS') : invariant(false) : void 0; | ||
this.decimals = decimals; | ||
@@ -79,9 +92,3 @@ this.symbol = symbol; | ||
}; | ||
/** | ||
* The only instance of the base class `Currency`. | ||
*/ | ||
Currency.ETHER = /*#__PURE__*/new Currency(18, 'ETH', 'Ether'); | ||
var ETHER = Currency.ETHER; | ||
var _WETH; | ||
@@ -92,4 +99,4 @@ /** | ||
var Token = /*#__PURE__*/function (_Currency) { | ||
_inheritsLoose(Token, _Currency); | ||
var Token = /*#__PURE__*/function (_BaseCurrency) { | ||
_inheritsLoose(Token, _BaseCurrency); | ||
@@ -99,6 +106,7 @@ function Token(chainId, address, decimals, symbol, name) { | ||
_this = _Currency.call(this, decimals, symbol, name) || this; | ||
!(address.length === 42 && address.slice(0, 2) === '0x') ? process.env.NODE_ENV !== "production" ? invariant(false, 'ADDRESS') : invariant(false) : void 0; | ||
_this = _BaseCurrency.call(this, decimals, symbol, name) || this; | ||
_this.isEther = false; | ||
_this.isToken = true; | ||
_this.chainId = chainId; | ||
_this.address = address; | ||
_this.address = validateAndParseAddress(address); | ||
return _this; | ||
@@ -137,19 +145,25 @@ } | ||
return Token; | ||
}(Currency); | ||
}(BaseCurrency); | ||
var WETH9 = (_WETH = {}, _WETH[ChainId.MAINNET] = /*#__PURE__*/new Token(ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.ROPSTEN] = /*#__PURE__*/new Token(ChainId.ROPSTEN, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.RINKEBY] = /*#__PURE__*/new Token(ChainId.RINKEBY, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.GÖRLI] = /*#__PURE__*/new Token(ChainId.GÖRLI, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.KOVAN] = /*#__PURE__*/new Token(ChainId.KOVAN, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH9', 'Wrapped Ether'), _WETH); | ||
var Ether = /*#__PURE__*/function (_BaseCurrency) { | ||
_inheritsLoose(Ether, _BaseCurrency); | ||
function Ether() { | ||
var _this; | ||
_this = _BaseCurrency.apply(this, arguments) || this; | ||
_this.isEther = true; | ||
_this.isToken = false; | ||
return _this; | ||
} | ||
return Ether; | ||
}(BaseCurrency); | ||
/** | ||
* Compares two currencies for equality | ||
* The only instance of the base class `Currency`. | ||
*/ | ||
function currencyEquals(currencyA, currencyB) { | ||
if (currencyA instanceof Token && currencyB instanceof Token) { | ||
return currencyA.equals(currencyB); | ||
} else if (currencyA instanceof Token) { | ||
return false; | ||
} else if (currencyB instanceof Token) { | ||
return false; | ||
} else { | ||
return currencyA === currencyB; | ||
} | ||
} | ||
var WETH9 = (_WETH = {}, _WETH[ChainId.MAINNET] = /*#__PURE__*/new Token(ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.ROPSTEN] = /*#__PURE__*/new Token(ChainId.ROPSTEN, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.RINKEBY] = /*#__PURE__*/new Token(ChainId.RINKEBY, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.GÖRLI] = /*#__PURE__*/new Token(ChainId.GÖRLI, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.KOVAN] = /*#__PURE__*/new Token(ChainId.KOVAN, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH9', 'Wrapped Ether'), _WETH); | ||
Ether.ETHER = /*#__PURE__*/new Ether(18, 'ETH', 'Ether'); | ||
var ETHER = Ether.ETHER; | ||
@@ -309,2 +323,81 @@ var _toSignificantRoundin, _toFixedRounding; | ||
// `maxSize` by removing the last item | ||
function sortedInsert(items, add, maxSize, comparator) { | ||
!(maxSize > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_SIZE_ZERO') : invariant(false) : void 0; // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize | ||
!(items.length <= maxSize) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ITEMS_SIZE') : invariant(false) : void 0; // short circuit first item add | ||
if (items.length === 0) { | ||
items.push(add); | ||
return null; | ||
} else { | ||
var isFull = items.length === maxSize; // short circuit if full and the additional item does not come before the last item | ||
if (isFull && comparator(items[items.length - 1], add) <= 0) { | ||
return add; | ||
} | ||
var lo = 0, | ||
hi = items.length; | ||
while (lo < hi) { | ||
var mid = lo + hi >>> 1; | ||
if (comparator(items[mid], add) <= 0) { | ||
lo = mid + 1; | ||
} else { | ||
hi = mid; | ||
} | ||
} | ||
items.splice(lo, 0, add); | ||
return isFull ? items.pop() : null; | ||
} | ||
} | ||
var MAX_SAFE_INTEGER = /*#__PURE__*/JSBI.BigInt(Number.MAX_SAFE_INTEGER); | ||
var ZERO = /*#__PURE__*/JSBI.BigInt(0); | ||
var ONE = /*#__PURE__*/JSBI.BigInt(1); | ||
var TWO = /*#__PURE__*/JSBI.BigInt(2); | ||
/** | ||
* Computes floor(sqrt(value)) | ||
* @param value the value for which to compute the square root, rounded down | ||
*/ | ||
function sqrt(value) { | ||
!JSBI.greaterThanOrEqual(value, ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, 'NEGATIVE') : invariant(false) : void 0; // rely on built in sqrt if possible | ||
if (JSBI.lessThan(value, MAX_SAFE_INTEGER)) { | ||
return JSBI.BigInt(Math.floor(Math.sqrt(JSBI.toNumber(value)))); | ||
} | ||
var z; | ||
var x; | ||
z = value; | ||
x = JSBI.add(JSBI.divide(value, TWO), ONE); | ||
while (JSBI.lessThan(x, z)) { | ||
z = x; | ||
x = JSBI.divide(JSBI.add(JSBI.divide(value, x), x), TWO); | ||
} | ||
return z; | ||
} | ||
/** | ||
* Compares two currencies for equality | ||
*/ | ||
function currencyEquals(currencyA, currencyB) { | ||
if (currencyA.isToken && currencyB.isToken) { | ||
return currencyA.equals(currencyB); | ||
} else if (currencyA.isToken) { | ||
return false; | ||
} else if (currencyB.isToken) { | ||
return false; | ||
} else { | ||
return currencyA.isEther === currencyB.isEther; | ||
} | ||
} | ||
var Big$1 = /*#__PURE__*/toFormat(_Big); | ||
@@ -490,80 +583,3 @@ | ||
// `maxSize` by removing the last item | ||
function sortedInsert(items, add, maxSize, comparator) { | ||
!(maxSize > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_SIZE_ZERO') : invariant(false) : void 0; // this is an invariant because the interface cannot return multiple removed items if items.length exceeds maxSize | ||
!(items.length <= maxSize) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ITEMS_SIZE') : invariant(false) : void 0; // short circuit first item add | ||
if (items.length === 0) { | ||
items.push(add); | ||
return null; | ||
} else { | ||
var isFull = items.length === maxSize; // short circuit if full and the additional item does not come before the last item | ||
if (isFull && comparator(items[items.length - 1], add) <= 0) { | ||
return add; | ||
} | ||
var lo = 0, | ||
hi = items.length; | ||
while (lo < hi) { | ||
var mid = lo + hi >>> 1; | ||
if (comparator(items[mid], add) <= 0) { | ||
lo = mid + 1; | ||
} else { | ||
hi = mid; | ||
} | ||
} | ||
items.splice(lo, 0, add); | ||
return isFull ? items.pop() : null; | ||
} | ||
} | ||
/** | ||
* Validates an address and returns the parsed (checksummed) version of that address | ||
* @param address the unchecksummed hex address | ||
*/ | ||
function validateAndParseAddress(address) { | ||
try { | ||
return getAddress(address); | ||
} catch (error) { | ||
throw new Error(address + " is not a valid address."); | ||
} | ||
} | ||
var MAX_SAFE_INTEGER = /*#__PURE__*/JSBI.BigInt(Number.MAX_SAFE_INTEGER); | ||
var ZERO = /*#__PURE__*/JSBI.BigInt(0); | ||
var ONE = /*#__PURE__*/JSBI.BigInt(1); | ||
var TWO = /*#__PURE__*/JSBI.BigInt(2); | ||
/** | ||
* Computes floor(sqrt(value)) | ||
* @param value the value for which to compute the square root, rounded down | ||
*/ | ||
function sqrt(value) { | ||
!JSBI.greaterThanOrEqual(value, ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, 'NEGATIVE') : invariant(false) : void 0; // rely on built in sqrt if possible | ||
if (JSBI.lessThan(value, MAX_SAFE_INTEGER)) { | ||
return JSBI.BigInt(Math.floor(Math.sqrt(JSBI.toNumber(value)))); | ||
} | ||
var z; | ||
var x; | ||
z = value; | ||
x = JSBI.add(JSBI.divide(value, TWO), ONE); | ||
while (JSBI.lessThan(x, z)) { | ||
z = x; | ||
x = JSBI.divide(JSBI.add(JSBI.divide(value, x), x), TWO); | ||
} | ||
return z; | ||
} | ||
export { ChainId, Currency, CurrencyAmount, ETHER, Fraction, MaxUint256, Percent, Price, Rounding, Token, TokenAmount, TradeType, WETH9, currencyEquals, sortedInsert, sqrt, validateAndParseAddress }; | ||
export { ChainId, CurrencyAmount, ETHER, Ether, Fraction, MaxUint256, Percent, Price, Rounding, Token, TokenAmount, TradeType, WETH9, currencyEquals, sortedInsert, sqrt, validateAndParseAddress }; | ||
//# sourceMappingURL=sdk-core.esm.js.map |
@@ -5,1 +5,2 @@ import sortedInsert from './sortedInsert'; | ||
export { sortedInsert, validateAndParseAddress, sqrt }; | ||
export { currencyEquals } from './currencyEquals'; |
{ | ||
"name": "@uniswap/sdk-core", | ||
"license": "MIT", | ||
"version": "1.0.11", | ||
"version": "2.0.0", | ||
"description": "⚒️ An SDK for building applications on top of Uniswap V3", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
157700
28
1148
0
20