@cetusprotocol/sui-clmm-sdk 1.2.1 → 1.2.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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Ao=Object.create;var Xe=Object.defineProperty;var So=Object.getOwnPropertyDescriptor;var xo=Object.getOwnPropertyNames;var Io=Object.getPrototypeOf,Eo=Object.prototype.hasOwnProperty;var Oo=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),Ro=(o,t)=>{for(var e in t)Xe(o,e,{get:t[e],enumerable:!0})},En=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of xo(t))!Eo.call(o,n)&&n!==e&&Xe(o,n,{get:()=>t[n],enumerable:!(i=So(t,n))||i.enumerable});return o};var fe=(o,t,e)=>(e=o!=null?Ao(Io(o)):{},En(t||!o||!o.__esModule?Xe(e,"default",{value:o,enumerable:!0}):e,o)),Fo=o=>En(Xe({},"__esModule",{value:!0}),o);var re=Oo((Xn,Vi)=>{"use strict";(function(o,t){"use strict";function e(y,s){if(!y)throw new Error(s||"Assertion failed")}function i(y,s){y.super_=s;var u=function(){};u.prototype=s.prototype,y.prototype=new u,y.prototype.constructor=y}function n(y,s,u){if(n.isBN(y))return y;this.negative=0,this.words=null,this.length=0,this.red=null,y!==null&&((s==="le"||s==="be")&&(u=s,s=10),this._init(y||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=require("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(y,s){var u=y.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 "+y)}function l(y,s,u){var _=a(y,u);return u-1>=s&&(_|=a(y,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(y,s,u,_){for(var p=0,g=0,v=Math.min(y.length,u),C=s;C<v;C++){var m=y.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,b=_;b<m;b+=p)c=d(s,b,b+p,u),this.imuln(g),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(C!==0){var x=1;for(c=d(s,b,s.length,u),b=0;b<C;b++)x*=u;this.imuln(x),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(y,s){y.words=s.words,y.length=s.length,y.negative=s.negative,y.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 w=["","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],M=[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?_=w[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],b=M[s];_="";var x=this.clone();for(x.negative=0;!x.isZero();){var E=x.modrn(b).toString(s);x=x.idivn(b),x.isZero()?_=E+_:_=w[c-E.length]+E+_}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 S=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=S(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 I(y){for(var s=new Array(y.bitLength()),u=0;u<s.length;u++){var _=u/26|0,p=u%26;s[u]=y.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(y,s,u){u.negative=s.negative^y.negative;var _=y.length+s.length|0;u.length=_,_=_-1|0;var p=y.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 b=m>>>26,x=m&67108863,E=Math.min(c,s.length-1),R=Math.max(0,c-y.length+1);R<=E;R++){var U=c-R|0;p=y.words[U]|0,g=s.words[R]|0,v=p*g+x,b+=v/67108864|0,x=v&67108863}u.words[c]=x|0,m=b|0}return m!==0?u.words[c]=m|0:u.length--,u._strip()}var $=function(s,u,_){var p=s.words,g=u.words,v=_.words,C=0,m,c,b,x=p[0]|0,E=x&8191,R=x>>>13,U=p[1]|0,z=U&8191,Q=U>>>13,oe=p[2]|0,J=oe&8191,it=oe>>>13,Ce=p[3]|0,ot=Ce&8191,rt=Ce>>>13,Je=p[4]|0,st=Je&8191,at=Je>>>13,mn=p[5]|0,ct=mn&8191,lt=mn>>>13,gn=p[6]|0,ut=gn&8191,dt=gn>>>13,bn=p[7]|0,ft=bn&8191,_t=bn>>>13,wn=p[8]|0,ht=wn&8191,pt=wn>>>13,yn=p[9]|0,mt=yn&8191,gt=yn>>>13,vn=g[0]|0,bt=vn&8191,wt=vn>>>13,Pn=g[1]|0,yt=Pn&8191,vt=Pn>>>13,Cn=g[2]|0,Pt=Cn&8191,Ct=Cn>>>13,Mn=g[3]|0,Mt=Mn&8191,kt=Mn>>>13,kn=g[4]|0,Tt=kn&8191,At=kn>>>13,Tn=g[5]|0,St=Tn&8191,xt=Tn>>>13,An=g[6]|0,It=An&8191,Et=An>>>13,Sn=g[7]|0,Ot=Sn&8191,Rt=Sn>>>13,xn=g[8]|0,Ft=xn&8191,Nt=xn>>>13,In=g[9]|0,Bt=In&8191,jt=In>>>13;_.negative=s.negative^u.negative,_.length=19,m=Math.imul(E,bt),c=Math.imul(E,wt),c=c+Math.imul(R,bt)|0,b=Math.imul(R,wt);var mi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(mi>>>26)|0,mi&=67108863,m=Math.imul(z,bt),c=Math.imul(z,wt),c=c+Math.imul(Q,bt)|0,b=Math.imul(Q,wt),m=m+Math.imul(E,yt)|0,c=c+Math.imul(E,vt)|0,c=c+Math.imul(R,yt)|0,b=b+Math.imul(R,vt)|0;var gi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,m=Math.imul(J,bt),c=Math.imul(J,wt),c=c+Math.imul(it,bt)|0,b=Math.imul(it,wt),m=m+Math.imul(z,yt)|0,c=c+Math.imul(z,vt)|0,c=c+Math.imul(Q,yt)|0,b=b+Math.imul(Q,vt)|0,m=m+Math.imul(E,Pt)|0,c=c+Math.imul(E,Ct)|0,c=c+Math.imul(R,Pt)|0,b=b+Math.imul(R,Ct)|0;var bi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,m=Math.imul(ot,bt),c=Math.imul(ot,wt),c=c+Math.imul(rt,bt)|0,b=Math.imul(rt,wt),m=m+Math.imul(J,yt)|0,c=c+Math.imul(J,vt)|0,c=c+Math.imul(it,yt)|0,b=b+Math.imul(it,vt)|0,m=m+Math.imul(z,Pt)|0,c=c+Math.imul(z,Ct)|0,c=c+Math.imul(Q,Pt)|0,b=b+Math.imul(Q,Ct)|0,m=m+Math.imul(E,Mt)|0,c=c+Math.imul(E,kt)|0,c=c+Math.imul(R,Mt)|0,b=b+Math.imul(R,kt)|0;var wi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,m=Math.imul(st,bt),c=Math.imul(st,wt),c=c+Math.imul(at,bt)|0,b=Math.imul(at,wt),m=m+Math.imul(ot,yt)|0,c=c+Math.imul(ot,vt)|0,c=c+Math.imul(rt,yt)|0,b=b+Math.imul(rt,vt)|0,m=m+Math.imul(J,Pt)|0,c=c+Math.imul(J,Ct)|0,c=c+Math.imul(it,Pt)|0,b=b+Math.imul(it,Ct)|0,m=m+Math.imul(z,Mt)|0,c=c+Math.imul(z,kt)|0,c=c+Math.imul(Q,Mt)|0,b=b+Math.imul(Q,kt)|0,m=m+Math.imul(E,Tt)|0,c=c+Math.imul(E,At)|0,c=c+Math.imul(R,Tt)|0,b=b+Math.imul(R,At)|0;var yi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,m=Math.imul(ct,bt),c=Math.imul(ct,wt),c=c+Math.imul(lt,bt)|0,b=Math.imul(lt,wt),m=m+Math.imul(st,yt)|0,c=c+Math.imul(st,vt)|0,c=c+Math.imul(at,yt)|0,b=b+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,b=b+Math.imul(rt,Ct)|0,m=m+Math.imul(J,Mt)|0,c=c+Math.imul(J,kt)|0,c=c+Math.imul(it,Mt)|0,b=b+Math.imul(it,kt)|0,m=m+Math.imul(z,Tt)|0,c=c+Math.imul(z,At)|0,c=c+Math.imul(Q,Tt)|0,b=b+Math.imul(Q,At)|0,m=m+Math.imul(E,St)|0,c=c+Math.imul(E,xt)|0,c=c+Math.imul(R,St)|0,b=b+Math.imul(R,xt)|0;var vi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,m=Math.imul(ut,bt),c=Math.imul(ut,wt),c=c+Math.imul(dt,bt)|0,b=Math.imul(dt,wt),m=m+Math.imul(ct,yt)|0,c=c+Math.imul(ct,vt)|0,c=c+Math.imul(lt,yt)|0,b=b+Math.imul(lt,vt)|0,m=m+Math.imul(st,Pt)|0,c=c+Math.imul(st,Ct)|0,c=c+Math.imul(at,Pt)|0,b=b+Math.imul(at,Ct)|0,m=m+Math.imul(ot,Mt)|0,c=c+Math.imul(ot,kt)|0,c=c+Math.imul(rt,Mt)|0,b=b+Math.imul(rt,kt)|0,m=m+Math.imul(J,Tt)|0,c=c+Math.imul(J,At)|0,c=c+Math.imul(it,Tt)|0,b=b+Math.imul(it,At)|0,m=m+Math.imul(z,St)|0,c=c+Math.imul(z,xt)|0,c=c+Math.imul(Q,St)|0,b=b+Math.imul(Q,xt)|0,m=m+Math.imul(E,It)|0,c=c+Math.imul(E,Et)|0,c=c+Math.imul(R,It)|0,b=b+Math.imul(R,Et)|0;var Pi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Pi>>>26)|0,Pi&=67108863,m=Math.imul(ft,bt),c=Math.imul(ft,wt),c=c+Math.imul(_t,bt)|0,b=Math.imul(_t,wt),m=m+Math.imul(ut,yt)|0,c=c+Math.imul(ut,vt)|0,c=c+Math.imul(dt,yt)|0,b=b+Math.imul(dt,vt)|0,m=m+Math.imul(ct,Pt)|0,c=c+Math.imul(ct,Ct)|0,c=c+Math.imul(lt,Pt)|0,b=b+Math.imul(lt,Ct)|0,m=m+Math.imul(st,Mt)|0,c=c+Math.imul(st,kt)|0,c=c+Math.imul(at,Mt)|0,b=b+Math.imul(at,kt)|0,m=m+Math.imul(ot,Tt)|0,c=c+Math.imul(ot,At)|0,c=c+Math.imul(rt,Tt)|0,b=b+Math.imul(rt,At)|0,m=m+Math.imul(J,St)|0,c=c+Math.imul(J,xt)|0,c=c+Math.imul(it,St)|0,b=b+Math.imul(it,xt)|0,m=m+Math.imul(z,It)|0,c=c+Math.imul(z,Et)|0,c=c+Math.imul(Q,It)|0,b=b+Math.imul(Q,Et)|0,m=m+Math.imul(E,Ot)|0,c=c+Math.imul(E,Rt)|0,c=c+Math.imul(R,Ot)|0,b=b+Math.imul(R,Rt)|0;var Ci=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,m=Math.imul(ht,bt),c=Math.imul(ht,wt),c=c+Math.imul(pt,bt)|0,b=Math.imul(pt,wt),m=m+Math.imul(ft,yt)|0,c=c+Math.imul(ft,vt)|0,c=c+Math.imul(_t,yt)|0,b=b+Math.imul(_t,vt)|0,m=m+Math.imul(ut,Pt)|0,c=c+Math.imul(ut,Ct)|0,c=c+Math.imul(dt,Pt)|0,b=b+Math.imul(dt,Ct)|0,m=m+Math.imul(ct,Mt)|0,c=c+Math.imul(ct,kt)|0,c=c+Math.imul(lt,Mt)|0,b=b+Math.imul(lt,kt)|0,m=m+Math.imul(st,Tt)|0,c=c+Math.imul(st,At)|0,c=c+Math.imul(at,Tt)|0,b=b+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,b=b+Math.imul(rt,xt)|0,m=m+Math.imul(J,It)|0,c=c+Math.imul(J,Et)|0,c=c+Math.imul(it,It)|0,b=b+Math.imul(it,Et)|0,m=m+Math.imul(z,Ot)|0,c=c+Math.imul(z,Rt)|0,c=c+Math.imul(Q,Ot)|0,b=b+Math.imul(Q,Rt)|0,m=m+Math.imul(E,Ft)|0,c=c+Math.imul(E,Nt)|0,c=c+Math.imul(R,Ft)|0,b=b+Math.imul(R,Nt)|0;var Mi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,m=Math.imul(mt,bt),c=Math.imul(mt,wt),c=c+Math.imul(gt,bt)|0,b=Math.imul(gt,wt),m=m+Math.imul(ht,yt)|0,c=c+Math.imul(ht,vt)|0,c=c+Math.imul(pt,yt)|0,b=b+Math.imul(pt,vt)|0,m=m+Math.imul(ft,Pt)|0,c=c+Math.imul(ft,Ct)|0,c=c+Math.imul(_t,Pt)|0,b=b+Math.imul(_t,Ct)|0,m=m+Math.imul(ut,Mt)|0,c=c+Math.imul(ut,kt)|0,c=c+Math.imul(dt,Mt)|0,b=b+Math.imul(dt,kt)|0,m=m+Math.imul(ct,Tt)|0,c=c+Math.imul(ct,At)|0,c=c+Math.imul(lt,Tt)|0,b=b+Math.imul(lt,At)|0,m=m+Math.imul(st,St)|0,c=c+Math.imul(st,xt)|0,c=c+Math.imul(at,St)|0,b=b+Math.imul(at,xt)|0,m=m+Math.imul(ot,It)|0,c=c+Math.imul(ot,Et)|0,c=c+Math.imul(rt,It)|0,b=b+Math.imul(rt,Et)|0,m=m+Math.imul(J,Ot)|0,c=c+Math.imul(J,Rt)|0,c=c+Math.imul(it,Ot)|0,b=b+Math.imul(it,Rt)|0,m=m+Math.imul(z,Ft)|0,c=c+Math.imul(z,Nt)|0,c=c+Math.imul(Q,Ft)|0,b=b+Math.imul(Q,Nt)|0,m=m+Math.imul(E,Bt)|0,c=c+Math.imul(E,jt)|0,c=c+Math.imul(R,Bt)|0,b=b+Math.imul(R,jt)|0;var ki=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(ki>>>26)|0,ki&=67108863,m=Math.imul(mt,yt),c=Math.imul(mt,vt),c=c+Math.imul(gt,yt)|0,b=Math.imul(gt,vt),m=m+Math.imul(ht,Pt)|0,c=c+Math.imul(ht,Ct)|0,c=c+Math.imul(pt,Pt)|0,b=b+Math.imul(pt,Ct)|0,m=m+Math.imul(ft,Mt)|0,c=c+Math.imul(ft,kt)|0,c=c+Math.imul(_t,Mt)|0,b=b+Math.imul(_t,kt)|0,m=m+Math.imul(ut,Tt)|0,c=c+Math.imul(ut,At)|0,c=c+Math.imul(dt,Tt)|0,b=b+Math.imul(dt,At)|0,m=m+Math.imul(ct,St)|0,c=c+Math.imul(ct,xt)|0,c=c+Math.imul(lt,St)|0,b=b+Math.imul(lt,xt)|0,m=m+Math.imul(st,It)|0,c=c+Math.imul(st,Et)|0,c=c+Math.imul(at,It)|0,b=b+Math.imul(at,Et)|0,m=m+Math.imul(ot,Ot)|0,c=c+Math.imul(ot,Rt)|0,c=c+Math.imul(rt,Ot)|0,b=b+Math.imul(rt,Rt)|0,m=m+Math.imul(J,Ft)|0,c=c+Math.imul(J,Nt)|0,c=c+Math.imul(it,Ft)|0,b=b+Math.imul(it,Nt)|0,m=m+Math.imul(z,Bt)|0,c=c+Math.imul(z,jt)|0,c=c+Math.imul(Q,Bt)|0,b=b+Math.imul(Q,jt)|0;var Ti=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ti>>>26)|0,Ti&=67108863,m=Math.imul(mt,Pt),c=Math.imul(mt,Ct),c=c+Math.imul(gt,Pt)|0,b=Math.imul(gt,Ct),m=m+Math.imul(ht,Mt)|0,c=c+Math.imul(ht,kt)|0,c=c+Math.imul(pt,Mt)|0,b=b+Math.imul(pt,kt)|0,m=m+Math.imul(ft,Tt)|0,c=c+Math.imul(ft,At)|0,c=c+Math.imul(_t,Tt)|0,b=b+Math.imul(_t,At)|0,m=m+Math.imul(ut,St)|0,c=c+Math.imul(ut,xt)|0,c=c+Math.imul(dt,St)|0,b=b+Math.imul(dt,xt)|0,m=m+Math.imul(ct,It)|0,c=c+Math.imul(ct,Et)|0,c=c+Math.imul(lt,It)|0,b=b+Math.imul(lt,Et)|0,m=m+Math.imul(st,Ot)|0,c=c+Math.imul(st,Rt)|0,c=c+Math.imul(at,Ot)|0,b=b+Math.imul(at,Rt)|0,m=m+Math.imul(ot,Ft)|0,c=c+Math.imul(ot,Nt)|0,c=c+Math.imul(rt,Ft)|0,b=b+Math.imul(rt,Nt)|0,m=m+Math.imul(J,Bt)|0,c=c+Math.imul(J,jt)|0,c=c+Math.imul(it,Bt)|0,b=b+Math.imul(it,jt)|0;var Ai=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,m=Math.imul(mt,Mt),c=Math.imul(mt,kt),c=c+Math.imul(gt,Mt)|0,b=Math.imul(gt,kt),m=m+Math.imul(ht,Tt)|0,c=c+Math.imul(ht,At)|0,c=c+Math.imul(pt,Tt)|0,b=b+Math.imul(pt,At)|0,m=m+Math.imul(ft,St)|0,c=c+Math.imul(ft,xt)|0,c=c+Math.imul(_t,St)|0,b=b+Math.imul(_t,xt)|0,m=m+Math.imul(ut,It)|0,c=c+Math.imul(ut,Et)|0,c=c+Math.imul(dt,It)|0,b=b+Math.imul(dt,Et)|0,m=m+Math.imul(ct,Ot)|0,c=c+Math.imul(ct,Rt)|0,c=c+Math.imul(lt,Ot)|0,b=b+Math.imul(lt,Rt)|0,m=m+Math.imul(st,Ft)|0,c=c+Math.imul(st,Nt)|0,c=c+Math.imul(at,Ft)|0,b=b+Math.imul(at,Nt)|0,m=m+Math.imul(ot,Bt)|0,c=c+Math.imul(ot,jt)|0,c=c+Math.imul(rt,Bt)|0,b=b+Math.imul(rt,jt)|0;var Si=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Si>>>26)|0,Si&=67108863,m=Math.imul(mt,Tt),c=Math.imul(mt,At),c=c+Math.imul(gt,Tt)|0,b=Math.imul(gt,At),m=m+Math.imul(ht,St)|0,c=c+Math.imul(ht,xt)|0,c=c+Math.imul(pt,St)|0,b=b+Math.imul(pt,xt)|0,m=m+Math.imul(ft,It)|0,c=c+Math.imul(ft,Et)|0,c=c+Math.imul(_t,It)|0,b=b+Math.imul(_t,Et)|0,m=m+Math.imul(ut,Ot)|0,c=c+Math.imul(ut,Rt)|0,c=c+Math.imul(dt,Ot)|0,b=b+Math.imul(dt,Rt)|0,m=m+Math.imul(ct,Ft)|0,c=c+Math.imul(ct,Nt)|0,c=c+Math.imul(lt,Ft)|0,b=b+Math.imul(lt,Nt)|0,m=m+Math.imul(st,Bt)|0,c=c+Math.imul(st,jt)|0,c=c+Math.imul(at,Bt)|0,b=b+Math.imul(at,jt)|0;var xi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(xi>>>26)|0,xi&=67108863,m=Math.imul(mt,St),c=Math.imul(mt,xt),c=c+Math.imul(gt,St)|0,b=Math.imul(gt,xt),m=m+Math.imul(ht,It)|0,c=c+Math.imul(ht,Et)|0,c=c+Math.imul(pt,It)|0,b=b+Math.imul(pt,Et)|0,m=m+Math.imul(ft,Ot)|0,c=c+Math.imul(ft,Rt)|0,c=c+Math.imul(_t,Ot)|0,b=b+Math.imul(_t,Rt)|0,m=m+Math.imul(ut,Ft)|0,c=c+Math.imul(ut,Nt)|0,c=c+Math.imul(dt,Ft)|0,b=b+Math.imul(dt,Nt)|0,m=m+Math.imul(ct,Bt)|0,c=c+Math.imul(ct,jt)|0,c=c+Math.imul(lt,Bt)|0,b=b+Math.imul(lt,jt)|0;var Ii=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ii>>>26)|0,Ii&=67108863,m=Math.imul(mt,It),c=Math.imul(mt,Et),c=c+Math.imul(gt,It)|0,b=Math.imul(gt,Et),m=m+Math.imul(ht,Ot)|0,c=c+Math.imul(ht,Rt)|0,c=c+Math.imul(pt,Ot)|0,b=b+Math.imul(pt,Rt)|0,m=m+Math.imul(ft,Ft)|0,c=c+Math.imul(ft,Nt)|0,c=c+Math.imul(_t,Ft)|0,b=b+Math.imul(_t,Nt)|0,m=m+Math.imul(ut,Bt)|0,c=c+Math.imul(ut,jt)|0,c=c+Math.imul(dt,Bt)|0,b=b+Math.imul(dt,jt)|0;var Ei=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ei>>>26)|0,Ei&=67108863,m=Math.imul(mt,Ot),c=Math.imul(mt,Rt),c=c+Math.imul(gt,Ot)|0,b=Math.imul(gt,Rt),m=m+Math.imul(ht,Ft)|0,c=c+Math.imul(ht,Nt)|0,c=c+Math.imul(pt,Ft)|0,b=b+Math.imul(pt,Nt)|0,m=m+Math.imul(ft,Bt)|0,c=c+Math.imul(ft,jt)|0,c=c+Math.imul(_t,Bt)|0,b=b+Math.imul(_t,jt)|0;var Oi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Oi>>>26)|0,Oi&=67108863,m=Math.imul(mt,Ft),c=Math.imul(mt,Nt),c=c+Math.imul(gt,Ft)|0,b=Math.imul(gt,Nt),m=m+Math.imul(ht,Bt)|0,c=c+Math.imul(ht,jt)|0,c=c+Math.imul(pt,Bt)|0,b=b+Math.imul(pt,jt)|0;var Ri=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ri>>>26)|0,Ri&=67108863,m=Math.imul(mt,Bt),c=Math.imul(mt,jt),c=c+Math.imul(gt,Bt)|0,b=Math.imul(gt,jt);var Fi=(C+m|0)+((c&8191)<<13)|0;return C=(b+(c>>>13)|0)+(Fi>>>26)|0,Fi&=67108863,v[0]=mi,v[1]=gi,v[2]=bi,v[3]=wi,v[4]=yi,v[5]=vi,v[6]=Pi,v[7]=Ci,v[8]=Mi,v[9]=ki,v[10]=Ti,v[11]=Ai,v[12]=Si,v[13]=xi,v[14]=Ii,v[15]=Ei,v[16]=Oi,v[17]=Ri,v[18]=Fi,C!==0&&(v[19]=C,_.length++),_};Math.imul||($=W);function G(y,s,u){u.negative=s.negative^y.negative,u.length=y.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-y.length+1);c<=m;c++){var b=g-c,x=y.words[b]|0,E=s.words[c]|0,R=x*E,U=R&67108863;v=v+(R/67108864|0)|0,U=U+C|0,C=U&67108863,v=v+(U>>>26)|0,p+=v>>>26,v&=67108863}u.words[g]=C,_=v,v=p}return _!==0?u.words[g]=_:u.length--,u._strip()}function D(y,s,u){return G(y,s,u)}n.prototype.mulTo=function(s,u){var _,p=this.length+s.length;return this.length===10&&s.length===10?_=$(this,s,u):p<63?_=W(this,s,u):p<1024?_=G(this,s,u):_=D(this,s,u),_};function K(y,s){this.x=y,this.y=s}K.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},K.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},K.prototype.permute=function(s,u,_,p,g,v){for(var C=0;C<v;C++)p[C]=u[s[C]],g[C]=_[s[C]]},K.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),b=Math.sin(2*Math.PI/m),x=0;x<g;x+=m)for(var E=c,R=b,U=0;U<C;U++){var z=_[x+U],Q=p[x+U],oe=_[x+U+C],J=p[x+U+C],it=E*oe-R*J;J=E*J+R*oe,oe=it,_[x+U]=z+oe,p[x+U]=Q+J,_[x+U+C]=z-oe,p[x+U+C]=Q-J,U!==m&&(it=c*E-b*R,R=c*R+b*E,E=it)}},K.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},K.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}},K.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},K.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)},K.prototype.stub=function(s){for(var u=new Array(s),_=0;_<s;_++)u[_]=0;return u},K.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),b=new Array(p),x=new Array(p),E=new Array(p),R=_.words;R.length=p,this.convert13b(s.words,s.length,C,p),this.convert13b(u.words,u.length,b,p),this.transform(C,v,m,c,p,g),this.transform(b,v,x,E,p,g);for(var U=0;U<p;U++){var z=m[U]*x[U]-c[U]*E[U];c[U]=m[U]*E[U]+c[U]*x[U],m[U]=z}return this.conjugate(m,c,p),this.transform(m,c,R,v,p,g),this.conjugate(R,v,p),this.normalize13b(R,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),D(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=I(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 b=0;for(c=this.length-1;c>=0&&(b!==0||c>=p);c--){var x=this.words[c]|0;this.words[c]=b<<26-g|x>>>g,b=x&C}return m&&b!==0&&(m.words[m.length++]=b),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 b=0;b<c.length;b++)c.words[b]=0}var x=p.clone()._ishlnsubmul(g,1,m);x.negative===0&&(p=x,c&&(c.words[m]=1));for(var E=m-1;E>=0;E--){var R=(p.words[g.length+E]|0)*67108864+(p.words[g.length+E-1]|0);for(R=Math.min(R/v|0,67108863),p._ishlnsubmul(g,R,E);p.negative!==0;)R--,p.negative=0,p._ishlnsubmul(g,1,E),p.isZero()||(p.negative^=1);c&&(c.words[E]=R)}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(),b=u.clone();!u.isZero();){for(var x=0,E=1;(u.words[0]&E)===0&&x<26;++x,E<<=1);if(x>0)for(u.iushrn(x);x-- >0;)(p.isOdd()||g.isOdd())&&(p.iadd(c),g.isub(b)),p.iushrn(1),g.iushrn(1);for(var R=0,U=1;(_.words[0]&U)===0&&R<26;++R,U<<=1);if(R>0)for(_.iushrn(R);R-- >0;)(v.isOdd()||C.isOdd())&&(v.iadd(c),C.isub(b)),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,b=1;(_.words[0]&b)===0&&c<26;++c,b<<=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 x;return u.cmpn(1)===0?x=p:x=g,x.cmpn(0)<0&&x.iadd(s),x},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 Z(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 zt={k256:null,p224:null,p192:null,p25519:null};function et(y,s){this.name=y,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()}et.prototype._tmp=function(){var s=new n(null);return s.words=new Array(Math.ceil(this.n/13)),s},et.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},et.prototype.split=function(s,u){s.iushrn(this.n,0,u)},et.prototype.imulK=function(s){return s.imul(this.k)};function Qt(){et.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}i(Qt,et),Qt.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},Qt.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 ue(){et.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}i(ue,et);function ne(){et.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}i(ne,et);function de(){et.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}i(de,et),de.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(zt[s])return zt[s];var u;if(s==="k256")u=new Qt;else if(s==="p224")u=new ue;else if(s==="p192")u=new ne;else if(s==="p25519")u=new de;else throw new Error("Unknown prime "+s);return zt[s]=u,u};function Z(y){if(typeof y=="string"){var s=n._prime(y);this.m=s.p,this.prime=s}else e(y.gtn(1),"modulus must be greater than 1"),this.m=y,this.prime=null}Z.prototype._verify1=function(s){e(s.negative===0,"red works only with positives"),e(s.red,"red works only with red numbers")},Z.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")},Z.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):(f(s,s.umod(this.m)._forceRed(this)),s)},Z.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},Z.prototype.add=function(s,u){this._verify2(s,u);var _=s.add(u);return _.cmp(this.m)>=0&&_.isub(this.m),_._forceRed(this)},Z.prototype.iadd=function(s,u){this._verify2(s,u);var _=s.iadd(u);return _.cmp(this.m)>=0&&_.isub(this.m),_},Z.prototype.sub=function(s,u){this._verify2(s,u);var _=s.sub(u);return _.cmpn(0)<0&&_.iadd(this.m),_._forceRed(this)},Z.prototype.isub=function(s,u){this._verify2(s,u);var _=s.isub(u);return _.cmpn(0)<0&&_.iadd(this.m),_},Z.prototype.shl=function(s,u){return this._verify1(s),this.imod(s.ushln(u))},Z.prototype.imul=function(s,u){return this._verify2(s,u),this.imod(s.imul(u))},Z.prototype.mul=function(s,u){return this._verify2(s,u),this.imod(s.mul(u))},Z.prototype.isqr=function(s){return this.imul(s,s.clone())},Z.prototype.sqr=function(s){return this.mul(s,s)},Z.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 b=this.pow(c,p),x=this.pow(s,p.addn(1).iushrn(1)),E=this.pow(s,p),R=g;E.cmp(v)!==0;){for(var U=E,z=0;U.cmp(v)!==0;z++)U=U.redSqr();e(z<R);var Q=this.pow(b,new n(1).iushln(R-z-1));x=x.redMul(Q),b=Q.redSqr(),E=E.redMul(b),R=z}return x},Z.prototype.invm=function(s){var u=s._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},Z.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 b=u.words[g],x=c-1;x>=0;x--){var E=b>>x&1;if(v!==p[0]&&(v=this.sqr(v)),E===0&&C===0){m=0;continue}C<<=1,C|=E,m++,!(m!==_&&(g!==0||x!==0))&&(v=this.mul(v,p[C]),m=0,C=0)}c=26}return v},Z.prototype.convertTo=function(s){var u=s.umod(this.m);return u===s?u.clone():u},Z.prototype.convertFrom=function(s){var u=s.clone();return u.red=null,u},n.mont=function(s){return new Ht(s)};function Ht(y){Z.call(this,y),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(Ht,Z),Ht.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},Ht.prototype.convertFrom=function(s){var u=this.imod(s.mul(this.rinv));return u.red=null,u},Ht.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)},Ht.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)},Ht.prototype.invm=function(s){var u=this.imod(s._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof Vi>"u"||Vi,Xn)});var cs={};Ro(cs,{AMM_SWAP_MODULE:()=>Jr,BPS:()=>go,CetusClmmSDK:()=>Ge,ClmmError:()=>be,ClmmExpectSwapModule:()=>Ho,ClmmFetcherModule:()=>Yt,ClmmIntegratePoolModule:()=>Ae,ClmmIntegratePoolV2Module:()=>Xt,ClmmIntegratePoolV3Module:()=>Ne,ClmmIntegrateRouterModule:()=>Be,ClmmIntegrateRouterWithPartnerModule:()=>zi,ClmmIntegrateUtilsModule:()=>Gi,ClmmPartnerModule:()=>Zi,ClmmPositionStatus:()=>Hi,ConfigErrorCode:()=>we,ConfigModule:()=>Fe,DeepbookClobV2Module:()=>Zo,DeepbookCustodianV2Module:()=>Wo,DeepbookEndpointsV2Module:()=>zo,POOL_STRUCT:()=>Xr,PartnerErrorCode:()=>$i,PoolErrorCode:()=>Te,PoolModule:()=>Ve,PositionErrorCode:()=>Re,PositionModule:()=>He,PositionUtils:()=>Gt,RewarderModule:()=>We,RouterErrorCode:()=>Jn,SwapErrorCode:()=>Di,SwapModule:()=>Ze,SwapUtils:()=>ee,TypesErrorCode:()=>Ui,UtilsErrorCode:()=>ii,VestErrorCode:()=>Li,VestModule:()=>ze,VestUtils:()=>ie,buildClmmPositionName:()=>Qr,buildPool:()=>De,buildPoolTransactionInfo:()=>sn,buildPosition:()=>Le,buildPositionInfo:()=>Ie,buildPositionTransactionInfo:()=>rn,buildTickData:()=>$e,buildTickDataByEvent:()=>on,buildTransferCoin:()=>an,buildTransferCoinToSender:()=>Ue,clmmMainnet:()=>cn,clmmTestnet:()=>un,computeSwap:()=>nn,computeSwapStep:()=>mo,default:()=>as,estPoolAPR:()=>ns,estPositionAPRWithDeltaMethod:()=>rs,estPositionAPRWithMultiMethod:()=>ss,eventMainnetContractMaps:()=>ln,eventTestnetContractMaps:()=>dn,findAdjustCoin:()=>ye,getDefaultSuiInputType:()=>Go,getLowerSqrtPriceFromCoinA:()=>Kr,getLowerSqrtPriceFromCoinB:()=>Wr,getUpperSqrtPriceFromCoinA:()=>Hr,getUpperSqrtPriceFromCoinB:()=>Zr,handleError:()=>Wt,handleMessageError:()=>B,newBits:()=>zr,poolFilterEvenTypes:()=>Wi,poolLiquiditySnapshotType:()=>Ki,transClmmpoolDataWithoutTicks:()=>en});module.exports=Fo(cs);var To=require("@cetusprotocol/common-sdk");var ni=require("@mysten/sui/utils"),F=require("@cetusprotocol/common-sdk");var jn="3.7.8",No=jn,ke=typeof Buffer=="function",On=typeof TextDecoder=="function"?new TextDecoder:void 0,Rn=typeof TextEncoder=="function"?new TextEncoder:void 0,Bo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Oe=Array.prototype.slice.call(Bo),Ye=(o=>{let t={};return o.forEach((e,i)=>t[e]=i),t})(Oe),jo=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Dt=String.fromCharCode.bind(String),Fn=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):o=>new Uint8Array(Array.prototype.slice.call(o,0)),qn=o=>o.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),Dn=o=>o.replace(/[^A-Za-z0-9\+\/]/g,""),Ln=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+=Oe[t>>18&63]+Oe[t>>12&63]+Oe[t>>6&63]+Oe[t&63]}return a?r.slice(0,a-3)+"===".substring(a):r},ji=typeof btoa=="function"?o=>btoa(o):ke?o=>Buffer.from(o,"binary").toString("base64"):Ln,Ni=ke?o=>Buffer.from(o).toString("base64"):o=>{let e=[];for(let i=0,n=o.length;i<n;i+=4096)e.push(Dt.apply(null,o.subarray(i,i+4096)));return ji(e.join(""))},ti=(o,t=!1)=>t?qn(Ni(o)):Ni(o),qo=o=>{if(o.length<2){var t=o.charCodeAt(0);return t<128?o:t<2048?Dt(192|t>>>6)+Dt(128|t&63):Dt(224|t>>>12&15)+Dt(128|t>>>6&63)+Dt(128|t&63)}else{var t=65536+(o.charCodeAt(0)-55296)*1024+(o.charCodeAt(1)-56320);return Dt(240|t>>>18&7)+Dt(128|t>>>12&63)+Dt(128|t>>>6&63)+Dt(128|t&63)}},Do=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,$n=o=>o.replace(Do,qo),Nn=ke?o=>Buffer.from(o,"utf8").toString("base64"):Rn?o=>Ni(Rn.encode(o)):o=>ji($n(o)),Me=(o,t=!1)=>t?qn(Nn(o)):Nn(o),Bn=o=>Me(o,!0),Lo=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,$o=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 Dt((e>>>10)+55296)+Dt((e&1023)+56320);case 3:return Dt((15&o.charCodeAt(0))<<12|(63&o.charCodeAt(1))<<6|63&o.charCodeAt(2));default:return Dt((31&o.charCodeAt(0))<<6|63&o.charCodeAt(1))}},Un=o=>o.replace(Lo,$o),Vn=o=>{if(o=o.replace(/\s+/g,""),!jo.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=Ye[o.charAt(r++)]<<18|Ye[o.charAt(r++)]<<12|(e=Ye[o.charAt(r++)])<<6|(i=Ye[o.charAt(r++)]),e===64?n.push(Dt(t>>16&255)):i===64?n.push(Dt(t>>16&255,t>>8&255)):n.push(Dt(t>>16&255,t>>8&255,t&255));return n.join("")},qi=typeof atob=="function"?o=>atob(Dn(o)):ke?o=>Buffer.from(o,"base64").toString("binary"):Vn,Kn=ke?o=>Fn(Buffer.from(o,"base64")):o=>Fn(qi(o).split("").map(t=>t.charCodeAt(0))),Hn=o=>Kn(Wn(o)),Uo=ke?o=>Buffer.from(o,"base64").toString("utf8"):On?o=>On.decode(Kn(o)):o=>Un(qi(o)),Wn=o=>Dn(o.replace(/[-_]/g,t=>t=="-"?"+":"/")),Bi=o=>Uo(Wn(o)),Vo=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)},Zn=o=>({value:o,enumerable:!1,writable:!0,configurable:!0}),zn=function(){let o=(t,e)=>Object.defineProperty(String.prototype,t,Zn(e));o("fromBase64",function(){return Bi(this)}),o("toBase64",function(t){return Me(this,t)}),o("toBase64URI",function(){return Me(this,!0)}),o("toBase64URL",function(){return Me(this,!0)}),o("toUint8Array",function(){return Hn(this)})},Gn=function(){let o=(t,e)=>Object.defineProperty(Uint8Array.prototype,t,Zn(e));o("toBase64",function(t){return ti(this,t)}),o("toBase64URI",function(){return ti(this,!0)}),o("toBase64URL",function(){return ti(this,!0)})},Ko=()=>{zn(),Gn()},ei={version:jn,VERSION:No,atob:qi,atobPolyfill:Vn,btoa:ji,btoaPolyfill:Ln,fromBase64:Bi,toBase64:Me,encode:Me,encodeURI:Bn,encodeURL:Bn,utob:$n,btou:Un,decode:Bi,isValid:Vo,fromUint8Array:ti,toUint8Array:Hn,extendString:zn,extendUint8Array:Gn,extendBuiltins:Ko};var Qn=require("@cetusprotocol/common-sdk"),Di=(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))(Di||{}),Re=(r=>(r.InvalidTickEvent="InvalidTickEvent",r.InvalidPositionObject="InvalidPositionObject",r.InvalidPositionRewardObject="InvalidPositionRewardObject",r.InvalidParams="InvalidParams",r.FetchError="FetchError",r))(Re||{}),Te=(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))(Te||{}),Li=(e=>(e.ClmmVestNotSet="ClmmVestNotSet",e.ClmmVestFetchError="ClmmVestFetchError",e))(Li||{}),$i=(e=>(e.NotFoundPartnerObject="NotFoundPartnerObject",e.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",e))($i||{}),we=(i=>(i.InvalidConfig="InvalidConfig",i.InvalidConfigHandle="InvalidConfigHandle",i.InvalidSimulateAccount="InvalidSimulateAccount",i))(we||{}),ii=(a=>(a.InvalidSendAddress="InvalidSendAddress",a.InvalidRecipientAddress="InvalidRecipientAddress",a.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",a.InsufficientBalance="InsufficientBalance",a.InvalidTarget="InvalidTarget",a.InvalidTransactionBuilder="InvalidTransactionBuilder",a))(ii||{}),Jn=(a=>(a.InvalidCoin="InvalidCoin",a.NotFoundPath="NotFoundPath",a.NoDowngradeNeedParams="NoDowngradeNeedParams",a.InvalidSwapCountUrl="InvalidSwapCountUrl",a.InvalidTransactionBuilder="InvalidTransactionBuilder",a.InvalidServerResponse="InvalidServerResponse",a))(Jn||{}),Ui=(t=>(t.InvalidType="InvalidType",t))(Ui||{}),be=class extends Qn.BaseError{constructor(t,e,i){super(t,e||"UnknownError",i)}static isVaultsErrorCode(t,e){return this.isErrorCode(t,e)}},Wt=(o,t,e)=>{throw new be(t.message,o,e)},B=(o,t,e)=>{throw new be(t,o,e)};var Fe=class{constructor(t){this._cache={};this._sdk=t}get sdk(){return this._sdk}setTokenListCache(t){let{coin_list_handle:e}=(0,F.getPackagerConfigs)(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}=(0,F.getPackagerConfigs)(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((0,F.normalizeCoinType)(d)===(0,F.normalizeCoinType)(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 w={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]=w,this.updateCache(d,w,F.CACHE_TIME_24H)}else console.log(`not found ${l}`)}}return e}async getCoinConfigs(t=!1,e=!0){let{coin_list_handle:i}=(0,F.getPackagerConfigs)(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")&&B("FetchError",`when getCoinConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getCoinConfigs"});let w=this.buildCoinConfig(h,e);this.updateCache(`${i}_${w.address}_getCoinConfig`,w,F.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,F.CACHE_TIME_24H),f}async getCoinConfig(t,e=!1,i=!0){let{coin_list_handle:n}=(0,F.getPackagerConfigs)(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:(0,F.fixCoinType)(t)}}});(l.error!=null||l.data?.content?.dataType!=="moveObject")&&B("FetchError",`when getCoinConfig get object error: ${l.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getCoinConfig"});let d=this.buildCoinConfig(l,i);return this.updateCache(r,d,F.CACHE_TIME_24H),d}buildCoinConfig(t,e=!0){let i=(0,F.getObjectFields)(t);i=i.value.fields;let n={...i};return n.id=(0,F.getObjectId)(t),n.address=(0,F.extractStructTagFromType)(i.coin_type.fields.name).full_address,i.pyth_id&&(n.pyth_id=(0,ni.normalizeSuiObjectId)(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}=(0,F.getPackagerConfigs)(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")&&B("FetchError",`when getClmmPoolsConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getClmmPoolConfigs"});let w=this.buildClmmPoolConfig(h,e);this.updateCache(`${w.pool_address}_getClmmPoolConfig`,w,F.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,F.CACHE_TIME_24H),f}async getClmmPoolConfig(t,e=!1,i=!0){let{clmm_pools_handle:n}=(0,F.getPackagerConfigs)(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,F.CACHE_TIME_24H),d}buildClmmPoolConfig(t,e=!0){let i=(0,F.getObjectFields)(t);i=i.value.fields;let n={...i};return n.id=(0,F.getObjectId)(t),n.pool_address=(0,ni.normalizeSuiObjectId)(i.pool_address),this.transformExtensions(n,i.extension_fields.fields.contents,e),n}async getLaunchpadPoolConfigs(t=!1,e=!0){let{launchpad_pools_handle:i}=(0,F.getPackagerConfigs)(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")&&B("FetchError",`when getCoinConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getLaunchpadPoolConfigs"});let w=this.buildLaunchpadPoolConfig(h,e);this.updateCache(`${w.pool_address}_getLaunchpadPoolConfig`,w,F.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,F.CACHE_TIME_24H),f}async getLaunchpadPoolConfig(t,e=!1,i=!0){let{launchpad_pools_handle:n}=(0,F.getPackagerConfigs)(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,F.CACHE_TIME_24H),d}buildLaunchpadPoolConfig(t,e=!0){let i=(0,F.getObjectFields)(t);i=i.value.fields;let n={...i};n.id=(0,F.getObjectId)(t),n.pool_address=(0,ni.normalizeSuiObjectId)(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(ei.decode(n.regulation).replace(/%/g,"%25"))}catch{n.regulation=ei.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(ei.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=(0,F.getObjectPreviousTransactionDigest)(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((0,F.extractStructTagFromType)(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,F.CACHE_TIME_24H),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")&&B("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${n.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getCetusConfigHandle"});let r=(0,F.getObjectFields)(n),a=(0,F.getObjectType)(n);switch((0,F.extractStructTagFromType)(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=F.CACHE_TIME_5MIN){let n=this._cache[t];n?(n.overdue_time=(0,F.getFutureTime)(i),n.value=e):n=new F.CachedContent(e,(0,F.getFutureTime)(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 vo=require("@mysten/sui/client"),Ee=require("@mysten/sui/transactions"),ve=require("@mysten/sui/utils"),Po=fe(re());var Ki="position_liquidity_snapshot",Hi=(i=>(i.Deleted="Deleted",i.Exists="Exists",i.NotExists="NotExists",i))(Hi||{}),Wi=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent","AddLiquidityV2Event","RemoveLiquidityV2Event"];var Vt=fe(re()),V=require("@cetusprotocol/common-sdk");var _i=require("@mysten/sui/transactions"),po=fe(re()),H=require("@cetusprotocol/common-sdk");var Zi="partner",Ae="pool_script",Xt="pool_script_v2",Ne="pool_script_v3",Be="router",zi="router_with_partner",Yt="fetcher_script",Ho="expect_swap",Gi="utils",Wo="custodian_v2",Zo="clob_v2",zo="endpoints_v2",Go=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 be(`Unknown type for value: ${o}`,"InvalidType")};var fi=require("@mysten/sui/transactions"),ho=fe(re()),X=require("@cetusprotocol/common-sdk");var Se=9e15,ge=1e9,Qi="0123456789abcdef",si="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ai="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ji={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Se,maxE:Se,crypto:!1},io,_e,L=!0,li="[DecimalError] ",me=li+"Invalid argument: ",no=li+"Precision limit exceeded",oo=li+"crypto unavailable",ro="[object Decimal]",Ut=Math.floor,qt=Math.pow,Qo=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Jo=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Xo=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,so=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,te=1e7,j=7,Yo=9007199254740991,tr=si.length-1,Xi=ai.length-1,k={toStringTag:ro};k.absoluteValue=k.abs=function(){var o=new this.constructor(this);return o.s<0&&(o.s=1),N(o)};k.ceil=function(){return N(new this.constructor(this),this.e+1,2)};k.clampedTo=k.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(me+t);return e=i.cmp(o),e<0?o:i.cmp(t)>0?t:new n(i)};k.comparedTo=k.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};k.cosine=k.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())+j,i.rounding=1,e=er(i,fo(i,e)),i.precision=o,i.rounding=t,N(_e==2||_e==3?e.neg():e,o,t,!0)):new i(1):new i(NaN)};k.cubeRoot=k.cbrt=function(){var o,t,e,i,n,r,a,l,d,f,h=this,w=h.constructor;if(!h.isFinite()||h.isZero())return new w(h);for(L=!1,r=h.s*qt(h.s*h,1/3),!r||Math.abs(r)==1/0?(e=Lt(h.d),o=h.e,(r=(o-e.length+1)%3)&&(e+=r==1||r==-2?"0":"00"),r=qt(e,1/3),o=Ut((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 w(e),i.s=h.s):i=new w(r.toString()),a=(o=w.precision)+3;;)if(l=i,d=l.times(l).times(l),f=d.plus(h),i=tt(f.plus(h).times(l),f.plus(d),a+2,1),Lt(l.d).slice(0,a)===(e=Lt(i.d)).slice(0,a))if(e=e.slice(a-3,a+1),e=="9999"||!n&&e=="4999"){if(!n&&(N(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")&&(N(i,o+1,1),t=!i.times(i).times(i).eq(h));break}return L=!0,N(i,o,w.rounding,t)};k.decimalPlaces=k.dp=function(){var o,t=this.d,e=NaN;if(t){if(o=t.length-1,e=(o-Ut(this.e/j))*j,o=t[o],o)for(;o%10==0;o/=10)e--;e<0&&(e=0)}return e};k.dividedBy=k.div=function(o){return tt(this,new this.constructor(o))};k.dividedToIntegerBy=k.divToInt=function(o){var t=this,e=t.constructor;return N(tt(t,new e(o),0,1,1),e.precision,e.rounding)};k.equals=k.eq=function(o){return this.cmp(o)===0};k.floor=function(){return N(new this.constructor(this),this.e+1,3)};k.greaterThan=k.gt=function(o){return this.cmp(o)>0};k.greaterThanOrEqualTo=k.gte=function(o){var t=this.cmp(o);return t==1||t===0};k.hyperbolicCosine=k.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/di(4,o)).toString()):(o=16,t="2.3283064365386962890625e-10"),r=xe(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 N(r,a.precision=e,a.rounding=i,!0)};k.hyperbolicSine=k.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=xe(r,2,n,n,!0);else{o=1.4*Math.sqrt(i),o=o>16?16:o|0,n=n.times(1/di(5,o)),n=xe(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,N(n,t,e,!0)};k.hyperbolicTangent=k.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,tt(e.sinh(),e.cosh(),i.precision=o,i.rounding=t)):new i(e.s)};k.inverseCosine=k.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()?se(t,i,n):new t(0):new t(NaN):o.isZero()?se(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))};k.inverseHyperbolicCosine=k.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,L=!1,e=e.times(e).minus(1).sqrt().plus(e),L=!0,i.precision=o,i.rounding=t,e.ln()):new i(e)};k.inverseHyperbolicSine=k.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,L=!1,e=e.times(e).plus(1).sqrt().plus(e),L=!0,i.precision=o,i.rounding=t,e.ln())};k.inverseHyperbolicTangent=k.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?N(new r(n),o,t,!0):(r.precision=e=i-n.e,n=tt(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)};k.inverseSine=k.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=se(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)))};k.inverseTangent=k.atan=function(){var o,t,e,i,n,r,a,l,d,f=this,h=f.constructor,w=h.precision,P=h.rounding;if(f.isFinite()){if(f.isZero())return new h(f);if(f.abs().eq(1)&&w+4<=Xi)return a=se(h,w+4,P).times(.25),a.s=f.s,a}else{if(!f.s)return new h(NaN);if(w+4<=Xi)return a=se(h,w+4,P).times(.5),a.s=f.s,a}for(h.precision=l=w+10,h.rounding=1,e=Math.min(28,l/j+2|0),o=e;o;--o)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(L=!1,t=Math.ceil(l/j),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)),L=!0,N(a,h.precision=w,h.rounding=P,!0)};k.isFinite=function(){return!!this.d};k.isInteger=k.isInt=function(){return!!this.d&&Ut(this.e/j)>this.d.length-2};k.isNaN=function(){return!this.s};k.isNegative=k.isNeg=function(){return this.s<0};k.isPositive=k.isPos=function(){return this.s>0};k.isZero=function(){return!!this.d&&this.d[0]===0};k.lessThan=k.lt=function(o){return this.cmp(o)<0};k.lessThanOrEqualTo=k.lte=function(o){return this.cmp(o)<1};k.logarithm=k.log=function(o){var t,e,i,n,r,a,l,d,f=this,h=f.constructor,w=h.precision,P=h.rounding,M=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(L=!1,l=w+M,a=pe(f,l),i=t?ci(h,l+10):pe(o,l),d=tt(a,i,l,1),je(d.d,n=w,P))do if(l+=10,a=pe(f,l),i=t?ci(h,l+10):pe(o,l),d=tt(a,i,l,1),!r){+Lt(d.d).slice(n+1,n+15)+1==1e14&&(d=N(d,w+1,0));break}while(je(d.d,n+=10,P));return L=!0,N(d,w,P)};k.minus=k.sub=function(o){var t,e,i,n,r,a,l,d,f,h,w,P,M=this,S=M.constructor;if(o=new S(o),!M.d||!o.d)return!M.s||!o.s?o=new S(NaN):M.d?o.s=-o.s:o=new S(o.d||M.s!==o.s?M:NaN),o;if(M.s!=o.s)return o.s=-o.s,M.plus(o);if(f=M.d,P=o.d,l=S.precision,d=S.rounding,!f[0]||!P[0]){if(P[0])o.s=-o.s;else if(f[0])o=new S(M);else return new S(d===3?-0:0);return L?N(o,l,d):o}if(e=Ut(o.e/j),h=Ut(M.e/j),f=f.slice(),r=h-e,r){for(w=r<0,w?(t=f,r=-r,a=P.length):(t=P,e=h,a=f.length),i=Math.max(Math.ceil(l/j),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,w=i<a,w&&(a=i),i=0;i<a;i++)if(f[i]!=P[i]){w=f[i]<P[i];break}r=0}for(w&&(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]=te-1;--f[n],f[i]+=te}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=ui(f,e),L?N(o,l,d):o):new S(d===3?-0:0)};k.modulo=k.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]?N(new i(e),i.precision,i.rounding):(L=!1,i.modulo==9?(t=tt(e,o.abs(),0,3,1),t.s*=o.s):t=tt(e,o,0,i.modulo,1),t=t.times(o),L=!0,e.minus(t))};k.naturalExponential=k.exp=function(){return Yi(this)};k.naturalLogarithm=k.ln=function(){return pe(this)};k.negated=k.neg=function(){var o=new this.constructor(this);return o.s=-o.s,N(o)};k.plus=k.add=function(o){var t,e,i,n,r,a,l,d,f,h,w=this,P=w.constructor;if(o=new P(o),!w.d||!o.d)return!w.s||!o.s?o=new P(NaN):w.d||(o=new P(o.d||w.s===o.s?w:NaN)),o;if(w.s!=o.s)return o.s=-o.s,w.minus(o);if(f=w.d,h=o.d,l=P.precision,d=P.rounding,!f[0]||!h[0])return h[0]||(o=new P(w)),L?N(o,l,d):o;if(r=Ut(w.e/j),i=Ut(o.e/j),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/j),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)/te|0,f[n]%=te;for(t&&(f.unshift(t),++i),a=f.length;f[--a]==0;)f.pop();return o.d=f,o.e=ui(f,i),L?N(o,l,d):o};k.precision=k.sd=function(o){var t,e=this;if(o!==void 0&&o!==!!o&&o!==1&&o!==0)throw Error(me+o);return e.d?(t=ao(e.d),o&&e.e+1>t&&(t=e.e+1)):t=NaN,t};k.round=function(){var o=this,t=o.constructor;return N(new t(o),o.e+1,t.rounding)};k.sine=k.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())+j,i.rounding=1,e=nr(i,fo(i,e)),i.precision=o,i.rounding=t,N(_e>2?e.neg():e,o,t,!0)):new i(NaN)};k.squareRoot=k.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(L=!1,f=Math.sqrt(+a),f==0||f==1/0?(t=Lt(l),(t.length+d)%2==0&&(t+="0"),f=Math.sqrt(t),d=Ut((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(tt(a,r,e+2,1)).times(.5),Lt(r.d).slice(0,e)===(t=Lt(i.d)).slice(0,e))if(t=t.slice(e-3,e+1),t=="9999"||!n&&t=="4999"){if(!n&&(N(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")&&(N(i,d+1,1),o=!i.times(i).eq(a));break}return L=!0,N(i,d,h.rounding,o)};k.tangent=k.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=tt(e,new i(1).minus(e.times(e)).sqrt(),o+10,0),i.precision=o,i.rounding=t,N(_e==2||_e==4?e.neg():e,o,t,!0)):new i(NaN)};k.times=k.mul=function(o){var t,e,i,n,r,a,l,d,f,h=this,w=h.constructor,P=h.d,M=(o=new w(o)).d;if(o.s*=h.s,!P||!P[0]||!M||!M[0])return new w(!o.s||P&&!P[0]&&!M||M&&!M[0]&&!P?NaN:!P||!M?o.s/0:o.s*0);for(e=Ut(h.e/j)+Ut(o.e/j),d=P.length,f=M.length,d<f&&(r=P,P=M,M=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]+M[i]*P[n-i-1]+t,r[n--]=l%te|0,t=l/te|0;r[n]=(r[n]+t)%te|0}for(;!r[--a];)r.pop();return t?++e:r.shift(),o.d=r,o.e=ui(r,e),L?N(o,w.precision,w.rounding):o};k.toBinary=function(o,t){return tn(this,2,o,t)};k.toDecimalPlaces=k.toDP=function(o,t){var e=this,i=e.constructor;return e=new i(e),o===void 0?e:(Zt(o,0,ge),t===void 0?t=i.rounding:Zt(t,0,8),N(e,o+e.e+1,t))};k.toExponential=function(o,t){var e,i=this,n=i.constructor;return o===void 0?e=ae(i,!0):(Zt(o,0,ge),t===void 0?t=n.rounding:Zt(t,0,8),i=N(new n(i),o+1,t),e=ae(i,!0,o+1)),i.isNeg()&&!i.isZero()?"-"+e:e};k.toFixed=function(o,t){var e,i,n=this,r=n.constructor;return o===void 0?e=ae(n):(Zt(o,0,ge),t===void 0?t=r.rounding:Zt(t,0,8),i=N(new r(n),o+n.e+1,t),e=ae(i,!1,o+i.e+1)),n.isNeg()&&!n.isZero()?"-"+e:e};k.toFraction=function(o){var t,e,i,n,r,a,l,d,f,h,w,P,M=this,S=M.d,I=M.constructor;if(!S)return new I(M);if(f=e=new I(1),i=d=new I(0),t=new I(i),r=t.e=ao(S)-M.e-1,a=r%j,t.d[0]=qt(10,a<0?j+a:a),o==null)o=r>0?t:f;else{if(l=new I(o),!l.isInt()||l.lt(f))throw Error(me+l);o=l.gt(t)?r>0?t:f:l}for(L=!1,l=new I(Lt(S)),h=I.precision,I.precision=r=S.length*j*2;w=tt(l,t,0,1,1),n=e.plus(w.times(i)),n.cmp(o)!=1;)e=i,i=n,n=f,f=d.plus(w.times(n)),d=n,n=t,t=l.minus(w.times(n)),l=n;return n=tt(o.minus(e),i,0,1,1),d=d.plus(n.times(f)),e=e.plus(n.times(i)),d.s=f.s=M.s,P=tt(f,i,r,1).minus(M).abs().cmp(tt(d,e,r,1).minus(M).abs())<1?[f,i]:[d,e],I.precision=h,L=!0,P};k.toHexadecimal=k.toHex=function(o,t){return tn(this,16,o,t)};k.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:Zt(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]?(L=!1,e=tt(e,o,0,t,1).times(o),L=!0,N(e)):(o.s=e.s,e=o),e};k.toNumber=function(){return+this};k.toOctal=function(o,t){return tn(this,8,o,t)};k.toPower=k.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(qt(+l,f));if(l=new d(l),l.eq(1))return l;if(i=d.precision,r=d.rounding,o.eq(1))return N(l,i,r);if(t=Ut(o.e/j),t>=o.d.length-1&&(e=f<0?-f:f)<=Yo)return n=co(d,l,e,i),o.s<0?new d(1).div(n):N(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=qt(+l,f),t=e==0||!isFinite(e)?Ut(f*(Math.log("0."+Lt(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):(L=!1,d.rounding=l.s=1,e=Math.min(12,(t+"").length),n=Yi(o.times(pe(l,i+e)),i),n.d&&(n=N(n,i+5,1),je(n.d,i,r)&&(t=i+10,n=N(Yi(o.times(pe(l,t+e)),t),t+5,1),+Lt(n.d).slice(i+1,i+15)+1==1e14&&(n=N(n,i+1,0)))),n.s=a,L=!0,d.rounding=r,N(n,i,r))};k.toPrecision=function(o,t){var e,i=this,n=i.constructor;return o===void 0?e=ae(i,i.e<=n.toExpNeg||i.e>=n.toExpPos):(Zt(o,1,ge),t===void 0?t=n.rounding:Zt(t,0,8),i=N(new n(i),o,t),e=ae(i,o<=i.e||i.e<=n.toExpNeg,o)),i.isNeg()&&!i.isZero()?"-"+e:e};k.toSignificantDigits=k.toSD=function(o,t){var e=this,i=e.constructor;return o===void 0?(o=i.precision,t=i.rounding):(Zt(o,1,ge),t===void 0?t=i.rounding:Zt(t,0,8)),N(new i(e),o,t)};k.toString=function(){var o=this,t=o.constructor,e=ae(o,o.e<=t.toExpNeg||o.e>=t.toExpPos);return o.isNeg()&&!o.isZero()?"-"+e:e};k.truncated=k.trunc=function(){return N(new this.constructor(this),this.e+1,1)};k.valueOf=k.toJSON=function(){var o=this,t=o.constructor,e=ae(o,o.e<=t.toExpNeg||o.e>=t.toExpPos);return o.isNeg()?"-"+e:e};function Lt(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=j-i.length,e&&(r+=he(e)),r+=i;a=o[t],i=a+"",e=j-i.length,e&&(r+=he(e))}else if(a===0)return"0";for(;a%10===0;)a/=10;return r+a}function Zt(o,t,e){if(o!==~~o||o<t||o>e)throw Error(me+o)}function je(o,t,e,i){var n,r,a,l;for(r=o[0];r>=10;r/=10)--t;return--t<0?(t+=j,n=0):(n=Math.ceil((t+1)/j),t%=j),r=qt(10,j-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)==qt(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)==qt(10,t-3)-1,a}function oi(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]+=Qi.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 er(o,t){var e,i,n;if(t.isZero())return t;i=t.d.length,i<32?(e=Math.ceil(i/3),n=(1/di(4,e)).toString()):(e=16,n="2.3283064365386962890625e-10"),o.precision+=e,t=xe(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 tt=(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,w,P,M,S,I,W,$,G,D,K,zt,et,Qt,ue,ne,de,Z,Ht,y=i.constructor,s=i.s==n.s?1:-1,u=i.d,_=n.d;if(!u||!u[0]||!_||!_[0])return new y(!i.s||!n.s||(u?_&&u[0]==_[0]:!_)?NaN:u&&u[0]==0||!_?s*0:s/0);for(d?(M=1,h=i.e-n.e):(d=te,M=j,h=Ut(i.e/M)-Ut(n.e/M)),Z=_.length,ne=u.length,$=new y(s),G=$.d=[],w=0;_[w]==(u[w]||0);w++);if(_[w]>(u[w]||0)&&h--,r==null?(et=r=y.precision,a=y.rounding):l?et=r+(i.e-n.e)+1:et=r,et<0)G.push(1),S=!0;else{if(et=et/M+2|0,w=0,Z==1){for(P=0,_=_[0],et++;(w<ne||P)&&et--;w++)Qt=P*d+(u[w]||0),G[w]=Qt/_|0,P=Qt%_|0;S=P||w<ne}else{for(P=d/(_[0]+1)|0,P>1&&(_=o(_,P,d),u=o(u,P,d),Z=_.length,ne=u.length),ue=Z,D=u.slice(0,Z),K=D.length;K<Z;)D[K++]=0;Ht=_.slice(),Ht.unshift(0),de=_[0],_[1]>=d/2&&++de;do P=0,f=t(_,D,Z,K),f<0?(zt=D[0],Z!=K&&(zt=zt*d+(D[1]||0)),P=zt/de|0,P>1?(P>=d&&(P=d-1),I=o(_,P,d),W=I.length,K=D.length,f=t(I,D,W,K),f==1&&(P--,e(I,Z<W?Ht:_,W,d))):(P==0&&(f=P=1),I=_.slice()),W=I.length,W<K&&I.unshift(0),e(D,I,K,d),f==-1&&(K=D.length,f=t(_,D,Z,K),f<1&&(P++,e(D,Z<K?Ht:_,K,d))),K=D.length):f===0&&(P++,D=[0]),G[w++]=P,f&&D[0]?D[K++]=u[ue]||0:(D=[u[ue]],K=1);while((ue++<ne||D[0]!==void 0)&&et--);S=D[0]!==void 0}G[0]||G.shift()}if(M==1)$.e=h,io=S;else{for(w=1,P=G[0];P>=10;P/=10)w++;$.e=w+h*M-1,N($,l?r+$.e+1:r,a,S)}return $}})();function N(o,t,e,i){var n,r,a,l,d,f,h,w,P,M=o.constructor;t:if(t!=null){if(w=o.d,!w)return o;for(n=1,l=w[0];l>=10;l/=10)n++;if(r=t-n,r<0)r+=j,a=t,h=w[P=0],d=h/qt(10,n-a-1)%10|0;else if(P=Math.ceil((r+1)/j),l=w.length,P>=l)if(i){for(;l++<=P;)w.push(0);h=d=0,n=1,r%=j,a=r-j+1}else break t;else{for(h=l=w[P],n=1;l>=10;l/=10)n++;r%=j,a=r-j+n,d=a<0?0:h/qt(10,n-a-1)%10|0}if(i=i||t<0||w[P+1]!==void 0||(a<0?h:h%qt(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/qt(10,n-a):0:w[P-1])%10&1||e==(o.s<0?8:7)),t<1||!w[0])return w.length=0,f?(t-=o.e+1,w[0]=qt(10,(j-t%j)%j),o.e=-t||0):w[0]=o.e=0,o;if(r==0?(w.length=P,l=1,P--):(w.length=P+1,l=qt(10,j-r),w[P]=a>0?(h/qt(10,n-a)%qt(10,a)|0)*l:0),f)for(;;)if(P==0){for(r=1,a=w[0];a>=10;a/=10)r++;for(a=w[0]+=l,l=1;a>=10;a/=10)l++;r!=l&&(o.e++,w[0]==te&&(w[0]=1));break}else{if(w[P]+=l,w[P]!=te)break;w[P--]=0,l=1}for(r=w.length;w[--r]===0;)w.pop()}return L&&(o.e>M.maxE?(o.d=null,o.e=NaN):o.e<M.minE&&(o.e=0,o.d=[0])),o}function ae(o,t,e){if(!o.isFinite())return uo(o);var i,n=o.e,r=Lt(o.d),a=r.length;return t?(e&&(i=e-a)>0?r=r.charAt(0)+"."+r.slice(1)+he(i):a>1&&(r=r.charAt(0)+"."+r.slice(1)),r=r+(o.e<0?"e":"e+")+o.e):n<0?(r="0."+he(-n-1)+r,e&&(i=e-a)>0&&(r+=he(i))):n>=a?(r+=he(n+1-a),e&&(i=e-n-1)>0&&(r=r+"."+he(i))):((i=n+1)<a&&(r=r.slice(0,i)+"."+r.slice(i)),e&&(i=e-a)>0&&(n+1===a&&(r+="."),r+=he(i))),r}function ui(o,t){var e=o[0];for(t*=j;e>=10;e/=10)t++;return t}function ci(o,t,e){if(t>tr)throw L=!0,e&&(o.precision=e),Error(no);return N(new o(si),t,1,!0)}function se(o,t,e){if(t>Xi)throw Error(no);return N(new o(ai),t,e,!0)}function ao(o){var t=o.length-1,e=t*j+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 he(o){for(var t="";o--;)t+="0";return t}function co(o,t,e,i){var n,r=new o(1),a=Math.ceil(i/j+4);for(L=!1;;){if(e%2&&(r=r.times(t),to(r.d,a)&&(n=!0)),e=Ut(e/2),e===0){e=r.d.length-1,n&&r.d[e]===0&&++r.d[e];break}t=t.times(t),to(t.d,a)}return L=!0,r}function Yn(o){return o.d[o.d.length-1]&1}function lo(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 Yi(o,t){var e,i,n,r,a,l,d,f=0,h=0,w=0,P=o.constructor,M=P.rounding,S=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?(L=!1,d=S):d=t,l=new P(.03125);o.e>-2;)o=o.times(l),w+=5;for(i=Math.log(qt(2,w))/Math.LN10*2+5|0,d+=i,e=r=a=new P(1),P.precision=d;;){if(r=N(r.times(o),d,1),e=e.times(++h),l=a.plus(tt(r,e,d,1)),Lt(l.d).slice(0,d)===Lt(a.d).slice(0,d)){for(n=w;n--;)a=N(a.times(a),d,1);if(t==null)if(f<3&&je(a.d,d-i,M,f))P.precision=d+=10,e=r=l=new P(1),h=0,f++;else return N(a,P.precision=S,M,L=!0);else return P.precision=S,a}a=l}}function pe(o,t){var e,i,n,r,a,l,d,f,h,w,P,M=1,S=10,I=o,W=I.d,$=I.constructor,G=$.rounding,D=$.precision;if(I.s<0||!W||!W[0]||!I.e&&W[0]==1&&W.length==1)return new $(W&&!W[0]?-1/0:I.s!=1?NaN:W?0:I);if(t==null?(L=!1,h=D):h=t,$.precision=h+=S,e=Lt(W),i=e.charAt(0),Math.abs(r=I.e)<15e14){for(;i<7&&i!=1||i==1&&e.charAt(1)>3;)I=I.times(o),e=Lt(I.d),i=e.charAt(0),M++;r=I.e,i>1?(I=new $("0."+e),r++):I=new $(i+"."+e.slice(1))}else return f=ci($,h+2,D).times(r+""),I=pe(new $(i+"."+e.slice(1)),h-S).plus(f),$.precision=D,t==null?N(I,D,G,L=!0):I;for(w=I,d=a=I=tt(I.minus(1),I.plus(1),h,1),P=N(I.times(I),h,1),n=3;;){if(a=N(a.times(P),h,1),f=d.plus(tt(a,new $(n),h,1)),Lt(f.d).slice(0,h)===Lt(d.d).slice(0,h))if(d=d.times(2),r!==0&&(d=d.plus(ci($,h+2,D).times(r+""))),d=tt(d,new $(M),h,1),t==null)if(je(d.d,h-S,G,l))$.precision=h+=S,f=a=I=tt(w.minus(1),w.plus(1),h,1),P=N(I.times(I),h,1),n=l=1;else return N(d,$.precision=D,G,L=!0);else return $.precision=D,d;d=f,n+=2}}function uo(o){return String(o.s*o.s/0)}function ri(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)%j,e<0&&(i+=j),i<n){for(i&&o.d.push(+t.slice(0,i)),n-=j;i<n;)o.d.push(+t.slice(i,i+=j));t=t.slice(i),i=j-t.length}else i-=n;for(;i--;)t+="0";o.d.push(+t),L&&(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 ir(o,t){var e,i,n,r,a,l,d,f,h;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),so.test(t))return ri(o,t)}else if(t==="Infinity"||t==="NaN")return+t||(o.s=NaN),o.e=NaN,o.d=null,o;if(Jo.test(t))e=16,t=t.toLowerCase();else if(Qo.test(t))e=2;else if(Xo.test(t))e=8;else throw Error(me+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=co(i,new i(e),r,r*2)),f=oi(t,e,te),h=f.length-1,r=h;f[r]===0;--r)f.pop();return r<0?new i(o.s*0):(o.e=ui(f,h),o.d=f,L=!1,a&&(o=tt(o,n,l*4)),d&&(o=o.times(Math.abs(d)<54?qt(2,d):qe.pow(2,d))),L=!0,o)}function nr(o,t){var e,i=t.d.length;if(i<3)return t.isZero()?t:xe(o,2,t,t);e=1.4*Math.sqrt(i),e=e>16?16:e|0,t=t.times(1/di(5,e)),t=xe(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 xe(o,t,e,i,n){var r,a,l,d,f=1,h=o.precision,w=Math.ceil(h/j);for(L=!1,d=e.times(e),l=new o(i);;){if(a=tt(l.times(d),new o(t++*t++),h,1),l=n?i.plus(a):i.minus(a),i=tt(a.times(d),new o(t++*t++),h,1),a=l.plus(i),a.d[w]!==void 0){for(r=w;a.d[r]===l.d[r]&&r--;);if(r==-1)break}r=l,l=i,i=a,a=r,f++}return L=!0,a.d.length=w+1,a}function di(o,t){for(var e=o;--t;)e*=o;return e}function fo(o,t){var e,i=t.s<0,n=se(o,o.precision,1),r=n.times(.5);if(t=t.abs(),t.lte(r))return _e=i?4:1,t;if(e=t.divToInt(n),e.isZero())_e=i?3:2;else{if(t=t.minus(e.times(n)),t.lte(r))return _e=Yn(e)?i?2:3:i?4:1,t;_e=Yn(e)?i?1:4:i?3:2}return t.minus(n).abs()}function tn(o,t,e,i){var n,r,a,l,d,f,h,w,P,M=o.constructor,S=e!==void 0;if(S?(Zt(e,1,ge),i===void 0?i=M.rounding:Zt(i,0,8)):(e=M.precision,i=M.rounding),!o.isFinite())h=uo(o);else{for(h=ae(o),a=h.indexOf("."),S?(n=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):n=t,a>=0&&(h=h.replace(".",""),P=new M(1),P.e=h.length-a,P.d=oi(ae(P),10,n),P.e=P.d.length),w=oi(h,10,n),r=d=w.length;w[--d]==0;)w.pop();if(!w[0])h=S?"0p+0":"0";else{if(a<0?r--:(o=new M(o),o.d=w,o.e=r,o=tt(o,P,e,i,0,n),w=o.d,r=o.e,f=io),a=w[e],l=n/2,f=f||w[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&&w[e-1]&1||i===(o.s<0?8:7)),w.length=e,f)for(;++w[--e]>n-1;)w[e]=0,e||(++r,w.unshift(1));for(d=w.length;!w[d-1];--d);for(a=0,h="";a<d;a++)h+=Qi.charAt(w[a]);if(S){if(d>1)if(t==16||t==8){for(a=t==16?4:3,--d;d%a;d++)h+="0";for(w=oi(h,n,t),d=w.length;!w[d-1];--d);for(a=1,h="1.";a<d;a++)h+=Qi.charAt(w[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 to(o,t){if(o.length>t)return o.length=t,!0}function or(o){return new this(o).abs()}function rr(o){return new this(o).acos()}function sr(o){return new this(o).acosh()}function ar(o,t){return new this(o).plus(t)}function cr(o){return new this(o).asin()}function lr(o){return new this(o).asinh()}function ur(o){return new this(o).atan()}function dr(o){return new this(o).atanh()}function fr(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=se(this,r,1).times(t.s>0?.25:.75),e.s=o.s):!t.d||o.isZero()?(e=t.s<0?se(this,i,n):new this(0),e.s=o.s):!o.d||t.isZero()?(e=se(this,r,1).times(.5),e.s=o.s):t.s<0?(this.precision=r,this.rounding=1,e=this.atan(tt(o,t,r,1)),t=se(this,r,1),this.precision=i,this.rounding=n,e=o.s<0?e.minus(t):e.plus(t)):e=this.atan(tt(o,t,r,1)),e}function _r(o){return new this(o).cbrt()}function hr(o){return N(o=new this(o),o.e+1,2)}function pr(o,t,e){return new this(o).clamp(t,e)}function mr(o){if(!o||typeof o!="object")throw Error(li+"Object expected");var t,e,i,n=o.defaults===!0,r=["precision",1,ge,"rounding",0,8,"toExpNeg",-Se,0,"toExpPos",0,Se,"maxE",0,Se,"minE",-Se,0,"modulo",0,9];for(t=0;t<r.length;t+=3)if(e=r[t],n&&(this[e]=Ji[e]),(i=o[e])!==void 0)if(Ut(i)===i&&i>=r[t+1]&&i<=r[t+2])this[e]=i;else throw Error(me+e+": "+i);if(e="crypto",n&&(this[e]=Ji[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(oo);else this[e]=!1;else throw Error(me+e+": "+i);return this}function gr(o){return new this(o).cos()}function br(o){return new this(o).cosh()}function _o(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,eo(r)){f.s=r.s,L?!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++;L?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 ri(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),so.test(r)?ri(f,r):ir(f,r);if(d==="bigint")return r<0?(r=-r,f.s=-1):f.s=1,ri(f,r.toString());throw Error(me+r)}if(n.prototype=k,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=mr,n.clone=_o,n.isDecimal=eo,n.abs=or,n.acos=rr,n.acosh=sr,n.add=ar,n.asin=cr,n.asinh=lr,n.atan=ur,n.atanh=dr,n.atan2=fr,n.cbrt=_r,n.ceil=hr,n.clamp=pr,n.cos=gr,n.cosh=br,n.div=wr,n.exp=yr,n.floor=vr,n.hypot=Pr,n.ln=Cr,n.log=Mr,n.log10=Tr,n.log2=kr,n.max=Ar,n.min=Sr,n.mod=xr,n.mul=Ir,n.pow=Er,n.random=Or,n.round=Rr,n.sign=Fr,n.sin=Nr,n.sinh=Br,n.sqrt=jr,n.sub=qr,n.sum=Dr,n.tan=Lr,n.tanh=$r,n.trunc=Ur,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 wr(o,t){return new this(o).div(t)}function yr(o){return new this(o).exp()}function vr(o){return N(o=new this(o),o.e+1,3)}function Pr(){var o,t,e=new this(0);for(L=!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 L=!0,new this(1/0);e=t}return L=!0,e.sqrt()}function eo(o){return o instanceof qe||o&&o.toStringTag===ro||!1}function Cr(o){return new this(o).ln()}function Mr(o,t){return new this(o).log(t)}function kr(o){return new this(o).log(2)}function Tr(o){return new this(o).log(10)}function Ar(){return lo(this,arguments,-1)}function Sr(){return lo(this,arguments,1)}function xr(o,t){return new this(o).mod(t)}function Ir(o,t){return new this(o).mul(t)}function Er(o,t){return new this(o).pow(t)}function Or(o){var t,e,i,n,r=0,a=new this(1),l=[];if(o===void 0?o=this.precision:Zt(o,1,ge),i=Math.ceil(o/j),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(oo);else for(;r<i;)l[r++]=Math.random()*1e7|0;for(i=l[--r],o%=j,i&&o&&(n=qt(10,j-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-=j)l.shift();for(i=1,n=l[0];n>=10;n/=10)i++;i<j&&(e-=j-i)}return a.e=e,a.d=l,a}function Rr(o){return N(o=new this(o),o.e+1,this.rounding)}function Fr(o){return o=new this(o),o.d?o.d[0]?o.s:0*o.s:o.s||NaN}function Nr(o){return new this(o).sin()}function Br(o){return new this(o).sinh()}function jr(o){return new this(o).sqrt()}function qr(o,t){return new this(o).sub(t)}function Dr(){var o=0,t=arguments,e=new this(t[o]);for(L=!1;e.s&&++o<t.length;)e=e.plus(t[o]);return L=!0,N(e,this.precision,this.rounding)}function Lr(o){return new this(o).tan()}function $r(o){return new this(o).tanh()}function Ur(o){return N(o=new this(o),o.e+1,1)}k[Symbol.for("nodejs.util.inspect.custom")]=k.toString;k[Symbol.toStringTag]="Decimal";var qe=k.constructor=_o(Ji);si=new qe(si);ai=new qe(ai);var O=qe;function ye(o){let t=X.CoinAssist.isSuiCoin(o.coin_type_a),e=X.CoinAssist.isSuiCoin(o.coin_type_b);return{is_adjust_coin_a:t,is_adjust_coin_b:e}}function Vr(o,t){return O.ceil(O(o).div(1+t)).toString()}var Gt=class{static createCollectRewarderAndFeeParams(t,e,i,n,r,a){r===void 0&&(r=[...n]),a===void 0&&(a=[...n]);let l=(0,X.normalizeCoinType)(i.coin_type_a),d=(0,X.normalizeCoinType)(i.coin_type_b);if(i.collect_fee){let h=X.CoinAssist.buildCoinForAmount(e,r,BigInt(0),l,!1);r=h.remain_coins;let w=X.CoinAssist.buildCoinForAmount(e,a,BigInt(0),d,!1);a=w.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,w.target_coin)}let f=[];return i.rewarder_coin_types.forEach(h=>{switch((0,X.normalizeCoinType)(h)){case l:f.push(X.CoinAssist.buildCoinForAmount(e,r,BigInt(0),h,!1).target_coin);break;case d:f.push(X.CoinAssist.buildCoinForAmount(e,a,BigInt(0),h,!1).target_coin);break;default:f.push(X.CoinAssist.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=X.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,i).selected_coins,a=X.CoinAssist.calculateTotalBalance(e);if(r.length===0&&B("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${a}`),a-i>1e9)return{fixAmount:i};let l=await t.FullClient.calculationTxGas(fi.Transaction.from(n));if(X.CoinAssist.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&&B("InsufficientBalance","gas Insufficient balance");let h=new fi.Transaction;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}=ye(i),f=d?i.amount_a:i.amount_b,h=await this.adjustTransactionForGas(t,X.CoinAssist.getCoinAssets(d?i.coin_type_a:i.coin_type_b,e),BigInt(f),r),{fixAmount:w}=h,P=h.newTx;if(P!=null){let M,S;if(d)i.amount_a=Number(w),M=this.buildAddLiquidityFixTokenCoinInput(P,!i.fix_amount_a,w.toString(),i.slippage,i.coin_type_a,e,!1,!0),S=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(w),M=this.buildAddLiquidityFixTokenCoinInput(P,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,e,!1,!0),S=this.buildAddLiquidityFixTokenCoinInput(P,i.fix_amount_a,w.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,M,S)}return r}static async buildAddLiquidityFixToken(t,e,i,n,r,a){n=n||new fi.Transaction;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?X.CoinAssist.buildCoinForAmountInterval(t,a,{amount_second:BigInt(Vr(i,n)),amount_first:BigInt(i)},r,l,d):X.CoinAssist.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=X.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(Number(t.tick_lower),Number(t.tick_upper),new ho.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 w=(0,X.getPackagerConfigs)(f),P=n.is_open?[t.object(w.global_config_id),t.object(n.pool_id),t.pure.u32(Number((0,X.asUintN)(BigInt(n.tick_lower)).toString())),t.pure.u32(Number((0,X.asUintN)(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(X.CLOCK_ADDRESS)]:[t.object(w.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(X.CLOCK_ADDRESS)];return t.moveCall({target:`${h.published_at}::${Xt}::${d}`,typeArguments:l,arguments:P}),t}static checkCoinThreshold(t,e,i,n,r,a){e&&i.moveCall({target:`${t.sdkOptions.integrate.published_at}::${Be}::check_coin_threshold`,typeArguments:[a],arguments:[n,i.pure.u64(r)]})}};var ee=class o{static getDefaultSqrtPriceLimit(t){return new po.default(t?H.MIN_SQRT_PRICE:H.MAX_SQRT_PRICE)}static getDefaultOtherAmountThreshold(t){return t?H.ZERO:H.U64_MAX}static async buildSwapTransactionForGas(t,e,i,n){let r=this.buildSwapTransaction(t,e,i);r.setSender(t.getSenderAddress());let a=await this.adjustTransactionForGas(t,H.CoinAssist.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=H.CoinAssist.buildCoinForAmount(r,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a),h=H.CoinAssist.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}=(0,H.getPackagerConfigs)(a);h===void 0&&B("InvalidConfig","clmm.config.global_config_id is undefined");let w=e.swap_partner!==void 0,P=w?e.a2b?"swap_a2b_with_partner":"swap_b2a_with_partner":e.a2b?"swap_a2b":"swap_b2a",M=w?[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(H.CLOCK_ADDRESS)]:[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(H.CLOCK_ADDRESS)];return t.moveCall({target:`${l.published_at}::${Xt}::${P}`,typeArguments:f,arguments:M}),t}static async adjustTransactionForGas(t,e,i,n){n.setSender(t.getSenderAddress());let r=H.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,i).selected_coins,a=H.CoinAssist.calculateTotalBalance(e);if(r.length===0&&B("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${a}`),a-i>1e9)return{fixAmount:i};let l=await t.FullClient.calculationTxGas(n);if(H.CoinAssist.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&&B("InsufficientBalance","gas Insufficient balance");let h=new _i.Transaction;return{fixAmount:i,newTx:h}}}return{fixAmount:i}}static buildSwapTransaction(t,e,i){let n=new _i.Transaction;n.setSender(t.getSenderAddress());let r=H.CoinAssist.buildCoinForAmount(n,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1),a=H.CoinAssist.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=(0,H.adjustForSlippage)(a,i.slippage,!i.by_amount_in);e.amount_limit=l.toString()}catch(r){Wt("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,H.CoinAssist.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=H.CoinAssist.buildCoinForAmount(r,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1,!0),w=H.CoinAssist.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,w);r=P.tx,a=P.txRes}return{tx:r,coin_ab_s:a}}static buildSwapTransactionWithoutTransferCoins(t,e,i){let n=new _i.Transaction;n.setSender(t.getSenderAddress());let r=H.CoinAssist.buildCoinForAmount(n,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1,!0),a=H.CoinAssist.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}=(0,H.getPackagerConfigs)(l);h===void 0&&B("InvalidConfig","clmm.config.global_config_id is undefined");let w=i.swap_partner!==void 0,P=w?"swap_with_partner":"swap",M=w?zi:Be,S=w?[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(H.CLOCK_ADDRESS)]:[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(H.CLOCK_ADDRESS)],I=[i.coin_type_a,i.coin_type_b],W=e.moveCall({target:`${d.published_at}::${M}::${P}`,typeArguments:I,arguments:S});if(i.by_amount_in){let $=i.a2b?i.coin_type_b:i.coin_type_a,G=i.a2b?W[1]:W[0],D=Number(i.amount_limit);Gt.checkCoinThreshold(t,i.by_amount_in,e,G,D,$)}return{tx:e,txRes:W}}};function Kr(o,t,e){let i=t.mul(e).shln(64),n=t.shln(64).add(o.mul(e));return H.MathUtil.divRoundUp(i,n)}function Hr(o,t,e){let i=t.mul(e).shln(64),n=t.shln(64).sub(o.mul(e));return H.MathUtil.divRoundUp(i,n)}function Wr(o,t,e){return e.sub(H.MathUtil.divRoundUp(o.shln(64),t))}function Zr(o,t,e){return e.add(o.shln(64).div(t))}function zr(o){let t=new Vt.default(o);return t.lt(V.ZERO)?{bits:t.neg().xor(new Vt.default(2).pow(new Vt.default(64)).sub(new Vt.default(1))).add(new Vt.default(1)).toString()}:{bits:t.toString()}}function en(o){return{coin_type_a:o.coin_type_a,coin_type_b:o.coin_type_b,current_sqrt_price:new Vt.default(o.current_sqrt_price),current_tick_index:o.current_tick_index,fee_growth_global_a:new Vt.default(o.fee_growth_global_a),fee_growth_global_b:new Vt.default(o.fee_growth_global_b),fee_protocol_coin_a:new Vt.default(o.fee_protocol_coin_a),fee_protocol_coin_b:new Vt.default(o.fee_protocol_coin_b),fee_rate:new Vt.default(o.fee_rate),liquidity:new Vt.default(o.liquidity),tick_indexes:[],tick_spacing:Number(o.tick_spacing),ticks:[],collection_name:""}}function mo(o,t,e,i,n,r){if(e===V.ZERO)return{amount_in:V.ZERO,amount_out:V.ZERO,next_sqrt_price:t,fee_amount:V.ZERO};let a=o.gte(t),l,d,f,h;if(r){let w=V.MathUtil.checkMulDivFloor(i,V.MathUtil.checkUnsignedSub(V.FEE_RATE_DENOMINATOR,n),V.FEE_RATE_DENOMINATOR,64),P=(0,V.getDeltaUpFromInput)(o,t,e,a);P.gt(w)?(l=w,h=V.MathUtil.checkUnsignedSub(i,w),f=(0,V.getNextSqrtPriceFromInput)(o,e,w,a)):(l=P,h=V.MathUtil.checkMulDivCeil(l,n,V.FEE_RATE_DENOMINATOR.sub(n),64),f=t),d=(0,V.getDeltaDownFromOutput)(o,f,e,a)}else{let w=(0,V.getDeltaDownFromOutput)(o,t,e,a);w.gt(i)?(d=i,f=(0,V.getNextSqrtPriceFromOutput)(o,e,i,a)):(d=w,f=t),l=(0,V.getDeltaUpFromInput)(o,f,e,a),h=V.MathUtil.checkMulDivCeil(l,n,V.FEE_RATE_DENOMINATOR.sub(n),64)}return{amount_in:l,amount_out:d,next_sqrt_price:f,fee_amount:h}}function nn(o,t,e,i,n){let r=e,a=i.liquidity,{current_sqrt_price:l}=i,d={amount_in:V.ZERO,amount_out:V.ZERO,fee_amount:V.ZERO,ref_amount:V.ZERO,next_sqrt_price:V.ZERO,cross_tick_num:0},f,h,w=ee.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&&w.gt(P.sqrt_price)||!o&&w.lt(P.sqrt_price)?f=w:f=P.sqrt_price;let M=mo(l,f,a,r,i.fee_rate,t);if(M.amount_in.eq(V.ZERO)||(r=t?r.sub(M.amount_in.add(M.fee_amount)):r.sub(M.amount_out)),d.amount_in=d.amount_in.add(M.amount_in),d.amount_out=d.amount_out.add(M.amount_out),d.fee_amount=d.fee_amount.add(M.fee_amount),M.next_sqrt_price.eq(P.sqrt_price)?(h=P.liquidity_net.mul(new Vt.default(-1)),o?V.MathUtil.is_neg(h)?a=a.add(new Vt.default((0,V.asUintN)(BigInt(h.toString()),128))):a=a.add(h):V.MathUtil.is_neg(h)?a=a.sub(new Vt.default((0,V.asUintN)(BigInt(h.toString()),128))):a=a.sub(h),l=P.sqrt_price):l=M.next_sqrt_price,d.cross_tick_num+=1,r.eq(V.ZERO))break}return d.amount_in=d.amount_in.add(d.fee_amount),d.next_sqrt_price=l,d}var Jt=fe(re()),q=require("@cetusprotocol/common-sdk");function Gr(o,t,e){let i=(0,q.extractStructTagFromType)(o).name,n=(0,q.extractStructTagFromType)(t).name;return`${i}-${n}[${e}]`}function De(o){let t=(0,q.getMoveObjectType)(o),e=(0,q.extractStructTagFromType)(t),i=(0,q.getObjectFields)(o);i==null&&B("InvalidPoolObject",`Pool id ${(0,q.getObjectId)(o)} not exists.`,{[q.DETAILS_KEYS.METHOD_NAME]:"buildPool"});let n=[];i.rewarder_manager.fields.rewarders.forEach(d=>{let{emissions_per_second:f}=d.fields,h=q.MathUtil.fromX64(new Jt.default(f)),w=Math.floor(h.toNumber()*60*60*24);n.push({emissions_per_second:f,coin_type:(0,q.extractStructTagFromType)(d.fields.reward_coin.fields.name).source_address,growth_global:d.fields.growth_global,emissions_every_day:w})});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:(0,q.getObjectId)(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:(0,q.asIntN)(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=Gr(l.coin_type_a,l.coin_type_b,l.tick_spacing),l}function Le(o){(o.error!=null||o.data?.content?.dataType!=="moveObject")&&B("InvalidPositionObject",`Position not exists. Get Position error:${o.error}`,{[q.DETAILS_KEYS.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=(0,q.getObjectFields)(o);if(i){let a=(0,q.getMoveObjectType)(o),l=(0,q.getObjectOwner)(o);"nft"in i?(i=i.nft.fields,t.description=i.description,t.name=i.name,t.link=i.url):t=(0,q.buildNFT)(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:(0,q.asIntN)(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:(0,q.asIntN)(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=(0,q.getObjectDeletedResponse)(o);n&&(e.pos_object_id=n.objectId,e.position_status="Deleted");let r=(0,q.getObjectNotExistsResponse)(o);return r&&(e.pos_object_id=r,e.position_status="NotExists"),e}function Ie(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:(0,q.asIntN)(BigInt(e)),tick_upper_index:(0,q.asIntN)(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 $e(o){(o.error!=null||o.data?.content?.dataType!=="moveObject")&&B("InvalidTickObject",`Tick not exists. Get tick data error:${o.error}`,{[q.DETAILS_KEYS.METHOD_NAME]:"buildTickData"});let e=(0,q.getObjectFields)(o).value.fields.value.fields;return{object_id:(0,q.getObjectId)(o),index:(0,q.asIntN)(BigInt(e.index.fields.bits)),sqrt_price:new Jt.default(e.sqrt_price),liquidity_net:new Jt.default(e.liquidity_net.fields.bits),liquidity_gross:new Jt.default(e.liquidity_gross),fee_growth_outside_a:new Jt.default(e.fee_growth_outside_a),fee_growth_outside_b:new Jt.default(e.fee_growth_outside_b),rewarders_growth_outside:e.rewards_growth_outside}}function on(o){(!o||!o.index||!o.sqrt_price||!o.liquidity_net||!o.liquidity_gross||!o.fee_growth_outside_a||!o.fee_growth_outside_b)&&B("InvalidTickFields","Invalid tick fields.",{[q.DETAILS_KEYS.METHOD_NAME]:"buildTickDataByEvent"});let t=(0,q.asIntN)(BigInt(o.index.bits)),e=new Jt.default(o.sqrt_price),i=new Jt.default(o.liquidity_net.bits),n=new Jt.default(o.liquidity_gross),r=new Jt.default(o.fee_growth_outside_a),a=new Jt.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 Qr(o,t){return`Cetus LP | Pool${o}-${t}`}function rn(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=(0,q.extractStructTagFromType)(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)&&((0,q.d)(h.parsed_json.amount_a).gt(0)||(0,q.d)(h.parsed_json.amount_b).gt(0))&&i.push(h);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":case"AddLiquidityV2Event":case"RemoveLiquidityV2Event":((0,q.d)(h.parsed_json.amount_a).gt(0)||(0,q.d)(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))&&(0,q.d)(h.parsed_json.amount).gt(0)&&i.push(h);break;default:break}}}),i}function sn(o,t,e,i){let n=[],{timestampMs:r,events:a}=o;return a?.forEach((l,d)=>{let{name:f,address:h}=(0,q.extractStructTagFromType)(l.type);if(Wi.includes(f)&&e.includes(h)&&i===l.parsedJson.pool){let w={tx:l.id.txDigest,sender:l.sender,type:l.type,block_time:r||"0",index:`${t}_${d}`,parsed_json:l.parsedJson};n.push(w)}}),n}function Ue(o,t,e,i){t.moveCall({target:`${o.sdkOptions.integrate.published_at}::${Gi}::transfer_coin_to_sender`,typeArguments:[i],arguments:[e]})}function an(o,t,e,i,n){n!=null?t.transferObjects([e],t.pure.address(n)):Ue(o,t,e,i)}var T=require("@cetusprotocol/common-sdk");var $t=require("@cetusprotocol/common-sdk"),go=1e4,ie=class{static parseClmmVestInfo(t){let e=(0,$t.getObjectFields)(t),i=(0,$t.getObjectType)(t),n=(0,$t.extractStructTagFromType)(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:(0,$t.d)(l.fields.percentage).div(go).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:(0,$t.fixCoinType)(t.coin_a.name,!1),coin_type_b:(0,$t.fixCoinType)(t.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(t){let e=(0,$t.getObjectFields)(t);return{current_sqrt_price:e.current_sqrt_price,remove_percent:(0,$t.d)(e.remove_percent).div(1e6).toString(),snapshots:{id:e.snapshots.fields.id.id,size:e.snapshots.fields.size}}}static parsePositionSnapshot(t){let e=(0,$t.getObjectFields)(t),i=e.value.fields.value.fields;return{position_id:e.name,liquidity:i.liquidity,tick_lower_index:(0,$t.asIntN)(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:(0,$t.asIntN)(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}}};var wo=require("@cetusprotocol/common-sdk"),bo={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"}},cn={env:"mainnet",full_rpc_url:wo.FullRpcUrlMainnet,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:bo.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xdb5cd62a06c79695bfc9982eb08534706d3752fe123b48e0144f480209b3117f",version:13,config:bo.clmmConfig},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x5bcd02f33d65c7ce98cd1ffb88174629210e59230b41c4b4572de1541f94946e",version:13},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"}}},ln=["0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb","0xdb5cd62a06c79695bfc9982eb08534706d3752fe123b48e0144f480209b3117f"];var yo=require("@cetusprotocol/common-sdk");var un={env:"testnet",full_rpc_url:yo.FullRpcUrlTestnet,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:"0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8",config:{pools_id:"0x20a086e6fa0741b3ca77d033a65faf0871349b986ddbdde6fa1d85d78a5f4222",global_config_id:"0xc6273f844b4bc258952c4e477697aa12c918c8e08106fac6b934811298c9820a",global_vault_id:"0x71e74a999dd7959e483f758ddf573e85fa4c24944db33ff6763c9d85a9c045fe",admin_cap_id:"0xbf4c48590f403c38351de0e8aa13d6d91bf78fd8c04e93ac1d0269c44d70ae02",partners_id:"0xb5ae5ed3f403654ae1307aadc0140f746db41efb7bda92235257c84d90a1397e"}},integrate:{package_id:"0x36187418dd79415d50e2e5903f9b3caca582052005f062959c86da64e82107a9",published_at:"0x36187418dd79415d50e2e5903f9b3caca582052005f062959c86da64e82107a9",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"}}},dn=["0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8","0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8"];var Ve=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&&B("InvalidConfig",`when getPositionList get position objects error: ${l.error}, please check the rpc, contracts address config and position id.`,{[T.DETAILS_KEYS.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 w=h.parsedJson;w&&n.push({id:w.pool_id,tick_spacing:w.tick_spacing,coin_type_a:(0,T.extractStructTagFromType)(w.coin_type_a).full_address,coin_type_b:(0,T.extractStructTagFromType)(w.coin_type_b).full_address})})}catch(d){return Wt("FetchError",d,{[T.DETAILS_KEYS.METHOD_NAME]:"getPoolImmutables"})}return r.data=n,a&&this._sdk.updateCache(`${i}_getPoolImmutables`,n,T.CACHE_TIME_24H),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")&&B("InvalidPoolObject",`getPoolWithPages error code: ${a.error?.code??"unknown error"}, please check config and object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getPoolsWithPage"});let l=De(a);i.data.push(l);let d=`${l.id}_getPoolObject`;this._sdk.updateCache(d,l,T.CACHE_TIME_24H)}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:Ki}}),n=ie.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=ie.parsePositionSnapshot(f);d.push(h)}),n.position_snapshots=d}}return n}catch(i){return Wt("InvalidPoolObject",i,{[T.DETAILS_KEYS.METHOD_NAME]:"getPoolLiquiditySnapshot",[T.DETAILS_KEYS.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=ie.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")&&B("InvalidPoolObject",`getPools error code: ${n.error?.code??"unknown error"}, please check config and object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getAssignPools"});let r=De(n);e.push(r);let a=`${r.id}_getPoolObject`;this._sdk.updateCache(a,r,T.CACHE_TIME_24H)}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")&&B("InvalidPoolObject",`getPool error code: ${a.error?.code??"unknown error"}, please check config and object id`,{[T.DETAILS_KEYS.METHOD_NAME]:"getPool"});let l=De(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||B("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[T.DETAILS_KEYS.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){Wt("FetchError",d,{[T.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins",[T.DETAILS_KEYS.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((0,T.isSortedSymbols)((0,ve.normalizeSuiAddress)(t.coin_type_a),(0,ve.normalizeSuiAddress)(t.coin_type_b))){let i=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=i;let n=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=n}return await this.createPoolAndAddLiquidity(t,e)}async createPoolRowPayload(t,e){if((0,T.isSortedSymbols)((0,ve.normalizeSuiAddress)(t.coin_type_a),(0,ve.normalizeSuiAddress)(t.coin_type_b))){let i=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=i;let n=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=n}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=(0,T.getObjectPreviousTransactionDigest)(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((0,T.extractStructTagFromType)(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,T.CACHE_TIME_24H)),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=(0,T.createFullClient)(new vo.SuiClient({url:n})):l=r;let d={data:[],has_next_page:!1},f=50,h=e,w=e.limit||10,P=a.env==="testnet"?dn:ln;do{let M=await l.queryTransactionBlocksByPage({ChangedObject:t},{...h,limit:50},i);M.data.forEach((S,I)=>{d.next_cursor=M.next_cursor;let W=sn(S,I,P,t);d.data=[...d.data,...W]}),d.has_next_page=M.has_next_page,d.next_cursor=M.next_cursor,h.cursor=M.next_cursor}while(d.data.length<w&&d.has_next_page);return d.data.length>w&&(d.data=d.data.slice(0,w),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=T.TickMath.priceToSqrtPriceX64(a==="coin_a"?(0,T.d)(e):(0,T.d)(1).div(e),l,d),h=0,w=0;if(r.is_full_range)h=T.TickUtil.getMinIndex(n),w=T.TickUtil.getMaxIndex(n);else{let{min_price:D,max_price:K}=r;h=T.TickMath.priceToInitializeTickIndex(a==="coin_a"?(0,T.d)(D):(0,T.d)(1).div(K),l,d,n),w=T.TickMath.priceToInitializeTickIndex(a==="coin_a"?(0,T.d)(K):(0,T.d)(1).div(D),l,d,n)}let{coin_amount:P,fix_amount_a:M}=t,{coin_amount_limit_a:S,coin_amount_limit_b:I,liquidity_amount:W,coin_amount_a:$,coin_amount_b:G}=T.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(h,w,new Po.default(P),M,!0,i,f);return{coin_amount_a:$,coin_amount_b:G,coin_amount_limit_a:S,coin_amount_limit_b:I,liquidity:W,initialize_sqrt_price:f.toString(),tick_lower:h,tick_upper:w,fix_amount_a:M}}async createPoolAndAddLiquidity(t,e){e=e||new Ee.Transaction,e.setSender(this.sdk.getSenderAddress());let{integrate:i,clmm_pool:n}=this.sdk.sdkOptions,r=(0,T.getPackagerConfigs)(n),a=r.global_config_id,l=r.pools_id,d=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),f=T.CoinAssist.buildCoinForAmount(e,d,BigInt(t.amount_a),t.coin_type_a,!1,!0),h=T.CoinAssist.buildCoinForAmount(e,d,BigInt(t.amount_b),t.coin_type_b,!1,!0),w=[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((0,T.asUintN)(BigInt(t.tick_lower)).toString())),e.pure.u32(Number((0,T.asUintN)(BigInt(t.tick_upper)).toString())),f.target_coin,h.target_coin,e.object(t.metadata_a),e.object(t.metadata_b),e.pure.bool(t.fix_amount_a),e.object(T.CLOCK_ADDRESS)];return e.moveCall({target:`${i.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:w}),Ue(this._sdk,e,f.target_coin,t.coin_type_a),Ue(this._sdk,e,h.target_coin,t.coin_type_b),e}async createPoolAndAddLiquidityRow(t,e){e=e||new Ee.Transaction;let{clmm_pool:i}=this.sdk.sdkOptions,n=(0,T.getPackagerConfigs)(i),r=n.global_config_id,a=n.pools_id,l=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),d=T.CoinAssist.buildCoinForAmount(e,l,BigInt(t.amount_a),t.coin_type_a,!1,!0),f=T.CoinAssist.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((0,T.asUintN)(BigInt(t.tick_lower)).toString())),e.pure.u32(Number((0,T.asUintN)(BigInt(t.tick_upper)).toString())),d.target_coin,f.target_coin,e.object(t.metadata_a),e.object(t.metadata_b),e.pure.bool(t.fix_amount_a),e.object(T.CLOCK_ADDRESS)],w=e.moveCall({target:`${i.published_at}::pool_creator::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:h});return{tx:e,pos_id:w[0],remain_coin_a:w[1],remain_coin_b:w[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:w,coin_amount_a:P,coin_amount_b:M,fix_amount_a:S,coin_amount_limit_a:I,coin_amount_limit_b:W}=l,$=await this._sdk.FullClient.fetchCoinMetadata(i),G=await this._sdk.FullClient.fetchCoinMetadata(n);if($===null)return B("FetchError",`fetch coin ${i} metadata failed`,{[T.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});if(G===null)return B("FetchError",`fetch coin ${n} metadata failed`,{[T.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});let D=$.id,K=G.id;return this.createPoolRowPayload({tick_spacing:r,initialize_sqrt_price:d,uri:a||"",coin_type_a:i,coin_type_b:n,amount_a:S?P:I,amount_b:S?W:M,fix_amount_a:S,tick_lower:f,tick_upper:h,metadata_a:D,metadata_b:K},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:w,coin_amount_b:P,fix_amount_a:M,coin_amount_limit_a:S,coin_amount_limit_b:I}=a,W=await this._sdk.FullClient.fetchCoinMetadata(e),$=await this._sdk.FullClient.fetchCoinMetadata(i);if(W===null)return B("FetchError",`fetch coin ${e} metadata failed`,{[T.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});if($===null)return B("FetchError",`fetch coin ${i} metadata failed`,{[T.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});let G=W.id,D=$.id;return this.createPoolPayload({tick_spacing:n,initialize_sqrt_price:l,uri:r||"",coin_type_a:e,coin_type_b:i,amount_a:M?w:S,amount_b:M?I:P,fix_amount_a:M,tick_lower:d,tick_upper:f,metadata_a:G,metadata_b:D})}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((0,T.asUintN)(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 Ee.Transaction,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}::${Yt}::fetch_ticks`,arguments:l,typeArguments:n});let d=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:(0,ve.normalizeSuiAddress)("0x0")});return d.error!=null&&B("InvalidTickObjectId",`getTicks error code: ${d.error??"unknown error"}, please check config and tick object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getTicks",[T.DETAILS_KEYS.REQUEST_PARAMS]:t}),d.events?.forEach(f=>{(0,T.extractStructTagFromType)(f.type).name==="FetchTicksResultEvent"&&f.parsedJson.ticks.forEach(h=>{i.push(on(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 Ee.Transaction,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}::${Yt}::fetch_positions`,arguments:f,typeArguments:a});let h=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:l,sender:(0,ve.normalizeSuiAddress)("0x0")});h.error!=null&&B("InvalidPositionRewardObject",`fetch position info error code: ${h.error??"unknown error"}, please check config and tick object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"fetchPoolPositionInfoList",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});let w=[];if(h?.events?.forEach(P=>{(0,T.extractStructTagFromType)(P.type).name==="FetchPositionsEvent"&&P.parsedJson.positions.forEach(M=>{let S=Ie(M);w.push(S)})}),i.push(...w),w.length<r)break;n=[w[w.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=>{(0,T.extractStructTagFromType)(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")&&B("InvalidTickObjectId",`getTicksByRpc error code: ${n.error?.code??"unknown error"}, please check config and tick object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getTicksByRpc"});let r=$e(n);r!=null&&e.push(r)}return e}async getTickDataByIndex(t,e){let i={type:"u64",value:(0,T.asUintN)(BigInt((0,T.tickScore)(e).toString())).toString()},n=await this.sdk.FullClient.getDynamicFieldObject({parentId:t,name:i});return(n.error!=null||n.data?.content?.dataType!=="moveObject")&&B("InvalidTickIndex",`get tick by index: ${e} error: ${n.error}`,{[T.DETAILS_KEYS.METHOD_NAME]:"getTickDataByIndex"}),$e(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")&&B("InvalidTickObjectId",`getTicksByRpc error code: ${e.error?.code??"unknown error"}, please check config and tick object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getTickDataByObjectId"}),$e(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"&&B("NotFoundPartnerObject",`get partner by object id: ${t} error: ${i[0].error}`,{[T.DETAILS_KEYS.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")&&B("InvalidPartnerRefFeeFields",`get coin by object id: ${f.data.objectId} error: ${f.error}`,{[T.DETAILS_KEYS.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 Ee.Transaction,{clmm_pool:r}=this.sdk.sdkOptions,{global_config_id:a}=(0,T.getPackagerConfigs)(r),l=[i],d=[n.object(a),n.object(t),n.object(e)];return n.moveCall({target:`${r.published_at}::${Zi}::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=(0,T.getObjectFields)(e).position.fields.status;if(n)return n}catch(e){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",e)}}};var Co=require("@mysten/sui/client"),ce=require("@mysten/sui/transactions"),hi=require("@mysten/sui/utils"),Ke=fe(re()),A=require("@cetusprotocol/common-sdk");var He=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=(0,A.createFullClient)(new Co.SuiClient({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((w,P)=>{let M=rn(w,P,l);f.data=[...f.data,...M]}),f.has_next_page=h.has_next_page,f.next_cursor=h.next_cursor,f}catch(h){Wt("FetchError",h,{[A.DETAILS_KEYS.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((0,A.extractStructTagFromType)(l.data.type).full_address===this.buildPositionType()){let f=Le(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=Le(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=Le(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=(0,A.getObjectFields)(i.data).value.fields.value;return Ie(r)}catch(i){return Wt("FetchError",i,{[A.DETAILS_KEYS.METHOD_NAME]:"getPositionInfo",[A.DETAILS_KEYS.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=(0,A.deriveDynamicFieldIdByType)(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=(0,A.getObjectFields)(r.data).value.fields.value,d=Ie(l);e.push(d)}catch(a){console.log("getPositionInfoList error",a)}}),e)}catch(e){return Wt("FetchError",e,{[A.DETAILS_KEYS.METHOD_NAME]:"getPositionInfoList",[A.DETAILS_KEYS.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((0,A.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id)];e.moveCall({target:`${n.published_at}::${Yt}::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.Transaction;for(let d of t)this.buildFetchPosFee(d,n);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,hi.normalizeSuiAddress)("0x0")});r.error!=null&&B("InvalidPoolObject",`fetch position fee error code: ${r.error??"unknown error"}, please check config and position and pool object ids`,{[A.DETAILS_KEYS.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}=ye(t);if(t=t,t.fix_amount_a&&l||!t.fix_amount_a&&d)return i=await Gt.buildAddLiquidityFixTokenForGas(this._sdk,a,t,e,i,n,r),i}return Gt.buildAddLiquidityFixToken(this._sdk,a,t,i,n,r)}async createAddLiquidityPayload(t,e,i,n){let{integrate:r,clmm_pool:a}=this._sdk.sdkOptions,l=(0,A.asUintN)(BigInt(t.tick_lower)).toString(),d=(0,A.asUintN)(BigInt(t.tick_upper)).toString(),f=[t.coin_type_a,t.coin_type_b];e=e||new ce.Transaction;let h=!(0,hi.isValidSuiObjectId)(t.pos_id),w=BigInt(t.max_amount_a),P=BigInt(t.max_amount_b),M,S;if(i==null||n==null){let I=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());M=A.CoinAssist.buildCoinForAmount(e,I,w,t.coin_type_a,!1,!0),S=A.CoinAssist.buildCoinForAmount(e,I,P,t.coin_type_b,!1,!0)}else M={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},S={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]};if(h)e.moveCall({target:`${r.published_at}::${Xt}::open_position_with_liquidity`,typeArguments:f,arguments:[e.object((0,A.getPackagerConfigs)(a).global_config_id),e.object(t.pool_id),e.pure.u32(Number(l)),e.pure.u32(Number(d)),M.target_coin,S.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(A.CLOCK_ADDRESS)]});else{let I=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());e=Gt.createCollectRewarderAndFeeParams(this._sdk,e,t,I,M.remain_coins,S.remain_coins),e.moveCall({target:`${r.published_at}::${Xt}::add_liquidity`,typeArguments:f,arguments:[e.object((0,A.getPackagerConfigs)(a).global_config_id),e.object(t.pool_id),e.object(t.pos_id),M.target_coin,S.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(A.CLOCK_ADDRESS)]})}return e}async removeLiquidityPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions,r="remove_liquidity";e=e||new ce.Transaction;let a=[t.coin_type_a,t.coin_type_b],l=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());e=Gt.createCollectRewarderAndFeeParams(this._sdk,e,t,l);let d=[e.object((0,A.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.u128(t.delta_liquidity),e.pure.u64(t.min_amount_a),e.pure.u64(t.min_amount_b),e.object(A.CLOCK_ADDRESS)];return e.moveCall({target:`${n.published_at}::${Ae}::${r}`,typeArguments:a,arguments:d}),e}async closePositionPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new ce.Transaction;let r=[t.coin_type_a,t.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return e=Gt.createCollectRewarderAndFeeParams(this._sdk,e,t,a),e.moveCall({target:`${n.published_at}::${Ae}::close_position`,typeArguments:r,arguments:[e.object((0,A.getPackagerConfigs)(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(A.CLOCK_ADDRESS)]}),e}openPositionPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new ce.Transaction;let r=[t.coin_type_a,t.coin_type_b],a=(0,A.asUintN)(BigInt(t.tick_lower)).toString(),l=(0,A.asUintN)(BigInt(t.tick_upper)).toString(),d=[e.object((0,A.getPackagerConfigs)(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}::${Ae}::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.Transaction;let a=await this.sdk.Pool.getPool(i,!1),l=Number(a.tick_spacing),d=0,f=0;if(t.is_full_range)d=A.TickUtil.getMinIndex(l),f=A.TickUtil.getMaxIndex(l);else{let{price_base_coin:P,min_price:M,max_price:S}=t;d=A.TickMath.priceToInitializeTickIndex(P==="coin_a"?(0,A.d)(M):(0,A.d)(1).div(S),t.coin_decimals_a,t.coin_decimals_b,l),f=A.TickMath.priceToInitializeTickIndex(P==="coin_a"?(0,A.d)(S):(0,A.d)(1).div(M),t.coin_decimals_a,t.coin_decimals_b,l)}let h=[a.coin_type_a,a.coin_type_b],w=[e.object((0,A.getPackagerConfigs)(n).global_config_id),e.object(t.pool_id),e.pure.u32(Number((0,A.asUintN)(BigInt(d)))),e.pure.u32(Number((0,A.asUintN)(BigInt(f))))];return e.moveCall({target:`${r.published_at}::${Ae}::open_position`,typeArguments:h,arguments:w}),e}async collectFeePayload(t,e,i,n){e=e||new ce.Transaction;let r=i||A.CoinAssist.buildCoinWithBalance(BigInt(0),t.coin_type_a,e),a=n||A.CoinAssist.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((0,A.getPackagerConfigs)(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),i,n];return e.moveCall({target:`${a.published_at}::${Xt}::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=A.TickUtil.getMinIndex(l),f=A.TickUtil.getMaxIndex(l);else{let{price_base_coin:$,min_price:G,max_price:D}=r;d=A.TickMath.priceToInitializeTickIndex($==="coin_a"?(0,A.d)(G):(0,A.d)(1).div(D),r.coin_decimals_a,r.coin_decimals_b,l),f=A.TickMath.priceToInitializeTickIndex($==="coin_a"?(0,A.d)(D):(0,A.d)(1).div(G),r.coin_decimals_a,r.coin_decimals_b,l)}if("liquidity"in t){let{liquidity:$}=t,G=A.TickMath.tickIndexToSqrtPriceX64(d),D=A.TickMath.tickIndexToSqrtPriceX64(f),{coin_amount_a:K,coin_amount_b:zt}=A.ClmmPoolUtil.getCoinAmountFromLiquidity(new Ke.default($),new Ke.default(a.current_sqrt_price),G,D,!1),et=(0,A.d)(K).mul(1+i).toFixed(0,O.ROUND_UP),Qt=(0,A.d)(zt).mul(1+i).toFixed(0,O.ROUND_UP);return{coin_amount_a:K,coin_amount_b:zt,coin_amount_limit_a:et,coin_amount_limit_b:Qt,liquidity:$,tick_lower:d,tick_upper:f}}let{coin_amount:h,fix_amount_a:w}=t,{coin_amount_limit_a:P,coin_amount_limit_b:M,liquidity_amount:S,coin_amount_a:I,coin_amount_b:W}=A.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(d,f,new Ke.default(h),w,!0,i,new Ke.default(a.current_sqrt_price));return{coin_amount_a:I,coin_amount_b:W,coin_amount_limit_a:P,coin_amount_limit_b:M,liquidity:S,tick_lower:d,tick_upper:f,fix_amount_a:w}}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:w}=a;e=e||new ce.Transaction;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:w,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:w,fix_amount_a:P,coin_amount_a:M,coin_amount_b:S}=a;if(P===void 0)throw B("InvalidParams","fix_amount_a is undefined",{[A.DETAILS_KEYS.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[A.DETAILS_KEYS.REQUEST_PARAMS]:t});e=e||new ce.Transaction;let I=await this.sdk.Pool.getPool(r,!1);return await this.createAddLiquidityFixTokenPayload({amount_a:P?M:l,amount_b:P?d:S,slippage:0,fix_amount_a:P,is_open:!0,tick_lower:h,tick_upper:w,collect_fee:!1,rewarder_coin_types:[],coin_type_a:I.coin_type_a,coin_type_b:I.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((0,A.getPackagerConfigs)(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),i,n];return e.moveCall({target:`${a.published_at}::${Ne}::collect_fee`,typeArguments:l,arguments:d}),e}};var pi=require("@mysten/sui/transactions"),Mo=require("@mysten/sui/utils"),fn=fe(re()),Y=require("@cetusprotocol/common-sdk");var We=class{constructor(t){this._sdk=t,this.growthGlobal=[Y.ZERO,Y.ZERO,Y.ZERO]}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=Y.MathUtil.fromX64(new fn.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((0,Y.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id),e.object(Y.CLOCK_ADDRESS)];e.moveCall({target:`${n.published_at}::${Yt}::fetch_position_rewards`,arguments:a,typeArguments:r})}async fetchPosRewardersAmount(t){let e=new pi.Transaction;for(let a of t)this.buildFetchPosReward(a,e);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:e,sender:(0,Mo.normalizeSuiAddress)("0x")});i.error!=null&&B("InvalidConfig",`fetch position rewards error code: ${i.error??"unknown error"}, please check config and params`,{[Y.DETAILS_KEYS.METHOD_NAME]:"fetchPosRewardersAmount",[Y.DETAILS_KEYS.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=[Y.ZERO,Y.ZERO,Y.ZERO];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 fn.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 pi.Transaction;return i=Gt.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 pi.Transaction;let a={};return t.forEach(l=>{let d=(0,Y.normalizeCoinType)(l.coin_type_a),f=(0,Y.normalizeCoinType)(l.coin_type_b);if(l.collect_fee){let w=a[d];w==null&&(i==null?w=Y.CoinAssist.buildCoinForAmount(e,r,BigInt(0),d,!1):w={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},a[d]=w);let P=a[f];P==null&&(n==null?P=Y.CoinAssist.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,w.target_coin,P.target_coin)}let h=[];l.rewarder_coin_types.forEach(w=>{let P=(0,Y.normalizeCoinType)(w),M=a[w];M===void 0&&(M=Y.CoinAssist.buildCoinForAmount(e,r,BigInt(0),P,!1),a[P]=M),h.push(M.target_coin)}),e=this.createCollectRewarderNoSendPayload(l,e,h)}),Object.keys(a).forEach(l=>{let d=a[l];d.is_mint_zero_coin&&an(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=(0,Y.getPackagerConfigs)(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}::${Xt}::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(Y.CLOCK_ADDRESS)]})}),e}createCollectRewarderNoSendPayload(t,e,i){let{clmm_pool:n,integrate:r}=this.sdk.sdkOptions,a=(0,Y.getPackagerConfigs)(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}::${Ne}::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(Y.CLOCK_ADDRESS)]})}),e}};var _n=require("@mysten/sui/transactions"),hn=require("@mysten/sui/utils"),Pe=fe(re()),nt=require("@cetusprotocol/common-sdk");var Jr="amm_swap",Xr="Pool",Ze=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=(0,nt.d)(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 O(r.fee_rate).div(10**6):new O(r.fee_rate).div(10**9),l=(0,nt.d)(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 O(1).div(r.current_price),h=d.direction?d.current_price:new O(1).div(d.current_price),w=d.label==="Cetus"?new O(d.fee_rate).div(10**6):new O(d.fee_rate).div(10**9),M=(0,nt.d)(d.output_amount).div(10**d.to_decimal).mul(w).div(f.mul(h));e=e.add(M)}}}),e.toString()}calculateSwapPriceImpact(t){let e=(0,nt.d)(0);return t.forEach(i=>{let n=i.base_paths.length;if(n===1){let r=i.base_paths[0],a=(0,nt.d)(r.output_amount).div(10**r.to_decimal),l=(0,nt.d)(r.input_amount).div(10**r.from_decimal),d=a.div(l),f=r.direction?new O(r.current_price):new O(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 O(r.current_price):new O(1).div(r.current_price),d=a.direction?new O(a.current_price):new O(1).div(a.current_price),f=l.mul(d),h=new O(a.output_amount).div(10**a.to_decimal),w=new O(r.input_amount).div(10**r.from_decimal),P=h.div(w);e=e.add(this.calculateSingleImpact(P,f))}}),e.toString()}async preSwapWithMultiPool(t){let{integrate:e}=this.sdk.sdkOptions,i=new _n.Transaction,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}::${Yt}::calculate_swap_result`,arguments:h,typeArguments:n})}let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,hn.normalizeSuiAddress)("0x0")});r.error!=null&&B("InvalidConfig",`pre swap with multi pools error code: ${r.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let a=r.events?.filter(f=>(0,nt.extractStructTagFromType)(f.type).name==="CalculatedSwapResultEvent");if(a.length===0)return null;a.length!==t.pool_ids.length&&B("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let l=t.by_amount_in?nt.ZERO:nt.U64_MAX,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 Pe.default(a[f].parsedJson.data.amount_out);h.gt(l)&&(d=f,l=h)}else{let h=new Pe.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 _n.Transaction,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}::${Yt}::calculate_swap_result`,arguments:r,typeArguments:n});let a=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,hn.normalizeSuiAddress)("0x0")});if(a.error!=null)return B("InvalidConfig",`preSwap error code: ${a.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let l=a.events?.filter(d=>(0,nt.extractStructTagFromType)(d.type).name==="CalculatedSwapResultEvent");return l.length===0?B("InvalidConfig",`preSwap error code: ${a.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}}):this.transformSwapData(t,l[0].parsedJson.data)}transformSwapData(t,e){let i=e.amount_in&&e.fee_amount?new Pe.default(e.amount_in).add(new Pe.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 Pe.default(i.amount_in).add(new Pe.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=en(e),n;t.a2b?n=t.swap_ticks.sort((P,M)=>M.index-P.index):n=t.swap_ticks.sort((P,M)=>P.index-M.index);let r=nn(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=ee.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=nt.TickMath.sqrtPriceX64ToPrice(i.current_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),h=nt.TickMath.sqrtPriceX64ToPrice(r.next_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),w=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:w}}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}=ye(t);if(t.a2b&&n||!t.a2b&&r)return await ee.buildSwapTransactionForGas(this._sdk,t,i,e)}return ee.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}=ye(t);if(t.a2b&&n||!t.a2b&&r)return await ee.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,t,i,e)}return ee.buildSwapTransactionWithoutTransferCoins(this.sdk,t,i)}};var Kt=require("@cetusprotocol/common-sdk");var pn=require("@mysten/sui/transactions"),ko=require("@mysten/sui/utils"),ze=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 B("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[Kt.DETAILS_KEYS.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=ie.parseClmmVestInfo(l),f=`${d.id}-ClmmVestInfo`;this._sdk.updateCache(f,d),e.push(d)}),e}catch(i){Wt("ClmmVestFetchError",i,{[Kt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(t=!0){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return B("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[Kt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:i}=(0,Kt.getPackagerConfigs)(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=ie.parseClmmVestInfo(a);return this._sdk.updateCache(n,l),l}catch(a){return Wt("ClmmVestFetchError",a,{[Kt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo",[Kt.DETAILS_KEYS.REQUEST_PARAMS]:{clmm_vest_id:i}})}}async getPositionVesting(t){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return B("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[Kt.DETAILS_KEYS.METHOD_NAME]:"getPositionVesting"});if(t.length===0)return[];let{clmm_vest_id:i}=(0,Kt.getPackagerConfigs)(e),n=new pn.Transaction;t.forEach(l=>{let{clmm_pool_id:d,coin_type_a:f,coin_type_b:h,clmm_position_ids:w}=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",w)]})});let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,ko.normalizeSuiAddress)("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=>ie.parsePositionVesting(f)))}}),a}buildRedeemPayload(t,e){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return B("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[Kt.DETAILS_KEYS.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:n,clmm_vest_id:r,cetus_coin_type:a}=(0,Kt.getPackagerConfigs)(i);return e=e||new pn.Transaction,t.forEach(l=>{let{clmm_pool_id:d,clmm_position_id:f,coin_type_a:h,coin_type_b:w,period:P}=l,M=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(Kt.CLOCK_ADDRESS)],typeArguments:[h,w]}),S=Kt.CoinAssist.fromBalance(M,a,e);e.transferObjects([S],this._sdk.getSenderAddress())}),e}};var Ge=class o extends To.SdkWrapper{constructor(t){super(t),this._swap=new Ze(this),this._pool=new Ve(this),this._position=new He(this),this._config=new Fe(this),this._rewarder=new We(this),this._vest=new ze(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({...cn,...t}):o.createCustomSDK({...un,...t})}static createCustomSDK(t){return new o(t)}};var Qe=fe(re()),le=require("@cetusprotocol/common-sdk");var Yr=new Qe.default(365),ts=new Qe.default(24),es=new Qe.default(3600),is=new Qe.default(.5);function ns(o,t,e,i){return Yr.mul(ts).mul(es).mul(is).mul(o.mul(t).add(e).div(i))}function os(o,t,e,i,n,r){let a=new O(o.toString()).div(new O(10**e)),l=new O(t.toString()).div(new O(10**i));return a.mul(n).add(l.mul(r))}function rs(o,t,e,i,n,r,a,l,d,f,h,w,P,M,S,I,W,$,G,D,K,zt,et,Qt){let ue=new O(w),ne=new O(P),de=new O(I),Z=new O(W),Ht=new O($),y=new O(G),s=new O(D),u=new O(K),_=new O(zt),p=new O(et),g=new O(Qt),v=le.TickMath.tickIndexToSqrtPriceX64(t),C=le.TickMath.tickIndexToSqrtPriceX64(e),m=le.MathUtil.toX64Decimal(le.MathUtil.fromX64(v)).round(),c=le.MathUtil.toX64Decimal(le.MathUtil.fromX64(C)).round(),b=le.MathUtil.toX64Decimal(le.MathUtil.fromX64(i)).round(),x,E=ue.mul(new O(10**r)).mul(c.mul(m)).div(c.sub(m)).round(),R=ne.mul(new O(10**a)).div(c.sub(m)).round();o<t?x=E:o>e?x=R:x=O.min(E,R);let U=x.mul(b.sub(m)),Q=x.mul(c.sub(b)).div(b.mul(c)).div(new O(10**r)).mul(s).add(U.div(new O(10**a).mul(u))),oe=os(M,S,r,a,s,u),J=Q.div(oe),it=x.eq(new O(0))?new O(0):new O(h/1e4).mul(de).mul(new O(x.toString()).div(new O(n.toString()).add(new O(x.toString())))).div(Q),Ce=J.eq(new O(0))?new O(0):J.mul(new O(36500/7)).div(Q),ot=Z.div(new O(10**l)).mul(_).mul(Ce),rt=Ht.div(new O(10**d)).mul(p).mul(Ce),Je=y.div(new O(10**f)).mul(g).mul(Ce);return{fee_apr:it,pos_rewarder_0_apr:ot,pos_rewarder_1_apr:rt,pos_rewarder_2_apr:Je}}function ss(o,t,e,i){let n=Math.max(o,e),a=Math.min(t,i)-n,l=t-o,d=i-e,f=new O(l.toString()),h=new O(d.toString()),w=new O(a.toString()),P=new O("0");return a<0?P=new O("0"):l===a?P=h.div(w):d===a?P=w.div(f):P=w.mul(w).div(h).div(f),P}var as=Ge;0&&(module.exports={AMM_SWAP_MODULE,BPS,CetusClmmSDK,ClmmError,ClmmExpectSwapModule,ClmmFetcherModule,ClmmIntegratePoolModule,ClmmIntegratePoolV2Module,ClmmIntegratePoolV3Module,ClmmIntegrateRouterModule,ClmmIntegrateRouterWithPartnerModule,ClmmIntegrateUtilsModule,ClmmPartnerModule,ClmmPositionStatus,ConfigErrorCode,ConfigModule,DeepbookClobV2Module,DeepbookCustodianV2Module,DeepbookEndpointsV2Module,POOL_STRUCT,PartnerErrorCode,PoolErrorCode,PoolModule,PositionErrorCode,PositionModule,PositionUtils,RewarderModule,RouterErrorCode,SwapErrorCode,SwapModule,SwapUtils,TypesErrorCode,UtilsErrorCode,VestErrorCode,VestModule,VestUtils,buildClmmPositionName,buildPool,buildPoolTransactionInfo,buildPosition,buildPositionInfo,buildPositionTransactionInfo,buildTickData,buildTickDataByEvent,buildTransferCoin,buildTransferCoinToSender,clmmMainnet,clmmTestnet,computeSwap,computeSwapStep,estPoolAPR,estPositionAPRWithDeltaMethod,estPositionAPRWithMultiMethod,eventMainnetContractMaps,eventTestnetContractMaps,findAdjustCoin,getDefaultSuiInputType,getLowerSqrtPriceFromCoinA,getLowerSqrtPriceFromCoinB,getUpperSqrtPriceFromCoinA,getUpperSqrtPriceFromCoinB,handleError,handleMessageError,newBits,poolFilterEvenTypes,poolLiquiditySnapshotType,transClmmpoolDataWithoutTicks});
|
|
1
|
+
"use strict";var Ao=Object.create;var Xe=Object.defineProperty;var So=Object.getOwnPropertyDescriptor;var xo=Object.getOwnPropertyNames;var Io=Object.getPrototypeOf,Eo=Object.prototype.hasOwnProperty;var Oo=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),Ro=(o,t)=>{for(var e in t)Xe(o,e,{get:t[e],enumerable:!0})},En=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of xo(t))!Eo.call(o,n)&&n!==e&&Xe(o,n,{get:()=>t[n],enumerable:!(i=So(t,n))||i.enumerable});return o};var fe=(o,t,e)=>(e=o!=null?Ao(Io(o)):{},En(t||!o||!o.__esModule?Xe(e,"default",{value:o,enumerable:!0}):e,o)),Fo=o=>En(Xe({},"__esModule",{value:!0}),o);var re=Oo((Xn,Vi)=>{"use strict";(function(o,t){"use strict";function e(y,s){if(!y)throw new Error(s||"Assertion failed")}function i(y,s){y.super_=s;var u=function(){};u.prototype=s.prototype,y.prototype=new u,y.prototype.constructor=y}function n(y,s,u){if(n.isBN(y))return y;this.negative=0,this.words=null,this.length=0,this.red=null,y!==null&&((s==="le"||s==="be")&&(u=s,s=10),this._init(y||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=require("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(y,s){var u=y.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 "+y)}function l(y,s,u){var _=a(y,u);return u-1>=s&&(_|=a(y,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(y,s,u,_){for(var p=0,g=0,v=Math.min(y.length,u),C=s;C<v;C++){var m=y.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,b=_;b<m;b+=p)c=d(s,b,b+p,u),this.imuln(g),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(C!==0){var x=1;for(c=d(s,b,s.length,u),b=0;b<C;b++)x*=u;this.imuln(x),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(y,s){y.words=s.words,y.length=s.length,y.negative=s.negative,y.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 w=["","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],M=[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?_=w[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],b=M[s];_="";var x=this.clone();for(x.negative=0;!x.isZero();){var E=x.modrn(b).toString(s);x=x.idivn(b),x.isZero()?_=E+_:_=w[c-E.length]+E+_}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 S=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=S(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 I(y){for(var s=new Array(y.bitLength()),u=0;u<s.length;u++){var _=u/26|0,p=u%26;s[u]=y.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(y,s,u){u.negative=s.negative^y.negative;var _=y.length+s.length|0;u.length=_,_=_-1|0;var p=y.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 b=m>>>26,x=m&67108863,E=Math.min(c,s.length-1),R=Math.max(0,c-y.length+1);R<=E;R++){var U=c-R|0;p=y.words[U]|0,g=s.words[R]|0,v=p*g+x,b+=v/67108864|0,x=v&67108863}u.words[c]=x|0,m=b|0}return m!==0?u.words[c]=m|0:u.length--,u._strip()}var $=function(s,u,_){var p=s.words,g=u.words,v=_.words,C=0,m,c,b,x=p[0]|0,E=x&8191,R=x>>>13,U=p[1]|0,z=U&8191,Q=U>>>13,oe=p[2]|0,J=oe&8191,it=oe>>>13,Ce=p[3]|0,ot=Ce&8191,rt=Ce>>>13,Je=p[4]|0,st=Je&8191,at=Je>>>13,mn=p[5]|0,ct=mn&8191,lt=mn>>>13,gn=p[6]|0,ut=gn&8191,dt=gn>>>13,bn=p[7]|0,ft=bn&8191,_t=bn>>>13,wn=p[8]|0,ht=wn&8191,pt=wn>>>13,yn=p[9]|0,mt=yn&8191,gt=yn>>>13,vn=g[0]|0,bt=vn&8191,wt=vn>>>13,Pn=g[1]|0,yt=Pn&8191,vt=Pn>>>13,Cn=g[2]|0,Pt=Cn&8191,Ct=Cn>>>13,Mn=g[3]|0,Mt=Mn&8191,kt=Mn>>>13,kn=g[4]|0,Tt=kn&8191,At=kn>>>13,Tn=g[5]|0,St=Tn&8191,xt=Tn>>>13,An=g[6]|0,It=An&8191,Et=An>>>13,Sn=g[7]|0,Ot=Sn&8191,Rt=Sn>>>13,xn=g[8]|0,Ft=xn&8191,Nt=xn>>>13,In=g[9]|0,Bt=In&8191,jt=In>>>13;_.negative=s.negative^u.negative,_.length=19,m=Math.imul(E,bt),c=Math.imul(E,wt),c=c+Math.imul(R,bt)|0,b=Math.imul(R,wt);var mi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(mi>>>26)|0,mi&=67108863,m=Math.imul(z,bt),c=Math.imul(z,wt),c=c+Math.imul(Q,bt)|0,b=Math.imul(Q,wt),m=m+Math.imul(E,yt)|0,c=c+Math.imul(E,vt)|0,c=c+Math.imul(R,yt)|0,b=b+Math.imul(R,vt)|0;var gi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,m=Math.imul(J,bt),c=Math.imul(J,wt),c=c+Math.imul(it,bt)|0,b=Math.imul(it,wt),m=m+Math.imul(z,yt)|0,c=c+Math.imul(z,vt)|0,c=c+Math.imul(Q,yt)|0,b=b+Math.imul(Q,vt)|0,m=m+Math.imul(E,Pt)|0,c=c+Math.imul(E,Ct)|0,c=c+Math.imul(R,Pt)|0,b=b+Math.imul(R,Ct)|0;var bi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,m=Math.imul(ot,bt),c=Math.imul(ot,wt),c=c+Math.imul(rt,bt)|0,b=Math.imul(rt,wt),m=m+Math.imul(J,yt)|0,c=c+Math.imul(J,vt)|0,c=c+Math.imul(it,yt)|0,b=b+Math.imul(it,vt)|0,m=m+Math.imul(z,Pt)|0,c=c+Math.imul(z,Ct)|0,c=c+Math.imul(Q,Pt)|0,b=b+Math.imul(Q,Ct)|0,m=m+Math.imul(E,Mt)|0,c=c+Math.imul(E,kt)|0,c=c+Math.imul(R,Mt)|0,b=b+Math.imul(R,kt)|0;var wi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,m=Math.imul(st,bt),c=Math.imul(st,wt),c=c+Math.imul(at,bt)|0,b=Math.imul(at,wt),m=m+Math.imul(ot,yt)|0,c=c+Math.imul(ot,vt)|0,c=c+Math.imul(rt,yt)|0,b=b+Math.imul(rt,vt)|0,m=m+Math.imul(J,Pt)|0,c=c+Math.imul(J,Ct)|0,c=c+Math.imul(it,Pt)|0,b=b+Math.imul(it,Ct)|0,m=m+Math.imul(z,Mt)|0,c=c+Math.imul(z,kt)|0,c=c+Math.imul(Q,Mt)|0,b=b+Math.imul(Q,kt)|0,m=m+Math.imul(E,Tt)|0,c=c+Math.imul(E,At)|0,c=c+Math.imul(R,Tt)|0,b=b+Math.imul(R,At)|0;var yi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,m=Math.imul(ct,bt),c=Math.imul(ct,wt),c=c+Math.imul(lt,bt)|0,b=Math.imul(lt,wt),m=m+Math.imul(st,yt)|0,c=c+Math.imul(st,vt)|0,c=c+Math.imul(at,yt)|0,b=b+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,b=b+Math.imul(rt,Ct)|0,m=m+Math.imul(J,Mt)|0,c=c+Math.imul(J,kt)|0,c=c+Math.imul(it,Mt)|0,b=b+Math.imul(it,kt)|0,m=m+Math.imul(z,Tt)|0,c=c+Math.imul(z,At)|0,c=c+Math.imul(Q,Tt)|0,b=b+Math.imul(Q,At)|0,m=m+Math.imul(E,St)|0,c=c+Math.imul(E,xt)|0,c=c+Math.imul(R,St)|0,b=b+Math.imul(R,xt)|0;var vi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,m=Math.imul(ut,bt),c=Math.imul(ut,wt),c=c+Math.imul(dt,bt)|0,b=Math.imul(dt,wt),m=m+Math.imul(ct,yt)|0,c=c+Math.imul(ct,vt)|0,c=c+Math.imul(lt,yt)|0,b=b+Math.imul(lt,vt)|0,m=m+Math.imul(st,Pt)|0,c=c+Math.imul(st,Ct)|0,c=c+Math.imul(at,Pt)|0,b=b+Math.imul(at,Ct)|0,m=m+Math.imul(ot,Mt)|0,c=c+Math.imul(ot,kt)|0,c=c+Math.imul(rt,Mt)|0,b=b+Math.imul(rt,kt)|0,m=m+Math.imul(J,Tt)|0,c=c+Math.imul(J,At)|0,c=c+Math.imul(it,Tt)|0,b=b+Math.imul(it,At)|0,m=m+Math.imul(z,St)|0,c=c+Math.imul(z,xt)|0,c=c+Math.imul(Q,St)|0,b=b+Math.imul(Q,xt)|0,m=m+Math.imul(E,It)|0,c=c+Math.imul(E,Et)|0,c=c+Math.imul(R,It)|0,b=b+Math.imul(R,Et)|0;var Pi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Pi>>>26)|0,Pi&=67108863,m=Math.imul(ft,bt),c=Math.imul(ft,wt),c=c+Math.imul(_t,bt)|0,b=Math.imul(_t,wt),m=m+Math.imul(ut,yt)|0,c=c+Math.imul(ut,vt)|0,c=c+Math.imul(dt,yt)|0,b=b+Math.imul(dt,vt)|0,m=m+Math.imul(ct,Pt)|0,c=c+Math.imul(ct,Ct)|0,c=c+Math.imul(lt,Pt)|0,b=b+Math.imul(lt,Ct)|0,m=m+Math.imul(st,Mt)|0,c=c+Math.imul(st,kt)|0,c=c+Math.imul(at,Mt)|0,b=b+Math.imul(at,kt)|0,m=m+Math.imul(ot,Tt)|0,c=c+Math.imul(ot,At)|0,c=c+Math.imul(rt,Tt)|0,b=b+Math.imul(rt,At)|0,m=m+Math.imul(J,St)|0,c=c+Math.imul(J,xt)|0,c=c+Math.imul(it,St)|0,b=b+Math.imul(it,xt)|0,m=m+Math.imul(z,It)|0,c=c+Math.imul(z,Et)|0,c=c+Math.imul(Q,It)|0,b=b+Math.imul(Q,Et)|0,m=m+Math.imul(E,Ot)|0,c=c+Math.imul(E,Rt)|0,c=c+Math.imul(R,Ot)|0,b=b+Math.imul(R,Rt)|0;var Ci=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,m=Math.imul(ht,bt),c=Math.imul(ht,wt),c=c+Math.imul(pt,bt)|0,b=Math.imul(pt,wt),m=m+Math.imul(ft,yt)|0,c=c+Math.imul(ft,vt)|0,c=c+Math.imul(_t,yt)|0,b=b+Math.imul(_t,vt)|0,m=m+Math.imul(ut,Pt)|0,c=c+Math.imul(ut,Ct)|0,c=c+Math.imul(dt,Pt)|0,b=b+Math.imul(dt,Ct)|0,m=m+Math.imul(ct,Mt)|0,c=c+Math.imul(ct,kt)|0,c=c+Math.imul(lt,Mt)|0,b=b+Math.imul(lt,kt)|0,m=m+Math.imul(st,Tt)|0,c=c+Math.imul(st,At)|0,c=c+Math.imul(at,Tt)|0,b=b+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,b=b+Math.imul(rt,xt)|0,m=m+Math.imul(J,It)|0,c=c+Math.imul(J,Et)|0,c=c+Math.imul(it,It)|0,b=b+Math.imul(it,Et)|0,m=m+Math.imul(z,Ot)|0,c=c+Math.imul(z,Rt)|0,c=c+Math.imul(Q,Ot)|0,b=b+Math.imul(Q,Rt)|0,m=m+Math.imul(E,Ft)|0,c=c+Math.imul(E,Nt)|0,c=c+Math.imul(R,Ft)|0,b=b+Math.imul(R,Nt)|0;var Mi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,m=Math.imul(mt,bt),c=Math.imul(mt,wt),c=c+Math.imul(gt,bt)|0,b=Math.imul(gt,wt),m=m+Math.imul(ht,yt)|0,c=c+Math.imul(ht,vt)|0,c=c+Math.imul(pt,yt)|0,b=b+Math.imul(pt,vt)|0,m=m+Math.imul(ft,Pt)|0,c=c+Math.imul(ft,Ct)|0,c=c+Math.imul(_t,Pt)|0,b=b+Math.imul(_t,Ct)|0,m=m+Math.imul(ut,Mt)|0,c=c+Math.imul(ut,kt)|0,c=c+Math.imul(dt,Mt)|0,b=b+Math.imul(dt,kt)|0,m=m+Math.imul(ct,Tt)|0,c=c+Math.imul(ct,At)|0,c=c+Math.imul(lt,Tt)|0,b=b+Math.imul(lt,At)|0,m=m+Math.imul(st,St)|0,c=c+Math.imul(st,xt)|0,c=c+Math.imul(at,St)|0,b=b+Math.imul(at,xt)|0,m=m+Math.imul(ot,It)|0,c=c+Math.imul(ot,Et)|0,c=c+Math.imul(rt,It)|0,b=b+Math.imul(rt,Et)|0,m=m+Math.imul(J,Ot)|0,c=c+Math.imul(J,Rt)|0,c=c+Math.imul(it,Ot)|0,b=b+Math.imul(it,Rt)|0,m=m+Math.imul(z,Ft)|0,c=c+Math.imul(z,Nt)|0,c=c+Math.imul(Q,Ft)|0,b=b+Math.imul(Q,Nt)|0,m=m+Math.imul(E,Bt)|0,c=c+Math.imul(E,jt)|0,c=c+Math.imul(R,Bt)|0,b=b+Math.imul(R,jt)|0;var ki=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(ki>>>26)|0,ki&=67108863,m=Math.imul(mt,yt),c=Math.imul(mt,vt),c=c+Math.imul(gt,yt)|0,b=Math.imul(gt,vt),m=m+Math.imul(ht,Pt)|0,c=c+Math.imul(ht,Ct)|0,c=c+Math.imul(pt,Pt)|0,b=b+Math.imul(pt,Ct)|0,m=m+Math.imul(ft,Mt)|0,c=c+Math.imul(ft,kt)|0,c=c+Math.imul(_t,Mt)|0,b=b+Math.imul(_t,kt)|0,m=m+Math.imul(ut,Tt)|0,c=c+Math.imul(ut,At)|0,c=c+Math.imul(dt,Tt)|0,b=b+Math.imul(dt,At)|0,m=m+Math.imul(ct,St)|0,c=c+Math.imul(ct,xt)|0,c=c+Math.imul(lt,St)|0,b=b+Math.imul(lt,xt)|0,m=m+Math.imul(st,It)|0,c=c+Math.imul(st,Et)|0,c=c+Math.imul(at,It)|0,b=b+Math.imul(at,Et)|0,m=m+Math.imul(ot,Ot)|0,c=c+Math.imul(ot,Rt)|0,c=c+Math.imul(rt,Ot)|0,b=b+Math.imul(rt,Rt)|0,m=m+Math.imul(J,Ft)|0,c=c+Math.imul(J,Nt)|0,c=c+Math.imul(it,Ft)|0,b=b+Math.imul(it,Nt)|0,m=m+Math.imul(z,Bt)|0,c=c+Math.imul(z,jt)|0,c=c+Math.imul(Q,Bt)|0,b=b+Math.imul(Q,jt)|0;var Ti=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ti>>>26)|0,Ti&=67108863,m=Math.imul(mt,Pt),c=Math.imul(mt,Ct),c=c+Math.imul(gt,Pt)|0,b=Math.imul(gt,Ct),m=m+Math.imul(ht,Mt)|0,c=c+Math.imul(ht,kt)|0,c=c+Math.imul(pt,Mt)|0,b=b+Math.imul(pt,kt)|0,m=m+Math.imul(ft,Tt)|0,c=c+Math.imul(ft,At)|0,c=c+Math.imul(_t,Tt)|0,b=b+Math.imul(_t,At)|0,m=m+Math.imul(ut,St)|0,c=c+Math.imul(ut,xt)|0,c=c+Math.imul(dt,St)|0,b=b+Math.imul(dt,xt)|0,m=m+Math.imul(ct,It)|0,c=c+Math.imul(ct,Et)|0,c=c+Math.imul(lt,It)|0,b=b+Math.imul(lt,Et)|0,m=m+Math.imul(st,Ot)|0,c=c+Math.imul(st,Rt)|0,c=c+Math.imul(at,Ot)|0,b=b+Math.imul(at,Rt)|0,m=m+Math.imul(ot,Ft)|0,c=c+Math.imul(ot,Nt)|0,c=c+Math.imul(rt,Ft)|0,b=b+Math.imul(rt,Nt)|0,m=m+Math.imul(J,Bt)|0,c=c+Math.imul(J,jt)|0,c=c+Math.imul(it,Bt)|0,b=b+Math.imul(it,jt)|0;var Ai=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,m=Math.imul(mt,Mt),c=Math.imul(mt,kt),c=c+Math.imul(gt,Mt)|0,b=Math.imul(gt,kt),m=m+Math.imul(ht,Tt)|0,c=c+Math.imul(ht,At)|0,c=c+Math.imul(pt,Tt)|0,b=b+Math.imul(pt,At)|0,m=m+Math.imul(ft,St)|0,c=c+Math.imul(ft,xt)|0,c=c+Math.imul(_t,St)|0,b=b+Math.imul(_t,xt)|0,m=m+Math.imul(ut,It)|0,c=c+Math.imul(ut,Et)|0,c=c+Math.imul(dt,It)|0,b=b+Math.imul(dt,Et)|0,m=m+Math.imul(ct,Ot)|0,c=c+Math.imul(ct,Rt)|0,c=c+Math.imul(lt,Ot)|0,b=b+Math.imul(lt,Rt)|0,m=m+Math.imul(st,Ft)|0,c=c+Math.imul(st,Nt)|0,c=c+Math.imul(at,Ft)|0,b=b+Math.imul(at,Nt)|0,m=m+Math.imul(ot,Bt)|0,c=c+Math.imul(ot,jt)|0,c=c+Math.imul(rt,Bt)|0,b=b+Math.imul(rt,jt)|0;var Si=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Si>>>26)|0,Si&=67108863,m=Math.imul(mt,Tt),c=Math.imul(mt,At),c=c+Math.imul(gt,Tt)|0,b=Math.imul(gt,At),m=m+Math.imul(ht,St)|0,c=c+Math.imul(ht,xt)|0,c=c+Math.imul(pt,St)|0,b=b+Math.imul(pt,xt)|0,m=m+Math.imul(ft,It)|0,c=c+Math.imul(ft,Et)|0,c=c+Math.imul(_t,It)|0,b=b+Math.imul(_t,Et)|0,m=m+Math.imul(ut,Ot)|0,c=c+Math.imul(ut,Rt)|0,c=c+Math.imul(dt,Ot)|0,b=b+Math.imul(dt,Rt)|0,m=m+Math.imul(ct,Ft)|0,c=c+Math.imul(ct,Nt)|0,c=c+Math.imul(lt,Ft)|0,b=b+Math.imul(lt,Nt)|0,m=m+Math.imul(st,Bt)|0,c=c+Math.imul(st,jt)|0,c=c+Math.imul(at,Bt)|0,b=b+Math.imul(at,jt)|0;var xi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(xi>>>26)|0,xi&=67108863,m=Math.imul(mt,St),c=Math.imul(mt,xt),c=c+Math.imul(gt,St)|0,b=Math.imul(gt,xt),m=m+Math.imul(ht,It)|0,c=c+Math.imul(ht,Et)|0,c=c+Math.imul(pt,It)|0,b=b+Math.imul(pt,Et)|0,m=m+Math.imul(ft,Ot)|0,c=c+Math.imul(ft,Rt)|0,c=c+Math.imul(_t,Ot)|0,b=b+Math.imul(_t,Rt)|0,m=m+Math.imul(ut,Ft)|0,c=c+Math.imul(ut,Nt)|0,c=c+Math.imul(dt,Ft)|0,b=b+Math.imul(dt,Nt)|0,m=m+Math.imul(ct,Bt)|0,c=c+Math.imul(ct,jt)|0,c=c+Math.imul(lt,Bt)|0,b=b+Math.imul(lt,jt)|0;var Ii=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ii>>>26)|0,Ii&=67108863,m=Math.imul(mt,It),c=Math.imul(mt,Et),c=c+Math.imul(gt,It)|0,b=Math.imul(gt,Et),m=m+Math.imul(ht,Ot)|0,c=c+Math.imul(ht,Rt)|0,c=c+Math.imul(pt,Ot)|0,b=b+Math.imul(pt,Rt)|0,m=m+Math.imul(ft,Ft)|0,c=c+Math.imul(ft,Nt)|0,c=c+Math.imul(_t,Ft)|0,b=b+Math.imul(_t,Nt)|0,m=m+Math.imul(ut,Bt)|0,c=c+Math.imul(ut,jt)|0,c=c+Math.imul(dt,Bt)|0,b=b+Math.imul(dt,jt)|0;var Ei=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ei>>>26)|0,Ei&=67108863,m=Math.imul(mt,Ot),c=Math.imul(mt,Rt),c=c+Math.imul(gt,Ot)|0,b=Math.imul(gt,Rt),m=m+Math.imul(ht,Ft)|0,c=c+Math.imul(ht,Nt)|0,c=c+Math.imul(pt,Ft)|0,b=b+Math.imul(pt,Nt)|0,m=m+Math.imul(ft,Bt)|0,c=c+Math.imul(ft,jt)|0,c=c+Math.imul(_t,Bt)|0,b=b+Math.imul(_t,jt)|0;var Oi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Oi>>>26)|0,Oi&=67108863,m=Math.imul(mt,Ft),c=Math.imul(mt,Nt),c=c+Math.imul(gt,Ft)|0,b=Math.imul(gt,Nt),m=m+Math.imul(ht,Bt)|0,c=c+Math.imul(ht,jt)|0,c=c+Math.imul(pt,Bt)|0,b=b+Math.imul(pt,jt)|0;var Ri=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ri>>>26)|0,Ri&=67108863,m=Math.imul(mt,Bt),c=Math.imul(mt,jt),c=c+Math.imul(gt,Bt)|0,b=Math.imul(gt,jt);var Fi=(C+m|0)+((c&8191)<<13)|0;return C=(b+(c>>>13)|0)+(Fi>>>26)|0,Fi&=67108863,v[0]=mi,v[1]=gi,v[2]=bi,v[3]=wi,v[4]=yi,v[5]=vi,v[6]=Pi,v[7]=Ci,v[8]=Mi,v[9]=ki,v[10]=Ti,v[11]=Ai,v[12]=Si,v[13]=xi,v[14]=Ii,v[15]=Ei,v[16]=Oi,v[17]=Ri,v[18]=Fi,C!==0&&(v[19]=C,_.length++),_};Math.imul||($=W);function G(y,s,u){u.negative=s.negative^y.negative,u.length=y.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-y.length+1);c<=m;c++){var b=g-c,x=y.words[b]|0,E=s.words[c]|0,R=x*E,U=R&67108863;v=v+(R/67108864|0)|0,U=U+C|0,C=U&67108863,v=v+(U>>>26)|0,p+=v>>>26,v&=67108863}u.words[g]=C,_=v,v=p}return _!==0?u.words[g]=_:u.length--,u._strip()}function D(y,s,u){return G(y,s,u)}n.prototype.mulTo=function(s,u){var _,p=this.length+s.length;return this.length===10&&s.length===10?_=$(this,s,u):p<63?_=W(this,s,u):p<1024?_=G(this,s,u):_=D(this,s,u),_};function K(y,s){this.x=y,this.y=s}K.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},K.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},K.prototype.permute=function(s,u,_,p,g,v){for(var C=0;C<v;C++)p[C]=u[s[C]],g[C]=_[s[C]]},K.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),b=Math.sin(2*Math.PI/m),x=0;x<g;x+=m)for(var E=c,R=b,U=0;U<C;U++){var z=_[x+U],Q=p[x+U],oe=_[x+U+C],J=p[x+U+C],it=E*oe-R*J;J=E*J+R*oe,oe=it,_[x+U]=z+oe,p[x+U]=Q+J,_[x+U+C]=z-oe,p[x+U+C]=Q-J,U!==m&&(it=c*E-b*R,R=c*R+b*E,E=it)}},K.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},K.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}},K.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},K.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)},K.prototype.stub=function(s){for(var u=new Array(s),_=0;_<s;_++)u[_]=0;return u},K.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),b=new Array(p),x=new Array(p),E=new Array(p),R=_.words;R.length=p,this.convert13b(s.words,s.length,C,p),this.convert13b(u.words,u.length,b,p),this.transform(C,v,m,c,p,g),this.transform(b,v,x,E,p,g);for(var U=0;U<p;U++){var z=m[U]*x[U]-c[U]*E[U];c[U]=m[U]*E[U]+c[U]*x[U],m[U]=z}return this.conjugate(m,c,p),this.transform(m,c,R,v,p,g),this.conjugate(R,v,p),this.normalize13b(R,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),D(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=I(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 b=0;for(c=this.length-1;c>=0&&(b!==0||c>=p);c--){var x=this.words[c]|0;this.words[c]=b<<26-g|x>>>g,b=x&C}return m&&b!==0&&(m.words[m.length++]=b),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 b=0;b<c.length;b++)c.words[b]=0}var x=p.clone()._ishlnsubmul(g,1,m);x.negative===0&&(p=x,c&&(c.words[m]=1));for(var E=m-1;E>=0;E--){var R=(p.words[g.length+E]|0)*67108864+(p.words[g.length+E-1]|0);for(R=Math.min(R/v|0,67108863),p._ishlnsubmul(g,R,E);p.negative!==0;)R--,p.negative=0,p._ishlnsubmul(g,1,E),p.isZero()||(p.negative^=1);c&&(c.words[E]=R)}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(),b=u.clone();!u.isZero();){for(var x=0,E=1;(u.words[0]&E)===0&&x<26;++x,E<<=1);if(x>0)for(u.iushrn(x);x-- >0;)(p.isOdd()||g.isOdd())&&(p.iadd(c),g.isub(b)),p.iushrn(1),g.iushrn(1);for(var R=0,U=1;(_.words[0]&U)===0&&R<26;++R,U<<=1);if(R>0)for(_.iushrn(R);R-- >0;)(v.isOdd()||C.isOdd())&&(v.iadd(c),C.isub(b)),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,b=1;(_.words[0]&b)===0&&c<26;++c,b<<=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 x;return u.cmpn(1)===0?x=p:x=g,x.cmpn(0)<0&&x.iadd(s),x},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 Z(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 zt={k256:null,p224:null,p192:null,p25519:null};function et(y,s){this.name=y,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()}et.prototype._tmp=function(){var s=new n(null);return s.words=new Array(Math.ceil(this.n/13)),s},et.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},et.prototype.split=function(s,u){s.iushrn(this.n,0,u)},et.prototype.imulK=function(s){return s.imul(this.k)};function Qt(){et.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}i(Qt,et),Qt.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},Qt.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 ue(){et.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}i(ue,et);function ne(){et.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}i(ne,et);function de(){et.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}i(de,et),de.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(zt[s])return zt[s];var u;if(s==="k256")u=new Qt;else if(s==="p224")u=new ue;else if(s==="p192")u=new ne;else if(s==="p25519")u=new de;else throw new Error("Unknown prime "+s);return zt[s]=u,u};function Z(y){if(typeof y=="string"){var s=n._prime(y);this.m=s.p,this.prime=s}else e(y.gtn(1),"modulus must be greater than 1"),this.m=y,this.prime=null}Z.prototype._verify1=function(s){e(s.negative===0,"red works only with positives"),e(s.red,"red works only with red numbers")},Z.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")},Z.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):(f(s,s.umod(this.m)._forceRed(this)),s)},Z.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},Z.prototype.add=function(s,u){this._verify2(s,u);var _=s.add(u);return _.cmp(this.m)>=0&&_.isub(this.m),_._forceRed(this)},Z.prototype.iadd=function(s,u){this._verify2(s,u);var _=s.iadd(u);return _.cmp(this.m)>=0&&_.isub(this.m),_},Z.prototype.sub=function(s,u){this._verify2(s,u);var _=s.sub(u);return _.cmpn(0)<0&&_.iadd(this.m),_._forceRed(this)},Z.prototype.isub=function(s,u){this._verify2(s,u);var _=s.isub(u);return _.cmpn(0)<0&&_.iadd(this.m),_},Z.prototype.shl=function(s,u){return this._verify1(s),this.imod(s.ushln(u))},Z.prototype.imul=function(s,u){return this._verify2(s,u),this.imod(s.imul(u))},Z.prototype.mul=function(s,u){return this._verify2(s,u),this.imod(s.mul(u))},Z.prototype.isqr=function(s){return this.imul(s,s.clone())},Z.prototype.sqr=function(s){return this.mul(s,s)},Z.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 b=this.pow(c,p),x=this.pow(s,p.addn(1).iushrn(1)),E=this.pow(s,p),R=g;E.cmp(v)!==0;){for(var U=E,z=0;U.cmp(v)!==0;z++)U=U.redSqr();e(z<R);var Q=this.pow(b,new n(1).iushln(R-z-1));x=x.redMul(Q),b=Q.redSqr(),E=E.redMul(b),R=z}return x},Z.prototype.invm=function(s){var u=s._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},Z.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 b=u.words[g],x=c-1;x>=0;x--){var E=b>>x&1;if(v!==p[0]&&(v=this.sqr(v)),E===0&&C===0){m=0;continue}C<<=1,C|=E,m++,!(m!==_&&(g!==0||x!==0))&&(v=this.mul(v,p[C]),m=0,C=0)}c=26}return v},Z.prototype.convertTo=function(s){var u=s.umod(this.m);return u===s?u.clone():u},Z.prototype.convertFrom=function(s){var u=s.clone();return u.red=null,u},n.mont=function(s){return new Ht(s)};function Ht(y){Z.call(this,y),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(Ht,Z),Ht.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},Ht.prototype.convertFrom=function(s){var u=this.imod(s.mul(this.rinv));return u.red=null,u},Ht.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)},Ht.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)},Ht.prototype.invm=function(s){var u=this.imod(s._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof Vi>"u"||Vi,Xn)});var cs={};Ro(cs,{AMM_SWAP_MODULE:()=>Jr,BPS:()=>go,CetusClmmSDK:()=>Ge,ClmmError:()=>be,ClmmExpectSwapModule:()=>Ho,ClmmFetcherModule:()=>Yt,ClmmIntegratePoolModule:()=>Ae,ClmmIntegratePoolV2Module:()=>Xt,ClmmIntegratePoolV3Module:()=>Ne,ClmmIntegrateRouterModule:()=>Be,ClmmIntegrateRouterWithPartnerModule:()=>zi,ClmmIntegrateUtilsModule:()=>Gi,ClmmPartnerModule:()=>Zi,ClmmPositionStatus:()=>Hi,ConfigErrorCode:()=>we,ConfigModule:()=>Fe,DeepbookClobV2Module:()=>Zo,DeepbookCustodianV2Module:()=>Wo,DeepbookEndpointsV2Module:()=>zo,POOL_STRUCT:()=>Xr,PartnerErrorCode:()=>$i,PoolErrorCode:()=>Te,PoolModule:()=>Ve,PositionErrorCode:()=>Re,PositionModule:()=>He,PositionUtils:()=>Gt,RewarderModule:()=>We,RouterErrorCode:()=>Jn,SwapErrorCode:()=>Di,SwapModule:()=>Ze,SwapUtils:()=>ee,TypesErrorCode:()=>Ui,UtilsErrorCode:()=>ii,VestErrorCode:()=>Li,VestModule:()=>ze,VestUtils:()=>ie,buildClmmPositionName:()=>Qr,buildPool:()=>De,buildPoolTransactionInfo:()=>sn,buildPosition:()=>Le,buildPositionInfo:()=>Ie,buildPositionTransactionInfo:()=>rn,buildTickData:()=>$e,buildTickDataByEvent:()=>on,buildTransferCoin:()=>an,buildTransferCoinToSender:()=>Ue,clmmMainnet:()=>cn,clmmTestnet:()=>un,computeSwap:()=>nn,computeSwapStep:()=>mo,default:()=>as,estPoolAPR:()=>ns,estPositionAPRWithDeltaMethod:()=>rs,estPositionAPRWithMultiMethod:()=>ss,eventMainnetContractMaps:()=>ln,eventTestnetContractMaps:()=>dn,findAdjustCoin:()=>ye,getDefaultSuiInputType:()=>Go,getLowerSqrtPriceFromCoinA:()=>Kr,getLowerSqrtPriceFromCoinB:()=>Wr,getUpperSqrtPriceFromCoinA:()=>Hr,getUpperSqrtPriceFromCoinB:()=>Zr,handleError:()=>Wt,handleMessageError:()=>B,newBits:()=>zr,poolFilterEvenTypes:()=>Wi,poolLiquiditySnapshotType:()=>Ki,transClmmpoolDataWithoutTicks:()=>en});module.exports=Fo(cs);var To=require("@cetusprotocol/common-sdk");var ni=require("@mysten/sui/utils"),F=require("@cetusprotocol/common-sdk");var jn="3.7.8",No=jn,ke=typeof Buffer=="function",On=typeof TextDecoder=="function"?new TextDecoder:void 0,Rn=typeof TextEncoder=="function"?new TextEncoder:void 0,Bo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Oe=Array.prototype.slice.call(Bo),Ye=(o=>{let t={};return o.forEach((e,i)=>t[e]=i),t})(Oe),jo=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Dt=String.fromCharCode.bind(String),Fn=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):o=>new Uint8Array(Array.prototype.slice.call(o,0)),qn=o=>o.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),Dn=o=>o.replace(/[^A-Za-z0-9\+\/]/g,""),Ln=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+=Oe[t>>18&63]+Oe[t>>12&63]+Oe[t>>6&63]+Oe[t&63]}return a?r.slice(0,a-3)+"===".substring(a):r},ji=typeof btoa=="function"?o=>btoa(o):ke?o=>Buffer.from(o,"binary").toString("base64"):Ln,Ni=ke?o=>Buffer.from(o).toString("base64"):o=>{let e=[];for(let i=0,n=o.length;i<n;i+=4096)e.push(Dt.apply(null,o.subarray(i,i+4096)));return ji(e.join(""))},ti=(o,t=!1)=>t?qn(Ni(o)):Ni(o),qo=o=>{if(o.length<2){var t=o.charCodeAt(0);return t<128?o:t<2048?Dt(192|t>>>6)+Dt(128|t&63):Dt(224|t>>>12&15)+Dt(128|t>>>6&63)+Dt(128|t&63)}else{var t=65536+(o.charCodeAt(0)-55296)*1024+(o.charCodeAt(1)-56320);return Dt(240|t>>>18&7)+Dt(128|t>>>12&63)+Dt(128|t>>>6&63)+Dt(128|t&63)}},Do=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,$n=o=>o.replace(Do,qo),Nn=ke?o=>Buffer.from(o,"utf8").toString("base64"):Rn?o=>Ni(Rn.encode(o)):o=>ji($n(o)),Me=(o,t=!1)=>t?qn(Nn(o)):Nn(o),Bn=o=>Me(o,!0),Lo=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,$o=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 Dt((e>>>10)+55296)+Dt((e&1023)+56320);case 3:return Dt((15&o.charCodeAt(0))<<12|(63&o.charCodeAt(1))<<6|63&o.charCodeAt(2));default:return Dt((31&o.charCodeAt(0))<<6|63&o.charCodeAt(1))}},Un=o=>o.replace(Lo,$o),Vn=o=>{if(o=o.replace(/\s+/g,""),!jo.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=Ye[o.charAt(r++)]<<18|Ye[o.charAt(r++)]<<12|(e=Ye[o.charAt(r++)])<<6|(i=Ye[o.charAt(r++)]),e===64?n.push(Dt(t>>16&255)):i===64?n.push(Dt(t>>16&255,t>>8&255)):n.push(Dt(t>>16&255,t>>8&255,t&255));return n.join("")},qi=typeof atob=="function"?o=>atob(Dn(o)):ke?o=>Buffer.from(o,"base64").toString("binary"):Vn,Kn=ke?o=>Fn(Buffer.from(o,"base64")):o=>Fn(qi(o).split("").map(t=>t.charCodeAt(0))),Hn=o=>Kn(Wn(o)),Uo=ke?o=>Buffer.from(o,"base64").toString("utf8"):On?o=>On.decode(Kn(o)):o=>Un(qi(o)),Wn=o=>Dn(o.replace(/[-_]/g,t=>t=="-"?"+":"/")),Bi=o=>Uo(Wn(o)),Vo=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)},Zn=o=>({value:o,enumerable:!1,writable:!0,configurable:!0}),zn=function(){let o=(t,e)=>Object.defineProperty(String.prototype,t,Zn(e));o("fromBase64",function(){return Bi(this)}),o("toBase64",function(t){return Me(this,t)}),o("toBase64URI",function(){return Me(this,!0)}),o("toBase64URL",function(){return Me(this,!0)}),o("toUint8Array",function(){return Hn(this)})},Gn=function(){let o=(t,e)=>Object.defineProperty(Uint8Array.prototype,t,Zn(e));o("toBase64",function(t){return ti(this,t)}),o("toBase64URI",function(){return ti(this,!0)}),o("toBase64URL",function(){return ti(this,!0)})},Ko=()=>{zn(),Gn()},ei={version:jn,VERSION:No,atob:qi,atobPolyfill:Vn,btoa:ji,btoaPolyfill:Ln,fromBase64:Bi,toBase64:Me,encode:Me,encodeURI:Bn,encodeURL:Bn,utob:$n,btou:Un,decode:Bi,isValid:Vo,fromUint8Array:ti,toUint8Array:Hn,extendString:zn,extendUint8Array:Gn,extendBuiltins:Ko};var Qn=require("@cetusprotocol/common-sdk"),Di=(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))(Di||{}),Re=(r=>(r.InvalidTickEvent="InvalidTickEvent",r.InvalidPositionObject="InvalidPositionObject",r.InvalidPositionRewardObject="InvalidPositionRewardObject",r.InvalidParams="InvalidParams",r.FetchError="FetchError",r))(Re||{}),Te=(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))(Te||{}),Li=(e=>(e.ClmmVestNotSet="ClmmVestNotSet",e.ClmmVestFetchError="ClmmVestFetchError",e))(Li||{}),$i=(e=>(e.NotFoundPartnerObject="NotFoundPartnerObject",e.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",e))($i||{}),we=(i=>(i.InvalidConfig="InvalidConfig",i.InvalidConfigHandle="InvalidConfigHandle",i.InvalidSimulateAccount="InvalidSimulateAccount",i))(we||{}),ii=(a=>(a.InvalidSendAddress="InvalidSendAddress",a.InvalidRecipientAddress="InvalidRecipientAddress",a.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",a.InsufficientBalance="InsufficientBalance",a.InvalidTarget="InvalidTarget",a.InvalidTransactionBuilder="InvalidTransactionBuilder",a))(ii||{}),Jn=(a=>(a.InvalidCoin="InvalidCoin",a.NotFoundPath="NotFoundPath",a.NoDowngradeNeedParams="NoDowngradeNeedParams",a.InvalidSwapCountUrl="InvalidSwapCountUrl",a.InvalidTransactionBuilder="InvalidTransactionBuilder",a.InvalidServerResponse="InvalidServerResponse",a))(Jn||{}),Ui=(t=>(t.InvalidType="InvalidType",t))(Ui||{}),be=class extends Qn.BaseError{constructor(t,e,i){super(t,e||"UnknownError",i)}static isVaultsErrorCode(t,e){return this.isErrorCode(t,e)}},Wt=(o,t,e)=>{throw new be(t.message,o,e)},B=(o,t,e)=>{throw new be(t,o,e)};var Fe=class{constructor(t){this._cache={};this._sdk=t}get sdk(){return this._sdk}setTokenListCache(t){let{coin_list_handle:e}=(0,F.getPackagerConfigs)(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}=(0,F.getPackagerConfigs)(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((0,F.normalizeCoinType)(d)===(0,F.normalizeCoinType)(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 w={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]=w,this.updateCache(d,w,F.CACHE_TIME_24H)}else console.log(`not found ${l}`)}}return e}async getCoinConfigs(t=!1,e=!0){let{coin_list_handle:i}=(0,F.getPackagerConfigs)(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")&&B("FetchError",`when getCoinConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getCoinConfigs"});let w=this.buildCoinConfig(h,e);this.updateCache(`${i}_${w.address}_getCoinConfig`,w,F.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,F.CACHE_TIME_24H),f}async getCoinConfig(t,e=!1,i=!0){let{coin_list_handle:n}=(0,F.getPackagerConfigs)(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:(0,F.fixCoinType)(t)}}});(l.error!=null||l.data?.content?.dataType!=="moveObject")&&B("FetchError",`when getCoinConfig get object error: ${l.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getCoinConfig"});let d=this.buildCoinConfig(l,i);return this.updateCache(r,d,F.CACHE_TIME_24H),d}buildCoinConfig(t,e=!0){let i=(0,F.getObjectFields)(t);i=i.value.fields;let n={...i};return n.id=(0,F.getObjectId)(t),n.address=(0,F.extractStructTagFromType)(i.coin_type.fields.name).full_address,i.pyth_id&&(n.pyth_id=(0,ni.normalizeSuiObjectId)(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}=(0,F.getPackagerConfigs)(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")&&B("FetchError",`when getClmmPoolsConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getClmmPoolConfigs"});let w=this.buildClmmPoolConfig(h,e);this.updateCache(`${w.pool_address}_getClmmPoolConfig`,w,F.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,F.CACHE_TIME_24H),f}async getClmmPoolConfig(t,e=!1,i=!0){let{clmm_pools_handle:n}=(0,F.getPackagerConfigs)(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,F.CACHE_TIME_24H),d}buildClmmPoolConfig(t,e=!0){let i=(0,F.getObjectFields)(t);i=i.value.fields;let n={...i};return n.id=(0,F.getObjectId)(t),n.pool_address=(0,ni.normalizeSuiObjectId)(i.pool_address),this.transformExtensions(n,i.extension_fields.fields.contents,e),n}async getLaunchpadPoolConfigs(t=!1,e=!0){let{launchpad_pools_handle:i}=(0,F.getPackagerConfigs)(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")&&B("FetchError",`when getCoinConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getLaunchpadPoolConfigs"});let w=this.buildLaunchpadPoolConfig(h,e);this.updateCache(`${w.pool_address}_getLaunchpadPoolConfig`,w,F.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,F.CACHE_TIME_24H),f}async getLaunchpadPoolConfig(t,e=!1,i=!0){let{launchpad_pools_handle:n}=(0,F.getPackagerConfigs)(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,F.CACHE_TIME_24H),d}buildLaunchpadPoolConfig(t,e=!0){let i=(0,F.getObjectFields)(t);i=i.value.fields;let n={...i};n.id=(0,F.getObjectId)(t),n.pool_address=(0,ni.normalizeSuiObjectId)(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(ei.decode(n.regulation).replace(/%/g,"%25"))}catch{n.regulation=ei.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(ei.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=(0,F.getObjectPreviousTransactionDigest)(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((0,F.extractStructTagFromType)(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,F.CACHE_TIME_24H),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")&&B("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${n.error}, please check the rpc and contracts address config.`,{[F.DETAILS_KEYS.METHOD_NAME]:"getCetusConfigHandle"});let r=(0,F.getObjectFields)(n),a=(0,F.getObjectType)(n);switch((0,F.extractStructTagFromType)(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=F.CACHE_TIME_5MIN){let n=this._cache[t];n?(n.overdue_time=(0,F.getFutureTime)(i),n.value=e):n=new F.CachedContent(e,(0,F.getFutureTime)(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 vo=require("@mysten/sui/client"),Ee=require("@mysten/sui/transactions"),ve=require("@mysten/sui/utils"),Po=fe(re());var Ki="position_liquidity_snapshot",Hi=(i=>(i.Deleted="Deleted",i.Exists="Exists",i.NotExists="NotExists",i))(Hi||{}),Wi=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent","AddLiquidityV2Event","RemoveLiquidityV2Event"];var Vt=fe(re()),V=require("@cetusprotocol/common-sdk");var _i=require("@mysten/sui/transactions"),po=fe(re()),H=require("@cetusprotocol/common-sdk");var Zi="partner",Ae="pool_script",Xt="pool_script_v2",Ne="pool_script_v3",Be="router",zi="router_with_partner",Yt="fetcher_script",Ho="expect_swap",Gi="utils",Wo="custodian_v2",Zo="clob_v2",zo="endpoints_v2",Go=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 be(`Unknown type for value: ${o}`,"InvalidType")};var fi=require("@mysten/sui/transactions"),ho=fe(re()),X=require("@cetusprotocol/common-sdk");var Se=9e15,ge=1e9,Qi="0123456789abcdef",si="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ai="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ji={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Se,maxE:Se,crypto:!1},io,_e,L=!0,li="[DecimalError] ",me=li+"Invalid argument: ",no=li+"Precision limit exceeded",oo=li+"crypto unavailable",ro="[object Decimal]",Ut=Math.floor,qt=Math.pow,Qo=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Jo=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Xo=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,so=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,te=1e7,j=7,Yo=9007199254740991,tr=si.length-1,Xi=ai.length-1,k={toStringTag:ro};k.absoluteValue=k.abs=function(){var o=new this.constructor(this);return o.s<0&&(o.s=1),N(o)};k.ceil=function(){return N(new this.constructor(this),this.e+1,2)};k.clampedTo=k.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(me+t);return e=i.cmp(o),e<0?o:i.cmp(t)>0?t:new n(i)};k.comparedTo=k.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};k.cosine=k.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())+j,i.rounding=1,e=er(i,fo(i,e)),i.precision=o,i.rounding=t,N(_e==2||_e==3?e.neg():e,o,t,!0)):new i(1):new i(NaN)};k.cubeRoot=k.cbrt=function(){var o,t,e,i,n,r,a,l,d,f,h=this,w=h.constructor;if(!h.isFinite()||h.isZero())return new w(h);for(L=!1,r=h.s*qt(h.s*h,1/3),!r||Math.abs(r)==1/0?(e=Lt(h.d),o=h.e,(r=(o-e.length+1)%3)&&(e+=r==1||r==-2?"0":"00"),r=qt(e,1/3),o=Ut((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 w(e),i.s=h.s):i=new w(r.toString()),a=(o=w.precision)+3;;)if(l=i,d=l.times(l).times(l),f=d.plus(h),i=tt(f.plus(h).times(l),f.plus(d),a+2,1),Lt(l.d).slice(0,a)===(e=Lt(i.d)).slice(0,a))if(e=e.slice(a-3,a+1),e=="9999"||!n&&e=="4999"){if(!n&&(N(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")&&(N(i,o+1,1),t=!i.times(i).times(i).eq(h));break}return L=!0,N(i,o,w.rounding,t)};k.decimalPlaces=k.dp=function(){var o,t=this.d,e=NaN;if(t){if(o=t.length-1,e=(o-Ut(this.e/j))*j,o=t[o],o)for(;o%10==0;o/=10)e--;e<0&&(e=0)}return e};k.dividedBy=k.div=function(o){return tt(this,new this.constructor(o))};k.dividedToIntegerBy=k.divToInt=function(o){var t=this,e=t.constructor;return N(tt(t,new e(o),0,1,1),e.precision,e.rounding)};k.equals=k.eq=function(o){return this.cmp(o)===0};k.floor=function(){return N(new this.constructor(this),this.e+1,3)};k.greaterThan=k.gt=function(o){return this.cmp(o)>0};k.greaterThanOrEqualTo=k.gte=function(o){var t=this.cmp(o);return t==1||t===0};k.hyperbolicCosine=k.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/di(4,o)).toString()):(o=16,t="2.3283064365386962890625e-10"),r=xe(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 N(r,a.precision=e,a.rounding=i,!0)};k.hyperbolicSine=k.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=xe(r,2,n,n,!0);else{o=1.4*Math.sqrt(i),o=o>16?16:o|0,n=n.times(1/di(5,o)),n=xe(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,N(n,t,e,!0)};k.hyperbolicTangent=k.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,tt(e.sinh(),e.cosh(),i.precision=o,i.rounding=t)):new i(e.s)};k.inverseCosine=k.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()?se(t,i,n):new t(0):new t(NaN):o.isZero()?se(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))};k.inverseHyperbolicCosine=k.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,L=!1,e=e.times(e).minus(1).sqrt().plus(e),L=!0,i.precision=o,i.rounding=t,e.ln()):new i(e)};k.inverseHyperbolicSine=k.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,L=!1,e=e.times(e).plus(1).sqrt().plus(e),L=!0,i.precision=o,i.rounding=t,e.ln())};k.inverseHyperbolicTangent=k.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?N(new r(n),o,t,!0):(r.precision=e=i-n.e,n=tt(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)};k.inverseSine=k.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=se(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)))};k.inverseTangent=k.atan=function(){var o,t,e,i,n,r,a,l,d,f=this,h=f.constructor,w=h.precision,P=h.rounding;if(f.isFinite()){if(f.isZero())return new h(f);if(f.abs().eq(1)&&w+4<=Xi)return a=se(h,w+4,P).times(.25),a.s=f.s,a}else{if(!f.s)return new h(NaN);if(w+4<=Xi)return a=se(h,w+4,P).times(.5),a.s=f.s,a}for(h.precision=l=w+10,h.rounding=1,e=Math.min(28,l/j+2|0),o=e;o;--o)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(L=!1,t=Math.ceil(l/j),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)),L=!0,N(a,h.precision=w,h.rounding=P,!0)};k.isFinite=function(){return!!this.d};k.isInteger=k.isInt=function(){return!!this.d&&Ut(this.e/j)>this.d.length-2};k.isNaN=function(){return!this.s};k.isNegative=k.isNeg=function(){return this.s<0};k.isPositive=k.isPos=function(){return this.s>0};k.isZero=function(){return!!this.d&&this.d[0]===0};k.lessThan=k.lt=function(o){return this.cmp(o)<0};k.lessThanOrEqualTo=k.lte=function(o){return this.cmp(o)<1};k.logarithm=k.log=function(o){var t,e,i,n,r,a,l,d,f=this,h=f.constructor,w=h.precision,P=h.rounding,M=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(L=!1,l=w+M,a=pe(f,l),i=t?ci(h,l+10):pe(o,l),d=tt(a,i,l,1),je(d.d,n=w,P))do if(l+=10,a=pe(f,l),i=t?ci(h,l+10):pe(o,l),d=tt(a,i,l,1),!r){+Lt(d.d).slice(n+1,n+15)+1==1e14&&(d=N(d,w+1,0));break}while(je(d.d,n+=10,P));return L=!0,N(d,w,P)};k.minus=k.sub=function(o){var t,e,i,n,r,a,l,d,f,h,w,P,M=this,S=M.constructor;if(o=new S(o),!M.d||!o.d)return!M.s||!o.s?o=new S(NaN):M.d?o.s=-o.s:o=new S(o.d||M.s!==o.s?M:NaN),o;if(M.s!=o.s)return o.s=-o.s,M.plus(o);if(f=M.d,P=o.d,l=S.precision,d=S.rounding,!f[0]||!P[0]){if(P[0])o.s=-o.s;else if(f[0])o=new S(M);else return new S(d===3?-0:0);return L?N(o,l,d):o}if(e=Ut(o.e/j),h=Ut(M.e/j),f=f.slice(),r=h-e,r){for(w=r<0,w?(t=f,r=-r,a=P.length):(t=P,e=h,a=f.length),i=Math.max(Math.ceil(l/j),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,w=i<a,w&&(a=i),i=0;i<a;i++)if(f[i]!=P[i]){w=f[i]<P[i];break}r=0}for(w&&(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]=te-1;--f[n],f[i]+=te}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=ui(f,e),L?N(o,l,d):o):new S(d===3?-0:0)};k.modulo=k.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]?N(new i(e),i.precision,i.rounding):(L=!1,i.modulo==9?(t=tt(e,o.abs(),0,3,1),t.s*=o.s):t=tt(e,o,0,i.modulo,1),t=t.times(o),L=!0,e.minus(t))};k.naturalExponential=k.exp=function(){return Yi(this)};k.naturalLogarithm=k.ln=function(){return pe(this)};k.negated=k.neg=function(){var o=new this.constructor(this);return o.s=-o.s,N(o)};k.plus=k.add=function(o){var t,e,i,n,r,a,l,d,f,h,w=this,P=w.constructor;if(o=new P(o),!w.d||!o.d)return!w.s||!o.s?o=new P(NaN):w.d||(o=new P(o.d||w.s===o.s?w:NaN)),o;if(w.s!=o.s)return o.s=-o.s,w.minus(o);if(f=w.d,h=o.d,l=P.precision,d=P.rounding,!f[0]||!h[0])return h[0]||(o=new P(w)),L?N(o,l,d):o;if(r=Ut(w.e/j),i=Ut(o.e/j),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/j),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)/te|0,f[n]%=te;for(t&&(f.unshift(t),++i),a=f.length;f[--a]==0;)f.pop();return o.d=f,o.e=ui(f,i),L?N(o,l,d):o};k.precision=k.sd=function(o){var t,e=this;if(o!==void 0&&o!==!!o&&o!==1&&o!==0)throw Error(me+o);return e.d?(t=ao(e.d),o&&e.e+1>t&&(t=e.e+1)):t=NaN,t};k.round=function(){var o=this,t=o.constructor;return N(new t(o),o.e+1,t.rounding)};k.sine=k.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())+j,i.rounding=1,e=nr(i,fo(i,e)),i.precision=o,i.rounding=t,N(_e>2?e.neg():e,o,t,!0)):new i(NaN)};k.squareRoot=k.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(L=!1,f=Math.sqrt(+a),f==0||f==1/0?(t=Lt(l),(t.length+d)%2==0&&(t+="0"),f=Math.sqrt(t),d=Ut((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(tt(a,r,e+2,1)).times(.5),Lt(r.d).slice(0,e)===(t=Lt(i.d)).slice(0,e))if(t=t.slice(e-3,e+1),t=="9999"||!n&&t=="4999"){if(!n&&(N(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")&&(N(i,d+1,1),o=!i.times(i).eq(a));break}return L=!0,N(i,d,h.rounding,o)};k.tangent=k.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=tt(e,new i(1).minus(e.times(e)).sqrt(),o+10,0),i.precision=o,i.rounding=t,N(_e==2||_e==4?e.neg():e,o,t,!0)):new i(NaN)};k.times=k.mul=function(o){var t,e,i,n,r,a,l,d,f,h=this,w=h.constructor,P=h.d,M=(o=new w(o)).d;if(o.s*=h.s,!P||!P[0]||!M||!M[0])return new w(!o.s||P&&!P[0]&&!M||M&&!M[0]&&!P?NaN:!P||!M?o.s/0:o.s*0);for(e=Ut(h.e/j)+Ut(o.e/j),d=P.length,f=M.length,d<f&&(r=P,P=M,M=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]+M[i]*P[n-i-1]+t,r[n--]=l%te|0,t=l/te|0;r[n]=(r[n]+t)%te|0}for(;!r[--a];)r.pop();return t?++e:r.shift(),o.d=r,o.e=ui(r,e),L?N(o,w.precision,w.rounding):o};k.toBinary=function(o,t){return tn(this,2,o,t)};k.toDecimalPlaces=k.toDP=function(o,t){var e=this,i=e.constructor;return e=new i(e),o===void 0?e:(Zt(o,0,ge),t===void 0?t=i.rounding:Zt(t,0,8),N(e,o+e.e+1,t))};k.toExponential=function(o,t){var e,i=this,n=i.constructor;return o===void 0?e=ae(i,!0):(Zt(o,0,ge),t===void 0?t=n.rounding:Zt(t,0,8),i=N(new n(i),o+1,t),e=ae(i,!0,o+1)),i.isNeg()&&!i.isZero()?"-"+e:e};k.toFixed=function(o,t){var e,i,n=this,r=n.constructor;return o===void 0?e=ae(n):(Zt(o,0,ge),t===void 0?t=r.rounding:Zt(t,0,8),i=N(new r(n),o+n.e+1,t),e=ae(i,!1,o+i.e+1)),n.isNeg()&&!n.isZero()?"-"+e:e};k.toFraction=function(o){var t,e,i,n,r,a,l,d,f,h,w,P,M=this,S=M.d,I=M.constructor;if(!S)return new I(M);if(f=e=new I(1),i=d=new I(0),t=new I(i),r=t.e=ao(S)-M.e-1,a=r%j,t.d[0]=qt(10,a<0?j+a:a),o==null)o=r>0?t:f;else{if(l=new I(o),!l.isInt()||l.lt(f))throw Error(me+l);o=l.gt(t)?r>0?t:f:l}for(L=!1,l=new I(Lt(S)),h=I.precision,I.precision=r=S.length*j*2;w=tt(l,t,0,1,1),n=e.plus(w.times(i)),n.cmp(o)!=1;)e=i,i=n,n=f,f=d.plus(w.times(n)),d=n,n=t,t=l.minus(w.times(n)),l=n;return n=tt(o.minus(e),i,0,1,1),d=d.plus(n.times(f)),e=e.plus(n.times(i)),d.s=f.s=M.s,P=tt(f,i,r,1).minus(M).abs().cmp(tt(d,e,r,1).minus(M).abs())<1?[f,i]:[d,e],I.precision=h,L=!0,P};k.toHexadecimal=k.toHex=function(o,t){return tn(this,16,o,t)};k.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:Zt(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]?(L=!1,e=tt(e,o,0,t,1).times(o),L=!0,N(e)):(o.s=e.s,e=o),e};k.toNumber=function(){return+this};k.toOctal=function(o,t){return tn(this,8,o,t)};k.toPower=k.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(qt(+l,f));if(l=new d(l),l.eq(1))return l;if(i=d.precision,r=d.rounding,o.eq(1))return N(l,i,r);if(t=Ut(o.e/j),t>=o.d.length-1&&(e=f<0?-f:f)<=Yo)return n=co(d,l,e,i),o.s<0?new d(1).div(n):N(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=qt(+l,f),t=e==0||!isFinite(e)?Ut(f*(Math.log("0."+Lt(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):(L=!1,d.rounding=l.s=1,e=Math.min(12,(t+"").length),n=Yi(o.times(pe(l,i+e)),i),n.d&&(n=N(n,i+5,1),je(n.d,i,r)&&(t=i+10,n=N(Yi(o.times(pe(l,t+e)),t),t+5,1),+Lt(n.d).slice(i+1,i+15)+1==1e14&&(n=N(n,i+1,0)))),n.s=a,L=!0,d.rounding=r,N(n,i,r))};k.toPrecision=function(o,t){var e,i=this,n=i.constructor;return o===void 0?e=ae(i,i.e<=n.toExpNeg||i.e>=n.toExpPos):(Zt(o,1,ge),t===void 0?t=n.rounding:Zt(t,0,8),i=N(new n(i),o,t),e=ae(i,o<=i.e||i.e<=n.toExpNeg,o)),i.isNeg()&&!i.isZero()?"-"+e:e};k.toSignificantDigits=k.toSD=function(o,t){var e=this,i=e.constructor;return o===void 0?(o=i.precision,t=i.rounding):(Zt(o,1,ge),t===void 0?t=i.rounding:Zt(t,0,8)),N(new i(e),o,t)};k.toString=function(){var o=this,t=o.constructor,e=ae(o,o.e<=t.toExpNeg||o.e>=t.toExpPos);return o.isNeg()&&!o.isZero()?"-"+e:e};k.truncated=k.trunc=function(){return N(new this.constructor(this),this.e+1,1)};k.valueOf=k.toJSON=function(){var o=this,t=o.constructor,e=ae(o,o.e<=t.toExpNeg||o.e>=t.toExpPos);return o.isNeg()?"-"+e:e};function Lt(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=j-i.length,e&&(r+=he(e)),r+=i;a=o[t],i=a+"",e=j-i.length,e&&(r+=he(e))}else if(a===0)return"0";for(;a%10===0;)a/=10;return r+a}function Zt(o,t,e){if(o!==~~o||o<t||o>e)throw Error(me+o)}function je(o,t,e,i){var n,r,a,l;for(r=o[0];r>=10;r/=10)--t;return--t<0?(t+=j,n=0):(n=Math.ceil((t+1)/j),t%=j),r=qt(10,j-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)==qt(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)==qt(10,t-3)-1,a}function oi(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]+=Qi.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 er(o,t){var e,i,n;if(t.isZero())return t;i=t.d.length,i<32?(e=Math.ceil(i/3),n=(1/di(4,e)).toString()):(e=16,n="2.3283064365386962890625e-10"),o.precision+=e,t=xe(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 tt=(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,w,P,M,S,I,W,$,G,D,K,zt,et,Qt,ue,ne,de,Z,Ht,y=i.constructor,s=i.s==n.s?1:-1,u=i.d,_=n.d;if(!u||!u[0]||!_||!_[0])return new y(!i.s||!n.s||(u?_&&u[0]==_[0]:!_)?NaN:u&&u[0]==0||!_?s*0:s/0);for(d?(M=1,h=i.e-n.e):(d=te,M=j,h=Ut(i.e/M)-Ut(n.e/M)),Z=_.length,ne=u.length,$=new y(s),G=$.d=[],w=0;_[w]==(u[w]||0);w++);if(_[w]>(u[w]||0)&&h--,r==null?(et=r=y.precision,a=y.rounding):l?et=r+(i.e-n.e)+1:et=r,et<0)G.push(1),S=!0;else{if(et=et/M+2|0,w=0,Z==1){for(P=0,_=_[0],et++;(w<ne||P)&&et--;w++)Qt=P*d+(u[w]||0),G[w]=Qt/_|0,P=Qt%_|0;S=P||w<ne}else{for(P=d/(_[0]+1)|0,P>1&&(_=o(_,P,d),u=o(u,P,d),Z=_.length,ne=u.length),ue=Z,D=u.slice(0,Z),K=D.length;K<Z;)D[K++]=0;Ht=_.slice(),Ht.unshift(0),de=_[0],_[1]>=d/2&&++de;do P=0,f=t(_,D,Z,K),f<0?(zt=D[0],Z!=K&&(zt=zt*d+(D[1]||0)),P=zt/de|0,P>1?(P>=d&&(P=d-1),I=o(_,P,d),W=I.length,K=D.length,f=t(I,D,W,K),f==1&&(P--,e(I,Z<W?Ht:_,W,d))):(P==0&&(f=P=1),I=_.slice()),W=I.length,W<K&&I.unshift(0),e(D,I,K,d),f==-1&&(K=D.length,f=t(_,D,Z,K),f<1&&(P++,e(D,Z<K?Ht:_,K,d))),K=D.length):f===0&&(P++,D=[0]),G[w++]=P,f&&D[0]?D[K++]=u[ue]||0:(D=[u[ue]],K=1);while((ue++<ne||D[0]!==void 0)&&et--);S=D[0]!==void 0}G[0]||G.shift()}if(M==1)$.e=h,io=S;else{for(w=1,P=G[0];P>=10;P/=10)w++;$.e=w+h*M-1,N($,l?r+$.e+1:r,a,S)}return $}})();function N(o,t,e,i){var n,r,a,l,d,f,h,w,P,M=o.constructor;t:if(t!=null){if(w=o.d,!w)return o;for(n=1,l=w[0];l>=10;l/=10)n++;if(r=t-n,r<0)r+=j,a=t,h=w[P=0],d=h/qt(10,n-a-1)%10|0;else if(P=Math.ceil((r+1)/j),l=w.length,P>=l)if(i){for(;l++<=P;)w.push(0);h=d=0,n=1,r%=j,a=r-j+1}else break t;else{for(h=l=w[P],n=1;l>=10;l/=10)n++;r%=j,a=r-j+n,d=a<0?0:h/qt(10,n-a-1)%10|0}if(i=i||t<0||w[P+1]!==void 0||(a<0?h:h%qt(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/qt(10,n-a):0:w[P-1])%10&1||e==(o.s<0?8:7)),t<1||!w[0])return w.length=0,f?(t-=o.e+1,w[0]=qt(10,(j-t%j)%j),o.e=-t||0):w[0]=o.e=0,o;if(r==0?(w.length=P,l=1,P--):(w.length=P+1,l=qt(10,j-r),w[P]=a>0?(h/qt(10,n-a)%qt(10,a)|0)*l:0),f)for(;;)if(P==0){for(r=1,a=w[0];a>=10;a/=10)r++;for(a=w[0]+=l,l=1;a>=10;a/=10)l++;r!=l&&(o.e++,w[0]==te&&(w[0]=1));break}else{if(w[P]+=l,w[P]!=te)break;w[P--]=0,l=1}for(r=w.length;w[--r]===0;)w.pop()}return L&&(o.e>M.maxE?(o.d=null,o.e=NaN):o.e<M.minE&&(o.e=0,o.d=[0])),o}function ae(o,t,e){if(!o.isFinite())return uo(o);var i,n=o.e,r=Lt(o.d),a=r.length;return t?(e&&(i=e-a)>0?r=r.charAt(0)+"."+r.slice(1)+he(i):a>1&&(r=r.charAt(0)+"."+r.slice(1)),r=r+(o.e<0?"e":"e+")+o.e):n<0?(r="0."+he(-n-1)+r,e&&(i=e-a)>0&&(r+=he(i))):n>=a?(r+=he(n+1-a),e&&(i=e-n-1)>0&&(r=r+"."+he(i))):((i=n+1)<a&&(r=r.slice(0,i)+"."+r.slice(i)),e&&(i=e-a)>0&&(n+1===a&&(r+="."),r+=he(i))),r}function ui(o,t){var e=o[0];for(t*=j;e>=10;e/=10)t++;return t}function ci(o,t,e){if(t>tr)throw L=!0,e&&(o.precision=e),Error(no);return N(new o(si),t,1,!0)}function se(o,t,e){if(t>Xi)throw Error(no);return N(new o(ai),t,e,!0)}function ao(o){var t=o.length-1,e=t*j+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 he(o){for(var t="";o--;)t+="0";return t}function co(o,t,e,i){var n,r=new o(1),a=Math.ceil(i/j+4);for(L=!1;;){if(e%2&&(r=r.times(t),to(r.d,a)&&(n=!0)),e=Ut(e/2),e===0){e=r.d.length-1,n&&r.d[e]===0&&++r.d[e];break}t=t.times(t),to(t.d,a)}return L=!0,r}function Yn(o){return o.d[o.d.length-1]&1}function lo(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 Yi(o,t){var e,i,n,r,a,l,d,f=0,h=0,w=0,P=o.constructor,M=P.rounding,S=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?(L=!1,d=S):d=t,l=new P(.03125);o.e>-2;)o=o.times(l),w+=5;for(i=Math.log(qt(2,w))/Math.LN10*2+5|0,d+=i,e=r=a=new P(1),P.precision=d;;){if(r=N(r.times(o),d,1),e=e.times(++h),l=a.plus(tt(r,e,d,1)),Lt(l.d).slice(0,d)===Lt(a.d).slice(0,d)){for(n=w;n--;)a=N(a.times(a),d,1);if(t==null)if(f<3&&je(a.d,d-i,M,f))P.precision=d+=10,e=r=l=new P(1),h=0,f++;else return N(a,P.precision=S,M,L=!0);else return P.precision=S,a}a=l}}function pe(o,t){var e,i,n,r,a,l,d,f,h,w,P,M=1,S=10,I=o,W=I.d,$=I.constructor,G=$.rounding,D=$.precision;if(I.s<0||!W||!W[0]||!I.e&&W[0]==1&&W.length==1)return new $(W&&!W[0]?-1/0:I.s!=1?NaN:W?0:I);if(t==null?(L=!1,h=D):h=t,$.precision=h+=S,e=Lt(W),i=e.charAt(0),Math.abs(r=I.e)<15e14){for(;i<7&&i!=1||i==1&&e.charAt(1)>3;)I=I.times(o),e=Lt(I.d),i=e.charAt(0),M++;r=I.e,i>1?(I=new $("0."+e),r++):I=new $(i+"."+e.slice(1))}else return f=ci($,h+2,D).times(r+""),I=pe(new $(i+"."+e.slice(1)),h-S).plus(f),$.precision=D,t==null?N(I,D,G,L=!0):I;for(w=I,d=a=I=tt(I.minus(1),I.plus(1),h,1),P=N(I.times(I),h,1),n=3;;){if(a=N(a.times(P),h,1),f=d.plus(tt(a,new $(n),h,1)),Lt(f.d).slice(0,h)===Lt(d.d).slice(0,h))if(d=d.times(2),r!==0&&(d=d.plus(ci($,h+2,D).times(r+""))),d=tt(d,new $(M),h,1),t==null)if(je(d.d,h-S,G,l))$.precision=h+=S,f=a=I=tt(w.minus(1),w.plus(1),h,1),P=N(I.times(I),h,1),n=l=1;else return N(d,$.precision=D,G,L=!0);else return $.precision=D,d;d=f,n+=2}}function uo(o){return String(o.s*o.s/0)}function ri(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)%j,e<0&&(i+=j),i<n){for(i&&o.d.push(+t.slice(0,i)),n-=j;i<n;)o.d.push(+t.slice(i,i+=j));t=t.slice(i),i=j-t.length}else i-=n;for(;i--;)t+="0";o.d.push(+t),L&&(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 ir(o,t){var e,i,n,r,a,l,d,f,h;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),so.test(t))return ri(o,t)}else if(t==="Infinity"||t==="NaN")return+t||(o.s=NaN),o.e=NaN,o.d=null,o;if(Jo.test(t))e=16,t=t.toLowerCase();else if(Qo.test(t))e=2;else if(Xo.test(t))e=8;else throw Error(me+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=co(i,new i(e),r,r*2)),f=oi(t,e,te),h=f.length-1,r=h;f[r]===0;--r)f.pop();return r<0?new i(o.s*0):(o.e=ui(f,h),o.d=f,L=!1,a&&(o=tt(o,n,l*4)),d&&(o=o.times(Math.abs(d)<54?qt(2,d):qe.pow(2,d))),L=!0,o)}function nr(o,t){var e,i=t.d.length;if(i<3)return t.isZero()?t:xe(o,2,t,t);e=1.4*Math.sqrt(i),e=e>16?16:e|0,t=t.times(1/di(5,e)),t=xe(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 xe(o,t,e,i,n){var r,a,l,d,f=1,h=o.precision,w=Math.ceil(h/j);for(L=!1,d=e.times(e),l=new o(i);;){if(a=tt(l.times(d),new o(t++*t++),h,1),l=n?i.plus(a):i.minus(a),i=tt(a.times(d),new o(t++*t++),h,1),a=l.plus(i),a.d[w]!==void 0){for(r=w;a.d[r]===l.d[r]&&r--;);if(r==-1)break}r=l,l=i,i=a,a=r,f++}return L=!0,a.d.length=w+1,a}function di(o,t){for(var e=o;--t;)e*=o;return e}function fo(o,t){var e,i=t.s<0,n=se(o,o.precision,1),r=n.times(.5);if(t=t.abs(),t.lte(r))return _e=i?4:1,t;if(e=t.divToInt(n),e.isZero())_e=i?3:2;else{if(t=t.minus(e.times(n)),t.lte(r))return _e=Yn(e)?i?2:3:i?4:1,t;_e=Yn(e)?i?1:4:i?3:2}return t.minus(n).abs()}function tn(o,t,e,i){var n,r,a,l,d,f,h,w,P,M=o.constructor,S=e!==void 0;if(S?(Zt(e,1,ge),i===void 0?i=M.rounding:Zt(i,0,8)):(e=M.precision,i=M.rounding),!o.isFinite())h=uo(o);else{for(h=ae(o),a=h.indexOf("."),S?(n=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):n=t,a>=0&&(h=h.replace(".",""),P=new M(1),P.e=h.length-a,P.d=oi(ae(P),10,n),P.e=P.d.length),w=oi(h,10,n),r=d=w.length;w[--d]==0;)w.pop();if(!w[0])h=S?"0p+0":"0";else{if(a<0?r--:(o=new M(o),o.d=w,o.e=r,o=tt(o,P,e,i,0,n),w=o.d,r=o.e,f=io),a=w[e],l=n/2,f=f||w[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&&w[e-1]&1||i===(o.s<0?8:7)),w.length=e,f)for(;++w[--e]>n-1;)w[e]=0,e||(++r,w.unshift(1));for(d=w.length;!w[d-1];--d);for(a=0,h="";a<d;a++)h+=Qi.charAt(w[a]);if(S){if(d>1)if(t==16||t==8){for(a=t==16?4:3,--d;d%a;d++)h+="0";for(w=oi(h,n,t),d=w.length;!w[d-1];--d);for(a=1,h="1.";a<d;a++)h+=Qi.charAt(w[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 to(o,t){if(o.length>t)return o.length=t,!0}function or(o){return new this(o).abs()}function rr(o){return new this(o).acos()}function sr(o){return new this(o).acosh()}function ar(o,t){return new this(o).plus(t)}function cr(o){return new this(o).asin()}function lr(o){return new this(o).asinh()}function ur(o){return new this(o).atan()}function dr(o){return new this(o).atanh()}function fr(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=se(this,r,1).times(t.s>0?.25:.75),e.s=o.s):!t.d||o.isZero()?(e=t.s<0?se(this,i,n):new this(0),e.s=o.s):!o.d||t.isZero()?(e=se(this,r,1).times(.5),e.s=o.s):t.s<0?(this.precision=r,this.rounding=1,e=this.atan(tt(o,t,r,1)),t=se(this,r,1),this.precision=i,this.rounding=n,e=o.s<0?e.minus(t):e.plus(t)):e=this.atan(tt(o,t,r,1)),e}function _r(o){return new this(o).cbrt()}function hr(o){return N(o=new this(o),o.e+1,2)}function pr(o,t,e){return new this(o).clamp(t,e)}function mr(o){if(!o||typeof o!="object")throw Error(li+"Object expected");var t,e,i,n=o.defaults===!0,r=["precision",1,ge,"rounding",0,8,"toExpNeg",-Se,0,"toExpPos",0,Se,"maxE",0,Se,"minE",-Se,0,"modulo",0,9];for(t=0;t<r.length;t+=3)if(e=r[t],n&&(this[e]=Ji[e]),(i=o[e])!==void 0)if(Ut(i)===i&&i>=r[t+1]&&i<=r[t+2])this[e]=i;else throw Error(me+e+": "+i);if(e="crypto",n&&(this[e]=Ji[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(oo);else this[e]=!1;else throw Error(me+e+": "+i);return this}function gr(o){return new this(o).cos()}function br(o){return new this(o).cosh()}function _o(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,eo(r)){f.s=r.s,L?!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++;L?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 ri(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),so.test(r)?ri(f,r):ir(f,r);if(d==="bigint")return r<0?(r=-r,f.s=-1):f.s=1,ri(f,r.toString());throw Error(me+r)}if(n.prototype=k,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=mr,n.clone=_o,n.isDecimal=eo,n.abs=or,n.acos=rr,n.acosh=sr,n.add=ar,n.asin=cr,n.asinh=lr,n.atan=ur,n.atanh=dr,n.atan2=fr,n.cbrt=_r,n.ceil=hr,n.clamp=pr,n.cos=gr,n.cosh=br,n.div=wr,n.exp=yr,n.floor=vr,n.hypot=Pr,n.ln=Cr,n.log=Mr,n.log10=Tr,n.log2=kr,n.max=Ar,n.min=Sr,n.mod=xr,n.mul=Ir,n.pow=Er,n.random=Or,n.round=Rr,n.sign=Fr,n.sin=Nr,n.sinh=Br,n.sqrt=jr,n.sub=qr,n.sum=Dr,n.tan=Lr,n.tanh=$r,n.trunc=Ur,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 wr(o,t){return new this(o).div(t)}function yr(o){return new this(o).exp()}function vr(o){return N(o=new this(o),o.e+1,3)}function Pr(){var o,t,e=new this(0);for(L=!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 L=!0,new this(1/0);e=t}return L=!0,e.sqrt()}function eo(o){return o instanceof qe||o&&o.toStringTag===ro||!1}function Cr(o){return new this(o).ln()}function Mr(o,t){return new this(o).log(t)}function kr(o){return new this(o).log(2)}function Tr(o){return new this(o).log(10)}function Ar(){return lo(this,arguments,-1)}function Sr(){return lo(this,arguments,1)}function xr(o,t){return new this(o).mod(t)}function Ir(o,t){return new this(o).mul(t)}function Er(o,t){return new this(o).pow(t)}function Or(o){var t,e,i,n,r=0,a=new this(1),l=[];if(o===void 0?o=this.precision:Zt(o,1,ge),i=Math.ceil(o/j),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(oo);else for(;r<i;)l[r++]=Math.random()*1e7|0;for(i=l[--r],o%=j,i&&o&&(n=qt(10,j-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-=j)l.shift();for(i=1,n=l[0];n>=10;n/=10)i++;i<j&&(e-=j-i)}return a.e=e,a.d=l,a}function Rr(o){return N(o=new this(o),o.e+1,this.rounding)}function Fr(o){return o=new this(o),o.d?o.d[0]?o.s:0*o.s:o.s||NaN}function Nr(o){return new this(o).sin()}function Br(o){return new this(o).sinh()}function jr(o){return new this(o).sqrt()}function qr(o,t){return new this(o).sub(t)}function Dr(){var o=0,t=arguments,e=new this(t[o]);for(L=!1;e.s&&++o<t.length;)e=e.plus(t[o]);return L=!0,N(e,this.precision,this.rounding)}function Lr(o){return new this(o).tan()}function $r(o){return new this(o).tanh()}function Ur(o){return N(o=new this(o),o.e+1,1)}k[Symbol.for("nodejs.util.inspect.custom")]=k.toString;k[Symbol.toStringTag]="Decimal";var qe=k.constructor=_o(Ji);si=new qe(si);ai=new qe(ai);var O=qe;function ye(o){let t=X.CoinAssist.isSuiCoin(o.coin_type_a),e=X.CoinAssist.isSuiCoin(o.coin_type_b);return{is_adjust_coin_a:t,is_adjust_coin_b:e}}function Vr(o,t){return O.ceil(O(o).div(1+t)).toString()}var Gt=class{static createCollectRewarderAndFeeParams(t,e,i,n,r,a){r===void 0&&(r=[...n]),a===void 0&&(a=[...n]);let l=(0,X.normalizeCoinType)(i.coin_type_a),d=(0,X.normalizeCoinType)(i.coin_type_b);if(i.collect_fee){let h=X.CoinAssist.buildCoinForAmount(e,r,BigInt(0),l,!1);r=h.remain_coins;let w=X.CoinAssist.buildCoinForAmount(e,a,BigInt(0),d,!1);a=w.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,w.target_coin)}let f=[];return i.rewarder_coin_types.forEach(h=>{switch((0,X.normalizeCoinType)(h)){case l:f.push(X.CoinAssist.buildCoinForAmount(e,r,BigInt(0),h,!1).target_coin);break;case d:f.push(X.CoinAssist.buildCoinForAmount(e,a,BigInt(0),h,!1).target_coin);break;default:f.push(X.CoinAssist.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=X.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,i).selected_coins,a=X.CoinAssist.calculateTotalBalance(e);if(r.length===0&&B("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${a}`),a-i>1e9)return{fixAmount:i};let l=await t.FullClient.calculationTxGas(fi.Transaction.from(n));if(X.CoinAssist.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&&B("InsufficientBalance","gas Insufficient balance");let h=new fi.Transaction;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}=ye(i),f=d?i.amount_a:i.amount_b,h=await this.adjustTransactionForGas(t,X.CoinAssist.getCoinAssets(d?i.coin_type_a:i.coin_type_b,e),BigInt(f),r),{fixAmount:w}=h,P=h.newTx;if(P!=null){let M,S;if(d)i.amount_a=Number(w),M=this.buildAddLiquidityFixTokenCoinInput(P,!i.fix_amount_a,w.toString(),i.slippage,i.coin_type_a,e,!1,!0),S=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(w),M=this.buildAddLiquidityFixTokenCoinInput(P,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,e,!1,!0),S=this.buildAddLiquidityFixTokenCoinInput(P,i.fix_amount_a,w.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,M,S)}return r}static async buildAddLiquidityFixToken(t,e,i,n,r,a){n=n||new fi.Transaction;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?X.CoinAssist.buildCoinForAmountInterval(t,a,{amount_second:BigInt(Vr(i,n)),amount_first:BigInt(i)},r,l,d):X.CoinAssist.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=X.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(Number(t.tick_lower),Number(t.tick_upper),new ho.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 w=(0,X.getPackagerConfigs)(f),P=n.is_open?[t.object(w.global_config_id),t.object(n.pool_id),t.pure.u32(Number((0,X.asUintN)(BigInt(n.tick_lower)).toString())),t.pure.u32(Number((0,X.asUintN)(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(X.CLOCK_ADDRESS)]:[t.object(w.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(X.CLOCK_ADDRESS)];return t.moveCall({target:`${h.published_at}::${Xt}::${d}`,typeArguments:l,arguments:P}),t}static checkCoinThreshold(t,e,i,n,r,a){e&&i.moveCall({target:`${t.sdkOptions.integrate.published_at}::${Be}::check_coin_threshold`,typeArguments:[a],arguments:[n,i.pure.u64(r)]})}};var ee=class o{static getDefaultSqrtPriceLimit(t){return new po.default(t?H.MIN_SQRT_PRICE:H.MAX_SQRT_PRICE)}static getDefaultOtherAmountThreshold(t){return t?H.ZERO:H.U64_MAX}static async buildSwapTransactionForGas(t,e,i,n){let r=this.buildSwapTransaction(t,e,i);r.setSender(t.getSenderAddress());let a=await this.adjustTransactionForGas(t,H.CoinAssist.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=H.CoinAssist.buildCoinForAmount(r,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a),h=H.CoinAssist.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}=(0,H.getPackagerConfigs)(a);h===void 0&&B("InvalidConfig","clmm.config.global_config_id is undefined");let w=e.swap_partner!==void 0,P=w?e.a2b?"swap_a2b_with_partner":"swap_b2a_with_partner":e.a2b?"swap_a2b":"swap_b2a",M=w?[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(H.CLOCK_ADDRESS)]:[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(H.CLOCK_ADDRESS)];return t.moveCall({target:`${l.published_at}::${Xt}::${P}`,typeArguments:f,arguments:M}),t}static async adjustTransactionForGas(t,e,i,n){n.setSender(t.getSenderAddress());let r=H.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,i).selected_coins,a=H.CoinAssist.calculateTotalBalance(e);if(r.length===0&&B("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${a}`),a-i>1e9)return{fixAmount:i};let l=await t.FullClient.calculationTxGas(n);if(H.CoinAssist.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&&B("InsufficientBalance","gas Insufficient balance");let h=new _i.Transaction;return{fixAmount:i,newTx:h}}}return{fixAmount:i}}static buildSwapTransaction(t,e,i){let n=new _i.Transaction;n.setSender(t.getSenderAddress());let r=H.CoinAssist.buildCoinForAmount(n,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1),a=H.CoinAssist.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=(0,H.adjustForSlippage)(a,i.slippage,!i.by_amount_in);e.amount_limit=l.toString()}catch(r){Wt("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,H.CoinAssist.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=H.CoinAssist.buildCoinForAmount(r,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1,!0),w=H.CoinAssist.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,w);r=P.tx,a=P.txRes}return{tx:r,coin_ab_s:a}}static buildSwapTransactionWithoutTransferCoins(t,e,i){let n=new _i.Transaction;n.setSender(t.getSenderAddress());let r=H.CoinAssist.buildCoinForAmount(n,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1,!0),a=H.CoinAssist.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}=(0,H.getPackagerConfigs)(l);h===void 0&&B("InvalidConfig","clmm.config.global_config_id is undefined");let w=i.swap_partner!==void 0,P=w?"swap_with_partner":"swap",M=w?zi:Be,S=w?[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(H.CLOCK_ADDRESS)]:[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(H.CLOCK_ADDRESS)],I=[i.coin_type_a,i.coin_type_b],W=e.moveCall({target:`${d.published_at}::${M}::${P}`,typeArguments:I,arguments:S});if(i.by_amount_in){let $=i.a2b?i.coin_type_b:i.coin_type_a,G=i.a2b?W[1]:W[0],D=Number(i.amount_limit);Gt.checkCoinThreshold(t,i.by_amount_in,e,G,D,$)}return{tx:e,txRes:W}}};function Kr(o,t,e){let i=t.mul(e).shln(64),n=t.shln(64).add(o.mul(e));return H.MathUtil.divRoundUp(i,n)}function Hr(o,t,e){let i=t.mul(e).shln(64),n=t.shln(64).sub(o.mul(e));return H.MathUtil.divRoundUp(i,n)}function Wr(o,t,e){return e.sub(H.MathUtil.divRoundUp(o.shln(64),t))}function Zr(o,t,e){return e.add(o.shln(64).div(t))}function zr(o){let t=new Vt.default(o);return t.lt(V.ZERO)?{bits:t.neg().xor(new Vt.default(2).pow(new Vt.default(64)).sub(new Vt.default(1))).add(new Vt.default(1)).toString()}:{bits:t.toString()}}function en(o){return{coin_type_a:o.coin_type_a,coin_type_b:o.coin_type_b,current_sqrt_price:new Vt.default(o.current_sqrt_price),current_tick_index:o.current_tick_index,fee_growth_global_a:new Vt.default(o.fee_growth_global_a),fee_growth_global_b:new Vt.default(o.fee_growth_global_b),fee_protocol_coin_a:new Vt.default(o.fee_protocol_coin_a),fee_protocol_coin_b:new Vt.default(o.fee_protocol_coin_b),fee_rate:new Vt.default(o.fee_rate),liquidity:new Vt.default(o.liquidity),tick_indexes:[],tick_spacing:Number(o.tick_spacing),ticks:[],collection_name:""}}function mo(o,t,e,i,n,r){if(e===V.ZERO)return{amount_in:V.ZERO,amount_out:V.ZERO,next_sqrt_price:t,fee_amount:V.ZERO};let a=o.gte(t),l,d,f,h;if(r){let w=V.MathUtil.checkMulDivFloor(i,V.MathUtil.checkUnsignedSub(V.FEE_RATE_DENOMINATOR,n),V.FEE_RATE_DENOMINATOR,64),P=(0,V.getDeltaUpFromInput)(o,t,e,a);P.gt(w)?(l=w,h=V.MathUtil.checkUnsignedSub(i,w),f=(0,V.getNextSqrtPriceFromInput)(o,e,w,a)):(l=P,h=V.MathUtil.checkMulDivCeil(l,n,V.FEE_RATE_DENOMINATOR.sub(n),64),f=t),d=(0,V.getDeltaDownFromOutput)(o,f,e,a)}else{let w=(0,V.getDeltaDownFromOutput)(o,t,e,a);w.gt(i)?(d=i,f=(0,V.getNextSqrtPriceFromOutput)(o,e,i,a)):(d=w,f=t),l=(0,V.getDeltaUpFromInput)(o,f,e,a),h=V.MathUtil.checkMulDivCeil(l,n,V.FEE_RATE_DENOMINATOR.sub(n),64)}return{amount_in:l,amount_out:d,next_sqrt_price:f,fee_amount:h}}function nn(o,t,e,i,n){let r=e,a=i.liquidity,{current_sqrt_price:l}=i,d={amount_in:V.ZERO,amount_out:V.ZERO,fee_amount:V.ZERO,ref_amount:V.ZERO,next_sqrt_price:V.ZERO,cross_tick_num:0},f,h,w=ee.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&&w.gt(P.sqrt_price)||!o&&w.lt(P.sqrt_price)?f=w:f=P.sqrt_price;let M=mo(l,f,a,r,i.fee_rate,t);if(M.amount_in.eq(V.ZERO)||(r=t?r.sub(M.amount_in.add(M.fee_amount)):r.sub(M.amount_out)),d.amount_in=d.amount_in.add(M.amount_in),d.amount_out=d.amount_out.add(M.amount_out),d.fee_amount=d.fee_amount.add(M.fee_amount),M.next_sqrt_price.eq(P.sqrt_price)?(h=P.liquidity_net.mul(new Vt.default(-1)),o?V.MathUtil.is_neg(h)?a=a.add(new Vt.default((0,V.asUintN)(BigInt(h.toString()),128))):a=a.add(h):V.MathUtil.is_neg(h)?a=a.sub(new Vt.default((0,V.asUintN)(BigInt(h.toString()),128))):a=a.sub(h),l=P.sqrt_price):l=M.next_sqrt_price,d.cross_tick_num+=1,r.eq(V.ZERO))break}return d.amount_in=d.amount_in.add(d.fee_amount),d.next_sqrt_price=l,d}var Jt=fe(re()),q=require("@cetusprotocol/common-sdk");function Gr(o,t,e){let i=(0,q.extractStructTagFromType)(o).name,n=(0,q.extractStructTagFromType)(t).name;return`${i}-${n}[${e}]`}function De(o){let t=(0,q.getMoveObjectType)(o),e=(0,q.extractStructTagFromType)(t),i=(0,q.getObjectFields)(o);i==null&&B("InvalidPoolObject",`Pool id ${(0,q.getObjectId)(o)} not exists.`,{[q.DETAILS_KEYS.METHOD_NAME]:"buildPool"});let n=[];i.rewarder_manager.fields.rewarders.forEach(d=>{let{emissions_per_second:f}=d.fields,h=q.MathUtil.fromX64(new Jt.default(f)),w=Math.floor(h.toNumber()*60*60*24);n.push({emissions_per_second:f,coin_type:(0,q.extractStructTagFromType)(d.fields.reward_coin.fields.name).source_address,growth_global:d.fields.growth_global,emissions_every_day:w})});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:(0,q.getObjectId)(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:(0,q.asIntN)(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=Gr(l.coin_type_a,l.coin_type_b,l.tick_spacing),l}function Le(o){(o.error!=null||o.data?.content?.dataType!=="moveObject")&&B("InvalidPositionObject",`Position not exists. Get Position error:${o.error}`,{[q.DETAILS_KEYS.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=(0,q.getObjectFields)(o);if(i){let a=(0,q.getMoveObjectType)(o),l=(0,q.getObjectOwner)(o);"nft"in i?(i=i.nft.fields,t.description=i.description,t.name=i.name,t.link=i.url):t=(0,q.buildNFT)(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:(0,q.asIntN)(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:(0,q.asIntN)(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=(0,q.getObjectDeletedResponse)(o);n&&(e.pos_object_id=n.objectId,e.position_status="Deleted");let r=(0,q.getObjectNotExistsResponse)(o);return r&&(e.pos_object_id=r,e.position_status="NotExists"),e}function Ie(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:(0,q.asIntN)(BigInt(e)),tick_upper_index:(0,q.asIntN)(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 $e(o){(o.error!=null||o.data?.content?.dataType!=="moveObject")&&B("InvalidTickObject",`Tick not exists. Get tick data error:${o.error}`,{[q.DETAILS_KEYS.METHOD_NAME]:"buildTickData"});let e=(0,q.getObjectFields)(o).value.fields.value.fields;return{object_id:(0,q.getObjectId)(o),index:(0,q.asIntN)(BigInt(e.index.fields.bits)),sqrt_price:new Jt.default(e.sqrt_price),liquidity_net:new Jt.default(e.liquidity_net.fields.bits),liquidity_gross:new Jt.default(e.liquidity_gross),fee_growth_outside_a:new Jt.default(e.fee_growth_outside_a),fee_growth_outside_b:new Jt.default(e.fee_growth_outside_b),rewarders_growth_outside:e.rewards_growth_outside}}function on(o){(!o||!o.index||!o.sqrt_price||!o.liquidity_net||!o.liquidity_gross||!o.fee_growth_outside_a||!o.fee_growth_outside_b)&&B("InvalidTickFields","Invalid tick fields.",{[q.DETAILS_KEYS.METHOD_NAME]:"buildTickDataByEvent"});let t=(0,q.asIntN)(BigInt(o.index.bits)),e=new Jt.default(o.sqrt_price),i=new Jt.default(o.liquidity_net.bits),n=new Jt.default(o.liquidity_gross),r=new Jt.default(o.fee_growth_outside_a),a=new Jt.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 Qr(o,t){return`Cetus LP | Pool${o}-${t}`}function rn(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=(0,q.extractStructTagFromType)(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)&&((0,q.d)(h.parsed_json.amount_a).gt(0)||(0,q.d)(h.parsed_json.amount_b).gt(0))&&i.push(h);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":case"AddLiquidityV2Event":case"RemoveLiquidityV2Event":((0,q.d)(h.parsed_json.amount_a).gt(0)||(0,q.d)(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))&&(0,q.d)(h.parsed_json.amount).gt(0)&&i.push(h);break;default:break}}}),i}function sn(o,t,e,i){let n=[],{timestampMs:r,events:a}=o;return a?.forEach((l,d)=>{let{name:f,address:h}=(0,q.extractStructTagFromType)(l.type);if(Wi.includes(f)&&e.includes(h)&&i===l.parsedJson.pool){let w={tx:l.id.txDigest,sender:l.sender,type:l.type,block_time:r||"0",index:`${t}_${d}`,parsed_json:l.parsedJson};n.push(w)}}),n}function Ue(o,t,e,i){t.moveCall({target:`${o.sdkOptions.integrate.published_at}::${Gi}::transfer_coin_to_sender`,typeArguments:[i],arguments:[e]})}function an(o,t,e,i,n){n!=null?t.transferObjects([e],t.pure.address(n)):Ue(o,t,e,i)}var T=require("@cetusprotocol/common-sdk");var $t=require("@cetusprotocol/common-sdk"),go=1e4,ie=class{static parseClmmVestInfo(t){let e=(0,$t.getObjectFields)(t),i=(0,$t.getObjectType)(t),n=(0,$t.extractStructTagFromType)(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:(0,$t.d)(l.fields.percentage).div(go).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:(0,$t.fixCoinType)(t.coin_a.name,!1),coin_type_b:(0,$t.fixCoinType)(t.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(t){let e=(0,$t.getObjectFields)(t);return{current_sqrt_price:e.current_sqrt_price,remove_percent:(0,$t.d)(e.remove_percent).div(1e6).toString(),snapshots:{id:e.snapshots.fields.id.id,size:e.snapshots.fields.size}}}static parsePositionSnapshot(t){let e=(0,$t.getObjectFields)(t),i=e.value.fields.value.fields;return{position_id:e.name,liquidity:i.liquidity,tick_lower_index:(0,$t.asIntN)(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:(0,$t.asIntN)(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}}};var wo=require("@cetusprotocol/common-sdk"),bo={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"}},cn={env:"mainnet",full_rpc_url:wo.FullRpcUrlMainnet,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:bo.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xdb5cd62a06c79695bfc9982eb08534706d3752fe123b48e0144f480209b3117f",version:13,config:bo.clmmConfig},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x6219e52e9a9d2cce4d0e53f27a9152a827f3572678e5bdec85f528e3e175e479",version:14},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"}}},ln=["0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb","0xdb5cd62a06c79695bfc9982eb08534706d3752fe123b48e0144f480209b3117f"];var yo=require("@cetusprotocol/common-sdk");var un={env:"testnet",full_rpc_url:yo.FullRpcUrlTestnet,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:"0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8",config:{pools_id:"0x20a086e6fa0741b3ca77d033a65faf0871349b986ddbdde6fa1d85d78a5f4222",global_config_id:"0xc6273f844b4bc258952c4e477697aa12c918c8e08106fac6b934811298c9820a",global_vault_id:"0x71e74a999dd7959e483f758ddf573e85fa4c24944db33ff6763c9d85a9c045fe",admin_cap_id:"0xbf4c48590f403c38351de0e8aa13d6d91bf78fd8c04e93ac1d0269c44d70ae02",partners_id:"0xb5ae5ed3f403654ae1307aadc0140f746db41efb7bda92235257c84d90a1397e"}},integrate:{package_id:"0x36187418dd79415d50e2e5903f9b3caca582052005f062959c86da64e82107a9",published_at:"0x36187418dd79415d50e2e5903f9b3caca582052005f062959c86da64e82107a9",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"}}},dn=["0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8","0x5372d555ac734e272659136c2a0cd3227f9b92de67c80dc11250307268af2db8"];var Ve=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&&B("InvalidConfig",`when getPositionList get position objects error: ${l.error}, please check the rpc, contracts address config and position id.`,{[T.DETAILS_KEYS.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 w=h.parsedJson;w&&n.push({id:w.pool_id,tick_spacing:w.tick_spacing,coin_type_a:(0,T.extractStructTagFromType)(w.coin_type_a).full_address,coin_type_b:(0,T.extractStructTagFromType)(w.coin_type_b).full_address})})}catch(d){return Wt("FetchError",d,{[T.DETAILS_KEYS.METHOD_NAME]:"getPoolImmutables"})}return r.data=n,a&&this._sdk.updateCache(`${i}_getPoolImmutables`,n,T.CACHE_TIME_24H),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")&&B("InvalidPoolObject",`getPoolWithPages error code: ${a.error?.code??"unknown error"}, please check config and object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getPoolsWithPage"});let l=De(a);i.data.push(l);let d=`${l.id}_getPoolObject`;this._sdk.updateCache(d,l,T.CACHE_TIME_24H)}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:Ki}}),n=ie.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=ie.parsePositionSnapshot(f);d.push(h)}),n.position_snapshots=d}}return n}catch(i){return Wt("InvalidPoolObject",i,{[T.DETAILS_KEYS.METHOD_NAME]:"getPoolLiquiditySnapshot",[T.DETAILS_KEYS.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=ie.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")&&B("InvalidPoolObject",`getPools error code: ${n.error?.code??"unknown error"}, please check config and object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getAssignPools"});let r=De(n);e.push(r);let a=`${r.id}_getPoolObject`;this._sdk.updateCache(a,r,T.CACHE_TIME_24H)}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")&&B("InvalidPoolObject",`getPool error code: ${a.error?.code??"unknown error"}, please check config and object id`,{[T.DETAILS_KEYS.METHOD_NAME]:"getPool"});let l=De(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||B("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[T.DETAILS_KEYS.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){Wt("FetchError",d,{[T.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins",[T.DETAILS_KEYS.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((0,T.isSortedSymbols)((0,ve.normalizeSuiAddress)(t.coin_type_a),(0,ve.normalizeSuiAddress)(t.coin_type_b))){let i=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=i;let n=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=n}return await this.createPoolAndAddLiquidity(t,e)}async createPoolRowPayload(t,e){if((0,T.isSortedSymbols)((0,ve.normalizeSuiAddress)(t.coin_type_a),(0,ve.normalizeSuiAddress)(t.coin_type_b))){let i=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=i;let n=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=n}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=(0,T.getObjectPreviousTransactionDigest)(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((0,T.extractStructTagFromType)(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,T.CACHE_TIME_24H)),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=(0,T.createFullClient)(new vo.SuiClient({url:n})):l=r;let d={data:[],has_next_page:!1},f=50,h=e,w=e.limit||10,P=a.env==="testnet"?dn:ln;do{let M=await l.queryTransactionBlocksByPage({ChangedObject:t},{...h,limit:50},i);M.data.forEach((S,I)=>{d.next_cursor=M.next_cursor;let W=sn(S,I,P,t);d.data=[...d.data,...W]}),d.has_next_page=M.has_next_page,d.next_cursor=M.next_cursor,h.cursor=M.next_cursor}while(d.data.length<w&&d.has_next_page);return d.data.length>w&&(d.data=d.data.slice(0,w),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=T.TickMath.priceToSqrtPriceX64(a==="coin_a"?(0,T.d)(e):(0,T.d)(1).div(e),l,d),h=0,w=0;if(r.is_full_range)h=T.TickUtil.getMinIndex(n),w=T.TickUtil.getMaxIndex(n);else{let{min_price:D,max_price:K}=r;h=T.TickMath.priceToInitializeTickIndex(a==="coin_a"?(0,T.d)(D):(0,T.d)(1).div(K),l,d,n),w=T.TickMath.priceToInitializeTickIndex(a==="coin_a"?(0,T.d)(K):(0,T.d)(1).div(D),l,d,n)}let{coin_amount:P,fix_amount_a:M}=t,{coin_amount_limit_a:S,coin_amount_limit_b:I,liquidity_amount:W,coin_amount_a:$,coin_amount_b:G}=T.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(h,w,new Po.default(P),M,!0,i,f);return{coin_amount_a:$,coin_amount_b:G,coin_amount_limit_a:S,coin_amount_limit_b:I,liquidity:W,initialize_sqrt_price:f.toString(),tick_lower:h,tick_upper:w,fix_amount_a:M}}async createPoolAndAddLiquidity(t,e){e=e||new Ee.Transaction,e.setSender(this.sdk.getSenderAddress());let{integrate:i,clmm_pool:n}=this.sdk.sdkOptions,r=(0,T.getPackagerConfigs)(n),a=r.global_config_id,l=r.pools_id,d=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),f=T.CoinAssist.buildCoinForAmount(e,d,BigInt(t.amount_a),t.coin_type_a,!1,!0),h=T.CoinAssist.buildCoinForAmount(e,d,BigInt(t.amount_b),t.coin_type_b,!1,!0),w=[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((0,T.asUintN)(BigInt(t.tick_lower)).toString())),e.pure.u32(Number((0,T.asUintN)(BigInt(t.tick_upper)).toString())),f.target_coin,h.target_coin,e.object(t.metadata_a),e.object(t.metadata_b),e.pure.bool(t.fix_amount_a),e.object(T.CLOCK_ADDRESS)];return e.moveCall({target:`${i.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:w}),Ue(this._sdk,e,f.target_coin,t.coin_type_a),Ue(this._sdk,e,h.target_coin,t.coin_type_b),e}async createPoolAndAddLiquidityRow(t,e){e=e||new Ee.Transaction;let{clmm_pool:i}=this.sdk.sdkOptions,n=(0,T.getPackagerConfigs)(i),r=n.global_config_id,a=n.pools_id,l=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),d=T.CoinAssist.buildCoinForAmount(e,l,BigInt(t.amount_a),t.coin_type_a,!1,!0),f=T.CoinAssist.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((0,T.asUintN)(BigInt(t.tick_lower)).toString())),e.pure.u32(Number((0,T.asUintN)(BigInt(t.tick_upper)).toString())),d.target_coin,f.target_coin,e.object(t.metadata_a),e.object(t.metadata_b),e.pure.bool(t.fix_amount_a),e.object(T.CLOCK_ADDRESS)],w=e.moveCall({target:`${i.published_at}::pool_creator::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:h});return{tx:e,pos_id:w[0],remain_coin_a:w[1],remain_coin_b:w[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:w,coin_amount_a:P,coin_amount_b:M,fix_amount_a:S,coin_amount_limit_a:I,coin_amount_limit_b:W}=l,$=await this._sdk.FullClient.fetchCoinMetadata(i),G=await this._sdk.FullClient.fetchCoinMetadata(n);if($===null)return B("FetchError",`fetch coin ${i} metadata failed`,{[T.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});if(G===null)return B("FetchError",`fetch coin ${n} metadata failed`,{[T.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});let D=$.id,K=G.id;return this.createPoolRowPayload({tick_spacing:r,initialize_sqrt_price:d,uri:a||"",coin_type_a:i,coin_type_b:n,amount_a:S?P:I,amount_b:S?W:M,fix_amount_a:S,tick_lower:f,tick_upper:h,metadata_a:D,metadata_b:K},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:w,coin_amount_b:P,fix_amount_a:M,coin_amount_limit_a:S,coin_amount_limit_b:I}=a,W=await this._sdk.FullClient.fetchCoinMetadata(e),$=await this._sdk.FullClient.fetchCoinMetadata(i);if(W===null)return B("FetchError",`fetch coin ${e} metadata failed`,{[T.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});if($===null)return B("FetchError",`fetch coin ${i} metadata failed`,{[T.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});let G=W.id,D=$.id;return this.createPoolPayload({tick_spacing:n,initialize_sqrt_price:l,uri:r||"",coin_type_a:e,coin_type_b:i,amount_a:M?w:S,amount_b:M?I:P,fix_amount_a:M,tick_lower:d,tick_upper:f,metadata_a:G,metadata_b:D})}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((0,T.asUintN)(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 Ee.Transaction,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}::${Yt}::fetch_ticks`,arguments:l,typeArguments:n});let d=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:(0,ve.normalizeSuiAddress)("0x0")});return d.error!=null&&B("InvalidTickObjectId",`getTicks error code: ${d.error??"unknown error"}, please check config and tick object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getTicks",[T.DETAILS_KEYS.REQUEST_PARAMS]:t}),d.events?.forEach(f=>{(0,T.extractStructTagFromType)(f.type).name==="FetchTicksResultEvent"&&f.parsedJson.ticks.forEach(h=>{i.push(on(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 Ee.Transaction,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}::${Yt}::fetch_positions`,arguments:f,typeArguments:a});let h=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:l,sender:(0,ve.normalizeSuiAddress)("0x0")});h.error!=null&&B("InvalidPositionRewardObject",`fetch position info error code: ${h.error??"unknown error"}, please check config and tick object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"fetchPoolPositionInfoList",[T.DETAILS_KEYS.REQUEST_PARAMS]:t});let w=[];if(h?.events?.forEach(P=>{(0,T.extractStructTagFromType)(P.type).name==="FetchPositionsEvent"&&P.parsedJson.positions.forEach(M=>{let S=Ie(M);w.push(S)})}),i.push(...w),w.length<r)break;n=[w[w.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=>{(0,T.extractStructTagFromType)(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")&&B("InvalidTickObjectId",`getTicksByRpc error code: ${n.error?.code??"unknown error"}, please check config and tick object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getTicksByRpc"});let r=$e(n);r!=null&&e.push(r)}return e}async getTickDataByIndex(t,e){let i={type:"u64",value:(0,T.asUintN)(BigInt((0,T.tickScore)(e).toString())).toString()},n=await this.sdk.FullClient.getDynamicFieldObject({parentId:t,name:i});return(n.error!=null||n.data?.content?.dataType!=="moveObject")&&B("InvalidTickIndex",`get tick by index: ${e} error: ${n.error}`,{[T.DETAILS_KEYS.METHOD_NAME]:"getTickDataByIndex"}),$e(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")&&B("InvalidTickObjectId",`getTicksByRpc error code: ${e.error?.code??"unknown error"}, please check config and tick object ids`,{[T.DETAILS_KEYS.METHOD_NAME]:"getTickDataByObjectId"}),$e(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"&&B("NotFoundPartnerObject",`get partner by object id: ${t} error: ${i[0].error}`,{[T.DETAILS_KEYS.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")&&B("InvalidPartnerRefFeeFields",`get coin by object id: ${f.data.objectId} error: ${f.error}`,{[T.DETAILS_KEYS.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 Ee.Transaction,{clmm_pool:r}=this.sdk.sdkOptions,{global_config_id:a}=(0,T.getPackagerConfigs)(r),l=[i],d=[n.object(a),n.object(t),n.object(e)];return n.moveCall({target:`${r.published_at}::${Zi}::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=(0,T.getObjectFields)(e).position.fields.status;if(n)return n}catch(e){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",e)}}};var Co=require("@mysten/sui/client"),ce=require("@mysten/sui/transactions"),hi=require("@mysten/sui/utils"),Ke=fe(re()),A=require("@cetusprotocol/common-sdk");var He=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=(0,A.createFullClient)(new Co.SuiClient({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((w,P)=>{let M=rn(w,P,l);f.data=[...f.data,...M]}),f.has_next_page=h.has_next_page,f.next_cursor=h.next_cursor,f}catch(h){Wt("FetchError",h,{[A.DETAILS_KEYS.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((0,A.extractStructTagFromType)(l.data.type).full_address===this.buildPositionType()){let f=Le(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=Le(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=Le(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=(0,A.getObjectFields)(i.data).value.fields.value;return Ie(r)}catch(i){return Wt("FetchError",i,{[A.DETAILS_KEYS.METHOD_NAME]:"getPositionInfo",[A.DETAILS_KEYS.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=(0,A.deriveDynamicFieldIdByType)(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=(0,A.getObjectFields)(r.data).value.fields.value,d=Ie(l);e.push(d)}catch(a){console.log("getPositionInfoList error",a)}}),e)}catch(e){return Wt("FetchError",e,{[A.DETAILS_KEYS.METHOD_NAME]:"getPositionInfoList",[A.DETAILS_KEYS.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((0,A.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id)];e.moveCall({target:`${n.published_at}::${Yt}::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.Transaction;for(let d of t)this.buildFetchPosFee(d,n);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,hi.normalizeSuiAddress)("0x0")});r.error!=null&&B("InvalidPoolObject",`fetch position fee error code: ${r.error??"unknown error"}, please check config and position and pool object ids`,{[A.DETAILS_KEYS.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}=ye(t);if(t=t,t.fix_amount_a&&l||!t.fix_amount_a&&d)return i=await Gt.buildAddLiquidityFixTokenForGas(this._sdk,a,t,e,i,n,r),i}return Gt.buildAddLiquidityFixToken(this._sdk,a,t,i,n,r)}async createAddLiquidityPayload(t,e,i,n){let{integrate:r,clmm_pool:a}=this._sdk.sdkOptions,l=(0,A.asUintN)(BigInt(t.tick_lower)).toString(),d=(0,A.asUintN)(BigInt(t.tick_upper)).toString(),f=[t.coin_type_a,t.coin_type_b];e=e||new ce.Transaction;let h=!(0,hi.isValidSuiObjectId)(t.pos_id),w=BigInt(t.max_amount_a),P=BigInt(t.max_amount_b),M,S;if(i==null||n==null){let I=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());M=A.CoinAssist.buildCoinForAmount(e,I,w,t.coin_type_a,!1,!0),S=A.CoinAssist.buildCoinForAmount(e,I,P,t.coin_type_b,!1,!0)}else M={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},S={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]};if(h)e.moveCall({target:`${r.published_at}::${Xt}::open_position_with_liquidity`,typeArguments:f,arguments:[e.object((0,A.getPackagerConfigs)(a).global_config_id),e.object(t.pool_id),e.pure.u32(Number(l)),e.pure.u32(Number(d)),M.target_coin,S.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(A.CLOCK_ADDRESS)]});else{let I=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());e=Gt.createCollectRewarderAndFeeParams(this._sdk,e,t,I,M.remain_coins,S.remain_coins),e.moveCall({target:`${r.published_at}::${Xt}::add_liquidity`,typeArguments:f,arguments:[e.object((0,A.getPackagerConfigs)(a).global_config_id),e.object(t.pool_id),e.object(t.pos_id),M.target_coin,S.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(A.CLOCK_ADDRESS)]})}return e}async removeLiquidityPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions,r="remove_liquidity";e=e||new ce.Transaction;let a=[t.coin_type_a,t.coin_type_b],l=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());e=Gt.createCollectRewarderAndFeeParams(this._sdk,e,t,l);let d=[e.object((0,A.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.u128(t.delta_liquidity),e.pure.u64(t.min_amount_a),e.pure.u64(t.min_amount_b),e.object(A.CLOCK_ADDRESS)];return e.moveCall({target:`${n.published_at}::${Ae}::${r}`,typeArguments:a,arguments:d}),e}async closePositionPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new ce.Transaction;let r=[t.coin_type_a,t.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return e=Gt.createCollectRewarderAndFeeParams(this._sdk,e,t,a),e.moveCall({target:`${n.published_at}::${Ae}::close_position`,typeArguments:r,arguments:[e.object((0,A.getPackagerConfigs)(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(A.CLOCK_ADDRESS)]}),e}openPositionPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new ce.Transaction;let r=[t.coin_type_a,t.coin_type_b],a=(0,A.asUintN)(BigInt(t.tick_lower)).toString(),l=(0,A.asUintN)(BigInt(t.tick_upper)).toString(),d=[e.object((0,A.getPackagerConfigs)(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}::${Ae}::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.Transaction;let a=await this.sdk.Pool.getPool(i,!1),l=Number(a.tick_spacing),d=0,f=0;if(t.is_full_range)d=A.TickUtil.getMinIndex(l),f=A.TickUtil.getMaxIndex(l);else{let{price_base_coin:P,min_price:M,max_price:S}=t;d=A.TickMath.priceToInitializeTickIndex(P==="coin_a"?(0,A.d)(M):(0,A.d)(1).div(S),t.coin_decimals_a,t.coin_decimals_b,l),f=A.TickMath.priceToInitializeTickIndex(P==="coin_a"?(0,A.d)(S):(0,A.d)(1).div(M),t.coin_decimals_a,t.coin_decimals_b,l)}let h=[a.coin_type_a,a.coin_type_b],w=[e.object((0,A.getPackagerConfigs)(n).global_config_id),e.object(t.pool_id),e.pure.u32(Number((0,A.asUintN)(BigInt(d)))),e.pure.u32(Number((0,A.asUintN)(BigInt(f))))];return e.moveCall({target:`${r.published_at}::${Ae}::open_position`,typeArguments:h,arguments:w}),e}async collectFeePayload(t,e,i,n){e=e||new ce.Transaction;let r=i||A.CoinAssist.buildCoinWithBalance(BigInt(0),t.coin_type_a,e),a=n||A.CoinAssist.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((0,A.getPackagerConfigs)(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),i,n];return e.moveCall({target:`${a.published_at}::${Xt}::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=A.TickUtil.getMinIndex(l),f=A.TickUtil.getMaxIndex(l);else{let{price_base_coin:$,min_price:G,max_price:D}=r;d=A.TickMath.priceToInitializeTickIndex($==="coin_a"?(0,A.d)(G):(0,A.d)(1).div(D),r.coin_decimals_a,r.coin_decimals_b,l),f=A.TickMath.priceToInitializeTickIndex($==="coin_a"?(0,A.d)(D):(0,A.d)(1).div(G),r.coin_decimals_a,r.coin_decimals_b,l)}if("liquidity"in t){let{liquidity:$}=t,G=A.TickMath.tickIndexToSqrtPriceX64(d),D=A.TickMath.tickIndexToSqrtPriceX64(f),{coin_amount_a:K,coin_amount_b:zt}=A.ClmmPoolUtil.getCoinAmountFromLiquidity(new Ke.default($),new Ke.default(a.current_sqrt_price),G,D,!1),et=(0,A.d)(K).mul(1+i).toFixed(0,O.ROUND_UP),Qt=(0,A.d)(zt).mul(1+i).toFixed(0,O.ROUND_UP);return{coin_amount_a:K,coin_amount_b:zt,coin_amount_limit_a:et,coin_amount_limit_b:Qt,liquidity:$,tick_lower:d,tick_upper:f}}let{coin_amount:h,fix_amount_a:w}=t,{coin_amount_limit_a:P,coin_amount_limit_b:M,liquidity_amount:S,coin_amount_a:I,coin_amount_b:W}=A.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(d,f,new Ke.default(h),w,!0,i,new Ke.default(a.current_sqrt_price));return{coin_amount_a:I,coin_amount_b:W,coin_amount_limit_a:P,coin_amount_limit_b:M,liquidity:S,tick_lower:d,tick_upper:f,fix_amount_a:w}}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:w}=a;e=e||new ce.Transaction;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:w,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:w,fix_amount_a:P,coin_amount_a:M,coin_amount_b:S}=a;if(P===void 0)throw B("InvalidParams","fix_amount_a is undefined",{[A.DETAILS_KEYS.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[A.DETAILS_KEYS.REQUEST_PARAMS]:t});e=e||new ce.Transaction;let I=await this.sdk.Pool.getPool(r,!1);return await this.createAddLiquidityFixTokenPayload({amount_a:P?M:l,amount_b:P?d:S,slippage:0,fix_amount_a:P,is_open:!0,tick_lower:h,tick_upper:w,collect_fee:!1,rewarder_coin_types:[],coin_type_a:I.coin_type_a,coin_type_b:I.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((0,A.getPackagerConfigs)(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),i,n];return e.moveCall({target:`${a.published_at}::${Ne}::collect_fee`,typeArguments:l,arguments:d}),e}};var pi=require("@mysten/sui/transactions"),Mo=require("@mysten/sui/utils"),fn=fe(re()),Y=require("@cetusprotocol/common-sdk");var We=class{constructor(t){this._sdk=t,this.growthGlobal=[Y.ZERO,Y.ZERO,Y.ZERO]}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=Y.MathUtil.fromX64(new fn.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((0,Y.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id),e.object(Y.CLOCK_ADDRESS)];e.moveCall({target:`${n.published_at}::${Yt}::fetch_position_rewards`,arguments:a,typeArguments:r})}async fetchPosRewardersAmount(t){let e=new pi.Transaction;for(let a of t)this.buildFetchPosReward(a,e);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:e,sender:(0,Mo.normalizeSuiAddress)("0x")});i.error!=null&&B("InvalidConfig",`fetch position rewards error code: ${i.error??"unknown error"}, please check config and params`,{[Y.DETAILS_KEYS.METHOD_NAME]:"fetchPosRewardersAmount",[Y.DETAILS_KEYS.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=[Y.ZERO,Y.ZERO,Y.ZERO];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 fn.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 pi.Transaction;return i=Gt.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 pi.Transaction;let a={};return t.forEach(l=>{let d=(0,Y.normalizeCoinType)(l.coin_type_a),f=(0,Y.normalizeCoinType)(l.coin_type_b);if(l.collect_fee){let w=a[d];w==null&&(i==null?w=Y.CoinAssist.buildCoinForAmount(e,r,BigInt(0),d,!1):w={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},a[d]=w);let P=a[f];P==null&&(n==null?P=Y.CoinAssist.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,w.target_coin,P.target_coin)}let h=[];l.rewarder_coin_types.forEach(w=>{let P=(0,Y.normalizeCoinType)(w),M=a[w];M===void 0&&(M=Y.CoinAssist.buildCoinForAmount(e,r,BigInt(0),P,!1),a[P]=M),h.push(M.target_coin)}),e=this.createCollectRewarderNoSendPayload(l,e,h)}),Object.keys(a).forEach(l=>{let d=a[l];d.is_mint_zero_coin&&an(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=(0,Y.getPackagerConfigs)(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}::${Xt}::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(Y.CLOCK_ADDRESS)]})}),e}createCollectRewarderNoSendPayload(t,e,i){let{clmm_pool:n,integrate:r}=this.sdk.sdkOptions,a=(0,Y.getPackagerConfigs)(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}::${Ne}::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(Y.CLOCK_ADDRESS)]})}),e}};var _n=require("@mysten/sui/transactions"),hn=require("@mysten/sui/utils"),Pe=fe(re()),nt=require("@cetusprotocol/common-sdk");var Jr="amm_swap",Xr="Pool",Ze=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=(0,nt.d)(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 O(r.fee_rate).div(10**6):new O(r.fee_rate).div(10**9),l=(0,nt.d)(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 O(1).div(r.current_price),h=d.direction?d.current_price:new O(1).div(d.current_price),w=d.label==="Cetus"?new O(d.fee_rate).div(10**6):new O(d.fee_rate).div(10**9),M=(0,nt.d)(d.output_amount).div(10**d.to_decimal).mul(w).div(f.mul(h));e=e.add(M)}}}),e.toString()}calculateSwapPriceImpact(t){let e=(0,nt.d)(0);return t.forEach(i=>{let n=i.base_paths.length;if(n===1){let r=i.base_paths[0],a=(0,nt.d)(r.output_amount).div(10**r.to_decimal),l=(0,nt.d)(r.input_amount).div(10**r.from_decimal),d=a.div(l),f=r.direction?new O(r.current_price):new O(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 O(r.current_price):new O(1).div(r.current_price),d=a.direction?new O(a.current_price):new O(1).div(a.current_price),f=l.mul(d),h=new O(a.output_amount).div(10**a.to_decimal),w=new O(r.input_amount).div(10**r.from_decimal),P=h.div(w);e=e.add(this.calculateSingleImpact(P,f))}}),e.toString()}async preSwapWithMultiPool(t){let{integrate:e}=this.sdk.sdkOptions,i=new _n.Transaction,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}::${Yt}::calculate_swap_result`,arguments:h,typeArguments:n})}let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,hn.normalizeSuiAddress)("0x0")});r.error!=null&&B("InvalidConfig",`pre swap with multi pools error code: ${r.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let a=r.events?.filter(f=>(0,nt.extractStructTagFromType)(f.type).name==="CalculatedSwapResultEvent");if(a.length===0)return null;a.length!==t.pool_ids.length&&B("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let l=t.by_amount_in?nt.ZERO:nt.U64_MAX,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 Pe.default(a[f].parsedJson.data.amount_out);h.gt(l)&&(d=f,l=h)}else{let h=new Pe.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 _n.Transaction,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}::${Yt}::calculate_swap_result`,arguments:r,typeArguments:n});let a=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,hn.normalizeSuiAddress)("0x0")});if(a.error!=null)return B("InvalidConfig",`preSwap error code: ${a.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let l=a.events?.filter(d=>(0,nt.extractStructTagFromType)(d.type).name==="CalculatedSwapResultEvent");return l.length===0?B("InvalidConfig",`preSwap error code: ${a.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}}):this.transformSwapData(t,l[0].parsedJson.data)}transformSwapData(t,e){let i=e.amount_in&&e.fee_amount?new Pe.default(e.amount_in).add(new Pe.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 Pe.default(i.amount_in).add(new Pe.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=en(e),n;t.a2b?n=t.swap_ticks.sort((P,M)=>M.index-P.index):n=t.swap_ticks.sort((P,M)=>P.index-M.index);let r=nn(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=ee.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=nt.TickMath.sqrtPriceX64ToPrice(i.current_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),h=nt.TickMath.sqrtPriceX64ToPrice(r.next_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),w=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:w}}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}=ye(t);if(t.a2b&&n||!t.a2b&&r)return await ee.buildSwapTransactionForGas(this._sdk,t,i,e)}return ee.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}=ye(t);if(t.a2b&&n||!t.a2b&&r)return await ee.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,t,i,e)}return ee.buildSwapTransactionWithoutTransferCoins(this.sdk,t,i)}};var Kt=require("@cetusprotocol/common-sdk");var pn=require("@mysten/sui/transactions"),ko=require("@mysten/sui/utils"),ze=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 B("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[Kt.DETAILS_KEYS.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=ie.parseClmmVestInfo(l),f=`${d.id}-ClmmVestInfo`;this._sdk.updateCache(f,d),e.push(d)}),e}catch(i){Wt("ClmmVestFetchError",i,{[Kt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(t=!0){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return B("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[Kt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:i}=(0,Kt.getPackagerConfigs)(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=ie.parseClmmVestInfo(a);return this._sdk.updateCache(n,l),l}catch(a){return Wt("ClmmVestFetchError",a,{[Kt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo",[Kt.DETAILS_KEYS.REQUEST_PARAMS]:{clmm_vest_id:i}})}}async getPositionVesting(t){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return B("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[Kt.DETAILS_KEYS.METHOD_NAME]:"getPositionVesting"});if(t.length===0)return[];let{clmm_vest_id:i}=(0,Kt.getPackagerConfigs)(e),n=new pn.Transaction;t.forEach(l=>{let{clmm_pool_id:d,coin_type_a:f,coin_type_b:h,clmm_position_ids:w}=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",w)]})});let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,ko.normalizeSuiAddress)("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=>ie.parsePositionVesting(f)))}}),a}buildRedeemPayload(t,e){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return B("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[Kt.DETAILS_KEYS.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:n,clmm_vest_id:r,cetus_coin_type:a}=(0,Kt.getPackagerConfigs)(i);return e=e||new pn.Transaction,t.forEach(l=>{let{clmm_pool_id:d,clmm_position_id:f,coin_type_a:h,coin_type_b:w,period:P}=l,M=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(Kt.CLOCK_ADDRESS)],typeArguments:[h,w]}),S=Kt.CoinAssist.fromBalance(M,a,e);e.transferObjects([S],this._sdk.getSenderAddress())}),e}};var Ge=class o extends To.SdkWrapper{constructor(t){super(t),this._swap=new Ze(this),this._pool=new Ve(this),this._position=new He(this),this._config=new Fe(this),this._rewarder=new We(this),this._vest=new ze(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({...cn,...t}):o.createCustomSDK({...un,...t})}static createCustomSDK(t){return new o(t)}};var Qe=fe(re()),le=require("@cetusprotocol/common-sdk");var Yr=new Qe.default(365),ts=new Qe.default(24),es=new Qe.default(3600),is=new Qe.default(.5);function ns(o,t,e,i){return Yr.mul(ts).mul(es).mul(is).mul(o.mul(t).add(e).div(i))}function os(o,t,e,i,n,r){let a=new O(o.toString()).div(new O(10**e)),l=new O(t.toString()).div(new O(10**i));return a.mul(n).add(l.mul(r))}function rs(o,t,e,i,n,r,a,l,d,f,h,w,P,M,S,I,W,$,G,D,K,zt,et,Qt){let ue=new O(w),ne=new O(P),de=new O(I),Z=new O(W),Ht=new O($),y=new O(G),s=new O(D),u=new O(K),_=new O(zt),p=new O(et),g=new O(Qt),v=le.TickMath.tickIndexToSqrtPriceX64(t),C=le.TickMath.tickIndexToSqrtPriceX64(e),m=le.MathUtil.toX64Decimal(le.MathUtil.fromX64(v)).round(),c=le.MathUtil.toX64Decimal(le.MathUtil.fromX64(C)).round(),b=le.MathUtil.toX64Decimal(le.MathUtil.fromX64(i)).round(),x,E=ue.mul(new O(10**r)).mul(c.mul(m)).div(c.sub(m)).round(),R=ne.mul(new O(10**a)).div(c.sub(m)).round();o<t?x=E:o>e?x=R:x=O.min(E,R);let U=x.mul(b.sub(m)),Q=x.mul(c.sub(b)).div(b.mul(c)).div(new O(10**r)).mul(s).add(U.div(new O(10**a).mul(u))),oe=os(M,S,r,a,s,u),J=Q.div(oe),it=x.eq(new O(0))?new O(0):new O(h/1e4).mul(de).mul(new O(x.toString()).div(new O(n.toString()).add(new O(x.toString())))).div(Q),Ce=J.eq(new O(0))?new O(0):J.mul(new O(36500/7)).div(Q),ot=Z.div(new O(10**l)).mul(_).mul(Ce),rt=Ht.div(new O(10**d)).mul(p).mul(Ce),Je=y.div(new O(10**f)).mul(g).mul(Ce);return{fee_apr:it,pos_rewarder_0_apr:ot,pos_rewarder_1_apr:rt,pos_rewarder_2_apr:Je}}function ss(o,t,e,i){let n=Math.max(o,e),a=Math.min(t,i)-n,l=t-o,d=i-e,f=new O(l.toString()),h=new O(d.toString()),w=new O(a.toString()),P=new O("0");return a<0?P=new O("0"):l===a?P=h.div(w):d===a?P=w.div(f):P=w.mul(w).div(h).div(f),P}var as=Ge;0&&(module.exports={AMM_SWAP_MODULE,BPS,CetusClmmSDK,ClmmError,ClmmExpectSwapModule,ClmmFetcherModule,ClmmIntegratePoolModule,ClmmIntegratePoolV2Module,ClmmIntegratePoolV3Module,ClmmIntegrateRouterModule,ClmmIntegrateRouterWithPartnerModule,ClmmIntegrateUtilsModule,ClmmPartnerModule,ClmmPositionStatus,ConfigErrorCode,ConfigModule,DeepbookClobV2Module,DeepbookCustodianV2Module,DeepbookEndpointsV2Module,POOL_STRUCT,PartnerErrorCode,PoolErrorCode,PoolModule,PositionErrorCode,PositionModule,PositionUtils,RewarderModule,RouterErrorCode,SwapErrorCode,SwapModule,SwapUtils,TypesErrorCode,UtilsErrorCode,VestErrorCode,VestModule,VestUtils,buildClmmPositionName,buildPool,buildPoolTransactionInfo,buildPosition,buildPositionInfo,buildPositionTransactionInfo,buildTickData,buildTickDataByEvent,buildTransferCoin,buildTransferCoinToSender,clmmMainnet,clmmTestnet,computeSwap,computeSwapStep,estPoolAPR,estPositionAPRWithDeltaMethod,estPositionAPRWithMultiMethod,eventMainnetContractMaps,eventTestnetContractMaps,findAdjustCoin,getDefaultSuiInputType,getLowerSqrtPriceFromCoinA,getLowerSqrtPriceFromCoinB,getUpperSqrtPriceFromCoinA,getUpperSqrtPriceFromCoinB,handleError,handleMessageError,newBits,poolFilterEvenTypes,poolLiquiditySnapshotType,transClmmpoolDataWithoutTicks});
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
decimal.js/decimal.mjs:
|