@cetusprotocol/sui-clmm-sdk 1.4.0 → 1.4.2
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/README.md +5 -1
- package/dist/index.d.ts +318 -84
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +15 -6
- package/dist/index.d.mts +0 -2438
- package/dist/index.mjs +0 -13
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
var mr=Object.create;var Un=Object.defineProperty;var gr=Object.getOwnPropertyDescriptor;var br=Object.getOwnPropertyNames;var yr=Object.getPrototypeOf,wr=Object.prototype.hasOwnProperty;var vr=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var Pr=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var Cr=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of br(t))!wr.call(o,n)&&n!==e&&Un(o,n,{get:()=>t[n],enumerable:!(i=gr(t,n))||i.enumerable});return o};var se=(o,t,e)=>(e=o!=null?mr(yr(o)):{},Cr(t||!o||!o.__esModule?Un(e,"default",{value:o,enumerable:!0}):e,o));var Gt=Pr((ho,an)=>{"use strict";(function(o,t){"use strict";function e(w,s){if(!w)throw new Error(s||"Assertion failed")}function i(w,s){w.super_=s;var u=function(){};u.prototype=s.prototype,w.prototype=new u,w.prototype.constructor=w}function n(w,s,u){if(n.isBN(w))return w;this.negative=0,this.words=null,this.length=0,this.red=null,w!==null&&((s==="le"||s==="be")&&(u=s,s=10),this._init(w||0,s||10,u||"be"))}typeof o=="object"?o.exports=n:t.BN=n,n.BN=n,n.wordSize=26;var r;try{typeof window<"u"&&typeof window.Buffer<"u"?r=window.Buffer:r=vr("buffer").Buffer}catch{}n.isBN=function(s){return s instanceof n?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===n.wordSize&&Array.isArray(s.words)},n.max=function(s,u){return s.cmp(u)>0?s:u},n.min=function(s,u){return s.cmp(u)<0?s:u},n.prototype._init=function(s,u,_){if(typeof s=="number")return this._initNumber(s,u,_);if(typeof s=="object")return this._initArray(s,u,_);u==="hex"&&(u=16),e(u===(u|0)&&u>=2&&u<=36),s=s.toString().replace(/\s+/g,"");var p=0;s[0]==="-"&&(p++,this.negative=1),p<s.length&&(u===16?this._parseHex(s,p,_):(this._parseBase(s,u,p),_==="le"&&this._initArray(this.toArray(),u,_)))},n.prototype._initNumber=function(s,u,_){s<0&&(this.negative=1,s=-s),s<67108864?(this.words=[s&67108863],this.length=1):s<4503599627370496?(this.words=[s&67108863,s/67108864&67108863],this.length=2):(e(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),_==="le"&&this._initArray(this.toArray(),u,_)},n.prototype._initArray=function(s,u,_){if(e(typeof s.length=="number"),s.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(s.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var g,v,C=0;if(_==="be")for(p=s.length-1,g=0;p>=0;p-=3)v=s[p]|s[p-1]<<8|s[p-2]<<16,this.words[g]|=v<<C&67108863,this.words[g+1]=v>>>26-C&67108863,C+=24,C>=26&&(C-=26,g++);else if(_==="le")for(p=0,g=0;p<s.length;p+=3)v=s[p]|s[p+1]<<8|s[p+2]<<16,this.words[g]|=v<<C&67108863,this.words[g+1]=v>>>26-C&67108863,C+=24,C>=26&&(C-=26,g++);return this._strip()};function a(w,s){var u=w.charCodeAt(s);if(u>=48&&u<=57)return u-48;if(u>=65&&u<=70)return u-55;if(u>=97&&u<=102)return u-87;e(!1,"Invalid character in "+w)}function l(w,s,u){var _=a(w,u);return u-1>=s&&(_|=a(w,u-1)<<4),_}n.prototype._parseHex=function(s,u,_){this.length=Math.ceil((s.length-u)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var g=0,v=0,C;if(_==="be")for(p=s.length-1;p>=u;p-=2)C=l(s,u,p)<<g,this.words[v]|=C&67108863,g>=18?(g-=18,v+=1,this.words[v]|=C>>>26):g+=8;else{var m=s.length-u;for(p=m%2===0?u+1:u;p<s.length;p+=2)C=l(s,u,p)<<g,this.words[v]|=C&67108863,g>=18?(g-=18,v+=1,this.words[v]|=C>>>26):g+=8}this._strip()};function d(w,s,u,_){for(var p=0,g=0,v=Math.min(w.length,u),C=s;C<v;C++){var m=w.charCodeAt(C)-48;p*=_,m>=49?g=m-49+10:m>=17?g=m-17+10:g=m,e(m>=0&&g<_,"Invalid character"),p+=g}return p}n.prototype._parseBase=function(s,u,_){this.words=[0],this.length=1;for(var p=0,g=1;g<=67108863;g*=u)p++;p--,g=g/u|0;for(var v=s.length-_,C=v%p,m=Math.min(v,v-C)+_,c=0,y=_;y<m;y+=p)c=d(s,y,y+p,u),this.imuln(g),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(C!==0){var A=1;for(c=d(s,y,s.length,u),y=0;y<C;y++)A*=u;this.imuln(A),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},n.prototype.copy=function(s){s.words=new Array(this.length);for(var u=0;u<this.length;u++)s.words[u]=this.words[u];s.length=this.length,s.negative=this.negative,s.red=this.red};function f(w,s){w.words=s.words,w.length=s.length,w.negative=s.negative,w.red=s.red}if(n.prototype._move=function(s){f(s,this)},n.prototype.clone=function(){var s=new n(null);return this.copy(s),s},n.prototype._expand=function(s){for(;this.length<s;)this.words[this.length++]=0;return this},n.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},n.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{n.prototype[Symbol.for("nodejs.util.inspect.custom")]=h}catch{n.prototype.inspect=h}else n.prototype.inspect=h;function h(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var b=["","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"],P=[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],k=[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];n.prototype.toString=function(s,u){s=s||10,u=u|0||1;var _;if(s===16||s==="hex"){_="";for(var p=0,g=0,v=0;v<this.length;v++){var C=this.words[v],m=((C<<p|g)&16777215).toString(16);g=C>>>24-p&16777215,p+=2,p>=26&&(p-=26,v--),g!==0||v!==this.length-1?_=b[6-m.length]+m+_:_=m+_}for(g!==0&&(_=g.toString(16)+_);_.length%u!==0;)_="0"+_;return this.negative!==0&&(_="-"+_),_}if(s===(s|0)&&s>=2&&s<=36){var c=P[s],y=k[s];_="";var A=this.clone();for(A.negative=0;!A.isZero();){var x=A.modrn(y).toString(s);A=A.idivn(y),A.isZero()?_=x+_:_=b[c-x.length]+x+_}for(this.isZero()&&(_="0"+_);_.length%u!==0;)_="0"+_;return this.negative!==0&&(_="-"+_),_}e(!1,"Base should be between 2 and 36")},n.prototype.toNumber=function(){var s=this.words[0];return this.length===2?s+=this.words[1]*67108864:this.length===3&&this.words[2]===1?s+=4503599627370496+this.words[1]*67108864:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},n.prototype.toJSON=function(){return this.toString(16,2)},r&&(n.prototype.toBuffer=function(s,u){return this.toArrayLike(r,s,u)}),n.prototype.toArray=function(s,u){return this.toArrayLike(Array,s,u)};var T=function(s,u){return s.allocUnsafe?s.allocUnsafe(u):new s(u)};n.prototype.toArrayLike=function(s,u,_){this._strip();var p=this.byteLength(),g=_||Math.max(1,p);e(p<=g,"byte array longer than desired length"),e(g>0,"Requested array length <= 0");var v=T(s,g),C=u==="le"?"LE":"BE";return this["_toArrayLike"+C](v,p),v},n.prototype._toArrayLikeLE=function(s,u){for(var _=0,p=0,g=0,v=0;g<this.length;g++){var C=this.words[g]<<v|p;s[_++]=C&255,_<s.length&&(s[_++]=C>>8&255),_<s.length&&(s[_++]=C>>16&255),v===6?(_<s.length&&(s[_++]=C>>24&255),p=0,v=0):(p=C>>>24,v+=2)}if(_<s.length)for(s[_++]=p;_<s.length;)s[_++]=0},n.prototype._toArrayLikeBE=function(s,u){for(var _=s.length-1,p=0,g=0,v=0;g<this.length;g++){var C=this.words[g]<<v|p;s[_--]=C&255,_>=0&&(s[_--]=C>>8&255),_>=0&&(s[_--]=C>>16&255),v===6?(_>=0&&(s[_--]=C>>24&255),p=0,v=0):(p=C>>>24,v+=2)}if(_>=0)for(s[_--]=p;_>=0;)s[_--]=0},Math.clz32?n.prototype._countBits=function(s){return 32-Math.clz32(s)}:n.prototype._countBits=function(s){var u=s,_=0;return u>=4096&&(_+=13,u>>>=13),u>=64&&(_+=7,u>>>=7),u>=8&&(_+=4,u>>>=4),u>=2&&(_+=2,u>>>=2),_+u},n.prototype._zeroBits=function(s){if(s===0)return 26;var u=s,_=0;return(u&8191)===0&&(_+=13,u>>>=13),(u&127)===0&&(_+=7,u>>>=7),(u&15)===0&&(_+=4,u>>>=4),(u&3)===0&&(_+=2,u>>>=2),(u&1)===0&&_++,_},n.prototype.bitLength=function(){var s=this.words[this.length-1],u=this._countBits(s);return(this.length-1)*26+u};function S(w){for(var s=new Array(w.bitLength()),u=0;u<s.length;u++){var _=u/26|0,p=u%26;s[u]=w.words[_]>>>p&1}return s}n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,u=0;u<this.length;u++){var _=this._zeroBits(this.words[u]);if(s+=_,_!==26)break}return s},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},n.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return this.negative!==0},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.prototype.iuor=function(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var u=0;u<s.length;u++)this.words[u]=this.words[u]|s.words[u];return this._strip()},n.prototype.ior=function(s){return e((this.negative|s.negative)===0),this.iuor(s)},n.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},n.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},n.prototype.iuand=function(s){var u;this.length>s.length?u=s:u=this;for(var _=0;_<u.length;_++)this.words[_]=this.words[_]&s.words[_];return this.length=u.length,this._strip()},n.prototype.iand=function(s){return e((this.negative|s.negative)===0),this.iuand(s)},n.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},n.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},n.prototype.iuxor=function(s){var u,_;this.length>s.length?(u=this,_=s):(u=s,_=this);for(var p=0;p<_.length;p++)this.words[p]=u.words[p]^_.words[p];if(this!==u)for(;p<u.length;p++)this.words[p]=u.words[p];return this.length=u.length,this._strip()},n.prototype.ixor=function(s){return e((this.negative|s.negative)===0),this.iuxor(s)},n.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},n.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},n.prototype.inotn=function(s){e(typeof s=="number"&&s>=0);var u=Math.ceil(s/26)|0,_=s%26;this._expand(u),_>0&&u--;for(var p=0;p<u;p++)this.words[p]=~this.words[p]&67108863;return _>0&&(this.words[p]=~this.words[p]&67108863>>26-_),this._strip()},n.prototype.notn=function(s){return this.clone().inotn(s)},n.prototype.setn=function(s,u){e(typeof s=="number"&&s>=0);var _=s/26|0,p=s%26;return this._expand(_+1),u?this.words[_]=this.words[_]|1<<p:this.words[_]=this.words[_]&~(1<<p),this._strip()},n.prototype.iadd=function(s){var u;if(this.negative!==0&&s.negative===0)return this.negative=0,u=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,u=this.isub(s),s.negative=1,u._normSign();var _,p;this.length>s.length?(_=this,p=s):(_=s,p=this);for(var g=0,v=0;v<p.length;v++)u=(_.words[v]|0)+(p.words[v]|0)+g,this.words[v]=u&67108863,g=u>>>26;for(;g!==0&&v<_.length;v++)u=(_.words[v]|0)+g,this.words[v]=u&67108863,g=u>>>26;if(this.length=_.length,g!==0)this.words[this.length]=g,this.length++;else if(_!==this)for(;v<_.length;v++)this.words[v]=_.words[v];return this},n.prototype.add=function(s){var u;return s.negative!==0&&this.negative===0?(s.negative=0,u=this.sub(s),s.negative^=1,u):s.negative===0&&this.negative!==0?(this.negative=0,u=s.sub(this),this.negative=1,u):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},n.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var u=this.iadd(s);return s.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var _=this.cmp(s);if(_===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,g;_>0?(p=this,g=s):(p=s,g=this);for(var v=0,C=0;C<g.length;C++)u=(p.words[C]|0)-(g.words[C]|0)+v,v=u>>26,this.words[C]=u&67108863;for(;v!==0&&C<p.length;C++)u=(p.words[C]|0)+v,v=u>>26,this.words[C]=u&67108863;if(v===0&&C<p.length&&p!==this)for(;C<p.length;C++)this.words[C]=p.words[C];return this.length=Math.max(this.length,C),p!==this&&(this.negative=1),this._strip()},n.prototype.sub=function(s){return this.clone().isub(s)};function $(w,s,u){u.negative=s.negative^w.negative;var _=w.length+s.length|0;u.length=_,_=_-1|0;var p=w.words[0]|0,g=s.words[0]|0,v=p*g,C=v&67108863,m=v/67108864|0;u.words[0]=C;for(var c=1;c<_;c++){for(var y=m>>>26,A=m&67108863,x=Math.min(c,s.length-1),O=Math.max(0,c-w.length+1);O<=x;O++){var j=c-O|0;p=w.words[j]|0,g=s.words[O]|0,v=p*g+A,y+=v/67108864|0,A=v&67108863}u.words[c]=A|0,m=y|0}return m!==0?u.words[c]=m|0:u.length--,u._strip()}var q=function(s,u,_){var p=s.words,g=u.words,v=_.words,C=0,m,c,y,A=p[0]|0,x=A&8191,O=A>>>13,j=p[1]|0,U=j&8191,V=j>>>13,zt=p[2]|0,K=zt&8191,Z=zt>>>13,ve=p[3]|0,G=ve&8191,Q=ve>>>13,Je=p[4]|0,X=Je&8191,Y=Je>>>13,An=p[5]|0,tt=An&8191,et=An>>>13,Sn=p[6]|0,it=Sn&8191,nt=Sn>>>13,xn=p[7]|0,ot=xn&8191,rt=xn>>>13,In=p[8]|0,st=In&8191,at=In>>>13,On=p[9]|0,ct=On&8191,lt=On>>>13,En=g[0]|0,ut=En&8191,dt=En>>>13,Rn=g[1]|0,ft=Rn&8191,_t=Rn>>>13,Fn=g[2]|0,ht=Fn&8191,pt=Fn>>>13,Bn=g[3]|0,mt=Bn&8191,gt=Bn>>>13,jn=g[4]|0,bt=jn&8191,yt=jn>>>13,Nn=g[5]|0,wt=Nn&8191,vt=Nn>>>13,qn=g[6]|0,Pt=qn&8191,Ct=qn>>>13,Dn=g[7]|0,kt=Dn&8191,Mt=Dn>>>13,Ln=g[8]|0,Tt=Ln&8191,At=Ln>>>13,$n=g[9]|0,St=$n&8191,xt=$n>>>13;_.negative=s.negative^u.negative,_.length=19,m=Math.imul(x,ut),c=Math.imul(x,dt),c=c+Math.imul(O,ut)|0,y=Math.imul(O,dt);var Ri=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ri>>>26)|0,Ri&=67108863,m=Math.imul(U,ut),c=Math.imul(U,dt),c=c+Math.imul(V,ut)|0,y=Math.imul(V,dt),m=m+Math.imul(x,ft)|0,c=c+Math.imul(x,_t)|0,c=c+Math.imul(O,ft)|0,y=y+Math.imul(O,_t)|0;var Fi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Fi>>>26)|0,Fi&=67108863,m=Math.imul(K,ut),c=Math.imul(K,dt),c=c+Math.imul(Z,ut)|0,y=Math.imul(Z,dt),m=m+Math.imul(U,ft)|0,c=c+Math.imul(U,_t)|0,c=c+Math.imul(V,ft)|0,y=y+Math.imul(V,_t)|0,m=m+Math.imul(x,ht)|0,c=c+Math.imul(x,pt)|0,c=c+Math.imul(O,ht)|0,y=y+Math.imul(O,pt)|0;var Bi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Bi>>>26)|0,Bi&=67108863,m=Math.imul(G,ut),c=Math.imul(G,dt),c=c+Math.imul(Q,ut)|0,y=Math.imul(Q,dt),m=m+Math.imul(K,ft)|0,c=c+Math.imul(K,_t)|0,c=c+Math.imul(Z,ft)|0,y=y+Math.imul(Z,_t)|0,m=m+Math.imul(U,ht)|0,c=c+Math.imul(U,pt)|0,c=c+Math.imul(V,ht)|0,y=y+Math.imul(V,pt)|0,m=m+Math.imul(x,mt)|0,c=c+Math.imul(x,gt)|0,c=c+Math.imul(O,mt)|0,y=y+Math.imul(O,gt)|0;var ji=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(ji>>>26)|0,ji&=67108863,m=Math.imul(X,ut),c=Math.imul(X,dt),c=c+Math.imul(Y,ut)|0,y=Math.imul(Y,dt),m=m+Math.imul(G,ft)|0,c=c+Math.imul(G,_t)|0,c=c+Math.imul(Q,ft)|0,y=y+Math.imul(Q,_t)|0,m=m+Math.imul(K,ht)|0,c=c+Math.imul(K,pt)|0,c=c+Math.imul(Z,ht)|0,y=y+Math.imul(Z,pt)|0,m=m+Math.imul(U,mt)|0,c=c+Math.imul(U,gt)|0,c=c+Math.imul(V,mt)|0,y=y+Math.imul(V,gt)|0,m=m+Math.imul(x,bt)|0,c=c+Math.imul(x,yt)|0,c=c+Math.imul(O,bt)|0,y=y+Math.imul(O,yt)|0;var Ni=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ni>>>26)|0,Ni&=67108863,m=Math.imul(tt,ut),c=Math.imul(tt,dt),c=c+Math.imul(et,ut)|0,y=Math.imul(et,dt),m=m+Math.imul(X,ft)|0,c=c+Math.imul(X,_t)|0,c=c+Math.imul(Y,ft)|0,y=y+Math.imul(Y,_t)|0,m=m+Math.imul(G,ht)|0,c=c+Math.imul(G,pt)|0,c=c+Math.imul(Q,ht)|0,y=y+Math.imul(Q,pt)|0,m=m+Math.imul(K,mt)|0,c=c+Math.imul(K,gt)|0,c=c+Math.imul(Z,mt)|0,y=y+Math.imul(Z,gt)|0,m=m+Math.imul(U,bt)|0,c=c+Math.imul(U,yt)|0,c=c+Math.imul(V,bt)|0,y=y+Math.imul(V,yt)|0,m=m+Math.imul(x,wt)|0,c=c+Math.imul(x,vt)|0,c=c+Math.imul(O,wt)|0,y=y+Math.imul(O,vt)|0;var qi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(qi>>>26)|0,qi&=67108863,m=Math.imul(it,ut),c=Math.imul(it,dt),c=c+Math.imul(nt,ut)|0,y=Math.imul(nt,dt),m=m+Math.imul(tt,ft)|0,c=c+Math.imul(tt,_t)|0,c=c+Math.imul(et,ft)|0,y=y+Math.imul(et,_t)|0,m=m+Math.imul(X,ht)|0,c=c+Math.imul(X,pt)|0,c=c+Math.imul(Y,ht)|0,y=y+Math.imul(Y,pt)|0,m=m+Math.imul(G,mt)|0,c=c+Math.imul(G,gt)|0,c=c+Math.imul(Q,mt)|0,y=y+Math.imul(Q,gt)|0,m=m+Math.imul(K,bt)|0,c=c+Math.imul(K,yt)|0,c=c+Math.imul(Z,bt)|0,y=y+Math.imul(Z,yt)|0,m=m+Math.imul(U,wt)|0,c=c+Math.imul(U,vt)|0,c=c+Math.imul(V,wt)|0,y=y+Math.imul(V,vt)|0,m=m+Math.imul(x,Pt)|0,c=c+Math.imul(x,Ct)|0,c=c+Math.imul(O,Pt)|0,y=y+Math.imul(O,Ct)|0;var Di=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Di>>>26)|0,Di&=67108863,m=Math.imul(ot,ut),c=Math.imul(ot,dt),c=c+Math.imul(rt,ut)|0,y=Math.imul(rt,dt),m=m+Math.imul(it,ft)|0,c=c+Math.imul(it,_t)|0,c=c+Math.imul(nt,ft)|0,y=y+Math.imul(nt,_t)|0,m=m+Math.imul(tt,ht)|0,c=c+Math.imul(tt,pt)|0,c=c+Math.imul(et,ht)|0,y=y+Math.imul(et,pt)|0,m=m+Math.imul(X,mt)|0,c=c+Math.imul(X,gt)|0,c=c+Math.imul(Y,mt)|0,y=y+Math.imul(Y,gt)|0,m=m+Math.imul(G,bt)|0,c=c+Math.imul(G,yt)|0,c=c+Math.imul(Q,bt)|0,y=y+Math.imul(Q,yt)|0,m=m+Math.imul(K,wt)|0,c=c+Math.imul(K,vt)|0,c=c+Math.imul(Z,wt)|0,y=y+Math.imul(Z,vt)|0,m=m+Math.imul(U,Pt)|0,c=c+Math.imul(U,Ct)|0,c=c+Math.imul(V,Pt)|0,y=y+Math.imul(V,Ct)|0,m=m+Math.imul(x,kt)|0,c=c+Math.imul(x,Mt)|0,c=c+Math.imul(O,kt)|0,y=y+Math.imul(O,Mt)|0;var Li=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Li>>>26)|0,Li&=67108863,m=Math.imul(st,ut),c=Math.imul(st,dt),c=c+Math.imul(at,ut)|0,y=Math.imul(at,dt),m=m+Math.imul(ot,ft)|0,c=c+Math.imul(ot,_t)|0,c=c+Math.imul(rt,ft)|0,y=y+Math.imul(rt,_t)|0,m=m+Math.imul(it,ht)|0,c=c+Math.imul(it,pt)|0,c=c+Math.imul(nt,ht)|0,y=y+Math.imul(nt,pt)|0,m=m+Math.imul(tt,mt)|0,c=c+Math.imul(tt,gt)|0,c=c+Math.imul(et,mt)|0,y=y+Math.imul(et,gt)|0,m=m+Math.imul(X,bt)|0,c=c+Math.imul(X,yt)|0,c=c+Math.imul(Y,bt)|0,y=y+Math.imul(Y,yt)|0,m=m+Math.imul(G,wt)|0,c=c+Math.imul(G,vt)|0,c=c+Math.imul(Q,wt)|0,y=y+Math.imul(Q,vt)|0,m=m+Math.imul(K,Pt)|0,c=c+Math.imul(K,Ct)|0,c=c+Math.imul(Z,Pt)|0,y=y+Math.imul(Z,Ct)|0,m=m+Math.imul(U,kt)|0,c=c+Math.imul(U,Mt)|0,c=c+Math.imul(V,kt)|0,y=y+Math.imul(V,Mt)|0,m=m+Math.imul(x,Tt)|0,c=c+Math.imul(x,At)|0,c=c+Math.imul(O,Tt)|0,y=y+Math.imul(O,At)|0;var $i=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+($i>>>26)|0,$i&=67108863,m=Math.imul(ct,ut),c=Math.imul(ct,dt),c=c+Math.imul(lt,ut)|0,y=Math.imul(lt,dt),m=m+Math.imul(st,ft)|0,c=c+Math.imul(st,_t)|0,c=c+Math.imul(at,ft)|0,y=y+Math.imul(at,_t)|0,m=m+Math.imul(ot,ht)|0,c=c+Math.imul(ot,pt)|0,c=c+Math.imul(rt,ht)|0,y=y+Math.imul(rt,pt)|0,m=m+Math.imul(it,mt)|0,c=c+Math.imul(it,gt)|0,c=c+Math.imul(nt,mt)|0,y=y+Math.imul(nt,gt)|0,m=m+Math.imul(tt,bt)|0,c=c+Math.imul(tt,yt)|0,c=c+Math.imul(et,bt)|0,y=y+Math.imul(et,yt)|0,m=m+Math.imul(X,wt)|0,c=c+Math.imul(X,vt)|0,c=c+Math.imul(Y,wt)|0,y=y+Math.imul(Y,vt)|0,m=m+Math.imul(G,Pt)|0,c=c+Math.imul(G,Ct)|0,c=c+Math.imul(Q,Pt)|0,y=y+Math.imul(Q,Ct)|0,m=m+Math.imul(K,kt)|0,c=c+Math.imul(K,Mt)|0,c=c+Math.imul(Z,kt)|0,y=y+Math.imul(Z,Mt)|0,m=m+Math.imul(U,Tt)|0,c=c+Math.imul(U,At)|0,c=c+Math.imul(V,Tt)|0,y=y+Math.imul(V,At)|0,m=m+Math.imul(x,St)|0,c=c+Math.imul(x,xt)|0,c=c+Math.imul(O,St)|0,y=y+Math.imul(O,xt)|0;var Ui=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ui>>>26)|0,Ui&=67108863,m=Math.imul(ct,ft),c=Math.imul(ct,_t),c=c+Math.imul(lt,ft)|0,y=Math.imul(lt,_t),m=m+Math.imul(st,ht)|0,c=c+Math.imul(st,pt)|0,c=c+Math.imul(at,ht)|0,y=y+Math.imul(at,pt)|0,m=m+Math.imul(ot,mt)|0,c=c+Math.imul(ot,gt)|0,c=c+Math.imul(rt,mt)|0,y=y+Math.imul(rt,gt)|0,m=m+Math.imul(it,bt)|0,c=c+Math.imul(it,yt)|0,c=c+Math.imul(nt,bt)|0,y=y+Math.imul(nt,yt)|0,m=m+Math.imul(tt,wt)|0,c=c+Math.imul(tt,vt)|0,c=c+Math.imul(et,wt)|0,y=y+Math.imul(et,vt)|0,m=m+Math.imul(X,Pt)|0,c=c+Math.imul(X,Ct)|0,c=c+Math.imul(Y,Pt)|0,y=y+Math.imul(Y,Ct)|0,m=m+Math.imul(G,kt)|0,c=c+Math.imul(G,Mt)|0,c=c+Math.imul(Q,kt)|0,y=y+Math.imul(Q,Mt)|0,m=m+Math.imul(K,Tt)|0,c=c+Math.imul(K,At)|0,c=c+Math.imul(Z,Tt)|0,y=y+Math.imul(Z,At)|0,m=m+Math.imul(U,St)|0,c=c+Math.imul(U,xt)|0,c=c+Math.imul(V,St)|0,y=y+Math.imul(V,xt)|0;var Vi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Vi>>>26)|0,Vi&=67108863,m=Math.imul(ct,ht),c=Math.imul(ct,pt),c=c+Math.imul(lt,ht)|0,y=Math.imul(lt,pt),m=m+Math.imul(st,mt)|0,c=c+Math.imul(st,gt)|0,c=c+Math.imul(at,mt)|0,y=y+Math.imul(at,gt)|0,m=m+Math.imul(ot,bt)|0,c=c+Math.imul(ot,yt)|0,c=c+Math.imul(rt,bt)|0,y=y+Math.imul(rt,yt)|0,m=m+Math.imul(it,wt)|0,c=c+Math.imul(it,vt)|0,c=c+Math.imul(nt,wt)|0,y=y+Math.imul(nt,vt)|0,m=m+Math.imul(tt,Pt)|0,c=c+Math.imul(tt,Ct)|0,c=c+Math.imul(et,Pt)|0,y=y+Math.imul(et,Ct)|0,m=m+Math.imul(X,kt)|0,c=c+Math.imul(X,Mt)|0,c=c+Math.imul(Y,kt)|0,y=y+Math.imul(Y,Mt)|0,m=m+Math.imul(G,Tt)|0,c=c+Math.imul(G,At)|0,c=c+Math.imul(Q,Tt)|0,y=y+Math.imul(Q,At)|0,m=m+Math.imul(K,St)|0,c=c+Math.imul(K,xt)|0,c=c+Math.imul(Z,St)|0,y=y+Math.imul(Z,xt)|0;var Ki=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Ki>>>26)|0,Ki&=67108863,m=Math.imul(ct,mt),c=Math.imul(ct,gt),c=c+Math.imul(lt,mt)|0,y=Math.imul(lt,gt),m=m+Math.imul(st,bt)|0,c=c+Math.imul(st,yt)|0,c=c+Math.imul(at,bt)|0,y=y+Math.imul(at,yt)|0,m=m+Math.imul(ot,wt)|0,c=c+Math.imul(ot,vt)|0,c=c+Math.imul(rt,wt)|0,y=y+Math.imul(rt,vt)|0,m=m+Math.imul(it,Pt)|0,c=c+Math.imul(it,Ct)|0,c=c+Math.imul(nt,Pt)|0,y=y+Math.imul(nt,Ct)|0,m=m+Math.imul(tt,kt)|0,c=c+Math.imul(tt,Mt)|0,c=c+Math.imul(et,kt)|0,y=y+Math.imul(et,Mt)|0,m=m+Math.imul(X,Tt)|0,c=c+Math.imul(X,At)|0,c=c+Math.imul(Y,Tt)|0,y=y+Math.imul(Y,At)|0,m=m+Math.imul(G,St)|0,c=c+Math.imul(G,xt)|0,c=c+Math.imul(Q,St)|0,y=y+Math.imul(Q,xt)|0;var Hi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Hi>>>26)|0,Hi&=67108863,m=Math.imul(ct,bt),c=Math.imul(ct,yt),c=c+Math.imul(lt,bt)|0,y=Math.imul(lt,yt),m=m+Math.imul(st,wt)|0,c=c+Math.imul(st,vt)|0,c=c+Math.imul(at,wt)|0,y=y+Math.imul(at,vt)|0,m=m+Math.imul(ot,Pt)|0,c=c+Math.imul(ot,Ct)|0,c=c+Math.imul(rt,Pt)|0,y=y+Math.imul(rt,Ct)|0,m=m+Math.imul(it,kt)|0,c=c+Math.imul(it,Mt)|0,c=c+Math.imul(nt,kt)|0,y=y+Math.imul(nt,Mt)|0,m=m+Math.imul(tt,Tt)|0,c=c+Math.imul(tt,At)|0,c=c+Math.imul(et,Tt)|0,y=y+Math.imul(et,At)|0,m=m+Math.imul(X,St)|0,c=c+Math.imul(X,xt)|0,c=c+Math.imul(Y,St)|0,y=y+Math.imul(Y,xt)|0;var Wi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Wi>>>26)|0,Wi&=67108863,m=Math.imul(ct,wt),c=Math.imul(ct,vt),c=c+Math.imul(lt,wt)|0,y=Math.imul(lt,vt),m=m+Math.imul(st,Pt)|0,c=c+Math.imul(st,Ct)|0,c=c+Math.imul(at,Pt)|0,y=y+Math.imul(at,Ct)|0,m=m+Math.imul(ot,kt)|0,c=c+Math.imul(ot,Mt)|0,c=c+Math.imul(rt,kt)|0,y=y+Math.imul(rt,Mt)|0,m=m+Math.imul(it,Tt)|0,c=c+Math.imul(it,At)|0,c=c+Math.imul(nt,Tt)|0,y=y+Math.imul(nt,At)|0,m=m+Math.imul(tt,St)|0,c=c+Math.imul(tt,xt)|0,c=c+Math.imul(et,St)|0,y=y+Math.imul(et,xt)|0;var Zi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Zi>>>26)|0,Zi&=67108863,m=Math.imul(ct,Pt),c=Math.imul(ct,Ct),c=c+Math.imul(lt,Pt)|0,y=Math.imul(lt,Ct),m=m+Math.imul(st,kt)|0,c=c+Math.imul(st,Mt)|0,c=c+Math.imul(at,kt)|0,y=y+Math.imul(at,Mt)|0,m=m+Math.imul(ot,Tt)|0,c=c+Math.imul(ot,At)|0,c=c+Math.imul(rt,Tt)|0,y=y+Math.imul(rt,At)|0,m=m+Math.imul(it,St)|0,c=c+Math.imul(it,xt)|0,c=c+Math.imul(nt,St)|0,y=y+Math.imul(nt,xt)|0;var zi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(zi>>>26)|0,zi&=67108863,m=Math.imul(ct,kt),c=Math.imul(ct,Mt),c=c+Math.imul(lt,kt)|0,y=Math.imul(lt,Mt),m=m+Math.imul(st,Tt)|0,c=c+Math.imul(st,At)|0,c=c+Math.imul(at,Tt)|0,y=y+Math.imul(at,At)|0,m=m+Math.imul(ot,St)|0,c=c+Math.imul(ot,xt)|0,c=c+Math.imul(rt,St)|0,y=y+Math.imul(rt,xt)|0;var Gi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Gi>>>26)|0,Gi&=67108863,m=Math.imul(ct,Tt),c=Math.imul(ct,At),c=c+Math.imul(lt,Tt)|0,y=Math.imul(lt,At),m=m+Math.imul(st,St)|0,c=c+Math.imul(st,xt)|0,c=c+Math.imul(at,St)|0,y=y+Math.imul(at,xt)|0;var Qi=(C+m|0)+((c&8191)<<13)|0;C=(y+(c>>>13)|0)+(Qi>>>26)|0,Qi&=67108863,m=Math.imul(ct,St),c=Math.imul(ct,xt),c=c+Math.imul(lt,St)|0,y=Math.imul(lt,xt);var Ji=(C+m|0)+((c&8191)<<13)|0;return C=(y+(c>>>13)|0)+(Ji>>>26)|0,Ji&=67108863,v[0]=Ri,v[1]=Fi,v[2]=Bi,v[3]=ji,v[4]=Ni,v[5]=qi,v[6]=Di,v[7]=Li,v[8]=$i,v[9]=Ui,v[10]=Vi,v[11]=Ki,v[12]=Hi,v[13]=Wi,v[14]=Zi,v[15]=zi,v[16]=Gi,v[17]=Qi,v[18]=Ji,C!==0&&(v[19]=C,_.length++),_};Math.imul||(q=$);function z(w,s,u){u.negative=s.negative^w.negative,u.length=w.length+s.length;for(var _=0,p=0,g=0;g<u.length-1;g++){var v=p;p=0;for(var C=_&67108863,m=Math.min(g,s.length-1),c=Math.max(0,g-w.length+1);c<=m;c++){var y=g-c,A=w.words[y]|0,x=s.words[c]|0,O=A*x,j=O&67108863;v=v+(O/67108864|0)|0,j=j+C|0,C=j&67108863,v=v+(j>>>26)|0,p+=v>>>26,v&=67108863}u.words[g]=C,_=v,v=p}return _!==0?u.words[g]=_:u.length--,u._strip()}function N(w,s,u){return z(w,s,u)}n.prototype.mulTo=function(s,u){var _,p=this.length+s.length;return this.length===10&&s.length===10?_=q(this,s,u):p<63?_=$(this,s,u):p<1024?_=z(this,s,u):_=N(this,s,u),_};function D(w,s){this.x=w,this.y=s}D.prototype.makeRBT=function(s){for(var u=new Array(s),_=n.prototype._countBits(s)-1,p=0;p<s;p++)u[p]=this.revBin(p,_,s);return u},D.prototype.revBin=function(s,u,_){if(s===0||s===_-1)return s;for(var p=0,g=0;g<u;g++)p|=(s&1)<<u-g-1,s>>=1;return p},D.prototype.permute=function(s,u,_,p,g,v){for(var C=0;C<v;C++)p[C]=u[s[C]],g[C]=_[s[C]]},D.prototype.transform=function(s,u,_,p,g,v){this.permute(v,s,u,_,p,g);for(var C=1;C<g;C<<=1)for(var m=C<<1,c=Math.cos(2*Math.PI/m),y=Math.sin(2*Math.PI/m),A=0;A<g;A+=m)for(var x=c,O=y,j=0;j<C;j++){var U=_[A+j],V=p[A+j],zt=_[A+j+C],K=p[A+j+C],Z=x*zt-O*K;K=x*K+O*zt,zt=Z,_[A+j]=U+zt,p[A+j]=V+K,_[A+j+C]=U-zt,p[A+j+C]=V-K,j!==m&&(Z=c*x-y*O,O=c*O+y*x,x=Z)}},D.prototype.guessLen13b=function(s,u){var _=Math.max(u,s)|1,p=_&1,g=0;for(_=_/2|0;_;_=_>>>1)g++;return 1<<g+1+p},D.prototype.conjugate=function(s,u,_){if(!(_<=1))for(var p=0;p<_/2;p++){var g=s[p];s[p]=s[_-p-1],s[_-p-1]=g,g=u[p],u[p]=-u[_-p-1],u[_-p-1]=-g}},D.prototype.normalize13b=function(s,u){for(var _=0,p=0;p<u/2;p++){var g=Math.round(s[2*p+1]/u)*8192+Math.round(s[2*p]/u)+_;s[p]=g&67108863,g<67108864?_=0:_=g/67108864|0}return s},D.prototype.convert13b=function(s,u,_,p){for(var g=0,v=0;v<u;v++)g=g+(s[v]|0),_[2*v]=g&8191,g=g>>>13,_[2*v+1]=g&8191,g=g>>>13;for(v=2*u;v<p;++v)_[v]=0;e(g===0),e((g&-8192)===0)},D.prototype.stub=function(s){for(var u=new Array(s),_=0;_<s;_++)u[_]=0;return u},D.prototype.mulp=function(s,u,_){var p=2*this.guessLen13b(s.length,u.length),g=this.makeRBT(p),v=this.stub(p),C=new Array(p),m=new Array(p),c=new Array(p),y=new Array(p),A=new Array(p),x=new Array(p),O=_.words;O.length=p,this.convert13b(s.words,s.length,C,p),this.convert13b(u.words,u.length,y,p),this.transform(C,v,m,c,p,g),this.transform(y,v,A,x,p,g);for(var j=0;j<p;j++){var U=m[j]*A[j]-c[j]*x[j];c[j]=m[j]*x[j]+c[j]*A[j],m[j]=U}return this.conjugate(m,c,p),this.transform(m,c,O,v,p,g),this.conjugate(O,v,p),this.normalize13b(O,p),_.negative=s.negative^u.negative,_.length=s.length+u.length,_._strip()},n.prototype.mul=function(s){var u=new n(null);return u.words=new Array(this.length+s.length),this.mulTo(s,u)},n.prototype.mulf=function(s){var u=new n(null);return u.words=new Array(this.length+s.length),N(this,s,u)},n.prototype.imul=function(s){return this.clone().mulTo(s,this)},n.prototype.imuln=function(s){var u=s<0;u&&(s=-s),e(typeof s=="number"),e(s<67108864);for(var _=0,p=0;p<this.length;p++){var g=(this.words[p]|0)*s,v=(g&67108863)+(_&67108863);_>>=26,_+=g/67108864|0,_+=v>>>26,this.words[p]=v&67108863}return _!==0&&(this.words[p]=_,this.length++),this.length=s===0?1:this.length,u?this.ineg():this},n.prototype.muln=function(s){return this.clone().imuln(s)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(s){var u=S(s);if(u.length===0)return new n(1);for(var _=this,p=0;p<u.length&&u[p]===0;p++,_=_.sqr());if(++p<u.length)for(var g=_.sqr();p<u.length;p++,g=g.sqr())u[p]!==0&&(_=_.mul(g));return _},n.prototype.iushln=function(s){e(typeof s=="number"&&s>=0);var u=s%26,_=(s-u)/26,p=67108863>>>26-u<<26-u,g;if(u!==0){var v=0;for(g=0;g<this.length;g++){var C=this.words[g]&p,m=(this.words[g]|0)-C<<u;this.words[g]=m|v,v=C>>>26-u}v&&(this.words[g]=v,this.length++)}if(_!==0){for(g=this.length-1;g>=0;g--)this.words[g+_]=this.words[g];for(g=0;g<_;g++)this.words[g]=0;this.length+=_}return this._strip()},n.prototype.ishln=function(s){return e(this.negative===0),this.iushln(s)},n.prototype.iushrn=function(s,u,_){e(typeof s=="number"&&s>=0);var p;u?p=(u-u%26)/26:p=0;var g=s%26,v=Math.min((s-g)/26,this.length),C=67108863^67108863>>>g<<g,m=_;if(p-=v,p=Math.max(0,p),m){for(var c=0;c<v;c++)m.words[c]=this.words[c];m.length=v}if(v!==0)if(this.length>v)for(this.length-=v,c=0;c<this.length;c++)this.words[c]=this.words[c+v];else this.words[0]=0,this.length=1;var y=0;for(c=this.length-1;c>=0&&(y!==0||c>=p);c--){var A=this.words[c]|0;this.words[c]=y<<26-g|A>>>g,y=A&C}return m&&y!==0&&(m.words[m.length++]=y),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},n.prototype.ishrn=function(s,u,_){return e(this.negative===0),this.iushrn(s,u,_)},n.prototype.shln=function(s){return this.clone().ishln(s)},n.prototype.ushln=function(s){return this.clone().iushln(s)},n.prototype.shrn=function(s){return this.clone().ishrn(s)},n.prototype.ushrn=function(s){return this.clone().iushrn(s)},n.prototype.testn=function(s){e(typeof s=="number"&&s>=0);var u=s%26,_=(s-u)/26,p=1<<u;if(this.length<=_)return!1;var g=this.words[_];return!!(g&p)},n.prototype.imaskn=function(s){e(typeof s=="number"&&s>=0);var u=s%26,_=(s-u)/26;if(e(this.negative===0,"imaskn works only with positive numbers"),this.length<=_)return this;if(u!==0&&_++,this.length=Math.min(_,this.length),u!==0){var p=67108863^67108863>>>u<<u;this.words[this.length-1]&=p}return this._strip()},n.prototype.maskn=function(s){return this.clone().imaskn(s)},n.prototype.iaddn=function(s){return e(typeof s=="number"),e(s<67108864),s<0?this.isubn(-s):this.negative!==0?this.length===1&&(this.words[0]|0)<=s?(this.words[0]=s-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(s),this.negative=1,this):this._iaddn(s)},n.prototype._iaddn=function(s){this.words[0]+=s;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},n.prototype.isubn=function(s){if(e(typeof s=="number"),e(s<67108864),s<0)return this.iaddn(-s);if(this.negative!==0)return this.negative=0,this.iaddn(s),this.negative=1,this;if(this.words[0]-=s,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},n.prototype.addn=function(s){return this.clone().iaddn(s)},n.prototype.subn=function(s){return this.clone().isubn(s)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(s,u,_){var p=s.length+_,g;this._expand(p);var v,C=0;for(g=0;g<s.length;g++){v=(this.words[g+_]|0)+C;var m=(s.words[g]|0)*u;v-=m&67108863,C=(v>>26)-(m/67108864|0),this.words[g+_]=v&67108863}for(;g<this.length-_;g++)v=(this.words[g+_]|0)+C,C=v>>26,this.words[g+_]=v&67108863;if(C===0)return this._strip();for(e(C===-1),C=0,g=0;g<this.length;g++)v=-(this.words[g]|0)+C,C=v>>26,this.words[g]=v&67108863;return this.negative=1,this._strip()},n.prototype._wordDiv=function(s,u){var _=this.length-s.length,p=this.clone(),g=s,v=g.words[g.length-1]|0,C=this._countBits(v);_=26-C,_!==0&&(g=g.ushln(_),p.iushln(_),v=g.words[g.length-1]|0);var m=p.length-g.length,c;if(u!=="mod"){c=new n(null),c.length=m+1,c.words=new Array(c.length);for(var y=0;y<c.length;y++)c.words[y]=0}var A=p.clone()._ishlnsubmul(g,1,m);A.negative===0&&(p=A,c&&(c.words[m]=1));for(var x=m-1;x>=0;x--){var O=(p.words[g.length+x]|0)*67108864+(p.words[g.length+x-1]|0);for(O=Math.min(O/v|0,67108863),p._ishlnsubmul(g,O,x);p.negative!==0;)O--,p.negative=0,p._ishlnsubmul(g,1,x),p.isZero()||(p.negative^=1);c&&(c.words[x]=O)}return c&&c._strip(),p._strip(),u!=="div"&&_!==0&&p.iushrn(_),{div:c||null,mod:p}},n.prototype.divmod=function(s,u,_){if(e(!s.isZero()),this.isZero())return{div:new n(0),mod:new n(0)};var p,g,v;return this.negative!==0&&s.negative===0?(v=this.neg().divmod(s,u),u!=="mod"&&(p=v.div.neg()),u!=="div"&&(g=v.mod.neg(),_&&g.negative!==0&&g.iadd(s)),{div:p,mod:g}):this.negative===0&&s.negative!==0?(v=this.divmod(s.neg(),u),u!=="mod"&&(p=v.div.neg()),{div:p,mod:v.mod}):(this.negative&s.negative)!==0?(v=this.neg().divmod(s.neg(),u),u!=="div"&&(g=v.mod.neg(),_&&g.negative!==0&&g.isub(s)),{div:v.div,mod:g}):s.length>this.length||this.cmp(s)<0?{div:new n(0),mod:this}:s.length===1?u==="div"?{div:this.divn(s.words[0]),mod:null}:u==="mod"?{div:null,mod:new n(this.modrn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new n(this.modrn(s.words[0]))}:this._wordDiv(s,u)},n.prototype.div=function(s){return this.divmod(s,"div",!1).div},n.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},n.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},n.prototype.divRound=function(s){var u=this.divmod(s);if(u.mod.isZero())return u.div;var _=u.div.negative!==0?u.mod.isub(s):u.mod,p=s.ushrn(1),g=s.andln(1),v=_.cmp(p);return v<0||g===1&&v===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},n.prototype.modrn=function(s){var u=s<0;u&&(s=-s),e(s<=67108863);for(var _=(1<<26)%s,p=0,g=this.length-1;g>=0;g--)p=(_*p+(this.words[g]|0))%s;return u?-p:p},n.prototype.modn=function(s){return this.modrn(s)},n.prototype.idivn=function(s){var u=s<0;u&&(s=-s),e(s<=67108863);for(var _=0,p=this.length-1;p>=0;p--){var g=(this.words[p]|0)+_*67108864;this.words[p]=g/s|0,_=g%s}return this._strip(),u?this.ineg():this},n.prototype.divn=function(s){return this.clone().idivn(s)},n.prototype.egcd=function(s){e(s.negative===0),e(!s.isZero());var u=this,_=s.clone();u.negative!==0?u=u.umod(s):u=u.clone();for(var p=new n(1),g=new n(0),v=new n(0),C=new n(1),m=0;u.isEven()&&_.isEven();)u.iushrn(1),_.iushrn(1),++m;for(var c=_.clone(),y=u.clone();!u.isZero();){for(var A=0,x=1;(u.words[0]&x)===0&&A<26;++A,x<<=1);if(A>0)for(u.iushrn(A);A-- >0;)(p.isOdd()||g.isOdd())&&(p.iadd(c),g.isub(y)),p.iushrn(1),g.iushrn(1);for(var O=0,j=1;(_.words[0]&j)===0&&O<26;++O,j<<=1);if(O>0)for(_.iushrn(O);O-- >0;)(v.isOdd()||C.isOdd())&&(v.iadd(c),C.isub(y)),v.iushrn(1),C.iushrn(1);u.cmp(_)>=0?(u.isub(_),p.isub(v),g.isub(C)):(_.isub(u),v.isub(p),C.isub(g))}return{a:v,b:C,gcd:_.iushln(m)}},n.prototype._invmp=function(s){e(s.negative===0),e(!s.isZero());var u=this,_=s.clone();u.negative!==0?u=u.umod(s):u=u.clone();for(var p=new n(1),g=new n(0),v=_.clone();u.cmpn(1)>0&&_.cmpn(1)>0;){for(var C=0,m=1;(u.words[0]&m)===0&&C<26;++C,m<<=1);if(C>0)for(u.iushrn(C);C-- >0;)p.isOdd()&&p.iadd(v),p.iushrn(1);for(var c=0,y=1;(_.words[0]&y)===0&&c<26;++c,y<<=1);if(c>0)for(_.iushrn(c);c-- >0;)g.isOdd()&&g.iadd(v),g.iushrn(1);u.cmp(_)>=0?(u.isub(_),p.isub(g)):(_.isub(u),g.isub(p))}var A;return u.cmpn(1)===0?A=p:A=g,A.cmpn(0)<0&&A.iadd(s),A},n.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var u=this.clone(),_=s.clone();u.negative=0,_.negative=0;for(var p=0;u.isEven()&&_.isEven();p++)u.iushrn(1),_.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;_.isEven();)_.iushrn(1);var g=u.cmp(_);if(g<0){var v=u;u=_,_=v}else if(g===0||_.cmpn(1)===0)break;u.isub(_)}while(!0);return _.iushln(p)},n.prototype.invm=function(s){return this.egcd(s).a.umod(s)},n.prototype.isEven=function(){return(this.words[0]&1)===0},n.prototype.isOdd=function(){return(this.words[0]&1)===1},n.prototype.andln=function(s){return this.words[0]&s},n.prototype.bincn=function(s){e(typeof s=="number");var u=s%26,_=(s-u)/26,p=1<<u;if(this.length<=_)return this._expand(_+1),this.words[_]|=p,this;for(var g=p,v=_;g!==0&&v<this.length;v++){var C=this.words[v]|0;C+=g,g=C>>>26,C&=67108863,this.words[v]=C}return g!==0&&(this.words[v]=g,this.length++),this},n.prototype.isZero=function(){return this.length===1&&this.words[0]===0},n.prototype.cmpn=function(s){var u=s<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var _;if(this.length>1)_=1;else{u&&(s=-s),e(s<=67108863,"Number is too big");var p=this.words[0]|0;_=p===s?0:p<s?-1:1}return this.negative!==0?-_|0:_},n.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var u=this.ucmp(s);return this.negative!==0?-u|0:u},n.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var u=0,_=this.length-1;_>=0;_--){var p=this.words[_]|0,g=s.words[_]|0;if(p!==g){p<g?u=-1:p>g&&(u=1);break}}return u},n.prototype.gtn=function(s){return this.cmpn(s)===1},n.prototype.gt=function(s){return this.cmp(s)===1},n.prototype.gten=function(s){return this.cmpn(s)>=0},n.prototype.gte=function(s){return this.cmp(s)>=0},n.prototype.ltn=function(s){return this.cmpn(s)===-1},n.prototype.lt=function(s){return this.cmp(s)===-1},n.prototype.lten=function(s){return this.cmpn(s)<=0},n.prototype.lte=function(s){return this.cmp(s)<=0},n.prototype.eqn=function(s){return this.cmpn(s)===0},n.prototype.eq=function(s){return this.cmp(s)===0},n.red=function(s){return new L(s)},n.prototype.toRed=function(s){return e(!this.red,"Already a number in reduction context"),e(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},n.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(s){return this.red=s,this},n.prototype.forceRed=function(s){return e(!this.red,"Already a number in reduction context"),this._forceRed(s)},n.prototype.redAdd=function(s){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},n.prototype.redIAdd=function(s){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},n.prototype.redSub=function(s){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},n.prototype.redISub=function(s){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},n.prototype.redShl=function(s){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},n.prototype.redMul=function(s){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},n.prototype.redIMul=function(s){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},n.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(s){return e(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var qt={k256:null,p224:null,p192:null,p25519:null};function W(w,s){this.name=w,this.p=new n(s,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}W.prototype._tmp=function(){var s=new n(null);return s.words=new Array(Math.ceil(this.n/13)),s},W.prototype.ireduce=function(s){var u=s,_;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),_=u.bitLength();while(_>this.n);var p=_<this.n?-1:u.ucmp(this.p);return p===0?(u.words[0]=0,u.length=1):p>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},W.prototype.split=function(s,u){s.iushrn(this.n,0,u)},W.prototype.imulK=function(s){return s.imul(this.k)};function $t(){W.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}i($t,W),$t.prototype.split=function(s,u){for(var _=4194303,p=Math.min(s.length,9),g=0;g<p;g++)u.words[g]=s.words[g];if(u.length=p,s.length<=9){s.words[0]=0,s.length=1;return}var v=s.words[9];for(u.words[u.length++]=v&_,g=10;g<s.length;g++){var C=s.words[g]|0;s.words[g-10]=(C&_)<<4|v>>>22,v=C}v>>>=22,s.words[g-10]=v,v===0&&s.length>10?s.length-=10:s.length-=9},$t.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var u=0,_=0;_<s.length;_++){var p=s.words[_]|0;u+=p*977,s.words[_]=u&67108863,u=p*64+(u/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function oe(){W.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}i(oe,W);function Zt(){W.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}i(Zt,W);function re(){W.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}i(re,W),re.prototype.imulK=function(s){for(var u=0,_=0;_<s.length;_++){var p=(s.words[_]|0)*19+u,g=p&67108863;p>>>=26,s.words[_]=g,u=p}return u!==0&&(s.words[s.length++]=u),s},n._prime=function(s){if(qt[s])return qt[s];var u;if(s==="k256")u=new $t;else if(s==="p224")u=new oe;else if(s==="p192")u=new Zt;else if(s==="p25519")u=new re;else throw new Error("Unknown prime "+s);return qt[s]=u,u};function L(w){if(typeof w=="string"){var s=n._prime(w);this.m=s.p,this.prime=s}else e(w.gtn(1),"modulus must be greater than 1"),this.m=w,this.prime=null}L.prototype._verify1=function(s){e(s.negative===0,"red works only with positives"),e(s.red,"red works only with red numbers")},L.prototype._verify2=function(s,u){e((s.negative|u.negative)===0,"red works only with positives"),e(s.red&&s.red===u.red,"red works only with red numbers")},L.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):(f(s,s.umod(this.m)._forceRed(this)),s)},L.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},L.prototype.add=function(s,u){this._verify2(s,u);var _=s.add(u);return _.cmp(this.m)>=0&&_.isub(this.m),_._forceRed(this)},L.prototype.iadd=function(s,u){this._verify2(s,u);var _=s.iadd(u);return _.cmp(this.m)>=0&&_.isub(this.m),_},L.prototype.sub=function(s,u){this._verify2(s,u);var _=s.sub(u);return _.cmpn(0)<0&&_.iadd(this.m),_._forceRed(this)},L.prototype.isub=function(s,u){this._verify2(s,u);var _=s.isub(u);return _.cmpn(0)<0&&_.iadd(this.m),_},L.prototype.shl=function(s,u){return this._verify1(s),this.imod(s.ushln(u))},L.prototype.imul=function(s,u){return this._verify2(s,u),this.imod(s.imul(u))},L.prototype.mul=function(s,u){return this._verify2(s,u),this.imod(s.mul(u))},L.prototype.isqr=function(s){return this.imul(s,s.clone())},L.prototype.sqr=function(s){return this.mul(s,s)},L.prototype.sqrt=function(s){if(s.isZero())return s.clone();var u=this.m.andln(3);if(e(u%2===1),u===3){var _=this.m.add(new n(1)).iushrn(2);return this.pow(s,_)}for(var p=this.m.subn(1),g=0;!p.isZero()&&p.andln(1)===0;)g++,p.iushrn(1);e(!p.isZero());var v=new n(1).toRed(this),C=v.redNeg(),m=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new n(2*c*c).toRed(this);this.pow(c,m).cmp(C)!==0;)c.redIAdd(C);for(var y=this.pow(c,p),A=this.pow(s,p.addn(1).iushrn(1)),x=this.pow(s,p),O=g;x.cmp(v)!==0;){for(var j=x,U=0;j.cmp(v)!==0;U++)j=j.redSqr();e(U<O);var V=this.pow(y,new n(1).iushln(O-U-1));A=A.redMul(V),y=V.redSqr(),x=x.redMul(y),O=U}return A},L.prototype.invm=function(s){var u=s._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},L.prototype.pow=function(s,u){if(u.isZero())return new n(1).toRed(this);if(u.cmpn(1)===0)return s.clone();var _=4,p=new Array(1<<_);p[0]=new n(1).toRed(this),p[1]=s;for(var g=2;g<p.length;g++)p[g]=this.mul(p[g-1],s);var v=p[0],C=0,m=0,c=u.bitLength()%26;for(c===0&&(c=26),g=u.length-1;g>=0;g--){for(var y=u.words[g],A=c-1;A>=0;A--){var x=y>>A&1;if(v!==p[0]&&(v=this.sqr(v)),x===0&&C===0){m=0;continue}C<<=1,C|=x,m++,!(m!==_&&(g!==0||A!==0))&&(v=this.mul(v,p[C]),m=0,C=0)}c=26}return v},L.prototype.convertTo=function(s){var u=s.umod(this.m);return u===s?u.clone():u},L.prototype.convertFrom=function(s){var u=s.clone();return u.red=null,u},n.mont=function(s){return new Bt(s)};function Bt(w){L.call(this,w),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new n(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)}i(Bt,L),Bt.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},Bt.prototype.convertFrom=function(s){var u=this.imod(s.mul(this.rinv));return u.red=null,u},Bt.prototype.imul=function(s,u){if(s.isZero()||u.isZero())return s.words[0]=0,s.length=1,s;var _=s.imul(u),p=_.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=_.isub(p).iushrn(this.shift),v=g;return g.cmp(this.m)>=0?v=g.isub(this.m):g.cmpn(0)<0&&(v=g.iadd(this.m)),v._forceRed(this)},Bt.prototype.mul=function(s,u){if(s.isZero()||u.isZero())return new n(0)._forceRed(this);var _=s.mul(u),p=_.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=_.isub(p).iushrn(this.shift),v=g;return g.cmp(this.m)>=0?v=g.isub(this.m):g.cmpn(0)<0&&(v=g.iadd(this.m)),v._forceRed(this)},Bt.prototype.invm=function(s){var u=this.imod(s._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof an>"u"||an,ho)});import{SdkWrapper as Ca}from"@cetusprotocol/common-sdk";import{normalizeSuiObjectId as on}from"@mysten/sui/utils";import{CACHE_TIME_24H as Ht,CACHE_TIME_5MIN as jr,CachedContent as Nr,DETAILS_KEYS as Ve,extractStructTagFromType as rn,fixCoinType as qr,getFutureTime as fo,getObjectFields as ii,getObjectId as sn,getObjectPreviousTransactionDigest as Dr,getObjectType as Lr,getPackagerConfigs as le,normalizeCoinType as _o}from"@cetusprotocol/common-sdk";var zn="3.7.8",kr=zn,Ce=typeof Buffer=="function",Vn=typeof TextDecoder=="function"?new TextDecoder:void 0,Kn=typeof TextEncoder=="function"?new TextEncoder:void 0,Mr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",$e=Array.prototype.slice.call(Mr),Xe=(o=>{let t={};return o.forEach((e,i)=>t[e]=i),t})($e),Tr=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Ot=String.fromCharCode.bind(String),Hn=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):o=>new Uint8Array(Array.prototype.slice.call(o,0)),Gn=o=>o.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),Qn=o=>o.replace(/[^A-Za-z0-9\+\/]/g,""),Jn=o=>{let t,e,i,n,r="",a=o.length%3;for(let l=0;l<o.length;){if((e=o.charCodeAt(l++))>255||(i=o.charCodeAt(l++))>255||(n=o.charCodeAt(l++))>255)throw new TypeError("invalid character found");t=e<<16|i<<8|n,r+=$e[t>>18&63]+$e[t>>12&63]+$e[t>>6&63]+$e[t&63]}return a?r.slice(0,a-3)+"===".substring(a):r},tn=typeof btoa=="function"?o=>btoa(o):Ce?o=>Buffer.from(o,"binary").toString("base64"):Jn,Xi=Ce?o=>Buffer.from(o).toString("base64"):o=>{let e=[];for(let i=0,n=o.length;i<n;i+=4096)e.push(Ot.apply(null,o.subarray(i,i+4096)));return tn(e.join(""))},Ye=(o,t=!1)=>t?Gn(Xi(o)):Xi(o),Ar=o=>{if(o.length<2){var t=o.charCodeAt(0);return t<128?o:t<2048?Ot(192|t>>>6)+Ot(128|t&63):Ot(224|t>>>12&15)+Ot(128|t>>>6&63)+Ot(128|t&63)}else{var t=65536+(o.charCodeAt(0)-55296)*1024+(o.charCodeAt(1)-56320);return Ot(240|t>>>18&7)+Ot(128|t>>>12&63)+Ot(128|t>>>6&63)+Ot(128|t&63)}},Sr=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,Xn=o=>o.replace(Sr,Ar),Wn=Ce?o=>Buffer.from(o,"utf8").toString("base64"):Kn?o=>Xi(Kn.encode(o)):o=>tn(Xn(o)),Pe=(o,t=!1)=>t?Gn(Wn(o)):Wn(o),Zn=o=>Pe(o,!0),xr=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,Ir=o=>{switch(o.length){case 4:var t=(7&o.charCodeAt(0))<<18|(63&o.charCodeAt(1))<<12|(63&o.charCodeAt(2))<<6|63&o.charCodeAt(3),e=t-65536;return Ot((e>>>10)+55296)+Ot((e&1023)+56320);case 3:return Ot((15&o.charCodeAt(0))<<12|(63&o.charCodeAt(1))<<6|63&o.charCodeAt(2));default:return Ot((31&o.charCodeAt(0))<<6|63&o.charCodeAt(1))}},Yn=o=>o.replace(xr,Ir),to=o=>{if(o=o.replace(/\s+/g,""),!Tr.test(o))throw new TypeError("malformed base64.");o+="==".slice(2-(o.length&3));let t,e,i,n=[];for(let r=0;r<o.length;)t=Xe[o.charAt(r++)]<<18|Xe[o.charAt(r++)]<<12|(e=Xe[o.charAt(r++)])<<6|(i=Xe[o.charAt(r++)]),e===64?n.push(Ot(t>>16&255)):i===64?n.push(Ot(t>>16&255,t>>8&255)):n.push(Ot(t>>16&255,t>>8&255,t&255));return n.join("")},en=typeof atob=="function"?o=>atob(Qn(o)):Ce?o=>Buffer.from(o,"base64").toString("binary"):to,eo=Ce?o=>Hn(Buffer.from(o,"base64")):o=>Hn(en(o).split("").map(t=>t.charCodeAt(0))),io=o=>eo(no(o)),Or=Ce?o=>Buffer.from(o,"base64").toString("utf8"):Vn?o=>Vn.decode(eo(o)):o=>Yn(en(o)),no=o=>Qn(o.replace(/[-_]/g,t=>t=="-"?"+":"/")),Yi=o=>Or(no(o)),Er=o=>{if(typeof o!="string")return!1;let t=o.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(t)||!/[^\s0-9a-zA-Z\-_]/.test(t)},oo=o=>({value:o,enumerable:!1,writable:!0,configurable:!0}),ro=function(){let o=(t,e)=>Object.defineProperty(String.prototype,t,oo(e));o("fromBase64",function(){return Yi(this)}),o("toBase64",function(t){return Pe(this,t)}),o("toBase64URI",function(){return Pe(this,!0)}),o("toBase64URL",function(){return Pe(this,!0)}),o("toUint8Array",function(){return io(this)})},so=function(){let o=(t,e)=>Object.defineProperty(Uint8Array.prototype,t,oo(e));o("toBase64",function(t){return Ye(this,t)}),o("toBase64URI",function(){return Ye(this,!0)}),o("toBase64URL",function(){return Ye(this,!0)})},Rr=()=>{ro(),so()},ti={version:zn,VERSION:kr,atob:en,atobPolyfill:to,btoa:tn,btoaPolyfill:Jn,fromBase64:Yi,toBase64:Pe,encode:Pe,encodeURI:Zn,encodeURL:Zn,utob:Xn,btou:Yn,decode:Yi,isValid:Er,fromUint8Array:Ye,toUint8Array:io,extendString:ro,extendUint8Array:so,extendBuiltins:Rr};import{BaseError as Fr}from"@cetusprotocol/common-sdk";var ao=(f=>(f.InvalidSqrtPriceLimitDirection="InvalidSqrtPriceLimitDirection",f.ZeroTradableAmount="ZeroTradableAmount",f.AmountOutBelowMinimum="AmountOutBelowMinimum",f.AmountInAboveMaximum="AmountInAboveMaximum",f.NextTickNotFound="NextTickNotFound",f.TickArraySequenceInvalid="TickArraySequenceInvalid",f.TickArrayCrossingAboveMax="TickArrayCrossingAboveMax",f.TickArrayIndexNotInitialized="TickArrayIndexNotInitialized",f.ParamsLengthNotEqual="ParamsLengthNotEqual",f))(ao||{}),ei=(r=>(r.InvalidTickEvent="InvalidTickEvent",r.InvalidPositionObject="InvalidPositionObject",r.InvalidPositionRewardObject="InvalidPositionRewardObject",r.InvalidParams="InvalidParams",r.FetchError="FetchError",r))(ei||{}),Ue=(f=>(f.InvalidCoinTypeSequence="InvalidCoinTypeSequence",f.InvalidTickIndex="InvalidTickIndex",f.InvalidPoolObject="InvalidPoolObject",f.InvalidTickObjectId="InvalidTickObjectId",f.InvalidTickObject="InvalidTickObject",f.InvalidTickFields="InvalidTickFields",f.PoolsNotFound="PoolsNotFound",f.StatsPoolsUrlNotSet="StatsPoolsUrlNotSet",f.FetchError="FetchError",f))(Ue||{}),co=(e=>(e.ClmmVestNotSet="ClmmVestNotSet",e.ClmmVestFetchError="ClmmVestFetchError",e))(co||{}),lo=(e=>(e.NotFoundPartnerObject="NotFoundPartnerObject",e.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",e))(lo||{}),Me=(i=>(i.InvalidConfig="InvalidConfig",i.InvalidConfigHandle="InvalidConfigHandle",i.InvalidSimulateAccount="InvalidSimulateAccount",i))(Me||{}),nn=(a=>(a.InvalidSendAddress="InvalidSendAddress",a.InvalidRecipientAddress="InvalidRecipientAddress",a.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",a.InsufficientBalance="InsufficientBalance",a.InvalidTarget="InvalidTarget",a.InvalidTransactionBuilder="InvalidTransactionBuilder",a))(nn||{}),Br=(a=>(a.InvalidCoin="InvalidCoin",a.NotFoundPath="NotFoundPath",a.NoDowngradeNeedParams="NoDowngradeNeedParams",a.InvalidSwapCountUrl="InvalidSwapCountUrl",a.InvalidTransactionBuilder="InvalidTransactionBuilder",a.InvalidServerResponse="InvalidServerResponse",a))(Br||{}),uo=(t=>(t.InvalidType="InvalidType",t))(uo||{}),ke=class extends Fr{constructor(t,e,i){super(t,e||"UnknownError",i)}static isVaultsErrorCode(t,e){return this.isErrorCode(t,e)}},jt=(o,t,e)=>{throw new ke(t.message,o,e)},F=(o,t,e)=>{throw new ke(t,o,e)};var ni=class{constructor(t){this._cache={};this._sdk=t}get sdk(){return this._sdk}setTokenListCache(t){let{coin_list_handle:e}=le(this.sdk.sdkOptions.cetus_config),i=`${e}_getCoinConfigs`,n=this.getCache(i),r=n?[...n,...t]:t;this.updateCache(i,r)}async getTokenListByCoinTypes(t){let e={},{coin_list_handle:i}=le(this.sdk.sdkOptions.cetus_config),n=`${i}_getCoinConfigs`,r=this.getCache(n);if(r!==void 0){let l=r;for(let d of t)for(let f of l)if(_o(d)===_o(f.address)){e[d]=f;continue}}let a=t.filter(l=>e[l]===void 0);for(let l of a){let d=`${l}_metadata`,f=this.getCache(d);if(f!==void 0)e[l]=f;else{let h=await this._sdk.FullClient.getCoinMetadata({coinType:l});if(h){let b={id:h.id,pyth_id:"",name:h.name,symbol:h.symbol,official_symbol:h.symbol,coingecko_id:"",decimals:h.decimals,project_url:"",logo_url:h.iconUrl,address:l};e[l]=b,this.updateCache(d,b,Ht)}else console.log(`not found ${l}`)}}return e}async getCoinConfigs(t=!1,e=!0){let{coin_list_handle:i}=le(this.sdk.sdkOptions.cetus_config),n=`${i}_getCoinConfigs`,r=this.getCache(n,t);if(r)return r;let l=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(h=>h.objectId),d=await this._sdk.FullClient.batchGetObjects(l,{showContent:!0}),f=[];return d.forEach(h=>{(h.error!=null||h.data?.content?.dataType!=="moveObject")&&F("FetchError",`when getCoinConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[Ve.METHOD_NAME]:"getCoinConfigs"});let b=this.buildCoinConfig(h,e);this.updateCache(`${i}_${b.address}_getCoinConfig`,b,Ht),f.push({...b})}),this.updateCache(n,f,Ht),f}async getCoinConfig(t,e=!1,i=!0){let{coin_list_handle:n}=le(this.sdk.sdkOptions.cetus_config),r=`${n}_${t}_getCoinConfig`,a=this.getCache(r,e);if(a)return a;let l=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"0x1::type_name::TypeName",value:{name:qr(t)}}});(l.error!=null||l.data?.content?.dataType!=="moveObject")&&F("FetchError",`when getCoinConfig get object error: ${l.error}, please check the rpc and contracts address config.`,{[Ve.METHOD_NAME]:"getCoinConfig"});let d=this.buildCoinConfig(l,i);return this.updateCache(r,d,Ht),d}buildCoinConfig(t,e=!0){let i=ii(t);i=i.value.fields;let n={...i};return n.id=sn(t),n.address=rn(i.coin_type.fields.name).full_address,i.pyth_id&&(n.pyth_id=on(i.pyth_id)),this.transformExtensions(n,i.extension_fields.fields.contents,e),delete n.coin_type,n}async getClmmPoolConfigs(t=!1,e=!0){let{clmm_pools_handle:i}=le(this.sdk.sdkOptions.cetus_config),n=`${i}_getClmmPoolConfigs`,r=this.getCache(n,t);if(r)return r;let l=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(h=>h.objectId),d=await this._sdk.FullClient.batchGetObjects(l,{showContent:!0}),f=[];return d.forEach(h=>{(h.error!=null||h.data?.content?.dataType!=="moveObject")&&F("FetchError",`when getClmmPoolsConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[Ve.METHOD_NAME]:"getClmmPoolConfigs"});let b=this.buildClmmPoolConfig(h,e);this.updateCache(`${b.pool_address}_getClmmPoolConfig`,b,Ht),f.push({...b})}),this.updateCache(n,f,Ht),f}async getClmmPoolConfig(t,e=!1,i=!0){let{clmm_pools_handle:n}=le(this.sdk.sdkOptions.cetus_config),r=`${t}_getClmmPoolConfig`,a=this.getCache(r,e);if(a)return a;let l=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"address",value:t}}),d=this.buildClmmPoolConfig(l,i);return this.updateCache(r,d,Ht),d}buildClmmPoolConfig(t,e=!0){let i=ii(t);i=i.value.fields;let n={...i};return n.id=sn(t),n.pool_address=on(i.pool_address),this.transformExtensions(n,i.extension_fields.fields.contents,e),n}async getLaunchpadPoolConfigs(t=!1,e=!0){let{launchpad_pools_handle:i}=le(this.sdk.sdkOptions.cetus_config),n=`${i}_getLaunchpadPoolConfigs`,r=this.getCache(n,t);if(r)return r;let l=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(h=>h.objectId),d=await this._sdk.FullClient.batchGetObjects(l,{showContent:!0}),f=[];return d.forEach(h=>{(h.error!=null||h.data?.content?.dataType!=="moveObject")&&F("FetchError",`when getCoinConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[Ve.METHOD_NAME]:"getLaunchpadPoolConfigs"});let b=this.buildLaunchpadPoolConfig(h,e);this.updateCache(`${b.pool_address}_getLaunchpadPoolConfig`,b,Ht),f.push({...b})}),this.updateCache(n,f,Ht),f}async getLaunchpadPoolConfig(t,e=!1,i=!0){let{launchpad_pools_handle:n}=le(this.sdk.sdkOptions.cetus_config),r=`${t}_getLaunchpadPoolConfig`,a=this.getCache(r,e);if(a)return a;let l=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"address",value:t}}),d=this.buildLaunchpadPoolConfig(l,i);return this.updateCache(r,d,Ht),d}buildLaunchpadPoolConfig(t,e=!0){let i=ii(t);i=i.value.fields;let n={...i};n.id=sn(t),n.pool_address=on(i.pool_address),this.transformExtensions(n,i.extension_fields.fields.contents,e);let r=[];i.social_media.fields.contents.forEach(a=>{r.push({name:a.fields.value.fields.name,link:a.fields.value.fields.link})}),n.social_media=r;try{n.regulation=decodeURIComponent(ti.decode(n.regulation).replace(/%/g,"%25"))}catch{n.regulation=ti.decode(n.regulation)}return n}transformExtensions(t,e,i=!0){let n=[];for(let r of e){let{key:a}=r.fields,{value:l}=r.fields;if(a==="labels")try{let d=decodeURIComponent(ti.decode(l));try{l=JSON.parse(d)}catch{l=d}}catch{}i&&(t[a]=l),n.push({key:a,value:l})}delete t.extension_fields,i||(t.extensions=n)}async getCetusConfig(t=!1){let e=this._sdk.sdkOptions.cetus_config.package_id,i=`${e}_getCetusConfig`,n=this.getCache(i,t);if(n!==void 0)return n;let r=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),a=Dr(r),l=await this._sdk.FullClient.queryEventsByPage({Transaction:a}),d={coin_list_id:"",launchpad_pools_id:"",clmm_pools_id:"",admin_cap_id:"",global_config_id:"",coin_list_handle:"",launchpad_pools_handle:"",clmm_pools_handle:""};if(l.data.length>0)for(let f of l.data)switch(rn(f.type).name){case"InitCoinListEvent":d.coin_list_id=f.parsedJson.coin_list_id;break;case"InitLaunchpadPoolsEvent":d.launchpad_pools_id=f.parsedJson.launchpad_pools_id;break;case"InitClmmPoolsEvent":d.clmm_pools_id=f.parsedJson.pools_id;break;case"InitConfigEvent":d.global_config_id=f.parsedJson.global_config_id,d.admin_cap_id=f.parsedJson.admin_cap_id;break;default:break}return d=await this.getCetusConfigHandle(d),d.clmm_pools_id.length>0&&this.updateCache(i,d,Ht),d}async getCetusConfigHandle(t){let e=[t.clmm_pools_id,t.coin_list_id,t.launchpad_pools_id];return(await this._sdk.FullClient.multiGetObjects({ids:e,options:{showContent:!0}})).forEach(n=>{(n.error!=null||n.data?.content?.dataType!=="moveObject")&&F("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${n.error}, please check the rpc and contracts address config.`,{[Ve.METHOD_NAME]:"getCetusConfigHandle"});let r=ii(n),a=Lr(n);switch(rn(a).name){case"ClmmPools":t.clmm_pools_handle=r.pools.fields.id.id;break;case"CoinList":t.coin_list_handle=r.coins.fields.id.id;break;case"LaunchpadPools":t.launchpad_pools_handle=r.pools.fields.id.id;break;default:break}}),t}updateCache(t,e,i=jr){let n=this._cache[t];n?(n.overdue_time=fo(i),n.value=e):n=new Nr(e,fo(i)),this._cache[t]=n}getCache(t,e=!1){try{let i=this._cache[t];if(!i)return;if(e||!i.isValid()){delete this._cache[t];return}return i.value}catch(i){console.error(`Error accessing cache for key ${t}:`,i);return}}};var sr=se(Gt());import{SuiClient as oa}from"@mysten/sui/client";import{Transaction as Ie}from"@mysten/sui/transactions";import{normalizeSuiAddress as Oe}from"@mysten/sui/utils";var po="position_liquidity_snapshot",mo=(i=>(i.Deleted="Deleted",i.Exists="Exists",i.NotExists="NotExists",i))(mo||{}),go=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent","AddLiquidityV2Event","RemoveLiquidityV2Event"];var Ft=se(Gt());import{asUintN as Do,FEE_RATE_DENOMINATOR as pi,getDeltaDownFromOutput as Lo,getDeltaUpFromInput as $o,getNextSqrtPriceFromInput as Us,getNextSqrtPriceFromOutput as Vs,MathUtil as ge,ZERO as Vt}from"@cetusprotocol/common-sdk";var qo=se(Gt());import{Transaction as mn}from"@mysten/sui/transactions";import{adjustForSlippage as Ns,CLOCK_ADDRESS as hi,CoinAssist as Lt,getPackagerConfigs as No,MathUtil as gn,MAX_SQRT_PRICE as qs,MIN_SQRT_PRICE as Ds,U64_MAX as Ls,ZERO as $s}from"@cetusprotocol/common-sdk";var cn="partner",oi="pool_script",Qt="pool_script_v2",ri="pool_script_v3",me="router",bo="router_with_partner",Jt="fetcher_script",$a="expect_swap",yo="utils",Ua="custodian_v2",Va="clob_v2",Ka="endpoints_v2",Ha=o=>{if(typeof o=="string"&&o.startsWith("0x"))return"object";if(typeof o=="number"||typeof o=="bigint")return"u64";if(typeof o=="boolean")return"bool";throw new ke(`Unknown type for value: ${o}`,"InvalidType")};var jo=se(Gt());import{Transaction as hn}from"@mysten/sui/transactions";import{asUintN as Fo,ClmmPoolUtil as Fs,CLOCK_ADDRESS as Bo,CoinAssist as Dt,getPackagerConfigs as Bs,normalizeCoinType as pn}from"@cetusprotocol/common-sdk";var Te=9e15,_e=1e9,ln="0123456789abcdef",ci="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",li="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",un={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Te,maxE:Te,crypto:!1},Co,ae,B=!0,di="[DecimalError] ",fe=di+"Invalid argument: ",ko=di+"Precision limit exceeded",Mo=di+"crypto unavailable",To="[object Decimal]",Rt=Math.floor,It=Math.pow,$r=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Ur=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Vr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ao=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Wt=1e7,R=7,Kr=9007199254740991,Hr=ci.length-1,dn=li.length-1,M={toStringTag:To};M.absoluteValue=M.abs=function(){var o=new this.constructor(this);return o.s<0&&(o.s=1),E(o)};M.ceil=function(){return E(new this.constructor(this),this.e+1,2)};M.clampedTo=M.clamp=function(o,t){var e,i=this,n=i.constructor;if(o=new n(o),t=new n(t),!o.s||!t.s)return new n(NaN);if(o.gt(t))throw Error(fe+t);return e=i.cmp(o),e<0?o:i.cmp(t)>0?t:new n(i)};M.comparedTo=M.cmp=function(o){var t,e,i,n,r=this,a=r.d,l=(o=new r.constructor(o)).d,d=r.s,f=o.s;if(!a||!l)return!d||!f?NaN:d!==f?d:a===l?0:!a^d<0?1:-1;if(!a[0]||!l[0])return a[0]?d:l[0]?-f:0;if(d!==f)return d;if(r.e!==o.e)return r.e>o.e^d<0?1:-1;for(i=a.length,n=l.length,t=0,e=i<n?i:n;t<e;++t)if(a[t]!==l[t])return a[t]>l[t]^d<0?1:-1;return i===n?0:i>n^d<0?1:-1};M.cosine=M.cos=function(){var o,t,e=this,i=e.constructor;return e.d?e.d[0]?(o=i.precision,t=i.rounding,i.precision=o+Math.max(e.e,e.sd())+R,i.rounding=1,e=Wr(i,Eo(i,e)),i.precision=o,i.rounding=t,E(ae==2||ae==3?e.neg():e,o,t,!0)):new i(1):new i(NaN)};M.cubeRoot=M.cbrt=function(){var o,t,e,i,n,r,a,l,d,f,h=this,b=h.constructor;if(!h.isFinite()||h.isZero())return new b(h);for(B=!1,r=h.s*It(h.s*h,1/3),!r||Math.abs(r)==1/0?(e=Et(h.d),o=h.e,(r=(o-e.length+1)%3)&&(e+=r==1||r==-2?"0":"00"),r=It(e,1/3),o=Rt((o+1)/3)-(o%3==(o<0?-1:2)),r==1/0?e="5e"+o:(e=r.toExponential(),e=e.slice(0,e.indexOf("e")+1)+o),i=new b(e),i.s=h.s):i=new b(r.toString()),a=(o=b.precision)+3;;)if(l=i,d=l.times(l).times(l),f=d.plus(h),i=H(f.plus(h).times(l),f.plus(d),a+2,1),Et(l.d).slice(0,a)===(e=Et(i.d)).slice(0,a))if(e=e.slice(a-3,a+1),e=="9999"||!n&&e=="4999"){if(!n&&(E(l,o+1,0),l.times(l).times(l).eq(h))){i=l;break}a+=4,n=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(E(i,o+1,1),t=!i.times(i).times(i).eq(h));break}return B=!0,E(i,o,b.rounding,t)};M.decimalPlaces=M.dp=function(){var o,t=this.d,e=NaN;if(t){if(o=t.length-1,e=(o-Rt(this.e/R))*R,o=t[o],o)for(;o%10==0;o/=10)e--;e<0&&(e=0)}return e};M.dividedBy=M.div=function(o){return H(this,new this.constructor(o))};M.dividedToIntegerBy=M.divToInt=function(o){var t=this,e=t.constructor;return E(H(t,new e(o),0,1,1),e.precision,e.rounding)};M.equals=M.eq=function(o){return this.cmp(o)===0};M.floor=function(){return E(new this.constructor(this),this.e+1,3)};M.greaterThan=M.gt=function(o){return this.cmp(o)>0};M.greaterThanOrEqualTo=M.gte=function(o){var t=this.cmp(o);return t==1||t===0};M.hyperbolicCosine=M.cosh=function(){var o,t,e,i,n,r=this,a=r.constructor,l=new a(1);if(!r.isFinite())return new a(r.s?1/0:NaN);if(r.isZero())return l;e=a.precision,i=a.rounding,a.precision=e+Math.max(r.e,r.sd())+4,a.rounding=1,n=r.d.length,n<32?(o=Math.ceil(n/3),t=(1/_i(4,o)).toString()):(o=16,t="2.3283064365386962890625e-10"),r=Ae(a,1,r.times(t),new a(1),!0);for(var d,f=o,h=new a(8);f--;)d=r.times(r),r=l.minus(d.times(h.minus(d.times(h))));return E(r,a.precision=e,a.rounding=i,!0)};M.hyperbolicSine=M.sinh=function(){var o,t,e,i,n=this,r=n.constructor;if(!n.isFinite()||n.isZero())return new r(n);if(t=r.precision,e=r.rounding,r.precision=t+Math.max(n.e,n.sd())+4,r.rounding=1,i=n.d.length,i<3)n=Ae(r,2,n,n,!0);else{o=1.4*Math.sqrt(i),o=o>16?16:o|0,n=n.times(1/_i(5,o)),n=Ae(r,2,n,n,!0);for(var a,l=new r(5),d=new r(16),f=new r(20);o--;)a=n.times(n),n=n.times(l.plus(a.times(d.times(a).plus(f))))}return r.precision=t,r.rounding=e,E(n,t,e,!0)};M.hyperbolicTangent=M.tanh=function(){var o,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(o=i.precision,t=i.rounding,i.precision=o+7,i.rounding=1,H(e.sinh(),e.cosh(),i.precision=o,i.rounding=t)):new i(e.s)};M.inverseCosine=M.acos=function(){var o=this,t=o.constructor,e=o.abs().cmp(1),i=t.precision,n=t.rounding;return e!==-1?e===0?o.isNeg()?Xt(t,i,n):new t(0):new t(NaN):o.isZero()?Xt(t,i+4,n).times(.5):(t.precision=i+6,t.rounding=1,o=new t(1).minus(o).div(o.plus(1)).sqrt().atan(),t.precision=i,t.rounding=n,o.times(2))};M.inverseHyperbolicCosine=M.acosh=function(){var o,t,e=this,i=e.constructor;return e.lte(1)?new i(e.eq(1)?0:NaN):e.isFinite()?(o=i.precision,t=i.rounding,i.precision=o+Math.max(Math.abs(e.e),e.sd())+4,i.rounding=1,B=!1,e=e.times(e).minus(1).sqrt().plus(e),B=!0,i.precision=o,i.rounding=t,e.ln()):new i(e)};M.inverseHyperbolicSine=M.asinh=function(){var o,t,e=this,i=e.constructor;return!e.isFinite()||e.isZero()?new i(e):(o=i.precision,t=i.rounding,i.precision=o+2*Math.max(Math.abs(e.e),e.sd())+6,i.rounding=1,B=!1,e=e.times(e).plus(1).sqrt().plus(e),B=!0,i.precision=o,i.rounding=t,e.ln())};M.inverseHyperbolicTangent=M.atanh=function(){var o,t,e,i,n=this,r=n.constructor;return n.isFinite()?n.e>=0?new r(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(o=r.precision,t=r.rounding,i=n.sd(),Math.max(i,o)<2*-n.e-1?E(new r(n),o,t,!0):(r.precision=e=i-n.e,n=H(n.plus(1),new r(1).minus(n),e+o,1),r.precision=o+4,r.rounding=1,n=n.ln(),r.precision=o,r.rounding=t,n.times(.5))):new r(NaN)};M.inverseSine=M.asin=function(){var o,t,e,i,n=this,r=n.constructor;return n.isZero()?new r(n):(t=n.abs().cmp(1),e=r.precision,i=r.rounding,t!==-1?t===0?(o=Xt(r,e+4,i).times(.5),o.s=n.s,o):new r(NaN):(r.precision=e+6,r.rounding=1,n=n.div(new r(1).minus(n.times(n)).sqrt().plus(1)).atan(),r.precision=e,r.rounding=i,n.times(2)))};M.inverseTangent=M.atan=function(){var o,t,e,i,n,r,a,l,d,f=this,h=f.constructor,b=h.precision,P=h.rounding;if(f.isFinite()){if(f.isZero())return new h(f);if(f.abs().eq(1)&&b+4<=dn)return a=Xt(h,b+4,P).times(.25),a.s=f.s,a}else{if(!f.s)return new h(NaN);if(b+4<=dn)return a=Xt(h,b+4,P).times(.5),a.s=f.s,a}for(h.precision=l=b+10,h.rounding=1,e=Math.min(28,l/R+2|0),o=e;o;--o)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(B=!1,t=Math.ceil(l/R),i=1,d=f.times(f),a=new h(f),n=f;o!==-1;)if(n=n.times(d),r=a.minus(n.div(i+=2)),n=n.times(d),a=r.plus(n.div(i+=2)),a.d[t]!==void 0)for(o=t;a.d[o]===r.d[o]&&o--;);return e&&(a=a.times(2<<e-1)),B=!0,E(a,h.precision=b,h.rounding=P,!0)};M.isFinite=function(){return!!this.d};M.isInteger=M.isInt=function(){return!!this.d&&Rt(this.e/R)>this.d.length-2};M.isNaN=function(){return!this.s};M.isNegative=M.isNeg=function(){return this.s<0};M.isPositive=M.isPos=function(){return this.s>0};M.isZero=function(){return!!this.d&&this.d[0]===0};M.lessThan=M.lt=function(o){return this.cmp(o)<0};M.lessThanOrEqualTo=M.lte=function(o){return this.cmp(o)<1};M.logarithm=M.log=function(o){var t,e,i,n,r,a,l,d,f=this,h=f.constructor,b=h.precision,P=h.rounding,k=5;if(o==null)o=new h(10),t=!0;else{if(o=new h(o),e=o.d,o.s<0||!e||!e[0]||o.eq(1))return new h(NaN);t=o.eq(10)}if(e=f.d,f.s<0||!e||!e[0]||f.eq(1))return new h(e&&!e[0]?-1/0:f.s!=1?NaN:e?0:1/0);if(t)if(e.length>1)r=!0;else{for(n=e[0];n%10===0;)n/=10;r=n!==1}if(B=!1,l=b+k,a=de(f,l),i=t?ui(h,l+10):de(o,l),d=H(a,i,l,1),Ke(d.d,n=b,P))do if(l+=10,a=de(f,l),i=t?ui(h,l+10):de(o,l),d=H(a,i,l,1),!r){+Et(d.d).slice(n+1,n+15)+1==1e14&&(d=E(d,b+1,0));break}while(Ke(d.d,n+=10,P));return B=!0,E(d,b,P)};M.minus=M.sub=function(o){var t,e,i,n,r,a,l,d,f,h,b,P,k=this,T=k.constructor;if(o=new T(o),!k.d||!o.d)return!k.s||!o.s?o=new T(NaN):k.d?o.s=-o.s:o=new T(o.d||k.s!==o.s?k:NaN),o;if(k.s!=o.s)return o.s=-o.s,k.plus(o);if(f=k.d,P=o.d,l=T.precision,d=T.rounding,!f[0]||!P[0]){if(P[0])o.s=-o.s;else if(f[0])o=new T(k);else return new T(d===3?-0:0);return B?E(o,l,d):o}if(e=Rt(o.e/R),h=Rt(k.e/R),f=f.slice(),r=h-e,r){for(b=r<0,b?(t=f,r=-r,a=P.length):(t=P,e=h,a=f.length),i=Math.max(Math.ceil(l/R),a)+2,r>i&&(r=i,t.length=1),t.reverse(),i=r;i--;)t.push(0);t.reverse()}else{for(i=f.length,a=P.length,b=i<a,b&&(a=i),i=0;i<a;i++)if(f[i]!=P[i]){b=f[i]<P[i];break}r=0}for(b&&(t=f,f=P,P=t,o.s=-o.s),a=f.length,i=P.length-a;i>0;--i)f[a++]=0;for(i=P.length;i>r;){if(f[--i]<P[i]){for(n=i;n&&f[--n]===0;)f[n]=Wt-1;--f[n],f[i]+=Wt}f[i]-=P[i]}for(;f[--a]===0;)f.pop();for(;f[0]===0;f.shift())--e;return f[0]?(o.d=f,o.e=fi(f,e),B?E(o,l,d):o):new T(d===3?-0:0)};M.modulo=M.mod=function(o){var t,e=this,i=e.constructor;return o=new i(o),!e.d||!o.s||o.d&&!o.d[0]?new i(NaN):!o.d||e.d&&!e.d[0]?E(new i(e),i.precision,i.rounding):(B=!1,i.modulo==9?(t=H(e,o.abs(),0,3,1),t.s*=o.s):t=H(e,o,0,i.modulo,1),t=t.times(o),B=!0,e.minus(t))};M.naturalExponential=M.exp=function(){return fn(this)};M.naturalLogarithm=M.ln=function(){return de(this)};M.negated=M.neg=function(){var o=new this.constructor(this);return o.s=-o.s,E(o)};M.plus=M.add=function(o){var t,e,i,n,r,a,l,d,f,h,b=this,P=b.constructor;if(o=new P(o),!b.d||!o.d)return!b.s||!o.s?o=new P(NaN):b.d||(o=new P(o.d||b.s===o.s?b:NaN)),o;if(b.s!=o.s)return o.s=-o.s,b.minus(o);if(f=b.d,h=o.d,l=P.precision,d=P.rounding,!f[0]||!h[0])return h[0]||(o=new P(b)),B?E(o,l,d):o;if(r=Rt(b.e/R),i=Rt(o.e/R),f=f.slice(),n=r-i,n){for(n<0?(e=f,n=-n,a=h.length):(e=h,i=r,a=f.length),r=Math.ceil(l/R),a=r>a?r+1:a+1,n>a&&(n=a,e.length=1),e.reverse();n--;)e.push(0);e.reverse()}for(a=f.length,n=h.length,a-n<0&&(n=a,e=h,h=f,f=e),t=0;n;)t=(f[--n]=f[n]+h[n]+t)/Wt|0,f[n]%=Wt;for(t&&(f.unshift(t),++i),a=f.length;f[--a]==0;)f.pop();return o.d=f,o.e=fi(f,i),B?E(o,l,d):o};M.precision=M.sd=function(o){var t,e=this;if(o!==void 0&&o!==!!o&&o!==1&&o!==0)throw Error(fe+o);return e.d?(t=So(e.d),o&&e.e+1>t&&(t=e.e+1)):t=NaN,t};M.round=function(){var o=this,t=o.constructor;return E(new t(o),o.e+1,t.rounding)};M.sine=M.sin=function(){var o,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(o=i.precision,t=i.rounding,i.precision=o+Math.max(e.e,e.sd())+R,i.rounding=1,e=zr(i,Eo(i,e)),i.precision=o,i.rounding=t,E(ae>2?e.neg():e,o,t,!0)):new i(NaN)};M.squareRoot=M.sqrt=function(){var o,t,e,i,n,r,a=this,l=a.d,d=a.e,f=a.s,h=a.constructor;if(f!==1||!l||!l[0])return new h(!f||f<0&&(!l||l[0])?NaN:l?a:1/0);for(B=!1,f=Math.sqrt(+a),f==0||f==1/0?(t=Et(l),(t.length+d)%2==0&&(t+="0"),f=Math.sqrt(t),d=Rt((d+1)/2)-(d<0||d%2),f==1/0?t="5e"+d:(t=f.toExponential(),t=t.slice(0,t.indexOf("e")+1)+d),i=new h(t)):i=new h(f.toString()),e=(d=h.precision)+3;;)if(r=i,i=r.plus(H(a,r,e+2,1)).times(.5),Et(r.d).slice(0,e)===(t=Et(i.d)).slice(0,e))if(t=t.slice(e-3,e+1),t=="9999"||!n&&t=="4999"){if(!n&&(E(r,d+1,0),r.times(r).eq(a))){i=r;break}e+=4,n=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(E(i,d+1,1),o=!i.times(i).eq(a));break}return B=!0,E(i,d,h.rounding,o)};M.tangent=M.tan=function(){var o,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(o=i.precision,t=i.rounding,i.precision=o+10,i.rounding=1,e=e.sin(),e.s=1,e=H(e,new i(1).minus(e.times(e)).sqrt(),o+10,0),i.precision=o,i.rounding=t,E(ae==2||ae==4?e.neg():e,o,t,!0)):new i(NaN)};M.times=M.mul=function(o){var t,e,i,n,r,a,l,d,f,h=this,b=h.constructor,P=h.d,k=(o=new b(o)).d;if(o.s*=h.s,!P||!P[0]||!k||!k[0])return new b(!o.s||P&&!P[0]&&!k||k&&!k[0]&&!P?NaN:!P||!k?o.s/0:o.s*0);for(e=Rt(h.e/R)+Rt(o.e/R),d=P.length,f=k.length,d<f&&(r=P,P=k,k=r,a=d,d=f,f=a),r=[],a=d+f,i=a;i--;)r.push(0);for(i=f;--i>=0;){for(t=0,n=d+i;n>i;)l=r[n]+k[i]*P[n-i-1]+t,r[n--]=l%Wt|0,t=l/Wt|0;r[n]=(r[n]+t)%Wt|0}for(;!r[--a];)r.pop();return t?++e:r.shift(),o.d=r,o.e=fi(r,e),B?E(o,b.precision,b.rounding):o};M.toBinary=function(o,t){return _n(this,2,o,t)};M.toDecimalPlaces=M.toDP=function(o,t){var e=this,i=e.constructor;return e=new i(e),o===void 0?e:(Nt(o,0,_e),t===void 0?t=i.rounding:Nt(t,0,8),E(e,o+e.e+1,t))};M.toExponential=function(o,t){var e,i=this,n=i.constructor;return o===void 0?e=Yt(i,!0):(Nt(o,0,_e),t===void 0?t=n.rounding:Nt(t,0,8),i=E(new n(i),o+1,t),e=Yt(i,!0,o+1)),i.isNeg()&&!i.isZero()?"-"+e:e};M.toFixed=function(o,t){var e,i,n=this,r=n.constructor;return o===void 0?e=Yt(n):(Nt(o,0,_e),t===void 0?t=r.rounding:Nt(t,0,8),i=E(new r(n),o+n.e+1,t),e=Yt(i,!1,o+i.e+1)),n.isNeg()&&!n.isZero()?"-"+e:e};M.toFraction=function(o){var t,e,i,n,r,a,l,d,f,h,b,P,k=this,T=k.d,S=k.constructor;if(!T)return new S(k);if(f=e=new S(1),i=d=new S(0),t=new S(i),r=t.e=So(T)-k.e-1,a=r%R,t.d[0]=It(10,a<0?R+a:a),o==null)o=r>0?t:f;else{if(l=new S(o),!l.isInt()||l.lt(f))throw Error(fe+l);o=l.gt(t)?r>0?t:f:l}for(B=!1,l=new S(Et(T)),h=S.precision,S.precision=r=T.length*R*2;b=H(l,t,0,1,1),n=e.plus(b.times(i)),n.cmp(o)!=1;)e=i,i=n,n=f,f=d.plus(b.times(n)),d=n,n=t,t=l.minus(b.times(n)),l=n;return n=H(o.minus(e),i,0,1,1),d=d.plus(n.times(f)),e=e.plus(n.times(i)),d.s=f.s=k.s,P=H(f,i,r,1).minus(k).abs().cmp(H(d,e,r,1).minus(k).abs())<1?[f,i]:[d,e],S.precision=h,B=!0,P};M.toHexadecimal=M.toHex=function(o,t){return _n(this,16,o,t)};M.toNearest=function(o,t){var e=this,i=e.constructor;if(e=new i(e),o==null){if(!e.d)return e;o=new i(1),t=i.rounding}else{if(o=new i(o),t===void 0?t=i.rounding:Nt(t,0,8),!e.d)return o.s?e:o;if(!o.d)return o.s&&(o.s=e.s),o}return o.d[0]?(B=!1,e=H(e,o,0,t,1).times(o),B=!0,E(e)):(o.s=e.s,e=o),e};M.toNumber=function(){return+this};M.toOctal=function(o,t){return _n(this,8,o,t)};M.toPower=M.pow=function(o){var t,e,i,n,r,a,l=this,d=l.constructor,f=+(o=new d(o));if(!l.d||!o.d||!l.d[0]||!o.d[0])return new d(It(+l,f));if(l=new d(l),l.eq(1))return l;if(i=d.precision,r=d.rounding,o.eq(1))return E(l,i,r);if(t=Rt(o.e/R),t>=o.d.length-1&&(e=f<0?-f:f)<=Kr)return n=xo(d,l,e,i),o.s<0?new d(1).div(n):E(n,i,r);if(a=l.s,a<0){if(t<o.d.length-1)return new d(NaN);if((o.d[t]&1)==0&&(a=1),l.e==0&&l.d[0]==1&&l.d.length==1)return l.s=a,l}return e=It(+l,f),t=e==0||!isFinite(e)?Rt(f*(Math.log("0."+Et(l.d))/Math.LN10+l.e+1)):new d(e+"").e,t>d.maxE+1||t<d.minE-1?new d(t>0?a/0:0):(B=!1,d.rounding=l.s=1,e=Math.min(12,(t+"").length),n=fn(o.times(de(l,i+e)),i),n.d&&(n=E(n,i+5,1),Ke(n.d,i,r)&&(t=i+10,n=E(fn(o.times(de(l,t+e)),t),t+5,1),+Et(n.d).slice(i+1,i+15)+1==1e14&&(n=E(n,i+1,0)))),n.s=a,B=!0,d.rounding=r,E(n,i,r))};M.toPrecision=function(o,t){var e,i=this,n=i.constructor;return o===void 0?e=Yt(i,i.e<=n.toExpNeg||i.e>=n.toExpPos):(Nt(o,1,_e),t===void 0?t=n.rounding:Nt(t,0,8),i=E(new n(i),o,t),e=Yt(i,o<=i.e||i.e<=n.toExpNeg,o)),i.isNeg()&&!i.isZero()?"-"+e:e};M.toSignificantDigits=M.toSD=function(o,t){var e=this,i=e.constructor;return o===void 0?(o=i.precision,t=i.rounding):(Nt(o,1,_e),t===void 0?t=i.rounding:Nt(t,0,8)),E(new i(e),o,t)};M.toString=function(){var o=this,t=o.constructor,e=Yt(o,o.e<=t.toExpNeg||o.e>=t.toExpPos);return o.isNeg()&&!o.isZero()?"-"+e:e};M.truncated=M.trunc=function(){return E(new this.constructor(this),this.e+1,1)};M.valueOf=M.toJSON=function(){var o=this,t=o.constructor,e=Yt(o,o.e<=t.toExpNeg||o.e>=t.toExpPos);return o.isNeg()?"-"+e:e};function Et(o){var t,e,i,n=o.length-1,r="",a=o[0];if(n>0){for(r+=a,t=1;t<n;t++)i=o[t]+"",e=R-i.length,e&&(r+=ue(e)),r+=i;a=o[t],i=a+"",e=R-i.length,e&&(r+=ue(e))}else if(a===0)return"0";for(;a%10===0;)a/=10;return r+a}function Nt(o,t,e){if(o!==~~o||o<t||o>e)throw Error(fe+o)}function Ke(o,t,e,i){var n,r,a,l;for(r=o[0];r>=10;r/=10)--t;return--t<0?(t+=R,n=0):(n=Math.ceil((t+1)/R),t%=R),r=It(10,R-t),l=o[n]%r|0,i==null?t<3?(t==0?l=l/100|0:t==1&&(l=l/10|0),a=e<4&&l==99999||e>3&&l==49999||l==5e4||l==0):a=(e<4&&l+1==r||e>3&&l+1==r/2)&&(o[n+1]/r/100|0)==It(10,t-2)-1||(l==r/2||l==0)&&(o[n+1]/r/100|0)==0:t<4?(t==0?l=l/1e3|0:t==1?l=l/100|0:t==2&&(l=l/10|0),a=(i||e<4)&&l==9999||!i&&e>3&&l==4999):a=((i||e<4)&&l+1==r||!i&&e>3&&l+1==r/2)&&(o[n+1]/r/1e3|0)==It(10,t-3)-1,a}function si(o,t,e){for(var i,n=[0],r,a=0,l=o.length;a<l;){for(r=n.length;r--;)n[r]*=t;for(n[0]+=ln.indexOf(o.charAt(a++)),i=0;i<n.length;i++)n[i]>e-1&&(n[i+1]===void 0&&(n[i+1]=0),n[i+1]+=n[i]/e|0,n[i]%=e)}return n.reverse()}function Wr(o,t){var e,i,n;if(t.isZero())return t;i=t.d.length,i<32?(e=Math.ceil(i/3),n=(1/_i(4,e)).toString()):(e=16,n="2.3283064365386962890625e-10"),o.precision+=e,t=Ae(o,1,t.times(n),new o(1));for(var r=e;r--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return o.precision-=e,t}var H=(function(){function o(i,n,r){var a,l=0,d=i.length;for(i=i.slice();d--;)a=i[d]*n+l,i[d]=a%r|0,l=a/r|0;return l&&i.unshift(l),i}function t(i,n,r,a){var l,d;if(r!=a)d=r>a?1:-1;else for(l=d=0;l<r;l++)if(i[l]!=n[l]){d=i[l]>n[l]?1:-1;break}return d}function e(i,n,r,a){for(var l=0;r--;)i[r]-=l,l=i[r]<n[r]?1:0,i[r]=l*a+i[r]-n[r];for(;!i[0]&&i.length>1;)i.shift()}return function(i,n,r,a,l,d){var f,h,b,P,k,T,S,$,q,z,N,D,qt,W,$t,oe,Zt,re,L,Bt,w=i.constructor,s=i.s==n.s?1:-1,u=i.d,_=n.d;if(!u||!u[0]||!_||!_[0])return new w(!i.s||!n.s||(u?_&&u[0]==_[0]:!_)?NaN:u&&u[0]==0||!_?s*0:s/0);for(d?(k=1,h=i.e-n.e):(d=Wt,k=R,h=Rt(i.e/k)-Rt(n.e/k)),L=_.length,Zt=u.length,q=new w(s),z=q.d=[],b=0;_[b]==(u[b]||0);b++);if(_[b]>(u[b]||0)&&h--,r==null?(W=r=w.precision,a=w.rounding):l?W=r+(i.e-n.e)+1:W=r,W<0)z.push(1),T=!0;else{if(W=W/k+2|0,b=0,L==1){for(P=0,_=_[0],W++;(b<Zt||P)&&W--;b++)$t=P*d+(u[b]||0),z[b]=$t/_|0,P=$t%_|0;T=P||b<Zt}else{for(P=d/(_[0]+1)|0,P>1&&(_=o(_,P,d),u=o(u,P,d),L=_.length,Zt=u.length),oe=L,N=u.slice(0,L),D=N.length;D<L;)N[D++]=0;Bt=_.slice(),Bt.unshift(0),re=_[0],_[1]>=d/2&&++re;do P=0,f=t(_,N,L,D),f<0?(qt=N[0],L!=D&&(qt=qt*d+(N[1]||0)),P=qt/re|0,P>1?(P>=d&&(P=d-1),S=o(_,P,d),$=S.length,D=N.length,f=t(S,N,$,D),f==1&&(P--,e(S,L<$?Bt:_,$,d))):(P==0&&(f=P=1),S=_.slice()),$=S.length,$<D&&S.unshift(0),e(N,S,D,d),f==-1&&(D=N.length,f=t(_,N,L,D),f<1&&(P++,e(N,L<D?Bt:_,D,d))),D=N.length):f===0&&(P++,N=[0]),z[b++]=P,f&&N[0]?N[D++]=u[oe]||0:(N=[u[oe]],D=1);while((oe++<Zt||N[0]!==void 0)&&W--);T=N[0]!==void 0}z[0]||z.shift()}if(k==1)q.e=h,Co=T;else{for(b=1,P=z[0];P>=10;P/=10)b++;q.e=b+h*k-1,E(q,l?r+q.e+1:r,a,T)}return q}})();function E(o,t,e,i){var n,r,a,l,d,f,h,b,P,k=o.constructor;t:if(t!=null){if(b=o.d,!b)return o;for(n=1,l=b[0];l>=10;l/=10)n++;if(r=t-n,r<0)r+=R,a=t,h=b[P=0],d=h/It(10,n-a-1)%10|0;else if(P=Math.ceil((r+1)/R),l=b.length,P>=l)if(i){for(;l++<=P;)b.push(0);h=d=0,n=1,r%=R,a=r-R+1}else break t;else{for(h=l=b[P],n=1;l>=10;l/=10)n++;r%=R,a=r-R+n,d=a<0?0:h/It(10,n-a-1)%10|0}if(i=i||t<0||b[P+1]!==void 0||(a<0?h:h%It(10,n-a-1)),f=e<4?(d||i)&&(e==0||e==(o.s<0?3:2)):d>5||d==5&&(e==4||i||e==6&&(r>0?a>0?h/It(10,n-a):0:b[P-1])%10&1||e==(o.s<0?8:7)),t<1||!b[0])return b.length=0,f?(t-=o.e+1,b[0]=It(10,(R-t%R)%R),o.e=-t||0):b[0]=o.e=0,o;if(r==0?(b.length=P,l=1,P--):(b.length=P+1,l=It(10,R-r),b[P]=a>0?(h/It(10,n-a)%It(10,a)|0)*l:0),f)for(;;)if(P==0){for(r=1,a=b[0];a>=10;a/=10)r++;for(a=b[0]+=l,l=1;a>=10;a/=10)l++;r!=l&&(o.e++,b[0]==Wt&&(b[0]=1));break}else{if(b[P]+=l,b[P]!=Wt)break;b[P--]=0,l=1}for(r=b.length;b[--r]===0;)b.pop()}return B&&(o.e>k.maxE?(o.d=null,o.e=NaN):o.e<k.minE&&(o.e=0,o.d=[0])),o}function Yt(o,t,e){if(!o.isFinite())return Oo(o);var i,n=o.e,r=Et(o.d),a=r.length;return t?(e&&(i=e-a)>0?r=r.charAt(0)+"."+r.slice(1)+ue(i):a>1&&(r=r.charAt(0)+"."+r.slice(1)),r=r+(o.e<0?"e":"e+")+o.e):n<0?(r="0."+ue(-n-1)+r,e&&(i=e-a)>0&&(r+=ue(i))):n>=a?(r+=ue(n+1-a),e&&(i=e-n-1)>0&&(r=r+"."+ue(i))):((i=n+1)<a&&(r=r.slice(0,i)+"."+r.slice(i)),e&&(i=e-a)>0&&(n+1===a&&(r+="."),r+=ue(i))),r}function fi(o,t){var e=o[0];for(t*=R;e>=10;e/=10)t++;return t}function ui(o,t,e){if(t>Hr)throw B=!0,e&&(o.precision=e),Error(ko);return E(new o(ci),t,1,!0)}function Xt(o,t,e){if(t>dn)throw Error(ko);return E(new o(li),t,e,!0)}function So(o){var t=o.length-1,e=t*R+1;if(t=o[t],t){for(;t%10==0;t/=10)e--;for(t=o[0];t>=10;t/=10)e++}return e}function ue(o){for(var t="";o--;)t+="0";return t}function xo(o,t,e,i){var n,r=new o(1),a=Math.ceil(i/R+4);for(B=!1;;){if(e%2&&(r=r.times(t),vo(r.d,a)&&(n=!0)),e=Rt(e/2),e===0){e=r.d.length-1,n&&r.d[e]===0&&++r.d[e];break}t=t.times(t),vo(t.d,a)}return B=!0,r}function wo(o){return o.d[o.d.length-1]&1}function Io(o,t,e){for(var i,n,r=new o(t[0]),a=0;++a<t.length;){if(n=new o(t[a]),!n.s){r=n;break}i=r.cmp(n),(i===e||i===0&&r.s===e)&&(r=n)}return r}function fn(o,t){var e,i,n,r,a,l,d,f=0,h=0,b=0,P=o.constructor,k=P.rounding,T=P.precision;if(!o.d||!o.d[0]||o.e>17)return new P(o.d?o.d[0]?o.s<0?0:1/0:1:o.s?o.s<0?0:o:NaN);for(t==null?(B=!1,d=T):d=t,l=new P(.03125);o.e>-2;)o=o.times(l),b+=5;for(i=Math.log(It(2,b))/Math.LN10*2+5|0,d+=i,e=r=a=new P(1),P.precision=d;;){if(r=E(r.times(o),d,1),e=e.times(++h),l=a.plus(H(r,e,d,1)),Et(l.d).slice(0,d)===Et(a.d).slice(0,d)){for(n=b;n--;)a=E(a.times(a),d,1);if(t==null)if(f<3&&Ke(a.d,d-i,k,f))P.precision=d+=10,e=r=l=new P(1),h=0,f++;else return E(a,P.precision=T,k,B=!0);else return P.precision=T,a}a=l}}function de(o,t){var e,i,n,r,a,l,d,f,h,b,P,k=1,T=10,S=o,$=S.d,q=S.constructor,z=q.rounding,N=q.precision;if(S.s<0||!$||!$[0]||!S.e&&$[0]==1&&$.length==1)return new q($&&!$[0]?-1/0:S.s!=1?NaN:$?0:S);if(t==null?(B=!1,h=N):h=t,q.precision=h+=T,e=Et($),i=e.charAt(0),Math.abs(r=S.e)<15e14){for(;i<7&&i!=1||i==1&&e.charAt(1)>3;)S=S.times(o),e=Et(S.d),i=e.charAt(0),k++;r=S.e,i>1?(S=new q("0."+e),r++):S=new q(i+"."+e.slice(1))}else return f=ui(q,h+2,N).times(r+""),S=de(new q(i+"."+e.slice(1)),h-T).plus(f),q.precision=N,t==null?E(S,N,z,B=!0):S;for(b=S,d=a=S=H(S.minus(1),S.plus(1),h,1),P=E(S.times(S),h,1),n=3;;){if(a=E(a.times(P),h,1),f=d.plus(H(a,new q(n),h,1)),Et(f.d).slice(0,h)===Et(d.d).slice(0,h))if(d=d.times(2),r!==0&&(d=d.plus(ui(q,h+2,N).times(r+""))),d=H(d,new q(k),h,1),t==null)if(Ke(d.d,h-T,z,l))q.precision=h+=T,f=a=S=H(b.minus(1),b.plus(1),h,1),P=E(S.times(S),h,1),n=l=1;else return E(d,q.precision=N,z,B=!0);else return q.precision=N,d;d=f,n+=2}}function Oo(o){return String(o.s*o.s/0)}function ai(o,t){var e,i,n;for((e=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(e<0&&(e=i),e+=+t.slice(i+1),t=t.substring(0,i)):e<0&&(e=t.length),i=0;t.charCodeAt(i)===48;i++);for(n=t.length;t.charCodeAt(n-1)===48;--n);if(t=t.slice(i,n),t){if(n-=i,o.e=e=e-i-1,o.d=[],i=(e+1)%R,e<0&&(i+=R),i<n){for(i&&o.d.push(+t.slice(0,i)),n-=R;i<n;)o.d.push(+t.slice(i,i+=R));t=t.slice(i),i=R-t.length}else i-=n;for(;i--;)t+="0";o.d.push(+t),B&&(o.e>o.constructor.maxE?(o.d=null,o.e=NaN):o.e<o.constructor.minE&&(o.e=0,o.d=[0]))}else o.e=0,o.d=[0];return o}function Zr(o,t){var e,i,n,r,a,l,d,f,h;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Ao.test(t))return ai(o,t)}else if(t==="Infinity"||t==="NaN")return+t||(o.s=NaN),o.e=NaN,o.d=null,o;if(Ur.test(t))e=16,t=t.toLowerCase();else if($r.test(t))e=2;else if(Vr.test(t))e=8;else throw Error(fe+t);for(r=t.search(/p/i),r>0?(d=+t.slice(r+1),t=t.substring(2,r)):t=t.slice(2),r=t.indexOf("."),a=r>=0,i=o.constructor,a&&(t=t.replace(".",""),l=t.length,r=l-r,n=xo(i,new i(e),r,r*2)),f=si(t,e,Wt),h=f.length-1,r=h;f[r]===0;--r)f.pop();return r<0?new i(o.s*0):(o.e=fi(f,h),o.d=f,B=!1,a&&(o=H(o,n,l*4)),d&&(o=o.times(Math.abs(d)<54?It(2,d):He.pow(2,d))),B=!0,o)}function zr(o,t){var e,i=t.d.length;if(i<3)return t.isZero()?t:Ae(o,2,t,t);e=1.4*Math.sqrt(i),e=e>16?16:e|0,t=t.times(1/_i(5,e)),t=Ae(o,2,t,t);for(var n,r=new o(5),a=new o(16),l=new o(20);e--;)n=t.times(t),t=t.times(r.plus(n.times(a.times(n).minus(l))));return t}function Ae(o,t,e,i,n){var r,a,l,d,f=1,h=o.precision,b=Math.ceil(h/R);for(B=!1,d=e.times(e),l=new o(i);;){if(a=H(l.times(d),new o(t++*t++),h,1),l=n?i.plus(a):i.minus(a),i=H(a.times(d),new o(t++*t++),h,1),a=l.plus(i),a.d[b]!==void 0){for(r=b;a.d[r]===l.d[r]&&r--;);if(r==-1)break}r=l,l=i,i=a,a=r,f++}return B=!0,a.d.length=b+1,a}function _i(o,t){for(var e=o;--t;)e*=o;return e}function Eo(o,t){var e,i=t.s<0,n=Xt(o,o.precision,1),r=n.times(.5);if(t=t.abs(),t.lte(r))return ae=i?4:1,t;if(e=t.divToInt(n),e.isZero())ae=i?3:2;else{if(t=t.minus(e.times(n)),t.lte(r))return ae=wo(e)?i?2:3:i?4:1,t;ae=wo(e)?i?1:4:i?3:2}return t.minus(n).abs()}function _n(o,t,e,i){var n,r,a,l,d,f,h,b,P,k=o.constructor,T=e!==void 0;if(T?(Nt(e,1,_e),i===void 0?i=k.rounding:Nt(i,0,8)):(e=k.precision,i=k.rounding),!o.isFinite())h=Oo(o);else{for(h=Yt(o),a=h.indexOf("."),T?(n=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):n=t,a>=0&&(h=h.replace(".",""),P=new k(1),P.e=h.length-a,P.d=si(Yt(P),10,n),P.e=P.d.length),b=si(h,10,n),r=d=b.length;b[--d]==0;)b.pop();if(!b[0])h=T?"0p+0":"0";else{if(a<0?r--:(o=new k(o),o.d=b,o.e=r,o=H(o,P,e,i,0,n),b=o.d,r=o.e,f=Co),a=b[e],l=n/2,f=f||b[e+1]!==void 0,f=i<4?(a!==void 0||f)&&(i===0||i===(o.s<0?3:2)):a>l||a===l&&(i===4||f||i===6&&b[e-1]&1||i===(o.s<0?8:7)),b.length=e,f)for(;++b[--e]>n-1;)b[e]=0,e||(++r,b.unshift(1));for(d=b.length;!b[d-1];--d);for(a=0,h="";a<d;a++)h+=ln.charAt(b[a]);if(T){if(d>1)if(t==16||t==8){for(a=t==16?4:3,--d;d%a;d++)h+="0";for(b=si(h,n,t),d=b.length;!b[d-1];--d);for(a=1,h="1.";a<d;a++)h+=ln.charAt(b[a])}else h=h.charAt(0)+"."+h.slice(1);h=h+(r<0?"p":"p+")+r}else if(r<0){for(;++r;)h="0"+h;h="0."+h}else if(++r>d)for(r-=d;r--;)h+="0";else r<d&&(h=h.slice(0,r)+"."+h.slice(r))}h=(t==16?"0x":t==2?"0b":t==8?"0o":"")+h}return o.s<0?"-"+h:h}function vo(o,t){if(o.length>t)return o.length=t,!0}function Gr(o){return new this(o).abs()}function Qr(o){return new this(o).acos()}function Jr(o){return new this(o).acosh()}function Xr(o,t){return new this(o).plus(t)}function Yr(o){return new this(o).asin()}function ts(o){return new this(o).asinh()}function es(o){return new this(o).atan()}function is(o){return new this(o).atanh()}function ns(o,t){o=new this(o),t=new this(t);var e,i=this.precision,n=this.rounding,r=i+4;return!o.s||!t.s?e=new this(NaN):!o.d&&!t.d?(e=Xt(this,r,1).times(t.s>0?.25:.75),e.s=o.s):!t.d||o.isZero()?(e=t.s<0?Xt(this,i,n):new this(0),e.s=o.s):!o.d||t.isZero()?(e=Xt(this,r,1).times(.5),e.s=o.s):t.s<0?(this.precision=r,this.rounding=1,e=this.atan(H(o,t,r,1)),t=Xt(this,r,1),this.precision=i,this.rounding=n,e=o.s<0?e.minus(t):e.plus(t)):e=this.atan(H(o,t,r,1)),e}function os(o){return new this(o).cbrt()}function rs(o){return E(o=new this(o),o.e+1,2)}function ss(o,t,e){return new this(o).clamp(t,e)}function as(o){if(!o||typeof o!="object")throw Error(di+"Object expected");var t,e,i,n=o.defaults===!0,r=["precision",1,_e,"rounding",0,8,"toExpNeg",-Te,0,"toExpPos",0,Te,"maxE",0,Te,"minE",-Te,0,"modulo",0,9];for(t=0;t<r.length;t+=3)if(e=r[t],n&&(this[e]=un[e]),(i=o[e])!==void 0)if(Rt(i)===i&&i>=r[t+1]&&i<=r[t+2])this[e]=i;else throw Error(fe+e+": "+i);if(e="crypto",n&&(this[e]=un[e]),(i=o[e])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[e]=!0;else throw Error(Mo);else this[e]=!1;else throw Error(fe+e+": "+i);return this}function cs(o){return new this(o).cos()}function ls(o){return new this(o).cosh()}function Ro(o){var t,e,i;function n(r){var a,l,d,f=this;if(!(f instanceof n))return new n(r);if(f.constructor=n,Po(r)){f.s=r.s,B?!r.d||r.e>n.maxE?(f.e=NaN,f.d=null):r.e<n.minE?(f.e=0,f.d=[0]):(f.e=r.e,f.d=r.d.slice()):(f.e=r.e,f.d=r.d?r.d.slice():r.d);return}if(d=typeof r,d==="number"){if(r===0){f.s=1/r<0?-1:1,f.e=0,f.d=[0];return}if(r<0?(r=-r,f.s=-1):f.s=1,r===~~r&&r<1e7){for(a=0,l=r;l>=10;l/=10)a++;B?a>n.maxE?(f.e=NaN,f.d=null):a<n.minE?(f.e=0,f.d=[0]):(f.e=a,f.d=[r]):(f.e=a,f.d=[r]);return}if(r*0!==0){r||(f.s=NaN),f.e=NaN,f.d=null;return}return ai(f,r.toString())}if(d==="string")return(l=r.charCodeAt(0))===45?(r=r.slice(1),f.s=-1):(l===43&&(r=r.slice(1)),f.s=1),Ao.test(r)?ai(f,r):Zr(f,r);if(d==="bigint")return r<0?(r=-r,f.s=-1):f.s=1,ai(f,r.toString());throw Error(fe+r)}if(n.prototype=M,n.ROUND_UP=0,n.ROUND_DOWN=1,n.ROUND_CEIL=2,n.ROUND_FLOOR=3,n.ROUND_HALF_UP=4,n.ROUND_HALF_DOWN=5,n.ROUND_HALF_EVEN=6,n.ROUND_HALF_CEIL=7,n.ROUND_HALF_FLOOR=8,n.EUCLID=9,n.config=n.set=as,n.clone=Ro,n.isDecimal=Po,n.abs=Gr,n.acos=Qr,n.acosh=Jr,n.add=Xr,n.asin=Yr,n.asinh=ts,n.atan=es,n.atanh=is,n.atan2=ns,n.cbrt=os,n.ceil=rs,n.clamp=ss,n.cos=cs,n.cosh=ls,n.div=us,n.exp=ds,n.floor=fs,n.hypot=_s,n.ln=hs,n.log=ps,n.log10=gs,n.log2=ms,n.max=bs,n.min=ys,n.mod=ws,n.mul=vs,n.pow=Ps,n.random=Cs,n.round=ks,n.sign=Ms,n.sin=Ts,n.sinh=As,n.sqrt=Ss,n.sub=xs,n.sum=Is,n.tan=Os,n.tanh=Es,n.trunc=Rs,o===void 0&&(o={}),o&&o.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<i.length;)o.hasOwnProperty(e=i[t++])||(o[e]=this[e]);return n.config(o),n}function us(o,t){return new this(o).div(t)}function ds(o){return new this(o).exp()}function fs(o){return E(o=new this(o),o.e+1,3)}function _s(){var o,t,e=new this(0);for(B=!1,o=0;o<arguments.length;)if(t=new this(arguments[o++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return B=!0,new this(1/0);e=t}return B=!0,e.sqrt()}function Po(o){return o instanceof He||o&&o.toStringTag===To||!1}function hs(o){return new this(o).ln()}function ps(o,t){return new this(o).log(t)}function ms(o){return new this(o).log(2)}function gs(o){return new this(o).log(10)}function bs(){return Io(this,arguments,-1)}function ys(){return Io(this,arguments,1)}function ws(o,t){return new this(o).mod(t)}function vs(o,t){return new this(o).mul(t)}function Ps(o,t){return new this(o).pow(t)}function Cs(o){var t,e,i,n,r=0,a=new this(1),l=[];if(o===void 0?o=this.precision:Nt(o,1,_e),i=Math.ceil(o/R),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(i));r<i;)n=t[r],n>=429e7?t[r]=crypto.getRandomValues(new Uint32Array(1))[0]:l[r++]=n%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(i*=4);r<i;)n=t[r]+(t[r+1]<<8)+(t[r+2]<<16)+((t[r+3]&127)<<24),n>=214e7?crypto.randomBytes(4).copy(t,r):(l.push(n%1e7),r+=4);r=i/4}else throw Error(Mo);else for(;r<i;)l[r++]=Math.random()*1e7|0;for(i=l[--r],o%=R,i&&o&&(n=It(10,R-o),l[r]=(i/n|0)*n);l[r]===0;r--)l.pop();if(r<0)e=0,l=[0];else{for(e=-1;l[0]===0;e-=R)l.shift();for(i=1,n=l[0];n>=10;n/=10)i++;i<R&&(e-=R-i)}return a.e=e,a.d=l,a}function ks(o){return E(o=new this(o),o.e+1,this.rounding)}function Ms(o){return o=new this(o),o.d?o.d[0]?o.s:0*o.s:o.s||NaN}function Ts(o){return new this(o).sin()}function As(o){return new this(o).sinh()}function Ss(o){return new this(o).sqrt()}function xs(o,t){return new this(o).sub(t)}function Is(){var o=0,t=arguments,e=new this(t[o]);for(B=!1;e.s&&++o<t.length;)e=e.plus(t[o]);return B=!0,E(e,this.precision,this.rounding)}function Os(o){return new this(o).tan()}function Es(o){return new this(o).tanh()}function Rs(o){return E(o=new this(o),o.e+1,1)}M[Symbol.for("nodejs.util.inspect.custom")]=M.toString;M[Symbol.toStringTag]="Decimal";var He=M.constructor=Ro(un);ci=new He(ci);li=new He(li);var I=He;function Se(o){let t=Dt.isSuiCoin(o.coin_type_a),e=Dt.isSuiCoin(o.coin_type_b);return{is_adjust_coin_a:t,is_adjust_coin_b:e}}function js(o,t){return I.ceil(I(o).div(1+t)).toString()}var Ut=class{static createCollectRewarderAndFeeParams(t,e,i,n,r,a){r===void 0&&(r=[...n]),a===void 0&&(a=[...n]);let l=pn(i.coin_type_a),d=pn(i.coin_type_b);if(i.collect_fee){let h=Dt.buildCoinForAmount(e,r,BigInt(0),l,!1);r=h.remain_coins;let b=Dt.buildCoinForAmount(e,a,BigInt(0),d,!1);a=b.remain_coins,e=t.Position.createCollectFeePayload({pool_id:i.pool_id,pos_id:i.pos_id,coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b},e,h.target_coin,b.target_coin)}let f=[];return i.rewarder_coin_types.forEach(h=>{switch(pn(h)){case l:f.push(Dt.buildCoinForAmount(e,r,BigInt(0),h,!1).target_coin);break;case d:f.push(Dt.buildCoinForAmount(e,a,BigInt(0),h,!1).target_coin);break;default:f.push(Dt.buildCoinForAmount(e,n,BigInt(0),h,!1).target_coin);break}}),e=t.Rewarder.createCollectRewarderPayload(i,e,f),e}static async adjustTransactionForGas(t,e,i,n){n.setSender(t.getSenderAddress());let r=Dt.selectCoinAssetGreaterThanOrEqual(e,i).selected_coins,a=Dt.calculateTotalBalance(e);if(r.length===0&&F("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${a}`),a-i>1e9)return{fixAmount:i};let l=await t.FullClient.calculationTxGas(hn.from(n));if(Dt.selectCoinAssetGreaterThanOrEqual(e,BigInt(l),r.map(f=>f.coin_object_id)).selected_coins.length===0){let f=BigInt(l)+BigInt(500);if(a-i<f){i-=f,i<0&&F("InsufficientBalance","gas Insufficient balance");let h=new hn;return{fixAmount:i,newTx:h}}}return{fixAmount:i}}static async buildAddLiquidityFixTokenForGas(t,e,i,n,r,a,l){r=await this.buildAddLiquidityFixToken(t,e,i,r,a,l);let{is_adjust_coin_a:d}=Se(i),f=d?i.amount_a:i.amount_b,h=await this.adjustTransactionForGas(t,Dt.getCoinAssets(d?i.coin_type_a:i.coin_type_b,e),BigInt(f),r),{fixAmount:b}=h,P=h.newTx;if(P!=null){let k,T;if(d)i.amount_a=Number(b),k=this.buildAddLiquidityFixTokenCoinInput(P,!i.fix_amount_a,b.toString(),i.slippage,i.coin_type_a,e,!1,!0),T=this.buildAddLiquidityFixTokenCoinInput(P,i.fix_amount_a,i.amount_b,i.slippage,i.coin_type_b,e,!1,!0);else return i.amount_b=Number(b),k=this.buildAddLiquidityFixTokenCoinInput(P,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,e,!1,!0),T=this.buildAddLiquidityFixTokenCoinInput(P,i.fix_amount_a,b.toString(),i.slippage,i.coin_type_b,e,!1,!0),i=this.fixAddLiquidityFixTokenParams(i,n.slippage,n.cur_sqrt_price),this.buildAddLiquidityFixTokenArgs(P,t,e,i,k,T)}return r}static async buildAddLiquidityFixToken(t,e,i,n,r,a){n=n||new hn;let l,d;return r==null||a==null?(l=this.buildAddLiquidityFixTokenCoinInput(n,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,e,!1,!0),d=this.buildAddLiquidityFixTokenCoinInput(n,i.fix_amount_a,i.amount_b,i.slippage,i.coin_type_b,e,!1,!0)):(l={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},d={target_coin:a,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]}),n=this.buildAddLiquidityFixTokenArgs(n,t,e,i,l,d),n}static buildAddLiquidityFixTokenCoinInput(t,e,i,n,r,a,l=!0,d=!0){return e?Dt.buildCoinForAmountInterval(t,a,{amount_second:BigInt(js(i,n)),amount_first:BigInt(i)},r,l,d):Dt.buildCoinForAmount(t,a,BigInt(i),r,l,d)}static fixAddLiquidityFixTokenParams(t,e,i){let n=t.fix_amount_a?t.amount_a:t.amount_b,r=Fs.estLiquidityAndCoinAmountFromOneAmounts(Number(t.tick_lower),Number(t.tick_upper),new jo.default(n),t.fix_amount_a,!0,e,i);return t.amount_a=t.fix_amount_a?t.amount_a:r.coin_amount_limit_a,t.amount_b=t.fix_amount_a?r.coin_amount_limit_b:t.amount_b,t}static buildAddLiquidityFixTokenArgs(t,e,i,n,r,a){let l=[n.coin_type_a,n.coin_type_b],d=n.is_open?"open_position_with_liquidity_by_fix_coin":"add_liquidity_by_fix_coin",{clmm_pool:f,integrate:h}=e.sdkOptions;n.is_open||(t=this.createCollectRewarderAndFeeParams(e,t,n,i,r.remain_coins,a.remain_coins));let b=Bs(f),P=n.is_open?[t.object(b.global_config_id),t.object(n.pool_id),t.pure.u32(Number(Fo(BigInt(n.tick_lower)).toString())),t.pure.u32(Number(Fo(BigInt(n.tick_upper)).toString())),r.target_coin,a.target_coin,t.pure.u64(n.amount_a),t.pure.u64(n.amount_b),t.pure.bool(n.fix_amount_a),t.object(Bo)]:[t.object(b.global_config_id),t.object(n.pool_id),t.object(n.pos_id),r.target_coin,a.target_coin,t.pure.u64(n.amount_a),t.pure.u64(n.amount_b),t.pure.bool(n.fix_amount_a),t.object(Bo)];return t.moveCall({target:`${h.published_at}::${Qt}::${d}`,typeArguments:l,arguments:P}),t}static checkCoinThreshold(t,e,i,n,r,a){e&&i.moveCall({target:`${t.sdkOptions.integrate.published_at}::${me}::check_coin_threshold`,typeArguments:[a],arguments:[n,i.pure.u64(r)]})}};var te=class o{static getDefaultSqrtPriceLimit(t){return new qo.default(t?Ds:qs)}static getDefaultOtherAmountThreshold(t){return t?$s:Ls}static async buildSwapTransactionForGas(t,e,i,n){let r=this.buildSwapTransaction(t,e,i);r.setSender(t.getSenderAddress());let a=await this.adjustTransactionForGas(t,Lt.getCoinAssets(e.a2b?e.coin_type_a:e.coin_type_b,i),BigInt(e.by_amount_in?e.amount:e.amount_limit),r),{fixAmount:l,newTx:d}=a;if(d!==void 0){d.setSender(t.getSenderAddress()),e.by_amount_in?e.amount=l.toString():e.amount_limit=l.toString(),e=await this.fixSwapParams(t,e,n);let f=Lt.buildCoinForAmount(r,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a),h=Lt.buildCoinForAmount(r,i,e.a2b?BigInt(0):BigInt(e.by_amount_in?e.amount:e.amount_limit),e.coin_type_b);r=this.buildSwapTransactionArgs(d,e,t.sdkOptions,f,h)}return r}static buildSwapTransactionArgs(t,e,i,n,r){let{clmm_pool:a,integrate:l}=i,d=o.getDefaultSqrtPriceLimit(e.a2b),f=[e.coin_type_a,e.coin_type_b],{global_config_id:h}=No(a);h===void 0&&F("InvalidConfig","clmm.config.global_config_id is undefined");let b=e.swap_partner!==void 0,P=b?e.a2b?"swap_a2b_with_partner":"swap_b2a_with_partner":e.a2b?"swap_a2b":"swap_b2a",k=b?[t.object(h),t.object(e.pool_id),t.object(e.swap_partner),n.target_coin,r.target_coin,t.pure.bool(e.by_amount_in),t.pure.u64(e.amount),t.pure.u64(e.amount_limit),t.pure.u128(d.toString()),t.object(hi)]:[t.object(h),t.object(e.pool_id),n.target_coin,r.target_coin,t.pure.bool(e.by_amount_in),t.pure.u64(e.amount),t.pure.u64(e.amount_limit),t.pure.u128(d.toString()),t.object(hi)];return t.moveCall({target:`${l.published_at}::${Qt}::${P}`,typeArguments:f,arguments:k}),t}static async adjustTransactionForGas(t,e,i,n){n.setSender(t.getSenderAddress());let r=Lt.selectCoinAssetGreaterThanOrEqual(e,i).selected_coins,a=Lt.calculateTotalBalance(e);if(r.length===0&&F("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${a}`),a-i>1e9)return{fixAmount:i};let l=await t.FullClient.calculationTxGas(n);if(Lt.selectCoinAssetGreaterThanOrEqual(e,BigInt(l),r.map(f=>f.coin_object_id)).selected_coins.length===0){let f=BigInt(l)+BigInt(500);if(a-i<f){i-=f,i<0&&F("InsufficientBalance","gas Insufficient balance");let h=new mn;return{fixAmount:i,newTx:h}}}return{fixAmount:i}}static buildSwapTransaction(t,e,i){let n=new mn;n.setSender(t.getSenderAddress());let r=Lt.buildCoinForAmount(n,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1),a=Lt.buildCoinForAmount(n,i,e.a2b?BigInt(0):BigInt(e.by_amount_in?e.amount:e.amount_limit),e.coin_type_b,!1);return n=this.buildSwapTransactionArgs(n,e,t.sdkOptions,r,a),n}static async fixSwapParams(t,e,i){let{current_pool:n}=i;try{let r=await t.Swap.preSwap({decimals_a:i.decimals_a,decimals_b:i.decimals_b,a2b:e.a2b,by_amount_in:e.by_amount_in,amount:e.amount,pool:n,current_sqrt_price:n.current_sqrt_price,coin_type_a:n.coin_type_a,coin_type_b:n.coin_type_b}),a=i.by_amount_in?r.estimated_amount_out:r.estimated_amount_in,l=Ns(a,i.slippage,!i.by_amount_in);e.amount_limit=l.toString()}catch(r){jt("InvalidConfig",r)}return e}static async buildSwapTransactionWithoutTransferCoinsForGas(t,e,i,n){let{tx:r,coin_ab_s:a}=o.buildSwapTransactionWithoutTransferCoins(t,e,i);r.setSender(t.getSenderAddress());let l=await o.adjustTransactionForGas(t,Lt.getCoinAssets(e.a2b?e.coin_type_a:e.coin_type_b,i),BigInt(e.by_amount_in?e.amount:e.amount_limit),r),{fixAmount:d,newTx:f}=l;if(f!==void 0){f.setSender(t.getSenderAddress()),e.by_amount_in?e.amount=d.toString():e.amount_limit=d.toString(),e=await o.fixSwapParams(t,e,n);let h=Lt.buildCoinForAmount(r,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1,!0),b=Lt.buildCoinForAmount(r,i,e.a2b?BigInt(0):BigInt(e.by_amount_in?e.amount:e.amount_limit),e.coin_type_b,!1,!0),P=o.buildSwapTransactionWithoutTransferCoinArgs(t,f,e,t.sdkOptions,h,b);r=P.tx,a=P.txRes}return{tx:r,coin_ab_s:a}}static buildSwapTransactionWithoutTransferCoins(t,e,i){let n=new mn;n.setSender(t.getSenderAddress());let r=Lt.buildCoinForAmount(n,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1,!0),a=Lt.buildCoinForAmount(n,i,e.a2b?BigInt(0):BigInt(e.by_amount_in?e.amount:e.amount_limit),e.coin_type_b,!1,!0),l=o.buildSwapTransactionWithoutTransferCoinArgs(t,n,e,t.sdkOptions,r,a);return{tx:l.tx,coin_ab_s:l.txRes}}static buildSwapTransactionWithoutTransferCoinArgs(t,e,i,n,r,a){let{clmm_pool:l,integrate:d}=n,f=o.getDefaultSqrtPriceLimit(i.a2b),{global_config_id:h}=No(l);h===void 0&&F("InvalidConfig","clmm.config.global_config_id is undefined");let b=i.swap_partner!==void 0,P=b?"swap_with_partner":"swap",k=b?bo:me,T=b?[e.object(h),e.object(i.pool_id),e.object(i.swap_partner),r.target_coin,a.target_coin,e.pure.bool(i.a2b),e.pure.bool(i.by_amount_in),e.pure.u64(i.amount),e.pure.u128(f.toString()),e.pure.bool(!1),e.object(hi)]:[e.object(h),e.object(i.pool_id),r.target_coin,a.target_coin,e.pure.bool(i.a2b),e.pure.bool(i.by_amount_in),e.pure.u64(i.amount),e.pure.u128(f.toString()),e.pure.bool(!1),e.object(hi)],S=[i.coin_type_a,i.coin_type_b],$=e.moveCall({target:`${d.published_at}::${k}::${P}`,typeArguments:S,arguments:T});if(i.by_amount_in){let q=i.a2b?i.coin_type_b:i.coin_type_a,z=i.a2b?$[1]:$[0],N=Number(i.amount_limit);Ut.checkCoinThreshold(t,i.by_amount_in,e,z,N,q)}return{tx:e,txRes:$}}};function dc(o,t,e){let i=t.mul(e).shln(64),n=t.shln(64).add(o.mul(e));return gn.divRoundUp(i,n)}function fc(o,t,e){let i=t.mul(e).shln(64),n=t.shln(64).sub(o.mul(e));return gn.divRoundUp(i,n)}function _c(o,t,e){return e.sub(gn.divRoundUp(o.shln(64),t))}function hc(o,t,e){return e.add(o.shln(64).div(t))}function yc(o){let t=new Ft.default(o);return t.lt(Vt)?{bits:t.neg().xor(new Ft.default(2).pow(new Ft.default(64)).sub(new Ft.default(1))).add(new Ft.default(1)).toString()}:{bits:t.toString()}}function Uo(o){return{coin_type_a:o.coin_type_a,coin_type_b:o.coin_type_b,current_sqrt_price:new Ft.default(o.current_sqrt_price),current_tick_index:o.current_tick_index,fee_growth_global_a:new Ft.default(o.fee_growth_global_a),fee_growth_global_b:new Ft.default(o.fee_growth_global_b),fee_protocol_coin_a:new Ft.default(o.fee_protocol_coin_a),fee_protocol_coin_b:new Ft.default(o.fee_protocol_coin_b),fee_rate:new Ft.default(o.fee_rate),liquidity:new Ft.default(o.liquidity),tick_indexes:[],tick_spacing:Number(o.tick_spacing),ticks:[],collection_name:""}}function Ks(o,t,e,i,n,r){if(e===Vt)return{amount_in:Vt,amount_out:Vt,next_sqrt_price:t,fee_amount:Vt};let a=o.gte(t),l,d,f,h;if(r){let b=ge.checkMulDivFloor(i,ge.checkUnsignedSub(pi,n),pi,64),P=$o(o,t,e,a);P.gt(b)?(l=b,h=ge.checkUnsignedSub(i,b),f=Us(o,e,b,a)):(l=P,h=ge.checkMulDivCeil(l,n,pi.sub(n),64),f=t),d=Lo(o,f,e,a)}else{let b=Lo(o,t,e,a);b.gt(i)?(d=i,f=Vs(o,e,i,a)):(d=b,f=t),l=$o(o,f,e,a),h=ge.checkMulDivCeil(l,n,pi.sub(n),64)}return{amount_in:l,amount_out:d,next_sqrt_price:f,fee_amount:h}}function Vo(o,t,e,i,n){let r=e,a=i.liquidity,{current_sqrt_price:l}=i,d={amount_in:Vt,amount_out:Vt,fee_amount:Vt,ref_amount:Vt,next_sqrt_price:Vt,cross_tick_num:0},f,h,b=te.getDefaultSqrtPriceLimit(o);for(let P of n){if(o&&i.current_tick_index<P.index||!o&&i.current_tick_index>=P.index||P===null)continue;o&&b.gt(P.sqrt_price)||!o&&b.lt(P.sqrt_price)?f=b:f=P.sqrt_price;let k=Ks(l,f,a,r,i.fee_rate,t);if(k.amount_in.eq(Vt)||(r=t?r.sub(k.amount_in.add(k.fee_amount)):r.sub(k.amount_out)),d.amount_in=d.amount_in.add(k.amount_in),d.amount_out=d.amount_out.add(k.amount_out),d.fee_amount=d.fee_amount.add(k.fee_amount),k.next_sqrt_price.eq(P.sqrt_price)?(h=P.liquidity_net.mul(new Ft.default(-1)),o?ge.is_neg(h)?a=a.add(new Ft.default(Do(BigInt(h.toString()),128))):a=a.add(h):ge.is_neg(h)?a=a.sub(new Ft.default(Do(BigInt(h.toString()),128))):a=a.sub(h),l=P.sqrt_price):l=k.next_sqrt_price,d.cross_tick_num+=1,r.eq(Vt))break}return d.amount_in=d.amount_in.add(d.fee_amount),d.next_sqrt_price=l,d}var Kt=se(Gt());import{asIntN as be,buildNFT as Hs,d as We,DETAILS_KEYS as mi,extractStructTagFromType as xe,getMoveObjectType as Ko,getObjectDeletedResponse as Ws,getObjectFields as yn,getObjectId as bn,getObjectNotExistsResponse as Zs,getObjectOwner as zs,MathUtil as Gs}from"@cetusprotocol/common-sdk";function Qs(o,t,e){let i=xe(o).name,n=xe(t).name;return`${i}-${n}[${e}]`}function gi(o){let t=Ko(o),e=xe(t),i=yn(o);i==null&&F("InvalidPoolObject",`Pool id ${bn(o)} not exists.`,{[mi.METHOD_NAME]:"buildPool"});let n=[];i.rewarder_manager.fields.rewarders.forEach(d=>{let{emissions_per_second:f}=d.fields,h=Gs.fromX64(new Kt.default(f)),b=Math.floor(h.toNumber()*60*60*24);n.push({emissions_per_second:f,coin_type:xe(d.fields.reward_coin.fields.name).source_address,growth_global:d.fields.growth_global,emissions_every_day:b})});let r=i.is_pause,a={disable_add_liquidity:r,disable_remove_liquidity:r,disable_swap:r,disable_flash_loan:r,disable_collect_fee:r,disable_collect_reward:r},l={id:bn(o),pool_type:t,coin_type_a:e.type_arguments[0],coin_type_b:e.type_arguments[1],coin_amount_a:i.coin_a,coin_amount_b:i.coin_b,current_sqrt_price:i.current_sqrt_price,current_tick_index:be(BigInt(i.current_tick_index.fields.bits)),fee_growth_global_a:i.fee_growth_global_a,fee_growth_global_b:i.fee_growth_global_b,fee_protocol_coin_a:i.fee_protocol_coin_a,fee_protocol_coin_b:i.fee_protocol_coin_b,fee_rate:i.fee_rate,pool_status:a,liquidity:i.liquidity,position_manager:{positions_handle:i.position_manager.fields.positions.fields.id.id,size:i.position_manager.fields.positions.fields.size},rewarder_infos:n,rewarder_last_updated_time:i.rewarder_manager.fields.last_updated_time,tick_spacing:i.tick_spacing,ticks_handle:i.tick_manager.fields.ticks.fields.id.id,uri:i.url,index:Number(i.index),name:""};return l.name=Qs(l.coin_type_a,l.coin_type_b,l.tick_spacing),l}function bi(o){(o.error!=null||o.data?.content?.dataType!=="moveObject")&&F("InvalidPositionObject",`Position not exists. Get Position error:${o.error}`,{[mi.METHOD_NAME]:"buildPosition"});let t={creator:"",description:"",image_url:"",link:"",name:"",project_url:""},e={...t,pos_object_id:"",owner:"",type:"",coin_type_a:"",coin_type_b:"",liquidity:"",tick_lower_index:0,tick_upper_index:0,index:0,pool:"",reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"},i=yn(o);if(i){let a=Ko(o),l=zs(o);"nft"in i?(i=i.nft.fields,t.description=i.description,t.name=i.name,t.link=i.url):t=Hs(o),e={...t,pos_object_id:i.id.id,owner:l.AddressOwner,type:a,liquidity:i.liquidity,coin_type_a:i.coin_type_a.fields.name,coin_type_b:i.coin_type_b.fields.name,tick_lower_index:be(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:be(BigInt(i.tick_upper_index.fields.bits)),index:i.index,pool:i.pool,reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"}}let n=Ws(o);n&&(e.pos_object_id=n.objectId,e.position_status="Deleted");let r=Zs(o);return r&&(e.pos_object_id=r,e.position_status="NotExists"),e}function Ze(o){let t={reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0"};o="fields"in o?o.fields:o,o.rewards.forEach((r,a)=>{let{amount_owned:l,growth_inside:d}="fields"in r?r.fields:r;a===0?(t.reward_amount_owned_0=l,t.reward_growth_inside_0=d):a===1?(t.reward_amount_owned_1=l,t.reward_growth_inside_1=d):a===2&&(t.reward_amount_owned_2=l,t.reward_growth_inside_2=d)});let e="fields"in o.tick_lower_index?o.tick_lower_index.fields.bits:o.tick_lower_index.bits,i="fields"in o.tick_upper_index?o.tick_upper_index.fields.bits:o.tick_upper_index.bits;return{liquidity:o.liquidity,tick_lower_index:be(BigInt(e)),tick_upper_index:be(BigInt(i)),...t,fee_growth_inside_a:o.fee_growth_inside_a,fee_owned_a:o.fee_owned_a,fee_growth_inside_b:o.fee_growth_inside_b,fee_owned_b:o.fee_owned_b,pos_object_id:o.position_id}}function yi(o){(o.error!=null||o.data?.content?.dataType!=="moveObject")&&F("InvalidTickObject",`Tick not exists. Get tick data error:${o.error}`,{[mi.METHOD_NAME]:"buildTickData"});let e=yn(o).value.fields.value.fields;return{object_id:bn(o),index:be(BigInt(e.index.fields.bits)),sqrt_price:new Kt.default(e.sqrt_price),liquidity_net:new Kt.default(e.liquidity_net.fields.bits),liquidity_gross:new Kt.default(e.liquidity_gross),fee_growth_outside_a:new Kt.default(e.fee_growth_outside_a),fee_growth_outside_b:new Kt.default(e.fee_growth_outside_b),rewarders_growth_outside:e.rewards_growth_outside}}function Ho(o){(!o||!o.index||!o.sqrt_price||!o.liquidity_net||!o.liquidity_gross||!o.fee_growth_outside_a||!o.fee_growth_outside_b)&&F("InvalidTickFields","Invalid tick fields.",{[mi.METHOD_NAME]:"buildTickDataByEvent"});let t=be(BigInt(o.index.bits)),e=new Kt.default(o.sqrt_price),i=new Kt.default(o.liquidity_net.bits),n=new Kt.default(o.liquidity_gross),r=new Kt.default(o.fee_growth_outside_a),a=new Kt.default(o.fee_growth_outside_b),l=o.rewards_growth_outside||[];return{object_id:"",index:t,sqrt_price:e,liquidity_net:i,liquidity_gross:n,fee_growth_outside_a:r,fee_growth_outside_b:a,rewarders_growth_outside:l}}function Ic(o,t){return`Cetus LP | Pool${o}-${t}`}function Wo(o,t,e){let i=[],{timestampMs:n,events:r}=o,a=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent","AddLiquidityV2Event","RemoveLiquidityV2Event"];return r?.forEach((l,d)=>{let f=xe(l.type).name;if(a.includes(f)){let h={tx_digest:l.id.txDigest,package_id:l.packageId,transaction_module:l.transactionModule,sender:l.sender,type:l.type,timestamp_ms:n||"0",parsed_json:l.parsedJson,index:`${t}_${d}`};switch(f){case"CollectFeeEvent":e.includes(h.parsed_json.position)&&(We(h.parsed_json.amount_a).gt(0)||We(h.parsed_json.amount_b).gt(0))&&i.push(h);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":case"AddLiquidityV2Event":case"RemoveLiquidityV2Event":(We(h.parsed_json.amount_a).gt(0)||We(h.parsed_json.amount_b).gt(0))&&i.push(h);break;case"CollectRewardEvent":case"HarvestEvent":case"CollectRewardV2Event":(e.includes(h.parsed_json.position)||e.includes(h.parsed_json.wrapped_position_id))&&We(h.parsed_json.amount).gt(0)&&i.push(h);break;default:break}}}),i}function Zo(o,t,e,i){let n=[],{timestampMs:r,events:a}=o;return a?.forEach((l,d)=>{let{name:f,address:h}=xe(l.type);if(go.includes(f)&&e.includes(h)&&i===l.parsedJson.pool){let b={tx:l.id.txDigest,sender:l.sender,type:l.type,block_time:r||"0",index:`${t}_${d}`,parsed_json:l.parsedJson};n.push(b)}}),n}function wi(o,t,e,i){t.moveCall({target:`${o.sdkOptions.integrate.published_at}::${yo}::transfer_coin_to_sender`,typeArguments:[i],arguments:[e]})}function zo(o,t,e,i,n){n!=null?t.transferObjects([e],t.pure.address(n)):wi(o,t,e,i)}import{asUintN as Ee,CACHE_TIME_24H as vi,ClmmPoolUtil as ra,CLOCK_ADDRESS as nr,CoinAssist as Pi,createFullClient as sa,d as Re,DETAILS_KEYS as J,extractStructTagFromType as Fe,getObjectFields as aa,getObjectPreviousTransactionDigest as ca,getPackagerConfigs as Ci,isSortedSymbols as or,TickMath as vn,tickScore as la,TickUtil as rr}from"@cetusprotocol/common-sdk";import{asIntN as Go,d as Qo,extractStructTagFromType as Js,fixCoinType as Jo,getObjectFields as wn,getObjectType as Xs}from"@cetusprotocol/common-sdk";var Ys=1e4,ee=class{static parseClmmVestInfo(t){let e=wn(t),i=Xs(t),n=Js(i),r=e.global_vesting_periods.map(l=>({period:l.fields.period,release_time:l.fields.release_time,redeemed_amount:l.fields.redeemed_amount,percentage:Qo(l.fields.percentage).div(Ys).toNumber()}));return{id:e.id.id,balance:e.balance,global_vesting_periods:r,total_value:e.total_value,total_cetus_amount:e.total_cetus_amount,redeemed_amount:e.redeemed_amount,start_time:e.start_time,type:n.full_address,positions:{id:e.positions.fields.id,size:e.positions.fields.size}}}static parsePositionVesting(t){return{position_id:t.position_id,cetus_amount:t.cetus_amount,redeemed_amount:t.redeemed_amount,is_paused:t.is_paused,impaired_a:t.impaired_a,impaired_b:t.impaired_b,period_details:t.period_details,coin_type_a:Jo(t.coin_a.name,!1),coin_type_b:Jo(t.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(t){let e=wn(t);return{current_sqrt_price:e.current_sqrt_price,remove_percent:Qo(e.remove_percent).div(1e6).toString(),snapshots:{id:e.snapshots.fields.id.id,size:e.snapshots.fields.size}}}static parsePositionSnapshot(t){let e=wn(t),i=e.value.fields.value.fields;return{position_id:e.name,liquidity:i.liquidity,tick_lower_index:Go(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:Go(BigInt(i.tick_upper_index.fields.bits)),fee_owned_a:i.fee_owned_a,fee_owned_b:i.fee_owned_b,value_cut:i.value_cut,rewards:i.rewards}}};import{FullRpcUrlMainnet as ta,GraphRpcUrlMainnet as ea}from"@cetusprotocol/common-sdk";var Xo={clmmConfig:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:"0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"},cetusConfig:{coin_list_id:"0x8cbc11d9e10140db3d230f50b4d30e9b721201c0083615441707ffec1ef77b23",launchpad_pools_id:"0x1098fac992eab3a0ab7acf15bb654fc1cf29b5a6142c4ef1058e6c408dd15115",clmm_pools_id:"0x15b6a27dd9ae03eb455aba03b39e29aad74abd3757b8e18c0755651b2ae5b71e",admin_cap_id:"0x39d78781750e193ce35c45ff32c6c0c3f2941fa3ddaf8595c90c555589ddb113",global_config_id:"0x0408fa4e4a4c03cc0de8f23d0c2bbfe8913d178713c9a271ed4080973fe42d8f",coin_list_handle:"0x49136005e90e28c4695419ed4194cc240603f1ea8eb84e62275eaff088a71063",launchpad_pools_handle:"0x5e194a8efcf653830daf85a85b52e3ae8f65dc39481d54b2382acda25068375c",clmm_pools_handle:"0x37f60eb2d9d227949b95da8fea810db3c32d1e1fa8ed87434fc51664f87d83cb"}},Yo={env:"mainnet",full_rpc_url:ta,graph_rpc_url:ea,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:Xo.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0x25ebb9a7c50eb17b3fa9c5a30fb8b5ad8f97caaf4928943acbcff7153dfee5e3",version:14,config:Xo.clmmConfig},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0xae9c208cf58fd5ba36737c9ee5dcfa7f152d0fb5a5a99eebb7c881ebc2fe59e0",version:16},stats_pools_url:"https://api-sui.cetus.zone/v2/sui/stats_pools",clmm_vest:{package_id:"0x9d2f067d3b9d19ac0f8d2e5c2c393b1760232083e42005b2e5df39c06064d522",published_at:"0x9d2f067d3b9d19ac0f8d2e5c2c393b1760232083e42005b2e5df39c06064d522",version:1,config:{clmm_vest_id:"0xe255c47472470c03bbefb1fc883459c2b978d3ad29aa8ee0c8c1ec9753fa7d01",versioned_id:"0x4f6f2f638362505836114f313809b834dafd58e3910df5110f6e54e4e35c929b",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"}}},tr=["0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb","0xdb5cd62a06c79695bfc9982eb08534706d3752fe123b48e0144f480209b3117f"];import{FullRpcUrlTestnet as ia,GraphRpcUrlTestnet as na}from"@cetusprotocol/common-sdk";var er={env:"testnet",full_rpc_url:ia,graph_rpc_url:na,cetus_config:{package_id:"0x2933975c3f74ef7c31f512edead6c6ce3f58f8e8fdbea78770ec8d5abd8ff700",published_at:"0xb50a626294f743b40ea51c9cb75190f0e38c71f580981b5613aef910b67a2691",config:{coin_list_id:"",launchpad_pools_id:"",clmm_pools_id:"",admin_cap_id:"0x774656a83f4f625fcc4e4dbf103eb77caf2d8b8f114ad33f55b848be068267b9",global_config_id:"0x95275a022123c66682278e9df6b5bac4da9abcc29ab698b7b2a6213262a592fe",coin_list_handle:"",launchpad_pools_handle:"",clmm_pools_handle:""}},clmm_pool:{package_id:"0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8",published_at:"0x6bbdf09f9fa0baa1524080a5b8991042e95061c4e1206217279aec51ba08edf7",config:{pools_id:"0x20a086e6fa0741b3ca77d033a65faf0871349b986ddbdde6fa1d85d78a5f4222",global_config_id:"0xc6273f844b4bc258952c4e477697aa12c918c8e08106fac6b934811298c9820a",global_vault_id:"0x71e74a999dd7959e483f758ddf573e85fa4c24944db33ff6763c9d85a9c045fe",admin_cap_id:"0xbf4c48590f403c38351de0e8aa13d6d91bf78fd8c04e93ac1d0269c44d70ae02",partners_id:"0xb5ae5ed3f403654ae1307aadc0140f746db41efb7bda92235257c84d90a1397e"}},integrate:{package_id:"0xab2d58dd28ff0dc19b18ab2c634397b785a38c342a8f5065ade5f53f9dbffa1c",published_at:"0xab2d58dd28ff0dc19b18ab2c634397b785a38c342a8f5065ade5f53f9dbffa1c",version:1},stats_pools_url:"https://api-sui.devcetus.com/v2/sui/stats_pools",clmm_vest:{package_id:"0xa46d9c66e7b24ab14c5fc5f0d08fa257d833718f0295a6343556ea2f2fdfbd7f",published_at:"0xa46d9c66e7b24ab14c5fc5f0d08fa257d833718f0295a6343556ea2f2fdfbd7f",config:{clmm_vest_id:"0x308b24963e5992f699e32db2f7088b812566a0cae580317fd3b8bf61de7f5508",versioned_id:"0x1cfb684d8ff581416a56caba2aa419bee45fe98a23cbf28e2c6c1021b14cab7c",cetus_coin_type:"0xc6c51938da9a5cf6d6dca692783ea7bdf4478f7b1fef693f58947848f84bcf89::cetus::CETUS"}}},ir=["0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8","0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8"];var ki=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}async getPositionList(t,e="all"){let i={data:[],has_next_page:!0},n=await this._sdk.FullClient.getDynamicFieldsByPage(t,e);i.has_next_page=n.has_next_page,i.next_cursor=n.next_cursor;let r=n.data.map(l=>(l.error!=null&&F("InvalidConfig",`when getPositionList get position objects error: ${l.error}, please check the rpc, contracts address config and position id.`,{[J.METHOD_NAME]:"getPositionList"}),l.name.value)),a=await this._sdk.Position.getSimplePositionList(r);return i.data=a,i}async getPoolImmutablesWithPage(t="all",e=!1){let{package_id:i}=this._sdk.sdkOptions.clmm_pool,n=[],r={data:[],has_next_page:!1},a=t==="all",l=`${i}_getPoolImmutables`;if(a){let d=this._sdk.getCache(l,e);d&&n.push(...d)}if(n.length===0)try{let d=`${i}::factory::CreatePoolEvent`,f=await this._sdk.FullClient.queryEventsByPage({MoveEventType:d},t);r.has_next_page=f.has_next_page,r.next_cursor=f.next_cursor,f.data.forEach(h=>{let b=h.parsedJson;b&&n.push({id:b.pool_id,tick_spacing:b.tick_spacing,coin_type_a:Fe(b.coin_type_a).full_address,coin_type_b:Fe(b.coin_type_b).full_address})})}catch(d){return jt("FetchError",d,{[J.METHOD_NAME]:"getPoolImmutables"})}return r.data=n,a&&this._sdk.updateCache(`${i}_getPoolImmutables`,n,vi),r}async getPoolsWithPage(t="all",e=!1){let i={data:[],has_next_page:!1},n=await this.getPoolImmutablesWithPage(t,e),r=await this._sdk.FullClient.batchGetObjects(n.data.map(a=>a.id),{showContent:!0,showType:!0});for(let a of r){(a.error!=null||a.data?.content?.dataType!=="moveObject")&&F("InvalidPoolObject",`getPoolWithPages error code: ${a.error?.code??"unknown error"}, please check config and object ids`,{[J.METHOD_NAME]:"getPoolsWithPage"});let l=gi(a);i.data.push(l);let d=`${l.id}_getPoolObject`;this._sdk.updateCache(d,l,vi)}return i.has_next_page=n.has_next_page,i.next_cursor=n.next_cursor,i}async getPoolLiquiditySnapshot(t,e=!1){try{let i=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x1::string::String",value:po}}),n=ee.parsePoolLiquiditySnapshot(i);if(e){let a=(await this._sdk.FullClient.getDynamicFieldsByPage(n.snapshots.id)).data.map(l=>l.objectId);if(a.length>0){let l=await this._sdk.FullClient.batchGetObjects(a,{showContent:!0,showType:!0}),d=[];l.forEach(f=>{let h=ee.parsePositionSnapshot(f);d.push(h)}),n.position_snapshots=d}}return n}catch(i){return jt("InvalidPoolObject",i,{[J.METHOD_NAME]:"getPoolLiquiditySnapshot",[J.REQUEST_PARAMS]:t})}}async getPositionSnapshot(t,e){let i=await this._sdk.FullClient.getDynamicFieldObjects(t,e,"0x2::object::ID","address"),n=[];return i.forEach(r=>{try{let a=ee.parsePositionSnapshot(r);n.push(a)}catch(a){console.log("getPositionSnapshot error: ",a)}}),n}async getAssignPools(t){if(t.length===0)return[];let e=[],i=await this._sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let n of i){(n.error!=null||n.data?.content?.dataType!=="moveObject")&&F("InvalidPoolObject",`getPools error code: ${n.error?.code??"unknown error"}, please check config and object ids`,{[J.METHOD_NAME]:"getAssignPools"});let r=gi(n);e.push(r);let a=`${r.id}_getPoolObject`;this._sdk.updateCache(a,r,vi)}return e}async getPool(t,e=!0,i=!1){let n=`${t}_getPoolObject`,r=this._sdk.getCache(n,e);if(r!==void 0)return r;let a=await this._sdk.FullClient.getObject({id:t,options:{showType:!0,showContent:!0}});(a.error!=null||a.data?.content?.dataType!=="moveObject")&&F("InvalidPoolObject",`getPool error code: ${a.error?.code??"unknown error"}, please check config and object id`,{[J.METHOD_NAME]:"getPool"});let l=gi(a);if(i){let d=await this.getPoolStatus(t);d&&(l.pool_status=d)}return this._sdk.updateCache(n,l),l}async getPoolByCoins(t,e){if(t.length===0)return[];for(let d=0;d<t.length;d++)t[d]==="0x2::sui::SUI"&&(t[d]="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI");let i=this._sdk.sdkOptions.stats_pools_url;i||F("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[J.METHOD_NAME]:"getPoolByCoins"}),i+=`?order_by=-fees&limit=100&has_mining=true&has_farming=true&no_incentives=true&display_all_pools=true&coin_type=${t.join(",")}`;let n=await fetch(i),r;try{r=await n.json()}catch(d){jt("FetchError",d,{[J.METHOD_NAME]:"getPoolByCoins",[J.REQUEST_PARAMS]:i})}let a=r.data.lp_list,l=[];for(let d of a)t.includes(d.coin_a_address)&&t.includes(d.coin_b_address)&&(e!=null?d.object.feeRate===e&&l.push(d.address):l.push(d.address));return l.length>0?await this.getAssignPools(l):[]}async createPoolPayload(t,e){if(or(Oe(t.coin_type_a),Oe(t.coin_type_b))){let i=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=i}return await this.createPoolAndAddLiquidity(t,e)}async createPoolRowPayload(t,e){if(or(Oe(t.coin_type_a),Oe(t.coin_type_b))){let i=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=i}return await this.createPoolAndAddLiquidityRow(t,e)}async getClmmConfigs(t=!1){let{package_id:e}=this._sdk.sdkOptions.clmm_pool,i=`${e}_getInitEvent`,n=this._sdk.getCache(i,t);if(n!==void 0)return n;let r=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),a=ca(r),l=(await this._sdk.FullClient.queryEventsByPage({Transaction:a})).data,d={pools_id:"",global_config_id:"",global_vault_id:"",admin_cap_id:""};return l.length>0&&(l.forEach(f=>{let h=f.parsedJson;if(f.type)switch(Fe(f.type).full_address){case`${e}::config::InitConfigEvent`:d.global_config_id=h.global_config_id,d.admin_cap_id=h.admin_cap_id;break;case`${e}::factory::InitFactoryEvent`:d.pools_id=h.pools_id;break;case`${e}::rewarder::RewarderInitEvent`:d.global_vault_id=h.global_vault_id;break;case`${e}::partner::InitPartnerEvent`:d.partners_id=h.partners_id;break;default:break}}),this._sdk.updateCache(i,d,vi)),d}async getPoolTransactionList({pool_id:t,pagination_args:e,order:i="descending",full_rpc_url:n}){let{FullClient:r,sdkOptions:a}=this._sdk,l;n?l=sa(new oa({url:n})):l=r;let d={data:[],has_next_page:!1},f=50,h=e,b=e.limit||10,P=a.env==="testnet"?ir:tr;do{let k=await l.queryTransactionBlocksByPage({ChangedObject:t},{...h,limit:50},i);k.data.forEach((T,S)=>{d.next_cursor=k.next_cursor;let $=Zo(T,S,P,t);d.data=[...d.data,...$]}),d.has_next_page=k.has_next_page,d.next_cursor=k.next_cursor,h.cursor=k.next_cursor}while(d.data.length<b&&d.has_next_page);return d.data.length>b&&(d.data=d.data.slice(0,b),d.next_cursor=d.data[d.data.length-1].tx),d}async calculateCreatePoolWithPrice(t){let{current_price:e,slippage:i,tick_spacing:n,add_mode_params:r,price_base_coin:a,coin_decimals_a:l,coin_decimals_b:d}=t,f=vn.priceToSqrtPriceX64(a==="coin_a"?Re(e):Re(1).div(e),l,d),h=0,b=0;if(r.is_full_range)h=rr.getMinIndex(n),b=rr.getMaxIndex(n);else{let{min_price:N,max_price:D}=r;h=vn.priceToInitializeTickIndex(a==="coin_a"?Re(N):Re(1).div(D),l,d,n),b=vn.priceToInitializeTickIndex(a==="coin_a"?Re(D):Re(1).div(N),l,d,n)}let{coin_amount:P,fix_amount_a:k}=t,{coin_amount_limit_a:T,coin_amount_limit_b:S,liquidity_amount:$,coin_amount_a:q,coin_amount_b:z}=ra.estLiquidityAndCoinAmountFromOneAmounts(h,b,new sr.default(P),k,!0,i,f);return{coin_amount_a:q,coin_amount_b:z,coin_amount_limit_a:T,coin_amount_limit_b:S,liquidity:$,initialize_sqrt_price:f.toString(),tick_lower:h,tick_upper:b,fix_amount_a:k}}async createPoolAndAddLiquidity(t,e){e=e||new Ie,e.setSender(this.sdk.getSenderAddress());let{integrate:i,clmm_pool:n}=this.sdk.sdkOptions,r=Ci(n),a=r.global_config_id,l=r.pools_id,d=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),f=Pi.buildCoinForAmount(e,d,BigInt(t.amount_a),t.coin_type_a,!1,!0),h=Pi.buildCoinForAmount(e,d,BigInt(t.amount_b),t.coin_type_b,!1,!0),b=[e.object(a),e.object(l),e.pure.u32(t.tick_spacing),e.pure.u128(t.initialize_sqrt_price),e.pure.string(t.uri),e.pure.u32(Number(Ee(BigInt(t.tick_lower)).toString())),e.pure.u32(Number(Ee(BigInt(t.tick_upper)).toString())),f.target_coin,h.target_coin,e.pure.bool(t.fix_amount_a),e.object(nr)];return e.moveCall({target:`${i.published_at}::pool_creator_v3::create_pool_v3`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:b}),wi(this._sdk,e,f.target_coin,t.coin_type_a),wi(this._sdk,e,h.target_coin,t.coin_type_b),e}async createPoolAndAddLiquidityRow(t,e){e=e||new Ie;let{clmm_pool:i}=this.sdk.sdkOptions,n=Ci(i),r=n.global_config_id,a=n.pools_id,l=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),d=Pi.buildCoinForAmount(e,l,BigInt(t.amount_a),t.coin_type_a,!1,!0),f=Pi.buildCoinForAmount(e,l,BigInt(t.amount_b),t.coin_type_b,!1,!0),h=[e.object(r),e.object(a),e.pure.u32(t.tick_spacing),e.pure.u128(t.initialize_sqrt_price),e.pure.string(t.uri),e.pure.u32(Number(Ee(BigInt(t.tick_lower)).toString())),e.pure.u32(Number(Ee(BigInt(t.tick_upper)).toString())),d.target_coin,f.target_coin,e.pure.bool(t.fix_amount_a),e.object(nr)],b=e.moveCall({target:`${i.published_at}::pool_creator::create_pool_v3`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:h});return{tx:e,pos_id:b[0],remain_coin_a:b[1],remain_coin_b:b[2],remain_coin_type_a:t.coin_type_a,remain_coin_type_b:t.coin_type_b}}async createPoolWithPriceReturnPositionPayload(t,e){let{coin_type_a:i,coin_type_b:n,tick_spacing:r,uri:a,calculate_result:l}=t,{initialize_sqrt_price:d,tick_lower:f,tick_upper:h,liquidity:b,coin_amount_a:P,coin_amount_b:k,fix_amount_a:T,coin_amount_limit_a:S,coin_amount_limit_b:$}=l;return this.createPoolRowPayload({tick_spacing:r,initialize_sqrt_price:d,uri:a||"",coin_type_a:i,coin_type_b:n,amount_a:T?P:S,amount_b:T?$:k,fix_amount_a:T,tick_lower:f,tick_upper:h},e)}async createPoolWithPricePayload(t){let{coin_type_a:e,coin_type_b:i,tick_spacing:n,uri:r,calculate_result:a}=t,{initialize_sqrt_price:l,tick_lower:d,tick_upper:f,liquidity:h,coin_amount_a:b,coin_amount_b:P,fix_amount_a:k,coin_amount_limit_a:T,coin_amount_limit_b:S}=a;return this.createPoolPayload({tick_spacing:n,initialize_sqrt_price:l,uri:r||"",coin_type_a:e,coin_type_b:i,amount_a:k?b:T,amount_b:k?S:P,fix_amount_a:k,tick_lower:d,tick_upper:f})}async fetchTicks(t){let e=[],i=[];for(;;){let r=await this.getTicks({pool_id:t.pool_id,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,start:i,limit:512});if(e=[...e,...r],r.length<512)break;i=[Number(Ee(BigInt(r[r.length-1].index)))]}return e}async getTicks(t){let{integrate:e}=this.sdk.sdkOptions,i=[],n=[t.coin_type_a,t.coin_type_b],r=new Ie,a=r.makeMoveVec({elements:t.start.map(f=>r.pure.u32(f)),type:"u32"}),l=[r.object(t.pool_id),a,r.pure.u64(t.limit.toString())];r.moveCall({target:`${e.published_at}::${Jt}::fetch_ticks`,arguments:l,typeArguments:n});let d=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:Oe("0x0")});return d.error!=null&&F("InvalidTickObjectId",`getTicks error code: ${d.error??"unknown error"}, please check config and tick object ids`,{[J.METHOD_NAME]:"getTicks",[J.REQUEST_PARAMS]:t}),d.events?.forEach(f=>{Fe(f.type).name==="FetchTicksResultEvent"&&f.parsedJson.ticks.forEach(h=>{i.push(Ho(h))})}),i}async fetchPoolPositionInfoList(t){let{integrate:e}=this.sdk.sdkOptions,i=[],n=[],r=512;for(;;){let a=[t.coin_type_a,t.coin_type_b],l=new Ie,d=l.pure.vector("id",n.map(P=>P)),f=[l.object(t.pool_id),d,l.pure.u64(r)];l.moveCall({target:`${e.published_at}::${Jt}::fetch_positions`,arguments:f,typeArguments:a});let h=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:l,sender:Oe("0x0")});h.error!=null&&F("InvalidPositionRewardObject",`fetch position info error code: ${h.error??"unknown error"}, please check config and tick object ids`,{[J.METHOD_NAME]:"fetchPoolPositionInfoList",[J.REQUEST_PARAMS]:t});let b=[];if(h?.events?.forEach(P=>{Fe(P.type).name==="FetchPositionsEvent"&&P.parsedJson.positions.forEach(k=>{let T=Ze(k);b.push(T)})}),i.push(...b),b.length<r)break;n=[b[b.length-1].pos_object_id]}return i}async fetchTicksByRpc(t){let e=[],i=null,n=50;for(;;){let r=[],a=await this.sdk.FullClient.getDynamicFields({parentId:t,cursor:i,limit:n});if(i=a.nextCursor,a.data.forEach(l=>{Fe(l.objectType).module==="skip_list"&&r.push(l.objectId)}),e=[...e,...await this.getTicksByRpc(r)],!a.hasNextPage)break}return e}async getTicksByRpc(t){let e=[],i=await this.sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let n of i){(n.error!=null||n.data?.content?.dataType!=="moveObject")&&F("InvalidTickObjectId",`getTicksByRpc error code: ${n.error?.code??"unknown error"}, please check config and tick object ids`,{[J.METHOD_NAME]:"getTicksByRpc"});let r=yi(n);r!=null&&e.push(r)}return e}async getTickDataByIndex(t,e){let i={type:"u64",value:Ee(BigInt(la(e).toString())).toString()},n=await this.sdk.FullClient.getDynamicFieldObject({parentId:t,name:i});return(n.error!=null||n.data?.content?.dataType!=="moveObject")&&F("InvalidTickIndex",`get tick by index: ${e} error: ${n.error}`,{[J.METHOD_NAME]:"getTickDataByIndex"}),yi(n)}async getTickDataByObjectId(t){let e=await this.sdk.FullClient.getObject({id:t,options:{showContent:!0}});return(e.error!=null||e.data?.content?.dataType!=="moveObject")&&F("InvalidTickObjectId",`getTicksByRpc error code: ${e.error?.code??"unknown error"}, please check config and tick object ids`,{[J.METHOD_NAME]:"getTickDataByObjectId"}),yi(e)}async getPartnerRefFeeAmount(t,e=!0){let i=await this._sdk.FullClient.batchGetObjects([t],{showOwner:!0,showContent:!0,showDisplay:e,showType:!0});i[0].data?.content?.dataType!=="moveObject"&&F("NotFoundPartnerObject",`get partner by object id: ${t} error: ${i[0].error}`,{[J.METHOD_NAME]:"getPartnerRefFeeAmount"});let n=i[0].data.content.fields.balances,r=await this._sdk.FullClient.getDynamicFieldsByPage(n.fields.id.id),a=[];r.data.forEach(f=>{f.objectId!=null&&a.push(f.objectId)});let l=[];return(await this._sdk.FullClient.batchGetObjects(a,{showOwner:!0,showContent:!0,showDisplay:e,showType:!0})).forEach(f=>{(f.error!=null||f.data?.content?.dataType!=="moveObject")&&F("InvalidPartnerRefFeeFields",`get coin by object id: ${f.data.objectId} error: ${f.error}`,{[J.METHOD_NAME]:"getPartnerRefFeeAmount"});let h={coin_type:f.data.content.fields.name,coin_object_id:f.data.objectId,balance:BigInt(f.data.content.fields.value)};l.push(h)}),l}async claimPartnerRefFeePayload(t,e,i){let n=new Ie,{clmm_pool:r}=this.sdk.sdkOptions,{global_config_id:a}=Ci(r),l=[i],d=[n.object(a),n.object(t),n.object(e)];return n.moveCall({target:`${r.published_at}::${cn}::claim_ref_fee`,arguments:d,typeArguments:l}),n}async getPoolStatus(t){try{let e=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x1::string::String",value:"pool_status"}}),n=aa(e).position.fields.status;if(n)return n}catch(e){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",e)}}async claimAllPartnerRefFeesPayload(t,e,i){try{let{clmm_pool:n}=this._sdk.sdkOptions,{global_config_id:r}=Ci(n),a=await this.getPartnerRefFeeAmount(t,!0),l=new Ie;if(a.length===0)return{ref_fees:[],tx:l};for(let d of a){let f=d.coin_type;d.balance!==BigInt(0)&&(i&&i.length>0&&!i.includes(f)||l.moveCall({target:`${n.published_at}::${cn}::claim_ref_fee`,arguments:[l.object(r),l.object(e),l.object(t)],typeArguments:[f]}))}return{ref_fees:a,tx:l}}catch(n){return jt("InvalidPartnerRefFeeFields",n,{[J.METHOD_NAME]:"claimAllPartnerRefFeesPayload",[J.REQUEST_PARAMS]:{partner:t,partner_cap:e,specific_coin_types:i}})}}};var ze=se(Gt());import{SuiClient as ua}from"@mysten/sui/client";import{Transaction as ce}from"@mysten/sui/transactions";import{isValidSuiObjectId as da,normalizeSuiAddress as fa}from"@mysten/sui/utils";import{asUintN as Be,ClmmPoolUtil as ar,CLOCK_ADDRESS as Mi,CoinAssist as je,d as ie,DETAILS_KEYS as he,extractStructTagFromType as _a,getObjectFields as cr,getPackagerConfigs as ne,TickMath as Ne,TickUtil as Ti,createFullClient as ha,deriveDynamicFieldIdByType as pa}from"@cetusprotocol/common-sdk";var Ai=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}buildPositionType(){return`${this._sdk.sdkOptions.clmm_pool.package_id}::position::Position`}async getPositionTransactionList({pos_id:t,origin_pos_id:e,full_rpc_url:i,pagination_args:n="all",order:r="ascending"}){let{FullClient:a}=this._sdk,l=[t];e&&l.push(e);let d;i?d=ha(new ua({url:i})):d=a;let f={data:[],has_next_page:!1};try{let h=await d.queryTransactionBlocksByPage({ChangedObject:t},n,r);return h.data.forEach((b,P)=>{let k=Wo(b,P,l);f.data=[...f.data,...k]}),f.has_next_page=h.has_next_page,f.next_cursor=h.next_cursor,f}catch(h){jt("FetchError",h,{[he.METHOD_NAME]:"getPositionTransactionList"})}return f}async getPositionList(t,e=[],i=!0){let n=[],r=await this._sdk.FullClient.getOwnedObjectsByPage(t,{options:{showType:!0,showContent:!0,showDisplay:i,showOwner:!0},filter:{Package:this._sdk.sdkOptions.clmm_pool.package_id}}),a=e.length>0;for(let l of r.data)if(_a(l.data.type).full_address===this.buildPositionType()){let f=bi(l),h=`${f.pos_object_id}_getPositionList`;this._sdk.updateCache(h,f),a?e.includes(f.pool)&&n.push(f):n.push(f)}return n}async getPosition(t,e,i=!0,n=!0){let r=await this.getSimplePosition(e,n);return i&&(r=await this.updatePositionInfo(t,r)),r}async getPositionById(t,e=!0,i=!0){let n=await this.getSimplePosition(t,i);if(e){let r=await this._sdk.Pool.getPool(n.pool,!1);return await this.updatePositionInfo(r.position_manager.positions_handle,n)}return n}async getSimplePosition(t,e=!0){let i=`${t}_getPositionList`,n=this.getSimplePositionByCache(t);if(n===void 0){let r=await this.sdk.FullClient.getObject({id:t,options:{showContent:!0,showType:!0,showDisplay:e,showOwner:!0}});n=bi(r),this._sdk.updateCache(i,n)}return n}getSimplePositionByCache(t){let e=`${t}_getPositionList`;return this._sdk.getCache(e)}async getSimplePositionList(t,e=!0){let i=[],n=[];return t.forEach(r=>{let a=this.getSimplePositionByCache(r);a?i.push(a):n.push(r)}),n.length>0&&(await this._sdk.FullClient.batchGetObjects(n,{showOwner:!0,showContent:!0,showDisplay:e,showType:!0})).forEach(a=>{if(a.error==null){let l=bi(a);i.push(l);let d=`${l.pos_object_id}_getPositionList`;this._sdk.updateCache(d,l)}}),i}async updatePositionInfo(t,e){let i=await this.getPositionInfo(t,e.pos_object_id);return{...e,...i}}async getPositionInfo(t,e){try{let i=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x2::object::ID",value:e}}),r=cr(i.data).value.fields.value;return Ze(r)}catch(i){return jt("FetchError",i,{[he.METHOD_NAME]:"getPositionInfo",[he.REQUEST_PARAMS]:{position_handle:t,position_id:e}})}}async getPositionInfoList(t){try{let e=[],i=[];return t.forEach(async r=>{let{position_handle:a,position_ids:l}=r;l.forEach(d=>{let f=pa(a,d,"0x2::object::ID","address");i.push(f)})}),i.length===0?[]:((await this._sdk.FullClient.batchGetObjects(i,{showContent:!0,showType:!0,showOwner:!0})).forEach(r=>{try{let l=cr(r.data).value.fields.value,d=Ze(l);e.push(d)}catch(a){console.log("getPositionInfoList error",a)}}),e)}catch(e){return jt("FetchError",e,{[he.METHOD_NAME]:"getPositionInfoList",[he.REQUEST_PARAMS]:{options:t}})}}buildFetchPosFee(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions,r=[t.coin_type_a,t.coin_type_b],a=[e.object(ne(i).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id)];e.moveCall({target:`${n.published_at}::${Jt}::fetch_position_fees`,arguments:a,typeArguments:r})}parsedPosFeeData(t){let e={},i=t.events?.filter(n=>n.type.includes("fetcher_script::FetchPositionFeesEvent"));for(let n=0;n<i.length;n+=1){let{parsedJson:r}=i[n],a={position_id:r.position_id,fee_owned_a:r.fee_owned_a,fee_owned_b:r.fee_owned_b};e[r.position_id]=a}return e}async fetchPosFeeAmount(t){let{clmm_pool:e,integrate:i}=this.sdk.sdkOptions,n=new ce;for(let d of t)this.buildFetchPosFee(d,n);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:fa("0x0")});r.error!=null&&F("InvalidPoolObject",`fetch position fee error code: ${r.error??"unknown error"}, please check config and position and pool object ids`,{[he.METHOD_NAME]:"fetchPosFeeAmount"});let a=[],l=this.parsedPosFeeData(r);for(let d=0;d<t.length;d+=1){let f=l[t[d].position_id];if(f){let h={fee_owned_a:f.fee_owned_a,fee_owned_b:f.fee_owned_b,position_id:t[d].position_id};a.push(h)}}return a}async batchFetchPositionFees(t){let e=[];for(let n of t){let r=await this._sdk.Position.getPositionById(n,!1),a=await this._sdk.Pool.getPool(r.pool,!1);e.push({pool_id:a.id,position_id:r.pos_object_id,coin_type_a:a.coin_type_a,coin_type_b:a.coin_type_b})}let i={};if(e.length>0){let n=await this.fetchPosFeeAmount(e);for(let r of n)i[r.position_id]=r;return i}return i}async createAddLiquidityFixTokenPayload(t,e,i,n,r){let a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:l,is_adjust_coin_b:d}=Se(t);if(t=t,t.fix_amount_a&&l||!t.fix_amount_a&&d)return i=await Ut.buildAddLiquidityFixTokenForGas(this._sdk,a,t,e,i,n,r),i}return Ut.buildAddLiquidityFixToken(this._sdk,a,t,i,n,r)}async createAddLiquidityPayload(t,e,i,n){let{integrate:r,clmm_pool:a}=this._sdk.sdkOptions,l=Be(BigInt(t.tick_lower)).toString(),d=Be(BigInt(t.tick_upper)).toString(),f=[t.coin_type_a,t.coin_type_b];e=e||new ce;let h=!da(t.pos_id),b=BigInt(t.max_amount_a),P=BigInt(t.max_amount_b),k,T;if(i==null||n==null){let S=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());k=je.buildCoinForAmount(e,S,b,t.coin_type_a,!1,!0),T=je.buildCoinForAmount(e,S,P,t.coin_type_b,!1,!0)}else k={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},T={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]};if(h)e.moveCall({target:`${r.published_at}::${Qt}::open_position_with_liquidity`,typeArguments:f,arguments:[e.object(ne(a).global_config_id),e.object(t.pool_id),e.pure.u32(Number(l)),e.pure.u32(Number(d)),k.target_coin,T.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(Mi)]});else{let S=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());e=Ut.createCollectRewarderAndFeeParams(this._sdk,e,t,S,k.remain_coins,T.remain_coins),e.moveCall({target:`${r.published_at}::${Qt}::add_liquidity`,typeArguments:f,arguments:[e.object(ne(a).global_config_id),e.object(t.pool_id),e.object(t.pos_id),k.target_coin,T.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(Mi)]})}return e}async removeLiquidityPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new ce;let r=[t.coin_type_a,t.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());e=Ut.createCollectRewarderAndFeeParams(this._sdk,e,t,a);let l=[e.object(ne(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.u128(t.delta_liquidity),e.object(Mi)],[d,f]=e.moveCall({target:`${i.published_at}::pool::remove_liquidity`,typeArguments:r,arguments:l}),h=je.fromBalance(d,t.coin_type_a,e),b=je.fromBalance(f,t.coin_type_b,e);return e.moveCall({target:`${n.published_at}::${me}::check_coin_threshold`,typeArguments:[t.coin_type_a],arguments:[h,e.pure.u64(t.min_amount_a)]}),e.moveCall({target:`${n.published_at}::${me}::check_coin_threshold`,typeArguments:[t.coin_type_b],arguments:[b,e.pure.u64(t.min_amount_b)]}),t.is_return_coins?{coin_a:h,coin_b:b}:(e.transferObjects([h,b],this.sdk.getSenderAddress()),e)}async closePositionPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new ce;let r=[t.coin_type_a,t.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return e=Ut.createCollectRewarderAndFeeParams(this._sdk,e,t,a),e.moveCall({target:`${n.published_at}::${oi}::close_position`,typeArguments:r,arguments:[e.object(ne(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.u64(t.min_amount_a),e.pure.u64(t.min_amount_b),e.object(Mi)]}),e}openPositionPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new ce;let r=[t.coin_type_a,t.coin_type_b],a=Be(BigInt(t.tick_lower)).toString(),l=Be(BigInt(t.tick_upper)).toString(),d=[e.object(ne(i).global_config_id),e.object(t.pool_id),e.pure.u32(Number(a)),e.pure.u32(Number(l))];return e.moveCall({target:`${n.published_at}::${oi}::open_position`,typeArguments:r,arguments:d}),e}async openPositionWithPricePayload(t,e){let{pool_id:i}=t,{clmm_pool:n,integrate:r}=this.sdk.sdkOptions;e=e||new ce;let a=await this.sdk.Pool.getPool(i,!1),l=Number(a.tick_spacing),d=0,f=0;if(t.is_full_range)d=Ti.getMinIndex(l),f=Ti.getMaxIndex(l);else{let{price_base_coin:P,min_price:k,max_price:T}=t;d=Ne.priceToInitializeTickIndex(P==="coin_a"?ie(k):ie(1).div(T),t.coin_decimals_a,t.coin_decimals_b,l),f=Ne.priceToInitializeTickIndex(P==="coin_a"?ie(T):ie(1).div(k),t.coin_decimals_a,t.coin_decimals_b,l)}let h=[a.coin_type_a,a.coin_type_b],b=[e.object(ne(n).global_config_id),e.object(t.pool_id),e.pure.u32(Number(Be(BigInt(d)))),e.pure.u32(Number(Be(BigInt(f))))];return e.moveCall({target:`${r.published_at}::${oi}::open_position`,typeArguments:h,arguments:b}),e}async collectFeePayload(t,e,i,n){e=e||new ce;let r=i||je.buildCoinWithBalance(BigInt(0),t.coin_type_a,e),a=n||je.buildCoinWithBalance(BigInt(0),t.coin_type_b,e);return this.createCollectFeePayload(t,e,r,a),e}createCollectFeePayload(t,e,i,n){let{clmm_pool:r,integrate:a}=this.sdk.sdkOptions,l=[t.coin_type_a,t.coin_type_b],d=[e.object(ne(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),i,n];return e.moveCall({target:`${a.published_at}::${Qt}::collect_fee`,typeArguments:l,arguments:d}),e}async calculateAddLiquidityResultWithPrice(t){let{pool_id:e,slippage:i,refresh_pool_price:n,add_mode_params:r}=t,a=await this.sdk.Pool.getPool(e,n),l=Number(a.tick_spacing),d=0,f=0;if(r.is_full_range)d=Ti.getMinIndex(l),f=Ti.getMaxIndex(l);else{let{price_base_coin:q,min_price:z,max_price:N}=r;d=Ne.priceToInitializeTickIndex(q==="coin_a"?ie(z):ie(1).div(N),r.coin_decimals_a,r.coin_decimals_b,l),f=Ne.priceToInitializeTickIndex(q==="coin_a"?ie(N):ie(1).div(z),r.coin_decimals_a,r.coin_decimals_b,l)}if("liquidity"in t){let{liquidity:q}=t,z=Ne.tickIndexToSqrtPriceX64(d),N=Ne.tickIndexToSqrtPriceX64(f),{coin_amount_a:D,coin_amount_b:qt}=ar.getCoinAmountFromLiquidity(new ze.default(q),new ze.default(a.current_sqrt_price),z,N,!1),W=ie(D).mul(1+i).toFixed(0,I.ROUND_UP),$t=ie(qt).mul(1+i).toFixed(0,I.ROUND_UP);return{coin_amount_a:D,coin_amount_b:qt,coin_amount_limit_a:W,coin_amount_limit_b:$t,liquidity:q,tick_lower:d,tick_upper:f}}let{coin_amount:h,fix_amount_a:b}=t,{coin_amount_limit_a:P,coin_amount_limit_b:k,liquidity_amount:T,coin_amount_a:S,coin_amount_b:$}=ar.estLiquidityAndCoinAmountFromOneAmounts(d,f,new ze.default(h),b,!0,i,new ze.default(a.current_sqrt_price));return{coin_amount_a:S,coin_amount_b:$,coin_amount_limit_a:P,coin_amount_limit_b:k,liquidity:T,tick_lower:d,tick_upper:f,fix_amount_a:b}}async addLiquidityWithPricePayload(t,e,i,n){let{pool_id:r,calculate_result:a}=t,{coin_amount_limit_a:l,coin_amount_limit_b:d,liquidity:f,tick_lower:h,tick_upper:b}=a;e=e||new ce;let P=await this.sdk.Pool.getPool(r,!1);return await this.createAddLiquidityPayload({delta_liquidity:f,max_amount_a:l,max_amount_b:d,tick_lower:h,tick_upper:b,collect_fee:!1,rewarder_coin_types:[],coin_type_a:P.coin_type_a,coin_type_b:P.coin_type_b,pool_id:r,pos_id:""},e,i,n),e}async createAddLiquidityFixCoinWithPricePayload(t,e,i,n){let{pool_id:r,calculate_result:a}=t,{coin_amount_limit_a:l,coin_amount_limit_b:d,liquidity:f,tick_lower:h,tick_upper:b,fix_amount_a:P,coin_amount_a:k,coin_amount_b:T}=a;if(P===void 0)throw F("InvalidParams","fix_amount_a is undefined",{[he.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[he.REQUEST_PARAMS]:t});e=e||new ce;let S=await this.sdk.Pool.getPool(r,!1);return await this.createAddLiquidityFixTokenPayload({amount_a:P?k:l,amount_b:P?d:T,slippage:0,fix_amount_a:P,is_open:!0,tick_lower:h,tick_upper:b,collect_fee:!1,rewarder_coin_types:[],coin_type_a:S.coin_type_a,coin_type_b:S.coin_type_b,pool_id:r,pos_id:""},void 0,e,i,n),e}createCollectFeeNoSendPayload(t,e,i,n){let{clmm_pool:r,integrate:a}=this.sdk.sdkOptions,l=[t.coin_type_a,t.coin_type_b],d=[e.object(ne(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),i,n];return e.moveCall({target:`${a.published_at}::${ri}::collect_fee`,typeArguments:l,arguments:d}),e}createCollectFeeAndReturnCoinsPayload(t,e){let{clmm_pool:i}=this.sdk.sdkOptions,n=[t.coin_type_a,t.coin_type_b],r=[e.object(ne(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.bool(!0)],[a,l]=e.moveCall({target:`${i.published_at}::pool::collect_fee`,typeArguments:n,arguments:r});return{fee_a:a,fee_b:l}}};var Mn=se(Gt());import{Transaction as Pn}from"@mysten/sui/transactions";import{normalizeSuiAddress as ma}from"@mysten/sui/utils";import{CLOCK_ADDRESS as Si,CoinAssist as Cn,DETAILS_KEYS as lr,getPackagerConfigs as Ge,MathUtil as ga,normalizeCoinType as kn,ZERO as qe}from"@cetusprotocol/common-sdk";var xi=class{constructor(t){this._sdk=t,this.growthGlobal=[qe,qe,qe]}get sdk(){return this._sdk}async emissionsEveryDay(t){let i=(await this.sdk.Pool.getPool(t)).rewarder_infos;if(!i)return null;let n=[];for(let r of i){let a=ga.fromX64(new Mn.default(r.emissions_per_second));n.push({emissions:Math.floor(a.toNumber()*60*60*24),coin_type:r.coin_type})}return n}async batchFetchPositionRewarders(t){let e=[];for(let n of t){let r=await this._sdk.Position.getPositionById(n,!1),a=await this._sdk.Pool.getPool(r.pool,!1);e.push({pool_id:a.id,position_id:r.pos_object_id,coin_type_a:a.coin_type_a,coin_type_b:a.coin_type_b,rewarder_types:a.rewarder_infos.map(l=>l.coin_type)})}let i={};if(e.length>0){let n=await this.fetchPosRewardersAmount(e);for(let r of n)i[r.position_id]=r.rewarder_amounts;return i}return i}async fetchPositionRewarders(t,e){let i={pool_id:t.id,position_id:e,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,rewarder_types:t.rewarder_infos.map(r=>r.coin_type)};return(await this.fetchPosRewardersAmount([i]))[0].rewarder_amounts}async batchFetchPositionFees(t){return await this._sdk.Position.batchFetchPositionFees(t)}async fetchPosFeeAmount(t){return await this._sdk.Position.fetchPosFeeAmount(t)}buildFetchPosReward(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions,r=[t.coin_type_a,t.coin_type_b],a=[e.object(Ge(i).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id),e.object(Si)];e.moveCall({target:`${n.published_at}::${Jt}::fetch_position_rewards`,arguments:a,typeArguments:r})}async fetchPosRewardersAmount(t){let e=new Pn;for(let a of t)this.buildFetchPosReward(a,e);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:e,sender:ma("0x")});i.error!=null&&F("InvalidConfig",`fetch position rewards error code: ${i.error??"unknown error"}, please check config and params`,{[lr.METHOD_NAME]:"fetchPosRewardersAmount",[lr.REQUEST_PARAMS]:{params:t}});let n=this.parsedPosRewardData(i),r=[];for(let a=0;a<t.length;a+=1){let l=n[t[a].position_id];if(l){let d={pool_id:t[a].pool_id,position_id:t[a].position_id,rewarder_amounts:l.rewarder_amount.map((f,h)=>({amount_owned:f,coin_type:t[a].rewarder_types[h]}))};r.push(d)}}return r}parsedPosRewardData(t){let e={},i=t.events?.filter(n=>n.type.includes("fetcher_script::FetchPositionRewardsEvent"));for(let n=0;n<i.length;n+=1){let{parsedJson:r}=i[n],a={position_id:r.position_id,rewarder_amount:r.data};e[r.position_id]=a}return e}async fetchPoolRewardersAmount(t,e){let i=await this.sdk.Pool.getPool(e),n=await this.sdk.Position.getPositionList(t,[e]),r=[];for(let d of n)r.push({pool_id:i.id,position_id:d.pos_object_id,rewarder_types:i.rewarder_infos.map(f=>f.coin_type),coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b});let a=await this.fetchPosRewardersAmount(r),l=[qe,qe,qe];if(a!=null)for(let d of a)for(let f=0;f<d.rewarder_amounts.length;f+=1)l[f]=l[f].add(new Mn.default(d.rewarder_amounts[f].amount_owned));return l}async getPoolLowerAndUpperTicks(t,e){let i=[],n=[];for(let r of e){let a=await this.sdk.Pool.getTickDataByIndex(t,r.tick_lower_index),l=await this.sdk.Pool.getTickDataByIndex(t,r.tick_upper_index);i.push(a),n.push(l)}return[i,n]}async collectRewarderPayload(t){let e=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null),i=new Pn;return i=Ut.createCollectRewarderAndFeeParams(this._sdk,i,t,e),i}async batchCollectRewardsPayload(t,e,i,n){let r=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null);e=e||new Pn;let a={};return t.forEach(l=>{let d=kn(l.coin_type_a),f=kn(l.coin_type_b);if(l.collect_fee){let b=a[d];b==null&&(i==null?b=Cn.buildCoinForAmount(e,r,BigInt(0),d,!1):b={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},a[d]=b);let P=a[f];P==null&&(n==null?P=Cn.buildCoinForAmount(e,r,BigInt(0),f,!1):P={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},a[f]=P),e=this._sdk.Position.createCollectFeeNoSendPayload({pool_id:l.pool_id,pos_id:l.pos_id,coin_type_a:l.coin_type_a,coin_type_b:l.coin_type_b},e,b.target_coin,P.target_coin)}let h=[];l.rewarder_coin_types.forEach(b=>{let P=kn(b),k=a[b];k===void 0&&(k=Cn.buildCoinForAmount(e,r,BigInt(0),P,!1),a[P]=k),h.push(k.target_coin)}),e=this.createCollectRewarderNoSendPayload(l,e,h)}),Object.keys(a).forEach(l=>{let d=a[l];d.is_mint_zero_coin&&zo(this.sdk,e,d.target_coin,l,this.sdk.getSenderAddress())}),e}createCollectRewarderPayload(t,e,i){let{clmm_pool:n,integrate:r}=this.sdk.sdkOptions,a=Ge(n),l=[t.coin_type_a,t.coin_type_b];return t.rewarder_coin_types.forEach((d,f)=>{e&&e.moveCall({target:`${r.published_at}::${Qt}::collect_reward`,typeArguments:[...l,d],arguments:[e.object(a.global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.object(a.global_vault_id),i[f],e.object(Si)]})}),e}createCollectRewarderNoSendPayload(t,e,i){let{clmm_pool:n,integrate:r}=this.sdk.sdkOptions,a=Ge(n),l=[t.coin_type_a,t.coin_type_b];return t.rewarder_coin_types.forEach((d,f)=>{e&&e.moveCall({target:`${r.published_at}::${ri}::collect_reward`,typeArguments:[...l,d],arguments:[e.object(a.global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.object(a.global_vault_id),i[f],e.object(Si)]})}),e}createCollectRewarderAndReturnCoinPayload(t,e){let{clmm_pool:i}=this.sdk.sdkOptions,n=Ge(i),r=[t.coin_type_a,t.coin_type_b],a=[e.object(Ge(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.object(n.global_vault_id),e.pure.bool(!0),e.object(Si)];return e.moveCall({target:`${i.published_at}::pool::collect_reward`,typeArguments:[...r,t.rewarder_coin_type],arguments:a})}};var ye=se(Gt());import{Transaction as ur}from"@mysten/sui/transactions";import{normalizeSuiAddress as dr}from"@mysten/sui/utils";import{d as De,DETAILS_KEYS as pe,extractStructTagFromType as fr,TickMath as _r,U64_MAX as ba,ZERO as ya}from"@cetusprotocol/common-sdk";var Wl="amm_swap",Zl="Pool",Ii=class{constructor(t){this.calculateSingleImpact=(t,e)=>e.minus(t).div(e).mul(100);this._sdk=t}get sdk(){return this._sdk}calculateSwapFee(t){let e=De(0);return t.forEach(i=>{let n=i.base_paths.length;if(n>0){let r=i.base_paths[0],a=r.label==="Cetus"?new I(r.fee_rate).div(10**6):new I(r.fee_rate).div(10**9),l=De(r.input_amount).div(10**r.from_decimal).mul(a);if(e=e.add(l),n>1){let d=i.base_paths[1],f=r.direction?r.current_price:new I(1).div(r.current_price),h=d.direction?d.current_price:new I(1).div(d.current_price),b=d.label==="Cetus"?new I(d.fee_rate).div(10**6):new I(d.fee_rate).div(10**9),k=De(d.output_amount).div(10**d.to_decimal).mul(b).div(f.mul(h));e=e.add(k)}}}),e.toString()}calculateSwapPriceImpact(t){let e=De(0);return t.forEach(i=>{let n=i.base_paths.length;if(n===1){let r=i.base_paths[0],a=De(r.output_amount).div(10**r.to_decimal),l=De(r.input_amount).div(10**r.from_decimal),d=a.div(l),f=r.direction?new I(r.current_price):new I(1).div(r.current_price);e=e.add(this.calculateSingleImpact(d,f))}if(n===2){let r=i.base_paths[0],a=i.base_paths[1],l=r.direction?new I(r.current_price):new I(1).div(r.current_price),d=a.direction?new I(a.current_price):new I(1).div(a.current_price),f=l.mul(d),h=new I(a.output_amount).div(10**a.to_decimal),b=new I(r.input_amount).div(10**r.from_decimal),P=h.div(b);e=e.add(this.calculateSingleImpact(P,f))}}),e.toString()}async preSwapWithMultiPool(t){let{integrate:e}=this.sdk.sdkOptions,i=new ur,n=[t.coin_type_a,t.coin_type_b];for(let f=0;f<t.pool_ids.length;f+=1){let h=[i.object(t.pool_ids[f]),i.pure.bool(t.a2b),i.pure.bool(t.by_amount_in),i.pure.u64(t.amount)];i.moveCall({target:`${e.published_at}::${Jt}::calculate_swap_result`,arguments:h,typeArguments:n})}let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:dr("0x0")});r.error!=null&&F("InvalidConfig",`pre swap with multi pools error code: ${r.error??"unknown error"}, please check config and params`,{[pe.METHOD_NAME]:"preSwapWithMultiPool",[pe.REQUEST_PARAMS]:{params:t}});let a=r.events?.filter(f=>fr(f.type).name==="CalculatedSwapResultEvent");if(a.length===0)return null;a.length!==t.pool_ids.length&&F("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[pe.METHOD_NAME]:"preSwapWithMultiPool",[pe.REQUEST_PARAMS]:{params:t}});let l=t.by_amount_in?ya:ba,d=0;for(let f=0;f<a.length;f+=1)if(!a[f].parsedJson.data.is_exceed)if(t.by_amount_in){let h=new ye.default(a[f].parsedJson.data.amount_out);h.gt(l)&&(d=f,l=h)}else{let h=new ye.default(a[f].parsedJson.data.amount_out);h.lt(l)&&(d=f,l=h)}return this.transformSwapWithMultiPoolData({pool_address:t.pool_ids[d],a2b:t.a2b,by_amount_in:t.by_amount_in,amount:t.amount,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b},a[d].parsedJson)}async preSwap(t){let{integrate:e}=this.sdk.sdkOptions,i=new ur,n=[t.coin_type_a,t.coin_type_b],r=[i.object(t.pool.id),i.pure.bool(t.a2b),i.pure.bool(t.by_amount_in),i.pure.u64(t.amount)];i.moveCall({target:`${e.published_at}::${Jt}::calculate_swap_result`,arguments:r,typeArguments:n});let a=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:dr("0x0")});if(a.error!=null)return F("InvalidConfig",`preSwap error code: ${a.error??"unknown error"}, please check config and params`,{[pe.METHOD_NAME]:"preSwap",[pe.REQUEST_PARAMS]:{params:t}});let l=a.events?.filter(d=>fr(d.type).name==="CalculatedSwapResultEvent");return l.length===0?F("InvalidConfig",`preSwap error code: ${a.error??"unknown error"}, please check config and params`,{[pe.METHOD_NAME]:"preSwap",[pe.REQUEST_PARAMS]:{params:t}}):this.transformSwapData(t,l[0].parsedJson.data)}transformSwapData(t,e){let i=e.amount_in&&e.fee_amount?new ye.default(e.amount_in).add(new ye.default(e.fee_amount)).toString():"";return{pool_address:t.pool.id,current_sqrt_price:t.current_sqrt_price,estimated_amount_in:i,estimated_amount_out:e.amount_out,estimated_end_sqrt_price:e.after_sqrt_price,estimated_fee_amount:e.fee_amount,is_exceed:e.is_exceed,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in}}transformSwapWithMultiPoolData(t,e){let{data:i}=e;console.log("json data. ",i);let n=i.amount_in&&i.fee_amount?new ye.default(i.amount_in).add(new ye.default(i.fee_amount)).toString():"";return{pool_address:t.pool_address,estimated_amount_in:n,estimated_amount_out:i.amount_out,estimated_end_sqrt_price:i.after_sqrt_price,estimated_start_sqrt_price:i.step_results[0].current_sqrt_price,estimated_fee_amount:i.fee_amount,is_exceed:i.is_exceed,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in}}calculateRates(t){let{current_pool:e}=t,i=Uo(e),n;t.a2b?n=t.swap_ticks.sort((P,k)=>k.index-P.index):n=t.swap_ticks.sort((P,k)=>P.index-k.index);let r=Vo(t.a2b,t.by_amount_in,t.amount,i,n),a=!1;t.by_amount_in?a=r.amount_in.lt(t.amount):a=r.amount_out.lt(t.amount);let l=te.getDefaultSqrtPriceLimit(t.a2b);t.a2b&&r.next_sqrt_price.lt(l)&&(a=!0),!t.a2b&&r.next_sqrt_price.gt(l)&&(a=!0);let d=0;r.cross_tick_num>6&&r.cross_tick_num<40&&(d=22e3*(r.cross_tick_num-6)),r.cross_tick_num>40&&(a=!0);let f=_r.sqrtPriceX64ToPrice(i.current_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),h=_r.sqrtPriceX64ToPrice(r.next_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),b=Math.abs(f-h)/f*100;return{estimated_amount_in:r.amount_in,estimated_amount_out:r.amount_out,estimated_end_sqrt_price:r.next_sqrt_price,estimated_fee_amount:r.fee_amount,is_exceed:a,extra_compute_limit:d,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in,price_impact_pct:b}}async createSwapPayload(t,e){let i=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:n,is_adjust_coin_b:r}=Se(t);if(t.a2b&&n||!t.a2b&&r)return await te.buildSwapTransactionForGas(this._sdk,t,i,e)}return te.buildSwapTransaction(this.sdk,t,i)}async createSwapWithoutTransferCoinsPayload(t,e){let i=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:n,is_adjust_coin_b:r}=Se(t);if(t.a2b&&n||!t.a2b&&r)return await te.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,t,i,e)}return te.buildSwapTransactionWithoutTransferCoins(this.sdk,t,i)}};import{CLOCK_ADDRESS as wa,CoinAssist as va,DETAILS_KEYS as we,getPackagerConfigs as Tn}from"@cetusprotocol/common-sdk";import{Transaction as hr}from"@mysten/sui/transactions";import{normalizeSuiAddress as Pa}from"@mysten/sui/utils";var Oi=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}async getClmmVestInfoList(){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return F("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[we.METHOD_NAME]:"getClmmVestInfo"});let e=[];try{let i=`${t.package_id}::clmm_vester::CreateEvent`,r=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:i})).data.map(a=>a.parsedJson.clmm_vester_id);return r.length>0&&(await this._sdk.FullClient.batchGetObjects(r,{showContent:!0,showType:!0})).forEach(l=>{let d=ee.parseClmmVestInfo(l),f=`${d.id}-ClmmVestInfo`;this._sdk.updateCache(f,d),e.push(d)}),e}catch(i){jt("ClmmVestFetchError",i,{[we.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(t=!0){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return F("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[we.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:i}=Tn(e),n=`${i}-ClmmVestInfo`,r=this._sdk.getCache(n,t);if(r)return r;try{let a=await this._sdk.FullClient.getObject({id:i,options:{showContent:!0,showType:!0}}),l=ee.parseClmmVestInfo(a);return this._sdk.updateCache(n,l),l}catch(a){return jt("ClmmVestFetchError",a,{[we.METHOD_NAME]:"getClmmVestInfo",[we.REQUEST_PARAMS]:{clmm_vest_id:i}})}}async getPositionVesting(t){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return F("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[we.METHOD_NAME]:"getPositionVesting"});if(t.length===0)return[];let{clmm_vest_id:i}=Tn(e),n=new hr;t.forEach(l=>{let{clmm_pool_id:d,coin_type_a:f,coin_type_b:h,clmm_position_ids:b}=l;n.moveCall({package:e.published_at,module:"clmm_vester",function:"get_positions_vesting",typeArguments:[f,h],arguments:[n.object(i),n.object(d),n.pure.vector("id",b)]})});let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:Pa("0x0")}),a=[];return r.events?.forEach(l=>{if(l.type.includes("clmm_vester::GetPositionsVestingEvent")){let{parsedJson:d}=l;a.push(...d.position_vestings.map(f=>ee.parsePositionVesting(f)))}}),a}buildRedeemPayload(t,e){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return F("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[we.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:n,clmm_vest_id:r,cetus_coin_type:a}=Tn(i);return e=e||new hr,t.forEach(l=>{let{clmm_pool_id:d,clmm_position_id:f,coin_type_a:h,coin_type_b:b,period:P}=l,k=e.moveCall({package:i.published_at,module:"clmm_vester",function:"redeem",arguments:[e.object(n),e.object(r),e.object(d),typeof f=="string"?e.object(f):f,e.pure.u16(P),e.object(wa)],typeArguments:[h,b]}),T=va.fromBalance(k,a,e);e.transferObjects([T],this._sdk.getSenderAddress())}),e}};var Ei=class o extends Ca{constructor(t){super(t),this._swap=new Ii(this),this._pool=new ki(this),this._position=new Ai(this),this._config=new ni(this),this._rewarder=new xi(this),this._vest=new Oi(this)}get Pool(){return this._pool}get Position(){return this._position}get CetusConfig(){return this._config}get Rewarder(){return this._rewarder}get Swap(){return this._swap}get Vest(){return this._vest}static createSDK(t){let{env:e="mainnet"}=t;return e==="mainnet"?o.createCustomSDK({...Yo,...t}):o.createCustomSDK({...er,...t})}static createCustomSDK(t){return new o(t)}};var Qe=se(Gt());import{MathUtil as Le,TickMath as pr}from"@cetusprotocol/common-sdk";var ka=new Qe.default(365),Ma=new Qe.default(24),Ta=new Qe.default(3600),Aa=new Qe.default(.5);function vu(o,t,e,i){return ka.mul(Ma).mul(Ta).mul(Aa).mul(o.mul(t).add(e).div(i))}function Sa(o,t,e,i,n,r){let a=new I(o.toString()).div(new I(10**e)),l=new I(t.toString()).div(new I(10**i));return a.mul(n).add(l.mul(r))}function Pu(o,t,e,i,n,r,a,l,d,f,h,b,P,k,T,S,$,q,z,N,D,qt,W,$t){let oe=new I(b),Zt=new I(P),re=new I(S),L=new I($),Bt=new I(q),w=new I(z),s=new I(N),u=new I(D),_=new I(qt),p=new I(W),g=new I($t),v=pr.tickIndexToSqrtPriceX64(t),C=pr.tickIndexToSqrtPriceX64(e),m=Le.toX64Decimal(Le.fromX64(v)).round(),c=Le.toX64Decimal(Le.fromX64(C)).round(),y=Le.toX64Decimal(Le.fromX64(i)).round(),A,x=oe.mul(new I(10**r)).mul(c.mul(m)).div(c.sub(m)).round(),O=Zt.mul(new I(10**a)).div(c.sub(m)).round();o<t?A=x:o>e?A=O:A=I.min(x,O);let j=A.mul(y.sub(m)),V=A.mul(c.sub(y)).div(y.mul(c)).div(new I(10**r)).mul(s).add(j.div(new I(10**a).mul(u))),zt=Sa(k,T,r,a,s,u),K=V.div(zt),Z=A.eq(new I(0))?new I(0):new I(h/1e4).mul(re).mul(new I(A.toString()).div(new I(n.toString()).add(new I(A.toString())))).div(V),ve=K.eq(new I(0))?new I(0):K.mul(new I(36500/7)).div(V),G=L.div(new I(10**l)).mul(_).mul(ve),Q=Bt.div(new I(10**d)).mul(p).mul(ve),Je=w.div(new I(10**f)).mul(g).mul(ve);return{fee_apr:Z,pos_rewarder_0_apr:G,pos_rewarder_1_apr:Q,pos_rewarder_2_apr:Je}}function Cu(o,t,e,i){let n=Math.max(o,e),a=Math.min(t,i)-n,l=t-o,d=i-e,f=new I(l.toString()),h=new I(d.toString()),b=new I(a.toString()),P=new I("0");return a<0?P=new I("0"):l===a?P=h.div(b):d===a?P=b.div(f):P=b.mul(b).div(h).div(f),P}var xu=Ei;export{Wl as AMM_SWAP_MODULE,Ys as BPS,Ei as CetusClmmSDK,ke as ClmmError,$a as ClmmExpectSwapModule,Jt as ClmmFetcherModule,oi as ClmmIntegratePoolModule,Qt as ClmmIntegratePoolV2Module,ri as ClmmIntegratePoolV3Module,me as ClmmIntegrateRouterModule,bo as ClmmIntegrateRouterWithPartnerModule,yo as ClmmIntegrateUtilsModule,cn as ClmmPartnerModule,mo as ClmmPositionStatus,Me as ConfigErrorCode,ni as ConfigModule,Va as DeepbookClobV2Module,Ua as DeepbookCustodianV2Module,Ka as DeepbookEndpointsV2Module,Zl as POOL_STRUCT,lo as PartnerErrorCode,Ue as PoolErrorCode,ki as PoolModule,ei as PositionErrorCode,Ai as PositionModule,Ut as PositionUtils,xi as RewarderModule,Br as RouterErrorCode,ao as SwapErrorCode,Ii as SwapModule,te as SwapUtils,uo as TypesErrorCode,nn as UtilsErrorCode,co as VestErrorCode,Oi as VestModule,ee as VestUtils,Ic as buildClmmPositionName,gi as buildPool,Zo as buildPoolTransactionInfo,bi as buildPosition,Ze as buildPositionInfo,Wo as buildPositionTransactionInfo,yi as buildTickData,Ho as buildTickDataByEvent,zo as buildTransferCoin,wi as buildTransferCoinToSender,Yo as clmmMainnet,er as clmmTestnet,Vo as computeSwap,Ks as computeSwapStep,xu as default,vu as estPoolAPR,Pu as estPositionAPRWithDeltaMethod,Cu as estPositionAPRWithMultiMethod,tr as eventMainnetContractMaps,ir as eventTestnetContractMaps,Se as findAdjustCoin,Ha as getDefaultSuiInputType,dc as getLowerSqrtPriceFromCoinA,_c as getLowerSqrtPriceFromCoinB,fc as getUpperSqrtPriceFromCoinA,hc as getUpperSqrtPriceFromCoinB,jt as handleError,F as handleMessageError,yc as newBits,go as poolFilterEvenTypes,po as poolLiquiditySnapshotType,Uo as transClmmpoolDataWithoutTicks};
|
|
2
|
-
/*! Bundled license information:
|
|
3
|
-
|
|
4
|
-
decimal.js/decimal.mjs:
|
|
5
|
-
(*!
|
|
6
|
-
* decimal.js v10.6.0
|
|
7
|
-
* An arbitrary-precision Decimal type for JavaScript.
|
|
8
|
-
* https://github.com/MikeMcl/decimal.js
|
|
9
|
-
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
10
|
-
* MIT Licence
|
|
11
|
-
*)
|
|
12
|
-
*/
|
|
13
|
-
//# sourceMappingURL=index.mjs.map
|