UNPKG

@namgold/ks-sdk-core

Version:

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

3 lines (2 loc) • 14.3 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=t(require("bn.js")),d=require("@solana/web3.js"),c=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 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,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,(Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}var m,A,T,I,y,C=function(t){return new s(t.toString())},x=u(o),N=u(a),E=((m={})[exports.Rounding.ROUND_DOWN]=x.ROUND_DOWN,m[exports.Rounding.ROUND_HALF_UP]=x.ROUND_HALF_UP,m[exports.Rounding.ROUND_UP]=x.ROUND_UP,m),B=((A={})[exports.Rounding.ROUND_DOWN]=0,A[exports.Rounding.ROUND_HALF_UP]=1,A[exports.Rounding.ROUND_UP]=3,A),g=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),x.set({precision:t+1,rounding:E[e]});var n=new x(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),N.DP=t,N.RM=B[e],new N(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)},f(t,[{key:"numberatorBN",get:function(){return C(this.numerator)}},{key:"denominatorBN",get:function(){return C(this.denominator)}},{key:"quotient",get:function(){return n.divide(this.numerator,this.denominator)}},{key:"quotientBN",get:function(){return C(this.quotient)}},{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)}}]),t}();function v(t){return t===exports.ChainId.SOLANA?exports.ChainType.SOLANA:exports.ChainType.EVM}(T=exports.ChainId||(exports.ChainId={}))[T.MAINNET=1]="MAINNET",T[T["GĂ–RLI"]=5]="GĂ–RLI",T[T.MATIC=137]="MATIC",T[T.MUMBAI=80001]="MUMBAI",T[T.BSCTESTNET=97]="BSCTESTNET",T[T.BSCMAINNET=56]="BSCMAINNET",T[T.AVAXTESTNET=43113]="AVAXTESTNET",T[T.AVAXMAINNET=43114]="AVAXMAINNET",T[T.FANTOM=250]="FANTOM",T[T.CRONOS=25]="CRONOS",T[T.ARBITRUM=42161]="ARBITRUM",T[T.ARBITRUM_TESTNET=421611]="ARBITRUM_TESTNET",T[T.BTTC=199]="BTTC",T[T.VELAS=106]="VELAS",T[T.AURORA=1313161554]="AURORA",T[T.OASIS=42262]="OASIS",T[T.OPTIMISM=10]="OPTIMISM",T[T.SOLANA=101]="SOLANA",T[T.ETHW=10001]="ETHW",(I=exports.ChainType||(exports.ChainType={})).EVM="EVM",I.SOLANA="SOLANA";var S,O=n.BigInt(1),R=n.BigInt(0);!function(t){t.u64="u64",t.U256="U256"}(S||(S={}));var b=((y={})[S.u64]=n.subtract(n.exponentiate(n.BigInt(2),n.BigInt(64)),O),y[S.U256]=n.subtract(n.exponentiate(n.BigInt(2),n.BigInt(256)),O),y),w=u(a),D=function(t){function r(r,e,o){var a,u,s;return u=(a=t.call(this,e,o)||this).quotient,(s=v(r.chainId))===exports.ChainType.SOLANA&&function(t,r){n.greaterThanOrEqual(t,R)||i(!1),n.lessThanOrEqual(t,b[r])||i(!1)}(u,S.u64),s===exports.ChainType.EVM&&(n.lessThanOrEqual(u,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 instanceof s?e.toString():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:""}),w.DP=this.currency.decimals,new w(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)}}]),r}(g),M=function(t){function r(){return t.apply(this,arguments)||this}return l(r,t),r}(D),F=new g(n.BigInt(100));function U(t){return new W(t.numerator,t.denominator)}var W=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 U(t.prototype.add.call(this,r))},e.subtract=function(r){return U(t.prototype.subtract.call(this,r))},e.multiply=function(r){return U(t.prototype.multiply.call(this,r))},e.divide=function(r){return U(t.prototype.divide.call(this,r))},e.toSignificant=function(r,e,n){return void 0===r&&(r=5),t.prototype.multiply.call(this,F).toSignificant(r,e,n)},e.toFixed=function(r,e,n){return void 0===r&&(r=2),t.prototype.multiply.call(this,F).toFixed(r,e,n)},r}(g),_=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 a=n.multiply(n.BigInt(a),n.exponentiate(n.BigInt(10),n.BigInt(e.decimals))),o=n.multiply(n.BigInt(o),n.exponentiate(n.BigInt(10),n.BigInt(i.decimals))),(r=t.call(this,a,o)||this).baseCurrency=e,r.quoteCurrency=i,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 D.fromFractionalAmount(this.quoteCurrency,e.numerator,e.denominator)},r}(g),P=function(t,r,e,n){Number.isSafeInteger(t)||i(!1),r>=0&&r<255&&Number.isInteger(r)||i(!1),this.chainId=t in exports.ChainId?t:exports.ChainId.MAINNET,this.decimals=r,this.symbol=e,this.name=n,this.chainType=v(this.chainId)};function q(t,r){try{if(v(r)===exports.ChainType.SOLANA){if(function(t){try{if(!t)return!1;var r=new d.PublicKey(t);return d.PublicKey.isOnCurve(r),!0}catch(t){return!1}}(t))return t;throw new Error(t+" is not a valid address.")}return c.getAddress(t)}catch(r){throw new Error(t+" is not a valid address.")}}var L,H=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=q(e,r),a.mint=a.chainType===exports.ChainType.SOLANA?new d.PublicKey(a.address):null,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.chainType===exports.ChainType.SOLANA?new s(this.mint.toBytes()).lt(new s(t.mint.toBytes())):this.address.toLowerCase()<t.address.toLowerCase()},f(r,[{key:"wrapped",get:function(){return this}}]),r}(P),V=((L={})[exports.ChainId.MAINNET]=new H(exports.ChainId.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),L[exports.ChainId.ETHW]=new H(exports.ChainId.ETHW,"0x7Bf88d2c0e32dE92CdaF2D43CcDc23e8Edfd5990",18,"WETHW","Wrapped ETHPoW"),L[exports.ChainId.GĂ–RLI]=new H(exports.ChainId.GĂ–RLI,"0x48f6D7dAE56623Dde5a0D56B283165cAE1753D70",18,"WETH","Wrapped Ether"),L[exports.ChainId.MATIC]=new H(exports.ChainId.MATIC,"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",18,"WMATIC","Wrapped Matic"),L[exports.ChainId.MUMBAI]=new H(exports.ChainId.MUMBAI,"0x19395624C030A11f58e820C3AeFb1f5960d9742a",18,"WMATIC","Wrapped Matic"),L[exports.ChainId.BSCTESTNET]=new H(exports.ChainId.BSCTESTNET,"0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",18,"WBNB","Wrapped BNB"),L[exports.ChainId.BSCMAINNET]=new H(exports.ChainId.BSCMAINNET,"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",18,"WBNB","Wrapped BNB"),L[exports.ChainId.AVAXTESTNET]=new H(exports.ChainId.AVAXTESTNET,"0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",18,"WAVAX","Wrapped AVAX"),L[exports.ChainId.AVAXMAINNET]=new H(exports.ChainId.AVAXMAINNET,"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",18,"WAVAX","Wrapped AVAX"),L[exports.ChainId.FANTOM]=new H(exports.ChainId.FANTOM,"0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83",18,"WFTM","Wrapped Fantom"),L[exports.ChainId.CRONOS]=new H(exports.ChainId.CRONOS,"0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23",18,"WCRO","Wrapped CRO"),L[exports.ChainId.ARBITRUM]=new H(exports.ChainId.ARBITRUM,"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",18,"WETH","Wrapped Ether"),L[exports.ChainId.ARBITRUM_TESTNET]=new H(exports.ChainId.ARBITRUM_TESTNET,"0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681",18,"WETH","Wrapped Ether"),L[exports.ChainId.BTTC]=new H(exports.ChainId.BTTC,"0x8D193c6efa90BCFf940A98785d1Ce9D093d3DC8A",18,"WBTT","Wrapped BitTorrent"),L[exports.ChainId.VELAS]=new H(exports.ChainId.VELAS,"0xc579D1f3CF86749E05CD06f7ADe17856c2CE3126",18,"WVLX","Wrapped VLX"),L[exports.ChainId.AURORA]=new H(exports.ChainId.AURORA,"0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB",18,"WETH","Wrapped ETH"),L[exports.ChainId.OASIS]=new H(exports.ChainId.OASIS,"0x21C718C22D52d0F3a789b752D4c2fD5908a8A733",18,"WROSE","Wrapped ROSE"),L[exports.ChainId.OPTIMISM]=new H(exports.ChainId.OPTIMISM,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),L[exports.ChainId.SOLANA]=new H(exports.ChainId.SOLANA,"So11111111111111111111111111111111111111112",9,"WSOL","Wrapped SOL"),L),X=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 V[this.chainId]}}]),r}(P),k=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=V[this.chainId];return t||i(!1),t}}]),r}(X);k._etherCache={};var j=n.BigInt(Number.MAX_SAFE_INTEGER),G=n.BigInt(0),K=n.BigInt(1),J=n.BigInt(2);exports.BNtoJSBI=function(t){return n.BigInt(t)},exports.CurrencyAmount=D,exports.Ether=k,exports.Fraction=g,exports.JSBItoBN=C,exports.MaxUint256=p,exports.NativeCurrency=X,exports.Percent=W,exports.Price=_,exports.Token=H,exports.TokenAmount=M,exports.WETH=V,exports.computePriceImpact=function(t,r,e){var n=t.quote(r),i=n.subtract(e).divide(n);return new W(i.numerator,i.denominator)},exports.getChainType=v,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,G)||i(!1),n.lessThan(t,j))return n.BigInt(Math.floor(Math.sqrt(n.toNumber(t))));var r,e;for(r=t,e=n.add(n.divide(t,J),K);n.lessThan(e,r);)r=e,e=n.divide(n.add(n.divide(t,e),e),J);return r},exports.validateAndParseAddress=q; //# sourceMappingURL=ks-sdk-core.cjs.production.min.js.map