@energiswap/sdk-core
Version:
⚒️ An SDK for building applications on top of Energiswap V3
3 lines (2 loc) • 14.4 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=t(require("jsbi")),n=t(require("tiny-invariant")),o=t(require("decimal.js-light")),i=t(require("big.js")),a=t(require("toformat")),u=require("@ethersproject/bignumber"),s=require("@ethersproject/address"),c=require("@ethersproject/bytes"),d=require("@ethersproject/keccak256"),f=require("@ethersproject/strings");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,E(n.key),n)}}function l(t,r,e){return r&&p(t.prototype,r),e&&p(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function m(){return(m=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)({}).hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(null,arguments)}function h(t,r){t.prototype=Object.create(r.prototype),t.prototype.constructor=t,function(t,r){(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t})(t,r)}(t,r)}function E(t){var r=function(t,r){if("object"!=typeof t||!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)}(t);return"symbol"==typeof r?r:r+""}(r=exports.ChainId||(exports.ChainId={}))[r.ENERGI=39797]="ENERGI",r[r.ENERGI_TESTNET=49797]="ENERGI_TESTNET";var y,v,A,x,g=[exports.ChainId.ENERGI,exports.ChainId.ENERGI_TESTNET];(exports.NativeCurrencyName||(exports.NativeCurrencyName={})).ENERGI="NRG";var R=[exports.ChainId.ENERGI,exports.ChainId.ENERGI_TESTNET];function D(t,r){return void 0===r&&(r=[]),R.concat(r).reduce((function(r,e){return r[e]=t,r}),{})}var S,_,N=((y={})[exports.ChainId.ENERGI]="0x665B3A802979eC24e076c80025bFF33c18eB6007",y[exports.ChainId.ENERGI_TESTNET]="0xDFf7a6F2CDdD46c1a36Ae760fEbc399208e86E0A",y),C=((v={})[exports.ChainId.ENERGI]="0xa2dAE9e70D5A08B781DeE134617Cf5E7D23043c2",v[exports.ChainId.ENERGI_TESTNET]="0xb1F94d0d737755342a9d0cD84f5eBEAB4c2DaA54",v),F=((A={})[exports.ChainId.ENERGI]="0x2D4eB90118f6FBA1191F26Eb39f7FF0573F63C22",A[exports.ChainId.ENERGI_TESTNET]="0x07CC883c0B6E45B00E91840dcCdF99D66551Fa81",A),I={v3CoreFactoryAddress:"0x2BfD24B00413Fd35089cc9E3E6Aa285e4Bd7904d",multicallAddress:"0x51dd6b5596ca240FDe76698785cBFCDCa2E3ddb7",quoterAddress:"0xF20BC258323Df9d9c26Ef1A961FDCC4E8CEb71Bc",v3MigratorAddress:"0x5eeB515207a81dc55C1a29c0f57824D19Bc148B7",nonfungiblePositionManagerAddress:"0x47b4452CA33FEAcaD064eEDC210AF611516756F4"},b=m({},I,{mixedRouteQuoterV1Address:"0x84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E",v4PoolManagerAddress:"0x000000000004444c5dc75cB358380D2e3dE08A90",v4PositionManagerAddress:"0xbd216513d74c8cf14cf4747e6aaa6420ff64ee9e",v4StateView:"0x7ffe42c4a5deea5b0fec41c94c136cf115597227",v4QuoterAddress:"0x52f0e24d1c21c8a0cb1e5a5dd6198556bd9e1203"}),T=m({},I,{mixedRouteQuoterV1Address:"0xBa60b6e6fF25488308789E6e0A65D838be34194e"}),O=((x={})[exports.ChainId.ENERGI]=b,x[exports.ChainId.ENERGI_TESTNET]=T,x),B=m({},g.reduce((function(t,r){return t[r]=O[r].v3CoreFactoryAddress,t}),{})),P=m({},g.reduce((function(t,r){var e=O[r].v3MigratorAddress;return e&&(t[r]=e),t}),{})),U=m({},g.reduce((function(t,r){return t[r]=O[r].multicallAddress,t}),{})),w=m({},g.reduce((function(t,r){return t[r]=O[r].quoterAddress,t}),{})),q=m({},g.reduce((function(t,r){var e=O[r].nonfungiblePositionManagerAddress;return e&&(t[r]=e),t}),{})),G=m({},D("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e")),k=m({},g.reduce((function(t,r){var e=O[r].tickLensAddress;return e&&(t[r]=e),t}),{})),j=g.reduce((function(t,r){var e=O[r].mixedRouteQuoterV1Address;return e&&(t[r]=e),t}),{});(S=exports.TradeType||(exports.TradeType={}))[S.EXACT_INPUT=0]="EXACT_INPUT",S[S.EXACT_OUTPUT=1]="EXACT_OUTPUT",(_=exports.Rounding||(exports.Rounding={}))[_.ROUND_DOWN=0]="ROUND_DOWN",_[_.ROUND_HALF_UP=1]="ROUND_HALF_UP",_[_.ROUND_UP=2]="ROUND_UP";var L,M,W=e.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),V=a(o),H=a(i),Q=((L={})[exports.Rounding.ROUND_DOWN]=V.ROUND_DOWN,L[exports.Rounding.ROUND_HALF_UP]=V.ROUND_HALF_UP,L[exports.Rounding.ROUND_UP]=V.ROUND_UP,L),X=((M={})[exports.Rounding.ROUND_DOWN]=0,M[exports.Rounding.ROUND_HALF_UP]=1,M[exports.Rounding.ROUND_UP]=3,M),Y=function(){function t(t,r){void 0===r&&(r=e.BigInt(1)),this.numerator=e.BigInt(t),this.denominator=e.BigInt(r)}t.tryParseFraction=function(r){if(r instanceof e||"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 n=t.tryParseFraction(r);return e.equal(this.denominator,n.denominator)?new t(e.add(this.numerator,n.numerator),this.denominator):new t(e.add(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator)),e.multiply(this.denominator,n.denominator))},r.subtract=function(r){var n=t.tryParseFraction(r);return e.equal(this.denominator,n.denominator)?new t(e.subtract(this.numerator,n.numerator),this.denominator):new t(e.subtract(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator)),e.multiply(this.denominator,n.denominator))},r.lessThan=function(r){var n=t.tryParseFraction(r);return e.lessThan(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator))},r.equalTo=function(r){var n=t.tryParseFraction(r);return e.equal(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator))},r.greaterThan=function(r){var n=t.tryParseFraction(r);return e.greaterThan(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator))},r.multiply=function(r){var n=t.tryParseFraction(r);return new t(e.multiply(this.numerator,n.numerator),e.multiply(this.denominator,n.denominator))},r.divide=function(r){var n=t.tryParseFraction(r);return new t(e.multiply(this.numerator,n.denominator),e.multiply(this.denominator,n.numerator))},r.toSignificant=function(t,r,e){void 0===r&&(r={groupSeparator:""}),void 0===e&&(e=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||n(!1),t>0||n(!1),V.set({precision:t+1,rounding:Q[e]});var o=new V(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.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)||n(!1),t>=0||n(!1),H.DP=t,H.RM=X[e],new H(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)},l(t,[{key:"quotient",get:function(){return e.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(e.remainder(this.numerator,this.denominator),this.denominator)}},{key:"asFraction",get:function(){return new t(this.numerator,this.denominator)}}])}(),Z=a(i),z=function(t){function r(r,o,i){var a;return a=t.call(this,o,i)||this,e.lessThanOrEqual(a.quotient,W)||n(!1),a.currency=r,a.decimalScale=e.exponentiate(e.BigInt(10),e.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 o=r.prototype;return o.add=function(e){this.currency.equals(e.currency)||n(!1);var o=t.prototype.add.call(this,e);return r.fromFractionalAmount(this.currency,o.numerator,o.denominator)},o.subtract=function(e){this.currency.equals(e.currency)||n(!1);var o=t.prototype.subtract.call(this,e);return r.fromFractionalAmount(this.currency,o.numerator,o.denominator)},o.multiply=function(e){var n=t.prototype.multiply.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},o.divide=function(e){var n=t.prototype.divide.call(this,e);return r.fromFractionalAmount(this.currency,n.numerator,n.denominator)},o.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)},o.toFixed=function(r,e,o){return void 0===r&&(r=this.currency.decimals),void 0===o&&(o=exports.Rounding.ROUND_DOWN),r<=this.currency.decimals||n(!1),t.prototype.divide.call(this,this.decimalScale).toFixed(r,e,o)},o.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),Z.DP=this.currency.decimals,new Z(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(t)},l(r,[{key:"wrapped",get:function(){return this.currency.isToken?this:r.fromFractionalAmount(this.currency.wrapped,this.numerator,this.denominator)}}])}(Y),K=new Y(e.BigInt(100));function $(t){return new J(t.numerator,t.denominator)}var J=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 $(t.prototype.add.call(this,r))},e.subtract=function(r){return $(t.prototype.subtract.call(this,r))},e.multiply=function(r){return $(t.prototype.multiply.call(this,r))},e.divide=function(r){return $(t.prototype.divide.call(this,r))},e.toSignificant=function(r,e,n){return void 0===r&&(r=5),t.prototype.multiply.call(this,K).toSignificant(r,e,n)},e.toFixed=function(r,e,n){return void 0===r&&(r=2),t.prototype.multiply.call(this,K).toFixed(r,e,n)},r}(Y),tt=function(t){function r(){for(var r,n,o,i,a,u=arguments.length,s=new Array(u),c=0;c<u;c++)s[c]=arguments[c];if(4===s.length)n=s[0],o=s[1],i=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];n=f[0],o=f[1],i=f[2],a=f[3]}return(r=t.call(this,a,i)||this).baseCurrency=n,r.quoteCurrency=o,r.scalar=new Y(e.exponentiate(e.BigInt(10),e.BigInt(n.decimals)),e.exponentiate(e.BigInt(10),e.BigInt(o.decimals))),r}h(r,t);var o=r.prototype;return o.invert=function(){return new r(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},o.multiply=function(e){this.quoteCurrency.equals(e.baseCurrency)||n(!1);var o=t.prototype.multiply.call(this,e);return new r(this.baseCurrency,e.quoteCurrency,o.denominator,o.numerator)},o.quote=function(r){r.currency.equals(this.baseCurrency)||n(!1);var e=t.prototype.multiply.call(this,r);return z.fromFractionalAmount(this.quoteCurrency,e.numerator,e.denominator)},o.toSignificant=function(t,r,e){return void 0===t&&(t=6),this.adjustedForDecimals.toSignificant(t,r,e)},o.toFixed=function(t,r,e){return void 0===t&&(t=4),this.adjustedForDecimals.toFixed(t,r,e)},l(r,[{key:"adjustedForDecimals",get:function(){return t.prototype.multiply.call(this,this.scalar)}}])}(Y),rt=function(t,r,e,o){Number.isSafeInteger(t)||n(!1),r>=0&&r<255&&Number.isInteger(r)||n(!1),this.chainId=t,this.decimals=r,this.symbol=e,this.name=o},et=function(t){function r(){var r;return(r=t.apply(this,arguments)||this).isNative=!0,r.isToken=!1,r}return h(r,t),r}(rt);function nt(t){try{return s.getAddress(t)}catch(r){throw new Error(t+" is not a valid address.")}}var ot=/^0x[0-9a-fA-F]{40}$/,it=function(t){function r(r,e,o,i,a,s,c,d){var f;return(f=t.call(this,r,o,i,a)||this).isNative=!1,f.isToken=!0,f.address=s?function(t){if(ot.test(t))return t;throw new Error(t+" is not a valid address.")}(e):nt(e),c&&(c.gte(u.BigNumber.from(0))||n(!1)),d&&(d.gte(u.BigNumber.from(0))||n(!1)),f.buyFeeBps=c,f.sellFeeBps=d,f}h(r,t);var e=r.prototype;return e.equals=function(t){return t.isToken&&this.chainId===t.chainId&&this.address.toLowerCase()===t.address.toLowerCase()},e.sortsBefore=function(t){return this.chainId!==t.chainId&&n(!1),this.address.toLowerCase()===t.address.toLowerCase()&&n(!1),this.address.toLowerCase()<t.address.toLowerCase()},l(r,[{key:"wrapped",get:function(){return this}}])}(rt),at={39797:new it(1,"0xA55F26319462355474A9F2c8790860776a329aA4",18,"WNRG","Wrapped Energi"),49797:new it(11155111,"0x184F7b12f29d675f34ff816528ADBfd0E0501Ad4",18,"WNRG","Wrapped Energi")},ut=function(t){function r(r){return t.call(this,r,18,"NRG","Energi")||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},l(r,[{key:"wrapped",get:function(){var t=at[this.chainId];return t||n(!1),t}}])}(et);ut._etherCache={};var st=e.BigInt(Number.MAX_SAFE_INTEGER),ct=e.BigInt(0),dt=e.BigInt(1),ft=e.BigInt(2);exports.CHAIN_TO_ADDRESSES_MAP=O,exports.CurrencyAmount=z,exports.ENS_REGISTRAR_ADDRESSES=G,exports.Ether=ut,exports.Fraction=Y,exports.MIXED_ROUTE_QUOTER_V1_ADDRESSES=j,exports.MULTICALL_ADDRESSES=U,exports.MaxUint256=W,exports.NONFUNGIBLE_POSITION_MANAGER_ADDRESSES=q,exports.NativeCurrency=et,exports.Percent=J,exports.Price=tt,exports.QUOTER_ADDRESSES=w,exports.SUPPORTED_CHAINS=g,exports.SWAP_ROUTER_02_ADDRESSES=function(t){var r;return g.includes(t)?null!=(r=O[t].swapRouter02Address)?r:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45":""},exports.TICK_LENS_ADDRESSES=k,exports.Token=it,exports.UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS="0x8B799381ac40b838BBA4131ffB26197C432AFe78",exports.UNI_ADDRESSES=N,exports.V2_FACTORY_ADDRESS="0xa2dAE9e70D5A08B781DeE134617Cf5E7D23043c2",exports.V2_FACTORY_ADDRESSES=C,exports.V2_ROUTER_ADDRESS="0x2D4eB90118f6FBA1191F26Eb39f7FF0573F63C22",exports.V2_ROUTER_ADDRESSES=F,exports.V3_CORE_FACTORY_ADDRESSES=B,exports.V3_MIGRATOR_ADDRESSES=P,exports.WETH9=at,exports.computePriceImpact=function(t,r,e){var n=t.quote(r),o=n.subtract(e).divide(n);return new J(o.numerator,o.denominator)},exports.computeZksyncCreate2Address=function(t,r,e,n){void 0===n&&(n="0x");var o=d.keccak256(f.toUtf8Bytes("zksyncCreate2")),i=d.keccak256(n),a=d.keccak256(c.concat([o,c.hexZeroPad(t,32),e,r,i])).slice(26);return s.getAddress(a)},exports.sortedInsert=function(t,r,e,o){if(e>0||n(!1),t.length<=e||n(!1),0===t.length)return t.push(r),null;var i=t.length===e;if(i&&o(t[t.length-1],r)<=0)return r;for(var a=0,u=t.length;a<u;){var s=a+u>>>1;o(t[s],r)<=0?a=s+1:u=s}return t.splice(a,0,r),i?t.pop():null},exports.sqrt=function(t){if(e.greaterThanOrEqual(t,ct)||n(!1),e.lessThan(t,st))return e.BigInt(Math.floor(Math.sqrt(e.toNumber(t))));var r,o;for(r=t,o=e.add(e.divide(t,ft),dt);e.lessThan(o,r);)r=o,o=e.divide(e.add(e.divide(t,o),o),ft);return r},exports.validateAndParseAddress=nt;
//# sourceMappingURL=sdk-core.cjs.production.min.js.map