lll-sdk 0.0.0-experimental-20250821110614 → 0.0.0-experimental-20250821111532
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 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
"use strict";var Wr=Object.create;var Ei=Object.defineProperty;var Gr=Object.getOwnPropertyDescriptor;var Jr=Object.getOwnPropertyNames;var Xr=Object.getPrototypeOf,Qr=Object.prototype.hasOwnProperty;var Yr=(t,i)=>()=>(i||t((i={exports:{}}).exports,i),i.exports),to=(t,i)=>{for(var n in i)Ei(t,n,{get:i[n],enumerable:!0})},Rn=(t,i,n,a)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of Jr(i))!Qr.call(t,r)&&r!==n&&Ei(t,r,{get:()=>i[r],enumerable:!(a=Gr(i,r))||a.enumerable});return t};var an=(t,i,n)=>(n=t!=null?Wr(Xr(t)):{},Rn(i||!t||!t.__esModule?Ei(n,"default",{value:t,enumerable:!0}):n,t)),eo=t=>Rn(Ei({},"__esModule",{value:!0}),t);var Gn=Yr((Wn,mn)=>{"use strict";(function(t,i){"use strict";function n(v,s){if(!v)throw new Error(s||"Assertion failed")}function a(v,s){v.super_=s;var e=function(){};e.prototype=s.prototype,v.prototype=new e,v.prototype.constructor=v}function r(v,s,e){if(r.isBN(v))return v;this.negative=0,this.words=null,this.length=0,this.red=null,v!==null&&((s==="le"||s==="be")&&(e=s,s=10),this._init(v||0,s||10,e||"be"))}typeof t=="object"?t.exports=r:i.BN=r,r.BN=r,r.wordSize=26;var d;try{typeof window<"u"&&typeof window.Buffer<"u"?d=window.Buffer:d=require("buffer").Buffer}catch{}r.isBN=function(s){return s instanceof r?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===r.wordSize&&Array.isArray(s.words)},r.max=function(s,e){return s.cmp(e)>0?s:e},r.min=function(s,e){return s.cmp(e)<0?s:e},r.prototype._init=function(s,e,o){if(typeof s=="number")return this._initNumber(s,e,o);if(typeof s=="object")return this._initArray(s,e,o);e==="hex"&&(e=16),n(e===(e|0)&&e>=2&&e<=36),s=s.toString().replace(/\s+/g,"");var l=0;s[0]==="-"&&(l++,this.negative=1),l<s.length&&(e===16?this._parseHex(s,l,o):(this._parseBase(s,e,l),o==="le"&&this._initArray(this.toArray(),e,o)))},r.prototype._initNumber=function(s,e,o){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):(n(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),o==="le"&&this._initArray(this.toArray(),e,o)},r.prototype._initArray=function(s,e,o){if(n(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 l=0;l<this.length;l++)this.words[l]=0;var f,m,w=0;if(o==="be")for(l=s.length-1,f=0;l>=0;l-=3)m=s[l]|s[l-1]<<8|s[l-2]<<16,this.words[f]|=m<<w&67108863,this.words[f+1]=m>>>26-w&67108863,w+=24,w>=26&&(w-=26,f++);else if(o==="le")for(l=0,f=0;l<s.length;l+=3)m=s[l]|s[l+1]<<8|s[l+2]<<16,this.words[f]|=m<<w&67108863,this.words[f+1]=m>>>26-w&67108863,w+=24,w>=26&&(w-=26,f++);return this._strip()};function c(v,s){var e=v.charCodeAt(s);if(e>=48&&e<=57)return e-48;if(e>=65&&e<=70)return e-55;if(e>=97&&e<=102)return e-87;n(!1,"Invalid character in "+v)}function p(v,s,e){var o=c(v,e);return e-1>=s&&(o|=c(v,e-1)<<4),o}r.prototype._parseHex=function(s,e,o){this.length=Math.ceil((s.length-e)/6),this.words=new Array(this.length);for(var l=0;l<this.length;l++)this.words[l]=0;var f=0,m=0,w;if(o==="be")for(l=s.length-1;l>=e;l-=2)w=p(s,e,l)<<f,this.words[m]|=w&67108863,f>=18?(f-=18,m+=1,this.words[m]|=w>>>26):f+=8;else{var _=s.length-e;for(l=_%2===0?e+1:e;l<s.length;l+=2)w=p(s,e,l)<<f,this.words[m]|=w&67108863,f>=18?(f-=18,m+=1,this.words[m]|=w>>>26):f+=8}this._strip()};function g(v,s,e,o){for(var l=0,f=0,m=Math.min(v.length,e),w=s;w<m;w++){var _=v.charCodeAt(w)-48;l*=o,_>=49?f=_-49+10:_>=17?f=_-17+10:f=_,n(_>=0&&f<o,"Invalid character"),l+=f}return l}r.prototype._parseBase=function(s,e,o){this.words=[0],this.length=1;for(var l=0,f=1;f<=67108863;f*=e)l++;l--,f=f/e|0;for(var m=s.length-o,w=m%l,_=Math.min(m,m-w)+o,u=0,h=o;h<_;h+=l)u=g(s,h,h+l,e),this.imuln(f),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(w!==0){var b=1;for(u=g(s,h,s.length,e),h=0;h<w;h++)b*=e;this.imuln(b),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},r.prototype.copy=function(s){s.words=new Array(this.length);for(var e=0;e<this.length;e++)s.words[e]=this.words[e];s.length=this.length,s.negative=this.negative,s.red=this.red};function y(v,s){v.words=s.words,v.length=s.length,v.negative=s.negative,v.red=s.red}if(r.prototype._move=function(s){y(s,this)},r.prototype.clone=function(){var s=new r(null);return this.copy(s),s},r.prototype._expand=function(s){for(;this.length<s;)this.words[this.length++]=0;return this},r.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},r.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{r.prototype[Symbol.for("nodejs.util.inspect.custom")]=k}catch{r.prototype.inspect=k}else r.prototype.inspect=k;function k(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var C=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],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],N=[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];r.prototype.toString=function(s,e){s=s||10,e=e|0||1;var o;if(s===16||s==="hex"){o="";for(var l=0,f=0,m=0;m<this.length;m++){var w=this.words[m],_=((w<<l|f)&16777215).toString(16);f=w>>>24-l&16777215,l+=2,l>=26&&(l-=26,m--),f!==0||m!==this.length-1?o=C[6-_.length]+_+o:o=_+o}for(f!==0&&(o=f.toString(16)+o);o.length%e!==0;)o="0"+o;return this.negative!==0&&(o="-"+o),o}if(s===(s|0)&&s>=2&&s<=36){var u=P[s],h=N[s];o="";var b=this.clone();for(b.negative=0;!b.isZero();){var T=b.modrn(h).toString(s);b=b.idivn(h),b.isZero()?o=T+o:o=C[u-T.length]+T+o}for(this.isZero()&&(o="0"+o);o.length%e!==0;)o="0"+o;return this.negative!==0&&(o="-"+o),o}n(!1,"Base should be between 2 and 36")},r.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&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},r.prototype.toJSON=function(){return this.toString(16,2)},d&&(r.prototype.toBuffer=function(s,e){return this.toArrayLike(d,s,e)}),r.prototype.toArray=function(s,e){return this.toArrayLike(Array,s,e)};var q=function(s,e){return s.allocUnsafe?s.allocUnsafe(e):new s(e)};r.prototype.toArrayLike=function(s,e,o){this._strip();var l=this.byteLength(),f=o||Math.max(1,l);n(l<=f,"byte array longer than desired length"),n(f>0,"Requested array length <= 0");var m=q(s,f),w=e==="le"?"LE":"BE";return this["_toArrayLike"+w](m,l),m},r.prototype._toArrayLikeLE=function(s,e){for(var o=0,l=0,f=0,m=0;f<this.length;f++){var w=this.words[f]<<m|l;s[o++]=w&255,o<s.length&&(s[o++]=w>>8&255),o<s.length&&(s[o++]=w>>16&255),m===6?(o<s.length&&(s[o++]=w>>24&255),l=0,m=0):(l=w>>>24,m+=2)}if(o<s.length)for(s[o++]=l;o<s.length;)s[o++]=0},r.prototype._toArrayLikeBE=function(s,e){for(var o=s.length-1,l=0,f=0,m=0;f<this.length;f++){var w=this.words[f]<<m|l;s[o--]=w&255,o>=0&&(s[o--]=w>>8&255),o>=0&&(s[o--]=w>>16&255),m===6?(o>=0&&(s[o--]=w>>24&255),l=0,m=0):(l=w>>>24,m+=2)}if(o>=0)for(s[o--]=l;o>=0;)s[o--]=0},Math.clz32?r.prototype._countBits=function(s){return 32-Math.clz32(s)}:r.prototype._countBits=function(s){var e=s,o=0;return e>=4096&&(o+=13,e>>>=13),e>=64&&(o+=7,e>>>=7),e>=8&&(o+=4,e>>>=4),e>=2&&(o+=2,e>>>=2),o+e},r.prototype._zeroBits=function(s){if(s===0)return 26;var e=s,o=0;return(e&8191)===0&&(o+=13,e>>>=13),(e&127)===0&&(o+=7,e>>>=7),(e&15)===0&&(o+=4,e>>>=4),(e&3)===0&&(o+=2,e>>>=2),(e&1)===0&&o++,o},r.prototype.bitLength=function(){var s=this.words[this.length-1],e=this._countBits(s);return(this.length-1)*26+e};function L(v){for(var s=new Array(v.bitLength()),e=0;e<s.length;e++){var o=e/26|0,l=e%26;s[e]=v.words[o]>>>l&1}return s}r.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,e=0;e<this.length;e++){var o=this._zeroBits(this.words[e]);if(s+=o,o!==26)break}return s},r.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},r.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},r.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).iaddn(1).ineg():this.clone()},r.prototype.isNeg=function(){return this.negative!==0},r.prototype.neg=function(){return this.clone().ineg()},r.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},r.prototype.iuor=function(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var e=0;e<s.length;e++)this.words[e]=this.words[e]|s.words[e];return this._strip()},r.prototype.ior=function(s){return n((this.negative|s.negative)===0),this.iuor(s)},r.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},r.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},r.prototype.iuand=function(s){var e;this.length>s.length?e=s:e=this;for(var o=0;o<e.length;o++)this.words[o]=this.words[o]&s.words[o];return this.length=e.length,this._strip()},r.prototype.iand=function(s){return n((this.negative|s.negative)===0),this.iuand(s)},r.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},r.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},r.prototype.iuxor=function(s){var e,o;this.length>s.length?(e=this,o=s):(e=s,o=this);for(var l=0;l<o.length;l++)this.words[l]=e.words[l]^o.words[l];if(this!==e)for(;l<e.length;l++)this.words[l]=e.words[l];return this.length=e.length,this._strip()},r.prototype.ixor=function(s){return n((this.negative|s.negative)===0),this.iuxor(s)},r.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},r.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},r.prototype.inotn=function(s){n(typeof s=="number"&&s>=0);var e=Math.ceil(s/26)|0,o=s%26;this._expand(e),o>0&&e--;for(var l=0;l<e;l++)this.words[l]=~this.words[l]&67108863;return o>0&&(this.words[l]=~this.words[l]&67108863>>26-o),this._strip()},r.prototype.notn=function(s){return this.clone().inotn(s)},r.prototype.setn=function(s,e){n(typeof s=="number"&&s>=0);var o=s/26|0,l=s%26;return this._expand(o+1),e?this.words[o]=this.words[o]|1<<l:this.words[o]=this.words[o]&~(1<<l),this._strip()},r.prototype.iadd=function(s){var e;if(this.negative!==0&&s.negative===0)return this.negative=0,e=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,e=this.isub(s),s.negative=1,e._normSign();var o,l;this.length>s.length?(o=this,l=s):(o=s,l=this);for(var f=0,m=0;m<l.length;m++)e=(o.words[m]|0)+(l.words[m]|0)+f,this.words[m]=e&67108863,f=e>>>26;for(;f!==0&&m<o.length;m++)e=(o.words[m]|0)+f,this.words[m]=e&67108863,f=e>>>26;if(this.length=o.length,f!==0)this.words[this.length]=f,this.length++;else if(o!==this)for(;m<o.length;m++)this.words[m]=o.words[m];return this},r.prototype.add=function(s){var e;return s.negative!==0&&this.negative===0?(s.negative=0,e=this.sub(s),s.negative^=1,e):s.negative===0&&this.negative!==0?(this.negative=0,e=s.sub(this),this.negative=1,e):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},r.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var e=this.iadd(s);return s.negative=1,e._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var o=this.cmp(s);if(o===0)return this.negative=0,this.length=1,this.words[0]=0,this;var l,f;o>0?(l=this,f=s):(l=s,f=this);for(var m=0,w=0;w<f.length;w++)e=(l.words[w]|0)-(f.words[w]|0)+m,m=e>>26,this.words[w]=e&67108863;for(;m!==0&&w<l.length;w++)e=(l.words[w]|0)+m,m=e>>26,this.words[w]=e&67108863;if(m===0&&w<l.length&&l!==this)for(;w<l.length;w++)this.words[w]=l.words[w];return this.length=Math.max(this.length,w),l!==this&&(this.negative=1),this._strip()},r.prototype.sub=function(s){return this.clone().isub(s)};function K(v,s,e){e.negative=s.negative^v.negative;var o=v.length+s.length|0;e.length=o,o=o-1|0;var l=v.words[0]|0,f=s.words[0]|0,m=l*f,w=m&67108863,_=m/67108864|0;e.words[0]=w;for(var u=1;u<o;u++){for(var h=_>>>26,b=_&67108863,T=Math.min(u,s.length-1),I=Math.max(0,u-v.length+1);I<=T;I++){var F=u-I|0;l=v.words[F]|0,f=s.words[I]|0,m=l*f+b,h+=m/67108864|0,b=m&67108863}e.words[u]=b|0,_=h|0}return _!==0?e.words[u]=_|0:e.length--,e._strip()}var W=function(s,e,o){var l=s.words,f=e.words,m=o.words,w=0,_,u,h,b=l[0]|0,T=b&8191,I=b>>>13,F=l[1]|0,B=F&8191,$=F>>>13,yt=l[2]|0,Q=yt&8191,z=yt>>>13,wt=l[3]|0,bt=wt&8191,U=wt>>>13,It=l[4]|0,Ot=It&8191,it=It>>>13,Nt=l[5]|0,Ft=Nt&8191,nt=Nt>>>13,Rt=l[6]|0,Dt=Rt&8191,rt=Rt>>>13,Bt=l[7]|0,qt=Bt&8191,ot=Bt>>>13,jt=l[8]|0,Lt=jt&8191,at=jt>>>13,$t=l[9]|0,Ut=$t&8191,st=$t>>>13,zt=f[0]|0,Zt=zt&8191,lt=zt>>>13,Ht=f[1]|0,Kt=Ht&8191,ut=Ht>>>13,Vt=f[2]|0,Wt=Vt&8191,ht=Vt>>>13,Gt=f[3]|0,Jt=Gt&8191,dt=Gt>>>13,Xt=f[4]|0,Qt=Xt&8191,ct=Xt>>>13,Yt=f[5]|0,te=Yt&8191,ft=Yt>>>13,ee=f[6]|0,ie=ee&8191,pt=ee>>>13,ne=f[7]|0,re=ne&8191,mt=ne>>>13,oe=f[8]|0,ae=oe&8191,_t=oe>>>13,se=f[9]|0,le=se&8191,gt=se>>>13;o.negative=s.negative^e.negative,o.length=19,_=Math.imul(T,Zt),u=Math.imul(T,lt),u=u+Math.imul(I,Zt)|0,h=Math.imul(I,lt);var Et=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(Et>>>26)|0,Et&=67108863,_=Math.imul(B,Zt),u=Math.imul(B,lt),u=u+Math.imul($,Zt)|0,h=Math.imul($,lt),_=_+Math.imul(T,Kt)|0,u=u+Math.imul(T,ut)|0,u=u+Math.imul(I,Kt)|0,h=h+Math.imul(I,ut)|0;var Ke=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(Ke>>>26)|0,Ke&=67108863,_=Math.imul(Q,Zt),u=Math.imul(Q,lt),u=u+Math.imul(z,Zt)|0,h=Math.imul(z,lt),_=_+Math.imul(B,Kt)|0,u=u+Math.imul(B,ut)|0,u=u+Math.imul($,Kt)|0,h=h+Math.imul($,ut)|0,_=_+Math.imul(T,Wt)|0,u=u+Math.imul(T,ht)|0,u=u+Math.imul(I,Wt)|0,h=h+Math.imul(I,ht)|0;var Ve=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(Ve>>>26)|0,Ve&=67108863,_=Math.imul(bt,Zt),u=Math.imul(bt,lt),u=u+Math.imul(U,Zt)|0,h=Math.imul(U,lt),_=_+Math.imul(Q,Kt)|0,u=u+Math.imul(Q,ut)|0,u=u+Math.imul(z,Kt)|0,h=h+Math.imul(z,ut)|0,_=_+Math.imul(B,Wt)|0,u=u+Math.imul(B,ht)|0,u=u+Math.imul($,Wt)|0,h=h+Math.imul($,ht)|0,_=_+Math.imul(T,Jt)|0,u=u+Math.imul(T,dt)|0,u=u+Math.imul(I,Jt)|0,h=h+Math.imul(I,dt)|0;var We=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(We>>>26)|0,We&=67108863,_=Math.imul(Ot,Zt),u=Math.imul(Ot,lt),u=u+Math.imul(it,Zt)|0,h=Math.imul(it,lt),_=_+Math.imul(bt,Kt)|0,u=u+Math.imul(bt,ut)|0,u=u+Math.imul(U,Kt)|0,h=h+Math.imul(U,ut)|0,_=_+Math.imul(Q,Wt)|0,u=u+Math.imul(Q,ht)|0,u=u+Math.imul(z,Wt)|0,h=h+Math.imul(z,ht)|0,_=_+Math.imul(B,Jt)|0,u=u+Math.imul(B,dt)|0,u=u+Math.imul($,Jt)|0,h=h+Math.imul($,dt)|0,_=_+Math.imul(T,Qt)|0,u=u+Math.imul(T,ct)|0,u=u+Math.imul(I,Qt)|0,h=h+Math.imul(I,ct)|0;var Ge=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(Ge>>>26)|0,Ge&=67108863,_=Math.imul(Ft,Zt),u=Math.imul(Ft,lt),u=u+Math.imul(nt,Zt)|0,h=Math.imul(nt,lt),_=_+Math.imul(Ot,Kt)|0,u=u+Math.imul(Ot,ut)|0,u=u+Math.imul(it,Kt)|0,h=h+Math.imul(it,ut)|0,_=_+Math.imul(bt,Wt)|0,u=u+Math.imul(bt,ht)|0,u=u+Math.imul(U,Wt)|0,h=h+Math.imul(U,ht)|0,_=_+Math.imul(Q,Jt)|0,u=u+Math.imul(Q,dt)|0,u=u+Math.imul(z,Jt)|0,h=h+Math.imul(z,dt)|0,_=_+Math.imul(B,Qt)|0,u=u+Math.imul(B,ct)|0,u=u+Math.imul($,Qt)|0,h=h+Math.imul($,ct)|0,_=_+Math.imul(T,te)|0,u=u+Math.imul(T,ft)|0,u=u+Math.imul(I,te)|0,h=h+Math.imul(I,ft)|0;var Je=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(Je>>>26)|0,Je&=67108863,_=Math.imul(Dt,Zt),u=Math.imul(Dt,lt),u=u+Math.imul(rt,Zt)|0,h=Math.imul(rt,lt),_=_+Math.imul(Ft,Kt)|0,u=u+Math.imul(Ft,ut)|0,u=u+Math.imul(nt,Kt)|0,h=h+Math.imul(nt,ut)|0,_=_+Math.imul(Ot,Wt)|0,u=u+Math.imul(Ot,ht)|0,u=u+Math.imul(it,Wt)|0,h=h+Math.imul(it,ht)|0,_=_+Math.imul(bt,Jt)|0,u=u+Math.imul(bt,dt)|0,u=u+Math.imul(U,Jt)|0,h=h+Math.imul(U,dt)|0,_=_+Math.imul(Q,Qt)|0,u=u+Math.imul(Q,ct)|0,u=u+Math.imul(z,Qt)|0,h=h+Math.imul(z,ct)|0,_=_+Math.imul(B,te)|0,u=u+Math.imul(B,ft)|0,u=u+Math.imul($,te)|0,h=h+Math.imul($,ft)|0,_=_+Math.imul(T,ie)|0,u=u+Math.imul(T,pt)|0,u=u+Math.imul(I,ie)|0,h=h+Math.imul(I,pt)|0;var Xe=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(Xe>>>26)|0,Xe&=67108863,_=Math.imul(qt,Zt),u=Math.imul(qt,lt),u=u+Math.imul(ot,Zt)|0,h=Math.imul(ot,lt),_=_+Math.imul(Dt,Kt)|0,u=u+Math.imul(Dt,ut)|0,u=u+Math.imul(rt,Kt)|0,h=h+Math.imul(rt,ut)|0,_=_+Math.imul(Ft,Wt)|0,u=u+Math.imul(Ft,ht)|0,u=u+Math.imul(nt,Wt)|0,h=h+Math.imul(nt,ht)|0,_=_+Math.imul(Ot,Jt)|0,u=u+Math.imul(Ot,dt)|0,u=u+Math.imul(it,Jt)|0,h=h+Math.imul(it,dt)|0,_=_+Math.imul(bt,Qt)|0,u=u+Math.imul(bt,ct)|0,u=u+Math.imul(U,Qt)|0,h=h+Math.imul(U,ct)|0,_=_+Math.imul(Q,te)|0,u=u+Math.imul(Q,ft)|0,u=u+Math.imul(z,te)|0,h=h+Math.imul(z,ft)|0,_=_+Math.imul(B,ie)|0,u=u+Math.imul(B,pt)|0,u=u+Math.imul($,ie)|0,h=h+Math.imul($,pt)|0,_=_+Math.imul(T,re)|0,u=u+Math.imul(T,mt)|0,u=u+Math.imul(I,re)|0,h=h+Math.imul(I,mt)|0;var Qe=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(Qe>>>26)|0,Qe&=67108863,_=Math.imul(Lt,Zt),u=Math.imul(Lt,lt),u=u+Math.imul(at,Zt)|0,h=Math.imul(at,lt),_=_+Math.imul(qt,Kt)|0,u=u+Math.imul(qt,ut)|0,u=u+Math.imul(ot,Kt)|0,h=h+Math.imul(ot,ut)|0,_=_+Math.imul(Dt,Wt)|0,u=u+Math.imul(Dt,ht)|0,u=u+Math.imul(rt,Wt)|0,h=h+Math.imul(rt,ht)|0,_=_+Math.imul(Ft,Jt)|0,u=u+Math.imul(Ft,dt)|0,u=u+Math.imul(nt,Jt)|0,h=h+Math.imul(nt,dt)|0,_=_+Math.imul(Ot,Qt)|0,u=u+Math.imul(Ot,ct)|0,u=u+Math.imul(it,Qt)|0,h=h+Math.imul(it,ct)|0,_=_+Math.imul(bt,te)|0,u=u+Math.imul(bt,ft)|0,u=u+Math.imul(U,te)|0,h=h+Math.imul(U,ft)|0,_=_+Math.imul(Q,ie)|0,u=u+Math.imul(Q,pt)|0,u=u+Math.imul(z,ie)|0,h=h+Math.imul(z,pt)|0,_=_+Math.imul(B,re)|0,u=u+Math.imul(B,mt)|0,u=u+Math.imul($,re)|0,h=h+Math.imul($,mt)|0,_=_+Math.imul(T,ae)|0,u=u+Math.imul(T,_t)|0,u=u+Math.imul(I,ae)|0,h=h+Math.imul(I,_t)|0;var Ye=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,_=Math.imul(Ut,Zt),u=Math.imul(Ut,lt),u=u+Math.imul(st,Zt)|0,h=Math.imul(st,lt),_=_+Math.imul(Lt,Kt)|0,u=u+Math.imul(Lt,ut)|0,u=u+Math.imul(at,Kt)|0,h=h+Math.imul(at,ut)|0,_=_+Math.imul(qt,Wt)|0,u=u+Math.imul(qt,ht)|0,u=u+Math.imul(ot,Wt)|0,h=h+Math.imul(ot,ht)|0,_=_+Math.imul(Dt,Jt)|0,u=u+Math.imul(Dt,dt)|0,u=u+Math.imul(rt,Jt)|0,h=h+Math.imul(rt,dt)|0,_=_+Math.imul(Ft,Qt)|0,u=u+Math.imul(Ft,ct)|0,u=u+Math.imul(nt,Qt)|0,h=h+Math.imul(nt,ct)|0,_=_+Math.imul(Ot,te)|0,u=u+Math.imul(Ot,ft)|0,u=u+Math.imul(it,te)|0,h=h+Math.imul(it,ft)|0,_=_+Math.imul(bt,ie)|0,u=u+Math.imul(bt,pt)|0,u=u+Math.imul(U,ie)|0,h=h+Math.imul(U,pt)|0,_=_+Math.imul(Q,re)|0,u=u+Math.imul(Q,mt)|0,u=u+Math.imul(z,re)|0,h=h+Math.imul(z,mt)|0,_=_+Math.imul(B,ae)|0,u=u+Math.imul(B,_t)|0,u=u+Math.imul($,ae)|0,h=h+Math.imul($,_t)|0,_=_+Math.imul(T,le)|0,u=u+Math.imul(T,gt)|0,u=u+Math.imul(I,le)|0,h=h+Math.imul(I,gt)|0;var ti=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,_=Math.imul(Ut,Kt),u=Math.imul(Ut,ut),u=u+Math.imul(st,Kt)|0,h=Math.imul(st,ut),_=_+Math.imul(Lt,Wt)|0,u=u+Math.imul(Lt,ht)|0,u=u+Math.imul(at,Wt)|0,h=h+Math.imul(at,ht)|0,_=_+Math.imul(qt,Jt)|0,u=u+Math.imul(qt,dt)|0,u=u+Math.imul(ot,Jt)|0,h=h+Math.imul(ot,dt)|0,_=_+Math.imul(Dt,Qt)|0,u=u+Math.imul(Dt,ct)|0,u=u+Math.imul(rt,Qt)|0,h=h+Math.imul(rt,ct)|0,_=_+Math.imul(Ft,te)|0,u=u+Math.imul(Ft,ft)|0,u=u+Math.imul(nt,te)|0,h=h+Math.imul(nt,ft)|0,_=_+Math.imul(Ot,ie)|0,u=u+Math.imul(Ot,pt)|0,u=u+Math.imul(it,ie)|0,h=h+Math.imul(it,pt)|0,_=_+Math.imul(bt,re)|0,u=u+Math.imul(bt,mt)|0,u=u+Math.imul(U,re)|0,h=h+Math.imul(U,mt)|0,_=_+Math.imul(Q,ae)|0,u=u+Math.imul(Q,_t)|0,u=u+Math.imul(z,ae)|0,h=h+Math.imul(z,_t)|0,_=_+Math.imul(B,le)|0,u=u+Math.imul(B,gt)|0,u=u+Math.imul($,le)|0,h=h+Math.imul($,gt)|0;var ei=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,_=Math.imul(Ut,Wt),u=Math.imul(Ut,ht),u=u+Math.imul(st,Wt)|0,h=Math.imul(st,ht),_=_+Math.imul(Lt,Jt)|0,u=u+Math.imul(Lt,dt)|0,u=u+Math.imul(at,Jt)|0,h=h+Math.imul(at,dt)|0,_=_+Math.imul(qt,Qt)|0,u=u+Math.imul(qt,ct)|0,u=u+Math.imul(ot,Qt)|0,h=h+Math.imul(ot,ct)|0,_=_+Math.imul(Dt,te)|0,u=u+Math.imul(Dt,ft)|0,u=u+Math.imul(rt,te)|0,h=h+Math.imul(rt,ft)|0,_=_+Math.imul(Ft,ie)|0,u=u+Math.imul(Ft,pt)|0,u=u+Math.imul(nt,ie)|0,h=h+Math.imul(nt,pt)|0,_=_+Math.imul(Ot,re)|0,u=u+Math.imul(Ot,mt)|0,u=u+Math.imul(it,re)|0,h=h+Math.imul(it,mt)|0,_=_+Math.imul(bt,ae)|0,u=u+Math.imul(bt,_t)|0,u=u+Math.imul(U,ae)|0,h=h+Math.imul(U,_t)|0,_=_+Math.imul(Q,le)|0,u=u+Math.imul(Q,gt)|0,u=u+Math.imul(z,le)|0,h=h+Math.imul(z,gt)|0;var ii=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,_=Math.imul(Ut,Jt),u=Math.imul(Ut,dt),u=u+Math.imul(st,Jt)|0,h=Math.imul(st,dt),_=_+Math.imul(Lt,Qt)|0,u=u+Math.imul(Lt,ct)|0,u=u+Math.imul(at,Qt)|0,h=h+Math.imul(at,ct)|0,_=_+Math.imul(qt,te)|0,u=u+Math.imul(qt,ft)|0,u=u+Math.imul(ot,te)|0,h=h+Math.imul(ot,ft)|0,_=_+Math.imul(Dt,ie)|0,u=u+Math.imul(Dt,pt)|0,u=u+Math.imul(rt,ie)|0,h=h+Math.imul(rt,pt)|0,_=_+Math.imul(Ft,re)|0,u=u+Math.imul(Ft,mt)|0,u=u+Math.imul(nt,re)|0,h=h+Math.imul(nt,mt)|0,_=_+Math.imul(Ot,ae)|0,u=u+Math.imul(Ot,_t)|0,u=u+Math.imul(it,ae)|0,h=h+Math.imul(it,_t)|0,_=_+Math.imul(bt,le)|0,u=u+Math.imul(bt,gt)|0,u=u+Math.imul(U,le)|0,h=h+Math.imul(U,gt)|0;var ni=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,_=Math.imul(Ut,Qt),u=Math.imul(Ut,ct),u=u+Math.imul(st,Qt)|0,h=Math.imul(st,ct),_=_+Math.imul(Lt,te)|0,u=u+Math.imul(Lt,ft)|0,u=u+Math.imul(at,te)|0,h=h+Math.imul(at,ft)|0,_=_+Math.imul(qt,ie)|0,u=u+Math.imul(qt,pt)|0,u=u+Math.imul(ot,ie)|0,h=h+Math.imul(ot,pt)|0,_=_+Math.imul(Dt,re)|0,u=u+Math.imul(Dt,mt)|0,u=u+Math.imul(rt,re)|0,h=h+Math.imul(rt,mt)|0,_=_+Math.imul(Ft,ae)|0,u=u+Math.imul(Ft,_t)|0,u=u+Math.imul(nt,ae)|0,h=h+Math.imul(nt,_t)|0,_=_+Math.imul(Ot,le)|0,u=u+Math.imul(Ot,gt)|0,u=u+Math.imul(it,le)|0,h=h+Math.imul(it,gt)|0;var ri=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,_=Math.imul(Ut,te),u=Math.imul(Ut,ft),u=u+Math.imul(st,te)|0,h=Math.imul(st,ft),_=_+Math.imul(Lt,ie)|0,u=u+Math.imul(Lt,pt)|0,u=u+Math.imul(at,ie)|0,h=h+Math.imul(at,pt)|0,_=_+Math.imul(qt,re)|0,u=u+Math.imul(qt,mt)|0,u=u+Math.imul(ot,re)|0,h=h+Math.imul(ot,mt)|0,_=_+Math.imul(Dt,ae)|0,u=u+Math.imul(Dt,_t)|0,u=u+Math.imul(rt,ae)|0,h=h+Math.imul(rt,_t)|0,_=_+Math.imul(Ft,le)|0,u=u+Math.imul(Ft,gt)|0,u=u+Math.imul(nt,le)|0,h=h+Math.imul(nt,gt)|0;var oi=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,_=Math.imul(Ut,ie),u=Math.imul(Ut,pt),u=u+Math.imul(st,ie)|0,h=Math.imul(st,pt),_=_+Math.imul(Lt,re)|0,u=u+Math.imul(Lt,mt)|0,u=u+Math.imul(at,re)|0,h=h+Math.imul(at,mt)|0,_=_+Math.imul(qt,ae)|0,u=u+Math.imul(qt,_t)|0,u=u+Math.imul(ot,ae)|0,h=h+Math.imul(ot,_t)|0,_=_+Math.imul(Dt,le)|0,u=u+Math.imul(Dt,gt)|0,u=u+Math.imul(rt,le)|0,h=h+Math.imul(rt,gt)|0;var ai=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,_=Math.imul(Ut,re),u=Math.imul(Ut,mt),u=u+Math.imul(st,re)|0,h=Math.imul(st,mt),_=_+Math.imul(Lt,ae)|0,u=u+Math.imul(Lt,_t)|0,u=u+Math.imul(at,ae)|0,h=h+Math.imul(at,_t)|0,_=_+Math.imul(qt,le)|0,u=u+Math.imul(qt,gt)|0,u=u+Math.imul(ot,le)|0,h=h+Math.imul(ot,gt)|0;var si=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(si>>>26)|0,si&=67108863,_=Math.imul(Ut,ae),u=Math.imul(Ut,_t),u=u+Math.imul(st,ae)|0,h=Math.imul(st,_t),_=_+Math.imul(Lt,le)|0,u=u+Math.imul(Lt,gt)|0,u=u+Math.imul(at,le)|0,h=h+Math.imul(at,gt)|0;var li=(w+_|0)+((u&8191)<<13)|0;w=(h+(u>>>13)|0)+(li>>>26)|0,li&=67108863,_=Math.imul(Ut,le),u=Math.imul(Ut,gt),u=u+Math.imul(st,le)|0,h=Math.imul(st,gt);var ui=(w+_|0)+((u&8191)<<13)|0;return w=(h+(u>>>13)|0)+(ui>>>26)|0,ui&=67108863,m[0]=Et,m[1]=Ke,m[2]=Ve,m[3]=We,m[4]=Ge,m[5]=Je,m[6]=Xe,m[7]=Qe,m[8]=Ye,m[9]=ti,m[10]=ei,m[11]=ii,m[12]=ni,m[13]=ri,m[14]=oi,m[15]=ai,m[16]=si,m[17]=li,m[18]=ui,w!==0&&(m[19]=w,o.length++),o};Math.imul||(W=K);function O(v,s,e){e.negative=s.negative^v.negative,e.length=v.length+s.length;for(var o=0,l=0,f=0;f<e.length-1;f++){var m=l;l=0;for(var w=o&67108863,_=Math.min(f,s.length-1),u=Math.max(0,f-v.length+1);u<=_;u++){var h=f-u,b=v.words[h]|0,T=s.words[u]|0,I=b*T,F=I&67108863;m=m+(I/67108864|0)|0,F=F+w|0,w=F&67108863,m=m+(F>>>26)|0,l+=m>>>26,m&=67108863}e.words[f]=w,o=m,m=l}return o!==0?e.words[f]=o:e.length--,e._strip()}function J(v,s,e){return O(v,s,e)}r.prototype.mulTo=function(s,e){var o,l=this.length+s.length;return this.length===10&&s.length===10?o=W(this,s,e):l<63?o=K(this,s,e):l<1024?o=O(this,s,e):o=J(this,s,e),o};function vt(v,s){this.x=v,this.y=s}vt.prototype.makeRBT=function(s){for(var e=new Array(s),o=r.prototype._countBits(s)-1,l=0;l<s;l++)e[l]=this.revBin(l,o,s);return e},vt.prototype.revBin=function(s,e,o){if(s===0||s===o-1)return s;for(var l=0,f=0;f<e;f++)l|=(s&1)<<e-f-1,s>>=1;return l},vt.prototype.permute=function(s,e,o,l,f,m){for(var w=0;w<m;w++)l[w]=e[s[w]],f[w]=o[s[w]]},vt.prototype.transform=function(s,e,o,l,f,m){this.permute(m,s,e,o,l,f);for(var w=1;w<f;w<<=1)for(var _=w<<1,u=Math.cos(2*Math.PI/_),h=Math.sin(2*Math.PI/_),b=0;b<f;b+=_)for(var T=u,I=h,F=0;F<w;F++){var B=o[b+F],$=l[b+F],yt=o[b+F+w],Q=l[b+F+w],z=T*yt-I*Q;Q=T*Q+I*yt,yt=z,o[b+F]=B+yt,l[b+F]=$+Q,o[b+F+w]=B-yt,l[b+F+w]=$-Q,F!==_&&(z=u*T-h*I,I=u*I+h*T,T=z)}},vt.prototype.guessLen13b=function(s,e){var o=Math.max(e,s)|1,l=o&1,f=0;for(o=o/2|0;o;o=o>>>1)f++;return 1<<f+1+l},vt.prototype.conjugate=function(s,e,o){if(!(o<=1))for(var l=0;l<o/2;l++){var f=s[l];s[l]=s[o-l-1],s[o-l-1]=f,f=e[l],e[l]=-e[o-l-1],e[o-l-1]=-f}},vt.prototype.normalize13b=function(s,e){for(var o=0,l=0;l<e/2;l++){var f=Math.round(s[2*l+1]/e)*8192+Math.round(s[2*l]/e)+o;s[l]=f&67108863,f<67108864?o=0:o=f/67108864|0}return s},vt.prototype.convert13b=function(s,e,o,l){for(var f=0,m=0;m<e;m++)f=f+(s[m]|0),o[2*m]=f&8191,f=f>>>13,o[2*m+1]=f&8191,f=f>>>13;for(m=2*e;m<l;++m)o[m]=0;n(f===0),n((f&-8192)===0)},vt.prototype.stub=function(s){for(var e=new Array(s),o=0;o<s;o++)e[o]=0;return e},vt.prototype.mulp=function(s,e,o){var l=2*this.guessLen13b(s.length,e.length),f=this.makeRBT(l),m=this.stub(l),w=new Array(l),_=new Array(l),u=new Array(l),h=new Array(l),b=new Array(l),T=new Array(l),I=o.words;I.length=l,this.convert13b(s.words,s.length,w,l),this.convert13b(e.words,e.length,h,l),this.transform(w,m,_,u,l,f),this.transform(h,m,b,T,l,f);for(var F=0;F<l;F++){var B=_[F]*b[F]-u[F]*T[F];u[F]=_[F]*T[F]+u[F]*b[F],_[F]=B}return this.conjugate(_,u,l),this.transform(_,u,I,m,l,f),this.conjugate(I,m,l),this.normalize13b(I,l),o.negative=s.negative^e.negative,o.length=s.length+e.length,o._strip()},r.prototype.mul=function(s){var e=new r(null);return e.words=new Array(this.length+s.length),this.mulTo(s,e)},r.prototype.mulf=function(s){var e=new r(null);return e.words=new Array(this.length+s.length),J(this,s,e)},r.prototype.imul=function(s){return this.clone().mulTo(s,this)},r.prototype.imuln=function(s){var e=s<0;e&&(s=-s),n(typeof s=="number"),n(s<67108864);for(var o=0,l=0;l<this.length;l++){var f=(this.words[l]|0)*s,m=(f&67108863)+(o&67108863);o>>=26,o+=f/67108864|0,o+=m>>>26,this.words[l]=m&67108863}return o!==0&&(this.words[l]=o,this.length++),this.length=s===0?1:this.length,e?this.ineg():this},r.prototype.muln=function(s){return this.clone().imuln(s)},r.prototype.sqr=function(){return this.mul(this)},r.prototype.isqr=function(){return this.imul(this.clone())},r.prototype.pow=function(s){var e=L(s);if(e.length===0)return new r(1);for(var o=this,l=0;l<e.length&&e[l]===0;l++,o=o.sqr());if(++l<e.length)for(var f=o.sqr();l<e.length;l++,f=f.sqr())e[l]!==0&&(o=o.mul(f));return o},r.prototype.iushln=function(s){n(typeof s=="number"&&s>=0);var e=s%26,o=(s-e)/26,l=67108863>>>26-e<<26-e,f;if(e!==0){var m=0;for(f=0;f<this.length;f++){var w=this.words[f]&l,_=(this.words[f]|0)-w<<e;this.words[f]=_|m,m=w>>>26-e}m&&(this.words[f]=m,this.length++)}if(o!==0){for(f=this.length-1;f>=0;f--)this.words[f+o]=this.words[f];for(f=0;f<o;f++)this.words[f]=0;this.length+=o}return this._strip()},r.prototype.ishln=function(s){return n(this.negative===0),this.iushln(s)},r.prototype.iushrn=function(s,e,o){n(typeof s=="number"&&s>=0);var l;e?l=(e-e%26)/26:l=0;var f=s%26,m=Math.min((s-f)/26,this.length),w=67108863^67108863>>>f<<f,_=o;if(l-=m,l=Math.max(0,l),_){for(var u=0;u<m;u++)_.words[u]=this.words[u];_.length=m}if(m!==0)if(this.length>m)for(this.length-=m,u=0;u<this.length;u++)this.words[u]=this.words[u+m];else this.words[0]=0,this.length=1;var h=0;for(u=this.length-1;u>=0&&(h!==0||u>=l);u--){var b=this.words[u]|0;this.words[u]=h<<26-f|b>>>f,h=b&w}return _&&h!==0&&(_.words[_.length++]=h),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},r.prototype.ishrn=function(s,e,o){return n(this.negative===0),this.iushrn(s,e,o)},r.prototype.shln=function(s){return this.clone().ishln(s)},r.prototype.ushln=function(s){return this.clone().iushln(s)},r.prototype.shrn=function(s){return this.clone().ishrn(s)},r.prototype.ushrn=function(s){return this.clone().iushrn(s)},r.prototype.testn=function(s){n(typeof s=="number"&&s>=0);var e=s%26,o=(s-e)/26,l=1<<e;if(this.length<=o)return!1;var f=this.words[o];return!!(f&l)},r.prototype.imaskn=function(s){n(typeof s=="number"&&s>=0);var e=s%26,o=(s-e)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=o)return this;if(e!==0&&o++,this.length=Math.min(o,this.length),e!==0){var l=67108863^67108863>>>e<<e;this.words[this.length-1]&=l}return this._strip()},r.prototype.maskn=function(s){return this.clone().imaskn(s)},r.prototype.iaddn=function(s){return n(typeof s=="number"),n(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)},r.prototype._iaddn=function(s){this.words[0]+=s;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},r.prototype.isubn=function(s){if(n(typeof s=="number"),n(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 e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this._strip()},r.prototype.addn=function(s){return this.clone().iaddn(s)},r.prototype.subn=function(s){return this.clone().isubn(s)},r.prototype.iabs=function(){return this.negative=0,this},r.prototype.abs=function(){return this.clone().iabs()},r.prototype._ishlnsubmul=function(s,e,o){var l=s.length+o,f;this._expand(l);var m,w=0;for(f=0;f<s.length;f++){m=(this.words[f+o]|0)+w;var _=(s.words[f]|0)*e;m-=_&67108863,w=(m>>26)-(_/67108864|0),this.words[f+o]=m&67108863}for(;f<this.length-o;f++)m=(this.words[f+o]|0)+w,w=m>>26,this.words[f+o]=m&67108863;if(w===0)return this._strip();for(n(w===-1),w=0,f=0;f<this.length;f++)m=-(this.words[f]|0)+w,w=m>>26,this.words[f]=m&67108863;return this.negative=1,this._strip()},r.prototype._wordDiv=function(s,e){var o=this.length-s.length,l=this.clone(),f=s,m=f.words[f.length-1]|0,w=this._countBits(m);o=26-w,o!==0&&(f=f.ushln(o),l.iushln(o),m=f.words[f.length-1]|0);var _=l.length-f.length,u;if(e!=="mod"){u=new r(null),u.length=_+1,u.words=new Array(u.length);for(var h=0;h<u.length;h++)u.words[h]=0}var b=l.clone()._ishlnsubmul(f,1,_);b.negative===0&&(l=b,u&&(u.words[_]=1));for(var T=_-1;T>=0;T--){var I=(l.words[f.length+T]|0)*67108864+(l.words[f.length+T-1]|0);for(I=Math.min(I/m|0,67108863),l._ishlnsubmul(f,I,T);l.negative!==0;)I--,l.negative=0,l._ishlnsubmul(f,1,T),l.isZero()||(l.negative^=1);u&&(u.words[T]=I)}return u&&u._strip(),l._strip(),e!=="div"&&o!==0&&l.iushrn(o),{div:u||null,mod:l}},r.prototype.divmod=function(s,e,o){if(n(!s.isZero()),this.isZero())return{div:new r(0),mod:new r(0)};var l,f,m;return this.negative!==0&&s.negative===0?(m=this.neg().divmod(s,e),e!=="mod"&&(l=m.div.neg()),e!=="div"&&(f=m.mod.neg(),o&&f.negative!==0&&f.iadd(s)),{div:l,mod:f}):this.negative===0&&s.negative!==0?(m=this.divmod(s.neg(),e),e!=="mod"&&(l=m.div.neg()),{div:l,mod:m.mod}):(this.negative&s.negative)!==0?(m=this.neg().divmod(s.neg(),e),e!=="div"&&(f=m.mod.neg(),o&&f.negative!==0&&f.isub(s)),{div:m.div,mod:f}):s.length>this.length||this.cmp(s)<0?{div:new r(0),mod:this}:s.length===1?e==="div"?{div:this.divn(s.words[0]),mod:null}:e==="mod"?{div:null,mod:new r(this.modrn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new r(this.modrn(s.words[0]))}:this._wordDiv(s,e)},r.prototype.div=function(s){return this.divmod(s,"div",!1).div},r.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},r.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},r.prototype.divRound=function(s){var e=this.divmod(s);if(e.mod.isZero())return e.div;var o=e.div.negative!==0?e.mod.isub(s):e.mod,l=s.ushrn(1),f=s.andln(1),m=o.cmp(l);return m<0||f===1&&m===0?e.div:e.div.negative!==0?e.div.isubn(1):e.div.iaddn(1)},r.prototype.modrn=function(s){var e=s<0;e&&(s=-s),n(s<=67108863);for(var o=(1<<26)%s,l=0,f=this.length-1;f>=0;f--)l=(o*l+(this.words[f]|0))%s;return e?-l:l},r.prototype.modn=function(s){return this.modrn(s)},r.prototype.idivn=function(s){var e=s<0;e&&(s=-s),n(s<=67108863);for(var o=0,l=this.length-1;l>=0;l--){var f=(this.words[l]|0)+o*67108864;this.words[l]=f/s|0,o=f%s}return this._strip(),e?this.ineg():this},r.prototype.divn=function(s){return this.clone().idivn(s)},r.prototype.egcd=function(s){n(s.negative===0),n(!s.isZero());var e=this,o=s.clone();e.negative!==0?e=e.umod(s):e=e.clone();for(var l=new r(1),f=new r(0),m=new r(0),w=new r(1),_=0;e.isEven()&&o.isEven();)e.iushrn(1),o.iushrn(1),++_;for(var u=o.clone(),h=e.clone();!e.isZero();){for(var b=0,T=1;(e.words[0]&T)===0&&b<26;++b,T<<=1);if(b>0)for(e.iushrn(b);b-- >0;)(l.isOdd()||f.isOdd())&&(l.iadd(u),f.isub(h)),l.iushrn(1),f.iushrn(1);for(var I=0,F=1;(o.words[0]&F)===0&&I<26;++I,F<<=1);if(I>0)for(o.iushrn(I);I-- >0;)(m.isOdd()||w.isOdd())&&(m.iadd(u),w.isub(h)),m.iushrn(1),w.iushrn(1);e.cmp(o)>=0?(e.isub(o),l.isub(m),f.isub(w)):(o.isub(e),m.isub(l),w.isub(f))}return{a:m,b:w,gcd:o.iushln(_)}},r.prototype._invmp=function(s){n(s.negative===0),n(!s.isZero());var e=this,o=s.clone();e.negative!==0?e=e.umod(s):e=e.clone();for(var l=new r(1),f=new r(0),m=o.clone();e.cmpn(1)>0&&o.cmpn(1)>0;){for(var w=0,_=1;(e.words[0]&_)===0&&w<26;++w,_<<=1);if(w>0)for(e.iushrn(w);w-- >0;)l.isOdd()&&l.iadd(m),l.iushrn(1);for(var u=0,h=1;(o.words[0]&h)===0&&u<26;++u,h<<=1);if(u>0)for(o.iushrn(u);u-- >0;)f.isOdd()&&f.iadd(m),f.iushrn(1);e.cmp(o)>=0?(e.isub(o),l.isub(f)):(o.isub(e),f.isub(l))}var b;return e.cmpn(1)===0?b=l:b=f,b.cmpn(0)<0&&b.iadd(s),b},r.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var e=this.clone(),o=s.clone();e.negative=0,o.negative=0;for(var l=0;e.isEven()&&o.isEven();l++)e.iushrn(1),o.iushrn(1);do{for(;e.isEven();)e.iushrn(1);for(;o.isEven();)o.iushrn(1);var f=e.cmp(o);if(f<0){var m=e;e=o,o=m}else if(f===0||o.cmpn(1)===0)break;e.isub(o)}while(!0);return o.iushln(l)},r.prototype.invm=function(s){return this.egcd(s).a.umod(s)},r.prototype.isEven=function(){return(this.words[0]&1)===0},r.prototype.isOdd=function(){return(this.words[0]&1)===1},r.prototype.andln=function(s){return this.words[0]&s},r.prototype.bincn=function(s){n(typeof s=="number");var e=s%26,o=(s-e)/26,l=1<<e;if(this.length<=o)return this._expand(o+1),this.words[o]|=l,this;for(var f=l,m=o;f!==0&&m<this.length;m++){var w=this.words[m]|0;w+=f,f=w>>>26,w&=67108863,this.words[m]=w}return f!==0&&(this.words[m]=f,this.length++),this},r.prototype.isZero=function(){return this.length===1&&this.words[0]===0},r.prototype.cmpn=function(s){var e=s<0;if(this.negative!==0&&!e)return-1;if(this.negative===0&&e)return 1;this._strip();var o;if(this.length>1)o=1;else{e&&(s=-s),n(s<=67108863,"Number is too big");var l=this.words[0]|0;o=l===s?0:l<s?-1:1}return this.negative!==0?-o|0:o},r.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var e=this.ucmp(s);return this.negative!==0?-e|0:e},r.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var e=0,o=this.length-1;o>=0;o--){var l=this.words[o]|0,f=s.words[o]|0;if(l!==f){l<f?e=-1:l>f&&(e=1);break}}return e},r.prototype.gtn=function(s){return this.cmpn(s)===1},r.prototype.gt=function(s){return this.cmp(s)===1},r.prototype.gten=function(s){return this.cmpn(s)>=0},r.prototype.gte=function(s){return this.cmp(s)>=0},r.prototype.ltn=function(s){return this.cmpn(s)===-1},r.prototype.lt=function(s){return this.cmp(s)===-1},r.prototype.lten=function(s){return this.cmpn(s)<=0},r.prototype.lte=function(s){return this.cmp(s)<=0},r.prototype.eqn=function(s){return this.cmpn(s)===0},r.prototype.eq=function(s){return this.cmp(s)===0},r.red=function(s){return new E(s)},r.prototype.toRed=function(s){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},r.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},r.prototype._forceRed=function(s){return this.red=s,this},r.prototype.forceRed=function(s){return n(!this.red,"Already a number in reduction context"),this._forceRed(s)},r.prototype.redAdd=function(s){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},r.prototype.redIAdd=function(s){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},r.prototype.redSub=function(s){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},r.prototype.redISub=function(s){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},r.prototype.redShl=function(s){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},r.prototype.redMul=function(s){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},r.prototype.redIMul=function(s){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},r.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},r.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},r.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},r.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},r.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},r.prototype.redPow=function(s){return n(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var he={k256:null,p224:null,p192:null,p25519:null};function G(v,s){this.name=v,this.p=new r(s,16),this.n=this.p.bitLength(),this.k=new r(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}G.prototype._tmp=function(){var s=new r(null);return s.words=new Array(Math.ceil(this.n/13)),s},G.prototype.ireduce=function(s){var e=s,o;do this.split(e,this.tmp),e=this.imulK(e),e=e.iadd(this.tmp),o=e.bitLength();while(o>this.n);var l=o<this.n?-1:e.ucmp(this.p);return l===0?(e.words[0]=0,e.length=1):l>0?e.isub(this.p):e.strip!==void 0?e.strip():e._strip(),e},G.prototype.split=function(s,e){s.iushrn(this.n,0,e)},G.prototype.imulK=function(s){return s.imul(this.k)};function Pt(){G.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}a(Pt,G),Pt.prototype.split=function(s,e){for(var o=4194303,l=Math.min(s.length,9),f=0;f<l;f++)e.words[f]=s.words[f];if(e.length=l,s.length<=9){s.words[0]=0,s.length=1;return}var m=s.words[9];for(e.words[e.length++]=m&o,f=10;f<s.length;f++){var w=s.words[f]|0;s.words[f-10]=(w&o)<<4|m>>>22,m=w}m>>>=22,s.words[f-10]=m,m===0&&s.length>10?s.length-=10:s.length-=9},Pt.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var e=0,o=0;o<s.length;o++){var l=s.words[o]|0;e+=l*977,s.words[o]=e&67108863,e=l*64+(e/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function M(){G.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}a(M,G);function x(){G.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}a(x,G);function A(){G.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}a(A,G),A.prototype.imulK=function(s){for(var e=0,o=0;o<s.length;o++){var l=(s.words[o]|0)*19+e,f=l&67108863;l>>>=26,s.words[o]=f,e=l}return e!==0&&(s.words[s.length++]=e),s},r._prime=function(s){if(he[s])return he[s];var e;if(s==="k256")e=new Pt;else if(s==="p224")e=new M;else if(s==="p192")e=new x;else if(s==="p25519")e=new A;else throw new Error("Unknown prime "+s);return he[s]=e,e};function E(v){if(typeof v=="string"){var s=r._prime(v);this.m=s.p,this.prime=s}else n(v.gtn(1),"modulus must be greater than 1"),this.m=v,this.prime=null}E.prototype._verify1=function(s){n(s.negative===0,"red works only with positives"),n(s.red,"red works only with red numbers")},E.prototype._verify2=function(s,e){n((s.negative|e.negative)===0,"red works only with positives"),n(s.red&&s.red===e.red,"red works only with red numbers")},E.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):(y(s,s.umod(this.m)._forceRed(this)),s)},E.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},E.prototype.add=function(s,e){this._verify2(s,e);var o=s.add(e);return o.cmp(this.m)>=0&&o.isub(this.m),o._forceRed(this)},E.prototype.iadd=function(s,e){this._verify2(s,e);var o=s.iadd(e);return o.cmp(this.m)>=0&&o.isub(this.m),o},E.prototype.sub=function(s,e){this._verify2(s,e);var o=s.sub(e);return o.cmpn(0)<0&&o.iadd(this.m),o._forceRed(this)},E.prototype.isub=function(s,e){this._verify2(s,e);var o=s.isub(e);return o.cmpn(0)<0&&o.iadd(this.m),o},E.prototype.shl=function(s,e){return this._verify1(s),this.imod(s.ushln(e))},E.prototype.imul=function(s,e){return this._verify2(s,e),this.imod(s.imul(e))},E.prototype.mul=function(s,e){return this._verify2(s,e),this.imod(s.mul(e))},E.prototype.isqr=function(s){return this.imul(s,s.clone())},E.prototype.sqr=function(s){return this.mul(s,s)},E.prototype.sqrt=function(s){if(s.isZero())return s.clone();var e=this.m.andln(3);if(n(e%2===1),e===3){var o=this.m.add(new r(1)).iushrn(2);return this.pow(s,o)}for(var l=this.m.subn(1),f=0;!l.isZero()&&l.andln(1)===0;)f++,l.iushrn(1);n(!l.isZero());var m=new r(1).toRed(this),w=m.redNeg(),_=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new r(2*u*u).toRed(this);this.pow(u,_).cmp(w)!==0;)u.redIAdd(w);for(var h=this.pow(u,l),b=this.pow(s,l.addn(1).iushrn(1)),T=this.pow(s,l),I=f;T.cmp(m)!==0;){for(var F=T,B=0;F.cmp(m)!==0;B++)F=F.redSqr();n(B<I);var $=this.pow(h,new r(1).iushln(I-B-1));b=b.redMul($),h=$.redSqr(),T=T.redMul(h),I=B}return b},E.prototype.invm=function(s){var e=s._invmp(this.m);return e.negative!==0?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},E.prototype.pow=function(s,e){if(e.isZero())return new r(1).toRed(this);if(e.cmpn(1)===0)return s.clone();var o=4,l=new Array(1<<o);l[0]=new r(1).toRed(this),l[1]=s;for(var f=2;f<l.length;f++)l[f]=this.mul(l[f-1],s);var m=l[0],w=0,_=0,u=e.bitLength()%26;for(u===0&&(u=26),f=e.length-1;f>=0;f--){for(var h=e.words[f],b=u-1;b>=0;b--){var T=h>>b&1;if(m!==l[0]&&(m=this.sqr(m)),T===0&&w===0){_=0;continue}w<<=1,w|=T,_++,!(_!==o&&(f!==0||b!==0))&&(m=this.mul(m,l[w]),_=0,w=0)}u=26}return m},E.prototype.convertTo=function(s){var e=s.umod(this.m);return e===s?e.clone():e},E.prototype.convertFrom=function(s){var e=s.clone();return e.red=null,e},r.mont=function(s){return new S(s)};function S(v){E.call(this,v),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new r(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}a(S,E),S.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},S.prototype.convertFrom=function(s){var e=this.imod(s.mul(this.rinv));return e.red=null,e},S.prototype.imul=function(s,e){if(s.isZero()||e.isZero())return s.words[0]=0,s.length=1,s;var o=s.imul(e),l=o.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),f=o.isub(l).iushrn(this.shift),m=f;return f.cmp(this.m)>=0?m=f.isub(this.m):f.cmpn(0)<0&&(m=f.iadd(this.m)),m._forceRed(this)},S.prototype.mul=function(s,e){if(s.isZero()||e.isZero())return new r(0)._forceRed(this);var o=s.mul(e),l=o.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),f=o.isub(l).iushrn(this.shift),m=f;return f.cmp(this.m)>=0?m=f.isub(this.m):f.cmpn(0)<0&&(m=f.iadd(this.m)),m._forceRed(this)},S.prototype.invm=function(s){var e=this.imod(s._invmp(this.m).mul(this.r2));return e._forceRed(this)}})(typeof mn>"u"||mn,Wn)});var ts={};to(ts,{CetusLeverageSDK:()=>Si,default:()=>Ya,leverage_mainnet:()=>sn});module.exports=eo(ts);var Hr=require("@cetusprotocol/common-sdk");var Ti=require("@cetusprotocol/common-sdk");var sn={full_rpc_url:Ti.FullRpcUrlMainnet,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v2",providers:Ti.DefaultProviders,leverage:{package_id:"0xa1265373a081c3529c303a727118205b6a766843fcefa9ffc6d3463b2a7a3117",published_at:"0xa1265373a081c3529c303a727118205b6a766843fcefa9ffc6d3463b2a7a3117",version:0,config:{global_config_id:"0x248fe11489520df1902cef873fb7c83f055506b4510152450fb6925a4fe587f2",markets_table_id:"0x353e5a81fbc10a8efddb3217dc5200274bc5afc07496f83350b35fd6d715aba5"}},suilend:{lendingMarket:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",ownerCapId:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",ownerCapId:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",isHidden:!0}],lendingMarketId:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lendingMarketType:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",apiUrl:"https://d10td5ybgrf39v.cloudfront.net"}};var Vn=require("@suilend/sdk/client"),Tt=require("@suilend/sdk");var io=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,ln=Math.ceil,xe=Math.floor,ye="[BigNumber Error] ",Dn=ye+"Number primitive has more than 15 significant digits: ",Ae=1e14,tt=14,un=9007199254740991,hn=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Le=1e7,ce=1e9;function Bn(t){var i,n,a,r=O.prototype={constructor:O,toString:null,valueOf:null},d=new O(1),c=20,p=4,g=-7,y=21,k=-1e7,C=1e7,P=!1,N=1,q=0,L={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},K="0123456789abcdefghijklmnopqrstuvwxyz",W=!0;function O(M,x){var A,E,S,v,s,e,o,l,f=this;if(!(f instanceof O))return new O(M,x);if(x==null){if(M&&M._isBigNumber===!0){f.s=M.s,!M.c||M.e>C?f.c=f.e=null:M.e<k?f.c=[f.e=0]:(f.e=M.e,f.c=M.c.slice());return}if((e=typeof M=="number")&&M*0==0){if(f.s=1/M<0?(M=-M,-1):1,M===~~M){for(v=0,s=M;s>=10;s/=10,v++);v>C?f.c=f.e=null:(f.e=v,f.c=[M]);return}l=String(M)}else{if(!io.test(l=String(M)))return a(f,l,e);f.s=l.charCodeAt(0)==45?(l=l.slice(1),-1):1}(v=l.indexOf("."))>-1&&(l=l.replace(".","")),(s=l.search(/e/i))>0?(v<0&&(v=s),v+=+l.slice(s+1),l=l.substring(0,s)):v<0&&(v=l.length)}else{if(ue(x,2,K.length,"Base"),x==10&&W)return f=new O(M),G(f,c+f.e+1,p);if(l=String(M),e=typeof M=="number"){if(M*0!=0)return a(f,l,e,x);if(f.s=1/M<0?(l=l.slice(1),-1):1,O.DEBUG&&l.replace(/^0\.0*|\./,"").length>15)throw Error(Dn+M)}else f.s=l.charCodeAt(0)===45?(l=l.slice(1),-1):1;for(A=K.slice(0,x),v=s=0,o=l.length;s<o;s++)if(A.indexOf(E=l.charAt(s))<0){if(E=="."){if(s>v){v=o;continue}}else if(!S&&(l==l.toUpperCase()&&(l=l.toLowerCase())||l==l.toLowerCase()&&(l=l.toUpperCase()))){S=!0,s=-1,v=0;continue}return a(f,String(M),e,x)}e=!1,l=n(l,x,10,f.s),(v=l.indexOf("."))>-1?l=l.replace(".",""):v=l.length}for(s=0;l.charCodeAt(s)===48;s++);for(o=l.length;l.charCodeAt(--o)===48;);if(l=l.slice(s,++o)){if(o-=s,e&&O.DEBUG&&o>15&&(M>un||M!==xe(M)))throw Error(Dn+f.s*M);if((v=v-s-1)>C)f.c=f.e=null;else if(v<k)f.c=[f.e=0];else{if(f.e=v,f.c=[],s=(v+1)%tt,v<0&&(s+=tt),s<o){for(s&&f.c.push(+l.slice(0,s)),o-=tt;s<o;)f.c.push(+l.slice(s,s+=tt));s=tt-(l=l.slice(s)).length}else s-=o;for(;s--;l+="0");f.c.push(+l)}}else f.c=[f.e=0]}O.clone=Bn,O.ROUND_UP=0,O.ROUND_DOWN=1,O.ROUND_CEIL=2,O.ROUND_FLOOR=3,O.ROUND_HALF_UP=4,O.ROUND_HALF_DOWN=5,O.ROUND_HALF_EVEN=6,O.ROUND_HALF_CEIL=7,O.ROUND_HALF_FLOOR=8,O.EUCLID=9,O.config=O.set=function(M){var x,A;if(M!=null)if(typeof M=="object"){if(M.hasOwnProperty(x="DECIMAL_PLACES")&&(A=M[x],ue(A,0,ce,x),c=A),M.hasOwnProperty(x="ROUNDING_MODE")&&(A=M[x],ue(A,0,8,x),p=A),M.hasOwnProperty(x="EXPONENTIAL_AT")&&(A=M[x],A&&A.pop?(ue(A[0],-ce,0,x),ue(A[1],0,ce,x),g=A[0],y=A[1]):(ue(A,-ce,ce,x),g=-(y=A<0?-A:A))),M.hasOwnProperty(x="RANGE"))if(A=M[x],A&&A.pop)ue(A[0],-ce,-1,x),ue(A[1],1,ce,x),k=A[0],C=A[1];else if(ue(A,-ce,ce,x),A)k=-(C=A<0?-A:A);else throw Error(ye+x+" cannot be zero: "+A);if(M.hasOwnProperty(x="CRYPTO"))if(A=M[x],A===!!A)if(A)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))P=A;else throw P=!A,Error(ye+"crypto unavailable");else P=A;else throw Error(ye+x+" not true or false: "+A);if(M.hasOwnProperty(x="MODULO_MODE")&&(A=M[x],ue(A,0,9,x),N=A),M.hasOwnProperty(x="POW_PRECISION")&&(A=M[x],ue(A,0,ce,x),q=A),M.hasOwnProperty(x="FORMAT"))if(A=M[x],typeof A=="object")L=A;else throw Error(ye+x+" not an object: "+A);if(M.hasOwnProperty(x="ALPHABET"))if(A=M[x],typeof A=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(A))W=A.slice(0,10)=="0123456789",K=A;else throw Error(ye+x+" invalid: "+A)}else throw Error(ye+"Object expected: "+M);return{DECIMAL_PLACES:c,ROUNDING_MODE:p,EXPONENTIAL_AT:[g,y],RANGE:[k,C],CRYPTO:P,MODULO_MODE:N,POW_PRECISION:q,FORMAT:L,ALPHABET:K}},O.isBigNumber=function(M){if(!M||M._isBigNumber!==!0)return!1;if(!O.DEBUG)return!0;var x,A,E=M.c,S=M.e,v=M.s;t:if({}.toString.call(E)=="[object Array]"){if((v===1||v===-1)&&S>=-ce&&S<=ce&&S===xe(S)){if(E[0]===0){if(S===0&&E.length===1)return!0;break t}if(x=(S+1)%tt,x<1&&(x+=tt),String(E[0]).length==x){for(x=0;x<E.length;x++)if(A=E[x],A<0||A>=Ae||A!==xe(A))break t;if(A!==0)return!0}}}else if(E===null&&S===null&&(v===null||v===1||v===-1))return!0;throw Error(ye+"Invalid BigNumber: "+M)},O.maximum=O.max=function(){return vt(arguments,-1)},O.minimum=O.min=function(){return vt(arguments,1)},O.random=(function(){var M=9007199254740992,x=Math.random()*M&2097151?function(){return xe(Math.random()*M)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(A){var E,S,v,s,e,o=0,l=[],f=new O(d);if(A==null?A=c:ue(A,0,ce),s=ln(A/tt),P)if(crypto.getRandomValues){for(E=crypto.getRandomValues(new Uint32Array(s*=2));o<s;)e=E[o]*131072+(E[o+1]>>>11),e>=9e15?(S=crypto.getRandomValues(new Uint32Array(2)),E[o]=S[0],E[o+1]=S[1]):(l.push(e%1e14),o+=2);o=s/2}else if(crypto.randomBytes){for(E=crypto.randomBytes(s*=7);o<s;)e=(E[o]&31)*281474976710656+E[o+1]*1099511627776+E[o+2]*4294967296+E[o+3]*16777216+(E[o+4]<<16)+(E[o+5]<<8)+E[o+6],e>=9e15?crypto.randomBytes(7).copy(E,o):(l.push(e%1e14),o+=7);o=s/7}else throw P=!1,Error(ye+"crypto unavailable");if(!P)for(;o<s;)e=x(),e<9e15&&(l[o++]=e%1e14);for(s=l[--o],A%=tt,s&&A&&(e=hn[tt-A],l[o]=xe(s/e)*e);l[o]===0;l.pop(),o--);if(o<0)l=[v=0];else{for(v=-1;l[0]===0;l.splice(0,1),v-=tt);for(o=1,e=l[0];e>=10;e/=10,o++);o<tt&&(v-=tt-o)}return f.e=v,f.c=l,f}})(),O.sum=function(){for(var M=1,x=arguments,A=new O(x[0]);M<x.length;)A=A.plus(x[M++]);return A},n=(function(){var M="0123456789";function x(A,E,S,v){for(var s,e=[0],o,l=0,f=A.length;l<f;){for(o=e.length;o--;e[o]*=E);for(e[0]+=v.indexOf(A.charAt(l++)),s=0;s<e.length;s++)e[s]>S-1&&(e[s+1]==null&&(e[s+1]=0),e[s+1]+=e[s]/S|0,e[s]%=S)}return e.reverse()}return function(A,E,S,v,s){var e,o,l,f,m,w,_,u,h=A.indexOf("."),b=c,T=p;for(h>=0&&(f=q,q=0,A=A.replace(".",""),u=new O(E),w=u.pow(A.length-h),q=f,u.c=x(Re(ke(w.c),w.e,"0"),10,S,M),u.e=u.c.length),_=x(A,E,S,s?(e=K,M):(e=M,K)),l=f=_.length;_[--f]==0;_.pop());if(!_[0])return e.charAt(0);if(h<0?--l:(w.c=_,w.e=l,w.s=v,w=i(w,u,b,T,S),_=w.c,m=w.r,l=w.e),o=l+b+1,h=_[o],f=S/2,m=m||o<0||_[o+1]!=null,m=T<4?(h!=null||m)&&(T==0||T==(w.s<0?3:2)):h>f||h==f&&(T==4||m||T==6&&_[o-1]&1||T==(w.s<0?8:7)),o<1||!_[0])A=m?Re(e.charAt(1),-b,e.charAt(0)):e.charAt(0);else{if(_.length=o,m)for(--S;++_[--o]>S;)_[o]=0,o||(++l,_=[1].concat(_));for(f=_.length;!_[--f];);for(h=0,A="";h<=f;A+=e.charAt(_[h++]));A=Re(A,l,e.charAt(0))}return A}})(),i=(function(){function M(E,S,v){var s,e,o,l,f=0,m=E.length,w=S%Le,_=S/Le|0;for(E=E.slice();m--;)o=E[m]%Le,l=E[m]/Le|0,s=_*o+l*w,e=w*o+s%Le*Le+f,f=(e/v|0)+(s/Le|0)+_*l,E[m]=e%v;return f&&(E=[f].concat(E)),E}function x(E,S,v,s){var e,o;if(v!=s)o=v>s?1:-1;else for(e=o=0;e<v;e++)if(E[e]!=S[e]){o=E[e]>S[e]?1:-1;break}return o}function A(E,S,v,s){for(var e=0;v--;)E[v]-=e,e=E[v]<S[v]?1:0,E[v]=e*s+E[v]-S[v];for(;!E[0]&&E.length>1;E.splice(0,1));}return function(E,S,v,s,e){var o,l,f,m,w,_,u,h,b,T,I,F,B,$,yt,Q,z,wt=E.s==S.s?1:-1,bt=E.c,U=S.c;if(!bt||!bt[0]||!U||!U[0])return new O(!E.s||!S.s||(bt?U&&bt[0]==U[0]:!U)?NaN:bt&&bt[0]==0||!U?wt*0:wt/0);for(h=new O(wt),b=h.c=[],l=E.e-S.e,wt=v+l+1,e||(e=Ae,l=Ce(E.e/tt)-Ce(S.e/tt),wt=wt/tt|0),f=0;U[f]==(bt[f]||0);f++);if(U[f]>(bt[f]||0)&&l--,wt<0)b.push(1),m=!0;else{for($=bt.length,Q=U.length,f=0,wt+=2,w=xe(e/(U[0]+1)),w>1&&(U=M(U,w,e),bt=M(bt,w,e),Q=U.length,$=bt.length),B=Q,T=bt.slice(0,Q),I=T.length;I<Q;T[I++]=0);z=U.slice(),z=[0].concat(z),yt=U[0],U[1]>=e/2&&yt++;do{if(w=0,o=x(U,T,Q,I),o<0){if(F=T[0],Q!=I&&(F=F*e+(T[1]||0)),w=xe(F/yt),w>1)for(w>=e&&(w=e-1),_=M(U,w,e),u=_.length,I=T.length;x(_,T,u,I)==1;)w--,A(_,Q<u?z:U,u,e),u=_.length,o=1;else w==0&&(o=w=1),_=U.slice(),u=_.length;if(u<I&&(_=[0].concat(_)),A(T,_,I,e),I=T.length,o==-1)for(;x(U,T,Q,I)<1;)w++,A(T,Q<I?z:U,I,e),I=T.length}else o===0&&(w++,T=[0]);b[f++]=w,T[0]?T[I++]=bt[B]||0:(T=[bt[B]],I=1)}while((B++<$||T[0]!=null)&&wt--);m=T[0]!=null,b[0]||b.splice(0,1)}if(e==Ae){for(f=1,wt=b[0];wt>=10;wt/=10,f++);G(h,v+(h.e=f+l*tt-1)+1,s,m)}else h.e=l,h.r=+m;return h}})();function J(M,x,A,E){var S,v,s,e,o;if(A==null?A=p:ue(A,0,8),!M.c)return M.toString();if(S=M.c[0],s=M.e,x==null)o=ke(M.c),o=E==1||E==2&&(s<=g||s>=y)?Oi(o,s):Re(o,s,"0");else if(M=G(new O(M),x,A),v=M.e,o=ke(M.c),e=o.length,E==1||E==2&&(x<=v||v<=g)){for(;e<x;o+="0",e++);o=Oi(o,v)}else if(x-=s+(E===2&&v>s),o=Re(o,v,"0"),v+1>e){if(--x>0)for(o+=".";x--;o+="0");}else if(x+=v-e,x>0)for(v+1==e&&(o+=".");x--;o+="0");return M.s<0&&S?"-"+o:o}function vt(M,x){for(var A,E,S=1,v=new O(M[0]);S<M.length;S++)E=new O(M[S]),(!E.s||(A=hi(v,E))===x||A===0&&v.s===x)&&(v=E);return v}function he(M,x,A){for(var E=1,S=x.length;!x[--S];x.pop());for(S=x[0];S>=10;S/=10,E++);return(A=E+A*tt-1)>C?M.c=M.e=null:A<k?M.c=[M.e=0]:(M.e=A,M.c=x),M}a=(function(){var M=/^(-?)0([xbo])(?=\w[\w.]*$)/i,x=/^([^.]+)\.$/,A=/^\.([^.]+)$/,E=/^-?(Infinity|NaN)$/,S=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(v,s,e,o){var l,f=e?s:s.replace(S,"");if(E.test(f))v.s=isNaN(f)?null:f<0?-1:1;else{if(!e&&(f=f.replace(M,function(m,w,_){return l=(_=_.toLowerCase())=="x"?16:_=="b"?2:8,!o||o==l?w:m}),o&&(l=o,f=f.replace(x,"$1").replace(A,"0.$1")),s!=f))return new O(f,l);if(O.DEBUG)throw Error(ye+"Not a"+(o?" base "+o:"")+" number: "+s);v.s=null}v.c=v.e=null}})();function G(M,x,A,E){var S,v,s,e,o,l,f,m=M.c,w=hn;if(m){t:{for(S=1,e=m[0];e>=10;e/=10,S++);if(v=x-S,v<0)v+=tt,s=x,o=m[l=0],f=xe(o/w[S-s-1]%10);else if(l=ln((v+1)/tt),l>=m.length)if(E){for(;m.length<=l;m.push(0));o=f=0,S=1,v%=tt,s=v-tt+1}else break t;else{for(o=e=m[l],S=1;e>=10;e/=10,S++);v%=tt,s=v-tt+S,f=s<0?0:xe(o/w[S-s-1]%10)}if(E=E||x<0||m[l+1]!=null||(s<0?o:o%w[S-s-1]),E=A<4?(f||E)&&(A==0||A==(M.s<0?3:2)):f>5||f==5&&(A==4||E||A==6&&(v>0?s>0?o/w[S-s]:0:m[l-1])%10&1||A==(M.s<0?8:7)),x<1||!m[0])return m.length=0,E?(x-=M.e+1,m[0]=w[(tt-x%tt)%tt],M.e=-x||0):m[0]=M.e=0,M;if(v==0?(m.length=l,e=1,l--):(m.length=l+1,e=w[tt-v],m[l]=s>0?xe(o/w[S-s]%w[s])*e:0),E)for(;;)if(l==0){for(v=1,s=m[0];s>=10;s/=10,v++);for(s=m[0]+=e,e=1;s>=10;s/=10,e++);v!=e&&(M.e++,m[0]==Ae&&(m[0]=1));break}else{if(m[l]+=e,m[l]!=Ae)break;m[l--]=0,e=1}for(v=m.length;m[--v]===0;m.pop());}M.e>C?M.c=M.e=null:M.e<k&&(M.c=[M.e=0])}return M}function Pt(M){var x,A=M.e;return A===null?M.toString():(x=ke(M.c),x=A<=g||A>=y?Oi(x,A):Re(x,A,"0"),M.s<0?"-"+x:x)}return r.absoluteValue=r.abs=function(){var M=new O(this);return M.s<0&&(M.s=1),M},r.comparedTo=function(M,x){return hi(this,new O(M,x))},r.decimalPlaces=r.dp=function(M,x){var A,E,S,v=this;if(M!=null)return ue(M,0,ce),x==null?x=p:ue(x,0,8),G(new O(v),M+v.e+1,x);if(!(A=v.c))return null;if(E=((S=A.length-1)-Ce(this.e/tt))*tt,S=A[S])for(;S%10==0;S/=10,E--);return E<0&&(E=0),E},r.dividedBy=r.div=function(M,x){return i(this,new O(M,x),c,p)},r.dividedToIntegerBy=r.idiv=function(M,x){return i(this,new O(M,x),0,1)},r.exponentiatedBy=r.pow=function(M,x){var A,E,S,v,s,e,o,l,f,m=this;if(M=new O(M),M.c&&!M.isInteger())throw Error(ye+"Exponent not an integer: "+Pt(M));if(x!=null&&(x=new O(x)),e=M.e>14,!m.c||!m.c[0]||m.c[0]==1&&!m.e&&m.c.length==1||!M.c||!M.c[0])return f=new O(Math.pow(+Pt(m),e?M.s*(2-Ii(M)):+Pt(M))),x?f.mod(x):f;if(o=M.s<0,x){if(x.c?!x.c[0]:!x.s)return new O(NaN);E=!o&&m.isInteger()&&x.isInteger(),E&&(m=m.mod(x))}else{if(M.e>9&&(m.e>0||m.e<-1||(m.e==0?m.c[0]>1||e&&m.c[1]>=24e7:m.c[0]<8e13||e&&m.c[0]<=9999975e7)))return v=m.s<0&&Ii(M)?-0:0,m.e>-1&&(v=1/v),new O(o?1/v:v);q&&(v=ln(q/tt+2))}for(e?(A=new O(.5),o&&(M.s=1),l=Ii(M)):(S=Math.abs(+Pt(M)),l=S%2),f=new O(d);;){if(l){if(f=f.times(m),!f.c)break;v?f.c.length>v&&(f.c.length=v):E&&(f=f.mod(x))}if(S){if(S=xe(S/2),S===0)break;l=S%2}else if(M=M.times(A),G(M,M.e+1,1),M.e>14)l=Ii(M);else{if(S=+Pt(M),S===0)break;l=S%2}m=m.times(m),v?m.c&&m.c.length>v&&(m.c.length=v):E&&(m=m.mod(x))}return E?f:(o&&(f=d.div(f)),x?f.mod(x):v?G(f,q,p,s):f)},r.integerValue=function(M){var x=new O(this);return M==null?M=p:ue(M,0,8),G(x,x.e+1,M)},r.isEqualTo=r.eq=function(M,x){return hi(this,new O(M,x))===0},r.isFinite=function(){return!!this.c},r.isGreaterThan=r.gt=function(M,x){return hi(this,new O(M,x))>0},r.isGreaterThanOrEqualTo=r.gte=function(M,x){return(x=hi(this,new O(M,x)))===1||x===0},r.isInteger=function(){return!!this.c&&Ce(this.e/tt)>this.c.length-2},r.isLessThan=r.lt=function(M,x){return hi(this,new O(M,x))<0},r.isLessThanOrEqualTo=r.lte=function(M,x){return(x=hi(this,new O(M,x)))===-1||x===0},r.isNaN=function(){return!this.s},r.isNegative=function(){return this.s<0},r.isPositive=function(){return this.s>0},r.isZero=function(){return!!this.c&&this.c[0]==0},r.minus=function(M,x){var A,E,S,v,s=this,e=s.s;if(M=new O(M,x),x=M.s,!e||!x)return new O(NaN);if(e!=x)return M.s=-x,s.plus(M);var o=s.e/tt,l=M.e/tt,f=s.c,m=M.c;if(!o||!l){if(!f||!m)return f?(M.s=-x,M):new O(m?s:NaN);if(!f[0]||!m[0])return m[0]?(M.s=-x,M):new O(f[0]?s:p==3?-0:0)}if(o=Ce(o),l=Ce(l),f=f.slice(),e=o-l){for((v=e<0)?(e=-e,S=f):(l=o,S=m),S.reverse(),x=e;x--;S.push(0));S.reverse()}else for(E=(v=(e=f.length)<(x=m.length))?e:x,e=x=0;x<E;x++)if(f[x]!=m[x]){v=f[x]<m[x];break}if(v&&(S=f,f=m,m=S,M.s=-M.s),x=(E=m.length)-(A=f.length),x>0)for(;x--;f[A++]=0);for(x=Ae-1;E>e;){if(f[--E]<m[E]){for(A=E;A&&!f[--A];f[A]=x);--f[A],f[E]+=Ae}f[E]-=m[E]}for(;f[0]==0;f.splice(0,1),--l);return f[0]?he(M,f,l):(M.s=p==3?-1:1,M.c=[M.e=0],M)},r.modulo=r.mod=function(M,x){var A,E,S=this;return M=new O(M,x),!S.c||!M.s||M.c&&!M.c[0]?new O(NaN):!M.c||S.c&&!S.c[0]?new O(S):(N==9?(E=M.s,M.s=1,A=i(S,M,0,3),M.s=E,A.s*=E):A=i(S,M,0,N),M=S.minus(A.times(M)),!M.c[0]&&N==1&&(M.s=S.s),M)},r.multipliedBy=r.times=function(M,x){var A,E,S,v,s,e,o,l,f,m,w,_,u,h,b,T=this,I=T.c,F=(M=new O(M,x)).c;if(!I||!F||!I[0]||!F[0])return!T.s||!M.s||I&&!I[0]&&!F||F&&!F[0]&&!I?M.c=M.e=M.s=null:(M.s*=T.s,!I||!F?M.c=M.e=null:(M.c=[0],M.e=0)),M;for(E=Ce(T.e/tt)+Ce(M.e/tt),M.s*=T.s,o=I.length,m=F.length,o<m&&(u=I,I=F,F=u,S=o,o=m,m=S),S=o+m,u=[];S--;u.push(0));for(h=Ae,b=Le,S=m;--S>=0;){for(A=0,w=F[S]%b,_=F[S]/b|0,s=o,v=S+s;v>S;)l=I[--s]%b,f=I[s]/b|0,e=_*l+f*w,l=w*l+e%b*b+u[v]+A,A=(l/h|0)+(e/b|0)+_*f,u[v--]=l%h;u[v]=A}return A?++E:u.splice(0,1),he(M,u,E)},r.negated=function(){var M=new O(this);return M.s=-M.s||null,M},r.plus=function(M,x){var A,E=this,S=E.s;if(M=new O(M,x),x=M.s,!S||!x)return new O(NaN);if(S!=x)return M.s=-x,E.minus(M);var v=E.e/tt,s=M.e/tt,e=E.c,o=M.c;if(!v||!s){if(!e||!o)return new O(S/0);if(!e[0]||!o[0])return o[0]?M:new O(e[0]?E:S*0)}if(v=Ce(v),s=Ce(s),e=e.slice(),S=v-s){for(S>0?(s=v,A=o):(S=-S,A=e),A.reverse();S--;A.push(0));A.reverse()}for(S=e.length,x=o.length,S-x<0&&(A=o,o=e,e=A,x=S),S=0;x;)S=(e[--x]=e[x]+o[x]+S)/Ae|0,e[x]=Ae===e[x]?0:e[x]%Ae;return S&&(e=[S].concat(e),++s),he(M,e,s)},r.precision=r.sd=function(M,x){var A,E,S,v=this;if(M!=null&&M!==!!M)return ue(M,1,ce),x==null?x=p:ue(x,0,8),G(new O(v),M,x);if(!(A=v.c))return null;if(S=A.length-1,E=S*tt+1,S=A[S]){for(;S%10==0;S/=10,E--);for(S=A[0];S>=10;S/=10,E++);}return M&&v.e+1>E&&(E=v.e+1),E},r.shiftedBy=function(M){return ue(M,-un,un),this.times("1e"+M)},r.squareRoot=r.sqrt=function(){var M,x,A,E,S,v=this,s=v.c,e=v.s,o=v.e,l=c+4,f=new O("0.5");if(e!==1||!s||!s[0])return new O(!e||e<0&&(!s||s[0])?NaN:s?v:1/0);if(e=Math.sqrt(+Pt(v)),e==0||e==1/0?(x=ke(s),(x.length+o)%2==0&&(x+="0"),e=Math.sqrt(+x),o=Ce((o+1)/2)-(o<0||o%2),e==1/0?x="5e"+o:(x=e.toExponential(),x=x.slice(0,x.indexOf("e")+1)+o),A=new O(x)):A=new O(e+""),A.c[0]){for(o=A.e,e=o+l,e<3&&(e=0);;)if(S=A,A=f.times(S.plus(i(v,S,l,1))),ke(S.c).slice(0,e)===(x=ke(A.c)).slice(0,e))if(A.e<o&&--e,x=x.slice(e-3,e+1),x=="9999"||!E&&x=="4999"){if(!E&&(G(S,S.e+c+2,0),S.times(S).eq(v))){A=S;break}l+=4,e+=4,E=1}else{(!+x||!+x.slice(1)&&x.charAt(0)=="5")&&(G(A,A.e+c+2,1),M=!A.times(A).eq(v));break}}return G(A,A.e+c+1,p,M)},r.toExponential=function(M,x){return M!=null&&(ue(M,0,ce),M++),J(this,M,x,1)},r.toFixed=function(M,x){return M!=null&&(ue(M,0,ce),M=M+this.e+1),J(this,M,x)},r.toFormat=function(M,x,A){var E,S=this;if(A==null)M!=null&&x&&typeof x=="object"?(A=x,x=null):M&&typeof M=="object"?(A=M,M=x=null):A=L;else if(typeof A!="object")throw Error(ye+"Argument not an object: "+A);if(E=S.toFixed(M,x),S.c){var v,s=E.split("."),e=+A.groupSize,o=+A.secondaryGroupSize,l=A.groupSeparator||"",f=s[0],m=s[1],w=S.s<0,_=w?f.slice(1):f,u=_.length;if(o&&(v=e,e=o,o=v,u-=v),e>0&&u>0){for(v=u%e||e,f=_.substr(0,v);v<u;v+=e)f+=l+_.substr(v,e);o>0&&(f+=l+_.slice(v)),w&&(f="-"+f)}E=m?f+(A.decimalSeparator||"")+((o=+A.fractionGroupSize)?m.replace(new RegExp("\\d{"+o+"}\\B","g"),"$&"+(A.fractionGroupSeparator||"")):m):f}return(A.prefix||"")+E+(A.suffix||"")},r.toFraction=function(M){var x,A,E,S,v,s,e,o,l,f,m,w,_=this,u=_.c;if(M!=null&&(e=new O(M),!e.isInteger()&&(e.c||e.s!==1)||e.lt(d)))throw Error(ye+"Argument "+(e.isInteger()?"out of range: ":"not an integer: ")+Pt(e));if(!u)return new O(_);for(x=new O(d),l=A=new O(d),E=o=new O(d),w=ke(u),v=x.e=w.length-_.e-1,x.c[0]=hn[(s=v%tt)<0?tt+s:s],M=!M||e.comparedTo(x)>0?v>0?x:l:e,s=C,C=1/0,e=new O(w),o.c[0]=0;f=i(e,x,0,1),S=A.plus(f.times(E)),S.comparedTo(M)!=1;)A=E,E=S,l=o.plus(f.times(S=l)),o=S,x=e.minus(f.times(S=x)),e=S;return S=i(M.minus(A),E,0,1),o=o.plus(S.times(l)),A=A.plus(S.times(E)),o.s=l.s=_.s,v=v*2,m=i(l,E,v,p).minus(_).abs().comparedTo(i(o,A,v,p).minus(_).abs())<1?[l,E]:[o,A],C=s,m},r.toNumber=function(){return+Pt(this)},r.toPrecision=function(M,x){return M!=null&&ue(M,1,ce),J(this,M,x,2)},r.toString=function(M){var x,A=this,E=A.s,S=A.e;return S===null?E?(x="Infinity",E<0&&(x="-"+x)):x="NaN":(M==null?x=S<=g||S>=y?Oi(ke(A.c),S):Re(ke(A.c),S,"0"):M===10&&W?(A=G(new O(A),c+S+1,p),x=Re(ke(A.c),A.e,"0")):(ue(M,2,K.length,"Base"),x=n(Re(ke(A.c),S,"0"),10,M,E,!0)),E<0&&A.c[0]&&(x="-"+x)),x},r.valueOf=r.toJSON=function(){return Pt(this)},r._isBigNumber=!0,r[Symbol.toStringTag]="BigNumber",r[Symbol.for("nodejs.util.inspect.custom")]=r.valueOf,t!=null&&O.set(t),O}function Ce(t){var i=t|0;return t>0||t===i?i:i-1}function ke(t){for(var i,n,a=1,r=t.length,d=t[0]+"";a<r;){for(i=t[a++]+"",n=tt-i.length;n--;i="0"+i);d+=i}for(r=d.length;d.charCodeAt(--r)===48;);return d.slice(0,r+1||1)}function hi(t,i){var n,a,r=t.c,d=i.c,c=t.s,p=i.s,g=t.e,y=i.e;if(!c||!p)return null;if(n=r&&!r[0],a=d&&!d[0],n||a)return n?a?0:-p:c;if(c!=p)return c;if(n=c<0,a=g==y,!r||!d)return a?0:!r^n?1:-1;if(!a)return g>y^n?1:-1;for(p=(g=r.length)<(y=d.length)?g:y,c=0;c<p;c++)if(r[c]!=d[c])return r[c]>d[c]^n?1:-1;return g==y?0:g>y^n?1:-1}function ue(t,i,n,a){if(t<i||t>n||t!==xe(t))throw Error(ye+(a||"Argument")+(typeof t=="number"?t<i||t>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function Ii(t){var i=t.c.length-1;return Ce(t.e/tt)==i&&t.c[i]%2!=0}function Oi(t,i){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(i<0?"e":"e+")+i}function Re(t,i,n){var a,r;if(i<0){for(r=n+".";++i;r+=n);t=r+t}else if(a=t.length,++i>a){for(r=n,i-=a;--i;r+=n);t+=r}else i<a&&(t=t.slice(0,i)+"."+t.slice(i));return t}var no=Bn(),Ee=no;var Te=require("@suilend/sdk"),fi=require("@suilend/sui-fe");var qn=an(require("crypto")),Fi=new Uint8Array(256),Ni=Fi.length;function dn(){return Ni>Fi.length-16&&(qn.default.randomFillSync(Fi),Ni=0),Fi.slice(Ni,Ni+=16)}var pe=[];for(let t=0;t<256;++t)pe.push((t+256).toString(16).slice(1));function jn(t,i=0){return pe[t[i+0]]+pe[t[i+1]]+pe[t[i+2]]+pe[t[i+3]]+"-"+pe[t[i+4]]+pe[t[i+5]]+"-"+pe[t[i+6]]+pe[t[i+7]]+"-"+pe[t[i+8]]+pe[t[i+9]]+"-"+pe[t[i+10]]+pe[t[i+11]]+pe[t[i+12]]+pe[t[i+13]]+pe[t[i+14]]+pe[t[i+15]]}var Ln=an(require("crypto")),cn={randomUUID:Ln.default.randomUUID};function ro(t,i,n){if(cn.randomUUID&&!i&&!t)return cn.randomUUID();t=t||{};let a=t.random||(t.rng||dn)();if(a[6]=a[6]&15|64,a[8]=a[8]&63|128,i){n=n||0;for(let r=0;r<16;++r)i[n+r]=a[r];return i}return jn(a)}var Ri=ro;function $n(t){return t.depositedAmount.eq(0)?new Ee(0):t.borrowedAmount.div(t.depositedAmount).times(100)}function fn(t){let i=$n(t);if(!i.gt(100))return(0,Te.linearlyInterpolate)(t.config.interestRate,"utilPercent","aprPercent",i)}function Un(t){let i=$n(t),n=fn(t);if(!(n===void 0||i.gt(100)))return new Ee(i.div(100)).times(n.div(100)).times(1-t.config.spreadFeeBps/1e4).times(100)}function zn(t,i,n,a){t===Te.Side.DEPOSIT&&([fi.NORMALIZED_flSUI_COINTYPE,fi.NORMALIZED_jugSUI_COINTYPE].includes(i.coinType)&&n.push({stats:{id:Ri(),isActive:!0,rewardIndex:-1,reserve:i,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${a.sdkOptions?.suilend?.apiUrl}/partners/LiqAg.png`,perDay:new Ee(.036),side:Te.Side.DEPOSIT},obligationClaims:{}}),i.coinType===fi.NORMALIZED_LBTC_COINTYPE&&n.push({stats:{id:Ri(),isActive:!0,rewardIndex:-1,reserve:i,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${a.sdkOptions?.suilend?.apiUrl}/partners/Lombard Lux.png`,perDay:new Ee(0),side:Te.Side.DEPOSIT},obligationClaims:{}}))}function Zn(t,i,n){return{...t,depositedAmount:i===Te.Side.DEPOSIT?Ee.max(t.depositedAmount.plus(n),0):t.depositedAmount,borrowedAmount:i===Te.Side.BORROW?Ee.max(t.borrowedAmount.plus(n),0):t.borrowedAmount}}function Hn(t,i,n){let a=t===Te.Side.DEPOSIT?i.depositedAmount:i.borrowedAmount,r=t===Te.Side.DEPOSIT?n.depositedAmount:n.borrowedAmount,d=r.eq(0)?new Ee(-1):a.div(r);return{multiplier:d,isValid:!d.eq(-1)}}function Kn(t,i,n,a){let r=t.map(c=>({...c,stats:{...c.stats,perDay:a?c.stats.perDay.times(n):void 0}})),d=i.map(c=>({...c,stats:{...c.stats,aprPercent:a?c.stats.aprPercent.times(n):void 0}}));return{newPerDayRewards:r,newAprRewards:d}}var pn=require("@cetusprotocol/common-sdk"),Di=class{constructor(i){this.getSuiLendCoinInfo=(i,n)=>{let{allLendingMarketData:a,lstAprPercentMap:r}=this.lendingMarketCache??{};if(!a||!r)throw new Error("lendingMarketCache is not initialized");let d=Object.values(a??{})[0],c=d.lendingMarket.reserves.find(Pt=>Pt.coinType===i);if(!c)throw new Error("reserve not found");let p=this.obligationsCache?.[d.lendingMarket.id],g="borrow",y=p.rewardMap[c.token.coinType]?.[g]??[],k=(0,Tt.getFilteredRewards)(y);zn(g,c,k,this.sdk);let C=(0,Tt.getStakingYieldAprPercent)(g,c.coinType,r),P=g===Tt.Side.DEPOSIT?c.depositAprPercent:c.borrowAprPercent,N=P,q=Zn(c,g,n);N=g===Tt.Side.DEPOSIT?Un(q):fn(q);let{multiplier:L,isValid:K}=Hn(g,c,q),W=(0,Tt.getDedupedPerDayRewards)(k),O=(0,Tt.getDedupedAprRewards)(k),{newPerDayRewards:J,newAprRewards:vt}=Kn(W,O,L,K),he=(0,Tt.getTotalAprPercent)(g,P,k,C),G=N===void 0||vt.some(Pt=>Pt.stats.aprPercent===void 0)?void 0:(0,Tt.getTotalAprPercent)(g,N,vt,C);return{borrowLimit:c.config.borrowLimit.toString(),borrowedAmount:c.borrowedAmount.toString(),remainingBorrowLimit:(0,pn.d)(c.config.borrowLimit.toString()).sub((0,pn.d)(c.borrowedAmount.toString())).toString(),depositAprPercent:c.depositAprPercent.toString(),totalAprPercent:he.toString(),borrowInterest:P.toString(),stakingYieldAprPercent:C?.toString(),rewardAprPercent:O[0]?.stats.aprPercent?.toString()}};this.createObligation=async i=>{let{lendingMarketId:n,lendingMarketType:a}=this.sdk.sdkOptions?.suilend;return(await this.getSuilendClient(n,a)).createObligation(i)};this.sdk=i}async getSuilendClient(i,n){let a=`${i}_${n}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[a]||(this.suilendClientCache[a]=await Vn.SuilendClient.initialize(i,n,this.sdk.FullClient,!0)),this.suilendClientCache[a]}async getLendingMarketData(i=!1){if(!i&&this.lendingMarketCache)return this.lendingMarketCache;let n=this.sdk.sdkOptions?.suilend?.lendingMarket||[];if(!n.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[a,r]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(n.map(async c=>{let p=await this.getSuilendClient(c.id,c.type),{lendingMarket:g,coinMetadataMap:y,refreshedRawReserves:k,reserveMap:C,reserveCoinTypes:P,reserveCoinMetadataMap:N,rewardCoinTypes:q,activeRewardCoinTypes:L,rewardCoinMetadataMap:K}=await(0,Tt.initializeSuilend)(this.sdk.FullClient,p),{rewardPriceMap:W}=await(0,Tt.initializeSuilendRewards)(C,L);return[c.id,{suilendClient:p,lendingMarket:g,coinMetadataMap:y,refreshedRawReserves:k,reserveMap:C,reserveCoinTypes:P,reserveCoinMetadataMap:N,rewardPriceMap:W,rewardCoinTypes:q,activeRewardCoinTypes:L,rewardCoinMetadataMap:K}]}))))(),(async()=>{try{let d=await fetch(`${this.sdk.sdkOptions?.suilend?.apiUrl}/springsui/apy`),c=await d.json();if(d?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(c).map(([p,g])=>[p,new Ee(g)]))}catch(d){return console.error(d),{}}})()]);return this.lendingMarketCache={allLendingMarketData:a,lstAprPercentMap:r},this.lendingMarketCache}catch(a){throw console.log("\u{1F680} getLendingMarketData error:",a),a}}async getInitializeObligations(i,n=!1){if(!n&&this.obligationsCache)return this.obligationsCache;i||(i=await this.getLendingMarketData());let a={};for(let r of Object.values(i.allLendingMarketData)){let{obligationOwnerCaps:d,obligations:c}=await(0,Tt.initializeObligations)(this.sdk.FullClient,r.suilendClient,r.refreshedRawReserves,r.reserveMap,this.sdk.senderAddress),p=(0,Tt.formatRewards)(r.reserveMap,r.rewardCoinMetadataMap,r.rewardPriceMap,c);a[r.lendingMarket.id]={obligationOwnerCaps:d,obligations:c,rewardMap:p}}return this.obligationsCache=a,this.obligationsCache}async getSuiLendUserData(i,n=!1){let{lstAprPercentMap:a}=this.lendingMarketCache??{},r=this.obligationsCache??{},d=this.sdk.sdkOptions?.suilend?.lendingMarketId,c=r[d];if(!c)throw new Error(`No user data found for lending market: ${d}`);if(i){let p=c.obligations.find(y=>y.id===i);if(!p)throw new Error(`Obligation not found: ${i}`);let g=(0,Tt.getNetAprPercent)(p,c.rewardMap,a??{});return{obligation:p,netAprPercent:g,deposits:p.deposits,borrowedAmount:p.borrowedAmount,depositedAmount:p.depositedAmount,netValueUsd:p.netValueUsd,rewardMap:c.rewardMap}}}};var be=require("@cetusprotocol/common-sdk"),_n=an(Gn()),Jn=require("@mysten/sui/dist/cjs/transactions"),Bi=class{constructor(i){this.getLeverageConfig=async()=>{let i=(0,be.getPackagerConfigs)(this._sdk.sdkOptions.leverage);return(await this._sdk.FullClient.getObject({id:i.global_config_id,options:{showContent:!0}})).data.content.fields};this.getLeverageMarketsList=async(i=!1)=>{let n="leverage_markets_list",a=this._sdk.getCache(n,i);if(a)return a;let r=(0,be.getPackagerConfigs)(this._sdk.sdkOptions.leverage),d=await this._sdk.FullClient.getObject({id:r.markets_table_id,options:{showContent:!0}}),c=null,p=50,g=[];for(;;){let y=await this._sdk.FullClient.getDynamicFields({parentId:d.data.content.fields.list.fields.id.id,limit:p,cursor:c});if(g.push(...y.data),y.data.length<p)break;c=y.nextCursor}return this._sdk.updateCache(n,g,be.CACHE_TIME_5MIN),g};this.getLeverageMarketInfo=async i=>{let n=`leverage_market_info_${i}`,a=this._sdk.getCache(n);if(a)return a;let r=await this._sdk.FullClient.getObject({id:i,options:{showContent:!0}})};this.openShort=async i=>{let{isQuote:n,marketId:a,amount:r,clmmPool:d,slippage:c}=i,{leverage:p}=this._sdk.sdkOptions,g="0x2::sui::SUI",y="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",k=new Jn.Transaction;if(!n){let C=await this.findRouters(g,y,r,!0,[d]),P=be.CoinAssist.buildCoinWithBalance(BigInt(r.toString()),g,k),N=await this._sdk.AggregatorClient.routerSwap({routers:C.route_obj,byAmountIn:!0,inputCoin:P,slippage:c,txb:k}),{balanceA:q,balanceB:L,receipt:K}=this.flashSwap({amount:r,clmmPool:d,baseCoinType:g,quoteCoinType:y,tx:k})}};this.flashSwap=i=>{let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:a}=(0,be.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:r,clmmPool:d,baseCoinType:c,quoteCoinType:p,tx:g}=i,y=(0,be.getDefaultSqrtPriceLimit)(!0).toString(),[k,C,P]=g.moveCall({target:`${n.published_at}::pool::flash_swap`,arguments:[g.object(a),g.object(d),g.pure.bool(!0),g.pure.bool(!0),g.pure.u64(r.toString()),g.pure.u128(y),g.object(be.CLOCK_ADDRESS)],typeArguments:[c,p]});return{balanceA:k,balanceB:C,receipt:P}};this.repayFlashSwap=i=>{let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:a}=(0,be.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{clmmPool:r,coinA:d,coinB:c,tx:p,baseCoinType:g,quoteCoinType:y}=i;p.moveCall({target:`${n.published_at}::pool::repay_flash_swap`,arguments:[p.object(a),p.object(r),p.object(d),p.object(c),p.object(be.CLOCK_ADDRESS)],typeArguments:[g,y]})};this._sdk=i}async findRouters(i,n,a,r,d){let{providers:c}=this._sdk.sdkOptions;try{let p={from:i,target:n,amount:new _n.default(a.toFixed(0).toString()),byAmountIn:r,depth:3,providers:c},g=await this._sdk.AggregatorClient.findRouters(p);if(g?.error?.code===10001)return{...g,is_exceed:g.insufficientLiquidity};if(g?.insufficientLiquidity)return{...g,is_exceed:g.insufficientLiquidity};if(!g?.routes||g?.routes?.length===0)throw Error("Aggregator no router");return{amount_in:g.amountIn.toString(),amount_out:g.amountOut.toString(),is_exceed:g.insufficientLiquidity,route_obj:g,byAmountIn:!0,originRes:g}}catch{try{if(d){let g=await this._sdk.AggregatorClient.swapInPools({from:i,target:n,amount:new _n.default(a.toFixed(0).toString()),byAmountIn:r,pools:d});return g?{amount_in:g.routeData.amountIn.toString(),amount_out:g.routeData.amountOut.toString(),is_exceed:g.isExceed,route_obj:g.routeData,byAmountIn:!0,originRes:g}:null}return null}catch{return null}}}};var Pi=require("@cetusprotocol/aggregator-sdk"),Kr=require("@mysten/sui/utils"),Vr=require("@mysten/sui/client");var lr=require("@cetusprotocol/common-sdk"),$i=require("@mysten/sui/utils"),Z=require("@cetusprotocol/common-sdk"),Mr=require("@cetusprotocol/common-sdk"),xr=require("@mysten/sui/client"),mi=require("@mysten/sui/transactions"),di=require("@mysten/sui/utils"),Mt=require("@cetusprotocol/common-sdk"),zi=require("@mysten/sui/transactions"),kt=require("@cetusprotocol/common-sdk"),Zi=require("@mysten/sui/transactions"),xt=require("@cetusprotocol/common-sdk"),X=require("@cetusprotocol/common-sdk"),D=require("@cetusprotocol/common-sdk"),ge=require("@cetusprotocol/common-sdk"),qr=require("@mysten/sui/client"),Ie=require("@mysten/sui/transactions"),nn=require("@mysten/sui/utils"),j=require("@cetusprotocol/common-sdk"),Vi=require("@mysten/sui/transactions"),jr=require("@mysten/sui/utils"),Ct=require("@cetusprotocol/common-sdk"),En=require("@mysten/sui/transactions"),Tn=require("@mysten/sui/utils"),St=require("@cetusprotocol/common-sdk"),we=require("@cetusprotocol/common-sdk"),In=require("@mysten/sui/transactions"),Lr=require("@mysten/sui/utils"),$r=require("@cetusprotocol/common-sdk"),Ur=require("@cetusprotocol/common-sdk"),Zr=require("@cetusprotocol/common-sdk"),oo=Object.create,sr=Object.defineProperty,ao=Object.getOwnPropertyDescriptor,so=Object.getOwnPropertyNames,lo=Object.getPrototypeOf,uo=Object.prototype.hasOwnProperty,ho=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(i,n)=>(typeof require<"u"?require:i)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')}),co=(t,i)=>()=>(i||t((i={exports:{}}).exports,i),i.exports),fo=(t,i,n,a)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of so(i))!uo.call(t,r)&&r!==n&&sr(t,r,{get:()=>i[r],enumerable:!(a=ao(i,r))||a.enumerable});return t},qe=(t,i,n)=>(n=t!=null?oo(lo(t)):{},fo(i||!t||!t.__esModule?sr(n,"default",{value:t,enumerable:!0}):n,t)),je=co((t,i)=>{"use strict";(function(n,a){"use strict";function r(e,o){if(!e)throw new Error(o||"Assertion failed")}function d(e,o){e.super_=o;var l=function(){};l.prototype=o.prototype,e.prototype=new l,e.prototype.constructor=e}function c(e,o,l){if(c.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,e!==null&&((o==="le"||o==="be")&&(l=o,o=10),this._init(e||0,o||10,l||"be"))}typeof n=="object"?n.exports=c:a.BN=c,c.BN=c,c.wordSize=26;var p;try{typeof window<"u"&&typeof window.Buffer<"u"?p=window.Buffer:p=ho("buffer").Buffer}catch{}c.isBN=function(e){return e instanceof c?!0:e!==null&&typeof e=="object"&&e.constructor.wordSize===c.wordSize&&Array.isArray(e.words)},c.max=function(e,o){return e.cmp(o)>0?e:o},c.min=function(e,o){return e.cmp(o)<0?e:o},c.prototype._init=function(e,o,l){if(typeof e=="number")return this._initNumber(e,o,l);if(typeof e=="object")return this._initArray(e,o,l);o==="hex"&&(o=16),r(o===(o|0)&&o>=2&&o<=36),e=e.toString().replace(/\s+/g,"");var f=0;e[0]==="-"&&(f++,this.negative=1),f<e.length&&(o===16?this._parseHex(e,f,l):(this._parseBase(e,o,f),l==="le"&&this._initArray(this.toArray(),o,l)))},c.prototype._initNumber=function(e,o,l){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[e&67108863],this.length=1):e<4503599627370496?(this.words=[e&67108863,e/67108864&67108863],this.length=2):(r(e<9007199254740992),this.words=[e&67108863,e/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),o,l)},c.prototype._initArray=function(e,o,l){if(r(typeof e.length=="number"),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var m,w,_=0;if(l==="be")for(f=e.length-1,m=0;f>=0;f-=3)w=e[f]|e[f-1]<<8|e[f-2]<<16,this.words[m]|=w<<_&67108863,this.words[m+1]=w>>>26-_&67108863,_+=24,_>=26&&(_-=26,m++);else if(l==="le")for(f=0,m=0;f<e.length;f+=3)w=e[f]|e[f+1]<<8|e[f+2]<<16,this.words[m]|=w<<_&67108863,this.words[m+1]=w>>>26-_&67108863,_+=24,_>=26&&(_-=26,m++);return this._strip()};function g(e,o){var l=e.charCodeAt(o);if(l>=48&&l<=57)return l-48;if(l>=65&&l<=70)return l-55;if(l>=97&&l<=102)return l-87;r(!1,"Invalid character in "+e)}function y(e,o,l){var f=g(e,l);return l-1>=o&&(f|=g(e,l-1)<<4),f}c.prototype._parseHex=function(e,o,l){this.length=Math.ceil((e.length-o)/6),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var m=0,w=0,_;if(l==="be")for(f=e.length-1;f>=o;f-=2)_=y(e,o,f)<<m,this.words[w]|=_&67108863,m>=18?(m-=18,w+=1,this.words[w]|=_>>>26):m+=8;else{var u=e.length-o;for(f=u%2===0?o+1:o;f<e.length;f+=2)_=y(e,o,f)<<m,this.words[w]|=_&67108863,m>=18?(m-=18,w+=1,this.words[w]|=_>>>26):m+=8}this._strip()};function k(e,o,l,f){for(var m=0,w=0,_=Math.min(e.length,l),u=o;u<_;u++){var h=e.charCodeAt(u)-48;m*=f,h>=49?w=h-49+10:h>=17?w=h-17+10:w=h,r(h>=0&&w<f,"Invalid character"),m+=w}return m}c.prototype._parseBase=function(e,o,l){this.words=[0],this.length=1;for(var f=0,m=1;m<=67108863;m*=o)f++;f--,m=m/o|0;for(var w=e.length-l,_=w%f,u=Math.min(w,w-_)+l,h=0,b=l;b<u;b+=f)h=k(e,b,b+f,o),this.imuln(m),this.words[0]+h<67108864?this.words[0]+=h:this._iaddn(h);if(_!==0){var T=1;for(h=k(e,b,e.length,o),b=0;b<_;b++)T*=o;this.imuln(T),this.words[0]+h<67108864?this.words[0]+=h:this._iaddn(h)}this._strip()},c.prototype.copy=function(e){e.words=new Array(this.length);for(var o=0;o<this.length;o++)e.words[o]=this.words[o];e.length=this.length,e.negative=this.negative,e.red=this.red};function C(e,o){e.words=o.words,e.length=o.length,e.negative=o.negative,e.red=o.red}if(c.prototype._move=function(e){C(e,this)},c.prototype.clone=function(){var e=new c(null);return this.copy(e),e},c.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},c.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},c.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{c.prototype[Symbol.for("nodejs.util.inspect.custom")]=P}catch{c.prototype.inspect=P}else c.prototype.inspect=P;function P(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var N=["","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"],q=[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],L=[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];c.prototype.toString=function(e,o){e=e||10,o=o|0||1;var l;if(e===16||e==="hex"){l="";for(var f=0,m=0,w=0;w<this.length;w++){var _=this.words[w],u=((_<<f|m)&16777215).toString(16);m=_>>>24-f&16777215,f+=2,f>=26&&(f-=26,w--),m!==0||w!==this.length-1?l=N[6-u.length]+u+l:l=u+l}for(m!==0&&(l=m.toString(16)+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(e===(e|0)&&e>=2&&e<=36){var h=q[e],b=L[e];l="";var T=this.clone();for(T.negative=0;!T.isZero();){var I=T.modrn(b).toString(e);T=T.idivn(b),T.isZero()?l=I+l:l=N[h-I.length]+I+l}for(this.isZero()&&(l="0"+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}r(!1,"Base should be between 2 and 36")},c.prototype.toNumber=function(){var e=this.words[0];return this.length===2?e+=this.words[1]*67108864:this.length===3&&this.words[2]===1?e+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-e:e},c.prototype.toJSON=function(){return this.toString(16,2)},p&&(c.prototype.toBuffer=function(e,o){return this.toArrayLike(p,e,o)}),c.prototype.toArray=function(e,o){return this.toArrayLike(Array,e,o)};var K=function(e,o){return e.allocUnsafe?e.allocUnsafe(o):new e(o)};c.prototype.toArrayLike=function(e,o,l){this._strip();var f=this.byteLength(),m=l||Math.max(1,f);r(f<=m,"byte array longer than desired length"),r(m>0,"Requested array length <= 0");var w=K(e,m),_=o==="le"?"LE":"BE";return this["_toArrayLike"+_](w,f),w},c.prototype._toArrayLikeLE=function(e,o){for(var l=0,f=0,m=0,w=0;m<this.length;m++){var _=this.words[m]<<w|f;e[l++]=_&255,l<e.length&&(e[l++]=_>>8&255),l<e.length&&(e[l++]=_>>16&255),w===6?(l<e.length&&(e[l++]=_>>24&255),f=0,w=0):(f=_>>>24,w+=2)}if(l<e.length)for(e[l++]=f;l<e.length;)e[l++]=0},c.prototype._toArrayLikeBE=function(e,o){for(var l=e.length-1,f=0,m=0,w=0;m<this.length;m++){var _=this.words[m]<<w|f;e[l--]=_&255,l>=0&&(e[l--]=_>>8&255),l>=0&&(e[l--]=_>>16&255),w===6?(l>=0&&(e[l--]=_>>24&255),f=0,w=0):(f=_>>>24,w+=2)}if(l>=0)for(e[l--]=f;l>=0;)e[l--]=0},Math.clz32?c.prototype._countBits=function(e){return 32-Math.clz32(e)}:c.prototype._countBits=function(e){var o=e,l=0;return o>=4096&&(l+=13,o>>>=13),o>=64&&(l+=7,o>>>=7),o>=8&&(l+=4,o>>>=4),o>=2&&(l+=2,o>>>=2),l+o},c.prototype._zeroBits=function(e){if(e===0)return 26;var o=e,l=0;return(o&8191)===0&&(l+=13,o>>>=13),(o&127)===0&&(l+=7,o>>>=7),(o&15)===0&&(l+=4,o>>>=4),(o&3)===0&&(l+=2,o>>>=2),(o&1)===0&&l++,l},c.prototype.bitLength=function(){var e=this.words[this.length-1],o=this._countBits(e);return(this.length-1)*26+o};function W(e){for(var o=new Array(e.bitLength()),l=0;l<o.length;l++){var f=l/26|0,m=l%26;o[l]=e.words[f]>>>m&1}return o}c.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,o=0;o<this.length;o++){var l=this._zeroBits(this.words[o]);if(e+=l,l!==26)break}return e},c.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},c.prototype.toTwos=function(e){return this.negative!==0?this.abs().inotn(e).iaddn(1):this.clone()},c.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},c.prototype.isNeg=function(){return this.negative!==0},c.prototype.neg=function(){return this.clone().ineg()},c.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},c.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var o=0;o<e.length;o++)this.words[o]=this.words[o]|e.words[o];return this._strip()},c.prototype.ior=function(e){return r((this.negative|e.negative)===0),this.iuor(e)},c.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},c.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},c.prototype.iuand=function(e){var o;this.length>e.length?o=e:o=this;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]&e.words[l];return this.length=o.length,this._strip()},c.prototype.iand=function(e){return r((this.negative|e.negative)===0),this.iuand(e)},c.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},c.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},c.prototype.iuxor=function(e){var o,l;this.length>e.length?(o=this,l=e):(o=e,l=this);for(var f=0;f<l.length;f++)this.words[f]=o.words[f]^l.words[f];if(this!==o)for(;f<o.length;f++)this.words[f]=o.words[f];return this.length=o.length,this._strip()},c.prototype.ixor=function(e){return r((this.negative|e.negative)===0),this.iuxor(e)},c.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},c.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},c.prototype.inotn=function(e){r(typeof e=="number"&&e>=0);var o=Math.ceil(e/26)|0,l=e%26;this._expand(o),l>0&&o--;for(var f=0;f<o;f++)this.words[f]=~this.words[f]&67108863;return l>0&&(this.words[f]=~this.words[f]&67108863>>26-l),this._strip()},c.prototype.notn=function(e){return this.clone().inotn(e)},c.prototype.setn=function(e,o){r(typeof e=="number"&&e>=0);var l=e/26|0,f=e%26;return this._expand(l+1),o?this.words[l]=this.words[l]|1<<f:this.words[l]=this.words[l]&~(1<<f),this._strip()},c.prototype.iadd=function(e){var o;if(this.negative!==0&&e.negative===0)return this.negative=0,o=this.isub(e),this.negative^=1,this._normSign();if(this.negative===0&&e.negative!==0)return e.negative=0,o=this.isub(e),e.negative=1,o._normSign();var l,f;this.length>e.length?(l=this,f=e):(l=e,f=this);for(var m=0,w=0;w<f.length;w++)o=(l.words[w]|0)+(f.words[w]|0)+m,this.words[w]=o&67108863,m=o>>>26;for(;m!==0&&w<l.length;w++)o=(l.words[w]|0)+m,this.words[w]=o&67108863,m=o>>>26;if(this.length=l.length,m!==0)this.words[this.length]=m,this.length++;else if(l!==this)for(;w<l.length;w++)this.words[w]=l.words[w];return this},c.prototype.add=function(e){var o;return e.negative!==0&&this.negative===0?(e.negative=0,o=this.sub(e),e.negative^=1,o):e.negative===0&&this.negative!==0?(this.negative=0,o=e.sub(this),this.negative=1,o):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},c.prototype.isub=function(e){if(e.negative!==0){e.negative=0;var o=this.iadd(e);return e.negative=1,o._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var l=this.cmp(e);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var f,m;l>0?(f=this,m=e):(f=e,m=this);for(var w=0,_=0;_<m.length;_++)o=(f.words[_]|0)-(m.words[_]|0)+w,w=o>>26,this.words[_]=o&67108863;for(;w!==0&&_<f.length;_++)o=(f.words[_]|0)+w,w=o>>26,this.words[_]=o&67108863;if(w===0&&_<f.length&&f!==this)for(;_<f.length;_++)this.words[_]=f.words[_];return this.length=Math.max(this.length,_),f!==this&&(this.negative=1),this._strip()},c.prototype.sub=function(e){return this.clone().isub(e)};function O(e,o,l){l.negative=o.negative^e.negative;var f=e.length+o.length|0;l.length=f,f=f-1|0;var m=e.words[0]|0,w=o.words[0]|0,_=m*w,u=_&67108863,h=_/67108864|0;l.words[0]=u;for(var b=1;b<f;b++){for(var T=h>>>26,I=h&67108863,F=Math.min(b,o.length-1),B=Math.max(0,b-e.length+1);B<=F;B++){var $=b-B|0;m=e.words[$]|0,w=o.words[B]|0,_=m*w+I,T+=_/67108864|0,I=_&67108863}l.words[b]=I|0,h=T|0}return h!==0?l.words[b]=h|0:l.length--,l._strip()}var J=function(e,o,l){var f=e.words,m=o.words,w=l.words,_=0,u,h,b,T=f[0]|0,I=T&8191,F=T>>>13,B=f[1]|0,$=B&8191,yt=B>>>13,Q=f[2]|0,z=Q&8191,wt=Q>>>13,bt=f[3]|0,U=bt&8191,It=bt>>>13,Ot=f[4]|0,it=Ot&8191,Nt=Ot>>>13,Ft=f[5]|0,nt=Ft&8191,Rt=Ft>>>13,Dt=f[6]|0,rt=Dt&8191,Bt=Dt>>>13,qt=f[7]|0,ot=qt&8191,jt=qt>>>13,Lt=f[8]|0,at=Lt&8191,$t=Lt>>>13,Ut=f[9]|0,st=Ut&8191,zt=Ut>>>13,Zt=m[0]|0,lt=Zt&8191,Ht=Zt>>>13,Kt=m[1]|0,ut=Kt&8191,Vt=Kt>>>13,Wt=m[2]|0,ht=Wt&8191,Gt=Wt>>>13,Jt=m[3]|0,dt=Jt&8191,Xt=Jt>>>13,Qt=m[4]|0,ct=Qt&8191,Yt=Qt>>>13,te=m[5]|0,ft=te&8191,ee=te>>>13,ie=m[6]|0,pt=ie&8191,ne=ie>>>13,re=m[7]|0,mt=re&8191,oe=re>>>13,ae=m[8]|0,_t=ae&8191,se=ae>>>13,le=m[9]|0,gt=le&8191,Et=le>>>13;l.negative=e.negative^o.negative,l.length=19,u=Math.imul(I,lt),h=Math.imul(I,Ht),h=h+Math.imul(F,lt)|0,b=Math.imul(F,Ht);var Ke=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(Ke>>>26)|0,Ke&=67108863,u=Math.imul($,lt),h=Math.imul($,Ht),h=h+Math.imul(yt,lt)|0,b=Math.imul(yt,Ht),u=u+Math.imul(I,ut)|0,h=h+Math.imul(I,Vt)|0,h=h+Math.imul(F,ut)|0,b=b+Math.imul(F,Vt)|0;var Ve=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(Ve>>>26)|0,Ve&=67108863,u=Math.imul(z,lt),h=Math.imul(z,Ht),h=h+Math.imul(wt,lt)|0,b=Math.imul(wt,Ht),u=u+Math.imul($,ut)|0,h=h+Math.imul($,Vt)|0,h=h+Math.imul(yt,ut)|0,b=b+Math.imul(yt,Vt)|0,u=u+Math.imul(I,ht)|0,h=h+Math.imul(I,Gt)|0,h=h+Math.imul(F,ht)|0,b=b+Math.imul(F,Gt)|0;var We=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(We>>>26)|0,We&=67108863,u=Math.imul(U,lt),h=Math.imul(U,Ht),h=h+Math.imul(It,lt)|0,b=Math.imul(It,Ht),u=u+Math.imul(z,ut)|0,h=h+Math.imul(z,Vt)|0,h=h+Math.imul(wt,ut)|0,b=b+Math.imul(wt,Vt)|0,u=u+Math.imul($,ht)|0,h=h+Math.imul($,Gt)|0,h=h+Math.imul(yt,ht)|0,b=b+Math.imul(yt,Gt)|0,u=u+Math.imul(I,dt)|0,h=h+Math.imul(I,Xt)|0,h=h+Math.imul(F,dt)|0,b=b+Math.imul(F,Xt)|0;var Ge=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(Ge>>>26)|0,Ge&=67108863,u=Math.imul(it,lt),h=Math.imul(it,Ht),h=h+Math.imul(Nt,lt)|0,b=Math.imul(Nt,Ht),u=u+Math.imul(U,ut)|0,h=h+Math.imul(U,Vt)|0,h=h+Math.imul(It,ut)|0,b=b+Math.imul(It,Vt)|0,u=u+Math.imul(z,ht)|0,h=h+Math.imul(z,Gt)|0,h=h+Math.imul(wt,ht)|0,b=b+Math.imul(wt,Gt)|0,u=u+Math.imul($,dt)|0,h=h+Math.imul($,Xt)|0,h=h+Math.imul(yt,dt)|0,b=b+Math.imul(yt,Xt)|0,u=u+Math.imul(I,ct)|0,h=h+Math.imul(I,Yt)|0,h=h+Math.imul(F,ct)|0,b=b+Math.imul(F,Yt)|0;var Je=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(Je>>>26)|0,Je&=67108863,u=Math.imul(nt,lt),h=Math.imul(nt,Ht),h=h+Math.imul(Rt,lt)|0,b=Math.imul(Rt,Ht),u=u+Math.imul(it,ut)|0,h=h+Math.imul(it,Vt)|0,h=h+Math.imul(Nt,ut)|0,b=b+Math.imul(Nt,Vt)|0,u=u+Math.imul(U,ht)|0,h=h+Math.imul(U,Gt)|0,h=h+Math.imul(It,ht)|0,b=b+Math.imul(It,Gt)|0,u=u+Math.imul(z,dt)|0,h=h+Math.imul(z,Xt)|0,h=h+Math.imul(wt,dt)|0,b=b+Math.imul(wt,Xt)|0,u=u+Math.imul($,ct)|0,h=h+Math.imul($,Yt)|0,h=h+Math.imul(yt,ct)|0,b=b+Math.imul(yt,Yt)|0,u=u+Math.imul(I,ft)|0,h=h+Math.imul(I,ee)|0,h=h+Math.imul(F,ft)|0,b=b+Math.imul(F,ee)|0;var Xe=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(Xe>>>26)|0,Xe&=67108863,u=Math.imul(rt,lt),h=Math.imul(rt,Ht),h=h+Math.imul(Bt,lt)|0,b=Math.imul(Bt,Ht),u=u+Math.imul(nt,ut)|0,h=h+Math.imul(nt,Vt)|0,h=h+Math.imul(Rt,ut)|0,b=b+Math.imul(Rt,Vt)|0,u=u+Math.imul(it,ht)|0,h=h+Math.imul(it,Gt)|0,h=h+Math.imul(Nt,ht)|0,b=b+Math.imul(Nt,Gt)|0,u=u+Math.imul(U,dt)|0,h=h+Math.imul(U,Xt)|0,h=h+Math.imul(It,dt)|0,b=b+Math.imul(It,Xt)|0,u=u+Math.imul(z,ct)|0,h=h+Math.imul(z,Yt)|0,h=h+Math.imul(wt,ct)|0,b=b+Math.imul(wt,Yt)|0,u=u+Math.imul($,ft)|0,h=h+Math.imul($,ee)|0,h=h+Math.imul(yt,ft)|0,b=b+Math.imul(yt,ee)|0,u=u+Math.imul(I,pt)|0,h=h+Math.imul(I,ne)|0,h=h+Math.imul(F,pt)|0,b=b+Math.imul(F,ne)|0;var Qe=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(Qe>>>26)|0,Qe&=67108863,u=Math.imul(ot,lt),h=Math.imul(ot,Ht),h=h+Math.imul(jt,lt)|0,b=Math.imul(jt,Ht),u=u+Math.imul(rt,ut)|0,h=h+Math.imul(rt,Vt)|0,h=h+Math.imul(Bt,ut)|0,b=b+Math.imul(Bt,Vt)|0,u=u+Math.imul(nt,ht)|0,h=h+Math.imul(nt,Gt)|0,h=h+Math.imul(Rt,ht)|0,b=b+Math.imul(Rt,Gt)|0,u=u+Math.imul(it,dt)|0,h=h+Math.imul(it,Xt)|0,h=h+Math.imul(Nt,dt)|0,b=b+Math.imul(Nt,Xt)|0,u=u+Math.imul(U,ct)|0,h=h+Math.imul(U,Yt)|0,h=h+Math.imul(It,ct)|0,b=b+Math.imul(It,Yt)|0,u=u+Math.imul(z,ft)|0,h=h+Math.imul(z,ee)|0,h=h+Math.imul(wt,ft)|0,b=b+Math.imul(wt,ee)|0,u=u+Math.imul($,pt)|0,h=h+Math.imul($,ne)|0,h=h+Math.imul(yt,pt)|0,b=b+Math.imul(yt,ne)|0,u=u+Math.imul(I,mt)|0,h=h+Math.imul(I,oe)|0,h=h+Math.imul(F,mt)|0,b=b+Math.imul(F,oe)|0;var Ye=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,u=Math.imul(at,lt),h=Math.imul(at,Ht),h=h+Math.imul($t,lt)|0,b=Math.imul($t,Ht),u=u+Math.imul(ot,ut)|0,h=h+Math.imul(ot,Vt)|0,h=h+Math.imul(jt,ut)|0,b=b+Math.imul(jt,Vt)|0,u=u+Math.imul(rt,ht)|0,h=h+Math.imul(rt,Gt)|0,h=h+Math.imul(Bt,ht)|0,b=b+Math.imul(Bt,Gt)|0,u=u+Math.imul(nt,dt)|0,h=h+Math.imul(nt,Xt)|0,h=h+Math.imul(Rt,dt)|0,b=b+Math.imul(Rt,Xt)|0,u=u+Math.imul(it,ct)|0,h=h+Math.imul(it,Yt)|0,h=h+Math.imul(Nt,ct)|0,b=b+Math.imul(Nt,Yt)|0,u=u+Math.imul(U,ft)|0,h=h+Math.imul(U,ee)|0,h=h+Math.imul(It,ft)|0,b=b+Math.imul(It,ee)|0,u=u+Math.imul(z,pt)|0,h=h+Math.imul(z,ne)|0,h=h+Math.imul(wt,pt)|0,b=b+Math.imul(wt,ne)|0,u=u+Math.imul($,mt)|0,h=h+Math.imul($,oe)|0,h=h+Math.imul(yt,mt)|0,b=b+Math.imul(yt,oe)|0,u=u+Math.imul(I,_t)|0,h=h+Math.imul(I,se)|0,h=h+Math.imul(F,_t)|0,b=b+Math.imul(F,se)|0;var ti=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(ti>>>26)|0,ti&=67108863,u=Math.imul(st,lt),h=Math.imul(st,Ht),h=h+Math.imul(zt,lt)|0,b=Math.imul(zt,Ht),u=u+Math.imul(at,ut)|0,h=h+Math.imul(at,Vt)|0,h=h+Math.imul($t,ut)|0,b=b+Math.imul($t,Vt)|0,u=u+Math.imul(ot,ht)|0,h=h+Math.imul(ot,Gt)|0,h=h+Math.imul(jt,ht)|0,b=b+Math.imul(jt,Gt)|0,u=u+Math.imul(rt,dt)|0,h=h+Math.imul(rt,Xt)|0,h=h+Math.imul(Bt,dt)|0,b=b+Math.imul(Bt,Xt)|0,u=u+Math.imul(nt,ct)|0,h=h+Math.imul(nt,Yt)|0,h=h+Math.imul(Rt,ct)|0,b=b+Math.imul(Rt,Yt)|0,u=u+Math.imul(it,ft)|0,h=h+Math.imul(it,ee)|0,h=h+Math.imul(Nt,ft)|0,b=b+Math.imul(Nt,ee)|0,u=u+Math.imul(U,pt)|0,h=h+Math.imul(U,ne)|0,h=h+Math.imul(It,pt)|0,b=b+Math.imul(It,ne)|0,u=u+Math.imul(z,mt)|0,h=h+Math.imul(z,oe)|0,h=h+Math.imul(wt,mt)|0,b=b+Math.imul(wt,oe)|0,u=u+Math.imul($,_t)|0,h=h+Math.imul($,se)|0,h=h+Math.imul(yt,_t)|0,b=b+Math.imul(yt,se)|0,u=u+Math.imul(I,gt)|0,h=h+Math.imul(I,Et)|0,h=h+Math.imul(F,gt)|0,b=b+Math.imul(F,Et)|0;var ei=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(ei>>>26)|0,ei&=67108863,u=Math.imul(st,ut),h=Math.imul(st,Vt),h=h+Math.imul(zt,ut)|0,b=Math.imul(zt,Vt),u=u+Math.imul(at,ht)|0,h=h+Math.imul(at,Gt)|0,h=h+Math.imul($t,ht)|0,b=b+Math.imul($t,Gt)|0,u=u+Math.imul(ot,dt)|0,h=h+Math.imul(ot,Xt)|0,h=h+Math.imul(jt,dt)|0,b=b+Math.imul(jt,Xt)|0,u=u+Math.imul(rt,ct)|0,h=h+Math.imul(rt,Yt)|0,h=h+Math.imul(Bt,ct)|0,b=b+Math.imul(Bt,Yt)|0,u=u+Math.imul(nt,ft)|0,h=h+Math.imul(nt,ee)|0,h=h+Math.imul(Rt,ft)|0,b=b+Math.imul(Rt,ee)|0,u=u+Math.imul(it,pt)|0,h=h+Math.imul(it,ne)|0,h=h+Math.imul(Nt,pt)|0,b=b+Math.imul(Nt,ne)|0,u=u+Math.imul(U,mt)|0,h=h+Math.imul(U,oe)|0,h=h+Math.imul(It,mt)|0,b=b+Math.imul(It,oe)|0,u=u+Math.imul(z,_t)|0,h=h+Math.imul(z,se)|0,h=h+Math.imul(wt,_t)|0,b=b+Math.imul(wt,se)|0,u=u+Math.imul($,gt)|0,h=h+Math.imul($,Et)|0,h=h+Math.imul(yt,gt)|0,b=b+Math.imul(yt,Et)|0;var ii=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(ii>>>26)|0,ii&=67108863,u=Math.imul(st,ht),h=Math.imul(st,Gt),h=h+Math.imul(zt,ht)|0,b=Math.imul(zt,Gt),u=u+Math.imul(at,dt)|0,h=h+Math.imul(at,Xt)|0,h=h+Math.imul($t,dt)|0,b=b+Math.imul($t,Xt)|0,u=u+Math.imul(ot,ct)|0,h=h+Math.imul(ot,Yt)|0,h=h+Math.imul(jt,ct)|0,b=b+Math.imul(jt,Yt)|0,u=u+Math.imul(rt,ft)|0,h=h+Math.imul(rt,ee)|0,h=h+Math.imul(Bt,ft)|0,b=b+Math.imul(Bt,ee)|0,u=u+Math.imul(nt,pt)|0,h=h+Math.imul(nt,ne)|0,h=h+Math.imul(Rt,pt)|0,b=b+Math.imul(Rt,ne)|0,u=u+Math.imul(it,mt)|0,h=h+Math.imul(it,oe)|0,h=h+Math.imul(Nt,mt)|0,b=b+Math.imul(Nt,oe)|0,u=u+Math.imul(U,_t)|0,h=h+Math.imul(U,se)|0,h=h+Math.imul(It,_t)|0,b=b+Math.imul(It,se)|0,u=u+Math.imul(z,gt)|0,h=h+Math.imul(z,Et)|0,h=h+Math.imul(wt,gt)|0,b=b+Math.imul(wt,Et)|0;var ni=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(ni>>>26)|0,ni&=67108863,u=Math.imul(st,dt),h=Math.imul(st,Xt),h=h+Math.imul(zt,dt)|0,b=Math.imul(zt,Xt),u=u+Math.imul(at,ct)|0,h=h+Math.imul(at,Yt)|0,h=h+Math.imul($t,ct)|0,b=b+Math.imul($t,Yt)|0,u=u+Math.imul(ot,ft)|0,h=h+Math.imul(ot,ee)|0,h=h+Math.imul(jt,ft)|0,b=b+Math.imul(jt,ee)|0,u=u+Math.imul(rt,pt)|0,h=h+Math.imul(rt,ne)|0,h=h+Math.imul(Bt,pt)|0,b=b+Math.imul(Bt,ne)|0,u=u+Math.imul(nt,mt)|0,h=h+Math.imul(nt,oe)|0,h=h+Math.imul(Rt,mt)|0,b=b+Math.imul(Rt,oe)|0,u=u+Math.imul(it,_t)|0,h=h+Math.imul(it,se)|0,h=h+Math.imul(Nt,_t)|0,b=b+Math.imul(Nt,se)|0,u=u+Math.imul(U,gt)|0,h=h+Math.imul(U,Et)|0,h=h+Math.imul(It,gt)|0,b=b+Math.imul(It,Et)|0;var ri=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(ri>>>26)|0,ri&=67108863,u=Math.imul(st,ct),h=Math.imul(st,Yt),h=h+Math.imul(zt,ct)|0,b=Math.imul(zt,Yt),u=u+Math.imul(at,ft)|0,h=h+Math.imul(at,ee)|0,h=h+Math.imul($t,ft)|0,b=b+Math.imul($t,ee)|0,u=u+Math.imul(ot,pt)|0,h=h+Math.imul(ot,ne)|0,h=h+Math.imul(jt,pt)|0,b=b+Math.imul(jt,ne)|0,u=u+Math.imul(rt,mt)|0,h=h+Math.imul(rt,oe)|0,h=h+Math.imul(Bt,mt)|0,b=b+Math.imul(Bt,oe)|0,u=u+Math.imul(nt,_t)|0,h=h+Math.imul(nt,se)|0,h=h+Math.imul(Rt,_t)|0,b=b+Math.imul(Rt,se)|0,u=u+Math.imul(it,gt)|0,h=h+Math.imul(it,Et)|0,h=h+Math.imul(Nt,gt)|0,b=b+Math.imul(Nt,Et)|0;var oi=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(oi>>>26)|0,oi&=67108863,u=Math.imul(st,ft),h=Math.imul(st,ee),h=h+Math.imul(zt,ft)|0,b=Math.imul(zt,ee),u=u+Math.imul(at,pt)|0,h=h+Math.imul(at,ne)|0,h=h+Math.imul($t,pt)|0,b=b+Math.imul($t,ne)|0,u=u+Math.imul(ot,mt)|0,h=h+Math.imul(ot,oe)|0,h=h+Math.imul(jt,mt)|0,b=b+Math.imul(jt,oe)|0,u=u+Math.imul(rt,_t)|0,h=h+Math.imul(rt,se)|0,h=h+Math.imul(Bt,_t)|0,b=b+Math.imul(Bt,se)|0,u=u+Math.imul(nt,gt)|0,h=h+Math.imul(nt,Et)|0,h=h+Math.imul(Rt,gt)|0,b=b+Math.imul(Rt,Et)|0;var ai=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(ai>>>26)|0,ai&=67108863,u=Math.imul(st,pt),h=Math.imul(st,ne),h=h+Math.imul(zt,pt)|0,b=Math.imul(zt,ne),u=u+Math.imul(at,mt)|0,h=h+Math.imul(at,oe)|0,h=h+Math.imul($t,mt)|0,b=b+Math.imul($t,oe)|0,u=u+Math.imul(ot,_t)|0,h=h+Math.imul(ot,se)|0,h=h+Math.imul(jt,_t)|0,b=b+Math.imul(jt,se)|0,u=u+Math.imul(rt,gt)|0,h=h+Math.imul(rt,Et)|0,h=h+Math.imul(Bt,gt)|0,b=b+Math.imul(Bt,Et)|0;var si=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(si>>>26)|0,si&=67108863,u=Math.imul(st,mt),h=Math.imul(st,oe),h=h+Math.imul(zt,mt)|0,b=Math.imul(zt,oe),u=u+Math.imul(at,_t)|0,h=h+Math.imul(at,se)|0,h=h+Math.imul($t,_t)|0,b=b+Math.imul($t,se)|0,u=u+Math.imul(ot,gt)|0,h=h+Math.imul(ot,Et)|0,h=h+Math.imul(jt,gt)|0,b=b+Math.imul(jt,Et)|0;var li=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(li>>>26)|0,li&=67108863,u=Math.imul(st,_t),h=Math.imul(st,se),h=h+Math.imul(zt,_t)|0,b=Math.imul(zt,se),u=u+Math.imul(at,gt)|0,h=h+Math.imul(at,Et)|0,h=h+Math.imul($t,gt)|0,b=b+Math.imul($t,Et)|0;var ui=(_+u|0)+((h&8191)<<13)|0;_=(b+(h>>>13)|0)+(ui>>>26)|0,ui&=67108863,u=Math.imul(st,gt),h=Math.imul(st,Et),h=h+Math.imul(zt,gt)|0,b=Math.imul(zt,Et);var on=(_+u|0)+((h&8191)<<13)|0;return _=(b+(h>>>13)|0)+(on>>>26)|0,on&=67108863,w[0]=Ke,w[1]=Ve,w[2]=We,w[3]=Ge,w[4]=Je,w[5]=Xe,w[6]=Qe,w[7]=Ye,w[8]=ti,w[9]=ei,w[10]=ii,w[11]=ni,w[12]=ri,w[13]=oi,w[14]=ai,w[15]=si,w[16]=li,w[17]=ui,w[18]=on,_!==0&&(w[19]=_,l.length++),l};Math.imul||(J=O);function vt(e,o,l){l.negative=o.negative^e.negative,l.length=e.length+o.length;for(var f=0,m=0,w=0;w<l.length-1;w++){var _=m;m=0;for(var u=f&67108863,h=Math.min(w,o.length-1),b=Math.max(0,w-e.length+1);b<=h;b++){var T=w-b,I=e.words[T]|0,F=o.words[b]|0,B=I*F,$=B&67108863;_=_+(B/67108864|0)|0,$=$+u|0,u=$&67108863,_=_+($>>>26)|0,m+=_>>>26,_&=67108863}l.words[w]=u,f=_,_=m}return f!==0?l.words[w]=f:l.length--,l._strip()}function he(e,o,l){return vt(e,o,l)}c.prototype.mulTo=function(e,o){var l,f=this.length+e.length;return this.length===10&&e.length===10?l=J(this,e,o):f<63?l=O(this,e,o):f<1024?l=vt(this,e,o):l=he(this,e,o),l};function G(e,o){this.x=e,this.y=o}G.prototype.makeRBT=function(e){for(var o=new Array(e),l=c.prototype._countBits(e)-1,f=0;f<e;f++)o[f]=this.revBin(f,l,e);return o},G.prototype.revBin=function(e,o,l){if(e===0||e===l-1)return e;for(var f=0,m=0;m<o;m++)f|=(e&1)<<o-m-1,e>>=1;return f},G.prototype.permute=function(e,o,l,f,m,w){for(var _=0;_<w;_++)f[_]=o[e[_]],m[_]=l[e[_]]},G.prototype.transform=function(e,o,l,f,m,w){this.permute(w,e,o,l,f,m);for(var _=1;_<m;_<<=1)for(var u=_<<1,h=Math.cos(2*Math.PI/u),b=Math.sin(2*Math.PI/u),T=0;T<m;T+=u)for(var I=h,F=b,B=0;B<_;B++){var $=l[T+B],yt=f[T+B],Q=l[T+B+_],z=f[T+B+_],wt=I*Q-F*z;z=I*z+F*Q,Q=wt,l[T+B]=$+Q,f[T+B]=yt+z,l[T+B+_]=$-Q,f[T+B+_]=yt-z,B!==u&&(wt=h*I-b*F,F=h*F+b*I,I=wt)}},G.prototype.guessLen13b=function(e,o){var l=Math.max(o,e)|1,f=l&1,m=0;for(l=l/2|0;l;l=l>>>1)m++;return 1<<m+1+f},G.prototype.conjugate=function(e,o,l){if(!(l<=1))for(var f=0;f<l/2;f++){var m=e[f];e[f]=e[l-f-1],e[l-f-1]=m,m=o[f],o[f]=-o[l-f-1],o[l-f-1]=-m}},G.prototype.normalize13b=function(e,o){for(var l=0,f=0;f<o/2;f++){var m=Math.round(e[2*f+1]/o)*8192+Math.round(e[2*f]/o)+l;e[f]=m&67108863,m<67108864?l=0:l=m/67108864|0}return e},G.prototype.convert13b=function(e,o,l,f){for(var m=0,w=0;w<o;w++)m=m+(e[w]|0),l[2*w]=m&8191,m=m>>>13,l[2*w+1]=m&8191,m=m>>>13;for(w=2*o;w<f;++w)l[w]=0;r(m===0),r((m&-8192)===0)},G.prototype.stub=function(e){for(var o=new Array(e),l=0;l<e;l++)o[l]=0;return o},G.prototype.mulp=function(e,o,l){var f=2*this.guessLen13b(e.length,o.length),m=this.makeRBT(f),w=this.stub(f),_=new Array(f),u=new Array(f),h=new Array(f),b=new Array(f),T=new Array(f),I=new Array(f),F=l.words;F.length=f,this.convert13b(e.words,e.length,_,f),this.convert13b(o.words,o.length,b,f),this.transform(_,w,u,h,f,m),this.transform(b,w,T,I,f,m);for(var B=0;B<f;B++){var $=u[B]*T[B]-h[B]*I[B];h[B]=u[B]*I[B]+h[B]*T[B],u[B]=$}return this.conjugate(u,h,f),this.transform(u,h,F,w,f,m),this.conjugate(F,w,f),this.normalize13b(F,f),l.negative=e.negative^o.negative,l.length=e.length+o.length,l._strip()},c.prototype.mul=function(e){var o=new c(null);return o.words=new Array(this.length+e.length),this.mulTo(e,o)},c.prototype.mulf=function(e){var o=new c(null);return o.words=new Array(this.length+e.length),he(this,e,o)},c.prototype.imul=function(e){return this.clone().mulTo(e,this)},c.prototype.imuln=function(e){var o=e<0;o&&(e=-e),r(typeof e=="number"),r(e<67108864);for(var l=0,f=0;f<this.length;f++){var m=(this.words[f]|0)*e,w=(m&67108863)+(l&67108863);l>>=26,l+=m/67108864|0,l+=w>>>26,this.words[f]=w&67108863}return l!==0&&(this.words[f]=l,this.length++),this.length=e===0?1:this.length,o?this.ineg():this},c.prototype.muln=function(e){return this.clone().imuln(e)},c.prototype.sqr=function(){return this.mul(this)},c.prototype.isqr=function(){return this.imul(this.clone())},c.prototype.pow=function(e){var o=W(e);if(o.length===0)return new c(1);for(var l=this,f=0;f<o.length&&o[f]===0;f++,l=l.sqr());if(++f<o.length)for(var m=l.sqr();f<o.length;f++,m=m.sqr())o[f]!==0&&(l=l.mul(m));return l},c.prototype.iushln=function(e){r(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26,f=67108863>>>26-o<<26-o,m;if(o!==0){var w=0;for(m=0;m<this.length;m++){var _=this.words[m]&f,u=(this.words[m]|0)-_<<o;this.words[m]=u|w,w=_>>>26-o}w&&(this.words[m]=w,this.length++)}if(l!==0){for(m=this.length-1;m>=0;m--)this.words[m+l]=this.words[m];for(m=0;m<l;m++)this.words[m]=0;this.length+=l}return this._strip()},c.prototype.ishln=function(e){return r(this.negative===0),this.iushln(e)},c.prototype.iushrn=function(e,o,l){r(typeof e=="number"&&e>=0);var f;o?f=(o-o%26)/26:f=0;var m=e%26,w=Math.min((e-m)/26,this.length),_=67108863^67108863>>>m<<m,u=l;if(f-=w,f=Math.max(0,f),u){for(var h=0;h<w;h++)u.words[h]=this.words[h];u.length=w}if(w!==0)if(this.length>w)for(this.length-=w,h=0;h<this.length;h++)this.words[h]=this.words[h+w];else this.words[0]=0,this.length=1;var b=0;for(h=this.length-1;h>=0&&(b!==0||h>=f);h--){var T=this.words[h]|0;this.words[h]=b<<26-m|T>>>m,b=T&_}return u&&b!==0&&(u.words[u.length++]=b),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},c.prototype.ishrn=function(e,o,l){return r(this.negative===0),this.iushrn(e,o,l)},c.prototype.shln=function(e){return this.clone().ishln(e)},c.prototype.ushln=function(e){return this.clone().iushln(e)},c.prototype.shrn=function(e){return this.clone().ishrn(e)},c.prototype.ushrn=function(e){return this.clone().iushrn(e)},c.prototype.testn=function(e){r(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26,f=1<<o;if(this.length<=l)return!1;var m=this.words[l];return!!(m&f)},c.prototype.imaskn=function(e){r(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(o!==0&&l++,this.length=Math.min(l,this.length),o!==0){var f=67108863^67108863>>>o<<o;this.words[this.length-1]&=f}return this._strip()},c.prototype.maskn=function(e){return this.clone().imaskn(e)},c.prototype.iaddn=function(e){return r(typeof e=="number"),r(e<67108864),e<0?this.isubn(-e):this.negative!==0?this.length===1&&(this.words[0]|0)<=e?(this.words[0]=e-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},c.prototype._iaddn=function(e){this.words[0]+=e;for(var o=0;o<this.length&&this.words[o]>=67108864;o++)this.words[o]-=67108864,o===this.length-1?this.words[o+1]=1:this.words[o+1]++;return this.length=Math.max(this.length,o+1),this},c.prototype.isubn=function(e){if(r(typeof e=="number"),r(e<67108864),e<0)return this.iaddn(-e);if(this.negative!==0)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var o=0;o<this.length&&this.words[o]<0;o++)this.words[o]+=67108864,this.words[o+1]-=1;return this._strip()},c.prototype.addn=function(e){return this.clone().iaddn(e)},c.prototype.subn=function(e){return this.clone().isubn(e)},c.prototype.iabs=function(){return this.negative=0,this},c.prototype.abs=function(){return this.clone().iabs()},c.prototype._ishlnsubmul=function(e,o,l){var f=e.length+l,m;this._expand(f);var w,_=0;for(m=0;m<e.length;m++){w=(this.words[m+l]|0)+_;var u=(e.words[m]|0)*o;w-=u&67108863,_=(w>>26)-(u/67108864|0),this.words[m+l]=w&67108863}for(;m<this.length-l;m++)w=(this.words[m+l]|0)+_,_=w>>26,this.words[m+l]=w&67108863;if(_===0)return this._strip();for(r(_===-1),_=0,m=0;m<this.length;m++)w=-(this.words[m]|0)+_,_=w>>26,this.words[m]=w&67108863;return this.negative=1,this._strip()},c.prototype._wordDiv=function(e,o){var l=this.length-e.length,f=this.clone(),m=e,w=m.words[m.length-1]|0,_=this._countBits(w);l=26-_,l!==0&&(m=m.ushln(l),f.iushln(l),w=m.words[m.length-1]|0);var u=f.length-m.length,h;if(o!=="mod"){h=new c(null),h.length=u+1,h.words=new Array(h.length);for(var b=0;b<h.length;b++)h.words[b]=0}var T=f.clone()._ishlnsubmul(m,1,u);T.negative===0&&(f=T,h&&(h.words[u]=1));for(var I=u-1;I>=0;I--){var F=(f.words[m.length+I]|0)*67108864+(f.words[m.length+I-1]|0);for(F=Math.min(F/w|0,67108863),f._ishlnsubmul(m,F,I);f.negative!==0;)F--,f.negative=0,f._ishlnsubmul(m,1,I),f.isZero()||(f.negative^=1);h&&(h.words[I]=F)}return h&&h._strip(),f._strip(),o!=="div"&&l!==0&&f.iushrn(l),{div:h||null,mod:f}},c.prototype.divmod=function(e,o,l){if(r(!e.isZero()),this.isZero())return{div:new c(0),mod:new c(0)};var f,m,w;return this.negative!==0&&e.negative===0?(w=this.neg().divmod(e,o),o!=="mod"&&(f=w.div.neg()),o!=="div"&&(m=w.mod.neg(),l&&m.negative!==0&&m.iadd(e)),{div:f,mod:m}):this.negative===0&&e.negative!==0?(w=this.divmod(e.neg(),o),o!=="mod"&&(f=w.div.neg()),{div:f,mod:w.mod}):(this.negative&e.negative)!==0?(w=this.neg().divmod(e.neg(),o),o!=="div"&&(m=w.mod.neg(),l&&m.negative!==0&&m.isub(e)),{div:w.div,mod:m}):e.length>this.length||this.cmp(e)<0?{div:new c(0),mod:this}:e.length===1?o==="div"?{div:this.divn(e.words[0]),mod:null}:o==="mod"?{div:null,mod:new c(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new c(this.modrn(e.words[0]))}:this._wordDiv(e,o)},c.prototype.div=function(e){return this.divmod(e,"div",!1).div},c.prototype.mod=function(e){return this.divmod(e,"mod",!1).mod},c.prototype.umod=function(e){return this.divmod(e,"mod",!0).mod},c.prototype.divRound=function(e){var o=this.divmod(e);if(o.mod.isZero())return o.div;var l=o.div.negative!==0?o.mod.isub(e):o.mod,f=e.ushrn(1),m=e.andln(1),w=l.cmp(f);return w<0||m===1&&w===0?o.div:o.div.negative!==0?o.div.isubn(1):o.div.iaddn(1)},c.prototype.modrn=function(e){var o=e<0;o&&(e=-e),r(e<=67108863);for(var l=(1<<26)%e,f=0,m=this.length-1;m>=0;m--)f=(l*f+(this.words[m]|0))%e;return o?-f:f},c.prototype.modn=function(e){return this.modrn(e)},c.prototype.idivn=function(e){var o=e<0;o&&(e=-e),r(e<=67108863);for(var l=0,f=this.length-1;f>=0;f--){var m=(this.words[f]|0)+l*67108864;this.words[f]=m/e|0,l=m%e}return this._strip(),o?this.ineg():this},c.prototype.divn=function(e){return this.clone().idivn(e)},c.prototype.egcd=function(e){r(e.negative===0),r(!e.isZero());var o=this,l=e.clone();o.negative!==0?o=o.umod(e):o=o.clone();for(var f=new c(1),m=new c(0),w=new c(0),_=new c(1),u=0;o.isEven()&&l.isEven();)o.iushrn(1),l.iushrn(1),++u;for(var h=l.clone(),b=o.clone();!o.isZero();){for(var T=0,I=1;(o.words[0]&I)===0&&T<26;++T,I<<=1);if(T>0)for(o.iushrn(T);T-- >0;)(f.isOdd()||m.isOdd())&&(f.iadd(h),m.isub(b)),f.iushrn(1),m.iushrn(1);for(var F=0,B=1;(l.words[0]&B)===0&&F<26;++F,B<<=1);if(F>0)for(l.iushrn(F);F-- >0;)(w.isOdd()||_.isOdd())&&(w.iadd(h),_.isub(b)),w.iushrn(1),_.iushrn(1);o.cmp(l)>=0?(o.isub(l),f.isub(w),m.isub(_)):(l.isub(o),w.isub(f),_.isub(m))}return{a:w,b:_,gcd:l.iushln(u)}},c.prototype._invmp=function(e){r(e.negative===0),r(!e.isZero());var o=this,l=e.clone();o.negative!==0?o=o.umod(e):o=o.clone();for(var f=new c(1),m=new c(0),w=l.clone();o.cmpn(1)>0&&l.cmpn(1)>0;){for(var _=0,u=1;(o.words[0]&u)===0&&_<26;++_,u<<=1);if(_>0)for(o.iushrn(_);_-- >0;)f.isOdd()&&f.iadd(w),f.iushrn(1);for(var h=0,b=1;(l.words[0]&b)===0&&h<26;++h,b<<=1);if(h>0)for(l.iushrn(h);h-- >0;)m.isOdd()&&m.iadd(w),m.iushrn(1);o.cmp(l)>=0?(o.isub(l),f.isub(m)):(l.isub(o),m.isub(f))}var T;return o.cmpn(1)===0?T=f:T=m,T.cmpn(0)<0&&T.iadd(e),T},c.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var o=this.clone(),l=e.clone();o.negative=0,l.negative=0;for(var f=0;o.isEven()&&l.isEven();f++)o.iushrn(1),l.iushrn(1);do{for(;o.isEven();)o.iushrn(1);for(;l.isEven();)l.iushrn(1);var m=o.cmp(l);if(m<0){var w=o;o=l,l=w}else if(m===0||l.cmpn(1)===0)break;o.isub(l)}while(!0);return l.iushln(f)},c.prototype.invm=function(e){return this.egcd(e).a.umod(e)},c.prototype.isEven=function(){return(this.words[0]&1)===0},c.prototype.isOdd=function(){return(this.words[0]&1)===1},c.prototype.andln=function(e){return this.words[0]&e},c.prototype.bincn=function(e){r(typeof e=="number");var o=e%26,l=(e-o)/26,f=1<<o;if(this.length<=l)return this._expand(l+1),this.words[l]|=f,this;for(var m=f,w=l;m!==0&&w<this.length;w++){var _=this.words[w]|0;_+=m,m=_>>>26,_&=67108863,this.words[w]=_}return m!==0&&(this.words[w]=m,this.length++),this},c.prototype.isZero=function(){return this.length===1&&this.words[0]===0},c.prototype.cmpn=function(e){var o=e<0;if(this.negative!==0&&!o)return-1;if(this.negative===0&&o)return 1;this._strip();var l;if(this.length>1)l=1;else{o&&(e=-e),r(e<=67108863,"Number is too big");var f=this.words[0]|0;l=f===e?0:f<e?-1:1}return this.negative!==0?-l|0:l},c.prototype.cmp=function(e){if(this.negative!==0&&e.negative===0)return-1;if(this.negative===0&&e.negative!==0)return 1;var o=this.ucmp(e);return this.negative!==0?-o|0:o},c.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var o=0,l=this.length-1;l>=0;l--){var f=this.words[l]|0,m=e.words[l]|0;if(f!==m){f<m?o=-1:f>m&&(o=1);break}}return o},c.prototype.gtn=function(e){return this.cmpn(e)===1},c.prototype.gt=function(e){return this.cmp(e)===1},c.prototype.gten=function(e){return this.cmpn(e)>=0},c.prototype.gte=function(e){return this.cmp(e)>=0},c.prototype.ltn=function(e){return this.cmpn(e)===-1},c.prototype.lt=function(e){return this.cmp(e)===-1},c.prototype.lten=function(e){return this.cmpn(e)<=0},c.prototype.lte=function(e){return this.cmp(e)<=0},c.prototype.eqn=function(e){return this.cmpn(e)===0},c.prototype.eq=function(e){return this.cmp(e)===0},c.red=function(e){return new v(e)},c.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),e.convertTo(this)._forceRed(e)},c.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},c.prototype._forceRed=function(e){return this.red=e,this},c.prototype.forceRed=function(e){return r(!this.red,"Already a number in reduction context"),this._forceRed(e)},c.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},c.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},c.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},c.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},c.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},c.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},c.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},c.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},c.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},c.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},c.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},c.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},c.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var Pt={k256:null,p224:null,p192:null,p25519:null};function M(e,o){this.name=e,this.p=new c(o,16),this.n=this.p.bitLength(),this.k=new c(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}M.prototype._tmp=function(){var e=new c(null);return e.words=new Array(Math.ceil(this.n/13)),e},M.prototype.ireduce=function(e){var o=e,l;do this.split(o,this.tmp),o=this.imulK(o),o=o.iadd(this.tmp),l=o.bitLength();while(l>this.n);var f=l<this.n?-1:o.ucmp(this.p);return f===0?(o.words[0]=0,o.length=1):f>0?o.isub(this.p):o.strip!==void 0?o.strip():o._strip(),o},M.prototype.split=function(e,o){e.iushrn(this.n,0,o)},M.prototype.imulK=function(e){return e.imul(this.k)};function x(){M.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}d(x,M),x.prototype.split=function(e,o){for(var l=4194303,f=Math.min(e.length,9),m=0;m<f;m++)o.words[m]=e.words[m];if(o.length=f,e.length<=9){e.words[0]=0,e.length=1;return}var w=e.words[9];for(o.words[o.length++]=w&l,m=10;m<e.length;m++){var _=e.words[m]|0;e.words[m-10]=(_&l)<<4|w>>>22,w=_}w>>>=22,e.words[m-10]=w,w===0&&e.length>10?e.length-=10:e.length-=9},x.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var o=0,l=0;l<e.length;l++){var f=e.words[l]|0;o+=f*977,e.words[l]=o&67108863,o=f*64+(o/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function A(){M.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}d(A,M);function E(){M.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}d(E,M);function S(){M.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}d(S,M),S.prototype.imulK=function(e){for(var o=0,l=0;l<e.length;l++){var f=(e.words[l]|0)*19+o,m=f&67108863;f>>>=26,e.words[l]=m,o=f}return o!==0&&(e.words[e.length++]=o),e},c._prime=function(e){if(Pt[e])return Pt[e];var o;if(e==="k256")o=new x;else if(e==="p224")o=new A;else if(e==="p192")o=new E;else if(e==="p25519")o=new S;else throw new Error("Unknown prime "+e);return Pt[e]=o,o};function v(e){if(typeof e=="string"){var o=c._prime(e);this.m=o.p,this.prime=o}else r(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}v.prototype._verify1=function(e){r(e.negative===0,"red works only with positives"),r(e.red,"red works only with red numbers")},v.prototype._verify2=function(e,o){r((e.negative|o.negative)===0,"red works only with positives"),r(e.red&&e.red===o.red,"red works only with red numbers")},v.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(C(e,e.umod(this.m)._forceRed(this)),e)},v.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},v.prototype.add=function(e,o){this._verify2(e,o);var l=e.add(o);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},v.prototype.iadd=function(e,o){this._verify2(e,o);var l=e.iadd(o);return l.cmp(this.m)>=0&&l.isub(this.m),l},v.prototype.sub=function(e,o){this._verify2(e,o);var l=e.sub(o);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},v.prototype.isub=function(e,o){this._verify2(e,o);var l=e.isub(o);return l.cmpn(0)<0&&l.iadd(this.m),l},v.prototype.shl=function(e,o){return this._verify1(e),this.imod(e.ushln(o))},v.prototype.imul=function(e,o){return this._verify2(e,o),this.imod(e.imul(o))},v.prototype.mul=function(e,o){return this._verify2(e,o),this.imod(e.mul(o))},v.prototype.isqr=function(e){return this.imul(e,e.clone())},v.prototype.sqr=function(e){return this.mul(e,e)},v.prototype.sqrt=function(e){if(e.isZero())return e.clone();var o=this.m.andln(3);if(r(o%2===1),o===3){var l=this.m.add(new c(1)).iushrn(2);return this.pow(e,l)}for(var f=this.m.subn(1),m=0;!f.isZero()&&f.andln(1)===0;)m++,f.iushrn(1);r(!f.isZero());var w=new c(1).toRed(this),_=w.redNeg(),u=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new c(2*h*h).toRed(this);this.pow(h,u).cmp(_)!==0;)h.redIAdd(_);for(var b=this.pow(h,f),T=this.pow(e,f.addn(1).iushrn(1)),I=this.pow(e,f),F=m;I.cmp(w)!==0;){for(var B=I,$=0;B.cmp(w)!==0;$++)B=B.redSqr();r($<F);var yt=this.pow(b,new c(1).iushln(F-$-1));T=T.redMul(yt),b=yt.redSqr(),I=I.redMul(b),F=$}return T},v.prototype.invm=function(e){var o=e._invmp(this.m);return o.negative!==0?(o.negative=0,this.imod(o).redNeg()):this.imod(o)},v.prototype.pow=function(e,o){if(o.isZero())return new c(1).toRed(this);if(o.cmpn(1)===0)return e.clone();var l=4,f=new Array(1<<l);f[0]=new c(1).toRed(this),f[1]=e;for(var m=2;m<f.length;m++)f[m]=this.mul(f[m-1],e);var w=f[0],_=0,u=0,h=o.bitLength()%26;for(h===0&&(h=26),m=o.length-1;m>=0;m--){for(var b=o.words[m],T=h-1;T>=0;T--){var I=b>>T&1;if(w!==f[0]&&(w=this.sqr(w)),I===0&&_===0){u=0;continue}_<<=1,_|=I,u++,!(u!==l&&(m!==0||T!==0))&&(w=this.mul(w,f[_]),u=0,_=0)}h=26}return w},v.prototype.convertTo=function(e){var o=e.umod(this.m);return o===e?o.clone():o},v.prototype.convertFrom=function(e){var o=e.clone();return o.red=null,o},c.mont=function(e){return new s(e)};function s(e){v.call(this,e),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new c(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)}d(s,v),s.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},s.prototype.convertFrom=function(e){var o=this.imod(e.mul(this.rinv));return o.red=null,o},s.prototype.imul=function(e,o){if(e.isZero()||o.isZero())return e.words[0]=0,e.length=1,e;var l=e.imul(o),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),m=l.isub(f).iushrn(this.shift),w=m;return m.cmp(this.m)>=0?w=m.isub(this.m):m.cmpn(0)<0&&(w=m.iadd(this.m)),w._forceRed(this)},s.prototype.mul=function(e,o){if(e.isZero()||o.isZero())return new c(0)._forceRed(this);var l=e.mul(o),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),m=l.isub(f).iushrn(this.shift),w=m;return m.cmp(this.m)>=0?w=m.isub(this.m):m.cmpn(0)<0&&(w=m.iadd(this.m)),w._forceRed(this)},s.prototype.invm=function(e){var o=this.imod(e._invmp(this.m).mul(this.r2));return o._forceRed(this)}})(typeof i>"u"||i,t)}),ur="3.7.7",po=ur,ki=typeof Buffer=="function",Xn=typeof TextDecoder=="function"?new TextDecoder:void 0,Qn=typeof TextEncoder=="function"?new TextEncoder:void 0,mo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",xi=Array.prototype.slice.call(mo),qi=(t=>{let i={};return t.forEach((n,a)=>i[n]=a),i})(xi),_o=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,me=String.fromCharCode.bind(String),Yn=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),hr=t=>t.replace(/=/g,"").replace(/[+\/]/g,i=>i=="+"?"-":"_"),dr=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),cr=t=>{let i,n,a,r,d="",c=t.length%3;for(let p=0;p<t.length;){if((n=t.charCodeAt(p++))>255||(a=t.charCodeAt(p++))>255||(r=t.charCodeAt(p++))>255)throw new TypeError("invalid character found");i=n<<16|a<<8|r,d+=xi[i>>18&63]+xi[i>>12&63]+xi[i>>6&63]+xi[i&63]}return c?d.slice(0,c-3)+"===".substring(c):d},On=typeof btoa=="function"?t=>btoa(t):ki?t=>Buffer.from(t,"binary").toString("base64"):cr,bn=ki?t=>Buffer.from(t).toString("base64"):t=>{let i=[];for(let n=0,a=t.length;n<a;n+=4096)i.push(me.apply(null,t.subarray(n,n+4096)));return On(i.join(""))},Ui=(t,i=!1)=>i?hr(bn(t)):bn(t),go=t=>{if(t.length<2){var i=t.charCodeAt(0);return i<128?t:i<2048?me(192|i>>>6)+me(128|i&63):me(224|i>>>12&15)+me(128|i>>>6&63)+me(128|i&63)}else{var i=65536+(t.charCodeAt(0)-55296)*1024+(t.charCodeAt(1)-56320);return me(240|i>>>18&7)+me(128|i>>>12&63)+me(128|i>>>6&63)+me(128|i&63)}},wo=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,fr=t=>t.replace(wo,go),tr=ki?t=>Buffer.from(t,"utf8").toString("base64"):Qn?t=>bn(Qn.encode(t)):t=>On(fr(t)),wi=(t,i=!1)=>i?hr(tr(t)):tr(t),er=t=>wi(t,!0),vo=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,yo=t=>{switch(t.length){case 4:var i=(7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3),n=i-65536;return me((n>>>10)+55296)+me((n&1023)+56320);case 3:return me((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return me((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},pr=t=>t.replace(vo,yo),mr=t=>{if(t=t.replace(/\s+/g,""),!_o.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(t.length&3));let i,n="",a,r;for(let d=0;d<t.length;)i=qi[t.charAt(d++)]<<18|qi[t.charAt(d++)]<<12|(a=qi[t.charAt(d++)])<<6|(r=qi[t.charAt(d++)]),n+=a===64?me(i>>16&255):r===64?me(i>>16&255,i>>8&255):me(i>>16&255,i>>8&255,i&255);return n},Nn=typeof atob=="function"?t=>atob(dr(t)):ki?t=>Buffer.from(t,"base64").toString("binary"):mr,_r=ki?t=>Yn(Buffer.from(t,"base64")):t=>Yn(Nn(t).split("").map(i=>i.charCodeAt(0))),gr=t=>_r(wr(t)),bo=ki?t=>Buffer.from(t,"base64").toString("utf8"):Xn?t=>Xn.decode(_r(t)):t=>pr(Nn(t)),wr=t=>dr(t.replace(/[-_]/g,i=>i=="-"?"+":"/")),Mn=t=>bo(wr(t)),Mo=t=>{if(typeof t!="string")return!1;let i=t.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(i)||!/[^\s0-9a-zA-Z\-_]/.test(i)},vr=t=>({value:t,enumerable:!1,writable:!0,configurable:!0}),yr=function(){let t=(i,n)=>Object.defineProperty(String.prototype,i,vr(n));t("fromBase64",function(){return Mn(this)}),t("toBase64",function(i){return wi(this,i)}),t("toBase64URI",function(){return wi(this,!0)}),t("toBase64URL",function(){return wi(this,!0)}),t("toUint8Array",function(){return gr(this)})},br=function(){let t=(i,n)=>Object.defineProperty(Uint8Array.prototype,i,vr(n));t("toBase64",function(i){return Ui(this,i)}),t("toBase64URI",function(){return Ui(this,!0)}),t("toBase64URL",function(){return Ui(this,!0)})},ko=()=>{yr(),br()},gn={version:ur,VERSION:po,atob:Nn,atobPolyfill:mr,btoa:On,btoaPolyfill:cr,fromBase64:Mn,toBase64:wi,encode:wi,encodeURI:er,encodeURL:er,utob:fr,btou:pr,decode:Mn,isValid:Mo,fromUint8Array:Ui,toUint8Array:gr,extendString:yr,extendUint8Array:br,extendBuiltins:ko},xo=(t=>(t.InvalidSqrtPriceLimitDirection="InvalidSqrtPriceLimitDirection",t.ZeroTradableAmount="ZeroTradableAmount",t.AmountOutBelowMinimum="AmountOutBelowMinimum",t.AmountInAboveMaximum="AmountInAboveMaximum",t.NextTickNotFound="NextTickNotFound",t.TickArraySequenceInvalid="TickArraySequenceInvalid",t.TickArrayCrossingAboveMax="TickArrayCrossingAboveMax",t.TickArrayIndexNotInitialized="TickArrayIndexNotInitialized",t.ParamsLengthNotEqual="ParamsLengthNotEqual",t))(xo||{}),Co=(t=>(t.InvalidTickEvent="InvalidTickEvent",t.InvalidPositionObject="InvalidPositionObject",t.InvalidPositionRewardObject="InvalidPositionRewardObject",t.InvalidParams="InvalidParams",t.FetchError="FetchError",t))(Co||{}),Ao=(t=>(t.InvalidCoinTypeSequence="InvalidCoinTypeSequence",t.InvalidTickIndex="InvalidTickIndex",t.InvalidPoolObject="InvalidPoolObject",t.InvalidTickObjectId="InvalidTickObjectId",t.InvalidTickObject="InvalidTickObject",t.InvalidTickFields="InvalidTickFields",t.PoolsNotFound="PoolsNotFound",t.StatsPoolsUrlNotSet="StatsPoolsUrlNotSet",t.FetchError="FetchError",t))(Ao||{}),Po=(t=>(t.ClmmVestNotSet="ClmmVestNotSet",t.ClmmVestFetchError="ClmmVestFetchError",t))(Po||{}),So=(t=>(t.NotFoundPartnerObject="NotFoundPartnerObject",t.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",t))(So||{}),Eo=(t=>(t.InvalidConfig="InvalidConfig",t.InvalidConfigHandle="InvalidConfigHandle",t.InvalidSimulateAccount="InvalidSimulateAccount",t))(Eo||{}),To=(t=>(t.InvalidSendAddress="InvalidSendAddress",t.InvalidRecipientAddress="InvalidRecipientAddress",t.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",t.InsufficientBalance="InsufficientBalance",t.InvalidTarget="InvalidTarget",t.InvalidTransactionBuilder="InvalidTransactionBuilder",t))(To||{}),Io=(t=>(t.InvalidCoin="InvalidCoin",t.NotFoundPath="NotFoundPath",t.NoDowngradeNeedParams="NoDowngradeNeedParams",t.InvalidSwapCountUrl="InvalidSwapCountUrl",t.InvalidTransactionBuilder="InvalidTransactionBuilder",t.InvalidServerResponse="InvalidServerResponse",t))(Io||{}),Oo=(t=>(t.InvalidType="InvalidType",t))(Oo||{}),kr=class extends Mr.BaseError{constructor(t,i,n){super(t,i||"UnknownError",n)}static isVaultsErrorCode(t,i){return this.isErrorCode(t,i)}},Be=(t,i,n)=>{throw new kr(i.message,t,n)},et=(t,i,n)=>{throw new kr(i,t,n)},No=class{constructor(t){this._cache={},this._sdk=t}get sdk(){return this._sdk}setTokenListCache(t){let{coin_list_handle:i}=(0,Z.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),n=`${i}_getCoinConfigs`,a=this.getCache(n),r=a?[...a,...t]:t;this.updateCache(n,r)}async getTokenListByCoinTypes(t){let i={},{coin_list_handle:n}=(0,Z.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),a=`${n}_getCoinConfigs`,r=this.getCache(a);if(r!==void 0){let c=r;for(let p of t)for(let g of c)if((0,Z.normalizeCoinType)(p)===(0,Z.normalizeCoinType)(g.address)){i[p]=g;continue}}let d=t.filter(c=>i[c]===void 0);for(let c of d){let p=`${c}_metadata`,g=this.getCache(p);if(g!==void 0)i[c]=g;else{let y=await this._sdk.FullClient.getCoinMetadata({coinType:c});if(y){let k={id:y.id,pyth_id:"",name:y.name,symbol:y.symbol,official_symbol:y.symbol,coingecko_id:"",decimals:y.decimals,project_url:"",logo_url:y.iconUrl,address:c};i[c]=k,this.updateCache(p,k,Z.CACHE_TIME_24H)}else console.log(`not found ${c}`)}}return i}async getCoinConfigs(t=!1,i=!0){let{coin_list_handle:n}=(0,Z.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),a=`${n}_getCoinConfigs`,r=this.getCache(a,t);if(r)return r;let d=(await this._sdk.FullClient.getDynamicFieldsByPage(n)).data.map(g=>g.objectId),c=await this._sdk.FullClient.batchGetObjects(d,{showContent:!0}),p=[];return c.forEach(g=>{(g.error!=null||g.data?.content?.dataType!=="moveObject")&&et("FetchError",`when getCoinConfigs get objects error: ${g.error}, please check the rpc and contracts address config.`,{[Z.DETAILS_KEYS.METHOD_NAME]:"getCoinConfigs"});let y=this.buildCoinConfig(g,i);this.updateCache(`${n}_${y.address}_getCoinConfig`,y,Z.CACHE_TIME_24H),p.push({...y})}),this.updateCache(a,p,Z.CACHE_TIME_24H),p}async getCoinConfig(t,i=!1,n=!0){let{coin_list_handle:a}=(0,Z.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${a}_${t}_getCoinConfig`,d=this.getCache(r,i);if(d)return d;let c=await this._sdk.FullClient.getDynamicFieldObject({parentId:a,name:{type:"0x1::type_name::TypeName",value:{name:(0,Z.fixCoinType)(t)}}});(c.error!=null||c.data?.content?.dataType!=="moveObject")&&et("FetchError",`when getCoinConfig get object error: ${c.error}, please check the rpc and contracts address config.`,{[Z.DETAILS_KEYS.METHOD_NAME]:"getCoinConfig"});let p=this.buildCoinConfig(c,n);return this.updateCache(r,p,Z.CACHE_TIME_24H),p}buildCoinConfig(t,i=!0){let n=(0,Z.getObjectFields)(t);n=n.value.fields;let a={...n};return a.id=(0,Z.getObjectId)(t),a.address=(0,Z.extractStructTagFromType)(n.coin_type.fields.name).full_address,n.pyth_id&&(a.pyth_id=(0,$i.normalizeSuiObjectId)(n.pyth_id)),this.transformExtensions(a,n.extension_fields.fields.contents,i),delete a.coin_type,a}async getClmmPoolConfigs(t=!1,i=!0){let{clmm_pools_handle:n}=(0,Z.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),a=`${n}_getClmmPoolConfigs`,r=this.getCache(a,t);if(r)return r;let d=(await this._sdk.FullClient.getDynamicFieldsByPage(n)).data.map(g=>g.objectId),c=await this._sdk.FullClient.batchGetObjects(d,{showContent:!0}),p=[];return c.forEach(g=>{(g.error!=null||g.data?.content?.dataType!=="moveObject")&&et("FetchError",`when getClmmPoolsConfigs get objects error: ${g.error}, please check the rpc and contracts address config.`,{[Z.DETAILS_KEYS.METHOD_NAME]:"getClmmPoolConfigs"});let y=this.buildClmmPoolConfig(g,i);this.updateCache(`${y.pool_address}_getClmmPoolConfig`,y,Z.CACHE_TIME_24H),p.push({...y})}),this.updateCache(a,p,Z.CACHE_TIME_24H),p}async getClmmPoolConfig(t,i=!1,n=!0){let{clmm_pools_handle:a}=(0,Z.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${t}_getClmmPoolConfig`,d=this.getCache(r,i);if(d)return d;let c=await this._sdk.FullClient.getDynamicFieldObject({parentId:a,name:{type:"address",value:t}}),p=this.buildClmmPoolConfig(c,n);return this.updateCache(r,p,Z.CACHE_TIME_24H),p}buildClmmPoolConfig(t,i=!0){let n=(0,Z.getObjectFields)(t);n=n.value.fields;let a={...n};return a.id=(0,Z.getObjectId)(t),a.pool_address=(0,$i.normalizeSuiObjectId)(n.pool_address),this.transformExtensions(a,n.extension_fields.fields.contents,i),a}async getLaunchpadPoolConfigs(t=!1,i=!0){let{launchpad_pools_handle:n}=(0,Z.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),a=`${n}_getLaunchpadPoolConfigs`,r=this.getCache(a,t);if(r)return r;let d=(await this._sdk.FullClient.getDynamicFieldsByPage(n)).data.map(g=>g.objectId),c=await this._sdk.FullClient.batchGetObjects(d,{showContent:!0}),p=[];return c.forEach(g=>{(g.error!=null||g.data?.content?.dataType!=="moveObject")&&et("FetchError",`when getCoinConfigs get objects error: ${g.error}, please check the rpc and contracts address config.`,{[Z.DETAILS_KEYS.METHOD_NAME]:"getLaunchpadPoolConfigs"});let y=this.buildLaunchpadPoolConfig(g,i);this.updateCache(`${y.pool_address}_getLaunchpadPoolConfig`,y,Z.CACHE_TIME_24H),p.push({...y})}),this.updateCache(a,p,Z.CACHE_TIME_24H),p}async getLaunchpadPoolConfig(t,i=!1,n=!0){let{launchpad_pools_handle:a}=(0,Z.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${t}_getLaunchpadPoolConfig`,d=this.getCache(r,i);if(d)return d;let c=await this._sdk.FullClient.getDynamicFieldObject({parentId:a,name:{type:"address",value:t}}),p=this.buildLaunchpadPoolConfig(c,n);return this.updateCache(r,p,Z.CACHE_TIME_24H),p}buildLaunchpadPoolConfig(t,i=!0){let n=(0,Z.getObjectFields)(t);n=n.value.fields;let a={...n};a.id=(0,Z.getObjectId)(t),a.pool_address=(0,$i.normalizeSuiObjectId)(n.pool_address),this.transformExtensions(a,n.extension_fields.fields.contents,i);let r=[];n.social_media.fields.contents.forEach(d=>{r.push({name:d.fields.value.fields.name,link:d.fields.value.fields.link})}),a.social_media=r;try{a.regulation=decodeURIComponent(gn.decode(a.regulation).replace(/%/g,"%25"))}catch{a.regulation=gn.decode(a.regulation)}return a}transformExtensions(t,i,n=!0){let a=[];for(let r of i){let{key:d}=r.fields,{value:c}=r.fields;if(d==="labels")try{let p=decodeURIComponent(gn.decode(c));try{c=JSON.parse(p)}catch{c=p}}catch{}n&&(t[d]=c),a.push({key:d,value:c})}delete t.extension_fields,n||(t.extensions=a)}async getCetusConfig(t=!1){let i=this._sdk.sdkOptions.cetus_config.package_id,n=`${i}_getCetusConfig`,a=this.getCache(n,t);if(a!==void 0)return a;let r=await this._sdk.FullClient.getObject({id:i,options:{showPreviousTransaction:!0}}),d=(0,Z.getObjectPreviousTransactionDigest)(r),c=await this._sdk.FullClient.queryEventsByPage({Transaction:d}),p={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(c.data.length>0)for(let g of c.data)switch((0,Z.extractStructTagFromType)(g.type).name){case"InitCoinListEvent":p.coin_list_id=g.parsedJson.coin_list_id;break;case"InitLaunchpadPoolsEvent":p.launchpad_pools_id=g.parsedJson.launchpad_pools_id;break;case"InitClmmPoolsEvent":p.clmm_pools_id=g.parsedJson.pools_id;break;case"InitConfigEvent":p.global_config_id=g.parsedJson.global_config_id,p.admin_cap_id=g.parsedJson.admin_cap_id;break;default:break}return p=await this.getCetusConfigHandle(p),p.clmm_pools_id.length>0&&this.updateCache(n,p,Z.CACHE_TIME_24H),p}async getCetusConfigHandle(t){let i=[t.clmm_pools_id,t.coin_list_id,t.launchpad_pools_id];return(await this._sdk.FullClient.multiGetObjects({ids:i,options:{showContent:!0}})).forEach(n=>{(n.error!=null||n.data?.content?.dataType!=="moveObject")&&et("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${n.error}, please check the rpc and contracts address config.`,{[Z.DETAILS_KEYS.METHOD_NAME]:"getCetusConfigHandle"});let a=(0,Z.getObjectFields)(n),r=(0,Z.getObjectType)(n);switch((0,Z.extractStructTagFromType)(r).name){case"ClmmPools":t.clmm_pools_handle=a.pools.fields.id.id;break;case"CoinList":t.coin_list_handle=a.coins.fields.id.id;break;case"LaunchpadPools":t.launchpad_pools_handle=a.pools.fields.id.id;break;default:break}}),t}updateCache(t,i,n=Z.CACHE_TIME_5MIN){let a=this._cache[t];a?(a.overdue_time=(0,Z.getFutureTime)(n),a.value=i):a=new Z.CachedContent(i,(0,Z.getFutureTime)(n)),this._cache[t]=a}getCache(t,i=!1){try{let n=this._cache[t];if(!n)return;if(i||!n.isValid()){delete this._cache[t];return}return n.value}catch(n){console.error(`Error accessing cache for key ${t}:`,n);return}}},Fo=qe(je()),Ro="position_liquidity_snapshot",Do=(t=>(t.Deleted="Deleted",t.Exists="Exists",t.NotExists="NotExists",t))(Do||{}),Bo=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent"],Oe=qe(je()),qo=qe(je()),jo="partner",ji="pool_script",vi="pool_script_v2",Cr="pool_script_v3",Ar="router",Lo="router_with_partner",bi="fetcher_script";var $o="utils";var Uo=qe(je()),gi=9e15,He=1e9,kn="0123456789abcdef",Gi="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ji="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",xn={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-gi,maxE:gi,crypto:!1},Pr,De,Y=!0,Yi="[DecimalError] ",Ze=Yi+"Invalid argument: ",Sr=Yi+"Precision limit exceeded",Er=Yi+"crypto unavailable",Tr="[object Decimal]",ve=Math.floor,de=Math.pow,zo=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Zo=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ho=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ir=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Se=1e7,V=7,Ko=9007199254740991,Vo=Gi.length-1,Cn=Ji.length-1,R={toStringTag:Tr};R.absoluteValue=R.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),H(t)};R.ceil=function(){return H(new this.constructor(this),this.e+1,2)};R.clampedTo=R.clamp=function(t,i){var n,a=this,r=a.constructor;if(t=new r(t),i=new r(i),!t.s||!i.s)return new r(NaN);if(t.gt(i))throw Error(Ze+i);return n=a.cmp(t),n<0?t:a.cmp(i)>0?i:new r(a)};R.comparedTo=R.cmp=function(t){var i,n,a,r,d=this,c=d.d,p=(t=new d.constructor(t)).d,g=d.s,y=t.s;if(!c||!p)return!g||!y?NaN:g!==y?g:c===p?0:!c^g<0?1:-1;if(!c[0]||!p[0])return c[0]?g:p[0]?-y:0;if(g!==y)return g;if(d.e!==t.e)return d.e>t.e^g<0?1:-1;for(a=c.length,r=p.length,i=0,n=a<r?a:r;i<n;++i)if(c[i]!==p[i])return c[i]>p[i]^g<0?1:-1;return a===r?0:a>r^g<0?1:-1};R.cosine=R.cos=function(){var t,i,n=this,a=n.constructor;return n.d?n.d[0]?(t=a.precision,i=a.rounding,a.precision=t+Math.max(n.e,n.sd())+V,a.rounding=1,n=Wo(a,Dr(a,n)),a.precision=t,a.rounding=i,H(De==2||De==3?n.neg():n,t,i,!0)):new a(1):new a(NaN)};R.cubeRoot=R.cbrt=function(){var t,i,n,a,r,d,c,p,g,y,k=this,C=k.constructor;if(!k.isFinite()||k.isZero())return new C(k);for(Y=!1,d=k.s*de(k.s*k,1/3),!d||Math.abs(d)==1/0?(n=_e(k.d),t=k.e,(d=(t-n.length+1)%3)&&(n+=d==1||d==-2?"0":"00"),d=de(n,1/3),t=ve((t+1)/3)-(t%3==(t<0?-1:2)),d==1/0?n="5e"+t:(n=d.toExponential(),n=n.slice(0,n.indexOf("e")+1)+t),a=new C(n),a.s=k.s):a=new C(d.toString()),c=(t=C.precision)+3;;)if(p=a,g=p.times(p).times(p),y=g.plus(k),a=At(y.plus(k).times(p),y.plus(g),c+2,1),_e(p.d).slice(0,c)===(n=_e(a.d)).slice(0,c))if(n=n.slice(c-3,c+1),n=="9999"||!r&&n=="4999"){if(!r&&(H(p,t+1,0),p.times(p).times(p).eq(k))){a=p;break}c+=4,r=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(H(a,t+1,1),i=!a.times(a).times(a).eq(k));break}return Y=!0,H(a,t,C.rounding,i)};R.decimalPlaces=R.dp=function(){var t,i=this.d,n=NaN;if(i){if(t=i.length-1,n=(t-ve(this.e/V))*V,t=i[t],t)for(;t%10==0;t/=10)n--;n<0&&(n=0)}return n};R.dividedBy=R.div=function(t){return At(this,new this.constructor(t))};R.dividedToIntegerBy=R.divToInt=function(t){var i=this,n=i.constructor;return H(At(i,new n(t),0,1,1),n.precision,n.rounding)};R.equals=R.eq=function(t){return this.cmp(t)===0};R.floor=function(){return H(new this.constructor(this),this.e+1,3)};R.greaterThan=R.gt=function(t){return this.cmp(t)>0};R.greaterThanOrEqualTo=R.gte=function(t){var i=this.cmp(t);return i==1||i===0};R.hyperbolicCosine=R.cosh=function(){var t,i,n,a,r,d=this,c=d.constructor,p=new c(1);if(!d.isFinite())return new c(d.s?1/0:NaN);if(d.isZero())return p;n=c.precision,a=c.rounding,c.precision=n+Math.max(d.e,d.sd())+4,c.rounding=1,r=d.d.length,r<32?(t=Math.ceil(r/3),i=(1/en(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),d=Mi(c,1,d.times(i),new c(1),!0);for(var g,y=t,k=new c(8);y--;)g=d.times(d),d=p.minus(g.times(k.minus(g.times(k))));return H(d,c.precision=n,c.rounding=a,!0)};R.hyperbolicSine=R.sinh=function(){var t,i,n,a,r=this,d=r.constructor;if(!r.isFinite()||r.isZero())return new d(r);if(i=d.precision,n=d.rounding,d.precision=i+Math.max(r.e,r.sd())+4,d.rounding=1,a=r.d.length,a<3)r=Mi(d,2,r,r,!0);else{t=1.4*Math.sqrt(a),t=t>16?16:t|0,r=r.times(1/en(5,t)),r=Mi(d,2,r,r,!0);for(var c,p=new d(5),g=new d(16),y=new d(20);t--;)c=r.times(r),r=r.times(p.plus(c.times(g.times(c).plus(y))))}return d.precision=i,d.rounding=n,H(r,i,n,!0)};R.hyperbolicTangent=R.tanh=function(){var t,i,n=this,a=n.constructor;return n.isFinite()?n.isZero()?new a(n):(t=a.precision,i=a.rounding,a.precision=t+7,a.rounding=1,At(n.sinh(),n.cosh(),a.precision=t,a.rounding=i)):new a(n.s)};R.inverseCosine=R.acos=function(){var t=this,i=t.constructor,n=t.abs().cmp(1),a=i.precision,r=i.rounding;return n!==-1?n===0?t.isNeg()?Ne(i,a,r):new i(0):new i(NaN):t.isZero()?Ne(i,a+4,r).times(.5):(i.precision=a+6,i.rounding=1,t=new i(1).minus(t).div(t.plus(1)).sqrt().atan(),i.precision=a,i.rounding=r,t.times(2))};R.inverseHyperbolicCosine=R.acosh=function(){var t,i,n=this,a=n.constructor;return n.lte(1)?new a(n.eq(1)?0:NaN):n.isFinite()?(t=a.precision,i=a.rounding,a.precision=t+Math.max(Math.abs(n.e),n.sd())+4,a.rounding=1,Y=!1,n=n.times(n).minus(1).sqrt().plus(n),Y=!0,a.precision=t,a.rounding=i,n.ln()):new a(n)};R.inverseHyperbolicSine=R.asinh=function(){var t,i,n=this,a=n.constructor;return!n.isFinite()||n.isZero()?new a(n):(t=a.precision,i=a.rounding,a.precision=t+2*Math.max(Math.abs(n.e),n.sd())+6,a.rounding=1,Y=!1,n=n.times(n).plus(1).sqrt().plus(n),Y=!0,a.precision=t,a.rounding=i,n.ln())};R.inverseHyperbolicTangent=R.atanh=function(){var t,i,n,a,r=this,d=r.constructor;return r.isFinite()?r.e>=0?new d(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(t=d.precision,i=d.rounding,a=r.sd(),Math.max(a,t)<2*-r.e-1?H(new d(r),t,i,!0):(d.precision=n=a-r.e,r=At(r.plus(1),new d(1).minus(r),n+t,1),d.precision=t+4,d.rounding=1,r=r.ln(),d.precision=t,d.rounding=i,r.times(.5))):new d(NaN)};R.inverseSine=R.asin=function(){var t,i,n,a,r=this,d=r.constructor;return r.isZero()?new d(r):(i=r.abs().cmp(1),n=d.precision,a=d.rounding,i!==-1?i===0?(t=Ne(d,n+4,a).times(.5),t.s=r.s,t):new d(NaN):(d.precision=n+6,d.rounding=1,r=r.div(new d(1).minus(r.times(r)).sqrt().plus(1)).atan(),d.precision=n,d.rounding=a,r.times(2)))};R.inverseTangent=R.atan=function(){var t,i,n,a,r,d,c,p,g,y=this,k=y.constructor,C=k.precision,P=k.rounding;if(y.isFinite()){if(y.isZero())return new k(y);if(y.abs().eq(1)&&C+4<=Cn)return c=Ne(k,C+4,P).times(.25),c.s=y.s,c}else{if(!y.s)return new k(NaN);if(C+4<=Cn)return c=Ne(k,C+4,P).times(.5),c.s=y.s,c}for(k.precision=p=C+10,k.rounding=1,n=Math.min(28,p/V+2|0),t=n;t;--t)y=y.div(y.times(y).plus(1).sqrt().plus(1));for(Y=!1,i=Math.ceil(p/V),a=1,g=y.times(y),c=new k(y),r=y;t!==-1;)if(r=r.times(g),d=c.minus(r.div(a+=2)),r=r.times(g),c=d.plus(r.div(a+=2)),c.d[i]!==void 0)for(t=i;c.d[t]===d.d[t]&&t--;);return n&&(c=c.times(2<<n-1)),Y=!0,H(c,k.precision=C,k.rounding=P,!0)};R.isFinite=function(){return!!this.d};R.isInteger=R.isInt=function(){return!!this.d&&ve(this.e/V)>this.d.length-2};R.isNaN=function(){return!this.s};R.isNegative=R.isNeg=function(){return this.s<0};R.isPositive=R.isPos=function(){return this.s>0};R.isZero=function(){return!!this.d&&this.d[0]===0};R.lessThan=R.lt=function(t){return this.cmp(t)<0};R.lessThanOrEqualTo=R.lte=function(t){return this.cmp(t)<1};R.logarithm=R.log=function(t){var i,n,a,r,d,c,p,g,y=this,k=y.constructor,C=k.precision,P=k.rounding,N=5;if(t==null)t=new k(10),i=!0;else{if(t=new k(t),n=t.d,t.s<0||!n||!n[0]||t.eq(1))return new k(NaN);i=t.eq(10)}if(n=y.d,y.s<0||!n||!n[0]||y.eq(1))return new k(n&&!n[0]?-1/0:y.s!=1?NaN:n?0:1/0);if(i)if(n.length>1)d=!0;else{for(r=n[0];r%10===0;)r/=10;d=r!==1}if(Y=!1,p=C+N,c=ze(y,p),a=i?Xi(k,p+10):ze(t,p),g=At(c,a,p,1),Ci(g.d,r=C,P))do if(p+=10,c=ze(y,p),a=i?Xi(k,p+10):ze(t,p),g=At(c,a,p,1),!d){+_e(g.d).slice(r+1,r+15)+1==1e14&&(g=H(g,C+1,0));break}while(Ci(g.d,r+=10,P));return Y=!0,H(g,C,P)};R.minus=R.sub=function(t){var i,n,a,r,d,c,p,g,y,k,C,P,N=this,q=N.constructor;if(t=new q(t),!N.d||!t.d)return!N.s||!t.s?t=new q(NaN):N.d?t.s=-t.s:t=new q(t.d||N.s!==t.s?N:NaN),t;if(N.s!=t.s)return t.s=-t.s,N.plus(t);if(y=N.d,P=t.d,p=q.precision,g=q.rounding,!y[0]||!P[0]){if(P[0])t.s=-t.s;else if(y[0])t=new q(N);else return new q(g===3?-0:0);return Y?H(t,p,g):t}if(n=ve(t.e/V),k=ve(N.e/V),y=y.slice(),d=k-n,d){for(C=d<0,C?(i=y,d=-d,c=P.length):(i=P,n=k,c=y.length),a=Math.max(Math.ceil(p/V),c)+2,d>a&&(d=a,i.length=1),i.reverse(),a=d;a--;)i.push(0);i.reverse()}else{for(a=y.length,c=P.length,C=a<c,C&&(c=a),a=0;a<c;a++)if(y[a]!=P[a]){C=y[a]<P[a];break}d=0}for(C&&(i=y,y=P,P=i,t.s=-t.s),c=y.length,a=P.length-c;a>0;--a)y[c++]=0;for(a=P.length;a>d;){if(y[--a]<P[a]){for(r=a;r&&y[--r]===0;)y[r]=Se-1;--y[r],y[a]+=Se}y[a]-=P[a]}for(;y[--c]===0;)y.pop();for(;y[0]===0;y.shift())--n;return y[0]?(t.d=y,t.e=tn(y,n),Y?H(t,p,g):t):new q(g===3?-0:0)};R.modulo=R.mod=function(t){var i,n=this,a=n.constructor;return t=new a(t),!n.d||!t.s||t.d&&!t.d[0]?new a(NaN):!t.d||n.d&&!n.d[0]?H(new a(n),a.precision,a.rounding):(Y=!1,a.modulo==9?(i=At(n,t.abs(),0,3,1),i.s*=t.s):i=At(n,t,0,a.modulo,1),i=i.times(t),Y=!0,n.minus(i))};R.naturalExponential=R.exp=function(){return An(this)};R.naturalLogarithm=R.ln=function(){return ze(this)};R.negated=R.neg=function(){var t=new this.constructor(this);return t.s=-t.s,H(t)};R.plus=R.add=function(t){var i,n,a,r,d,c,p,g,y,k,C=this,P=C.constructor;if(t=new P(t),!C.d||!t.d)return!C.s||!t.s?t=new P(NaN):C.d||(t=new P(t.d||C.s===t.s?C:NaN)),t;if(C.s!=t.s)return t.s=-t.s,C.minus(t);if(y=C.d,k=t.d,p=P.precision,g=P.rounding,!y[0]||!k[0])return k[0]||(t=new P(C)),Y?H(t,p,g):t;if(d=ve(C.e/V),a=ve(t.e/V),y=y.slice(),r=d-a,r){for(r<0?(n=y,r=-r,c=k.length):(n=k,a=d,c=y.length),d=Math.ceil(p/V),c=d>c?d+1:c+1,r>c&&(r=c,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for(c=y.length,r=k.length,c-r<0&&(r=c,n=k,k=y,y=n),i=0;r;)i=(y[--r]=y[r]+k[r]+i)/Se|0,y[r]%=Se;for(i&&(y.unshift(i),++a),c=y.length;y[--c]==0;)y.pop();return t.d=y,t.e=tn(y,a),Y?H(t,p,g):t};R.precision=R.sd=function(t){var i,n=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(Ze+t);return n.d?(i=Or(n.d),t&&n.e+1>i&&(i=n.e+1)):i=NaN,i};R.round=function(){var t=this,i=t.constructor;return H(new i(t),t.e+1,i.rounding)};R.sine=R.sin=function(){var t,i,n=this,a=n.constructor;return n.isFinite()?n.isZero()?new a(n):(t=a.precision,i=a.rounding,a.precision=t+Math.max(n.e,n.sd())+V,a.rounding=1,n=Jo(a,Dr(a,n)),a.precision=t,a.rounding=i,H(De>2?n.neg():n,t,i,!0)):new a(NaN)};R.squareRoot=R.sqrt=function(){var t,i,n,a,r,d,c=this,p=c.d,g=c.e,y=c.s,k=c.constructor;if(y!==1||!p||!p[0])return new k(!y||y<0&&(!p||p[0])?NaN:p?c:1/0);for(Y=!1,y=Math.sqrt(+c),y==0||y==1/0?(i=_e(p),(i.length+g)%2==0&&(i+="0"),y=Math.sqrt(i),g=ve((g+1)/2)-(g<0||g%2),y==1/0?i="5e"+g:(i=y.toExponential(),i=i.slice(0,i.indexOf("e")+1)+g),a=new k(i)):a=new k(y.toString()),n=(g=k.precision)+3;;)if(d=a,a=d.plus(At(c,d,n+2,1)).times(.5),_e(d.d).slice(0,n)===(i=_e(a.d)).slice(0,n))if(i=i.slice(n-3,n+1),i=="9999"||!r&&i=="4999"){if(!r&&(H(d,g+1,0),d.times(d).eq(c))){a=d;break}n+=4,r=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(H(a,g+1,1),t=!a.times(a).eq(c));break}return Y=!0,H(a,g,k.rounding,t)};R.tangent=R.tan=function(){var t,i,n=this,a=n.constructor;return n.isFinite()?n.isZero()?new a(n):(t=a.precision,i=a.rounding,a.precision=t+10,a.rounding=1,n=n.sin(),n.s=1,n=At(n,new a(1).minus(n.times(n)).sqrt(),t+10,0),a.precision=t,a.rounding=i,H(De==2||De==4?n.neg():n,t,i,!0)):new a(NaN)};R.times=R.mul=function(t){var i,n,a,r,d,c,p,g,y,k=this,C=k.constructor,P=k.d,N=(t=new C(t)).d;if(t.s*=k.s,!P||!P[0]||!N||!N[0])return new C(!t.s||P&&!P[0]&&!N||N&&!N[0]&&!P?NaN:!P||!N?t.s/0:t.s*0);for(n=ve(k.e/V)+ve(t.e/V),g=P.length,y=N.length,g<y&&(d=P,P=N,N=d,c=g,g=y,y=c),d=[],c=g+y,a=c;a--;)d.push(0);for(a=y;--a>=0;){for(i=0,r=g+a;r>a;)p=d[r]+N[a]*P[r-a-1]+i,d[r--]=p%Se|0,i=p/Se|0;d[r]=(d[r]+i)%Se|0}for(;!d[--c];)d.pop();return i?++n:d.shift(),t.d=d,t.e=tn(d,n),Y?H(t,C.precision,C.rounding):t};R.toBinary=function(t,i){return Fn(this,2,t,i)};R.toDecimalPlaces=R.toDP=function(t,i){var n=this,a=n.constructor;return n=new a(n),t===void 0?n:(Me(t,0,He),i===void 0?i=a.rounding:Me(i,0,8),H(n,t+n.e+1,i))};R.toExponential=function(t,i){var n,a=this,r=a.constructor;return t===void 0?n=Fe(a,!0):(Me(t,0,He),i===void 0?i=r.rounding:Me(i,0,8),a=H(new r(a),t+1,i),n=Fe(a,!0,t+1)),a.isNeg()&&!a.isZero()?"-"+n:n};R.toFixed=function(t,i){var n,a,r=this,d=r.constructor;return t===void 0?n=Fe(r):(Me(t,0,He),i===void 0?i=d.rounding:Me(i,0,8),a=H(new d(r),t+r.e+1,i),n=Fe(a,!1,t+a.e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};R.toFraction=function(t){var i,n,a,r,d,c,p,g,y,k,C,P,N=this,q=N.d,L=N.constructor;if(!q)return new L(N);if(y=n=new L(1),a=g=new L(0),i=new L(a),d=i.e=Or(q)-N.e-1,c=d%V,i.d[0]=de(10,c<0?V+c:c),t==null)t=d>0?i:y;else{if(p=new L(t),!p.isInt()||p.lt(y))throw Error(Ze+p);t=p.gt(i)?d>0?i:y:p}for(Y=!1,p=new L(_e(q)),k=L.precision,L.precision=d=q.length*V*2;C=At(p,i,0,1,1),r=n.plus(C.times(a)),r.cmp(t)!=1;)n=a,a=r,r=y,y=g.plus(C.times(r)),g=r,r=i,i=p.minus(C.times(r)),p=r;return r=At(t.minus(n),a,0,1,1),g=g.plus(r.times(y)),n=n.plus(r.times(a)),g.s=y.s=N.s,P=At(y,a,d,1).minus(N).abs().cmp(At(g,n,d,1).minus(N).abs())<1?[y,a]:[g,n],L.precision=k,Y=!0,P};R.toHexadecimal=R.toHex=function(t,i){return Fn(this,16,t,i)};R.toNearest=function(t,i){var n=this,a=n.constructor;if(n=new a(n),t==null){if(!n.d)return n;t=new a(1),i=a.rounding}else{if(t=new a(t),i===void 0?i=a.rounding:Me(i,0,8),!n.d)return t.s?n:t;if(!t.d)return t.s&&(t.s=n.s),t}return t.d[0]?(Y=!1,n=At(n,t,0,i,1).times(t),Y=!0,H(n)):(t.s=n.s,n=t),n};R.toNumber=function(){return+this};R.toOctal=function(t,i){return Fn(this,8,t,i)};R.toPower=R.pow=function(t){var i,n,a,r,d,c,p=this,g=p.constructor,y=+(t=new g(t));if(!p.d||!t.d||!p.d[0]||!t.d[0])return new g(de(+p,y));if(p=new g(p),p.eq(1))return p;if(a=g.precision,d=g.rounding,t.eq(1))return H(p,a,d);if(i=ve(t.e/V),i>=t.d.length-1&&(n=y<0?-y:y)<=Ko)return r=Nr(g,p,n,a),t.s<0?new g(1).div(r):H(r,a,d);if(c=p.s,c<0){if(i<t.d.length-1)return new g(NaN);if((t.d[i]&1)==0&&(c=1),p.e==0&&p.d[0]==1&&p.d.length==1)return p.s=c,p}return n=de(+p,y),i=n==0||!isFinite(n)?ve(y*(Math.log("0."+_e(p.d))/Math.LN10+p.e+1)):new g(n+"").e,i>g.maxE+1||i<g.minE-1?new g(i>0?c/0:0):(Y=!1,g.rounding=p.s=1,n=Math.min(12,(i+"").length),r=An(t.times(ze(p,a+n)),a),r.d&&(r=H(r,a+5,1),Ci(r.d,a,d)&&(i=a+10,r=H(An(t.times(ze(p,i+n)),i),i+5,1),+_e(r.d).slice(a+1,a+15)+1==1e14&&(r=H(r,a+1,0)))),r.s=c,Y=!0,g.rounding=d,H(r,a,d))};R.toPrecision=function(t,i){var n,a=this,r=a.constructor;return t===void 0?n=Fe(a,a.e<=r.toExpNeg||a.e>=r.toExpPos):(Me(t,1,He),i===void 0?i=r.rounding:Me(i,0,8),a=H(new r(a),t,i),n=Fe(a,t<=a.e||a.e<=r.toExpNeg,t)),a.isNeg()&&!a.isZero()?"-"+n:n};R.toSignificantDigits=R.toSD=function(t,i){var n=this,a=n.constructor;return t===void 0?(t=a.precision,i=a.rounding):(Me(t,1,He),i===void 0?i=a.rounding:Me(i,0,8)),H(new a(n),t,i)};R.toString=function(){var t=this,i=t.constructor,n=Fe(t,t.e<=i.toExpNeg||t.e>=i.toExpPos);return t.isNeg()&&!t.isZero()?"-"+n:n};R.truncated=R.trunc=function(){return H(new this.constructor(this),this.e+1,1)};R.valueOf=R.toJSON=function(){var t=this,i=t.constructor,n=Fe(t,t.e<=i.toExpNeg||t.e>=i.toExpPos);return t.isNeg()?"-"+n:n};function _e(t){var i,n,a,r=t.length-1,d="",c=t[0];if(r>0){for(d+=c,i=1;i<r;i++)a=t[i]+"",n=V-a.length,n&&(d+=Ue(n)),d+=a;c=t[i],a=c+"",n=V-a.length,n&&(d+=Ue(n))}else if(c===0)return"0";for(;c%10===0;)c/=10;return d+c}function Me(t,i,n){if(t!==~~t||t<i||t>n)throw Error(Ze+t)}function Ci(t,i,n,a){var r,d,c,p;for(d=t[0];d>=10;d/=10)--i;return--i<0?(i+=V,r=0):(r=Math.ceil((i+1)/V),i%=V),d=de(10,V-i),p=t[r]%d|0,a==null?i<3?(i==0?p=p/100|0:i==1&&(p=p/10|0),c=n<4&&p==99999||n>3&&p==49999||p==5e4||p==0):c=(n<4&&p+1==d||n>3&&p+1==d/2)&&(t[r+1]/d/100|0)==de(10,i-2)-1||(p==d/2||p==0)&&(t[r+1]/d/100|0)==0:i<4?(i==0?p=p/1e3|0:i==1?p=p/100|0:i==2&&(p=p/10|0),c=(a||n<4)&&p==9999||!a&&n>3&&p==4999):c=((a||n<4)&&p+1==d||!a&&n>3&&p+1==d/2)&&(t[r+1]/d/1e3|0)==de(10,i-3)-1,c}function Hi(t,i,n){for(var a,r=[0],d,c=0,p=t.length;c<p;){for(d=r.length;d--;)r[d]*=i;for(r[0]+=kn.indexOf(t.charAt(c++)),a=0;a<r.length;a++)r[a]>n-1&&(r[a+1]===void 0&&(r[a+1]=0),r[a+1]+=r[a]/n|0,r[a]%=n)}return r.reverse()}function Wo(t,i){var n,a,r;if(i.isZero())return i;a=i.d.length,a<32?(n=Math.ceil(a/3),r=(1/en(4,n)).toString()):(n=16,r="2.3283064365386962890625e-10"),t.precision+=n,i=Mi(t,1,i.times(r),new t(1));for(var d=n;d--;){var c=i.times(i);i=c.times(c).minus(c).times(8).plus(1)}return t.precision-=n,i}var At=(function(){function t(a,r,d){var c,p=0,g=a.length;for(a=a.slice();g--;)c=a[g]*r+p,a[g]=c%d|0,p=c/d|0;return p&&a.unshift(p),a}function i(a,r,d,c){var p,g;if(d!=c)g=d>c?1:-1;else for(p=g=0;p<d;p++)if(a[p]!=r[p]){g=a[p]>r[p]?1:-1;break}return g}function n(a,r,d,c){for(var p=0;d--;)a[d]-=p,p=a[d]<r[d]?1:0,a[d]=p*c+a[d]-r[d];for(;!a[0]&&a.length>1;)a.shift()}return function(a,r,d,c,p,g){var y,k,C,P,N,q,L,K,W,O,J,vt,he,G,Pt,M,x,A,E,S,v=a.constructor,s=a.s==r.s?1:-1,e=a.d,o=r.d;if(!e||!e[0]||!o||!o[0])return new v(!a.s||!r.s||(e?o&&e[0]==o[0]:!o)?NaN:e&&e[0]==0||!o?s*0:s/0);for(g?(N=1,k=a.e-r.e):(g=Se,N=V,k=ve(a.e/N)-ve(r.e/N)),E=o.length,x=e.length,W=new v(s),O=W.d=[],C=0;o[C]==(e[C]||0);C++);if(o[C]>(e[C]||0)&&k--,d==null?(G=d=v.precision,c=v.rounding):p?G=d+(a.e-r.e)+1:G=d,G<0)O.push(1),q=!0;else{if(G=G/N+2|0,C=0,E==1){for(P=0,o=o[0],G++;(C<x||P)&&G--;C++)Pt=P*g+(e[C]||0),O[C]=Pt/o|0,P=Pt%o|0;q=P||C<x}else{for(P=g/(o[0]+1)|0,P>1&&(o=t(o,P,g),e=t(e,P,g),E=o.length,x=e.length),M=E,J=e.slice(0,E),vt=J.length;vt<E;)J[vt++]=0;S=o.slice(),S.unshift(0),A=o[0],o[1]>=g/2&&++A;do P=0,y=i(o,J,E,vt),y<0?(he=J[0],E!=vt&&(he=he*g+(J[1]||0)),P=he/A|0,P>1?(P>=g&&(P=g-1),L=t(o,P,g),K=L.length,vt=J.length,y=i(L,J,K,vt),y==1&&(P--,n(L,E<K?S:o,K,g))):(P==0&&(y=P=1),L=o.slice()),K=L.length,K<vt&&L.unshift(0),n(J,L,vt,g),y==-1&&(vt=J.length,y=i(o,J,E,vt),y<1&&(P++,n(J,E<vt?S:o,vt,g))),vt=J.length):y===0&&(P++,J=[0]),O[C++]=P,y&&J[0]?J[vt++]=e[M]||0:(J=[e[M]],vt=1);while((M++<x||J[0]!==void 0)&&G--);q=J[0]!==void 0}O[0]||O.shift()}if(N==1)W.e=k,Pr=q;else{for(C=1,P=O[0];P>=10;P/=10)C++;W.e=C+k*N-1,H(W,p?d+W.e+1:d,c,q)}return W}})();function H(t,i,n,a){var r,d,c,p,g,y,k,C,P,N=t.constructor;t:if(i!=null){if(C=t.d,!C)return t;for(r=1,p=C[0];p>=10;p/=10)r++;if(d=i-r,d<0)d+=V,c=i,k=C[P=0],g=k/de(10,r-c-1)%10|0;else if(P=Math.ceil((d+1)/V),p=C.length,P>=p)if(a){for(;p++<=P;)C.push(0);k=g=0,r=1,d%=V,c=d-V+1}else break t;else{for(k=p=C[P],r=1;p>=10;p/=10)r++;d%=V,c=d-V+r,g=c<0?0:k/de(10,r-c-1)%10|0}if(a=a||i<0||C[P+1]!==void 0||(c<0?k:k%de(10,r-c-1)),y=n<4?(g||a)&&(n==0||n==(t.s<0?3:2)):g>5||g==5&&(n==4||a||n==6&&(d>0?c>0?k/de(10,r-c):0:C[P-1])%10&1||n==(t.s<0?8:7)),i<1||!C[0])return C.length=0,y?(i-=t.e+1,C[0]=de(10,(V-i%V)%V),t.e=-i||0):C[0]=t.e=0,t;if(d==0?(C.length=P,p=1,P--):(C.length=P+1,p=de(10,V-d),C[P]=c>0?(k/de(10,r-c)%de(10,c)|0)*p:0),y)for(;;)if(P==0){for(d=1,c=C[0];c>=10;c/=10)d++;for(c=C[0]+=p,p=1;c>=10;c/=10)p++;d!=p&&(t.e++,C[0]==Se&&(C[0]=1));break}else{if(C[P]+=p,C[P]!=Se)break;C[P--]=0,p=1}for(d=C.length;C[--d]===0;)C.pop()}return Y&&(t.e>N.maxE?(t.d=null,t.e=NaN):t.e<N.minE&&(t.e=0,t.d=[0])),t}function Fe(t,i,n){if(!t.isFinite())return Rr(t);var a,r=t.e,d=_e(t.d),c=d.length;return i?(n&&(a=n-c)>0?d=d.charAt(0)+"."+d.slice(1)+Ue(a):c>1&&(d=d.charAt(0)+"."+d.slice(1)),d=d+(t.e<0?"e":"e+")+t.e):r<0?(d="0."+Ue(-r-1)+d,n&&(a=n-c)>0&&(d+=Ue(a))):r>=c?(d+=Ue(r+1-c),n&&(a=n-r-1)>0&&(d=d+"."+Ue(a))):((a=r+1)<c&&(d=d.slice(0,a)+"."+d.slice(a)),n&&(a=n-c)>0&&(r+1===c&&(d+="."),d+=Ue(a))),d}function tn(t,i){var n=t[0];for(i*=V;n>=10;n/=10)i++;return i}function Xi(t,i,n){if(i>Vo)throw Y=!0,n&&(t.precision=n),Error(Sr);return H(new t(Gi),i,1,!0)}function Ne(t,i,n){if(i>Cn)throw Error(Sr);return H(new t(Ji),i,n,!0)}function Or(t){var i=t.length-1,n=i*V+1;if(i=t[i],i){for(;i%10==0;i/=10)n--;for(i=t[0];i>=10;i/=10)n++}return n}function Ue(t){for(var i="";t--;)i+="0";return i}function Nr(t,i,n,a){var r,d=new t(1),c=Math.ceil(a/V+4);for(Y=!1;;){if(n%2&&(d=d.times(i),nr(d.d,c)&&(r=!0)),n=ve(n/2),n===0){n=d.d.length-1,r&&d.d[n]===0&&++d.d[n];break}i=i.times(i),nr(i.d,c)}return Y=!0,d}function ir(t){return t.d[t.d.length-1]&1}function Fr(t,i,n){for(var a,r,d=new t(i[0]),c=0;++c<i.length;){if(r=new t(i[c]),!r.s){d=r;break}a=d.cmp(r),(a===n||a===0&&d.s===n)&&(d=r)}return d}function An(t,i){var n,a,r,d,c,p,g,y=0,k=0,C=0,P=t.constructor,N=P.rounding,q=P.precision;if(!t.d||!t.d[0]||t.e>17)return new P(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:NaN);for(i==null?(Y=!1,g=q):g=i,p=new P(.03125);t.e>-2;)t=t.times(p),C+=5;for(a=Math.log(de(2,C))/Math.LN10*2+5|0,g+=a,n=d=c=new P(1),P.precision=g;;){if(d=H(d.times(t),g,1),n=n.times(++k),p=c.plus(At(d,n,g,1)),_e(p.d).slice(0,g)===_e(c.d).slice(0,g)){for(r=C;r--;)c=H(c.times(c),g,1);if(i==null)if(y<3&&Ci(c.d,g-a,N,y))P.precision=g+=10,n=d=p=new P(1),k=0,y++;else return H(c,P.precision=q,N,Y=!0);else return P.precision=q,c}c=p}}function ze(t,i){var n,a,r,d,c,p,g,y,k,C,P,N=1,q=10,L=t,K=L.d,W=L.constructor,O=W.rounding,J=W.precision;if(L.s<0||!K||!K[0]||!L.e&&K[0]==1&&K.length==1)return new W(K&&!K[0]?-1/0:L.s!=1?NaN:K?0:L);if(i==null?(Y=!1,k=J):k=i,W.precision=k+=q,n=_e(K),a=n.charAt(0),Math.abs(d=L.e)<15e14){for(;a<7&&a!=1||a==1&&n.charAt(1)>3;)L=L.times(t),n=_e(L.d),a=n.charAt(0),N++;d=L.e,a>1?(L=new W("0."+n),d++):L=new W(a+"."+n.slice(1))}else return y=Xi(W,k+2,J).times(d+""),L=ze(new W(a+"."+n.slice(1)),k-q).plus(y),W.precision=J,i==null?H(L,J,O,Y=!0):L;for(C=L,g=c=L=At(L.minus(1),L.plus(1),k,1),P=H(L.times(L),k,1),r=3;;){if(c=H(c.times(P),k,1),y=g.plus(At(c,new W(r),k,1)),_e(y.d).slice(0,k)===_e(g.d).slice(0,k))if(g=g.times(2),d!==0&&(g=g.plus(Xi(W,k+2,J).times(d+""))),g=At(g,new W(N),k,1),i==null)if(Ci(g.d,k-q,O,p))W.precision=k+=q,y=c=L=At(C.minus(1),C.plus(1),k,1),P=H(L.times(L),k,1),r=p=1;else return H(g,W.precision=J,O,Y=!0);else return W.precision=J,g;g=y,r+=2}}function Rr(t){return String(t.s*t.s/0)}function Ki(t,i){var n,a,r;for((n=i.indexOf("."))>-1&&(i=i.replace(".","")),(a=i.search(/e/i))>0?(n<0&&(n=a),n+=+i.slice(a+1),i=i.substring(0,a)):n<0&&(n=i.length),a=0;i.charCodeAt(a)===48;a++);for(r=i.length;i.charCodeAt(r-1)===48;--r);if(i=i.slice(a,r),i){if(r-=a,t.e=n=n-a-1,t.d=[],a=(n+1)%V,n<0&&(a+=V),a<r){for(a&&t.d.push(+i.slice(0,a)),r-=V;a<r;)t.d.push(+i.slice(a,a+=V));i=i.slice(a),a=V-i.length}else a-=r;for(;a--;)i+="0";t.d.push(+i),Y&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function Go(t,i){var n,a,r,d,c,p,g,y,k;if(i.indexOf("_")>-1){if(i=i.replace(/(\d)_(?=\d)/g,"$1"),Ir.test(i))return Ki(t,i)}else if(i==="Infinity"||i==="NaN")return+i||(t.s=NaN),t.e=NaN,t.d=null,t;if(Zo.test(i))n=16,i=i.toLowerCase();else if(zo.test(i))n=2;else if(Ho.test(i))n=8;else throw Error(Ze+i);for(d=i.search(/p/i),d>0?(g=+i.slice(d+1),i=i.substring(2,d)):i=i.slice(2),d=i.indexOf("."),c=d>=0,a=t.constructor,c&&(i=i.replace(".",""),p=i.length,d=p-d,r=Nr(a,new a(n),d,d*2)),y=Hi(i,n,Se),k=y.length-1,d=k;y[d]===0;--d)y.pop();return d<0?new a(t.s*0):(t.e=tn(y,k),t.d=y,Y=!1,c&&(t=At(t,r,p*4)),g&&(t=t.times(Math.abs(g)<54?de(2,g):Ai.pow(2,g))),Y=!0,t)}function Jo(t,i){var n,a=i.d.length;if(a<3)return i.isZero()?i:Mi(t,2,i,i);n=1.4*Math.sqrt(a),n=n>16?16:n|0,i=i.times(1/en(5,n)),i=Mi(t,2,i,i);for(var r,d=new t(5),c=new t(16),p=new t(20);n--;)r=i.times(i),i=i.times(d.plus(r.times(c.times(r).minus(p))));return i}function Mi(t,i,n,a,r){var d,c,p,g,y=1,k=t.precision,C=Math.ceil(k/V);for(Y=!1,g=n.times(n),p=new t(a);;){if(c=At(p.times(g),new t(i++*i++),k,1),p=r?a.plus(c):a.minus(c),a=At(c.times(g),new t(i++*i++),k,1),c=p.plus(a),c.d[C]!==void 0){for(d=C;c.d[d]===p.d[d]&&d--;);if(d==-1)break}d=p,p=a,a=c,c=d,y++}return Y=!0,c.d.length=C+1,c}function en(t,i){for(var n=t;--i;)n*=t;return n}function Dr(t,i){var n,a=i.s<0,r=Ne(t,t.precision,1),d=r.times(.5);if(i=i.abs(),i.lte(d))return De=a?4:1,i;if(n=i.divToInt(r),n.isZero())De=a?3:2;else{if(i=i.minus(n.times(r)),i.lte(d))return De=ir(n)?a?2:3:a?4:1,i;De=ir(n)?a?1:4:a?3:2}return i.minus(r).abs()}function Fn(t,i,n,a){var r,d,c,p,g,y,k,C,P,N=t.constructor,q=n!==void 0;if(q?(Me(n,1,He),a===void 0?a=N.rounding:Me(a,0,8)):(n=N.precision,a=N.rounding),!t.isFinite())k=Rr(t);else{for(k=Fe(t),c=k.indexOf("."),q?(r=2,i==16?n=n*4-3:i==8&&(n=n*3-2)):r=i,c>=0&&(k=k.replace(".",""),P=new N(1),P.e=k.length-c,P.d=Hi(Fe(P),10,r),P.e=P.d.length),C=Hi(k,10,r),d=g=C.length;C[--g]==0;)C.pop();if(!C[0])k=q?"0p+0":"0";else{if(c<0?d--:(t=new N(t),t.d=C,t.e=d,t=At(t,P,n,a,0,r),C=t.d,d=t.e,y=Pr),c=C[n],p=r/2,y=y||C[n+1]!==void 0,y=a<4?(c!==void 0||y)&&(a===0||a===(t.s<0?3:2)):c>p||c===p&&(a===4||y||a===6&&C[n-1]&1||a===(t.s<0?8:7)),C.length=n,y)for(;++C[--n]>r-1;)C[n]=0,n||(++d,C.unshift(1));for(g=C.length;!C[g-1];--g);for(c=0,k="";c<g;c++)k+=kn.charAt(C[c]);if(q){if(g>1)if(i==16||i==8){for(c=i==16?4:3,--g;g%c;g++)k+="0";for(C=Hi(k,r,i),g=C.length;!C[g-1];--g);for(c=1,k="1.";c<g;c++)k+=kn.charAt(C[c])}else k=k.charAt(0)+"."+k.slice(1);k=k+(d<0?"p":"p+")+d}else if(d<0){for(;++d;)k="0"+k;k="0."+k}else if(++d>g)for(d-=g;d--;)k+="0";else d<g&&(k=k.slice(0,d)+"."+k.slice(d))}k=(i==16?"0x":i==2?"0b":i==8?"0o":"")+k}return t.s<0?"-"+k:k}function nr(t,i){if(t.length>i)return t.length=i,!0}function Xo(t){return new this(t).abs()}function Qo(t){return new this(t).acos()}function Yo(t){return new this(t).acosh()}function ta(t,i){return new this(t).plus(i)}function ea(t){return new this(t).asin()}function ia(t){return new this(t).asinh()}function na(t){return new this(t).atan()}function ra(t){return new this(t).atanh()}function oa(t,i){t=new this(t),i=new this(i);var n,a=this.precision,r=this.rounding,d=a+4;return!t.s||!i.s?n=new this(NaN):!t.d&&!i.d?(n=Ne(this,d,1).times(i.s>0?.25:.75),n.s=t.s):!i.d||t.isZero()?(n=i.s<0?Ne(this,a,r):new this(0),n.s=t.s):!t.d||i.isZero()?(n=Ne(this,d,1).times(.5),n.s=t.s):i.s<0?(this.precision=d,this.rounding=1,n=this.atan(At(t,i,d,1)),i=Ne(this,d,1),this.precision=a,this.rounding=r,n=t.s<0?n.minus(i):n.plus(i)):n=this.atan(At(t,i,d,1)),n}function aa(t){return new this(t).cbrt()}function sa(t){return H(t=new this(t),t.e+1,2)}function la(t,i,n){return new this(t).clamp(i,n)}function ua(t){if(!t||typeof t!="object")throw Error(Yi+"Object expected");var i,n,a,r=t.defaults===!0,d=["precision",1,He,"rounding",0,8,"toExpNeg",-gi,0,"toExpPos",0,gi,"maxE",0,gi,"minE",-gi,0,"modulo",0,9];for(i=0;i<d.length;i+=3)if(n=d[i],r&&(this[n]=xn[n]),(a=t[n])!==void 0)if(ve(a)===a&&a>=d[i+1]&&a<=d[i+2])this[n]=a;else throw Error(Ze+n+": "+a);if(n="crypto",r&&(this[n]=xn[n]),(a=t[n])!==void 0)if(a===!0||a===!1||a===0||a===1)if(a)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Er);else this[n]=!1;else throw Error(Ze+n+": "+a);return this}function ha(t){return new this(t).cos()}function da(t){return new this(t).cosh()}function Br(t){var i,n,a;function r(d){var c,p,g,y=this;if(!(y instanceof r))return new r(d);if(y.constructor=r,rr(d)){y.s=d.s,Y?!d.d||d.e>r.maxE?(y.e=NaN,y.d=null):d.e<r.minE?(y.e=0,y.d=[0]):(y.e=d.e,y.d=d.d.slice()):(y.e=d.e,y.d=d.d?d.d.slice():d.d);return}if(g=typeof d,g==="number"){if(d===0){y.s=1/d<0?-1:1,y.e=0,y.d=[0];return}if(d<0?(d=-d,y.s=-1):y.s=1,d===~~d&&d<1e7){for(c=0,p=d;p>=10;p/=10)c++;Y?c>r.maxE?(y.e=NaN,y.d=null):c<r.minE?(y.e=0,y.d=[0]):(y.e=c,y.d=[d]):(y.e=c,y.d=[d]);return}if(d*0!==0){d||(y.s=NaN),y.e=NaN,y.d=null;return}return Ki(y,d.toString())}if(g==="string")return(p=d.charCodeAt(0))===45?(d=d.slice(1),y.s=-1):(p===43&&(d=d.slice(1)),y.s=1),Ir.test(d)?Ki(y,d):Go(y,d);if(g==="bigint")return d<0?(d=-d,y.s=-1):y.s=1,Ki(y,d.toString());throw Error(Ze+d)}if(r.prototype=R,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=ua,r.clone=Br,r.isDecimal=rr,r.abs=Xo,r.acos=Qo,r.acosh=Yo,r.add=ta,r.asin=ea,r.asinh=ia,r.atan=na,r.atanh=ra,r.atan2=oa,r.cbrt=aa,r.ceil=sa,r.clamp=la,r.cos=ha,r.cosh=da,r.div=ca,r.exp=fa,r.floor=pa,r.hypot=ma,r.ln=_a,r.log=ga,r.log10=va,r.log2=wa,r.max=ya,r.min=ba,r.mod=Ma,r.mul=ka,r.pow=xa,r.random=Ca,r.round=Aa,r.sign=Pa,r.sin=Sa,r.sinh=Ea,r.sqrt=Ta,r.sub=Ia,r.sum=Oa,r.tan=Na,r.tanh=Fa,r.trunc=Ra,t===void 0&&(t={}),t&&t.defaults!==!0)for(a=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],i=0;i<a.length;)t.hasOwnProperty(n=a[i++])||(t[n]=this[n]);return r.config(t),r}function ca(t,i){return new this(t).div(i)}function fa(t){return new this(t).exp()}function pa(t){return H(t=new this(t),t.e+1,3)}function ma(){var t,i,n=new this(0);for(Y=!1,t=0;t<arguments.length;)if(i=new this(arguments[t++]),i.d)n.d&&(n=n.plus(i.times(i)));else{if(i.s)return Y=!0,new this(1/0);n=i}return Y=!0,n.sqrt()}function rr(t){return t instanceof Ai||t&&t.toStringTag===Tr||!1}function _a(t){return new this(t).ln()}function ga(t,i){return new this(t).log(i)}function wa(t){return new this(t).log(2)}function va(t){return new this(t).log(10)}function ya(){return Fr(this,arguments,-1)}function ba(){return Fr(this,arguments,1)}function Ma(t,i){return new this(t).mod(i)}function ka(t,i){return new this(t).mul(i)}function xa(t,i){return new this(t).pow(i)}function Ca(t){var i,n,a,r,d=0,c=new this(1),p=[];if(t===void 0?t=this.precision:Me(t,1,He),a=Math.ceil(t/V),this.crypto)if(crypto.getRandomValues)for(i=crypto.getRandomValues(new Uint32Array(a));d<a;)r=i[d],r>=429e7?i[d]=crypto.getRandomValues(new Uint32Array(1))[0]:p[d++]=r%1e7;else if(crypto.randomBytes){for(i=crypto.randomBytes(a*=4);d<a;)r=i[d]+(i[d+1]<<8)+(i[d+2]<<16)+((i[d+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(i,d):(p.push(r%1e7),d+=4);d=a/4}else throw Error(Er);else for(;d<a;)p[d++]=Math.random()*1e7|0;for(a=p[--d],t%=V,a&&t&&(r=de(10,V-t),p[d]=(a/r|0)*r);p[d]===0;d--)p.pop();if(d<0)n=0,p=[0];else{for(n=-1;p[0]===0;n-=V)p.shift();for(a=1,r=p[0];r>=10;r/=10)a++;a<V&&(n-=V-a)}return c.e=n,c.d=p,c}function Aa(t){return H(t=new this(t),t.e+1,this.rounding)}function Pa(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function Sa(t){return new this(t).sin()}function Ea(t){return new this(t).sinh()}function Ta(t){return new this(t).sqrt()}function Ia(t,i){return new this(t).sub(i)}function Oa(){var t=0,i=arguments,n=new this(i[t]);for(Y=!1;n.s&&++t<i.length;)n=n.plus(i[t]);return Y=!0,H(n,this.precision,this.rounding)}function Na(t){return new this(t).tan()}function Fa(t){return new this(t).tanh()}function Ra(t){return H(t=new this(t),t.e+1,1)}R[Symbol.for("nodejs.util.inspect.custom")]=R.toString;R[Symbol.toStringTag]="Decimal";var Ai=R.constructor=Br(xn);Gi=new Ai(Gi);Ji=new Ai(Ji);var fe=Ai;function Qi(t){let i=xt.CoinAssist.isSuiCoin(t.coin_type_a),n=xt.CoinAssist.isSuiCoin(t.coin_type_b);return{is_adjust_coin_a:i,is_adjust_coin_b:n}}function Da(t,i){return fe.ceil(fe(t).div(1+i)).toString()}var ci=class{static createCollectRewarderAndFeeParams(t,i,n,a,r,d){r===void 0&&(r=[...a]),d===void 0&&(d=[...a]);let c=(0,xt.normalizeCoinType)(n.coin_type_a),p=(0,xt.normalizeCoinType)(n.coin_type_b);if(n.collect_fee){let y=xt.CoinAssist.buildCoinForAmount(i,r,BigInt(0),c,!1);r=y.remain_coins;let k=xt.CoinAssist.buildCoinForAmount(i,d,BigInt(0),p,!1);d=k.remain_coins,i=t.Position.createCollectFeePayload({pool_id:n.pool_id,pos_id:n.pos_id,coin_type_a:n.coin_type_a,coin_type_b:n.coin_type_b},i,y.target_coin,k.target_coin)}let g=[];return n.rewarder_coin_types.forEach(y=>{switch((0,xt.normalizeCoinType)(y)){case c:g.push(xt.CoinAssist.buildCoinForAmount(i,r,BigInt(0),y,!1).target_coin);break;case p:g.push(xt.CoinAssist.buildCoinForAmount(i,d,BigInt(0),y,!1).target_coin);break;default:g.push(xt.CoinAssist.buildCoinForAmount(i,a,BigInt(0),y,!1).target_coin);break}}),i=t.Rewarder.createCollectRewarderPayload(n,i,g),i}static async adjustTransactionForGas(t,i,n,a){a.setSender(t.getSenderAddress());let r=xt.CoinAssist.selectCoinAssetGreaterThanOrEqual(i,n).selected_coins,d=xt.CoinAssist.calculateTotalBalance(i);if(r.length===0&&et("InsufficientBalance",`Insufficient balance exceed amount ${n} real amount ${d}`),d-n>1e9)return{fixAmount:n};let c=await t.FullClient.calculationTxGas(Zi.Transaction.from(a));if(xt.CoinAssist.selectCoinAssetGreaterThanOrEqual(i,BigInt(c),r.map(p=>p.coin_object_id)).selected_coins.length===0){let p=BigInt(c)+BigInt(500);if(d-n<p){n-=p,n<0&&et("InsufficientBalance","gas Insufficient balance");let g=new Zi.Transaction;return{fixAmount:n,newTx:g}}}return{fixAmount:n}}static async buildAddLiquidityFixTokenForGas(t,i,n,a,r,d,c){r=await this.buildAddLiquidityFixToken(t,i,n,r,d,c);let{is_adjust_coin_a:p}=Qi(n),g=p?n.amount_a:n.amount_b,y=await this.adjustTransactionForGas(t,xt.CoinAssist.getCoinAssets(p?n.coin_type_a:n.coin_type_b,i),BigInt(g),r),{fixAmount:k}=y,C=y.newTx;if(C!=null){let P,N;if(p)n.amount_a=Number(k),P=this.buildAddLiquidityFixTokenCoinInput(C,!n.fix_amount_a,k.toString(),n.slippage,n.coin_type_a,i,!1,!0),N=this.buildAddLiquidityFixTokenCoinInput(C,n.fix_amount_a,n.amount_b,n.slippage,n.coin_type_b,i,!1,!0);else return n.amount_b=Number(k),P=this.buildAddLiquidityFixTokenCoinInput(C,!n.fix_amount_a,n.amount_a,n.slippage,n.coin_type_a,i,!1,!0),N=this.buildAddLiquidityFixTokenCoinInput(C,n.fix_amount_a,k.toString(),n.slippage,n.coin_type_b,i,!1,!0),n=this.fixAddLiquidityFixTokenParams(n,a.slippage,a.cur_sqrt_price),this.buildAddLiquidityFixTokenArgs(C,t,i,n,P,N)}return r}static async buildAddLiquidityFixToken(t,i,n,a,r,d){a=a||new Zi.Transaction;let c,p;return r==null||d==null?(c=this.buildAddLiquidityFixTokenCoinInput(a,!n.fix_amount_a,n.amount_a,n.slippage,n.coin_type_a,i,!1,!0),p=this.buildAddLiquidityFixTokenCoinInput(a,n.fix_amount_a,n.amount_b,n.slippage,n.coin_type_b,i,!1,!0)):(c={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},p={target_coin:d,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]}),a=this.buildAddLiquidityFixTokenArgs(a,t,i,n,c,p),a}static buildAddLiquidityFixTokenCoinInput(t,i,n,a,r,d,c=!0,p=!0){return i?xt.CoinAssist.buildCoinForAmountInterval(t,d,{amount_second:BigInt(Da(n,a)),amount_first:BigInt(n)},r,c,p):xt.CoinAssist.buildCoinForAmount(t,d,BigInt(n),r,c,p)}static fixAddLiquidityFixTokenParams(t,i,n){let a=t.fix_amount_a?t.amount_a:t.amount_b,r=xt.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(Number(t.tick_lower),Number(t.tick_upper),new Uo.default(a),t.fix_amount_a,!0,i,n);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,i,n,a,r,d){let c=[a.coin_type_a,a.coin_type_b],p=a.is_open?"open_position_with_liquidity_by_fix_coin":"add_liquidity_by_fix_coin",{clmm_pool:g,integrate:y}=i.sdkOptions;a.is_open||(t=this.createCollectRewarderAndFeeParams(i,t,a,n,r.remain_coins,d.remain_coins));let k=(0,xt.getPackagerConfigs)(g),C=a.is_open?[t.object(k.global_config_id),t.object(a.pool_id),t.pure.u32(Number((0,xt.asUintN)(BigInt(a.tick_lower)).toString())),t.pure.u32(Number((0,xt.asUintN)(BigInt(a.tick_upper)).toString())),r.target_coin,d.target_coin,t.pure.u64(a.amount_a),t.pure.u64(a.amount_b),t.pure.bool(a.fix_amount_a),t.object(xt.CLOCK_ADDRESS)]:[t.object(k.global_config_id),t.object(a.pool_id),t.object(a.pos_id),r.target_coin,d.target_coin,t.pure.u64(a.amount_a),t.pure.u64(a.amount_b),t.pure.bool(a.fix_amount_a),t.object(xt.CLOCK_ADDRESS)];return t.moveCall({target:`${y.published_at}::${vi}::${p}`,typeArguments:c,arguments:C}),t}static checkCoinThreshold(t,i,n,a,r,d){i&&n.moveCall({target:`${t.sdkOptions.integrate.published_at}::${Ar}::check_coin_threshold`,typeArguments:[d],arguments:[a,n.pure.u64(r)]})}},_i=class $e{static getDefaultSqrtPriceLimit(i){return new qo.default(i?kt.MIN_SQRT_PRICE:kt.MAX_SQRT_PRICE)}static getDefaultOtherAmountThreshold(i){return i?kt.ZERO:kt.U64_MAX}static async buildSwapTransactionForGas(i,n,a,r){let d=this.buildSwapTransaction(i,n,a);d.setSender(i.getSenderAddress());let c=await this.adjustTransactionForGas(i,kt.CoinAssist.getCoinAssets(n.a2b?n.coin_type_a:n.coin_type_b,a),BigInt(n.by_amount_in?n.amount:n.amount_limit),d),{fixAmount:p,newTx:g}=c;if(g!==void 0){g.setSender(i.getSenderAddress()),n.by_amount_in?n.amount=p.toString():n.amount_limit=p.toString(),n=await this.fixSwapParams(i,n,r);let y=kt.CoinAssist.buildCoinForAmount(d,a,n.a2b?BigInt(n.by_amount_in?n.amount:n.amount_limit):BigInt(0),n.coin_type_a),k=kt.CoinAssist.buildCoinForAmount(d,a,n.a2b?BigInt(0):BigInt(n.by_amount_in?n.amount:n.amount_limit),n.coin_type_b);d=this.buildSwapTransactionArgs(g,n,i.sdkOptions,y,k)}return d}static buildSwapTransactionArgs(i,n,a,r,d){let{clmm_pool:c,integrate:p}=a,g=$e.getDefaultSqrtPriceLimit(n.a2b),y=[n.coin_type_a,n.coin_type_b],{global_config_id:k}=(0,kt.getPackagerConfigs)(c);k===void 0&&et("InvalidConfig","clmm.config.global_config_id is undefined");let C=n.swap_partner!==void 0,P=C?n.a2b?"swap_a2b_with_partner":"swap_b2a_with_partner":n.a2b?"swap_a2b":"swap_b2a",N=C?[i.object(k),i.object(n.pool_id),i.object(n.swap_partner),r.target_coin,d.target_coin,i.pure.bool(n.by_amount_in),i.pure.u64(n.amount),i.pure.u64(n.amount_limit),i.pure.u128(g.toString()),i.object(kt.CLOCK_ADDRESS)]:[i.object(k),i.object(n.pool_id),r.target_coin,d.target_coin,i.pure.bool(n.by_amount_in),i.pure.u64(n.amount),i.pure.u64(n.amount_limit),i.pure.u128(g.toString()),i.object(kt.CLOCK_ADDRESS)];return i.moveCall({target:`${p.published_at}::${vi}::${P}`,typeArguments:y,arguments:N}),i}static async adjustTransactionForGas(i,n,a,r){r.setSender(i.getSenderAddress());let d=kt.CoinAssist.selectCoinAssetGreaterThanOrEqual(n,a).selected_coins,c=kt.CoinAssist.calculateTotalBalance(n);if(d.length===0&&et("InsufficientBalance",`Insufficient balance exceed amount ${a} real amount ${c}`),c-a>1e9)return{fixAmount:a};let p=await i.FullClient.calculationTxGas(r);if(kt.CoinAssist.selectCoinAssetGreaterThanOrEqual(n,BigInt(p),d.map(g=>g.coin_object_id)).selected_coins.length===0){let g=BigInt(p)+BigInt(500);if(c-a<g){a-=g,a<0&&et("InsufficientBalance","gas Insufficient balance");let y=new zi.Transaction;return{fixAmount:a,newTx:y}}}return{fixAmount:a}}static buildSwapTransaction(i,n,a){let r=new zi.Transaction;r.setSender(i.getSenderAddress());let d=kt.CoinAssist.buildCoinForAmount(r,a,n.a2b?BigInt(n.by_amount_in?n.amount:n.amount_limit):BigInt(0),n.coin_type_a,!1),c=kt.CoinAssist.buildCoinForAmount(r,a,n.a2b?BigInt(0):BigInt(n.by_amount_in?n.amount:n.amount_limit),n.coin_type_b,!1);return r=this.buildSwapTransactionArgs(r,n,i.sdkOptions,d,c),r}static async fixSwapParams(i,n,a){let{current_pool:r}=a;try{let d=await i.Swap.preSwap({decimals_a:a.decimals_a,decimals_b:a.decimals_b,a2b:n.a2b,by_amount_in:n.by_amount_in,amount:n.amount,pool:r,current_sqrt_price:r.current_sqrt_price,coin_type_a:r.coin_type_a,coin_type_b:r.coin_type_b}),c=a.by_amount_in?d.estimated_amount_out:d.estimated_amount_in,p=(0,kt.adjustForSlippage)(c,a.slippage,!a.by_amount_in);n.amount_limit=p.toString()}catch(d){Be("InvalidConfig",d)}return n}static async buildSwapTransactionWithoutTransferCoinsForGas(i,n,a,r){let{tx:d,coin_ab_s:c}=$e.buildSwapTransactionWithoutTransferCoins(i,n,a);d.setSender(i.getSenderAddress());let p=await $e.adjustTransactionForGas(i,kt.CoinAssist.getCoinAssets(n.a2b?n.coin_type_a:n.coin_type_b,a),BigInt(n.by_amount_in?n.amount:n.amount_limit),d),{fixAmount:g,newTx:y}=p;if(y!==void 0){y.setSender(i.getSenderAddress()),n.by_amount_in?n.amount=g.toString():n.amount_limit=g.toString(),n=await $e.fixSwapParams(i,n,r);let k=kt.CoinAssist.buildCoinForAmount(d,a,n.a2b?BigInt(n.by_amount_in?n.amount:n.amount_limit):BigInt(0),n.coin_type_a,!1,!0),C=kt.CoinAssist.buildCoinForAmount(d,a,n.a2b?BigInt(0):BigInt(n.by_amount_in?n.amount:n.amount_limit),n.coin_type_b,!1,!0),P=$e.buildSwapTransactionWithoutTransferCoinArgs(i,y,n,i.sdkOptions,k,C);d=P.tx,c=P.txRes}return{tx:d,coin_ab_s:c}}static buildSwapTransactionWithoutTransferCoins(i,n,a){let r=new zi.Transaction;r.setSender(i.getSenderAddress());let d=kt.CoinAssist.buildCoinForAmount(r,a,n.a2b?BigInt(n.by_amount_in?n.amount:n.amount_limit):BigInt(0),n.coin_type_a,!1,!0),c=kt.CoinAssist.buildCoinForAmount(r,a,n.a2b?BigInt(0):BigInt(n.by_amount_in?n.amount:n.amount_limit),n.coin_type_b,!1,!0),p=$e.buildSwapTransactionWithoutTransferCoinArgs(i,r,n,i.sdkOptions,d,c);return{tx:p.tx,coin_ab_s:p.txRes}}static buildSwapTransactionWithoutTransferCoinArgs(i,n,a,r,d,c){let{clmm_pool:p,integrate:g}=r,y=$e.getDefaultSqrtPriceLimit(a.a2b),{global_config_id:k}=(0,kt.getPackagerConfigs)(p);k===void 0&&et("InvalidConfig","clmm.config.global_config_id is undefined");let C=a.swap_partner!==void 0,P=C?"swap_with_partner":"swap",N=C?Lo:Ar,q=C?[n.object(k),n.object(a.pool_id),n.object(a.swap_partner),d.target_coin,c.target_coin,n.pure.bool(a.a2b),n.pure.bool(a.by_amount_in),n.pure.u64(a.amount),n.pure.u128(y.toString()),n.pure.bool(!1),n.object(kt.CLOCK_ADDRESS)]:[n.object(k),n.object(a.pool_id),d.target_coin,c.target_coin,n.pure.bool(a.a2b),n.pure.bool(a.by_amount_in),n.pure.u64(a.amount),n.pure.u128(y.toString()),n.pure.bool(!1),n.object(kt.CLOCK_ADDRESS)],L=[a.coin_type_a,a.coin_type_b],K=n.moveCall({target:`${g.published_at}::${N}::${P}`,typeArguments:L,arguments:q});if(a.by_amount_in){let W=a.a2b?a.coin_type_b:a.coin_type_a,O=a.a2b?K[1]:K[0],J=Number(a.amount_limit);ci.checkCoinThreshold(i,a.by_amount_in,n,O,J,W)}return{tx:n,txRes:K}}};function Ba(t){return{coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,current_sqrt_price:new Oe.default(t.current_sqrt_price),current_tick_index:t.current_tick_index,fee_growth_global_a:new Oe.default(t.fee_growth_global_a),fee_growth_global_b:new Oe.default(t.fee_growth_global_b),fee_protocol_coin_a:new Oe.default(t.fee_protocol_coin_a),fee_protocol_coin_b:new Oe.default(t.fee_protocol_coin_b),fee_rate:new Oe.default(t.fee_rate),liquidity:new Oe.default(t.liquidity),tick_indexes:[],tick_spacing:Number(t.tick_spacing),ticks:[],collection_name:""}}function qa(t,i,n,a,r,d){if(n===Mt.ZERO)return{amount_in:Mt.ZERO,amount_out:Mt.ZERO,next_sqrt_price:i,fee_amount:Mt.ZERO};let c=t.gte(i),p,g,y,k;if(d){let C=Mt.MathUtil.checkMulDivFloor(a,Mt.MathUtil.checkUnsignedSub(Mt.FEE_RATE_DENOMINATOR,r),Mt.FEE_RATE_DENOMINATOR,64),P=(0,Mt.getDeltaUpFromInput)(t,i,n,c);P.gt(C)?(p=C,k=Mt.MathUtil.checkUnsignedSub(a,C),y=(0,Mt.getNextSqrtPriceFromInput)(t,n,C,c)):(p=P,k=Mt.MathUtil.checkMulDivCeil(p,r,Mt.FEE_RATE_DENOMINATOR.sub(r),64),y=i),g=(0,Mt.getDeltaDownFromOutput)(t,y,n,c)}else{let C=(0,Mt.getDeltaDownFromOutput)(t,i,n,c);C.gt(a)?(g=a,y=(0,Mt.getNextSqrtPriceFromOutput)(t,n,a,c)):(g=C,y=i),p=(0,Mt.getDeltaUpFromInput)(t,y,n,c),k=Mt.MathUtil.checkMulDivCeil(p,r,Mt.FEE_RATE_DENOMINATOR.sub(r),64)}return{amount_in:p,amount_out:g,next_sqrt_price:y,fee_amount:k}}function ja(t,i,n,a,r){let d=n,c=a.liquidity,{current_sqrt_price:p}=a,g={amount_in:Mt.ZERO,amount_out:Mt.ZERO,fee_amount:Mt.ZERO,ref_amount:Mt.ZERO,next_sqrt_price:Mt.ZERO,cross_tick_num:0},y,k,C=_i.getDefaultSqrtPriceLimit(t);for(let P of r){if(t&&a.current_tick_index<P.index||!t&&a.current_tick_index>=P.index||P===null)continue;t&&C.gt(P.sqrt_price)||!t&&C.lt(P.sqrt_price)?y=C:y=P.sqrt_price;let N=qa(p,y,c,d,a.fee_rate,i);if(N.amount_in.eq(Mt.ZERO)||(d=i?d.sub(N.amount_in.add(N.fee_amount)):d.sub(N.amount_out)),g.amount_in=g.amount_in.add(N.amount_in),g.amount_out=g.amount_out.add(N.amount_out),g.fee_amount=g.fee_amount.add(N.fee_amount),N.next_sqrt_price.eq(P.sqrt_price)?(k=P.liquidity_net.mul(new Oe.default(-1)),t?Mt.MathUtil.is_neg(k)?c=c.add(new Oe.default((0,Mt.asUintN)(BigInt(k.toString()),128))):c=c.add(k):Mt.MathUtil.is_neg(k)?c=c.sub(new Oe.default((0,Mt.asUintN)(BigInt(k.toString()),128))):c=c.sub(k),p=P.sqrt_price):p=N.next_sqrt_price,g.cross_tick_num+=1,d.eq(Mt.ZERO))break}return g.amount_in=g.amount_in.add(g.fee_amount),g.next_sqrt_price=p,g}var Pe=qe(je());function La(t,i,n){let a=(0,X.extractStructTagFromType)(t).name,r=(0,X.extractStructTagFromType)(i).name;return`${a}-${r}[${n}]`}function wn(t){let i=(0,X.getMoveObjectType)(t),n=(0,X.extractStructTagFromType)(i),a=(0,X.getObjectFields)(t);a==null&&et("InvalidPoolObject",`Pool id ${(0,X.getObjectId)(t)} not exists.`,{[X.DETAILS_KEYS.METHOD_NAME]:"buildPool"});let r=[];a.rewarder_manager.fields.rewarders.forEach(g=>{let{emissions_per_second:y}=g.fields,k=X.MathUtil.fromX64(new Pe.default(y)),C=Math.floor(k.toNumber()*60*60*24);r.push({emissions_per_second:y,coin_type:(0,X.extractStructTagFromType)(g.fields.reward_coin.fields.name).source_address,growth_global:g.fields.growth_global,emissions_every_day:C})});let d=a.is_pause,c={disable_add_liquidity:d,disable_remove_liquidity:d,disable_swap:d,disable_flash_loan:d,disable_collect_fee:d,disable_collect_reward:d},p={id:(0,X.getObjectId)(t),pool_type:i,coin_type_a:n.type_arguments[0],coin_type_b:n.type_arguments[1],coin_amount_a:a.coin_a,coin_amount_b:a.coin_b,current_sqrt_price:a.current_sqrt_price,current_tick_index:(0,X.asIntN)(BigInt(a.current_tick_index.fields.bits)),fee_growth_global_a:a.fee_growth_global_a,fee_growth_global_b:a.fee_growth_global_b,fee_protocol_coin_a:a.fee_protocol_coin_a,fee_protocol_coin_b:a.fee_protocol_coin_b,fee_rate:a.fee_rate,pool_status:c,liquidity:a.liquidity,position_manager:{positions_handle:a.position_manager.fields.positions.fields.id.id,size:a.position_manager.fields.positions.fields.size},rewarder_infos:r,rewarder_last_updated_time:a.rewarder_manager.fields.last_updated_time,tick_spacing:a.tick_spacing,ticks_handle:a.tick_manager.fields.ticks.fields.id.id,uri:a.url,index:Number(a.index),name:""};return p.name=La(p.coin_type_a,p.coin_type_b,p.tick_spacing),p}function vn(t){(t.error!=null||t.data?.content?.dataType!=="moveObject")&&et("InvalidPositionObject",`Position not exists. Get Position error:${t.error}`,{[X.DETAILS_KEYS.METHOD_NAME]:"buildPosition"});let i={creator:"",description:"",image_url:"",link:"",name:"",project_url:""},n={...i,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"},a=(0,X.getObjectFields)(t);if(a){let c=(0,X.getMoveObjectType)(t),p=(0,X.getObjectOwner)(t);"nft"in a?(a=a.nft.fields,i.description=a.description,i.name=a.name,i.link=a.url):i=(0,X.buildNFT)(t),n={...i,pos_object_id:a.id.id,owner:p.AddressOwner,type:c,liquidity:a.liquidity,coin_type_a:a.coin_type_a.fields.name,coin_type_b:a.coin_type_b.fields.name,tick_lower_index:(0,X.asIntN)(BigInt(a.tick_lower_index.fields.bits)),tick_upper_index:(0,X.asIntN)(BigInt(a.tick_upper_index.fields.bits)),index:a.index,pool:a.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 r=(0,X.getObjectDeletedResponse)(t);r&&(n.pos_object_id=r.objectId,n.position_status="Deleted");let d=(0,X.getObjectNotExistsResponse)(t);return d&&(n.pos_object_id=d,n.position_status="NotExists"),n}function Pn(t){let i={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"};t="fields"in t?t.fields:t,t.rewards.forEach((r,d)=>{let{amount_owned:c,growth_inside:p}="fields"in r?r.fields:r;d===0?(i.reward_amount_owned_0=c,i.reward_growth_inside_0=p):d===1?(i.reward_amount_owned_1=c,i.reward_growth_inside_1=p):d===2&&(i.reward_amount_owned_2=c,i.reward_growth_inside_2=p)});let n="fields"in t.tick_lower_index?t.tick_lower_index.fields.bits:t.tick_lower_index.bits,a="fields"in t.tick_upper_index?t.tick_upper_index.fields.bits:t.tick_upper_index.bits;return{liquidity:t.liquidity,tick_lower_index:(0,X.asIntN)(BigInt(n)),tick_upper_index:(0,X.asIntN)(BigInt(a)),...i,fee_growth_inside_a:t.fee_growth_inside_a,fee_owned_a:t.fee_owned_a,fee_growth_inside_b:t.fee_growth_inside_b,fee_owned_b:t.fee_owned_b,pos_object_id:t.position_id}}function yn(t){(t.error!=null||t.data?.content?.dataType!=="moveObject")&&et("InvalidTickObject",`Tick not exists. Get tick data error:${t.error}`,{[X.DETAILS_KEYS.METHOD_NAME]:"buildTickData"});let i=(0,X.getObjectFields)(t).value.fields.value.fields;return{object_id:(0,X.getObjectId)(t),index:(0,X.asIntN)(BigInt(i.index.fields.bits)),sqrt_price:new Pe.default(i.sqrt_price),liquidity_net:new Pe.default(i.liquidity_net.fields.bits),liquidity_gross:new Pe.default(i.liquidity_gross),fee_growth_outside_a:new Pe.default(i.fee_growth_outside_a),fee_growth_outside_b:new Pe.default(i.fee_growth_outside_b),rewarders_growth_outside:i.rewards_growth_outside}}function $a(t){(!t||!t.index||!t.sqrt_price||!t.liquidity_net||!t.liquidity_gross||!t.fee_growth_outside_a||!t.fee_growth_outside_b)&&et("InvalidTickFields","Invalid tick fields.",{[X.DETAILS_KEYS.METHOD_NAME]:"buildTickDataByEvent"});let i=(0,X.asIntN)(BigInt(t.index.bits)),n=new Pe.default(t.sqrt_price),a=new Pe.default(t.liquidity_net.bits),r=new Pe.default(t.liquidity_gross),d=new Pe.default(t.fee_growth_outside_a),c=new Pe.default(t.fee_growth_outside_b),p=t.rewards_growth_outside||[];return{object_id:"",index:i,sqrt_price:n,liquidity_net:a,liquidity_gross:r,fee_growth_outside_a:d,fee_growth_outside_b:c,rewarders_growth_outside:p}}function Ua(t,i,n){let a=[],{timestampMs:r,events:d}=t,c=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent"];return d?.forEach((p,g)=>{let y=(0,X.extractStructTagFromType)(p.type).name;if(c.includes(y)){let k={tx_digest:p.id.txDigest,package_id:p.packageId,transaction_module:p.transactionModule,sender:p.sender,type:p.type,timestamp_ms:r||"0",parsed_json:p.parsedJson,index:`${i}_${g}`};switch(y){case"CollectFeeEvent":n.includes(k.parsed_json.position)&&((0,X.d)(k.parsed_json.amount_a).gt(0)||(0,X.d)(k.parsed_json.amount_b).gt(0))&&a.push(k);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":((0,X.d)(k.parsed_json.amount_a).gt(0)||(0,X.d)(k.parsed_json.amount_b).gt(0))&&a.push(k);break;case"CollectRewardEvent":case"HarvestEvent":case"CollectRewardV2Event":(n.includes(k.parsed_json.position)||n.includes(k.parsed_json.wrapped_position_id))&&(0,X.d)(k.parsed_json.amount).gt(0)&&a.push(k);break;default:break}}}),a}function za(t,i,n,a){let r=[],{timestampMs:d,events:c}=t;return c?.forEach((p,g)=>{let{name:y,address:k}=(0,X.extractStructTagFromType)(p.type);if(Bo.includes(y)&&k===n&&a===p.parsedJson.pool){let C={tx:p.id.txDigest,sender:p.sender,type:p.type,block_time:d||"0",index:`${i}_${g}`,parsed_json:p.parsedJson};r.push(C)}}),r}function Sn(t,i,n,a){i.moveCall({target:`${t.sdkOptions.integrate.published_at}::${$o}::transfer_coin_to_sender`,typeArguments:[a],arguments:[n]})}function Za(t,i,n,a,r){r!=null?i.transferObjects([n],i.pure.address(r)):Sn(t,i,n,a)}var Ha=1e4,yi=class{static parseClmmVestInfo(t){let i=(0,ge.getObjectFields)(t),n=(0,ge.getObjectType)(t),a=(0,ge.extractStructTagFromType)(n),r=i.global_vesting_periods.map(d=>({period:d.fields.period,release_time:d.fields.release_time,redeemed_amount:d.fields.redeemed_amount,percentage:(0,ge.d)(d.fields.percentage).div(Ha).toNumber()}));return{id:i.id.id,balance:i.balance,global_vesting_periods:r,total_value:i.total_value,total_cetus_amount:i.total_cetus_amount,redeemed_amount:i.redeemed_amount,start_time:i.start_time,type:a.full_address,positions:{id:i.positions.fields.id,size:i.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,ge.fixCoinType)(t.coin_a.name,!1),coin_type_b:(0,ge.fixCoinType)(t.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(t){let i=(0,ge.getObjectFields)(t);return{current_sqrt_price:i.current_sqrt_price,remove_percent:(0,ge.d)(i.remove_percent).div(1e6).toString(),snapshots:{id:i.snapshots.fields.id.id,size:i.snapshots.fields.size}}}static parsePositionSnapshot(t){let i=(0,ge.getObjectFields)(t),n=i.value.fields.value.fields;return{position_id:i.name,liquidity:n.liquidity,tick_lower_index:(0,ge.asIntN)(BigInt(n.tick_lower_index.fields.bits)),tick_upper_index:(0,ge.asIntN)(BigInt(n.tick_upper_index.fields.bits)),fee_owned_a:n.fee_owned_a,fee_owned_b:n.fee_owned_b,value_cut:n.value_cut,rewards:n.rewards}}},Ka=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}async getPositionList(t,i="all"){let n={data:[],has_next_page:!0},a=await this._sdk.FullClient.getDynamicFieldsByPage(t,i);n.has_next_page=a.has_next_page,n.next_cursor=a.next_cursor;let r=a.data.map(c=>(c.error!=null&&et("InvalidConfig",`when getPositionList get position objects error: ${c.error}, please check the rpc, contracts address config and position id.`,{[D.DETAILS_KEYS.METHOD_NAME]:"getPositionList"}),c.name.value)),d=await this._sdk.Position.getSimplePositionList(r);return n.data=d,n}async getPoolImmutablesWithPage(t="all",i=!1){let{package_id:n}=this._sdk.sdkOptions.clmm_pool,a=[],r={data:[],has_next_page:!1},d=t==="all",c=`${n}_getPoolImmutables`;if(d){let p=this._sdk.getCache(c,i);p&&a.push(...p)}if(a.length===0)try{let p=`${n}::factory::CreatePoolEvent`,g=await this._sdk.FullClient.queryEventsByPage({MoveEventType:p},t);r.has_next_page=g.has_next_page,r.next_cursor=g.next_cursor,g.data.forEach(y=>{let k=y.parsedJson;k&&a.push({id:k.pool_id,tick_spacing:k.tick_spacing,coin_type_a:(0,D.extractStructTagFromType)(k.coin_type_a).full_address,coin_type_b:(0,D.extractStructTagFromType)(k.coin_type_b).full_address})})}catch(p){return Be("FetchError",p,{[D.DETAILS_KEYS.METHOD_NAME]:"getPoolImmutables"})}return r.data=a,d&&this._sdk.updateCache(`${n}_getPoolImmutables`,a,D.CACHE_TIME_24H),r}async getPoolsWithPage(t="all",i=!1){let n={data:[],has_next_page:!1},a=await this.getPoolImmutablesWithPage(t,i),r=await this._sdk.FullClient.batchGetObjects(a.data.map(d=>d.id),{showContent:!0,showType:!0});for(let d of r){(d.error!=null||d.data?.content?.dataType!=="moveObject")&&et("InvalidPoolObject",`getPoolWithPages error code: ${d.error?.code??"unknown error"}, please check config and object ids`,{[D.DETAILS_KEYS.METHOD_NAME]:"getPoolsWithPage"});let c=wn(d);n.data.push(c);let p=`${c.id}_getPoolObject`;this._sdk.updateCache(p,c,D.CACHE_TIME_24H)}return n.has_next_page=a.has_next_page,n.next_cursor=a.next_cursor,n}async getPoolLiquiditySnapshot(t,i=!1){try{let n=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x1::string::String",value:Ro}}),a=yi.parsePoolLiquiditySnapshot(n);if(i){let r=(await this._sdk.FullClient.getDynamicFieldsByPage(a.snapshots.id)).data.map(d=>d.objectId);if(r.length>0){let d=await this._sdk.FullClient.batchGetObjects(r,{showContent:!0,showType:!0}),c=[];d.forEach(p=>{let g=yi.parsePositionSnapshot(p);c.push(g)}),a.position_snapshots=c}}return a}catch(n){return Be("InvalidPoolObject",n,{[D.DETAILS_KEYS.METHOD_NAME]:"getPoolLiquiditySnapshot",[D.DETAILS_KEYS.REQUEST_PARAMS]:t})}}async getPositionSnapshot(t,i){let n=await this._sdk.FullClient.getDynamicFieldObjects(t,i,"0x2::object::ID","address"),a=[];return n.forEach(r=>{try{let d=yi.parsePositionSnapshot(r);a.push(d)}catch(d){console.log("getPositionSnapshot error: ",d)}}),a}async getAssignPools(t){if(t.length===0)return[];let i=[],n=await this._sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let a of n){(a.error!=null||a.data?.content?.dataType!=="moveObject")&&et("InvalidPoolObject",`getPools error code: ${a.error?.code??"unknown error"}, please check config and object ids`,{[D.DETAILS_KEYS.METHOD_NAME]:"getAssignPools"});let r=wn(a);i.push(r);let d=`${r.id}_getPoolObject`;this._sdk.updateCache(d,r,D.CACHE_TIME_24H)}return i}async getPool(t,i=!0,n=!1){let a=`${t}_getPoolObject`,r=this._sdk.getCache(a,i);if(r!==void 0)return r;let d=await this._sdk.FullClient.getObject({id:t,options:{showType:!0,showContent:!0}});(d.error!=null||d.data?.content?.dataType!=="moveObject")&&et("InvalidPoolObject",`getPool error code: ${d.error?.code??"unknown error"}, please check config and object id`,{[D.DETAILS_KEYS.METHOD_NAME]:"getPool"});let c=wn(d);if(n){let p=await this.getPoolStatus(t);p&&(c.pool_status=p)}return this._sdk.updateCache(a,c),c}async getPoolByCoins(t,i){if(t.length===0)return[];for(let p=0;p<t.length;p++)t[p]==="0x2::sui::SUI"&&(t[p]="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI");let n=this._sdk.sdkOptions.stats_pools_url;n||et("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[D.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins"}),n+=`?order_by=-fees&limit=100&has_mining=true&has_farming=true&no_incentives=true&display_all_pools=true&coin_type=${t.join(",")}`;let a=await fetch(n),r;try{r=await a.json()}catch(p){Be("FetchError",p,{[D.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins",[D.DETAILS_KEYS.REQUEST_PARAMS]:n})}let d=r.data.lp_list,c=[];for(let p of d)t.includes(p.coin_a_address)&&t.includes(p.coin_b_address)&&(i!=null?p.object.feeRate===i&&c.push(p.address):c.push(p.address));return c.length>0?await this.getAssignPools(c):[]}async createPoolPayload(t,i){if((0,D.isSortedSymbols)((0,di.normalizeSuiAddress)(t.coin_type_a),(0,di.normalizeSuiAddress)(t.coin_type_b))){let n=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=n;let a=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=a}return await this.createPoolAndAddLiquidity(t,i)}async createPoolRowPayload(t,i){if((0,D.isSortedSymbols)((0,di.normalizeSuiAddress)(t.coin_type_a),(0,di.normalizeSuiAddress)(t.coin_type_b))){let n=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=n;let a=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=a}return await this.createPoolAndAddLiquidityRow(t,i)}async getClmmConfigs(t=!1){let{package_id:i}=this._sdk.sdkOptions.clmm_pool,n=`${i}_getInitEvent`,a=this._sdk.getCache(n,t);if(a!==void 0)return a;let r=await this._sdk.FullClient.getObject({id:i,options:{showPreviousTransaction:!0}}),d=(0,D.getObjectPreviousTransactionDigest)(r),c=(await this._sdk.FullClient.queryEventsByPage({Transaction:d})).data,p={pools_id:"",global_config_id:"",global_vault_id:"",admin_cap_id:""};return c.length>0&&(c.forEach(g=>{let y=g.parsedJson;if(g.type)switch((0,D.extractStructTagFromType)(g.type).full_address){case`${i}::config::InitConfigEvent`:p.global_config_id=y.global_config_id,p.admin_cap_id=y.admin_cap_id;break;case`${i}::factory::InitFactoryEvent`:p.pools_id=y.pools_id;break;case`${i}::rewarder::RewarderInitEvent`:p.global_vault_id=y.global_vault_id;break;case`${i}::partner::InitPartnerEvent`:p.partners_id=y.partners_id;break;default:break}}),this._sdk.updateCache(n,p,D.CACHE_TIME_24H)),p}async getPoolTransactionList({pool_id:t,pagination_args:i,order:n="descending",full_rpc_url:a}){let{FullClient:r,sdkOptions:d}=this._sdk,c;a?c=(0,D.createFullClient)(new xr.SuiClient({url:a})):c=r;let p={data:[],has_next_page:!1},g=50,y=i,k=i.limit||10;do{let C=await c.queryTransactionBlocksByPage({ChangedObject:t},{...y,limit:50},n);C.data.forEach((P,N)=>{p.next_cursor=C.next_cursor;let q=za(P,N,d.clmm_pool.package_id,t);p.data=[...p.data,...q]}),p.has_next_page=C.has_next_page,p.next_cursor=C.next_cursor,y.cursor=C.next_cursor}while(p.data.length<k&&p.has_next_page);return p.data.length>k&&(p.data=p.data.slice(0,k),p.next_cursor=p.data[p.data.length-1].tx),p}async calculateCreatePoolWithPrice(t){let{current_price:i,slippage:n,tick_spacing:a,add_mode_params:r,price_base_coin:d,coin_decimals_a:c,coin_decimals_b:p}=t,g=D.TickMath.priceToSqrtPriceX64(d==="coin_a"?(0,D.d)(i):(0,D.d)(1).div(i),c,p),y=0,k=0;if(r.is_full_range)y=D.TickUtil.getMinIndex(a),k=D.TickUtil.getMaxIndex(a);else{let{min_price:O,max_price:J}=r;y=D.TickMath.priceToInitializeTickIndex(d==="coin_a"?(0,D.d)(O):(0,D.d)(1).div(J),c,p,a),k=D.TickMath.priceToInitializeTickIndex(d==="coin_a"?(0,D.d)(J):(0,D.d)(1).div(O),c,p,a)}let{coin_amount:C,fix_amount_a:P}=t,{coin_amount_limit_a:N,coin_amount_limit_b:q,liquidity_amount:L,coin_amount_a:K,coin_amount_b:W}=D.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(y,k,new Fo.default(C),P,!0,n,g);return{coin_amount_a:K,coin_amount_b:W,coin_amount_limit_a:N,coin_amount_limit_b:q,liquidity:L,initialize_sqrt_price:g.toString(),tick_lower:y,tick_upper:k,fix_amount_a:P}}async createPoolAndAddLiquidity(t,i){i=i||new mi.Transaction,i.setSender(this.sdk.getSenderAddress());let{integrate:n,clmm_pool:a}=this.sdk.sdkOptions,r=(0,D.getPackagerConfigs)(a),d=r.global_config_id,c=r.pools_id,p=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),g=D.CoinAssist.buildCoinForAmount(i,p,BigInt(t.amount_a),t.coin_type_a,!1,!0),y=D.CoinAssist.buildCoinForAmount(i,p,BigInt(t.amount_b),t.coin_type_b,!1,!0),k=[i.object(d),i.object(c),i.pure.u32(t.tick_spacing),i.pure.u128(t.initialize_sqrt_price),i.pure.string(t.uri),i.pure.u32(Number((0,D.asUintN)(BigInt(t.tick_lower)).toString())),i.pure.u32(Number((0,D.asUintN)(BigInt(t.tick_upper)).toString())),g.target_coin,y.target_coin,i.object(t.metadata_a),i.object(t.metadata_b),i.pure.bool(t.fix_amount_a),i.object(D.CLOCK_ADDRESS)];return i.moveCall({target:`${n.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:k}),Sn(this._sdk,i,g.target_coin,t.coin_type_a),Sn(this._sdk,i,y.target_coin,t.coin_type_b),i}async createPoolAndAddLiquidityRow(t,i){i=i||new mi.Transaction;let{clmm_pool:n}=this.sdk.sdkOptions,a=(0,D.getPackagerConfigs)(n),r=a.global_config_id,d=a.pools_id,c=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),p=D.CoinAssist.buildCoinForAmount(i,c,BigInt(t.amount_a),t.coin_type_a,!1,!0),g=D.CoinAssist.buildCoinForAmount(i,c,BigInt(t.amount_b),t.coin_type_b,!1,!0),y=[i.object(r),i.object(d),i.pure.u32(t.tick_spacing),i.pure.u128(t.initialize_sqrt_price),i.pure.string(t.uri),i.pure.u32(Number((0,D.asUintN)(BigInt(t.tick_lower)).toString())),i.pure.u32(Number((0,D.asUintN)(BigInt(t.tick_upper)).toString())),p.target_coin,g.target_coin,i.object(t.metadata_a),i.object(t.metadata_b),i.pure.bool(t.fix_amount_a),i.object(D.CLOCK_ADDRESS)],k=i.moveCall({target:`${n.published_at}::pool_creator::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:y});return{tx:i,pos_id:k[0],remain_coin_a:k[1],remain_coin_b:k[2],remain_coin_type_a:t.coin_type_a,remain_coin_type_b:t.coin_type_b}}async createPoolWithPriceReturnPositionPayload(t,i){let{coin_type_a:n,coin_type_b:a,tick_spacing:r,uri:d,calculate_result:c}=t,{initialize_sqrt_price:p,tick_lower:g,tick_upper:y,liquidity:k,coin_amount_a:C,coin_amount_b:P,fix_amount_a:N,coin_amount_limit_a:q,coin_amount_limit_b:L}=c,K=await this._sdk.FullClient.fetchCoinMetadata(n),W=await this._sdk.FullClient.fetchCoinMetadata(a);if(K===null)return et("FetchError",`fetch coin ${n} metadata failed`,{[D.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[D.DETAILS_KEYS.REQUEST_PARAMS]:t});if(W===null)return et("FetchError",`fetch coin ${a} metadata failed`,{[D.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[D.DETAILS_KEYS.REQUEST_PARAMS]:t});let O=K.id,J=W.id;return this.createPoolRowPayload({tick_spacing:r,initialize_sqrt_price:p,uri:d||"",coin_type_a:n,coin_type_b:a,amount_a:N?C:q,amount_b:N?L:P,fix_amount_a:N,tick_lower:g,tick_upper:y,metadata_a:O,metadata_b:J},i)}async createPoolWithPricePayload(t){let{coin_type_a:i,coin_type_b:n,tick_spacing:a,uri:r,calculate_result:d}=t,{initialize_sqrt_price:c,tick_lower:p,tick_upper:g,liquidity:y,coin_amount_a:k,coin_amount_b:C,fix_amount_a:P,coin_amount_limit_a:N,coin_amount_limit_b:q}=d,L=await this._sdk.FullClient.fetchCoinMetadata(i),K=await this._sdk.FullClient.fetchCoinMetadata(n);if(L===null)return et("FetchError",`fetch coin ${i} metadata failed`,{[D.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[D.DETAILS_KEYS.REQUEST_PARAMS]:t});if(K===null)return et("FetchError",`fetch coin ${n} metadata failed`,{[D.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[D.DETAILS_KEYS.REQUEST_PARAMS]:t});let W=L.id,O=K.id;return this.createPoolPayload({tick_spacing:a,initialize_sqrt_price:c,uri:r||"",coin_type_a:i,coin_type_b:n,amount_a:P?k:N,amount_b:P?q:C,fix_amount_a:P,tick_lower:p,tick_upper:g,metadata_a:W,metadata_b:O})}async fetchTicks(t){let i=[],n=[];for(;;){let a=await this.getTicks({pool_id:t.pool_id,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,start:n,limit:512});if(i=[...i,...a],a.length<512)break;n=[Number((0,D.asUintN)(BigInt(a[a.length-1].index)))]}return i}async getTicks(t){let{integrate:i}=this.sdk.sdkOptions,n=[],a=[t.coin_type_a,t.coin_type_b],r=new mi.Transaction,d=r.makeMoveVec({elements:t.start.map(g=>r.pure.u32(g)),type:"u32"}),c=[r.object(t.pool_id),d,r.pure.u64(t.limit.toString())];r.moveCall({target:`${i.published_at}::${bi}::fetch_ticks`,arguments:c,typeArguments:a});let p=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:(0,di.normalizeSuiAddress)("0x0")});return p.error!=null&&et("InvalidTickObjectId",`getTicks error code: ${p.error??"unknown error"}, please check config and tick object ids`,{[D.DETAILS_KEYS.METHOD_NAME]:"getTicks",[D.DETAILS_KEYS.REQUEST_PARAMS]:t}),p.events?.forEach(g=>{(0,D.extractStructTagFromType)(g.type).name==="FetchTicksResultEvent"&&g.parsedJson.ticks.forEach(y=>{n.push($a(y))})}),n}async fetchPoolPositionInfoList(t){let{integrate:i}=this.sdk.sdkOptions,n=[],a=[],r=512;for(;;){let d=[t.coin_type_a,t.coin_type_b],c=new mi.Transaction,p=c.pure.vector("id",a.map(C=>C)),g=[c.object(t.pool_id),p,c.pure.u64(r)];c.moveCall({target:`${i.published_at}::${bi}::fetch_positions`,arguments:g,typeArguments:d});let y=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:c,sender:(0,di.normalizeSuiAddress)("0x0")});y.error!=null&&et("InvalidPositionRewardObject",`fetch position info error code: ${y.error??"unknown error"}, please check config and tick object ids`,{[D.DETAILS_KEYS.METHOD_NAME]:"fetchPoolPositionInfoList",[D.DETAILS_KEYS.REQUEST_PARAMS]:t});let k=[];if(y?.events?.forEach(C=>{(0,D.extractStructTagFromType)(C.type).name==="FetchPositionsEvent"&&C.parsedJson.positions.forEach(P=>{let N=Pn(P);k.push(N)})}),n.push(...k),k.length<r)break;a=[k[k.length-1].pos_object_id]}return n}async fetchTicksByRpc(t){let i=[],n=null,a=50;for(;;){let r=[],d=await this.sdk.FullClient.getDynamicFields({parentId:t,cursor:n,limit:a});if(n=d.nextCursor,d.data.forEach(c=>{(0,D.extractStructTagFromType)(c.objectType).module==="skip_list"&&r.push(c.objectId)}),i=[...i,...await this.getTicksByRpc(r)],!d.hasNextPage)break}return i}async getTicksByRpc(t){let i=[],n=await this.sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let a of n){(a.error!=null||a.data?.content?.dataType!=="moveObject")&&et("InvalidTickObjectId",`getTicksByRpc error code: ${a.error?.code??"unknown error"}, please check config and tick object ids`,{[D.DETAILS_KEYS.METHOD_NAME]:"getTicksByRpc"});let r=yn(a);r!=null&&i.push(r)}return i}async getTickDataByIndex(t,i){let n={type:"u64",value:(0,D.asUintN)(BigInt((0,D.tickScore)(i).toString())).toString()},a=await this.sdk.FullClient.getDynamicFieldObject({parentId:t,name:n});return(a.error!=null||a.data?.content?.dataType!=="moveObject")&&et("InvalidTickIndex",`get tick by index: ${i} error: ${a.error}`,{[D.DETAILS_KEYS.METHOD_NAME]:"getTickDataByIndex"}),yn(a)}async getTickDataByObjectId(t){let i=await this.sdk.FullClient.getObject({id:t,options:{showContent:!0}});return(i.error!=null||i.data?.content?.dataType!=="moveObject")&&et("InvalidTickObjectId",`getTicksByRpc error code: ${i.error?.code??"unknown error"}, please check config and tick object ids`,{[D.DETAILS_KEYS.METHOD_NAME]:"getTickDataByObjectId"}),yn(i)}async getPartnerRefFeeAmount(t,i=!0){let n=await this._sdk.FullClient.batchGetObjects([t],{showOwner:!0,showContent:!0,showDisplay:i,showType:!0});n[0].data?.content?.dataType!=="moveObject"&&et("NotFoundPartnerObject",`get partner by object id: ${t} error: ${n[0].error}`,{[D.DETAILS_KEYS.METHOD_NAME]:"getPartnerRefFeeAmount"});let a=n[0].data.content.fields.balances,r=await this._sdk.FullClient.getDynamicFieldsByPage(a.fields.id.id),d=[];r.data.forEach(p=>{p.objectId!=null&&d.push(p.objectId)});let c=[];return(await this._sdk.FullClient.batchGetObjects(d,{showOwner:!0,showContent:!0,showDisplay:i,showType:!0})).forEach(p=>{(p.error!=null||p.data?.content?.dataType!=="moveObject")&&et("InvalidPartnerRefFeeFields",`get coin by object id: ${p.data.objectId} error: ${p.error}`,{[D.DETAILS_KEYS.METHOD_NAME]:"getPartnerRefFeeAmount"});let g={coin_type:p.data.content.fields.name,coin_object_id:p.data.objectId,balance:BigInt(p.data.content.fields.value)};c.push(g)}),c}async claimPartnerRefFeePayload(t,i,n){let a=new mi.Transaction,{clmm_pool:r}=this.sdk.sdkOptions,{global_config_id:d}=(0,D.getPackagerConfigs)(r),c=[n],p=[a.object(d),a.object(t),a.object(i)];return a.moveCall({target:`${r.published_at}::${jo}::claim_ref_fee`,arguments:p,typeArguments:c}),a}async getPoolStatus(t){try{let i=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x1::string::String",value:"pool_status"}}),n=(0,D.getObjectFields)(i).position.fields.status;if(n)return n}catch(i){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",i)}}},Li=qe(je()),Va=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:i,full_rpc_url:n,pagination_args:a="all",order:r="ascending"}){let{FullClient:d}=this._sdk,c=[t];i&&c.push(i);let p;n?p=(0,j.createFullClient)(new qr.SuiClient({url:n})):p=d;let g={data:[],has_next_page:!1};try{let y=await p.queryTransactionBlocksByPage({ChangedObject:t},a,r);return y.data.forEach((k,C)=>{let P=Ua(k,C,c);g.data=[...g.data,...P]}),g.has_next_page=y.has_next_page,g.next_cursor=y.next_cursor,g}catch(y){Be("FetchError",y,{[j.DETAILS_KEYS.METHOD_NAME]:"getPositionTransactionList"})}return g}async getPositionList(t,i=[],n=!0){let a=[],r=await this._sdk.FullClient.getOwnedObjectsByPage(t,{options:{showType:!0,showContent:!0,showDisplay:n,showOwner:!0},filter:{Package:this._sdk.sdkOptions.clmm_pool.package_id}}),d=i.length>0;for(let c of r.data)if((0,j.extractStructTagFromType)(c.data.type).full_address===this.buildPositionType()){let p=vn(c),g=`${p.pos_object_id}_getPositionList`;this._sdk.updateCache(g,p),d?i.includes(p.pool)&&a.push(p):a.push(p)}return a}async getPosition(t,i,n=!0,a=!0){let r=await this.getSimplePosition(i,a);return n&&(r=await this.updatePositionInfo(t,r)),r}async getPositionById(t,i=!0,n=!0){let a=await this.getSimplePosition(t,n);if(i){let r=await this._sdk.Pool.getPool(a.pool,!1);return await this.updatePositionInfo(r.position_manager.positions_handle,a)}return a}async getSimplePosition(t,i=!0){let n=`${t}_getPositionList`,a=this.getSimplePositionByCache(t);if(a===void 0){let r=await this.sdk.FullClient.getObject({id:t,options:{showContent:!0,showType:!0,showDisplay:i,showOwner:!0}});a=vn(r),this._sdk.updateCache(n,a)}return a}getSimplePositionByCache(t){let i=`${t}_getPositionList`;return this._sdk.getCache(i)}async getSimplePositionList(t,i=!0){let n=[],a=[];return t.forEach(r=>{let d=this.getSimplePositionByCache(r);d?n.push(d):a.push(r)}),a.length>0&&(await this._sdk.FullClient.batchGetObjects(a,{showOwner:!0,showContent:!0,showDisplay:i,showType:!0})).forEach(r=>{if(r.error==null){let d=vn(r);n.push(d);let c=`${d.pos_object_id}_getPositionList`;this._sdk.updateCache(c,d)}}),n}async updatePositionInfo(t,i){let n=await this.getPositionInfo(t,i.pos_object_id);return{...i,...n}}async getPositionInfo(t,i){try{let n=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x2::object::ID",value:i}}),a=(0,j.getObjectFields)(n.data).value.fields.value;return Pn(a)}catch(n){return Be("FetchError",n,{[j.DETAILS_KEYS.METHOD_NAME]:"getPositionInfo",[j.DETAILS_KEYS.REQUEST_PARAMS]:{position_handle:t,position_id:i}})}}async getPositionInfoList(t){try{let i=[],n=[];return t.forEach(async a=>{let{position_handle:r,position_ids:d}=a;d.forEach(c=>{let p=(0,j.deriveDynamicFieldIdByType)(r,c,"0x2::object::ID","address");n.push(p)})}),n.length===0?[]:((await this._sdk.FullClient.batchGetObjects(n,{showContent:!0,showType:!0,showOwner:!0})).forEach(a=>{try{let r=(0,j.getObjectFields)(a.data).value.fields.value,d=Pn(r);i.push(d)}catch(r){console.log("getPositionInfoList error",r)}}),i)}catch(i){return Be("FetchError",i,{[j.DETAILS_KEYS.METHOD_NAME]:"getPositionInfoList",[j.DETAILS_KEYS.REQUEST_PARAMS]:{options:t}})}}buildFetchPosFee(t,i){let{clmm_pool:n,integrate:a}=this.sdk.sdkOptions,r=[t.coin_type_a,t.coin_type_b],d=[i.object((0,j.getPackagerConfigs)(n).global_config_id),i.object(t.pool_id),i.pure.address(t.position_id)];i.moveCall({target:`${a.published_at}::${bi}::fetch_position_fees`,arguments:d,typeArguments:r})}parsedPosFeeData(t){let i={},n=t.events?.filter(a=>a.type.includes("fetcher_script::FetchPositionFeesEvent"));for(let a=0;a<n.length;a+=1){let{parsedJson:r}=n[a],d={position_id:r.position_id,fee_owned_a:r.fee_owned_a,fee_owned_b:r.fee_owned_b};i[r.position_id]=d}return i}async fetchPosFeeAmount(t){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions,a=new Ie.Transaction;for(let p of t)this.buildFetchPosFee(p,a);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:a,sender:(0,nn.normalizeSuiAddress)("0x0")});r.error!=null&&et("InvalidPoolObject",`fetch position fee error code: ${r.error??"unknown error"}, please check config and position and pool object ids`,{[j.DETAILS_KEYS.METHOD_NAME]:"fetchPosFeeAmount"});let d=[],c=this.parsedPosFeeData(r);for(let p=0;p<t.length;p+=1){let g=c[t[p].position_id];if(g){let y={fee_owned_a:g.fee_owned_a,fee_owned_b:g.fee_owned_b,position_id:t[p].position_id};d.push(y)}}return d}async batchFetchPositionFees(t){let i=[];for(let a of t){let r=await this._sdk.Position.getPositionById(a,!1),d=await this._sdk.Pool.getPool(r.pool,!1);i.push({pool_id:d.id,position_id:r.pos_object_id,coin_type_a:d.coin_type_a,coin_type_b:d.coin_type_b})}let n={};if(i.length>0){let a=await this.fetchPosFeeAmount(i);for(let r of a)n[r.position_id]=r;return n}return n}async createAddLiquidityFixTokenPayload(t,i,n,a,r){let d=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(i){let{is_adjust_coin_a:c,is_adjust_coin_b:p}=Qi(t);if(t=t,t.fix_amount_a&&c||!t.fix_amount_a&&p)return n=await ci.buildAddLiquidityFixTokenForGas(this._sdk,d,t,i,n,a,r),n}return ci.buildAddLiquidityFixToken(this._sdk,d,t,n,a,r)}async createAddLiquidityPayload(t,i,n,a){let{integrate:r,clmm_pool:d}=this._sdk.sdkOptions,c=(0,j.asUintN)(BigInt(t.tick_lower)).toString(),p=(0,j.asUintN)(BigInt(t.tick_upper)).toString(),g=[t.coin_type_a,t.coin_type_b];i=i||new Ie.Transaction;let y=!(0,nn.isValidSuiObjectId)(t.pos_id),k=BigInt(t.max_amount_a),C=BigInt(t.max_amount_b),P,N;if(n==null||a==null){let q=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());P=j.CoinAssist.buildCoinForAmount(i,q,k,t.coin_type_a,!1,!0),N=j.CoinAssist.buildCoinForAmount(i,q,C,t.coin_type_b,!1,!0)}else P={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},N={target_coin:a,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]};if(y)i.moveCall({target:`${r.published_at}::${vi}::open_position_with_liquidity`,typeArguments:g,arguments:[i.object((0,j.getPackagerConfigs)(d).global_config_id),i.object(t.pool_id),i.pure.u32(Number(c)),i.pure.u32(Number(p)),P.target_coin,N.target_coin,i.pure.u64(t.max_amount_a),i.pure.u64(t.max_amount_b),i.pure.u128(t.delta_liquidity),i.object(j.CLOCK_ADDRESS)]});else{let q=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());i=ci.createCollectRewarderAndFeeParams(this._sdk,i,t,q,P.remain_coins,N.remain_coins),i.moveCall({target:`${r.published_at}::${vi}::add_liquidity`,typeArguments:g,arguments:[i.object((0,j.getPackagerConfigs)(d).global_config_id),i.object(t.pool_id),i.object(t.pos_id),P.target_coin,N.target_coin,i.pure.u64(t.max_amount_a),i.pure.u64(t.max_amount_b),i.pure.u128(t.delta_liquidity),i.object(j.CLOCK_ADDRESS)]})}return i}async removeLiquidityPayload(t,i){let{clmm_pool:n,integrate:a}=this.sdk.sdkOptions,r="remove_liquidity";i=i||new Ie.Transaction;let d=[t.coin_type_a,t.coin_type_b],c=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());i=ci.createCollectRewarderAndFeeParams(this._sdk,i,t,c);let p=[i.object((0,j.getPackagerConfigs)(n).global_config_id),i.object(t.pool_id),i.object(t.pos_id),i.pure.u128(t.delta_liquidity),i.pure.u64(t.min_amount_a),i.pure.u64(t.min_amount_b),i.object(j.CLOCK_ADDRESS)];return i.moveCall({target:`${a.published_at}::${ji}::${r}`,typeArguments:d,arguments:p}),i}async closePositionPayload(t,i){let{clmm_pool:n,integrate:a}=this.sdk.sdkOptions;i=i||new Ie.Transaction;let r=[t.coin_type_a,t.coin_type_b],d=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return i=ci.createCollectRewarderAndFeeParams(this._sdk,i,t,d),i.moveCall({target:`${a.published_at}::${ji}::close_position`,typeArguments:r,arguments:[i.object((0,j.getPackagerConfigs)(n).global_config_id),i.object(t.pool_id),i.object(t.pos_id),i.pure.u64(t.min_amount_a),i.pure.u64(t.min_amount_b),i.object(j.CLOCK_ADDRESS)]}),i}openPositionPayload(t,i){let{clmm_pool:n,integrate:a}=this.sdk.sdkOptions;i=i||new Ie.Transaction;let r=[t.coin_type_a,t.coin_type_b],d=(0,j.asUintN)(BigInt(t.tick_lower)).toString(),c=(0,j.asUintN)(BigInt(t.tick_upper)).toString(),p=[i.object((0,j.getPackagerConfigs)(n).global_config_id),i.object(t.pool_id),i.pure.u32(Number(d)),i.pure.u32(Number(c))];return i.moveCall({target:`${a.published_at}::${ji}::open_position`,typeArguments:r,arguments:p}),i}async openPositionWithPricePayload(t,i){let{pool_id:n}=t,{clmm_pool:a,integrate:r}=this.sdk.sdkOptions;i=i||new Ie.Transaction;let d=await this.sdk.Pool.getPool(n,!1),c=Number(d.tick_spacing),p=0,g=0;if(t.is_full_range)p=j.TickUtil.getMinIndex(c),g=j.TickUtil.getMaxIndex(c);else{let{price_base_coin:C,min_price:P,max_price:N}=t;p=j.TickMath.priceToInitializeTickIndex(C==="coin_a"?(0,j.d)(P):(0,j.d)(1).div(N),t.coin_decimals_a,t.coin_decimals_b,c),g=j.TickMath.priceToInitializeTickIndex(C==="coin_a"?(0,j.d)(N):(0,j.d)(1).div(P),t.coin_decimals_a,t.coin_decimals_b,c)}let y=[d.coin_type_a,d.coin_type_b],k=[i.object((0,j.getPackagerConfigs)(a).global_config_id),i.object(t.pool_id),i.pure.u32(Number((0,j.asUintN)(BigInt(p)))),i.pure.u32(Number((0,j.asUintN)(BigInt(g))))];return i.moveCall({target:`${r.published_at}::${ji}::open_position`,typeArguments:y,arguments:k}),i}async collectFeePayload(t,i,n,a){i=i||new Ie.Transaction;let r=n||j.CoinAssist.buildCoinWithBalance(BigInt(0),t.coin_type_a,i),d=a||j.CoinAssist.buildCoinWithBalance(BigInt(0),t.coin_type_b,i);return this.createCollectFeePayload(t,i,r,d),i}createCollectFeePayload(t,i,n,a){let{clmm_pool:r,integrate:d}=this.sdk.sdkOptions,c=[t.coin_type_a,t.coin_type_b],p=[i.object((0,j.getPackagerConfigs)(r).global_config_id),i.object(t.pool_id),i.object(t.pos_id),n,a];return i.moveCall({target:`${d.published_at}::${vi}::collect_fee`,typeArguments:c,arguments:p}),i}async calculateAddLiquidityResultWithPrice(t){let{pool_id:i,slippage:n,refresh_pool_price:a,add_mode_params:r}=t,d=await this.sdk.Pool.getPool(i,a),c=Number(d.tick_spacing),p=0,g=0;if(r.is_full_range)p=j.TickUtil.getMinIndex(c),g=j.TickUtil.getMaxIndex(c);else{let{price_base_coin:K,min_price:W,max_price:O}=r;p=j.TickMath.priceToInitializeTickIndex(K==="coin_a"?(0,j.d)(W):(0,j.d)(1).div(O),r.coin_decimals_a,r.coin_decimals_b,c),g=j.TickMath.priceToInitializeTickIndex(K==="coin_a"?(0,j.d)(O):(0,j.d)(1).div(W),r.coin_decimals_a,r.coin_decimals_b,c)}if("liquidity"in t){let{liquidity:K}=t,W=j.TickMath.tickIndexToSqrtPriceX64(p),O=j.TickMath.tickIndexToSqrtPriceX64(g),{coin_amount_a:J,coin_amount_b:vt}=j.ClmmPoolUtil.getCoinAmountFromLiquidity(new Li.default(K),new Li.default(d.current_sqrt_price),W,O,!1),he=(0,j.d)(J).mul(1+n).toFixed(0,fe.ROUND_UP),G=(0,j.d)(vt).mul(1+n).toFixed(0,fe.ROUND_UP);return{coin_amount_a:J,coin_amount_b:vt,coin_amount_limit_a:he,coin_amount_limit_b:G,liquidity:K,tick_lower:p,tick_upper:g}}let{coin_amount:y,fix_amount_a:k}=t,{coin_amount_limit_a:C,coin_amount_limit_b:P,liquidity_amount:N,coin_amount_a:q,coin_amount_b:L}=j.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(p,g,new Li.default(y),k,!0,n,new Li.default(d.current_sqrt_price));return{coin_amount_a:q,coin_amount_b:L,coin_amount_limit_a:C,coin_amount_limit_b:P,liquidity:N,tick_lower:p,tick_upper:g,fix_amount_a:k}}async addLiquidityWithPricePayload(t,i,n,a){let{pool_id:r,calculate_result:d}=t,{coin_amount_limit_a:c,coin_amount_limit_b:p,liquidity:g,tick_lower:y,tick_upper:k}=d;i=i||new Ie.Transaction;let C=await this.sdk.Pool.getPool(r,!1);return await this.createAddLiquidityPayload({delta_liquidity:g,max_amount_a:c,max_amount_b:p,tick_lower:y,tick_upper:k,collect_fee:!1,rewarder_coin_types:[],coin_type_a:C.coin_type_a,coin_type_b:C.coin_type_b,pool_id:r,pos_id:""},i,n,a),i}async createAddLiquidityFixCoinWithPricePayload(t,i,n,a){let{pool_id:r,calculate_result:d}=t,{coin_amount_limit_a:c,coin_amount_limit_b:p,liquidity:g,tick_lower:y,tick_upper:k,fix_amount_a:C,coin_amount_a:P,coin_amount_b:N}=d;if(C===void 0)throw et("InvalidParams","fix_amount_a is undefined",{[j.DETAILS_KEYS.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[j.DETAILS_KEYS.REQUEST_PARAMS]:t});i=i||new Ie.Transaction;let q=await this.sdk.Pool.getPool(r,!1);return await this.createAddLiquidityFixTokenPayload({amount_a:C?P:c,amount_b:C?p:N,slippage:0,fix_amount_a:C,is_open:!0,tick_lower:y,tick_upper:k,collect_fee:!1,rewarder_coin_types:[],coin_type_a:q.coin_type_a,coin_type_b:q.coin_type_b,pool_id:r,pos_id:""},void 0,i,n,a),i}createCollectFeeNoSendPayload(t,i,n,a){let{clmm_pool:r,integrate:d}=this.sdk.sdkOptions,c=[t.coin_type_a,t.coin_type_b],p=[i.object((0,j.getPackagerConfigs)(r).global_config_id),i.object(t.pool_id),i.object(t.pos_id),n,a];return i.moveCall({target:`${d.published_at}::${Cr}::collect_fee`,typeArguments:c,arguments:p}),i}},or=qe(je()),Wa=class{constructor(t){this._sdk=t,this.growthGlobal=[Ct.ZERO,Ct.ZERO,Ct.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 a of i){let r=Ct.MathUtil.fromX64(new or.default(a.emissions_per_second));n.push({emissions:Math.floor(r.toNumber()*60*60*24),coin_type:a.coin_type})}return n}async batchFetchPositionRewarders(t){let i=[];for(let a of t){let r=await this._sdk.Position.getPositionById(a,!1),d=await this._sdk.Pool.getPool(r.pool,!1);i.push({pool_id:d.id,position_id:r.pos_object_id,coin_type_a:d.coin_type_a,coin_type_b:d.coin_type_b,rewarder_types:d.rewarder_infos.map(c=>c.coin_type)})}let n={};if(i.length>0){let a=await this.fetchPosRewardersAmount(i);for(let r of a)n[r.position_id]=r.rewarder_amounts;return n}return n}async fetchPositionRewarders(t,i){let n={pool_id:t.id,position_id:i,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,rewarder_types:t.rewarder_infos.map(a=>a.coin_type)};return(await this.fetchPosRewardersAmount([n]))[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,i){let{clmm_pool:n,integrate:a}=this.sdk.sdkOptions,r=[t.coin_type_a,t.coin_type_b],d=[i.object((0,Ct.getPackagerConfigs)(n).global_config_id),i.object(t.pool_id),i.pure.address(t.position_id),i.object(Ct.CLOCK_ADDRESS)];i.moveCall({target:`${a.published_at}::${bi}::fetch_position_rewards`,arguments:d,typeArguments:r})}async fetchPosRewardersAmount(t){let i=new Vi.Transaction;for(let d of t)this.buildFetchPosReward(d,i);let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,jr.normalizeSuiAddress)("0x")});n.error!=null&&et("InvalidConfig",`fetch position rewards error code: ${n.error??"unknown error"}, please check config and params`,{[Ct.DETAILS_KEYS.METHOD_NAME]:"fetchPosRewardersAmount",[Ct.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let a=this.parsedPosRewardData(n),r=[];for(let d=0;d<t.length;d+=1){let c=a[t[d].position_id];if(c){let p={pool_id:t[d].pool_id,position_id:t[d].position_id,rewarder_amounts:c.rewarder_amount.map((g,y)=>({amount_owned:g,coin_type:t[d].rewarder_types[y]}))};r.push(p)}}return r}parsedPosRewardData(t){let i={},n=t.events?.filter(a=>a.type.includes("fetcher_script::FetchPositionRewardsEvent"));for(let a=0;a<n.length;a+=1){let{parsedJson:r}=n[a],d={position_id:r.position_id,rewarder_amount:r.data};i[r.position_id]=d}return i}async fetchPoolRewardersAmount(t,i){let n=await this.sdk.Pool.getPool(i),a=await this.sdk.Position.getPositionList(t,[i]),r=[];for(let p of a)r.push({pool_id:n.id,position_id:p.pos_object_id,rewarder_types:n.rewarder_infos.map(g=>g.coin_type),coin_type_a:n.coin_type_a,coin_type_b:n.coin_type_b});let d=await this.fetchPosRewardersAmount(r),c=[Ct.ZERO,Ct.ZERO,Ct.ZERO];if(d!=null)for(let p of d)for(let g=0;g<p.rewarder_amounts.length;g+=1)c[g]=c[g].add(new or.default(p.rewarder_amounts[g].amount_owned));return c}async getPoolLowerAndUpperTicks(t,i){let n=[],a=[];for(let r of i){let d=await this.sdk.Pool.getTickDataByIndex(t,r.tick_lower_index),c=await this.sdk.Pool.getTickDataByIndex(t,r.tick_upper_index);n.push(d),a.push(c)}return[n,a]}async collectRewarderPayload(t){let i=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null),n=new Vi.Transaction;return n=ci.createCollectRewarderAndFeeParams(this._sdk,n,t,i),n}async batchCollectRewardsPayload(t,i,n,a){let r=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null);i=i||new Vi.Transaction;let d={};return t.forEach(c=>{let p=(0,Ct.normalizeCoinType)(c.coin_type_a),g=(0,Ct.normalizeCoinType)(c.coin_type_b);if(c.collect_fee){let k=d[p];k==null&&(n==null?k=Ct.CoinAssist.buildCoinForAmount(i,r,BigInt(0),p,!1):k={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},d[p]=k);let C=d[g];C==null&&(a==null?C=Ct.CoinAssist.buildCoinForAmount(i,r,BigInt(0),g,!1):C={target_coin:a,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},d[g]=C),i=this._sdk.Position.createCollectFeeNoSendPayload({pool_id:c.pool_id,pos_id:c.pos_id,coin_type_a:c.coin_type_a,coin_type_b:c.coin_type_b},i,k.target_coin,C.target_coin)}let y=[];c.rewarder_coin_types.forEach(k=>{let C=(0,Ct.normalizeCoinType)(k),P=d[k];P===void 0&&(P=Ct.CoinAssist.buildCoinForAmount(i,r,BigInt(0),C,!1),d[C]=P),y.push(P.target_coin)}),i=this.createCollectRewarderNoSendPayload(c,i,y)}),Object.keys(d).forEach(c=>{let p=d[c];p.is_mint_zero_coin&&Za(this.sdk,i,p.target_coin,c,this.sdk.getSenderAddress())}),i}createCollectRewarderPayload(t,i,n){let{clmm_pool:a,integrate:r}=this.sdk.sdkOptions,d=(0,Ct.getPackagerConfigs)(a),c=[t.coin_type_a,t.coin_type_b];return t.rewarder_coin_types.forEach((p,g)=>{i&&i.moveCall({target:`${r.published_at}::${vi}::collect_reward`,typeArguments:[...c,p],arguments:[i.object(d.global_config_id),i.object(t.pool_id),i.object(t.pos_id),i.object(d.global_vault_id),n[g],i.object(Ct.CLOCK_ADDRESS)]})}),i}createCollectRewarderNoSendPayload(t,i,n){let{clmm_pool:a,integrate:r}=this.sdk.sdkOptions,d=(0,Ct.getPackagerConfigs)(a),c=[t.coin_type_a,t.coin_type_b];return t.rewarder_coin_types.forEach((p,g)=>{i&&i.moveCall({target:`${r.published_at}::${Cr}::collect_reward`,typeArguments:[...c,p],arguments:[i.object(d.global_config_id),i.object(t.pool_id),i.object(t.pos_id),i.object(d.global_vault_id),n[g],i.object(Ct.CLOCK_ADDRESS)]})}),i}},pi=qe(je());var Ga=class{constructor(t){this.calculateSingleImpact=(i,n)=>n.minus(i).div(n).mul(100),this._sdk=t}get sdk(){return this._sdk}calculateSwapFee(t){let i=(0,St.d)(0);return t.forEach(n=>{let a=n.base_paths.length;if(a>0){let r=n.base_paths[0],d=r.label==="Cetus"?new fe(r.fee_rate).div(10**6):new fe(r.fee_rate).div(10**9),c=(0,St.d)(r.input_amount).div(10**r.from_decimal).mul(d);if(i=i.add(c),a>1){let p=n.base_paths[1],g=r.direction?r.current_price:new fe(1).div(r.current_price),y=p.direction?p.current_price:new fe(1).div(p.current_price),k=p.label==="Cetus"?new fe(p.fee_rate).div(10**6):new fe(p.fee_rate).div(10**9),C=(0,St.d)(p.output_amount).div(10**p.to_decimal).mul(k).div(g.mul(y));i=i.add(C)}}}),i.toString()}calculateSwapPriceImpact(t){let i=(0,St.d)(0);return t.forEach(n=>{let a=n.base_paths.length;if(a===1){let r=n.base_paths[0],d=(0,St.d)(r.output_amount).div(10**r.to_decimal),c=(0,St.d)(r.input_amount).div(10**r.from_decimal),p=d.div(c),g=r.direction?new fe(r.current_price):new fe(1).div(r.current_price);i=i.add(this.calculateSingleImpact(p,g))}if(a===2){let r=n.base_paths[0],d=n.base_paths[1],c=r.direction?new fe(r.current_price):new fe(1).div(r.current_price),p=d.direction?new fe(d.current_price):new fe(1).div(d.current_price),g=c.mul(p),y=new fe(d.output_amount).div(10**d.to_decimal),k=new fe(r.input_amount).div(10**r.from_decimal),C=y.div(k);i=i.add(this.calculateSingleImpact(C,g))}}),i.toString()}async preSwapWithMultiPool(t){let{integrate:i}=this.sdk.sdkOptions,n=new En.Transaction,a=[t.coin_type_a,t.coin_type_b];for(let g=0;g<t.pool_ids.length;g+=1){let y=[n.object(t.pool_ids[g]),n.pure.bool(t.a2b),n.pure.bool(t.by_amount_in),n.pure.u64(t.amount)];n.moveCall({target:`${i.published_at}::${bi}::calculate_swap_result`,arguments:y,typeArguments:a})}let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,Tn.normalizeSuiAddress)("0x0")});r.error!=null&&et("InvalidConfig",`pre swap with multi pools error code: ${r.error??"unknown error"}, please check config and params`,{[St.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[St.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let d=r.events?.filter(g=>(0,St.extractStructTagFromType)(g.type).name==="CalculatedSwapResultEvent");if(d.length===0)return null;d.length!==t.pool_ids.length&&et("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[St.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[St.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let c=t.by_amount_in?St.ZERO:St.U64_MAX,p=0;for(let g=0;g<d.length;g+=1)if(!d[g].parsedJson.data.is_exceed)if(t.by_amount_in){let y=new pi.default(d[g].parsedJson.data.amount_out);y.gt(c)&&(p=g,c=y)}else{let y=new pi.default(d[g].parsedJson.data.amount_out);y.lt(c)&&(p=g,c=y)}return this.transformSwapWithMultiPoolData({pool_address:t.pool_ids[p],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},d[p].parsedJson)}async preSwap(t){let{integrate:i}=this.sdk.sdkOptions,n=new En.Transaction,a=[t.coin_type_a,t.coin_type_b],r=[n.object(t.pool.id),n.pure.bool(t.a2b),n.pure.bool(t.by_amount_in),n.pure.u64(t.amount)];n.moveCall({target:`${i.published_at}::${bi}::calculate_swap_result`,arguments:r,typeArguments:a});let d=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,Tn.normalizeSuiAddress)("0x0")});if(d.error!=null)return et("InvalidConfig",`preSwap error code: ${d.error??"unknown error"}, please check config and params`,{[St.DETAILS_KEYS.METHOD_NAME]:"preSwap",[St.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let c=d.events?.filter(p=>(0,St.extractStructTagFromType)(p.type).name==="CalculatedSwapResultEvent");return c.length===0?et("InvalidConfig",`preSwap error code: ${d.error??"unknown error"}, please check config and params`,{[St.DETAILS_KEYS.METHOD_NAME]:"preSwap",[St.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}}):this.transformSwapData(t,c[0].parsedJson.data)}transformSwapData(t,i){let n=i.amount_in&&i.fee_amount?new pi.default(i.amount_in).add(new pi.default(i.fee_amount)).toString():"";return{pool_address:t.pool.id,current_sqrt_price:t.current_sqrt_price,estimated_amount_in:n,estimated_amount_out:i.amount_out,estimated_end_sqrt_price:i.after_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}}transformSwapWithMultiPoolData(t,i){let{data:n}=i;console.log("json data. ",n);let a=n.amount_in&&n.fee_amount?new pi.default(n.amount_in).add(new pi.default(n.fee_amount)).toString():"";return{pool_address:t.pool_address,estimated_amount_in:a,estimated_amount_out:n.amount_out,estimated_end_sqrt_price:n.after_sqrt_price,estimated_start_sqrt_price:n.step_results[0].current_sqrt_price,estimated_fee_amount:n.fee_amount,is_exceed:n.is_exceed,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in}}calculateRates(t){let{current_pool:i}=t,n=Ba(i),a;t.a2b?a=t.swap_ticks.sort((C,P)=>P.index-C.index):a=t.swap_ticks.sort((C,P)=>C.index-P.index);let r=ja(t.a2b,t.by_amount_in,t.amount,n,a),d=!1;t.by_amount_in?d=r.amount_in.lt(t.amount):d=r.amount_out.lt(t.amount);let c=_i.getDefaultSqrtPriceLimit(t.a2b);t.a2b&&r.next_sqrt_price.lt(c)&&(d=!0),!t.a2b&&r.next_sqrt_price.gt(c)&&(d=!0);let p=0;r.cross_tick_num>6&&r.cross_tick_num<40&&(p=22e3*(r.cross_tick_num-6)),r.cross_tick_num>40&&(d=!0);let g=St.TickMath.sqrtPriceX64ToPrice(n.current_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),y=St.TickMath.sqrtPriceX64ToPrice(r.next_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),k=Math.abs(g-y)/g*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:d,extra_compute_limit:p,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in,price_impact_pct:k}}async createSwapPayload(t,i){let n=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(i){let{is_adjust_coin_a:a,is_adjust_coin_b:r}=Qi(t);if(t.a2b&&a||!t.a2b&&r)return await _i.buildSwapTransactionForGas(this._sdk,t,n,i)}return _i.buildSwapTransaction(this.sdk,t,n)}async createSwapWithoutTransferCoinsPayload(t,i){let n=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(i){let{is_adjust_coin_a:a,is_adjust_coin_b:r}=Qi(t);if(t.a2b&&a||!t.a2b&&r)return await _i.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,t,n,i)}return _i.buildSwapTransactionWithoutTransferCoins(this.sdk,t,n)}},Ja=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 et("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[we.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo"});let i=[];try{let n=`${t.package_id}::clmm_vester::CreateEvent`,a=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:n})).data.map(r=>r.parsedJson.clmm_vester_id);return a.length>0&&(await this._sdk.FullClient.batchGetObjects(a,{showContent:!0,showType:!0})).forEach(r=>{let d=yi.parseClmmVestInfo(r),c=`${d.id}-ClmmVestInfo`;this._sdk.updateCache(c,d),i.push(d)}),i}catch(n){Be("ClmmVestFetchError",n,{[we.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(t=!0){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return et("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[we.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:n}=(0,we.getPackagerConfigs)(i),a=`${n}-ClmmVestInfo`,r=this._sdk.getCache(a,t);if(r)return r;try{let d=await this._sdk.FullClient.getObject({id:n,options:{showContent:!0,showType:!0}}),c=yi.parseClmmVestInfo(d);return this._sdk.updateCache(a,c),c}catch(d){return Be("ClmmVestFetchError",d,{[we.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo",[we.DETAILS_KEYS.REQUEST_PARAMS]:{clmm_vest_id:n}})}}async getPositionVesting(t){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return et("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[we.DETAILS_KEYS.METHOD_NAME]:"getPositionVesting"});if(t.length===0)return[];let{clmm_vest_id:n}=(0,we.getPackagerConfigs)(i),a=new In.Transaction;t.forEach(c=>{let{clmm_pool_id:p,coin_type_a:g,coin_type_b:y,clmm_position_ids:k}=c;a.moveCall({package:i.published_at,module:"clmm_vester",function:"get_positions_vesting",typeArguments:[g,y],arguments:[a.object(n),a.object(p),a.pure.vector("id",k)]})});let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:a,sender:(0,Lr.normalizeSuiAddress)("0x0")}),d=[];return r.events?.forEach(c=>{if(c.type.includes("clmm_vester::GetPositionsVestingEvent")){let{parsedJson:p}=c;d.push(...p.position_vestings.map(g=>yi.parsePositionVesting(g)))}}),d}buildRedeemPayload(t,i){let{clmm_vest:n}=this._sdk.sdkOptions;if(n===void 0)return et("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[we.DETAILS_KEYS.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:a,clmm_vest_id:r,cetus_coin_type:d}=(0,we.getPackagerConfigs)(n);return i=i||new In.Transaction,t.forEach(c=>{let{clmm_pool_id:p,clmm_position_id:g,coin_type_a:y,coin_type_b:k,period:C}=c,P=i.moveCall({package:n.published_at,module:"clmm_vester",function:"redeem",arguments:[i.object(a),i.object(r),i.object(p),typeof g=="string"?i.object(g):g,i.pure.u16(C),i.object(we.CLOCK_ADDRESS)],typeArguments:[y,k]}),N=we.CoinAssist.fromBalance(P,d,i);i.transferObjects([N],this._sdk.getSenderAddress())}),i}},ar={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"}},Xa={env:"mainnet",full_rpc_url:$r.FullRpcUrlMainnet,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:ar.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0x75b2e9ecad34944b8d0c874e568c90db0cf9437f0d7392abfd4cb902972f3e40",version:12,config:ar.clmmConfig},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d",version:12},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"}}},Qa={env:"testnet",full_rpc_url:Ur.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"}}},zr=class Wi extends lr.SdkWrapper{constructor(i){super(i),this._swap=new Ga(this),this._pool=new Ka(this),this._position=new Va(this),this._config=new No(this),this._rewarder=new Wa(this),this._vest=new Ja(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(i){let{env:n="mainnet"}=i;return n==="mainnet"?Wi.createCustomSDK({...Xa,...i}):Wi.createCustomSDK({...Qa,...i})}static createCustomSDK(i){return new Wi(i)}},rn=qe(je()),Cs=new rn.default(365),As=new rn.default(24),Ps=new rn.default(3600),Ss=new rn.default(.5);var Si=class t extends Hr.SdkWrapper{constructor(i,n){super(i),this._suilendModule=new Di(this),this._leverageModules=new Bi(this),this._aggregatorClient=new Pi.AggregatorClient({signer:(0,Kr.normalizeSuiAddress)("0x0"),client:i.sui_client||new Vr.SuiClient({url:i.full_rpc_url}),env:i.env==="testnet"?Pi.Env.Testnet:Pi.Env.Mainnet,pythUrls:i.pyth_urls}),this._clmmSDK=n||zr.createSDK({env:i.env,full_rpc_url:i.full_rpc_url})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}static createSDK(i){return t.createCustomSDK({...sn,...i})}static createCustomSDK(i){return new t(i)}};var Ya=Si;0&&(module.exports={CetusLeverageSDK,leverage_mainnet});
|
|
2
|
-
/*! Bundled license information:
|
|
3
|
-
|
|
4
|
-
decimal.js/decimal.mjs:
|
|
5
|
-
(*!
|
|
6
|
-
* decimal.js v10.5.0
|
|
7
|
-
* An arbitrary-precision Decimal type for JavaScript.
|
|
8
|
-
* https://github.com/MikeMcl/decimal.js
|
|
9
|
-
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
10
|
-
* MIT Licence
|
|
11
|
-
*)
|
|
12
|
-
*/
|
|
1
|
+
"use strict";var gr=Object.create;var Xt=Object.defineProperty;var vr=Object.getOwnPropertyDescriptor;var Mr=Object.getOwnPropertyNames;var wr=Object.getPrototypeOf,yr=Object.prototype.hasOwnProperty;var xr=(w,v)=>()=>(v||w((v={exports:{}}).exports,v),v.exports),_r=(w,v)=>{for(var M in v)Xt(w,M,{get:v[M],enumerable:!0})},Ye=(w,v,M,S)=>{if(v&&typeof v=="object"||typeof v=="function")for(let h of Mr(v))!yr.call(w,h)&&h!==M&&Xt(w,h,{get:()=>v[h],enumerable:!(S=vr(v,h))||S.enumerable});return w};var be=(w,v,M)=>(M=w!=null?gr(wr(w)):{},Ye(v||!w||!w.__esModule?Xt(M,"default",{value:w,enumerable:!0}):M,w)),br=w=>Ye(Xt({},"__esModule",{value:!0}),w);var lr=xr((hr,Le)=>{"use strict";(function(w,v){"use strict";function M(s,t){if(!s)throw new Error(t||"Assertion failed")}function S(s,t){s.super_=t;var e=function(){};e.prototype=t.prototype,s.prototype=new e,s.prototype.constructor=s}function h(s,t,e){if(h.isBN(s))return s;this.negative=0,this.words=null,this.length=0,this.red=null,s!==null&&((t==="le"||t==="be")&&(e=t,t=10),this._init(s||0,t||10,e||"be"))}typeof w=="object"?w.exports=h:v.BN=h,h.BN=h,h.wordSize=26;var D;try{typeof window<"u"&&typeof window.Buffer<"u"?D=window.Buffer:D=require("buffer").Buffer}catch{}h.isBN=function(t){return t instanceof h?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===h.wordSize&&Array.isArray(t.words)},h.max=function(t,e){return t.cmp(e)>0?t:e},h.min=function(t,e){return t.cmp(e)<0?t:e},h.prototype._init=function(t,e,i){if(typeof t=="number")return this._initNumber(t,e,i);if(typeof t=="object")return this._initArray(t,e,i);e==="hex"&&(e=16),M(e===(e|0)&&e>=2&&e<=36),t=t.toString().replace(/\s+/g,"");var n=0;t[0]==="-"&&(n++,this.negative=1),n<t.length&&(e===16?this._parseHex(t,n,i):(this._parseBase(t,e,n),i==="le"&&this._initArray(this.toArray(),e,i)))},h.prototype._initNumber=function(t,e,i){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(M(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),i==="le"&&this._initArray(this.toArray(),e,i)},h.prototype._initArray=function(t,e,i){if(M(typeof t.length=="number"),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var o,f,c=0;if(i==="be")for(n=t.length-1,o=0;n>=0;n-=3)f=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[o]|=f<<c&67108863,this.words[o+1]=f>>>26-c&67108863,c+=24,c>=26&&(c-=26,o++);else if(i==="le")for(n=0,o=0;n<t.length;n+=3)f=t[n]|t[n+1]<<8|t[n+2]<<16,this.words[o]|=f<<c&67108863,this.words[o+1]=f>>>26-c&67108863,c+=24,c>=26&&(c-=26,o++);return this._strip()};function A(s,t){var e=s.charCodeAt(t);if(e>=48&&e<=57)return e-48;if(e>=65&&e<=70)return e-55;if(e>=97&&e<=102)return e-87;M(!1,"Invalid character in "+s)}function C(s,t,e){var i=A(s,e);return e-1>=t&&(i|=A(s,e-1)<<4),i}h.prototype._parseHex=function(t,e,i){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var o=0,f=0,c;if(i==="be")for(n=t.length-1;n>=e;n-=2)c=C(t,e,n)<<o,this.words[f]|=c&67108863,o>=18?(o-=18,f+=1,this.words[f]|=c>>>26):o+=8;else{var a=t.length-e;for(n=a%2===0?e+1:e;n<t.length;n+=2)c=C(t,e,n)<<o,this.words[f]|=c&67108863,o>=18?(o-=18,f+=1,this.words[f]|=c>>>26):o+=8}this._strip()};function k(s,t,e,i){for(var n=0,o=0,f=Math.min(s.length,e),c=t;c<f;c++){var a=s.charCodeAt(c)-48;n*=i,a>=49?o=a-49+10:a>=17?o=a-17+10:o=a,M(a>=0&&o<i,"Invalid character"),n+=o}return n}h.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var n=0,o=1;o<=67108863;o*=e)n++;n--,o=o/e|0;for(var f=t.length-i,c=f%n,a=Math.min(f,f-c)+i,r=0,u=i;u<a;u+=n)r=k(t,u,u+n,e),this.imuln(o),this.words[0]+r<67108864?this.words[0]+=r:this._iaddn(r);if(c!==0){var b=1;for(r=k(t,u,t.length,e),u=0;u<c;u++)b*=e;this.imuln(b),this.words[0]+r<67108864?this.words[0]+=r:this._iaddn(r)}this._strip()},h.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red};function B(s,t){s.words=t.words,s.length=t.length,s.negative=t.negative,s.red=t.red}if(h.prototype._move=function(t){B(t,this)},h.prototype.clone=function(){var t=new h(null);return this.copy(t),t},h.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},h.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},h.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{h.prototype[Symbol.for("nodejs.util.inspect.custom")]=F}catch{h.prototype.inspect=F}else h.prototype.inspect=F;function F(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var U=["","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"],xt=[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],Dt=[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];h.prototype.toString=function(t,e){t=t||10,e=e|0||1;var i;if(t===16||t==="hex"){i="";for(var n=0,o=0,f=0;f<this.length;f++){var c=this.words[f],a=((c<<n|o)&16777215).toString(16);o=c>>>24-n&16777215,n+=2,n>=26&&(n-=26,f--),o!==0||f!==this.length-1?i=U[6-a.length]+a+i:i=a+i}for(o!==0&&(i=o.toString(16)+i);i.length%e!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}if(t===(t|0)&&t>=2&&t<=36){var r=xt[t],u=Dt[t];i="";var b=this.clone();for(b.negative=0;!b.isZero();){var y=b.modrn(u).toString(t);b=b.idivn(u),b.isZero()?i=y+i:i=U[r-y.length]+y+i}for(this.isZero()&&(i="0"+i);i.length%e!==0;)i="0"+i;return this.negative!==0&&(i="-"+i),i}M(!1,"Base should be between 2 and 36")},h.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&M(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},h.prototype.toJSON=function(){return this.toString(16,2)},D&&(h.prototype.toBuffer=function(t,e){return this.toArrayLike(D,t,e)}),h.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)};var St=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)};h.prototype.toArrayLike=function(t,e,i){this._strip();var n=this.byteLength(),o=i||Math.max(1,n);M(n<=o,"byte array longer than desired length"),M(o>0,"Requested array length <= 0");var f=St(t,o),c=e==="le"?"LE":"BE";return this["_toArrayLike"+c](f,n),f},h.prototype._toArrayLikeLE=function(t,e){for(var i=0,n=0,o=0,f=0;o<this.length;o++){var c=this.words[o]<<f|n;t[i++]=c&255,i<t.length&&(t[i++]=c>>8&255),i<t.length&&(t[i++]=c>>16&255),f===6?(i<t.length&&(t[i++]=c>>24&255),n=0,f=0):(n=c>>>24,f+=2)}if(i<t.length)for(t[i++]=n;i<t.length;)t[i++]=0},h.prototype._toArrayLikeBE=function(t,e){for(var i=t.length-1,n=0,o=0,f=0;o<this.length;o++){var c=this.words[o]<<f|n;t[i--]=c&255,i>=0&&(t[i--]=c>>8&255),i>=0&&(t[i--]=c>>16&255),f===6?(i>=0&&(t[i--]=c>>24&255),n=0,f=0):(n=c>>>24,f+=2)}if(i>=0)for(t[i--]=n;i>=0;)t[i--]=0},Math.clz32?h.prototype._countBits=function(t){return 32-Math.clz32(t)}:h.prototype._countBits=function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},h.prototype._zeroBits=function(t){if(t===0)return 26;var e=t,i=0;return(e&8191)===0&&(i+=13,e>>>=13),(e&127)===0&&(i+=7,e>>>=7),(e&15)===0&&(i+=4,e>>>=4),(e&3)===0&&(i+=2,e>>>=2),(e&1)===0&&i++,i},h.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return(this.length-1)*26+e};function It(s){for(var t=new Array(s.bitLength()),e=0;e<t.length;e++){var i=e/26|0,n=e%26;t[e]=s.words[i]>>>n&1}return t}h.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,i!==26)break}return t},h.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},h.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},h.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},h.prototype.isNeg=function(){return this.negative!==0},h.prototype.neg=function(){return this.clone().ineg()},h.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},h.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},h.prototype.ior=function(t){return M((this.negative|t.negative)===0),this.iuor(t)},h.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},h.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},h.prototype.iuand=function(t){var e;this.length>t.length?e=t:e=this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this._strip()},h.prototype.iand=function(t){return M((this.negative|t.negative)===0),this.iuand(t)},h.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},h.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},h.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var n=0;n<i.length;n++)this.words[n]=e.words[n]^i.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},h.prototype.ixor=function(t){return M((this.negative|t.negative)===0),this.iuxor(t)},h.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},h.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},h.prototype.inotn=function(t){M(typeof t=="number"&&t>=0);var e=Math.ceil(t/26)|0,i=t%26;this._expand(e),i>0&&e--;for(var n=0;n<e;n++)this.words[n]=~this.words[n]&67108863;return i>0&&(this.words[n]=~this.words[n]&67108863>>26-i),this._strip()},h.prototype.notn=function(t){return this.clone().inotn(t)},h.prototype.setn=function(t,e){M(typeof t=="number"&&t>=0);var i=t/26|0,n=t%26;return this._expand(i+1),e?this.words[i]=this.words[i]|1<<n:this.words[i]=this.words[i]&~(1<<n),this._strip()},h.prototype.iadd=function(t){var e;if(this.negative!==0&&t.negative===0)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();var i,n;this.length>t.length?(i=this,n=t):(i=t,n=this);for(var o=0,f=0;f<n.length;f++)e=(i.words[f]|0)+(n.words[f]|0)+o,this.words[f]=e&67108863,o=e>>>26;for(;o!==0&&f<i.length;f++)e=(i.words[f]|0)+o,this.words[f]=e&67108863,o=e>>>26;if(this.length=i.length,o!==0)this.words[this.length]=o,this.length++;else if(i!==this)for(;f<i.length;f++)this.words[f]=i.words[f];return this},h.prototype.add=function(t){var e;return t.negative!==0&&this.negative===0?(t.negative=0,e=this.sub(t),t.negative^=1,e):t.negative===0&&this.negative!==0?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},h.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var i=this.cmp(t);if(i===0)return this.negative=0,this.length=1,this.words[0]=0,this;var n,o;i>0?(n=this,o=t):(n=t,o=this);for(var f=0,c=0;c<o.length;c++)e=(n.words[c]|0)-(o.words[c]|0)+f,f=e>>26,this.words[c]=e&67108863;for(;f!==0&&c<n.length;c++)e=(n.words[c]|0)+f,f=e>>26,this.words[c]=e&67108863;if(f===0&&c<n.length&&n!==this)for(;c<n.length;c++)this.words[c]=n.words[c];return this.length=Math.max(this.length,c),n!==this&&(this.negative=1),this._strip()},h.prototype.sub=function(t){return this.clone().isub(t)};function Ct(s,t,e){e.negative=t.negative^s.negative;var i=s.length+t.length|0;e.length=i,i=i-1|0;var n=s.words[0]|0,o=t.words[0]|0,f=n*o,c=f&67108863,a=f/67108864|0;e.words[0]=c;for(var r=1;r<i;r++){for(var u=a>>>26,b=a&67108863,y=Math.min(r,t.length-1),_=Math.max(0,r-s.length+1);_<=y;_++){var O=r-_|0;n=s.words[O]|0,o=t.words[_]|0,f=n*o+b,u+=f/67108864|0,b=f&67108863}e.words[r]=b|0,a=u|0}return a!==0?e.words[r]=a|0:e.length--,e._strip()}var qt=function(t,e,i){var n=t.words,o=e.words,f=i.words,c=0,a,r,u,b=n[0]|0,y=b&8191,_=b>>>13,O=n[1]|0,N=O&8191,I=O>>>13,Lt=n[2]|0,L=Lt&8191,T=Lt>>>13,Ot=n[3]|0,E=Ot&8191,R=Ot>>>13,Ne=n[4]|0,Z=Ne&8191,$=Ne>>>13,Be=n[5]|0,G=Be&8191,H=Be>>>13,Ie=n[6]|0,W=Ie&8191,V=Ie>>>13,Te=n[7]|0,X=Te&8191,Y=Te>>>13,qe=n[8]|0,J=qe&8191,Q=qe>>>13,Ue=n[9]|0,j=Ue&8191,tt=Ue>>>13,Fe=o[0]|0,et=Fe&8191,rt=Fe>>>13,Ke=o[1]|0,it=Ke&8191,nt=Ke>>>13,ze=o[2]|0,ot=ze&8191,st=ze>>>13,Ze=o[3]|0,at=Ze&8191,ft=Ze>>>13,$e=o[4]|0,ht=$e&8191,lt=$e>>>13,Ge=o[5]|0,ut=Ge&8191,dt=Ge>>>13,He=o[6]|0,ct=He&8191,pt=He>>>13,We=o[7]|0,mt=We&8191,gt=We>>>13,Ve=o[8]|0,vt=Ve&8191,Mt=Ve>>>13,Xe=o[9]|0,wt=Xe&8191,yt=Xe>>>13;i.negative=t.negative^e.negative,i.length=19,a=Math.imul(y,et),r=Math.imul(y,rt),r=r+Math.imul(_,et)|0,u=Math.imul(_,rt);var ne=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(ne>>>26)|0,ne&=67108863,a=Math.imul(N,et),r=Math.imul(N,rt),r=r+Math.imul(I,et)|0,u=Math.imul(I,rt),a=a+Math.imul(y,it)|0,r=r+Math.imul(y,nt)|0,r=r+Math.imul(_,it)|0,u=u+Math.imul(_,nt)|0;var oe=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(oe>>>26)|0,oe&=67108863,a=Math.imul(L,et),r=Math.imul(L,rt),r=r+Math.imul(T,et)|0,u=Math.imul(T,rt),a=a+Math.imul(N,it)|0,r=r+Math.imul(N,nt)|0,r=r+Math.imul(I,it)|0,u=u+Math.imul(I,nt)|0,a=a+Math.imul(y,ot)|0,r=r+Math.imul(y,st)|0,r=r+Math.imul(_,ot)|0,u=u+Math.imul(_,st)|0;var se=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(se>>>26)|0,se&=67108863,a=Math.imul(E,et),r=Math.imul(E,rt),r=r+Math.imul(R,et)|0,u=Math.imul(R,rt),a=a+Math.imul(L,it)|0,r=r+Math.imul(L,nt)|0,r=r+Math.imul(T,it)|0,u=u+Math.imul(T,nt)|0,a=a+Math.imul(N,ot)|0,r=r+Math.imul(N,st)|0,r=r+Math.imul(I,ot)|0,u=u+Math.imul(I,st)|0,a=a+Math.imul(y,at)|0,r=r+Math.imul(y,ft)|0,r=r+Math.imul(_,at)|0,u=u+Math.imul(_,ft)|0;var ae=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(ae>>>26)|0,ae&=67108863,a=Math.imul(Z,et),r=Math.imul(Z,rt),r=r+Math.imul($,et)|0,u=Math.imul($,rt),a=a+Math.imul(E,it)|0,r=r+Math.imul(E,nt)|0,r=r+Math.imul(R,it)|0,u=u+Math.imul(R,nt)|0,a=a+Math.imul(L,ot)|0,r=r+Math.imul(L,st)|0,r=r+Math.imul(T,ot)|0,u=u+Math.imul(T,st)|0,a=a+Math.imul(N,at)|0,r=r+Math.imul(N,ft)|0,r=r+Math.imul(I,at)|0,u=u+Math.imul(I,ft)|0,a=a+Math.imul(y,ht)|0,r=r+Math.imul(y,lt)|0,r=r+Math.imul(_,ht)|0,u=u+Math.imul(_,lt)|0;var fe=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(fe>>>26)|0,fe&=67108863,a=Math.imul(G,et),r=Math.imul(G,rt),r=r+Math.imul(H,et)|0,u=Math.imul(H,rt),a=a+Math.imul(Z,it)|0,r=r+Math.imul(Z,nt)|0,r=r+Math.imul($,it)|0,u=u+Math.imul($,nt)|0,a=a+Math.imul(E,ot)|0,r=r+Math.imul(E,st)|0,r=r+Math.imul(R,ot)|0,u=u+Math.imul(R,st)|0,a=a+Math.imul(L,at)|0,r=r+Math.imul(L,ft)|0,r=r+Math.imul(T,at)|0,u=u+Math.imul(T,ft)|0,a=a+Math.imul(N,ht)|0,r=r+Math.imul(N,lt)|0,r=r+Math.imul(I,ht)|0,u=u+Math.imul(I,lt)|0,a=a+Math.imul(y,ut)|0,r=r+Math.imul(y,dt)|0,r=r+Math.imul(_,ut)|0,u=u+Math.imul(_,dt)|0;var he=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(he>>>26)|0,he&=67108863,a=Math.imul(W,et),r=Math.imul(W,rt),r=r+Math.imul(V,et)|0,u=Math.imul(V,rt),a=a+Math.imul(G,it)|0,r=r+Math.imul(G,nt)|0,r=r+Math.imul(H,it)|0,u=u+Math.imul(H,nt)|0,a=a+Math.imul(Z,ot)|0,r=r+Math.imul(Z,st)|0,r=r+Math.imul($,ot)|0,u=u+Math.imul($,st)|0,a=a+Math.imul(E,at)|0,r=r+Math.imul(E,ft)|0,r=r+Math.imul(R,at)|0,u=u+Math.imul(R,ft)|0,a=a+Math.imul(L,ht)|0,r=r+Math.imul(L,lt)|0,r=r+Math.imul(T,ht)|0,u=u+Math.imul(T,lt)|0,a=a+Math.imul(N,ut)|0,r=r+Math.imul(N,dt)|0,r=r+Math.imul(I,ut)|0,u=u+Math.imul(I,dt)|0,a=a+Math.imul(y,ct)|0,r=r+Math.imul(y,pt)|0,r=r+Math.imul(_,ct)|0,u=u+Math.imul(_,pt)|0;var le=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(le>>>26)|0,le&=67108863,a=Math.imul(X,et),r=Math.imul(X,rt),r=r+Math.imul(Y,et)|0,u=Math.imul(Y,rt),a=a+Math.imul(W,it)|0,r=r+Math.imul(W,nt)|0,r=r+Math.imul(V,it)|0,u=u+Math.imul(V,nt)|0,a=a+Math.imul(G,ot)|0,r=r+Math.imul(G,st)|0,r=r+Math.imul(H,ot)|0,u=u+Math.imul(H,st)|0,a=a+Math.imul(Z,at)|0,r=r+Math.imul(Z,ft)|0,r=r+Math.imul($,at)|0,u=u+Math.imul($,ft)|0,a=a+Math.imul(E,ht)|0,r=r+Math.imul(E,lt)|0,r=r+Math.imul(R,ht)|0,u=u+Math.imul(R,lt)|0,a=a+Math.imul(L,ut)|0,r=r+Math.imul(L,dt)|0,r=r+Math.imul(T,ut)|0,u=u+Math.imul(T,dt)|0,a=a+Math.imul(N,ct)|0,r=r+Math.imul(N,pt)|0,r=r+Math.imul(I,ct)|0,u=u+Math.imul(I,pt)|0,a=a+Math.imul(y,mt)|0,r=r+Math.imul(y,gt)|0,r=r+Math.imul(_,mt)|0,u=u+Math.imul(_,gt)|0;var ue=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(ue>>>26)|0,ue&=67108863,a=Math.imul(J,et),r=Math.imul(J,rt),r=r+Math.imul(Q,et)|0,u=Math.imul(Q,rt),a=a+Math.imul(X,it)|0,r=r+Math.imul(X,nt)|0,r=r+Math.imul(Y,it)|0,u=u+Math.imul(Y,nt)|0,a=a+Math.imul(W,ot)|0,r=r+Math.imul(W,st)|0,r=r+Math.imul(V,ot)|0,u=u+Math.imul(V,st)|0,a=a+Math.imul(G,at)|0,r=r+Math.imul(G,ft)|0,r=r+Math.imul(H,at)|0,u=u+Math.imul(H,ft)|0,a=a+Math.imul(Z,ht)|0,r=r+Math.imul(Z,lt)|0,r=r+Math.imul($,ht)|0,u=u+Math.imul($,lt)|0,a=a+Math.imul(E,ut)|0,r=r+Math.imul(E,dt)|0,r=r+Math.imul(R,ut)|0,u=u+Math.imul(R,dt)|0,a=a+Math.imul(L,ct)|0,r=r+Math.imul(L,pt)|0,r=r+Math.imul(T,ct)|0,u=u+Math.imul(T,pt)|0,a=a+Math.imul(N,mt)|0,r=r+Math.imul(N,gt)|0,r=r+Math.imul(I,mt)|0,u=u+Math.imul(I,gt)|0,a=a+Math.imul(y,vt)|0,r=r+Math.imul(y,Mt)|0,r=r+Math.imul(_,vt)|0,u=u+Math.imul(_,Mt)|0;var de=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(de>>>26)|0,de&=67108863,a=Math.imul(j,et),r=Math.imul(j,rt),r=r+Math.imul(tt,et)|0,u=Math.imul(tt,rt),a=a+Math.imul(J,it)|0,r=r+Math.imul(J,nt)|0,r=r+Math.imul(Q,it)|0,u=u+Math.imul(Q,nt)|0,a=a+Math.imul(X,ot)|0,r=r+Math.imul(X,st)|0,r=r+Math.imul(Y,ot)|0,u=u+Math.imul(Y,st)|0,a=a+Math.imul(W,at)|0,r=r+Math.imul(W,ft)|0,r=r+Math.imul(V,at)|0,u=u+Math.imul(V,ft)|0,a=a+Math.imul(G,ht)|0,r=r+Math.imul(G,lt)|0,r=r+Math.imul(H,ht)|0,u=u+Math.imul(H,lt)|0,a=a+Math.imul(Z,ut)|0,r=r+Math.imul(Z,dt)|0,r=r+Math.imul($,ut)|0,u=u+Math.imul($,dt)|0,a=a+Math.imul(E,ct)|0,r=r+Math.imul(E,pt)|0,r=r+Math.imul(R,ct)|0,u=u+Math.imul(R,pt)|0,a=a+Math.imul(L,mt)|0,r=r+Math.imul(L,gt)|0,r=r+Math.imul(T,mt)|0,u=u+Math.imul(T,gt)|0,a=a+Math.imul(N,vt)|0,r=r+Math.imul(N,Mt)|0,r=r+Math.imul(I,vt)|0,u=u+Math.imul(I,Mt)|0,a=a+Math.imul(y,wt)|0,r=r+Math.imul(y,yt)|0,r=r+Math.imul(_,wt)|0,u=u+Math.imul(_,yt)|0;var ce=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(ce>>>26)|0,ce&=67108863,a=Math.imul(j,it),r=Math.imul(j,nt),r=r+Math.imul(tt,it)|0,u=Math.imul(tt,nt),a=a+Math.imul(J,ot)|0,r=r+Math.imul(J,st)|0,r=r+Math.imul(Q,ot)|0,u=u+Math.imul(Q,st)|0,a=a+Math.imul(X,at)|0,r=r+Math.imul(X,ft)|0,r=r+Math.imul(Y,at)|0,u=u+Math.imul(Y,ft)|0,a=a+Math.imul(W,ht)|0,r=r+Math.imul(W,lt)|0,r=r+Math.imul(V,ht)|0,u=u+Math.imul(V,lt)|0,a=a+Math.imul(G,ut)|0,r=r+Math.imul(G,dt)|0,r=r+Math.imul(H,ut)|0,u=u+Math.imul(H,dt)|0,a=a+Math.imul(Z,ct)|0,r=r+Math.imul(Z,pt)|0,r=r+Math.imul($,ct)|0,u=u+Math.imul($,pt)|0,a=a+Math.imul(E,mt)|0,r=r+Math.imul(E,gt)|0,r=r+Math.imul(R,mt)|0,u=u+Math.imul(R,gt)|0,a=a+Math.imul(L,vt)|0,r=r+Math.imul(L,Mt)|0,r=r+Math.imul(T,vt)|0,u=u+Math.imul(T,Mt)|0,a=a+Math.imul(N,wt)|0,r=r+Math.imul(N,yt)|0,r=r+Math.imul(I,wt)|0,u=u+Math.imul(I,yt)|0;var pe=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(pe>>>26)|0,pe&=67108863,a=Math.imul(j,ot),r=Math.imul(j,st),r=r+Math.imul(tt,ot)|0,u=Math.imul(tt,st),a=a+Math.imul(J,at)|0,r=r+Math.imul(J,ft)|0,r=r+Math.imul(Q,at)|0,u=u+Math.imul(Q,ft)|0,a=a+Math.imul(X,ht)|0,r=r+Math.imul(X,lt)|0,r=r+Math.imul(Y,ht)|0,u=u+Math.imul(Y,lt)|0,a=a+Math.imul(W,ut)|0,r=r+Math.imul(W,dt)|0,r=r+Math.imul(V,ut)|0,u=u+Math.imul(V,dt)|0,a=a+Math.imul(G,ct)|0,r=r+Math.imul(G,pt)|0,r=r+Math.imul(H,ct)|0,u=u+Math.imul(H,pt)|0,a=a+Math.imul(Z,mt)|0,r=r+Math.imul(Z,gt)|0,r=r+Math.imul($,mt)|0,u=u+Math.imul($,gt)|0,a=a+Math.imul(E,vt)|0,r=r+Math.imul(E,Mt)|0,r=r+Math.imul(R,vt)|0,u=u+Math.imul(R,Mt)|0,a=a+Math.imul(L,wt)|0,r=r+Math.imul(L,yt)|0,r=r+Math.imul(T,wt)|0,u=u+Math.imul(T,yt)|0;var me=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(me>>>26)|0,me&=67108863,a=Math.imul(j,at),r=Math.imul(j,ft),r=r+Math.imul(tt,at)|0,u=Math.imul(tt,ft),a=a+Math.imul(J,ht)|0,r=r+Math.imul(J,lt)|0,r=r+Math.imul(Q,ht)|0,u=u+Math.imul(Q,lt)|0,a=a+Math.imul(X,ut)|0,r=r+Math.imul(X,dt)|0,r=r+Math.imul(Y,ut)|0,u=u+Math.imul(Y,dt)|0,a=a+Math.imul(W,ct)|0,r=r+Math.imul(W,pt)|0,r=r+Math.imul(V,ct)|0,u=u+Math.imul(V,pt)|0,a=a+Math.imul(G,mt)|0,r=r+Math.imul(G,gt)|0,r=r+Math.imul(H,mt)|0,u=u+Math.imul(H,gt)|0,a=a+Math.imul(Z,vt)|0,r=r+Math.imul(Z,Mt)|0,r=r+Math.imul($,vt)|0,u=u+Math.imul($,Mt)|0,a=a+Math.imul(E,wt)|0,r=r+Math.imul(E,yt)|0,r=r+Math.imul(R,wt)|0,u=u+Math.imul(R,yt)|0;var ge=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(ge>>>26)|0,ge&=67108863,a=Math.imul(j,ht),r=Math.imul(j,lt),r=r+Math.imul(tt,ht)|0,u=Math.imul(tt,lt),a=a+Math.imul(J,ut)|0,r=r+Math.imul(J,dt)|0,r=r+Math.imul(Q,ut)|0,u=u+Math.imul(Q,dt)|0,a=a+Math.imul(X,ct)|0,r=r+Math.imul(X,pt)|0,r=r+Math.imul(Y,ct)|0,u=u+Math.imul(Y,pt)|0,a=a+Math.imul(W,mt)|0,r=r+Math.imul(W,gt)|0,r=r+Math.imul(V,mt)|0,u=u+Math.imul(V,gt)|0,a=a+Math.imul(G,vt)|0,r=r+Math.imul(G,Mt)|0,r=r+Math.imul(H,vt)|0,u=u+Math.imul(H,Mt)|0,a=a+Math.imul(Z,wt)|0,r=r+Math.imul(Z,yt)|0,r=r+Math.imul($,wt)|0,u=u+Math.imul($,yt)|0;var ve=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(ve>>>26)|0,ve&=67108863,a=Math.imul(j,ut),r=Math.imul(j,dt),r=r+Math.imul(tt,ut)|0,u=Math.imul(tt,dt),a=a+Math.imul(J,ct)|0,r=r+Math.imul(J,pt)|0,r=r+Math.imul(Q,ct)|0,u=u+Math.imul(Q,pt)|0,a=a+Math.imul(X,mt)|0,r=r+Math.imul(X,gt)|0,r=r+Math.imul(Y,mt)|0,u=u+Math.imul(Y,gt)|0,a=a+Math.imul(W,vt)|0,r=r+Math.imul(W,Mt)|0,r=r+Math.imul(V,vt)|0,u=u+Math.imul(V,Mt)|0,a=a+Math.imul(G,wt)|0,r=r+Math.imul(G,yt)|0,r=r+Math.imul(H,wt)|0,u=u+Math.imul(H,yt)|0;var Me=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(Me>>>26)|0,Me&=67108863,a=Math.imul(j,ct),r=Math.imul(j,pt),r=r+Math.imul(tt,ct)|0,u=Math.imul(tt,pt),a=a+Math.imul(J,mt)|0,r=r+Math.imul(J,gt)|0,r=r+Math.imul(Q,mt)|0,u=u+Math.imul(Q,gt)|0,a=a+Math.imul(X,vt)|0,r=r+Math.imul(X,Mt)|0,r=r+Math.imul(Y,vt)|0,u=u+Math.imul(Y,Mt)|0,a=a+Math.imul(W,wt)|0,r=r+Math.imul(W,yt)|0,r=r+Math.imul(V,wt)|0,u=u+Math.imul(V,yt)|0;var we=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(we>>>26)|0,we&=67108863,a=Math.imul(j,mt),r=Math.imul(j,gt),r=r+Math.imul(tt,mt)|0,u=Math.imul(tt,gt),a=a+Math.imul(J,vt)|0,r=r+Math.imul(J,Mt)|0,r=r+Math.imul(Q,vt)|0,u=u+Math.imul(Q,Mt)|0,a=a+Math.imul(X,wt)|0,r=r+Math.imul(X,yt)|0,r=r+Math.imul(Y,wt)|0,u=u+Math.imul(Y,yt)|0;var ye=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(ye>>>26)|0,ye&=67108863,a=Math.imul(j,vt),r=Math.imul(j,Mt),r=r+Math.imul(tt,vt)|0,u=Math.imul(tt,Mt),a=a+Math.imul(J,wt)|0,r=r+Math.imul(J,yt)|0,r=r+Math.imul(Q,wt)|0,u=u+Math.imul(Q,yt)|0;var xe=(c+a|0)+((r&8191)<<13)|0;c=(u+(r>>>13)|0)+(xe>>>26)|0,xe&=67108863,a=Math.imul(j,wt),r=Math.imul(j,yt),r=r+Math.imul(tt,wt)|0,u=Math.imul(tt,yt);var _e=(c+a|0)+((r&8191)<<13)|0;return c=(u+(r>>>13)|0)+(_e>>>26)|0,_e&=67108863,f[0]=ne,f[1]=oe,f[2]=se,f[3]=ae,f[4]=fe,f[5]=he,f[6]=le,f[7]=ue,f[8]=de,f[9]=ce,f[10]=pe,f[11]=me,f[12]=ge,f[13]=ve,f[14]=Me,f[15]=we,f[16]=ye,f[17]=xe,f[18]=_e,c!==0&&(f[19]=c,i.length++),i};Math.imul||(qt=Ct);function x(s,t,e){e.negative=t.negative^s.negative,e.length=s.length+t.length;for(var i=0,n=0,o=0;o<e.length-1;o++){var f=n;n=0;for(var c=i&67108863,a=Math.min(o,t.length-1),r=Math.max(0,o-s.length+1);r<=a;r++){var u=o-r,b=s.words[u]|0,y=t.words[r]|0,_=b*y,O=_&67108863;f=f+(_/67108864|0)|0,O=O+c|0,c=O&67108863,f=f+(O>>>26)|0,n+=f>>>26,f&=67108863}e.words[o]=c,i=f,f=n}return i!==0?e.words[o]=i:e.length--,e._strip()}function $t(s,t,e){return x(s,t,e)}h.prototype.mulTo=function(t,e){var i,n=this.length+t.length;return this.length===10&&t.length===10?i=qt(this,t,e):n<63?i=Ct(this,t,e):n<1024?i=x(this,t,e):i=$t(this,t,e),i};function kt(s,t){this.x=s,this.y=t}kt.prototype.makeRBT=function(t){for(var e=new Array(t),i=h.prototype._countBits(t)-1,n=0;n<t;n++)e[n]=this.revBin(n,i,t);return e},kt.prototype.revBin=function(t,e,i){if(t===0||t===i-1)return t;for(var n=0,o=0;o<e;o++)n|=(t&1)<<e-o-1,t>>=1;return n},kt.prototype.permute=function(t,e,i,n,o,f){for(var c=0;c<f;c++)n[c]=e[t[c]],o[c]=i[t[c]]},kt.prototype.transform=function(t,e,i,n,o,f){this.permute(f,t,e,i,n,o);for(var c=1;c<o;c<<=1)for(var a=c<<1,r=Math.cos(2*Math.PI/a),u=Math.sin(2*Math.PI/a),b=0;b<o;b+=a)for(var y=r,_=u,O=0;O<c;O++){var N=i[b+O],I=n[b+O],Lt=i[b+O+c],L=n[b+O+c],T=y*Lt-_*L;L=y*L+_*Lt,Lt=T,i[b+O]=N+Lt,n[b+O]=I+L,i[b+O+c]=N-Lt,n[b+O+c]=I-L,O!==a&&(T=r*y-u*_,_=r*_+u*y,y=T)}},kt.prototype.guessLen13b=function(t,e){var i=Math.max(e,t)|1,n=i&1,o=0;for(i=i/2|0;i;i=i>>>1)o++;return 1<<o+1+n},kt.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var n=0;n<i/2;n++){var o=t[n];t[n]=t[i-n-1],t[i-n-1]=o,o=e[n],e[n]=-e[i-n-1],e[i-n-1]=-o}},kt.prototype.normalize13b=function(t,e){for(var i=0,n=0;n<e/2;n++){var o=Math.round(t[2*n+1]/e)*8192+Math.round(t[2*n]/e)+i;t[n]=o&67108863,o<67108864?i=0:i=o/67108864|0}return t},kt.prototype.convert13b=function(t,e,i,n){for(var o=0,f=0;f<e;f++)o=o+(t[f]|0),i[2*f]=o&8191,o=o>>>13,i[2*f+1]=o&8191,o=o>>>13;for(f=2*e;f<n;++f)i[f]=0;M(o===0),M((o&-8192)===0)},kt.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},kt.prototype.mulp=function(t,e,i){var n=2*this.guessLen13b(t.length,e.length),o=this.makeRBT(n),f=this.stub(n),c=new Array(n),a=new Array(n),r=new Array(n),u=new Array(n),b=new Array(n),y=new Array(n),_=i.words;_.length=n,this.convert13b(t.words,t.length,c,n),this.convert13b(e.words,e.length,u,n),this.transform(c,f,a,r,n,o),this.transform(u,f,b,y,n,o);for(var O=0;O<n;O++){var N=a[O]*b[O]-r[O]*y[O];r[O]=a[O]*y[O]+r[O]*b[O],a[O]=N}return this.conjugate(a,r,n),this.transform(a,r,_,f,n,o),this.conjugate(_,f,n),this.normalize13b(_,n),i.negative=t.negative^e.negative,i.length=t.length+e.length,i._strip()},h.prototype.mul=function(t){var e=new h(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},h.prototype.mulf=function(t){var e=new h(null);return e.words=new Array(this.length+t.length),$t(this,t,e)},h.prototype.imul=function(t){return this.clone().mulTo(t,this)},h.prototype.imuln=function(t){var e=t<0;e&&(t=-t),M(typeof t=="number"),M(t<67108864);for(var i=0,n=0;n<this.length;n++){var o=(this.words[n]|0)*t,f=(o&67108863)+(i&67108863);i>>=26,i+=o/67108864|0,i+=f>>>26,this.words[n]=f&67108863}return i!==0&&(this.words[n]=i,this.length++),this.length=t===0?1:this.length,e?this.ineg():this},h.prototype.muln=function(t){return this.clone().imuln(t)},h.prototype.sqr=function(){return this.mul(this)},h.prototype.isqr=function(){return this.imul(this.clone())},h.prototype.pow=function(t){var e=It(t);if(e.length===0)return new h(1);for(var i=this,n=0;n<e.length&&e[n]===0;n++,i=i.sqr());if(++n<e.length)for(var o=i.sqr();n<e.length;n++,o=o.sqr())e[n]!==0&&(i=i.mul(o));return i},h.prototype.iushln=function(t){M(typeof t=="number"&&t>=0);var e=t%26,i=(t-e)/26,n=67108863>>>26-e<<26-e,o;if(e!==0){var f=0;for(o=0;o<this.length;o++){var c=this.words[o]&n,a=(this.words[o]|0)-c<<e;this.words[o]=a|f,f=c>>>26-e}f&&(this.words[o]=f,this.length++)}if(i!==0){for(o=this.length-1;o>=0;o--)this.words[o+i]=this.words[o];for(o=0;o<i;o++)this.words[o]=0;this.length+=i}return this._strip()},h.prototype.ishln=function(t){return M(this.negative===0),this.iushln(t)},h.prototype.iushrn=function(t,e,i){M(typeof t=="number"&&t>=0);var n;e?n=(e-e%26)/26:n=0;var o=t%26,f=Math.min((t-o)/26,this.length),c=67108863^67108863>>>o<<o,a=i;if(n-=f,n=Math.max(0,n),a){for(var r=0;r<f;r++)a.words[r]=this.words[r];a.length=f}if(f!==0)if(this.length>f)for(this.length-=f,r=0;r<this.length;r++)this.words[r]=this.words[r+f];else this.words[0]=0,this.length=1;var u=0;for(r=this.length-1;r>=0&&(u!==0||r>=n);r--){var b=this.words[r]|0;this.words[r]=u<<26-o|b>>>o,u=b&c}return a&&u!==0&&(a.words[a.length++]=u),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},h.prototype.ishrn=function(t,e,i){return M(this.negative===0),this.iushrn(t,e,i)},h.prototype.shln=function(t){return this.clone().ishln(t)},h.prototype.ushln=function(t){return this.clone().iushln(t)},h.prototype.shrn=function(t){return this.clone().ishrn(t)},h.prototype.ushrn=function(t){return this.clone().iushrn(t)},h.prototype.testn=function(t){M(typeof t=="number"&&t>=0);var e=t%26,i=(t-e)/26,n=1<<e;if(this.length<=i)return!1;var o=this.words[i];return!!(o&n)},h.prototype.imaskn=function(t){M(typeof t=="number"&&t>=0);var e=t%26,i=(t-e)/26;if(M(this.negative===0,"imaskn works only with positive numbers"),this.length<=i)return this;if(e!==0&&i++,this.length=Math.min(i,this.length),e!==0){var n=67108863^67108863>>>e<<e;this.words[this.length-1]&=n}return this._strip()},h.prototype.maskn=function(t){return this.clone().imaskn(t)},h.prototype.iaddn=function(t){return M(typeof t=="number"),M(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<=t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},h.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},h.prototype.isubn=function(t){if(M(typeof t=="number"),M(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this._strip()},h.prototype.addn=function(t){return this.clone().iaddn(t)},h.prototype.subn=function(t){return this.clone().isubn(t)},h.prototype.iabs=function(){return this.negative=0,this},h.prototype.abs=function(){return this.clone().iabs()},h.prototype._ishlnsubmul=function(t,e,i){var n=t.length+i,o;this._expand(n);var f,c=0;for(o=0;o<t.length;o++){f=(this.words[o+i]|0)+c;var a=(t.words[o]|0)*e;f-=a&67108863,c=(f>>26)-(a/67108864|0),this.words[o+i]=f&67108863}for(;o<this.length-i;o++)f=(this.words[o+i]|0)+c,c=f>>26,this.words[o+i]=f&67108863;if(c===0)return this._strip();for(M(c===-1),c=0,o=0;o<this.length;o++)f=-(this.words[o]|0)+c,c=f>>26,this.words[o]=f&67108863;return this.negative=1,this._strip()},h.prototype._wordDiv=function(t,e){var i=this.length-t.length,n=this.clone(),o=t,f=o.words[o.length-1]|0,c=this._countBits(f);i=26-c,i!==0&&(o=o.ushln(i),n.iushln(i),f=o.words[o.length-1]|0);var a=n.length-o.length,r;if(e!=="mod"){r=new h(null),r.length=a+1,r.words=new Array(r.length);for(var u=0;u<r.length;u++)r.words[u]=0}var b=n.clone()._ishlnsubmul(o,1,a);b.negative===0&&(n=b,r&&(r.words[a]=1));for(var y=a-1;y>=0;y--){var _=(n.words[o.length+y]|0)*67108864+(n.words[o.length+y-1]|0);for(_=Math.min(_/f|0,67108863),n._ishlnsubmul(o,_,y);n.negative!==0;)_--,n.negative=0,n._ishlnsubmul(o,1,y),n.isZero()||(n.negative^=1);r&&(r.words[y]=_)}return r&&r._strip(),n._strip(),e!=="div"&&i!==0&&n.iushrn(i),{div:r||null,mod:n}},h.prototype.divmod=function(t,e,i){if(M(!t.isZero()),this.isZero())return{div:new h(0),mod:new h(0)};var n,o,f;return this.negative!==0&&t.negative===0?(f=this.neg().divmod(t,e),e!=="mod"&&(n=f.div.neg()),e!=="div"&&(o=f.mod.neg(),i&&o.negative!==0&&o.iadd(t)),{div:n,mod:o}):this.negative===0&&t.negative!==0?(f=this.divmod(t.neg(),e),e!=="mod"&&(n=f.div.neg()),{div:n,mod:f.mod}):(this.negative&t.negative)!==0?(f=this.neg().divmod(t.neg(),e),e!=="div"&&(o=f.mod.neg(),i&&o.negative!==0&&o.isub(t)),{div:f.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new h(0),mod:this}:t.length===1?e==="div"?{div:this.divn(t.words[0]),mod:null}:e==="mod"?{div:null,mod:new h(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new h(this.modrn(t.words[0]))}:this._wordDiv(t,e)},h.prototype.div=function(t){return this.divmod(t,"div",!1).div},h.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},h.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},h.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=e.div.negative!==0?e.mod.isub(t):e.mod,n=t.ushrn(1),o=t.andln(1),f=i.cmp(n);return f<0||o===1&&f===0?e.div:e.div.negative!==0?e.div.isubn(1):e.div.iaddn(1)},h.prototype.modrn=function(t){var e=t<0;e&&(t=-t),M(t<=67108863);for(var i=(1<<26)%t,n=0,o=this.length-1;o>=0;o--)n=(i*n+(this.words[o]|0))%t;return e?-n:n},h.prototype.modn=function(t){return this.modrn(t)},h.prototype.idivn=function(t){var e=t<0;e&&(t=-t),M(t<=67108863);for(var i=0,n=this.length-1;n>=0;n--){var o=(this.words[n]|0)+i*67108864;this.words[n]=o/t|0,i=o%t}return this._strip(),e?this.ineg():this},h.prototype.divn=function(t){return this.clone().idivn(t)},h.prototype.egcd=function(t){M(t.negative===0),M(!t.isZero());var e=this,i=t.clone();e.negative!==0?e=e.umod(t):e=e.clone();for(var n=new h(1),o=new h(0),f=new h(0),c=new h(1),a=0;e.isEven()&&i.isEven();)e.iushrn(1),i.iushrn(1),++a;for(var r=i.clone(),u=e.clone();!e.isZero();){for(var b=0,y=1;(e.words[0]&y)===0&&b<26;++b,y<<=1);if(b>0)for(e.iushrn(b);b-- >0;)(n.isOdd()||o.isOdd())&&(n.iadd(r),o.isub(u)),n.iushrn(1),o.iushrn(1);for(var _=0,O=1;(i.words[0]&O)===0&&_<26;++_,O<<=1);if(_>0)for(i.iushrn(_);_-- >0;)(f.isOdd()||c.isOdd())&&(f.iadd(r),c.isub(u)),f.iushrn(1),c.iushrn(1);e.cmp(i)>=0?(e.isub(i),n.isub(f),o.isub(c)):(i.isub(e),f.isub(n),c.isub(o))}return{a:f,b:c,gcd:i.iushln(a)}},h.prototype._invmp=function(t){M(t.negative===0),M(!t.isZero());var e=this,i=t.clone();e.negative!==0?e=e.umod(t):e=e.clone();for(var n=new h(1),o=new h(0),f=i.clone();e.cmpn(1)>0&&i.cmpn(1)>0;){for(var c=0,a=1;(e.words[0]&a)===0&&c<26;++c,a<<=1);if(c>0)for(e.iushrn(c);c-- >0;)n.isOdd()&&n.iadd(f),n.iushrn(1);for(var r=0,u=1;(i.words[0]&u)===0&&r<26;++r,u<<=1);if(r>0)for(i.iushrn(r);r-- >0;)o.isOdd()&&o.iadd(f),o.iushrn(1);e.cmp(i)>=0?(e.isub(i),n.isub(o)):(i.isub(e),o.isub(n))}var b;return e.cmpn(1)===0?b=n:b=o,b.cmpn(0)<0&&b.iadd(t),b},h.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var n=0;e.isEven()&&i.isEven();n++)e.iushrn(1),i.iushrn(1);do{for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var o=e.cmp(i);if(o<0){var f=e;e=i,i=f}else if(o===0||i.cmpn(1)===0)break;e.isub(i)}while(!0);return i.iushln(n)},h.prototype.invm=function(t){return this.egcd(t).a.umod(t)},h.prototype.isEven=function(){return(this.words[0]&1)===0},h.prototype.isOdd=function(){return(this.words[0]&1)===1},h.prototype.andln=function(t){return this.words[0]&t},h.prototype.bincn=function(t){M(typeof t=="number");var e=t%26,i=(t-e)/26,n=1<<e;if(this.length<=i)return this._expand(i+1),this.words[i]|=n,this;for(var o=n,f=i;o!==0&&f<this.length;f++){var c=this.words[f]|0;c+=o,o=c>>>26,c&=67108863,this.words[f]=c}return o!==0&&(this.words[f]=o,this.length++),this},h.prototype.isZero=function(){return this.length===1&&this.words[0]===0},h.prototype.cmpn=function(t){var e=t<0;if(this.negative!==0&&!e)return-1;if(this.negative===0&&e)return 1;this._strip();var i;if(this.length>1)i=1;else{e&&(t=-t),M(t<=67108863,"Number is too big");var n=this.words[0]|0;i=n===t?0:n<t?-1:1}return this.negative!==0?-i|0:i},h.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return-1;if(this.negative===0&&t.negative!==0)return 1;var e=this.ucmp(t);return this.negative!==0?-e|0:e},h.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var n=this.words[i]|0,o=t.words[i]|0;if(n!==o){n<o?e=-1:n>o&&(e=1);break}}return e},h.prototype.gtn=function(t){return this.cmpn(t)===1},h.prototype.gt=function(t){return this.cmp(t)===1},h.prototype.gten=function(t){return this.cmpn(t)>=0},h.prototype.gte=function(t){return this.cmp(t)>=0},h.prototype.ltn=function(t){return this.cmpn(t)===-1},h.prototype.lt=function(t){return this.cmp(t)===-1},h.prototype.lten=function(t){return this.cmpn(t)<=0},h.prototype.lte=function(t){return this.cmp(t)<=0},h.prototype.eqn=function(t){return this.cmpn(t)===0},h.prototype.eq=function(t){return this.cmp(t)===0},h.red=function(t){return new g(t)},h.prototype.toRed=function(t){return M(!this.red,"Already a number in reduction context"),M(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},h.prototype.fromRed=function(){return M(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},h.prototype._forceRed=function(t){return this.red=t,this},h.prototype.forceRed=function(t){return M(!this.red,"Already a number in reduction context"),this._forceRed(t)},h.prototype.redAdd=function(t){return M(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},h.prototype.redIAdd=function(t){return M(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},h.prototype.redSub=function(t){return M(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},h.prototype.redISub=function(t){return M(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},h.prototype.redShl=function(t){return M(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},h.prototype.redMul=function(t){return M(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},h.prototype.redIMul=function(t){return M(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},h.prototype.redSqr=function(){return M(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},h.prototype.redISqr=function(){return M(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},h.prototype.redSqrt=function(){return M(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},h.prototype.redInvm=function(){return M(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},h.prototype.redNeg=function(){return M(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},h.prototype.redPow=function(t){return M(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var Kt={k256:null,p224:null,p192:null,p25519:null};function q(s,t){this.name=s,this.p=new h(t,16),this.n=this.p.bitLength(),this.k=new h(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}q.prototype._tmp=function(){var t=new h(null);return t.words=new Array(Math.ceil(this.n/13)),t},q.prototype.ireduce=function(t){var e=t,i;do this.split(e,this.tmp),e=this.imulK(e),e=e.iadd(this.tmp),i=e.bitLength();while(i>this.n);var n=i<this.n?-1:e.ucmp(this.p);return n===0?(e.words[0]=0,e.length=1):n>0?e.isub(this.p):e.strip!==void 0?e.strip():e._strip(),e},q.prototype.split=function(t,e){t.iushrn(this.n,0,e)},q.prototype.imulK=function(t){return t.imul(this.k)};function _t(){q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}S(_t,q),_t.prototype.split=function(t,e){for(var i=4194303,n=Math.min(t.length,9),o=0;o<n;o++)e.words[o]=t.words[o];if(e.length=n,t.length<=9){t.words[0]=0,t.length=1;return}var f=t.words[9];for(e.words[e.length++]=f&i,o=10;o<t.length;o++){var c=t.words[o]|0;t.words[o-10]=(c&i)<<4|f>>>22,f=c}f>>>=22,t.words[o-10]=f,f===0&&t.length>10?t.length-=10:t.length-=9},_t.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var n=t.words[i]|0;e+=n*977,t.words[i]=e&67108863,e=n*64+(e/67108864|0)}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function l(){q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}S(l,q);function d(){q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}S(d,q);function p(){q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}S(p,q),p.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var n=(t.words[i]|0)*19+e,o=n&67108863;n>>>=26,t.words[i]=o,e=n}return e!==0&&(t.words[t.length++]=e),t},h._prime=function(t){if(Kt[t])return Kt[t];var e;if(t==="k256")e=new _t;else if(t==="p224")e=new l;else if(t==="p192")e=new d;else if(t==="p25519")e=new p;else throw new Error("Unknown prime "+t);return Kt[t]=e,e};function g(s){if(typeof s=="string"){var t=h._prime(s);this.m=t.p,this.prime=t}else M(s.gtn(1),"modulus must be greater than 1"),this.m=s,this.prime=null}g.prototype._verify1=function(t){M(t.negative===0,"red works only with positives"),M(t.red,"red works only with red numbers")},g.prototype._verify2=function(t,e){M((t.negative|e.negative)===0,"red works only with positives"),M(t.red&&t.red===e.red,"red works only with red numbers")},g.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(B(t,t.umod(this.m)._forceRed(this)),t)},g.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},g.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},g.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},g.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},g.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},g.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},g.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},g.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},g.prototype.isqr=function(t){return this.imul(t,t.clone())},g.prototype.sqr=function(t){return this.mul(t,t)},g.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(M(e%2===1),e===3){var i=this.m.add(new h(1)).iushrn(2);return this.pow(t,i)}for(var n=this.m.subn(1),o=0;!n.isZero()&&n.andln(1)===0;)o++,n.iushrn(1);M(!n.isZero());var f=new h(1).toRed(this),c=f.redNeg(),a=this.m.subn(1).iushrn(1),r=this.m.bitLength();for(r=new h(2*r*r).toRed(this);this.pow(r,a).cmp(c)!==0;)r.redIAdd(c);for(var u=this.pow(r,n),b=this.pow(t,n.addn(1).iushrn(1)),y=this.pow(t,n),_=o;y.cmp(f)!==0;){for(var O=y,N=0;O.cmp(f)!==0;N++)O=O.redSqr();M(N<_);var I=this.pow(u,new h(1).iushln(_-N-1));b=b.redMul(I),u=I.redSqr(),y=y.redMul(u),_=N}return b},g.prototype.invm=function(t){var e=t._invmp(this.m);return e.negative!==0?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},g.prototype.pow=function(t,e){if(e.isZero())return new h(1).toRed(this);if(e.cmpn(1)===0)return t.clone();var i=4,n=new Array(1<<i);n[0]=new h(1).toRed(this),n[1]=t;for(var o=2;o<n.length;o++)n[o]=this.mul(n[o-1],t);var f=n[0],c=0,a=0,r=e.bitLength()%26;for(r===0&&(r=26),o=e.length-1;o>=0;o--){for(var u=e.words[o],b=r-1;b>=0;b--){var y=u>>b&1;if(f!==n[0]&&(f=this.sqr(f)),y===0&&c===0){a=0;continue}c<<=1,c|=y,a++,!(a!==i&&(o!==0||b!==0))&&(f=this.mul(f,n[c]),a=0,c=0)}r=26}return f},g.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},g.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},h.mont=function(t){return new m(t)};function m(s){g.call(this,s),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new h(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)}S(m,g),m.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},m.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},m.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=i.isub(n).iushrn(this.shift),f=o;return o.cmp(this.m)>=0?f=o.isub(this.m):o.cmpn(0)<0&&(f=o.iadd(this.m)),f._forceRed(this)},m.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new h(0)._forceRed(this);var i=t.mul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=i.isub(n).iushrn(this.shift),f=o;return o.cmp(this.m)>=0?f=o.isub(this.m):o.cmpn(0)<0&&(f=o.iadd(this.m)),f._forceRed(this)},m.prototype.invm=function(t){var e=this.imod(t._invmp(this.m).mul(this.r2));return e._forceRed(this)}})(typeof Le>"u"||Le,hr)});var Or={};_r(Or,{CetusLeverageSDK:()=>Vt,default:()=>Cr,leverage_mainnet:()=>Se});module.exports=br(Or);var dr=require("@cetusprotocol/common-sdk");var Yt=require("@cetusprotocol/common-sdk");var Se={full_rpc_url:Yt.FullRpcUrlMainnet,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v2",providers:Yt.DefaultProviders,leverage:{package_id:"0xa1265373a081c3529c303a727118205b6a766843fcefa9ffc6d3463b2a7a3117",published_at:"0xa1265373a081c3529c303a727118205b6a766843fcefa9ffc6d3463b2a7a3117",version:0,config:{global_config_id:"0x248fe11489520df1902cef873fb7c83f055506b4510152450fb6925a4fe587f2",markets_table_id:"0x353e5a81fbc10a8efddb3217dc5200274bc5afc07496f83350b35fd6d715aba5"}},suilend:{lendingMarket:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",ownerCapId:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",ownerCapId:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",isHidden:!0}],lendingMarketId:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lendingMarketType:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",apiUrl:"https://d10td5ybgrf39v.cloudfront.net"}};var fr=require("@suilend/sdk/client"),K=require("@suilend/sdk");var Sr=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Ae=Math.ceil,Nt=Math.floor,Rt="[BigNumber Error] ",Je=Rt+"Number primitive has more than 15 significant digits: ",Tt=1e14,P=14,ke=9007199254740991,Ce=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Zt=1e7,bt=1e9;function Qe(w){var v,M,S,h=x.prototype={constructor:x,toString:null,valueOf:null},D=new x(1),A=20,C=4,k=-7,B=21,F=-1e7,U=1e7,xt=!1,Dt=1,St=0,It={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},Ct="0123456789abcdefghijklmnopqrstuvwxyz",qt=!0;function x(l,d){var p,g,m,s,t,e,i,n,o=this;if(!(o instanceof x))return new x(l,d);if(d==null){if(l&&l._isBigNumber===!0){o.s=l.s,!l.c||l.e>U?o.c=o.e=null:l.e<F?o.c=[o.e=0]:(o.e=l.e,o.c=l.c.slice());return}if((e=typeof l=="number")&&l*0==0){if(o.s=1/l<0?(l=-l,-1):1,l===~~l){for(s=0,t=l;t>=10;t/=10,s++);s>U?o.c=o.e=null:(o.e=s,o.c=[l]);return}n=String(l)}else{if(!Sr.test(n=String(l)))return S(o,n,e);o.s=n.charCodeAt(0)==45?(n=n.slice(1),-1):1}(s=n.indexOf("."))>-1&&(n=n.replace(".","")),(t=n.search(/e/i))>0?(s<0&&(s=t),s+=+n.slice(t+1),n=n.substring(0,t)):s<0&&(s=n.length)}else{if(z(d,2,Ct.length,"Base"),d==10&&qt)return o=new x(l),q(o,A+o.e+1,C);if(n=String(l),e=typeof l=="number"){if(l*0!=0)return S(o,n,e,d);if(o.s=1/l<0?(n=n.slice(1),-1):1,x.DEBUG&&n.replace(/^0\.0*|\./,"").length>15)throw Error(Je+l)}else o.s=n.charCodeAt(0)===45?(n=n.slice(1),-1):1;for(p=Ct.slice(0,d),s=t=0,i=n.length;t<i;t++)if(p.indexOf(g=n.charAt(t))<0){if(g=="."){if(t>s){s=i;continue}}else if(!m&&(n==n.toUpperCase()&&(n=n.toLowerCase())||n==n.toLowerCase()&&(n=n.toUpperCase()))){m=!0,t=-1,s=0;continue}return S(o,String(l),e,d)}e=!1,n=M(n,d,10,o.s),(s=n.indexOf("."))>-1?n=n.replace(".",""):s=n.length}for(t=0;n.charCodeAt(t)===48;t++);for(i=n.length;n.charCodeAt(--i)===48;);if(n=n.slice(t,++i)){if(i-=t,e&&x.DEBUG&&i>15&&(l>ke||l!==Nt(l)))throw Error(Je+o.s*l);if((s=s-t-1)>U)o.c=o.e=null;else if(s<F)o.c=[o.e=0];else{if(o.e=s,o.c=[],t=(s+1)%P,s<0&&(t+=P),t<i){for(t&&o.c.push(+n.slice(0,t)),i-=P;t<i;)o.c.push(+n.slice(t,t+=P));t=P-(n=n.slice(t)).length}else t-=i;for(;t--;n+="0");o.c.push(+n)}}else o.c=[o.e=0]}x.clone=Qe,x.ROUND_UP=0,x.ROUND_DOWN=1,x.ROUND_CEIL=2,x.ROUND_FLOOR=3,x.ROUND_HALF_UP=4,x.ROUND_HALF_DOWN=5,x.ROUND_HALF_EVEN=6,x.ROUND_HALF_CEIL=7,x.ROUND_HALF_FLOOR=8,x.EUCLID=9,x.config=x.set=function(l){var d,p;if(l!=null)if(typeof l=="object"){if(l.hasOwnProperty(d="DECIMAL_PLACES")&&(p=l[d],z(p,0,bt,d),A=p),l.hasOwnProperty(d="ROUNDING_MODE")&&(p=l[d],z(p,0,8,d),C=p),l.hasOwnProperty(d="EXPONENTIAL_AT")&&(p=l[d],p&&p.pop?(z(p[0],-bt,0,d),z(p[1],0,bt,d),k=p[0],B=p[1]):(z(p,-bt,bt,d),k=-(B=p<0?-p:p))),l.hasOwnProperty(d="RANGE"))if(p=l[d],p&&p.pop)z(p[0],-bt,-1,d),z(p[1],1,bt,d),F=p[0],U=p[1];else if(z(p,-bt,bt,d),p)F=-(U=p<0?-p:p);else throw Error(Rt+d+" cannot be zero: "+p);if(l.hasOwnProperty(d="CRYPTO"))if(p=l[d],p===!!p)if(p)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))xt=p;else throw xt=!p,Error(Rt+"crypto unavailable");else xt=p;else throw Error(Rt+d+" not true or false: "+p);if(l.hasOwnProperty(d="MODULO_MODE")&&(p=l[d],z(p,0,9,d),Dt=p),l.hasOwnProperty(d="POW_PRECISION")&&(p=l[d],z(p,0,bt,d),St=p),l.hasOwnProperty(d="FORMAT"))if(p=l[d],typeof p=="object")It=p;else throw Error(Rt+d+" not an object: "+p);if(l.hasOwnProperty(d="ALPHABET"))if(p=l[d],typeof p=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(p))qt=p.slice(0,10)=="0123456789",Ct=p;else throw Error(Rt+d+" invalid: "+p)}else throw Error(Rt+"Object expected: "+l);return{DECIMAL_PLACES:A,ROUNDING_MODE:C,EXPONENTIAL_AT:[k,B],RANGE:[F,U],CRYPTO:xt,MODULO_MODE:Dt,POW_PRECISION:St,FORMAT:It,ALPHABET:Ct}},x.isBigNumber=function(l){if(!l||l._isBigNumber!==!0)return!1;if(!x.DEBUG)return!0;var d,p,g=l.c,m=l.e,s=l.s;t:if({}.toString.call(g)=="[object Array]"){if((s===1||s===-1)&&m>=-bt&&m<=bt&&m===Nt(m)){if(g[0]===0){if(m===0&&g.length===1)return!0;break t}if(d=(m+1)%P,d<1&&(d+=P),String(g[0]).length==d){for(d=0;d<g.length;d++)if(p=g[d],p<0||p>=Tt||p!==Nt(p))break t;if(p!==0)return!0}}}else if(g===null&&m===null&&(s===null||s===1||s===-1))return!0;throw Error(Rt+"Invalid BigNumber: "+l)},x.maximum=x.max=function(){return kt(arguments,-1)},x.minimum=x.min=function(){return kt(arguments,1)},x.random=(function(){var l=9007199254740992,d=Math.random()*l&2097151?function(){return Nt(Math.random()*l)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(p){var g,m,s,t,e,i=0,n=[],o=new x(D);if(p==null?p=A:z(p,0,bt),t=Ae(p/P),xt)if(crypto.getRandomValues){for(g=crypto.getRandomValues(new Uint32Array(t*=2));i<t;)e=g[i]*131072+(g[i+1]>>>11),e>=9e15?(m=crypto.getRandomValues(new Uint32Array(2)),g[i]=m[0],g[i+1]=m[1]):(n.push(e%1e14),i+=2);i=t/2}else if(crypto.randomBytes){for(g=crypto.randomBytes(t*=7);i<t;)e=(g[i]&31)*281474976710656+g[i+1]*1099511627776+g[i+2]*4294967296+g[i+3]*16777216+(g[i+4]<<16)+(g[i+5]<<8)+g[i+6],e>=9e15?crypto.randomBytes(7).copy(g,i):(n.push(e%1e14),i+=7);i=t/7}else throw xt=!1,Error(Rt+"crypto unavailable");if(!xt)for(;i<t;)e=d(),e<9e15&&(n[i++]=e%1e14);for(t=n[--i],p%=P,t&&p&&(e=Ce[P-p],n[i]=Nt(t/e)*e);n[i]===0;n.pop(),i--);if(i<0)n=[s=0];else{for(s=-1;n[0]===0;n.splice(0,1),s-=P);for(i=1,e=n[0];e>=10;e/=10,i++);i<P&&(s-=P-i)}return o.e=s,o.c=n,o}})(),x.sum=function(){for(var l=1,d=arguments,p=new x(d[0]);l<d.length;)p=p.plus(d[l++]);return p},M=(function(){var l="0123456789";function d(p,g,m,s){for(var t,e=[0],i,n=0,o=p.length;n<o;){for(i=e.length;i--;e[i]*=g);for(e[0]+=s.indexOf(p.charAt(n++)),t=0;t<e.length;t++)e[t]>m-1&&(e[t+1]==null&&(e[t+1]=0),e[t+1]+=e[t]/m|0,e[t]%=m)}return e.reverse()}return function(p,g,m,s,t){var e,i,n,o,f,c,a,r,u=p.indexOf("."),b=A,y=C;for(u>=0&&(o=St,St=0,p=p.replace(".",""),r=new x(g),c=r.pow(p.length-u),St=o,r.c=d(zt(Et(c.c),c.e,"0"),10,m,l),r.e=r.c.length),a=d(p,g,m,t?(e=Ct,l):(e=l,Ct)),n=o=a.length;a[--o]==0;a.pop());if(!a[0])return e.charAt(0);if(u<0?--n:(c.c=a,c.e=n,c.s=s,c=v(c,r,b,y,m),a=c.c,f=c.r,n=c.e),i=n+b+1,u=a[i],o=m/2,f=f||i<0||a[i+1]!=null,f=y<4?(u!=null||f)&&(y==0||y==(c.s<0?3:2)):u>o||u==o&&(y==4||f||y==6&&a[i-1]&1||y==(c.s<0?8:7)),i<1||!a[0])p=f?zt(e.charAt(1),-b,e.charAt(0)):e.charAt(0);else{if(a.length=i,f)for(--m;++a[--i]>m;)a[i]=0,i||(++n,a=[1].concat(a));for(o=a.length;!a[--o];);for(u=0,p="";u<=o;p+=e.charAt(a[u++]));p=zt(p,n,e.charAt(0))}return p}})(),v=(function(){function l(g,m,s){var t,e,i,n,o=0,f=g.length,c=m%Zt,a=m/Zt|0;for(g=g.slice();f--;)i=g[f]%Zt,n=g[f]/Zt|0,t=a*i+n*c,e=c*i+t%Zt*Zt+o,o=(e/s|0)+(t/Zt|0)+a*n,g[f]=e%s;return o&&(g=[o].concat(g)),g}function d(g,m,s,t){var e,i;if(s!=t)i=s>t?1:-1;else for(e=i=0;e<s;e++)if(g[e]!=m[e]){i=g[e]>m[e]?1:-1;break}return i}function p(g,m,s,t){for(var e=0;s--;)g[s]-=e,e=g[s]<m[s]?1:0,g[s]=e*t+g[s]-m[s];for(;!g[0]&&g.length>1;g.splice(0,1));}return function(g,m,s,t,e){var i,n,o,f,c,a,r,u,b,y,_,O,N,I,Lt,L,T,Ot=g.s==m.s?1:-1,E=g.c,R=m.c;if(!E||!E[0]||!R||!R[0])return new x(!g.s||!m.s||(E?R&&E[0]==R[0]:!R)?NaN:E&&E[0]==0||!R?Ot*0:Ot/0);for(u=new x(Ot),b=u.c=[],n=g.e-m.e,Ot=s+n+1,e||(e=Tt,n=Bt(g.e/P)-Bt(m.e/P),Ot=Ot/P|0),o=0;R[o]==(E[o]||0);o++);if(R[o]>(E[o]||0)&&n--,Ot<0)b.push(1),f=!0;else{for(I=E.length,L=R.length,o=0,Ot+=2,c=Nt(e/(R[0]+1)),c>1&&(R=l(R,c,e),E=l(E,c,e),L=R.length,I=E.length),N=L,y=E.slice(0,L),_=y.length;_<L;y[_++]=0);T=R.slice(),T=[0].concat(T),Lt=R[0],R[1]>=e/2&&Lt++;do{if(c=0,i=d(R,y,L,_),i<0){if(O=y[0],L!=_&&(O=O*e+(y[1]||0)),c=Nt(O/Lt),c>1)for(c>=e&&(c=e-1),a=l(R,c,e),r=a.length,_=y.length;d(a,y,r,_)==1;)c--,p(a,L<r?T:R,r,e),r=a.length,i=1;else c==0&&(i=c=1),a=R.slice(),r=a.length;if(r<_&&(a=[0].concat(a)),p(y,a,_,e),_=y.length,i==-1)for(;d(R,y,L,_)<1;)c++,p(y,L<_?T:R,_,e),_=y.length}else i===0&&(c++,y=[0]);b[o++]=c,y[0]?y[_++]=E[N]||0:(y=[E[N]],_=1)}while((N++<I||y[0]!=null)&&Ot--);f=y[0]!=null,b[0]||b.splice(0,1)}if(e==Tt){for(o=1,Ot=b[0];Ot>=10;Ot/=10,o++);q(u,s+(u.e=o+n*P-1)+1,t,f)}else u.e=n,u.r=+f;return u}})();function $t(l,d,p,g){var m,s,t,e,i;if(p==null?p=C:z(p,0,8),!l.c)return l.toString();if(m=l.c[0],t=l.e,d==null)i=Et(l.c),i=g==1||g==2&&(t<=k||t>=B)?Qt(i,t):zt(i,t,"0");else if(l=q(new x(l),d,p),s=l.e,i=Et(l.c),e=i.length,g==1||g==2&&(d<=s||s<=k)){for(;e<d;i+="0",e++);i=Qt(i,s)}else if(d-=t+(g===2&&s>t),i=zt(i,s,"0"),s+1>e){if(--d>0)for(i+=".";d--;i+="0");}else if(d+=s-e,d>0)for(s+1==e&&(i+=".");d--;i+="0");return l.s<0&&m?"-"+i:i}function kt(l,d){for(var p,g,m=1,s=new x(l[0]);m<l.length;m++)g=new x(l[m]),(!g.s||(p=Gt(s,g))===d||p===0&&s.s===d)&&(s=g);return s}function Kt(l,d,p){for(var g=1,m=d.length;!d[--m];d.pop());for(m=d[0];m>=10;m/=10,g++);return(p=g+p*P-1)>U?l.c=l.e=null:p<F?l.c=[l.e=0]:(l.e=p,l.c=d),l}S=(function(){var l=/^(-?)0([xbo])(?=\w[\w.]*$)/i,d=/^([^.]+)\.$/,p=/^\.([^.]+)$/,g=/^-?(Infinity|NaN)$/,m=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(s,t,e,i){var n,o=e?t:t.replace(m,"");if(g.test(o))s.s=isNaN(o)?null:o<0?-1:1;else{if(!e&&(o=o.replace(l,function(f,c,a){return n=(a=a.toLowerCase())=="x"?16:a=="b"?2:8,!i||i==n?c:f}),i&&(n=i,o=o.replace(d,"$1").replace(p,"0.$1")),t!=o))return new x(o,n);if(x.DEBUG)throw Error(Rt+"Not a"+(i?" base "+i:"")+" number: "+t);s.s=null}s.c=s.e=null}})();function q(l,d,p,g){var m,s,t,e,i,n,o,f=l.c,c=Ce;if(f){t:{for(m=1,e=f[0];e>=10;e/=10,m++);if(s=d-m,s<0)s+=P,t=d,i=f[n=0],o=Nt(i/c[m-t-1]%10);else if(n=Ae((s+1)/P),n>=f.length)if(g){for(;f.length<=n;f.push(0));i=o=0,m=1,s%=P,t=s-P+1}else break t;else{for(i=e=f[n],m=1;e>=10;e/=10,m++);s%=P,t=s-P+m,o=t<0?0:Nt(i/c[m-t-1]%10)}if(g=g||d<0||f[n+1]!=null||(t<0?i:i%c[m-t-1]),g=p<4?(o||g)&&(p==0||p==(l.s<0?3:2)):o>5||o==5&&(p==4||g||p==6&&(s>0?t>0?i/c[m-t]:0:f[n-1])%10&1||p==(l.s<0?8:7)),d<1||!f[0])return f.length=0,g?(d-=l.e+1,f[0]=c[(P-d%P)%P],l.e=-d||0):f[0]=l.e=0,l;if(s==0?(f.length=n,e=1,n--):(f.length=n+1,e=c[P-s],f[n]=t>0?Nt(i/c[m-t]%c[t])*e:0),g)for(;;)if(n==0){for(s=1,t=f[0];t>=10;t/=10,s++);for(t=f[0]+=e,e=1;t>=10;t/=10,e++);s!=e&&(l.e++,f[0]==Tt&&(f[0]=1));break}else{if(f[n]+=e,f[n]!=Tt)break;f[n--]=0,e=1}for(s=f.length;f[--s]===0;f.pop());}l.e>U?l.c=l.e=null:l.e<F&&(l.c=[l.e=0])}return l}function _t(l){var d,p=l.e;return p===null?l.toString():(d=Et(l.c),d=p<=k||p>=B?Qt(d,p):zt(d,p,"0"),l.s<0?"-"+d:d)}return h.absoluteValue=h.abs=function(){var l=new x(this);return l.s<0&&(l.s=1),l},h.comparedTo=function(l,d){return Gt(this,new x(l,d))},h.decimalPlaces=h.dp=function(l,d){var p,g,m,s=this;if(l!=null)return z(l,0,bt),d==null?d=C:z(d,0,8),q(new x(s),l+s.e+1,d);if(!(p=s.c))return null;if(g=((m=p.length-1)-Bt(this.e/P))*P,m=p[m])for(;m%10==0;m/=10,g--);return g<0&&(g=0),g},h.dividedBy=h.div=function(l,d){return v(this,new x(l,d),A,C)},h.dividedToIntegerBy=h.idiv=function(l,d){return v(this,new x(l,d),0,1)},h.exponentiatedBy=h.pow=function(l,d){var p,g,m,s,t,e,i,n,o,f=this;if(l=new x(l),l.c&&!l.isInteger())throw Error(Rt+"Exponent not an integer: "+_t(l));if(d!=null&&(d=new x(d)),e=l.e>14,!f.c||!f.c[0]||f.c[0]==1&&!f.e&&f.c.length==1||!l.c||!l.c[0])return o=new x(Math.pow(+_t(f),e?l.s*(2-Jt(l)):+_t(l))),d?o.mod(d):o;if(i=l.s<0,d){if(d.c?!d.c[0]:!d.s)return new x(NaN);g=!i&&f.isInteger()&&d.isInteger(),g&&(f=f.mod(d))}else{if(l.e>9&&(f.e>0||f.e<-1||(f.e==0?f.c[0]>1||e&&f.c[1]>=24e7:f.c[0]<8e13||e&&f.c[0]<=9999975e7)))return s=f.s<0&&Jt(l)?-0:0,f.e>-1&&(s=1/s),new x(i?1/s:s);St&&(s=Ae(St/P+2))}for(e?(p=new x(.5),i&&(l.s=1),n=Jt(l)):(m=Math.abs(+_t(l)),n=m%2),o=new x(D);;){if(n){if(o=o.times(f),!o.c)break;s?o.c.length>s&&(o.c.length=s):g&&(o=o.mod(d))}if(m){if(m=Nt(m/2),m===0)break;n=m%2}else if(l=l.times(p),q(l,l.e+1,1),l.e>14)n=Jt(l);else{if(m=+_t(l),m===0)break;n=m%2}f=f.times(f),s?f.c&&f.c.length>s&&(f.c.length=s):g&&(f=f.mod(d))}return g?o:(i&&(o=D.div(o)),d?o.mod(d):s?q(o,St,C,t):o)},h.integerValue=function(l){var d=new x(this);return l==null?l=C:z(l,0,8),q(d,d.e+1,l)},h.isEqualTo=h.eq=function(l,d){return Gt(this,new x(l,d))===0},h.isFinite=function(){return!!this.c},h.isGreaterThan=h.gt=function(l,d){return Gt(this,new x(l,d))>0},h.isGreaterThanOrEqualTo=h.gte=function(l,d){return(d=Gt(this,new x(l,d)))===1||d===0},h.isInteger=function(){return!!this.c&&Bt(this.e/P)>this.c.length-2},h.isLessThan=h.lt=function(l,d){return Gt(this,new x(l,d))<0},h.isLessThanOrEqualTo=h.lte=function(l,d){return(d=Gt(this,new x(l,d)))===-1||d===0},h.isNaN=function(){return!this.s},h.isNegative=function(){return this.s<0},h.isPositive=function(){return this.s>0},h.isZero=function(){return!!this.c&&this.c[0]==0},h.minus=function(l,d){var p,g,m,s,t=this,e=t.s;if(l=new x(l,d),d=l.s,!e||!d)return new x(NaN);if(e!=d)return l.s=-d,t.plus(l);var i=t.e/P,n=l.e/P,o=t.c,f=l.c;if(!i||!n){if(!o||!f)return o?(l.s=-d,l):new x(f?t:NaN);if(!o[0]||!f[0])return f[0]?(l.s=-d,l):new x(o[0]?t:C==3?-0:0)}if(i=Bt(i),n=Bt(n),o=o.slice(),e=i-n){for((s=e<0)?(e=-e,m=o):(n=i,m=f),m.reverse(),d=e;d--;m.push(0));m.reverse()}else for(g=(s=(e=o.length)<(d=f.length))?e:d,e=d=0;d<g;d++)if(o[d]!=f[d]){s=o[d]<f[d];break}if(s&&(m=o,o=f,f=m,l.s=-l.s),d=(g=f.length)-(p=o.length),d>0)for(;d--;o[p++]=0);for(d=Tt-1;g>e;){if(o[--g]<f[g]){for(p=g;p&&!o[--p];o[p]=d);--o[p],o[g]+=Tt}o[g]-=f[g]}for(;o[0]==0;o.splice(0,1),--n);return o[0]?Kt(l,o,n):(l.s=C==3?-1:1,l.c=[l.e=0],l)},h.modulo=h.mod=function(l,d){var p,g,m=this;return l=new x(l,d),!m.c||!l.s||l.c&&!l.c[0]?new x(NaN):!l.c||m.c&&!m.c[0]?new x(m):(Dt==9?(g=l.s,l.s=1,p=v(m,l,0,3),l.s=g,p.s*=g):p=v(m,l,0,Dt),l=m.minus(p.times(l)),!l.c[0]&&Dt==1&&(l.s=m.s),l)},h.multipliedBy=h.times=function(l,d){var p,g,m,s,t,e,i,n,o,f,c,a,r,u,b,y=this,_=y.c,O=(l=new x(l,d)).c;if(!_||!O||!_[0]||!O[0])return!y.s||!l.s||_&&!_[0]&&!O||O&&!O[0]&&!_?l.c=l.e=l.s=null:(l.s*=y.s,!_||!O?l.c=l.e=null:(l.c=[0],l.e=0)),l;for(g=Bt(y.e/P)+Bt(l.e/P),l.s*=y.s,i=_.length,f=O.length,i<f&&(r=_,_=O,O=r,m=i,i=f,f=m),m=i+f,r=[];m--;r.push(0));for(u=Tt,b=Zt,m=f;--m>=0;){for(p=0,c=O[m]%b,a=O[m]/b|0,t=i,s=m+t;s>m;)n=_[--t]%b,o=_[t]/b|0,e=a*n+o*c,n=c*n+e%b*b+r[s]+p,p=(n/u|0)+(e/b|0)+a*o,r[s--]=n%u;r[s]=p}return p?++g:r.splice(0,1),Kt(l,r,g)},h.negated=function(){var l=new x(this);return l.s=-l.s||null,l},h.plus=function(l,d){var p,g=this,m=g.s;if(l=new x(l,d),d=l.s,!m||!d)return new x(NaN);if(m!=d)return l.s=-d,g.minus(l);var s=g.e/P,t=l.e/P,e=g.c,i=l.c;if(!s||!t){if(!e||!i)return new x(m/0);if(!e[0]||!i[0])return i[0]?l:new x(e[0]?g:m*0)}if(s=Bt(s),t=Bt(t),e=e.slice(),m=s-t){for(m>0?(t=s,p=i):(m=-m,p=e),p.reverse();m--;p.push(0));p.reverse()}for(m=e.length,d=i.length,m-d<0&&(p=i,i=e,e=p,d=m),m=0;d;)m=(e[--d]=e[d]+i[d]+m)/Tt|0,e[d]=Tt===e[d]?0:e[d]%Tt;return m&&(e=[m].concat(e),++t),Kt(l,e,t)},h.precision=h.sd=function(l,d){var p,g,m,s=this;if(l!=null&&l!==!!l)return z(l,1,bt),d==null?d=C:z(d,0,8),q(new x(s),l,d);if(!(p=s.c))return null;if(m=p.length-1,g=m*P+1,m=p[m]){for(;m%10==0;m/=10,g--);for(m=p[0];m>=10;m/=10,g++);}return l&&s.e+1>g&&(g=s.e+1),g},h.shiftedBy=function(l){return z(l,-ke,ke),this.times("1e"+l)},h.squareRoot=h.sqrt=function(){var l,d,p,g,m,s=this,t=s.c,e=s.s,i=s.e,n=A+4,o=new x("0.5");if(e!==1||!t||!t[0])return new x(!e||e<0&&(!t||t[0])?NaN:t?s:1/0);if(e=Math.sqrt(+_t(s)),e==0||e==1/0?(d=Et(t),(d.length+i)%2==0&&(d+="0"),e=Math.sqrt(+d),i=Bt((i+1)/2)-(i<0||i%2),e==1/0?d="5e"+i:(d=e.toExponential(),d=d.slice(0,d.indexOf("e")+1)+i),p=new x(d)):p=new x(e+""),p.c[0]){for(i=p.e,e=i+n,e<3&&(e=0);;)if(m=p,p=o.times(m.plus(v(s,m,n,1))),Et(m.c).slice(0,e)===(d=Et(p.c)).slice(0,e))if(p.e<i&&--e,d=d.slice(e-3,e+1),d=="9999"||!g&&d=="4999"){if(!g&&(q(m,m.e+A+2,0),m.times(m).eq(s))){p=m;break}n+=4,e+=4,g=1}else{(!+d||!+d.slice(1)&&d.charAt(0)=="5")&&(q(p,p.e+A+2,1),l=!p.times(p).eq(s));break}}return q(p,p.e+A+1,C,l)},h.toExponential=function(l,d){return l!=null&&(z(l,0,bt),l++),$t(this,l,d,1)},h.toFixed=function(l,d){return l!=null&&(z(l,0,bt),l=l+this.e+1),$t(this,l,d)},h.toFormat=function(l,d,p){var g,m=this;if(p==null)l!=null&&d&&typeof d=="object"?(p=d,d=null):l&&typeof l=="object"?(p=l,l=d=null):p=It;else if(typeof p!="object")throw Error(Rt+"Argument not an object: "+p);if(g=m.toFixed(l,d),m.c){var s,t=g.split("."),e=+p.groupSize,i=+p.secondaryGroupSize,n=p.groupSeparator||"",o=t[0],f=t[1],c=m.s<0,a=c?o.slice(1):o,r=a.length;if(i&&(s=e,e=i,i=s,r-=s),e>0&&r>0){for(s=r%e||e,o=a.substr(0,s);s<r;s+=e)o+=n+a.substr(s,e);i>0&&(o+=n+a.slice(s)),c&&(o="-"+o)}g=f?o+(p.decimalSeparator||"")+((i=+p.fractionGroupSize)?f.replace(new RegExp("\\d{"+i+"}\\B","g"),"$&"+(p.fractionGroupSeparator||"")):f):o}return(p.prefix||"")+g+(p.suffix||"")},h.toFraction=function(l){var d,p,g,m,s,t,e,i,n,o,f,c,a=this,r=a.c;if(l!=null&&(e=new x(l),!e.isInteger()&&(e.c||e.s!==1)||e.lt(D)))throw Error(Rt+"Argument "+(e.isInteger()?"out of range: ":"not an integer: ")+_t(e));if(!r)return new x(a);for(d=new x(D),n=p=new x(D),g=i=new x(D),c=Et(r),s=d.e=c.length-a.e-1,d.c[0]=Ce[(t=s%P)<0?P+t:t],l=!l||e.comparedTo(d)>0?s>0?d:n:e,t=U,U=1/0,e=new x(c),i.c[0]=0;o=v(e,d,0,1),m=p.plus(o.times(g)),m.comparedTo(l)!=1;)p=g,g=m,n=i.plus(o.times(m=n)),i=m,d=e.minus(o.times(m=d)),e=m;return m=v(l.minus(p),g,0,1),i=i.plus(m.times(n)),p=p.plus(m.times(g)),i.s=n.s=a.s,s=s*2,f=v(n,g,s,C).minus(a).abs().comparedTo(v(i,p,s,C).minus(a).abs())<1?[n,g]:[i,p],U=t,f},h.toNumber=function(){return+_t(this)},h.toPrecision=function(l,d){return l!=null&&z(l,1,bt),$t(this,l,d,2)},h.toString=function(l){var d,p=this,g=p.s,m=p.e;return m===null?g?(d="Infinity",g<0&&(d="-"+d)):d="NaN":(l==null?d=m<=k||m>=B?Qt(Et(p.c),m):zt(Et(p.c),m,"0"):l===10&&qt?(p=q(new x(p),A+m+1,C),d=zt(Et(p.c),p.e,"0")):(z(l,2,Ct.length,"Base"),d=M(zt(Et(p.c),m,"0"),10,l,g,!0)),g<0&&p.c[0]&&(d="-"+d)),d},h.valueOf=h.toJSON=function(){return _t(this)},h._isBigNumber=!0,h[Symbol.toStringTag]="BigNumber",h[Symbol.for("nodejs.util.inspect.custom")]=h.valueOf,w!=null&&x.set(w),x}function Bt(w){var v=w|0;return w>0||w===v?v:v-1}function Et(w){for(var v,M,S=1,h=w.length,D=w[0]+"";S<h;){for(v=w[S++]+"",M=P-v.length;M--;v="0"+v);D+=v}for(h=D.length;D.charCodeAt(--h)===48;);return D.slice(0,h+1||1)}function Gt(w,v){var M,S,h=w.c,D=v.c,A=w.s,C=v.s,k=w.e,B=v.e;if(!A||!C)return null;if(M=h&&!h[0],S=D&&!D[0],M||S)return M?S?0:-C:A;if(A!=C)return A;if(M=A<0,S=k==B,!h||!D)return S?0:!h^M?1:-1;if(!S)return k>B^M?1:-1;for(C=(k=h.length)<(B=D.length)?k:B,A=0;A<C;A++)if(h[A]!=D[A])return h[A]>D[A]^M?1:-1;return k==B?0:k>B^M?1:-1}function z(w,v,M,S){if(w<v||w>M||w!==Nt(w))throw Error(Rt+(S||"Argument")+(typeof w=="number"?w<v||w>M?" out of range: ":" not an integer: ":" not a primitive number: ")+String(w))}function Jt(w){var v=w.c.length-1;return Bt(w.e/P)==v&&w.c[v]%2!=0}function Qt(w,v){return(w.length>1?w.charAt(0)+"."+w.slice(1):w)+(v<0?"e":"e+")+v}function zt(w,v,M){var S,h;if(v<0){for(h=M+".";++v;h+=M);w=h+w}else if(S=w.length,++v>S){for(h=M,v-=S;--v;h+=M);w+=h}else v<S&&(w=w.slice(0,v)+"."+w.slice(v));return w}var Ar=Qe(),Ut=Ar;var Ft=require("@suilend/sdk"),Ht=require("@suilend/sui-fe");var je=be(require("crypto")),te=new Uint8Array(256),jt=te.length;function Oe(){return jt>te.length-16&&(je.default.randomFillSync(te),jt=0),te.slice(jt,jt+=16)}var At=[];for(let w=0;w<256;++w)At.push((w+256).toString(16).slice(1));function tr(w,v=0){return At[w[v+0]]+At[w[v+1]]+At[w[v+2]]+At[w[v+3]]+"-"+At[w[v+4]]+At[w[v+5]]+"-"+At[w[v+6]]+At[w[v+7]]+"-"+At[w[v+8]]+At[w[v+9]]+"-"+At[w[v+10]]+At[w[v+11]]+At[w[v+12]]+At[w[v+13]]+At[w[v+14]]+At[w[v+15]]}var er=be(require("crypto")),De={randomUUID:er.default.randomUUID};function kr(w,v,M){if(De.randomUUID&&!v&&!w)return De.randomUUID();w=w||{};let S=w.random||(w.rng||Oe)();if(S[6]=S[6]&15|64,S[8]=S[8]&63|128,v){M=M||0;for(let h=0;h<16;++h)v[M+h]=S[h];return v}return tr(S)}var ee=kr;function rr(w){return w.depositedAmount.eq(0)?new Ut(0):w.borrowedAmount.div(w.depositedAmount).times(100)}function Re(w){let v=rr(w);if(!v.gt(100))return(0,Ft.linearlyInterpolate)(w.config.interestRate,"utilPercent","aprPercent",v)}function ir(w){let v=rr(w),M=Re(w);if(!(M===void 0||v.gt(100)))return new Ut(v.div(100)).times(M.div(100)).times(1-w.config.spreadFeeBps/1e4).times(100)}function nr(w,v,M,S){w===Ft.Side.DEPOSIT&&([Ht.NORMALIZED_flSUI_COINTYPE,Ht.NORMALIZED_jugSUI_COINTYPE].includes(v.coinType)&&M.push({stats:{id:ee(),isActive:!0,rewardIndex:-1,reserve:v,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${S.sdkOptions?.suilend?.apiUrl}/partners/LiqAg.png`,perDay:new Ut(.036),side:Ft.Side.DEPOSIT},obligationClaims:{}}),v.coinType===Ht.NORMALIZED_LBTC_COINTYPE&&M.push({stats:{id:ee(),isActive:!0,rewardIndex:-1,reserve:v,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${S.sdkOptions?.suilend?.apiUrl}/partners/Lombard Lux.png`,perDay:new Ut(0),side:Ft.Side.DEPOSIT},obligationClaims:{}}))}function or(w,v,M){return{...w,depositedAmount:v===Ft.Side.DEPOSIT?Ut.max(w.depositedAmount.plus(M),0):w.depositedAmount,borrowedAmount:v===Ft.Side.BORROW?Ut.max(w.borrowedAmount.plus(M),0):w.borrowedAmount}}function sr(w,v,M){let S=w===Ft.Side.DEPOSIT?v.depositedAmount:v.borrowedAmount,h=w===Ft.Side.DEPOSIT?M.depositedAmount:M.borrowedAmount,D=h.eq(0)?new Ut(-1):S.div(h);return{multiplier:D,isValid:!D.eq(-1)}}function ar(w,v,M,S){let h=w.map(A=>({...A,stats:{...A.stats,perDay:S?A.stats.perDay.times(M):void 0}})),D=v.map(A=>({...A,stats:{...A.stats,aprPercent:S?A.stats.aprPercent.times(M):void 0}}));return{newPerDayRewards:h,newAprRewards:D}}var Pe=require("@cetusprotocol/common-sdk"),re=class{constructor(v){this.getSuiLendCoinInfo=(v,M)=>{let{allLendingMarketData:S,lstAprPercentMap:h}=this.lendingMarketCache??{};if(!S||!h)throw new Error("lendingMarketCache is not initialized");let D=Object.values(S??{})[0],A=D.lendingMarket.reserves.find(_t=>_t.coinType===v);if(!A)throw new Error("reserve not found");let C=this.obligationsCache?.[D.lendingMarket.id],k="borrow",B=C.rewardMap[A.token.coinType]?.[k]??[],F=(0,K.getFilteredRewards)(B);nr(k,A,F,this.sdk);let U=(0,K.getStakingYieldAprPercent)(k,A.coinType,h),xt=k===K.Side.DEPOSIT?A.depositAprPercent:A.borrowAprPercent,Dt=xt,St=or(A,k,M);Dt=k===K.Side.DEPOSIT?ir(St):Re(St);let{multiplier:It,isValid:Ct}=sr(k,A,St),qt=(0,K.getDedupedPerDayRewards)(F),x=(0,K.getDedupedAprRewards)(F),{newPerDayRewards:$t,newAprRewards:kt}=ar(qt,x,It,Ct),Kt=(0,K.getTotalAprPercent)(k,xt,F,U),q=Dt===void 0||kt.some(_t=>_t.stats.aprPercent===void 0)?void 0:(0,K.getTotalAprPercent)(k,Dt,kt,U);return{borrowLimit:A.config.borrowLimit.toString(),borrowedAmount:A.borrowedAmount.toString(),remainingBorrowLimit:(0,Pe.d)(A.config.borrowLimit.toString()).sub((0,Pe.d)(A.borrowedAmount.toString())).toString(),depositAprPercent:A.depositAprPercent.toString(),totalAprPercent:Kt.toString(),borrowInterest:xt.toString(),stakingYieldAprPercent:U?.toString(),rewardAprPercent:x[0]?.stats.aprPercent?.toString()}};this.createObligation=async v=>{let{lendingMarketId:M,lendingMarketType:S}=this.sdk.sdkOptions?.suilend;return(await this.getSuilendClient(M,S)).createObligation(v)};this.sdk=v}async getSuilendClient(v,M){let S=`${v}_${M}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[S]||(this.suilendClientCache[S]=await fr.SuilendClient.initialize(v,M,this.sdk.FullClient,!0)),this.suilendClientCache[S]}async getLendingMarketData(v=!1){if(!v&&this.lendingMarketCache)return this.lendingMarketCache;let M=this.sdk.sdkOptions?.suilend?.lendingMarket||[];if(!M.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[S,h]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(M.map(async A=>{let C=await this.getSuilendClient(A.id,A.type),{lendingMarket:k,coinMetadataMap:B,refreshedRawReserves:F,reserveMap:U,reserveCoinTypes:xt,reserveCoinMetadataMap:Dt,rewardCoinTypes:St,activeRewardCoinTypes:It,rewardCoinMetadataMap:Ct}=await(0,K.initializeSuilend)(this.sdk.FullClient,C),{rewardPriceMap:qt}=await(0,K.initializeSuilendRewards)(U,It);return[A.id,{suilendClient:C,lendingMarket:k,coinMetadataMap:B,refreshedRawReserves:F,reserveMap:U,reserveCoinTypes:xt,reserveCoinMetadataMap:Dt,rewardPriceMap:qt,rewardCoinTypes:St,activeRewardCoinTypes:It,rewardCoinMetadataMap:Ct}]}))))(),(async()=>{try{let D=await fetch(`${this.sdk.sdkOptions?.suilend?.apiUrl}/springsui/apy`),A=await D.json();if(D?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(A).map(([C,k])=>[C,new Ut(k)]))}catch(D){return console.error(D),{}}})()]);return this.lendingMarketCache={allLendingMarketData:S,lstAprPercentMap:h},this.lendingMarketCache}catch(S){throw console.log("\u{1F680} getLendingMarketData error:",S),S}}async getInitializeObligations(v,M=!1){if(!M&&this.obligationsCache)return this.obligationsCache;v||(v=await this.getLendingMarketData());let S={};for(let h of Object.values(v.allLendingMarketData)){let{obligationOwnerCaps:D,obligations:A}=await(0,K.initializeObligations)(this.sdk.FullClient,h.suilendClient,h.refreshedRawReserves,h.reserveMap,this.sdk.senderAddress),C=(0,K.formatRewards)(h.reserveMap,h.rewardCoinMetadataMap,h.rewardPriceMap,A);S[h.lendingMarket.id]={obligationOwnerCaps:D,obligations:A,rewardMap:C}}return this.obligationsCache=S,this.obligationsCache}async getSuiLendUserData(v,M=!1){let{lstAprPercentMap:S}=this.lendingMarketCache??{},h=this.obligationsCache??{},D=this.sdk.sdkOptions?.suilend?.lendingMarketId,A=h[D];if(!A)throw new Error(`No user data found for lending market: ${D}`);if(v){let C=A.obligations.find(B=>B.id===v);if(!C)throw new Error(`Obligation not found: ${v}`);let k=(0,K.getNetAprPercent)(C,A.rewardMap,S??{});return{obligation:C,netAprPercent:k,deposits:C.deposits,borrowedAmount:C.borrowedAmount,depositedAmount:C.depositedAmount,netValueUsd:C.netValueUsd,rewardMap:A.rewardMap}}}};var Pt=require("@cetusprotocol/common-sdk"),Ee=be(lr()),ur=require("@mysten/sui/dist/cjs/transactions"),ie=class{constructor(v){this.getLeverageConfig=async()=>{let v=(0,Pt.getPackagerConfigs)(this._sdk.sdkOptions.leverage);return(await this._sdk.FullClient.getObject({id:v.global_config_id,options:{showContent:!0}})).data.content.fields};this.getLeverageMarketsList=async(v=!1)=>{let M="leverage_markets_list",S=this._sdk.getCache(M,v);if(S)return S;let h=(0,Pt.getPackagerConfigs)(this._sdk.sdkOptions.leverage),D=await this._sdk.FullClient.getObject({id:h.markets_table_id,options:{showContent:!0}}),A=null,C=50,k=[];for(;;){let B=await this._sdk.FullClient.getDynamicFields({parentId:D.data.content.fields.list.fields.id.id,limit:C,cursor:A});if(k.push(...B.data),B.data.length<C)break;A=B.nextCursor}return this._sdk.updateCache(M,k,Pt.CACHE_TIME_5MIN),k};this.getLeverageMarketInfo=async v=>{let M=`leverage_market_info_${v}`,S=this._sdk.getCache(M);if(S)return S;let h=await this._sdk.FullClient.getObject({id:v,options:{showContent:!0}})};this.openShort=async v=>{let{isQuote:M,marketId:S,amount:h,clmmPool:D,slippage:A}=v,{leverage:C}=this._sdk.sdkOptions,k="0x2::sui::SUI",B="0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",F=new ur.Transaction;if(!M){let U=await this.findRouters(k,B,h,!0,[D]),xt=Pt.CoinAssist.buildCoinWithBalance(BigInt(h.toString()),k,F),Dt=await this._sdk.AggregatorClient.routerSwap({routers:U.route_obj,byAmountIn:!0,inputCoin:xt,slippage:A,txb:F}),{balanceA:St,balanceB:It,receipt:Ct}=this.flashSwap({amount:h,clmmPool:D,baseCoinType:k,quoteCoinType:B,tx:F})}};this.flashSwap=v=>{let{clmm_pool:M}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:S}=(0,Pt.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:h,clmmPool:D,baseCoinType:A,quoteCoinType:C,tx:k}=v,B=(0,Pt.getDefaultSqrtPriceLimit)(!0).toString(),[F,U,xt]=k.moveCall({target:`${M.published_at}::pool::flash_swap`,arguments:[k.object(S),k.object(D),k.pure.bool(!0),k.pure.bool(!0),k.pure.u64(h.toString()),k.pure.u128(B),k.object(Pt.CLOCK_ADDRESS)],typeArguments:[A,C]});return{balanceA:F,balanceB:U,receipt:xt}};this.repayFlashSwap=v=>{let{clmm_pool:M}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:S}=(0,Pt.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{clmmPool:h,coinA:D,coinB:A,tx:C,baseCoinType:k,quoteCoinType:B}=v;C.moveCall({target:`${M.published_at}::pool::repay_flash_swap`,arguments:[C.object(S),C.object(h),C.object(D),C.object(A),C.object(Pt.CLOCK_ADDRESS)],typeArguments:[k,B]})};this._sdk=v}async findRouters(v,M,S,h,D){let{providers:A}=this._sdk.sdkOptions;try{let C={from:v,target:M,amount:new Ee.default(S.toFixed(0).toString()),byAmountIn:h,depth:3,providers:A},k=await this._sdk.AggregatorClient.findRouters(C);if(k?.error?.code===10001)return{...k,is_exceed:k.insufficientLiquidity};if(k?.insufficientLiquidity)return{...k,is_exceed:k.insufficientLiquidity};if(!k?.routes||k?.routes?.length===0)throw Error("Aggregator no router");return{amount_in:k.amountIn.toString(),amount_out:k.amountOut.toString(),is_exceed:k.insufficientLiquidity,route_obj:k,byAmountIn:!0,originRes:k}}catch{try{if(D){let k=await this._sdk.AggregatorClient.swapInPools({from:v,target:M,amount:new Ee.default(S.toFixed(0).toString()),byAmountIn:h,pools:D});return k?{amount_in:k.routeData.amountIn.toString(),amount_out:k.routeData.amountOut.toString(),is_exceed:k.isExceed,route_obj:k.routeData,byAmountIn:!0,originRes:k}:null}return null}catch{return null}}}};var Wt=require("@cetusprotocol/aggregator-sdk"),cr=require("@mysten/sui/utils"),pr=require("@mysten/sui/client"),mr=require("@cetusprotocol/sui-clmm-sdk"),Vt=class w extends dr.SdkWrapper{constructor(v,M){super(v),this._suilendModule=new re(this),this._leverageModules=new ie(this),this._aggregatorClient=new Wt.AggregatorClient({signer:(0,cr.normalizeSuiAddress)("0x0"),client:v.sui_client||new pr.SuiClient({url:v.full_rpc_url}),env:v.env==="testnet"?Wt.Env.Testnet:Wt.Env.Mainnet,pythUrls:v.pyth_urls}),this._clmmSDK=M||mr.CetusClmmSDK.createSDK({env:v.env,full_rpc_url:v.full_rpc_url})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return console.log("\u{1F680}\u{1F680}\u{1F680} ~ sdk.ts:53 ~ CetusLeverageSDK ~ this._aggregatorClient:",this._aggregatorClient),this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}static createSDK(v){return w.createCustomSDK({...Se,...v})}static createCustomSDK(v){return new w(v)}};var Cr=Vt;0&&(module.exports={CetusLeverageSDK,leverage_mainnet});
|
|
13
2
|
//# sourceMappingURL=index.js.map
|