@ape.swap/sdk-core
Version:
⚒️ An SDK for building applications on top of Apeswap
3 lines (2 loc) • 11.3 kB
JavaScript
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var r,e,n,i=t(require("jsbi")),o=t(require("tiny-invariant")),a=t(require("decimal.js-light")),u=t(require("big.js")),s=t(require("toformat")),c=require("@ethersproject/address");(r=exports.SupportedChainId||(exports.SupportedChainId={}))[r.MAINNET=1]="MAINNET",r[r.ARBITRUM_ONE=42161]="ARBITRUM_ONE",r[r.POLYGON=137]="POLYGON",r[r.POLYGON_MUMBAI=80001]="POLYGON_MUMBAI",r[r.BSC=56]="BSC",r[r.BSC_TESTNET=97]="BSC_TESTNET",r[r.TLOS=40]="TLOS",(e=exports.TradeType||(exports.TradeType={}))[e.EXACT_INPUT=0]="EXACT_INPUT",e[e.EXACT_OUTPUT=1]="EXACT_OUTPUT",(n=exports.Rounding||(exports.Rounding={}))[n.ROUND_DOWN=0]="ROUND_DOWN",n[n.ROUND_HALF_UP=1]="ROUND_HALF_UP",n[n.ROUND_UP=2]="ROUND_UP";var d,f,l=i.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function p(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,"symbol"==typeof(i=function(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(n.key))?i:String(i),n)}var i}function m(t,r,e){return r&&p(t.prototype,r),e&&p(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function h(t,r){var e,n;t.prototype=Object.create(r.prototype),t.prototype.constructor=t,e=t,n=r,(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t})(e,n)}var y=s(a),v=s(u),g=((d={})[exports.Rounding.ROUND_DOWN]=y.ROUND_DOWN,d[exports.Rounding.ROUND_HALF_UP]=y.ROUND_HALF_UP,d[exports.Rounding.ROUND_UP]=y.ROUND_UP,d),x=((f={})[exports.Rounding.ROUND_DOWN]=0,f[exports.Rounding.ROUND_HALF_UP]=1,f[exports.Rounding.ROUND_UP]=3,f),T=function(){function t(t,r){void 0===r&&(r=i.BigInt(1)),this.numerator=i.BigInt(t),this.denominator=i.BigInt(r)}t.tryParseFraction=function(r){if(r instanceof i||"number"==typeof r||"string"==typeof r)return new t(r);if("numerator"in r&&"denominator"in r)return r;throw new Error("Could not parse fraction")};var r=t.prototype;return r.invert=function(){return new t(this.denominator,this.numerator)},r.add=function(r){var e=t.tryParseFraction(r);return i.equal(this.denominator,e.denominator)?new t(i.add(this.numerator,e.numerator),this.denominator):new t(i.add(i.multiply(this.numerator,e.denominator),i.multiply(e.numerator,this.denominator)),i.multiply(this.denominator,e.denominator))},r.subtract=function(r){var e=t.tryParseFraction(r);return i.equal(this.denominator,e.denominator)?new t(i.subtract(this.numerator,e.numerator),this.denominator):new t(i.subtract(i.multiply(this.numerator,e.denominator),i.multiply(e.numerator,this.denominator)),i.multiply(this.denominator,e.denominator))},r.lessThan=function(r){var e=t.tryParseFraction(r);return i.lessThan(i.multiply(this.numerator,e.denominator),i.multiply(e.numerator,this.denominator))},r.equalTo=function(r){var e=t.tryParseFraction(r);return i.equal(i.multiply(this.numerator,e.denominator),i.multiply(e.numerator,this.denominator))},r.greaterThan=function(r){var e=t.tryParseFraction(r);return i.greaterThan(i.multiply(this.numerator,e.denominator),i.multiply(e.numerator,this.denominator))},r.multiply=function(r){var e=t.tryParseFraction(r);return new t(i.multiply(this.numerator,e.numerator),i.multiply(this.denominator,e.denominator))},r.divide=function(r){var e=t.tryParseFraction(r);return new t(i.multiply(this.numerator,e.denominator),i.multiply(this.denominator,e.numerator))},r.toSignificant=function(t,r,e){void 0===r&&(r={groupSeparator:""}),void 0===e&&(e=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||o(!1),t>0||o(!1),y.set({precision:t+1,rounding:g[e]});var n=new y(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return n.toFormat(n.decimalPlaces(),r)},r.toFixed=function(t,r,e){return void 0===r&&(r={groupSeparator:""}),void 0===e&&(e=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||o(!1),t>=0||o(!1),v.DP=t,v.RM=x[e],new v(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)},m(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)}},{key:"asFraction",get:function(){return new t(this.numerator,this.denominator)}}]),t}(),N=s(u),b=function(t){function r(r,e,n){var a;return a=t.call(this,e,n)||this,i.lessThanOrEqual(a.quotient,l)||o(!1),a.currency=r,a.decimalScale=i.exponentiate(i.BigInt(10),i.BigInt(r.decimals)),a}h(r,t),r.fromRawAmount=function(t,e){return new r(t,e)},r.fromFractionalAmount=function(t,e,n){return new r(t,e,n)};var e=r.prototype;return e.add=function(e){this.currency.equals(e.currency)||o(!1);var n=t.prototype.add.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},e.subtract=function(e){this.currency.equals(e.currency)||o(!1);var n=t.prototype.subtract.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},e.multiply=function(e){var n=t.prototype.multiply.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},e.divide=function(e){var n=t.prototype.divide.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},e.toSignificant=function(r,e,n){return void 0===r&&(r=6),void 0===n&&(n=exports.Rounding.ROUND_DOWN),t.prototype.divide.call(this,this.decimalScale).toSignificant(r,e,n)},e.toFixed=function(r,e,n){return void 0===r&&(r=this.currency.decimals),void 0===n&&(n=exports.Rounding.ROUND_DOWN),r<=this.currency.decimals||o(!1),t.prototype.divide.call(this,this.decimalScale).toFixed(r,e,n)},e.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),N.DP=this.currency.decimals,new N(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(t)},m(r,[{key:"wrapped",get:function(){return this.currency.isToken?this:r.fromFractionalAmount(this.currency.wrapped,this.numerator,this.denominator)}}]),r}(T),E=new T(i.BigInt(100));function F(t){return new O(t.numerator,t.denominator)}var O=function(t){function r(){var r;return(r=t.apply(this,arguments)||this).isPercent=!0,r}h(r,t);var e=r.prototype;return e.add=function(r){return F(t.prototype.add.call(this,r))},e.subtract=function(r){return F(t.prototype.subtract.call(this,r))},e.multiply=function(r){return F(t.prototype.multiply.call(this,r))},e.divide=function(r){return F(t.prototype.divide.call(this,r))},e.toSignificant=function(r,e,n){return void 0===r&&(r=5),t.prototype.multiply.call(this,E).toSignificant(r,e,n)},e.toFixed=function(r,e,n){return void 0===r&&(r=2),t.prototype.multiply.call(this,E).toFixed(r,e,n)},r}(T),w=function(t){function r(){for(var r,e,n,o,a,u=arguments.length,s=new Array(u),c=0;c<u;c++)s[c]=arguments[c];if(4===s.length)e=s[0],n=s[1],o=s[2],a=s[3];else{var d=s[0].quoteAmount.divide(s[0].baseAmount),f=[s[0].baseAmount.currency,s[0].quoteAmount.currency,d.denominator,d.numerator];e=f[0],n=f[1],o=f[2],a=f[3]}return(r=t.call(this,a,o)||this).baseCurrency=e,r.quoteCurrency=n,r.scalar=new T(i.exponentiate(i.BigInt(10),i.BigInt(e.decimals)),i.exponentiate(i.BigInt(10),i.BigInt(n.decimals))),r}h(r,t);var e=r.prototype;return e.invert=function(){return new r(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},e.multiply=function(e){this.quoteCurrency.equals(e.baseCurrency)||o(!1);var n=t.prototype.multiply.call(this,e);return new r(this.baseCurrency,e.quoteCurrency,n.denominator,n.numerator)},e.quote=function(r){r.currency.equals(this.baseCurrency)||o(!1);var e=t.prototype.multiply.call(this,r);return b.fromFractionalAmount(this.quoteCurrency,e.numerator,e.denominator)},e.toSignificant=function(t,r,e){return void 0===t&&(t=6),this.adjustedForDecimals.toSignificant(t,r,e)},e.toFixed=function(t,r,e){return void 0===t&&(t=4),this.adjustedForDecimals.toFixed(t,r,e)},m(r,[{key:"adjustedForDecimals",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),r}(T),A=function(t,r,e,n){Number.isSafeInteger(t)||o(!1),r>=0&&r<255&&Number.isInteger(r)||o(!1),this.chainId=t,this.decimals=r,this.symbol=e,this.name=n},_=function(t){function r(){var r;return(r=t.apply(this,arguments)||this).isNative=!0,r.isToken=!1,r}return h(r,t),r}(A);function P(t){try{return c.getAddress(t)}catch(r){throw new Error(t+" is not a valid address.")}}var U,I=/^0x[0-9a-fA-F]{40}$/,D=function(t){function r(r,e,n,i,o,a){var u;return(u=t.call(this,r,n,i,o)||this).isNative=!1,u.isToken=!0,u.address=a?function(t){if(I.test(t))return t;throw new Error(t+" is not a valid address.")}(e):P(e),u}h(r,t);var e=r.prototype;return e.equals=function(t){return t.isToken&&this.chainId===t.chainId&&this.address===t.address},e.sortsBefore=function(t){return this.chainId!==t.chainId&&o(!1),this.address===t.address&&o(!1),this.address.toLowerCase()<t.address.toLowerCase()},m(r,[{key:"wrapped",get:function(){return this}}]),r}(A),R=((U={})[1]=new D(1,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),U[3]=new D(3,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),U[4]=new D(4,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),U[5]=new D(5,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH","Wrapped Ether"),U[42]=new D(42,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH","Wrapped Ether"),U[10]=new D(10,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),U[69]=new D(69,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),U[42161]=new D(42161,"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",18,"WETH","Wrapped Ether"),U[421611]=new D(421611,"0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681",18,"WETH","Wrapped Ether"),U),C=function(t){function r(r){return t.call(this,r,18,"ETH","Ether")||this}return h(r,t),r.onChain=function(t){var e;return null!=(e=this._etherCache[t])?e:this._etherCache[t]=new r(t)},r.prototype.equals=function(t){return t.isNative&&t.chainId===this.chainId},m(r,[{key:"wrapped",get:function(){var t=R[this.chainId];return t||o(!1),t}}]),r}(_);C._etherCache={};var S=i.BigInt(Number.MAX_SAFE_INTEGER),q=i.BigInt(0),B=i.BigInt(1),W=i.BigInt(2);exports.CurrencyAmount=b,exports.Ether=C,exports.Fraction=T,exports.MaxUint256=l,exports.NativeCurrency=_,exports.Percent=O,exports.Price=w,exports.Token=D,exports.WETH9=R,exports.computePriceImpact=function(t,r,e){var n=t.quote(r),i=n.subtract(e).divide(n);return new O(i.numerator,i.denominator)},exports.sortedInsert=function(t,r,e,n){if(e>0||o(!1),t.length<=e||o(!1),0===t.length)return t.push(r),null;var i=t.length===e;if(i&&n(t[t.length-1],r)<=0)return r;for(var a=0,u=t.length;a<u;){var s=a+u>>>1;n(t[s],r)<=0?a=s+1:u=s}return t.splice(a,0,r),i?t.pop():null},exports.sqrt=function(t){if(i.greaterThanOrEqual(t,q)||o(!1),i.lessThan(t,S))return i.BigInt(Math.floor(Math.sqrt(i.toNumber(t))));var r,e;for(r=t,e=i.add(i.divide(t,W),B);i.lessThan(e,r);)r=e,e=i.divide(i.add(i.divide(t,e),e),W);return r},exports.validateAndParseAddress=P;
//# sourceMappingURL=sdk-core.cjs.production.min.js.map