@retherswap/sdk
Version:
🛠An SDK for building applications on top of Retherswap.
3 lines (2 loc) • 24.1 kB
JavaScript
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n,r,o,i=t(require("jsbi")),u=t(require("tiny-invariant")),a=(t(require("tiny-warning")),require("@ethersproject/address")),s=t(require("big.js")),c=t(require("toformat")),d=t(require("decimal.js-light")),p=require("@ethersproject/solidity"),f=require("@ethersproject/contracts"),l=require("@ethersproject/networks"),h=require("@ethersproject/providers"),m=t(require("@retherswap/core/build/IRetherswapPair.json"));(n=exports.ChainId||(exports.ChainId={}))[n.ETHEREUM=1]="ETHEREUM",n[n.HYPRA=622277]="HYPRA",n[n.BNB=56]="BNB",n[n.MATIC=137]="MATIC",(r=exports.TradeType||(exports.TradeType={}))[r.EXACT_INPUT=0]="EXACT_INPUT",r[r.EXACT_OUTPUT=1]="EXACT_OUTPUT",(o=exports.Rounding||(exports.Rounding={}))[o.ROUND_DOWN=0]="ROUND_DOWN",o[o.ROUND_HALF_UP=1]="ROUND_HALF_UP",o[o.ROUND_UP=2]="ROUND_UP";var v,y="0xde186f7c98a68bc92dccbea3473f931444ae359af8d48372ec6689eba1b7412c",w=i.BigInt(1e3),T=i.BigInt(0),g=i.BigInt(1),k=i.BigInt(2),x=i.BigInt(3),A=i.BigInt(5),b=i.BigInt(10),I=i.BigInt(100),E=i.BigInt(997),O=i.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(v||(v={}));var q=((e={})[v.uint8]=i.BigInt("0xff"),e[v.uint256]=i.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),e);function P(t,e,n){if(C())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,e);var o=new(t.bind.apply(t,r));return n&&S(o,n.prototype),o}function C(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(C=function(){return!!t})()}function R(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function U(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(r.key),r)}}function _(t,e,n){return e&&U(t.prototype,e),n&&U(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function D(){return(D=Object.assign?Object.assign.bind():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 B(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,S(t,e)}function N(t){return(N=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function S(t,e){return(S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function F(t){var e="function"==typeof Map?new Map:void 0;return(F=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return P(t,arguments,N(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),S(n,t)})(t)}function H(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function j(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function M(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return j(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?j(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var W="setPrototypeOf"in Object,X=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(H(n),(this instanceof e?this.constructor:void 0).prototype),n}return B(e,t),e}(F(Error)),L=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(H(n),(this instanceof e?this.constructor:void 0).prototype),n}return B(e,t),e}(F(Error));function Y(t,e){i.greaterThanOrEqual(t,T)||u(!1),i.lessThanOrEqual(t,q[e])||u(!1)}function J(t){try{return a.getAddress(t)}catch(t){u(!1)}}function Q(t){return t instanceof i?t:i.BigInt("bigint"==typeof t?t.toString():t)}function V(t){Y(t,v.uint256);var e,n=T;if(i.greaterThan(t,x))for(n=t,e=i.add(i.divide(t,k),g);i.lessThan(e,n);)n=e,e=i.divide(i.add(i.divide(t,e),e),k);else i.notEqual(t,T)&&(n=g);return n}function $(t,e,n,r){if(n>0||u(!1),t.length<=n||u(!1),0===t.length)return t.push(e),null;var o=t.length===n;if(o&&r(t[t.length-1],e)<=0)return e;for(var i=0,a=t.length;i<a;){var s=i+a>>>1;r(t[s],e)<=0?i=s+1:a=s}return t.splice(i,0,e),o?t.pop():null}var z=function(t,e,n){Y(i.BigInt(t),v.uint8),this.decimals=t,this.symbol=e,this.name=n},G=function(t){function e(){return t.apply(this,arguments)||this}return B(e,t),e.prototype.changeNameAndSymbol=function(t,e){this.name=t,this.symbol=e},e}(z);G.ETHER=new G(18,"ETH","Ether");var K,Z=G.ETHER,tt=function(t){function e(e,n,r,o,i){var u;return(u=t.call(this,r,o,i)||this).chainId=e,u.address=J(n),u}B(e,t);var n=e.prototype;return n.equals=function(t){return this===t||this.chainId===t.chainId&&this.address===t.address},n.sortsBefore=function(t){return this.chainId!==t.chainId&&u(!1),this.address===t.address&&u(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(z);function et(t,e){return t instanceof tt&&e instanceof tt?t.equals(e):!(t instanceof tt||e instanceof tt||t!==e)}var nt,rt,ot=((K={})[exports.ChainId.ETHEREUM]=new tt(exports.ChainId.ETHEREUM,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),K[exports.ChainId.BNB]=new tt(exports.ChainId.BNB,"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",18,"WBNB","Wrapped BNB"),K[exports.ChainId.MATIC]=new tt(exports.ChainId.MATIC,"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",18,"WMATIC","Wrapped Matic"),K[exports.ChainId.HYPRA]=new tt(exports.ChainId.HYPRA,"0x0000000000079c645A9bDE0Bd8Af1775FAF5598A",18,"WHYP","Wrapped Hypra"),K),it=c(d),ut=c(s),at=((nt={})[exports.Rounding.ROUND_DOWN]=it.ROUND_DOWN,nt[exports.Rounding.ROUND_HALF_UP]=it.ROUND_HALF_UP,nt[exports.Rounding.ROUND_UP]=it.ROUND_UP,nt),st=((rt={})[exports.Rounding.ROUND_DOWN]=0,rt[exports.Rounding.ROUND_HALF_UP]=1,rt[exports.Rounding.ROUND_UP]=3,rt),ct=function(){function t(t,e){void 0===e&&(e=g),this.numerator=Q(t),this.denominator=Q(e)}var e=t.prototype;return e.invert=function(){return new t(this.denominator,this.numerator)},e.add=function(e){var n=e instanceof t?e:new t(Q(e));return i.equal(this.denominator,n.denominator)?new t(i.add(this.numerator,n.numerator),this.denominator):new t(i.add(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator)),i.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=e instanceof t?e:new t(Q(e));return i.equal(this.denominator,n.denominator)?new t(i.subtract(this.numerator,n.numerator),this.denominator):new t(i.subtract(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator)),i.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=e instanceof t?e:new t(Q(e));return i.lessThan(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=e instanceof t?e:new t(Q(e));return i.equal(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=e instanceof t?e:new t(Q(e));return i.greaterThan(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=e instanceof t?e:new t(Q(e));return new t(i.multiply(this.numerator,n.numerator),i.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=e instanceof t?e:new t(Q(e));return new t(i.multiply(this.numerator,n.denominator),i.multiply(this.denominator,n.numerator))},e.toSignificant=function(t,e,n){void 0===e&&(e={groupSeparator:""}),void 0===n&&(n=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||u(!1),t>0||u(!1),it.set({precision:t+1,rounding:at[n]});var r=new it(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return r.toFormat(r.decimalPlaces(),e)},e.toFixed=function(t,e,n){return void 0===e&&(e={groupSeparator:""}),void 0===n&&(n=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||u(!1),t>=0||u(!1),ut.DP=t,ut.RM=st[n],new ut(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},_(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}(),dt=c(s),pt=function(t){function e(e,n){var r,o=Q(n);return Y(o,v.uint256),(r=t.call(this,o,i.exponentiate(b,i.BigInt(e.decimals)))||this).currency=e,r}B(e,t),e.ether=function(t){return new e(Z,t)};var n=e.prototype;return n.add=function(t){return et(this.currency,t.currency)||u(!1),new e(this.currency,i.add(this.raw,t.raw))},n.subtract=function(t){return et(this.currency,t.currency)||u(!1),new e(this.currency,i.subtract(this.raw,t.raw))},n.toSignificant=function(e,n,r){return void 0===e&&(e=6),void 0===r&&(r=exports.Rounding.ROUND_DOWN),t.prototype.toSignificant.call(this,e,n,r)},n.toFixed=function(e,n,r){return void 0===e&&(e=this.currency.decimals),void 0===r&&(r=exports.Rounding.ROUND_DOWN),e<=this.currency.decimals||u(!1),t.prototype.toFixed.call(this,e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),dt.DP=this.currency.decimals,new dt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},_(e,[{key:"raw",get:function(){return this.numerator}}]),e}(ct),ft=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}B(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||u(!1),new e(this.token,i.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||u(!1),new e(this.token,i.subtract(this.raw,t.raw))},e}(pt),lt=function(t){function e(e,n,r,o){var u;return(u=t.call(this,o,r)||this).baseCurrency=e,u.quoteCurrency=n,u.scalar=new ct(i.exponentiate(b,i.BigInt(e.decimals)),i.exponentiate(b,i.BigInt(n.decimals))),u}B(e,t),e.fromRoute=function(t){for(var n,r=[],o=M(t.pairs.entries());!(n=o()).done;){var i=n.value,u=i[1];r.push(t.path[i[0]].equals(u.token0)?new e(u.reserve0.currency,u.reserve1.currency,u.reserve0.raw,u.reserve1.raw):new e(u.reserve1.currency,u.reserve0.currency,u.reserve1.raw,u.reserve0.raw))}return r.slice(1).reduce((function(t,e){return t.multiply(e)}),r[0])};var n=e.prototype;return n.invert=function(){return new e(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},n.multiply=function(n){et(this.quoteCurrency,n.baseCurrency)||u(!1);var r=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,r.denominator,r.numerator)},n.quote=function(e){return et(e.currency,this.baseCurrency)||u(!1),this.quoteCurrency instanceof tt?new ft(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):pt.ether(t.prototype.multiply.call(this,e.raw).quotient)},n.toSignificant=function(t,e,n){return void 0===t&&(t=6),this.adjusted.toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=4),this.adjusted.toFixed(t,e,n)},_(e,[{key:"raw",get:function(){return new ct(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(ct),ht={},mt=function(){function t(e,n){var r=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new tt(r[0].token.chainId,t.getAddress(r[0].token,r[1].token),18,"RETHERS-LP","RETHERSWAP-LP"),this.tokenAmounts=r}t.getAddress=function(t,e){var n,r,o,i,u,s=t.sortsBefore(e)?[t,e]:[e,t];return void 0===(null===(n=ht)||void 0===n||null===(r=n[s[0].address])||void 0===r?void 0:r[s[1].address])&&(ht=D({},ht,((u={})[s[0].address]=D({},null===(o=ht)||void 0===o?void 0:o[s[0].address],((i={})[s[1].address]=a.getCreate2Address("0xa995CBAd84fdeE7608F082bC0dBDB5DdD91D373f",p.keccak256(["bytes"],[p.pack(["address","address"],[s[0].address,s[1].address])]),y),i)),u))),ht[s[0].address][s[1].address]};var e=t.prototype;return e.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},e.priceOf=function(t){return this.involvesToken(t)||u(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||u(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||u(!1),i.equal(this.reserve0.raw,T)||i.equal(this.reserve1.raw,T))throw new X;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=i.multiply(e.raw,E),a=i.multiply(o,r.raw),s=i.add(i.multiply(n.raw,O),o),c=new ft(e.token.equals(this.token0)?this.token1:this.token0,i.divide(a,s));if(i.equal(c.raw,T))throw new L;return[c,new t(n.add(e),r.subtract(c))]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||u(!1),i.equal(this.reserve0.raw,T)||i.equal(this.reserve1.raw,T)||i.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new X;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=i.multiply(i.multiply(r.raw,e.raw),O),a=i.multiply(i.subtract(n.raw,e.raw),E),s=new ft(e.token.equals(this.token0)?this.token1:this.token0,i.add(i.divide(o,a),g));return[s,new t(r.add(s),n.subtract(e))]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||u(!1);var r,o=e.token.sortsBefore(n.token)?[e,n]:[n,e];if(o[0].token.equals(this.token0)&&o[1].token.equals(this.token1)||u(!1),i.equal(t.raw,T))r=i.subtract(V(i.multiply(o[0].raw,o[1].raw)),w);else{var a=i.divide(i.multiply(o[0].raw,t.raw),this.reserve0.raw),s=i.divide(i.multiply(o[1].raw,t.raw),this.reserve1.raw);r=i.lessThanOrEqual(a,s)?a:s}if(!i.greaterThan(r,T))throw new L;return new ft(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var a;if(void 0===r&&(r=!1),this.involvesToken(t)||u(!1),e.token.equals(this.liquidityToken)||u(!1),n.token.equals(this.liquidityToken)||u(!1),i.lessThanOrEqual(n.raw,e.raw)||u(!1),r){o||u(!1);var s=Q(o);if(i.equal(s,T))a=e;else{var c=V(i.multiply(this.reserve0.raw,this.reserve1.raw)),d=V(s);if(i.greaterThan(c,d)){var p=i.multiply(e.raw,i.subtract(c,d)),f=i.add(i.multiply(c,A),d),l=i.divide(p,f);a=e.add(new ft(this.liquidityToken,l))}else a=e}}else a=e;return new ft(t,i.divide(i.multiply(n.raw,this.reserveOf(t).raw),a.raw))},_(t,[{key:"token0Price",get:function(){return new lt(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new lt(this.token1,this.token0,this.tokenAmounts[1].raw,this.tokenAmounts[0].raw)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"token0",get:function(){return this.tokenAmounts[0].token}},{key:"token1",get:function(){return this.tokenAmounts[1].token}},{key:"reserve0",get:function(){return this.tokenAmounts[0]}},{key:"reserve1",get:function(){return this.tokenAmounts[1]}}]),t}(),vt=function(){function t(t,e,n){t.length>0||u(!1),t.every((function(e){return e.chainId===t[0].chainId}))||u(!1),e instanceof tt&&t[0].involvesToken(e)||e===Z&&t[0].involvesToken(ot[t[0].chainId])||u(!1),void 0===n||n instanceof tt&&t[t.length-1].involvesToken(n)||n===Z&&t[t.length-1].involvesToken(ot[t[0].chainId])||u(!1);for(var r,o=[e instanceof tt?e:ot[t[0].chainId]],i=M(t.entries());!(r=i()).done;){var a=r.value,s=a[1],c=o[a[0]];c.equals(s.token0)||c.equals(s.token1)||u(!1);var d=c.equals(s.token0)?s.token1:s.token0;o.push(d)}this.pairs=t,this.path=o,this.midPrice=lt.fromRoute(this),this.input=e,this.output=null!=n?n:o[o.length-1]}return _(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),yt=new ct(I),wt=function(t){function e(){return t.apply(this,arguments)||this}B(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(yt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(yt).toFixed(t,e,n)},e}(ct);function Tt(t,e){return et(t.inputAmount.currency,e.inputAmount.currency)||u(!1),et(t.outputAmount.currency,e.outputAmount.currency)||u(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?0:t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}function gt(t,e){var n=Tt(t,e);return 0!==n?n:t.priceImpact.lessThan(e.priceImpact)?-1:t.priceImpact.greaterThan(e.priceImpact)?1:t.route.path.length-e.route.path.length}function kt(t,e){return t instanceof ft?t:t.currency===Z?new ft(ot[e],t.raw):void u(!1)}function xt(t,e){return t instanceof tt?t:t===Z?ot[e]:void u(!1)}var At=function(){function t(t,e,n){var r,o,i,a=new Array(t.path.length),s=new Array(t.pairs.length);if(n===exports.TradeType.EXACT_INPUT){et(e.currency,t.input)||u(!1),a[0]=kt(e,t.chainId);for(var c=0;c<t.path.length-1;c++){var d=t.pairs[c].getOutputAmount(a[c]),p=d[1];a[c+1]=d[0],s[c]=p}}else{et(e.currency,t.output)||u(!1),a[a.length-1]=kt(e,t.chainId);for(var f=t.path.length-1;f>0;f--){var l=t.pairs[f-1].getInputAmount(a[f]),h=l[1];a[f-1]=l[0],s[f-1]=h}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===Z?pt.ether(a[0].raw):a[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===Z?pt.ether(a[a.length-1].raw):a[a.length-1],this.executionPrice=new lt(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=lt.fromRoute(new vt(s,t.input)),this.priceImpact=(r=this.outputAmount,i=(o=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(r.raw).divide(o),new wt(i.numerator,i.denominator))}t.exactIn=function(e,n){return new t(e,n,exports.TradeType.EXACT_INPUT)},t.exactOut=function(e,n){return new t(e,n,exports.TradeType.EXACT_OUTPUT)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(T)&&u(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new ct(g).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof ft?new ft(this.outputAmount.token,e):pt.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(T)&&u(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new ct(g).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof ft?new ft(this.inputAmount.token,e):pt.ether(e)},t.bestTradeExactIn=function(e,n,r,o,i,a,s){var c=void 0===o?{}:o,d=c.maxNumResults,p=void 0===d?3:d,f=c.maxHops,l=void 0===f?3:f;void 0===i&&(i=[]),void 0===a&&(a=n),void 0===s&&(s=[]),e.length>0||u(!1),l>0||u(!1),a===n||i.length>0||u(!1);var h=n instanceof ft?n.token.chainId:r instanceof tt?r.chainId:void 0;void 0===h&&u(!1);for(var m=kt(n,h),v=xt(r,h),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(m.token)||w.token1.equals(m.token))&&!w.reserve0.equalTo(T)&&!w.reserve1.equalTo(T)){var g=void 0;try{g=w.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(g.token.equals(v))$(s,new t(new vt([].concat(i,[w]),a.currency,r),a,exports.TradeType.EXACT_INPUT),p,gt);else if(l>1&&e.length>1){var k=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(k,g,r,{maxNumResults:p,maxHops:l-1},[].concat(i,[w]),a,s)}}}return s},t.bestTradeExactOut=function(e,n,r,o,i,a,s){var c=void 0===o?{}:o,d=c.maxNumResults,p=void 0===d?3:d,f=c.maxHops,l=void 0===f?3:f;void 0===i&&(i=[]),void 0===a&&(a=r),void 0===s&&(s=[]),e.length>0||u(!1),l>0||u(!1),a===r||i.length>0||u(!1);var h=r instanceof ft?r.token.chainId:n instanceof tt?n.chainId:void 0;void 0===h&&u(!1);for(var m=kt(r,h),v=xt(n,h),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(m.token)||w.token1.equals(m.token))&&!w.reserve0.equalTo(T)&&!w.reserve1.equalTo(T)){var g=void 0;try{g=w.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(g.token.equals(v))$(s,new t(new vt([w].concat(i),n,a.currency),a,exports.TradeType.EXACT_OUTPUT),p,gt);else if(l>1&&e.length>1){var k=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(k,n,g,{maxNumResults:p,maxHops:l-1},[w].concat(i),a,s)}}}return s},t}();function bt(t){return"0x"+t.raw.toString(16)}var It,Et=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===Z,r=t.outputAmount.currency===Z;n&&r&&u(!1),!("ttl"in e)||e.ttl>0||u(!1);var o,i,a,s=J(e.recipient),c=bt(t.maximumAmountIn(e.allowedSlippage)),d=bt(t.minimumAmountOut(e.allowedSlippage)),p=t.route.path.map((function(t){return t.address})),f="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),l=Boolean(e.feeOnTransfer);switch(t.tradeType){case exports.TradeType.EXACT_INPUT:n?(o=l?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[d,p,s,f],a=c):r?(o=l?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[c,d,p,s,f],a="0x0"):(o=l?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[c,d,p,s,f],a="0x0");break;case exports.TradeType.EXACT_OUTPUT:l&&u(!1),n?(o="swapETHForExactTokens",i=[d,p,s,f],a=c):r?(o="swapTokensForExactETH",i=[d,c,p,s,f],a="0x0"):(o="swapTokensForExactTokens",i=[d,c,p,s,f],a="0x0")}return{methodName:o,args:i,value:a}},t}(),Ot=[{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}],qt=((It={})[exports.ChainId.HYPRA]={"0xCf52025D37f68dEdA9ef8307Ba4474eCbf15C33c":9},It),Pt=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,u,a=function(n){return new tt(t,e,n,r,o)};void 0===n&&(n=h.getDefaultProvider(l.getNetwork(t)));var s="number"==typeof(null===(i=qt)||void 0===i||null===(u=i[t])||void 0===u?void 0:u[e]);return Promise.resolve(s?a(qt[t][e]):Promise.resolve(new f.Contract(e,Ot,n).decimals().then((function(n){var r,o,i;return qt=D({},qt,((i={})[t]=D({},null===(r=qt)||void 0===r?void 0:r[t],((o={})[e]=n,o)),i)),n}))).then(a))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e,n){try{void 0===n&&(n=h.getDefaultProvider(l.getNetwork(t.chainId))),t.chainId!==e.chainId&&u(!1);var r=mt.getAddress(t,e);return Promise.resolve(new f.Contract(r,m.abi,n).getReserves()).then((function(n){var r=n[0],o=n[1],i=t.sortsBefore(e)?[r,o]:[o,r];return new mt(new ft(t,i[0]),new ft(e,i[1]))}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=i,exports.Currency=z,exports.CurrencyAmount=pt,exports.ETHER=Z,exports.FACTORY_ADDRESS="0xa995CBAd84fdeE7608F082bC0dBDB5DdD91D373f",exports.Fetcher=Pt,exports.Fraction=ct,exports.INIT_CODE_HASH=y,exports.InsufficientInputAmountError=L,exports.InsufficientReservesError=X,exports.MINIMUM_LIQUIDITY=w,exports.Pair=mt,exports.Percent=wt,exports.Price=lt,exports.Route=vt,exports.Router=Et,exports.Token=tt,exports.TokenAmount=ft,exports.Trade=At,exports.WETH=ot,exports.currencyEquals=et,exports.inputOutputComparator=Tt,exports.nativeCurrency=G,exports.tradeComparator=gt;
//# sourceMappingURL=sdk.cjs.production.min.js.map