@ring-protocol/router-sdk 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/router-sdk.cjs.development.js +28 -16
- package/dist/router-sdk.cjs.development.js.map +1 -1
- package/dist/router-sdk.cjs.production.min.js +1 -1
- package/dist/router-sdk.cjs.production.min.js.map +1 -1
- package/dist/router-sdk.esm.js +29 -17
- package/dist/router-sdk.esm.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"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=require("@ring-protocol/sdk-core"),o=t(require("jsbi")),r=require("@ethersproject/abi"),u=t(require("tiny-invariant")),i=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json")),a=require("@ring-protocol/v3-sdk"),p=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json")),s=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json")),c=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json")),d=require("@ring-protocol/v2-sdk"),m=require("@ring-protocol/v4-sdk"),l=require("@ring-protocol/few-v2-sdk"),f=require("@ethersproject/solidity"),h="0x0000000000000000000000000000000000000000",A="0x0000000000000000000000000000000000000001",v="0x0000000000000000000000000000000000000002",T=o.BigInt(0),w=o.BigInt(1),y=new n.Percent(T),k=new n.Percent(100,100);function E(t){return Object.keys(t).some((function(t){return"recipient"===t}))}(e=exports.ApprovalTypes||(exports.ApprovalTypes={}))[e.NOT_REQUIRED=0]="NOT_REQUIRED",e[e.MAX=1]="MAX",e[e.MAX_MINUS_ONE=2]="MAX_MINUS_ONE",e[e.ZERO_THEN_MAX=3]="ZERO_THEN_MAX",e[e.ZERO_THEN_MAX_MINUS_ONE=4]="ZERO_THEN_MAX_MINUS_ONE";var I=function(){function t(){}return t.encodeApproveMax=function(e){return t.INTERFACE.encodeFunctionData("approveMax",[e.address])},t.encodeApproveMaxMinusOne=function(e){return t.INTERFACE.encodeFunctionData("approveMaxMinusOne",[e.address])},t.encodeApproveZeroThenMax=function(e){return t.INTERFACE.encodeFunctionData("approveZeroThenMax",[e.address])},t.encodeApproveZeroThenMaxMinusOne=function(e){return t.INTERFACE.encodeFunctionData("approveZeroThenMaxMinusOne",[e.address])},t.encodeCallPositionManager=function(e){if(e.length>0||u(!1),1===e.length)return t.INTERFACE.encodeFunctionData("callPositionManager",e);var n=a.NonfungiblePositionManager.INTERFACE.encodeFunctionData("multicall",[e]);return t.INTERFACE.encodeFunctionData("callPositionManager",[n])},t.encodeAddLiquidity=function(e,n,r,u){var i=e.mintAmountsWithSlippage(u),p=i.amount0,s=i.amount1;return o.lessThan(n.amount0.quotient,p)&&(p=n.amount0.quotient),o.lessThan(n.amount1.quotient,s)&&(s=n.amount1.quotient),E(r)?t.INTERFACE.encodeFunctionData("mint",[{token0:e.pool.token0.address,token1:e.pool.token1.address,fee:e.pool.fee,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0Min:a.toHex(p),amount1Min:a.toHex(s),recipient:r.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:a.toHex(p),amount1Min:a.toHex(s),tokenId:a.toHex(r.tokenId)}])},t.encodeApprove=function(e,n){switch(n){case exports.ApprovalTypes.MAX:return t.encodeApproveMax(e.wrapped);case exports.ApprovalTypes.MAX_MINUS_ONE:return t.encodeApproveMaxMinusOne(e.wrapped);case exports.ApprovalTypes.ZERO_THEN_MAX:return t.encodeApproveZeroThenMax(e.wrapped);case exports.ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE:return t.encodeApproveZeroThenMaxMinusOne(e.wrapped);default:throw new Error("Error: invalid ApprovalType")}},t}();I.INTERFACE=new r.Interface(i.abi);var P=function(){function t(){}return t.encodeMulticall=function(e,n){if(void 0===n)return a.Multicall.encodeMulticall(e);if(Array.isArray(e)||(e=[e]),"string"==typeof n&&n.startsWith("0x")){var o=function(t){if(!t.match(/^0x[0-9a-fA-F]{64}$/))throw new Error(t+" is not valid bytes32.");return t.toLowerCase()}(n);return t.INTERFACE.encodeFunctionData("multicall(bytes32,bytes[])",[o,e])}var r=a.toHex(n);return t.INTERFACE.encodeFunctionData("multicall(uint256,bytes[])",[r,e])},t}();function x(t){return a.toHex(t.multiply(1e4).quotient)}P.INTERFACE=new r.Interface(p.abi);var R=function(){function t(){}return t.encodeUnwrapWETH9=function(e,o,r){if("string"==typeof o)return a.Payments.encodeUnwrapWETH9(e,o,r);if(r){var u=x(r.fee),i=n.validateAndParseAddress(r.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee(uint256,uint256,address)",[a.toHex(e),u,i])}return t.INTERFACE.encodeFunctionData("unwrapWETH9(uint256)",[a.toHex(e)])},t.encodeSweepToken=function(e,o,r,u){if("string"==typeof r)return a.Payments.encodeSweepToken(e,o,r,u);if(u){var i=x(u.fee),p=n.validateAndParseAddress(u.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,a.toHex(o),i,p])}return t.INTERFACE.encodeFunctionData("sweepToken(address,uint256)",[e.address,a.toHex(o)])},t.encodePull=function(e,n){return t.INTERFACE.encodeFunctionData("pull",[e.address,a.toHex(n)])},t.encodeWrapETH=function(e){return t.INTERFACE.encodeFunctionData("wrapETH",[a.toHex(e)])},t}();function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function _(t,e,n,o,r,u,i){try{var a=t[u](i),p=a.value}catch(t){return void n(t)}a.done?e(p):Promise.resolve(p).then(o,r)}function b(t){return function(){var e=this,n=arguments;return new Promise((function(o,r){var u=t.apply(e,n);function i(t){_(u,o,r,i,a,"next",t)}function a(t){_(u,o,r,i,a,"throw",t)}i(void 0)}))}}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,H(o.key),o)}}function N(t,e,n){return e&&O(t.prototype,e),n&&O(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function q(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 g(t,e);var n={}.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)?g(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function F(){return(F=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)({}).hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(null,arguments)}function C(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,function(t,e){(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}(t,e)}function M(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function u(n,o,r,u){var p=Object.create((o&&o.prototype instanceof a?o:a).prototype);return S(p,"_invoke",function(n,o,r){var u,a,p,s=0,c=r||[],d=!1,m={p:0,n:0,v:t,a:l,f:l.bind(t,4),d:function(e,n){return u=e,a=0,p=t,m.n=n,i}};function l(n,o){for(a=n,p=o,e=0;!d&&s&&!r&&e<c.length;e++){var r,u=c[e],l=m.p,f=u[2];n>3?(r=f===o)&&(p=u[(a=u[4])?5:(a=3,3)],u[4]=u[5]=t):u[0]<=l&&((r=n<2&&l<u[1])?(a=0,m.v=o,m.n=u[1]):l<f&&(r=n<3||u[0]>o||o>f)&&(u[4]=n,u[5]=o,m.n=f,a=0))}if(r||n>1)return i;throw d=!0,o}return function(r,c,f){if(s>1)throw TypeError("Generator is already running");for(d&&1===c&&l(c,f),a=c,p=f;(e=a<2?t:p)||!d;){u||(a?a<3?(a>1&&(m.n=-1),l(a,p)):m.n=p:m.v=p);try{if(s=2,u){if(a||(r="next"),e=u[r]){if(!(e=e.call(u,p)))throw TypeError("iterator result is not an object");if(!e.done)return e;p=e.value,a<2&&(a=0)}else 1===a&&(e=u.return)&&e.call(u),a<2&&(p=TypeError("The iterator does not provide a '"+r+"' method"),a=1);u=t}else if((e=(d=m.n<0)?p:n.call(o,m))!==i)break}catch(e){u=t,a=1,p=e}finally{s=1}}return{value:e,done:d}}}(n,r,u),!0),p}var i={};function a(){}function p(){}function s(){}e=Object.getPrototypeOf;var c=[][o]?e(e([][o]())):(S(e={},o,(function(){return this})),e),d=s.prototype=a.prototype=Object.create(c);function m(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,s):(t.__proto__=s,S(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return p.prototype=s,S(d,"constructor",s),S(s,"constructor",p),p.displayName="GeneratorFunction",S(s,r,"GeneratorFunction"),S(d),S(d,r,"Generator"),S(d,o,(function(){return this})),S(d,"toString",(function(){return"[object Generator]"})),(M=function(){return{w:u,m:m}})()}function S(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}(S=function(t,e,n,o){function u(e,n){S(t,e,(function(t){return this._invoke(e,n,t)}))}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(u("next",0),u("throw",1),u("return",2))})(t,e,n,o)}function H(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function D(t,e){return n.CurrencyAmount.fromFractionalAmount(U(t.currency,e),t.numerator,t.denominator)}function U(t,e){if(e.involvesToken(t))return t;if(e.involvesToken(t.wrapped))return t.wrapped;if(!(e instanceof m.Pool))throw new Error("Expected currency "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol);return e.token0.wrapped.equals(t)?e.token0:e.token1.wrapped.equals(t)?e.token1:t}R.INTERFACE=new r.Interface(s.abi);var V=function(){return N((function(t,e,n,o){void 0===o&&(o=!1),this._midPrice=null,(t=o?t:t.filter((function(t){return!(t instanceof m.Pool&&0===t.tickSpacing)}))).length>0||u(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||u(!1),this.pathInput=U(e,t[0]),this.pathOutput=U(n,t[t.length-1]),t[0]instanceof m.Pool?t[0].v4InvolvesToken(this.pathInput)||u(!1):t[0].involvesToken(this.pathInput)||u(!1);var i=t[t.length-1];i instanceof m.Pool?i.v4InvolvesToken(n)||i.v4InvolvesToken(n.wrapped)||u(!1):i.involvesToken(n.wrapped)||u(!1);var a=[this.pathInput];t[0].token0.equals(this.pathInput)?a.push(t[0].token1):a.push(t[0].token0);for(var p=1;p<t.length;p++){var s=t[p],c=a[p],d=void 0;if(s instanceof m.Pool&&!s.involvesToken(c)||!(s instanceof m.Pool)&&c.isNative)if(c.equals(s.token0.wrapped))d=s.token1;else{if(!c.wrapped.equals(s.token0)&&!c.wrapped.equals(s.token1))throw new Error("POOL_MISMATCH pool: "+JSON.stringify(s)+" inputToken: "+JSON.stringify(c));d=c.wrapped.equals(s.token0)?s.token1:s.token0}else c.equals(s.token0)||c.equals(s.token1)||u(!1),d=c.equals(s.token0)?s.token1:s.token0;a.push(d)}this.pools=t,this.path=a,this.input=e,this.output=null!=n?n:a[a.length-1]}),[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,e){var n=t.price;return t.nextInput.equals(e.token0)?{nextInput:e.token1,price:n.multiply(e.token0Price.asFraction)}:{nextInput:e.token0,price:n.multiply(e.token1Price.asFraction)}}),this.pools[0].token0.equals(this.pathInput)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price.asFraction}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price.asFraction}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}])}();function X(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||u(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||u(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?t.swaps.reduce((function(t,e){return t+e.route.path.length}),0)-e.swaps.reduce((function(t,e){return t+e.route.path.length}),0):t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}var j,W=function(){function t(t){var e=t.routes,o=t.tradeType,r=e[0].inputAmount.currency,i=e[0].outputAmount.currency;e.every((function(t){return r.wrapped.equals(t.route.input.wrapped)}))||u(!1),e.every((function(t){return i.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var p,s=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,l=q(e);!(p=l()).done;)for(var f,h=q(p.value.route.pools);!(f=h()).done;){var A=f.value;if(A instanceof m.Pool)c.add(A.poolId);else if(A instanceof a.Pool)c.add(a.Pool.getAddress(A.token0,A.token1,A.fee));else{if(!(A instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");c.add(d.Pair.getAddress(A.token0,A.token1))}}s!==c.size&&u(!1),o!==n.TradeType.EXACT_INPUT&&u(!1),this.swaps=e,this.tradeType=o}t.fromRoute=function(){var e=b(M().m((function e(o,r,i){var a,p,s,c,d;return M().w((function(e){for(;;)switch(e.n){case 0:a=new Array(o.path.length),i!==n.TradeType.EXACT_INPUT&&u(!1),r.currency.equals(o.input)||u(!1),a[0]=D(r,o.pools[0]),c=0;case 1:if(!(c<o.path.length-1)){e.n=4;break}return d=o.pools[c],e.n=2,d.getOutputAmount(D(a[c],d));case 2:a[c+1]=e.v[0];case 3:c++,e.n=1;break;case 4:return p=n.CurrencyAmount.fromFractionalAmount(o.input,r.numerator,r.denominator),s=n.CurrencyAmount.fromFractionalAmount(o.output,a[a.length-1].numerator,a[a.length-1].denominator),e.a(2,new t({routes:[{inputAmount:p,outputAmount:s,route:o}],tradeType:i}))}}),e)})));return function(t,n,o){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=b(M().m((function e(o,r){var i,a,p,s,c,d,m,l,f,h,A;return M().w((function(e){for(;;)switch(e.n){case 0:i=[],r!==n.TradeType.EXACT_INPUT&&u(!1),a=q(o);case 1:if((p=a()).done){e.n=7;break}c=(s=p.value).route,d=s.amount,m=new Array(c.path.length),l=void 0,f=void 0,d.currency.equals(c.input)||u(!1),l=n.CurrencyAmount.fromFractionalAmount(c.input,d.numerator,d.denominator),m[0]=n.CurrencyAmount.fromFractionalAmount(c.pathInput,d.numerator,d.denominator),h=0;case 2:if(!(h<c.path.length-1)){e.n=5;break}return A=c.pools[h],e.n=3,A.getOutputAmount(D(m[h],A));case 3:m[h+1]=e.v[0];case 4:h++,e.n=2;break;case 5:f=n.CurrencyAmount.fromFractionalAmount(c.output,m[m.length-1].numerator,m[m.length-1].denominator),i.push({route:c,inputAmount:l,outputAmount:f});case 6:e.n=1;break;case 7:return e.a(2,new t({routes:i,tradeType:r}))}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(F({},e,{routes:[{inputAmount:e.inputAmount,outputAmount:e.outputAmount,route:e.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(e){return new t(e)};var e=t.prototype;return e.minimumAmountOut=function(t,e){void 0===e&&(e=this.outputAmount),t.lessThan(T)&&u(!1);var o=new n.Fraction(w).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},e.maximumAmountIn=function(t,e){return void 0===e&&(e=this.inputAmount),t.lessThan(T)&&u(!1),e},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=b(M().m((function e(o,r,i,a,p,s,c){var l,f,h,A,v,w,y,k,E,I,P,x,R,g,_;return M().w((function(e){for(;;)switch(e.p=e.n){case 0:h=void 0===(f=(l=void 0===a?{}:a).maxNumResults)?3:f,v=void 0===(A=l.maxHops)?3:A,void 0===p&&(p=[]),void 0===s&&(s=r),void 0===c&&(c=[]),o.length>0||u(!1),v>0||u(!1),r===s||p.length>0||u(!1),w=s,y=0;case 1:if(!(y<o.length)){e.n=15;break}if((k=o[y]).token0.equals((E=k instanceof m.Pool?w:w.wrapped).currency)||k.token1.equals(E.currency)){e.n=2;break}return e.a(3,14);case 2:if(!(k instanceof d.Pair)){e.n=3;break}if(!k.reserve0.equalTo(T)&&!k.reserve1.equalTo(T)){e.n=3;break}return e.a(3,14);case 3:if(I=void 0,e.p=4,!(k instanceof m.Pool)){e.n=6;break}return e.n=5,k.getOutputAmount(E);case 5:x=e.v,e.n=8;break;case 6:return e.n=7,k.getOutputAmount(E.wrapped);case 7:x=e.v;case 8:I=x[0],e.n=11;break;case 9:if(e.p=9,!(R=e.v).isInsufficientInputAmountError){e.n=10;break}return e.a(3,14);case 10:throw R;case 11:if(!I.currency.wrapped.equals(i.wrapped)){e.n=13;break}return g=n.sortedInsert,_=c,e.n=12,t.fromRoute(new V([].concat(p,[k]),r.currency,i),r,n.TradeType.EXACT_INPUT);case 12:g(_,e.v,h,X),e.n=14;break;case 13:if(!(v>1&&o.length>1)){e.n=14;break}return P=o.slice(0,y).concat(o.slice(y+1,o.length)),e.n=14,t.bestTradeExactIn(P,r,i,{maxNumResults:h,maxHops:v-1},[].concat(p,[k]),I,c);case 14:y++,e.n=1;break;case 15:return e.a(2,c)}}),e,null,[[4,9]])})));return function(t,n,o,r,u,i,a){return e.apply(this,arguments)}}(),N(t,[{key:"route",get:function(){return 1!==this.swaps.length&&u(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),o=q(this.swaps);!(t=o()).done;){var r=t.value;e=e.add(r.route.midPrice.quote(r.inputAmount))}var u=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new n.Percent(u.numerator,u.denominator),this._priceImpact}}])}();function L(t,e){var n=l.getFewTokenFromOriginalToken(t.wrapped,t.chainId);if(e instanceof l.Pair||e instanceof d.Pair){if(e.token0.wrapped.equals(n))return e.token0;if(e.token1.wrapped.equals(n))return e.token1;if(e.token0.wrapped.equals(t.wrapped))return e.token0;if(e.token1.wrapped.equals(t.wrapped))return e.token1;throw new Error("Expected fewToken "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol)}if(e.token0.wrapped.equals(t.wrapped))return e.token0;if(e.token1.wrapped.equals(t.wrapped))return e.token1;if(e.token0.wrapped.equals(n))return e.token0;if(e.token1.wrapped.equals(n))return e.token1;throw new Error("Expected token "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol)}(j=exports.Protocol||(exports.Protocol={})).V2="V2",j.V3="V3",j.V4="V4",j.FEWV2="FEWV2",j.MIXED="MIXED";var Z=function(t){function e(e){var n;return(n=t.call(this,e.pairs,e.input,e.output)||this).protocol=exports.Protocol.V2,n.pools=n.pairs,n.pathInput=L(e.input,n.pairs[0]),n.pathOutput=L(e.output,n.pairs[n.pairs.length-1]),n}return C(e,t),e}(d.Route),B=function(t){function e(e){var n;return(n=t.call(this,e.pairs,e.input,e.output)||this).protocol=exports.Protocol.FEWV2,n.pools=n.pairs,n.pathInput=L(e.input,n.pairs[0]),n.pathOutput=L(e.output,n.pairs[n.pairs.length-1]),n}return C(e,t),e}(l.Route),G=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.V3,n.path=e.tokenPath,n.pathInput=L(e.input,n.pools[0]),n.pathOutput=L(e.output,n.pools[n.pools.length-1]),n}return C(e,t),e}(a.Route),Q=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.V4,n.path=e.currencyPath,n}return C(e,t),e}(m.Route),J=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.MIXED,n}return C(e,t),e}(V),z=function(){function t(t){var e=t.fewV2Routes,n=void 0===e?[]:e,o=t.v2Routes,r=void 0===o?[]:o,i=t.v3Routes,p=void 0===i?[]:i,s=t.v4Routes,c=void 0===s?[]:s,f=t.mixedRoutes,h=void 0===f?[]:f,A=t.tradeType;this.swaps=[],this.routes=[];for(var v,T=q(n);!(v=T()).done;){var w=v.value,y=w.inputAmount,k=w.outputAmount,E=new B(w.fewRouteV2);this.routes.push(E),this.swaps.push({route:E,inputAmount:y,outputAmount:k})}for(var I,P=q(r);!(I=P()).done;){var x=I.value,R=x.inputAmount,g=x.outputAmount,_=new Z(x.routev2);this.routes.push(_),this.swaps.push({route:_,inputAmount:R,outputAmount:g})}for(var b,O=q(p);!(b=O()).done;){var N=b.value,F=N.inputAmount,C=N.outputAmount,M=new G(N.routev3);this.routes.push(M),this.swaps.push({route:M,inputAmount:F,outputAmount:C})}for(var S,H=q(c);!(S=H()).done;){var D=S.value,U=D.inputAmount,V=D.outputAmount,X=new Q(D.routev4);this.routes.push(X),this.swaps.push({route:X,inputAmount:U,outputAmount:V})}for(var j,W=q(h);!(j=W()).done;){var L=j.value,z=L.inputAmount,$=L.outputAmount,K=new J(L.mixedRoute);this.routes.push(K),this.swaps.push({route:K,inputAmount:z,outputAmount:$})}if(0===this.swaps.length)throw new Error("No routes provided when calling Trade constructor");this.tradeType=A;for(var Y,tt=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),et=new Set,nt=q(this.swaps);!(Y=nt()).done;)for(var ot,rt=q(Y.value.route.pools);!(ot=rt()).done;){var ut=ot.value;if(ut instanceof m.Pool)et.add(ut.poolId);else if(ut instanceof a.Pool)et.add(a.Pool.getAddress(ut.token0,ut.token1,ut.fee));else if(ut instanceof d.Pair)et.add(d.Pair.getAddress(ut.token0,ut.token1));else{if(!(ut instanceof l.Pair))throw new Error("Unexpected pool type in route when constructing trade object");et.add(l.Pair.getAddress(ut.token0,ut.token1))}}tt!==et.size&&u(!1)}var e=t.prototype;return e.isWrappedNative=function(t){return t.equals(n.Ether.onChain(t.chainId).wrapped)},e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(T)&&u(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var o=new n.Fraction(w).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(T)&&u(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var o=new n.Fraction(w).add(t).multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.fromRoutes=function(){var e=b(M().m((function e(n,o,r,u,i,p){var s,c,f,h,A,v,T,w,y,k,E,I,P,x,R,g,_,b,O,N,F,C,S,H,D,U,V,X,j,L,Z,B,G;return M().w((function(e){for(;;)switch(e.n){case 0:for(s=[],c=[],f=[],h=[],A=[],v=q(n);!(T=v()).done;)k=new l.Trade(y=(w=T.value).fewRouteV2,w.amount,u),s.push({fewRouteV2:y,inputAmount:k.inputAmount,outputAmount:k.outputAmount});for(E=q(o);!(I=E()).done;)R=new d.Trade(x=(P=I.value).routev2,P.amount,u),c.push({routev2:x,inputAmount:R.inputAmount,outputAmount:R.outputAmount});g=q(r);case 1:if((_=g()).done){e.n=4;break}return O=(b=_.value).routev3,N=b.amount,e.n=2,a.Trade.fromRoute(O,N,u);case 2:f.push({routev3:O,inputAmount:(F=e.v).inputAmount,outputAmount:F.outputAmount});case 3:e.n=1;break;case 4:if(!p){e.n=8;break}C=q(p);case 5:if((S=C()).done){e.n=8;break}return D=(H=S.value).routev4,U=H.amount,e.n=6,m.Trade.fromRoute(D,U,u);case 6:h.push({routev4:D,inputAmount:(V=e.v).inputAmount,outputAmount:V.outputAmount});case 7:e.n=5;break;case 8:if(!i){e.n=12;break}X=q(i);case 9:if((j=X()).done){e.n=12;break}return Z=(L=j.value).mixedRoute,B=L.amount,e.n=10,W.fromRoute(Z,B,u);case 10:A.push({mixedRoute:Z,inputAmount:(G=e.v).inputAmount,outputAmount:G.outputAmount});case 11:e.n=9;break;case 12:return e.a(2,new t({fewV2Routes:s,v2Routes:c,v3Routes:f,v4Routes:h,mixedRoutes:A,tradeType:u}))}}),e)})));return function(t,n,o,r,u,i){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=b(M().m((function e(n,o,r){var u,i,p,s,c,f,h,A,v,T;return M().w((function(e){for(;;)switch(e.n){case 0:if(u=[],i=[],p=[],s=[],c=[],!(n instanceof l.Route)){e.n=1;break}f=new l.Trade(n,o,r),u=[{fewRouteV2:n,inputAmount:f.inputAmount,outputAmount:f.outputAmount}],e.n=9;break;case 1:if(!(n instanceof d.Route)){e.n=2;break}h=new d.Trade(n,o,r),i=[{routev2:n,inputAmount:h.inputAmount,outputAmount:h.outputAmount}],e.n=9;break;case 2:if(!(n instanceof a.Route)){e.n=4;break}return e.n=3,a.Trade.fromRoute(n,o,r);case 3:p=[{routev3:n,inputAmount:(A=e.v).inputAmount,outputAmount:A.outputAmount}],e.n=9;break;case 4:if(!(n instanceof m.Route)){e.n=6;break}return e.n=5,m.Trade.fromRoute(n,o,r);case 5:s=[{routev4:n,inputAmount:(v=e.v).inputAmount,outputAmount:v.outputAmount}],e.n=9;break;case 6:if(!(n instanceof V)){e.n=8;break}return e.n=7,W.fromRoute(n,o,r);case 7:c=[{mixedRoute:n,inputAmount:(T=e.v).inputAmount,outputAmount:T.outputAmount}],e.n=9;break;case 8:throw new Error("Invalid route type");case 9:return e.a(2,new t({fewV2Routes:u,v2Routes:i,v3Routes:p,v4Routes:s,mixedRoutes:c,tradeType:r}))}}),e)})));return function(t,n,o){return e.apply(this,arguments)}}(),N(t,[{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"amounts",get:function(){var t,e,o=null==(t=this.swaps.find((function(t){return t.inputAmount.currency.isNative})))?void 0:t.inputAmount.currency,r=null==(e=this.swaps.find((function(t){return t.outputAmount.currency.isNative})))?void 0:e.outputAmount.currency;return{inputAmount:this.inputAmount,inputAmountNative:o?this.swaps.reduce((function(t,e){return e.route.pathInput.isNative?t.add(e.inputAmount):t}),n.CurrencyAmount.fromRawAmount(o,0)):void 0,outputAmount:this.outputAmount,outputAmountNative:r?this.swaps.reduce((function(t,e){return e.route.pathOutput.isNative?t.add(e.outputAmount):t}),n.CurrencyAmount.fromRawAmount(r,0)):void 0}}},{key:"numberOfInputWraps",get:function(){return this.inputAmount.currency.isNative?this.wethInputRoutes.length:0}},{key:"numberOfInputUnwraps",get:function(){return this.isWrappedNative(this.inputAmount.currency)?this.nativeInputRoutes.length:0}},{key:"nativeInputRoutes",get:function(){return this._nativeInputRoutes||(this._nativeInputRoutes=this.routes.filter((function(t){return t.pathInput.isNative}))),this._nativeInputRoutes}},{key:"wethInputRoutes",get:function(){var t=this;return this._wethInputRoutes||(this._wethInputRoutes=this.routes.filter((function(e){return t.isWrappedNative(e.pathInput)}))),this._wethInputRoutes}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"inputTax",get:function(){var t=this.inputAmount.currency;return t.isNative||!t.wrapped.sellFeeBps?y:new n.Percent(t.wrapped.sellFeeBps.toNumber(),1e4)}},{key:"outputTax",get:function(){var t=this.outputAmount.currency;return t.isNative||!t.wrapped.buyFeeBps?y:new n.Percent(t.wrapped.buyFeeBps.toNumber(),1e4)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;if(this.outputTax.equalTo(k))return y;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),o=q(this.swaps);!(t=o()).done;){var r=t.value,u=r.route.midPrice,i=r.inputAmount.multiply(new n.Fraction(w).subtract(this.inputTax));e=e.add(u.quote(i))}if(e.equalTo(T))return y;var a=this.outputAmount.divide(new n.Fraction(w).subtract(this.outputTax)),p=e.subtract(a).divide(e);return this._priceImpact=new n.Percent(p.numerator,p.denominator),this._priceImpact}}])}();function $(t,e){var n,o;if(null!=e?e:t.pools.some((function(t){return t instanceof m.Pool}))){n=[t.pathInput.isNative?h:t.pathInput.address],o=["address"];for(var r,u=t.pathInput,i=q(t.pools);!(r=i()).done;){var p=r.value,s=u.equals(p.token0)?p.token1:p.token0;if(p instanceof m.Pool)0===p.tickSpacing?(n.push(0,s.isNative?h:s.wrapped.address),o.push("uint8","address")):(n.push(p.fee+(4<<20),p.tickSpacing,p.hooks,s.isNative?h:s.wrapped.address),o.push("uint24","uint24","address","address"));else if(p instanceof a.Pool)n.push(p.fee+(3<<20),s.wrapped.address),o.push("uint24","address");else{if(!(p instanceof d.Pair))throw new Error("Unsupported pool type "+JSON.stringify(p));n.push(32,s.wrapped.address),o.push("uint8","address")}u=s}}else{var c=t.pools.reduce((function(t,e,n){var o=t.inputToken,r=t.path,u=t.types,i=e.token0.equals(o)?e.token1:e.token0;return 0===n?{inputToken:i,types:["address","uint24","address"],path:[o.wrapped.address,e instanceof a.Pool?e.fee:1<<23,i.wrapped.address]}:{inputToken:i,types:[].concat(u,["uint24","address"]),path:[].concat(r,[e instanceof a.Pool?e.fee:1<<23,i.wrapped.address])}}),{inputToken:t.input,path:[],types:[]});n=c.path,o=c.types}return f.pack(o,n)}var K=function(t){for(var e=[],n=0,o=0;o<t.pools.length;)(t.pools[n]instanceof m.Pool&&!(t.pools[o]instanceof m.Pool)||t.pools[n]instanceof a.Pool&&!(t.pools[o]instanceof a.Pool)||t.pools[n]instanceof d.Pair&&!(t.pools[o]instanceof d.Pair))&&(e.push(t.pools.slice(n,o)),n=o),++o===t.pools.length&&e.push(t.pools.slice(n,o));return e},Y=function(t,e){return t.reduce((function(t,e){var n=t.inputToken;if(!e.involvesToken(n))throw new Error("PATH");return{inputToken:e.token0.equals(n)?e.token1:e.token0}}),{inputToken:e}).inputToken},tt=o.BigInt(0),et=new n.Percent(o.BigInt(50),o.BigInt(100)),nt=function(){function t(){}return t.encodeV2Swap=function(e,o,r,u){var i=a.toHex(e.maximumAmountIn(o.slippageTolerance).quotient),p=a.toHex(e.minimumAmountOut(o.slippageTolerance).quotient),s=e.route.path.map((function(t){return t.address})),c=r?v:void 0===o.recipient?A:n.validateAndParseAddress(o.recipient);return e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[i,u?0:p,s,c]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[p,i,s,c])},t.encodeV3Swap=function(e,o,r,u){for(var i,p=[],s=q(e.swaps);!(i=s()).done;){var c=i.value,d=c.route,m=c.outputAmount,l=a.toHex(e.maximumAmountIn(o.slippageTolerance,c.inputAmount).quotient),f=a.toHex(e.minimumAmountOut(o.slippageTolerance,m).quotient),h=1===d.pools.length,T=r?v:void 0===o.recipient?A:n.validateAndParseAddress(o.recipient);if(h)p.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:T,amountIn:l,amountOutMinimum:u?0:f,sqrtPriceLimitX96:0}]):t.INTERFACE.encodeFunctionData("exactOutputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:T,amountOut:f,amountInMaximum:l,sqrtPriceLimitX96:0}]));else{var w=a.encodeRouteToPath(d,e.tradeType===n.TradeType.EXACT_OUTPUT);p.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:w,recipient:T,amountIn:l,amountOutMinimum:u?0:f}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:w,recipient:T,amountOut:f,amountInMaximum:l}]))}}return p},t.encodeMixedRouteSwap=function(e,o,r,i){var p=[];e.tradeType!==n.TradeType.EXACT_INPUT&&u(!1);for(var s,c=function(){var u=s.value,c=u.route,d=u.inputAmount,l=u.outputAmount;if(c.pools.some((function(t){return t instanceof m.Pool})))throw new Error("Encoding mixed routes with V4 not supported");var f=a.toHex(e.maximumAmountIn(o.slippageTolerance,d).quotient),h=a.toHex(e.minimumAmountOut(o.slippageTolerance,l).quotient),T=1===c.pools.length,w=r?v:void 0===o.recipient?A:n.validateAndParseAddress(o.recipient),y=function(t){return t.pools.every((function(t){return t instanceof a.Pool}))};if(T)if(y(c))p.push(t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:c.path[0].wrapped.address,tokenOut:c.path[1].wrapped.address,fee:c.pools[0].fee,recipient:w,amountIn:f,amountOutMinimum:i?0:h,sqrtPriceLimitX96:0}]));else{var k=c.path.map((function(t){return t.wrapped.address}));p.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[f,i?0:h,k,w]))}else for(var E,I=K(c),P=function(t){return t===I.length-1},x=c.input.wrapped,R=0;R<I.length;R++){var g=I[R];E=Y(g,x);var _=new V([].concat(g),g[0].token0.equals(x)?g[0].token0:g[0].token1,E),b=new J(_);if(x=E.wrapped,y(b)){var O={path:$(b),recipient:P(R)?w:v,amountIn:0===R?f:0,amountOutMinimum:P(R)?h:0};p.push(t.INTERFACE.encodeFunctionData("exactInput",[O]))}else{var N=[0===R?f:0,P(R)?h:0,b.path.map((function(t){return t.wrapped.address})),P(R)?w:v];p.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",N))}}},d=q(e.swaps);!(s=d()).done;)c();return p},t.encodeSwaps=function(e,o,r){if(e instanceof z){e.swaps.every((function(t){return t.route.protocol===exports.Protocol.V3||t.route.protocol===exports.Protocol.V2||t.route.protocol===exports.Protocol.MIXED}))||u(!1);for(var i,p=[],s=q(e.swaps);!(i=s()).done;){var c=i.value,m=c.route,l=c.inputAmount,f=c.outputAmount;if(m.protocol===exports.Protocol.V2)p.push(new d.Trade(m,e.tradeType===n.TradeType.EXACT_INPUT?l:f,e.tradeType));else if(m.protocol===exports.Protocol.V3)p.push(a.Trade.createUncheckedTrade({route:m,inputAmount:l,outputAmount:f,tradeType:e.tradeType}));else{if(m.protocol!==exports.Protocol.MIXED)throw new Error("UNSUPPORTED_TRADE_PROTOCOL");p.push(W.createUncheckedTrade({route:m,inputAmount:l,outputAmount:f,tradeType:e.tradeType}))}}e=p}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof a.Trade||e instanceof W?e.swaps.length:1)}),0),A=e[0];e.every((function(t){return t.inputAmount.currency.equals(A.inputAmount.currency)}))||u(!1),e.every((function(t){return t.outputAmount.currency.equals(A.outputAmount.currency)}))||u(!1),e.every((function(t){return t.tradeType===A.tradeType}))||u(!1);var v=[],T=A.inputAmount.currency.isNative,w=A.outputAmount.currency.isNative,y=A.tradeType===n.TradeType.EXACT_INPUT&&h>2,k=w||!!o.fee||!!r||y;o.inputTokenPermit&&(A.inputAmount.currency.isToken||u(!1),v.push(a.SelfPermit.encodePermit(A.inputAmount.currency,o.inputTokenPermit)));for(var E,I=q(e);!(E=I()).done;){var P=E.value;if(P instanceof d.Trade)v.push(t.encodeV2Swap(P,o,k,y));else if(P instanceof a.Trade)for(var x,R=q(t.encodeV3Swap(P,o,k,y));!(x=R()).done;)v.push(x.value);else{if(!(P instanceof W))throw new Error("Unsupported trade object");for(var g,_=q(t.encodeMixedRouteSwap(P,o,k,y));!(g=_()).done;)v.push(g.value)}}var b=n.CurrencyAmount.fromRawAmount(A.inputAmount.currency,0),O=n.CurrencyAmount.fromRawAmount(A.outputAmount.currency,0),N=e.reduce((function(t,e){return t.add(e.minimumAmountOut(o.slippageTolerance))}),O),F=e.reduce((function(t,e){return t.add(e.outputAmount)}),O),C=e.reduce((function(t,e){return t.add(e.maximumAmountIn(o.slippageTolerance))}),b);return{calldatas:v,sampleTrade:A,routerMustCustody:k,inputIsNative:T,outputIsNative:w,totalAmountIn:C,minimumAmountOut:N,quoteAmountOut:F}},t.swapCallParameters=function(e,o){var r=t.encodeSwaps(e,o),u=r.calldatas,i=r.sampleTrade,p=r.inputIsNative,s=r.totalAmountIn,c=r.minimumAmountOut;return r.routerMustCustody&&u.push(r.outputIsNative?R.encodeUnwrapWETH9(c.quotient,o.recipient,o.fee):R.encodeSweepToken(i.outputAmount.currency.wrapped,c.quotient,o.recipient,o.fee)),p&&(i.tradeType===n.TradeType.EXACT_OUTPUT||t.riskOfPartialFill(e))&&u.push(a.Payments.encodeRefundETH()),{calldata:P.encodeMulticall(u,o.deadlineOrPreviousBlockhash),value:a.toHex(p?s.quotient:tt)}},t.swapAndAddCallParameters=function(e,o,r,i,p,s){var c=t.encodeSwaps(e,o,!0),d=c.calldatas,m=c.inputIsNative,l=c.outputIsNative,f=c.sampleTrade,h=c.totalAmountIn,A=c.quoteAmountOut,v=c.minimumAmountOut;o.outputTokenPermit&&(A.currency.isToken||u(!1),d.push(a.SelfPermit.encodePermit(A.currency,o.outputTokenPermit)));var T=f.route.chainId,w=r.pool.token0.wrapped.address===h.currency.wrapped.address,y=t.getPositionAmounts(r,w),k=y.positionAmountIn,E=y.positionAmountOut,x=m?n.WETH9[T]:k.currency.wrapped,g=l?n.WETH9[T]:E.currency.wrapped,_=E.subtract(A.wrapped);_.greaterThan(n.CurrencyAmount.fromRawAmount(E.currency,0))&&d.push(l?R.encodeWrapETH(_.quotient):R.encodePull(g,_.quotient)),d.push(m?R.encodeWrapETH(k.quotient):R.encodePull(x,k.quotient)),p!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(I.encodeApprove(x,p)),s!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(I.encodeApprove(g,s));var b,O=a.Position.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:w?r.amount0.quotient.toString():v.quotient.toString(),amount1:w?v.quotient.toString():r.amount1.quotient.toString(),useFullPrecision:!1});return d.push(I.encodeAddLiquidity(r,O,i,o.slippageTolerance)),d.push(m?R.encodeUnwrapWETH9(tt):R.encodeSweepToken(x,tt)),d.push(l?R.encodeUnwrapWETH9(tt):R.encodeSweepToken(g,tt)),b=m?h.wrapped.add(k.wrapped).quotient:l?_.quotient:tt,{calldata:P.encodeMulticall(d,o.deadlineOrPreviousBlockhash),value:b.toString()}},t.riskOfPartialFill=function(e){return Array.isArray(e)?e.some((function(e){return t.v3TradeWithHighPriceImpact(e)})):t.v3TradeWithHighPriceImpact(e)},t.v3TradeWithHighPriceImpact=function(t){return!(t instanceof d.Trade)&&t.priceImpact.greaterThan(et)},t.getPositionAmounts=function(t,e){var o=t.mintAmounts,r=o.amount1,u=n.CurrencyAmount.fromRawAmount(t.pool.token0,o.amount0),i=n.CurrencyAmount.fromRawAmount(t.pool.token1,r),a=e?[u,i]:[i,u];return{positionAmountIn:a[0],positionAmountOut:a[1]}},t}();nt.INTERFACE=new r.Interface(c.abi),exports.ADDRESS_THIS=v,exports.ADDRESS_ZERO=h,exports.ApproveAndCall=I,exports.FewRouteV2=B,exports.MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER=1<<23,exports.MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER=32,exports.MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER=3<<20,exports.MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER=4<<20,exports.MSG_SENDER=A,exports.MixedRoute=J,exports.MixedRouteSDK=V,exports.MixedRouteTrade=W,exports.MulticallExtended=P,exports.ONE=w,exports.ONE_HUNDRED_PERCENT=k,exports.PaymentsExtended=R,exports.RING_FEE_PATH_PLACEHOLDER=4194304,exports.RouteV2=Z,exports.RouteV3=G,exports.RouteV4=Q,exports.SwapRouter=nt,exports.Trade=z,exports.ZERO=T,exports.ZERO_PERCENT=y,exports.amountWithPathCurrency=D,exports.encodeMixedRouteToPath=$,exports.getOutputOfPools=Y,exports.getPathCurrency=U,exports.getPathToken=L,exports.isMint=E,exports.partitionMixedRouteByProtocol=K,exports.tradeComparator=X;
|
|
1
|
+
"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=require("@ring-protocol/sdk-core"),o=t(require("jsbi")),r=require("@ethersproject/abi"),u=t(require("tiny-invariant")),i=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json")),a=require("@ring-protocol/v3-sdk"),p=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json")),s=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json")),c=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json")),d=require("@ring-protocol/v2-sdk"),l=require("@ring-protocol/v4-sdk"),m=require("@ring-protocol/few-v2-sdk"),f=require("@ethersproject/solidity"),h="0x0000000000000000000000000000000000000000",A="0x0000000000000000000000000000000000000001",v="0x0000000000000000000000000000000000000002",w=o.BigInt(0),y=o.BigInt(1),T=new n.Percent(w),k=new n.Percent(100,100);function E(t){return Object.keys(t).some((function(t){return"recipient"===t}))}(e=exports.ApprovalTypes||(exports.ApprovalTypes={}))[e.NOT_REQUIRED=0]="NOT_REQUIRED",e[e.MAX=1]="MAX",e[e.MAX_MINUS_ONE=2]="MAX_MINUS_ONE",e[e.ZERO_THEN_MAX=3]="ZERO_THEN_MAX",e[e.ZERO_THEN_MAX_MINUS_ONE=4]="ZERO_THEN_MAX_MINUS_ONE";var I=function(){function t(){}return t.encodeApproveMax=function(e){return t.INTERFACE.encodeFunctionData("approveMax",[e.address])},t.encodeApproveMaxMinusOne=function(e){return t.INTERFACE.encodeFunctionData("approveMaxMinusOne",[e.address])},t.encodeApproveZeroThenMax=function(e){return t.INTERFACE.encodeFunctionData("approveZeroThenMax",[e.address])},t.encodeApproveZeroThenMaxMinusOne=function(e){return t.INTERFACE.encodeFunctionData("approveZeroThenMaxMinusOne",[e.address])},t.encodeCallPositionManager=function(e){if(e.length>0||u(!1),1===e.length)return t.INTERFACE.encodeFunctionData("callPositionManager",e);var n=a.NonfungiblePositionManager.INTERFACE.encodeFunctionData("multicall",[e]);return t.INTERFACE.encodeFunctionData("callPositionManager",[n])},t.encodeAddLiquidity=function(e,n,r,u){var i=e.mintAmountsWithSlippage(u),p=i.amount0,s=i.amount1;return o.lessThan(n.amount0.quotient,p)&&(p=n.amount0.quotient),o.lessThan(n.amount1.quotient,s)&&(s=n.amount1.quotient),E(r)?t.INTERFACE.encodeFunctionData("mint",[{token0:e.pool.token0.address,token1:e.pool.token1.address,fee:e.pool.fee,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0Min:a.toHex(p),amount1Min:a.toHex(s),recipient:r.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:a.toHex(p),amount1Min:a.toHex(s),tokenId:a.toHex(r.tokenId)}])},t.encodeApprove=function(e,n){switch(n){case exports.ApprovalTypes.MAX:return t.encodeApproveMax(e.wrapped);case exports.ApprovalTypes.MAX_MINUS_ONE:return t.encodeApproveMaxMinusOne(e.wrapped);case exports.ApprovalTypes.ZERO_THEN_MAX:return t.encodeApproveZeroThenMax(e.wrapped);case exports.ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE:return t.encodeApproveZeroThenMaxMinusOne(e.wrapped);default:throw new Error("Error: invalid ApprovalType")}},t}();I.INTERFACE=new r.Interface(i.abi);var P=function(){function t(){}return t.encodeMulticall=function(e,n){if(void 0===n)return a.Multicall.encodeMulticall(e);if(Array.isArray(e)||(e=[e]),"string"==typeof n&&n.startsWith("0x")){var o=function(t){if(!t.match(/^0x[0-9a-fA-F]{64}$/))throw new Error(t+" is not valid bytes32.");return t.toLowerCase()}(n);return t.INTERFACE.encodeFunctionData("multicall(bytes32,bytes[])",[o,e])}var r=a.toHex(n);return t.INTERFACE.encodeFunctionData("multicall(uint256,bytes[])",[r,e])},t}();function x(t){return a.toHex(t.multiply(1e4).quotient)}P.INTERFACE=new r.Interface(p.abi);var R=function(){function t(){}return t.encodeUnwrapWETH9=function(e,o,r){if("string"==typeof o)return a.Payments.encodeUnwrapWETH9(e,o,r);if(r){var u=x(r.fee),i=n.validateAndParseAddress(r.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee(uint256,uint256,address)",[a.toHex(e),u,i])}return t.INTERFACE.encodeFunctionData("unwrapWETH9(uint256)",[a.toHex(e)])},t.encodeSweepToken=function(e,o,r,u){if("string"==typeof r)return a.Payments.encodeSweepToken(e,o,r,u);if(u){var i=x(u.fee),p=n.validateAndParseAddress(u.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,a.toHex(o),i,p])}return t.INTERFACE.encodeFunctionData("sweepToken(address,uint256)",[e.address,a.toHex(o)])},t.encodePull=function(e,n){return t.INTERFACE.encodeFunctionData("pull",[e.address,a.toHex(n)])},t.encodeWrapETH=function(e){return t.INTERFACE.encodeFunctionData("wrapETH",[a.toHex(e)])},t}();function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function _(t,e,n,o,r,u,i){try{var a=t[u](i),p=a.value}catch(t){return void n(t)}a.done?e(p):Promise.resolve(p).then(o,r)}function b(t){return function(){var e=this,n=arguments;return new Promise((function(o,r){var u=t.apply(e,n);function i(t){_(u,o,r,i,a,"next",t)}function a(t){_(u,o,r,i,a,"throw",t)}i(void 0)}))}}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,H(o.key),o)}}function N(t,e,n){return e&&O(t.prototype,e),n&&O(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function q(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 g(t,e);var n={}.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)?g(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function F(){return(F=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)({}).hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(null,arguments)}function C(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,function(t,e){(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}(t,e)}function M(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function u(n,o,r,u){var p=Object.create((o&&o.prototype instanceof a?o:a).prototype);return S(p,"_invoke",function(n,o,r){var u,a,p,s=0,c=r||[],d=!1,l={p:0,n:0,v:t,a:m,f:m.bind(t,4),d:function(e,n){return u=e,a=0,p=t,l.n=n,i}};function m(n,o){for(a=n,p=o,e=0;!d&&s&&!r&&e<c.length;e++){var r,u=c[e],m=l.p,f=u[2];n>3?(r=f===o)&&(p=u[(a=u[4])?5:(a=3,3)],u[4]=u[5]=t):u[0]<=m&&((r=n<2&&m<u[1])?(a=0,l.v=o,l.n=u[1]):m<f&&(r=n<3||u[0]>o||o>f)&&(u[4]=n,u[5]=o,l.n=f,a=0))}if(r||n>1)return i;throw d=!0,o}return function(r,c,f){if(s>1)throw TypeError("Generator is already running");for(d&&1===c&&m(c,f),a=c,p=f;(e=a<2?t:p)||!d;){u||(a?a<3?(a>1&&(l.n=-1),m(a,p)):l.n=p:l.v=p);try{if(s=2,u){if(a||(r="next"),e=u[r]){if(!(e=e.call(u,p)))throw TypeError("iterator result is not an object");if(!e.done)return e;p=e.value,a<2&&(a=0)}else 1===a&&(e=u.return)&&e.call(u),a<2&&(p=TypeError("The iterator does not provide a '"+r+"' method"),a=1);u=t}else if((e=(d=l.n<0)?p:n.call(o,l))!==i)break}catch(e){u=t,a=1,p=e}finally{s=1}}return{value:e,done:d}}}(n,r,u),!0),p}var i={};function a(){}function p(){}function s(){}e=Object.getPrototypeOf;var c=[][o]?e(e([][o]())):(S(e={},o,(function(){return this})),e),d=s.prototype=a.prototype=Object.create(c);function l(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,s):(t.__proto__=s,S(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return p.prototype=s,S(d,"constructor",s),S(s,"constructor",p),p.displayName="GeneratorFunction",S(s,r,"GeneratorFunction"),S(d),S(d,r,"Generator"),S(d,o,(function(){return this})),S(d,"toString",(function(){return"[object Generator]"})),(M=function(){return{w:u,m:l}})()}function S(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}(S=function(t,e,n,o){function u(e,n){S(t,e,(function(t){return this._invoke(e,n,t)}))}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(u("next",0),u("throw",1),u("return",2))})(t,e,n,o)}function H(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function D(t,e){return n.CurrencyAmount.fromFractionalAmount(U(t.currency,e),t.numerator,t.denominator)}function U(t,e){if(e.involvesToken(t))return t;if(e.involvesToken(t.wrapped))return t.wrapped;if(!(e instanceof l.Pool))throw new Error("Expected currency "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol);return e.token0.wrapped.equals(t)?e.token0:e.token1.wrapped.equals(t)?e.token1:t}R.INTERFACE=new r.Interface(s.abi);var V=function(){return N((function(t,e,n,o){void 0===o&&(o=!1),this._midPrice=null,(t=o?t:t.filter((function(t){return!(t instanceof l.Pool&&0===t.tickSpacing)}))).length>0||u(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||u(!1),this.pathInput=U(e,t[0]),this.pathOutput=U(n,t[t.length-1]),t[0]instanceof l.Pool?t[0].v4InvolvesToken(this.pathInput)||u(!1):t[0].involvesToken(this.pathInput)||u(!1);var i=t[t.length-1];i instanceof l.Pool?i.v4InvolvesToken(n)||i.v4InvolvesToken(n.wrapped)||u(!1):i.involvesToken(n.wrapped)||u(!1);var a=[this.pathInput];t[0].token0.equals(this.pathInput)?a.push(t[0].token1):a.push(t[0].token0);for(var p=1;p<t.length;p++){var s=t[p],c=a[p],d=void 0;if(s instanceof l.Pool&&!s.involvesToken(c)||!(s instanceof l.Pool)&&c.isNative)if(c.equals(s.token0.wrapped))d=s.token1;else{if(!c.wrapped.equals(s.token0)&&!c.wrapped.equals(s.token1))throw new Error("POOL_MISMATCH pool: "+JSON.stringify(s)+" inputToken: "+JSON.stringify(c));d=c.wrapped.equals(s.token0)?s.token1:s.token0}else c.equals(s.token0)||c.equals(s.token1)||u(!1),d=c.equals(s.token0)?s.token1:s.token0;a.push(d)}this.pools=t,this.path=a,this.input=e,this.output=null!=n?n:a[a.length-1]}),[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,e){var n=t.price;return t.nextInput.equals(e.token0)?{nextInput:e.token1,price:n.multiply(e.token0Price.asFraction)}:{nextInput:e.token0,price:n.multiply(e.token1Price.asFraction)}}),this.pools[0].token0.equals(this.pathInput)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price.asFraction}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price.asFraction}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}])}();function X(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||u(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||u(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?t.swaps.reduce((function(t,e){return t+e.route.path.length}),0)-e.swaps.reduce((function(t,e){return t+e.route.path.length}),0):t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}var j,W=function(){function t(t){var e=t.routes,o=t.tradeType,r=e[0].inputAmount.currency,i=e[0].outputAmount.currency;e.every((function(t){return r.wrapped.equals(t.route.input.wrapped)}))||u(!1),e.every((function(t){return i.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var p,s=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,m=q(e);!(p=m()).done;)for(var f,h=q(p.value.route.pools);!(f=h()).done;){var A=f.value;if(A instanceof l.Pool)c.add(A.poolId);else if(A instanceof a.Pool)c.add(a.Pool.getAddress(A.token0,A.token1,A.fee));else{if(!(A instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");c.add(d.Pair.getAddress(A.token0,A.token1))}}s!==c.size&&u(!1),o!==n.TradeType.EXACT_INPUT&&u(!1),this.swaps=e,this.tradeType=o}t.fromRoute=function(){var e=b(M().m((function e(o,r,i){var a,p,s,c,d;return M().w((function(e){for(;;)switch(e.n){case 0:a=new Array(o.path.length),i!==n.TradeType.EXACT_INPUT&&u(!1),r.currency.equals(o.input)||u(!1),a[0]=D(r,o.pools[0]),c=0;case 1:if(!(c<o.path.length-1)){e.n=4;break}return d=o.pools[c],e.n=2,d.getOutputAmount(D(a[c],d));case 2:a[c+1]=e.v[0];case 3:c++,e.n=1;break;case 4:return p=n.CurrencyAmount.fromFractionalAmount(o.input,r.numerator,r.denominator),s=n.CurrencyAmount.fromFractionalAmount(o.output,a[a.length-1].numerator,a[a.length-1].denominator),e.a(2,new t({routes:[{inputAmount:p,outputAmount:s,route:o}],tradeType:i}))}}),e)})));return function(t,n,o){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=b(M().m((function e(o,r){var i,a,p,s,c,d,l,m,f,h,A;return M().w((function(e){for(;;)switch(e.n){case 0:i=[],r!==n.TradeType.EXACT_INPUT&&u(!1),a=q(o);case 1:if((p=a()).done){e.n=7;break}c=(s=p.value).route,d=s.amount,l=new Array(c.path.length),m=void 0,f=void 0,d.currency.equals(c.input)||u(!1),m=n.CurrencyAmount.fromFractionalAmount(c.input,d.numerator,d.denominator),l[0]=n.CurrencyAmount.fromFractionalAmount(c.pathInput,d.numerator,d.denominator),h=0;case 2:if(!(h<c.path.length-1)){e.n=5;break}return A=c.pools[h],e.n=3,A.getOutputAmount(D(l[h],A));case 3:l[h+1]=e.v[0];case 4:h++,e.n=2;break;case 5:f=n.CurrencyAmount.fromFractionalAmount(c.output,l[l.length-1].numerator,l[l.length-1].denominator),i.push({route:c,inputAmount:m,outputAmount:f});case 6:e.n=1;break;case 7:return e.a(2,new t({routes:i,tradeType:r}))}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(F({},e,{routes:[{inputAmount:e.inputAmount,outputAmount:e.outputAmount,route:e.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(e){return new t(e)};var e=t.prototype;return e.minimumAmountOut=function(t,e){void 0===e&&(e=this.outputAmount),t.lessThan(w)&&u(!1);var o=new n.Fraction(y).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},e.maximumAmountIn=function(t,e){return void 0===e&&(e=this.inputAmount),t.lessThan(w)&&u(!1),e},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=b(M().m((function e(o,r,i,a,p,s,c){var m,f,h,A,v,y,T,k,E,I,P,x,R,g,_;return M().w((function(e){for(;;)switch(e.p=e.n){case 0:h=void 0===(f=(m=void 0===a?{}:a).maxNumResults)?3:f,v=void 0===(A=m.maxHops)?3:A,void 0===p&&(p=[]),void 0===s&&(s=r),void 0===c&&(c=[]),o.length>0||u(!1),v>0||u(!1),r===s||p.length>0||u(!1),y=s,T=0;case 1:if(!(T<o.length)){e.n=15;break}if((k=o[T]).token0.equals((E=k instanceof l.Pool?y:y.wrapped).currency)||k.token1.equals(E.currency)){e.n=2;break}return e.a(3,14);case 2:if(!(k instanceof d.Pair)){e.n=3;break}if(!k.reserve0.equalTo(w)&&!k.reserve1.equalTo(w)){e.n=3;break}return e.a(3,14);case 3:if(I=void 0,e.p=4,!(k instanceof l.Pool)){e.n=6;break}return e.n=5,k.getOutputAmount(E);case 5:x=e.v,e.n=8;break;case 6:return e.n=7,k.getOutputAmount(E.wrapped);case 7:x=e.v;case 8:I=x[0],e.n=11;break;case 9:if(e.p=9,!(R=e.v).isInsufficientInputAmountError){e.n=10;break}return e.a(3,14);case 10:throw R;case 11:if(!I.currency.wrapped.equals(i.wrapped)){e.n=13;break}return g=n.sortedInsert,_=c,e.n=12,t.fromRoute(new V([].concat(p,[k]),r.currency,i),r,n.TradeType.EXACT_INPUT);case 12:g(_,e.v,h,X),e.n=14;break;case 13:if(!(v>1&&o.length>1)){e.n=14;break}return P=o.slice(0,T).concat(o.slice(T+1,o.length)),e.n=14,t.bestTradeExactIn(P,r,i,{maxNumResults:h,maxHops:v-1},[].concat(p,[k]),I,c);case 14:T++,e.n=1;break;case 15:return e.a(2,c)}}),e,null,[[4,9]])})));return function(t,n,o,r,u,i,a){return e.apply(this,arguments)}}(),N(t,[{key:"route",get:function(){return 1!==this.swaps.length&&u(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),o=q(this.swaps);!(t=o()).done;){var r=t.value;e=e.add(r.route.midPrice.quote(r.inputAmount))}var u=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new n.Percent(u.numerator,u.denominator),this._priceImpact}}])}();function L(t,e){var o=t.chainId!==n.ChainId.POLYGON;if(o){console.log("isSupportFewV2 16",o,t.chainId);var r=m.getFewTokenFromOriginalToken(t.wrapped,t.chainId);if(e instanceof m.Pair||e instanceof d.Pair){if(e.token0.wrapped.equals(r))return e.token0;if(e.token1.wrapped.equals(r))return e.token1;if(e.token0.wrapped.equals(t.wrapped))return e.token0;if(e.token1.wrapped.equals(t.wrapped))return e.token1;throw new Error("Expected fewToken "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol)}if(console.log("isSupportFewV2 33",o,t.chainId),e.token0.wrapped.equals(t.wrapped))return e.token0;if(e.token1.wrapped.equals(t.wrapped))return e.token1;if(e.token0.wrapped.equals(r))return e.token0;if(e.token1.wrapped.equals(r))return e.token1;throw new Error("Expected token "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol)}if(e.token0.wrapped.equals(t.wrapped))return e.token0;if(e.token1.wrapped.equals(t.wrapped))return e.token1;throw new Error("Expected token "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol)}(j=exports.Protocol||(exports.Protocol={})).V2="V2",j.V3="V3",j.V4="V4",j.FEWV2="FEWV2",j.MIXED="MIXED";var Z=function(t){function e(e){var n;return(n=t.call(this,e.pairs,e.input,e.output)||this).protocol=exports.Protocol.V2,n.pools=n.pairs,n.pathInput=L(e.input,n.pairs[0]),n.pathOutput=L(e.output,n.pairs[n.pairs.length-1]),n}return C(e,t),e}(d.Route),B=function(t){function e(e){var n;return(n=t.call(this,e.pairs,e.input,e.output)||this).protocol=exports.Protocol.FEWV2,n.pools=n.pairs,n.pathInput=L(e.input,n.pairs[0]),n.pathOutput=L(e.output,n.pairs[n.pairs.length-1]),n}return C(e,t),e}(m.Route),G=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.V3,n.path=e.tokenPath,n.pathInput=L(e.input,n.pools[0]),n.pathOutput=L(e.output,n.pools[n.pools.length-1]),n}return C(e,t),e}(a.Route),Q=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.V4,n.path=e.currencyPath,n}return C(e,t),e}(l.Route),J=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.MIXED,n}return C(e,t),e}(V),z=function(){function t(t){var e=t.fewV2Routes,n=void 0===e?[]:e,o=t.v2Routes,r=void 0===o?[]:o,i=t.v3Routes,p=void 0===i?[]:i,s=t.v4Routes,c=void 0===s?[]:s,f=t.mixedRoutes,h=void 0===f?[]:f,A=t.tradeType;this.swaps=[],this.routes=[];for(var v,w=q(n);!(v=w()).done;){var y=v.value,T=y.inputAmount,k=y.outputAmount,E=new B(y.fewRouteV2);this.routes.push(E),this.swaps.push({route:E,inputAmount:T,outputAmount:k})}for(var I,P=q(r);!(I=P()).done;){var x=I.value,R=x.inputAmount,g=x.outputAmount,_=new Z(x.routev2);this.routes.push(_),this.swaps.push({route:_,inputAmount:R,outputAmount:g})}for(var b,O=q(p);!(b=O()).done;){var N=b.value,F=N.inputAmount,C=N.outputAmount,M=new G(N.routev3);this.routes.push(M),this.swaps.push({route:M,inputAmount:F,outputAmount:C})}for(var S,H=q(c);!(S=H()).done;){var D=S.value,U=D.inputAmount,V=D.outputAmount,X=new Q(D.routev4);this.routes.push(X),this.swaps.push({route:X,inputAmount:U,outputAmount:V})}for(var j,W=q(h);!(j=W()).done;){var L=j.value,z=L.inputAmount,$=L.outputAmount,K=new J(L.mixedRoute);this.routes.push(K),this.swaps.push({route:K,inputAmount:z,outputAmount:$})}if(0===this.swaps.length)throw new Error("No routes provided when calling Trade constructor");this.tradeType=A;for(var Y,tt=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),et=new Set,nt=q(this.swaps);!(Y=nt()).done;)for(var ot,rt=q(Y.value.route.pools);!(ot=rt()).done;){var ut=ot.value;if(ut instanceof l.Pool)et.add(ut.poolId);else if(ut instanceof a.Pool)et.add(a.Pool.getAddress(ut.token0,ut.token1,ut.fee));else if(ut instanceof d.Pair)et.add(d.Pair.getAddress(ut.token0,ut.token1));else{if(!(ut instanceof m.Pair))throw new Error("Unexpected pool type in route when constructing trade object");et.add(m.Pair.getAddress(ut.token0,ut.token1))}}tt!==et.size&&u(!1)}var e=t.prototype;return e.isWrappedNative=function(t){return t.equals(n.Ether.onChain(t.chainId).wrapped)},e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(w)&&u(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var o=new n.Fraction(y).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(w)&&u(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var o=new n.Fraction(y).add(t).multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.fromRoutes=function(){var e=b(M().m((function e(n,o,r,u,i,p){var s,c,f,h,A,v,w,y,T,k,E,I,P,x,R,g,_,b,O,N,F,C,S,H,D,U,V,X,j,L,Z,B,G;return M().w((function(e){for(;;)switch(e.n){case 0:for(s=[],c=[],f=[],h=[],A=[],v=q(n);!(w=v()).done;)k=new m.Trade(T=(y=w.value).fewRouteV2,y.amount,u),s.push({fewRouteV2:T,inputAmount:k.inputAmount,outputAmount:k.outputAmount});for(E=q(o);!(I=E()).done;)R=new d.Trade(x=(P=I.value).routev2,P.amount,u),c.push({routev2:x,inputAmount:R.inputAmount,outputAmount:R.outputAmount});g=q(r);case 1:if((_=g()).done){e.n=4;break}return O=(b=_.value).routev3,N=b.amount,e.n=2,a.Trade.fromRoute(O,N,u);case 2:f.push({routev3:O,inputAmount:(F=e.v).inputAmount,outputAmount:F.outputAmount});case 3:e.n=1;break;case 4:if(!p){e.n=8;break}C=q(p);case 5:if((S=C()).done){e.n=8;break}return D=(H=S.value).routev4,U=H.amount,e.n=6,l.Trade.fromRoute(D,U,u);case 6:h.push({routev4:D,inputAmount:(V=e.v).inputAmount,outputAmount:V.outputAmount});case 7:e.n=5;break;case 8:if(!i){e.n=12;break}X=q(i);case 9:if((j=X()).done){e.n=12;break}return Z=(L=j.value).mixedRoute,B=L.amount,e.n=10,W.fromRoute(Z,B,u);case 10:A.push({mixedRoute:Z,inputAmount:(G=e.v).inputAmount,outputAmount:G.outputAmount});case 11:e.n=9;break;case 12:return e.a(2,new t({fewV2Routes:s,v2Routes:c,v3Routes:f,v4Routes:h,mixedRoutes:A,tradeType:u}))}}),e)})));return function(t,n,o,r,u,i){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=b(M().m((function e(n,o,r){var u,i,p,s,c,f,h,A,v,w;return M().w((function(e){for(;;)switch(e.n){case 0:if(u=[],i=[],p=[],s=[],c=[],!(n instanceof m.Route)){e.n=1;break}f=new m.Trade(n,o,r),u=[{fewRouteV2:n,inputAmount:f.inputAmount,outputAmount:f.outputAmount}],e.n=9;break;case 1:if(!(n instanceof d.Route)){e.n=2;break}h=new d.Trade(n,o,r),i=[{routev2:n,inputAmount:h.inputAmount,outputAmount:h.outputAmount}],e.n=9;break;case 2:if(!(n instanceof a.Route)){e.n=4;break}return e.n=3,a.Trade.fromRoute(n,o,r);case 3:p=[{routev3:n,inputAmount:(A=e.v).inputAmount,outputAmount:A.outputAmount}],e.n=9;break;case 4:if(!(n instanceof l.Route)){e.n=6;break}return e.n=5,l.Trade.fromRoute(n,o,r);case 5:s=[{routev4:n,inputAmount:(v=e.v).inputAmount,outputAmount:v.outputAmount}],e.n=9;break;case 6:if(!(n instanceof V)){e.n=8;break}return e.n=7,W.fromRoute(n,o,r);case 7:c=[{mixedRoute:n,inputAmount:(w=e.v).inputAmount,outputAmount:w.outputAmount}],e.n=9;break;case 8:throw new Error("Invalid route type");case 9:return e.a(2,new t({fewV2Routes:u,v2Routes:i,v3Routes:p,v4Routes:s,mixedRoutes:c,tradeType:r}))}}),e)})));return function(t,n,o){return e.apply(this,arguments)}}(),N(t,[{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"amounts",get:function(){var t,e,o=null==(t=this.swaps.find((function(t){return t.inputAmount.currency.isNative})))?void 0:t.inputAmount.currency,r=null==(e=this.swaps.find((function(t){return t.outputAmount.currency.isNative})))?void 0:e.outputAmount.currency;return{inputAmount:this.inputAmount,inputAmountNative:o?this.swaps.reduce((function(t,e){return e.route.pathInput.isNative?t.add(e.inputAmount):t}),n.CurrencyAmount.fromRawAmount(o,0)):void 0,outputAmount:this.outputAmount,outputAmountNative:r?this.swaps.reduce((function(t,e){return e.route.pathOutput.isNative?t.add(e.outputAmount):t}),n.CurrencyAmount.fromRawAmount(r,0)):void 0}}},{key:"numberOfInputWraps",get:function(){return this.inputAmount.currency.isNative?this.wethInputRoutes.length:0}},{key:"numberOfInputUnwraps",get:function(){return this.isWrappedNative(this.inputAmount.currency)?this.nativeInputRoutes.length:0}},{key:"nativeInputRoutes",get:function(){return this._nativeInputRoutes||(this._nativeInputRoutes=this.routes.filter((function(t){return t.pathInput.isNative}))),this._nativeInputRoutes}},{key:"wethInputRoutes",get:function(){var t=this;return this._wethInputRoutes||(this._wethInputRoutes=this.routes.filter((function(e){return t.isWrappedNative(e.pathInput)}))),this._wethInputRoutes}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"inputTax",get:function(){var t=this.inputAmount.currency;return t.isNative||!t.wrapped.sellFeeBps?T:new n.Percent(t.wrapped.sellFeeBps.toNumber(),1e4)}},{key:"outputTax",get:function(){var t=this.outputAmount.currency;return t.isNative||!t.wrapped.buyFeeBps?T:new n.Percent(t.wrapped.buyFeeBps.toNumber(),1e4)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;if(this.outputTax.equalTo(k))return T;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),o=q(this.swaps);!(t=o()).done;){var r=t.value,u=r.route.midPrice,i=r.inputAmount.multiply(new n.Fraction(y).subtract(this.inputTax));e=e.add(u.quote(i))}if(e.equalTo(w))return T;var a=this.outputAmount.divide(new n.Fraction(y).subtract(this.outputTax)),p=e.subtract(a).divide(e);return this._priceImpact=new n.Percent(p.numerator,p.denominator),this._priceImpact}}])}();function $(t,e){var n,o;if(null!=e?e:t.pools.some((function(t){return t instanceof l.Pool}))){n=[t.pathInput.isNative?h:t.pathInput.address],o=["address"];for(var r,u=t.pathInput,i=q(t.pools);!(r=i()).done;){var p=r.value,s=u.equals(p.token0)?p.token1:p.token0;if(p instanceof l.Pool)0===p.tickSpacing?(n.push(0,s.isNative?h:s.wrapped.address),o.push("uint8","address")):(n.push(p.fee+(4<<20),p.tickSpacing,p.hooks,s.isNative?h:s.wrapped.address),o.push("uint24","uint24","address","address"));else if(p instanceof a.Pool)n.push(p.fee+(3<<20),s.wrapped.address),o.push("uint24","address");else{if(!(p instanceof d.Pair))throw new Error("Unsupported pool type "+JSON.stringify(p));n.push(32,s.wrapped.address),o.push("uint8","address")}u=s}}else{var c=t.pools.reduce((function(t,e,n){var o=t.inputToken,r=t.path,u=t.types,i=e.token0.equals(o)?e.token1:e.token0;return 0===n?{inputToken:i,types:["address","uint24","address"],path:[o.wrapped.address,e instanceof a.Pool?e.fee:1<<23,i.wrapped.address]}:{inputToken:i,types:[].concat(u,["uint24","address"]),path:[].concat(r,[e instanceof a.Pool?e.fee:1<<23,i.wrapped.address])}}),{inputToken:t.input,path:[],types:[]});n=c.path,o=c.types}return f.pack(o,n)}var K=function(t){for(var e=[],n=0,o=0;o<t.pools.length;)(t.pools[n]instanceof l.Pool&&!(t.pools[o]instanceof l.Pool)||t.pools[n]instanceof a.Pool&&!(t.pools[o]instanceof a.Pool)||t.pools[n]instanceof d.Pair&&!(t.pools[o]instanceof d.Pair))&&(e.push(t.pools.slice(n,o)),n=o),++o===t.pools.length&&e.push(t.pools.slice(n,o));return e},Y=function(t,e){return t.reduce((function(t,e){var n=t.inputToken;if(!e.involvesToken(n))throw new Error("PATH");return{inputToken:e.token0.equals(n)?e.token1:e.token0}}),{inputToken:e}).inputToken},tt=o.BigInt(0),et=new n.Percent(o.BigInt(50),o.BigInt(100)),nt=function(){function t(){}return t.encodeV2Swap=function(e,o,r,u){var i=a.toHex(e.maximumAmountIn(o.slippageTolerance).quotient),p=a.toHex(e.minimumAmountOut(o.slippageTolerance).quotient),s=e.route.path.map((function(t){return t.address})),c=r?v:void 0===o.recipient?A:n.validateAndParseAddress(o.recipient);return e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[i,u?0:p,s,c]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[p,i,s,c])},t.encodeV3Swap=function(e,o,r,u){for(var i,p=[],s=q(e.swaps);!(i=s()).done;){var c=i.value,d=c.route,l=c.outputAmount,m=a.toHex(e.maximumAmountIn(o.slippageTolerance,c.inputAmount).quotient),f=a.toHex(e.minimumAmountOut(o.slippageTolerance,l).quotient),h=1===d.pools.length,w=r?v:void 0===o.recipient?A:n.validateAndParseAddress(o.recipient);if(h)p.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:w,amountIn:m,amountOutMinimum:u?0:f,sqrtPriceLimitX96:0}]):t.INTERFACE.encodeFunctionData("exactOutputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:w,amountOut:f,amountInMaximum:m,sqrtPriceLimitX96:0}]));else{var y=a.encodeRouteToPath(d,e.tradeType===n.TradeType.EXACT_OUTPUT);p.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:y,recipient:w,amountIn:m,amountOutMinimum:u?0:f}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:y,recipient:w,amountOut:f,amountInMaximum:m}]))}}return p},t.encodeMixedRouteSwap=function(e,o,r,i){var p=[];e.tradeType!==n.TradeType.EXACT_INPUT&&u(!1);for(var s,c=function(){var u=s.value,c=u.route,d=u.inputAmount,m=u.outputAmount;if(c.pools.some((function(t){return t instanceof l.Pool})))throw new Error("Encoding mixed routes with V4 not supported");var f=a.toHex(e.maximumAmountIn(o.slippageTolerance,d).quotient),h=a.toHex(e.minimumAmountOut(o.slippageTolerance,m).quotient),w=1===c.pools.length,y=r?v:void 0===o.recipient?A:n.validateAndParseAddress(o.recipient),T=function(t){return t.pools.every((function(t){return t instanceof a.Pool}))};if(w)if(T(c))p.push(t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:c.path[0].wrapped.address,tokenOut:c.path[1].wrapped.address,fee:c.pools[0].fee,recipient:y,amountIn:f,amountOutMinimum:i?0:h,sqrtPriceLimitX96:0}]));else{var k=c.path.map((function(t){return t.wrapped.address}));p.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[f,i?0:h,k,y]))}else for(var E,I=K(c),P=function(t){return t===I.length-1},x=c.input.wrapped,R=0;R<I.length;R++){var g=I[R];E=Y(g,x);var _=new V([].concat(g),g[0].token0.equals(x)?g[0].token0:g[0].token1,E),b=new J(_);if(x=E.wrapped,T(b)){var O={path:$(b),recipient:P(R)?y:v,amountIn:0===R?f:0,amountOutMinimum:P(R)?h:0};p.push(t.INTERFACE.encodeFunctionData("exactInput",[O]))}else{var N=[0===R?f:0,P(R)?h:0,b.path.map((function(t){return t.wrapped.address})),P(R)?y:v];p.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",N))}}},d=q(e.swaps);!(s=d()).done;)c();return p},t.encodeSwaps=function(e,o,r){if(e instanceof z){e.swaps.every((function(t){return t.route.protocol===exports.Protocol.V3||t.route.protocol===exports.Protocol.V2||t.route.protocol===exports.Protocol.MIXED}))||u(!1);for(var i,p=[],s=q(e.swaps);!(i=s()).done;){var c=i.value,l=c.route,m=c.inputAmount,f=c.outputAmount;if(l.protocol===exports.Protocol.V2)p.push(new d.Trade(l,e.tradeType===n.TradeType.EXACT_INPUT?m:f,e.tradeType));else if(l.protocol===exports.Protocol.V3)p.push(a.Trade.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}));else{if(l.protocol!==exports.Protocol.MIXED)throw new Error("UNSUPPORTED_TRADE_PROTOCOL");p.push(W.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}))}}e=p}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof a.Trade||e instanceof W?e.swaps.length:1)}),0),A=e[0];e.every((function(t){return t.inputAmount.currency.equals(A.inputAmount.currency)}))||u(!1),e.every((function(t){return t.outputAmount.currency.equals(A.outputAmount.currency)}))||u(!1),e.every((function(t){return t.tradeType===A.tradeType}))||u(!1);var v=[],w=A.inputAmount.currency.isNative,y=A.outputAmount.currency.isNative,T=A.tradeType===n.TradeType.EXACT_INPUT&&h>2,k=y||!!o.fee||!!r||T;o.inputTokenPermit&&(A.inputAmount.currency.isToken||u(!1),v.push(a.SelfPermit.encodePermit(A.inputAmount.currency,o.inputTokenPermit)));for(var E,I=q(e);!(E=I()).done;){var P=E.value;if(P instanceof d.Trade)v.push(t.encodeV2Swap(P,o,k,T));else if(P instanceof a.Trade)for(var x,R=q(t.encodeV3Swap(P,o,k,T));!(x=R()).done;)v.push(x.value);else{if(!(P instanceof W))throw new Error("Unsupported trade object");for(var g,_=q(t.encodeMixedRouteSwap(P,o,k,T));!(g=_()).done;)v.push(g.value)}}var b=n.CurrencyAmount.fromRawAmount(A.inputAmount.currency,0),O=n.CurrencyAmount.fromRawAmount(A.outputAmount.currency,0),N=e.reduce((function(t,e){return t.add(e.minimumAmountOut(o.slippageTolerance))}),O),F=e.reduce((function(t,e){return t.add(e.outputAmount)}),O),C=e.reduce((function(t,e){return t.add(e.maximumAmountIn(o.slippageTolerance))}),b);return{calldatas:v,sampleTrade:A,routerMustCustody:k,inputIsNative:w,outputIsNative:y,totalAmountIn:C,minimumAmountOut:N,quoteAmountOut:F}},t.swapCallParameters=function(e,o){var r=t.encodeSwaps(e,o),u=r.calldatas,i=r.sampleTrade,p=r.inputIsNative,s=r.totalAmountIn,c=r.minimumAmountOut;return r.routerMustCustody&&u.push(r.outputIsNative?R.encodeUnwrapWETH9(c.quotient,o.recipient,o.fee):R.encodeSweepToken(i.outputAmount.currency.wrapped,c.quotient,o.recipient,o.fee)),p&&(i.tradeType===n.TradeType.EXACT_OUTPUT||t.riskOfPartialFill(e))&&u.push(a.Payments.encodeRefundETH()),{calldata:P.encodeMulticall(u,o.deadlineOrPreviousBlockhash),value:a.toHex(p?s.quotient:tt)}},t.swapAndAddCallParameters=function(e,o,r,i,p,s){var c=t.encodeSwaps(e,o,!0),d=c.calldatas,l=c.inputIsNative,m=c.outputIsNative,f=c.sampleTrade,h=c.totalAmountIn,A=c.quoteAmountOut,v=c.minimumAmountOut;o.outputTokenPermit&&(A.currency.isToken||u(!1),d.push(a.SelfPermit.encodePermit(A.currency,o.outputTokenPermit)));var w=f.route.chainId,y=r.pool.token0.wrapped.address===h.currency.wrapped.address,T=t.getPositionAmounts(r,y),k=T.positionAmountIn,E=T.positionAmountOut,x=l?n.WETH9[w]:k.currency.wrapped,g=m?n.WETH9[w]:E.currency.wrapped,_=E.subtract(A.wrapped);_.greaterThan(n.CurrencyAmount.fromRawAmount(E.currency,0))&&d.push(m?R.encodeWrapETH(_.quotient):R.encodePull(g,_.quotient)),d.push(l?R.encodeWrapETH(k.quotient):R.encodePull(x,k.quotient)),p!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(I.encodeApprove(x,p)),s!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(I.encodeApprove(g,s));var b,O=a.Position.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:y?r.amount0.quotient.toString():v.quotient.toString(),amount1:y?v.quotient.toString():r.amount1.quotient.toString(),useFullPrecision:!1});return d.push(I.encodeAddLiquidity(r,O,i,o.slippageTolerance)),d.push(l?R.encodeUnwrapWETH9(tt):R.encodeSweepToken(x,tt)),d.push(m?R.encodeUnwrapWETH9(tt):R.encodeSweepToken(g,tt)),b=l?h.wrapped.add(k.wrapped).quotient:m?_.quotient:tt,{calldata:P.encodeMulticall(d,o.deadlineOrPreviousBlockhash),value:b.toString()}},t.riskOfPartialFill=function(e){return Array.isArray(e)?e.some((function(e){return t.v3TradeWithHighPriceImpact(e)})):t.v3TradeWithHighPriceImpact(e)},t.v3TradeWithHighPriceImpact=function(t){return!(t instanceof d.Trade)&&t.priceImpact.greaterThan(et)},t.getPositionAmounts=function(t,e){var o=t.mintAmounts,r=o.amount1,u=n.CurrencyAmount.fromRawAmount(t.pool.token0,o.amount0),i=n.CurrencyAmount.fromRawAmount(t.pool.token1,r),a=e?[u,i]:[i,u];return{positionAmountIn:a[0],positionAmountOut:a[1]}},t}();nt.INTERFACE=new r.Interface(c.abi),exports.ADDRESS_THIS=v,exports.ADDRESS_ZERO=h,exports.ApproveAndCall=I,exports.FewRouteV2=B,exports.MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER=1<<23,exports.MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER=32,exports.MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER=3<<20,exports.MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER=4<<20,exports.MSG_SENDER=A,exports.MixedRoute=J,exports.MixedRouteSDK=V,exports.MixedRouteTrade=W,exports.MulticallExtended=P,exports.ONE=y,exports.ONE_HUNDRED_PERCENT=k,exports.PaymentsExtended=R,exports.RING_FEE_PATH_PLACEHOLDER=4194304,exports.RouteV2=Z,exports.RouteV3=G,exports.RouteV4=Q,exports.SwapRouter=nt,exports.Trade=z,exports.ZERO=w,exports.ZERO_PERCENT=T,exports.amountWithPathCurrency=D,exports.encodeMixedRouteToPath=$,exports.getOutputOfPools=Y,exports.getPathCurrency=U,exports.getPathToken=L,exports.isMint=E,exports.partitionMixedRouteByProtocol=K,exports.tradeComparator=X;
|
|
2
2
|
//# sourceMappingURL=router-sdk.cjs.production.min.js.map
|