@unifinance/sdk-core
Version:
⚒️ An SDK for building applications on top of Unifinance V3
3 lines (2 loc) • 16.7 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"),p=require("@ethersproject/strings");function f(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,h(n.key),n)}}function E(t,r,e){return r&&f(t.prototype,r),e&&f(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function l(){return(l=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 A(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 h(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=1]="MAINNET",r[r.GOERLI=5]="GOERLI",r[r.SEPOLIA=11155111]="SEPOLIA",r[r.OPTIMISM=10]="OPTIMISM",r[r.OPTIMISM_GOERLI=420]="OPTIMISM_GOERLI",r[r.OPTIMISM_SEPOLIA=11155420]="OPTIMISM_SEPOLIA",r[r.ARBITRUM_ONE=42161]="ARBITRUM_ONE",r[r.ARBITRUM_GOERLI=421613]="ARBITRUM_GOERLI",r[r.ARBITRUM_SEPOLIA=421614]="ARBITRUM_SEPOLIA",r[r.POLYGON=137]="POLYGON",r[r.POLYGON_MUMBAI=80001]="POLYGON_MUMBAI",r[r.CELO=42220]="CELO",r[r.CELO_ALFAJORES=44787]="CELO_ALFAJORES",r[r.GNOSIS=100]="GNOSIS",r[r.MOONBEAM=1284]="MOONBEAM",r[r.BNB=56]="BNB",r[r.AVALANCHE=43114]="AVALANCHE",r[r.BASE_GOERLI=84531]="BASE_GOERLI",r[r.BASE=8453]="BASE",r[r.ZORA=7777777]="ZORA",r[r.ZORA_SEPOLIA=999999999]="ZORA_SEPOLIA",r[r.ROOTSTOCK=30]="ROOTSTOCK",r[r.BLAST=81457]="BLAST",r[r.WONDER=9637]="WONDER";var m,O,R,D,S,y,x,C,I,_=[exports.ChainId.MAINNET,exports.ChainId.WONDER];(m=exports.NativeCurrencyName||(exports.NativeCurrencyName={})).ETHER="ETH",m.MATIC="MATIC",m.CELO="CELO",m.GNOSIS="XDAI",m.MOONBEAM="GLMR",m.BNB="BNB",m.AVAX="AVAX",m.ROOTSTOCK="RBTC";var v=[exports.ChainId.WONDER];function N(t,r){return void 0===r&&(r=[]),v.concat(r).reduce((function(r,e){return r[e]=t,r}),{})}var B,T,b=N("0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",[exports.ChainId.OPTIMISM,exports.ChainId.ARBITRUM_ONE,exports.ChainId.POLYGON,exports.ChainId.POLYGON_MUMBAI,exports.ChainId.SEPOLIA]),F=((O={})[exports.ChainId.WONDER]="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",O),g=((R={})[exports.ChainId.WONDER]="0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",R),P=l({},{v3CoreFactoryAddress:"0x1F98431c8aD98523631AE4a59f267346ea31F984",multicallAddress:"0x1F98415757620B543A52E61c46B32eB19261F984",quoterAddress:"0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",v3MigratorAddress:"0xA5644E29708357803b5A882D272c41cC0dF92B34",nonfungiblePositionManagerAddress:"0xC36442b4a4522E871399CD717aBDD847Ab11FE88"},{v1MixedRouteQuoterAddress:"0x84E44095eeBfEC7793Cd7d5b57B7e401D7f1cA2E"}),L=((D={})[exports.ChainId.MAINNET]=P,D[exports.ChainId.WONDER]=P,D),M=l({},_.reduce((function(t,r){return t[r]=L[r].v3CoreFactoryAddress,t}),{})),w=l({},_.reduce((function(t,r){var e=L[r].v3MigratorAddress;return e&&(t[r]=e),t}),{})),U=l({},_.reduce((function(t,r){return t[r]=L[r].multicallAddress,t}),{})),W=N("0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F"),q=((S={})[exports.ChainId.WONDER]="0xC4e172459f1E7939D522503B81AFAaC1014CE6F6",S),H=((y={})[exports.ChainId.WONDER]="0x408ED6354d4973f66138C91495F2f2FCbd8724C3",y),G=N("0x1a9C8182C09F50C8318d769245beA52c32BE35BC"),k=((x={})[exports.ChainId.WONDER]="0x090D4613473dEE047c3f2706764f49E0821D256e",x),j=((C={})[exports.ChainId.WONDER]="0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8",C),V=l({},_.reduce((function(t,r){return t[r]=L[r].quoterAddress,t}),{})),X=l({},_.reduce((function(t,r){var e=L[r].nonfungiblePositionManagerAddress;return e&&(t[r]=e),t}),{})),Y=l({},N("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e")),K=((I={})[exports.ChainId.WONDER]="0x65770b5283117639760beA3F867b69b3697a91dd",I),Z=l({},_.reduce((function(t,r){var e=L[r].tickLensAddress;return e&&(t[r]=e),t}),{})),Q=_.reduce((function(t,r){var e=L[r].v1MixedRouteQuoterAddress;return e&&(t[r]=e),t}),{});(B=exports.TradeType||(exports.TradeType={}))[B.EXACT_INPUT=0]="EXACT_INPUT",B[B.EXACT_OUTPUT=1]="EXACT_OUTPUT",(T=exports.Rounding||(exports.Rounding={}))[T.ROUND_DOWN=0]="ROUND_DOWN",T[T.ROUND_HALF_UP=1]="ROUND_HALF_UP",T[T.ROUND_UP=2]="ROUND_UP";var J,z,$=e.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),tt=a(o),rt=a(i),et=((J={})[exports.Rounding.ROUND_DOWN]=tt.ROUND_DOWN,J[exports.Rounding.ROUND_HALF_UP]=tt.ROUND_HALF_UP,J[exports.Rounding.ROUND_UP]=tt.ROUND_UP,J),nt=((z={})[exports.Rounding.ROUND_DOWN]=0,z[exports.Rounding.ROUND_HALF_UP]=1,z[exports.Rounding.ROUND_UP]=3,z),ot=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),tt.set({precision:t+1,rounding:et[e]});var o=new tt(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),rt.DP=t,rt.RM=nt[e],new rt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)},E(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)}}])}(),it=a(i),at=function(t){function r(r,o,i){var a;return a=t.call(this,o,i)||this,e.lessThanOrEqual(a.quotient,$)||n(!1),a.currency=r,a.decimalScale=e.exponentiate(e.BigInt(10),e.BigInt(r.decimals)),a}A(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:""}),it.DP=this.currency.decimals,new it(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(t)},E(r,[{key:"wrapped",get:function(){return this.currency.isToken?this:r.fromFractionalAmount(this.currency.wrapped,this.numerator,this.denominator)}}])}(ot),ut=new ot(e.BigInt(100));function st(t){return new ct(t.numerator,t.denominator)}var ct=function(t){function r(){var r;return(r=t.apply(this,arguments)||this).isPercent=!0,r}A(r,t);var e=r.prototype;return e.add=function(r){return st(t.prototype.add.call(this,r))},e.subtract=function(r){return st(t.prototype.subtract.call(this,r))},e.multiply=function(r){return st(t.prototype.multiply.call(this,r))},e.divide=function(r){return st(t.prototype.divide.call(this,r))},e.toSignificant=function(r,e,n){return void 0===r&&(r=5),t.prototype.multiply.call(this,ut).toSignificant(r,e,n)},e.toFixed=function(r,e,n){return void 0===r&&(r=2),t.prototype.multiply.call(this,ut).toFixed(r,e,n)},r}(ot),dt=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),p=[s[0].baseAmount.currency,s[0].quoteAmount.currency,d.denominator,d.numerator];n=p[0],o=p[1],i=p[2],a=p[3]}return(r=t.call(this,a,i)||this).baseCurrency=n,r.quoteCurrency=o,r.scalar=new ot(e.exponentiate(e.BigInt(10),e.BigInt(n.decimals)),e.exponentiate(e.BigInt(10),e.BigInt(o.decimals))),r}A(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 at.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)},E(r,[{key:"adjustedForDecimals",get:function(){return t.prototype.multiply.call(this,this.scalar)}}])}(ot),pt=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},ft=function(t){function r(){var r;return(r=t.apply(this,arguments)||this).isNative=!0,r.isToken=!1,r}return A(r,t),r}(pt);function Et(t){try{return s.getAddress(t)}catch(r){throw new Error(t+" is not a valid address.")}}var lt,At=/^0x[0-9a-fA-F]{40}$/,ht=function(t){function r(r,e,o,i,a,s,c,d){var p;return(p=t.call(this,r,o,i,a)||this).isNative=!1,p.isToken=!0,p.address=s?function(t){if(At.test(t))return t;throw new Error(t+" is not a valid address.")}(e):Et(e),c&&(c.gte(u.BigNumber.from(0))||n(!1)),d&&(d.gte(u.BigNumber.from(0))||n(!1)),p.buyFeeBps=c,p.sellFeeBps=d,p}A(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()},E(r,[{key:"wrapped",get:function(){return this}}])}(pt),mt=((lt={})[1]=new ht(1,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),lt[3]=new ht(3,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),lt[4]=new ht(4,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),lt[5]=new ht(5,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH","Wrapped Ether"),lt[42]=new ht(42,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH","Wrapped Ether"),lt[10]=new ht(10,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),lt[69]=new ht(69,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),lt[11155420]=new ht(11155420,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),lt[42161]=new ht(42161,"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",18,"WETH","Wrapped Ether"),lt[421611]=new ht(421611,"0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681",18,"WETH","Wrapped Ether"),lt[421614]=new ht(421614,"0x980B62Da83eFf3D4576C647993b0c1D7faf17c73",18,"WETH","Wrapped Ether"),lt[8453]=new ht(8453,"0x4200000000000000000000000000000000000006",18,"WETH","Wrapped Ether"),lt[56]=new ht(56,"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",18,"WBNB","Wrapped BNB"),lt[137]=new ht(137,"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",18,"WMATIC","Wrapped MATIC"),lt[43114]=new ht(43114,"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",18,"WAVAX","Wrapped AVAX"),lt),Ot=function(t){function r(r){return t.call(this,r,18,"ETH","Ether")||this}return A(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},E(r,[{key:"wrapped",get:function(){var t=mt[this.chainId];return t||n(!1),t}}])}(ft);Ot._etherCache={};var Rt=e.BigInt(Number.MAX_SAFE_INTEGER),Dt=e.BigInt(0),St=e.BigInt(1),yt=e.BigInt(2);exports.ARGENT_WALLET_DETECTOR_ADDRESS=j,exports.CHAIN_TO_ADDRESSES_MAP=L,exports.CurrencyAmount=at,exports.ENS_REGISTRAR_ADDRESSES=Y,exports.Ether=Ot,exports.Fraction=ot,exports.GOVERNANCE_ALPHA_V0_ADDRESSES=W,exports.GOVERNANCE_ALPHA_V1_ADDRESSES=q,exports.GOVERNANCE_BRAVO_ADDRESSES=H,exports.MERKLE_DISTRIBUTOR_ADDRESS=k,exports.MIXED_ROUTE_QUOTER_V1_ADDRESSES=Q,exports.MULTICALL_ADDRESSES=U,exports.MaxUint256=$,exports.NONFUNGIBLE_POSITION_MANAGER_ADDRESSES=X,exports.NativeCurrency=ft,exports.Percent=ct,exports.Price=dt,exports.QUOTER_ADDRESSES=V,exports.SOCKS_CONTROLLER_ADDRESSES=K,exports.SUPPORTED_CHAINS=_,exports.SWAP_ROUTER_02_ADDRESSES=function(t){var r;return _.includes(t)?null!=(r=L[t].swapRouter02Address)?r:"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45":""},exports.TICK_LENS_ADDRESSES=Z,exports.TIMELOCK_ADDRESSES=G,exports.Token=ht,exports.UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS="0x8B799381ac40b838BBA4131ffB26197C432AFe78",exports.UNI_ADDRESSES=b,exports.V2_FACTORY_ADDRESS="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.V2_FACTORY_ADDRESSES=F,exports.V2_ROUTER_ADDRESS="0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",exports.V2_ROUTER_ADDRESSES=g,exports.V3_CORE_FACTORY_ADDRESSES=M,exports.V3_MIGRATOR_ADDRESSES=w,exports.WETH9=mt,exports.computePriceImpact=function(t,r,e){var n=t.quote(r),o=n.subtract(e).divide(n);return new ct(o.numerator,o.denominator)},exports.computeZksyncCreate2Address=function(t,r,e,n){void 0===n&&(n="0x");var o=d.keccak256(p.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,Dt)||n(!1),e.lessThan(t,Rt))return e.BigInt(Math.floor(Math.sqrt(e.toNumber(t))));var r,o;for(r=t,o=e.add(e.divide(t,yt),St);e.lessThan(o,r);)r=o,o=e.divide(e.add(e.divide(t,o),o),yt);return r},exports.validateAndParseAddress=Et;
//# sourceMappingURL=sdk-core.cjs.production.min.js.map