@hybridx-exchange/hybridx-sdk
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n,r,o,i,a,s,u,c,d,p,h=t(require("jsbi")),l=t(require("tiny-invariant")),f=(t(require("tiny-warning")),require("@ethersproject/address")),T=t(require("big.js")),m=t(require("toformat")),v=t(require("decimal.js-light")),I=require("@ethersproject/units"),y=require("@ethersproject/solidity"),x=require("@ethersproject/contracts"),w=require("@ethersproject/networks"),k=require("@ethersproject/providers"),g=t(require("@hybridx-exchange/hybridx-protocol/build/IPair.json"));(u=exports.ChainId||(exports.ChainId={}))[u.MAINNET=42262]="MAINNET",u[u.TESTNET=42261]="TESTNET",u[u.OPTIMISM_MAINNET=10]="OPTIMISM_MAINNET",u[u.OPTIMISM_TESTNET=69]="OPTIMISM_TESTNET",(c=exports.SwapType||(exports.SwapType={}))[c.EXACT_INPUT=0]="EXACT_INPUT",c[c.EXACT_OUTPUT=1]="EXACT_OUTPUT",(d=exports.TradeType||(exports.TradeType={}))[d.LIMIT_BUY=1]="LIMIT_BUY",d[d.LIMIT_SELL=2]="LIMIT_SELL",(p=exports.Rounding||(exports.Rounding={}))[p.ROUND_DOWN=0]="ROUND_DOWN",p[p.ROUND_HALF_UP=1]="ROUND_HALF_UP",p[p.ROUND_UP=2]="ROUND_UP";var E,A=((e={})[exports.ChainId.TESTNET]="0x35bAFF0DC208db7e0701fc16791E5f6871443470",e[exports.ChainId.MAINNET]="",e[exports.ChainId.OPTIMISM_TESTNET]="0x437dF742fA73286d0614CB06a82c3181503eF1C4",e[exports.ChainId.OPTIMISM_MAINNET]="",e),O=((n={})[exports.ChainId.TESTNET]="0x8b466f281C2067a5F40A42daE43350b6A35a0b05",n[exports.ChainId.MAINNET]="",n[exports.ChainId.OPTIMISM_TESTNET]="0x0278b3b257a99DE6465519bb7cD1ba974D2e07dc",n[exports.ChainId.OPTIMISM_MAINNET]="",n),b=((r={})[exports.ChainId.TESTNET]="0x581ef0ccd0c15ef0a380cd82bca41249ca81e3c415fdb4fc8f6977e7d4f8c8fa",r[exports.ChainId.MAINNET]="",r[exports.ChainId.OPTIMISM_TESTNET]="0xf569504b9c978ab3c6f54f6800fc13a32c9577594e844050bb275b0cf69d74f2",r[exports.ChainId.OPTIMISM_MAINNET]="",r),S=((o={})[exports.ChainId.TESTNET]="0xA9a06cf12AE3514b101D426797D190b79B335Eb2",o[exports.ChainId.MAINNET]="",o[exports.ChainId.OPTIMISM_TESTNET]="0xe3B3eC21D39971eD9dD3b845d16d44e56DE03A36",o[exports.ChainId.OPTIMISM_MAINNET]="",o),N=((i={})[exports.ChainId.TESTNET]="0x1da881d372a03ec2bce6e0bdc6c5d5696b7e7c47e8632d0bdfb6eb52d80abb48",i[exports.ChainId.MAINNET]="",i[exports.ChainId.OPTIMISM_TESTNET]="0x7bf7b81d62e2d81627067202acb75c43b0144a088886d3cd99c8dd61315700c7",i[exports.ChainId.OPTIMISM_MAINNET]="",i),q=((a={})[exports.ChainId.TESTNET]="0x374d19331443638013ff34b50550a36e2622d2839fe244467678500262d11f40",a[exports.ChainId.MAINNET]="",a[exports.ChainId.OPTIMISM_TESTNET]="0x374d19331443638013ff34b50550a36e2622d2839fe244467678500262d11f40",a[exports.ChainId.OPTIMISM_MAINNET]="",a),_=h.BigInt(1e3),M=h.BigInt(0),P=h.BigInt(1),C=h.BigInt(2),R=h.BigInt(3),D=h.BigInt(5),U=h.BigInt(10),B=h.BigInt(100),F=h.BigInt(997),L=h.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(E||(E={}));var H=((s={})[E.uint8]=h.BigInt("0xff"),s[E.uint256]=h.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),s);function j(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function W(t,e,n){return e&&j(t.prototype,e),n&&j(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function X(){return(X=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function Y(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,K(t,e)}function Z(t){return(Z=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function K(t,e){return(K=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function Q(){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 G(t,e,n){return(G=Q()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&K(o,n.prototype),o}).apply(null,arguments)}function J(t){var e="function"==typeof Map?new Map:void 0;return(J=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return G(t,arguments,Z(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),K(n,t)})(t)}function V(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function $(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 z(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 $(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)?$(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 tt,et="setPrototypeOf"in Object,nt=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,et&&Object.setPrototypeOf(V(n),(this instanceof e?this.constructor:void 0).prototype),n}return Y(e,t),e}(J(Error)),rt=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,et&&Object.setPrototypeOf(V(n),(this instanceof e?this.constructor:void 0).prototype),n}return Y(e,t),e}(J(Error));function ot(t){return"0x"+t.raw.toString(16)}function it(t,e){h.greaterThanOrEqual(t,M)||l(!1),h.lessThanOrEqual(t,H[e])||l(!1)}function at(t){try{return f.getAddress(t)}catch(t){l(!1)}}function st(t){return t instanceof h?t:h.BigInt("bigint"==typeof t?t.toString():t)}function ut(t){it(t,E.uint256);var e,n=M;if(h.greaterThan(t,R))for(n=t,e=h.add(h.divide(t,C),P);h.lessThan(e,n);)n=e,e=h.divide(h.add(h.divide(t,e),e),C);else h.notEqual(t,M)&&(n=P);return n}var ct,dt=function(t,e,n){it(h.BigInt(t),E.uint8),this.decimals=t,this.symbol=e,this.name=n},pt=dt.ETHER=((tt={})[exports.ChainId.TESTNET]=new dt(18,"ROSE","ROSE"),tt[exports.ChainId.MAINNET]=new dt(18,"ROSE","ROSE"),tt[exports.ChainId.OPTIMISM_MAINNET]=new dt(18,"ETH","ETH"),tt[exports.ChainId.OPTIMISM_TESTNET]=new dt(18,"ETH","ETH"),tt),ht=function(t){function e(e,n,r,o,i){var a;return(a=t.call(this,r,o,i)||this).chainId=e,a.address=at(n),a}Y(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&&l(!1),this.address===t.address&&l(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(dt);function lt(t,e){return t instanceof ht&&e instanceof ht?t.equals(e):!(t instanceof ht||e instanceof ht||t!==e)}var ft,Tt,mt=((ct={})[exports.ChainId.MAINNET]=new ht(exports.ChainId.MAINNET,"0xb9ab821f7323dB4357Bf71eA66670C01761c3d73",18,"WROSE","Wrapped ROSE"),ct[exports.ChainId.TESTNET]=new ht(exports.ChainId.TESTNET,"0xb9ab821f7323dB4357Bf71eA66670C01761c3d73",18,"WROSE","Wrapped ROSE"),ct[exports.ChainId.OPTIMISM_TESTNET]=new ht(exports.ChainId.OPTIMISM_TESTNET,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped ETH"),ct[exports.ChainId.OPTIMISM_MAINNET]=new ht(exports.ChainId.OPTIMISM_MAINNET,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped ETH"),ct),vt=m(v),It=m(T),yt=((ft={})[exports.Rounding.ROUND_DOWN]=vt.ROUND_DOWN,ft[exports.Rounding.ROUND_HALF_UP]=vt.ROUND_HALF_UP,ft[exports.Rounding.ROUND_UP]=vt.ROUND_UP,ft),xt=((Tt={})[exports.Rounding.ROUND_DOWN]=0,Tt[exports.Rounding.ROUND_HALF_UP]=1,Tt[exports.Rounding.ROUND_UP]=3,Tt),wt=function(){function t(t,e){void 0===e&&(e=P),this.numerator=st(t),this.denominator=st(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(st(e));return h.equal(this.denominator,n.denominator)?new t(h.add(this.numerator,n.numerator),this.denominator):new t(h.add(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator)),h.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=e instanceof t?e:new t(st(e));return h.equal(this.denominator,n.denominator)?new t(h.subtract(this.numerator,n.numerator),this.denominator):new t(h.subtract(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator)),h.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=e instanceof t?e:new t(st(e));return h.lessThan(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=e instanceof t?e:new t(st(e));return h.equal(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=e instanceof t?e:new t(st(e));return h.greaterThan(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=e instanceof t?e:new t(st(e));return new t(h.multiply(this.numerator,n.numerator),h.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=e instanceof t?e:new t(st(e));return new t(h.multiply(this.numerator,n.denominator),h.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)||l(!1),t>0||l(!1),vt.set({precision:t+1,rounding:yt[n]});var r=new vt(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)||l(!1),t>=0||l(!1),It.DP=t,It.RM=xt[n],new It(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},W(t,[{key:"quotient",get:function(){return h.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(h.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),kt=m(T),gt=function(t){function e(e,n){var r,o=st(n);return it(o,E.uint256),(r=t.call(this,o,h.exponentiate(U,h.BigInt(e.decimals)))||this).currency=e,r}Y(e,t),e.ether=function(t,n){return new e(pt[n],t)};var n=e.prototype;return n.add=function(t){return lt(this.currency,t.currency)||l(!1),new e(this.currency,h.add(this.raw,t.raw))},n.subtract=function(t){return lt(this.currency,t.currency)||l(!1),new e(this.currency,h.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||l(!1),t.prototype.toFixed.call(this,e,n,r)},n.toFixedWithoutExtraZero=function(n,r,o){void 0===n&&(n=this.currency.decimals),void 0===o&&(o=exports.Rounding.ROUND_DOWN),n<=this.currency.decimals||l(!1);var i=t.prototype.toFixed.call(this,n,r,o);return new e(this.currency,I.parseUnits(i,this.currency.decimals).toString()).toExact(r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),kt.DP=this.currency.decimals,new kt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},W(e,[{key:"raw",get:function(){return this.numerator}}]),e}(wt),Et=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}Y(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||l(!1),new e(this.token,h.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||l(!1),new e(this.token,h.subtract(this.raw,t.raw))},e}(gt),At=function(t){function e(e,n,r,o){var i;return(i=t.call(this,o,r)||this).baseCurrency=e,i.quoteCurrency=n,i.scalar=new wt(h.exponentiate(U,h.BigInt(e.decimals)),h.exponentiate(U,h.BigInt(n.decimals))),i}Y(e,t),e.fromRoute=function(t){for(var n,r=[],o=z(t.pairs.entries());!(n=o()).done;){var i=n.value,a=i[1];r.push(t.path[i[0]].equals(a.token0)?new e(a.reserve0.currency,a.reserve1.currency,a.reserve0.raw,a.reserve1.raw):new e(a.reserve1.currency,a.reserve0.currency,a.reserve1.raw,a.reserve0.raw))}return r.slice(1).reduce((function(t,e){return t.multiply(e)}),r[0])};var n=e.prototype;return n.invert=function(){return new e(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},n.multiply=function(n){lt(this.quoteCurrency,n.baseCurrency)||l(!1);var r=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,r.denominator,r.numerator)},n.quote=function(e,n){return lt(e.currency,this.baseCurrency)||l(!1),this.quoteCurrency instanceof ht?new Et(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):gt.ether(t.prototype.multiply.call(this,e.raw).quotient,n)},n.toSignificant=function(t,e,n){return void 0===t&&(t=6),this.adjusted.toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=4),this.adjusted.toFixed(t,e,n)},W(e,[{key:"raw",get:function(){return new wt(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(wt),Ot={},bt=function(){function t(e,n){var r=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new ht(r[0].token.chainId,t.getAddress(r[0].token,r[1].token),18,"LPT","HybridX LP Token"),this.tokenAmounts=r}t.getAddress=function(t,e){var n,r,o,i,a,s,u,c,d,p=t.sortsBefore(e)?[t,e]:[e,t],h=t.chainId;return void 0===(null===(n=Ot)||void 0===n||null===(r=n[h])||void 0===r||null===(o=r[p[0].address])||void 0===o?void 0:o[p[1].address])&&(Ot=X({},Ot,((d={})[h]=X({},null===(i=Ot)||void 0===i?void 0:i[h],((c={})[p[0].address]=X({},null===(a=Ot)||void 0===a||null===(s=a[h])||void 0===s?void 0:s[p[0].address],((u={})[p[1].address]=f.getCreate2Address(O[h],y.keccak256(["bytes"],[y.pack(["address","address"],[p[0].address,p[1].address])]),b[h]),u)),c)),d))),Ot[h][p[0].address][p[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)||l(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||l(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||l(!1),h.equal(this.reserve0.raw,M)||h.equal(this.reserve1.raw,M))throw new nt;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=h.multiply(e.raw,F),i=h.multiply(o,r.raw),a=h.add(h.multiply(n.raw,L),o),s=new Et(e.token.equals(this.token0)?this.token1:this.token0,h.divide(i,a));if(h.equal(s.raw,M))throw new rt;return[s,new t(n.add(e),r.subtract(s))]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||l(!1),h.equal(this.reserve0.raw,M)||h.equal(this.reserve1.raw,M)||h.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new nt;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=h.multiply(h.multiply(r.raw,e.raw),L),i=h.multiply(h.subtract(n.raw,e.raw),F),a=new Et(e.token.equals(this.token0)?this.token1:this.token0,h.add(h.divide(o,i),P));return[a,new t(r.add(a),n.subtract(e))]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||l(!1);var r,o=e.token.sortsBefore(n.token)?[e,n]:[n,e];if(o[0].token.equals(this.token0)&&o[1].token.equals(this.token1)||l(!1),h.equal(t.raw,M))r=h.subtract(ut(h.multiply(o[0].raw,o[1].raw)),_);else{var i=h.divide(h.multiply(o[0].raw,t.raw),this.reserve0.raw),a=h.divide(h.multiply(o[1].raw,t.raw),this.reserve1.raw);r=h.lessThanOrEqual(i,a)?i:a}if(!h.greaterThan(r,M))throw new rt;return new Et(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var i;if(void 0===r&&(r=!1),this.involvesToken(t)||l(!1),e.token.equals(this.liquidityToken)||l(!1),n.token.equals(this.liquidityToken)||l(!1),h.lessThanOrEqual(n.raw,e.raw)||l(!1),r){o||l(!1);var a=st(o);if(h.equal(a,M))i=e;else{var s=ut(h.multiply(this.reserve0.raw,this.reserve1.raw)),u=ut(a);if(h.greaterThan(s,u)){var c=h.multiply(e.raw,h.subtract(s,u)),d=h.add(h.multiply(s,D),u),p=h.divide(c,d);i=e.add(new Et(this.liquidityToken,p))}else i=e}}else i=e;return new Et(t,h.divide(h.multiply(n.raw,this.reserveOf(t).raw),i.raw))},W(t,[{key:"token0Price",get:function(){return new At(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new At(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}(),St={},Nt={},qt=function(){function t(e,n,r,o,i,a,s,u,c,d,p,h){this.exist=e,this.orderBookAddress=t.getAddress(n.token,r.token),this.baseToken=n,this.quoteToken=r,this.baseSignificantDigits=o<n.token.decimals?o:n.token.decimals,this.quoteSignificantDigits=i<r.token.decimals?i:r.token.decimals,this.priceStepFactor=s,this.priceStep=a,this.protocolFeeRate=u,this.subsidyFeeRate=c,this.curPrice=d,this.buyOrders=p,this.sellOrders=h}t.getAddress=function(t,e){var n,r,o,i,a,s,u,c,d,p=t.sortsBefore(e)?[t,e]:[e,t],h=t.chainId;return void 0===(null===(n=St)||void 0===n||null===(r=n[h])||void 0===r||null===(o=r[p[0].address])||void 0===o?void 0:o[p[1].address])&&(St=X({},St,((d={})[h]=X({},null===(i=St)||void 0===i?void 0:i[h],((c={})[p[0].address]=X({},null===(a=St)||void 0===a||null===(s=a[h])||void 0===s?void 0:s[p[0].address],((u={})[p[1].address]=f.getCreate2Address(S[h],y.keccak256(["bytes"],[y.pack(["address","address"],[p[0].address,p[1].address])]),N[h]),u)),c)),d))),St[h][p[0].address][p[1].address]},t.getNFTAddress=function(e,n){var r,o,i,a,s,u,c,d,p,h=e.sortsBefore(n)?[e,n]:[n,e],l=e.chainId;return void 0===(null===(r=Nt)||void 0===r||null===(o=r[l])||void 0===o||null===(i=o[h[0].address])||void 0===i?void 0:i[h[1].address])&&(Nt=X({},Nt,((p={})[l]=X({},null===(a=Nt)||void 0===a?void 0:a[l],((d={})[h[0].address]=X({},null===(s=Nt)||void 0===s||null===(u=s[l])||void 0===u?void 0:u[h[0].address],((c={})[h[1].address]=f.getCreate2Address(S[l],y.keccak256(["bytes"],[y.pack(["address","address","address"],[t.getAddress(e,n),h[0].address,h[1].address])]),q[l]),c)),d)),p))),Nt[l][h[0].address][h[1].address]},t.culPrice=function(t,e){if(t&&e){var n=st(t.raw),r=st(e.raw),o=st(I.parseUnits("1",t.token.decimals).toString()),i=e.token,a=h.divide(h.multiply(r,o),n);return new Et(i,a)}};var e=t.prototype;return e.getPriceStep=function(t){return!this.priceStep||h.EQ(st(this.priceStep),st("0"))?h.lessThanOrEqual(st(t),h.BigInt(1e4))?h.BigInt(1e4):h.multiply(h.divide(st(t),h.BigInt(1e4)),st(this.priceStepFactor)):this.priceStep},e.getPriceStepDecimal=function(){return this.quoteSignificantDigits},e.getMinAmountDecimal=function(t){return t===exports.TradeType.LIMIT_BUY?this.quoteSignificantDigits:t===exports.TradeType.LIMIT_SELL?this.baseSignificantDigits:18},e.getMinOutputAmountDecimal=function(t){return t===exports.TradeType.LIMIT_SELL?this.quoteSignificantDigits:t===exports.TradeType.LIMIT_BUY?this.baseSignificantDigits:18},t}(),_t=function(){function t(t,e,n,r,o){t.length>0||l(!1),t.every((function(e){return e.chainId===t[0].chainId}))||l(!1);var i=t[0].chainId;r instanceof ht&&t[0].involvesToken(r)||r===pt[i]&&t[0].involvesToken(mt[i])||l(!1),void 0===o||o instanceof ht&&t[t.length-1].involvesToken(o)||o===pt[i]&&t[t.length-1].involvesToken(mt[i])||l(!1);for(var a,s=[r instanceof ht?r:mt[i]],u=z(t.entries());!(a=u()).done;){var c=a.value,d=c[1],p=s[c[0]];p.equals(d.token0)||p.equals(d.token1)||l(!1);var h=p.equals(d.token0)?d.token1:d.token0;s.push(h)}this.pairs=t,this.path=s,this.amounts=e,this.extra=n,this.midPrice=At.fromRoute(this),this.input=r,this.output=null!=o?o:s[s.length-1]}return W(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),Mt=new wt(B),Pt=function(t){function e(){return t.apply(this,arguments)||this}Y(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(Mt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(Mt).toFixed(t,e,n)},e}(wt);function Ct(t,e){return lt(t.inputAmount.currency,e.inputAmount.currency)||l(!1),lt(t.outputAmount.currency,e.outputAmount.currency)||l(!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 Rt(t,e){return t instanceof Et?t:t.currency===pt[e]?new Et(mt[e],t.raw):void l(!1)}function Dt(t,e){return t instanceof ht?t:t===pt[e]?mt[e]:void l(!1)}function Ut(t,e){return new Et(t.token,e)}var Bt,Ft=function(){function t(t,e,n){var r=new Array(t.path.length),o=new Array(t.pairs.length),i=t.chainId;if(t.amounts.length!==t.path.length&&l(!1),n===exports.SwapType.EXACT_INPUT){lt(e.currency,t.input)||l(!1),r[0]=Rt(e,t.chainId);for(var a=0;a<t.path.length-1;a++){var s=t.pairs[a],u=r[a].token.equals(s.token0)?s.token1:s.token0,c=new Et(u,t.amounts[a+1]),d=new bt(Ut(r[a],t.extra[6*a]),Ut(c,t.extra[6*a+1]));r[a+1]=c,o[a]=d}}else{lt(e.currency,t.output)||l(!1),r[r.length-1]=Rt(e,t.chainId);for(var p=t.path.length-1;p>0;p--){var h=t.pairs[p-1],f=r[p].token.equals(h.token0)?h.token1:h.token0,T=new Et(f,t.amounts[p-1]),m=new bt(Ut(T,t.extra[6*(p-1)]),Ut(r[p],t.extra[6*(p-1)+1]));r[p-1]=T,o[p-1]=m}}this.route=t,this.swapType=n,this.inputAmount=n===exports.SwapType.EXACT_INPUT?e:t.input===pt[i]?gt.ether(r[0].raw,i):r[0],this.outputAmount=n===exports.SwapType.EXACT_OUTPUT?e:t.output===pt[i]?gt.ether(r[r.length-1].raw,i):r[r.length-1],this.executionPrice=new At(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=At.fromRoute(new _t(o,[],[],t.input)),this.priceImpact=function(t,e,n){var r=t.raw.multiply(e.raw),o=r.subtract(n.raw).divide(r);return new Pt(o.numerator,o.denominator)}(t.midPrice,this.inputAmount,this.outputAmount)}t.exactIn=function(e,n){return new t(e,n,exports.SwapType.EXACT_INPUT)},t.exactOut=function(e,n){return new t(e,n,exports.SwapType.EXACT_OUTPUT)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(M)&&l(!1),this.swapType===exports.SwapType.EXACT_OUTPUT)return this.outputAmount;var e=new wt(P).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof Et?new Et(this.outputAmount.token,e):gt.ether(e,this.route.chainId)},e.maximumAmountIn=function(t){if(t.lessThan(M)&&l(!1),this.swapType===exports.SwapType.EXACT_INPUT)return this.inputAmount;var e=new wt(P).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof Et?new Et(this.inputAmount.token,e):gt.ether(e,this.route.chainId)},t.allPathExactIn=function(e,n,r,o,i,a,s){var u=(void 0===o?{}:o).maxHops,c=void 0===u?3:u;void 0===i&&(i=[]),void 0===a&&(a=n),void 0===s&&(s=[]),e.length>0||l(!1),c>0||l(!1),a===n||i.length>0||l(!1);var d=n instanceof ht?n.chainId:r instanceof ht?r.chainId:void 0;void 0===d&&l(!1);for(var p=Dt(n,d),h=Dt(r,d),f=0;f<e.length;f++){var T=e[f];if((T.token0.equals(p)||T.token1.equals(p))&&!T.reserve0.equalTo(M)&&!T.reserve1.equalTo(M)){var m=p.equals(T.token0)?T.token1:T.token0;if(m.equals(h))s.push(new _t([].concat(i,[T]),[],[],a,r));else if(c>1&&e.length>1){var v=e.slice(0,f).concat(e.slice(f+1,e.length));t.allPathExactIn(v,m,r,{maxHops:c-1},[].concat(i,[T]),a,s)}}}return s},t.allPathExactOut=function(e,n,r,o,i,a,s){var u=(void 0===o?{}:o).maxHops,c=void 0===u?3:u;void 0===i&&(i=[]),void 0===a&&(a=r),void 0===s&&(s=[]),e.length>0||l(!1),c>0||l(!1),a===r||i.length>0||l(!1);var d=r instanceof ht?r.chainId:n instanceof ht?n.chainId:void 0;void 0===d&&l(!1);for(var p=Dt(r,d),h=Dt(n,d),f=0;f<e.length;f++){var T=e[f];if((T.token0.equals(p)||T.token1.equals(p))&&!T.reserve0.equalTo(M)&&!T.reserve1.equalTo(M)){var m=p.equals(T.token0)?T.token1:T.token0;if(m.equals(h))s.push(new _t([T].concat(i),[],[],n,a));else if(c>1&&e.length>1){var v=e.slice(0,f).concat(e.slice(f+1,e.length));t.allPathExactOut(v,n,m,{maxHops:c-1},[T].concat(i),a,s)}}}return s},t}(),Lt=function(){function t(t,e,n,r,o,i,a,s){this.ammAmountIn=t,this.ammAmountOut=e,this.orderAmountIn=n,this.orderAmountOut=r,this.orderFee=o,this.amountLeft=i,this.amountExpect=a,this.priceTo=s}return t.prototype.equalTo=function(t){return!!(this.ammAmountIn||this.ammAmountOut||this.orderAmountIn||this.orderAmountOut||this.amountLeft||this.amountExpect||this.orderFee)&&this.ammAmountIn.equalTo(t.ammAmountIn)&&this.ammAmountOut.equalTo(t.ammAmountOut)&&this.orderAmountIn.equalTo(t.orderAmountIn)&&this.orderAmountOut.equalTo(t.orderAmountOut)&&this.amountLeft.equalTo(t.amountLeft)&&this.amountExpect.equalTo(t.amountExpect)&&this.orderFee.equalTo(t.orderFee)},t}(),Ht=function(){function t(t,e){this.price=t,this.amount=e}var e=t.prototype;return e.lessThan=function(t){return this.price.lessThan(t.price)},e.equalTo=function(t){return this.price.equalTo(t.price)},e.greaterThan=function(t){return this.price.greaterThan(t.price)},t}(),jt=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.route.chainId,r=t.inputAmount.currency===pt[n],o=t.outputAmount.currency===pt[n];r&&o&&l(!1),!("ttl"in e)||e.ttl>0||l(!1);var i,a,s,u=at(e.recipient),c=ot(t.maximumAmountIn(e.allowedSlippage)),d=ot(t.minimumAmountOut(e.allowedSlippage)),p=t.route.path.map((function(t){return t.address})),h="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),f=Boolean(e.feeOnTransfer);switch(t.swapType){case exports.SwapType.EXACT_INPUT:r?(i=f?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",a=[d,p,u,h],s=c):o?(i=f?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",a=[c,d,p,u,h],s="0x0"):(i=f?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",a=[c,d,p,u,h],s="0x0");break;case exports.SwapType.EXACT_OUTPUT:f&&l(!1),r?(i="swapETHForExactTokens",a=[d,p,u,h],s=c):o?(i="swapTokensForExactETH",a=[d,c,p,u,h],s="0x0"):(i="swapTokensForExactTokens",a=[d,c,p,u,h],s="0x0")}return{methodName:i,args:a,value:s}},t}(),Wt=function(){function t(){}return t.tradeCallParameters=function(t,e){var n=t.tradeType,r=t.orderBook.baseToken.token,o=t.orderBook.quoteToken.token,i=r.chainId,a=n===exports.TradeType.LIMIT_BUY&&t.quoteToken===pt[i]||n===exports.TradeType.LIMIT_SELL&&t.baseToken===pt[i];t.baseToken===pt[i]&&r===mt[i]||t.baseToken===r||l(!1),t.quoteToken===pt[i]&&o===mt[i]||t.quoteToken===o||l(!1),(t.quoteToken===pt[i]&&t.baseToken===mt[i]||t.baseToken===pt[i]&&t.quoteToken===mt[i]||t.quoteToken===t.baseToken)&&l(!1),!("ttl"in e)||e.ttl>0||l(!1);var s,u,c,d=at(e.recipient),p=ot(t.amount),h=ot(t.price),f="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16);switch(t.tradeType){case exports.TradeType.LIMIT_BUY:a?(s="buyWithEth",u=[h,r.address,d,f],c=p):(s="buyWithToken",u=[p,h,r.address,o.address,d,f],c="0x0");break;case exports.TradeType.LIMIT_SELL:a?(s="sellEth",u=[h,o.address,d,f],c=p):(s="sellToken",u=[p,h,r.address,o.address,d,f],c="0x0")}return{methodName:s,args:u,value:c}},t}(),Xt=[{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"}],Yt=((Bt={})[exports.ChainId.MAINNET]={},Bt),Zt=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,a,s=function(n){return new ht(t,e,n,r,o)};void 0===n&&(n=k.getDefaultProvider(w.getNetwork(t)));var u="number"==typeof(null===(i=Yt)||void 0===i||null===(a=i[t])||void 0===a?void 0:a[e]);return Promise.resolve(u?s(Yt[t][e]):Promise.resolve(new x.Contract(e,Xt,n).decimals().then((function(n){var r,o,i;return Yt=X({},Yt,((i={})[t]=X({},null===(r=Yt)||void 0===r?void 0:r[t],((o={})[e]=n,o)),i)),n}))).then(s))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e,n){try{void 0===n&&(n=k.getDefaultProvider(w.getNetwork(t.chainId))),t.chainId!==e.chainId&&l(!1);var r=bt.getAddress(t,e);return Promise.resolve(new x.Contract(r,g.abi,n).getReserves()).then((function(n){var r=n[0],o=n[1],i=t.sortsBefore(e)?[r,o]:[o,r];return new bt(new Et(t,i[0]),new Et(e,i[1]))}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=h,exports.CONFIG_ADDRESS=A,exports.Currency=dt,exports.CurrencyAmount=gt,exports.ETHER=pt,exports.FACTORY_ADDRESS=O,exports.Fetcher=Zt,exports.Fraction=wt,exports.INIT_CODE_HASH=b,exports.InsufficientInputAmountError=rt,exports.InsufficientReservesError=nt,exports.MINIMUM_LIQUIDITY=_,exports.ORDER_BOOK_FACTORY_ADDRESS=S,exports.ORDER_BOOK_INIT_CODE_HASH=N,exports.ORDER_NFT_INIT_CODE_HASH=q,exports.Order=Ht,exports.OrderBook=qt,exports.Pair=bt,exports.Percent=Pt,exports.Price=At,exports.Route=_t,exports.Router=jt,exports.Swap=Ft,exports.Token=ht,exports.TokenAmount=Et,exports.Trade=function(t,e,n,r,o,i,a){this.orderBook=t,this.baseToken=n,this.quoteToken=r,this.tradeType=e,this.amount=o,this.price=i,this.tradeRet=a},exports.TradeRet=Lt,exports.Trader=Wt,exports.UserOrder=function(t,e,n,r,o,i,a,s,u,c){this.orderBook=t,this.baseToken=e,this.quoteToken=n,this.owner=r,this.orderId=o,this.price=i,this.amountOffer=a,this.amountLeft=s,this.orderType=u,this.orderIndex=c},exports.WETH=mt,exports.ZERO=M,exports.ZERO_HEX="0x0",exports.currencyEquals=lt,exports.inputOutputComparator=Ct,exports.parseBigintIsh=st,exports.sortedInsert=function(t,e,n,r){if(n>0||l(!1),t.length<=n||l(!1),0===t.length)return t.push(e),null;var o=t.length===n;if(o&&r(t[t.length-1],e)<=0)return e;for(var i=0,a=t.length;i<a;){var s=i+a>>>1;r(t[s],e)<=0?i=s+1:a=s}return t.splice(i,0,e),o?t.pop():null},exports.sqrt=ut,exports.swapComparator=function(t,e){var n=Ct(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},exports.toHex=ot,exports.validChainId=function(t){return t===exports.ChainId.MAINNET.valueOf()||t===exports.ChainId.TESTNET.valueOf()},exports.validateAndParseAddress=at,exports.validateSolidityTypeInstance=it; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n,r,o,i,a,s,u,c,d,p,h=t(require("jsbi")),l=t(require("tiny-invariant")),f=(t(require("tiny-warning")),require("@ethersproject/address")),T=t(require("big.js")),m=t(require("toformat")),v=t(require("decimal.js-light")),I=require("@ethersproject/units"),y=require("@ethersproject/solidity"),x=require("@ethersproject/contracts"),w=require("@ethersproject/networks"),k=require("@ethersproject/providers"),g=t(require("@hybridx-exchange/hybridx-protocol/build/IPair.json"));(u=exports.ChainId||(exports.ChainId={}))[u.MAINNET=42262]="MAINNET",u[u.TESTNET=42261]="TESTNET",u[u.OPTIMISM_MAINNET=10]="OPTIMISM_MAINNET",u[u.OPTIMISM_TESTNET=69]="OPTIMISM_TESTNET",(c=exports.SwapType||(exports.SwapType={}))[c.EXACT_INPUT=0]="EXACT_INPUT",c[c.EXACT_OUTPUT=1]="EXACT_OUTPUT",(d=exports.TradeType||(exports.TradeType={}))[d.LIMIT_BUY=1]="LIMIT_BUY",d[d.LIMIT_SELL=2]="LIMIT_SELL",(p=exports.Rounding||(exports.Rounding={}))[p.ROUND_DOWN=0]="ROUND_DOWN",p[p.ROUND_HALF_UP=1]="ROUND_HALF_UP",p[p.ROUND_UP=2]="ROUND_UP";var E,A=((e={})[exports.ChainId.TESTNET]="0x35bAFF0DC208db7e0701fc16791E5f6871443470",e[exports.ChainId.MAINNET]="",e[exports.ChainId.OPTIMISM_TESTNET]="0xd138C850ADBC2A22846edDb32aaA49E1bE7A8328",e[exports.ChainId.OPTIMISM_MAINNET]="",e),O=((n={})[exports.ChainId.TESTNET]="0x8b466f281C2067a5F40A42daE43350b6A35a0b05",n[exports.ChainId.MAINNET]="",n[exports.ChainId.OPTIMISM_TESTNET]="0xB45070DFD2209eAA070d0103DBA4A8eafa98B600",n[exports.ChainId.OPTIMISM_MAINNET]="",n),S=((r={})[exports.ChainId.TESTNET]="0x581ef0ccd0c15ef0a380cd82bca41249ca81e3c415fdb4fc8f6977e7d4f8c8fa",r[exports.ChainId.MAINNET]="",r[exports.ChainId.OPTIMISM_TESTNET]="0x0f027b89f245ef5d0afabf8e7f8fa4ba3bd7d22d6931d627ea006047b4a3ed9b",r[exports.ChainId.OPTIMISM_MAINNET]="",r),b=((o={})[exports.ChainId.TESTNET]="0xA9a06cf12AE3514b101D426797D190b79B335Eb2",o[exports.ChainId.MAINNET]="",o[exports.ChainId.OPTIMISM_TESTNET]="0xb0E2E28CA39805d7fe31E9588ff0d04f3F3A10d8",o[exports.ChainId.OPTIMISM_MAINNET]="",o),N=((i={})[exports.ChainId.TESTNET]="0x1da881d372a03ec2bce6e0bdc6c5d5696b7e7c47e8632d0bdfb6eb52d80abb48",i[exports.ChainId.MAINNET]="",i[exports.ChainId.OPTIMISM_TESTNET]="0x98e1887b07cfd3ea509868639339574d566b15b7ac2765aec4742be87de6a67a",i[exports.ChainId.OPTIMISM_MAINNET]="",i),q=((a={})[exports.ChainId.TESTNET]="0x374d19331443638013ff34b50550a36e2622d2839fe244467678500262d11f40",a[exports.ChainId.MAINNET]="",a[exports.ChainId.OPTIMISM_TESTNET]="0x374d19331443638013ff34b50550a36e2622d2839fe244467678500262d11f40",a[exports.ChainId.OPTIMISM_MAINNET]="",a),_=h.BigInt(1e3),M=h.BigInt(0),P=h.BigInt(1),C=h.BigInt(2),R=h.BigInt(3),D=h.BigInt(5),U=h.BigInt(10),B=h.BigInt(100),F=h.BigInt(997),L=h.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(E||(E={}));var H=((s={})[E.uint8]=h.BigInt("0xff"),s[E.uint256]=h.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),s);function j(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function W(t,e,n){return e&&j(t.prototype,e),n&&j(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function X(){return(X=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function Y(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,K(t,e)}function Z(t){return(Z=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function K(t,e){return(K=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function Q(){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 G(t,e,n){return(G=Q()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&K(o,n.prototype),o}).apply(null,arguments)}function J(t){var e="function"==typeof Map?new Map:void 0;return(J=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return G(t,arguments,Z(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),K(n,t)})(t)}function V(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function $(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 z(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 $(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)?$(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 tt,et="setPrototypeOf"in Object,nt=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,et&&Object.setPrototypeOf(V(n),(this instanceof e?this.constructor:void 0).prototype),n}return Y(e,t),e}(J(Error)),rt=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,et&&Object.setPrototypeOf(V(n),(this instanceof e?this.constructor:void 0).prototype),n}return Y(e,t),e}(J(Error));function ot(t){return"0x"+t.raw.toString(16)}function it(t,e){h.greaterThanOrEqual(t,M)||l(!1),h.lessThanOrEqual(t,H[e])||l(!1)}function at(t){try{return f.getAddress(t)}catch(t){l(!1)}}function st(t){return t instanceof h?t:h.BigInt("bigint"==typeof t?t.toString():t)}function ut(t){it(t,E.uint256);var e,n=M;if(h.greaterThan(t,R))for(n=t,e=h.add(h.divide(t,C),P);h.lessThan(e,n);)n=e,e=h.divide(h.add(h.divide(t,e),e),C);else h.notEqual(t,M)&&(n=P);return n}var ct,dt=function(t,e,n){it(h.BigInt(t),E.uint8),this.decimals=t,this.symbol=e,this.name=n},pt=dt.ETHER=((tt={})[exports.ChainId.TESTNET]=new dt(18,"ROSE","ROSE"),tt[exports.ChainId.MAINNET]=new dt(18,"ROSE","ROSE"),tt[exports.ChainId.OPTIMISM_MAINNET]=new dt(18,"ETH","ETH"),tt[exports.ChainId.OPTIMISM_TESTNET]=new dt(18,"ETH","ETH"),tt),ht=function(t){function e(e,n,r,o,i){var a;return(a=t.call(this,r,o,i)||this).chainId=e,a.address=at(n),a}Y(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&&l(!1),this.address===t.address&&l(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(dt);function lt(t,e){return t instanceof ht&&e instanceof ht?t.equals(e):!(t instanceof ht||e instanceof ht||t!==e)}var ft,Tt,mt=((ct={})[exports.ChainId.MAINNET]=new ht(exports.ChainId.MAINNET,"0xb9ab821f7323dB4357Bf71eA66670C01761c3d73",18,"WROSE","Wrapped ROSE"),ct[exports.ChainId.TESTNET]=new ht(exports.ChainId.TESTNET,"0xb9ab821f7323dB4357Bf71eA66670C01761c3d73",18,"WROSE","Wrapped ROSE"),ct[exports.ChainId.OPTIMISM_TESTNET]=new ht(exports.ChainId.OPTIMISM_TESTNET,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped ETH"),ct[exports.ChainId.OPTIMISM_MAINNET]=new ht(exports.ChainId.OPTIMISM_MAINNET,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped ETH"),ct),vt=m(v),It=m(T),yt=((ft={})[exports.Rounding.ROUND_DOWN]=vt.ROUND_DOWN,ft[exports.Rounding.ROUND_HALF_UP]=vt.ROUND_HALF_UP,ft[exports.Rounding.ROUND_UP]=vt.ROUND_UP,ft),xt=((Tt={})[exports.Rounding.ROUND_DOWN]=0,Tt[exports.Rounding.ROUND_HALF_UP]=1,Tt[exports.Rounding.ROUND_UP]=3,Tt),wt=function(){function t(t,e){void 0===e&&(e=P),this.numerator=st(t),this.denominator=st(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(st(e));return h.equal(this.denominator,n.denominator)?new t(h.add(this.numerator,n.numerator),this.denominator):new t(h.add(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator)),h.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=e instanceof t?e:new t(st(e));return h.equal(this.denominator,n.denominator)?new t(h.subtract(this.numerator,n.numerator),this.denominator):new t(h.subtract(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator)),h.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=e instanceof t?e:new t(st(e));return h.lessThan(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=e instanceof t?e:new t(st(e));return h.equal(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=e instanceof t?e:new t(st(e));return h.greaterThan(h.multiply(this.numerator,n.denominator),h.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=e instanceof t?e:new t(st(e));return new t(h.multiply(this.numerator,n.numerator),h.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=e instanceof t?e:new t(st(e));return new t(h.multiply(this.numerator,n.denominator),h.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)||l(!1),t>0||l(!1),vt.set({precision:t+1,rounding:yt[n]});var r=new vt(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)||l(!1),t>=0||l(!1),It.DP=t,It.RM=xt[n],new It(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},W(t,[{key:"quotient",get:function(){return h.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(h.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),kt=m(T),gt=function(t){function e(e,n){var r,o=st(n);return it(o,E.uint256),(r=t.call(this,o,h.exponentiate(U,h.BigInt(e.decimals)))||this).currency=e,r}Y(e,t),e.ether=function(t,n){return new e(pt[n],t)};var n=e.prototype;return n.add=function(t){return lt(this.currency,t.currency)||l(!1),new e(this.currency,h.add(this.raw,t.raw))},n.subtract=function(t){return lt(this.currency,t.currency)||l(!1),new e(this.currency,h.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||l(!1),t.prototype.toFixed.call(this,e,n,r)},n.toFixedWithoutExtraZero=function(n,r,o){void 0===n&&(n=this.currency.decimals),void 0===o&&(o=exports.Rounding.ROUND_DOWN),n<=this.currency.decimals||l(!1);var i=t.prototype.toFixed.call(this,n,r,o);return new e(this.currency,I.parseUnits(i,this.currency.decimals).toString()).toExact(r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),kt.DP=this.currency.decimals,new kt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},W(e,[{key:"raw",get:function(){return this.numerator}}]),e}(wt),Et=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}Y(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||l(!1),new e(this.token,h.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||l(!1),new e(this.token,h.subtract(this.raw,t.raw))},e}(gt),At=function(t){function e(e,n,r,o){var i;return(i=t.call(this,o,r)||this).baseCurrency=e,i.quoteCurrency=n,i.scalar=new wt(h.exponentiate(U,h.BigInt(e.decimals)),h.exponentiate(U,h.BigInt(n.decimals))),i}Y(e,t),e.fromRoute=function(t){for(var n,r=[],o=z(t.pairs.entries());!(n=o()).done;){var i=n.value,a=i[1];r.push(t.path[i[0]].equals(a.token0)?new e(a.reserve0.currency,a.reserve1.currency,a.reserve0.raw,a.reserve1.raw):new e(a.reserve1.currency,a.reserve0.currency,a.reserve1.raw,a.reserve0.raw))}return r.slice(1).reduce((function(t,e){return t.multiply(e)}),r[0])};var n=e.prototype;return n.invert=function(){return new e(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},n.multiply=function(n){lt(this.quoteCurrency,n.baseCurrency)||l(!1);var r=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,r.denominator,r.numerator)},n.quote=function(e,n){return lt(e.currency,this.baseCurrency)||l(!1),this.quoteCurrency instanceof ht?new Et(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):gt.ether(t.prototype.multiply.call(this,e.raw).quotient,n)},n.toSignificant=function(t,e,n){return void 0===t&&(t=6),this.adjusted.toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=4),this.adjusted.toFixed(t,e,n)},W(e,[{key:"raw",get:function(){return new wt(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(wt),Ot={},St=function(){function t(e,n){var r=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new ht(r[0].token.chainId,t.getAddress(r[0].token,r[1].token),18,"LPT","HybridX LP Token"),this.tokenAmounts=r}t.getAddress=function(t,e){var n,r,o,i,a,s,u,c,d,p=t.sortsBefore(e)?[t,e]:[e,t],h=t.chainId;return void 0===(null===(n=Ot)||void 0===n||null===(r=n[h])||void 0===r||null===(o=r[p[0].address])||void 0===o?void 0:o[p[1].address])&&(Ot=X({},Ot,((d={})[h]=X({},null===(i=Ot)||void 0===i?void 0:i[h],((c={})[p[0].address]=X({},null===(a=Ot)||void 0===a||null===(s=a[h])||void 0===s?void 0:s[p[0].address],((u={})[p[1].address]=f.getCreate2Address(O[h],y.keccak256(["bytes"],[y.pack(["address","address"],[p[0].address,p[1].address])]),S[h]),u)),c)),d))),Ot[h][p[0].address][p[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)||l(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||l(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||l(!1),h.equal(this.reserve0.raw,M)||h.equal(this.reserve1.raw,M))throw new nt;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=h.multiply(e.raw,F),i=h.multiply(o,r.raw),a=h.add(h.multiply(n.raw,L),o),s=new Et(e.token.equals(this.token0)?this.token1:this.token0,h.divide(i,a));if(h.equal(s.raw,M))throw new rt;return[s,new t(n.add(e),r.subtract(s))]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||l(!1),h.equal(this.reserve0.raw,M)||h.equal(this.reserve1.raw,M)||h.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new nt;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=h.multiply(h.multiply(r.raw,e.raw),L),i=h.multiply(h.subtract(n.raw,e.raw),F),a=new Et(e.token.equals(this.token0)?this.token1:this.token0,h.add(h.divide(o,i),P));return[a,new t(r.add(a),n.subtract(e))]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||l(!1);var r,o=e.token.sortsBefore(n.token)?[e,n]:[n,e];if(o[0].token.equals(this.token0)&&o[1].token.equals(this.token1)||l(!1),h.equal(t.raw,M))r=h.subtract(ut(h.multiply(o[0].raw,o[1].raw)),_);else{var i=h.divide(h.multiply(o[0].raw,t.raw),this.reserve0.raw),a=h.divide(h.multiply(o[1].raw,t.raw),this.reserve1.raw);r=h.lessThanOrEqual(i,a)?i:a}if(!h.greaterThan(r,M))throw new rt;return new Et(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var i;if(void 0===r&&(r=!1),this.involvesToken(t)||l(!1),e.token.equals(this.liquidityToken)||l(!1),n.token.equals(this.liquidityToken)||l(!1),h.lessThanOrEqual(n.raw,e.raw)||l(!1),r){o||l(!1);var a=st(o);if(h.equal(a,M))i=e;else{var s=ut(h.multiply(this.reserve0.raw,this.reserve1.raw)),u=ut(a);if(h.greaterThan(s,u)){var c=h.multiply(e.raw,h.subtract(s,u)),d=h.add(h.multiply(s,D),u),p=h.divide(c,d);i=e.add(new Et(this.liquidityToken,p))}else i=e}}else i=e;return new Et(t,h.divide(h.multiply(n.raw,this.reserveOf(t).raw),i.raw))},W(t,[{key:"token0Price",get:function(){return new At(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new At(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}(),bt={},Nt={},qt=function(){function t(e,n,r,o,i,a,s,u,c,d,p,h){this.exist=e,this.orderBookAddress=t.getAddress(n.token,r.token),this.baseToken=n,this.quoteToken=r,this.baseSignificantDigits=o<n.token.decimals?o:n.token.decimals,this.quoteSignificantDigits=i<r.token.decimals?i:r.token.decimals,this.priceStepFactor=s,this.priceStep=a,this.protocolFeeRate=u,this.subsidyFeeRate=c,this.curPrice=d,this.buyOrders=p,this.sellOrders=h}t.getAddress=function(t,e){var n,r,o,i,a,s,u,c,d,p=t.sortsBefore(e)?[t,e]:[e,t],h=t.chainId;return void 0===(null===(n=bt)||void 0===n||null===(r=n[h])||void 0===r||null===(o=r[p[0].address])||void 0===o?void 0:o[p[1].address])&&(bt=X({},bt,((d={})[h]=X({},null===(i=bt)||void 0===i?void 0:i[h],((c={})[p[0].address]=X({},null===(a=bt)||void 0===a||null===(s=a[h])||void 0===s?void 0:s[p[0].address],((u={})[p[1].address]=f.getCreate2Address(b[h],y.keccak256(["bytes"],[y.pack(["address","address"],[p[0].address,p[1].address])]),N[h]),u)),c)),d))),bt[h][p[0].address][p[1].address]},t.getNFTAddress=function(e,n){var r,o,i,a,s,u,c,d,p,h=e.sortsBefore(n)?[e,n]:[n,e],l=e.chainId;return void 0===(null===(r=Nt)||void 0===r||null===(o=r[l])||void 0===o||null===(i=o[h[0].address])||void 0===i?void 0:i[h[1].address])&&(Nt=X({},Nt,((p={})[l]=X({},null===(a=Nt)||void 0===a?void 0:a[l],((d={})[h[0].address]=X({},null===(s=Nt)||void 0===s||null===(u=s[l])||void 0===u?void 0:u[h[0].address],((c={})[h[1].address]=f.getCreate2Address(b[l],y.keccak256(["bytes"],[y.pack(["address","address","address"],[t.getAddress(e,n),h[0].address,h[1].address])]),q[l]),c)),d)),p))),Nt[l][h[0].address][h[1].address]},t.culPrice=function(t,e){if(t&&e){var n=st(t.raw),r=st(e.raw),o=st(I.parseUnits("1",t.token.decimals).toString()),i=e.token,a=h.divide(h.multiply(r,o),n);return new Et(i,a)}};var e=t.prototype;return e.getPriceStep=function(t){return!this.priceStep||h.EQ(st(this.priceStep),st("0"))?h.lessThanOrEqual(st(t),h.BigInt(1e4))?h.BigInt(1e4):h.multiply(h.divide(st(t),h.BigInt(1e4)),st(this.priceStepFactor)):this.priceStep},e.getPriceStepDecimal=function(){return this.quoteSignificantDigits},e.getMinAmountDecimal=function(t){return t===exports.TradeType.LIMIT_BUY?this.quoteSignificantDigits:t===exports.TradeType.LIMIT_SELL?this.baseSignificantDigits:18},e.getMinOutputAmountDecimal=function(t){return t===exports.TradeType.LIMIT_SELL?this.quoteSignificantDigits:t===exports.TradeType.LIMIT_BUY?this.baseSignificantDigits:18},t}(),_t=function(){function t(t,e,n,r,o){t.length>0||l(!1),t.every((function(e){return e.chainId===t[0].chainId}))||l(!1);var i=t[0].chainId;r instanceof ht&&t[0].involvesToken(r)||r===pt[i]&&t[0].involvesToken(mt[i])||l(!1),void 0===o||o instanceof ht&&t[t.length-1].involvesToken(o)||o===pt[i]&&t[t.length-1].involvesToken(mt[i])||l(!1);for(var a,s=[r instanceof ht?r:mt[i]],u=z(t.entries());!(a=u()).done;){var c=a.value,d=c[1],p=s[c[0]];p.equals(d.token0)||p.equals(d.token1)||l(!1);var h=p.equals(d.token0)?d.token1:d.token0;s.push(h)}this.pairs=t,this.path=s,this.amounts=e,this.extra=n,this.midPrice=At.fromRoute(this),this.input=r,this.output=null!=o?o:s[s.length-1]}return W(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),Mt=new wt(B),Pt=function(t){function e(){return t.apply(this,arguments)||this}Y(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(Mt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(Mt).toFixed(t,e,n)},e}(wt);function Ct(t,e){return lt(t.inputAmount.currency,e.inputAmount.currency)||l(!1),lt(t.outputAmount.currency,e.outputAmount.currency)||l(!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 Rt(t,e){return t instanceof Et?t:t.currency===pt[e]?new Et(mt[e],t.raw):void l(!1)}function Dt(t,e){return t instanceof ht?t:t===pt[e]?mt[e]:void l(!1)}function Ut(t,e){return new Et(t.token,e)}var Bt,Ft=function(){function t(t,e,n){var r=new Array(t.path.length),o=new Array(t.pairs.length),i=t.chainId;if(t.amounts.length!==t.path.length&&l(!1),n===exports.SwapType.EXACT_INPUT){lt(e.currency,t.input)||l(!1),r[0]=Rt(e,t.chainId);for(var a=0;a<t.path.length-1;a++){var s=t.pairs[a],u=r[a].token.equals(s.token0)?s.token1:s.token0,c=new Et(u,t.amounts[a+1]),d=new St(Ut(r[a],t.extra[6*a]),Ut(c,t.extra[6*a+1]));r[a+1]=c,o[a]=d}}else{lt(e.currency,t.output)||l(!1),r[r.length-1]=Rt(e,t.chainId);for(var p=t.path.length-1;p>0;p--){var h=t.pairs[p-1],f=r[p].token.equals(h.token0)?h.token1:h.token0,T=new Et(f,t.amounts[p-1]),m=new St(Ut(T,t.extra[6*(p-1)]),Ut(r[p],t.extra[6*(p-1)+1]));r[p-1]=T,o[p-1]=m}}this.route=t,this.swapType=n,this.inputAmount=n===exports.SwapType.EXACT_INPUT?e:t.input===pt[i]?gt.ether(r[0].raw,i):r[0],this.outputAmount=n===exports.SwapType.EXACT_OUTPUT?e:t.output===pt[i]?gt.ether(r[r.length-1].raw,i):r[r.length-1],this.executionPrice=new At(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=At.fromRoute(new _t(o,[],[],t.input)),this.priceImpact=function(t,e,n){var r=t.raw.multiply(e.raw),o=r.subtract(n.raw).divide(r);return new Pt(o.numerator,o.denominator)}(t.midPrice,this.inputAmount,this.outputAmount)}t.exactIn=function(e,n){return new t(e,n,exports.SwapType.EXACT_INPUT)},t.exactOut=function(e,n){return new t(e,n,exports.SwapType.EXACT_OUTPUT)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(M)&&l(!1),this.swapType===exports.SwapType.EXACT_OUTPUT)return this.outputAmount;var e=new wt(P).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof Et?new Et(this.outputAmount.token,e):gt.ether(e,this.route.chainId)},e.maximumAmountIn=function(t){if(t.lessThan(M)&&l(!1),this.swapType===exports.SwapType.EXACT_INPUT)return this.inputAmount;var e=new wt(P).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof Et?new Et(this.inputAmount.token,e):gt.ether(e,this.route.chainId)},t.allPathExactIn=function(e,n,r,o,i,a,s){var u=(void 0===o?{}:o).maxHops,c=void 0===u?3:u;void 0===i&&(i=[]),void 0===a&&(a=n),void 0===s&&(s=[]),e.length>0||l(!1),c>0||l(!1),a===n||i.length>0||l(!1);var d=n instanceof ht?n.chainId:r instanceof ht?r.chainId:void 0;void 0===d&&l(!1);for(var p=Dt(n,d),h=Dt(r,d),f=0;f<e.length;f++){var T=e[f];if((T.token0.equals(p)||T.token1.equals(p))&&!T.reserve0.equalTo(M)&&!T.reserve1.equalTo(M)){var m=p.equals(T.token0)?T.token1:T.token0;if(m.equals(h))s.push(new _t([].concat(i,[T]),[],[],a,r));else if(c>1&&e.length>1){var v=e.slice(0,f).concat(e.slice(f+1,e.length));t.allPathExactIn(v,m,r,{maxHops:c-1},[].concat(i,[T]),a,s)}}}return s},t.allPathExactOut=function(e,n,r,o,i,a,s){var u=(void 0===o?{}:o).maxHops,c=void 0===u?3:u;void 0===i&&(i=[]),void 0===a&&(a=r),void 0===s&&(s=[]),e.length>0||l(!1),c>0||l(!1),a===r||i.length>0||l(!1);var d=r instanceof ht?r.chainId:n instanceof ht?n.chainId:void 0;void 0===d&&l(!1);for(var p=Dt(r,d),h=Dt(n,d),f=0;f<e.length;f++){var T=e[f];if((T.token0.equals(p)||T.token1.equals(p))&&!T.reserve0.equalTo(M)&&!T.reserve1.equalTo(M)){var m=p.equals(T.token0)?T.token1:T.token0;if(m.equals(h))s.push(new _t([T].concat(i),[],[],n,a));else if(c>1&&e.length>1){var v=e.slice(0,f).concat(e.slice(f+1,e.length));t.allPathExactOut(v,n,m,{maxHops:c-1},[T].concat(i),a,s)}}}return s},t}(),Lt=function(){function t(t,e,n,r,o,i,a,s){this.ammAmountIn=t,this.ammAmountOut=e,this.orderAmountIn=n,this.orderAmountOut=r,this.orderFee=o,this.amountLeft=i,this.amountExpect=a,this.priceTo=s}return t.prototype.equalTo=function(t){return!!(this.ammAmountIn||this.ammAmountOut||this.orderAmountIn||this.orderAmountOut||this.amountLeft||this.amountExpect||this.orderFee)&&this.ammAmountIn.equalTo(t.ammAmountIn)&&this.ammAmountOut.equalTo(t.ammAmountOut)&&this.orderAmountIn.equalTo(t.orderAmountIn)&&this.orderAmountOut.equalTo(t.orderAmountOut)&&this.amountLeft.equalTo(t.amountLeft)&&this.amountExpect.equalTo(t.amountExpect)&&this.orderFee.equalTo(t.orderFee)},t}(),Ht=function(){function t(t,e){this.price=t,this.amount=e}var e=t.prototype;return e.lessThan=function(t){return this.price.lessThan(t.price)},e.equalTo=function(t){return this.price.equalTo(t.price)},e.greaterThan=function(t){return this.price.greaterThan(t.price)},t}(),jt=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.route.chainId,r=t.inputAmount.currency===pt[n],o=t.outputAmount.currency===pt[n];r&&o&&l(!1),!("ttl"in e)||e.ttl>0||l(!1);var i,a,s,u=at(e.recipient),c=ot(t.maximumAmountIn(e.allowedSlippage)),d=ot(t.minimumAmountOut(e.allowedSlippage)),p=t.route.path.map((function(t){return t.address})),h="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),f=Boolean(e.feeOnTransfer);switch(t.swapType){case exports.SwapType.EXACT_INPUT:r?(i=f?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",a=[d,p,u,h],s=c):o?(i=f?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",a=[c,d,p,u,h],s="0x0"):(i=f?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",a=[c,d,p,u,h],s="0x0");break;case exports.SwapType.EXACT_OUTPUT:f&&l(!1),r?(i="swapETHForExactTokens",a=[d,p,u,h],s=c):o?(i="swapTokensForExactETH",a=[d,c,p,u,h],s="0x0"):(i="swapTokensForExactTokens",a=[d,c,p,u,h],s="0x0")}return{methodName:i,args:a,value:s}},t}(),Wt=function(){function t(){}return t.tradeCallParameters=function(t,e){var n=t.tradeType,r=t.orderBook.baseToken.token,o=t.orderBook.quoteToken.token,i=r.chainId,a=n===exports.TradeType.LIMIT_BUY&&t.quoteToken===pt[i]||n===exports.TradeType.LIMIT_SELL&&t.baseToken===pt[i];t.baseToken===pt[i]&&r===mt[i]||t.baseToken===r||l(!1),t.quoteToken===pt[i]&&o===mt[i]||t.quoteToken===o||l(!1),(t.quoteToken===pt[i]&&t.baseToken===mt[i]||t.baseToken===pt[i]&&t.quoteToken===mt[i]||t.quoteToken===t.baseToken)&&l(!1),!("ttl"in e)||e.ttl>0||l(!1);var s,u,c,d=at(e.recipient),p=ot(t.amount),h=ot(t.price),f="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16);switch(t.tradeType){case exports.TradeType.LIMIT_BUY:a?(s="buyWithEth",u=[h,r.address,d,f],c=p):(s="buyWithToken",u=[p,h,r.address,o.address,d,f],c="0x0");break;case exports.TradeType.LIMIT_SELL:a?(s="sellEth",u=[h,o.address,d,f],c=p):(s="sellToken",u=[p,h,r.address,o.address,d,f],c="0x0")}return{methodName:s,args:u,value:c}},t}(),Xt=[{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"}],Yt=((Bt={})[exports.ChainId.MAINNET]={},Bt),Zt=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,a,s=function(n){return new ht(t,e,n,r,o)};void 0===n&&(n=k.getDefaultProvider(w.getNetwork(t)));var u="number"==typeof(null===(i=Yt)||void 0===i||null===(a=i[t])||void 0===a?void 0:a[e]);return Promise.resolve(u?s(Yt[t][e]):Promise.resolve(new x.Contract(e,Xt,n).decimals().then((function(n){var r,o,i;return Yt=X({},Yt,((i={})[t]=X({},null===(r=Yt)||void 0===r?void 0:r[t],((o={})[e]=n,o)),i)),n}))).then(s))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e,n){try{void 0===n&&(n=k.getDefaultProvider(w.getNetwork(t.chainId))),t.chainId!==e.chainId&&l(!1);var r=St.getAddress(t,e);return Promise.resolve(new x.Contract(r,g.abi,n).getReserves()).then((function(n){var r=n[0],o=n[1],i=t.sortsBefore(e)?[r,o]:[o,r];return new St(new Et(t,i[0]),new Et(e,i[1]))}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=h,exports.CONFIG_ADDRESS=A,exports.Currency=dt,exports.CurrencyAmount=gt,exports.ETHER=pt,exports.FACTORY_ADDRESS=O,exports.Fetcher=Zt,exports.Fraction=wt,exports.INIT_CODE_HASH=S,exports.InsufficientInputAmountError=rt,exports.InsufficientReservesError=nt,exports.MINIMUM_LIQUIDITY=_,exports.ORDER_BOOK_FACTORY_ADDRESS=b,exports.ORDER_BOOK_INIT_CODE_HASH=N,exports.ORDER_NFT_INIT_CODE_HASH=q,exports.Order=Ht,exports.OrderBook=qt,exports.Pair=St,exports.Percent=Pt,exports.Price=At,exports.Route=_t,exports.Router=jt,exports.Swap=Ft,exports.Token=ht,exports.TokenAmount=Et,exports.Trade=function(t,e,n,r,o,i,a){this.orderBook=t,this.baseToken=n,this.quoteToken=r,this.tradeType=e,this.amount=o,this.price=i,this.tradeRet=a},exports.TradeRet=Lt,exports.Trader=Wt,exports.UserOrder=function(t,e,n,r,o,i,a,s,u,c){this.orderBook=t,this.baseToken=e,this.quoteToken=n,this.owner=r,this.orderId=o,this.price=i,this.amountOffer=a,this.amountLeft=s,this.orderType=u,this.orderIndex=c},exports.WETH=mt,exports.ZERO=M,exports.ZERO_HEX="0x0",exports.currencyEquals=lt,exports.inputOutputComparator=Ct,exports.parseBigintIsh=st,exports.sortedInsert=function(t,e,n,r){if(n>0||l(!1),t.length<=n||l(!1),0===t.length)return t.push(e),null;var o=t.length===n;if(o&&r(t[t.length-1],e)<=0)return e;for(var i=0,a=t.length;i<a;){var s=i+a>>>1;r(t[s],e)<=0?i=s+1:a=s}return t.splice(i,0,e),o?t.pop():null},exports.sqrt=ut,exports.swapComparator=function(t,e){var n=Ct(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},exports.toHex=ot,exports.validChainId=function(t){return t===exports.ChainId.MAINNET.valueOf()||t===exports.ChainId.TESTNET.valueOf()},exports.validateAndParseAddress=at,exports.validateSolidityTypeInstance=it; | ||
//# sourceMappingURL=hybridx-sdk.cjs.production.min.js.map |
{ | ||
"name": "@hybridx-exchange/hybridx-sdk", | ||
"license": "GPL-3.0-or-later", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "🛠 An SDK for building applications on top of HybridX.", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package