UNPKG

@jfswap/sdk

Version:

đź›  An SDK for building applications on top of JFSwap.

3 lines (2 loc) • 34 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,a,u=t(require("jsbi")),s=t(require("big.js")),c=t(require("tiny-invariant")),d=(t(require("tiny-warning")),require("@ethersproject/address")),f=t(require("toformat")),h=t(require("decimal.js-light")),p=require("@ethersproject/solidity"),l=require("@ethersproject/contracts"),v=require("@ethersproject/networks"),m=require("@ethersproject/providers"),y=t(require("@uniswap/v2-core/build/IUniswapV2Pair.json"));(o=exports.ChainId||(exports.ChainId={}))[o.MAINNET=1]="MAINNET",o[o.ROPSTEN=3]="ROPSTEN",o[o.RINKEBY=4]="RINKEBY",o[o["GĂ–RLI"]=5]="GĂ–RLI",o[o.KOVAN=42]="KOVAN",o[o.OKEXCHAIN=66]="OKEXCHAIN",o[o.OKEXCHAIN_TESTNET=65]="OKEXCHAIN_TESTNET",o[o.BSC=56]="BSC",o[o.BSC_TESTNET=97]="BSC_TESTNET",o[o.MATIC=137]="MATIC",o[o.MATIC_MUMBAI=80001]="MATIC_MUMBAI",o[o.DEV=1337]="DEV",(i=exports.TradeType||(exports.TradeType={}))[i.EXACT_INPUT=0]="EXACT_INPUT",i[i.EXACT_OUTPUT=1]="EXACT_OUTPUT",(a=exports.Rounding||(exports.Rounding={}))[a.ROUND_DOWN=0]="ROUND_DOWN",a[a.ROUND_HALF_UP=1]="ROUND_HALF_UP",a[a.ROUND_UP=2]="ROUND_UP";var T,w="0x498225CdCA2256598D45904D515EBc9e7b4B7228",x="0x6c5de0c557eaa47927c0c766d79019a897028d77dec6f3ca8e4e3d8ac105bc92",g=((e={})[exports.ChainId.OKEXCHAIN]="0x2A24C4b12f62b14E35fdfFe9bAf9c2E16Ba11D08",e[exports.ChainId.OKEXCHAIN_TESTNET]="0x1fE3ed44cA4a2add77BbCA7553e23CfA36Fa3e5a",e[exports.ChainId.MATIC]="",e[exports.ChainId.MATIC_MUMBAI]="0x0aE532B0d3066ff6d4f4EA55FE29D1b37cd8D0De",e[exports.ChainId.BSC]="0x2A24C4b12f62b14E35fdfFe9bAf9c2E16Ba11D08",e[exports.ChainId.BSC_TESTNET]="0x9f38cFC1B86698FE2a3c0b0FD1504c855596d2A9",e[exports.ChainId.GĂ–RLI]="0xeb86db89953dF90C5cF6136B303d4d89398Fa07E",e[exports.ChainId.MAINNET]="0x2A24C4b12f62b14E35fdfFe9bAf9c2E16Ba11D08",e),I=((n={})[exports.ChainId.OKEXCHAIN]="0x98298017bcc1f221d4c741a0b2ba9dd37d645be3fd93ec79aaa4b2516289d470",n[exports.ChainId.OKEXCHAIN_TESTNET]="0xe03d68db6b3b6c2e80ae8285de7c066ce3446aeb445391e429764dbdcc68ee13",n[exports.ChainId.MATIC]="",n[exports.ChainId.MATIC_MUMBAI]="0xade8b278d2f0f0da4d9d043fd0ac133a5c02eed5094e7ca3c6630caa64c9073e",n[exports.ChainId.BSC]="0x98298017bcc1f221d4c741a0b2ba9dd37d645be3fd93ec79aaa4b2516289d470",n[exports.ChainId.BSC_TESTNET]="0x5ebaa858afb401cfc6b62189261b88e455ac9d6cc692f2c54c554b82928c40c1",n[exports.ChainId.GĂ–RLI]="0x4eb2a9a5e06a100e4d5b5e8d230ee3e75c09cda328f179296d2b372392167255",n[exports.ChainId.MAINNET]="0x98298017bcc1f221d4c741a0b2ba9dd37d645be3fd93ec79aaa4b2516289d470",n),E=u.BigInt(1e3),A=u.BigInt(0),b=u.BigInt(1),C=u.BigInt(2),k=u.BigInt(3),O=u.BigInt(5),N=u.BigInt(10),_=u.BigInt(100),B=u.BigInt(997),q=u.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(T||(T={}));var S=((r={})[T.uint8]=u.BigInt("0xff"),r[T.uint256]=u.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),r);function R(){R=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",i=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function u(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,n){return t[e]=n}}function s(t,e,n,r){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new E(r||[]);return o._invoke=function(t,e,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return{value:void 0,done:!0}}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var u=x(a,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var s=c(t,e,n);if("normal"===s.type){if(r=n.done?"completed":"suspendedYield",s.arg===d)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r="completed",n.method="throw",n.arg=s.arg)}}}(t,n,i),o}function c(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var d={};function f(){}function h(){}function p(){}var l={};u(l,o,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(A([])));m&&m!==e&&n.call(m,o)&&(l=m);var y=p.prototype=f.prototype=Object.create(l);function T(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){var r;this._invoke=function(o,i){function a(){return new e((function(r,a){!function r(o,i,a,u){var s=c(t[o],t,i);if("throw"!==s.type){var d=s.arg,f=d.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(f).then((function(t){d.value=t,a(d)}),(function(t){return r("throw",t,a,u)}))}u(s.arg)}(o,i,r,a)}))}return r=r?r.then(a,a):a()}}function x(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return d;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var r=c(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,d;var o=r.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,d):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function g(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function I(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(g,this),this.reset(!0)}function A(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:b}}function b(){return{value:void 0,done:!0}}return h.prototype=p,u(y,"constructor",p),u(p,"constructor",h),h.displayName=u(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,u(t,a,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},T(w.prototype),u(w.prototype,i,(function(){return this})),t.AsyncIterator=w,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var a=new w(s(e,n,r,o),i);return t.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},T(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=A,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(I),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(n,r){return a.type="throw",a.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),I(n),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;I(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:A(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},t}function P(t,e,n,r,o,i,a){try{var u=t[i](a),s=u.value}catch(t){return void n(t)}u.done?e(s):Promise.resolve(s).then(r,o)}function F(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var i=t.apply(e,n);function a(t){P(i,r,o,a,u,"next",t)}function u(t){P(i,r,o,a,u,"throw",t)}a(void 0)}))}}function U(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 D(t,e,n){return e&&U(t.prototype,e),n&&U(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function M(){return(M=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function L(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,j(t,e)}function H(t){return(H=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function j(t,e){return(j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function K(){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 W(t,e,n){return(W=K()?Reflect.construct.bind():function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&j(o,n.prototype),o}).apply(null,arguments)}function X(t){var e="function"==typeof Map?new Map:void 0;return(X=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,H(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),j(n,t)})(t)}function G(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function V(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 Y(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 V(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)?V(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 J,Q="setPrototypeOf"in Object,$=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,Q&&Object.setPrototypeOf(G(n),(this instanceof e?this.constructor:void 0).prototype),n}return L(e,t),e}(X(Error)),z=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,Q&&Object.setPrototypeOf(G(n),(this instanceof e?this.constructor:void 0).prototype),n}return L(e,t),e}(X(Error));function Z(t,e){u.greaterThanOrEqual(t,A)||c(!1),u.lessThanOrEqual(t,S[e])||c(!1)}function tt(t){try{return d.getAddress(t)}catch(t){c(!1)}}function et(t){return t instanceof u?t:u.BigInt("bigint"==typeof t?t.toString():t)}function nt(t){Z(t,T.uint256);var e,n=A;if(u.greaterThan(t,k))for(n=t,e=u.add(u.divide(t,C),b);u.lessThan(e,n);)n=e,e=u.divide(u.add(u.divide(t,e),e),C);else u.notEqual(t,A)&&(n=b);return n}function rt(t,e,n,r){if(n>0||c(!1),t.length<=n||c(!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 u=i+a>>>1;r(t[u],e)<=0?i=u+1:a=u}return t.splice(i,0,e),o?t.pop():null}var ot=function(t,e,n){Z(u.BigInt(t),T.uint8),this.decimals=t,this.symbol=e,this.name=n};ot.ETHER=new ot(18,"ETH","Ether"),ot.BNB=new ot(18,"BNB","BNB"),ot.OKT=new ot(18,"OKT","OKT"),ot.MATIC=new ot(18,"MATIC","MATIC");var it,at=((J={})[exports.ChainId.OKEXCHAIN]=ot.OKT,J[exports.ChainId.OKEXCHAIN_TESTNET]=ot.OKT,J[exports.ChainId.MATIC]=ot.MATIC,J[exports.ChainId.MATIC_MUMBAI]=ot.MATIC,J[exports.ChainId.BSC]=ot.BNB,J[exports.ChainId.BSC_TESTNET]=ot.BNB,J[exports.ChainId.GĂ–RLI]=ot.ETHER,J[exports.ChainId.MAINNET]=ot.ETHER,J),ut=ot.ETHER,st=function(t){function e(e,n,r,o,i){var a;return(a=t.call(this,r,o,i)||this).chainId=e,a.address=tt(n),a}L(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&&c(!1),this.address===t.address&&c(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(ot);function ct(t,e){return t instanceof st&&e instanceof st?t.equals(e):!(t instanceof st||e instanceof st||t!==e)}var dt,ft,ht=((it={})[exports.ChainId.MAINNET]=new st(exports.ChainId.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),it[exports.ChainId.ROPSTEN]=new st(exports.ChainId.ROPSTEN,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),it[exports.ChainId.RINKEBY]=new st(exports.ChainId.RINKEBY,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),it[exports.ChainId.GĂ–RLI]=new st(exports.ChainId.GĂ–RLI,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH","Wrapped Ether"),it[exports.ChainId.KOVAN]=new st(exports.ChainId.KOVAN,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH","Wrapped Ether"),it[exports.ChainId.OKEXCHAIN]=new st(exports.ChainId.OKEXCHAIN,"0x8f8526dbfd6e38e3d8307702ca8469bae6c56c15",18,"WOKT","Wrapped OKT"),it[exports.ChainId.OKEXCHAIN_TESTNET]=new st(exports.ChainId.OKEXCHAIN_TESTNET,"0x70c1c53e991f31981d592c2d865383ac0d212225",18,"WOKT","Wrapped OKT"),it[exports.ChainId.MATIC]=new st(exports.ChainId.MATIC,"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",18,"WMATIC","Wrapped MATIC"),it[exports.ChainId.MATIC_MUMBAI]=new st(exports.ChainId.MATIC_MUMBAI,"0x0000000000000000000000000000000000001010",18,"WMATIC","Wrapped MATIC"),it[exports.ChainId.BSC]=new st(exports.ChainId.BSC,"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",18,"WBNB","Wrapped BNB"),it[exports.ChainId.BSC_TESTNET]=new st(exports.ChainId.BSC_TESTNET,"0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",18,"WBNB","Wrapped BNB"),it[exports.ChainId.DEV]=new st(exports.ChainId.DEV,"0x78b32fe15B696A2e958184dEFd1c92921963848A",18,"WOKT","Wrapped OKT"),it),pt=f(h),lt=f(s),vt=((dt={})[exports.Rounding.ROUND_DOWN]=pt.ROUND_DOWN,dt[exports.Rounding.ROUND_HALF_UP]=pt.ROUND_HALF_UP,dt[exports.Rounding.ROUND_UP]=pt.ROUND_UP,dt),mt=((ft={})[exports.Rounding.ROUND_DOWN]=0,ft[exports.Rounding.ROUND_HALF_UP]=1,ft[exports.Rounding.ROUND_UP]=3,ft),yt=function(){function t(t,e){void 0===e&&(e=b),this.numerator=et(t),this.denominator=et(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(et(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(et(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(et(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(et(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(et(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(et(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(et(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)||c(!1),t>0||c(!1),pt.set({precision:t+1,rounding:vt[n]});var r=new pt(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)||c(!1),t>=0||c(!1),lt.DP=t,lt.RM=mt[n],new lt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},D(t,[{key:"quotient",get:function(){return u.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(u.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),Tt=f(s),wt=function(t){function e(e,n){var r,o=et(n);return Z(o,T.uint256),(r=t.call(this,o,u.exponentiate(N,u.BigInt(e.decimals)))||this).currency=e,r}L(e,t),e.ether=function(t,n){var r;return new e(null!=(r=at[t])?r:ut,n)};var n=e.prototype;return n.add=function(t){return ct(this.currency,t.currency)||c(!1),new e(this.currency,u.add(this.raw,t.raw))},n.subtract=function(t){return ct(this.currency,t.currency)||c(!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||c(!1),t.prototype.toFixed.call(this,e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),Tt.DP=this.currency.decimals,new Tt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},D(e,[{key:"raw",get:function(){return this.numerator}}]),e}(yt),xt=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}L(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||c(!1),new e(this.token,u.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||c(!1),new e(this.token,u.subtract(this.raw,t.raw))},e}(wt),gt=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 yt(u.exponentiate(N,u.BigInt(e.decimals)),u.exponentiate(N,u.BigInt(n.decimals))),i}L(e,t),e.fromRoute=function(t){for(var n,r=[],o=Y(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){ct(this.quoteCurrency,n.baseCurrency)||c(!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 ct(n.currency,this.baseCurrency)||c(!1),this.quoteCurrency instanceof st?new xt(this.quoteCurrency,t.prototype.multiply.call(this,n.raw).quotient):wt.ether(e,t.prototype.multiply.call(this,n.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)},D(e,[{key:"raw",get:function(){return new yt(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(yt),It={},Et=function(){function t(e,n){var r=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new st(r[0].token.chainId,t.getAddress(r[0].token,r[1].token,!0),18,"JLP","Jswap LP Token"),this.tokenAmounts=r}t.getAddress=function(t,e,n){var r,o,i=t.sortsBefore(e)?[t,e]:[e,t];if(void 0===(null==(r=It)||null==(o=r[i[0].address])?void 0:o[i[1].address])){var a,u,s,c,f,h=t.chainId,l=null!=(a=n?g[h]:w)?a:w,v=null!=(u=n?I[h]:x)?u:x;It=M({},It,((f={})[i[0].address]=M({},null==(s=It)?void 0:s[i[0].address],((c={})[i[1].address]=d.getCreate2Address(l,p.keccak256(["bytes"],[p.pack(["address","address"],[i[0].address,i[1].address])]),v),c)),f))}return It[i[0].address][i[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)||c(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||c(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||c(!1),u.equal(this.reserve0.raw,A)||u.equal(this.reserve1.raw,A))throw new $;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=u.multiply(e.raw,B),i=u.multiply(o,r.raw),a=u.add(u.multiply(n.raw,q),o),s=new xt(e.token.equals(this.token0)?this.token1:this.token0,u.divide(i,a));if(u.equal(s.raw,A))throw new z;return[s,new t(n.add(e),r.subtract(s))]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||c(!1),u.equal(this.reserve0.raw,A)||u.equal(this.reserve1.raw,A)||u.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new $;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=u.multiply(u.multiply(r.raw,e.raw),q),i=u.multiply(u.subtract(n.raw,e.raw),B),a=new xt(e.token.equals(this.token0)?this.token1:this.token0,u.add(u.divide(o,i),b));return[a,new t(r.add(a),n.subtract(e))]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||c(!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)||c(!1),u.equal(t.raw,A))r=u.subtract(nt(u.multiply(o[0].raw,o[1].raw)),E);else{var i=u.divide(u.multiply(o[0].raw,t.raw),this.reserve0.raw),a=u.divide(u.multiply(o[1].raw,t.raw),this.reserve1.raw);r=u.lessThanOrEqual(i,a)?i:a}if(!u.greaterThan(r,A))throw new z;return new xt(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var i;if(void 0===r&&(r=!1),this.involvesToken(t)||c(!1),e.token.equals(this.liquidityToken)||c(!1),n.token.equals(this.liquidityToken)||c(!1),u.lessThanOrEqual(n.raw,e.raw)||c(!1),r){o||c(!1);var a=et(o);if(u.equal(a,A))i=e;else{var s=nt(u.multiply(this.reserve0.raw,this.reserve1.raw)),d=nt(a);if(u.greaterThan(s,d)){var f=u.multiply(e.raw,u.subtract(s,d)),h=u.add(u.multiply(s,O),d),p=u.divide(f,h);i=e.add(new xt(this.liquidityToken,p))}else i=e}}else i=e;return new xt(t,u.divide(u.multiply(n.raw,this.reserveOf(t).raw),i.raw))},D(t,[{key:"token0Price",get:function(){return new gt(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new gt(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}(),At=function(){function t(t,e,n){t.length>0||c(!1),t.every((function(e){return e.chainId===t[0].chainId}))||c(!1);var r=at[t[0].chainId];r||c(!1),e instanceof st&&t[0].involvesToken(e)||e===r&&t[0].involvesToken(ht[t[0].chainId])||c(!1),void 0===n||n instanceof st&&t[t.length-1].involvesToken(n)||n===r&&t[t.length-1].involvesToken(ht[t[0].chainId])||c(!1);for(var o,i=[e instanceof st?e:ht[t[0].chainId]],a=Y(t.entries());!(o=a()).done;){var u=o.value,s=u[1],d=i[u[0]];d.equals(s.token0)||d.equals(s.token1)||c(!1);var f=d.equals(s.token0)?s.token1:s.token0;i.push(f)}this.pairs=t,this.path=i,this.midPrice=gt.fromRoute(this),this.input=e,this.output=null!=n?n:i[i.length-1]}return D(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),bt=new yt(_),Ct=function(t){function e(){return t.apply(this,arguments)||this}L(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}(yt);function kt(t,e){return ct(t.inputAmount.currency,e.inputAmount.currency)||c(!1),ct(t.outputAmount.currency,e.outputAmount.currency)||c(!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 Ot(t,e){var n=kt(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 Nt(t,e){return t instanceof xt?t:t.currency===at[e]?new xt(ht[e],t.raw):void c(!1)}function _t(t,e){return t instanceof st?t:t===at[e]?ht[e]:void c(!1)}var Bt=function(){function t(t,e,n){var r=new Array(t.path.length),o=new Array(t.pairs.length);if(n===exports.TradeType.EXACT_INPUT){ct(e.currency,t.input)||c(!1),r[0]=Nt(e,t.chainId);for(var i=0;i<t.path.length-1;i++){var a=t.pairs[i].getOutputAmount(r[i]),u=a[1];r[i+1]=a[0],o[i]=u}}else{ct(e.currency,t.output)||c(!1),r[r.length-1]=Nt(e,t.chainId);for(var s=t.path.length-1;s>0;s--){var d=t.pairs[s-1].getInputAmount(r[s]),f=d[1];r[s-1]=d[0],o[s-1]=f}}var h,p,l,v=t.pairs[0].chainId,m=at[t.pairs[0].chainId];m||c(!1),this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===m?wt.ether(v,r[0].raw):r[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===m?wt.ether(v,r[r.length-1].raw):r[r.length-1],this.executionPrice=new gt(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=gt.fromRoute(new At(o,t.input)),this.priceImpact=(h=this.outputAmount,l=(p=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(h.raw).divide(p),new Ct(l.numerator,l.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,e){if(e.lessThan(A)&&c(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var n=new yt(b).add(e).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof xt?new xt(this.outputAmount.token,n):wt.ether(t,n)},e.maximumAmountIn=function(t,e){if(e.lessThan(A)&&c(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var n=new yt(b).add(e).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof xt?new xt(this.inputAmount.token,n):wt.ether(t,n)},t.bestTradeExactIn=function(e,n,r,o,i,a,u){var s=void 0===o?{}:o,d=s.maxNumResults,f=void 0===d?3:d,h=s.maxHops,p=void 0===h?3:h;void 0===i&&(i=[]),void 0===a&&(a=n),void 0===u&&(u=[]),e.length>0||c(!1),p>0||c(!1),a===n||i.length>0||c(!1);var l=n instanceof xt?n.token.chainId:r instanceof st?r.chainId:void 0;void 0===l&&c(!1);for(var v=Nt(n,l),m=_t(r,l),y=0;y<e.length;y++){var T=e[y];if((T.token0.equals(v.token)||T.token1.equals(v.token))&&!T.reserve0.equalTo(A)&&!T.reserve1.equalTo(A)){var w=void 0;try{w=T.getOutputAmount(v)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(w.token.equals(m))rt(u,new t(new At([].concat(i,[T]),a.currency,r),a,exports.TradeType.EXACT_INPUT),f,Ot);else if(p>1&&e.length>1){var x=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(x,w,r,{maxNumResults:f,maxHops:p-1},[].concat(i,[T]),a,u)}}}return u},t.bestTradeExactOut=function(e,n,r,o,i,a,u){var s=void 0===o?{}:o,d=s.maxNumResults,f=void 0===d?3:d,h=s.maxHops,p=void 0===h?3:h;void 0===i&&(i=[]),void 0===a&&(a=r),void 0===u&&(u=[]),e.length>0||c(!1),p>0||c(!1),a===r||i.length>0||c(!1);var l=r instanceof xt?r.token.chainId:n instanceof st?n.chainId:void 0;void 0===l&&c(!1);for(var v=Nt(r,l),m=_t(n,l),y=0;y<e.length;y++){var T=e[y];if((T.token0.equals(v.token)||T.token1.equals(v.token))&&!T.reserve0.equalTo(A)&&!T.reserve1.equalTo(A)){var w=void 0;try{w=T.getInputAmount(v)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(w.token.equals(m))rt(u,new t(new At([T].concat(i),n,a.currency),a,exports.TradeType.EXACT_OUTPUT),f,Ot);else if(p>1&&e.length>1){var x=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(x,n,w,{maxNumResults:f,maxHops:p-1},[T].concat(i),a,u)}}}return u},t}();function qt(t){return"0x"+t.raw.toString(16)}var St=function(){function t(){}return t.swapCallParameters=function(t,e,n){var r=e.inputAmount.currency===at[t],o=e.outputAmount.currency===at[t];r&&o&&c(!1),!("ttl"in n)||n.ttl>0||c(!1);var i,a,u,s=tt(n.recipient),d=qt(e.maximumAmountIn(t,n.allowedSlippage)),f=qt(e.minimumAmountOut(t,n.allowedSlippage)),h=e.route.path.map((function(t){return t.address})),p="ttl"in n?"0x"+(Math.floor((new Date).getTime()/1e3)+n.ttl).toString(16):"0x"+n.deadline.toString(16),l=Boolean(n.feeOnTransfer);switch(e.tradeType){case exports.TradeType.EXACT_INPUT:r?(i=l?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",a=[f,h,s,p],u=d):o?(i=l?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",a=[d,f,h,s,p],u="0x0"):(i=l?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",a=[d,f,h,s,p],u="0x0");break;case exports.TradeType.EXACT_OUTPUT:l&&c(!1),r?(i="swapETHForExactTokens",a=[f,h,s,p],u=d):o?(i="swapTokensForExactETH",a=[f,d,h,s,p],u="0x0"):(i="swapTokensForExactTokens",a=[f,d,h,s,p],u="0x0")}return{methodName:i,args:a,value:u}},t}(),Rt=[{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}],Pt={},Ft=function(){function t(){}return t.fetchTokenData=function(){var t=F(R().mark((function t(e,n,r,o,i){var a,u;return R().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===r&&(r=m.getDefaultProvider(v.getNetwork(e))),"number"!=typeof(null==(a=Pt)||null==(u=a[e])?void 0:u[n])){t.next=5;break}t.t0=Pt[e][n],t.next=8;break;case 5:return t.next=7,new l.Contract(n,Rt,r).decimals().then((function(t){var r,o,i;return Pt=M({},Pt,((i={})[e]=M({},null==(r=Pt)?void 0:r[e],((o={})[n]=t,o)),i)),t}));case 7:t.t0=t.sent;case 8:return t.abrupt("return",new st(e,n,t.t0,o,i));case 10:case"end":return t.stop()}}),t)})));return function(e,n,r,o,i){return t.apply(this,arguments)}}(),t.fetchPairData=function(){var t=F(R().mark((function t(e,n,r){var o,i,a,u,s;return R().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r=m.getDefaultProvider(v.getNetwork(e.chainId))),e.chainId!==n.chainId&&c(!1),o=Et.getAddress(e,n,!0),t.next=5,new l.Contract(o,y.abi,r).getReserves();case 5:return a=(i=t.sent)[0],u=i[1],s=e.sortsBefore(n)?[a,u]:[u,a],t.abrupt("return",new Et(new xt(e,s[0]),new xt(n,s[1])));case 10:case"end":return t.stop()}}),t)})));return function(e,n,r){return t.apply(this,arguments)}}(),t}();exports.JSBI=u,exports.Big=s,exports.Currency=ot,exports.CurrencyAmount=wt,exports.ETHER=ut,exports.FACTORY_ADDRESS=w,exports.FACTORY_ADDRESSES=g,exports.Fetcher=Ft,exports.Fraction=yt,exports.GAS_TOKENS=at,exports.INIT_CODE_HASH=x,exports.INIT_CODE_HASHES=I,exports.InsufficientInputAmountError=z,exports.InsufficientReservesError=$,exports.MINIMUM_LIQUIDITY=E,exports.Pair=Et,exports.Percent=Ct,exports.Price=gt,exports.Route=At,exports.Router=St,exports.Token=st,exports.TokenAmount=xt,exports.Trade=Bt,exports.WETH=ht,exports.currencyEquals=ct,exports.inputOutputComparator=kt,exports.tradeComparator=Ot; //# sourceMappingURL=sdk.cjs.production.min.js.map