@cronswap/sdk
Version:
🛠An example SDK for building applications on top of Cronswap.
3 lines (2 loc) • 23.5 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,u,a=t(require("jsbi")),s=t(require("tiny-invariant")),c=(t(require("tiny-warning")),require("@ethersproject/address")),f=t(require("big.js")),l=t(require("toformat")),d=t(require("decimal.js-light")),p=require("@ethersproject/solidity"),h=require("@ethersproject/contracts"),m=require("@ethersproject/networks"),v=require("@ethersproject/providers"),y=t(require("@uniswap/v2-core/build/IUniswapV2Pair.json"));(o=exports.ChainId||(exports.ChainId={}))[o.CRONOSTEST=338]="CRONOSTEST",o[o.BSC_TEST_NET=97]="BSC_TEST_NET",(i=exports.TradeType||(exports.TradeType={}))[i.EXACT_INPUT=0]="EXACT_INPUT",i[i.EXACT_OUTPUT=1]="EXACT_OUTPUT",(u=exports.Rounding||(exports.Rounding={}))[u.ROUND_DOWN=0]="ROUND_DOWN",u[u.ROUND_HALF_UP=1]="ROUND_HALF_UP",u[u.ROUND_UP=2]="ROUND_UP";var T,w=((e={})[exports.ChainId.CRONOSTEST]="0x22c61E96B9c451261E5CD6a3408394A7FA3b83f7",e[exports.ChainId.BSC_TEST_NET]="0x22c61E96B9c451261E5CD6a3408394A7FA3b83f7",e),g=((n={})[exports.ChainId.CRONOSTEST]="0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c",n[exports.ChainId.BSC_TEST_NET]="0x01429e880a7972ebfbba904a5bbe32a816e78273e4b38ffa6bdeaebce8adba7c",n),k=a.BigInt(1e3),x=a.BigInt(0),O=a.BigInt(1),A=a.BigInt(2),I=a.BigInt(3),b=a.BigInt(5),E=a.BigInt(10),q=a.BigInt(100),C=a.BigInt(997),_=a.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(T||(T={}));var R=((r={})[T.uint8]=a.BigInt("0xff"),r[T.uint256]=a.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),r);function S(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function P(t,e,n){return e&&S(t.prototype,e),n&&S(t,n),t}function N(){return(N=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function U(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,D(t,e)}function B(t){return(B=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function D(t,e){return(D=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function F(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function j(t,e,n){return(j=F()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&D(o,n.prototype),o}).apply(null,arguments)}function H(t){var e="function"==typeof Map?new Map:void 0;return(H=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))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 j(t,arguments,B(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),D(n,t)})(t)}function X(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function M(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 L(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 M(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)?M(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,V=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(X(n),(this instanceof e?this.constructor:void 0).prototype),n}return U(e,t),e}(H(Error)),Y=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(X(n),(this instanceof e?this.constructor:void 0).prototype),n}return U(e,t),e}(H(Error));function J(t,e){a.greaterThanOrEqual(t,x)||s(!1),a.lessThanOrEqual(t,R[e])||s(!1)}function Q(t){try{return c.getAddress(t)}catch(t){s(!1)}}function $(t){return t instanceof a?t:a.BigInt("bigint"==typeof t?t.toString():t)}function z(t){J(t,T.uint256);var e,n=x;if(a.greaterThan(t,I))for(n=t,e=a.add(a.divide(t,A),O);a.lessThan(e,n);)n=e,e=a.divide(a.add(a.divide(t,e),e),A);else a.notEqual(t,x)&&(n=O);return n}function G(t,e,n,r){if(n>0||s(!1),t.length<=n||s(!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,u=t.length;i<u;){var a=i+u>>>1;r(t[a],e)<=0?i=a+1:u=a}return t.splice(i,0,e),o?t.pop():null}var K,Z=function(t,e,n){J(a.BigInt(t),T.uint8),this.decimals=t,this.symbol=e,this.name=n},tt=Z.ETHER=new Z(18,"ETHER","Eth"),et=function(t){function e(e,n,r,o,i){var u;return(u=t.call(this,r,o,i)||this).chainId=e,u.address=Q(n),u}U(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&&s(!1),this.address===t.address&&s(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(Z);function nt(t,e){return t instanceof et&&e instanceof et?t.equals(e):!(t instanceof et||e instanceof et||t!==e)}var rt,ot,it=((K={})[exports.ChainId.CRONOSTEST]=new et(exports.ChainId.CRONOSTEST,"0x613035a5CC23527CB0535Ea564771198E5e0Ebf8",18,"WCRO","Wrapped Cronos"),K[exports.ChainId.BSC_TEST_NET]=new et(exports.ChainId.BSC_TEST_NET,"0x613035a5CC23527CB0535Ea564771198E5e0Ebf8",18,"WBNB","Wrapped BNB"),K),ut=l(d),at=l(f),st=((rt={})[exports.Rounding.ROUND_DOWN]=ut.ROUND_DOWN,rt[exports.Rounding.ROUND_HALF_UP]=ut.ROUND_HALF_UP,rt[exports.Rounding.ROUND_UP]=ut.ROUND_UP,rt),ct=((ot={})[exports.Rounding.ROUND_DOWN]=0,ot[exports.Rounding.ROUND_HALF_UP]=1,ot[exports.Rounding.ROUND_UP]=3,ot),ft=function(){function t(t,e){void 0===e&&(e=O),this.numerator=$(t),this.denominator=$(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($(e));return a.equal(this.denominator,n.denominator)?new t(a.add(this.numerator,n.numerator),this.denominator):new t(a.add(a.multiply(this.numerator,n.denominator),a.multiply(n.numerator,this.denominator)),a.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=e instanceof t?e:new t($(e));return a.equal(this.denominator,n.denominator)?new t(a.subtract(this.numerator,n.numerator),this.denominator):new t(a.subtract(a.multiply(this.numerator,n.denominator),a.multiply(n.numerator,this.denominator)),a.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=e instanceof t?e:new t($(e));return a.lessThan(a.multiply(this.numerator,n.denominator),a.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=e instanceof t?e:new t($(e));return a.equal(a.multiply(this.numerator,n.denominator),a.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=e instanceof t?e:new t($(e));return a.greaterThan(a.multiply(this.numerator,n.denominator),a.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=e instanceof t?e:new t($(e));return new t(a.multiply(this.numerator,n.numerator),a.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=e instanceof t?e:new t($(e));return new t(a.multiply(this.numerator,n.denominator),a.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)||s(!1),t>0||s(!1),ut.set({precision:t+1,rounding:st[n]});var r=new ut(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)||s(!1),t>=0||s(!1),at.DP=t,at.RM=ct[n],new at(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},P(t,[{key:"quotient",get:function(){return a.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(a.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),lt=l(f),dt=function(t){function e(e,n){var r,o=$(n);return J(o,T.uint256),(r=t.call(this,o,a.exponentiate(E,a.BigInt(e.decimals)))||this).currency=e,r}U(e,t),e.ether=function(t){return new e(tt,t)};var n=e.prototype;return n.add=function(t){return nt(this.currency,t.currency)||s(!1),new e(this.currency,a.add(this.raw,t.raw))},n.subtract=function(t){return nt(this.currency,t.currency)||s(!1),new e(this.currency,a.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||s(!1),t.prototype.toFixed.call(this,e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),lt.DP=this.currency.decimals,new lt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},P(e,[{key:"raw",get:function(){return this.numerator}}]),e}(ft),pt=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}U(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||s(!1),new e(this.token,a.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||s(!1),new e(this.token,a.subtract(this.raw,t.raw))},e}(dt),ht=function(t){function e(e,n,r,o){var i;return(i=t.call(this,o,r)||this).baseCurrency=e,i.quoteCurrency=n,i.scalar=new ft(a.exponentiate(E,a.BigInt(e.decimals)),a.exponentiate(E,a.BigInt(n.decimals))),i}U(e,t),e.fromRoute=function(t){for(var n,r=[],o=L(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){nt(this.quoteCurrency,n.baseCurrency)||s(!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 nt(e.currency,this.baseCurrency)||s(!1),this.quoteCurrency instanceof et?new pt(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):dt.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)},P(e,[{key:"raw",get:function(){return new ft(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(ft),mt={},vt=function(){function t(e,n){var r=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new et(r[0].token.chainId,t.getAddress(r[0].token,r[1].token),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=r}t.getAddress=function(t,e){var n,r,o,i,u,a=t.sortsBefore(e)?[t,e]:[e,t];return void 0===(null===(n=mt)||void 0===n||null===(r=n[a[0].address])||void 0===r?void 0:r[a[1].address])&&(mt=N({},mt,((u={})[a[0].address]=N({},null===(o=mt)||void 0===o?void 0:o[a[0].address],((i={})[a[1].address]=c.getCreate2Address(w[a[0].chainId],p.keccak256(["bytes"],[p.pack(["address","address"],[a[0].address,a[1].address])]),g[a[0].chainId]),i)),u))),mt[a[0].address][a[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)||s(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||s(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||s(!1),a.equal(this.reserve0.raw,x)||a.equal(this.reserve1.raw,x))throw new V;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=a.multiply(e.raw,C),i=a.multiply(o,r.raw),u=a.add(a.multiply(n.raw,_),o),c=new pt(e.token.equals(this.token0)?this.token1:this.token0,a.divide(i,u));if(a.equal(c.raw,x))throw new Y;return[c,new t(n.add(e),r.subtract(c))]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||s(!1),a.equal(this.reserve0.raw,x)||a.equal(this.reserve1.raw,x)||a.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new V;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=a.multiply(a.multiply(r.raw,e.raw),_),i=a.multiply(a.subtract(n.raw,e.raw),C),u=new pt(e.token.equals(this.token0)?this.token1:this.token0,a.add(a.divide(o,i),O));return[u,new t(r.add(u),n.subtract(e))]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||s(!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)||s(!1),a.equal(t.raw,x))r=a.subtract(z(a.multiply(o[0].raw,o[1].raw)),k);else{var i=a.divide(a.multiply(o[0].raw,t.raw),this.reserve0.raw),u=a.divide(a.multiply(o[1].raw,t.raw),this.reserve1.raw);r=a.lessThanOrEqual(i,u)?i:u}if(!a.greaterThan(r,x))throw new Y;return new pt(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var i;if(void 0===r&&(r=!1),this.involvesToken(t)||s(!1),e.token.equals(this.liquidityToken)||s(!1),n.token.equals(this.liquidityToken)||s(!1),a.lessThanOrEqual(n.raw,e.raw)||s(!1),r){o||s(!1);var u=$(o);if(a.equal(u,x))i=e;else{var c=z(a.multiply(this.reserve0.raw,this.reserve1.raw)),f=z(u);if(a.greaterThan(c,f)){var l=a.multiply(e.raw,a.subtract(c,f)),d=a.add(a.multiply(c,b),f),p=a.divide(l,d);i=e.add(new pt(this.liquidityToken,p))}else i=e}}else i=e;return new pt(t,a.divide(a.multiply(n.raw,this.reserveOf(t).raw),i.raw))},P(t,[{key:"token0Price",get:function(){return new ht(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new ht(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}(),yt=function(){function t(t,e,n){t.length>0||s(!1),t.every((function(e){return e.chainId===t[0].chainId}))||s(!1),e instanceof et&&t[0].involvesToken(e)||e===tt&&t[0].involvesToken(it[t[0].chainId])||s(!1),void 0===n||n instanceof et&&t[t.length-1].involvesToken(n)||n===tt&&t[t.length-1].involvesToken(it[t[0].chainId])||s(!1);for(var r,o=[e instanceof et?e:it[t[0].chainId]],i=L(t.entries());!(r=i()).done;){var u=r.value,a=u[1],c=o[u[0]];c.equals(a.token0)||c.equals(a.token1)||s(!1);var f=c.equals(a.token0)?a.token1:a.token0;o.push(f)}this.pairs=t,this.path=o,this.midPrice=ht.fromRoute(this),this.input=e,this.output=null!=n?n:o[o.length-1]}return P(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),Tt=new ft(q),wt=function(t){function e(){return t.apply(this,arguments)||this}U(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(Tt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(Tt).toFixed(t,e,n)},e}(ft);function gt(t,e){return nt(t.inputAmount.currency,e.inputAmount.currency)||s(!1),nt(t.outputAmount.currency,e.outputAmount.currency)||s(!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 kt(t,e){var n=gt(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 xt(t,e){return t instanceof pt?t:t.currency===tt?new pt(it[e],t.raw):void s(!1)}function Ot(t,e){return t instanceof et?t:t===tt?it[e]:void s(!1)}var At=function(){function t(t,e,n){var r,o,i,u=new Array(t.path.length),a=new Array(t.pairs.length);if(n===exports.TradeType.EXACT_INPUT){nt(e.currency,t.input)||s(!1),u[0]=xt(e,t.chainId);for(var c=0;c<t.path.length-1;c++){var f=t.pairs[c].getOutputAmount(u[c]),l=f[1];u[c+1]=f[0],a[c]=l}}else{nt(e.currency,t.output)||s(!1),u[u.length-1]=xt(e,t.chainId);for(var d=t.path.length-1;d>0;d--){var p=t.pairs[d-1].getInputAmount(u[d]),h=p[1];u[d-1]=p[0],a[d-1]=h}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===tt?dt.ether(u[0].raw):u[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===tt?dt.ether(u[u.length-1].raw):u[u.length-1],this.executionPrice=new ht(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=ht.fromRoute(new yt(a,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(x)&&s(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new ft(O).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof pt?new pt(this.outputAmount.token,e):dt.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(x)&&s(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new ft(O).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof pt?new pt(this.inputAmount.token,e):dt.ether(e)},t.bestTradeExactIn=function(e,n,r,o,i,u,a){var c=void 0===o?{}:o,f=c.maxNumResults,l=void 0===f?3:f,d=c.maxHops,p=void 0===d?3:d;void 0===i&&(i=[]),void 0===u&&(u=n),void 0===a&&(a=[]),e.length>0||s(!1),p>0||s(!1),u===n||i.length>0||s(!1);var h=n instanceof pt?n.token.chainId:r instanceof et?r.chainId:void 0;void 0===h&&s(!1);for(var m=xt(n,h),v=Ot(r,h),y=0;y<e.length;y++){var T=e[y];if((T.token0.equals(m.token)||T.token1.equals(m.token))&&!T.reserve0.equalTo(x)&&!T.reserve1.equalTo(x)){var w=void 0;try{w=T.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(w.token.equals(v))G(a,new t(new yt([].concat(i,[T]),u.currency,r),u,exports.TradeType.EXACT_INPUT),l,kt);else if(p>1&&e.length>1){var g=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(g,w,r,{maxNumResults:l,maxHops:p-1},[].concat(i,[T]),u,a)}}}return a},t.bestTradeExactOut=function(e,n,r,o,i,u,a){var c=void 0===o?{}:o,f=c.maxNumResults,l=void 0===f?3:f,d=c.maxHops,p=void 0===d?3:d;void 0===i&&(i=[]),void 0===u&&(u=r),void 0===a&&(a=[]),e.length>0||s(!1),p>0||s(!1),u===r||i.length>0||s(!1);var h=r instanceof pt?r.token.chainId:n instanceof et?n.chainId:void 0;void 0===h&&s(!1);for(var m=xt(r,h),v=Ot(n,h),y=0;y<e.length;y++){var T=e[y];if((T.token0.equals(m.token)||T.token1.equals(m.token))&&!T.reserve0.equalTo(x)&&!T.reserve1.equalTo(x)){var w=void 0;try{w=T.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(w.token.equals(v))G(a,new t(new yt([T].concat(i),n,u.currency),u,exports.TradeType.EXACT_OUTPUT),l,kt);else if(p>1&&e.length>1){var g=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(g,n,w,{maxNumResults:l,maxHops:p-1},[T].concat(i),u,a)}}}return a},t}();function It(t){return"0x"+t.raw.toString(16)}var bt,Et=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===tt,r=t.outputAmount.currency===tt;n&&r&&s(!1),e.ttl>0||s(!1);var o,i,u,a=Q(e.recipient),c=It(t.maximumAmountIn(e.allowedSlippage)),f=It(t.minimumAmountOut(e.allowedSlippage)),l=t.route.path.map((function(t){return t.address})),d="0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16),p=Boolean(e.feeOnTransfer);switch(t.tradeType){case exports.TradeType.EXACT_INPUT:n?(o=p?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[f,l,a,d],u=c):r?(o=p?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[c,f,l,a,d],u="0x0"):(o=p?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[c,f,l,a,d],u="0x0");break;case exports.TradeType.EXACT_OUTPUT:p&&s(!1),n?(o="swapETHForExactTokens",i=[f,l,a,d],u=c):r?(o="swapTokensForExactETH",i=[f,c,l,a,d],u="0x0"):(o="swapTokensForExactTokens",i=[f,c,l,a,d],u="0x0")}return{methodName:o,args:i,value:u}},t}(),qt=[{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"}],Ct=((bt={})[exports.ChainId.CRONOSTEST]={"0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A":9},bt),_t=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,u,a=function(n){return new et(t,e,n,r,o)};void 0===n&&(n=v.getDefaultProvider(m.getNetwork(t)));var s="number"==typeof(null===(i=Ct)||void 0===i||null===(u=i[t])||void 0===u?void 0:u[e]);return Promise.resolve(s?a(Ct[t][e]):Promise.resolve(new h.Contract(e,qt,n).decimals().then((function(n){var r,o,i;return Ct=N({},Ct,((i={})[t]=N({},null===(r=Ct)||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=v.getDefaultProvider(m.getNetwork(t.chainId))),t.chainId!==e.chainId&&s(!1);var r=vt.getAddress(t,e);return Promise.resolve(new h.Contract(r,y.abi,n).getReserves()).then((function(n){var r=n[0],o=n[1],i=t.sortsBefore(e)?[r,o]:[o,r];return new vt(new pt(t,i[0]),new pt(e,i[1]))}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=a,exports.Currency=Z,exports.CurrencyAmount=dt,exports.ETHER=tt,exports.FACTORY_ADDRESSES=w,exports.Fetcher=_t,exports.Fraction=ft,exports.INIT_CODE_HASH=g,exports.InsufficientInputAmountError=Y,exports.InsufficientReservesError=V,exports.MINIMUM_LIQUIDITY=k,exports.Pair=vt,exports.Percent=wt,exports.Price=ht,exports.Route=yt,exports.Router=Et,exports.Token=et,exports.TokenAmount=pt,exports.Trade=At,exports.WETH=it,exports.currencyEquals=nt,exports.inputOutputComparator=gt,exports.tradeComparator=kt;
//# sourceMappingURL=sdk.cjs.production.min.js.map