UNPKG

@sonicxchain/soxswap-sdk

Version:

An SDK for building applications on top of Soxswap.

3 lines (2 loc) 25.1 kB
"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,u,a,s,c,d=t(require("jsbi")),p=t(require("tiny-invariant")),l=require("@sonicxchain/sonicxscan-cli/src/utils/crypto"),f=t(require("big.js")),h=t(require("toformat")),m=t(require("decimal.js-light")),v=require("@ethersproject/solidity"),y=t(require("@sonicxchain/soxswap-core/build/contracts/ISoxswapPair.json"));(a=exports.ChainId||(exports.ChainId={}))[a.MAINNET=1]="MAINNET",a[a.TESTNET=2]="TESTNET",(s=exports.TradeType||(exports.TradeType={}))[s.EXACT_INPUT=0]="EXACT_INPUT",s[s.EXACT_OUTPUT=1]="EXACT_OUTPUT",(c=exports.Rounding||(exports.Rounding={}))[c.ROUND_DOWN=0]="ROUND_DOWN",c[c.ROUND_HALF_UP=1]="ROUND_HALF_UP",c[c.ROUND_UP=2]="ROUND_UP";var T,w=((e={})[exports.ChainId.MAINNET]="Sd6Dx2FgME6rZGjSjNxSRidefA8kyZFVvz",e[exports.ChainId.TESTNET]="SRPppHHX2AMw8G54Xi9g85fd4eYm4kX9rK",e),x=((n={})[exports.ChainId.MAINNET]="SQkzjQfm1TZwe56bNBLeNVKxZTTgrB4Cus",n[exports.ChainId.TESTNET]="Sji4tHWLUkmTe14BwqPGAh7YmexHuEFESu",n),g=((r={})[exports.ChainId.MAINNET]="SgJv9bDBRXUDMvGvqs16DYjZAK7SCTwXP6",r[exports.ChainId.TESTNET]="SYa6wyc5UZeAu5NtbhKJ8Ujm8tdiSmTTQ7",r),k=((o={})[exports.ChainId.MAINNET]="0xf981e577ad59b44db8b24e8fb96dfd1be7e8630d20fd32724894cf23f48b0765",o[exports.ChainId.TESTNET]="0x5f316048a12ee51e3cdb82f0940408f1c068427996ebcebaba0de2834c255b0d",o),I=d.BigInt(1e3),A=d.BigInt(0),O=d.BigInt(1),b=d.BigInt(2),E=d.BigInt(3),N=d.BigInt(5),S=d.BigInt(10),q=d.BigInt(100),P=d.BigInt(997),_=d.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(T||(T={}));var U=((i={})[T.uint8]=d.BigInt("0xff"),i[T.uint256]=d.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),i),C=require("sonicxweb"),R="D8B708BFFFA424473D83349CF4C6A2395E4436E065B60F0BF31E582281256D1C",D=((u={})[exports.ChainId.MAINNET]=new C({fullNode:"https://fullnode.sonicxhub.com",solidityNode:"https://solnode.sonicxhub.com",eventServer:"https://event.sonicxhub.com/",privateKey:R}),u[exports.ChainId.TESTNET]=new C({fullNode:"https://fullnode-testnet.sonicxhub.com",solidityNode:"https://solnode-testnet.sonicxhub.com",eventServer:"https://event-testnet.sonicxhub.com/",privateKey:R}),u);function F(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 X(t,e,n){return e&&F(t.prototype,e),n&&F(t,n),t}function j(){return(j=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 B(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function M(t){return(M=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function L(t,e){return(L=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function H(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function W(t,e,n){return(W=H()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&L(o,n.prototype),o}).apply(null,arguments)}function Y(t){var e="function"==typeof Map?new Map:void 0;return(Y=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 W(t,arguments,M(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),L(n,t)})(t)}function K(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Q(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;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Q(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)?Q(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}var G="setPrototypeOf"in Object,V=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,G&&Object.setPrototypeOf(K(n),(this instanceof e?this.constructor:void 0).prototype),n}return B(e,t),e}(Y(Error)),J=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,G&&Object.setPrototypeOf(K(n),(this instanceof e?this.constructor:void 0).prototype),n}return B(e,t),e}(Y(Error)),z=function(t){function e(){var n;return(n=t.call(this)||this).isInvalidPairError=!0,n.name=n.constructor.name,G&&Object.setPrototypeOf(K(n),(this instanceof e?this.constructor:void 0).prototype),n}return B(e,t),e}(Y(Error));function $(t,e){d.greaterThanOrEqual(t,A)||p(!1),d.lessThanOrEqual(t,U[e])||p(!1)}function tt(t){return t instanceof d?t:d.BigInt("bigint"==typeof t?t.toString():t)}function et(t){$(t,T.uint256);var e,n=A;if(d.greaterThan(t,E))for(n=t,e=d.add(d.divide(t,b),O);d.lessThan(e,n);)n=e,e=d.divide(d.add(d.divide(t,e),e),b);else d.notEqual(t,A)&&(n=O);return n}function nt(t,e,n,r){if(n>0||p(!1),t.length<=n||p(!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,u=t.length;i<u;){var a=i+u>>>1;r(t[a],e)<=0?i=a+1:u=a}return t.splice(i,0,e),o?t.pop():null}var rt=function(){function t(t,e,n){$(d.BigInt(t),T.uint8),this.decimals=t,this.symbol=e,this.name=n}return t.prototype.isLiquidityToken=function(){return"Soxswap"===this.name&&"SXW"===this.symbol&&8==this.decimals},t}();rt.SOX=new rt(6,"SOX","SonicX");var ot,it=rt.SOX,ut=function(t){if(l.isAddressValid(t))return t;p(!1)},at=function(t){function e(e,n,r,o,i){var u;return(u=t.call(this,r,o,i)||this).chainId=e,u.address=ut(n),u}B(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&&p(!1),this.address===t.address&&p(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(rt);function st(t,e){return t instanceof at&&e instanceof at?t.equals(e):!(t instanceof at||e instanceof at||t!==e)}var ct,dt,pt=((ot={})[exports.ChainId.MAINNET]=new at(exports.ChainId.MAINNET,g[exports.ChainId.MAINNET],6,"WSOX","Internal Wrapped SOX"),ot[exports.ChainId.TESTNET]=new at(exports.ChainId.TESTNET,g[exports.ChainId.TESTNET],6,"WSOX","Internal Wrapped SOX"),ot),lt=h(m),ft=h(f),ht=((ct={})[exports.Rounding.ROUND_DOWN]=lt.ROUND_DOWN,ct[exports.Rounding.ROUND_HALF_UP]=lt.ROUND_HALF_UP,ct[exports.Rounding.ROUND_UP]=lt.ROUND_UP,ct),mt=((dt={})[exports.Rounding.ROUND_DOWN]=0,dt[exports.Rounding.ROUND_HALF_UP]=1,dt[exports.Rounding.ROUND_UP]=3,dt),vt=function(){function t(t,e){void 0===e&&(e=O),this.numerator=tt(t),this.denominator=tt(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(tt(e));return d.equal(this.denominator,n.denominator)?new t(d.add(this.numerator,n.numerator),this.denominator):new t(d.add(d.multiply(this.numerator,n.denominator),d.multiply(n.numerator,this.denominator)),d.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=e instanceof t?e:new t(tt(e));return d.equal(this.denominator,n.denominator)?new t(d.subtract(this.numerator,n.numerator),this.denominator):new t(d.subtract(d.multiply(this.numerator,n.denominator),d.multiply(n.numerator,this.denominator)),d.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=e instanceof t?e:new t(tt(e));return d.lessThan(d.multiply(this.numerator,n.denominator),d.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=e instanceof t?e:new t(tt(e));return d.equal(d.multiply(this.numerator,n.denominator),d.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=e instanceof t?e:new t(tt(e));return d.greaterThan(d.multiply(this.numerator,n.denominator),d.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=e instanceof t?e:new t(tt(e));return new t(d.multiply(this.numerator,n.numerator),d.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=e instanceof t?e:new t(tt(e));return new t(d.multiply(this.numerator,n.denominator),d.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)||p(!1),t>0||p(!1),lt.set({precision:t+1,rounding:ht[n]});var r=new lt(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)||p(!1),t>=0||p(!1),ft.DP=t,ft.RM=mt[n],new ft(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},X(t,[{key:"quotient",get:function(){return d.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(d.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),yt=h(f),Tt=function(t){function e(e,n){var r,o=tt(n);return $(o,T.uint256),(r=t.call(this,o,d.exponentiate(S,d.BigInt(e.decimals)))||this).currency=e,r}B(e,t),e.sox=function(t){return new e(it,t)};var n=e.prototype;return n.add=function(t){return st(this.currency,t.currency)||p(!1),new e(this.currency,d.add(this.raw,t.raw))},n.subtract=function(t){return st(this.currency,t.currency)||p(!1),new e(this.currency,d.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||p(!1),t.prototype.toFixed.call(this,e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),yt.DP=this.currency.decimals,new yt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},X(e,[{key:"raw",get:function(){return this.numerator}}]),e}(vt),wt=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}B(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||p(!1),new e(this.token,d.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||p(!1),new e(this.token,d.subtract(this.raw,t.raw))},e}(Tt),xt=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 vt(d.exponentiate(S,d.BigInt(e.decimals)),d.exponentiate(S,d.BigInt(n.decimals))),i}B(e,t),e.fromRoute=function(t){for(var n,r=[],o=Z(t.pairs.entries());!(n=o()).done;){var i=n.value,u=i[1];r.push(t.path[i[0]].equals(u.token0)?new e(u.reserve0.currency,u.reserve1.currency,u.reserve0.raw,u.reserve1.raw):new e(u.reserve1.currency,u.reserve0.currency,u.reserve1.raw,u.reserve0.raw))}return r.slice(1).reduce((function(t,e){return t.multiply(e)}),r[0])};var n=e.prototype;return n.invert=function(){return new e(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},n.multiply=function(n){st(this.quoteCurrency,n.baseCurrency)||p(!1);var r=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,r.denominator,r.numerator)},n.quote=function(e){return st(e.currency,this.baseCurrency)||p(!1),this.quoteCurrency instanceof at?new wt(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):Tt.sox(t.prototype.multiply.call(this,e.raw).quotient)},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)},X(e,[{key:"raw",get:function(){return new vt(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(vt),gt=require("sonicxweb"),kt=/^(3f)/,It={},At=function(){function t(t,e,n){var r=t.token.sortsBefore(e.token)?[t,e]:[e,t];this.liquidityToken=new at(r[0].token.chainId,n,8,"SXW","Soxswap"),this.tokenAmounts=r}t.getAddress=function(e,n){var r,o,i,u=e.sortsBefore(n)?[e,n]:[n,e];if(void 0===(null===(r=It)||void 0===r||null===(o=r[u[0].address])||void 0===o?void 0:o[u[1].address])){var a=t.toEthAddress(u[0].address),s=t.toEthAddress(u[1].address),c=t.toEthAddress(x[e.chainId]);try{var d,p,l,f=v.keccak256(["bytes"],[v.pack(["address","address"],[a,s])]),h=v.keccak256(["bytes","address","bytes","bytes"],["0x3f",c,f,k[e.chainId]]),m="3f"+h.substring(h.length-40),y=gt.address.fromHex(m);It=j({},It,((l={})[u[0].address]=j({},null===(d=It)||void 0===d?void 0:d[u[0].address],((p={})[u[1].address]=y,p)),l))}catch(t){}}return null===(i=It[u[0].address])||void 0===i?void 0:i[u[1].address]},t.toEthAddress=function(t){return gt.address.toHex(t).replace(kt,"0x")},t.NewPair=function(e,n){var r=t.getAddress(e.token,n.token);if(r)return new t(e,n,r)};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)||p(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||p(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||p(!1),d.equal(this.reserve0.raw,A)||d.equal(this.reserve1.raw,A))throw new V;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=d.multiply(e.raw,P),i=d.multiply(o,r.raw),u=d.add(d.multiply(n.raw,_),o),a=new wt(e.token.equals(this.token0)?this.token1:this.token0,d.divide(i,u));if(d.equal(a.raw,A))throw new J;var s=t.NewPair(n.add(e),r.subtract(a));if(!s)throw new z;return[a,s]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||p(!1),d.equal(this.reserve0.raw,A)||d.equal(this.reserve1.raw,A)||d.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new V;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=d.multiply(d.multiply(r.raw,e.raw),_),i=d.multiply(d.subtract(n.raw,e.raw),P),u=new wt(e.token.equals(this.token0)?this.token1:this.token0,d.add(d.divide(o,i),O)),a=t.NewPair(r.add(u),n.subtract(e));if(!a)throw new z;return[u,a]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||p(!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)||p(!1),d.equal(t.raw,A))r=d.subtract(et(d.multiply(o[0].raw,o[1].raw)),I);else{var i=d.divide(d.multiply(o[0].raw,t.raw),this.reserve0.raw),u=d.divide(d.multiply(o[1].raw,t.raw),this.reserve1.raw);r=d.lessThanOrEqual(i,u)?i:u}if(!d.greaterThan(r,A))throw new J;return new wt(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var i;if(void 0===r&&(r=!1),this.involvesToken(t)||p(!1),e.token.equals(this.liquidityToken)||p(!1),n.token.equals(this.liquidityToken)||p(!1),d.lessThanOrEqual(n.raw,e.raw)||p(!1),r){o||p(!1);var u=tt(o);if(d.equal(u,A))i=e;else{var a=et(d.multiply(this.reserve0.raw,this.reserve1.raw)),s=et(u);if(d.greaterThan(a,s)){var c=d.multiply(e.raw,d.subtract(a,s)),l=d.add(d.multiply(a,N),s),f=d.divide(c,l);i=e.add(new wt(this.liquidityToken,f))}else i=e}}else i=e;return new wt(t,d.divide(d.multiply(n.raw,this.reserveOf(t).raw),i.raw))},X(t,[{key:"token0Price",get:function(){return new xt(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new xt(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}(),Ot=function(){function t(t,e,n){t.length>0||p(!1),t.every((function(e){return e.chainId===t[0].chainId}))||p(!1),e instanceof at&&t[0].involvesToken(e)||e===it&&t[0].involvesToken(pt[t[0].chainId])||p(!1),void 0===n||n instanceof at&&t[t.length-1].involvesToken(n)||n===it&&t[t.length-1].involvesToken(pt[t[0].chainId])||p(!1);for(var r,o=[e instanceof at?e:pt[t[0].chainId]],i=Z(t.entries());!(r=i()).done;){var u=r.value,a=u[1],s=o[u[0]];s.equals(a.token0)||s.equals(a.token1)||p(!1);var c=s.equals(a.token0)?a.token1:a.token0;o.push(c)}this.pairs=t,this.path=o,this.midPrice=xt.fromRoute(this),this.input=e,this.output=null!=n?n:o[o.length-1]}return X(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),bt=new vt(q),Et=function(t){function e(){return t.apply(this,arguments)||this}B(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(bt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(bt).toFixed(t,e,n)},e}(vt);function Nt(t,e){return st(t.inputAmount.currency,e.inputAmount.currency)||p(!1),st(t.outputAmount.currency,e.outputAmount.currency)||p(!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 St(t,e){var n=Nt(t,e);return 0!==n?n:t.priceImpact.lessThan(e.priceImpact)?-1:t.priceImpact.greaterThan(e.priceImpact)?1:t.route.path.length-e.route.path.length}function qt(t,e){return t instanceof wt?t:t.currency===it?new wt(pt[e],t.raw):void p(!1)}function Pt(t,e){return t instanceof at?t:t===it?pt[e]:void p(!1)}var _t=function(){function t(t,e,n,r,o){var i,u,a;this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===it?Tt.sox(r[0].raw):r[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===it?Tt.sox(r[r.length-1].raw):r[r.length-1],this.executionPrice=new xt(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=xt.fromRoute(new Ot(o,t.input)),this.priceImpact=(i=this.outputAmount,a=(u=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(i.raw).divide(u),new Et(a.numerator,a.denominator))}t.exactIn=function(e,n){return t.NewTrade(e,n,exports.TradeType.EXACT_INPUT)},t.exactOut=function(e,n){return t.NewTrade(e,n,exports.TradeType.EXACT_OUTPUT)},t.NewTrade=function(e,n,r){var o=new Array(e.path.length),i=new Array(e.pairs.length);if(r===exports.TradeType.EXACT_INPUT){st(n.currency,e.input)||p(!1),o[0]=qt(n,e.chainId);for(var u=0;u<e.path.length-1;u++){var a=e.pairs[u].getOutputAmount(o[u]),s=a[1];o[u+1]=a[0],i[u]=s}}else{st(n.currency,e.output)||p(!1),o[o.length-1]=qt(n,e.chainId);for(var c=e.path.length-1;c>0;c--){var d=e.pairs[c-1].getInputAmount(o[c]),l=d[1];o[c-1]=d[0],i[c-1]=l}}return new t(e,n,r,o,i)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(A)&&p(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new vt(O).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof wt?new wt(this.outputAmount.token,e):Tt.sox(e)},e.maximumAmountIn=function(t){if(t.lessThan(A)&&p(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new vt(O).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof wt?new wt(this.inputAmount.token,e):Tt.sox(e)},t.bestTradeExactIn=function(e,n,r,o,i,u,a){var s=void 0===o?{}:o,c=s.maxNumResults,d=void 0===c?3:c,l=s.maxHops,f=void 0===l?3:l;void 0===i&&(i=[]),void 0===u&&(u=n),void 0===a&&(a=[]),e.length>0||p(!1),f>0||p(!1),u===n||i.length>0||p(!1);var h=n instanceof wt?n.token.chainId:r instanceof at?r.chainId:void 0;void 0===h&&p(!1);for(var m=qt(n,h),v=Pt(r,h),y=0;y<e.length;y++){var T=e[y];if((T.token0.equals(m.token)||T.token1.equals(m.token))&&!T.reserve0.equalTo(A)&&!T.reserve1.equalTo(A)){var w=void 0;try{w=T.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(w.token.equals(v))nt(a,t.NewTrade(new Ot([].concat(i,[T]),u.currency,r),u,exports.TradeType.EXACT_INPUT),d,St);else if(f>1&&e.length>1){var x=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(x,w,r,{maxNumResults:d,maxHops:f-1},[].concat(i,[T]),u,a)}}}return a},t.bestTradeExactOut=function(e,n,r,o,i,u,a){var s=void 0===o?{}:o,c=s.maxNumResults,d=void 0===c?3:c,l=s.maxHops,f=void 0===l?3:l;void 0===i&&(i=[]),void 0===u&&(u=r),void 0===a&&(a=[]),e.length>0||p(!1),f>0||p(!1),u===r||i.length>0||p(!1);var h=r instanceof wt?r.token.chainId:n instanceof at?n.chainId:void 0;void 0===h&&p(!1);for(var m=qt(r,h),v=Pt(n,h),y=0;y<e.length;y++){var T=e[y];if((T.token0.equals(m.token)||T.token1.equals(m.token))&&!T.reserve0.equalTo(A)&&!T.reserve1.equalTo(A)){var w=void 0;try{w=T.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(w.token.equals(v))nt(a,t.NewTrade(new Ot([T].concat(i),n,u.currency),u,exports.TradeType.EXACT_OUTPUT),d,St);else if(f>1&&e.length>1){var x=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(x,n,w,{maxNumResults:d,maxHops:f-1},[T].concat(i),u,a)}}}return a},t}();function Ut(t){return"0x"+t.raw.toString(16)}var Ct,Rt=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===it,r=t.outputAmount.currency===it;n&&r&&p(!1),!("ttl"in e)||e.ttl>0||p(!1);var o,i,u,a=ut(e.recipient),s=Ut(t.maximumAmountIn(e.allowedSlippage)),c=Ut(t.minimumAmountOut(e.allowedSlippage)),d=t.route.path.map((function(t){return t.address})),l="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.tradeType){case exports.TradeType.EXACT_INPUT:n?(o=f?"swapExactSOXForTokensSupportingFeeOnTransferTokens":"swapExactSOXForTokens",i=[c,d,a,l],u=s):r?(o=f?"swapExactTokensForSOXSupportingFeeOnTransferTokens":"swapExactTokensForSOX",i=[s,c,d,a,l],u="0x0"):(o=f?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[s,c,d,a,l],u="0x0");break;case exports.TradeType.EXACT_OUTPUT:f&&p(!1),n?(o="swapSOXForExactTokens",i=[c,d,a,l],u=s):r?(o="swapTokensForExactSOX",i=[c,s,d,a,l],u="0x0"):(o="swapTokensForExactTokens",i=[c,s,d,a,l],u="0x0")}return{methodName:o,args:i,value:u}},t}(),Dt=[{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"}],Ft=((Ct={})[exports.ChainId.MAINNET]={"0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A":9},Ct),Xt=function(){function t(){}return t.fetchTokenData=function(t,e,n,r){try{var o,i,u=function(o){return new at(t,e,o,n,r)},a="number"==typeof(null===(o=Ft)||void 0===o||null===(i=o[t])||void 0===i?void 0:i[e]);return Promise.resolve(a?u(Ft[t][e]):Promise.resolve(D[t].contract(Dt,e).decimals().then((function(n){var r,o,i;return Ft=j({},Ft,((i={})[t]=j({},null===(r=Ft)||void 0===r?void 0:r[t],((o={})[e]=n,o)),i)),n}))).then(u))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e){try{t.chainId!==e.chainId&&p(!1);var n=At.getAddress(t,e);return n?Promise.resolve(D[t.chainId].contract(y.abi,n).getReserves()).then((function(n){var r=n[0],o=n[1],i=t.sortsBefore(e)?[r,o]:[o,r];return At.NewPair(new wt(t,i[0]),new wt(e,i[1]))})):Promise.resolve(void 0)}catch(t){return Promise.reject(t)}},t}();exports.JSBI=d,exports.Currency=rt,exports.CurrencyAmount=Tt,exports.FACTORY_ADDRESS=w,exports.Fetcher=Xt,exports.Fraction=vt,exports.INIT_CODE_HASH=k,exports.InsufficientInputAmountError=J,exports.InsufficientReservesError=V,exports.InvalidPairError=z,exports.LIQUIDITY_TOKEN_DECIMALS=8,exports.LIQUIDITY_TOKEN_NAME="Soxswap",exports.LIQUIDITY_TOKEN_SYMBOL="SXW",exports.MINIMUM_LIQUIDITY=I,exports.Pair=At,exports.Percent=Et,exports.Price=xt,exports.ROUTER_ADDRESS=x,exports.Route=Ot,exports.Router=Rt,exports.SOX=it,exports.SonicxWebObjs=D,exports.Token=at,exports.TokenAmount=wt,exports.Trade=_t,exports.WSOX=pt,exports.currencyEquals=st,exports.inputOutputComparator=Nt,exports.tradeComparator=St; //# sourceMappingURL=soxswap-sdk.cjs.production.min.js.map