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