UNPKG

@kyberswap/ks-sdk-core

Version:

đź›  An CORE SDK for building DMM Classic SDK, Elastic SDK

3 lines (2 loc) • 13.4 kB
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var r,e,n=t(require("jsbi")),i=t(require("tiny-invariant")),o=t(require("decimal.js-light")),a=t(require("big.js")),u=t(require("toformat")),s=require("@ethersproject/address");(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 d,c,p=n.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function h(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,m(n.key),n)}}function f(t,r,e){return r&&h(t.prototype,r),e&&h(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function l(t,r){t.prototype=Object.create(r.prototype),t.prototype.constructor=t,function(t,r){(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t})(t,r)}(t,r)}function m(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof r?r:r+""}var I=u(o),y=u(a),A=((d={})[exports.Rounding.ROUND_DOWN]=I.ROUND_DOWN,d[exports.Rounding.ROUND_HALF_UP]=I.ROUND_HALF_UP,d[exports.Rounding.ROUND_UP]=I.ROUND_UP,d),C=((c={})[exports.Rounding.ROUND_DOWN]=0,c[exports.Rounding.ROUND_HALF_UP]=1,c[exports.Rounding.ROUND_UP]=3,c),N=function(){function t(t,r){void 0===r&&(r=n.BigInt(1)),this.numerator=n.BigInt(t),this.denominator=n.BigInt(r)}t.tryParseFraction=function(r){if(r instanceof n||"number"==typeof r||"string"==typeof r)return new t(r);if("numerator"in r&&"denominator"in r)return r;throw new Error("Could not parse fraction")};var r=t.prototype;return r.invert=function(){return new t(this.denominator,this.numerator)},r.add=function(r){var e=t.tryParseFraction(r);return n.equal(this.denominator,e.denominator)?new t(n.add(this.numerator,e.numerator),this.denominator):new t(n.add(n.multiply(this.numerator,e.denominator),n.multiply(e.numerator,this.denominator)),n.multiply(this.denominator,e.denominator))},r.subtract=function(r){var e=t.tryParseFraction(r);return n.equal(this.denominator,e.denominator)?new t(n.subtract(this.numerator,e.numerator),this.denominator):new t(n.subtract(n.multiply(this.numerator,e.denominator),n.multiply(e.numerator,this.denominator)),n.multiply(this.denominator,e.denominator))},r.lessThan=function(r){var e=t.tryParseFraction(r);return n.lessThan(n.multiply(this.numerator,e.denominator),n.multiply(e.numerator,this.denominator))},r.equalTo=function(r){var e=t.tryParseFraction(r);return n.equal(n.multiply(this.numerator,e.denominator),n.multiply(e.numerator,this.denominator))},r.greaterThan=function(r){var e=t.tryParseFraction(r);return n.greaterThan(n.multiply(this.numerator,e.denominator),n.multiply(e.numerator,this.denominator))},r.multiply=function(r){var e=t.tryParseFraction(r);return new t(n.multiply(this.numerator,e.numerator),n.multiply(this.denominator,e.denominator))},r.divide=function(r){var e=t.tryParseFraction(r);return new t(n.multiply(this.numerator,e.denominator),n.multiply(this.denominator,e.numerator))},r.toSignificant=function(t,r,e){void 0===r&&(r={groupSeparator:""}),void 0===e&&(e=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||i(!1),t>0||i(!1),I.set({precision:t+1,rounding:A[e]});var n=new I(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return n.toFormat(n.decimalPlaces(),r)},r.toFixed=function(t,r,e){return void 0===r&&(r={groupSeparator:""}),void 0===e&&(e=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||i(!1),t>=0||i(!1),y.DP=t,y.RM=C[e],new y(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)},f(t,[{key:"quotient",get:function(){return n.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(n.remainder(this.numerator,this.denominator),this.denominator)}},{key:"asFraction",get:function(){return new t(this.numerator,this.denominator)}}])}(),x=u(a),v=function(t){function r(r,e,o){var a;return a=t.call(this,e,o)||this,n.lessThanOrEqual(a.quotient,p)||i(!1),a.currency=r,a.decimalScale=n.exponentiate(n.BigInt(10),n.BigInt(r.decimals)),a}l(r,t),r.fromRawAmount=function(t,e){return new r(t,e)},r.fromFractionalAmount=function(t,e,n){return new r(t,e,n)};var e=r.prototype;return e.add=function(e){this.currency.equals(e.currency)||i(!1);var n=t.prototype.add.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},e.subtract=function(e){this.currency.equals(e.currency)||i(!1);var n=t.prototype.subtract.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},e.multiply=function(e){var n=t.prototype.multiply.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},e.divide=function(e){var n=t.prototype.divide.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},e.toSignificant=function(r,e,n){return void 0===r&&(r=6),void 0===n&&(n=exports.Rounding.ROUND_DOWN),t.prototype.divide.call(this,this.decimalScale).toSignificant(r,e,n)},e.toFixed=function(r,e,n){return void 0===r&&(r=this.currency.decimals),void 0===n&&(n=exports.Rounding.ROUND_DOWN),r<=this.currency.decimals||i(!1),t.prototype.divide.call(this,this.decimalScale).toFixed(r,e,n)},e.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),x.DP=this.currency.decimals,new x(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(t)},f(r,[{key:"wrapped",get:function(){return this.currency.isToken?this:r.fromFractionalAmount(this.currency.wrapped,this.numerator,this.denominator)}}])}(N),E=function(t){function r(){return t.apply(this,arguments)||this}return l(r,t),r}(v),T=new N(n.BigInt(100));function g(t){return new R(t.numerator,t.denominator)}var b,R=function(t){function r(){var r;return(r=t.apply(this,arguments)||this).isPercent=!0,r}l(r,t);var e=r.prototype;return e.add=function(r){return g(t.prototype.add.call(this,r))},e.subtract=function(r){return g(t.prototype.subtract.call(this,r))},e.multiply=function(r){return g(t.prototype.multiply.call(this,r))},e.divide=function(r){return g(t.prototype.divide.call(this,r))},e.toSignificant=function(r,e,n){return void 0===r&&(r=5),t.prototype.multiply.call(this,T).toSignificant(r,e,n)},e.toFixed=function(r,e,n){return void 0===r&&(r=2),t.prototype.multiply.call(this,T).toFixed(r,e,n)},r}(N),w=function(t){function r(){for(var r,e,i,o,a,u=arguments.length,s=new Array(u),d=0;d<u;d++)s[d]=arguments[d];if(4===s.length)e=s[0],i=s[1],o=s[2],a=s[3];else{var c=s[0].quoteAmount.divide(s[0].baseAmount),p=[s[0].baseAmount.currency,s[0].quoteAmount.currency,c.denominator,c.numerator];e=p[0],i=p[1],o=p[2],a=p[3]}return(r=t.call(this,a,o)||this).baseCurrency=e,r.quoteCurrency=i,r.scalar=new N(n.exponentiate(n.BigInt(10),n.BigInt(e.decimals)),n.exponentiate(n.BigInt(10),n.BigInt(i.decimals))),r}l(r,t);var e=r.prototype;return e.invert=function(){return new r(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},e.multiply=function(e){this.quoteCurrency.equals(e.baseCurrency)||i(!1);var n=t.prototype.multiply.call(this,e);return new r(this.baseCurrency,e.quoteCurrency,n.denominator,n.numerator)},e.quote=function(r){r.currency.equals(this.baseCurrency)||i(!1);var e=t.prototype.multiply.call(this,r);return v.fromFractionalAmount(this.quoteCurrency,e.numerator,e.denominator)},e.toSignificant=function(t,r,e){return void 0===t&&(t=6),this.adjustedForDecimals.toSignificant(t,r,e)},e.toFixed=function(t,r,e){return void 0===t&&(t=4),this.adjustedForDecimals.toFixed(t,r,e)},f(r,[{key:"adjustedForDecimals",get:function(){return t.prototype.multiply.call(this,this.scalar)}}])}(N);(b=exports.ChainId||(exports.ChainId={}))[b.MAINNET=1]="MAINNET",b[b["GĂ–RLI"]=5]="GĂ–RLI",b[b.MATIC=137]="MATIC",b[b.BSCMAINNET=56]="BSCMAINNET",b[b.AVAXMAINNET=43114]="AVAXMAINNET",b[b.FANTOM=250]="FANTOM",b[b.ARBITRUM=42161]="ARBITRUM",b[b.OPTIMISM=10]="OPTIMISM",b[b.ZKSYNC=324]="ZKSYNC",b[b.LINEA=59144]="LINEA",b[b.BASE=8453]="BASE",b[b.SCROLL=534352]="SCROLL",b[b.BLAST=81457]="BLAST",b[b.MANTLE=5e3]="MANTLE",b[b.SONIC=146]="SONIC",b[b.BERA=80094]="BERA",b[b.RONIN=2020]="RONIN",b[b.UNICHAIN=130]="UNICHAIN",b[b.HYPEREVM=999]="HYPEREVM";var O=function(t,r,e,n){Number.isSafeInteger(t)||i(!1),t in exports.ChainId||i(!1),r>=0&&r<255&&Number.isInteger(r)||i(!1),this.chainId=t,this.decimals=r,this.symbol=e,this.name=n};function B(t){try{return s.getAddress(t)}catch(r){throw new Error(t+" is not a valid address.")}}var F,S=function(t){function r(r,e,n,i,o){var a;return(a=t.call(this,r,n,i,o)||this).isNative=!1,a.isToken=!0,a.address=B(e),a}l(r,t);var e=r.prototype;return e.equals=function(t){return t.isToken&&this.chainId===t.chainId&&this.address===t.address},e.sortsBefore=function(t){return this.chainId!==t.chainId&&i(!1),this.address===t.address&&i(!1),this.address.toLowerCase()<t.address.toLowerCase()},f(r,[{key:"wrapped",get:function(){return this}}])}(O),D=((F={})[exports.ChainId.MAINNET]=new S(exports.ChainId.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),F[exports.ChainId.GĂ–RLI]=new S(exports.ChainId.GĂ–RLI,"0x48f6D7dAE56623Dde5a0D56B283165cAE1753D70",18,"WETH","Wrapped Ether"),F[exports.ChainId.MATIC]=new S(exports.ChainId.MATIC,"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",18,"WMATIC","Wrapped Matic"),F[exports.ChainId.BSCMAINNET]=new S(exports.ChainId.BSCMAINNET,"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",18,"WBNB","Wrapped BNB"),F[exports.ChainId.AVAXMAINNET]=new S(exports.ChainId.AVAXMAINNET,"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",18,"WAVAX","Wrapped AVAX"),F[exports.ChainId.FANTOM]=new S(exports.ChainId.FANTOM,"0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83",18,"WFTM","Wrapped Fantom"),F[exports.ChainId.ARBITRUM]=new S(exports.ChainId.ARBITRUM,"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",18,"WETH","Wrapped Ether"),F[exports.ChainId.OPTIMISM]=new S(exports.ChainId.OPTIMISM,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),F[exports.ChainId.ZKSYNC]=new S(exports.ChainId.ZKSYNC,"0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91",18,"WETH","Wrapped Ether"),F[exports.ChainId.LINEA]=new S(exports.ChainId.LINEA,"0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",18,"WETH","Wrapped Ether"),F[exports.ChainId.BASE]=new S(exports.ChainId.BASE,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),F[exports.ChainId.SCROLL]=new S(exports.ChainId.SCROLL,"0x5300000000000000000000000000000000000004",18,"WETH","Wrapped Ether"),F[exports.ChainId.BLAST]=new S(exports.ChainId.BLAST,"0x4300000000000000000000000000000000000004",18,"WETH","Wrapped Ether"),F[exports.ChainId.MANTLE]=new S(exports.ChainId.MANTLE,"0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8",18,"WMNT","Wrapped Mantle"),F[exports.ChainId.SONIC]=new S(exports.ChainId.SONIC,"0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38",18,"wS","Wrapped S"),F[exports.ChainId.BERA]=new S(exports.ChainId.BERA,"0x6969696969696969696969696969696969696969",18,"wBera","Wrapped Bera"),F[exports.ChainId.RONIN]=new S(exports.ChainId.RONIN,"0xe514d9deb7966c8be0ca922de8a064264ea6bcd4",18,"WRON","Wrapped Ronin"),F[exports.ChainId.UNICHAIN]=new S(exports.ChainId.UNICHAIN,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped ETH"),F[exports.ChainId.HYPEREVM]=new S(exports.ChainId.HYPEREVM,"0x5555555555555555555555555555555555555555",18,"WHYPE","Wrapped HYPE"),F),M=function(t){function r(r,e,n,i){var o;return(o=t.call(this,r,e,n,i)||this).isNative=!0,o.isToken=!1,o}return l(r,t),r.prototype.equals=function(t){return t.isNative&&t.chainId===this.chainId},f(r,[{key:"wrapped",get:function(){return D[this.chainId]}}])}(O),P=function(t){function r(r){return t.call(this,r,18,"ETH","Ether")||this}return l(r,t),r.onChain=function(t){var e;return null!=(e=this._etherCache[t])?e:this._etherCache[t]=new r(t)},r.prototype.equals=function(t){return t.isNative&&t.chainId===this.chainId},f(r,[{key:"wrapped",get:function(){var t=D[this.chainId];return t||i(!1),t}}])}(M);P._etherCache={};var U=n.BigInt(Number.MAX_SAFE_INTEGER),W=n.BigInt(0),_=n.BigInt(1),q=n.BigInt(2);exports.CurrencyAmount=v,exports.Ether=P,exports.Fraction=N,exports.MaxUint256=p,exports.NativeCurrency=M,exports.Percent=R,exports.Price=w,exports.Token=S,exports.TokenAmount=E,exports.WETH=D,exports.computePriceImpact=function(t,r,e){var n=t.quote(r),i=n.subtract(e).divide(n);return new R(i.numerator,i.denominator)},exports.sortedInsert=function(t,r,e,n){if(e>0||i(!1),t.length<=e||i(!1),0===t.length)return t.push(r),null;var o=t.length===e;if(o&&n(t[t.length-1],r)<=0)return r;for(var a=0,u=t.length;a<u;){var s=a+u>>>1;n(t[s],r)<=0?a=s+1:u=s}return t.splice(a,0,r),o?t.pop():null},exports.sqrt=function(t){if(n.greaterThanOrEqual(t,W)||i(!1),n.lessThan(t,U))return n.BigInt(Math.floor(Math.sqrt(n.toNumber(t))));var r,e;for(r=t,e=n.add(n.divide(t,q),_);n.lessThan(e,r);)r=e,e=n.divide(n.add(n.divide(t,e),e),q);return r},exports.validateAndParseAddress=B; //# sourceMappingURL=ks-sdk-core.cjs.production.min.js.map