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