UNPKG

@eaglevision/sdk

Version:

🛠 An SDK for building applications on top of evi.

3 lines (2 loc) • 25 kB
"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")),a=t(require("tiny-invariant")),u=(t(require("tiny-warning")),require("@ethersproject/address")),s=t(require("big.js")),c=t(require("toformat")),d=t(require("decimal.js-light")),f=require("@ethersproject/solidity"),h=require("@ethersproject/contracts"),p=require("@ethersproject/networks"),l=require("@ethersproject/providers"),m=t(require("@pancakeswap-libs/pancake-swap-core/build/IPancakePair.json"));(n=exports.ChainId||(exports.ChainId={}))[n.MAINNET=56]="MAINNET",n[n.BSCTESTNET=97]="BSCTESTNET",n[n.FANTOMNET=250]="FANTOMNET",n[n.FANTOMTESTNET=4002]="FANTOMTESTNET",n[n.HARMONYNET=16666e5]="HARMONYNET",n[n.HARMONYTESTNET=16667e5]="HARMONYTESTNET",(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,T={56:"0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",97:"0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",250:"0xEF45d134b73241eDa7703fa787148D9C9F4950b0",4002:"0xEF45d134b73241eDa7703fa787148D9C9F4950b0",16666e5:"0x7D02c116b98d0965ba7B642ace0183ad8b8D2196",16667e5:"0x7D02c116b98d0965ba7B642ace0183ad8b8D2196"},y={56:"0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5",97:"0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5",250:"0xe242e798f6cee26a9cb0bbf24653bf066e5356ffeac160907fe2cc108e238617",4002:"0xe242e798f6cee26a9cb0bbf24653bf066e5356ffeac160907fe2cc108e238617",16666e5:"0x162f79e638367cd45a118c778971dfd8d96c625d2798d3b71994b035cfe9b6dc",16667e5:"0x162f79e638367cd45a118c778971dfd8d96c625d2798d3b71994b035cfe9b6dc"},w=i.BigInt(1e3),k=i.BigInt(0),g=i.BigInt(1),x=i.BigInt(2),I=i.BigInt(3),b=i.BigInt(5),A=i.BigInt(10),E=i.BigInt(100),O=i.BigInt(997),N=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 C(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&&C(t.prototype,e),n&&C(t,n),t}function R(){return(R=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 F(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function _(t){return(_=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function U(t,e){return(U=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function B(t,e,n){return(B=S()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&U(o,n.prototype),o}).apply(null,arguments)}function D(t){var e="function"==typeof Map?new Map:void 0;return(D=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 B(t,arguments,_(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),U(n,t)})(t)}function M(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function H(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 j(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return H(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)?H(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.")}return(n=t[Symbol.iterator]()).next.bind(n)}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(M(n),(this instanceof e?this.constructor:void 0).prototype),n}return F(e,t),e}(D(Error)),L=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(M(n),(this instanceof e?this.constructor:void 0).prototype),n}return F(e,t),e}(D(Error));function Y(t,e){i.greaterThanOrEqual(t,k)||a(!1),i.lessThanOrEqual(t,q[e])||a(!1)}function J(t){try{return u.getAddress(t)}catch(t){a(!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=k;if(i.greaterThan(t,I))for(n=t,e=i.add(i.divide(t,x),g);i.lessThan(e,n);)n=e,e=i.divide(i.add(i.divide(t,e),e),x);else i.notEqual(t,k)&&(n=g);return n}function $(t,e,n,r){if(n>0||a(!1),t.length<=n||a(!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 s=i+u>>>1;r(t[s],e)<=0?i=s+1:u=s}return t.splice(i,0,e),o?t.pop():null}var z,G=function(t,e,n){Y(i.BigInt(t),v.uint8),this.decimals=t,this.symbol=e,this.name=n},K=G.ETHER={56:new G(18,"BNB","Binance"),97:new G(18,"BNB","Binance"),250:new G(18,"FTM","Fantom"),4002:new G(18,"FTM","Fantom"),16666e5:new G(18,"ONE","Harmony"),16667e5:new G(18,"ONE","Harmony")},Z=function(t){function e(e,n,r,o,i){var a;return(a=t.call(this,r,o,i)||this).chainId=e,a.address=J(n),a}F(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&&a(!1),this.address===t.address&&a(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(G);function tt(t,e){return t instanceof Z&&e instanceof Z?t.equals(e):!(t instanceof Z||e instanceof Z||t!==e)}var et,nt,rt=((z={})[exports.ChainId.MAINNET]=new Z(exports.ChainId.MAINNET,"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",18,"WBNB","Wrapped BNB"),z[exports.ChainId.BSCTESTNET]=new Z(exports.ChainId.BSCTESTNET,"0xaE8E19eFB41e7b96815649A6a60785e1fbA84C1e",18,"WBNB","Wrapped BNB"),z[exports.ChainId.FANTOMNET]=new Z(exports.ChainId.FANTOMNET,"0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83",18,"wFTM","Wrapped Fantom"),z[exports.ChainId.FANTOMTESTNET]=new Z(exports.ChainId.FANTOMTESTNET,"0xf1277d1ed8ad466beddf92ef448a132661956621",18,"wFTM","Wrapped Fantom"),z[exports.ChainId.HARMONYNET]=new Z(exports.ChainId.HARMONYNET,"0xcf664087a5bb0237a0bad6742852ec6c8d69a27a",18,"WONE","Wrapped ONE"),z[exports.ChainId.HARMONYTESTNET]=new Z(exports.ChainId.HARMONYTESTNET,"0xcf664087a5bb0237a0bad6742852ec6c8d69a27a",18,"WONE","Wrapped ONE"),z),ot=c(d),it=c(s),at=((et={})[exports.Rounding.ROUND_DOWN]=ot.ROUND_DOWN,et[exports.Rounding.ROUND_HALF_UP]=ot.ROUND_HALF_UP,et[exports.Rounding.ROUND_UP]=ot.ROUND_UP,et),ut=((nt={})[exports.Rounding.ROUND_DOWN]=0,nt[exports.Rounding.ROUND_HALF_UP]=1,nt[exports.Rounding.ROUND_UP]=3,nt),st=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)||a(!1),t>0||a(!1),ot.set({precision:t+1,rounding:at[n]});var r=new ot(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)||a(!1),t>=0||a(!1),it.DP=t,it.RM=ut[n],new it(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},P(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}(),ct=c(s),dt=function(t){function e(e,n){var r,o=Q(n);return Y(o,v.uint256),(r=t.call(this,o,i.exponentiate(A,i.BigInt(e.decimals)))||this).currency=e,r}F(e,t),e.ether=function(t,n){return new e(K[n],t)};var n=e.prototype;return n.add=function(t){return tt(this.currency,t.currency)||a(!1),new e(this.currency,i.add(this.raw,t.raw))},n.subtract=function(t){return tt(this.currency,t.currency)||a(!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||a(!1),t.prototype.toFixed.call(this,e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),ct.DP=this.currency.decimals,new ct(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},P(e,[{key:"raw",get:function(){return this.numerator}}]),e}(st),ft=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}F(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||a(!1),new e(this.token,i.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||a(!1),new e(this.token,i.subtract(this.raw,t.raw))},e}(dt),ht=function(t){function e(e,n,r,o,a){var u;return(u=t.call(this,o,r)||this).baseCurrency=e,u.quoteCurrency=n,u.chainId=a,u.scalar=new st(i.exponentiate(A,i.BigInt(e.decimals)),i.exponentiate(A,i.BigInt(n.decimals))),u}F(e,t),e.fromRoute=function(t){for(var n,r=[],o=j(t.pairs.entries());!(n=o()).done;){var i=n.value,a=i[1];r.push(t.path[i[0]].equals(a.token0)?new e(a.reserve0.currency,a.reserve1.currency,a.reserve0.raw,a.reserve1.raw,a.token0.chainId):new e(a.reserve1.currency,a.reserve0.currency,a.reserve1.raw,a.reserve0.raw,a.token0.chainId))}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,this.chainId)},n.multiply=function(n){tt(this.quoteCurrency,n.baseCurrency)||a(!1);var r=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,r.denominator,r.numerator,n.chainId)},n.quote=function(e){return tt(e.currency,this.baseCurrency)||a(!1),this.quoteCurrency instanceof Z?new ft(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):dt.ether(t.prototype.multiply.call(this,e.raw).quotient,this.chainId)},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 st(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(st),pt={},lt=function(){function t(e,n){var r=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new Z(r[0].token.chainId,t.getAddress(r[0].token,r[1].token),18,"Cake-LP","Pancake LPs"),this.tokenAmounts=r}t.getAddress=function(t,e){var n,r,o,i,a,s=t.sortsBefore(e)?[t,e]:[e,t];return void 0===(null===(n=pt)||void 0===n||null===(r=n[s[0].address])||void 0===r?void 0:r[s[1].address])&&(pt=R({},pt,((a={})[s[0].address]=R({},null===(o=pt)||void 0===o?void 0:o[s[0].address],((i={})[s[1].address]=u.getCreate2Address(T[t.chainId],f.keccak256(["bytes"],[f.pack(["address","address"],[s[0].address,s[1].address])]),y[t.chainId]),i)),a))),pt[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)||a(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||a(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||a(!1),i.equal(this.reserve0.raw,k)||i.equal(this.reserve1.raw,k))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,O),u=i.multiply(o,r.raw),s=i.add(i.multiply(n.raw,N),o),c=new ft(e.token.equals(this.token0)?this.token1:this.token0,i.divide(u,s));if(i.equal(c.raw,k))throw new L;return[c,new t(n.add(e),r.subtract(c))]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||a(!1),i.equal(this.reserve0.raw,k)||i.equal(this.reserve1.raw,k)||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),N),u=i.multiply(i.subtract(n.raw,e.raw),O),s=new ft(e.token.equals(this.token0)?this.token1:this.token0,i.add(i.divide(o,u),g));return[s,new t(r.add(s),n.subtract(e))]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||a(!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)||a(!1),i.equal(t.raw,k))r=i.subtract(V(i.multiply(o[0].raw,o[1].raw)),w);else{var u=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(u,s)?u:s}if(!i.greaterThan(r,k))throw new L;return new ft(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var u;if(void 0===r&&(r=!1),this.involvesToken(t)||a(!1),e.token.equals(this.liquidityToken)||a(!1),n.token.equals(this.liquidityToken)||a(!1),i.lessThanOrEqual(n.raw,e.raw)||a(!1),r){o||a(!1);var s=Q(o);if(i.equal(s,k))u=e;else{var c=V(i.multiply(this.reserve0.raw,this.reserve1.raw)),d=V(s);if(i.greaterThan(c,d)){var f=i.multiply(e.raw,i.subtract(c,d)),h=i.add(i.multiply(c,b),d),p=i.divide(f,h);u=e.add(new ft(this.liquidityToken,p))}else u=e}}else u=e;return new ft(t,i.divide(i.multiply(n.raw,this.reserveOf(t).raw),u.raw))},P(t,[{key:"token0Price",get:function(){return new ht(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw,this.token0.chainId)}},{key:"token1Price",get:function(){return new ht(this.token1,this.token0,this.tokenAmounts[1].raw,this.tokenAmounts[0].raw,this.token1.chainId)}},{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}(),mt=function(){function t(t,e,n){t.length>0||a(!1),t.every((function(e){return e.chainId===t[0].chainId}))||a(!1),e instanceof Z&&t[0].involvesToken(e)||e===K[t[0].chainId]&&t[0].involvesToken(rt[t[0].chainId])||a(!1),void 0===n||n instanceof Z&&t[t.length-1].involvesToken(n)||n===K[t[0].chainId]&&t[t.length-1].involvesToken(rt[t[0].chainId])||a(!1);for(var r,o=[e instanceof Z?e:rt[t[0].chainId]],i=j(t.entries());!(r=i()).done;){var u=r.value,s=u[1],c=o[u[0]];c.equals(s.token0)||c.equals(s.token1)||a(!1);var d=c.equals(s.token0)?s.token1:s.token0;o.push(d)}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}(),vt=new st(E),Tt=function(t){function e(){return t.apply(this,arguments)||this}F(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(vt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(vt).toFixed(t,e,n)},e}(st);function yt(t,e){return tt(t.inputAmount.currency,e.inputAmount.currency)||a(!1),tt(t.outputAmount.currency,e.outputAmount.currency)||a(!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 wt(t,e){var n=yt(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===K[e]?new ft(rt[e],t.raw):void a(!1)}function gt(t,e){return t instanceof Z?t:t===K[e]?rt[e]:void a(!1)}var xt=function(){function t(t,e,n){var r,o,i,u=new Array(t.path.length),s=new Array(t.pairs.length);if(n===exports.TradeType.EXACT_INPUT){tt(e.currency,t.input)||a(!1),u[0]=kt(e,t.chainId);for(var c=0;c<t.path.length-1;c++){var d=t.pairs[c].getOutputAmount(u[c]),f=d[1];u[c+1]=d[0],s[c]=f}}else{tt(e.currency,t.output)||a(!1),u[u.length-1]=kt(e,t.chainId);for(var h=t.path.length-1;h>0;h--){var p=t.pairs[h-1].getInputAmount(u[h]),l=p[1];u[h-1]=p[0],s[h-1]=l}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===K[t.chainId]?dt.ether(u[0].raw,t.chainId):u[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===K[t.chainId]?dt.ether(u[u.length-1].raw,t.chainId):u[u.length-1],this.executionPrice=new ht(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw,t.chainId),this.nextMidPrice=ht.fromRoute(new mt(s,t.input)),this.priceImpact=(r=this.outputAmount,i=(o=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(r.raw).divide(o),new Tt(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(k)&&a(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new st(g).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof ft?new ft(this.outputAmount.token,e):dt.ether(e,this.route.chainId)},e.maximumAmountIn=function(t){if(t.lessThan(k)&&a(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new st(g).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof ft?new ft(this.inputAmount.token,e):dt.ether(e,this.route.chainId)},t.bestTradeExactIn=function(e,n,r,o,i,u,s){var c=void 0===o?{}:o,d=c.maxNumResults,f=void 0===d?3:d,h=c.maxHops,p=void 0===h?3:h;void 0===i&&(i=[]),void 0===u&&(u=n),void 0===s&&(s=[]),e.length>0||a(!1),p>0||a(!1),u===n||i.length>0||a(!1);var l=n instanceof ft?n.token.chainId:r instanceof Z?r.chainId:void 0;void 0===l&&a(!1);for(var m=kt(n,l),v=gt(r,l),T=0;T<e.length;T++){var y=e[T];if((y.token0.equals(m.token)||y.token1.equals(m.token))&&!y.reserve0.equalTo(k)&&!y.reserve1.equalTo(k)){var w=void 0;try{w=y.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(w.token.equals(v))$(s,new t(new mt([].concat(i,[y]),u.currency,r),u,exports.TradeType.EXACT_INPUT),f,wt);else if(p>1&&e.length>1){var g=e.slice(0,T).concat(e.slice(T+1,e.length));t.bestTradeExactIn(g,w,r,{maxNumResults:f,maxHops:p-1},[].concat(i,[y]),u,s)}}}return s},t.bestTradeExactOut=function(e,n,r,o,i,u,s){var c=void 0===o?{}:o,d=c.maxNumResults,f=void 0===d?3:d,h=c.maxHops,p=void 0===h?3:h;void 0===i&&(i=[]),void 0===u&&(u=r),void 0===s&&(s=[]),e.length>0||a(!1),p>0||a(!1),u===r||i.length>0||a(!1);var l=r instanceof ft?r.token.chainId:n instanceof Z?n.chainId:void 0;void 0===l&&a(!1);for(var m=kt(r,l),v=gt(n,l),T=0;T<e.length;T++){var y=e[T];if((y.token0.equals(m.token)||y.token1.equals(m.token))&&!y.reserve0.equalTo(k)&&!y.reserve1.equalTo(k)){var w=void 0;try{w=y.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(w.token.equals(v))$(s,new t(new mt([y].concat(i),n,u.currency),u,exports.TradeType.EXACT_OUTPUT),f,wt);else if(p>1&&e.length>1){var g=e.slice(0,T).concat(e.slice(T+1,e.length));t.bestTradeExactOut(g,n,w,{maxNumResults:f,maxHops:p-1},[y].concat(i),u,s)}}}return s},t}();function It(t){return"0x"+t.raw.toString(16)}var bt,At=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===K[t.route.chainId],r=t.outputAmount.currency===K[t.route.chainId];n&&r&&a(!1),e.ttl>0||a(!1);var o,i,u,s=J(e.recipient),c=It(t.maximumAmountIn(e.allowedSlippage)),d=It(t.minimumAmountOut(e.allowedSlippage)),f=t.route.path.map((function(t){return t.address})),h="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=[d,f,s,h],u=c):r?(o=p?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[c,d,f,s,h],u="0x0"):(o=p?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[c,d,f,s,h],u="0x0");break;case exports.TradeType.EXACT_OUTPUT:p&&a(!1),n?(o="swapETHForExactTokens",i=[d,f,s,h],u=c):r?(o="swapTokensForExactETH",i=[d,c,f,s,h],u="0x0"):(o="swapTokensForExactTokens",i=[d,c,f,s,h],u="0x0")}return{methodName:o,args:i,value:u}},t}(),Et=[{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"}],Ot=((bt={})[exports.ChainId.MAINNET]={"0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A":9},bt),Nt=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,a,u=function(n){return new Z(t,e,n,r,o)};void 0===n&&(n=l.getDefaultProvider(p.getNetwork(t)));var s="number"==typeof(null===(i=Ot)||void 0===i||null===(a=i[t])||void 0===a?void 0:a[e]);return Promise.resolve(s?u(Ot[t][e]):Promise.resolve(new h.Contract(e,Et,n).decimals().then((function(n){var r,o,i;return Ot=R({},Ot,((i={})[t]=R({},null===(r=Ot)||void 0===r?void 0:r[t],((o={})[e]=n,o)),i)),n}))).then(u))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e,n){try{void 0===n&&(n=l.getDefaultProvider(p.getNetwork(t.chainId))),t.chainId!==e.chainId&&a(!1);var r=lt.getAddress(t,e);return Promise.resolve(new h.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 lt(new ft(t,i[0]),new ft(e,i[1]))}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=i,exports.Currency=G,exports.CurrencyAmount=dt,exports.ETHER=K,exports.FACTORY_ADDRESS=T,exports.Fetcher=Nt,exports.Fraction=st,exports.INIT_CODE_HASH=y,exports.InsufficientInputAmountError=L,exports.InsufficientReservesError=X,exports.MINIMUM_LIQUIDITY=w,exports.Pair=lt,exports.Percent=Tt,exports.Price=ht,exports.Route=mt,exports.Router=At,exports.Token=Z,exports.TokenAmount=ft,exports.Trade=xt,exports.WETH=rt,exports.currencyEquals=tt,exports.inputOutputComparator=yt,exports.tradeComparator=wt; //# sourceMappingURL=sdk.cjs.production.min.js.map