UNPKG

@mochiswap/asdk

Version:

🛠 An SDK for building applications on top of MochiSwap.

3 lines (2 loc) • 23.9 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,u,a=t(require("jsbi")),s=t(require("tiny-invariant")),c=(t(require("tiny-warning")),require("@ethersproject/address")),l=t(require("big.js")),d=t(require("toformat")),p=t(require("decimal.js-light")),f=require("@ethersproject/solidity"),h=require("@ethersproject/contracts"),m=require("@ethersproject/networks"),v=require("@ethersproject/providers"),y=t(require("@mochiswap/core/build/IMochiPair.json"));(r=exports.Blockchain||(exports.Blockchain={}))[r.ETHEREUM=1]="ETHEREUM",r[r.BINANCE_SMART_CHAIN=2]="BINANCE_SMART_CHAIN",r[r.HARMONY=3]="HARMONY",r[r.AVAX=4]="AVAX",(o=exports.ChainId||(exports.ChainId={}))[o.MAINNET=43114]="MAINNET",o[o.AVAX=43114]="AVAX",(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 w,T=((e={})[exports.ChainId.MAINNET]="0xd9F58F79bcdFb5cF5E7741eb14Ca4060d32F2b21",e[exports.ChainId.AVAX]="0xd9F58F79bcdFb5cF5E7741eb14Ca4060d32F2b21",e),A="0xeff99456d11797424a098ab4631ed7db0a76f6708d68052abfb7c4036616a739",g=a.BigInt(1e3),k=a.BigInt(0),x=a.BigInt(1),I=a.BigInt(2),O=a.BigInt(3),b=a.BigInt(5),q=a.BigInt(10),E=a.BigInt(100),P=a.BigInt(997),R=a.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(w||(w={}));var C=((n={})[w.uint8]=a.BigInt("0xff"),n[w.uint256]=a.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n);function N(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 U(t,e,n){return e&&N(t.prototype,e),n&&N(t,n),t}function _(){return(_=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,D(t,e)}function S(t){return(S=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 B(){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 X(t,e,n){return(X=B()?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 X(t,arguments,S(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),D(n,t)})(t)}function j(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 V(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 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.")}return(n=t[Symbol.iterator]()).next.bind(n)}var L="setPrototypeOf"in Object,W=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,L&&Object.setPrototypeOf(j(n),(this instanceof e?this.constructor:void 0).prototype),n}return F(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,L&&Object.setPrototypeOf(j(n),(this instanceof e?this.constructor:void 0).prototype),n}return F(e,t),e}(H(Error));function J(t,e){a.greaterThanOrEqual(t,k)||s(!1),a.lessThanOrEqual(t,C[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,w.uint256);var e,n=k;if(a.greaterThan(t,O))for(n=t,e=a.add(a.divide(t,I),x);a.lessThan(e,n);)n=e,e=a.divide(a.add(a.divide(t,e),e),I);else a.notEqual(t,k)&&(n=x);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,tt=function(t,e,n){J(a.BigInt(t),w.uint8),this.decimals=t,this.symbol=e,this.name=n},et=tt.ETHER=new tt(18,"AVAX","Avalanche"),nt=tt.AVAX=new tt(18,"AVAX","Avalanche"),rt=tt.MOCHI=new tt(18,"aMOCHI","Mochiswap Token"),ot=[et,rt,nt],it=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}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&&s(!1),this.address===t.address&&s(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(tt);function ut(t,e){return t instanceof it&&e instanceof it?t.equals(e):!(t instanceof it||e instanceof it||t!==e)}var at,st,ct=((K={})[exports.ChainId.AVAX]=new it(exports.ChainId.AVAX,"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",18,"AVAX","Wrapped AVAX"),K),lt=((Z={})[exports.ChainId.AVAX]=new it(exports.ChainId.AVAX,"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",18,"AVAX","Wrapped AVAX"),Z),dt=d(p),pt=d(l),ft=((at={})[exports.Rounding.ROUND_DOWN]=dt.ROUND_DOWN,at[exports.Rounding.ROUND_HALF_UP]=dt.ROUND_HALF_UP,at[exports.Rounding.ROUND_UP]=dt.ROUND_UP,at),ht=((st={})[exports.Rounding.ROUND_DOWN]=0,st[exports.Rounding.ROUND_HALF_UP]=1,st[exports.Rounding.ROUND_UP]=3,st),mt=function(){function t(t,e){void 0===e&&(e=x),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),dt.set({precision:t+1,rounding:ft[n]});var r=new dt(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),pt.DP=t,pt.RM=ht[n],new pt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},U(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}(),vt=d(l),yt=function(t){function e(e,n){var r,o=$(n);return J(o,w.uint256),(r=t.call(this,o,a.exponentiate(q,a.BigInt(e.decimals)))||this).currency=e,r}F(e,t),e.ether=function(t){return new e(et,t)};var n=e.prototype;return n.add=function(t){return ut(this.currency,t.currency)||s(!1),new e(this.currency,a.add(this.raw,t.raw))},n.subtract=function(t){return ut(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:""}),vt.DP=this.currency.decimals,new vt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},U(e,[{key:"raw",get:function(){return this.numerator}}]),e}(mt),wt=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)||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}(yt),Tt=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 mt(a.exponentiate(q,a.BigInt(e.decimals)),a.exponentiate(q,a.BigInt(n.decimals))),i}F(e,t),e.fromRoute=function(t){console.log("fromRoute",t);for(var n,r=[],o=V(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){ut(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 ut(e.currency,this.baseCurrency)||s(!1),this.quoteCurrency instanceof it?new wt(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):yt.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)},U(e,[{key:"raw",get:function(){return new mt(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(mt),At={},gt=function(){function t(e,n){var r=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new it(r[0].token.chainId,t.getAddress(r[0].token,r[1].token),18,"MOCHI-LP","Mochi LP Token"),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=At)||void 0===n||null===(r=n[a[0].address])||void 0===r?void 0:r[a[1].address])&&(At=_({},At,((u={})[a[0].address]=_({},null===(o=At)||void 0===o?void 0:o[a[0].address],((i={})[a[1].address]=c.getCreate2Address(T[t.chainId],f.keccak256(["bytes"],[f.pack(["address","address"],[a[0].address,a[1].address])]),A),i)),u))),At[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,k)||a.equal(this.reserve1.raw,k))throw new W;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=a.multiply(e.raw,P),i=a.multiply(o,r.raw),u=a.add(a.multiply(n.raw,R),o),c=new wt(e.token.equals(this.token0)?this.token1:this.token0,a.divide(i,u));if(a.equal(c.raw,k))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,k)||a.equal(this.reserve1.raw,k)||a.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new W;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),R),i=a.multiply(a.subtract(n.raw,e.raw),P),u=new wt(e.token.equals(this.token0)?this.token1:this.token0,a.add(a.divide(o,i),x));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,k))r=a.subtract(z(a.multiply(o[0].raw,o[1].raw)),g);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,k))throw new Y;return new wt(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,k))i=e;else{var c=z(a.multiply(this.reserve0.raw,this.reserve1.raw)),l=z(u);if(a.greaterThan(c,l)){var d=a.multiply(e.raw,a.subtract(c,l)),p=a.add(a.multiply(c,b),l),f=a.divide(d,p);i=e.add(new wt(this.liquidityToken,f))}else i=e}}else i=e;return new wt(t,a.divide(a.multiply(n.raw,this.reserveOf(t).raw),i.raw))},U(t,[{key:"token0Price",get:function(){return new Tt(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new Tt(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}(),kt=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 it&&t[0].involvesToken(e)||e&&ot.includes(e)&&t[0].involvesToken(ct[t[0].chainId])||s(!1),void 0===n||n instanceof it&&t[t.length-1].involvesToken(n)||n&&ot.includes(n)&&t[t.length-1].involvesToken(ct[t[0].chainId])||s(!1);for(var r,o=[e instanceof it?e:ct[t[0].chainId]],i=V(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 l=c.equals(a.token0)?a.token1:a.token0;o.push(l)}this.pairs=t,this.path=o,this.midPrice=Tt.fromRoute(this),this.input=e,this.output=null!=n?n:o[o.length-1]}return U(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),xt=new mt(E),It=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(xt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(xt).toFixed(t,e,n)},e}(mt);function Ot(t,e){return ut(t.inputAmount.currency,e.inputAmount.currency)||s(!1),ut(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 bt(t,e){var n=Ot(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 qt(t,e){return t instanceof wt?t:t.currency&&ot.includes(t.currency)?new wt(ct[e],t.raw):void s(!1)}function Et(t,e){return t instanceof it?t:t&&ot.includes(t)?ct[e]:void s(!1)}var Pt=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){ut(e.currency,t.input)||s(!1),u[0]=qt(e,t.chainId);for(var c=0;c<t.path.length-1;c++){var l=t.pairs[c].getOutputAmount(u[c]),d=l[1];u[c+1]=l[0],a[c]=d}}else{ut(e.currency,t.output)||s(!1),u[u.length-1]=qt(e,t.chainId);for(var p=t.path.length-1;p>0;p--){var f=t.pairs[p-1].getInputAmount(u[p]),h=f[1];u[p-1]=f[0],a[p-1]=h}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input&&ot.includes(t.input)?yt.ether(u[0].raw):u[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output&&ot.includes(t.output)?yt.ether(u[u.length-1].raw):u[u.length-1],this.executionPrice=new Tt(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=Tt.fromRoute(new kt(a,t.input)),this.priceImpact=(r=this.outputAmount,i=(o=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(r.raw).divide(o),new It(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)&&s(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new mt(x).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof wt?new wt(this.outputAmount.token,e):yt.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(k)&&s(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new mt(x).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof wt?new wt(this.inputAmount.token,e):yt.ether(e)},t.bestTradeExactIn=function(e,n,r,o,i,u,a){var c=void 0===o?{}:o,l=c.maxNumResults,d=void 0===l?3:l,p=c.maxHops,f=void 0===p?3:p;void 0===i&&(i=[]),void 0===u&&(u=n),void 0===a&&(a=[]),e.length>0||s(!1),f>0||s(!1),u===n||i.length>0||s(!1);var h=n instanceof wt?n.token.chainId:r instanceof it?r.chainId:void 0;void 0===h&&s(!1);for(var m=qt(n,h),v=Et(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(k)&&!w.reserve1.equalTo(k)){var T=void 0;try{T=w.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(T.token.equals(v))G(a,new t(new kt([].concat(i,[w]),u.currency,r),u,exports.TradeType.EXACT_INPUT),d,bt);else if(f>1&&e.length>1){var A=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(A,T,r,{maxNumResults:d,maxHops:f-1},[].concat(i,[w]),u,a)}}}return a},t.bestTradeExactOut=function(e,n,r,o,i,u,a){var c=void 0===o?{}:o,l=c.maxNumResults,d=void 0===l?3:l,p=c.maxHops,f=void 0===p?3:p;void 0===i&&(i=[]),void 0===u&&(u=r),void 0===a&&(a=[]),e.length>0||s(!1),f>0||s(!1),u===r||i.length>0||s(!1);var h=r instanceof wt?r.token.chainId:n instanceof it?n.chainId:void 0;void 0===h&&s(!1);for(var m=qt(r,h),v=Et(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(k)&&!w.reserve1.equalTo(k)){var T=void 0;try{T=w.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(T.token.equals(v))G(a,new t(new kt([w].concat(i),n,u.currency),u,exports.TradeType.EXACT_OUTPUT),d,bt);else if(f>1&&e.length>1){var A=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(A,n,T,{maxNumResults:d,maxHops:f-1},[w].concat(i),u,a)}}}return a},t}();function Rt(t){return"0x"+t.raw.toString(16)}var Ct,Nt=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency&&ot.includes(t.inputAmount.currency),r=t.outputAmount.currency&&ot.includes(t.outputAmount.currency);n&&r&&s(!1),!("ttl"in e)||e.ttl>0||s(!1);var o,i,u,a=Q(e.recipient),c=Rt(t.maximumAmountIn(e.allowedSlippage)),l=Rt(t.minimumAmountOut(e.allowedSlippage)),d=t.route.path.map((function(t){return t.address})),p="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),f=Boolean(e.feeOnTransfer);switch(t.tradeType){case exports.TradeType.EXACT_INPUT:n?(o=f?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[l,d,a,p],u=c):r?(o=f?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[c,l,d,a,p],u="0x0"):(o=f?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[c,l,d,a,p],u="0x0");break;case exports.TradeType.EXACT_OUTPUT:f&&s(!1),n?(o="swapETHForExactTokens",i=[l,d,a,p],u=c):r?(o="swapTokensForExactETH",i=[l,c,d,a,p],u="0x0"):(o="swapTokensForExactTokens",i=[l,c,d,a,p],u="0x0")}return{methodName:o,args:i,value:u}},t}(),Ut=[{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"}],_t=((Ct={})[exports.ChainId.MAINNET]={"0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A":9},Ct),Ft=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,u,a=function(n){return new it(t,e,n,r,o)};void 0===n&&(n=v.getDefaultProvider(m.getNetwork(t)));var s="number"==typeof(null===(i=_t)||void 0===i||null===(u=i[t])||void 0===u?void 0:u[e]);return Promise.resolve(s?a(_t[t][e]):Promise.resolve(new h.Contract(e,Ut,n).decimals().then((function(n){var r,o,i;return _t=_({},_t,((i={})[t]=_({},null===(r=_t)||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=gt.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 gt(new wt(t,i[0]),new wt(e,i[1]))}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=a,exports.AVAX=nt,exports.Currency=tt,exports.CurrencyAmount=yt,exports.DEFAULT_CURRENCIES=ot,exports.ETHER=et,exports.FACTORY_ADDRESSES=T,exports.Fetcher=Ft,exports.Fraction=mt,exports.INIT_CODE_HASH=A,exports.InsufficientInputAmountError=Y,exports.InsufficientReservesError=W,exports.MINIMUM_LIQUIDITY=g,exports.MOCHI=rt,exports.Pair=gt,exports.Percent=It,exports.Price=Tt,exports.Route=kt,exports.Router=Nt,exports.Token=it,exports.TokenAmount=wt,exports.Trade=Pt,exports.WAVAX=lt,exports.WETH=ct,exports.currencyEquals=ut,exports.inputOutputComparator=Ot,exports.tradeComparator=bt; //# sourceMappingURL=asdk.cjs.production.min.js.map