UNPKG

astra-sdk-core

Version:

⚒️ An SDK for building applications on top of Astra CL

3 lines (2 loc) 14.3 kB
"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");function c(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,p(n.key),n)}}function d(t,r,e){return r&&c(t.prototype,r),e&&c(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(){return(f=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 l(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 p(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.MAINNET=16718]="MAINNET",r[r.DEVNET=30746]="DEVNET",r[r.TESTNET=22040]="TESTNET";var m,h,A,y=[exports.ChainId.MAINNET,exports.ChainId.DEVNET,exports.ChainId.TESTNET];(exports.NativeCurrencyName||(exports.NativeCurrencyName={})).AMBER="AMB";var E,x,D=((m={})[exports.ChainId.MAINNET]="0x2b6852CeDEF193ece9814Ee99BE4A4Df7F463557",m[exports.ChainId.DEVNET]="0x4FdFd41dF574a321C9891Df8D643b8006f2Fd19e",m[exports.ChainId.TESTNET]="0x7bf4227eDfAA6823aD577dc198DbCadECccbEb07",m),b=((h={})[exports.ChainId.MAINNET]="0xf7237C595425b49Eaeb3Dc930644de6DCa09c3C4",h[exports.ChainId.DEVNET]="0xd17dAd67B81cf11293b3fE644f18ffaaC5e289c0",h[exports.ChainId.TESTNET]="0xA3E524dFc9deA66aE32e81a5E2B4DF24F56e2CBc",h),v=((A={})[exports.ChainId.MAINNET]={clCoreFactoryAddress:"0x1F98431c8aD98523631AE4a59f267346ea31F984",multicallAddress:"0x1F98415757620B543A52E61c46B32eB19261F984",quoterAddress:"0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",clMigratorAddress:"0xA5644E29708357803b5A882D272c41cC0dF92B34",nonfungiblePositionManagerAddress:"0xC36442b4a4522E871399CD717aBDD847Ab11FE88",mixedRouteQuoterV1Address:"0x84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E",swapRouterAddress:"0xf7237C595425b49Eaeb3Dc930644de6DCa09c3C4"},A[exports.ChainId.DEVNET]={clCoreFactoryAddress:"0x1F98431c8aD98523631AE4a59f267346ea31F984",multicallAddress:"0x1F98415757620B543A52E61c46B32eB19261F984",quoterAddress:"0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",clMigratorAddress:"0xA5644E29708357803b5A882D272c41cC0dF92B34",nonfungiblePositionManagerAddress:"0xC36442b4a4522E871399CD717aBDD847Ab11FE88",mixedRouteQuoterV1Address:"0xBa60b6e6fF25488308789E6e0A65D838be34194e",swapRouterAddress:"0xd17dAd67B81cf11293b3fE644f18ffaaC5e289c0"},A[exports.ChainId.TESTNET]={clCoreFactoryAddress:"0xCD1C424a67ea5a1EfD9593E0230F26e0F5Cd0045",multicallAddress:"0xeEB35b2b13B7F312684c4E0Af670475F0698F7A0",quoterAddress:"0xebDD68E03924Fd91a0eda2BB0Cf9EaFcDacbF169",clMigratorAddress:"0x9d2D06100A5a6a23E83264acfaB280E86fAcc4B3",nonfungiblePositionManagerAddress:"0xe809A49Ad6F72C32755f20ae3c760F6d8516C265",tickLensAddress:"0x077FE43d1cffF2a323881958587d038030EC0FcA",swapRouterAddress:"0xA3E524dFc9deA66aE32e81a5E2B4DF24F56e2CBc"},A),C=f({},y.reduce((function(t,r){return t[r]=v[r].clCoreFactoryAddress,t}),{})),g=f({},y.reduce((function(t,r){var e=v[r].clMigratorAddress;return e&&(t[r]=e),t}),{})),F=f({},y.reduce((function(t,r){return t[r]=v[r].multicallAddress,t}),{})),S=f({},y.reduce((function(t,r){return t[r]=v[r].quoterAddress,t}),{})),N=f({},y.reduce((function(t,r){var e=v[r].nonfungiblePositionManagerAddress;return e&&(t[r]=e),t}),{})),T=f({},y.reduce((function(t,r){var e=v[r].tickLensAddress;return e&&(t[r]=e),t}),{})),B=y.reduce((function(t,r){var e=v[r].mixedRouteQuoterV1Address;return e&&(t[r]=e),t}),{});(E=exports.TradeType||(exports.TradeType={}))[E.EXACT_INPUT=0]="EXACT_INPUT",E[E.EXACT_OUTPUT=1]="EXACT_OUTPUT",(x=exports.Rounding||(exports.Rounding={}))[x.ROUND_DOWN=0]="ROUND_DOWN",x[x.ROUND_HALF_UP=1]="ROUND_HALF_UP",x[x.ROUND_UP=2]="ROUND_UP";var R,_,I=e.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),O=a(o),w=a(i),P=((R={})[exports.Rounding.ROUND_DOWN]=O.ROUND_DOWN,R[exports.Rounding.ROUND_HALF_UP]=O.ROUND_HALF_UP,R[exports.Rounding.ROUND_UP]=O.ROUND_UP,R),U=((_={})[exports.Rounding.ROUND_DOWN]=0,_[exports.Rounding.ROUND_HALF_UP]=1,_[exports.Rounding.ROUND_UP]=3,_),q=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),O.set({precision:t+1,rounding:P[e]});var o=new O(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),w.DP=t,w.RM=U[e],new w(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)},d(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)}}])}(),M=a(i),L=function(t){function r(r,o,i){var a;return a=t.call(this,o,i)||this,e.lessThanOrEqual(a.quotient,I)||n(!1),a.currency=r,a.decimalScale=e.exponentiate(e.BigInt(10),e.BigInt(r.decimals)),a}l(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:""}),M.DP=this.currency.decimals,new M(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(t)},d(r,[{key:"wrapped",get:function(){return this.currency.isToken?this:r.fromFractionalAmount(this.currency.wrapped,this.numerator,this.denominator)}}])}(q),j=new q(e.BigInt(100));function k(t){return new V(t.numerator,t.denominator)}var V=function(t){function r(){var r;return(r=t.apply(this,arguments)||this).isPercent=!0,r}l(r,t);var e=r.prototype;return e.add=function(r){return k(t.prototype.add.call(this,r))},e.subtract=function(r){return k(t.prototype.subtract.call(this,r))},e.multiply=function(r){return k(t.prototype.multiply.call(this,r))},e.divide=function(r){return k(t.prototype.divide.call(this,r))},e.toSignificant=function(r,e,n){return void 0===r&&(r=5),t.prototype.multiply.call(this,j).toSignificant(r,e,n)},e.toFixed=function(r,e,n){return void 0===r&&(r=2),t.prototype.multiply.call(this,j).toFixed(r,e,n)},r}(q),H=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 q(e.exponentiate(e.BigInt(10),e.BigInt(n.decimals)),e.exponentiate(e.BigInt(10),e.BigInt(o.decimals))),r}l(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 L.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)},d(r,[{key:"adjustedForDecimals",get:function(){return t.prototype.multiply.call(this,this.scalar)}}])}(q),W=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},X=function(t){function r(){var r;return(r=t.apply(this,arguments)||this).isNative=!0,r.isToken=!1,r}return l(r,t),r}(W);function Q(t){try{return s.getAddress(t)}catch(r){throw new Error(t+" is not a valid address.")}}var G=/^0x[0-9a-fA-F]{40}$/,Y=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(G.test(t))return t;throw new Error(t+" is not a valid address.")}(e):Q(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}l(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()},d(r,[{key:"wrapped",get:function(){return this}}])}(W),K={16718:new Y(16718,"0x2b2d892C3fe2b4113dd7aC0D2c1882AF202FB28F",18,"SAMB","Synthetic Amber"),22040:new Y(22040,"0x2Cf845b49e1c4E5D657fbBF36E97B7B5B7B7b74b",18,"SAMB","Synthetic Amber"),30746:new Y(30746,"0x2F52348a707ede8Dbcf2BF79cbd65406E92522BD",18,"SAMB","Synthetic Amber")},$=function(t){function r(r){return t.call(this,r,18,"AMB","AMBER")||this}return l(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},d(r,[{key:"wrapped",get:function(){var t=K[this.chainId];return t||n(!1),t}}])}(X);$._etherCache={};var z=e.BigInt(Number.MAX_SAFE_INTEGER),J=e.BigInt(0),Z=e.BigInt(1),tt=e.BigInt(2);exports.ASTRA_NFT_AIRDROP_CLAIM_ADDRESS="0x8B799381ac40b838BBA4131ffB26197C432AFe78",exports.Amber=$,exports.CHAIN_TO_ADDRESSES_MAP=v,exports.CLASSIC_FACTORY_ADDRESSES=D,exports.CLASSIC_ROUTER_ADDRESSES=b,exports.CL_CORE_FACTORY_ADDRESSES=C,exports.CL_MIGRATOR_ADDRESSES=g,exports.CurrencyAmount=L,exports.Fraction=q,exports.MIXED_ROUTE_QUOTER_V1_ADDRESSES=B,exports.MULTICALL_ADDRESSES=F,exports.MaxUint256=I,exports.NONFUNGIBLE_POSITION_MANAGER_ADDRESSES=N,exports.NativeCurrency=X,exports.Percent=V,exports.Price=H,exports.QUOTER_ADDRESSES=S,exports.SAMB=K,exports.SUPPORTED_CHAINS=y,exports.SWAP_ROUTER_ADDRESSES=function(t){var r;return y.includes(t)?null!=(r=v[t].swapRouterAddress)?r:"0xf7237C595425b49Eaeb3Dc930644de6DCa09c3C4":""},exports.TICK_LENS_ADDRESSES=T,exports.Token=Y,exports.computePriceImpact=function(t,r,e){var n=t.quote(r),o=n.subtract(e).divide(n);return new V(o.numerator,o.denominator)},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,J)||n(!1),e.lessThan(t,z))return e.BigInt(Math.floor(Math.sqrt(e.toNumber(t))));var r,o;for(r=t,o=e.add(e.divide(t,tt),Z);e.lessThan(o,r);)r=o,o=e.divide(e.add(e.divide(t,o),o),tt);return r},exports.validateAndParseAddress=Q; //# sourceMappingURL=astra-sdk-core.cjs.production.min.js.map