haedal-vault-sdk 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var wr=Object.create;var ze=Object.defineProperty;var vr=Object.getOwnPropertyDescriptor;var yr=Object.getOwnPropertyNames;var Mr=Object.getPrototypeOf,Cr=Object.prototype.hasOwnProperty;var kr=(i,t)=>{for(var e in t)ze(i,e,{get:t[e],enumerable:!0})},Tn=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of yr(t))!Cr.call(i,r)&&r!==e&&ze(i,r,{get:()=>t[r],enumerable:!(n=vr(t,r))||n.enumerable});return i};var ne=(i,t,e)=>(e=i!=null?wr(Mr(i)):{},Tn(t||!i||!i.__esModule?ze(e,"default",{value:i,enumerable:!0}):e,i)),Pr=i=>Tn(ze({},"__esModule",{value:!0}),i);var fs={};kr(fs,{PythPriceModule:()=>Se,SdkEnv:()=>cr,VaultsModule:()=>$e,VaultsModuleV2:()=>We,VestModule:()=>Ke,VolatileVaultsSDK:()=>fe,buildDLMMMarket:()=>Yi,buildDLMMMarketId:()=>rn,buildDLMMMarketPosition:()=>tn,buildDLMMPositionId:()=>cs,buildPoolData:()=>ci,buildPoolV2Data:()=>en,buildVaultsBalance:()=>Xi,buildVaultsBalanceV2:()=>fi,calculateAum:()=>zi,calculateAumV2:()=>nn,calculateDepositRatioFixTokenA:()=>or,calculateTotalAumBasedOnQuote:()=>ye,checkIsMinOrMaxIndex:()=>si,convertU64BytesToDecimal:()=>ns,default:()=>ds,defaultProvider:()=>dn,estCoinAmountsFromTotalAmount:()=>Zi,feed_map_mainnet:()=>sn,feed_map_testnet:()=>ln,getAmountBalanceByLpAmount:()=>Ue,getCoinAmountsFromRatio:()=>ae,getPositionPriceRange:()=>ss,getPriceWithFormattedDecimals:()=>Hi,getPrimitivePricesFromBaseQuote:()=>sr,getQuotePerBaseAndBasePerQuote:()=>qe,getShareBufferAssets:()=>Pe,getUpdatePriceType:()=>Ne,getVaultValidBalances:()=>De,get_lp_amount_by_liquidity:()=>os,get_lp_amount_by_tvl:()=>Re,get_share_liquidity_by_amount:()=>ke,initMainnetSDK:()=>an,initTestnetSDK:()=>un,initVaultSDK:()=>ls,oraclePriceMultiplierDecimal:()=>Ce,parseVaultVestNFT:()=>Qi,parseVaultsVestInfo:()=>li,printTransaction:()=>rs,toSuiObjectId:()=>Gi,vaults_mainnet:()=>on,vaults_testnet:()=>cn});module.exports=Pr(fs);var gr=require("@mysten/sui/client"),mi=require("@mysten/sui/utils"),Ze=require("@cetusprotocol/aggregator-sdk");var Vr=require("@mysten/sui/utils"),Lr=require("@mysten/sui/client"),jr=require("@mysten/sui/utils"),qr=require("@mysten/sui/keypairs/ed25519"),Rr=require("@mysten/sui/keypairs/secp256k1"),Me=require("@mysten/sui/utils"),Fi=require("@mysten/sui/transactions"),Lo=require("@mysten/sui/bcs"),jo=require("@mysten/sui/utils"),qo=require("@mysten/sui/graphql/schemas/latest"),Ro=require("@mysten/sui/graphql"),Ni=require("@mysten/sui/client"),Sr=Object.create,Nn=Object.defineProperty,Ar=Object.getOwnPropertyDescriptor,Or=Object.getOwnPropertyNames,xr=Object.getPrototypeOf,Dr=Object.prototype.hasOwnProperty,Er=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')}),Tr=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Br=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Or(t))!Dr.call(i,r)&&r!==e&&Nn(i,r,{get:()=>t[r],enumerable:!(n=Ar(t,r))||n.enumerable});return i},Ie=(i,t,e)=>(e=i!=null?Sr(xr(i)):{},Br(t||!i||!i.__esModule?Nn(e,"default",{value:i,enumerable:!0}):e,i)),Le=Tr((i,t)=>{"use strict";(function(e,n){"use strict";function r(s,l){if(!s)throw new Error(l||"Assertion failed")}function a(s,l){s.super_=l;var h=function(){};h.prototype=l.prototype,s.prototype=new h,s.prototype.constructor=s}function o(s,l,h){if(o.isBN(s))return s;this.negative=0,this.words=null,this.length=0,this.red=null,s!==null&&((l==="le"||l==="be")&&(h=l,l=10),this._init(s||0,l||10,h||"be"))}typeof e=="object"?e.exports=o:n.BN=o,o.BN=o,o.wordSize=26;var u;try{typeof window<"u"&&typeof window.Buffer<"u"?u=window.Buffer:u=Er("buffer").Buffer}catch{}o.isBN=function(s){return s instanceof o?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===o.wordSize&&Array.isArray(s.words)},o.max=function(s,l){return s.cmp(l)>0?s:l},o.min=function(s,l){return s.cmp(l)<0?s:l},o.prototype._init=function(s,l,h){if(typeof s=="number")return this._initNumber(s,l,h);if(typeof s=="object")return this._initArray(s,l,h);l==="hex"&&(l=16),r(l===(l|0)&&l>=2&&l<=36),s=s.toString().replace(/\s+/g,"");var p=0;s[0]==="-"&&(p++,this.negative=1),p<s.length&&(l===16?this._parseHex(s,p,h):(this._parseBase(s,l,p),h==="le"&&this._initArray(this.toArray(),l,h)))},o.prototype._initNumber=function(s,l,h){s<0&&(this.negative=1,s=-s),s<67108864?(this.words=[s&67108863],this.length=1):s<4503599627370496?(this.words=[s&67108863,s/67108864&67108863],this.length=2):(r(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),l,h)},o.prototype._initArray=function(s,l,h){if(r(typeof s.length=="number"),s.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(s.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var w,y,M=0;if(h==="be")for(p=s.length-1,w=0;p>=0;p-=3)y=s[p]|s[p-1]<<8|s[p-2]<<16,this.words[w]|=y<<M&67108863,this.words[w+1]=y>>>26-M&67108863,M+=24,M>=26&&(M-=26,w++);else if(h==="le")for(p=0,w=0;p<s.length;p+=3)y=s[p]|s[p+1]<<8|s[p+2]<<16,this.words[w]|=y<<M&67108863,this.words[w+1]=y>>>26-M&67108863,M+=24,M>=26&&(M-=26,w++);return this._strip()};function d(s,l){var h=s.charCodeAt(l);if(h>=48&&h<=57)return h-48;if(h>=65&&h<=70)return h-55;if(h>=97&&h<=102)return h-87;r(!1,"Invalid character in "+s)}function f(s,l,h){var p=d(s,h);return h-1>=l&&(p|=d(s,h-1)<<4),p}o.prototype._parseHex=function(s,l,h){this.length=Math.ceil((s.length-l)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var w=0,y=0,M;if(h==="be")for(p=s.length-1;p>=l;p-=2)M=f(s,l,p)<<w,this.words[y]|=M&67108863,w>=18?(w-=18,y+=1,this.words[y]|=M>>>26):w+=8;else{var b=s.length-l;for(p=b%2===0?l+1:l;p<s.length;p+=2)M=f(s,l,p)<<w,this.words[y]|=M&67108863,w>=18?(w-=18,y+=1,this.words[y]|=M>>>26):w+=8}this._strip()};function m(s,l,h,p){for(var w=0,y=0,M=Math.min(s.length,h),b=l;b<M;b++){var c=s.charCodeAt(b)-48;w*=p,c>=49?y=c-49+10:c>=17?y=c-17+10:y=c,r(c>=0&&y<p,"Invalid character"),w+=y}return w}o.prototype._parseBase=function(s,l,h){this.words=[0],this.length=1;for(var p=0,w=1;w<=67108863;w*=l)p++;p--,w=w/l|0;for(var y=s.length-h,M=y%p,b=Math.min(y,y-M)+h,c=0,v=h;v<b;v+=p)c=m(s,v,v+p,l),this.imuln(w),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(M!==0){var B=1;for(c=m(s,v,s.length,l),v=0;v<M;v++)B*=l;this.imuln(B),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},o.prototype.copy=function(s){s.words=new Array(this.length);for(var l=0;l<this.length;l++)s.words[l]=this.words[l];s.length=this.length,s.negative=this.negative,s.red=this.red};function _(s,l){s.words=l.words,s.length=l.length,s.negative=l.negative,s.red=l.red}if(o.prototype._move=function(s){_(s,this)},o.prototype.clone=function(){var s=new o(null);return this.copy(s),s},o.prototype._expand=function(s){for(;this.length<s;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=g}catch{o.prototype.inspect=g}else o.prototype.inspect=g;function g(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var C=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],k=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],P=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(s,l){s=s||10,l=l|0||1;var h;if(s===16||s==="hex"){h="";for(var p=0,w=0,y=0;y<this.length;y++){var M=this.words[y],b=((M<<p|w)&16777215).toString(16);w=M>>>24-p&16777215,p+=2,p>=26&&(p-=26,y--),w!==0||y!==this.length-1?h=C[6-b.length]+b+h:h=b+h}for(w!==0&&(h=w.toString(16)+h);h.length%l!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(s===(s|0)&&s>=2&&s<=36){var c=k[s],v=P[s];h="";var B=this.clone();for(B.negative=0;!B.isZero();){var V=B.modrn(v).toString(s);B=B.idivn(v),B.isZero()?h=V+h:h=C[c-V.length]+V+h}for(this.isZero()&&(h="0"+h);h.length%l!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}r(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var s=this.words[0];return this.length===2?s+=this.words[1]*67108864:this.length===3&&this.words[2]===1?s+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},o.prototype.toJSON=function(){return this.toString(16,2)},u&&(o.prototype.toBuffer=function(s,l){return this.toArrayLike(u,s,l)}),o.prototype.toArray=function(s,l){return this.toArrayLike(Array,s,l)};var D=function(s,l){return s.allocUnsafe?s.allocUnsafe(l):new s(l)};o.prototype.toArrayLike=function(s,l,h){this._strip();var p=this.byteLength(),w=h||Math.max(1,p);r(p<=w,"byte array longer than desired length"),r(w>0,"Requested array length <= 0");var y=D(s,w),M=l==="le"?"LE":"BE";return this["_toArrayLike"+M](y,p),y},o.prototype._toArrayLikeLE=function(s,l){for(var h=0,p=0,w=0,y=0;w<this.length;w++){var M=this.words[w]<<y|p;s[h++]=M&255,h<s.length&&(s[h++]=M>>8&255),h<s.length&&(s[h++]=M>>16&255),y===6?(h<s.length&&(s[h++]=M>>24&255),p=0,y=0):(p=M>>>24,y+=2)}if(h<s.length)for(s[h++]=p;h<s.length;)s[h++]=0},o.prototype._toArrayLikeBE=function(s,l){for(var h=s.length-1,p=0,w=0,y=0;w<this.length;w++){var M=this.words[w]<<y|p;s[h--]=M&255,h>=0&&(s[h--]=M>>8&255),h>=0&&(s[h--]=M>>16&255),y===6?(h>=0&&(s[h--]=M>>24&255),p=0,y=0):(p=M>>>24,y+=2)}if(h>=0)for(s[h--]=p;h>=0;)s[h--]=0},Math.clz32?o.prototype._countBits=function(s){return 32-Math.clz32(s)}:o.prototype._countBits=function(s){var l=s,h=0;return l>=4096&&(h+=13,l>>>=13),l>=64&&(h+=7,l>>>=7),l>=8&&(h+=4,l>>>=4),l>=2&&(h+=2,l>>>=2),h+l},o.prototype._zeroBits=function(s){if(s===0)return 26;var l=s,h=0;return!(l&8191)&&(h+=13,l>>>=13),!(l&127)&&(h+=7,l>>>=7),!(l&15)&&(h+=4,l>>>=4),!(l&3)&&(h+=2,l>>>=2),!(l&1)&&h++,h},o.prototype.bitLength=function(){var s=this.words[this.length-1],l=this._countBits(s);return(this.length-1)*26+l};function x(s){for(var l=new Array(s.bitLength()),h=0;h<l.length;h++){var p=h/26|0,w=h%26;l[h]=s.words[p]>>>w&1}return l}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,l=0;l<this.length;l++){var h=this._zeroBits(this.words[l]);if(s+=h,h!==26)break}return s},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},o.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var l=0;l<s.length;l++)this.words[l]=this.words[l]|s.words[l];return this._strip()},o.prototype.ior=function(s){return r((this.negative|s.negative)===0),this.iuor(s)},o.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},o.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},o.prototype.iuand=function(s){var l;this.length>s.length?l=s:l=this;for(var h=0;h<l.length;h++)this.words[h]=this.words[h]&s.words[h];return this.length=l.length,this._strip()},o.prototype.iand=function(s){return r((this.negative|s.negative)===0),this.iuand(s)},o.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},o.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},o.prototype.iuxor=function(s){var l,h;this.length>s.length?(l=this,h=s):(l=s,h=this);for(var p=0;p<h.length;p++)this.words[p]=l.words[p]^h.words[p];if(this!==l)for(;p<l.length;p++)this.words[p]=l.words[p];return this.length=l.length,this._strip()},o.prototype.ixor=function(s){return r((this.negative|s.negative)===0),this.iuxor(s)},o.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},o.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},o.prototype.inotn=function(s){r(typeof s=="number"&&s>=0);var l=Math.ceil(s/26)|0,h=s%26;this._expand(l),h>0&&l--;for(var p=0;p<l;p++)this.words[p]=~this.words[p]&67108863;return h>0&&(this.words[p]=~this.words[p]&67108863>>26-h),this._strip()},o.prototype.notn=function(s){return this.clone().inotn(s)},o.prototype.setn=function(s,l){r(typeof s=="number"&&s>=0);var h=s/26|0,p=s%26;return this._expand(h+1),l?this.words[h]=this.words[h]|1<<p:this.words[h]=this.words[h]&~(1<<p),this._strip()},o.prototype.iadd=function(s){var l;if(this.negative!==0&&s.negative===0)return this.negative=0,l=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,l=this.isub(s),s.negative=1,l._normSign();var h,p;this.length>s.length?(h=this,p=s):(h=s,p=this);for(var w=0,y=0;y<p.length;y++)l=(h.words[y]|0)+(p.words[y]|0)+w,this.words[y]=l&67108863,w=l>>>26;for(;w!==0&&y<h.length;y++)l=(h.words[y]|0)+w,this.words[y]=l&67108863,w=l>>>26;if(this.length=h.length,w!==0)this.words[this.length]=w,this.length++;else if(h!==this)for(;y<h.length;y++)this.words[y]=h.words[y];return this},o.prototype.add=function(s){var l;return s.negative!==0&&this.negative===0?(s.negative=0,l=this.sub(s),s.negative^=1,l):s.negative===0&&this.negative!==0?(this.negative=0,l=s.sub(this),this.negative=1,l):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},o.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var l=this.iadd(s);return s.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var h=this.cmp(s);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,w;h>0?(p=this,w=s):(p=s,w=this);for(var y=0,M=0;M<w.length;M++)l=(p.words[M]|0)-(w.words[M]|0)+y,y=l>>26,this.words[M]=l&67108863;for(;y!==0&&M<p.length;M++)l=(p.words[M]|0)+y,y=l>>26,this.words[M]=l&67108863;if(y===0&&M<p.length&&p!==this)for(;M<p.length;M++)this.words[M]=p.words[M];return this.length=Math.max(this.length,M),p!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(s){return this.clone().isub(s)};function E(s,l,h){h.negative=l.negative^s.negative;var p=s.length+l.length|0;h.length=p,p=p-1|0;var w=s.words[0]|0,y=l.words[0]|0,M=w*y,b=M&67108863,c=M/67108864|0;h.words[0]=b;for(var v=1;v<p;v++){for(var B=c>>>26,V=c&67108863,I=Math.min(v,l.length-1),U=Math.max(0,v-s.length+1);U<=I;U++){var Z=v-U|0;w=s.words[Z]|0,y=l.words[U]|0,M=w*y+V,B+=M/67108864|0,V=M&67108863}h.words[v]=V|0,c=B|0}return c!==0?h.words[v]=c|0:h.length--,h._strip()}var O=function(s,l,h){var p=s.words,w=l.words,y=h.words,M=0,b,c,v,B=p[0]|0,V=B&8191,I=B>>>13,U=p[1]|0,Z=U&8191,Y=U>>>13,me=p[2]|0,tt=me&8191,it=me>>>13,pn=p[3]|0,rt=pn&8191,ot=pn>>>13,_n=p[4]|0,st=_n&8191,at=_n>>>13,gn=p[5]|0,ct=gn&8191,lt=gn>>>13,bn=p[6]|0,ut=bn&8191,dt=bn>>>13,wn=p[7]|0,ft=wn&8191,ht=wn>>>13,vn=p[8]|0,mt=vn&8191,pt=vn>>>13,yn=p[9]|0,_t=yn&8191,gt=yn>>>13,Mn=w[0]|0,bt=Mn&8191,wt=Mn>>>13,Cn=w[1]|0,vt=Cn&8191,yt=Cn>>>13,kn=w[2]|0,Mt=kn&8191,Ct=kn>>>13,Pn=w[3]|0,kt=Pn&8191,Pt=Pn>>>13,Sn=w[4]|0,St=Sn&8191,At=Sn>>>13,An=w[5]|0,Ot=An&8191,xt=An>>>13,On=w[6]|0,Dt=On&8191,Et=On>>>13,xn=w[7]|0,Tt=xn&8191,Bt=xn>>>13,Dn=w[8]|0,Vt=Dn&8191,Ft=Dn>>>13,En=w[9]|0,It=En&8191,Lt=En>>>13;h.negative=s.negative^l.negative,h.length=19,b=Math.imul(V,bt),c=Math.imul(V,wt),c=c+Math.imul(I,bt)|0,v=Math.imul(I,wt);var pi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(pi>>>26)|0,pi&=67108863,b=Math.imul(Z,bt),c=Math.imul(Z,wt),c=c+Math.imul(Y,bt)|0,v=Math.imul(Y,wt),b=b+Math.imul(V,vt)|0,c=c+Math.imul(V,yt)|0,c=c+Math.imul(I,vt)|0,v=v+Math.imul(I,yt)|0;var _i=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(_i>>>26)|0,_i&=67108863,b=Math.imul(tt,bt),c=Math.imul(tt,wt),c=c+Math.imul(it,bt)|0,v=Math.imul(it,wt),b=b+Math.imul(Z,vt)|0,c=c+Math.imul(Z,yt)|0,c=c+Math.imul(Y,vt)|0,v=v+Math.imul(Y,yt)|0,b=b+Math.imul(V,Mt)|0,c=c+Math.imul(V,Ct)|0,c=c+Math.imul(I,Mt)|0,v=v+Math.imul(I,Ct)|0;var gi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,b=Math.imul(rt,bt),c=Math.imul(rt,wt),c=c+Math.imul(ot,bt)|0,v=Math.imul(ot,wt),b=b+Math.imul(tt,vt)|0,c=c+Math.imul(tt,yt)|0,c=c+Math.imul(it,vt)|0,v=v+Math.imul(it,yt)|0,b=b+Math.imul(Z,Mt)|0,c=c+Math.imul(Z,Ct)|0,c=c+Math.imul(Y,Mt)|0,v=v+Math.imul(Y,Ct)|0,b=b+Math.imul(V,kt)|0,c=c+Math.imul(V,Pt)|0,c=c+Math.imul(I,kt)|0,v=v+Math.imul(I,Pt)|0;var bi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,b=Math.imul(st,bt),c=Math.imul(st,wt),c=c+Math.imul(at,bt)|0,v=Math.imul(at,wt),b=b+Math.imul(rt,vt)|0,c=c+Math.imul(rt,yt)|0,c=c+Math.imul(ot,vt)|0,v=v+Math.imul(ot,yt)|0,b=b+Math.imul(tt,Mt)|0,c=c+Math.imul(tt,Ct)|0,c=c+Math.imul(it,Mt)|0,v=v+Math.imul(it,Ct)|0,b=b+Math.imul(Z,kt)|0,c=c+Math.imul(Z,Pt)|0,c=c+Math.imul(Y,kt)|0,v=v+Math.imul(Y,Pt)|0,b=b+Math.imul(V,St)|0,c=c+Math.imul(V,At)|0,c=c+Math.imul(I,St)|0,v=v+Math.imul(I,At)|0;var wi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,b=Math.imul(ct,bt),c=Math.imul(ct,wt),c=c+Math.imul(lt,bt)|0,v=Math.imul(lt,wt),b=b+Math.imul(st,vt)|0,c=c+Math.imul(st,yt)|0,c=c+Math.imul(at,vt)|0,v=v+Math.imul(at,yt)|0,b=b+Math.imul(rt,Mt)|0,c=c+Math.imul(rt,Ct)|0,c=c+Math.imul(ot,Mt)|0,v=v+Math.imul(ot,Ct)|0,b=b+Math.imul(tt,kt)|0,c=c+Math.imul(tt,Pt)|0,c=c+Math.imul(it,kt)|0,v=v+Math.imul(it,Pt)|0,b=b+Math.imul(Z,St)|0,c=c+Math.imul(Z,At)|0,c=c+Math.imul(Y,St)|0,v=v+Math.imul(Y,At)|0,b=b+Math.imul(V,Ot)|0,c=c+Math.imul(V,xt)|0,c=c+Math.imul(I,Ot)|0,v=v+Math.imul(I,xt)|0;var vi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,b=Math.imul(ut,bt),c=Math.imul(ut,wt),c=c+Math.imul(dt,bt)|0,v=Math.imul(dt,wt),b=b+Math.imul(ct,vt)|0,c=c+Math.imul(ct,yt)|0,c=c+Math.imul(lt,vt)|0,v=v+Math.imul(lt,yt)|0,b=b+Math.imul(st,Mt)|0,c=c+Math.imul(st,Ct)|0,c=c+Math.imul(at,Mt)|0,v=v+Math.imul(at,Ct)|0,b=b+Math.imul(rt,kt)|0,c=c+Math.imul(rt,Pt)|0,c=c+Math.imul(ot,kt)|0,v=v+Math.imul(ot,Pt)|0,b=b+Math.imul(tt,St)|0,c=c+Math.imul(tt,At)|0,c=c+Math.imul(it,St)|0,v=v+Math.imul(it,At)|0,b=b+Math.imul(Z,Ot)|0,c=c+Math.imul(Z,xt)|0,c=c+Math.imul(Y,Ot)|0,v=v+Math.imul(Y,xt)|0,b=b+Math.imul(V,Dt)|0,c=c+Math.imul(V,Et)|0,c=c+Math.imul(I,Dt)|0,v=v+Math.imul(I,Et)|0;var yi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,b=Math.imul(ft,bt),c=Math.imul(ft,wt),c=c+Math.imul(ht,bt)|0,v=Math.imul(ht,wt),b=b+Math.imul(ut,vt)|0,c=c+Math.imul(ut,yt)|0,c=c+Math.imul(dt,vt)|0,v=v+Math.imul(dt,yt)|0,b=b+Math.imul(ct,Mt)|0,c=c+Math.imul(ct,Ct)|0,c=c+Math.imul(lt,Mt)|0,v=v+Math.imul(lt,Ct)|0,b=b+Math.imul(st,kt)|0,c=c+Math.imul(st,Pt)|0,c=c+Math.imul(at,kt)|0,v=v+Math.imul(at,Pt)|0,b=b+Math.imul(rt,St)|0,c=c+Math.imul(rt,At)|0,c=c+Math.imul(ot,St)|0,v=v+Math.imul(ot,At)|0,b=b+Math.imul(tt,Ot)|0,c=c+Math.imul(tt,xt)|0,c=c+Math.imul(it,Ot)|0,v=v+Math.imul(it,xt)|0,b=b+Math.imul(Z,Dt)|0,c=c+Math.imul(Z,Et)|0,c=c+Math.imul(Y,Dt)|0,v=v+Math.imul(Y,Et)|0,b=b+Math.imul(V,Tt)|0,c=c+Math.imul(V,Bt)|0,c=c+Math.imul(I,Tt)|0,v=v+Math.imul(I,Bt)|0;var Mi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,b=Math.imul(mt,bt),c=Math.imul(mt,wt),c=c+Math.imul(pt,bt)|0,v=Math.imul(pt,wt),b=b+Math.imul(ft,vt)|0,c=c+Math.imul(ft,yt)|0,c=c+Math.imul(ht,vt)|0,v=v+Math.imul(ht,yt)|0,b=b+Math.imul(ut,Mt)|0,c=c+Math.imul(ut,Ct)|0,c=c+Math.imul(dt,Mt)|0,v=v+Math.imul(dt,Ct)|0,b=b+Math.imul(ct,kt)|0,c=c+Math.imul(ct,Pt)|0,c=c+Math.imul(lt,kt)|0,v=v+Math.imul(lt,Pt)|0,b=b+Math.imul(st,St)|0,c=c+Math.imul(st,At)|0,c=c+Math.imul(at,St)|0,v=v+Math.imul(at,At)|0,b=b+Math.imul(rt,Ot)|0,c=c+Math.imul(rt,xt)|0,c=c+Math.imul(ot,Ot)|0,v=v+Math.imul(ot,xt)|0,b=b+Math.imul(tt,Dt)|0,c=c+Math.imul(tt,Et)|0,c=c+Math.imul(it,Dt)|0,v=v+Math.imul(it,Et)|0,b=b+Math.imul(Z,Tt)|0,c=c+Math.imul(Z,Bt)|0,c=c+Math.imul(Y,Tt)|0,v=v+Math.imul(Y,Bt)|0,b=b+Math.imul(V,Vt)|0,c=c+Math.imul(V,Ft)|0,c=c+Math.imul(I,Vt)|0,v=v+Math.imul(I,Ft)|0;var Ci=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,b=Math.imul(_t,bt),c=Math.imul(_t,wt),c=c+Math.imul(gt,bt)|0,v=Math.imul(gt,wt),b=b+Math.imul(mt,vt)|0,c=c+Math.imul(mt,yt)|0,c=c+Math.imul(pt,vt)|0,v=v+Math.imul(pt,yt)|0,b=b+Math.imul(ft,Mt)|0,c=c+Math.imul(ft,Ct)|0,c=c+Math.imul(ht,Mt)|0,v=v+Math.imul(ht,Ct)|0,b=b+Math.imul(ut,kt)|0,c=c+Math.imul(ut,Pt)|0,c=c+Math.imul(dt,kt)|0,v=v+Math.imul(dt,Pt)|0,b=b+Math.imul(ct,St)|0,c=c+Math.imul(ct,At)|0,c=c+Math.imul(lt,St)|0,v=v+Math.imul(lt,At)|0,b=b+Math.imul(st,Ot)|0,c=c+Math.imul(st,xt)|0,c=c+Math.imul(at,Ot)|0,v=v+Math.imul(at,xt)|0,b=b+Math.imul(rt,Dt)|0,c=c+Math.imul(rt,Et)|0,c=c+Math.imul(ot,Dt)|0,v=v+Math.imul(ot,Et)|0,b=b+Math.imul(tt,Tt)|0,c=c+Math.imul(tt,Bt)|0,c=c+Math.imul(it,Tt)|0,v=v+Math.imul(it,Bt)|0,b=b+Math.imul(Z,Vt)|0,c=c+Math.imul(Z,Ft)|0,c=c+Math.imul(Y,Vt)|0,v=v+Math.imul(Y,Ft)|0,b=b+Math.imul(V,It)|0,c=c+Math.imul(V,Lt)|0,c=c+Math.imul(I,It)|0,v=v+Math.imul(I,Lt)|0;var ki=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(ki>>>26)|0,ki&=67108863,b=Math.imul(_t,vt),c=Math.imul(_t,yt),c=c+Math.imul(gt,vt)|0,v=Math.imul(gt,yt),b=b+Math.imul(mt,Mt)|0,c=c+Math.imul(mt,Ct)|0,c=c+Math.imul(pt,Mt)|0,v=v+Math.imul(pt,Ct)|0,b=b+Math.imul(ft,kt)|0,c=c+Math.imul(ft,Pt)|0,c=c+Math.imul(ht,kt)|0,v=v+Math.imul(ht,Pt)|0,b=b+Math.imul(ut,St)|0,c=c+Math.imul(ut,At)|0,c=c+Math.imul(dt,St)|0,v=v+Math.imul(dt,At)|0,b=b+Math.imul(ct,Ot)|0,c=c+Math.imul(ct,xt)|0,c=c+Math.imul(lt,Ot)|0,v=v+Math.imul(lt,xt)|0,b=b+Math.imul(st,Dt)|0,c=c+Math.imul(st,Et)|0,c=c+Math.imul(at,Dt)|0,v=v+Math.imul(at,Et)|0,b=b+Math.imul(rt,Tt)|0,c=c+Math.imul(rt,Bt)|0,c=c+Math.imul(ot,Tt)|0,v=v+Math.imul(ot,Bt)|0,b=b+Math.imul(tt,Vt)|0,c=c+Math.imul(tt,Ft)|0,c=c+Math.imul(it,Vt)|0,v=v+Math.imul(it,Ft)|0,b=b+Math.imul(Z,It)|0,c=c+Math.imul(Z,Lt)|0,c=c+Math.imul(Y,It)|0,v=v+Math.imul(Y,Lt)|0;var Pi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Pi>>>26)|0,Pi&=67108863,b=Math.imul(_t,Mt),c=Math.imul(_t,Ct),c=c+Math.imul(gt,Mt)|0,v=Math.imul(gt,Ct),b=b+Math.imul(mt,kt)|0,c=c+Math.imul(mt,Pt)|0,c=c+Math.imul(pt,kt)|0,v=v+Math.imul(pt,Pt)|0,b=b+Math.imul(ft,St)|0,c=c+Math.imul(ft,At)|0,c=c+Math.imul(ht,St)|0,v=v+Math.imul(ht,At)|0,b=b+Math.imul(ut,Ot)|0,c=c+Math.imul(ut,xt)|0,c=c+Math.imul(dt,Ot)|0,v=v+Math.imul(dt,xt)|0,b=b+Math.imul(ct,Dt)|0,c=c+Math.imul(ct,Et)|0,c=c+Math.imul(lt,Dt)|0,v=v+Math.imul(lt,Et)|0,b=b+Math.imul(st,Tt)|0,c=c+Math.imul(st,Bt)|0,c=c+Math.imul(at,Tt)|0,v=v+Math.imul(at,Bt)|0,b=b+Math.imul(rt,Vt)|0,c=c+Math.imul(rt,Ft)|0,c=c+Math.imul(ot,Vt)|0,v=v+Math.imul(ot,Ft)|0,b=b+Math.imul(tt,It)|0,c=c+Math.imul(tt,Lt)|0,c=c+Math.imul(it,It)|0,v=v+Math.imul(it,Lt)|0;var Si=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Si>>>26)|0,Si&=67108863,b=Math.imul(_t,kt),c=Math.imul(_t,Pt),c=c+Math.imul(gt,kt)|0,v=Math.imul(gt,Pt),b=b+Math.imul(mt,St)|0,c=c+Math.imul(mt,At)|0,c=c+Math.imul(pt,St)|0,v=v+Math.imul(pt,At)|0,b=b+Math.imul(ft,Ot)|0,c=c+Math.imul(ft,xt)|0,c=c+Math.imul(ht,Ot)|0,v=v+Math.imul(ht,xt)|0,b=b+Math.imul(ut,Dt)|0,c=c+Math.imul(ut,Et)|0,c=c+Math.imul(dt,Dt)|0,v=v+Math.imul(dt,Et)|0,b=b+Math.imul(ct,Tt)|0,c=c+Math.imul(ct,Bt)|0,c=c+Math.imul(lt,Tt)|0,v=v+Math.imul(lt,Bt)|0,b=b+Math.imul(st,Vt)|0,c=c+Math.imul(st,Ft)|0,c=c+Math.imul(at,Vt)|0,v=v+Math.imul(at,Ft)|0,b=b+Math.imul(rt,It)|0,c=c+Math.imul(rt,Lt)|0,c=c+Math.imul(ot,It)|0,v=v+Math.imul(ot,Lt)|0;var Ai=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,b=Math.imul(_t,St),c=Math.imul(_t,At),c=c+Math.imul(gt,St)|0,v=Math.imul(gt,At),b=b+Math.imul(mt,Ot)|0,c=c+Math.imul(mt,xt)|0,c=c+Math.imul(pt,Ot)|0,v=v+Math.imul(pt,xt)|0,b=b+Math.imul(ft,Dt)|0,c=c+Math.imul(ft,Et)|0,c=c+Math.imul(ht,Dt)|0,v=v+Math.imul(ht,Et)|0,b=b+Math.imul(ut,Tt)|0,c=c+Math.imul(ut,Bt)|0,c=c+Math.imul(dt,Tt)|0,v=v+Math.imul(dt,Bt)|0,b=b+Math.imul(ct,Vt)|0,c=c+Math.imul(ct,Ft)|0,c=c+Math.imul(lt,Vt)|0,v=v+Math.imul(lt,Ft)|0,b=b+Math.imul(st,It)|0,c=c+Math.imul(st,Lt)|0,c=c+Math.imul(at,It)|0,v=v+Math.imul(at,Lt)|0;var Oi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Oi>>>26)|0,Oi&=67108863,b=Math.imul(_t,Ot),c=Math.imul(_t,xt),c=c+Math.imul(gt,Ot)|0,v=Math.imul(gt,xt),b=b+Math.imul(mt,Dt)|0,c=c+Math.imul(mt,Et)|0,c=c+Math.imul(pt,Dt)|0,v=v+Math.imul(pt,Et)|0,b=b+Math.imul(ft,Tt)|0,c=c+Math.imul(ft,Bt)|0,c=c+Math.imul(ht,Tt)|0,v=v+Math.imul(ht,Bt)|0,b=b+Math.imul(ut,Vt)|0,c=c+Math.imul(ut,Ft)|0,c=c+Math.imul(dt,Vt)|0,v=v+Math.imul(dt,Ft)|0,b=b+Math.imul(ct,It)|0,c=c+Math.imul(ct,Lt)|0,c=c+Math.imul(lt,It)|0,v=v+Math.imul(lt,Lt)|0;var xi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(xi>>>26)|0,xi&=67108863,b=Math.imul(_t,Dt),c=Math.imul(_t,Et),c=c+Math.imul(gt,Dt)|0,v=Math.imul(gt,Et),b=b+Math.imul(mt,Tt)|0,c=c+Math.imul(mt,Bt)|0,c=c+Math.imul(pt,Tt)|0,v=v+Math.imul(pt,Bt)|0,b=b+Math.imul(ft,Vt)|0,c=c+Math.imul(ft,Ft)|0,c=c+Math.imul(ht,Vt)|0,v=v+Math.imul(ht,Ft)|0,b=b+Math.imul(ut,It)|0,c=c+Math.imul(ut,Lt)|0,c=c+Math.imul(dt,It)|0,v=v+Math.imul(dt,Lt)|0;var Di=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Di>>>26)|0,Di&=67108863,b=Math.imul(_t,Tt),c=Math.imul(_t,Bt),c=c+Math.imul(gt,Tt)|0,v=Math.imul(gt,Bt),b=b+Math.imul(mt,Vt)|0,c=c+Math.imul(mt,Ft)|0,c=c+Math.imul(pt,Vt)|0,v=v+Math.imul(pt,Ft)|0,b=b+Math.imul(ft,It)|0,c=c+Math.imul(ft,Lt)|0,c=c+Math.imul(ht,It)|0,v=v+Math.imul(ht,Lt)|0;var Ei=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Ei>>>26)|0,Ei&=67108863,b=Math.imul(_t,Vt),c=Math.imul(_t,Ft),c=c+Math.imul(gt,Vt)|0,v=Math.imul(gt,Ft),b=b+Math.imul(mt,It)|0,c=c+Math.imul(mt,Lt)|0,c=c+Math.imul(pt,It)|0,v=v+Math.imul(pt,Lt)|0;var Ti=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Ti>>>26)|0,Ti&=67108863,b=Math.imul(_t,It),c=Math.imul(_t,Lt),c=c+Math.imul(gt,It)|0,v=Math.imul(gt,Lt);var Bi=(M+b|0)+((c&8191)<<13)|0;return M=(v+(c>>>13)|0)+(Bi>>>26)|0,Bi&=67108863,y[0]=pi,y[1]=_i,y[2]=gi,y[3]=bi,y[4]=wi,y[5]=vi,y[6]=yi,y[7]=Mi,y[8]=Ci,y[9]=ki,y[10]=Pi,y[11]=Si,y[12]=Ai,y[13]=Oi,y[14]=xi,y[15]=Di,y[16]=Ei,y[17]=Ti,y[18]=Bi,M!==0&&(y[19]=M,h.length++),h};Math.imul||(O=E);function T(s,l,h){h.negative=l.negative^s.negative,h.length=s.length+l.length;for(var p=0,w=0,y=0;y<h.length-1;y++){var M=w;w=0;for(var b=p&67108863,c=Math.min(y,l.length-1),v=Math.max(0,y-s.length+1);v<=c;v++){var B=y-v,V=s.words[B]|0,I=l.words[v]|0,U=V*I,Z=U&67108863;M=M+(U/67108864|0)|0,Z=Z+b|0,b=Z&67108863,M=M+(Z>>>26)|0,w+=M>>>26,M&=67108863}h.words[y]=b,p=M,M=w}return p!==0?h.words[y]=p:h.length--,h._strip()}function H(s,l,h){return T(s,l,h)}o.prototype.mulTo=function(s,l){var h,p=this.length+s.length;return this.length===10&&s.length===10?h=O(this,s,l):p<63?h=E(this,s,l):p<1024?h=T(this,s,l):h=H(this,s,l),h};function N(s,l){this.x=s,this.y=l}N.prototype.makeRBT=function(s){for(var l=new Array(s),h=o.prototype._countBits(s)-1,p=0;p<s;p++)l[p]=this.revBin(p,h,s);return l},N.prototype.revBin=function(s,l,h){if(s===0||s===h-1)return s;for(var p=0,w=0;w<l;w++)p|=(s&1)<<l-w-1,s>>=1;return p},N.prototype.permute=function(s,l,h,p,w,y){for(var M=0;M<y;M++)p[M]=l[s[M]],w[M]=h[s[M]]},N.prototype.transform=function(s,l,h,p,w,y){this.permute(y,s,l,h,p,w);for(var M=1;M<w;M<<=1)for(var b=M<<1,c=Math.cos(2*Math.PI/b),v=Math.sin(2*Math.PI/b),B=0;B<w;B+=b)for(var V=c,I=v,U=0;U<M;U++){var Z=h[B+U],Y=p[B+U],me=h[B+U+M],tt=p[B+U+M],it=V*me-I*tt;tt=V*tt+I*me,me=it,h[B+U]=Z+me,p[B+U]=Y+tt,h[B+U+M]=Z-me,p[B+U+M]=Y-tt,U!==b&&(it=c*V-v*I,I=c*I+v*V,V=it)}},N.prototype.guessLen13b=function(s,l){var h=Math.max(l,s)|1,p=h&1,w=0;for(h=h/2|0;h;h=h>>>1)w++;return 1<<w+1+p},N.prototype.conjugate=function(s,l,h){if(!(h<=1))for(var p=0;p<h/2;p++){var w=s[p];s[p]=s[h-p-1],s[h-p-1]=w,w=l[p],l[p]=-l[h-p-1],l[h-p-1]=-w}},N.prototype.normalize13b=function(s,l){for(var h=0,p=0;p<l/2;p++){var w=Math.round(s[2*p+1]/l)*8192+Math.round(s[2*p]/l)+h;s[p]=w&67108863,w<67108864?h=0:h=w/67108864|0}return s},N.prototype.convert13b=function(s,l,h,p){for(var w=0,y=0;y<l;y++)w=w+(s[y]|0),h[2*y]=w&8191,w=w>>>13,h[2*y+1]=w&8191,w=w>>>13;for(y=2*l;y<p;++y)h[y]=0;r(w===0),r((w&-8192)===0)},N.prototype.stub=function(s){for(var l=new Array(s),h=0;h<s;h++)l[h]=0;return l},N.prototype.mulp=function(s,l,h){var p=2*this.guessLen13b(s.length,l.length),w=this.makeRBT(p),y=this.stub(p),M=new Array(p),b=new Array(p),c=new Array(p),v=new Array(p),B=new Array(p),V=new Array(p),I=h.words;I.length=p,this.convert13b(s.words,s.length,M,p),this.convert13b(l.words,l.length,v,p),this.transform(M,y,b,c,p,w),this.transform(v,y,B,V,p,w);for(var U=0;U<p;U++){var Z=b[U]*B[U]-c[U]*V[U];c[U]=b[U]*V[U]+c[U]*B[U],b[U]=Z}return this.conjugate(b,c,p),this.transform(b,c,I,y,p,w),this.conjugate(I,y,p),this.normalize13b(I,p),h.negative=s.negative^l.negative,h.length=s.length+l.length,h._strip()},o.prototype.mul=function(s){var l=new o(null);return l.words=new Array(this.length+s.length),this.mulTo(s,l)},o.prototype.mulf=function(s){var l=new o(null);return l.words=new Array(this.length+s.length),H(this,s,l)},o.prototype.imul=function(s){return this.clone().mulTo(s,this)},o.prototype.imuln=function(s){var l=s<0;l&&(s=-s),r(typeof s=="number"),r(s<67108864);for(var h=0,p=0;p<this.length;p++){var w=(this.words[p]|0)*s,y=(w&67108863)+(h&67108863);h>>=26,h+=w/67108864|0,h+=y>>>26,this.words[p]=y&67108863}return h!==0&&(this.words[p]=h,this.length++),this.length=s===0?1:this.length,l?this.ineg():this},o.prototype.muln=function(s){return this.clone().imuln(s)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(s){var l=x(s);if(l.length===0)return new o(1);for(var h=this,p=0;p<l.length&&l[p]===0;p++,h=h.sqr());if(++p<l.length)for(var w=h.sqr();p<l.length;p++,w=w.sqr())l[p]!==0&&(h=h.mul(w));return h},o.prototype.iushln=function(s){r(typeof s=="number"&&s>=0);var l=s%26,h=(s-l)/26,p=67108863>>>26-l<<26-l,w;if(l!==0){var y=0;for(w=0;w<this.length;w++){var M=this.words[w]&p,b=(this.words[w]|0)-M<<l;this.words[w]=b|y,y=M>>>26-l}y&&(this.words[w]=y,this.length++)}if(h!==0){for(w=this.length-1;w>=0;w--)this.words[w+h]=this.words[w];for(w=0;w<h;w++)this.words[w]=0;this.length+=h}return this._strip()},o.prototype.ishln=function(s){return r(this.negative===0),this.iushln(s)},o.prototype.iushrn=function(s,l,h){r(typeof s=="number"&&s>=0);var p;l?p=(l-l%26)/26:p=0;var w=s%26,y=Math.min((s-w)/26,this.length),M=67108863^67108863>>>w<<w,b=h;if(p-=y,p=Math.max(0,p),b){for(var c=0;c<y;c++)b.words[c]=this.words[c];b.length=y}if(y!==0)if(this.length>y)for(this.length-=y,c=0;c<this.length;c++)this.words[c]=this.words[c+y];else this.words[0]=0,this.length=1;var v=0;for(c=this.length-1;c>=0&&(v!==0||c>=p);c--){var B=this.words[c]|0;this.words[c]=v<<26-w|B>>>w,v=B&M}return b&&v!==0&&(b.words[b.length++]=v),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(s,l,h){return r(this.negative===0),this.iushrn(s,l,h)},o.prototype.shln=function(s){return this.clone().ishln(s)},o.prototype.ushln=function(s){return this.clone().iushln(s)},o.prototype.shrn=function(s){return this.clone().ishrn(s)},o.prototype.ushrn=function(s){return this.clone().iushrn(s)},o.prototype.testn=function(s){r(typeof s=="number"&&s>=0);var l=s%26,h=(s-l)/26,p=1<<l;if(this.length<=h)return!1;var w=this.words[h];return!!(w&p)},o.prototype.imaskn=function(s){r(typeof s=="number"&&s>=0);var l=s%26,h=(s-l)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(l!==0&&h++,this.length=Math.min(h,this.length),l!==0){var p=67108863^67108863>>>l<<l;this.words[this.length-1]&=p}return this._strip()},o.prototype.maskn=function(s){return this.clone().imaskn(s)},o.prototype.iaddn=function(s){return r(typeof s=="number"),r(s<67108864),s<0?this.isubn(-s):this.negative!==0?this.length===1&&(this.words[0]|0)<=s?(this.words[0]=s-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(s),this.negative=1,this):this._iaddn(s)},o.prototype._iaddn=function(s){this.words[0]+=s;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},o.prototype.isubn=function(s){if(r(typeof s=="number"),r(s<67108864),s<0)return this.iaddn(-s);if(this.negative!==0)return this.negative=0,this.iaddn(s),this.negative=1,this;if(this.words[0]-=s,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},o.prototype.addn=function(s){return this.clone().iaddn(s)},o.prototype.subn=function(s){return this.clone().isubn(s)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(s,l,h){var p=s.length+h,w;this._expand(p);var y,M=0;for(w=0;w<s.length;w++){y=(this.words[w+h]|0)+M;var b=(s.words[w]|0)*l;y-=b&67108863,M=(y>>26)-(b/67108864|0),this.words[w+h]=y&67108863}for(;w<this.length-h;w++)y=(this.words[w+h]|0)+M,M=y>>26,this.words[w+h]=y&67108863;if(M===0)return this._strip();for(r(M===-1),M=0,w=0;w<this.length;w++)y=-(this.words[w]|0)+M,M=y>>26,this.words[w]=y&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(s,l){var h=this.length-s.length,p=this.clone(),w=s,y=w.words[w.length-1]|0,M=this._countBits(y);h=26-M,h!==0&&(w=w.ushln(h),p.iushln(h),y=w.words[w.length-1]|0);var b=p.length-w.length,c;if(l!=="mod"){c=new o(null),c.length=b+1,c.words=new Array(c.length);for(var v=0;v<c.length;v++)c.words[v]=0}var B=p.clone()._ishlnsubmul(w,1,b);B.negative===0&&(p=B,c&&(c.words[b]=1));for(var V=b-1;V>=0;V--){var I=(p.words[w.length+V]|0)*67108864+(p.words[w.length+V-1]|0);for(I=Math.min(I/y|0,67108863),p._ishlnsubmul(w,I,V);p.negative!==0;)I--,p.negative=0,p._ishlnsubmul(w,1,V),p.isZero()||(p.negative^=1);c&&(c.words[V]=I)}return c&&c._strip(),p._strip(),l!=="div"&&h!==0&&p.iushrn(h),{div:c||null,mod:p}},o.prototype.divmod=function(s,l,h){if(r(!s.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var p,w,y;return this.negative!==0&&s.negative===0?(y=this.neg().divmod(s,l),l!=="mod"&&(p=y.div.neg()),l!=="div"&&(w=y.mod.neg(),h&&w.negative!==0&&w.iadd(s)),{div:p,mod:w}):this.negative===0&&s.negative!==0?(y=this.divmod(s.neg(),l),l!=="mod"&&(p=y.div.neg()),{div:p,mod:y.mod}):this.negative&s.negative?(y=this.neg().divmod(s.neg(),l),l!=="div"&&(w=y.mod.neg(),h&&w.negative!==0&&w.isub(s)),{div:y.div,mod:w}):s.length>this.length||this.cmp(s)<0?{div:new o(0),mod:this}:s.length===1?l==="div"?{div:this.divn(s.words[0]),mod:null}:l==="mod"?{div:null,mod:new o(this.modrn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new o(this.modrn(s.words[0]))}:this._wordDiv(s,l)},o.prototype.div=function(s){return this.divmod(s,"div",!1).div},o.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},o.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},o.prototype.divRound=function(s){var l=this.divmod(s);if(l.mod.isZero())return l.div;var h=l.div.negative!==0?l.mod.isub(s):l.mod,p=s.ushrn(1),w=s.andln(1),y=h.cmp(p);return y<0||w===1&&y===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},o.prototype.modrn=function(s){var l=s<0;l&&(s=-s),r(s<=67108863);for(var h=(1<<26)%s,p=0,w=this.length-1;w>=0;w--)p=(h*p+(this.words[w]|0))%s;return l?-p:p},o.prototype.modn=function(s){return this.modrn(s)},o.prototype.idivn=function(s){var l=s<0;l&&(s=-s),r(s<=67108863);for(var h=0,p=this.length-1;p>=0;p--){var w=(this.words[p]|0)+h*67108864;this.words[p]=w/s|0,h=w%s}return this._strip(),l?this.ineg():this},o.prototype.divn=function(s){return this.clone().idivn(s)},o.prototype.egcd=function(s){r(s.negative===0),r(!s.isZero());var l=this,h=s.clone();l.negative!==0?l=l.umod(s):l=l.clone();for(var p=new o(1),w=new o(0),y=new o(0),M=new o(1),b=0;l.isEven()&&h.isEven();)l.iushrn(1),h.iushrn(1),++b;for(var c=h.clone(),v=l.clone();!l.isZero();){for(var B=0,V=1;!(l.words[0]&V)&&B<26;++B,V<<=1);if(B>0)for(l.iushrn(B);B-- >0;)(p.isOdd()||w.isOdd())&&(p.iadd(c),w.isub(v)),p.iushrn(1),w.iushrn(1);for(var I=0,U=1;!(h.words[0]&U)&&I<26;++I,U<<=1);if(I>0)for(h.iushrn(I);I-- >0;)(y.isOdd()||M.isOdd())&&(y.iadd(c),M.isub(v)),y.iushrn(1),M.iushrn(1);l.cmp(h)>=0?(l.isub(h),p.isub(y),w.isub(M)):(h.isub(l),y.isub(p),M.isub(w))}return{a:y,b:M,gcd:h.iushln(b)}},o.prototype._invmp=function(s){r(s.negative===0),r(!s.isZero());var l=this,h=s.clone();l.negative!==0?l=l.umod(s):l=l.clone();for(var p=new o(1),w=new o(0),y=h.clone();l.cmpn(1)>0&&h.cmpn(1)>0;){for(var M=0,b=1;!(l.words[0]&b)&&M<26;++M,b<<=1);if(M>0)for(l.iushrn(M);M-- >0;)p.isOdd()&&p.iadd(y),p.iushrn(1);for(var c=0,v=1;!(h.words[0]&v)&&c<26;++c,v<<=1);if(c>0)for(h.iushrn(c);c-- >0;)w.isOdd()&&w.iadd(y),w.iushrn(1);l.cmp(h)>=0?(l.isub(h),p.isub(w)):(h.isub(l),w.isub(p))}var B;return l.cmpn(1)===0?B=p:B=w,B.cmpn(0)<0&&B.iadd(s),B},o.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var l=this.clone(),h=s.clone();l.negative=0,h.negative=0;for(var p=0;l.isEven()&&h.isEven();p++)l.iushrn(1),h.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;h.isEven();)h.iushrn(1);var w=l.cmp(h);if(w<0){var y=l;l=h,h=y}else if(w===0||h.cmpn(1)===0)break;l.isub(h)}while(!0);return h.iushln(p)},o.prototype.invm=function(s){return this.egcd(s).a.umod(s)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(s){return this.words[0]&s},o.prototype.bincn=function(s){r(typeof s=="number");var l=s%26,h=(s-l)/26,p=1<<l;if(this.length<=h)return this._expand(h+1),this.words[h]|=p,this;for(var w=p,y=h;w!==0&&y<this.length;y++){var M=this.words[y]|0;M+=w,w=M>>>26,M&=67108863,this.words[y]=M}return w!==0&&(this.words[y]=w,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(s){var l=s<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var h;if(this.length>1)h=1;else{l&&(s=-s),r(s<=67108863,"Number is too big");var p=this.words[0]|0;h=p===s?0:p<s?-1:1}return this.negative!==0?-h|0:h},o.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var l=this.ucmp(s);return this.negative!==0?-l|0:l},o.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var l=0,h=this.length-1;h>=0;h--){var p=this.words[h]|0,w=s.words[h]|0;if(p!==w){p<w?l=-1:p>w&&(l=1);break}}return l},o.prototype.gtn=function(s){return this.cmpn(s)===1},o.prototype.gt=function(s){return this.cmp(s)===1},o.prototype.gten=function(s){return this.cmpn(s)>=0},o.prototype.gte=function(s){return this.cmp(s)>=0},o.prototype.ltn=function(s){return this.cmpn(s)===-1},o.prototype.lt=function(s){return this.cmp(s)===-1},o.prototype.lten=function(s){return this.cmpn(s)<=0},o.prototype.lte=function(s){return this.cmp(s)<=0},o.prototype.eqn=function(s){return this.cmpn(s)===0},o.prototype.eq=function(s){return this.cmp(s)===0},o.red=function(s){return new X(s)},o.prototype.toRed=function(s){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},o.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(s){return this.red=s,this},o.prototype.forceRed=function(s){return r(!this.red,"Already a number in reduction context"),this._forceRed(s)},o.prototype.redAdd=function(s){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},o.prototype.redIAdd=function(s){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},o.prototype.redSub=function(s){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},o.prototype.redISub=function(s){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},o.prototype.redShl=function(s){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},o.prototype.redMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},o.prototype.redIMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(s){return r(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var G={k256:null,p224:null,p192:null,p25519:null};function $(s,l){this.name=s,this.p=new o(l,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}$.prototype._tmp=function(){var s=new o(null);return s.words=new Array(Math.ceil(this.n/13)),s},$.prototype.ireduce=function(s){var l=s,h;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),h=l.bitLength();while(h>this.n);var p=h<this.n?-1:l.ucmp(this.p);return p===0?(l.words[0]=0,l.length=1):p>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},$.prototype.split=function(s,l){s.iushrn(this.n,0,l)},$.prototype.imulK=function(s){return s.imul(this.k)};function z(){$.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a(z,$),z.prototype.split=function(s,l){for(var h=4194303,p=Math.min(s.length,9),w=0;w<p;w++)l.words[w]=s.words[w];if(l.length=p,s.length<=9){s.words[0]=0,s.length=1;return}var y=s.words[9];for(l.words[l.length++]=y&h,w=10;w<s.length;w++){var M=s.words[w]|0;s.words[w-10]=(M&h)<<4|y>>>22,y=M}y>>>=22,s.words[w-10]=y,y===0&&s.length>10?s.length-=10:s.length-=9},z.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var l=0,h=0;h<s.length;h++){var p=s.words[h]|0;l+=p*977,s.words[h]=l&67108863,l=p*64+(l/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function W(){$.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}a(W,$);function et(){$.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}a(et,$);function qt(){$.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}a(qt,$),qt.prototype.imulK=function(s){for(var l=0,h=0;h<s.length;h++){var p=(s.words[h]|0)*19+l,w=p&67108863;p>>>=26,s.words[h]=w,l=p}return l!==0&&(s.words[s.length++]=l),s},o._prime=function(s){if(G[s])return G[s];var l;if(s==="k256")l=new z;else if(s==="p224")l=new W;else if(s==="p192")l=new et;else if(s==="p25519")l=new qt;else throw new Error("Unknown prime "+s);return G[s]=l,l};function X(s){if(typeof s=="string"){var l=o._prime(s);this.m=l.p,this.prime=l}else r(s.gtn(1),"modulus must be greater than 1"),this.m=s,this.prime=null}X.prototype._verify1=function(s){r(s.negative===0,"red works only with positives"),r(s.red,"red works only with red numbers")},X.prototype._verify2=function(s,l){r((s.negative|l.negative)===0,"red works only with positives"),r(s.red&&s.red===l.red,"red works only with red numbers")},X.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):(_(s,s.umod(this.m)._forceRed(this)),s)},X.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},X.prototype.add=function(s,l){this._verify2(s,l);var h=s.add(l);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},X.prototype.iadd=function(s,l){this._verify2(s,l);var h=s.iadd(l);return h.cmp(this.m)>=0&&h.isub(this.m),h},X.prototype.sub=function(s,l){this._verify2(s,l);var h=s.sub(l);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},X.prototype.isub=function(s,l){this._verify2(s,l);var h=s.isub(l);return h.cmpn(0)<0&&h.iadd(this.m),h},X.prototype.shl=function(s,l){return this._verify1(s),this.imod(s.ushln(l))},X.prototype.imul=function(s,l){return this._verify2(s,l),this.imod(s.imul(l))},X.prototype.mul=function(s,l){return this._verify2(s,l),this.imod(s.mul(l))},X.prototype.isqr=function(s){return this.imul(s,s.clone())},X.prototype.sqr=function(s){return this.mul(s,s)},X.prototype.sqrt=function(s){if(s.isZero())return s.clone();var l=this.m.andln(3);if(r(l%2===1),l===3){var h=this.m.add(new o(1)).iushrn(2);return this.pow(s,h)}for(var p=this.m.subn(1),w=0;!p.isZero()&&p.andln(1)===0;)w++,p.iushrn(1);r(!p.isZero());var y=new o(1).toRed(this),M=y.redNeg(),b=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new o(2*c*c).toRed(this);this.pow(c,b).cmp(M)!==0;)c.redIAdd(M);for(var v=this.pow(c,p),B=this.pow(s,p.addn(1).iushrn(1)),V=this.pow(s,p),I=w;V.cmp(y)!==0;){for(var U=V,Z=0;U.cmp(y)!==0;Z++)U=U.redSqr();r(Z<I);var Y=this.pow(v,new o(1).iushln(I-Z-1));B=B.redMul(Y),v=Y.redSqr(),V=V.redMul(v),I=Z}return B},X.prototype.invm=function(s){var l=s._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},X.prototype.pow=function(s,l){if(l.isZero())return new o(1).toRed(this);if(l.cmpn(1)===0)return s.clone();var h=4,p=new Array(1<<h);p[0]=new o(1).toRed(this),p[1]=s;for(var w=2;w<p.length;w++)p[w]=this.mul(p[w-1],s);var y=p[0],M=0,b=0,c=l.bitLength()%26;for(c===0&&(c=26),w=l.length-1;w>=0;w--){for(var v=l.words[w],B=c-1;B>=0;B--){var V=v>>B&1;if(y!==p[0]&&(y=this.sqr(y)),V===0&&M===0){b=0;continue}M<<=1,M|=V,b++,!(b!==h&&(w!==0||B!==0))&&(y=this.mul(y,p[M]),b=0,M=0)}c=26}return y},X.prototype.convertTo=function(s){var l=s.umod(this.m);return l===s?l.clone():l},X.prototype.convertFrom=function(s){var l=s.clone();return l.red=null,l},o.mont=function(s){return new Q(s)};function Q(s){X.call(this,s),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}a(Q,X),Q.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},Q.prototype.convertFrom=function(s){var l=this.imod(s.mul(this.rinv));return l.red=null,l},Q.prototype.imul=function(s,l){if(s.isZero()||l.isZero())return s.words[0]=0,s.length=1,s;var h=s.imul(l),p=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),w=h.isub(p).iushrn(this.shift),y=w;return w.cmp(this.m)>=0?y=w.isub(this.m):w.cmpn(0)<0&&(y=w.iadd(this.m)),y._forceRed(this)},Q.prototype.mul=function(s,l){if(s.isZero()||l.isZero())return new o(0)._forceRed(this);var h=s.mul(l),p=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),w=h.isub(p).iushrn(this.shift),y=w;return w.cmp(this.m)>=0?y=w.isub(this.m):w.cmpn(0)<0&&(y=w.iadd(this.m)),y._forceRed(this)},Q.prototype.invm=function(s){var l=this.imod(s._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof t>"u"||t,i)}),Vi={REQUEST_PARAMS:"requestParams",METHOD_NAME:"methodName"},Fr=class Un extends Error{constructor(t,e,n){super(t),this.code=e,this.details=n,this.name=this.constructor.name}static{this.DETAILS_KEYS=Vi}toJSON(){return{name:this.name,message:this.message,code:this.code,details:this.details}}toString(){return JSON.stringify(this.toJSON())}static isErrorCode(t,e){return t instanceof Un&&t.code===e}},Ir=class extends Fr{constructor(i,t,e){super(i,t||"UnknownError",e)}static isCommonErrorCode(i,t){return this.isErrorCode(i,t)}},Gt=(i,t,e)=>{throw new Ir(t,i,e)};var $n=864e5;var Oe=9e15,be=1e9,Ii="0123456789abcdef",Je="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ye="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Li={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Oe,maxE:Oe,crypto:!1},Kn,le,R=!0,ei="[DecimalError] ",ge=ei+"Invalid argument: ",Wn=ei+"Precision limit exceeded",Zn=ei+"crypto unavailable",zn="[object Decimal]",Wt=Math.floor,Nt=Math.pow,Nr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Ur=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,$r=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Xn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,te=1e7,j=7,Kr=9007199254740991,Wr=Je.length-1,ji=Ye.length-1,A={toStringTag:zn};A.absoluteValue=A.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),F(i)};A.ceil=function(){return F(new this.constructor(this),this.e+1,2)};A.clampedTo=A.clamp=function(i,t){var e,n=this,r=n.constructor;if(i=new r(i),t=new r(t),!i.s||!t.s)return new r(NaN);if(i.gt(t))throw Error(ge+t);return e=n.cmp(i),e<0?i:n.cmp(t)>0?t:new r(n)};A.comparedTo=A.cmp=function(i){var t,e,n,r,a=this,o=a.d,u=(i=new a.constructor(i)).d,d=a.s,f=i.s;if(!o||!u)return!d||!f?NaN:d!==f?d:o===u?0:!o^d<0?1:-1;if(!o[0]||!u[0])return o[0]?d:u[0]?-f:0;if(d!==f)return d;if(a.e!==i.e)return a.e>i.e^d<0?1:-1;for(n=o.length,r=u.length,t=0,e=n<r?n:r;t<e;++t)if(o[t]!==u[t])return o[t]>u[t]^d<0?1:-1;return n===r?0:n>r^d<0?1:-1};A.cosine=A.cos=function(){var i,t,e=this,n=e.constructor;return e.d?e.d[0]?(i=n.precision,t=n.rounding,n.precision=i+Math.max(e.e,e.sd())+j,n.rounding=1,e=Zr(n,Yn(n,e)),n.precision=i,n.rounding=t,F(le==2||le==3?e.neg():e,i,t,!0)):new n(1):new n(NaN)};A.cubeRoot=A.cbrt=function(){var i,t,e,n,r,a,o,u,d,f,m=this,_=m.constructor;if(!m.isFinite()||m.isZero())return new _(m);for(R=!1,a=m.s*Nt(m.s*m,1/3),!a||Math.abs(a)==1/0?(e=Ut(m.d),i=m.e,(a=(i-e.length+1)%3)&&(e+=a==1||a==-2?"0":"00"),a=Nt(e,1/3),i=Wt((i+1)/3)-(i%3==(i<0?-1:2)),a==1/0?e="5e"+i:(e=a.toExponential(),e=e.slice(0,e.indexOf("e")+1)+i),n=new _(e),n.s=m.s):n=new _(a.toString()),o=(i=_.precision)+3;;)if(u=n,d=u.times(u).times(u),f=d.plus(m),n=J(f.plus(m).times(u),f.plus(d),o+2,1),Ut(u.d).slice(0,o)===(e=Ut(n.d)).slice(0,o))if(e=e.slice(o-3,o+1),e=="9999"||!r&&e=="4999"){if(!r&&(F(u,i+1,0),u.times(u).times(u).eq(m))){n=u;break}o+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(F(n,i+1,1),t=!n.times(n).times(n).eq(m));break}return R=!0,F(n,i,_.rounding,t)};A.decimalPlaces=A.dp=function(){var i,t=this.d,e=NaN;if(t){if(i=t.length-1,e=(i-Wt(this.e/j))*j,i=t[i],i)for(;i%10==0;i/=10)e--;e<0&&(e=0)}return e};A.dividedBy=A.div=function(i){return J(this,new this.constructor(i))};A.dividedToIntegerBy=A.divToInt=function(i){var t=this,e=t.constructor;return F(J(t,new e(i),0,1,1),e.precision,e.rounding)};A.equals=A.eq=function(i){return this.cmp(i)===0};A.floor=function(){return F(new this.constructor(this),this.e+1,3)};A.greaterThan=A.gt=function(i){return this.cmp(i)>0};A.greaterThanOrEqualTo=A.gte=function(i){var t=this.cmp(i);return t==1||t===0};A.hyperbolicCosine=A.cosh=function(){var i,t,e,n,r,a=this,o=a.constructor,u=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return u;e=o.precision,n=o.rounding,o.precision=e+Math.max(a.e,a.sd())+4,o.rounding=1,r=a.d.length,r<32?(i=Math.ceil(r/3),t=(1/ni(4,i)).toString()):(i=16,t="2.3283064365386962890625e-10"),a=xe(o,1,a.times(t),new o(1),!0);for(var d,f=i,m=new o(8);f--;)d=a.times(a),a=u.minus(d.times(m.minus(d.times(m))));return F(a,o.precision=e,o.rounding=n,!0)};A.hyperbolicSine=A.sinh=function(){var i,t,e,n,r=this,a=r.constructor;if(!r.isFinite()||r.isZero())return new a(r);if(t=a.precision,e=a.rounding,a.precision=t+Math.max(r.e,r.sd())+4,a.rounding=1,n=r.d.length,n<3)r=xe(a,2,r,r,!0);else{i=1.4*Math.sqrt(n),i=i>16?16:i|0,r=r.times(1/ni(5,i)),r=xe(a,2,r,r,!0);for(var o,u=new a(5),d=new a(16),f=new a(20);i--;)o=r.times(r),r=r.times(u.plus(o.times(d.times(o).plus(f))))}return a.precision=t,a.rounding=e,F(r,t,e,!0)};A.hyperbolicTangent=A.tanh=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+7,n.rounding=1,J(e.sinh(),e.cosh(),n.precision=i,n.rounding=t)):new n(e.s)};A.inverseCosine=A.acos=function(){var i=this,t=i.constructor,e=i.abs().cmp(1),n=t.precision,r=t.rounding;return e!==-1?e===0?i.isNeg()?oe(t,n,r):new t(0):new t(NaN):i.isZero()?oe(t,n+4,r).times(.5):(t.precision=n+6,t.rounding=1,i=new t(1).minus(i).div(i.plus(1)).sqrt().atan(),t.precision=n,t.rounding=r,i.times(2))};A.inverseHyperbolicCosine=A.acosh=function(){var i,t,e=this,n=e.constructor;return e.lte(1)?new n(e.eq(1)?0:NaN):e.isFinite()?(i=n.precision,t=n.rounding,n.precision=i+Math.max(Math.abs(e.e),e.sd())+4,n.rounding=1,R=!1,e=e.times(e).minus(1).sqrt().plus(e),R=!0,n.precision=i,n.rounding=t,e.ln()):new n(e)};A.inverseHyperbolicSine=A.asinh=function(){var i,t,e=this,n=e.constructor;return!e.isFinite()||e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+2*Math.max(Math.abs(e.e),e.sd())+6,n.rounding=1,R=!1,e=e.times(e).plus(1).sqrt().plus(e),R=!0,n.precision=i,n.rounding=t,e.ln())};A.inverseHyperbolicTangent=A.atanh=function(){var i,t,e,n,r=this,a=r.constructor;return r.isFinite()?r.e>=0?new a(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(i=a.precision,t=a.rounding,n=r.sd(),Math.max(n,i)<2*-r.e-1?F(new a(r),i,t,!0):(a.precision=e=n-r.e,r=J(r.plus(1),new a(1).minus(r),e+i,1),a.precision=i+4,a.rounding=1,r=r.ln(),a.precision=i,a.rounding=t,r.times(.5))):new a(NaN)};A.inverseSine=A.asin=function(){var i,t,e,n,r=this,a=r.constructor;return r.isZero()?new a(r):(t=r.abs().cmp(1),e=a.precision,n=a.rounding,t!==-1?t===0?(i=oe(a,e+4,n).times(.5),i.s=r.s,i):new a(NaN):(a.precision=e+6,a.rounding=1,r=r.div(new a(1).minus(r.times(r)).sqrt().plus(1)).atan(),a.precision=e,a.rounding=n,r.times(2)))};A.inverseTangent=A.atan=function(){var i,t,e,n,r,a,o,u,d,f=this,m=f.constructor,_=m.precision,g=m.rounding;if(f.isFinite()){if(f.isZero())return new m(f);if(f.abs().eq(1)&&_+4<=ji)return o=oe(m,_+4,g).times(.25),o.s=f.s,o}else{if(!f.s)return new m(NaN);if(_+4<=ji)return o=oe(m,_+4,g).times(.5),o.s=f.s,o}for(m.precision=u=_+10,m.rounding=1,e=Math.min(28,u/j+2|0),i=e;i;--i)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(R=!1,t=Math.ceil(u/j),n=1,d=f.times(f),o=new m(f),r=f;i!==-1;)if(r=r.times(d),a=o.minus(r.div(n+=2)),r=r.times(d),o=a.plus(r.div(n+=2)),o.d[t]!==void 0)for(i=t;o.d[i]===a.d[i]&&i--;);return e&&(o=o.times(2<<e-1)),R=!0,F(o,m.precision=_,m.rounding=g,!0)};A.isFinite=function(){return!!this.d};A.isInteger=A.isInt=function(){return!!this.d&&Wt(this.e/j)>this.d.length-2};A.isNaN=function(){return!this.s};A.isNegative=A.isNeg=function(){return this.s<0};A.isPositive=A.isPos=function(){return this.s>0};A.isZero=function(){return!!this.d&&this.d[0]===0};A.lessThan=A.lt=function(i){return this.cmp(i)<0};A.lessThanOrEqualTo=A.lte=function(i){return this.cmp(i)<1};A.logarithm=A.log=function(i){var t,e,n,r,a,o,u,d,f=this,m=f.constructor,_=m.precision,g=m.rounding,C=5;if(i==null)i=new m(10),t=!0;else{if(i=new m(i),e=i.d,i.s<0||!e||!e[0]||i.eq(1))return new m(NaN);t=i.eq(10)}if(e=f.d,f.s<0||!e||!e[0]||f.eq(1))return new m(e&&!e[0]?-1/0:f.s!=1?NaN:e?0:1/0);if(t)if(e.length>1)a=!0;else{for(r=e[0];r%10===0;)r/=10;a=r!==1}if(R=!1,u=_+C,o=_e(f,u),n=t?ti(m,u+10):_e(i,u),d=J(o,n,u,1),Fe(d.d,r=_,g))do if(u+=10,o=_e(f,u),n=t?ti(m,u+10):_e(i,u),d=J(o,n,u,1),!a){+Ut(d.d).slice(r+1,r+15)+1==1e14&&(d=F(d,_+1,0));break}while(Fe(d.d,r+=10,g));return R=!0,F(d,_,g)};A.minus=A.sub=function(i){var t,e,n,r,a,o,u,d,f,m,_,g,C=this,k=C.constructor;if(i=new k(i),!C.d||!i.d)return!C.s||!i.s?i=new k(NaN):C.d?i.s=-i.s:i=new k(i.d||C.s!==i.s?C:NaN),i;if(C.s!=i.s)return i.s=-i.s,C.plus(i);if(f=C.d,g=i.d,u=k.precision,d=k.rounding,!f[0]||!g[0]){if(g[0])i.s=-i.s;else if(f[0])i=new k(C);else return new k(d===3?-0:0);return R?F(i,u,d):i}if(e=Wt(i.e/j),m=Wt(C.e/j),f=f.slice(),a=m-e,a){for(_=a<0,_?(t=f,a=-a,o=g.length):(t=g,e=m,o=f.length),n=Math.max(Math.ceil(u/j),o)+2,a>n&&(a=n,t.length=1),t.reverse(),n=a;n--;)t.push(0);t.reverse()}else{for(n=f.length,o=g.length,_=n<o,_&&(o=n),n=0;n<o;n++)if(f[n]!=g[n]){_=f[n]<g[n];break}a=0}for(_&&(t=f,f=g,g=t,i.s=-i.s),o=f.length,n=g.length-o;n>0;--n)f[o++]=0;for(n=g.length;n>a;){if(f[--n]<g[n]){for(r=n;r&&f[--r]===0;)f[r]=te-1;--f[r],f[n]+=te}f[n]-=g[n]}for(;f[--o]===0;)f.pop();for(;f[0]===0;f.shift())--e;return f[0]?(i.d=f,i.e=ii(f,e),R?F(i,u,d):i):new k(d===3?-0:0)};A.modulo=A.mod=function(i){var t,e=this,n=e.constructor;return i=new n(i),!e.d||!i.s||i.d&&!i.d[0]?new n(NaN):!i.d||e.d&&!e.d[0]?F(new n(e),n.precision,n.rounding):(R=!1,n.modulo==9?(t=J(e,i.abs(),0,3,1),t.s*=i.s):t=J(e,i,0,n.modulo,1),t=t.times(i),R=!0,e.minus(t))};A.naturalExponential=A.exp=function(){return qi(this)};A.naturalLogarithm=A.ln=function(){return _e(this)};A.negated=A.neg=function(){var i=new this.constructor(this);return i.s=-i.s,F(i)};A.plus=A.add=function(i){var t,e,n,r,a,o,u,d,f,m,_=this,g=_.constructor;if(i=new g(i),!_.d||!i.d)return!_.s||!i.s?i=new g(NaN):_.d||(i=new g(i.d||_.s===i.s?_:NaN)),i;if(_.s!=i.s)return i.s=-i.s,_.minus(i);if(f=_.d,m=i.d,u=g.precision,d=g.rounding,!f[0]||!m[0])return m[0]||(i=new g(_)),R?F(i,u,d):i;if(a=Wt(_.e/j),n=Wt(i.e/j),f=f.slice(),r=a-n,r){for(r<0?(e=f,r=-r,o=m.length):(e=m,n=a,o=f.length),a=Math.ceil(u/j),o=a>o?a+1:o+1,r>o&&(r=o,e.length=1),e.reverse();r--;)e.push(0);e.reverse()}for(o=f.length,r=m.length,o-r<0&&(r=o,e=m,m=f,f=e),t=0;r;)t=(f[--r]=f[r]+m[r]+t)/te|0,f[r]%=te;for(t&&(f.unshift(t),++n),o=f.length;f[--o]==0;)f.pop();return i.d=f,i.e=ii(f,n),R?F(i,u,d):i};A.precision=A.sd=function(i){var t,e=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(ge+i);return e.d?(t=Hn(e.d),i&&e.e+1>t&&(t=e.e+1)):t=NaN,t};A.round=function(){var i=this,t=i.constructor;return F(new t(i),i.e+1,t.rounding)};A.sine=A.sin=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+Math.max(e.e,e.sd())+j,n.rounding=1,e=Xr(n,Yn(n,e)),n.precision=i,n.rounding=t,F(le>2?e.neg():e,i,t,!0)):new n(NaN)};A.squareRoot=A.sqrt=function(){var i,t,e,n,r,a,o=this,u=o.d,d=o.e,f=o.s,m=o.constructor;if(f!==1||!u||!u[0])return new m(!f||f<0&&(!u||u[0])?NaN:u?o:1/0);for(R=!1,f=Math.sqrt(+o),f==0||f==1/0?(t=Ut(u),(t.length+d)%2==0&&(t+="0"),f=Math.sqrt(t),d=Wt((d+1)/2)-(d<0||d%2),f==1/0?t="5e"+d:(t=f.toExponential(),t=t.slice(0,t.indexOf("e")+1)+d),n=new m(t)):n=new m(f.toString()),e=(d=m.precision)+3;;)if(a=n,n=a.plus(J(o,a,e+2,1)).times(.5),Ut(a.d).slice(0,e)===(t=Ut(n.d)).slice(0,e))if(t=t.slice(e-3,e+1),t=="9999"||!r&&t=="4999"){if(!r&&(F(a,d+1,0),a.times(a).eq(o))){n=a;break}e+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(F(n,d+1,1),i=!n.times(n).eq(o));break}return R=!0,F(n,d,m.rounding,i)};A.tangent=A.tan=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+10,n.rounding=1,e=e.sin(),e.s=1,e=J(e,new n(1).minus(e.times(e)).sqrt(),i+10,0),n.precision=i,n.rounding=t,F(le==2||le==4?e.neg():e,i,t,!0)):new n(NaN)};A.times=A.mul=function(i){var t,e,n,r,a,o,u,d,f,m=this,_=m.constructor,g=m.d,C=(i=new _(i)).d;if(i.s*=m.s,!g||!g[0]||!C||!C[0])return new _(!i.s||g&&!g[0]&&!C||C&&!C[0]&&!g?NaN:!g||!C?i.s/0:i.s*0);for(e=Wt(m.e/j)+Wt(i.e/j),d=g.length,f=C.length,d<f&&(a=g,g=C,C=a,o=d,d=f,f=o),a=[],o=d+f,n=o;n--;)a.push(0);for(n=f;--n>=0;){for(t=0,r=d+n;r>n;)u=a[r]+C[n]*g[r-n-1]+t,a[r--]=u%te|0,t=u/te|0;a[r]=(a[r]+t)%te|0}for(;!a[--o];)a.pop();return t?++e:a.shift(),i.d=a,i.e=ii(a,e),R?F(i,_.precision,_.rounding):i};A.toBinary=function(i,t){return Ri(this,2,i,t)};A.toDecimalPlaces=A.toDP=function(i,t){var e=this,n=e.constructor;return e=new n(e),i===void 0?e:(zt(i,0,be),t===void 0?t=n.rounding:zt(t,0,8),F(e,i+e.e+1,t))};A.toExponential=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=se(n,!0):(zt(i,0,be),t===void 0?t=r.rounding:zt(t,0,8),n=F(new r(n),i+1,t),e=se(n,!0,i+1)),n.isNeg()&&!n.isZero()?"-"+e:e};A.toFixed=function(i,t){var e,n,r=this,a=r.constructor;return i===void 0?e=se(r):(zt(i,0,be),t===void 0?t=a.rounding:zt(t,0,8),n=F(new a(r),i+r.e+1,t),e=se(n,!1,i+n.e+1)),r.isNeg()&&!r.isZero()?"-"+e:e};A.toFraction=function(i){var t,e,n,r,a,o,u,d,f,m,_,g,C=this,k=C.d,P=C.constructor;if(!k)return new P(C);if(f=e=new P(1),n=d=new P(0),t=new P(n),a=t.e=Hn(k)-C.e-1,o=a%j,t.d[0]=Nt(10,o<0?j+o:o),i==null)i=a>0?t:f;else{if(u=new P(i),!u.isInt()||u.lt(f))throw Error(ge+u);i=u.gt(t)?a>0?t:f:u}for(R=!1,u=new P(Ut(k)),m=P.precision,P.precision=a=k.length*j*2;_=J(u,t,0,1,1),r=e.plus(_.times(n)),r.cmp(i)!=1;)e=n,n=r,r=f,f=d.plus(_.times(r)),d=r,r=t,t=u.minus(_.times(r)),u=r;return r=J(i.minus(e),n,0,1,1),d=d.plus(r.times(f)),e=e.plus(r.times(n)),d.s=f.s=C.s,g=J(f,n,a,1).minus(C).abs().cmp(J(d,e,a,1).minus(C).abs())<1?[f,n]:[d,e],P.precision=m,R=!0,g};A.toHexadecimal=A.toHex=function(i,t){return Ri(this,16,i,t)};A.toNearest=function(i,t){var e=this,n=e.constructor;if(e=new n(e),i==null){if(!e.d)return e;i=new n(1),t=n.rounding}else{if(i=new n(i),t===void 0?t=n.rounding:zt(t,0,8),!e.d)return i.s?e:i;if(!i.d)return i.s&&(i.s=e.s),i}return i.d[0]?(R=!1,e=J(e,i,0,t,1).times(i),R=!0,F(e)):(i.s=e.s,e=i),e};A.toNumber=function(){return+this};A.toOctal=function(i,t){return Ri(this,8,i,t)};A.toPower=A.pow=function(i){var t,e,n,r,a,o,u=this,d=u.constructor,f=+(i=new d(i));if(!u.d||!i.d||!u.d[0]||!i.d[0])return new d(Nt(+u,f));if(u=new d(u),u.eq(1))return u;if(n=d.precision,a=d.rounding,i.eq(1))return F(u,n,a);if(t=Wt(i.e/j),t>=i.d.length-1&&(e=f<0?-f:f)<=Kr)return r=Gn(d,u,e,n),i.s<0?new d(1).div(r):F(r,n,a);if(o=u.s,o<0){if(t<i.d.length-1)return new d(NaN);if(!(i.d[t]&1)&&(o=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=o,u}return e=Nt(+u,f),t=e==0||!isFinite(e)?Wt(f*(Math.log("0."+Ut(u.d))/Math.LN10+u.e+1)):new d(e+"").e,t>d.maxE+1||t<d.minE-1?new d(t>0?o/0:0):(R=!1,d.rounding=u.s=1,e=Math.min(12,(t+"").length),r=qi(i.times(_e(u,n+e)),n),r.d&&(r=F(r,n+5,1),Fe(r.d,n,a)&&(t=n+10,r=F(qi(i.times(_e(u,t+e)),t),t+5,1),+Ut(r.d).slice(n+1,n+15)+1==1e14&&(r=F(r,n+1,0)))),r.s=o,R=!0,d.rounding=a,F(r,n,a))};A.toPrecision=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=se(n,n.e<=r.toExpNeg||n.e>=r.toExpPos):(zt(i,1,be),t===void 0?t=r.rounding:zt(t,0,8),n=F(new r(n),i,t),e=se(n,i<=n.e||n.e<=r.toExpNeg,i)),n.isNeg()&&!n.isZero()?"-"+e:e};A.toSignificantDigits=A.toSD=function(i,t){var e=this,n=e.constructor;return i===void 0?(i=n.precision,t=n.rounding):(zt(i,1,be),t===void 0?t=n.rounding:zt(t,0,8)),F(new n(e),i,t)};A.toString=function(){var i=this,t=i.constructor,e=se(i,i.e<=t.toExpNeg||i.e>=t.toExpPos);return i.isNeg()&&!i.isZero()?"-"+e:e};A.truncated=A.trunc=function(){return F(new this.constructor(this),this.e+1,1)};A.valueOf=A.toJSON=function(){var i=this,t=i.constructor,e=se(i,i.e<=t.toExpNeg||i.e>=t.toExpPos);return i.isNeg()?"-"+e:e};function Ut(i){var t,e,n,r=i.length-1,a="",o=i[0];if(r>0){for(a+=o,t=1;t<r;t++)n=i[t]+"",e=j-n.length,e&&(a+=pe(e)),a+=n;o=i[t],n=o+"",e=j-n.length,e&&(a+=pe(e))}else if(o===0)return"0";for(;o%10===0;)o/=10;return a+o}function zt(i,t,e){if(i!==~~i||i<t||i>e)throw Error(ge+i)}function Fe(i,t,e,n){var r,a,o,u;for(a=i[0];a>=10;a/=10)--t;return--t<0?(t+=j,r=0):(r=Math.ceil((t+1)/j),t%=j),a=Nt(10,j-t),u=i[r]%a|0,n==null?t<3?(t==0?u=u/100|0:t==1&&(u=u/10|0),o=e<4&&u==99999||e>3&&u==49999||u==5e4||u==0):o=(e<4&&u+1==a||e>3&&u+1==a/2)&&(i[r+1]/a/100|0)==Nt(10,t-2)-1||(u==a/2||u==0)&&(i[r+1]/a/100|0)==0:t<4?(t==0?u=u/1e3|0:t==1?u=u/100|0:t==2&&(u=u/10|0),o=(n||e<4)&&u==9999||!n&&e>3&&u==4999):o=((n||e<4)&&u+1==a||!n&&e>3&&u+1==a/2)&&(i[r+1]/a/1e3|0)==Nt(10,t-3)-1,o}function Ge(i,t,e){for(var n,r=[0],a,o=0,u=i.length;o<u;){for(a=r.length;a--;)r[a]*=t;for(r[0]+=Ii.indexOf(i.charAt(o++)),n=0;n<r.length;n++)r[n]>e-1&&(r[n+1]===void 0&&(r[n+1]=0),r[n+1]+=r[n]/e|0,r[n]%=e)}return r.reverse()}function Zr(i,t){var e,n,r;if(t.isZero())return t;n=t.d.length,n<32?(e=Math.ceil(n/3),r=(1/ni(4,e)).toString()):(e=16,r="2.3283064365386962890625e-10"),i.precision+=e,t=xe(i,1,t.times(r),new i(1));for(var a=e;a--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return i.precision-=e,t}var J=function(){function i(n,r,a){var o,u=0,d=n.length;for(n=n.slice();d--;)o=n[d]*r+u,n[d]=o%a|0,u=o/a|0;return u&&n.unshift(u),n}function t(n,r,a,o){var u,d;if(a!=o)d=a>o?1:-1;else for(u=d=0;u<a;u++)if(n[u]!=r[u]){d=n[u]>r[u]?1:-1;break}return d}function e(n,r,a,o){for(var u=0;a--;)n[a]-=u,u=n[a]<r[a]?1:0,n[a]=u*o+n[a]-r[a];for(;!n[0]&&n.length>1;)n.shift()}return function(n,r,a,o,u,d){var f,m,_,g,C,k,P,D,x,E,O,T,H,N,G,$,z,W,et,qt,X=n.constructor,Q=n.s==r.s?1:-1,s=n.d,l=r.d;if(!s||!s[0]||!l||!l[0])return new X(!n.s||!r.s||(s?l&&s[0]==l[0]:!l)?NaN:s&&s[0]==0||!l?Q*0:Q/0);for(d?(C=1,m=n.e-r.e):(d=te,C=j,m=Wt(n.e/C)-Wt(r.e/C)),et=l.length,z=s.length,x=new X(Q),E=x.d=[],_=0;l[_]==(s[_]||0);_++);if(l[_]>(s[_]||0)&&m--,a==null?(N=a=X.precision,o=X.rounding):u?N=a+(n.e-r.e)+1:N=a,N<0)E.push(1),k=!0;else{if(N=N/C+2|0,_=0,et==1){for(g=0,l=l[0],N++;(_<z||g)&&N--;_++)G=g*d+(s[_]||0),E[_]=G/l|0,g=G%l|0;k=g||_<z}else{for(g=d/(l[0]+1)|0,g>1&&(l=i(l,g,d),s=i(s,g,d),et=l.length,z=s.length),$=et,O=s.slice(0,et),T=O.length;T<et;)O[T++]=0;qt=l.slice(),qt.unshift(0),W=l[0],l[1]>=d/2&&++W;do g=0,f=t(l,O,et,T),f<0?(H=O[0],et!=T&&(H=H*d+(O[1]||0)),g=H/W|0,g>1?(g>=d&&(g=d-1),P=i(l,g,d),D=P.length,T=O.length,f=t(P,O,D,T),f==1&&(g--,e(P,et<D?qt:l,D,d))):(g==0&&(f=g=1),P=l.slice()),D=P.length,D<T&&P.unshift(0),e(O,P,T,d),f==-1&&(T=O.length,f=t(l,O,et,T),f<1&&(g++,e(O,et<T?qt:l,T,d))),T=O.length):f===0&&(g++,O=[0]),E[_++]=g,f&&O[0]?O[T++]=s[$]||0:(O=[s[$]],T=1);while(($++<z||O[0]!==void 0)&&N--);k=O[0]!==void 0}E[0]||E.shift()}if(C==1)x.e=m,Kn=k;else{for(_=1,g=E[0];g>=10;g/=10)_++;x.e=_+m*C-1,F(x,u?a+x.e+1:a,o,k)}return x}}();function F(i,t,e,n){var r,a,o,u,d,f,m,_,g,C=i.constructor;t:if(t!=null){if(_=i.d,!_)return i;for(r=1,u=_[0];u>=10;u/=10)r++;if(a=t-r,a<0)a+=j,o=t,m=_[g=0],d=m/Nt(10,r-o-1)%10|0;else if(g=Math.ceil((a+1)/j),u=_.length,g>=u)if(n){for(;u++<=g;)_.push(0);m=d=0,r=1,a%=j,o=a-j+1}else break t;else{for(m=u=_[g],r=1;u>=10;u/=10)r++;a%=j,o=a-j+r,d=o<0?0:m/Nt(10,r-o-1)%10|0}if(n=n||t<0||_[g+1]!==void 0||(o<0?m:m%Nt(10,r-o-1)),f=e<4?(d||n)&&(e==0||e==(i.s<0?3:2)):d>5||d==5&&(e==4||n||e==6&&(a>0?o>0?m/Nt(10,r-o):0:_[g-1])%10&1||e==(i.s<0?8:7)),t<1||!_[0])return _.length=0,f?(t-=i.e+1,_[0]=Nt(10,(j-t%j)%j),i.e=-t||0):_[0]=i.e=0,i;if(a==0?(_.length=g,u=1,g--):(_.length=g+1,u=Nt(10,j-a),_[g]=o>0?(m/Nt(10,r-o)%Nt(10,o)|0)*u:0),f)for(;;)if(g==0){for(a=1,o=_[0];o>=10;o/=10)a++;for(o=_[0]+=u,u=1;o>=10;o/=10)u++;a!=u&&(i.e++,_[0]==te&&(_[0]=1));break}else{if(_[g]+=u,_[g]!=te)break;_[g--]=0,u=1}for(a=_.length;_[--a]===0;)_.pop()}return R&&(i.e>C.maxE?(i.d=null,i.e=NaN):i.e<C.minE&&(i.e=0,i.d=[0])),i}function se(i,t,e){if(!i.isFinite())return Jn(i);var n,r=i.e,a=Ut(i.d),o=a.length;return t?(e&&(n=e-o)>0?a=a.charAt(0)+"."+a.slice(1)+pe(n):o>1&&(a=a.charAt(0)+"."+a.slice(1)),a=a+(i.e<0?"e":"e+")+i.e):r<0?(a="0."+pe(-r-1)+a,e&&(n=e-o)>0&&(a+=pe(n))):r>=o?(a+=pe(r+1-o),e&&(n=e-r-1)>0&&(a=a+"."+pe(n))):((n=r+1)<o&&(a=a.slice(0,n)+"."+a.slice(n)),e&&(n=e-o)>0&&(r+1===o&&(a+="."),a+=pe(n))),a}function ii(i,t){var e=i[0];for(t*=j;e>=10;e/=10)t++;return t}function ti(i,t,e){if(t>Wr)throw R=!0,e&&(i.precision=e),Error(Wn);return F(new i(Je),t,1,!0)}function oe(i,t,e){if(t>ji)throw Error(Wn);return F(new i(Ye),t,e,!0)}function Hn(i){var t=i.length-1,e=t*j+1;if(t=i[t],t){for(;t%10==0;t/=10)e--;for(t=i[0];t>=10;t/=10)e++}return e}function pe(i){for(var t="";i--;)t+="0";return t}function Gn(i,t,e,n){var r,a=new i(1),o=Math.ceil(n/j+4);for(R=!1;;){if(e%2&&(a=a.times(t),Vn(a.d,o)&&(r=!0)),e=Wt(e/2),e===0){e=a.d.length-1,r&&a.d[e]===0&&++a.d[e];break}t=t.times(t),Vn(t.d,o)}return R=!0,a}function Bn(i){return i.d[i.d.length-1]&1}function Qn(i,t,e){for(var n,r,a=new i(t[0]),o=0;++o<t.length;){if(r=new i(t[o]),!r.s){a=r;break}n=a.cmp(r),(n===e||n===0&&a.s===e)&&(a=r)}return a}function qi(i,t){var e,n,r,a,o,u,d,f=0,m=0,_=0,g=i.constructor,C=g.rounding,k=g.precision;if(!i.d||!i.d[0]||i.e>17)return new g(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(t==null?(R=!1,d=k):d=t,u=new g(.03125);i.e>-2;)i=i.times(u),_+=5;for(n=Math.log(Nt(2,_))/Math.LN10*2+5|0,d+=n,e=a=o=new g(1),g.precision=d;;){if(a=F(a.times(i),d,1),e=e.times(++m),u=o.plus(J(a,e,d,1)),Ut(u.d).slice(0,d)===Ut(o.d).slice(0,d)){for(r=_;r--;)o=F(o.times(o),d,1);if(t==null)if(f<3&&Fe(o.d,d-n,C,f))g.precision=d+=10,e=a=u=new g(1),m=0,f++;else return F(o,g.precision=k,C,R=!0);else return g.precision=k,o}o=u}}function _e(i,t){var e,n,r,a,o,u,d,f,m,_,g,C=1,k=10,P=i,D=P.d,x=P.constructor,E=x.rounding,O=x.precision;if(P.s<0||!D||!D[0]||!P.e&&D[0]==1&&D.length==1)return new x(D&&!D[0]?-1/0:P.s!=1?NaN:D?0:P);if(t==null?(R=!1,m=O):m=t,x.precision=m+=k,e=Ut(D),n=e.charAt(0),Math.abs(a=P.e)<15e14){for(;n<7&&n!=1||n==1&&e.charAt(1)>3;)P=P.times(i),e=Ut(P.d),n=e.charAt(0),C++;a=P.e,n>1?(P=new x("0."+e),a++):P=new x(n+"."+e.slice(1))}else return f=ti(x,m+2,O).times(a+""),P=_e(new x(n+"."+e.slice(1)),m-k).plus(f),x.precision=O,t==null?F(P,O,E,R=!0):P;for(_=P,d=o=P=J(P.minus(1),P.plus(1),m,1),g=F(P.times(P),m,1),r=3;;){if(o=F(o.times(g),m,1),f=d.plus(J(o,new x(r),m,1)),Ut(f.d).slice(0,m)===Ut(d.d).slice(0,m))if(d=d.times(2),a!==0&&(d=d.plus(ti(x,m+2,O).times(a+""))),d=J(d,new x(C),m,1),t==null)if(Fe(d.d,m-k,E,u))x.precision=m+=k,f=o=P=J(_.minus(1),_.plus(1),m,1),g=F(P.times(P),m,1),r=u=1;else return F(d,x.precision=O,E,R=!0);else return x.precision=O,d;d=f,r+=2}}function Jn(i){return String(i.s*i.s/0)}function Qe(i,t){var e,n,r;for((e=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(e<0&&(e=n),e+=+t.slice(n+1),t=t.substring(0,n)):e<0&&(e=t.length),n=0;t.charCodeAt(n)===48;n++);for(r=t.length;t.charCodeAt(r-1)===48;--r);if(t=t.slice(n,r),t){if(r-=n,i.e=e=e-n-1,i.d=[],n=(e+1)%j,e<0&&(n+=j),n<r){for(n&&i.d.push(+t.slice(0,n)),r-=j;n<r;)i.d.push(+t.slice(n,n+=j));t=t.slice(n),n=j-t.length}else n-=r;for(;n--;)t+="0";i.d.push(+t),R&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function zr(i,t){var e,n,r,a,o,u,d,f,m;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Xn.test(t))return Qe(i,t)}else if(t==="Infinity"||t==="NaN")return+t||(i.s=NaN),i.e=NaN,i.d=null,i;if(Ur.test(t))e=16,t=t.toLowerCase();else if(Nr.test(t))e=2;else if($r.test(t))e=8;else throw Error(ge+t);for(a=t.search(/p/i),a>0?(d=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf("."),o=a>=0,n=i.constructor,o&&(t=t.replace(".",""),u=t.length,a=u-a,r=Gn(n,new n(e),a,a*2)),f=Ge(t,e,te),m=f.length-1,a=m;f[a]===0;--a)f.pop();return a<0?new n(i.s*0):(i.e=ii(f,m),i.d=f,R=!1,o&&(i=J(i,r,u*4)),d&&(i=i.times(Math.abs(d)<54?Nt(2,d):je.pow(2,d))),R=!0,i)}function Xr(i,t){var e,n=t.d.length;if(n<3)return t.isZero()?t:xe(i,2,t,t);e=1.4*Math.sqrt(n),e=e>16?16:e|0,t=t.times(1/ni(5,e)),t=xe(i,2,t,t);for(var r,a=new i(5),o=new i(16),u=new i(20);e--;)r=t.times(t),t=t.times(a.plus(r.times(o.times(r).minus(u))));return t}function xe(i,t,e,n,r){var a,o,u,d,f=1,m=i.precision,_=Math.ceil(m/j);for(R=!1,d=e.times(e),u=new i(n);;){if(o=J(u.times(d),new i(t++*t++),m,1),u=r?n.plus(o):n.minus(o),n=J(o.times(d),new i(t++*t++),m,1),o=u.plus(n),o.d[_]!==void 0){for(a=_;o.d[a]===u.d[a]&&a--;);if(a==-1)break}a=u,u=n,n=o,o=a,f++}return R=!0,o.d.length=_+1,o}function ni(i,t){for(var e=i;--t;)e*=i;return e}function Yn(i,t){var e,n=t.s<0,r=oe(i,i.precision,1),a=r.times(.5);if(t=t.abs(),t.lte(a))return le=n?4:1,t;if(e=t.divToInt(r),e.isZero())le=n?3:2;else{if(t=t.minus(e.times(r)),t.lte(a))return le=Bn(e)?n?2:3:n?4:1,t;le=Bn(e)?n?1:4:n?3:2}return t.minus(r).abs()}function Ri(i,t,e,n){var r,a,o,u,d,f,m,_,g,C=i.constructor,k=e!==void 0;if(k?(zt(e,1,be),n===void 0?n=C.rounding:zt(n,0,8)):(e=C.precision,n=C.rounding),!i.isFinite())m=Jn(i);else{for(m=se(i),o=m.indexOf("."),k?(r=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):r=t,o>=0&&(m=m.replace(".",""),g=new C(1),g.e=m.length-o,g.d=Ge(se(g),10,r),g.e=g.d.length),_=Ge(m,10,r),a=d=_.length;_[--d]==0;)_.pop();if(!_[0])m=k?"0p+0":"0";else{if(o<0?a--:(i=new C(i),i.d=_,i.e=a,i=J(i,g,e,n,0,r),_=i.d,a=i.e,f=Kn),o=_[e],u=r/2,f=f||_[e+1]!==void 0,f=n<4?(o!==void 0||f)&&(n===0||n===(i.s<0?3:2)):o>u||o===u&&(n===4||f||n===6&&_[e-1]&1||n===(i.s<0?8:7)),_.length=e,f)for(;++_[--e]>r-1;)_[e]=0,e||(++a,_.unshift(1));for(d=_.length;!_[d-1];--d);for(o=0,m="";o<d;o++)m+=Ii.charAt(_[o]);if(k){if(d>1)if(t==16||t==8){for(o=t==16?4:3,--d;d%o;d++)m+="0";for(_=Ge(m,r,t),d=_.length;!_[d-1];--d);for(o=1,m="1.";o<d;o++)m+=Ii.charAt(_[o])}else m=m.charAt(0)+"."+m.slice(1);m=m+(a<0?"p":"p+")+a}else if(a<0){for(;++a;)m="0"+m;m="0."+m}else if(++a>d)for(a-=d;a--;)m+="0";else a<d&&(m=m.slice(0,a)+"."+m.slice(a))}m=(t==16?"0x":t==2?"0b":t==8?"0o":"")+m}return i.s<0?"-"+m:m}function Vn(i,t){if(i.length>t)return i.length=t,!0}function Hr(i){return new this(i).abs()}function Gr(i){return new this(i).acos()}function Qr(i){return new this(i).acosh()}function Jr(i,t){return new this(i).plus(t)}function Yr(i){return new this(i).asin()}function to(i){return new this(i).asinh()}function eo(i){return new this(i).atan()}function io(i){return new this(i).atanh()}function no(i,t){i=new this(i),t=new this(t);var e,n=this.precision,r=this.rounding,a=n+4;return!i.s||!t.s?e=new this(NaN):!i.d&&!t.d?(e=oe(this,a,1).times(t.s>0?.25:.75),e.s=i.s):!t.d||i.isZero()?(e=t.s<0?oe(this,n,r):new this(0),e.s=i.s):!i.d||t.isZero()?(e=oe(this,a,1).times(.5),e.s=i.s):t.s<0?(this.precision=a,this.rounding=1,e=this.atan(J(i,t,a,1)),t=oe(this,a,1),this.precision=n,this.rounding=r,e=i.s<0?e.minus(t):e.plus(t)):e=this.atan(J(i,t,a,1)),e}function ro(i){return new this(i).cbrt()}function oo(i){return F(i=new this(i),i.e+1,2)}function so(i,t,e){return new this(i).clamp(t,e)}function ao(i){if(!i||typeof i!="object")throw Error(ei+"Object expected");var t,e,n,r=i.defaults===!0,a=["precision",1,be,"rounding",0,8,"toExpNeg",-Oe,0,"toExpPos",0,Oe,"maxE",0,Oe,"minE",-Oe,0,"modulo",0,9];for(t=0;t<a.length;t+=3)if(e=a[t],r&&(this[e]=Li[e]),(n=i[e])!==void 0)if(Wt(n)===n&&n>=a[t+1]&&n<=a[t+2])this[e]=n;else throw Error(ge+e+": "+n);if(e="crypto",r&&(this[e]=Li[e]),(n=i[e])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[e]=!0;else throw Error(Zn);else this[e]=!1;else throw Error(ge+e+": "+n);return this}function co(i){return new this(i).cos()}function lo(i){return new this(i).cosh()}function tr(i){var t,e,n;function r(a){var o,u,d,f=this;if(!(f instanceof r))return new r(a);if(f.constructor=r,Fn(a)){f.s=a.s,R?!a.d||a.e>r.maxE?(f.e=NaN,f.d=null):a.e<r.minE?(f.e=0,f.d=[0]):(f.e=a.e,f.d=a.d.slice()):(f.e=a.e,f.d=a.d?a.d.slice():a.d);return}if(d=typeof a,d==="number"){if(a===0){f.s=1/a<0?-1:1,f.e=0,f.d=[0];return}if(a<0?(a=-a,f.s=-1):f.s=1,a===~~a&&a<1e7){for(o=0,u=a;u>=10;u/=10)o++;R?o>r.maxE?(f.e=NaN,f.d=null):o<r.minE?(f.e=0,f.d=[0]):(f.e=o,f.d=[a]):(f.e=o,f.d=[a]);return}if(a*0!==0){a||(f.s=NaN),f.e=NaN,f.d=null;return}return Qe(f,a.toString())}if(d==="string")return(u=a.charCodeAt(0))===45?(a=a.slice(1),f.s=-1):(u===43&&(a=a.slice(1)),f.s=1),Xn.test(a)?Qe(f,a):zr(f,a);if(d==="bigint")return a<0?(a=-a,f.s=-1):f.s=1,Qe(f,a.toString());throw Error(ge+a)}if(r.prototype=A,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=ao,r.clone=tr,r.isDecimal=Fn,r.abs=Hr,r.acos=Gr,r.acosh=Qr,r.add=Jr,r.asin=Yr,r.asinh=to,r.atan=eo,r.atanh=io,r.atan2=no,r.cbrt=ro,r.ceil=oo,r.clamp=so,r.cos=co,r.cosh=lo,r.div=uo,r.exp=fo,r.floor=ho,r.hypot=mo,r.ln=po,r.log=_o,r.log10=bo,r.log2=go,r.max=wo,r.min=vo,r.mod=yo,r.mul=Mo,r.pow=Co,r.random=ko,r.round=Po,r.sign=So,r.sin=Ao,r.sinh=Oo,r.sqrt=xo,r.sub=Do,r.sum=Eo,r.tan=To,r.tanh=Bo,r.trunc=Vo,i===void 0&&(i={}),i&&i.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<n.length;)i.hasOwnProperty(e=n[t++])||(i[e]=this[e]);return r.config(i),r}function uo(i,t){return new this(i).div(t)}function fo(i){return new this(i).exp()}function ho(i){return F(i=new this(i),i.e+1,3)}function mo(){var i,t,e=new this(0);for(R=!1,i=0;i<arguments.length;)if(t=new this(arguments[i++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return R=!0,new this(1/0);e=t}return R=!0,e.sqrt()}function Fn(i){return i instanceof je||i&&i.toStringTag===zn||!1}function po(i){return new this(i).ln()}function _o(i,t){return new this(i).log(t)}function go(i){return new this(i).log(2)}function bo(i){return new this(i).log(10)}function wo(){return Qn(this,arguments,-1)}function vo(){return Qn(this,arguments,1)}function yo(i,t){return new this(i).mod(t)}function Mo(i,t){return new this(i).mul(t)}function Co(i,t){return new this(i).pow(t)}function ko(i){var t,e,n,r,a=0,o=new this(1),u=[];if(i===void 0?i=this.precision:zt(i,1,be),n=Math.ceil(i/j),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));a<n;)r=t[a],r>=429e7?t[a]=crypto.getRandomValues(new Uint32Array(1))[0]:u[a++]=r%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(n*=4);a<n;)r=t[a]+(t[a+1]<<8)+(t[a+2]<<16)+((t[a+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(t,a):(u.push(r%1e7),a+=4);a=n/4}else throw Error(Zn);else for(;a<n;)u[a++]=Math.random()*1e7|0;for(n=u[--a],i%=j,n&&i&&(r=Nt(10,j-i),u[a]=(n/r|0)*r);u[a]===0;a--)u.pop();if(a<0)e=0,u=[0];else{for(e=-1;u[0]===0;e-=j)u.shift();for(n=1,r=u[0];r>=10;r/=10)n++;n<j&&(e-=j-n)}return o.e=e,o.d=u,o}function Po(i){return F(i=new this(i),i.e+1,this.rounding)}function So(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function Ao(i){return new this(i).sin()}function Oo(i){return new this(i).sinh()}function xo(i){return new this(i).sqrt()}function Do(i,t){return new this(i).sub(t)}function Eo(){var i=0,t=arguments,e=new this(t[i]);for(R=!1;e.s&&++i<t.length;)e=e.plus(t[i]);return R=!0,F(e,this.precision,this.rounding)}function To(i){return new this(i).tan()}function Bo(i){return new this(i).tanh()}function Vo(i){return F(i=new this(i),i.e+1,1)}A[Symbol.for("nodejs.util.inspect.custom")]=A.toString;A[Symbol.toStringTag]="Decimal";var je=A.constructor=tr(Li);Je=new je(Je);Ye=new je(Ye);var Jt=je;function S(i){return Jt.isDecimal(i)?i:new Jt(i===void 0?0:i)}function er(i){return S(10).pow(S(i).abs())}function Qt(i,t,e=Jt.ROUND_DOWN){let n=er(S(t));return S(i).mul(n).toFixed(0,e).toString()}function we(i,t=32){return Number(BigInt.asIntN(t,BigInt(i)))}function ue(i,t){let e=er(S(t));return S(i).div(e).toString()}var ir="0x2::sui::SUI",Fo="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";var Ht=class jt{static totalBalance(t,e){let n=BigInt(0);return t.forEach(r=>{e===r.coin_type&&(n+=BigInt(r.balance))}),n}static getCoinAssets(t,e){let n=[];return e.forEach(r=>{Ln(r.coin_type)===Ln(t)&&n.push(r)}),n}static isSuiCoin(t){return ee(t).full_address===ir}static selectCoinObjectIdGreaterThanOrEqual(t,e,n=[]){let r=jt.selectCoinAssetGreaterThanOrEqual(t,e,n),a=r.selected_coins.map(d=>d.coin_object_id),o=r.remain_coins,u=r.selected_coins.map(d=>d.balance.toString());return{object_array:a,remain_coins:o,amount_array:u}}static selectCoinAssetGreaterThanOrEqual(t,e,n=[]){let r=jt.sortByBalance(t.filter(f=>!n.includes(f.coin_object_id))),a=jt.calculateTotalBalance(r);if(a<e)return{selected_coins:[],remain_coins:r};if(a===e)return{selected_coins:r,remain_coins:[]};let o=BigInt(0),u=[],d=[...r];for(;o<a;){let f=e-o,m=d.findIndex(g=>g.balance>=f);if(m!==-1){u.push(d[m]),d.splice(m,1);break}let _=d.pop();_.balance>0&&(u.push(_),o+=_.balance)}return{selected_coins:jt.sortByBalance(u),remain_coins:jt.sortByBalance(d)}}static sortByBalance(t){return t.sort((e,n)=>e.balance<n.balance?-1:e.balance>n.balance?1:0)}static sortByBalanceDes(t){return t.sort((e,n)=>e.balance>n.balance?-1:e.balance<n.balance?0:1)}static calculateTotalBalance(t){return t.reduce((e,n)=>e+n.balance,BigInt(0))}static buildCoinForAmount(t,e,n,r,a=!0,o=!0){let u=jt.getCoinAssets(r,e);if(n===BigInt(0))return this.buildZeroValueCoin(e,t,r,a);let d=jt.calculateTotalBalance(u);if(d<n)throw new Error(`The amount(${d}) is Insufficient balance for ${r} , expect ${n} `);return this.buildCoin(t,e,u,n,r,a,o)}static buildCoinWithBalance(t,e,n){return t===BigInt(0)&&jt.isSuiCoin(e)?n.add((0,Fi.coinWithBalance)({balance:t,useGasCoin:!1})):n.add((0,Fi.coinWithBalance)({balance:t,type:e}))}static buildVectorCoin(t,e,n,r,a,o=!0){if(jt.isSuiCoin(a)){let g=t.splitCoins(t.gas,[t.pure.u64(r)]);return{selected_coins:[],target_coin:g,remain_coins:e,target_coin_amount:r.toString(),is_mint_zero_coin:!1,original_spited_coin:t.gas}}let{original_spited_coin:u,target_coin:d,target_coin_amount:f,remain_coins:m,selected_coins:_}=this.buildSpitTargeCoin(t,r,n,o);return o?{target_coin:t.makeMoveVec({elements:[d]}),selected_coins:_,remain_coins:m,target_coin_amount:f,is_mint_zero_coin:!1,original_spited_coin:u}:{selected_coins:_,target_coin:t.makeMoveVec({elements:_.map(g=>t.object(g))}),remain_coins:m,target_coin_amount:f,is_mint_zero_coin:!1}}static buildOneCoin(t,e,n,r,a=!0){if(jt.isSuiCoin(r)){if(n===0n&&e.length>1){let d=jt.selectCoinObjectIdGreaterThanOrEqual(e,n);return{selected_coins:d.object_array,target_coin:t.object(d.object_array[0]),remain_coins:d.remain_coins,target_coin_amount:d.amount_array[0],is_mint_zero_coin:!1}}let o=jt.selectCoinObjectIdGreaterThanOrEqual(e,n),u=t.splitCoins(t.gas,[t.pure.u64(n)]);return{selected_coins:[],target_coin:u,remain_coins:o.remain_coins,target_coin_amount:n.toString(),is_mint_zero_coin:!1,original_spited_coin:t.gas}}return this.buildSpitTargeCoin(t,n,e,a)}static buildSpitTargeCoin(t,e,n,r){let a=jt.selectCoinObjectIdGreaterThanOrEqual(n,e),o=a.amount_array.reduce((k,P)=>Number(k)+Number(P),0).toString(),u=a.object_array,[d,...f]=u,m=t.object(d),_=m,g=a.amount_array.reduce((k,P)=>Number(k)+Number(P),0).toString(),C;return f.length>0&&t.mergeCoins(m,f.map(k=>t.object(k))),r&&Number(o)>Number(e)&&(_=t.splitCoins(m,[t.pure.u64(e)]),C=m),{original_spited_coin:C,target_coin:_,target_coin_amount:g,remain_coins:a.remain_coins,selected_coins:a.object_array,is_mint_zero_coin:!1}}static buildCoin(t,e,n,r,a,o=!0,u=!0){return o?this.buildVectorCoin(t,e,n,r,a,u):this.buildOneCoin(t,n,r,a,u)}static buildZeroValueCoin(t,e,n,r=!0){let a=this.callMintZeroValueCoin(e,n),o;return r?o=e.makeMoveVec({elements:[a]}):o=a,{target_coin:o,remain_coins:t,selected_coins:[],is_mint_zero_coin:!0,target_coin_amount:"0"}}static buildCoinForAmountInterval(t,e,n,r,a=!0,o=!0){let u=jt.getCoinAssets(r,e);if(n.amount_first===BigInt(0))return u.length>0?this.buildCoin(t,[...e],[...u],n.amount_first,r,a,o):this.buildZeroValueCoin(e,t,r,a);let d=jt.calculateTotalBalance(u);if(d>=n.amount_first)return this.buildCoin(t,[...e],[...u],n.amount_first,r,a,o);if(d<n.amount_second)throw new Error(`The amount(${d}) is Insufficient balance for ${r} , expect ${n.amount_second} `);return this.buildCoin(t,[...e],[...u],n.amount_second,r,a,o)}static{this.callMintZeroValueCoin=(t,e)=>t.moveCall({target:"0x2::coin::zero",typeArguments:[e]})}static fromBalance(t,e,n){return n.moveCall({target:"0x2::coin::from_balance",typeArguments:[e],arguments:[t]})}static intoBalance(t,e,n){return n.moveCall({target:"0x2::coin::into_balance",typeArguments:[e],arguments:[typeof t=="string"?n.object(t):t]})}static mintBalanceZero(t,e){return e.moveCall({target:"0x2::balance::zero",typeArguments:[t],arguments:[]})}static destroyBalanceZero(t,e,n){return n.moveCall({target:"0x2::balance::destroy_zero",typeArguments:[e],arguments:[t]})}static getCoinAmountObjId(t,e){let n=t.amount_coin_array.find(r=>!r.used&&S(r.amount).eq(e)?(r.used=!0,!0):!1);return n?n.coin_object_id:Gt("CoinNotFound",`Coin not found for ${e} ${t.coin_type}`)}static buildMultiCoinInput(t,e,n,r){let a=jt.getCoinAssets(n,e);if(jt.isSuiCoin(n)){let _=t.splitCoins(t.gas,r.map(g=>t.pure.u64(g)));return{amount_coin_array:r.map((g,C)=>({coin_object_id:_[C],amount:g.toString(),used:!1})),coin_type:n,remain_coins:a}}let o=r.reduce((_,g)=>_+g,BigInt(0)),u=jt.selectCoinObjectIdGreaterThanOrEqual(a,o);if(u.object_array.length===0)return Gt("InsufficientBalance",`No enough coins for ${n} expect ${o} actual ${jt.calculateTotalBalance(a)}`);let[d,...f]=u.object_array;f.length>0&&t.mergeCoins(d,[...f]);let m=t.splitCoins(d,r.map(_=>t.pure.u64(_)));return{amount_coin_array:r.map((_,g)=>({coin_object_id:m[g],amount:_.toString(),used:!1})),remain_coins:u.remain_coins,coin_type:n}}};function Io(i){return i.startsWith("0x")?`${i.slice(2)}`:i}function In(i,...t){let e=Array.isArray(t[t.length-1])?t.pop():[],n=[i,...t].filter(Boolean).join("::");return e&&e.length&&(n+=`<${e.join(", ")}>`),n}function ee(i){try{let t=i.replace(/\s/g,""),e=t.match(/(<.+>)$/)?.[0]?.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(e){t=t.slice(0,t.indexOf("<"));let a={...ee(t),type_arguments:e.map(o=>ee(o).source_address)};return a.type_arguments=a.type_arguments.map(o=>Ht.isSuiCoin(o)?o:ee(o).source_address),a.source_address=In(a.full_address,a.type_arguments),a}let n=t.split("::"),r={full_address:t,address:t===ir||t===Fo?"0x2":(0,Me.normalizeSuiObjectId)(n[0]),module:n[1],name:n[2],type_arguments:[],source_address:""};return r.full_address=`${r.address}::${r.module}::${r.name}`,r.source_address=In(r.full_address,r.type_arguments),r}catch{return{full_address:i,address:"",module:"",name:"",type_arguments:[],source_address:i}}}function Ln(i){return ee(i).source_address}var q=(i,t=!0)=>{let e=i.split("::"),n=e.shift(),r=(0,Me.normalizeSuiObjectId)(n);return t&&(r=Io(r)),`${r}::${e.join("::")}`};var No=Ie(Le()),jn=443636,qn=-443636,Uo="79226673515401279992447579055";var $o="4295048016",ms=new No.default(1e6),Ko=(i=>(i[i.BelowRange=0]="BelowRange",i[i.InRange=1]="InRange",i[i.AboveRange=2]="AboveRange",i))(Ko||{}),Zt="0x0000000000000000000000000000000000000000000000000000000000000006";var ps=(0,Ni.getFullnodeUrl)("mainnet"),_s=(0,Ni.getFullnodeUrl)("testnet");var Rt=Ie(Le()),ce=new Rt.default(0),Ve=new Rt.default(1),ri=new Rt.default(2),Wo=ri.pow(new Rt.default(128)),Rn=ri.pow(new Rt.default(64)).sub(Ve),Zo=ri.pow(new Rt.default(128)).sub(Ve),Yt=class{static toX64BN(i){return i.mul(new Rt.default(2).pow(new Rt.default(64)))}static toX64Decimal(i){return i.mul(Jt.pow(2,64))}static toX64(i){return new Rt.default(i.mul(Jt.pow(2,64)).floor().toFixed())}static fromX64(i){return new Jt(i.toString()).mul(Jt.pow(2,-64))}static fromX64Decimal(i){return i.mul(Jt.pow(2,-64))}static fromX64BN(i){return i.div(new Rt.default(2).pow(new Rt.default(64)))}static shiftRightRoundUp(i){let t=i.shrn(64);return i.mod(Rn).gt(ce)&&(t=t.add(Ve)),t}static divRoundUp(i,t){return i.mod(t).eq(ce)?i.div(t):i.div(t).add(new Rt.default(1))}static subUnderflowU128(i,t){return i.lt(t)?i.sub(t).add(Zo):i.sub(t)}static checkUnsignedSub(i,t){let e=i.sub(t);if(e.isNeg())throw new Error("Unsigned integer sub overflow");return e}static checkMul(i,t,e){let n=i.mul(t);return this.isOverflow(n,e)&&Gt("MultiplicationOverflow","Multiplication overflow"),n}static checkMulDivFloor(i,t,e,n){e.eq(ce)&&Gt("DivisionByZero","Divide by zero");let r=i.mul(t).div(e);return this.isOverflow(r,n)&&Gt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulDivCeil(i,t,e,n){if(e.eq(ce))throw new Error("Divide by zero");let r=i.mul(t).add(e.sub(Ve)).div(e);if(this.isOverflow(r,n))throw new Error("Multiplication div overflow");return r}static checkMulDivRound(i,t,e,n){e.eq(ce)&&Gt("DivisionByZero","Divide by zero");let r=i.mul(t.add(e.shrn(1))).div(e);return this.isOverflow(r,n)&&Gt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulShiftRight(i,t,e,n){let r=i.mul(t).div(new Rt.default(2).pow(new Rt.default(e)));return this.isOverflow(r,n)&&Gt("MultiplicationOverflow","Multiplication shift right overflow"),r}static checkMulShiftRight64RoundUpIf(i,t,e,n){let r=i.mul(t),a=n&&r.and(Rn).gt(ce)?r.shrn(64).add(Ve):r.shrn(64);return this.isOverflow(a,e)&&Gt("MultiplicationOverflow","Multiplication shift right overflow"),a}static checkMulShiftLeft(i,t,e,n){let r=i.mul(t).shln(e);return this.isOverflow(r,n)&&Gt("MultiplicationOverflow","Multiplication shift left overflow"),r}static checkDivRoundUpIf(i,t,e){return t.eq(ce)&&Gt("DivisionByZero","Divide by zero"),e?this.divRoundUp(i,t):i.div(t)}static isOverflow(i,t){return i.gte(ri.pow(new Rt.default(t)))}static sign(i){return i.testn(127)?1:0}static is_neg(i){return this.sign(i)===1}static abs_u128(i){return i.gt(ce)?i:this.u128Neg(i.subn(1))}static u128Neg(i){return i.uxor(new Rt.default("ffffffffffffffffffffffffffffffff",16))}static neg(i){return this.is_neg(i)?i.abs():this.negFrom(i)}static abs(i){return this.sign(i)===0?i:this.u128Neg(i.sub(new Rt.default(1)))}static negFrom(i){return i.eq(ce)?i:this.u128Neg(i).add(new Rt.default(1)).or(new Rt.default(1).shln(127))}static u128ToI128(i){return i.testn(127)?Wo.sub(i).neg():i}},Ui=class{static getMinIndex(i){return qn+Math.abs(qn)%i}static getMaxIndex(i){return jn-jn%i}};function nr(i){return i.data}function zo(i){return i.data!==void 0}function Xo(i){return i.content!==void 0}function rr(i){let t="data"in i?nr(i):i;if(!(!t||!Xo(t)||t.content.dataType!=="moveObject"))return t.content}function Ho(i){return rr(i)?.type}function $i(i){let t=zo(i)?i.data:i;return!t?.type&&"data"in i?t?.content?.dataType==="package"?"package":Ho(i):t?.type}function oi(i){return nr(i)?.previousTransaction}function ie(i){let t=rr(i)?.fields;if(t)return"fields"in t?t.fields:t}Jt.config({precision:64,rounding:Jt.ROUND_DOWN,toExpNeg:-64,toExpPos:64});var Kt=Jt,Xt=Ie(Le()),L=Ie(Le()),Go=14,Qo="59543866431248",Jo="184467440737095516",Yo="15793534762490258745";function ts(i,t,e){let n=i.toTwos(e).shln(t);return n.imaskn(e+1),n.fromTwos(e)}function K(i,t,e){let n=i.toTwos(e).shrn(t);return n.imaskn(e-t+1),n.fromTwos(e-t)}function es(i){let t;return i&1?t=new L.default("79232123823359799118286999567"):t=new L.default("79228162514264337593543950336"),i&2&&(t=K(t.mul(new L.default("79236085330515764027303304731")),96,256)),i&4&&(t=K(t.mul(new L.default("79244008939048815603706035061")),96,256)),i&8&&(t=K(t.mul(new L.default("79259858533276714757314932305")),96,256)),i&16&&(t=K(t.mul(new L.default("79291567232598584799939703904")),96,256)),i&32&&(t=K(t.mul(new L.default("79355022692464371645785046466")),96,256)),i&64&&(t=K(t.mul(new L.default("79482085999252804386437311141")),96,256)),i&128&&(t=K(t.mul(new L.default("79736823300114093921829183326")),96,256)),i&256&&(t=K(t.mul(new L.default("80248749790819932309965073892")),96,256)),i&512&&(t=K(t.mul(new L.default("81282483887344747381513967011")),96,256)),i&1024&&(t=K(t.mul(new L.default("83390072131320151908154831281")),96,256)),i&2048&&(t=K(t.mul(new L.default("87770609709833776024991924138")),96,256)),i&4096&&(t=K(t.mul(new L.default("97234110755111693312479820773")),96,256)),i&8192&&(t=K(t.mul(new L.default("119332217159966728226237229890")),96,256)),i&16384&&(t=K(t.mul(new L.default("179736315981702064433883588727")),96,256)),i&32768&&(t=K(t.mul(new L.default("407748233172238350107850275304")),96,256)),i&65536&&(t=K(t.mul(new L.default("2098478828474011932436660412517")),96,256)),i&131072&&(t=K(t.mul(new L.default("55581415166113811149459800483533")),96,256)),i&262144&&(t=K(t.mul(new L.default("38992368544603139932233054999993551")),96,256)),K(t,32,256)}function is(i){let t=Math.abs(i),e;return t&1?e=new L.default("18445821805675392311"):e=new L.default("18446744073709551616"),t&2&&(e=K(e.mul(new L.default("18444899583751176498")),64,256)),t&4&&(e=K(e.mul(new L.default("18443055278223354162")),64,256)),t&8&&(e=K(e.mul(new L.default("18439367220385604838")),64,256)),t&16&&(e=K(e.mul(new L.default("18431993317065449817")),64,256)),t&32&&(e=K(e.mul(new L.default("18417254355718160513")),64,256)),t&64&&(e=K(e.mul(new L.default("18387811781193591352")),64,256)),t&128&&(e=K(e.mul(new L.default("18329067761203520168")),64,256)),t&256&&(e=K(e.mul(new L.default("18212142134806087854")),64,256)),t&512&&(e=K(e.mul(new L.default("17980523815641551639")),64,256)),t&1024&&(e=K(e.mul(new L.default("17526086738831147013")),64,256)),t&2048&&(e=K(e.mul(new L.default("16651378430235024244")),64,256)),t&4096&&(e=K(e.mul(new L.default("15030750278693429944")),64,256)),t&8192&&(e=K(e.mul(new L.default("12247334978882834399")),64,256)),t&16384&&(e=K(e.mul(new L.default("8131365268884726200")),64,256)),t&32768&&(e=K(e.mul(new L.default("3584323654723342297")),64,256)),t&65536&&(e=K(e.mul(new L.default("696457651847595233")),64,256)),t&131072&&(e=K(e.mul(new L.default("26294789957452057")),64,256)),t&262144&&(e=K(e.mul(new L.default("37481735321082")),64,256)),e}var nt=class re{static priceToSqrtPriceX64(t,e,n){return Yt.toX64(t.mul(Kt.pow(10,n-e)).sqrt())}static sqrtPriceX64ToPrice(t,e,n){return Yt.fromX64(t).pow(2).mul(Kt.pow(10,e-n))}static tickIndexToSqrtPriceX64(t){return t>0?new L.default(es(t)):new L.default(is(t))}static sqrtPriceX64ToTickIndex(t){if(t.gt(new L.default(Uo))||t.lt(new L.default($o)))throw new Error("Provided sqrtPrice is not within the supported sqrtPrice range.");let e=t.bitLength()-1,n=new L.default(e-64),r=ts(n,32,128),a=new L.default("8000000000000000","hex"),o=0,u=new L.default(0),d=e>=64?t.shrn(e-63):t.shln(63-e);for(;a.gt(new L.default(0))&&o<Go;){d=d.mul(d);let C=d.shrn(127);d=d.shrn(63+C.toNumber()),u=u.add(a.mul(C)),a=a.shrn(1),o+=1}let f=u.shrn(32),m=r.add(f).mul(new L.default(Qo)),_=K(m.sub(new L.default(Jo)),64,128).toNumber(),g=K(m.add(new L.default(Yo)),64,128).toNumber();return _===g?_:re.tickIndexToSqrtPriceX64(g).lte(t)?g:_}static tickIndexToPrice(t,e,n){return re.sqrtPriceX64ToPrice(re.tickIndexToSqrtPriceX64(t),e,n)}static priceToTickIndex(t,e,n){return re.sqrtPriceX64ToTickIndex(re.priceToSqrtPriceX64(t,e,n))}static priceToInitializeTickIndex(t,e,n,r){return re.getInitializeTickIndex(re.priceToTickIndex(t,e,n),r)}static getInitializeTickIndex(t,e){return t-t%e}static getNextInitializeTickIndex(t,e){return re.getInitializeTickIndex(t,e)+e}static getPrevInitializeTickIndex(t,e){return re.getInitializeTickIndex(t,e)-e}};function Xe(i,t,e){let n=Xt.default.min(i,t),r=Xt.default.max(i,t),a=Yt.fromX64BN(e.mul(r).mul(n)),o=r.sub(n);return!a.isZero()&&!o.isZero()?a.div(o):new Xt.default(0)}function He(i,t,e){let n=Xt.default.min(i,t),r=Xt.default.max(i,t).sub(n);return r.isZero()?new Xt.default(0):e.shln(64).div(r)}var de=class Ae{static getCoinAmountFromLiquidity(t,e,n,r,a){let o=new Kt(t.toString()),u=new Kt(e.toString()),d=new Kt(n.toString()),f=new Kt(r.toString()),m,_;return e.lt(n)?(m=Yt.toX64Decimal(o).mul(f.sub(d)).div(d.mul(f)),_=new Kt(0)):e.lt(r)?(m=Yt.toX64Decimal(o).mul(f.sub(u)).div(u.mul(f)),_=Yt.fromX64Decimal(o.mul(u.sub(d)))):(m=new Kt(0),_=Yt.fromX64Decimal(o.mul(f.sub(d)))),a?{coin_amount_a:m.ceil().toString(),coin_amount_b:_.ceil().toString()}:{coin_amount_a:m.floor().toString(),coin_amount_b:_.floor().toString()}}static estLiquidityAndCoinAmountFromOneAmounts(t,e,n,r,a,o,u){let d=nt.sqrtPriceX64ToTickIndex(u),f=nt.tickIndexToSqrtPriceX64(t),m=nt.tickIndexToSqrtPriceX64(e),_;if(d<t){if(!r)throw new Error("lower tick cannot calculate liquidity by coinB");_=Xe(f,m,n)}else if(d>e){if(r)throw new Error("upper tick cannot calculate liquidity by coinA");_=He(m,f,n)}else r?_=Xe(u,m,n):_=He(u,f,n);let g=Ae.getCoinAmountFromLiquidity(_,u,f,m,a),C=a?S(g.coin_amount_a.toString()).mul(1+o).toString():S(g.coin_amount_a.toString()).mul(1-o).toString(),k=a?S(g.coin_amount_b.toString()).mul(1+o).toString():S(g.coin_amount_b.toString()).mul(1-o).toString();return{coin_amount_a:g.coin_amount_a,coin_amount_b:g.coin_amount_b,coin_amount_limit_a:a?Kt.ceil(C).toString():Kt.floor(C).toString(),coin_amount_limit_b:a?Kt.ceil(k).toString():Kt.floor(k).toString(),liquidity_amount:_.toString(),fix_amount_a:r}}static estimateLiquidityFromCoinAmounts(t,e,n,r){if(e>n)return Gt("InvalidTick","lower tick cannot be greater than lower tick",{[Vi.METHOD_NAME]:"estimateLiquidityFromCoinAmounts",[Vi.REQUEST_PARAMS]:{lower_tick:e,upper_tick:n,token_amount:r}});let a=nt.sqrtPriceX64ToTickIndex(t),o=nt.tickIndexToSqrtPriceX64(e),u=nt.tickIndexToSqrtPriceX64(n);if(a<e)return Xe(o,u,new Xt.default(r.coin_amount_a)).toString();if(a>=n)return He(u,o,new Xt.default(r.coin_amount_b)).toString();let d=Xe(t,u,new Xt.default(r.coin_amount_a)),f=He(t,o,new Xt.default(r.coin_amount_b));return Xt.default.min(d,f).toString()}static calculateDepositRatio(t,e,n){let r=new Xt.default(1e8),{coin_amount_b:a}=Ae.estLiquidityAndCoinAmountFromOneAmounts(t,e,r,!0,!0,0,n),o=nt.sqrtPriceX64ToPrice(n,0,0),u=S(r.toString()).mul(o),d=u.add(a.toString()),f=u.div(d),m=S(a.toString()).div(d);return{ratio_a:f,ratio_b:m}}static calculateAmountDepositRatio(t,e,n,r,a){let o=nt.sqrtPriceX64ToPrice(n,r,a),u=nt.sqrtPriceX64ToTickIndex(n);if(u<t)return{ratio_a:new Kt(1),ratio_b:new Kt(0),curr_price:o};if(u>e)return{ratio_a:new Kt(0),ratio_b:new Kt(1),curr_price:o};let d=new Xt.default(Qt(1,r)),{coin_amount_b:f}=Ae.estLiquidityAndCoinAmountFromOneAmounts(t,e,d,!0,!0,0,n),m=ue(d.toString(),r),_=ue(f.toString(),a),g=S(m).add(_),C=S(m).div(g),k=S(_).div(g);return{ratio_a:C,ratio_b:k,curr_price:o}}static getCoinAmountsFromRatio(t,e,n,r,a,o,u){let d=S(Qt(S(n).mul(t).div(r).toString(),o)).toFixed(0),f=S(Qt(S(n).mul(e).div(a).toString(),u)).toFixed(0);return{amount_a:d,amount_b:f}}static estCoinAmountsFromTotalAmount(t,e,n,r,a,o,u,d){let{ratio_a:f,ratio_b:m}=Ae.calculateDepositRatio(t,e,n);return Ae.getCoinAmountsFromRatio(f,m,r,a,o,u,d)}static getPositionStatus(t,e,n){return t<e?0:t<n?1:2}};function ve(i){if(i.config===void 0)throw new Error(`package: ${i.package_id} not config in sdk SdkOptions`);return i.config}var gs=Ie(Le());var mn=require("@cetusprotocol/sui-clmm-sdk");var Te=require("@mysten/sui/transactions"),he=ne(require("bn.js")),ur=require("@cetusprotocol/aggregator-sdk");var dr=require("@mysten/sui/utils"),fr=ne(require("decimal.js"));var $t=ne(require("bn.js")),ai=ne(require("decimal.js"));var Ki=ne(require("bn.js")),Wi=ne(require("decimal.js")),si=(i,t,e)=>{if(t==="min"){if(i===Ui.getMinIndex(e))return!0}else if(i===Ui.getMaxIndex(e))return!0;return!1};function ns(i){if(i.length!==8)throw new Error("Invalid u64 byte array length");let t=i.map(e=>e.toString(16).padStart(2,"0")).reverse().join("");return BigInt(`0x${t}`).toString()}function or(i,t,e,n,r){let a=new Ki.default(10).pow(new Ki.default(n)),{coin_amount_b:o}=de.estLiquidityAndCoinAmountFromOneAmounts(i,t,a,!0,!0,0,e),u=nt.sqrtPriceX64ToPrice(e,n,r),d=S(a.toString()).mul(u).div(new Wi.default(10).pow(n)).mul(new Wi.default(10).pow(r)),f=d.add(o.toString()),m=d.div(f),_=S(o.toString()).div(f);return{ratioA:m,ratioB:_}}function ae(i,t,e,n,r,a,o){let u=S(Qt(S(e).mul(i).div(n).toString(),a)).toFixed(0),d=S(Qt(S(e).mul(t).div(r).toString(),o)).toFixed(0);return{amountA:u,amountB:d}}function Zi(i,t,e,n,r,a,o,u){let{ratioA:d,ratioB:f}=or(i,t,e,o,u);return ae(d,f,n,r,a,o,u)}var Ce=10n;function ci(i){let{fields:t,type:e}=i,{liquidity_range:n,pool_id:r,wrapped_position:a}=t.clmm_vault.fields,o=a.fields,u={clmm_pool_id:r,liquidity_range:{lower_offset:n.fields.lower_offset,rebalance_threshold:n.fields.rebalance_threshold,upper_offset:n.fields.upper_offset},wrapped_position:{coin_type_a:q(o.coin_type_a.fields.name,!1),coin_type_b:q(o.coin_type_b.fields.name,!1),description:o.description,id:o.id.id,index:o.index,liquidity:o.liquidity,name:o.name,pool:o.pool,tick_lower_index:we(BigInt(o.tick_lower_index.fields.bits)),tick_upper_index:we(BigInt(o.tick_upper_index.fields.bits)),url:o.url}},{balances:d}=t.buffer_assets.fields,f=d.fields.contents.map(_=>{let{key:g,value:C}=_.fields;return{coin_type:q(g.fields.name,!1),value:C}});return{id:t.id.id,is_pause:t.is_pause,clmm_vault:u,lp_token_treasury:t.lp_token_treasury.fields.total_supply.fields.value,protocol_fees_handle:t.protocol_fees.fields.id.id,hard_cap:t.hard_cap,quote_type:ee(t.quote_type.fields.name).full_address,lp_token_type:ee(e).type_arguments[0],balances:f,protocol_fee_rate:t.protocol_fee_rate}}async function rs(i,t=!0){i.getData().commands.forEach((e,n)=>{})}function qe(i,t){let e=S(i).div(t).toString(),n=S(t).div(i).toString();return{quote_per_base:e,base_per_quote:n}}function sr(i,t,e,n){let r=10n**(Ce+n-e),a=10n**(Ce+e-n),o=Yt.checkMulDivFloor(new $t.default(i.toString()),new $t.default(r.toString()),new $t.default(t.toString()),64),u=Yt.checkMulDivFloor(new $t.default(t.toString()),new $t.default(a.toString()),new $t.default(i.toString()),64);return{primitive_base_price:BigInt(o.toString()),primitive_quote_price:BigInt(u.toString())}}function ye(i,t){let e=t?i[t].price:{coin_type:"",price:"1",coin_decimals:6,oracle_price:1000000000000000000000000n},n=new $t.default("0");for(let[r,{price:a,value:o}]of Object.entries(i)){let{primitive_quote_price:u}=sr(BigInt(e.oracle_price),BigInt(a.oracle_price),BigInt(e.coin_decimals),BigInt(a.coin_decimals)),d=Yt.checkMulDivFloor(new $t.default(u.toString()),new $t.default(o),new $t.default((BigInt(10)**Ce).toString()),64);n=n.add(d)}return n.toString()}async function zi(i,t,e,n,r=!1){let{clmm_vault:a,quote_type:o}=t,{wrapped_position:u}=a,{tick_lower_index:d,tick_upper_index:f,liquidity:m}=u,{current_sqrt_price:_,coin_type_a:g,coin_type_b:C}=e,k=[...n],P=o&&q(t.quote_type,!1),D=nt.tickIndexToSqrtPriceX64(d),x=nt.tickIndexToSqrtPriceX64(f),{coin_amount_a:E,coin_amount_b:O}=de.getCoinAmountFromLiquidity(new $t.default(m),new $t.default(_),new $t.default(D),new $t.default(x),!1);k.push({coin_type:g,value:E.toString()}),k.push({coin_type:C,value:O.toString()});let T={};k.forEach(z=>{let W=q(z.coin_type,!1),et=S(z.value),qt=T[W]||0;T[W]=et.add(qt).toString()});let H=Object.entries(T).filter(([z,W])=>S(W).gt(0)).map(([z])=>z);if(P&&!H.includes(P)&&H.push(P),H.length===0)return"0";let N=await i.PythPrice.getLatestPrice(H,r),G={};return H.forEach(z=>{let W=N[z];if(W)G[z]={price:W,value:T[z]||"0"};else throw Error(`find ${z} price fail `)}),ye(G,P).toString()}function Re(i,t,e){return S(i).eq(0)?t:S(i).mul(t).div(e).toFixed(0,ai.default.ROUND_HALF_UP)}function os(i,t,e){return S(i).eq(0)?"0":S(i).mul(t).div(e).toFixed(0,ai.default.ROUND_HALF_UP)}function ke(i,t,e){return S(i).eq(0)?"0":S(t).mul(e).div(i).toFixed(0,ai.default.ROUND_HALF_UP)}function Pe(i,t,e){let n={};return t.forEach(r=>{let a=ke(e,i,r.value),o={coin_type:r.coin_type,value:a};n[o.coin_type]=o}),n}function Xi(i,t,e,n){let{tick_lower_index:r,tick_upper_index:a,coin_type_a:o,coin_type_b:u,liquidity:d}=e.clmm_vault.wrapped_position,f=ke(e.lp_token_treasury,t,d),m=nt.tickIndexToSqrtPriceX64(r),_=nt.tickIndexToSqrtPriceX64(a),g=de.getCoinAmountFromLiquidity(new $t.default(f),new $t.default(n.current_sqrt_price),m,_,!0),C=g.coin_amount_a.toString(),k=g.coin_amount_b.toString(),P=Pe(t,e.balances,e.lp_token_treasury),D=S(C).add(P[o]?.value||"0").toFixed(0),x=S(k).add(P[u]?.value||"0").toFixed(0);return{vault_id:e.id,clmm_pool_id:n.id,owner:i,lp_token_type:e.lp_token_type,lp_token_balance:t,liquidity:f,tick_lower_index:r,tick_upper_index:a,amount_a:D,amount_b:x,coin_type_a:o,coin_type_b:u}}function De(i,t,e){let n=[];return t.forEach(r=>{S(r.value).gt(0)&&n.push(r)}),e.forEach(r=>{S(r.value).gt(0)&&n.push(r)}),i.forEach(r=>{S(r.value).gt(0)&&n.push(r)}),n}function Ne(i,t,e,n,r){let a=De(i,t,e),o=new Set;return a.forEach(u=>o.add(u.coin_type)),o.add(n),o.add(r),Array.from(o)}function Hi(i,t){if(!Ce)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(t<0n){let e=10n**(Ce- -t);return i*e}return i/10n**(t+Ce)}function Gi(i){return`0x${Buffer.from(i).toString("hex")}`}function ss(i,t,e,n,r){let a="0",o="0";return si(i,"min",Number(e))?a="0":a=nt.tickIndexToPrice(Number(i),n,r).toString(),si(t,"max",Number(e))?o="\u221E":o=nt.tickIndexToPrice(Number(t),n,r).toString(),{minPrice:a,maxPrice:o}}function li(i){let t=ie(i),e=$i(i),n=ee(e),r=t.position.fields,a={id:r.id.id,pool_id:r.pool,index:r.index,liquidity:r.liquidity,tick_lower_index:we(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:we(BigInt(r.tick_upper_index.fields.bits)),coin_type_a:q(r.coin_type_a.fields.name,!1),coin_type_b:q(r.coin_type_b.fields.name,!1),name:r.name,description:r.description,url:r.url},o=t.global_vesting_periods.map(d=>({period:d.fields.period,release_time:d.fields.release_time,redeemed_amount:d.fields.redeemed_amount,cetus_amount:d.fields.cetus_amount}));return{id:t.id.id,vault_id:t.vault_id,index:t.index,lp_coin_type:t.lp_coin_type.fields.name,allocated_lp_amount:t.allocated_lp_amount,position:a,balance:t.balance,total_supply:t.total_supply,impaired_a:t.impaired_a,impaired_b:t.impaired_b,redeemed_amount:t.redeemed_amount,url:t.url,coin_type_a:q(t.coin_a.fields.name,!1),coin_type_b:q(t.coin_b.fields.name,!1),cetus_amount:t.cetus_amount,start_time:t.start_time,global_vesting_periods:o,vest_infos:{id:t.vester_infos.fields.id,size:t.vester_infos.fields.size}}}function Qi(i){let t=ie(i),e=$i(i);return{id:t.id.id,vault_id:t.vault_id,index:t.index,lp_amount:t.lp_amount,url:t.url,redeemed_amount:t.redeemed_amount,impaired_a:t.impaired_a,impaired_b:t.impaired_b,period_infos:t.period_infos.map(r=>({period:r.fields.period,cetus_amount:r.fields.cetus_amount,is_redeemed:r.fields.is_redeemed})),name:t.name,vester_id:t.vester_id}}var Ji=require("@cetusprotocol/dlmm-sdk");var ar=ne(require("decimal.js")),ui=require("@mysten/sui/bcs"),di=require("@mysten/sui/utils");function Yi(i){let{fields:t}=i,{certified_pools:e,positions:n,id:r,coin_type_a:a,coin_type_b:o,vault_id:u,position_keys:d}=t;return{id:r.id,certified_pools:e.fields.contents.map(m=>m.fields.key),positions_handle:{id:n.fields.id.id,size:n.fields.size},position_list:[],coin_type_a:q(a.fields.name,!1),coin_type_b:q(o.fields.name,!1),vault_id:u,position_keys:d.fields.contents}}function as(i){return{uri:i.uri,index:i.index,id:i.id.id,name:i.name,pool_id:i.pool_id,lower_bin_id:we(BigInt(i.lower_bin_id.fields.bits)),upper_bin_id:we(BigInt(i.upper_bin_id.fields.bits)),liquidity_shares:i.liquidity_shares,description:i.description,coin_type_a:q(i.coin_type_a,!1),coin_type_b:q(i.coin_type_b,!1)}}function tn(i){let{fields:t}=i,{position:e,amounts:n,id:r}=t,a=n.fields.contents.map(g=>{let{key:C,value:k}=g.fields;return{coin_type:q(C.fields.name,!1),value:k}}),o=as(e.fields),u=o.lower_bin_id,d=o.liquidity_shares.map((g,C)=>({bin_id:u+C,liquidity:g})).filter(g=>S(g.liquidity).gt(0)),f=d.length>0?d[0].bin_id:u,m=d.length>0?d[d.length-1].bin_id:u+o.liquidity_shares.length-1;return{id:r.id,valid_lower_bin_id:f,valid_upper_bin_id:m,position:o,amounts:a}}function en(i){let{fields:t,type:e}=i,{action_status:n,buffer_assets:r,coin_type_a:a,coin_type_b:o,hard_cap:u,id:d,last_aum:f,lp_token_treasury:m,markets:_,protocol_fee_rate:g,protocol_fees:C,quote_type:k}=t,P=(Number(n)&1)!==0,D=(Number(n)&2)!==0,{balances:x}=r.fields,E=x.fields.contents.map(H=>{let{key:N,value:G}=H.fields;return{coin_type:q(N.fields.name,!1),value:G}}),O=k.fields.pos0.fields.name;return{id:d.id,lp_token_treasury:m.fields.total_supply.fields.value,hard_cap:u,quote_type:O?q(O,!1):void 0,protocol_fee_rate:g,buffer_assets:E,protocol_fees_handle:{id:C.fields.id.id,size:C.fields.size},markets_handle:{id:_.fields.id.id,size:_.fields.size},markets:[],action_status:{is_deposit_allowed:P,is_withdraw_allowed:D},last_aum:f,coin_type_a:q(a.fields.name,!1),coin_type_b:q(o.fields.name,!1),lp_token_type:ee(e).type_arguments[0]}}async function nn(i,t,e,n=!1){let{quote_type:r,coin_type_a:a,coin_type_b:o}=t,u=[...e],d=await i.CetusDlmmSDK.Pool.getPool(t.markets[0].position_list[0].position.pool_id,!1),f=await i.CetusDlmmSDK.Pool.getBinInfo(d.bin_manager.bin_manager_handle,d.active_id,d.bin_step,!1),m=(0,Ji.parseLiquidityShares)(t.markets[0].position_list[0].position.liquidity_shares,d.bin_step,t.markets[0].position_list[0].position.lower_bin_id,f),_=m.amount_a,g=m.amount_b,C=r&&q(r,!1);u.push({coin_type:a,value:_.toString()}),u.push({coin_type:o,value:g.toString()});let k={};u.forEach(O=>{let T=q(O.coin_type,!1),H=S(O.value),N=k[T]||0;k[T]=H.add(N).toString()});let P=Object.entries(k).filter(([O,T])=>S(T).gt(0)).map(([O])=>O);if(C&&!P.includes(C)&&P.push(C),P.length===0)return"0";let D=await i.VaultsV2.PythPrice.getLatestPrice(P,n),x={};return P.forEach(O=>{let T=D[O];if(T)x[O]={price:T,value:k[O]||"0"};else throw Error(`find ${O} price fail `)}),ye(x,C).toString()}async function fi(i,t,e,n,r){let{coin_type_a:a,coin_type_b:o,id:u,lp_token_type:d,markets:f}=e,m=f[0].position_list[0],{lower_bin_id:_,upper_bin_id:g,liquidity_shares:C}=m.position,{receive_amount_a:k,receive_amount_b:P,valid_lower_bin_id:D,valid_upper_bin_id:x,bin_infos:E,position_coin_amount_a:O,position_coin_amount_b:T}=await Ue(i,t,e,n);return{vault_id:u,certified_pool_id:n.id,owner:r,lp_token_type:d,lp_token_balance:t,liquidity_shares:C,valid_lower_bin_id:D,valid_upper_bin_id:x,original_lower_bin_id:_,original_upper_bin_id:g,amount_a:k,amount_b:P,position_amount_a:O,position_amount_b:T,coin_type_a:a,coin_type_b:o,bin_infos:E}}async function Ue(i,t,e,n){let{markets:r,lp_token_treasury:a,coin_type_a:o,coin_type_b:u}=e,d=r[0].position_list[0],{lower_bin_id:f}=d.position,{bin_manager:m,bin_step:_,active_id:g}=n,C=await i.CetusDlmmSDK.Pool.getBinInfo(m.bin_manager_handle,g,_,!1),k=S(t).div(a),P=(0,Ji.parseLiquidityShares)(d.position.liquidity_shares.map($=>S($.toString()).mul(k).toFixed(0,ar.default.ROUND_HALF_UP).toString()),_,f,C),D=P.amount_a,x=P.amount_b,E=Pe(t,e.buffer_assets,a),O=E[o]?.value||"0",T=E[u]?.value||"0",H=S(D.toString()).add(O).toFixed(0),N=S(x.toString()).add(T).toFixed(0),G=P.bins.filter($=>S($.liquidity).gt(0));return{valid_lower_bin_id:G.length>0?G[0].bin_id:P.bins[0].bin_id,valid_upper_bin_id:G.length>0?G[G.length-1].bin_id:P.bins[P.bins.length-1].bin_id,receive_amount_a:H,receive_amount_b:N,position_coin_amount_a:D,position_coin_amount_b:x,bin_infos:{bins:G,amount_a:P.amount_a,amount_b:P.amount_b}}}function rn(i){let t=ui.bcs.vector(ui.bcs.u8()).serialize(new TextEncoder().encode("DLMM_MARKET")).toBytes();return(0,di.deriveObjectID)(i,"vector<u8>",t)}function cs(i,t){let e=ui.bcs.Address.serialize(t).toBytes();return(0,di.deriveDynamicFieldID)(i,"0x2::object::ID",e)}var Ee=require("@pythnetwork/pyth-sui-js"),fn=require("@mysten/sui/bcs");var on={env:"mainnet",fullRpcUrl:"https://fullnode.mainnet.sui.io",vaults:{package_id:"0xc4ebf35be1478318d78c324342854dd2735a036139373a9d41a1aa3a46a01d05",published_at:"0xee17b7533c1067693296b3f7b53559fe7a8f3815999b13baa5a4225042914e0f",configs:{registry_id:"0x23014734280164270fa4c58f973c00079651e730d6f46491678ea8858f3bd13a",pools_handle:"0x31c810b6fcf3bb8699384e7c61fe9f7db53a04c4c22d514b3f79b6caa86183a8",pyth_oracle_id:"0xaed73fd854dfceedb2522903feec8c0e251764f5945bd38f969473024c4fb4d0",oracle_infos_handle:"0x6951ab4b36639e79ddbd9ba4478d7f72d1c5396b9198d0864c00e796c5815b01",prices_handle:"0x20a65a0f747f4f1ad465bdb61d784bbc5080ee5d200d5dd6594a354723b8c171",global_config_id:"0x5f8371674cd8e1e9eef5542ffe8adb339e3ff3a67894b14c954c7a92e992e0c1"},clmm_configs:{global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b"}},vaultsV2:{package_id:"0xfbc91f75397ce25b3b1b01cab2bf494d2e3f9b9e89c97545d88bd616cbbfcc37",published_at:"0xfbc91f75397ce25b3b1b01cab2bf494d2e3f9b9e89c97545d88bd616cbbfcc37",configs:{registry_id:"0xb6e0d2a2457af53a83b1435ea398f9460ba8abd98686387a4399fceefdfc22e2",pools_handle:"0xc88e97a3a3bb71dfcf8cc90e6383d7e3e1dee0170fa07c9365d233568659fc8f",global_config_id:"0x05bedfb68e6bf273946f8e1f2529e8f30acdf8b287dec524973c6bae9e979743",versioned_id:"0x70bea2f242b057cda9994e9fecee121cb35ee914c360cc86f061268110b6d9ec",oracle_infos_handle:"0x4631c11bfeae9461863d233285d03e3dba14f8dfb574781f1e2cbe9b58ba903e",pyth_oracle_id:"0xc08cdf8479075b0dae05aadc76f941038a25d74dcbedd9c339f7ce5da08fab92"}},pythConfigs:{pyth_state_id:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",hermes_service_urls:{primary:"https://hermes.pyth.network"},wormhole_state_id:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pyth_package_id:"0x04e20ddf36af412a4096f9014f4a565af9e812db9a05cc40254846cf6ed0ad91",pyth_published_at:"0x04e20ddf36af412a4096f9014f4a565af9e812db9a05cc40254846cf6ed0ad91"},aggregatorUrl:"https://api-sui.cetus.zone/router_v3",providers:["CETUS","TURBOS","STEAMM","SPRINGSUI","HAEDAL","FLOWX","AFTERMATH","ALPHAFI","BLUEFIN","METASTABLE","VOLO","SCALLOP","KRIYA","FLOWXV3","DEEPBOOKV3","AFSUI","BLUEMOVE","KRIYAV3","HAEDALPMM","OBRIC"],vest:{package_id:"0xd0587f397e47d31a79d1c36710c2c28f48ff8f1e8ea73b6a54fa2ec6fdfe0a7d",published_at:"0x57731e8bd3971eca68019afecb0e11699ece6301f0d4f255969f5b4227e0c5f8",version:1,config:{versioned_id:"0xee1e2214314737df6193cc4cf6815cf8dc3b4cc1c5cc0a078c6579dda19e8552",create_event_list:[{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0xb2d502d4ef89395934de020b195ded323bfa86d7f40b65ed5b15d6b66c722a3d::lpcoin::LPCOIN",pool_id:"0x2fc6ee9183d0f1ca0d2dded02c416be6f4671bb82db55c26ce12b536812a4b8e",position_id:"0x99f7fbeaf18c88e8af7553ad2ef055772477a1851550a2e7c2d7a503420c6b05",vault_id:"0xbd6252e0d56ae5eaabf055fd6c518ee5f66c1114287ca957cc698a17c3d25b16",vault_vester_id:"0xe4196586ed151a38c7c9169c72b9e5e3f51bfea9afbc2d1f082d6bedb88b086f"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x0484a9162669957e1c1883fc2da59e3cce9afdc1eec3c72c983898dbc9e92b91::lpcoin::LPCOIN",pool_id:"0xaa020ad81e1621d98d4fb82c4acb80dc064722f24ef828ab633bef50fc28268b",position_id:"0x90918d035e37b4447e11c2043c4c4374baeb7c2cbd2729063d939d016b04770f",vault_id:"0x99db9a7d3320d31fe6e4dc4122b948162010e331c41dc279636ca75567b93497",vault_vester_id:"0xd891e4c866a67e6339d1539edd1c28db629c81d9fb8499ee029cfa3803a0819e"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x242ddc526b9cb75513bee2fc629e01d5b7dc6da4c02d39cdab0160794635334f::lpcoin::LPCOIN",pool_id:"0x2e041f3fd93646dcc877f783c1f2b7fa62d30271bdef1f21ef002cebf857bded",position_id:"0xf82ebf822b0a7eff84f0079f3998611c4fec2ae714fe627225640eb305dc5a7c",vault_id:"0xbbd2d4850e4f238d39c3aa24957d2dfbb5787fa43d6c7de306bf15abe27f29f2",vault_vester_id:"0x7cc6404b903542ff6410b8e85c9647005713f8a23166ef08a488fe267c81c8bb"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0xd418945e16ef3db737df093d0827f5ce387b36f089523e13c16e50dec6bd2524::lpcoin::LPCOIN",pool_id:"0xe01243f37f712ef87e556afb9b1d03d0fae13f96d324ec912daffc339dfdcbd2",position_id:"0x1ea05f946e995edcda18ba9fdaefd1021eddfb8d62e4fa09da89753ffb5b90ee",vault_id:"0xed754b6a3a6c7549c3d734cb7b464bccf9c805814b9e47b0cb99f43b4efcb4a6",vault_vester_id:"0xd67cd239a34852cbc2e530db2ef296bc3e4a977464309c21ce706d90a17a5d5d"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0xf21d82f767cac2e8892db252aa539c137dcf8a6d1e6ebd2d0a11c16362171df7::lpcoin::LPCOIN",pool_id:"0x72f5c6eef73d77de271886219a2543e7c29a33de19a6c69c5cf1899f729c3f17",position_id:"0x5bd93e30000eb9f3217a04c938c7f939ee33ac161f6fe7ea34bac268dbe36893",vault_id:"0x12ac7deea4b92b3e2c16687e2d2695fa8c045ec0a52844db7b2fc3876c9552aa",vault_vester_id:"0x5d87bb3db28e77604f9bd210cdde0916e95a9d37925ec3c466fa785bba3d63f9"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x2f46a040b9bc3a584a3be4d7bfbb02a5fb479da17a04c6d2860ed61d95e97f3f::lpcoin::LPCOIN",pool_id:"0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105",position_id:"0xa2141e99975e203172f62c97b1f314f845b94730f6dfdb8ab2d32d014c659bcf",vault_id:"0x41a4ab1e82f90f5965bbcd828b8ffa13bab7560bd2e352ab067e343db552f527",vault_vester_id:"0x0e4782ee96095af233a6c5219b50cd8c92bd79d84f1df7e629bcc7a094c5a09d"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x5c79c0ab2c45682aba43b1acbe5c478d947f7c8397d47447906d6cc127e180fb::lpcoin::LPCOIN",pool_id:"0xea648440bd640d3530e8a5f02c0b56da82c2efe851156c39974b901bbb0eeab1",position_id:"0x896a01cc57ba25799ec320dc25d1969f3129f2591689ce8c8dbf380c7e00bf48",vault_id:"0x5525f5a70fffd93f616c39b59f3abdd2054fc2d19f09c8a4d94950d611a43b74",vault_vester_id:"0xe116bb120d2d91f85ee419cbff73fdd9d7f87e9b085dd4de781347b51361ae17"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x8275bc774497b319db110bb97a4812a19859ab6f19dc1574746097f06103c0f9::lpcoin::LPCOIN",pool_id:"0x9e59de50d9e5979fc03ac5bcacdb581c823dbd27d63a036131e17b391f2fac88",position_id:"0xd080bfb32b9c24f8875bd5a803a417b8ca0c02f2208d0b9058692f9013db3b52",vault_id:"0xedfb22d1bbe5045fd1888bb8bc1c4bc1823ab24d40f5a4bea9f6eb9758a4b820",vault_vester_id:"0x8bc7ccefae4db25873a0692bfb0d2c7cbdbbe644574a537789b98815960155a4"}]}}},sn={"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC":{coin_type:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",price_feed_id:"0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",coin_decimals:6},"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI":{coin_type:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",price_feed_id:"0x23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",coin_decimals:9},"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS":{coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS",price_feed_id:"0xe5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",coin_decimals:9},"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP":{coin_type:"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",price_feed_id:"0x29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff",coin_decimals:6},"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX":{coin_type:"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX",price_feed_id:"0x88250f854c019ef4f88a5c073d52a18bb1c6ac437033f5932cd017d24917ab46",coin_decimals:9},"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN":{coin_type:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",price_feed_id:"0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",coin_decimals:9},"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI":{coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI",price_feed_id:"0x6120ffcf96395c70aa77e72dcb900bf9d40dccab228efca59a17b90ce423d5e8",coin_decimals:9},"0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH":{coin_type:"0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH",price_feed_id:"0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",coin_decimals:8},"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL":{coin_type:"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",price_feed_id:"0xeba0732395fae9dec4bae12e52760b35fc1c5671e2da8b449c9af4efe5d54341",coin_decimals:9},"0x3e8e9423d80e1774a7ca128fccd8bf5f1f7753be658c5e645929037f7c819040::lbtc::LBTC":{coin_type:"0x3e8e9423d80e1774a7ca128fccd8bf5f1f7753be658c5e645929037f7c819040::lbtc::LBTC",price_feed_id:"0x8f257aab6e7698bb92b15511915e593d6f8eae914452f781874754b03d0c612b",coin_decimals:8},"0x3a304c7feba2d819ea57c3542d68439ca2c386ba02159c740f7b406e592c62ea::haedal::HAEDAL":{coin_type:"0x3a304c7feba2d819ea57c3542d68439ca2c386ba02159c740f7b406e592c62ea::haedal::HAEDAL",price_feed_id:"0xe67d98cc1fbd94f569d5ba6c3c3c759eb3ffc5d2b28e64538a53ae13efad8fd1",coin_decimals:9}};function an(i){return i&&(on.fullRpcUrl=i),new fe(on)}var cn={env:"testnet",fullRpcUrl:"https://fullnode.testnet.sui.io",vaults:{package_id:"0x0a624f2dcafc9f7f381684b3d553a9837411925b6e8530b1f8f4e6ff3f1fde77",published_at:"0x36f9d8e6219e6ba4d8840165ec27676a1bcb43fc5712f87ca702ac7b5924507d",configs:{registry_id:"0xa2ebae3656c5fbdd2473caadfc077cd1780a881759a356f1a5bc0f9fd470adb9",pools_handle:"0x0df305d395f8e0359da0ac5717bc96e0e1da9792684ec8e8f6a20b7ab544f98e",pyth_oracle_id:"0x6c74aec8d4471d9b05f718c467204c9010c450b94a4e40b0b4031a7d6c386337",global_config_id:"0x8969b09cfdd72b1635263b569027ded4b91bbabd7d8cd91b21e355325e218b10",oracle_infos_handle:"0x8707c6665d202f277ffe8e7fd58684e232622a3e6826b94ba99f7569f253fa9d",prices_handle:"0x74230bb2c6a63235acbfe477ce16144afca7ccd16a458fa93f4605330b5d1c58"},clmm_configs:{global_config_id:"0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e",global_vault_id:"0xf78d2ee3c312f298882cb680695e5e8c81b1d441a646caccc058006c2851ddea"}},pythConfigs:{pyth_state_id:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c",wormhole_state_id:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",hermes_service_urls:{primary:"https://hermes-beta.pyth.network"},pyth_package_id:"0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837",pyth_published_at:"0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837"},vaultsV2:{package_id:"0x0000000000000000000000000000000000000000000000000000000000000000",published_at:"0x0000000000000000000000000000000000000000000000000000000000000000",configs:{registry_id:"0x0000000000000000000000000000000000000000000000000000000000000000",pools_handle:"0x0000000000000000000000000000000000000000000000000000000000000000",global_config_id:"0x0000000000000000000000000000000000000000000000000000000000000000",versioned_id:"0x0000000000000000000000000000000000000000000000000000000000000000",pyth_oracle_id:"0x0000000000000000000000000000000000000000000000000000000000000000",oracle_infos_handle:"0x0000000000000000000000000000000000000000000000000000000000000000"}},aggregatorUrl:"https://api-sui.devcetus.com/router_v2",providers:["CETUS","DEEPBOOK","KRIYA","KRIYAV3","FLOWX","FLOWXV3","AFTERMATH","TURBOS","HAEDAL","VOLO","AFSUI"],vest:{package_id:"0x76ccc11581265c821a666af3baee1c4162165aed504674621a39d474bb32513b",published_at:"0x76ccc11581265c821a666af3baee1c4162165aed504674621a39d474bb32513b",config:{versioned_id:"0x2c5b6227da87ce840035955e0d82725178ce53c8cd2b01934d6540feccf2a8f7",create_event_list:[{clmm_vester_id:"0x308b24963e5992f699e32db2f7088b812566a0cae580317fd3b8bf61de7f5508",lp_coin_type:"0xb0c18dcd849d4b47528831c64707f2f7f6aa1b7fd9ed5e1ac2f8ab356e031f25::lp_token::LP_TOKEN",pool_id:"0x403c7d9c1e959c029f61d970286eac8ad5bca2db2edba358585abf4dbd4ed3cd",position_id:"0xd1dbcdb1789b92772b367bc1f68d7d078b4fd3326b8bfb53750bf28585463508",vault_id:"0xed754b6a3a6c7549c3d734cb7b464bccf9c805814b9e47b0cb99f43b4efcb4a6",vault_vester_id:"0x6098c69613ed5d503ff2b81447e96408feab8f2e4bf582966a811b5b582d23e3"}]}}},ln={};function un(i){return i&&(cn.fullRpcUrl=i),new fe(cn)}var cr=(e=>(e.mainnet="mainnet",e.testnet="testnet",e))(cr||{});function ls(i){let{env:t,fullNodeUrl:e}=i;return t==="mainnet"?an(e):un(e)}var dn=["CETUS","TURBOS","STEAMM","SPRINGSUI","HAEDAL","FLOWX","AFTERMATH","ALPHAFI","BLUEFIN","METASTABLE","VOLO","SCALLOP","KRIYA","FLOWXV3","DEEPBOOKV3","AFSUI","BLUEMOVE","KRIYAV3","HAEDALPMM","OBRIC"];function lr(i){try{let{request_time:t,error:e,request_params:n,request_url:r,action:a}=i;if(window?.gtag){let o=e.message==="Request Timeout";window.gtag("event","API_Error",{request_action:a,request_url:r,request_time:t,request_params:JSON.stringify(n),error_msg:String(e)})}}catch{}}var us=16*1024,Se=class{_sdk;connection;suiPythClient;hasChangeConnection=!1;errorList=[];pythConfigs;global_config_id;pyth_oracle_id;oracle_infos_handle;vaults_published_at;versioned_id;isV2;constructor(t,e,n,r,a,o,u,d){this.vaults_published_at=n,this.pythConfigs=e,this.global_config_id=r,this.pyth_oracle_id=a,this.oracle_infos_handle=u,this.isV2=d,this.versioned_id=o;let{pyth_state_id:f,wormhole_state_id:m,hermes_service_urls:_}=e;this._sdk=t,this.hasChangeConnection=!1;let{primary:g}=_;if(g.length===0)throw new Error("primary url is empty");this.connection=new Ee.SuiPriceServiceConnection(g),this.suiPythClient=new Ee.SuiPythClient(this._sdk.FullClient,f,m)}get sdk(){return this._sdk}recordError(t,e,n){let{secondary:r,primary:a}=this.pythConfigs.hermes_service_urls,o={error:t,request_params:e,request_url:this.hasChangeConnection&&r?r:a,action:n,request_time:Date.now()};lr(o),this.errorList.push(o)}readErrorList(){let t=this.errorList;return this.errorList=[],t}async getFeedInfoList(t){let e=t.map(r=>this.getFeedInfo(r,!1));return await Promise.all(e)}priceCheck(t,e=60){let n=Math.floor(Date.now()/1e3);if(!(Math.abs(n-t.last_update_time)>e))return t}async getLatestPrice(t,e=!1){let n={},r=[];if(e?t.forEach(u=>{let d=this._sdk.getCache(`getLatestPrice_${u}`);d&&this.priceCheck(d,60)?n[u]=d:r.push(u)}):r=[...t],r.length===0)return n;let a=await this.getFeedInfoList(r);return(await this.getLatestPriceFeeds(a.map(u=>u.price_feed_id)))?.forEach((u,d)=>{let f=u.getPriceUnchecked();if(f){let{price:m,expo:_}=f,g=S(m).mul(S(10).pow(S(_))).toString(),C=a[d],k={coin_type:C.coin_type,price:g,coin_decimals:C.coin_decimals,oracle_price:0n,last_update_time:f.publishTime};k.oracle_price=Hi(BigInt(m),BigInt(_)),n[r[d]]=k,this._sdk.updateCache(`getLatestPrice_${k.coin_type}`,k)}}),n}async getPriceFeedsUpdateData(t){try{return await this.connection.getPriceFeedsUpdateData(t)}catch(e){this.recordError(e,t,"getPriceFeedsUpdateData");let{secondary:n}=this.pythConfigs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Ee.SuiPriceServiceConnection(n);try{return await this.connection.getPriceFeedsUpdateData(t)}catch(r){this.recordError(r,t,"getPriceFeedsUpdateData")}}}}async getLatestPriceFeeds(t){try{return await this.connection.getLatestPriceFeeds(t)}catch(e){this.recordError(e,t,"getLatestPriceFeeds");let{secondary:n}=this.pythConfigs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Ee.SuiPriceServiceConnection(n);try{return await this.connection.getLatestPriceFeeds(t)}catch(r){this.recordError(r,t,"getLatestPriceFeeds")}}}}async buildUpdatePythPricePayload(t,e){let{pyth_state_id:n,pyth_published_at:r,pyth_package_id:a}=this.pythConfigs,o=(await this.getFeedInfoList(t)).map(g=>g.price_feed_id);if(t.length!==o.length)throw Error("find feed id fail");let u=await this.getPriceFeedsUpdateData(o);if(!u)throw new Error("get price update data fail");if(u.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");let d=this.suiPythClient.extractVaaBytesFromAccumulatorMessage(u[0]),f=await this.suiPythClient.verifyVaas([d],e),[m]=e.moveCall({target:`${r}::pyth::create_authenticated_price_infos_using_accumulator`,typeArguments:[],arguments:[e.object(n),e.pure(fn.bcs.vector(fn.bcs.U8).serialize(Array.from(u[0]),{maxSize:us}).toBytes()),f[0],e.object(Zt)]}),_=0;for(let g of o){let C=await this.suiPythClient.getPriceFeedObjectId(g);if(!C)throw new Error(`Price feed ${g} not found, please create it first`);this.isV2?[m]=e.moveCall({target:`${this.vaults_published_at}::pyth_oracle::update_price`,typeArguments:[t[_]],arguments:[e.object(this.pyth_oracle_id),e.object(n),m,e.object(C),e.object(Zt),e.object(this.versioned_id)]}):[m]=e.moveCall({target:`${this.vaults_published_at}::pyth_oracle::update_price`,typeArguments:[t[_]],arguments:[e.object(this.pyth_oracle_id),e.object(this.global_config_id),e.object(n),m,e.object(C),e.object(Zt)]}),_+=1}return e.moveCall({target:`${r}::hot_potato_vector::destroy`,arguments:[m],typeArguments:[`${a}::price_info::PriceInfo`]}),e}getFeedInfoByJson(t){let{env:e}=this._sdk.sdkOptions,n=q(t,!1);return e==="mainnet"?sn[n]:ln[n]}async getFeedInfo(t,e){let n=`getFeedInfo_${t}`,r=this._sdk.getCache(n,e);if(r)return r;let a=this.getFeedInfoByJson(t);if(a)return a;let o=await this._sdk.FullClient.getDynamicFieldObject({parentId:this.oracle_infos_handle,name:{type:"0x1::type_name::TypeName",value:q(t,!0)}}),{fields:u}=o.data.content.fields.value,d={coin_type:t,price_feed_id:Gi(u.price_feed_id),coin_decimals:u.coin_decimals};return this._sdk.updateCache(n,d),d}};var $e=class{_sdk;pythPrice;constructor(t){this._sdk=t;let{vaults:e,pythConfigs:n}=t.sdkOptions;this.pythPrice=new Se(t,n,e.published_at,e.configs.global_config_id,e.configs.pyth_oracle_id,"",e.configs.oracle_infos_handle,!1)}get sdk(){return this._sdk}get PythPrice(){return this.pythPrice}async getProtocolFeeRate(){let t="getProtocolFeeRate",e=this._sdk.getCache(t);if(e)return e;let{configs:n}=this._sdk.sdkOptions.vaults,a=(await this._sdk.FullClient.getObject({id:n.global_config_id,options:{showContent:!0}})).data.content.fields.protocol_fee_rate;return this._sdk.updateCache(t,a),a}async getOwnerVaultsBalance(t,e){let{pool:n,clmmPool:r}=await this.getVaultAndPool(e,!0),o=(await this._sdk.FullClient.getBalance({owner:t,coinType:n.lp_token_type})).totalBalance;return Xi(t,o,n,r)}async getOwnerVaultsBalanceList(t){let{data:e}=await this.getPoolList(),n=[];for(let r=0;r<e.length;r++){let a=await this.getOwnerVaultsBalance(t,e[r].id);n.push(a)}return n}async getVaultsPositionRewarderAndFee(t){try{let{package_id:e}=this._sdk.sdkOptions.vaults,{pool:n,clmmPool:r}=await this.getVaultAndPool(t,!1),a=`getVaultsPositionRewarderAndFee_${t}`,o=this._sdk.getCache(a);if(o)return o;let{lp_token_type:u}=n,{rewarder_infos:d,id:f,coin_type_a:m,coin_type_b:_}=r,g=new Te.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...d.map(E=>E.coin_type)],lp_token_type:u,pool_id:t,clmm_pool_id:f,coin_type_a:m,coin_type_b:_},g),this.buildCollectFeePayload({lp_token_type:u,pool_id:t,clmm_pool_id:f,coin_type_a:m,coin_type_b:_},g);let C=await this._sdk.FullClient.sendSimulationTransaction(g,(0,dr.normalizeSuiAddress)("0x0")),k=`${e}::pool::FeeClaimedEvent`,P=`${e}::pool::RewardClaimedEvent`,D=[],x=[];return C?.events.forEach(E=>{let{parsedJson:O,type:T}=E;T===k&&(D.push({coin_type:q(m,!1),value:O.amount_a}),D.push({coin_type:q(_,!1),value:O.amount_b})),T===P&&x.push({coin_type:q(O.reward_type.name,!1),value:O.amount})}),this._sdk.updateCache(a,{feeList:D,rewarderList:x},10*1e3),{feeList:D,rewarderList:x}}catch{}return{feeList:[],rewarderList:[]}}async getPoolList(t="all"){let e={data:[],has_next_page:!1},{vaults:n}=this._sdk.sdkOptions,{FullClient:r}=this._sdk,a=await r.getDynamicFieldsByPage(n.configs.pools_handle,t),o=a.data.map(u=>u.name.value);return o.length>0&&((await r.batchGetObjects(o,{showContent:!0})).forEach(d=>{let f=ci(d.data.content);this._sdk.updateCache(`getPool_${f.id}`,f),e.data.push(f)}),e.next_cursor=a.next_cursor,e.has_next_page=a.has_next_page),e}async getPool(t,e=!0){let n=`getPool_${t}`,r=this._sdk.getCache(n,e);if(r)return r;let a=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),o=ci(a.data.content);return this._sdk.updateCache(n,o),o}buildCollectRewardPayload(t,e){let{coin_type_a:n,coin_type_b:r,pool_id:a,clmm_pool_id:o,lp_token_type:u,reward_coin_types:d}=t,{published_at:f,configs:m,clmm_configs:_}=this._sdk.sdkOptions.vaults;return e=e||new Te.Transaction,d.forEach(g=>{e.moveCall({target:`${f}::pool::collect_reward`,typeArguments:[n,r,u,g],arguments:[e.object(a),e.object(m.global_config_id),e.object(_.global_config_id),e.object(o),e.object(_.global_vault_id),e.object(Zt)]})}),e}buildCollectFeePayload(t,e){let{coin_type_a:n,coin_type_b:r,pool_id:a,clmm_pool_id:o,lp_token_type:u}=t,{published_at:d,configs:f,clmm_configs:m}=this._sdk.sdkOptions.vaults;return e=e||new Te.Transaction,e.moveCall({target:`${d}::pool::collect_fee`,typeArguments:[n,r,u],arguments:[e.object(a),e.object(f.global_config_id),e.object(m.global_config_id),e.object(o)]}),e}async buildDepositPayload(t,e){let{pool_id:n,amount_a:r,amount_b:a,return_lp_coin:o}=t,{pool:u,clmmPool:d}=await this.getVaultAndPool(n,!0),{rewarderList:f,feeList:m}=await this.getVaultsPositionRewarderAndFee(n),_=Ne(u.balances,f,m,d.coin_type_a,d.coin_type_b),{lp_token_type:g}=u,{rewarder_infos:C,id:k,coin_type_a:P,coin_type_b:D}=d,x=f.length>0?f.filter(W=>S(W.value.toString()).gt(0)).map(W=>q(W.coin_type,!1)):C.map(W=>q(W.coin_type,!1)),{published_at:E,configs:O,clmm_configs:T}=this._sdk.sdkOptions.vaults;e=e||new Te.Transaction,e=this.buildCollectRewardPayload({reward_coin_types:x,lp_token_type:g,pool_id:n,clmm_pool_id:k,coin_type_a:P,coin_type_b:D},e),e=this.buildCollectFeePayload({lp_token_type:g,pool_id:n,clmm_pool_id:k,coin_type_a:P,coin_type_b:D},e),e=await this.pythPrice.buildUpdatePythPricePayload(_,e),e.moveCall({target:`${E}::pool::calculate_aum`,typeArguments:[P,D,g],arguments:[e.object(n),e.object(O.global_config_id),e.object(O.pyth_oracle_id),e.object(T.global_config_id),e.object(k),e.object(Zt)]});let H=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress,P),N=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress,D),G=Ht.buildCoinForAmount(e,H,BigInt(r),P,!1,!0),$=Ht.buildCoinForAmount(e,N,BigInt(a),D,!1,!0),z=e.moveCall({target:`${E}::pool::${o?"deposit_for":"deposit"}`,typeArguments:[P,D,g],arguments:[e.object(n),e.object(O.global_config_id),e.object(O.pyth_oracle_id),e.object(T.global_config_id),e.object(k),G.target_coin,$.target_coin,e.object(Zt)]});return o?z:void 0}async buildWithdrawPayload(t,e){let{pool_id:n,burn_lp_amount:r,mode:a,slippage:o,partner:u,extra_burn:d}=t,{pool:f,clmmPool:m}=await this.getVaultAndPool(n,!0),{published_at:_,configs:g,clmm_configs:C}=this._sdk.sdkOptions.vaults;e=e||new Te.Transaction;let{lp_token_type:k,clmm_vault:P,lp_token_treasury:D}=f,{rewarder_infos:x,id:E,coin_type_a:O,coin_type_b:T,liquidity:H}=m,N=x.map(Q=>q(Q.coin_type,!1));e=this.buildCollectRewardPayload({reward_coin_types:N,lp_token_type:k,pool_id:n,clmm_pool_id:E,coin_type_a:O,coin_type_b:T},e),e=this.buildCollectFeePayload({lp_token_type:k,pool_id:n,clmm_pool_id:E,coin_type_a:O,coin_type_b:T},e);let G=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress),$,z=d?S(d.burn_lp_amount).add(S(r)).toFixed(0):S(r).toFixed(0),W=S(r).isZero();if(W&&!d)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");W?$=d.lp_burn_coin:($=Ht.buildCoinForAmount(e,G,BigInt(r),k,!1,!0).target_coin,d&&e.mergeCoins($,[d.lp_burn_coin]));let[et,qt,X]=e.moveCall({target:`${_}::pool::withdraw`,typeArguments:[O,T,k],arguments:[e.object(n),e.object(g.global_config_id),e.object(C.global_config_id),e.object(E),$,e.object(Zt)]});if(this.buildWithdrawBufferReward({reward_coin_types:N.filter(Q=>![q(O,!1),q(T,!1)].includes(Q)),pool_id:n,withdraw_cert:X,lp_token_type:k},e,G),e.moveCall({target:`${_}::pool::destory_withdraw_cert`,typeArguments:[k],arguments:[e.object(n),e.object(g.global_config_id),X]}),a!=="FixedOneSide"){if(o===void 0)throw Error("the slippage is undefined");let Q=a==="OnlyCoinA",s=Q?qt:et,l=ke(D,z,H.toString());await this.handleWithSwap(e,s,O,T,z,n,Q,o,u,[{poolID:E,ticklower:P.wrapped_position.tick_lower_index,tickUpper:P.wrapped_position.tick_upper_index,deltaLiquidity:Number(l)}]),e.transferObjects([Q?et:qt],this._sdk.senderAddress)}else e.transferObjects([et,qt],this._sdk.senderAddress);return e}async handleWithSwap(t,e,n,r,a,o,u,d,f,m){let{receive_amount_a:_,receive_amount_b:g}=await this.preCalculateWithdrawAmount({pool_id:o,mode:"FixedOneSide",burn_lp_amount:a}),C=u?r:n,k=u?n:r,P=u?g:_,D={from:C,target:k,amount:new he.default(P),byAmountIn:!0,depth:3,splitAlgorithm:void 0,splitFactor:void 0,splitCount:void 0,providers:this._sdk.sdkOptions.providers,liquidityChanges:m},x=await this._sdk.AggregatorClient.findRouters(D);if(!x)throw Error("not find Router");if(x.error!==void 0)throw Error(`find Router error : ${x.error}`);let E={router:x,inputCoin:e,slippage:d,txb:t,partner:f},O=await this._sdk.AggregatorClient.fixableRouterSwapV3(E);t.transferObjects([O],t.pure.address(this._sdk.getVerifySenderAddress()))}buildWithdrawBufferReward({reward_coin_types:t,pool_id:e,withdraw_cert:n,lp_token_type:r},a,o){let{published_at:u,configs:d}=this._sdk.sdkOptions.vaults;t.forEach(f=>{let m=a.moveCall({target:`${u}::pool::withdraw_buffer_reward`,typeArguments:[r,f],arguments:[a.object(e),a.object(d.global_config_id),n]}),_=Ht.getCoinAssets(f,o),g=Ht.selectCoinAssetGreaterThanOrEqual(_,BigInt(0));if(g.selected_coins.length>0&&!Ht.isSuiCoin(f))a.mergeCoins(g.selected_coins[0].coin_object_id,[m]);else{let C=Ht.buildCoinForAmount(a,o,BigInt(0),f,!1,!1);a.mergeCoins(C.target_coin,[m]),a.transferObjects([C.target_coin],this._sdk.senderAddress)}})}async preCalculateDepositValue(t,e){let{amount_usd:n,pool_id:r,mode:a,uuid:o}=t,{pool:u,clmmPool:d}=await this.getVaultAndPool(r,!1),{current_sqrt_price:f}=d,{tick_lower_index:m,tick_upper_index:_,coin_type_a:g,coin_type_b:C}=u.clmm_vault.wrapped_position,k="0",P="0",D=await this.pythPrice.getLatestPrice([g,C],!0),x=D[g],E=D[C];if(!x||!E)throw new Error("get coin price failed");switch(a){case"FixedOneSide":{let{amountA:O,amountB:T}=Zi(m,_,new he.default(f),n,x.price,E.price,x.coin_decimals,E.coin_decimals);k=O.toString(),P=T.toString();break}case"FlexibleBoth":{let{amountA:O,amountB:T}=ae(S(.5),S(.5),n,x.price,E.price,x.coin_decimals,E.coin_decimals);k=O.toString(),P=T.toString();break}case"OnlyCoinA":{let{amountA:O,amountB:T}=ae(S(1),S(0),n,x.price,E.price,x.coin_decimals,E.coin_decimals);k=O.toString(),P=T.toString();break}case"OnlyCoinB":{let{amountA:O,amountB:T}=ae(S(0),S(1),n,x.price,E.price,x.coin_decimals,E.coin_decimals);k=O.toString(),P=T.toString();break}default:throw new Error(`Unsupported deposit mode: ${a}`)}return e&&this.calculateDepositLpAmountBoth(u,d,k,P).then(O=>{e.onSuccess(O,o)}).catch(O=>{e.onError(O,o)}),{deposit_amount_a:k,deposit_amount_b:P,mode:a}}async preCalculateDepositAmount(t,e){let{mode:n,pool_id:r,uuid:a}=t,o="0",u="0",{pool:d,clmmPool:f}=await this.getVaultAndPool(r,!1);switch(n){case"FixedOneSide":{let{fixed_amount:m,fixed_coin_a:_}=t,{other_amount:g}=this.calculateDepositOtherSide(d,f,m,_,e,a);_?(o=m,u=g):(u=m,o=g);break}case"FlexibleBoth":{let{coin_amount_a:m,coin_amount_b:_}=t;o=m,u=_,this.calculateDepositLpAmountBoth(d,f,m,_).then(g=>{e.onSuccess(g,a)}).catch(g=>{e.onError(g,a)});break}case"OnlyCoinA":{o=t.coin_amount_a,this.calculateDepositLpAmountBoth(d,f,o,"0").then(m=>{e.onSuccess(m,a)}).catch(m=>{e.onError(m,a)});break}case"OnlyCoinB":{u=t.coin_amount_b,this.calculateDepositLpAmountBoth(d,f,"0",u).then(m=>{e.onSuccess(m,a)}).catch(m=>{e.onError(m,a)});break}default:throw new Error(`Unsupported deposit mode: ${n}`)}return{deposit_amount_a:o,deposit_amount_b:u,mode:n}}async getVaultAndPool(t,e=!1){let n=await this.getPool(t,e);if(n===void 0)throw new Error("get vaults pool failed");let r=await this._sdk.CetusClmmSDK.Pool.getPool(n.clmm_vault.clmm_pool_id,e);if(r===void 0)throw new Error("get vaults clmmPool failed");return{clmmPool:r,pool:n}}calculateDepositOtherSide(t,e,n,r,a,o){let{clmm_vault:u}=t,{current_sqrt_price:d}=e,f=u.wrapped_position.tick_lower_index,m=u.wrapped_position.tick_upper_index,_=de.estLiquidityAndCoinAmountFromOneAmounts(f,m,new he.default(n),r,!0,1,new he.default(d)),{coin_amount_a:g,coin_amount_b:C}=_;return this.calculateDepositLpAmountBoth(t,e,g.toString(),C.toString()).then(k=>{a.onSuccess(k,o)}).catch(k=>{a.onError(k,o)}),{other_amount:r?C.toString():g.toString()}}async calculateDepositLpAmountBoth(t,e,n,r){let{lp_token_treasury:a,hard_cap:o}=t,u=q(e.coin_type_a,!1),d=q(e.coin_type_b,!1),{rewarderList:f,feeList:m}=await this.getVaultsPositionRewarderAndFee(t.id),_=De(t.balances,m,f),g=await zi(this,t,e,_,!0),C=await this.pythPrice.getLatestPrice([u,d],!0),k=C[u],P=C[d];if(!k)throw Error(`not find ${u} price`);if(!P)throw Error(`not find ${d} price`);let D={};D[u]={price:k,value:n.toString()},D[d]={price:P,value:r.toString()};let x=ye(D,t.quote_type);return Re(a,x,g)}async preCalculateWithdrawAmount(t){let{mode:e,pool_id:n}=t,r="0",a="0",o="0",u="0",d,{pool:f,clmmPool:m}=await this.getVaultAndPool(n,!1);switch(e){case"FixedOneSide":let _=await this.calculateWithdrawOtherSide(f,m,t.burn_lp_amount);o=_.burn_lp_amount,r=_.receive_amount_a,a=_.receive_amount_b,u=_.remove_liquidity;break;case"OnlyCoinA":{let g=await this.calculateWithdrawOnlyCoin(f,m,t.burn_lp_amount,!0);o=g.burn_lp_amount,r=g.receive_amount_a,a=g.receive_amount_b,u=g.remove_liquidity,d=g.swap;break}case"OnlyCoinB":{let g=await this.calculateWithdrawOnlyCoin(f,m,t.burn_lp_amount,!1);o=g.burn_lp_amount,r=g.receive_amount_a,a=g.receive_amount_b,u=g.remove_liquidity,d=g.swap;break}default:throw new Error(`Unsupported withdraw mode: ${e}`)}return{remove_liquidity:u,burn_lp_amount:o,receive_amount_a:r,receive_amount_b:a,mode:e,swap:d}}async calculateWithdrawOtherSide(t,e,n){let{clmm_vault:r,lp_token_treasury:a}=t,{current_sqrt_price:o}=e,{coin_type_a:u,coin_type_b:d}=t.clmm_vault.wrapped_position,f=r.wrapped_position.tick_lower_index,m=r.wrapped_position.tick_upper_index,_=r.wrapped_position.liquidity,g=nt.tickIndexToSqrtPriceX64(f),C=nt.tickIndexToSqrtPriceX64(m),k=ke(a,n,_),{coin_amount_a:P,coin_amount_b:D}=de.getCoinAmountFromLiquidity(new he.default(k),new he.default(o),g,C,!1),x=Pe(n,t.balances,a),E=S(P.toString()).add(x[u]?.value||"0").toFixed(0),O=S(D.toString()).add(x[d]?.value||"0").toFixed(0);return{receive_amount_a:E,receive_amount_b:O,burn_lp_amount:n,mode:"FixedOneSide",remove_liquidity:k}}async calculateWithdrawOnlyCoin(t,e,n,r){let{totalReceiveAmount:a,swapAmountIn:o,swapAmountOut:u,removeLiquidity:d}=await this.calculateWithdrawOnlyCoinByLpAmount(t,e,r,n);return{receive_amount_a:r?a:"0",receive_amount_b:r?"0":a,burn_lp_amount:n,remove_liquidity:d,swap:{swap_amount_in:o,swap_amount_out:u},mode:"FixedOneSide"}}async calculateWithdrawOnlyCoinByLpAmount(t,e,n,r){let{clmm_vault:a,lp_token_treasury:o}=t,{current_sqrt_price:u}=e,{coin_type_a:d,coin_type_b:f}=a.wrapped_position,m=a.wrapped_position.tick_lower_index,_=a.wrapped_position.tick_upper_index,g=a.wrapped_position.liquidity,C=nt.tickIndexToSqrtPriceX64(m),k=nt.tickIndexToSqrtPriceX64(_),P=ke(o,r,g),{coin_amount_a:D,coin_amount_b:x}=de.getCoinAmountFromLiquidity(new he.default(P),new he.default(u),C,k,!1),E=await this.pythPrice.getLatestPrice([d,f],!0),O=E[d],T=E[f];if(!O)throw Error(`not find ${d} price`);if(!T)throw Error(`not find ${f} price`);let H=n?T:O,N=n?O:T,{quote_per_base:G}=qe(H.price,N.price),$=Pe(r,t.balances,o),z=S(D.toString()).add($[d]?.value||"0").toFixed(0),W=S(x.toString()).add($[f]?.value||"0").toFixed(0),et=n?z:W,qt=n?W:z,X=Qt(S(ue(qt,n?T.coin_decimals:O.coin_decimals)).mul(G).toString(),n?O.coin_decimals:T.coin_decimals).toString(),Q=S(et).add(X).toFixed(0);return{burn_lp_amount:r,removeLiquidity:P,is_coin_a:n,originAmount:et,swapAmountIn:qt,swapAmountOut:S(X).toFixed(0,fr.default.ROUND_DOWN),totalReceiveAmount:Q}}async getPackageConfigs(){let t={registry_id:"1",pools_handle:"",pyth_oracle_id:"1",oracle_infos_handle:"",prices_handle:"1",global_config_id:"1"},{package_id:e}=this._sdk.sdkOptions.vaults,n=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),r=oi(n);(await this._sdk.FullClient.queryEventsByPage({Transaction:r})).data.forEach(m=>{let _=m.parsedJson;if(m.type)switch((0,ur.extractStructTagFromType)(m.type).full_address){case`${e}::pool::InitEvent`:t.registry_id=_.registry_id;break;case`${e}::pyth_oracle::InitEvent`:t.pyth_oracle_id=_.pyth_oracle_id;break;case`${e}::config::InitConfigEvent`:t.global_config_id=_.global_config;break;default:break}});let o=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),u=ie(o);t.pools_handle=u.pools.fields.id.id;let d=await this._sdk.FullClient.getObject({id:t.pyth_oracle_id,options:{showContent:!0}}),f=ie(d);return t.oracle_infos_handle=f.oracle_infos.fields.id.id,t.prices_handle=f.prices.fields.id.id,this._sdk.sdkOptions.vaults.configs=t,this._sdk.sdkOptions}};var hr=require("@mysten/sui/transactions");var Ke=class{_sdk;constructor(t){this._sdk=t}get sdk(){return this._sdk}async vestNftIsAvailable(t,e){try{let n=await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"0x2::object::ID",value:t}});return!ie(n).value.fields.is_pause}catch{return!0}}async getVestCreateEventList(){let{vest:t}=this._sdk.sdkOptions;if(t===void 0)throw new Error("vest is not set config in sdk options");try{let e=`${t.package_id}::hae_vester::CreateEvent`;return(await this._sdk.FullClient.queryEventsByPage({MoveEventType:e})).data.map(r=>{let a=r.parsedJson,o={clmm_vester_id:a.clmm_vester_id,lp_coin_type:q(a.lp_coin_type.name,!1),pool_id:a.pool_id,position_id:a.position_id,vault_id:a.vault_id,vault_vester_id:a.hae_vester_id},u=`${o.vault_id}-VestCreateEvent`;return this._sdk.updateCache(u,o),o})}catch(e){throw new Error(`getVestCreateEventList error: ${e}`)}return[]}async getVaultsVestInfoList(t){let{vest:e}=this._sdk.sdkOptions;if(!e)throw new Error("vest is not set config in sdk options");let n=[];for(let o of t){let u=await this.getVaultVestEvent(o);n.push(u.vault_vester_id)}let r=[];return(await this._sdk.FullClient.batchGetObjects(n,{showContent:!0,showType:!0})).forEach(o=>{try{let u=li(o);r.push(u);let d=`${u.id}-VaultsVestInfo`;this._sdk.updateCache(d,u)}catch{}}),r}async getVaultsVestInfo(t,e=!0){let n=(await this.getVaultVestEvent(t)).vault_vester_id,r=`${n}-VaultsVestInfo`,a=this._sdk.getCache(r,e);if(a)return a;try{let o=await this._sdk.FullClient.getObject({id:n,options:{showContent:!0,showType:!0}}),u=li(o);return this._sdk.updateCache(r,u),u}catch(o){throw new Error(`getVaultsVestInfo error: ${o}`)}}async getVaultVestEvent(t){let{vest:e}=this._sdk.sdkOptions;if(!e)throw new Error("vest is not set config in sdk options");let{create_event_list:n}=ve(e),r=n.find(a=>a.vault_id===t);if(!r){let a=`${t}-VestCreateEvent`,o=this._sdk.getCache(a,!1);o?r=o:(r=(await this.getVestCreateEventList()).find(d=>d.vault_id===t),this._sdk.updateCache(a,r))}if(!r)throw new Error("vault_id not found in vest_ids_map");return r}async getOwnerVaultVestNFT(t){let{vest:e}=this._sdk.sdkOptions;if(!e)throw new Error("vest is not set config in sdk options");let n=await this._sdk.FullClient.getOwnedObjectsByPage(t,{filter:{StructType:`${e.package_id}::hae_vester::HaeVesterNFT`},options:{showContent:!0,showType:!0,showOwner:!0}}),r=[];return n.data.forEach(a=>{try{let o=Qi(a);r.push(o)}catch{}}),r}async buildRedeemPayload(t,e){let{vest:n}=this._sdk.sdkOptions,{clmm_vest:r}=this._sdk.CetusClmmSDK.sdkOptions;if(!n)throw new Error("vest is not set config in sdk options");if(!r)throw new Error("clmm_vest is not set config in clmm sdk options");let{versioned_id:a}=ve(n),{versioned_id:o,clmm_vest_id:u}=ve(r);e=e||new hr.Transaction;for(let d of t){let{vault_id:f,vesting_nft_id:m,period:_,coin_type_a:g,coin_type_b:C}=d,k=await this.getVaultVestEvent(f);e.moveCall({package:n.published_at,module:"hae_vester",function:"redeem_coin",arguments:[e.object(a),e.object(k.vault_vester_id),e.object(m),e.object(o),e.object(u),e.object(k.pool_id),e.pure.u16(_),e.object(Zt)],typeArguments:[g,C]})}return e}};var hn=require("@mysten/sui/transactions"),mr=ne(require("bn.js")),pr=require("@cetusprotocol/aggregator-sdk");var _r=require("@mysten/sui/utils"),hi=ne(require("decimal.js"));var Be=require("@cetusprotocol/dlmm-sdk");var We=class{_sdk;pythPrice;constructor(t){this._sdk=t;let{vaultsV2:e,pythConfigs:n}=t.sdkOptions;this.pythPrice=new Se(t,n,e.published_at,e.configs.global_config_id,e.configs.pyth_oracle_id,e.configs.versioned_id,e.configs.oracle_infos_handle,!0)}get PythPrice(){return this.pythPrice}get sdk(){return this._sdk}async getOwnerVaultsBalance(t,e){let{pool:n,dlmmPool:r}=await this.getVaultAndPool(e,!1),o=(await this._sdk.FullClient.getBalance({owner:t,coinType:n.lp_token_type})).totalBalance;return await fi(this._sdk,o,n,r,t)}async getOwnerVaultsBalanceList(t){let{data:e}=await this.getPoolList(),n=[];for(let r=0;r<e.length;r++){let a=await this.getOwnerVaultsBalance(t,e[r].id);n.push(a)}return n}async getVaultsPositionRewarderAndFee(t,e,n=!0){try{let{pool:r,dlmmPool:a}=await this.getVaultAndPool(t,!1),o=`getVaultsV2PositionRewarderAndFee_${t}_${e}`,u=this._sdk.getCache(o);if(u)return u;let{lp_token_type:d}=r,{reward_manager:f,id:m,coin_type_a:_,coin_type_b:g}=a,C=new hn.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...f.rewards.map(x=>x.reward_coin)],lp_token_type:d,pool_id:t,certified_pool_id:m,position_id:e,coin_type_a:_,coin_type_b:g},C),n&&this.buildCollectFeePayload({lp_token_type:d,pool_id:t,certified_pool_id:m,position_id:e,coin_type_a:_,coin_type_b:g},C);let k=await this._sdk.FullClient.sendSimulationTransaction(C,(0,_r.normalizeSuiAddress)("0x0")),P=[],D=[];return k?.events.forEach(x=>{let{parsedJson:E,type:O}=x;O.includes("CollectDlmmFeeEvent")&&(P.push({coin_type:q(_,!1),value:E.amount_a}),P.push({coin_type:q(g,!1),value:E.amount_b})),O.includes("CollectDlmmRewardEvent")&&D.push({coin_type:q(E.reward_type.name,!1),value:E.amount})}),this._sdk.updateCache(o,{feeList:P,rewarderList:D},10*1e3),{feeList:P,rewarderList:D}}catch{}return{feeList:[],rewarderList:[]}}async getPoolList(t="all"){let e={data:[],has_next_page:!1},{vaultsV2:n}=this._sdk.sdkOptions,{FullClient:r}=this._sdk,a=await r.getDynamicFieldsByPage(n.configs.pools_handle,t),o=a.data.map(u=>u.name.value);if(o.length>0){let u=await this.getAssignPoolList(o);e.data.push(...u),e.next_cursor=a.next_cursor,e.has_next_page=a.has_next_page}return e}async getPool(t,e=!0){let n=`getPool_${t}`,r=this._sdk.getCache(n,e);if(r)return r;let a=await this.getAssignPoolList([t]);if(a.length>0){let o=a[0];return this._sdk.updateCache(n,o),o}throw new Error(`get pool failed ${t}`)}async getAssignPoolList(t){let e=[];if(t.length>0){(await this._sdk.FullClient.batchGetObjects(t,{showContent:!0})).forEach(a=>{let o=en(a.data.content);e.push(o)});let r=e.map(a=>a.id);if(r.length>0){let a=await this.geMarketList(r);e.forEach(o=>{let u=a[o.id];u&&(o.markets=[u])})}}return e}async geMarketList(t){let e={},n=t.map(o=>rn(o));(await this._sdk.FullClient.batchGetObjects(n,{showContent:!0})).forEach(o=>{let u=Yi(o?.data?.content);e[u.vault_id]=u});let a=Object.values(e);if(a.length>0){let o=0;for(let u of a){let d=await this.getMarketPositionList(u.positions_handle.id);a[o].position_list=d,o++}}return e}async getMarketPositionList(t){let e=[],r=(await this._sdk.FullClient.getDynamicFieldsByPage(t)).data.map(o=>o.objectId);return(await this._sdk.FullClient.batchGetObjects(r,{showContent:!0})).forEach(o=>{let u=tn(o?.data?.content);e.push(u)}),e}buildCollectRewardPayload(t,e){let{reward_coin_types:n,lp_token_type:r,pool_id:a,certified_pool_id:o,position_id:u,coin_type_a:d,coin_type_b:f,withdraw_cert:m}=t,{published_at:_,configs:g}=this._sdk.sdkOptions.vaultsV2,{dlmm_pool:C}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:k,global_config_id:P}=ve(C);m?n.forEach(D=>{e.moveCall({target:`${_}::vault::collect_dlmm_reward_on_withdraw`,typeArguments:[d,f,r,D],arguments:[e.object(a),m,e.object(o),e.object(u),e.object(P),e.object(k),e.object(g.versioned_id)]})}):n.forEach(D=>{e.moveCall({target:`${_}::vault::collect_dlmm_reward`,typeArguments:[d,f,r,D],arguments:[e.object(a),e.object(o),e.object(u),e.object(P),e.object(k),e.object(g.versioned_id)]})})}buildCollectFeePayload(t,e){let{lp_token_type:n,pool_id:r,certified_pool_id:a,position_id:o,coin_type_a:u,coin_type_b:d,withdraw_cert:f}=t,{published_at:m,configs:_}=this._sdk.sdkOptions.vaultsV2,{dlmm_pool:g}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:C,global_config_id:k}=ve(g);f?e.moveCall({target:`${m}::vault::collect_dlmm_fee_on_withdraw`,typeArguments:[u,d,n],arguments:[e.object(r),f,e.object(a),e.object(o),e.object(k),e.object(C),e.object(_.versioned_id)]}):e.moveCall({target:`${m}::vault::collect_dlmm_fee`,typeArguments:[u,d,n],arguments:[e.object(r),e.object(a),e.object(o),e.object(k),e.object(C),e.object(_.versioned_id)]})}async buildDepositPayload(t,e){let{published_at:n,configs:r}=this._sdk.sdkOptions.vaultsV2,{pool_id:a,amount_a:o,amount_b:u,return_lp_coin:d}=t,{pool:f,dlmmPool:m}=await this.getVaultAndPool(a,!1),{coin_type_a:_,coin_type_b:g,markets:C,lp_token_type:k}=f,{reward_manager:P,id:D}=m,x=C[0].position_list[0].position.id,{rewarderList:E}=await this.getVaultsPositionRewarderAndFee(a,x,!1),O=Ne(f.buffer_assets,E,[],_,g),T=E.length>0?E.filter(W=>S(W.value.toString()).gt(0)).map(W=>q(W.coin_type,!1)):P.rewards.map(W=>q(W.reward_coin,!1));this.buildCollectRewardPayload({reward_coin_types:T,lp_token_type:k,pool_id:a,certified_pool_id:C[0].position_list[0].position.pool_id,position_id:x,coin_type_a:_,coin_type_b:g},e),await this.pythPrice.buildUpdatePythPricePayload(O,e);let{dlmm_pool:H}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:N}=ve(H);e.moveCall({target:`${n}::vault::calculate_dlmm_position_amounts`,typeArguments:[_,g,k],arguments:[e.object(a),e.object(r.pyth_oracle_id),e.object(D),e.object(x),e.object(N),e.object(r.versioned_id),e.object(Zt)]}),e.moveCall({target:`${n}::vault::calculate_aum`,typeArguments:[k],arguments:[e.object(a),e.object(r.pyth_oracle_id),e.object(r.versioned_id),e.object(Zt)]});let G=Ht.buildCoinWithBalance(BigInt(o),_,e),$=Ht.buildCoinWithBalance(BigInt(u),g,e),z=e.moveCall({target:`${n}::vault::deposit`,typeArguments:[_,g,k],arguments:[e.object(a),e.object(r.global_config_id),e.object(r.pyth_oracle_id),G,$,e.object(Zt),e.object(r.versioned_id)]});if(d)return z;e.transferObjects([z],this._sdk.getVerifySenderAddress())}async buildWithdrawPayload(t,e){let{pool_id:n,burn_lp_amount:r,mode:a,slippage:o,partner:u,extra_burn:d}=t,{pool:f,dlmmPool:m}=await this.getVaultAndPool(n,!0),{lp_token_type:_,coin_type_a:g,coin_type_b:C,markets:k}=f,{id:P,reward_manager:D}=m,x=k[0].position_list[0].position.id;e=e||new hn.Transaction;let E,O=d?S(d.burn_lp_amount).add(S(r)).toFixed(0):S(r).toFixed(0),T=S(r).isZero();if(T&&!d)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");T?E=d.lp_burn_coin:(E=Ht.buildCoinWithBalance(BigInt(r),_,e),d&&d.lp_burn_coin&&e.mergeCoins(E,[d.lp_burn_coin]));let{published_at:H,configs:N}=this._sdk.sdkOptions.vaultsV2,{config:G}=this._sdk.CetusDlmmSDK.sdkOptions.dlmm_pool,$=e.moveCall({target:`${H}::vault::new_withdraw_cert`,typeArguments:[_],arguments:[e.object(n),E,e.object(N.versioned_id)]});e.moveCall({target:`${H}::vault::withdraw_dlmm`,typeArguments:[g,C,_],arguments:[e.object(n),$,e.object(P),e.object(x),e.object(G.global_config_id),e.object(G.versioned_id),e.object(N.versioned_id),e.object(Zt)]});let z=D.rewards.map(Q=>q(Q.reward_coin,!1));this.buildCollectRewardPayload({reward_coin_types:z,lp_token_type:_,pool_id:n,certified_pool_id:k[0].position_list[0].position.pool_id,position_id:x,coin_type_a:g,coin_type_b:C,withdraw_cert:$},e),this.buildCollectFeePayload({lp_token_type:_,pool_id:n,certified_pool_id:k[0].position_list[0].position.pool_id,position_id:x,coin_type_a:g,coin_type_b:C,withdraw_cert:$},e),e.moveCall({target:`${H}::vault::finalize_buffer_assets`,typeArguments:[_],arguments:[e.object(n),$,e.object(N.versioned_id)]});let W=new Set;z.forEach(Q=>W.add(Q)),W.add(g),W.add(C);let et=Array.from(W),qt=a!=="FixedOneSide"?[a==="OnlyCoinA"?C:g]:[],X=this.buildWithdrawBufferReward({reward_coin_types:et,pool_id:n,withdraw_cert:$,lp_token_type:_,not_transfer_coin_types:qt},e);if(e.moveCall({target:`${H}::vault::destroy_withdraw_cert`,typeArguments:[_],arguments:[e.object(n),$,e.object(N.versioned_id)]}),a!=="FixedOneSide"){if(o===void 0)throw Error("the slippage is undefined");let Q=a==="OnlyCoinA",s=Q?C:g,l=X.find(h=>h.coin_type===s).reward_coin_object_id;await this.handleWithSwap(e,l,g,C,O,n,Q,o,u)}}async handleWithSwap(t,e,n,r,a,o,u,d,f){let{receive_amount_a:m,receive_amount_b:_}=await this.preCalculateWithdrawAmount({pool_id:o,mode:"FixedOneSide",burn_lp_amount:a}),g=u?r:n,C=u?n:r,k=u?_:m,P={from:g,target:C,amount:new mr.default(k),byAmountIn:!0,depth:3,splitAlgorithm:void 0,splitFactor:void 0,splitCount:void 0,providers:this._sdk.sdkOptions.providers},D=await this._sdk.AggregatorClient.findRouters(P);if(!D)throw Error("not find Router");if(D.error!==void 0)throw Error(`find Router error : ${D.error}`);let x={router:D,inputCoin:e,slippage:d,txb:t,partner:f},E=await this._sdk.AggregatorClient.fixableRouterSwapV3(x);t.transferObjects([E],t.pure.address(this._sdk.getVerifySenderAddress()))}buildWithdrawBufferReward({reward_coin_types:t,pool_id:e,withdraw_cert:n,lp_token_type:r,not_transfer_coin_types:a},o){let{published_at:u,configs:d}=this._sdk.sdkOptions.vaultsV2;return t.map(f=>{let m=o.moveCall({target:`${u}::vault::withdraw_asset`,typeArguments:[r,f],arguments:[o.object(e),n,o.object(d.versioned_id)]});return a.includes(f)||o.transferObjects([m],o.pure.address(this._sdk.getVerifySenderAddress())),{coin_type:f,reward_coin_object_id:m}})}async preCalculateDepositValue(t,e){let{amount_usd:n,pool_id:r,mode:a,uuid:o}=t,{pool:u,dlmmPool:d}=await this.getVaultAndPool(r,!1),{coin_type_a:f,coin_type_b:m}=u,_=await this.pythPrice.getLatestPrice([f,m],!0),g=_[f],C=_[m];if(!g)throw new Error(`get ${f} price failed`);if(!C)throw new Error(`get ${m} price failed`);let k="0",P="0";switch(a){case"FlexibleBoth":{let{position_amount_a_rate:x,position_amount_b_rate:E}=await this.calculatePositionValueRates(u,d,_),{amountA:O,amountB:T}=ae(x,E,n,g.price,C.price,g.coin_decimals,C.coin_decimals);k=O,P=T;break}case"OnlyCoinA":{let{amountA:x,amountB:E}=ae(S(1),S(0),n,g.price,C.price,g.coin_decimals,C.coin_decimals);k=x,P=E;break}case"OnlyCoinB":{let{amountA:x,amountB:E}=ae(S(0),S(1),n,g.price,C.price,g.coin_decimals,C.coin_decimals);k=x,P=E;break}}return await this.preCalculateDepositAmount({mode:a,pool_id:r,uuid:o,coin_amount_a:k,coin_amount_b:P},e)}async preCalculateDepositAmount(t,e){let{mode:n,pool_id:r,uuid:a}=t,{pool:o,dlmmPool:u}=await this.getVaultAndPool(r,!1);switch(n){case"FixedOneSide":{let{fixed_amount:d,fixed_coin_a:f}=t;return await this.calculateDepositOtherSide(o,u,d,f,e,a)}case"FlexibleBoth":{let{coin_amount_a:d,coin_amount_b:f}=t;return await this.calculateDepositFlexibleBoth(o,u,d,f,e,a)}case"OnlyCoinA":{let{coin_amount_a:d}=t;return await this.calculateDepositFlexibleBoth(o,u,d,"0",e,a)}case"OnlyCoinB":{let{coin_amount_b:d}=t;return await this.calculateDepositFlexibleBoth(o,u,"0",d,e,a)}}throw new Error(`Unsupported deposit mode: ${n}`)}async getVaultAndPool(t,e=!1){let n=await this.getPool(t,e);if(n===void 0)throw new Error("get vaults pool failed");let r=n.markets[0].position_list[0].position.pool_id,a=await this._sdk.CetusDlmmSDK.Pool.getPool(r,e);if(a===void 0)throw new Error("get vaults dlmmPool failed");return{dlmmPool:a,pool:n}}async calculatePositionValueRates(t,e,n){let{lp_token_treasury:r,coin_type_a:a,coin_type_b:o}=t;if(S(r).eq(0))return{position_amount_a_rate:S(.5),position_amount_b_rate:S(.5)};let{position_amount_a:u,position_amount_b:d}=await fi(this._sdk,r,t,e,""),f=n[a],m=n[o];if(!f)throw Error(`not find ${a} price`);if(!m)throw Error(`not find ${o} price`);let _=S(ue(u,f.coin_decimals)).mul(f.price),g=S(ue(d,m.coin_decimals)).mul(m.price),C=S(_).add(g),k=S(_).div(C),P=S(1).sub(k);return{position_amount_a_rate:k,position_amount_b_rate:P}}async calculateDepositAmountsV2(t,e,n,r){let{markets:a}=t,o=a[0].position_list[0].position,u=await this._sdk.CetusDlmmSDK.Pool.getBinInfo(e.bin_manager.bin_manager_handle,e.active_id,e.bin_step,!1),d=Be.BinUtils.getPricePerLamportFromBinId(e.active_id,e.bin_step),f=S(d).mul(1-.05),m=S(d).mul(1+.05),_=Be.BinUtils.getBinIdFromLamportPrice(f.toString(),e.bin_step,!1),g=Be.BinUtils.getBinIdFromLamportPrice(m.toString(),e.bin_step,!1),C={pool_id:o.pool_id,coin_amount:S(r).mul(1e5).toFixed(0),fix_amount_a:n,active_id:e.active_id,bin_step:e.bin_step,lower_bin_id:_,upper_bin_id:g,strategy_type:Be.StrategyType.Spot,active_bin_of_pool:u},k=await this._sdk.CetusDlmmSDK.Position.calculateAddLiquidityInfo(C),{amount_a:P,amount_b:D}=k;return{deposit_amount_a:S(P).div(1e5).toFixed(0),deposit_amount_b:S(D).div(1e5).toFixed(0)}}async calculateDepositAmounts(t,e,n,r){let{coin_type_a:a,coin_type_b:o}=t,u=await this.pythPrice.getLatestPrice([a,o],!0),d=u[a],f=u[o];if(!d)throw Error(`not find ${a} price`);if(!f)throw Error(`not find ${o} price`);let m=S(ue(r,n?d.coin_decimals:f.coin_decimals));n?m=S(m).mul(d.price):m=S(m).mul(f.price);let{position_amount_a_rate:_,position_amount_b_rate:g}=await this.calculatePositionValueRates(t,e,u),C,k;if(n){let P=S(m).div(_);C=r,k=S(Qt(P.mul(g).div(f.price).toString(),f.coin_decimals)).toFixed(0,hi.default.ROUND_FLOOR)}else{let P=S(m).div(g);C=S(Qt(P.mul(_).div(d.price).toString(),d.coin_decimals)).toFixed(0,hi.default.ROUND_FLOOR),k=r}return{deposit_amount_a:C,deposit_amount_b:k}}async calculateDepositOtherSide(t,e,n,r,a,o){let{deposit_amount_a:u,deposit_amount_b:d}=await this.calculateDepositAmountsV2(t,e,r,n);if(a)this.calculateDepositLpAmountBoth(t,u,d).then(f=>{a.onSuccess(f,o)}).catch(f=>{a.onError(f,o)});else{let f=await this.calculateDepositLpAmountBoth(t,u,d);return{deposit_amount_a:u,deposit_amount_b:d,lp_amount:f,uuid:o,mode:"FixedOneSide"}}return{deposit_amount_a:u,deposit_amount_b:d,lp_amount:void 0,uuid:o,mode:"FixedOneSide"}}async calculateDepositFlexibleBoth(t,e,n,r,a,o){if(a)this.calculateDepositLpAmountBoth(t,n,r).then(u=>{a.onSuccess(u,o)}).catch(u=>{a.onError(u,o)});else{let u=await this.calculateDepositLpAmountBoth(t,n,r);return{deposit_amount_a:n,deposit_amount_b:r,lp_amount:u,uuid:o,mode:"FlexibleBoth"}}return{deposit_amount_a:n,deposit_amount_b:r,lp_amount:void 0,uuid:o,mode:"FlexibleBoth"}}async calculateDepositLpAmountBoth(t,e,n){let{lp_token_treasury:r,markets:a,quote_type:o,coin_type_a:u,coin_type_b:d}=t,f=q(u,!1),m=q(d,!1),{rewarderList:_,feeList:g}=await this.getVaultsPositionRewarderAndFee(t.id,a[0].position_list[0].position.id),C=De(t.buffer_assets,g,_),k=await nn(this._sdk,t,C,!0),P=await this.pythPrice.getLatestPrice([f,m],!0),D=P[f],x=P[m];if(!D)throw Error(`not find ${f} price`);if(!x)throw Error(`not find ${m} price`);let E={};E[f]={price:D,value:e.toString()},E[m]={price:x,value:n.toString()};let O=ye(E,o);return Re(r,O,k)}async preCalculateWithdrawAmount(t){let{mode:e,pool_id:n}=t,{pool:r,dlmmPool:a}=await this.getVaultAndPool(n,!1);switch(e){case"FixedOneSide":{let{burn_lp_amount:o}=t;return await this.calculateWithdrawOtherSide(r,a,o)}case"OnlyCoinA":return await this.calculateWithdrawOnlyCoin(r,a,t.burn_lp_amount,!0);case"OnlyCoinB":return await this.calculateWithdrawOnlyCoin(r,a,t.burn_lp_amount,!1)}throw new Error(`Unsupported withdraw mode: ${e}`)}async calculateWithdrawOtherSide(t,e,n){let{receive_amount_a:r,receive_amount_b:a}=await Ue(this._sdk,n,t,e);return{receive_amount_a:r,receive_amount_b:a,burn_lp_amount:n,mode:"FixedOneSide"}}async calculateWithdrawOnlyCoin(t,e,n,r){let{totalReceiveAmount:a,swapAmountIn:o,swapAmountOut:u}=await this.calculateWithdrawOnlyCoinByLpAmount(t,e,r,n);return{receive_amount_a:r?a:"0",receive_amount_b:r?"0":a,burn_lp_amount:n,swap:{swap_amount_in:o,swap_amount_out:u},mode:r?"OnlyCoinA":"OnlyCoinB"}}async calculateWithdrawOnlyCoinByLpAmount(t,e,n,r){let{coin_type_a:a,coin_type_b:o}=t,{receive_amount_a:u,receive_amount_b:d}=await Ue(this._sdk,r,t,e),f=await this.pythPrice.getLatestPrice([a,o],!0),m=f[a],_=f[o];if(!m)throw Error(`not find ${a} price`);if(!_)throw Error(`not find ${o} price`);let g=n?_:m,C=n?m:_,{quote_per_base:k}=qe(g.price,C.price),P=n?u:d,D=n?d:u,x=Qt(S(ue(D,n?_.coin_decimals:m.coin_decimals)).mul(k).toString(),n?m.coin_decimals:_.coin_decimals).toString(),E=S(P).add(x).toFixed(0);return{burn_lp_amount:r,is_coin_a:n,originAmount:P,swapAmountIn:D,swapAmountOut:S(x).toFixed(0,hi.default.ROUND_DOWN),totalReceiveAmount:E}}async getPackageConfigs(){let t={registry_id:"1",pools_handle:"",pyth_oracle_id:"1",oracle_infos_handle:"",prices_handle:"1",global_config_id:"1"},{package_id:e}=this._sdk.sdkOptions.vaults,n=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),r=oi(n);(await this._sdk.FullClient.queryEventsByPage({Transaction:r})).data.forEach(m=>{let _=m.parsedJson;if(m.type)switch((0,pr.extractStructTagFromType)(m.type).full_address){case`${e}::pool::InitEvent`:t.registry_id=_.registry_id;break;case`${e}::pyth_oracle::InitEvent`:t.pyth_oracle_id=_.pyth_oracle_id;break;case`${e}::config::InitConfigEvent`:t.global_config_id=_.global_config;break;default:break}});let o=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),u=ie(o);t.pools_handle=u.pools.fields.id.id;let d=await this._sdk.FullClient.getObject({id:t.pyth_oracle_id,options:{showContent:!0}}),f=ie(d);return t.oracle_infos_handle=f.oracle_infos.fields.id.id,t.prices_handle=f.prices.fields.id.id,this._sdk.sdkOptions.vaults.configs=t,this._sdk.sdkOptions}};var br=ne(require("@cetusprotocol/dlmm-sdk")),fe=class{_sdkOptions;_senderAddress="";_vaults;_vaultsV2;_aggregatorClient;_vest;_cetusClmmSDK;_cetusDlmmSDK;constructor(t){(!t.providers||t.providers.length===0)&&(t.providers=dn),this._sdkOptions=t,this._cetusClmmSDK=t.env==="testnet"?mn.CetusClmmSDK.createSDK({env:"testnet",full_rpc_url:t.fullRpcUrl}):mn.CetusClmmSDK.createSDK({env:"mainnet",full_rpc_url:t.fullRpcUrl}),this._cetusDlmmSDK=br.default.createSDK({env:t.env,full_rpc_url:t.fullRpcUrl}),this._vaults=new $e(this),this._vaultsV2=new We(this);let{primary:e,secondary:n}=t.pythConfigs.hermes_service_urls,r=[e,n].filter(Boolean);this._aggregatorClient=new Ze.AggregatorClient({endpoint:t.aggregatorUrl,signer:(0,mi.normalizeSuiAddress)("0x0"),client:new gr.SuiClient({url:t.fullRpcUrl}),env:t.env==="testnet"?Ze.Env.Testnet:Ze.Env.Mainnet,pythUrls:r}),this._vest=new Ke(this)}get senderAddress(){return this._senderAddress}set senderAddress(t){this._senderAddress=t,this.CetusClmmSDK.setSenderAddress(t)}get sdkOptions(){return this._sdkOptions}get Vaults(){return this._vaults}get VaultsV2(){return this._vaultsV2}get FullClient(){return this._cetusClmmSDK.FullClient}get AggregatorClient(){return this._aggregatorClient}get CetusClmmSDK(){return this._cetusClmmSDK}get CetusDlmmSDK(){return this._cetusDlmmSDK}get Vest(){return this._vest}getVerifySenderAddress(){if(this.senderAddress.length===0||!(0,mi.isValidSuiAddress)(this.senderAddress))throw Error("this sdk senderAddress is illegal");return this.senderAddress}async getOwnerCoinAssets(t,e){return await this._cetusClmmSDK.FullClient.getOwnerCoinAssets(t,e)}async getOwnerCoinBalances(t,e){return await this._cetusClmmSDK.FullClient.getOwnerCoinBalances(t,e)}updateCache(t,e,n=$n){this.CetusClmmSDK.updateCache(t,e,n)}getCache(t,e=!1){return this.CetusClmmSDK.getCache(t,e)}};var ds=fe;0&&(module.exports={PythPriceModule,SdkEnv,VaultsModule,VaultsModuleV2,VestModule,VolatileVaultsSDK,buildDLMMMarket,buildDLMMMarketId,buildDLMMMarketPosition,buildDLMMPositionId,buildPoolData,buildPoolV2Data,buildVaultsBalance,buildVaultsBalanceV2,calculateAum,calculateAumV2,calculateDepositRatioFixTokenA,calculateTotalAumBasedOnQuote,checkIsMinOrMaxIndex,convertU64BytesToDecimal,defaultProvider,estCoinAmountsFromTotalAmount,feed_map_mainnet,feed_map_testnet,getAmountBalanceByLpAmount,getCoinAmountsFromRatio,getPositionPriceRange,getPriceWithFormattedDecimals,getPrimitivePricesFromBaseQuote,getQuotePerBaseAndBasePerQuote,getShareBufferAssets,getUpdatePriceType,getVaultValidBalances,get_lp_amount_by_liquidity,get_lp_amount_by_tvl,get_share_liquidity_by_amount,initMainnetSDK,initTestnetSDK,initVaultSDK,oraclePriceMultiplierDecimal,parseVaultVestNFT,parseVaultsVestInfo,printTransaction,toSuiObjectId,vaults_mainnet,vaults_testnet});
1
+ "use strict";var wr=Object.create;var ze=Object.defineProperty;var vr=Object.getOwnPropertyDescriptor;var yr=Object.getOwnPropertyNames;var Mr=Object.getPrototypeOf,Cr=Object.prototype.hasOwnProperty;var kr=(i,t)=>{for(var e in t)ze(i,e,{get:t[e],enumerable:!0})},Tn=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of yr(t))!Cr.call(i,r)&&r!==e&&ze(i,r,{get:()=>t[r],enumerable:!(n=vr(t,r))||n.enumerable});return i};var ne=(i,t,e)=>(e=i!=null?wr(Mr(i)):{},Tn(t||!i||!i.__esModule?ze(e,"default",{value:i,enumerable:!0}):e,i)),Pr=i=>Tn(ze({},"__esModule",{value:!0}),i);var fs={};kr(fs,{PythPriceModule:()=>Se,SdkEnv:()=>cr,VaultsModule:()=>$e,VaultsModuleV2:()=>We,VestModule:()=>Ke,VolatileVaultsSDK:()=>fe,buildDLMMMarket:()=>Yi,buildDLMMMarketId:()=>rn,buildDLMMMarketPosition:()=>tn,buildDLMMPositionId:()=>cs,buildPoolData:()=>ci,buildPoolV2Data:()=>en,buildVaultsBalance:()=>Xi,buildVaultsBalanceV2:()=>fi,calculateAum:()=>zi,calculateAumV2:()=>nn,calculateDepositRatioFixTokenA:()=>or,calculateTotalAumBasedOnQuote:()=>ye,checkIsMinOrMaxIndex:()=>si,convertU64BytesToDecimal:()=>ns,default:()=>ds,defaultProvider:()=>dn,estCoinAmountsFromTotalAmount:()=>Zi,feed_map_mainnet:()=>sn,feed_map_testnet:()=>ln,getAmountBalanceByLpAmount:()=>Ue,getCoinAmountsFromRatio:()=>ae,getPositionPriceRange:()=>ss,getPriceWithFormattedDecimals:()=>Hi,getPrimitivePricesFromBaseQuote:()=>sr,getQuotePerBaseAndBasePerQuote:()=>qe,getShareBufferAssets:()=>Pe,getUpdatePriceType:()=>Ne,getVaultValidBalances:()=>De,get_lp_amount_by_liquidity:()=>os,get_lp_amount_by_tvl:()=>Re,get_share_liquidity_by_amount:()=>ke,initMainnetSDK:()=>an,initTestnetSDK:()=>un,initVaultSDK:()=>ls,oraclePriceMultiplierDecimal:()=>Ce,parseVaultVestNFT:()=>Qi,parseVaultsVestInfo:()=>li,printTransaction:()=>rs,toSuiObjectId:()=>Gi,vaults_mainnet:()=>on,vaults_testnet:()=>cn});module.exports=Pr(fs);var gr=require("@mysten/sui/client"),mi=require("@mysten/sui/utils"),Ze=require("@cetusprotocol/aggregator-sdk");var Vr=require("@mysten/sui/utils"),Lr=require("@mysten/sui/client"),jr=require("@mysten/sui/utils"),qr=require("@mysten/sui/keypairs/ed25519"),Rr=require("@mysten/sui/keypairs/secp256k1"),Me=require("@mysten/sui/utils"),Fi=require("@mysten/sui/transactions"),Lo=require("@mysten/sui/bcs"),jo=require("@mysten/sui/utils"),qo=require("@mysten/sui/graphql/schemas/latest"),Ro=require("@mysten/sui/graphql"),Ni=require("@mysten/sui/client"),Sr=Object.create,Nn=Object.defineProperty,Ar=Object.getOwnPropertyDescriptor,Or=Object.getOwnPropertyNames,xr=Object.getPrototypeOf,Dr=Object.prototype.hasOwnProperty,Er=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')}),Tr=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Br=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Or(t))!Dr.call(i,r)&&r!==e&&Nn(i,r,{get:()=>t[r],enumerable:!(n=Ar(t,r))||n.enumerable});return i},Ie=(i,t,e)=>(e=i!=null?Sr(xr(i)):{},Br(t||!i||!i.__esModule?Nn(e,"default",{value:i,enumerable:!0}):e,i)),Le=Tr((i,t)=>{"use strict";(function(e,n){"use strict";function r(s,l){if(!s)throw new Error(l||"Assertion failed")}function a(s,l){s.super_=l;var h=function(){};h.prototype=l.prototype,s.prototype=new h,s.prototype.constructor=s}function o(s,l,h){if(o.isBN(s))return s;this.negative=0,this.words=null,this.length=0,this.red=null,s!==null&&((l==="le"||l==="be")&&(h=l,l=10),this._init(s||0,l||10,h||"be"))}typeof e=="object"?e.exports=o:n.BN=o,o.BN=o,o.wordSize=26;var u;try{typeof window<"u"&&typeof window.Buffer<"u"?u=window.Buffer:u=Er("buffer").Buffer}catch{}o.isBN=function(s){return s instanceof o?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===o.wordSize&&Array.isArray(s.words)},o.max=function(s,l){return s.cmp(l)>0?s:l},o.min=function(s,l){return s.cmp(l)<0?s:l},o.prototype._init=function(s,l,h){if(typeof s=="number")return this._initNumber(s,l,h);if(typeof s=="object")return this._initArray(s,l,h);l==="hex"&&(l=16),r(l===(l|0)&&l>=2&&l<=36),s=s.toString().replace(/\s+/g,"");var p=0;s[0]==="-"&&(p++,this.negative=1),p<s.length&&(l===16?this._parseHex(s,p,h):(this._parseBase(s,l,p),h==="le"&&this._initArray(this.toArray(),l,h)))},o.prototype._initNumber=function(s,l,h){s<0&&(this.negative=1,s=-s),s<67108864?(this.words=[s&67108863],this.length=1):s<4503599627370496?(this.words=[s&67108863,s/67108864&67108863],this.length=2):(r(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),l,h)},o.prototype._initArray=function(s,l,h){if(r(typeof s.length=="number"),s.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(s.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var w,y,M=0;if(h==="be")for(p=s.length-1,w=0;p>=0;p-=3)y=s[p]|s[p-1]<<8|s[p-2]<<16,this.words[w]|=y<<M&67108863,this.words[w+1]=y>>>26-M&67108863,M+=24,M>=26&&(M-=26,w++);else if(h==="le")for(p=0,w=0;p<s.length;p+=3)y=s[p]|s[p+1]<<8|s[p+2]<<16,this.words[w]|=y<<M&67108863,this.words[w+1]=y>>>26-M&67108863,M+=24,M>=26&&(M-=26,w++);return this._strip()};function d(s,l){var h=s.charCodeAt(l);if(h>=48&&h<=57)return h-48;if(h>=65&&h<=70)return h-55;if(h>=97&&h<=102)return h-87;r(!1,"Invalid character in "+s)}function f(s,l,h){var p=d(s,h);return h-1>=l&&(p|=d(s,h-1)<<4),p}o.prototype._parseHex=function(s,l,h){this.length=Math.ceil((s.length-l)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var w=0,y=0,M;if(h==="be")for(p=s.length-1;p>=l;p-=2)M=f(s,l,p)<<w,this.words[y]|=M&67108863,w>=18?(w-=18,y+=1,this.words[y]|=M>>>26):w+=8;else{var b=s.length-l;for(p=b%2===0?l+1:l;p<s.length;p+=2)M=f(s,l,p)<<w,this.words[y]|=M&67108863,w>=18?(w-=18,y+=1,this.words[y]|=M>>>26):w+=8}this._strip()};function m(s,l,h,p){for(var w=0,y=0,M=Math.min(s.length,h),b=l;b<M;b++){var c=s.charCodeAt(b)-48;w*=p,c>=49?y=c-49+10:c>=17?y=c-17+10:y=c,r(c>=0&&y<p,"Invalid character"),w+=y}return w}o.prototype._parseBase=function(s,l,h){this.words=[0],this.length=1;for(var p=0,w=1;w<=67108863;w*=l)p++;p--,w=w/l|0;for(var y=s.length-h,M=y%p,b=Math.min(y,y-M)+h,c=0,v=h;v<b;v+=p)c=m(s,v,v+p,l),this.imuln(w),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(M!==0){var B=1;for(c=m(s,v,s.length,l),v=0;v<M;v++)B*=l;this.imuln(B),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},o.prototype.copy=function(s){s.words=new Array(this.length);for(var l=0;l<this.length;l++)s.words[l]=this.words[l];s.length=this.length,s.negative=this.negative,s.red=this.red};function _(s,l){s.words=l.words,s.length=l.length,s.negative=l.negative,s.red=l.red}if(o.prototype._move=function(s){_(s,this)},o.prototype.clone=function(){var s=new o(null);return this.copy(s),s},o.prototype._expand=function(s){for(;this.length<s;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=g}catch{o.prototype.inspect=g}else o.prototype.inspect=g;function g(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var C=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],k=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],P=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(s,l){s=s||10,l=l|0||1;var h;if(s===16||s==="hex"){h="";for(var p=0,w=0,y=0;y<this.length;y++){var M=this.words[y],b=((M<<p|w)&16777215).toString(16);w=M>>>24-p&16777215,p+=2,p>=26&&(p-=26,y--),w!==0||y!==this.length-1?h=C[6-b.length]+b+h:h=b+h}for(w!==0&&(h=w.toString(16)+h);h.length%l!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(s===(s|0)&&s>=2&&s<=36){var c=k[s],v=P[s];h="";var B=this.clone();for(B.negative=0;!B.isZero();){var V=B.modrn(v).toString(s);B=B.idivn(v),B.isZero()?h=V+h:h=C[c-V.length]+V+h}for(this.isZero()&&(h="0"+h);h.length%l!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}r(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var s=this.words[0];return this.length===2?s+=this.words[1]*67108864:this.length===3&&this.words[2]===1?s+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},o.prototype.toJSON=function(){return this.toString(16,2)},u&&(o.prototype.toBuffer=function(s,l){return this.toArrayLike(u,s,l)}),o.prototype.toArray=function(s,l){return this.toArrayLike(Array,s,l)};var D=function(s,l){return s.allocUnsafe?s.allocUnsafe(l):new s(l)};o.prototype.toArrayLike=function(s,l,h){this._strip();var p=this.byteLength(),w=h||Math.max(1,p);r(p<=w,"byte array longer than desired length"),r(w>0,"Requested array length <= 0");var y=D(s,w),M=l==="le"?"LE":"BE";return this["_toArrayLike"+M](y,p),y},o.prototype._toArrayLikeLE=function(s,l){for(var h=0,p=0,w=0,y=0;w<this.length;w++){var M=this.words[w]<<y|p;s[h++]=M&255,h<s.length&&(s[h++]=M>>8&255),h<s.length&&(s[h++]=M>>16&255),y===6?(h<s.length&&(s[h++]=M>>24&255),p=0,y=0):(p=M>>>24,y+=2)}if(h<s.length)for(s[h++]=p;h<s.length;)s[h++]=0},o.prototype._toArrayLikeBE=function(s,l){for(var h=s.length-1,p=0,w=0,y=0;w<this.length;w++){var M=this.words[w]<<y|p;s[h--]=M&255,h>=0&&(s[h--]=M>>8&255),h>=0&&(s[h--]=M>>16&255),y===6?(h>=0&&(s[h--]=M>>24&255),p=0,y=0):(p=M>>>24,y+=2)}if(h>=0)for(s[h--]=p;h>=0;)s[h--]=0},Math.clz32?o.prototype._countBits=function(s){return 32-Math.clz32(s)}:o.prototype._countBits=function(s){var l=s,h=0;return l>=4096&&(h+=13,l>>>=13),l>=64&&(h+=7,l>>>=7),l>=8&&(h+=4,l>>>=4),l>=2&&(h+=2,l>>>=2),h+l},o.prototype._zeroBits=function(s){if(s===0)return 26;var l=s,h=0;return!(l&8191)&&(h+=13,l>>>=13),!(l&127)&&(h+=7,l>>>=7),!(l&15)&&(h+=4,l>>>=4),!(l&3)&&(h+=2,l>>>=2),!(l&1)&&h++,h},o.prototype.bitLength=function(){var s=this.words[this.length-1],l=this._countBits(s);return(this.length-1)*26+l};function x(s){for(var l=new Array(s.bitLength()),h=0;h<l.length;h++){var p=h/26|0,w=h%26;l[h]=s.words[p]>>>w&1}return l}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,l=0;l<this.length;l++){var h=this._zeroBits(this.words[l]);if(s+=h,h!==26)break}return s},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},o.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var l=0;l<s.length;l++)this.words[l]=this.words[l]|s.words[l];return this._strip()},o.prototype.ior=function(s){return r((this.negative|s.negative)===0),this.iuor(s)},o.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},o.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},o.prototype.iuand=function(s){var l;this.length>s.length?l=s:l=this;for(var h=0;h<l.length;h++)this.words[h]=this.words[h]&s.words[h];return this.length=l.length,this._strip()},o.prototype.iand=function(s){return r((this.negative|s.negative)===0),this.iuand(s)},o.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},o.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},o.prototype.iuxor=function(s){var l,h;this.length>s.length?(l=this,h=s):(l=s,h=this);for(var p=0;p<h.length;p++)this.words[p]=l.words[p]^h.words[p];if(this!==l)for(;p<l.length;p++)this.words[p]=l.words[p];return this.length=l.length,this._strip()},o.prototype.ixor=function(s){return r((this.negative|s.negative)===0),this.iuxor(s)},o.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},o.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},o.prototype.inotn=function(s){r(typeof s=="number"&&s>=0);var l=Math.ceil(s/26)|0,h=s%26;this._expand(l),h>0&&l--;for(var p=0;p<l;p++)this.words[p]=~this.words[p]&67108863;return h>0&&(this.words[p]=~this.words[p]&67108863>>26-h),this._strip()},o.prototype.notn=function(s){return this.clone().inotn(s)},o.prototype.setn=function(s,l){r(typeof s=="number"&&s>=0);var h=s/26|0,p=s%26;return this._expand(h+1),l?this.words[h]=this.words[h]|1<<p:this.words[h]=this.words[h]&~(1<<p),this._strip()},o.prototype.iadd=function(s){var l;if(this.negative!==0&&s.negative===0)return this.negative=0,l=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,l=this.isub(s),s.negative=1,l._normSign();var h,p;this.length>s.length?(h=this,p=s):(h=s,p=this);for(var w=0,y=0;y<p.length;y++)l=(h.words[y]|0)+(p.words[y]|0)+w,this.words[y]=l&67108863,w=l>>>26;for(;w!==0&&y<h.length;y++)l=(h.words[y]|0)+w,this.words[y]=l&67108863,w=l>>>26;if(this.length=h.length,w!==0)this.words[this.length]=w,this.length++;else if(h!==this)for(;y<h.length;y++)this.words[y]=h.words[y];return this},o.prototype.add=function(s){var l;return s.negative!==0&&this.negative===0?(s.negative=0,l=this.sub(s),s.negative^=1,l):s.negative===0&&this.negative!==0?(this.negative=0,l=s.sub(this),this.negative=1,l):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},o.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var l=this.iadd(s);return s.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var h=this.cmp(s);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,w;h>0?(p=this,w=s):(p=s,w=this);for(var y=0,M=0;M<w.length;M++)l=(p.words[M]|0)-(w.words[M]|0)+y,y=l>>26,this.words[M]=l&67108863;for(;y!==0&&M<p.length;M++)l=(p.words[M]|0)+y,y=l>>26,this.words[M]=l&67108863;if(y===0&&M<p.length&&p!==this)for(;M<p.length;M++)this.words[M]=p.words[M];return this.length=Math.max(this.length,M),p!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(s){return this.clone().isub(s)};function E(s,l,h){h.negative=l.negative^s.negative;var p=s.length+l.length|0;h.length=p,p=p-1|0;var w=s.words[0]|0,y=l.words[0]|0,M=w*y,b=M&67108863,c=M/67108864|0;h.words[0]=b;for(var v=1;v<p;v++){for(var B=c>>>26,V=c&67108863,I=Math.min(v,l.length-1),U=Math.max(0,v-s.length+1);U<=I;U++){var Z=v-U|0;w=s.words[Z]|0,y=l.words[U]|0,M=w*y+V,B+=M/67108864|0,V=M&67108863}h.words[v]=V|0,c=B|0}return c!==0?h.words[v]=c|0:h.length--,h._strip()}var O=function(s,l,h){var p=s.words,w=l.words,y=h.words,M=0,b,c,v,B=p[0]|0,V=B&8191,I=B>>>13,U=p[1]|0,Z=U&8191,Y=U>>>13,me=p[2]|0,tt=me&8191,it=me>>>13,pn=p[3]|0,rt=pn&8191,ot=pn>>>13,_n=p[4]|0,st=_n&8191,at=_n>>>13,gn=p[5]|0,ct=gn&8191,lt=gn>>>13,bn=p[6]|0,ut=bn&8191,dt=bn>>>13,wn=p[7]|0,ft=wn&8191,ht=wn>>>13,vn=p[8]|0,mt=vn&8191,pt=vn>>>13,yn=p[9]|0,_t=yn&8191,gt=yn>>>13,Mn=w[0]|0,bt=Mn&8191,wt=Mn>>>13,Cn=w[1]|0,vt=Cn&8191,yt=Cn>>>13,kn=w[2]|0,Mt=kn&8191,Ct=kn>>>13,Pn=w[3]|0,kt=Pn&8191,Pt=Pn>>>13,Sn=w[4]|0,St=Sn&8191,At=Sn>>>13,An=w[5]|0,Ot=An&8191,xt=An>>>13,On=w[6]|0,Dt=On&8191,Et=On>>>13,xn=w[7]|0,Tt=xn&8191,Bt=xn>>>13,Dn=w[8]|0,Vt=Dn&8191,Ft=Dn>>>13,En=w[9]|0,It=En&8191,Lt=En>>>13;h.negative=s.negative^l.negative,h.length=19,b=Math.imul(V,bt),c=Math.imul(V,wt),c=c+Math.imul(I,bt)|0,v=Math.imul(I,wt);var pi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(pi>>>26)|0,pi&=67108863,b=Math.imul(Z,bt),c=Math.imul(Z,wt),c=c+Math.imul(Y,bt)|0,v=Math.imul(Y,wt),b=b+Math.imul(V,vt)|0,c=c+Math.imul(V,yt)|0,c=c+Math.imul(I,vt)|0,v=v+Math.imul(I,yt)|0;var _i=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(_i>>>26)|0,_i&=67108863,b=Math.imul(tt,bt),c=Math.imul(tt,wt),c=c+Math.imul(it,bt)|0,v=Math.imul(it,wt),b=b+Math.imul(Z,vt)|0,c=c+Math.imul(Z,yt)|0,c=c+Math.imul(Y,vt)|0,v=v+Math.imul(Y,yt)|0,b=b+Math.imul(V,Mt)|0,c=c+Math.imul(V,Ct)|0,c=c+Math.imul(I,Mt)|0,v=v+Math.imul(I,Ct)|0;var gi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,b=Math.imul(rt,bt),c=Math.imul(rt,wt),c=c+Math.imul(ot,bt)|0,v=Math.imul(ot,wt),b=b+Math.imul(tt,vt)|0,c=c+Math.imul(tt,yt)|0,c=c+Math.imul(it,vt)|0,v=v+Math.imul(it,yt)|0,b=b+Math.imul(Z,Mt)|0,c=c+Math.imul(Z,Ct)|0,c=c+Math.imul(Y,Mt)|0,v=v+Math.imul(Y,Ct)|0,b=b+Math.imul(V,kt)|0,c=c+Math.imul(V,Pt)|0,c=c+Math.imul(I,kt)|0,v=v+Math.imul(I,Pt)|0;var bi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,b=Math.imul(st,bt),c=Math.imul(st,wt),c=c+Math.imul(at,bt)|0,v=Math.imul(at,wt),b=b+Math.imul(rt,vt)|0,c=c+Math.imul(rt,yt)|0,c=c+Math.imul(ot,vt)|0,v=v+Math.imul(ot,yt)|0,b=b+Math.imul(tt,Mt)|0,c=c+Math.imul(tt,Ct)|0,c=c+Math.imul(it,Mt)|0,v=v+Math.imul(it,Ct)|0,b=b+Math.imul(Z,kt)|0,c=c+Math.imul(Z,Pt)|0,c=c+Math.imul(Y,kt)|0,v=v+Math.imul(Y,Pt)|0,b=b+Math.imul(V,St)|0,c=c+Math.imul(V,At)|0,c=c+Math.imul(I,St)|0,v=v+Math.imul(I,At)|0;var wi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,b=Math.imul(ct,bt),c=Math.imul(ct,wt),c=c+Math.imul(lt,bt)|0,v=Math.imul(lt,wt),b=b+Math.imul(st,vt)|0,c=c+Math.imul(st,yt)|0,c=c+Math.imul(at,vt)|0,v=v+Math.imul(at,yt)|0,b=b+Math.imul(rt,Mt)|0,c=c+Math.imul(rt,Ct)|0,c=c+Math.imul(ot,Mt)|0,v=v+Math.imul(ot,Ct)|0,b=b+Math.imul(tt,kt)|0,c=c+Math.imul(tt,Pt)|0,c=c+Math.imul(it,kt)|0,v=v+Math.imul(it,Pt)|0,b=b+Math.imul(Z,St)|0,c=c+Math.imul(Z,At)|0,c=c+Math.imul(Y,St)|0,v=v+Math.imul(Y,At)|0,b=b+Math.imul(V,Ot)|0,c=c+Math.imul(V,xt)|0,c=c+Math.imul(I,Ot)|0,v=v+Math.imul(I,xt)|0;var vi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,b=Math.imul(ut,bt),c=Math.imul(ut,wt),c=c+Math.imul(dt,bt)|0,v=Math.imul(dt,wt),b=b+Math.imul(ct,vt)|0,c=c+Math.imul(ct,yt)|0,c=c+Math.imul(lt,vt)|0,v=v+Math.imul(lt,yt)|0,b=b+Math.imul(st,Mt)|0,c=c+Math.imul(st,Ct)|0,c=c+Math.imul(at,Mt)|0,v=v+Math.imul(at,Ct)|0,b=b+Math.imul(rt,kt)|0,c=c+Math.imul(rt,Pt)|0,c=c+Math.imul(ot,kt)|0,v=v+Math.imul(ot,Pt)|0,b=b+Math.imul(tt,St)|0,c=c+Math.imul(tt,At)|0,c=c+Math.imul(it,St)|0,v=v+Math.imul(it,At)|0,b=b+Math.imul(Z,Ot)|0,c=c+Math.imul(Z,xt)|0,c=c+Math.imul(Y,Ot)|0,v=v+Math.imul(Y,xt)|0,b=b+Math.imul(V,Dt)|0,c=c+Math.imul(V,Et)|0,c=c+Math.imul(I,Dt)|0,v=v+Math.imul(I,Et)|0;var yi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,b=Math.imul(ft,bt),c=Math.imul(ft,wt),c=c+Math.imul(ht,bt)|0,v=Math.imul(ht,wt),b=b+Math.imul(ut,vt)|0,c=c+Math.imul(ut,yt)|0,c=c+Math.imul(dt,vt)|0,v=v+Math.imul(dt,yt)|0,b=b+Math.imul(ct,Mt)|0,c=c+Math.imul(ct,Ct)|0,c=c+Math.imul(lt,Mt)|0,v=v+Math.imul(lt,Ct)|0,b=b+Math.imul(st,kt)|0,c=c+Math.imul(st,Pt)|0,c=c+Math.imul(at,kt)|0,v=v+Math.imul(at,Pt)|0,b=b+Math.imul(rt,St)|0,c=c+Math.imul(rt,At)|0,c=c+Math.imul(ot,St)|0,v=v+Math.imul(ot,At)|0,b=b+Math.imul(tt,Ot)|0,c=c+Math.imul(tt,xt)|0,c=c+Math.imul(it,Ot)|0,v=v+Math.imul(it,xt)|0,b=b+Math.imul(Z,Dt)|0,c=c+Math.imul(Z,Et)|0,c=c+Math.imul(Y,Dt)|0,v=v+Math.imul(Y,Et)|0,b=b+Math.imul(V,Tt)|0,c=c+Math.imul(V,Bt)|0,c=c+Math.imul(I,Tt)|0,v=v+Math.imul(I,Bt)|0;var Mi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,b=Math.imul(mt,bt),c=Math.imul(mt,wt),c=c+Math.imul(pt,bt)|0,v=Math.imul(pt,wt),b=b+Math.imul(ft,vt)|0,c=c+Math.imul(ft,yt)|0,c=c+Math.imul(ht,vt)|0,v=v+Math.imul(ht,yt)|0,b=b+Math.imul(ut,Mt)|0,c=c+Math.imul(ut,Ct)|0,c=c+Math.imul(dt,Mt)|0,v=v+Math.imul(dt,Ct)|0,b=b+Math.imul(ct,kt)|0,c=c+Math.imul(ct,Pt)|0,c=c+Math.imul(lt,kt)|0,v=v+Math.imul(lt,Pt)|0,b=b+Math.imul(st,St)|0,c=c+Math.imul(st,At)|0,c=c+Math.imul(at,St)|0,v=v+Math.imul(at,At)|0,b=b+Math.imul(rt,Ot)|0,c=c+Math.imul(rt,xt)|0,c=c+Math.imul(ot,Ot)|0,v=v+Math.imul(ot,xt)|0,b=b+Math.imul(tt,Dt)|0,c=c+Math.imul(tt,Et)|0,c=c+Math.imul(it,Dt)|0,v=v+Math.imul(it,Et)|0,b=b+Math.imul(Z,Tt)|0,c=c+Math.imul(Z,Bt)|0,c=c+Math.imul(Y,Tt)|0,v=v+Math.imul(Y,Bt)|0,b=b+Math.imul(V,Vt)|0,c=c+Math.imul(V,Ft)|0,c=c+Math.imul(I,Vt)|0,v=v+Math.imul(I,Ft)|0;var Ci=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,b=Math.imul(_t,bt),c=Math.imul(_t,wt),c=c+Math.imul(gt,bt)|0,v=Math.imul(gt,wt),b=b+Math.imul(mt,vt)|0,c=c+Math.imul(mt,yt)|0,c=c+Math.imul(pt,vt)|0,v=v+Math.imul(pt,yt)|0,b=b+Math.imul(ft,Mt)|0,c=c+Math.imul(ft,Ct)|0,c=c+Math.imul(ht,Mt)|0,v=v+Math.imul(ht,Ct)|0,b=b+Math.imul(ut,kt)|0,c=c+Math.imul(ut,Pt)|0,c=c+Math.imul(dt,kt)|0,v=v+Math.imul(dt,Pt)|0,b=b+Math.imul(ct,St)|0,c=c+Math.imul(ct,At)|0,c=c+Math.imul(lt,St)|0,v=v+Math.imul(lt,At)|0,b=b+Math.imul(st,Ot)|0,c=c+Math.imul(st,xt)|0,c=c+Math.imul(at,Ot)|0,v=v+Math.imul(at,xt)|0,b=b+Math.imul(rt,Dt)|0,c=c+Math.imul(rt,Et)|0,c=c+Math.imul(ot,Dt)|0,v=v+Math.imul(ot,Et)|0,b=b+Math.imul(tt,Tt)|0,c=c+Math.imul(tt,Bt)|0,c=c+Math.imul(it,Tt)|0,v=v+Math.imul(it,Bt)|0,b=b+Math.imul(Z,Vt)|0,c=c+Math.imul(Z,Ft)|0,c=c+Math.imul(Y,Vt)|0,v=v+Math.imul(Y,Ft)|0,b=b+Math.imul(V,It)|0,c=c+Math.imul(V,Lt)|0,c=c+Math.imul(I,It)|0,v=v+Math.imul(I,Lt)|0;var ki=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(ki>>>26)|0,ki&=67108863,b=Math.imul(_t,vt),c=Math.imul(_t,yt),c=c+Math.imul(gt,vt)|0,v=Math.imul(gt,yt),b=b+Math.imul(mt,Mt)|0,c=c+Math.imul(mt,Ct)|0,c=c+Math.imul(pt,Mt)|0,v=v+Math.imul(pt,Ct)|0,b=b+Math.imul(ft,kt)|0,c=c+Math.imul(ft,Pt)|0,c=c+Math.imul(ht,kt)|0,v=v+Math.imul(ht,Pt)|0,b=b+Math.imul(ut,St)|0,c=c+Math.imul(ut,At)|0,c=c+Math.imul(dt,St)|0,v=v+Math.imul(dt,At)|0,b=b+Math.imul(ct,Ot)|0,c=c+Math.imul(ct,xt)|0,c=c+Math.imul(lt,Ot)|0,v=v+Math.imul(lt,xt)|0,b=b+Math.imul(st,Dt)|0,c=c+Math.imul(st,Et)|0,c=c+Math.imul(at,Dt)|0,v=v+Math.imul(at,Et)|0,b=b+Math.imul(rt,Tt)|0,c=c+Math.imul(rt,Bt)|0,c=c+Math.imul(ot,Tt)|0,v=v+Math.imul(ot,Bt)|0,b=b+Math.imul(tt,Vt)|0,c=c+Math.imul(tt,Ft)|0,c=c+Math.imul(it,Vt)|0,v=v+Math.imul(it,Ft)|0,b=b+Math.imul(Z,It)|0,c=c+Math.imul(Z,Lt)|0,c=c+Math.imul(Y,It)|0,v=v+Math.imul(Y,Lt)|0;var Pi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Pi>>>26)|0,Pi&=67108863,b=Math.imul(_t,Mt),c=Math.imul(_t,Ct),c=c+Math.imul(gt,Mt)|0,v=Math.imul(gt,Ct),b=b+Math.imul(mt,kt)|0,c=c+Math.imul(mt,Pt)|0,c=c+Math.imul(pt,kt)|0,v=v+Math.imul(pt,Pt)|0,b=b+Math.imul(ft,St)|0,c=c+Math.imul(ft,At)|0,c=c+Math.imul(ht,St)|0,v=v+Math.imul(ht,At)|0,b=b+Math.imul(ut,Ot)|0,c=c+Math.imul(ut,xt)|0,c=c+Math.imul(dt,Ot)|0,v=v+Math.imul(dt,xt)|0,b=b+Math.imul(ct,Dt)|0,c=c+Math.imul(ct,Et)|0,c=c+Math.imul(lt,Dt)|0,v=v+Math.imul(lt,Et)|0,b=b+Math.imul(st,Tt)|0,c=c+Math.imul(st,Bt)|0,c=c+Math.imul(at,Tt)|0,v=v+Math.imul(at,Bt)|0,b=b+Math.imul(rt,Vt)|0,c=c+Math.imul(rt,Ft)|0,c=c+Math.imul(ot,Vt)|0,v=v+Math.imul(ot,Ft)|0,b=b+Math.imul(tt,It)|0,c=c+Math.imul(tt,Lt)|0,c=c+Math.imul(it,It)|0,v=v+Math.imul(it,Lt)|0;var Si=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Si>>>26)|0,Si&=67108863,b=Math.imul(_t,kt),c=Math.imul(_t,Pt),c=c+Math.imul(gt,kt)|0,v=Math.imul(gt,Pt),b=b+Math.imul(mt,St)|0,c=c+Math.imul(mt,At)|0,c=c+Math.imul(pt,St)|0,v=v+Math.imul(pt,At)|0,b=b+Math.imul(ft,Ot)|0,c=c+Math.imul(ft,xt)|0,c=c+Math.imul(ht,Ot)|0,v=v+Math.imul(ht,xt)|0,b=b+Math.imul(ut,Dt)|0,c=c+Math.imul(ut,Et)|0,c=c+Math.imul(dt,Dt)|0,v=v+Math.imul(dt,Et)|0,b=b+Math.imul(ct,Tt)|0,c=c+Math.imul(ct,Bt)|0,c=c+Math.imul(lt,Tt)|0,v=v+Math.imul(lt,Bt)|0,b=b+Math.imul(st,Vt)|0,c=c+Math.imul(st,Ft)|0,c=c+Math.imul(at,Vt)|0,v=v+Math.imul(at,Ft)|0,b=b+Math.imul(rt,It)|0,c=c+Math.imul(rt,Lt)|0,c=c+Math.imul(ot,It)|0,v=v+Math.imul(ot,Lt)|0;var Ai=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,b=Math.imul(_t,St),c=Math.imul(_t,At),c=c+Math.imul(gt,St)|0,v=Math.imul(gt,At),b=b+Math.imul(mt,Ot)|0,c=c+Math.imul(mt,xt)|0,c=c+Math.imul(pt,Ot)|0,v=v+Math.imul(pt,xt)|0,b=b+Math.imul(ft,Dt)|0,c=c+Math.imul(ft,Et)|0,c=c+Math.imul(ht,Dt)|0,v=v+Math.imul(ht,Et)|0,b=b+Math.imul(ut,Tt)|0,c=c+Math.imul(ut,Bt)|0,c=c+Math.imul(dt,Tt)|0,v=v+Math.imul(dt,Bt)|0,b=b+Math.imul(ct,Vt)|0,c=c+Math.imul(ct,Ft)|0,c=c+Math.imul(lt,Vt)|0,v=v+Math.imul(lt,Ft)|0,b=b+Math.imul(st,It)|0,c=c+Math.imul(st,Lt)|0,c=c+Math.imul(at,It)|0,v=v+Math.imul(at,Lt)|0;var Oi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Oi>>>26)|0,Oi&=67108863,b=Math.imul(_t,Ot),c=Math.imul(_t,xt),c=c+Math.imul(gt,Ot)|0,v=Math.imul(gt,xt),b=b+Math.imul(mt,Dt)|0,c=c+Math.imul(mt,Et)|0,c=c+Math.imul(pt,Dt)|0,v=v+Math.imul(pt,Et)|0,b=b+Math.imul(ft,Tt)|0,c=c+Math.imul(ft,Bt)|0,c=c+Math.imul(ht,Tt)|0,v=v+Math.imul(ht,Bt)|0,b=b+Math.imul(ut,Vt)|0,c=c+Math.imul(ut,Ft)|0,c=c+Math.imul(dt,Vt)|0,v=v+Math.imul(dt,Ft)|0,b=b+Math.imul(ct,It)|0,c=c+Math.imul(ct,Lt)|0,c=c+Math.imul(lt,It)|0,v=v+Math.imul(lt,Lt)|0;var xi=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(xi>>>26)|0,xi&=67108863,b=Math.imul(_t,Dt),c=Math.imul(_t,Et),c=c+Math.imul(gt,Dt)|0,v=Math.imul(gt,Et),b=b+Math.imul(mt,Tt)|0,c=c+Math.imul(mt,Bt)|0,c=c+Math.imul(pt,Tt)|0,v=v+Math.imul(pt,Bt)|0,b=b+Math.imul(ft,Vt)|0,c=c+Math.imul(ft,Ft)|0,c=c+Math.imul(ht,Vt)|0,v=v+Math.imul(ht,Ft)|0,b=b+Math.imul(ut,It)|0,c=c+Math.imul(ut,Lt)|0,c=c+Math.imul(dt,It)|0,v=v+Math.imul(dt,Lt)|0;var Di=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Di>>>26)|0,Di&=67108863,b=Math.imul(_t,Tt),c=Math.imul(_t,Bt),c=c+Math.imul(gt,Tt)|0,v=Math.imul(gt,Bt),b=b+Math.imul(mt,Vt)|0,c=c+Math.imul(mt,Ft)|0,c=c+Math.imul(pt,Vt)|0,v=v+Math.imul(pt,Ft)|0,b=b+Math.imul(ft,It)|0,c=c+Math.imul(ft,Lt)|0,c=c+Math.imul(ht,It)|0,v=v+Math.imul(ht,Lt)|0;var Ei=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Ei>>>26)|0,Ei&=67108863,b=Math.imul(_t,Vt),c=Math.imul(_t,Ft),c=c+Math.imul(gt,Vt)|0,v=Math.imul(gt,Ft),b=b+Math.imul(mt,It)|0,c=c+Math.imul(mt,Lt)|0,c=c+Math.imul(pt,It)|0,v=v+Math.imul(pt,Lt)|0;var Ti=(M+b|0)+((c&8191)<<13)|0;M=(v+(c>>>13)|0)+(Ti>>>26)|0,Ti&=67108863,b=Math.imul(_t,It),c=Math.imul(_t,Lt),c=c+Math.imul(gt,It)|0,v=Math.imul(gt,Lt);var Bi=(M+b|0)+((c&8191)<<13)|0;return M=(v+(c>>>13)|0)+(Bi>>>26)|0,Bi&=67108863,y[0]=pi,y[1]=_i,y[2]=gi,y[3]=bi,y[4]=wi,y[5]=vi,y[6]=yi,y[7]=Mi,y[8]=Ci,y[9]=ki,y[10]=Pi,y[11]=Si,y[12]=Ai,y[13]=Oi,y[14]=xi,y[15]=Di,y[16]=Ei,y[17]=Ti,y[18]=Bi,M!==0&&(y[19]=M,h.length++),h};Math.imul||(O=E);function T(s,l,h){h.negative=l.negative^s.negative,h.length=s.length+l.length;for(var p=0,w=0,y=0;y<h.length-1;y++){var M=w;w=0;for(var b=p&67108863,c=Math.min(y,l.length-1),v=Math.max(0,y-s.length+1);v<=c;v++){var B=y-v,V=s.words[B]|0,I=l.words[v]|0,U=V*I,Z=U&67108863;M=M+(U/67108864|0)|0,Z=Z+b|0,b=Z&67108863,M=M+(Z>>>26)|0,w+=M>>>26,M&=67108863}h.words[y]=b,p=M,M=w}return p!==0?h.words[y]=p:h.length--,h._strip()}function H(s,l,h){return T(s,l,h)}o.prototype.mulTo=function(s,l){var h,p=this.length+s.length;return this.length===10&&s.length===10?h=O(this,s,l):p<63?h=E(this,s,l):p<1024?h=T(this,s,l):h=H(this,s,l),h};function N(s,l){this.x=s,this.y=l}N.prototype.makeRBT=function(s){for(var l=new Array(s),h=o.prototype._countBits(s)-1,p=0;p<s;p++)l[p]=this.revBin(p,h,s);return l},N.prototype.revBin=function(s,l,h){if(s===0||s===h-1)return s;for(var p=0,w=0;w<l;w++)p|=(s&1)<<l-w-1,s>>=1;return p},N.prototype.permute=function(s,l,h,p,w,y){for(var M=0;M<y;M++)p[M]=l[s[M]],w[M]=h[s[M]]},N.prototype.transform=function(s,l,h,p,w,y){this.permute(y,s,l,h,p,w);for(var M=1;M<w;M<<=1)for(var b=M<<1,c=Math.cos(2*Math.PI/b),v=Math.sin(2*Math.PI/b),B=0;B<w;B+=b)for(var V=c,I=v,U=0;U<M;U++){var Z=h[B+U],Y=p[B+U],me=h[B+U+M],tt=p[B+U+M],it=V*me-I*tt;tt=V*tt+I*me,me=it,h[B+U]=Z+me,p[B+U]=Y+tt,h[B+U+M]=Z-me,p[B+U+M]=Y-tt,U!==b&&(it=c*V-v*I,I=c*I+v*V,V=it)}},N.prototype.guessLen13b=function(s,l){var h=Math.max(l,s)|1,p=h&1,w=0;for(h=h/2|0;h;h=h>>>1)w++;return 1<<w+1+p},N.prototype.conjugate=function(s,l,h){if(!(h<=1))for(var p=0;p<h/2;p++){var w=s[p];s[p]=s[h-p-1],s[h-p-1]=w,w=l[p],l[p]=-l[h-p-1],l[h-p-1]=-w}},N.prototype.normalize13b=function(s,l){for(var h=0,p=0;p<l/2;p++){var w=Math.round(s[2*p+1]/l)*8192+Math.round(s[2*p]/l)+h;s[p]=w&67108863,w<67108864?h=0:h=w/67108864|0}return s},N.prototype.convert13b=function(s,l,h,p){for(var w=0,y=0;y<l;y++)w=w+(s[y]|0),h[2*y]=w&8191,w=w>>>13,h[2*y+1]=w&8191,w=w>>>13;for(y=2*l;y<p;++y)h[y]=0;r(w===0),r((w&-8192)===0)},N.prototype.stub=function(s){for(var l=new Array(s),h=0;h<s;h++)l[h]=0;return l},N.prototype.mulp=function(s,l,h){var p=2*this.guessLen13b(s.length,l.length),w=this.makeRBT(p),y=this.stub(p),M=new Array(p),b=new Array(p),c=new Array(p),v=new Array(p),B=new Array(p),V=new Array(p),I=h.words;I.length=p,this.convert13b(s.words,s.length,M,p),this.convert13b(l.words,l.length,v,p),this.transform(M,y,b,c,p,w),this.transform(v,y,B,V,p,w);for(var U=0;U<p;U++){var Z=b[U]*B[U]-c[U]*V[U];c[U]=b[U]*V[U]+c[U]*B[U],b[U]=Z}return this.conjugate(b,c,p),this.transform(b,c,I,y,p,w),this.conjugate(I,y,p),this.normalize13b(I,p),h.negative=s.negative^l.negative,h.length=s.length+l.length,h._strip()},o.prototype.mul=function(s){var l=new o(null);return l.words=new Array(this.length+s.length),this.mulTo(s,l)},o.prototype.mulf=function(s){var l=new o(null);return l.words=new Array(this.length+s.length),H(this,s,l)},o.prototype.imul=function(s){return this.clone().mulTo(s,this)},o.prototype.imuln=function(s){var l=s<0;l&&(s=-s),r(typeof s=="number"),r(s<67108864);for(var h=0,p=0;p<this.length;p++){var w=(this.words[p]|0)*s,y=(w&67108863)+(h&67108863);h>>=26,h+=w/67108864|0,h+=y>>>26,this.words[p]=y&67108863}return h!==0&&(this.words[p]=h,this.length++),this.length=s===0?1:this.length,l?this.ineg():this},o.prototype.muln=function(s){return this.clone().imuln(s)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(s){var l=x(s);if(l.length===0)return new o(1);for(var h=this,p=0;p<l.length&&l[p]===0;p++,h=h.sqr());if(++p<l.length)for(var w=h.sqr();p<l.length;p++,w=w.sqr())l[p]!==0&&(h=h.mul(w));return h},o.prototype.iushln=function(s){r(typeof s=="number"&&s>=0);var l=s%26,h=(s-l)/26,p=67108863>>>26-l<<26-l,w;if(l!==0){var y=0;for(w=0;w<this.length;w++){var M=this.words[w]&p,b=(this.words[w]|0)-M<<l;this.words[w]=b|y,y=M>>>26-l}y&&(this.words[w]=y,this.length++)}if(h!==0){for(w=this.length-1;w>=0;w--)this.words[w+h]=this.words[w];for(w=0;w<h;w++)this.words[w]=0;this.length+=h}return this._strip()},o.prototype.ishln=function(s){return r(this.negative===0),this.iushln(s)},o.prototype.iushrn=function(s,l,h){r(typeof s=="number"&&s>=0);var p;l?p=(l-l%26)/26:p=0;var w=s%26,y=Math.min((s-w)/26,this.length),M=67108863^67108863>>>w<<w,b=h;if(p-=y,p=Math.max(0,p),b){for(var c=0;c<y;c++)b.words[c]=this.words[c];b.length=y}if(y!==0)if(this.length>y)for(this.length-=y,c=0;c<this.length;c++)this.words[c]=this.words[c+y];else this.words[0]=0,this.length=1;var v=0;for(c=this.length-1;c>=0&&(v!==0||c>=p);c--){var B=this.words[c]|0;this.words[c]=v<<26-w|B>>>w,v=B&M}return b&&v!==0&&(b.words[b.length++]=v),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(s,l,h){return r(this.negative===0),this.iushrn(s,l,h)},o.prototype.shln=function(s){return this.clone().ishln(s)},o.prototype.ushln=function(s){return this.clone().iushln(s)},o.prototype.shrn=function(s){return this.clone().ishrn(s)},o.prototype.ushrn=function(s){return this.clone().iushrn(s)},o.prototype.testn=function(s){r(typeof s=="number"&&s>=0);var l=s%26,h=(s-l)/26,p=1<<l;if(this.length<=h)return!1;var w=this.words[h];return!!(w&p)},o.prototype.imaskn=function(s){r(typeof s=="number"&&s>=0);var l=s%26,h=(s-l)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(l!==0&&h++,this.length=Math.min(h,this.length),l!==0){var p=67108863^67108863>>>l<<l;this.words[this.length-1]&=p}return this._strip()},o.prototype.maskn=function(s){return this.clone().imaskn(s)},o.prototype.iaddn=function(s){return r(typeof s=="number"),r(s<67108864),s<0?this.isubn(-s):this.negative!==0?this.length===1&&(this.words[0]|0)<=s?(this.words[0]=s-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(s),this.negative=1,this):this._iaddn(s)},o.prototype._iaddn=function(s){this.words[0]+=s;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},o.prototype.isubn=function(s){if(r(typeof s=="number"),r(s<67108864),s<0)return this.iaddn(-s);if(this.negative!==0)return this.negative=0,this.iaddn(s),this.negative=1,this;if(this.words[0]-=s,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},o.prototype.addn=function(s){return this.clone().iaddn(s)},o.prototype.subn=function(s){return this.clone().isubn(s)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(s,l,h){var p=s.length+h,w;this._expand(p);var y,M=0;for(w=0;w<s.length;w++){y=(this.words[w+h]|0)+M;var b=(s.words[w]|0)*l;y-=b&67108863,M=(y>>26)-(b/67108864|0),this.words[w+h]=y&67108863}for(;w<this.length-h;w++)y=(this.words[w+h]|0)+M,M=y>>26,this.words[w+h]=y&67108863;if(M===0)return this._strip();for(r(M===-1),M=0,w=0;w<this.length;w++)y=-(this.words[w]|0)+M,M=y>>26,this.words[w]=y&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(s,l){var h=this.length-s.length,p=this.clone(),w=s,y=w.words[w.length-1]|0,M=this._countBits(y);h=26-M,h!==0&&(w=w.ushln(h),p.iushln(h),y=w.words[w.length-1]|0);var b=p.length-w.length,c;if(l!=="mod"){c=new o(null),c.length=b+1,c.words=new Array(c.length);for(var v=0;v<c.length;v++)c.words[v]=0}var B=p.clone()._ishlnsubmul(w,1,b);B.negative===0&&(p=B,c&&(c.words[b]=1));for(var V=b-1;V>=0;V--){var I=(p.words[w.length+V]|0)*67108864+(p.words[w.length+V-1]|0);for(I=Math.min(I/y|0,67108863),p._ishlnsubmul(w,I,V);p.negative!==0;)I--,p.negative=0,p._ishlnsubmul(w,1,V),p.isZero()||(p.negative^=1);c&&(c.words[V]=I)}return c&&c._strip(),p._strip(),l!=="div"&&h!==0&&p.iushrn(h),{div:c||null,mod:p}},o.prototype.divmod=function(s,l,h){if(r(!s.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var p,w,y;return this.negative!==0&&s.negative===0?(y=this.neg().divmod(s,l),l!=="mod"&&(p=y.div.neg()),l!=="div"&&(w=y.mod.neg(),h&&w.negative!==0&&w.iadd(s)),{div:p,mod:w}):this.negative===0&&s.negative!==0?(y=this.divmod(s.neg(),l),l!=="mod"&&(p=y.div.neg()),{div:p,mod:y.mod}):this.negative&s.negative?(y=this.neg().divmod(s.neg(),l),l!=="div"&&(w=y.mod.neg(),h&&w.negative!==0&&w.isub(s)),{div:y.div,mod:w}):s.length>this.length||this.cmp(s)<0?{div:new o(0),mod:this}:s.length===1?l==="div"?{div:this.divn(s.words[0]),mod:null}:l==="mod"?{div:null,mod:new o(this.modrn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new o(this.modrn(s.words[0]))}:this._wordDiv(s,l)},o.prototype.div=function(s){return this.divmod(s,"div",!1).div},o.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},o.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},o.prototype.divRound=function(s){var l=this.divmod(s);if(l.mod.isZero())return l.div;var h=l.div.negative!==0?l.mod.isub(s):l.mod,p=s.ushrn(1),w=s.andln(1),y=h.cmp(p);return y<0||w===1&&y===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},o.prototype.modrn=function(s){var l=s<0;l&&(s=-s),r(s<=67108863);for(var h=(1<<26)%s,p=0,w=this.length-1;w>=0;w--)p=(h*p+(this.words[w]|0))%s;return l?-p:p},o.prototype.modn=function(s){return this.modrn(s)},o.prototype.idivn=function(s){var l=s<0;l&&(s=-s),r(s<=67108863);for(var h=0,p=this.length-1;p>=0;p--){var w=(this.words[p]|0)+h*67108864;this.words[p]=w/s|0,h=w%s}return this._strip(),l?this.ineg():this},o.prototype.divn=function(s){return this.clone().idivn(s)},o.prototype.egcd=function(s){r(s.negative===0),r(!s.isZero());var l=this,h=s.clone();l.negative!==0?l=l.umod(s):l=l.clone();for(var p=new o(1),w=new o(0),y=new o(0),M=new o(1),b=0;l.isEven()&&h.isEven();)l.iushrn(1),h.iushrn(1),++b;for(var c=h.clone(),v=l.clone();!l.isZero();){for(var B=0,V=1;!(l.words[0]&V)&&B<26;++B,V<<=1);if(B>0)for(l.iushrn(B);B-- >0;)(p.isOdd()||w.isOdd())&&(p.iadd(c),w.isub(v)),p.iushrn(1),w.iushrn(1);for(var I=0,U=1;!(h.words[0]&U)&&I<26;++I,U<<=1);if(I>0)for(h.iushrn(I);I-- >0;)(y.isOdd()||M.isOdd())&&(y.iadd(c),M.isub(v)),y.iushrn(1),M.iushrn(1);l.cmp(h)>=0?(l.isub(h),p.isub(y),w.isub(M)):(h.isub(l),y.isub(p),M.isub(w))}return{a:y,b:M,gcd:h.iushln(b)}},o.prototype._invmp=function(s){r(s.negative===0),r(!s.isZero());var l=this,h=s.clone();l.negative!==0?l=l.umod(s):l=l.clone();for(var p=new o(1),w=new o(0),y=h.clone();l.cmpn(1)>0&&h.cmpn(1)>0;){for(var M=0,b=1;!(l.words[0]&b)&&M<26;++M,b<<=1);if(M>0)for(l.iushrn(M);M-- >0;)p.isOdd()&&p.iadd(y),p.iushrn(1);for(var c=0,v=1;!(h.words[0]&v)&&c<26;++c,v<<=1);if(c>0)for(h.iushrn(c);c-- >0;)w.isOdd()&&w.iadd(y),w.iushrn(1);l.cmp(h)>=0?(l.isub(h),p.isub(w)):(h.isub(l),w.isub(p))}var B;return l.cmpn(1)===0?B=p:B=w,B.cmpn(0)<0&&B.iadd(s),B},o.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var l=this.clone(),h=s.clone();l.negative=0,h.negative=0;for(var p=0;l.isEven()&&h.isEven();p++)l.iushrn(1),h.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;h.isEven();)h.iushrn(1);var w=l.cmp(h);if(w<0){var y=l;l=h,h=y}else if(w===0||h.cmpn(1)===0)break;l.isub(h)}while(!0);return h.iushln(p)},o.prototype.invm=function(s){return this.egcd(s).a.umod(s)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(s){return this.words[0]&s},o.prototype.bincn=function(s){r(typeof s=="number");var l=s%26,h=(s-l)/26,p=1<<l;if(this.length<=h)return this._expand(h+1),this.words[h]|=p,this;for(var w=p,y=h;w!==0&&y<this.length;y++){var M=this.words[y]|0;M+=w,w=M>>>26,M&=67108863,this.words[y]=M}return w!==0&&(this.words[y]=w,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(s){var l=s<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var h;if(this.length>1)h=1;else{l&&(s=-s),r(s<=67108863,"Number is too big");var p=this.words[0]|0;h=p===s?0:p<s?-1:1}return this.negative!==0?-h|0:h},o.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var l=this.ucmp(s);return this.negative!==0?-l|0:l},o.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var l=0,h=this.length-1;h>=0;h--){var p=this.words[h]|0,w=s.words[h]|0;if(p!==w){p<w?l=-1:p>w&&(l=1);break}}return l},o.prototype.gtn=function(s){return this.cmpn(s)===1},o.prototype.gt=function(s){return this.cmp(s)===1},o.prototype.gten=function(s){return this.cmpn(s)>=0},o.prototype.gte=function(s){return this.cmp(s)>=0},o.prototype.ltn=function(s){return this.cmpn(s)===-1},o.prototype.lt=function(s){return this.cmp(s)===-1},o.prototype.lten=function(s){return this.cmpn(s)<=0},o.prototype.lte=function(s){return this.cmp(s)<=0},o.prototype.eqn=function(s){return this.cmpn(s)===0},o.prototype.eq=function(s){return this.cmp(s)===0},o.red=function(s){return new X(s)},o.prototype.toRed=function(s){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},o.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(s){return this.red=s,this},o.prototype.forceRed=function(s){return r(!this.red,"Already a number in reduction context"),this._forceRed(s)},o.prototype.redAdd=function(s){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},o.prototype.redIAdd=function(s){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},o.prototype.redSub=function(s){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},o.prototype.redISub=function(s){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},o.prototype.redShl=function(s){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},o.prototype.redMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},o.prototype.redIMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(s){return r(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var G={k256:null,p224:null,p192:null,p25519:null};function $(s,l){this.name=s,this.p=new o(l,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}$.prototype._tmp=function(){var s=new o(null);return s.words=new Array(Math.ceil(this.n/13)),s},$.prototype.ireduce=function(s){var l=s,h;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),h=l.bitLength();while(h>this.n);var p=h<this.n?-1:l.ucmp(this.p);return p===0?(l.words[0]=0,l.length=1):p>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},$.prototype.split=function(s,l){s.iushrn(this.n,0,l)},$.prototype.imulK=function(s){return s.imul(this.k)};function z(){$.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a(z,$),z.prototype.split=function(s,l){for(var h=4194303,p=Math.min(s.length,9),w=0;w<p;w++)l.words[w]=s.words[w];if(l.length=p,s.length<=9){s.words[0]=0,s.length=1;return}var y=s.words[9];for(l.words[l.length++]=y&h,w=10;w<s.length;w++){var M=s.words[w]|0;s.words[w-10]=(M&h)<<4|y>>>22,y=M}y>>>=22,s.words[w-10]=y,y===0&&s.length>10?s.length-=10:s.length-=9},z.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var l=0,h=0;h<s.length;h++){var p=s.words[h]|0;l+=p*977,s.words[h]=l&67108863,l=p*64+(l/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function W(){$.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}a(W,$);function et(){$.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}a(et,$);function qt(){$.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}a(qt,$),qt.prototype.imulK=function(s){for(var l=0,h=0;h<s.length;h++){var p=(s.words[h]|0)*19+l,w=p&67108863;p>>>=26,s.words[h]=w,l=p}return l!==0&&(s.words[s.length++]=l),s},o._prime=function(s){if(G[s])return G[s];var l;if(s==="k256")l=new z;else if(s==="p224")l=new W;else if(s==="p192")l=new et;else if(s==="p25519")l=new qt;else throw new Error("Unknown prime "+s);return G[s]=l,l};function X(s){if(typeof s=="string"){var l=o._prime(s);this.m=l.p,this.prime=l}else r(s.gtn(1),"modulus must be greater than 1"),this.m=s,this.prime=null}X.prototype._verify1=function(s){r(s.negative===0,"red works only with positives"),r(s.red,"red works only with red numbers")},X.prototype._verify2=function(s,l){r((s.negative|l.negative)===0,"red works only with positives"),r(s.red&&s.red===l.red,"red works only with red numbers")},X.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):(_(s,s.umod(this.m)._forceRed(this)),s)},X.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},X.prototype.add=function(s,l){this._verify2(s,l);var h=s.add(l);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},X.prototype.iadd=function(s,l){this._verify2(s,l);var h=s.iadd(l);return h.cmp(this.m)>=0&&h.isub(this.m),h},X.prototype.sub=function(s,l){this._verify2(s,l);var h=s.sub(l);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},X.prototype.isub=function(s,l){this._verify2(s,l);var h=s.isub(l);return h.cmpn(0)<0&&h.iadd(this.m),h},X.prototype.shl=function(s,l){return this._verify1(s),this.imod(s.ushln(l))},X.prototype.imul=function(s,l){return this._verify2(s,l),this.imod(s.imul(l))},X.prototype.mul=function(s,l){return this._verify2(s,l),this.imod(s.mul(l))},X.prototype.isqr=function(s){return this.imul(s,s.clone())},X.prototype.sqr=function(s){return this.mul(s,s)},X.prototype.sqrt=function(s){if(s.isZero())return s.clone();var l=this.m.andln(3);if(r(l%2===1),l===3){var h=this.m.add(new o(1)).iushrn(2);return this.pow(s,h)}for(var p=this.m.subn(1),w=0;!p.isZero()&&p.andln(1)===0;)w++,p.iushrn(1);r(!p.isZero());var y=new o(1).toRed(this),M=y.redNeg(),b=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new o(2*c*c).toRed(this);this.pow(c,b).cmp(M)!==0;)c.redIAdd(M);for(var v=this.pow(c,p),B=this.pow(s,p.addn(1).iushrn(1)),V=this.pow(s,p),I=w;V.cmp(y)!==0;){for(var U=V,Z=0;U.cmp(y)!==0;Z++)U=U.redSqr();r(Z<I);var Y=this.pow(v,new o(1).iushln(I-Z-1));B=B.redMul(Y),v=Y.redSqr(),V=V.redMul(v),I=Z}return B},X.prototype.invm=function(s){var l=s._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},X.prototype.pow=function(s,l){if(l.isZero())return new o(1).toRed(this);if(l.cmpn(1)===0)return s.clone();var h=4,p=new Array(1<<h);p[0]=new o(1).toRed(this),p[1]=s;for(var w=2;w<p.length;w++)p[w]=this.mul(p[w-1],s);var y=p[0],M=0,b=0,c=l.bitLength()%26;for(c===0&&(c=26),w=l.length-1;w>=0;w--){for(var v=l.words[w],B=c-1;B>=0;B--){var V=v>>B&1;if(y!==p[0]&&(y=this.sqr(y)),V===0&&M===0){b=0;continue}M<<=1,M|=V,b++,!(b!==h&&(w!==0||B!==0))&&(y=this.mul(y,p[M]),b=0,M=0)}c=26}return y},X.prototype.convertTo=function(s){var l=s.umod(this.m);return l===s?l.clone():l},X.prototype.convertFrom=function(s){var l=s.clone();return l.red=null,l},o.mont=function(s){return new Q(s)};function Q(s){X.call(this,s),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}a(Q,X),Q.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},Q.prototype.convertFrom=function(s){var l=this.imod(s.mul(this.rinv));return l.red=null,l},Q.prototype.imul=function(s,l){if(s.isZero()||l.isZero())return s.words[0]=0,s.length=1,s;var h=s.imul(l),p=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),w=h.isub(p).iushrn(this.shift),y=w;return w.cmp(this.m)>=0?y=w.isub(this.m):w.cmpn(0)<0&&(y=w.iadd(this.m)),y._forceRed(this)},Q.prototype.mul=function(s,l){if(s.isZero()||l.isZero())return new o(0)._forceRed(this);var h=s.mul(l),p=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),w=h.isub(p).iushrn(this.shift),y=w;return w.cmp(this.m)>=0?y=w.isub(this.m):w.cmpn(0)<0&&(y=w.iadd(this.m)),y._forceRed(this)},Q.prototype.invm=function(s){var l=this.imod(s._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof t>"u"||t,i)}),Vi={REQUEST_PARAMS:"requestParams",METHOD_NAME:"methodName"},Fr=class Un extends Error{constructor(t,e,n){super(t),this.code=e,this.details=n,this.name=this.constructor.name}static{this.DETAILS_KEYS=Vi}toJSON(){return{name:this.name,message:this.message,code:this.code,details:this.details}}toString(){return JSON.stringify(this.toJSON())}static isErrorCode(t,e){return t instanceof Un&&t.code===e}},Ir=class extends Fr{constructor(i,t,e){super(i,t||"UnknownError",e)}static isCommonErrorCode(i,t){return this.isErrorCode(i,t)}},Gt=(i,t,e)=>{throw new Ir(t,i,e)};var $n=864e5;var Oe=9e15,be=1e9,Ii="0123456789abcdef",Je="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ye="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Li={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Oe,maxE:Oe,crypto:!1},Kn,le,R=!0,ei="[DecimalError] ",ge=ei+"Invalid argument: ",Wn=ei+"Precision limit exceeded",Zn=ei+"crypto unavailable",zn="[object Decimal]",Wt=Math.floor,Nt=Math.pow,Nr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Ur=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,$r=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Xn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,te=1e7,j=7,Kr=9007199254740991,Wr=Je.length-1,ji=Ye.length-1,A={toStringTag:zn};A.absoluteValue=A.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),F(i)};A.ceil=function(){return F(new this.constructor(this),this.e+1,2)};A.clampedTo=A.clamp=function(i,t){var e,n=this,r=n.constructor;if(i=new r(i),t=new r(t),!i.s||!t.s)return new r(NaN);if(i.gt(t))throw Error(ge+t);return e=n.cmp(i),e<0?i:n.cmp(t)>0?t:new r(n)};A.comparedTo=A.cmp=function(i){var t,e,n,r,a=this,o=a.d,u=(i=new a.constructor(i)).d,d=a.s,f=i.s;if(!o||!u)return!d||!f?NaN:d!==f?d:o===u?0:!o^d<0?1:-1;if(!o[0]||!u[0])return o[0]?d:u[0]?-f:0;if(d!==f)return d;if(a.e!==i.e)return a.e>i.e^d<0?1:-1;for(n=o.length,r=u.length,t=0,e=n<r?n:r;t<e;++t)if(o[t]!==u[t])return o[t]>u[t]^d<0?1:-1;return n===r?0:n>r^d<0?1:-1};A.cosine=A.cos=function(){var i,t,e=this,n=e.constructor;return e.d?e.d[0]?(i=n.precision,t=n.rounding,n.precision=i+Math.max(e.e,e.sd())+j,n.rounding=1,e=Zr(n,Yn(n,e)),n.precision=i,n.rounding=t,F(le==2||le==3?e.neg():e,i,t,!0)):new n(1):new n(NaN)};A.cubeRoot=A.cbrt=function(){var i,t,e,n,r,a,o,u,d,f,m=this,_=m.constructor;if(!m.isFinite()||m.isZero())return new _(m);for(R=!1,a=m.s*Nt(m.s*m,1/3),!a||Math.abs(a)==1/0?(e=Ut(m.d),i=m.e,(a=(i-e.length+1)%3)&&(e+=a==1||a==-2?"0":"00"),a=Nt(e,1/3),i=Wt((i+1)/3)-(i%3==(i<0?-1:2)),a==1/0?e="5e"+i:(e=a.toExponential(),e=e.slice(0,e.indexOf("e")+1)+i),n=new _(e),n.s=m.s):n=new _(a.toString()),o=(i=_.precision)+3;;)if(u=n,d=u.times(u).times(u),f=d.plus(m),n=J(f.plus(m).times(u),f.plus(d),o+2,1),Ut(u.d).slice(0,o)===(e=Ut(n.d)).slice(0,o))if(e=e.slice(o-3,o+1),e=="9999"||!r&&e=="4999"){if(!r&&(F(u,i+1,0),u.times(u).times(u).eq(m))){n=u;break}o+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(F(n,i+1,1),t=!n.times(n).times(n).eq(m));break}return R=!0,F(n,i,_.rounding,t)};A.decimalPlaces=A.dp=function(){var i,t=this.d,e=NaN;if(t){if(i=t.length-1,e=(i-Wt(this.e/j))*j,i=t[i],i)for(;i%10==0;i/=10)e--;e<0&&(e=0)}return e};A.dividedBy=A.div=function(i){return J(this,new this.constructor(i))};A.dividedToIntegerBy=A.divToInt=function(i){var t=this,e=t.constructor;return F(J(t,new e(i),0,1,1),e.precision,e.rounding)};A.equals=A.eq=function(i){return this.cmp(i)===0};A.floor=function(){return F(new this.constructor(this),this.e+1,3)};A.greaterThan=A.gt=function(i){return this.cmp(i)>0};A.greaterThanOrEqualTo=A.gte=function(i){var t=this.cmp(i);return t==1||t===0};A.hyperbolicCosine=A.cosh=function(){var i,t,e,n,r,a=this,o=a.constructor,u=new o(1);if(!a.isFinite())return new o(a.s?1/0:NaN);if(a.isZero())return u;e=o.precision,n=o.rounding,o.precision=e+Math.max(a.e,a.sd())+4,o.rounding=1,r=a.d.length,r<32?(i=Math.ceil(r/3),t=(1/ni(4,i)).toString()):(i=16,t="2.3283064365386962890625e-10"),a=xe(o,1,a.times(t),new o(1),!0);for(var d,f=i,m=new o(8);f--;)d=a.times(a),a=u.minus(d.times(m.minus(d.times(m))));return F(a,o.precision=e,o.rounding=n,!0)};A.hyperbolicSine=A.sinh=function(){var i,t,e,n,r=this,a=r.constructor;if(!r.isFinite()||r.isZero())return new a(r);if(t=a.precision,e=a.rounding,a.precision=t+Math.max(r.e,r.sd())+4,a.rounding=1,n=r.d.length,n<3)r=xe(a,2,r,r,!0);else{i=1.4*Math.sqrt(n),i=i>16?16:i|0,r=r.times(1/ni(5,i)),r=xe(a,2,r,r,!0);for(var o,u=new a(5),d=new a(16),f=new a(20);i--;)o=r.times(r),r=r.times(u.plus(o.times(d.times(o).plus(f))))}return a.precision=t,a.rounding=e,F(r,t,e,!0)};A.hyperbolicTangent=A.tanh=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+7,n.rounding=1,J(e.sinh(),e.cosh(),n.precision=i,n.rounding=t)):new n(e.s)};A.inverseCosine=A.acos=function(){var i=this,t=i.constructor,e=i.abs().cmp(1),n=t.precision,r=t.rounding;return e!==-1?e===0?i.isNeg()?oe(t,n,r):new t(0):new t(NaN):i.isZero()?oe(t,n+4,r).times(.5):(t.precision=n+6,t.rounding=1,i=new t(1).minus(i).div(i.plus(1)).sqrt().atan(),t.precision=n,t.rounding=r,i.times(2))};A.inverseHyperbolicCosine=A.acosh=function(){var i,t,e=this,n=e.constructor;return e.lte(1)?new n(e.eq(1)?0:NaN):e.isFinite()?(i=n.precision,t=n.rounding,n.precision=i+Math.max(Math.abs(e.e),e.sd())+4,n.rounding=1,R=!1,e=e.times(e).minus(1).sqrt().plus(e),R=!0,n.precision=i,n.rounding=t,e.ln()):new n(e)};A.inverseHyperbolicSine=A.asinh=function(){var i,t,e=this,n=e.constructor;return!e.isFinite()||e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+2*Math.max(Math.abs(e.e),e.sd())+6,n.rounding=1,R=!1,e=e.times(e).plus(1).sqrt().plus(e),R=!0,n.precision=i,n.rounding=t,e.ln())};A.inverseHyperbolicTangent=A.atanh=function(){var i,t,e,n,r=this,a=r.constructor;return r.isFinite()?r.e>=0?new a(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(i=a.precision,t=a.rounding,n=r.sd(),Math.max(n,i)<2*-r.e-1?F(new a(r),i,t,!0):(a.precision=e=n-r.e,r=J(r.plus(1),new a(1).minus(r),e+i,1),a.precision=i+4,a.rounding=1,r=r.ln(),a.precision=i,a.rounding=t,r.times(.5))):new a(NaN)};A.inverseSine=A.asin=function(){var i,t,e,n,r=this,a=r.constructor;return r.isZero()?new a(r):(t=r.abs().cmp(1),e=a.precision,n=a.rounding,t!==-1?t===0?(i=oe(a,e+4,n).times(.5),i.s=r.s,i):new a(NaN):(a.precision=e+6,a.rounding=1,r=r.div(new a(1).minus(r.times(r)).sqrt().plus(1)).atan(),a.precision=e,a.rounding=n,r.times(2)))};A.inverseTangent=A.atan=function(){var i,t,e,n,r,a,o,u,d,f=this,m=f.constructor,_=m.precision,g=m.rounding;if(f.isFinite()){if(f.isZero())return new m(f);if(f.abs().eq(1)&&_+4<=ji)return o=oe(m,_+4,g).times(.25),o.s=f.s,o}else{if(!f.s)return new m(NaN);if(_+4<=ji)return o=oe(m,_+4,g).times(.5),o.s=f.s,o}for(m.precision=u=_+10,m.rounding=1,e=Math.min(28,u/j+2|0),i=e;i;--i)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(R=!1,t=Math.ceil(u/j),n=1,d=f.times(f),o=new m(f),r=f;i!==-1;)if(r=r.times(d),a=o.minus(r.div(n+=2)),r=r.times(d),o=a.plus(r.div(n+=2)),o.d[t]!==void 0)for(i=t;o.d[i]===a.d[i]&&i--;);return e&&(o=o.times(2<<e-1)),R=!0,F(o,m.precision=_,m.rounding=g,!0)};A.isFinite=function(){return!!this.d};A.isInteger=A.isInt=function(){return!!this.d&&Wt(this.e/j)>this.d.length-2};A.isNaN=function(){return!this.s};A.isNegative=A.isNeg=function(){return this.s<0};A.isPositive=A.isPos=function(){return this.s>0};A.isZero=function(){return!!this.d&&this.d[0]===0};A.lessThan=A.lt=function(i){return this.cmp(i)<0};A.lessThanOrEqualTo=A.lte=function(i){return this.cmp(i)<1};A.logarithm=A.log=function(i){var t,e,n,r,a,o,u,d,f=this,m=f.constructor,_=m.precision,g=m.rounding,C=5;if(i==null)i=new m(10),t=!0;else{if(i=new m(i),e=i.d,i.s<0||!e||!e[0]||i.eq(1))return new m(NaN);t=i.eq(10)}if(e=f.d,f.s<0||!e||!e[0]||f.eq(1))return new m(e&&!e[0]?-1/0:f.s!=1?NaN:e?0:1/0);if(t)if(e.length>1)a=!0;else{for(r=e[0];r%10===0;)r/=10;a=r!==1}if(R=!1,u=_+C,o=_e(f,u),n=t?ti(m,u+10):_e(i,u),d=J(o,n,u,1),Fe(d.d,r=_,g))do if(u+=10,o=_e(f,u),n=t?ti(m,u+10):_e(i,u),d=J(o,n,u,1),!a){+Ut(d.d).slice(r+1,r+15)+1==1e14&&(d=F(d,_+1,0));break}while(Fe(d.d,r+=10,g));return R=!0,F(d,_,g)};A.minus=A.sub=function(i){var t,e,n,r,a,o,u,d,f,m,_,g,C=this,k=C.constructor;if(i=new k(i),!C.d||!i.d)return!C.s||!i.s?i=new k(NaN):C.d?i.s=-i.s:i=new k(i.d||C.s!==i.s?C:NaN),i;if(C.s!=i.s)return i.s=-i.s,C.plus(i);if(f=C.d,g=i.d,u=k.precision,d=k.rounding,!f[0]||!g[0]){if(g[0])i.s=-i.s;else if(f[0])i=new k(C);else return new k(d===3?-0:0);return R?F(i,u,d):i}if(e=Wt(i.e/j),m=Wt(C.e/j),f=f.slice(),a=m-e,a){for(_=a<0,_?(t=f,a=-a,o=g.length):(t=g,e=m,o=f.length),n=Math.max(Math.ceil(u/j),o)+2,a>n&&(a=n,t.length=1),t.reverse(),n=a;n--;)t.push(0);t.reverse()}else{for(n=f.length,o=g.length,_=n<o,_&&(o=n),n=0;n<o;n++)if(f[n]!=g[n]){_=f[n]<g[n];break}a=0}for(_&&(t=f,f=g,g=t,i.s=-i.s),o=f.length,n=g.length-o;n>0;--n)f[o++]=0;for(n=g.length;n>a;){if(f[--n]<g[n]){for(r=n;r&&f[--r]===0;)f[r]=te-1;--f[r],f[n]+=te}f[n]-=g[n]}for(;f[--o]===0;)f.pop();for(;f[0]===0;f.shift())--e;return f[0]?(i.d=f,i.e=ii(f,e),R?F(i,u,d):i):new k(d===3?-0:0)};A.modulo=A.mod=function(i){var t,e=this,n=e.constructor;return i=new n(i),!e.d||!i.s||i.d&&!i.d[0]?new n(NaN):!i.d||e.d&&!e.d[0]?F(new n(e),n.precision,n.rounding):(R=!1,n.modulo==9?(t=J(e,i.abs(),0,3,1),t.s*=i.s):t=J(e,i,0,n.modulo,1),t=t.times(i),R=!0,e.minus(t))};A.naturalExponential=A.exp=function(){return qi(this)};A.naturalLogarithm=A.ln=function(){return _e(this)};A.negated=A.neg=function(){var i=new this.constructor(this);return i.s=-i.s,F(i)};A.plus=A.add=function(i){var t,e,n,r,a,o,u,d,f,m,_=this,g=_.constructor;if(i=new g(i),!_.d||!i.d)return!_.s||!i.s?i=new g(NaN):_.d||(i=new g(i.d||_.s===i.s?_:NaN)),i;if(_.s!=i.s)return i.s=-i.s,_.minus(i);if(f=_.d,m=i.d,u=g.precision,d=g.rounding,!f[0]||!m[0])return m[0]||(i=new g(_)),R?F(i,u,d):i;if(a=Wt(_.e/j),n=Wt(i.e/j),f=f.slice(),r=a-n,r){for(r<0?(e=f,r=-r,o=m.length):(e=m,n=a,o=f.length),a=Math.ceil(u/j),o=a>o?a+1:o+1,r>o&&(r=o,e.length=1),e.reverse();r--;)e.push(0);e.reverse()}for(o=f.length,r=m.length,o-r<0&&(r=o,e=m,m=f,f=e),t=0;r;)t=(f[--r]=f[r]+m[r]+t)/te|0,f[r]%=te;for(t&&(f.unshift(t),++n),o=f.length;f[--o]==0;)f.pop();return i.d=f,i.e=ii(f,n),R?F(i,u,d):i};A.precision=A.sd=function(i){var t,e=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(ge+i);return e.d?(t=Hn(e.d),i&&e.e+1>t&&(t=e.e+1)):t=NaN,t};A.round=function(){var i=this,t=i.constructor;return F(new t(i),i.e+1,t.rounding)};A.sine=A.sin=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+Math.max(e.e,e.sd())+j,n.rounding=1,e=Xr(n,Yn(n,e)),n.precision=i,n.rounding=t,F(le>2?e.neg():e,i,t,!0)):new n(NaN)};A.squareRoot=A.sqrt=function(){var i,t,e,n,r,a,o=this,u=o.d,d=o.e,f=o.s,m=o.constructor;if(f!==1||!u||!u[0])return new m(!f||f<0&&(!u||u[0])?NaN:u?o:1/0);for(R=!1,f=Math.sqrt(+o),f==0||f==1/0?(t=Ut(u),(t.length+d)%2==0&&(t+="0"),f=Math.sqrt(t),d=Wt((d+1)/2)-(d<0||d%2),f==1/0?t="5e"+d:(t=f.toExponential(),t=t.slice(0,t.indexOf("e")+1)+d),n=new m(t)):n=new m(f.toString()),e=(d=m.precision)+3;;)if(a=n,n=a.plus(J(o,a,e+2,1)).times(.5),Ut(a.d).slice(0,e)===(t=Ut(n.d)).slice(0,e))if(t=t.slice(e-3,e+1),t=="9999"||!r&&t=="4999"){if(!r&&(F(a,d+1,0),a.times(a).eq(o))){n=a;break}e+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(F(n,d+1,1),i=!n.times(n).eq(o));break}return R=!0,F(n,d,m.rounding,i)};A.tangent=A.tan=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+10,n.rounding=1,e=e.sin(),e.s=1,e=J(e,new n(1).minus(e.times(e)).sqrt(),i+10,0),n.precision=i,n.rounding=t,F(le==2||le==4?e.neg():e,i,t,!0)):new n(NaN)};A.times=A.mul=function(i){var t,e,n,r,a,o,u,d,f,m=this,_=m.constructor,g=m.d,C=(i=new _(i)).d;if(i.s*=m.s,!g||!g[0]||!C||!C[0])return new _(!i.s||g&&!g[0]&&!C||C&&!C[0]&&!g?NaN:!g||!C?i.s/0:i.s*0);for(e=Wt(m.e/j)+Wt(i.e/j),d=g.length,f=C.length,d<f&&(a=g,g=C,C=a,o=d,d=f,f=o),a=[],o=d+f,n=o;n--;)a.push(0);for(n=f;--n>=0;){for(t=0,r=d+n;r>n;)u=a[r]+C[n]*g[r-n-1]+t,a[r--]=u%te|0,t=u/te|0;a[r]=(a[r]+t)%te|0}for(;!a[--o];)a.pop();return t?++e:a.shift(),i.d=a,i.e=ii(a,e),R?F(i,_.precision,_.rounding):i};A.toBinary=function(i,t){return Ri(this,2,i,t)};A.toDecimalPlaces=A.toDP=function(i,t){var e=this,n=e.constructor;return e=new n(e),i===void 0?e:(zt(i,0,be),t===void 0?t=n.rounding:zt(t,0,8),F(e,i+e.e+1,t))};A.toExponential=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=se(n,!0):(zt(i,0,be),t===void 0?t=r.rounding:zt(t,0,8),n=F(new r(n),i+1,t),e=se(n,!0,i+1)),n.isNeg()&&!n.isZero()?"-"+e:e};A.toFixed=function(i,t){var e,n,r=this,a=r.constructor;return i===void 0?e=se(r):(zt(i,0,be),t===void 0?t=a.rounding:zt(t,0,8),n=F(new a(r),i+r.e+1,t),e=se(n,!1,i+n.e+1)),r.isNeg()&&!r.isZero()?"-"+e:e};A.toFraction=function(i){var t,e,n,r,a,o,u,d,f,m,_,g,C=this,k=C.d,P=C.constructor;if(!k)return new P(C);if(f=e=new P(1),n=d=new P(0),t=new P(n),a=t.e=Hn(k)-C.e-1,o=a%j,t.d[0]=Nt(10,o<0?j+o:o),i==null)i=a>0?t:f;else{if(u=new P(i),!u.isInt()||u.lt(f))throw Error(ge+u);i=u.gt(t)?a>0?t:f:u}for(R=!1,u=new P(Ut(k)),m=P.precision,P.precision=a=k.length*j*2;_=J(u,t,0,1,1),r=e.plus(_.times(n)),r.cmp(i)!=1;)e=n,n=r,r=f,f=d.plus(_.times(r)),d=r,r=t,t=u.minus(_.times(r)),u=r;return r=J(i.minus(e),n,0,1,1),d=d.plus(r.times(f)),e=e.plus(r.times(n)),d.s=f.s=C.s,g=J(f,n,a,1).minus(C).abs().cmp(J(d,e,a,1).minus(C).abs())<1?[f,n]:[d,e],P.precision=m,R=!0,g};A.toHexadecimal=A.toHex=function(i,t){return Ri(this,16,i,t)};A.toNearest=function(i,t){var e=this,n=e.constructor;if(e=new n(e),i==null){if(!e.d)return e;i=new n(1),t=n.rounding}else{if(i=new n(i),t===void 0?t=n.rounding:zt(t,0,8),!e.d)return i.s?e:i;if(!i.d)return i.s&&(i.s=e.s),i}return i.d[0]?(R=!1,e=J(e,i,0,t,1).times(i),R=!0,F(e)):(i.s=e.s,e=i),e};A.toNumber=function(){return+this};A.toOctal=function(i,t){return Ri(this,8,i,t)};A.toPower=A.pow=function(i){var t,e,n,r,a,o,u=this,d=u.constructor,f=+(i=new d(i));if(!u.d||!i.d||!u.d[0]||!i.d[0])return new d(Nt(+u,f));if(u=new d(u),u.eq(1))return u;if(n=d.precision,a=d.rounding,i.eq(1))return F(u,n,a);if(t=Wt(i.e/j),t>=i.d.length-1&&(e=f<0?-f:f)<=Kr)return r=Gn(d,u,e,n),i.s<0?new d(1).div(r):F(r,n,a);if(o=u.s,o<0){if(t<i.d.length-1)return new d(NaN);if(!(i.d[t]&1)&&(o=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=o,u}return e=Nt(+u,f),t=e==0||!isFinite(e)?Wt(f*(Math.log("0."+Ut(u.d))/Math.LN10+u.e+1)):new d(e+"").e,t>d.maxE+1||t<d.minE-1?new d(t>0?o/0:0):(R=!1,d.rounding=u.s=1,e=Math.min(12,(t+"").length),r=qi(i.times(_e(u,n+e)),n),r.d&&(r=F(r,n+5,1),Fe(r.d,n,a)&&(t=n+10,r=F(qi(i.times(_e(u,t+e)),t),t+5,1),+Ut(r.d).slice(n+1,n+15)+1==1e14&&(r=F(r,n+1,0)))),r.s=o,R=!0,d.rounding=a,F(r,n,a))};A.toPrecision=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=se(n,n.e<=r.toExpNeg||n.e>=r.toExpPos):(zt(i,1,be),t===void 0?t=r.rounding:zt(t,0,8),n=F(new r(n),i,t),e=se(n,i<=n.e||n.e<=r.toExpNeg,i)),n.isNeg()&&!n.isZero()?"-"+e:e};A.toSignificantDigits=A.toSD=function(i,t){var e=this,n=e.constructor;return i===void 0?(i=n.precision,t=n.rounding):(zt(i,1,be),t===void 0?t=n.rounding:zt(t,0,8)),F(new n(e),i,t)};A.toString=function(){var i=this,t=i.constructor,e=se(i,i.e<=t.toExpNeg||i.e>=t.toExpPos);return i.isNeg()&&!i.isZero()?"-"+e:e};A.truncated=A.trunc=function(){return F(new this.constructor(this),this.e+1,1)};A.valueOf=A.toJSON=function(){var i=this,t=i.constructor,e=se(i,i.e<=t.toExpNeg||i.e>=t.toExpPos);return i.isNeg()?"-"+e:e};function Ut(i){var t,e,n,r=i.length-1,a="",o=i[0];if(r>0){for(a+=o,t=1;t<r;t++)n=i[t]+"",e=j-n.length,e&&(a+=pe(e)),a+=n;o=i[t],n=o+"",e=j-n.length,e&&(a+=pe(e))}else if(o===0)return"0";for(;o%10===0;)o/=10;return a+o}function zt(i,t,e){if(i!==~~i||i<t||i>e)throw Error(ge+i)}function Fe(i,t,e,n){var r,a,o,u;for(a=i[0];a>=10;a/=10)--t;return--t<0?(t+=j,r=0):(r=Math.ceil((t+1)/j),t%=j),a=Nt(10,j-t),u=i[r]%a|0,n==null?t<3?(t==0?u=u/100|0:t==1&&(u=u/10|0),o=e<4&&u==99999||e>3&&u==49999||u==5e4||u==0):o=(e<4&&u+1==a||e>3&&u+1==a/2)&&(i[r+1]/a/100|0)==Nt(10,t-2)-1||(u==a/2||u==0)&&(i[r+1]/a/100|0)==0:t<4?(t==0?u=u/1e3|0:t==1?u=u/100|0:t==2&&(u=u/10|0),o=(n||e<4)&&u==9999||!n&&e>3&&u==4999):o=((n||e<4)&&u+1==a||!n&&e>3&&u+1==a/2)&&(i[r+1]/a/1e3|0)==Nt(10,t-3)-1,o}function Ge(i,t,e){for(var n,r=[0],a,o=0,u=i.length;o<u;){for(a=r.length;a--;)r[a]*=t;for(r[0]+=Ii.indexOf(i.charAt(o++)),n=0;n<r.length;n++)r[n]>e-1&&(r[n+1]===void 0&&(r[n+1]=0),r[n+1]+=r[n]/e|0,r[n]%=e)}return r.reverse()}function Zr(i,t){var e,n,r;if(t.isZero())return t;n=t.d.length,n<32?(e=Math.ceil(n/3),r=(1/ni(4,e)).toString()):(e=16,r="2.3283064365386962890625e-10"),i.precision+=e,t=xe(i,1,t.times(r),new i(1));for(var a=e;a--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return i.precision-=e,t}var J=function(){function i(n,r,a){var o,u=0,d=n.length;for(n=n.slice();d--;)o=n[d]*r+u,n[d]=o%a|0,u=o/a|0;return u&&n.unshift(u),n}function t(n,r,a,o){var u,d;if(a!=o)d=a>o?1:-1;else for(u=d=0;u<a;u++)if(n[u]!=r[u]){d=n[u]>r[u]?1:-1;break}return d}function e(n,r,a,o){for(var u=0;a--;)n[a]-=u,u=n[a]<r[a]?1:0,n[a]=u*o+n[a]-r[a];for(;!n[0]&&n.length>1;)n.shift()}return function(n,r,a,o,u,d){var f,m,_,g,C,k,P,D,x,E,O,T,H,N,G,$,z,W,et,qt,X=n.constructor,Q=n.s==r.s?1:-1,s=n.d,l=r.d;if(!s||!s[0]||!l||!l[0])return new X(!n.s||!r.s||(s?l&&s[0]==l[0]:!l)?NaN:s&&s[0]==0||!l?Q*0:Q/0);for(d?(C=1,m=n.e-r.e):(d=te,C=j,m=Wt(n.e/C)-Wt(r.e/C)),et=l.length,z=s.length,x=new X(Q),E=x.d=[],_=0;l[_]==(s[_]||0);_++);if(l[_]>(s[_]||0)&&m--,a==null?(N=a=X.precision,o=X.rounding):u?N=a+(n.e-r.e)+1:N=a,N<0)E.push(1),k=!0;else{if(N=N/C+2|0,_=0,et==1){for(g=0,l=l[0],N++;(_<z||g)&&N--;_++)G=g*d+(s[_]||0),E[_]=G/l|0,g=G%l|0;k=g||_<z}else{for(g=d/(l[0]+1)|0,g>1&&(l=i(l,g,d),s=i(s,g,d),et=l.length,z=s.length),$=et,O=s.slice(0,et),T=O.length;T<et;)O[T++]=0;qt=l.slice(),qt.unshift(0),W=l[0],l[1]>=d/2&&++W;do g=0,f=t(l,O,et,T),f<0?(H=O[0],et!=T&&(H=H*d+(O[1]||0)),g=H/W|0,g>1?(g>=d&&(g=d-1),P=i(l,g,d),D=P.length,T=O.length,f=t(P,O,D,T),f==1&&(g--,e(P,et<D?qt:l,D,d))):(g==0&&(f=g=1),P=l.slice()),D=P.length,D<T&&P.unshift(0),e(O,P,T,d),f==-1&&(T=O.length,f=t(l,O,et,T),f<1&&(g++,e(O,et<T?qt:l,T,d))),T=O.length):f===0&&(g++,O=[0]),E[_++]=g,f&&O[0]?O[T++]=s[$]||0:(O=[s[$]],T=1);while(($++<z||O[0]!==void 0)&&N--);k=O[0]!==void 0}E[0]||E.shift()}if(C==1)x.e=m,Kn=k;else{for(_=1,g=E[0];g>=10;g/=10)_++;x.e=_+m*C-1,F(x,u?a+x.e+1:a,o,k)}return x}}();function F(i,t,e,n){var r,a,o,u,d,f,m,_,g,C=i.constructor;t:if(t!=null){if(_=i.d,!_)return i;for(r=1,u=_[0];u>=10;u/=10)r++;if(a=t-r,a<0)a+=j,o=t,m=_[g=0],d=m/Nt(10,r-o-1)%10|0;else if(g=Math.ceil((a+1)/j),u=_.length,g>=u)if(n){for(;u++<=g;)_.push(0);m=d=0,r=1,a%=j,o=a-j+1}else break t;else{for(m=u=_[g],r=1;u>=10;u/=10)r++;a%=j,o=a-j+r,d=o<0?0:m/Nt(10,r-o-1)%10|0}if(n=n||t<0||_[g+1]!==void 0||(o<0?m:m%Nt(10,r-o-1)),f=e<4?(d||n)&&(e==0||e==(i.s<0?3:2)):d>5||d==5&&(e==4||n||e==6&&(a>0?o>0?m/Nt(10,r-o):0:_[g-1])%10&1||e==(i.s<0?8:7)),t<1||!_[0])return _.length=0,f?(t-=i.e+1,_[0]=Nt(10,(j-t%j)%j),i.e=-t||0):_[0]=i.e=0,i;if(a==0?(_.length=g,u=1,g--):(_.length=g+1,u=Nt(10,j-a),_[g]=o>0?(m/Nt(10,r-o)%Nt(10,o)|0)*u:0),f)for(;;)if(g==0){for(a=1,o=_[0];o>=10;o/=10)a++;for(o=_[0]+=u,u=1;o>=10;o/=10)u++;a!=u&&(i.e++,_[0]==te&&(_[0]=1));break}else{if(_[g]+=u,_[g]!=te)break;_[g--]=0,u=1}for(a=_.length;_[--a]===0;)_.pop()}return R&&(i.e>C.maxE?(i.d=null,i.e=NaN):i.e<C.minE&&(i.e=0,i.d=[0])),i}function se(i,t,e){if(!i.isFinite())return Jn(i);var n,r=i.e,a=Ut(i.d),o=a.length;return t?(e&&(n=e-o)>0?a=a.charAt(0)+"."+a.slice(1)+pe(n):o>1&&(a=a.charAt(0)+"."+a.slice(1)),a=a+(i.e<0?"e":"e+")+i.e):r<0?(a="0."+pe(-r-1)+a,e&&(n=e-o)>0&&(a+=pe(n))):r>=o?(a+=pe(r+1-o),e&&(n=e-r-1)>0&&(a=a+"."+pe(n))):((n=r+1)<o&&(a=a.slice(0,n)+"."+a.slice(n)),e&&(n=e-o)>0&&(r+1===o&&(a+="."),a+=pe(n))),a}function ii(i,t){var e=i[0];for(t*=j;e>=10;e/=10)t++;return t}function ti(i,t,e){if(t>Wr)throw R=!0,e&&(i.precision=e),Error(Wn);return F(new i(Je),t,1,!0)}function oe(i,t,e){if(t>ji)throw Error(Wn);return F(new i(Ye),t,e,!0)}function Hn(i){var t=i.length-1,e=t*j+1;if(t=i[t],t){for(;t%10==0;t/=10)e--;for(t=i[0];t>=10;t/=10)e++}return e}function pe(i){for(var t="";i--;)t+="0";return t}function Gn(i,t,e,n){var r,a=new i(1),o=Math.ceil(n/j+4);for(R=!1;;){if(e%2&&(a=a.times(t),Vn(a.d,o)&&(r=!0)),e=Wt(e/2),e===0){e=a.d.length-1,r&&a.d[e]===0&&++a.d[e];break}t=t.times(t),Vn(t.d,o)}return R=!0,a}function Bn(i){return i.d[i.d.length-1]&1}function Qn(i,t,e){for(var n,r,a=new i(t[0]),o=0;++o<t.length;){if(r=new i(t[o]),!r.s){a=r;break}n=a.cmp(r),(n===e||n===0&&a.s===e)&&(a=r)}return a}function qi(i,t){var e,n,r,a,o,u,d,f=0,m=0,_=0,g=i.constructor,C=g.rounding,k=g.precision;if(!i.d||!i.d[0]||i.e>17)return new g(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(t==null?(R=!1,d=k):d=t,u=new g(.03125);i.e>-2;)i=i.times(u),_+=5;for(n=Math.log(Nt(2,_))/Math.LN10*2+5|0,d+=n,e=a=o=new g(1),g.precision=d;;){if(a=F(a.times(i),d,1),e=e.times(++m),u=o.plus(J(a,e,d,1)),Ut(u.d).slice(0,d)===Ut(o.d).slice(0,d)){for(r=_;r--;)o=F(o.times(o),d,1);if(t==null)if(f<3&&Fe(o.d,d-n,C,f))g.precision=d+=10,e=a=u=new g(1),m=0,f++;else return F(o,g.precision=k,C,R=!0);else return g.precision=k,o}o=u}}function _e(i,t){var e,n,r,a,o,u,d,f,m,_,g,C=1,k=10,P=i,D=P.d,x=P.constructor,E=x.rounding,O=x.precision;if(P.s<0||!D||!D[0]||!P.e&&D[0]==1&&D.length==1)return new x(D&&!D[0]?-1/0:P.s!=1?NaN:D?0:P);if(t==null?(R=!1,m=O):m=t,x.precision=m+=k,e=Ut(D),n=e.charAt(0),Math.abs(a=P.e)<15e14){for(;n<7&&n!=1||n==1&&e.charAt(1)>3;)P=P.times(i),e=Ut(P.d),n=e.charAt(0),C++;a=P.e,n>1?(P=new x("0."+e),a++):P=new x(n+"."+e.slice(1))}else return f=ti(x,m+2,O).times(a+""),P=_e(new x(n+"."+e.slice(1)),m-k).plus(f),x.precision=O,t==null?F(P,O,E,R=!0):P;for(_=P,d=o=P=J(P.minus(1),P.plus(1),m,1),g=F(P.times(P),m,1),r=3;;){if(o=F(o.times(g),m,1),f=d.plus(J(o,new x(r),m,1)),Ut(f.d).slice(0,m)===Ut(d.d).slice(0,m))if(d=d.times(2),a!==0&&(d=d.plus(ti(x,m+2,O).times(a+""))),d=J(d,new x(C),m,1),t==null)if(Fe(d.d,m-k,E,u))x.precision=m+=k,f=o=P=J(_.minus(1),_.plus(1),m,1),g=F(P.times(P),m,1),r=u=1;else return F(d,x.precision=O,E,R=!0);else return x.precision=O,d;d=f,r+=2}}function Jn(i){return String(i.s*i.s/0)}function Qe(i,t){var e,n,r;for((e=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(e<0&&(e=n),e+=+t.slice(n+1),t=t.substring(0,n)):e<0&&(e=t.length),n=0;t.charCodeAt(n)===48;n++);for(r=t.length;t.charCodeAt(r-1)===48;--r);if(t=t.slice(n,r),t){if(r-=n,i.e=e=e-n-1,i.d=[],n=(e+1)%j,e<0&&(n+=j),n<r){for(n&&i.d.push(+t.slice(0,n)),r-=j;n<r;)i.d.push(+t.slice(n,n+=j));t=t.slice(n),n=j-t.length}else n-=r;for(;n--;)t+="0";i.d.push(+t),R&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function zr(i,t){var e,n,r,a,o,u,d,f,m;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Xn.test(t))return Qe(i,t)}else if(t==="Infinity"||t==="NaN")return+t||(i.s=NaN),i.e=NaN,i.d=null,i;if(Ur.test(t))e=16,t=t.toLowerCase();else if(Nr.test(t))e=2;else if($r.test(t))e=8;else throw Error(ge+t);for(a=t.search(/p/i),a>0?(d=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf("."),o=a>=0,n=i.constructor,o&&(t=t.replace(".",""),u=t.length,a=u-a,r=Gn(n,new n(e),a,a*2)),f=Ge(t,e,te),m=f.length-1,a=m;f[a]===0;--a)f.pop();return a<0?new n(i.s*0):(i.e=ii(f,m),i.d=f,R=!1,o&&(i=J(i,r,u*4)),d&&(i=i.times(Math.abs(d)<54?Nt(2,d):je.pow(2,d))),R=!0,i)}function Xr(i,t){var e,n=t.d.length;if(n<3)return t.isZero()?t:xe(i,2,t,t);e=1.4*Math.sqrt(n),e=e>16?16:e|0,t=t.times(1/ni(5,e)),t=xe(i,2,t,t);for(var r,a=new i(5),o=new i(16),u=new i(20);e--;)r=t.times(t),t=t.times(a.plus(r.times(o.times(r).minus(u))));return t}function xe(i,t,e,n,r){var a,o,u,d,f=1,m=i.precision,_=Math.ceil(m/j);for(R=!1,d=e.times(e),u=new i(n);;){if(o=J(u.times(d),new i(t++*t++),m,1),u=r?n.plus(o):n.minus(o),n=J(o.times(d),new i(t++*t++),m,1),o=u.plus(n),o.d[_]!==void 0){for(a=_;o.d[a]===u.d[a]&&a--;);if(a==-1)break}a=u,u=n,n=o,o=a,f++}return R=!0,o.d.length=_+1,o}function ni(i,t){for(var e=i;--t;)e*=i;return e}function Yn(i,t){var e,n=t.s<0,r=oe(i,i.precision,1),a=r.times(.5);if(t=t.abs(),t.lte(a))return le=n?4:1,t;if(e=t.divToInt(r),e.isZero())le=n?3:2;else{if(t=t.minus(e.times(r)),t.lte(a))return le=Bn(e)?n?2:3:n?4:1,t;le=Bn(e)?n?1:4:n?3:2}return t.minus(r).abs()}function Ri(i,t,e,n){var r,a,o,u,d,f,m,_,g,C=i.constructor,k=e!==void 0;if(k?(zt(e,1,be),n===void 0?n=C.rounding:zt(n,0,8)):(e=C.precision,n=C.rounding),!i.isFinite())m=Jn(i);else{for(m=se(i),o=m.indexOf("."),k?(r=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):r=t,o>=0&&(m=m.replace(".",""),g=new C(1),g.e=m.length-o,g.d=Ge(se(g),10,r),g.e=g.d.length),_=Ge(m,10,r),a=d=_.length;_[--d]==0;)_.pop();if(!_[0])m=k?"0p+0":"0";else{if(o<0?a--:(i=new C(i),i.d=_,i.e=a,i=J(i,g,e,n,0,r),_=i.d,a=i.e,f=Kn),o=_[e],u=r/2,f=f||_[e+1]!==void 0,f=n<4?(o!==void 0||f)&&(n===0||n===(i.s<0?3:2)):o>u||o===u&&(n===4||f||n===6&&_[e-1]&1||n===(i.s<0?8:7)),_.length=e,f)for(;++_[--e]>r-1;)_[e]=0,e||(++a,_.unshift(1));for(d=_.length;!_[d-1];--d);for(o=0,m="";o<d;o++)m+=Ii.charAt(_[o]);if(k){if(d>1)if(t==16||t==8){for(o=t==16?4:3,--d;d%o;d++)m+="0";for(_=Ge(m,r,t),d=_.length;!_[d-1];--d);for(o=1,m="1.";o<d;o++)m+=Ii.charAt(_[o])}else m=m.charAt(0)+"."+m.slice(1);m=m+(a<0?"p":"p+")+a}else if(a<0){for(;++a;)m="0"+m;m="0."+m}else if(++a>d)for(a-=d;a--;)m+="0";else a<d&&(m=m.slice(0,a)+"."+m.slice(a))}m=(t==16?"0x":t==2?"0b":t==8?"0o":"")+m}return i.s<0?"-"+m:m}function Vn(i,t){if(i.length>t)return i.length=t,!0}function Hr(i){return new this(i).abs()}function Gr(i){return new this(i).acos()}function Qr(i){return new this(i).acosh()}function Jr(i,t){return new this(i).plus(t)}function Yr(i){return new this(i).asin()}function to(i){return new this(i).asinh()}function eo(i){return new this(i).atan()}function io(i){return new this(i).atanh()}function no(i,t){i=new this(i),t=new this(t);var e,n=this.precision,r=this.rounding,a=n+4;return!i.s||!t.s?e=new this(NaN):!i.d&&!t.d?(e=oe(this,a,1).times(t.s>0?.25:.75),e.s=i.s):!t.d||i.isZero()?(e=t.s<0?oe(this,n,r):new this(0),e.s=i.s):!i.d||t.isZero()?(e=oe(this,a,1).times(.5),e.s=i.s):t.s<0?(this.precision=a,this.rounding=1,e=this.atan(J(i,t,a,1)),t=oe(this,a,1),this.precision=n,this.rounding=r,e=i.s<0?e.minus(t):e.plus(t)):e=this.atan(J(i,t,a,1)),e}function ro(i){return new this(i).cbrt()}function oo(i){return F(i=new this(i),i.e+1,2)}function so(i,t,e){return new this(i).clamp(t,e)}function ao(i){if(!i||typeof i!="object")throw Error(ei+"Object expected");var t,e,n,r=i.defaults===!0,a=["precision",1,be,"rounding",0,8,"toExpNeg",-Oe,0,"toExpPos",0,Oe,"maxE",0,Oe,"minE",-Oe,0,"modulo",0,9];for(t=0;t<a.length;t+=3)if(e=a[t],r&&(this[e]=Li[e]),(n=i[e])!==void 0)if(Wt(n)===n&&n>=a[t+1]&&n<=a[t+2])this[e]=n;else throw Error(ge+e+": "+n);if(e="crypto",r&&(this[e]=Li[e]),(n=i[e])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[e]=!0;else throw Error(Zn);else this[e]=!1;else throw Error(ge+e+": "+n);return this}function co(i){return new this(i).cos()}function lo(i){return new this(i).cosh()}function tr(i){var t,e,n;function r(a){var o,u,d,f=this;if(!(f instanceof r))return new r(a);if(f.constructor=r,Fn(a)){f.s=a.s,R?!a.d||a.e>r.maxE?(f.e=NaN,f.d=null):a.e<r.minE?(f.e=0,f.d=[0]):(f.e=a.e,f.d=a.d.slice()):(f.e=a.e,f.d=a.d?a.d.slice():a.d);return}if(d=typeof a,d==="number"){if(a===0){f.s=1/a<0?-1:1,f.e=0,f.d=[0];return}if(a<0?(a=-a,f.s=-1):f.s=1,a===~~a&&a<1e7){for(o=0,u=a;u>=10;u/=10)o++;R?o>r.maxE?(f.e=NaN,f.d=null):o<r.minE?(f.e=0,f.d=[0]):(f.e=o,f.d=[a]):(f.e=o,f.d=[a]);return}if(a*0!==0){a||(f.s=NaN),f.e=NaN,f.d=null;return}return Qe(f,a.toString())}if(d==="string")return(u=a.charCodeAt(0))===45?(a=a.slice(1),f.s=-1):(u===43&&(a=a.slice(1)),f.s=1),Xn.test(a)?Qe(f,a):zr(f,a);if(d==="bigint")return a<0?(a=-a,f.s=-1):f.s=1,Qe(f,a.toString());throw Error(ge+a)}if(r.prototype=A,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=ao,r.clone=tr,r.isDecimal=Fn,r.abs=Hr,r.acos=Gr,r.acosh=Qr,r.add=Jr,r.asin=Yr,r.asinh=to,r.atan=eo,r.atanh=io,r.atan2=no,r.cbrt=ro,r.ceil=oo,r.clamp=so,r.cos=co,r.cosh=lo,r.div=uo,r.exp=fo,r.floor=ho,r.hypot=mo,r.ln=po,r.log=_o,r.log10=bo,r.log2=go,r.max=wo,r.min=vo,r.mod=yo,r.mul=Mo,r.pow=Co,r.random=ko,r.round=Po,r.sign=So,r.sin=Ao,r.sinh=Oo,r.sqrt=xo,r.sub=Do,r.sum=Eo,r.tan=To,r.tanh=Bo,r.trunc=Vo,i===void 0&&(i={}),i&&i.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<n.length;)i.hasOwnProperty(e=n[t++])||(i[e]=this[e]);return r.config(i),r}function uo(i,t){return new this(i).div(t)}function fo(i){return new this(i).exp()}function ho(i){return F(i=new this(i),i.e+1,3)}function mo(){var i,t,e=new this(0);for(R=!1,i=0;i<arguments.length;)if(t=new this(arguments[i++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return R=!0,new this(1/0);e=t}return R=!0,e.sqrt()}function Fn(i){return i instanceof je||i&&i.toStringTag===zn||!1}function po(i){return new this(i).ln()}function _o(i,t){return new this(i).log(t)}function go(i){return new this(i).log(2)}function bo(i){return new this(i).log(10)}function wo(){return Qn(this,arguments,-1)}function vo(){return Qn(this,arguments,1)}function yo(i,t){return new this(i).mod(t)}function Mo(i,t){return new this(i).mul(t)}function Co(i,t){return new this(i).pow(t)}function ko(i){var t,e,n,r,a=0,o=new this(1),u=[];if(i===void 0?i=this.precision:zt(i,1,be),n=Math.ceil(i/j),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));a<n;)r=t[a],r>=429e7?t[a]=crypto.getRandomValues(new Uint32Array(1))[0]:u[a++]=r%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(n*=4);a<n;)r=t[a]+(t[a+1]<<8)+(t[a+2]<<16)+((t[a+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(t,a):(u.push(r%1e7),a+=4);a=n/4}else throw Error(Zn);else for(;a<n;)u[a++]=Math.random()*1e7|0;for(n=u[--a],i%=j,n&&i&&(r=Nt(10,j-i),u[a]=(n/r|0)*r);u[a]===0;a--)u.pop();if(a<0)e=0,u=[0];else{for(e=-1;u[0]===0;e-=j)u.shift();for(n=1,r=u[0];r>=10;r/=10)n++;n<j&&(e-=j-n)}return o.e=e,o.d=u,o}function Po(i){return F(i=new this(i),i.e+1,this.rounding)}function So(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function Ao(i){return new this(i).sin()}function Oo(i){return new this(i).sinh()}function xo(i){return new this(i).sqrt()}function Do(i,t){return new this(i).sub(t)}function Eo(){var i=0,t=arguments,e=new this(t[i]);for(R=!1;e.s&&++i<t.length;)e=e.plus(t[i]);return R=!0,F(e,this.precision,this.rounding)}function To(i){return new this(i).tan()}function Bo(i){return new this(i).tanh()}function Vo(i){return F(i=new this(i),i.e+1,1)}A[Symbol.for("nodejs.util.inspect.custom")]=A.toString;A[Symbol.toStringTag]="Decimal";var je=A.constructor=tr(Li);Je=new je(Je);Ye=new je(Ye);var Jt=je;function S(i){return Jt.isDecimal(i)?i:new Jt(i===void 0?0:i)}function er(i){return S(10).pow(S(i).abs())}function Qt(i,t,e=Jt.ROUND_DOWN){let n=er(S(t));return S(i).mul(n).toFixed(0,e).toString()}function we(i,t=32){return Number(BigInt.asIntN(t,BigInt(i)))}function ue(i,t){let e=er(S(t));return S(i).div(e).toString()}var ir="0x2::sui::SUI",Fo="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";var Ht=class jt{static totalBalance(t,e){let n=BigInt(0);return t.forEach(r=>{e===r.coin_type&&(n+=BigInt(r.balance))}),n}static getCoinAssets(t,e){let n=[];return e.forEach(r=>{Ln(r.coin_type)===Ln(t)&&n.push(r)}),n}static isSuiCoin(t){return ee(t).full_address===ir}static selectCoinObjectIdGreaterThanOrEqual(t,e,n=[]){let r=jt.selectCoinAssetGreaterThanOrEqual(t,e,n),a=r.selected_coins.map(d=>d.coin_object_id),o=r.remain_coins,u=r.selected_coins.map(d=>d.balance.toString());return{object_array:a,remain_coins:o,amount_array:u}}static selectCoinAssetGreaterThanOrEqual(t,e,n=[]){let r=jt.sortByBalance(t.filter(f=>!n.includes(f.coin_object_id))),a=jt.calculateTotalBalance(r);if(a<e)return{selected_coins:[],remain_coins:r};if(a===e)return{selected_coins:r,remain_coins:[]};let o=BigInt(0),u=[],d=[...r];for(;o<a;){let f=e-o,m=d.findIndex(g=>g.balance>=f);if(m!==-1){u.push(d[m]),d.splice(m,1);break}let _=d.pop();_.balance>0&&(u.push(_),o+=_.balance)}return{selected_coins:jt.sortByBalance(u),remain_coins:jt.sortByBalance(d)}}static sortByBalance(t){return t.sort((e,n)=>e.balance<n.balance?-1:e.balance>n.balance?1:0)}static sortByBalanceDes(t){return t.sort((e,n)=>e.balance>n.balance?-1:e.balance<n.balance?0:1)}static calculateTotalBalance(t){return t.reduce((e,n)=>e+n.balance,BigInt(0))}static buildCoinForAmount(t,e,n,r,a=!0,o=!0){let u=jt.getCoinAssets(r,e);if(n===BigInt(0))return this.buildZeroValueCoin(e,t,r,a);let d=jt.calculateTotalBalance(u);if(d<n)throw new Error(`The amount(${d}) is Insufficient balance for ${r} , expect ${n} `);return this.buildCoin(t,e,u,n,r,a,o)}static buildCoinWithBalance(t,e,n){return t===BigInt(0)&&jt.isSuiCoin(e)?n.add((0,Fi.coinWithBalance)({balance:t,useGasCoin:!1})):n.add((0,Fi.coinWithBalance)({balance:t,type:e}))}static buildVectorCoin(t,e,n,r,a,o=!0){if(jt.isSuiCoin(a)){let g=t.splitCoins(t.gas,[t.pure.u64(r)]);return{selected_coins:[],target_coin:g,remain_coins:e,target_coin_amount:r.toString(),is_mint_zero_coin:!1,original_spited_coin:t.gas}}let{original_spited_coin:u,target_coin:d,target_coin_amount:f,remain_coins:m,selected_coins:_}=this.buildSpitTargeCoin(t,r,n,o);return o?{target_coin:t.makeMoveVec({elements:[d]}),selected_coins:_,remain_coins:m,target_coin_amount:f,is_mint_zero_coin:!1,original_spited_coin:u}:{selected_coins:_,target_coin:t.makeMoveVec({elements:_.map(g=>t.object(g))}),remain_coins:m,target_coin_amount:f,is_mint_zero_coin:!1}}static buildOneCoin(t,e,n,r,a=!0){if(jt.isSuiCoin(r)){if(n===0n&&e.length>1){let d=jt.selectCoinObjectIdGreaterThanOrEqual(e,n);return{selected_coins:d.object_array,target_coin:t.object(d.object_array[0]),remain_coins:d.remain_coins,target_coin_amount:d.amount_array[0],is_mint_zero_coin:!1}}let o=jt.selectCoinObjectIdGreaterThanOrEqual(e,n),u=t.splitCoins(t.gas,[t.pure.u64(n)]);return{selected_coins:[],target_coin:u,remain_coins:o.remain_coins,target_coin_amount:n.toString(),is_mint_zero_coin:!1,original_spited_coin:t.gas}}return this.buildSpitTargeCoin(t,n,e,a)}static buildSpitTargeCoin(t,e,n,r){let a=jt.selectCoinObjectIdGreaterThanOrEqual(n,e),o=a.amount_array.reduce((k,P)=>Number(k)+Number(P),0).toString(),u=a.object_array,[d,...f]=u,m=t.object(d),_=m,g=a.amount_array.reduce((k,P)=>Number(k)+Number(P),0).toString(),C;return f.length>0&&t.mergeCoins(m,f.map(k=>t.object(k))),r&&Number(o)>Number(e)&&(_=t.splitCoins(m,[t.pure.u64(e)]),C=m),{original_spited_coin:C,target_coin:_,target_coin_amount:g,remain_coins:a.remain_coins,selected_coins:a.object_array,is_mint_zero_coin:!1}}static buildCoin(t,e,n,r,a,o=!0,u=!0){return o?this.buildVectorCoin(t,e,n,r,a,u):this.buildOneCoin(t,n,r,a,u)}static buildZeroValueCoin(t,e,n,r=!0){let a=this.callMintZeroValueCoin(e,n),o;return r?o=e.makeMoveVec({elements:[a]}):o=a,{target_coin:o,remain_coins:t,selected_coins:[],is_mint_zero_coin:!0,target_coin_amount:"0"}}static buildCoinForAmountInterval(t,e,n,r,a=!0,o=!0){let u=jt.getCoinAssets(r,e);if(n.amount_first===BigInt(0))return u.length>0?this.buildCoin(t,[...e],[...u],n.amount_first,r,a,o):this.buildZeroValueCoin(e,t,r,a);let d=jt.calculateTotalBalance(u);if(d>=n.amount_first)return this.buildCoin(t,[...e],[...u],n.amount_first,r,a,o);if(d<n.amount_second)throw new Error(`The amount(${d}) is Insufficient balance for ${r} , expect ${n.amount_second} `);return this.buildCoin(t,[...e],[...u],n.amount_second,r,a,o)}static{this.callMintZeroValueCoin=(t,e)=>t.moveCall({target:"0x2::coin::zero",typeArguments:[e]})}static fromBalance(t,e,n){return n.moveCall({target:"0x2::coin::from_balance",typeArguments:[e],arguments:[t]})}static intoBalance(t,e,n){return n.moveCall({target:"0x2::coin::into_balance",typeArguments:[e],arguments:[typeof t=="string"?n.object(t):t]})}static mintBalanceZero(t,e){return e.moveCall({target:"0x2::balance::zero",typeArguments:[t],arguments:[]})}static destroyBalanceZero(t,e,n){return n.moveCall({target:"0x2::balance::destroy_zero",typeArguments:[e],arguments:[t]})}static getCoinAmountObjId(t,e){let n=t.amount_coin_array.find(r=>!r.used&&S(r.amount).eq(e)?(r.used=!0,!0):!1);return n?n.coin_object_id:Gt("CoinNotFound",`Coin not found for ${e} ${t.coin_type}`)}static buildMultiCoinInput(t,e,n,r){let a=jt.getCoinAssets(n,e);if(jt.isSuiCoin(n)){let _=t.splitCoins(t.gas,r.map(g=>t.pure.u64(g)));return{amount_coin_array:r.map((g,C)=>({coin_object_id:_[C],amount:g.toString(),used:!1})),coin_type:n,remain_coins:a}}let o=r.reduce((_,g)=>_+g,BigInt(0)),u=jt.selectCoinObjectIdGreaterThanOrEqual(a,o);if(u.object_array.length===0)return Gt("InsufficientBalance",`No enough coins for ${n} expect ${o} actual ${jt.calculateTotalBalance(a)}`);let[d,...f]=u.object_array;f.length>0&&t.mergeCoins(d,[...f]);let m=t.splitCoins(d,r.map(_=>t.pure.u64(_)));return{amount_coin_array:r.map((_,g)=>({coin_object_id:m[g],amount:_.toString(),used:!1})),remain_coins:u.remain_coins,coin_type:n}}};function Io(i){return i.startsWith("0x")?`${i.slice(2)}`:i}function In(i,...t){let e=Array.isArray(t[t.length-1])?t.pop():[],n=[i,...t].filter(Boolean).join("::");return e&&e.length&&(n+=`<${e.join(", ")}>`),n}function ee(i){try{let t=i.replace(/\s/g,""),e=t.match(/(<.+>)$/)?.[0]?.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(e){t=t.slice(0,t.indexOf("<"));let a={...ee(t),type_arguments:e.map(o=>ee(o).source_address)};return a.type_arguments=a.type_arguments.map(o=>Ht.isSuiCoin(o)?o:ee(o).source_address),a.source_address=In(a.full_address,a.type_arguments),a}let n=t.split("::"),r={full_address:t,address:t===ir||t===Fo?"0x2":(0,Me.normalizeSuiObjectId)(n[0]),module:n[1],name:n[2],type_arguments:[],source_address:""};return r.full_address=`${r.address}::${r.module}::${r.name}`,r.source_address=In(r.full_address,r.type_arguments),r}catch{return{full_address:i,address:"",module:"",name:"",type_arguments:[],source_address:i}}}function Ln(i){return ee(i).source_address}var q=(i,t=!0)=>{let e=i.split("::"),n=e.shift(),r=(0,Me.normalizeSuiObjectId)(n);return t&&(r=Io(r)),`${r}::${e.join("::")}`};var No=Ie(Le()),jn=443636,qn=-443636,Uo="79226673515401279992447579055";var $o="4295048016",ms=new No.default(1e6),Ko=(i=>(i[i.BelowRange=0]="BelowRange",i[i.InRange=1]="InRange",i[i.AboveRange=2]="AboveRange",i))(Ko||{}),Zt="0x0000000000000000000000000000000000000000000000000000000000000006";var ps=(0,Ni.getFullnodeUrl)("mainnet"),_s=(0,Ni.getFullnodeUrl)("testnet");var Rt=Ie(Le()),ce=new Rt.default(0),Ve=new Rt.default(1),ri=new Rt.default(2),Wo=ri.pow(new Rt.default(128)),Rn=ri.pow(new Rt.default(64)).sub(Ve),Zo=ri.pow(new Rt.default(128)).sub(Ve),Yt=class{static toX64BN(i){return i.mul(new Rt.default(2).pow(new Rt.default(64)))}static toX64Decimal(i){return i.mul(Jt.pow(2,64))}static toX64(i){return new Rt.default(i.mul(Jt.pow(2,64)).floor().toFixed())}static fromX64(i){return new Jt(i.toString()).mul(Jt.pow(2,-64))}static fromX64Decimal(i){return i.mul(Jt.pow(2,-64))}static fromX64BN(i){return i.div(new Rt.default(2).pow(new Rt.default(64)))}static shiftRightRoundUp(i){let t=i.shrn(64);return i.mod(Rn).gt(ce)&&(t=t.add(Ve)),t}static divRoundUp(i,t){return i.mod(t).eq(ce)?i.div(t):i.div(t).add(new Rt.default(1))}static subUnderflowU128(i,t){return i.lt(t)?i.sub(t).add(Zo):i.sub(t)}static checkUnsignedSub(i,t){let e=i.sub(t);if(e.isNeg())throw new Error("Unsigned integer sub overflow");return e}static checkMul(i,t,e){let n=i.mul(t);return this.isOverflow(n,e)&&Gt("MultiplicationOverflow","Multiplication overflow"),n}static checkMulDivFloor(i,t,e,n){e.eq(ce)&&Gt("DivisionByZero","Divide by zero");let r=i.mul(t).div(e);return this.isOverflow(r,n)&&Gt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulDivCeil(i,t,e,n){if(e.eq(ce))throw new Error("Divide by zero");let r=i.mul(t).add(e.sub(Ve)).div(e);if(this.isOverflow(r,n))throw new Error("Multiplication div overflow");return r}static checkMulDivRound(i,t,e,n){e.eq(ce)&&Gt("DivisionByZero","Divide by zero");let r=i.mul(t.add(e.shrn(1))).div(e);return this.isOverflow(r,n)&&Gt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulShiftRight(i,t,e,n){let r=i.mul(t).div(new Rt.default(2).pow(new Rt.default(e)));return this.isOverflow(r,n)&&Gt("MultiplicationOverflow","Multiplication shift right overflow"),r}static checkMulShiftRight64RoundUpIf(i,t,e,n){let r=i.mul(t),a=n&&r.and(Rn).gt(ce)?r.shrn(64).add(Ve):r.shrn(64);return this.isOverflow(a,e)&&Gt("MultiplicationOverflow","Multiplication shift right overflow"),a}static checkMulShiftLeft(i,t,e,n){let r=i.mul(t).shln(e);return this.isOverflow(r,n)&&Gt("MultiplicationOverflow","Multiplication shift left overflow"),r}static checkDivRoundUpIf(i,t,e){return t.eq(ce)&&Gt("DivisionByZero","Divide by zero"),e?this.divRoundUp(i,t):i.div(t)}static isOverflow(i,t){return i.gte(ri.pow(new Rt.default(t)))}static sign(i){return i.testn(127)?1:0}static is_neg(i){return this.sign(i)===1}static abs_u128(i){return i.gt(ce)?i:this.u128Neg(i.subn(1))}static u128Neg(i){return i.uxor(new Rt.default("ffffffffffffffffffffffffffffffff",16))}static neg(i){return this.is_neg(i)?i.abs():this.negFrom(i)}static abs(i){return this.sign(i)===0?i:this.u128Neg(i.sub(new Rt.default(1)))}static negFrom(i){return i.eq(ce)?i:this.u128Neg(i).add(new Rt.default(1)).or(new Rt.default(1).shln(127))}static u128ToI128(i){return i.testn(127)?Wo.sub(i).neg():i}},Ui=class{static getMinIndex(i){return qn+Math.abs(qn)%i}static getMaxIndex(i){return jn-jn%i}};function nr(i){return i.data}function zo(i){return i.data!==void 0}function Xo(i){return i.content!==void 0}function rr(i){let t="data"in i?nr(i):i;if(!(!t||!Xo(t)||t.content.dataType!=="moveObject"))return t.content}function Ho(i){return rr(i)?.type}function $i(i){let t=zo(i)?i.data:i;return!t?.type&&"data"in i?t?.content?.dataType==="package"?"package":Ho(i):t?.type}function oi(i){return nr(i)?.previousTransaction}function ie(i){let t=rr(i)?.fields;if(t)return"fields"in t?t.fields:t}Jt.config({precision:64,rounding:Jt.ROUND_DOWN,toExpNeg:-64,toExpPos:64});var Kt=Jt,Xt=Ie(Le()),L=Ie(Le()),Go=14,Qo="59543866431248",Jo="184467440737095516",Yo="15793534762490258745";function ts(i,t,e){let n=i.toTwos(e).shln(t);return n.imaskn(e+1),n.fromTwos(e)}function K(i,t,e){let n=i.toTwos(e).shrn(t);return n.imaskn(e-t+1),n.fromTwos(e-t)}function es(i){let t;return i&1?t=new L.default("79232123823359799118286999567"):t=new L.default("79228162514264337593543950336"),i&2&&(t=K(t.mul(new L.default("79236085330515764027303304731")),96,256)),i&4&&(t=K(t.mul(new L.default("79244008939048815603706035061")),96,256)),i&8&&(t=K(t.mul(new L.default("79259858533276714757314932305")),96,256)),i&16&&(t=K(t.mul(new L.default("79291567232598584799939703904")),96,256)),i&32&&(t=K(t.mul(new L.default("79355022692464371645785046466")),96,256)),i&64&&(t=K(t.mul(new L.default("79482085999252804386437311141")),96,256)),i&128&&(t=K(t.mul(new L.default("79736823300114093921829183326")),96,256)),i&256&&(t=K(t.mul(new L.default("80248749790819932309965073892")),96,256)),i&512&&(t=K(t.mul(new L.default("81282483887344747381513967011")),96,256)),i&1024&&(t=K(t.mul(new L.default("83390072131320151908154831281")),96,256)),i&2048&&(t=K(t.mul(new L.default("87770609709833776024991924138")),96,256)),i&4096&&(t=K(t.mul(new L.default("97234110755111693312479820773")),96,256)),i&8192&&(t=K(t.mul(new L.default("119332217159966728226237229890")),96,256)),i&16384&&(t=K(t.mul(new L.default("179736315981702064433883588727")),96,256)),i&32768&&(t=K(t.mul(new L.default("407748233172238350107850275304")),96,256)),i&65536&&(t=K(t.mul(new L.default("2098478828474011932436660412517")),96,256)),i&131072&&(t=K(t.mul(new L.default("55581415166113811149459800483533")),96,256)),i&262144&&(t=K(t.mul(new L.default("38992368544603139932233054999993551")),96,256)),K(t,32,256)}function is(i){let t=Math.abs(i),e;return t&1?e=new L.default("18445821805675392311"):e=new L.default("18446744073709551616"),t&2&&(e=K(e.mul(new L.default("18444899583751176498")),64,256)),t&4&&(e=K(e.mul(new L.default("18443055278223354162")),64,256)),t&8&&(e=K(e.mul(new L.default("18439367220385604838")),64,256)),t&16&&(e=K(e.mul(new L.default("18431993317065449817")),64,256)),t&32&&(e=K(e.mul(new L.default("18417254355718160513")),64,256)),t&64&&(e=K(e.mul(new L.default("18387811781193591352")),64,256)),t&128&&(e=K(e.mul(new L.default("18329067761203520168")),64,256)),t&256&&(e=K(e.mul(new L.default("18212142134806087854")),64,256)),t&512&&(e=K(e.mul(new L.default("17980523815641551639")),64,256)),t&1024&&(e=K(e.mul(new L.default("17526086738831147013")),64,256)),t&2048&&(e=K(e.mul(new L.default("16651378430235024244")),64,256)),t&4096&&(e=K(e.mul(new L.default("15030750278693429944")),64,256)),t&8192&&(e=K(e.mul(new L.default("12247334978882834399")),64,256)),t&16384&&(e=K(e.mul(new L.default("8131365268884726200")),64,256)),t&32768&&(e=K(e.mul(new L.default("3584323654723342297")),64,256)),t&65536&&(e=K(e.mul(new L.default("696457651847595233")),64,256)),t&131072&&(e=K(e.mul(new L.default("26294789957452057")),64,256)),t&262144&&(e=K(e.mul(new L.default("37481735321082")),64,256)),e}var nt=class re{static priceToSqrtPriceX64(t,e,n){return Yt.toX64(t.mul(Kt.pow(10,n-e)).sqrt())}static sqrtPriceX64ToPrice(t,e,n){return Yt.fromX64(t).pow(2).mul(Kt.pow(10,e-n))}static tickIndexToSqrtPriceX64(t){return t>0?new L.default(es(t)):new L.default(is(t))}static sqrtPriceX64ToTickIndex(t){if(t.gt(new L.default(Uo))||t.lt(new L.default($o)))throw new Error("Provided sqrtPrice is not within the supported sqrtPrice range.");let e=t.bitLength()-1,n=new L.default(e-64),r=ts(n,32,128),a=new L.default("8000000000000000","hex"),o=0,u=new L.default(0),d=e>=64?t.shrn(e-63):t.shln(63-e);for(;a.gt(new L.default(0))&&o<Go;){d=d.mul(d);let C=d.shrn(127);d=d.shrn(63+C.toNumber()),u=u.add(a.mul(C)),a=a.shrn(1),o+=1}let f=u.shrn(32),m=r.add(f).mul(new L.default(Qo)),_=K(m.sub(new L.default(Jo)),64,128).toNumber(),g=K(m.add(new L.default(Yo)),64,128).toNumber();return _===g?_:re.tickIndexToSqrtPriceX64(g).lte(t)?g:_}static tickIndexToPrice(t,e,n){return re.sqrtPriceX64ToPrice(re.tickIndexToSqrtPriceX64(t),e,n)}static priceToTickIndex(t,e,n){return re.sqrtPriceX64ToTickIndex(re.priceToSqrtPriceX64(t,e,n))}static priceToInitializeTickIndex(t,e,n,r){return re.getInitializeTickIndex(re.priceToTickIndex(t,e,n),r)}static getInitializeTickIndex(t,e){return t-t%e}static getNextInitializeTickIndex(t,e){return re.getInitializeTickIndex(t,e)+e}static getPrevInitializeTickIndex(t,e){return re.getInitializeTickIndex(t,e)-e}};function Xe(i,t,e){let n=Xt.default.min(i,t),r=Xt.default.max(i,t),a=Yt.fromX64BN(e.mul(r).mul(n)),o=r.sub(n);return!a.isZero()&&!o.isZero()?a.div(o):new Xt.default(0)}function He(i,t,e){let n=Xt.default.min(i,t),r=Xt.default.max(i,t).sub(n);return r.isZero()?new Xt.default(0):e.shln(64).div(r)}var de=class Ae{static getCoinAmountFromLiquidity(t,e,n,r,a){let o=new Kt(t.toString()),u=new Kt(e.toString()),d=new Kt(n.toString()),f=new Kt(r.toString()),m,_;return e.lt(n)?(m=Yt.toX64Decimal(o).mul(f.sub(d)).div(d.mul(f)),_=new Kt(0)):e.lt(r)?(m=Yt.toX64Decimal(o).mul(f.sub(u)).div(u.mul(f)),_=Yt.fromX64Decimal(o.mul(u.sub(d)))):(m=new Kt(0),_=Yt.fromX64Decimal(o.mul(f.sub(d)))),a?{coin_amount_a:m.ceil().toString(),coin_amount_b:_.ceil().toString()}:{coin_amount_a:m.floor().toString(),coin_amount_b:_.floor().toString()}}static estLiquidityAndCoinAmountFromOneAmounts(t,e,n,r,a,o,u){let d=nt.sqrtPriceX64ToTickIndex(u),f=nt.tickIndexToSqrtPriceX64(t),m=nt.tickIndexToSqrtPriceX64(e),_;if(d<t){if(!r)throw new Error("lower tick cannot calculate liquidity by coinB");_=Xe(f,m,n)}else if(d>e){if(r)throw new Error("upper tick cannot calculate liquidity by coinA");_=He(m,f,n)}else r?_=Xe(u,m,n):_=He(u,f,n);let g=Ae.getCoinAmountFromLiquidity(_,u,f,m,a),C=a?S(g.coin_amount_a.toString()).mul(1+o).toString():S(g.coin_amount_a.toString()).mul(1-o).toString(),k=a?S(g.coin_amount_b.toString()).mul(1+o).toString():S(g.coin_amount_b.toString()).mul(1-o).toString();return{coin_amount_a:g.coin_amount_a,coin_amount_b:g.coin_amount_b,coin_amount_limit_a:a?Kt.ceil(C).toString():Kt.floor(C).toString(),coin_amount_limit_b:a?Kt.ceil(k).toString():Kt.floor(k).toString(),liquidity_amount:_.toString(),fix_amount_a:r}}static estimateLiquidityFromCoinAmounts(t,e,n,r){if(e>n)return Gt("InvalidTick","lower tick cannot be greater than lower tick",{[Vi.METHOD_NAME]:"estimateLiquidityFromCoinAmounts",[Vi.REQUEST_PARAMS]:{lower_tick:e,upper_tick:n,token_amount:r}});let a=nt.sqrtPriceX64ToTickIndex(t),o=nt.tickIndexToSqrtPriceX64(e),u=nt.tickIndexToSqrtPriceX64(n);if(a<e)return Xe(o,u,new Xt.default(r.coin_amount_a)).toString();if(a>=n)return He(u,o,new Xt.default(r.coin_amount_b)).toString();let d=Xe(t,u,new Xt.default(r.coin_amount_a)),f=He(t,o,new Xt.default(r.coin_amount_b));return Xt.default.min(d,f).toString()}static calculateDepositRatio(t,e,n){let r=new Xt.default(1e8),{coin_amount_b:a}=Ae.estLiquidityAndCoinAmountFromOneAmounts(t,e,r,!0,!0,0,n),o=nt.sqrtPriceX64ToPrice(n,0,0),u=S(r.toString()).mul(o),d=u.add(a.toString()),f=u.div(d),m=S(a.toString()).div(d);return{ratio_a:f,ratio_b:m}}static calculateAmountDepositRatio(t,e,n,r,a){let o=nt.sqrtPriceX64ToPrice(n,r,a),u=nt.sqrtPriceX64ToTickIndex(n);if(u<t)return{ratio_a:new Kt(1),ratio_b:new Kt(0),curr_price:o};if(u>e)return{ratio_a:new Kt(0),ratio_b:new Kt(1),curr_price:o};let d=new Xt.default(Qt(1,r)),{coin_amount_b:f}=Ae.estLiquidityAndCoinAmountFromOneAmounts(t,e,d,!0,!0,0,n),m=ue(d.toString(),r),_=ue(f.toString(),a),g=S(m).add(_),C=S(m).div(g),k=S(_).div(g);return{ratio_a:C,ratio_b:k,curr_price:o}}static getCoinAmountsFromRatio(t,e,n,r,a,o,u){let d=S(Qt(S(n).mul(t).div(r).toString(),o)).toFixed(0),f=S(Qt(S(n).mul(e).div(a).toString(),u)).toFixed(0);return{amount_a:d,amount_b:f}}static estCoinAmountsFromTotalAmount(t,e,n,r,a,o,u,d){let{ratio_a:f,ratio_b:m}=Ae.calculateDepositRatio(t,e,n);return Ae.getCoinAmountsFromRatio(f,m,r,a,o,u,d)}static getPositionStatus(t,e,n){return t<e?0:t<n?1:2}};function ve(i){if(i.config===void 0)throw new Error(`package: ${i.package_id} not config in sdk SdkOptions`);return i.config}var gs=Ie(Le());var mn=require("@cetusprotocol/sui-clmm-sdk");var Te=require("@mysten/sui/transactions"),he=ne(require("bn.js")),ur=require("@cetusprotocol/aggregator-sdk");var dr=require("@mysten/sui/utils"),fr=ne(require("decimal.js"));var $t=ne(require("bn.js")),ai=ne(require("decimal.js"));var Ki=ne(require("bn.js")),Wi=ne(require("decimal.js")),si=(i,t,e)=>{if(t==="min"){if(i===Ui.getMinIndex(e))return!0}else if(i===Ui.getMaxIndex(e))return!0;return!1};function ns(i){if(i.length!==8)throw new Error("Invalid u64 byte array length");let t=i.map(e=>e.toString(16).padStart(2,"0")).reverse().join("");return BigInt(`0x${t}`).toString()}function or(i,t,e,n,r){let a=new Ki.default(10).pow(new Ki.default(n)),{coin_amount_b:o}=de.estLiquidityAndCoinAmountFromOneAmounts(i,t,a,!0,!0,0,e),u=nt.sqrtPriceX64ToPrice(e,n,r),d=S(a.toString()).mul(u).div(new Wi.default(10).pow(n)).mul(new Wi.default(10).pow(r)),f=d.add(o.toString()),m=d.div(f),_=S(o.toString()).div(f);return{ratioA:m,ratioB:_}}function ae(i,t,e,n,r,a,o){let u=S(Qt(S(e).mul(i).div(n).toString(),a)).toFixed(0),d=S(Qt(S(e).mul(t).div(r).toString(),o)).toFixed(0);return{amountA:u,amountB:d}}function Zi(i,t,e,n,r,a,o,u){let{ratioA:d,ratioB:f}=or(i,t,e,o,u);return ae(d,f,n,r,a,o,u)}var Ce=10n;function ci(i){let{fields:t,type:e}=i,{liquidity_range:n,pool_id:r,wrapped_position:a}=t.clmm_vault.fields,o=a.fields,u={clmm_pool_id:r,liquidity_range:{lower_offset:n.fields.lower_offset,rebalance_threshold:n.fields.rebalance_threshold,upper_offset:n.fields.upper_offset},wrapped_position:{coin_type_a:q(o.coin_type_a.fields.name,!1),coin_type_b:q(o.coin_type_b.fields.name,!1),description:o.description,id:o.id.id,index:o.index,liquidity:o.liquidity,name:o.name,pool:o.pool,tick_lower_index:we(BigInt(o.tick_lower_index.fields.bits)),tick_upper_index:we(BigInt(o.tick_upper_index.fields.bits)),url:o.url}},{balances:d}=t.buffer_assets.fields,f=d.fields.contents.map(_=>{let{key:g,value:C}=_.fields;return{coin_type:q(g.fields.name,!1),value:C}});return{id:t.id.id,is_pause:t.is_pause,clmm_vault:u,lp_token_treasury:t.lp_token_treasury.fields.total_supply.fields.value,protocol_fees_handle:t.protocol_fees.fields.id.id,hard_cap:t.hard_cap,quote_type:ee(t.quote_type.fields.name).full_address,lp_token_type:ee(e).type_arguments[0],balances:f,protocol_fee_rate:t.protocol_fee_rate}}async function rs(i,t=!0){i.getData().commands.forEach((e,n)=>{})}function qe(i,t){let e=S(i).div(t).toString(),n=S(t).div(i).toString();return{quote_per_base:e,base_per_quote:n}}function sr(i,t,e,n){let r=10n**(Ce+n-e),a=10n**(Ce+e-n),o=Yt.checkMulDivFloor(new $t.default(i.toString()),new $t.default(r.toString()),new $t.default(t.toString()),64),u=Yt.checkMulDivFloor(new $t.default(t.toString()),new $t.default(a.toString()),new $t.default(i.toString()),64);return{primitive_base_price:BigInt(o.toString()),primitive_quote_price:BigInt(u.toString())}}function ye(i,t){let e=t?i[t].price:{coin_type:"",price:"1",coin_decimals:6,oracle_price:1000000000000000000000000n},n=new $t.default("0");for(let[r,{price:a,value:o}]of Object.entries(i)){let{primitive_quote_price:u}=sr(BigInt(e.oracle_price),BigInt(a.oracle_price),BigInt(e.coin_decimals),BigInt(a.coin_decimals)),d=Yt.checkMulDivFloor(new $t.default(u.toString()),new $t.default(o),new $t.default((BigInt(10)**Ce).toString()),64);n=n.add(d)}return n.toString()}async function zi(i,t,e,n,r=!1){let{clmm_vault:a,quote_type:o}=t,{wrapped_position:u}=a,{tick_lower_index:d,tick_upper_index:f,liquidity:m}=u,{current_sqrt_price:_,coin_type_a:g,coin_type_b:C}=e,k=[...n],P=o&&q(t.quote_type,!1),D=nt.tickIndexToSqrtPriceX64(d),x=nt.tickIndexToSqrtPriceX64(f),{coin_amount_a:E,coin_amount_b:O}=de.getCoinAmountFromLiquidity(new $t.default(m),new $t.default(_),new $t.default(D),new $t.default(x),!1);k.push({coin_type:g,value:E.toString()}),k.push({coin_type:C,value:O.toString()});let T={};k.forEach(z=>{let W=q(z.coin_type,!1),et=S(z.value),qt=T[W]||0;T[W]=et.add(qt).toString()});let H=Object.entries(T).filter(([z,W])=>S(W).gt(0)).map(([z])=>z);if(P&&!H.includes(P)&&H.push(P),H.length===0)return"0";let N=await i.PythPrice.getLatestPrice(H,r),G={};return H.forEach(z=>{let W=N[z];if(W)G[z]={price:W,value:T[z]||"0"};else throw Error(`find ${z} price fail `)}),ye(G,P).toString()}function Re(i,t,e){return S(i).eq(0)?t:S(i).mul(t).div(e).toFixed(0,ai.default.ROUND_HALF_UP)}function os(i,t,e){return S(i).eq(0)?"0":S(i).mul(t).div(e).toFixed(0,ai.default.ROUND_HALF_UP)}function ke(i,t,e){return S(i).eq(0)?"0":S(t).mul(e).div(i).toFixed(0,ai.default.ROUND_HALF_UP)}function Pe(i,t,e){let n={};return t.forEach(r=>{let a=ke(e,i,r.value),o={coin_type:r.coin_type,value:a};n[o.coin_type]=o}),n}function Xi(i,t,e,n){let{tick_lower_index:r,tick_upper_index:a,coin_type_a:o,coin_type_b:u,liquidity:d}=e.clmm_vault.wrapped_position,f=ke(e.lp_token_treasury,t,d),m=nt.tickIndexToSqrtPriceX64(r),_=nt.tickIndexToSqrtPriceX64(a),g=de.getCoinAmountFromLiquidity(new $t.default(f),new $t.default(n.current_sqrt_price),m,_,!0),C=g.coin_amount_a.toString(),k=g.coin_amount_b.toString(),P=Pe(t,e.balances,e.lp_token_treasury),D=S(C).add(P[o]?.value||"0").toFixed(0),x=S(k).add(P[u]?.value||"0").toFixed(0);return{vault_id:e.id,clmm_pool_id:n.id,owner:i,lp_token_type:e.lp_token_type,lp_token_balance:t,liquidity:f,tick_lower_index:r,tick_upper_index:a,amount_a:D,amount_b:x,coin_type_a:o,coin_type_b:u}}function De(i,t,e){let n=[];return t.forEach(r=>{S(r.value).gt(0)&&n.push(r)}),e.forEach(r=>{S(r.value).gt(0)&&n.push(r)}),i.forEach(r=>{S(r.value).gt(0)&&n.push(r)}),n}function Ne(i,t,e,n,r){let a=De(i,t,e),o=new Set;return a.forEach(u=>o.add(u.coin_type)),o.add(n),o.add(r),Array.from(o)}function Hi(i,t){if(!Ce)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(t<0n){let e=10n**(Ce- -t);return i*e}return i/10n**(t+Ce)}function Gi(i){return`0x${Buffer.from(i).toString("hex")}`}function ss(i,t,e,n,r){let a="0",o="0";return si(i,"min",Number(e))?a="0":a=nt.tickIndexToPrice(Number(i),n,r).toString(),si(t,"max",Number(e))?o="\u221E":o=nt.tickIndexToPrice(Number(t),n,r).toString(),{minPrice:a,maxPrice:o}}function li(i){let t=ie(i),e=$i(i),n=ee(e),r=t.position.fields,a={id:r.id.id,pool_id:r.pool,index:r.index,liquidity:r.liquidity,tick_lower_index:we(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:we(BigInt(r.tick_upper_index.fields.bits)),coin_type_a:q(r.coin_type_a.fields.name,!1),coin_type_b:q(r.coin_type_b.fields.name,!1),name:r.name,description:r.description,url:r.url},o=t.global_vesting_periods.map(d=>({period:d.fields.period,release_time:d.fields.release_time,redeemed_amount:d.fields.redeemed_amount,cetus_amount:d.fields.cetus_amount}));return{id:t.id.id,vault_id:t.vault_id,index:t.index,lp_coin_type:t.lp_coin_type.fields.name,allocated_lp_amount:t.allocated_lp_amount,position:a,balance:t.balance,total_supply:t.total_supply,impaired_a:t.impaired_a,impaired_b:t.impaired_b,redeemed_amount:t.redeemed_amount,url:t.url,coin_type_a:q(t.coin_a.fields.name,!1),coin_type_b:q(t.coin_b.fields.name,!1),cetus_amount:t.cetus_amount,start_time:t.start_time,global_vesting_periods:o,vest_infos:{id:t.vester_infos.fields.id,size:t.vester_infos.fields.size}}}function Qi(i){let t=ie(i),e=$i(i);return{id:t.id.id,vault_id:t.vault_id,index:t.index,lp_amount:t.lp_amount,url:t.url,redeemed_amount:t.redeemed_amount,impaired_a:t.impaired_a,impaired_b:t.impaired_b,period_infos:t.period_infos.map(r=>({period:r.fields.period,cetus_amount:r.fields.cetus_amount,is_redeemed:r.fields.is_redeemed})),name:t.name,vester_id:t.vester_id}}var Ji=require("@cetusprotocol/dlmm-sdk");var ar=ne(require("decimal.js")),ui=require("@mysten/sui/bcs"),di=require("@mysten/sui/utils");function Yi(i){let{fields:t}=i,{certified_pools:e,positions:n,id:r,coin_type_a:a,coin_type_b:o,vault_id:u,position_keys:d}=t;return{id:r.id,certified_pools:e.fields.contents.map(m=>m.fields.key),positions_handle:{id:n.fields.id.id,size:n.fields.size},position_list:[],coin_type_a:q(a.fields.name,!1),coin_type_b:q(o.fields.name,!1),vault_id:u,position_keys:d.fields.contents}}function as(i){return{uri:i.uri,index:i.index,id:i.id.id,name:i.name,pool_id:i.pool_id,lower_bin_id:we(BigInt(i.lower_bin_id.fields.bits)),upper_bin_id:we(BigInt(i.upper_bin_id.fields.bits)),liquidity_shares:i.liquidity_shares,description:i.description,coin_type_a:q(i.coin_type_a,!1),coin_type_b:q(i.coin_type_b,!1)}}function tn(i){let{fields:t}=i,{position:e,amounts:n,id:r}=t,a=n.fields.contents.map(g=>{let{key:C,value:k}=g.fields;return{coin_type:q(C.fields.name,!1),value:k}}),o=as(e.fields),u=o.lower_bin_id,d=o.liquidity_shares.map((g,C)=>({bin_id:u+C,liquidity:g})).filter(g=>S(g.liquidity).gt(0)),f=d.length>0?d[0].bin_id:u,m=d.length>0?d[d.length-1].bin_id:u+o.liquidity_shares.length-1;return{id:r.id,valid_lower_bin_id:f,valid_upper_bin_id:m,position:o,amounts:a}}function en(i){let{fields:t,type:e}=i,{action_status:n,buffer_assets:r,coin_type_a:a,coin_type_b:o,hard_cap:u,id:d,last_aum:f,lp_token_treasury:m,markets:_,protocol_fee_rate:g,protocol_fees:C,quote_type:k}=t,P=(Number(n)&1)!==0,D=(Number(n)&2)!==0,{balances:x}=r.fields,E=x.fields.contents.map(H=>{let{key:N,value:G}=H.fields;return{coin_type:q(N.fields.name,!1),value:G}}),O=k.fields.pos0.fields.name;return{id:d.id,lp_token_treasury:m.fields.total_supply.fields.value,hard_cap:u,quote_type:O?q(O,!1):void 0,protocol_fee_rate:g,buffer_assets:E,protocol_fees_handle:{id:C.fields.id.id,size:C.fields.size},markets_handle:{id:_.fields.id.id,size:_.fields.size},markets:[],action_status:{is_deposit_allowed:P,is_withdraw_allowed:D},last_aum:f,coin_type_a:q(a.fields.name,!1),coin_type_b:q(o.fields.name,!1),lp_token_type:ee(e).type_arguments[0]}}async function nn(i,t,e,n=!1){let{quote_type:r,coin_type_a:a,coin_type_b:o}=t,u=[...e],d=await i.CetusDlmmSDK.Pool.getPool(t.markets[0].position_list[0].position.pool_id,!1),f=await i.CetusDlmmSDK.Pool.getBinInfo(d.bin_manager.bin_manager_handle,d.active_id,d.bin_step,!1),m=(0,Ji.parseLiquidityShares)(t.markets[0].position_list[0].position.liquidity_shares,d.bin_step,t.markets[0].position_list[0].position.lower_bin_id,f),_=m.amount_a,g=m.amount_b,C=r&&q(r,!1);u.push({coin_type:a,value:_.toString()}),u.push({coin_type:o,value:g.toString()});let k={};u.forEach(O=>{let T=q(O.coin_type,!1),H=S(O.value),N=k[T]||0;k[T]=H.add(N).toString()});let P=Object.entries(k).filter(([O,T])=>S(T).gt(0)).map(([O])=>O);if(C&&!P.includes(C)&&P.push(C),P.length===0)return"0";let D=await i.VaultsV2.PythPrice.getLatestPrice(P,n),x={};return P.forEach(O=>{let T=D[O];if(T)x[O]={price:T,value:k[O]||"0"};else throw Error(`find ${O} price fail `)}),ye(x,C).toString()}async function fi(i,t,e,n,r){let{coin_type_a:a,coin_type_b:o,id:u,lp_token_type:d,markets:f}=e,m=f[0].position_list[0],{lower_bin_id:_,upper_bin_id:g,liquidity_shares:C}=m.position,{receive_amount_a:k,receive_amount_b:P,valid_lower_bin_id:D,valid_upper_bin_id:x,bin_infos:E,position_coin_amount_a:O,position_coin_amount_b:T}=await Ue(i,t,e,n);return{vault_id:u,certified_pool_id:n.id,owner:r,lp_token_type:d,lp_token_balance:t,liquidity_shares:C,valid_lower_bin_id:D,valid_upper_bin_id:x,original_lower_bin_id:_,original_upper_bin_id:g,amount_a:k,amount_b:P,position_amount_a:O,position_amount_b:T,coin_type_a:a,coin_type_b:o,bin_infos:E}}async function Ue(i,t,e,n){let{markets:r,lp_token_treasury:a,coin_type_a:o,coin_type_b:u}=e,d=r[0].position_list[0],{lower_bin_id:f}=d.position,{bin_manager:m,bin_step:_,active_id:g}=n,C=await i.CetusDlmmSDK.Pool.getBinInfo(m.bin_manager_handle,g,_,!1),k=S(t).div(a),P=(0,Ji.parseLiquidityShares)(d.position.liquidity_shares.map($=>S($.toString()).mul(k).toFixed(0,ar.default.ROUND_HALF_UP).toString()),_,f,C),D=P.amount_a,x=P.amount_b,E=Pe(t,e.buffer_assets,a),O=E[o]?.value||"0",T=E[u]?.value||"0",H=S(D.toString()).add(O).toFixed(0),N=S(x.toString()).add(T).toFixed(0),G=P.bins.filter($=>S($.liquidity).gt(0));return{valid_lower_bin_id:G.length>0?G[0].bin_id:P.bins[0].bin_id,valid_upper_bin_id:G.length>0?G[G.length-1].bin_id:P.bins[P.bins.length-1].bin_id,receive_amount_a:H,receive_amount_b:N,position_coin_amount_a:D,position_coin_amount_b:x,bin_infos:{bins:G,amount_a:P.amount_a,amount_b:P.amount_b}}}function rn(i){let t=ui.bcs.vector(ui.bcs.u8()).serialize(new TextEncoder().encode("DLMM_MARKET")).toBytes();return(0,di.deriveObjectID)(i,"vector<u8>",t)}function cs(i,t){let e=ui.bcs.Address.serialize(t).toBytes();return(0,di.deriveDynamicFieldID)(i,"0x2::object::ID",e)}var Ee=require("@pythnetwork/pyth-sui-js"),fn=require("@mysten/sui/bcs");var on={env:"mainnet",fullRpcUrl:"https://fullnode.mainnet.sui.io",vaults:{package_id:"0xc4ebf35be1478318d78c324342854dd2735a036139373a9d41a1aa3a46a01d05",published_at:"0x720f861bda572e891eb422c117fb7224c0f91aaf69b655f6e40bcd68f0edad41",configs:{registry_id:"0x23014734280164270fa4c58f973c00079651e730d6f46491678ea8858f3bd13a",pools_handle:"0x31c810b6fcf3bb8699384e7c61fe9f7db53a04c4c22d514b3f79b6caa86183a8",pyth_oracle_id:"0xaed73fd854dfceedb2522903feec8c0e251764f5945bd38f969473024c4fb4d0",oracle_infos_handle:"0x6951ab4b36639e79ddbd9ba4478d7f72d1c5396b9198d0864c00e796c5815b01",prices_handle:"0x20a65a0f747f4f1ad465bdb61d784bbc5080ee5d200d5dd6594a354723b8c171",global_config_id:"0x5f8371674cd8e1e9eef5542ffe8adb339e3ff3a67894b14c954c7a92e992e0c1"},clmm_configs:{global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b"}},vaultsV2:{package_id:"0xfbc91f75397ce25b3b1b01cab2bf494d2e3f9b9e89c97545d88bd616cbbfcc37",published_at:"0xfbc91f75397ce25b3b1b01cab2bf494d2e3f9b9e89c97545d88bd616cbbfcc37",configs:{registry_id:"0xb6e0d2a2457af53a83b1435ea398f9460ba8abd98686387a4399fceefdfc22e2",pools_handle:"0xc88e97a3a3bb71dfcf8cc90e6383d7e3e1dee0170fa07c9365d233568659fc8f",global_config_id:"0x05bedfb68e6bf273946f8e1f2529e8f30acdf8b287dec524973c6bae9e979743",versioned_id:"0x70bea2f242b057cda9994e9fecee121cb35ee914c360cc86f061268110b6d9ec",oracle_infos_handle:"0x4631c11bfeae9461863d233285d03e3dba14f8dfb574781f1e2cbe9b58ba903e",pyth_oracle_id:"0xc08cdf8479075b0dae05aadc76f941038a25d74dcbedd9c339f7ce5da08fab92"}},pythConfigs:{pyth_state_id:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",hermes_service_urls:{primary:"https://hermes.pyth.network"},wormhole_state_id:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pyth_package_id:"0x04e20ddf36af412a4096f9014f4a565af9e812db9a05cc40254846cf6ed0ad91",pyth_published_at:"0x04e20ddf36af412a4096f9014f4a565af9e812db9a05cc40254846cf6ed0ad91"},aggregatorUrl:"https://api-sui.cetus.zone/router_v3",providers:["CETUS","TURBOS","STEAMM","SPRINGSUI","HAEDAL","FLOWX","AFTERMATH","ALPHAFI","BLUEFIN","METASTABLE","VOLO","SCALLOP","KRIYA","FLOWXV3","DEEPBOOKV3","AFSUI","BLUEMOVE","KRIYAV3","HAEDALPMM","OBRIC"],vest:{package_id:"0xd0587f397e47d31a79d1c36710c2c28f48ff8f1e8ea73b6a54fa2ec6fdfe0a7d",published_at:"0x57731e8bd3971eca68019afecb0e11699ece6301f0d4f255969f5b4227e0c5f8",version:1,config:{versioned_id:"0xee1e2214314737df6193cc4cf6815cf8dc3b4cc1c5cc0a078c6579dda19e8552",create_event_list:[{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0xb2d502d4ef89395934de020b195ded323bfa86d7f40b65ed5b15d6b66c722a3d::lpcoin::LPCOIN",pool_id:"0x2fc6ee9183d0f1ca0d2dded02c416be6f4671bb82db55c26ce12b536812a4b8e",position_id:"0x99f7fbeaf18c88e8af7553ad2ef055772477a1851550a2e7c2d7a503420c6b05",vault_id:"0xbd6252e0d56ae5eaabf055fd6c518ee5f66c1114287ca957cc698a17c3d25b16",vault_vester_id:"0xe4196586ed151a38c7c9169c72b9e5e3f51bfea9afbc2d1f082d6bedb88b086f"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x0484a9162669957e1c1883fc2da59e3cce9afdc1eec3c72c983898dbc9e92b91::lpcoin::LPCOIN",pool_id:"0xaa020ad81e1621d98d4fb82c4acb80dc064722f24ef828ab633bef50fc28268b",position_id:"0x90918d035e37b4447e11c2043c4c4374baeb7c2cbd2729063d939d016b04770f",vault_id:"0x99db9a7d3320d31fe6e4dc4122b948162010e331c41dc279636ca75567b93497",vault_vester_id:"0xd891e4c866a67e6339d1539edd1c28db629c81d9fb8499ee029cfa3803a0819e"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x242ddc526b9cb75513bee2fc629e01d5b7dc6da4c02d39cdab0160794635334f::lpcoin::LPCOIN",pool_id:"0x2e041f3fd93646dcc877f783c1f2b7fa62d30271bdef1f21ef002cebf857bded",position_id:"0xf82ebf822b0a7eff84f0079f3998611c4fec2ae714fe627225640eb305dc5a7c",vault_id:"0xbbd2d4850e4f238d39c3aa24957d2dfbb5787fa43d6c7de306bf15abe27f29f2",vault_vester_id:"0x7cc6404b903542ff6410b8e85c9647005713f8a23166ef08a488fe267c81c8bb"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0xd418945e16ef3db737df093d0827f5ce387b36f089523e13c16e50dec6bd2524::lpcoin::LPCOIN",pool_id:"0xe01243f37f712ef87e556afb9b1d03d0fae13f96d324ec912daffc339dfdcbd2",position_id:"0x1ea05f946e995edcda18ba9fdaefd1021eddfb8d62e4fa09da89753ffb5b90ee",vault_id:"0xed754b6a3a6c7549c3d734cb7b464bccf9c805814b9e47b0cb99f43b4efcb4a6",vault_vester_id:"0xd67cd239a34852cbc2e530db2ef296bc3e4a977464309c21ce706d90a17a5d5d"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0xf21d82f767cac2e8892db252aa539c137dcf8a6d1e6ebd2d0a11c16362171df7::lpcoin::LPCOIN",pool_id:"0x72f5c6eef73d77de271886219a2543e7c29a33de19a6c69c5cf1899f729c3f17",position_id:"0x5bd93e30000eb9f3217a04c938c7f939ee33ac161f6fe7ea34bac268dbe36893",vault_id:"0x12ac7deea4b92b3e2c16687e2d2695fa8c045ec0a52844db7b2fc3876c9552aa",vault_vester_id:"0x5d87bb3db28e77604f9bd210cdde0916e95a9d37925ec3c466fa785bba3d63f9"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x2f46a040b9bc3a584a3be4d7bfbb02a5fb479da17a04c6d2860ed61d95e97f3f::lpcoin::LPCOIN",pool_id:"0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105",position_id:"0xa2141e99975e203172f62c97b1f314f845b94730f6dfdb8ab2d32d014c659bcf",vault_id:"0x41a4ab1e82f90f5965bbcd828b8ffa13bab7560bd2e352ab067e343db552f527",vault_vester_id:"0x0e4782ee96095af233a6c5219b50cd8c92bd79d84f1df7e629bcc7a094c5a09d"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x5c79c0ab2c45682aba43b1acbe5c478d947f7c8397d47447906d6cc127e180fb::lpcoin::LPCOIN",pool_id:"0xea648440bd640d3530e8a5f02c0b56da82c2efe851156c39974b901bbb0eeab1",position_id:"0x896a01cc57ba25799ec320dc25d1969f3129f2591689ce8c8dbf380c7e00bf48",vault_id:"0x5525f5a70fffd93f616c39b59f3abdd2054fc2d19f09c8a4d94950d611a43b74",vault_vester_id:"0xe116bb120d2d91f85ee419cbff73fdd9d7f87e9b085dd4de781347b51361ae17"},{clmm_vester_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",lp_coin_type:"0x8275bc774497b319db110bb97a4812a19859ab6f19dc1574746097f06103c0f9::lpcoin::LPCOIN",pool_id:"0x9e59de50d9e5979fc03ac5bcacdb581c823dbd27d63a036131e17b391f2fac88",position_id:"0xd080bfb32b9c24f8875bd5a803a417b8ca0c02f2208d0b9058692f9013db3b52",vault_id:"0xedfb22d1bbe5045fd1888bb8bc1c4bc1823ab24d40f5a4bea9f6eb9758a4b820",vault_vester_id:"0x8bc7ccefae4db25873a0692bfb0d2c7cbdbbe644574a537789b98815960155a4"}]}}},sn={"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC":{coin_type:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",price_feed_id:"0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",coin_decimals:6},"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI":{coin_type:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",price_feed_id:"0x23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",coin_decimals:9},"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS":{coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS",price_feed_id:"0xe5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",coin_decimals:9},"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP":{coin_type:"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",price_feed_id:"0x29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff",coin_decimals:6},"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX":{coin_type:"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX",price_feed_id:"0x88250f854c019ef4f88a5c073d52a18bb1c6ac437033f5932cd017d24917ab46",coin_decimals:9},"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN":{coin_type:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",price_feed_id:"0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",coin_decimals:9},"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI":{coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI",price_feed_id:"0x6120ffcf96395c70aa77e72dcb900bf9d40dccab228efca59a17b90ce423d5e8",coin_decimals:9},"0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH":{coin_type:"0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH",price_feed_id:"0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",coin_decimals:8},"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL":{coin_type:"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",price_feed_id:"0xeba0732395fae9dec4bae12e52760b35fc1c5671e2da8b449c9af4efe5d54341",coin_decimals:9},"0x3e8e9423d80e1774a7ca128fccd8bf5f1f7753be658c5e645929037f7c819040::lbtc::LBTC":{coin_type:"0x3e8e9423d80e1774a7ca128fccd8bf5f1f7753be658c5e645929037f7c819040::lbtc::LBTC",price_feed_id:"0x8f257aab6e7698bb92b15511915e593d6f8eae914452f781874754b03d0c612b",coin_decimals:8},"0x3a304c7feba2d819ea57c3542d68439ca2c386ba02159c740f7b406e592c62ea::haedal::HAEDAL":{coin_type:"0x3a304c7feba2d819ea57c3542d68439ca2c386ba02159c740f7b406e592c62ea::haedal::HAEDAL",price_feed_id:"0xe67d98cc1fbd94f569d5ba6c3c3c759eb3ffc5d2b28e64538a53ae13efad8fd1",coin_decimals:9}};function an(i){return i&&(on.fullRpcUrl=i),new fe(on)}var cn={env:"testnet",fullRpcUrl:"https://fullnode.testnet.sui.io",vaults:{package_id:"0x0a624f2dcafc9f7f381684b3d553a9837411925b6e8530b1f8f4e6ff3f1fde77",published_at:"0x36f9d8e6219e6ba4d8840165ec27676a1bcb43fc5712f87ca702ac7b5924507d",configs:{registry_id:"0xa2ebae3656c5fbdd2473caadfc077cd1780a881759a356f1a5bc0f9fd470adb9",pools_handle:"0x0df305d395f8e0359da0ac5717bc96e0e1da9792684ec8e8f6a20b7ab544f98e",pyth_oracle_id:"0x6c74aec8d4471d9b05f718c467204c9010c450b94a4e40b0b4031a7d6c386337",global_config_id:"0x8969b09cfdd72b1635263b569027ded4b91bbabd7d8cd91b21e355325e218b10",oracle_infos_handle:"0x8707c6665d202f277ffe8e7fd58684e232622a3e6826b94ba99f7569f253fa9d",prices_handle:"0x74230bb2c6a63235acbfe477ce16144afca7ccd16a458fa93f4605330b5d1c58"},clmm_configs:{global_config_id:"0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e",global_vault_id:"0xf78d2ee3c312f298882cb680695e5e8c81b1d441a646caccc058006c2851ddea"}},pythConfigs:{pyth_state_id:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c",wormhole_state_id:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",hermes_service_urls:{primary:"https://hermes-beta.pyth.network"},pyth_package_id:"0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837",pyth_published_at:"0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837"},vaultsV2:{package_id:"0x0000000000000000000000000000000000000000000000000000000000000000",published_at:"0x0000000000000000000000000000000000000000000000000000000000000000",configs:{registry_id:"0x0000000000000000000000000000000000000000000000000000000000000000",pools_handle:"0x0000000000000000000000000000000000000000000000000000000000000000",global_config_id:"0x0000000000000000000000000000000000000000000000000000000000000000",versioned_id:"0x0000000000000000000000000000000000000000000000000000000000000000",pyth_oracle_id:"0x0000000000000000000000000000000000000000000000000000000000000000",oracle_infos_handle:"0x0000000000000000000000000000000000000000000000000000000000000000"}},aggregatorUrl:"https://api-sui.devcetus.com/router_v2",providers:["CETUS","DEEPBOOK","KRIYA","KRIYAV3","FLOWX","FLOWXV3","AFTERMATH","TURBOS","HAEDAL","VOLO","AFSUI"],vest:{package_id:"0x76ccc11581265c821a666af3baee1c4162165aed504674621a39d474bb32513b",published_at:"0x76ccc11581265c821a666af3baee1c4162165aed504674621a39d474bb32513b",config:{versioned_id:"0x2c5b6227da87ce840035955e0d82725178ce53c8cd2b01934d6540feccf2a8f7",create_event_list:[{clmm_vester_id:"0x308b24963e5992f699e32db2f7088b812566a0cae580317fd3b8bf61de7f5508",lp_coin_type:"0xb0c18dcd849d4b47528831c64707f2f7f6aa1b7fd9ed5e1ac2f8ab356e031f25::lp_token::LP_TOKEN",pool_id:"0x403c7d9c1e959c029f61d970286eac8ad5bca2db2edba358585abf4dbd4ed3cd",position_id:"0xd1dbcdb1789b92772b367bc1f68d7d078b4fd3326b8bfb53750bf28585463508",vault_id:"0xed754b6a3a6c7549c3d734cb7b464bccf9c805814b9e47b0cb99f43b4efcb4a6",vault_vester_id:"0x6098c69613ed5d503ff2b81447e96408feab8f2e4bf582966a811b5b582d23e3"}]}}},ln={};function un(i){return i&&(cn.fullRpcUrl=i),new fe(cn)}var cr=(e=>(e.mainnet="mainnet",e.testnet="testnet",e))(cr||{});function ls(i){let{env:t,fullNodeUrl:e}=i;return t==="mainnet"?an(e):un(e)}var dn=["CETUS","TURBOS","STEAMM","SPRINGSUI","HAEDAL","FLOWX","AFTERMATH","ALPHAFI","BLUEFIN","METASTABLE","VOLO","SCALLOP","KRIYA","FLOWXV3","DEEPBOOKV3","AFSUI","BLUEMOVE","KRIYAV3","HAEDALPMM","OBRIC"];function lr(i){try{let{request_time:t,error:e,request_params:n,request_url:r,action:a}=i;if(window?.gtag){let o=e.message==="Request Timeout";window.gtag("event","API_Error",{request_action:a,request_url:r,request_time:t,request_params:JSON.stringify(n),error_msg:String(e)})}}catch{}}var us=16*1024,Se=class{_sdk;connection;suiPythClient;hasChangeConnection=!1;errorList=[];pythConfigs;global_config_id;pyth_oracle_id;oracle_infos_handle;vaults_published_at;versioned_id;isV2;constructor(t,e,n,r,a,o,u,d){this.vaults_published_at=n,this.pythConfigs=e,this.global_config_id=r,this.pyth_oracle_id=a,this.oracle_infos_handle=u,this.isV2=d,this.versioned_id=o;let{pyth_state_id:f,wormhole_state_id:m,hermes_service_urls:_}=e;this._sdk=t,this.hasChangeConnection=!1;let{primary:g}=_;if(g.length===0)throw new Error("primary url is empty");this.connection=new Ee.SuiPriceServiceConnection(g),this.suiPythClient=new Ee.SuiPythClient(this._sdk.FullClient,f,m)}get sdk(){return this._sdk}recordError(t,e,n){let{secondary:r,primary:a}=this.pythConfigs.hermes_service_urls,o={error:t,request_params:e,request_url:this.hasChangeConnection&&r?r:a,action:n,request_time:Date.now()};lr(o),this.errorList.push(o)}readErrorList(){let t=this.errorList;return this.errorList=[],t}async getFeedInfoList(t){let e=t.map(r=>this.getFeedInfo(r,!1));return await Promise.all(e)}priceCheck(t,e=60){let n=Math.floor(Date.now()/1e3);if(!(Math.abs(n-t.last_update_time)>e))return t}async getLatestPrice(t,e=!1){let n={},r=[];if(e?t.forEach(u=>{let d=this._sdk.getCache(`getLatestPrice_${u}`);d&&this.priceCheck(d,60)?n[u]=d:r.push(u)}):r=[...t],r.length===0)return n;let a=await this.getFeedInfoList(r);return(await this.getLatestPriceFeeds(a.map(u=>u.price_feed_id)))?.forEach((u,d)=>{let f=u.getPriceUnchecked();if(f){let{price:m,expo:_}=f,g=S(m).mul(S(10).pow(S(_))).toString(),C=a[d],k={coin_type:C.coin_type,price:g,coin_decimals:C.coin_decimals,oracle_price:0n,last_update_time:f.publishTime};k.oracle_price=Hi(BigInt(m),BigInt(_)),n[r[d]]=k,this._sdk.updateCache(`getLatestPrice_${k.coin_type}`,k)}}),n}async getPriceFeedsUpdateData(t){try{return await this.connection.getPriceFeedsUpdateData(t)}catch(e){this.recordError(e,t,"getPriceFeedsUpdateData");let{secondary:n}=this.pythConfigs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Ee.SuiPriceServiceConnection(n);try{return await this.connection.getPriceFeedsUpdateData(t)}catch(r){this.recordError(r,t,"getPriceFeedsUpdateData")}}}}async getLatestPriceFeeds(t){try{return await this.connection.getLatestPriceFeeds(t)}catch(e){this.recordError(e,t,"getLatestPriceFeeds");let{secondary:n}=this.pythConfigs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Ee.SuiPriceServiceConnection(n);try{return await this.connection.getLatestPriceFeeds(t)}catch(r){this.recordError(r,t,"getLatestPriceFeeds")}}}}async buildUpdatePythPricePayload(t,e){let{pyth_state_id:n,pyth_published_at:r,pyth_package_id:a}=this.pythConfigs,o=(await this.getFeedInfoList(t)).map(g=>g.price_feed_id);if(t.length!==o.length)throw Error("find feed id fail");let u=await this.getPriceFeedsUpdateData(o);if(!u)throw new Error("get price update data fail");if(u.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");let d=this.suiPythClient.extractVaaBytesFromAccumulatorMessage(u[0]),f=await this.suiPythClient.verifyVaas([d],e),[m]=e.moveCall({target:`${r}::pyth::create_authenticated_price_infos_using_accumulator`,typeArguments:[],arguments:[e.object(n),e.pure(fn.bcs.vector(fn.bcs.U8).serialize(Array.from(u[0]),{maxSize:us}).toBytes()),f[0],e.object(Zt)]}),_=0;for(let g of o){let C=await this.suiPythClient.getPriceFeedObjectId(g);if(!C)throw new Error(`Price feed ${g} not found, please create it first`);this.isV2?[m]=e.moveCall({target:`${this.vaults_published_at}::pyth_oracle::update_price`,typeArguments:[t[_]],arguments:[e.object(this.pyth_oracle_id),e.object(n),m,e.object(C),e.object(Zt),e.object(this.versioned_id)]}):[m]=e.moveCall({target:`${this.vaults_published_at}::pyth_oracle::update_price`,typeArguments:[t[_]],arguments:[e.object(this.pyth_oracle_id),e.object(this.global_config_id),e.object(n),m,e.object(C),e.object(Zt)]}),_+=1}return e.moveCall({target:`${r}::hot_potato_vector::destroy`,arguments:[m],typeArguments:[`${a}::price_info::PriceInfo`]}),e}getFeedInfoByJson(t){let{env:e}=this._sdk.sdkOptions,n=q(t,!1);return e==="mainnet"?sn[n]:ln[n]}async getFeedInfo(t,e){let n=`getFeedInfo_${t}`,r=this._sdk.getCache(n,e);if(r)return r;let a=this.getFeedInfoByJson(t);if(a)return a;let o=await this._sdk.FullClient.getDynamicFieldObject({parentId:this.oracle_infos_handle,name:{type:"0x1::type_name::TypeName",value:q(t,!0)}}),{fields:u}=o.data.content.fields.value,d={coin_type:t,price_feed_id:Gi(u.price_feed_id),coin_decimals:u.coin_decimals};return this._sdk.updateCache(n,d),d}};var $e=class{_sdk;pythPrice;constructor(t){this._sdk=t;let{vaults:e,pythConfigs:n}=t.sdkOptions;this.pythPrice=new Se(t,n,e.published_at,e.configs.global_config_id,e.configs.pyth_oracle_id,"",e.configs.oracle_infos_handle,!1)}get sdk(){return this._sdk}get PythPrice(){return this.pythPrice}async getProtocolFeeRate(){let t="getProtocolFeeRate",e=this._sdk.getCache(t);if(e)return e;let{configs:n}=this._sdk.sdkOptions.vaults,a=(await this._sdk.FullClient.getObject({id:n.global_config_id,options:{showContent:!0}})).data.content.fields.protocol_fee_rate;return this._sdk.updateCache(t,a),a}async getOwnerVaultsBalance(t,e){let{pool:n,clmmPool:r}=await this.getVaultAndPool(e,!0),o=(await this._sdk.FullClient.getBalance({owner:t,coinType:n.lp_token_type})).totalBalance;return Xi(t,o,n,r)}async getOwnerVaultsBalanceList(t){let{data:e}=await this.getPoolList(),n=[];for(let r=0;r<e.length;r++){let a=await this.getOwnerVaultsBalance(t,e[r].id);n.push(a)}return n}async getVaultsPositionRewarderAndFee(t){try{let{package_id:e}=this._sdk.sdkOptions.vaults,{pool:n,clmmPool:r}=await this.getVaultAndPool(t,!1),a=`getVaultsPositionRewarderAndFee_${t}`,o=this._sdk.getCache(a);if(o)return o;let{lp_token_type:u}=n,{rewarder_infos:d,id:f,coin_type_a:m,coin_type_b:_}=r,g=new Te.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...d.map(E=>E.coin_type)],lp_token_type:u,pool_id:t,clmm_pool_id:f,coin_type_a:m,coin_type_b:_},g),this.buildCollectFeePayload({lp_token_type:u,pool_id:t,clmm_pool_id:f,coin_type_a:m,coin_type_b:_},g);let C=await this._sdk.FullClient.sendSimulationTransaction(g,(0,dr.normalizeSuiAddress)("0x0")),k=`${e}::pool::FeeClaimedEvent`,P=`${e}::pool::RewardClaimedEvent`,D=[],x=[];return C?.events.forEach(E=>{let{parsedJson:O,type:T}=E;T===k&&(D.push({coin_type:q(m,!1),value:O.amount_a}),D.push({coin_type:q(_,!1),value:O.amount_b})),T===P&&x.push({coin_type:q(O.reward_type.name,!1),value:O.amount})}),this._sdk.updateCache(a,{feeList:D,rewarderList:x},10*1e3),{feeList:D,rewarderList:x}}catch{}return{feeList:[],rewarderList:[]}}async getPoolList(t="all"){let e={data:[],has_next_page:!1},{vaults:n}=this._sdk.sdkOptions,{FullClient:r}=this._sdk,a=await r.getDynamicFieldsByPage(n.configs.pools_handle,t),o=a.data.map(u=>u.name.value);return o.length>0&&((await r.batchGetObjects(o,{showContent:!0})).forEach(d=>{let f=ci(d.data.content);this._sdk.updateCache(`getPool_${f.id}`,f),e.data.push(f)}),e.next_cursor=a.next_cursor,e.has_next_page=a.has_next_page),e}async getPool(t,e=!0){let n=`getPool_${t}`,r=this._sdk.getCache(n,e);if(r)return r;let a=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),o=ci(a.data.content);return this._sdk.updateCache(n,o),o}buildCollectRewardPayload(t,e){let{coin_type_a:n,coin_type_b:r,pool_id:a,clmm_pool_id:o,lp_token_type:u,reward_coin_types:d}=t,{published_at:f,configs:m,clmm_configs:_}=this._sdk.sdkOptions.vaults;return e=e||new Te.Transaction,d.forEach(g=>{e.moveCall({target:`${f}::pool::collect_reward`,typeArguments:[n,r,u,g],arguments:[e.object(a),e.object(m.global_config_id),e.object(_.global_config_id),e.object(o),e.object(_.global_vault_id),e.object(Zt)]})}),e}buildCollectFeePayload(t,e){let{coin_type_a:n,coin_type_b:r,pool_id:a,clmm_pool_id:o,lp_token_type:u}=t,{published_at:d,configs:f,clmm_configs:m}=this._sdk.sdkOptions.vaults;return e=e||new Te.Transaction,e.moveCall({target:`${d}::pool::collect_fee`,typeArguments:[n,r,u],arguments:[e.object(a),e.object(f.global_config_id),e.object(m.global_config_id),e.object(o)]}),e}async buildDepositPayload(t,e){let{pool_id:n,amount_a:r,amount_b:a,return_lp_coin:o}=t,{pool:u,clmmPool:d}=await this.getVaultAndPool(n,!0),{rewarderList:f,feeList:m}=await this.getVaultsPositionRewarderAndFee(n),_=Ne(u.balances,f,m,d.coin_type_a,d.coin_type_b),{lp_token_type:g}=u,{rewarder_infos:C,id:k,coin_type_a:P,coin_type_b:D}=d,x=f.length>0?f.filter(W=>S(W.value.toString()).gt(0)).map(W=>q(W.coin_type,!1)):C.map(W=>q(W.coin_type,!1)),{published_at:E,configs:O,clmm_configs:T}=this._sdk.sdkOptions.vaults;e=e||new Te.Transaction,e=this.buildCollectRewardPayload({reward_coin_types:x,lp_token_type:g,pool_id:n,clmm_pool_id:k,coin_type_a:P,coin_type_b:D},e),e=this.buildCollectFeePayload({lp_token_type:g,pool_id:n,clmm_pool_id:k,coin_type_a:P,coin_type_b:D},e),e=await this.pythPrice.buildUpdatePythPricePayload(_,e),e.moveCall({target:`${E}::pool::calculate_aum`,typeArguments:[P,D,g],arguments:[e.object(n),e.object(O.global_config_id),e.object(O.pyth_oracle_id),e.object(T.global_config_id),e.object(k),e.object(Zt)]});let H=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress,P),N=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress,D),G=Ht.buildCoinForAmount(e,H,BigInt(r),P,!1,!0),$=Ht.buildCoinForAmount(e,N,BigInt(a),D,!1,!0),z=e.moveCall({target:`${E}::pool::${o?"deposit_for":"deposit"}`,typeArguments:[P,D,g],arguments:[e.object(n),e.object(O.global_config_id),e.object(O.pyth_oracle_id),e.object(T.global_config_id),e.object(k),G.target_coin,$.target_coin,e.object(Zt)]});return o?z:void 0}async buildWithdrawPayload(t,e){let{pool_id:n,burn_lp_amount:r,mode:a,slippage:o,partner:u,extra_burn:d}=t,{pool:f,clmmPool:m}=await this.getVaultAndPool(n,!0),{published_at:_,configs:g,clmm_configs:C}=this._sdk.sdkOptions.vaults;e=e||new Te.Transaction;let{lp_token_type:k,clmm_vault:P,lp_token_treasury:D}=f,{rewarder_infos:x,id:E,coin_type_a:O,coin_type_b:T,liquidity:H}=m,N=x.map(Q=>q(Q.coin_type,!1));e=this.buildCollectRewardPayload({reward_coin_types:N,lp_token_type:k,pool_id:n,clmm_pool_id:E,coin_type_a:O,coin_type_b:T},e),e=this.buildCollectFeePayload({lp_token_type:k,pool_id:n,clmm_pool_id:E,coin_type_a:O,coin_type_b:T},e);let G=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress),$,z=d?S(d.burn_lp_amount).add(S(r)).toFixed(0):S(r).toFixed(0),W=S(r).isZero();if(W&&!d)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");W?$=d.lp_burn_coin:($=Ht.buildCoinForAmount(e,G,BigInt(r),k,!1,!0).target_coin,d&&e.mergeCoins($,[d.lp_burn_coin]));let[et,qt,X]=e.moveCall({target:`${_}::pool::withdraw`,typeArguments:[O,T,k],arguments:[e.object(n),e.object(g.global_config_id),e.object(C.global_config_id),e.object(E),$,e.object(Zt)]});if(this.buildWithdrawBufferReward({reward_coin_types:N.filter(Q=>![q(O,!1),q(T,!1)].includes(Q)),pool_id:n,withdraw_cert:X,lp_token_type:k},e,G),e.moveCall({target:`${_}::pool::destory_withdraw_cert`,typeArguments:[k],arguments:[e.object(n),e.object(g.global_config_id),X]}),a!=="FixedOneSide"){if(o===void 0)throw Error("the slippage is undefined");let Q=a==="OnlyCoinA",s=Q?qt:et,l=ke(D,z,H.toString());await this.handleWithSwap(e,s,O,T,z,n,Q,o,u,[{poolID:E,ticklower:P.wrapped_position.tick_lower_index,tickUpper:P.wrapped_position.tick_upper_index,deltaLiquidity:Number(l)}]),e.transferObjects([Q?et:qt],this._sdk.senderAddress)}else e.transferObjects([et,qt],this._sdk.senderAddress);return e}async handleWithSwap(t,e,n,r,a,o,u,d,f,m){let{receive_amount_a:_,receive_amount_b:g}=await this.preCalculateWithdrawAmount({pool_id:o,mode:"FixedOneSide",burn_lp_amount:a}),C=u?r:n,k=u?n:r,P=u?g:_,D={from:C,target:k,amount:new he.default(P),byAmountIn:!0,depth:3,splitAlgorithm:void 0,splitFactor:void 0,splitCount:void 0,providers:this._sdk.sdkOptions.providers,liquidityChanges:m},x=await this._sdk.AggregatorClient.findRouters(D);if(!x)throw Error("not find Router");if(x.error!==void 0)throw Error(`find Router error : ${x.error}`);let E={router:x,inputCoin:e,slippage:d,txb:t,partner:f},O=await this._sdk.AggregatorClient.fixableRouterSwapV3(E);t.transferObjects([O],t.pure.address(this._sdk.getVerifySenderAddress()))}buildWithdrawBufferReward({reward_coin_types:t,pool_id:e,withdraw_cert:n,lp_token_type:r},a,o){let{published_at:u,configs:d}=this._sdk.sdkOptions.vaults;t.forEach(f=>{let m=a.moveCall({target:`${u}::pool::withdraw_buffer_reward`,typeArguments:[r,f],arguments:[a.object(e),a.object(d.global_config_id),n]}),_=Ht.getCoinAssets(f,o),g=Ht.selectCoinAssetGreaterThanOrEqual(_,BigInt(0));if(g.selected_coins.length>0&&!Ht.isSuiCoin(f))a.mergeCoins(g.selected_coins[0].coin_object_id,[m]);else{let C=Ht.buildCoinForAmount(a,o,BigInt(0),f,!1,!1);a.mergeCoins(C.target_coin,[m]),a.transferObjects([C.target_coin],this._sdk.senderAddress)}})}async preCalculateDepositValue(t,e){let{amount_usd:n,pool_id:r,mode:a,uuid:o}=t,{pool:u,clmmPool:d}=await this.getVaultAndPool(r,!1),{current_sqrt_price:f}=d,{tick_lower_index:m,tick_upper_index:_,coin_type_a:g,coin_type_b:C}=u.clmm_vault.wrapped_position,k="0",P="0",D=await this.pythPrice.getLatestPrice([g,C],!0),x=D[g],E=D[C];if(!x||!E)throw new Error("get coin price failed");switch(a){case"FixedOneSide":{let{amountA:O,amountB:T}=Zi(m,_,new he.default(f),n,x.price,E.price,x.coin_decimals,E.coin_decimals);k=O.toString(),P=T.toString();break}case"FlexibleBoth":{let{amountA:O,amountB:T}=ae(S(.5),S(.5),n,x.price,E.price,x.coin_decimals,E.coin_decimals);k=O.toString(),P=T.toString();break}case"OnlyCoinA":{let{amountA:O,amountB:T}=ae(S(1),S(0),n,x.price,E.price,x.coin_decimals,E.coin_decimals);k=O.toString(),P=T.toString();break}case"OnlyCoinB":{let{amountA:O,amountB:T}=ae(S(0),S(1),n,x.price,E.price,x.coin_decimals,E.coin_decimals);k=O.toString(),P=T.toString();break}default:throw new Error(`Unsupported deposit mode: ${a}`)}return e&&this.calculateDepositLpAmountBoth(u,d,k,P).then(O=>{e.onSuccess(O,o)}).catch(O=>{e.onError(O,o)}),{deposit_amount_a:k,deposit_amount_b:P,mode:a}}async preCalculateDepositAmount(t,e){let{mode:n,pool_id:r,uuid:a}=t,o="0",u="0",{pool:d,clmmPool:f}=await this.getVaultAndPool(r,!1);switch(n){case"FixedOneSide":{let{fixed_amount:m,fixed_coin_a:_}=t,{other_amount:g}=this.calculateDepositOtherSide(d,f,m,_,e,a);_?(o=m,u=g):(u=m,o=g);break}case"FlexibleBoth":{let{coin_amount_a:m,coin_amount_b:_}=t;o=m,u=_,this.calculateDepositLpAmountBoth(d,f,m,_).then(g=>{e.onSuccess(g,a)}).catch(g=>{e.onError(g,a)});break}case"OnlyCoinA":{o=t.coin_amount_a,this.calculateDepositLpAmountBoth(d,f,o,"0").then(m=>{e.onSuccess(m,a)}).catch(m=>{e.onError(m,a)});break}case"OnlyCoinB":{u=t.coin_amount_b,this.calculateDepositLpAmountBoth(d,f,"0",u).then(m=>{e.onSuccess(m,a)}).catch(m=>{e.onError(m,a)});break}default:throw new Error(`Unsupported deposit mode: ${n}`)}return{deposit_amount_a:o,deposit_amount_b:u,mode:n}}async getVaultAndPool(t,e=!1){let n=await this.getPool(t,e);if(n===void 0)throw new Error("get vaults pool failed");let r=await this._sdk.CetusClmmSDK.Pool.getPool(n.clmm_vault.clmm_pool_id,e);if(r===void 0)throw new Error("get vaults clmmPool failed");return{clmmPool:r,pool:n}}calculateDepositOtherSide(t,e,n,r,a,o){let{clmm_vault:u}=t,{current_sqrt_price:d}=e,f=u.wrapped_position.tick_lower_index,m=u.wrapped_position.tick_upper_index,_=de.estLiquidityAndCoinAmountFromOneAmounts(f,m,new he.default(n),r,!0,1,new he.default(d)),{coin_amount_a:g,coin_amount_b:C}=_;return this.calculateDepositLpAmountBoth(t,e,g.toString(),C.toString()).then(k=>{a.onSuccess(k,o)}).catch(k=>{a.onError(k,o)}),{other_amount:r?C.toString():g.toString()}}async calculateDepositLpAmountBoth(t,e,n,r){let{lp_token_treasury:a,hard_cap:o}=t,u=q(e.coin_type_a,!1),d=q(e.coin_type_b,!1),{rewarderList:f,feeList:m}=await this.getVaultsPositionRewarderAndFee(t.id),_=De(t.balances,m,f),g=await zi(this,t,e,_,!0),C=await this.pythPrice.getLatestPrice([u,d],!0),k=C[u],P=C[d];if(!k)throw Error(`not find ${u} price`);if(!P)throw Error(`not find ${d} price`);let D={};D[u]={price:k,value:n.toString()},D[d]={price:P,value:r.toString()};let x=ye(D,t.quote_type);return Re(a,x,g)}async preCalculateWithdrawAmount(t){let{mode:e,pool_id:n}=t,r="0",a="0",o="0",u="0",d,{pool:f,clmmPool:m}=await this.getVaultAndPool(n,!1);switch(e){case"FixedOneSide":let _=await this.calculateWithdrawOtherSide(f,m,t.burn_lp_amount);o=_.burn_lp_amount,r=_.receive_amount_a,a=_.receive_amount_b,u=_.remove_liquidity;break;case"OnlyCoinA":{let g=await this.calculateWithdrawOnlyCoin(f,m,t.burn_lp_amount,!0);o=g.burn_lp_amount,r=g.receive_amount_a,a=g.receive_amount_b,u=g.remove_liquidity,d=g.swap;break}case"OnlyCoinB":{let g=await this.calculateWithdrawOnlyCoin(f,m,t.burn_lp_amount,!1);o=g.burn_lp_amount,r=g.receive_amount_a,a=g.receive_amount_b,u=g.remove_liquidity,d=g.swap;break}default:throw new Error(`Unsupported withdraw mode: ${e}`)}return{remove_liquidity:u,burn_lp_amount:o,receive_amount_a:r,receive_amount_b:a,mode:e,swap:d}}async calculateWithdrawOtherSide(t,e,n){let{clmm_vault:r,lp_token_treasury:a}=t,{current_sqrt_price:o}=e,{coin_type_a:u,coin_type_b:d}=t.clmm_vault.wrapped_position,f=r.wrapped_position.tick_lower_index,m=r.wrapped_position.tick_upper_index,_=r.wrapped_position.liquidity,g=nt.tickIndexToSqrtPriceX64(f),C=nt.tickIndexToSqrtPriceX64(m),k=ke(a,n,_),{coin_amount_a:P,coin_amount_b:D}=de.getCoinAmountFromLiquidity(new he.default(k),new he.default(o),g,C,!1),x=Pe(n,t.balances,a),E=S(P.toString()).add(x[u]?.value||"0").toFixed(0),O=S(D.toString()).add(x[d]?.value||"0").toFixed(0);return{receive_amount_a:E,receive_amount_b:O,burn_lp_amount:n,mode:"FixedOneSide",remove_liquidity:k}}async calculateWithdrawOnlyCoin(t,e,n,r){let{totalReceiveAmount:a,swapAmountIn:o,swapAmountOut:u,removeLiquidity:d}=await this.calculateWithdrawOnlyCoinByLpAmount(t,e,r,n);return{receive_amount_a:r?a:"0",receive_amount_b:r?"0":a,burn_lp_amount:n,remove_liquidity:d,swap:{swap_amount_in:o,swap_amount_out:u},mode:"FixedOneSide"}}async calculateWithdrawOnlyCoinByLpAmount(t,e,n,r){let{clmm_vault:a,lp_token_treasury:o}=t,{current_sqrt_price:u}=e,{coin_type_a:d,coin_type_b:f}=a.wrapped_position,m=a.wrapped_position.tick_lower_index,_=a.wrapped_position.tick_upper_index,g=a.wrapped_position.liquidity,C=nt.tickIndexToSqrtPriceX64(m),k=nt.tickIndexToSqrtPriceX64(_),P=ke(o,r,g),{coin_amount_a:D,coin_amount_b:x}=de.getCoinAmountFromLiquidity(new he.default(P),new he.default(u),C,k,!1),E=await this.pythPrice.getLatestPrice([d,f],!0),O=E[d],T=E[f];if(!O)throw Error(`not find ${d} price`);if(!T)throw Error(`not find ${f} price`);let H=n?T:O,N=n?O:T,{quote_per_base:G}=qe(H.price,N.price),$=Pe(r,t.balances,o),z=S(D.toString()).add($[d]?.value||"0").toFixed(0),W=S(x.toString()).add($[f]?.value||"0").toFixed(0),et=n?z:W,qt=n?W:z,X=Qt(S(ue(qt,n?T.coin_decimals:O.coin_decimals)).mul(G).toString(),n?O.coin_decimals:T.coin_decimals).toString(),Q=S(et).add(X).toFixed(0);return{burn_lp_amount:r,removeLiquidity:P,is_coin_a:n,originAmount:et,swapAmountIn:qt,swapAmountOut:S(X).toFixed(0,fr.default.ROUND_DOWN),totalReceiveAmount:Q}}async getPackageConfigs(){let t={registry_id:"1",pools_handle:"",pyth_oracle_id:"1",oracle_infos_handle:"",prices_handle:"1",global_config_id:"1"},{package_id:e}=this._sdk.sdkOptions.vaults,n=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),r=oi(n);(await this._sdk.FullClient.queryEventsByPage({Transaction:r})).data.forEach(m=>{let _=m.parsedJson;if(m.type)switch((0,ur.extractStructTagFromType)(m.type).full_address){case`${e}::pool::InitEvent`:t.registry_id=_.registry_id;break;case`${e}::pyth_oracle::InitEvent`:t.pyth_oracle_id=_.pyth_oracle_id;break;case`${e}::config::InitConfigEvent`:t.global_config_id=_.global_config;break;default:break}});let o=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),u=ie(o);t.pools_handle=u.pools.fields.id.id;let d=await this._sdk.FullClient.getObject({id:t.pyth_oracle_id,options:{showContent:!0}}),f=ie(d);return t.oracle_infos_handle=f.oracle_infos.fields.id.id,t.prices_handle=f.prices.fields.id.id,this._sdk.sdkOptions.vaults.configs=t,this._sdk.sdkOptions}};var hr=require("@mysten/sui/transactions");var Ke=class{_sdk;constructor(t){this._sdk=t}get sdk(){return this._sdk}async vestNftIsAvailable(t,e){try{let n=await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"0x2::object::ID",value:t}});return!ie(n).value.fields.is_pause}catch{return!0}}async getVestCreateEventList(){let{vest:t}=this._sdk.sdkOptions;if(t===void 0)throw new Error("vest is not set config in sdk options");try{let e=`${t.package_id}::hae_vester::CreateEvent`;return(await this._sdk.FullClient.queryEventsByPage({MoveEventType:e})).data.map(r=>{let a=r.parsedJson,o={clmm_vester_id:a.clmm_vester_id,lp_coin_type:q(a.lp_coin_type.name,!1),pool_id:a.pool_id,position_id:a.position_id,vault_id:a.vault_id,vault_vester_id:a.hae_vester_id},u=`${o.vault_id}-VestCreateEvent`;return this._sdk.updateCache(u,o),o})}catch(e){throw new Error(`getVestCreateEventList error: ${e}`)}return[]}async getVaultsVestInfoList(t){let{vest:e}=this._sdk.sdkOptions;if(!e)throw new Error("vest is not set config in sdk options");let n=[];for(let o of t){let u=await this.getVaultVestEvent(o);n.push(u.vault_vester_id)}let r=[];return(await this._sdk.FullClient.batchGetObjects(n,{showContent:!0,showType:!0})).forEach(o=>{try{let u=li(o);r.push(u);let d=`${u.id}-VaultsVestInfo`;this._sdk.updateCache(d,u)}catch{}}),r}async getVaultsVestInfo(t,e=!0){let n=(await this.getVaultVestEvent(t)).vault_vester_id,r=`${n}-VaultsVestInfo`,a=this._sdk.getCache(r,e);if(a)return a;try{let o=await this._sdk.FullClient.getObject({id:n,options:{showContent:!0,showType:!0}}),u=li(o);return this._sdk.updateCache(r,u),u}catch(o){throw new Error(`getVaultsVestInfo error: ${o}`)}}async getVaultVestEvent(t){let{vest:e}=this._sdk.sdkOptions;if(!e)throw new Error("vest is not set config in sdk options");let{create_event_list:n}=ve(e),r=n.find(a=>a.vault_id===t);if(!r){let a=`${t}-VestCreateEvent`,o=this._sdk.getCache(a,!1);o?r=o:(r=(await this.getVestCreateEventList()).find(d=>d.vault_id===t),this._sdk.updateCache(a,r))}if(!r)throw new Error("vault_id not found in vest_ids_map");return r}async getOwnerVaultVestNFT(t){let{vest:e}=this._sdk.sdkOptions;if(!e)throw new Error("vest is not set config in sdk options");let n=await this._sdk.FullClient.getOwnedObjectsByPage(t,{filter:{StructType:`${e.package_id}::hae_vester::HaeVesterNFT`},options:{showContent:!0,showType:!0,showOwner:!0}}),r=[];return n.data.forEach(a=>{try{let o=Qi(a);r.push(o)}catch{}}),r}async buildRedeemPayload(t,e){let{vest:n}=this._sdk.sdkOptions,{clmm_vest:r}=this._sdk.CetusClmmSDK.sdkOptions;if(!n)throw new Error("vest is not set config in sdk options");if(!r)throw new Error("clmm_vest is not set config in clmm sdk options");let{versioned_id:a}=ve(n),{versioned_id:o,clmm_vest_id:u}=ve(r);e=e||new hr.Transaction;for(let d of t){let{vault_id:f,vesting_nft_id:m,period:_,coin_type_a:g,coin_type_b:C}=d,k=await this.getVaultVestEvent(f);e.moveCall({package:n.published_at,module:"hae_vester",function:"redeem_coin",arguments:[e.object(a),e.object(k.vault_vester_id),e.object(m),e.object(o),e.object(u),e.object(k.pool_id),e.pure.u16(_),e.object(Zt)],typeArguments:[g,C]})}return e}};var hn=require("@mysten/sui/transactions"),mr=ne(require("bn.js")),pr=require("@cetusprotocol/aggregator-sdk");var _r=require("@mysten/sui/utils"),hi=ne(require("decimal.js"));var Be=require("@cetusprotocol/dlmm-sdk");var We=class{_sdk;pythPrice;constructor(t){this._sdk=t;let{vaultsV2:e,pythConfigs:n}=t.sdkOptions;this.pythPrice=new Se(t,n,e.published_at,e.configs.global_config_id,e.configs.pyth_oracle_id,e.configs.versioned_id,e.configs.oracle_infos_handle,!0)}get PythPrice(){return this.pythPrice}get sdk(){return this._sdk}async getOwnerVaultsBalance(t,e){let{pool:n,dlmmPool:r}=await this.getVaultAndPool(e,!1),o=(await this._sdk.FullClient.getBalance({owner:t,coinType:n.lp_token_type})).totalBalance;return await fi(this._sdk,o,n,r,t)}async getOwnerVaultsBalanceList(t){let{data:e}=await this.getPoolList(),n=[];for(let r=0;r<e.length;r++){let a=await this.getOwnerVaultsBalance(t,e[r].id);n.push(a)}return n}async getVaultsPositionRewarderAndFee(t,e,n=!0){try{let{pool:r,dlmmPool:a}=await this.getVaultAndPool(t,!1),o=`getVaultsV2PositionRewarderAndFee_${t}_${e}`,u=this._sdk.getCache(o);if(u)return u;let{lp_token_type:d}=r,{reward_manager:f,id:m,coin_type_a:_,coin_type_b:g}=a,C=new hn.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...f.rewards.map(x=>x.reward_coin)],lp_token_type:d,pool_id:t,certified_pool_id:m,position_id:e,coin_type_a:_,coin_type_b:g},C),n&&this.buildCollectFeePayload({lp_token_type:d,pool_id:t,certified_pool_id:m,position_id:e,coin_type_a:_,coin_type_b:g},C);let k=await this._sdk.FullClient.sendSimulationTransaction(C,(0,_r.normalizeSuiAddress)("0x0")),P=[],D=[];return k?.events.forEach(x=>{let{parsedJson:E,type:O}=x;O.includes("CollectDlmmFeeEvent")&&(P.push({coin_type:q(_,!1),value:E.amount_a}),P.push({coin_type:q(g,!1),value:E.amount_b})),O.includes("CollectDlmmRewardEvent")&&D.push({coin_type:q(E.reward_type.name,!1),value:E.amount})}),this._sdk.updateCache(o,{feeList:P,rewarderList:D},10*1e3),{feeList:P,rewarderList:D}}catch{}return{feeList:[],rewarderList:[]}}async getPoolList(t="all"){let e={data:[],has_next_page:!1},{vaultsV2:n}=this._sdk.sdkOptions,{FullClient:r}=this._sdk,a=await r.getDynamicFieldsByPage(n.configs.pools_handle,t),o=a.data.map(u=>u.name.value);if(o.length>0){let u=await this.getAssignPoolList(o);e.data.push(...u),e.next_cursor=a.next_cursor,e.has_next_page=a.has_next_page}return e}async getPool(t,e=!0){let n=`getPool_${t}`,r=this._sdk.getCache(n,e);if(r)return r;let a=await this.getAssignPoolList([t]);if(a.length>0){let o=a[0];return this._sdk.updateCache(n,o),o}throw new Error(`get pool failed ${t}`)}async getAssignPoolList(t){let e=[];if(t.length>0){(await this._sdk.FullClient.batchGetObjects(t,{showContent:!0})).forEach(a=>{let o=en(a.data.content);e.push(o)});let r=e.map(a=>a.id);if(r.length>0){let a=await this.geMarketList(r);e.forEach(o=>{let u=a[o.id];u&&(o.markets=[u])})}}return e}async geMarketList(t){let e={},n=t.map(o=>rn(o));(await this._sdk.FullClient.batchGetObjects(n,{showContent:!0})).forEach(o=>{let u=Yi(o?.data?.content);e[u.vault_id]=u});let a=Object.values(e);if(a.length>0){let o=0;for(let u of a){let d=await this.getMarketPositionList(u.positions_handle.id);a[o].position_list=d,o++}}return e}async getMarketPositionList(t){let e=[],r=(await this._sdk.FullClient.getDynamicFieldsByPage(t)).data.map(o=>o.objectId);return(await this._sdk.FullClient.batchGetObjects(r,{showContent:!0})).forEach(o=>{let u=tn(o?.data?.content);e.push(u)}),e}buildCollectRewardPayload(t,e){let{reward_coin_types:n,lp_token_type:r,pool_id:a,certified_pool_id:o,position_id:u,coin_type_a:d,coin_type_b:f,withdraw_cert:m}=t,{published_at:_,configs:g}=this._sdk.sdkOptions.vaultsV2,{dlmm_pool:C}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:k,global_config_id:P}=ve(C);m?n.forEach(D=>{e.moveCall({target:`${_}::vault::collect_dlmm_reward_on_withdraw`,typeArguments:[d,f,r,D],arguments:[e.object(a),m,e.object(o),e.object(u),e.object(P),e.object(k),e.object(g.versioned_id)]})}):n.forEach(D=>{e.moveCall({target:`${_}::vault::collect_dlmm_reward`,typeArguments:[d,f,r,D],arguments:[e.object(a),e.object(o),e.object(u),e.object(P),e.object(k),e.object(g.versioned_id)]})})}buildCollectFeePayload(t,e){let{lp_token_type:n,pool_id:r,certified_pool_id:a,position_id:o,coin_type_a:u,coin_type_b:d,withdraw_cert:f}=t,{published_at:m,configs:_}=this._sdk.sdkOptions.vaultsV2,{dlmm_pool:g}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:C,global_config_id:k}=ve(g);f?e.moveCall({target:`${m}::vault::collect_dlmm_fee_on_withdraw`,typeArguments:[u,d,n],arguments:[e.object(r),f,e.object(a),e.object(o),e.object(k),e.object(C),e.object(_.versioned_id)]}):e.moveCall({target:`${m}::vault::collect_dlmm_fee`,typeArguments:[u,d,n],arguments:[e.object(r),e.object(a),e.object(o),e.object(k),e.object(C),e.object(_.versioned_id)]})}async buildDepositPayload(t,e){let{published_at:n,configs:r}=this._sdk.sdkOptions.vaultsV2,{pool_id:a,amount_a:o,amount_b:u,return_lp_coin:d}=t,{pool:f,dlmmPool:m}=await this.getVaultAndPool(a,!1),{coin_type_a:_,coin_type_b:g,markets:C,lp_token_type:k}=f,{reward_manager:P,id:D}=m,x=C[0].position_list[0].position.id,{rewarderList:E}=await this.getVaultsPositionRewarderAndFee(a,x,!1),O=Ne(f.buffer_assets,E,[],_,g),T=E.length>0?E.filter(W=>S(W.value.toString()).gt(0)).map(W=>q(W.coin_type,!1)):P.rewards.map(W=>q(W.reward_coin,!1));this.buildCollectRewardPayload({reward_coin_types:T,lp_token_type:k,pool_id:a,certified_pool_id:C[0].position_list[0].position.pool_id,position_id:x,coin_type_a:_,coin_type_b:g},e),await this.pythPrice.buildUpdatePythPricePayload(O,e);let{dlmm_pool:H}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:N}=ve(H);e.moveCall({target:`${n}::vault::calculate_dlmm_position_amounts`,typeArguments:[_,g,k],arguments:[e.object(a),e.object(r.pyth_oracle_id),e.object(D),e.object(x),e.object(N),e.object(r.versioned_id),e.object(Zt)]}),e.moveCall({target:`${n}::vault::calculate_aum`,typeArguments:[k],arguments:[e.object(a),e.object(r.pyth_oracle_id),e.object(r.versioned_id),e.object(Zt)]});let G=Ht.buildCoinWithBalance(BigInt(o),_,e),$=Ht.buildCoinWithBalance(BigInt(u),g,e),z=e.moveCall({target:`${n}::vault::deposit`,typeArguments:[_,g,k],arguments:[e.object(a),e.object(r.global_config_id),e.object(r.pyth_oracle_id),G,$,e.object(Zt),e.object(r.versioned_id)]});if(d)return z;e.transferObjects([z],this._sdk.getVerifySenderAddress())}async buildWithdrawPayload(t,e){let{pool_id:n,burn_lp_amount:r,mode:a,slippage:o,partner:u,extra_burn:d}=t,{pool:f,dlmmPool:m}=await this.getVaultAndPool(n,!0),{lp_token_type:_,coin_type_a:g,coin_type_b:C,markets:k}=f,{id:P,reward_manager:D}=m,x=k[0].position_list[0].position.id;e=e||new hn.Transaction;let E,O=d?S(d.burn_lp_amount).add(S(r)).toFixed(0):S(r).toFixed(0),T=S(r).isZero();if(T&&!d)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");T?E=d.lp_burn_coin:(E=Ht.buildCoinWithBalance(BigInt(r),_,e),d&&d.lp_burn_coin&&e.mergeCoins(E,[d.lp_burn_coin]));let{published_at:H,configs:N}=this._sdk.sdkOptions.vaultsV2,{config:G}=this._sdk.CetusDlmmSDK.sdkOptions.dlmm_pool,$=e.moveCall({target:`${H}::vault::new_withdraw_cert`,typeArguments:[_],arguments:[e.object(n),E,e.object(N.versioned_id)]});e.moveCall({target:`${H}::vault::withdraw_dlmm`,typeArguments:[g,C,_],arguments:[e.object(n),$,e.object(P),e.object(x),e.object(G.global_config_id),e.object(G.versioned_id),e.object(N.versioned_id),e.object(Zt)]});let z=D.rewards.map(Q=>q(Q.reward_coin,!1));this.buildCollectRewardPayload({reward_coin_types:z,lp_token_type:_,pool_id:n,certified_pool_id:k[0].position_list[0].position.pool_id,position_id:x,coin_type_a:g,coin_type_b:C,withdraw_cert:$},e),this.buildCollectFeePayload({lp_token_type:_,pool_id:n,certified_pool_id:k[0].position_list[0].position.pool_id,position_id:x,coin_type_a:g,coin_type_b:C,withdraw_cert:$},e),e.moveCall({target:`${H}::vault::finalize_buffer_assets`,typeArguments:[_],arguments:[e.object(n),$,e.object(N.versioned_id)]});let W=new Set;z.forEach(Q=>W.add(Q)),W.add(g),W.add(C);let et=Array.from(W),qt=a!=="FixedOneSide"?[a==="OnlyCoinA"?C:g]:[],X=this.buildWithdrawBufferReward({reward_coin_types:et,pool_id:n,withdraw_cert:$,lp_token_type:_,not_transfer_coin_types:qt},e);if(e.moveCall({target:`${H}::vault::destroy_withdraw_cert`,typeArguments:[_],arguments:[e.object(n),$,e.object(N.versioned_id)]}),a!=="FixedOneSide"){if(o===void 0)throw Error("the slippage is undefined");let Q=a==="OnlyCoinA",s=Q?C:g,l=X.find(h=>h.coin_type===s).reward_coin_object_id;await this.handleWithSwap(e,l,g,C,O,n,Q,o,u)}}async handleWithSwap(t,e,n,r,a,o,u,d,f){let{receive_amount_a:m,receive_amount_b:_}=await this.preCalculateWithdrawAmount({pool_id:o,mode:"FixedOneSide",burn_lp_amount:a}),g=u?r:n,C=u?n:r,k=u?_:m,P={from:g,target:C,amount:new mr.default(k),byAmountIn:!0,depth:3,splitAlgorithm:void 0,splitFactor:void 0,splitCount:void 0,providers:this._sdk.sdkOptions.providers},D=await this._sdk.AggregatorClient.findRouters(P);if(!D)throw Error("not find Router");if(D.error!==void 0)throw Error(`find Router error : ${D.error}`);let x={router:D,inputCoin:e,slippage:d,txb:t,partner:f},E=await this._sdk.AggregatorClient.fixableRouterSwapV3(x);t.transferObjects([E],t.pure.address(this._sdk.getVerifySenderAddress()))}buildWithdrawBufferReward({reward_coin_types:t,pool_id:e,withdraw_cert:n,lp_token_type:r,not_transfer_coin_types:a},o){let{published_at:u,configs:d}=this._sdk.sdkOptions.vaultsV2;return t.map(f=>{let m=o.moveCall({target:`${u}::vault::withdraw_asset`,typeArguments:[r,f],arguments:[o.object(e),n,o.object(d.versioned_id)]});return a.includes(f)||o.transferObjects([m],o.pure.address(this._sdk.getVerifySenderAddress())),{coin_type:f,reward_coin_object_id:m}})}async preCalculateDepositValue(t,e){let{amount_usd:n,pool_id:r,mode:a,uuid:o}=t,{pool:u,dlmmPool:d}=await this.getVaultAndPool(r,!1),{coin_type_a:f,coin_type_b:m}=u,_=await this.pythPrice.getLatestPrice([f,m],!0),g=_[f],C=_[m];if(!g)throw new Error(`get ${f} price failed`);if(!C)throw new Error(`get ${m} price failed`);let k="0",P="0";switch(a){case"FlexibleBoth":{let{position_amount_a_rate:x,position_amount_b_rate:E}=await this.calculatePositionValueRates(u,d,_),{amountA:O,amountB:T}=ae(x,E,n,g.price,C.price,g.coin_decimals,C.coin_decimals);k=O,P=T;break}case"OnlyCoinA":{let{amountA:x,amountB:E}=ae(S(1),S(0),n,g.price,C.price,g.coin_decimals,C.coin_decimals);k=x,P=E;break}case"OnlyCoinB":{let{amountA:x,amountB:E}=ae(S(0),S(1),n,g.price,C.price,g.coin_decimals,C.coin_decimals);k=x,P=E;break}}return await this.preCalculateDepositAmount({mode:a,pool_id:r,uuid:o,coin_amount_a:k,coin_amount_b:P},e)}async preCalculateDepositAmount(t,e){let{mode:n,pool_id:r,uuid:a}=t,{pool:o,dlmmPool:u}=await this.getVaultAndPool(r,!1);switch(n){case"FixedOneSide":{let{fixed_amount:d,fixed_coin_a:f}=t;return await this.calculateDepositOtherSide(o,u,d,f,e,a)}case"FlexibleBoth":{let{coin_amount_a:d,coin_amount_b:f}=t;return await this.calculateDepositFlexibleBoth(o,u,d,f,e,a)}case"OnlyCoinA":{let{coin_amount_a:d}=t;return await this.calculateDepositFlexibleBoth(o,u,d,"0",e,a)}case"OnlyCoinB":{let{coin_amount_b:d}=t;return await this.calculateDepositFlexibleBoth(o,u,"0",d,e,a)}}throw new Error(`Unsupported deposit mode: ${n}`)}async getVaultAndPool(t,e=!1){let n=await this.getPool(t,e);if(n===void 0)throw new Error("get vaults pool failed");let r=n.markets[0].position_list[0].position.pool_id,a=await this._sdk.CetusDlmmSDK.Pool.getPool(r,e);if(a===void 0)throw new Error("get vaults dlmmPool failed");return{dlmmPool:a,pool:n}}async calculatePositionValueRates(t,e,n){let{lp_token_treasury:r,coin_type_a:a,coin_type_b:o}=t;if(S(r).eq(0))return{position_amount_a_rate:S(.5),position_amount_b_rate:S(.5)};let{position_amount_a:u,position_amount_b:d}=await fi(this._sdk,r,t,e,""),f=n[a],m=n[o];if(!f)throw Error(`not find ${a} price`);if(!m)throw Error(`not find ${o} price`);let _=S(ue(u,f.coin_decimals)).mul(f.price),g=S(ue(d,m.coin_decimals)).mul(m.price),C=S(_).add(g),k=S(_).div(C),P=S(1).sub(k);return{position_amount_a_rate:k,position_amount_b_rate:P}}async calculateDepositAmountsV2(t,e,n,r){let{markets:a}=t,o=a[0].position_list[0].position,u=await this._sdk.CetusDlmmSDK.Pool.getBinInfo(e.bin_manager.bin_manager_handle,e.active_id,e.bin_step,!1),d=Be.BinUtils.getPricePerLamportFromBinId(e.active_id,e.bin_step),f=S(d).mul(1-.05),m=S(d).mul(1+.05),_=Be.BinUtils.getBinIdFromLamportPrice(f.toString(),e.bin_step,!1),g=Be.BinUtils.getBinIdFromLamportPrice(m.toString(),e.bin_step,!1),C={pool_id:o.pool_id,coin_amount:S(r).mul(1e5).toFixed(0),fix_amount_a:n,active_id:e.active_id,bin_step:e.bin_step,lower_bin_id:_,upper_bin_id:g,strategy_type:Be.StrategyType.Spot,active_bin_of_pool:u},k=await this._sdk.CetusDlmmSDK.Position.calculateAddLiquidityInfo(C),{amount_a:P,amount_b:D}=k;return{deposit_amount_a:S(P).div(1e5).toFixed(0),deposit_amount_b:S(D).div(1e5).toFixed(0)}}async calculateDepositAmounts(t,e,n,r){let{coin_type_a:a,coin_type_b:o}=t,u=await this.pythPrice.getLatestPrice([a,o],!0),d=u[a],f=u[o];if(!d)throw Error(`not find ${a} price`);if(!f)throw Error(`not find ${o} price`);let m=S(ue(r,n?d.coin_decimals:f.coin_decimals));n?m=S(m).mul(d.price):m=S(m).mul(f.price);let{position_amount_a_rate:_,position_amount_b_rate:g}=await this.calculatePositionValueRates(t,e,u),C,k;if(n){let P=S(m).div(_);C=r,k=S(Qt(P.mul(g).div(f.price).toString(),f.coin_decimals)).toFixed(0,hi.default.ROUND_FLOOR)}else{let P=S(m).div(g);C=S(Qt(P.mul(_).div(d.price).toString(),d.coin_decimals)).toFixed(0,hi.default.ROUND_FLOOR),k=r}return{deposit_amount_a:C,deposit_amount_b:k}}async calculateDepositOtherSide(t,e,n,r,a,o){let{deposit_amount_a:u,deposit_amount_b:d}=await this.calculateDepositAmountsV2(t,e,r,n);if(a)this.calculateDepositLpAmountBoth(t,u,d).then(f=>{a.onSuccess(f,o)}).catch(f=>{a.onError(f,o)});else{let f=await this.calculateDepositLpAmountBoth(t,u,d);return{deposit_amount_a:u,deposit_amount_b:d,lp_amount:f,uuid:o,mode:"FixedOneSide"}}return{deposit_amount_a:u,deposit_amount_b:d,lp_amount:void 0,uuid:o,mode:"FixedOneSide"}}async calculateDepositFlexibleBoth(t,e,n,r,a,o){if(a)this.calculateDepositLpAmountBoth(t,n,r).then(u=>{a.onSuccess(u,o)}).catch(u=>{a.onError(u,o)});else{let u=await this.calculateDepositLpAmountBoth(t,n,r);return{deposit_amount_a:n,deposit_amount_b:r,lp_amount:u,uuid:o,mode:"FlexibleBoth"}}return{deposit_amount_a:n,deposit_amount_b:r,lp_amount:void 0,uuid:o,mode:"FlexibleBoth"}}async calculateDepositLpAmountBoth(t,e,n){let{lp_token_treasury:r,markets:a,quote_type:o,coin_type_a:u,coin_type_b:d}=t,f=q(u,!1),m=q(d,!1),{rewarderList:_,feeList:g}=await this.getVaultsPositionRewarderAndFee(t.id,a[0].position_list[0].position.id),C=De(t.buffer_assets,g,_),k=await nn(this._sdk,t,C,!0),P=await this.pythPrice.getLatestPrice([f,m],!0),D=P[f],x=P[m];if(!D)throw Error(`not find ${f} price`);if(!x)throw Error(`not find ${m} price`);let E={};E[f]={price:D,value:e.toString()},E[m]={price:x,value:n.toString()};let O=ye(E,o);return Re(r,O,k)}async preCalculateWithdrawAmount(t){let{mode:e,pool_id:n}=t,{pool:r,dlmmPool:a}=await this.getVaultAndPool(n,!1);switch(e){case"FixedOneSide":{let{burn_lp_amount:o}=t;return await this.calculateWithdrawOtherSide(r,a,o)}case"OnlyCoinA":return await this.calculateWithdrawOnlyCoin(r,a,t.burn_lp_amount,!0);case"OnlyCoinB":return await this.calculateWithdrawOnlyCoin(r,a,t.burn_lp_amount,!1)}throw new Error(`Unsupported withdraw mode: ${e}`)}async calculateWithdrawOtherSide(t,e,n){let{receive_amount_a:r,receive_amount_b:a}=await Ue(this._sdk,n,t,e);return{receive_amount_a:r,receive_amount_b:a,burn_lp_amount:n,mode:"FixedOneSide"}}async calculateWithdrawOnlyCoin(t,e,n,r){let{totalReceiveAmount:a,swapAmountIn:o,swapAmountOut:u}=await this.calculateWithdrawOnlyCoinByLpAmount(t,e,r,n);return{receive_amount_a:r?a:"0",receive_amount_b:r?"0":a,burn_lp_amount:n,swap:{swap_amount_in:o,swap_amount_out:u},mode:r?"OnlyCoinA":"OnlyCoinB"}}async calculateWithdrawOnlyCoinByLpAmount(t,e,n,r){let{coin_type_a:a,coin_type_b:o}=t,{receive_amount_a:u,receive_amount_b:d}=await Ue(this._sdk,r,t,e),f=await this.pythPrice.getLatestPrice([a,o],!0),m=f[a],_=f[o];if(!m)throw Error(`not find ${a} price`);if(!_)throw Error(`not find ${o} price`);let g=n?_:m,C=n?m:_,{quote_per_base:k}=qe(g.price,C.price),P=n?u:d,D=n?d:u,x=Qt(S(ue(D,n?_.coin_decimals:m.coin_decimals)).mul(k).toString(),n?m.coin_decimals:_.coin_decimals).toString(),E=S(P).add(x).toFixed(0);return{burn_lp_amount:r,is_coin_a:n,originAmount:P,swapAmountIn:D,swapAmountOut:S(x).toFixed(0,hi.default.ROUND_DOWN),totalReceiveAmount:E}}async getPackageConfigs(){let t={registry_id:"1",pools_handle:"",pyth_oracle_id:"1",oracle_infos_handle:"",prices_handle:"1",global_config_id:"1"},{package_id:e}=this._sdk.sdkOptions.vaults,n=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),r=oi(n);(await this._sdk.FullClient.queryEventsByPage({Transaction:r})).data.forEach(m=>{let _=m.parsedJson;if(m.type)switch((0,pr.extractStructTagFromType)(m.type).full_address){case`${e}::pool::InitEvent`:t.registry_id=_.registry_id;break;case`${e}::pyth_oracle::InitEvent`:t.pyth_oracle_id=_.pyth_oracle_id;break;case`${e}::config::InitConfigEvent`:t.global_config_id=_.global_config;break;default:break}});let o=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),u=ie(o);t.pools_handle=u.pools.fields.id.id;let d=await this._sdk.FullClient.getObject({id:t.pyth_oracle_id,options:{showContent:!0}}),f=ie(d);return t.oracle_infos_handle=f.oracle_infos.fields.id.id,t.prices_handle=f.prices.fields.id.id,this._sdk.sdkOptions.vaults.configs=t,this._sdk.sdkOptions}};var br=ne(require("@cetusprotocol/dlmm-sdk")),fe=class{_sdkOptions;_senderAddress="";_vaults;_vaultsV2;_aggregatorClient;_vest;_cetusClmmSDK;_cetusDlmmSDK;constructor(t){(!t.providers||t.providers.length===0)&&(t.providers=dn),this._sdkOptions=t,this._cetusClmmSDK=t.env==="testnet"?mn.CetusClmmSDK.createSDK({env:"testnet",full_rpc_url:t.fullRpcUrl}):mn.CetusClmmSDK.createSDK({env:"mainnet",full_rpc_url:t.fullRpcUrl}),this._cetusDlmmSDK=br.default.createSDK({env:t.env,full_rpc_url:t.fullRpcUrl}),this._vaults=new $e(this),this._vaultsV2=new We(this);let{primary:e,secondary:n}=t.pythConfigs.hermes_service_urls,r=[e,n].filter(Boolean);this._aggregatorClient=new Ze.AggregatorClient({endpoint:t.aggregatorUrl,signer:(0,mi.normalizeSuiAddress)("0x0"),client:new gr.SuiClient({url:t.fullRpcUrl}),env:t.env==="testnet"?Ze.Env.Testnet:Ze.Env.Mainnet,pythUrls:r}),this._vest=new Ke(this)}get senderAddress(){return this._senderAddress}set senderAddress(t){this._senderAddress=t,this.CetusClmmSDK.setSenderAddress(t)}get sdkOptions(){return this._sdkOptions}get Vaults(){return this._vaults}get VaultsV2(){return this._vaultsV2}get FullClient(){return this._cetusClmmSDK.FullClient}get AggregatorClient(){return this._aggregatorClient}get CetusClmmSDK(){return this._cetusClmmSDK}get CetusDlmmSDK(){return this._cetusDlmmSDK}get Vest(){return this._vest}getVerifySenderAddress(){if(this.senderAddress.length===0||!(0,mi.isValidSuiAddress)(this.senderAddress))throw Error("this sdk senderAddress is illegal");return this.senderAddress}async getOwnerCoinAssets(t,e){return await this._cetusClmmSDK.FullClient.getOwnerCoinAssets(t,e)}async getOwnerCoinBalances(t,e){return await this._cetusClmmSDK.FullClient.getOwnerCoinBalances(t,e)}updateCache(t,e,n=$n){this.CetusClmmSDK.updateCache(t,e,n)}getCache(t,e=!1){return this.CetusClmmSDK.getCache(t,e)}};var ds=fe;0&&(module.exports={PythPriceModule,SdkEnv,VaultsModule,VaultsModuleV2,VestModule,VolatileVaultsSDK,buildDLMMMarket,buildDLMMMarketId,buildDLMMMarketPosition,buildDLMMPositionId,buildPoolData,buildPoolV2Data,buildVaultsBalance,buildVaultsBalanceV2,calculateAum,calculateAumV2,calculateDepositRatioFixTokenA,calculateTotalAumBasedOnQuote,checkIsMinOrMaxIndex,convertU64BytesToDecimal,defaultProvider,estCoinAmountsFromTotalAmount,feed_map_mainnet,feed_map_testnet,getAmountBalanceByLpAmount,getCoinAmountsFromRatio,getPositionPriceRange,getPriceWithFormattedDecimals,getPrimitivePricesFromBaseQuote,getQuotePerBaseAndBasePerQuote,getShareBufferAssets,getUpdatePriceType,getVaultValidBalances,get_lp_amount_by_liquidity,get_lp_amount_by_tvl,get_share_liquidity_by_amount,initMainnetSDK,initTestnetSDK,initVaultSDK,oraclePriceMultiplierDecimal,parseVaultVestNFT,parseVaultsVestInfo,printTransaction,toSuiObjectId,vaults_mainnet,vaults_testnet});
2
2
  /*! Bundled license information:
3
3
 
4
4
  @cetusprotocol/common-sdk/dist/index.mjs: