@0xkilo/localhost
Version:
🛠An SDK for building applications on top of Pangolin.
3 lines (2 loc) • 23.8 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,a=t(require("jsbi")),u=t(require("tiny-invariant")),s=(t(require("tiny-warning")),require("@ethersproject/address")),c=t(require("big.js")),d=t(require("toformat")),l=t(require("decimal.js-light")),p=require("@ethersproject/solidity"),f=require("@ethersproject/contracts"),h=require("@ethersproject/networks"),m=require("@ethersproject/providers"),v=t(require("@pangolindex/exchange-contracts/artifacts/contracts/pangolin-core/PangolinPair.sol/PangolinPair.json"));(r=exports.ChainId||(exports.ChainId={}))[r.FUJI=43113]="FUJI",r[r.AVALANCHE=43114]="AVALANCHE",r[r.FANTOM=31337]="FANTOM",(o=exports.TradeType||(exports.TradeType={}))[o.EXACT_INPUT=0]="EXACT_INPUT",o[o.EXACT_OUTPUT=1]="EXACT_OUTPUT",(i=exports.Rounding||(exports.Rounding={}))[i.ROUND_DOWN=0]="ROUND_DOWN",i[i.ROUND_HALF_UP=1]="ROUND_HALF_UP",i[i.ROUND_UP=2]="ROUND_UP";var y,w=((e={})[exports.ChainId.FUJI]="0xE4A575550C2b460d2307b82dCd7aFe84AD1484dd",e[exports.ChainId.AVALANCHE]="0xefa94DE7a4656D787667C749f7E1223D71E9FD88",e[exports.ChainId.FANTOM]="0xdbC43Ba45381e02825b14322cDdd15eC4B3164E6",e),g="0x40231f6b438bce0797c9ada29b718a87ea0a5cea3fe9a771abdd76bd41a3e545",A=a.BigInt(1e3),T=a.BigInt(0),k=a.BigInt(1),x=a.BigInt(2),I=a.BigInt(3),b=a.BigInt(5),O=a.BigInt(10),q=a.BigInt(100),C=a.BigInt(997),P=a.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(y||(y={}));var E=((n={})[y.uint8]=a.BigInt("0xff"),n[y.uint256]=a.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n);function U(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function _(t,e,n){return e&&U(t.prototype,e),n&&U(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 R(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function F(t){return(F=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 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 j(t,e,n){return(j=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&&D(o,n.prototype),o}).apply(null,arguments)}function X(t){var e="function"==typeof Map?new Map:void 0;return(X=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,F(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),D(n,t)})(t)}function B(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 H,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(B(n),(this instanceof e?this.constructor:void 0).prototype),n}return R(e,t),e}(X(Error)),J=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,L&&Object.setPrototypeOf(B(n),(this instanceof e?this.constructor:void 0).prototype),n}return R(e,t),e}(X(Error));function Y(t,e){a.greaterThanOrEqual(t,T)||u(!1),a.lessThanOrEqual(t,E[e])||u(!1)}function Q(t){try{return s.getAddress(t)}catch(t){u(!1)}}function $(t){return t instanceof a?t:a.BigInt("bigint"==typeof t?t.toString():t)}function z(t){Y(t,y.uint256);var e,n=T;if(a.greaterThan(t,I))for(n=t,e=a.add(a.divide(t,x),k);a.lessThan(e,n);)n=e,e=a.divide(a.add(a.divide(t,e),e),x);else a.notEqual(t,T)&&(n=k);return n}function G(t,e,n,r){if(n>0||u(!1),t.length<=n||u(!1),0===t.length)return t.push(e),null;var o=t.length===n;if(o&&r(t[t.length-1],e)<=0)return e;for(var i=0,a=t.length;i<a;){var s=i+a>>>1;r(t[s],e)<=0?i=s+1:a=s}return t.splice(i,0,e),o?t.pop():null}var K,Z=function(t,e,n){Y(a.BigInt(t),y.uint8),this.decimals=t,this.symbol=e,this.name=n},tt=Z.CURRENCY=((H={})[exports.ChainId.FUJI]=new Z(18,"AVAX","Avalanche"),H[exports.ChainId.AVALANCHE]=new Z(18,"AVAX","Avalanche"),H[exports.ChainId.FANTOM]=new Z(18,"FTM","Fantom"),H),et=function(t){function e(e,n,r,o,i){var a;return(a=t.call(this,r,o,i)||this).chainId=e,a.address=Q(n),a}R(e,t);var n=e.prototype;return n.equals=function(t){return this===t||this.chainId===t.chainId&&this.address===t.address},n.sortsBefore=function(t){return this.chainId!==t.chainId&&u(!1),this.address===t.address&&u(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(Z);function 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.FUJI]=new et(exports.ChainId.FUJI,"0xd00ae08403B9bbb9124bB305C09058E32C39A48c",18,"WAVAX","Wrapped AVAX"),K[exports.ChainId.AVALANCHE]=new et(exports.ChainId.AVALANCHE,"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",18,"WAVAX","Wrapped AVAX"),K[exports.ChainId.FANTOM]=new et(exports.ChainId.FANTOM,"0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83",18,"WFTM","Wrapped FTM"),K),at=d(l),ut=d(c),st=((rt={})[exports.Rounding.ROUND_DOWN]=at.ROUND_DOWN,rt[exports.Rounding.ROUND_HALF_UP]=at.ROUND_HALF_UP,rt[exports.Rounding.ROUND_UP]=at.ROUND_UP,rt),ct=((ot={})[exports.Rounding.ROUND_DOWN]=0,ot[exports.Rounding.ROUND_HALF_UP]=1,ot[exports.Rounding.ROUND_UP]=3,ot),dt=function(){function t(t,e){void 0===e&&(e=k),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)||u(!1),t>0||u(!1),at.set({precision:t+1,rounding:st[n]});var r=new at(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return r.toFormat(r.decimalPlaces(),e)},e.toFixed=function(t,e,n){return void 0===e&&(e={groupSeparator:""}),void 0===n&&(n=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||u(!1),t>=0||u(!1),ut.DP=t,ut.RM=ct[n],new ut(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},_(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=d(c),pt=function(t){function e(e,n){var r,o=$(n);return Y(o,y.uint256),(r=t.call(this,o,a.exponentiate(O,a.BigInt(e.decimals)))||this).currency=e,r}R(e,t),e.ether=function(t,n){return new e(tt[n],t)};var n=e.prototype;return n.add=function(t){return nt(this.currency,t.currency)||u(!1),new e(this.currency,a.add(this.raw,t.raw))},n.subtract=function(t){return nt(this.currency,t.currency)||u(!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||u(!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)},_(e,[{key:"raw",get:function(){return this.numerator}}]),e}(dt),ft=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}R(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||u(!1),new e(this.token,a.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||u(!1),new e(this.token,a.subtract(this.raw,t.raw))},e}(pt),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 dt(a.exponentiate(O,a.BigInt(e.decimals)),a.exponentiate(O,a.BigInt(n.decimals))),i}R(e,t),e.fromRoute=function(t){for(var n,r=[],o=V(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){nt(this.quoteCurrency,n.baseCurrency)||u(!1);var r=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,r.denominator,r.numerator)},n.quote=function(e,n){return nt(e.currency,this.baseCurrency)||u(!1),this.quoteCurrency instanceof et?new ft(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):pt.ether(t.prototype.multiply.call(this,e.raw).quotient,n)},n.toSignificant=function(t,e,n){return void 0===t&&(t=6),this.adjusted.toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=4),this.adjusted.toFixed(t,e,n)},_(e,[{key:"raw",get:function(){return new dt(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(dt),mt={},vt=function(){function t(e,n,r){var o=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new et(o[0].token.chainId,t.getAddress(o[0].token,o[1].token,r),18,"AXP","avaXwap"),this.tokenAmounts=o}t.getAddress=function(t,e,n){var r,o,i,a,u,c=t.sortsBefore(e)?[t,e]:[e,t];return void 0===(null===(r=mt)||void 0===r||null===(o=r[c[0].address])||void 0===o?void 0:o[c[1].address])&&(mt=N({},mt,((u={})[c[0].address]=N({},null===(i=mt)||void 0===i?void 0:i[c[0].address],((a={})[c[1].address]=s.getCreate2Address(w[n],p.keccak256(["bytes"],[p.pack(["address","address"],[c[0].address,c[1].address])]),g),a)),u))),mt[c[0].address][c[1].address]};var e=t.prototype;return e.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},e.priceOf=function(t){return this.involvesToken(t)||u(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||u(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e,n){if(this.involvesToken(e.token)||u(!1),a.equal(this.reserve0.raw,T)||a.equal(this.reserve1.raw,T))throw new W;var r=this.reserveOf(e.token),o=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),i=a.multiply(e.raw,C),s=a.multiply(i,o.raw),c=a.add(a.multiply(r.raw,P),i),d=new ft(e.token.equals(this.token0)?this.token1:this.token0,a.divide(s,c));if(a.equal(d.raw,T))throw new J;return[d,new t(r.add(e),o.subtract(d),n)]},e.getInputAmount=function(e,n){if(this.involvesToken(e.token)||u(!1),a.equal(this.reserve0.raw,T)||a.equal(this.reserve1.raw,T)||a.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new W;var r=this.reserveOf(e.token),o=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),i=a.multiply(a.multiply(o.raw,e.raw),P),s=a.multiply(a.subtract(r.raw,e.raw),C),c=new ft(e.token.equals(this.token0)?this.token1:this.token0,a.add(a.divide(i,s),k));return[c,new t(o.add(c),r.subtract(e),n)]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||u(!1);var r,o=e.token.sortsBefore(n.token)?[e,n]:[n,e];if(o[0].token.equals(this.token0)&&o[1].token.equals(this.token1)||u(!1),a.equal(t.raw,T))r=a.subtract(z(a.multiply(o[0].raw,o[1].raw)),A);else{var i=a.divide(a.multiply(o[0].raw,t.raw),this.reserve0.raw),s=a.divide(a.multiply(o[1].raw,t.raw),this.reserve1.raw);r=a.lessThanOrEqual(i,s)?i:s}if(!a.greaterThan(r,T))throw new J;return new ft(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var i;if(void 0===r&&(r=!1),this.involvesToken(t)||u(!1),e.token.equals(this.liquidityToken)||u(!1),n.token.equals(this.liquidityToken)||u(!1),a.lessThanOrEqual(n.raw,e.raw)||u(!1),r){o||u(!1);var s=$(o);if(a.equal(s,T))i=e;else{var c=z(a.multiply(this.reserve0.raw,this.reserve1.raw)),d=z(s);if(a.greaterThan(c,d)){var l=a.multiply(e.raw,a.subtract(c,d)),p=a.add(a.multiply(c,b),d),f=a.divide(l,p);i=e.add(new ft(this.liquidityToken,f))}else i=e}}else i=e;return new ft(t,a.divide(a.multiply(n.raw,this.reserveOf(t).raw),i.raw))},_(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||u(!1),t.every((function(e){return e.chainId===t[0].chainId}))||u(!1),e instanceof et&&t[0].involvesToken(e)||e===tt[t[0].chainId]&&t[0].involvesToken(it[t[0].chainId])||u(!1),void 0===n||n instanceof et&&t[t.length-1].involvesToken(n)||n===tt[t[0].chainId]&&t[t.length-1].involvesToken(it[t[0].chainId])||u(!1);for(var r,o=[e instanceof et?e:it[t[0].chainId]],i=V(t.entries());!(r=i()).done;){var a=r.value,s=a[1],c=o[a[0]];c.equals(s.token0)||c.equals(s.token1)||u(!1);var d=c.equals(s.token0)?s.token1:s.token0;o.push(d)}this.pairs=t,this.path=o,this.midPrice=ht.fromRoute(this),this.input=e,this.output=null!=n?n:o[o.length-1]}return _(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),wt=new dt(q),gt=function(t){function e(){return t.apply(this,arguments)||this}R(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(wt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(wt).toFixed(t,e,n)},e}(dt);function At(t,e){return nt(t.inputAmount.currency,e.inputAmount.currency)||u(!1),nt(t.outputAmount.currency,e.outputAmount.currency)||u(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?0:t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}function Tt(t,e){var n=At(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===tt[e]?new ft(it[e],t.raw):void u(!1)}function xt(t,e){return t instanceof et?t:t===tt[e]?it[e]:void u(!1)}var It=function(){function t(t,e,n,r){var o,i,a,s=new Array(t.path.length),c=new Array(t.pairs.length);if(n===exports.TradeType.EXACT_INPUT){nt(e.currency,t.input)||u(!1),s[0]=kt(e,t.chainId);for(var d=0;d<t.path.length-1;d++){var l=t.pairs[d].getOutputAmount(s[d],r),p=l[1];s[d+1]=l[0],c[d]=p}}else{nt(e.currency,t.output)||u(!1),s[s.length-1]=kt(e,t.chainId);for(var f=t.path.length-1;f>0;f--){var h=t.pairs[f-1].getInputAmount(s[f],r),m=h[1];s[f-1]=h[0],c[f-1]=m}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===tt[r]?pt.ether(s[0].raw,r):s[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===tt[r]?pt.ether(s[s.length-1].raw,r):s[s.length-1],this.executionPrice=new ht(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=ht.fromRoute(new yt(c,t.input)),this.priceImpact=(o=this.outputAmount,a=(i=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(o.raw).divide(i),new gt(a.numerator,a.denominator)),this.chainId=r}t.exactIn=function(e,n,r){return new t(e,n,exports.TradeType.EXACT_INPUT,r)},t.exactOut=function(e,n,r){return new t(e,n,exports.TradeType.EXACT_OUTPUT,r)};var e=t.prototype;return e.minimumAmountOut=function(t,e){if(t.lessThan(T)&&u(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var n=new dt(k).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof ft?new ft(this.outputAmount.token,n):pt.ether(n,e)},e.maximumAmountIn=function(t,e){if(t.lessThan(T)&&u(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var n=new dt(k).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof ft?new ft(this.inputAmount.token,n):pt.ether(n,e)},t.bestTradeExactIn=function(e,n,r,o,i,a,s){var c=void 0===o?{}:o,d=c.maxNumResults,l=void 0===d?3:d,p=c.maxHops,f=void 0===p?3:p;void 0===i&&(i=[]),void 0===a&&(a=n),void 0===s&&(s=[]),e.length>0||u(!1),f>0||u(!1),a===n||i.length>0||u(!1);var h=n instanceof ft?n.token.chainId:r instanceof et?r.chainId:void 0;void 0===h&&u(!1);for(var m=kt(n,h),v=xt(r,h),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(m.token)||w.token1.equals(m.token))&&!w.reserve0.equalTo(T)&&!w.reserve1.equalTo(T)){var g=void 0;try{g=w.getOutputAmount(m,h)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(g.token.equals(v))G(s,new t(new yt([].concat(i,[w]),a.currency,r),a,exports.TradeType.EXACT_INPUT,h),l,Tt);else if(f>1&&e.length>1){var A=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(A,g,r,{maxNumResults:l,maxHops:f-1},[].concat(i,[w]),a,s)}}}return s},t.bestTradeExactOut=function(e,n,r,o,i,a,s){var c=void 0===o?{}:o,d=c.maxNumResults,l=void 0===d?3:d,p=c.maxHops,f=void 0===p?3:p;void 0===i&&(i=[]),void 0===a&&(a=r),void 0===s&&(s=[]),e.length>0||u(!1),f>0||u(!1),a===r||i.length>0||u(!1);var h=r instanceof ft?r.token.chainId:n instanceof et?n.chainId:void 0;void 0===h&&u(!1);for(var m=kt(r,h),v=xt(n,h),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(m.token)||w.token1.equals(m.token))&&!w.reserve0.equalTo(T)&&!w.reserve1.equalTo(T)){var g=void 0;try{g=w.getInputAmount(m,h)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(g.token.equals(v))G(s,new t(new yt([w].concat(i),n,a.currency),a,exports.TradeType.EXACT_OUTPUT,h),l,Tt);else if(f>1&&e.length>1){var A=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(A,n,g,{maxNumResults:l,maxHops:f-1},[w].concat(i),a,s)}}}return s},t}();function bt(t){return"0x"+t.raw.toString(16)}var Ot=function(){function t(){}return t.swapCallParameters=function(t,e,n){var r=t.inputAmount.currency===tt[n],o=t.outputAmount.currency===tt[n];r&&o&&u(!1),!("ttl"in e)||e.ttl>0||u(!1);var i,a,s,c=Q(e.recipient),d=bt(t.maximumAmountIn(e.allowedSlippage,n)),l=bt(t.minimumAmountOut(e.allowedSlippage,n)),p=t.route.path.map((function(t){return t.address})),f="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),h=Boolean(e.feeOnTransfer);switch(t.tradeType){case exports.TradeType.EXACT_INPUT:r?(i=h?"swapExactAVAXForTokensSupportingFeeOnTransferTokens":"swapExactAVAXForTokens",a=[l,p,c,f],s=d):o?(i=h?"swapExactTokensForAVAXSupportingFeeOnTransferTokens":"swapExactTokensForAVAX",a=[d,l,p,c,f],s="0x0"):(i=h?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",a=[d,l,p,c,f],s="0x0");break;case exports.TradeType.EXACT_OUTPUT:h&&u(!1),r?(i="swapAVAXForExactTokens",a=[l,p,c,f],s=d):o?(i="swapTokensForExactAVAX",a=[l,d,p,c,f],s="0x0"):(i="swapTokensForExactTokens",a=[l,d,p,c,f],s="0x0")}return{methodName:i,args:a,value:s}},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={},Pt=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,a,u=function(n){return new et(t,e,n,r,o)};void 0===n&&(n=m.getDefaultProvider(h.getNetwork(t)));var s="number"==typeof(null===(i=Ct)||void 0===i||null===(a=i[t])||void 0===a?void 0:a[e]);return Promise.resolve(s?u(Ct[t][e]):Promise.resolve(new f.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(u))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e,n){try{void 0===n&&(n=m.getDefaultProvider(h.getNetwork(t.chainId))),t.chainId!==e.chainId&&u(!1);var r=vt.getAddress(t,e,t.chainId);return Promise.resolve(new f.Contract(r,v.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 ft(t,i[0]),new ft(e,i[1]),t.chainId)}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=a,exports.CAVAX=tt,exports.Currency=Z,exports.CurrencyAmount=pt,exports.FACTORY_ADDRESS=w,exports.Fetcher=Pt,exports.Fraction=dt,exports.INIT_CODE_HASH=g,exports.InsufficientInputAmountError=J,exports.InsufficientReservesError=W,exports.MINIMUM_LIQUIDITY=A,exports.Pair=vt,exports.Percent=gt,exports.Price=ht,exports.Route=yt,exports.Router=Ot,exports.Token=et,exports.TokenAmount=ft,exports.Trade=It,exports.WAVAX=it,exports.currencyEquals=nt,exports.inputOutputComparator=At,exports.tradeComparator=Tt;
//# sourceMappingURL=localhost.cjs.production.min.js.map