UNPKG

psc-sdk

Version:

🛠 An SDK for building applications on top of psc-swap.

3 lines (2 loc) • 30.7 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,i,a,o,u=t(require("jsbi")),s=t(require("tiny-invariant")),p=(t(require("tiny-warning")),require("@ethersproject/address")),c=t(require("big.js")),d=t(require("toformat")),l=t(require("decimal.js-light")),y=require("@ethersproject/solidity"),f=require("@ethersproject/contracts"),m=require("@ethersproject/networks"),h=require("@ethersproject/providers");(i=exports.ChainId||(exports.ChainId={}))[i.MAINNET=16969696]="MAINNET",i[i.TESTNET=97]="TESTNET",(a=exports.TradeType||(exports.TradeType={}))[a.EXACT_INPUT=0]="EXACT_INPUT",a[a.EXACT_OUTPUT=1]="EXACT_OUTPUT",(o=exports.Rounding||(exports.Rounding={}))[o.ROUND_DOWN=0]="ROUND_DOWN",o[o.ROUND_HALF_UP=1]="ROUND_HALF_UP",o[o.ROUND_UP=2]="ROUND_UP";var v,T=((e={})[exports.ChainId.MAINNET]="0xb07Beb1d245D2a89762dB4C7ddbCA6632eb04e4B",e[exports.ChainId.TESTNET]="0x6725f303b657a9451d8ba641348b6761a6cc7a17",e),w="0xf97aca7f4359e458ad27d29d9d645e7337a7c2e40ee90f770d376e839d81ff3f",b=((n={})[exports.ChainId.MAINNET]=w,n[exports.ChainId.TESTNET]="0xd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66",n),g=u.BigInt(1e3),k=u.BigInt(0),x=u.BigInt(1),I=u.BigInt(2),A=u.BigInt(3),O=u.BigInt(5),E=u.BigInt(10),q=u.BigInt(100),P=u.BigInt(9975),N=u.BigInt(1e4);!function(t){t.uint8="uint8",t.uint256="uint256"}(v||(v={}));var _=((r={})[v.uint8]=u.BigInt("0xff"),r[v.uint256]=u.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),r);function C(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 R(t,e,n){return e&&C(t.prototype,e),n&&C(t,n),t}function U(){return(U=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 M(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function S(t){return(S=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function D(t,e){return(D=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function F(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function B(t,e,n){return(B=F()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var i=new(Function.bind.apply(t,r));return n&&D(i,n.prototype),i}).apply(null,arguments)}function j(t){var e="function"==typeof Map?new Map:void 0;return(j=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return B(t,arguments,S(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),D(n,t)})(t)}function H(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function L(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function X(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return L(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?L(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}var W="setPrototypeOf"in Object,V=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(H(n),(this instanceof e?this.constructor:void 0).prototype),n}return M(e,t),e}(j(Error)),Y=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(H(n),(this instanceof e?this.constructor:void 0).prototype),n}return M(e,t),e}(j(Error));function Q(t,e){u.greaterThanOrEqual(t,k)||s(!1),u.lessThanOrEqual(t,_[e])||s(!1)}function z(t){try{return p.getAddress(t)}catch(t){s(!1)}}function J(t){return t instanceof u?t:u.BigInt(t)}function $(t){Q(t,v.uint256);var e,n=k;if(u.greaterThan(t,A))for(n=t,e=u.add(u.divide(t,I),x);u.lessThan(e,n);)n=e,e=u.divide(u.add(u.divide(t,e),e),I);else u.notEqual(t,k)&&(n=x);return n}function G(t,e,n,r){if(n>0||s(!1),t.length<=n||s(!1),0===t.length)return t.push(e),null;var i=t.length===n;if(i&&r(t[t.length-1],e)<=0)return e;for(var a=0,o=t.length;a<o;){var u=a+o>>>1;r(t[u],e)<=0?a=u+1:o=u}return t.splice(a,0,e),i?t.pop():null}var K,Z=function(t,e,n){Q(u.BigInt(t),v.uint8),this.decimals=t,this.symbol=e,this.name=n},tt=Z.ETHER=new Z(18,"PRIVIX","PRIVIX"),et=function(t){function e(e,n,r,i,a,o){var u;return(u=t.call(this,r,i,a)||this).chainId=e,u.address=z(n),u.projectLink=o,u}M(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&&s(!1),this.address===t.address&&s(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(Z);function nt(t,e){return t instanceof et&&e instanceof et?t.equals(e):!(t instanceof et||e instanceof et||t!==e)}var rt,it,at=((K={})[exports.ChainId.MAINNET]=new et(exports.ChainId.MAINNET,"0x0863c36D0f7ce3f0Dd2Cd52846D7ad6d99a49FC3",18,"WPRIVIX","Wrapped Privix","https://privixai.org/"),K[exports.ChainId.TESTNET]=new et(exports.ChainId.TESTNET,"0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",18,"WBNB","Wrapped BNB","https://www.binance.org"),K),ot=d(l),ut=d(c),st=((rt={})[exports.Rounding.ROUND_DOWN]=ot.ROUND_DOWN,rt[exports.Rounding.ROUND_HALF_UP]=ot.ROUND_HALF_UP,rt[exports.Rounding.ROUND_UP]=ot.ROUND_UP,rt),pt=((it={})[exports.Rounding.ROUND_DOWN]=0,it[exports.Rounding.ROUND_HALF_UP]=1,it[exports.Rounding.ROUND_UP]=3,it),ct=function(){function t(t,e){void 0===e&&(e=x),this.numerator=J(t),this.denominator=J(e)}var e=t.prototype;return e.invert=function(){return new t(this.denominator,this.numerator)},e.add=function(e){var n=e instanceof t?e:new t(J(e));return u.equal(this.denominator,n.denominator)?new t(u.add(this.numerator,n.numerator),this.denominator):new t(u.add(u.multiply(this.numerator,n.denominator),u.multiply(n.numerator,this.denominator)),u.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=e instanceof t?e:new t(J(e));return u.equal(this.denominator,n.denominator)?new t(u.subtract(this.numerator,n.numerator),this.denominator):new t(u.subtract(u.multiply(this.numerator,n.denominator),u.multiply(n.numerator,this.denominator)),u.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=e instanceof t?e:new t(J(e));return u.lessThan(u.multiply(this.numerator,n.denominator),u.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=e instanceof t?e:new t(J(e));return u.equal(u.multiply(this.numerator,n.denominator),u.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=e instanceof t?e:new t(J(e));return u.greaterThan(u.multiply(this.numerator,n.denominator),u.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=e instanceof t?e:new t(J(e));return new t(u.multiply(this.numerator,n.numerator),u.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=e instanceof t?e:new t(J(e));return new t(u.multiply(this.numerator,n.denominator),u.multiply(this.denominator,n.numerator))},e.toSignificant=function(t,e,n){void 0===e&&(e={groupSeparator:""}),void 0===n&&(n=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||s(!1),t>0||s(!1),ot.set({precision:t+1,rounding:st[n]});var r=new ot(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)||s(!1),t>=0||s(!1),ut.DP=t,ut.RM=pt[n],new ut(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},R(t,[{key:"quotient",get:function(){return u.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(u.remainder(this.numerator,this.denominator),this.denominator)}},{key:"asFraction",get:function(){return new t(this.numerator,this.denominator)}}]),t}(),dt=d(c),lt=function(t){function e(e,n){var r,i=J(n);return Q(i,v.uint256),(r=t.call(this,i,u.exponentiate(E,u.BigInt(e.decimals)))||this).currency=e,r}M(e,t),e.ether=function(t){return new e(tt,t)};var n=e.prototype;return n.add=function(t){return nt(this.currency,t.currency)||s(!1),new e(this.currency,u.add(this.raw,t.raw))},n.subtract=function(t){return nt(this.currency,t.currency)||s(!1),new e(this.currency,u.subtract(this.raw,t.raw))},n.toSignificant=function(e,n,r){return void 0===e&&(e=6),void 0===r&&(r=exports.Rounding.ROUND_DOWN),t.prototype.toSignificant.call(this,e,n,r)},n.toFixed=function(e,n,r){return void 0===e&&(e=this.currency.decimals),void 0===r&&(r=exports.Rounding.ROUND_DOWN),e<=this.currency.decimals||s(!1),t.prototype.toFixed.call(this,e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),dt.DP=this.currency.decimals,new dt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},R(e,[{key:"raw",get:function(){return this.numerator}}]),e}(ct),yt=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}M(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||s(!1),new e(this.token,u.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||s(!1),new e(this.token,u.subtract(this.raw,t.raw))},e}(lt),ft=function(t){function e(e,n,r,i){var a;return(a=t.call(this,i,r)||this).baseCurrency=e,a.quoteCurrency=n,a.scalar=new ct(u.exponentiate(E,u.BigInt(e.decimals)),u.exponentiate(E,u.BigInt(n.decimals))),a}M(e,t),e.fromRoute=function(t){for(var n,r=[],i=X(t.pairs.entries());!(n=i()).done;){var a=n.value,o=a[1];r.push(t.path[a[0]].equals(o.token0)?new e(o.reserve0.currency,o.reserve1.currency,o.reserve0.raw,o.reserve1.raw):new e(o.reserve1.currency,o.reserve0.currency,o.reserve1.raw,o.reserve0.raw))}return r.slice(1).reduce((function(t,e){return t.multiply(e)}),r[0])};var n=e.prototype;return n.invert=function(){return new e(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},n.multiply=function(n){nt(this.quoteCurrency,n.baseCurrency)||s(!1);var r=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,r.denominator,r.numerator)},n.quote=function(e){return nt(e.currency,this.baseCurrency)||s(!1),this.quoteCurrency instanceof et?new yt(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):lt.ether(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)},R(e,[{key:"raw",get:function(){return new ct(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(ct),mt={},ht=function(){function t(e,n){var r=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new et(r[0].token.chainId,t.getAddress(r[0].token,r[1].token),18,"Privix-LP","PrivixSwap LPs"),this.tokenAmounts=r}t.getAddress=function(t,e){var n,r,i=t.sortsBefore(e)?[t,e]:[e,t],a=i[0],o=i[1],u=function(t,e){return t.chainId+"-"+t.address+"-"+e.address}(a,o);return void 0===(null===(n=mt)||void 0===n?void 0:n[u])&&(mt=U({},mt,((r={})[u]=p.getCreate2Address(T[a.chainId],y.keccak256(["bytes"],[y.pack(["address","address"],[a.address,o.address])]),b[a.chainId]),r))),mt[u]};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)||s(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||s(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||s(!1),u.equal(this.reserve0.raw,k)||u.equal(this.reserve1.raw,k))throw new V;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),i=u.multiply(e.raw,P),a=u.multiply(i,r.raw),o=u.add(u.multiply(n.raw,N),i),p=new yt(e.token.equals(this.token0)?this.token1:this.token0,u.divide(a,o));if(u.equal(p.raw,k))throw new Y;return[p,new t(n.add(e),r.subtract(p))]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||s(!1),u.equal(this.reserve0.raw,k)||u.equal(this.reserve1.raw,k)||u.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new V;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),i=u.multiply(u.multiply(r.raw,e.raw),N),a=u.multiply(u.subtract(n.raw,e.raw),P),o=new yt(e.token.equals(this.token0)?this.token1:this.token0,u.add(u.divide(i,a),x));return[o,new t(r.add(o),n.subtract(e))]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||s(!1);var r,i=e.token.sortsBefore(n.token)?[e,n]:[n,e];if(i[0].token.equals(this.token0)&&i[1].token.equals(this.token1)||s(!1),u.equal(t.raw,k))r=u.subtract($(u.multiply(i[0].raw,i[1].raw)),g);else{var a=u.divide(u.multiply(i[0].raw,t.raw),this.reserve0.raw),o=u.divide(u.multiply(i[1].raw,t.raw),this.reserve1.raw);r=u.lessThanOrEqual(a,o)?a:o}if(!u.greaterThan(r,k))throw new Y;return new yt(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,i){var a;if(void 0===r&&(r=!1),this.involvesToken(t)||s(!1),e.token.equals(this.liquidityToken)||s(!1),n.token.equals(this.liquidityToken)||s(!1),u.lessThanOrEqual(n.raw,e.raw)||s(!1),r){i||s(!1);var o=J(i);if(u.equal(o,k))a=e;else{var p=$(u.multiply(this.reserve0.raw,this.reserve1.raw)),c=$(o);if(u.greaterThan(p,c)){var d=u.multiply(e.raw,u.subtract(p,c)),l=u.add(u.multiply(p,O),c),y=u.divide(d,l);a=e.add(new yt(this.liquidityToken,y))}else a=e}}else a=e;return new yt(t,u.divide(u.multiply(n.raw,this.reserveOf(t).raw),a.raw))},R(t,[{key:"token0Price",get:function(){return new ft(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new ft(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}(),vt=function(){function t(t,e,n){t.length>0||s(!1),t.every((function(e){return e.chainId===t[0].chainId}))||s(!1),e instanceof et&&t[0].involvesToken(e)||e===tt&&t[0].involvesToken(at[t[0].chainId])||s(!1),void 0===n||n instanceof et&&t[t.length-1].involvesToken(n)||n===tt&&t[t.length-1].involvesToken(at[t[0].chainId])||s(!1);for(var r,i=[e instanceof et?e:at[t[0].chainId]],a=X(t.entries());!(r=a()).done;){var o=r.value,u=o[1],p=i[o[0]];p.equals(u.token0)||p.equals(u.token1)||s(!1);var c=p.equals(u.token0)?u.token1:u.token0;i.push(c)}this.pairs=t,this.path=i,this.midPrice=ft.fromRoute(this),this.input=e,this.output=null!=n?n:i[i.length-1]}return R(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),Tt=new ct(q),wt=function(t){function e(){return t.apply(this,arguments)||this}M(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(Tt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(Tt).toFixed(t,e,n)},e}(ct);function bt(t,e){return nt(t.inputAmount.currency,e.inputAmount.currency)||s(!1),nt(t.outputAmount.currency,e.outputAmount.currency)||s(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?0:t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}function gt(t,e){var n=bt(t,e);return 0!==n?n:t.priceImpact.lessThan(e.priceImpact)?-1:t.priceImpact.greaterThan(e.priceImpact)?1:t.route.path.length-e.route.path.length}function kt(t,e){return t instanceof yt?t:t.currency===tt?new yt(at[e],t.raw):void s(!1)}function xt(t,e){return t instanceof et?t:t===tt?at[e]:void s(!1)}var It=function(){function t(t,e,n){var r,i,a,o=new Array(t.path.length),u=new Array(t.pairs.length);if(n===exports.TradeType.EXACT_INPUT){nt(e.currency,t.input)||s(!1),o[0]=kt(e,t.chainId);for(var p=0;p<t.path.length-1;p++){var c=t.pairs[p].getOutputAmount(o[p]),d=c[1];o[p+1]=c[0],u[p]=d}}else{nt(e.currency,t.output)||s(!1),o[o.length-1]=kt(e,t.chainId);for(var l=t.path.length-1;l>0;l--){var y=t.pairs[l-1].getInputAmount(o[l]),f=y[1];o[l-1]=y[0],u[l-1]=f}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===tt?lt.ether(o[0].raw):o[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===tt?lt.ether(o[o.length-1].raw):o[o.length-1],this.executionPrice=new ft(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=ft.fromRoute(new vt(u,t.input)),this.priceImpact=(r=this.outputAmount,a=(i=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(r.raw).divide(i),new wt(a.numerator,a.denominator))}t.exactIn=function(e,n){return new t(e,n,exports.TradeType.EXACT_INPUT)},t.exactOut=function(e,n){return new t(e,n,exports.TradeType.EXACT_OUTPUT)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(k)&&s(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new ct(x).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof yt?new yt(this.outputAmount.token,e):lt.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(k)&&s(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new ct(x).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof yt?new yt(this.inputAmount.token,e):lt.ether(e)},t.bestTradeExactIn=function(e,n,r,i,a,o,u){var p=void 0===i?{}:i,c=p.maxNumResults,d=void 0===c?3:c,l=p.maxHops,y=void 0===l?3:l;void 0===a&&(a=[]),void 0===o&&(o=n),void 0===u&&(u=[]),e.length>0||s(!1),y>0||s(!1),o===n||a.length>0||s(!1);var f=n instanceof yt?n.token.chainId:r instanceof et?r.chainId:void 0;void 0===f&&s(!1);for(var m=kt(n,f),h=xt(r,f),v=0;v<e.length;v++){var T=e[v];if((T.token0.equals(m.token)||T.token1.equals(m.token))&&!T.reserve0.equalTo(k)&&!T.reserve1.equalTo(k)){var w=void 0;try{w=T.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(w.token.equals(h))G(u,new t(new vt([].concat(a,[T]),o.currency,r),o,exports.TradeType.EXACT_INPUT),d,gt);else if(y>1&&e.length>1){var b=e.slice(0,v).concat(e.slice(v+1,e.length));t.bestTradeExactIn(b,w,r,{maxNumResults:d,maxHops:y-1},[].concat(a,[T]),o,u)}}}return u},t.bestTradeExactOut=function(e,n,r,i,a,o,u){var p=void 0===i?{}:i,c=p.maxNumResults,d=void 0===c?3:c,l=p.maxHops,y=void 0===l?3:l;void 0===a&&(a=[]),void 0===o&&(o=r),void 0===u&&(u=[]),e.length>0||s(!1),y>0||s(!1),o===r||a.length>0||s(!1);var f=r instanceof yt?r.token.chainId:n instanceof et?n.chainId:void 0;void 0===f&&s(!1);for(var m=kt(r,f),h=xt(n,f),v=0;v<e.length;v++){var T=e[v];if((T.token0.equals(m.token)||T.token1.equals(m.token))&&!T.reserve0.equalTo(k)&&!T.reserve1.equalTo(k)){var w=void 0;try{w=T.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(w.token.equals(h))G(u,new t(new vt([T].concat(a),n,o.currency),o,exports.TradeType.EXACT_OUTPUT),d,gt);else if(y>1&&e.length>1){var b=e.slice(0,v).concat(e.slice(v+1,e.length));t.bestTradeExactOut(b,n,w,{maxNumResults:d,maxHops:y-1},[T].concat(a),o,u)}}}return u},t}();function At(t){return"0x"+t.raw.toString(16)}var Ot,Et=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===tt,r=t.outputAmount.currency===tt;n&&r&&s(!1),!("ttl"in e)||e.ttl>0||s(!1);var i,a,o,u=z(e.recipient),p=At(t.maximumAmountIn(e.allowedSlippage)),c=At(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),y=Boolean(e.feeOnTransfer);switch(t.tradeType){case exports.TradeType.EXACT_INPUT:n?(i=y?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",a=[c,d,u,l],o=p):r?(i=y?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",a=[p,c,d,u,l],o="0x0"):(i=y?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",a=[p,c,d,u,l],o="0x0");break;case exports.TradeType.EXACT_OUTPUT:y&&s(!1),n?(i="swapETHForExactTokens",a=[c,d,u,l],o=p):r?(i="swapTokensForExactETH",a=[c,p,d,u,l],o="0x0"):(i="swapTokensForExactTokens",a=[c,p,d,u,l],o="0x0")}return{methodName:i,args:a,value:o}},t}(),qt=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!1,internalType:"uint256",name:"amount0",type:"uint256"},{indexed:!1,internalType:"uint256",name:"amount1",type:"uint256"},{indexed:!0,internalType:"address",name:"to",type:"address"}],name:"Burn",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!1,internalType:"uint256",name:"amount0",type:"uint256"},{indexed:!1,internalType:"uint256",name:"amount1",type:"uint256"}],name:"Mint",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"sender",type:"address"},{indexed:!1,internalType:"uint256",name:"amount0In",type:"uint256"},{indexed:!1,internalType:"uint256",name:"amount1In",type:"uint256"},{indexed:!1,internalType:"uint256",name:"amount0Out",type:"uint256"},{indexed:!1,internalType:"uint256",name:"amount1Out",type:"uint256"},{indexed:!0,internalType:"address",name:"to",type:"address"}],name:"Swap",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint112",name:"reserve0",type:"uint112"},{indexed:!1,internalType:"uint112",name:"reserve1",type:"uint112"}],name:"Sync",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{constant:!0,inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"MINIMUM_LIQUIDITY",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"pure",type:"function"},{constant:!0,inputs:[],name:"PERMIT_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],payable:!1,stateMutability:"pure",type:"function"},{constant:!0,inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{internalType:"address",name:"owner",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"to",type:"address"}],name:"burn",outputs:[{internalType:"uint256",name:"amount0",type:"uint256"},{internalType:"uint256",name:"amount1",type:"uint256"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],payable:!1,stateMutability:"pure",type:"function"},{constant:!0,inputs:[],name:"factory",outputs:[{internalType:"address",name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"getReserves",outputs:[{internalType:"uint112",name:"reserve0",type:"uint112"},{internalType:"uint112",name:"reserve1",type:"uint112"},{internalType:"uint32",name:"blockTimestampLast",type:"uint32"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"initialize",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"kLast",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"to",type:"address"}],name:"mint",outputs:[{internalType:"uint256",name:"liquidity",type:"uint256"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],payable:!1,stateMutability:"pure",type:"function"},{constant:!0,inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"price0CumulativeLast",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"price1CumulativeLast",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"to",type:"address"}],name:"skim",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{internalType:"uint256",name:"amount0Out",type:"uint256"},{internalType:"uint256",name:"amount1Out",type:"uint256"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],name:"swap",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],payable:!1,stateMutability:"pure",type:"function"},{constant:!1,inputs:[],name:"sync",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"token0",outputs:[{internalType:"address",name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"token1",outputs:[{internalType:"address",name:"",type:"address"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],Pt=[{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"}],Nt=((Ot={})[exports.ChainId.MAINNET]={"0xC6bF9487F53deE994210b7844636685b9C75bBA7":9},Ot),_t=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,i){try{var a,o,u=function(n){return new et(t,e,n,r,i)};void 0===n&&(n=h.getDefaultProvider(m.getNetwork(t)));var s="number"==typeof(null===(a=Nt)||void 0===a||null===(o=a[t])||void 0===o?void 0:o[e]);return Promise.resolve(s?u(Nt[t][e]):Promise.resolve(new f.Contract(e,Pt,n).decimals().then((function(n){var r,i,a;return Nt=U({},Nt,((a={})[t]=U({},null===(r=Nt)||void 0===r?void 0:r[t],((i={})[e]=n,i)),a)),n}))).then(u))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e,n){try{void 0===n&&(n=h.getDefaultProvider(m.getNetwork(t.chainId))),t.chainId!==e.chainId&&s(!1);var r=ht.getAddress(t,e);return Promise.resolve(new f.Contract(r,qt,n).getReserves()).then((function(n){var r=n[0],i=n[1],a=t.sortsBefore(e)?[r,i]:[i,r];return new ht(new yt(t,a[0]),new yt(e,a[1]))}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=u,exports.Currency=Z,exports.CurrencyAmount=lt,exports.ETHER=tt,exports.FACTORY_ADDRESS="0xb07Beb1d245D2a89762dB4C7ddbCA6632eb04e4B",exports.FACTORY_ADDRESS_MAP=T,exports.Fetcher=_t,exports.Fraction=ct,exports.INIT_CODE_HASH=w,exports.INIT_CODE_HASH_MAP=b,exports.InsufficientInputAmountError=Y,exports.InsufficientReservesError=V,exports.MINIMUM_LIQUIDITY=g,exports.Pair=ht,exports.Percent=wt,exports.Price=ft,exports.Route=vt,exports.Router=Et,exports.Token=et,exports.TokenAmount=yt,exports.Trade=It,exports.WPRIVIX=at,exports.currencyEquals=nt,exports.inputOutputComparator=bt,exports.tradeComparator=gt; //# sourceMappingURL=psc-sdk.cjs.production.min.js.map