haedal-vault-sdk 2.1.0 → 2.1.1

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 yr=Object.create;var Ge=Object.defineProperty;var vr=Object.getOwnPropertyDescriptor;var Mr=Object.getOwnPropertyNames;var Cr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var Pr=(i,t)=>{for(var e in t)Ge(i,e,{get:t[e],enumerable:!0})},Vn=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Mr(t))!Sr.call(i,r)&&r!==e&&Ge(i,r,{get:()=>t[r],enumerable:!(n=vr(t,r))||n.enumerable});return i};var oe=(i,t,e)=>(e=i!=null?yr(Cr(i)):{},Vn(t||!i||!i.__esModule?Ge(e,"default",{value:i,enumerable:!0}):e,i)),kr=i=>Vn(Ge({},"__esModule",{value:!0}),i);var hs={};Pr(hs,{PythPriceModule:()=>Ae,SdkEnv:()=>lr,VaultsModule:()=>We,VaultsModuleV2:()=>ze,VestModule:()=>Ze,VolatileVaultsSDK:()=>he,buildDLMMMarket:()=>Yi,buildDLMMMarketId:()=>rn,buildDLMMMarketPosition:()=>tn,buildDLMMPositionId:()=>ls,buildPoolData:()=>je,buildPoolV2Data:()=>en,buildVaultsBalance:()=>Xi,buildVaultsBalanceV2:()=>hi,calcExactSwapAmount:()=>Ke,calculateAum:()=>zi,calculateAumV2:()=>nn,calculateDepositRatioFixTokenA:()=>sr,calculateTotalAumBasedOnQuote:()=>Me,checkIsMinOrMaxIndex:()=>ci,convertU64BytesToDecimal:()=>rs,default:()=>fs,defaultProvider:()=>dn,estCoinAmountsFromTotalAmount:()=>Zi,feed_map_mainnet:()=>sn,feed_map_testnet:()=>ln,getAmountBalanceByLpAmount:()=>$e,getCoinAmountsFromRatio:()=>ue,getPositionPriceRange:()=>as,getPriceWithFormattedDecimals:()=>Gi,getPrimitivePricesFromBaseQuote:()=>ar,getQuotePerBaseAndBasePerQuote:()=>qe,getShareBufferAssets:()=>ke,getUpdatePriceType:()=>Ue,getVaultValidBalances:()=>Ne,get_lp_amount_by_liquidity:()=>ss,get_lp_amount_by_tvl:()=>Re,get_share_liquidity_by_amount:()=>Pe,initMainnetSDK:()=>an,initTestnetSDK:()=>un,initVaultSDK:()=>us,oraclePriceMultiplierDecimal:()=>Se,parseVaultVestNFT:()=>Qi,parseVaultsVestInfo:()=>ui,printTransaction:()=>os,toSuiObjectId:()=>Hi,vaults_mainnet:()=>on,vaults_testnet:()=>cn});module.exports=kr(hs);var br=require("@mysten/sui/client"),mi=require("@mysten/sui/utils"),Xe=require("@cetusprotocol/aggregator-sdk");var Fr=require("@mysten/sui/utils"),jr=require("@mysten/sui/client"),qr=require("@mysten/sui/utils"),Rr=require("@mysten/sui/keypairs/ed25519"),Nr=require("@mysten/sui/keypairs/secp256k1"),Ce=require("@mysten/sui/utils"),Fi=require("@mysten/sui/transactions"),jo=require("@mysten/sui/bcs"),qo=require("@mysten/sui/utils"),Ro=require("@mysten/sui/graphql/schemas/latest"),No=require("@mysten/sui/graphql"),Ni=require("@mysten/sui/client"),Ar=Object.create,Un=Object.defineProperty,Or=Object.getOwnPropertyDescriptor,xr=Object.getOwnPropertyNames,Dr=Object.getPrototypeOf,Br=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')}),Vr=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Tr=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of xr(t))!Br.call(i,r)&&r!==e&&Un(i,r,{get:()=>t[r],enumerable:!(n=Or(t,r))||n.enumerable});return i},Fe=(i,t,e)=>(e=i!=null?Ar(Dr(i)):{},Tr(t||!i||!i.__esModule?Un(e,"default",{value:i,enumerable:!0}):e,i)),Ie=Vr((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 b,M,C=0;if(h==="be")for(p=s.length-1,b=0;p>=0;p-=3)M=s[p]|s[p-1]<<8|s[p-2]<<16,this.words[b]|=M<<C&67108863,this.words[b+1]=M>>>26-C&67108863,C+=24,C>=26&&(C-=26,b++);else if(h==="le")for(p=0,b=0;p<s.length;p+=3)M=s[p]|s[p+1]<<8|s[p+2]<<16,this.words[b]|=M<<C&67108863,this.words[b+1]=M>>>26-C&67108863,C+=24,C>=26&&(C-=26,b++);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 b=0,M=0,C;if(h==="be")for(p=s.length-1;p>=l;p-=2)C=f(s,l,p)<<b,this.words[M]|=C&67108863,b>=18?(b-=18,M+=1,this.words[M]|=C>>>26):b+=8;else{var w=s.length-l;for(p=w%2===0?l+1:l;p<s.length;p+=2)C=f(s,l,p)<<b,this.words[M]|=C&67108863,b>=18?(b-=18,M+=1,this.words[M]|=C>>>26):b+=8}this._strip()};function m(s,l,h,p){for(var b=0,M=0,C=Math.min(s.length,h),w=l;w<C;w++){var c=s.charCodeAt(w)-48;b*=p,c>=49?M=c-49+10:c>=17?M=c-17+10:M=c,r(c>=0&&M<p,"Invalid character"),b+=M}return b}o.prototype._parseBase=function(s,l,h){this.words=[0],this.length=1;for(var p=0,b=1;b<=67108863;b*=l)p++;p--,b=b/l|0;for(var M=s.length-h,C=M%p,w=Math.min(M,M-C)+h,c=0,y=h;y<w;y+=p)c=m(s,y,y+p,l),this.imuln(b),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(C!==0){var V=1;for(c=m(s,y,s.length,l),y=0;y<C;y++)V*=l;this.imuln(V),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 v=["","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"],S=[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,b=0,M=0;M<this.length;M++){var C=this.words[M],w=((C<<p|b)&16777215).toString(16);b=C>>>24-p&16777215,p+=2,p>=26&&(p-=26,M--),b!==0||M!==this.length-1?h=v[6-w.length]+w+h:h=w+h}for(b!==0&&(h=b.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=S[s],y=P[s];h="";var V=this.clone();for(V.negative=0;!V.isZero();){var T=V.modrn(y).toString(s);V=V.idivn(y),V.isZero()?h=T+h:h=v[c-T.length]+T+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(),b=h||Math.max(1,p);r(p<=b,"byte array longer than desired length"),r(b>0,"Requested array length <= 0");var M=D(s,b),C=l==="le"?"LE":"BE";return this["_toArrayLike"+C](M,p),M},o.prototype._toArrayLikeLE=function(s,l){for(var h=0,p=0,b=0,M=0;b<this.length;b++){var C=this.words[b]<<M|p;s[h++]=C&255,h<s.length&&(s[h++]=C>>8&255),h<s.length&&(s[h++]=C>>16&255),M===6?(h<s.length&&(s[h++]=C>>24&255),p=0,M=0):(p=C>>>24,M+=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,b=0,M=0;b<this.length;b++){var C=this.words[b]<<M|p;s[h--]=C&255,h>=0&&(s[h--]=C>>8&255),h>=0&&(s[h--]=C>>16&255),M===6?(h>=0&&(s[h--]=C>>24&255),p=0,M=0):(p=C>>>24,M+=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 B(s){for(var l=new Array(s.bitLength()),h=0;h<l.length;h++){var p=h/26|0,b=h%26;l[h]=s.words[p]>>>b&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 b=0,M=0;M<p.length;M++)l=(h.words[M]|0)+(p.words[M]|0)+b,this.words[M]=l&67108863,b=l>>>26;for(;b!==0&&M<h.length;M++)l=(h.words[M]|0)+b,this.words[M]=l&67108863,b=l>>>26;if(this.length=h.length,b!==0)this.words[this.length]=b,this.length++;else if(h!==this)for(;M<h.length;M++)this.words[M]=h.words[M];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,b;h>0?(p=this,b=s):(p=s,b=this);for(var M=0,C=0;C<b.length;C++)l=(p.words[C]|0)-(b.words[C]|0)+M,M=l>>26,this.words[C]=l&67108863;for(;M!==0&&C<p.length;C++)l=(p.words[C]|0)+M,M=l>>26,this.words[C]=l&67108863;if(M===0&&C<p.length&&p!==this)for(;C<p.length;C++)this.words[C]=p.words[C];return this.length=Math.max(this.length,C),p!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(s){return this.clone().isub(s)};function x(s,l,h){h.negative=l.negative^s.negative;var p=s.length+l.length|0;h.length=p,p=p-1|0;var b=s.words[0]|0,M=l.words[0]|0,C=b*M,w=C&67108863,c=C/67108864|0;h.words[0]=w;for(var y=1;y<p;y++){for(var V=c>>>26,T=c&67108863,L=Math.min(y,l.length-1),K=Math.max(0,y-s.length+1);K<=L;K++){var G=y-K|0;b=s.words[G]|0,M=l.words[K]|0,C=b*M+T,V+=C/67108864|0,T=C&67108863}h.words[y]=T|0,c=V|0}return c!==0?h.words[y]=c|0:h.length--,h._strip()}var A=function(s,l,h){var p=s.words,b=l.words,M=h.words,C=0,w,c,y,V=p[0]|0,T=V&8191,L=V>>>13,K=p[1]|0,G=K&8191,et=K>>>13,me=p[2]|0,it=me&8191,nt=me>>>13,_n=p[3]|0,ot=_n&8191,st=_n>>>13,gn=p[4]|0,at=gn&8191,ct=gn>>>13,bn=p[5]|0,lt=bn&8191,ut=bn>>>13,wn=p[6]|0,dt=wn&8191,ft=wn>>>13,yn=p[7]|0,ht=yn&8191,mt=yn>>>13,vn=p[8]|0,pt=vn&8191,_t=vn>>>13,Mn=p[9]|0,gt=Mn&8191,bt=Mn>>>13,Cn=b[0]|0,wt=Cn&8191,yt=Cn>>>13,Sn=b[1]|0,vt=Sn&8191,Mt=Sn>>>13,Pn=b[2]|0,Ct=Pn&8191,St=Pn>>>13,kn=b[3]|0,Pt=kn&8191,kt=kn>>>13,An=b[4]|0,At=An&8191,Ot=An>>>13,On=b[5]|0,xt=On&8191,Dt=On>>>13,xn=b[6]|0,Bt=xn&8191,Et=xn>>>13,Dn=b[7]|0,Vt=Dn&8191,Tt=Dn>>>13,Bn=b[8]|0,Ft=Bn&8191,It=Bn>>>13,En=b[9]|0,Lt=En&8191,jt=En>>>13;h.negative=s.negative^l.negative,h.length=19,w=Math.imul(T,wt),c=Math.imul(T,yt),c=c+Math.imul(L,wt)|0,y=Math.imul(L,yt);var pi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(pi>>>26)|0,pi&=67108863,w=Math.imul(G,wt),c=Math.imul(G,yt),c=c+Math.imul(et,wt)|0,y=Math.imul(et,yt),w=w+Math.imul(T,vt)|0,c=c+Math.imul(T,Mt)|0,c=c+Math.imul(L,vt)|0,y=y+Math.imul(L,Mt)|0;var _i=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(_i>>>26)|0,_i&=67108863,w=Math.imul(it,wt),c=Math.imul(it,yt),c=c+Math.imul(nt,wt)|0,y=Math.imul(nt,yt),w=w+Math.imul(G,vt)|0,c=c+Math.imul(G,Mt)|0,c=c+Math.imul(et,vt)|0,y=y+Math.imul(et,Mt)|0,w=w+Math.imul(T,Ct)|0,c=c+Math.imul(T,St)|0,c=c+Math.imul(L,Ct)|0,y=y+Math.imul(L,St)|0;var gi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,w=Math.imul(ot,wt),c=Math.imul(ot,yt),c=c+Math.imul(st,wt)|0,y=Math.imul(st,yt),w=w+Math.imul(it,vt)|0,c=c+Math.imul(it,Mt)|0,c=c+Math.imul(nt,vt)|0,y=y+Math.imul(nt,Mt)|0,w=w+Math.imul(G,Ct)|0,c=c+Math.imul(G,St)|0,c=c+Math.imul(et,Ct)|0,y=y+Math.imul(et,St)|0,w=w+Math.imul(T,Pt)|0,c=c+Math.imul(T,kt)|0,c=c+Math.imul(L,Pt)|0,y=y+Math.imul(L,kt)|0;var bi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,w=Math.imul(at,wt),c=Math.imul(at,yt),c=c+Math.imul(ct,wt)|0,y=Math.imul(ct,yt),w=w+Math.imul(ot,vt)|0,c=c+Math.imul(ot,Mt)|0,c=c+Math.imul(st,vt)|0,y=y+Math.imul(st,Mt)|0,w=w+Math.imul(it,Ct)|0,c=c+Math.imul(it,St)|0,c=c+Math.imul(nt,Ct)|0,y=y+Math.imul(nt,St)|0,w=w+Math.imul(G,Pt)|0,c=c+Math.imul(G,kt)|0,c=c+Math.imul(et,Pt)|0,y=y+Math.imul(et,kt)|0,w=w+Math.imul(T,At)|0,c=c+Math.imul(T,Ot)|0,c=c+Math.imul(L,At)|0,y=y+Math.imul(L,Ot)|0;var wi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,w=Math.imul(lt,wt),c=Math.imul(lt,yt),c=c+Math.imul(ut,wt)|0,y=Math.imul(ut,yt),w=w+Math.imul(at,vt)|0,c=c+Math.imul(at,Mt)|0,c=c+Math.imul(ct,vt)|0,y=y+Math.imul(ct,Mt)|0,w=w+Math.imul(ot,Ct)|0,c=c+Math.imul(ot,St)|0,c=c+Math.imul(st,Ct)|0,y=y+Math.imul(st,St)|0,w=w+Math.imul(it,Pt)|0,c=c+Math.imul(it,kt)|0,c=c+Math.imul(nt,Pt)|0,y=y+Math.imul(nt,kt)|0,w=w+Math.imul(G,At)|0,c=c+Math.imul(G,Ot)|0,c=c+Math.imul(et,At)|0,y=y+Math.imul(et,Ot)|0,w=w+Math.imul(T,xt)|0,c=c+Math.imul(T,Dt)|0,c=c+Math.imul(L,xt)|0,y=y+Math.imul(L,Dt)|0;var yi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,w=Math.imul(dt,wt),c=Math.imul(dt,yt),c=c+Math.imul(ft,wt)|0,y=Math.imul(ft,yt),w=w+Math.imul(lt,vt)|0,c=c+Math.imul(lt,Mt)|0,c=c+Math.imul(ut,vt)|0,y=y+Math.imul(ut,Mt)|0,w=w+Math.imul(at,Ct)|0,c=c+Math.imul(at,St)|0,c=c+Math.imul(ct,Ct)|0,y=y+Math.imul(ct,St)|0,w=w+Math.imul(ot,Pt)|0,c=c+Math.imul(ot,kt)|0,c=c+Math.imul(st,Pt)|0,y=y+Math.imul(st,kt)|0,w=w+Math.imul(it,At)|0,c=c+Math.imul(it,Ot)|0,c=c+Math.imul(nt,At)|0,y=y+Math.imul(nt,Ot)|0,w=w+Math.imul(G,xt)|0,c=c+Math.imul(G,Dt)|0,c=c+Math.imul(et,xt)|0,y=y+Math.imul(et,Dt)|0,w=w+Math.imul(T,Bt)|0,c=c+Math.imul(T,Et)|0,c=c+Math.imul(L,Bt)|0,y=y+Math.imul(L,Et)|0;var vi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,w=Math.imul(ht,wt),c=Math.imul(ht,yt),c=c+Math.imul(mt,wt)|0,y=Math.imul(mt,yt),w=w+Math.imul(dt,vt)|0,c=c+Math.imul(dt,Mt)|0,c=c+Math.imul(ft,vt)|0,y=y+Math.imul(ft,Mt)|0,w=w+Math.imul(lt,Ct)|0,c=c+Math.imul(lt,St)|0,c=c+Math.imul(ut,Ct)|0,y=y+Math.imul(ut,St)|0,w=w+Math.imul(at,Pt)|0,c=c+Math.imul(at,kt)|0,c=c+Math.imul(ct,Pt)|0,y=y+Math.imul(ct,kt)|0,w=w+Math.imul(ot,At)|0,c=c+Math.imul(ot,Ot)|0,c=c+Math.imul(st,At)|0,y=y+Math.imul(st,Ot)|0,w=w+Math.imul(it,xt)|0,c=c+Math.imul(it,Dt)|0,c=c+Math.imul(nt,xt)|0,y=y+Math.imul(nt,Dt)|0,w=w+Math.imul(G,Bt)|0,c=c+Math.imul(G,Et)|0,c=c+Math.imul(et,Bt)|0,y=y+Math.imul(et,Et)|0,w=w+Math.imul(T,Vt)|0,c=c+Math.imul(T,Tt)|0,c=c+Math.imul(L,Vt)|0,y=y+Math.imul(L,Tt)|0;var Mi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,w=Math.imul(pt,wt),c=Math.imul(pt,yt),c=c+Math.imul(_t,wt)|0,y=Math.imul(_t,yt),w=w+Math.imul(ht,vt)|0,c=c+Math.imul(ht,Mt)|0,c=c+Math.imul(mt,vt)|0,y=y+Math.imul(mt,Mt)|0,w=w+Math.imul(dt,Ct)|0,c=c+Math.imul(dt,St)|0,c=c+Math.imul(ft,Ct)|0,y=y+Math.imul(ft,St)|0,w=w+Math.imul(lt,Pt)|0,c=c+Math.imul(lt,kt)|0,c=c+Math.imul(ut,Pt)|0,y=y+Math.imul(ut,kt)|0,w=w+Math.imul(at,At)|0,c=c+Math.imul(at,Ot)|0,c=c+Math.imul(ct,At)|0,y=y+Math.imul(ct,Ot)|0,w=w+Math.imul(ot,xt)|0,c=c+Math.imul(ot,Dt)|0,c=c+Math.imul(st,xt)|0,y=y+Math.imul(st,Dt)|0,w=w+Math.imul(it,Bt)|0,c=c+Math.imul(it,Et)|0,c=c+Math.imul(nt,Bt)|0,y=y+Math.imul(nt,Et)|0,w=w+Math.imul(G,Vt)|0,c=c+Math.imul(G,Tt)|0,c=c+Math.imul(et,Vt)|0,y=y+Math.imul(et,Tt)|0,w=w+Math.imul(T,Ft)|0,c=c+Math.imul(T,It)|0,c=c+Math.imul(L,Ft)|0,y=y+Math.imul(L,It)|0;var Ci=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,w=Math.imul(gt,wt),c=Math.imul(gt,yt),c=c+Math.imul(bt,wt)|0,y=Math.imul(bt,yt),w=w+Math.imul(pt,vt)|0,c=c+Math.imul(pt,Mt)|0,c=c+Math.imul(_t,vt)|0,y=y+Math.imul(_t,Mt)|0,w=w+Math.imul(ht,Ct)|0,c=c+Math.imul(ht,St)|0,c=c+Math.imul(mt,Ct)|0,y=y+Math.imul(mt,St)|0,w=w+Math.imul(dt,Pt)|0,c=c+Math.imul(dt,kt)|0,c=c+Math.imul(ft,Pt)|0,y=y+Math.imul(ft,kt)|0,w=w+Math.imul(lt,At)|0,c=c+Math.imul(lt,Ot)|0,c=c+Math.imul(ut,At)|0,y=y+Math.imul(ut,Ot)|0,w=w+Math.imul(at,xt)|0,c=c+Math.imul(at,Dt)|0,c=c+Math.imul(ct,xt)|0,y=y+Math.imul(ct,Dt)|0,w=w+Math.imul(ot,Bt)|0,c=c+Math.imul(ot,Et)|0,c=c+Math.imul(st,Bt)|0,y=y+Math.imul(st,Et)|0,w=w+Math.imul(it,Vt)|0,c=c+Math.imul(it,Tt)|0,c=c+Math.imul(nt,Vt)|0,y=y+Math.imul(nt,Tt)|0,w=w+Math.imul(G,Ft)|0,c=c+Math.imul(G,It)|0,c=c+Math.imul(et,Ft)|0,y=y+Math.imul(et,It)|0,w=w+Math.imul(T,Lt)|0,c=c+Math.imul(T,jt)|0,c=c+Math.imul(L,Lt)|0,y=y+Math.imul(L,jt)|0;var Si=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Si>>>26)|0,Si&=67108863,w=Math.imul(gt,vt),c=Math.imul(gt,Mt),c=c+Math.imul(bt,vt)|0,y=Math.imul(bt,Mt),w=w+Math.imul(pt,Ct)|0,c=c+Math.imul(pt,St)|0,c=c+Math.imul(_t,Ct)|0,y=y+Math.imul(_t,St)|0,w=w+Math.imul(ht,Pt)|0,c=c+Math.imul(ht,kt)|0,c=c+Math.imul(mt,Pt)|0,y=y+Math.imul(mt,kt)|0,w=w+Math.imul(dt,At)|0,c=c+Math.imul(dt,Ot)|0,c=c+Math.imul(ft,At)|0,y=y+Math.imul(ft,Ot)|0,w=w+Math.imul(lt,xt)|0,c=c+Math.imul(lt,Dt)|0,c=c+Math.imul(ut,xt)|0,y=y+Math.imul(ut,Dt)|0,w=w+Math.imul(at,Bt)|0,c=c+Math.imul(at,Et)|0,c=c+Math.imul(ct,Bt)|0,y=y+Math.imul(ct,Et)|0,w=w+Math.imul(ot,Vt)|0,c=c+Math.imul(ot,Tt)|0,c=c+Math.imul(st,Vt)|0,y=y+Math.imul(st,Tt)|0,w=w+Math.imul(it,Ft)|0,c=c+Math.imul(it,It)|0,c=c+Math.imul(nt,Ft)|0,y=y+Math.imul(nt,It)|0,w=w+Math.imul(G,Lt)|0,c=c+Math.imul(G,jt)|0,c=c+Math.imul(et,Lt)|0,y=y+Math.imul(et,jt)|0;var Pi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Pi>>>26)|0,Pi&=67108863,w=Math.imul(gt,Ct),c=Math.imul(gt,St),c=c+Math.imul(bt,Ct)|0,y=Math.imul(bt,St),w=w+Math.imul(pt,Pt)|0,c=c+Math.imul(pt,kt)|0,c=c+Math.imul(_t,Pt)|0,y=y+Math.imul(_t,kt)|0,w=w+Math.imul(ht,At)|0,c=c+Math.imul(ht,Ot)|0,c=c+Math.imul(mt,At)|0,y=y+Math.imul(mt,Ot)|0,w=w+Math.imul(dt,xt)|0,c=c+Math.imul(dt,Dt)|0,c=c+Math.imul(ft,xt)|0,y=y+Math.imul(ft,Dt)|0,w=w+Math.imul(lt,Bt)|0,c=c+Math.imul(lt,Et)|0,c=c+Math.imul(ut,Bt)|0,y=y+Math.imul(ut,Et)|0,w=w+Math.imul(at,Vt)|0,c=c+Math.imul(at,Tt)|0,c=c+Math.imul(ct,Vt)|0,y=y+Math.imul(ct,Tt)|0,w=w+Math.imul(ot,Ft)|0,c=c+Math.imul(ot,It)|0,c=c+Math.imul(st,Ft)|0,y=y+Math.imul(st,It)|0,w=w+Math.imul(it,Lt)|0,c=c+Math.imul(it,jt)|0,c=c+Math.imul(nt,Lt)|0,y=y+Math.imul(nt,jt)|0;var ki=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(ki>>>26)|0,ki&=67108863,w=Math.imul(gt,Pt),c=Math.imul(gt,kt),c=c+Math.imul(bt,Pt)|0,y=Math.imul(bt,kt),w=w+Math.imul(pt,At)|0,c=c+Math.imul(pt,Ot)|0,c=c+Math.imul(_t,At)|0,y=y+Math.imul(_t,Ot)|0,w=w+Math.imul(ht,xt)|0,c=c+Math.imul(ht,Dt)|0,c=c+Math.imul(mt,xt)|0,y=y+Math.imul(mt,Dt)|0,w=w+Math.imul(dt,Bt)|0,c=c+Math.imul(dt,Et)|0,c=c+Math.imul(ft,Bt)|0,y=y+Math.imul(ft,Et)|0,w=w+Math.imul(lt,Vt)|0,c=c+Math.imul(lt,Tt)|0,c=c+Math.imul(ut,Vt)|0,y=y+Math.imul(ut,Tt)|0,w=w+Math.imul(at,Ft)|0,c=c+Math.imul(at,It)|0,c=c+Math.imul(ct,Ft)|0,y=y+Math.imul(ct,It)|0,w=w+Math.imul(ot,Lt)|0,c=c+Math.imul(ot,jt)|0,c=c+Math.imul(st,Lt)|0,y=y+Math.imul(st,jt)|0;var Ai=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,w=Math.imul(gt,At),c=Math.imul(gt,Ot),c=c+Math.imul(bt,At)|0,y=Math.imul(bt,Ot),w=w+Math.imul(pt,xt)|0,c=c+Math.imul(pt,Dt)|0,c=c+Math.imul(_t,xt)|0,y=y+Math.imul(_t,Dt)|0,w=w+Math.imul(ht,Bt)|0,c=c+Math.imul(ht,Et)|0,c=c+Math.imul(mt,Bt)|0,y=y+Math.imul(mt,Et)|0,w=w+Math.imul(dt,Vt)|0,c=c+Math.imul(dt,Tt)|0,c=c+Math.imul(ft,Vt)|0,y=y+Math.imul(ft,Tt)|0,w=w+Math.imul(lt,Ft)|0,c=c+Math.imul(lt,It)|0,c=c+Math.imul(ut,Ft)|0,y=y+Math.imul(ut,It)|0,w=w+Math.imul(at,Lt)|0,c=c+Math.imul(at,jt)|0,c=c+Math.imul(ct,Lt)|0,y=y+Math.imul(ct,jt)|0;var Oi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Oi>>>26)|0,Oi&=67108863,w=Math.imul(gt,xt),c=Math.imul(gt,Dt),c=c+Math.imul(bt,xt)|0,y=Math.imul(bt,Dt),w=w+Math.imul(pt,Bt)|0,c=c+Math.imul(pt,Et)|0,c=c+Math.imul(_t,Bt)|0,y=y+Math.imul(_t,Et)|0,w=w+Math.imul(ht,Vt)|0,c=c+Math.imul(ht,Tt)|0,c=c+Math.imul(mt,Vt)|0,y=y+Math.imul(mt,Tt)|0,w=w+Math.imul(dt,Ft)|0,c=c+Math.imul(dt,It)|0,c=c+Math.imul(ft,Ft)|0,y=y+Math.imul(ft,It)|0,w=w+Math.imul(lt,Lt)|0,c=c+Math.imul(lt,jt)|0,c=c+Math.imul(ut,Lt)|0,y=y+Math.imul(ut,jt)|0;var xi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(xi>>>26)|0,xi&=67108863,w=Math.imul(gt,Bt),c=Math.imul(gt,Et),c=c+Math.imul(bt,Bt)|0,y=Math.imul(bt,Et),w=w+Math.imul(pt,Vt)|0,c=c+Math.imul(pt,Tt)|0,c=c+Math.imul(_t,Vt)|0,y=y+Math.imul(_t,Tt)|0,w=w+Math.imul(ht,Ft)|0,c=c+Math.imul(ht,It)|0,c=c+Math.imul(mt,Ft)|0,y=y+Math.imul(mt,It)|0,w=w+Math.imul(dt,Lt)|0,c=c+Math.imul(dt,jt)|0,c=c+Math.imul(ft,Lt)|0,y=y+Math.imul(ft,jt)|0;var Di=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Di>>>26)|0,Di&=67108863,w=Math.imul(gt,Vt),c=Math.imul(gt,Tt),c=c+Math.imul(bt,Vt)|0,y=Math.imul(bt,Tt),w=w+Math.imul(pt,Ft)|0,c=c+Math.imul(pt,It)|0,c=c+Math.imul(_t,Ft)|0,y=y+Math.imul(_t,It)|0,w=w+Math.imul(ht,Lt)|0,c=c+Math.imul(ht,jt)|0,c=c+Math.imul(mt,Lt)|0,y=y+Math.imul(mt,jt)|0;var Bi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Bi>>>26)|0,Bi&=67108863,w=Math.imul(gt,Ft),c=Math.imul(gt,It),c=c+Math.imul(bt,Ft)|0,y=Math.imul(bt,It),w=w+Math.imul(pt,Lt)|0,c=c+Math.imul(pt,jt)|0,c=c+Math.imul(_t,Lt)|0,y=y+Math.imul(_t,jt)|0;var Ei=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ei>>>26)|0,Ei&=67108863,w=Math.imul(gt,Lt),c=Math.imul(gt,jt),c=c+Math.imul(bt,Lt)|0,y=Math.imul(bt,jt);var Vi=(C+w|0)+((c&8191)<<13)|0;return C=(y+(c>>>13)|0)+(Vi>>>26)|0,Vi&=67108863,M[0]=pi,M[1]=_i,M[2]=gi,M[3]=bi,M[4]=wi,M[5]=yi,M[6]=vi,M[7]=Mi,M[8]=Ci,M[9]=Si,M[10]=Pi,M[11]=ki,M[12]=Ai,M[13]=Oi,M[14]=xi,M[15]=Di,M[16]=Bi,M[17]=Ei,M[18]=Vi,C!==0&&(M[19]=C,h.length++),h};Math.imul||(A=x);function E(s,l,h){h.negative=l.negative^s.negative,h.length=s.length+l.length;for(var p=0,b=0,M=0;M<h.length-1;M++){var C=b;b=0;for(var w=p&67108863,c=Math.min(M,l.length-1),y=Math.max(0,M-s.length+1);y<=c;y++){var V=M-y,T=s.words[V]|0,L=l.words[y]|0,K=T*L,G=K&67108863;C=C+(K/67108864|0)|0,G=G+w|0,w=G&67108863,C=C+(G>>>26)|0,b+=C>>>26,C&=67108863}h.words[M]=w,p=C,C=b}return p!==0?h.words[M]=p:h.length--,h._strip()}function $(s,l,h){return E(s,l,h)}o.prototype.mulTo=function(s,l){var h,p=this.length+s.length;return this.length===10&&s.length===10?h=A(this,s,l):p<63?h=x(this,s,l):p<1024?h=E(this,s,l):h=$(this,s,l),h};function I(s,l){this.x=s,this.y=l}I.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},I.prototype.revBin=function(s,l,h){if(s===0||s===h-1)return s;for(var p=0,b=0;b<l;b++)p|=(s&1)<<l-b-1,s>>=1;return p},I.prototype.permute=function(s,l,h,p,b,M){for(var C=0;C<M;C++)p[C]=l[s[C]],b[C]=h[s[C]]},I.prototype.transform=function(s,l,h,p,b,M){this.permute(M,s,l,h,p,b);for(var C=1;C<b;C<<=1)for(var w=C<<1,c=Math.cos(2*Math.PI/w),y=Math.sin(2*Math.PI/w),V=0;V<b;V+=w)for(var T=c,L=y,K=0;K<C;K++){var G=h[V+K],et=p[V+K],me=h[V+K+C],it=p[V+K+C],nt=T*me-L*it;it=T*it+L*me,me=nt,h[V+K]=G+me,p[V+K]=et+it,h[V+K+C]=G-me,p[V+K+C]=et-it,K!==w&&(nt=c*T-y*L,L=c*L+y*T,T=nt)}},I.prototype.guessLen13b=function(s,l){var h=Math.max(l,s)|1,p=h&1,b=0;for(h=h/2|0;h;h=h>>>1)b++;return 1<<b+1+p},I.prototype.conjugate=function(s,l,h){if(!(h<=1))for(var p=0;p<h/2;p++){var b=s[p];s[p]=s[h-p-1],s[h-p-1]=b,b=l[p],l[p]=-l[h-p-1],l[h-p-1]=-b}},I.prototype.normalize13b=function(s,l){for(var h=0,p=0;p<l/2;p++){var b=Math.round(s[2*p+1]/l)*8192+Math.round(s[2*p]/l)+h;s[p]=b&67108863,b<67108864?h=0:h=b/67108864|0}return s},I.prototype.convert13b=function(s,l,h,p){for(var b=0,M=0;M<l;M++)b=b+(s[M]|0),h[2*M]=b&8191,b=b>>>13,h[2*M+1]=b&8191,b=b>>>13;for(M=2*l;M<p;++M)h[M]=0;r(b===0),r((b&-8192)===0)},I.prototype.stub=function(s){for(var l=new Array(s),h=0;h<s;h++)l[h]=0;return l},I.prototype.mulp=function(s,l,h){var p=2*this.guessLen13b(s.length,l.length),b=this.makeRBT(p),M=this.stub(p),C=new Array(p),w=new Array(p),c=new Array(p),y=new Array(p),V=new Array(p),T=new Array(p),L=h.words;L.length=p,this.convert13b(s.words,s.length,C,p),this.convert13b(l.words,l.length,y,p),this.transform(C,M,w,c,p,b),this.transform(y,M,V,T,p,b);for(var K=0;K<p;K++){var G=w[K]*V[K]-c[K]*T[K];c[K]=w[K]*T[K]+c[K]*V[K],w[K]=G}return this.conjugate(w,c,p),this.transform(w,c,L,M,p,b),this.conjugate(L,M,p),this.normalize13b(L,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),$(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 b=(this.words[p]|0)*s,M=(b&67108863)+(h&67108863);h>>=26,h+=b/67108864|0,h+=M>>>26,this.words[p]=M&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=B(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 b=h.sqr();p<l.length;p++,b=b.sqr())l[p]!==0&&(h=h.mul(b));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,b;if(l!==0){var M=0;for(b=0;b<this.length;b++){var C=this.words[b]&p,w=(this.words[b]|0)-C<<l;this.words[b]=w|M,M=C>>>26-l}M&&(this.words[b]=M,this.length++)}if(h!==0){for(b=this.length-1;b>=0;b--)this.words[b+h]=this.words[b];for(b=0;b<h;b++)this.words[b]=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 b=s%26,M=Math.min((s-b)/26,this.length),C=67108863^67108863>>>b<<b,w=h;if(p-=M,p=Math.max(0,p),w){for(var c=0;c<M;c++)w.words[c]=this.words[c];w.length=M}if(M!==0)if(this.length>M)for(this.length-=M,c=0;c<this.length;c++)this.words[c]=this.words[c+M];else this.words[0]=0,this.length=1;var y=0;for(c=this.length-1;c>=0&&(y!==0||c>=p);c--){var V=this.words[c]|0;this.words[c]=y<<26-b|V>>>b,y=V&C}return w&&y!==0&&(w.words[w.length++]=y),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 b=this.words[h];return!!(b&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,b;this._expand(p);var M,C=0;for(b=0;b<s.length;b++){M=(this.words[b+h]|0)+C;var w=(s.words[b]|0)*l;M-=w&67108863,C=(M>>26)-(w/67108864|0),this.words[b+h]=M&67108863}for(;b<this.length-h;b++)M=(this.words[b+h]|0)+C,C=M>>26,this.words[b+h]=M&67108863;if(C===0)return this._strip();for(r(C===-1),C=0,b=0;b<this.length;b++)M=-(this.words[b]|0)+C,C=M>>26,this.words[b]=M&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(s,l){var h=this.length-s.length,p=this.clone(),b=s,M=b.words[b.length-1]|0,C=this._countBits(M);h=26-C,h!==0&&(b=b.ushln(h),p.iushln(h),M=b.words[b.length-1]|0);var w=p.length-b.length,c;if(l!=="mod"){c=new o(null),c.length=w+1,c.words=new Array(c.length);for(var y=0;y<c.length;y++)c.words[y]=0}var V=p.clone()._ishlnsubmul(b,1,w);V.negative===0&&(p=V,c&&(c.words[w]=1));for(var T=w-1;T>=0;T--){var L=(p.words[b.length+T]|0)*67108864+(p.words[b.length+T-1]|0);for(L=Math.min(L/M|0,67108863),p._ishlnsubmul(b,L,T);p.negative!==0;)L--,p.negative=0,p._ishlnsubmul(b,1,T),p.isZero()||(p.negative^=1);c&&(c.words[T]=L)}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,b,M;return this.negative!==0&&s.negative===0?(M=this.neg().divmod(s,l),l!=="mod"&&(p=M.div.neg()),l!=="div"&&(b=M.mod.neg(),h&&b.negative!==0&&b.iadd(s)),{div:p,mod:b}):this.negative===0&&s.negative!==0?(M=this.divmod(s.neg(),l),l!=="mod"&&(p=M.div.neg()),{div:p,mod:M.mod}):this.negative&s.negative?(M=this.neg().divmod(s.neg(),l),l!=="div"&&(b=M.mod.neg(),h&&b.negative!==0&&b.isub(s)),{div:M.div,mod:b}):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),b=s.andln(1),M=h.cmp(p);return M<0||b===1&&M===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,b=this.length-1;b>=0;b--)p=(h*p+(this.words[b]|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 b=(this.words[p]|0)+h*67108864;this.words[p]=b/s|0,h=b%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),b=new o(0),M=new o(0),C=new o(1),w=0;l.isEven()&&h.isEven();)l.iushrn(1),h.iushrn(1),++w;for(var c=h.clone(),y=l.clone();!l.isZero();){for(var V=0,T=1;!(l.words[0]&T)&&V<26;++V,T<<=1);if(V>0)for(l.iushrn(V);V-- >0;)(p.isOdd()||b.isOdd())&&(p.iadd(c),b.isub(y)),p.iushrn(1),b.iushrn(1);for(var L=0,K=1;!(h.words[0]&K)&&L<26;++L,K<<=1);if(L>0)for(h.iushrn(L);L-- >0;)(M.isOdd()||C.isOdd())&&(M.iadd(c),C.isub(y)),M.iushrn(1),C.iushrn(1);l.cmp(h)>=0?(l.isub(h),p.isub(M),b.isub(C)):(h.isub(l),M.isub(p),C.isub(b))}return{a:M,b:C,gcd:h.iushln(w)}},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),b=new o(0),M=h.clone();l.cmpn(1)>0&&h.cmpn(1)>0;){for(var C=0,w=1;!(l.words[0]&w)&&C<26;++C,w<<=1);if(C>0)for(l.iushrn(C);C-- >0;)p.isOdd()&&p.iadd(M),p.iushrn(1);for(var c=0,y=1;!(h.words[0]&y)&&c<26;++c,y<<=1);if(c>0)for(h.iushrn(c);c-- >0;)b.isOdd()&&b.iadd(M),b.iushrn(1);l.cmp(h)>=0?(l.isub(h),p.isub(b)):(h.isub(l),b.isub(p))}var V;return l.cmpn(1)===0?V=p:V=b,V.cmpn(0)<0&&V.iadd(s),V},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 b=l.cmp(h);if(b<0){var M=l;l=h,h=M}else if(b===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 b=p,M=h;b!==0&&M<this.length;M++){var C=this.words[M]|0;C+=b,b=C>>>26,C&=67108863,this.words[M]=C}return b!==0&&(this.words[M]=b,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,b=s.words[h]|0;if(p!==b){p<b?l=-1:p>b&&(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 Z={k256:null,p224:null,p192:null,p25519:null};function R(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()}R.prototype._tmp=function(){var s=new o(null);return s.words=new Array(Math.ceil(this.n/13)),s},R.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},R.prototype.split=function(s,l){s.iushrn(this.n,0,l)},R.prototype.imulK=function(s){return s.imul(this.k)};function W(){R.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a(W,R),W.prototype.split=function(s,l){for(var h=4194303,p=Math.min(s.length,9),b=0;b<p;b++)l.words[b]=s.words[b];if(l.length=p,s.length<=9){s.words[0]=0,s.length=1;return}var M=s.words[9];for(l.words[l.length++]=M&h,b=10;b<s.length;b++){var C=s.words[b]|0;s.words[b-10]=(C&h)<<4|M>>>22,M=C}M>>>=22,s.words[b-10]=M,M===0&&s.length>10?s.length-=10:s.length-=9},W.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 Q(){R.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}a(Q,R);function J(){R.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}a(J,R);function Y(){R.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}a(Y,R),Y.prototype.imulK=function(s){for(var l=0,h=0;h<s.length;h++){var p=(s.words[h]|0)*19+l,b=p&67108863;p>>>=26,s.words[h]=b,l=p}return l!==0&&(s.words[s.length++]=l),s},o._prime=function(s){if(Z[s])return Z[s];var l;if(s==="k256")l=new W;else if(s==="p224")l=new Q;else if(s==="p192")l=new J;else if(s==="p25519")l=new Y;else throw new Error("Unknown prime "+s);return Z[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),b=0;!p.isZero()&&p.andln(1)===0;)b++,p.iushrn(1);r(!p.isZero());var M=new o(1).toRed(this),C=M.redNeg(),w=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new o(2*c*c).toRed(this);this.pow(c,w).cmp(C)!==0;)c.redIAdd(C);for(var y=this.pow(c,p),V=this.pow(s,p.addn(1).iushrn(1)),T=this.pow(s,p),L=b;T.cmp(M)!==0;){for(var K=T,G=0;K.cmp(M)!==0;G++)K=K.redSqr();r(G<L);var et=this.pow(y,new o(1).iushln(L-G-1));V=V.redMul(et),y=et.redSqr(),T=T.redMul(y),L=G}return V},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 b=2;b<p.length;b++)p[b]=this.mul(p[b-1],s);var M=p[0],C=0,w=0,c=l.bitLength()%26;for(c===0&&(c=26),b=l.length-1;b>=0;b--){for(var y=l.words[b],V=c-1;V>=0;V--){var T=y>>V&1;if(M!==p[0]&&(M=this.sqr(M)),T===0&&C===0){w=0;continue}C<<=1,C|=T,w++,!(w!==h&&(b!==0||V!==0))&&(M=this.mul(M,p[C]),w=0,C=0)}c=26}return M},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 H(s)};function H(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(H,X),H.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},H.prototype.convertFrom=function(s){var l=this.imod(s.mul(this.rinv));return l.red=null,l},H.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),b=h.isub(p).iushrn(this.shift),M=b;return b.cmp(this.m)>=0?M=b.isub(this.m):b.cmpn(0)<0&&(M=b.iadd(this.m)),M._forceRed(this)},H.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),b=h.isub(p).iushrn(this.shift),M=b;return b.cmp(this.m)>=0?M=b.isub(this.m):b.cmpn(0)<0&&(M=b.iadd(this.m)),M._forceRed(this)},H.prototype.invm=function(s){var l=this.imod(s._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof t>"u"||t,i)}),Ti={REQUEST_PARAMS:"requestParams",METHOD_NAME:"methodName"},Ir=class $n extends Error{constructor(t,e,n){super(t),this.code=e,this.details=n,this.name=this.constructor.name}static{this.DETAILS_KEYS=Ti}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 $n&&t.code===e}},Lr=class extends Ir{constructor(i,t,e){super(i,t||"UnknownError",e)}static isCommonErrorCode(i,t){return this.isErrorCode(i,t)}},Jt=(i,t,e)=>{throw new Lr(t,i,e)};var Kn=864e5;var xe=9e15,we=1e9,Ii="0123456789abcdef",ti="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ei="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Li={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-xe,maxE:xe,crypto:!1},Wn,fe,N=!0,ni="[DecimalError] ",ge=ni+"Invalid argument: ",Zn=ni+"Precision limit exceeded",zn=ni+"crypto unavailable",Xn="[object Decimal]",Wt=Math.floor,Nt=Math.pow,Ur=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,$r=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Kr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Gn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ee=1e7,q=7,Wr=9007199254740991,Zr=ti.length-1,ji=ei.length-1,O={toStringTag:Xn};O.absoluteValue=O.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),F(i)};O.ceil=function(){return F(new this.constructor(this),this.e+1,2)};O.clampedTo=O.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)};O.comparedTo=O.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};O.cosine=O.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())+q,n.rounding=1,e=zr(n,tr(n,e)),n.precision=i,n.rounding=t,F(fe==2||fe==3?e.neg():e,i,t,!0)):new n(1):new n(NaN)};O.cubeRoot=O.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(N=!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=tt(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 N=!0,F(n,i,_.rounding,t)};O.decimalPlaces=O.dp=function(){var i,t=this.d,e=NaN;if(t){if(i=t.length-1,e=(i-Wt(this.e/q))*q,i=t[i],i)for(;i%10==0;i/=10)e--;e<0&&(e=0)}return e};O.dividedBy=O.div=function(i){return tt(this,new this.constructor(i))};O.dividedToIntegerBy=O.divToInt=function(i){var t=this,e=t.constructor;return F(tt(t,new e(i),0,1,1),e.precision,e.rounding)};O.equals=O.eq=function(i){return this.cmp(i)===0};O.floor=function(){return F(new this.constructor(this),this.e+1,3)};O.greaterThan=O.gt=function(i){return this.cmp(i)>0};O.greaterThanOrEqualTo=O.gte=function(i){var t=this.cmp(i);return t==1||t===0};O.hyperbolicCosine=O.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/oi(4,i)).toString()):(i=16,t="2.3283064365386962890625e-10"),a=De(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)};O.hyperbolicSine=O.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=De(a,2,r,r,!0);else{i=1.4*Math.sqrt(n),i=i>16?16:i|0,r=r.times(1/oi(5,i)),r=De(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)};O.hyperbolicTangent=O.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,tt(e.sinh(),e.cosh(),n.precision=i,n.rounding=t)):new n(e.s)};O.inverseCosine=O.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()?ae(t,n,r):new t(0):new t(NaN):i.isZero()?ae(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))};O.inverseHyperbolicCosine=O.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,N=!1,e=e.times(e).minus(1).sqrt().plus(e),N=!0,n.precision=i,n.rounding=t,e.ln()):new n(e)};O.inverseHyperbolicSine=O.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,N=!1,e=e.times(e).plus(1).sqrt().plus(e),N=!0,n.precision=i,n.rounding=t,e.ln())};O.inverseHyperbolicTangent=O.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=tt(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)};O.inverseSine=O.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=ae(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)))};O.inverseTangent=O.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=ae(m,_+4,g).times(.25),o.s=f.s,o}else{if(!f.s)return new m(NaN);if(_+4<=ji)return o=ae(m,_+4,g).times(.5),o.s=f.s,o}for(m.precision=u=_+10,m.rounding=1,e=Math.min(28,u/q+2|0),i=e;i;--i)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(N=!1,t=Math.ceil(u/q),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)),N=!0,F(o,m.precision=_,m.rounding=g,!0)};O.isFinite=function(){return!!this.d};O.isInteger=O.isInt=function(){return!!this.d&&Wt(this.e/q)>this.d.length-2};O.isNaN=function(){return!this.s};O.isNegative=O.isNeg=function(){return this.s<0};O.isPositive=O.isPos=function(){return this.s>0};O.isZero=function(){return!!this.d&&this.d[0]===0};O.lessThan=O.lt=function(i){return this.cmp(i)<0};O.lessThanOrEqualTo=O.lte=function(i){return this.cmp(i)<1};O.logarithm=O.log=function(i){var t,e,n,r,a,o,u,d,f=this,m=f.constructor,_=m.precision,g=m.rounding,v=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(N=!1,u=_+v,o=_e(f,u),n=t?ii(m,u+10):_e(i,u),d=tt(o,n,u,1),Te(d.d,r=_,g))do if(u+=10,o=_e(f,u),n=t?ii(m,u+10):_e(i,u),d=tt(o,n,u,1),!a){+Ut(d.d).slice(r+1,r+15)+1==1e14&&(d=F(d,_+1,0));break}while(Te(d.d,r+=10,g));return N=!0,F(d,_,g)};O.minus=O.sub=function(i){var t,e,n,r,a,o,u,d,f,m,_,g,v=this,S=v.constructor;if(i=new S(i),!v.d||!i.d)return!v.s||!i.s?i=new S(NaN):v.d?i.s=-i.s:i=new S(i.d||v.s!==i.s?v:NaN),i;if(v.s!=i.s)return i.s=-i.s,v.plus(i);if(f=v.d,g=i.d,u=S.precision,d=S.rounding,!f[0]||!g[0]){if(g[0])i.s=-i.s;else if(f[0])i=new S(v);else return new S(d===3?-0:0);return N?F(i,u,d):i}if(e=Wt(i.e/q),m=Wt(v.e/q),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/q),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]=ee-1;--f[r],f[n]+=ee}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=ri(f,e),N?F(i,u,d):i):new S(d===3?-0:0)};O.modulo=O.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):(N=!1,n.modulo==9?(t=tt(e,i.abs(),0,3,1),t.s*=i.s):t=tt(e,i,0,n.modulo,1),t=t.times(i),N=!0,e.minus(t))};O.naturalExponential=O.exp=function(){return qi(this)};O.naturalLogarithm=O.ln=function(){return _e(this)};O.negated=O.neg=function(){var i=new this.constructor(this);return i.s=-i.s,F(i)};O.plus=O.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(_)),N?F(i,u,d):i;if(a=Wt(_.e/q),n=Wt(i.e/q),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/q),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)/ee|0,f[r]%=ee;for(t&&(f.unshift(t),++n),o=f.length;f[--o]==0;)f.pop();return i.d=f,i.e=ri(f,n),N?F(i,u,d):i};O.precision=O.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};O.round=function(){var i=this,t=i.constructor;return F(new t(i),i.e+1,t.rounding)};O.sine=O.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())+q,n.rounding=1,e=Gr(n,tr(n,e)),n.precision=i,n.rounding=t,F(fe>2?e.neg():e,i,t,!0)):new n(NaN)};O.squareRoot=O.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(N=!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(tt(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 N=!0,F(n,d,m.rounding,i)};O.tangent=O.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=tt(e,new n(1).minus(e.times(e)).sqrt(),i+10,0),n.precision=i,n.rounding=t,F(fe==2||fe==4?e.neg():e,i,t,!0)):new n(NaN)};O.times=O.mul=function(i){var t,e,n,r,a,o,u,d,f,m=this,_=m.constructor,g=m.d,v=(i=new _(i)).d;if(i.s*=m.s,!g||!g[0]||!v||!v[0])return new _(!i.s||g&&!g[0]&&!v||v&&!v[0]&&!g?NaN:!g||!v?i.s/0:i.s*0);for(e=Wt(m.e/q)+Wt(i.e/q),d=g.length,f=v.length,d<f&&(a=g,g=v,v=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]+v[n]*g[r-n-1]+t,a[r--]=u%ee|0,t=u/ee|0;a[r]=(a[r]+t)%ee|0}for(;!a[--o];)a.pop();return t?++e:a.shift(),i.d=a,i.e=ri(a,e),N?F(i,_.precision,_.rounding):i};O.toBinary=function(i,t){return Ri(this,2,i,t)};O.toDecimalPlaces=O.toDP=function(i,t){var e=this,n=e.constructor;return e=new n(e),i===void 0?e:(Xt(i,0,we),t===void 0?t=n.rounding:Xt(t,0,8),F(e,i+e.e+1,t))};O.toExponential=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=le(n,!0):(Xt(i,0,we),t===void 0?t=r.rounding:Xt(t,0,8),n=F(new r(n),i+1,t),e=le(n,!0,i+1)),n.isNeg()&&!n.isZero()?"-"+e:e};O.toFixed=function(i,t){var e,n,r=this,a=r.constructor;return i===void 0?e=le(r):(Xt(i,0,we),t===void 0?t=a.rounding:Xt(t,0,8),n=F(new a(r),i+r.e+1,t),e=le(n,!1,i+n.e+1)),r.isNeg()&&!r.isZero()?"-"+e:e};O.toFraction=function(i){var t,e,n,r,a,o,u,d,f,m,_,g,v=this,S=v.d,P=v.constructor;if(!S)return new P(v);if(f=e=new P(1),n=d=new P(0),t=new P(n),a=t.e=Hn(S)-v.e-1,o=a%q,t.d[0]=Nt(10,o<0?q+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(N=!1,u=new P(Ut(S)),m=P.precision,P.precision=a=S.length*q*2;_=tt(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=tt(i.minus(e),n,0,1,1),d=d.plus(r.times(f)),e=e.plus(r.times(n)),d.s=f.s=v.s,g=tt(f,n,a,1).minus(v).abs().cmp(tt(d,e,a,1).minus(v).abs())<1?[f,n]:[d,e],P.precision=m,N=!0,g};O.toHexadecimal=O.toHex=function(i,t){return Ri(this,16,i,t)};O.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:Xt(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]?(N=!1,e=tt(e,i,0,t,1).times(i),N=!0,F(e)):(i.s=e.s,e=i),e};O.toNumber=function(){return+this};O.toOctal=function(i,t){return Ri(this,8,i,t)};O.toPower=O.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/q),t>=i.d.length-1&&(e=f<0?-f:f)<=Wr)return r=Qn(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):(N=!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),Te(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,N=!0,d.rounding=a,F(r,n,a))};O.toPrecision=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=le(n,n.e<=r.toExpNeg||n.e>=r.toExpPos):(Xt(i,1,we),t===void 0?t=r.rounding:Xt(t,0,8),n=F(new r(n),i,t),e=le(n,i<=n.e||n.e<=r.toExpNeg,i)),n.isNeg()&&!n.isZero()?"-"+e:e};O.toSignificantDigits=O.toSD=function(i,t){var e=this,n=e.constructor;return i===void 0?(i=n.precision,t=n.rounding):(Xt(i,1,we),t===void 0?t=n.rounding:Xt(t,0,8)),F(new n(e),i,t)};O.toString=function(){var i=this,t=i.constructor,e=le(i,i.e<=t.toExpNeg||i.e>=t.toExpPos);return i.isNeg()&&!i.isZero()?"-"+e:e};O.truncated=O.trunc=function(){return F(new this.constructor(this),this.e+1,1)};O.valueOf=O.toJSON=function(){var i=this,t=i.constructor,e=le(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=q-n.length,e&&(a+=pe(e)),a+=n;o=i[t],n=o+"",e=q-n.length,e&&(a+=pe(e))}else if(o===0)return"0";for(;o%10===0;)o/=10;return a+o}function Xt(i,t,e){if(i!==~~i||i<t||i>e)throw Error(ge+i)}function Te(i,t,e,n){var r,a,o,u;for(a=i[0];a>=10;a/=10)--t;return--t<0?(t+=q,r=0):(r=Math.ceil((t+1)/q),t%=q),a=Nt(10,q-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 Je(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/oi(4,e)).toString()):(e=16,r="2.3283064365386962890625e-10"),i.precision+=e,t=De(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 tt=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,v,S,P,D,B,x,A,E,$,I,Z,R,W,Q,J,Y,X=n.constructor,H=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?H*0:H/0);for(d?(v=1,m=n.e-r.e):(d=ee,v=q,m=Wt(n.e/v)-Wt(r.e/v)),J=l.length,W=s.length,B=new X(H),x=B.d=[],_=0;l[_]==(s[_]||0);_++);if(l[_]>(s[_]||0)&&m--,a==null?(I=a=X.precision,o=X.rounding):u?I=a+(n.e-r.e)+1:I=a,I<0)x.push(1),S=!0;else{if(I=I/v+2|0,_=0,J==1){for(g=0,l=l[0],I++;(_<W||g)&&I--;_++)Z=g*d+(s[_]||0),x[_]=Z/l|0,g=Z%l|0;S=g||_<W}else{for(g=d/(l[0]+1)|0,g>1&&(l=i(l,g,d),s=i(s,g,d),J=l.length,W=s.length),R=J,A=s.slice(0,J),E=A.length;E<J;)A[E++]=0;Y=l.slice(),Y.unshift(0),Q=l[0],l[1]>=d/2&&++Q;do g=0,f=t(l,A,J,E),f<0?($=A[0],J!=E&&($=$*d+(A[1]||0)),g=$/Q|0,g>1?(g>=d&&(g=d-1),P=i(l,g,d),D=P.length,E=A.length,f=t(P,A,D,E),f==1&&(g--,e(P,J<D?Y:l,D,d))):(g==0&&(f=g=1),P=l.slice()),D=P.length,D<E&&P.unshift(0),e(A,P,E,d),f==-1&&(E=A.length,f=t(l,A,J,E),f<1&&(g++,e(A,J<E?Y:l,E,d))),E=A.length):f===0&&(g++,A=[0]),x[_++]=g,f&&A[0]?A[E++]=s[R]||0:(A=[s[R]],E=1);while((R++<W||A[0]!==void 0)&&I--);S=A[0]!==void 0}x[0]||x.shift()}if(v==1)B.e=m,Wn=S;else{for(_=1,g=x[0];g>=10;g/=10)_++;B.e=_+m*v-1,F(B,u?a+B.e+1:a,o,S)}return B}}();function F(i,t,e,n){var r,a,o,u,d,f,m,_,g,v=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+=q,o=t,m=_[g=0],d=m/Nt(10,r-o-1)%10|0;else if(g=Math.ceil((a+1)/q),u=_.length,g>=u)if(n){for(;u++<=g;)_.push(0);m=d=0,r=1,a%=q,o=a-q+1}else break t;else{for(m=u=_[g],r=1;u>=10;u/=10)r++;a%=q,o=a-q+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,(q-t%q)%q),i.e=-t||0):_[0]=i.e=0,i;if(a==0?(_.length=g,u=1,g--):(_.length=g+1,u=Nt(10,q-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]==ee&&(_[0]=1));break}else{if(_[g]+=u,_[g]!=ee)break;_[g--]=0,u=1}for(a=_.length;_[--a]===0;)_.pop()}return N&&(i.e>v.maxE?(i.d=null,i.e=NaN):i.e<v.minE&&(i.e=0,i.d=[0])),i}function le(i,t,e){if(!i.isFinite())return Yn(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 ri(i,t){var e=i[0];for(t*=q;e>=10;e/=10)t++;return t}function ii(i,t,e){if(t>Zr)throw N=!0,e&&(i.precision=e),Error(Zn);return F(new i(ti),t,1,!0)}function ae(i,t,e){if(t>ji)throw Error(Zn);return F(new i(ei),t,e,!0)}function Hn(i){var t=i.length-1,e=t*q+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 Qn(i,t,e,n){var r,a=new i(1),o=Math.ceil(n/q+4);for(N=!1;;){if(e%2&&(a=a.times(t),Fn(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),Fn(t.d,o)}return N=!0,a}function Tn(i){return i.d[i.d.length-1]&1}function Jn(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,v=g.rounding,S=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?(N=!1,d=S):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(tt(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&&Te(o.d,d-n,v,f))g.precision=d+=10,e=a=u=new g(1),m=0,f++;else return F(o,g.precision=S,v,N=!0);else return g.precision=S,o}o=u}}function _e(i,t){var e,n,r,a,o,u,d,f,m,_,g,v=1,S=10,P=i,D=P.d,B=P.constructor,x=B.rounding,A=B.precision;if(P.s<0||!D||!D[0]||!P.e&&D[0]==1&&D.length==1)return new B(D&&!D[0]?-1/0:P.s!=1?NaN:D?0:P);if(t==null?(N=!1,m=A):m=t,B.precision=m+=S,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),v++;a=P.e,n>1?(P=new B("0."+e),a++):P=new B(n+"."+e.slice(1))}else return f=ii(B,m+2,A).times(a+""),P=_e(new B(n+"."+e.slice(1)),m-S).plus(f),B.precision=A,t==null?F(P,A,x,N=!0):P;for(_=P,d=o=P=tt(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(tt(o,new B(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(ii(B,m+2,A).times(a+""))),d=tt(d,new B(v),m,1),t==null)if(Te(d.d,m-S,x,u))B.precision=m+=S,f=o=P=tt(_.minus(1),_.plus(1),m,1),g=F(P.times(P),m,1),r=u=1;else return F(d,B.precision=A,x,N=!0);else return B.precision=A,d;d=f,r+=2}}function Yn(i){return String(i.s*i.s/0)}function Ye(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)%q,e<0&&(n+=q),n<r){for(n&&i.d.push(+t.slice(0,n)),r-=q;n<r;)i.d.push(+t.slice(n,n+=q));t=t.slice(n),n=q-t.length}else n-=r;for(;n--;)t+="0";i.d.push(+t),N&&(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 Xr(i,t){var e,n,r,a,o,u,d,f,m;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Gn.test(t))return Ye(i,t)}else if(t==="Infinity"||t==="NaN")return+t||(i.s=NaN),i.e=NaN,i.d=null,i;if($r.test(t))e=16,t=t.toLowerCase();else if(Ur.test(t))e=2;else if(Kr.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=Qn(n,new n(e),a,a*2)),f=Je(t,e,ee),m=f.length-1,a=m;f[a]===0;--a)f.pop();return a<0?new n(i.s*0):(i.e=ri(f,m),i.d=f,N=!1,o&&(i=tt(i,r,u*4)),d&&(i=i.times(Math.abs(d)<54?Nt(2,d):Le.pow(2,d))),N=!0,i)}function Gr(i,t){var e,n=t.d.length;if(n<3)return t.isZero()?t:De(i,2,t,t);e=1.4*Math.sqrt(n),e=e>16?16:e|0,t=t.times(1/oi(5,e)),t=De(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 De(i,t,e,n,r){var a,o,u,d,f=1,m=i.precision,_=Math.ceil(m/q);for(N=!1,d=e.times(e),u=new i(n);;){if(o=tt(u.times(d),new i(t++*t++),m,1),u=r?n.plus(o):n.minus(o),n=tt(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 N=!0,o.d.length=_+1,o}function oi(i,t){for(var e=i;--t;)e*=i;return e}function tr(i,t){var e,n=t.s<0,r=ae(i,i.precision,1),a=r.times(.5);if(t=t.abs(),t.lte(a))return fe=n?4:1,t;if(e=t.divToInt(r),e.isZero())fe=n?3:2;else{if(t=t.minus(e.times(r)),t.lte(a))return fe=Tn(e)?n?2:3:n?4:1,t;fe=Tn(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,v=i.constructor,S=e!==void 0;if(S?(Xt(e,1,we),n===void 0?n=v.rounding:Xt(n,0,8)):(e=v.precision,n=v.rounding),!i.isFinite())m=Yn(i);else{for(m=le(i),o=m.indexOf("."),S?(r=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):r=t,o>=0&&(m=m.replace(".",""),g=new v(1),g.e=m.length-o,g.d=Je(le(g),10,r),g.e=g.d.length),_=Je(m,10,r),a=d=_.length;_[--d]==0;)_.pop();if(!_[0])m=S?"0p+0":"0";else{if(o<0?a--:(i=new v(i),i.d=_,i.e=a,i=tt(i,g,e,n,0,r),_=i.d,a=i.e,f=Wn),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(S){if(d>1)if(t==16||t==8){for(o=t==16?4:3,--d;d%o;d++)m+="0";for(_=Je(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 Fn(i,t){if(i.length>t)return i.length=t,!0}function Hr(i){return new this(i).abs()}function Qr(i){return new this(i).acos()}function Jr(i){return new this(i).acosh()}function Yr(i,t){return new this(i).plus(t)}function to(i){return new this(i).asin()}function eo(i){return new this(i).asinh()}function io(i){return new this(i).atan()}function no(i){return new this(i).atanh()}function ro(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=ae(this,a,1).times(t.s>0?.25:.75),e.s=i.s):!t.d||i.isZero()?(e=t.s<0?ae(this,n,r):new this(0),e.s=i.s):!i.d||t.isZero()?(e=ae(this,a,1).times(.5),e.s=i.s):t.s<0?(this.precision=a,this.rounding=1,e=this.atan(tt(i,t,a,1)),t=ae(this,a,1),this.precision=n,this.rounding=r,e=i.s<0?e.minus(t):e.plus(t)):e=this.atan(tt(i,t,a,1)),e}function oo(i){return new this(i).cbrt()}function so(i){return F(i=new this(i),i.e+1,2)}function ao(i,t,e){return new this(i).clamp(t,e)}function co(i){if(!i||typeof i!="object")throw Error(ni+"Object expected");var t,e,n,r=i.defaults===!0,a=["precision",1,we,"rounding",0,8,"toExpNeg",-xe,0,"toExpPos",0,xe,"maxE",0,xe,"minE",-xe,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 lo(i){return new this(i).cos()}function uo(i){return new this(i).cosh()}function er(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,In(a)){f.s=a.s,N?!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++;N?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 Ye(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),Gn.test(a)?Ye(f,a):Xr(f,a);if(d==="bigint")return a<0?(a=-a,f.s=-1):f.s=1,Ye(f,a.toString());throw Error(ge+a)}if(r.prototype=O,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=co,r.clone=er,r.isDecimal=In,r.abs=Hr,r.acos=Qr,r.acosh=Jr,r.add=Yr,r.asin=to,r.asinh=eo,r.atan=io,r.atanh=no,r.atan2=ro,r.cbrt=oo,r.ceil=so,r.clamp=ao,r.cos=lo,r.cosh=uo,r.div=fo,r.exp=ho,r.floor=mo,r.hypot=po,r.ln=_o,r.log=go,r.log10=wo,r.log2=bo,r.max=yo,r.min=vo,r.mod=Mo,r.mul=Co,r.pow=So,r.random=Po,r.round=ko,r.sign=Ao,r.sin=Oo,r.sinh=xo,r.sqrt=Do,r.sub=Bo,r.sum=Eo,r.tan=Vo,r.tanh=To,r.trunc=Fo,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 fo(i,t){return new this(i).div(t)}function ho(i){return new this(i).exp()}function mo(i){return F(i=new this(i),i.e+1,3)}function po(){var i,t,e=new this(0);for(N=!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 N=!0,new this(1/0);e=t}return N=!0,e.sqrt()}function In(i){return i instanceof Le||i&&i.toStringTag===Xn||!1}function _o(i){return new this(i).ln()}function go(i,t){return new this(i).log(t)}function bo(i){return new this(i).log(2)}function wo(i){return new this(i).log(10)}function yo(){return Jn(this,arguments,-1)}function vo(){return Jn(this,arguments,1)}function Mo(i,t){return new this(i).mod(t)}function Co(i,t){return new this(i).mul(t)}function So(i,t){return new this(i).pow(t)}function Po(i){var t,e,n,r,a=0,o=new this(1),u=[];if(i===void 0?i=this.precision:Xt(i,1,we),n=Math.ceil(i/q),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%=q,n&&i&&(r=Nt(10,q-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-=q)u.shift();for(n=1,r=u[0];r>=10;r/=10)n++;n<q&&(e-=q-n)}return o.e=e,o.d=u,o}function ko(i){return F(i=new this(i),i.e+1,this.rounding)}function Ao(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function Oo(i){return new this(i).sin()}function xo(i){return new this(i).sinh()}function Do(i){return new this(i).sqrt()}function Bo(i,t){return new this(i).sub(t)}function Eo(){var i=0,t=arguments,e=new this(t[i]);for(N=!1;e.s&&++i<t.length;)e=e.plus(t[i]);return N=!0,F(e,this.precision,this.rounding)}function Vo(i){return new this(i).tan()}function To(i){return new this(i).tanh()}function Fo(i){return F(i=new this(i),i.e+1,1)}O[Symbol.for("nodejs.util.inspect.custom")]=O.toString;O[Symbol.toStringTag]="Decimal";var Le=O.constructor=er(Li);ti=new Le(ti);ei=new Le(ei);var Yt=Le;function k(i){return Yt.isDecimal(i)?i:new Yt(i===void 0?0:i)}function ir(i){return k(10).pow(k(i).abs())}function ce(i,t,e=Yt.ROUND_DOWN){let n=ir(k(t));return k(i).mul(n).toFixed(0,e).toString()}function ye(i,t=32){return Number(BigInt.asIntN(t,BigInt(i)))}function be(i,t){let e=ir(k(t));return k(i).div(e).toString()}var nr="0x2::sui::SUI",Io="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";var zt=class qt{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=>{jn(r.coin_type)===jn(t)&&n.push(r)}),n}static isSuiCoin(t){return ie(t).full_address===nr}static selectCoinObjectIdGreaterThanOrEqual(t,e,n=[]){let r=qt.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=qt.sortByBalance(t.filter(f=>!n.includes(f.coin_object_id))),a=qt.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:qt.sortByBalance(u),remain_coins:qt.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=qt.getCoinAssets(r,e);if(n===BigInt(0))return this.buildZeroValueCoin(e,t,r,a);let d=qt.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)&&qt.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(qt.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(qt.isSuiCoin(r)){if(n===0n&&e.length>1){let d=qt.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=qt.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=qt.selectCoinObjectIdGreaterThanOrEqual(n,e),o=a.amount_array.reduce((S,P)=>Number(S)+Number(P),0).toString(),u=a.object_array,[d,...f]=u,m=t.object(d),_=m,g=a.amount_array.reduce((S,P)=>Number(S)+Number(P),0).toString(),v;return f.length>0&&t.mergeCoins(m,f.map(S=>t.object(S))),r&&Number(o)>Number(e)&&(_=t.splitCoins(m,[t.pure.u64(e)]),v=m),{original_spited_coin:v,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=qt.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=qt.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&&k(r.amount).eq(e)?(r.used=!0,!0):!1);return n?n.coin_object_id:Jt("CoinNotFound",`Coin not found for ${e} ${t.coin_type}`)}static buildMultiCoinInput(t,e,n,r){let a=qt.getCoinAssets(n,e);if(qt.isSuiCoin(n)){let _=t.splitCoins(t.gas,r.map(g=>t.pure.u64(g)));return{amount_coin_array:r.map((g,v)=>({coin_object_id:_[v],amount:g.toString(),used:!1})),coin_type:n,remain_coins:a}}let o=r.reduce((_,g)=>_+g,BigInt(0)),u=qt.selectCoinObjectIdGreaterThanOrEqual(a,o);if(u.object_array.length===0)return Jt("InsufficientBalance",`No enough coins for ${n} expect ${o} actual ${qt.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 Lo(i){return i.startsWith("0x")?`${i.slice(2)}`:i}function Ln(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 ie(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={...ie(t),type_arguments:e.map(o=>ie(o).source_address)};return a.type_arguments=a.type_arguments.map(o=>zt.isSuiCoin(o)?o:ie(o).source_address),a.source_address=Ln(a.full_address,a.type_arguments),a}let n=t.split("::"),r={full_address:t,address:t===nr||t===Io?"0x2":(0,Ce.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=Ln(r.full_address,r.type_arguments),r}catch{return{full_address:i,address:"",module:"",name:"",type_arguments:[],source_address:i}}}function jn(i){return ie(i).source_address}var U=(i,t=!0)=>{let e=i.split("::"),n=e.shift(),r=(0,Ce.normalizeSuiObjectId)(n);return t&&(r=Lo(r)),`${r}::${e.join("::")}`};var Uo=Fe(Ie()),qn=443636,Rn=-443636,$o="79226673515401279992447579055";var Ko="4295048016",ps=new Uo.default(1e6),Wo=(i=>(i[i.BelowRange=0]="BelowRange",i[i.InRange=1]="InRange",i[i.AboveRange=2]="AboveRange",i))(Wo||{}),Zt="0x0000000000000000000000000000000000000000000000000000000000000006";var _s=(0,Ni.getFullnodeUrl)("mainnet"),gs=(0,Ni.getFullnodeUrl)("testnet");var Rt=Fe(Ie()),de=new Rt.default(0),Ve=new Rt.default(1),si=new Rt.default(2),Zo=si.pow(new Rt.default(128)),Nn=si.pow(new Rt.default(64)).sub(Ve),zo=si.pow(new Rt.default(128)).sub(Ve),te=class{static toX64BN(i){return i.mul(new Rt.default(2).pow(new Rt.default(64)))}static toX64Decimal(i){return i.mul(Yt.pow(2,64))}static toX64(i){return new Rt.default(i.mul(Yt.pow(2,64)).floor().toFixed())}static fromX64(i){return new Yt(i.toString()).mul(Yt.pow(2,-64))}static fromX64Decimal(i){return i.mul(Yt.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(Nn).gt(de)&&(t=t.add(Ve)),t}static divRoundUp(i,t){return i.mod(t).eq(de)?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)&&Jt("MultiplicationOverflow","Multiplication overflow"),n}static checkMulDivFloor(i,t,e,n){e.eq(de)&&Jt("DivisionByZero","Divide by zero");let r=i.mul(t).div(e);return this.isOverflow(r,n)&&Jt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulDivCeil(i,t,e,n){if(e.eq(de))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(de)&&Jt("DivisionByZero","Divide by zero");let r=i.mul(t.add(e.shrn(1))).div(e);return this.isOverflow(r,n)&&Jt("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)&&Jt("MultiplicationOverflow","Multiplication shift right overflow"),r}static checkMulShiftRight64RoundUpIf(i,t,e,n){let r=i.mul(t),a=n&&r.and(Nn).gt(de)?r.shrn(64).add(Ve):r.shrn(64);return this.isOverflow(a,e)&&Jt("MultiplicationOverflow","Multiplication shift right overflow"),a}static checkMulShiftLeft(i,t,e,n){let r=i.mul(t).shln(e);return this.isOverflow(r,n)&&Jt("MultiplicationOverflow","Multiplication shift left overflow"),r}static checkDivRoundUpIf(i,t,e){return t.eq(de)&&Jt("DivisionByZero","Divide by zero"),e?this.divRoundUp(i,t):i.div(t)}static isOverflow(i,t){return i.gte(si.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(de)?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(de)?i:this.u128Neg(i).add(new Rt.default(1)).or(new Rt.default(1).shln(127))}static u128ToI128(i){return i.testn(127)?Zo.sub(i).neg():i}},Ui=class{static getMinIndex(i){return Rn+Math.abs(Rn)%i}static getMaxIndex(i){return qn-qn%i}};function rr(i){return i.data}function Xo(i){return i.data!==void 0}function Go(i){return i.content!==void 0}function or(i){let t="data"in i?rr(i):i;if(!(!t||!Go(t)||t.content.dataType!=="moveObject"))return t.content}function Ho(i){return or(i)?.type}function $i(i){let t=Xo(i)?i.data:i;return!t?.type&&"data"in i?t?.content?.dataType==="package"?"package":Ho(i):t?.type}function ai(i){return rr(i)?.previousTransaction}function ne(i){let t=or(i)?.fields;if(t)return"fields"in t?t.fields:t}Yt.config({precision:64,rounding:Yt.ROUND_DOWN,toExpNeg:-64,toExpPos:64});var Kt=Yt,Gt=Fe(Ie()),j=Fe(Ie()),Qo=14,Jo="59543866431248",Yo="184467440737095516",ts="15793534762490258745";function es(i,t,e){let n=i.toTwos(e).shln(t);return n.imaskn(e+1),n.fromTwos(e)}function z(i,t,e){let n=i.toTwos(e).shrn(t);return n.imaskn(e-t+1),n.fromTwos(e-t)}function is(i){let t;return i&1?t=new j.default("79232123823359799118286999567"):t=new j.default("79228162514264337593543950336"),i&2&&(t=z(t.mul(new j.default("79236085330515764027303304731")),96,256)),i&4&&(t=z(t.mul(new j.default("79244008939048815603706035061")),96,256)),i&8&&(t=z(t.mul(new j.default("79259858533276714757314932305")),96,256)),i&16&&(t=z(t.mul(new j.default("79291567232598584799939703904")),96,256)),i&32&&(t=z(t.mul(new j.default("79355022692464371645785046466")),96,256)),i&64&&(t=z(t.mul(new j.default("79482085999252804386437311141")),96,256)),i&128&&(t=z(t.mul(new j.default("79736823300114093921829183326")),96,256)),i&256&&(t=z(t.mul(new j.default("80248749790819932309965073892")),96,256)),i&512&&(t=z(t.mul(new j.default("81282483887344747381513967011")),96,256)),i&1024&&(t=z(t.mul(new j.default("83390072131320151908154831281")),96,256)),i&2048&&(t=z(t.mul(new j.default("87770609709833776024991924138")),96,256)),i&4096&&(t=z(t.mul(new j.default("97234110755111693312479820773")),96,256)),i&8192&&(t=z(t.mul(new j.default("119332217159966728226237229890")),96,256)),i&16384&&(t=z(t.mul(new j.default("179736315981702064433883588727")),96,256)),i&32768&&(t=z(t.mul(new j.default("407748233172238350107850275304")),96,256)),i&65536&&(t=z(t.mul(new j.default("2098478828474011932436660412517")),96,256)),i&131072&&(t=z(t.mul(new j.default("55581415166113811149459800483533")),96,256)),i&262144&&(t=z(t.mul(new j.default("38992368544603139932233054999993551")),96,256)),z(t,32,256)}function ns(i){let t=Math.abs(i),e;return t&1?e=new j.default("18445821805675392311"):e=new j.default("18446744073709551616"),t&2&&(e=z(e.mul(new j.default("18444899583751176498")),64,256)),t&4&&(e=z(e.mul(new j.default("18443055278223354162")),64,256)),t&8&&(e=z(e.mul(new j.default("18439367220385604838")),64,256)),t&16&&(e=z(e.mul(new j.default("18431993317065449817")),64,256)),t&32&&(e=z(e.mul(new j.default("18417254355718160513")),64,256)),t&64&&(e=z(e.mul(new j.default("18387811781193591352")),64,256)),t&128&&(e=z(e.mul(new j.default("18329067761203520168")),64,256)),t&256&&(e=z(e.mul(new j.default("18212142134806087854")),64,256)),t&512&&(e=z(e.mul(new j.default("17980523815641551639")),64,256)),t&1024&&(e=z(e.mul(new j.default("17526086738831147013")),64,256)),t&2048&&(e=z(e.mul(new j.default("16651378430235024244")),64,256)),t&4096&&(e=z(e.mul(new j.default("15030750278693429944")),64,256)),t&8192&&(e=z(e.mul(new j.default("12247334978882834399")),64,256)),t&16384&&(e=z(e.mul(new j.default("8131365268884726200")),64,256)),t&32768&&(e=z(e.mul(new j.default("3584323654723342297")),64,256)),t&65536&&(e=z(e.mul(new j.default("696457651847595233")),64,256)),t&131072&&(e=z(e.mul(new j.default("26294789957452057")),64,256)),t&262144&&(e=z(e.mul(new j.default("37481735321082")),64,256)),e}var rt=class se{static priceToSqrtPriceX64(t,e,n){return te.toX64(t.mul(Kt.pow(10,n-e)).sqrt())}static sqrtPriceX64ToPrice(t,e,n){return te.fromX64(t).pow(2).mul(Kt.pow(10,e-n))}static tickIndexToSqrtPriceX64(t){return t>0?new j.default(is(t)):new j.default(ns(t))}static sqrtPriceX64ToTickIndex(t){if(t.gt(new j.default($o))||t.lt(new j.default(Ko)))throw new Error("Provided sqrtPrice is not within the supported sqrtPrice range.");let e=t.bitLength()-1,n=new j.default(e-64),r=es(n,32,128),a=new j.default("8000000000000000","hex"),o=0,u=new j.default(0),d=e>=64?t.shrn(e-63):t.shln(63-e);for(;a.gt(new j.default(0))&&o<Qo;){d=d.mul(d);let v=d.shrn(127);d=d.shrn(63+v.toNumber()),u=u.add(a.mul(v)),a=a.shrn(1),o+=1}let f=u.shrn(32),m=r.add(f).mul(new j.default(Jo)),_=z(m.sub(new j.default(Yo)),64,128).toNumber(),g=z(m.add(new j.default(ts)),64,128).toNumber();return _===g?_:se.tickIndexToSqrtPriceX64(g).lte(t)?g:_}static tickIndexToPrice(t,e,n){return se.sqrtPriceX64ToPrice(se.tickIndexToSqrtPriceX64(t),e,n)}static priceToTickIndex(t,e,n){return se.sqrtPriceX64ToTickIndex(se.priceToSqrtPriceX64(t,e,n))}static priceToInitializeTickIndex(t,e,n,r){return se.getInitializeTickIndex(se.priceToTickIndex(t,e,n),r)}static getInitializeTickIndex(t,e){return t-t%e}static getNextInitializeTickIndex(t,e){return se.getInitializeTickIndex(t,e)+e}static getPrevInitializeTickIndex(t,e){return se.getInitializeTickIndex(t,e)-e}};function He(i,t,e){let n=Gt.default.min(i,t),r=Gt.default.max(i,t),a=te.fromX64BN(e.mul(r).mul(n)),o=r.sub(n);return!a.isZero()&&!o.isZero()?a.div(o):new Gt.default(0)}function Qe(i,t,e){let n=Gt.default.min(i,t),r=Gt.default.max(i,t).sub(n);return r.isZero()?new Gt.default(0):e.shln(64).div(r)}var re=class Oe{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=te.toX64Decimal(o).mul(f.sub(d)).div(d.mul(f)),_=new Kt(0)):e.lt(r)?(m=te.toX64Decimal(o).mul(f.sub(u)).div(u.mul(f)),_=te.fromX64Decimal(o.mul(u.sub(d)))):(m=new Kt(0),_=te.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=rt.sqrtPriceX64ToTickIndex(u),f=rt.tickIndexToSqrtPriceX64(t),m=rt.tickIndexToSqrtPriceX64(e),_;if(d<t){if(!r)throw new Error("lower tick cannot calculate liquidity by coinB");_=He(f,m,n)}else if(d>e){if(r)throw new Error("upper tick cannot calculate liquidity by coinA");_=Qe(m,f,n)}else r?_=He(u,m,n):_=Qe(u,f,n);let g=Oe.getCoinAmountFromLiquidity(_,u,f,m,a),v=a?k(g.coin_amount_a.toString()).mul(1+o).toString():k(g.coin_amount_a.toString()).mul(1-o).toString(),S=a?k(g.coin_amount_b.toString()).mul(1+o).toString():k(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(v).toString():Kt.floor(v).toString(),coin_amount_limit_b:a?Kt.ceil(S).toString():Kt.floor(S).toString(),liquidity_amount:_.toString(),fix_amount_a:r}}static estimateLiquidityFromCoinAmounts(t,e,n,r){if(e>n)return Jt("InvalidTick","lower tick cannot be greater than lower tick",{[Ti.METHOD_NAME]:"estimateLiquidityFromCoinAmounts",[Ti.REQUEST_PARAMS]:{lower_tick:e,upper_tick:n,token_amount:r}});let a=rt.sqrtPriceX64ToTickIndex(t),o=rt.tickIndexToSqrtPriceX64(e),u=rt.tickIndexToSqrtPriceX64(n);if(a<e)return He(o,u,new Gt.default(r.coin_amount_a)).toString();if(a>=n)return Qe(u,o,new Gt.default(r.coin_amount_b)).toString();let d=He(t,u,new Gt.default(r.coin_amount_a)),f=Qe(t,o,new Gt.default(r.coin_amount_b));return Gt.default.min(d,f).toString()}static calculateDepositRatio(t,e,n){let r=new Gt.default(1e8),{coin_amount_b:a}=Oe.estLiquidityAndCoinAmountFromOneAmounts(t,e,r,!0,!0,0,n),o=rt.sqrtPriceX64ToPrice(n,0,0),u=k(r.toString()).mul(o),d=u.add(a.toString()),f=u.div(d),m=k(a.toString()).div(d);return{ratio_a:f,ratio_b:m}}static calculateAmountDepositRatio(t,e,n,r,a){let o=rt.sqrtPriceX64ToPrice(n,r,a),u=rt.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 Gt.default(ce(1,r)),{coin_amount_b:f}=Oe.estLiquidityAndCoinAmountFromOneAmounts(t,e,d,!0,!0,0,n),m=be(d.toString(),r),_=be(f.toString(),a),g=k(m).add(_),v=k(m).div(g),S=k(_).div(g);return{ratio_a:v,ratio_b:S,curr_price:o}}static getCoinAmountsFromRatio(t,e,n,r,a,o,u){let d=k(ce(k(n).mul(t).div(r).toString(),o)).toFixed(0),f=k(ce(k(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}=Oe.calculateDepositRatio(t,e,n);return Oe.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 bs=Fe(Ie());var pn=require("@cetusprotocol/sui-clmm-sdk");var Ee=require("@mysten/sui/transactions"),Ht=oe(require("bn.js")),dr=require("@cetusprotocol/aggregator-sdk");var fr=require("@mysten/sui/utils"),hr=oe(require("decimal.js"));var $t=oe(require("bn.js")),li=oe(require("decimal.js"));var Ki=oe(require("bn.js")),Wi=oe(require("decimal.js")),ci=(i,t,e)=>{if(t==="min"){if(i===Ui.getMinIndex(e))return!0}else if(i===Ui.getMaxIndex(e))return!0;return!1};function rs(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 sr(i,t,e,n,r){let a=new Ki.default(10).pow(new Ki.default(n)),{coin_amount_b:o}=re.estLiquidityAndCoinAmountFromOneAmounts(i,t,a,!0,!0,0,e),u=rt.sqrtPriceX64ToPrice(e,n,r),d=k(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),_=k(o.toString()).div(f);return{ratioA:m,ratioB:_}}function ue(i,t,e,n,r,a,o){let u=k(ce(k(e).mul(i).div(n).toString(),a)).toFixed(0),d=k(ce(k(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}=sr(i,t,e,o,u);return ue(d,f,n,r,a,o,u)}var Se=10n;function je(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:U(o.coin_type_a.fields.name,!1),coin_type_b:U(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:ye(BigInt(o.tick_lower_index.fields.bits)),tick_upper_index:ye(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:v}=_.fields;return{coin_type:U(g.fields.name,!1),value:v}});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:ie(t.quote_type.fields.name).full_address,lp_token_type:ie(e).type_arguments[0],balances:f,protocol_fee_rate:t.protocol_fee_rate}}async function os(i,t=!0){i.getData().commands.forEach((e,n)=>{})}function qe(i,t){let e=k(i).div(t).toString(),n=k(t).div(i).toString();return{quote_per_base:e,base_per_quote:n}}function ar(i,t,e,n){let r=10n**(Se+n-e),a=10n**(Se+e-n),o=te.checkMulDivFloor(new $t.default(i.toString()),new $t.default(r.toString()),new $t.default(t.toString()),64),u=te.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 Me(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}=ar(BigInt(e.oracle_price),BigInt(a.oracle_price),BigInt(e.coin_decimals),BigInt(a.coin_decimals)),d=te.checkMulDivFloor(new $t.default(u.toString()),new $t.default(o),new $t.default((BigInt(10)**Se).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:v}=e,S=[...n],P=o&&U(t.quote_type,!1),D=rt.tickIndexToSqrtPriceX64(d),B=rt.tickIndexToSqrtPriceX64(f),{coin_amount_a:x,coin_amount_b:A}=re.getCoinAmountFromLiquidity(new $t.default(m),new $t.default(_),new $t.default(D),new $t.default(B),!1);S.push({coin_type:g,value:x.toString()}),S.push({coin_type:v,value:A.toString()});let E={};S.forEach(W=>{let Q=U(W.coin_type,!1),J=k(W.value),Y=E[Q]||0;E[Q]=J.add(Y).toString()});let $=Object.entries(E).filter(([W,Q])=>k(Q).gt(0)).map(([W])=>W);if(P&&!$.includes(P)&&$.push(P),$.length===0)return"0";let I=await i.PythPrice.getLatestPrice($,r),Z={};return $.forEach(W=>{let Q=I[W];if(Q)Z[W]={price:Q,value:E[W]||"0"};else throw Error(`find ${W} price fail `)}),Me(Z,P).toString()}function Re(i,t,e){return k(i).eq(0)?t:k(i).mul(t).div(e).toFixed(0,li.default.ROUND_HALF_UP)}function ss(i,t,e){return k(i).eq(0)?"0":k(i).mul(t).div(e).toFixed(0,li.default.ROUND_HALF_UP)}function Pe(i,t,e){return k(i).eq(0)?"0":k(t).mul(e).div(i).toFixed(0,li.default.ROUND_HALF_UP)}function ke(i,t,e){let n={};return t.forEach(r=>{let a=Pe(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=Pe(e.lp_token_treasury,t,d),m=rt.tickIndexToSqrtPriceX64(r),_=rt.tickIndexToSqrtPriceX64(a),g=re.getCoinAmountFromLiquidity(new $t.default(f),new $t.default(n.current_sqrt_price),m,_,!0),v=g.coin_amount_a.toString(),S=g.coin_amount_b.toString(),P=ke(t,e.balances,e.lp_token_treasury),D=k(v).add(P[o]?.value||"0").toFixed(0),B=k(S).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:B,coin_type_a:o,coin_type_b:u}}function Ne(i,t,e){let n=[];return t.forEach(r=>{k(r.value).gt(0)&&n.push(r)}),e.forEach(r=>{k(r.value).gt(0)&&n.push(r)}),i.forEach(r=>{k(r.value).gt(0)&&n.push(r)}),n}function Ue(i,t,e){let n=new Set;return i.forEach(r=>n.add(r)),n.add(t),n.add(e),Array.from(n)}function Gi(i,t){if(!Se)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(t<0n){let e=10n**(Se- -t);return i*e}return i/10n**(t+Se)}function Hi(i){return`0x${Buffer.from(i).toString("hex")}`}function as(i,t,e,n,r){let a="0",o="0";return ci(i,"min",Number(e))?a="0":a=rt.tickIndexToPrice(Number(i),n,r).toString(),ci(t,"max",Number(e))?o="\u221E":o=rt.tickIndexToPrice(Number(t),n,r).toString(),{minPrice:a,maxPrice:o}}function ui(i){let t=ne(i),e=$i(i),n=ie(e),r=t.position.fields,a={id:r.id.id,pool_id:r.pool,index:r.index,liquidity:r.liquidity,tick_lower_index:ye(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:ye(BigInt(r.tick_upper_index.fields.bits)),coin_type_a:U(r.coin_type_a.fields.name,!1),coin_type_b:U(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:U(t.coin_a.fields.name,!1),coin_type_b:U(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=ne(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 cr=oe(require("decimal.js")),di=require("@mysten/sui/bcs"),fi=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:U(a.fields.name,!1),coin_type_b:U(o.fields.name,!1),vault_id:u,position_keys:d.fields.contents}}function cs(i){return{uri:i.uri,index:i.index,id:i.id.id,name:i.name,pool_id:i.pool_id,lower_bin_id:ye(BigInt(i.lower_bin_id.fields.bits)),upper_bin_id:ye(BigInt(i.upper_bin_id.fields.bits)),liquidity_shares:i.liquidity_shares,description:i.description,coin_type_a:U(i.coin_type_a,!1),coin_type_b:U(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:v,value:S}=g.fields;return{coin_type:U(v.fields.name,!1),value:S}}),o=cs(e.fields),u=o.lower_bin_id,d=o.liquidity_shares.map((g,v)=>({bin_id:u+v,liquidity:g})).filter(g=>k(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:v,quote_type:S}=t,P=(Number(n)&1)!==0,D=(Number(n)&2)!==0,{balances:B}=r.fields,x=B.fields.contents.map($=>{let{key:I,value:Z}=$.fields;return{coin_type:U(I.fields.name,!1),value:Z}}),A=S.fields.pos0.fields.name;return{id:d.id,lp_token_treasury:m.fields.total_supply.fields.value,hard_cap:u,quote_type:A?U(A,!1):void 0,protocol_fee_rate:g,buffer_assets:x,protocol_fees_handle:{id:v.fields.id.id,size:v.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:U(a.fields.name,!1),coin_type_b:U(o.fields.name,!1),lp_token_type:ie(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,v=r&&U(r,!1);u.push({coin_type:a,value:_.toString()}),u.push({coin_type:o,value:g.toString()});let S={};u.forEach(A=>{let E=U(A.coin_type,!1),$=k(A.value),I=S[E]||0;S[E]=$.add(I).toString()});let P=Object.entries(S).filter(([A,E])=>k(E).gt(0)).map(([A])=>A);if(v&&!P.includes(v)&&P.push(v),P.length===0)return"0";let D=await i.VaultsV2.PythPrice.getLatestPrice(P,n),B={};return P.forEach(A=>{let E=D[A];if(E)B[A]={price:E,value:S[A]||"0"};else throw Error(`find ${A} price fail `)}),Me(B,v).toString()}async function hi(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:v}=m.position,{receive_amount_a:S,receive_amount_b:P,valid_lower_bin_id:D,valid_upper_bin_id:B,bin_infos:x,position_coin_amount_a:A,position_coin_amount_b:E}=await $e(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:v,valid_lower_bin_id:D,valid_upper_bin_id:B,original_lower_bin_id:_,original_upper_bin_id:g,amount_a:S,amount_b:P,position_amount_a:A,position_amount_b:E,coin_type_a:a,coin_type_b:o,bin_infos:x}}async function $e(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,v=await i.CetusDlmmSDK.Pool.getBinInfo(m.bin_manager_handle,g,_,!1),S=k(t).div(a),P=(0,Ji.parseLiquidityShares)(d.position.liquidity_shares.map(R=>k(R.toString()).mul(S).toFixed(0,cr.default.ROUND_HALF_UP).toString()),_,f,v),D=P.amount_a,B=P.amount_b,x=ke(t,e.buffer_assets,a),A=x[o]?.value||"0",E=x[u]?.value||"0",$=k(D.toString()).add(A).toFixed(0),I=k(B.toString()).add(E).toFixed(0),Z=P.bins.filter(R=>k(R.liquidity).gt(0));return{valid_lower_bin_id:Z.length>0?Z[0].bin_id:P.bins[0].bin_id,valid_upper_bin_id:Z.length>0?Z[Z.length-1].bin_id:P.bins[P.bins.length-1].bin_id,receive_amount_a:$,receive_amount_b:I,position_coin_amount_a:D,position_coin_amount_b:B,bin_infos:{bins:Z,amount_a:P.amount_a,amount_b:P.amount_b}}}function rn(i){let t=di.bcs.vector(di.bcs.u8()).serialize(new TextEncoder().encode("DLMM_MARKET")).toBytes();return(0,fi.deriveObjectID)(i,"vector<u8>",t)}function ls(i,t){let e=di.bcs.Address.serialize(t).toBytes();return(0,fi.deriveDynamicFieldID)(i,"0x2::object::ID",e)}function Ke(i,t,e,n){let r=k(i),a=k(e),o=k(n),u=r,d=t?r:k(0),f=t?k(0):r,m=o,_=k(o).mul(.999),g=k(0),v=u,S=null;function P(x){if(t){let A=d.minus(x),E=f.plus(x.mul(a));return{A,B:E,R:E.div(A)}}else{let A=d.plus(x.mul(a)),E=f.minus(x);return{A,B:E,R:A.div(E)}}}for(let x=0;x<120;x++){let A=g.plus(v).div(2),{A:E,B:$,R:I}=P(A);if(E.lte(0)||$.lte(0)){v=A;continue}if(I.gt(m))v=A;else if(I.lt(_))g=A;else{if(S=A,k(_).eq(0))break;v=A}}if(!S)return{swap_amount:"0",final_amount_a:d.toFixed(0),final_amount_b:f.toFixed(0)};let{A:D,B}=P(S);return{swap_amount:S.toFixed(0),final_amount_a:D.toFixed(0),final_amount_b:B.toFixed(0),best:S.toString()}}var Be=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 he(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 he(cn)}var lr=(e=>(e.mainnet="mainnet",e.testnet="testnet",e))(lr||{});function us(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 ur(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 ds=16*1024,Ae=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 Be.SuiPriceServiceConnection(g),this.suiPythClient=new Be.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()};ur(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)))?.parsed?.forEach((u,d)=>{if(u){let{price:f,expo:m,publish_time:_}=u.price,g=k(f).mul(k(10).pow(k(m))).toString(),v=a[d],S={coin_type:v.coin_type,price:g,coin_decimals:v.coin_decimals,oracle_price:0n,last_update_time:_};S.oracle_price=Gi(BigInt(f),BigInt(m)),n[r[d]]=S,this._sdk.updateCache(`getLatestPrice_${S.coin_type}`,S)}}),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 Be.SuiPriceServiceConnection(n);try{return await this.connection.getPriceFeedsUpdateData(t)}catch(r){this.recordError(r,t,"getPriceFeedsUpdateData")}}}}async getLatestPriceFeeds(t){try{return await this.connection.getLatestPriceUpdates(t,{parsed:!0})}catch(e){this.recordError(e,t,"getLatestPriceFeeds");let{secondary:n}=this.pythConfigs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Be.SuiPriceServiceConnection(n);try{return await this.connection.getLatestPriceUpdates(t,{parsed:!0})}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:ds}).toBytes()),f[0],e.object(Zt)]}),_=0;for(let g of o){let v=await this.suiPythClient.getPriceFeedObjectId(g);if(!v)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(v),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(v),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=U(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:U(t,!0)}}),{fields:u}=o.data.content.fields.value,d={coin_type:t,price_feed_id:Hi(u.price_feed_id),coin_decimals:u.coin_decimals};return this._sdk.updateCache(n,d),d}};var We=class{_sdk;pythPrice;constructor(t){this._sdk=t;let{vaults:e,pythConfigs:n}=t.sdkOptions;this.pythPrice=new Ae(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 Ee.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...d.map(x=>x.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 v=await this._sdk.FullClient.sendSimulationTransaction(g,(0,fr.normalizeSuiAddress)("0x0")),S=`${e}::pool::FeeClaimedEvent`,P=`${e}::pool::RewardClaimedEvent`,D=[],B=[];return v?.events.forEach(x=>{let{parsedJson:A,type:E}=x;E===S&&(D.push({coin_type:U(m,!1),value:A.amount_a}),D.push({coin_type:U(_,!1),value:A.amount_b})),E===P&&B.push({coin_type:U(A.reward_type.name,!1),value:A.amount})}),this._sdk.updateCache(a,{feeList:D,rewarderList:B},10*1e3),{feeList:D,rewarderList:B}}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=je(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 getAssignPoolList(t){if(t.length===0)return[];let e=[],n=await this._sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let r of n){let a=je(r.data.content);this._sdk.updateCache(`getPool_${a.id}`,a),e.push(a)}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._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),o=je(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 Ee.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 Ee.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,re_balance:u}=t,{pool:d,clmmPool:f}=await this.getVaultAndPool(n,!0),{lp_token_type:m}=d,{rewarder_infos:_,id:g,coin_type_a:v,coin_type_b:S}=f,P=_.map(Z=>U(Z.coin_type,!1)),D=Ue(P,f.coin_type_a,f.coin_type_b),{published_at:B,configs:x,clmm_configs:A}=this._sdk.sdkOptions.vaults;e=e||new Ee.Transaction,e=this.buildCollectRewardPayload({reward_coin_types:P,lp_token_type:m,pool_id:n,clmm_pool_id:g,coin_type_a:v,coin_type_b:S},e),e=this.buildCollectFeePayload({lp_token_type:m,pool_id:n,clmm_pool_id:g,coin_type_a:v,coin_type_b:S},e),e=await this.pythPrice.buildUpdatePythPricePayload(D,e),e.moveCall({target:`${B}::pool::calculate_aum`,typeArguments:[v,S,m],arguments:[e.object(n),e.object(x.global_config_id),e.object(x.pyth_oracle_id),e.object(A.global_config_id),e.object(g),e.object(Zt)]});let E,$;if(u&&u.swap_result){let{swap_result:Z,coin_amount:R,mode:W,swap_slippage:Q}=u,{swap_in_amount:J,swap_out_amount:Y,route_obj:X}=Z,H=zt.buildCoinWithBalance(BigInt(R),W==="OnlyCoinA"?v:S,e),s=e.splitCoins(H,[J]),l={router:X,slippage:Q,txb:e,inputCoin:s},h=await this._sdk.AggregatorClient.fixableRouterSwapV3(l);E=W==="OnlyCoinA"?H:h,$=W==="OnlyCoinA"?h:H}else E=zt.buildCoinWithBalance(BigInt(r),v,e),$=zt.buildCoinWithBalance(BigInt(a),S,e);let I=e.moveCall({target:`${B}::pool::${o?"deposit_for":"deposit"}`,typeArguments:[v,S,m],arguments:[e.object(n),e.object(x.global_config_id),e.object(x.pyth_oracle_id),e.object(A.global_config_id),e.object(g),E,$,e.object(Zt)]});return o?I: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:v}=this._sdk.sdkOptions.vaults;e=e||new Ee.Transaction;let{lp_token_type:S,clmm_vault:P,lp_token_treasury:D}=f,{rewarder_infos:B,id:x,coin_type_a:A,coin_type_b:E,liquidity:$}=m,I=B.map(H=>U(H.coin_type,!1));e=this.buildCollectRewardPayload({reward_coin_types:I,lp_token_type:S,pool_id:n,clmm_pool_id:x,coin_type_a:A,coin_type_b:E},e),e=this.buildCollectFeePayload({lp_token_type:S,pool_id:n,clmm_pool_id:x,coin_type_a:A,coin_type_b:E},e);let Z=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress),R,W=d?k(d.burn_lp_amount).add(k(r)).toFixed(0):k(r).toFixed(0),Q=k(r).isZero();if(Q&&!d)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");Q?R=d.lp_burn_coin:(R=zt.buildCoinForAmount(e,Z,BigInt(r),S,!1,!0).target_coin,d&&e.mergeCoins(R,[d.lp_burn_coin]));let[J,Y,X]=e.moveCall({target:`${_}::pool::withdraw`,typeArguments:[A,E,S],arguments:[e.object(n),e.object(g.global_config_id),e.object(v.global_config_id),e.object(x),R,e.object(Zt)]});if(this.buildWithdrawBufferReward({reward_coin_types:I.filter(H=>![U(A,!1),U(E,!1)].includes(H)),pool_id:n,withdraw_cert:X,lp_token_type:S},e,Z),e.moveCall({target:`${_}::pool::destory_withdraw_cert`,typeArguments:[S],arguments:[e.object(n),e.object(g.global_config_id),X]}),a!=="FixedOneSide"){if(o===void 0)throw Error("the slippage is undefined");let H=a==="OnlyCoinA",s=H?Y:J,l=Pe(D,W,$.toString());await this.handleWithSwap(e,s,A,E,W,n,H,o,u,[{poolID:x,ticklower:P.wrapped_position.tick_lower_index,tickUpper:P.wrapped_position.tick_upper_index,deltaLiquidity:Number(l)}]),e.transferObjects([H?J:Y],this._sdk.senderAddress)}else e.transferObjects([J,Y],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}),v=u?r:n,S=u?n:r,P=u?g:_;if(k(P).isZero()){t.transferObjects([e],t.pure.address(this._sdk.getVerifySenderAddress()));return}let D={from:v,target:S,amount:new Ht.default(P),byAmountIn:!0,depth:3,splitAlgorithm:void 0,splitFactor:void 0,splitCount:void 0,providers:this._sdk.sdkOptions.providers,liquidityChanges:m},B=await this._sdk.AggregatorClient.findRouters(D);if(!B)throw Error("not find Router");if(B.error!==void 0)throw Error(`find Router error : ${B.error}`);let x={router:B,inputCoin:e,slippage:d,txb:t,partner:f},A=await this._sdk.AggregatorClient.fixableRouterSwapV3(x);t.transferObjects([A],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]}),_=zt.getCoinAssets(f,o),g=zt.selectCoinAssetGreaterThanOrEqual(_,BigInt(0));if(g.selected_coins.length>0&&!zt.isSuiCoin(f))a.mergeCoins(g.selected_coins[0].coin_object_id,[m]);else{let v=zt.buildCoinForAmount(a,o,BigInt(0),f,!1,!1);a.mergeCoins(v.target_coin,[m]),a.transferObjects([v.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:v}=u.clmm_vault.wrapped_position,S="0",P="0",D=await this.pythPrice.getLatestPrice([g,v],!0),B=D[g],x=D[v];if(!B||!x)throw new Error("get coin price failed");switch(a){case"FixedOneSide":{let{amountA:A,amountB:E}=Zi(m,_,new Ht.default(f),n,B.price,x.price,B.coin_decimals,x.coin_decimals);S=A.toString(),P=E.toString();break}case"FlexibleBoth":{let{amountA:A,amountB:E}=ue(k(.5),k(.5),n,B.price,x.price,B.coin_decimals,x.coin_decimals);S=A.toString(),P=E.toString();break}case"OnlyCoinA":{let{amountA:A,amountB:E}=ue(k(1),k(0),n,B.price,x.price,B.coin_decimals,x.coin_decimals);S=A.toString(),P=E.toString();break}case"OnlyCoinB":{let{amountA:A,amountB:E}=ue(k(0),k(1),n,B.price,x.price,B.coin_decimals,x.coin_decimals);S=A.toString(),P=E.toString();break}default:throw new Error(`Unsupported deposit mode: ${a}`)}return e&&this.calculateDepositLpAmountBoth(u,d,S,P).then(A=>{e.onSuccess(A,o)}).catch(A=>{e.onError(A,o)}),{deposit_amount_a:S,deposit_amount_b:P,mode:a}}async calculateBalanceSwapAmount(t){let{mode:e,pool_id:n}=t;if(e==="OnlyCoinA"||e==="OnlyCoinB"){let{pool:r,clmmPool:a}=await this.getVaultAndPool(n,!1),{clmm_vault:o}=r,{current_sqrt_price:u,coin_type_a:d,coin_type_b:f}=a,m=o.wrapped_position.tick_lower_index,_=o.wrapped_position.tick_upper_index,g=e==="OnlyCoinA"?t.coin_amount_a:t.coin_amount_b,v=e==="OnlyCoinA",S=re.estLiquidityAndCoinAmountFromOneAmounts(m,_,new Ht.default(g),v,!0,1,new Ht.default(u)),P=v?k(S.coin_amount_b).div(S.coin_amount_a):k(S.coin_amount_a).div(S.coin_amount_b),D=v?k(u).toString():k(1).div(k(u)).toString();try{let I=await this._sdk.VaultsV2.findRouters(v?d:f,v?f:d,g);I&&(D=k(I.swap_out_amount).div(I.swap_in_amount).toString())}catch{}let{swap_amount:B}=Ke(g,v,D.toString(),P.toString()),x=k(g).sub(B).toFixed(0),A=await this._sdk.VaultsV2.findRouters(v?d:f,v?f:d,B),E=k(A.swap_out_amount).mul(.999).toFixed(0),$=re.estLiquidityAndCoinAmountFromOneAmounts(m,_,new Ht.default(x),v,!0,1,new Ht.default(u));return v?$.coin_amount_b=E:$.coin_amount_a=E,{swap_result:A,liquidity_info:$}}throw new Error(`calculateBalanceSwapAmount Unsupported deposit mode: ${e}`)}async preCalculateDepositAmount(t,e){let{mode:n,pool_id:r,uuid:a}=t,o="0",u="0",d,f,{pool:m,clmmPool:_}=await this.getVaultAndPool(r,!1);switch(n){case"FixedOneSide":{let{fixed_amount:g,fixed_coin_a:v}=t,{other_amount:S,lp_amount:P}=await this.calculateDepositOtherSide(m,_,g,v,e,a);f=P,v?(o=g,u=S):(u=g,o=S);break}case"FlexibleBoth":{let{coin_amount_a:g,coin_amount_b:v}=t;o=g,u=v;break}case"OnlyCoinA":{if(t.re_balance){let g=await this.calculateBalanceSwapAmount(t),{swap_result:v,liquidity_info:S}=g,{coin_amount_a:P,coin_amount_b:D}=S;o=P,u=D,d={swap_result:v,coin_amount:t.coin_amount_a}}else o=t.coin_amount_a;break}case"OnlyCoinB":{if(t.re_balance){let g=await this.calculateBalanceSwapAmount(t),{swap_result:v,liquidity_info:S}=g,{coin_amount_a:P,coin_amount_b:D}=S;o=P,u=D,d={swap_result:v,coin_amount:t.coin_amount_b}}else u=t.coin_amount_b;break}default:throw new Error(`Unsupported deposit mode: ${n}`)}return e?this.calculateDepositLpAmountBoth(m,_,o,u).then(g=>{e?.onSuccess(g,a)}).catch(g=>{e?.onError(g,a)}):f=await this.calculateDepositLpAmountBoth(m,_,o,u),{deposit_amount_a:o,deposit_amount_b:u,mode:n,re_balance:d,lp_amount:f}}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}}async 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,_=re.estLiquidityAndCoinAmountFromOneAmounts(f,m,new Ht.default(n),r,!0,1,new Ht.default(d)),{coin_amount_a:g,coin_amount_b:v}=_;if(a)this.calculateDepositLpAmountBoth(t,e,g.toString(),v.toString()).then(S=>{a.onSuccess(S,o)}).catch(S=>{a.onError(S,o)});else{let S=await this.calculateDepositLpAmountBoth(t,e,g.toString(),v.toString());return{other_amount:r?v.toString():g.toString(),lp_amount:S}}return{other_amount:r?v.toString():g.toString(),lp_amount:void 0}}async calculateDepositLpAmountBoth(t,e,n,r){let{lp_token_treasury:a,hard_cap:o}=t,u=U(e.coin_type_a,!1),d=U(e.coin_type_b,!1),{rewarderList:f,feeList:m}=await this.getVaultsPositionRewarderAndFee(t.id),_=Ne(t.balances,m,f),g=await zi(this,t,e,_,!0),v=await this.pythPrice.getLatestPrice([u,d],!0),S=v[u],P=v[d];if(!S)throw Error(`not find ${u} price`);if(!P)throw Error(`not find ${d} price`);let D={};D[u]={price:S,value:n.toString()},D[d]={price:P,value:r.toString()};let B=Me(D,t.quote_type);return Re(a,B,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=rt.tickIndexToSqrtPriceX64(f),v=rt.tickIndexToSqrtPriceX64(m),S=Pe(a,n,_),{coin_amount_a:P,coin_amount_b:D}=re.getCoinAmountFromLiquidity(new Ht.default(S),new Ht.default(o),g,v,!1),B=ke(n,t.balances,a),x=k(P.toString()).add(B[u]?.value||"0").toFixed(0),A=k(D.toString()).add(B[d]?.value||"0").toFixed(0);return{receive_amount_a:x,receive_amount_b:A,burn_lp_amount:n,mode:"FixedOneSide",remove_liquidity:S}}async calculateWithdrawOnlyCoin(t,e,n,r){let{totalReceiveAmount:a,swapAmountIn:o,swapAmountOut:u,removeLiquidity:d,remove_amount_a:f,remove_amount_b:m}=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,remove_amount_a:f,remove_amount_b:m},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,v=rt.tickIndexToSqrtPriceX64(m),S=rt.tickIndexToSqrtPriceX64(_),P=Pe(o,r,g),{coin_amount_a:D,coin_amount_b:B}=re.getCoinAmountFromLiquidity(new Ht.default(P),new Ht.default(u),v,S,!1),x=await this.pythPrice.getLatestPrice([d,f],!0),A=x[d],E=x[f];if(!A)throw Error(`not find ${d} price`);if(!E)throw Error(`not find ${f} price`);let $=n?E:A,I=n?A:E,{quote_per_base:Z}=qe($.price,I.price),R=ke(r,t.balances,o),W=k(D.toString()).add(R[d]?.value||"0").toFixed(0),Q=k(B.toString()).add(R[f]?.value||"0").toFixed(0),J=n?W:Q,Y=n?Q:W,X=ce(k(be(Y,n?E.coin_decimals:A.coin_decimals)).mul(Z).toString(),n?A.coin_decimals:E.coin_decimals).toString(),H=k(J).add(X).toFixed(0);return{remove_amount_a:W,remove_amount_b:Q,burn_lp_amount:r,removeLiquidity:P,is_coin_a:n,originAmount:J,swapAmountIn:Y,swapAmountOut:k(X).toFixed(0,hr.default.ROUND_DOWN),totalReceiveAmount:H}}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=ai(n);(await this._sdk.FullClient.queryEventsByPage({Transaction:r})).data.forEach(m=>{let _=m.parsedJson;if(m.type)switch((0,dr.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=ne(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=ne(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 mr=require("@mysten/sui/transactions");var Ze=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!ne(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:U(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=ui(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=ui(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 mr.Transaction;for(let d of t){let{vault_id:f,vesting_nft_id:m,period:_,coin_type_a:g,coin_type_b:v}=d,S=await this.getVaultVestEvent(f);e.moveCall({package:n.published_at,module:"hae_vester",function:"redeem_coin",arguments:[e.object(a),e.object(S.vault_vester_id),e.object(m),e.object(o),e.object(u),e.object(S.pool_id),e.pure.u16(_),e.object(Zt)],typeArguments:[g,v]})}return e}};var hn=require("@mysten/sui/transactions"),mn=oe(require("bn.js")),pr=require("@cetusprotocol/aggregator-sdk");var _r=require("@mysten/sui/utils"),gr=oe(require("decimal.js"));var Qt=require("@cetusprotocol/dlmm-sdk");var ze=class{_sdk;pythPrice;constructor(t){this._sdk=t;let{vaultsV2:e,pythConfigs:n}=t.sdkOptions;this.pythPrice=new Ae(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 hi(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,v=new hn.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...f.rewards.map(B=>B.reward_coin)],lp_token_type:d,pool_id:t,certified_pool_id:m,position_id:e,coin_type_a:_,coin_type_b:g},v),n&&this.buildCollectFeePayload({lp_token_type:d,pool_id:t,certified_pool_id:m,position_id:e,coin_type_a:_,coin_type_b:g},v);let S=await this._sdk.FullClient.sendSimulationTransaction(v,(0,_r.normalizeSuiAddress)("0x0")),P=[],D=[];return S?.events.forEach(B=>{let{parsedJson:x,type:A}=B;A.includes("CollectDlmmFeeEvent")&&(P.push({coin_type:U(_,!1),value:x.amount_a}),P.push({coin_type:U(g,!1),value:x.amount_b})),A.includes("CollectDlmmRewardEvent")&&D.push({coin_type:U(x.reward_type.name,!1),value:x.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:v}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:S,global_config_id:P}=ve(v);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(S),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(S),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:v,global_config_id:S}=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(S),e.object(v),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(S),e.object(v),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,re_balance:f}=t,{pool:m,dlmmPool:_}=await this.getVaultAndPool(a,!1),{coin_type_a:g,coin_type_b:v,markets:S,lp_token_type:P}=m,{reward_manager:D,id:B}=_,x=S[0].position_list[0].position.id,A=D.rewards.map(Q=>U(Q.reward_coin,!1)),E=Ue(A,g,v);this.buildCollectRewardPayload({reward_coin_types:A,lp_token_type:P,pool_id:a,certified_pool_id:S[0].position_list[0].position.pool_id,position_id:x,coin_type_a:g,coin_type_b:v},e),await this.pythPrice.buildUpdatePythPricePayload(E,e);let{dlmm_pool:$}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:I}=ve($);e.moveCall({target:`${n}::vault::calculate_dlmm_position_amounts`,typeArguments:[g,v,P],arguments:[e.object(a),e.object(r.pyth_oracle_id),e.object(B),e.object(x),e.object(I),e.object(r.versioned_id),e.object(Zt)]}),e.moveCall({target:`${n}::vault::calculate_aum`,typeArguments:[P],arguments:[e.object(a),e.object(r.pyth_oracle_id),e.object(r.versioned_id),e.object(Zt)]});let Z,R;if(f&&f.swap_result){let{swap_result:Q,coin_amount:J,mode:Y,swap_slippage:X}=f,{swap_in_amount:H,swap_out_amount:s,route_obj:l}=Q,h=zt.buildCoinWithBalance(BigInt(J),Y==="OnlyCoinA"?g:v,e),p=e.splitCoins(h,[H]),b={router:l,slippage:X,txb:e,inputCoin:p},M=await this._sdk.AggregatorClient.fixableRouterSwapV3(b);Z=Y==="OnlyCoinA"?h:M,R=Y==="OnlyCoinA"?M:h}else Z=zt.buildCoinWithBalance(BigInt(o),g,e),R=zt.buildCoinWithBalance(BigInt(u),v,e);let W=e.moveCall({target:`${n}::vault::deposit`,typeArguments:[g,v,P],arguments:[e.object(a),e.object(r.global_config_id),e.object(r.pyth_oracle_id),Z,R,e.object(Zt),e.object(r.versioned_id)]});if(d)return W;e.transferObjects([W],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:v,markets:S}=f,{id:P,reward_manager:D}=m,B=S[0].position_list[0].position.id;e=e||new hn.Transaction;let x,A=d?k(d.burn_lp_amount).add(k(r)).toFixed(0):k(r).toFixed(0),E=k(r).isZero();if(E&&!d)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");E?x=d.lp_burn_coin:(x=zt.buildCoinWithBalance(BigInt(r),_,e),d&&d.lp_burn_coin&&e.mergeCoins(x,[d.lp_burn_coin]));let{published_at:$,configs:I}=this._sdk.sdkOptions.vaultsV2,{config:Z}=this._sdk.CetusDlmmSDK.sdkOptions.dlmm_pool,R=e.moveCall({target:`${$}::vault::new_withdraw_cert`,typeArguments:[_],arguments:[e.object(n),x,e.object(I.versioned_id)]});e.moveCall({target:`${$}::vault::withdraw_dlmm`,typeArguments:[g,v,_],arguments:[e.object(n),R,e.object(P),e.object(B),e.object(Z.global_config_id),e.object(Z.versioned_id),e.object(I.versioned_id),e.object(Zt)]});let W=D.rewards.map(H=>U(H.reward_coin,!1));this.buildCollectRewardPayload({reward_coin_types:W,lp_token_type:_,pool_id:n,certified_pool_id:S[0].position_list[0].position.pool_id,position_id:B,coin_type_a:g,coin_type_b:v,withdraw_cert:R},e),this.buildCollectFeePayload({lp_token_type:_,pool_id:n,certified_pool_id:S[0].position_list[0].position.pool_id,position_id:B,coin_type_a:g,coin_type_b:v,withdraw_cert:R},e),e.moveCall({target:`${$}::vault::finalize_buffer_assets`,typeArguments:[_],arguments:[e.object(n),R,e.object(I.versioned_id)]});let Q=new Set;W.forEach(H=>Q.add(H)),Q.add(g),Q.add(v);let J=Array.from(Q),Y=a!=="FixedOneSide"?[a==="OnlyCoinA"?v:g]:[],X=this.buildWithdrawBufferReward({reward_coin_types:J,pool_id:n,withdraw_cert:R,lp_token_type:_,not_transfer_coin_types:Y},e);if(e.moveCall({target:`${$}::vault::destroy_withdraw_cert`,typeArguments:[_],arguments:[e.object(n),R,e.object(I.versioned_id)]}),a!=="FixedOneSide"){if(o===void 0)throw Error("the slippage is undefined");let H=a==="OnlyCoinA",s=H?v:g,l=X.find(h=>h.coin_type===s).reward_coin_object_id;await this.handleWithSwap(e,l,g,v,A,n,H,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,v=u?n:r,S=u?_:m;if(k(S).isZero()){t.transferObjects([e],t.pure.address(this._sdk.getVerifySenderAddress()));return}let P={from:g,target:v,amount:new mn.default(S),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 B={router:D,inputCoin:e,slippage:d,txb:t,partner:f},x=await this._sdk.AggregatorClient.fixableRouterSwapV3(B);t.transferObjects([x],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,re_balance:u}=t,{pool:d,dlmmPool:f}=await this.getVaultAndPool(r,!1),{coin_type_a:m,coin_type_b:_}=d,g=await this.pythPrice.getLatestPrice([m,_],!0),v=g[m],S=g[_];if(!v)throw new Error(`get ${m} price failed`);if(!S)throw new Error(`get ${_} price failed`);let P="0",D="0";switch(a){case"FlexibleBoth":{let{position_amount_a_rate:x,position_amount_b_rate:A}=await this.calculatePositionValueRates(d,f,g),{amountA:E,amountB:$}=ue(x,A,n,v.price,S.price,v.coin_decimals,S.coin_decimals);P=E,D=$;break}case"OnlyCoinA":{let{amountA:x,amountB:A}=ue(k(1),k(0),n,v.price,S.price,v.coin_decimals,S.coin_decimals);P=x,D=A;break}case"OnlyCoinB":{let{amountA:x,amountB:A}=ue(k(0),k(1),n,v.price,S.price,v.coin_decimals,S.coin_decimals);P=x,D=A;break}}return await this.preCalculateDepositAmount({mode:a,pool_id:r,uuid:o,coin_amount_a:P,coin_amount_b:D,re_balance:u},e)}async calculateBalanceSwapAmount(t){let{mode:e,pool_id:n}=t;if(e==="OnlyCoinA"||e==="OnlyCoinB"){let{pool:r,dlmmPool:a}=await this.getVaultAndPool(n,!1),o=await this._sdk.CetusDlmmSDK.Pool.getBinInfo(a.bin_manager.bin_manager_handle,a.active_id,a.bin_step,!1),{active_id:u,bin_step:d}=a,f=Qt.BinUtils.getPricePerLamportFromBinId(a.active_id,a.bin_step),m=k(f).mul(1-.05),_=k(f).mul(1+.05),g=Qt.BinUtils.getBinIdFromLamportPrice(m.toString(),a.bin_step,!1),v=Qt.BinUtils.getBinIdFromLamportPrice(_.toString(),a.bin_step,!1),S=e==="OnlyCoinA"?t.coin_amount_a:t.coin_amount_b,P=e==="OnlyCoinA",D=await this._sdk.CetusDlmmSDK.Position.calculateAddLiquidityInfo({pool_id:a.id,coin_amount:S,fix_amount_a:P,active_id:u,bin_step:d,lower_bin_id:g,upper_bin_id:v,active_bin_of_pool:o,strategy_type:Qt.StrategyType.Spot}),B=P?k(D.amount_b).div(D.amount_a):k(D.amount_a).div(D.amount_b),x=P?Qt.BinUtils.getPricePerLamportFromBinId(u,d):k(1).div(Qt.BinUtils.getPricePerLamportFromBinId(u,d)).toString();try{let Y=await this.findRouters(P?r.coin_type_a:r.coin_type_b,P?r.coin_type_b:r.coin_type_a,S);Y&&(x=k(Y.swap_out_amount).div(Y.swap_in_amount).toString())}catch{}let{swap_amount:A,final_amount_a:E,final_amount_b:$}=Ke(S,P,x,B.toString()),I=k(S).sub(A).toFixed(0),Z=await this.findRouters(P?r.coin_type_a:r.coin_type_b,P?r.coin_type_b:r.coin_type_a,A),R=k(Z.swap_out_amount).mul(.999).toFixed(0),W=P?I:R,Q=P?R:I,J=await this._sdk.CetusDlmmSDK.Position.calculateAddLiquidityInfo({pool_id:a.id,amount_a:W,amount_b:Q,active_id:u,bin_step:d,lower_bin_id:g,upper_bin_id:v,active_bin_of_pool:o,strategy_type:Qt.StrategyType.Spot});return P?J.amount_b=Z.swap_out_amount:J.amount_a=Z.swap_out_amount,{swap_result:Z,liquidity_info:J}}throw new Error(`calculateBalanceSwapAmount Unsupported deposit mode: ${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,re_balance:f}=t;if(f){let m=await this.calculateBalanceSwapAmount(t),{swap_result:_,liquidity_info:g}=m,{amount_a:v,amount_b:S}=g,P=await this.calculateDepositFlexibleBoth(o,u,v,S,e,a);return P.re_balance={swap_result:_,coin_amount:d,mode:"OnlyCoinA"},P}else return await this.calculateDepositFlexibleBoth(o,u,d,"0",e,a)}case"OnlyCoinB":{let{coin_amount_b:d,re_balance:f}=t;if(f){let m=await this.calculateBalanceSwapAmount(t),{swap_result:_,liquidity_info:g}=m,{amount_a:v,amount_b:S}=g,P=await this.calculateDepositFlexibleBoth(o,u,v,S,e,a);return P.re_balance={swap_result:_,coin_amount:d,mode:"OnlyCoinB"},P}else 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(k(r).eq(0))return{position_amount_a_rate:k(.5),position_amount_b_rate:k(.5)};let{position_amount_a:u,position_amount_b:d}=await hi(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 _=k(be(u,f.coin_decimals)).mul(f.price),g=k(be(d,m.coin_decimals)).mul(m.price),v=k(_).add(g),S=k(_).div(v),P=k(1).sub(S);return{position_amount_a_rate:S,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=Qt.BinUtils.getPricePerLamportFromBinId(e.active_id,e.bin_step),f=k(d).mul(1-.05),m=k(d).mul(1+.05),_=Qt.BinUtils.getBinIdFromLamportPrice(f.toString(),e.bin_step,!1),g=Qt.BinUtils.getBinIdFromLamportPrice(m.toString(),e.bin_step,!1),v={pool_id:o.pool_id,coin_amount:k(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:Qt.StrategyType.Spot,active_bin_of_pool:u},S=await this._sdk.CetusDlmmSDK.Position.calculateAddLiquidityInfo(v),{amount_a:P,amount_b:D}=S;return{deposit_amount_a:k(P).div(1e5).toFixed(0),deposit_amount_b:k(D).div(1e5).toFixed(0)}}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=U(u,!1),m=U(d,!1),{rewarderList:_,feeList:g}=await this.getVaultsPositionRewarderAndFee(t.id,a[0].position_list[0].position.id),v=Ne(t.buffer_assets,g,_),S=await nn(this._sdk,t,v,!0),P=await this.pythPrice.getLatestPrice([f,m],!0),D=P[f],B=P[m];if(!D)throw Error(`not find ${f} price`);if(!B)throw Error(`not find ${m} price`);let x={};x[f]={price:D,value:e.toString()},x[m]={price:B,value:n.toString()};let A=Me(x,o);return Re(r,A,S)}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 $e(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,remove_amount_a:d,remove_amount_b:f}=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,remove_amount_a:d,remove_amount_b:f},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 $e(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,v=n?m:_,{quote_per_base:S}=qe(g.price,v.price),P=n?u:d,D=n?d:u,B=ce(k(be(D,n?_.coin_decimals:m.coin_decimals)).mul(S).toString(),n?m.coin_decimals:_.coin_decimals).toString(),x=k(P).add(B).toFixed(0);return{remove_amount_a:u,remove_amount_b:d,burn_lp_amount:r,is_coin_a:n,originAmount:P,swapAmountIn:D,swapAmountOut:k(B).toFixed(0,gr.default.ROUND_DOWN),totalReceiveAmount:x}}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=ai(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=ne(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=ne(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}async findRouters(t,e,n){let{providers:r}=this._sdk.sdkOptions,a=this._sdk.AggregatorClient;if(k(n).lt(1))throw new Error("Swap amount is less than the minimum precision");try{let o={from:t,target:e,amount:new mn.default(n),byAmountIn:!0,depth:3,providers:r},u=await a.findRouters(o);if(u?.error)throw new Error(`Aggregator findRouters error: ${u?.error}`);if(!u?.paths||u?.paths?.length===0)throw new Error("Aggregator findRouters error: no router");let d=u.amountIn.toString(),f=u.amountOut.toString();return{swap_in_amount:d,swap_out_amount:f,route_obj:u}}catch(o){throw new Error(`Aggregator findRouters error: ${o}`)}}};var wr=oe(require("@cetusprotocol/dlmm-sdk")),he=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"?pn.CetusClmmSDK.createSDK({env:"testnet",full_rpc_url:t.fullRpcUrl}):pn.CetusClmmSDK.createSDK({env:"mainnet",full_rpc_url:t.fullRpcUrl}),this._cetusDlmmSDK=wr.default.createSDK({env:t.env,full_rpc_url:t.fullRpcUrl}),this._vaults=new We(this),this._vaultsV2=new ze(this);let{primary:e,secondary:n}=t.pythConfigs.hermes_service_urls,r=[e,n].filter(Boolean);this._aggregatorClient=new Xe.AggregatorClient({endpoint:t.aggregatorUrl,signer:(0,mi.normalizeSuiAddress)("0x0"),client:new br.SuiClient({url:t.fullRpcUrl}),env:t.env==="testnet"?Xe.Env.Testnet:Xe.Env.Mainnet,pythUrls:r}),this._vest=new Ze(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=Kn){this.CetusClmmSDK.updateCache(t,e,n)}getCache(t,e=!1){return this.CetusClmmSDK.getCache(t,e)}};var fs=he;0&&(module.exports={PythPriceModule,SdkEnv,VaultsModule,VaultsModuleV2,VestModule,VolatileVaultsSDK,buildDLMMMarket,buildDLMMMarketId,buildDLMMMarketPosition,buildDLMMPositionId,buildPoolData,buildPoolV2Data,buildVaultsBalance,buildVaultsBalanceV2,calcExactSwapAmount,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 yr=Object.create;var Ge=Object.defineProperty;var vr=Object.getOwnPropertyDescriptor;var Mr=Object.getOwnPropertyNames;var Cr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var Pr=(i,t)=>{for(var e in t)Ge(i,e,{get:t[e],enumerable:!0})},Vn=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Mr(t))!Sr.call(i,r)&&r!==e&&Ge(i,r,{get:()=>t[r],enumerable:!(n=vr(t,r))||n.enumerable});return i};var oe=(i,t,e)=>(e=i!=null?yr(Cr(i)):{},Vn(t||!i||!i.__esModule?Ge(e,"default",{value:i,enumerable:!0}):e,i)),kr=i=>Vn(Ge({},"__esModule",{value:!0}),i);var hs={};Pr(hs,{PythPriceModule:()=>Ae,SdkEnv:()=>lr,VaultsModule:()=>We,VaultsModuleV2:()=>ze,VestModule:()=>Ze,VolatileVaultsSDK:()=>he,buildDLMMMarket:()=>Yi,buildDLMMMarketId:()=>rn,buildDLMMMarketPosition:()=>tn,buildDLMMPositionId:()=>ls,buildPoolData:()=>je,buildPoolV2Data:()=>en,buildVaultsBalance:()=>Xi,buildVaultsBalanceV2:()=>hi,calcExactSwapAmount:()=>Ke,calculateAum:()=>zi,calculateAumV2:()=>nn,calculateDepositRatioFixTokenA:()=>sr,calculateTotalAumBasedOnQuote:()=>Me,checkIsMinOrMaxIndex:()=>ci,convertU64BytesToDecimal:()=>rs,default:()=>fs,defaultProvider:()=>dn,estCoinAmountsFromTotalAmount:()=>Zi,feed_map_mainnet:()=>sn,feed_map_testnet:()=>ln,getAmountBalanceByLpAmount:()=>$e,getCoinAmountsFromRatio:()=>ue,getPositionPriceRange:()=>as,getPriceWithFormattedDecimals:()=>Gi,getPrimitivePricesFromBaseQuote:()=>ar,getQuotePerBaseAndBasePerQuote:()=>qe,getShareBufferAssets:()=>ke,getUpdatePriceType:()=>Ue,getVaultValidBalances:()=>Ne,get_lp_amount_by_liquidity:()=>ss,get_lp_amount_by_tvl:()=>Re,get_share_liquidity_by_amount:()=>Pe,initMainnetSDK:()=>an,initTestnetSDK:()=>un,initVaultSDK:()=>us,oraclePriceMultiplierDecimal:()=>Se,parseVaultVestNFT:()=>Qi,parseVaultsVestInfo:()=>ui,printTransaction:()=>os,toSuiObjectId:()=>Hi,vaults_mainnet:()=>on,vaults_testnet:()=>cn});module.exports=kr(hs);var br=require("@mysten/sui/client"),mi=require("@mysten/sui/utils"),Xe=require("@cetusprotocol/aggregator-sdk");var Fr=require("@mysten/sui/utils"),jr=require("@mysten/sui/client"),qr=require("@mysten/sui/utils"),Rr=require("@mysten/sui/keypairs/ed25519"),Nr=require("@mysten/sui/keypairs/secp256k1"),Ce=require("@mysten/sui/utils"),Fi=require("@mysten/sui/transactions"),jo=require("@mysten/sui/bcs"),qo=require("@mysten/sui/utils"),Ro=require("@mysten/sui/graphql/schemas/latest"),No=require("@mysten/sui/graphql"),Ni=require("@mysten/sui/client"),Ar=Object.create,Un=Object.defineProperty,Or=Object.getOwnPropertyDescriptor,xr=Object.getOwnPropertyNames,Dr=Object.getPrototypeOf,Br=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')}),Vr=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Tr=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of xr(t))!Br.call(i,r)&&r!==e&&Un(i,r,{get:()=>t[r],enumerable:!(n=Or(t,r))||n.enumerable});return i},Fe=(i,t,e)=>(e=i!=null?Ar(Dr(i)):{},Tr(t||!i||!i.__esModule?Un(e,"default",{value:i,enumerable:!0}):e,i)),Ie=Vr((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 b,M,C=0;if(h==="be")for(p=s.length-1,b=0;p>=0;p-=3)M=s[p]|s[p-1]<<8|s[p-2]<<16,this.words[b]|=M<<C&67108863,this.words[b+1]=M>>>26-C&67108863,C+=24,C>=26&&(C-=26,b++);else if(h==="le")for(p=0,b=0;p<s.length;p+=3)M=s[p]|s[p+1]<<8|s[p+2]<<16,this.words[b]|=M<<C&67108863,this.words[b+1]=M>>>26-C&67108863,C+=24,C>=26&&(C-=26,b++);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 b=0,M=0,C;if(h==="be")for(p=s.length-1;p>=l;p-=2)C=f(s,l,p)<<b,this.words[M]|=C&67108863,b>=18?(b-=18,M+=1,this.words[M]|=C>>>26):b+=8;else{var w=s.length-l;for(p=w%2===0?l+1:l;p<s.length;p+=2)C=f(s,l,p)<<b,this.words[M]|=C&67108863,b>=18?(b-=18,M+=1,this.words[M]|=C>>>26):b+=8}this._strip()};function m(s,l,h,p){for(var b=0,M=0,C=Math.min(s.length,h),w=l;w<C;w++){var c=s.charCodeAt(w)-48;b*=p,c>=49?M=c-49+10:c>=17?M=c-17+10:M=c,r(c>=0&&M<p,"Invalid character"),b+=M}return b}o.prototype._parseBase=function(s,l,h){this.words=[0],this.length=1;for(var p=0,b=1;b<=67108863;b*=l)p++;p--,b=b/l|0;for(var M=s.length-h,C=M%p,w=Math.min(M,M-C)+h,c=0,y=h;y<w;y+=p)c=m(s,y,y+p,l),this.imuln(b),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(C!==0){var V=1;for(c=m(s,y,s.length,l),y=0;y<C;y++)V*=l;this.imuln(V),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 v=["","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"],S=[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,b=0,M=0;M<this.length;M++){var C=this.words[M],w=((C<<p|b)&16777215).toString(16);b=C>>>24-p&16777215,p+=2,p>=26&&(p-=26,M--),b!==0||M!==this.length-1?h=v[6-w.length]+w+h:h=w+h}for(b!==0&&(h=b.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=S[s],y=P[s];h="";var V=this.clone();for(V.negative=0;!V.isZero();){var T=V.modrn(y).toString(s);V=V.idivn(y),V.isZero()?h=T+h:h=v[c-T.length]+T+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(),b=h||Math.max(1,p);r(p<=b,"byte array longer than desired length"),r(b>0,"Requested array length <= 0");var M=D(s,b),C=l==="le"?"LE":"BE";return this["_toArrayLike"+C](M,p),M},o.prototype._toArrayLikeLE=function(s,l){for(var h=0,p=0,b=0,M=0;b<this.length;b++){var C=this.words[b]<<M|p;s[h++]=C&255,h<s.length&&(s[h++]=C>>8&255),h<s.length&&(s[h++]=C>>16&255),M===6?(h<s.length&&(s[h++]=C>>24&255),p=0,M=0):(p=C>>>24,M+=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,b=0,M=0;b<this.length;b++){var C=this.words[b]<<M|p;s[h--]=C&255,h>=0&&(s[h--]=C>>8&255),h>=0&&(s[h--]=C>>16&255),M===6?(h>=0&&(s[h--]=C>>24&255),p=0,M=0):(p=C>>>24,M+=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 B(s){for(var l=new Array(s.bitLength()),h=0;h<l.length;h++){var p=h/26|0,b=h%26;l[h]=s.words[p]>>>b&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 b=0,M=0;M<p.length;M++)l=(h.words[M]|0)+(p.words[M]|0)+b,this.words[M]=l&67108863,b=l>>>26;for(;b!==0&&M<h.length;M++)l=(h.words[M]|0)+b,this.words[M]=l&67108863,b=l>>>26;if(this.length=h.length,b!==0)this.words[this.length]=b,this.length++;else if(h!==this)for(;M<h.length;M++)this.words[M]=h.words[M];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,b;h>0?(p=this,b=s):(p=s,b=this);for(var M=0,C=0;C<b.length;C++)l=(p.words[C]|0)-(b.words[C]|0)+M,M=l>>26,this.words[C]=l&67108863;for(;M!==0&&C<p.length;C++)l=(p.words[C]|0)+M,M=l>>26,this.words[C]=l&67108863;if(M===0&&C<p.length&&p!==this)for(;C<p.length;C++)this.words[C]=p.words[C];return this.length=Math.max(this.length,C),p!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(s){return this.clone().isub(s)};function x(s,l,h){h.negative=l.negative^s.negative;var p=s.length+l.length|0;h.length=p,p=p-1|0;var b=s.words[0]|0,M=l.words[0]|0,C=b*M,w=C&67108863,c=C/67108864|0;h.words[0]=w;for(var y=1;y<p;y++){for(var V=c>>>26,T=c&67108863,L=Math.min(y,l.length-1),K=Math.max(0,y-s.length+1);K<=L;K++){var G=y-K|0;b=s.words[G]|0,M=l.words[K]|0,C=b*M+T,V+=C/67108864|0,T=C&67108863}h.words[y]=T|0,c=V|0}return c!==0?h.words[y]=c|0:h.length--,h._strip()}var A=function(s,l,h){var p=s.words,b=l.words,M=h.words,C=0,w,c,y,V=p[0]|0,T=V&8191,L=V>>>13,K=p[1]|0,G=K&8191,et=K>>>13,me=p[2]|0,it=me&8191,nt=me>>>13,_n=p[3]|0,ot=_n&8191,st=_n>>>13,gn=p[4]|0,at=gn&8191,ct=gn>>>13,bn=p[5]|0,lt=bn&8191,ut=bn>>>13,wn=p[6]|0,dt=wn&8191,ft=wn>>>13,yn=p[7]|0,ht=yn&8191,mt=yn>>>13,vn=p[8]|0,pt=vn&8191,_t=vn>>>13,Mn=p[9]|0,gt=Mn&8191,bt=Mn>>>13,Cn=b[0]|0,wt=Cn&8191,yt=Cn>>>13,Sn=b[1]|0,vt=Sn&8191,Mt=Sn>>>13,Pn=b[2]|0,Ct=Pn&8191,St=Pn>>>13,kn=b[3]|0,Pt=kn&8191,kt=kn>>>13,An=b[4]|0,At=An&8191,Ot=An>>>13,On=b[5]|0,xt=On&8191,Dt=On>>>13,xn=b[6]|0,Bt=xn&8191,Et=xn>>>13,Dn=b[7]|0,Vt=Dn&8191,Tt=Dn>>>13,Bn=b[8]|0,Ft=Bn&8191,It=Bn>>>13,En=b[9]|0,Lt=En&8191,jt=En>>>13;h.negative=s.negative^l.negative,h.length=19,w=Math.imul(T,wt),c=Math.imul(T,yt),c=c+Math.imul(L,wt)|0,y=Math.imul(L,yt);var pi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(pi>>>26)|0,pi&=67108863,w=Math.imul(G,wt),c=Math.imul(G,yt),c=c+Math.imul(et,wt)|0,y=Math.imul(et,yt),w=w+Math.imul(T,vt)|0,c=c+Math.imul(T,Mt)|0,c=c+Math.imul(L,vt)|0,y=y+Math.imul(L,Mt)|0;var _i=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(_i>>>26)|0,_i&=67108863,w=Math.imul(it,wt),c=Math.imul(it,yt),c=c+Math.imul(nt,wt)|0,y=Math.imul(nt,yt),w=w+Math.imul(G,vt)|0,c=c+Math.imul(G,Mt)|0,c=c+Math.imul(et,vt)|0,y=y+Math.imul(et,Mt)|0,w=w+Math.imul(T,Ct)|0,c=c+Math.imul(T,St)|0,c=c+Math.imul(L,Ct)|0,y=y+Math.imul(L,St)|0;var gi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,w=Math.imul(ot,wt),c=Math.imul(ot,yt),c=c+Math.imul(st,wt)|0,y=Math.imul(st,yt),w=w+Math.imul(it,vt)|0,c=c+Math.imul(it,Mt)|0,c=c+Math.imul(nt,vt)|0,y=y+Math.imul(nt,Mt)|0,w=w+Math.imul(G,Ct)|0,c=c+Math.imul(G,St)|0,c=c+Math.imul(et,Ct)|0,y=y+Math.imul(et,St)|0,w=w+Math.imul(T,Pt)|0,c=c+Math.imul(T,kt)|0,c=c+Math.imul(L,Pt)|0,y=y+Math.imul(L,kt)|0;var bi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,w=Math.imul(at,wt),c=Math.imul(at,yt),c=c+Math.imul(ct,wt)|0,y=Math.imul(ct,yt),w=w+Math.imul(ot,vt)|0,c=c+Math.imul(ot,Mt)|0,c=c+Math.imul(st,vt)|0,y=y+Math.imul(st,Mt)|0,w=w+Math.imul(it,Ct)|0,c=c+Math.imul(it,St)|0,c=c+Math.imul(nt,Ct)|0,y=y+Math.imul(nt,St)|0,w=w+Math.imul(G,Pt)|0,c=c+Math.imul(G,kt)|0,c=c+Math.imul(et,Pt)|0,y=y+Math.imul(et,kt)|0,w=w+Math.imul(T,At)|0,c=c+Math.imul(T,Ot)|0,c=c+Math.imul(L,At)|0,y=y+Math.imul(L,Ot)|0;var wi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,w=Math.imul(lt,wt),c=Math.imul(lt,yt),c=c+Math.imul(ut,wt)|0,y=Math.imul(ut,yt),w=w+Math.imul(at,vt)|0,c=c+Math.imul(at,Mt)|0,c=c+Math.imul(ct,vt)|0,y=y+Math.imul(ct,Mt)|0,w=w+Math.imul(ot,Ct)|0,c=c+Math.imul(ot,St)|0,c=c+Math.imul(st,Ct)|0,y=y+Math.imul(st,St)|0,w=w+Math.imul(it,Pt)|0,c=c+Math.imul(it,kt)|0,c=c+Math.imul(nt,Pt)|0,y=y+Math.imul(nt,kt)|0,w=w+Math.imul(G,At)|0,c=c+Math.imul(G,Ot)|0,c=c+Math.imul(et,At)|0,y=y+Math.imul(et,Ot)|0,w=w+Math.imul(T,xt)|0,c=c+Math.imul(T,Dt)|0,c=c+Math.imul(L,xt)|0,y=y+Math.imul(L,Dt)|0;var yi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,w=Math.imul(dt,wt),c=Math.imul(dt,yt),c=c+Math.imul(ft,wt)|0,y=Math.imul(ft,yt),w=w+Math.imul(lt,vt)|0,c=c+Math.imul(lt,Mt)|0,c=c+Math.imul(ut,vt)|0,y=y+Math.imul(ut,Mt)|0,w=w+Math.imul(at,Ct)|0,c=c+Math.imul(at,St)|0,c=c+Math.imul(ct,Ct)|0,y=y+Math.imul(ct,St)|0,w=w+Math.imul(ot,Pt)|0,c=c+Math.imul(ot,kt)|0,c=c+Math.imul(st,Pt)|0,y=y+Math.imul(st,kt)|0,w=w+Math.imul(it,At)|0,c=c+Math.imul(it,Ot)|0,c=c+Math.imul(nt,At)|0,y=y+Math.imul(nt,Ot)|0,w=w+Math.imul(G,xt)|0,c=c+Math.imul(G,Dt)|0,c=c+Math.imul(et,xt)|0,y=y+Math.imul(et,Dt)|0,w=w+Math.imul(T,Bt)|0,c=c+Math.imul(T,Et)|0,c=c+Math.imul(L,Bt)|0,y=y+Math.imul(L,Et)|0;var vi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,w=Math.imul(ht,wt),c=Math.imul(ht,yt),c=c+Math.imul(mt,wt)|0,y=Math.imul(mt,yt),w=w+Math.imul(dt,vt)|0,c=c+Math.imul(dt,Mt)|0,c=c+Math.imul(ft,vt)|0,y=y+Math.imul(ft,Mt)|0,w=w+Math.imul(lt,Ct)|0,c=c+Math.imul(lt,St)|0,c=c+Math.imul(ut,Ct)|0,y=y+Math.imul(ut,St)|0,w=w+Math.imul(at,Pt)|0,c=c+Math.imul(at,kt)|0,c=c+Math.imul(ct,Pt)|0,y=y+Math.imul(ct,kt)|0,w=w+Math.imul(ot,At)|0,c=c+Math.imul(ot,Ot)|0,c=c+Math.imul(st,At)|0,y=y+Math.imul(st,Ot)|0,w=w+Math.imul(it,xt)|0,c=c+Math.imul(it,Dt)|0,c=c+Math.imul(nt,xt)|0,y=y+Math.imul(nt,Dt)|0,w=w+Math.imul(G,Bt)|0,c=c+Math.imul(G,Et)|0,c=c+Math.imul(et,Bt)|0,y=y+Math.imul(et,Et)|0,w=w+Math.imul(T,Vt)|0,c=c+Math.imul(T,Tt)|0,c=c+Math.imul(L,Vt)|0,y=y+Math.imul(L,Tt)|0;var Mi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,w=Math.imul(pt,wt),c=Math.imul(pt,yt),c=c+Math.imul(_t,wt)|0,y=Math.imul(_t,yt),w=w+Math.imul(ht,vt)|0,c=c+Math.imul(ht,Mt)|0,c=c+Math.imul(mt,vt)|0,y=y+Math.imul(mt,Mt)|0,w=w+Math.imul(dt,Ct)|0,c=c+Math.imul(dt,St)|0,c=c+Math.imul(ft,Ct)|0,y=y+Math.imul(ft,St)|0,w=w+Math.imul(lt,Pt)|0,c=c+Math.imul(lt,kt)|0,c=c+Math.imul(ut,Pt)|0,y=y+Math.imul(ut,kt)|0,w=w+Math.imul(at,At)|0,c=c+Math.imul(at,Ot)|0,c=c+Math.imul(ct,At)|0,y=y+Math.imul(ct,Ot)|0,w=w+Math.imul(ot,xt)|0,c=c+Math.imul(ot,Dt)|0,c=c+Math.imul(st,xt)|0,y=y+Math.imul(st,Dt)|0,w=w+Math.imul(it,Bt)|0,c=c+Math.imul(it,Et)|0,c=c+Math.imul(nt,Bt)|0,y=y+Math.imul(nt,Et)|0,w=w+Math.imul(G,Vt)|0,c=c+Math.imul(G,Tt)|0,c=c+Math.imul(et,Vt)|0,y=y+Math.imul(et,Tt)|0,w=w+Math.imul(T,Ft)|0,c=c+Math.imul(T,It)|0,c=c+Math.imul(L,Ft)|0,y=y+Math.imul(L,It)|0;var Ci=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,w=Math.imul(gt,wt),c=Math.imul(gt,yt),c=c+Math.imul(bt,wt)|0,y=Math.imul(bt,yt),w=w+Math.imul(pt,vt)|0,c=c+Math.imul(pt,Mt)|0,c=c+Math.imul(_t,vt)|0,y=y+Math.imul(_t,Mt)|0,w=w+Math.imul(ht,Ct)|0,c=c+Math.imul(ht,St)|0,c=c+Math.imul(mt,Ct)|0,y=y+Math.imul(mt,St)|0,w=w+Math.imul(dt,Pt)|0,c=c+Math.imul(dt,kt)|0,c=c+Math.imul(ft,Pt)|0,y=y+Math.imul(ft,kt)|0,w=w+Math.imul(lt,At)|0,c=c+Math.imul(lt,Ot)|0,c=c+Math.imul(ut,At)|0,y=y+Math.imul(ut,Ot)|0,w=w+Math.imul(at,xt)|0,c=c+Math.imul(at,Dt)|0,c=c+Math.imul(ct,xt)|0,y=y+Math.imul(ct,Dt)|0,w=w+Math.imul(ot,Bt)|0,c=c+Math.imul(ot,Et)|0,c=c+Math.imul(st,Bt)|0,y=y+Math.imul(st,Et)|0,w=w+Math.imul(it,Vt)|0,c=c+Math.imul(it,Tt)|0,c=c+Math.imul(nt,Vt)|0,y=y+Math.imul(nt,Tt)|0,w=w+Math.imul(G,Ft)|0,c=c+Math.imul(G,It)|0,c=c+Math.imul(et,Ft)|0,y=y+Math.imul(et,It)|0,w=w+Math.imul(T,Lt)|0,c=c+Math.imul(T,jt)|0,c=c+Math.imul(L,Lt)|0,y=y+Math.imul(L,jt)|0;var Si=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Si>>>26)|0,Si&=67108863,w=Math.imul(gt,vt),c=Math.imul(gt,Mt),c=c+Math.imul(bt,vt)|0,y=Math.imul(bt,Mt),w=w+Math.imul(pt,Ct)|0,c=c+Math.imul(pt,St)|0,c=c+Math.imul(_t,Ct)|0,y=y+Math.imul(_t,St)|0,w=w+Math.imul(ht,Pt)|0,c=c+Math.imul(ht,kt)|0,c=c+Math.imul(mt,Pt)|0,y=y+Math.imul(mt,kt)|0,w=w+Math.imul(dt,At)|0,c=c+Math.imul(dt,Ot)|0,c=c+Math.imul(ft,At)|0,y=y+Math.imul(ft,Ot)|0,w=w+Math.imul(lt,xt)|0,c=c+Math.imul(lt,Dt)|0,c=c+Math.imul(ut,xt)|0,y=y+Math.imul(ut,Dt)|0,w=w+Math.imul(at,Bt)|0,c=c+Math.imul(at,Et)|0,c=c+Math.imul(ct,Bt)|0,y=y+Math.imul(ct,Et)|0,w=w+Math.imul(ot,Vt)|0,c=c+Math.imul(ot,Tt)|0,c=c+Math.imul(st,Vt)|0,y=y+Math.imul(st,Tt)|0,w=w+Math.imul(it,Ft)|0,c=c+Math.imul(it,It)|0,c=c+Math.imul(nt,Ft)|0,y=y+Math.imul(nt,It)|0,w=w+Math.imul(G,Lt)|0,c=c+Math.imul(G,jt)|0,c=c+Math.imul(et,Lt)|0,y=y+Math.imul(et,jt)|0;var Pi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Pi>>>26)|0,Pi&=67108863,w=Math.imul(gt,Ct),c=Math.imul(gt,St),c=c+Math.imul(bt,Ct)|0,y=Math.imul(bt,St),w=w+Math.imul(pt,Pt)|0,c=c+Math.imul(pt,kt)|0,c=c+Math.imul(_t,Pt)|0,y=y+Math.imul(_t,kt)|0,w=w+Math.imul(ht,At)|0,c=c+Math.imul(ht,Ot)|0,c=c+Math.imul(mt,At)|0,y=y+Math.imul(mt,Ot)|0,w=w+Math.imul(dt,xt)|0,c=c+Math.imul(dt,Dt)|0,c=c+Math.imul(ft,xt)|0,y=y+Math.imul(ft,Dt)|0,w=w+Math.imul(lt,Bt)|0,c=c+Math.imul(lt,Et)|0,c=c+Math.imul(ut,Bt)|0,y=y+Math.imul(ut,Et)|0,w=w+Math.imul(at,Vt)|0,c=c+Math.imul(at,Tt)|0,c=c+Math.imul(ct,Vt)|0,y=y+Math.imul(ct,Tt)|0,w=w+Math.imul(ot,Ft)|0,c=c+Math.imul(ot,It)|0,c=c+Math.imul(st,Ft)|0,y=y+Math.imul(st,It)|0,w=w+Math.imul(it,Lt)|0,c=c+Math.imul(it,jt)|0,c=c+Math.imul(nt,Lt)|0,y=y+Math.imul(nt,jt)|0;var ki=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(ki>>>26)|0,ki&=67108863,w=Math.imul(gt,Pt),c=Math.imul(gt,kt),c=c+Math.imul(bt,Pt)|0,y=Math.imul(bt,kt),w=w+Math.imul(pt,At)|0,c=c+Math.imul(pt,Ot)|0,c=c+Math.imul(_t,At)|0,y=y+Math.imul(_t,Ot)|0,w=w+Math.imul(ht,xt)|0,c=c+Math.imul(ht,Dt)|0,c=c+Math.imul(mt,xt)|0,y=y+Math.imul(mt,Dt)|0,w=w+Math.imul(dt,Bt)|0,c=c+Math.imul(dt,Et)|0,c=c+Math.imul(ft,Bt)|0,y=y+Math.imul(ft,Et)|0,w=w+Math.imul(lt,Vt)|0,c=c+Math.imul(lt,Tt)|0,c=c+Math.imul(ut,Vt)|0,y=y+Math.imul(ut,Tt)|0,w=w+Math.imul(at,Ft)|0,c=c+Math.imul(at,It)|0,c=c+Math.imul(ct,Ft)|0,y=y+Math.imul(ct,It)|0,w=w+Math.imul(ot,Lt)|0,c=c+Math.imul(ot,jt)|0,c=c+Math.imul(st,Lt)|0,y=y+Math.imul(st,jt)|0;var Ai=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,w=Math.imul(gt,At),c=Math.imul(gt,Ot),c=c+Math.imul(bt,At)|0,y=Math.imul(bt,Ot),w=w+Math.imul(pt,xt)|0,c=c+Math.imul(pt,Dt)|0,c=c+Math.imul(_t,xt)|0,y=y+Math.imul(_t,Dt)|0,w=w+Math.imul(ht,Bt)|0,c=c+Math.imul(ht,Et)|0,c=c+Math.imul(mt,Bt)|0,y=y+Math.imul(mt,Et)|0,w=w+Math.imul(dt,Vt)|0,c=c+Math.imul(dt,Tt)|0,c=c+Math.imul(ft,Vt)|0,y=y+Math.imul(ft,Tt)|0,w=w+Math.imul(lt,Ft)|0,c=c+Math.imul(lt,It)|0,c=c+Math.imul(ut,Ft)|0,y=y+Math.imul(ut,It)|0,w=w+Math.imul(at,Lt)|0,c=c+Math.imul(at,jt)|0,c=c+Math.imul(ct,Lt)|0,y=y+Math.imul(ct,jt)|0;var Oi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Oi>>>26)|0,Oi&=67108863,w=Math.imul(gt,xt),c=Math.imul(gt,Dt),c=c+Math.imul(bt,xt)|0,y=Math.imul(bt,Dt),w=w+Math.imul(pt,Bt)|0,c=c+Math.imul(pt,Et)|0,c=c+Math.imul(_t,Bt)|0,y=y+Math.imul(_t,Et)|0,w=w+Math.imul(ht,Vt)|0,c=c+Math.imul(ht,Tt)|0,c=c+Math.imul(mt,Vt)|0,y=y+Math.imul(mt,Tt)|0,w=w+Math.imul(dt,Ft)|0,c=c+Math.imul(dt,It)|0,c=c+Math.imul(ft,Ft)|0,y=y+Math.imul(ft,It)|0,w=w+Math.imul(lt,Lt)|0,c=c+Math.imul(lt,jt)|0,c=c+Math.imul(ut,Lt)|0,y=y+Math.imul(ut,jt)|0;var xi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(xi>>>26)|0,xi&=67108863,w=Math.imul(gt,Bt),c=Math.imul(gt,Et),c=c+Math.imul(bt,Bt)|0,y=Math.imul(bt,Et),w=w+Math.imul(pt,Vt)|0,c=c+Math.imul(pt,Tt)|0,c=c+Math.imul(_t,Vt)|0,y=y+Math.imul(_t,Tt)|0,w=w+Math.imul(ht,Ft)|0,c=c+Math.imul(ht,It)|0,c=c+Math.imul(mt,Ft)|0,y=y+Math.imul(mt,It)|0,w=w+Math.imul(dt,Lt)|0,c=c+Math.imul(dt,jt)|0,c=c+Math.imul(ft,Lt)|0,y=y+Math.imul(ft,jt)|0;var Di=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Di>>>26)|0,Di&=67108863,w=Math.imul(gt,Vt),c=Math.imul(gt,Tt),c=c+Math.imul(bt,Vt)|0,y=Math.imul(bt,Tt),w=w+Math.imul(pt,Ft)|0,c=c+Math.imul(pt,It)|0,c=c+Math.imul(_t,Ft)|0,y=y+Math.imul(_t,It)|0,w=w+Math.imul(ht,Lt)|0,c=c+Math.imul(ht,jt)|0,c=c+Math.imul(mt,Lt)|0,y=y+Math.imul(mt,jt)|0;var Bi=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Bi>>>26)|0,Bi&=67108863,w=Math.imul(gt,Ft),c=Math.imul(gt,It),c=c+Math.imul(bt,Ft)|0,y=Math.imul(bt,It),w=w+Math.imul(pt,Lt)|0,c=c+Math.imul(pt,jt)|0,c=c+Math.imul(_t,Lt)|0,y=y+Math.imul(_t,jt)|0;var Ei=(C+w|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ei>>>26)|0,Ei&=67108863,w=Math.imul(gt,Lt),c=Math.imul(gt,jt),c=c+Math.imul(bt,Lt)|0,y=Math.imul(bt,jt);var Vi=(C+w|0)+((c&8191)<<13)|0;return C=(y+(c>>>13)|0)+(Vi>>>26)|0,Vi&=67108863,M[0]=pi,M[1]=_i,M[2]=gi,M[3]=bi,M[4]=wi,M[5]=yi,M[6]=vi,M[7]=Mi,M[8]=Ci,M[9]=Si,M[10]=Pi,M[11]=ki,M[12]=Ai,M[13]=Oi,M[14]=xi,M[15]=Di,M[16]=Bi,M[17]=Ei,M[18]=Vi,C!==0&&(M[19]=C,h.length++),h};Math.imul||(A=x);function E(s,l,h){h.negative=l.negative^s.negative,h.length=s.length+l.length;for(var p=0,b=0,M=0;M<h.length-1;M++){var C=b;b=0;for(var w=p&67108863,c=Math.min(M,l.length-1),y=Math.max(0,M-s.length+1);y<=c;y++){var V=M-y,T=s.words[V]|0,L=l.words[y]|0,K=T*L,G=K&67108863;C=C+(K/67108864|0)|0,G=G+w|0,w=G&67108863,C=C+(G>>>26)|0,b+=C>>>26,C&=67108863}h.words[M]=w,p=C,C=b}return p!==0?h.words[M]=p:h.length--,h._strip()}function $(s,l,h){return E(s,l,h)}o.prototype.mulTo=function(s,l){var h,p=this.length+s.length;return this.length===10&&s.length===10?h=A(this,s,l):p<63?h=x(this,s,l):p<1024?h=E(this,s,l):h=$(this,s,l),h};function I(s,l){this.x=s,this.y=l}I.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},I.prototype.revBin=function(s,l,h){if(s===0||s===h-1)return s;for(var p=0,b=0;b<l;b++)p|=(s&1)<<l-b-1,s>>=1;return p},I.prototype.permute=function(s,l,h,p,b,M){for(var C=0;C<M;C++)p[C]=l[s[C]],b[C]=h[s[C]]},I.prototype.transform=function(s,l,h,p,b,M){this.permute(M,s,l,h,p,b);for(var C=1;C<b;C<<=1)for(var w=C<<1,c=Math.cos(2*Math.PI/w),y=Math.sin(2*Math.PI/w),V=0;V<b;V+=w)for(var T=c,L=y,K=0;K<C;K++){var G=h[V+K],et=p[V+K],me=h[V+K+C],it=p[V+K+C],nt=T*me-L*it;it=T*it+L*me,me=nt,h[V+K]=G+me,p[V+K]=et+it,h[V+K+C]=G-me,p[V+K+C]=et-it,K!==w&&(nt=c*T-y*L,L=c*L+y*T,T=nt)}},I.prototype.guessLen13b=function(s,l){var h=Math.max(l,s)|1,p=h&1,b=0;for(h=h/2|0;h;h=h>>>1)b++;return 1<<b+1+p},I.prototype.conjugate=function(s,l,h){if(!(h<=1))for(var p=0;p<h/2;p++){var b=s[p];s[p]=s[h-p-1],s[h-p-1]=b,b=l[p],l[p]=-l[h-p-1],l[h-p-1]=-b}},I.prototype.normalize13b=function(s,l){for(var h=0,p=0;p<l/2;p++){var b=Math.round(s[2*p+1]/l)*8192+Math.round(s[2*p]/l)+h;s[p]=b&67108863,b<67108864?h=0:h=b/67108864|0}return s},I.prototype.convert13b=function(s,l,h,p){for(var b=0,M=0;M<l;M++)b=b+(s[M]|0),h[2*M]=b&8191,b=b>>>13,h[2*M+1]=b&8191,b=b>>>13;for(M=2*l;M<p;++M)h[M]=0;r(b===0),r((b&-8192)===0)},I.prototype.stub=function(s){for(var l=new Array(s),h=0;h<s;h++)l[h]=0;return l},I.prototype.mulp=function(s,l,h){var p=2*this.guessLen13b(s.length,l.length),b=this.makeRBT(p),M=this.stub(p),C=new Array(p),w=new Array(p),c=new Array(p),y=new Array(p),V=new Array(p),T=new Array(p),L=h.words;L.length=p,this.convert13b(s.words,s.length,C,p),this.convert13b(l.words,l.length,y,p),this.transform(C,M,w,c,p,b),this.transform(y,M,V,T,p,b);for(var K=0;K<p;K++){var G=w[K]*V[K]-c[K]*T[K];c[K]=w[K]*T[K]+c[K]*V[K],w[K]=G}return this.conjugate(w,c,p),this.transform(w,c,L,M,p,b),this.conjugate(L,M,p),this.normalize13b(L,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),$(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 b=(this.words[p]|0)*s,M=(b&67108863)+(h&67108863);h>>=26,h+=b/67108864|0,h+=M>>>26,this.words[p]=M&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=B(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 b=h.sqr();p<l.length;p++,b=b.sqr())l[p]!==0&&(h=h.mul(b));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,b;if(l!==0){var M=0;for(b=0;b<this.length;b++){var C=this.words[b]&p,w=(this.words[b]|0)-C<<l;this.words[b]=w|M,M=C>>>26-l}M&&(this.words[b]=M,this.length++)}if(h!==0){for(b=this.length-1;b>=0;b--)this.words[b+h]=this.words[b];for(b=0;b<h;b++)this.words[b]=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 b=s%26,M=Math.min((s-b)/26,this.length),C=67108863^67108863>>>b<<b,w=h;if(p-=M,p=Math.max(0,p),w){for(var c=0;c<M;c++)w.words[c]=this.words[c];w.length=M}if(M!==0)if(this.length>M)for(this.length-=M,c=0;c<this.length;c++)this.words[c]=this.words[c+M];else this.words[0]=0,this.length=1;var y=0;for(c=this.length-1;c>=0&&(y!==0||c>=p);c--){var V=this.words[c]|0;this.words[c]=y<<26-b|V>>>b,y=V&C}return w&&y!==0&&(w.words[w.length++]=y),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 b=this.words[h];return!!(b&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,b;this._expand(p);var M,C=0;for(b=0;b<s.length;b++){M=(this.words[b+h]|0)+C;var w=(s.words[b]|0)*l;M-=w&67108863,C=(M>>26)-(w/67108864|0),this.words[b+h]=M&67108863}for(;b<this.length-h;b++)M=(this.words[b+h]|0)+C,C=M>>26,this.words[b+h]=M&67108863;if(C===0)return this._strip();for(r(C===-1),C=0,b=0;b<this.length;b++)M=-(this.words[b]|0)+C,C=M>>26,this.words[b]=M&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(s,l){var h=this.length-s.length,p=this.clone(),b=s,M=b.words[b.length-1]|0,C=this._countBits(M);h=26-C,h!==0&&(b=b.ushln(h),p.iushln(h),M=b.words[b.length-1]|0);var w=p.length-b.length,c;if(l!=="mod"){c=new o(null),c.length=w+1,c.words=new Array(c.length);for(var y=0;y<c.length;y++)c.words[y]=0}var V=p.clone()._ishlnsubmul(b,1,w);V.negative===0&&(p=V,c&&(c.words[w]=1));for(var T=w-1;T>=0;T--){var L=(p.words[b.length+T]|0)*67108864+(p.words[b.length+T-1]|0);for(L=Math.min(L/M|0,67108863),p._ishlnsubmul(b,L,T);p.negative!==0;)L--,p.negative=0,p._ishlnsubmul(b,1,T),p.isZero()||(p.negative^=1);c&&(c.words[T]=L)}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,b,M;return this.negative!==0&&s.negative===0?(M=this.neg().divmod(s,l),l!=="mod"&&(p=M.div.neg()),l!=="div"&&(b=M.mod.neg(),h&&b.negative!==0&&b.iadd(s)),{div:p,mod:b}):this.negative===0&&s.negative!==0?(M=this.divmod(s.neg(),l),l!=="mod"&&(p=M.div.neg()),{div:p,mod:M.mod}):this.negative&s.negative?(M=this.neg().divmod(s.neg(),l),l!=="div"&&(b=M.mod.neg(),h&&b.negative!==0&&b.isub(s)),{div:M.div,mod:b}):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),b=s.andln(1),M=h.cmp(p);return M<0||b===1&&M===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,b=this.length-1;b>=0;b--)p=(h*p+(this.words[b]|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 b=(this.words[p]|0)+h*67108864;this.words[p]=b/s|0,h=b%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),b=new o(0),M=new o(0),C=new o(1),w=0;l.isEven()&&h.isEven();)l.iushrn(1),h.iushrn(1),++w;for(var c=h.clone(),y=l.clone();!l.isZero();){for(var V=0,T=1;!(l.words[0]&T)&&V<26;++V,T<<=1);if(V>0)for(l.iushrn(V);V-- >0;)(p.isOdd()||b.isOdd())&&(p.iadd(c),b.isub(y)),p.iushrn(1),b.iushrn(1);for(var L=0,K=1;!(h.words[0]&K)&&L<26;++L,K<<=1);if(L>0)for(h.iushrn(L);L-- >0;)(M.isOdd()||C.isOdd())&&(M.iadd(c),C.isub(y)),M.iushrn(1),C.iushrn(1);l.cmp(h)>=0?(l.isub(h),p.isub(M),b.isub(C)):(h.isub(l),M.isub(p),C.isub(b))}return{a:M,b:C,gcd:h.iushln(w)}},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),b=new o(0),M=h.clone();l.cmpn(1)>0&&h.cmpn(1)>0;){for(var C=0,w=1;!(l.words[0]&w)&&C<26;++C,w<<=1);if(C>0)for(l.iushrn(C);C-- >0;)p.isOdd()&&p.iadd(M),p.iushrn(1);for(var c=0,y=1;!(h.words[0]&y)&&c<26;++c,y<<=1);if(c>0)for(h.iushrn(c);c-- >0;)b.isOdd()&&b.iadd(M),b.iushrn(1);l.cmp(h)>=0?(l.isub(h),p.isub(b)):(h.isub(l),b.isub(p))}var V;return l.cmpn(1)===0?V=p:V=b,V.cmpn(0)<0&&V.iadd(s),V},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 b=l.cmp(h);if(b<0){var M=l;l=h,h=M}else if(b===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 b=p,M=h;b!==0&&M<this.length;M++){var C=this.words[M]|0;C+=b,b=C>>>26,C&=67108863,this.words[M]=C}return b!==0&&(this.words[M]=b,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,b=s.words[h]|0;if(p!==b){p<b?l=-1:p>b&&(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 Z={k256:null,p224:null,p192:null,p25519:null};function R(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()}R.prototype._tmp=function(){var s=new o(null);return s.words=new Array(Math.ceil(this.n/13)),s},R.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},R.prototype.split=function(s,l){s.iushrn(this.n,0,l)},R.prototype.imulK=function(s){return s.imul(this.k)};function W(){R.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a(W,R),W.prototype.split=function(s,l){for(var h=4194303,p=Math.min(s.length,9),b=0;b<p;b++)l.words[b]=s.words[b];if(l.length=p,s.length<=9){s.words[0]=0,s.length=1;return}var M=s.words[9];for(l.words[l.length++]=M&h,b=10;b<s.length;b++){var C=s.words[b]|0;s.words[b-10]=(C&h)<<4|M>>>22,M=C}M>>>=22,s.words[b-10]=M,M===0&&s.length>10?s.length-=10:s.length-=9},W.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 Q(){R.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}a(Q,R);function J(){R.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}a(J,R);function Y(){R.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}a(Y,R),Y.prototype.imulK=function(s){for(var l=0,h=0;h<s.length;h++){var p=(s.words[h]|0)*19+l,b=p&67108863;p>>>=26,s.words[h]=b,l=p}return l!==0&&(s.words[s.length++]=l),s},o._prime=function(s){if(Z[s])return Z[s];var l;if(s==="k256")l=new W;else if(s==="p224")l=new Q;else if(s==="p192")l=new J;else if(s==="p25519")l=new Y;else throw new Error("Unknown prime "+s);return Z[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),b=0;!p.isZero()&&p.andln(1)===0;)b++,p.iushrn(1);r(!p.isZero());var M=new o(1).toRed(this),C=M.redNeg(),w=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new o(2*c*c).toRed(this);this.pow(c,w).cmp(C)!==0;)c.redIAdd(C);for(var y=this.pow(c,p),V=this.pow(s,p.addn(1).iushrn(1)),T=this.pow(s,p),L=b;T.cmp(M)!==0;){for(var K=T,G=0;K.cmp(M)!==0;G++)K=K.redSqr();r(G<L);var et=this.pow(y,new o(1).iushln(L-G-1));V=V.redMul(et),y=et.redSqr(),T=T.redMul(y),L=G}return V},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 b=2;b<p.length;b++)p[b]=this.mul(p[b-1],s);var M=p[0],C=0,w=0,c=l.bitLength()%26;for(c===0&&(c=26),b=l.length-1;b>=0;b--){for(var y=l.words[b],V=c-1;V>=0;V--){var T=y>>V&1;if(M!==p[0]&&(M=this.sqr(M)),T===0&&C===0){w=0;continue}C<<=1,C|=T,w++,!(w!==h&&(b!==0||V!==0))&&(M=this.mul(M,p[C]),w=0,C=0)}c=26}return M},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 H(s)};function H(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(H,X),H.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},H.prototype.convertFrom=function(s){var l=this.imod(s.mul(this.rinv));return l.red=null,l},H.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),b=h.isub(p).iushrn(this.shift),M=b;return b.cmp(this.m)>=0?M=b.isub(this.m):b.cmpn(0)<0&&(M=b.iadd(this.m)),M._forceRed(this)},H.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),b=h.isub(p).iushrn(this.shift),M=b;return b.cmp(this.m)>=0?M=b.isub(this.m):b.cmpn(0)<0&&(M=b.iadd(this.m)),M._forceRed(this)},H.prototype.invm=function(s){var l=this.imod(s._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof t>"u"||t,i)}),Ti={REQUEST_PARAMS:"requestParams",METHOD_NAME:"methodName"},Ir=class $n extends Error{constructor(t,e,n){super(t),this.code=e,this.details=n,this.name=this.constructor.name}static{this.DETAILS_KEYS=Ti}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 $n&&t.code===e}},Lr=class extends Ir{constructor(i,t,e){super(i,t||"UnknownError",e)}static isCommonErrorCode(i,t){return this.isErrorCode(i,t)}},Jt=(i,t,e)=>{throw new Lr(t,i,e)};var Kn=864e5;var xe=9e15,we=1e9,Ii="0123456789abcdef",ti="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ei="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Li={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-xe,maxE:xe,crypto:!1},Wn,fe,N=!0,ni="[DecimalError] ",ge=ni+"Invalid argument: ",Zn=ni+"Precision limit exceeded",zn=ni+"crypto unavailable",Xn="[object Decimal]",Wt=Math.floor,Nt=Math.pow,Ur=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,$r=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Kr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Gn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ee=1e7,q=7,Wr=9007199254740991,Zr=ti.length-1,ji=ei.length-1,O={toStringTag:Xn};O.absoluteValue=O.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),F(i)};O.ceil=function(){return F(new this.constructor(this),this.e+1,2)};O.clampedTo=O.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)};O.comparedTo=O.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};O.cosine=O.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())+q,n.rounding=1,e=zr(n,tr(n,e)),n.precision=i,n.rounding=t,F(fe==2||fe==3?e.neg():e,i,t,!0)):new n(1):new n(NaN)};O.cubeRoot=O.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(N=!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=tt(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 N=!0,F(n,i,_.rounding,t)};O.decimalPlaces=O.dp=function(){var i,t=this.d,e=NaN;if(t){if(i=t.length-1,e=(i-Wt(this.e/q))*q,i=t[i],i)for(;i%10==0;i/=10)e--;e<0&&(e=0)}return e};O.dividedBy=O.div=function(i){return tt(this,new this.constructor(i))};O.dividedToIntegerBy=O.divToInt=function(i){var t=this,e=t.constructor;return F(tt(t,new e(i),0,1,1),e.precision,e.rounding)};O.equals=O.eq=function(i){return this.cmp(i)===0};O.floor=function(){return F(new this.constructor(this),this.e+1,3)};O.greaterThan=O.gt=function(i){return this.cmp(i)>0};O.greaterThanOrEqualTo=O.gte=function(i){var t=this.cmp(i);return t==1||t===0};O.hyperbolicCosine=O.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/oi(4,i)).toString()):(i=16,t="2.3283064365386962890625e-10"),a=De(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)};O.hyperbolicSine=O.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=De(a,2,r,r,!0);else{i=1.4*Math.sqrt(n),i=i>16?16:i|0,r=r.times(1/oi(5,i)),r=De(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)};O.hyperbolicTangent=O.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,tt(e.sinh(),e.cosh(),n.precision=i,n.rounding=t)):new n(e.s)};O.inverseCosine=O.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()?ae(t,n,r):new t(0):new t(NaN):i.isZero()?ae(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))};O.inverseHyperbolicCosine=O.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,N=!1,e=e.times(e).minus(1).sqrt().plus(e),N=!0,n.precision=i,n.rounding=t,e.ln()):new n(e)};O.inverseHyperbolicSine=O.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,N=!1,e=e.times(e).plus(1).sqrt().plus(e),N=!0,n.precision=i,n.rounding=t,e.ln())};O.inverseHyperbolicTangent=O.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=tt(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)};O.inverseSine=O.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=ae(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)))};O.inverseTangent=O.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=ae(m,_+4,g).times(.25),o.s=f.s,o}else{if(!f.s)return new m(NaN);if(_+4<=ji)return o=ae(m,_+4,g).times(.5),o.s=f.s,o}for(m.precision=u=_+10,m.rounding=1,e=Math.min(28,u/q+2|0),i=e;i;--i)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(N=!1,t=Math.ceil(u/q),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)),N=!0,F(o,m.precision=_,m.rounding=g,!0)};O.isFinite=function(){return!!this.d};O.isInteger=O.isInt=function(){return!!this.d&&Wt(this.e/q)>this.d.length-2};O.isNaN=function(){return!this.s};O.isNegative=O.isNeg=function(){return this.s<0};O.isPositive=O.isPos=function(){return this.s>0};O.isZero=function(){return!!this.d&&this.d[0]===0};O.lessThan=O.lt=function(i){return this.cmp(i)<0};O.lessThanOrEqualTo=O.lte=function(i){return this.cmp(i)<1};O.logarithm=O.log=function(i){var t,e,n,r,a,o,u,d,f=this,m=f.constructor,_=m.precision,g=m.rounding,v=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(N=!1,u=_+v,o=_e(f,u),n=t?ii(m,u+10):_e(i,u),d=tt(o,n,u,1),Te(d.d,r=_,g))do if(u+=10,o=_e(f,u),n=t?ii(m,u+10):_e(i,u),d=tt(o,n,u,1),!a){+Ut(d.d).slice(r+1,r+15)+1==1e14&&(d=F(d,_+1,0));break}while(Te(d.d,r+=10,g));return N=!0,F(d,_,g)};O.minus=O.sub=function(i){var t,e,n,r,a,o,u,d,f,m,_,g,v=this,S=v.constructor;if(i=new S(i),!v.d||!i.d)return!v.s||!i.s?i=new S(NaN):v.d?i.s=-i.s:i=new S(i.d||v.s!==i.s?v:NaN),i;if(v.s!=i.s)return i.s=-i.s,v.plus(i);if(f=v.d,g=i.d,u=S.precision,d=S.rounding,!f[0]||!g[0]){if(g[0])i.s=-i.s;else if(f[0])i=new S(v);else return new S(d===3?-0:0);return N?F(i,u,d):i}if(e=Wt(i.e/q),m=Wt(v.e/q),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/q),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]=ee-1;--f[r],f[n]+=ee}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=ri(f,e),N?F(i,u,d):i):new S(d===3?-0:0)};O.modulo=O.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):(N=!1,n.modulo==9?(t=tt(e,i.abs(),0,3,1),t.s*=i.s):t=tt(e,i,0,n.modulo,1),t=t.times(i),N=!0,e.minus(t))};O.naturalExponential=O.exp=function(){return qi(this)};O.naturalLogarithm=O.ln=function(){return _e(this)};O.negated=O.neg=function(){var i=new this.constructor(this);return i.s=-i.s,F(i)};O.plus=O.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(_)),N?F(i,u,d):i;if(a=Wt(_.e/q),n=Wt(i.e/q),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/q),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)/ee|0,f[r]%=ee;for(t&&(f.unshift(t),++n),o=f.length;f[--o]==0;)f.pop();return i.d=f,i.e=ri(f,n),N?F(i,u,d):i};O.precision=O.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};O.round=function(){var i=this,t=i.constructor;return F(new t(i),i.e+1,t.rounding)};O.sine=O.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())+q,n.rounding=1,e=Gr(n,tr(n,e)),n.precision=i,n.rounding=t,F(fe>2?e.neg():e,i,t,!0)):new n(NaN)};O.squareRoot=O.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(N=!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(tt(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 N=!0,F(n,d,m.rounding,i)};O.tangent=O.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=tt(e,new n(1).minus(e.times(e)).sqrt(),i+10,0),n.precision=i,n.rounding=t,F(fe==2||fe==4?e.neg():e,i,t,!0)):new n(NaN)};O.times=O.mul=function(i){var t,e,n,r,a,o,u,d,f,m=this,_=m.constructor,g=m.d,v=(i=new _(i)).d;if(i.s*=m.s,!g||!g[0]||!v||!v[0])return new _(!i.s||g&&!g[0]&&!v||v&&!v[0]&&!g?NaN:!g||!v?i.s/0:i.s*0);for(e=Wt(m.e/q)+Wt(i.e/q),d=g.length,f=v.length,d<f&&(a=g,g=v,v=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]+v[n]*g[r-n-1]+t,a[r--]=u%ee|0,t=u/ee|0;a[r]=(a[r]+t)%ee|0}for(;!a[--o];)a.pop();return t?++e:a.shift(),i.d=a,i.e=ri(a,e),N?F(i,_.precision,_.rounding):i};O.toBinary=function(i,t){return Ri(this,2,i,t)};O.toDecimalPlaces=O.toDP=function(i,t){var e=this,n=e.constructor;return e=new n(e),i===void 0?e:(Xt(i,0,we),t===void 0?t=n.rounding:Xt(t,0,8),F(e,i+e.e+1,t))};O.toExponential=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=le(n,!0):(Xt(i,0,we),t===void 0?t=r.rounding:Xt(t,0,8),n=F(new r(n),i+1,t),e=le(n,!0,i+1)),n.isNeg()&&!n.isZero()?"-"+e:e};O.toFixed=function(i,t){var e,n,r=this,a=r.constructor;return i===void 0?e=le(r):(Xt(i,0,we),t===void 0?t=a.rounding:Xt(t,0,8),n=F(new a(r),i+r.e+1,t),e=le(n,!1,i+n.e+1)),r.isNeg()&&!r.isZero()?"-"+e:e};O.toFraction=function(i){var t,e,n,r,a,o,u,d,f,m,_,g,v=this,S=v.d,P=v.constructor;if(!S)return new P(v);if(f=e=new P(1),n=d=new P(0),t=new P(n),a=t.e=Hn(S)-v.e-1,o=a%q,t.d[0]=Nt(10,o<0?q+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(N=!1,u=new P(Ut(S)),m=P.precision,P.precision=a=S.length*q*2;_=tt(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=tt(i.minus(e),n,0,1,1),d=d.plus(r.times(f)),e=e.plus(r.times(n)),d.s=f.s=v.s,g=tt(f,n,a,1).minus(v).abs().cmp(tt(d,e,a,1).minus(v).abs())<1?[f,n]:[d,e],P.precision=m,N=!0,g};O.toHexadecimal=O.toHex=function(i,t){return Ri(this,16,i,t)};O.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:Xt(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]?(N=!1,e=tt(e,i,0,t,1).times(i),N=!0,F(e)):(i.s=e.s,e=i),e};O.toNumber=function(){return+this};O.toOctal=function(i,t){return Ri(this,8,i,t)};O.toPower=O.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/q),t>=i.d.length-1&&(e=f<0?-f:f)<=Wr)return r=Qn(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):(N=!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),Te(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,N=!0,d.rounding=a,F(r,n,a))};O.toPrecision=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=le(n,n.e<=r.toExpNeg||n.e>=r.toExpPos):(Xt(i,1,we),t===void 0?t=r.rounding:Xt(t,0,8),n=F(new r(n),i,t),e=le(n,i<=n.e||n.e<=r.toExpNeg,i)),n.isNeg()&&!n.isZero()?"-"+e:e};O.toSignificantDigits=O.toSD=function(i,t){var e=this,n=e.constructor;return i===void 0?(i=n.precision,t=n.rounding):(Xt(i,1,we),t===void 0?t=n.rounding:Xt(t,0,8)),F(new n(e),i,t)};O.toString=function(){var i=this,t=i.constructor,e=le(i,i.e<=t.toExpNeg||i.e>=t.toExpPos);return i.isNeg()&&!i.isZero()?"-"+e:e};O.truncated=O.trunc=function(){return F(new this.constructor(this),this.e+1,1)};O.valueOf=O.toJSON=function(){var i=this,t=i.constructor,e=le(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=q-n.length,e&&(a+=pe(e)),a+=n;o=i[t],n=o+"",e=q-n.length,e&&(a+=pe(e))}else if(o===0)return"0";for(;o%10===0;)o/=10;return a+o}function Xt(i,t,e){if(i!==~~i||i<t||i>e)throw Error(ge+i)}function Te(i,t,e,n){var r,a,o,u;for(a=i[0];a>=10;a/=10)--t;return--t<0?(t+=q,r=0):(r=Math.ceil((t+1)/q),t%=q),a=Nt(10,q-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 Je(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/oi(4,e)).toString()):(e=16,r="2.3283064365386962890625e-10"),i.precision+=e,t=De(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 tt=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,v,S,P,D,B,x,A,E,$,I,Z,R,W,Q,J,Y,X=n.constructor,H=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?H*0:H/0);for(d?(v=1,m=n.e-r.e):(d=ee,v=q,m=Wt(n.e/v)-Wt(r.e/v)),J=l.length,W=s.length,B=new X(H),x=B.d=[],_=0;l[_]==(s[_]||0);_++);if(l[_]>(s[_]||0)&&m--,a==null?(I=a=X.precision,o=X.rounding):u?I=a+(n.e-r.e)+1:I=a,I<0)x.push(1),S=!0;else{if(I=I/v+2|0,_=0,J==1){for(g=0,l=l[0],I++;(_<W||g)&&I--;_++)Z=g*d+(s[_]||0),x[_]=Z/l|0,g=Z%l|0;S=g||_<W}else{for(g=d/(l[0]+1)|0,g>1&&(l=i(l,g,d),s=i(s,g,d),J=l.length,W=s.length),R=J,A=s.slice(0,J),E=A.length;E<J;)A[E++]=0;Y=l.slice(),Y.unshift(0),Q=l[0],l[1]>=d/2&&++Q;do g=0,f=t(l,A,J,E),f<0?($=A[0],J!=E&&($=$*d+(A[1]||0)),g=$/Q|0,g>1?(g>=d&&(g=d-1),P=i(l,g,d),D=P.length,E=A.length,f=t(P,A,D,E),f==1&&(g--,e(P,J<D?Y:l,D,d))):(g==0&&(f=g=1),P=l.slice()),D=P.length,D<E&&P.unshift(0),e(A,P,E,d),f==-1&&(E=A.length,f=t(l,A,J,E),f<1&&(g++,e(A,J<E?Y:l,E,d))),E=A.length):f===0&&(g++,A=[0]),x[_++]=g,f&&A[0]?A[E++]=s[R]||0:(A=[s[R]],E=1);while((R++<W||A[0]!==void 0)&&I--);S=A[0]!==void 0}x[0]||x.shift()}if(v==1)B.e=m,Wn=S;else{for(_=1,g=x[0];g>=10;g/=10)_++;B.e=_+m*v-1,F(B,u?a+B.e+1:a,o,S)}return B}}();function F(i,t,e,n){var r,a,o,u,d,f,m,_,g,v=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+=q,o=t,m=_[g=0],d=m/Nt(10,r-o-1)%10|0;else if(g=Math.ceil((a+1)/q),u=_.length,g>=u)if(n){for(;u++<=g;)_.push(0);m=d=0,r=1,a%=q,o=a-q+1}else break t;else{for(m=u=_[g],r=1;u>=10;u/=10)r++;a%=q,o=a-q+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,(q-t%q)%q),i.e=-t||0):_[0]=i.e=0,i;if(a==0?(_.length=g,u=1,g--):(_.length=g+1,u=Nt(10,q-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]==ee&&(_[0]=1));break}else{if(_[g]+=u,_[g]!=ee)break;_[g--]=0,u=1}for(a=_.length;_[--a]===0;)_.pop()}return N&&(i.e>v.maxE?(i.d=null,i.e=NaN):i.e<v.minE&&(i.e=0,i.d=[0])),i}function le(i,t,e){if(!i.isFinite())return Yn(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 ri(i,t){var e=i[0];for(t*=q;e>=10;e/=10)t++;return t}function ii(i,t,e){if(t>Zr)throw N=!0,e&&(i.precision=e),Error(Zn);return F(new i(ti),t,1,!0)}function ae(i,t,e){if(t>ji)throw Error(Zn);return F(new i(ei),t,e,!0)}function Hn(i){var t=i.length-1,e=t*q+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 Qn(i,t,e,n){var r,a=new i(1),o=Math.ceil(n/q+4);for(N=!1;;){if(e%2&&(a=a.times(t),Fn(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),Fn(t.d,o)}return N=!0,a}function Tn(i){return i.d[i.d.length-1]&1}function Jn(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,v=g.rounding,S=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?(N=!1,d=S):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(tt(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&&Te(o.d,d-n,v,f))g.precision=d+=10,e=a=u=new g(1),m=0,f++;else return F(o,g.precision=S,v,N=!0);else return g.precision=S,o}o=u}}function _e(i,t){var e,n,r,a,o,u,d,f,m,_,g,v=1,S=10,P=i,D=P.d,B=P.constructor,x=B.rounding,A=B.precision;if(P.s<0||!D||!D[0]||!P.e&&D[0]==1&&D.length==1)return new B(D&&!D[0]?-1/0:P.s!=1?NaN:D?0:P);if(t==null?(N=!1,m=A):m=t,B.precision=m+=S,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),v++;a=P.e,n>1?(P=new B("0."+e),a++):P=new B(n+"."+e.slice(1))}else return f=ii(B,m+2,A).times(a+""),P=_e(new B(n+"."+e.slice(1)),m-S).plus(f),B.precision=A,t==null?F(P,A,x,N=!0):P;for(_=P,d=o=P=tt(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(tt(o,new B(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(ii(B,m+2,A).times(a+""))),d=tt(d,new B(v),m,1),t==null)if(Te(d.d,m-S,x,u))B.precision=m+=S,f=o=P=tt(_.minus(1),_.plus(1),m,1),g=F(P.times(P),m,1),r=u=1;else return F(d,B.precision=A,x,N=!0);else return B.precision=A,d;d=f,r+=2}}function Yn(i){return String(i.s*i.s/0)}function Ye(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)%q,e<0&&(n+=q),n<r){for(n&&i.d.push(+t.slice(0,n)),r-=q;n<r;)i.d.push(+t.slice(n,n+=q));t=t.slice(n),n=q-t.length}else n-=r;for(;n--;)t+="0";i.d.push(+t),N&&(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 Xr(i,t){var e,n,r,a,o,u,d,f,m;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Gn.test(t))return Ye(i,t)}else if(t==="Infinity"||t==="NaN")return+t||(i.s=NaN),i.e=NaN,i.d=null,i;if($r.test(t))e=16,t=t.toLowerCase();else if(Ur.test(t))e=2;else if(Kr.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=Qn(n,new n(e),a,a*2)),f=Je(t,e,ee),m=f.length-1,a=m;f[a]===0;--a)f.pop();return a<0?new n(i.s*0):(i.e=ri(f,m),i.d=f,N=!1,o&&(i=tt(i,r,u*4)),d&&(i=i.times(Math.abs(d)<54?Nt(2,d):Le.pow(2,d))),N=!0,i)}function Gr(i,t){var e,n=t.d.length;if(n<3)return t.isZero()?t:De(i,2,t,t);e=1.4*Math.sqrt(n),e=e>16?16:e|0,t=t.times(1/oi(5,e)),t=De(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 De(i,t,e,n,r){var a,o,u,d,f=1,m=i.precision,_=Math.ceil(m/q);for(N=!1,d=e.times(e),u=new i(n);;){if(o=tt(u.times(d),new i(t++*t++),m,1),u=r?n.plus(o):n.minus(o),n=tt(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 N=!0,o.d.length=_+1,o}function oi(i,t){for(var e=i;--t;)e*=i;return e}function tr(i,t){var e,n=t.s<0,r=ae(i,i.precision,1),a=r.times(.5);if(t=t.abs(),t.lte(a))return fe=n?4:1,t;if(e=t.divToInt(r),e.isZero())fe=n?3:2;else{if(t=t.minus(e.times(r)),t.lte(a))return fe=Tn(e)?n?2:3:n?4:1,t;fe=Tn(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,v=i.constructor,S=e!==void 0;if(S?(Xt(e,1,we),n===void 0?n=v.rounding:Xt(n,0,8)):(e=v.precision,n=v.rounding),!i.isFinite())m=Yn(i);else{for(m=le(i),o=m.indexOf("."),S?(r=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):r=t,o>=0&&(m=m.replace(".",""),g=new v(1),g.e=m.length-o,g.d=Je(le(g),10,r),g.e=g.d.length),_=Je(m,10,r),a=d=_.length;_[--d]==0;)_.pop();if(!_[0])m=S?"0p+0":"0";else{if(o<0?a--:(i=new v(i),i.d=_,i.e=a,i=tt(i,g,e,n,0,r),_=i.d,a=i.e,f=Wn),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(S){if(d>1)if(t==16||t==8){for(o=t==16?4:3,--d;d%o;d++)m+="0";for(_=Je(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 Fn(i,t){if(i.length>t)return i.length=t,!0}function Hr(i){return new this(i).abs()}function Qr(i){return new this(i).acos()}function Jr(i){return new this(i).acosh()}function Yr(i,t){return new this(i).plus(t)}function to(i){return new this(i).asin()}function eo(i){return new this(i).asinh()}function io(i){return new this(i).atan()}function no(i){return new this(i).atanh()}function ro(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=ae(this,a,1).times(t.s>0?.25:.75),e.s=i.s):!t.d||i.isZero()?(e=t.s<0?ae(this,n,r):new this(0),e.s=i.s):!i.d||t.isZero()?(e=ae(this,a,1).times(.5),e.s=i.s):t.s<0?(this.precision=a,this.rounding=1,e=this.atan(tt(i,t,a,1)),t=ae(this,a,1),this.precision=n,this.rounding=r,e=i.s<0?e.minus(t):e.plus(t)):e=this.atan(tt(i,t,a,1)),e}function oo(i){return new this(i).cbrt()}function so(i){return F(i=new this(i),i.e+1,2)}function ao(i,t,e){return new this(i).clamp(t,e)}function co(i){if(!i||typeof i!="object")throw Error(ni+"Object expected");var t,e,n,r=i.defaults===!0,a=["precision",1,we,"rounding",0,8,"toExpNeg",-xe,0,"toExpPos",0,xe,"maxE",0,xe,"minE",-xe,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 lo(i){return new this(i).cos()}function uo(i){return new this(i).cosh()}function er(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,In(a)){f.s=a.s,N?!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++;N?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 Ye(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),Gn.test(a)?Ye(f,a):Xr(f,a);if(d==="bigint")return a<0?(a=-a,f.s=-1):f.s=1,Ye(f,a.toString());throw Error(ge+a)}if(r.prototype=O,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=co,r.clone=er,r.isDecimal=In,r.abs=Hr,r.acos=Qr,r.acosh=Jr,r.add=Yr,r.asin=to,r.asinh=eo,r.atan=io,r.atanh=no,r.atan2=ro,r.cbrt=oo,r.ceil=so,r.clamp=ao,r.cos=lo,r.cosh=uo,r.div=fo,r.exp=ho,r.floor=mo,r.hypot=po,r.ln=_o,r.log=go,r.log10=wo,r.log2=bo,r.max=yo,r.min=vo,r.mod=Mo,r.mul=Co,r.pow=So,r.random=Po,r.round=ko,r.sign=Ao,r.sin=Oo,r.sinh=xo,r.sqrt=Do,r.sub=Bo,r.sum=Eo,r.tan=Vo,r.tanh=To,r.trunc=Fo,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 fo(i,t){return new this(i).div(t)}function ho(i){return new this(i).exp()}function mo(i){return F(i=new this(i),i.e+1,3)}function po(){var i,t,e=new this(0);for(N=!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 N=!0,new this(1/0);e=t}return N=!0,e.sqrt()}function In(i){return i instanceof Le||i&&i.toStringTag===Xn||!1}function _o(i){return new this(i).ln()}function go(i,t){return new this(i).log(t)}function bo(i){return new this(i).log(2)}function wo(i){return new this(i).log(10)}function yo(){return Jn(this,arguments,-1)}function vo(){return Jn(this,arguments,1)}function Mo(i,t){return new this(i).mod(t)}function Co(i,t){return new this(i).mul(t)}function So(i,t){return new this(i).pow(t)}function Po(i){var t,e,n,r,a=0,o=new this(1),u=[];if(i===void 0?i=this.precision:Xt(i,1,we),n=Math.ceil(i/q),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%=q,n&&i&&(r=Nt(10,q-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-=q)u.shift();for(n=1,r=u[0];r>=10;r/=10)n++;n<q&&(e-=q-n)}return o.e=e,o.d=u,o}function ko(i){return F(i=new this(i),i.e+1,this.rounding)}function Ao(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function Oo(i){return new this(i).sin()}function xo(i){return new this(i).sinh()}function Do(i){return new this(i).sqrt()}function Bo(i,t){return new this(i).sub(t)}function Eo(){var i=0,t=arguments,e=new this(t[i]);for(N=!1;e.s&&++i<t.length;)e=e.plus(t[i]);return N=!0,F(e,this.precision,this.rounding)}function Vo(i){return new this(i).tan()}function To(i){return new this(i).tanh()}function Fo(i){return F(i=new this(i),i.e+1,1)}O[Symbol.for("nodejs.util.inspect.custom")]=O.toString;O[Symbol.toStringTag]="Decimal";var Le=O.constructor=er(Li);ti=new Le(ti);ei=new Le(ei);var Yt=Le;function k(i){return Yt.isDecimal(i)?i:new Yt(i===void 0?0:i)}function ir(i){return k(10).pow(k(i).abs())}function ce(i,t,e=Yt.ROUND_DOWN){let n=ir(k(t));return k(i).mul(n).toFixed(0,e).toString()}function ye(i,t=32){return Number(BigInt.asIntN(t,BigInt(i)))}function be(i,t){let e=ir(k(t));return k(i).div(e).toString()}var nr="0x2::sui::SUI",Io="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";var zt=class qt{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=>{jn(r.coin_type)===jn(t)&&n.push(r)}),n}static isSuiCoin(t){return ie(t).full_address===nr}static selectCoinObjectIdGreaterThanOrEqual(t,e,n=[]){let r=qt.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=qt.sortByBalance(t.filter(f=>!n.includes(f.coin_object_id))),a=qt.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:qt.sortByBalance(u),remain_coins:qt.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=qt.getCoinAssets(r,e);if(n===BigInt(0))return this.buildZeroValueCoin(e,t,r,a);let d=qt.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)&&qt.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(qt.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(qt.isSuiCoin(r)){if(n===0n&&e.length>1){let d=qt.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=qt.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=qt.selectCoinObjectIdGreaterThanOrEqual(n,e),o=a.amount_array.reduce((S,P)=>Number(S)+Number(P),0).toString(),u=a.object_array,[d,...f]=u,m=t.object(d),_=m,g=a.amount_array.reduce((S,P)=>Number(S)+Number(P),0).toString(),v;return f.length>0&&t.mergeCoins(m,f.map(S=>t.object(S))),r&&Number(o)>Number(e)&&(_=t.splitCoins(m,[t.pure.u64(e)]),v=m),{original_spited_coin:v,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=qt.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=qt.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&&k(r.amount).eq(e)?(r.used=!0,!0):!1);return n?n.coin_object_id:Jt("CoinNotFound",`Coin not found for ${e} ${t.coin_type}`)}static buildMultiCoinInput(t,e,n,r){let a=qt.getCoinAssets(n,e);if(qt.isSuiCoin(n)){let _=t.splitCoins(t.gas,r.map(g=>t.pure.u64(g)));return{amount_coin_array:r.map((g,v)=>({coin_object_id:_[v],amount:g.toString(),used:!1})),coin_type:n,remain_coins:a}}let o=r.reduce((_,g)=>_+g,BigInt(0)),u=qt.selectCoinObjectIdGreaterThanOrEqual(a,o);if(u.object_array.length===0)return Jt("InsufficientBalance",`No enough coins for ${n} expect ${o} actual ${qt.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 Lo(i){return i.startsWith("0x")?`${i.slice(2)}`:i}function Ln(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 ie(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={...ie(t),type_arguments:e.map(o=>ie(o).source_address)};return a.type_arguments=a.type_arguments.map(o=>zt.isSuiCoin(o)?o:ie(o).source_address),a.source_address=Ln(a.full_address,a.type_arguments),a}let n=t.split("::"),r={full_address:t,address:t===nr||t===Io?"0x2":(0,Ce.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=Ln(r.full_address,r.type_arguments),r}catch{return{full_address:i,address:"",module:"",name:"",type_arguments:[],source_address:i}}}function jn(i){return ie(i).source_address}var U=(i,t=!0)=>{let e=i.split("::"),n=e.shift(),r=(0,Ce.normalizeSuiObjectId)(n);return t&&(r=Lo(r)),`${r}::${e.join("::")}`};var Uo=Fe(Ie()),qn=443636,Rn=-443636,$o="79226673515401279992447579055";var Ko="4295048016",ps=new Uo.default(1e6),Wo=(i=>(i[i.BelowRange=0]="BelowRange",i[i.InRange=1]="InRange",i[i.AboveRange=2]="AboveRange",i))(Wo||{}),Zt="0x0000000000000000000000000000000000000000000000000000000000000006";var _s=(0,Ni.getFullnodeUrl)("mainnet"),gs=(0,Ni.getFullnodeUrl)("testnet");var Rt=Fe(Ie()),de=new Rt.default(0),Ve=new Rt.default(1),si=new Rt.default(2),Zo=si.pow(new Rt.default(128)),Nn=si.pow(new Rt.default(64)).sub(Ve),zo=si.pow(new Rt.default(128)).sub(Ve),te=class{static toX64BN(i){return i.mul(new Rt.default(2).pow(new Rt.default(64)))}static toX64Decimal(i){return i.mul(Yt.pow(2,64))}static toX64(i){return new Rt.default(i.mul(Yt.pow(2,64)).floor().toFixed())}static fromX64(i){return new Yt(i.toString()).mul(Yt.pow(2,-64))}static fromX64Decimal(i){return i.mul(Yt.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(Nn).gt(de)&&(t=t.add(Ve)),t}static divRoundUp(i,t){return i.mod(t).eq(de)?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)&&Jt("MultiplicationOverflow","Multiplication overflow"),n}static checkMulDivFloor(i,t,e,n){e.eq(de)&&Jt("DivisionByZero","Divide by zero");let r=i.mul(t).div(e);return this.isOverflow(r,n)&&Jt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulDivCeil(i,t,e,n){if(e.eq(de))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(de)&&Jt("DivisionByZero","Divide by zero");let r=i.mul(t.add(e.shrn(1))).div(e);return this.isOverflow(r,n)&&Jt("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)&&Jt("MultiplicationOverflow","Multiplication shift right overflow"),r}static checkMulShiftRight64RoundUpIf(i,t,e,n){let r=i.mul(t),a=n&&r.and(Nn).gt(de)?r.shrn(64).add(Ve):r.shrn(64);return this.isOverflow(a,e)&&Jt("MultiplicationOverflow","Multiplication shift right overflow"),a}static checkMulShiftLeft(i,t,e,n){let r=i.mul(t).shln(e);return this.isOverflow(r,n)&&Jt("MultiplicationOverflow","Multiplication shift left overflow"),r}static checkDivRoundUpIf(i,t,e){return t.eq(de)&&Jt("DivisionByZero","Divide by zero"),e?this.divRoundUp(i,t):i.div(t)}static isOverflow(i,t){return i.gte(si.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(de)?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(de)?i:this.u128Neg(i).add(new Rt.default(1)).or(new Rt.default(1).shln(127))}static u128ToI128(i){return i.testn(127)?Zo.sub(i).neg():i}},Ui=class{static getMinIndex(i){return Rn+Math.abs(Rn)%i}static getMaxIndex(i){return qn-qn%i}};function rr(i){return i.data}function Xo(i){return i.data!==void 0}function Go(i){return i.content!==void 0}function or(i){let t="data"in i?rr(i):i;if(!(!t||!Go(t)||t.content.dataType!=="moveObject"))return t.content}function Ho(i){return or(i)?.type}function $i(i){let t=Xo(i)?i.data:i;return!t?.type&&"data"in i?t?.content?.dataType==="package"?"package":Ho(i):t?.type}function ai(i){return rr(i)?.previousTransaction}function ne(i){let t=or(i)?.fields;if(t)return"fields"in t?t.fields:t}Yt.config({precision:64,rounding:Yt.ROUND_DOWN,toExpNeg:-64,toExpPos:64});var Kt=Yt,Gt=Fe(Ie()),j=Fe(Ie()),Qo=14,Jo="59543866431248",Yo="184467440737095516",ts="15793534762490258745";function es(i,t,e){let n=i.toTwos(e).shln(t);return n.imaskn(e+1),n.fromTwos(e)}function z(i,t,e){let n=i.toTwos(e).shrn(t);return n.imaskn(e-t+1),n.fromTwos(e-t)}function is(i){let t;return i&1?t=new j.default("79232123823359799118286999567"):t=new j.default("79228162514264337593543950336"),i&2&&(t=z(t.mul(new j.default("79236085330515764027303304731")),96,256)),i&4&&(t=z(t.mul(new j.default("79244008939048815603706035061")),96,256)),i&8&&(t=z(t.mul(new j.default("79259858533276714757314932305")),96,256)),i&16&&(t=z(t.mul(new j.default("79291567232598584799939703904")),96,256)),i&32&&(t=z(t.mul(new j.default("79355022692464371645785046466")),96,256)),i&64&&(t=z(t.mul(new j.default("79482085999252804386437311141")),96,256)),i&128&&(t=z(t.mul(new j.default("79736823300114093921829183326")),96,256)),i&256&&(t=z(t.mul(new j.default("80248749790819932309965073892")),96,256)),i&512&&(t=z(t.mul(new j.default("81282483887344747381513967011")),96,256)),i&1024&&(t=z(t.mul(new j.default("83390072131320151908154831281")),96,256)),i&2048&&(t=z(t.mul(new j.default("87770609709833776024991924138")),96,256)),i&4096&&(t=z(t.mul(new j.default("97234110755111693312479820773")),96,256)),i&8192&&(t=z(t.mul(new j.default("119332217159966728226237229890")),96,256)),i&16384&&(t=z(t.mul(new j.default("179736315981702064433883588727")),96,256)),i&32768&&(t=z(t.mul(new j.default("407748233172238350107850275304")),96,256)),i&65536&&(t=z(t.mul(new j.default("2098478828474011932436660412517")),96,256)),i&131072&&(t=z(t.mul(new j.default("55581415166113811149459800483533")),96,256)),i&262144&&(t=z(t.mul(new j.default("38992368544603139932233054999993551")),96,256)),z(t,32,256)}function ns(i){let t=Math.abs(i),e;return t&1?e=new j.default("18445821805675392311"):e=new j.default("18446744073709551616"),t&2&&(e=z(e.mul(new j.default("18444899583751176498")),64,256)),t&4&&(e=z(e.mul(new j.default("18443055278223354162")),64,256)),t&8&&(e=z(e.mul(new j.default("18439367220385604838")),64,256)),t&16&&(e=z(e.mul(new j.default("18431993317065449817")),64,256)),t&32&&(e=z(e.mul(new j.default("18417254355718160513")),64,256)),t&64&&(e=z(e.mul(new j.default("18387811781193591352")),64,256)),t&128&&(e=z(e.mul(new j.default("18329067761203520168")),64,256)),t&256&&(e=z(e.mul(new j.default("18212142134806087854")),64,256)),t&512&&(e=z(e.mul(new j.default("17980523815641551639")),64,256)),t&1024&&(e=z(e.mul(new j.default("17526086738831147013")),64,256)),t&2048&&(e=z(e.mul(new j.default("16651378430235024244")),64,256)),t&4096&&(e=z(e.mul(new j.default("15030750278693429944")),64,256)),t&8192&&(e=z(e.mul(new j.default("12247334978882834399")),64,256)),t&16384&&(e=z(e.mul(new j.default("8131365268884726200")),64,256)),t&32768&&(e=z(e.mul(new j.default("3584323654723342297")),64,256)),t&65536&&(e=z(e.mul(new j.default("696457651847595233")),64,256)),t&131072&&(e=z(e.mul(new j.default("26294789957452057")),64,256)),t&262144&&(e=z(e.mul(new j.default("37481735321082")),64,256)),e}var rt=class se{static priceToSqrtPriceX64(t,e,n){return te.toX64(t.mul(Kt.pow(10,n-e)).sqrt())}static sqrtPriceX64ToPrice(t,e,n){return te.fromX64(t).pow(2).mul(Kt.pow(10,e-n))}static tickIndexToSqrtPriceX64(t){return t>0?new j.default(is(t)):new j.default(ns(t))}static sqrtPriceX64ToTickIndex(t){if(t.gt(new j.default($o))||t.lt(new j.default(Ko)))throw new Error("Provided sqrtPrice is not within the supported sqrtPrice range.");let e=t.bitLength()-1,n=new j.default(e-64),r=es(n,32,128),a=new j.default("8000000000000000","hex"),o=0,u=new j.default(0),d=e>=64?t.shrn(e-63):t.shln(63-e);for(;a.gt(new j.default(0))&&o<Qo;){d=d.mul(d);let v=d.shrn(127);d=d.shrn(63+v.toNumber()),u=u.add(a.mul(v)),a=a.shrn(1),o+=1}let f=u.shrn(32),m=r.add(f).mul(new j.default(Jo)),_=z(m.sub(new j.default(Yo)),64,128).toNumber(),g=z(m.add(new j.default(ts)),64,128).toNumber();return _===g?_:se.tickIndexToSqrtPriceX64(g).lte(t)?g:_}static tickIndexToPrice(t,e,n){return se.sqrtPriceX64ToPrice(se.tickIndexToSqrtPriceX64(t),e,n)}static priceToTickIndex(t,e,n){return se.sqrtPriceX64ToTickIndex(se.priceToSqrtPriceX64(t,e,n))}static priceToInitializeTickIndex(t,e,n,r){return se.getInitializeTickIndex(se.priceToTickIndex(t,e,n),r)}static getInitializeTickIndex(t,e){return t-t%e}static getNextInitializeTickIndex(t,e){return se.getInitializeTickIndex(t,e)+e}static getPrevInitializeTickIndex(t,e){return se.getInitializeTickIndex(t,e)-e}};function He(i,t,e){let n=Gt.default.min(i,t),r=Gt.default.max(i,t),a=te.fromX64BN(e.mul(r).mul(n)),o=r.sub(n);return!a.isZero()&&!o.isZero()?a.div(o):new Gt.default(0)}function Qe(i,t,e){let n=Gt.default.min(i,t),r=Gt.default.max(i,t).sub(n);return r.isZero()?new Gt.default(0):e.shln(64).div(r)}var re=class Oe{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=te.toX64Decimal(o).mul(f.sub(d)).div(d.mul(f)),_=new Kt(0)):e.lt(r)?(m=te.toX64Decimal(o).mul(f.sub(u)).div(u.mul(f)),_=te.fromX64Decimal(o.mul(u.sub(d)))):(m=new Kt(0),_=te.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=rt.sqrtPriceX64ToTickIndex(u),f=rt.tickIndexToSqrtPriceX64(t),m=rt.tickIndexToSqrtPriceX64(e),_;if(d<t){if(!r)throw new Error("lower tick cannot calculate liquidity by coinB");_=He(f,m,n)}else if(d>e){if(r)throw new Error("upper tick cannot calculate liquidity by coinA");_=Qe(m,f,n)}else r?_=He(u,m,n):_=Qe(u,f,n);let g=Oe.getCoinAmountFromLiquidity(_,u,f,m,a),v=a?k(g.coin_amount_a.toString()).mul(1+o).toString():k(g.coin_amount_a.toString()).mul(1-o).toString(),S=a?k(g.coin_amount_b.toString()).mul(1+o).toString():k(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(v).toString():Kt.floor(v).toString(),coin_amount_limit_b:a?Kt.ceil(S).toString():Kt.floor(S).toString(),liquidity_amount:_.toString(),fix_amount_a:r}}static estimateLiquidityFromCoinAmounts(t,e,n,r){if(e>n)return Jt("InvalidTick","lower tick cannot be greater than lower tick",{[Ti.METHOD_NAME]:"estimateLiquidityFromCoinAmounts",[Ti.REQUEST_PARAMS]:{lower_tick:e,upper_tick:n,token_amount:r}});let a=rt.sqrtPriceX64ToTickIndex(t),o=rt.tickIndexToSqrtPriceX64(e),u=rt.tickIndexToSqrtPriceX64(n);if(a<e)return He(o,u,new Gt.default(r.coin_amount_a)).toString();if(a>=n)return Qe(u,o,new Gt.default(r.coin_amount_b)).toString();let d=He(t,u,new Gt.default(r.coin_amount_a)),f=Qe(t,o,new Gt.default(r.coin_amount_b));return Gt.default.min(d,f).toString()}static calculateDepositRatio(t,e,n){let r=new Gt.default(1e8),{coin_amount_b:a}=Oe.estLiquidityAndCoinAmountFromOneAmounts(t,e,r,!0,!0,0,n),o=rt.sqrtPriceX64ToPrice(n,0,0),u=k(r.toString()).mul(o),d=u.add(a.toString()),f=u.div(d),m=k(a.toString()).div(d);return{ratio_a:f,ratio_b:m}}static calculateAmountDepositRatio(t,e,n,r,a){let o=rt.sqrtPriceX64ToPrice(n,r,a),u=rt.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 Gt.default(ce(1,r)),{coin_amount_b:f}=Oe.estLiquidityAndCoinAmountFromOneAmounts(t,e,d,!0,!0,0,n),m=be(d.toString(),r),_=be(f.toString(),a),g=k(m).add(_),v=k(m).div(g),S=k(_).div(g);return{ratio_a:v,ratio_b:S,curr_price:o}}static getCoinAmountsFromRatio(t,e,n,r,a,o,u){let d=k(ce(k(n).mul(t).div(r).toString(),o)).toFixed(0),f=k(ce(k(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}=Oe.calculateDepositRatio(t,e,n);return Oe.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 bs=Fe(Ie());var pn=require("@cetusprotocol/sui-clmm-sdk");var Ee=require("@mysten/sui/transactions"),Ht=oe(require("bn.js")),dr=require("@cetusprotocol/aggregator-sdk");var fr=require("@mysten/sui/utils"),hr=oe(require("decimal.js"));var $t=oe(require("bn.js")),li=oe(require("decimal.js"));var Ki=oe(require("bn.js")),Wi=oe(require("decimal.js")),ci=(i,t,e)=>{if(t==="min"){if(i===Ui.getMinIndex(e))return!0}else if(i===Ui.getMaxIndex(e))return!0;return!1};function rs(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 sr(i,t,e,n,r){let a=new Ki.default(10).pow(new Ki.default(n)),{coin_amount_b:o}=re.estLiquidityAndCoinAmountFromOneAmounts(i,t,a,!0,!0,0,e),u=rt.sqrtPriceX64ToPrice(e,n,r),d=k(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),_=k(o.toString()).div(f);return{ratioA:m,ratioB:_}}function ue(i,t,e,n,r,a,o){let u=k(ce(k(e).mul(i).div(n).toString(),a)).toFixed(0),d=k(ce(k(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}=sr(i,t,e,o,u);return ue(d,f,n,r,a,o,u)}var Se=10n;function je(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:U(o.coin_type_a.fields.name,!1),coin_type_b:U(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:ye(BigInt(o.tick_lower_index.fields.bits)),tick_upper_index:ye(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:v}=_.fields;return{coin_type:U(g.fields.name,!1),value:v}});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:ie(t.quote_type.fields.name).full_address,lp_token_type:ie(e).type_arguments[0],balances:f,protocol_fee_rate:t.protocol_fee_rate}}async function os(i,t=!0){i.getData().commands.forEach((e,n)=>{})}function qe(i,t){let e=k(i).div(t).toString(),n=k(t).div(i).toString();return{quote_per_base:e,base_per_quote:n}}function ar(i,t,e,n){let r=10n**(Se+n-e),a=10n**(Se+e-n),o=te.checkMulDivFloor(new $t.default(i.toString()),new $t.default(r.toString()),new $t.default(t.toString()),64),u=te.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 Me(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}=ar(BigInt(e.oracle_price),BigInt(a.oracle_price),BigInt(e.coin_decimals),BigInt(a.coin_decimals)),d=te.checkMulDivFloor(new $t.default(u.toString()),new $t.default(o),new $t.default((BigInt(10)**Se).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:v}=e,S=[...n],P=o&&U(t.quote_type,!1),D=rt.tickIndexToSqrtPriceX64(d),B=rt.tickIndexToSqrtPriceX64(f),{coin_amount_a:x,coin_amount_b:A}=re.getCoinAmountFromLiquidity(new $t.default(m),new $t.default(_),new $t.default(D),new $t.default(B),!1);S.push({coin_type:g,value:x.toString()}),S.push({coin_type:v,value:A.toString()});let E={};S.forEach(W=>{let Q=U(W.coin_type,!1),J=k(W.value),Y=E[Q]||0;E[Q]=J.add(Y).toString()});let $=Object.entries(E).filter(([W,Q])=>k(Q).gt(0)).map(([W])=>W);if(P&&!$.includes(P)&&$.push(P),$.length===0)return"0";let I=await i.PythPrice.getLatestPrice($,r),Z={};return $.forEach(W=>{let Q=I[W];if(Q)Z[W]={price:Q,value:E[W]||"0"};else throw Error(`find ${W} price fail `)}),Me(Z,P).toString()}function Re(i,t,e){return k(i).eq(0)?t:k(i).mul(t).div(e).toFixed(0,li.default.ROUND_HALF_UP)}function ss(i,t,e){return k(i).eq(0)?"0":k(i).mul(t).div(e).toFixed(0,li.default.ROUND_HALF_UP)}function Pe(i,t,e){return k(i).eq(0)?"0":k(t).mul(e).div(i).toFixed(0,li.default.ROUND_HALF_UP)}function ke(i,t,e){let n={};return t.forEach(r=>{let a=Pe(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=Pe(e.lp_token_treasury,t,d),m=rt.tickIndexToSqrtPriceX64(r),_=rt.tickIndexToSqrtPriceX64(a),g=re.getCoinAmountFromLiquidity(new $t.default(f),new $t.default(n.current_sqrt_price),m,_,!0),v=g.coin_amount_a.toString(),S=g.coin_amount_b.toString(),P=ke(t,e.balances,e.lp_token_treasury),D=k(v).add(P[o]?.value||"0").toFixed(0),B=k(S).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:B,coin_type_a:o,coin_type_b:u}}function Ne(i,t,e){let n=[];return t.forEach(r=>{k(r.value).gt(0)&&n.push(r)}),e.forEach(r=>{k(r.value).gt(0)&&n.push(r)}),i.forEach(r=>{k(r.value).gt(0)&&n.push(r)}),n}function Ue(i,t,e){let n=new Set;return i.forEach(r=>n.add(r)),n.add(t),n.add(e),Array.from(n)}function Gi(i,t){if(!Se)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(t<0n){let e=10n**(Se- -t);return i*e}return i/10n**(t+Se)}function Hi(i){return`0x${Buffer.from(i).toString("hex")}`}function as(i,t,e,n,r){let a="0",o="0";return ci(i,"min",Number(e))?a="0":a=rt.tickIndexToPrice(Number(i),n,r).toString(),ci(t,"max",Number(e))?o="\u221E":o=rt.tickIndexToPrice(Number(t),n,r).toString(),{minPrice:a,maxPrice:o}}function ui(i){let t=ne(i),e=$i(i),n=ie(e),r=t.position.fields,a={id:r.id.id,pool_id:r.pool,index:r.index,liquidity:r.liquidity,tick_lower_index:ye(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:ye(BigInt(r.tick_upper_index.fields.bits)),coin_type_a:U(r.coin_type_a.fields.name,!1),coin_type_b:U(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:U(t.coin_a.fields.name,!1),coin_type_b:U(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=ne(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 cr=oe(require("decimal.js")),di=require("@mysten/sui/bcs"),fi=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:U(a.fields.name,!1),coin_type_b:U(o.fields.name,!1),vault_id:u,position_keys:d.fields.contents}}function cs(i){return{uri:i.uri,index:i.index,id:i.id.id,name:i.name,pool_id:i.pool_id,lower_bin_id:ye(BigInt(i.lower_bin_id.fields.bits)),upper_bin_id:ye(BigInt(i.upper_bin_id.fields.bits)),liquidity_shares:i.liquidity_shares,description:i.description,coin_type_a:U(i.coin_type_a,!1),coin_type_b:U(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:v,value:S}=g.fields;return{coin_type:U(v.fields.name,!1),value:S}}),o=cs(e.fields),u=o.lower_bin_id,d=o.liquidity_shares.map((g,v)=>({bin_id:u+v,liquidity:g})).filter(g=>k(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:v,quote_type:S}=t,P=(Number(n)&1)!==0,D=(Number(n)&2)!==0,{balances:B}=r.fields,x=B.fields.contents.map($=>{let{key:I,value:Z}=$.fields;return{coin_type:U(I.fields.name,!1),value:Z}}),A=S.fields.pos0.fields.name;return{id:d.id,lp_token_treasury:m.fields.total_supply.fields.value,hard_cap:u,quote_type:A?U(A,!1):void 0,protocol_fee_rate:g,buffer_assets:x,protocol_fees_handle:{id:v.fields.id.id,size:v.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:U(a.fields.name,!1),coin_type_b:U(o.fields.name,!1),lp_token_type:ie(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,v=r&&U(r,!1);u.push({coin_type:a,value:_.toString()}),u.push({coin_type:o,value:g.toString()});let S={};u.forEach(A=>{let E=U(A.coin_type,!1),$=k(A.value),I=S[E]||0;S[E]=$.add(I).toString()});let P=Object.entries(S).filter(([A,E])=>k(E).gt(0)).map(([A])=>A);if(v&&!P.includes(v)&&P.push(v),P.length===0)return"0";let D=await i.VaultsV2.PythPrice.getLatestPrice(P,n),B={};return P.forEach(A=>{let E=D[A];if(E)B[A]={price:E,value:S[A]||"0"};else throw Error(`find ${A} price fail `)}),Me(B,v).toString()}async function hi(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:v}=m.position,{receive_amount_a:S,receive_amount_b:P,valid_lower_bin_id:D,valid_upper_bin_id:B,bin_infos:x,position_coin_amount_a:A,position_coin_amount_b:E}=await $e(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:v,valid_lower_bin_id:D,valid_upper_bin_id:B,original_lower_bin_id:_,original_upper_bin_id:g,amount_a:S,amount_b:P,position_amount_a:A,position_amount_b:E,coin_type_a:a,coin_type_b:o,bin_infos:x}}async function $e(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,v=await i.CetusDlmmSDK.Pool.getBinInfo(m.bin_manager_handle,g,_,!1),S=k(t).div(a),P=(0,Ji.parseLiquidityShares)(d.position.liquidity_shares.map(R=>k(R.toString()).mul(S).toFixed(0,cr.default.ROUND_HALF_UP).toString()),_,f,v),D=P.amount_a,B=P.amount_b,x=ke(t,e.buffer_assets,a),A=x[o]?.value||"0",E=x[u]?.value||"0",$=k(D.toString()).add(A).toFixed(0),I=k(B.toString()).add(E).toFixed(0),Z=P.bins.filter(R=>k(R.liquidity).gt(0));return{valid_lower_bin_id:Z.length>0?Z[0].bin_id:P.bins[0].bin_id,valid_upper_bin_id:Z.length>0?Z[Z.length-1].bin_id:P.bins[P.bins.length-1].bin_id,receive_amount_a:$,receive_amount_b:I,position_coin_amount_a:D,position_coin_amount_b:B,bin_infos:{bins:Z,amount_a:P.amount_a,amount_b:P.amount_b}}}function rn(i){let t=di.bcs.vector(di.bcs.u8()).serialize(new TextEncoder().encode("DLMM_MARKET")).toBytes();return(0,fi.deriveObjectID)(i,"vector<u8>",t)}function ls(i,t){let e=di.bcs.Address.serialize(t).toBytes();return(0,fi.deriveDynamicFieldID)(i,"0x2::object::ID",e)}function Ke(i,t,e,n){let r=k(i),a=k(e),o=k(n),u=r,d=t?r:k(0),f=t?k(0):r,m=o,_=k(o).mul(.999),g=k(0),v=u,S=null;function P(x){if(t){let A=d.minus(x),E=f.plus(x.mul(a));return{A,B:E,R:E.div(A)}}else{let A=d.plus(x.mul(a)),E=f.minus(x);return{A,B:E,R:A.div(E)}}}for(let x=0;x<120;x++){let A=g.plus(v).div(2),{A:E,B:$,R:I}=P(A);if(E.lte(0)||$.lte(0)){v=A;continue}if(I.gt(m))v=A;else if(I.lt(_))g=A;else{if(S=A,k(_).eq(0))break;v=A}}if(!S)return{swap_amount:"0",final_amount_a:d.toFixed(0),final_amount_b:f.toFixed(0)};let{A:D,B}=P(S);return{swap_amount:S.toFixed(0),final_amount_a:D.toFixed(0),final_amount_b:B.toFixed(0),best:S.toString()}}var Be=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:"0xc2e2473f27a8c3f6bc398c181c3fe95a23847d53fa89cdf1339bb24086120f58",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 he(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 he(cn)}var lr=(e=>(e.mainnet="mainnet",e.testnet="testnet",e))(lr||{});function us(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 ur(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 ds=16*1024,Ae=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 Be.SuiPriceServiceConnection(g),this.suiPythClient=new Be.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()};ur(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)))?.parsed?.forEach((u,d)=>{if(u){let{price:f,expo:m,publish_time:_}=u.price,g=k(f).mul(k(10).pow(k(m))).toString(),v=a[d],S={coin_type:v.coin_type,price:g,coin_decimals:v.coin_decimals,oracle_price:0n,last_update_time:_};S.oracle_price=Gi(BigInt(f),BigInt(m)),n[r[d]]=S,this._sdk.updateCache(`getLatestPrice_${S.coin_type}`,S)}}),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 Be.SuiPriceServiceConnection(n);try{return await this.connection.getPriceFeedsUpdateData(t)}catch(r){this.recordError(r,t,"getPriceFeedsUpdateData")}}}}async getLatestPriceFeeds(t){try{return await this.connection.getLatestPriceUpdates(t,{parsed:!0})}catch(e){this.recordError(e,t,"getLatestPriceFeeds");let{secondary:n}=this.pythConfigs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Be.SuiPriceServiceConnection(n);try{return await this.connection.getLatestPriceUpdates(t,{parsed:!0})}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:ds}).toBytes()),f[0],e.object(Zt)]}),_=0;for(let g of o){let v=await this.suiPythClient.getPriceFeedObjectId(g);if(!v)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(v),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(v),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=U(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:U(t,!0)}}),{fields:u}=o.data.content.fields.value,d={coin_type:t,price_feed_id:Hi(u.price_feed_id),coin_decimals:u.coin_decimals};return this._sdk.updateCache(n,d),d}};var We=class{_sdk;pythPrice;constructor(t){this._sdk=t;let{vaults:e,pythConfigs:n}=t.sdkOptions;this.pythPrice=new Ae(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 Ee.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...d.map(x=>x.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 v=await this._sdk.FullClient.sendSimulationTransaction(g,(0,fr.normalizeSuiAddress)("0x0")),S=`${e}::pool::FeeClaimedEvent`,P=`${e}::pool::RewardClaimedEvent`,D=[],B=[];return v?.events.forEach(x=>{let{parsedJson:A,type:E}=x;E===S&&(D.push({coin_type:U(m,!1),value:A.amount_a}),D.push({coin_type:U(_,!1),value:A.amount_b})),E===P&&B.push({coin_type:U(A.reward_type.name,!1),value:A.amount})}),this._sdk.updateCache(a,{feeList:D,rewarderList:B},10*1e3),{feeList:D,rewarderList:B}}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=je(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 getAssignPoolList(t){if(t.length===0)return[];let e=[],n=await this._sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let r of n){let a=je(r.data.content);this._sdk.updateCache(`getPool_${a.id}`,a),e.push(a)}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._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),o=je(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 Ee.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 Ee.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,re_balance:u}=t,{pool:d,clmmPool:f}=await this.getVaultAndPool(n,!0),{lp_token_type:m}=d,{rewarder_infos:_,id:g,coin_type_a:v,coin_type_b:S}=f,P=_.map(Z=>U(Z.coin_type,!1)),D=Ue(P,f.coin_type_a,f.coin_type_b),{published_at:B,configs:x,clmm_configs:A}=this._sdk.sdkOptions.vaults;e=e||new Ee.Transaction,e=this.buildCollectRewardPayload({reward_coin_types:P,lp_token_type:m,pool_id:n,clmm_pool_id:g,coin_type_a:v,coin_type_b:S},e),e=this.buildCollectFeePayload({lp_token_type:m,pool_id:n,clmm_pool_id:g,coin_type_a:v,coin_type_b:S},e),e=await this.pythPrice.buildUpdatePythPricePayload(D,e),e.moveCall({target:`${B}::pool::calculate_aum`,typeArguments:[v,S,m],arguments:[e.object(n),e.object(x.global_config_id),e.object(x.pyth_oracle_id),e.object(A.global_config_id),e.object(g),e.object(Zt)]});let E,$;if(u&&u.swap_result){let{swap_result:Z,coin_amount:R,mode:W,swap_slippage:Q}=u,{swap_in_amount:J,swap_out_amount:Y,route_obj:X}=Z,H=zt.buildCoinWithBalance(BigInt(R),W==="OnlyCoinA"?v:S,e),s=e.splitCoins(H,[J]),l={router:X,slippage:Q,txb:e,inputCoin:s},h=await this._sdk.AggregatorClient.fixableRouterSwapV3(l);E=W==="OnlyCoinA"?H:h,$=W==="OnlyCoinA"?h:H}else E=zt.buildCoinWithBalance(BigInt(r),v,e),$=zt.buildCoinWithBalance(BigInt(a),S,e);let I=e.moveCall({target:`${B}::pool::${o?"deposit_for":"deposit"}`,typeArguments:[v,S,m],arguments:[e.object(n),e.object(x.global_config_id),e.object(x.pyth_oracle_id),e.object(A.global_config_id),e.object(g),E,$,e.object(Zt)]});return o?I: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:v}=this._sdk.sdkOptions.vaults;e=e||new Ee.Transaction;let{lp_token_type:S,clmm_vault:P,lp_token_treasury:D}=f,{rewarder_infos:B,id:x,coin_type_a:A,coin_type_b:E,liquidity:$}=m,I=B.map(H=>U(H.coin_type,!1));e=this.buildCollectRewardPayload({reward_coin_types:I,lp_token_type:S,pool_id:n,clmm_pool_id:x,coin_type_a:A,coin_type_b:E},e),e=this.buildCollectFeePayload({lp_token_type:S,pool_id:n,clmm_pool_id:x,coin_type_a:A,coin_type_b:E},e);let Z=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress),R,W=d?k(d.burn_lp_amount).add(k(r)).toFixed(0):k(r).toFixed(0),Q=k(r).isZero();if(Q&&!d)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");Q?R=d.lp_burn_coin:(R=zt.buildCoinForAmount(e,Z,BigInt(r),S,!1,!0).target_coin,d&&e.mergeCoins(R,[d.lp_burn_coin]));let[J,Y,X]=e.moveCall({target:`${_}::pool::withdraw`,typeArguments:[A,E,S],arguments:[e.object(n),e.object(g.global_config_id),e.object(v.global_config_id),e.object(x),R,e.object(Zt)]});if(this.buildWithdrawBufferReward({reward_coin_types:I.filter(H=>![U(A,!1),U(E,!1)].includes(H)),pool_id:n,withdraw_cert:X,lp_token_type:S},e,Z),e.moveCall({target:`${_}::pool::destory_withdraw_cert`,typeArguments:[S],arguments:[e.object(n),e.object(g.global_config_id),X]}),a!=="FixedOneSide"){if(o===void 0)throw Error("the slippage is undefined");let H=a==="OnlyCoinA",s=H?Y:J,l=Pe(D,W,$.toString());await this.handleWithSwap(e,s,A,E,W,n,H,o,u,[{poolID:x,ticklower:P.wrapped_position.tick_lower_index,tickUpper:P.wrapped_position.tick_upper_index,deltaLiquidity:Number(l)}]),e.transferObjects([H?J:Y],this._sdk.senderAddress)}else e.transferObjects([J,Y],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}),v=u?r:n,S=u?n:r,P=u?g:_;if(k(P).isZero()){t.transferObjects([e],t.pure.address(this._sdk.getVerifySenderAddress()));return}let D={from:v,target:S,amount:new Ht.default(P),byAmountIn:!0,depth:3,splitAlgorithm:void 0,splitFactor:void 0,splitCount:void 0,providers:this._sdk.sdkOptions.providers,liquidityChanges:m},B=await this._sdk.AggregatorClient.findRouters(D);if(!B)throw Error("not find Router");if(B.error!==void 0)throw Error(`find Router error : ${B.error}`);let x={router:B,inputCoin:e,slippage:d,txb:t,partner:f},A=await this._sdk.AggregatorClient.fixableRouterSwapV3(x);t.transferObjects([A],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]}),_=zt.getCoinAssets(f,o),g=zt.selectCoinAssetGreaterThanOrEqual(_,BigInt(0));if(g.selected_coins.length>0&&!zt.isSuiCoin(f))a.mergeCoins(g.selected_coins[0].coin_object_id,[m]);else{let v=zt.buildCoinForAmount(a,o,BigInt(0),f,!1,!1);a.mergeCoins(v.target_coin,[m]),a.transferObjects([v.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:v}=u.clmm_vault.wrapped_position,S="0",P="0",D=await this.pythPrice.getLatestPrice([g,v],!0),B=D[g],x=D[v];if(!B||!x)throw new Error("get coin price failed");switch(a){case"FixedOneSide":{let{amountA:A,amountB:E}=Zi(m,_,new Ht.default(f),n,B.price,x.price,B.coin_decimals,x.coin_decimals);S=A.toString(),P=E.toString();break}case"FlexibleBoth":{let{amountA:A,amountB:E}=ue(k(.5),k(.5),n,B.price,x.price,B.coin_decimals,x.coin_decimals);S=A.toString(),P=E.toString();break}case"OnlyCoinA":{let{amountA:A,amountB:E}=ue(k(1),k(0),n,B.price,x.price,B.coin_decimals,x.coin_decimals);S=A.toString(),P=E.toString();break}case"OnlyCoinB":{let{amountA:A,amountB:E}=ue(k(0),k(1),n,B.price,x.price,B.coin_decimals,x.coin_decimals);S=A.toString(),P=E.toString();break}default:throw new Error(`Unsupported deposit mode: ${a}`)}return e&&this.calculateDepositLpAmountBoth(u,d,S,P).then(A=>{e.onSuccess(A,o)}).catch(A=>{e.onError(A,o)}),{deposit_amount_a:S,deposit_amount_b:P,mode:a}}async calculateBalanceSwapAmount(t){let{mode:e,pool_id:n}=t;if(e==="OnlyCoinA"||e==="OnlyCoinB"){let{pool:r,clmmPool:a}=await this.getVaultAndPool(n,!1),{clmm_vault:o}=r,{current_sqrt_price:u,coin_type_a:d,coin_type_b:f}=a,m=o.wrapped_position.tick_lower_index,_=o.wrapped_position.tick_upper_index,g=e==="OnlyCoinA"?t.coin_amount_a:t.coin_amount_b,v=e==="OnlyCoinA",S=re.estLiquidityAndCoinAmountFromOneAmounts(m,_,new Ht.default(g),v,!0,1,new Ht.default(u)),P=v?k(S.coin_amount_b).div(S.coin_amount_a):k(S.coin_amount_a).div(S.coin_amount_b),D=v?k(u).toString():k(1).div(k(u)).toString();try{let I=await this._sdk.VaultsV2.findRouters(v?d:f,v?f:d,g);I&&(D=k(I.swap_out_amount).div(I.swap_in_amount).toString())}catch{}let{swap_amount:B}=Ke(g,v,D.toString(),P.toString()),x=k(g).sub(B).toFixed(0),A=await this._sdk.VaultsV2.findRouters(v?d:f,v?f:d,B),E=k(A.swap_out_amount).mul(.999).toFixed(0),$=re.estLiquidityAndCoinAmountFromOneAmounts(m,_,new Ht.default(x),v,!0,1,new Ht.default(u));return v?$.coin_amount_b=E:$.coin_amount_a=E,{swap_result:A,liquidity_info:$}}throw new Error(`calculateBalanceSwapAmount Unsupported deposit mode: ${e}`)}async preCalculateDepositAmount(t,e){let{mode:n,pool_id:r,uuid:a}=t,o="0",u="0",d,f,{pool:m,clmmPool:_}=await this.getVaultAndPool(r,!1);switch(n){case"FixedOneSide":{let{fixed_amount:g,fixed_coin_a:v}=t,{other_amount:S,lp_amount:P}=await this.calculateDepositOtherSide(m,_,g,v,e,a);f=P,v?(o=g,u=S):(u=g,o=S);break}case"FlexibleBoth":{let{coin_amount_a:g,coin_amount_b:v}=t;o=g,u=v;break}case"OnlyCoinA":{if(t.re_balance){let g=await this.calculateBalanceSwapAmount(t),{swap_result:v,liquidity_info:S}=g,{coin_amount_a:P,coin_amount_b:D}=S;o=P,u=D,d={swap_result:v,coin_amount:t.coin_amount_a}}else o=t.coin_amount_a;break}case"OnlyCoinB":{if(t.re_balance){let g=await this.calculateBalanceSwapAmount(t),{swap_result:v,liquidity_info:S}=g,{coin_amount_a:P,coin_amount_b:D}=S;o=P,u=D,d={swap_result:v,coin_amount:t.coin_amount_b}}else u=t.coin_amount_b;break}default:throw new Error(`Unsupported deposit mode: ${n}`)}return e?this.calculateDepositLpAmountBoth(m,_,o,u).then(g=>{e?.onSuccess(g,a)}).catch(g=>{e?.onError(g,a)}):f=await this.calculateDepositLpAmountBoth(m,_,o,u),{deposit_amount_a:o,deposit_amount_b:u,mode:n,re_balance:d,lp_amount:f}}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}}async 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,_=re.estLiquidityAndCoinAmountFromOneAmounts(f,m,new Ht.default(n),r,!0,1,new Ht.default(d)),{coin_amount_a:g,coin_amount_b:v}=_;if(a)this.calculateDepositLpAmountBoth(t,e,g.toString(),v.toString()).then(S=>{a.onSuccess(S,o)}).catch(S=>{a.onError(S,o)});else{let S=await this.calculateDepositLpAmountBoth(t,e,g.toString(),v.toString());return{other_amount:r?v.toString():g.toString(),lp_amount:S}}return{other_amount:r?v.toString():g.toString(),lp_amount:void 0}}async calculateDepositLpAmountBoth(t,e,n,r){let{lp_token_treasury:a,hard_cap:o}=t,u=U(e.coin_type_a,!1),d=U(e.coin_type_b,!1),{rewarderList:f,feeList:m}=await this.getVaultsPositionRewarderAndFee(t.id),_=Ne(t.balances,m,f),g=await zi(this,t,e,_,!0),v=await this.pythPrice.getLatestPrice([u,d],!0),S=v[u],P=v[d];if(!S)throw Error(`not find ${u} price`);if(!P)throw Error(`not find ${d} price`);let D={};D[u]={price:S,value:n.toString()},D[d]={price:P,value:r.toString()};let B=Me(D,t.quote_type);return Re(a,B,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=rt.tickIndexToSqrtPriceX64(f),v=rt.tickIndexToSqrtPriceX64(m),S=Pe(a,n,_),{coin_amount_a:P,coin_amount_b:D}=re.getCoinAmountFromLiquidity(new Ht.default(S),new Ht.default(o),g,v,!1),B=ke(n,t.balances,a),x=k(P.toString()).add(B[u]?.value||"0").toFixed(0),A=k(D.toString()).add(B[d]?.value||"0").toFixed(0);return{receive_amount_a:x,receive_amount_b:A,burn_lp_amount:n,mode:"FixedOneSide",remove_liquidity:S}}async calculateWithdrawOnlyCoin(t,e,n,r){let{totalReceiveAmount:a,swapAmountIn:o,swapAmountOut:u,removeLiquidity:d,remove_amount_a:f,remove_amount_b:m}=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,remove_amount_a:f,remove_amount_b:m},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,v=rt.tickIndexToSqrtPriceX64(m),S=rt.tickIndexToSqrtPriceX64(_),P=Pe(o,r,g),{coin_amount_a:D,coin_amount_b:B}=re.getCoinAmountFromLiquidity(new Ht.default(P),new Ht.default(u),v,S,!1),x=await this.pythPrice.getLatestPrice([d,f],!0),A=x[d],E=x[f];if(!A)throw Error(`not find ${d} price`);if(!E)throw Error(`not find ${f} price`);let $=n?E:A,I=n?A:E,{quote_per_base:Z}=qe($.price,I.price),R=ke(r,t.balances,o),W=k(D.toString()).add(R[d]?.value||"0").toFixed(0),Q=k(B.toString()).add(R[f]?.value||"0").toFixed(0),J=n?W:Q,Y=n?Q:W,X=ce(k(be(Y,n?E.coin_decimals:A.coin_decimals)).mul(Z).toString(),n?A.coin_decimals:E.coin_decimals).toString(),H=k(J).add(X).toFixed(0);return{remove_amount_a:W,remove_amount_b:Q,burn_lp_amount:r,removeLiquidity:P,is_coin_a:n,originAmount:J,swapAmountIn:Y,swapAmountOut:k(X).toFixed(0,hr.default.ROUND_DOWN),totalReceiveAmount:H}}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=ai(n);(await this._sdk.FullClient.queryEventsByPage({Transaction:r})).data.forEach(m=>{let _=m.parsedJson;if(m.type)switch((0,dr.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=ne(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=ne(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 mr=require("@mysten/sui/transactions");var Ze=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!ne(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:U(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=ui(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=ui(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 mr.Transaction;for(let d of t){let{vault_id:f,vesting_nft_id:m,period:_,coin_type_a:g,coin_type_b:v}=d,S=await this.getVaultVestEvent(f);e.moveCall({package:n.published_at,module:"hae_vester",function:"redeem_coin",arguments:[e.object(a),e.object(S.vault_vester_id),e.object(m),e.object(o),e.object(u),e.object(S.pool_id),e.pure.u16(_),e.object(Zt)],typeArguments:[g,v]})}return e}};var hn=require("@mysten/sui/transactions"),mn=oe(require("bn.js")),pr=require("@cetusprotocol/aggregator-sdk");var _r=require("@mysten/sui/utils"),gr=oe(require("decimal.js"));var Qt=require("@cetusprotocol/dlmm-sdk");var ze=class{_sdk;pythPrice;constructor(t){this._sdk=t;let{vaultsV2:e,pythConfigs:n}=t.sdkOptions;this.pythPrice=new Ae(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 hi(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,v=new hn.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...f.rewards.map(B=>B.reward_coin)],lp_token_type:d,pool_id:t,certified_pool_id:m,position_id:e,coin_type_a:_,coin_type_b:g},v),n&&this.buildCollectFeePayload({lp_token_type:d,pool_id:t,certified_pool_id:m,position_id:e,coin_type_a:_,coin_type_b:g},v);let S=await this._sdk.FullClient.sendSimulationTransaction(v,(0,_r.normalizeSuiAddress)("0x0")),P=[],D=[];return S?.events.forEach(B=>{let{parsedJson:x,type:A}=B;A.includes("CollectDlmmFeeEvent")&&(P.push({coin_type:U(_,!1),value:x.amount_a}),P.push({coin_type:U(g,!1),value:x.amount_b})),A.includes("CollectDlmmRewardEvent")&&D.push({coin_type:U(x.reward_type.name,!1),value:x.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:v}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:S,global_config_id:P}=ve(v);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(S),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(S),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:v,global_config_id:S}=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(S),e.object(v),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(S),e.object(v),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,re_balance:f}=t,{pool:m,dlmmPool:_}=await this.getVaultAndPool(a,!1),{coin_type_a:g,coin_type_b:v,markets:S,lp_token_type:P}=m,{reward_manager:D,id:B}=_,x=S[0].position_list[0].position.id,A=D.rewards.map(Q=>U(Q.reward_coin,!1)),E=Ue(A,g,v);this.buildCollectRewardPayload({reward_coin_types:A,lp_token_type:P,pool_id:a,certified_pool_id:S[0].position_list[0].position.pool_id,position_id:x,coin_type_a:g,coin_type_b:v},e),await this.pythPrice.buildUpdatePythPricePayload(E,e);let{dlmm_pool:$}=this._sdk.CetusDlmmSDK.sdkOptions,{versioned_id:I}=ve($);e.moveCall({target:`${n}::vault::calculate_dlmm_position_amounts`,typeArguments:[g,v,P],arguments:[e.object(a),e.object(r.pyth_oracle_id),e.object(B),e.object(x),e.object(I),e.object(r.versioned_id),e.object(Zt)]}),e.moveCall({target:`${n}::vault::calculate_aum`,typeArguments:[P],arguments:[e.object(a),e.object(r.pyth_oracle_id),e.object(r.versioned_id),e.object(Zt)]});let Z,R;if(f&&f.swap_result){let{swap_result:Q,coin_amount:J,mode:Y,swap_slippage:X}=f,{swap_in_amount:H,swap_out_amount:s,route_obj:l}=Q,h=zt.buildCoinWithBalance(BigInt(J),Y==="OnlyCoinA"?g:v,e),p=e.splitCoins(h,[H]),b={router:l,slippage:X,txb:e,inputCoin:p},M=await this._sdk.AggregatorClient.fixableRouterSwapV3(b);Z=Y==="OnlyCoinA"?h:M,R=Y==="OnlyCoinA"?M:h}else Z=zt.buildCoinWithBalance(BigInt(o),g,e),R=zt.buildCoinWithBalance(BigInt(u),v,e);let W=e.moveCall({target:`${n}::vault::deposit`,typeArguments:[g,v,P],arguments:[e.object(a),e.object(r.global_config_id),e.object(r.pyth_oracle_id),Z,R,e.object(Zt),e.object(r.versioned_id)]});if(d)return W;e.transferObjects([W],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:v,markets:S}=f,{id:P,reward_manager:D}=m,B=S[0].position_list[0].position.id;e=e||new hn.Transaction;let x,A=d?k(d.burn_lp_amount).add(k(r)).toFixed(0):k(r).toFixed(0),E=k(r).isZero();if(E&&!d)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");E?x=d.lp_burn_coin:(x=zt.buildCoinWithBalance(BigInt(r),_,e),d&&d.lp_burn_coin&&e.mergeCoins(x,[d.lp_burn_coin]));let{published_at:$,configs:I}=this._sdk.sdkOptions.vaultsV2,{config:Z}=this._sdk.CetusDlmmSDK.sdkOptions.dlmm_pool,R=e.moveCall({target:`${$}::vault::new_withdraw_cert`,typeArguments:[_],arguments:[e.object(n),x,e.object(I.versioned_id)]});e.moveCall({target:`${$}::vault::withdraw_dlmm`,typeArguments:[g,v,_],arguments:[e.object(n),R,e.object(P),e.object(B),e.object(Z.global_config_id),e.object(Z.versioned_id),e.object(I.versioned_id),e.object(Zt)]});let W=D.rewards.map(H=>U(H.reward_coin,!1));this.buildCollectRewardPayload({reward_coin_types:W,lp_token_type:_,pool_id:n,certified_pool_id:S[0].position_list[0].position.pool_id,position_id:B,coin_type_a:g,coin_type_b:v,withdraw_cert:R},e),this.buildCollectFeePayload({lp_token_type:_,pool_id:n,certified_pool_id:S[0].position_list[0].position.pool_id,position_id:B,coin_type_a:g,coin_type_b:v,withdraw_cert:R},e),e.moveCall({target:`${$}::vault::finalize_buffer_assets`,typeArguments:[_],arguments:[e.object(n),R,e.object(I.versioned_id)]});let Q=new Set;W.forEach(H=>Q.add(H)),Q.add(g),Q.add(v);let J=Array.from(Q),Y=a!=="FixedOneSide"?[a==="OnlyCoinA"?v:g]:[],X=this.buildWithdrawBufferReward({reward_coin_types:J,pool_id:n,withdraw_cert:R,lp_token_type:_,not_transfer_coin_types:Y},e);if(e.moveCall({target:`${$}::vault::destroy_withdraw_cert`,typeArguments:[_],arguments:[e.object(n),R,e.object(I.versioned_id)]}),a!=="FixedOneSide"){if(o===void 0)throw Error("the slippage is undefined");let H=a==="OnlyCoinA",s=H?v:g,l=X.find(h=>h.coin_type===s).reward_coin_object_id;await this.handleWithSwap(e,l,g,v,A,n,H,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,v=u?n:r,S=u?_:m;if(k(S).isZero()){t.transferObjects([e],t.pure.address(this._sdk.getVerifySenderAddress()));return}let P={from:g,target:v,amount:new mn.default(S),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 B={router:D,inputCoin:e,slippage:d,txb:t,partner:f},x=await this._sdk.AggregatorClient.fixableRouterSwapV3(B);t.transferObjects([x],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,re_balance:u}=t,{pool:d,dlmmPool:f}=await this.getVaultAndPool(r,!1),{coin_type_a:m,coin_type_b:_}=d,g=await this.pythPrice.getLatestPrice([m,_],!0),v=g[m],S=g[_];if(!v)throw new Error(`get ${m} price failed`);if(!S)throw new Error(`get ${_} price failed`);let P="0",D="0";switch(a){case"FlexibleBoth":{let{position_amount_a_rate:x,position_amount_b_rate:A}=await this.calculatePositionValueRates(d,f,g),{amountA:E,amountB:$}=ue(x,A,n,v.price,S.price,v.coin_decimals,S.coin_decimals);P=E,D=$;break}case"OnlyCoinA":{let{amountA:x,amountB:A}=ue(k(1),k(0),n,v.price,S.price,v.coin_decimals,S.coin_decimals);P=x,D=A;break}case"OnlyCoinB":{let{amountA:x,amountB:A}=ue(k(0),k(1),n,v.price,S.price,v.coin_decimals,S.coin_decimals);P=x,D=A;break}}return await this.preCalculateDepositAmount({mode:a,pool_id:r,uuid:o,coin_amount_a:P,coin_amount_b:D,re_balance:u},e)}async calculateBalanceSwapAmount(t){let{mode:e,pool_id:n}=t;if(e==="OnlyCoinA"||e==="OnlyCoinB"){let{pool:r,dlmmPool:a}=await this.getVaultAndPool(n,!1),o=await this._sdk.CetusDlmmSDK.Pool.getBinInfo(a.bin_manager.bin_manager_handle,a.active_id,a.bin_step,!1),{active_id:u,bin_step:d}=a,f=Qt.BinUtils.getPricePerLamportFromBinId(a.active_id,a.bin_step),m=k(f).mul(1-.05),_=k(f).mul(1+.05),g=Qt.BinUtils.getBinIdFromLamportPrice(m.toString(),a.bin_step,!1),v=Qt.BinUtils.getBinIdFromLamportPrice(_.toString(),a.bin_step,!1),S=e==="OnlyCoinA"?t.coin_amount_a:t.coin_amount_b,P=e==="OnlyCoinA",D=await this._sdk.CetusDlmmSDK.Position.calculateAddLiquidityInfo({pool_id:a.id,coin_amount:S,fix_amount_a:P,active_id:u,bin_step:d,lower_bin_id:g,upper_bin_id:v,active_bin_of_pool:o,strategy_type:Qt.StrategyType.Spot}),B=P?k(D.amount_b).div(D.amount_a):k(D.amount_a).div(D.amount_b),x=P?Qt.BinUtils.getPricePerLamportFromBinId(u,d):k(1).div(Qt.BinUtils.getPricePerLamportFromBinId(u,d)).toString();try{let Y=await this.findRouters(P?r.coin_type_a:r.coin_type_b,P?r.coin_type_b:r.coin_type_a,S);Y&&(x=k(Y.swap_out_amount).div(Y.swap_in_amount).toString())}catch{}let{swap_amount:A,final_amount_a:E,final_amount_b:$}=Ke(S,P,x,B.toString()),I=k(S).sub(A).toFixed(0),Z=await this.findRouters(P?r.coin_type_a:r.coin_type_b,P?r.coin_type_b:r.coin_type_a,A),R=k(Z.swap_out_amount).mul(.999).toFixed(0),W=P?I:R,Q=P?R:I,J=await this._sdk.CetusDlmmSDK.Position.calculateAddLiquidityInfo({pool_id:a.id,amount_a:W,amount_b:Q,active_id:u,bin_step:d,lower_bin_id:g,upper_bin_id:v,active_bin_of_pool:o,strategy_type:Qt.StrategyType.Spot});return P?J.amount_b=Z.swap_out_amount:J.amount_a=Z.swap_out_amount,{swap_result:Z,liquidity_info:J}}throw new Error(`calculateBalanceSwapAmount Unsupported deposit mode: ${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,re_balance:f}=t;if(f){let m=await this.calculateBalanceSwapAmount(t),{swap_result:_,liquidity_info:g}=m,{amount_a:v,amount_b:S}=g,P=await this.calculateDepositFlexibleBoth(o,u,v,S,e,a);return P.re_balance={swap_result:_,coin_amount:d,mode:"OnlyCoinA"},P}else return await this.calculateDepositFlexibleBoth(o,u,d,"0",e,a)}case"OnlyCoinB":{let{coin_amount_b:d,re_balance:f}=t;if(f){let m=await this.calculateBalanceSwapAmount(t),{swap_result:_,liquidity_info:g}=m,{amount_a:v,amount_b:S}=g,P=await this.calculateDepositFlexibleBoth(o,u,v,S,e,a);return P.re_balance={swap_result:_,coin_amount:d,mode:"OnlyCoinB"},P}else 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(k(r).eq(0))return{position_amount_a_rate:k(.5),position_amount_b_rate:k(.5)};let{position_amount_a:u,position_amount_b:d}=await hi(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 _=k(be(u,f.coin_decimals)).mul(f.price),g=k(be(d,m.coin_decimals)).mul(m.price),v=k(_).add(g),S=k(_).div(v),P=k(1).sub(S);return{position_amount_a_rate:S,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=Qt.BinUtils.getPricePerLamportFromBinId(e.active_id,e.bin_step),f=k(d).mul(1-.05),m=k(d).mul(1+.05),_=Qt.BinUtils.getBinIdFromLamportPrice(f.toString(),e.bin_step,!1),g=Qt.BinUtils.getBinIdFromLamportPrice(m.toString(),e.bin_step,!1),v={pool_id:o.pool_id,coin_amount:k(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:Qt.StrategyType.Spot,active_bin_of_pool:u},S=await this._sdk.CetusDlmmSDK.Position.calculateAddLiquidityInfo(v),{amount_a:P,amount_b:D}=S;return{deposit_amount_a:k(P).div(1e5).toFixed(0),deposit_amount_b:k(D).div(1e5).toFixed(0)}}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=U(u,!1),m=U(d,!1),{rewarderList:_,feeList:g}=await this.getVaultsPositionRewarderAndFee(t.id,a[0].position_list[0].position.id),v=Ne(t.buffer_assets,g,_),S=await nn(this._sdk,t,v,!0),P=await this.pythPrice.getLatestPrice([f,m],!0),D=P[f],B=P[m];if(!D)throw Error(`not find ${f} price`);if(!B)throw Error(`not find ${m} price`);let x={};x[f]={price:D,value:e.toString()},x[m]={price:B,value:n.toString()};let A=Me(x,o);return Re(r,A,S)}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 $e(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,remove_amount_a:d,remove_amount_b:f}=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,remove_amount_a:d,remove_amount_b:f},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 $e(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,v=n?m:_,{quote_per_base:S}=qe(g.price,v.price),P=n?u:d,D=n?d:u,B=ce(k(be(D,n?_.coin_decimals:m.coin_decimals)).mul(S).toString(),n?m.coin_decimals:_.coin_decimals).toString(),x=k(P).add(B).toFixed(0);return{remove_amount_a:u,remove_amount_b:d,burn_lp_amount:r,is_coin_a:n,originAmount:P,swapAmountIn:D,swapAmountOut:k(B).toFixed(0,gr.default.ROUND_DOWN),totalReceiveAmount:x}}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=ai(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=ne(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=ne(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}async findRouters(t,e,n){let{providers:r}=this._sdk.sdkOptions,a=this._sdk.AggregatorClient;if(k(n).lt(1))throw new Error("Swap amount is less than the minimum precision");try{let o={from:t,target:e,amount:new mn.default(n),byAmountIn:!0,depth:3,providers:r},u=await a.findRouters(o);if(u?.error)throw new Error(`Aggregator findRouters error: ${u?.error}`);if(!u?.paths||u?.paths?.length===0)throw new Error("Aggregator findRouters error: no router");let d=u.amountIn.toString(),f=u.amountOut.toString();return{swap_in_amount:d,swap_out_amount:f,route_obj:u}}catch(o){throw new Error(`Aggregator findRouters error: ${o}`)}}};var wr=oe(require("@cetusprotocol/dlmm-sdk")),he=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"?pn.CetusClmmSDK.createSDK({env:"testnet",full_rpc_url:t.fullRpcUrl}):pn.CetusClmmSDK.createSDK({env:"mainnet",full_rpc_url:t.fullRpcUrl}),this._cetusDlmmSDK=wr.default.createSDK({env:t.env,full_rpc_url:t.fullRpcUrl}),this._vaults=new We(this),this._vaultsV2=new ze(this);let{primary:e,secondary:n}=t.pythConfigs.hermes_service_urls,r=[e,n].filter(Boolean);this._aggregatorClient=new Xe.AggregatorClient({endpoint:t.aggregatorUrl,signer:(0,mi.normalizeSuiAddress)("0x0"),client:new br.SuiClient({url:t.fullRpcUrl}),env:t.env==="testnet"?Xe.Env.Testnet:Xe.Env.Mainnet,pythUrls:r}),this._vest=new Ze(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=Kn){this.CetusClmmSDK.updateCache(t,e,n)}getCache(t,e=!1){return this.CetusClmmSDK.getCache(t,e)}};var fs=he;0&&(module.exports={PythPriceModule,SdkEnv,VaultsModule,VaultsModuleV2,VestModule,VolatileVaultsSDK,buildDLMMMarket,buildDLMMMarketId,buildDLMMMarketPosition,buildDLMMPositionId,buildPoolData,buildPoolV2Data,buildVaultsBalance,buildVaultsBalanceV2,calcExactSwapAmount,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: