haedal-vault-sdk 1.4.0 → 1.5.0
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 +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var tr=Object.create;var qe=Object.defineProperty;var er=Object.getOwnPropertyDescriptor;var ir=Object.getOwnPropertyNames;var nr=Object.getPrototypeOf,rr=Object.prototype.hasOwnProperty;var or=(i,t)=>{for(var e in t)qe(i,e,{get:t[e],enumerable:!0})},_n=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ir(t))!rr.call(i,r)&&r!==e&&qe(i,r,{get:()=>t[r],enumerable:!(n=er(t,r))||n.enumerable});return i};var we=(i,t,e)=>(e=i!=null?tr(nr(i)):{},_n(t||!i||!i.__esModule?qe(e,"default",{value:i,enumerable:!0}):e,i)),sr=i=>_n(qe({},"__esModule",{value:!0}),i);var Uo={};or(Uo,{PythPriceModule:()=>Fe,SdkEnv:()=>Gn,VaultsModule:()=>Ne,VestModule:()=>Be,VolatileVaultsSDK:()=>ce,buildPoolData:()=>Qe,buildVaultsBalance:()=>Ri,calculateAum:()=>qi,calculateDepositRatioFixTokenA:()=>Zn,calculateTotalAumBasedOnQuote:()=>ti,checkIsMinOrMaxIndex:()=>Ye,convertU64BytesToDecimal:()=>Bo,default:()=>jo,defaultProvider:()=>Gi,estCoinAmountsFromTotalAmount:()=>Bi,feed_map_mainnet:()=>Zi,feed_map_testnet:()=>zi,getCoinAmountsFromRatio:()=>Se,getPositionPriceRange:()=>Vo,getPriceWithFormattedDecimals:()=>ji,getPrimitivePricesFromBaseQuote:()=>Xn,getQuotePerBaseAndBasePerQuote:()=>Di,getShareBufferAssets:()=>Te,getUpdatePriceType:()=>Li,getVaultValidBalances:()=>ei,get_lp_amount_by_liquidity:()=>qo,get_lp_amount_by_tvl:()=>Vi,get_share_liquidity_by_amount:()=>be,initMainnetSDK:()=>Xi,initTestnetSDK:()=>Wi,initVaultSDK:()=>Ro,oraclePriceMultiplierDecimal:()=>_e,parseVaultVestNFT:()=>$i,parseVaultsVestInfo:()=>ii,printTransaction:()=>Do,toSuiObjectId:()=>Ui,vaults_mainnet:()=>Ki,vaults_testnet:()=>Hi});module.exports=sr(Uo);var Qn=require("@mysten/sui/client"),ni=require("@mysten/sui/utils"),De=require("@cetusprotocol/aggregator-sdk");var pr=require("@mysten/sui/utils"),Ei=require("@mysten/sui/client"),br=require("@mysten/sui/client"),wr=require("@mysten/sui/utils"),vr=require("@mysten/sui/keypairs/ed25519"),yr=require("@mysten/sui/keypairs/secp256k1"),ge=require("@mysten/sui/utils"),Ai=require("@mysten/sui/transactions"),bo=require("@mysten/sui/bcs"),wo=require("@mysten/sui/utils"),ar=Object.create,xn=Object.defineProperty,cr=Object.getOwnPropertyDescriptor,ur=Object.getOwnPropertyNames,lr=Object.getPrototypeOf,dr=Object.prototype.hasOwnProperty,fr=(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')}),hr=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),mr=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ur(t))!dr.call(i,r)&&r!==e&&xn(i,r,{get:()=>t[r],enumerable:!(n=cr(t,r))||n.enumerable});return i},Pe=(i,t,e)=>(e=i!=null?ar(lr(i)):{},mr(t||!i||!i.__esModule?xn(e,"default",{value:i,enumerable:!0}):e,i)),Ee=hr((i,t)=>{"use strict";(function(e,n){"use strict";function r(o,u){if(!o)throw new Error(u||"Assertion failed")}function a(o,u){o.super_=u;var d=function(){};d.prototype=u.prototype,o.prototype=new d,o.prototype.constructor=o}function s(o,u,d){if(s.isBN(o))return o;this.negative=0,this.words=null,this.length=0,this.red=null,o!==null&&((u==="le"||u==="be")&&(d=u,u=10),this._init(o||0,u||10,d||"be"))}typeof e=="object"?e.exports=s:n.BN=s,s.BN=s,s.wordSize=26;var l;try{typeof window<"u"&&typeof window.Buffer<"u"?l=window.Buffer:l=fr("buffer").Buffer}catch{}s.isBN=function(o){return o instanceof s?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===s.wordSize&&Array.isArray(o.words)},s.max=function(o,u){return o.cmp(u)>0?o:u},s.min=function(o,u){return o.cmp(u)<0?o:u},s.prototype._init=function(o,u,d){if(typeof o=="number")return this._initNumber(o,u,d);if(typeof o=="object")return this._initArray(o,u,d);u==="hex"&&(u=16),r(u===(u|0)&&u>=2&&u<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(u===16?this._parseHex(o,m,d):(this._parseBase(o,u,m),d==="le"&&this._initArray(this.toArray(),u,d)))},s.prototype._initNumber=function(o,u,d){o<0&&(this.negative=1,o=-o),o<67108864?(this.words=[o&67108863],this.length=1):o<4503599627370496?(this.words=[o&67108863,o/67108864&67108863],this.length=2):(r(o<9007199254740992),this.words=[o&67108863,o/67108864&67108863,1],this.length=3),d==="le"&&this._initArray(this.toArray(),u,d)},s.prototype._initArray=function(o,u,d){if(r(typeof o.length=="number"),o.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(o.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var g,y,M=0;if(d==="be")for(m=o.length-1,g=0;m>=0;m-=3)y=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[g]|=y<<M&67108863,this.words[g+1]=y>>>26-M&67108863,M+=24,M>=26&&(M-=26,g++);else if(d==="le")for(m=0,g=0;m<o.length;m+=3)y=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[g]|=y<<M&67108863,this.words[g+1]=y>>>26-M&67108863,M+=24,M>=26&&(M-=26,g++);return this._strip()};function f(o,u){var d=o.charCodeAt(u);if(d>=48&&d<=57)return d-48;if(d>=65&&d<=70)return d-55;if(d>=97&&d<=102)return d-87;r(!1,"Invalid character in "+o)}function h(o,u,d){var m=f(o,d);return d-1>=u&&(m|=f(o,d-1)<<4),m}s.prototype._parseHex=function(o,u,d){this.length=Math.ceil((o.length-u)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var g=0,y=0,M;if(d==="be")for(m=o.length-1;m>=u;m-=2)M=h(o,u,m)<<g,this.words[y]|=M&67108863,g>=18?(g-=18,y+=1,this.words[y]|=M>>>26):g+=8;else{var p=o.length-u;for(m=p%2===0?u+1:u;m<o.length;m+=2)M=h(o,u,m)<<g,this.words[y]|=M&67108863,g>=18?(g-=18,y+=1,this.words[y]|=M>>>26):g+=8}this._strip()};function b(o,u,d,m){for(var g=0,y=0,M=Math.min(o.length,d),p=u;p<M;p++){var c=o.charCodeAt(p)-48;g*=m,c>=49?y=c-49+10:c>=17?y=c-17+10:y=c,r(c>=0&&y<m,"Invalid character"),g+=y}return g}s.prototype._parseBase=function(o,u,d){this.words=[0],this.length=1;for(var m=0,g=1;g<=67108863;g*=u)m++;m--,g=g/u|0;for(var y=o.length-d,M=y%m,p=Math.min(y,y-M)+d,c=0,_=d;_<p;_+=m)c=b(o,_,_+m,u),this.imuln(g),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(M!==0){var O=1;for(c=b(o,_,o.length,u),_=0;_<M;_++)O*=u;this.imuln(O),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},s.prototype.copy=function(o){o.words=new Array(this.length);for(var u=0;u<this.length;u++)o.words[u]=this.words[u];o.length=this.length,o.negative=this.negative,o.red=this.red};function w(o,u){o.words=u.words,o.length=u.length,o.negative=u.negative,o.red=u.red}if(s.prototype._move=function(o){w(o,this)},s.prototype.clone=function(){var o=new s(null);return this.copy(o),o},s.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},s.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},s.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{s.prototype[Symbol.for("nodejs.util.inspect.custom")]=v}catch{s.prototype.inspect=v}else s.prototype.inspect=v;function v(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var S=["","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"],C=[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],x=[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];s.prototype.toString=function(o,u){o=o||10,u=u|0||1;var d;if(o===16||o==="hex"){d="";for(var m=0,g=0,y=0;y<this.length;y++){var M=this.words[y],p=((M<<m|g)&16777215).toString(16);g=M>>>24-m&16777215,m+=2,m>=26&&(m-=26,y--),g!==0||y!==this.length-1?d=S[6-p.length]+p+d:d=p+d}for(g!==0&&(d=g.toString(16)+d);d.length%u!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}if(o===(o|0)&&o>=2&&o<=36){var c=C[o],_=x[o];d="";var O=this.clone();for(O.negative=0;!O.isZero();){var I=O.modrn(_).toString(o);O=O.idivn(_),O.isZero()?d=I+d:d=S[c-I.length]+I+d}for(this.isZero()&&(d="0"+d);d.length%u!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}r(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var o=this.words[0];return this.length===2?o+=this.words[1]*67108864:this.length===3&&this.words[2]===1?o+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-o:o},s.prototype.toJSON=function(){return this.toString(16,2)},l&&(s.prototype.toBuffer=function(o,u){return this.toArrayLike(l,o,u)}),s.prototype.toArray=function(o,u){return this.toArrayLike(Array,o,u)};var N=function(o,u){return o.allocUnsafe?o.allocUnsafe(u):new o(u)};s.prototype.toArrayLike=function(o,u,d){this._strip();var m=this.byteLength(),g=d||Math.max(1,m);r(m<=g,"byte array longer than desired length"),r(g>0,"Requested array length <= 0");var y=N(o,g),M=u==="le"?"LE":"BE";return this["_toArrayLike"+M](y,m),y},s.prototype._toArrayLikeLE=function(o,u){for(var d=0,m=0,g=0,y=0;g<this.length;g++){var M=this.words[g]<<y|m;o[d++]=M&255,d<o.length&&(o[d++]=M>>8&255),d<o.length&&(o[d++]=M>>16&255),y===6?(d<o.length&&(o[d++]=M>>24&255),m=0,y=0):(m=M>>>24,y+=2)}if(d<o.length)for(o[d++]=m;d<o.length;)o[d++]=0},s.prototype._toArrayLikeBE=function(o,u){for(var d=o.length-1,m=0,g=0,y=0;g<this.length;g++){var M=this.words[g]<<y|m;o[d--]=M&255,d>=0&&(o[d--]=M>>8&255),d>=0&&(o[d--]=M>>16&255),y===6?(d>=0&&(o[d--]=M>>24&255),m=0,y=0):(m=M>>>24,y+=2)}if(d>=0)for(o[d--]=m;d>=0;)o[d--]=0},Math.clz32?s.prototype._countBits=function(o){return 32-Math.clz32(o)}:s.prototype._countBits=function(o){var u=o,d=0;return u>=4096&&(d+=13,u>>>=13),u>=64&&(d+=7,u>>>=7),u>=8&&(d+=4,u>>>=4),u>=2&&(d+=2,u>>>=2),d+u},s.prototype._zeroBits=function(o){if(o===0)return 26;var u=o,d=0;return!(u&8191)&&(d+=13,u>>>=13),!(u&127)&&(d+=7,u>>>=7),!(u&15)&&(d+=4,u>>>=4),!(u&3)&&(d+=2,u>>>=2),!(u&1)&&d++,d},s.prototype.bitLength=function(){var o=this.words[this.length-1],u=this._countBits(o);return(this.length-1)*26+u};function E(o){for(var u=new Array(o.bitLength()),d=0;d<u.length;d++){var m=d/26|0,g=d%26;u[d]=o.words[m]>>>g&1}return u}s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,u=0;u<this.length;u++){var d=this._zeroBits(this.words[u]);if(o+=d,d!==26)break}return o},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},s.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return this.negative!==0},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var u=0;u<o.length;u++)this.words[u]=this.words[u]|o.words[u];return this._strip()},s.prototype.ior=function(o){return r((this.negative|o.negative)===0),this.iuor(o)},s.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},s.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},s.prototype.iuand=function(o){var u;this.length>o.length?u=o:u=this;for(var d=0;d<u.length;d++)this.words[d]=this.words[d]&o.words[d];return this.length=u.length,this._strip()},s.prototype.iand=function(o){return r((this.negative|o.negative)===0),this.iuand(o)},s.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},s.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},s.prototype.iuxor=function(o){var u,d;this.length>o.length?(u=this,d=o):(u=o,d=this);for(var m=0;m<d.length;m++)this.words[m]=u.words[m]^d.words[m];if(this!==u)for(;m<u.length;m++)this.words[m]=u.words[m];return this.length=u.length,this._strip()},s.prototype.ixor=function(o){return r((this.negative|o.negative)===0),this.iuxor(o)},s.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},s.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},s.prototype.inotn=function(o){r(typeof o=="number"&&o>=0);var u=Math.ceil(o/26)|0,d=o%26;this._expand(u),d>0&&u--;for(var m=0;m<u;m++)this.words[m]=~this.words[m]&67108863;return d>0&&(this.words[m]=~this.words[m]&67108863>>26-d),this._strip()},s.prototype.notn=function(o){return this.clone().inotn(o)},s.prototype.setn=function(o,u){r(typeof o=="number"&&o>=0);var d=o/26|0,m=o%26;return this._expand(d+1),u?this.words[d]=this.words[d]|1<<m:this.words[d]=this.words[d]&~(1<<m),this._strip()},s.prototype.iadd=function(o){var u;if(this.negative!==0&&o.negative===0)return this.negative=0,u=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,u=this.isub(o),o.negative=1,u._normSign();var d,m;this.length>o.length?(d=this,m=o):(d=o,m=this);for(var g=0,y=0;y<m.length;y++)u=(d.words[y]|0)+(m.words[y]|0)+g,this.words[y]=u&67108863,g=u>>>26;for(;g!==0&&y<d.length;y++)u=(d.words[y]|0)+g,this.words[y]=u&67108863,g=u>>>26;if(this.length=d.length,g!==0)this.words[this.length]=g,this.length++;else if(d!==this)for(;y<d.length;y++)this.words[y]=d.words[y];return this},s.prototype.add=function(o){var u;return o.negative!==0&&this.negative===0?(o.negative=0,u=this.sub(o),o.negative^=1,u):o.negative===0&&this.negative!==0?(this.negative=0,u=o.sub(this),this.negative=1,u):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},s.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var u=this.iadd(o);return o.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var d=this.cmp(o);if(d===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,g;d>0?(m=this,g=o):(m=o,g=this);for(var y=0,M=0;M<g.length;M++)u=(m.words[M]|0)-(g.words[M]|0)+y,y=u>>26,this.words[M]=u&67108863;for(;y!==0&&M<m.length;M++)u=(m.words[M]|0)+y,y=u>>26,this.words[M]=u&67108863;if(y===0&&M<m.length&&m!==this)for(;M<m.length;M++)this.words[M]=m.words[M];return this.length=Math.max(this.length,M),m!==this&&(this.negative=1),this._strip()},s.prototype.sub=function(o){return this.clone().isub(o)};function q(o,u,d){d.negative=u.negative^o.negative;var m=o.length+u.length|0;d.length=m,m=m-1|0;var g=o.words[0]|0,y=u.words[0]|0,M=g*y,p=M&67108863,c=M/67108864|0;d.words[0]=p;for(var _=1;_<m;_++){for(var O=c>>>26,I=c&67108863,F=Math.min(_,u.length-1),L=Math.max(0,_-o.length+1);L<=F;L++){var U=_-L|0;g=o.words[U]|0,y=u.words[L]|0,M=g*y+I,O+=M/67108864|0,I=M&67108863}d.words[_]=I|0,c=O|0}return c!==0?d.words[_]=c|0:d.length--,d._strip()}var k=function(o,u,d){var m=o.words,g=u.words,y=d.words,M=0,p,c,_,O=m[0]|0,I=O&8191,F=O>>>13,L=m[1]|0,U=L&8191,W=L>>>13,ue=m[2]|0,G=ue&8191,J=ue>>>13,Qi=m[3]|0,it=Qi&8191,nt=Qi>>>13,tn=m[4]|0,rt=tn&8191,ot=tn>>>13,en=m[5]|0,st=en&8191,at=en>>>13,nn=m[6]|0,ct=nn&8191,ut=nn>>>13,rn=m[7]|0,lt=rn&8191,dt=rn>>>13,on=m[8]|0,ft=on&8191,ht=on>>>13,sn=m[9]|0,mt=sn&8191,pt=sn>>>13,an=g[0]|0,gt=an&8191,_t=an>>>13,cn=g[1]|0,bt=cn&8191,wt=cn>>>13,un=g[2]|0,vt=un&8191,yt=un>>>13,ln=g[3]|0,Mt=ln&8191,St=ln>>>13,dn=g[4]|0,At=dn&8191,Ct=dn>>>13,fn=g[5]|0,xt=fn&8191,kt=fn>>>13,hn=g[6]|0,Pt=hn&8191,Et=hn>>>13,mn=g[7]|0,Ot=mn&8191,It=mn>>>13,pn=g[8]|0,Tt=pn&8191,Nt=pn>>>13,gn=g[9]|0,Ft=gn&8191,Bt=gn>>>13;d.negative=o.negative^u.negative,d.length=19,p=Math.imul(I,gt),c=Math.imul(I,_t),c=c+Math.imul(F,gt)|0,_=Math.imul(F,_t);var ri=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(ri>>>26)|0,ri&=67108863,p=Math.imul(U,gt),c=Math.imul(U,_t),c=c+Math.imul(W,gt)|0,_=Math.imul(W,_t),p=p+Math.imul(I,bt)|0,c=c+Math.imul(I,wt)|0,c=c+Math.imul(F,bt)|0,_=_+Math.imul(F,wt)|0;var oi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(oi>>>26)|0,oi&=67108863,p=Math.imul(G,gt),c=Math.imul(G,_t),c=c+Math.imul(J,gt)|0,_=Math.imul(J,_t),p=p+Math.imul(U,bt)|0,c=c+Math.imul(U,wt)|0,c=c+Math.imul(W,bt)|0,_=_+Math.imul(W,wt)|0,p=p+Math.imul(I,vt)|0,c=c+Math.imul(I,yt)|0,c=c+Math.imul(F,vt)|0,_=_+Math.imul(F,yt)|0;var si=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(si>>>26)|0,si&=67108863,p=Math.imul(it,gt),c=Math.imul(it,_t),c=c+Math.imul(nt,gt)|0,_=Math.imul(nt,_t),p=p+Math.imul(G,bt)|0,c=c+Math.imul(G,wt)|0,c=c+Math.imul(J,bt)|0,_=_+Math.imul(J,wt)|0,p=p+Math.imul(U,vt)|0,c=c+Math.imul(U,yt)|0,c=c+Math.imul(W,vt)|0,_=_+Math.imul(W,yt)|0,p=p+Math.imul(I,Mt)|0,c=c+Math.imul(I,St)|0,c=c+Math.imul(F,Mt)|0,_=_+Math.imul(F,St)|0;var ai=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(ai>>>26)|0,ai&=67108863,p=Math.imul(rt,gt),c=Math.imul(rt,_t),c=c+Math.imul(ot,gt)|0,_=Math.imul(ot,_t),p=p+Math.imul(it,bt)|0,c=c+Math.imul(it,wt)|0,c=c+Math.imul(nt,bt)|0,_=_+Math.imul(nt,wt)|0,p=p+Math.imul(G,vt)|0,c=c+Math.imul(G,yt)|0,c=c+Math.imul(J,vt)|0,_=_+Math.imul(J,yt)|0,p=p+Math.imul(U,Mt)|0,c=c+Math.imul(U,St)|0,c=c+Math.imul(W,Mt)|0,_=_+Math.imul(W,St)|0,p=p+Math.imul(I,At)|0,c=c+Math.imul(I,Ct)|0,c=c+Math.imul(F,At)|0,_=_+Math.imul(F,Ct)|0;var ci=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(ci>>>26)|0,ci&=67108863,p=Math.imul(st,gt),c=Math.imul(st,_t),c=c+Math.imul(at,gt)|0,_=Math.imul(at,_t),p=p+Math.imul(rt,bt)|0,c=c+Math.imul(rt,wt)|0,c=c+Math.imul(ot,bt)|0,_=_+Math.imul(ot,wt)|0,p=p+Math.imul(it,vt)|0,c=c+Math.imul(it,yt)|0,c=c+Math.imul(nt,vt)|0,_=_+Math.imul(nt,yt)|0,p=p+Math.imul(G,Mt)|0,c=c+Math.imul(G,St)|0,c=c+Math.imul(J,Mt)|0,_=_+Math.imul(J,St)|0,p=p+Math.imul(U,At)|0,c=c+Math.imul(U,Ct)|0,c=c+Math.imul(W,At)|0,_=_+Math.imul(W,Ct)|0,p=p+Math.imul(I,xt)|0,c=c+Math.imul(I,kt)|0,c=c+Math.imul(F,xt)|0,_=_+Math.imul(F,kt)|0;var ui=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(ui>>>26)|0,ui&=67108863,p=Math.imul(ct,gt),c=Math.imul(ct,_t),c=c+Math.imul(ut,gt)|0,_=Math.imul(ut,_t),p=p+Math.imul(st,bt)|0,c=c+Math.imul(st,wt)|0,c=c+Math.imul(at,bt)|0,_=_+Math.imul(at,wt)|0,p=p+Math.imul(rt,vt)|0,c=c+Math.imul(rt,yt)|0,c=c+Math.imul(ot,vt)|0,_=_+Math.imul(ot,yt)|0,p=p+Math.imul(it,Mt)|0,c=c+Math.imul(it,St)|0,c=c+Math.imul(nt,Mt)|0,_=_+Math.imul(nt,St)|0,p=p+Math.imul(G,At)|0,c=c+Math.imul(G,Ct)|0,c=c+Math.imul(J,At)|0,_=_+Math.imul(J,Ct)|0,p=p+Math.imul(U,xt)|0,c=c+Math.imul(U,kt)|0,c=c+Math.imul(W,xt)|0,_=_+Math.imul(W,kt)|0,p=p+Math.imul(I,Pt)|0,c=c+Math.imul(I,Et)|0,c=c+Math.imul(F,Pt)|0,_=_+Math.imul(F,Et)|0;var li=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(li>>>26)|0,li&=67108863,p=Math.imul(lt,gt),c=Math.imul(lt,_t),c=c+Math.imul(dt,gt)|0,_=Math.imul(dt,_t),p=p+Math.imul(ct,bt)|0,c=c+Math.imul(ct,wt)|0,c=c+Math.imul(ut,bt)|0,_=_+Math.imul(ut,wt)|0,p=p+Math.imul(st,vt)|0,c=c+Math.imul(st,yt)|0,c=c+Math.imul(at,vt)|0,_=_+Math.imul(at,yt)|0,p=p+Math.imul(rt,Mt)|0,c=c+Math.imul(rt,St)|0,c=c+Math.imul(ot,Mt)|0,_=_+Math.imul(ot,St)|0,p=p+Math.imul(it,At)|0,c=c+Math.imul(it,Ct)|0,c=c+Math.imul(nt,At)|0,_=_+Math.imul(nt,Ct)|0,p=p+Math.imul(G,xt)|0,c=c+Math.imul(G,kt)|0,c=c+Math.imul(J,xt)|0,_=_+Math.imul(J,kt)|0,p=p+Math.imul(U,Pt)|0,c=c+Math.imul(U,Et)|0,c=c+Math.imul(W,Pt)|0,_=_+Math.imul(W,Et)|0,p=p+Math.imul(I,Ot)|0,c=c+Math.imul(I,It)|0,c=c+Math.imul(F,Ot)|0,_=_+Math.imul(F,It)|0;var di=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(di>>>26)|0,di&=67108863,p=Math.imul(ft,gt),c=Math.imul(ft,_t),c=c+Math.imul(ht,gt)|0,_=Math.imul(ht,_t),p=p+Math.imul(lt,bt)|0,c=c+Math.imul(lt,wt)|0,c=c+Math.imul(dt,bt)|0,_=_+Math.imul(dt,wt)|0,p=p+Math.imul(ct,vt)|0,c=c+Math.imul(ct,yt)|0,c=c+Math.imul(ut,vt)|0,_=_+Math.imul(ut,yt)|0,p=p+Math.imul(st,Mt)|0,c=c+Math.imul(st,St)|0,c=c+Math.imul(at,Mt)|0,_=_+Math.imul(at,St)|0,p=p+Math.imul(rt,At)|0,c=c+Math.imul(rt,Ct)|0,c=c+Math.imul(ot,At)|0,_=_+Math.imul(ot,Ct)|0,p=p+Math.imul(it,xt)|0,c=c+Math.imul(it,kt)|0,c=c+Math.imul(nt,xt)|0,_=_+Math.imul(nt,kt)|0,p=p+Math.imul(G,Pt)|0,c=c+Math.imul(G,Et)|0,c=c+Math.imul(J,Pt)|0,_=_+Math.imul(J,Et)|0,p=p+Math.imul(U,Ot)|0,c=c+Math.imul(U,It)|0,c=c+Math.imul(W,Ot)|0,_=_+Math.imul(W,It)|0,p=p+Math.imul(I,Tt)|0,c=c+Math.imul(I,Nt)|0,c=c+Math.imul(F,Tt)|0,_=_+Math.imul(F,Nt)|0;var fi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(fi>>>26)|0,fi&=67108863,p=Math.imul(mt,gt),c=Math.imul(mt,_t),c=c+Math.imul(pt,gt)|0,_=Math.imul(pt,_t),p=p+Math.imul(ft,bt)|0,c=c+Math.imul(ft,wt)|0,c=c+Math.imul(ht,bt)|0,_=_+Math.imul(ht,wt)|0,p=p+Math.imul(lt,vt)|0,c=c+Math.imul(lt,yt)|0,c=c+Math.imul(dt,vt)|0,_=_+Math.imul(dt,yt)|0,p=p+Math.imul(ct,Mt)|0,c=c+Math.imul(ct,St)|0,c=c+Math.imul(ut,Mt)|0,_=_+Math.imul(ut,St)|0,p=p+Math.imul(st,At)|0,c=c+Math.imul(st,Ct)|0,c=c+Math.imul(at,At)|0,_=_+Math.imul(at,Ct)|0,p=p+Math.imul(rt,xt)|0,c=c+Math.imul(rt,kt)|0,c=c+Math.imul(ot,xt)|0,_=_+Math.imul(ot,kt)|0,p=p+Math.imul(it,Pt)|0,c=c+Math.imul(it,Et)|0,c=c+Math.imul(nt,Pt)|0,_=_+Math.imul(nt,Et)|0,p=p+Math.imul(G,Ot)|0,c=c+Math.imul(G,It)|0,c=c+Math.imul(J,Ot)|0,_=_+Math.imul(J,It)|0,p=p+Math.imul(U,Tt)|0,c=c+Math.imul(U,Nt)|0,c=c+Math.imul(W,Tt)|0,_=_+Math.imul(W,Nt)|0,p=p+Math.imul(I,Ft)|0,c=c+Math.imul(I,Bt)|0,c=c+Math.imul(F,Ft)|0,_=_+Math.imul(F,Bt)|0;var hi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(hi>>>26)|0,hi&=67108863,p=Math.imul(mt,bt),c=Math.imul(mt,wt),c=c+Math.imul(pt,bt)|0,_=Math.imul(pt,wt),p=p+Math.imul(ft,vt)|0,c=c+Math.imul(ft,yt)|0,c=c+Math.imul(ht,vt)|0,_=_+Math.imul(ht,yt)|0,p=p+Math.imul(lt,Mt)|0,c=c+Math.imul(lt,St)|0,c=c+Math.imul(dt,Mt)|0,_=_+Math.imul(dt,St)|0,p=p+Math.imul(ct,At)|0,c=c+Math.imul(ct,Ct)|0,c=c+Math.imul(ut,At)|0,_=_+Math.imul(ut,Ct)|0,p=p+Math.imul(st,xt)|0,c=c+Math.imul(st,kt)|0,c=c+Math.imul(at,xt)|0,_=_+Math.imul(at,kt)|0,p=p+Math.imul(rt,Pt)|0,c=c+Math.imul(rt,Et)|0,c=c+Math.imul(ot,Pt)|0,_=_+Math.imul(ot,Et)|0,p=p+Math.imul(it,Ot)|0,c=c+Math.imul(it,It)|0,c=c+Math.imul(nt,Ot)|0,_=_+Math.imul(nt,It)|0,p=p+Math.imul(G,Tt)|0,c=c+Math.imul(G,Nt)|0,c=c+Math.imul(J,Tt)|0,_=_+Math.imul(J,Nt)|0,p=p+Math.imul(U,Ft)|0,c=c+Math.imul(U,Bt)|0,c=c+Math.imul(W,Ft)|0,_=_+Math.imul(W,Bt)|0;var mi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(mi>>>26)|0,mi&=67108863,p=Math.imul(mt,vt),c=Math.imul(mt,yt),c=c+Math.imul(pt,vt)|0,_=Math.imul(pt,yt),p=p+Math.imul(ft,Mt)|0,c=c+Math.imul(ft,St)|0,c=c+Math.imul(ht,Mt)|0,_=_+Math.imul(ht,St)|0,p=p+Math.imul(lt,At)|0,c=c+Math.imul(lt,Ct)|0,c=c+Math.imul(dt,At)|0,_=_+Math.imul(dt,Ct)|0,p=p+Math.imul(ct,xt)|0,c=c+Math.imul(ct,kt)|0,c=c+Math.imul(ut,xt)|0,_=_+Math.imul(ut,kt)|0,p=p+Math.imul(st,Pt)|0,c=c+Math.imul(st,Et)|0,c=c+Math.imul(at,Pt)|0,_=_+Math.imul(at,Et)|0,p=p+Math.imul(rt,Ot)|0,c=c+Math.imul(rt,It)|0,c=c+Math.imul(ot,Ot)|0,_=_+Math.imul(ot,It)|0,p=p+Math.imul(it,Tt)|0,c=c+Math.imul(it,Nt)|0,c=c+Math.imul(nt,Tt)|0,_=_+Math.imul(nt,Nt)|0,p=p+Math.imul(G,Ft)|0,c=c+Math.imul(G,Bt)|0,c=c+Math.imul(J,Ft)|0,_=_+Math.imul(J,Bt)|0;var pi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(pi>>>26)|0,pi&=67108863,p=Math.imul(mt,Mt),c=Math.imul(mt,St),c=c+Math.imul(pt,Mt)|0,_=Math.imul(pt,St),p=p+Math.imul(ft,At)|0,c=c+Math.imul(ft,Ct)|0,c=c+Math.imul(ht,At)|0,_=_+Math.imul(ht,Ct)|0,p=p+Math.imul(lt,xt)|0,c=c+Math.imul(lt,kt)|0,c=c+Math.imul(dt,xt)|0,_=_+Math.imul(dt,kt)|0,p=p+Math.imul(ct,Pt)|0,c=c+Math.imul(ct,Et)|0,c=c+Math.imul(ut,Pt)|0,_=_+Math.imul(ut,Et)|0,p=p+Math.imul(st,Ot)|0,c=c+Math.imul(st,It)|0,c=c+Math.imul(at,Ot)|0,_=_+Math.imul(at,It)|0,p=p+Math.imul(rt,Tt)|0,c=c+Math.imul(rt,Nt)|0,c=c+Math.imul(ot,Tt)|0,_=_+Math.imul(ot,Nt)|0,p=p+Math.imul(it,Ft)|0,c=c+Math.imul(it,Bt)|0,c=c+Math.imul(nt,Ft)|0,_=_+Math.imul(nt,Bt)|0;var gi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,p=Math.imul(mt,At),c=Math.imul(mt,Ct),c=c+Math.imul(pt,At)|0,_=Math.imul(pt,Ct),p=p+Math.imul(ft,xt)|0,c=c+Math.imul(ft,kt)|0,c=c+Math.imul(ht,xt)|0,_=_+Math.imul(ht,kt)|0,p=p+Math.imul(lt,Pt)|0,c=c+Math.imul(lt,Et)|0,c=c+Math.imul(dt,Pt)|0,_=_+Math.imul(dt,Et)|0,p=p+Math.imul(ct,Ot)|0,c=c+Math.imul(ct,It)|0,c=c+Math.imul(ut,Ot)|0,_=_+Math.imul(ut,It)|0,p=p+Math.imul(st,Tt)|0,c=c+Math.imul(st,Nt)|0,c=c+Math.imul(at,Tt)|0,_=_+Math.imul(at,Nt)|0,p=p+Math.imul(rt,Ft)|0,c=c+Math.imul(rt,Bt)|0,c=c+Math.imul(ot,Ft)|0,_=_+Math.imul(ot,Bt)|0;var _i=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(_i>>>26)|0,_i&=67108863,p=Math.imul(mt,xt),c=Math.imul(mt,kt),c=c+Math.imul(pt,xt)|0,_=Math.imul(pt,kt),p=p+Math.imul(ft,Pt)|0,c=c+Math.imul(ft,Et)|0,c=c+Math.imul(ht,Pt)|0,_=_+Math.imul(ht,Et)|0,p=p+Math.imul(lt,Ot)|0,c=c+Math.imul(lt,It)|0,c=c+Math.imul(dt,Ot)|0,_=_+Math.imul(dt,It)|0,p=p+Math.imul(ct,Tt)|0,c=c+Math.imul(ct,Nt)|0,c=c+Math.imul(ut,Tt)|0,_=_+Math.imul(ut,Nt)|0,p=p+Math.imul(st,Ft)|0,c=c+Math.imul(st,Bt)|0,c=c+Math.imul(at,Ft)|0,_=_+Math.imul(at,Bt)|0;var bi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,p=Math.imul(mt,Pt),c=Math.imul(mt,Et),c=c+Math.imul(pt,Pt)|0,_=Math.imul(pt,Et),p=p+Math.imul(ft,Ot)|0,c=c+Math.imul(ft,It)|0,c=c+Math.imul(ht,Ot)|0,_=_+Math.imul(ht,It)|0,p=p+Math.imul(lt,Tt)|0,c=c+Math.imul(lt,Nt)|0,c=c+Math.imul(dt,Tt)|0,_=_+Math.imul(dt,Nt)|0,p=p+Math.imul(ct,Ft)|0,c=c+Math.imul(ct,Bt)|0,c=c+Math.imul(ut,Ft)|0,_=_+Math.imul(ut,Bt)|0;var wi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,p=Math.imul(mt,Ot),c=Math.imul(mt,It),c=c+Math.imul(pt,Ot)|0,_=Math.imul(pt,It),p=p+Math.imul(ft,Tt)|0,c=c+Math.imul(ft,Nt)|0,c=c+Math.imul(ht,Tt)|0,_=_+Math.imul(ht,Nt)|0,p=p+Math.imul(lt,Ft)|0,c=c+Math.imul(lt,Bt)|0,c=c+Math.imul(dt,Ft)|0,_=_+Math.imul(dt,Bt)|0;var vi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,p=Math.imul(mt,Tt),c=Math.imul(mt,Nt),c=c+Math.imul(pt,Tt)|0,_=Math.imul(pt,Nt),p=p+Math.imul(ft,Ft)|0,c=c+Math.imul(ft,Bt)|0,c=c+Math.imul(ht,Ft)|0,_=_+Math.imul(ht,Bt)|0;var yi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,p=Math.imul(mt,Ft),c=Math.imul(mt,Bt),c=c+Math.imul(pt,Ft)|0,_=Math.imul(pt,Bt);var Mi=(M+p|0)+((c&8191)<<13)|0;return M=(_+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,y[0]=ri,y[1]=oi,y[2]=si,y[3]=ai,y[4]=ci,y[5]=ui,y[6]=li,y[7]=di,y[8]=fi,y[9]=hi,y[10]=mi,y[11]=pi,y[12]=gi,y[13]=_i,y[14]=bi,y[15]=wi,y[16]=vi,y[17]=yi,y[18]=Mi,M!==0&&(y[19]=M,d.length++),d};Math.imul||(k=q);function V(o,u,d){d.negative=u.negative^o.negative,d.length=o.length+u.length;for(var m=0,g=0,y=0;y<d.length-1;y++){var M=g;g=0;for(var p=m&67108863,c=Math.min(y,u.length-1),_=Math.max(0,y-o.length+1);_<=c;_++){var O=y-_,I=o.words[O]|0,F=u.words[_]|0,L=I*F,U=L&67108863;M=M+(L/67108864|0)|0,U=U+p|0,p=U&67108863,M=M+(U>>>26)|0,g+=M>>>26,M&=67108863}d.words[y]=p,m=M,M=g}return m!==0?d.words[y]=m:d.length--,d._strip()}function qt(o,u,d){return V(o,u,d)}s.prototype.mulTo=function(o,u){var d,m=this.length+o.length;return this.length===10&&o.length===10?d=k(this,o,u):m<63?d=q(this,o,u):m<1024?d=V(this,o,u):d=qt(this,o,u),d};function K(o,u){this.x=o,this.y=u}K.prototype.makeRBT=function(o){for(var u=new Array(o),d=s.prototype._countBits(o)-1,m=0;m<o;m++)u[m]=this.revBin(m,d,o);return u},K.prototype.revBin=function(o,u,d){if(o===0||o===d-1)return o;for(var m=0,g=0;g<u;g++)m|=(o&1)<<u-g-1,o>>=1;return m},K.prototype.permute=function(o,u,d,m,g,y){for(var M=0;M<y;M++)m[M]=u[o[M]],g[M]=d[o[M]]},K.prototype.transform=function(o,u,d,m,g,y){this.permute(y,o,u,d,m,g);for(var M=1;M<g;M<<=1)for(var p=M<<1,c=Math.cos(2*Math.PI/p),_=Math.sin(2*Math.PI/p),O=0;O<g;O+=p)for(var I=c,F=_,L=0;L<M;L++){var U=d[O+L],W=m[O+L],ue=d[O+L+M],G=m[O+L+M],J=I*ue-F*G;G=I*G+F*ue,ue=J,d[O+L]=U+ue,m[O+L]=W+G,d[O+L+M]=U-ue,m[O+L+M]=W-G,L!==p&&(J=c*I-_*F,F=c*F+_*I,I=J)}},K.prototype.guessLen13b=function(o,u){var d=Math.max(u,o)|1,m=d&1,g=0;for(d=d/2|0;d;d=d>>>1)g++;return 1<<g+1+m},K.prototype.conjugate=function(o,u,d){if(!(d<=1))for(var m=0;m<d/2;m++){var g=o[m];o[m]=o[d-m-1],o[d-m-1]=g,g=u[m],u[m]=-u[d-m-1],u[d-m-1]=-g}},K.prototype.normalize13b=function(o,u){for(var d=0,m=0;m<u/2;m++){var g=Math.round(o[2*m+1]/u)*8192+Math.round(o[2*m]/u)+d;o[m]=g&67108863,g<67108864?d=0:d=g/67108864|0}return o},K.prototype.convert13b=function(o,u,d,m){for(var g=0,y=0;y<u;y++)g=g+(o[y]|0),d[2*y]=g&8191,g=g>>>13,d[2*y+1]=g&8191,g=g>>>13;for(y=2*u;y<m;++y)d[y]=0;r(g===0),r((g&-8192)===0)},K.prototype.stub=function(o){for(var u=new Array(o),d=0;d<o;d++)u[d]=0;return u},K.prototype.mulp=function(o,u,d){var m=2*this.guessLen13b(o.length,u.length),g=this.makeRBT(m),y=this.stub(m),M=new Array(m),p=new Array(m),c=new Array(m),_=new Array(m),O=new Array(m),I=new Array(m),F=d.words;F.length=m,this.convert13b(o.words,o.length,M,m),this.convert13b(u.words,u.length,_,m),this.transform(M,y,p,c,m,g),this.transform(_,y,O,I,m,g);for(var L=0;L<m;L++){var U=p[L]*O[L]-c[L]*I[L];c[L]=p[L]*I[L]+c[L]*O[L],p[L]=U}return this.conjugate(p,c,m),this.transform(p,c,F,y,m,g),this.conjugate(F,y,m),this.normalize13b(F,m),d.negative=o.negative^u.negative,d.length=o.length+u.length,d._strip()},s.prototype.mul=function(o){var u=new s(null);return u.words=new Array(this.length+o.length),this.mulTo(o,u)},s.prototype.mulf=function(o){var u=new s(null);return u.words=new Array(this.length+o.length),qt(this,o,u)},s.prototype.imul=function(o){return this.clone().mulTo(o,this)},s.prototype.imuln=function(o){var u=o<0;u&&(o=-o),r(typeof o=="number"),r(o<67108864);for(var d=0,m=0;m<this.length;m++){var g=(this.words[m]|0)*o,y=(g&67108863)+(d&67108863);d>>=26,d+=g/67108864|0,d+=y>>>26,this.words[m]=y&67108863}return d!==0&&(this.words[m]=d,this.length++),this.length=o===0?1:this.length,u?this.ineg():this},s.prototype.muln=function(o){return this.clone().imuln(o)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(o){var u=E(o);if(u.length===0)return new s(1);for(var d=this,m=0;m<u.length&&u[m]===0;m++,d=d.sqr());if(++m<u.length)for(var g=d.sqr();m<u.length;m++,g=g.sqr())u[m]!==0&&(d=d.mul(g));return d},s.prototype.iushln=function(o){r(typeof o=="number"&&o>=0);var u=o%26,d=(o-u)/26,m=67108863>>>26-u<<26-u,g;if(u!==0){var y=0;for(g=0;g<this.length;g++){var M=this.words[g]&m,p=(this.words[g]|0)-M<<u;this.words[g]=p|y,y=M>>>26-u}y&&(this.words[g]=y,this.length++)}if(d!==0){for(g=this.length-1;g>=0;g--)this.words[g+d]=this.words[g];for(g=0;g<d;g++)this.words[g]=0;this.length+=d}return this._strip()},s.prototype.ishln=function(o){return r(this.negative===0),this.iushln(o)},s.prototype.iushrn=function(o,u,d){r(typeof o=="number"&&o>=0);var m;u?m=(u-u%26)/26:m=0;var g=o%26,y=Math.min((o-g)/26,this.length),M=67108863^67108863>>>g<<g,p=d;if(m-=y,m=Math.max(0,m),p){for(var c=0;c<y;c++)p.words[c]=this.words[c];p.length=y}if(y!==0)if(this.length>y)for(this.length-=y,c=0;c<this.length;c++)this.words[c]=this.words[c+y];else this.words[0]=0,this.length=1;var _=0;for(c=this.length-1;c>=0&&(_!==0||c>=m);c--){var O=this.words[c]|0;this.words[c]=_<<26-g|O>>>g,_=O&M}return p&&_!==0&&(p.words[p.length++]=_),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},s.prototype.ishrn=function(o,u,d){return r(this.negative===0),this.iushrn(o,u,d)},s.prototype.shln=function(o){return this.clone().ishln(o)},s.prototype.ushln=function(o){return this.clone().iushln(o)},s.prototype.shrn=function(o){return this.clone().ishrn(o)},s.prototype.ushrn=function(o){return this.clone().iushrn(o)},s.prototype.testn=function(o){r(typeof o=="number"&&o>=0);var u=o%26,d=(o-u)/26,m=1<<u;if(this.length<=d)return!1;var g=this.words[d];return!!(g&m)},s.prototype.imaskn=function(o){r(typeof o=="number"&&o>=0);var u=o%26,d=(o-u)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=d)return this;if(u!==0&&d++,this.length=Math.min(d,this.length),u!==0){var m=67108863^67108863>>>u<<u;this.words[this.length-1]&=m}return this._strip()},s.prototype.maskn=function(o){return this.clone().imaskn(o)},s.prototype.iaddn=function(o){return r(typeof o=="number"),r(o<67108864),o<0?this.isubn(-o):this.negative!==0?this.length===1&&(this.words[0]|0)<=o?(this.words[0]=o-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(o),this.negative=1,this):this._iaddn(o)},s.prototype._iaddn=function(o){this.words[0]+=o;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},s.prototype.isubn=function(o){if(r(typeof o=="number"),r(o<67108864),o<0)return this.iaddn(-o);if(this.negative!==0)return this.negative=0,this.iaddn(o),this.negative=1,this;if(this.words[0]-=o,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},s.prototype.addn=function(o){return this.clone().iaddn(o)},s.prototype.subn=function(o){return this.clone().isubn(o)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(o,u,d){var m=o.length+d,g;this._expand(m);var y,M=0;for(g=0;g<o.length;g++){y=(this.words[g+d]|0)+M;var p=(o.words[g]|0)*u;y-=p&67108863,M=(y>>26)-(p/67108864|0),this.words[g+d]=y&67108863}for(;g<this.length-d;g++)y=(this.words[g+d]|0)+M,M=y>>26,this.words[g+d]=y&67108863;if(M===0)return this._strip();for(r(M===-1),M=0,g=0;g<this.length;g++)y=-(this.words[g]|0)+M,M=y>>26,this.words[g]=y&67108863;return this.negative=1,this._strip()},s.prototype._wordDiv=function(o,u){var d=this.length-o.length,m=this.clone(),g=o,y=g.words[g.length-1]|0,M=this._countBits(y);d=26-M,d!==0&&(g=g.ushln(d),m.iushln(d),y=g.words[g.length-1]|0);var p=m.length-g.length,c;if(u!=="mod"){c=new s(null),c.length=p+1,c.words=new Array(c.length);for(var _=0;_<c.length;_++)c.words[_]=0}var O=m.clone()._ishlnsubmul(g,1,p);O.negative===0&&(m=O,c&&(c.words[p]=1));for(var I=p-1;I>=0;I--){var F=(m.words[g.length+I]|0)*67108864+(m.words[g.length+I-1]|0);for(F=Math.min(F/y|0,67108863),m._ishlnsubmul(g,F,I);m.negative!==0;)F--,m.negative=0,m._ishlnsubmul(g,1,I),m.isZero()||(m.negative^=1);c&&(c.words[I]=F)}return c&&c._strip(),m._strip(),u!=="div"&&d!==0&&m.iushrn(d),{div:c||null,mod:m}},s.prototype.divmod=function(o,u,d){if(r(!o.isZero()),this.isZero())return{div:new s(0),mod:new s(0)};var m,g,y;return this.negative!==0&&o.negative===0?(y=this.neg().divmod(o,u),u!=="mod"&&(m=y.div.neg()),u!=="div"&&(g=y.mod.neg(),d&&g.negative!==0&&g.iadd(o)),{div:m,mod:g}):this.negative===0&&o.negative!==0?(y=this.divmod(o.neg(),u),u!=="mod"&&(m=y.div.neg()),{div:m,mod:y.mod}):this.negative&o.negative?(y=this.neg().divmod(o.neg(),u),u!=="div"&&(g=y.mod.neg(),d&&g.negative!==0&&g.isub(o)),{div:y.div,mod:g}):o.length>this.length||this.cmp(o)<0?{div:new s(0),mod:this}:o.length===1?u==="div"?{div:this.divn(o.words[0]),mod:null}:u==="mod"?{div:null,mod:new s(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new s(this.modrn(o.words[0]))}:this._wordDiv(o,u)},s.prototype.div=function(o){return this.divmod(o,"div",!1).div},s.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},s.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},s.prototype.divRound=function(o){var u=this.divmod(o);if(u.mod.isZero())return u.div;var d=u.div.negative!==0?u.mod.isub(o):u.mod,m=o.ushrn(1),g=o.andln(1),y=d.cmp(m);return y<0||g===1&&y===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},s.prototype.modrn=function(o){var u=o<0;u&&(o=-o),r(o<=67108863);for(var d=(1<<26)%o,m=0,g=this.length-1;g>=0;g--)m=(d*m+(this.words[g]|0))%o;return u?-m:m},s.prototype.modn=function(o){return this.modrn(o)},s.prototype.idivn=function(o){var u=o<0;u&&(o=-o),r(o<=67108863);for(var d=0,m=this.length-1;m>=0;m--){var g=(this.words[m]|0)+d*67108864;this.words[m]=g/o|0,d=g%o}return this._strip(),u?this.ineg():this},s.prototype.divn=function(o){return this.clone().idivn(o)},s.prototype.egcd=function(o){r(o.negative===0),r(!o.isZero());var u=this,d=o.clone();u.negative!==0?u=u.umod(o):u=u.clone();for(var m=new s(1),g=new s(0),y=new s(0),M=new s(1),p=0;u.isEven()&&d.isEven();)u.iushrn(1),d.iushrn(1),++p;for(var c=d.clone(),_=u.clone();!u.isZero();){for(var O=0,I=1;!(u.words[0]&I)&&O<26;++O,I<<=1);if(O>0)for(u.iushrn(O);O-- >0;)(m.isOdd()||g.isOdd())&&(m.iadd(c),g.isub(_)),m.iushrn(1),g.iushrn(1);for(var F=0,L=1;!(d.words[0]&L)&&F<26;++F,L<<=1);if(F>0)for(d.iushrn(F);F-- >0;)(y.isOdd()||M.isOdd())&&(y.iadd(c),M.isub(_)),y.iushrn(1),M.iushrn(1);u.cmp(d)>=0?(u.isub(d),m.isub(y),g.isub(M)):(d.isub(u),y.isub(m),M.isub(g))}return{a:y,b:M,gcd:d.iushln(p)}},s.prototype._invmp=function(o){r(o.negative===0),r(!o.isZero());var u=this,d=o.clone();u.negative!==0?u=u.umod(o):u=u.clone();for(var m=new s(1),g=new s(0),y=d.clone();u.cmpn(1)>0&&d.cmpn(1)>0;){for(var M=0,p=1;!(u.words[0]&p)&&M<26;++M,p<<=1);if(M>0)for(u.iushrn(M);M-- >0;)m.isOdd()&&m.iadd(y),m.iushrn(1);for(var c=0,_=1;!(d.words[0]&_)&&c<26;++c,_<<=1);if(c>0)for(d.iushrn(c);c-- >0;)g.isOdd()&&g.iadd(y),g.iushrn(1);u.cmp(d)>=0?(u.isub(d),m.isub(g)):(d.isub(u),g.isub(m))}var O;return u.cmpn(1)===0?O=m:O=g,O.cmpn(0)<0&&O.iadd(o),O},s.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var u=this.clone(),d=o.clone();u.negative=0,d.negative=0;for(var m=0;u.isEven()&&d.isEven();m++)u.iushrn(1),d.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;d.isEven();)d.iushrn(1);var g=u.cmp(d);if(g<0){var y=u;u=d,d=y}else if(g===0||d.cmpn(1)===0)break;u.isub(d)}while(!0);return d.iushln(m)},s.prototype.invm=function(o){return this.egcd(o).a.umod(o)},s.prototype.isEven=function(){return(this.words[0]&1)===0},s.prototype.isOdd=function(){return(this.words[0]&1)===1},s.prototype.andln=function(o){return this.words[0]&o},s.prototype.bincn=function(o){r(typeof o=="number");var u=o%26,d=(o-u)/26,m=1<<u;if(this.length<=d)return this._expand(d+1),this.words[d]|=m,this;for(var g=m,y=d;g!==0&&y<this.length;y++){var M=this.words[y]|0;M+=g,g=M>>>26,M&=67108863,this.words[y]=M}return g!==0&&(this.words[y]=g,this.length++),this},s.prototype.isZero=function(){return this.length===1&&this.words[0]===0},s.prototype.cmpn=function(o){var u=o<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var d;if(this.length>1)d=1;else{u&&(o=-o),r(o<=67108863,"Number is too big");var m=this.words[0]|0;d=m===o?0:m<o?-1:1}return this.negative!==0?-d|0:d},s.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var u=this.ucmp(o);return this.negative!==0?-u|0:u},s.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var u=0,d=this.length-1;d>=0;d--){var m=this.words[d]|0,g=o.words[d]|0;if(m!==g){m<g?u=-1:m>g&&(u=1);break}}return u},s.prototype.gtn=function(o){return this.cmpn(o)===1},s.prototype.gt=function(o){return this.cmp(o)===1},s.prototype.gten=function(o){return this.cmpn(o)>=0},s.prototype.gte=function(o){return this.cmp(o)>=0},s.prototype.ltn=function(o){return this.cmpn(o)===-1},s.prototype.lt=function(o){return this.cmp(o)===-1},s.prototype.lten=function(o){return this.cmpn(o)<=0},s.prototype.lte=function(o){return this.cmp(o)<=0},s.prototype.eqn=function(o){return this.cmpn(o)===0},s.prototype.eq=function(o){return this.cmp(o)===0},s.red=function(o){return new $(o)},s.prototype.toRed=function(o){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),o.convertTo(this)._forceRed(o)},s.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(o){return this.red=o,this},s.prototype.forceRed=function(o){return r(!this.red,"Already a number in reduction context"),this._forceRed(o)},s.prototype.redAdd=function(o){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},s.prototype.redIAdd=function(o){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},s.prototype.redSub=function(o){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},s.prototype.redISub=function(o){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},s.prototype.redShl=function(o){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},s.prototype.redMul=function(o){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},s.prototype.redIMul=function(o){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},s.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(o){return r(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var Lt={k256:null,p224:null,p192:null,p25519:null};function X(o,u){this.name=o,this.p=new s(u,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}X.prototype._tmp=function(){var o=new s(null);return o.words=new Array(Math.ceil(this.n/13)),o},X.prototype.ireduce=function(o){var u=o,d;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),d=u.bitLength();while(d>this.n);var m=d<this.n?-1:u.ucmp(this.p);return m===0?(u.words[0]=0,u.length=1):m>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},X.prototype.split=function(o,u){o.iushrn(this.n,0,u)},X.prototype.imulK=function(o){return o.imul(this.k)};function Z(){X.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a(Z,X),Z.prototype.split=function(o,u){for(var d=4194303,m=Math.min(o.length,9),g=0;g<m;g++)u.words[g]=o.words[g];if(u.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var y=o.words[9];for(u.words[u.length++]=y&d,g=10;g<o.length;g++){var M=o.words[g]|0;o.words[g-10]=(M&d)<<4|y>>>22,y=M}y>>>=22,o.words[g-10]=y,y===0&&o.length>10?o.length-=10:o.length-=9},Z.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var u=0,d=0;d<o.length;d++){var m=o.words[d]|0;u+=m*977,o.words[d]=u&67108863,u=m*64+(u/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function z(){X.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}a(z,X);function Q(){X.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}a(Q,X);function jt(){X.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}a(jt,X),jt.prototype.imulK=function(o){for(var u=0,d=0;d<o.length;d++){var m=(o.words[d]|0)*19+u,g=m&67108863;m>>>=26,o.words[d]=g,u=m}return u!==0&&(o.words[o.length++]=u),o},s._prime=function(o){if(Lt[o])return Lt[o];var u;if(o==="k256")u=new Z;else if(o==="p224")u=new z;else if(o==="p192")u=new Q;else if(o==="p25519")u=new jt;else throw new Error("Unknown prime "+o);return Lt[o]=u,u};function $(o){if(typeof o=="string"){var u=s._prime(o);this.m=u.p,this.prime=u}else r(o.gtn(1),"modulus must be greater than 1"),this.m=o,this.prime=null}$.prototype._verify1=function(o){r(o.negative===0,"red works only with positives"),r(o.red,"red works only with red numbers")},$.prototype._verify2=function(o,u){r((o.negative|u.negative)===0,"red works only with positives"),r(o.red&&o.red===u.red,"red works only with red numbers")},$.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(w(o,o.umod(this.m)._forceRed(this)),o)},$.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},$.prototype.add=function(o,u){this._verify2(o,u);var d=o.add(u);return d.cmp(this.m)>=0&&d.isub(this.m),d._forceRed(this)},$.prototype.iadd=function(o,u){this._verify2(o,u);var d=o.iadd(u);return d.cmp(this.m)>=0&&d.isub(this.m),d},$.prototype.sub=function(o,u){this._verify2(o,u);var d=o.sub(u);return d.cmpn(0)<0&&d.iadd(this.m),d._forceRed(this)},$.prototype.isub=function(o,u){this._verify2(o,u);var d=o.isub(u);return d.cmpn(0)<0&&d.iadd(this.m),d},$.prototype.shl=function(o,u){return this._verify1(o),this.imod(o.ushln(u))},$.prototype.imul=function(o,u){return this._verify2(o,u),this.imod(o.imul(u))},$.prototype.mul=function(o,u){return this._verify2(o,u),this.imod(o.mul(u))},$.prototype.isqr=function(o){return this.imul(o,o.clone())},$.prototype.sqr=function(o){return this.mul(o,o)},$.prototype.sqrt=function(o){if(o.isZero())return o.clone();var u=this.m.andln(3);if(r(u%2===1),u===3){var d=this.m.add(new s(1)).iushrn(2);return this.pow(o,d)}for(var m=this.m.subn(1),g=0;!m.isZero()&&m.andln(1)===0;)g++,m.iushrn(1);r(!m.isZero());var y=new s(1).toRed(this),M=y.redNeg(),p=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new s(2*c*c).toRed(this);this.pow(c,p).cmp(M)!==0;)c.redIAdd(M);for(var _=this.pow(c,m),O=this.pow(o,m.addn(1).iushrn(1)),I=this.pow(o,m),F=g;I.cmp(y)!==0;){for(var L=I,U=0;L.cmp(y)!==0;U++)L=L.redSqr();r(U<F);var W=this.pow(_,new s(1).iushln(F-U-1));O=O.redMul(W),_=W.redSqr(),I=I.redMul(_),F=U}return O},$.prototype.invm=function(o){var u=o._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},$.prototype.pow=function(o,u){if(u.isZero())return new s(1).toRed(this);if(u.cmpn(1)===0)return o.clone();var d=4,m=new Array(1<<d);m[0]=new s(1).toRed(this),m[1]=o;for(var g=2;g<m.length;g++)m[g]=this.mul(m[g-1],o);var y=m[0],M=0,p=0,c=u.bitLength()%26;for(c===0&&(c=26),g=u.length-1;g>=0;g--){for(var _=u.words[g],O=c-1;O>=0;O--){var I=_>>O&1;if(y!==m[0]&&(y=this.sqr(y)),I===0&&M===0){p=0;continue}M<<=1,M|=I,p++,!(p!==d&&(g!==0||O!==0))&&(y=this.mul(y,m[M]),p=0,M=0)}c=26}return y},$.prototype.convertTo=function(o){var u=o.umod(this.m);return u===o?u.clone():u},$.prototype.convertFrom=function(o){var u=o.clone();return u.red=null,u},s.mont=function(o){return new et(o)};function et(o){$.call(this,o),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new s(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(et,$),et.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},et.prototype.convertFrom=function(o){var u=this.imod(o.mul(this.rinv));return u.red=null,u},et.prototype.imul=function(o,u){if(o.isZero()||u.isZero())return o.words[0]=0,o.length=1,o;var d=o.imul(u),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=d.isub(m).iushrn(this.shift),y=g;return g.cmp(this.m)>=0?y=g.isub(this.m):g.cmpn(0)<0&&(y=g.iadd(this.m)),y._forceRed(this)},et.prototype.mul=function(o,u){if(o.isZero()||u.isZero())return new s(0)._forceRed(this);var d=o.mul(u),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=d.isub(m).iushrn(this.shift),y=g;return g.cmp(this.m)>=0?y=g.isub(this.m):g.cmpn(0)<0&&(y=g.iadd(this.m)),y._forceRed(this)},et.prototype.invm=function(o){var u=this.imod(o._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof t>"u"||t,i)}),Si={REQUEST_PARAMS:"requestParams",METHOD_NAME:"methodName"},gr=class kn extends Error{constructor(t,e,n){super(t),this.code=e,this.details=n,this.name=this.constructor.name}static{this.DETAILS_KEYS=Si}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 kn&&t.code===e}},_r=class extends gr{constructor(i,t,e){super(i,t||"UnknownError",e)}static isCommonErrorCode(i,t){return this.isErrorCode(i,t)}},zt=(i,t,e)=>{throw new _r(t,i,e)},ee="0x0000000000000000000000000000000000000000000000000000000000000006";var Ko=(0,Ei.getFullnodeUrl)("mainnet"),Zo=(0,Ei.getFullnodeUrl)("testnet");var Pn=864e5;var ye=9e15,me=1e9,Ci="0123456789abcdef",Ue="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",$e="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",xi={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ye,maxE:ye,crypto:!1},En,ne,R=!0,Xe="[DecimalError] ",he=Xe+"Invalid argument: ",On=Xe+"Precision limit exceeded",In=Xe+"crypto unavailable",Tn="[object Decimal]",Zt=Math.floor,Rt=Math.pow,Mr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Sr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ar=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Nn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Gt=1e7,D=7,Cr=9007199254740991,xr=Ue.length-1,ki=$e.length-1,A={toStringTag:Tn};A.absoluteValue=A.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),T(i)};A.ceil=function(){return T(new this.constructor(this),this.e+1,2)};A.clampedTo=A.clamp=function(i,t){var e,n=this,r=n.constructor;if(i=new r(i),t=new r(t),!i.s||!t.s)return new r(NaN);if(i.gt(t))throw Error(he+t);return e=n.cmp(i),e<0?i:n.cmp(t)>0?t:new r(n)};A.comparedTo=A.cmp=function(i){var t,e,n,r,a=this,s=a.d,l=(i=new a.constructor(i)).d,f=a.s,h=i.s;if(!s||!l)return!f||!h?NaN:f!==h?f:s===l?0:!s^f<0?1:-1;if(!s[0]||!l[0])return s[0]?f:l[0]?-h:0;if(f!==h)return f;if(a.e!==i.e)return a.e>i.e^f<0?1:-1;for(n=s.length,r=l.length,t=0,e=n<r?n:r;t<e;++t)if(s[t]!==l[t])return s[t]>l[t]^f<0?1:-1;return n===r?0:n>r^f<0?1:-1};A.cosine=A.cos=function(){var i,t,e=this,n=e.constructor;return e.d?e.d[0]?(i=n.precision,t=n.rounding,n.precision=i+Math.max(e.e,e.sd())+D,n.rounding=1,e=kr(n,Vn(n,e)),n.precision=i,n.rounding=t,T(ne==2||ne==3?e.neg():e,i,t,!0)):new n(1):new n(NaN)};A.cubeRoot=A.cbrt=function(){var i,t,e,n,r,a,s,l,f,h,b=this,w=b.constructor;if(!b.isFinite()||b.isZero())return new w(b);for(R=!1,a=b.s*Rt(b.s*b,1/3),!a||Math.abs(a)==1/0?(e=Ut(b.d),i=b.e,(a=(i-e.length+1)%3)&&(e+=a==1||a==-2?"0":"00"),a=Rt(e,1/3),i=Zt((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 w(e),n.s=b.s):n=new w(a.toString()),s=(i=w.precision)+3;;)if(l=n,f=l.times(l).times(l),h=f.plus(b),n=H(h.plus(b).times(l),h.plus(f),s+2,1),Ut(l.d).slice(0,s)===(e=Ut(n.d)).slice(0,s))if(e=e.slice(s-3,s+1),e=="9999"||!r&&e=="4999"){if(!r&&(T(l,i+1,0),l.times(l).times(l).eq(b))){n=l;break}s+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(T(n,i+1,1),t=!n.times(n).times(n).eq(b));break}return R=!0,T(n,i,w.rounding,t)};A.decimalPlaces=A.dp=function(){var i,t=this.d,e=NaN;if(t){if(i=t.length-1,e=(i-Zt(this.e/D))*D,i=t[i],i)for(;i%10==0;i/=10)e--;e<0&&(e=0)}return e};A.dividedBy=A.div=function(i){return H(this,new this.constructor(i))};A.dividedToIntegerBy=A.divToInt=function(i){var t=this,e=t.constructor;return T(H(t,new e(i),0,1,1),e.precision,e.rounding)};A.equals=A.eq=function(i){return this.cmp(i)===0};A.floor=function(){return T(new this.constructor(this),this.e+1,3)};A.greaterThan=A.gt=function(i){return this.cmp(i)>0};A.greaterThanOrEqualTo=A.gte=function(i){var t=this.cmp(i);return t==1||t===0};A.hyperbolicCosine=A.cosh=function(){var i,t,e,n,r,a=this,s=a.constructor,l=new s(1);if(!a.isFinite())return new s(a.s?1/0:NaN);if(a.isZero())return l;e=s.precision,n=s.rounding,s.precision=e+Math.max(a.e,a.sd())+4,s.rounding=1,r=a.d.length,r<32?(i=Math.ceil(r/3),t=(1/ze(4,i)).toString()):(i=16,t="2.3283064365386962890625e-10"),a=Me(s,1,a.times(t),new s(1),!0);for(var f,h=i,b=new s(8);h--;)f=a.times(a),a=l.minus(f.times(b.minus(f.times(b))));return T(a,s.precision=e,s.rounding=n,!0)};A.hyperbolicSine=A.sinh=function(){var i,t,e,n,r=this,a=r.constructor;if(!r.isFinite()||r.isZero())return new a(r);if(t=a.precision,e=a.rounding,a.precision=t+Math.max(r.e,r.sd())+4,a.rounding=1,n=r.d.length,n<3)r=Me(a,2,r,r,!0);else{i=1.4*Math.sqrt(n),i=i>16?16:i|0,r=r.times(1/ze(5,i)),r=Me(a,2,r,r,!0);for(var s,l=new a(5),f=new a(16),h=new a(20);i--;)s=r.times(r),r=r.times(l.plus(s.times(f.times(s).plus(h))))}return a.precision=t,a.rounding=e,T(r,t,e,!0)};A.hyperbolicTangent=A.tanh=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+7,n.rounding=1,H(e.sinh(),e.cosh(),n.precision=i,n.rounding=t)):new n(e.s)};A.inverseCosine=A.acos=function(){var i=this,t=i.constructor,e=i.abs().cmp(1),n=t.precision,r=t.rounding;return e!==-1?e===0?i.isNeg()?Qt(t,n,r):new t(0):new t(NaN):i.isZero()?Qt(t,n+4,r).times(.5):(t.precision=n+6,t.rounding=1,i=new t(1).minus(i).div(i.plus(1)).sqrt().atan(),t.precision=n,t.rounding=r,i.times(2))};A.inverseHyperbolicCosine=A.acosh=function(){var i,t,e=this,n=e.constructor;return e.lte(1)?new n(e.eq(1)?0:NaN):e.isFinite()?(i=n.precision,t=n.rounding,n.precision=i+Math.max(Math.abs(e.e),e.sd())+4,n.rounding=1,R=!1,e=e.times(e).minus(1).sqrt().plus(e),R=!0,n.precision=i,n.rounding=t,e.ln()):new n(e)};A.inverseHyperbolicSine=A.asinh=function(){var i,t,e=this,n=e.constructor;return!e.isFinite()||e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+2*Math.max(Math.abs(e.e),e.sd())+6,n.rounding=1,R=!1,e=e.times(e).plus(1).sqrt().plus(e),R=!0,n.precision=i,n.rounding=t,e.ln())};A.inverseHyperbolicTangent=A.atanh=function(){var i,t,e,n,r=this,a=r.constructor;return r.isFinite()?r.e>=0?new a(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(i=a.precision,t=a.rounding,n=r.sd(),Math.max(n,i)<2*-r.e-1?T(new a(r),i,t,!0):(a.precision=e=n-r.e,r=H(r.plus(1),new a(1).minus(r),e+i,1),a.precision=i+4,a.rounding=1,r=r.ln(),a.precision=i,a.rounding=t,r.times(.5))):new a(NaN)};A.inverseSine=A.asin=function(){var i,t,e,n,r=this,a=r.constructor;return r.isZero()?new a(r):(t=r.abs().cmp(1),e=a.precision,n=a.rounding,t!==-1?t===0?(i=Qt(a,e+4,n).times(.5),i.s=r.s,i):new a(NaN):(a.precision=e+6,a.rounding=1,r=r.div(new a(1).minus(r.times(r)).sqrt().plus(1)).atan(),a.precision=e,a.rounding=n,r.times(2)))};A.inverseTangent=A.atan=function(){var i,t,e,n,r,a,s,l,f,h=this,b=h.constructor,w=b.precision,v=b.rounding;if(h.isFinite()){if(h.isZero())return new b(h);if(h.abs().eq(1)&&w+4<=ki)return s=Qt(b,w+4,v).times(.25),s.s=h.s,s}else{if(!h.s)return new b(NaN);if(w+4<=ki)return s=Qt(b,w+4,v).times(.5),s.s=h.s,s}for(b.precision=l=w+10,b.rounding=1,e=Math.min(28,l/D+2|0),i=e;i;--i)h=h.div(h.times(h).plus(1).sqrt().plus(1));for(R=!1,t=Math.ceil(l/D),n=1,f=h.times(h),s=new b(h),r=h;i!==-1;)if(r=r.times(f),a=s.minus(r.div(n+=2)),r=r.times(f),s=a.plus(r.div(n+=2)),s.d[t]!==void 0)for(i=t;s.d[i]===a.d[i]&&i--;);return e&&(s=s.times(2<<e-1)),R=!0,T(s,b.precision=w,b.rounding=v,!0)};A.isFinite=function(){return!!this.d};A.isInteger=A.isInt=function(){return!!this.d&&Zt(this.e/D)>this.d.length-2};A.isNaN=function(){return!this.s};A.isNegative=A.isNeg=function(){return this.s<0};A.isPositive=A.isPos=function(){return this.s>0};A.isZero=function(){return!!this.d&&this.d[0]===0};A.lessThan=A.lt=function(i){return this.cmp(i)<0};A.lessThanOrEqualTo=A.lte=function(i){return this.cmp(i)<1};A.logarithm=A.log=function(i){var t,e,n,r,a,s,l,f,h=this,b=h.constructor,w=b.precision,v=b.rounding,S=5;if(i==null)i=new b(10),t=!0;else{if(i=new b(i),e=i.d,i.s<0||!e||!e[0]||i.eq(1))return new b(NaN);t=i.eq(10)}if(e=h.d,h.s<0||!e||!e[0]||h.eq(1))return new b(e&&!e[0]?-1/0:h.s!=1?NaN:e?0:1/0);if(t)if(e.length>1)a=!0;else{for(r=e[0];r%10===0;)r/=10;a=r!==1}if(R=!1,l=w+S,s=de(h,l),n=t?Ke(b,l+10):de(i,l),f=H(s,n,l,1),ke(f.d,r=w,v))do if(l+=10,s=de(h,l),n=t?Ke(b,l+10):de(i,l),f=H(s,n,l,1),!a){+Ut(f.d).slice(r+1,r+15)+1==1e14&&(f=T(f,w+1,0));break}while(ke(f.d,r+=10,v));return R=!0,T(f,w,v)};A.minus=A.sub=function(i){var t,e,n,r,a,s,l,f,h,b,w,v,S=this,C=S.constructor;if(i=new C(i),!S.d||!i.d)return!S.s||!i.s?i=new C(NaN):S.d?i.s=-i.s:i=new C(i.d||S.s!==i.s?S:NaN),i;if(S.s!=i.s)return i.s=-i.s,S.plus(i);if(h=S.d,v=i.d,l=C.precision,f=C.rounding,!h[0]||!v[0]){if(v[0])i.s=-i.s;else if(h[0])i=new C(S);else return new C(f===3?-0:0);return R?T(i,l,f):i}if(e=Zt(i.e/D),b=Zt(S.e/D),h=h.slice(),a=b-e,a){for(w=a<0,w?(t=h,a=-a,s=v.length):(t=v,e=b,s=h.length),n=Math.max(Math.ceil(l/D),s)+2,a>n&&(a=n,t.length=1),t.reverse(),n=a;n--;)t.push(0);t.reverse()}else{for(n=h.length,s=v.length,w=n<s,w&&(s=n),n=0;n<s;n++)if(h[n]!=v[n]){w=h[n]<v[n];break}a=0}for(w&&(t=h,h=v,v=t,i.s=-i.s),s=h.length,n=v.length-s;n>0;--n)h[s++]=0;for(n=v.length;n>a;){if(h[--n]<v[n]){for(r=n;r&&h[--r]===0;)h[r]=Gt-1;--h[r],h[n]+=Gt}h[n]-=v[n]}for(;h[--s]===0;)h.pop();for(;h[0]===0;h.shift())--e;return h[0]?(i.d=h,i.e=He(h,e),R?T(i,l,f):i):new C(f===3?-0:0)};A.modulo=A.mod=function(i){var t,e=this,n=e.constructor;return i=new n(i),!e.d||!i.s||i.d&&!i.d[0]?new n(NaN):!i.d||e.d&&!e.d[0]?T(new n(e),n.precision,n.rounding):(R=!1,n.modulo==9?(t=H(e,i.abs(),0,3,1),t.s*=i.s):t=H(e,i,0,n.modulo,1),t=t.times(i),R=!0,e.minus(t))};A.naturalExponential=A.exp=function(){return Pi(this)};A.naturalLogarithm=A.ln=function(){return de(this)};A.negated=A.neg=function(){var i=new this.constructor(this);return i.s=-i.s,T(i)};A.plus=A.add=function(i){var t,e,n,r,a,s,l,f,h,b,w=this,v=w.constructor;if(i=new v(i),!w.d||!i.d)return!w.s||!i.s?i=new v(NaN):w.d||(i=new v(i.d||w.s===i.s?w:NaN)),i;if(w.s!=i.s)return i.s=-i.s,w.minus(i);if(h=w.d,b=i.d,l=v.precision,f=v.rounding,!h[0]||!b[0])return b[0]||(i=new v(w)),R?T(i,l,f):i;if(a=Zt(w.e/D),n=Zt(i.e/D),h=h.slice(),r=a-n,r){for(r<0?(e=h,r=-r,s=b.length):(e=b,n=a,s=h.length),a=Math.ceil(l/D),s=a>s?a+1:s+1,r>s&&(r=s,e.length=1),e.reverse();r--;)e.push(0);e.reverse()}for(s=h.length,r=b.length,s-r<0&&(r=s,e=b,b=h,h=e),t=0;r;)t=(h[--r]=h[r]+b[r]+t)/Gt|0,h[r]%=Gt;for(t&&(h.unshift(t),++n),s=h.length;h[--s]==0;)h.pop();return i.d=h,i.e=He(h,n),R?T(i,l,f):i};A.precision=A.sd=function(i){var t,e=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(he+i);return e.d?(t=Fn(e.d),i&&e.e+1>t&&(t=e.e+1)):t=NaN,t};A.round=function(){var i=this,t=i.constructor;return T(new t(i),i.e+1,t.rounding)};A.sine=A.sin=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+Math.max(e.e,e.sd())+D,n.rounding=1,e=Er(n,Vn(n,e)),n.precision=i,n.rounding=t,T(ne>2?e.neg():e,i,t,!0)):new n(NaN)};A.squareRoot=A.sqrt=function(){var i,t,e,n,r,a,s=this,l=s.d,f=s.e,h=s.s,b=s.constructor;if(h!==1||!l||!l[0])return new b(!h||h<0&&(!l||l[0])?NaN:l?s:1/0);for(R=!1,h=Math.sqrt(+s),h==0||h==1/0?(t=Ut(l),(t.length+f)%2==0&&(t+="0"),h=Math.sqrt(t),f=Zt((f+1)/2)-(f<0||f%2),h==1/0?t="5e"+f:(t=h.toExponential(),t=t.slice(0,t.indexOf("e")+1)+f),n=new b(t)):n=new b(h.toString()),e=(f=b.precision)+3;;)if(a=n,n=a.plus(H(s,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&&(T(a,f+1,0),a.times(a).eq(s))){n=a;break}e+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(T(n,f+1,1),i=!n.times(n).eq(s));break}return R=!0,T(n,f,b.rounding,i)};A.tangent=A.tan=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+10,n.rounding=1,e=e.sin(),e.s=1,e=H(e,new n(1).minus(e.times(e)).sqrt(),i+10,0),n.precision=i,n.rounding=t,T(ne==2||ne==4?e.neg():e,i,t,!0)):new n(NaN)};A.times=A.mul=function(i){var t,e,n,r,a,s,l,f,h,b=this,w=b.constructor,v=b.d,S=(i=new w(i)).d;if(i.s*=b.s,!v||!v[0]||!S||!S[0])return new w(!i.s||v&&!v[0]&&!S||S&&!S[0]&&!v?NaN:!v||!S?i.s/0:i.s*0);for(e=Zt(b.e/D)+Zt(i.e/D),f=v.length,h=S.length,f<h&&(a=v,v=S,S=a,s=f,f=h,h=s),a=[],s=f+h,n=s;n--;)a.push(0);for(n=h;--n>=0;){for(t=0,r=f+n;r>n;)l=a[r]+S[n]*v[r-n-1]+t,a[r--]=l%Gt|0,t=l/Gt|0;a[r]=(a[r]+t)%Gt|0}for(;!a[--s];)a.pop();return t?++e:a.shift(),i.d=a,i.e=He(a,e),R?T(i,w.precision,w.rounding):i};A.toBinary=function(i,t){return Oi(this,2,i,t)};A.toDecimalPlaces=A.toDP=function(i,t){var e=this,n=e.constructor;return e=new n(e),i===void 0?e:(Xt(i,0,me),t===void 0?t=n.rounding:Xt(t,0,8),T(e,i+e.e+1,t))};A.toExponential=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=te(n,!0):(Xt(i,0,me),t===void 0?t=r.rounding:Xt(t,0,8),n=T(new r(n),i+1,t),e=te(n,!0,i+1)),n.isNeg()&&!n.isZero()?"-"+e:e};A.toFixed=function(i,t){var e,n,r=this,a=r.constructor;return i===void 0?e=te(r):(Xt(i,0,me),t===void 0?t=a.rounding:Xt(t,0,8),n=T(new a(r),i+r.e+1,t),e=te(n,!1,i+n.e+1)),r.isNeg()&&!r.isZero()?"-"+e:e};A.toFraction=function(i){var t,e,n,r,a,s,l,f,h,b,w,v,S=this,C=S.d,x=S.constructor;if(!C)return new x(S);if(h=e=new x(1),n=f=new x(0),t=new x(n),a=t.e=Fn(C)-S.e-1,s=a%D,t.d[0]=Rt(10,s<0?D+s:s),i==null)i=a>0?t:h;else{if(l=new x(i),!l.isInt()||l.lt(h))throw Error(he+l);i=l.gt(t)?a>0?t:h:l}for(R=!1,l=new x(Ut(C)),b=x.precision,x.precision=a=C.length*D*2;w=H(l,t,0,1,1),r=e.plus(w.times(n)),r.cmp(i)!=1;)e=n,n=r,r=h,h=f.plus(w.times(r)),f=r,r=t,t=l.minus(w.times(r)),l=r;return r=H(i.minus(e),n,0,1,1),f=f.plus(r.times(h)),e=e.plus(r.times(n)),f.s=h.s=S.s,v=H(h,n,a,1).minus(S).abs().cmp(H(f,e,a,1).minus(S).abs())<1?[h,n]:[f,e],x.precision=b,R=!0,v};A.toHexadecimal=A.toHex=function(i,t){return Oi(this,16,i,t)};A.toNearest=function(i,t){var e=this,n=e.constructor;if(e=new n(e),i==null){if(!e.d)return e;i=new n(1),t=n.rounding}else{if(i=new n(i),t===void 0?t=n.rounding: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]?(R=!1,e=H(e,i,0,t,1).times(i),R=!0,T(e)):(i.s=e.s,e=i),e};A.toNumber=function(){return+this};A.toOctal=function(i,t){return Oi(this,8,i,t)};A.toPower=A.pow=function(i){var t,e,n,r,a,s,l=this,f=l.constructor,h=+(i=new f(i));if(!l.d||!i.d||!l.d[0]||!i.d[0])return new f(Rt(+l,h));if(l=new f(l),l.eq(1))return l;if(n=f.precision,a=f.rounding,i.eq(1))return T(l,n,a);if(t=Zt(i.e/D),t>=i.d.length-1&&(e=h<0?-h:h)<=Cr)return r=Bn(f,l,e,n),i.s<0?new f(1).div(r):T(r,n,a);if(s=l.s,s<0){if(t<i.d.length-1)return new f(NaN);if(!(i.d[t]&1)&&(s=1),l.e==0&&l.d[0]==1&&l.d.length==1)return l.s=s,l}return e=Rt(+l,h),t=e==0||!isFinite(e)?Zt(h*(Math.log("0."+Ut(l.d))/Math.LN10+l.e+1)):new f(e+"").e,t>f.maxE+1||t<f.minE-1?new f(t>0?s/0:0):(R=!1,f.rounding=l.s=1,e=Math.min(12,(t+"").length),r=Pi(i.times(de(l,n+e)),n),r.d&&(r=T(r,n+5,1),ke(r.d,n,a)&&(t=n+10,r=T(Pi(i.times(de(l,t+e)),t),t+5,1),+Ut(r.d).slice(n+1,n+15)+1==1e14&&(r=T(r,n+1,0)))),r.s=s,R=!0,f.rounding=a,T(r,n,a))};A.toPrecision=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=te(n,n.e<=r.toExpNeg||n.e>=r.toExpPos):(Xt(i,1,me),t===void 0?t=r.rounding:Xt(t,0,8),n=T(new r(n),i,t),e=te(n,i<=n.e||n.e<=r.toExpNeg,i)),n.isNeg()&&!n.isZero()?"-"+e:e};A.toSignificantDigits=A.toSD=function(i,t){var e=this,n=e.constructor;return i===void 0?(i=n.precision,t=n.rounding):(Xt(i,1,me),t===void 0?t=n.rounding:Xt(t,0,8)),T(new n(e),i,t)};A.toString=function(){var i=this,t=i.constructor,e=te(i,i.e<=t.toExpNeg||i.e>=t.toExpPos);return i.isNeg()&&!i.isZero()?"-"+e:e};A.truncated=A.trunc=function(){return T(new this.constructor(this),this.e+1,1)};A.valueOf=A.toJSON=function(){var i=this,t=i.constructor,e=te(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="",s=i[0];if(r>0){for(a+=s,t=1;t<r;t++)n=i[t]+"",e=D-n.length,e&&(a+=le(e)),a+=n;s=i[t],n=s+"",e=D-n.length,e&&(a+=le(e))}else if(s===0)return"0";for(;s%10===0;)s/=10;return a+s}function Xt(i,t,e){if(i!==~~i||i<t||i>e)throw Error(he+i)}function ke(i,t,e,n){var r,a,s,l;for(a=i[0];a>=10;a/=10)--t;return--t<0?(t+=D,r=0):(r=Math.ceil((t+1)/D),t%=D),a=Rt(10,D-t),l=i[r]%a|0,n==null?t<3?(t==0?l=l/100|0:t==1&&(l=l/10|0),s=e<4&&l==99999||e>3&&l==49999||l==5e4||l==0):s=(e<4&&l+1==a||e>3&&l+1==a/2)&&(i[r+1]/a/100|0)==Rt(10,t-2)-1||(l==a/2||l==0)&&(i[r+1]/a/100|0)==0:t<4?(t==0?l=l/1e3|0:t==1?l=l/100|0:t==2&&(l=l/10|0),s=(n||e<4)&&l==9999||!n&&e>3&&l==4999):s=((n||e<4)&&l+1==a||!n&&e>3&&l+1==a/2)&&(i[r+1]/a/1e3|0)==Rt(10,t-3)-1,s}function Le(i,t,e){for(var n,r=[0],a,s=0,l=i.length;s<l;){for(a=r.length;a--;)r[a]*=t;for(r[0]+=Ci.indexOf(i.charAt(s++)),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 kr(i,t){var e,n,r;if(t.isZero())return t;n=t.d.length,n<32?(e=Math.ceil(n/3),r=(1/ze(4,e)).toString()):(e=16,r="2.3283064365386962890625e-10"),i.precision+=e,t=Me(i,1,t.times(r),new i(1));for(var a=e;a--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return i.precision-=e,t}var H=function(){function i(n,r,a){var s,l=0,f=n.length;for(n=n.slice();f--;)s=n[f]*r+l,n[f]=s%a|0,l=s/a|0;return l&&n.unshift(l),n}function t(n,r,a,s){var l,f;if(a!=s)f=a>s?1:-1;else for(l=f=0;l<a;l++)if(n[l]!=r[l]){f=n[l]>r[l]?1:-1;break}return f}function e(n,r,a,s){for(var l=0;a--;)n[a]-=l,l=n[a]<r[a]?1:0,n[a]=l*s+n[a]-r[a];for(;!n[0]&&n.length>1;)n.shift()}return function(n,r,a,s,l,f){var h,b,w,v,S,C,x,N,E,q,k,V,qt,K,Lt,X,Z,z,Q,jt,$=n.constructor,et=n.s==r.s?1:-1,o=n.d,u=r.d;if(!o||!o[0]||!u||!u[0])return new $(!n.s||!r.s||(o?u&&o[0]==u[0]:!u)?NaN:o&&o[0]==0||!u?et*0:et/0);for(f?(S=1,b=n.e-r.e):(f=Gt,S=D,b=Zt(n.e/S)-Zt(r.e/S)),Q=u.length,Z=o.length,E=new $(et),q=E.d=[],w=0;u[w]==(o[w]||0);w++);if(u[w]>(o[w]||0)&&b--,a==null?(K=a=$.precision,s=$.rounding):l?K=a+(n.e-r.e)+1:K=a,K<0)q.push(1),C=!0;else{if(K=K/S+2|0,w=0,Q==1){for(v=0,u=u[0],K++;(w<Z||v)&&K--;w++)Lt=v*f+(o[w]||0),q[w]=Lt/u|0,v=Lt%u|0;C=v||w<Z}else{for(v=f/(u[0]+1)|0,v>1&&(u=i(u,v,f),o=i(o,v,f),Q=u.length,Z=o.length),X=Q,k=o.slice(0,Q),V=k.length;V<Q;)k[V++]=0;jt=u.slice(),jt.unshift(0),z=u[0],u[1]>=f/2&&++z;do v=0,h=t(u,k,Q,V),h<0?(qt=k[0],Q!=V&&(qt=qt*f+(k[1]||0)),v=qt/z|0,v>1?(v>=f&&(v=f-1),x=i(u,v,f),N=x.length,V=k.length,h=t(x,k,N,V),h==1&&(v--,e(x,Q<N?jt:u,N,f))):(v==0&&(h=v=1),x=u.slice()),N=x.length,N<V&&x.unshift(0),e(k,x,V,f),h==-1&&(V=k.length,h=t(u,k,Q,V),h<1&&(v++,e(k,Q<V?jt:u,V,f))),V=k.length):h===0&&(v++,k=[0]),q[w++]=v,h&&k[0]?k[V++]=o[X]||0:(k=[o[X]],V=1);while((X++<Z||k[0]!==void 0)&&K--);C=k[0]!==void 0}q[0]||q.shift()}if(S==1)E.e=b,En=C;else{for(w=1,v=q[0];v>=10;v/=10)w++;E.e=w+b*S-1,T(E,l?a+E.e+1:a,s,C)}return E}}();function T(i,t,e,n){var r,a,s,l,f,h,b,w,v,S=i.constructor;t:if(t!=null){if(w=i.d,!w)return i;for(r=1,l=w[0];l>=10;l/=10)r++;if(a=t-r,a<0)a+=D,s=t,b=w[v=0],f=b/Rt(10,r-s-1)%10|0;else if(v=Math.ceil((a+1)/D),l=w.length,v>=l)if(n){for(;l++<=v;)w.push(0);b=f=0,r=1,a%=D,s=a-D+1}else break t;else{for(b=l=w[v],r=1;l>=10;l/=10)r++;a%=D,s=a-D+r,f=s<0?0:b/Rt(10,r-s-1)%10|0}if(n=n||t<0||w[v+1]!==void 0||(s<0?b:b%Rt(10,r-s-1)),h=e<4?(f||n)&&(e==0||e==(i.s<0?3:2)):f>5||f==5&&(e==4||n||e==6&&(a>0?s>0?b/Rt(10,r-s):0:w[v-1])%10&1||e==(i.s<0?8:7)),t<1||!w[0])return w.length=0,h?(t-=i.e+1,w[0]=Rt(10,(D-t%D)%D),i.e=-t||0):w[0]=i.e=0,i;if(a==0?(w.length=v,l=1,v--):(w.length=v+1,l=Rt(10,D-a),w[v]=s>0?(b/Rt(10,r-s)%Rt(10,s)|0)*l:0),h)for(;;)if(v==0){for(a=1,s=w[0];s>=10;s/=10)a++;for(s=w[0]+=l,l=1;s>=10;s/=10)l++;a!=l&&(i.e++,w[0]==Gt&&(w[0]=1));break}else{if(w[v]+=l,w[v]!=Gt)break;w[v--]=0,l=1}for(a=w.length;w[--a]===0;)w.pop()}return R&&(i.e>S.maxE?(i.d=null,i.e=NaN):i.e<S.minE&&(i.e=0,i.d=[0])),i}function te(i,t,e){if(!i.isFinite())return qn(i);var n,r=i.e,a=Ut(i.d),s=a.length;return t?(e&&(n=e-s)>0?a=a.charAt(0)+"."+a.slice(1)+le(n):s>1&&(a=a.charAt(0)+"."+a.slice(1)),a=a+(i.e<0?"e":"e+")+i.e):r<0?(a="0."+le(-r-1)+a,e&&(n=e-s)>0&&(a+=le(n))):r>=s?(a+=le(r+1-s),e&&(n=e-r-1)>0&&(a=a+"."+le(n))):((n=r+1)<s&&(a=a.slice(0,n)+"."+a.slice(n)),e&&(n=e-s)>0&&(r+1===s&&(a+="."),a+=le(n))),a}function He(i,t){var e=i[0];for(t*=D;e>=10;e/=10)t++;return t}function Ke(i,t,e){if(t>xr)throw R=!0,e&&(i.precision=e),Error(On);return T(new i(Ue),t,1,!0)}function Qt(i,t,e){if(t>ki)throw Error(On);return T(new i($e),t,e,!0)}function Fn(i){var t=i.length-1,e=t*D+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 le(i){for(var t="";i--;)t+="0";return t}function Bn(i,t,e,n){var r,a=new i(1),s=Math.ceil(n/D+4);for(R=!1;;){if(e%2&&(a=a.times(t),wn(a.d,s)&&(r=!0)),e=Zt(e/2),e===0){e=a.d.length-1,r&&a.d[e]===0&&++a.d[e];break}t=t.times(t),wn(t.d,s)}return R=!0,a}function bn(i){return i.d[i.d.length-1]&1}function Dn(i,t,e){for(var n,r,a=new i(t[0]),s=0;++s<t.length;){if(r=new i(t[s]),!r.s){a=r;break}n=a.cmp(r),(n===e||n===0&&a.s===e)&&(a=r)}return a}function Pi(i,t){var e,n,r,a,s,l,f,h=0,b=0,w=0,v=i.constructor,S=v.rounding,C=v.precision;if(!i.d||!i.d[0]||i.e>17)return new v(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(t==null?(R=!1,f=C):f=t,l=new v(.03125);i.e>-2;)i=i.times(l),w+=5;for(n=Math.log(Rt(2,w))/Math.LN10*2+5|0,f+=n,e=a=s=new v(1),v.precision=f;;){if(a=T(a.times(i),f,1),e=e.times(++b),l=s.plus(H(a,e,f,1)),Ut(l.d).slice(0,f)===Ut(s.d).slice(0,f)){for(r=w;r--;)s=T(s.times(s),f,1);if(t==null)if(h<3&&ke(s.d,f-n,S,h))v.precision=f+=10,e=a=l=new v(1),b=0,h++;else return T(s,v.precision=C,S,R=!0);else return v.precision=C,s}s=l}}function de(i,t){var e,n,r,a,s,l,f,h,b,w,v,S=1,C=10,x=i,N=x.d,E=x.constructor,q=E.rounding,k=E.precision;if(x.s<0||!N||!N[0]||!x.e&&N[0]==1&&N.length==1)return new E(N&&!N[0]?-1/0:x.s!=1?NaN:N?0:x);if(t==null?(R=!1,b=k):b=t,E.precision=b+=C,e=Ut(N),n=e.charAt(0),Math.abs(a=x.e)<15e14){for(;n<7&&n!=1||n==1&&e.charAt(1)>3;)x=x.times(i),e=Ut(x.d),n=e.charAt(0),S++;a=x.e,n>1?(x=new E("0."+e),a++):x=new E(n+"."+e.slice(1))}else return h=Ke(E,b+2,k).times(a+""),x=de(new E(n+"."+e.slice(1)),b-C).plus(h),E.precision=k,t==null?T(x,k,q,R=!0):x;for(w=x,f=s=x=H(x.minus(1),x.plus(1),b,1),v=T(x.times(x),b,1),r=3;;){if(s=T(s.times(v),b,1),h=f.plus(H(s,new E(r),b,1)),Ut(h.d).slice(0,b)===Ut(f.d).slice(0,b))if(f=f.times(2),a!==0&&(f=f.plus(Ke(E,b+2,k).times(a+""))),f=H(f,new E(S),b,1),t==null)if(ke(f.d,b-C,q,l))E.precision=b+=C,h=s=x=H(w.minus(1),w.plus(1),b,1),v=T(x.times(x),b,1),r=l=1;else return T(f,E.precision=k,q,R=!0);else return E.precision=k,f;f=h,r+=2}}function qn(i){return String(i.s*i.s/0)}function je(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)%D,e<0&&(n+=D),n<r){for(n&&i.d.push(+t.slice(0,n)),r-=D;n<r;)i.d.push(+t.slice(n,n+=D));t=t.slice(n),n=D-t.length}else n-=r;for(;n--;)t+="0";i.d.push(+t),R&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function Pr(i,t){var e,n,r,a,s,l,f,h,b;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Nn.test(t))return je(i,t)}else if(t==="Infinity"||t==="NaN")return+t||(i.s=NaN),i.e=NaN,i.d=null,i;if(Sr.test(t))e=16,t=t.toLowerCase();else if(Mr.test(t))e=2;else if(Ar.test(t))e=8;else throw Error(he+t);for(a=t.search(/p/i),a>0?(f=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf("."),s=a>=0,n=i.constructor,s&&(t=t.replace(".",""),l=t.length,a=l-a,r=Bn(n,new n(e),a,a*2)),h=Le(t,e,Gt),b=h.length-1,a=b;h[a]===0;--a)h.pop();return a<0?new n(i.s*0):(i.e=He(h,b),i.d=h,R=!1,s&&(i=H(i,r,l*4)),f&&(i=i.times(Math.abs(f)<54?Rt(2,f):Oe.pow(2,f))),R=!0,i)}function Er(i,t){var e,n=t.d.length;if(n<3)return t.isZero()?t:Me(i,2,t,t);e=1.4*Math.sqrt(n),e=e>16?16:e|0,t=t.times(1/ze(5,e)),t=Me(i,2,t,t);for(var r,a=new i(5),s=new i(16),l=new i(20);e--;)r=t.times(t),t=t.times(a.plus(r.times(s.times(r).minus(l))));return t}function Me(i,t,e,n,r){var a,s,l,f,h=1,b=i.precision,w=Math.ceil(b/D);for(R=!1,f=e.times(e),l=new i(n);;){if(s=H(l.times(f),new i(t++*t++),b,1),l=r?n.plus(s):n.minus(s),n=H(s.times(f),new i(t++*t++),b,1),s=l.plus(n),s.d[w]!==void 0){for(a=w;s.d[a]===l.d[a]&&a--;);if(a==-1)break}a=l,l=n,n=s,s=a,h++}return R=!0,s.d.length=w+1,s}function ze(i,t){for(var e=i;--t;)e*=i;return e}function Vn(i,t){var e,n=t.s<0,r=Qt(i,i.precision,1),a=r.times(.5);if(t=t.abs(),t.lte(a))return ne=n?4:1,t;if(e=t.divToInt(r),e.isZero())ne=n?3:2;else{if(t=t.minus(e.times(r)),t.lte(a))return ne=bn(e)?n?2:3:n?4:1,t;ne=bn(e)?n?1:4:n?3:2}return t.minus(r).abs()}function Oi(i,t,e,n){var r,a,s,l,f,h,b,w,v,S=i.constructor,C=e!==void 0;if(C?(Xt(e,1,me),n===void 0?n=S.rounding:Xt(n,0,8)):(e=S.precision,n=S.rounding),!i.isFinite())b=qn(i);else{for(b=te(i),s=b.indexOf("."),C?(r=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):r=t,s>=0&&(b=b.replace(".",""),v=new S(1),v.e=b.length-s,v.d=Le(te(v),10,r),v.e=v.d.length),w=Le(b,10,r),a=f=w.length;w[--f]==0;)w.pop();if(!w[0])b=C?"0p+0":"0";else{if(s<0?a--:(i=new S(i),i.d=w,i.e=a,i=H(i,v,e,n,0,r),w=i.d,a=i.e,h=En),s=w[e],l=r/2,h=h||w[e+1]!==void 0,h=n<4?(s!==void 0||h)&&(n===0||n===(i.s<0?3:2)):s>l||s===l&&(n===4||h||n===6&&w[e-1]&1||n===(i.s<0?8:7)),w.length=e,h)for(;++w[--e]>r-1;)w[e]=0,e||(++a,w.unshift(1));for(f=w.length;!w[f-1];--f);for(s=0,b="";s<f;s++)b+=Ci.charAt(w[s]);if(C){if(f>1)if(t==16||t==8){for(s=t==16?4:3,--f;f%s;f++)b+="0";for(w=Le(b,r,t),f=w.length;!w[f-1];--f);for(s=1,b="1.";s<f;s++)b+=Ci.charAt(w[s])}else b=b.charAt(0)+"."+b.slice(1);b=b+(a<0?"p":"p+")+a}else if(a<0){for(;++a;)b="0"+b;b="0."+b}else if(++a>f)for(a-=f;a--;)b+="0";else a<f&&(b=b.slice(0,a)+"."+b.slice(a))}b=(t==16?"0x":t==2?"0b":t==8?"0o":"")+b}return i.s<0?"-"+b:b}function wn(i,t){if(i.length>t)return i.length=t,!0}function Or(i){return new this(i).abs()}function Ir(i){return new this(i).acos()}function Tr(i){return new this(i).acosh()}function Nr(i,t){return new this(i).plus(t)}function Fr(i){return new this(i).asin()}function Br(i){return new this(i).asinh()}function Dr(i){return new this(i).atan()}function qr(i){return new this(i).atanh()}function Vr(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=Qt(this,a,1).times(t.s>0?.25:.75),e.s=i.s):!t.d||i.isZero()?(e=t.s<0?Qt(this,n,r):new this(0),e.s=i.s):!i.d||t.isZero()?(e=Qt(this,a,1).times(.5),e.s=i.s):t.s<0?(this.precision=a,this.rounding=1,e=this.atan(H(i,t,a,1)),t=Qt(this,a,1),this.precision=n,this.rounding=r,e=i.s<0?e.minus(t):e.plus(t)):e=this.atan(H(i,t,a,1)),e}function Rr(i){return new this(i).cbrt()}function Lr(i){return T(i=new this(i),i.e+1,2)}function jr(i,t,e){return new this(i).clamp(t,e)}function Ur(i){if(!i||typeof i!="object")throw Error(Xe+"Object expected");var t,e,n,r=i.defaults===!0,a=["precision",1,me,"rounding",0,8,"toExpNeg",-ye,0,"toExpPos",0,ye,"maxE",0,ye,"minE",-ye,0,"modulo",0,9];for(t=0;t<a.length;t+=3)if(e=a[t],r&&(this[e]=xi[e]),(n=i[e])!==void 0)if(Zt(n)===n&&n>=a[t+1]&&n<=a[t+2])this[e]=n;else throw Error(he+e+": "+n);if(e="crypto",r&&(this[e]=xi[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(In);else this[e]=!1;else throw Error(he+e+": "+n);return this}function $r(i){return new this(i).cos()}function Kr(i){return new this(i).cosh()}function Rn(i){var t,e,n;function r(a){var s,l,f,h=this;if(!(h instanceof r))return new r(a);if(h.constructor=r,vn(a)){h.s=a.s,R?!a.d||a.e>r.maxE?(h.e=NaN,h.d=null):a.e<r.minE?(h.e=0,h.d=[0]):(h.e=a.e,h.d=a.d.slice()):(h.e=a.e,h.d=a.d?a.d.slice():a.d);return}if(f=typeof a,f==="number"){if(a===0){h.s=1/a<0?-1:1,h.e=0,h.d=[0];return}if(a<0?(a=-a,h.s=-1):h.s=1,a===~~a&&a<1e7){for(s=0,l=a;l>=10;l/=10)s++;R?s>r.maxE?(h.e=NaN,h.d=null):s<r.minE?(h.e=0,h.d=[0]):(h.e=s,h.d=[a]):(h.e=s,h.d=[a]);return}if(a*0!==0){a||(h.s=NaN),h.e=NaN,h.d=null;return}return je(h,a.toString())}if(f==="string")return(l=a.charCodeAt(0))===45?(a=a.slice(1),h.s=-1):(l===43&&(a=a.slice(1)),h.s=1),Nn.test(a)?je(h,a):Pr(h,a);if(f==="bigint")return a<0?(a=-a,h.s=-1):h.s=1,je(h,a.toString());throw Error(he+a)}if(r.prototype=A,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=Ur,r.clone=Rn,r.isDecimal=vn,r.abs=Or,r.acos=Ir,r.acosh=Tr,r.add=Nr,r.asin=Fr,r.asinh=Br,r.atan=Dr,r.atanh=qr,r.atan2=Vr,r.cbrt=Rr,r.ceil=Lr,r.clamp=jr,r.cos=$r,r.cosh=Kr,r.div=Zr,r.exp=Xr,r.floor=Hr,r.hypot=zr,r.ln=Wr,r.log=Gr,r.log10=Jr,r.log2=Yr,r.max=Qr,r.min=to,r.mod=eo,r.mul=io,r.pow=no,r.random=ro,r.round=oo,r.sign=so,r.sin=ao,r.sinh=co,r.sqrt=uo,r.sub=lo,r.sum=fo,r.tan=ho,r.tanh=mo,r.trunc=po,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 Zr(i,t){return new this(i).div(t)}function Xr(i){return new this(i).exp()}function Hr(i){return T(i=new this(i),i.e+1,3)}function zr(){var i,t,e=new this(0);for(R=!1,i=0;i<arguments.length;)if(t=new this(arguments[i++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return R=!0,new this(1/0);e=t}return R=!0,e.sqrt()}function vn(i){return i instanceof Oe||i&&i.toStringTag===Tn||!1}function Wr(i){return new this(i).ln()}function Gr(i,t){return new this(i).log(t)}function Yr(i){return new this(i).log(2)}function Jr(i){return new this(i).log(10)}function Qr(){return Dn(this,arguments,-1)}function to(){return Dn(this,arguments,1)}function eo(i,t){return new this(i).mod(t)}function io(i,t){return new this(i).mul(t)}function no(i,t){return new this(i).pow(t)}function ro(i){var t,e,n,r,a=0,s=new this(1),l=[];if(i===void 0?i=this.precision:Xt(i,1,me),n=Math.ceil(i/D),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]:l[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):(l.push(r%1e7),a+=4);a=n/4}else throw Error(In);else for(;a<n;)l[a++]=Math.random()*1e7|0;for(n=l[--a],i%=D,n&&i&&(r=Rt(10,D-i),l[a]=(n/r|0)*r);l[a]===0;a--)l.pop();if(a<0)e=0,l=[0];else{for(e=-1;l[0]===0;e-=D)l.shift();for(n=1,r=l[0];r>=10;r/=10)n++;n<D&&(e-=D-n)}return s.e=e,s.d=l,s}function oo(i){return T(i=new this(i),i.e+1,this.rounding)}function so(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function ao(i){return new this(i).sin()}function co(i){return new this(i).sinh()}function uo(i){return new this(i).sqrt()}function lo(i,t){return new this(i).sub(t)}function fo(){var i=0,t=arguments,e=new this(t[i]);for(R=!1;e.s&&++i<t.length;)e=e.plus(t[i]);return R=!0,T(e,this.precision,this.rounding)}function ho(i){return new this(i).tan()}function mo(i){return new this(i).tanh()}function po(i){return T(i=new this(i),i.e+1,1)}A[Symbol.for("nodejs.util.inspect.custom")]=A.toString;A[Symbol.toStringTag]="Decimal";var Oe=A.constructor=Rn(xi);Ue=new Oe(Ue);$e=new Oe($e);var Jt=Oe;function P(i){return Jt.isDecimal(i)?i:new Jt(i===void 0?0:i)}function Ln(i){return P(10).pow(P(i).abs())}function fe(i,t){let e=Ln(P(t));return Number(P(i).mul(e))}function Ie(i,t=32){return Number(BigInt.asIntN(t,BigInt(i)))}function Ze(i,t){let e=Ln(P(t));return Number(P(i).div(e))}var jn="0x2::sui::SUI",go="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";var oe=class Dt{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=>{Mn(r.coin_type)===Mn(t)&&n.push(r)}),n}static isSuiCoin(t){return re(t).full_address===jn}static selectCoinObjectIdGreaterThanOrEqual(t,e,n=[]){let r=Dt.selectCoinAssetGreaterThanOrEqual(t,e,n),a=r.selected_coins.map(f=>f.coin_object_id),s=r.remain_coins,l=r.selected_coins.map(f=>f.balance.toString());return{object_array:a,remain_coins:s,amount_array:l}}static selectCoinAssetGreaterThanOrEqual(t,e,n=[]){let r=Dt.sortByBalance(t.filter(h=>!n.includes(h.coin_object_id))),a=Dt.calculateTotalBalance(r);if(a<e)return{selected_coins:[],remain_coins:r};if(a===e)return{selected_coins:r,remain_coins:[]};let s=BigInt(0),l=[],f=[...r];for(;s<a;){let h=e-s,b=f.findIndex(v=>v.balance>=h);if(b!==-1){l.push(f[b]),f.splice(b,1);break}let w=f.pop();w.balance>0&&(l.push(w),s+=w.balance)}return{selected_coins:Dt.sortByBalance(l),remain_coins:Dt.sortByBalance(f)}}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,s=!0){let l=Dt.getCoinAssets(r,e);if(n===BigInt(0))return this.buildZeroValueCoin(e,t,r,a);let f=Dt.calculateTotalBalance(l);if(f<n)throw new Error(`The amount(${f}) is Insufficient balance for ${r} , expect ${n} `);return this.buildCoin(t,e,l,n,r,a,s)}static buildCoinWithBalance(t,e,n){return t===BigInt(0)&&Dt.isSuiCoin(e)?n.add((0,Ai.coinWithBalance)({balance:t,useGasCoin:!1})):n.add((0,Ai.coinWithBalance)({balance:t,type:e}))}static buildVectorCoin(t,e,n,r,a,s=!0){if(Dt.isSuiCoin(a)){let v=t.splitCoins(t.gas,[t.pure.u64(r)]);return{selected_coins:[],target_coin:v,remain_coins:e,target_coin_amount:r.toString(),is_mint_zero_coin:!1,original_spited_coin:t.gas}}let{original_spited_coin:l,target_coin:f,target_coin_amount:h,remain_coins:b,selected_coins:w}=this.buildSpitTargeCoin(t,r,n,s);return s?{target_coin:t.makeMoveVec({elements:[f]}),selected_coins:w,remain_coins:b,target_coin_amount:h,is_mint_zero_coin:!1,original_spited_coin:l}:{selected_coins:w,target_coin:t.makeMoveVec({elements:w.map(v=>t.object(v))}),remain_coins:b,target_coin_amount:h,is_mint_zero_coin:!1}}static buildOneCoin(t,e,n,r,a=!0){if(Dt.isSuiCoin(r)){if(n===0n&&e.length>1){let f=Dt.selectCoinObjectIdGreaterThanOrEqual(e,n);return{selected_coins:f.object_array,target_coin:t.object(f.object_array[0]),remain_coins:f.remain_coins,target_coin_amount:f.amount_array[0],is_mint_zero_coin:!1}}let s=Dt.selectCoinObjectIdGreaterThanOrEqual(e,n),l=t.splitCoins(t.gas,[t.pure.u64(n)]);return{selected_coins:[],target_coin:l,remain_coins:s.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=Dt.selectCoinObjectIdGreaterThanOrEqual(n,e),s=a.amount_array.reduce((C,x)=>Number(C)+Number(x),0).toString(),l=a.object_array,[f,...h]=l,b=t.object(f),w=b,v=a.amount_array.reduce((C,x)=>Number(C)+Number(x),0).toString(),S;return h.length>0&&t.mergeCoins(b,h.map(C=>t.object(C))),r&&Number(s)>Number(e)&&(w=t.splitCoins(b,[t.pure.u64(e)]),S=b),{original_spited_coin:S,target_coin:w,target_coin_amount:v,remain_coins:a.remain_coins,selected_coins:a.object_array,is_mint_zero_coin:!1}}static buildCoin(t,e,n,r,a,s=!0,l=!0){return s?this.buildVectorCoin(t,e,n,r,a,l):this.buildOneCoin(t,n,r,a,l)}static buildZeroValueCoin(t,e,n,r=!0){let a=this.callMintZeroValueCoin(e,n),s;return r?s=e.makeMoveVec({elements:[a]}):s=a,{target_coin:s,remain_coins:t,selected_coins:[],is_mint_zero_coin:!0,target_coin_amount:"0"}}static buildCoinForAmountInterval(t,e,n,r,a=!0,s=!0){let l=Dt.getCoinAssets(r,e);if(n.amount_first===BigInt(0))return l.length>0?this.buildCoin(t,[...e],[...l],n.amount_first,r,a,s):this.buildZeroValueCoin(e,t,r,a);let f=Dt.calculateTotalBalance(l);if(f>=n.amount_first)return this.buildCoin(t,[...e],[...l],n.amount_first,r,a,s);if(f<n.amount_second)throw new Error(`The amount(${f}) is Insufficient balance for ${r} , expect ${n.amount_second} `);return this.buildCoin(t,[...e],[...l],n.amount_second,r,a,s)}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 getCoinAmountObjId(t,e){let n=t.amount_coin_array.find(r=>!r.used&&P(r.amount).eq(e)?(r.used=!0,!0):!1);return n?n.coin_object_id:zt("CoinNotFound",`Coin not found for ${e} ${t.coin_type}`)}static buildMultiCoinInput(t,e,n,r){let a=Dt.getCoinAssets(n,e);if(Dt.isSuiCoin(n)){let w=t.splitCoins(t.gas,r.map(v=>t.pure.u64(v)));return{amount_coin_array:r.map((v,S)=>({coin_object_id:w[S],amount:v.toString(),used:!1})),coin_type:n,remain_coins:a}}let s=r.reduce((w,v)=>w+v,BigInt(0)),l=Dt.selectCoinObjectIdGreaterThanOrEqual(a,s);if(l.object_array.length===0)return zt("InsufficientBalance",`No enough coins for ${n} expect ${s} actual ${Dt.calculateTotalBalance(a)}`);let[f,...h]=l.object_array;h.length>0&&t.mergeCoins(f,[...h]);let b=t.splitCoins(f,r.map(w=>t.pure.u64(w)));return{amount_coin_array:r.map((w,v)=>({coin_object_id:b[v],amount:w.toString(),used:!1})),remain_coins:l.remain_coins,coin_type:n}}};function _o(i){return i.startsWith("0x")?`${i.slice(2)}`:i}function yn(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 re(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={...re(t),type_arguments:e.map(s=>re(s).source_address)};return a.type_arguments=a.type_arguments.map(s=>oe.isSuiCoin(s)?s:re(s).source_address),a.source_address=yn(a.full_address,a.type_arguments),a}let n=t.split("::"),r={full_address:t,address:t===jn||t===go?"0x2":(0,ge.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=yn(r.full_address,r.type_arguments),r}catch{return{full_address:i,address:"",module:"",name:"",type_arguments:[],source_address:i}}}function Mn(i){return re(i).source_address}var Y=(i,t=!0)=>{let e=i.split("::"),n=e.shift(),r=(0,ge.normalizeSuiObjectId)(n);return t&&(r=_o(r)),`${r}::${e.join("::")}`};var vo=Pe(Ee()),Sn=443636,An=-443636,yo="79226673515401279992447579055";var Mo="4295048016",Xo=new vo.default(1e6),So=(i=>(i[i.BelowRange=0]="BelowRange",i[i.InRange=1]="InRange",i[i.AboveRange=2]="AboveRange",i))(So||{}),Vt=Pe(Ee()),ie=new Vt.default(0),xe=new Vt.default(1),We=new Vt.default(2),Ho=We.pow(new Vt.default(128)),Cn=We.pow(new Vt.default(64)).sub(xe),Ao=We.pow(new Vt.default(128)).sub(xe),Wt=class{static toX64BN(i){return i.mul(new Vt.default(2).pow(new Vt.default(64)))}static toX64Decimal(i){return i.mul(Jt.pow(2,64))}static toX64(i){return new Vt.default(i.mul(Jt.pow(2,64)).floor().toFixed())}static fromX64(i){return new Jt(i.toString()).mul(Jt.pow(2,-64))}static fromX64Decimal(i){return i.mul(Jt.pow(2,-64))}static fromX64BN(i){return i.div(new Vt.default(2).pow(new Vt.default(64)))}static shiftRightRoundUp(i){let t=i.shrn(64);return i.mod(Cn).gt(ie)&&(t=t.add(xe)),t}static divRoundUp(i,t){return i.mod(t).eq(ie)?i.div(t):i.div(t).add(new Vt.default(1))}static subUnderflowU128(i,t){return i.lt(t)?i.sub(t).add(Ao):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)&&zt("MultiplicationOverflow","Multiplication overflow"),n}static checkMulDivFloor(i,t,e,n){e.eq(ie)&&zt("DivisionByZero","Divide by zero");let r=i.mul(t).div(e);return this.isOverflow(r,n)&&zt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulDivCeil(i,t,e,n){if(e.eq(ie))throw new Error("Divide by zero");let r=i.mul(t).add(e.sub(xe)).div(e);if(this.isOverflow(r,n))throw new Error("Multiplication div overflow");return r}static checkMulDivRound(i,t,e,n){e.eq(ie)&&zt("DivisionByZero","Divide by zero");let r=i.mul(t.add(e.shrn(1))).div(e);return this.isOverflow(r,n)&&zt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulShiftRight(i,t,e,n){let r=i.mul(t).div(new Vt.default(2).pow(new Vt.default(e)));return this.isOverflow(r,n)&&zt("MultiplicationOverflow","Multiplication shift right overflow"),r}static checkMulShiftRight64RoundUpIf(i,t,e,n){let r=i.mul(t),a=n&&r.and(Cn).gt(ie)?r.shrn(64).add(xe):r.shrn(64);return this.isOverflow(a,e)&&zt("MultiplicationOverflow","Multiplication shift right overflow"),a}static checkMulShiftLeft(i,t,e,n){let r=i.mul(t).shln(e);return this.isOverflow(r,n)&&zt("MultiplicationOverflow","Multiplication shift left overflow"),r}static checkDivRoundUpIf(i,t,e){return t.eq(ie)&&zt("DivisionByZero","Divide by zero"),e?this.divRoundUp(i,t):i.div(t)}static isOverflow(i,t){return i.gte(We.pow(new Vt.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(ie)?i:this.u128Neg(i.subn(1))}static u128Neg(i){return i.uxor(new Vt.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 Vt.default(1)))}static negFrom(i){return i.eq(ie)?i:this.u128Neg(i).add(new Vt.default(1)).or(new Vt.default(1).shln(127))}},Ii=class{static getMinIndex(i){return An+Math.abs(An)%i}static getMaxIndex(i){return Sn-Sn%i}};function Un(i){return i.data}function Co(i){return i.data!==void 0}function xo(i){return i.content!==void 0}function $n(i){let t="data"in i?Un(i):i;if(!(!t||!xo(t)||t.content.dataType!=="moveObject"))return t.content}function ko(i){return $n(i)?.type}function Ti(i){let t=Co(i)?i.data:i;return!t?.type&&"data"in i?t?.content?.dataType==="package"?"package":ko(i):t?.type}function Kn(i){return Un(i)?.previousTransaction}function pe(i){let t=$n(i)?.fields;if(t)return"fields"in t?t.fields:t}Jt.config({precision:64,rounding:Jt.ROUND_DOWN,toExpNeg:-64,toExpPos:64});var Kt=Jt,Ht=Pe(Ee()),B=Pe(Ee()),Po=14,Eo="59543866431248",Oo="184467440737095516",Io="15793534762490258745";function To(i,t,e){let n=i.toTwos(e).shln(t);return n.imaskn(e+1),n.fromTwos(e)}function j(i,t,e){let n=i.toTwos(e).shrn(t);return n.imaskn(e-t+1),n.fromTwos(e-t)}function No(i){let t;return i&1?t=new B.default("79232123823359799118286999567"):t=new B.default("79228162514264337593543950336"),i&2&&(t=j(t.mul(new B.default("79236085330515764027303304731")),96,256)),i&4&&(t=j(t.mul(new B.default("79244008939048815603706035061")),96,256)),i&8&&(t=j(t.mul(new B.default("79259858533276714757314932305")),96,256)),i&16&&(t=j(t.mul(new B.default("79291567232598584799939703904")),96,256)),i&32&&(t=j(t.mul(new B.default("79355022692464371645785046466")),96,256)),i&64&&(t=j(t.mul(new B.default("79482085999252804386437311141")),96,256)),i&128&&(t=j(t.mul(new B.default("79736823300114093921829183326")),96,256)),i&256&&(t=j(t.mul(new B.default("80248749790819932309965073892")),96,256)),i&512&&(t=j(t.mul(new B.default("81282483887344747381513967011")),96,256)),i&1024&&(t=j(t.mul(new B.default("83390072131320151908154831281")),96,256)),i&2048&&(t=j(t.mul(new B.default("87770609709833776024991924138")),96,256)),i&4096&&(t=j(t.mul(new B.default("97234110755111693312479820773")),96,256)),i&8192&&(t=j(t.mul(new B.default("119332217159966728226237229890")),96,256)),i&16384&&(t=j(t.mul(new B.default("179736315981702064433883588727")),96,256)),i&32768&&(t=j(t.mul(new B.default("407748233172238350107850275304")),96,256)),i&65536&&(t=j(t.mul(new B.default("2098478828474011932436660412517")),96,256)),i&131072&&(t=j(t.mul(new B.default("55581415166113811149459800483533")),96,256)),i&262144&&(t=j(t.mul(new B.default("38992368544603139932233054999993551")),96,256)),j(t,32,256)}function Fo(i){let t=Math.abs(i),e;return t&1?e=new B.default("18445821805675392311"):e=new B.default("18446744073709551616"),t&2&&(e=j(e.mul(new B.default("18444899583751176498")),64,256)),t&4&&(e=j(e.mul(new B.default("18443055278223354162")),64,256)),t&8&&(e=j(e.mul(new B.default("18439367220385604838")),64,256)),t&16&&(e=j(e.mul(new B.default("18431993317065449817")),64,256)),t&32&&(e=j(e.mul(new B.default("18417254355718160513")),64,256)),t&64&&(e=j(e.mul(new B.default("18387811781193591352")),64,256)),t&128&&(e=j(e.mul(new B.default("18329067761203520168")),64,256)),t&256&&(e=j(e.mul(new B.default("18212142134806087854")),64,256)),t&512&&(e=j(e.mul(new B.default("17980523815641551639")),64,256)),t&1024&&(e=j(e.mul(new B.default("17526086738831147013")),64,256)),t&2048&&(e=j(e.mul(new B.default("16651378430235024244")),64,256)),t&4096&&(e=j(e.mul(new B.default("15030750278693429944")),64,256)),t&8192&&(e=j(e.mul(new B.default("12247334978882834399")),64,256)),t&16384&&(e=j(e.mul(new B.default("8131365268884726200")),64,256)),t&32768&&(e=j(e.mul(new B.default("3584323654723342297")),64,256)),t&65536&&(e=j(e.mul(new B.default("696457651847595233")),64,256)),t&131072&&(e=j(e.mul(new B.default("26294789957452057")),64,256)),t&262144&&(e=j(e.mul(new B.default("37481735321082")),64,256)),e}var tt=class Yt{static priceToSqrtPriceX64(t,e,n){return Wt.toX64(t.mul(Kt.pow(10,n-e)).sqrt())}static sqrtPriceX64ToPrice(t,e,n){return Wt.fromX64(t).pow(2).mul(Kt.pow(10,e-n))}static tickIndexToSqrtPriceX64(t){return t>0?new B.default(No(t)):new B.default(Fo(t))}static sqrtPriceX64ToTickIndex(t){if(t.gt(new B.default(yo))||t.lt(new B.default(Mo)))throw new Error("Provided sqrtPrice is not within the supported sqrtPrice range.");let e=t.bitLength()-1,n=new B.default(e-64),r=To(n,32,128),a=new B.default("8000000000000000","hex"),s=0,l=new B.default(0),f=e>=64?t.shrn(e-63):t.shln(63-e);for(;a.gt(new B.default(0))&&s<Po;){f=f.mul(f);let S=f.shrn(127);f=f.shrn(63+S.toNumber()),l=l.add(a.mul(S)),a=a.shrn(1),s+=1}let h=l.shrn(32),b=r.add(h).mul(new B.default(Eo)),w=j(b.sub(new B.default(Oo)),64,128).toNumber(),v=j(b.add(new B.default(Io)),64,128).toNumber();return w===v?w:Yt.tickIndexToSqrtPriceX64(v).lte(t)?v:w}static tickIndexToPrice(t,e,n){return Yt.sqrtPriceX64ToPrice(Yt.tickIndexToSqrtPriceX64(t),e,n)}static priceToTickIndex(t,e,n){return Yt.sqrtPriceX64ToTickIndex(Yt.priceToSqrtPriceX64(t,e,n))}static priceToInitializeTickIndex(t,e,n,r){return Yt.getInitializeTickIndex(Yt.priceToTickIndex(t,e,n),r)}static getInitializeTickIndex(t,e){return t-t%e}static getNextInitializeTickIndex(t,e){return Yt.getInitializeTickIndex(t,e)+e}static getPrevInitializeTickIndex(t,e){return Yt.getInitializeTickIndex(t,e)-e}};function Ve(i,t,e){let n=Ht.default.min(i,t),r=Ht.default.max(i,t),a=Wt.fromX64BN(e.mul(r).mul(n)),s=r.sub(n);return!a.isZero()&&!s.isZero()?a.div(s):new Ht.default(0)}function Re(i,t,e){let n=Ht.default.min(i,t),r=Ht.default.max(i,t).sub(n);return r.isZero()?new Ht.default(0):e.shln(64).div(r)}var se=class ve{static getCoinAmountFromLiquidity(t,e,n,r,a){let s=new Kt(t.toString()),l=new Kt(e.toString()),f=new Kt(n.toString()),h=new Kt(r.toString()),b,w;return e.lt(n)?(b=Wt.toX64Decimal(s).mul(h.sub(f)).div(f.mul(h)),w=new Kt(0)):e.lt(r)?(b=Wt.toX64Decimal(s).mul(h.sub(l)).div(l.mul(h)),w=Wt.fromX64Decimal(s.mul(l.sub(f)))):(b=new Kt(0),w=Wt.fromX64Decimal(s.mul(h.sub(f)))),a?{coin_amount_a:b.ceil().toString(),coin_amount_b:w.ceil().toString()}:{coin_amount_a:b.floor().toString(),coin_amount_b:w.floor().toString()}}static estLiquidityAndCoinAmountFromOneAmounts(t,e,n,r,a,s,l){let f=tt.sqrtPriceX64ToTickIndex(l),h=tt.tickIndexToSqrtPriceX64(t),b=tt.tickIndexToSqrtPriceX64(e),w;if(f<t){if(!r)throw new Error("lower tick cannot calculate liquidity by coinB");w=Ve(h,b,n)}else if(f>e){if(r)throw new Error("upper tick cannot calculate liquidity by coinA");w=Re(b,h,n)}else r?w=Ve(l,b,n):w=Re(l,h,n);let v=ve.getCoinAmountFromLiquidity(w,l,h,b,a),S=a?P(v.coin_amount_a.toString()).mul(1+s).toString():P(v.coin_amount_a.toString()).mul(1-s).toString(),C=a?P(v.coin_amount_b.toString()).mul(1+s).toString():P(v.coin_amount_b.toString()).mul(1-s).toString();return{coin_amount_a:v.coin_amount_a,coin_amount_b:v.coin_amount_b,coin_amount_limit_a:a?Kt.ceil(S).toString():Kt.floor(S).toString(),coin_amount_limit_b:a?Kt.ceil(C).toString():Kt.floor(C).toString(),liquidity_amount:w.toString(),fix_amount_a:r}}static estimateLiquidityFromCoinAmounts(t,e,n,r){if(e>n)return zt("InvalidTick","lower tick cannot be greater than lower tick",{[Si.METHOD_NAME]:"estimateLiquidityFromCoinAmounts",[Si.REQUEST_PARAMS]:{lower_tick:e,upper_tick:n,token_amount:r}});let a=tt.sqrtPriceX64ToTickIndex(t),s=tt.tickIndexToSqrtPriceX64(e),l=tt.tickIndexToSqrtPriceX64(n);if(a<e)return Ve(s,l,new Ht.default(r.coin_amount_a)).toString();if(a>=n)return Re(l,s,new Ht.default(r.coin_amount_b)).toString();let f=Ve(t,l,new Ht.default(r.coin_amount_a)),h=Re(t,s,new Ht.default(r.coin_amount_b));return Ht.default.min(f,h).toString()}static calculateDepositRatio(t,e,n){let r=new Ht.default(1e8),{coin_amount_b:a}=ve.estLiquidityAndCoinAmountFromOneAmounts(t,e,r,!0,!0,0,n),s=tt.sqrtPriceX64ToPrice(n,0,0),l=P(r.toString()).mul(s),f=l.add(a.toString()),h=l.div(f),b=P(a.toString()).div(f);return{ratio_a:h,ratio_b:b}}static calculateAmountDepositRatio(t,e,n,r,a){let s=tt.sqrtPriceX64ToPrice(n,r,a),l=tt.sqrtPriceX64ToTickIndex(n);if(l<t)return{ratio_a:new Kt(1),ratio_b:new Kt(0),curr_price:s};if(l>e)return{ratio_a:new Kt(0),ratio_b:new Kt(1),curr_price:s};let f=new Ht.default(fe(1,r)),{coin_amount_b:h}=ve.estLiquidityAndCoinAmountFromOneAmounts(t,e,f,!0,!0,0,n),b=Ze(f.toString(),r),w=Ze(h.toString(),a),v=P(b).add(w),S=P(b).div(v),C=P(w).div(v);return{ratio_a:S,ratio_b:C,curr_price:s}}static getCoinAmountsFromRatio(t,e,n,r,a,s,l){let f=P(fe(P(n).mul(t).div(r).toString(),s)).toFixed(0),h=P(fe(P(n).mul(e).div(a).toString(),l)).toFixed(0);return{amount_a:f,amount_b:h}}static estCoinAmountsFromTotalAmount(t,e,n,r,a,s,l,f){let{ratio_a:h,ratio_b:b}=ve.calculateDepositRatio(t,e,n);return ve.getCoinAmountsFromRatio(h,b,r,a,s,l,f)}static getPositionStatus(t,e,n){return t<e?0:t<n?1:2}};function Ge(i){if(i.config===void 0)throw new Error(`package: ${i.package_id} not config in sdk SdkOptions`);return i.config}var zo=Pe(Ee());var Ji=require("@cetusprotocol/sui-clmm-sdk");var Ae=require("@mysten/sui/transactions"),ae=we(require("bn.js")),Hn=require("@cetusprotocol/aggregator-sdk");var zn=require("@mysten/sui/utils"),Wn=we(require("decimal.js"));var $t=we(require("bn.js")),Je=we(require("decimal.js"));var Ni=we(require("bn.js")),Fi=we(require("decimal.js")),Ye=(i,t,e)=>{if(t==="min"){if(i===Ii.getMinIndex(e))return!0}else if(i===Ii.getMaxIndex(e))return!0;return!1};function Bo(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 Zn(i,t,e,n,r){let a=new Ni.default(10).pow(new Ni.default(n)),{coin_amount_b:s}=se.estLiquidityAndCoinAmountFromOneAmounts(i,t,a,!0,!0,0,e),l=tt.sqrtPriceX64ToPrice(e,n,r),f=P(a.toString()).mul(l).div(new Fi.default(10).pow(n)).mul(new Fi.default(10).pow(r)),h=f.add(s.toString()),b=f.div(h),w=P(s.toString()).div(h);return{ratioA:b,ratioB:w}}function Se(i,t,e,n,r,a,s){let l=P(fe(P(e).mul(i).div(n).toString(),a)).toFixed(0),f=P(fe(P(e).mul(t).div(r).toString(),s)).toFixed(0);return{amountA:l,amountB:f}}function Bi(i,t,e,n,r,a,s,l){let{ratioA:f,ratioB:h}=Zn(i,t,e,s,l);return Se(f,h,n,r,a,s,l)}var _e=10n;function Qe(i){let{fields:t,type:e}=i,{liquidity_range:n,pool_id:r,wrapped_position:a}=t.clmm_vault.fields,s=a.fields,l={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:Y(s.coin_type_a.fields.name,!1),coin_type_b:Y(s.coin_type_b.fields.name,!1),description:s.description,id:s.id.id,index:s.index,liquidity:s.liquidity,name:s.name,pool:s.pool,tick_lower_index:Ie(BigInt(s.tick_lower_index.fields.bits)),tick_upper_index:Ie(BigInt(s.tick_upper_index.fields.bits)),url:s.url}},{balances:f}=t.buffer_assets.fields,h=f.fields.contents.map(w=>{let{key:v,value:S}=w.fields;return{coin_type:Y(v.fields.name,!1),value:S}});return{id:t.id.id,is_pause:t.is_pause,clmm_vault:l,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:re(t.quote_type.fields.name).full_address,lp_token_type:re(e).type_arguments[0],balances:h,protocol_fee_rate:t.protocol_fee_rate}}async function Do(i,t=!0){i.getData().commands.forEach((e,n)=>{})}function Di(i,t){let e=P(i).div(t).toString(),n=P(t).div(i).toString();return{quote_per_base:e,base_per_quote:n}}function Xn(i,t,e,n){let r=10n**(_e+n-e),a=10n**(_e+e-n),s=Wt.checkMulDivFloor(new $t.default(i.toString()),new $t.default(r.toString()),new $t.default(t.toString()),64),l=Wt.checkMulDivFloor(new $t.default(t.toString()),new $t.default(a.toString()),new $t.default(i.toString()),64);return{primitive_base_price:BigInt(s.toString()),primitive_quote_price:BigInt(l.toString())}}function ti(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:s}]of Object.entries(i)){let{primitive_quote_price:l}=Xn(BigInt(e.oracle_price),BigInt(a.oracle_price),BigInt(e.coin_decimals),BigInt(a.coin_decimals)),f=Wt.checkMulDivFloor(new $t.default(l.toString()),new $t.default(s),new $t.default((BigInt(10)**_e).toString()),64);n=n.add(f)}return n.toString()}async function qi(i,t,e,n,r=!1){let{clmm_vault:a,quote_type:s}=t,{wrapped_position:l}=a,{tick_lower_index:f,tick_upper_index:h,liquidity:b}=l,{current_sqrt_price:w,coin_type_a:v,coin_type_b:S}=e,C=[...n],x=s&&Y(t.quote_type,!1),N=tt.tickIndexToSqrtPriceX64(f),E=tt.tickIndexToSqrtPriceX64(h),{coin_amount_a:q,coin_amount_b:k}=se.getCoinAmountFromLiquidity(new $t.default(b),new $t.default(w),new $t.default(N),new $t.default(E),!1);C.push({coin_type:v,value:q.toString()}),C.push({coin_type:S,value:k.toString()});let V={};C.forEach(Z=>{let z=Y(Z.coin_type,!1),Q=P(Z.value),jt=V[z]||0;V[z]=Q.add(jt).toString()});let qt=Object.entries(V).filter(([Z,z])=>P(z).gt(0)).map(([Z])=>Z);if(x&&!qt.includes(x)&&qt.push(x),qt.length===0)return"0";let K=await i.sdk.PythPrice.getLatestPrice(qt,r),Lt={};return qt.forEach(Z=>{let z=K[Z];if(z)Lt[Z]={price:z,value:V[Z]||"0"};else throw Error(`find ${Z} price fail `)}),ti(Lt,x).toString()}function Vi(i,t,e){return P(i).eq(0)?t:P(i).mul(t).div(e).toFixed(0,Je.default.ROUND_HALF_UP)}function qo(i,t,e){return P(i).eq(0)?"0":P(i).mul(t).div(e).toFixed(0,Je.default.ROUND_HALF_UP)}function be(i,t,e){return P(i).eq(0)?"0":P(t).mul(e).div(i).toFixed(0,Je.default.ROUND_HALF_UP)}function Te(i,t){let{balances:e,lp_token_treasury:n}=t,r={};return e.forEach(a=>{let s=be(n,i,a.value),l={coin_type:a.coin_type,value:s};r[l.coin_type]=l}),r}function Ri(i,t,e,n){let{tick_lower_index:r,tick_upper_index:a,coin_type_a:s,coin_type_b:l,liquidity:f}=e.clmm_vault.wrapped_position,h=be(e.lp_token_treasury,t,f),b=tt.tickIndexToSqrtPriceX64(r),w=tt.tickIndexToSqrtPriceX64(a),v=se.getCoinAmountFromLiquidity(new $t.default(h),new $t.default(n.current_sqrt_price),b,w,!0),S=v.coin_amount_a.toString(),C=v.coin_amount_b.toString(),x=Te(t,e),N=P(S).add(x[s]?.value||"0").toFixed(0),E=P(C).add(x[l]?.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:h,tick_lower_index:r,tick_upper_index:a,amount_a:N,amount_b:E,coin_type_a:s,coin_type_b:l}}function ei(i,t,e){let n=[];return t.forEach(r=>{P(r.value).gt(0)&&n.push(r)}),e.forEach(r=>{P(r.value).gt(0)&&n.push(r)}),i.balances.forEach(r=>{P(r.value).gt(0)&&n.push(r)}),n}function Li(i,t,e){let{coin_type_a:n,coin_type_b:r}=i.clmm_vault.wrapped_position,a=ei(i,t,e),s=new Set;return a.forEach(l=>s.add(l.coin_type)),s.add(n),s.add(r),Array.from(s)}function ji(i,t){if(!_e)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(t<0n){let e=10n**(_e- -t);return i*e}return i/10n**(t+_e)}function Ui(i){return`0x${Buffer.from(i).toString("hex")}`}function Vo(i,t,e,n,r){let a="0",s="0";return Ye(i,"min",Number(e))?a="0":a=tt.tickIndexToPrice(Number(i),n,r).toString(),Ye(t,"max",Number(e))?s="\u221E":s=tt.tickIndexToPrice(Number(t),n,r).toString(),{minPrice:a,maxPrice:s}}function ii(i){let t=pe(i),e=Ti(i),n=re(e),r=t.position.fields,a={id:r.id.id,pool_id:r.pool,index:r.index,liquidity:r.liquidity,tick_lower_index:Ie(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:Ie(BigInt(r.tick_upper_index.fields.bits)),coin_type_a:Y(r.coin_type_a.fields.name,!1),coin_type_b:Y(r.coin_type_b.fields.name,!1),name:r.name,description:r.description,url:r.url},s=t.global_vesting_periods.map(f=>({period:f.fields.period,release_time:f.fields.release_time,redeemed_amount:f.fields.redeemed_amount,cetus_amount:f.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:Y(t.coin_a.fields.name,!1),coin_type_b:Y(t.coin_b.fields.name,!1),cetus_amount:t.cetus_amount,start_time:t.start_time,global_vesting_periods:s,vest_infos:{id:t.vester_infos.fields.id,size:t.vester_infos.fields.size}}}function $i(i){let t=pe(i),e=Ti(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 Ne=class{_sdk;constructor(t){this._sdk=t}get sdk(){return this._sdk}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),s=(await this._sdk.FullClient.getBalance({owner:t,coinType:n.lp_token_type})).totalBalance;return Ri(t,s,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}`,s=this._sdk.getCache(a);if(s)return s;let{lp_token_type:l}=n,{rewarder_infos:f,id:h,coin_type_a:b,coin_type_b:w}=r,v=new Ae.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...f.map(q=>q.coin_type)],lp_token_type:l,pool_id:t,clmm_pool_id:h,coin_type_a:b,coin_type_b:w},v),this.buildCollectFeePayload({lp_token_type:l,pool_id:t,clmm_pool_id:h,coin_type_a:b,coin_type_b:w},v);let S=await this._sdk.FullClient.sendSimulationTransaction(v,(0,zn.normalizeSuiAddress)("0x0")),C=`${e}::pool::FeeClaimedEvent`,x=`${e}::pool::RewardClaimedEvent`,N=[],E=[];return S?.events.forEach(q=>{let{parsedJson:k,type:V}=q;V===C&&(N.push({coin_type:Y(b,!1),value:k.amount_a}),N.push({coin_type:Y(w,!1),value:k.amount_b})),V===x&&E.push({coin_type:Y(k.reward_type.name,!1),value:k.amount})}),this._sdk.updateCache(a,{feeList:N,rewarderList:E},10*1e3),{feeList:N,rewarderList:E}}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),s=a.data.map(l=>l.name.value);return s.length>0&&((await r.batchGetObjects(s,{showContent:!0})).forEach(f=>{let h=Qe(f.data.content);this._sdk.updateCache(`getPool_${h.id}`,h),e.data.push(h)}),e.next_cursor=a.next_cursor,e.has_next_page=a.has_next_page),e}async getPool(t,e=!0){let n=`getPool_${t}`,r=this._sdk.getCache(n,e);if(r)return r;let a=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),s=Qe(a.data.content);return this._sdk.updateCache(n,s),s}buildCollectRewardPayload(t,e){let{coin_type_a:n,coin_type_b:r,pool_id:a,clmm_pool_id:s,lp_token_type:l,reward_coin_types:f}=t,{published_at:h,configs:b,clmm_configs:w}=this._sdk.sdkOptions.vaults;return e=e||new Ae.Transaction,f.forEach(v=>{e.moveCall({target:`${h}::pool::collect_reward`,typeArguments:[n,r,l,v],arguments:[e.object(a),e.object(b.global_config_id),e.object(w.global_config_id),e.object(s),e.object(w.global_vault_id),e.object(ee)]})}),e}buildCollectFeePayload(t,e){let{coin_type_a:n,coin_type_b:r,pool_id:a,clmm_pool_id:s,lp_token_type:l}=t,{published_at:f,configs:h,clmm_configs:b}=this._sdk.sdkOptions.vaults;return e=e||new Ae.Transaction,e.moveCall({target:`${f}::pool::collect_fee`,typeArguments:[n,r,l],arguments:[e.object(a),e.object(h.global_config_id),e.object(b.global_config_id),e.object(s)]}),e}async buildDepositPayload(t,e){let{pool_id:n,amount_a:r,amount_b:a,return_lp_coin:s}=t,{pool:l,clmmPool:f}=await this.getVaultAndPool(n,!0),{rewarderList:h,feeList:b}=await this.getVaultsPositionRewarderAndFee(n),w=Li(l,h,b),{lp_token_type:v}=l,{rewarder_infos:S,id:C,coin_type_a:x,coin_type_b:N}=f,E=h.length>0?h.filter(z=>P(z.value.toString()).gt(0)).map(z=>Y(z.coin_type,!1)):S.map(z=>Y(z.coin_type,!1)),{published_at:q,configs:k,clmm_configs:V}=this._sdk.sdkOptions.vaults;e=e||new Ae.Transaction,e=this.buildCollectRewardPayload({reward_coin_types:E,lp_token_type:v,pool_id:n,clmm_pool_id:C,coin_type_a:x,coin_type_b:N},e),e=this.buildCollectFeePayload({lp_token_type:v,pool_id:n,clmm_pool_id:C,coin_type_a:x,coin_type_b:N},e),e=await this._sdk.PythPrice.buildUpdatePythPricePayload(w,e),e.moveCall({target:`${q}::pool::calculate_aum`,typeArguments:[x,N,v],arguments:[e.object(n),e.object(k.global_config_id),e.object(k.pyth_oracle_id),e.object(V.global_config_id),e.object(C),e.object(ee)]});let qt=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress,x),K=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress,N),Lt=oe.buildCoinForAmount(e,qt,BigInt(r),x,!1,!0),X=oe.buildCoinForAmount(e,K,BigInt(a),N,!1,!0),Z=e.moveCall({target:`${q}::pool::${s?"deposit_for":"deposit"}`,typeArguments:[x,N,v],arguments:[e.object(n),e.object(k.global_config_id),e.object(k.pyth_oracle_id),e.object(V.global_config_id),e.object(C),Lt.target_coin,X.target_coin,e.object(ee)]});return s?Z:void 0}async buildWithdrawPayload(t,e){let{pool_id:n,burn_lp_amount:r,mode:a,slippage:s,partner:l,extra_burn:f}=t,{pool:h,clmmPool:b}=await this.getVaultAndPool(n,!0),{published_at:w,configs:v,clmm_configs:S}=this._sdk.sdkOptions.vaults;e=e||new Ae.Transaction;let{lp_token_type:C,clmm_vault:x,lp_token_treasury:N}=h,{rewarder_infos:E,id:q,coin_type_a:k,coin_type_b:V,liquidity:qt}=b,K=E.map(et=>Y(et.coin_type,!1));e=this.buildCollectRewardPayload({reward_coin_types:K,lp_token_type:C,pool_id:n,clmm_pool_id:q,coin_type_a:k,coin_type_b:V},e),e=this.buildCollectFeePayload({lp_token_type:C,pool_id:n,clmm_pool_id:q,coin_type_a:k,coin_type_b:V},e);let Lt=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress),X,Z=f?P(f.burn_lp_amount).add(P(r)).toFixed(0):P(r).toFixed(0),z=P(r).isZero();if(z&&!f)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");z?X=f.lp_burn_coin:(X=oe.buildCoinForAmount(e,Lt,BigInt(r),C,!1,!0).target_coin,f&&e.mergeCoins(X,[f.lp_burn_coin]));let[Q,jt,$]=e.moveCall({target:`${w}::pool::withdraw`,typeArguments:[k,V,C],arguments:[e.object(n),e.object(v.global_config_id),e.object(S.global_config_id),e.object(q),X,e.object(ee)]});if(this.buildWithdrawBufferReward({reward_coin_types:K.filter(et=>![Y(k,!1),Y(V,!1)].includes(et)),pool_id:n,withdraw_cert:$,lp_token_type:C},e,Lt),e.moveCall({target:`${w}::pool::destory_withdraw_cert`,typeArguments:[C],arguments:[e.object(n),e.object(v.global_config_id),$]}),a!=="FixedOneSide"){if(s===void 0)throw Error("the slippage is undefined");let et=a==="OnlyCoinA",o=et?jt:Q,u=be(N,Z,qt.toString());await this.handleWithSwap(e,o,k,V,Z,n,et,s,l,[{poolID:q,ticklower:x.wrapped_position.tick_lower_index,tickUpper:x.wrapped_position.tick_upper_index,deltaLiquidity:Number(u)}]),e.transferObjects([et?Q:jt],this._sdk.senderAddress)}else e.transferObjects([Q,jt],this._sdk.senderAddress);return e}async handleWithSwap(t,e,n,r,a,s,l,f,h,b){let{receive_amount_a:w,receive_amount_b:v}=await this.preCalculateWithdrawAmount({pool_id:s,mode:"FixedOneSide",burn_lp_amount:a}),S=l?r:n,C=l?n:r,x=l?v:w,N={from:S,target:C,amount:new ae.default(x),byAmountIn:!0,depth:3,splitAlgorithm:void 0,splitFactor:void 0,splitCount:void 0,providers:this._sdk.sdkOptions.providers,liquidityChanges:b},E=await this._sdk.AggregatorClient.findRouters(N);if(!E)throw Error("not find Router");if(E.error!==void 0)throw Error(`find Router error : ${E.error}`);let q={router:E,inputCoin:e,slippage:f,txb:t,partner:h},k=await this._sdk.AggregatorClient.fixableRouterSwapV3(q);t.transferObjects([k],t.pure.address(this._sdk.getVerifySenderAddress()))}buildWithdrawBufferReward({reward_coin_types:t,pool_id:e,withdraw_cert:n,lp_token_type:r},a,s){let{published_at:l,configs:f}=this._sdk.sdkOptions.vaults;t.forEach(h=>{let b=a.moveCall({target:`${l}::pool::withdraw_buffer_reward`,typeArguments:[r,h],arguments:[a.object(e),a.object(f.global_config_id),n]}),w=oe.getCoinAssets(h,s),v=oe.selectCoinAssetGreaterThanOrEqual(w,BigInt(0));if(v.selected_coins.length>0&&!oe.isSuiCoin(h))a.mergeCoins(v.selected_coins[0].coin_object_id,[b]);else{let S=oe.buildCoinForAmount(a,s,BigInt(0),h,!1,!1);a.mergeCoins(S.target_coin,[b]),a.transferObjects([S.target_coin],this._sdk.senderAddress)}})}async preCalculateDepositValue(t,e){let{amount_usd:n,pool_id:r,mode:a,uuid:s}=t,{pool:l,clmmPool:f}=await this.getVaultAndPool(r,!1),{current_sqrt_price:h}=f,{tick_lower_index:b,tick_upper_index:w,coin_type_a:v,coin_type_b:S}=l.clmm_vault.wrapped_position,C="0",x="0",N=await this._sdk.PythPrice.getLatestPrice([v,S],!0),E=N[v],q=N[S];if(!E||!q)throw new Error("get coin price failed");switch(a){case"FixedOneSide":{let{amountA:k,amountB:V}=Bi(b,w,new ae.default(h),n,E.price,q.price,E.coin_decimals,q.coin_decimals);C=k.toString(),x=V.toString();break}case"FlexibleBoth":{let{amountA:k,amountB:V}=Se(P(.5),P(.5),n,E.price,q.price,E.coin_decimals,q.coin_decimals);C=k.toString(),x=V.toString();break}case"OnlyCoinA":{let{amountA:k,amountB:V}=Se(P(1),P(0),n,E.price,q.price,E.coin_decimals,q.coin_decimals);C=k.toString(),x=V.toString();break}case"OnlyCoinB":{let{amountA:k,amountB:V}=Se(P(0),P(1),n,E.price,q.price,E.coin_decimals,q.coin_decimals);C=k.toString(),x=V.toString();break}default:throw new Error(`Unsupported deposit mode: ${a}`)}return e&&this.calculateDepositLpAmountBoth(l,f,C,x).then(k=>{e.onSuccess(k,s)}).catch(k=>{e.onError(k,s)}),{deposit_amount_a:C,deposit_amount_b:x,mode:a}}async preCalculateDepositAmount(t,e){let{mode:n,pool_id:r,uuid:a}=t,s="0",l="0",{pool:f,clmmPool:h}=await this.getVaultAndPool(r,!1);switch(n){case"FixedOneSide":{let{fixed_amount:b,fixed_coin_a:w}=t,{other_amount:v}=this.calculateDepositOtherSide(f,h,b,w,e,a);w?(s=b,l=v):(l=b,s=v);break}case"FlexibleBoth":{let{coin_amount_a:b,coin_amount_b:w}=t;s=b,l=w,this.calculateDepositLpAmountBoth(f,h,b,w).then(v=>{e.onSuccess(v,a)}).catch(v=>{e.onError(v,a)});break}case"OnlyCoinA":{s=t.coin_amount_a,this.calculateDepositLpAmountBoth(f,h,s,"0").then(b=>{e.onSuccess(b,a)}).catch(b=>{e.onError(b,a)});break}case"OnlyCoinB":{l=t.coin_amount_b,this.calculateDepositLpAmountBoth(f,h,"0",l).then(b=>{e.onSuccess(b,a)}).catch(b=>{e.onError(b,a)});break}default:throw new Error(`Unsupported deposit mode: ${n}`)}return{deposit_amount_a:s,deposit_amount_b:l,mode:n}}async getVaultAndPool(t,e=!1){let n=await this.getPool(t,e);if(n===void 0)throw new Error("get vaults pool failed");let r=await this._sdk.CetusClmmSDK.Pool.getPool(n.clmm_vault.clmm_pool_id,e);if(r===void 0)throw new Error("get vaults clmmPool failed");return{clmmPool:r,pool:n}}calculateDepositOtherSide(t,e,n,r,a,s){let{clmm_vault:l}=t,{current_sqrt_price:f}=e,h=l.wrapped_position.tick_lower_index,b=l.wrapped_position.tick_upper_index,w=se.estLiquidityAndCoinAmountFromOneAmounts(h,b,new ae.default(n),r,!0,1,new ae.default(f)),{coin_amount_a:v,coin_amount_b:S}=w;return this.calculateDepositLpAmountBoth(t,e,v.toString(),S.toString()).then(C=>{a.onSuccess(C,s)}).catch(C=>{a.onError(C,s)}),{other_amount:r?S.toString():v.toString()}}async calculateDepositLpAmountBoth(t,e,n,r){let{lp_token_treasury:a,hard_cap:s}=t,l=Y(e.coin_type_a,!1),f=Y(e.coin_type_b,!1),{rewarderList:h,feeList:b}=await this.getVaultsPositionRewarderAndFee(t.id),w=ei(t,b,h),v=await qi(this,t,e,w,!0),S=await this._sdk.PythPrice.getLatestPrice([l,f],!0),C=S[l],x=S[f];if(!C)throw Error(`not find ${l} price`);if(!x)throw Error(`not find ${f} price`);let N={};N[l]={price:C,value:n.toString()},N[f]={price:x,value:r.toString()};let E=ti(N,t.quote_type);return Vi(a,E,v)}async preCalculateWithdrawAmount(t){let{mode:e,pool_id:n}=t,r="0",a="0",s="0",l="0",f,{pool:h,clmmPool:b}=await this.getVaultAndPool(n,!1);switch(e){case"FixedOneSide":let w=await this.calculateWithdrawOtherSide(h,b,t.burn_lp_amount);s=w.burn_lp_amount,r=w.receive_amount_a,a=w.receive_amount_b,l=w.remove_liquidity;break;case"OnlyCoinA":{let v=await this.calculateWithdrawOnlyCoin(h,b,t.burn_lp_amount,!0);s=v.burn_lp_amount,r=v.receive_amount_a,a=v.receive_amount_b,l=v.remove_liquidity,f=v.swap;break}case"OnlyCoinB":{let v=await this.calculateWithdrawOnlyCoin(h,b,t.burn_lp_amount,!1);s=v.burn_lp_amount,r=v.receive_amount_a,a=v.receive_amount_b,l=v.remove_liquidity,f=v.swap;break}default:throw new Error(`Unsupported withdraw mode: ${e}`)}return{remove_liquidity:l,burn_lp_amount:s,receive_amount_a:r,receive_amount_b:a,mode:e,swap:f}}async calculateWithdrawOtherSide(t,e,n){let{clmm_vault:r,lp_token_treasury:a}=t,{current_sqrt_price:s}=e,{coin_type_a:l,coin_type_b:f}=t.clmm_vault.wrapped_position,h=r.wrapped_position.tick_lower_index,b=r.wrapped_position.tick_upper_index,w=r.wrapped_position.liquidity,v=tt.tickIndexToSqrtPriceX64(h),S=tt.tickIndexToSqrtPriceX64(b),C=be(a,n,w),{coin_amount_a:x,coin_amount_b:N}=se.getCoinAmountFromLiquidity(new ae.default(C),new ae.default(s),v,S,!1),E=Te(n,t),q=P(x.toString()).add(E[l]?.value||"0").toFixed(0),k=P(N.toString()).add(E[f]?.value||"0").toFixed(0);return{receive_amount_a:q,receive_amount_b:k,burn_lp_amount:n,mode:"FixedOneSide",remove_liquidity:C}}async calculateWithdrawOnlyCoin(t,e,n,r){let{totalReceiveAmount:a,swapAmountIn:s,swapAmountOut:l,removeLiquidity: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,remove_liquidity:f,swap:{swap_amount_in:s,swap_amount_out:l},mode:"FixedOneSide"}}async calculateWithdrawOnlyCoinByLpAmount(t,e,n,r){let{clmm_vault:a,lp_token_treasury:s}=t,{current_sqrt_price:l}=e,{coin_type_a:f,coin_type_b:h}=a.wrapped_position,b=a.wrapped_position.tick_lower_index,w=a.wrapped_position.tick_upper_index,v=a.wrapped_position.liquidity,S=tt.tickIndexToSqrtPriceX64(b),C=tt.tickIndexToSqrtPriceX64(w),x=be(s,r,v),{coin_amount_a:N,coin_amount_b:E}=se.getCoinAmountFromLiquidity(new ae.default(x),new ae.default(l),S,C,!1),q=await this._sdk.PythPrice.getLatestPrice([f,h],!0),k=q[f],V=q[h];if(!k)throw Error(`not find ${f} price`);if(!V)throw Error(`not find ${h} price`);let qt=n?V:k,K=n?k:V,{quote_per_base:Lt}=Di(qt.price,K.price),X=Te(r,t),Z=P(N.toString()).add(X[f]?.value||"0").toFixed(0),z=P(E.toString()).add(X[h]?.value||"0").toFixed(0),Q=n?Z:z,jt=n?z:Z,$=fe(P(Ze(jt,n?V.coin_decimals:k.coin_decimals)).mul(Lt).toString(),n?k.coin_decimals:V.coin_decimals).toString(),et=P(Q).add($).toFixed(0);return{burn_lp_amount:r,removeLiquidity:x,is_coin_a:n,originAmount:Q,swapAmountIn:jt,swapAmountOut:P($).toFixed(0,Wn.default.ROUND_DOWN),totalReceiveAmount:et}}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=Kn(n);(await this._sdk.FullClient.queryEventsByPage({Transaction:r})).data.forEach(b=>{let w=b.parsedJson;if(b.type)switch((0,Hn.extractStructTagFromType)(b.type).full_address){case`${e}::pool::InitEvent`:t.registry_id=w.registry_id;break;case`${e}::pyth_oracle::InitEvent`:t.pyth_oracle_id=w.pyth_oracle_id;break;case`${e}::config::InitConfigEvent`:t.global_config_id=w.global_config;break;default:break}});let s=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),l=pe(s);t.pools_handle=l.pools.fields.id.id;let f=await this._sdk.FullClient.getObject({id:t.pyth_oracle_id,options:{showContent:!0}}),h=pe(f);return t.oracle_infos_handle=h.oracle_infos.fields.id.id,t.prices_handle=h.prices.fields.id.id,this._sdk.sdkOptions.vaults.configs=t,this._sdk.sdkOptions}};var Ce=require("@pythnetwork/pyth-sui-js"),Yi=require("@mysten/sui/bcs");var Ki={env:"mainnet",fullRpcUrl:"https://fullnode.mainnet.sui.io",vaults:{package_id:"0xc4ebf35be1478318d78c324342854dd2735a036139373a9d41a1aa3a46a01d05",published_at:"0x47024b72191f46f080f2ca87f84493ec56744b2e3624be38ad633c07d1373cba",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"},pyth_configs:{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"}]}}},Zi={"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}};function Xi(i){return i&&(Ki.fullRpcUrl=i),new ce(Ki)}var Hi={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"},pyth_configs:{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"}},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"}]}}},zi={};function Wi(i){return i&&(Hi.fullRpcUrl=i),new ce(Hi)}var Gn=(e=>(e.mainnet="mainnet",e.testnet="testnet",e))(Gn||{});function Ro(i){let{env:t,fullNodeUrl:e}=i;return t==="mainnet"?Xi(e):Wi(e)}var Gi=["CETUS","TURBOS","STEAMM","SPRINGSUI","HAEDAL","FLOWX","AFTERMATH","ALPHAFI","BLUEFIN","METASTABLE","VOLO","SCALLOP","KRIYA","FLOWXV3","DEEPBOOKV3","AFSUI","BLUEMOVE","KRIYAV3","HAEDALPMM","OBRIC"];function Yn(i){try{let{request_time:t,error:e,request_params:n,request_url:r,action:a}=i;if(window?.gtag){let s=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 Lo=16*1024,Fe=class{_sdk;connection;suiPythClient;hasChangeConnection=!1;errorList=[];constructor(t){let{pyth_configs:e}=t.sdkOptions.vaults,{pyth_state_id:n,wormhole_state_id:r}=e;this._sdk=t,this.hasChangeConnection=!1;let{primary:a}=t.sdkOptions.vaults.pyth_configs.hermes_service_urls;if(a.length===0)throw new Error("primary url is empty");this.connection=new Ce.SuiPriceServiceConnection(a),this.suiPythClient=new Ce.SuiPythClient(this._sdk.FullClient,n,r)}get sdk(){return this._sdk}recordError(t,e,n){let{secondary:r,primary:a}=this._sdk.sdkOptions.vaults.pyth_configs.hermes_service_urls,s={error:t,request_params:e,request_url:this.hasChangeConnection&&r?r:a,action:n,request_time:Date.now()};Yn(s),this.errorList.push(s)}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(l=>{let f=this._sdk.getCache(`getLatestPrice_${l}`);f&&this.priceCheck(f,60)?n[l]=f:r.push(l)}):r=[...t],r.length===0)return n;let a=await this.getFeedInfoList(r);return(await this.getLatestPriceFeeds(a.map(l=>l.price_feed_id)))?.forEach((l,f)=>{let h=l.getPriceUnchecked();if(h){let{price:b,expo:w}=h,v=P(b).mul(P(10).pow(P(w))).toString(),S=a[f],C={coin_type:S.coin_type,price:v,coin_decimals:S.coin_decimals,oracle_price:0n,last_update_time:h.publishTime};C.oracle_price=ji(BigInt(b),BigInt(w)),n[r[f]]=C,this._sdk.updateCache(`getLatestPrice_${C.coin_type}`,C)}}),n}async getPriceFeedsUpdateData(t){try{return await this.connection.getPriceFeedsUpdateData(t)}catch(e){this.recordError(e,t,"getPriceFeedsUpdateData");let{secondary:n}=this._sdk.sdkOptions.vaults.pyth_configs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Ce.SuiPriceServiceConnection(n);try{return await this.connection.getPriceFeedsUpdateData(t)}catch(r){this.recordError(r,t,"getPriceFeedsUpdateData")}}}}async getLatestPriceFeeds(t){try{return await this.connection.getLatestPriceFeeds(t)}catch(e){this.recordError(e,t,"getLatestPriceFeeds");let{secondary:n}=this._sdk.sdkOptions.vaults.pyth_configs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Ce.SuiPriceServiceConnection(n);try{return await this.connection.getLatestPriceFeeds(t)}catch(r){this.recordError(r,t,"getLatestPriceFeeds")}}}}async buildUpdatePythPricePayload(t,e){let{pyth_configs:n,published_at:r,configs:a}=this._sdk.sdkOptions.vaults,{pyth_state_id:s,pyth_published_at:l,pyth_package_id:f}=n,{global_config_id:h,pyth_oracle_id:b}=a,w=(await this.getFeedInfoList(t)).map(E=>E.price_feed_id);if(t.length!==w.length)throw Error("find feed id fail");let v=await this.getPriceFeedsUpdateData(w);if(!v)throw new Error("get price update data fail");if(v.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");let S=this.suiPythClient.extractVaaBytesFromAccumulatorMessage(v[0]),C=await this.suiPythClient.verifyVaas([S],e),[x]=e.moveCall({target:`${l}::pyth::create_authenticated_price_infos_using_accumulator`,typeArguments:[],arguments:[e.object(s),e.pure(Yi.bcs.vector(Yi.bcs.U8).serialize(Array.from(v[0]),{maxSize:Lo}).toBytes()),C[0],e.object(ee)]}),N=0;for(let E of w){let q=await this.suiPythClient.getPriceFeedObjectId(E);if(!q)throw new Error(`Price feed ${E} not found, please create it first`);[x]=e.moveCall({target:`${r}::pyth_oracle::update_price`,typeArguments:[t[N]],arguments:[e.object(b),e.object(h),e.object(s),x,e.object(q),e.object(ee)]}),N+=1}return e.moveCall({target:`${l}::hot_potato_vector::destroy`,arguments:[x],typeArguments:[`${f}::price_info::PriceInfo`]}),e}getFeedInfoByJson(t){let{env:e}=this._sdk.sdkOptions,n=Y(t,!1);return e==="mainnet"?Zi[n]:zi[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{configs:s}=this._sdk.sdkOptions.vaults,l=await this._sdk.FullClient.getDynamicFieldObject({parentId:s.oracle_infos_handle,name:{type:"0x1::type_name::TypeName",value:Y(t,!0)}}),{fields:f}=l.data.content.fields.value,h={coin_type:t,price_feed_id:Ui(f.price_feed_id),coin_decimals:f.coin_decimals};return this._sdk.updateCache(n,h),h}};var Jn=require("@mysten/sui/transactions");var Be=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!pe(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,s={clmm_vester_id:a.clmm_vester_id,lp_coin_type:Y(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},l=`${s.vault_id}-VestCreateEvent`;return this._sdk.updateCache(l,s),s})}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 s of t){let l=await this.getVaultVestEvent(s);n.push(l.vault_vester_id)}let r=[];return(await this._sdk.FullClient.batchGetObjects(n,{showContent:!0,showType:!0})).forEach(s=>{try{let l=ii(s);r.push(l);let f=`${l.id}-VaultsVestInfo`;this._sdk.updateCache(f,l)}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 s=await this._sdk.FullClient.getObject({id:n,options:{showContent:!0,showType:!0}}),l=ii(s);return this._sdk.updateCache(r,l),l}catch(s){throw new Error(`getVaultsVestInfo error: ${s}`)}}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}=Ge(e),r=n.find(a=>a.vault_id===t);if(!r){let a=`${t}-VestCreateEvent`,s=this._sdk.getCache(a,!1);s?r=s:(r=(await this.getVestCreateEventList()).find(f=>f.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 s=$i(a);r.push(s)}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}=Ge(n),{versioned_id:s,clmm_vest_id:l}=Ge(r);e=e||new Jn.Transaction;for(let f of t){let{vault_id:h,vesting_nft_id:b,period:w,coin_type_a:v,coin_type_b:S}=f,C=await this.getVaultVestEvent(h);e.moveCall({package:n.published_at,module:"hae_vester",function:"redeem_coin",arguments:[e.object(a),e.object(C.vault_vester_id),e.object(b),e.object(s),e.object(l),e.object(C.pool_id),e.pure.u16(w),e.object(ee)],typeArguments:[v,S]})}return e}};var ce=class{_cache={};_sdkOptions;_senderAddress="";_vaults;_pythPrice;_aggregatorClient;_vest;_cetusClmmSDK;constructor(t){(!t.providers||t.providers.length===0)&&(t.providers=Gi),this._sdkOptions=t,this._cetusClmmSDK=t.env==="testnet"?Ji.CetusClmmSDK.createSDK({env:"testnet",full_rpc_url:t.fullRpcUrl}):Ji.CetusClmmSDK.createSDK({env:"mainnet",full_rpc_url:t.fullRpcUrl}),this._vaults=new Ne(this),this._pythPrice=new Fe(this);let{primary:e,secondary:n}=t.vaults.pyth_configs.hermes_service_urls,r=[e,n].filter(Boolean);this._aggregatorClient=new De.AggregatorClient({endpoint:t.aggregatorUrl,signer:(0,ni.normalizeSuiAddress)("0x0"),client:new Qn.SuiClient({url:t.fullRpcUrl}),env:t.env==="testnet"?De.Env.Testnet:De.Env.Mainnet,pythUrls:r}),this._vest=new Be(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 PythPrice(){return this._pythPrice}get FullClient(){return this._cetusClmmSDK.FullClient}get AggregatorClient(){return this._aggregatorClient}get CetusClmmSDK(){return this._cetusClmmSDK}get Vest(){return this._vest}getVerifySenderAddress(){if(this.senderAddress.length===0||!(0,ni.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=Pn){this.CetusClmmSDK.updateCache(t,e,n)}getCache(t,e=!1){return this.CetusClmmSDK.getCache(t,e)}};var jo=ce;0&&(module.exports={PythPriceModule,SdkEnv,VaultsModule,VestModule,VolatileVaultsSDK,buildPoolData,buildVaultsBalance,calculateAum,calculateDepositRatioFixTokenA,calculateTotalAumBasedOnQuote,checkIsMinOrMaxIndex,convertU64BytesToDecimal,defaultProvider,estCoinAmountsFromTotalAmount,feed_map_mainnet,feed_map_testnet,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 tr=Object.create;var qe=Object.defineProperty;var er=Object.getOwnPropertyDescriptor;var ir=Object.getOwnPropertyNames;var nr=Object.getPrototypeOf,rr=Object.prototype.hasOwnProperty;var or=(i,t)=>{for(var e in t)qe(i,e,{get:t[e],enumerable:!0})},_n=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ir(t))!rr.call(i,r)&&r!==e&&qe(i,r,{get:()=>t[r],enumerable:!(n=er(t,r))||n.enumerable});return i};var we=(i,t,e)=>(e=i!=null?tr(nr(i)):{},_n(t||!i||!i.__esModule?qe(e,"default",{value:i,enumerable:!0}):e,i)),sr=i=>_n(qe({},"__esModule",{value:!0}),i);var Uo={};or(Uo,{PythPriceModule:()=>Fe,SdkEnv:()=>Gn,VaultsModule:()=>Ne,VestModule:()=>Be,VolatileVaultsSDK:()=>ce,buildPoolData:()=>Qe,buildVaultsBalance:()=>Ri,calculateAum:()=>qi,calculateDepositRatioFixTokenA:()=>Zn,calculateTotalAumBasedOnQuote:()=>ti,checkIsMinOrMaxIndex:()=>Ye,convertU64BytesToDecimal:()=>Bo,default:()=>jo,defaultProvider:()=>Gi,estCoinAmountsFromTotalAmount:()=>Bi,feed_map_mainnet:()=>Zi,feed_map_testnet:()=>zi,getCoinAmountsFromRatio:()=>Se,getPositionPriceRange:()=>Vo,getPriceWithFormattedDecimals:()=>ji,getPrimitivePricesFromBaseQuote:()=>Xn,getQuotePerBaseAndBasePerQuote:()=>Di,getShareBufferAssets:()=>Te,getUpdatePriceType:()=>Li,getVaultValidBalances:()=>ei,get_lp_amount_by_liquidity:()=>qo,get_lp_amount_by_tvl:()=>Vi,get_share_liquidity_by_amount:()=>be,initMainnetSDK:()=>Xi,initTestnetSDK:()=>Wi,initVaultSDK:()=>Ro,oraclePriceMultiplierDecimal:()=>_e,parseVaultVestNFT:()=>$i,parseVaultsVestInfo:()=>ii,printTransaction:()=>Do,toSuiObjectId:()=>Ui,vaults_mainnet:()=>Ki,vaults_testnet:()=>Hi});module.exports=sr(Uo);var Qn=require("@mysten/sui/client"),ni=require("@mysten/sui/utils"),De=require("@cetusprotocol/aggregator-sdk");var pr=require("@mysten/sui/utils"),Ei=require("@mysten/sui/client"),br=require("@mysten/sui/client"),wr=require("@mysten/sui/utils"),vr=require("@mysten/sui/keypairs/ed25519"),yr=require("@mysten/sui/keypairs/secp256k1"),ge=require("@mysten/sui/utils"),Ai=require("@mysten/sui/transactions"),bo=require("@mysten/sui/bcs"),wo=require("@mysten/sui/utils"),ar=Object.create,xn=Object.defineProperty,cr=Object.getOwnPropertyDescriptor,ur=Object.getOwnPropertyNames,lr=Object.getPrototypeOf,dr=Object.prototype.hasOwnProperty,fr=(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')}),hr=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),mr=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ur(t))!dr.call(i,r)&&r!==e&&xn(i,r,{get:()=>t[r],enumerable:!(n=cr(t,r))||n.enumerable});return i},Pe=(i,t,e)=>(e=i!=null?ar(lr(i)):{},mr(t||!i||!i.__esModule?xn(e,"default",{value:i,enumerable:!0}):e,i)),Ee=hr((i,t)=>{"use strict";(function(e,n){"use strict";function r(o,u){if(!o)throw new Error(u||"Assertion failed")}function a(o,u){o.super_=u;var d=function(){};d.prototype=u.prototype,o.prototype=new d,o.prototype.constructor=o}function s(o,u,d){if(s.isBN(o))return o;this.negative=0,this.words=null,this.length=0,this.red=null,o!==null&&((u==="le"||u==="be")&&(d=u,u=10),this._init(o||0,u||10,d||"be"))}typeof e=="object"?e.exports=s:n.BN=s,s.BN=s,s.wordSize=26;var l;try{typeof window<"u"&&typeof window.Buffer<"u"?l=window.Buffer:l=fr("buffer").Buffer}catch{}s.isBN=function(o){return o instanceof s?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===s.wordSize&&Array.isArray(o.words)},s.max=function(o,u){return o.cmp(u)>0?o:u},s.min=function(o,u){return o.cmp(u)<0?o:u},s.prototype._init=function(o,u,d){if(typeof o=="number")return this._initNumber(o,u,d);if(typeof o=="object")return this._initArray(o,u,d);u==="hex"&&(u=16),r(u===(u|0)&&u>=2&&u<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(u===16?this._parseHex(o,m,d):(this._parseBase(o,u,m),d==="le"&&this._initArray(this.toArray(),u,d)))},s.prototype._initNumber=function(o,u,d){o<0&&(this.negative=1,o=-o),o<67108864?(this.words=[o&67108863],this.length=1):o<4503599627370496?(this.words=[o&67108863,o/67108864&67108863],this.length=2):(r(o<9007199254740992),this.words=[o&67108863,o/67108864&67108863,1],this.length=3),d==="le"&&this._initArray(this.toArray(),u,d)},s.prototype._initArray=function(o,u,d){if(r(typeof o.length=="number"),o.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(o.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var g,y,M=0;if(d==="be")for(m=o.length-1,g=0;m>=0;m-=3)y=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[g]|=y<<M&67108863,this.words[g+1]=y>>>26-M&67108863,M+=24,M>=26&&(M-=26,g++);else if(d==="le")for(m=0,g=0;m<o.length;m+=3)y=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[g]|=y<<M&67108863,this.words[g+1]=y>>>26-M&67108863,M+=24,M>=26&&(M-=26,g++);return this._strip()};function f(o,u){var d=o.charCodeAt(u);if(d>=48&&d<=57)return d-48;if(d>=65&&d<=70)return d-55;if(d>=97&&d<=102)return d-87;r(!1,"Invalid character in "+o)}function h(o,u,d){var m=f(o,d);return d-1>=u&&(m|=f(o,d-1)<<4),m}s.prototype._parseHex=function(o,u,d){this.length=Math.ceil((o.length-u)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var g=0,y=0,M;if(d==="be")for(m=o.length-1;m>=u;m-=2)M=h(o,u,m)<<g,this.words[y]|=M&67108863,g>=18?(g-=18,y+=1,this.words[y]|=M>>>26):g+=8;else{var p=o.length-u;for(m=p%2===0?u+1:u;m<o.length;m+=2)M=h(o,u,m)<<g,this.words[y]|=M&67108863,g>=18?(g-=18,y+=1,this.words[y]|=M>>>26):g+=8}this._strip()};function b(o,u,d,m){for(var g=0,y=0,M=Math.min(o.length,d),p=u;p<M;p++){var c=o.charCodeAt(p)-48;g*=m,c>=49?y=c-49+10:c>=17?y=c-17+10:y=c,r(c>=0&&y<m,"Invalid character"),g+=y}return g}s.prototype._parseBase=function(o,u,d){this.words=[0],this.length=1;for(var m=0,g=1;g<=67108863;g*=u)m++;m--,g=g/u|0;for(var y=o.length-d,M=y%m,p=Math.min(y,y-M)+d,c=0,_=d;_<p;_+=m)c=b(o,_,_+m,u),this.imuln(g),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(M!==0){var O=1;for(c=b(o,_,o.length,u),_=0;_<M;_++)O*=u;this.imuln(O),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},s.prototype.copy=function(o){o.words=new Array(this.length);for(var u=0;u<this.length;u++)o.words[u]=this.words[u];o.length=this.length,o.negative=this.negative,o.red=this.red};function w(o,u){o.words=u.words,o.length=u.length,o.negative=u.negative,o.red=u.red}if(s.prototype._move=function(o){w(o,this)},s.prototype.clone=function(){var o=new s(null);return this.copy(o),o},s.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},s.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},s.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{s.prototype[Symbol.for("nodejs.util.inspect.custom")]=v}catch{s.prototype.inspect=v}else s.prototype.inspect=v;function v(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var S=["","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"],C=[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],x=[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];s.prototype.toString=function(o,u){o=o||10,u=u|0||1;var d;if(o===16||o==="hex"){d="";for(var m=0,g=0,y=0;y<this.length;y++){var M=this.words[y],p=((M<<m|g)&16777215).toString(16);g=M>>>24-m&16777215,m+=2,m>=26&&(m-=26,y--),g!==0||y!==this.length-1?d=S[6-p.length]+p+d:d=p+d}for(g!==0&&(d=g.toString(16)+d);d.length%u!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}if(o===(o|0)&&o>=2&&o<=36){var c=C[o],_=x[o];d="";var O=this.clone();for(O.negative=0;!O.isZero();){var I=O.modrn(_).toString(o);O=O.idivn(_),O.isZero()?d=I+d:d=S[c-I.length]+I+d}for(this.isZero()&&(d="0"+d);d.length%u!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}r(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var o=this.words[0];return this.length===2?o+=this.words[1]*67108864:this.length===3&&this.words[2]===1?o+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-o:o},s.prototype.toJSON=function(){return this.toString(16,2)},l&&(s.prototype.toBuffer=function(o,u){return this.toArrayLike(l,o,u)}),s.prototype.toArray=function(o,u){return this.toArrayLike(Array,o,u)};var N=function(o,u){return o.allocUnsafe?o.allocUnsafe(u):new o(u)};s.prototype.toArrayLike=function(o,u,d){this._strip();var m=this.byteLength(),g=d||Math.max(1,m);r(m<=g,"byte array longer than desired length"),r(g>0,"Requested array length <= 0");var y=N(o,g),M=u==="le"?"LE":"BE";return this["_toArrayLike"+M](y,m),y},s.prototype._toArrayLikeLE=function(o,u){for(var d=0,m=0,g=0,y=0;g<this.length;g++){var M=this.words[g]<<y|m;o[d++]=M&255,d<o.length&&(o[d++]=M>>8&255),d<o.length&&(o[d++]=M>>16&255),y===6?(d<o.length&&(o[d++]=M>>24&255),m=0,y=0):(m=M>>>24,y+=2)}if(d<o.length)for(o[d++]=m;d<o.length;)o[d++]=0},s.prototype._toArrayLikeBE=function(o,u){for(var d=o.length-1,m=0,g=0,y=0;g<this.length;g++){var M=this.words[g]<<y|m;o[d--]=M&255,d>=0&&(o[d--]=M>>8&255),d>=0&&(o[d--]=M>>16&255),y===6?(d>=0&&(o[d--]=M>>24&255),m=0,y=0):(m=M>>>24,y+=2)}if(d>=0)for(o[d--]=m;d>=0;)o[d--]=0},Math.clz32?s.prototype._countBits=function(o){return 32-Math.clz32(o)}:s.prototype._countBits=function(o){var u=o,d=0;return u>=4096&&(d+=13,u>>>=13),u>=64&&(d+=7,u>>>=7),u>=8&&(d+=4,u>>>=4),u>=2&&(d+=2,u>>>=2),d+u},s.prototype._zeroBits=function(o){if(o===0)return 26;var u=o,d=0;return!(u&8191)&&(d+=13,u>>>=13),!(u&127)&&(d+=7,u>>>=7),!(u&15)&&(d+=4,u>>>=4),!(u&3)&&(d+=2,u>>>=2),!(u&1)&&d++,d},s.prototype.bitLength=function(){var o=this.words[this.length-1],u=this._countBits(o);return(this.length-1)*26+u};function E(o){for(var u=new Array(o.bitLength()),d=0;d<u.length;d++){var m=d/26|0,g=d%26;u[d]=o.words[m]>>>g&1}return u}s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,u=0;u<this.length;u++){var d=this._zeroBits(this.words[u]);if(o+=d,d!==26)break}return o},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},s.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return this.negative!==0},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var u=0;u<o.length;u++)this.words[u]=this.words[u]|o.words[u];return this._strip()},s.prototype.ior=function(o){return r((this.negative|o.negative)===0),this.iuor(o)},s.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},s.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},s.prototype.iuand=function(o){var u;this.length>o.length?u=o:u=this;for(var d=0;d<u.length;d++)this.words[d]=this.words[d]&o.words[d];return this.length=u.length,this._strip()},s.prototype.iand=function(o){return r((this.negative|o.negative)===0),this.iuand(o)},s.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},s.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},s.prototype.iuxor=function(o){var u,d;this.length>o.length?(u=this,d=o):(u=o,d=this);for(var m=0;m<d.length;m++)this.words[m]=u.words[m]^d.words[m];if(this!==u)for(;m<u.length;m++)this.words[m]=u.words[m];return this.length=u.length,this._strip()},s.prototype.ixor=function(o){return r((this.negative|o.negative)===0),this.iuxor(o)},s.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},s.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},s.prototype.inotn=function(o){r(typeof o=="number"&&o>=0);var u=Math.ceil(o/26)|0,d=o%26;this._expand(u),d>0&&u--;for(var m=0;m<u;m++)this.words[m]=~this.words[m]&67108863;return d>0&&(this.words[m]=~this.words[m]&67108863>>26-d),this._strip()},s.prototype.notn=function(o){return this.clone().inotn(o)},s.prototype.setn=function(o,u){r(typeof o=="number"&&o>=0);var d=o/26|0,m=o%26;return this._expand(d+1),u?this.words[d]=this.words[d]|1<<m:this.words[d]=this.words[d]&~(1<<m),this._strip()},s.prototype.iadd=function(o){var u;if(this.negative!==0&&o.negative===0)return this.negative=0,u=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,u=this.isub(o),o.negative=1,u._normSign();var d,m;this.length>o.length?(d=this,m=o):(d=o,m=this);for(var g=0,y=0;y<m.length;y++)u=(d.words[y]|0)+(m.words[y]|0)+g,this.words[y]=u&67108863,g=u>>>26;for(;g!==0&&y<d.length;y++)u=(d.words[y]|0)+g,this.words[y]=u&67108863,g=u>>>26;if(this.length=d.length,g!==0)this.words[this.length]=g,this.length++;else if(d!==this)for(;y<d.length;y++)this.words[y]=d.words[y];return this},s.prototype.add=function(o){var u;return o.negative!==0&&this.negative===0?(o.negative=0,u=this.sub(o),o.negative^=1,u):o.negative===0&&this.negative!==0?(this.negative=0,u=o.sub(this),this.negative=1,u):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},s.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var u=this.iadd(o);return o.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var d=this.cmp(o);if(d===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,g;d>0?(m=this,g=o):(m=o,g=this);for(var y=0,M=0;M<g.length;M++)u=(m.words[M]|0)-(g.words[M]|0)+y,y=u>>26,this.words[M]=u&67108863;for(;y!==0&&M<m.length;M++)u=(m.words[M]|0)+y,y=u>>26,this.words[M]=u&67108863;if(y===0&&M<m.length&&m!==this)for(;M<m.length;M++)this.words[M]=m.words[M];return this.length=Math.max(this.length,M),m!==this&&(this.negative=1),this._strip()},s.prototype.sub=function(o){return this.clone().isub(o)};function q(o,u,d){d.negative=u.negative^o.negative;var m=o.length+u.length|0;d.length=m,m=m-1|0;var g=o.words[0]|0,y=u.words[0]|0,M=g*y,p=M&67108863,c=M/67108864|0;d.words[0]=p;for(var _=1;_<m;_++){for(var O=c>>>26,I=c&67108863,F=Math.min(_,u.length-1),L=Math.max(0,_-o.length+1);L<=F;L++){var U=_-L|0;g=o.words[U]|0,y=u.words[L]|0,M=g*y+I,O+=M/67108864|0,I=M&67108863}d.words[_]=I|0,c=O|0}return c!==0?d.words[_]=c|0:d.length--,d._strip()}var k=function(o,u,d){var m=o.words,g=u.words,y=d.words,M=0,p,c,_,O=m[0]|0,I=O&8191,F=O>>>13,L=m[1]|0,U=L&8191,W=L>>>13,ue=m[2]|0,G=ue&8191,J=ue>>>13,Qi=m[3]|0,it=Qi&8191,nt=Qi>>>13,tn=m[4]|0,rt=tn&8191,ot=tn>>>13,en=m[5]|0,st=en&8191,at=en>>>13,nn=m[6]|0,ct=nn&8191,ut=nn>>>13,rn=m[7]|0,lt=rn&8191,dt=rn>>>13,on=m[8]|0,ft=on&8191,ht=on>>>13,sn=m[9]|0,mt=sn&8191,pt=sn>>>13,an=g[0]|0,gt=an&8191,_t=an>>>13,cn=g[1]|0,bt=cn&8191,wt=cn>>>13,un=g[2]|0,vt=un&8191,yt=un>>>13,ln=g[3]|0,Mt=ln&8191,St=ln>>>13,dn=g[4]|0,At=dn&8191,Ct=dn>>>13,fn=g[5]|0,xt=fn&8191,kt=fn>>>13,hn=g[6]|0,Pt=hn&8191,Et=hn>>>13,mn=g[7]|0,Ot=mn&8191,It=mn>>>13,pn=g[8]|0,Tt=pn&8191,Nt=pn>>>13,gn=g[9]|0,Ft=gn&8191,Bt=gn>>>13;d.negative=o.negative^u.negative,d.length=19,p=Math.imul(I,gt),c=Math.imul(I,_t),c=c+Math.imul(F,gt)|0,_=Math.imul(F,_t);var ri=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(ri>>>26)|0,ri&=67108863,p=Math.imul(U,gt),c=Math.imul(U,_t),c=c+Math.imul(W,gt)|0,_=Math.imul(W,_t),p=p+Math.imul(I,bt)|0,c=c+Math.imul(I,wt)|0,c=c+Math.imul(F,bt)|0,_=_+Math.imul(F,wt)|0;var oi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(oi>>>26)|0,oi&=67108863,p=Math.imul(G,gt),c=Math.imul(G,_t),c=c+Math.imul(J,gt)|0,_=Math.imul(J,_t),p=p+Math.imul(U,bt)|0,c=c+Math.imul(U,wt)|0,c=c+Math.imul(W,bt)|0,_=_+Math.imul(W,wt)|0,p=p+Math.imul(I,vt)|0,c=c+Math.imul(I,yt)|0,c=c+Math.imul(F,vt)|0,_=_+Math.imul(F,yt)|0;var si=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(si>>>26)|0,si&=67108863,p=Math.imul(it,gt),c=Math.imul(it,_t),c=c+Math.imul(nt,gt)|0,_=Math.imul(nt,_t),p=p+Math.imul(G,bt)|0,c=c+Math.imul(G,wt)|0,c=c+Math.imul(J,bt)|0,_=_+Math.imul(J,wt)|0,p=p+Math.imul(U,vt)|0,c=c+Math.imul(U,yt)|0,c=c+Math.imul(W,vt)|0,_=_+Math.imul(W,yt)|0,p=p+Math.imul(I,Mt)|0,c=c+Math.imul(I,St)|0,c=c+Math.imul(F,Mt)|0,_=_+Math.imul(F,St)|0;var ai=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(ai>>>26)|0,ai&=67108863,p=Math.imul(rt,gt),c=Math.imul(rt,_t),c=c+Math.imul(ot,gt)|0,_=Math.imul(ot,_t),p=p+Math.imul(it,bt)|0,c=c+Math.imul(it,wt)|0,c=c+Math.imul(nt,bt)|0,_=_+Math.imul(nt,wt)|0,p=p+Math.imul(G,vt)|0,c=c+Math.imul(G,yt)|0,c=c+Math.imul(J,vt)|0,_=_+Math.imul(J,yt)|0,p=p+Math.imul(U,Mt)|0,c=c+Math.imul(U,St)|0,c=c+Math.imul(W,Mt)|0,_=_+Math.imul(W,St)|0,p=p+Math.imul(I,At)|0,c=c+Math.imul(I,Ct)|0,c=c+Math.imul(F,At)|0,_=_+Math.imul(F,Ct)|0;var ci=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(ci>>>26)|0,ci&=67108863,p=Math.imul(st,gt),c=Math.imul(st,_t),c=c+Math.imul(at,gt)|0,_=Math.imul(at,_t),p=p+Math.imul(rt,bt)|0,c=c+Math.imul(rt,wt)|0,c=c+Math.imul(ot,bt)|0,_=_+Math.imul(ot,wt)|0,p=p+Math.imul(it,vt)|0,c=c+Math.imul(it,yt)|0,c=c+Math.imul(nt,vt)|0,_=_+Math.imul(nt,yt)|0,p=p+Math.imul(G,Mt)|0,c=c+Math.imul(G,St)|0,c=c+Math.imul(J,Mt)|0,_=_+Math.imul(J,St)|0,p=p+Math.imul(U,At)|0,c=c+Math.imul(U,Ct)|0,c=c+Math.imul(W,At)|0,_=_+Math.imul(W,Ct)|0,p=p+Math.imul(I,xt)|0,c=c+Math.imul(I,kt)|0,c=c+Math.imul(F,xt)|0,_=_+Math.imul(F,kt)|0;var ui=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(ui>>>26)|0,ui&=67108863,p=Math.imul(ct,gt),c=Math.imul(ct,_t),c=c+Math.imul(ut,gt)|0,_=Math.imul(ut,_t),p=p+Math.imul(st,bt)|0,c=c+Math.imul(st,wt)|0,c=c+Math.imul(at,bt)|0,_=_+Math.imul(at,wt)|0,p=p+Math.imul(rt,vt)|0,c=c+Math.imul(rt,yt)|0,c=c+Math.imul(ot,vt)|0,_=_+Math.imul(ot,yt)|0,p=p+Math.imul(it,Mt)|0,c=c+Math.imul(it,St)|0,c=c+Math.imul(nt,Mt)|0,_=_+Math.imul(nt,St)|0,p=p+Math.imul(G,At)|0,c=c+Math.imul(G,Ct)|0,c=c+Math.imul(J,At)|0,_=_+Math.imul(J,Ct)|0,p=p+Math.imul(U,xt)|0,c=c+Math.imul(U,kt)|0,c=c+Math.imul(W,xt)|0,_=_+Math.imul(W,kt)|0,p=p+Math.imul(I,Pt)|0,c=c+Math.imul(I,Et)|0,c=c+Math.imul(F,Pt)|0,_=_+Math.imul(F,Et)|0;var li=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(li>>>26)|0,li&=67108863,p=Math.imul(lt,gt),c=Math.imul(lt,_t),c=c+Math.imul(dt,gt)|0,_=Math.imul(dt,_t),p=p+Math.imul(ct,bt)|0,c=c+Math.imul(ct,wt)|0,c=c+Math.imul(ut,bt)|0,_=_+Math.imul(ut,wt)|0,p=p+Math.imul(st,vt)|0,c=c+Math.imul(st,yt)|0,c=c+Math.imul(at,vt)|0,_=_+Math.imul(at,yt)|0,p=p+Math.imul(rt,Mt)|0,c=c+Math.imul(rt,St)|0,c=c+Math.imul(ot,Mt)|0,_=_+Math.imul(ot,St)|0,p=p+Math.imul(it,At)|0,c=c+Math.imul(it,Ct)|0,c=c+Math.imul(nt,At)|0,_=_+Math.imul(nt,Ct)|0,p=p+Math.imul(G,xt)|0,c=c+Math.imul(G,kt)|0,c=c+Math.imul(J,xt)|0,_=_+Math.imul(J,kt)|0,p=p+Math.imul(U,Pt)|0,c=c+Math.imul(U,Et)|0,c=c+Math.imul(W,Pt)|0,_=_+Math.imul(W,Et)|0,p=p+Math.imul(I,Ot)|0,c=c+Math.imul(I,It)|0,c=c+Math.imul(F,Ot)|0,_=_+Math.imul(F,It)|0;var di=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(di>>>26)|0,di&=67108863,p=Math.imul(ft,gt),c=Math.imul(ft,_t),c=c+Math.imul(ht,gt)|0,_=Math.imul(ht,_t),p=p+Math.imul(lt,bt)|0,c=c+Math.imul(lt,wt)|0,c=c+Math.imul(dt,bt)|0,_=_+Math.imul(dt,wt)|0,p=p+Math.imul(ct,vt)|0,c=c+Math.imul(ct,yt)|0,c=c+Math.imul(ut,vt)|0,_=_+Math.imul(ut,yt)|0,p=p+Math.imul(st,Mt)|0,c=c+Math.imul(st,St)|0,c=c+Math.imul(at,Mt)|0,_=_+Math.imul(at,St)|0,p=p+Math.imul(rt,At)|0,c=c+Math.imul(rt,Ct)|0,c=c+Math.imul(ot,At)|0,_=_+Math.imul(ot,Ct)|0,p=p+Math.imul(it,xt)|0,c=c+Math.imul(it,kt)|0,c=c+Math.imul(nt,xt)|0,_=_+Math.imul(nt,kt)|0,p=p+Math.imul(G,Pt)|0,c=c+Math.imul(G,Et)|0,c=c+Math.imul(J,Pt)|0,_=_+Math.imul(J,Et)|0,p=p+Math.imul(U,Ot)|0,c=c+Math.imul(U,It)|0,c=c+Math.imul(W,Ot)|0,_=_+Math.imul(W,It)|0,p=p+Math.imul(I,Tt)|0,c=c+Math.imul(I,Nt)|0,c=c+Math.imul(F,Tt)|0,_=_+Math.imul(F,Nt)|0;var fi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(fi>>>26)|0,fi&=67108863,p=Math.imul(mt,gt),c=Math.imul(mt,_t),c=c+Math.imul(pt,gt)|0,_=Math.imul(pt,_t),p=p+Math.imul(ft,bt)|0,c=c+Math.imul(ft,wt)|0,c=c+Math.imul(ht,bt)|0,_=_+Math.imul(ht,wt)|0,p=p+Math.imul(lt,vt)|0,c=c+Math.imul(lt,yt)|0,c=c+Math.imul(dt,vt)|0,_=_+Math.imul(dt,yt)|0,p=p+Math.imul(ct,Mt)|0,c=c+Math.imul(ct,St)|0,c=c+Math.imul(ut,Mt)|0,_=_+Math.imul(ut,St)|0,p=p+Math.imul(st,At)|0,c=c+Math.imul(st,Ct)|0,c=c+Math.imul(at,At)|0,_=_+Math.imul(at,Ct)|0,p=p+Math.imul(rt,xt)|0,c=c+Math.imul(rt,kt)|0,c=c+Math.imul(ot,xt)|0,_=_+Math.imul(ot,kt)|0,p=p+Math.imul(it,Pt)|0,c=c+Math.imul(it,Et)|0,c=c+Math.imul(nt,Pt)|0,_=_+Math.imul(nt,Et)|0,p=p+Math.imul(G,Ot)|0,c=c+Math.imul(G,It)|0,c=c+Math.imul(J,Ot)|0,_=_+Math.imul(J,It)|0,p=p+Math.imul(U,Tt)|0,c=c+Math.imul(U,Nt)|0,c=c+Math.imul(W,Tt)|0,_=_+Math.imul(W,Nt)|0,p=p+Math.imul(I,Ft)|0,c=c+Math.imul(I,Bt)|0,c=c+Math.imul(F,Ft)|0,_=_+Math.imul(F,Bt)|0;var hi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(hi>>>26)|0,hi&=67108863,p=Math.imul(mt,bt),c=Math.imul(mt,wt),c=c+Math.imul(pt,bt)|0,_=Math.imul(pt,wt),p=p+Math.imul(ft,vt)|0,c=c+Math.imul(ft,yt)|0,c=c+Math.imul(ht,vt)|0,_=_+Math.imul(ht,yt)|0,p=p+Math.imul(lt,Mt)|0,c=c+Math.imul(lt,St)|0,c=c+Math.imul(dt,Mt)|0,_=_+Math.imul(dt,St)|0,p=p+Math.imul(ct,At)|0,c=c+Math.imul(ct,Ct)|0,c=c+Math.imul(ut,At)|0,_=_+Math.imul(ut,Ct)|0,p=p+Math.imul(st,xt)|0,c=c+Math.imul(st,kt)|0,c=c+Math.imul(at,xt)|0,_=_+Math.imul(at,kt)|0,p=p+Math.imul(rt,Pt)|0,c=c+Math.imul(rt,Et)|0,c=c+Math.imul(ot,Pt)|0,_=_+Math.imul(ot,Et)|0,p=p+Math.imul(it,Ot)|0,c=c+Math.imul(it,It)|0,c=c+Math.imul(nt,Ot)|0,_=_+Math.imul(nt,It)|0,p=p+Math.imul(G,Tt)|0,c=c+Math.imul(G,Nt)|0,c=c+Math.imul(J,Tt)|0,_=_+Math.imul(J,Nt)|0,p=p+Math.imul(U,Ft)|0,c=c+Math.imul(U,Bt)|0,c=c+Math.imul(W,Ft)|0,_=_+Math.imul(W,Bt)|0;var mi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(mi>>>26)|0,mi&=67108863,p=Math.imul(mt,vt),c=Math.imul(mt,yt),c=c+Math.imul(pt,vt)|0,_=Math.imul(pt,yt),p=p+Math.imul(ft,Mt)|0,c=c+Math.imul(ft,St)|0,c=c+Math.imul(ht,Mt)|0,_=_+Math.imul(ht,St)|0,p=p+Math.imul(lt,At)|0,c=c+Math.imul(lt,Ct)|0,c=c+Math.imul(dt,At)|0,_=_+Math.imul(dt,Ct)|0,p=p+Math.imul(ct,xt)|0,c=c+Math.imul(ct,kt)|0,c=c+Math.imul(ut,xt)|0,_=_+Math.imul(ut,kt)|0,p=p+Math.imul(st,Pt)|0,c=c+Math.imul(st,Et)|0,c=c+Math.imul(at,Pt)|0,_=_+Math.imul(at,Et)|0,p=p+Math.imul(rt,Ot)|0,c=c+Math.imul(rt,It)|0,c=c+Math.imul(ot,Ot)|0,_=_+Math.imul(ot,It)|0,p=p+Math.imul(it,Tt)|0,c=c+Math.imul(it,Nt)|0,c=c+Math.imul(nt,Tt)|0,_=_+Math.imul(nt,Nt)|0,p=p+Math.imul(G,Ft)|0,c=c+Math.imul(G,Bt)|0,c=c+Math.imul(J,Ft)|0,_=_+Math.imul(J,Bt)|0;var pi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(pi>>>26)|0,pi&=67108863,p=Math.imul(mt,Mt),c=Math.imul(mt,St),c=c+Math.imul(pt,Mt)|0,_=Math.imul(pt,St),p=p+Math.imul(ft,At)|0,c=c+Math.imul(ft,Ct)|0,c=c+Math.imul(ht,At)|0,_=_+Math.imul(ht,Ct)|0,p=p+Math.imul(lt,xt)|0,c=c+Math.imul(lt,kt)|0,c=c+Math.imul(dt,xt)|0,_=_+Math.imul(dt,kt)|0,p=p+Math.imul(ct,Pt)|0,c=c+Math.imul(ct,Et)|0,c=c+Math.imul(ut,Pt)|0,_=_+Math.imul(ut,Et)|0,p=p+Math.imul(st,Ot)|0,c=c+Math.imul(st,It)|0,c=c+Math.imul(at,Ot)|0,_=_+Math.imul(at,It)|0,p=p+Math.imul(rt,Tt)|0,c=c+Math.imul(rt,Nt)|0,c=c+Math.imul(ot,Tt)|0,_=_+Math.imul(ot,Nt)|0,p=p+Math.imul(it,Ft)|0,c=c+Math.imul(it,Bt)|0,c=c+Math.imul(nt,Ft)|0,_=_+Math.imul(nt,Bt)|0;var gi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,p=Math.imul(mt,At),c=Math.imul(mt,Ct),c=c+Math.imul(pt,At)|0,_=Math.imul(pt,Ct),p=p+Math.imul(ft,xt)|0,c=c+Math.imul(ft,kt)|0,c=c+Math.imul(ht,xt)|0,_=_+Math.imul(ht,kt)|0,p=p+Math.imul(lt,Pt)|0,c=c+Math.imul(lt,Et)|0,c=c+Math.imul(dt,Pt)|0,_=_+Math.imul(dt,Et)|0,p=p+Math.imul(ct,Ot)|0,c=c+Math.imul(ct,It)|0,c=c+Math.imul(ut,Ot)|0,_=_+Math.imul(ut,It)|0,p=p+Math.imul(st,Tt)|0,c=c+Math.imul(st,Nt)|0,c=c+Math.imul(at,Tt)|0,_=_+Math.imul(at,Nt)|0,p=p+Math.imul(rt,Ft)|0,c=c+Math.imul(rt,Bt)|0,c=c+Math.imul(ot,Ft)|0,_=_+Math.imul(ot,Bt)|0;var _i=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(_i>>>26)|0,_i&=67108863,p=Math.imul(mt,xt),c=Math.imul(mt,kt),c=c+Math.imul(pt,xt)|0,_=Math.imul(pt,kt),p=p+Math.imul(ft,Pt)|0,c=c+Math.imul(ft,Et)|0,c=c+Math.imul(ht,Pt)|0,_=_+Math.imul(ht,Et)|0,p=p+Math.imul(lt,Ot)|0,c=c+Math.imul(lt,It)|0,c=c+Math.imul(dt,Ot)|0,_=_+Math.imul(dt,It)|0,p=p+Math.imul(ct,Tt)|0,c=c+Math.imul(ct,Nt)|0,c=c+Math.imul(ut,Tt)|0,_=_+Math.imul(ut,Nt)|0,p=p+Math.imul(st,Ft)|0,c=c+Math.imul(st,Bt)|0,c=c+Math.imul(at,Ft)|0,_=_+Math.imul(at,Bt)|0;var bi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,p=Math.imul(mt,Pt),c=Math.imul(mt,Et),c=c+Math.imul(pt,Pt)|0,_=Math.imul(pt,Et),p=p+Math.imul(ft,Ot)|0,c=c+Math.imul(ft,It)|0,c=c+Math.imul(ht,Ot)|0,_=_+Math.imul(ht,It)|0,p=p+Math.imul(lt,Tt)|0,c=c+Math.imul(lt,Nt)|0,c=c+Math.imul(dt,Tt)|0,_=_+Math.imul(dt,Nt)|0,p=p+Math.imul(ct,Ft)|0,c=c+Math.imul(ct,Bt)|0,c=c+Math.imul(ut,Ft)|0,_=_+Math.imul(ut,Bt)|0;var wi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,p=Math.imul(mt,Ot),c=Math.imul(mt,It),c=c+Math.imul(pt,Ot)|0,_=Math.imul(pt,It),p=p+Math.imul(ft,Tt)|0,c=c+Math.imul(ft,Nt)|0,c=c+Math.imul(ht,Tt)|0,_=_+Math.imul(ht,Nt)|0,p=p+Math.imul(lt,Ft)|0,c=c+Math.imul(lt,Bt)|0,c=c+Math.imul(dt,Ft)|0,_=_+Math.imul(dt,Bt)|0;var vi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,p=Math.imul(mt,Tt),c=Math.imul(mt,Nt),c=c+Math.imul(pt,Tt)|0,_=Math.imul(pt,Nt),p=p+Math.imul(ft,Ft)|0,c=c+Math.imul(ft,Bt)|0,c=c+Math.imul(ht,Ft)|0,_=_+Math.imul(ht,Bt)|0;var yi=(M+p|0)+((c&8191)<<13)|0;M=(_+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,p=Math.imul(mt,Ft),c=Math.imul(mt,Bt),c=c+Math.imul(pt,Ft)|0,_=Math.imul(pt,Bt);var Mi=(M+p|0)+((c&8191)<<13)|0;return M=(_+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,y[0]=ri,y[1]=oi,y[2]=si,y[3]=ai,y[4]=ci,y[5]=ui,y[6]=li,y[7]=di,y[8]=fi,y[9]=hi,y[10]=mi,y[11]=pi,y[12]=gi,y[13]=_i,y[14]=bi,y[15]=wi,y[16]=vi,y[17]=yi,y[18]=Mi,M!==0&&(y[19]=M,d.length++),d};Math.imul||(k=q);function V(o,u,d){d.negative=u.negative^o.negative,d.length=o.length+u.length;for(var m=0,g=0,y=0;y<d.length-1;y++){var M=g;g=0;for(var p=m&67108863,c=Math.min(y,u.length-1),_=Math.max(0,y-o.length+1);_<=c;_++){var O=y-_,I=o.words[O]|0,F=u.words[_]|0,L=I*F,U=L&67108863;M=M+(L/67108864|0)|0,U=U+p|0,p=U&67108863,M=M+(U>>>26)|0,g+=M>>>26,M&=67108863}d.words[y]=p,m=M,M=g}return m!==0?d.words[y]=m:d.length--,d._strip()}function qt(o,u,d){return V(o,u,d)}s.prototype.mulTo=function(o,u){var d,m=this.length+o.length;return this.length===10&&o.length===10?d=k(this,o,u):m<63?d=q(this,o,u):m<1024?d=V(this,o,u):d=qt(this,o,u),d};function K(o,u){this.x=o,this.y=u}K.prototype.makeRBT=function(o){for(var u=new Array(o),d=s.prototype._countBits(o)-1,m=0;m<o;m++)u[m]=this.revBin(m,d,o);return u},K.prototype.revBin=function(o,u,d){if(o===0||o===d-1)return o;for(var m=0,g=0;g<u;g++)m|=(o&1)<<u-g-1,o>>=1;return m},K.prototype.permute=function(o,u,d,m,g,y){for(var M=0;M<y;M++)m[M]=u[o[M]],g[M]=d[o[M]]},K.prototype.transform=function(o,u,d,m,g,y){this.permute(y,o,u,d,m,g);for(var M=1;M<g;M<<=1)for(var p=M<<1,c=Math.cos(2*Math.PI/p),_=Math.sin(2*Math.PI/p),O=0;O<g;O+=p)for(var I=c,F=_,L=0;L<M;L++){var U=d[O+L],W=m[O+L],ue=d[O+L+M],G=m[O+L+M],J=I*ue-F*G;G=I*G+F*ue,ue=J,d[O+L]=U+ue,m[O+L]=W+G,d[O+L+M]=U-ue,m[O+L+M]=W-G,L!==p&&(J=c*I-_*F,F=c*F+_*I,I=J)}},K.prototype.guessLen13b=function(o,u){var d=Math.max(u,o)|1,m=d&1,g=0;for(d=d/2|0;d;d=d>>>1)g++;return 1<<g+1+m},K.prototype.conjugate=function(o,u,d){if(!(d<=1))for(var m=0;m<d/2;m++){var g=o[m];o[m]=o[d-m-1],o[d-m-1]=g,g=u[m],u[m]=-u[d-m-1],u[d-m-1]=-g}},K.prototype.normalize13b=function(o,u){for(var d=0,m=0;m<u/2;m++){var g=Math.round(o[2*m+1]/u)*8192+Math.round(o[2*m]/u)+d;o[m]=g&67108863,g<67108864?d=0:d=g/67108864|0}return o},K.prototype.convert13b=function(o,u,d,m){for(var g=0,y=0;y<u;y++)g=g+(o[y]|0),d[2*y]=g&8191,g=g>>>13,d[2*y+1]=g&8191,g=g>>>13;for(y=2*u;y<m;++y)d[y]=0;r(g===0),r((g&-8192)===0)},K.prototype.stub=function(o){for(var u=new Array(o),d=0;d<o;d++)u[d]=0;return u},K.prototype.mulp=function(o,u,d){var m=2*this.guessLen13b(o.length,u.length),g=this.makeRBT(m),y=this.stub(m),M=new Array(m),p=new Array(m),c=new Array(m),_=new Array(m),O=new Array(m),I=new Array(m),F=d.words;F.length=m,this.convert13b(o.words,o.length,M,m),this.convert13b(u.words,u.length,_,m),this.transform(M,y,p,c,m,g),this.transform(_,y,O,I,m,g);for(var L=0;L<m;L++){var U=p[L]*O[L]-c[L]*I[L];c[L]=p[L]*I[L]+c[L]*O[L],p[L]=U}return this.conjugate(p,c,m),this.transform(p,c,F,y,m,g),this.conjugate(F,y,m),this.normalize13b(F,m),d.negative=o.negative^u.negative,d.length=o.length+u.length,d._strip()},s.prototype.mul=function(o){var u=new s(null);return u.words=new Array(this.length+o.length),this.mulTo(o,u)},s.prototype.mulf=function(o){var u=new s(null);return u.words=new Array(this.length+o.length),qt(this,o,u)},s.prototype.imul=function(o){return this.clone().mulTo(o,this)},s.prototype.imuln=function(o){var u=o<0;u&&(o=-o),r(typeof o=="number"),r(o<67108864);for(var d=0,m=0;m<this.length;m++){var g=(this.words[m]|0)*o,y=(g&67108863)+(d&67108863);d>>=26,d+=g/67108864|0,d+=y>>>26,this.words[m]=y&67108863}return d!==0&&(this.words[m]=d,this.length++),this.length=o===0?1:this.length,u?this.ineg():this},s.prototype.muln=function(o){return this.clone().imuln(o)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(o){var u=E(o);if(u.length===0)return new s(1);for(var d=this,m=0;m<u.length&&u[m]===0;m++,d=d.sqr());if(++m<u.length)for(var g=d.sqr();m<u.length;m++,g=g.sqr())u[m]!==0&&(d=d.mul(g));return d},s.prototype.iushln=function(o){r(typeof o=="number"&&o>=0);var u=o%26,d=(o-u)/26,m=67108863>>>26-u<<26-u,g;if(u!==0){var y=0;for(g=0;g<this.length;g++){var M=this.words[g]&m,p=(this.words[g]|0)-M<<u;this.words[g]=p|y,y=M>>>26-u}y&&(this.words[g]=y,this.length++)}if(d!==0){for(g=this.length-1;g>=0;g--)this.words[g+d]=this.words[g];for(g=0;g<d;g++)this.words[g]=0;this.length+=d}return this._strip()},s.prototype.ishln=function(o){return r(this.negative===0),this.iushln(o)},s.prototype.iushrn=function(o,u,d){r(typeof o=="number"&&o>=0);var m;u?m=(u-u%26)/26:m=0;var g=o%26,y=Math.min((o-g)/26,this.length),M=67108863^67108863>>>g<<g,p=d;if(m-=y,m=Math.max(0,m),p){for(var c=0;c<y;c++)p.words[c]=this.words[c];p.length=y}if(y!==0)if(this.length>y)for(this.length-=y,c=0;c<this.length;c++)this.words[c]=this.words[c+y];else this.words[0]=0,this.length=1;var _=0;for(c=this.length-1;c>=0&&(_!==0||c>=m);c--){var O=this.words[c]|0;this.words[c]=_<<26-g|O>>>g,_=O&M}return p&&_!==0&&(p.words[p.length++]=_),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},s.prototype.ishrn=function(o,u,d){return r(this.negative===0),this.iushrn(o,u,d)},s.prototype.shln=function(o){return this.clone().ishln(o)},s.prototype.ushln=function(o){return this.clone().iushln(o)},s.prototype.shrn=function(o){return this.clone().ishrn(o)},s.prototype.ushrn=function(o){return this.clone().iushrn(o)},s.prototype.testn=function(o){r(typeof o=="number"&&o>=0);var u=o%26,d=(o-u)/26,m=1<<u;if(this.length<=d)return!1;var g=this.words[d];return!!(g&m)},s.prototype.imaskn=function(o){r(typeof o=="number"&&o>=0);var u=o%26,d=(o-u)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=d)return this;if(u!==0&&d++,this.length=Math.min(d,this.length),u!==0){var m=67108863^67108863>>>u<<u;this.words[this.length-1]&=m}return this._strip()},s.prototype.maskn=function(o){return this.clone().imaskn(o)},s.prototype.iaddn=function(o){return r(typeof o=="number"),r(o<67108864),o<0?this.isubn(-o):this.negative!==0?this.length===1&&(this.words[0]|0)<=o?(this.words[0]=o-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(o),this.negative=1,this):this._iaddn(o)},s.prototype._iaddn=function(o){this.words[0]+=o;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},s.prototype.isubn=function(o){if(r(typeof o=="number"),r(o<67108864),o<0)return this.iaddn(-o);if(this.negative!==0)return this.negative=0,this.iaddn(o),this.negative=1,this;if(this.words[0]-=o,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},s.prototype.addn=function(o){return this.clone().iaddn(o)},s.prototype.subn=function(o){return this.clone().isubn(o)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(o,u,d){var m=o.length+d,g;this._expand(m);var y,M=0;for(g=0;g<o.length;g++){y=(this.words[g+d]|0)+M;var p=(o.words[g]|0)*u;y-=p&67108863,M=(y>>26)-(p/67108864|0),this.words[g+d]=y&67108863}for(;g<this.length-d;g++)y=(this.words[g+d]|0)+M,M=y>>26,this.words[g+d]=y&67108863;if(M===0)return this._strip();for(r(M===-1),M=0,g=0;g<this.length;g++)y=-(this.words[g]|0)+M,M=y>>26,this.words[g]=y&67108863;return this.negative=1,this._strip()},s.prototype._wordDiv=function(o,u){var d=this.length-o.length,m=this.clone(),g=o,y=g.words[g.length-1]|0,M=this._countBits(y);d=26-M,d!==0&&(g=g.ushln(d),m.iushln(d),y=g.words[g.length-1]|0);var p=m.length-g.length,c;if(u!=="mod"){c=new s(null),c.length=p+1,c.words=new Array(c.length);for(var _=0;_<c.length;_++)c.words[_]=0}var O=m.clone()._ishlnsubmul(g,1,p);O.negative===0&&(m=O,c&&(c.words[p]=1));for(var I=p-1;I>=0;I--){var F=(m.words[g.length+I]|0)*67108864+(m.words[g.length+I-1]|0);for(F=Math.min(F/y|0,67108863),m._ishlnsubmul(g,F,I);m.negative!==0;)F--,m.negative=0,m._ishlnsubmul(g,1,I),m.isZero()||(m.negative^=1);c&&(c.words[I]=F)}return c&&c._strip(),m._strip(),u!=="div"&&d!==0&&m.iushrn(d),{div:c||null,mod:m}},s.prototype.divmod=function(o,u,d){if(r(!o.isZero()),this.isZero())return{div:new s(0),mod:new s(0)};var m,g,y;return this.negative!==0&&o.negative===0?(y=this.neg().divmod(o,u),u!=="mod"&&(m=y.div.neg()),u!=="div"&&(g=y.mod.neg(),d&&g.negative!==0&&g.iadd(o)),{div:m,mod:g}):this.negative===0&&o.negative!==0?(y=this.divmod(o.neg(),u),u!=="mod"&&(m=y.div.neg()),{div:m,mod:y.mod}):this.negative&o.negative?(y=this.neg().divmod(o.neg(),u),u!=="div"&&(g=y.mod.neg(),d&&g.negative!==0&&g.isub(o)),{div:y.div,mod:g}):o.length>this.length||this.cmp(o)<0?{div:new s(0),mod:this}:o.length===1?u==="div"?{div:this.divn(o.words[0]),mod:null}:u==="mod"?{div:null,mod:new s(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new s(this.modrn(o.words[0]))}:this._wordDiv(o,u)},s.prototype.div=function(o){return this.divmod(o,"div",!1).div},s.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},s.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},s.prototype.divRound=function(o){var u=this.divmod(o);if(u.mod.isZero())return u.div;var d=u.div.negative!==0?u.mod.isub(o):u.mod,m=o.ushrn(1),g=o.andln(1),y=d.cmp(m);return y<0||g===1&&y===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},s.prototype.modrn=function(o){var u=o<0;u&&(o=-o),r(o<=67108863);for(var d=(1<<26)%o,m=0,g=this.length-1;g>=0;g--)m=(d*m+(this.words[g]|0))%o;return u?-m:m},s.prototype.modn=function(o){return this.modrn(o)},s.prototype.idivn=function(o){var u=o<0;u&&(o=-o),r(o<=67108863);for(var d=0,m=this.length-1;m>=0;m--){var g=(this.words[m]|0)+d*67108864;this.words[m]=g/o|0,d=g%o}return this._strip(),u?this.ineg():this},s.prototype.divn=function(o){return this.clone().idivn(o)},s.prototype.egcd=function(o){r(o.negative===0),r(!o.isZero());var u=this,d=o.clone();u.negative!==0?u=u.umod(o):u=u.clone();for(var m=new s(1),g=new s(0),y=new s(0),M=new s(1),p=0;u.isEven()&&d.isEven();)u.iushrn(1),d.iushrn(1),++p;for(var c=d.clone(),_=u.clone();!u.isZero();){for(var O=0,I=1;!(u.words[0]&I)&&O<26;++O,I<<=1);if(O>0)for(u.iushrn(O);O-- >0;)(m.isOdd()||g.isOdd())&&(m.iadd(c),g.isub(_)),m.iushrn(1),g.iushrn(1);for(var F=0,L=1;!(d.words[0]&L)&&F<26;++F,L<<=1);if(F>0)for(d.iushrn(F);F-- >0;)(y.isOdd()||M.isOdd())&&(y.iadd(c),M.isub(_)),y.iushrn(1),M.iushrn(1);u.cmp(d)>=0?(u.isub(d),m.isub(y),g.isub(M)):(d.isub(u),y.isub(m),M.isub(g))}return{a:y,b:M,gcd:d.iushln(p)}},s.prototype._invmp=function(o){r(o.negative===0),r(!o.isZero());var u=this,d=o.clone();u.negative!==0?u=u.umod(o):u=u.clone();for(var m=new s(1),g=new s(0),y=d.clone();u.cmpn(1)>0&&d.cmpn(1)>0;){for(var M=0,p=1;!(u.words[0]&p)&&M<26;++M,p<<=1);if(M>0)for(u.iushrn(M);M-- >0;)m.isOdd()&&m.iadd(y),m.iushrn(1);for(var c=0,_=1;!(d.words[0]&_)&&c<26;++c,_<<=1);if(c>0)for(d.iushrn(c);c-- >0;)g.isOdd()&&g.iadd(y),g.iushrn(1);u.cmp(d)>=0?(u.isub(d),m.isub(g)):(d.isub(u),g.isub(m))}var O;return u.cmpn(1)===0?O=m:O=g,O.cmpn(0)<0&&O.iadd(o),O},s.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var u=this.clone(),d=o.clone();u.negative=0,d.negative=0;for(var m=0;u.isEven()&&d.isEven();m++)u.iushrn(1),d.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;d.isEven();)d.iushrn(1);var g=u.cmp(d);if(g<0){var y=u;u=d,d=y}else if(g===0||d.cmpn(1)===0)break;u.isub(d)}while(!0);return d.iushln(m)},s.prototype.invm=function(o){return this.egcd(o).a.umod(o)},s.prototype.isEven=function(){return(this.words[0]&1)===0},s.prototype.isOdd=function(){return(this.words[0]&1)===1},s.prototype.andln=function(o){return this.words[0]&o},s.prototype.bincn=function(o){r(typeof o=="number");var u=o%26,d=(o-u)/26,m=1<<u;if(this.length<=d)return this._expand(d+1),this.words[d]|=m,this;for(var g=m,y=d;g!==0&&y<this.length;y++){var M=this.words[y]|0;M+=g,g=M>>>26,M&=67108863,this.words[y]=M}return g!==0&&(this.words[y]=g,this.length++),this},s.prototype.isZero=function(){return this.length===1&&this.words[0]===0},s.prototype.cmpn=function(o){var u=o<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var d;if(this.length>1)d=1;else{u&&(o=-o),r(o<=67108863,"Number is too big");var m=this.words[0]|0;d=m===o?0:m<o?-1:1}return this.negative!==0?-d|0:d},s.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var u=this.ucmp(o);return this.negative!==0?-u|0:u},s.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var u=0,d=this.length-1;d>=0;d--){var m=this.words[d]|0,g=o.words[d]|0;if(m!==g){m<g?u=-1:m>g&&(u=1);break}}return u},s.prototype.gtn=function(o){return this.cmpn(o)===1},s.prototype.gt=function(o){return this.cmp(o)===1},s.prototype.gten=function(o){return this.cmpn(o)>=0},s.prototype.gte=function(o){return this.cmp(o)>=0},s.prototype.ltn=function(o){return this.cmpn(o)===-1},s.prototype.lt=function(o){return this.cmp(o)===-1},s.prototype.lten=function(o){return this.cmpn(o)<=0},s.prototype.lte=function(o){return this.cmp(o)<=0},s.prototype.eqn=function(o){return this.cmpn(o)===0},s.prototype.eq=function(o){return this.cmp(o)===0},s.red=function(o){return new $(o)},s.prototype.toRed=function(o){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),o.convertTo(this)._forceRed(o)},s.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(o){return this.red=o,this},s.prototype.forceRed=function(o){return r(!this.red,"Already a number in reduction context"),this._forceRed(o)},s.prototype.redAdd=function(o){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},s.prototype.redIAdd=function(o){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},s.prototype.redSub=function(o){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},s.prototype.redISub=function(o){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},s.prototype.redShl=function(o){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},s.prototype.redMul=function(o){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},s.prototype.redIMul=function(o){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},s.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(o){return r(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var Lt={k256:null,p224:null,p192:null,p25519:null};function X(o,u){this.name=o,this.p=new s(u,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}X.prototype._tmp=function(){var o=new s(null);return o.words=new Array(Math.ceil(this.n/13)),o},X.prototype.ireduce=function(o){var u=o,d;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),d=u.bitLength();while(d>this.n);var m=d<this.n?-1:u.ucmp(this.p);return m===0?(u.words[0]=0,u.length=1):m>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},X.prototype.split=function(o,u){o.iushrn(this.n,0,u)},X.prototype.imulK=function(o){return o.imul(this.k)};function Z(){X.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a(Z,X),Z.prototype.split=function(o,u){for(var d=4194303,m=Math.min(o.length,9),g=0;g<m;g++)u.words[g]=o.words[g];if(u.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var y=o.words[9];for(u.words[u.length++]=y&d,g=10;g<o.length;g++){var M=o.words[g]|0;o.words[g-10]=(M&d)<<4|y>>>22,y=M}y>>>=22,o.words[g-10]=y,y===0&&o.length>10?o.length-=10:o.length-=9},Z.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var u=0,d=0;d<o.length;d++){var m=o.words[d]|0;u+=m*977,o.words[d]=u&67108863,u=m*64+(u/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function z(){X.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}a(z,X);function Q(){X.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}a(Q,X);function jt(){X.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}a(jt,X),jt.prototype.imulK=function(o){for(var u=0,d=0;d<o.length;d++){var m=(o.words[d]|0)*19+u,g=m&67108863;m>>>=26,o.words[d]=g,u=m}return u!==0&&(o.words[o.length++]=u),o},s._prime=function(o){if(Lt[o])return Lt[o];var u;if(o==="k256")u=new Z;else if(o==="p224")u=new z;else if(o==="p192")u=new Q;else if(o==="p25519")u=new jt;else throw new Error("Unknown prime "+o);return Lt[o]=u,u};function $(o){if(typeof o=="string"){var u=s._prime(o);this.m=u.p,this.prime=u}else r(o.gtn(1),"modulus must be greater than 1"),this.m=o,this.prime=null}$.prototype._verify1=function(o){r(o.negative===0,"red works only with positives"),r(o.red,"red works only with red numbers")},$.prototype._verify2=function(o,u){r((o.negative|u.negative)===0,"red works only with positives"),r(o.red&&o.red===u.red,"red works only with red numbers")},$.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(w(o,o.umod(this.m)._forceRed(this)),o)},$.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},$.prototype.add=function(o,u){this._verify2(o,u);var d=o.add(u);return d.cmp(this.m)>=0&&d.isub(this.m),d._forceRed(this)},$.prototype.iadd=function(o,u){this._verify2(o,u);var d=o.iadd(u);return d.cmp(this.m)>=0&&d.isub(this.m),d},$.prototype.sub=function(o,u){this._verify2(o,u);var d=o.sub(u);return d.cmpn(0)<0&&d.iadd(this.m),d._forceRed(this)},$.prototype.isub=function(o,u){this._verify2(o,u);var d=o.isub(u);return d.cmpn(0)<0&&d.iadd(this.m),d},$.prototype.shl=function(o,u){return this._verify1(o),this.imod(o.ushln(u))},$.prototype.imul=function(o,u){return this._verify2(o,u),this.imod(o.imul(u))},$.prototype.mul=function(o,u){return this._verify2(o,u),this.imod(o.mul(u))},$.prototype.isqr=function(o){return this.imul(o,o.clone())},$.prototype.sqr=function(o){return this.mul(o,o)},$.prototype.sqrt=function(o){if(o.isZero())return o.clone();var u=this.m.andln(3);if(r(u%2===1),u===3){var d=this.m.add(new s(1)).iushrn(2);return this.pow(o,d)}for(var m=this.m.subn(1),g=0;!m.isZero()&&m.andln(1)===0;)g++,m.iushrn(1);r(!m.isZero());var y=new s(1).toRed(this),M=y.redNeg(),p=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new s(2*c*c).toRed(this);this.pow(c,p).cmp(M)!==0;)c.redIAdd(M);for(var _=this.pow(c,m),O=this.pow(o,m.addn(1).iushrn(1)),I=this.pow(o,m),F=g;I.cmp(y)!==0;){for(var L=I,U=0;L.cmp(y)!==0;U++)L=L.redSqr();r(U<F);var W=this.pow(_,new s(1).iushln(F-U-1));O=O.redMul(W),_=W.redSqr(),I=I.redMul(_),F=U}return O},$.prototype.invm=function(o){var u=o._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},$.prototype.pow=function(o,u){if(u.isZero())return new s(1).toRed(this);if(u.cmpn(1)===0)return o.clone();var d=4,m=new Array(1<<d);m[0]=new s(1).toRed(this),m[1]=o;for(var g=2;g<m.length;g++)m[g]=this.mul(m[g-1],o);var y=m[0],M=0,p=0,c=u.bitLength()%26;for(c===0&&(c=26),g=u.length-1;g>=0;g--){for(var _=u.words[g],O=c-1;O>=0;O--){var I=_>>O&1;if(y!==m[0]&&(y=this.sqr(y)),I===0&&M===0){p=0;continue}M<<=1,M|=I,p++,!(p!==d&&(g!==0||O!==0))&&(y=this.mul(y,m[M]),p=0,M=0)}c=26}return y},$.prototype.convertTo=function(o){var u=o.umod(this.m);return u===o?u.clone():u},$.prototype.convertFrom=function(o){var u=o.clone();return u.red=null,u},s.mont=function(o){return new et(o)};function et(o){$.call(this,o),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new s(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(et,$),et.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},et.prototype.convertFrom=function(o){var u=this.imod(o.mul(this.rinv));return u.red=null,u},et.prototype.imul=function(o,u){if(o.isZero()||u.isZero())return o.words[0]=0,o.length=1,o;var d=o.imul(u),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=d.isub(m).iushrn(this.shift),y=g;return g.cmp(this.m)>=0?y=g.isub(this.m):g.cmpn(0)<0&&(y=g.iadd(this.m)),y._forceRed(this)},et.prototype.mul=function(o,u){if(o.isZero()||u.isZero())return new s(0)._forceRed(this);var d=o.mul(u),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=d.isub(m).iushrn(this.shift),y=g;return g.cmp(this.m)>=0?y=g.isub(this.m):g.cmpn(0)<0&&(y=g.iadd(this.m)),y._forceRed(this)},et.prototype.invm=function(o){var u=this.imod(o._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof t>"u"||t,i)}),Si={REQUEST_PARAMS:"requestParams",METHOD_NAME:"methodName"},gr=class kn extends Error{constructor(t,e,n){super(t),this.code=e,this.details=n,this.name=this.constructor.name}static{this.DETAILS_KEYS=Si}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 kn&&t.code===e}},_r=class extends gr{constructor(i,t,e){super(i,t||"UnknownError",e)}static isCommonErrorCode(i,t){return this.isErrorCode(i,t)}},zt=(i,t,e)=>{throw new _r(t,i,e)},ee="0x0000000000000000000000000000000000000000000000000000000000000006";var Ko=(0,Ei.getFullnodeUrl)("mainnet"),Zo=(0,Ei.getFullnodeUrl)("testnet");var Pn=864e5;var ye=9e15,me=1e9,Ci="0123456789abcdef",Ue="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",$e="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",xi={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ye,maxE:ye,crypto:!1},En,ne,R=!0,Xe="[DecimalError] ",he=Xe+"Invalid argument: ",On=Xe+"Precision limit exceeded",In=Xe+"crypto unavailable",Tn="[object Decimal]",Zt=Math.floor,Rt=Math.pow,Mr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Sr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ar=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Nn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Gt=1e7,D=7,Cr=9007199254740991,xr=Ue.length-1,ki=$e.length-1,A={toStringTag:Tn};A.absoluteValue=A.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),T(i)};A.ceil=function(){return T(new this.constructor(this),this.e+1,2)};A.clampedTo=A.clamp=function(i,t){var e,n=this,r=n.constructor;if(i=new r(i),t=new r(t),!i.s||!t.s)return new r(NaN);if(i.gt(t))throw Error(he+t);return e=n.cmp(i),e<0?i:n.cmp(t)>0?t:new r(n)};A.comparedTo=A.cmp=function(i){var t,e,n,r,a=this,s=a.d,l=(i=new a.constructor(i)).d,f=a.s,h=i.s;if(!s||!l)return!f||!h?NaN:f!==h?f:s===l?0:!s^f<0?1:-1;if(!s[0]||!l[0])return s[0]?f:l[0]?-h:0;if(f!==h)return f;if(a.e!==i.e)return a.e>i.e^f<0?1:-1;for(n=s.length,r=l.length,t=0,e=n<r?n:r;t<e;++t)if(s[t]!==l[t])return s[t]>l[t]^f<0?1:-1;return n===r?0:n>r^f<0?1:-1};A.cosine=A.cos=function(){var i,t,e=this,n=e.constructor;return e.d?e.d[0]?(i=n.precision,t=n.rounding,n.precision=i+Math.max(e.e,e.sd())+D,n.rounding=1,e=kr(n,Vn(n,e)),n.precision=i,n.rounding=t,T(ne==2||ne==3?e.neg():e,i,t,!0)):new n(1):new n(NaN)};A.cubeRoot=A.cbrt=function(){var i,t,e,n,r,a,s,l,f,h,b=this,w=b.constructor;if(!b.isFinite()||b.isZero())return new w(b);for(R=!1,a=b.s*Rt(b.s*b,1/3),!a||Math.abs(a)==1/0?(e=Ut(b.d),i=b.e,(a=(i-e.length+1)%3)&&(e+=a==1||a==-2?"0":"00"),a=Rt(e,1/3),i=Zt((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 w(e),n.s=b.s):n=new w(a.toString()),s=(i=w.precision)+3;;)if(l=n,f=l.times(l).times(l),h=f.plus(b),n=H(h.plus(b).times(l),h.plus(f),s+2,1),Ut(l.d).slice(0,s)===(e=Ut(n.d)).slice(0,s))if(e=e.slice(s-3,s+1),e=="9999"||!r&&e=="4999"){if(!r&&(T(l,i+1,0),l.times(l).times(l).eq(b))){n=l;break}s+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(T(n,i+1,1),t=!n.times(n).times(n).eq(b));break}return R=!0,T(n,i,w.rounding,t)};A.decimalPlaces=A.dp=function(){var i,t=this.d,e=NaN;if(t){if(i=t.length-1,e=(i-Zt(this.e/D))*D,i=t[i],i)for(;i%10==0;i/=10)e--;e<0&&(e=0)}return e};A.dividedBy=A.div=function(i){return H(this,new this.constructor(i))};A.dividedToIntegerBy=A.divToInt=function(i){var t=this,e=t.constructor;return T(H(t,new e(i),0,1,1),e.precision,e.rounding)};A.equals=A.eq=function(i){return this.cmp(i)===0};A.floor=function(){return T(new this.constructor(this),this.e+1,3)};A.greaterThan=A.gt=function(i){return this.cmp(i)>0};A.greaterThanOrEqualTo=A.gte=function(i){var t=this.cmp(i);return t==1||t===0};A.hyperbolicCosine=A.cosh=function(){var i,t,e,n,r,a=this,s=a.constructor,l=new s(1);if(!a.isFinite())return new s(a.s?1/0:NaN);if(a.isZero())return l;e=s.precision,n=s.rounding,s.precision=e+Math.max(a.e,a.sd())+4,s.rounding=1,r=a.d.length,r<32?(i=Math.ceil(r/3),t=(1/ze(4,i)).toString()):(i=16,t="2.3283064365386962890625e-10"),a=Me(s,1,a.times(t),new s(1),!0);for(var f,h=i,b=new s(8);h--;)f=a.times(a),a=l.minus(f.times(b.minus(f.times(b))));return T(a,s.precision=e,s.rounding=n,!0)};A.hyperbolicSine=A.sinh=function(){var i,t,e,n,r=this,a=r.constructor;if(!r.isFinite()||r.isZero())return new a(r);if(t=a.precision,e=a.rounding,a.precision=t+Math.max(r.e,r.sd())+4,a.rounding=1,n=r.d.length,n<3)r=Me(a,2,r,r,!0);else{i=1.4*Math.sqrt(n),i=i>16?16:i|0,r=r.times(1/ze(5,i)),r=Me(a,2,r,r,!0);for(var s,l=new a(5),f=new a(16),h=new a(20);i--;)s=r.times(r),r=r.times(l.plus(s.times(f.times(s).plus(h))))}return a.precision=t,a.rounding=e,T(r,t,e,!0)};A.hyperbolicTangent=A.tanh=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+7,n.rounding=1,H(e.sinh(),e.cosh(),n.precision=i,n.rounding=t)):new n(e.s)};A.inverseCosine=A.acos=function(){var i=this,t=i.constructor,e=i.abs().cmp(1),n=t.precision,r=t.rounding;return e!==-1?e===0?i.isNeg()?Qt(t,n,r):new t(0):new t(NaN):i.isZero()?Qt(t,n+4,r).times(.5):(t.precision=n+6,t.rounding=1,i=new t(1).minus(i).div(i.plus(1)).sqrt().atan(),t.precision=n,t.rounding=r,i.times(2))};A.inverseHyperbolicCosine=A.acosh=function(){var i,t,e=this,n=e.constructor;return e.lte(1)?new n(e.eq(1)?0:NaN):e.isFinite()?(i=n.precision,t=n.rounding,n.precision=i+Math.max(Math.abs(e.e),e.sd())+4,n.rounding=1,R=!1,e=e.times(e).minus(1).sqrt().plus(e),R=!0,n.precision=i,n.rounding=t,e.ln()):new n(e)};A.inverseHyperbolicSine=A.asinh=function(){var i,t,e=this,n=e.constructor;return!e.isFinite()||e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+2*Math.max(Math.abs(e.e),e.sd())+6,n.rounding=1,R=!1,e=e.times(e).plus(1).sqrt().plus(e),R=!0,n.precision=i,n.rounding=t,e.ln())};A.inverseHyperbolicTangent=A.atanh=function(){var i,t,e,n,r=this,a=r.constructor;return r.isFinite()?r.e>=0?new a(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(i=a.precision,t=a.rounding,n=r.sd(),Math.max(n,i)<2*-r.e-1?T(new a(r),i,t,!0):(a.precision=e=n-r.e,r=H(r.plus(1),new a(1).minus(r),e+i,1),a.precision=i+4,a.rounding=1,r=r.ln(),a.precision=i,a.rounding=t,r.times(.5))):new a(NaN)};A.inverseSine=A.asin=function(){var i,t,e,n,r=this,a=r.constructor;return r.isZero()?new a(r):(t=r.abs().cmp(1),e=a.precision,n=a.rounding,t!==-1?t===0?(i=Qt(a,e+4,n).times(.5),i.s=r.s,i):new a(NaN):(a.precision=e+6,a.rounding=1,r=r.div(new a(1).minus(r.times(r)).sqrt().plus(1)).atan(),a.precision=e,a.rounding=n,r.times(2)))};A.inverseTangent=A.atan=function(){var i,t,e,n,r,a,s,l,f,h=this,b=h.constructor,w=b.precision,v=b.rounding;if(h.isFinite()){if(h.isZero())return new b(h);if(h.abs().eq(1)&&w+4<=ki)return s=Qt(b,w+4,v).times(.25),s.s=h.s,s}else{if(!h.s)return new b(NaN);if(w+4<=ki)return s=Qt(b,w+4,v).times(.5),s.s=h.s,s}for(b.precision=l=w+10,b.rounding=1,e=Math.min(28,l/D+2|0),i=e;i;--i)h=h.div(h.times(h).plus(1).sqrt().plus(1));for(R=!1,t=Math.ceil(l/D),n=1,f=h.times(h),s=new b(h),r=h;i!==-1;)if(r=r.times(f),a=s.minus(r.div(n+=2)),r=r.times(f),s=a.plus(r.div(n+=2)),s.d[t]!==void 0)for(i=t;s.d[i]===a.d[i]&&i--;);return e&&(s=s.times(2<<e-1)),R=!0,T(s,b.precision=w,b.rounding=v,!0)};A.isFinite=function(){return!!this.d};A.isInteger=A.isInt=function(){return!!this.d&&Zt(this.e/D)>this.d.length-2};A.isNaN=function(){return!this.s};A.isNegative=A.isNeg=function(){return this.s<0};A.isPositive=A.isPos=function(){return this.s>0};A.isZero=function(){return!!this.d&&this.d[0]===0};A.lessThan=A.lt=function(i){return this.cmp(i)<0};A.lessThanOrEqualTo=A.lte=function(i){return this.cmp(i)<1};A.logarithm=A.log=function(i){var t,e,n,r,a,s,l,f,h=this,b=h.constructor,w=b.precision,v=b.rounding,S=5;if(i==null)i=new b(10),t=!0;else{if(i=new b(i),e=i.d,i.s<0||!e||!e[0]||i.eq(1))return new b(NaN);t=i.eq(10)}if(e=h.d,h.s<0||!e||!e[0]||h.eq(1))return new b(e&&!e[0]?-1/0:h.s!=1?NaN:e?0:1/0);if(t)if(e.length>1)a=!0;else{for(r=e[0];r%10===0;)r/=10;a=r!==1}if(R=!1,l=w+S,s=de(h,l),n=t?Ke(b,l+10):de(i,l),f=H(s,n,l,1),ke(f.d,r=w,v))do if(l+=10,s=de(h,l),n=t?Ke(b,l+10):de(i,l),f=H(s,n,l,1),!a){+Ut(f.d).slice(r+1,r+15)+1==1e14&&(f=T(f,w+1,0));break}while(ke(f.d,r+=10,v));return R=!0,T(f,w,v)};A.minus=A.sub=function(i){var t,e,n,r,a,s,l,f,h,b,w,v,S=this,C=S.constructor;if(i=new C(i),!S.d||!i.d)return!S.s||!i.s?i=new C(NaN):S.d?i.s=-i.s:i=new C(i.d||S.s!==i.s?S:NaN),i;if(S.s!=i.s)return i.s=-i.s,S.plus(i);if(h=S.d,v=i.d,l=C.precision,f=C.rounding,!h[0]||!v[0]){if(v[0])i.s=-i.s;else if(h[0])i=new C(S);else return new C(f===3?-0:0);return R?T(i,l,f):i}if(e=Zt(i.e/D),b=Zt(S.e/D),h=h.slice(),a=b-e,a){for(w=a<0,w?(t=h,a=-a,s=v.length):(t=v,e=b,s=h.length),n=Math.max(Math.ceil(l/D),s)+2,a>n&&(a=n,t.length=1),t.reverse(),n=a;n--;)t.push(0);t.reverse()}else{for(n=h.length,s=v.length,w=n<s,w&&(s=n),n=0;n<s;n++)if(h[n]!=v[n]){w=h[n]<v[n];break}a=0}for(w&&(t=h,h=v,v=t,i.s=-i.s),s=h.length,n=v.length-s;n>0;--n)h[s++]=0;for(n=v.length;n>a;){if(h[--n]<v[n]){for(r=n;r&&h[--r]===0;)h[r]=Gt-1;--h[r],h[n]+=Gt}h[n]-=v[n]}for(;h[--s]===0;)h.pop();for(;h[0]===0;h.shift())--e;return h[0]?(i.d=h,i.e=He(h,e),R?T(i,l,f):i):new C(f===3?-0:0)};A.modulo=A.mod=function(i){var t,e=this,n=e.constructor;return i=new n(i),!e.d||!i.s||i.d&&!i.d[0]?new n(NaN):!i.d||e.d&&!e.d[0]?T(new n(e),n.precision,n.rounding):(R=!1,n.modulo==9?(t=H(e,i.abs(),0,3,1),t.s*=i.s):t=H(e,i,0,n.modulo,1),t=t.times(i),R=!0,e.minus(t))};A.naturalExponential=A.exp=function(){return Pi(this)};A.naturalLogarithm=A.ln=function(){return de(this)};A.negated=A.neg=function(){var i=new this.constructor(this);return i.s=-i.s,T(i)};A.plus=A.add=function(i){var t,e,n,r,a,s,l,f,h,b,w=this,v=w.constructor;if(i=new v(i),!w.d||!i.d)return!w.s||!i.s?i=new v(NaN):w.d||(i=new v(i.d||w.s===i.s?w:NaN)),i;if(w.s!=i.s)return i.s=-i.s,w.minus(i);if(h=w.d,b=i.d,l=v.precision,f=v.rounding,!h[0]||!b[0])return b[0]||(i=new v(w)),R?T(i,l,f):i;if(a=Zt(w.e/D),n=Zt(i.e/D),h=h.slice(),r=a-n,r){for(r<0?(e=h,r=-r,s=b.length):(e=b,n=a,s=h.length),a=Math.ceil(l/D),s=a>s?a+1:s+1,r>s&&(r=s,e.length=1),e.reverse();r--;)e.push(0);e.reverse()}for(s=h.length,r=b.length,s-r<0&&(r=s,e=b,b=h,h=e),t=0;r;)t=(h[--r]=h[r]+b[r]+t)/Gt|0,h[r]%=Gt;for(t&&(h.unshift(t),++n),s=h.length;h[--s]==0;)h.pop();return i.d=h,i.e=He(h,n),R?T(i,l,f):i};A.precision=A.sd=function(i){var t,e=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(he+i);return e.d?(t=Fn(e.d),i&&e.e+1>t&&(t=e.e+1)):t=NaN,t};A.round=function(){var i=this,t=i.constructor;return T(new t(i),i.e+1,t.rounding)};A.sine=A.sin=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+Math.max(e.e,e.sd())+D,n.rounding=1,e=Er(n,Vn(n,e)),n.precision=i,n.rounding=t,T(ne>2?e.neg():e,i,t,!0)):new n(NaN)};A.squareRoot=A.sqrt=function(){var i,t,e,n,r,a,s=this,l=s.d,f=s.e,h=s.s,b=s.constructor;if(h!==1||!l||!l[0])return new b(!h||h<0&&(!l||l[0])?NaN:l?s:1/0);for(R=!1,h=Math.sqrt(+s),h==0||h==1/0?(t=Ut(l),(t.length+f)%2==0&&(t+="0"),h=Math.sqrt(t),f=Zt((f+1)/2)-(f<0||f%2),h==1/0?t="5e"+f:(t=h.toExponential(),t=t.slice(0,t.indexOf("e")+1)+f),n=new b(t)):n=new b(h.toString()),e=(f=b.precision)+3;;)if(a=n,n=a.plus(H(s,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&&(T(a,f+1,0),a.times(a).eq(s))){n=a;break}e+=4,r=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(T(n,f+1,1),i=!n.times(n).eq(s));break}return R=!0,T(n,f,b.rounding,i)};A.tangent=A.tan=function(){var i,t,e=this,n=e.constructor;return e.isFinite()?e.isZero()?new n(e):(i=n.precision,t=n.rounding,n.precision=i+10,n.rounding=1,e=e.sin(),e.s=1,e=H(e,new n(1).minus(e.times(e)).sqrt(),i+10,0),n.precision=i,n.rounding=t,T(ne==2||ne==4?e.neg():e,i,t,!0)):new n(NaN)};A.times=A.mul=function(i){var t,e,n,r,a,s,l,f,h,b=this,w=b.constructor,v=b.d,S=(i=new w(i)).d;if(i.s*=b.s,!v||!v[0]||!S||!S[0])return new w(!i.s||v&&!v[0]&&!S||S&&!S[0]&&!v?NaN:!v||!S?i.s/0:i.s*0);for(e=Zt(b.e/D)+Zt(i.e/D),f=v.length,h=S.length,f<h&&(a=v,v=S,S=a,s=f,f=h,h=s),a=[],s=f+h,n=s;n--;)a.push(0);for(n=h;--n>=0;){for(t=0,r=f+n;r>n;)l=a[r]+S[n]*v[r-n-1]+t,a[r--]=l%Gt|0,t=l/Gt|0;a[r]=(a[r]+t)%Gt|0}for(;!a[--s];)a.pop();return t?++e:a.shift(),i.d=a,i.e=He(a,e),R?T(i,w.precision,w.rounding):i};A.toBinary=function(i,t){return Oi(this,2,i,t)};A.toDecimalPlaces=A.toDP=function(i,t){var e=this,n=e.constructor;return e=new n(e),i===void 0?e:(Xt(i,0,me),t===void 0?t=n.rounding:Xt(t,0,8),T(e,i+e.e+1,t))};A.toExponential=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=te(n,!0):(Xt(i,0,me),t===void 0?t=r.rounding:Xt(t,0,8),n=T(new r(n),i+1,t),e=te(n,!0,i+1)),n.isNeg()&&!n.isZero()?"-"+e:e};A.toFixed=function(i,t){var e,n,r=this,a=r.constructor;return i===void 0?e=te(r):(Xt(i,0,me),t===void 0?t=a.rounding:Xt(t,0,8),n=T(new a(r),i+r.e+1,t),e=te(n,!1,i+n.e+1)),r.isNeg()&&!r.isZero()?"-"+e:e};A.toFraction=function(i){var t,e,n,r,a,s,l,f,h,b,w,v,S=this,C=S.d,x=S.constructor;if(!C)return new x(S);if(h=e=new x(1),n=f=new x(0),t=new x(n),a=t.e=Fn(C)-S.e-1,s=a%D,t.d[0]=Rt(10,s<0?D+s:s),i==null)i=a>0?t:h;else{if(l=new x(i),!l.isInt()||l.lt(h))throw Error(he+l);i=l.gt(t)?a>0?t:h:l}for(R=!1,l=new x(Ut(C)),b=x.precision,x.precision=a=C.length*D*2;w=H(l,t,0,1,1),r=e.plus(w.times(n)),r.cmp(i)!=1;)e=n,n=r,r=h,h=f.plus(w.times(r)),f=r,r=t,t=l.minus(w.times(r)),l=r;return r=H(i.minus(e),n,0,1,1),f=f.plus(r.times(h)),e=e.plus(r.times(n)),f.s=h.s=S.s,v=H(h,n,a,1).minus(S).abs().cmp(H(f,e,a,1).minus(S).abs())<1?[h,n]:[f,e],x.precision=b,R=!0,v};A.toHexadecimal=A.toHex=function(i,t){return Oi(this,16,i,t)};A.toNearest=function(i,t){var e=this,n=e.constructor;if(e=new n(e),i==null){if(!e.d)return e;i=new n(1),t=n.rounding}else{if(i=new n(i),t===void 0?t=n.rounding: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]?(R=!1,e=H(e,i,0,t,1).times(i),R=!0,T(e)):(i.s=e.s,e=i),e};A.toNumber=function(){return+this};A.toOctal=function(i,t){return Oi(this,8,i,t)};A.toPower=A.pow=function(i){var t,e,n,r,a,s,l=this,f=l.constructor,h=+(i=new f(i));if(!l.d||!i.d||!l.d[0]||!i.d[0])return new f(Rt(+l,h));if(l=new f(l),l.eq(1))return l;if(n=f.precision,a=f.rounding,i.eq(1))return T(l,n,a);if(t=Zt(i.e/D),t>=i.d.length-1&&(e=h<0?-h:h)<=Cr)return r=Bn(f,l,e,n),i.s<0?new f(1).div(r):T(r,n,a);if(s=l.s,s<0){if(t<i.d.length-1)return new f(NaN);if(!(i.d[t]&1)&&(s=1),l.e==0&&l.d[0]==1&&l.d.length==1)return l.s=s,l}return e=Rt(+l,h),t=e==0||!isFinite(e)?Zt(h*(Math.log("0."+Ut(l.d))/Math.LN10+l.e+1)):new f(e+"").e,t>f.maxE+1||t<f.minE-1?new f(t>0?s/0:0):(R=!1,f.rounding=l.s=1,e=Math.min(12,(t+"").length),r=Pi(i.times(de(l,n+e)),n),r.d&&(r=T(r,n+5,1),ke(r.d,n,a)&&(t=n+10,r=T(Pi(i.times(de(l,t+e)),t),t+5,1),+Ut(r.d).slice(n+1,n+15)+1==1e14&&(r=T(r,n+1,0)))),r.s=s,R=!0,f.rounding=a,T(r,n,a))};A.toPrecision=function(i,t){var e,n=this,r=n.constructor;return i===void 0?e=te(n,n.e<=r.toExpNeg||n.e>=r.toExpPos):(Xt(i,1,me),t===void 0?t=r.rounding:Xt(t,0,8),n=T(new r(n),i,t),e=te(n,i<=n.e||n.e<=r.toExpNeg,i)),n.isNeg()&&!n.isZero()?"-"+e:e};A.toSignificantDigits=A.toSD=function(i,t){var e=this,n=e.constructor;return i===void 0?(i=n.precision,t=n.rounding):(Xt(i,1,me),t===void 0?t=n.rounding:Xt(t,0,8)),T(new n(e),i,t)};A.toString=function(){var i=this,t=i.constructor,e=te(i,i.e<=t.toExpNeg||i.e>=t.toExpPos);return i.isNeg()&&!i.isZero()?"-"+e:e};A.truncated=A.trunc=function(){return T(new this.constructor(this),this.e+1,1)};A.valueOf=A.toJSON=function(){var i=this,t=i.constructor,e=te(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="",s=i[0];if(r>0){for(a+=s,t=1;t<r;t++)n=i[t]+"",e=D-n.length,e&&(a+=le(e)),a+=n;s=i[t],n=s+"",e=D-n.length,e&&(a+=le(e))}else if(s===0)return"0";for(;s%10===0;)s/=10;return a+s}function Xt(i,t,e){if(i!==~~i||i<t||i>e)throw Error(he+i)}function ke(i,t,e,n){var r,a,s,l;for(a=i[0];a>=10;a/=10)--t;return--t<0?(t+=D,r=0):(r=Math.ceil((t+1)/D),t%=D),a=Rt(10,D-t),l=i[r]%a|0,n==null?t<3?(t==0?l=l/100|0:t==1&&(l=l/10|0),s=e<4&&l==99999||e>3&&l==49999||l==5e4||l==0):s=(e<4&&l+1==a||e>3&&l+1==a/2)&&(i[r+1]/a/100|0)==Rt(10,t-2)-1||(l==a/2||l==0)&&(i[r+1]/a/100|0)==0:t<4?(t==0?l=l/1e3|0:t==1?l=l/100|0:t==2&&(l=l/10|0),s=(n||e<4)&&l==9999||!n&&e>3&&l==4999):s=((n||e<4)&&l+1==a||!n&&e>3&&l+1==a/2)&&(i[r+1]/a/1e3|0)==Rt(10,t-3)-1,s}function Le(i,t,e){for(var n,r=[0],a,s=0,l=i.length;s<l;){for(a=r.length;a--;)r[a]*=t;for(r[0]+=Ci.indexOf(i.charAt(s++)),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 kr(i,t){var e,n,r;if(t.isZero())return t;n=t.d.length,n<32?(e=Math.ceil(n/3),r=(1/ze(4,e)).toString()):(e=16,r="2.3283064365386962890625e-10"),i.precision+=e,t=Me(i,1,t.times(r),new i(1));for(var a=e;a--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return i.precision-=e,t}var H=function(){function i(n,r,a){var s,l=0,f=n.length;for(n=n.slice();f--;)s=n[f]*r+l,n[f]=s%a|0,l=s/a|0;return l&&n.unshift(l),n}function t(n,r,a,s){var l,f;if(a!=s)f=a>s?1:-1;else for(l=f=0;l<a;l++)if(n[l]!=r[l]){f=n[l]>r[l]?1:-1;break}return f}function e(n,r,a,s){for(var l=0;a--;)n[a]-=l,l=n[a]<r[a]?1:0,n[a]=l*s+n[a]-r[a];for(;!n[0]&&n.length>1;)n.shift()}return function(n,r,a,s,l,f){var h,b,w,v,S,C,x,N,E,q,k,V,qt,K,Lt,X,Z,z,Q,jt,$=n.constructor,et=n.s==r.s?1:-1,o=n.d,u=r.d;if(!o||!o[0]||!u||!u[0])return new $(!n.s||!r.s||(o?u&&o[0]==u[0]:!u)?NaN:o&&o[0]==0||!u?et*0:et/0);for(f?(S=1,b=n.e-r.e):(f=Gt,S=D,b=Zt(n.e/S)-Zt(r.e/S)),Q=u.length,Z=o.length,E=new $(et),q=E.d=[],w=0;u[w]==(o[w]||0);w++);if(u[w]>(o[w]||0)&&b--,a==null?(K=a=$.precision,s=$.rounding):l?K=a+(n.e-r.e)+1:K=a,K<0)q.push(1),C=!0;else{if(K=K/S+2|0,w=0,Q==1){for(v=0,u=u[0],K++;(w<Z||v)&&K--;w++)Lt=v*f+(o[w]||0),q[w]=Lt/u|0,v=Lt%u|0;C=v||w<Z}else{for(v=f/(u[0]+1)|0,v>1&&(u=i(u,v,f),o=i(o,v,f),Q=u.length,Z=o.length),X=Q,k=o.slice(0,Q),V=k.length;V<Q;)k[V++]=0;jt=u.slice(),jt.unshift(0),z=u[0],u[1]>=f/2&&++z;do v=0,h=t(u,k,Q,V),h<0?(qt=k[0],Q!=V&&(qt=qt*f+(k[1]||0)),v=qt/z|0,v>1?(v>=f&&(v=f-1),x=i(u,v,f),N=x.length,V=k.length,h=t(x,k,N,V),h==1&&(v--,e(x,Q<N?jt:u,N,f))):(v==0&&(h=v=1),x=u.slice()),N=x.length,N<V&&x.unshift(0),e(k,x,V,f),h==-1&&(V=k.length,h=t(u,k,Q,V),h<1&&(v++,e(k,Q<V?jt:u,V,f))),V=k.length):h===0&&(v++,k=[0]),q[w++]=v,h&&k[0]?k[V++]=o[X]||0:(k=[o[X]],V=1);while((X++<Z||k[0]!==void 0)&&K--);C=k[0]!==void 0}q[0]||q.shift()}if(S==1)E.e=b,En=C;else{for(w=1,v=q[0];v>=10;v/=10)w++;E.e=w+b*S-1,T(E,l?a+E.e+1:a,s,C)}return E}}();function T(i,t,e,n){var r,a,s,l,f,h,b,w,v,S=i.constructor;t:if(t!=null){if(w=i.d,!w)return i;for(r=1,l=w[0];l>=10;l/=10)r++;if(a=t-r,a<0)a+=D,s=t,b=w[v=0],f=b/Rt(10,r-s-1)%10|0;else if(v=Math.ceil((a+1)/D),l=w.length,v>=l)if(n){for(;l++<=v;)w.push(0);b=f=0,r=1,a%=D,s=a-D+1}else break t;else{for(b=l=w[v],r=1;l>=10;l/=10)r++;a%=D,s=a-D+r,f=s<0?0:b/Rt(10,r-s-1)%10|0}if(n=n||t<0||w[v+1]!==void 0||(s<0?b:b%Rt(10,r-s-1)),h=e<4?(f||n)&&(e==0||e==(i.s<0?3:2)):f>5||f==5&&(e==4||n||e==6&&(a>0?s>0?b/Rt(10,r-s):0:w[v-1])%10&1||e==(i.s<0?8:7)),t<1||!w[0])return w.length=0,h?(t-=i.e+1,w[0]=Rt(10,(D-t%D)%D),i.e=-t||0):w[0]=i.e=0,i;if(a==0?(w.length=v,l=1,v--):(w.length=v+1,l=Rt(10,D-a),w[v]=s>0?(b/Rt(10,r-s)%Rt(10,s)|0)*l:0),h)for(;;)if(v==0){for(a=1,s=w[0];s>=10;s/=10)a++;for(s=w[0]+=l,l=1;s>=10;s/=10)l++;a!=l&&(i.e++,w[0]==Gt&&(w[0]=1));break}else{if(w[v]+=l,w[v]!=Gt)break;w[v--]=0,l=1}for(a=w.length;w[--a]===0;)w.pop()}return R&&(i.e>S.maxE?(i.d=null,i.e=NaN):i.e<S.minE&&(i.e=0,i.d=[0])),i}function te(i,t,e){if(!i.isFinite())return qn(i);var n,r=i.e,a=Ut(i.d),s=a.length;return t?(e&&(n=e-s)>0?a=a.charAt(0)+"."+a.slice(1)+le(n):s>1&&(a=a.charAt(0)+"."+a.slice(1)),a=a+(i.e<0?"e":"e+")+i.e):r<0?(a="0."+le(-r-1)+a,e&&(n=e-s)>0&&(a+=le(n))):r>=s?(a+=le(r+1-s),e&&(n=e-r-1)>0&&(a=a+"."+le(n))):((n=r+1)<s&&(a=a.slice(0,n)+"."+a.slice(n)),e&&(n=e-s)>0&&(r+1===s&&(a+="."),a+=le(n))),a}function He(i,t){var e=i[0];for(t*=D;e>=10;e/=10)t++;return t}function Ke(i,t,e){if(t>xr)throw R=!0,e&&(i.precision=e),Error(On);return T(new i(Ue),t,1,!0)}function Qt(i,t,e){if(t>ki)throw Error(On);return T(new i($e),t,e,!0)}function Fn(i){var t=i.length-1,e=t*D+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 le(i){for(var t="";i--;)t+="0";return t}function Bn(i,t,e,n){var r,a=new i(1),s=Math.ceil(n/D+4);for(R=!1;;){if(e%2&&(a=a.times(t),wn(a.d,s)&&(r=!0)),e=Zt(e/2),e===0){e=a.d.length-1,r&&a.d[e]===0&&++a.d[e];break}t=t.times(t),wn(t.d,s)}return R=!0,a}function bn(i){return i.d[i.d.length-1]&1}function Dn(i,t,e){for(var n,r,a=new i(t[0]),s=0;++s<t.length;){if(r=new i(t[s]),!r.s){a=r;break}n=a.cmp(r),(n===e||n===0&&a.s===e)&&(a=r)}return a}function Pi(i,t){var e,n,r,a,s,l,f,h=0,b=0,w=0,v=i.constructor,S=v.rounding,C=v.precision;if(!i.d||!i.d[0]||i.e>17)return new v(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(t==null?(R=!1,f=C):f=t,l=new v(.03125);i.e>-2;)i=i.times(l),w+=5;for(n=Math.log(Rt(2,w))/Math.LN10*2+5|0,f+=n,e=a=s=new v(1),v.precision=f;;){if(a=T(a.times(i),f,1),e=e.times(++b),l=s.plus(H(a,e,f,1)),Ut(l.d).slice(0,f)===Ut(s.d).slice(0,f)){for(r=w;r--;)s=T(s.times(s),f,1);if(t==null)if(h<3&&ke(s.d,f-n,S,h))v.precision=f+=10,e=a=l=new v(1),b=0,h++;else return T(s,v.precision=C,S,R=!0);else return v.precision=C,s}s=l}}function de(i,t){var e,n,r,a,s,l,f,h,b,w,v,S=1,C=10,x=i,N=x.d,E=x.constructor,q=E.rounding,k=E.precision;if(x.s<0||!N||!N[0]||!x.e&&N[0]==1&&N.length==1)return new E(N&&!N[0]?-1/0:x.s!=1?NaN:N?0:x);if(t==null?(R=!1,b=k):b=t,E.precision=b+=C,e=Ut(N),n=e.charAt(0),Math.abs(a=x.e)<15e14){for(;n<7&&n!=1||n==1&&e.charAt(1)>3;)x=x.times(i),e=Ut(x.d),n=e.charAt(0),S++;a=x.e,n>1?(x=new E("0."+e),a++):x=new E(n+"."+e.slice(1))}else return h=Ke(E,b+2,k).times(a+""),x=de(new E(n+"."+e.slice(1)),b-C).plus(h),E.precision=k,t==null?T(x,k,q,R=!0):x;for(w=x,f=s=x=H(x.minus(1),x.plus(1),b,1),v=T(x.times(x),b,1),r=3;;){if(s=T(s.times(v),b,1),h=f.plus(H(s,new E(r),b,1)),Ut(h.d).slice(0,b)===Ut(f.d).slice(0,b))if(f=f.times(2),a!==0&&(f=f.plus(Ke(E,b+2,k).times(a+""))),f=H(f,new E(S),b,1),t==null)if(ke(f.d,b-C,q,l))E.precision=b+=C,h=s=x=H(w.minus(1),w.plus(1),b,1),v=T(x.times(x),b,1),r=l=1;else return T(f,E.precision=k,q,R=!0);else return E.precision=k,f;f=h,r+=2}}function qn(i){return String(i.s*i.s/0)}function je(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)%D,e<0&&(n+=D),n<r){for(n&&i.d.push(+t.slice(0,n)),r-=D;n<r;)i.d.push(+t.slice(n,n+=D));t=t.slice(n),n=D-t.length}else n-=r;for(;n--;)t+="0";i.d.push(+t),R&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function Pr(i,t){var e,n,r,a,s,l,f,h,b;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Nn.test(t))return je(i,t)}else if(t==="Infinity"||t==="NaN")return+t||(i.s=NaN),i.e=NaN,i.d=null,i;if(Sr.test(t))e=16,t=t.toLowerCase();else if(Mr.test(t))e=2;else if(Ar.test(t))e=8;else throw Error(he+t);for(a=t.search(/p/i),a>0?(f=+t.slice(a+1),t=t.substring(2,a)):t=t.slice(2),a=t.indexOf("."),s=a>=0,n=i.constructor,s&&(t=t.replace(".",""),l=t.length,a=l-a,r=Bn(n,new n(e),a,a*2)),h=Le(t,e,Gt),b=h.length-1,a=b;h[a]===0;--a)h.pop();return a<0?new n(i.s*0):(i.e=He(h,b),i.d=h,R=!1,s&&(i=H(i,r,l*4)),f&&(i=i.times(Math.abs(f)<54?Rt(2,f):Oe.pow(2,f))),R=!0,i)}function Er(i,t){var e,n=t.d.length;if(n<3)return t.isZero()?t:Me(i,2,t,t);e=1.4*Math.sqrt(n),e=e>16?16:e|0,t=t.times(1/ze(5,e)),t=Me(i,2,t,t);for(var r,a=new i(5),s=new i(16),l=new i(20);e--;)r=t.times(t),t=t.times(a.plus(r.times(s.times(r).minus(l))));return t}function Me(i,t,e,n,r){var a,s,l,f,h=1,b=i.precision,w=Math.ceil(b/D);for(R=!1,f=e.times(e),l=new i(n);;){if(s=H(l.times(f),new i(t++*t++),b,1),l=r?n.plus(s):n.minus(s),n=H(s.times(f),new i(t++*t++),b,1),s=l.plus(n),s.d[w]!==void 0){for(a=w;s.d[a]===l.d[a]&&a--;);if(a==-1)break}a=l,l=n,n=s,s=a,h++}return R=!0,s.d.length=w+1,s}function ze(i,t){for(var e=i;--t;)e*=i;return e}function Vn(i,t){var e,n=t.s<0,r=Qt(i,i.precision,1),a=r.times(.5);if(t=t.abs(),t.lte(a))return ne=n?4:1,t;if(e=t.divToInt(r),e.isZero())ne=n?3:2;else{if(t=t.minus(e.times(r)),t.lte(a))return ne=bn(e)?n?2:3:n?4:1,t;ne=bn(e)?n?1:4:n?3:2}return t.minus(r).abs()}function Oi(i,t,e,n){var r,a,s,l,f,h,b,w,v,S=i.constructor,C=e!==void 0;if(C?(Xt(e,1,me),n===void 0?n=S.rounding:Xt(n,0,8)):(e=S.precision,n=S.rounding),!i.isFinite())b=qn(i);else{for(b=te(i),s=b.indexOf("."),C?(r=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):r=t,s>=0&&(b=b.replace(".",""),v=new S(1),v.e=b.length-s,v.d=Le(te(v),10,r),v.e=v.d.length),w=Le(b,10,r),a=f=w.length;w[--f]==0;)w.pop();if(!w[0])b=C?"0p+0":"0";else{if(s<0?a--:(i=new S(i),i.d=w,i.e=a,i=H(i,v,e,n,0,r),w=i.d,a=i.e,h=En),s=w[e],l=r/2,h=h||w[e+1]!==void 0,h=n<4?(s!==void 0||h)&&(n===0||n===(i.s<0?3:2)):s>l||s===l&&(n===4||h||n===6&&w[e-1]&1||n===(i.s<0?8:7)),w.length=e,h)for(;++w[--e]>r-1;)w[e]=0,e||(++a,w.unshift(1));for(f=w.length;!w[f-1];--f);for(s=0,b="";s<f;s++)b+=Ci.charAt(w[s]);if(C){if(f>1)if(t==16||t==8){for(s=t==16?4:3,--f;f%s;f++)b+="0";for(w=Le(b,r,t),f=w.length;!w[f-1];--f);for(s=1,b="1.";s<f;s++)b+=Ci.charAt(w[s])}else b=b.charAt(0)+"."+b.slice(1);b=b+(a<0?"p":"p+")+a}else if(a<0){for(;++a;)b="0"+b;b="0."+b}else if(++a>f)for(a-=f;a--;)b+="0";else a<f&&(b=b.slice(0,a)+"."+b.slice(a))}b=(t==16?"0x":t==2?"0b":t==8?"0o":"")+b}return i.s<0?"-"+b:b}function wn(i,t){if(i.length>t)return i.length=t,!0}function Or(i){return new this(i).abs()}function Ir(i){return new this(i).acos()}function Tr(i){return new this(i).acosh()}function Nr(i,t){return new this(i).plus(t)}function Fr(i){return new this(i).asin()}function Br(i){return new this(i).asinh()}function Dr(i){return new this(i).atan()}function qr(i){return new this(i).atanh()}function Vr(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=Qt(this,a,1).times(t.s>0?.25:.75),e.s=i.s):!t.d||i.isZero()?(e=t.s<0?Qt(this,n,r):new this(0),e.s=i.s):!i.d||t.isZero()?(e=Qt(this,a,1).times(.5),e.s=i.s):t.s<0?(this.precision=a,this.rounding=1,e=this.atan(H(i,t,a,1)),t=Qt(this,a,1),this.precision=n,this.rounding=r,e=i.s<0?e.minus(t):e.plus(t)):e=this.atan(H(i,t,a,1)),e}function Rr(i){return new this(i).cbrt()}function Lr(i){return T(i=new this(i),i.e+1,2)}function jr(i,t,e){return new this(i).clamp(t,e)}function Ur(i){if(!i||typeof i!="object")throw Error(Xe+"Object expected");var t,e,n,r=i.defaults===!0,a=["precision",1,me,"rounding",0,8,"toExpNeg",-ye,0,"toExpPos",0,ye,"maxE",0,ye,"minE",-ye,0,"modulo",0,9];for(t=0;t<a.length;t+=3)if(e=a[t],r&&(this[e]=xi[e]),(n=i[e])!==void 0)if(Zt(n)===n&&n>=a[t+1]&&n<=a[t+2])this[e]=n;else throw Error(he+e+": "+n);if(e="crypto",r&&(this[e]=xi[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(In);else this[e]=!1;else throw Error(he+e+": "+n);return this}function $r(i){return new this(i).cos()}function Kr(i){return new this(i).cosh()}function Rn(i){var t,e,n;function r(a){var s,l,f,h=this;if(!(h instanceof r))return new r(a);if(h.constructor=r,vn(a)){h.s=a.s,R?!a.d||a.e>r.maxE?(h.e=NaN,h.d=null):a.e<r.minE?(h.e=0,h.d=[0]):(h.e=a.e,h.d=a.d.slice()):(h.e=a.e,h.d=a.d?a.d.slice():a.d);return}if(f=typeof a,f==="number"){if(a===0){h.s=1/a<0?-1:1,h.e=0,h.d=[0];return}if(a<0?(a=-a,h.s=-1):h.s=1,a===~~a&&a<1e7){for(s=0,l=a;l>=10;l/=10)s++;R?s>r.maxE?(h.e=NaN,h.d=null):s<r.minE?(h.e=0,h.d=[0]):(h.e=s,h.d=[a]):(h.e=s,h.d=[a]);return}if(a*0!==0){a||(h.s=NaN),h.e=NaN,h.d=null;return}return je(h,a.toString())}if(f==="string")return(l=a.charCodeAt(0))===45?(a=a.slice(1),h.s=-1):(l===43&&(a=a.slice(1)),h.s=1),Nn.test(a)?je(h,a):Pr(h,a);if(f==="bigint")return a<0?(a=-a,h.s=-1):h.s=1,je(h,a.toString());throw Error(he+a)}if(r.prototype=A,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=Ur,r.clone=Rn,r.isDecimal=vn,r.abs=Or,r.acos=Ir,r.acosh=Tr,r.add=Nr,r.asin=Fr,r.asinh=Br,r.atan=Dr,r.atanh=qr,r.atan2=Vr,r.cbrt=Rr,r.ceil=Lr,r.clamp=jr,r.cos=$r,r.cosh=Kr,r.div=Zr,r.exp=Xr,r.floor=Hr,r.hypot=zr,r.ln=Wr,r.log=Gr,r.log10=Jr,r.log2=Yr,r.max=Qr,r.min=to,r.mod=eo,r.mul=io,r.pow=no,r.random=ro,r.round=oo,r.sign=so,r.sin=ao,r.sinh=co,r.sqrt=uo,r.sub=lo,r.sum=fo,r.tan=ho,r.tanh=mo,r.trunc=po,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 Zr(i,t){return new this(i).div(t)}function Xr(i){return new this(i).exp()}function Hr(i){return T(i=new this(i),i.e+1,3)}function zr(){var i,t,e=new this(0);for(R=!1,i=0;i<arguments.length;)if(t=new this(arguments[i++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return R=!0,new this(1/0);e=t}return R=!0,e.sqrt()}function vn(i){return i instanceof Oe||i&&i.toStringTag===Tn||!1}function Wr(i){return new this(i).ln()}function Gr(i,t){return new this(i).log(t)}function Yr(i){return new this(i).log(2)}function Jr(i){return new this(i).log(10)}function Qr(){return Dn(this,arguments,-1)}function to(){return Dn(this,arguments,1)}function eo(i,t){return new this(i).mod(t)}function io(i,t){return new this(i).mul(t)}function no(i,t){return new this(i).pow(t)}function ro(i){var t,e,n,r,a=0,s=new this(1),l=[];if(i===void 0?i=this.precision:Xt(i,1,me),n=Math.ceil(i/D),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]:l[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):(l.push(r%1e7),a+=4);a=n/4}else throw Error(In);else for(;a<n;)l[a++]=Math.random()*1e7|0;for(n=l[--a],i%=D,n&&i&&(r=Rt(10,D-i),l[a]=(n/r|0)*r);l[a]===0;a--)l.pop();if(a<0)e=0,l=[0];else{for(e=-1;l[0]===0;e-=D)l.shift();for(n=1,r=l[0];r>=10;r/=10)n++;n<D&&(e-=D-n)}return s.e=e,s.d=l,s}function oo(i){return T(i=new this(i),i.e+1,this.rounding)}function so(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function ao(i){return new this(i).sin()}function co(i){return new this(i).sinh()}function uo(i){return new this(i).sqrt()}function lo(i,t){return new this(i).sub(t)}function fo(){var i=0,t=arguments,e=new this(t[i]);for(R=!1;e.s&&++i<t.length;)e=e.plus(t[i]);return R=!0,T(e,this.precision,this.rounding)}function ho(i){return new this(i).tan()}function mo(i){return new this(i).tanh()}function po(i){return T(i=new this(i),i.e+1,1)}A[Symbol.for("nodejs.util.inspect.custom")]=A.toString;A[Symbol.toStringTag]="Decimal";var Oe=A.constructor=Rn(xi);Ue=new Oe(Ue);$e=new Oe($e);var Jt=Oe;function P(i){return Jt.isDecimal(i)?i:new Jt(i===void 0?0:i)}function Ln(i){return P(10).pow(P(i).abs())}function fe(i,t){let e=Ln(P(t));return Number(P(i).mul(e))}function Ie(i,t=32){return Number(BigInt.asIntN(t,BigInt(i)))}function Ze(i,t){let e=Ln(P(t));return Number(P(i).div(e))}var jn="0x2::sui::SUI",go="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";var oe=class Dt{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=>{Mn(r.coin_type)===Mn(t)&&n.push(r)}),n}static isSuiCoin(t){return re(t).full_address===jn}static selectCoinObjectIdGreaterThanOrEqual(t,e,n=[]){let r=Dt.selectCoinAssetGreaterThanOrEqual(t,e,n),a=r.selected_coins.map(f=>f.coin_object_id),s=r.remain_coins,l=r.selected_coins.map(f=>f.balance.toString());return{object_array:a,remain_coins:s,amount_array:l}}static selectCoinAssetGreaterThanOrEqual(t,e,n=[]){let r=Dt.sortByBalance(t.filter(h=>!n.includes(h.coin_object_id))),a=Dt.calculateTotalBalance(r);if(a<e)return{selected_coins:[],remain_coins:r};if(a===e)return{selected_coins:r,remain_coins:[]};let s=BigInt(0),l=[],f=[...r];for(;s<a;){let h=e-s,b=f.findIndex(v=>v.balance>=h);if(b!==-1){l.push(f[b]),f.splice(b,1);break}let w=f.pop();w.balance>0&&(l.push(w),s+=w.balance)}return{selected_coins:Dt.sortByBalance(l),remain_coins:Dt.sortByBalance(f)}}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,s=!0){let l=Dt.getCoinAssets(r,e);if(n===BigInt(0))return this.buildZeroValueCoin(e,t,r,a);let f=Dt.calculateTotalBalance(l);if(f<n)throw new Error(`The amount(${f}) is Insufficient balance for ${r} , expect ${n} `);return this.buildCoin(t,e,l,n,r,a,s)}static buildCoinWithBalance(t,e,n){return t===BigInt(0)&&Dt.isSuiCoin(e)?n.add((0,Ai.coinWithBalance)({balance:t,useGasCoin:!1})):n.add((0,Ai.coinWithBalance)({balance:t,type:e}))}static buildVectorCoin(t,e,n,r,a,s=!0){if(Dt.isSuiCoin(a)){let v=t.splitCoins(t.gas,[t.pure.u64(r)]);return{selected_coins:[],target_coin:v,remain_coins:e,target_coin_amount:r.toString(),is_mint_zero_coin:!1,original_spited_coin:t.gas}}let{original_spited_coin:l,target_coin:f,target_coin_amount:h,remain_coins:b,selected_coins:w}=this.buildSpitTargeCoin(t,r,n,s);return s?{target_coin:t.makeMoveVec({elements:[f]}),selected_coins:w,remain_coins:b,target_coin_amount:h,is_mint_zero_coin:!1,original_spited_coin:l}:{selected_coins:w,target_coin:t.makeMoveVec({elements:w.map(v=>t.object(v))}),remain_coins:b,target_coin_amount:h,is_mint_zero_coin:!1}}static buildOneCoin(t,e,n,r,a=!0){if(Dt.isSuiCoin(r)){if(n===0n&&e.length>1){let f=Dt.selectCoinObjectIdGreaterThanOrEqual(e,n);return{selected_coins:f.object_array,target_coin:t.object(f.object_array[0]),remain_coins:f.remain_coins,target_coin_amount:f.amount_array[0],is_mint_zero_coin:!1}}let s=Dt.selectCoinObjectIdGreaterThanOrEqual(e,n),l=t.splitCoins(t.gas,[t.pure.u64(n)]);return{selected_coins:[],target_coin:l,remain_coins:s.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=Dt.selectCoinObjectIdGreaterThanOrEqual(n,e),s=a.amount_array.reduce((C,x)=>Number(C)+Number(x),0).toString(),l=a.object_array,[f,...h]=l,b=t.object(f),w=b,v=a.amount_array.reduce((C,x)=>Number(C)+Number(x),0).toString(),S;return h.length>0&&t.mergeCoins(b,h.map(C=>t.object(C))),r&&Number(s)>Number(e)&&(w=t.splitCoins(b,[t.pure.u64(e)]),S=b),{original_spited_coin:S,target_coin:w,target_coin_amount:v,remain_coins:a.remain_coins,selected_coins:a.object_array,is_mint_zero_coin:!1}}static buildCoin(t,e,n,r,a,s=!0,l=!0){return s?this.buildVectorCoin(t,e,n,r,a,l):this.buildOneCoin(t,n,r,a,l)}static buildZeroValueCoin(t,e,n,r=!0){let a=this.callMintZeroValueCoin(e,n),s;return r?s=e.makeMoveVec({elements:[a]}):s=a,{target_coin:s,remain_coins:t,selected_coins:[],is_mint_zero_coin:!0,target_coin_amount:"0"}}static buildCoinForAmountInterval(t,e,n,r,a=!0,s=!0){let l=Dt.getCoinAssets(r,e);if(n.amount_first===BigInt(0))return l.length>0?this.buildCoin(t,[...e],[...l],n.amount_first,r,a,s):this.buildZeroValueCoin(e,t,r,a);let f=Dt.calculateTotalBalance(l);if(f>=n.amount_first)return this.buildCoin(t,[...e],[...l],n.amount_first,r,a,s);if(f<n.amount_second)throw new Error(`The amount(${f}) is Insufficient balance for ${r} , expect ${n.amount_second} `);return this.buildCoin(t,[...e],[...l],n.amount_second,r,a,s)}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 getCoinAmountObjId(t,e){let n=t.amount_coin_array.find(r=>!r.used&&P(r.amount).eq(e)?(r.used=!0,!0):!1);return n?n.coin_object_id:zt("CoinNotFound",`Coin not found for ${e} ${t.coin_type}`)}static buildMultiCoinInput(t,e,n,r){let a=Dt.getCoinAssets(n,e);if(Dt.isSuiCoin(n)){let w=t.splitCoins(t.gas,r.map(v=>t.pure.u64(v)));return{amount_coin_array:r.map((v,S)=>({coin_object_id:w[S],amount:v.toString(),used:!1})),coin_type:n,remain_coins:a}}let s=r.reduce((w,v)=>w+v,BigInt(0)),l=Dt.selectCoinObjectIdGreaterThanOrEqual(a,s);if(l.object_array.length===0)return zt("InsufficientBalance",`No enough coins for ${n} expect ${s} actual ${Dt.calculateTotalBalance(a)}`);let[f,...h]=l.object_array;h.length>0&&t.mergeCoins(f,[...h]);let b=t.splitCoins(f,r.map(w=>t.pure.u64(w)));return{amount_coin_array:r.map((w,v)=>({coin_object_id:b[v],amount:w.toString(),used:!1})),remain_coins:l.remain_coins,coin_type:n}}};function _o(i){return i.startsWith("0x")?`${i.slice(2)}`:i}function yn(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 re(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={...re(t),type_arguments:e.map(s=>re(s).source_address)};return a.type_arguments=a.type_arguments.map(s=>oe.isSuiCoin(s)?s:re(s).source_address),a.source_address=yn(a.full_address,a.type_arguments),a}let n=t.split("::"),r={full_address:t,address:t===jn||t===go?"0x2":(0,ge.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=yn(r.full_address,r.type_arguments),r}catch{return{full_address:i,address:"",module:"",name:"",type_arguments:[],source_address:i}}}function Mn(i){return re(i).source_address}var Y=(i,t=!0)=>{let e=i.split("::"),n=e.shift(),r=(0,ge.normalizeSuiObjectId)(n);return t&&(r=_o(r)),`${r}::${e.join("::")}`};var vo=Pe(Ee()),Sn=443636,An=-443636,yo="79226673515401279992447579055";var Mo="4295048016",Xo=new vo.default(1e6),So=(i=>(i[i.BelowRange=0]="BelowRange",i[i.InRange=1]="InRange",i[i.AboveRange=2]="AboveRange",i))(So||{}),Vt=Pe(Ee()),ie=new Vt.default(0),xe=new Vt.default(1),We=new Vt.default(2),Ho=We.pow(new Vt.default(128)),Cn=We.pow(new Vt.default(64)).sub(xe),Ao=We.pow(new Vt.default(128)).sub(xe),Wt=class{static toX64BN(i){return i.mul(new Vt.default(2).pow(new Vt.default(64)))}static toX64Decimal(i){return i.mul(Jt.pow(2,64))}static toX64(i){return new Vt.default(i.mul(Jt.pow(2,64)).floor().toFixed())}static fromX64(i){return new Jt(i.toString()).mul(Jt.pow(2,-64))}static fromX64Decimal(i){return i.mul(Jt.pow(2,-64))}static fromX64BN(i){return i.div(new Vt.default(2).pow(new Vt.default(64)))}static shiftRightRoundUp(i){let t=i.shrn(64);return i.mod(Cn).gt(ie)&&(t=t.add(xe)),t}static divRoundUp(i,t){return i.mod(t).eq(ie)?i.div(t):i.div(t).add(new Vt.default(1))}static subUnderflowU128(i,t){return i.lt(t)?i.sub(t).add(Ao):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)&&zt("MultiplicationOverflow","Multiplication overflow"),n}static checkMulDivFloor(i,t,e,n){e.eq(ie)&&zt("DivisionByZero","Divide by zero");let r=i.mul(t).div(e);return this.isOverflow(r,n)&&zt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulDivCeil(i,t,e,n){if(e.eq(ie))throw new Error("Divide by zero");let r=i.mul(t).add(e.sub(xe)).div(e);if(this.isOverflow(r,n))throw new Error("Multiplication div overflow");return r}static checkMulDivRound(i,t,e,n){e.eq(ie)&&zt("DivisionByZero","Divide by zero");let r=i.mul(t.add(e.shrn(1))).div(e);return this.isOverflow(r,n)&&zt("MultiplicationOverflow","Multiplication div overflow"),r}static checkMulShiftRight(i,t,e,n){let r=i.mul(t).div(new Vt.default(2).pow(new Vt.default(e)));return this.isOverflow(r,n)&&zt("MultiplicationOverflow","Multiplication shift right overflow"),r}static checkMulShiftRight64RoundUpIf(i,t,e,n){let r=i.mul(t),a=n&&r.and(Cn).gt(ie)?r.shrn(64).add(xe):r.shrn(64);return this.isOverflow(a,e)&&zt("MultiplicationOverflow","Multiplication shift right overflow"),a}static checkMulShiftLeft(i,t,e,n){let r=i.mul(t).shln(e);return this.isOverflow(r,n)&&zt("MultiplicationOverflow","Multiplication shift left overflow"),r}static checkDivRoundUpIf(i,t,e){return t.eq(ie)&&zt("DivisionByZero","Divide by zero"),e?this.divRoundUp(i,t):i.div(t)}static isOverflow(i,t){return i.gte(We.pow(new Vt.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(ie)?i:this.u128Neg(i.subn(1))}static u128Neg(i){return i.uxor(new Vt.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 Vt.default(1)))}static negFrom(i){return i.eq(ie)?i:this.u128Neg(i).add(new Vt.default(1)).or(new Vt.default(1).shln(127))}},Ii=class{static getMinIndex(i){return An+Math.abs(An)%i}static getMaxIndex(i){return Sn-Sn%i}};function Un(i){return i.data}function Co(i){return i.data!==void 0}function xo(i){return i.content!==void 0}function $n(i){let t="data"in i?Un(i):i;if(!(!t||!xo(t)||t.content.dataType!=="moveObject"))return t.content}function ko(i){return $n(i)?.type}function Ti(i){let t=Co(i)?i.data:i;return!t?.type&&"data"in i?t?.content?.dataType==="package"?"package":ko(i):t?.type}function Kn(i){return Un(i)?.previousTransaction}function pe(i){let t=$n(i)?.fields;if(t)return"fields"in t?t.fields:t}Jt.config({precision:64,rounding:Jt.ROUND_DOWN,toExpNeg:-64,toExpPos:64});var Kt=Jt,Ht=Pe(Ee()),B=Pe(Ee()),Po=14,Eo="59543866431248",Oo="184467440737095516",Io="15793534762490258745";function To(i,t,e){let n=i.toTwos(e).shln(t);return n.imaskn(e+1),n.fromTwos(e)}function j(i,t,e){let n=i.toTwos(e).shrn(t);return n.imaskn(e-t+1),n.fromTwos(e-t)}function No(i){let t;return i&1?t=new B.default("79232123823359799118286999567"):t=new B.default("79228162514264337593543950336"),i&2&&(t=j(t.mul(new B.default("79236085330515764027303304731")),96,256)),i&4&&(t=j(t.mul(new B.default("79244008939048815603706035061")),96,256)),i&8&&(t=j(t.mul(new B.default("79259858533276714757314932305")),96,256)),i&16&&(t=j(t.mul(new B.default("79291567232598584799939703904")),96,256)),i&32&&(t=j(t.mul(new B.default("79355022692464371645785046466")),96,256)),i&64&&(t=j(t.mul(new B.default("79482085999252804386437311141")),96,256)),i&128&&(t=j(t.mul(new B.default("79736823300114093921829183326")),96,256)),i&256&&(t=j(t.mul(new B.default("80248749790819932309965073892")),96,256)),i&512&&(t=j(t.mul(new B.default("81282483887344747381513967011")),96,256)),i&1024&&(t=j(t.mul(new B.default("83390072131320151908154831281")),96,256)),i&2048&&(t=j(t.mul(new B.default("87770609709833776024991924138")),96,256)),i&4096&&(t=j(t.mul(new B.default("97234110755111693312479820773")),96,256)),i&8192&&(t=j(t.mul(new B.default("119332217159966728226237229890")),96,256)),i&16384&&(t=j(t.mul(new B.default("179736315981702064433883588727")),96,256)),i&32768&&(t=j(t.mul(new B.default("407748233172238350107850275304")),96,256)),i&65536&&(t=j(t.mul(new B.default("2098478828474011932436660412517")),96,256)),i&131072&&(t=j(t.mul(new B.default("55581415166113811149459800483533")),96,256)),i&262144&&(t=j(t.mul(new B.default("38992368544603139932233054999993551")),96,256)),j(t,32,256)}function Fo(i){let t=Math.abs(i),e;return t&1?e=new B.default("18445821805675392311"):e=new B.default("18446744073709551616"),t&2&&(e=j(e.mul(new B.default("18444899583751176498")),64,256)),t&4&&(e=j(e.mul(new B.default("18443055278223354162")),64,256)),t&8&&(e=j(e.mul(new B.default("18439367220385604838")),64,256)),t&16&&(e=j(e.mul(new B.default("18431993317065449817")),64,256)),t&32&&(e=j(e.mul(new B.default("18417254355718160513")),64,256)),t&64&&(e=j(e.mul(new B.default("18387811781193591352")),64,256)),t&128&&(e=j(e.mul(new B.default("18329067761203520168")),64,256)),t&256&&(e=j(e.mul(new B.default("18212142134806087854")),64,256)),t&512&&(e=j(e.mul(new B.default("17980523815641551639")),64,256)),t&1024&&(e=j(e.mul(new B.default("17526086738831147013")),64,256)),t&2048&&(e=j(e.mul(new B.default("16651378430235024244")),64,256)),t&4096&&(e=j(e.mul(new B.default("15030750278693429944")),64,256)),t&8192&&(e=j(e.mul(new B.default("12247334978882834399")),64,256)),t&16384&&(e=j(e.mul(new B.default("8131365268884726200")),64,256)),t&32768&&(e=j(e.mul(new B.default("3584323654723342297")),64,256)),t&65536&&(e=j(e.mul(new B.default("696457651847595233")),64,256)),t&131072&&(e=j(e.mul(new B.default("26294789957452057")),64,256)),t&262144&&(e=j(e.mul(new B.default("37481735321082")),64,256)),e}var tt=class Yt{static priceToSqrtPriceX64(t,e,n){return Wt.toX64(t.mul(Kt.pow(10,n-e)).sqrt())}static sqrtPriceX64ToPrice(t,e,n){return Wt.fromX64(t).pow(2).mul(Kt.pow(10,e-n))}static tickIndexToSqrtPriceX64(t){return t>0?new B.default(No(t)):new B.default(Fo(t))}static sqrtPriceX64ToTickIndex(t){if(t.gt(new B.default(yo))||t.lt(new B.default(Mo)))throw new Error("Provided sqrtPrice is not within the supported sqrtPrice range.");let e=t.bitLength()-1,n=new B.default(e-64),r=To(n,32,128),a=new B.default("8000000000000000","hex"),s=0,l=new B.default(0),f=e>=64?t.shrn(e-63):t.shln(63-e);for(;a.gt(new B.default(0))&&s<Po;){f=f.mul(f);let S=f.shrn(127);f=f.shrn(63+S.toNumber()),l=l.add(a.mul(S)),a=a.shrn(1),s+=1}let h=l.shrn(32),b=r.add(h).mul(new B.default(Eo)),w=j(b.sub(new B.default(Oo)),64,128).toNumber(),v=j(b.add(new B.default(Io)),64,128).toNumber();return w===v?w:Yt.tickIndexToSqrtPriceX64(v).lte(t)?v:w}static tickIndexToPrice(t,e,n){return Yt.sqrtPriceX64ToPrice(Yt.tickIndexToSqrtPriceX64(t),e,n)}static priceToTickIndex(t,e,n){return Yt.sqrtPriceX64ToTickIndex(Yt.priceToSqrtPriceX64(t,e,n))}static priceToInitializeTickIndex(t,e,n,r){return Yt.getInitializeTickIndex(Yt.priceToTickIndex(t,e,n),r)}static getInitializeTickIndex(t,e){return t-t%e}static getNextInitializeTickIndex(t,e){return Yt.getInitializeTickIndex(t,e)+e}static getPrevInitializeTickIndex(t,e){return Yt.getInitializeTickIndex(t,e)-e}};function Ve(i,t,e){let n=Ht.default.min(i,t),r=Ht.default.max(i,t),a=Wt.fromX64BN(e.mul(r).mul(n)),s=r.sub(n);return!a.isZero()&&!s.isZero()?a.div(s):new Ht.default(0)}function Re(i,t,e){let n=Ht.default.min(i,t),r=Ht.default.max(i,t).sub(n);return r.isZero()?new Ht.default(0):e.shln(64).div(r)}var se=class ve{static getCoinAmountFromLiquidity(t,e,n,r,a){let s=new Kt(t.toString()),l=new Kt(e.toString()),f=new Kt(n.toString()),h=new Kt(r.toString()),b,w;return e.lt(n)?(b=Wt.toX64Decimal(s).mul(h.sub(f)).div(f.mul(h)),w=new Kt(0)):e.lt(r)?(b=Wt.toX64Decimal(s).mul(h.sub(l)).div(l.mul(h)),w=Wt.fromX64Decimal(s.mul(l.sub(f)))):(b=new Kt(0),w=Wt.fromX64Decimal(s.mul(h.sub(f)))),a?{coin_amount_a:b.ceil().toString(),coin_amount_b:w.ceil().toString()}:{coin_amount_a:b.floor().toString(),coin_amount_b:w.floor().toString()}}static estLiquidityAndCoinAmountFromOneAmounts(t,e,n,r,a,s,l){let f=tt.sqrtPriceX64ToTickIndex(l),h=tt.tickIndexToSqrtPriceX64(t),b=tt.tickIndexToSqrtPriceX64(e),w;if(f<t){if(!r)throw new Error("lower tick cannot calculate liquidity by coinB");w=Ve(h,b,n)}else if(f>e){if(r)throw new Error("upper tick cannot calculate liquidity by coinA");w=Re(b,h,n)}else r?w=Ve(l,b,n):w=Re(l,h,n);let v=ve.getCoinAmountFromLiquidity(w,l,h,b,a),S=a?P(v.coin_amount_a.toString()).mul(1+s).toString():P(v.coin_amount_a.toString()).mul(1-s).toString(),C=a?P(v.coin_amount_b.toString()).mul(1+s).toString():P(v.coin_amount_b.toString()).mul(1-s).toString();return{coin_amount_a:v.coin_amount_a,coin_amount_b:v.coin_amount_b,coin_amount_limit_a:a?Kt.ceil(S).toString():Kt.floor(S).toString(),coin_amount_limit_b:a?Kt.ceil(C).toString():Kt.floor(C).toString(),liquidity_amount:w.toString(),fix_amount_a:r}}static estimateLiquidityFromCoinAmounts(t,e,n,r){if(e>n)return zt("InvalidTick","lower tick cannot be greater than lower tick",{[Si.METHOD_NAME]:"estimateLiquidityFromCoinAmounts",[Si.REQUEST_PARAMS]:{lower_tick:e,upper_tick:n,token_amount:r}});let a=tt.sqrtPriceX64ToTickIndex(t),s=tt.tickIndexToSqrtPriceX64(e),l=tt.tickIndexToSqrtPriceX64(n);if(a<e)return Ve(s,l,new Ht.default(r.coin_amount_a)).toString();if(a>=n)return Re(l,s,new Ht.default(r.coin_amount_b)).toString();let f=Ve(t,l,new Ht.default(r.coin_amount_a)),h=Re(t,s,new Ht.default(r.coin_amount_b));return Ht.default.min(f,h).toString()}static calculateDepositRatio(t,e,n){let r=new Ht.default(1e8),{coin_amount_b:a}=ve.estLiquidityAndCoinAmountFromOneAmounts(t,e,r,!0,!0,0,n),s=tt.sqrtPriceX64ToPrice(n,0,0),l=P(r.toString()).mul(s),f=l.add(a.toString()),h=l.div(f),b=P(a.toString()).div(f);return{ratio_a:h,ratio_b:b}}static calculateAmountDepositRatio(t,e,n,r,a){let s=tt.sqrtPriceX64ToPrice(n,r,a),l=tt.sqrtPriceX64ToTickIndex(n);if(l<t)return{ratio_a:new Kt(1),ratio_b:new Kt(0),curr_price:s};if(l>e)return{ratio_a:new Kt(0),ratio_b:new Kt(1),curr_price:s};let f=new Ht.default(fe(1,r)),{coin_amount_b:h}=ve.estLiquidityAndCoinAmountFromOneAmounts(t,e,f,!0,!0,0,n),b=Ze(f.toString(),r),w=Ze(h.toString(),a),v=P(b).add(w),S=P(b).div(v),C=P(w).div(v);return{ratio_a:S,ratio_b:C,curr_price:s}}static getCoinAmountsFromRatio(t,e,n,r,a,s,l){let f=P(fe(P(n).mul(t).div(r).toString(),s)).toFixed(0),h=P(fe(P(n).mul(e).div(a).toString(),l)).toFixed(0);return{amount_a:f,amount_b:h}}static estCoinAmountsFromTotalAmount(t,e,n,r,a,s,l,f){let{ratio_a:h,ratio_b:b}=ve.calculateDepositRatio(t,e,n);return ve.getCoinAmountsFromRatio(h,b,r,a,s,l,f)}static getPositionStatus(t,e,n){return t<e?0:t<n?1:2}};function Ge(i){if(i.config===void 0)throw new Error(`package: ${i.package_id} not config in sdk SdkOptions`);return i.config}var zo=Pe(Ee());var Ji=require("@cetusprotocol/sui-clmm-sdk");var Ae=require("@mysten/sui/transactions"),ae=we(require("bn.js")),Hn=require("@cetusprotocol/aggregator-sdk");var zn=require("@mysten/sui/utils"),Wn=we(require("decimal.js"));var $t=we(require("bn.js")),Je=we(require("decimal.js"));var Ni=we(require("bn.js")),Fi=we(require("decimal.js")),Ye=(i,t,e)=>{if(t==="min"){if(i===Ii.getMinIndex(e))return!0}else if(i===Ii.getMaxIndex(e))return!0;return!1};function Bo(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 Zn(i,t,e,n,r){let a=new Ni.default(10).pow(new Ni.default(n)),{coin_amount_b:s}=se.estLiquidityAndCoinAmountFromOneAmounts(i,t,a,!0,!0,0,e),l=tt.sqrtPriceX64ToPrice(e,n,r),f=P(a.toString()).mul(l).div(new Fi.default(10).pow(n)).mul(new Fi.default(10).pow(r)),h=f.add(s.toString()),b=f.div(h),w=P(s.toString()).div(h);return{ratioA:b,ratioB:w}}function Se(i,t,e,n,r,a,s){let l=P(fe(P(e).mul(i).div(n).toString(),a)).toFixed(0),f=P(fe(P(e).mul(t).div(r).toString(),s)).toFixed(0);return{amountA:l,amountB:f}}function Bi(i,t,e,n,r,a,s,l){let{ratioA:f,ratioB:h}=Zn(i,t,e,s,l);return Se(f,h,n,r,a,s,l)}var _e=10n;function Qe(i){let{fields:t,type:e}=i,{liquidity_range:n,pool_id:r,wrapped_position:a}=t.clmm_vault.fields,s=a.fields,l={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:Y(s.coin_type_a.fields.name,!1),coin_type_b:Y(s.coin_type_b.fields.name,!1),description:s.description,id:s.id.id,index:s.index,liquidity:s.liquidity,name:s.name,pool:s.pool,tick_lower_index:Ie(BigInt(s.tick_lower_index.fields.bits)),tick_upper_index:Ie(BigInt(s.tick_upper_index.fields.bits)),url:s.url}},{balances:f}=t.buffer_assets.fields,h=f.fields.contents.map(w=>{let{key:v,value:S}=w.fields;return{coin_type:Y(v.fields.name,!1),value:S}});return{id:t.id.id,is_pause:t.is_pause,clmm_vault:l,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:re(t.quote_type.fields.name).full_address,lp_token_type:re(e).type_arguments[0],balances:h,protocol_fee_rate:t.protocol_fee_rate}}async function Do(i,t=!0){i.getData().commands.forEach((e,n)=>{})}function Di(i,t){let e=P(i).div(t).toString(),n=P(t).div(i).toString();return{quote_per_base:e,base_per_quote:n}}function Xn(i,t,e,n){let r=10n**(_e+n-e),a=10n**(_e+e-n),s=Wt.checkMulDivFloor(new $t.default(i.toString()),new $t.default(r.toString()),new $t.default(t.toString()),64),l=Wt.checkMulDivFloor(new $t.default(t.toString()),new $t.default(a.toString()),new $t.default(i.toString()),64);return{primitive_base_price:BigInt(s.toString()),primitive_quote_price:BigInt(l.toString())}}function ti(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:s}]of Object.entries(i)){let{primitive_quote_price:l}=Xn(BigInt(e.oracle_price),BigInt(a.oracle_price),BigInt(e.coin_decimals),BigInt(a.coin_decimals)),f=Wt.checkMulDivFloor(new $t.default(l.toString()),new $t.default(s),new $t.default((BigInt(10)**_e).toString()),64);n=n.add(f)}return n.toString()}async function qi(i,t,e,n,r=!1){let{clmm_vault:a,quote_type:s}=t,{wrapped_position:l}=a,{tick_lower_index:f,tick_upper_index:h,liquidity:b}=l,{current_sqrt_price:w,coin_type_a:v,coin_type_b:S}=e,C=[...n],x=s&&Y(t.quote_type,!1),N=tt.tickIndexToSqrtPriceX64(f),E=tt.tickIndexToSqrtPriceX64(h),{coin_amount_a:q,coin_amount_b:k}=se.getCoinAmountFromLiquidity(new $t.default(b),new $t.default(w),new $t.default(N),new $t.default(E),!1);C.push({coin_type:v,value:q.toString()}),C.push({coin_type:S,value:k.toString()});let V={};C.forEach(Z=>{let z=Y(Z.coin_type,!1),Q=P(Z.value),jt=V[z]||0;V[z]=Q.add(jt).toString()});let qt=Object.entries(V).filter(([Z,z])=>P(z).gt(0)).map(([Z])=>Z);if(x&&!qt.includes(x)&&qt.push(x),qt.length===0)return"0";let K=await i.sdk.PythPrice.getLatestPrice(qt,r),Lt={};return qt.forEach(Z=>{let z=K[Z];if(z)Lt[Z]={price:z,value:V[Z]||"0"};else throw Error(`find ${Z} price fail `)}),ti(Lt,x).toString()}function Vi(i,t,e){return P(i).eq(0)?t:P(i).mul(t).div(e).toFixed(0,Je.default.ROUND_HALF_UP)}function qo(i,t,e){return P(i).eq(0)?"0":P(i).mul(t).div(e).toFixed(0,Je.default.ROUND_HALF_UP)}function be(i,t,e){return P(i).eq(0)?"0":P(t).mul(e).div(i).toFixed(0,Je.default.ROUND_HALF_UP)}function Te(i,t){let{balances:e,lp_token_treasury:n}=t,r={};return e.forEach(a=>{let s=be(n,i,a.value),l={coin_type:a.coin_type,value:s};r[l.coin_type]=l}),r}function Ri(i,t,e,n){let{tick_lower_index:r,tick_upper_index:a,coin_type_a:s,coin_type_b:l,liquidity:f}=e.clmm_vault.wrapped_position,h=be(e.lp_token_treasury,t,f),b=tt.tickIndexToSqrtPriceX64(r),w=tt.tickIndexToSqrtPriceX64(a),v=se.getCoinAmountFromLiquidity(new $t.default(h),new $t.default(n.current_sqrt_price),b,w,!0),S=v.coin_amount_a.toString(),C=v.coin_amount_b.toString(),x=Te(t,e),N=P(S).add(x[s]?.value||"0").toFixed(0),E=P(C).add(x[l]?.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:h,tick_lower_index:r,tick_upper_index:a,amount_a:N,amount_b:E,coin_type_a:s,coin_type_b:l}}function ei(i,t,e){let n=[];return t.forEach(r=>{P(r.value).gt(0)&&n.push(r)}),e.forEach(r=>{P(r.value).gt(0)&&n.push(r)}),i.balances.forEach(r=>{P(r.value).gt(0)&&n.push(r)}),n}function Li(i,t,e){let{coin_type_a:n,coin_type_b:r}=i.clmm_vault.wrapped_position,a=ei(i,t,e),s=new Set;return a.forEach(l=>s.add(l.coin_type)),s.add(n),s.add(r),Array.from(s)}function ji(i,t){if(!_e)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(t<0n){let e=10n**(_e- -t);return i*e}return i/10n**(t+_e)}function Ui(i){return`0x${Buffer.from(i).toString("hex")}`}function Vo(i,t,e,n,r){let a="0",s="0";return Ye(i,"min",Number(e))?a="0":a=tt.tickIndexToPrice(Number(i),n,r).toString(),Ye(t,"max",Number(e))?s="\u221E":s=tt.tickIndexToPrice(Number(t),n,r).toString(),{minPrice:a,maxPrice:s}}function ii(i){let t=pe(i),e=Ti(i),n=re(e),r=t.position.fields,a={id:r.id.id,pool_id:r.pool,index:r.index,liquidity:r.liquidity,tick_lower_index:Ie(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:Ie(BigInt(r.tick_upper_index.fields.bits)),coin_type_a:Y(r.coin_type_a.fields.name,!1),coin_type_b:Y(r.coin_type_b.fields.name,!1),name:r.name,description:r.description,url:r.url},s=t.global_vesting_periods.map(f=>({period:f.fields.period,release_time:f.fields.release_time,redeemed_amount:f.fields.redeemed_amount,cetus_amount:f.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:Y(t.coin_a.fields.name,!1),coin_type_b:Y(t.coin_b.fields.name,!1),cetus_amount:t.cetus_amount,start_time:t.start_time,global_vesting_periods:s,vest_infos:{id:t.vester_infos.fields.id,size:t.vester_infos.fields.size}}}function $i(i){let t=pe(i),e=Ti(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 Ne=class{_sdk;constructor(t){this._sdk=t}get sdk(){return this._sdk}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),s=(await this._sdk.FullClient.getBalance({owner:t,coinType:n.lp_token_type})).totalBalance;return Ri(t,s,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}`,s=this._sdk.getCache(a);if(s)return s;let{lp_token_type:l}=n,{rewarder_infos:f,id:h,coin_type_a:b,coin_type_b:w}=r,v=new Ae.Transaction;this.buildCollectRewardPayload({reward_coin_types:[...f.map(q=>q.coin_type)],lp_token_type:l,pool_id:t,clmm_pool_id:h,coin_type_a:b,coin_type_b:w},v),this.buildCollectFeePayload({lp_token_type:l,pool_id:t,clmm_pool_id:h,coin_type_a:b,coin_type_b:w},v);let S=await this._sdk.FullClient.sendSimulationTransaction(v,(0,zn.normalizeSuiAddress)("0x0")),C=`${e}::pool::FeeClaimedEvent`,x=`${e}::pool::RewardClaimedEvent`,N=[],E=[];return S?.events.forEach(q=>{let{parsedJson:k,type:V}=q;V===C&&(N.push({coin_type:Y(b,!1),value:k.amount_a}),N.push({coin_type:Y(w,!1),value:k.amount_b})),V===x&&E.push({coin_type:Y(k.reward_type.name,!1),value:k.amount})}),this._sdk.updateCache(a,{feeList:N,rewarderList:E},10*1e3),{feeList:N,rewarderList:E}}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),s=a.data.map(l=>l.name.value);return s.length>0&&((await r.batchGetObjects(s,{showContent:!0})).forEach(f=>{let h=Qe(f.data.content);this._sdk.updateCache(`getPool_${h.id}`,h),e.data.push(h)}),e.next_cursor=a.next_cursor,e.has_next_page=a.has_next_page),e}async getPool(t,e=!0){let n=`getPool_${t}`,r=this._sdk.getCache(n,e);if(r)return r;let a=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),s=Qe(a.data.content);return this._sdk.updateCache(n,s),s}buildCollectRewardPayload(t,e){let{coin_type_a:n,coin_type_b:r,pool_id:a,clmm_pool_id:s,lp_token_type:l,reward_coin_types:f}=t,{published_at:h,configs:b,clmm_configs:w}=this._sdk.sdkOptions.vaults;return e=e||new Ae.Transaction,f.forEach(v=>{e.moveCall({target:`${h}::pool::collect_reward`,typeArguments:[n,r,l,v],arguments:[e.object(a),e.object(b.global_config_id),e.object(w.global_config_id),e.object(s),e.object(w.global_vault_id),e.object(ee)]})}),e}buildCollectFeePayload(t,e){let{coin_type_a:n,coin_type_b:r,pool_id:a,clmm_pool_id:s,lp_token_type:l}=t,{published_at:f,configs:h,clmm_configs:b}=this._sdk.sdkOptions.vaults;return e=e||new Ae.Transaction,e.moveCall({target:`${f}::pool::collect_fee`,typeArguments:[n,r,l],arguments:[e.object(a),e.object(h.global_config_id),e.object(b.global_config_id),e.object(s)]}),e}async buildDepositPayload(t,e){let{pool_id:n,amount_a:r,amount_b:a,return_lp_coin:s}=t,{pool:l,clmmPool:f}=await this.getVaultAndPool(n,!0),{rewarderList:h,feeList:b}=await this.getVaultsPositionRewarderAndFee(n),w=Li(l,h,b),{lp_token_type:v}=l,{rewarder_infos:S,id:C,coin_type_a:x,coin_type_b:N}=f,E=h.length>0?h.filter(z=>P(z.value.toString()).gt(0)).map(z=>Y(z.coin_type,!1)):S.map(z=>Y(z.coin_type,!1)),{published_at:q,configs:k,clmm_configs:V}=this._sdk.sdkOptions.vaults;e=e||new Ae.Transaction,e=this.buildCollectRewardPayload({reward_coin_types:E,lp_token_type:v,pool_id:n,clmm_pool_id:C,coin_type_a:x,coin_type_b:N},e),e=this.buildCollectFeePayload({lp_token_type:v,pool_id:n,clmm_pool_id:C,coin_type_a:x,coin_type_b:N},e),e=await this._sdk.PythPrice.buildUpdatePythPricePayload(w,e),e.moveCall({target:`${q}::pool::calculate_aum`,typeArguments:[x,N,v],arguments:[e.object(n),e.object(k.global_config_id),e.object(k.pyth_oracle_id),e.object(V.global_config_id),e.object(C),e.object(ee)]});let qt=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress,x),K=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress,N),Lt=oe.buildCoinForAmount(e,qt,BigInt(r),x,!1,!0),X=oe.buildCoinForAmount(e,K,BigInt(a),N,!1,!0),Z=e.moveCall({target:`${q}::pool::${s?"deposit_for":"deposit"}`,typeArguments:[x,N,v],arguments:[e.object(n),e.object(k.global_config_id),e.object(k.pyth_oracle_id),e.object(V.global_config_id),e.object(C),Lt.target_coin,X.target_coin,e.object(ee)]});return s?Z:void 0}async buildWithdrawPayload(t,e){let{pool_id:n,burn_lp_amount:r,mode:a,slippage:s,partner:l,extra_burn:f}=t,{pool:h,clmmPool:b}=await this.getVaultAndPool(n,!0),{published_at:w,configs:v,clmm_configs:S}=this._sdk.sdkOptions.vaults;e=e||new Ae.Transaction;let{lp_token_type:C,clmm_vault:x,lp_token_treasury:N}=h,{rewarder_infos:E,id:q,coin_type_a:k,coin_type_b:V,liquidity:qt}=b,K=E.map(et=>Y(et.coin_type,!1));e=this.buildCollectRewardPayload({reward_coin_types:K,lp_token_type:C,pool_id:n,clmm_pool_id:q,coin_type_a:k,coin_type_b:V},e),e=this.buildCollectFeePayload({lp_token_type:C,pool_id:n,clmm_pool_id:q,coin_type_a:k,coin_type_b:V},e);let Lt=await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress),X,Z=f?P(f.burn_lp_amount).add(P(r)).toFixed(0):P(r).toFixed(0),z=P(r).isZero();if(z&&!f)throw new Error("burn_lp_amount or extra_burn_lp_coin is zero");z?X=f.lp_burn_coin:(X=oe.buildCoinForAmount(e,Lt,BigInt(r),C,!1,!0).target_coin,f&&e.mergeCoins(X,[f.lp_burn_coin]));let[Q,jt,$]=e.moveCall({target:`${w}::pool::withdraw`,typeArguments:[k,V,C],arguments:[e.object(n),e.object(v.global_config_id),e.object(S.global_config_id),e.object(q),X,e.object(ee)]});if(this.buildWithdrawBufferReward({reward_coin_types:K.filter(et=>![Y(k,!1),Y(V,!1)].includes(et)),pool_id:n,withdraw_cert:$,lp_token_type:C},e,Lt),e.moveCall({target:`${w}::pool::destory_withdraw_cert`,typeArguments:[C],arguments:[e.object(n),e.object(v.global_config_id),$]}),a!=="FixedOneSide"){if(s===void 0)throw Error("the slippage is undefined");let et=a==="OnlyCoinA",o=et?jt:Q,u=be(N,Z,qt.toString());await this.handleWithSwap(e,o,k,V,Z,n,et,s,l,[{poolID:q,ticklower:x.wrapped_position.tick_lower_index,tickUpper:x.wrapped_position.tick_upper_index,deltaLiquidity:Number(u)}]),e.transferObjects([et?Q:jt],this._sdk.senderAddress)}else e.transferObjects([Q,jt],this._sdk.senderAddress);return e}async handleWithSwap(t,e,n,r,a,s,l,f,h,b){let{receive_amount_a:w,receive_amount_b:v}=await this.preCalculateWithdrawAmount({pool_id:s,mode:"FixedOneSide",burn_lp_amount:a}),S=l?r:n,C=l?n:r,x=l?v:w,N={from:S,target:C,amount:new ae.default(x),byAmountIn:!0,depth:3,splitAlgorithm:void 0,splitFactor:void 0,splitCount:void 0,providers:this._sdk.sdkOptions.providers,liquidityChanges:b},E=await this._sdk.AggregatorClient.findRouters(N);if(!E)throw Error("not find Router");if(E.error!==void 0)throw Error(`find Router error : ${E.error}`);let q={router:E,inputCoin:e,slippage:f,txb:t,partner:h},k=await this._sdk.AggregatorClient.fixableRouterSwapV3(q);t.transferObjects([k],t.pure.address(this._sdk.getVerifySenderAddress()))}buildWithdrawBufferReward({reward_coin_types:t,pool_id:e,withdraw_cert:n,lp_token_type:r},a,s){let{published_at:l,configs:f}=this._sdk.sdkOptions.vaults;t.forEach(h=>{let b=a.moveCall({target:`${l}::pool::withdraw_buffer_reward`,typeArguments:[r,h],arguments:[a.object(e),a.object(f.global_config_id),n]}),w=oe.getCoinAssets(h,s),v=oe.selectCoinAssetGreaterThanOrEqual(w,BigInt(0));if(v.selected_coins.length>0&&!oe.isSuiCoin(h))a.mergeCoins(v.selected_coins[0].coin_object_id,[b]);else{let S=oe.buildCoinForAmount(a,s,BigInt(0),h,!1,!1);a.mergeCoins(S.target_coin,[b]),a.transferObjects([S.target_coin],this._sdk.senderAddress)}})}async preCalculateDepositValue(t,e){let{amount_usd:n,pool_id:r,mode:a,uuid:s}=t,{pool:l,clmmPool:f}=await this.getVaultAndPool(r,!1),{current_sqrt_price:h}=f,{tick_lower_index:b,tick_upper_index:w,coin_type_a:v,coin_type_b:S}=l.clmm_vault.wrapped_position,C="0",x="0",N=await this._sdk.PythPrice.getLatestPrice([v,S],!0),E=N[v],q=N[S];if(!E||!q)throw new Error("get coin price failed");switch(a){case"FixedOneSide":{let{amountA:k,amountB:V}=Bi(b,w,new ae.default(h),n,E.price,q.price,E.coin_decimals,q.coin_decimals);C=k.toString(),x=V.toString();break}case"FlexibleBoth":{let{amountA:k,amountB:V}=Se(P(.5),P(.5),n,E.price,q.price,E.coin_decimals,q.coin_decimals);C=k.toString(),x=V.toString();break}case"OnlyCoinA":{let{amountA:k,amountB:V}=Se(P(1),P(0),n,E.price,q.price,E.coin_decimals,q.coin_decimals);C=k.toString(),x=V.toString();break}case"OnlyCoinB":{let{amountA:k,amountB:V}=Se(P(0),P(1),n,E.price,q.price,E.coin_decimals,q.coin_decimals);C=k.toString(),x=V.toString();break}default:throw new Error(`Unsupported deposit mode: ${a}`)}return e&&this.calculateDepositLpAmountBoth(l,f,C,x).then(k=>{e.onSuccess(k,s)}).catch(k=>{e.onError(k,s)}),{deposit_amount_a:C,deposit_amount_b:x,mode:a}}async preCalculateDepositAmount(t,e){let{mode:n,pool_id:r,uuid:a}=t,s="0",l="0",{pool:f,clmmPool:h}=await this.getVaultAndPool(r,!1);switch(n){case"FixedOneSide":{let{fixed_amount:b,fixed_coin_a:w}=t,{other_amount:v}=this.calculateDepositOtherSide(f,h,b,w,e,a);w?(s=b,l=v):(l=b,s=v);break}case"FlexibleBoth":{let{coin_amount_a:b,coin_amount_b:w}=t;s=b,l=w,this.calculateDepositLpAmountBoth(f,h,b,w).then(v=>{e.onSuccess(v,a)}).catch(v=>{e.onError(v,a)});break}case"OnlyCoinA":{s=t.coin_amount_a,this.calculateDepositLpAmountBoth(f,h,s,"0").then(b=>{e.onSuccess(b,a)}).catch(b=>{e.onError(b,a)});break}case"OnlyCoinB":{l=t.coin_amount_b,this.calculateDepositLpAmountBoth(f,h,"0",l).then(b=>{e.onSuccess(b,a)}).catch(b=>{e.onError(b,a)});break}default:throw new Error(`Unsupported deposit mode: ${n}`)}return{deposit_amount_a:s,deposit_amount_b:l,mode:n}}async getVaultAndPool(t,e=!1){let n=await this.getPool(t,e);if(n===void 0)throw new Error("get vaults pool failed");let r=await this._sdk.CetusClmmSDK.Pool.getPool(n.clmm_vault.clmm_pool_id,e);if(r===void 0)throw new Error("get vaults clmmPool failed");return{clmmPool:r,pool:n}}calculateDepositOtherSide(t,e,n,r,a,s){let{clmm_vault:l}=t,{current_sqrt_price:f}=e,h=l.wrapped_position.tick_lower_index,b=l.wrapped_position.tick_upper_index,w=se.estLiquidityAndCoinAmountFromOneAmounts(h,b,new ae.default(n),r,!0,1,new ae.default(f)),{coin_amount_a:v,coin_amount_b:S}=w;return this.calculateDepositLpAmountBoth(t,e,v.toString(),S.toString()).then(C=>{a.onSuccess(C,s)}).catch(C=>{a.onError(C,s)}),{other_amount:r?S.toString():v.toString()}}async calculateDepositLpAmountBoth(t,e,n,r){let{lp_token_treasury:a,hard_cap:s}=t,l=Y(e.coin_type_a,!1),f=Y(e.coin_type_b,!1),{rewarderList:h,feeList:b}=await this.getVaultsPositionRewarderAndFee(t.id),w=ei(t,b,h),v=await qi(this,t,e,w,!0),S=await this._sdk.PythPrice.getLatestPrice([l,f],!0),C=S[l],x=S[f];if(!C)throw Error(`not find ${l} price`);if(!x)throw Error(`not find ${f} price`);let N={};N[l]={price:C,value:n.toString()},N[f]={price:x,value:r.toString()};let E=ti(N,t.quote_type);return Vi(a,E,v)}async preCalculateWithdrawAmount(t){let{mode:e,pool_id:n}=t,r="0",a="0",s="0",l="0",f,{pool:h,clmmPool:b}=await this.getVaultAndPool(n,!1);switch(e){case"FixedOneSide":let w=await this.calculateWithdrawOtherSide(h,b,t.burn_lp_amount);s=w.burn_lp_amount,r=w.receive_amount_a,a=w.receive_amount_b,l=w.remove_liquidity;break;case"OnlyCoinA":{let v=await this.calculateWithdrawOnlyCoin(h,b,t.burn_lp_amount,!0);s=v.burn_lp_amount,r=v.receive_amount_a,a=v.receive_amount_b,l=v.remove_liquidity,f=v.swap;break}case"OnlyCoinB":{let v=await this.calculateWithdrawOnlyCoin(h,b,t.burn_lp_amount,!1);s=v.burn_lp_amount,r=v.receive_amount_a,a=v.receive_amount_b,l=v.remove_liquidity,f=v.swap;break}default:throw new Error(`Unsupported withdraw mode: ${e}`)}return{remove_liquidity:l,burn_lp_amount:s,receive_amount_a:r,receive_amount_b:a,mode:e,swap:f}}async calculateWithdrawOtherSide(t,e,n){let{clmm_vault:r,lp_token_treasury:a}=t,{current_sqrt_price:s}=e,{coin_type_a:l,coin_type_b:f}=t.clmm_vault.wrapped_position,h=r.wrapped_position.tick_lower_index,b=r.wrapped_position.tick_upper_index,w=r.wrapped_position.liquidity,v=tt.tickIndexToSqrtPriceX64(h),S=tt.tickIndexToSqrtPriceX64(b),C=be(a,n,w),{coin_amount_a:x,coin_amount_b:N}=se.getCoinAmountFromLiquidity(new ae.default(C),new ae.default(s),v,S,!1),E=Te(n,t),q=P(x.toString()).add(E[l]?.value||"0").toFixed(0),k=P(N.toString()).add(E[f]?.value||"0").toFixed(0);return{receive_amount_a:q,receive_amount_b:k,burn_lp_amount:n,mode:"FixedOneSide",remove_liquidity:C}}async calculateWithdrawOnlyCoin(t,e,n,r){let{totalReceiveAmount:a,swapAmountIn:s,swapAmountOut:l,removeLiquidity: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,remove_liquidity:f,swap:{swap_amount_in:s,swap_amount_out:l},mode:"FixedOneSide"}}async calculateWithdrawOnlyCoinByLpAmount(t,e,n,r){let{clmm_vault:a,lp_token_treasury:s}=t,{current_sqrt_price:l}=e,{coin_type_a:f,coin_type_b:h}=a.wrapped_position,b=a.wrapped_position.tick_lower_index,w=a.wrapped_position.tick_upper_index,v=a.wrapped_position.liquidity,S=tt.tickIndexToSqrtPriceX64(b),C=tt.tickIndexToSqrtPriceX64(w),x=be(s,r,v),{coin_amount_a:N,coin_amount_b:E}=se.getCoinAmountFromLiquidity(new ae.default(x),new ae.default(l),S,C,!1),q=await this._sdk.PythPrice.getLatestPrice([f,h],!0),k=q[f],V=q[h];if(!k)throw Error(`not find ${f} price`);if(!V)throw Error(`not find ${h} price`);let qt=n?V:k,K=n?k:V,{quote_per_base:Lt}=Di(qt.price,K.price),X=Te(r,t),Z=P(N.toString()).add(X[f]?.value||"0").toFixed(0),z=P(E.toString()).add(X[h]?.value||"0").toFixed(0),Q=n?Z:z,jt=n?z:Z,$=fe(P(Ze(jt,n?V.coin_decimals:k.coin_decimals)).mul(Lt).toString(),n?k.coin_decimals:V.coin_decimals).toString(),et=P(Q).add($).toFixed(0);return{burn_lp_amount:r,removeLiquidity:x,is_coin_a:n,originAmount:Q,swapAmountIn:jt,swapAmountOut:P($).toFixed(0,Wn.default.ROUND_DOWN),totalReceiveAmount:et}}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=Kn(n);(await this._sdk.FullClient.queryEventsByPage({Transaction:r})).data.forEach(b=>{let w=b.parsedJson;if(b.type)switch((0,Hn.extractStructTagFromType)(b.type).full_address){case`${e}::pool::InitEvent`:t.registry_id=w.registry_id;break;case`${e}::pyth_oracle::InitEvent`:t.pyth_oracle_id=w.pyth_oracle_id;break;case`${e}::config::InitConfigEvent`:t.global_config_id=w.global_config;break;default:break}});let s=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),l=pe(s);t.pools_handle=l.pools.fields.id.id;let f=await this._sdk.FullClient.getObject({id:t.pyth_oracle_id,options:{showContent:!0}}),h=pe(f);return t.oracle_infos_handle=h.oracle_infos.fields.id.id,t.prices_handle=h.prices.fields.id.id,this._sdk.sdkOptions.vaults.configs=t,this._sdk.sdkOptions}};var Ce=require("@pythnetwork/pyth-sui-js"),Yi=require("@mysten/sui/bcs");var Ki={env:"mainnet",fullRpcUrl:"https://fullnode.mainnet.sui.io",vaults:{package_id:"0xc4ebf35be1478318d78c324342854dd2735a036139373a9d41a1aa3a46a01d05",published_at:"0xa9055ca2c63f5d746fed832f2171b20303fb464d1629b394dd0132122abbe158",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"},pyth_configs:{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"}]}}},Zi={"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}};function Xi(i){return i&&(Ki.fullRpcUrl=i),new ce(Ki)}var Hi={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"},pyth_configs:{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"}},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"}]}}},zi={};function Wi(i){return i&&(Hi.fullRpcUrl=i),new ce(Hi)}var Gn=(e=>(e.mainnet="mainnet",e.testnet="testnet",e))(Gn||{});function Ro(i){let{env:t,fullNodeUrl:e}=i;return t==="mainnet"?Xi(e):Wi(e)}var Gi=["CETUS","TURBOS","STEAMM","SPRINGSUI","HAEDAL","FLOWX","AFTERMATH","ALPHAFI","BLUEFIN","METASTABLE","VOLO","SCALLOP","KRIYA","FLOWXV3","DEEPBOOKV3","AFSUI","BLUEMOVE","KRIYAV3","HAEDALPMM","OBRIC"];function Yn(i){try{let{request_time:t,error:e,request_params:n,request_url:r,action:a}=i;if(window?.gtag){let s=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 Lo=16*1024,Fe=class{_sdk;connection;suiPythClient;hasChangeConnection=!1;errorList=[];constructor(t){let{pyth_configs:e}=t.sdkOptions.vaults,{pyth_state_id:n,wormhole_state_id:r}=e;this._sdk=t,this.hasChangeConnection=!1;let{primary:a}=t.sdkOptions.vaults.pyth_configs.hermes_service_urls;if(a.length===0)throw new Error("primary url is empty");this.connection=new Ce.SuiPriceServiceConnection(a),this.suiPythClient=new Ce.SuiPythClient(this._sdk.FullClient,n,r)}get sdk(){return this._sdk}recordError(t,e,n){let{secondary:r,primary:a}=this._sdk.sdkOptions.vaults.pyth_configs.hermes_service_urls,s={error:t,request_params:e,request_url:this.hasChangeConnection&&r?r:a,action:n,request_time:Date.now()};Yn(s),this.errorList.push(s)}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(l=>{let f=this._sdk.getCache(`getLatestPrice_${l}`);f&&this.priceCheck(f,60)?n[l]=f:r.push(l)}):r=[...t],r.length===0)return n;let a=await this.getFeedInfoList(r);return(await this.getLatestPriceFeeds(a.map(l=>l.price_feed_id)))?.forEach((l,f)=>{let h=l.getPriceUnchecked();if(h){let{price:b,expo:w}=h,v=P(b).mul(P(10).pow(P(w))).toString(),S=a[f],C={coin_type:S.coin_type,price:v,coin_decimals:S.coin_decimals,oracle_price:0n,last_update_time:h.publishTime};C.oracle_price=ji(BigInt(b),BigInt(w)),n[r[f]]=C,this._sdk.updateCache(`getLatestPrice_${C.coin_type}`,C)}}),n}async getPriceFeedsUpdateData(t){try{return await this.connection.getPriceFeedsUpdateData(t)}catch(e){this.recordError(e,t,"getPriceFeedsUpdateData");let{secondary:n}=this._sdk.sdkOptions.vaults.pyth_configs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Ce.SuiPriceServiceConnection(n);try{return await this.connection.getPriceFeedsUpdateData(t)}catch(r){this.recordError(r,t,"getPriceFeedsUpdateData")}}}}async getLatestPriceFeeds(t){try{return await this.connection.getLatestPriceFeeds(t)}catch(e){this.recordError(e,t,"getLatestPriceFeeds");let{secondary:n}=this._sdk.sdkOptions.vaults.pyth_configs.hermes_service_urls;if(n){this.hasChangeConnection=!0,this.connection=new Ce.SuiPriceServiceConnection(n);try{return await this.connection.getLatestPriceFeeds(t)}catch(r){this.recordError(r,t,"getLatestPriceFeeds")}}}}async buildUpdatePythPricePayload(t,e){let{pyth_configs:n,published_at:r,configs:a}=this._sdk.sdkOptions.vaults,{pyth_state_id:s,pyth_published_at:l,pyth_package_id:f}=n,{global_config_id:h,pyth_oracle_id:b}=a,w=(await this.getFeedInfoList(t)).map(E=>E.price_feed_id);if(t.length!==w.length)throw Error("find feed id fail");let v=await this.getPriceFeedsUpdateData(w);if(!v)throw new Error("get price update data fail");if(v.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");let S=this.suiPythClient.extractVaaBytesFromAccumulatorMessage(v[0]),C=await this.suiPythClient.verifyVaas([S],e),[x]=e.moveCall({target:`${l}::pyth::create_authenticated_price_infos_using_accumulator`,typeArguments:[],arguments:[e.object(s),e.pure(Yi.bcs.vector(Yi.bcs.U8).serialize(Array.from(v[0]),{maxSize:Lo}).toBytes()),C[0],e.object(ee)]}),N=0;for(let E of w){let q=await this.suiPythClient.getPriceFeedObjectId(E);if(!q)throw new Error(`Price feed ${E} not found, please create it first`);[x]=e.moveCall({target:`${r}::pyth_oracle::update_price`,typeArguments:[t[N]],arguments:[e.object(b),e.object(h),e.object(s),x,e.object(q),e.object(ee)]}),N+=1}return e.moveCall({target:`${l}::hot_potato_vector::destroy`,arguments:[x],typeArguments:[`${f}::price_info::PriceInfo`]}),e}getFeedInfoByJson(t){let{env:e}=this._sdk.sdkOptions,n=Y(t,!1);return e==="mainnet"?Zi[n]:zi[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{configs:s}=this._sdk.sdkOptions.vaults,l=await this._sdk.FullClient.getDynamicFieldObject({parentId:s.oracle_infos_handle,name:{type:"0x1::type_name::TypeName",value:Y(t,!0)}}),{fields:f}=l.data.content.fields.value,h={coin_type:t,price_feed_id:Ui(f.price_feed_id),coin_decimals:f.coin_decimals};return this._sdk.updateCache(n,h),h}};var Jn=require("@mysten/sui/transactions");var Be=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!pe(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,s={clmm_vester_id:a.clmm_vester_id,lp_coin_type:Y(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},l=`${s.vault_id}-VestCreateEvent`;return this._sdk.updateCache(l,s),s})}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 s of t){let l=await this.getVaultVestEvent(s);n.push(l.vault_vester_id)}let r=[];return(await this._sdk.FullClient.batchGetObjects(n,{showContent:!0,showType:!0})).forEach(s=>{try{let l=ii(s);r.push(l);let f=`${l.id}-VaultsVestInfo`;this._sdk.updateCache(f,l)}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 s=await this._sdk.FullClient.getObject({id:n,options:{showContent:!0,showType:!0}}),l=ii(s);return this._sdk.updateCache(r,l),l}catch(s){throw new Error(`getVaultsVestInfo error: ${s}`)}}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}=Ge(e),r=n.find(a=>a.vault_id===t);if(!r){let a=`${t}-VestCreateEvent`,s=this._sdk.getCache(a,!1);s?r=s:(r=(await this.getVestCreateEventList()).find(f=>f.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 s=$i(a);r.push(s)}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}=Ge(n),{versioned_id:s,clmm_vest_id:l}=Ge(r);e=e||new Jn.Transaction;for(let f of t){let{vault_id:h,vesting_nft_id:b,period:w,coin_type_a:v,coin_type_b:S}=f,C=await this.getVaultVestEvent(h);e.moveCall({package:n.published_at,module:"hae_vester",function:"redeem_coin",arguments:[e.object(a),e.object(C.vault_vester_id),e.object(b),e.object(s),e.object(l),e.object(C.pool_id),e.pure.u16(w),e.object(ee)],typeArguments:[v,S]})}return e}};var ce=class{_cache={};_sdkOptions;_senderAddress="";_vaults;_pythPrice;_aggregatorClient;_vest;_cetusClmmSDK;constructor(t){(!t.providers||t.providers.length===0)&&(t.providers=Gi),this._sdkOptions=t,this._cetusClmmSDK=t.env==="testnet"?Ji.CetusClmmSDK.createSDK({env:"testnet",full_rpc_url:t.fullRpcUrl}):Ji.CetusClmmSDK.createSDK({env:"mainnet",full_rpc_url:t.fullRpcUrl}),this._vaults=new Ne(this),this._pythPrice=new Fe(this);let{primary:e,secondary:n}=t.vaults.pyth_configs.hermes_service_urls,r=[e,n].filter(Boolean);this._aggregatorClient=new De.AggregatorClient({endpoint:t.aggregatorUrl,signer:(0,ni.normalizeSuiAddress)("0x0"),client:new Qn.SuiClient({url:t.fullRpcUrl}),env:t.env==="testnet"?De.Env.Testnet:De.Env.Mainnet,pythUrls:r}),this._vest=new Be(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 PythPrice(){return this._pythPrice}get FullClient(){return this._cetusClmmSDK.FullClient}get AggregatorClient(){return this._aggregatorClient}get CetusClmmSDK(){return this._cetusClmmSDK}get Vest(){return this._vest}getVerifySenderAddress(){if(this.senderAddress.length===0||!(0,ni.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=Pn){this.CetusClmmSDK.updateCache(t,e,n)}getCache(t,e=!1){return this.CetusClmmSDK.getCache(t,e)}};var jo=ce;0&&(module.exports={PythPriceModule,SdkEnv,VaultsModule,VestModule,VolatileVaultsSDK,buildPoolData,buildVaultsBalance,calculateAum,calculateDepositRatioFixTokenA,calculateTotalAumBasedOnQuote,checkIsMinOrMaxIndex,convertU64BytesToDecimal,defaultProvider,estCoinAmountsFromTotalAmount,feed_map_mainnet,feed_map_testnet,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:
|