@indexed-finance/narwhal-sdk
Advanced tools
Comparing version 0.0.1 to 1.0.1
@@ -6,3 +6,3 @@ import { ChainId } from '../constants'; | ||
import { Price } from './fractions/price'; | ||
export declare const packPathEntry: (pair: Pair, zeroForOne: boolean) => string; | ||
export declare function encodePathToken(token: Token, sushi: boolean): string; | ||
export declare class Route { | ||
@@ -9,0 +9,0 @@ readonly pairs: Pair[]; |
@@ -28,3 +28,3 @@ import { Pair } from './entities/pair'; | ||
*/ | ||
static fetchPairData(tokenA: Token, tokenB: Token, provider: import("@ethersproject/providers").BaseProvider | undefined, sushiswap: boolean): Promise<Pair>; | ||
static fetchPairData(tokenA: Token, tokenB: Token, sushiswap: boolean, provider?: import("@ethersproject/providers").BaseProvider): Promise<Pair>; | ||
} |
@@ -962,5 +962,5 @@ 'use strict'; | ||
var packPathEntry = function packPathEntry(pair, zeroForOne) { | ||
return ['0x', pair.liquidityToken.address.slice(2).padStart(62, '0'), zeroForOne ? '01' : '00'].join(''); | ||
}; | ||
function encodePathToken(token, sushi) { | ||
return ['0x', token.address.slice(2).padStart(62, '0'), sushi ? '01' : '00'].join(''); | ||
} | ||
var Route = /*#__PURE__*/function () { | ||
@@ -975,3 +975,3 @@ function Route(pairs, input, output) { | ||
var path = [input instanceof Token ? input : WETH[pairs[0].chainId]]; | ||
var encodedPath = []; | ||
var encodedPath = [encodePathToken(path[0], pairs[0].sushi)]; | ||
@@ -984,8 +984,13 @@ for (var _iterator = _createForOfIteratorHelperLoose(pairs.entries()), _step; !(_step = _iterator()).done;) { | ||
!(currentInput.equals(pair.token0) || currentInput.equals(pair.token1)) ? invariant(false, 'PATH') : void 0; | ||
var zeroForOne = currentInput.equals(pair.token0); | ||
var _output = zeroForOne ? pair.token1 : pair.token0; | ||
var _output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0; | ||
path.push(_output); | ||
encodedPath.push(packPathEntry(pair, zeroForOne)); | ||
var sushi = false; | ||
if (i < pairs.length - 1) { | ||
sushi = pairs[i + 1].sushi; | ||
} | ||
encodedPath.push(encodePathToken(_output, sushi)); | ||
} | ||
@@ -1571,3 +1576,3 @@ | ||
Fetcher.fetchPairData = function fetchPairData(tokenA, tokenB, provider, sushiswap) { | ||
Fetcher.fetchPairData = function fetchPairData(tokenA, tokenB, sushiswap, provider) { | ||
try { | ||
@@ -1614,5 +1619,5 @@ if (provider === undefined) provider = providers.getDefaultProvider(networks.getNetwork(tokenA.chainId)); | ||
exports.currencyEquals = currencyEquals; | ||
exports.encodePathToken = encodePathToken; | ||
exports.inputOutputComparator = inputOutputComparator; | ||
exports.packPathEntry = packPathEntry; | ||
exports.tradeComparator = tradeComparator; | ||
//# sourceMappingURL=narwhal-sdk.cjs.development.js.map |
@@ -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=t(require("jsbi")),u=t(require("tiny-invariant")),a=(t(require("tiny-warning")),require("@ethersproject/address")),s=t(require("big.js")),c=t(require("toformat")),p=t(require("decimal.js-light")),d=require("@ethersproject/solidity"),f=require("@ethersproject/contracts"),h=require("@ethersproject/networks"),l=require("@ethersproject/providers"),m=t(require("@uniswap/v2-core/build/IUniswapV2Pair.json"));(n=exports.ChainId||(exports.ChainId={}))[n.MAINNET=1]="MAINNET",n[n.ROPSTEN=3]="ROPSTEN",n[n.RINKEBY=4]="RINKEBY",n[n["GÖRLI"]=5]="GÖRLI",n[n.KOVAN=42]="KOVAN",(r=exports.TradeType||(exports.TradeType={}))[r.EXACT_INPUT=0]="EXACT_INPUT",r[r.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,y="0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303",w="0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",T=i.BigInt(1e3),g=i.BigInt(0),k=i.BigInt(1),x=i.BigInt(2),A=i.BigInt(3),I=i.BigInt(5),E=i.BigInt(10),O=i.BigInt(100),b=i.BigInt(997),q=i.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(v||(v={}));var N=((e={})[v.uint8]=i.BigInt("0xff"),e[v.uint256]=i.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),e);function P(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&&P(t.prototype,e),n&&P(t,n),t}function C(){return(C=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 _(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function U(t){return(U=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 S(){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 F(t,e,n){return(F=S()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&D(o,n.prototype),o}).apply(null,arguments)}function B(t){var e="function"==typeof Map?new Map:void 0;return(B=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 F(t,arguments,U(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),D(n,t)})(t)}function j(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function H(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 M(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 H(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)?H(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,L=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(j(n),(this instanceof e?this.constructor:void 0).prototype),n}return _(e,t),e}(B(Error)),X=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(j(n),(this instanceof e?this.constructor:void 0).prototype),n}return _(e,t),e}(B(Error));function K(t,e){i.greaterThanOrEqual(t,g)||u(!1),i.lessThanOrEqual(t,N[e])||u(!1)}function V(t){try{return a.getAddress(t)}catch(t){u(!1)}}function Y(t){return t instanceof i?t:i.BigInt("bigint"==typeof t?t.toString():t)}function G(t){K(t,v.uint256);var e,n=g;if(i.greaterThan(t,A))for(n=t,e=i.add(i.divide(t,x),k);i.lessThan(e,n);)n=e,e=i.divide(i.add(i.divide(t,e),e),x);else i.notEqual(t,g)&&(n=k);return n}function J(t,e,n,r){if(n>0||u(!1),t.length<=n||u(!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}var Q,$=function(t,e,n){K(i.BigInt(t),v.uint8),this.decimals=t,this.symbol=e,this.name=n},z=$.ETHER=new $(18,"ETH","Ether"),Z=function(t){function e(e,n,r,o,i){var u;return(u=t.call(this,r,o,i)||this).chainId=e,u.address=V(n),u}_(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&&u(!1),this.address===t.address&&u(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}($);function tt(t,e){return t instanceof Z&&e instanceof Z?t.equals(e):!(t instanceof Z||e instanceof Z||t!==e)}var et,nt,rt=((Q={})[exports.ChainId.MAINNET]=new Z(exports.ChainId.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),Q[exports.ChainId.ROPSTEN]=new Z(exports.ChainId.ROPSTEN,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),Q[exports.ChainId.RINKEBY]=new Z(exports.ChainId.RINKEBY,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),Q[exports.ChainId.GÖRLI]=new Z(exports.ChainId.GÖRLI,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH","Wrapped Ether"),Q[exports.ChainId.KOVAN]=new Z(exports.ChainId.KOVAN,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH","Wrapped Ether"),Q),ot=c(p),it=c(s),ut=((et={})[exports.Rounding.ROUND_DOWN]=ot.ROUND_DOWN,et[exports.Rounding.ROUND_HALF_UP]=ot.ROUND_HALF_UP,et[exports.Rounding.ROUND_UP]=ot.ROUND_UP,et),at=((nt={})[exports.Rounding.ROUND_DOWN]=0,nt[exports.Rounding.ROUND_HALF_UP]=1,nt[exports.Rounding.ROUND_UP]=3,nt),st=function(){function t(t,e){void 0===e&&(e=k),this.numerator=Y(t),this.denominator=Y(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(Y(e));return i.equal(this.denominator,n.denominator)?new t(i.add(this.numerator,n.numerator),this.denominator):new t(i.add(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator)),i.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=e instanceof t?e:new t(Y(e));return i.equal(this.denominator,n.denominator)?new t(i.subtract(this.numerator,n.numerator),this.denominator):new t(i.subtract(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator)),i.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=e instanceof t?e:new t(Y(e));return i.lessThan(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=e instanceof t?e:new t(Y(e));return i.equal(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=e instanceof t?e:new t(Y(e));return i.greaterThan(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=e instanceof t?e:new t(Y(e));return new t(i.multiply(this.numerator,n.numerator),i.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=e instanceof t?e:new t(Y(e));return new t(i.multiply(this.numerator,n.denominator),i.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)||u(!1),t>0||u(!1),ot.set({precision:t+1,rounding:ut[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)||u(!1),t>=0||u(!1),it.DP=t,it.RM=at[n],new it(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},R(t,[{key:"quotient",get:function(){return i.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(i.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),ct=c(s),pt=function(t){function e(e,n){var r,o=Y(n);return K(o,v.uint256),(r=t.call(this,o,i.exponentiate(E,i.BigInt(e.decimals)))||this).currency=e,r}_(e,t),e.ether=function(t){return new e(z,t)};var n=e.prototype;return n.add=function(t){return tt(this.currency,t.currency)||u(!1),new e(this.currency,i.add(this.raw,t.raw))},n.subtract=function(t){return tt(this.currency,t.currency)||u(!1),new e(this.currency,i.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||u(!1),t.prototype.toFixed.call(this,e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),ct.DP=this.currency.decimals,new ct(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},R(e,[{key:"raw",get:function(){return this.numerator}}]),e}(st),dt=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}_(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||u(!1),new e(this.token,i.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||u(!1),new e(this.token,i.subtract(this.raw,t.raw))},e}(pt),ft=function(t){function e(e,n,r,o){var u;return(u=t.call(this,o,r)||this).baseCurrency=e,u.quoteCurrency=n,u.scalar=new st(i.exponentiate(E,i.BigInt(e.decimals)),i.exponentiate(E,i.BigInt(n.decimals))),u}_(e,t),e.fromRoute=function(t){for(var n,r=[],o=M(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){tt(this.quoteCurrency,n.baseCurrency)||u(!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 tt(e.currency,this.baseCurrency)||u(!1),this.quoteCurrency instanceof Z?new dt(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):pt.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 st(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(st),ht={uniswap:{},sushiswap:{}},lt=function(){function t(e,n,r){this.sushi=r;var o=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new Z(o[0].token.chainId,t.getAddress(o[0].token,o[1].token,r),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=o}t.getAddress=function(t,e,n){var r,o,i,u,s,c=t.sortsBefore(e)?[t,e]:[e,t],p=n?"sushiswap":"uniswap";return void 0===(null===(r=ht[p])||void 0===r||null===(o=r[c[0].address])||void 0===o?void 0:o[c[1].address])&&(ht[p]=C({},ht[p],((s={})[c[0].address]=C({},null===(i=ht[p])||void 0===i?void 0:i[c[0].address],((u={})[c[1].address]=a.getCreate2Address(n?"0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac":"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",d.keccak256(["bytes"],[d.pack(["address","address"],[c[0].address,c[1].address])]),n?y:w),u)),s))),ht[p][c[0].address][c[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)||u(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||u(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||u(!1),i.equal(this.reserve0.raw,g)||i.equal(this.reserve1.raw,g))throw new L;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=i.multiply(e.raw,b),a=i.multiply(o,r.raw),s=i.add(i.multiply(n.raw,q),o),c=new dt(e.token.equals(this.token0)?this.token1:this.token0,i.divide(a,s));if(i.equal(c.raw,g))throw new X;return[c,new t(n.add(e),r.subtract(c),this.sushi)]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||u(!1),i.equal(this.reserve0.raw,g)||i.equal(this.reserve1.raw,g)||i.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new L;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=i.multiply(i.multiply(r.raw,e.raw),q),a=i.multiply(i.subtract(n.raw,e.raw),b),s=new dt(e.token.equals(this.token0)?this.token1:this.token0,i.add(i.divide(o,a),k));return[s,new t(r.add(s),n.subtract(e),this.sushi)]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||u(!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)||u(!1),i.equal(t.raw,g))r=i.subtract(G(i.multiply(o[0].raw,o[1].raw)),T);else{var a=i.divide(i.multiply(o[0].raw,t.raw),this.reserve0.raw),s=i.divide(i.multiply(o[1].raw,t.raw),this.reserve1.raw);r=i.lessThanOrEqual(a,s)?a:s}if(!i.greaterThan(r,g))throw new X;return new dt(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var a;if(void 0===r&&(r=!1),this.involvesToken(t)||u(!1),e.token.equals(this.liquidityToken)||u(!1),n.token.equals(this.liquidityToken)||u(!1),i.lessThanOrEqual(n.raw,e.raw)||u(!1),r){o||u(!1);var s=Y(o);if(i.equal(s,g))a=e;else{var c=G(i.multiply(this.reserve0.raw,this.reserve1.raw)),p=G(s);if(i.greaterThan(c,p)){var d=i.multiply(e.raw,i.subtract(c,p)),f=i.add(i.multiply(c,I),p),h=i.divide(d,f);a=e.add(new dt(this.liquidityToken,h))}else a=e}}else a=e;return new dt(t,i.divide(i.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}(),mt=function(t,e){return["0x",t.liquidityToken.address.slice(2).padStart(62,"0"),e?"01":"00"].join("")},vt=function(){function t(t,e,n){t.length>0||u(!1),t.every((function(e){return e.chainId===t[0].chainId}))||u(!1),e instanceof Z&&t[0].involvesToken(e)||e===z&&t[0].involvesToken(rt[t[0].chainId])||u(!1),void 0===n||n instanceof Z&&t[t.length-1].involvesToken(n)||n===z&&t[t.length-1].involvesToken(rt[t[0].chainId])||u(!1);for(var r,o=[e instanceof Z?e:rt[t[0].chainId]],i=[],a=M(t.entries());!(r=a()).done;){var s=r.value,c=s[1],p=o[s[0]];p.equals(c.token0)||p.equals(c.token1)||u(!1);var d=p.equals(c.token0);o.push(d?c.token1:c.token0),i.push(mt(c,d))}this.pairs=t,this.path=o,this.encodedPath=i,this.midPrice=ft.fromRoute(this),this.input=e,this.output=null!=n?n:o[o.length-1]}return R(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),yt=new st(O),wt=function(t){function e(){return t.apply(this,arguments)||this}_(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(yt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(yt).toFixed(t,e,n)},e}(st);function Tt(t,e){return tt(t.inputAmount.currency,e.inputAmount.currency)||u(!1),tt(t.outputAmount.currency,e.outputAmount.currency)||u(!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=Tt(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 dt?t:t.currency===z?new dt(rt[e],t.raw):void u(!1)}function xt(t,e){return t instanceof Z?t:t===z?rt[e]:void u(!1)}var At=function(){function t(t,e,n){var r,o,i,a=new Array(t.path.length),s=new Array(t.pairs.length);if(n===exports.TradeType.EXACT_INPUT){tt(e.currency,t.input)||u(!1),a[0]=kt(e,t.chainId);for(var c=0;c<t.path.length-1;c++){var p=t.pairs[c].getOutputAmount(a[c]),d=p[1];a[c+1]=p[0],s[c]=d}}else{tt(e.currency,t.output)||u(!1),a[a.length-1]=kt(e,t.chainId);for(var f=t.path.length-1;f>0;f--){var h=t.pairs[f-1].getInputAmount(a[f]),l=h[1];a[f-1]=h[0],s[f-1]=l}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===z?pt.ether(a[0].raw):a[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===z?pt.ether(a[a.length-1].raw):a[a.length-1],this.executionPrice=new ft(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=ft.fromRoute(new vt(s,t.input)),this.priceImpact=(r=this.outputAmount,i=(o=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(r.raw).divide(o),new wt(i.numerator,i.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(g)&&u(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new st(k).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof dt?new dt(this.outputAmount.token,e):pt.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(g)&&u(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new st(k).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof dt?new dt(this.inputAmount.token,e):pt.ether(e)},t.bestTradeExactIn=function(e,n,r,o,i,a,s){var c=void 0===o?{}:o,p=c.maxNumResults,d=void 0===p?3:p,f=c.maxHops,h=void 0===f?3:f;void 0===i&&(i=[]),void 0===a&&(a=n),void 0===s&&(s=[]),e.length>0||u(!1),h>0||u(!1),a===n||i.length>0||u(!1);var l=n instanceof dt?n.token.chainId:r instanceof Z?r.chainId:void 0;void 0===l&&u(!1);for(var m=kt(n,l),v=xt(r,l),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(m.token)||w.token1.equals(m.token))&&!w.reserve0.equalTo(g)&&!w.reserve1.equalTo(g)){var T=void 0;try{T=w.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(T.token.equals(v))J(s,new t(new vt([].concat(i,[w]),a.currency,r),a,exports.TradeType.EXACT_INPUT),d,gt);else if(h>1&&e.length>1){var k=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(k,T,r,{maxNumResults:d,maxHops:h-1},[].concat(i,[w]),a,s)}}}return s},t.bestTradeExactOut=function(e,n,r,o,i,a,s){var c=void 0===o?{}:o,p=c.maxNumResults,d=void 0===p?3:p,f=c.maxHops,h=void 0===f?3:f;void 0===i&&(i=[]),void 0===a&&(a=r),void 0===s&&(s=[]),e.length>0||u(!1),h>0||u(!1),a===r||i.length>0||u(!1);var l=r instanceof dt?r.token.chainId:n instanceof Z?n.chainId:void 0;void 0===l&&u(!1);for(var m=kt(r,l),v=xt(n,l),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(m.token)||w.token1.equals(m.token))&&!w.reserve0.equalTo(g)&&!w.reserve1.equalTo(g)){var T=void 0;try{T=w.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(T.token.equals(v))J(s,new t(new vt([w].concat(i),n,a.currency),a,exports.TradeType.EXACT_OUTPUT),d,gt);else if(h>1&&e.length>1){var k=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(k,n,T,{maxNumResults:d,maxHops:h-1},[w].concat(i),a,s)}}}return s},t}();function It(t){return"0x"+t.raw.toString(16)}var Et,Ot=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===z,r=t.outputAmount.currency===z;n&&r&&u(!1),e.ttl>0||u(!1);var o,i,a,s=V(e.recipient),c=It(t.maximumAmountIn(e.allowedSlippage)),p=It(t.minimumAmountOut(e.allowedSlippage)),d=t.route.encodedPath,f="0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16),h=Boolean(e.feeOnTransfer);switch(t.tradeType){case exports.TradeType.EXACT_INPUT:n?(o=h?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[p,d,s,f],a=c):r?(o=h?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[c,p,d,s,f],a="0x0"):(o=h?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[c,p,d,s,f],a="0x0");break;case exports.TradeType.EXACT_OUTPUT:h&&u(!1),n?(o="swapETHForExactTokens",i=[p,d,s,f],a=c):r?(o="swapTokensForExactETH",i=[p,c,d,s,f],a="0x0"):(o="swapTokensForExactTokens",i=[p,c,d,s,f],a="0x0")}return{methodName:o,args:i,value:a}},t}(),bt=[{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"}],qt=((Et={})[exports.ChainId.MAINNET]={"0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A":9},Et),Nt=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,u,a=function(n){return new Z(t,e,n,r,o)};void 0===n&&(n=l.getDefaultProvider(h.getNetwork(t)));var s="number"==typeof(null===(i=qt)||void 0===i||null===(u=i[t])||void 0===u?void 0:u[e]);return Promise.resolve(s?a(qt[t][e]):Promise.resolve(new f.Contract(e,bt,n).decimals().then((function(n){var r,o,i;return qt=C({},qt,((i={})[t]=C({},null===(r=qt)||void 0===r?void 0:r[t],((o={})[e]=n,o)),i)),n}))).then(a))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e,n,r){try{void 0===n&&(n=l.getDefaultProvider(h.getNetwork(t.chainId))),t.chainId!==e.chainId&&u(!1);var o=lt.getAddress(t,e,r);return Promise.resolve(new f.Contract(o,m.abi,n).getReserves()).then((function(n){var r=n[0],o=n[1],i=t.sortsBefore(e)?[r,o]:[o,r];return new lt(new dt(t,i[0]),new dt(e,i[1]),!0)}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=i,exports.Currency=$,exports.CurrencyAmount=pt,exports.ETHER=z,exports.FACTORY_ADDRESS_SUSHI="0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac",exports.FACTORY_ADDRESS_UNI="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.Fetcher=Nt,exports.Fraction=st,exports.INIT_CODE_HASH_SUSHI=y,exports.INIT_CODE_HASH_UNI=w,exports.InsufficientInputAmountError=X,exports.InsufficientReservesError=L,exports.MINIMUM_LIQUIDITY=T,exports.Pair=lt,exports.Percent=wt,exports.Price=ft,exports.Route=vt,exports.Router=Ot,exports.Token=Z,exports.TokenAmount=dt,exports.Trade=At,exports.WETH=rt,exports.currencyEquals=tt,exports.inputOutputComparator=Tt,exports.packPathEntry=mt,exports.tradeComparator=gt; | ||
"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=t(require("jsbi")),u=t(require("tiny-invariant")),a=(t(require("tiny-warning")),require("@ethersproject/address")),s=t(require("big.js")),c=t(require("toformat")),d=t(require("decimal.js-light")),p=require("@ethersproject/solidity"),f=require("@ethersproject/contracts"),h=require("@ethersproject/networks"),l=require("@ethersproject/providers"),m=t(require("@uniswap/v2-core/build/IUniswapV2Pair.json"));(n=exports.ChainId||(exports.ChainId={}))[n.MAINNET=1]="MAINNET",n[n.ROPSTEN=3]="ROPSTEN",n[n.RINKEBY=4]="RINKEBY",n[n["GÖRLI"]=5]="GÖRLI",n[n.KOVAN=42]="KOVAN",(r=exports.TradeType||(exports.TradeType={}))[r.EXACT_INPUT=0]="EXACT_INPUT",r[r.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,y="0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303",w="0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",T=i.BigInt(1e3),g=i.BigInt(0),k=i.BigInt(1),x=i.BigInt(2),A=i.BigInt(3),I=i.BigInt(5),E=i.BigInt(10),O=i.BigInt(100),b=i.BigInt(997),q=i.BigInt(1e3);!function(t){t.uint8="uint8",t.uint256="uint256"}(v||(v={}));var N=((e={})[v.uint8]=i.BigInt("0xff"),e[v.uint256]=i.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),e);function P(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&&P(t.prototype,e),n&&P(t,n),t}function C(){return(C=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 _(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function U(t){return(U=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 S(){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 F(t,e,n){return(F=S()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&D(o,n.prototype),o}).apply(null,arguments)}function B(t){var e="function"==typeof Map?new Map:void 0;return(B=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 F(t,arguments,U(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),D(n,t)})(t)}function j(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function H(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 M(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 H(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)?H(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,L=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(j(n),(this instanceof e?this.constructor:void 0).prototype),n}return _(e,t),e}(B(Error)),X=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,W&&Object.setPrototypeOf(j(n),(this instanceof e?this.constructor:void 0).prototype),n}return _(e,t),e}(B(Error));function K(t,e){i.greaterThanOrEqual(t,g)||u(!1),i.lessThanOrEqual(t,N[e])||u(!1)}function V(t){try{return a.getAddress(t)}catch(t){u(!1)}}function Y(t){return t instanceof i?t:i.BigInt("bigint"==typeof t?t.toString():t)}function G(t){K(t,v.uint256);var e,n=g;if(i.greaterThan(t,A))for(n=t,e=i.add(i.divide(t,x),k);i.lessThan(e,n);)n=e,e=i.divide(i.add(i.divide(t,e),e),x);else i.notEqual(t,g)&&(n=k);return n}function J(t,e,n,r){if(n>0||u(!1),t.length<=n||u(!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}var Q,$=function(t,e,n){K(i.BigInt(t),v.uint8),this.decimals=t,this.symbol=e,this.name=n},z=$.ETHER=new $(18,"ETH","Ether"),Z=function(t){function e(e,n,r,o,i){var u;return(u=t.call(this,r,o,i)||this).chainId=e,u.address=V(n),u}_(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&&u(!1),this.address===t.address&&u(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}($);function tt(t,e){return t instanceof Z&&e instanceof Z?t.equals(e):!(t instanceof Z||e instanceof Z||t!==e)}var et,nt,rt=((Q={})[exports.ChainId.MAINNET]=new Z(exports.ChainId.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),Q[exports.ChainId.ROPSTEN]=new Z(exports.ChainId.ROPSTEN,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),Q[exports.ChainId.RINKEBY]=new Z(exports.ChainId.RINKEBY,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),Q[exports.ChainId.GÖRLI]=new Z(exports.ChainId.GÖRLI,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH","Wrapped Ether"),Q[exports.ChainId.KOVAN]=new Z(exports.ChainId.KOVAN,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH","Wrapped Ether"),Q),ot=c(d),it=c(s),ut=((et={})[exports.Rounding.ROUND_DOWN]=ot.ROUND_DOWN,et[exports.Rounding.ROUND_HALF_UP]=ot.ROUND_HALF_UP,et[exports.Rounding.ROUND_UP]=ot.ROUND_UP,et),at=((nt={})[exports.Rounding.ROUND_DOWN]=0,nt[exports.Rounding.ROUND_HALF_UP]=1,nt[exports.Rounding.ROUND_UP]=3,nt),st=function(){function t(t,e){void 0===e&&(e=k),this.numerator=Y(t),this.denominator=Y(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(Y(e));return i.equal(this.denominator,n.denominator)?new t(i.add(this.numerator,n.numerator),this.denominator):new t(i.add(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator)),i.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=e instanceof t?e:new t(Y(e));return i.equal(this.denominator,n.denominator)?new t(i.subtract(this.numerator,n.numerator),this.denominator):new t(i.subtract(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator)),i.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=e instanceof t?e:new t(Y(e));return i.lessThan(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=e instanceof t?e:new t(Y(e));return i.equal(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=e instanceof t?e:new t(Y(e));return i.greaterThan(i.multiply(this.numerator,n.denominator),i.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=e instanceof t?e:new t(Y(e));return new t(i.multiply(this.numerator,n.numerator),i.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=e instanceof t?e:new t(Y(e));return new t(i.multiply(this.numerator,n.denominator),i.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)||u(!1),t>0||u(!1),ot.set({precision:t+1,rounding:ut[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)||u(!1),t>=0||u(!1),it.DP=t,it.RM=at[n],new it(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},R(t,[{key:"quotient",get:function(){return i.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(i.remainder(this.numerator,this.denominator),this.denominator)}}]),t}(),ct=c(s),dt=function(t){function e(e,n){var r,o=Y(n);return K(o,v.uint256),(r=t.call(this,o,i.exponentiate(E,i.BigInt(e.decimals)))||this).currency=e,r}_(e,t),e.ether=function(t){return new e(z,t)};var n=e.prototype;return n.add=function(t){return tt(this.currency,t.currency)||u(!1),new e(this.currency,i.add(this.raw,t.raw))},n.subtract=function(t){return tt(this.currency,t.currency)||u(!1),new e(this.currency,i.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||u(!1),t.prototype.toFixed.call(this,e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),ct.DP=this.currency.decimals,new ct(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)},R(e,[{key:"raw",get:function(){return this.numerator}}]),e}(st),pt=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).token=e,r}_(e,t);var n=e.prototype;return n.add=function(t){return this.token.equals(t.token)||u(!1),new e(this.token,i.add(this.raw,t.raw))},n.subtract=function(t){return this.token.equals(t.token)||u(!1),new e(this.token,i.subtract(this.raw,t.raw))},e}(dt),ft=function(t){function e(e,n,r,o){var u;return(u=t.call(this,o,r)||this).baseCurrency=e,u.quoteCurrency=n,u.scalar=new st(i.exponentiate(E,i.BigInt(e.decimals)),i.exponentiate(E,i.BigInt(n.decimals))),u}_(e,t),e.fromRoute=function(t){for(var n,r=[],o=M(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){tt(this.quoteCurrency,n.baseCurrency)||u(!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 tt(e.currency,this.baseCurrency)||u(!1),this.quoteCurrency instanceof Z?new pt(this.quoteCurrency,t.prototype.multiply.call(this,e.raw).quotient):dt.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 st(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(st),ht={uniswap:{},sushiswap:{}},lt=function(){function t(e,n,r){this.sushi=r;var o=e.token.sortsBefore(n.token)?[e,n]:[n,e];this.liquidityToken=new Z(o[0].token.chainId,t.getAddress(o[0].token,o[1].token,r),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=o}t.getAddress=function(t,e,n){var r,o,i,u,s,c=t.sortsBefore(e)?[t,e]:[e,t],d=n?"sushiswap":"uniswap";return void 0===(null===(r=ht[d])||void 0===r||null===(o=r[c[0].address])||void 0===o?void 0:o[c[1].address])&&(ht[d]=C({},ht[d],((s={})[c[0].address]=C({},null===(i=ht[d])||void 0===i?void 0:i[c[0].address],((u={})[c[1].address]=a.getCreate2Address(n?"0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac":"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",p.keccak256(["bytes"],[p.pack(["address","address"],[c[0].address,c[1].address])]),n?y:w),u)),s))),ht[d][c[0].address][c[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)||u(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||u(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(e){if(this.involvesToken(e.token)||u(!1),i.equal(this.reserve0.raw,g)||i.equal(this.reserve1.raw,g))throw new L;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=i.multiply(e.raw,b),a=i.multiply(o,r.raw),s=i.add(i.multiply(n.raw,q),o),c=new pt(e.token.equals(this.token0)?this.token1:this.token0,i.divide(a,s));if(i.equal(c.raw,g))throw new X;return[c,new t(n.add(e),r.subtract(c),this.sushi)]},e.getInputAmount=function(e){if(this.involvesToken(e.token)||u(!1),i.equal(this.reserve0.raw,g)||i.equal(this.reserve1.raw,g)||i.greaterThanOrEqual(e.raw,this.reserveOf(e.token).raw))throw new L;var n=this.reserveOf(e.token),r=this.reserveOf(e.token.equals(this.token0)?this.token1:this.token0),o=i.multiply(i.multiply(r.raw,e.raw),q),a=i.multiply(i.subtract(n.raw,e.raw),b),s=new pt(e.token.equals(this.token0)?this.token1:this.token0,i.add(i.divide(o,a),k));return[s,new t(r.add(s),n.subtract(e),this.sushi)]},e.getLiquidityMinted=function(t,e,n){t.token.equals(this.liquidityToken)||u(!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)||u(!1),i.equal(t.raw,g))r=i.subtract(G(i.multiply(o[0].raw,o[1].raw)),T);else{var a=i.divide(i.multiply(o[0].raw,t.raw),this.reserve0.raw),s=i.divide(i.multiply(o[1].raw,t.raw),this.reserve1.raw);r=i.lessThanOrEqual(a,s)?a:s}if(!i.greaterThan(r,g))throw new X;return new pt(this.liquidityToken,r)},e.getLiquidityValue=function(t,e,n,r,o){var a;if(void 0===r&&(r=!1),this.involvesToken(t)||u(!1),e.token.equals(this.liquidityToken)||u(!1),n.token.equals(this.liquidityToken)||u(!1),i.lessThanOrEqual(n.raw,e.raw)||u(!1),r){o||u(!1);var s=Y(o);if(i.equal(s,g))a=e;else{var c=G(i.multiply(this.reserve0.raw,this.reserve1.raw)),d=G(s);if(i.greaterThan(c,d)){var p=i.multiply(e.raw,i.subtract(c,d)),f=i.add(i.multiply(c,I),d),h=i.divide(p,f);a=e.add(new pt(this.liquidityToken,h))}else a=e}}else a=e;return new pt(t,i.divide(i.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}();function mt(t,e){return["0x",t.address.slice(2).padStart(62,"0"),e?"01":"00"].join("")}var vt=function(){function t(t,e,n){t.length>0||u(!1),t.every((function(e){return e.chainId===t[0].chainId}))||u(!1),e instanceof Z&&t[0].involvesToken(e)||e===z&&t[0].involvesToken(rt[t[0].chainId])||u(!1),void 0===n||n instanceof Z&&t[t.length-1].involvesToken(n)||n===z&&t[t.length-1].involvesToken(rt[t[0].chainId])||u(!1);for(var r,o=[e instanceof Z?e:rt[t[0].chainId]],i=[mt(o[0],t[0].sushi)],a=M(t.entries());!(r=a()).done;){var s=r.value,c=s[0],d=s[1],p=o[c];p.equals(d.token0)||p.equals(d.token1)||u(!1);var f=p.equals(d.token0)?d.token1:d.token0;o.push(f);var h=!1;c<t.length-1&&(h=t[c+1].sushi),i.push(mt(f,h))}this.pairs=t,this.path=o,this.encodedPath=i,this.midPrice=ft.fromRoute(this),this.input=e,this.output=null!=n?n:o[o.length-1]}return R(t,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}(),yt=new st(O),wt=function(t){function e(){return t.apply(this,arguments)||this}_(e,t);var n=e.prototype;return n.toSignificant=function(t,e,n){return void 0===t&&(t=5),this.multiply(yt).toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=2),this.multiply(yt).toFixed(t,e,n)},e}(st);function Tt(t,e){return tt(t.inputAmount.currency,e.inputAmount.currency)||u(!1),tt(t.outputAmount.currency,e.outputAmount.currency)||u(!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=Tt(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 pt?t:t.currency===z?new pt(rt[e],t.raw):void u(!1)}function xt(t,e){return t instanceof Z?t:t===z?rt[e]:void u(!1)}var At=function(){function t(t,e,n){var r,o,i,a=new Array(t.path.length),s=new Array(t.pairs.length);if(n===exports.TradeType.EXACT_INPUT){tt(e.currency,t.input)||u(!1),a[0]=kt(e,t.chainId);for(var c=0;c<t.path.length-1;c++){var d=t.pairs[c].getOutputAmount(a[c]),p=d[1];a[c+1]=d[0],s[c]=p}}else{tt(e.currency,t.output)||u(!1),a[a.length-1]=kt(e,t.chainId);for(var f=t.path.length-1;f>0;f--){var h=t.pairs[f-1].getInputAmount(a[f]),l=h[1];a[f-1]=h[0],s[f-1]=l}}this.route=t,this.tradeType=n,this.inputAmount=n===exports.TradeType.EXACT_INPUT?e:t.input===z?dt.ether(a[0].raw):a[0],this.outputAmount=n===exports.TradeType.EXACT_OUTPUT?e:t.output===z?dt.ether(a[a.length-1].raw):a[a.length-1],this.executionPrice=new ft(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=ft.fromRoute(new vt(s,t.input)),this.priceImpact=(r=this.outputAmount,i=(o=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(r.raw).divide(o),new wt(i.numerator,i.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(g)&&u(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new st(k).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof pt?new pt(this.outputAmount.token,e):dt.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(g)&&u(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return this.inputAmount;var e=new st(k).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof pt?new pt(this.inputAmount.token,e):dt.ether(e)},t.bestTradeExactIn=function(e,n,r,o,i,a,s){var c=void 0===o?{}:o,d=c.maxNumResults,p=void 0===d?3:d,f=c.maxHops,h=void 0===f?3:f;void 0===i&&(i=[]),void 0===a&&(a=n),void 0===s&&(s=[]),e.length>0||u(!1),h>0||u(!1),a===n||i.length>0||u(!1);var l=n instanceof pt?n.token.chainId:r instanceof Z?r.chainId:void 0;void 0===l&&u(!1);for(var m=kt(n,l),v=xt(r,l),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(m.token)||w.token1.equals(m.token))&&!w.reserve0.equalTo(g)&&!w.reserve1.equalTo(g)){var T=void 0;try{T=w.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(T.token.equals(v))J(s,new t(new vt([].concat(i,[w]),a.currency,r),a,exports.TradeType.EXACT_INPUT),p,gt);else if(h>1&&e.length>1){var k=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(k,T,r,{maxNumResults:p,maxHops:h-1},[].concat(i,[w]),a,s)}}}return s},t.bestTradeExactOut=function(e,n,r,o,i,a,s){var c=void 0===o?{}:o,d=c.maxNumResults,p=void 0===d?3:d,f=c.maxHops,h=void 0===f?3:f;void 0===i&&(i=[]),void 0===a&&(a=r),void 0===s&&(s=[]),e.length>0||u(!1),h>0||u(!1),a===r||i.length>0||u(!1);var l=r instanceof pt?r.token.chainId:n instanceof Z?n.chainId:void 0;void 0===l&&u(!1);for(var m=kt(r,l),v=xt(n,l),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(m.token)||w.token1.equals(m.token))&&!w.reserve0.equalTo(g)&&!w.reserve1.equalTo(g)){var T=void 0;try{T=w.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(T.token.equals(v))J(s,new t(new vt([w].concat(i),n,a.currency),a,exports.TradeType.EXACT_OUTPUT),p,gt);else if(h>1&&e.length>1){var k=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(k,n,T,{maxNumResults:p,maxHops:h-1},[w].concat(i),a,s)}}}return s},t}();function It(t){return"0x"+t.raw.toString(16)}var Et,Ot=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===z,r=t.outputAmount.currency===z;n&&r&&u(!1),e.ttl>0||u(!1);var o,i,a,s=V(e.recipient),c=It(t.maximumAmountIn(e.allowedSlippage)),d=It(t.minimumAmountOut(e.allowedSlippage)),p=t.route.encodedPath,f="0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16),h=Boolean(e.feeOnTransfer);switch(t.tradeType){case exports.TradeType.EXACT_INPUT:n?(o=h?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[d,p,s,f],a=c):r?(o=h?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[c,d,p,s,f],a="0x0"):(o=h?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[c,d,p,s,f],a="0x0");break;case exports.TradeType.EXACT_OUTPUT:h&&u(!1),n?(o="swapETHForExactTokens",i=[d,p,s,f],a=c):r?(o="swapTokensForExactETH",i=[d,c,p,s,f],a="0x0"):(o="swapTokensForExactTokens",i=[d,c,p,s,f],a="0x0")}return{methodName:o,args:i,value:a}},t}(),bt=[{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"}],qt=((Et={})[exports.ChainId.MAINNET]={"0xE0B7927c4aF23765Cb51314A0E0521A9645F0E2A":9},Et),Nt=function(){function t(){}return t.fetchTokenData=function(t,e,n,r,o){try{var i,u,a=function(n){return new Z(t,e,n,r,o)};void 0===n&&(n=l.getDefaultProvider(h.getNetwork(t)));var s="number"==typeof(null===(i=qt)||void 0===i||null===(u=i[t])||void 0===u?void 0:u[e]);return Promise.resolve(s?a(qt[t][e]):Promise.resolve(new f.Contract(e,bt,n).decimals().then((function(n){var r,o,i;return qt=C({},qt,((i={})[t]=C({},null===(r=qt)||void 0===r?void 0:r[t],((o={})[e]=n,o)),i)),n}))).then(a))}catch(t){return Promise.reject(t)}},t.fetchPairData=function(t,e,n,r){try{void 0===r&&(r=l.getDefaultProvider(h.getNetwork(t.chainId))),t.chainId!==e.chainId&&u(!1);var o=lt.getAddress(t,e,n);return Promise.resolve(new f.Contract(o,m.abi,r).getReserves()).then((function(n){var r=n[0],o=n[1],i=t.sortsBefore(e)?[r,o]:[o,r];return new lt(new pt(t,i[0]),new pt(e,i[1]),!0)}))}catch(t){return Promise.reject(t)}},t}();exports.JSBI=i,exports.Currency=$,exports.CurrencyAmount=dt,exports.ETHER=z,exports.FACTORY_ADDRESS_SUSHI="0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac",exports.FACTORY_ADDRESS_UNI="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.Fetcher=Nt,exports.Fraction=st,exports.INIT_CODE_HASH_SUSHI=y,exports.INIT_CODE_HASH_UNI=w,exports.InsufficientInputAmountError=X,exports.InsufficientReservesError=L,exports.MINIMUM_LIQUIDITY=T,exports.Pair=lt,exports.Percent=wt,exports.Price=ft,exports.Route=vt,exports.Router=Ot,exports.Token=Z,exports.TokenAmount=pt,exports.Trade=At,exports.WETH=rt,exports.currencyEquals=tt,exports.encodePathToken=mt,exports.inputOutputComparator=Tt,exports.tradeComparator=gt; | ||
//# sourceMappingURL=narwhal-sdk.cjs.production.min.js.map |
@@ -962,5 +962,5 @@ import JSBI from 'jsbi'; | ||
var packPathEntry = function packPathEntry(pair, zeroForOne) { | ||
return ['0x', pair.liquidityToken.address.slice(2).padStart(62, '0'), zeroForOne ? '01' : '00'].join(''); | ||
}; | ||
function encodePathToken(token, sushi) { | ||
return ['0x', token.address.slice(2).padStart(62, '0'), sushi ? '01' : '00'].join(''); | ||
} | ||
var Route = /*#__PURE__*/function () { | ||
@@ -975,3 +975,3 @@ function Route(pairs, input, output) { | ||
var path = [input instanceof Token ? input : WETH[pairs[0].chainId]]; | ||
var encodedPath = []; | ||
var encodedPath = [encodePathToken(path[0], pairs[0].sushi)]; | ||
@@ -984,8 +984,13 @@ for (var _iterator = _createForOfIteratorHelperLoose(pairs.entries()), _step; !(_step = _iterator()).done;) { | ||
!(currentInput.equals(pair.token0) || currentInput.equals(pair.token1)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'PATH') : invariant(false) : void 0; | ||
var zeroForOne = currentInput.equals(pair.token0); | ||
var _output = zeroForOne ? pair.token1 : pair.token0; | ||
var _output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0; | ||
path.push(_output); | ||
encodedPath.push(packPathEntry(pair, zeroForOne)); | ||
var sushi = false; | ||
if (i < pairs.length - 1) { | ||
sushi = pairs[i + 1].sushi; | ||
} | ||
encodedPath.push(encodePathToken(_output, sushi)); | ||
} | ||
@@ -1571,3 +1576,3 @@ | ||
Fetcher.fetchPairData = function fetchPairData(tokenA, tokenB, provider, sushiswap) { | ||
Fetcher.fetchPairData = function fetchPairData(tokenA, tokenB, sushiswap, provider) { | ||
try { | ||
@@ -1591,3 +1596,3 @@ if (provider === undefined) provider = getDefaultProvider(getNetwork(tokenA.chainId)); | ||
export { ChainId, Currency, CurrencyAmount, ETHER, FACTORY_ADDRESS_SUSHI, FACTORY_ADDRESS_UNI, Fetcher, Fraction, INIT_CODE_HASH_SUSHI, INIT_CODE_HASH_UNI, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, Pair, Percent, Price, Rounding, Route, Router, Token, TokenAmount, Trade, TradeType, WETH, currencyEquals, inputOutputComparator, packPathEntry, tradeComparator }; | ||
export { ChainId, Currency, CurrencyAmount, ETHER, FACTORY_ADDRESS_SUSHI, FACTORY_ADDRESS_UNI, Fetcher, Fraction, INIT_CODE_HASH_SUSHI, INIT_CODE_HASH_UNI, InsufficientInputAmountError, InsufficientReservesError, MINIMUM_LIQUIDITY, Pair, Percent, Price, Rounding, Route, Router, Token, TokenAmount, Trade, TradeType, WETH, currencyEquals, encodePathToken, inputOutputComparator, tradeComparator }; | ||
//# sourceMappingURL=narwhal-sdk.esm.js.map |
{ | ||
"name": "@indexed-finance/narwhal-sdk", | ||
"license": "MIT", | ||
"version": "0.0.1", | ||
"version": "1.0.1", | ||
"description": "🛠 An SDK for building applications on top of Sushiswap and Uniswap.", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
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 not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
460656
3197
2