moonwalkerswap-avalanche-sdk
Version:
🛠An SDK for building applications on top of Moonwalkerswap.
3 lines (2 loc) • 30.3 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")),a=t(require("tiny-invariant")),u=(t(require("tiny-warning")),require("@ethersproject/address")),s=t(require("big.js")),c=t(require("toformat")),f=t(require("decimal.js-light")),l=require("@ethersproject/solidity"),h=require("@ethersproject/contracts"),p=require("@ethersproject/networks"),d=require("@ethersproject/providers"),v=t(require("moonwalkerswap-v2-core/build/contracts/IMoonwalkerPair.json"));(n=exports.ChainId||(exports.ChainId={}))[n.AVALANCHE=43114]="AVALANCHE",(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 m,y="0xdc881fbbbdf45595337cc751b266384ded4942f7326bf7ebbc8bde142f820018",w=i.BigInt(1e3),g=i.BigInt(0),T=i.BigInt(1),k=i.BigInt(2),x=i.BigInt(3),b=i.BigInt(5),A=i.BigInt(10),O=i.BigInt(100),I=i.BigInt(997),E=i.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(m||(m={}));var q=((e={})[m.uint8]=i.BigInt("0xff"),e[m.uint256]=i.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),e);function _(t,e,n,r,o,i,a){try{var u=t[i](a),s=u.value}catch(t){return void n(t)}u.done?e(s):Promise.resolve(s).then(r,o)}function P(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var i=t.apply(e,n);function a(t){_(i,r,o,a,u,"next",t)}function u(t){_(i,r,o,a,u,"throw",t)}a(void 0)}))}}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 R(t,e,n){return e&&N(t.prototype,e),n&&N(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function U(){return(U=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 C(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,S(t,e)}function L(t){return(L=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function S(t,e){return(S=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function j(){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 F(t,e,n){return(F=j()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&S(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 F(t,arguments,L(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 B(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 X(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 B(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)?B(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 M="setPrototypeOf"in Object,W=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,M&&Object.setPrototypeOf(H(n),(this instanceof e?this.constructor:void 0).prototype),n}return C(e,t),e}(D(Error)),V=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,M&&Object.setPrototypeOf(H(n),(this instanceof e?this.constructor:void 0).prototype),n}return C(e,t),e}(D(Error));function G(t,e){i.greaterThanOrEqual(t,g)||a(!1),i.lessThanOrEqual(t,q[e])||a(!1)}function Y(t){try{return u.getAddress(t)}catch(t){a(!1)}}function J(t){return t instanceof i?t:i.BigInt("bigint"==typeof t?t.toString():t)}function Q(t){G(t,m.uint256);var e,n=g;if(i.greaterThan(t,x))for(n=t,e=i.add(i.divide(t,k),T);i.lessThan(e,n);)n=e,e=i.divide(i.add(i.divide(t,e),e),k);else i.notEqual(t,g)&&(n=T);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,K=function(t,e,n){G(i.BigInt(t),m.uint8),this.decimals=t,this.symbol=e,this.name=n},Z=K.ETHER=new K(18,"Avax","Avax"),tt=function(t){function e(e,n,r,o,i){var a;return(a=t.call(this,r,o,i)||this).chainId=e,a.address=Y(n),a}C(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}(K);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=((z={})[exports.ChainId.AVALANCHE]=new tt(exports.ChainId.AVALANCHE,"0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",18,"WAVAX","Wrapped Avax"),z),it=c(f),at=c(s),ut=((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=T),this.numerator=J(t),this.denominator=J(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(J(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(J(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(J(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(J(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(J(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(J(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(J(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),it.set({precision:t+1,rounding:ut[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)||a(!1),t>=0||a(!1),at.DP=t,at.RM=st[n],new at(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},R(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}(),ft=c(s),lt=function(t){function e(e,n){var r,o=J(n);return G(o,m.uint256),(r=t.call(this,o,i.exponentiate(A,i.BigInt(e.decimals)))||this).currency=e,r}C(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)||a(!1),new e(this.currency,i.add(this.raw,t.raw))},n.subtract=function(t){return et(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:""}),ft.DP=this.currency.decimals,new ft(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},R(e,[{key:"raw",get:function(){return this.numerator}}]),e}(ct),ht=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}C(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}(lt),pt=function(t){function e(e,n,r,o){var a;return(a=t.call(this,o,r)||this).baseCurrency=e,a.quoteCurrency=n,a.scalar=new ct(i.exponentiate(A,i.BigInt(e.decimals)),i.exponentiate(A,i.BigInt(n.decimals))),a}C(e,t),e.fromRoute=function(t){for(var n,r=[],o=X(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):new e(a.reserve1.currency,a.reserve0.currency,a.reserve1.raw,a.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)||a(!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)||a(!1),this.quoteCurrency instanceof tt?new ht(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):lt.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)},R(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),dt={},vt=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,"SLR-V2","Solar V2"),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=dt)||null==(r=n[s[0].address])?void 0:r[s[1].address])&&(dt=U({},dt,((a={})[s[0].address]=U({},null==(o=dt)?void 0:o[s[0].address],((i={})[s[1].address]=u.getCreate2Address("0x2b85c99d6f40f584c8742aafd93844309df396cb",l.keccak256(["bytes"],[l.pack(["address","address"],[s[0].address,s[1].address])]),y),i)),a))),dt[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,g)||i.equal(this.reserve1.raw,g))throw new W;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=i.multiply(e.raw,I),u=i.multiply(o,r.raw),s=i.add(i.multiply(n.raw,E),o),c=new ht(e.token.equals(this.token0)?this.token1:this.token0,i.divide(u,s));if(i.equal(c.raw,g))throw new V;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,g)||i.equal(this.reserve1.raw,g)||i.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=i.multiply(i.multiply(r.raw,e.raw),E),u=i.multiply(i.subtract(n.raw,e.raw),I),s=new ht(e.token.equals(this.token0)?this.token1:this.token0,i.add(i.divide(o,u),T));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,g))r=i.subtract(Q(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,g))throw new V;return new ht(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=J(o);if(i.equal(s,g))u=e;else{var c=Q(i.multiply(this.reserve0.raw,this.reserve1.raw)),f=Q(s);if(i.greaterThan(c,f)){var l=i.multiply(e.raw,i.subtract(c,f)),h=i.add(i.multiply(c,b),f),p=i.divide(l,h);u=e.add(new ht(this.liquidityToken,p))}else u=e}}else u=e;return new ht(t,i.divide(i.multiply(n.raw,this.reserveOf(t).raw),u.raw))},R(t,[{key:"token0Price",get:function(){return new pt(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new pt(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}(),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 tt&&t[0].involvesToken(e)||e===Z&&t[0].involvesToken(ot[t[0].chainId])||a(!1),void 0===n||n instanceof tt&&t[t.length-1].involvesToken(n)||n===Z&&t[t.length-1].involvesToken(ot[t[0].chainId])||a(!1);for(var r,o=[e instanceof tt?e:ot[t[0].chainId]],i=X(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 f=c.equals(s.token0)?s.token1:s.token0;o.push(f)}this.pairs=t,this.path=o,this.midPrice=pt.fromRoute(this),this.input=e,this.output=null!=n?n:o[o.length-1]}return R(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),yt=new ct(O),wt=function(t){function e(){return t.apply(this,arguments)||this}C(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 gt(t,e){return et(t.inputAmount.currency,e.inputAmount.currency)||a(!1),et(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 Tt(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 kt(t,e){return t instanceof ht?t:t.currency===Z?new ht(ot[e],t.raw):void a(!1)}function xt(t,e){return t instanceof tt?t:t===Z?ot[e]:void a(!1)}var bt=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){et(e.currency,t.input)||a(!1),u[0]=kt(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],s[c]=l}}else{et(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]),d=p[1];u[h-1]=p[0],s[h-1]=d}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===Z?lt.ether(u[0].raw):u[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===Z?lt.ether(u[u.length-1].raw):u[u.length-1],this.executionPrice=new pt(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=pt.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 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(g)&&a(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new ct(T).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof ht?new ht(this.outputAmount.token,e):lt.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(g)&&a(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new ct(T).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof ht?new ht(this.inputAmount.token,e):lt.ether(e)},t.bestTradeExactIn=function(e,n,r,o,i,u,s){var c=void 0===o?{}:o,f=c.maxNumResults,l=void 0===f?3:f,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 d=n instanceof ht?n.token.chainId:r instanceof tt?r.chainId:void 0;void 0===d&&a(!1);for(var v=kt(n,d),m=xt(r,d),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(v.token)||w.token1.equals(v.token))&&!w.reserve0.equalTo(g)&&!w.reserve1.equalTo(g)){var T=void 0;try{T=w.getOutputAmount(v)[0]}catch(t){if(t instanceof Error)continue;throw t}if(T.token.equals(m))$(s,new t(new mt([].concat(i,[w]),u.currency,r),u,exports.TradeType.EXACT_INPUT),l,Tt);else if(p>1&&e.length>1){var k=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(k,T,r,{maxNumResults:l,maxHops:p-1},[].concat(i,[w]),u,s)}}}return s},t.bestTradeExactOut=function(e,n,r,o,i,u,s){var c=void 0===o?{}:o,f=c.maxNumResults,l=void 0===f?3:f,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 d=r instanceof ht?r.token.chainId:n instanceof tt?n.chainId:void 0;void 0===d&&a(!1);for(var v=kt(r,d),m=xt(n,d),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(v.token)||w.token1.equals(v.token))&&!w.reserve0.equalTo(g)&&!w.reserve1.equalTo(g)){var T=void 0;try{T=w.getInputAmount(v)[0]}catch(t){if(t instanceof Error)continue;throw t}if(T.token.equals(m))$(s,new t(new mt([w].concat(i),n,u.currency),u,exports.TradeType.EXACT_OUTPUT),l,Tt);else if(p>1&&e.length>1){var k=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(k,n,T,{maxNumResults:l,maxHops:p-1},[w].concat(i),u,s)}}}return s},t}();function At(t){return"0x"+t.raw.toString(16)}var Ot,It,Et=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===Z,r=t.outputAmount.currency===Z;n&&r&&a(!1),e.ttl>0||a(!1);var o,i,u,s=Y(e.recipient),c=At(t.maximumAmountIn(e.allowedSlippage)),f=At(t.minimumAmountOut(e.allowedSlippage)),l=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=[f,l,s,h],u=c):r?(o=p?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[c,f,l,s,h],u="0x0"):(o=p?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[c,f,l,s,h],u="0x0");break;case exports.TradeType.EXACT_OUTPUT:p&&a(!1),n?(o="swapETHForExactTokens",i=[f,l,s,h],u=c):r?(o="swapTokensForExactETH",i=[f,c,l,s,h],u="0x0"):(o="swapTokensForExactTokens",i=[f,c,l,s,h],u="0x0")}return{methodName:o,args:i,value:u}},t}(),qt=(function(t){var e=function(t){var e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",i=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function u(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,n){return t[e]=n}}function s(t,e,n,r){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new b(r||[]);return o._invoke=function(t,e,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return{value:void 0,done:!0}}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var u=T(a,n);if(u){if(u===f)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var s=c(t,e,n);if("normal"===s.type){if(r=n.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r="completed",n.method="throw",n.arg=s.arg)}}}(t,n,i),o}function c(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function l(){}function h(){}function p(){}var d={};u(d,o,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(A([])));m&&m!==e&&n.call(m,o)&&(d=m);var y=p.prototype=l.prototype=Object.create(d);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){var r;this._invoke=function(o,i){function a(){return new e((function(r,a){!function r(o,i,a,u){var s=c(t[o],t,i);if("throw"!==s.type){var f=s.arg,l=f.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return r("throw",t,a,u)}))}u(s.arg)}(o,i,r,a)}))}return r=r?r.then(a,a):a()}}function T(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,T(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var r=c(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,f;var o=r.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function b(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function A(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return h.prototype=p,u(y,"constructor",p),u(p,"constructor",h),h.displayName=u(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,u(t,a,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},w(g.prototype),u(g.prototype,i,(function(){return this})),t.AsyncIterator=g,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var a=new g(s(e,n,r,o),i);return t.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=A,b.prototype={constructor:b,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(n,r){return a.type="throw",a.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),x(n),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;x(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:A(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(It={exports:{}}),It.exports),_t=[{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"}],Pt=((Ot={})[exports.ChainId.AVALANCHE]={"0x5ce9680bddc91d955a51b959f5cabaf466b0be5a":18},Ot),Nt=function(){function t(){}return t.fetchTokenData=function(){var t=P(qt.mark((function t(e,n,r,o,i){var a,u;return qt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===r&&(r=d.getDefaultProvider(p.getNetwork(e))),"number"!=typeof(null==(a=Pt)||null==(u=a[e])?void 0:u[n])){t.next=5;break}t.t0=Pt[e][n],t.next=8;break;case 5:return t.next=7,new h.Contract(n,_t,r).decimals().then((function(t){var r,o,i;return Pt=U({},Pt,((i={})[e]=U({},null==(r=Pt)?void 0:r[e],((o={})[n]=t,o)),i)),t}));case 7:t.t0=t.sent;case 8:return t.abrupt("return",new tt(e,n,t.t0,o,i));case 10:case"end":return t.stop()}}),t)})));return function(e,n,r,o,i){return t.apply(this,arguments)}}(),t.fetchPairData=function(){var t=P(qt.mark((function t(e,n,r){var o,i,u,s,c;return qt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r=d.getDefaultProvider(p.getNetwork(e.chainId))),e.chainId!==n.chainId&&a(!1),o=vt.getAddress(e,n),t.next=5,new h.Contract(o,v.abi,r).getReserves();case 5:return u=(i=t.sent)[0],s=i[1],c=e.sortsBefore(n)?[u,s]:[s,u],t.abrupt("return",new vt(new ht(e,c[0]),new ht(n,c[1])));case 10:case"end":return t.stop()}}),t)})));return function(e,n,r){return t.apply(this,arguments)}}(),t}();exports.JSBI=i,exports.Currency=K,exports.CurrencyAmount=lt,exports.ETHER=Z,exports.FACTORY_ADDRESS="0x2b85c99d6f40f584c8742aafd93844309df396cb",exports.Fetcher=Nt,exports.Fraction=ct,exports.INIT_CODE_HASH=y,exports.InsufficientInputAmountError=V,exports.InsufficientReservesError=W,exports.MINIMUM_LIQUIDITY=w,exports.Pair=vt,exports.Percent=wt,exports.Price=pt,exports.Route=mt,exports.Router=Et,exports.Token=tt,exports.TokenAmount=ht,exports.Trade=bt,exports.WETH=ot,exports.currencyEquals=et,exports.inputOutputComparator=gt,exports.tradeComparator=Tt;
//# sourceMappingURL=moonwalkerswap-avalanche-sdk.cjs.production.min.js.map