lll-sdk 0.0.0-experimental-20250902143335 → 0.0.0-experimental-20250902145508
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 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -4
package/dist/index.js
CHANGED
|
@@ -1,38 +1,6 @@
|
|
|
1
|
-
"use strict";var su=Object.create;var Gr=Object.defineProperty;var au=Object.getOwnPropertyDescriptor;var lu=Object.getOwnPropertyNames;var uu=Object.getPrototypeOf,cu=Object.prototype.hasOwnProperty;var ur=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),du=(e,t)=>{for(var i in t)Gr(e,i,{get:t[i],enumerable:!0})},ms=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of lu(t))!cu.call(e,n)&&n!==i&&Gr(e,n,{get:()=>t[n],enumerable:!(r=au(t,n))||r.enumerable});return e};var Vr=(e,t,i)=>(i=e!=null?su(uu(e)):{},ms(t||!e||!e.__esModule?Gr(i,"default",{value:e,enumerable:!0}):i,e)),hu=e=>ms(Gr({},"__esModule",{value:!0}),e);var Zs=ur((Vs,fo)=>{"use strict";(function(e,t){"use strict";function i(S,h){if(!S)throw new Error(h||"Assertion failed")}function r(S,h){S.super_=h;var o=function(){};o.prototype=h.prototype,S.prototype=new o,S.prototype.constructor=S}function n(S,h,o){if(n.isBN(S))return S;this.negative=0,this.words=null,this.length=0,this.red=null,S!==null&&((h==="le"||h==="be")&&(o=h,h=10),this._init(S||0,h||10,o||"be"))}typeof e=="object"?e.exports=n:t.BN=n,n.BN=n,n.wordSize=26;var s;try{typeof window<"u"&&typeof window.Buffer<"u"?s=window.Buffer:s=require("buffer").Buffer}catch{}n.isBN=function(h){return h instanceof n?!0:h!==null&&typeof h=="object"&&h.constructor.wordSize===n.wordSize&&Array.isArray(h.words)},n.max=function(h,o){return h.cmp(o)>0?h:o},n.min=function(h,o){return h.cmp(o)<0?h:o},n.prototype._init=function(h,o,l){if(typeof h=="number")return this._initNumber(h,o,l);if(typeof h=="object")return this._initArray(h,o,l);o==="hex"&&(o=16),i(o===(o|0)&&o>=2&&o<=36),h=h.toString().replace(/\s+/g,"");var d=0;h[0]==="-"&&(d++,this.negative=1),d<h.length&&(o===16?this._parseHex(h,d,l):(this._parseBase(h,o,d),l==="le"&&this._initArray(this.toArray(),o,l)))},n.prototype._initNumber=function(h,o,l){h<0&&(this.negative=1,h=-h),h<67108864?(this.words=[h&67108863],this.length=1):h<4503599627370496?(this.words=[h&67108863,h/67108864&67108863],this.length=2):(i(h<9007199254740992),this.words=[h&67108863,h/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),o,l)},n.prototype._initArray=function(h,o,l){if(i(typeof h.length=="number"),h.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(h.length/3),this.words=new Array(this.length);for(var d=0;d<this.length;d++)this.words[d]=0;var m,_,b=0;if(l==="be")for(d=h.length-1,m=0;d>=0;d-=3)_=h[d]|h[d-1]<<8|h[d-2]<<16,this.words[m]|=_<<b&67108863,this.words[m+1]=_>>>26-b&67108863,b+=24,b>=26&&(b-=26,m++);else if(l==="le")for(d=0,m=0;d<h.length;d+=3)_=h[d]|h[d+1]<<8|h[d+2]<<16,this.words[m]|=_<<b&67108863,this.words[m+1]=_>>>26-b&67108863,b+=24,b>=26&&(b-=26,m++);return this._strip()};function a(S,h){var o=S.charCodeAt(h);if(o>=48&&o<=57)return o-48;if(o>=65&&o<=70)return o-55;if(o>=97&&o<=102)return o-87;i(!1,"Invalid character in "+S)}function c(S,h,o){var l=a(S,o);return o-1>=h&&(l|=a(S,o-1)<<4),l}n.prototype._parseHex=function(h,o,l){this.length=Math.ceil((h.length-o)/6),this.words=new Array(this.length);for(var d=0;d<this.length;d++)this.words[d]=0;var m=0,_=0,b;if(l==="be")for(d=h.length-1;d>=o;d-=2)b=c(h,o,d)<<m,this.words[_]|=b&67108863,m>=18?(m-=18,_+=1,this.words[_]|=b>>>26):m+=8;else{var w=h.length-o;for(d=w%2===0?o+1:o;d<h.length;d+=2)b=c(h,o,d)<<m,this.words[_]|=b&67108863,m>=18?(m-=18,_+=1,this.words[_]|=b>>>26):m+=8}this._strip()};function p(S,h,o,l){for(var d=0,m=0,_=Math.min(S.length,o),b=h;b<_;b++){var w=S.charCodeAt(b)-48;d*=l,w>=49?m=w-49+10:w>=17?m=w-17+10:m=w,i(w>=0&&m<l,"Invalid character"),d+=m}return d}n.prototype._parseBase=function(h,o,l){this.words=[0],this.length=1;for(var d=0,m=1;m<=67108863;m*=o)d++;d--,m=m/o|0;for(var _=h.length-l,b=_%d,w=Math.min(_,_-b)+l,f=0,u=l;u<w;u+=d)f=p(h,u,u+d,o),this.imuln(m),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f);if(b!==0){var M=1;for(f=p(h,u,h.length,o),u=0;u<b;u++)M*=o;this.imuln(M),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f)}this._strip()},n.prototype.copy=function(h){h.words=new Array(this.length);for(var o=0;o<this.length;o++)h.words[o]=this.words[o];h.length=this.length,h.negative=this.negative,h.red=this.red};function g(S,h){S.words=h.words,S.length=h.length,S.negative=h.negative,S.red=h.red}if(n.prototype._move=function(h){g(h,this)},n.prototype.clone=function(){var h=new n(null);return this.copy(h),h},n.prototype._expand=function(h){for(;this.length<h;)this.words[this.length++]=0;return this},n.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},n.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{n.prototype[Symbol.for("nodejs.util.inspect.custom")]=v}catch{n.prototype.inspect=v}else n.prototype.inspect=v;function v(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var y=["","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"],A=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],k=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];n.prototype.toString=function(h,o){h=h||10,o=o|0||1;var l;if(h===16||h==="hex"){l="";for(var d=0,m=0,_=0;_<this.length;_++){var b=this.words[_],w=((b<<d|m)&16777215).toString(16);m=b>>>24-d&16777215,d+=2,d>=26&&(d-=26,_--),m!==0||_!==this.length-1?l=y[6-w.length]+w+l:l=w+l}for(m!==0&&(l=m.toString(16)+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(h===(h|0)&&h>=2&&h<=36){var f=A[h],u=k[h];l="";var M=this.clone();for(M.negative=0;!M.isZero();){var q=M.modrn(u).toString(h);M=M.idivn(u),M.isZero()?l=q+l:l=y[f-q.length]+q+l}for(this.isZero()&&(l="0"+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}i(!1,"Base should be between 2 and 36")},n.prototype.toNumber=function(){var h=this.words[0];return this.length===2?h+=this.words[1]*67108864:this.length===3&&this.words[2]===1?h+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-h:h},n.prototype.toJSON=function(){return this.toString(16,2)},s&&(n.prototype.toBuffer=function(h,o){return this.toArrayLike(s,h,o)}),n.prototype.toArray=function(h,o){return this.toArrayLike(Array,h,o)};var U=function(h,o){return h.allocUnsafe?h.allocUnsafe(o):new h(o)};n.prototype.toArrayLike=function(h,o,l){this._strip();var d=this.byteLength(),m=l||Math.max(1,d);i(d<=m,"byte array longer than desired length"),i(m>0,"Requested array length <= 0");var _=U(h,m),b=o==="le"?"LE":"BE";return this["_toArrayLike"+b](_,d),_},n.prototype._toArrayLikeLE=function(h,o){for(var l=0,d=0,m=0,_=0;m<this.length;m++){var b=this.words[m]<<_|d;h[l++]=b&255,l<h.length&&(h[l++]=b>>8&255),l<h.length&&(h[l++]=b>>16&255),_===6?(l<h.length&&(h[l++]=b>>24&255),d=0,_=0):(d=b>>>24,_+=2)}if(l<h.length)for(h[l++]=d;l<h.length;)h[l++]=0},n.prototype._toArrayLikeBE=function(h,o){for(var l=h.length-1,d=0,m=0,_=0;m<this.length;m++){var b=this.words[m]<<_|d;h[l--]=b&255,l>=0&&(h[l--]=b>>8&255),l>=0&&(h[l--]=b>>16&255),_===6?(l>=0&&(h[l--]=b>>24&255),d=0,_=0):(d=b>>>24,_+=2)}if(l>=0)for(h[l--]=d;l>=0;)h[l--]=0},Math.clz32?n.prototype._countBits=function(h){return 32-Math.clz32(h)}:n.prototype._countBits=function(h){var o=h,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},n.prototype._zeroBits=function(h){if(h===0)return 26;var o=h,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},n.prototype.bitLength=function(){var h=this.words[this.length-1],o=this._countBits(h);return(this.length-1)*26+o};function P(S){for(var h=new Array(S.bitLength()),o=0;o<h.length;o++){var l=o/26|0,d=o%26;h[o]=S.words[l]>>>d&1}return h}n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var h=0,o=0;o<this.length;o++){var l=this._zeroBits(this.words[o]);if(h+=l,l!==26)break}return h},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(h){return this.negative!==0?this.abs().inotn(h).iaddn(1):this.clone()},n.prototype.fromTwos=function(h){return this.testn(h-1)?this.notn(h).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return this.negative!==0},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.prototype.iuor=function(h){for(;this.length<h.length;)this.words[this.length++]=0;for(var o=0;o<h.length;o++)this.words[o]=this.words[o]|h.words[o];return this._strip()},n.prototype.ior=function(h){return i((this.negative|h.negative)===0),this.iuor(h)},n.prototype.or=function(h){return this.length>h.length?this.clone().ior(h):h.clone().ior(this)},n.prototype.uor=function(h){return this.length>h.length?this.clone().iuor(h):h.clone().iuor(this)},n.prototype.iuand=function(h){var o;this.length>h.length?o=h:o=this;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]&h.words[l];return this.length=o.length,this._strip()},n.prototype.iand=function(h){return i((this.negative|h.negative)===0),this.iuand(h)},n.prototype.and=function(h){return this.length>h.length?this.clone().iand(h):h.clone().iand(this)},n.prototype.uand=function(h){return this.length>h.length?this.clone().iuand(h):h.clone().iuand(this)},n.prototype.iuxor=function(h){var o,l;this.length>h.length?(o=this,l=h):(o=h,l=this);for(var d=0;d<l.length;d++)this.words[d]=o.words[d]^l.words[d];if(this!==o)for(;d<o.length;d++)this.words[d]=o.words[d];return this.length=o.length,this._strip()},n.prototype.ixor=function(h){return i((this.negative|h.negative)===0),this.iuxor(h)},n.prototype.xor=function(h){return this.length>h.length?this.clone().ixor(h):h.clone().ixor(this)},n.prototype.uxor=function(h){return this.length>h.length?this.clone().iuxor(h):h.clone().iuxor(this)},n.prototype.inotn=function(h){i(typeof h=="number"&&h>=0);var o=Math.ceil(h/26)|0,l=h%26;this._expand(o),l>0&&o--;for(var d=0;d<o;d++)this.words[d]=~this.words[d]&67108863;return l>0&&(this.words[d]=~this.words[d]&67108863>>26-l),this._strip()},n.prototype.notn=function(h){return this.clone().inotn(h)},n.prototype.setn=function(h,o){i(typeof h=="number"&&h>=0);var l=h/26|0,d=h%26;return this._expand(l+1),o?this.words[l]=this.words[l]|1<<d:this.words[l]=this.words[l]&~(1<<d),this._strip()},n.prototype.iadd=function(h){var o;if(this.negative!==0&&h.negative===0)return this.negative=0,o=this.isub(h),this.negative^=1,this._normSign();if(this.negative===0&&h.negative!==0)return h.negative=0,o=this.isub(h),h.negative=1,o._normSign();var l,d;this.length>h.length?(l=this,d=h):(l=h,d=this);for(var m=0,_=0;_<d.length;_++)o=(l.words[_]|0)+(d.words[_]|0)+m,this.words[_]=o&67108863,m=o>>>26;for(;m!==0&&_<l.length;_++)o=(l.words[_]|0)+m,this.words[_]=o&67108863,m=o>>>26;if(this.length=l.length,m!==0)this.words[this.length]=m,this.length++;else if(l!==this)for(;_<l.length;_++)this.words[_]=l.words[_];return this},n.prototype.add=function(h){var o;return h.negative!==0&&this.negative===0?(h.negative=0,o=this.sub(h),h.negative^=1,o):h.negative===0&&this.negative!==0?(this.negative=0,o=h.sub(this),this.negative=1,o):this.length>h.length?this.clone().iadd(h):h.clone().iadd(this)},n.prototype.isub=function(h){if(h.negative!==0){h.negative=0;var o=this.iadd(h);return h.negative=1,o._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(h),this.negative=1,this._normSign();var l=this.cmp(h);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var d,m;l>0?(d=this,m=h):(d=h,m=this);for(var _=0,b=0;b<m.length;b++)o=(d.words[b]|0)-(m.words[b]|0)+_,_=o>>26,this.words[b]=o&67108863;for(;_!==0&&b<d.length;b++)o=(d.words[b]|0)+_,_=o>>26,this.words[b]=o&67108863;if(_===0&&b<d.length&&d!==this)for(;b<d.length;b++)this.words[b]=d.words[b];return this.length=Math.max(this.length,b),d!==this&&(this.negative=1),this._strip()},n.prototype.sub=function(h){return this.clone().isub(h)};function W(S,h,o){o.negative=h.negative^S.negative;var l=S.length+h.length|0;o.length=l,l=l-1|0;var d=S.words[0]|0,m=h.words[0]|0,_=d*m,b=_&67108863,w=_/67108864|0;o.words[0]=b;for(var f=1;f<l;f++){for(var u=w>>>26,M=w&67108863,q=Math.min(f,h.length-1),$=Math.max(0,f-S.length+1);$<=q;$++){var z=f-$|0;d=S.words[z]|0,m=h.words[$]|0,_=d*m+M,u+=_/67108864|0,M=_&67108863}o.words[f]=M|0,w=u|0}return w!==0?o.words[f]=w|0:o.length--,o._strip()}var j=function(h,o,l){var d=h.words,m=o.words,_=l.words,b=0,w,f,u,M=d[0]|0,q=M&8191,$=M>>>13,z=d[1]|0,ie=z&8191,C=z>>>13,T=d[2]|0,x=T&8191,F=T>>>13,L=d[3]|0,G=L&8191,B=L>>>13,D=d[4]|0,Z=D&8191,H=D>>>13,V=d[5]|0,ee=V&8191,te=V>>>13,ue=d[6]|0,Te=ue&8191,he=ue>>>13,_e=d[7]|0,ke=_e&8191,ce=_e>>>13,Ie=d[8]|0,st=Ie&8191,ge=Ie>>>13,Be=d[9]|0,rt=Be&8191,me=Be>>>13,Oe=m[0]|0,et=Oe&8191,fe=Oe>>>13,Ge=m[1]|0,ht=Ge&8191,ve=Ge>>>13,Ve=m[2]|0,ft=Ve&8191,we=Ve>>>13,Ze=m[3]|0,pt=Ze&8191,be=Ze>>>13,Ke=m[4]|0,mt=Ke&8191,ye=Ke>>>13,We=m[5]|0,gt=We&8191,Me=We>>>13,ze=m[6]|0,_t=ze&8191,Ae=ze>>>13,Xe=m[7]|0,vt=Xe&8191,Se=Xe>>>13,Je=m[8]|0,wt=Je&8191,Ce=Je>>>13,Ye=m[9]|0,bt=Ye&8191,Ee=Ye>>>13;l.negative=h.negative^o.negative,l.length=19,w=Math.imul(q,et),f=Math.imul(q,fe),f=f+Math.imul($,et)|0,u=Math.imul($,fe);var He=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(He>>>26)|0,He&=67108863,w=Math.imul(ie,et),f=Math.imul(ie,fe),f=f+Math.imul(C,et)|0,u=Math.imul(C,fe),w=w+Math.imul(q,ht)|0,f=f+Math.imul(q,ve)|0,f=f+Math.imul($,ht)|0,u=u+Math.imul($,ve)|0;var Jt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,w=Math.imul(x,et),f=Math.imul(x,fe),f=f+Math.imul(F,et)|0,u=Math.imul(F,fe),w=w+Math.imul(ie,ht)|0,f=f+Math.imul(ie,ve)|0,f=f+Math.imul(C,ht)|0,u=u+Math.imul(C,ve)|0,w=w+Math.imul(q,ft)|0,f=f+Math.imul(q,we)|0,f=f+Math.imul($,ft)|0,u=u+Math.imul($,we)|0;var Yt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,w=Math.imul(G,et),f=Math.imul(G,fe),f=f+Math.imul(B,et)|0,u=Math.imul(B,fe),w=w+Math.imul(x,ht)|0,f=f+Math.imul(x,ve)|0,f=f+Math.imul(F,ht)|0,u=u+Math.imul(F,ve)|0,w=w+Math.imul(ie,ft)|0,f=f+Math.imul(ie,we)|0,f=f+Math.imul(C,ft)|0,u=u+Math.imul(C,we)|0,w=w+Math.imul(q,pt)|0,f=f+Math.imul(q,be)|0,f=f+Math.imul($,pt)|0,u=u+Math.imul($,be)|0;var Qt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,w=Math.imul(Z,et),f=Math.imul(Z,fe),f=f+Math.imul(H,et)|0,u=Math.imul(H,fe),w=w+Math.imul(G,ht)|0,f=f+Math.imul(G,ve)|0,f=f+Math.imul(B,ht)|0,u=u+Math.imul(B,ve)|0,w=w+Math.imul(x,ft)|0,f=f+Math.imul(x,we)|0,f=f+Math.imul(F,ft)|0,u=u+Math.imul(F,we)|0,w=w+Math.imul(ie,pt)|0,f=f+Math.imul(ie,be)|0,f=f+Math.imul(C,pt)|0,u=u+Math.imul(C,be)|0,w=w+Math.imul(q,mt)|0,f=f+Math.imul(q,ye)|0,f=f+Math.imul($,mt)|0,u=u+Math.imul($,ye)|0;var ei=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ei>>>26)|0,ei&=67108863,w=Math.imul(ee,et),f=Math.imul(ee,fe),f=f+Math.imul(te,et)|0,u=Math.imul(te,fe),w=w+Math.imul(Z,ht)|0,f=f+Math.imul(Z,ve)|0,f=f+Math.imul(H,ht)|0,u=u+Math.imul(H,ve)|0,w=w+Math.imul(G,ft)|0,f=f+Math.imul(G,we)|0,f=f+Math.imul(B,ft)|0,u=u+Math.imul(B,we)|0,w=w+Math.imul(x,pt)|0,f=f+Math.imul(x,be)|0,f=f+Math.imul(F,pt)|0,u=u+Math.imul(F,be)|0,w=w+Math.imul(ie,mt)|0,f=f+Math.imul(ie,ye)|0,f=f+Math.imul(C,mt)|0,u=u+Math.imul(C,ye)|0,w=w+Math.imul(q,gt)|0,f=f+Math.imul(q,Me)|0,f=f+Math.imul($,gt)|0,u=u+Math.imul($,Me)|0;var ti=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ti>>>26)|0,ti&=67108863,w=Math.imul(Te,et),f=Math.imul(Te,fe),f=f+Math.imul(he,et)|0,u=Math.imul(he,fe),w=w+Math.imul(ee,ht)|0,f=f+Math.imul(ee,ve)|0,f=f+Math.imul(te,ht)|0,u=u+Math.imul(te,ve)|0,w=w+Math.imul(Z,ft)|0,f=f+Math.imul(Z,we)|0,f=f+Math.imul(H,ft)|0,u=u+Math.imul(H,we)|0,w=w+Math.imul(G,pt)|0,f=f+Math.imul(G,be)|0,f=f+Math.imul(B,pt)|0,u=u+Math.imul(B,be)|0,w=w+Math.imul(x,mt)|0,f=f+Math.imul(x,ye)|0,f=f+Math.imul(F,mt)|0,u=u+Math.imul(F,ye)|0,w=w+Math.imul(ie,gt)|0,f=f+Math.imul(ie,Me)|0,f=f+Math.imul(C,gt)|0,u=u+Math.imul(C,Me)|0,w=w+Math.imul(q,_t)|0,f=f+Math.imul(q,Ae)|0,f=f+Math.imul($,_t)|0,u=u+Math.imul($,Ae)|0;var ii=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ii>>>26)|0,ii&=67108863,w=Math.imul(ke,et),f=Math.imul(ke,fe),f=f+Math.imul(ce,et)|0,u=Math.imul(ce,fe),w=w+Math.imul(Te,ht)|0,f=f+Math.imul(Te,ve)|0,f=f+Math.imul(he,ht)|0,u=u+Math.imul(he,ve)|0,w=w+Math.imul(ee,ft)|0,f=f+Math.imul(ee,we)|0,f=f+Math.imul(te,ft)|0,u=u+Math.imul(te,we)|0,w=w+Math.imul(Z,pt)|0,f=f+Math.imul(Z,be)|0,f=f+Math.imul(H,pt)|0,u=u+Math.imul(H,be)|0,w=w+Math.imul(G,mt)|0,f=f+Math.imul(G,ye)|0,f=f+Math.imul(B,mt)|0,u=u+Math.imul(B,ye)|0,w=w+Math.imul(x,gt)|0,f=f+Math.imul(x,Me)|0,f=f+Math.imul(F,gt)|0,u=u+Math.imul(F,Me)|0,w=w+Math.imul(ie,_t)|0,f=f+Math.imul(ie,Ae)|0,f=f+Math.imul(C,_t)|0,u=u+Math.imul(C,Ae)|0,w=w+Math.imul(q,vt)|0,f=f+Math.imul(q,Se)|0,f=f+Math.imul($,vt)|0,u=u+Math.imul($,Se)|0;var ri=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ri>>>26)|0,ri&=67108863,w=Math.imul(st,et),f=Math.imul(st,fe),f=f+Math.imul(ge,et)|0,u=Math.imul(ge,fe),w=w+Math.imul(ke,ht)|0,f=f+Math.imul(ke,ve)|0,f=f+Math.imul(ce,ht)|0,u=u+Math.imul(ce,ve)|0,w=w+Math.imul(Te,ft)|0,f=f+Math.imul(Te,we)|0,f=f+Math.imul(he,ft)|0,u=u+Math.imul(he,we)|0,w=w+Math.imul(ee,pt)|0,f=f+Math.imul(ee,be)|0,f=f+Math.imul(te,pt)|0,u=u+Math.imul(te,be)|0,w=w+Math.imul(Z,mt)|0,f=f+Math.imul(Z,ye)|0,f=f+Math.imul(H,mt)|0,u=u+Math.imul(H,ye)|0,w=w+Math.imul(G,gt)|0,f=f+Math.imul(G,Me)|0,f=f+Math.imul(B,gt)|0,u=u+Math.imul(B,Me)|0,w=w+Math.imul(x,_t)|0,f=f+Math.imul(x,Ae)|0,f=f+Math.imul(F,_t)|0,u=u+Math.imul(F,Ae)|0,w=w+Math.imul(ie,vt)|0,f=f+Math.imul(ie,Se)|0,f=f+Math.imul(C,vt)|0,u=u+Math.imul(C,Se)|0,w=w+Math.imul(q,wt)|0,f=f+Math.imul(q,Ce)|0,f=f+Math.imul($,wt)|0,u=u+Math.imul($,Ce)|0;var ni=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ni>>>26)|0,ni&=67108863,w=Math.imul(rt,et),f=Math.imul(rt,fe),f=f+Math.imul(me,et)|0,u=Math.imul(me,fe),w=w+Math.imul(st,ht)|0,f=f+Math.imul(st,ve)|0,f=f+Math.imul(ge,ht)|0,u=u+Math.imul(ge,ve)|0,w=w+Math.imul(ke,ft)|0,f=f+Math.imul(ke,we)|0,f=f+Math.imul(ce,ft)|0,u=u+Math.imul(ce,we)|0,w=w+Math.imul(Te,pt)|0,f=f+Math.imul(Te,be)|0,f=f+Math.imul(he,pt)|0,u=u+Math.imul(he,be)|0,w=w+Math.imul(ee,mt)|0,f=f+Math.imul(ee,ye)|0,f=f+Math.imul(te,mt)|0,u=u+Math.imul(te,ye)|0,w=w+Math.imul(Z,gt)|0,f=f+Math.imul(Z,Me)|0,f=f+Math.imul(H,gt)|0,u=u+Math.imul(H,Me)|0,w=w+Math.imul(G,_t)|0,f=f+Math.imul(G,Ae)|0,f=f+Math.imul(B,_t)|0,u=u+Math.imul(B,Ae)|0,w=w+Math.imul(x,vt)|0,f=f+Math.imul(x,Se)|0,f=f+Math.imul(F,vt)|0,u=u+Math.imul(F,Se)|0,w=w+Math.imul(ie,wt)|0,f=f+Math.imul(ie,Ce)|0,f=f+Math.imul(C,wt)|0,u=u+Math.imul(C,Ce)|0,w=w+Math.imul(q,bt)|0,f=f+Math.imul(q,Ee)|0,f=f+Math.imul($,bt)|0,u=u+Math.imul($,Ee)|0;var oi=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(oi>>>26)|0,oi&=67108863,w=Math.imul(rt,ht),f=Math.imul(rt,ve),f=f+Math.imul(me,ht)|0,u=Math.imul(me,ve),w=w+Math.imul(st,ft)|0,f=f+Math.imul(st,we)|0,f=f+Math.imul(ge,ft)|0,u=u+Math.imul(ge,we)|0,w=w+Math.imul(ke,pt)|0,f=f+Math.imul(ke,be)|0,f=f+Math.imul(ce,pt)|0,u=u+Math.imul(ce,be)|0,w=w+Math.imul(Te,mt)|0,f=f+Math.imul(Te,ye)|0,f=f+Math.imul(he,mt)|0,u=u+Math.imul(he,ye)|0,w=w+Math.imul(ee,gt)|0,f=f+Math.imul(ee,Me)|0,f=f+Math.imul(te,gt)|0,u=u+Math.imul(te,Me)|0,w=w+Math.imul(Z,_t)|0,f=f+Math.imul(Z,Ae)|0,f=f+Math.imul(H,_t)|0,u=u+Math.imul(H,Ae)|0,w=w+Math.imul(G,vt)|0,f=f+Math.imul(G,Se)|0,f=f+Math.imul(B,vt)|0,u=u+Math.imul(B,Se)|0,w=w+Math.imul(x,wt)|0,f=f+Math.imul(x,Ce)|0,f=f+Math.imul(F,wt)|0,u=u+Math.imul(F,Ce)|0,w=w+Math.imul(ie,bt)|0,f=f+Math.imul(ie,Ee)|0,f=f+Math.imul(C,bt)|0,u=u+Math.imul(C,Ee)|0;var si=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(si>>>26)|0,si&=67108863,w=Math.imul(rt,ft),f=Math.imul(rt,we),f=f+Math.imul(me,ft)|0,u=Math.imul(me,we),w=w+Math.imul(st,pt)|0,f=f+Math.imul(st,be)|0,f=f+Math.imul(ge,pt)|0,u=u+Math.imul(ge,be)|0,w=w+Math.imul(ke,mt)|0,f=f+Math.imul(ke,ye)|0,f=f+Math.imul(ce,mt)|0,u=u+Math.imul(ce,ye)|0,w=w+Math.imul(Te,gt)|0,f=f+Math.imul(Te,Me)|0,f=f+Math.imul(he,gt)|0,u=u+Math.imul(he,Me)|0,w=w+Math.imul(ee,_t)|0,f=f+Math.imul(ee,Ae)|0,f=f+Math.imul(te,_t)|0,u=u+Math.imul(te,Ae)|0,w=w+Math.imul(Z,vt)|0,f=f+Math.imul(Z,Se)|0,f=f+Math.imul(H,vt)|0,u=u+Math.imul(H,Se)|0,w=w+Math.imul(G,wt)|0,f=f+Math.imul(G,Ce)|0,f=f+Math.imul(B,wt)|0,u=u+Math.imul(B,Ce)|0,w=w+Math.imul(x,bt)|0,f=f+Math.imul(x,Ee)|0,f=f+Math.imul(F,bt)|0,u=u+Math.imul(F,Ee)|0;var ai=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ai>>>26)|0,ai&=67108863,w=Math.imul(rt,pt),f=Math.imul(rt,be),f=f+Math.imul(me,pt)|0,u=Math.imul(me,be),w=w+Math.imul(st,mt)|0,f=f+Math.imul(st,ye)|0,f=f+Math.imul(ge,mt)|0,u=u+Math.imul(ge,ye)|0,w=w+Math.imul(ke,gt)|0,f=f+Math.imul(ke,Me)|0,f=f+Math.imul(ce,gt)|0,u=u+Math.imul(ce,Me)|0,w=w+Math.imul(Te,_t)|0,f=f+Math.imul(Te,Ae)|0,f=f+Math.imul(he,_t)|0,u=u+Math.imul(he,Ae)|0,w=w+Math.imul(ee,vt)|0,f=f+Math.imul(ee,Se)|0,f=f+Math.imul(te,vt)|0,u=u+Math.imul(te,Se)|0,w=w+Math.imul(Z,wt)|0,f=f+Math.imul(Z,Ce)|0,f=f+Math.imul(H,wt)|0,u=u+Math.imul(H,Ce)|0,w=w+Math.imul(G,bt)|0,f=f+Math.imul(G,Ee)|0,f=f+Math.imul(B,bt)|0,u=u+Math.imul(B,Ee)|0;var li=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(li>>>26)|0,li&=67108863,w=Math.imul(rt,mt),f=Math.imul(rt,ye),f=f+Math.imul(me,mt)|0,u=Math.imul(me,ye),w=w+Math.imul(st,gt)|0,f=f+Math.imul(st,Me)|0,f=f+Math.imul(ge,gt)|0,u=u+Math.imul(ge,Me)|0,w=w+Math.imul(ke,_t)|0,f=f+Math.imul(ke,Ae)|0,f=f+Math.imul(ce,_t)|0,u=u+Math.imul(ce,Ae)|0,w=w+Math.imul(Te,vt)|0,f=f+Math.imul(Te,Se)|0,f=f+Math.imul(he,vt)|0,u=u+Math.imul(he,Se)|0,w=w+Math.imul(ee,wt)|0,f=f+Math.imul(ee,Ce)|0,f=f+Math.imul(te,wt)|0,u=u+Math.imul(te,Ce)|0,w=w+Math.imul(Z,bt)|0,f=f+Math.imul(Z,Ee)|0,f=f+Math.imul(H,bt)|0,u=u+Math.imul(H,Ee)|0;var ui=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ui>>>26)|0,ui&=67108863,w=Math.imul(rt,gt),f=Math.imul(rt,Me),f=f+Math.imul(me,gt)|0,u=Math.imul(me,Me),w=w+Math.imul(st,_t)|0,f=f+Math.imul(st,Ae)|0,f=f+Math.imul(ge,_t)|0,u=u+Math.imul(ge,Ae)|0,w=w+Math.imul(ke,vt)|0,f=f+Math.imul(ke,Se)|0,f=f+Math.imul(ce,vt)|0,u=u+Math.imul(ce,Se)|0,w=w+Math.imul(Te,wt)|0,f=f+Math.imul(Te,Ce)|0,f=f+Math.imul(he,wt)|0,u=u+Math.imul(he,Ce)|0,w=w+Math.imul(ee,bt)|0,f=f+Math.imul(ee,Ee)|0,f=f+Math.imul(te,bt)|0,u=u+Math.imul(te,Ee)|0;var ci=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ci>>>26)|0,ci&=67108863,w=Math.imul(rt,_t),f=Math.imul(rt,Ae),f=f+Math.imul(me,_t)|0,u=Math.imul(me,Ae),w=w+Math.imul(st,vt)|0,f=f+Math.imul(st,Se)|0,f=f+Math.imul(ge,vt)|0,u=u+Math.imul(ge,Se)|0,w=w+Math.imul(ke,wt)|0,f=f+Math.imul(ke,Ce)|0,f=f+Math.imul(ce,wt)|0,u=u+Math.imul(ce,Ce)|0,w=w+Math.imul(Te,bt)|0,f=f+Math.imul(Te,Ee)|0,f=f+Math.imul(he,bt)|0,u=u+Math.imul(he,Ee)|0;var di=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(di>>>26)|0,di&=67108863,w=Math.imul(rt,vt),f=Math.imul(rt,Se),f=f+Math.imul(me,vt)|0,u=Math.imul(me,Se),w=w+Math.imul(st,wt)|0,f=f+Math.imul(st,Ce)|0,f=f+Math.imul(ge,wt)|0,u=u+Math.imul(ge,Ce)|0,w=w+Math.imul(ke,bt)|0,f=f+Math.imul(ke,Ee)|0,f=f+Math.imul(ce,bt)|0,u=u+Math.imul(ce,Ee)|0;var hi=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(hi>>>26)|0,hi&=67108863,w=Math.imul(rt,wt),f=Math.imul(rt,Ce),f=f+Math.imul(me,wt)|0,u=Math.imul(me,Ce),w=w+Math.imul(st,bt)|0,f=f+Math.imul(st,Ee)|0,f=f+Math.imul(ge,bt)|0,u=u+Math.imul(ge,Ee)|0;var fi=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(fi>>>26)|0,fi&=67108863,w=Math.imul(rt,bt),f=Math.imul(rt,Ee),f=f+Math.imul(me,bt)|0,u=Math.imul(me,Ee);var pi=(b+w|0)+((f&8191)<<13)|0;return b=(u+(f>>>13)|0)+(pi>>>26)|0,pi&=67108863,_[0]=He,_[1]=Jt,_[2]=Yt,_[3]=Qt,_[4]=ei,_[5]=ti,_[6]=ii,_[7]=ri,_[8]=ni,_[9]=oi,_[10]=si,_[11]=ai,_[12]=li,_[13]=ui,_[14]=ci,_[15]=di,_[16]=hi,_[17]=fi,_[18]=pi,b!==0&&(_[19]=b,l.length++),l};Math.imul||(j=W);function K(S,h,o){o.negative=h.negative^S.negative,o.length=S.length+h.length;for(var l=0,d=0,m=0;m<o.length-1;m++){var _=d;d=0;for(var b=l&67108863,w=Math.min(m,h.length-1),f=Math.max(0,m-S.length+1);f<=w;f++){var u=m-f,M=S.words[u]|0,q=h.words[f]|0,$=M*q,z=$&67108863;_=_+($/67108864|0)|0,z=z+b|0,b=z&67108863,_=_+(z>>>26)|0,d+=_>>>26,_&=67108863}o.words[m]=b,l=_,_=d}return l!==0?o.words[m]=l:o.length--,o._strip()}function X(S,h,o){return K(S,h,o)}n.prototype.mulTo=function(h,o){var l,d=this.length+h.length;return this.length===10&&h.length===10?l=j(this,h,o):d<63?l=W(this,h,o):d<1024?l=K(this,h,o):l=X(this,h,o),l};function Q(S,h){this.x=S,this.y=h}Q.prototype.makeRBT=function(h){for(var o=new Array(h),l=n.prototype._countBits(h)-1,d=0;d<h;d++)o[d]=this.revBin(d,l,h);return o},Q.prototype.revBin=function(h,o,l){if(h===0||h===l-1)return h;for(var d=0,m=0;m<o;m++)d|=(h&1)<<o-m-1,h>>=1;return d},Q.prototype.permute=function(h,o,l,d,m,_){for(var b=0;b<_;b++)d[b]=o[h[b]],m[b]=l[h[b]]},Q.prototype.transform=function(h,o,l,d,m,_){this.permute(_,h,o,l,d,m);for(var b=1;b<m;b<<=1)for(var w=b<<1,f=Math.cos(2*Math.PI/w),u=Math.sin(2*Math.PI/w),M=0;M<m;M+=w)for(var q=f,$=u,z=0;z<b;z++){var ie=l[M+z],C=d[M+z],T=l[M+z+b],x=d[M+z+b],F=q*T-$*x;x=q*x+$*T,T=F,l[M+z]=ie+T,d[M+z]=C+x,l[M+z+b]=ie-T,d[M+z+b]=C-x,z!==w&&(F=f*q-u*$,$=f*$+u*q,q=F)}},Q.prototype.guessLen13b=function(h,o){var l=Math.max(o,h)|1,d=l&1,m=0;for(l=l/2|0;l;l=l>>>1)m++;return 1<<m+1+d},Q.prototype.conjugate=function(h,o,l){if(!(l<=1))for(var d=0;d<l/2;d++){var m=h[d];h[d]=h[l-d-1],h[l-d-1]=m,m=o[d],o[d]=-o[l-d-1],o[l-d-1]=-m}},Q.prototype.normalize13b=function(h,o){for(var l=0,d=0;d<o/2;d++){var m=Math.round(h[2*d+1]/o)*8192+Math.round(h[2*d]/o)+l;h[d]=m&67108863,m<67108864?l=0:l=m/67108864|0}return h},Q.prototype.convert13b=function(h,o,l,d){for(var m=0,_=0;_<o;_++)m=m+(h[_]|0),l[2*_]=m&8191,m=m>>>13,l[2*_+1]=m&8191,m=m>>>13;for(_=2*o;_<d;++_)l[_]=0;i(m===0),i((m&-8192)===0)},Q.prototype.stub=function(h){for(var o=new Array(h),l=0;l<h;l++)o[l]=0;return o},Q.prototype.mulp=function(h,o,l){var d=2*this.guessLen13b(h.length,o.length),m=this.makeRBT(d),_=this.stub(d),b=new Array(d),w=new Array(d),f=new Array(d),u=new Array(d),M=new Array(d),q=new Array(d),$=l.words;$.length=d,this.convert13b(h.words,h.length,b,d),this.convert13b(o.words,o.length,u,d),this.transform(b,_,w,f,d,m),this.transform(u,_,M,q,d,m);for(var z=0;z<d;z++){var ie=w[z]*M[z]-f[z]*q[z];f[z]=w[z]*q[z]+f[z]*M[z],w[z]=ie}return this.conjugate(w,f,d),this.transform(w,f,$,_,d,m),this.conjugate($,_,d),this.normalize13b($,d),l.negative=h.negative^o.negative,l.length=h.length+o.length,l._strip()},n.prototype.mul=function(h){var o=new n(null);return o.words=new Array(this.length+h.length),this.mulTo(h,o)},n.prototype.mulf=function(h){var o=new n(null);return o.words=new Array(this.length+h.length),X(this,h,o)},n.prototype.imul=function(h){return this.clone().mulTo(h,this)},n.prototype.imuln=function(h){var o=h<0;o&&(h=-h),i(typeof h=="number"),i(h<67108864);for(var l=0,d=0;d<this.length;d++){var m=(this.words[d]|0)*h,_=(m&67108863)+(l&67108863);l>>=26,l+=m/67108864|0,l+=_>>>26,this.words[d]=_&67108863}return l!==0&&(this.words[d]=l,this.length++),this.length=h===0?1:this.length,o?this.ineg():this},n.prototype.muln=function(h){return this.clone().imuln(h)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(h){var o=P(h);if(o.length===0)return new n(1);for(var l=this,d=0;d<o.length&&o[d]===0;d++,l=l.sqr());if(++d<o.length)for(var m=l.sqr();d<o.length;d++,m=m.sqr())o[d]!==0&&(l=l.mul(m));return l},n.prototype.iushln=function(h){i(typeof h=="number"&&h>=0);var o=h%26,l=(h-o)/26,d=67108863>>>26-o<<26-o,m;if(o!==0){var _=0;for(m=0;m<this.length;m++){var b=this.words[m]&d,w=(this.words[m]|0)-b<<o;this.words[m]=w|_,_=b>>>26-o}_&&(this.words[m]=_,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()},n.prototype.ishln=function(h){return i(this.negative===0),this.iushln(h)},n.prototype.iushrn=function(h,o,l){i(typeof h=="number"&&h>=0);var d;o?d=(o-o%26)/26:d=0;var m=h%26,_=Math.min((h-m)/26,this.length),b=67108863^67108863>>>m<<m,w=l;if(d-=_,d=Math.max(0,d),w){for(var f=0;f<_;f++)w.words[f]=this.words[f];w.length=_}if(_!==0)if(this.length>_)for(this.length-=_,f=0;f<this.length;f++)this.words[f]=this.words[f+_];else this.words[0]=0,this.length=1;var u=0;for(f=this.length-1;f>=0&&(u!==0||f>=d);f--){var M=this.words[f]|0;this.words[f]=u<<26-m|M>>>m,u=M&b}return w&&u!==0&&(w.words[w.length++]=u),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},n.prototype.ishrn=function(h,o,l){return i(this.negative===0),this.iushrn(h,o,l)},n.prototype.shln=function(h){return this.clone().ishln(h)},n.prototype.ushln=function(h){return this.clone().iushln(h)},n.prototype.shrn=function(h){return this.clone().ishrn(h)},n.prototype.ushrn=function(h){return this.clone().iushrn(h)},n.prototype.testn=function(h){i(typeof h=="number"&&h>=0);var o=h%26,l=(h-o)/26,d=1<<o;if(this.length<=l)return!1;var m=this.words[l];return!!(m&d)},n.prototype.imaskn=function(h){i(typeof h=="number"&&h>=0);var o=h%26,l=(h-o)/26;if(i(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 d=67108863^67108863>>>o<<o;this.words[this.length-1]&=d}return this._strip()},n.prototype.maskn=function(h){return this.clone().imaskn(h)},n.prototype.iaddn=function(h){return i(typeof h=="number"),i(h<67108864),h<0?this.isubn(-h):this.negative!==0?this.length===1&&(this.words[0]|0)<=h?(this.words[0]=h-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(h),this.negative=1,this):this._iaddn(h)},n.prototype._iaddn=function(h){this.words[0]+=h;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},n.prototype.isubn=function(h){if(i(typeof h=="number"),i(h<67108864),h<0)return this.iaddn(-h);if(this.negative!==0)return this.negative=0,this.iaddn(h),this.negative=1,this;if(this.words[0]-=h,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()},n.prototype.addn=function(h){return this.clone().iaddn(h)},n.prototype.subn=function(h){return this.clone().isubn(h)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(h,o,l){var d=h.length+l,m;this._expand(d);var _,b=0;for(m=0;m<h.length;m++){_=(this.words[m+l]|0)+b;var w=(h.words[m]|0)*o;_-=w&67108863,b=(_>>26)-(w/67108864|0),this.words[m+l]=_&67108863}for(;m<this.length-l;m++)_=(this.words[m+l]|0)+b,b=_>>26,this.words[m+l]=_&67108863;if(b===0)return this._strip();for(i(b===-1),b=0,m=0;m<this.length;m++)_=-(this.words[m]|0)+b,b=_>>26,this.words[m]=_&67108863;return this.negative=1,this._strip()},n.prototype._wordDiv=function(h,o){var l=this.length-h.length,d=this.clone(),m=h,_=m.words[m.length-1]|0,b=this._countBits(_);l=26-b,l!==0&&(m=m.ushln(l),d.iushln(l),_=m.words[m.length-1]|0);var w=d.length-m.length,f;if(o!=="mod"){f=new n(null),f.length=w+1,f.words=new Array(f.length);for(var u=0;u<f.length;u++)f.words[u]=0}var M=d.clone()._ishlnsubmul(m,1,w);M.negative===0&&(d=M,f&&(f.words[w]=1));for(var q=w-1;q>=0;q--){var $=(d.words[m.length+q]|0)*67108864+(d.words[m.length+q-1]|0);for($=Math.min($/_|0,67108863),d._ishlnsubmul(m,$,q);d.negative!==0;)$--,d.negative=0,d._ishlnsubmul(m,1,q),d.isZero()||(d.negative^=1);f&&(f.words[q]=$)}return f&&f._strip(),d._strip(),o!=="div"&&l!==0&&d.iushrn(l),{div:f||null,mod:d}},n.prototype.divmod=function(h,o,l){if(i(!h.isZero()),this.isZero())return{div:new n(0),mod:new n(0)};var d,m,_;return this.negative!==0&&h.negative===0?(_=this.neg().divmod(h,o),o!=="mod"&&(d=_.div.neg()),o!=="div"&&(m=_.mod.neg(),l&&m.negative!==0&&m.iadd(h)),{div:d,mod:m}):this.negative===0&&h.negative!==0?(_=this.divmod(h.neg(),o),o!=="mod"&&(d=_.div.neg()),{div:d,mod:_.mod}):(this.negative&h.negative)!==0?(_=this.neg().divmod(h.neg(),o),o!=="div"&&(m=_.mod.neg(),l&&m.negative!==0&&m.isub(h)),{div:_.div,mod:m}):h.length>this.length||this.cmp(h)<0?{div:new n(0),mod:this}:h.length===1?o==="div"?{div:this.divn(h.words[0]),mod:null}:o==="mod"?{div:null,mod:new n(this.modrn(h.words[0]))}:{div:this.divn(h.words[0]),mod:new n(this.modrn(h.words[0]))}:this._wordDiv(h,o)},n.prototype.div=function(h){return this.divmod(h,"div",!1).div},n.prototype.mod=function(h){return this.divmod(h,"mod",!1).mod},n.prototype.umod=function(h){return this.divmod(h,"mod",!0).mod},n.prototype.divRound=function(h){var o=this.divmod(h);if(o.mod.isZero())return o.div;var l=o.div.negative!==0?o.mod.isub(h):o.mod,d=h.ushrn(1),m=h.andln(1),_=l.cmp(d);return _<0||m===1&&_===0?o.div:o.div.negative!==0?o.div.isubn(1):o.div.iaddn(1)},n.prototype.modrn=function(h){var o=h<0;o&&(h=-h),i(h<=67108863);for(var l=(1<<26)%h,d=0,m=this.length-1;m>=0;m--)d=(l*d+(this.words[m]|0))%h;return o?-d:d},n.prototype.modn=function(h){return this.modrn(h)},n.prototype.idivn=function(h){var o=h<0;o&&(h=-h),i(h<=67108863);for(var l=0,d=this.length-1;d>=0;d--){var m=(this.words[d]|0)+l*67108864;this.words[d]=m/h|0,l=m%h}return this._strip(),o?this.ineg():this},n.prototype.divn=function(h){return this.clone().idivn(h)},n.prototype.egcd=function(h){i(h.negative===0),i(!h.isZero());var o=this,l=h.clone();o.negative!==0?o=o.umod(h):o=o.clone();for(var d=new n(1),m=new n(0),_=new n(0),b=new n(1),w=0;o.isEven()&&l.isEven();)o.iushrn(1),l.iushrn(1),++w;for(var f=l.clone(),u=o.clone();!o.isZero();){for(var M=0,q=1;(o.words[0]&q)===0&&M<26;++M,q<<=1);if(M>0)for(o.iushrn(M);M-- >0;)(d.isOdd()||m.isOdd())&&(d.iadd(f),m.isub(u)),d.iushrn(1),m.iushrn(1);for(var $=0,z=1;(l.words[0]&z)===0&&$<26;++$,z<<=1);if($>0)for(l.iushrn($);$-- >0;)(_.isOdd()||b.isOdd())&&(_.iadd(f),b.isub(u)),_.iushrn(1),b.iushrn(1);o.cmp(l)>=0?(o.isub(l),d.isub(_),m.isub(b)):(l.isub(o),_.isub(d),b.isub(m))}return{a:_,b,gcd:l.iushln(w)}},n.prototype._invmp=function(h){i(h.negative===0),i(!h.isZero());var o=this,l=h.clone();o.negative!==0?o=o.umod(h):o=o.clone();for(var d=new n(1),m=new n(0),_=l.clone();o.cmpn(1)>0&&l.cmpn(1)>0;){for(var b=0,w=1;(o.words[0]&w)===0&&b<26;++b,w<<=1);if(b>0)for(o.iushrn(b);b-- >0;)d.isOdd()&&d.iadd(_),d.iushrn(1);for(var f=0,u=1;(l.words[0]&u)===0&&f<26;++f,u<<=1);if(f>0)for(l.iushrn(f);f-- >0;)m.isOdd()&&m.iadd(_),m.iushrn(1);o.cmp(l)>=0?(o.isub(l),d.isub(m)):(l.isub(o),m.isub(d))}var M;return o.cmpn(1)===0?M=d:M=m,M.cmpn(0)<0&&M.iadd(h),M},n.prototype.gcd=function(h){if(this.isZero())return h.abs();if(h.isZero())return this.abs();var o=this.clone(),l=h.clone();o.negative=0,l.negative=0;for(var d=0;o.isEven()&&l.isEven();d++)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 _=o;o=l,l=_}else if(m===0||l.cmpn(1)===0)break;o.isub(l)}while(!0);return l.iushln(d)},n.prototype.invm=function(h){return this.egcd(h).a.umod(h)},n.prototype.isEven=function(){return(this.words[0]&1)===0},n.prototype.isOdd=function(){return(this.words[0]&1)===1},n.prototype.andln=function(h){return this.words[0]&h},n.prototype.bincn=function(h){i(typeof h=="number");var o=h%26,l=(h-o)/26,d=1<<o;if(this.length<=l)return this._expand(l+1),this.words[l]|=d,this;for(var m=d,_=l;m!==0&&_<this.length;_++){var b=this.words[_]|0;b+=m,m=b>>>26,b&=67108863,this.words[_]=b}return m!==0&&(this.words[_]=m,this.length++),this},n.prototype.isZero=function(){return this.length===1&&this.words[0]===0},n.prototype.cmpn=function(h){var o=h<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&&(h=-h),i(h<=67108863,"Number is too big");var d=this.words[0]|0;l=d===h?0:d<h?-1:1}return this.negative!==0?-l|0:l},n.prototype.cmp=function(h){if(this.negative!==0&&h.negative===0)return-1;if(this.negative===0&&h.negative!==0)return 1;var o=this.ucmp(h);return this.negative!==0?-o|0:o},n.prototype.ucmp=function(h){if(this.length>h.length)return 1;if(this.length<h.length)return-1;for(var o=0,l=this.length-1;l>=0;l--){var d=this.words[l]|0,m=h.words[l]|0;if(d!==m){d<m?o=-1:d>m&&(o=1);break}}return o},n.prototype.gtn=function(h){return this.cmpn(h)===1},n.prototype.gt=function(h){return this.cmp(h)===1},n.prototype.gten=function(h){return this.cmpn(h)>=0},n.prototype.gte=function(h){return this.cmp(h)>=0},n.prototype.ltn=function(h){return this.cmpn(h)===-1},n.prototype.lt=function(h){return this.cmp(h)===-1},n.prototype.lten=function(h){return this.cmpn(h)<=0},n.prototype.lte=function(h){return this.cmp(h)<=0},n.prototype.eqn=function(h){return this.cmpn(h)===0},n.prototype.eq=function(h){return this.cmp(h)===0},n.red=function(h){return new R(h)},n.prototype.toRed=function(h){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),h.convertTo(this)._forceRed(h)},n.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(h){return this.red=h,this},n.prototype.forceRed=function(h){return i(!this.red,"Already a number in reduction context"),this._forceRed(h)},n.prototype.redAdd=function(h){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,h)},n.prototype.redIAdd=function(h){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,h)},n.prototype.redSub=function(h){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,h)},n.prototype.redISub=function(h){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,h)},n.prototype.redShl=function(h){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,h)},n.prototype.redMul=function(h){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,h),this.red.mul(this,h)},n.prototype.redIMul=function(h){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,h),this.red.imul(this,h)},n.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(h){return i(this.red&&!h.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,h)};var se={k256:null,p224:null,p192:null,p25519:null};function Y(S,h){this.name=S,this.p=new n(h,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Y.prototype._tmp=function(){var h=new n(null);return h.words=new Array(Math.ceil(this.n/13)),h},Y.prototype.ireduce=function(h){var o=h,l;do this.split(o,this.tmp),o=this.imulK(o),o=o.iadd(this.tmp),l=o.bitLength();while(l>this.n);var d=l<this.n?-1:o.ucmp(this.p);return d===0?(o.words[0]=0,o.length=1):d>0?o.isub(this.p):o.strip!==void 0?o.strip():o._strip(),o},Y.prototype.split=function(h,o){h.iushrn(this.n,0,o)},Y.prototype.imulK=function(h){return h.imul(this.k)};function le(){Y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(le,Y),le.prototype.split=function(h,o){for(var l=4194303,d=Math.min(h.length,9),m=0;m<d;m++)o.words[m]=h.words[m];if(o.length=d,h.length<=9){h.words[0]=0,h.length=1;return}var _=h.words[9];for(o.words[o.length++]=_&l,m=10;m<h.length;m++){var b=h.words[m]|0;h.words[m-10]=(b&l)<<4|_>>>22,_=b}_>>>=22,h.words[m-10]=_,_===0&&h.length>10?h.length-=10:h.length-=9},le.prototype.imulK=function(h){h.words[h.length]=0,h.words[h.length+1]=0,h.length+=2;for(var o=0,l=0;l<h.length;l++){var d=h.words[l]|0;o+=d*977,h.words[l]=o&67108863,o=d*64+(o/67108864|0)}return h.words[h.length-1]===0&&(h.length--,h.words[h.length-1]===0&&h.length--),h};function E(){Y.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(E,Y);function I(){Y.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(I,Y);function O(){Y.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(O,Y),O.prototype.imulK=function(h){for(var o=0,l=0;l<h.length;l++){var d=(h.words[l]|0)*19+o,m=d&67108863;d>>>=26,h.words[l]=m,o=d}return o!==0&&(h.words[h.length++]=o),h},n._prime=function(h){if(se[h])return se[h];var o;if(h==="k256")o=new le;else if(h==="p224")o=new E;else if(h==="p192")o=new I;else if(h==="p25519")o=new O;else throw new Error("Unknown prime "+h);return se[h]=o,o};function R(S){if(typeof S=="string"){var h=n._prime(S);this.m=h.p,this.prime=h}else i(S.gtn(1),"modulus must be greater than 1"),this.m=S,this.prime=null}R.prototype._verify1=function(h){i(h.negative===0,"red works only with positives"),i(h.red,"red works only with red numbers")},R.prototype._verify2=function(h,o){i((h.negative|o.negative)===0,"red works only with positives"),i(h.red&&h.red===o.red,"red works only with red numbers")},R.prototype.imod=function(h){return this.prime?this.prime.ireduce(h)._forceRed(this):(g(h,h.umod(this.m)._forceRed(this)),h)},R.prototype.neg=function(h){return h.isZero()?h.clone():this.m.sub(h)._forceRed(this)},R.prototype.add=function(h,o){this._verify2(h,o);var l=h.add(o);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},R.prototype.iadd=function(h,o){this._verify2(h,o);var l=h.iadd(o);return l.cmp(this.m)>=0&&l.isub(this.m),l},R.prototype.sub=function(h,o){this._verify2(h,o);var l=h.sub(o);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},R.prototype.isub=function(h,o){this._verify2(h,o);var l=h.isub(o);return l.cmpn(0)<0&&l.iadd(this.m),l},R.prototype.shl=function(h,o){return this._verify1(h),this.imod(h.ushln(o))},R.prototype.imul=function(h,o){return this._verify2(h,o),this.imod(h.imul(o))},R.prototype.mul=function(h,o){return this._verify2(h,o),this.imod(h.mul(o))},R.prototype.isqr=function(h){return this.imul(h,h.clone())},R.prototype.sqr=function(h){return this.mul(h,h)},R.prototype.sqrt=function(h){if(h.isZero())return h.clone();var o=this.m.andln(3);if(i(o%2===1),o===3){var l=this.m.add(new n(1)).iushrn(2);return this.pow(h,l)}for(var d=this.m.subn(1),m=0;!d.isZero()&&d.andln(1)===0;)m++,d.iushrn(1);i(!d.isZero());var _=new n(1).toRed(this),b=_.redNeg(),w=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new n(2*f*f).toRed(this);this.pow(f,w).cmp(b)!==0;)f.redIAdd(b);for(var u=this.pow(f,d),M=this.pow(h,d.addn(1).iushrn(1)),q=this.pow(h,d),$=m;q.cmp(_)!==0;){for(var z=q,ie=0;z.cmp(_)!==0;ie++)z=z.redSqr();i(ie<$);var C=this.pow(u,new n(1).iushln($-ie-1));M=M.redMul(C),u=C.redSqr(),q=q.redMul(u),$=ie}return M},R.prototype.invm=function(h){var o=h._invmp(this.m);return o.negative!==0?(o.negative=0,this.imod(o).redNeg()):this.imod(o)},R.prototype.pow=function(h,o){if(o.isZero())return new n(1).toRed(this);if(o.cmpn(1)===0)return h.clone();var l=4,d=new Array(1<<l);d[0]=new n(1).toRed(this),d[1]=h;for(var m=2;m<d.length;m++)d[m]=this.mul(d[m-1],h);var _=d[0],b=0,w=0,f=o.bitLength()%26;for(f===0&&(f=26),m=o.length-1;m>=0;m--){for(var u=o.words[m],M=f-1;M>=0;M--){var q=u>>M&1;if(_!==d[0]&&(_=this.sqr(_)),q===0&&b===0){w=0;continue}b<<=1,b|=q,w++,!(w!==l&&(m!==0||M!==0))&&(_=this.mul(_,d[b]),w=0,b=0)}f=26}return _},R.prototype.convertTo=function(h){var o=h.umod(this.m);return o===h?o.clone():o},R.prototype.convertFrom=function(h){var o=h.clone();return o.red=null,o},n.mont=function(h){return new N(h)};function N(S){R.call(this,S),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new n(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}r(N,R),N.prototype.convertTo=function(h){return this.imod(h.ushln(this.shift))},N.prototype.convertFrom=function(h){var o=this.imod(h.mul(this.rinv));return o.red=null,o},N.prototype.imul=function(h,o){if(h.isZero()||o.isZero())return h.words[0]=0,h.length=1,h;var l=h.imul(o),d=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),m=l.isub(d).iushrn(this.shift),_=m;return m.cmp(this.m)>=0?_=m.isub(this.m):m.cmpn(0)<0&&(_=m.iadd(this.m)),_._forceRed(this)},N.prototype.mul=function(h,o){if(h.isZero()||o.isZero())return new n(0)._forceRed(this);var l=h.mul(o),d=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),m=l.isub(d).iushrn(this.shift),_=m;return m.cmp(this.m)>=0?_=m.isub(this.m):m.cmpn(0)<0&&(_=m.iadd(this.m)),_._forceRed(this)},N.prototype.invm=function(h){var o=this.imod(h._invmp(this.m).mul(this.r2));return o._forceRed(this)}})(typeof fo>"u"||fo,Vs)});var _o=ur((Xs,un)=>{"use strict";(function(e){"use strict";var t,i=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,r=Math.ceil,n=Math.floor,s="[BigNumber Error] ",a=s+"Number primitive has more than 15 significant digits: ",c=1e14,p=14,g=9007199254740991,v=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],y=1e7,A=1e9;function k(se){var Y,le,E,I=u.prototype={constructor:u,toString:null,valueOf:null},O=new u(1),R=20,N=4,S=-7,h=21,o=-1e7,l=1e7,d=!1,m=1,_=0,b={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},w="0123456789abcdefghijklmnopqrstuvwxyz",f=!0;function u(C,T){var x,F,L,G,B,D,Z,H,V=this;if(!(V instanceof u))return new u(C,T);if(T==null){if(C&&C._isBigNumber===!0){V.s=C.s,!C.c||C.e>l?V.c=V.e=null:C.e<o?V.c=[V.e=0]:(V.e=C.e,V.c=C.c.slice());return}if((D=typeof C=="number")&&C*0==0){if(V.s=1/C<0?(C=-C,-1):1,C===~~C){for(G=0,B=C;B>=10;B/=10,G++);G>l?V.c=V.e=null:(V.e=G,V.c=[C]);return}H=String(C)}else{if(!i.test(H=String(C)))return E(V,H,D);V.s=H.charCodeAt(0)==45?(H=H.slice(1),-1):1}(G=H.indexOf("."))>-1&&(H=H.replace(".","")),(B=H.search(/e/i))>0?(G<0&&(G=B),G+=+H.slice(B+1),H=H.substring(0,B)):G<0&&(G=H.length)}else{if(j(T,2,w.length,"Base"),T==10&&f)return V=new u(C),z(V,R+V.e+1,N);if(H=String(C),D=typeof C=="number"){if(C*0!=0)return E(V,H,D,T);if(V.s=1/C<0?(H=H.slice(1),-1):1,u.DEBUG&&H.replace(/^0\.0*|\./,"").length>15)throw Error(a+C)}else V.s=H.charCodeAt(0)===45?(H=H.slice(1),-1):1;for(x=w.slice(0,T),G=B=0,Z=H.length;B<Z;B++)if(x.indexOf(F=H.charAt(B))<0){if(F=="."){if(B>G){G=Z;continue}}else if(!L&&(H==H.toUpperCase()&&(H=H.toLowerCase())||H==H.toLowerCase()&&(H=H.toUpperCase()))){L=!0,B=-1,G=0;continue}return E(V,String(C),D,T)}D=!1,H=le(H,T,10,V.s),(G=H.indexOf("."))>-1?H=H.replace(".",""):G=H.length}for(B=0;H.charCodeAt(B)===48;B++);for(Z=H.length;H.charCodeAt(--Z)===48;);if(H=H.slice(B,++Z)){if(Z-=B,D&&u.DEBUG&&Z>15&&(C>g||C!==n(C)))throw Error(a+V.s*C);if((G=G-B-1)>l)V.c=V.e=null;else if(G<o)V.c=[V.e=0];else{if(V.e=G,V.c=[],B=(G+1)%p,G<0&&(B+=p),B<Z){for(B&&V.c.push(+H.slice(0,B)),Z-=p;B<Z;)V.c.push(+H.slice(B,B+=p));B=p-(H=H.slice(B)).length}else B-=Z;for(;B--;H+="0");V.c.push(+H)}}else V.c=[V.e=0]}u.clone=k,u.ROUND_UP=0,u.ROUND_DOWN=1,u.ROUND_CEIL=2,u.ROUND_FLOOR=3,u.ROUND_HALF_UP=4,u.ROUND_HALF_DOWN=5,u.ROUND_HALF_EVEN=6,u.ROUND_HALF_CEIL=7,u.ROUND_HALF_FLOOR=8,u.EUCLID=9,u.config=u.set=function(C){var T,x;if(C!=null)if(typeof C=="object"){if(C.hasOwnProperty(T="DECIMAL_PLACES")&&(x=C[T],j(x,0,A,T),R=x),C.hasOwnProperty(T="ROUNDING_MODE")&&(x=C[T],j(x,0,8,T),N=x),C.hasOwnProperty(T="EXPONENTIAL_AT")&&(x=C[T],x&&x.pop?(j(x[0],-A,0,T),j(x[1],0,A,T),S=x[0],h=x[1]):(j(x,-A,A,T),S=-(h=x<0?-x:x))),C.hasOwnProperty(T="RANGE"))if(x=C[T],x&&x.pop)j(x[0],-A,-1,T),j(x[1],1,A,T),o=x[0],l=x[1];else if(j(x,-A,A,T),x)o=-(l=x<0?-x:x);else throw Error(s+T+" cannot be zero: "+x);if(C.hasOwnProperty(T="CRYPTO"))if(x=C[T],x===!!x)if(x)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))d=x;else throw d=!x,Error(s+"crypto unavailable");else d=x;else throw Error(s+T+" not true or false: "+x);if(C.hasOwnProperty(T="MODULO_MODE")&&(x=C[T],j(x,0,9,T),m=x),C.hasOwnProperty(T="POW_PRECISION")&&(x=C[T],j(x,0,A,T),_=x),C.hasOwnProperty(T="FORMAT"))if(x=C[T],typeof x=="object")b=x;else throw Error(s+T+" not an object: "+x);if(C.hasOwnProperty(T="ALPHABET"))if(x=C[T],typeof x=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(x))f=x.slice(0,10)=="0123456789",w=x;else throw Error(s+T+" invalid: "+x)}else throw Error(s+"Object expected: "+C);return{DECIMAL_PLACES:R,ROUNDING_MODE:N,EXPONENTIAL_AT:[S,h],RANGE:[o,l],CRYPTO:d,MODULO_MODE:m,POW_PRECISION:_,FORMAT:b,ALPHABET:w}},u.isBigNumber=function(C){if(!C||C._isBigNumber!==!0)return!1;if(!u.DEBUG)return!0;var T,x,F=C.c,L=C.e,G=C.s;e:if({}.toString.call(F)=="[object Array]"){if((G===1||G===-1)&&L>=-A&&L<=A&&L===n(L)){if(F[0]===0){if(L===0&&F.length===1)return!0;break e}if(T=(L+1)%p,T<1&&(T+=p),String(F[0]).length==T){for(T=0;T<F.length;T++)if(x=F[T],x<0||x>=c||x!==n(x))break e;if(x!==0)return!0}}}else if(F===null&&L===null&&(G===null||G===1||G===-1))return!0;throw Error(s+"Invalid BigNumber: "+C)},u.maximum=u.max=function(){return q(arguments,-1)},u.minimum=u.min=function(){return q(arguments,1)},u.random=(function(){var C=9007199254740992,T=Math.random()*C&2097151?function(){return n(Math.random()*C)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(x){var F,L,G,B,D,Z=0,H=[],V=new u(O);if(x==null?x=R:j(x,0,A),B=r(x/p),d)if(crypto.getRandomValues){for(F=crypto.getRandomValues(new Uint32Array(B*=2));Z<B;)D=F[Z]*131072+(F[Z+1]>>>11),D>=9e15?(L=crypto.getRandomValues(new Uint32Array(2)),F[Z]=L[0],F[Z+1]=L[1]):(H.push(D%1e14),Z+=2);Z=B/2}else if(crypto.randomBytes){for(F=crypto.randomBytes(B*=7);Z<B;)D=(F[Z]&31)*281474976710656+F[Z+1]*1099511627776+F[Z+2]*4294967296+F[Z+3]*16777216+(F[Z+4]<<16)+(F[Z+5]<<8)+F[Z+6],D>=9e15?crypto.randomBytes(7).copy(F,Z):(H.push(D%1e14),Z+=7);Z=B/7}else throw d=!1,Error(s+"crypto unavailable");if(!d)for(;Z<B;)D=T(),D<9e15&&(H[Z++]=D%1e14);for(B=H[--Z],x%=p,B&&x&&(D=v[p-x],H[Z]=n(B/D)*D);H[Z]===0;H.pop(),Z--);if(Z<0)H=[G=0];else{for(G=-1;H[0]===0;H.splice(0,1),G-=p);for(Z=1,D=H[0];D>=10;D/=10,Z++);Z<p&&(G-=p-Z)}return V.e=G,V.c=H,V}})(),u.sum=function(){for(var C=1,T=arguments,x=new u(T[0]);C<T.length;)x=x.plus(T[C++]);return x},le=(function(){var C="0123456789";function T(x,F,L,G){for(var B,D=[0],Z,H=0,V=x.length;H<V;){for(Z=D.length;Z--;D[Z]*=F);for(D[0]+=G.indexOf(x.charAt(H++)),B=0;B<D.length;B++)D[B]>L-1&&(D[B+1]==null&&(D[B+1]=0),D[B+1]+=D[B]/L|0,D[B]%=L)}return D.reverse()}return function(x,F,L,G,B){var D,Z,H,V,ee,te,ue,Te,he=x.indexOf("."),_e=R,ke=N;for(he>=0&&(V=_,_=0,x=x.replace(".",""),Te=new u(F),te=Te.pow(x.length-he),_=V,Te.c=T(Q(P(te.c),te.e,"0"),10,L,C),Te.e=Te.c.length),ue=T(x,F,L,B?(D=w,C):(D=C,w)),H=V=ue.length;ue[--V]==0;ue.pop());if(!ue[0])return D.charAt(0);if(he<0?--H:(te.c=ue,te.e=H,te.s=G,te=Y(te,Te,_e,ke,L),ue=te.c,ee=te.r,H=te.e),Z=H+_e+1,he=ue[Z],V=L/2,ee=ee||Z<0||ue[Z+1]!=null,ee=ke<4?(he!=null||ee)&&(ke==0||ke==(te.s<0?3:2)):he>V||he==V&&(ke==4||ee||ke==6&&ue[Z-1]&1||ke==(te.s<0?8:7)),Z<1||!ue[0])x=ee?Q(D.charAt(1),-_e,D.charAt(0)):D.charAt(0);else{if(ue.length=Z,ee)for(--L;++ue[--Z]>L;)ue[Z]=0,Z||(++H,ue=[1].concat(ue));for(V=ue.length;!ue[--V];);for(he=0,x="";he<=V;x+=D.charAt(ue[he++]));x=Q(x,H,D.charAt(0))}return x}})(),Y=(function(){function C(F,L,G){var B,D,Z,H,V=0,ee=F.length,te=L%y,ue=L/y|0;for(F=F.slice();ee--;)Z=F[ee]%y,H=F[ee]/y|0,B=ue*Z+H*te,D=te*Z+B%y*y+V,V=(D/G|0)+(B/y|0)+ue*H,F[ee]=D%G;return V&&(F=[V].concat(F)),F}function T(F,L,G,B){var D,Z;if(G!=B)Z=G>B?1:-1;else for(D=Z=0;D<G;D++)if(F[D]!=L[D]){Z=F[D]>L[D]?1:-1;break}return Z}function x(F,L,G,B){for(var D=0;G--;)F[G]-=D,D=F[G]<L[G]?1:0,F[G]=D*B+F[G]-L[G];for(;!F[0]&&F.length>1;F.splice(0,1));}return function(F,L,G,B,D){var Z,H,V,ee,te,ue,Te,he,_e,ke,ce,Ie,st,ge,Be,rt,me,Oe=F.s==L.s?1:-1,et=F.c,fe=L.c;if(!et||!et[0]||!fe||!fe[0])return new u(!F.s||!L.s||(et?fe&&et[0]==fe[0]:!fe)?NaN:et&&et[0]==0||!fe?Oe*0:Oe/0);for(he=new u(Oe),_e=he.c=[],H=F.e-L.e,Oe=G+H+1,D||(D=c,H=U(F.e/p)-U(L.e/p),Oe=Oe/p|0),V=0;fe[V]==(et[V]||0);V++);if(fe[V]>(et[V]||0)&&H--,Oe<0)_e.push(1),ee=!0;else{for(ge=et.length,rt=fe.length,V=0,Oe+=2,te=n(D/(fe[0]+1)),te>1&&(fe=C(fe,te,D),et=C(et,te,D),rt=fe.length,ge=et.length),st=rt,ke=et.slice(0,rt),ce=ke.length;ce<rt;ke[ce++]=0);me=fe.slice(),me=[0].concat(me),Be=fe[0],fe[1]>=D/2&&Be++;do{if(te=0,Z=T(fe,ke,rt,ce),Z<0){if(Ie=ke[0],rt!=ce&&(Ie=Ie*D+(ke[1]||0)),te=n(Ie/Be),te>1)for(te>=D&&(te=D-1),ue=C(fe,te,D),Te=ue.length,ce=ke.length;T(ue,ke,Te,ce)==1;)te--,x(ue,rt<Te?me:fe,Te,D),Te=ue.length,Z=1;else te==0&&(Z=te=1),ue=fe.slice(),Te=ue.length;if(Te<ce&&(ue=[0].concat(ue)),x(ke,ue,ce,D),ce=ke.length,Z==-1)for(;T(fe,ke,rt,ce)<1;)te++,x(ke,rt<ce?me:fe,ce,D),ce=ke.length}else Z===0&&(te++,ke=[0]);_e[V++]=te,ke[0]?ke[ce++]=et[st]||0:(ke=[et[st]],ce=1)}while((st++<ge||ke[0]!=null)&&Oe--);ee=ke[0]!=null,_e[0]||_e.splice(0,1)}if(D==c){for(V=1,Oe=_e[0];Oe>=10;Oe/=10,V++);z(he,G+(he.e=V+H*p-1)+1,B,ee)}else he.e=H,he.r=+ee;return he}})();function M(C,T,x,F){var L,G,B,D,Z;if(x==null?x=N:j(x,0,8),!C.c)return C.toString();if(L=C.c[0],B=C.e,T==null)Z=P(C.c),Z=F==1||F==2&&(B<=S||B>=h)?X(Z,B):Q(Z,B,"0");else if(C=z(new u(C),T,x),G=C.e,Z=P(C.c),D=Z.length,F==1||F==2&&(T<=G||G<=S)){for(;D<T;Z+="0",D++);Z=X(Z,G)}else if(T-=B+(F===2&&G>B),Z=Q(Z,G,"0"),G+1>D){if(--T>0)for(Z+=".";T--;Z+="0");}else if(T+=G-D,T>0)for(G+1==D&&(Z+=".");T--;Z+="0");return C.s<0&&L?"-"+Z:Z}function q(C,T){for(var x,F,L=1,G=new u(C[0]);L<C.length;L++)F=new u(C[L]),(!F.s||(x=W(G,F))===T||x===0&&G.s===T)&&(G=F);return G}function $(C,T,x){for(var F=1,L=T.length;!T[--L];T.pop());for(L=T[0];L>=10;L/=10,F++);return(x=F+x*p-1)>l?C.c=C.e=null:x<o?C.c=[C.e=0]:(C.e=x,C.c=T),C}E=(function(){var C=/^(-?)0([xbo])(?=\w[\w.]*$)/i,T=/^([^.]+)\.$/,x=/^\.([^.]+)$/,F=/^-?(Infinity|NaN)$/,L=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(G,B,D,Z){var H,V=D?B:B.replace(L,"");if(F.test(V))G.s=isNaN(V)?null:V<0?-1:1;else{if(!D&&(V=V.replace(C,function(ee,te,ue){return H=(ue=ue.toLowerCase())=="x"?16:ue=="b"?2:8,!Z||Z==H?te:ee}),Z&&(H=Z,V=V.replace(T,"$1").replace(x,"0.$1")),B!=V))return new u(V,H);if(u.DEBUG)throw Error(s+"Not a"+(Z?" base "+Z:"")+" number: "+B);G.s=null}G.c=G.e=null}})();function z(C,T,x,F){var L,G,B,D,Z,H,V,ee=C.c,te=v;if(ee){e:{for(L=1,D=ee[0];D>=10;D/=10,L++);if(G=T-L,G<0)G+=p,B=T,Z=ee[H=0],V=n(Z/te[L-B-1]%10);else if(H=r((G+1)/p),H>=ee.length)if(F){for(;ee.length<=H;ee.push(0));Z=V=0,L=1,G%=p,B=G-p+1}else break e;else{for(Z=D=ee[H],L=1;D>=10;D/=10,L++);G%=p,B=G-p+L,V=B<0?0:n(Z/te[L-B-1]%10)}if(F=F||T<0||ee[H+1]!=null||(B<0?Z:Z%te[L-B-1]),F=x<4?(V||F)&&(x==0||x==(C.s<0?3:2)):V>5||V==5&&(x==4||F||x==6&&(G>0?B>0?Z/te[L-B]:0:ee[H-1])%10&1||x==(C.s<0?8:7)),T<1||!ee[0])return ee.length=0,F?(T-=C.e+1,ee[0]=te[(p-T%p)%p],C.e=-T||0):ee[0]=C.e=0,C;if(G==0?(ee.length=H,D=1,H--):(ee.length=H+1,D=te[p-G],ee[H]=B>0?n(Z/te[L-B]%te[B])*D:0),F)for(;;)if(H==0){for(G=1,B=ee[0];B>=10;B/=10,G++);for(B=ee[0]+=D,D=1;B>=10;B/=10,D++);G!=D&&(C.e++,ee[0]==c&&(ee[0]=1));break}else{if(ee[H]+=D,ee[H]!=c)break;ee[H--]=0,D=1}for(G=ee.length;ee[--G]===0;ee.pop());}C.e>l?C.c=C.e=null:C.e<o&&(C.c=[C.e=0])}return C}function ie(C){var T,x=C.e;return x===null?C.toString():(T=P(C.c),T=x<=S||x>=h?X(T,x):Q(T,x,"0"),C.s<0?"-"+T:T)}return I.absoluteValue=I.abs=function(){var C=new u(this);return C.s<0&&(C.s=1),C},I.comparedTo=function(C,T){return W(this,new u(C,T))},I.decimalPlaces=I.dp=function(C,T){var x,F,L,G=this;if(C!=null)return j(C,0,A),T==null?T=N:j(T,0,8),z(new u(G),C+G.e+1,T);if(!(x=G.c))return null;if(F=((L=x.length-1)-U(this.e/p))*p,L=x[L])for(;L%10==0;L/=10,F--);return F<0&&(F=0),F},I.dividedBy=I.div=function(C,T){return Y(this,new u(C,T),R,N)},I.dividedToIntegerBy=I.idiv=function(C,T){return Y(this,new u(C,T),0,1)},I.exponentiatedBy=I.pow=function(C,T){var x,F,L,G,B,D,Z,H,V,ee=this;if(C=new u(C),C.c&&!C.isInteger())throw Error(s+"Exponent not an integer: "+ie(C));if(T!=null&&(T=new u(T)),D=C.e>14,!ee.c||!ee.c[0]||ee.c[0]==1&&!ee.e&&ee.c.length==1||!C.c||!C.c[0])return V=new u(Math.pow(+ie(ee),D?C.s*(2-K(C)):+ie(C))),T?V.mod(T):V;if(Z=C.s<0,T){if(T.c?!T.c[0]:!T.s)return new u(NaN);F=!Z&&ee.isInteger()&&T.isInteger(),F&&(ee=ee.mod(T))}else{if(C.e>9&&(ee.e>0||ee.e<-1||(ee.e==0?ee.c[0]>1||D&&ee.c[1]>=24e7:ee.c[0]<8e13||D&&ee.c[0]<=9999975e7)))return G=ee.s<0&&K(C)?-0:0,ee.e>-1&&(G=1/G),new u(Z?1/G:G);_&&(G=r(_/p+2))}for(D?(x=new u(.5),Z&&(C.s=1),H=K(C)):(L=Math.abs(+ie(C)),H=L%2),V=new u(O);;){if(H){if(V=V.times(ee),!V.c)break;G?V.c.length>G&&(V.c.length=G):F&&(V=V.mod(T))}if(L){if(L=n(L/2),L===0)break;H=L%2}else if(C=C.times(x),z(C,C.e+1,1),C.e>14)H=K(C);else{if(L=+ie(C),L===0)break;H=L%2}ee=ee.times(ee),G?ee.c&&ee.c.length>G&&(ee.c.length=G):F&&(ee=ee.mod(T))}return F?V:(Z&&(V=O.div(V)),T?V.mod(T):G?z(V,_,N,B):V)},I.integerValue=function(C){var T=new u(this);return C==null?C=N:j(C,0,8),z(T,T.e+1,C)},I.isEqualTo=I.eq=function(C,T){return W(this,new u(C,T))===0},I.isFinite=function(){return!!this.c},I.isGreaterThan=I.gt=function(C,T){return W(this,new u(C,T))>0},I.isGreaterThanOrEqualTo=I.gte=function(C,T){return(T=W(this,new u(C,T)))===1||T===0},I.isInteger=function(){return!!this.c&&U(this.e/p)>this.c.length-2},I.isLessThan=I.lt=function(C,T){return W(this,new u(C,T))<0},I.isLessThanOrEqualTo=I.lte=function(C,T){return(T=W(this,new u(C,T)))===-1||T===0},I.isNaN=function(){return!this.s},I.isNegative=function(){return this.s<0},I.isPositive=function(){return this.s>0},I.isZero=function(){return!!this.c&&this.c[0]==0},I.minus=function(C,T){var x,F,L,G,B=this,D=B.s;if(C=new u(C,T),T=C.s,!D||!T)return new u(NaN);if(D!=T)return C.s=-T,B.plus(C);var Z=B.e/p,H=C.e/p,V=B.c,ee=C.c;if(!Z||!H){if(!V||!ee)return V?(C.s=-T,C):new u(ee?B:NaN);if(!V[0]||!ee[0])return ee[0]?(C.s=-T,C):new u(V[0]?B:N==3?-0:0)}if(Z=U(Z),H=U(H),V=V.slice(),D=Z-H){for((G=D<0)?(D=-D,L=V):(H=Z,L=ee),L.reverse(),T=D;T--;L.push(0));L.reverse()}else for(F=(G=(D=V.length)<(T=ee.length))?D:T,D=T=0;T<F;T++)if(V[T]!=ee[T]){G=V[T]<ee[T];break}if(G&&(L=V,V=ee,ee=L,C.s=-C.s),T=(F=ee.length)-(x=V.length),T>0)for(;T--;V[x++]=0);for(T=c-1;F>D;){if(V[--F]<ee[F]){for(x=F;x&&!V[--x];V[x]=T);--V[x],V[F]+=c}V[F]-=ee[F]}for(;V[0]==0;V.splice(0,1),--H);return V[0]?$(C,V,H):(C.s=N==3?-1:1,C.c=[C.e=0],C)},I.modulo=I.mod=function(C,T){var x,F,L=this;return C=new u(C,T),!L.c||!C.s||C.c&&!C.c[0]?new u(NaN):!C.c||L.c&&!L.c[0]?new u(L):(m==9?(F=C.s,C.s=1,x=Y(L,C,0,3),C.s=F,x.s*=F):x=Y(L,C,0,m),C=L.minus(x.times(C)),!C.c[0]&&m==1&&(C.s=L.s),C)},I.multipliedBy=I.times=function(C,T){var x,F,L,G,B,D,Z,H,V,ee,te,ue,Te,he,_e,ke=this,ce=ke.c,Ie=(C=new u(C,T)).c;if(!ce||!Ie||!ce[0]||!Ie[0])return!ke.s||!C.s||ce&&!ce[0]&&!Ie||Ie&&!Ie[0]&&!ce?C.c=C.e=C.s=null:(C.s*=ke.s,!ce||!Ie?C.c=C.e=null:(C.c=[0],C.e=0)),C;for(F=U(ke.e/p)+U(C.e/p),C.s*=ke.s,Z=ce.length,ee=Ie.length,Z<ee&&(Te=ce,ce=Ie,Ie=Te,L=Z,Z=ee,ee=L),L=Z+ee,Te=[];L--;Te.push(0));for(he=c,_e=y,L=ee;--L>=0;){for(x=0,te=Ie[L]%_e,ue=Ie[L]/_e|0,B=Z,G=L+B;G>L;)H=ce[--B]%_e,V=ce[B]/_e|0,D=ue*H+V*te,H=te*H+D%_e*_e+Te[G]+x,x=(H/he|0)+(D/_e|0)+ue*V,Te[G--]=H%he;Te[G]=x}return x?++F:Te.splice(0,1),$(C,Te,F)},I.negated=function(){var C=new u(this);return C.s=-C.s||null,C},I.plus=function(C,T){var x,F=this,L=F.s;if(C=new u(C,T),T=C.s,!L||!T)return new u(NaN);if(L!=T)return C.s=-T,F.minus(C);var G=F.e/p,B=C.e/p,D=F.c,Z=C.c;if(!G||!B){if(!D||!Z)return new u(L/0);if(!D[0]||!Z[0])return Z[0]?C:new u(D[0]?F:L*0)}if(G=U(G),B=U(B),D=D.slice(),L=G-B){for(L>0?(B=G,x=Z):(L=-L,x=D),x.reverse();L--;x.push(0));x.reverse()}for(L=D.length,T=Z.length,L-T<0&&(x=Z,Z=D,D=x,T=L),L=0;T;)L=(D[--T]=D[T]+Z[T]+L)/c|0,D[T]=c===D[T]?0:D[T]%c;return L&&(D=[L].concat(D),++B),$(C,D,B)},I.precision=I.sd=function(C,T){var x,F,L,G=this;if(C!=null&&C!==!!C)return j(C,1,A),T==null?T=N:j(T,0,8),z(new u(G),C,T);if(!(x=G.c))return null;if(L=x.length-1,F=L*p+1,L=x[L]){for(;L%10==0;L/=10,F--);for(L=x[0];L>=10;L/=10,F++);}return C&&G.e+1>F&&(F=G.e+1),F},I.shiftedBy=function(C){return j(C,-g,g),this.times("1e"+C)},I.squareRoot=I.sqrt=function(){var C,T,x,F,L,G=this,B=G.c,D=G.s,Z=G.e,H=R+4,V=new u("0.5");if(D!==1||!B||!B[0])return new u(!D||D<0&&(!B||B[0])?NaN:B?G:1/0);if(D=Math.sqrt(+ie(G)),D==0||D==1/0?(T=P(B),(T.length+Z)%2==0&&(T+="0"),D=Math.sqrt(+T),Z=U((Z+1)/2)-(Z<0||Z%2),D==1/0?T="5e"+Z:(T=D.toExponential(),T=T.slice(0,T.indexOf("e")+1)+Z),x=new u(T)):x=new u(D+""),x.c[0]){for(Z=x.e,D=Z+H,D<3&&(D=0);;)if(L=x,x=V.times(L.plus(Y(G,L,H,1))),P(L.c).slice(0,D)===(T=P(x.c)).slice(0,D))if(x.e<Z&&--D,T=T.slice(D-3,D+1),T=="9999"||!F&&T=="4999"){if(!F&&(z(L,L.e+R+2,0),L.times(L).eq(G))){x=L;break}H+=4,D+=4,F=1}else{(!+T||!+T.slice(1)&&T.charAt(0)=="5")&&(z(x,x.e+R+2,1),C=!x.times(x).eq(G));break}}return z(x,x.e+R+1,N,C)},I.toExponential=function(C,T){return C!=null&&(j(C,0,A),C++),M(this,C,T,1)},I.toFixed=function(C,T){return C!=null&&(j(C,0,A),C=C+this.e+1),M(this,C,T)},I.toFormat=function(C,T,x){var F,L=this;if(x==null)C!=null&&T&&typeof T=="object"?(x=T,T=null):C&&typeof C=="object"?(x=C,C=T=null):x=b;else if(typeof x!="object")throw Error(s+"Argument not an object: "+x);if(F=L.toFixed(C,T),L.c){var G,B=F.split("."),D=+x.groupSize,Z=+x.secondaryGroupSize,H=x.groupSeparator||"",V=B[0],ee=B[1],te=L.s<0,ue=te?V.slice(1):V,Te=ue.length;if(Z&&(G=D,D=Z,Z=G,Te-=G),D>0&&Te>0){for(G=Te%D||D,V=ue.substr(0,G);G<Te;G+=D)V+=H+ue.substr(G,D);Z>0&&(V+=H+ue.slice(G)),te&&(V="-"+V)}F=ee?V+(x.decimalSeparator||"")+((Z=+x.fractionGroupSize)?ee.replace(new RegExp("\\d{"+Z+"}\\B","g"),"$&"+(x.fractionGroupSeparator||"")):ee):V}return(x.prefix||"")+F+(x.suffix||"")},I.toFraction=function(C){var T,x,F,L,G,B,D,Z,H,V,ee,te,ue=this,Te=ue.c;if(C!=null&&(D=new u(C),!D.isInteger()&&(D.c||D.s!==1)||D.lt(O)))throw Error(s+"Argument "+(D.isInteger()?"out of range: ":"not an integer: ")+ie(D));if(!Te)return new u(ue);for(T=new u(O),H=x=new u(O),F=Z=new u(O),te=P(Te),G=T.e=te.length-ue.e-1,T.c[0]=v[(B=G%p)<0?p+B:B],C=!C||D.comparedTo(T)>0?G>0?T:H:D,B=l,l=1/0,D=new u(te),Z.c[0]=0;V=Y(D,T,0,1),L=x.plus(V.times(F)),L.comparedTo(C)!=1;)x=F,F=L,H=Z.plus(V.times(L=H)),Z=L,T=D.minus(V.times(L=T)),D=L;return L=Y(C.minus(x),F,0,1),Z=Z.plus(L.times(H)),x=x.plus(L.times(F)),Z.s=H.s=ue.s,G=G*2,ee=Y(H,F,G,N).minus(ue).abs().comparedTo(Y(Z,x,G,N).minus(ue).abs())<1?[H,F]:[Z,x],l=B,ee},I.toNumber=function(){return+ie(this)},I.toPrecision=function(C,T){return C!=null&&j(C,1,A),M(this,C,T,2)},I.toString=function(C){var T,x=this,F=x.s,L=x.e;return L===null?F?(T="Infinity",F<0&&(T="-"+T)):T="NaN":(C==null?T=L<=S||L>=h?X(P(x.c),L):Q(P(x.c),L,"0"):C===10&&f?(x=z(new u(x),R+L+1,N),T=Q(P(x.c),x.e,"0")):(j(C,2,w.length,"Base"),T=le(Q(P(x.c),L,"0"),10,C,F,!0)),F<0&&x.c[0]&&(T="-"+T)),T},I.valueOf=I.toJSON=function(){return ie(this)},I._isBigNumber=!0,se!=null&&u.set(se),u}function U(se){var Y=se|0;return se>0||se===Y?Y:Y-1}function P(se){for(var Y,le,E=1,I=se.length,O=se[0]+"";E<I;){for(Y=se[E++]+"",le=p-Y.length;le--;Y="0"+Y);O+=Y}for(I=O.length;O.charCodeAt(--I)===48;);return O.slice(0,I+1||1)}function W(se,Y){var le,E,I=se.c,O=Y.c,R=se.s,N=Y.s,S=se.e,h=Y.e;if(!R||!N)return null;if(le=I&&!I[0],E=O&&!O[0],le||E)return le?E?0:-N:R;if(R!=N)return R;if(le=R<0,E=S==h,!I||!O)return E?0:!I^le?1:-1;if(!E)return S>h^le?1:-1;for(N=(S=I.length)<(h=O.length)?S:h,R=0;R<N;R++)if(I[R]!=O[R])return I[R]>O[R]^le?1:-1;return S==h?0:S>h^le?1:-1}function j(se,Y,le,E){if(se<Y||se>le||se!==n(se))throw Error(s+(E||"Argument")+(typeof se=="number"?se<Y||se>le?" out of range: ":" not an integer: ":" not a primitive number: ")+String(se))}function K(se){var Y=se.c.length-1;return U(se.e/p)==Y&&se.c[Y]%2!=0}function X(se,Y){return(se.length>1?se.charAt(0)+"."+se.slice(1):se)+(Y<0?"e":"e+")+Y}function Q(se,Y,le){var E,I;if(Y<0){for(I=le+".";++Y;I+=le);se=I+se}else if(E=se.length,++Y>E){for(I=le,Y-=E;--Y;I+=le);se+=I}else Y<E&&(se=se.slice(0,Y)+"."+se.slice(Y));return se}t=k(),t.default=t.BigNumber=t,typeof define=="function"&&define.amd?define(function(){return t}):typeof un<"u"&&un.exports?un.exports=t:(e||(e=typeof self<"u"&&self?self:window),e.BigNumber=t)})(Xs)});var ea=ur((Nm,Qs)=>{"use strict";var Js=_o(),Ys=Qs.exports;(function(){"use strict";function e(g){return g<10?"0"+g:g}var t=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,i=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,r,n,s={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},a;function c(g){return i.lastIndex=0,i.test(g)?'"'+g.replace(i,function(v){var y=s[v];return typeof y=="string"?y:"\\u"+("0000"+v.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+g+'"'}function p(g,v){var y,A,k,U,P=r,W,j=v[g],K=j!=null&&(j instanceof Js||Js.isBigNumber(j));switch(j&&typeof j=="object"&&typeof j.toJSON=="function"&&(j=j.toJSON(g)),typeof a=="function"&&(j=a.call(v,g,j)),typeof j){case"string":return K?j:c(j);case"number":return isFinite(j)?String(j):"null";case"boolean":case"null":case"bigint":return String(j);case"object":if(!j)return"null";if(r+=n,W=[],Object.prototype.toString.apply(j)==="[object Array]"){for(U=j.length,y=0;y<U;y+=1)W[y]=p(y,j)||"null";return k=W.length===0?"[]":r?`[
|
|
2
|
-
`+r+W.join(`,
|
|
3
|
-
`+r)+`
|
|
4
|
-
`+P+"]":"["+W.join(",")+"]",r=P,k}if(a&&typeof a=="object")for(U=a.length,y=0;y<U;y+=1)typeof a[y]=="string"&&(A=a[y],k=p(A,j),k&&W.push(c(A)+(r?": ":":")+k));else Object.keys(j).forEach(function(X){var Q=p(X,j);Q&&W.push(c(X)+(r?": ":":")+Q)});return k=W.length===0?"{}":r?`{
|
|
5
|
-
`+r+W.join(`,
|
|
6
|
-
`+r)+`
|
|
7
|
-
`+P+"}":"{"+W.join(",")+"}",r=P,k}}typeof Ys.stringify!="function"&&(Ys.stringify=function(g,v,y){var A;if(r="",n="",typeof y=="number")for(A=0;A<y;A+=1)n+=" ";else typeof y=="string"&&(n=y);if(a=v,v&&typeof v!="function"&&(typeof v!="object"||typeof v.length!="number"))throw new Error("JSON.stringify");return p("",{"":g})})})()});var ia=ur((Rm,ta)=>{"use strict";var cn=null,u0=/(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/,c0=/(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)/,d0=function(e){"use strict";var t={strict:!1,storeAsString:!1,alwaysParseAsBig:!1,useNativeBigInt:!1,protoAction:"error",constructorAction:"error"};if(e!=null){if(e.strict===!0&&(t.strict=!0),e.storeAsString===!0&&(t.storeAsString=!0),t.alwaysParseAsBig=e.alwaysParseAsBig===!0?e.alwaysParseAsBig:!1,t.useNativeBigInt=e.useNativeBigInt===!0?e.useNativeBigInt:!1,typeof e.constructorAction<"u")if(e.constructorAction==="error"||e.constructorAction==="ignore"||e.constructorAction==="preserve")t.constructorAction=e.constructorAction;else throw new Error(`Incorrect value for constructorAction option, must be "error", "ignore" or undefined but passed ${e.constructorAction}`);if(typeof e.protoAction<"u")if(e.protoAction==="error"||e.protoAction==="ignore"||e.protoAction==="preserve")t.protoAction=e.protoAction;else throw new Error(`Incorrect value for protoAction option, must be "error", "ignore" or undefined but passed ${e.protoAction}`)}var i,r,n={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
8
|
-
`,r:"\r",t:" "},s,a=function(P){throw{name:"SyntaxError",message:P,at:i,text:s}},c=function(P){return P&&P!==r&&a("Expected '"+P+"' instead of '"+r+"'"),r=s.charAt(i),i+=1,r},p=function(){var P,W="";for(r==="-"&&(W="-",c("-"));r>="0"&&r<="9";)W+=r,c();if(r===".")for(W+=".";c()&&r>="0"&&r<="9";)W+=r;if(r==="e"||r==="E")for(W+=r,c(),(r==="-"||r==="+")&&(W+=r,c());r>="0"&&r<="9";)W+=r,c();if(P=+W,!isFinite(P))a("Bad number");else return cn==null&&(cn=_o()),W.length>15?t.storeAsString?W:t.useNativeBigInt?BigInt(W):new cn(W):t.alwaysParseAsBig?t.useNativeBigInt?BigInt(P):new cn(P):P},g=function(){var P,W,j="",K;if(r==='"')for(var X=i;c();){if(r==='"')return i-1>X&&(j+=s.substring(X,i-1)),c(),j;if(r==="\\"){if(i-1>X&&(j+=s.substring(X,i-1)),c(),r==="u"){for(K=0,W=0;W<4&&(P=parseInt(c(),16),!!isFinite(P));W+=1)K=K*16+P;j+=String.fromCharCode(K)}else if(typeof n[r]=="string")j+=n[r];else break;X=i}}a("Bad string")},v=function(){for(;r&&r<=" ";)c()},y=function(){switch(r){case"t":return c("t"),c("r"),c("u"),c("e"),!0;case"f":return c("f"),c("a"),c("l"),c("s"),c("e"),!1;case"n":return c("n"),c("u"),c("l"),c("l"),null}a("Unexpected '"+r+"'")},A,k=function(){var P=[];if(r==="["){if(c("["),v(),r==="]")return c("]"),P;for(;r;){if(P.push(A()),v(),r==="]")return c("]"),P;c(","),v()}}a("Bad array")},U=function(){var P,W=Object.create(null);if(r==="{"){if(c("{"),v(),r==="}")return c("}"),W;for(;r;){if(P=g(),v(),c(":"),t.strict===!0&&Object.hasOwnProperty.call(W,P)&&a('Duplicate key "'+P+'"'),u0.test(P)===!0?t.protoAction==="error"?a("Object contains forbidden prototype property"):t.protoAction==="ignore"?A():W[P]=A():c0.test(P)===!0?t.constructorAction==="error"?a("Object contains forbidden constructor property"):t.constructorAction==="ignore"?A():W[P]=A():W[P]=A(),v(),r==="}")return c("}"),W;c(","),v()}}a("Bad object")};return A=function(){switch(v(),r){case"{":return U();case"[":return k();case'"':return g();case"-":return p();default:return r>="0"&&r<="9"?p():y()}},function(P,W){var j;return s=P+"",i=0,r=" ",j=A(),v(),r&&a("Syntax error"),typeof W=="function"?(function K(X,Q){var se,Y,le=X[Q];return le&&typeof le=="object"&&Object.keys(le).forEach(function(E){Y=K(le,E),Y!==void 0?le[E]=Y:delete le[E]}),W.call(X,Q,le)})({"":j},""):j}};ta.exports=d0});var oa=ur((Lm,dn)=>{"use strict";var ra=ea().stringify,na=ia();dn.exports=function(e){return{parse:na(e),stringify:ra}};dn.exports.parse=na();dn.exports.stringify=ra});var al=ur(J=>{"use strict";var vo=require("@mysten/sui/transactions"),h0=oa(),yt=require("@mysten/sui/utils"),sa=require("@mysten/sui/client"),aa=require("@pythnetwork/pyth-sui-js");function f0(e){return e&&e.__esModule?e:{default:e}}var p0=f0(h0),m0=Object.create,Io=Object.defineProperty,g0=Object.defineProperties,_0=Object.getOwnPropertyDescriptor,v0=Object.getOwnPropertyDescriptors,Ma=Object.getOwnPropertyNames,la=Object.getOwnPropertySymbols,w0=Object.getPrototypeOf,Aa=Object.prototype.hasOwnProperty,b0=Object.prototype.propertyIsEnumerable,ua=(e,t,i)=>t in e?Io(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,xr=(e,t)=>{for(var i in t||(t={}))Aa.call(t,i)&&ua(e,i,t[i]);if(la)for(var i of la(t))b0.call(t,i)&&ua(e,i,t[i]);return e},pn=(e,t)=>g0(e,v0(t)),y0=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof require<"u"?require:t)[i]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),M0=(e,t)=>function(){return t||(0,e[Ma(e)[0]])((t={exports:{}}).exports,t),t.exports},A0=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ma(t))!Aa.call(e,n)&&n!==i&&Io(e,n,{get:()=>t[n],enumerable:!(r=_0(t,n))||r.enumerable});return e},vr=(e,t,i)=>(i=e!=null?m0(w0(e)):{},A0(!e||!e.__esModule?Io(i,"default",{value:e,enumerable:!0}):i,e)),Nt=(e,t,i)=>new Promise((r,n)=>{var s=p=>{try{c(i.next(p))}catch(g){n(g)}},a=p=>{try{c(i.throw(p))}catch(g){n(g)}},c=p=>p.done?r(p.value):Promise.resolve(p.value).then(s,a);c((i=i.apply(e,t)).next())}),wr=M0({"node_modules/bn.js/lib/bn.js"(e,t){(function(i,r){function n(h,o){if(!h)throw new Error(o||"Assertion failed")}function s(h,o){h.super_=o;var l=function(){};l.prototype=o.prototype,h.prototype=new l,h.prototype.constructor=h}function a(h,o,l){if(a.isBN(h))return h;this.negative=0,this.words=null,this.length=0,this.red=null,h!==null&&((o==="le"||o==="be")&&(l=o,o=10),this._init(h||0,o||10,l||"be"))}typeof i=="object"?i.exports=a:r.BN=a,a.BN=a,a.wordSize=26;var c;try{typeof window<"u"&&typeof window.Buffer<"u"?c=window.Buffer:c=y0("buffer").Buffer}catch{}a.isBN=function(o){return o instanceof a?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===a.wordSize&&Array.isArray(o.words)},a.max=function(o,l){return o.cmp(l)>0?o:l},a.min=function(o,l){return o.cmp(l)<0?o:l},a.prototype._init=function(o,l,d){if(typeof o=="number")return this._initNumber(o,l,d);if(typeof o=="object")return this._initArray(o,l,d);l==="hex"&&(l=16),n(l===(l|0)&&l>=2&&l<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(l===16?this._parseHex(o,m,d):(this._parseBase(o,l,m),d==="le"&&this._initArray(this.toArray(),l,d)))},a.prototype._initNumber=function(o,l,d){o<0&&(this.negative=1,o=-o),o<67108864?(this.words=[o&67108863],this.length=1):o<4503599627370496?(this.words=[o&67108863,o/67108864&67108863],this.length=2):(n(o<9007199254740992),this.words=[o&67108863,o/67108864&67108863,1],this.length=3),d==="le"&&this._initArray(this.toArray(),l,d)},a.prototype._initArray=function(o,l,d){if(n(typeof o.length=="number"),o.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(o.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var _,b,w=0;if(d==="be")for(m=o.length-1,_=0;m>=0;m-=3)b=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[_]|=b<<w&67108863,this.words[_+1]=b>>>26-w&67108863,w+=24,w>=26&&(w-=26,_++);else if(d==="le")for(m=0,_=0;m<o.length;m+=3)b=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[_]|=b<<w&67108863,this.words[_+1]=b>>>26-w&67108863,w+=24,w>=26&&(w-=26,_++);return this._strip()};function p(h,o){var l=h.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;n(!1,"Invalid character in "+h)}function g(h,o,l){var d=p(h,l);return l-1>=o&&(d|=p(h,l-1)<<4),d}a.prototype._parseHex=function(o,l,d){this.length=Math.ceil((o.length-l)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var _=0,b=0,w;if(d==="be")for(m=o.length-1;m>=l;m-=2)w=g(o,l,m)<<_,this.words[b]|=w&67108863,_>=18?(_-=18,b+=1,this.words[b]|=w>>>26):_+=8;else{var f=o.length-l;for(m=f%2===0?l+1:l;m<o.length;m+=2)w=g(o,l,m)<<_,this.words[b]|=w&67108863,_>=18?(_-=18,b+=1,this.words[b]|=w>>>26):_+=8}this._strip()};function v(h,o,l,d){for(var m=0,_=0,b=Math.min(h.length,l),w=o;w<b;w++){var f=h.charCodeAt(w)-48;m*=d,f>=49?_=f-49+10:f>=17?_=f-17+10:_=f,n(f>=0&&_<d,"Invalid character"),m+=_}return m}a.prototype._parseBase=function(o,l,d){this.words=[0],this.length=1;for(var m=0,_=1;_<=67108863;_*=l)m++;m--,_=_/l|0;for(var b=o.length-d,w=b%m,f=Math.min(b,b-w)+d,u=0,M=d;M<f;M+=m)u=v(o,M,M+m,l),this.imuln(_),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(w!==0){var q=1;for(u=v(o,M,o.length,l),M=0;M<w;M++)q*=l;this.imuln(q),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},a.prototype.copy=function(o){o.words=new Array(this.length);for(var l=0;l<this.length;l++)o.words[l]=this.words[l];o.length=this.length,o.negative=this.negative,o.red=this.red};function y(h,o){h.words=o.words,h.length=o.length,h.negative=o.negative,h.red=o.red}if(a.prototype._move=function(o){y(o,this)},a.prototype.clone=function(){var o=new a(null);return this.copy(o),o},a.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},a.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{a.prototype[Symbol.for("nodejs.util.inspect.custom")]=A}catch{a.prototype.inspect=A}else a.prototype.inspect=A;function A(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var k=["","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"],U=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],P=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];a.prototype.toString=function(o,l){o=o||10,l=l|0||1;var d;if(o===16||o==="hex"){d="";for(var m=0,_=0,b=0;b<this.length;b++){var w=this.words[b],f=((w<<m|_)&16777215).toString(16);_=w>>>24-m&16777215,m+=2,m>=26&&(m-=26,b--),_!==0||b!==this.length-1?d=k[6-f.length]+f+d:d=f+d}for(_!==0&&(d=_.toString(16)+d);d.length%l!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}if(o===(o|0)&&o>=2&&o<=36){var u=U[o],M=P[o];d="";var q=this.clone();for(q.negative=0;!q.isZero();){var $=q.modrn(M).toString(o);q=q.idivn(M),q.isZero()?d=$+d:d=k[u-$.length]+$+d}for(this.isZero()&&(d="0"+d);d.length%l!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}n(!1,"Base should be between 2 and 36")},a.prototype.toNumber=function(){var o=this.words[0];return this.length===2?o+=this.words[1]*67108864:this.length===3&&this.words[2]===1?o+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-o:o},a.prototype.toJSON=function(){return this.toString(16,2)},c&&(a.prototype.toBuffer=function(o,l){return this.toArrayLike(c,o,l)}),a.prototype.toArray=function(o,l){return this.toArrayLike(Array,o,l)};var W=function(o,l){return o.allocUnsafe?o.allocUnsafe(l):new o(l)};a.prototype.toArrayLike=function(o,l,d){this._strip();var m=this.byteLength(),_=d||Math.max(1,m);n(m<=_,"byte array longer than desired length"),n(_>0,"Requested array length <= 0");var b=W(o,_),w=l==="le"?"LE":"BE";return this["_toArrayLike"+w](b,m),b},a.prototype._toArrayLikeLE=function(o,l){for(var d=0,m=0,_=0,b=0;_<this.length;_++){var w=this.words[_]<<b|m;o[d++]=w&255,d<o.length&&(o[d++]=w>>8&255),d<o.length&&(o[d++]=w>>16&255),b===6?(d<o.length&&(o[d++]=w>>24&255),m=0,b=0):(m=w>>>24,b+=2)}if(d<o.length)for(o[d++]=m;d<o.length;)o[d++]=0},a.prototype._toArrayLikeBE=function(o,l){for(var d=o.length-1,m=0,_=0,b=0;_<this.length;_++){var w=this.words[_]<<b|m;o[d--]=w&255,d>=0&&(o[d--]=w>>8&255),d>=0&&(o[d--]=w>>16&255),b===6?(d>=0&&(o[d--]=w>>24&255),m=0,b=0):(m=w>>>24,b+=2)}if(d>=0)for(o[d--]=m;d>=0;)o[d--]=0},Math.clz32?a.prototype._countBits=function(o){return 32-Math.clz32(o)}:a.prototype._countBits=function(o){var l=o,d=0;return l>=4096&&(d+=13,l>>>=13),l>=64&&(d+=7,l>>>=7),l>=8&&(d+=4,l>>>=4),l>=2&&(d+=2,l>>>=2),d+l},a.prototype._zeroBits=function(o){if(o===0)return 26;var l=o,d=0;return(l&8191)===0&&(d+=13,l>>>=13),(l&127)===0&&(d+=7,l>>>=7),(l&15)===0&&(d+=4,l>>>=4),(l&3)===0&&(d+=2,l>>>=2),(l&1)===0&&d++,d},a.prototype.bitLength=function(){var o=this.words[this.length-1],l=this._countBits(o);return(this.length-1)*26+l};function j(h){for(var o=new Array(h.bitLength()),l=0;l<o.length;l++){var d=l/26|0,m=l%26;o[l]=h.words[d]>>>m&1}return o}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,l=0;l<this.length;l++){var d=this._zeroBits(this.words[l]);if(o+=d,d!==26)break}return o},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},a.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return this.negative!==0},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]|o.words[l];return this._strip()},a.prototype.ior=function(o){return n((this.negative|o.negative)===0),this.iuor(o)},a.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},a.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},a.prototype.iuand=function(o){var l;this.length>o.length?l=o:l=this;for(var d=0;d<l.length;d++)this.words[d]=this.words[d]&o.words[d];return this.length=l.length,this._strip()},a.prototype.iand=function(o){return n((this.negative|o.negative)===0),this.iuand(o)},a.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},a.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},a.prototype.iuxor=function(o){var l,d;this.length>o.length?(l=this,d=o):(l=o,d=this);for(var m=0;m<d.length;m++)this.words[m]=l.words[m]^d.words[m];if(this!==l)for(;m<l.length;m++)this.words[m]=l.words[m];return this.length=l.length,this._strip()},a.prototype.ixor=function(o){return n((this.negative|o.negative)===0),this.iuxor(o)},a.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},a.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},a.prototype.inotn=function(o){n(typeof o=="number"&&o>=0);var l=Math.ceil(o/26)|0,d=o%26;this._expand(l),d>0&&l--;for(var m=0;m<l;m++)this.words[m]=~this.words[m]&67108863;return d>0&&(this.words[m]=~this.words[m]&67108863>>26-d),this._strip()},a.prototype.notn=function(o){return this.clone().inotn(o)},a.prototype.setn=function(o,l){n(typeof o=="number"&&o>=0);var d=o/26|0,m=o%26;return this._expand(d+1),l?this.words[d]=this.words[d]|1<<m:this.words[d]=this.words[d]&~(1<<m),this._strip()},a.prototype.iadd=function(o){var l;if(this.negative!==0&&o.negative===0)return this.negative=0,l=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,l=this.isub(o),o.negative=1,l._normSign();var d,m;this.length>o.length?(d=this,m=o):(d=o,m=this);for(var _=0,b=0;b<m.length;b++)l=(d.words[b]|0)+(m.words[b]|0)+_,this.words[b]=l&67108863,_=l>>>26;for(;_!==0&&b<d.length;b++)l=(d.words[b]|0)+_,this.words[b]=l&67108863,_=l>>>26;if(this.length=d.length,_!==0)this.words[this.length]=_,this.length++;else if(d!==this)for(;b<d.length;b++)this.words[b]=d.words[b];return this},a.prototype.add=function(o){var l;return o.negative!==0&&this.negative===0?(o.negative=0,l=this.sub(o),o.negative^=1,l):o.negative===0&&this.negative!==0?(this.negative=0,l=o.sub(this),this.negative=1,l):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},a.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var l=this.iadd(o);return o.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var d=this.cmp(o);if(d===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,_;d>0?(m=this,_=o):(m=o,_=this);for(var b=0,w=0;w<_.length;w++)l=(m.words[w]|0)-(_.words[w]|0)+b,b=l>>26,this.words[w]=l&67108863;for(;b!==0&&w<m.length;w++)l=(m.words[w]|0)+b,b=l>>26,this.words[w]=l&67108863;if(b===0&&w<m.length&&m!==this)for(;w<m.length;w++)this.words[w]=m.words[w];return this.length=Math.max(this.length,w),m!==this&&(this.negative=1),this._strip()},a.prototype.sub=function(o){return this.clone().isub(o)};function K(h,o,l){l.negative=o.negative^h.negative;var d=h.length+o.length|0;l.length=d,d=d-1|0;var m=h.words[0]|0,_=o.words[0]|0,b=m*_,w=b&67108863,f=b/67108864|0;l.words[0]=w;for(var u=1;u<d;u++){for(var M=f>>>26,q=f&67108863,$=Math.min(u,o.length-1),z=Math.max(0,u-h.length+1);z<=$;z++){var ie=u-z|0;m=h.words[ie]|0,_=o.words[z]|0,b=m*_+q,M+=b/67108864|0,q=b&67108863}l.words[u]=q|0,f=M|0}return f!==0?l.words[u]=f|0:l.length--,l._strip()}var X=function(o,l,d){var m=o.words,_=l.words,b=d.words,w=0,f,u,M,q=m[0]|0,$=q&8191,z=q>>>13,ie=m[1]|0,C=ie&8191,T=ie>>>13,x=m[2]|0,F=x&8191,L=x>>>13,G=m[3]|0,B=G&8191,D=G>>>13,Z=m[4]|0,H=Z&8191,V=Z>>>13,ee=m[5]|0,te=ee&8191,ue=ee>>>13,Te=m[6]|0,he=Te&8191,_e=Te>>>13,ke=m[7]|0,ce=ke&8191,Ie=ke>>>13,st=m[8]|0,ge=st&8191,Be=st>>>13,rt=m[9]|0,me=rt&8191,Oe=rt>>>13,et=_[0]|0,fe=et&8191,Ge=et>>>13,ht=_[1]|0,ve=ht&8191,Ve=ht>>>13,ft=_[2]|0,we=ft&8191,Ze=ft>>>13,pt=_[3]|0,be=pt&8191,Ke=pt>>>13,mt=_[4]|0,ye=mt&8191,We=mt>>>13,gt=_[5]|0,Me=gt&8191,ze=gt>>>13,_t=_[6]|0,Ae=_t&8191,Xe=_t>>>13,vt=_[7]|0,Se=vt&8191,Je=vt>>>13,wt=_[8]|0,Ce=wt&8191,Ye=wt>>>13,bt=_[9]|0,Ee=bt&8191,He=bt>>>13;d.negative=o.negative^l.negative,d.length=19,f=Math.imul($,fe),u=Math.imul($,Ge),u=u+Math.imul(z,fe)|0,M=Math.imul(z,Ge);var Jt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,f=Math.imul(C,fe),u=Math.imul(C,Ge),u=u+Math.imul(T,fe)|0,M=Math.imul(T,Ge),f=f+Math.imul($,ve)|0,u=u+Math.imul($,Ve)|0,u=u+Math.imul(z,ve)|0,M=M+Math.imul(z,Ve)|0;var Yt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,f=Math.imul(F,fe),u=Math.imul(F,Ge),u=u+Math.imul(L,fe)|0,M=Math.imul(L,Ge),f=f+Math.imul(C,ve)|0,u=u+Math.imul(C,Ve)|0,u=u+Math.imul(T,ve)|0,M=M+Math.imul(T,Ve)|0,f=f+Math.imul($,we)|0,u=u+Math.imul($,Ze)|0,u=u+Math.imul(z,we)|0,M=M+Math.imul(z,Ze)|0;var Qt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,f=Math.imul(B,fe),u=Math.imul(B,Ge),u=u+Math.imul(D,fe)|0,M=Math.imul(D,Ge),f=f+Math.imul(F,ve)|0,u=u+Math.imul(F,Ve)|0,u=u+Math.imul(L,ve)|0,M=M+Math.imul(L,Ve)|0,f=f+Math.imul(C,we)|0,u=u+Math.imul(C,Ze)|0,u=u+Math.imul(T,we)|0,M=M+Math.imul(T,Ze)|0,f=f+Math.imul($,be)|0,u=u+Math.imul($,Ke)|0,u=u+Math.imul(z,be)|0,M=M+Math.imul(z,Ke)|0;var ei=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,f=Math.imul(H,fe),u=Math.imul(H,Ge),u=u+Math.imul(V,fe)|0,M=Math.imul(V,Ge),f=f+Math.imul(B,ve)|0,u=u+Math.imul(B,Ve)|0,u=u+Math.imul(D,ve)|0,M=M+Math.imul(D,Ve)|0,f=f+Math.imul(F,we)|0,u=u+Math.imul(F,Ze)|0,u=u+Math.imul(L,we)|0,M=M+Math.imul(L,Ze)|0,f=f+Math.imul(C,be)|0,u=u+Math.imul(C,Ke)|0,u=u+Math.imul(T,be)|0,M=M+Math.imul(T,Ke)|0,f=f+Math.imul($,ye)|0,u=u+Math.imul($,We)|0,u=u+Math.imul(z,ye)|0,M=M+Math.imul(z,We)|0;var ti=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,f=Math.imul(te,fe),u=Math.imul(te,Ge),u=u+Math.imul(ue,fe)|0,M=Math.imul(ue,Ge),f=f+Math.imul(H,ve)|0,u=u+Math.imul(H,Ve)|0,u=u+Math.imul(V,ve)|0,M=M+Math.imul(V,Ve)|0,f=f+Math.imul(B,we)|0,u=u+Math.imul(B,Ze)|0,u=u+Math.imul(D,we)|0,M=M+Math.imul(D,Ze)|0,f=f+Math.imul(F,be)|0,u=u+Math.imul(F,Ke)|0,u=u+Math.imul(L,be)|0,M=M+Math.imul(L,Ke)|0,f=f+Math.imul(C,ye)|0,u=u+Math.imul(C,We)|0,u=u+Math.imul(T,ye)|0,M=M+Math.imul(T,We)|0,f=f+Math.imul($,Me)|0,u=u+Math.imul($,ze)|0,u=u+Math.imul(z,Me)|0,M=M+Math.imul(z,ze)|0;var ii=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,f=Math.imul(he,fe),u=Math.imul(he,Ge),u=u+Math.imul(_e,fe)|0,M=Math.imul(_e,Ge),f=f+Math.imul(te,ve)|0,u=u+Math.imul(te,Ve)|0,u=u+Math.imul(ue,ve)|0,M=M+Math.imul(ue,Ve)|0,f=f+Math.imul(H,we)|0,u=u+Math.imul(H,Ze)|0,u=u+Math.imul(V,we)|0,M=M+Math.imul(V,Ze)|0,f=f+Math.imul(B,be)|0,u=u+Math.imul(B,Ke)|0,u=u+Math.imul(D,be)|0,M=M+Math.imul(D,Ke)|0,f=f+Math.imul(F,ye)|0,u=u+Math.imul(F,We)|0,u=u+Math.imul(L,ye)|0,M=M+Math.imul(L,We)|0,f=f+Math.imul(C,Me)|0,u=u+Math.imul(C,ze)|0,u=u+Math.imul(T,Me)|0,M=M+Math.imul(T,ze)|0,f=f+Math.imul($,Ae)|0,u=u+Math.imul($,Xe)|0,u=u+Math.imul(z,Ae)|0,M=M+Math.imul(z,Xe)|0;var ri=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,f=Math.imul(ce,fe),u=Math.imul(ce,Ge),u=u+Math.imul(Ie,fe)|0,M=Math.imul(Ie,Ge),f=f+Math.imul(he,ve)|0,u=u+Math.imul(he,Ve)|0,u=u+Math.imul(_e,ve)|0,M=M+Math.imul(_e,Ve)|0,f=f+Math.imul(te,we)|0,u=u+Math.imul(te,Ze)|0,u=u+Math.imul(ue,we)|0,M=M+Math.imul(ue,Ze)|0,f=f+Math.imul(H,be)|0,u=u+Math.imul(H,Ke)|0,u=u+Math.imul(V,be)|0,M=M+Math.imul(V,Ke)|0,f=f+Math.imul(B,ye)|0,u=u+Math.imul(B,We)|0,u=u+Math.imul(D,ye)|0,M=M+Math.imul(D,We)|0,f=f+Math.imul(F,Me)|0,u=u+Math.imul(F,ze)|0,u=u+Math.imul(L,Me)|0,M=M+Math.imul(L,ze)|0,f=f+Math.imul(C,Ae)|0,u=u+Math.imul(C,Xe)|0,u=u+Math.imul(T,Ae)|0,M=M+Math.imul(T,Xe)|0,f=f+Math.imul($,Se)|0,u=u+Math.imul($,Je)|0,u=u+Math.imul(z,Se)|0,M=M+Math.imul(z,Je)|0;var ni=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,f=Math.imul(ge,fe),u=Math.imul(ge,Ge),u=u+Math.imul(Be,fe)|0,M=Math.imul(Be,Ge),f=f+Math.imul(ce,ve)|0,u=u+Math.imul(ce,Ve)|0,u=u+Math.imul(Ie,ve)|0,M=M+Math.imul(Ie,Ve)|0,f=f+Math.imul(he,we)|0,u=u+Math.imul(he,Ze)|0,u=u+Math.imul(_e,we)|0,M=M+Math.imul(_e,Ze)|0,f=f+Math.imul(te,be)|0,u=u+Math.imul(te,Ke)|0,u=u+Math.imul(ue,be)|0,M=M+Math.imul(ue,Ke)|0,f=f+Math.imul(H,ye)|0,u=u+Math.imul(H,We)|0,u=u+Math.imul(V,ye)|0,M=M+Math.imul(V,We)|0,f=f+Math.imul(B,Me)|0,u=u+Math.imul(B,ze)|0,u=u+Math.imul(D,Me)|0,M=M+Math.imul(D,ze)|0,f=f+Math.imul(F,Ae)|0,u=u+Math.imul(F,Xe)|0,u=u+Math.imul(L,Ae)|0,M=M+Math.imul(L,Xe)|0,f=f+Math.imul(C,Se)|0,u=u+Math.imul(C,Je)|0,u=u+Math.imul(T,Se)|0,M=M+Math.imul(T,Je)|0,f=f+Math.imul($,Ce)|0,u=u+Math.imul($,Ye)|0,u=u+Math.imul(z,Ce)|0,M=M+Math.imul(z,Ye)|0;var oi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,f=Math.imul(me,fe),u=Math.imul(me,Ge),u=u+Math.imul(Oe,fe)|0,M=Math.imul(Oe,Ge),f=f+Math.imul(ge,ve)|0,u=u+Math.imul(ge,Ve)|0,u=u+Math.imul(Be,ve)|0,M=M+Math.imul(Be,Ve)|0,f=f+Math.imul(ce,we)|0,u=u+Math.imul(ce,Ze)|0,u=u+Math.imul(Ie,we)|0,M=M+Math.imul(Ie,Ze)|0,f=f+Math.imul(he,be)|0,u=u+Math.imul(he,Ke)|0,u=u+Math.imul(_e,be)|0,M=M+Math.imul(_e,Ke)|0,f=f+Math.imul(te,ye)|0,u=u+Math.imul(te,We)|0,u=u+Math.imul(ue,ye)|0,M=M+Math.imul(ue,We)|0,f=f+Math.imul(H,Me)|0,u=u+Math.imul(H,ze)|0,u=u+Math.imul(V,Me)|0,M=M+Math.imul(V,ze)|0,f=f+Math.imul(B,Ae)|0,u=u+Math.imul(B,Xe)|0,u=u+Math.imul(D,Ae)|0,M=M+Math.imul(D,Xe)|0,f=f+Math.imul(F,Se)|0,u=u+Math.imul(F,Je)|0,u=u+Math.imul(L,Se)|0,M=M+Math.imul(L,Je)|0,f=f+Math.imul(C,Ce)|0,u=u+Math.imul(C,Ye)|0,u=u+Math.imul(T,Ce)|0,M=M+Math.imul(T,Ye)|0,f=f+Math.imul($,Ee)|0,u=u+Math.imul($,He)|0,u=u+Math.imul(z,Ee)|0,M=M+Math.imul(z,He)|0;var si=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(si>>>26)|0,si&=67108863,f=Math.imul(me,ve),u=Math.imul(me,Ve),u=u+Math.imul(Oe,ve)|0,M=Math.imul(Oe,Ve),f=f+Math.imul(ge,we)|0,u=u+Math.imul(ge,Ze)|0,u=u+Math.imul(Be,we)|0,M=M+Math.imul(Be,Ze)|0,f=f+Math.imul(ce,be)|0,u=u+Math.imul(ce,Ke)|0,u=u+Math.imul(Ie,be)|0,M=M+Math.imul(Ie,Ke)|0,f=f+Math.imul(he,ye)|0,u=u+Math.imul(he,We)|0,u=u+Math.imul(_e,ye)|0,M=M+Math.imul(_e,We)|0,f=f+Math.imul(te,Me)|0,u=u+Math.imul(te,ze)|0,u=u+Math.imul(ue,Me)|0,M=M+Math.imul(ue,ze)|0,f=f+Math.imul(H,Ae)|0,u=u+Math.imul(H,Xe)|0,u=u+Math.imul(V,Ae)|0,M=M+Math.imul(V,Xe)|0,f=f+Math.imul(B,Se)|0,u=u+Math.imul(B,Je)|0,u=u+Math.imul(D,Se)|0,M=M+Math.imul(D,Je)|0,f=f+Math.imul(F,Ce)|0,u=u+Math.imul(F,Ye)|0,u=u+Math.imul(L,Ce)|0,M=M+Math.imul(L,Ye)|0,f=f+Math.imul(C,Ee)|0,u=u+Math.imul(C,He)|0,u=u+Math.imul(T,Ee)|0,M=M+Math.imul(T,He)|0;var ai=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,f=Math.imul(me,we),u=Math.imul(me,Ze),u=u+Math.imul(Oe,we)|0,M=Math.imul(Oe,Ze),f=f+Math.imul(ge,be)|0,u=u+Math.imul(ge,Ke)|0,u=u+Math.imul(Be,be)|0,M=M+Math.imul(Be,Ke)|0,f=f+Math.imul(ce,ye)|0,u=u+Math.imul(ce,We)|0,u=u+Math.imul(Ie,ye)|0,M=M+Math.imul(Ie,We)|0,f=f+Math.imul(he,Me)|0,u=u+Math.imul(he,ze)|0,u=u+Math.imul(_e,Me)|0,M=M+Math.imul(_e,ze)|0,f=f+Math.imul(te,Ae)|0,u=u+Math.imul(te,Xe)|0,u=u+Math.imul(ue,Ae)|0,M=M+Math.imul(ue,Xe)|0,f=f+Math.imul(H,Se)|0,u=u+Math.imul(H,Je)|0,u=u+Math.imul(V,Se)|0,M=M+Math.imul(V,Je)|0,f=f+Math.imul(B,Ce)|0,u=u+Math.imul(B,Ye)|0,u=u+Math.imul(D,Ce)|0,M=M+Math.imul(D,Ye)|0,f=f+Math.imul(F,Ee)|0,u=u+Math.imul(F,He)|0,u=u+Math.imul(L,Ee)|0,M=M+Math.imul(L,He)|0;var li=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(li>>>26)|0,li&=67108863,f=Math.imul(me,be),u=Math.imul(me,Ke),u=u+Math.imul(Oe,be)|0,M=Math.imul(Oe,Ke),f=f+Math.imul(ge,ye)|0,u=u+Math.imul(ge,We)|0,u=u+Math.imul(Be,ye)|0,M=M+Math.imul(Be,We)|0,f=f+Math.imul(ce,Me)|0,u=u+Math.imul(ce,ze)|0,u=u+Math.imul(Ie,Me)|0,M=M+Math.imul(Ie,ze)|0,f=f+Math.imul(he,Ae)|0,u=u+Math.imul(he,Xe)|0,u=u+Math.imul(_e,Ae)|0,M=M+Math.imul(_e,Xe)|0,f=f+Math.imul(te,Se)|0,u=u+Math.imul(te,Je)|0,u=u+Math.imul(ue,Se)|0,M=M+Math.imul(ue,Je)|0,f=f+Math.imul(H,Ce)|0,u=u+Math.imul(H,Ye)|0,u=u+Math.imul(V,Ce)|0,M=M+Math.imul(V,Ye)|0,f=f+Math.imul(B,Ee)|0,u=u+Math.imul(B,He)|0,u=u+Math.imul(D,Ee)|0,M=M+Math.imul(D,He)|0;var ui=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ui>>>26)|0,ui&=67108863,f=Math.imul(me,ye),u=Math.imul(me,We),u=u+Math.imul(Oe,ye)|0,M=Math.imul(Oe,We),f=f+Math.imul(ge,Me)|0,u=u+Math.imul(ge,ze)|0,u=u+Math.imul(Be,Me)|0,M=M+Math.imul(Be,ze)|0,f=f+Math.imul(ce,Ae)|0,u=u+Math.imul(ce,Xe)|0,u=u+Math.imul(Ie,Ae)|0,M=M+Math.imul(Ie,Xe)|0,f=f+Math.imul(he,Se)|0,u=u+Math.imul(he,Je)|0,u=u+Math.imul(_e,Se)|0,M=M+Math.imul(_e,Je)|0,f=f+Math.imul(te,Ce)|0,u=u+Math.imul(te,Ye)|0,u=u+Math.imul(ue,Ce)|0,M=M+Math.imul(ue,Ye)|0,f=f+Math.imul(H,Ee)|0,u=u+Math.imul(H,He)|0,u=u+Math.imul(V,Ee)|0,M=M+Math.imul(V,He)|0;var ci=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ci>>>26)|0,ci&=67108863,f=Math.imul(me,Me),u=Math.imul(me,ze),u=u+Math.imul(Oe,Me)|0,M=Math.imul(Oe,ze),f=f+Math.imul(ge,Ae)|0,u=u+Math.imul(ge,Xe)|0,u=u+Math.imul(Be,Ae)|0,M=M+Math.imul(Be,Xe)|0,f=f+Math.imul(ce,Se)|0,u=u+Math.imul(ce,Je)|0,u=u+Math.imul(Ie,Se)|0,M=M+Math.imul(Ie,Je)|0,f=f+Math.imul(he,Ce)|0,u=u+Math.imul(he,Ye)|0,u=u+Math.imul(_e,Ce)|0,M=M+Math.imul(_e,Ye)|0,f=f+Math.imul(te,Ee)|0,u=u+Math.imul(te,He)|0,u=u+Math.imul(ue,Ee)|0,M=M+Math.imul(ue,He)|0;var di=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(di>>>26)|0,di&=67108863,f=Math.imul(me,Ae),u=Math.imul(me,Xe),u=u+Math.imul(Oe,Ae)|0,M=Math.imul(Oe,Xe),f=f+Math.imul(ge,Se)|0,u=u+Math.imul(ge,Je)|0,u=u+Math.imul(Be,Se)|0,M=M+Math.imul(Be,Je)|0,f=f+Math.imul(ce,Ce)|0,u=u+Math.imul(ce,Ye)|0,u=u+Math.imul(Ie,Ce)|0,M=M+Math.imul(Ie,Ye)|0,f=f+Math.imul(he,Ee)|0,u=u+Math.imul(he,He)|0,u=u+Math.imul(_e,Ee)|0,M=M+Math.imul(_e,He)|0;var hi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(hi>>>26)|0,hi&=67108863,f=Math.imul(me,Se),u=Math.imul(me,Je),u=u+Math.imul(Oe,Se)|0,M=Math.imul(Oe,Je),f=f+Math.imul(ge,Ce)|0,u=u+Math.imul(ge,Ye)|0,u=u+Math.imul(Be,Ce)|0,M=M+Math.imul(Be,Ye)|0,f=f+Math.imul(ce,Ee)|0,u=u+Math.imul(ce,He)|0,u=u+Math.imul(Ie,Ee)|0,M=M+Math.imul(Ie,He)|0;var fi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(fi>>>26)|0,fi&=67108863,f=Math.imul(me,Ce),u=Math.imul(me,Ye),u=u+Math.imul(Oe,Ce)|0,M=Math.imul(Oe,Ye),f=f+Math.imul(ge,Ee)|0,u=u+Math.imul(ge,He)|0,u=u+Math.imul(Be,Ee)|0,M=M+Math.imul(Be,He)|0;var pi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(pi>>>26)|0,pi&=67108863,f=Math.imul(me,Ee),u=Math.imul(me,He),u=u+Math.imul(Oe,Ee)|0,M=Math.imul(Oe,He);var nr=(w+f|0)+((u&8191)<<13)|0;return w=(M+(u>>>13)|0)+(nr>>>26)|0,nr&=67108863,b[0]=Jt,b[1]=Yt,b[2]=Qt,b[3]=ei,b[4]=ti,b[5]=ii,b[6]=ri,b[7]=ni,b[8]=oi,b[9]=si,b[10]=ai,b[11]=li,b[12]=ui,b[13]=ci,b[14]=di,b[15]=hi,b[16]=fi,b[17]=pi,b[18]=nr,w!==0&&(b[19]=w,d.length++),d};Math.imul||(X=K);function Q(h,o,l){l.negative=o.negative^h.negative,l.length=h.length+o.length;for(var d=0,m=0,_=0;_<l.length-1;_++){var b=m;m=0;for(var w=d&67108863,f=Math.min(_,o.length-1),u=Math.max(0,_-h.length+1);u<=f;u++){var M=_-u,q=h.words[M]|0,$=o.words[u]|0,z=q*$,ie=z&67108863;b=b+(z/67108864|0)|0,ie=ie+w|0,w=ie&67108863,b=b+(ie>>>26)|0,m+=b>>>26,b&=67108863}l.words[_]=w,d=b,b=m}return d!==0?l.words[_]=d:l.length--,l._strip()}function se(h,o,l){return Q(h,o,l)}a.prototype.mulTo=function(o,l){var d,m=this.length+o.length;return this.length===10&&o.length===10?d=X(this,o,l):m<63?d=K(this,o,l):m<1024?d=Q(this,o,l):d=se(this,o,l),d},a.prototype.mul=function(o){var l=new a(null);return l.words=new Array(this.length+o.length),this.mulTo(o,l)},a.prototype.mulf=function(o){var l=new a(null);return l.words=new Array(this.length+o.length),se(this,o,l)},a.prototype.imul=function(o){return this.clone().mulTo(o,this)},a.prototype.imuln=function(o){var l=o<0;l&&(o=-o),n(typeof o=="number"),n(o<67108864);for(var d=0,m=0;m<this.length;m++){var _=(this.words[m]|0)*o,b=(_&67108863)+(d&67108863);d>>=26,d+=_/67108864|0,d+=b>>>26,this.words[m]=b&67108863}return d!==0&&(this.words[m]=d,this.length++),l?this.ineg():this},a.prototype.muln=function(o){return this.clone().imuln(o)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(o){var l=j(o);if(l.length===0)return new a(1);for(var d=this,m=0;m<l.length&&l[m]===0;m++,d=d.sqr());if(++m<l.length)for(var _=d.sqr();m<l.length;m++,_=_.sqr())l[m]!==0&&(d=d.mul(_));return d},a.prototype.iushln=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26,m=67108863>>>26-l<<26-l,_;if(l!==0){var b=0;for(_=0;_<this.length;_++){var w=this.words[_]&m,f=(this.words[_]|0)-w<<l;this.words[_]=f|b,b=w>>>26-l}b&&(this.words[_]=b,this.length++)}if(d!==0){for(_=this.length-1;_>=0;_--)this.words[_+d]=this.words[_];for(_=0;_<d;_++)this.words[_]=0;this.length+=d}return this._strip()},a.prototype.ishln=function(o){return n(this.negative===0),this.iushln(o)},a.prototype.iushrn=function(o,l,d){n(typeof o=="number"&&o>=0);var m;l?m=(l-l%26)/26:m=0;var _=o%26,b=Math.min((o-_)/26,this.length),w=67108863^67108863>>>_<<_,f=d;if(m-=b,m=Math.max(0,m),f){for(var u=0;u<b;u++)f.words[u]=this.words[u];f.length=b}if(b!==0)if(this.length>b)for(this.length-=b,u=0;u<this.length;u++)this.words[u]=this.words[u+b];else this.words[0]=0,this.length=1;var M=0;for(u=this.length-1;u>=0&&(M!==0||u>=m);u--){var q=this.words[u]|0;this.words[u]=M<<26-_|q>>>_,M=q&w}return f&&M!==0&&(f.words[f.length++]=M),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},a.prototype.ishrn=function(o,l,d){return n(this.negative===0),this.iushrn(o,l,d)},a.prototype.shln=function(o){return this.clone().ishln(o)},a.prototype.ushln=function(o){return this.clone().iushln(o)},a.prototype.shrn=function(o){return this.clone().ishrn(o)},a.prototype.ushrn=function(o){return this.clone().iushrn(o)},a.prototype.testn=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26,m=1<<l;if(this.length<=d)return!1;var _=this.words[d];return!!(_&m)},a.prototype.imaskn=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=d)return this;if(l!==0&&d++,this.length=Math.min(d,this.length),l!==0){var m=67108863^67108863>>>l<<l;this.words[this.length-1]&=m}return this._strip()},a.prototype.maskn=function(o){return this.clone().imaskn(o)},a.prototype.iaddn=function(o){return n(typeof o=="number"),n(o<67108864),o<0?this.isubn(-o):this.negative!==0?this.length===1&&(this.words[0]|0)<=o?(this.words[0]=o-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(o),this.negative=1,this):this._iaddn(o)},a.prototype._iaddn=function(o){this.words[0]+=o;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},a.prototype.isubn=function(o){if(n(typeof o=="number"),n(o<67108864),o<0)return this.iaddn(-o);if(this.negative!==0)return this.negative=0,this.iaddn(o),this.negative=1,this;if(this.words[0]-=o,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},a.prototype.addn=function(o){return this.clone().iaddn(o)},a.prototype.subn=function(o){return this.clone().isubn(o)},a.prototype.iabs=function(){return this.negative=0,this},a.prototype.abs=function(){return this.clone().iabs()},a.prototype._ishlnsubmul=function(o,l,d){var m=o.length+d,_;this._expand(m);var b,w=0;for(_=0;_<o.length;_++){b=(this.words[_+d]|0)+w;var f=(o.words[_]|0)*l;b-=f&67108863,w=(b>>26)-(f/67108864|0),this.words[_+d]=b&67108863}for(;_<this.length-d;_++)b=(this.words[_+d]|0)+w,w=b>>26,this.words[_+d]=b&67108863;if(w===0)return this._strip();for(n(w===-1),w=0,_=0;_<this.length;_++)b=-(this.words[_]|0)+w,w=b>>26,this.words[_]=b&67108863;return this.negative=1,this._strip()},a.prototype._wordDiv=function(o,l){var d=this.length-o.length,m=this.clone(),_=o,b=_.words[_.length-1]|0,w=this._countBits(b);d=26-w,d!==0&&(_=_.ushln(d),m.iushln(d),b=_.words[_.length-1]|0);var f=m.length-_.length,u;if(l!=="mod"){u=new a(null),u.length=f+1,u.words=new Array(u.length);for(var M=0;M<u.length;M++)u.words[M]=0}var q=m.clone()._ishlnsubmul(_,1,f);q.negative===0&&(m=q,u&&(u.words[f]=1));for(var $=f-1;$>=0;$--){var z=(m.words[_.length+$]|0)*67108864+(m.words[_.length+$-1]|0);for(z=Math.min(z/b|0,67108863),m._ishlnsubmul(_,z,$);m.negative!==0;)z--,m.negative=0,m._ishlnsubmul(_,1,$),m.isZero()||(m.negative^=1);u&&(u.words[$]=z)}return u&&u._strip(),m._strip(),l!=="div"&&d!==0&&m.iushrn(d),{div:u||null,mod:m}},a.prototype.divmod=function(o,l,d){if(n(!o.isZero()),this.isZero())return{div:new a(0),mod:new a(0)};var m,_,b;return this.negative!==0&&o.negative===0?(b=this.neg().divmod(o,l),l!=="mod"&&(m=b.div.neg()),l!=="div"&&(_=b.mod.neg(),d&&_.negative!==0&&_.iadd(o)),{div:m,mod:_}):this.negative===0&&o.negative!==0?(b=this.divmod(o.neg(),l),l!=="mod"&&(m=b.div.neg()),{div:m,mod:b.mod}):(this.negative&o.negative)!==0?(b=this.neg().divmod(o.neg(),l),l!=="div"&&(_=b.mod.neg(),d&&_.negative!==0&&_.isub(o)),{div:b.div,mod:_}):o.length>this.length||this.cmp(o)<0?{div:new a(0),mod:this}:o.length===1?l==="div"?{div:this.divn(o.words[0]),mod:null}:l==="mod"?{div:null,mod:new a(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new a(this.modrn(o.words[0]))}:this._wordDiv(o,l)},a.prototype.div=function(o){return this.divmod(o,"div",!1).div},a.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},a.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},a.prototype.divRound=function(o){var l=this.divmod(o);if(l.mod.isZero())return l.div;var d=l.div.negative!==0?l.mod.isub(o):l.mod,m=o.ushrn(1),_=o.andln(1),b=d.cmp(m);return b<0||_===1&&b===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},a.prototype.modrn=function(o){var l=o<0;l&&(o=-o),n(o<=67108863);for(var d=(1<<26)%o,m=0,_=this.length-1;_>=0;_--)m=(d*m+(this.words[_]|0))%o;return l?-m:m},a.prototype.modn=function(o){return this.modrn(o)},a.prototype.idivn=function(o){var l=o<0;l&&(o=-o),n(o<=67108863);for(var d=0,m=this.length-1;m>=0;m--){var _=(this.words[m]|0)+d*67108864;this.words[m]=_/o|0,d=_%o}return this._strip(),l?this.ineg():this},a.prototype.divn=function(o){return this.clone().idivn(o)},a.prototype.egcd=function(o){n(o.negative===0),n(!o.isZero());var l=this,d=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new a(1),_=new a(0),b=new a(0),w=new a(1),f=0;l.isEven()&&d.isEven();)l.iushrn(1),d.iushrn(1),++f;for(var u=d.clone(),M=l.clone();!l.isZero();){for(var q=0,$=1;(l.words[0]&$)===0&&q<26;++q,$<<=1);if(q>0)for(l.iushrn(q);q-- >0;)(m.isOdd()||_.isOdd())&&(m.iadd(u),_.isub(M)),m.iushrn(1),_.iushrn(1);for(var z=0,ie=1;(d.words[0]&ie)===0&&z<26;++z,ie<<=1);if(z>0)for(d.iushrn(z);z-- >0;)(b.isOdd()||w.isOdd())&&(b.iadd(u),w.isub(M)),b.iushrn(1),w.iushrn(1);l.cmp(d)>=0?(l.isub(d),m.isub(b),_.isub(w)):(d.isub(l),b.isub(m),w.isub(_))}return{a:b,b:w,gcd:d.iushln(f)}},a.prototype._invmp=function(o){n(o.negative===0),n(!o.isZero());var l=this,d=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new a(1),_=new a(0),b=d.clone();l.cmpn(1)>0&&d.cmpn(1)>0;){for(var w=0,f=1;(l.words[0]&f)===0&&w<26;++w,f<<=1);if(w>0)for(l.iushrn(w);w-- >0;)m.isOdd()&&m.iadd(b),m.iushrn(1);for(var u=0,M=1;(d.words[0]&M)===0&&u<26;++u,M<<=1);if(u>0)for(d.iushrn(u);u-- >0;)_.isOdd()&&_.iadd(b),_.iushrn(1);l.cmp(d)>=0?(l.isub(d),m.isub(_)):(d.isub(l),_.isub(m))}var q;return l.cmpn(1)===0?q=m:q=_,q.cmpn(0)<0&&q.iadd(o),q},a.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var l=this.clone(),d=o.clone();l.negative=0,d.negative=0;for(var m=0;l.isEven()&&d.isEven();m++)l.iushrn(1),d.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;d.isEven();)d.iushrn(1);var _=l.cmp(d);if(_<0){var b=l;l=d,d=b}else if(_===0||d.cmpn(1)===0)break;l.isub(d)}while(!0);return d.iushln(m)},a.prototype.invm=function(o){return this.egcd(o).a.umod(o)},a.prototype.isEven=function(){return(this.words[0]&1)===0},a.prototype.isOdd=function(){return(this.words[0]&1)===1},a.prototype.andln=function(o){return this.words[0]&o},a.prototype.bincn=function(o){n(typeof o=="number");var l=o%26,d=(o-l)/26,m=1<<l;if(this.length<=d)return this._expand(d+1),this.words[d]|=m,this;for(var _=m,b=d;_!==0&&b<this.length;b++){var w=this.words[b]|0;w+=_,_=w>>>26,w&=67108863,this.words[b]=w}return _!==0&&(this.words[b]=_,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(o){var l=o<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var d;if(this.length>1)d=1;else{l&&(o=-o),n(o<=67108863,"Number is too big");var m=this.words[0]|0;d=m===o?0:m<o?-1:1}return this.negative!==0?-d|0:d},a.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var l=this.ucmp(o);return this.negative!==0?-l|0:l},a.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var l=0,d=this.length-1;d>=0;d--){var m=this.words[d]|0,_=o.words[d]|0;if(m!==_){m<_?l=-1:m>_&&(l=1);break}}return l},a.prototype.gtn=function(o){return this.cmpn(o)===1},a.prototype.gt=function(o){return this.cmp(o)===1},a.prototype.gten=function(o){return this.cmpn(o)>=0},a.prototype.gte=function(o){return this.cmp(o)>=0},a.prototype.ltn=function(o){return this.cmpn(o)===-1},a.prototype.lt=function(o){return this.cmp(o)===-1},a.prototype.lten=function(o){return this.cmpn(o)<=0},a.prototype.lte=function(o){return this.cmp(o)<=0},a.prototype.eqn=function(o){return this.cmpn(o)===0},a.prototype.eq=function(o){return this.cmp(o)===0},a.red=function(o){return new N(o)},a.prototype.toRed=function(o){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),o.convertTo(this)._forceRed(o)},a.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(o){return this.red=o,this},a.prototype.forceRed=function(o){return n(!this.red,"Already a number in reduction context"),this._forceRed(o)},a.prototype.redAdd=function(o){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},a.prototype.redIAdd=function(o){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},a.prototype.redSub=function(o){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},a.prototype.redISub=function(o){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},a.prototype.redShl=function(o){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},a.prototype.redMul=function(o){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},a.prototype.redIMul=function(o){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},a.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(o){return n(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var Y={k256:null,p224:null,p192:null,p25519:null};function le(h,o){this.name=h,this.p=new a(o,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}le.prototype._tmp=function(){var o=new a(null);return o.words=new Array(Math.ceil(this.n/13)),o},le.prototype.ireduce=function(o){var l=o,d;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),d=l.bitLength();while(d>this.n);var m=d<this.n?-1:l.ucmp(this.p);return m===0?(l.words[0]=0,l.length=1):m>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},le.prototype.split=function(o,l){o.iushrn(this.n,0,l)},le.prototype.imulK=function(o){return o.imul(this.k)};function E(){le.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(E,le),E.prototype.split=function(o,l){for(var d=4194303,m=Math.min(o.length,9),_=0;_<m;_++)l.words[_]=o.words[_];if(l.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var b=o.words[9];for(l.words[l.length++]=b&d,_=10;_<o.length;_++){var w=o.words[_]|0;o.words[_-10]=(w&d)<<4|b>>>22,b=w}b>>>=22,o.words[_-10]=b,b===0&&o.length>10?o.length-=10:o.length-=9},E.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var l=0,d=0;d<o.length;d++){var m=o.words[d]|0;l+=m*977,o.words[d]=l&67108863,l=m*64+(l/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function I(){le.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(I,le);function O(){le.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(O,le);function R(){le.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(R,le),R.prototype.imulK=function(o){for(var l=0,d=0;d<o.length;d++){var m=(o.words[d]|0)*19+l,_=m&67108863;m>>>=26,o.words[d]=_,l=m}return l!==0&&(o.words[o.length++]=l),o},a._prime=function(o){if(Y[o])return Y[o];var l;if(o==="k256")l=new E;else if(o==="p224")l=new I;else if(o==="p192")l=new O;else if(o==="p25519")l=new R;else throw new Error("Unknown prime "+o);return Y[o]=l,l};function N(h){if(typeof h=="string"){var o=a._prime(h);this.m=o.p,this.prime=o}else n(h.gtn(1),"modulus must be greater than 1"),this.m=h,this.prime=null}N.prototype._verify1=function(o){n(o.negative===0,"red works only with positives"),n(o.red,"red works only with red numbers")},N.prototype._verify2=function(o,l){n((o.negative|l.negative)===0,"red works only with positives"),n(o.red&&o.red===l.red,"red works only with red numbers")},N.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(y(o,o.umod(this.m)._forceRed(this)),o)},N.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},N.prototype.add=function(o,l){this._verify2(o,l);var d=o.add(l);return d.cmp(this.m)>=0&&d.isub(this.m),d._forceRed(this)},N.prototype.iadd=function(o,l){this._verify2(o,l);var d=o.iadd(l);return d.cmp(this.m)>=0&&d.isub(this.m),d},N.prototype.sub=function(o,l){this._verify2(o,l);var d=o.sub(l);return d.cmpn(0)<0&&d.iadd(this.m),d._forceRed(this)},N.prototype.isub=function(o,l){this._verify2(o,l);var d=o.isub(l);return d.cmpn(0)<0&&d.iadd(this.m),d},N.prototype.shl=function(o,l){return this._verify1(o),this.imod(o.ushln(l))},N.prototype.imul=function(o,l){return this._verify2(o,l),this.imod(o.imul(l))},N.prototype.mul=function(o,l){return this._verify2(o,l),this.imod(o.mul(l))},N.prototype.isqr=function(o){return this.imul(o,o.clone())},N.prototype.sqr=function(o){return this.mul(o,o)},N.prototype.sqrt=function(o){if(o.isZero())return o.clone();var l=this.m.andln(3);if(n(l%2===1),l===3){var d=this.m.add(new a(1)).iushrn(2);return this.pow(o,d)}for(var m=this.m.subn(1),_=0;!m.isZero()&&m.andln(1)===0;)_++,m.iushrn(1);n(!m.isZero());var b=new a(1).toRed(this),w=b.redNeg(),f=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new a(2*u*u).toRed(this);this.pow(u,f).cmp(w)!==0;)u.redIAdd(w);for(var M=this.pow(u,m),q=this.pow(o,m.addn(1).iushrn(1)),$=this.pow(o,m),z=_;$.cmp(b)!==0;){for(var ie=$,C=0;ie.cmp(b)!==0;C++)ie=ie.redSqr();n(C<z);var T=this.pow(M,new a(1).iushln(z-C-1));q=q.redMul(T),M=T.redSqr(),$=$.redMul(M),z=C}return q},N.prototype.invm=function(o){var l=o._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},N.prototype.pow=function(o,l){if(l.isZero())return new a(1).toRed(this);if(l.cmpn(1)===0)return o.clone();var d=4,m=new Array(1<<d);m[0]=new a(1).toRed(this),m[1]=o;for(var _=2;_<m.length;_++)m[_]=this.mul(m[_-1],o);var b=m[0],w=0,f=0,u=l.bitLength()%26;for(u===0&&(u=26),_=l.length-1;_>=0;_--){for(var M=l.words[_],q=u-1;q>=0;q--){var $=M>>q&1;if(b!==m[0]&&(b=this.sqr(b)),$===0&&w===0){f=0;continue}w<<=1,w|=$,f++,!(f!==d&&(_!==0||q!==0))&&(b=this.mul(b,m[w]),f=0,w=0)}u=26}return b},N.prototype.convertTo=function(o){var l=o.umod(this.m);return l===o?l.clone():l},N.prototype.convertFrom=function(o){var l=o.clone();return l.red=null,l},a.mont=function(o){return new S(o)};function S(h){N.call(this,h),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(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(S,N),S.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},S.prototype.convertFrom=function(o){var l=this.imod(o.mul(this.rinv));return l.red=null,l},S.prototype.imul=function(o,l){if(o.isZero()||l.isZero())return o.words[0]=0,o.length=1,o;var d=o.imul(l),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=d.isub(m).iushrn(this.shift),b=_;return _.cmp(this.m)>=0?b=_.isub(this.m):_.cmpn(0)<0&&(b=_.iadd(this.m)),b._forceRed(this)},S.prototype.mul=function(o,l){if(o.isZero()||l.isZero())return new a(0)._forceRed(this);var d=o.mul(l),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=d.isub(m).iushrn(this.shift),b=_;return _.cmp(this.m)>=0?b=_.isub(this.m):_.cmpn(0)<0&&(b=_.iadd(this.m)),b._forceRed(this)},S.prototype.invm=function(o){var l=this.imod(o._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof t>"u"||t,e)}}),St=vr(wr()),pr=vr(wr()),Sa=(e=>(e.InvalidType="InvalidType",e))(Sa||{}),Ca=(e=>(e.MissAggregatorPackage="MissAggregatorPackage",e.MissGlobalConfig="MissGlobalConfig",e.InvalidWallet="InvalidWallet",e.SimulateError="SimulateError",e))(Ca||{}),Ea=(e=>(e.InsufficientBalance="InsufficientBalance",e.SimulateEventError="simulateEventError",e.CannotGetDecimals="CannotGetDecimals",e.MissCoinA="MissCoinA",e.MissCoinB="MissCoinB",e.MissTurbosFeeType="MissTurbosFeeType",e.MissAftermathLpSupplyType="MissAftermathLpSupplyType",e))(Ea||{}),Ia=(e=>(e[e.NumberTooLarge=1e3]="NumberTooLarge",e[e.RateLimitExceeded=1001]="RateLimitExceeded",e[e.InsufficientLiquidity=1002]="InsufficientLiquidity",e[e.HoneyPot=1003]="HoneyPot",e))(Ia||{});function hn(e){switch(e){case 1e3:return"Number too large";case 1001:return"Rate limit exceeded";case 1002:return"Insufficient liquidity";case 1003:return"HoneyPot scam detected";default:return"Unknown error"}}var S0=class ka extends Error{constructor(t,i){super(t),this.message=t,this.errorCode=i}static isAggregatorErrorCode(t,i){return t instanceof ka&&t.errorCode===i}},C0=0,Ta=1,E0=2;function ca(e,t){return e===t?C0:e<t?Ta:E0}function I0(e,t){let i=0,r=e.length<=t.length?e.length:t.length,n=ca(e.length,t.length);for(;i<r;){let s=ca(e.charCodeAt(i),t.charCodeAt(i));if(i+=1,s!==0)return s}return n}function k0(e,t){return I0(e,t)===Ta}function wo(e,...t){let i=Array.isArray(t[t.length-1])?t.pop():[],n=[e,...t].filter(Boolean).join("::");return i&&i.length&&(n+=`<${i.join(", ")}>`),n}function T0(e){return e.split("::")[0]}function gr(e){var t;try{let i=e.replace(/\s/g,""),r=i.match(/(<.+>)$/),n=(t=r?.[0])==null?void 0:t.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(n){i=i.slice(0,i.indexOf("<"));let p=gr(i),g=pn(xr({},p),{type_arguments:n.map(v=>gr(v).source_address)});return g.type_arguments=g.type_arguments.map(v=>_i.isSuiCoin(v)?v:gr(v).source_address),g.source_address=wo(g.full_address,g.type_arguments),g}let s=i.split("::"),c={full_address:i,address:i===ko||i===xa?"0x2":yt.normalizeSuiObjectId(s[0]),module:s[1],name:s[2],type_arguments:[],source_address:""};return c.full_address=`${c.address}::${c.module}::${c.name}`,c.source_address=wo(c.full_address,c.type_arguments),c}catch{return{full_address:e,address:"",module:"",name:"",type_arguments:[],source_address:e}}}function bo(e){return gr(e).source_address}function Oa(e){return e.toLowerCase().startsWith("0x")?yt.normalizeSuiObjectId(e):e}function Pa(e){for(let t in e){let i=typeof e[t];if(i==="object")Pa(e[t]);else if(i==="string"){let r=e[t];e[t]=Oa(r)}}}function O0(e,t,i){return`${e}::${t}::${i}`}var P0="0x2::coin::Coin",x0=/^0x2::coin::Coin<(.+)>$/,N0=1e3,R0=500,L0=100,F0=100,D0=1e3,ko="0x2::sui::SUI",xa="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",B0="SUI",U0=450,j0="0x0000000000000000000000000000000000000005",_i=class Wi{static getCoinTypeArg(t){let i=t.type.match(x0);return i?i[1]:null}static isSUI(t){let i=Wi.getCoinTypeArg(t);return i?Wi.getCoinSymbol(i)==="SUI":!1}static getCoinSymbol(t){return t.substring(t.lastIndexOf(":")+1)}static getBalance(t){return BigInt(t.fields.balance)}static totalBalance(t,i){let r=BigInt(0);return t.forEach(n=>{i===n.coinAddress&&(r+=BigInt(n.balance))}),r}static getID(t){return t.fields.id.id}static getCoinTypeFromArg(t){return`${P0}<${t}>`}static getCoinAssets(t,i){let r=[];return i.forEach(n=>{bo(n.coinAddress)===bo(t)&&r.push(n)}),r}static isSuiCoin(t){return gr(t).full_address===ko}static selectCoinObjectIdGreaterThanOrEqual(t,i,r=[]){let n=Wi.selectCoinAssetGreaterThanOrEqual(t,i,r),s=n.selectedCoins.map(p=>p.coinObjectId),a=n.remainingCoins,c=n.selectedCoins.map(p=>p.balance.toString());return{objectArray:s,remainCoins:a,amountArray:c}}static selectCoinAssetGreaterThanOrEqual(t,i,r=[]){let n=Wi.sortByBalance(t.filter(g=>!r.includes(g.coinObjectId))),s=Wi.calculateTotalBalance(n);if(s<i)return{selectedCoins:[],remainingCoins:n};if(s===i)return{selectedCoins:n,remainingCoins:[]};let a=BigInt(0),c=[],p=[...n];for(;a<s;){let g=i-a,v=p.findIndex(A=>A.balance>=g);if(v!==-1){c.push(p[v]),p.splice(v,1);break}let y=p.pop();y.balance>0&&(c.push(y),a+=y.balance)}return{selectedCoins:Wi.sortByBalance(c),remainingCoins:Wi.sortByBalance(p)}}static sortByBalance(t){return t.sort((i,r)=>i.balance<r.balance?-1:i.balance>r.balance?1:0)}static sortByBalanceDes(t){return t.sort((i,r)=>i.balance>r.balance?-1:i.balance<r.balance?0:1)}static calculateTotalBalance(t){return t.reduce((i,r)=>i+r.balance,BigInt(0))}};function Bi(e){let t=e.indexOf("::");if(t===-1)return e;let i=e.substring(0,t),r=e.substring(t);if(!i.startsWith("0x"))return e;let n=i.substring(2);return n.length>64?e:`0x${n.padStart(64,"0")}${r}`}function Na(e,t){return e.moveCall({target:"0x2::coin::zero",typeArguments:[t],arguments:[]})}function Ra(e,t){e=Bi(e),t=Bi(t);let i=Math.min(e.length,t.length);for(let r=0;r<i;r++){if(e[r]>t[r])return!0;if(e[r]<t[r])return!1}return!0}function q0(e){let t=/,([^,>]*>)/g,i=[...e.matchAll(t)];if(i.length>0){let r=i[i.length-1][1];return r.substring(0,r.length-1).trim()}return null}function $0(e){let t=/<([^>]*)>/,i=e.match(t);if(i)return i[1]}function H0(e,t,i,r){let n=_i.getCoinAssets(r,t);if(i===BigInt(0))return _i.isSuiCoin(r)||n.length===0&&!_i.isSuiCoin(r)?{targetCoin:Na(e,r),isMintZeroCoin:!0,targetCoinAmount:0}:{targetCoin:e.object(n[0].coinObjectId),isMintZeroCoin:!1,targetCoinAmount:Number(n[0].balance.toString())};if(_i.calculateTotalBalance(n)<i)throw new AggregateError("Insufficient balance when build merge coin, coinType: "+r,"InsufficientBalance"+r);if(_i.isSuiCoin(r))return{targetCoin:e.splitCoins(e.gas,[e.pure.u64(i.toString())]),isMintZeroCoin:!0,targetCoinAmount:Number(i.toString())};let a=_i.sortByBalance(n);a.slice(0,3).reduce((A,k)=>A+k.balance,BigInt(0))<BigInt(i)&&(a=_i.sortByBalanceDes(n));let p=_i.selectCoinObjectIdGreaterThanOrEqual(a,i),[g,...v]=p.objectArray;return v.length>0&&e.mergeCoins(g,v.map(A=>e.object(A))),{targetCoin:e.splitCoins(e.object(g),[e.pure.u64(i.toString())]),isMintZeroCoin:!1,targetCoinAmount:Number(i.toString())}}var Fr=vr(wr()),sr=new Fr.default(0),G0=new Fr.default(1),La=new Fr.default(2),V0=La.pow(new Fr.default(128)),Z0=new Fr.default("18446744073709551615"),mn="18446744073709551615",K0=1e9,W0="aggregator",z0="CETUS",X0="DEEPBOOK",J0="KRIYA",Y0="FLOWX",Q0="TURBOS",ec="AFTERMATH",tc="integrate",ic="cetus",rc="deepbook",nc="kriya",oc="utils",sc="pool",ac="pay",lc="flowx_amm",uc="turbos",cc="aftermath",Fa="custodian_v2",Da="clob_v2",dc="flash_swap",hc="flash_swap_with_partner",fc="repay_flash_swap",pc="repay_flash_swap_with_partner",mc="flash_swap_a2b",gc="flash_swap_b2a",_c="flash_swap_with_partner_a2b",vc="flash_swap_with_partner_b2a",wc="repay_flash_swap_a2b",bc="repay_flash_swap_b2a",yc="repay_flash_swap_with_partner_a2b",Mc="repay_flash_swap_with_partner_b2a",Ac="swap_a2b",Sc="swap_b2a",Cc="transfer_or_destroy_coin",Ec="check_coins_threshold",Ic="join_vec",kc="transfer_account_cap",Tc="0x0000000000000000000000000000000000000000000000000000000000000006",Oc="0x1::coin::CoinInfo",Pc="0x1::coin::CoinStore",xc="0x2::coin::zero",Ba="0x000000000000000000000000000000000000000000000000000000000000dee9",Ua="0x000000000000000000000000000000000000000000000000000000000000dee9",Nc="0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a",ja="0x550dcd6070230d8bf18d99d34e3b2ca1d3657b76cc80ffdacdb2b5d28d7e0124",Rc="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",Lc="0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a",Fc="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511",Dc="",Bc="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f",Uc="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",jc="",qc="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",$c="",Hc="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",Gc="",Vc="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",Zc="",Kc="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278",Wc="",Nr={AGGREGATOR_V3:"aggregator_v3"},zc="https://api-sui.cetus.zone/router_v3",Xc="https://api-sui.cetus.zone/router_v2",Jc={Testnet:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},Mainnet:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}},yn={V2:{Mainnet:"0x8ae871505a80d8bf6bf9c05906cda6edfeea460c85bebe2e26a4313f5e67874a",Testnet:"0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"},V2_EXTEND:{Mainnet:"0x8a2f7a5b20665eeccc79de3aa37c3b6c473eca233ada1e1cd4678ec07d4d4073",Testnet:"0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"},V2_EXTEND2:{Mainnet:"0x5cb7499fc49c2642310e24a4ecffdbee00133f97e80e2b45bca90c64d55de880",Testnet:"0x0"}},Rr={Mainnet:"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",Testnet:"0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"},Fi={DEFAULT_PYTH_URL:"https://hermes.pyth.network",PYTH_TIMEOUT:3e3,MAX_OVERLAY_FEE_RATE:.1,FEE_RATE_MULTIPLIER:1e6,DEFAULT_OVERLAY_FEE_RECEIVER:"0x0",ERRORS:{SIGNER_REQUIRED:"Signer is required, but not provided.",INVALID_OVERLAY_FEE_RATE:"Overlay fee rate must be between 0 and 0.1",INVALID_SLIPPAGE:"Invalid slippage value. Must be between 0 and 1 (e.g., 0.01 represents 1% slippage)",NO_ROUTER_FOUND:"No router found",EMPTY_PATH:"Empty path",UNSUPPORTED_DEX:"Unsupported dex",PYTH_UNAVAILABLE:"All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes",QUOTE_ID_REQUIRED:"Quote ID is required",AGGREGATOR_V3_PACKAGE_REQUIRED:"Aggregator V3 package is required",PACKAGES_REQUIRED:"Packages are required"}},ot={FEE_DENOMINATOR:1e6,MAX_FEE_RATE:1e5,MAX_AMOUNT_IN:mn,DEFAULT_PUBLISHED_AT:{Mainnet:"0x07c27e879ba9282506284b0fef26d393978906fc9496550d978c6f493dbfa3e5",Testnet:"0x0"}},qa=1010102;function Yc(e,t){let i=new Map;return e.packages&&(e.packages instanceof Map?i=e.packages:typeof e.packages=="object"&&Object.entries(e.packages).forEach(([r,n])=>{i.set(r,n)})),{quoteID:e.request_id||"",amountIn:new pr.default(e.amount_in.toString()),amountOut:new pr.default(e.amount_out.toString()),byAmountIn:t,insufficientLiquidity:!1,packages:i,paths:e.paths.map(r=>({id:r.id,direction:r.direction,provider:r.provider,from:r.from,target:r.target,feeRate:r.fee_rate,amountIn:r.amount_in.toString(),amountOut:r.amount_out.toString(),version:r.version,publishedAt:r.published_at,extendedDetails:r.extended_details}))}}function $a(e,t,i,r,n){return Nt(this,null,function*(){let s;if(i.liquidityChanges&&i.liquidityChanges.length>0?s=yield ed(e,i):s=yield Qc(e,t,i),!s)return null;if(!s.ok){let p=1e3;return s.status===429&&(p=1001),{quoteID:"",amountIn:sr,amountOut:sr,paths:[],byAmountIn:i.byAmountIn,insufficientLiquidity:!1,deviationRatio:0,error:{code:p,msg:hn(p)}}}let a=p0.default.parse(yield s.text()),c=a.msg==="liquidity is not enough";if(a.msg&&a.msg.indexOf("HoneyPot scam")>-1)return{quoteID:"",amountIn:sr,amountOut:sr,paths:[],byAmountIn:i.byAmountIn,insufficientLiquidity:c,deviationRatio:0,error:{code:1003,msg:hn(1003)}};if(a.data!=null){let p=Yc(a.data,i.byAmountIn);if(r>0&&n!=="0x0")if(i.byAmountIn){let g=p.amountOut.mul(new pr.default(r)).div(new pr.default(1e6));p.overlayFee=Number(g.toString()),p.amountOut=p.amountOut.sub(g)}else{let g=p.amountIn.mul(new pr.default(r)).div(new pr.default(1e6));p.overlayFee=Number(g.toString()),p.amountIn=p.amountIn.add(g)}return p.packages||(p.packages=new Map),p.packages.has("aggregator_v3")||p.packages.set("aggregator_v3","0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032"),p}return{quoteID:"",amountIn:sr,amountOut:sr,paths:[],insufficientLiquidity:c,byAmountIn:i.byAmountIn,deviationRatio:0,error:{code:1002,msg:hn(1002)}}})}function Qc(e,t,i){return Nt(this,null,function*(){try{let{from:r,target:n,amount:s,byAmountIn:a,depth:c,splitAlgorithm:p,splitFactor:g,splitCount:v,providers:y}=i,A=Bi(r),k=Bi(n),U=`${e}/find_routes?from=${A}&target=${k}&amount=${s.toString()}&by_amount_in=${a}`;return c&&(U+=`&depth=${c}`),p&&(U+=`&split_algorithm=${p}`),g&&(U+=`&split_factor=${g}`),v&&(U+=`&split_count=${v}`),y&&y.length>0&&(U+=`&providers=${y.join(",")}`),t.length>0&&(U+=`&apiKey=${t}`),U+=`&v=${qa}`,console.log("url",U),yield fetch(U)}catch(r){return console.error(r),null}})}function ed(e,t){return Nt(this,null,function*(){let{from:i,target:r,amount:n,byAmountIn:s,depth:a,splitAlgorithm:c,splitFactor:p,splitCount:g,providers:v,liquidityChanges:y}=t,A=Bi(i),k=Bi(r),U=`${e}/find_routes`,P=v?.join(","),W={from:A,target:k,amount:Number(n.toString()),by_amount_in:s,depth:a,split_algorithm:c,split_factor:p,split_count:g,providers:P,liquidity_changes:y.map(j=>({pool:j.poolID,tick_lower:j.ticklower,tick_upper:j.tickUpper,delta_liquidity:j.deltaLiquidity})),v:qa};try{return yield fetch(U,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(W)})}catch(j){return console.error("Error:",j),null}})}function td(e){return Nt(this,null,function*(){let t=`${e}/deepbookv3_config`;try{return(yield fetch(t)).json()}catch(i){return console.error("Error:",i),null}})}function yo(e){let t=e.paths,i=t[0].from,r=t[t.length-1].target,n=[];for(let a of t)n.push({path:a,isLastUseOfIntermediateToken:!1});let s=new Map;for(let a=n.length-1;a>=0;a--){let{from:c}=n[a].path;s.has(c)||(s.set(c,!0),n[a].isLastUseOfIntermediateToken=!0)}return console.log("flattenedPaths",n),{quoteID:e.quoteID||"",amountIn:e.amountIn,amountOut:e.amountOut,byAmountIn:e.byAmountIn,flattenedPaths:n,fromCoinType:i,targetCoinType:r,packages:e.packages,totalDeepFee:e.totalDeepFee,error:e.error,overlayFee:e.overlayFee}}var Ha=(e=>(e[e.Mainnet=0]="Mainnet",e[e.Testnet=1]="Testnet",e))(Ha||{}),id=class{constructor(e,t,i,r){this.endpoint=e,this.fullNodeUrl=t,this.signer=i,this.env=r}getAggregatorUrl(){return this.endpoint}getFullNodeUrl(){return this.fullNodeUrl}getWallet(){return this.signer}getENV(){return this.env}},rd=vr(wr()),mr=9e15,Yi=1e9,Mo="0123456789abcdef",gn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",_n="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ao={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-mr,maxE:mr,crypto:!1},Ga,Di,qe=!0,Mn="[DecimalError] ",Ji=Mn+"Invalid argument: ",Va=Mn+"Precision limit exceeded",Za=Mn+"crypto unavailable",Ka="[object Decimal]",jt=Math.floor,It=Math.pow,nd=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,od=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,sd=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Wa=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,wi=1e7,Fe=7,ad=9007199254740991,ld=gn.length-1,So=_n.length-1,ne={toStringTag:Ka};ne.absoluteValue=ne.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),xe(e)};ne.ceil=function(){return xe(new this.constructor(this),this.e+1,2)};ne.clampedTo=ne.clamp=function(e,t){var i,r=this,n=r.constructor;if(e=new n(e),t=new n(t),!e.s||!t.s)return new n(NaN);if(e.gt(t))throw Error(Ji+t);return i=r.cmp(e),i<0?e:r.cmp(t)>0?t:new n(r)};ne.comparedTo=ne.cmp=function(e){var t,i,r,n,s=this,a=s.d,c=(e=new s.constructor(e)).d,p=s.s,g=e.s;if(!a||!c)return!p||!g?NaN:p!==g?p:a===c?0:!a^p<0?1:-1;if(!a[0]||!c[0])return a[0]?p:c[0]?-g:0;if(p!==g)return p;if(s.e!==e.e)return s.e>e.e^p<0?1:-1;for(r=a.length,n=c.length,t=0,i=r<n?r:n;t<i;++t)if(a[t]!==c[t])return a[t]>c[t]^p<0?1:-1;return r===n?0:r>n^p<0?1:-1};ne.cosine=ne.cos=function(){var e,t,i=this,r=i.constructor;return i.d?i.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+Fe,r.rounding=1,i=ud(r,Qa(r,i)),r.precision=e,r.rounding=t,xe(Di==2||Di==3?i.neg():i,e,t,!0)):new r(1):new r(NaN)};ne.cubeRoot=ne.cbrt=function(){var e,t,i,r,n,s,a,c,p,g,v=this,y=v.constructor;if(!v.isFinite()||v.isZero())return new y(v);for(qe=!1,s=v.s*It(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=Rt(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=It(i,1/3),e=jt((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?i="5e"+e:(i=s.toExponential(),i=i.slice(0,i.indexOf("e")+1)+e),r=new y(i),r.s=v.s):r=new y(s.toString()),a=(e=y.precision)+3;;)if(c=r,p=c.times(c).times(c),g=p.plus(v),r=ct(g.plus(v).times(c),g.plus(p),a+2,1),Rt(c.d).slice(0,a)===(i=Rt(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(xe(c,e+1,0),c.times(c).times(c).eq(v))){r=c;break}a+=4,n=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(xe(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return qe=!0,xe(r,e,y.rounding,t)};ne.decimalPlaces=ne.dp=function(){var e,t=this.d,i=NaN;if(t){if(e=t.length-1,i=(e-jt(this.e/Fe))*Fe,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};ne.dividedBy=ne.div=function(e){return ct(this,new this.constructor(e))};ne.dividedToIntegerBy=ne.divToInt=function(e){var t=this,i=t.constructor;return xe(ct(t,new i(e),0,1,1),i.precision,i.rounding)};ne.equals=ne.eq=function(e){return this.cmp(e)===0};ne.floor=function(){return xe(new this.constructor(this),this.e+1,3)};ne.greaterThan=ne.gt=function(e){return this.cmp(e)>0};ne.greaterThanOrEqualTo=ne.gte=function(e){var t=this.cmp(e);return t==1||t===0};ne.hyperbolicCosine=ne.cosh=function(){var e,t,i,r,n,s=this,a=s.constructor,c=new a(1);if(!s.isFinite())return new a(s.s?1/0:NaN);if(s.isZero())return c;i=a.precision,r=a.rounding,a.precision=i+Math.max(s.e,s.sd())+4,a.rounding=1,n=s.d.length,n<32?(e=Math.ceil(n/3),t=(1/Sn(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=_r(a,1,s.times(t),new a(1),!0);for(var p,g=e,v=new a(8);g--;)p=s.times(s),s=c.minus(p.times(v.minus(p.times(v))));return xe(s,a.precision=i,a.rounding=r,!0)};ne.hyperbolicSine=ne.sinh=function(){var e,t,i,r,n=this,s=n.constructor;if(!n.isFinite()||n.isZero())return new s(n);if(t=s.precision,i=s.rounding,s.precision=t+Math.max(n.e,n.sd())+4,s.rounding=1,r=n.d.length,r<3)n=_r(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/Sn(5,e)),n=_r(s,2,n,n,!0);for(var a,c=new s(5),p=new s(16),g=new s(20);e--;)a=n.times(n),n=n.times(c.plus(a.times(p.times(a).plus(g))))}return s.precision=t,s.rounding=i,xe(n,t,i,!0)};ne.hyperbolicTangent=ne.tanh=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,ct(i.sinh(),i.cosh(),r.precision=e,r.rounding=t)):new r(i.s)};ne.inverseCosine=ne.acos=function(){var e,t=this,i=t.constructor,r=t.abs().cmp(1),n=i.precision,s=i.rounding;return r!==-1?r===0?t.isNeg()?vi(i,n,s):new i(0):new i(NaN):t.isZero()?vi(i,n+4,s).times(.5):(i.precision=n+6,i.rounding=1,t=t.asin(),e=vi(i,n+4,s).times(.5),i.precision=n,i.rounding=s,e.minus(t))};ne.inverseHyperbolicCosine=ne.acosh=function(){var e,t,i=this,r=i.constructor;return i.lte(1)?new r(i.eq(1)?0:NaN):i.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(i.e),i.sd())+4,r.rounding=1,qe=!1,i=i.times(i).minus(1).sqrt().plus(i),qe=!0,r.precision=e,r.rounding=t,i.ln()):new r(i)};ne.inverseHyperbolicSine=ne.asinh=function(){var e,t,i=this,r=i.constructor;return!i.isFinite()||i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(i.e),i.sd())+6,r.rounding=1,qe=!1,i=i.times(i).plus(1).sqrt().plus(i),qe=!0,r.precision=e,r.rounding=t,i.ln())};ne.inverseHyperbolicTangent=ne.atanh=function(){var e,t,i,r,n=this,s=n.constructor;return n.isFinite()?n.e>=0?new s(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(e=s.precision,t=s.rounding,r=n.sd(),Math.max(r,e)<2*-n.e-1?xe(new s(n),e,t,!0):(s.precision=i=r-n.e,n=ct(n.plus(1),new s(1).minus(n),i+e,1),s.precision=e+4,s.rounding=1,n=n.ln(),s.precision=e,s.rounding=t,n.times(.5))):new s(NaN)};ne.inverseSine=ne.asin=function(){var e,t,i,r,n=this,s=n.constructor;return n.isZero()?new s(n):(t=n.abs().cmp(1),i=s.precision,r=s.rounding,t!==-1?t===0?(e=vi(s,i+4,r).times(.5),e.s=n.s,e):new s(NaN):(s.precision=i+6,s.rounding=1,n=n.div(new s(1).minus(n.times(n)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=r,n.times(2)))};ne.inverseTangent=ne.atan=function(){var e,t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding;if(g.isFinite()){if(g.isZero())return new v(g);if(g.abs().eq(1)&&y+4<=So)return a=vi(v,y+4,A).times(.25),a.s=g.s,a}else{if(!g.s)return new v(NaN);if(y+4<=So)return a=vi(v,y+4,A).times(.5),a.s=g.s,a}for(v.precision=c=y+10,v.rounding=1,i=Math.min(28,c/Fe+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(qe=!1,t=Math.ceil(c/Fe),r=1,p=g.times(g),a=new v(g),n=g;e!==-1;)if(n=n.times(p),s=a.minus(n.div(r+=2)),n=n.times(p),a=s.plus(n.div(r+=2)),a.d[t]!==void 0)for(e=t;a.d[e]===s.d[e]&&e--;);return i&&(a=a.times(2<<i-1)),qe=!0,xe(a,v.precision=y,v.rounding=A,!0)};ne.isFinite=function(){return!!this.d};ne.isInteger=ne.isInt=function(){return!!this.d&&jt(this.e/Fe)>this.d.length-2};ne.isNaN=function(){return!this.s};ne.isNegative=ne.isNeg=function(){return this.s<0};ne.isPositive=ne.isPos=function(){return this.s>0};ne.isZero=function(){return!!this.d&&this.d[0]===0};ne.lessThan=ne.lt=function(e){return this.cmp(e)<0};ne.lessThanOrEqualTo=ne.lte=function(e){return this.cmp(e)<1};ne.logarithm=ne.log=function(e){var t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding,k=5;if(e==null)e=new v(10),t=!0;else{if(e=new v(e),i=e.d,e.s<0||!i||!i[0]||e.eq(1))return new v(NaN);t=e.eq(10)}if(i=g.d,g.s<0||!i||!i[0]||g.eq(1))return new v(i&&!i[0]?-1/0:g.s!=1?NaN:i?0:1/0);if(t)if(i.length>1)s=!0;else{for(n=i[0];n%10===0;)n/=10;s=n!==1}if(qe=!1,c=y+k,a=Xi(g,c),r=t?vn(v,c+10):Xi(e,c),p=ct(a,r,c,1),Lr(p.d,n=y,A))do if(c+=10,a=Xi(g,c),r=t?vn(v,c+10):Xi(e,c),p=ct(a,r,c,1),!s){+Rt(p.d).slice(n+1,n+15)+1==1e14&&(p=xe(p,y+1,0));break}while(Lr(p.d,n+=10,A));return qe=!0,xe(p,y,A)};ne.minus=ne.sub=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.constructor;if(e=new U(e),!k.d||!e.d)return!k.s||!e.s?e=new U(NaN):k.d?e.s=-e.s:e=new U(e.d||k.s!==e.s?k:NaN),e;if(k.s!=e.s)return e.s=-e.s,k.plus(e);if(g=k.d,A=e.d,c=U.precision,p=U.rounding,!g[0]||!A[0]){if(A[0])e.s=-e.s;else if(g[0])e=new U(k);else return new U(p===3?-0:0);return qe?xe(e,c,p):e}if(i=jt(e.e/Fe),v=jt(k.e/Fe),g=g.slice(),s=v-i,s){for(y=s<0,y?(t=g,s=-s,a=A.length):(t=A,i=v,a=g.length),r=Math.max(Math.ceil(c/Fe),a)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=g.length,a=A.length,y=r<a,y&&(a=r),r=0;r<a;r++)if(g[r]!=A[r]){y=g[r]<A[r];break}s=0}for(y&&(t=g,g=A,A=t,e.s=-e.s),a=g.length,r=A.length-a;r>0;--r)g[a++]=0;for(r=A.length;r>s;){if(g[--r]<A[r]){for(n=r;n&&g[--n]===0;)g[n]=wi-1;--g[n],g[r]+=wi}g[r]-=A[r]}for(;g[--a]===0;)g.pop();for(;g[0]===0;g.shift())--i;return g[0]?(e.d=g,e.e=An(g,i),qe?xe(e,c,p):e):new U(p===3?-0:0)};ne.modulo=ne.mod=function(e){var t,i=this,r=i.constructor;return e=new r(e),!i.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||i.d&&!i.d[0]?xe(new r(i),r.precision,r.rounding):(qe=!1,r.modulo==9?(t=ct(i,e.abs(),0,3,1),t.s*=e.s):t=ct(i,e,0,r.modulo,1),t=t.times(e),qe=!0,i.minus(t))};ne.naturalExponential=ne.exp=function(){return Co(this)};ne.naturalLogarithm=ne.ln=function(){return Xi(this)};ne.negated=ne.neg=function(){var e=new this.constructor(this);return e.s=-e.s,xe(e)};ne.plus=ne.add=function(e){var t,i,r,n,s,a,c,p,g,v,y=this,A=y.constructor;if(e=new A(e),!y.d||!e.d)return!y.s||!e.s?e=new A(NaN):y.d||(e=new A(e.d||y.s===e.s?y:NaN)),e;if(y.s!=e.s)return e.s=-e.s,y.minus(e);if(g=y.d,v=e.d,c=A.precision,p=A.rounding,!g[0]||!v[0])return v[0]||(e=new A(y)),qe?xe(e,c,p):e;if(s=jt(y.e/Fe),r=jt(e.e/Fe),g=g.slice(),n=s-r,n){for(n<0?(i=g,n=-n,a=v.length):(i=v,r=s,a=g.length),s=Math.ceil(c/Fe),a=s>a?s+1:a+1,n>a&&(n=a,i.length=1),i.reverse();n--;)i.push(0);i.reverse()}for(a=g.length,n=v.length,a-n<0&&(n=a,i=v,v=g,g=i),t=0;n;)t=(g[--n]=g[n]+v[n]+t)/wi|0,g[n]%=wi;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=An(g,r),qe?xe(e,c,p):e};ne.precision=ne.sd=function(e){var t,i=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Ji+e);return i.d?(t=za(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};ne.round=function(){var e=this,t=e.constructor;return xe(new t(e),e.e+1,t.rounding)};ne.sine=ne.sin=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+Fe,r.rounding=1,i=dd(r,Qa(r,i)),r.precision=e,r.rounding=t,xe(Di>2?i.neg():i,e,t,!0)):new r(NaN)};ne.squareRoot=ne.sqrt=function(){var e,t,i,r,n,s,a=this,c=a.d,p=a.e,g=a.s,v=a.constructor;if(g!==1||!c||!c[0])return new v(!g||g<0&&(!c||c[0])?NaN:c?a:1/0);for(qe=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=Rt(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=jt((p+1)/2)-(p<0||p%2),g==1/0?t="5e"+p:(t=g.toExponential(),t=t.slice(0,t.indexOf("e")+1)+p),r=new v(t)):r=new v(g.toString()),i=(p=v.precision)+3;;)if(s=r,r=s.plus(ct(a,s,i+2,1)).times(.5),Rt(s.d).slice(0,i)===(t=Rt(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(xe(s,p+1,0),s.times(s).eq(a))){r=s;break}i+=4,n=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(xe(r,p+1,1),e=!r.times(r).eq(a));break}return qe=!0,xe(r,p,v.rounding,e)};ne.tangent=ne.tan=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,i=i.sin(),i.s=1,i=ct(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,xe(Di==2||Di==4?i.neg():i,e,t,!0)):new r(NaN)};ne.times=ne.mul=function(e){var t,i,r,n,s,a,c,p,g,v=this,y=v.constructor,A=v.d,k=(e=new y(e)).d;if(e.s*=v.s,!A||!A[0]||!k||!k[0])return new y(!e.s||A&&!A[0]&&!k||k&&!k[0]&&!A?NaN:!A||!k?e.s/0:e.s*0);for(i=jt(v.e/Fe)+jt(e.e/Fe),p=A.length,g=k.length,p<g&&(s=A,A=k,k=s,a=p,p=g,g=a),s=[],a=p+g,r=a;r--;)s.push(0);for(r=g;--r>=0;){for(t=0,n=p+r;n>r;)c=s[n]+k[r]*A[n-r-1]+t,s[n--]=c%wi|0,t=c/wi|0;s[n]=(s[n]+t)%wi|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=An(s,i),qe?xe(e,y.precision,y.rounding):e};ne.toBinary=function(e,t){return To(this,2,e,t)};ne.toDecimalPlaces=ne.toDP=function(e,t){var i=this,r=i.constructor;return i=new r(i),e===void 0?i:(Vt(e,0,Yi),t===void 0?t=r.rounding:Vt(t,0,8),xe(i,e+i.e+1,t))};ne.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ii(r,!0):(Vt(e,0,Yi),t===void 0?t=n.rounding:Vt(t,0,8),r=xe(new n(r),e+1,t),i=Ii(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+i:i};ne.toFixed=function(e,t){var i,r,n=this,s=n.constructor;return e===void 0?i=Ii(n):(Vt(e,0,Yi),t===void 0?t=s.rounding:Vt(t,0,8),r=xe(new s(n),e+n.e+1,t),i=Ii(r,!1,e+r.e+1)),n.isNeg()&&!n.isZero()?"-"+i:i};ne.toFraction=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.d,P=k.constructor;if(!U)return new P(k);if(g=i=new P(1),r=p=new P(0),t=new P(r),s=t.e=za(U)-k.e-1,a=s%Fe,t.d[0]=It(10,a<0?Fe+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(Ji+c);e=c.gt(t)?s>0?t:g:c}for(qe=!1,c=new P(Rt(U)),v=P.precision,P.precision=s=U.length*Fe*2;y=ct(c,t,0,1,1),n=i.plus(y.times(r)),n.cmp(e)!=1;)i=r,r=n,n=g,g=p.plus(y.times(n)),p=n,n=t,t=c.minus(y.times(n)),c=n;return n=ct(e.minus(i),r,0,1,1),p=p.plus(n.times(g)),i=i.plus(n.times(r)),p.s=g.s=k.s,A=ct(g,r,s,1).minus(k).abs().cmp(ct(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,qe=!0,A};ne.toHexadecimal=ne.toHex=function(e,t){return To(this,16,e,t)};ne.toNearest=function(e,t){var i=this,r=i.constructor;if(i=new r(i),e==null){if(!i.d)return i;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Vt(t,0,8),!i.d)return e.s?i:e;if(!e.d)return e.s&&(e.s=i.s),e}return e.d[0]?(qe=!1,i=ct(i,e,0,t,1).times(e),qe=!0,xe(i)):(e.s=i.s,i=e),i};ne.toNumber=function(){return+this};ne.toOctal=function(e,t){return To(this,8,e,t)};ne.toPower=ne.pow=function(e){var t,i,r,n,s,a,c=this,p=c.constructor,g=+(e=new p(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new p(It(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return xe(c,r,s);if(t=jt(e.e/Fe),t>=e.d.length-1&&(i=g<0?-g:g)<=ad)return n=Xa(p,c,i,r),e.s<0?new p(1).div(n):xe(n,r,s);if(a=c.s,a<0){if(t<e.d.length-1)return new p(NaN);if((e.d[t]&1)==0&&(a=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=a,c}return i=It(+c,g),t=i==0||!isFinite(i)?jt(g*(Math.log("0."+Rt(c.d))/Math.LN10+c.e+1)):new p(i+"").e,t>p.maxE+1||t<p.minE-1?new p(t>0?a/0:0):(qe=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=Co(e.times(Xi(c,r+i)),r),n.d&&(n=xe(n,r+5,1),Lr(n.d,r,s)&&(t=r+10,n=xe(Co(e.times(Xi(c,t+i)),t),t+5,1),+Rt(n.d).slice(r+1,r+15)+1==1e14&&(n=xe(n,r+1,0)))),n.s=a,qe=!0,p.rounding=s,xe(n,r,s))};ne.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ii(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Vt(e,1,Yi),t===void 0?t=n.rounding:Vt(t,0,8),r=xe(new n(r),e,t),i=Ii(r,e<=r.e||r.e<=n.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+i:i};ne.toSignificantDigits=ne.toSD=function(e,t){var i=this,r=i.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Vt(e,1,Yi),t===void 0?t=r.rounding:Vt(t,0,8)),xe(new r(i),e,t)};ne.toString=function(){var e=this,t=e.constructor,i=Ii(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};ne.truncated=ne.trunc=function(){return xe(new this.constructor(this),this.e+1,1)};ne.valueOf=ne.toJSON=function(){var e=this,t=e.constructor,i=Ii(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function Rt(e){var t,i,r,n=e.length-1,s="",a=e[0];if(n>0){for(s+=a,t=1;t<n;t++)r=e[t]+"",i=Fe-r.length,i&&(s+=zi(i)),s+=r;a=e[t],r=a+"",i=Fe-r.length,i&&(s+=zi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Vt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(Ji+e)}function Lr(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Fe,n=0):(n=Math.ceil((t+1)/Fe),t%=Fe),s=It(10,Fe-t),c=e[n]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),a=i<4&&c==99999||i>3&&c==49999||c==5e4||c==0):a=(i<4&&c+1==s||i>3&&c+1==s/2)&&(e[n+1]/s/100|0)==It(10,t-2)-1||(c==s/2||c==0)&&(e[n+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),a=(r||i<4)&&c==9999||!r&&i>3&&c==4999):a=((r||i<4)&&c+1==s||!r&&i>3&&c+1==s/2)&&(e[n+1]/s/1e3|0)==It(10,t-3)-1,a}function fn(e,t,i){for(var r,n=[0],s,a=0,c=e.length;a<c;){for(s=n.length;s--;)n[s]*=t;for(n[0]+=Mo.indexOf(e.charAt(a++)),r=0;r<n.length;r++)n[r]>i-1&&(n[r+1]===void 0&&(n[r+1]=0),n[r+1]+=n[r]/i|0,n[r]%=i)}return n.reverse()}function ud(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/Sn(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=_r(e,1,t.times(n),new e(1));for(var s=i;s--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return e.precision-=i,t}var ct=(function(){function e(r,n,s){var a,c=0,p=r.length;for(r=r.slice();p--;)a=r[p]*n+c,r[p]=a%s|0,c=a/s|0;return c&&r.unshift(c),r}function t(r,n,s,a){var c,p;if(s!=a)p=s>a?1:-1;else for(c=p=0;c<s;c++)if(r[c]!=n[c]){p=r[c]>n[c]?1:-1;break}return p}function i(r,n,s,a){for(var c=0;s--;)r[s]-=c,c=r[s]<n[s]?1:0,r[s]=c*a+r[s]-n[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,n,s,a,c,p){var g,v,y,A,k,U,P,W,j,K,X,Q,se,Y,le,E,I,O,R,N,S=r.constructor,h=r.s==n.s?1:-1,o=r.d,l=n.d;if(!o||!o[0]||!l||!l[0])return new S(!r.s||!n.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?h*0:h/0);for(p?(k=1,v=r.e-n.e):(p=wi,k=Fe,v=jt(r.e/k)-jt(n.e/k)),R=l.length,I=o.length,j=new S(h),K=j.d=[],y=0;l[y]==(o[y]||0);y++);if(l[y]>(o[y]||0)&&v--,s==null?(Y=s=S.precision,a=S.rounding):c?Y=s+(r.e-n.e)+1:Y=s,Y<0)K.push(1),U=!0;else{if(Y=Y/k+2|0,y=0,R==1){for(A=0,l=l[0],Y++;(y<I||A)&&Y--;y++)le=A*p+(o[y]||0),K[y]=le/l|0,A=le%l|0;U=A||y<I}else{for(A=p/(l[0]+1)|0,A>1&&(l=e(l,A,p),o=e(o,A,p),R=l.length,I=o.length),E=R,X=o.slice(0,R),Q=X.length;Q<R;)X[Q++]=0;N=l.slice(),N.unshift(0),O=l[0],l[1]>=p/2&&++O;do A=0,g=t(l,X,R,Q),g<0?(se=X[0],R!=Q&&(se=se*p+(X[1]||0)),A=se/O|0,A>1?(A>=p&&(A=p-1),P=e(l,A,p),W=P.length,Q=X.length,g=t(P,X,W,Q),g==1&&(A--,i(P,R<W?N:l,W,p))):(A==0&&(g=A=1),P=l.slice()),W=P.length,W<Q&&P.unshift(0),i(X,P,Q,p),g==-1&&(Q=X.length,g=t(l,X,R,Q),g<1&&(A++,i(X,R<Q?N:l,Q,p))),Q=X.length):g===0&&(A++,X=[0]),K[y++]=A,g&&X[0]?X[Q++]=o[E]||0:(X=[o[E]],Q=1);while((E++<I||X[0]!==void 0)&&Y--);U=X[0]!==void 0}K[0]||K.shift()}if(k==1)j.e=v,Ga=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,xe(j,c?s+j.e+1:s,a,U)}return j}})();function xe(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor;e:if(t!=null){if(y=e.d,!y)return e;for(n=1,c=y[0];c>=10;c/=10)n++;if(s=t-n,s<0)s+=Fe,a=t,v=y[A=0],p=v/It(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/Fe),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=Fe,a=s-Fe+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=Fe,a=s-Fe+n,p=a<0?0:v/It(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%It(10,n-a-1)),g=i<4?(p||r)&&(i==0||i==(e.s<0?3:2)):p>5||p==5&&(i==4||r||i==6&&(s>0?a>0?v/It(10,n-a):0:y[A-1])%10&1||i==(e.s<0?8:7)),t<1||!y[0])return y.length=0,g?(t-=e.e+1,y[0]=It(10,(Fe-t%Fe)%Fe),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=It(10,Fe-s),y[A]=a>0?(v/It(10,n-a)%It(10,a)|0)*c:0),g)for(;;)if(A==0){for(s=1,a=y[0];a>=10;a/=10)s++;for(a=y[0]+=c,c=1;a>=10;a/=10)c++;s!=c&&(e.e++,y[0]==wi&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=wi)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return qe&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function Ii(e,t,i){if(!e.isFinite())return Ya(e);var r,n=e.e,s=Rt(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+zi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+zi(-n-1)+s,i&&(r=i-a)>0&&(s+=zi(r))):n>=a?(s+=zi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+zi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=zi(r))),s}function An(e,t){var i=e[0];for(t*=Fe;i>=10;i/=10)t++;return t}function vn(e,t,i){if(t>ld)throw qe=!0,i&&(e.precision=i),Error(Va);return xe(new e(gn),t,1,!0)}function vi(e,t,i){if(t>So)throw Error(Va);return xe(new e(_n),t,i,!0)}function za(e){var t=e.length-1,i=t*Fe+1;if(t=e[t],t){for(;t%10==0;t/=10)i--;for(t=e[0];t>=10;t/=10)i++}return i}function zi(e){for(var t="";e--;)t+="0";return t}function Xa(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/Fe+4);for(qe=!1;;){if(i%2&&(s=s.times(t),ha(s.d,a)&&(n=!0)),i=jt(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),ha(t.d,a)}return qe=!0,s}function da(e){return e.d[e.d.length-1]&1}function Ja(e,t,i){for(var r,n=new e(t[0]),s=0;++s<t.length;)if(r=new e(t[s]),r.s)n[i](r)&&(n=r);else{n=r;break}return n}function Co(e,t){var i,r,n,s,a,c,p,g=0,v=0,y=0,A=e.constructor,k=A.rounding,U=A.precision;if(!e.d||!e.d[0]||e.e>17)return new A(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(qe=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(It(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=xe(s.times(e),p,1),i=i.times(++v),c=a.plus(ct(s,i,p,1)),Rt(c.d).slice(0,p)===Rt(a.d).slice(0,p)){for(n=y;n--;)a=xe(a.times(a),p,1);if(t==null)if(g<3&&Lr(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return xe(a,A.precision=U,k,qe=!0);else return A.precision=U,a}a=c}}function Xi(e,t){var i,r,n,s,a,c,p,g,v,y,A,k=1,U=10,P=e,W=P.d,j=P.constructor,K=j.rounding,X=j.precision;if(P.s<0||!W||!W[0]||!P.e&&W[0]==1&&W.length==1)return new j(W&&!W[0]?-1/0:P.s!=1?NaN:W?0:P);if(t==null?(qe=!1,v=X):v=t,j.precision=v+=U,i=Rt(W),r=i.charAt(0),Math.abs(s=P.e)<15e14){for(;r<7&&r!=1||r==1&&i.charAt(1)>3;)P=P.times(e),i=Rt(P.d),r=i.charAt(0),k++;s=P.e,r>1?(P=new j("0."+i),s++):P=new j(r+"."+i.slice(1))}else return g=vn(j,v+2,X).times(s+""),P=Xi(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?xe(P,X,K,qe=!0):P;for(y=P,p=a=P=ct(P.minus(1),P.plus(1),v,1),A=xe(P.times(P),v,1),n=3;;){if(a=xe(a.times(A),v,1),g=p.plus(ct(a,new j(n),v,1)),Rt(g.d).slice(0,v)===Rt(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(vn(j,v+2,X).times(s+""))),p=ct(p,new j(k),v,1),t==null)if(Lr(p.d,v-U,K,c))j.precision=v+=U,g=a=P=ct(y.minus(1),y.plus(1),v,1),A=xe(P.times(P),v,1),n=c=1;else return xe(p,j.precision=X,K,qe=!0);else return j.precision=X,p;p=g,n+=2}}function Ya(e){return String(e.s*e.s/0)}function Eo(e,t){var i,r,n;for((i=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(i<0&&(i=r),i+=+t.slice(r+1),t=t.substring(0,r)):i<0&&(i=t.length),r=0;t.charCodeAt(r)===48;r++);for(n=t.length;t.charCodeAt(n-1)===48;--n);if(t=t.slice(r,n),t){if(n-=r,e.e=i=i-r-1,e.d=[],r=(i+1)%Fe,i<0&&(r+=Fe),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=Fe;r<n;)e.d.push(+t.slice(r,r+=Fe));t=t.slice(r),r=Fe-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),qe&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function cd(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Wa.test(t))return Eo(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(od.test(t))i=16,t=t.toLowerCase();else if(nd.test(t))i=2;else if(sd.test(t))i=8;else throw Error(Ji+t);for(s=t.search(/p/i),s>0?(p=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),a=s>=0,r=e.constructor,a&&(t=t.replace(".",""),c=t.length,s=c-s,n=Xa(r,new r(i),s,s*2)),g=fn(t,i,wi),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=An(g,v),e.d=g,qe=!1,a&&(e=ct(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?It(2,p):Dr.pow(2,p))),qe=!0,e)}function dd(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:_r(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/Sn(5,i)),t=_r(e,2,t,t);for(var n,s=new e(5),a=new e(16),c=new e(20);i--;)n=t.times(t),t=t.times(s.plus(n.times(a.times(n).minus(c))));return t}function _r(e,t,i,r,n){var s,a,c,p,g=e.precision,v=Math.ceil(g/Fe);for(qe=!1,p=i.times(i),c=new e(r);;){if(a=ct(c.times(p),new e(t++*t++),g,1),c=n?r.plus(a):r.minus(a),r=ct(a.times(p),new e(t++*t++),g,1),a=c.plus(r),a.d[v]!==void 0){for(s=v;a.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=a,a=s}return qe=!0,a.d.length=v+1,a}function Sn(e,t){for(var i=e;--t;)i*=e;return i}function Qa(e,t){var i,r=t.s<0,n=vi(e,e.precision,1),s=n.times(.5);if(t=t.abs(),t.lte(s))return Di=r?4:1,t;if(i=t.divToInt(n),i.isZero())Di=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Di=da(i)?r?2:3:r?4:1,t;Di=da(i)?r?1:4:r?3:2}return t.minus(n).abs()}function To(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Vt(i,1,Yi),r===void 0?r=k.rounding:Vt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=Ya(e);else{for(v=Ii(e),a=v.indexOf("."),U?(n=2,t==16?i=i*4-3:t==8&&(i=i*3-2)):n=t,a>=0&&(v=v.replace(".",""),A=new k(1),A.e=v.length-a,A.d=fn(Ii(A),10,n),A.e=A.d.length),y=fn(v,10,n),s=p=y.length;y[--p]==0;)y.pop();if(!y[0])v=U?"0p+0":"0";else{if(a<0?s--:(e=new k(e),e.d=y,e.e=s,e=ct(e,A,i,r,0,n),y=e.d,s=e.e,g=Ga),a=y[i],c=n/2,g=g||y[i+1]!==void 0,g=r<4?(a!==void 0||g)&&(r===0||r===(e.s<0?3:2)):a>c||a===c&&(r===4||g||r===6&&y[i-1]&1||r===(e.s<0?8:7)),y.length=i,g)for(;++y[--i]>n-1;)y[i]=0,i||(++s,y.unshift(1));for(p=y.length;!y[p-1];--p);for(a=0,v="";a<p;a++)v+=Mo.charAt(y[a]);if(U){if(p>1)if(t==16||t==8){for(a=t==16?4:3,--p;p%a;p++)v+="0";for(y=fn(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=Mo.charAt(y[a])}else v=v.charAt(0)+"."+v.slice(1);v=v+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)v="0"+v;v="0."+v}else if(++s>p)for(s-=p;s--;)v+="0";else s<p&&(v=v.slice(0,s)+"."+v.slice(s))}v=(t==16?"0x":t==2?"0b":t==8?"0o":"")+v}return e.s<0?"-"+v:v}function ha(e,t){if(e.length>t)return e.length=t,!0}function hd(e){return new this(e).abs()}function fd(e){return new this(e).acos()}function pd(e){return new this(e).acosh()}function md(e,t){return new this(e).plus(t)}function gd(e){return new this(e).asin()}function _d(e){return new this(e).asinh()}function vd(e){return new this(e).atan()}function wd(e){return new this(e).atanh()}function bd(e,t){e=new this(e),t=new this(t);var i,r=this.precision,n=this.rounding,s=r+4;return!e.s||!t.s?i=new this(NaN):!e.d&&!t.d?(i=vi(this,s,1).times(t.s>0?.25:.75),i.s=e.s):!t.d||e.isZero()?(i=t.s<0?vi(this,r,n):new this(0),i.s=e.s):!e.d||t.isZero()?(i=vi(this,s,1).times(.5),i.s=e.s):t.s<0?(this.precision=s,this.rounding=1,i=this.atan(ct(e,t,s,1)),t=vi(this,s,1),this.precision=r,this.rounding=n,i=e.s<0?i.minus(t):i.plus(t)):i=this.atan(ct(e,t,s,1)),i}function yd(e){return new this(e).cbrt()}function Md(e){return xe(e=new this(e),e.e+1,2)}function Ad(e,t,i){return new this(e).clamp(t,i)}function Sd(e){if(!e||typeof e!="object")throw Error(Mn+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,Yi,"rounding",0,8,"toExpNeg",-mr,0,"toExpPos",0,mr,"maxE",0,mr,"minE",-mr,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(i=s[t],n&&(this[i]=Ao[i]),(r=e[i])!==void 0)if(jt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(Ji+i+": "+r);if(i="crypto",n&&(this[i]=Ao[i]),(r=e[i])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[i]=!0;else throw Error(Za);else this[i]=!1;else throw Error(Ji+i+": "+r);return this}function Cd(e){return new this(e).cos()}function Ed(e){return new this(e).cosh()}function el(e){var t,i,r;function n(s){var a,c,p,g=this;if(!(g instanceof n))return new n(s);if(g.constructor=n,fa(s)){g.s=s.s,qe?!s.d||s.e>n.maxE?(g.e=NaN,g.d=null):s.e<n.minE?(g.e=0,g.d=[0]):(g.e=s.e,g.d=s.d.slice()):(g.e=s.e,g.d=s.d?s.d.slice():s.d);return}if(p=typeof s,p==="number"){if(s===0){g.s=1/s<0?-1:1,g.e=0,g.d=[0];return}if(s<0?(s=-s,g.s=-1):g.s=1,s===~~s&&s<1e7){for(a=0,c=s;c>=10;c/=10)a++;qe?a>n.maxE?(g.e=NaN,g.d=null):a<n.minE?(g.e=0,g.d=[0]):(g.e=a,g.d=[s]):(g.e=a,g.d=[s]);return}else if(s*0!==0){s||(g.s=NaN),g.e=NaN,g.d=null;return}return Eo(g,s.toString())}else if(p!=="string")throw Error(Ji+s);return(c=s.charCodeAt(0))===45?(s=s.slice(1),g.s=-1):(c===43&&(s=s.slice(1)),g.s=1),Wa.test(s)?Eo(g,s):cd(g,s)}if(n.prototype=ne,n.ROUND_UP=0,n.ROUND_DOWN=1,n.ROUND_CEIL=2,n.ROUND_FLOOR=3,n.ROUND_HALF_UP=4,n.ROUND_HALF_DOWN=5,n.ROUND_HALF_EVEN=6,n.ROUND_HALF_CEIL=7,n.ROUND_HALF_FLOOR=8,n.EUCLID=9,n.config=n.set=Sd,n.clone=el,n.isDecimal=fa,n.abs=hd,n.acos=fd,n.acosh=pd,n.add=md,n.asin=gd,n.asinh=_d,n.atan=vd,n.atanh=wd,n.atan2=bd,n.cbrt=yd,n.ceil=Md,n.clamp=Ad,n.cos=Cd,n.cosh=Ed,n.div=Id,n.exp=kd,n.floor=Td,n.hypot=Od,n.ln=Pd,n.log=xd,n.log10=Rd,n.log2=Nd,n.max=Ld,n.min=Fd,n.mod=Dd,n.mul=Bd,n.pow=Ud,n.random=jd,n.round=qd,n.sign=$d,n.sin=Hd,n.sinh=Gd,n.sqrt=Vd,n.sub=Zd,n.sum=Kd,n.tan=Wd,n.tanh=zd,n.trunc=Xd,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(i=r[t++])||(e[i]=this[i]);return n.config(e),n}function Id(e,t){return new this(e).div(t)}function kd(e){return new this(e).exp()}function Td(e){return xe(e=new this(e),e.e+1,3)}function Od(){var e,t,i=new this(0);for(qe=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)i.d&&(i=i.plus(t.times(t)));else{if(t.s)return qe=!0,new this(1/0);i=t}return qe=!0,i.sqrt()}function fa(e){return e instanceof Dr||e&&e.toStringTag===Ka||!1}function Pd(e){return new this(e).ln()}function xd(e,t){return new this(e).log(t)}function Nd(e){return new this(e).log(2)}function Rd(e){return new this(e).log(10)}function Ld(){return Ja(this,arguments,"lt")}function Fd(){return Ja(this,arguments,"gt")}function Dd(e,t){return new this(e).mod(t)}function Bd(e,t){return new this(e).mul(t)}function Ud(e,t){return new this(e).pow(t)}function jd(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Vt(e,1,Yi),r=Math.ceil(e/Fe),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)n=t[s],n>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=n%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)n=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),n>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(n%1e7),s+=4);s=r/4}else throw Error(Za);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=Fe,r&&e&&(n=It(10,Fe-e),c[s]=(r/n|0)*n);c[s]===0;s--)c.pop();if(s<0)i=0,c=[0];else{for(i=-1;c[0]===0;i-=Fe)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<Fe&&(i-=Fe-r)}return a.e=i,a.d=c,a}function qd(e){return xe(e=new this(e),e.e+1,this.rounding)}function $d(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Hd(e){return new this(e).sin()}function Gd(e){return new this(e).sinh()}function Vd(e){return new this(e).sqrt()}function Zd(e,t){return new this(e).sub(t)}function Kd(){var e=0,t=arguments,i=new this(t[e]);for(qe=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return qe=!0,xe(i,this.precision,this.rounding)}function Wd(e){return new this(e).tan()}function zd(e){return new this(e).tanh()}function Xd(e){return xe(e=new this(e),e.e+1,1)}ne[Symbol.for("nodejs.util.inspect.custom")]=ne.toString;ne[Symbol.toStringTag]="Decimal";var Dr=ne.constructor=el(Ao);gn=new Dr(gn);_n=new Dr(_n);var wn=Dr;function Jd(e,t,i){return Number(tl(new wn(e.toString()),t,i).toFixed(0))}function pa(e,t,i){let r=tl(new wn(e.toString()),t,i);return new rd.default(r.toFixed(0))}function tl(e,t,i){return t?e.mul(1-i):e.mul(1+i)}var ma=class{constructor(e,t){if(e!==0)throw new Error("CetusRouter only supported on mainnet");this.globalConfig=e===0?"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f":"0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e",this.partner=t??(e===0?"0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b":"0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Cetus not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.globalConfig),e.object(t.poolId),e.object(this.partner),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::cetus::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}flashSwapFixedOutput(e,t,i,r){let n=[r,e.object(this.globalConfig),e.object(t.id),e.object(this.partner),i,e.pure.bool(t.direction),e.pure.bool(!1),e.object(yt.SUI_CLOCK_OBJECT_ID)],[s,a]=t.direction?[t.from,t.target]:[t.target,t.from],[c,p]=e.moveCall({target:`${t.publishedAt}::cetus::flash_swap_fixed_output`,typeArguments:[s,a],arguments:n});return{flashReceipt:c,repayAmount:p}}repayFlashSwapFixedOutput(e,t,i,r){let n=[i,e.object(this.globalConfig),e.object(t.id),e.object(this.partner),e.pure.bool(t.direction),r],[s,a]=t.direction?[t.from,t.target]:[t.target,t.from];e.moveCall({target:`${t.publishedAt}::cetus::repay_flash_swap_fixed_output`,typeArguments:[s,a],arguments:n})}add(e,t,i,r){let n=[t,i];return e.moveCall({target:`${r}::cetus::add`,typeArguments:[],arguments:n})}sub(e,t,i,r){let n=[t,i];return e.moveCall({target:`${r}::cetus::sub`,typeArguments:[],arguments:n})}},Yd=class{constructor(e){if(e!==0)throw new Error("Kriya V3 only supported on mainnet");this.version="0xf5145a7ac345ca8736cf8c76047d00d6d378f30e81be6f6eb557184d9de93c78"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Kriya V3 not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(this.version),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::kriya_clmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},Qd=class{constructor(e){if(e!==0)throw new Error("FlowX V3 only supported on mainnet");this.poolRegistry="0x27565d24a4cd51127ac90e4074a841bbe356cca7bf5759ddc14a975be1632abc",this.versioned="0x67624a1533b5aff5d0dfcf5e598684350efd38134d2d245f475524c03a64e656"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("FlowX V3 not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn,s=t.feeRate*1e6;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id,feeRate:s}}executeSwapContract(e,t,i){let r=[i,e.object(this.poolRegistry),e.object(this.versioned),e.pure.u64(t.feeRate),e.pure.u64(t.amountIn),e.pure.bool(t.direction),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::flowx_clmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},eh=class{constructor(e){if(e!==0)throw new Error("Turbos only supported on mainnet");this.versioned="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Turbos not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;if(t.extendedDetails==null)throw new Error("Extended details not supported");if(t.extendedDetails.turbos_fee_type==null)throw new Error("Turbos fee type not supported");let s=t.extendedDetails.turbos_fee_type;return{coinAType:i,coinBType:r,feeType:s,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(this.versioned),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::turbos::swap`,typeArguments:[t.coinAType,t.coinBType,t.feeType],arguments:r})}},th=class{constructor(e){if(e!==0)throw new Error("Bluefin only supported on mainnet");this.globalConfig="0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Bluefin not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.globalConfig),e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::bluefin::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},ih=class{constructor(e){if(e!==0)throw new Error("Momentum only supported on mainnet");this.version="0x2375a0b1ec12010aaea3b2545acfa2ad34cfbba03ce4b59f4c39e1e25eed1b2a"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Momentum not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(this.version),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::momentum::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},rh=class{constructor(e){if(e!==0)throw new Error("Magma only supported on mainnet");this.globalConfig="0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Magma not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.globalConfig),e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::magma::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},nh=class{constructor(e){if(e!==0)throw new Error("Kriya V2 only supported on mainnet")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Kriya V2 not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::kriya_amm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},oh=class{constructor(e){if(e!==0)throw new Error("FlowX V2 only supported on mainnet");this.container="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("FlowX V2 not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.container),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::flowx_amm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},sh=class{constructor(e){if(e!==0)throw new Error("BlueMove only supported on mainnet");this.dexInfo="0x3f2d9f724f4a1ce5e71676448dc452be9a6243dac9c5b975a588c8c867066e92"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("BlueMove not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.dexInfo),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::bluemove::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},ah=class{constructor(e){if(e!==0)throw new Error("DeepBook V3 only supported on mainnet");this.env=e,this.globalConfig="0x699d455ab8c5e02075b4345ea1f91be55bf46064ae6026cc2528e701ce3ac135"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i,r)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("DeepBook V3 not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i,r){let n=r?.deepbookv3DeepFee||e.moveCall({target:"0x2::coin::zero",typeArguments:[this.getDeepFeeType()]}),s=[i,e.object(this.globalConfig),e.object(t.poolId),e.pure.u64(t.amountIn),e.pure.bool(t.direction),n,e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::deepbookv3::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:s})}getDeepFeeType(){return this.env===0?Rr.Mainnet:Rr.Testnet}},lh=class{constructor(e){if(e!==0)throw new Error("Aftermath only supported on mainnet");this.poolRegistry="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",this.protocolFeeVault="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",this.treasury="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",this.insuranceFund="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",this.referralVault="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){var t,i;if(e.path.publishedAt==null)throw new Error("Aftermath not set publishedAt");let r=e.path,[n,s]=r.direction?[r.from,r.target]:[r.target,r.from],a=e.isLastUseOfIntermediateToken?"18446744073709551615":r.amountIn;return{coinAType:n,coinBType:s,feeType:((t=r.extendedDetails)==null?void 0:t.aftermath_lp_supply_type)||((i=r.extendedDetails)==null?void 0:i.aftermath_lp_supply_type)||"0x2::sui::SUI",direction:r.direction,amountIn:a,expectAmountOut:r.amountOut,publishedAt:r.publishedAt,poolId:r.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(this.poolRegistry),e.object(this.protocolFeeVault),e.object(this.treasury),e.object(this.insuranceFund),e.object(this.referralVault),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.pure.u64(t.expectAmountOut)];e.moveCall({target:`${t.publishedAt}::aftermath::swap`,typeArguments:[t.coinAType,t.coinBType,t.feeType],arguments:r})}},uh=class{constructor(e){if(e!==0)throw new Error("Steamm CPMM only supported on mainnet")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}validateExtendedDetails(e){let t=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type"];for(let i of t)if(e[i]==null)throw new Error(`Steamm CPMM ${i} not supported`)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Steamm CPMM not set publishedAt");if(!t.extendedDetails)throw new Error("Extended details not found for Steamm CPMM");this.validateExtendedDetails(t.extendedDetails);let{direction:i,from:r,target:n}=t,[s,a]=i?[r,n]:[n,r],c=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:s,coinBType:a,direction:i,amountIn:c,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:t.extendedDetails}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(t.extendedDetails.steamm_bank_a),e.object(t.extendedDetails.steamm_bank_b),e.object(t.extendedDetails.steamm_lending_market),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::steamm_cpmm::swap`,typeArguments:[t.extendedDetails.steamm_lending_market_type,t.coinAType,t.coinBType,t.extendedDetails.steamm_btoken_a_type,t.extendedDetails.steamm_btoken_b_type,t.extendedDetails.steamm_lp_token_type],arguments:r})}},ch=class{constructor(e){if(e!==0)throw new Error("Scallop only supported on mainnet");this.version="0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7",this.marketData="0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Scallop not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.from,t.target],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;if(t.extendedDetails==null)throw new Error("Extended details not supported");let s=t.extendedDetails.scallopScoinTreasury||t.extendedDetails.scallop_scoin_treasury;if(s==null)throw new Error("Scallop scoin treasury not supported");return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id,scallopScoinTreasury:s}}executeSwapContract(e,t,i){let r=[i,e.object(this.version),e.object(this.marketData),e.object(t.scallopScoinTreasury),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)],n=t.direction?"swap_a2b":"swap_b2a";e.moveCall({target:`${t.publishedAt}::scallop::${n}`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},ga=class{constructor(e){if(e!==0)throw new Error("Springsui only supported on mainnet")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Springsui not set publishedAt");let i=t.direction?t.target:t.from,r=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{springSUICoinType:i,direction:t.direction,amountIn:r,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object("0x5"),e.pure.u64(t.amountIn),e.pure.bool(t.direction)];e.moveCall({target:`${t.publishedAt}::springsui::swap`,typeArguments:[t.springSUICoinType],arguments:r})}},dh=class{constructor(e,t){if(e!==0)throw new Error("Haedal PMM only supported on mainnet");this.pythPriceIDs=t}swap(e,t,i,r){let n=t.path;if(!n.extendedDetails)throw new Error("Extended details not found for Haedal PMM");this.validateExtendedDetails(n.extendedDetails);let s=this.prepareSwapData(t);this.executeSwapContract(e,s,i)}validateExtendedDetails(e){if(!e.haedal_pmm_base_price_seed)throw new Error("Haedal PMM base price seed not supported");if(!e.haedal_pmm_quote_price_seed)throw new Error("Haedal PMM quote price seed not supported")}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Haedal PMM not set publishedAt");let i=t.extendedDetails,[r,n]=t.direction?[t.from,t.target]:[t.target,t.from],s=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn,a=i.haedal_pmm_base_price_seed,c=i.haedal_pmm_quote_price_seed,p=this.pythPriceIDs.get(a),g=this.pythPriceIDs.get(c);if(!p||!g)throw new Error("Haedal HMM requires oracle price IDs for both coins");return{coinAType:r,coinBType:n,basePriceId:p,quotePriceId:g,a2b:t.direction,amountIn:s,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(t.basePriceId),e.object(t.quotePriceId),e.pure.u64(t.amountIn),e.pure.bool(t.a2b),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::haedal_hmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},hh=class{constructor(e,t){if(e===1)throw new Error("Obric is not supported on testnet");this.pythStateObjectId="0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",this.pythPriceIDs=t}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Obric not set publishedAt");if(!t.extendedDetails)throw new Error("Extended details not supported in obric");let{direction:i,from:r,target:n}=t,[s,a]=i?[r,n]:[n,r],c=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn,p,g;if(t.extendedDetails.obric_coin_a_price_seed&&t.extendedDetails.obric_coin_b_price_seed)p=this.pythPriceIDs.get(t.extendedDetails.obric_coin_a_price_seed),g=this.pythPriceIDs.get(t.extendedDetails.obric_coin_b_price_seed);else if(t.extendedDetails.obric_coin_a_price_id&&t.extendedDetails.obric_coin_b_price_id)p=t.extendedDetails.obric_coin_a_price_id,g=t.extendedDetails.obric_coin_b_price_id;else throw new Error("Base price id or quote price id not supported");return{coinAType:s,coinBType:a,coinAPriceInfoObjectId:p,coinBPriceInfoObjectId:g,direction:i,amountIn:c,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:t.extendedDetails}}executeSwapContract(e,t,i){if(!t.coinAPriceInfoObjectId||!t.coinBPriceInfoObjectId)throw new Error("Base price info object id or quote price info object id not found");let r=[i,e.object(t.poolId),e.pure.u64(t.amountIn),e.pure.bool(t.direction),e.object(this.pythStateObjectId),e.object(t.coinAPriceInfoObjectId),e.object(t.coinBPriceInfoObjectId),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::obric::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},fh=class{constructor(e,t){if(e!==0)throw new Error("Sevenk only supported on mainnet");this.oraclePublishedAt="0x8c36ea167c5e6da8c3d60b4fc897416105dcb986471bd81cfbfd38720a4487c0",this.pythPriceIDs=t}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i,r)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Sevenk not set publishedAt");if(!t.extendedDetails)throw new Error("Extended details not found for Sevenk");let{direction:i,from:r,target:n}=t,[s,a,c]=i?["swap_a2b",r,n]:["swap_b2a",n,r],p=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn,g=t.extendedDetails;if(!g.sevenk_coin_a_price_seed||!g.sevenk_coin_b_price_seed||!g.sevenk_oracle_config_a||!g.sevenk_oracle_config_b||!g.sevenk_lp_cap_type)throw new Error("Required Sevenk extended details not found");let v=g.sevenk_coin_a_price_seed,y=g.sevenk_coin_b_price_seed,A=g.sevenk_oracle_config_a,k=g.sevenk_oracle_config_b,U=g.sevenk_lp_cap_type,P=this.pythPriceIDs.get(v),W=this.pythPriceIDs.get(y);if(!P||!W)throw new Error("Sevenk price info object IDs not found");return{func:s,coinAType:a,coinBType:c,coinAPriceId:P,coinBPriceId:W,coinAOracleId:A,coinBOracleId:k,lpCapType:U,direction:i,amountIn:p,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:t.extendedDetails}}executeSwapContract(e,t,i,r){let n=e.moveCall({target:`${this.oraclePublishedAt}::oracle::new_holder`,typeArguments:[],arguments:[]});e.moveCall({target:`${this.oraclePublishedAt}::pyth::get_price`,typeArguments:[],arguments:[e.object(t.coinAOracleId),n,e.object(t.coinAPriceId),e.object(yt.SUI_CLOCK_OBJECT_ID)]}),e.moveCall({target:`${this.oraclePublishedAt}::pyth::get_price`,typeArguments:[],arguments:[e.object(t.coinBOracleId),n,e.object(t.coinBPriceId),e.object(yt.SUI_CLOCK_OBJECT_ID)]});let s=[i,e.object(t.poolId),n,e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::sevenk::${t.func}`,typeArguments:[t.coinAType,t.coinBType,t.lpCapType],arguments:s})}},ph=class{constructor(e,t){if(e!==0)throw new Error("Steamm OMM only supported on mainnet");this.pythPriceIDs=t,this.oraclePackageId="0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b"}swap(e,t,i,r){let n=t.path;if(!n.extendedDetails)throw new Error("Extended details not found for Steamm OMM");this.validateExtendedDetails(n.extendedDetails);let s=this.prepareSwapData(t);this.executeSwapContract(e,s,i)}validateExtendedDetails(e){let t=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type","steammOracleRegistryId","steammOracleIndexA","steammOracleIndexB","steammOraclePythPriceSeedA","steammOraclePythPriceSeedB"];for(let i of t)if(e[i]==null)throw new Error(`Steamm ${i} not supported`)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Steamm OMM not set publishedAt");let i=t.extendedDetails,{direction:r,from:n,target:s}=t,[a,c,p]=r?["swap_a2b_v2",n,s]:["swap_b2a_v2",s,n],g=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn,v=i.steamm_oracle_pyth_price_seed_a,y=i.steamm_oracle_pyth_price_seed_b;if(!v||!y)throw new Error("Steamm oracle price seeds not found");let A=this.pythPriceIDs.get(v),k=this.pythPriceIDs.get(y);if(!A||!k)throw new Error("Base price info object id or quote price info object id not found");return{func:a,coinAType:c,coinBType:p,direction:r,amountIn:g,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:i,priceInfoObjectIdA:A,priceInfoObjectIdB:k}}executeSwapContract(e,t,i){let r=t.extendedDetails,n=e.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[e.object(r.steammOracleRegistryId),e.object(t.priceInfoObjectIdA),e.pure.u64(r.steammOracleIndexA),e.object(yt.SUI_CLOCK_OBJECT_ID)]}),s=e.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[e.object(r.steammOracleRegistryId),e.object(t.priceInfoObjectIdB),e.pure.u64(r.steammOracleIndexB),e.object(yt.SUI_CLOCK_OBJECT_ID)]}),a=[i,e.object(t.poolId),e.object(r.steamm_bank_a),e.object(r.steamm_bank_b),e.object(r.steamm_lending_market),n,s,e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::steamm_omm::${t.func}`,typeArguments:[r.steamm_lending_market_type,t.coinAType,t.coinBType,r.steamm_btoken_a_type,r.steamm_btoken_b_type,r.steamm_lp_token_type],arguments:a})}},mh=class{constructor(e,t){if(e!==0)throw new Error("Steamm OMM V2 only supported on mainnet");this.pythPriceIDs=t,this.oraclePackageId="0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b"}swap(e,t,i,r){let n=t.path;if(!n.extendedDetails)throw new Error("Extended details not found for Steamm OMM V2");this.validateExtendedDetails(n.extendedDetails);let s=this.prepareSwapData(t);this.executeSwapContract(e,s,i)}validateExtendedDetails(e){let t=["steamm_bank_a","steamm_bank_b","steamm_lending_market","steamm_lending_market_type","steamm_btoken_a_type","steamm_btoken_b_type","steamm_lp_token_type","steamm_oracle_registry_id","steamm_oracle_index_a","steamm_oracle_index_b","steamm_oracle_pyth_price_seed_a","steamm_oracle_pyth_price_seed_b"];for(let i of t)if(e[i]==null)throw new Error(`Steamm OMM V2 ${i} not supported`)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Steamm OMM V2 not set publishedAt");let i=t.extendedDetails,{direction:r,from:n,target:s}=t,[a,c]=r?[n,s]:[s,n],p=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn,g=i.steamm_oracle_pyth_price_seed_a,v=i.steamm_oracle_pyth_price_seed_b;if(!g||!v)throw new Error("Steamm OMM V2 oracle price seeds not found");let y=this.pythPriceIDs.get(g),A=this.pythPriceIDs.get(v);if(!y||!A)throw new Error("Base price info object id or quote price info object id not found");return{coinAType:a,coinBType:c,direction:r,amountIn:p,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:i,priceInfoObjectIdA:y,priceInfoObjectIdB:A}}executeSwapContract(e,t,i){let r=t.extendedDetails,n=e.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[e.object(r.steamm_oracle_registry_id),e.object(t.priceInfoObjectIdA),e.pure.u64(r.steamm_oracle_index_a),e.object(yt.SUI_CLOCK_OBJECT_ID)]}),s=e.moveCall({target:`${this.oraclePackageId}::oracles::get_pyth_price`,typeArguments:[],arguments:[e.object(r.steamm_oracle_registry_id),e.object(t.priceInfoObjectIdB),e.pure.u64(r.steamm_oracle_index_b),e.object(yt.SUI_CLOCK_OBJECT_ID)]}),a=[i,e.object(t.poolId),e.object(r.steamm_bank_a),e.object(r.steamm_bank_b),e.object(r.steamm_lending_market),n,s,e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::steamm_omm_v2::swap`,typeArguments:[r.steamm_lending_market_type,t.coinAType,t.coinBType,r.steamm_btoken_a_type,r.steamm_btoken_b_type,r.steamm_lp_token_type],arguments:a})}},gh="0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI",_h="0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD",vh="0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH",wh=class{constructor(e,t){if(e!==0)throw new Error("Metastable only supported on mainnet");this.versionID="0x4696559327b35ff2ab26904e7426a1646312e9c836d5c6cff6709a5ccc30915c",this.pythPriceIDs=t}swap(e,t,i,r){let n=this.prepareSwapData(t),s=this.createDepositCap(e,n);this.executeSwapContract(e,n,i,s)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Metastable not set publishedAt");if(!t.extendedDetails)throw new Error("Extended details not found for Metastable");let{direction:i,from:r,target:n}=t,[s,a]=i?[r,n]:[n,r],[c,p]=i?["swap_a2b","create_deposit_cap"]:["swap_b2a","create_withdraw_cap"];if(!t.extendedDetails.metastable_create_cap_pkg_id||!t.extendedDetails.metastable_create_cap_module||!t.extendedDetails.metastable_whitelisted_app_id)throw new Error("CreateCapPkgId or CreateCapModule or WhitelistedAppId not found in extended details");let g=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinType:s,metaCoinType:a,func:c,createCapFunc:p,direction:i,amountIn:g,publishedAt:t.publishedAt,poolId:t.id,extendedDetails:t.extendedDetails}}createDepositCap(e,t){let i=[t.metaCoinType];t.extendedDetails.metastable_create_cap_all_type_params&&i.push(t.coinType);let r=[e.object(t.extendedDetails.metastable_whitelisted_app_id),e.object(t.poolId)];switch(t.metaCoinType){case gh:{if(!t.extendedDetails.metastable_registry_id)throw new Error("Not found registry id for super sui");r.push(e.object(t.extendedDetails.metastable_registry_id));break}case _h:case vh:{if(t.extendedDetails.metastable_price_seed!=null){let n=this.pythPriceIDs.get(t.extendedDetails.metastable_price_seed);if(n==null)throw new Error("Invalid Pyth price feed: "+t.extendedDetails.metastable_price_seed);r.push(e.object(n))}if(t.extendedDetails.metastable_eth_price_seed!=null){let n=this.pythPriceIDs.get(t.extendedDetails.metastable_eth_price_seed);if(n==null)throw new Error("Invalid Pyth price feed: "+t.extendedDetails.metastable_eth_price_seed);r.push(e.object(n))}r.push(e.object(yt.SUI_CLOCK_OBJECT_ID));break}default:throw new Error("Invalid Metacoin: "+t.metaCoinType)}return e.moveCall({target:`${t.extendedDetails.metastable_create_cap_pkg_id}::${t.extendedDetails.metastable_create_cap_module}::${t.createCapFunc}`,typeArguments:i,arguments:r})}executeSwapContract(e,t,i,r){let n=[i,e.object(t.poolId),e.object(this.versionID),r,e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::metastable::${t.func}`,typeArguments:[t.coinType,t.metaCoinType],arguments:n})}},bh=class{constructor(e){if(e!==0)throw new Error("Alphafi only supported on mainnet");this.suiSystemState="0x0000000000000000000000000000000000000000000000000000000000000005"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("Alphafi not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(this.suiSystemState),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::alphafi::swap`,typeArguments:[t.coinBType],arguments:r})}},yh=class{constructor(e){if(e!==0)throw new Error("Volo only supported on mainnet");this.stakePool="0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",this.metadata="0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Volo not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.stakePool),e.object(this.metadata),e.object("0x5"),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::volo::swap`,typeArguments:[],arguments:r})}},Mh=class{constructor(e){if(e!==0)throw new Error("afSUI only supported on mainnet");this.stakedSuiVault="0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",this.safe="0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",this.referVault="0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",this.validator="0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){if(e.path.publishedAt==null)throw new Error("AFSUI not set publishedAt");let t=e.path,[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){if(!t.direction)throw new Error("AFSUI not support b2a swap");let r=[i,e.object(this.stakedSuiVault),e.object(this.safe),e.object("0x5"),e.object(this.referVault),e.object(this.validator),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::afsui::swap`,typeArguments:[],arguments:r})}},Ah=class{constructor(e){if(e!==0)throw new Error("Haedal only supported on mainnet")}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Haedal not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object("0x5"),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::hasui::swap`,typeArguments:[],arguments:r})}},Sh=class{constructor(e){if(e!==0)throw new Error("Hawal only supported on mainnet");this.staking="0x10b9d30c28448939ce6c4d6c6e0ffce4a7f8a4ada8248bdad09ef8b70e4a3904",this.validator="0x7b3ba6de2ae58283f60d5b8dc04bb9e90e4796b3b2e0dea75569f491275242e7"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Hawal not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.staking),e.object(t.poolId),e.object(this.validator),e.pure.bool(t.direction),e.pure.u64(t.amountIn)];e.moveCall({target:`${t.publishedAt}::hawal::swap`,typeArguments:[],arguments:r})}},Ch=ot.DEFAULT_PUBLISHED_AT.Mainnet;function Br(e,t){return e&&e.has(Nr.AGGREGATOR_V3)?e.get(Nr.AGGREGATOR_V3):t||Ch}function _a(e,t){let{quoteID:i,fromCoinType:r,targetCoinType:n,expectAmountOut:s,amountOutLimit:a,inputCoin:c,feeRate:p,feeRecipient:g,aggregatorPublishedAt:v,packages:y}=e,A=Br(y,v),k=[t.pure.string(i),t.pure.u64(s.toString()),t.pure.u64(a.toString()),c,t.pure.u32(Number(p.toString())),t.pure.address(g)];return t.moveCall({target:`${A}::router::new_swap_context`,typeArguments:[r,n],arguments:k})}function va(e,t){let{swapContext:i,targetCoinType:r,aggregatorPublishedAt:n,packages:s}=e,a=Br(s,n);return t.moveCall({target:`${a}::router::confirm_swap`,typeArguments:[r],arguments:[i]})}function Eh(e,t){let{coinType:i,amount:r,swapCtx:n,aggregatorPublishedAt:s,packages:a}=e,c=Br(a,s),p=[n,t.pure.u64(r.toString())];return t.moveCall({target:`${c}::router::take_balance`,typeArguments:[i],arguments:p})}function Ih(e,t){let{balance:i,coinType:r,recipient:n,aggregatorPublishedAt:s,packages:a}=e,c=Br(a,s),p=[i,t.pure.address(n)];t.moveCall({target:`${c}::router::transfer_balance`,typeArguments:[r],arguments:p})}function kh(e,t){let{coin:i,coinType:r,aggregatorPublishedAt:n,packages:s}=e,a=Br(s,n);t.moveCall({target:`${a}::router::transfer_or_destroy_coin`,typeArguments:[r],arguments:[i]})}function Th(){let t=Date.now().toString(16).padStart(12,"0"),i=t.substring(0,8),r=t.substring(8,12),n=Math.floor(Math.random()*16383).toString(16).padStart(4,"0"),s=Math.floor(Math.random()*0xffffffffffff).toString(16).padStart(12,"0"),c=(parseInt(i,16)&268435455|1610612736).toString(16).padStart(8,"0"),g=(parseInt(n,16)&16383|32768).toString(16).padStart(4,"0");return`downgrade_${[c,r,"6"+Math.floor(Math.random()*4095).toString(16).padStart(3,"0"),g,s].join("-")}`}function Oh(){let e=Date.now(),t=Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");return`downgrade_${e.toString(16)}_${t}`}function il(e){if(!e.startsWith("downgrade_"))return!1;let t=e.substring(10),i=/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,r=/^[0-9a-f]+_[0-9a-f]{6}$/i;return i.test(t)||r.test(t)}function Ph(e){if(!il(e))return null;let t=e.substring(10);if(t.includes("_")){let r=t.split("_");if(r.length===2){let n=parseInt(r[0],16);return isNaN(n)?null:n}}let i=t.split("-");if(i.length===5)try{let r=(parseInt(i[0],16)&268435455).toString(16).padStart(8,"0"),n=i[1],s=r+n,a=parseInt(s,16);return isNaN(a)?null:a}catch{return null}return null}function rl(e){return e.endsWith("/find_routes")?e.replace("/find_routes",""):e}function xh(e,t,i){return Nt(this,null,function*(){let r=yield Nh(t,i);return r!==null?{accountCap:e.object(r),isCreate:!1}:{accountCap:e.moveCall({target:`${Ua}::${Da}::create_account`,typeArguments:[],arguments:[]}),isCreate:!0}})}function Nh(e,t){return Nt(this,null,function*(){let i=50,r=null;for(;;){let n=e.getOwnedObjects({owner:t,cursor:r,limit:i,filter:{MoveModule:{package:Ba,module:Fa}}});if(n!=null&&n.data!=null){if(n.data.length!==0)return n.data[0].data.objectId;if(n.data.length<50)break}else break}return null})}function Rh(e,t){return t?.has("aggregator_v2")?t.get("aggregator_v2"):e||yn.V2.Mainnet}function Lh(e,t){return t?.has("aggregator_v2_extend")?t.get("aggregator_v2_extend"):e||yn.V2_EXTEND.Mainnet}function Fh(e,t){return t?.has("aggregator_v2_extend2")?t.get("aggregator_v2_extend2"):e||yn.V2_EXTEND2.Mainnet}var Kt=vr(wr());function Dh(e){let t=e.effects;if(!(t.status.status==="success"))return{computationCost:"0",storageCost:"0",storageRebate:"0",nonRefundableStorageFee:"0",totalGasCost:"0",gasUsed:"0",gasPrice:"0",success:!1,error:t.status.error||"Unknown error"};let r=t.gasUsed;return{computationCost:r.computationCost||"0",storageCost:r.storageCost||"0",storageRebate:r.storageRebate||"0",nonRefundableStorageFee:r.nonRefundableStorageFee||"0",totalGasCost:Bh(r),gasUsed:r.computationCost||"0",gasPrice:"1000",success:!0}}function Bh(e){let t=new Kt.default(e.computationCost||"0"),i=new Kt.default(e.storageCost||"0"),r=new Kt.default(e.storageRebate||"0"),n=new Kt.default(e.nonRefundableStorageFee||"0");return t.add(i).sub(r).add(n).toString()}function Uh(e,t){let i=new Kt.default(t);return i.isZero()?0:e.div(i).toNumber()}function jh(e,t,i=1){let r=e.mul(new Kt.default(Math.floor(i*1e6))).div(new Kt.default(1e6));return r.isZero()?0:r.sub(t).mul(new Kt.default(1e4)).div(r).toNumber()/100}function qh(e,t){let i=e.filter(c=>c.gasMetrics.success),r=t.filter(c=>c.gasMetrics.success),n=wa(i),s=wa(r),a=n.isZero()?0:n.sub(s).mul(new Kt.default(1e4)).div(n).toNumber()/100;return{v2:e,v3:t,summary:{v2AverageGas:n.toString(),v3AverageGas:s.toString(),gasSavingsPercent:a,v2SuccessRate:i.length/e.length*100,v3SuccessRate:r.length/t.length*100,totalTests:e.length+t.length}}}function wa(e){return e.length===0?new Kt.default(0):e.reduce((i,r)=>i.add(new Kt.default(r.gasMetrics.totalGasCost)),new Kt.default(0)).div(new Kt.default(e.length))}function $h(e,t){if(!e.success)return`\u274C Failed: ${e.error}`;let i=Number(e.totalGasCost),r=i/1e9,n=t?" (estimated)":"";return`\u2705 Gas: ${i.toString()} MIST (${r.toString()} SUI)${n}`}function Hh(e){return JSON.stringify(e,null,2)}function Gh(e){let i=[["Version","Provider","Success","AmountIn","AmountOut","TotalGasCost","ComputationCost","GasEfficiency","PriceImpact","OriginalPaths","MergedPaths","PathReduction%","Timestamp"].join(",")];return e.v2.forEach(r=>{let n=r.originalPathCount&&r.mergedPathCount?((r.originalPathCount-r.mergedPathCount)/r.originalPathCount*100).toFixed(1):"0";i.push(["V2",r.provider,r.gasMetrics.success,r.amountIn.toString(),r.amountOut.toString(),r.gasMetrics.totalGasCost,r.gasMetrics.computationCost,r.gasEfficiency.toString(),r.priceImpact.toString(),r.originalPathCount||0,r.mergedPathCount||0,n,r.timestamp.toString()].join(","))}),e.v3.forEach(r=>{let n=r.originalPathCount&&r.mergedPathCount?((r.originalPathCount-r.mergedPathCount)/r.originalPathCount*100).toFixed(1):"0";i.push(["V3",r.provider,r.gasMetrics.success,r.amountIn.toString(),r.amountOut.toString(),r.gasMetrics.totalGasCost,r.gasMetrics.computationCost,r.gasEfficiency.toString(),r.priceImpact.toString(),r.originalPathCount||0,r.mergedPathCount||0,n,r.timestamp.toString()].join(","))}),i.join(`
|
|
9
|
-
`)}var ba=vr(wr()),Vh=e=>{var t,i,r;return pn(xr({},e),{amountIn:(t=e?.amountIn)==null?void 0:t.toString(),amountOut:(i=e?.amountIn)==null?void 0:i.toString(),paths:(r=e?.paths)==null?void 0:r.map(s=>{var a,c,p,g,v,y;let A=pn(xr({},s),{amountIn:(a=s?.amountIn)==null?void 0:a.toString(),amountOut:(c=s?.amountOut)==null?void 0:c.toString()});return s?.initialPrice&&(A.initialPrice=(p=s?.initialPrice)==null?void 0:p.toString()),(g=s?.extendedDetails)!=null&&g.after_sqrt_price&&(A.extendedDetails={after_sqrt_price:(y=(v=s?.extendedDetails)==null?void 0:v.afterSqrtPrice)==null?void 0:y.toString()}),A})})},Zh=e=>{var t;return pn(xr({},e),{amountIn:new ba.default(e?.amountIn),amountOut:new ba.default(e?.amountIn),paths:(t=e?.paths)==null?void 0:t.map(r=>{var n,s,a,c;let p=xr({},r);return r?.initialPrice&&(p.initialPrice=new wn((n=r?.initialPrice)==null?void 0:n.toString())),(s=r?.extendedDetails)!=null&&s.after_sqrt_price&&(p.extendedDetails={after_sqrt_price:new wn((c=(a=r?.extendedDetails)==null?void 0:a.after_sqrt_price)==null?void 0:c.toString())}),p})})};function Kh(e,t=!0){return Nt(this,null,function*(){console.log("inputs",e.getData().inputs),e.getData().commands.forEach((i,r)=>{t&&console.log(`transaction ${r}: `,JSON.stringify(i,Wh,2))})})}function Wh(e,t){return typeof t=="bigint"?t.toString():t}function zh(e){return!(!e.startsWith("0x")||e.length!==66)}var Xh=class{constructor(e,t){if(e!==0)throw new Error("Haedal HMM V2 only supported on mainnet");this.pythPriceIDs=t}swap(e,t,i,r){let n=t.path;if(!n.extendedDetails)throw new Error("Extended details not found for Haedal HMM V2");console.log("path.extendedDetails",n.extendedDetails),this.validateExtendedDetails(n.extendedDetails);let s=this.prepareSwapData(t);this.executeSwapContract(e,s,i)}validateExtendedDetails(e){if(!e.haedalhmmv2_base_price_seed)throw new Error("Haedal HMM V2 base price seed not supported")}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Haedal HMM V2 not set publishedAt");let i=t.extendedDetails,[r,n]=t.direction?[t.from,t.target]:[t.target,t.from],s=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn,a=i.haedalhmmv2_base_price_seed,c=this.pythPriceIDs.get(a);if(!c)throw new Error("Haedal HMM V2 requires oracle price IDs for base coin");return{coinAType:r,coinBType:n,basePriceId:c,a2b:t.direction,amountIn:s,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(t.poolId),e.object(t.basePriceId),e.pure.u64(t.amountIn),e.pure.bool(t.a2b),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::haedal_hmm_v2::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},Jh=class{constructor(e){if(e!==0)throw new Error("Fullsail only supported on mainnet");this.globalConfig="0xe93baa80cb570b3a494cbf0621b2ba96bc993926d34dc92508c9446f9a05d615",this.vault="0xfb971d3a2fb98bde74e1c30ba15a3d8bef60a02789e59ae0b91660aeed3e64e1",this.stats="0x6822a33d1d971e040c32f7cc74507010d1fe786f7d06ab89135083ddb07d2dc2",this.price_provider="0x854b2d2c0381bb656ec962f8b443eb082654384cf97885359d1956c7d76e33c9"}swap(e,t,i,r){let n=this.prepareSwapData(t);this.executeSwapContract(e,n,i)}prepareSwapData(e){let t=e.path;if(e.path.publishedAt==null)throw new Error("Fullsail not set publishedAt");let[i,r]=t.direction?[t.from,t.target]:[t.target,t.from],n=e.isLastUseOfIntermediateToken?ot.MAX_AMOUNT_IN:t.amountIn;return{coinAType:i,coinBType:r,direction:t.direction,amountIn:n,publishedAt:t.publishedAt,poolId:t.id}}executeSwapContract(e,t,i){let r=[i,e.object(this.globalConfig),e.object(this.vault),e.object(this.stats),e.object(this.price_provider),e.object(t.poolId),e.pure.bool(t.direction),e.pure.u64(t.amountIn),e.object(yt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::fullsail::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},bn="CETUS",Yh="DEEPBOOK",Oo="KRIYA",Po="FLOWX",xo="FLOWXV3",No="KRIYAV3",Ro="TURBOS",Lo="AFTERMATH",Fo="HAEDAL",Do="VOLO",Bo="AFSUI",Uo="BLUEMOVE",jo="DEEPBOOKV3",qo="SCALLOP",$o="SUILEND",Ho="BLUEFIN",Cn="HAEDALPMM",Go="ALPHAFI",Vo="SPRINGSUI",Zo="STEAMM",En="METASTABLE",In="OBRIC",Ko="HAWAL",kn="STEAMM_OMM",Wo="MOMENTUM",Tn="STEAMM_OMM_V2",zo="MAGMA",On="SEVENK",Pn="HAEDALHMMV2",Xo="FULLSAIL",nl="https://api-sui.cetus.zone/router_v3",xn=[bn,Oo,Po,xo,No,Ro,Lo,Fo,Do,Bo,Uo,jo,qo,$o,Ho,Cn,Go,Vo,Zo,En,In,Ko,Wo,kn,Tn,zo,On,Pn,Xo];function Qh(){return xn}function ef(e){return xn.filter(t=>!e.includes(t))}function tf(e){return xn.filter(t=>e.includes(t))}function ya(e){let t=new Set;for(let i of e){if(i.provider===Cn&&i.extendedDetails&&i.extendedDetails.haedal_pmm_base_price_seed&&i.extendedDetails.haedal_pmm_quote_price_seed&&(t.add(i.extendedDetails.haedal_pmm_base_price_seed),t.add(i.extendedDetails.haedal_pmm_quote_price_seed)),i.provider===En&&(i.extendedDetails&&i.extendedDetails.metastable_price_seed&&t.add(i.extendedDetails.metastable_price_seed),i.extendedDetails&&i.extendedDetails.metastable_eth_price_seed&&t.add(i.extendedDetails.metastable_eth_price_seed)),i.provider===In&&(i.extendedDetails&&i.extendedDetails.obric_coin_a_price_seed&&t.add(i.extendedDetails.obric_coin_a_price_seed),i.extendedDetails&&i.extendedDetails.obric_coin_b_price_seed&&t.add(i.extendedDetails.obric_coin_b_price_seed)),(i.provider===kn||i.provider===Tn)&&(i.extendedDetails&&i.extendedDetails.steamm_oracle_pyth_price_seed_a&&t.add(i.extendedDetails.steamm_oracle_pyth_price_seed_a),i.extendedDetails&&i.extendedDetails.steamm_oracle_pyth_price_seed_b&&t.add(i.extendedDetails.steamm_oracle_pyth_price_seed_b)),i.provider===On&&i.extendedDetails){let r=i.extendedDetails;r.sevenk_coin_a_price_seed&&t.add(r.sevenk_coin_a_price_seed),r.sevenk_coin_b_price_seed&&t.add(r.sevenk_coin_b_price_seed)}i.provider===Pn&&i.extendedDetails&&i.extendedDetails.haedalhmmv2_base_price_seed&&t.add(i.extendedDetails.haedalhmmv2_base_price_seed)}return Array.from(t)}var ol=class sl{constructor(t){var i,r;this.endpoint=t.endpoint?rl(t.endpoint):nl,this.client=t.client||new sa.SuiClient({url:sa.getFullnodeUrl("mainnet")}),this.signer=t.signer||"",this.env=t.env||0;let n=sl.CONFIG[this.env];if(this.pythConnections=this.newPythClients((i=t.pythUrls)!=null?i:[]),this.pythClient=new aa.SuiPythClient(this.client,n.pythStateId,n.wormholeStateId),this.apiKey=t.apiKey||"",this.partner=t.partner,t.overlayFeeRate)if(t.overlayFeeRate>0&&t.overlayFeeRate<=Fi.MAX_OVERLAY_FEE_RATE){if(this.overlayFeeRate=t.overlayFeeRate*ot.FEE_DENOMINATOR,this.overlayFeeRate>ot.MAX_FEE_RATE)throw new Error(Fi.ERRORS.INVALID_OVERLAY_FEE_RATE)}else throw new Error(Fi.ERRORS.INVALID_OVERLAY_FEE_RATE);else this.overlayFeeRate=0;this.overlayFeeReceiver=(r=t.overlayFeeReceiver)!=null?r:Fi.DEFAULT_OVERLAY_FEE_RECEIVER}newPythClients(t){return t.includes("https://hermes.pyth.network")||t.push("https://hermes.pyth.network"),t.map(r=>new aa.SuiPriceServiceConnection(r,{timeout:3e3}))}deepbookv3DeepFeeType(){return this.env===0?Rr.Mainnet:Rr.Testnet}getOneCoinUsedToMerge(t){return Nt(this,null,function*(){try{let i=yield this.client.getCoins({owner:this.signer,coinType:t,limit:1});return i.data.length===1?i.data[0].coinObjectId:null}catch{return null}})}findRouters(t){return Nt(this,null,function*(){return $a(this.endpoint,this.apiKey,t,this.overlayFeeRate,this.overlayFeeReceiver)})}executeFlexibleInputSwap(t,i,r,n,s,a,c,p,g){return Nt(this,null,function*(){})}newDexRouterV3(t,i,r){switch(t){case bn:return new ma(this.env,r);case No:return new Yd(this.env);case xo:return new Qd(this.env);case Ro:return new eh(this.env);case Ho:return new th(this.env);case Wo:return new ih(this.env);case zo:return new rh(this.env);case Oo:return new nh(this.env);case Po:return new oh(this.env);case Uo:return new sh(this.env);case jo:return new ah(this.env);case Lo:return new lh(this.env);case Zo:return new uh(this.env);case qo:return new ch(this.env);case $o:return new ga(this.env);case Vo:return new ga(this.env);case Cn:return new dh(this.env,i);case In:return new hh(this.env,i);case On:return new fh(this.env,i);case kn:return new ph(this.env,i);case Tn:return new mh(this.env,i);case En:return new wh(this.env,i);case Go:return new bh(this.env);case Do:return new yh(this.env);case Bo:return new Mh(this.env);case Fo:return new Ah(this.env);case Ko:return new Sh(this.env);case Pn:return new Xh(this.env,i);case Xo:return new Jh(this.env);default:throw new Error(`${Fi.ERRORS.UNSUPPORTED_DEX} ${t}`)}}expectInputSwapV3(t,i,r,n,s,a,c){if(r.quoteID==null)throw new Error(Fi.ERRORS.QUOTE_ID_REQUIRED);let p=yo(r),g=_a({quoteID:p.quoteID,fromCoinType:p.fromCoinType,targetCoinType:p.targetCoinType,expectAmountOut:n,amountOutLimit:s,inputCoin:i,feeRate:this.overlayFeeRate,feeRecipient:this.overlayFeeReceiver,packages:p.packages},t),v=new Map;for(let A of p.flattenedPaths){let k=A.path;v.has(k.provider)||v.set(k.provider,this.newDexRouterV3(k.provider,a,c)),v.get(k.provider).swap(t,A,g,{pythPriceIDs:a})}return va({swapContext:g,targetCoinType:p.targetCoinType,packages:p.packages},t)}expectOutputSwapV3(t,i,r,n,s,a){let c=[],p=new ma(this.env,a),g=yo(r),v=_a({quoteID:g.quoteID,fromCoinType:g.fromCoinType,targetCoinType:g.targetCoinType,expectAmountOut:n,amountOutLimit:n,inputCoin:i,feeRate:this.overlayFeeRate,feeRecipient:this.overlayFeeReceiver,packages:g.packages},t),y=of(r.paths),A=new Map,k=new Map;for(let W=r.paths.length-1;W>=0;W--){let j=r.paths[W],K=y.get(j.from),X;if(W!==K||j.target===g.targetCoinType){if(j.target!==g.targetCoinType){let se=BigInt(j.amountOut);k.has(j.target)&&(se=k.get(j.target)+se),k.set(j.target,se)}X=t.pure.u64(j.amountOut.toString())}else{if(!A.has(j.target))throw Error("no need repay record");if(k.has(j.target)){let se=k.get(j.target),Y=A.get(j.target);X=p.sub(t,Y,t.pure.u64(se),j.publishedAt)}else X=A.get(j.target)}let Q=p.flashSwapFixedOutput(t,j,X,v);if(c.unshift(Q.flashReceipt),A.has(j.from)){let se=A.get(j.from);A.set(j.from,p.add(t,se,Q.repayAmount,j.publishedAt))}else A.set(j.from,Q.repayAmount)}for(let W=0;W<r.paths.length;W++){let j=r.paths[W];p.repayFlashSwapFixedOutput(t,j,v,c[W])}let U=Eh({coinType:g.fromCoinType,amount:mn,swapCtx:v,packages:g.packages},t);return Ih({balance:U,coinType:g.fromCoinType,recipient:this.signer,packages:g.packages},t),va({swapContext:v,targetCoinType:g.targetCoinType,packages:g.packages},t)}routerSwap(t){return Nt(this,null,function*(){let{router:i,inputCoin:r,slippage:n,txb:s,fixable:a,partner:c}=t;if(n>1||n<0)throw new Error(Fi.ERRORS.INVALID_SLIPPAGE);let p=t.router.byAmountIn,g=i.amountIn,v=i.amountOut,y=new St.default(0);this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(p?y=v.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)):y=g.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)));let A=p?v.sub(y):v,k=p?g:g.add(y),U=pa(p?A:k,p,n);if(!t.router.packages||!t.router.packages.get(Nr.AGGREGATOR_V3))throw new Error(Fi.ERRORS.PACKAGES_REQUIRED);let P=ya(i.paths),W=P.length>0?yield this.updatePythPriceIDs(P,s):new Map;return p?this.expectInputSwapV3(s,r,i,v.toString(),U.toString(),W,c??this.partner):this.expectOutputSwapV3(s,r,i,v.toString(),U.toString(),c??this.partner)})}fastRouterSwap(t){return Nt(this,null,function*(){let{router:i,slippage:r,txb:n,partner:s,payDeepFeeAmount:a}=t,c=i.paths[0].from,p=i.paths[i.paths.length-1].target,g=i.byAmountIn,v=0;this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(g?v=Number(i.amountOut.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)).toString()):v=Number(i.amountIn.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)).toString()));let y=g?i.amountOut.sub(new St.default(v)):i.amountOut,A=g?i.amountIn:i.amountIn.add(new St.default(v)),k=Jd(g?y:A,g,r),U=g?A:k,P=vo.coinWithBalance({balance:BigInt(U.toString()),useGasCoin:!0,type:c}),W;a&&a>0&&(W=vo.coinWithBalance({balance:BigInt(a),type:this.deepbookv3DeepFeeType()}));let j={router:i,inputCoin:P,slippage:r,txb:n,partner:s??this.partner,deepbookv3DeepFee:W},K=yield this.routerSwap(j);if(_i.isSuiCoin(p))n.mergeCoins(n.gas,[K]);else{let X=yield this.getOneCoinUsedToMerge(p);X!=null?n.mergeCoins(n.object(X),[K]):kh({coin:K,coinType:p,packages:i.packages},n)}})}fixableRouterSwapV3(t){return Nt(this,null,function*(){let{router:i,inputCoin:r,slippage:n,txb:s,deepbookv3DeepFee:a,partner:c}=t,p=0;this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(i.byAmountIn?p=Number(i.amountOut.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)).toString()):p=Number(i.amountIn.mul(new St.default(this.overlayFeeRate)).div(new St.default(1e6)).toString()));let g=i.byAmountIn?i.amountOut.sub(new St.default(p)):i.amountOut,v=i.byAmountIn?i.amountIn:i.amountIn.add(new St.default(p)),y=pa(i.byAmountIn?g:v,i.byAmountIn,n),A=ya(i.paths),k=A.length>0?yield this.updatePythPriceIDs(A,s):new Map;return i.byAmountIn?this.expectInputSwapV3(s,r,i,g.toString(),y.toString(),k,c??this.partner):this.expectOutputSwapV3(s,r,i,g.toString(),y.toString(),c??this.partner)})}swapInPools(t){return Nt(this,null,function*(){var i,r,n,s;let{from:a,target:c,amount:p,byAmountIn:g,pools:v}=t,y=Bi(a),A=Bi(c),k=new vo.Transaction,U=Ra(y,A),P=U?y:A,W=U?A:y,j=[P,W],K=this.env===0?"0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d":"0x4f920e1ef6318cfba77e20a0538a419a5a504c14230169438b99aba485db40a6";for(let l=0;l<v.length;l++){let d=[k.object(v[l]),k.pure.bool(U),k.pure.bool(g),k.pure.u64(p.toString())];k.moveCall({target:`${K}::fetcher_script::calculate_swap_result`,arguments:d,typeArguments:j})}this.signer||(this.signer="0x0");let X=yield this.client.devInspectTransactionBlock({transactionBlock:k,sender:this.signer});if(X.error!=null)throw new Error("Simulation error: "+X.error);let Q=(i=X.events)==null?void 0:i.filter(l=>l.type.includes("CalculatedSwapResultEvent"));if(Q.length===0||Q.length!==v.length)throw new Error("Simulate event result error");let se=g?new St.default(0):new St.default(mn),Y=0;for(let l=0;l<Q.length;l+=1)if(!Q[l].parsedJson.data.is_exceed)if(t.byAmountIn){let d=new St.default(Q[l].parsedJson.data.amount_out);d.gt(se)&&(Y=l,se=d)}else{let d=new St.default(Q[l].parsedJson.data.amount_out);d.lt(se)&&(Y=l,se=d)}let le=Q[Y].parsedJson.data,[E,I]=yield Promise.all([this.client.getCoinMetadata({coinType:P}).then(l=>l?.decimals),this.client.getCoinMetadata({coinType:W}).then(l=>l?.decimals)]);if(E==null||I==null)throw new Error("Cannot get coin decimals");let O=Number(le.fee_rate)/1e6,R=new St.default((r=le.amount_in)!=null?r:0),N=new St.default((n=le.fee_amount)!=null?n:0),S=R.add(N),h={amountIn:S,amountOut:new St.default((s=le.amount_out)!=null?s:0),paths:[{id:v[Y],direction:U,provider:bn,from:y,target:A,feeRate:O,amountIn:S.toString(),amountOut:le.amount_out,publishedAt:ja,extendedDetails:{afterSqrtPrice:le.after_sqrt_price}}],insufficientLiquidity:!1,byAmountIn:t.byAmountIn,quoteID:`degraded-${nf()}`,packages:new Map([[Nr.AGGREGATOR_V3,ot.DEFAULT_PUBLISHED_AT.Mainnet]])};return{isExceed:le.is_exceed,routeData:h}})}updatePythPriceIDs(t,i){return Nt(this,null,function*(){let r=null,n=null;for(let c of this.pythConnections)try{r=yield c.getPriceFeedsUpdateData(t);break}catch(p){n=p,console.log("Error: ",p);continue}if(r==null)throw new Error(`All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes. Detailed error: ${n?.message}`);let s=[];try{s=yield this.pythClient.updatePriceFeeds(i,r,t)}catch(c){throw new Error(`All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes in the pythUrls parameter when initializing AggregatorClient, for example: new AggregatorClient({ pythUrls: ["https://your-pyth-node-url"] }). Detailed error: ${c}`)}let a=new Map;for(let c=0;c<t.length;c++)a.set(t[c],s[c]);return a})}devInspectTransactionBlock(t){return Nt(this,null,function*(){return yield this.client.devInspectTransactionBlock({transactionBlock:t,sender:this.signer})})}sendTransaction(t,i){return Nt(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:t,signer:i})})}};ol.CONFIG={1:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},0:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}};var rf=ol;function nf(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function of(e){let t=new Map;for(let i=0;i<e.length;i++)t.has(e[i].from)||t.set(e[i].from,i);return t}var sf=e=>{if(typeof e=="string"&&e.startsWith("0x"))return"object";if(typeof e=="number"||typeof e=="bigint")return"u64";if(typeof e=="boolean")return"bool";throw new AggregateError(`Unknown type for value: ${e}`,"InvalidType")};J.AFSUI=Bo;J.AFTERMATH=Lo;J.AFTERMATH_AMM=ec;J.AFTERMATH_MODULE=cc;J.AGGREGATOR=W0;J.AGGREGATOR_V3_CONFIG=ot;J.ALL_DEXES=xn;J.ALPHAFI=Go;J.AggregatorClient=rf;J.AggregatorConfig=id;J.AggregatorError=S0;J.AggregatorServerErrorCode=Ia;J.BLUEFIN=Ho;J.BLUEMOVE=Uo;J.CETUS=bn;J.CETUS_DEX=z0;J.CETUS_MODULE=ic;J.CETUS_PUBLISHED_AT=Nc;J.CETUS_V3_PUBLISHED_AT=ja;J.CHECK_COINS_THRESHOLD_FUNC=Ec;J.CLIENT_CONFIG=Fi;J.CLOCK_ADDRESS=Tc;J.CoinInfoAddress=Oc;J.CoinStoreAddress=Pc;J.CoinUtils=_i;J.ConfigErrorCode=Ca;J.DEEPBOOKV2=Yh;J.DEEPBOOKV3=jo;J.DEEPBOOK_CLOB_V2_MODULE=Da;J.DEEPBOOK_CUSTODIAN_V2_MODULE=Fa;J.DEEPBOOK_DEX=X0;J.DEEPBOOK_MODULE=rc;J.DEEPBOOK_PACKAGE_ID=Ba;J.DEEPBOOK_PUBLISHED_AT=Ua;J.DEEPBOOK_V3_DEEP_FEE_TYPES=Rr;J.DEFAULT_AGG_V2_ENDPOINT=Xc;J.DEFAULT_AGG_V3_ENDPOINT=zc;J.DEFAULT_ENDPOINT=nl;J.DEFAULT_GAS_BUDGET_FOR_MERGE=R0;J.DEFAULT_GAS_BUDGET_FOR_SPLIT=N0;J.DEFAULT_GAS_BUDGET_FOR_STAKE=D0;J.DEFAULT_GAS_BUDGET_FOR_TRANSFER=L0;J.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI=F0;J.DEFAULT_NFT_TRANSFER_GAS_FEE=U0;J.Env=Ha;J.FLOWXV2=Po;J.FLOWXV3=xo;J.FLOWX_AMM=Y0;J.FLOWX_AMM_MODULE=lc;J.FULLSAIL=Xo;J.FlashSwapA2BFunc=mc;J.FlashSwapB2AFunc=gc;J.FlashSwapFunc=dc;J.FlashSwapWithPartnerA2BFunc=_c;J.FlashSwapWithPartnerB2AFunc=vc;J.FlashSwapWithPartnerFunc=hc;J.GAS_SYMBOL=B0;J.GAS_TYPE_ARG=ko;J.GAS_TYPE_ARG_LONG=xa;J.HAEDAL=Fo;J.HAEDALHMMV2=Pn;J.HAEDALPMM=Cn;J.HAWAL=Ko;J.INTEGRATE=tc;J.JOIN_FUNC=Ic;J.KRIYA=Oo;J.KRIYAV3=No;J.KRIYA_DEX=J0;J.KRIYA_MODULE=nc;J.MAGMA=zo;J.MAINNET_AFTERMATH_INSURANCE_FUND_ID=Vc;J.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=qc;J.MAINNET_AFTERMATH_REFERRAL_VAULT_ID=Kc;J.MAINNET_AFTERMATH_REGISTRY_ID=Uc;J.MAINNET_AFTERMATH_TREASURY_ID=Hc;J.MAINNET_CETUS_GLOBAL_CONFIG_ID=Rc;J.MAINNET_FLOWX_AMM_CONTAINER_ID=Fc;J.METASTABLE=En;J.MOMENTUM=Wo;J.OBRIC=In;J.ONE=G0;J.PACKAGE_NAMES=Nr;J.PAY_MODULE=ac;J.POOL_MODULT=sc;J.PUBLISHED_ADDRESSES=yn;J.PYTH_CONFIG=Jc;J.REPAY_FLASH_SWAP_A2B_FUNC=wc;J.REPAY_FLASH_SWAP_B2A_FUNC=bc;J.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC=yc;J.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC=Mc;J.RepayFalshSwapFunc=fc;J.RepayFlashSwapWithPartnerFunc=pc;J.SCALLOP=qo;J.SEVENK=On;J.SPRINGSUI=Vo;J.STEAMM=Zo;J.STEAMM_OMM=kn;J.STEAMM_OMM_V2=Tn;J.SUILEND=$o;J.SUI_SYSTEM_STATE_OBJECT_ID=j0;J.SWAP_A2B_FUNC=Ac;J.SWAP_B2A_FUNC=Sc;J.SuiZeroCoinFn=xc;J.TEN_POW_NINE=K0;J.TESTNET_AFTERMATH_INSURANCE_FUND_ID=Zc;J.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=$c;J.TESTNET_AFTERMATH_REFERRAL_VAULT_ID=Wc;J.TESTNET_AFTERMATH_REGISTRY_ID=jc;J.TESTNET_AFTERMATH_TREASURY_ID=Gc;J.TESTNET_CETUS_GLOBAL_CONFIG_ID=Lc;J.TESTNET_FLOWX_AMM_CONTAINER_ID=Dc;J.TRANSFER_ACCOUNT_CAP=kc;J.TRANSFER_OR_DESTORY_COIN_FUNC=Cc;J.TURBOS=Ro;J.TURBOS_DEX=Q0;J.TURBOS_MODULE=uc;J.TURBOS_VERSIONED=Bc;J.TWO=La;J.TransactionErrorCode=Ea;J.TypesErrorCode=Sa;J.U128=V0;J.U64_MAX=mn;J.U64_MAX_BN=Z0;J.UTILS_MODULE=oc;J.VOLO=Do;J.ZERO=sr;J.buildInputCoin=H0;J.calculateGasEfficiency=Uh;J.calculatePriceImpact=jh;J.checkInvalidSuiAddress=zh;J.compareCoins=Ra;J.compareGasMetrics=qh;J.completionCoin=Bi;J.composeType=wo;J.createTarget=O0;J.dealWithFastRouterSwapParamsForMsafe=Vh;J.exportToCSV=Gh;J.exportToJSON=Hh;J.extractAddressFromType=T0;J.extractGasMetrics=Dh;J.extractStructTagFromType=gr;J.extractTimestampFromDowngradeUuid6=Ph;J.fixSuiObjectId=Oa;J.formatGasMetrics=$h;J.generateDowngradeUuid6=Th;J.generateSimpleDowngradeUuid6=Oh;J.getAggregatorServerErrorMessage=hn;J.getAggregatorV2Extend2PublishedAt=Fh;J.getAggregatorV2ExtendPublishedAt=Lh;J.getAggregatorV2PublishedAt=Rh;J.getAllProviders=Qh;J.getDeepbookV3Config=td;J.getDefaultSuiInputType=sf;J.getOrCreateAccountCap=xh;J.getProvidersExcluding=ef;J.getProvidersIncluding=tf;J.getRouterResult=$a;J.isSortedSymbols=k0;J.isValidDowngradeUuid6=il;J.mintZeroCoin=Na;J.normalizeCoinType=bo;J.parseAftermathFeeType=$0;J.parseTurbosPoolFeeType=q0;J.patchFixSuiObjectId=Pa;J.printTransaction=Kh;J.processEndpoint=rl;J.processFlattenRoutes=yo;J.restituteMsafeFastRouterSwapParams=Zh});var tm={};du(tm,{CetusLeverageSDK:()=>Hr,default:()=>em,leverage_mainnet:()=>Qn});module.exports=hu(tm);var iu=require("@cetusprotocol/common-sdk");var Zr=require("@cetusprotocol/common-sdk");var Qn={full_rpc_url:Zr.FullRpcUrlMainnet,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:Zr.DefaultProviders,leverage:{package_id:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",published_at:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",version:0,config:{global_config_id:"0xf6c5da03798ff33dd4036aa1fe8b8321f8d41b279247abb5c01254e12b05c19b",markets_table_id:"0x2720d2dfe2b50f700edb69dabd8b51d611961521682a935f09c01d191000f8d0"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{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 Ts=require("@suilend/sdk/client"),At=require("@suilend/sdk");var fu=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,eo=Math.ceil,zt=Math.floor,Ht="[BigNumber Error] ",gs=Ht+"Number primitive has more than 15 significant digits: ",mi=1e14,Qe=14,to=9007199254740991,io=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Hi=1e7,Tt=1e9;function _s(e){var t,i,r,n=K.prototype={constructor:K,toString:null,valueOf:null},s=new K(1),a=20,c=4,p=-7,g=21,v=-1e7,y=1e7,A=!1,k=1,U=0,P={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},W="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function K(E,I){var O,R,N,S,h,o,l,d,m=this;if(!(m instanceof K))return new K(E,I);if(I==null){if(E&&E._isBigNumber===!0){m.s=E.s,!E.c||E.e>y?m.c=m.e=null:E.e<v?m.c=[m.e=0]:(m.e=E.e,m.c=E.c.slice());return}if((o=typeof E=="number")&&E*0==0){if(m.s=1/E<0?(E=-E,-1):1,E===~~E){for(S=0,h=E;h>=10;h/=10,S++);S>y?m.c=m.e=null:(m.e=S,m.c=[E]);return}d=String(E)}else{if(!fu.test(d=String(E)))return r(m,d,o);m.s=d.charCodeAt(0)==45?(d=d.slice(1),-1):1}(S=d.indexOf("."))>-1&&(d=d.replace(".","")),(h=d.search(/e/i))>0?(S<0&&(S=h),S+=+d.slice(h+1),d=d.substring(0,h)):S<0&&(S=d.length)}else{if(Ct(I,2,W.length,"Base"),I==10&&j)return m=new K(E),Y(m,a+m.e+1,c);if(d=String(E),o=typeof E=="number"){if(E*0!=0)return r(m,d,o,I);if(m.s=1/E<0?(d=d.slice(1),-1):1,K.DEBUG&&d.replace(/^0\.0*|\./,"").length>15)throw Error(gs+E)}else m.s=d.charCodeAt(0)===45?(d=d.slice(1),-1):1;for(O=W.slice(0,I),S=h=0,l=d.length;h<l;h++)if(O.indexOf(R=d.charAt(h))<0){if(R=="."){if(h>S){S=l;continue}}else if(!N&&(d==d.toUpperCase()&&(d=d.toLowerCase())||d==d.toLowerCase()&&(d=d.toUpperCase()))){N=!0,h=-1,S=0;continue}return r(m,String(E),o,I)}o=!1,d=i(d,I,10,m.s),(S=d.indexOf("."))>-1?d=d.replace(".",""):S=d.length}for(h=0;d.charCodeAt(h)===48;h++);for(l=d.length;d.charCodeAt(--l)===48;);if(d=d.slice(h,++l)){if(l-=h,o&&K.DEBUG&&l>15&&(E>to||E!==zt(E)))throw Error(gs+m.s*E);if((S=S-h-1)>y)m.c=m.e=null;else if(S<v)m.c=[m.e=0];else{if(m.e=S,m.c=[],h=(S+1)%Qe,S<0&&(h+=Qe),h<l){for(h&&m.c.push(+d.slice(0,h)),l-=Qe;h<l;)m.c.push(+d.slice(h,h+=Qe));h=Qe-(d=d.slice(h)).length}else h-=l;for(;h--;d+="0");m.c.push(+d)}}else m.c=[m.e=0]}K.clone=_s,K.ROUND_UP=0,K.ROUND_DOWN=1,K.ROUND_CEIL=2,K.ROUND_FLOOR=3,K.ROUND_HALF_UP=4,K.ROUND_HALF_DOWN=5,K.ROUND_HALF_EVEN=6,K.ROUND_HALF_CEIL=7,K.ROUND_HALF_FLOOR=8,K.EUCLID=9,K.config=K.set=function(E){var I,O;if(E!=null)if(typeof E=="object"){if(E.hasOwnProperty(I="DECIMAL_PLACES")&&(O=E[I],Ct(O,0,Tt,I),a=O),E.hasOwnProperty(I="ROUNDING_MODE")&&(O=E[I],Ct(O,0,8,I),c=O),E.hasOwnProperty(I="EXPONENTIAL_AT")&&(O=E[I],O&&O.pop?(Ct(O[0],-Tt,0,I),Ct(O[1],0,Tt,I),p=O[0],g=O[1]):(Ct(O,-Tt,Tt,I),p=-(g=O<0?-O:O))),E.hasOwnProperty(I="RANGE"))if(O=E[I],O&&O.pop)Ct(O[0],-Tt,-1,I),Ct(O[1],1,Tt,I),v=O[0],y=O[1];else if(Ct(O,-Tt,Tt,I),O)v=-(y=O<0?-O:O);else throw Error(Ht+I+" cannot be zero: "+O);if(E.hasOwnProperty(I="CRYPTO"))if(O=E[I],O===!!O)if(O)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))A=O;else throw A=!O,Error(Ht+"crypto unavailable");else A=O;else throw Error(Ht+I+" not true or false: "+O);if(E.hasOwnProperty(I="MODULO_MODE")&&(O=E[I],Ct(O,0,9,I),k=O),E.hasOwnProperty(I="POW_PRECISION")&&(O=E[I],Ct(O,0,Tt,I),U=O),E.hasOwnProperty(I="FORMAT"))if(O=E[I],typeof O=="object")P=O;else throw Error(Ht+I+" not an object: "+O);if(E.hasOwnProperty(I="ALPHABET"))if(O=E[I],typeof O=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(O))j=O.slice(0,10)=="0123456789",W=O;else throw Error(Ht+I+" invalid: "+O)}else throw Error(Ht+"Object expected: "+E);return{DECIMAL_PLACES:a,ROUNDING_MODE:c,EXPONENTIAL_AT:[p,g],RANGE:[v,y],CRYPTO:A,MODULO_MODE:k,POW_PRECISION:U,FORMAT:P,ALPHABET:W}},K.isBigNumber=function(E){if(!E||E._isBigNumber!==!0)return!1;if(!K.DEBUG)return!0;var I,O,R=E.c,N=E.e,S=E.s;e:if({}.toString.call(R)=="[object Array]"){if((S===1||S===-1)&&N>=-Tt&&N<=Tt&&N===zt(N)){if(R[0]===0){if(N===0&&R.length===1)return!0;break e}if(I=(N+1)%Qe,I<1&&(I+=Qe),String(R[0]).length==I){for(I=0;I<R.length;I++)if(O=R[I],O<0||O>=mi||O!==zt(O))break e;if(O!==0)return!0}}}else if(R===null&&N===null&&(S===null||S===1||S===-1))return!0;throw Error(Ht+"Invalid BigNumber: "+E)},K.maximum=K.max=function(){return Q(arguments,-1)},K.minimum=K.min=function(){return Q(arguments,1)},K.random=(function(){var E=9007199254740992,I=Math.random()*E&2097151?function(){return zt(Math.random()*E)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(O){var R,N,S,h,o,l=0,d=[],m=new K(s);if(O==null?O=a:Ct(O,0,Tt),h=eo(O/Qe),A)if(crypto.getRandomValues){for(R=crypto.getRandomValues(new Uint32Array(h*=2));l<h;)o=R[l]*131072+(R[l+1]>>>11),o>=9e15?(N=crypto.getRandomValues(new Uint32Array(2)),R[l]=N[0],R[l+1]=N[1]):(d.push(o%1e14),l+=2);l=h/2}else if(crypto.randomBytes){for(R=crypto.randomBytes(h*=7);l<h;)o=(R[l]&31)*281474976710656+R[l+1]*1099511627776+R[l+2]*4294967296+R[l+3]*16777216+(R[l+4]<<16)+(R[l+5]<<8)+R[l+6],o>=9e15?crypto.randomBytes(7).copy(R,l):(d.push(o%1e14),l+=7);l=h/7}else throw A=!1,Error(Ht+"crypto unavailable");if(!A)for(;l<h;)o=I(),o<9e15&&(d[l++]=o%1e14);for(h=d[--l],O%=Qe,h&&O&&(o=io[Qe-O],d[l]=zt(h/o)*o);d[l]===0;d.pop(),l--);if(l<0)d=[S=0];else{for(S=-1;d[0]===0;d.splice(0,1),S-=Qe);for(l=1,o=d[0];o>=10;o/=10,l++);l<Qe&&(S-=Qe-l)}return m.e=S,m.c=d,m}})(),K.sum=function(){for(var E=1,I=arguments,O=new K(I[0]);E<I.length;)O=O.plus(I[E++]);return O},i=(function(){var E="0123456789";function I(O,R,N,S){for(var h,o=[0],l,d=0,m=O.length;d<m;){for(l=o.length;l--;o[l]*=R);for(o[0]+=S.indexOf(O.charAt(d++)),h=0;h<o.length;h++)o[h]>N-1&&(o[h+1]==null&&(o[h+1]=0),o[h+1]+=o[h]/N|0,o[h]%=N)}return o.reverse()}return function(O,R,N,S,h){var o,l,d,m,_,b,w,f,u=O.indexOf("."),M=a,q=c;for(u>=0&&(m=U,U=0,O=O.replace(".",""),f=new K(R),b=f.pow(O.length-u),U=m,f.c=I(xi(Wt(b.c),b.e,"0"),10,N,E),f.e=f.c.length),w=I(O,R,N,h?(o=W,E):(o=E,W)),d=m=w.length;w[--m]==0;w.pop());if(!w[0])return o.charAt(0);if(u<0?--d:(b.c=w,b.e=d,b.s=S,b=t(b,f,M,q,N),w=b.c,_=b.r,d=b.e),l=d+M+1,u=w[l],m=N/2,_=_||l<0||w[l+1]!=null,_=q<4?(u!=null||_)&&(q==0||q==(b.s<0?3:2)):u>m||u==m&&(q==4||_||q==6&&w[l-1]&1||q==(b.s<0?8:7)),l<1||!w[0])O=_?xi(o.charAt(1),-M,o.charAt(0)):o.charAt(0);else{if(w.length=l,_)for(--N;++w[--l]>N;)w[l]=0,l||(++d,w=[1].concat(w));for(m=w.length;!w[--m];);for(u=0,O="";u<=m;O+=o.charAt(w[u++]));O=xi(O,d,o.charAt(0))}return O}})(),t=(function(){function E(R,N,S){var h,o,l,d,m=0,_=R.length,b=N%Hi,w=N/Hi|0;for(R=R.slice();_--;)l=R[_]%Hi,d=R[_]/Hi|0,h=w*l+d*b,o=b*l+h%Hi*Hi+m,m=(o/S|0)+(h/Hi|0)+w*d,R[_]=o%S;return m&&(R=[m].concat(R)),R}function I(R,N,S,h){var o,l;if(S!=h)l=S>h?1:-1;else for(o=l=0;o<S;o++)if(R[o]!=N[o]){l=R[o]>N[o]?1:-1;break}return l}function O(R,N,S,h){for(var o=0;S--;)R[S]-=o,o=R[S]<N[S]?1:0,R[S]=o*h+R[S]-N[S];for(;!R[0]&&R.length>1;R.splice(0,1));}return function(R,N,S,h,o){var l,d,m,_,b,w,f,u,M,q,$,z,ie,C,T,x,F,L=R.s==N.s?1:-1,G=R.c,B=N.c;if(!G||!G[0]||!B||!B[0])return new K(!R.s||!N.s||(G?B&&G[0]==B[0]:!B)?NaN:G&&G[0]==0||!B?L*0:L/0);for(u=new K(L),M=u.c=[],d=R.e-N.e,L=S+d+1,o||(o=mi,d=Xt(R.e/Qe)-Xt(N.e/Qe),L=L/Qe|0),m=0;B[m]==(G[m]||0);m++);if(B[m]>(G[m]||0)&&d--,L<0)M.push(1),_=!0;else{for(C=G.length,x=B.length,m=0,L+=2,b=zt(o/(B[0]+1)),b>1&&(B=E(B,b,o),G=E(G,b,o),x=B.length,C=G.length),ie=x,q=G.slice(0,x),$=q.length;$<x;q[$++]=0);F=B.slice(),F=[0].concat(F),T=B[0],B[1]>=o/2&&T++;do{if(b=0,l=I(B,q,x,$),l<0){if(z=q[0],x!=$&&(z=z*o+(q[1]||0)),b=zt(z/T),b>1)for(b>=o&&(b=o-1),w=E(B,b,o),f=w.length,$=q.length;I(w,q,f,$)==1;)b--,O(w,x<f?F:B,f,o),f=w.length,l=1;else b==0&&(l=b=1),w=B.slice(),f=w.length;if(f<$&&(w=[0].concat(w)),O(q,w,$,o),$=q.length,l==-1)for(;I(B,q,x,$)<1;)b++,O(q,x<$?F:B,$,o),$=q.length}else l===0&&(b++,q=[0]);M[m++]=b,q[0]?q[$++]=G[ie]||0:(q=[G[ie]],$=1)}while((ie++<C||q[0]!=null)&&L--);_=q[0]!=null,M[0]||M.splice(0,1)}if(o==mi){for(m=1,L=M[0];L>=10;L/=10,m++);Y(u,S+(u.e=m+d*Qe-1)+1,h,_)}else u.e=d,u.r=+_;return u}})();function X(E,I,O,R){var N,S,h,o,l;if(O==null?O=c:Ct(O,0,8),!E.c)return E.toString();if(N=E.c[0],h=E.e,I==null)l=Wt(E.c),l=R==1||R==2&&(h<=p||h>=g)?Wr(l,h):xi(l,h,"0");else if(E=Y(new K(E),I,O),S=E.e,l=Wt(E.c),o=l.length,R==1||R==2&&(I<=S||S<=p)){for(;o<I;l+="0",o++);l=Wr(l,S)}else if(I-=h+(R===2&&S>h),l=xi(l,S,"0"),S+1>o){if(--I>0)for(l+=".";I--;l+="0");}else if(I+=S-o,I>0)for(S+1==o&&(l+=".");I--;l+="0");return E.s<0&&N?"-"+l:l}function Q(E,I){for(var O,R,N=1,S=new K(E[0]);N<E.length;N++)R=new K(E[N]),(!R.s||(O=or(S,R))===I||O===0&&S.s===I)&&(S=R);return S}function se(E,I,O){for(var R=1,N=I.length;!I[--N];I.pop());for(N=I[0];N>=10;N/=10,R++);return(O=R+O*Qe-1)>y?E.c=E.e=null:O<v?E.c=[E.e=0]:(E.e=O,E.c=I),E}r=(function(){var E=/^(-?)0([xbo])(?=\w[\w.]*$)/i,I=/^([^.]+)\.$/,O=/^\.([^.]+)$/,R=/^-?(Infinity|NaN)$/,N=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(S,h,o,l){var d,m=o?h:h.replace(N,"");if(R.test(m))S.s=isNaN(m)?null:m<0?-1:1;else{if(!o&&(m=m.replace(E,function(_,b,w){return d=(w=w.toLowerCase())=="x"?16:w=="b"?2:8,!l||l==d?b:_}),l&&(d=l,m=m.replace(I,"$1").replace(O,"0.$1")),h!=m))return new K(m,d);if(K.DEBUG)throw Error(Ht+"Not a"+(l?" base "+l:"")+" number: "+h);S.s=null}S.c=S.e=null}})();function Y(E,I,O,R){var N,S,h,o,l,d,m,_=E.c,b=io;if(_){e:{for(N=1,o=_[0];o>=10;o/=10,N++);if(S=I-N,S<0)S+=Qe,h=I,l=_[d=0],m=zt(l/b[N-h-1]%10);else if(d=eo((S+1)/Qe),d>=_.length)if(R){for(;_.length<=d;_.push(0));l=m=0,N=1,S%=Qe,h=S-Qe+1}else break e;else{for(l=o=_[d],N=1;o>=10;o/=10,N++);S%=Qe,h=S-Qe+N,m=h<0?0:zt(l/b[N-h-1]%10)}if(R=R||I<0||_[d+1]!=null||(h<0?l:l%b[N-h-1]),R=O<4?(m||R)&&(O==0||O==(E.s<0?3:2)):m>5||m==5&&(O==4||R||O==6&&(S>0?h>0?l/b[N-h]:0:_[d-1])%10&1||O==(E.s<0?8:7)),I<1||!_[0])return _.length=0,R?(I-=E.e+1,_[0]=b[(Qe-I%Qe)%Qe],E.e=-I||0):_[0]=E.e=0,E;if(S==0?(_.length=d,o=1,d--):(_.length=d+1,o=b[Qe-S],_[d]=h>0?zt(l/b[N-h]%b[h])*o:0),R)for(;;)if(d==0){for(S=1,h=_[0];h>=10;h/=10,S++);for(h=_[0]+=o,o=1;h>=10;h/=10,o++);S!=o&&(E.e++,_[0]==mi&&(_[0]=1));break}else{if(_[d]+=o,_[d]!=mi)break;_[d--]=0,o=1}for(S=_.length;_[--S]===0;_.pop());}E.e>y?E.c=E.e=null:E.e<v&&(E.c=[E.e=0])}return E}function le(E){var I,O=E.e;return O===null?E.toString():(I=Wt(E.c),I=O<=p||O>=g?Wr(I,O):xi(I,O,"0"),E.s<0?"-"+I:I)}return n.absoluteValue=n.abs=function(){var E=new K(this);return E.s<0&&(E.s=1),E},n.comparedTo=function(E,I){return or(this,new K(E,I))},n.decimalPlaces=n.dp=function(E,I){var O,R,N,S=this;if(E!=null)return Ct(E,0,Tt),I==null?I=c:Ct(I,0,8),Y(new K(S),E+S.e+1,I);if(!(O=S.c))return null;if(R=((N=O.length-1)-Xt(this.e/Qe))*Qe,N=O[N])for(;N%10==0;N/=10,R--);return R<0&&(R=0),R},n.dividedBy=n.div=function(E,I){return t(this,new K(E,I),a,c)},n.dividedToIntegerBy=n.idiv=function(E,I){return t(this,new K(E,I),0,1)},n.exponentiatedBy=n.pow=function(E,I){var O,R,N,S,h,o,l,d,m,_=this;if(E=new K(E),E.c&&!E.isInteger())throw Error(Ht+"Exponent not an integer: "+le(E));if(I!=null&&(I=new K(I)),o=E.e>14,!_.c||!_.c[0]||_.c[0]==1&&!_.e&&_.c.length==1||!E.c||!E.c[0])return m=new K(Math.pow(+le(_),o?E.s*(2-Kr(E)):+le(E))),I?m.mod(I):m;if(l=E.s<0,I){if(I.c?!I.c[0]:!I.s)return new K(NaN);R=!l&&_.isInteger()&&I.isInteger(),R&&(_=_.mod(I))}else{if(E.e>9&&(_.e>0||_.e<-1||(_.e==0?_.c[0]>1||o&&_.c[1]>=24e7:_.c[0]<8e13||o&&_.c[0]<=9999975e7)))return S=_.s<0&&Kr(E)?-0:0,_.e>-1&&(S=1/S),new K(l?1/S:S);U&&(S=eo(U/Qe+2))}for(o?(O=new K(.5),l&&(E.s=1),d=Kr(E)):(N=Math.abs(+le(E)),d=N%2),m=new K(s);;){if(d){if(m=m.times(_),!m.c)break;S?m.c.length>S&&(m.c.length=S):R&&(m=m.mod(I))}if(N){if(N=zt(N/2),N===0)break;d=N%2}else if(E=E.times(O),Y(E,E.e+1,1),E.e>14)d=Kr(E);else{if(N=+le(E),N===0)break;d=N%2}_=_.times(_),S?_.c&&_.c.length>S&&(_.c.length=S):R&&(_=_.mod(I))}return R?m:(l&&(m=s.div(m)),I?m.mod(I):S?Y(m,U,c,h):m)},n.integerValue=function(E){var I=new K(this);return E==null?E=c:Ct(E,0,8),Y(I,I.e+1,E)},n.isEqualTo=n.eq=function(E,I){return or(this,new K(E,I))===0},n.isFinite=function(){return!!this.c},n.isGreaterThan=n.gt=function(E,I){return or(this,new K(E,I))>0},n.isGreaterThanOrEqualTo=n.gte=function(E,I){return(I=or(this,new K(E,I)))===1||I===0},n.isInteger=function(){return!!this.c&&Xt(this.e/Qe)>this.c.length-2},n.isLessThan=n.lt=function(E,I){return or(this,new K(E,I))<0},n.isLessThanOrEqualTo=n.lte=function(E,I){return(I=or(this,new K(E,I)))===-1||I===0},n.isNaN=function(){return!this.s},n.isNegative=function(){return this.s<0},n.isPositive=function(){return this.s>0},n.isZero=function(){return!!this.c&&this.c[0]==0},n.minus=function(E,I){var O,R,N,S,h=this,o=h.s;if(E=new K(E,I),I=E.s,!o||!I)return new K(NaN);if(o!=I)return E.s=-I,h.plus(E);var l=h.e/Qe,d=E.e/Qe,m=h.c,_=E.c;if(!l||!d){if(!m||!_)return m?(E.s=-I,E):new K(_?h:NaN);if(!m[0]||!_[0])return _[0]?(E.s=-I,E):new K(m[0]?h:c==3?-0:0)}if(l=Xt(l),d=Xt(d),m=m.slice(),o=l-d){for((S=o<0)?(o=-o,N=m):(d=l,N=_),N.reverse(),I=o;I--;N.push(0));N.reverse()}else for(R=(S=(o=m.length)<(I=_.length))?o:I,o=I=0;I<R;I++)if(m[I]!=_[I]){S=m[I]<_[I];break}if(S&&(N=m,m=_,_=N,E.s=-E.s),I=(R=_.length)-(O=m.length),I>0)for(;I--;m[O++]=0);for(I=mi-1;R>o;){if(m[--R]<_[R]){for(O=R;O&&!m[--O];m[O]=I);--m[O],m[R]+=mi}m[R]-=_[R]}for(;m[0]==0;m.splice(0,1),--d);return m[0]?se(E,m,d):(E.s=c==3?-1:1,E.c=[E.e=0],E)},n.modulo=n.mod=function(E,I){var O,R,N=this;return E=new K(E,I),!N.c||!E.s||E.c&&!E.c[0]?new K(NaN):!E.c||N.c&&!N.c[0]?new K(N):(k==9?(R=E.s,E.s=1,O=t(N,E,0,3),E.s=R,O.s*=R):O=t(N,E,0,k),E=N.minus(O.times(E)),!E.c[0]&&k==1&&(E.s=N.s),E)},n.multipliedBy=n.times=function(E,I){var O,R,N,S,h,o,l,d,m,_,b,w,f,u,M,q=this,$=q.c,z=(E=new K(E,I)).c;if(!$||!z||!$[0]||!z[0])return!q.s||!E.s||$&&!$[0]&&!z||z&&!z[0]&&!$?E.c=E.e=E.s=null:(E.s*=q.s,!$||!z?E.c=E.e=null:(E.c=[0],E.e=0)),E;for(R=Xt(q.e/Qe)+Xt(E.e/Qe),E.s*=q.s,l=$.length,_=z.length,l<_&&(f=$,$=z,z=f,N=l,l=_,_=N),N=l+_,f=[];N--;f.push(0));for(u=mi,M=Hi,N=_;--N>=0;){for(O=0,b=z[N]%M,w=z[N]/M|0,h=l,S=N+h;S>N;)d=$[--h]%M,m=$[h]/M|0,o=w*d+m*b,d=b*d+o%M*M+f[S]+O,O=(d/u|0)+(o/M|0)+w*m,f[S--]=d%u;f[S]=O}return O?++R:f.splice(0,1),se(E,f,R)},n.negated=function(){var E=new K(this);return E.s=-E.s||null,E},n.plus=function(E,I){var O,R=this,N=R.s;if(E=new K(E,I),I=E.s,!N||!I)return new K(NaN);if(N!=I)return E.s=-I,R.minus(E);var S=R.e/Qe,h=E.e/Qe,o=R.c,l=E.c;if(!S||!h){if(!o||!l)return new K(N/0);if(!o[0]||!l[0])return l[0]?E:new K(o[0]?R:N*0)}if(S=Xt(S),h=Xt(h),o=o.slice(),N=S-h){for(N>0?(h=S,O=l):(N=-N,O=o),O.reverse();N--;O.push(0));O.reverse()}for(N=o.length,I=l.length,N-I<0&&(O=l,l=o,o=O,I=N),N=0;I;)N=(o[--I]=o[I]+l[I]+N)/mi|0,o[I]=mi===o[I]?0:o[I]%mi;return N&&(o=[N].concat(o),++h),se(E,o,h)},n.precision=n.sd=function(E,I){var O,R,N,S=this;if(E!=null&&E!==!!E)return Ct(E,1,Tt),I==null?I=c:Ct(I,0,8),Y(new K(S),E,I);if(!(O=S.c))return null;if(N=O.length-1,R=N*Qe+1,N=O[N]){for(;N%10==0;N/=10,R--);for(N=O[0];N>=10;N/=10,R++);}return E&&S.e+1>R&&(R=S.e+1),R},n.shiftedBy=function(E){return Ct(E,-to,to),this.times("1e"+E)},n.squareRoot=n.sqrt=function(){var E,I,O,R,N,S=this,h=S.c,o=S.s,l=S.e,d=a+4,m=new K("0.5");if(o!==1||!h||!h[0])return new K(!o||o<0&&(!h||h[0])?NaN:h?S:1/0);if(o=Math.sqrt(+le(S)),o==0||o==1/0?(I=Wt(h),(I.length+l)%2==0&&(I+="0"),o=Math.sqrt(+I),l=Xt((l+1)/2)-(l<0||l%2),o==1/0?I="5e"+l:(I=o.toExponential(),I=I.slice(0,I.indexOf("e")+1)+l),O=new K(I)):O=new K(o+""),O.c[0]){for(l=O.e,o=l+d,o<3&&(o=0);;)if(N=O,O=m.times(N.plus(t(S,N,d,1))),Wt(N.c).slice(0,o)===(I=Wt(O.c)).slice(0,o))if(O.e<l&&--o,I=I.slice(o-3,o+1),I=="9999"||!R&&I=="4999"){if(!R&&(Y(N,N.e+a+2,0),N.times(N).eq(S))){O=N;break}d+=4,o+=4,R=1}else{(!+I||!+I.slice(1)&&I.charAt(0)=="5")&&(Y(O,O.e+a+2,1),E=!O.times(O).eq(S));break}}return Y(O,O.e+a+1,c,E)},n.toExponential=function(E,I){return E!=null&&(Ct(E,0,Tt),E++),X(this,E,I,1)},n.toFixed=function(E,I){return E!=null&&(Ct(E,0,Tt),E=E+this.e+1),X(this,E,I)},n.toFormat=function(E,I,O){var R,N=this;if(O==null)E!=null&&I&&typeof I=="object"?(O=I,I=null):E&&typeof E=="object"?(O=E,E=I=null):O=P;else if(typeof O!="object")throw Error(Ht+"Argument not an object: "+O);if(R=N.toFixed(E,I),N.c){var S,h=R.split("."),o=+O.groupSize,l=+O.secondaryGroupSize,d=O.groupSeparator||"",m=h[0],_=h[1],b=N.s<0,w=b?m.slice(1):m,f=w.length;if(l&&(S=o,o=l,l=S,f-=S),o>0&&f>0){for(S=f%o||o,m=w.substr(0,S);S<f;S+=o)m+=d+w.substr(S,o);l>0&&(m+=d+w.slice(S)),b&&(m="-"+m)}R=_?m+(O.decimalSeparator||"")+((l=+O.fractionGroupSize)?_.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(O.fractionGroupSeparator||"")):_):m}return(O.prefix||"")+R+(O.suffix||"")},n.toFraction=function(E){var I,O,R,N,S,h,o,l,d,m,_,b,w=this,f=w.c;if(E!=null&&(o=new K(E),!o.isInteger()&&(o.c||o.s!==1)||o.lt(s)))throw Error(Ht+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+le(o));if(!f)return new K(w);for(I=new K(s),d=O=new K(s),R=l=new K(s),b=Wt(f),S=I.e=b.length-w.e-1,I.c[0]=io[(h=S%Qe)<0?Qe+h:h],E=!E||o.comparedTo(I)>0?S>0?I:d:o,h=y,y=1/0,o=new K(b),l.c[0]=0;m=t(o,I,0,1),N=O.plus(m.times(R)),N.comparedTo(E)!=1;)O=R,R=N,d=l.plus(m.times(N=d)),l=N,I=o.minus(m.times(N=I)),o=N;return N=t(E.minus(O),R,0,1),l=l.plus(N.times(d)),O=O.plus(N.times(R)),l.s=d.s=w.s,S=S*2,_=t(d,R,S,c).minus(w).abs().comparedTo(t(l,O,S,c).minus(w).abs())<1?[d,R]:[l,O],y=h,_},n.toNumber=function(){return+le(this)},n.toPrecision=function(E,I){return E!=null&&Ct(E,1,Tt),X(this,E,I,2)},n.toString=function(E){var I,O=this,R=O.s,N=O.e;return N===null?R?(I="Infinity",R<0&&(I="-"+I)):I="NaN":(E==null?I=N<=p||N>=g?Wr(Wt(O.c),N):xi(Wt(O.c),N,"0"):E===10&&j?(O=Y(new K(O),a+N+1,c),I=xi(Wt(O.c),O.e,"0")):(Ct(E,2,W.length,"Base"),I=i(xi(Wt(O.c),N,"0"),10,E,R,!0)),R<0&&O.c[0]&&(I="-"+I)),I},n.valueOf=n.toJSON=function(){return le(this)},n._isBigNumber=!0,n[Symbol.toStringTag]="BigNumber",n[Symbol.for("nodejs.util.inspect.custom")]=n.valueOf,e!=null&&K.set(e),K}function Xt(e){var t=e|0;return e>0||e===t?t:t-1}function Wt(e){for(var t,i,r=1,n=e.length,s=e[0]+"";r<n;){for(t=e[r++]+"",i=Qe-t.length;i--;t="0"+t);s+=t}for(n=s.length;s.charCodeAt(--n)===48;);return s.slice(0,n+1||1)}function or(e,t){var i,r,n=e.c,s=t.c,a=e.s,c=t.s,p=e.e,g=t.e;if(!a||!c)return null;if(i=n&&!n[0],r=s&&!s[0],i||r)return i?r?0:-c:a;if(a!=c)return a;if(i=a<0,r=p==g,!n||!s)return r?0:!n^i?1:-1;if(!r)return p>g^i?1:-1;for(c=(p=n.length)<(g=s.length)?p:g,a=0;a<c;a++)if(n[a]!=s[a])return n[a]>s[a]^i?1:-1;return p==g?0:p>g^i?1:-1}function Ct(e,t,i,r){if(e<t||e>i||e!==zt(e))throw Error(Ht+(r||"Argument")+(typeof e=="number"?e<t||e>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function Kr(e){var t=e.c.length-1;return Xt(e.e/Qe)==t&&e.c[t]%2!=0}function Wr(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function xi(e,t,i){var r,n;if(t<0){for(n=i+".";++t;n+=i);e=n+e}else if(r=e.length,++t>r){for(n=i,t-=r;--t;n+=i);e+=n}else t<r&&(e=e.slice(0,t)+"."+e.slice(t));return e}var pu=_s(),Mi=pu;var Ai=require("@suilend/sdk"),cr=require("@suilend/sui-fe");var vs=Vr(require("crypto")),Xr=new Uint8Array(256),zr=Xr.length;function ro(){return zr>Xr.length-16&&(vs.default.randomFillSync(Xr),zr=0),Xr.slice(zr,zr+=16)}var Pt=[];for(let e=0;e<256;++e)Pt.push((e+256).toString(16).slice(1));function ws(e,t=0){return Pt[e[t+0]]+Pt[e[t+1]]+Pt[e[t+2]]+Pt[e[t+3]]+"-"+Pt[e[t+4]]+Pt[e[t+5]]+"-"+Pt[e[t+6]]+Pt[e[t+7]]+"-"+Pt[e[t+8]]+Pt[e[t+9]]+"-"+Pt[e[t+10]]+Pt[e[t+11]]+Pt[e[t+12]]+Pt[e[t+13]]+Pt[e[t+14]]+Pt[e[t+15]]}var bs=Vr(require("crypto")),no={randomUUID:bs.default.randomUUID};function mu(e,t,i){if(no.randomUUID&&!t&&!e)return no.randomUUID();e=e||{};let r=e.random||(e.rng||ro)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){i=i||0;for(let n=0;n<16;++n)t[i+n]=r[n];return t}return ws(r)}var Jr=mu;var ys=require("@cetusprotocol/common-sdk"),oo=10n;function Ms(e){return e.depositedAmount.eq(0)?new Mi(0):e.borrowedAmount.div(e.depositedAmount).times(100)}function so(e){let t=Ms(e);if(!t.gt(100))return(0,Ai.linearlyInterpolate)(e.config.interestRate,"utilPercent","aprPercent",t)}function As(e){let t=Ms(e),i=so(e);if(!(i===void 0||t.gt(100)))return new Mi(t.div(100)).times(i.div(100)).times(1-e.config.spreadFeeBps/1e4).times(100)}function Ss(e,t,i,r){let{apiUrl:n}=(0,ys.getPackagerConfigs)(r.sdkOptions.suilend);e===Ai.Side.DEPOSIT&&([cr.NORMALIZED_flSUI_COINTYPE,cr.NORMALIZED_jugSUI_COINTYPE].includes(t.coinType)&&i.push({stats:{id:Jr(),isActive:!0,rewardIndex:-1,reserve:t,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${n}/partners/LiqAg.png`,perDay:new Mi(.036),side:Ai.Side.DEPOSIT},obligationClaims:{}}),t.coinType===cr.NORMALIZED_LBTC_COINTYPE&&i.push({stats:{id:Jr(),isActive:!0,rewardIndex:-1,reserve:t,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${n}/partners/Lombard Lux.png`,perDay:new Mi(0),side:Ai.Side.DEPOSIT},obligationClaims:{}}))}function Cs(e,t,i){return{...e,depositedAmount:t===Ai.Side.DEPOSIT?Mi.max(e.depositedAmount.plus(i),0):e.depositedAmount,borrowedAmount:t===Ai.Side.BORROW?Mi.max(e.borrowedAmount.plus(i),0):e.borrowedAmount}}function Es(e,t,i){let r=e===Ai.Side.DEPOSIT?t.depositedAmount:t.borrowedAmount,n=e===Ai.Side.DEPOSIT?i.depositedAmount:i.borrowedAmount,s=n.eq(0)?new Mi(-1):r.div(n);return{multiplier:s,isValid:!s.eq(-1)}}function Is(e,t,i,r){let n=e.map(a=>({...a,stats:{...a.stats,perDay:r?a.stats.perDay.times(i):void 0}})),s=t.map(a=>({...a,stats:{...a.stats,aprPercent:r?a.stats.aprPercent.times(i):void 0}}));return{newPerDayRewards:n,newAprRewards:s}}function ks(e,t){if(!oo)throw new Error("oraclePriceMultiplierDecimal is required");if(e===0n)throw new Error("Invalid oracle price");if(t<0n){let i=10n**(oo- -t);return e*i}return e/10n**(t+oo)}var Bt=require("@cetusprotocol/common-sdk"),Os=require("@mysten/sui/utils"),Yr=class{constructor(t){this.getSuiLendCoinInfo=(t,i)=>{let{allLendingMarketData:r,lstAprPercentMap:n}=this.lendingMarketCache??{};if(!r||!n)throw new Error("lendingMarketCache is not initialized");let s=Object.values(r??{})[0],a=s.lendingMarket.reserves.find(le=>le.coinType===t);if(!a)throw new Error("reserve not found");let c=this.obligationsCache?.[s.lendingMarket.id],p="borrow",g=c.rewardMap[a.token.coinType]?.[p]??[],v=(0,At.getFilteredRewards)(g);Ss(p,a,v,this.sdk);let y=(0,At.getStakingYieldAprPercent)(p,a.coinType,n),A=p===At.Side.DEPOSIT?a.depositAprPercent:a.borrowAprPercent,k=A,U=Cs(a,p,i);k=p===At.Side.DEPOSIT?As(U):so(U);let{multiplier:P,isValid:W}=Es(p,a,U),j=(0,At.getDedupedPerDayRewards)(v),K=(0,At.getDedupedAprRewards)(v),{newPerDayRewards:X,newAprRewards:Q}=Is(j,K,P,W),se=(0,At.getTotalAprPercent)(p,A,v,y),Y=k===void 0||Q.some(le=>le.stats.aprPercent===void 0)?void 0:(0,At.getTotalAprPercent)(p,k,Q,y);return{borrowLimit:a.config.borrowLimit.toString(),borrowedAmount:a.borrowedAmount.toString(),remainingBorrowLimit:(0,Bt.d)(a.config.borrowLimit.toString()).sub((0,Bt.d)(a.borrowedAmount.toString())).toString(),depositAprPercent:a.depositAprPercent.toString(),totalAprPercent:se.toString(),borrowInterest:A.toString(),stakingYieldAprPercent:y?.toString(),rewardAprPercent:K[0]?.stats.aprPercent?.toString()}};this.createObligation=async t=>{let{lendingMarketId:i,lendingMarketType:r}=(0,Bt.getPackagerConfigs)(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(i,r)).createObligation(t)};this.refreshReservePrices=async(t,i,r)=>{let{lendingMarketId:n,lendingMarketType:s}=(0,Bt.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),a=`${n}_${s}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let c=await this.suilendClientCache[a].pythClient.getPriceFeedObjectId(i);console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:322 ~ SuiLendModule ~ priceInfoObjectId:",c),this.suilendClientCache[a].pythConnection.getLatestPriceFeeds,this.suilendClientCache[a].refreshReservePrices(t,c,r)};this.getLatestPriceFeeds=async t=>{let{lendingMarketId:i,lendingMarketType:r}=(0,Bt.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),n=`${i}_${r}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let s=Array.from(new Set(t.map(p=>(0,Os.toHEX)(new Uint8Array(p.priceIdentifier.bytes))))),a=await this.suilendClientCache[n].pythConnection.getLatestPriceFeeds(s),c={};return a?.forEach((p,g)=>{let v=p.getPriceUnchecked(),y=t[g];if(v){let{price:A,expo:k}=v,U=(0,Bt.d)(A).mul((0,Bt.d)(10).pow((0,Bt.d)(k))).toString(),P={coin_type:y.coinType.name,price:U,oracle_price:0n,last_update_time:v.publishTime};P.oracle_price=ks(BigInt(A),BigInt(k)),c[y.coinType.name]=P,this.sdk.updateCache(`getLatestPrice_${P.coin_type}`,P)}}),c};this.getSuiLendReserveInfo=async(t,i)=>{let{lendingMarketId:r}=(0,Bt.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),{allLendingMarketData:n}=await this.getLendingMarketData(),s=n[r].reserveMap[t],a=n[r].reserveMap[i],c=n[r].refreshedRawReserves.filter(p=>p.coinType.name==(0,Bt.removeHexPrefix)(t)||p.coinType.name==(0,Bt.removeHexPrefix)(i));return{baseReserveArrayIndex:s.arrayIndex.toString(),quoteReserveArrayIndex:a.arrayIndex.toString(),reserve:c}};this.sdk=t}async getSuilendClient(t,i){let r=`${t}_${i}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[r]||(this.suilendClientCache[r]=await Ts.SuilendClient.initialize(t,i,this.sdk.FullClient,!0)),this.suilendClientCache[r]}async getLendingMarketData(t=!1){if(!t&&this.lendingMarketCache)return this.lendingMarketCache;let i=(0,Bt.getPackagerConfigs)(this.sdk.sdkOptions?.suilend)?.lendingMarket||[];if(!i.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[r,n]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(i.map(async a=>{let c=await this.getSuilendClient(a.id,a.type),{lendingMarket:p,coinMetadataMap:g,refreshedRawReserves:v,reserveMap:y,reserveCoinTypes:A,reserveCoinMetadataMap:k,rewardCoinTypes:U,activeRewardCoinTypes:P,rewardCoinMetadataMap:W}=await(0,At.initializeSuilend)(this.sdk.FullClient,c),{rewardPriceMap:j}=await(0,At.initializeSuilendRewards)(y,P);return[a.id,{suilendClient:c,lendingMarket:p,coinMetadataMap:g,refreshedRawReserves:v,reserveMap:y,reserveCoinTypes:A,reserveCoinMetadataMap:k,rewardPriceMap:j,rewardCoinTypes:U,activeRewardCoinTypes:P,rewardCoinMetadataMap:W}]}))))(),(async()=>{try{let s=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.apiUrl}/springsui/apy`),a=await s.json();if(s?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(a).map(([c,p])=>[c,new Mi(p)]))}catch(s){return console.error(s),{}}})()]);return this.lendingMarketCache={allLendingMarketData:r,lstAprPercentMap:n},this.lendingMarketCache}catch(r){throw console.log("\u{1F680} getLendingMarketData error:",r),r}}async getInitializeObligations(t,i=!1){if(!i&&this.obligationsCache)return this.obligationsCache;t||(t=await this.getLendingMarketData());let r={};for(let n of Object.values(t.allLendingMarketData)){let{obligationOwnerCaps:s,obligations:a}=await(0,At.initializeObligations)(this.sdk.FullClient,n.suilendClient,n.refreshedRawReserves,n.reserveMap,this.sdk.senderAddress),c=(0,At.formatRewards)(n.reserveMap,n.rewardCoinMetadataMap,n.rewardPriceMap,a);r[n.lendingMarket.id]={obligationOwnerCaps:s,obligations:a,rewardMap:c}}return this.obligationsCache=r,this.obligationsCache}async getSuiLendUserData(t,i=!1){let{lstAprPercentMap:r}=this.lendingMarketCache??{},n=this.obligationsCache??{},{lendingMarketId:s}=(0,Bt.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),a=n[s];if(!a)throw new Error(`No user data found for lending market: ${s}`);if(t){let c=a.obligations.find(g=>g.id===t);if(!c)throw new Error(`Obligation not found: ${t}`);let p=(0,At.getNetAprPercent)(c,a.rewardMap,r??{});return{obligation:c,netAprPercent:p,deposits:c.deposits,borrowedAmount:c.borrowedAmount,depositedAmount:c.depositedAmount,netValueUsd:c.netValueUsd,rewardMap:a.rewardMap}}}priceCheck(t,i=60){let r=Math.floor(Date.now()/1e3);if(!(Math.abs(r-t.last_update_time)>i))return t}};var ae=require("@cetusprotocol/common-sdk");var dr=9e15,Ki=1e9,ao="0123456789abcdef",tn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",rn="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",lo={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-dr,maxE:dr,crypto:!1},Rs,Ni,je=!0,on="[DecimalError] ",Zi=on+"Invalid argument: ",Ls=on+"Precision limit exceeded",Fs=on+"crypto unavailable",Ds="[object Decimal]",Ut=Math.floor,Et=Math.pow,gu=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,_u=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,vu=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Bs=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,gi=1e7,Le=7,wu=9007199254740991,bu=tn.length-1,uo=rn.length-1,re={toStringTag:Ds};re.absoluteValue=re.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Pe(e)};re.ceil=function(){return Pe(new this.constructor(this),this.e+1,2)};re.clampedTo=re.clamp=function(e,t){var i,r=this,n=r.constructor;if(e=new n(e),t=new n(t),!e.s||!t.s)return new n(NaN);if(e.gt(t))throw Error(Zi+t);return i=r.cmp(e),i<0?e:r.cmp(t)>0?t:new n(r)};re.comparedTo=re.cmp=function(e){var t,i,r,n,s=this,a=s.d,c=(e=new s.constructor(e)).d,p=s.s,g=e.s;if(!a||!c)return!p||!g?NaN:p!==g?p:a===c?0:!a^p<0?1:-1;if(!a[0]||!c[0])return a[0]?p:c[0]?-g:0;if(p!==g)return p;if(s.e!==e.e)return s.e>e.e^p<0?1:-1;for(r=a.length,n=c.length,t=0,i=r<n?r:n;t<i;++t)if(a[t]!==c[t])return a[t]>c[t]^p<0?1:-1;return r===n?0:r>n^p<0?1:-1};re.cosine=re.cos=function(){var e,t,i=this,r=i.constructor;return i.d?i.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+Le,r.rounding=1,i=yu(r,Hs(r,i)),r.precision=e,r.rounding=t,Pe(Ni==2||Ni==3?i.neg():i,e,t,!0)):new r(1):new r(NaN)};re.cubeRoot=re.cbrt=function(){var e,t,i,r,n,s,a,c,p,g,v=this,y=v.constructor;if(!v.isFinite()||v.isZero())return new y(v);for(je=!1,s=v.s*Et(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=xt(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=Et(i,1/3),e=Ut((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?i="5e"+e:(i=s.toExponential(),i=i.slice(0,i.indexOf("e")+1)+e),r=new y(i),r.s=v.s):r=new y(s.toString()),a=(e=y.precision)+3;;)if(c=r,p=c.times(c).times(c),g=p.plus(v),r=ut(g.plus(v).times(c),g.plus(p),a+2,1),xt(c.d).slice(0,a)===(i=xt(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(Pe(c,e+1,0),c.times(c).times(c).eq(v))){r=c;break}a+=4,n=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(Pe(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return je=!0,Pe(r,e,y.rounding,t)};re.decimalPlaces=re.dp=function(){var e,t=this.d,i=NaN;if(t){if(e=t.length-1,i=(e-Ut(this.e/Le))*Le,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};re.dividedBy=re.div=function(e){return ut(this,new this.constructor(e))};re.dividedToIntegerBy=re.divToInt=function(e){var t=this,i=t.constructor;return Pe(ut(t,new i(e),0,1,1),i.precision,i.rounding)};re.equals=re.eq=function(e){return this.cmp(e)===0};re.floor=function(){return Pe(new this.constructor(this),this.e+1,3)};re.greaterThan=re.gt=function(e){return this.cmp(e)>0};re.greaterThanOrEqualTo=re.gte=function(e){var t=this.cmp(e);return t==1||t===0};re.hyperbolicCosine=re.cosh=function(){var e,t,i,r,n,s=this,a=s.constructor,c=new a(1);if(!s.isFinite())return new a(s.s?1/0:NaN);if(s.isZero())return c;i=a.precision,r=a.rounding,a.precision=i+Math.max(s.e,s.sd())+4,a.rounding=1,n=s.d.length,n<32?(e=Math.ceil(n/3),t=(1/an(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=hr(a,1,s.times(t),new a(1),!0);for(var p,g=e,v=new a(8);g--;)p=s.times(s),s=c.minus(p.times(v.minus(p.times(v))));return Pe(s,a.precision=i,a.rounding=r,!0)};re.hyperbolicSine=re.sinh=function(){var e,t,i,r,n=this,s=n.constructor;if(!n.isFinite()||n.isZero())return new s(n);if(t=s.precision,i=s.rounding,s.precision=t+Math.max(n.e,n.sd())+4,s.rounding=1,r=n.d.length,r<3)n=hr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/an(5,e)),n=hr(s,2,n,n,!0);for(var a,c=new s(5),p=new s(16),g=new s(20);e--;)a=n.times(n),n=n.times(c.plus(a.times(p.times(a).plus(g))))}return s.precision=t,s.rounding=i,Pe(n,t,i,!0)};re.hyperbolicTangent=re.tanh=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,ut(i.sinh(),i.cosh(),r.precision=e,r.rounding=t)):new r(i.s)};re.inverseCosine=re.acos=function(){var e=this,t=e.constructor,i=e.abs().cmp(1),r=t.precision,n=t.rounding;return i!==-1?i===0?e.isNeg()?Si(t,r,n):new t(0):new t(NaN):e.isZero()?Si(t,r+4,n).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=n,e.times(2))};re.inverseHyperbolicCosine=re.acosh=function(){var e,t,i=this,r=i.constructor;return i.lte(1)?new r(i.eq(1)?0:NaN):i.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(i.e),i.sd())+4,r.rounding=1,je=!1,i=i.times(i).minus(1).sqrt().plus(i),je=!0,r.precision=e,r.rounding=t,i.ln()):new r(i)};re.inverseHyperbolicSine=re.asinh=function(){var e,t,i=this,r=i.constructor;return!i.isFinite()||i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(i.e),i.sd())+6,r.rounding=1,je=!1,i=i.times(i).plus(1).sqrt().plus(i),je=!0,r.precision=e,r.rounding=t,i.ln())};re.inverseHyperbolicTangent=re.atanh=function(){var e,t,i,r,n=this,s=n.constructor;return n.isFinite()?n.e>=0?new s(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(e=s.precision,t=s.rounding,r=n.sd(),Math.max(r,e)<2*-n.e-1?Pe(new s(n),e,t,!0):(s.precision=i=r-n.e,n=ut(n.plus(1),new s(1).minus(n),i+e,1),s.precision=e+4,s.rounding=1,n=n.ln(),s.precision=e,s.rounding=t,n.times(.5))):new s(NaN)};re.inverseSine=re.asin=function(){var e,t,i,r,n=this,s=n.constructor;return n.isZero()?new s(n):(t=n.abs().cmp(1),i=s.precision,r=s.rounding,t!==-1?t===0?(e=Si(s,i+4,r).times(.5),e.s=n.s,e):new s(NaN):(s.precision=i+6,s.rounding=1,n=n.div(new s(1).minus(n.times(n)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=r,n.times(2)))};re.inverseTangent=re.atan=function(){var e,t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding;if(g.isFinite()){if(g.isZero())return new v(g);if(g.abs().eq(1)&&y+4<=uo)return a=Si(v,y+4,A).times(.25),a.s=g.s,a}else{if(!g.s)return new v(NaN);if(y+4<=uo)return a=Si(v,y+4,A).times(.5),a.s=g.s,a}for(v.precision=c=y+10,v.rounding=1,i=Math.min(28,c/Le+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(je=!1,t=Math.ceil(c/Le),r=1,p=g.times(g),a=new v(g),n=g;e!==-1;)if(n=n.times(p),s=a.minus(n.div(r+=2)),n=n.times(p),a=s.plus(n.div(r+=2)),a.d[t]!==void 0)for(e=t;a.d[e]===s.d[e]&&e--;);return i&&(a=a.times(2<<i-1)),je=!0,Pe(a,v.precision=y,v.rounding=A,!0)};re.isFinite=function(){return!!this.d};re.isInteger=re.isInt=function(){return!!this.d&&Ut(this.e/Le)>this.d.length-2};re.isNaN=function(){return!this.s};re.isNegative=re.isNeg=function(){return this.s<0};re.isPositive=re.isPos=function(){return this.s>0};re.isZero=function(){return!!this.d&&this.d[0]===0};re.lessThan=re.lt=function(e){return this.cmp(e)<0};re.lessThanOrEqualTo=re.lte=function(e){return this.cmp(e)<1};re.logarithm=re.log=function(e){var t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding,k=5;if(e==null)e=new v(10),t=!0;else{if(e=new v(e),i=e.d,e.s<0||!i||!i[0]||e.eq(1))return new v(NaN);t=e.eq(10)}if(i=g.d,g.s<0||!i||!i[0]||g.eq(1))return new v(i&&!i[0]?-1/0:g.s!=1?NaN:i?0:1/0);if(t)if(i.length>1)s=!0;else{for(n=i[0];n%10===0;)n/=10;s=n!==1}if(je=!1,c=y+k,a=Vi(g,c),r=t?nn(v,c+10):Vi(e,c),p=ut(a,r,c,1),Or(p.d,n=y,A))do if(c+=10,a=Vi(g,c),r=t?nn(v,c+10):Vi(e,c),p=ut(a,r,c,1),!s){+xt(p.d).slice(n+1,n+15)+1==1e14&&(p=Pe(p,y+1,0));break}while(Or(p.d,n+=10,A));return je=!0,Pe(p,y,A)};re.minus=re.sub=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.constructor;if(e=new U(e),!k.d||!e.d)return!k.s||!e.s?e=new U(NaN):k.d?e.s=-e.s:e=new U(e.d||k.s!==e.s?k:NaN),e;if(k.s!=e.s)return e.s=-e.s,k.plus(e);if(g=k.d,A=e.d,c=U.precision,p=U.rounding,!g[0]||!A[0]){if(A[0])e.s=-e.s;else if(g[0])e=new U(k);else return new U(p===3?-0:0);return je?Pe(e,c,p):e}if(i=Ut(e.e/Le),v=Ut(k.e/Le),g=g.slice(),s=v-i,s){for(y=s<0,y?(t=g,s=-s,a=A.length):(t=A,i=v,a=g.length),r=Math.max(Math.ceil(c/Le),a)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=g.length,a=A.length,y=r<a,y&&(a=r),r=0;r<a;r++)if(g[r]!=A[r]){y=g[r]<A[r];break}s=0}for(y&&(t=g,g=A,A=t,e.s=-e.s),a=g.length,r=A.length-a;r>0;--r)g[a++]=0;for(r=A.length;r>s;){if(g[--r]<A[r]){for(n=r;n&&g[--n]===0;)g[n]=gi-1;--g[n],g[r]+=gi}g[r]-=A[r]}for(;g[--a]===0;)g.pop();for(;g[0]===0;g.shift())--i;return g[0]?(e.d=g,e.e=sn(g,i),je?Pe(e,c,p):e):new U(p===3?-0:0)};re.modulo=re.mod=function(e){var t,i=this,r=i.constructor;return e=new r(e),!i.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||i.d&&!i.d[0]?Pe(new r(i),r.precision,r.rounding):(je=!1,r.modulo==9?(t=ut(i,e.abs(),0,3,1),t.s*=e.s):t=ut(i,e,0,r.modulo,1),t=t.times(e),je=!0,i.minus(t))};re.naturalExponential=re.exp=function(){return co(this)};re.naturalLogarithm=re.ln=function(){return Vi(this)};re.negated=re.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Pe(e)};re.plus=re.add=function(e){var t,i,r,n,s,a,c,p,g,v,y=this,A=y.constructor;if(e=new A(e),!y.d||!e.d)return!y.s||!e.s?e=new A(NaN):y.d||(e=new A(e.d||y.s===e.s?y:NaN)),e;if(y.s!=e.s)return e.s=-e.s,y.minus(e);if(g=y.d,v=e.d,c=A.precision,p=A.rounding,!g[0]||!v[0])return v[0]||(e=new A(y)),je?Pe(e,c,p):e;if(s=Ut(y.e/Le),r=Ut(e.e/Le),g=g.slice(),n=s-r,n){for(n<0?(i=g,n=-n,a=v.length):(i=v,r=s,a=g.length),s=Math.ceil(c/Le),a=s>a?s+1:a+1,n>a&&(n=a,i.length=1),i.reverse();n--;)i.push(0);i.reverse()}for(a=g.length,n=v.length,a-n<0&&(n=a,i=v,v=g,g=i),t=0;n;)t=(g[--n]=g[n]+v[n]+t)/gi|0,g[n]%=gi;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=sn(g,r),je?Pe(e,c,p):e};re.precision=re.sd=function(e){var t,i=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Zi+e);return i.d?(t=Us(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};re.round=function(){var e=this,t=e.constructor;return Pe(new t(e),e.e+1,t.rounding)};re.sine=re.sin=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+Le,r.rounding=1,i=Au(r,Hs(r,i)),r.precision=e,r.rounding=t,Pe(Ni>2?i.neg():i,e,t,!0)):new r(NaN)};re.squareRoot=re.sqrt=function(){var e,t,i,r,n,s,a=this,c=a.d,p=a.e,g=a.s,v=a.constructor;if(g!==1||!c||!c[0])return new v(!g||g<0&&(!c||c[0])?NaN:c?a:1/0);for(je=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=xt(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=Ut((p+1)/2)-(p<0||p%2),g==1/0?t="5e"+p:(t=g.toExponential(),t=t.slice(0,t.indexOf("e")+1)+p),r=new v(t)):r=new v(g.toString()),i=(p=v.precision)+3;;)if(s=r,r=s.plus(ut(a,s,i+2,1)).times(.5),xt(s.d).slice(0,i)===(t=xt(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(Pe(s,p+1,0),s.times(s).eq(a))){r=s;break}i+=4,n=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(Pe(r,p+1,1),e=!r.times(r).eq(a));break}return je=!0,Pe(r,p,v.rounding,e)};re.tangent=re.tan=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,i=i.sin(),i.s=1,i=ut(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Pe(Ni==2||Ni==4?i.neg():i,e,t,!0)):new r(NaN)};re.times=re.mul=function(e){var t,i,r,n,s,a,c,p,g,v=this,y=v.constructor,A=v.d,k=(e=new y(e)).d;if(e.s*=v.s,!A||!A[0]||!k||!k[0])return new y(!e.s||A&&!A[0]&&!k||k&&!k[0]&&!A?NaN:!A||!k?e.s/0:e.s*0);for(i=Ut(v.e/Le)+Ut(e.e/Le),p=A.length,g=k.length,p<g&&(s=A,A=k,k=s,a=p,p=g,g=a),s=[],a=p+g,r=a;r--;)s.push(0);for(r=g;--r>=0;){for(t=0,n=p+r;n>r;)c=s[n]+k[r]*A[n-r-1]+t,s[n--]=c%gi|0,t=c/gi|0;s[n]=(s[n]+t)%gi|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=sn(s,i),je?Pe(e,y.precision,y.rounding):e};re.toBinary=function(e,t){return ho(this,2,e,t)};re.toDecimalPlaces=re.toDP=function(e,t){var i=this,r=i.constructor;return i=new r(i),e===void 0?i:(Gt(e,0,Ki),t===void 0?t=r.rounding:Gt(t,0,8),Pe(i,e+i.e+1,t))};re.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ci(r,!0):(Gt(e,0,Ki),t===void 0?t=n.rounding:Gt(t,0,8),r=Pe(new n(r),e+1,t),i=Ci(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+i:i};re.toFixed=function(e,t){var i,r,n=this,s=n.constructor;return e===void 0?i=Ci(n):(Gt(e,0,Ki),t===void 0?t=s.rounding:Gt(t,0,8),r=Pe(new s(n),e+n.e+1,t),i=Ci(r,!1,e+r.e+1)),n.isNeg()&&!n.isZero()?"-"+i:i};re.toFraction=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.d,P=k.constructor;if(!U)return new P(k);if(g=i=new P(1),r=p=new P(0),t=new P(r),s=t.e=Us(U)-k.e-1,a=s%Le,t.d[0]=Et(10,a<0?Le+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(Zi+c);e=c.gt(t)?s>0?t:g:c}for(je=!1,c=new P(xt(U)),v=P.precision,P.precision=s=U.length*Le*2;y=ut(c,t,0,1,1),n=i.plus(y.times(r)),n.cmp(e)!=1;)i=r,r=n,n=g,g=p.plus(y.times(n)),p=n,n=t,t=c.minus(y.times(n)),c=n;return n=ut(e.minus(i),r,0,1,1),p=p.plus(n.times(g)),i=i.plus(n.times(r)),p.s=g.s=k.s,A=ut(g,r,s,1).minus(k).abs().cmp(ut(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,je=!0,A};re.toHexadecimal=re.toHex=function(e,t){return ho(this,16,e,t)};re.toNearest=function(e,t){var i=this,r=i.constructor;if(i=new r(i),e==null){if(!i.d)return i;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Gt(t,0,8),!i.d)return e.s?i:e;if(!e.d)return e.s&&(e.s=i.s),e}return e.d[0]?(je=!1,i=ut(i,e,0,t,1).times(e),je=!0,Pe(i)):(e.s=i.s,i=e),i};re.toNumber=function(){return+this};re.toOctal=function(e,t){return ho(this,8,e,t)};re.toPower=re.pow=function(e){var t,i,r,n,s,a,c=this,p=c.constructor,g=+(e=new p(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new p(Et(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return Pe(c,r,s);if(t=Ut(e.e/Le),t>=e.d.length-1&&(i=g<0?-g:g)<=wu)return n=js(p,c,i,r),e.s<0?new p(1).div(n):Pe(n,r,s);if(a=c.s,a<0){if(t<e.d.length-1)return new p(NaN);if((e.d[t]&1)==0&&(a=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=a,c}return i=Et(+c,g),t=i==0||!isFinite(i)?Ut(g*(Math.log("0."+xt(c.d))/Math.LN10+c.e+1)):new p(i+"").e,t>p.maxE+1||t<p.minE-1?new p(t>0?a/0:0):(je=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=co(e.times(Vi(c,r+i)),r),n.d&&(n=Pe(n,r+5,1),Or(n.d,r,s)&&(t=r+10,n=Pe(co(e.times(Vi(c,t+i)),t),t+5,1),+xt(n.d).slice(r+1,r+15)+1==1e14&&(n=Pe(n,r+1,0)))),n.s=a,je=!0,p.rounding=s,Pe(n,r,s))};re.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ci(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Gt(e,1,Ki),t===void 0?t=n.rounding:Gt(t,0,8),r=Pe(new n(r),e,t),i=Ci(r,e<=r.e||r.e<=n.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+i:i};re.toSignificantDigits=re.toSD=function(e,t){var i=this,r=i.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Gt(e,1,Ki),t===void 0?t=r.rounding:Gt(t,0,8)),Pe(new r(i),e,t)};re.toString=function(){var e=this,t=e.constructor,i=Ci(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};re.truncated=re.trunc=function(){return Pe(new this.constructor(this),this.e+1,1)};re.valueOf=re.toJSON=function(){var e=this,t=e.constructor,i=Ci(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function xt(e){var t,i,r,n=e.length-1,s="",a=e[0];if(n>0){for(s+=a,t=1;t<n;t++)r=e[t]+"",i=Le-r.length,i&&(s+=Gi(i)),s+=r;a=e[t],r=a+"",i=Le-r.length,i&&(s+=Gi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Gt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(Zi+e)}function Or(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Le,n=0):(n=Math.ceil((t+1)/Le),t%=Le),s=Et(10,Le-t),c=e[n]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),a=i<4&&c==99999||i>3&&c==49999||c==5e4||c==0):a=(i<4&&c+1==s||i>3&&c+1==s/2)&&(e[n+1]/s/100|0)==Et(10,t-2)-1||(c==s/2||c==0)&&(e[n+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),a=(r||i<4)&&c==9999||!r&&i>3&&c==4999):a=((r||i<4)&&c+1==s||!r&&i>3&&c+1==s/2)&&(e[n+1]/s/1e3|0)==Et(10,t-3)-1,a}function Qr(e,t,i){for(var r,n=[0],s,a=0,c=e.length;a<c;){for(s=n.length;s--;)n[s]*=t;for(n[0]+=ao.indexOf(e.charAt(a++)),r=0;r<n.length;r++)n[r]>i-1&&(n[r+1]===void 0&&(n[r+1]=0),n[r+1]+=n[r]/i|0,n[r]%=i)}return n.reverse()}function yu(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/an(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=hr(e,1,t.times(n),new e(1));for(var s=i;s--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return e.precision-=i,t}var ut=(function(){function e(r,n,s){var a,c=0,p=r.length;for(r=r.slice();p--;)a=r[p]*n+c,r[p]=a%s|0,c=a/s|0;return c&&r.unshift(c),r}function t(r,n,s,a){var c,p;if(s!=a)p=s>a?1:-1;else for(c=p=0;c<s;c++)if(r[c]!=n[c]){p=r[c]>n[c]?1:-1;break}return p}function i(r,n,s,a){for(var c=0;s--;)r[s]-=c,c=r[s]<n[s]?1:0,r[s]=c*a+r[s]-n[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,n,s,a,c,p){var g,v,y,A,k,U,P,W,j,K,X,Q,se,Y,le,E,I,O,R,N,S=r.constructor,h=r.s==n.s?1:-1,o=r.d,l=n.d;if(!o||!o[0]||!l||!l[0])return new S(!r.s||!n.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?h*0:h/0);for(p?(k=1,v=r.e-n.e):(p=gi,k=Le,v=Ut(r.e/k)-Ut(n.e/k)),R=l.length,I=o.length,j=new S(h),K=j.d=[],y=0;l[y]==(o[y]||0);y++);if(l[y]>(o[y]||0)&&v--,s==null?(Y=s=S.precision,a=S.rounding):c?Y=s+(r.e-n.e)+1:Y=s,Y<0)K.push(1),U=!0;else{if(Y=Y/k+2|0,y=0,R==1){for(A=0,l=l[0],Y++;(y<I||A)&&Y--;y++)le=A*p+(o[y]||0),K[y]=le/l|0,A=le%l|0;U=A||y<I}else{for(A=p/(l[0]+1)|0,A>1&&(l=e(l,A,p),o=e(o,A,p),R=l.length,I=o.length),E=R,X=o.slice(0,R),Q=X.length;Q<R;)X[Q++]=0;N=l.slice(),N.unshift(0),O=l[0],l[1]>=p/2&&++O;do A=0,g=t(l,X,R,Q),g<0?(se=X[0],R!=Q&&(se=se*p+(X[1]||0)),A=se/O|0,A>1?(A>=p&&(A=p-1),P=e(l,A,p),W=P.length,Q=X.length,g=t(P,X,W,Q),g==1&&(A--,i(P,R<W?N:l,W,p))):(A==0&&(g=A=1),P=l.slice()),W=P.length,W<Q&&P.unshift(0),i(X,P,Q,p),g==-1&&(Q=X.length,g=t(l,X,R,Q),g<1&&(A++,i(X,R<Q?N:l,Q,p))),Q=X.length):g===0&&(A++,X=[0]),K[y++]=A,g&&X[0]?X[Q++]=o[E]||0:(X=[o[E]],Q=1);while((E++<I||X[0]!==void 0)&&Y--);U=X[0]!==void 0}K[0]||K.shift()}if(k==1)j.e=v,Rs=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,Pe(j,c?s+j.e+1:s,a,U)}return j}})();function Pe(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor;e:if(t!=null){if(y=e.d,!y)return e;for(n=1,c=y[0];c>=10;c/=10)n++;if(s=t-n,s<0)s+=Le,a=t,v=y[A=0],p=v/Et(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/Le),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=Le,a=s-Le+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=Le,a=s-Le+n,p=a<0?0:v/Et(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%Et(10,n-a-1)),g=i<4?(p||r)&&(i==0||i==(e.s<0?3:2)):p>5||p==5&&(i==4||r||i==6&&(s>0?a>0?v/Et(10,n-a):0:y[A-1])%10&1||i==(e.s<0?8:7)),t<1||!y[0])return y.length=0,g?(t-=e.e+1,y[0]=Et(10,(Le-t%Le)%Le),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=Et(10,Le-s),y[A]=a>0?(v/Et(10,n-a)%Et(10,a)|0)*c:0),g)for(;;)if(A==0){for(s=1,a=y[0];a>=10;a/=10)s++;for(a=y[0]+=c,c=1;a>=10;a/=10)c++;s!=c&&(e.e++,y[0]==gi&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=gi)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return je&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function Ci(e,t,i){if(!e.isFinite())return $s(e);var r,n=e.e,s=xt(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+Gi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+Gi(-n-1)+s,i&&(r=i-a)>0&&(s+=Gi(r))):n>=a?(s+=Gi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+Gi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=Gi(r))),s}function sn(e,t){var i=e[0];for(t*=Le;i>=10;i/=10)t++;return t}function nn(e,t,i){if(t>bu)throw je=!0,i&&(e.precision=i),Error(Ls);return Pe(new e(tn),t,1,!0)}function Si(e,t,i){if(t>uo)throw Error(Ls);return Pe(new e(rn),t,i,!0)}function Us(e){var t=e.length-1,i=t*Le+1;if(t=e[t],t){for(;t%10==0;t/=10)i--;for(t=e[0];t>=10;t/=10)i++}return i}function Gi(e){for(var t="";e--;)t+="0";return t}function js(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/Le+4);for(je=!1;;){if(i%2&&(s=s.times(t),xs(s.d,a)&&(n=!0)),i=Ut(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),xs(t.d,a)}return je=!0,s}function Ps(e){return e.d[e.d.length-1]&1}function qs(e,t,i){for(var r,n,s=new e(t[0]),a=0;++a<t.length;){if(n=new e(t[a]),!n.s){s=n;break}r=s.cmp(n),(r===i||r===0&&s.s===i)&&(s=n)}return s}function co(e,t){var i,r,n,s,a,c,p,g=0,v=0,y=0,A=e.constructor,k=A.rounding,U=A.precision;if(!e.d||!e.d[0]||e.e>17)return new A(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(je=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(Et(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=Pe(s.times(e),p,1),i=i.times(++v),c=a.plus(ut(s,i,p,1)),xt(c.d).slice(0,p)===xt(a.d).slice(0,p)){for(n=y;n--;)a=Pe(a.times(a),p,1);if(t==null)if(g<3&&Or(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return Pe(a,A.precision=U,k,je=!0);else return A.precision=U,a}a=c}}function Vi(e,t){var i,r,n,s,a,c,p,g,v,y,A,k=1,U=10,P=e,W=P.d,j=P.constructor,K=j.rounding,X=j.precision;if(P.s<0||!W||!W[0]||!P.e&&W[0]==1&&W.length==1)return new j(W&&!W[0]?-1/0:P.s!=1?NaN:W?0:P);if(t==null?(je=!1,v=X):v=t,j.precision=v+=U,i=xt(W),r=i.charAt(0),Math.abs(s=P.e)<15e14){for(;r<7&&r!=1||r==1&&i.charAt(1)>3;)P=P.times(e),i=xt(P.d),r=i.charAt(0),k++;s=P.e,r>1?(P=new j("0."+i),s++):P=new j(r+"."+i.slice(1))}else return g=nn(j,v+2,X).times(s+""),P=Vi(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?Pe(P,X,K,je=!0):P;for(y=P,p=a=P=ut(P.minus(1),P.plus(1),v,1),A=Pe(P.times(P),v,1),n=3;;){if(a=Pe(a.times(A),v,1),g=p.plus(ut(a,new j(n),v,1)),xt(g.d).slice(0,v)===xt(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(nn(j,v+2,X).times(s+""))),p=ut(p,new j(k),v,1),t==null)if(Or(p.d,v-U,K,c))j.precision=v+=U,g=a=P=ut(y.minus(1),y.plus(1),v,1),A=Pe(P.times(P),v,1),n=c=1;else return Pe(p,j.precision=X,K,je=!0);else return j.precision=X,p;p=g,n+=2}}function $s(e){return String(e.s*e.s/0)}function en(e,t){var i,r,n;for((i=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(i<0&&(i=r),i+=+t.slice(r+1),t=t.substring(0,r)):i<0&&(i=t.length),r=0;t.charCodeAt(r)===48;r++);for(n=t.length;t.charCodeAt(n-1)===48;--n);if(t=t.slice(r,n),t){if(n-=r,e.e=i=i-r-1,e.d=[],r=(i+1)%Le,i<0&&(r+=Le),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=Le;r<n;)e.d.push(+t.slice(r,r+=Le));t=t.slice(r),r=Le-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),je&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Mu(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Bs.test(t))return en(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(_u.test(t))i=16,t=t.toLowerCase();else if(gu.test(t))i=2;else if(vu.test(t))i=8;else throw Error(Zi+t);for(s=t.search(/p/i),s>0?(p=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),a=s>=0,r=e.constructor,a&&(t=t.replace(".",""),c=t.length,s=c-s,n=js(r,new r(i),s,s*2)),g=Qr(t,i,gi),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=sn(g,v),e.d=g,je=!1,a&&(e=ut(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?Et(2,p):Pr.pow(2,p))),je=!0,e)}function Au(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:hr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/an(5,i)),t=hr(e,2,t,t);for(var n,s=new e(5),a=new e(16),c=new e(20);i--;)n=t.times(t),t=t.times(s.plus(n.times(a.times(n).minus(c))));return t}function hr(e,t,i,r,n){var s,a,c,p,g=1,v=e.precision,y=Math.ceil(v/Le);for(je=!1,p=i.times(i),c=new e(r);;){if(a=ut(c.times(p),new e(t++*t++),v,1),c=n?r.plus(a):r.minus(a),r=ut(a.times(p),new e(t++*t++),v,1),a=c.plus(r),a.d[y]!==void 0){for(s=y;a.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=a,a=s,g++}return je=!0,a.d.length=y+1,a}function an(e,t){for(var i=e;--t;)i*=e;return i}function Hs(e,t){var i,r=t.s<0,n=Si(e,e.precision,1),s=n.times(.5);if(t=t.abs(),t.lte(s))return Ni=r?4:1,t;if(i=t.divToInt(n),i.isZero())Ni=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Ni=Ps(i)?r?2:3:r?4:1,t;Ni=Ps(i)?r?1:4:r?3:2}return t.minus(n).abs()}function ho(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Gt(i,1,Ki),r===void 0?r=k.rounding:Gt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=$s(e);else{for(v=Ci(e),a=v.indexOf("."),U?(n=2,t==16?i=i*4-3:t==8&&(i=i*3-2)):n=t,a>=0&&(v=v.replace(".",""),A=new k(1),A.e=v.length-a,A.d=Qr(Ci(A),10,n),A.e=A.d.length),y=Qr(v,10,n),s=p=y.length;y[--p]==0;)y.pop();if(!y[0])v=U?"0p+0":"0";else{if(a<0?s--:(e=new k(e),e.d=y,e.e=s,e=ut(e,A,i,r,0,n),y=e.d,s=e.e,g=Rs),a=y[i],c=n/2,g=g||y[i+1]!==void 0,g=r<4?(a!==void 0||g)&&(r===0||r===(e.s<0?3:2)):a>c||a===c&&(r===4||g||r===6&&y[i-1]&1||r===(e.s<0?8:7)),y.length=i,g)for(;++y[--i]>n-1;)y[i]=0,i||(++s,y.unshift(1));for(p=y.length;!y[p-1];--p);for(a=0,v="";a<p;a++)v+=ao.charAt(y[a]);if(U){if(p>1)if(t==16||t==8){for(a=t==16?4:3,--p;p%a;p++)v+="0";for(y=Qr(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=ao.charAt(y[a])}else v=v.charAt(0)+"."+v.slice(1);v=v+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)v="0"+v;v="0."+v}else if(++s>p)for(s-=p;s--;)v+="0";else s<p&&(v=v.slice(0,s)+"."+v.slice(s))}v=(t==16?"0x":t==2?"0b":t==8?"0o":"")+v}return e.s<0?"-"+v:v}function xs(e,t){if(e.length>t)return e.length=t,!0}function Su(e){return new this(e).abs()}function Cu(e){return new this(e).acos()}function Eu(e){return new this(e).acosh()}function Iu(e,t){return new this(e).plus(t)}function ku(e){return new this(e).asin()}function Tu(e){return new this(e).asinh()}function Ou(e){return new this(e).atan()}function Pu(e){return new this(e).atanh()}function xu(e,t){e=new this(e),t=new this(t);var i,r=this.precision,n=this.rounding,s=r+4;return!e.s||!t.s?i=new this(NaN):!e.d&&!t.d?(i=Si(this,s,1).times(t.s>0?.25:.75),i.s=e.s):!t.d||e.isZero()?(i=t.s<0?Si(this,r,n):new this(0),i.s=e.s):!e.d||t.isZero()?(i=Si(this,s,1).times(.5),i.s=e.s):t.s<0?(this.precision=s,this.rounding=1,i=this.atan(ut(e,t,s,1)),t=Si(this,s,1),this.precision=r,this.rounding=n,i=e.s<0?i.minus(t):i.plus(t)):i=this.atan(ut(e,t,s,1)),i}function Nu(e){return new this(e).cbrt()}function Ru(e){return Pe(e=new this(e),e.e+1,2)}function Lu(e,t,i){return new this(e).clamp(t,i)}function Fu(e){if(!e||typeof e!="object")throw Error(on+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,Ki,"rounding",0,8,"toExpNeg",-dr,0,"toExpPos",0,dr,"maxE",0,dr,"minE",-dr,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(i=s[t],n&&(this[i]=lo[i]),(r=e[i])!==void 0)if(Ut(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(Zi+i+": "+r);if(i="crypto",n&&(this[i]=lo[i]),(r=e[i])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[i]=!0;else throw Error(Fs);else this[i]=!1;else throw Error(Zi+i+": "+r);return this}function Du(e){return new this(e).cos()}function Bu(e){return new this(e).cosh()}function Gs(e){var t,i,r;function n(s){var a,c,p,g=this;if(!(g instanceof n))return new n(s);if(g.constructor=n,Ns(s)){g.s=s.s,je?!s.d||s.e>n.maxE?(g.e=NaN,g.d=null):s.e<n.minE?(g.e=0,g.d=[0]):(g.e=s.e,g.d=s.d.slice()):(g.e=s.e,g.d=s.d?s.d.slice():s.d);return}if(p=typeof s,p==="number"){if(s===0){g.s=1/s<0?-1:1,g.e=0,g.d=[0];return}if(s<0?(s=-s,g.s=-1):g.s=1,s===~~s&&s<1e7){for(a=0,c=s;c>=10;c/=10)a++;je?a>n.maxE?(g.e=NaN,g.d=null):a<n.minE?(g.e=0,g.d=[0]):(g.e=a,g.d=[s]):(g.e=a,g.d=[s]);return}if(s*0!==0){s||(g.s=NaN),g.e=NaN,g.d=null;return}return en(g,s.toString())}if(p==="string")return(c=s.charCodeAt(0))===45?(s=s.slice(1),g.s=-1):(c===43&&(s=s.slice(1)),g.s=1),Bs.test(s)?en(g,s):Mu(g,s);if(p==="bigint")return s<0?(s=-s,g.s=-1):g.s=1,en(g,s.toString());throw Error(Zi+s)}if(n.prototype=re,n.ROUND_UP=0,n.ROUND_DOWN=1,n.ROUND_CEIL=2,n.ROUND_FLOOR=3,n.ROUND_HALF_UP=4,n.ROUND_HALF_DOWN=5,n.ROUND_HALF_EVEN=6,n.ROUND_HALF_CEIL=7,n.ROUND_HALF_FLOOR=8,n.EUCLID=9,n.config=n.set=Fu,n.clone=Gs,n.isDecimal=Ns,n.abs=Su,n.acos=Cu,n.acosh=Eu,n.add=Iu,n.asin=ku,n.asinh=Tu,n.atan=Ou,n.atanh=Pu,n.atan2=xu,n.cbrt=Nu,n.ceil=Ru,n.clamp=Lu,n.cos=Du,n.cosh=Bu,n.div=Uu,n.exp=ju,n.floor=qu,n.hypot=$u,n.ln=Hu,n.log=Gu,n.log10=Zu,n.log2=Vu,n.max=Ku,n.min=Wu,n.mod=zu,n.mul=Xu,n.pow=Ju,n.random=Yu,n.round=Qu,n.sign=e0,n.sin=t0,n.sinh=i0,n.sqrt=r0,n.sub=n0,n.sum=o0,n.tan=s0,n.tanh=a0,n.trunc=l0,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(i=r[t++])||(e[i]=this[i]);return n.config(e),n}function Uu(e,t){return new this(e).div(t)}function ju(e){return new this(e).exp()}function qu(e){return Pe(e=new this(e),e.e+1,3)}function $u(){var e,t,i=new this(0);for(je=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)i.d&&(i=i.plus(t.times(t)));else{if(t.s)return je=!0,new this(1/0);i=t}return je=!0,i.sqrt()}function Ns(e){return e instanceof Pr||e&&e.toStringTag===Ds||!1}function Hu(e){return new this(e).ln()}function Gu(e,t){return new this(e).log(t)}function Vu(e){return new this(e).log(2)}function Zu(e){return new this(e).log(10)}function Ku(){return qs(this,arguments,-1)}function Wu(){return qs(this,arguments,1)}function zu(e,t){return new this(e).mod(t)}function Xu(e,t){return new this(e).mul(t)}function Ju(e,t){return new this(e).pow(t)}function Yu(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Gt(e,1,Ki),r=Math.ceil(e/Le),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)n=t[s],n>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=n%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)n=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),n>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(n%1e7),s+=4);s=r/4}else throw Error(Fs);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=Le,r&&e&&(n=Et(10,Le-e),c[s]=(r/n|0)*n);c[s]===0;s--)c.pop();if(s<0)i=0,c=[0];else{for(i=-1;c[0]===0;i-=Le)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<Le&&(i-=Le-r)}return a.e=i,a.d=c,a}function Qu(e){return Pe(e=new this(e),e.e+1,this.rounding)}function e0(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function t0(e){return new this(e).sin()}function i0(e){return new this(e).sinh()}function r0(e){return new this(e).sqrt()}function n0(e,t){return new this(e).sub(t)}function o0(){var e=0,t=arguments,i=new this(t[e]);for(je=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return je=!0,Pe(i,this.precision,this.rounding)}function s0(e){return new this(e).tan()}function a0(e){return new this(e).tanh()}function l0(e){return Pe(e=new this(e),e.e+1,1)}re[Symbol.for("nodejs.util.inspect.custom")]=re.toString;re[Symbol.toStringTag]="Decimal";var Pr=re.constructor=Gs(lo);tn=new Pr(tn);rn=new Pr(rn);var Ei=Pr;var go=Vr(Zs()),Ri=require("@mysten/sui/transactions");var fr=require("@cetusprotocol/common-sdk"),Ks=e=>{let t=[];return e.forEach(i=>{t.push(po(i))}),t},po=e=>{let t=(0,fr.getObjectFields)(e);return{marketId:t.id.id,baseToken:(0,fr.addHexPrefix)(t.base_token.fields.name),quoteToken:(0,fr.addHexPrefix)(t.quote_token.fields.name),isOpenPause:t.is_open_pause,isClosePause:t.is_close_pause,maxLongLeverage:t.max_long_leverage,maxShortLeverage:t.max_short_leverage,openFeeRate:(t.open_fee_rate/1e6).toString(),closeFeeRate:(t.close_fee_rate/1e6).toString(),positionsHandle:t.positions.fields.id.id}},mo=e=>{let t=(0,fr.getObjectFields)(e);return{createdAt:t.created_ts,id:t.id.id,initDepositAmount:t.init_deposit_amount,isLong:t.is_long,lendingMarketId:t.lending_market_id,obligationOwnerCap:t.obligation_owner_cap.fields.obligation_id}};var Li=require("@mysten/sui/utils"),Ws=require("@suilend/sdk/parsers/obligation"),zs=require("@suilend/sdk/_generated/suilend/lending-market/functions"),ln=class{constructor(t){this.getLeverageConfig=async()=>{let t=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.leverage);return(await this._sdk.FullClient.getObject({id:t.global_config_id,options:{showContent:!0}})).data.content.fields};this.getLeverageMarketsList=async(t=!1)=>{let i="leverage_markets_list",r=this._sdk.getCache(i,t);if(r)return r;let n=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.leverage),s=50,a=null,c=[];for(;;){let A=await this._sdk.FullClient.getDynamicFields({parentId:n.markets_table_id,limit:s,cursor:a});if(A.data.forEach(k=>{c.push(k.objectId)}),A.data.length<s)break;a=A.nextCursor}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:63 ~ LeverageModules ~ marketSimpleIdList:",c);let p=await this._sdk.FullClient.batchGetObjects(c,{showContent:!0}),g=[];p.forEach(A=>{g.push(A.data.content.fields.value.fields.market_id)});let v=await this._sdk.FullClient.batchGetObjects(g,{showContent:!0}),y=Ks(v);return this._sdk.updateCache(i,y,ae.CACHE_TIME_5MIN),y};this.getLeverageMarketInfo=async t=>{let i=`leverage_market_info_${t}`,r=this._sdk.getCache(i);if(r)return r;let n=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),s=po(n);return this._sdk.updateCache(i,s,ae.CACHE_TIME_5MIN),s};this.getLeveragePositionList=async()=>{let t=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{Package:this._sdk.sdkOptions.leverage.package_id}]}}),{lendingMarketId:i,lendingMarketType:r}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),n=await this._sdk.SuiLendModule.getSuilendClient(i,r),s=[];for(let a=0;a<t.data.length;a++){let c=mo(t.data[a]),p=await n.getObligation(c.obligationOwnerCap);s.push({...c,...p})}return s};this.getLeveragePosition=async t=>{let i=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{ObjectId:t}}),r=mo(i.data[0]),{lendingMarketId:n,lendingMarketType:s}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),a=await this._sdk.SuiLendModule.getSuilendClient(n,s),{allLendingMarketData:c}=await this._sdk.SuiLendModule.getLendingMarketData(),p=c[n].reserveMap,g=await a.getObligation(r.obligationOwnerCap);return{...(0,Ws.parseObligation)(g,p||{}),...r}};this.getClmmPoolInfo=async t=>{let i=await this._sdk.ClmmSDK.Pool.getPool(t),{coin_type_a:r,coin_type_b:n,fee_rate:s}=i;return{clmmFeeTier:s/1e6,clmmPoolCoinTypeA:r,clmmPoolCoinTypeB:n}};this.openLeveragePosition=async t=>{let{isQuote:i,isLong:r,depositAmount:n,clmmPool:s,slippage:a,leverage:c,marketId:p}=t,{lendingMarketId:g}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),v=new Ri.Transaction,{openFeeRate:y,baseToken:A,quoteToken:k}=await this.getLeverageMarketInfo(p),{clmmFeeTier:U,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W}=await this.getClmmPoolInfo(s);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",U,P,W);let{baseReserveArrayIndex:j,quoteReserveArrayIndex:K,reserve:X}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(A,k),Q=r&&i||!r&&!i;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",Q);let se=n.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",se);let Y,le;if(Q){let $=r&&i?k:A,z=r&&i?A:k,ie=await this.findRouters($,z,n,!0,[s]);if(se=ie?.amount_out.toString(),ie){let C=ae.CoinAssist.buildCoinWithBalance(BigInt(n.toString()),$,v);le=await this.routerSwap({router:ie.route_obj,slippage:a,inputCoin:C,txb:v}),Y=le}}else Y=ae.CoinAssist.buildCoinWithBalance(BigInt(n.toString()),i?k:A,v);let{flashAmount:E}=await this.calculateFlashLoanParams({isLong:r,leverage:c,baseToken:A,quoteToken:k,initDepositAmount:se,reserve:X});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",E);let I=r?k:A;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",I);let O=P===I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",P),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",O);let R=(0,ae.d)(E).mul(U).toString(),{balanceA:N,balanceB:S,receipt:h}=this.flashLoan({amount:(0,ae.d)(E),clmmPool:s,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W,flashLoanCoin:I,tx:v}),o=r?k:A,l=r?A:k,d=await this.findRouters(o,l,(0,ae.d)(E),!0,[s]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:d,debtFrom:o,debtTo:l,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W});let m=(0,ae.d)(d?.amount_out||0),_;d&&(_=await this.routerSwap({router:d.route_obj,inputCoin:O?ae.CoinAssist.fromBalance(N,P,v):ae.CoinAssist.fromBalance(S,W,v),slippage:a,txb:v}));let b=(0,ae.d)(m).add(se).mul(1-y).toDP(0,Ei.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:258 ~ LeverageModules ~ totalDepositAmount:",b,se,m);let w=this.createLeveragePosition({leverage:c,marketId:p,baseToken:A,quoteToken:k,isLong:r,totalDepositAmount:b,tx:v});for(let $=0;$<X.length;$++){let z=(0,Li.toHEX)(new Uint8Array(X[$].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(v,z,BigInt(X[$].arrayIndex))}let f=r?j:K;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",Y),await v.mergeCoins(_,[Y]),await this.depositToLeveragePosition({isLong:r,marketId:p,position:w,depositReserveArrayIndex:f,inputCoin:_},v);let u=(0,ae.d)(E).add(R).toDP(0,Ei.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",u,E,R);let M=await this.borrowAsset({position:w,reserveArrayIndex:r?K:j,borrowAmount:(0,ae.d)(u),baseToken:A,quoteToken:k,isLong:r,lendingMarketId:g},v);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",M);let q=ae.CoinAssist.mintBalanceZero(O?W:P,v);return this.repayFlashLoan({tx:v,clmmPool:s,repayBase:O?ae.CoinAssist.intoBalance(M,P,v):q,repayQuote:O?q:ae.CoinAssist.intoBalance(M,W,v),receipt:h,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W}),v.transferObjects([w],v.pure.address(this._sdk.getSenderAddress())),ae.CoinAssist.destroyBalanceZero(O?S:N,O?W:P,v),v};this.positionManageSizeDeposit=async t=>{let{marketId:i,positionId:r,isQuote:n,depositAmount:s,clmmPool:a,slippage:c,leverage:p,txb:g}=t,{lendingMarketId:v}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{baseToken:y,quoteToken:A}=await this.getLeverageMarketInfo(i),{isLong:k,deposits:U,borrows:P}=await this.getLeveragePosition(r),{reserve:W}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(y,A),{clmmFeeTier:j,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X}=await this.getClmmPoolInfo(a),Q=g||new Ri.Transaction,se=U[0].reserveArrayIndex.toString(),Y=P[0].reserveArrayIndex.toString(),le=n&&k||!n&&!k,E;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",le);let I;if(le){let M=n&&k?A:y,q=n&&k?y:A,$=await this.findRouters(M,q,s,!0,[a]);if($){let z=ae.CoinAssist.buildCoinWithBalance(BigInt(s.toString()),M,Q);I=await this.routerSwap({router:$.route_obj,inputCoin:z,slippage:c,txb:Q}),E=I}}else E=ae.CoinAssist.buildCoinWithBalance(BigInt(s.toString()),n?A:y,Q);let O=k?A:y;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",O);let{flashAmount:R}=await this.calculateFlashLoanParams({isLong:k,leverage:p,baseToken:y,quoteToken:A,initDepositAmount:s.toString(),reserve:W}),N=(0,ae.d)(R).mul(j).toString(),S=K===O;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",S);let{balanceA:h,balanceB:o,receipt:l}=this.flashLoan({amount:(0,ae.d)(R),clmmPool:a,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X,flashLoanCoin:O,tx:Q}),d=k?A:y,m=k?y:A,_=await this.findRouters(d,m,(0,ae.d)(R),!0,[a]),b;_&&(b=await this.routerSwap({router:_.route_obj,inputCoin:S?ae.CoinAssist.fromBalance(h,K,Q):ae.CoinAssist.fromBalance(o,X,Q),slippage:c,txb:Q})),Q.mergeCoins(b,[E]);for(let M=0;M<W.length;M++){let q=(0,Li.toHEX)(new Uint8Array(W[M].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(Q,q,BigInt(W[M].arrayIndex))}this.depositToLeveragePosition({isLong:k,marketId:i,positionId:r,depositReserveArrayIndex:se,inputCoin:b},Q);let w=(0,ae.d)(R).add(N).toDP(0,Ei.ROUND_UP).toString(),f=this.borrowAsset({positionId:r,reserveArrayIndex:Y,borrowAmount:(0,ae.d)(w),baseToken:y,quoteToken:A,isLong:k,lendingMarketId:v},Q),u=ae.CoinAssist.mintBalanceZero(S?X:K,Q);return this.repayFlashLoan({tx:Q,clmmPool:a,repayBase:S?ae.CoinAssist.intoBalance(f,K,Q):u,repayQuote:S?u:ae.CoinAssist.intoBalance(f,X,Q),receipt:l,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X}),ae.CoinAssist.destroyBalanceZero(S?o:h,S?X:K,Q),Q};this.positionManageSizeWithdraw=async t=>{let{marketId:i,positionId:r,withdrawAmount:n,isQuote:s,txb:a,clmmPool:c,slippage:p,leverage:g}=t,{lendingMarketType:v,lendingMarketId:y}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),A=a||new Ri.Transaction,{baseToken:k,quoteToken:U}=await this.getLeverageMarketInfo(i),{isLong:P,deposits:W,borrows:j}=await this.getLeveragePosition(r),{reserve:K}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(k,U),X=s&&P||!s&&!P;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:479 ~ LeverageModules ~ hasSwap:",X);let Q=n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:482 ~ LeverageModules ~ withdrawCtokenAmount:",Q);let se=null;if(X){let b=k,w=U;se=await this.findRouters(b,w,n,!1,[c]),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ routers:",{hasSwapRouters:se,from:b,to:w}),Q=se?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",Q);for(let b=0;b<K.length;b++){let w=(0,Li.toHEX)(new Uint8Array(K[b].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,w,BigInt(K[b].arrayIndex))}let{token:Y}=j[0].reserve,le=(0,ae.d)(W[0].depositedCtokenAmount.toString()).div((0,ae.d)(g)).toDP(0,Ei.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",le);let E=(0,ae.d)(Q).div((0,ae.d)(le)).toString(),I=(0,ae.d)(j[0].borrowedAmount.toString()).mul(10**Y.decimals).toString(),O=(0,ae.d)(I).mul(E).toDP(0,Ei.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:508 ~ LeverageModules ~ repayAmount:",{\u9700\u8981\u507F\u8FD8\u591A\u5C11borrowAmount:O,\u63D0\u53D6\u4FDD\u8BC1\u91D1\u6570\u91CF:Q,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:le});let R=await this._sdk.SuiLendModule.getSuilendClient(y,v),N=await this._sdk.PythConnection.getPriceFeedsUpdateData([W[0].reserve.priceIdentifier]),S=await R.pythClient.updatePriceFeeds(A,N,[W[0].reserve.priceIdentifier]),h=this.withdrawAsset({marketId:i,positionId:r,withdrawAmount:(0,ae.d)(Q),withdrawReserveArrayIndex:W[0].reserveArrayIndex.toString(),withdrawCoinType:P?k:U,baseToken:k,quoteToken:U,priceObjectId:S&&S[0]},A),o=P?k:U,l=P?U:k;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let d=await this.findRouters(o,l,(0,ae.d)(O),!1,[c]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:530 ~ LeverageModules ~ debtRouter:",{debtRouter:d,debtFrom:o,debtTo:l});let m;d&&(m=await this.routerSwap({router:d.route_obj,inputCoin:h,slippage:p,txb:A}));let _=A.splitCoins(m,[O]);return this.repay({txb:A,positionId:r,repayReserveArrayIndex:j[0].reserveArrayIndex.toString(),repayCoin:_,repayCoinType:P?U:k,repayAmount:(0,ae.d)(0)}),A.transferObjects([m,_],this._sdk.getSenderAddress()),A};this.positionManageLeverageIncrease=async t=>{let{marketId:i,positionId:r,isLong:n,currentLeverage:s,targetLeverage:a,clmmPool:c,slippage:p}=t,{baseToken:g,quoteToken:v}=await this.getLeverageMarketInfo(i),{deposits:y,borrows:A}=await this.getLeveragePosition(r),{reserve:k}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(g,v),{clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P,clmmFeeTier:W}=await this.getClmmPoolInfo(c),{lendingMarketId:j}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{token:K}=A[0].reserve,X=new Ri.Transaction,Q=(0,ae.d)(A[0].borrowedAmount.toString()).mul((0,ae.d)(a).sub((0,ae.d)(s))).mul(10**K.decimals).toDP(0,Ei.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",Q);let se=Q,Y=n?v:g,{balanceA:le,balanceB:E,receipt:I}=this.flashLoan({tx:X,amount:(0,ae.d)(se),clmmPool:c,clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P,flashLoanCoin:Y}),O=n?v:g,R=n?g:v,N=await this.findRouters(O,R,(0,ae.d)(Q),!0,[c]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:592 ~ LeverageModules ~ routers:",N,O,R);let S=await this.routerSwap({router:N?.route_obj,inputCoin:n?ae.CoinAssist.fromBalance(E,P,X):ae.CoinAssist.fromBalance(le,U,X),slippage:p,txb:X});for(let m=0;m<k.length;m++){let _=(0,Li.toHEX)(new Uint8Array(k[m].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(X,_,BigInt(k[m].arrayIndex))}this.depositToLeveragePosition({isLong:n,marketId:i,positionId:r,depositReserveArrayIndex:n?y[0].reserveArrayIndex.toString():A[0].reserveArrayIndex.toString(),inputCoin:S},X);let h=(0,ae.d)(se).mul((0,ae.d)(1).add(W)).toDP(0,Ei.ROUND_UP).toString(),o=await this.borrowAsset({positionId:r,reserveArrayIndex:A[0].reserveArrayIndex.toString(),borrowAmount:(0,ae.d)(h),baseToken:g,quoteToken:v,isLong:n,lendingMarketId:j},X),l=ae.CoinAssist.mintBalanceZero(n?g:v,X),d=U===Y;return this.repayFlashLoan({tx:X,clmmPool:c,repayBase:n?l:ae.CoinAssist.intoBalance(o,g,X),repayQuote:n?ae.CoinAssist.intoBalance(o,v,X):l,receipt:I,clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P}),ae.CoinAssist.destroyBalanceZero(d?E:le,d?P:U,X),X};this.positionManageLeverageDecrease=async t=>{let{marketId:i,positionId:r,isLong:n,currentLeverage:s,targetLeverage:a,clmmPool:c,slippage:p}=t,{baseToken:g,quoteToken:v,closeFeeRate:y}=await this.getLeverageMarketInfo(i),{deposits:A,borrows:k}=await this.getLeveragePosition(r),{reserve:U}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(g,v),{lendingMarketId:P,lendingMarketType:W}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),j=new Ri.Transaction,K=(0,ae.d)(A[0].depositedCtokenAmount.toString()).mul((0,ae.d)(s).sub((0,ae.d)(a))).toString(),X=(0,ae.d)(K).toDP(0,Ei.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",X);for(let N=0;N<U.length;N++){let S=(0,Li.toHEX)(new Uint8Array(U[N].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(j,S,BigInt(U[N].arrayIndex))}let Q=await this._sdk.SuiLendModule.getSuilendClient(P,W),se=await this._sdk.PythConnection.getPriceFeedsUpdateData([A[0].reserve.priceIdentifier]),Y=await Q.pythClient.updatePriceFeeds(j,se,[A[0].reserve.priceIdentifier]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:672 ~ LeverageModules ~ baseToken:",g);let le=this.withdrawAsset({marketId:i,positionId:r,withdrawAmount:(0,ae.d)(X),withdrawReserveArrayIndex:A[0].reserveArrayIndex.toString(),withdrawCoinType:n?g:v,baseToken:g,quoteToken:v,priceObjectId:Y&&Y[0]},j),E=n?g:v,I=n?v:g,O=await this.findRouters(E,I,(0,ae.d)(X),!0,[c]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:681 ~ LeverageModules ~ routers:",O,O?.route_obj.paths,E,I);let R=await this.routerSwap({router:O?.route_obj,inputCoin:le,slippage:p,txb:j});return this.repay({txb:j,positionId:r,repayReserveArrayIndex:k[0].reserveArrayIndex.toString(),repayCoin:R,repayCoinType:n?v:g,repayAmount:(0,ae.d)(0)}),R&&j.transferObjects([R],this._sdk.getSenderAddress()),j};this.leveragePositionClose=async(t,i)=>{let r=i||new Ri.Transaction,{marketId:n,positionId:s}=t,{leverage:a}=this._sdk.sdkOptions,{global_config_id:c}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.leverage),{lendingMarketType:p,lendingMarketId:g}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{baseToken:v,quoteToken:y}=await this.getLeverageMarketInfo(n),A=await this.getLeveragePosition(s);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:541 ~ LeverageModules ~ positionInfo:",A.original.id);let k=(0,zs.obligation)(r,p,{obligationId:A.original.id,lendingMarket:r.object(g)});return r.moveCall({target:`${a.published_at}::position::close_Position`,typeArguments:[p,v,y],arguments:[r.object(c),r.object(n),r.object(s),k,r.object(ae.CLOCK_ADDRESS)]}),r};this.flashLoan=t=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:698 ~ LeverageModules ~ params:",t);let{clmm_pool:i}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:r}=(0,ae.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:n,clmmPool:s,clmmPoolCoinTypeA:a,clmmPoolCoinTypeB:c,flashLoanCoin:p,tx:g}=t,v=a===p,[y,A,k]=g.moveCall({target:`${i.published_at}::pool::flash_loan`,arguments:[g.object(r),g.object(s),g.pure.bool(v),g.pure.u64(n.toString())],typeArguments:[a,c]});return{balanceA:y,balanceB:A,receipt:k}};this.repayFlashLoan=t=>{let{clmm_pool:i}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:r}=(0,ae.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:n,repayBase:s,repayQuote:a,receipt:c,clmmPool:p,clmmPoolCoinTypeA:g,clmmPoolCoinTypeB:v}=t;return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:612 ~ LeverageModules ~ params:",t),n.moveCall({target:`${i.published_at}::pool::repay_flash_loan`,arguments:[n.object(r),n.object(p),s,a,c],typeArguments:[g,v]}),n};this.borrowAsset=(t,i)=>{let{position:r,reserveArrayIndex:n,borrowAmount:s,baseToken:a,quoteToken:c,lendingMarketId:p,isLong:g,positionId:v}=t;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:677 ~ LeverageModules ~ params:",t);let{leverage:y}=this._sdk.sdkOptions,{lendingMarketType:A}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend);return ae.CoinAssist.isSuiCoin(g?c:a)?i.moveCall({target:`${y.published_at}::position::borrow_sui`,typeArguments:[A],arguments:[i.object(p),r,i.pure.u64(n),i.pure.u64(s.toString()),i.object(Li.SUI_SYSTEM_STATE_OBJECT_ID),i.object(ae.CLOCK_ADDRESS)]}):i.moveCall({target:`${y.published_at}::position::borrow_not_sui`,typeArguments:[A,g?c:a],arguments:[i.object(p),v?i.object(v):r,i.pure.u64(n),i.pure.u64(s.toString()),i.object(ae.CLOCK_ADDRESS)]})};this.withdrawAsset=(t,i)=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:749 ~ LeverageModules ~ params:",t);let{leverage:r}=this._sdk.sdkOptions,{lendingMarketId:n,lendingMarketType:s}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{package_id:a}=this._sdk.sdkOptions.suilend,{marketId:c,positionId:p,withdrawAmount:g,withdrawReserveArrayIndex:v,withdrawCoinType:y,baseToken:A,quoteToken:k,priceObjectId:U}=t,[P]=i.moveCall({target:"0x1::option::none",typeArguments:[`${a}::lending_market::RateLimiterExemption<${s}, ${y}>`],arguments:[]});return ae.CoinAssist.isSuiCoin(y)?i.moveCall({target:`${r.published_at}::position::withdraw_sui`,typeArguments:[s,A,k],arguments:[i.object(n),i.object(c),i.object(p),i.object(U),i.object(P),i.pure.u64(g.toString()),i.pure.u64(v),i.object(Li.SUI_SYSTEM_STATE_OBJECT_ID),i.object(ae.CLOCK_ADDRESS)]}):i.moveCall({target:`${r.published_at}::position::withdraw_not_sui`,typeArguments:[s,A,k,y],arguments:[i.object(n),i.object(c),i.object(p),i.object(U),i.object(P),i.pure.u64(g.toString()),i.pure.u64(v),i.object(ae.CLOCK_ADDRESS)]})};this.repay=t=>{let{leverage:i}=this._sdk.sdkOptions,{lendingMarketId:r,lendingMarketType:n}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{txb:s,positionId:a,repayAmount:c,repayCoinType:p,repayCoin:g,repayReserveArrayIndex:v}=t,y=s||new Ri.Transaction,A=g||ae.CoinAssist.buildCoinWithBalance(BigInt(c.toString()),p,y);y.moveCall({target:`${i.published_at}::position::repay`,typeArguments:[n,p],arguments:[y.object(r),y.object(a),y.object(A),y.pure.u64(v.toString()),y.object(ae.CLOCK_ADDRESS)]})};this.routerSwap=async t=>{let{slippage:i,txb:r,inputCoin:n,router:s}=t,a=r||new Ri.Transaction;if(s)return await this._sdk.AggregatorClient.routerSwap({router:s,inputCoin:n,slippage:i,txb:a})};this.calculateOpenPosition=async t=>{let{isQuote:i,isLong:r,depositAmount:n,clmmPool:s,slippage:a,leverage:c,marketId:p}=t,{baseToken:g,quoteToken:v}=await this.getLeverageMarketInfo(p),{reserve:y}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(g,v),A=r&&i||!r&&!i;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",A);let k=n.toString();if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",k),A){let K=r&&i?v:g,X=r&&i?g:v;k=(await this.findRouters(K,X,n,!0,[s]))?.amount_out.toString()}let{flashAmount:U}=await this.calculateFlashLoanParams({isLong:r,leverage:c,baseToken:g,quoteToken:v,initDepositAmount:k,reserve:y});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",U);let P=r?v:g,W=r?g:v,j=await this.findRouters(P,W,(0,ae.d)(U),!0,[s]);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:956 ~ LeverageModules ~ debtRouters:",j),j};this._sdk=t}async calculateFlashLoanParams(t){let{isLong:i,leverage:r,baseToken:n,quoteToken:s,initDepositAmount:a,reserve:c}=t,p=await this._sdk.SuiLendModule.getLatestPriceFeeds(c);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:587 ~ LeverageModules ~ calculateFlashLoanParams ~ priceUpdateData:",p,s,n);let g=p[(0,ae.removeHexPrefix)(s)]?.price,v=p[(0,ae.removeHexPrefix)(n)]?.price,y=i?(0,ae.d)(v).div((0,ae.d)(g)).toString():(0,ae.d)(g).div((0,ae.d)(v)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",a.toString(),i,y,g,v),{flashAmount:(0,ae.d)(a).mul(r-1).mul(y).toDP(0,Ei.ROUND_UP).toString(),rate:y,quotePrice:g,basePrice:v}}createLeveragePosition(t){let{lendingMarketId:i,lendingMarketType:r}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{global_config_id:n}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.leverage),s=this._sdk.sdkOptions.leverage,{leverage:a,marketId:c,baseToken:p,quoteToken:g,isLong:v,totalDepositAmount:y,tx:A}=t;return A.moveCall({target:`${s.published_at}::position::open_position`,arguments:[A.object(n),A.object(c),A.object(i),A.pure.u64(y),A.pure.u64(a*1e4),A.object(ae.CLOCK_ADDRESS)],typeArguments:[r,p,g,v?p:g]})}async depositToLeveragePosition(t,i){console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:651 ~ LeverageModules ~ depositToLeveragePosition ~ params:",t);let{leverage:r}=this._sdk.sdkOptions,{lendingMarketType:n,lendingMarketId:s}=(0,ae.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{isLong:a,marketId:c,position:p,positionId:g,depositReserveArrayIndex:v,inputCoin:y}=t,{baseToken:A,quoteToken:k}=await this.getLeverageMarketInfo(c);return i.moveCall({target:`${r.published_at}::position::deposit`,typeArguments:[n,A,k,a?A:k],arguments:[i.object(s),i.object(c),p||i.object(g),y,i.pure.u64(v),i.object(ae.CLOCK_ADDRESS)]}),i}async findRouters(t,i,r,n,s){let{providers:a}=this._sdk.sdkOptions;try{let c={from:t,target:i,amount:new go.default(r.toFixed(0).toString()),byAmountIn:n,depth:3,providers:a},p=await this._sdk.AggregatorClient.findRouters(c);if(p?.error?.code===10001)return{...p,is_exceed:p.insufficientLiquidity};if(p?.insufficientLiquidity)return{...p,is_exceed:p.insufficientLiquidity};if(!p?.paths||p?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:p.amountIn.toString(),amount_out:p.amountOut.toString(),is_exceed:p.insufficientLiquidity,route_obj:p,byAmountIn:!0,originRes:p}}catch{try{if(s){let p=await this._sdk.AggregatorClient.swapInPools({from:t,target:i,amount:new go.default(r.toFixed(0).toString()),byAmountIn:n,pools:s});return p?{amount_in:p.routeData.amountIn.toString(),amount_out:p.routeData.amountOut.toString(),is_exceed:p.isExceed,route_obj:p.routeData,byAmountIn:!0,originRes:p}:null}return null}catch{return null}}}};var $r=Vr(al()),ru=require("@mysten/sui/utils"),nu=require("@mysten/sui/client");var wl=require("@cetusprotocol/common-sdk"),Fn=require("@mysten/sui/utils"),Ne=require("@cetusprotocol/common-sdk"),Nl=require("@cetusprotocol/common-sdk"),Ll=require("@mysten/sui/client"),yr=require("@mysten/sui/transactions"),ar=require("@mysten/sui/utils"),it=require("@cetusprotocol/common-sdk"),Bn=require("@mysten/sui/transactions"),nt=require("@cetusprotocol/common-sdk"),Un=require("@mysten/sui/transactions"),at=require("@cetusprotocol/common-sdk"),Ue=require("@cetusprotocol/common-sdk"),de=require("@cetusprotocol/common-sdk"),Dt=require("@cetusprotocol/common-sdk"),zl=require("@mysten/sui/client"),ki=require("@mysten/sui/transactions"),Jn=require("@mysten/sui/utils"),pe=require("@cetusprotocol/common-sdk"),$n=require("@mysten/sui/transactions"),Xl=require("@mysten/sui/utils"),lt=require("@cetusprotocol/common-sdk"),us=require("@mysten/sui/transactions"),cs=require("@mysten/sui/utils"),Mt=require("@cetusprotocol/common-sdk"),qt=require("@cetusprotocol/common-sdk"),ds=require("@mysten/sui/transactions"),Jl=require("@mysten/sui/utils"),Yl=require("@cetusprotocol/common-sdk"),Ql=require("@cetusprotocol/common-sdk"),tu=require("@cetusprotocol/common-sdk"),af=Object.create,vl=Object.defineProperty,lf=Object.getOwnPropertyDescriptor,uf=Object.getOwnPropertyNames,cf=Object.getPrototypeOf,df=Object.prototype.hasOwnProperty,hf=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof require<"u"?require:t)[i]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),ff=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),pf=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of uf(t))!df.call(e,n)&&n!==i&&vl(e,n,{get:()=>t[n],enumerable:!(r=lf(t,n))||r.enumerable});return e},qi=(e,t,i)=>(i=e!=null?af(cf(e)):{},pf(t||!e||!e.__esModule?vl(i,"default",{value:e,enumerable:!0}):i,e)),$i=ff((e,t)=>{"use strict";(function(i,r){"use strict";function n(o,l){if(!o)throw new Error(l||"Assertion failed")}function s(o,l){o.super_=l;var d=function(){};d.prototype=l.prototype,o.prototype=new d,o.prototype.constructor=o}function a(o,l,d){if(a.isBN(o))return o;this.negative=0,this.words=null,this.length=0,this.red=null,o!==null&&((l==="le"||l==="be")&&(d=l,l=10),this._init(o||0,l||10,d||"be"))}typeof i=="object"?i.exports=a:r.BN=a,a.BN=a,a.wordSize=26;var c;try{typeof window<"u"&&typeof window.Buffer<"u"?c=window.Buffer:c=hf("buffer").Buffer}catch{}a.isBN=function(o){return o instanceof a?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===a.wordSize&&Array.isArray(o.words)},a.max=function(o,l){return o.cmp(l)>0?o:l},a.min=function(o,l){return o.cmp(l)<0?o:l},a.prototype._init=function(o,l,d){if(typeof o=="number")return this._initNumber(o,l,d);if(typeof o=="object")return this._initArray(o,l,d);l==="hex"&&(l=16),n(l===(l|0)&&l>=2&&l<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(l===16?this._parseHex(o,m,d):(this._parseBase(o,l,m),d==="le"&&this._initArray(this.toArray(),l,d)))},a.prototype._initNumber=function(o,l,d){o<0&&(this.negative=1,o=-o),o<67108864?(this.words=[o&67108863],this.length=1):o<4503599627370496?(this.words=[o&67108863,o/67108864&67108863],this.length=2):(n(o<9007199254740992),this.words=[o&67108863,o/67108864&67108863,1],this.length=3),d==="le"&&this._initArray(this.toArray(),l,d)},a.prototype._initArray=function(o,l,d){if(n(typeof o.length=="number"),o.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(o.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var _,b,w=0;if(d==="be")for(m=o.length-1,_=0;m>=0;m-=3)b=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[_]|=b<<w&67108863,this.words[_+1]=b>>>26-w&67108863,w+=24,w>=26&&(w-=26,_++);else if(d==="le")for(m=0,_=0;m<o.length;m+=3)b=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[_]|=b<<w&67108863,this.words[_+1]=b>>>26-w&67108863,w+=24,w>=26&&(w-=26,_++);return this._strip()};function p(o,l){var d=o.charCodeAt(l);if(d>=48&&d<=57)return d-48;if(d>=65&&d<=70)return d-55;if(d>=97&&d<=102)return d-87;n(!1,"Invalid character in "+o)}function g(o,l,d){var m=p(o,d);return d-1>=l&&(m|=p(o,d-1)<<4),m}a.prototype._parseHex=function(o,l,d){this.length=Math.ceil((o.length-l)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var _=0,b=0,w;if(d==="be")for(m=o.length-1;m>=l;m-=2)w=g(o,l,m)<<_,this.words[b]|=w&67108863,_>=18?(_-=18,b+=1,this.words[b]|=w>>>26):_+=8;else{var f=o.length-l;for(m=f%2===0?l+1:l;m<o.length;m+=2)w=g(o,l,m)<<_,this.words[b]|=w&67108863,_>=18?(_-=18,b+=1,this.words[b]|=w>>>26):_+=8}this._strip()};function v(o,l,d,m){for(var _=0,b=0,w=Math.min(o.length,d),f=l;f<w;f++){var u=o.charCodeAt(f)-48;_*=m,u>=49?b=u-49+10:u>=17?b=u-17+10:b=u,n(u>=0&&b<m,"Invalid character"),_+=b}return _}a.prototype._parseBase=function(o,l,d){this.words=[0],this.length=1;for(var m=0,_=1;_<=67108863;_*=l)m++;m--,_=_/l|0;for(var b=o.length-d,w=b%m,f=Math.min(b,b-w)+d,u=0,M=d;M<f;M+=m)u=v(o,M,M+m,l),this.imuln(_),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(w!==0){var q=1;for(u=v(o,M,o.length,l),M=0;M<w;M++)q*=l;this.imuln(q),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},a.prototype.copy=function(o){o.words=new Array(this.length);for(var l=0;l<this.length;l++)o.words[l]=this.words[l];o.length=this.length,o.negative=this.negative,o.red=this.red};function y(o,l){o.words=l.words,o.length=l.length,o.negative=l.negative,o.red=l.red}if(a.prototype._move=function(o){y(o,this)},a.prototype.clone=function(){var o=new a(null);return this.copy(o),o},a.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},a.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{a.prototype[Symbol.for("nodejs.util.inspect.custom")]=A}catch{a.prototype.inspect=A}else a.prototype.inspect=A;function A(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var k=["","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"],U=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],P=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];a.prototype.toString=function(o,l){o=o||10,l=l|0||1;var d;if(o===16||o==="hex"){d="";for(var m=0,_=0,b=0;b<this.length;b++){var w=this.words[b],f=((w<<m|_)&16777215).toString(16);_=w>>>24-m&16777215,m+=2,m>=26&&(m-=26,b--),_!==0||b!==this.length-1?d=k[6-f.length]+f+d:d=f+d}for(_!==0&&(d=_.toString(16)+d);d.length%l!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}if(o===(o|0)&&o>=2&&o<=36){var u=U[o],M=P[o];d="";var q=this.clone();for(q.negative=0;!q.isZero();){var $=q.modrn(M).toString(o);q=q.idivn(M),q.isZero()?d=$+d:d=k[u-$.length]+$+d}for(this.isZero()&&(d="0"+d);d.length%l!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}n(!1,"Base should be between 2 and 36")},a.prototype.toNumber=function(){var o=this.words[0];return this.length===2?o+=this.words[1]*67108864:this.length===3&&this.words[2]===1?o+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-o:o},a.prototype.toJSON=function(){return this.toString(16,2)},c&&(a.prototype.toBuffer=function(o,l){return this.toArrayLike(c,o,l)}),a.prototype.toArray=function(o,l){return this.toArrayLike(Array,o,l)};var W=function(o,l){return o.allocUnsafe?o.allocUnsafe(l):new o(l)};a.prototype.toArrayLike=function(o,l,d){this._strip();var m=this.byteLength(),_=d||Math.max(1,m);n(m<=_,"byte array longer than desired length"),n(_>0,"Requested array length <= 0");var b=W(o,_),w=l==="le"?"LE":"BE";return this["_toArrayLike"+w](b,m),b},a.prototype._toArrayLikeLE=function(o,l){for(var d=0,m=0,_=0,b=0;_<this.length;_++){var w=this.words[_]<<b|m;o[d++]=w&255,d<o.length&&(o[d++]=w>>8&255),d<o.length&&(o[d++]=w>>16&255),b===6?(d<o.length&&(o[d++]=w>>24&255),m=0,b=0):(m=w>>>24,b+=2)}if(d<o.length)for(o[d++]=m;d<o.length;)o[d++]=0},a.prototype._toArrayLikeBE=function(o,l){for(var d=o.length-1,m=0,_=0,b=0;_<this.length;_++){var w=this.words[_]<<b|m;o[d--]=w&255,d>=0&&(o[d--]=w>>8&255),d>=0&&(o[d--]=w>>16&255),b===6?(d>=0&&(o[d--]=w>>24&255),m=0,b=0):(m=w>>>24,b+=2)}if(d>=0)for(o[d--]=m;d>=0;)o[d--]=0},Math.clz32?a.prototype._countBits=function(o){return 32-Math.clz32(o)}:a.prototype._countBits=function(o){var l=o,d=0;return l>=4096&&(d+=13,l>>>=13),l>=64&&(d+=7,l>>>=7),l>=8&&(d+=4,l>>>=4),l>=2&&(d+=2,l>>>=2),d+l},a.prototype._zeroBits=function(o){if(o===0)return 26;var l=o,d=0;return(l&8191)===0&&(d+=13,l>>>=13),(l&127)===0&&(d+=7,l>>>=7),(l&15)===0&&(d+=4,l>>>=4),(l&3)===0&&(d+=2,l>>>=2),(l&1)===0&&d++,d},a.prototype.bitLength=function(){var o=this.words[this.length-1],l=this._countBits(o);return(this.length-1)*26+l};function j(o){for(var l=new Array(o.bitLength()),d=0;d<l.length;d++){var m=d/26|0,_=d%26;l[d]=o.words[m]>>>_&1}return l}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,l=0;l<this.length;l++){var d=this._zeroBits(this.words[l]);if(o+=d,d!==26)break}return o},a.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},a.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},a.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},a.prototype.isNeg=function(){return this.negative!==0},a.prototype.neg=function(){return this.clone().ineg()},a.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},a.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]|o.words[l];return this._strip()},a.prototype.ior=function(o){return n((this.negative|o.negative)===0),this.iuor(o)},a.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},a.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},a.prototype.iuand=function(o){var l;this.length>o.length?l=o:l=this;for(var d=0;d<l.length;d++)this.words[d]=this.words[d]&o.words[d];return this.length=l.length,this._strip()},a.prototype.iand=function(o){return n((this.negative|o.negative)===0),this.iuand(o)},a.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},a.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},a.prototype.iuxor=function(o){var l,d;this.length>o.length?(l=this,d=o):(l=o,d=this);for(var m=0;m<d.length;m++)this.words[m]=l.words[m]^d.words[m];if(this!==l)for(;m<l.length;m++)this.words[m]=l.words[m];return this.length=l.length,this._strip()},a.prototype.ixor=function(o){return n((this.negative|o.negative)===0),this.iuxor(o)},a.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},a.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},a.prototype.inotn=function(o){n(typeof o=="number"&&o>=0);var l=Math.ceil(o/26)|0,d=o%26;this._expand(l),d>0&&l--;for(var m=0;m<l;m++)this.words[m]=~this.words[m]&67108863;return d>0&&(this.words[m]=~this.words[m]&67108863>>26-d),this._strip()},a.prototype.notn=function(o){return this.clone().inotn(o)},a.prototype.setn=function(o,l){n(typeof o=="number"&&o>=0);var d=o/26|0,m=o%26;return this._expand(d+1),l?this.words[d]=this.words[d]|1<<m:this.words[d]=this.words[d]&~(1<<m),this._strip()},a.prototype.iadd=function(o){var l;if(this.negative!==0&&o.negative===0)return this.negative=0,l=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,l=this.isub(o),o.negative=1,l._normSign();var d,m;this.length>o.length?(d=this,m=o):(d=o,m=this);for(var _=0,b=0;b<m.length;b++)l=(d.words[b]|0)+(m.words[b]|0)+_,this.words[b]=l&67108863,_=l>>>26;for(;_!==0&&b<d.length;b++)l=(d.words[b]|0)+_,this.words[b]=l&67108863,_=l>>>26;if(this.length=d.length,_!==0)this.words[this.length]=_,this.length++;else if(d!==this)for(;b<d.length;b++)this.words[b]=d.words[b];return this},a.prototype.add=function(o){var l;return o.negative!==0&&this.negative===0?(o.negative=0,l=this.sub(o),o.negative^=1,l):o.negative===0&&this.negative!==0?(this.negative=0,l=o.sub(this),this.negative=1,l):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},a.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var l=this.iadd(o);return o.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var d=this.cmp(o);if(d===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,_;d>0?(m=this,_=o):(m=o,_=this);for(var b=0,w=0;w<_.length;w++)l=(m.words[w]|0)-(_.words[w]|0)+b,b=l>>26,this.words[w]=l&67108863;for(;b!==0&&w<m.length;w++)l=(m.words[w]|0)+b,b=l>>26,this.words[w]=l&67108863;if(b===0&&w<m.length&&m!==this)for(;w<m.length;w++)this.words[w]=m.words[w];return this.length=Math.max(this.length,w),m!==this&&(this.negative=1),this._strip()},a.prototype.sub=function(o){return this.clone().isub(o)};function K(o,l,d){d.negative=l.negative^o.negative;var m=o.length+l.length|0;d.length=m,m=m-1|0;var _=o.words[0]|0,b=l.words[0]|0,w=_*b,f=w&67108863,u=w/67108864|0;d.words[0]=f;for(var M=1;M<m;M++){for(var q=u>>>26,$=u&67108863,z=Math.min(M,l.length-1),ie=Math.max(0,M-o.length+1);ie<=z;ie++){var C=M-ie|0;_=o.words[C]|0,b=l.words[ie]|0,w=_*b+$,q+=w/67108864|0,$=w&67108863}d.words[M]=$|0,u=q|0}return u!==0?d.words[M]=u|0:d.length--,d._strip()}var X=function(o,l,d){var m=o.words,_=l.words,b=d.words,w=0,f,u,M,q=m[0]|0,$=q&8191,z=q>>>13,ie=m[1]|0,C=ie&8191,T=ie>>>13,x=m[2]|0,F=x&8191,L=x>>>13,G=m[3]|0,B=G&8191,D=G>>>13,Z=m[4]|0,H=Z&8191,V=Z>>>13,ee=m[5]|0,te=ee&8191,ue=ee>>>13,Te=m[6]|0,he=Te&8191,_e=Te>>>13,ke=m[7]|0,ce=ke&8191,Ie=ke>>>13,st=m[8]|0,ge=st&8191,Be=st>>>13,rt=m[9]|0,me=rt&8191,Oe=rt>>>13,et=_[0]|0,fe=et&8191,Ge=et>>>13,ht=_[1]|0,ve=ht&8191,Ve=ht>>>13,ft=_[2]|0,we=ft&8191,Ze=ft>>>13,pt=_[3]|0,be=pt&8191,Ke=pt>>>13,mt=_[4]|0,ye=mt&8191,We=mt>>>13,gt=_[5]|0,Me=gt&8191,ze=gt>>>13,_t=_[6]|0,Ae=_t&8191,Xe=_t>>>13,vt=_[7]|0,Se=vt&8191,Je=vt>>>13,wt=_[8]|0,Ce=wt&8191,Ye=wt>>>13,bt=_[9]|0,Ee=bt&8191,He=bt>>>13;d.negative=o.negative^l.negative,d.length=19,f=Math.imul($,fe),u=Math.imul($,Ge),u=u+Math.imul(z,fe)|0,M=Math.imul(z,Ge);var Jt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,f=Math.imul(C,fe),u=Math.imul(C,Ge),u=u+Math.imul(T,fe)|0,M=Math.imul(T,Ge),f=f+Math.imul($,ve)|0,u=u+Math.imul($,Ve)|0,u=u+Math.imul(z,ve)|0,M=M+Math.imul(z,Ve)|0;var Yt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,f=Math.imul(F,fe),u=Math.imul(F,Ge),u=u+Math.imul(L,fe)|0,M=Math.imul(L,Ge),f=f+Math.imul(C,ve)|0,u=u+Math.imul(C,Ve)|0,u=u+Math.imul(T,ve)|0,M=M+Math.imul(T,Ve)|0,f=f+Math.imul($,we)|0,u=u+Math.imul($,Ze)|0,u=u+Math.imul(z,we)|0,M=M+Math.imul(z,Ze)|0;var Qt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,f=Math.imul(B,fe),u=Math.imul(B,Ge),u=u+Math.imul(D,fe)|0,M=Math.imul(D,Ge),f=f+Math.imul(F,ve)|0,u=u+Math.imul(F,Ve)|0,u=u+Math.imul(L,ve)|0,M=M+Math.imul(L,Ve)|0,f=f+Math.imul(C,we)|0,u=u+Math.imul(C,Ze)|0,u=u+Math.imul(T,we)|0,M=M+Math.imul(T,Ze)|0,f=f+Math.imul($,be)|0,u=u+Math.imul($,Ke)|0,u=u+Math.imul(z,be)|0,M=M+Math.imul(z,Ke)|0;var ei=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,f=Math.imul(H,fe),u=Math.imul(H,Ge),u=u+Math.imul(V,fe)|0,M=Math.imul(V,Ge),f=f+Math.imul(B,ve)|0,u=u+Math.imul(B,Ve)|0,u=u+Math.imul(D,ve)|0,M=M+Math.imul(D,Ve)|0,f=f+Math.imul(F,we)|0,u=u+Math.imul(F,Ze)|0,u=u+Math.imul(L,we)|0,M=M+Math.imul(L,Ze)|0,f=f+Math.imul(C,be)|0,u=u+Math.imul(C,Ke)|0,u=u+Math.imul(T,be)|0,M=M+Math.imul(T,Ke)|0,f=f+Math.imul($,ye)|0,u=u+Math.imul($,We)|0,u=u+Math.imul(z,ye)|0,M=M+Math.imul(z,We)|0;var ti=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,f=Math.imul(te,fe),u=Math.imul(te,Ge),u=u+Math.imul(ue,fe)|0,M=Math.imul(ue,Ge),f=f+Math.imul(H,ve)|0,u=u+Math.imul(H,Ve)|0,u=u+Math.imul(V,ve)|0,M=M+Math.imul(V,Ve)|0,f=f+Math.imul(B,we)|0,u=u+Math.imul(B,Ze)|0,u=u+Math.imul(D,we)|0,M=M+Math.imul(D,Ze)|0,f=f+Math.imul(F,be)|0,u=u+Math.imul(F,Ke)|0,u=u+Math.imul(L,be)|0,M=M+Math.imul(L,Ke)|0,f=f+Math.imul(C,ye)|0,u=u+Math.imul(C,We)|0,u=u+Math.imul(T,ye)|0,M=M+Math.imul(T,We)|0,f=f+Math.imul($,Me)|0,u=u+Math.imul($,ze)|0,u=u+Math.imul(z,Me)|0,M=M+Math.imul(z,ze)|0;var ii=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,f=Math.imul(he,fe),u=Math.imul(he,Ge),u=u+Math.imul(_e,fe)|0,M=Math.imul(_e,Ge),f=f+Math.imul(te,ve)|0,u=u+Math.imul(te,Ve)|0,u=u+Math.imul(ue,ve)|0,M=M+Math.imul(ue,Ve)|0,f=f+Math.imul(H,we)|0,u=u+Math.imul(H,Ze)|0,u=u+Math.imul(V,we)|0,M=M+Math.imul(V,Ze)|0,f=f+Math.imul(B,be)|0,u=u+Math.imul(B,Ke)|0,u=u+Math.imul(D,be)|0,M=M+Math.imul(D,Ke)|0,f=f+Math.imul(F,ye)|0,u=u+Math.imul(F,We)|0,u=u+Math.imul(L,ye)|0,M=M+Math.imul(L,We)|0,f=f+Math.imul(C,Me)|0,u=u+Math.imul(C,ze)|0,u=u+Math.imul(T,Me)|0,M=M+Math.imul(T,ze)|0,f=f+Math.imul($,Ae)|0,u=u+Math.imul($,Xe)|0,u=u+Math.imul(z,Ae)|0,M=M+Math.imul(z,Xe)|0;var ri=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,f=Math.imul(ce,fe),u=Math.imul(ce,Ge),u=u+Math.imul(Ie,fe)|0,M=Math.imul(Ie,Ge),f=f+Math.imul(he,ve)|0,u=u+Math.imul(he,Ve)|0,u=u+Math.imul(_e,ve)|0,M=M+Math.imul(_e,Ve)|0,f=f+Math.imul(te,we)|0,u=u+Math.imul(te,Ze)|0,u=u+Math.imul(ue,we)|0,M=M+Math.imul(ue,Ze)|0,f=f+Math.imul(H,be)|0,u=u+Math.imul(H,Ke)|0,u=u+Math.imul(V,be)|0,M=M+Math.imul(V,Ke)|0,f=f+Math.imul(B,ye)|0,u=u+Math.imul(B,We)|0,u=u+Math.imul(D,ye)|0,M=M+Math.imul(D,We)|0,f=f+Math.imul(F,Me)|0,u=u+Math.imul(F,ze)|0,u=u+Math.imul(L,Me)|0,M=M+Math.imul(L,ze)|0,f=f+Math.imul(C,Ae)|0,u=u+Math.imul(C,Xe)|0,u=u+Math.imul(T,Ae)|0,M=M+Math.imul(T,Xe)|0,f=f+Math.imul($,Se)|0,u=u+Math.imul($,Je)|0,u=u+Math.imul(z,Se)|0,M=M+Math.imul(z,Je)|0;var ni=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,f=Math.imul(ge,fe),u=Math.imul(ge,Ge),u=u+Math.imul(Be,fe)|0,M=Math.imul(Be,Ge),f=f+Math.imul(ce,ve)|0,u=u+Math.imul(ce,Ve)|0,u=u+Math.imul(Ie,ve)|0,M=M+Math.imul(Ie,Ve)|0,f=f+Math.imul(he,we)|0,u=u+Math.imul(he,Ze)|0,u=u+Math.imul(_e,we)|0,M=M+Math.imul(_e,Ze)|0,f=f+Math.imul(te,be)|0,u=u+Math.imul(te,Ke)|0,u=u+Math.imul(ue,be)|0,M=M+Math.imul(ue,Ke)|0,f=f+Math.imul(H,ye)|0,u=u+Math.imul(H,We)|0,u=u+Math.imul(V,ye)|0,M=M+Math.imul(V,We)|0,f=f+Math.imul(B,Me)|0,u=u+Math.imul(B,ze)|0,u=u+Math.imul(D,Me)|0,M=M+Math.imul(D,ze)|0,f=f+Math.imul(F,Ae)|0,u=u+Math.imul(F,Xe)|0,u=u+Math.imul(L,Ae)|0,M=M+Math.imul(L,Xe)|0,f=f+Math.imul(C,Se)|0,u=u+Math.imul(C,Je)|0,u=u+Math.imul(T,Se)|0,M=M+Math.imul(T,Je)|0,f=f+Math.imul($,Ce)|0,u=u+Math.imul($,Ye)|0,u=u+Math.imul(z,Ce)|0,M=M+Math.imul(z,Ye)|0;var oi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,f=Math.imul(me,fe),u=Math.imul(me,Ge),u=u+Math.imul(Oe,fe)|0,M=Math.imul(Oe,Ge),f=f+Math.imul(ge,ve)|0,u=u+Math.imul(ge,Ve)|0,u=u+Math.imul(Be,ve)|0,M=M+Math.imul(Be,Ve)|0,f=f+Math.imul(ce,we)|0,u=u+Math.imul(ce,Ze)|0,u=u+Math.imul(Ie,we)|0,M=M+Math.imul(Ie,Ze)|0,f=f+Math.imul(he,be)|0,u=u+Math.imul(he,Ke)|0,u=u+Math.imul(_e,be)|0,M=M+Math.imul(_e,Ke)|0,f=f+Math.imul(te,ye)|0,u=u+Math.imul(te,We)|0,u=u+Math.imul(ue,ye)|0,M=M+Math.imul(ue,We)|0,f=f+Math.imul(H,Me)|0,u=u+Math.imul(H,ze)|0,u=u+Math.imul(V,Me)|0,M=M+Math.imul(V,ze)|0,f=f+Math.imul(B,Ae)|0,u=u+Math.imul(B,Xe)|0,u=u+Math.imul(D,Ae)|0,M=M+Math.imul(D,Xe)|0,f=f+Math.imul(F,Se)|0,u=u+Math.imul(F,Je)|0,u=u+Math.imul(L,Se)|0,M=M+Math.imul(L,Je)|0,f=f+Math.imul(C,Ce)|0,u=u+Math.imul(C,Ye)|0,u=u+Math.imul(T,Ce)|0,M=M+Math.imul(T,Ye)|0,f=f+Math.imul($,Ee)|0,u=u+Math.imul($,He)|0,u=u+Math.imul(z,Ee)|0,M=M+Math.imul(z,He)|0;var si=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(si>>>26)|0,si&=67108863,f=Math.imul(me,ve),u=Math.imul(me,Ve),u=u+Math.imul(Oe,ve)|0,M=Math.imul(Oe,Ve),f=f+Math.imul(ge,we)|0,u=u+Math.imul(ge,Ze)|0,u=u+Math.imul(Be,we)|0,M=M+Math.imul(Be,Ze)|0,f=f+Math.imul(ce,be)|0,u=u+Math.imul(ce,Ke)|0,u=u+Math.imul(Ie,be)|0,M=M+Math.imul(Ie,Ke)|0,f=f+Math.imul(he,ye)|0,u=u+Math.imul(he,We)|0,u=u+Math.imul(_e,ye)|0,M=M+Math.imul(_e,We)|0,f=f+Math.imul(te,Me)|0,u=u+Math.imul(te,ze)|0,u=u+Math.imul(ue,Me)|0,M=M+Math.imul(ue,ze)|0,f=f+Math.imul(H,Ae)|0,u=u+Math.imul(H,Xe)|0,u=u+Math.imul(V,Ae)|0,M=M+Math.imul(V,Xe)|0,f=f+Math.imul(B,Se)|0,u=u+Math.imul(B,Je)|0,u=u+Math.imul(D,Se)|0,M=M+Math.imul(D,Je)|0,f=f+Math.imul(F,Ce)|0,u=u+Math.imul(F,Ye)|0,u=u+Math.imul(L,Ce)|0,M=M+Math.imul(L,Ye)|0,f=f+Math.imul(C,Ee)|0,u=u+Math.imul(C,He)|0,u=u+Math.imul(T,Ee)|0,M=M+Math.imul(T,He)|0;var ai=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,f=Math.imul(me,we),u=Math.imul(me,Ze),u=u+Math.imul(Oe,we)|0,M=Math.imul(Oe,Ze),f=f+Math.imul(ge,be)|0,u=u+Math.imul(ge,Ke)|0,u=u+Math.imul(Be,be)|0,M=M+Math.imul(Be,Ke)|0,f=f+Math.imul(ce,ye)|0,u=u+Math.imul(ce,We)|0,u=u+Math.imul(Ie,ye)|0,M=M+Math.imul(Ie,We)|0,f=f+Math.imul(he,Me)|0,u=u+Math.imul(he,ze)|0,u=u+Math.imul(_e,Me)|0,M=M+Math.imul(_e,ze)|0,f=f+Math.imul(te,Ae)|0,u=u+Math.imul(te,Xe)|0,u=u+Math.imul(ue,Ae)|0,M=M+Math.imul(ue,Xe)|0,f=f+Math.imul(H,Se)|0,u=u+Math.imul(H,Je)|0,u=u+Math.imul(V,Se)|0,M=M+Math.imul(V,Je)|0,f=f+Math.imul(B,Ce)|0,u=u+Math.imul(B,Ye)|0,u=u+Math.imul(D,Ce)|0,M=M+Math.imul(D,Ye)|0,f=f+Math.imul(F,Ee)|0,u=u+Math.imul(F,He)|0,u=u+Math.imul(L,Ee)|0,M=M+Math.imul(L,He)|0;var li=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(li>>>26)|0,li&=67108863,f=Math.imul(me,be),u=Math.imul(me,Ke),u=u+Math.imul(Oe,be)|0,M=Math.imul(Oe,Ke),f=f+Math.imul(ge,ye)|0,u=u+Math.imul(ge,We)|0,u=u+Math.imul(Be,ye)|0,M=M+Math.imul(Be,We)|0,f=f+Math.imul(ce,Me)|0,u=u+Math.imul(ce,ze)|0,u=u+Math.imul(Ie,Me)|0,M=M+Math.imul(Ie,ze)|0,f=f+Math.imul(he,Ae)|0,u=u+Math.imul(he,Xe)|0,u=u+Math.imul(_e,Ae)|0,M=M+Math.imul(_e,Xe)|0,f=f+Math.imul(te,Se)|0,u=u+Math.imul(te,Je)|0,u=u+Math.imul(ue,Se)|0,M=M+Math.imul(ue,Je)|0,f=f+Math.imul(H,Ce)|0,u=u+Math.imul(H,Ye)|0,u=u+Math.imul(V,Ce)|0,M=M+Math.imul(V,Ye)|0,f=f+Math.imul(B,Ee)|0,u=u+Math.imul(B,He)|0,u=u+Math.imul(D,Ee)|0,M=M+Math.imul(D,He)|0;var ui=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ui>>>26)|0,ui&=67108863,f=Math.imul(me,ye),u=Math.imul(me,We),u=u+Math.imul(Oe,ye)|0,M=Math.imul(Oe,We),f=f+Math.imul(ge,Me)|0,u=u+Math.imul(ge,ze)|0,u=u+Math.imul(Be,Me)|0,M=M+Math.imul(Be,ze)|0,f=f+Math.imul(ce,Ae)|0,u=u+Math.imul(ce,Xe)|0,u=u+Math.imul(Ie,Ae)|0,M=M+Math.imul(Ie,Xe)|0,f=f+Math.imul(he,Se)|0,u=u+Math.imul(he,Je)|0,u=u+Math.imul(_e,Se)|0,M=M+Math.imul(_e,Je)|0,f=f+Math.imul(te,Ce)|0,u=u+Math.imul(te,Ye)|0,u=u+Math.imul(ue,Ce)|0,M=M+Math.imul(ue,Ye)|0,f=f+Math.imul(H,Ee)|0,u=u+Math.imul(H,He)|0,u=u+Math.imul(V,Ee)|0,M=M+Math.imul(V,He)|0;var ci=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ci>>>26)|0,ci&=67108863,f=Math.imul(me,Me),u=Math.imul(me,ze),u=u+Math.imul(Oe,Me)|0,M=Math.imul(Oe,ze),f=f+Math.imul(ge,Ae)|0,u=u+Math.imul(ge,Xe)|0,u=u+Math.imul(Be,Ae)|0,M=M+Math.imul(Be,Xe)|0,f=f+Math.imul(ce,Se)|0,u=u+Math.imul(ce,Je)|0,u=u+Math.imul(Ie,Se)|0,M=M+Math.imul(Ie,Je)|0,f=f+Math.imul(he,Ce)|0,u=u+Math.imul(he,Ye)|0,u=u+Math.imul(_e,Ce)|0,M=M+Math.imul(_e,Ye)|0,f=f+Math.imul(te,Ee)|0,u=u+Math.imul(te,He)|0,u=u+Math.imul(ue,Ee)|0,M=M+Math.imul(ue,He)|0;var di=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(di>>>26)|0,di&=67108863,f=Math.imul(me,Ae),u=Math.imul(me,Xe),u=u+Math.imul(Oe,Ae)|0,M=Math.imul(Oe,Xe),f=f+Math.imul(ge,Se)|0,u=u+Math.imul(ge,Je)|0,u=u+Math.imul(Be,Se)|0,M=M+Math.imul(Be,Je)|0,f=f+Math.imul(ce,Ce)|0,u=u+Math.imul(ce,Ye)|0,u=u+Math.imul(Ie,Ce)|0,M=M+Math.imul(Ie,Ye)|0,f=f+Math.imul(he,Ee)|0,u=u+Math.imul(he,He)|0,u=u+Math.imul(_e,Ee)|0,M=M+Math.imul(_e,He)|0;var hi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(hi>>>26)|0,hi&=67108863,f=Math.imul(me,Se),u=Math.imul(me,Je),u=u+Math.imul(Oe,Se)|0,M=Math.imul(Oe,Je),f=f+Math.imul(ge,Ce)|0,u=u+Math.imul(ge,Ye)|0,u=u+Math.imul(Be,Ce)|0,M=M+Math.imul(Be,Ye)|0,f=f+Math.imul(ce,Ee)|0,u=u+Math.imul(ce,He)|0,u=u+Math.imul(Ie,Ee)|0,M=M+Math.imul(Ie,He)|0;var fi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(fi>>>26)|0,fi&=67108863,f=Math.imul(me,Ce),u=Math.imul(me,Ye),u=u+Math.imul(Oe,Ce)|0,M=Math.imul(Oe,Ye),f=f+Math.imul(ge,Ee)|0,u=u+Math.imul(ge,He)|0,u=u+Math.imul(Be,Ee)|0,M=M+Math.imul(Be,He)|0;var pi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(pi>>>26)|0,pi&=67108863,f=Math.imul(me,Ee),u=Math.imul(me,He),u=u+Math.imul(Oe,Ee)|0,M=Math.imul(Oe,He);var nr=(w+f|0)+((u&8191)<<13)|0;return w=(M+(u>>>13)|0)+(nr>>>26)|0,nr&=67108863,b[0]=Jt,b[1]=Yt,b[2]=Qt,b[3]=ei,b[4]=ti,b[5]=ii,b[6]=ri,b[7]=ni,b[8]=oi,b[9]=si,b[10]=ai,b[11]=li,b[12]=ui,b[13]=ci,b[14]=di,b[15]=hi,b[16]=fi,b[17]=pi,b[18]=nr,w!==0&&(b[19]=w,d.length++),d};Math.imul||(X=K);function Q(o,l,d){d.negative=l.negative^o.negative,d.length=o.length+l.length;for(var m=0,_=0,b=0;b<d.length-1;b++){var w=_;_=0;for(var f=m&67108863,u=Math.min(b,l.length-1),M=Math.max(0,b-o.length+1);M<=u;M++){var q=b-M,$=o.words[q]|0,z=l.words[M]|0,ie=$*z,C=ie&67108863;w=w+(ie/67108864|0)|0,C=C+f|0,f=C&67108863,w=w+(C>>>26)|0,_+=w>>>26,w&=67108863}d.words[b]=f,m=w,w=_}return m!==0?d.words[b]=m:d.length--,d._strip()}function se(o,l,d){return Q(o,l,d)}a.prototype.mulTo=function(o,l){var d,m=this.length+o.length;return this.length===10&&o.length===10?d=X(this,o,l):m<63?d=K(this,o,l):m<1024?d=Q(this,o,l):d=se(this,o,l),d};function Y(o,l){this.x=o,this.y=l}Y.prototype.makeRBT=function(o){for(var l=new Array(o),d=a.prototype._countBits(o)-1,m=0;m<o;m++)l[m]=this.revBin(m,d,o);return l},Y.prototype.revBin=function(o,l,d){if(o===0||o===d-1)return o;for(var m=0,_=0;_<l;_++)m|=(o&1)<<l-_-1,o>>=1;return m},Y.prototype.permute=function(o,l,d,m,_,b){for(var w=0;w<b;w++)m[w]=l[o[w]],_[w]=d[o[w]]},Y.prototype.transform=function(o,l,d,m,_,b){this.permute(b,o,l,d,m,_);for(var w=1;w<_;w<<=1)for(var f=w<<1,u=Math.cos(2*Math.PI/f),M=Math.sin(2*Math.PI/f),q=0;q<_;q+=f)for(var $=u,z=M,ie=0;ie<w;ie++){var C=d[q+ie],T=m[q+ie],x=d[q+ie+w],F=m[q+ie+w],L=$*x-z*F;F=$*F+z*x,x=L,d[q+ie]=C+x,m[q+ie]=T+F,d[q+ie+w]=C-x,m[q+ie+w]=T-F,ie!==f&&(L=u*$-M*z,z=u*z+M*$,$=L)}},Y.prototype.guessLen13b=function(o,l){var d=Math.max(l,o)|1,m=d&1,_=0;for(d=d/2|0;d;d=d>>>1)_++;return 1<<_+1+m},Y.prototype.conjugate=function(o,l,d){if(!(d<=1))for(var m=0;m<d/2;m++){var _=o[m];o[m]=o[d-m-1],o[d-m-1]=_,_=l[m],l[m]=-l[d-m-1],l[d-m-1]=-_}},Y.prototype.normalize13b=function(o,l){for(var d=0,m=0;m<l/2;m++){var _=Math.round(o[2*m+1]/l)*8192+Math.round(o[2*m]/l)+d;o[m]=_&67108863,_<67108864?d=0:d=_/67108864|0}return o},Y.prototype.convert13b=function(o,l,d,m){for(var _=0,b=0;b<l;b++)_=_+(o[b]|0),d[2*b]=_&8191,_=_>>>13,d[2*b+1]=_&8191,_=_>>>13;for(b=2*l;b<m;++b)d[b]=0;n(_===0),n((_&-8192)===0)},Y.prototype.stub=function(o){for(var l=new Array(o),d=0;d<o;d++)l[d]=0;return l},Y.prototype.mulp=function(o,l,d){var m=2*this.guessLen13b(o.length,l.length),_=this.makeRBT(m),b=this.stub(m),w=new Array(m),f=new Array(m),u=new Array(m),M=new Array(m),q=new Array(m),$=new Array(m),z=d.words;z.length=m,this.convert13b(o.words,o.length,w,m),this.convert13b(l.words,l.length,M,m),this.transform(w,b,f,u,m,_),this.transform(M,b,q,$,m,_);for(var ie=0;ie<m;ie++){var C=f[ie]*q[ie]-u[ie]*$[ie];u[ie]=f[ie]*$[ie]+u[ie]*q[ie],f[ie]=C}return this.conjugate(f,u,m),this.transform(f,u,z,b,m,_),this.conjugate(z,b,m),this.normalize13b(z,m),d.negative=o.negative^l.negative,d.length=o.length+l.length,d._strip()},a.prototype.mul=function(o){var l=new a(null);return l.words=new Array(this.length+o.length),this.mulTo(o,l)},a.prototype.mulf=function(o){var l=new a(null);return l.words=new Array(this.length+o.length),se(this,o,l)},a.prototype.imul=function(o){return this.clone().mulTo(o,this)},a.prototype.imuln=function(o){var l=o<0;l&&(o=-o),n(typeof o=="number"),n(o<67108864);for(var d=0,m=0;m<this.length;m++){var _=(this.words[m]|0)*o,b=(_&67108863)+(d&67108863);d>>=26,d+=_/67108864|0,d+=b>>>26,this.words[m]=b&67108863}return d!==0&&(this.words[m]=d,this.length++),this.length=o===0?1:this.length,l?this.ineg():this},a.prototype.muln=function(o){return this.clone().imuln(o)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(o){var l=j(o);if(l.length===0)return new a(1);for(var d=this,m=0;m<l.length&&l[m]===0;m++,d=d.sqr());if(++m<l.length)for(var _=d.sqr();m<l.length;m++,_=_.sqr())l[m]!==0&&(d=d.mul(_));return d},a.prototype.iushln=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26,m=67108863>>>26-l<<26-l,_;if(l!==0){var b=0;for(_=0;_<this.length;_++){var w=this.words[_]&m,f=(this.words[_]|0)-w<<l;this.words[_]=f|b,b=w>>>26-l}b&&(this.words[_]=b,this.length++)}if(d!==0){for(_=this.length-1;_>=0;_--)this.words[_+d]=this.words[_];for(_=0;_<d;_++)this.words[_]=0;this.length+=d}return this._strip()},a.prototype.ishln=function(o){return n(this.negative===0),this.iushln(o)},a.prototype.iushrn=function(o,l,d){n(typeof o=="number"&&o>=0);var m;l?m=(l-l%26)/26:m=0;var _=o%26,b=Math.min((o-_)/26,this.length),w=67108863^67108863>>>_<<_,f=d;if(m-=b,m=Math.max(0,m),f){for(var u=0;u<b;u++)f.words[u]=this.words[u];f.length=b}if(b!==0)if(this.length>b)for(this.length-=b,u=0;u<this.length;u++)this.words[u]=this.words[u+b];else this.words[0]=0,this.length=1;var M=0;for(u=this.length-1;u>=0&&(M!==0||u>=m);u--){var q=this.words[u]|0;this.words[u]=M<<26-_|q>>>_,M=q&w}return f&&M!==0&&(f.words[f.length++]=M),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},a.prototype.ishrn=function(o,l,d){return n(this.negative===0),this.iushrn(o,l,d)},a.prototype.shln=function(o){return this.clone().ishln(o)},a.prototype.ushln=function(o){return this.clone().iushln(o)},a.prototype.shrn=function(o){return this.clone().ishrn(o)},a.prototype.ushrn=function(o){return this.clone().iushrn(o)},a.prototype.testn=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26,m=1<<l;if(this.length<=d)return!1;var _=this.words[d];return!!(_&m)},a.prototype.imaskn=function(o){n(typeof o=="number"&&o>=0);var l=o%26,d=(o-l)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=d)return this;if(l!==0&&d++,this.length=Math.min(d,this.length),l!==0){var m=67108863^67108863>>>l<<l;this.words[this.length-1]&=m}return this._strip()},a.prototype.maskn=function(o){return this.clone().imaskn(o)},a.prototype.iaddn=function(o){return n(typeof o=="number"),n(o<67108864),o<0?this.isubn(-o):this.negative!==0?this.length===1&&(this.words[0]|0)<=o?(this.words[0]=o-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(o),this.negative=1,this):this._iaddn(o)},a.prototype._iaddn=function(o){this.words[0]+=o;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},a.prototype.isubn=function(o){if(n(typeof o=="number"),n(o<67108864),o<0)return this.iaddn(-o);if(this.negative!==0)return this.negative=0,this.iaddn(o),this.negative=1,this;if(this.words[0]-=o,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},a.prototype.addn=function(o){return this.clone().iaddn(o)},a.prototype.subn=function(o){return this.clone().isubn(o)},a.prototype.iabs=function(){return this.negative=0,this},a.prototype.abs=function(){return this.clone().iabs()},a.prototype._ishlnsubmul=function(o,l,d){var m=o.length+d,_;this._expand(m);var b,w=0;for(_=0;_<o.length;_++){b=(this.words[_+d]|0)+w;var f=(o.words[_]|0)*l;b-=f&67108863,w=(b>>26)-(f/67108864|0),this.words[_+d]=b&67108863}for(;_<this.length-d;_++)b=(this.words[_+d]|0)+w,w=b>>26,this.words[_+d]=b&67108863;if(w===0)return this._strip();for(n(w===-1),w=0,_=0;_<this.length;_++)b=-(this.words[_]|0)+w,w=b>>26,this.words[_]=b&67108863;return this.negative=1,this._strip()},a.prototype._wordDiv=function(o,l){var d=this.length-o.length,m=this.clone(),_=o,b=_.words[_.length-1]|0,w=this._countBits(b);d=26-w,d!==0&&(_=_.ushln(d),m.iushln(d),b=_.words[_.length-1]|0);var f=m.length-_.length,u;if(l!=="mod"){u=new a(null),u.length=f+1,u.words=new Array(u.length);for(var M=0;M<u.length;M++)u.words[M]=0}var q=m.clone()._ishlnsubmul(_,1,f);q.negative===0&&(m=q,u&&(u.words[f]=1));for(var $=f-1;$>=0;$--){var z=(m.words[_.length+$]|0)*67108864+(m.words[_.length+$-1]|0);for(z=Math.min(z/b|0,67108863),m._ishlnsubmul(_,z,$);m.negative!==0;)z--,m.negative=0,m._ishlnsubmul(_,1,$),m.isZero()||(m.negative^=1);u&&(u.words[$]=z)}return u&&u._strip(),m._strip(),l!=="div"&&d!==0&&m.iushrn(d),{div:u||null,mod:m}},a.prototype.divmod=function(o,l,d){if(n(!o.isZero()),this.isZero())return{div:new a(0),mod:new a(0)};var m,_,b;return this.negative!==0&&o.negative===0?(b=this.neg().divmod(o,l),l!=="mod"&&(m=b.div.neg()),l!=="div"&&(_=b.mod.neg(),d&&_.negative!==0&&_.iadd(o)),{div:m,mod:_}):this.negative===0&&o.negative!==0?(b=this.divmod(o.neg(),l),l!=="mod"&&(m=b.div.neg()),{div:m,mod:b.mod}):(this.negative&o.negative)!==0?(b=this.neg().divmod(o.neg(),l),l!=="div"&&(_=b.mod.neg(),d&&_.negative!==0&&_.isub(o)),{div:b.div,mod:_}):o.length>this.length||this.cmp(o)<0?{div:new a(0),mod:this}:o.length===1?l==="div"?{div:this.divn(o.words[0]),mod:null}:l==="mod"?{div:null,mod:new a(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new a(this.modrn(o.words[0]))}:this._wordDiv(o,l)},a.prototype.div=function(o){return this.divmod(o,"div",!1).div},a.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},a.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},a.prototype.divRound=function(o){var l=this.divmod(o);if(l.mod.isZero())return l.div;var d=l.div.negative!==0?l.mod.isub(o):l.mod,m=o.ushrn(1),_=o.andln(1),b=d.cmp(m);return b<0||_===1&&b===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},a.prototype.modrn=function(o){var l=o<0;l&&(o=-o),n(o<=67108863);for(var d=(1<<26)%o,m=0,_=this.length-1;_>=0;_--)m=(d*m+(this.words[_]|0))%o;return l?-m:m},a.prototype.modn=function(o){return this.modrn(o)},a.prototype.idivn=function(o){var l=o<0;l&&(o=-o),n(o<=67108863);for(var d=0,m=this.length-1;m>=0;m--){var _=(this.words[m]|0)+d*67108864;this.words[m]=_/o|0,d=_%o}return this._strip(),l?this.ineg():this},a.prototype.divn=function(o){return this.clone().idivn(o)},a.prototype.egcd=function(o){n(o.negative===0),n(!o.isZero());var l=this,d=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new a(1),_=new a(0),b=new a(0),w=new a(1),f=0;l.isEven()&&d.isEven();)l.iushrn(1),d.iushrn(1),++f;for(var u=d.clone(),M=l.clone();!l.isZero();){for(var q=0,$=1;(l.words[0]&$)===0&&q<26;++q,$<<=1);if(q>0)for(l.iushrn(q);q-- >0;)(m.isOdd()||_.isOdd())&&(m.iadd(u),_.isub(M)),m.iushrn(1),_.iushrn(1);for(var z=0,ie=1;(d.words[0]&ie)===0&&z<26;++z,ie<<=1);if(z>0)for(d.iushrn(z);z-- >0;)(b.isOdd()||w.isOdd())&&(b.iadd(u),w.isub(M)),b.iushrn(1),w.iushrn(1);l.cmp(d)>=0?(l.isub(d),m.isub(b),_.isub(w)):(d.isub(l),b.isub(m),w.isub(_))}return{a:b,b:w,gcd:d.iushln(f)}},a.prototype._invmp=function(o){n(o.negative===0),n(!o.isZero());var l=this,d=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new a(1),_=new a(0),b=d.clone();l.cmpn(1)>0&&d.cmpn(1)>0;){for(var w=0,f=1;(l.words[0]&f)===0&&w<26;++w,f<<=1);if(w>0)for(l.iushrn(w);w-- >0;)m.isOdd()&&m.iadd(b),m.iushrn(1);for(var u=0,M=1;(d.words[0]&M)===0&&u<26;++u,M<<=1);if(u>0)for(d.iushrn(u);u-- >0;)_.isOdd()&&_.iadd(b),_.iushrn(1);l.cmp(d)>=0?(l.isub(d),m.isub(_)):(d.isub(l),_.isub(m))}var q;return l.cmpn(1)===0?q=m:q=_,q.cmpn(0)<0&&q.iadd(o),q},a.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var l=this.clone(),d=o.clone();l.negative=0,d.negative=0;for(var m=0;l.isEven()&&d.isEven();m++)l.iushrn(1),d.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;d.isEven();)d.iushrn(1);var _=l.cmp(d);if(_<0){var b=l;l=d,d=b}else if(_===0||d.cmpn(1)===0)break;l.isub(d)}while(!0);return d.iushln(m)},a.prototype.invm=function(o){return this.egcd(o).a.umod(o)},a.prototype.isEven=function(){return(this.words[0]&1)===0},a.prototype.isOdd=function(){return(this.words[0]&1)===1},a.prototype.andln=function(o){return this.words[0]&o},a.prototype.bincn=function(o){n(typeof o=="number");var l=o%26,d=(o-l)/26,m=1<<l;if(this.length<=d)return this._expand(d+1),this.words[d]|=m,this;for(var _=m,b=d;_!==0&&b<this.length;b++){var w=this.words[b]|0;w+=_,_=w>>>26,w&=67108863,this.words[b]=w}return _!==0&&(this.words[b]=_,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(o){var l=o<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var d;if(this.length>1)d=1;else{l&&(o=-o),n(o<=67108863,"Number is too big");var m=this.words[0]|0;d=m===o?0:m<o?-1:1}return this.negative!==0?-d|0:d},a.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var l=this.ucmp(o);return this.negative!==0?-l|0:l},a.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var l=0,d=this.length-1;d>=0;d--){var m=this.words[d]|0,_=o.words[d]|0;if(m!==_){m<_?l=-1:m>_&&(l=1);break}}return l},a.prototype.gtn=function(o){return this.cmpn(o)===1},a.prototype.gt=function(o){return this.cmp(o)===1},a.prototype.gten=function(o){return this.cmpn(o)>=0},a.prototype.gte=function(o){return this.cmp(o)>=0},a.prototype.ltn=function(o){return this.cmpn(o)===-1},a.prototype.lt=function(o){return this.cmp(o)===-1},a.prototype.lten=function(o){return this.cmpn(o)<=0},a.prototype.lte=function(o){return this.cmp(o)<=0},a.prototype.eqn=function(o){return this.cmpn(o)===0},a.prototype.eq=function(o){return this.cmp(o)===0},a.red=function(o){return new S(o)},a.prototype.toRed=function(o){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),o.convertTo(this)._forceRed(o)},a.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(o){return this.red=o,this},a.prototype.forceRed=function(o){return n(!this.red,"Already a number in reduction context"),this._forceRed(o)},a.prototype.redAdd=function(o){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},a.prototype.redIAdd=function(o){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},a.prototype.redSub=function(o){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},a.prototype.redISub=function(o){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},a.prototype.redShl=function(o){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},a.prototype.redMul=function(o){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},a.prototype.redIMul=function(o){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},a.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(o){return n(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var le={k256:null,p224:null,p192:null,p25519:null};function E(o,l){this.name=o,this.p=new a(l,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}E.prototype._tmp=function(){var o=new a(null);return o.words=new Array(Math.ceil(this.n/13)),o},E.prototype.ireduce=function(o){var l=o,d;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),d=l.bitLength();while(d>this.n);var m=d<this.n?-1:l.ucmp(this.p);return m===0?(l.words[0]=0,l.length=1):m>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},E.prototype.split=function(o,l){o.iushrn(this.n,0,l)},E.prototype.imulK=function(o){return o.imul(this.k)};function I(){E.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(I,E),I.prototype.split=function(o,l){for(var d=4194303,m=Math.min(o.length,9),_=0;_<m;_++)l.words[_]=o.words[_];if(l.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var b=o.words[9];for(l.words[l.length++]=b&d,_=10;_<o.length;_++){var w=o.words[_]|0;o.words[_-10]=(w&d)<<4|b>>>22,b=w}b>>>=22,o.words[_-10]=b,b===0&&o.length>10?o.length-=10:o.length-=9},I.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var l=0,d=0;d<o.length;d++){var m=o.words[d]|0;l+=m*977,o.words[d]=l&67108863,l=m*64+(l/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function O(){E.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(O,E);function R(){E.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(R,E);function N(){E.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(N,E),N.prototype.imulK=function(o){for(var l=0,d=0;d<o.length;d++){var m=(o.words[d]|0)*19+l,_=m&67108863;m>>>=26,o.words[d]=_,l=m}return l!==0&&(o.words[o.length++]=l),o},a._prime=function(o){if(le[o])return le[o];var l;if(o==="k256")l=new I;else if(o==="p224")l=new O;else if(o==="p192")l=new R;else if(o==="p25519")l=new N;else throw new Error("Unknown prime "+o);return le[o]=l,l};function S(o){if(typeof o=="string"){var l=a._prime(o);this.m=l.p,this.prime=l}else n(o.gtn(1),"modulus must be greater than 1"),this.m=o,this.prime=null}S.prototype._verify1=function(o){n(o.negative===0,"red works only with positives"),n(o.red,"red works only with red numbers")},S.prototype._verify2=function(o,l){n((o.negative|l.negative)===0,"red works only with positives"),n(o.red&&o.red===l.red,"red works only with red numbers")},S.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(y(o,o.umod(this.m)._forceRed(this)),o)},S.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},S.prototype.add=function(o,l){this._verify2(o,l);var d=o.add(l);return d.cmp(this.m)>=0&&d.isub(this.m),d._forceRed(this)},S.prototype.iadd=function(o,l){this._verify2(o,l);var d=o.iadd(l);return d.cmp(this.m)>=0&&d.isub(this.m),d},S.prototype.sub=function(o,l){this._verify2(o,l);var d=o.sub(l);return d.cmpn(0)<0&&d.iadd(this.m),d._forceRed(this)},S.prototype.isub=function(o,l){this._verify2(o,l);var d=o.isub(l);return d.cmpn(0)<0&&d.iadd(this.m),d},S.prototype.shl=function(o,l){return this._verify1(o),this.imod(o.ushln(l))},S.prototype.imul=function(o,l){return this._verify2(o,l),this.imod(o.imul(l))},S.prototype.mul=function(o,l){return this._verify2(o,l),this.imod(o.mul(l))},S.prototype.isqr=function(o){return this.imul(o,o.clone())},S.prototype.sqr=function(o){return this.mul(o,o)},S.prototype.sqrt=function(o){if(o.isZero())return o.clone();var l=this.m.andln(3);if(n(l%2===1),l===3){var d=this.m.add(new a(1)).iushrn(2);return this.pow(o,d)}for(var m=this.m.subn(1),_=0;!m.isZero()&&m.andln(1)===0;)_++,m.iushrn(1);n(!m.isZero());var b=new a(1).toRed(this),w=b.redNeg(),f=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new a(2*u*u).toRed(this);this.pow(u,f).cmp(w)!==0;)u.redIAdd(w);for(var M=this.pow(u,m),q=this.pow(o,m.addn(1).iushrn(1)),$=this.pow(o,m),z=_;$.cmp(b)!==0;){for(var ie=$,C=0;ie.cmp(b)!==0;C++)ie=ie.redSqr();n(C<z);var T=this.pow(M,new a(1).iushln(z-C-1));q=q.redMul(T),M=T.redSqr(),$=$.redMul(M),z=C}return q},S.prototype.invm=function(o){var l=o._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},S.prototype.pow=function(o,l){if(l.isZero())return new a(1).toRed(this);if(l.cmpn(1)===0)return o.clone();var d=4,m=new Array(1<<d);m[0]=new a(1).toRed(this),m[1]=o;for(var _=2;_<m.length;_++)m[_]=this.mul(m[_-1],o);var b=m[0],w=0,f=0,u=l.bitLength()%26;for(u===0&&(u=26),_=l.length-1;_>=0;_--){for(var M=l.words[_],q=u-1;q>=0;q--){var $=M>>q&1;if(b!==m[0]&&(b=this.sqr(b)),$===0&&w===0){f=0;continue}w<<=1,w|=$,f++,!(f!==d&&(_!==0||q!==0))&&(b=this.mul(b,m[w]),f=0,w=0)}u=26}return b},S.prototype.convertTo=function(o){var l=o.umod(this.m);return l===o?l.clone():l},S.prototype.convertFrom=function(o){var l=o.clone();return l.red=null,l},a.mont=function(o){return new h(o)};function h(o){S.call(this,o),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(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(h,S),h.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},h.prototype.convertFrom=function(o){var l=this.imod(o.mul(this.rinv));return l.red=null,l},h.prototype.imul=function(o,l){if(o.isZero()||l.isZero())return o.words[0]=0,o.length=1,o;var d=o.imul(l),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=d.isub(m).iushrn(this.shift),b=_;return _.cmp(this.m)>=0?b=_.isub(this.m):_.cmpn(0)<0&&(b=_.iadd(this.m)),b._forceRed(this)},h.prototype.mul=function(o,l){if(o.isZero()||l.isZero())return new a(0)._forceRed(this);var d=o.mul(l),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=d.isub(m).iushrn(this.shift),b=_;return _.cmp(this.m)>=0?b=_.isub(this.m):_.cmpn(0)<0&&(b=_.iadd(this.m)),b._forceRed(this)},h.prototype.invm=function(o){var l=this.imod(o._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof t>"u"||t,e)}),bl="3.7.8",mf=bl,Tr=typeof Buffer=="function",ll=typeof TextDecoder=="function"?new TextDecoder:void 0,ul=typeof TextEncoder=="function"?new TextEncoder:void 0,gf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Ur=Array.prototype.slice.call(gf),Nn=(e=>{let t={};return e.forEach((i,r)=>t[i]=r),t})(Ur),_f=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Lt=String.fromCharCode.bind(String),cl=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),yl=e=>e.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),Ml=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),Al=e=>{let t,i,r,n,s="",a=e.length%3;for(let c=0;c<e.length;){if((i=e.charCodeAt(c++))>255||(r=e.charCodeAt(c++))>255||(n=e.charCodeAt(c++))>255)throw new TypeError("invalid character found");t=i<<16|r<<8|n,s+=Ur[t>>18&63]+Ur[t>>12&63]+Ur[t>>6&63]+Ur[t&63]}return a?s.slice(0,a-3)+"===".substring(a):s},hs=typeof btoa=="function"?e=>btoa(e):Tr?e=>Buffer.from(e,"binary").toString("base64"):Al,ts=Tr?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let i=0,r=e.length;i<r;i+=4096)t.push(Lt.apply(null,e.subarray(i,i+4096)));return hs(t.join(""))},Dn=(e,t=!1)=>t?yl(ts(e)):ts(e),vf=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?Lt(192|t>>>6)+Lt(128|t&63):Lt(224|t>>>12&15)+Lt(128|t>>>6&63)+Lt(128|t&63)}else{var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return Lt(240|t>>>18&7)+Lt(128|t>>>12&63)+Lt(128|t>>>6&63)+Lt(128|t&63)}},wf=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,Sl=e=>e.replace(wf,vf),dl=Tr?e=>Buffer.from(e,"utf8").toString("base64"):ul?e=>ts(ul.encode(e)):e=>hs(Sl(e)),Sr=(e,t=!1)=>t?yl(dl(e)):dl(e),hl=e=>Sr(e,!0),bf=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,yf=e=>{switch(e.length){case 4:var t=(7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3),i=t-65536;return Lt((i>>>10)+55296)+Lt((i&1023)+56320);case 3:return Lt((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return Lt((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},Cl=e=>e.replace(bf,yf),El=e=>{if(e=e.replace(/\s+/g,""),!_f.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(e.length&3));let t,i,r,n=[];for(let s=0;s<e.length;)t=Nn[e.charAt(s++)]<<18|Nn[e.charAt(s++)]<<12|(i=Nn[e.charAt(s++)])<<6|(r=Nn[e.charAt(s++)]),i===64?n.push(Lt(t>>16&255)):r===64?n.push(Lt(t>>16&255,t>>8&255)):n.push(Lt(t>>16&255,t>>8&255,t&255));return n.join("")},fs=typeof atob=="function"?e=>atob(Ml(e)):Tr?e=>Buffer.from(e,"base64").toString("binary"):El,Il=Tr?e=>cl(Buffer.from(e,"base64")):e=>cl(fs(e).split("").map(t=>t.charCodeAt(0))),kl=e=>Il(Tl(e)),Mf=Tr?e=>Buffer.from(e,"base64").toString("utf8"):ll?e=>ll.decode(Il(e)):e=>Cl(fs(e)),Tl=e=>Ml(e.replace(/[-_]/g,t=>t=="-"?"+":"/")),is=e=>Mf(Tl(e)),Af=e=>{if(typeof e!="string")return!1;let t=e.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(t)||!/[^\s0-9a-zA-Z\-_]/.test(t)},Ol=e=>({value:e,enumerable:!1,writable:!0,configurable:!0}),Pl=function(){let e=(t,i)=>Object.defineProperty(String.prototype,t,Ol(i));e("fromBase64",function(){return is(this)}),e("toBase64",function(t){return Sr(this,t)}),e("toBase64URI",function(){return Sr(this,!0)}),e("toBase64URL",function(){return Sr(this,!0)}),e("toUint8Array",function(){return kl(this)})},xl=function(){let e=(t,i)=>Object.defineProperty(Uint8Array.prototype,t,Ol(i));e("toBase64",function(t){return Dn(this,t)}),e("toBase64URI",function(){return Dn(this,!0)}),e("toBase64URL",function(){return Dn(this,!0)})},Sf=()=>{Pl(),xl()},Jo={version:bl,VERSION:mf,atob:fs,atobPolyfill:El,btoa:hs,btoaPolyfill:Al,fromBase64:is,toBase64:Sr,encode:Sr,encodeURI:hl,encodeURL:hl,utob:Sl,btou:Cl,decode:is,isValid:Af,fromUint8Array:Dn,toUint8Array:kl,extendString:Pl,extendUint8Array:xl,extendBuiltins:Sf},Cf=(e=>(e.InvalidSqrtPriceLimitDirection="InvalidSqrtPriceLimitDirection",e.ZeroTradableAmount="ZeroTradableAmount",e.AmountOutBelowMinimum="AmountOutBelowMinimum",e.AmountInAboveMaximum="AmountInAboveMaximum",e.NextTickNotFound="NextTickNotFound",e.TickArraySequenceInvalid="TickArraySequenceInvalid",e.TickArrayCrossingAboveMax="TickArrayCrossingAboveMax",e.TickArrayIndexNotInitialized="TickArrayIndexNotInitialized",e.ParamsLengthNotEqual="ParamsLengthNotEqual",e))(Cf||{}),Ef=(e=>(e.InvalidTickEvent="InvalidTickEvent",e.InvalidPositionObject="InvalidPositionObject",e.InvalidPositionRewardObject="InvalidPositionRewardObject",e.InvalidParams="InvalidParams",e.FetchError="FetchError",e))(Ef||{}),If=(e=>(e.InvalidCoinTypeSequence="InvalidCoinTypeSequence",e.InvalidTickIndex="InvalidTickIndex",e.InvalidPoolObject="InvalidPoolObject",e.InvalidTickObjectId="InvalidTickObjectId",e.InvalidTickObject="InvalidTickObject",e.InvalidTickFields="InvalidTickFields",e.PoolsNotFound="PoolsNotFound",e.StatsPoolsUrlNotSet="StatsPoolsUrlNotSet",e.FetchError="FetchError",e))(If||{}),kf=(e=>(e.ClmmVestNotSet="ClmmVestNotSet",e.ClmmVestFetchError="ClmmVestFetchError",e))(kf||{}),Tf=(e=>(e.NotFoundPartnerObject="NotFoundPartnerObject",e.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",e))(Tf||{}),Of=(e=>(e.InvalidConfig="InvalidConfig",e.InvalidConfigHandle="InvalidConfigHandle",e.InvalidSimulateAccount="InvalidSimulateAccount",e))(Of||{}),Pf=(e=>(e.InvalidSendAddress="InvalidSendAddress",e.InvalidRecipientAddress="InvalidRecipientAddress",e.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",e.InsufficientBalance="InsufficientBalance",e.InvalidTarget="InvalidTarget",e.InvalidTransactionBuilder="InvalidTransactionBuilder",e))(Pf||{}),xf=(e=>(e.InvalidCoin="InvalidCoin",e.NotFoundPath="NotFoundPath",e.NoDowngradeNeedParams="NoDowngradeNeedParams",e.InvalidSwapCountUrl="InvalidSwapCountUrl",e.InvalidTransactionBuilder="InvalidTransactionBuilder",e.InvalidServerResponse="InvalidServerResponse",e))(xf||{}),Nf=(e=>(e.InvalidType="InvalidType",e))(Nf||{}),Rl=class extends Nl.BaseError{constructor(e,t,i){super(e,t||"UnknownError",i)}static isVaultsErrorCode(e,t){return this.isErrorCode(e,t)}},ji=(e,t,i)=>{throw new Rl(t.message,e,i)},tt=(e,t,i)=>{throw new Rl(t,e,i)},Rf=class{constructor(e){this._cache={},this._sdk=e}get sdk(){return this._sdk}setTokenListCache(e){let{coin_list_handle:t}=(0,Ne.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),i=`${t}_getCoinConfigs`,r=this.getCache(i),n=r?[...r,...e]:e;this.updateCache(i,n)}async getTokenListByCoinTypes(e){let t={},{coin_list_handle:i}=(0,Ne.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${i}_getCoinConfigs`,n=this.getCache(r);if(n!==void 0){let a=n;for(let c of e)for(let p of a)if((0,Ne.normalizeCoinType)(c)===(0,Ne.normalizeCoinType)(p.address)){t[c]=p;continue}}let s=e.filter(a=>t[a]===void 0);for(let a of s){let c=`${a}_metadata`,p=this.getCache(c);if(p!==void 0)t[a]=p;else{let g=await this._sdk.FullClient.getCoinMetadata({coinType:a});if(g){let v={id:g.id,pyth_id:"",name:g.name,symbol:g.symbol,official_symbol:g.symbol,coingecko_id:"",decimals:g.decimals,project_url:"",logo_url:g.iconUrl,address:a};t[a]=v,this.updateCache(c,v,Ne.CACHE_TIME_24H)}else console.log(`not found ${a}`)}}return t}async getCoinConfigs(e=!1,t=!0){let{coin_list_handle:i}=(0,Ne.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${i}_getCoinConfigs`,n=this.getCache(r,e);if(n)return n;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(p=>p.objectId),a=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),c=[];return a.forEach(p=>{(p.error!=null||p.data?.content?.dataType!=="moveObject")&&tt("FetchError",`when getCoinConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getCoinConfigs"});let g=this.buildCoinConfig(p,t);this.updateCache(`${i}_${g.address}_getCoinConfig`,g,Ne.CACHE_TIME_24H),c.push({...g})}),this.updateCache(r,c,Ne.CACHE_TIME_24H),c}async getCoinConfig(e,t=!1,i=!0){let{coin_list_handle:r}=(0,Ne.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),n=`${r}_${e}_getCoinConfig`,s=this.getCache(n,t);if(s)return s;let a=await this._sdk.FullClient.getDynamicFieldObject({parentId:r,name:{type:"0x1::type_name::TypeName",value:{name:(0,Ne.fixCoinType)(e)}}});(a.error!=null||a.data?.content?.dataType!=="moveObject")&&tt("FetchError",`when getCoinConfig get object error: ${a.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getCoinConfig"});let c=this.buildCoinConfig(a,i);return this.updateCache(n,c,Ne.CACHE_TIME_24H),c}buildCoinConfig(e,t=!0){let i=(0,Ne.getObjectFields)(e);i=i.value.fields;let r={...i};return r.id=(0,Ne.getObjectId)(e),r.address=(0,Ne.extractStructTagFromType)(i.coin_type.fields.name).full_address,i.pyth_id&&(r.pyth_id=(0,Fn.normalizeSuiObjectId)(i.pyth_id)),this.transformExtensions(r,i.extension_fields.fields.contents,t),delete r.coin_type,r}async getClmmPoolConfigs(e=!1,t=!0){let{clmm_pools_handle:i}=(0,Ne.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${i}_getClmmPoolConfigs`,n=this.getCache(r,e);if(n)return n;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(p=>p.objectId),a=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),c=[];return a.forEach(p=>{(p.error!=null||p.data?.content?.dataType!=="moveObject")&&tt("FetchError",`when getClmmPoolsConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getClmmPoolConfigs"});let g=this.buildClmmPoolConfig(p,t);this.updateCache(`${g.pool_address}_getClmmPoolConfig`,g,Ne.CACHE_TIME_24H),c.push({...g})}),this.updateCache(r,c,Ne.CACHE_TIME_24H),c}async getClmmPoolConfig(e,t=!1,i=!0){let{clmm_pools_handle:r}=(0,Ne.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),n=`${e}_getClmmPoolConfig`,s=this.getCache(n,t);if(s)return s;let a=await this._sdk.FullClient.getDynamicFieldObject({parentId:r,name:{type:"address",value:e}}),c=this.buildClmmPoolConfig(a,i);return this.updateCache(n,c,Ne.CACHE_TIME_24H),c}buildClmmPoolConfig(e,t=!0){let i=(0,Ne.getObjectFields)(e);i=i.value.fields;let r={...i};return r.id=(0,Ne.getObjectId)(e),r.pool_address=(0,Fn.normalizeSuiObjectId)(i.pool_address),this.transformExtensions(r,i.extension_fields.fields.contents,t),r}async getLaunchpadPoolConfigs(e=!1,t=!0){let{launchpad_pools_handle:i}=(0,Ne.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${i}_getLaunchpadPoolConfigs`,n=this.getCache(r,e);if(n)return n;let s=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(p=>p.objectId),a=await this._sdk.FullClient.batchGetObjects(s,{showContent:!0}),c=[];return a.forEach(p=>{(p.error!=null||p.data?.content?.dataType!=="moveObject")&&tt("FetchError",`when getCoinConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getLaunchpadPoolConfigs"});let g=this.buildLaunchpadPoolConfig(p,t);this.updateCache(`${g.pool_address}_getLaunchpadPoolConfig`,g,Ne.CACHE_TIME_24H),c.push({...g})}),this.updateCache(r,c,Ne.CACHE_TIME_24H),c}async getLaunchpadPoolConfig(e,t=!1,i=!0){let{launchpad_pools_handle:r}=(0,Ne.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),n=`${e}_getLaunchpadPoolConfig`,s=this.getCache(n,t);if(s)return s;let a=await this._sdk.FullClient.getDynamicFieldObject({parentId:r,name:{type:"address",value:e}}),c=this.buildLaunchpadPoolConfig(a,i);return this.updateCache(n,c,Ne.CACHE_TIME_24H),c}buildLaunchpadPoolConfig(e,t=!0){let i=(0,Ne.getObjectFields)(e);i=i.value.fields;let r={...i};r.id=(0,Ne.getObjectId)(e),r.pool_address=(0,Fn.normalizeSuiObjectId)(i.pool_address),this.transformExtensions(r,i.extension_fields.fields.contents,t);let n=[];i.social_media.fields.contents.forEach(s=>{n.push({name:s.fields.value.fields.name,link:s.fields.value.fields.link})}),r.social_media=n;try{r.regulation=decodeURIComponent(Jo.decode(r.regulation).replace(/%/g,"%25"))}catch{r.regulation=Jo.decode(r.regulation)}return r}transformExtensions(e,t,i=!0){let r=[];for(let n of t){let{key:s}=n.fields,{value:a}=n.fields;if(s==="labels")try{let c=decodeURIComponent(Jo.decode(a));try{a=JSON.parse(c)}catch{a=c}}catch{}i&&(e[s]=a),r.push({key:s,value:a})}delete e.extension_fields,i||(e.extensions=r)}async getCetusConfig(e=!1){let t=this._sdk.sdkOptions.cetus_config.package_id,i=`${t}_getCetusConfig`,r=this.getCache(i,e);if(r!==void 0)return r;let n=await this._sdk.FullClient.getObject({id:t,options:{showPreviousTransaction:!0}}),s=(0,Ne.getObjectPreviousTransactionDigest)(n),a=await this._sdk.FullClient.queryEventsByPage({Transaction:s}),c={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(a.data.length>0)for(let p of a.data)switch((0,Ne.extractStructTagFromType)(p.type).name){case"InitCoinListEvent":c.coin_list_id=p.parsedJson.coin_list_id;break;case"InitLaunchpadPoolsEvent":c.launchpad_pools_id=p.parsedJson.launchpad_pools_id;break;case"InitClmmPoolsEvent":c.clmm_pools_id=p.parsedJson.pools_id;break;case"InitConfigEvent":c.global_config_id=p.parsedJson.global_config_id,c.admin_cap_id=p.parsedJson.admin_cap_id;break;default:break}return c=await this.getCetusConfigHandle(c),c.clmm_pools_id.length>0&&this.updateCache(i,c,Ne.CACHE_TIME_24H),c}async getCetusConfigHandle(e){let t=[e.clmm_pools_id,e.coin_list_id,e.launchpad_pools_id];return(await this._sdk.FullClient.multiGetObjects({ids:t,options:{showContent:!0}})).forEach(i=>{(i.error!=null||i.data?.content?.dataType!=="moveObject")&&tt("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${i.error}, please check the rpc and contracts address config.`,{[Ne.DETAILS_KEYS.METHOD_NAME]:"getCetusConfigHandle"});let r=(0,Ne.getObjectFields)(i),n=(0,Ne.getObjectType)(i);switch((0,Ne.extractStructTagFromType)(n).name){case"ClmmPools":e.clmm_pools_handle=r.pools.fields.id.id;break;case"CoinList":e.coin_list_handle=r.coins.fields.id.id;break;case"LaunchpadPools":e.launchpad_pools_handle=r.pools.fields.id.id;break;default:break}}),e}updateCache(e,t,i=Ne.CACHE_TIME_5MIN){let r=this._cache[e];r?(r.overdue_time=(0,Ne.getFutureTime)(i),r.value=t):r=new Ne.CachedContent(t,(0,Ne.getFutureTime)(i)),this._cache[e]=r}getCache(e,t=!1){try{let i=this._cache[e];if(!i)return;if(t||!i.isValid()){delete this._cache[e];return}return i.value}catch(i){console.error(`Error accessing cache for key ${e}:`,i);return}}},Lf=qi($i()),Ff="position_liquidity_snapshot",Df=(e=>(e.Deleted="Deleted",e.Exists="Exists",e.NotExists="NotExists",e))(Df||{}),Bf=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent"],Ti=qi($i()),Uf=qi($i()),jf="partner",Rn="pool_script",Cr="pool_script_v2",Fl="pool_script_v3",Dl="router",qf="router_with_partner",Ir="fetcher_script";var $f="utils";var Hf=qi($i()),Ar=9e15,rr=1e9,rs="0123456789abcdef",Gn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Vn="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ns={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ar,maxE:Ar,crypto:!1},Bl,Ui,$e=!0,Wn="[DecimalError] ",ir=Wn+"Invalid argument: ",Ul=Wn+"Precision limit exceeded",jl=Wn+"crypto unavailable",ql="[object Decimal]",$t=Math.floor,kt=Math.pow,Gf=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Vf=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Zf=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,$l=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,yi=1e7,De=7,Kf=9007199254740991,Wf=Gn.length-1,os=Vn.length-1,oe={toStringTag:ql};oe.absoluteValue=oe.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Re(e)};oe.ceil=function(){return Re(new this.constructor(this),this.e+1,2)};oe.clampedTo=oe.clamp=function(e,t){var i,r=this,n=r.constructor;if(e=new n(e),t=new n(t),!e.s||!t.s)return new n(NaN);if(e.gt(t))throw Error(ir+t);return i=r.cmp(e),i<0?e:r.cmp(t)>0?t:new n(r)};oe.comparedTo=oe.cmp=function(e){var t,i,r,n,s=this,a=s.d,c=(e=new s.constructor(e)).d,p=s.s,g=e.s;if(!a||!c)return!p||!g?NaN:p!==g?p:a===c?0:!a^p<0?1:-1;if(!a[0]||!c[0])return a[0]?p:c[0]?-g:0;if(p!==g)return p;if(s.e!==e.e)return s.e>e.e^p<0?1:-1;for(r=a.length,n=c.length,t=0,i=r<n?r:n;t<i;++t)if(a[t]!==c[t])return a[t]>c[t]^p<0?1:-1;return r===n?0:r>n^p<0?1:-1};oe.cosine=oe.cos=function(){var e,t,i=this,r=i.constructor;return i.d?i.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+De,r.rounding=1,i=zf(r,Kl(r,i)),r.precision=e,r.rounding=t,Re(Ui==2||Ui==3?i.neg():i,e,t,!0)):new r(1):new r(NaN)};oe.cubeRoot=oe.cbrt=function(){var e,t,i,r,n,s,a,c,p,g,v=this,y=v.constructor;if(!v.isFinite()||v.isZero())return new y(v);for($e=!1,s=v.s*kt(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=Ft(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=kt(i,1/3),e=$t((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?i="5e"+e:(i=s.toExponential(),i=i.slice(0,i.indexOf("e")+1)+e),r=new y(i),r.s=v.s):r=new y(s.toString()),a=(e=y.precision)+3;;)if(c=r,p=c.times(c).times(c),g=p.plus(v),r=dt(g.plus(v).times(c),g.plus(p),a+2,1),Ft(c.d).slice(0,a)===(i=Ft(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(Re(c,e+1,0),c.times(c).times(c).eq(v))){r=c;break}a+=4,n=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(Re(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return $e=!0,Re(r,e,y.rounding,t)};oe.decimalPlaces=oe.dp=function(){var e,t=this.d,i=NaN;if(t){if(e=t.length-1,i=(e-$t(this.e/De))*De,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};oe.dividedBy=oe.div=function(e){return dt(this,new this.constructor(e))};oe.dividedToIntegerBy=oe.divToInt=function(e){var t=this,i=t.constructor;return Re(dt(t,new i(e),0,1,1),i.precision,i.rounding)};oe.equals=oe.eq=function(e){return this.cmp(e)===0};oe.floor=function(){return Re(new this.constructor(this),this.e+1,3)};oe.greaterThan=oe.gt=function(e){return this.cmp(e)>0};oe.greaterThanOrEqualTo=oe.gte=function(e){var t=this.cmp(e);return t==1||t===0};oe.hyperbolicCosine=oe.cosh=function(){var e,t,i,r,n,s=this,a=s.constructor,c=new a(1);if(!s.isFinite())return new a(s.s?1/0:NaN);if(s.isZero())return c;i=a.precision,r=a.rounding,a.precision=i+Math.max(s.e,s.sd())+4,a.rounding=1,n=s.d.length,n<32?(e=Math.ceil(n/3),t=(1/Xn(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=kr(a,1,s.times(t),new a(1),!0);for(var p,g=e,v=new a(8);g--;)p=s.times(s),s=c.minus(p.times(v.minus(p.times(v))));return Re(s,a.precision=i,a.rounding=r,!0)};oe.hyperbolicSine=oe.sinh=function(){var e,t,i,r,n=this,s=n.constructor;if(!n.isFinite()||n.isZero())return new s(n);if(t=s.precision,i=s.rounding,s.precision=t+Math.max(n.e,n.sd())+4,s.rounding=1,r=n.d.length,r<3)n=kr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/Xn(5,e)),n=kr(s,2,n,n,!0);for(var a,c=new s(5),p=new s(16),g=new s(20);e--;)a=n.times(n),n=n.times(c.plus(a.times(p.times(a).plus(g))))}return s.precision=t,s.rounding=i,Re(n,t,i,!0)};oe.hyperbolicTangent=oe.tanh=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,dt(i.sinh(),i.cosh(),r.precision=e,r.rounding=t)):new r(i.s)};oe.inverseCosine=oe.acos=function(){var e=this,t=e.constructor,i=e.abs().cmp(1),r=t.precision,n=t.rounding;return i!==-1?i===0?e.isNeg()?Oi(t,r,n):new t(0):new t(NaN):e.isZero()?Oi(t,r+4,n).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=n,e.times(2))};oe.inverseHyperbolicCosine=oe.acosh=function(){var e,t,i=this,r=i.constructor;return i.lte(1)?new r(i.eq(1)?0:NaN):i.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(i.e),i.sd())+4,r.rounding=1,$e=!1,i=i.times(i).minus(1).sqrt().plus(i),$e=!0,r.precision=e,r.rounding=t,i.ln()):new r(i)};oe.inverseHyperbolicSine=oe.asinh=function(){var e,t,i=this,r=i.constructor;return!i.isFinite()||i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(i.e),i.sd())+6,r.rounding=1,$e=!1,i=i.times(i).plus(1).sqrt().plus(i),$e=!0,r.precision=e,r.rounding=t,i.ln())};oe.inverseHyperbolicTangent=oe.atanh=function(){var e,t,i,r,n=this,s=n.constructor;return n.isFinite()?n.e>=0?new s(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(e=s.precision,t=s.rounding,r=n.sd(),Math.max(r,e)<2*-n.e-1?Re(new s(n),e,t,!0):(s.precision=i=r-n.e,n=dt(n.plus(1),new s(1).minus(n),i+e,1),s.precision=e+4,s.rounding=1,n=n.ln(),s.precision=e,s.rounding=t,n.times(.5))):new s(NaN)};oe.inverseSine=oe.asin=function(){var e,t,i,r,n=this,s=n.constructor;return n.isZero()?new s(n):(t=n.abs().cmp(1),i=s.precision,r=s.rounding,t!==-1?t===0?(e=Oi(s,i+4,r).times(.5),e.s=n.s,e):new s(NaN):(s.precision=i+6,s.rounding=1,n=n.div(new s(1).minus(n.times(n)).sqrt().plus(1)).atan(),s.precision=i,s.rounding=r,n.times(2)))};oe.inverseTangent=oe.atan=function(){var e,t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding;if(g.isFinite()){if(g.isZero())return new v(g);if(g.abs().eq(1)&&y+4<=os)return a=Oi(v,y+4,A).times(.25),a.s=g.s,a}else{if(!g.s)return new v(NaN);if(y+4<=os)return a=Oi(v,y+4,A).times(.5),a.s=g.s,a}for(v.precision=c=y+10,v.rounding=1,i=Math.min(28,c/De+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for($e=!1,t=Math.ceil(c/De),r=1,p=g.times(g),a=new v(g),n=g;e!==-1;)if(n=n.times(p),s=a.minus(n.div(r+=2)),n=n.times(p),a=s.plus(n.div(r+=2)),a.d[t]!==void 0)for(e=t;a.d[e]===s.d[e]&&e--;);return i&&(a=a.times(2<<i-1)),$e=!0,Re(a,v.precision=y,v.rounding=A,!0)};oe.isFinite=function(){return!!this.d};oe.isInteger=oe.isInt=function(){return!!this.d&&$t(this.e/De)>this.d.length-2};oe.isNaN=function(){return!this.s};oe.isNegative=oe.isNeg=function(){return this.s<0};oe.isPositive=oe.isPos=function(){return this.s>0};oe.isZero=function(){return!!this.d&&this.d[0]===0};oe.lessThan=oe.lt=function(e){return this.cmp(e)<0};oe.lessThanOrEqualTo=oe.lte=function(e){return this.cmp(e)<1};oe.logarithm=oe.log=function(e){var t,i,r,n,s,a,c,p,g=this,v=g.constructor,y=v.precision,A=v.rounding,k=5;if(e==null)e=new v(10),t=!0;else{if(e=new v(e),i=e.d,e.s<0||!i||!i[0]||e.eq(1))return new v(NaN);t=e.eq(10)}if(i=g.d,g.s<0||!i||!i[0]||g.eq(1))return new v(i&&!i[0]?-1/0:g.s!=1?NaN:i?0:1/0);if(t)if(i.length>1)s=!0;else{for(n=i[0];n%10===0;)n/=10;s=n!==1}if($e=!1,c=y+k,a=tr(g,c),r=t?Zn(v,c+10):tr(e,c),p=dt(a,r,c,1),jr(p.d,n=y,A))do if(c+=10,a=tr(g,c),r=t?Zn(v,c+10):tr(e,c),p=dt(a,r,c,1),!s){+Ft(p.d).slice(n+1,n+15)+1==1e14&&(p=Re(p,y+1,0));break}while(jr(p.d,n+=10,A));return $e=!0,Re(p,y,A)};oe.minus=oe.sub=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.constructor;if(e=new U(e),!k.d||!e.d)return!k.s||!e.s?e=new U(NaN):k.d?e.s=-e.s:e=new U(e.d||k.s!==e.s?k:NaN),e;if(k.s!=e.s)return e.s=-e.s,k.plus(e);if(g=k.d,A=e.d,c=U.precision,p=U.rounding,!g[0]||!A[0]){if(A[0])e.s=-e.s;else if(g[0])e=new U(k);else return new U(p===3?-0:0);return $e?Re(e,c,p):e}if(i=$t(e.e/De),v=$t(k.e/De),g=g.slice(),s=v-i,s){for(y=s<0,y?(t=g,s=-s,a=A.length):(t=A,i=v,a=g.length),r=Math.max(Math.ceil(c/De),a)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=g.length,a=A.length,y=r<a,y&&(a=r),r=0;r<a;r++)if(g[r]!=A[r]){y=g[r]<A[r];break}s=0}for(y&&(t=g,g=A,A=t,e.s=-e.s),a=g.length,r=A.length-a;r>0;--r)g[a++]=0;for(r=A.length;r>s;){if(g[--r]<A[r]){for(n=r;n&&g[--n]===0;)g[n]=yi-1;--g[n],g[r]+=yi}g[r]-=A[r]}for(;g[--a]===0;)g.pop();for(;g[0]===0;g.shift())--i;return g[0]?(e.d=g,e.e=zn(g,i),$e?Re(e,c,p):e):new U(p===3?-0:0)};oe.modulo=oe.mod=function(e){var t,i=this,r=i.constructor;return e=new r(e),!i.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||i.d&&!i.d[0]?Re(new r(i),r.precision,r.rounding):($e=!1,r.modulo==9?(t=dt(i,e.abs(),0,3,1),t.s*=e.s):t=dt(i,e,0,r.modulo,1),t=t.times(e),$e=!0,i.minus(t))};oe.naturalExponential=oe.exp=function(){return ss(this)};oe.naturalLogarithm=oe.ln=function(){return tr(this)};oe.negated=oe.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Re(e)};oe.plus=oe.add=function(e){var t,i,r,n,s,a,c,p,g,v,y=this,A=y.constructor;if(e=new A(e),!y.d||!e.d)return!y.s||!e.s?e=new A(NaN):y.d||(e=new A(e.d||y.s===e.s?y:NaN)),e;if(y.s!=e.s)return e.s=-e.s,y.minus(e);if(g=y.d,v=e.d,c=A.precision,p=A.rounding,!g[0]||!v[0])return v[0]||(e=new A(y)),$e?Re(e,c,p):e;if(s=$t(y.e/De),r=$t(e.e/De),g=g.slice(),n=s-r,n){for(n<0?(i=g,n=-n,a=v.length):(i=v,r=s,a=g.length),s=Math.ceil(c/De),a=s>a?s+1:a+1,n>a&&(n=a,i.length=1),i.reverse();n--;)i.push(0);i.reverse()}for(a=g.length,n=v.length,a-n<0&&(n=a,i=v,v=g,g=i),t=0;n;)t=(g[--n]=g[n]+v[n]+t)/yi|0,g[n]%=yi;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=zn(g,r),$e?Re(e,c,p):e};oe.precision=oe.sd=function(e){var t,i=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ir+e);return i.d?(t=Hl(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};oe.round=function(){var e=this,t=e.constructor;return Re(new t(e),e.e+1,t.rounding)};oe.sine=oe.sin=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+De,r.rounding=1,i=Jf(r,Kl(r,i)),r.precision=e,r.rounding=t,Re(Ui>2?i.neg():i,e,t,!0)):new r(NaN)};oe.squareRoot=oe.sqrt=function(){var e,t,i,r,n,s,a=this,c=a.d,p=a.e,g=a.s,v=a.constructor;if(g!==1||!c||!c[0])return new v(!g||g<0&&(!c||c[0])?NaN:c?a:1/0);for($e=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=Ft(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=$t((p+1)/2)-(p<0||p%2),g==1/0?t="5e"+p:(t=g.toExponential(),t=t.slice(0,t.indexOf("e")+1)+p),r=new v(t)):r=new v(g.toString()),i=(p=v.precision)+3;;)if(s=r,r=s.plus(dt(a,s,i+2,1)).times(.5),Ft(s.d).slice(0,i)===(t=Ft(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(Re(s,p+1,0),s.times(s).eq(a))){r=s;break}i+=4,n=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(Re(r,p+1,1),e=!r.times(r).eq(a));break}return $e=!0,Re(r,p,v.rounding,e)};oe.tangent=oe.tan=function(){var e,t,i=this,r=i.constructor;return i.isFinite()?i.isZero()?new r(i):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,i=i.sin(),i.s=1,i=dt(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Re(Ui==2||Ui==4?i.neg():i,e,t,!0)):new r(NaN)};oe.times=oe.mul=function(e){var t,i,r,n,s,a,c,p,g,v=this,y=v.constructor,A=v.d,k=(e=new y(e)).d;if(e.s*=v.s,!A||!A[0]||!k||!k[0])return new y(!e.s||A&&!A[0]&&!k||k&&!k[0]&&!A?NaN:!A||!k?e.s/0:e.s*0);for(i=$t(v.e/De)+$t(e.e/De),p=A.length,g=k.length,p<g&&(s=A,A=k,k=s,a=p,p=g,g=a),s=[],a=p+g,r=a;r--;)s.push(0);for(r=g;--r>=0;){for(t=0,n=p+r;n>r;)c=s[n]+k[r]*A[n-r-1]+t,s[n--]=c%yi|0,t=c/yi|0;s[n]=(s[n]+t)%yi|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=zn(s,i),$e?Re(e,y.precision,y.rounding):e};oe.toBinary=function(e,t){return ps(this,2,e,t)};oe.toDecimalPlaces=oe.toDP=function(e,t){var i=this,r=i.constructor;return i=new r(i),e===void 0?i:(Zt(e,0,rr),t===void 0?t=r.rounding:Zt(t,0,8),Re(i,e+i.e+1,t))};oe.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Pi(r,!0):(Zt(e,0,rr),t===void 0?t=n.rounding:Zt(t,0,8),r=Re(new n(r),e+1,t),i=Pi(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+i:i};oe.toFixed=function(e,t){var i,r,n=this,s=n.constructor;return e===void 0?i=Pi(n):(Zt(e,0,rr),t===void 0?t=s.rounding:Zt(t,0,8),r=Re(new s(n),e+n.e+1,t),i=Pi(r,!1,e+r.e+1)),n.isNeg()&&!n.isZero()?"-"+i:i};oe.toFraction=function(e){var t,i,r,n,s,a,c,p,g,v,y,A,k=this,U=k.d,P=k.constructor;if(!U)return new P(k);if(g=i=new P(1),r=p=new P(0),t=new P(r),s=t.e=Hl(U)-k.e-1,a=s%De,t.d[0]=kt(10,a<0?De+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(ir+c);e=c.gt(t)?s>0?t:g:c}for($e=!1,c=new P(Ft(U)),v=P.precision,P.precision=s=U.length*De*2;y=dt(c,t,0,1,1),n=i.plus(y.times(r)),n.cmp(e)!=1;)i=r,r=n,n=g,g=p.plus(y.times(n)),p=n,n=t,t=c.minus(y.times(n)),c=n;return n=dt(e.minus(i),r,0,1,1),p=p.plus(n.times(g)),i=i.plus(n.times(r)),p.s=g.s=k.s,A=dt(g,r,s,1).minus(k).abs().cmp(dt(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,$e=!0,A};oe.toHexadecimal=oe.toHex=function(e,t){return ps(this,16,e,t)};oe.toNearest=function(e,t){var i=this,r=i.constructor;if(i=new r(i),e==null){if(!i.d)return i;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Zt(t,0,8),!i.d)return e.s?i:e;if(!e.d)return e.s&&(e.s=i.s),e}return e.d[0]?($e=!1,i=dt(i,e,0,t,1).times(e),$e=!0,Re(i)):(e.s=i.s,i=e),i};oe.toNumber=function(){return+this};oe.toOctal=function(e,t){return ps(this,8,e,t)};oe.toPower=oe.pow=function(e){var t,i,r,n,s,a,c=this,p=c.constructor,g=+(e=new p(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new p(kt(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return Re(c,r,s);if(t=$t(e.e/De),t>=e.d.length-1&&(i=g<0?-g:g)<=Kf)return n=Gl(p,c,i,r),e.s<0?new p(1).div(n):Re(n,r,s);if(a=c.s,a<0){if(t<e.d.length-1)return new p(NaN);if((e.d[t]&1)==0&&(a=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=a,c}return i=kt(+c,g),t=i==0||!isFinite(i)?$t(g*(Math.log("0."+Ft(c.d))/Math.LN10+c.e+1)):new p(i+"").e,t>p.maxE+1||t<p.minE-1?new p(t>0?a/0:0):($e=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=ss(e.times(tr(c,r+i)),r),n.d&&(n=Re(n,r+5,1),jr(n.d,r,s)&&(t=r+10,n=Re(ss(e.times(tr(c,t+i)),t),t+5,1),+Ft(n.d).slice(r+1,r+15)+1==1e14&&(n=Re(n,r+1,0)))),n.s=a,$e=!0,p.rounding=s,Re(n,r,s))};oe.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Pi(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Zt(e,1,rr),t===void 0?t=n.rounding:Zt(t,0,8),r=Re(new n(r),e,t),i=Pi(r,e<=r.e||r.e<=n.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+i:i};oe.toSignificantDigits=oe.toSD=function(e,t){var i=this,r=i.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Zt(e,1,rr),t===void 0?t=r.rounding:Zt(t,0,8)),Re(new r(i),e,t)};oe.toString=function(){var e=this,t=e.constructor,i=Pi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};oe.truncated=oe.trunc=function(){return Re(new this.constructor(this),this.e+1,1)};oe.valueOf=oe.toJSON=function(){var e=this,t=e.constructor,i=Pi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function Ft(e){var t,i,r,n=e.length-1,s="",a=e[0];if(n>0){for(s+=a,t=1;t<n;t++)r=e[t]+"",i=De-r.length,i&&(s+=er(i)),s+=r;a=e[t],r=a+"",i=De-r.length,i&&(s+=er(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Zt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(ir+e)}function jr(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=De,n=0):(n=Math.ceil((t+1)/De),t%=De),s=kt(10,De-t),c=e[n]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),a=i<4&&c==99999||i>3&&c==49999||c==5e4||c==0):a=(i<4&&c+1==s||i>3&&c+1==s/2)&&(e[n+1]/s/100|0)==kt(10,t-2)-1||(c==s/2||c==0)&&(e[n+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),a=(r||i<4)&&c==9999||!r&&i>3&&c==4999):a=((r||i<4)&&c+1==s||!r&&i>3&&c+1==s/2)&&(e[n+1]/s/1e3|0)==kt(10,t-3)-1,a}function jn(e,t,i){for(var r,n=[0],s,a=0,c=e.length;a<c;){for(s=n.length;s--;)n[s]*=t;for(n[0]+=rs.indexOf(e.charAt(a++)),r=0;r<n.length;r++)n[r]>i-1&&(n[r+1]===void 0&&(n[r+1]=0),n[r+1]+=n[r]/i|0,n[r]%=i)}return n.reverse()}function zf(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/Xn(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=kr(e,1,t.times(n),new e(1));for(var s=i;s--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return e.precision-=i,t}var dt=(function(){function e(r,n,s){var a,c=0,p=r.length;for(r=r.slice();p--;)a=r[p]*n+c,r[p]=a%s|0,c=a/s|0;return c&&r.unshift(c),r}function t(r,n,s,a){var c,p;if(s!=a)p=s>a?1:-1;else for(c=p=0;c<s;c++)if(r[c]!=n[c]){p=r[c]>n[c]?1:-1;break}return p}function i(r,n,s,a){for(var c=0;s--;)r[s]-=c,c=r[s]<n[s]?1:0,r[s]=c*a+r[s]-n[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,n,s,a,c,p){var g,v,y,A,k,U,P,W,j,K,X,Q,se,Y,le,E,I,O,R,N,S=r.constructor,h=r.s==n.s?1:-1,o=r.d,l=n.d;if(!o||!o[0]||!l||!l[0])return new S(!r.s||!n.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?h*0:h/0);for(p?(k=1,v=r.e-n.e):(p=yi,k=De,v=$t(r.e/k)-$t(n.e/k)),R=l.length,I=o.length,j=new S(h),K=j.d=[],y=0;l[y]==(o[y]||0);y++);if(l[y]>(o[y]||0)&&v--,s==null?(Y=s=S.precision,a=S.rounding):c?Y=s+(r.e-n.e)+1:Y=s,Y<0)K.push(1),U=!0;else{if(Y=Y/k+2|0,y=0,R==1){for(A=0,l=l[0],Y++;(y<I||A)&&Y--;y++)le=A*p+(o[y]||0),K[y]=le/l|0,A=le%l|0;U=A||y<I}else{for(A=p/(l[0]+1)|0,A>1&&(l=e(l,A,p),o=e(o,A,p),R=l.length,I=o.length),E=R,X=o.slice(0,R),Q=X.length;Q<R;)X[Q++]=0;N=l.slice(),N.unshift(0),O=l[0],l[1]>=p/2&&++O;do A=0,g=t(l,X,R,Q),g<0?(se=X[0],R!=Q&&(se=se*p+(X[1]||0)),A=se/O|0,A>1?(A>=p&&(A=p-1),P=e(l,A,p),W=P.length,Q=X.length,g=t(P,X,W,Q),g==1&&(A--,i(P,R<W?N:l,W,p))):(A==0&&(g=A=1),P=l.slice()),W=P.length,W<Q&&P.unshift(0),i(X,P,Q,p),g==-1&&(Q=X.length,g=t(l,X,R,Q),g<1&&(A++,i(X,R<Q?N:l,Q,p))),Q=X.length):g===0&&(A++,X=[0]),K[y++]=A,g&&X[0]?X[Q++]=o[E]||0:(X=[o[E]],Q=1);while((E++<I||X[0]!==void 0)&&Y--);U=X[0]!==void 0}K[0]||K.shift()}if(k==1)j.e=v,Bl=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,Re(j,c?s+j.e+1:s,a,U)}return j}})();function Re(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor;e:if(t!=null){if(y=e.d,!y)return e;for(n=1,c=y[0];c>=10;c/=10)n++;if(s=t-n,s<0)s+=De,a=t,v=y[A=0],p=v/kt(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/De),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=De,a=s-De+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=De,a=s-De+n,p=a<0?0:v/kt(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%kt(10,n-a-1)),g=i<4?(p||r)&&(i==0||i==(e.s<0?3:2)):p>5||p==5&&(i==4||r||i==6&&(s>0?a>0?v/kt(10,n-a):0:y[A-1])%10&1||i==(e.s<0?8:7)),t<1||!y[0])return y.length=0,g?(t-=e.e+1,y[0]=kt(10,(De-t%De)%De),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=kt(10,De-s),y[A]=a>0?(v/kt(10,n-a)%kt(10,a)|0)*c:0),g)for(;;)if(A==0){for(s=1,a=y[0];a>=10;a/=10)s++;for(a=y[0]+=c,c=1;a>=10;a/=10)c++;s!=c&&(e.e++,y[0]==yi&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=yi)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return $e&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function Pi(e,t,i){if(!e.isFinite())return Zl(e);var r,n=e.e,s=Ft(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+er(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+er(-n-1)+s,i&&(r=i-a)>0&&(s+=er(r))):n>=a?(s+=er(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+er(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=er(r))),s}function zn(e,t){var i=e[0];for(t*=De;i>=10;i/=10)t++;return t}function Zn(e,t,i){if(t>Wf)throw $e=!0,i&&(e.precision=i),Error(Ul);return Re(new e(Gn),t,1,!0)}function Oi(e,t,i){if(t>os)throw Error(Ul);return Re(new e(Vn),t,i,!0)}function Hl(e){var t=e.length-1,i=t*De+1;if(t=e[t],t){for(;t%10==0;t/=10)i--;for(t=e[0];t>=10;t/=10)i++}return i}function er(e){for(var t="";e--;)t+="0";return t}function Gl(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/De+4);for($e=!1;;){if(i%2&&(s=s.times(t),pl(s.d,a)&&(n=!0)),i=$t(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),pl(t.d,a)}return $e=!0,s}function fl(e){return e.d[e.d.length-1]&1}function Vl(e,t,i){for(var r,n,s=new e(t[0]),a=0;++a<t.length;){if(n=new e(t[a]),!n.s){s=n;break}r=s.cmp(n),(r===i||r===0&&s.s===i)&&(s=n)}return s}function ss(e,t){var i,r,n,s,a,c,p,g=0,v=0,y=0,A=e.constructor,k=A.rounding,U=A.precision;if(!e.d||!e.d[0]||e.e>17)return new A(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?($e=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(kt(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=Re(s.times(e),p,1),i=i.times(++v),c=a.plus(dt(s,i,p,1)),Ft(c.d).slice(0,p)===Ft(a.d).slice(0,p)){for(n=y;n--;)a=Re(a.times(a),p,1);if(t==null)if(g<3&&jr(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return Re(a,A.precision=U,k,$e=!0);else return A.precision=U,a}a=c}}function tr(e,t){var i,r,n,s,a,c,p,g,v,y,A,k=1,U=10,P=e,W=P.d,j=P.constructor,K=j.rounding,X=j.precision;if(P.s<0||!W||!W[0]||!P.e&&W[0]==1&&W.length==1)return new j(W&&!W[0]?-1/0:P.s!=1?NaN:W?0:P);if(t==null?($e=!1,v=X):v=t,j.precision=v+=U,i=Ft(W),r=i.charAt(0),Math.abs(s=P.e)<15e14){for(;r<7&&r!=1||r==1&&i.charAt(1)>3;)P=P.times(e),i=Ft(P.d),r=i.charAt(0),k++;s=P.e,r>1?(P=new j("0."+i),s++):P=new j(r+"."+i.slice(1))}else return g=Zn(j,v+2,X).times(s+""),P=tr(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?Re(P,X,K,$e=!0):P;for(y=P,p=a=P=dt(P.minus(1),P.plus(1),v,1),A=Re(P.times(P),v,1),n=3;;){if(a=Re(a.times(A),v,1),g=p.plus(dt(a,new j(n),v,1)),Ft(g.d).slice(0,v)===Ft(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(Zn(j,v+2,X).times(s+""))),p=dt(p,new j(k),v,1),t==null)if(jr(p.d,v-U,K,c))j.precision=v+=U,g=a=P=dt(y.minus(1),y.plus(1),v,1),A=Re(P.times(P),v,1),n=c=1;else return Re(p,j.precision=X,K,$e=!0);else return j.precision=X,p;p=g,n+=2}}function Zl(e){return String(e.s*e.s/0)}function qn(e,t){var i,r,n;for((i=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(i<0&&(i=r),i+=+t.slice(r+1),t=t.substring(0,r)):i<0&&(i=t.length),r=0;t.charCodeAt(r)===48;r++);for(n=t.length;t.charCodeAt(n-1)===48;--n);if(t=t.slice(r,n),t){if(n-=r,e.e=i=i-r-1,e.d=[],r=(i+1)%De,i<0&&(r+=De),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=De;r<n;)e.d.push(+t.slice(r,r+=De));t=t.slice(r),r=De-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),$e&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Xf(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),$l.test(t))return qn(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Vf.test(t))i=16,t=t.toLowerCase();else if(Gf.test(t))i=2;else if(Zf.test(t))i=8;else throw Error(ir+t);for(s=t.search(/p/i),s>0?(p=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),a=s>=0,r=e.constructor,a&&(t=t.replace(".",""),c=t.length,s=c-s,n=Gl(r,new r(i),s,s*2)),g=jn(t,i,yi),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=zn(g,v),e.d=g,$e=!1,a&&(e=dt(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?kt(2,p):qr.pow(2,p))),$e=!0,e)}function Jf(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:kr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/Xn(5,i)),t=kr(e,2,t,t);for(var n,s=new e(5),a=new e(16),c=new e(20);i--;)n=t.times(t),t=t.times(s.plus(n.times(a.times(n).minus(c))));return t}function kr(e,t,i,r,n){var s,a,c,p,g=1,v=e.precision,y=Math.ceil(v/De);for($e=!1,p=i.times(i),c=new e(r);;){if(a=dt(c.times(p),new e(t++*t++),v,1),c=n?r.plus(a):r.minus(a),r=dt(a.times(p),new e(t++*t++),v,1),a=c.plus(r),a.d[y]!==void 0){for(s=y;a.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=a,a=s,g++}return $e=!0,a.d.length=y+1,a}function Xn(e,t){for(var i=e;--t;)i*=e;return i}function Kl(e,t){var i,r=t.s<0,n=Oi(e,e.precision,1),s=n.times(.5);if(t=t.abs(),t.lte(s))return Ui=r?4:1,t;if(i=t.divToInt(n),i.isZero())Ui=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Ui=fl(i)?r?2:3:r?4:1,t;Ui=fl(i)?r?1:4:r?3:2}return t.minus(n).abs()}function ps(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Zt(i,1,rr),r===void 0?r=k.rounding:Zt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=Zl(e);else{for(v=Pi(e),a=v.indexOf("."),U?(n=2,t==16?i=i*4-3:t==8&&(i=i*3-2)):n=t,a>=0&&(v=v.replace(".",""),A=new k(1),A.e=v.length-a,A.d=jn(Pi(A),10,n),A.e=A.d.length),y=jn(v,10,n),s=p=y.length;y[--p]==0;)y.pop();if(!y[0])v=U?"0p+0":"0";else{if(a<0?s--:(e=new k(e),e.d=y,e.e=s,e=dt(e,A,i,r,0,n),y=e.d,s=e.e,g=Bl),a=y[i],c=n/2,g=g||y[i+1]!==void 0,g=r<4?(a!==void 0||g)&&(r===0||r===(e.s<0?3:2)):a>c||a===c&&(r===4||g||r===6&&y[i-1]&1||r===(e.s<0?8:7)),y.length=i,g)for(;++y[--i]>n-1;)y[i]=0,i||(++s,y.unshift(1));for(p=y.length;!y[p-1];--p);for(a=0,v="";a<p;a++)v+=rs.charAt(y[a]);if(U){if(p>1)if(t==16||t==8){for(a=t==16?4:3,--p;p%a;p++)v+="0";for(y=jn(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=rs.charAt(y[a])}else v=v.charAt(0)+"."+v.slice(1);v=v+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)v="0"+v;v="0."+v}else if(++s>p)for(s-=p;s--;)v+="0";else s<p&&(v=v.slice(0,s)+"."+v.slice(s))}v=(t==16?"0x":t==2?"0b":t==8?"0o":"")+v}return e.s<0?"-"+v:v}function pl(e,t){if(e.length>t)return e.length=t,!0}function Yf(e){return new this(e).abs()}function Qf(e){return new this(e).acos()}function ep(e){return new this(e).acosh()}function tp(e,t){return new this(e).plus(t)}function ip(e){return new this(e).asin()}function rp(e){return new this(e).asinh()}function np(e){return new this(e).atan()}function op(e){return new this(e).atanh()}function sp(e,t){e=new this(e),t=new this(t);var i,r=this.precision,n=this.rounding,s=r+4;return!e.s||!t.s?i=new this(NaN):!e.d&&!t.d?(i=Oi(this,s,1).times(t.s>0?.25:.75),i.s=e.s):!t.d||e.isZero()?(i=t.s<0?Oi(this,r,n):new this(0),i.s=e.s):!e.d||t.isZero()?(i=Oi(this,s,1).times(.5),i.s=e.s):t.s<0?(this.precision=s,this.rounding=1,i=this.atan(dt(e,t,s,1)),t=Oi(this,s,1),this.precision=r,this.rounding=n,i=e.s<0?i.minus(t):i.plus(t)):i=this.atan(dt(e,t,s,1)),i}function ap(e){return new this(e).cbrt()}function lp(e){return Re(e=new this(e),e.e+1,2)}function up(e,t,i){return new this(e).clamp(t,i)}function cp(e){if(!e||typeof e!="object")throw Error(Wn+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,rr,"rounding",0,8,"toExpNeg",-Ar,0,"toExpPos",0,Ar,"maxE",0,Ar,"minE",-Ar,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(i=s[t],n&&(this[i]=ns[i]),(r=e[i])!==void 0)if($t(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(ir+i+": "+r);if(i="crypto",n&&(this[i]=ns[i]),(r=e[i])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[i]=!0;else throw Error(jl);else this[i]=!1;else throw Error(ir+i+": "+r);return this}function dp(e){return new this(e).cos()}function hp(e){return new this(e).cosh()}function Wl(e){var t,i,r;function n(s){var a,c,p,g=this;if(!(g instanceof n))return new n(s);if(g.constructor=n,ml(s)){g.s=s.s,$e?!s.d||s.e>n.maxE?(g.e=NaN,g.d=null):s.e<n.minE?(g.e=0,g.d=[0]):(g.e=s.e,g.d=s.d.slice()):(g.e=s.e,g.d=s.d?s.d.slice():s.d);return}if(p=typeof s,p==="number"){if(s===0){g.s=1/s<0?-1:1,g.e=0,g.d=[0];return}if(s<0?(s=-s,g.s=-1):g.s=1,s===~~s&&s<1e7){for(a=0,c=s;c>=10;c/=10)a++;$e?a>n.maxE?(g.e=NaN,g.d=null):a<n.minE?(g.e=0,g.d=[0]):(g.e=a,g.d=[s]):(g.e=a,g.d=[s]);return}if(s*0!==0){s||(g.s=NaN),g.e=NaN,g.d=null;return}return qn(g,s.toString())}if(p==="string")return(c=s.charCodeAt(0))===45?(s=s.slice(1),g.s=-1):(c===43&&(s=s.slice(1)),g.s=1),$l.test(s)?qn(g,s):Xf(g,s);if(p==="bigint")return s<0?(s=-s,g.s=-1):g.s=1,qn(g,s.toString());throw Error(ir+s)}if(n.prototype=oe,n.ROUND_UP=0,n.ROUND_DOWN=1,n.ROUND_CEIL=2,n.ROUND_FLOOR=3,n.ROUND_HALF_UP=4,n.ROUND_HALF_DOWN=5,n.ROUND_HALF_EVEN=6,n.ROUND_HALF_CEIL=7,n.ROUND_HALF_FLOOR=8,n.EUCLID=9,n.config=n.set=cp,n.clone=Wl,n.isDecimal=ml,n.abs=Yf,n.acos=Qf,n.acosh=ep,n.add=tp,n.asin=ip,n.asinh=rp,n.atan=np,n.atanh=op,n.atan2=sp,n.cbrt=ap,n.ceil=lp,n.clamp=up,n.cos=dp,n.cosh=hp,n.div=fp,n.exp=pp,n.floor=mp,n.hypot=gp,n.ln=_p,n.log=vp,n.log10=bp,n.log2=wp,n.max=yp,n.min=Mp,n.mod=Ap,n.mul=Sp,n.pow=Cp,n.random=Ep,n.round=Ip,n.sign=kp,n.sin=Tp,n.sinh=Op,n.sqrt=Pp,n.sub=xp,n.sum=Np,n.tan=Rp,n.tanh=Lp,n.trunc=Fp,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(i=r[t++])||(e[i]=this[i]);return n.config(e),n}function fp(e,t){return new this(e).div(t)}function pp(e){return new this(e).exp()}function mp(e){return Re(e=new this(e),e.e+1,3)}function gp(){var e,t,i=new this(0);for($e=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)i.d&&(i=i.plus(t.times(t)));else{if(t.s)return $e=!0,new this(1/0);i=t}return $e=!0,i.sqrt()}function ml(e){return e instanceof qr||e&&e.toStringTag===ql||!1}function _p(e){return new this(e).ln()}function vp(e,t){return new this(e).log(t)}function wp(e){return new this(e).log(2)}function bp(e){return new this(e).log(10)}function yp(){return Vl(this,arguments,-1)}function Mp(){return Vl(this,arguments,1)}function Ap(e,t){return new this(e).mod(t)}function Sp(e,t){return new this(e).mul(t)}function Cp(e,t){return new this(e).pow(t)}function Ep(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Zt(e,1,rr),r=Math.ceil(e/De),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)n=t[s],n>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=n%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)n=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),n>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(n%1e7),s+=4);s=r/4}else throw Error(jl);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=De,r&&e&&(n=kt(10,De-e),c[s]=(r/n|0)*n);c[s]===0;s--)c.pop();if(s<0)i=0,c=[0];else{for(i=-1;c[0]===0;i-=De)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<De&&(i-=De-r)}return a.e=i,a.d=c,a}function Ip(e){return Re(e=new this(e),e.e+1,this.rounding)}function kp(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Tp(e){return new this(e).sin()}function Op(e){return new this(e).sinh()}function Pp(e){return new this(e).sqrt()}function xp(e,t){return new this(e).sub(t)}function Np(){var e=0,t=arguments,i=new this(t[e]);for($e=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return $e=!0,Re(i,this.precision,this.rounding)}function Rp(e){return new this(e).tan()}function Lp(e){return new this(e).tanh()}function Fp(e){return Re(e=new this(e),e.e+1,1)}oe[Symbol.for("nodejs.util.inspect.custom")]=oe.toString;oe[Symbol.toStringTag]="Decimal";var qr=oe.constructor=Wl(ns);Gn=new qr(Gn);Vn=new qr(Vn);var Ot=qr;function Kn(e){let t=at.CoinAssist.isSuiCoin(e.coin_type_a),i=at.CoinAssist.isSuiCoin(e.coin_type_b);return{is_adjust_coin_a:t,is_adjust_coin_b:i}}function Dp(e,t){return Ot.ceil(Ot(e).div(1+t)).toString()}var lr=class{static createCollectRewarderAndFeeParams(e,t,i,r,n,s){n===void 0&&(n=[...r]),s===void 0&&(s=[...r]);let a=(0,at.normalizeCoinType)(i.coin_type_a),c=(0,at.normalizeCoinType)(i.coin_type_b);if(i.collect_fee){let g=at.CoinAssist.buildCoinForAmount(t,n,BigInt(0),a,!1);n=g.remain_coins;let v=at.CoinAssist.buildCoinForAmount(t,s,BigInt(0),c,!1);s=v.remain_coins,t=e.Position.createCollectFeePayload({pool_id:i.pool_id,pos_id:i.pos_id,coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b},t,g.target_coin,v.target_coin)}let p=[];return i.rewarder_coin_types.forEach(g=>{switch((0,at.normalizeCoinType)(g)){case a:p.push(at.CoinAssist.buildCoinForAmount(t,n,BigInt(0),g,!1).target_coin);break;case c:p.push(at.CoinAssist.buildCoinForAmount(t,s,BigInt(0),g,!1).target_coin);break;default:p.push(at.CoinAssist.buildCoinForAmount(t,r,BigInt(0),g,!1).target_coin);break}}),t=e.Rewarder.createCollectRewarderPayload(i,t,p),t}static async adjustTransactionForGas(e,t,i,r){r.setSender(e.getSenderAddress());let n=at.CoinAssist.selectCoinAssetGreaterThanOrEqual(t,i).selected_coins,s=at.CoinAssist.calculateTotalBalance(t);if(n.length===0&&tt("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${s}`),s-i>1e9)return{fixAmount:i};let a=await e.FullClient.calculationTxGas(Un.Transaction.from(r));if(at.CoinAssist.selectCoinAssetGreaterThanOrEqual(t,BigInt(a),n.map(c=>c.coin_object_id)).selected_coins.length===0){let c=BigInt(a)+BigInt(500);if(s-i<c){i-=c,i<0&&tt("InsufficientBalance","gas Insufficient balance");let p=new Un.Transaction;return{fixAmount:i,newTx:p}}}return{fixAmount:i}}static async buildAddLiquidityFixTokenForGas(e,t,i,r,n,s,a){n=await this.buildAddLiquidityFixToken(e,t,i,n,s,a);let{is_adjust_coin_a:c}=Kn(i),p=c?i.amount_a:i.amount_b,g=await this.adjustTransactionForGas(e,at.CoinAssist.getCoinAssets(c?i.coin_type_a:i.coin_type_b,t),BigInt(p),n),{fixAmount:v}=g,y=g.newTx;if(y!=null){let A,k;if(c)i.amount_a=Number(v),A=this.buildAddLiquidityFixTokenCoinInput(y,!i.fix_amount_a,v.toString(),i.slippage,i.coin_type_a,t,!1,!0),k=this.buildAddLiquidityFixTokenCoinInput(y,i.fix_amount_a,i.amount_b,i.slippage,i.coin_type_b,t,!1,!0);else return i.amount_b=Number(v),A=this.buildAddLiquidityFixTokenCoinInput(y,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,t,!1,!0),k=this.buildAddLiquidityFixTokenCoinInput(y,i.fix_amount_a,v.toString(),i.slippage,i.coin_type_b,t,!1,!0),i=this.fixAddLiquidityFixTokenParams(i,r.slippage,r.cur_sqrt_price),this.buildAddLiquidityFixTokenArgs(y,e,t,i,A,k)}return n}static async buildAddLiquidityFixToken(e,t,i,r,n,s){r=r||new Un.Transaction;let a,c;return n==null||s==null?(a=this.buildAddLiquidityFixTokenCoinInput(r,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,t,!1,!0),c=this.buildAddLiquidityFixTokenCoinInput(r,i.fix_amount_a,i.amount_b,i.slippage,i.coin_type_b,t,!1,!0)):(a={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},c={target_coin:s,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]}),r=this.buildAddLiquidityFixTokenArgs(r,e,t,i,a,c),r}static buildAddLiquidityFixTokenCoinInput(e,t,i,r,n,s,a=!0,c=!0){return t?at.CoinAssist.buildCoinForAmountInterval(e,s,{amount_second:BigInt(Dp(i,r)),amount_first:BigInt(i)},n,a,c):at.CoinAssist.buildCoinForAmount(e,s,BigInt(i),n,a,c)}static fixAddLiquidityFixTokenParams(e,t,i){let r=e.fix_amount_a?e.amount_a:e.amount_b,n=at.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(Number(e.tick_lower),Number(e.tick_upper),new Hf.default(r),e.fix_amount_a,!0,t,i);return e.amount_a=e.fix_amount_a?e.amount_a:n.coin_amount_limit_a,e.amount_b=e.fix_amount_a?n.coin_amount_limit_b:e.amount_b,e}static buildAddLiquidityFixTokenArgs(e,t,i,r,n,s){let a=[r.coin_type_a,r.coin_type_b],c=r.is_open?"open_position_with_liquidity_by_fix_coin":"add_liquidity_by_fix_coin",{clmm_pool:p,integrate:g}=t.sdkOptions;r.is_open||(e=this.createCollectRewarderAndFeeParams(t,e,r,i,n.remain_coins,s.remain_coins));let v=(0,at.getPackagerConfigs)(p),y=r.is_open?[e.object(v.global_config_id),e.object(r.pool_id),e.pure.u32(Number((0,at.asUintN)(BigInt(r.tick_lower)).toString())),e.pure.u32(Number((0,at.asUintN)(BigInt(r.tick_upper)).toString())),n.target_coin,s.target_coin,e.pure.u64(r.amount_a),e.pure.u64(r.amount_b),e.pure.bool(r.fix_amount_a),e.object(at.CLOCK_ADDRESS)]:[e.object(v.global_config_id),e.object(r.pool_id),e.object(r.pos_id),n.target_coin,s.target_coin,e.pure.u64(r.amount_a),e.pure.u64(r.amount_b),e.pure.bool(r.fix_amount_a),e.object(at.CLOCK_ADDRESS)];return e.moveCall({target:`${g.published_at}::${Cr}::${c}`,typeArguments:a,arguments:y}),e}static checkCoinThreshold(e,t,i,r,n,s){t&&i.moveCall({target:`${e.sdkOptions.integrate.published_at}::${Dl}::check_coin_threshold`,typeArguments:[s],arguments:[r,i.pure.u64(n)]})}},Mr=class Qi{static getDefaultSqrtPriceLimit(t){return new Uf.default(t?nt.MIN_SQRT_PRICE:nt.MAX_SQRT_PRICE)}static getDefaultOtherAmountThreshold(t){return t?nt.ZERO:nt.U64_MAX}static async buildSwapTransactionForGas(t,i,r,n){let s=this.buildSwapTransaction(t,i,r);s.setSender(t.getSenderAddress());let a=await this.adjustTransactionForGas(t,nt.CoinAssist.getCoinAssets(i.a2b?i.coin_type_a:i.coin_type_b,r),BigInt(i.by_amount_in?i.amount:i.amount_limit),s),{fixAmount:c,newTx:p}=a;if(p!==void 0){p.setSender(t.getSenderAddress()),i.by_amount_in?i.amount=c.toString():i.amount_limit=c.toString(),i=await this.fixSwapParams(t,i,n);let g=nt.CoinAssist.buildCoinForAmount(s,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a),v=nt.CoinAssist.buildCoinForAmount(s,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b);s=this.buildSwapTransactionArgs(p,i,t.sdkOptions,g,v)}return s}static buildSwapTransactionArgs(t,i,r,n,s){let{clmm_pool:a,integrate:c}=r,p=Qi.getDefaultSqrtPriceLimit(i.a2b),g=[i.coin_type_a,i.coin_type_b],{global_config_id:v}=(0,nt.getPackagerConfigs)(a);v===void 0&&tt("InvalidConfig","clmm.config.global_config_id is undefined");let y=i.swap_partner!==void 0,A=y?i.a2b?"swap_a2b_with_partner":"swap_b2a_with_partner":i.a2b?"swap_a2b":"swap_b2a",k=y?[t.object(v),t.object(i.pool_id),t.object(i.swap_partner),n.target_coin,s.target_coin,t.pure.bool(i.by_amount_in),t.pure.u64(i.amount),t.pure.u64(i.amount_limit),t.pure.u128(p.toString()),t.object(nt.CLOCK_ADDRESS)]:[t.object(v),t.object(i.pool_id),n.target_coin,s.target_coin,t.pure.bool(i.by_amount_in),t.pure.u64(i.amount),t.pure.u64(i.amount_limit),t.pure.u128(p.toString()),t.object(nt.CLOCK_ADDRESS)];return t.moveCall({target:`${c.published_at}::${Cr}::${A}`,typeArguments:g,arguments:k}),t}static async adjustTransactionForGas(t,i,r,n){n.setSender(t.getSenderAddress());let s=nt.CoinAssist.selectCoinAssetGreaterThanOrEqual(i,r).selected_coins,a=nt.CoinAssist.calculateTotalBalance(i);if(s.length===0&&tt("InsufficientBalance",`Insufficient balance exceed amount ${r} real amount ${a}`),a-r>1e9)return{fixAmount:r};let c=await t.FullClient.calculationTxGas(n);if(nt.CoinAssist.selectCoinAssetGreaterThanOrEqual(i,BigInt(c),s.map(p=>p.coin_object_id)).selected_coins.length===0){let p=BigInt(c)+BigInt(500);if(a-r<p){r-=p,r<0&&tt("InsufficientBalance","gas Insufficient balance");let g=new Bn.Transaction;return{fixAmount:r,newTx:g}}}return{fixAmount:r}}static buildSwapTransaction(t,i,r){let n=new Bn.Transaction;n.setSender(t.getSenderAddress());let s=nt.CoinAssist.buildCoinForAmount(n,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1),a=nt.CoinAssist.buildCoinForAmount(n,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1);return n=this.buildSwapTransactionArgs(n,i,t.sdkOptions,s,a),n}static async fixSwapParams(t,i,r){let{current_pool:n}=r;try{let s=await t.Swap.preSwap({decimals_a:r.decimals_a,decimals_b:r.decimals_b,a2b:i.a2b,by_amount_in:i.by_amount_in,amount:i.amount,pool:n,current_sqrt_price:n.current_sqrt_price,coin_type_a:n.coin_type_a,coin_type_b:n.coin_type_b}),a=r.by_amount_in?s.estimated_amount_out:s.estimated_amount_in,c=(0,nt.adjustForSlippage)(a,r.slippage,!r.by_amount_in);i.amount_limit=c.toString()}catch(s){ji("InvalidConfig",s)}return i}static async buildSwapTransactionWithoutTransferCoinsForGas(t,i,r,n){let{tx:s,coin_ab_s:a}=Qi.buildSwapTransactionWithoutTransferCoins(t,i,r);s.setSender(t.getSenderAddress());let c=await Qi.adjustTransactionForGas(t,nt.CoinAssist.getCoinAssets(i.a2b?i.coin_type_a:i.coin_type_b,r),BigInt(i.by_amount_in?i.amount:i.amount_limit),s),{fixAmount:p,newTx:g}=c;if(g!==void 0){g.setSender(t.getSenderAddress()),i.by_amount_in?i.amount=p.toString():i.amount_limit=p.toString(),i=await Qi.fixSwapParams(t,i,n);let v=nt.CoinAssist.buildCoinForAmount(s,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1,!0),y=nt.CoinAssist.buildCoinForAmount(s,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1,!0),A=Qi.buildSwapTransactionWithoutTransferCoinArgs(t,g,i,t.sdkOptions,v,y);s=A.tx,a=A.txRes}return{tx:s,coin_ab_s:a}}static buildSwapTransactionWithoutTransferCoins(t,i,r){let n=new Bn.Transaction;n.setSender(t.getSenderAddress());let s=nt.CoinAssist.buildCoinForAmount(n,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1,!0),a=nt.CoinAssist.buildCoinForAmount(n,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1,!0),c=Qi.buildSwapTransactionWithoutTransferCoinArgs(t,n,i,t.sdkOptions,s,a);return{tx:c.tx,coin_ab_s:c.txRes}}static buildSwapTransactionWithoutTransferCoinArgs(t,i,r,n,s,a){let{clmm_pool:c,integrate:p}=n,g=Qi.getDefaultSqrtPriceLimit(r.a2b),{global_config_id:v}=(0,nt.getPackagerConfigs)(c);v===void 0&&tt("InvalidConfig","clmm.config.global_config_id is undefined");let y=r.swap_partner!==void 0,A=y?"swap_with_partner":"swap",k=y?qf:Dl,U=y?[i.object(v),i.object(r.pool_id),i.object(r.swap_partner),s.target_coin,a.target_coin,i.pure.bool(r.a2b),i.pure.bool(r.by_amount_in),i.pure.u64(r.amount),i.pure.u128(g.toString()),i.pure.bool(!1),i.object(nt.CLOCK_ADDRESS)]:[i.object(v),i.object(r.pool_id),s.target_coin,a.target_coin,i.pure.bool(r.a2b),i.pure.bool(r.by_amount_in),i.pure.u64(r.amount),i.pure.u128(g.toString()),i.pure.bool(!1),i.object(nt.CLOCK_ADDRESS)],P=[r.coin_type_a,r.coin_type_b],W=i.moveCall({target:`${p.published_at}::${k}::${A}`,typeArguments:P,arguments:U});if(r.by_amount_in){let j=r.a2b?r.coin_type_b:r.coin_type_a,K=r.a2b?W[1]:W[0],X=Number(r.amount_limit);lr.checkCoinThreshold(t,r.by_amount_in,i,K,X,j)}return{tx:i,txRes:W}}};function Bp(e){return{coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b,current_sqrt_price:new Ti.default(e.current_sqrt_price),current_tick_index:e.current_tick_index,fee_growth_global_a:new Ti.default(e.fee_growth_global_a),fee_growth_global_b:new Ti.default(e.fee_growth_global_b),fee_protocol_coin_a:new Ti.default(e.fee_protocol_coin_a),fee_protocol_coin_b:new Ti.default(e.fee_protocol_coin_b),fee_rate:new Ti.default(e.fee_rate),liquidity:new Ti.default(e.liquidity),tick_indexes:[],tick_spacing:Number(e.tick_spacing),ticks:[],collection_name:""}}function Up(e,t,i,r,n,s){if(i===it.ZERO)return{amount_in:it.ZERO,amount_out:it.ZERO,next_sqrt_price:t,fee_amount:it.ZERO};let a=e.gte(t),c,p,g,v;if(s){let y=it.MathUtil.checkMulDivFloor(r,it.MathUtil.checkUnsignedSub(it.FEE_RATE_DENOMINATOR,n),it.FEE_RATE_DENOMINATOR,64),A=(0,it.getDeltaUpFromInput)(e,t,i,a);A.gt(y)?(c=y,v=it.MathUtil.checkUnsignedSub(r,y),g=(0,it.getNextSqrtPriceFromInput)(e,i,y,a)):(c=A,v=it.MathUtil.checkMulDivCeil(c,n,it.FEE_RATE_DENOMINATOR.sub(n),64),g=t),p=(0,it.getDeltaDownFromOutput)(e,g,i,a)}else{let y=(0,it.getDeltaDownFromOutput)(e,t,i,a);y.gt(r)?(p=r,g=(0,it.getNextSqrtPriceFromOutput)(e,i,r,a)):(p=y,g=t),c=(0,it.getDeltaUpFromInput)(e,g,i,a),v=it.MathUtil.checkMulDivCeil(c,n,it.FEE_RATE_DENOMINATOR.sub(n),64)}return{amount_in:c,amount_out:p,next_sqrt_price:g,fee_amount:v}}function jp(e,t,i,r,n){let s=i,a=r.liquidity,{current_sqrt_price:c}=r,p={amount_in:it.ZERO,amount_out:it.ZERO,fee_amount:it.ZERO,ref_amount:it.ZERO,next_sqrt_price:it.ZERO,cross_tick_num:0},g,v,y=Mr.getDefaultSqrtPriceLimit(e);for(let A of n){if(e&&r.current_tick_index<A.index||!e&&r.current_tick_index>=A.index||A===null)continue;e&&y.gt(A.sqrt_price)||!e&&y.lt(A.sqrt_price)?g=y:g=A.sqrt_price;let k=Up(c,g,a,s,r.fee_rate,t);if(k.amount_in.eq(it.ZERO)||(s=t?s.sub(k.amount_in.add(k.fee_amount)):s.sub(k.amount_out)),p.amount_in=p.amount_in.add(k.amount_in),p.amount_out=p.amount_out.add(k.amount_out),p.fee_amount=p.fee_amount.add(k.fee_amount),k.next_sqrt_price.eq(A.sqrt_price)?(v=A.liquidity_net.mul(new Ti.default(-1)),e?it.MathUtil.is_neg(v)?a=a.add(new Ti.default((0,it.asUintN)(BigInt(v.toString()),128))):a=a.add(v):it.MathUtil.is_neg(v)?a=a.sub(new Ti.default((0,it.asUintN)(BigInt(v.toString()),128))):a=a.sub(v),c=A.sqrt_price):c=k.next_sqrt_price,p.cross_tick_num+=1,s.eq(it.ZERO))break}return p.amount_in=p.amount_in.add(p.fee_amount),p.next_sqrt_price=c,p}var bi=qi($i());function qp(e,t,i){let r=(0,Ue.extractStructTagFromType)(e).name,n=(0,Ue.extractStructTagFromType)(t).name;return`${r}-${n}[${i}]`}function Yo(e){let t=(0,Ue.getMoveObjectType)(e),i=(0,Ue.extractStructTagFromType)(t),r=(0,Ue.getObjectFields)(e);r==null&&tt("InvalidPoolObject",`Pool id ${(0,Ue.getObjectId)(e)} not exists.`,{[Ue.DETAILS_KEYS.METHOD_NAME]:"buildPool"});let n=[];r.rewarder_manager.fields.rewarders.forEach(p=>{let{emissions_per_second:g}=p.fields,v=Ue.MathUtil.fromX64(new bi.default(g)),y=Math.floor(v.toNumber()*60*60*24);n.push({emissions_per_second:g,coin_type:(0,Ue.extractStructTagFromType)(p.fields.reward_coin.fields.name).source_address,growth_global:p.fields.growth_global,emissions_every_day:y})});let s=r.is_pause,a={disable_add_liquidity:s,disable_remove_liquidity:s,disable_swap:s,disable_flash_loan:s,disable_collect_fee:s,disable_collect_reward:s},c={id:(0,Ue.getObjectId)(e),pool_type:t,coin_type_a:i.type_arguments[0],coin_type_b:i.type_arguments[1],coin_amount_a:r.coin_a,coin_amount_b:r.coin_b,current_sqrt_price:r.current_sqrt_price,current_tick_index:(0,Ue.asIntN)(BigInt(r.current_tick_index.fields.bits)),fee_growth_global_a:r.fee_growth_global_a,fee_growth_global_b:r.fee_growth_global_b,fee_protocol_coin_a:r.fee_protocol_coin_a,fee_protocol_coin_b:r.fee_protocol_coin_b,fee_rate:r.fee_rate,pool_status:a,liquidity:r.liquidity,position_manager:{positions_handle:r.position_manager.fields.positions.fields.id.id,size:r.position_manager.fields.positions.fields.size},rewarder_infos:n,rewarder_last_updated_time:r.rewarder_manager.fields.last_updated_time,tick_spacing:r.tick_spacing,ticks_handle:r.tick_manager.fields.ticks.fields.id.id,uri:r.url,index:Number(r.index),name:""};return c.name=qp(c.coin_type_a,c.coin_type_b,c.tick_spacing),c}function Qo(e){(e.error!=null||e.data?.content?.dataType!=="moveObject")&&tt("InvalidPositionObject",`Position not exists. Get Position error:${e.error}`,{[Ue.DETAILS_KEYS.METHOD_NAME]:"buildPosition"});let t={creator:"",description:"",image_url:"",link:"",name:"",project_url:""},i={...t,pos_object_id:"",owner:"",type:"",coin_type_a:"",coin_type_b:"",liquidity:"",tick_lower_index:0,tick_upper_index:0,index:0,pool:"",reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"},r=(0,Ue.getObjectFields)(e);if(r){let a=(0,Ue.getMoveObjectType)(e),c=(0,Ue.getObjectOwner)(e);"nft"in r?(r=r.nft.fields,t.description=r.description,t.name=r.name,t.link=r.url):t=(0,Ue.buildNFT)(e),i={...t,pos_object_id:r.id.id,owner:c.AddressOwner,type:a,liquidity:r.liquidity,coin_type_a:r.coin_type_a.fields.name,coin_type_b:r.coin_type_b.fields.name,tick_lower_index:(0,Ue.asIntN)(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:(0,Ue.asIntN)(BigInt(r.tick_upper_index.fields.bits)),index:r.index,pool:r.pool,reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"}}let n=(0,Ue.getObjectDeletedResponse)(e);n&&(i.pos_object_id=n.objectId,i.position_status="Deleted");let s=(0,Ue.getObjectNotExistsResponse)(e);return s&&(i.pos_object_id=s,i.position_status="NotExists"),i}function as(e){let t={reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0"};e="fields"in e?e.fields:e,e.rewards.forEach((n,s)=>{let{amount_owned:a,growth_inside:c}="fields"in n?n.fields:n;s===0?(t.reward_amount_owned_0=a,t.reward_growth_inside_0=c):s===1?(t.reward_amount_owned_1=a,t.reward_growth_inside_1=c):s===2&&(t.reward_amount_owned_2=a,t.reward_growth_inside_2=c)});let i="fields"in e.tick_lower_index?e.tick_lower_index.fields.bits:e.tick_lower_index.bits,r="fields"in e.tick_upper_index?e.tick_upper_index.fields.bits:e.tick_upper_index.bits;return{liquidity:e.liquidity,tick_lower_index:(0,Ue.asIntN)(BigInt(i)),tick_upper_index:(0,Ue.asIntN)(BigInt(r)),...t,fee_growth_inside_a:e.fee_growth_inside_a,fee_owned_a:e.fee_owned_a,fee_growth_inside_b:e.fee_growth_inside_b,fee_owned_b:e.fee_owned_b,pos_object_id:e.position_id}}function es(e){(e.error!=null||e.data?.content?.dataType!=="moveObject")&&tt("InvalidTickObject",`Tick not exists. Get tick data error:${e.error}`,{[Ue.DETAILS_KEYS.METHOD_NAME]:"buildTickData"});let t=(0,Ue.getObjectFields)(e).value.fields.value.fields;return{object_id:(0,Ue.getObjectId)(e),index:(0,Ue.asIntN)(BigInt(t.index.fields.bits)),sqrt_price:new bi.default(t.sqrt_price),liquidity_net:new bi.default(t.liquidity_net.fields.bits),liquidity_gross:new bi.default(t.liquidity_gross),fee_growth_outside_a:new bi.default(t.fee_growth_outside_a),fee_growth_outside_b:new bi.default(t.fee_growth_outside_b),rewarders_growth_outside:t.rewards_growth_outside}}function $p(e){(!e||!e.index||!e.sqrt_price||!e.liquidity_net||!e.liquidity_gross||!e.fee_growth_outside_a||!e.fee_growth_outside_b)&&tt("InvalidTickFields","Invalid tick fields.",{[Ue.DETAILS_KEYS.METHOD_NAME]:"buildTickDataByEvent"});let t=(0,Ue.asIntN)(BigInt(e.index.bits)),i=new bi.default(e.sqrt_price),r=new bi.default(e.liquidity_net.bits),n=new bi.default(e.liquidity_gross),s=new bi.default(e.fee_growth_outside_a),a=new bi.default(e.fee_growth_outside_b),c=e.rewards_growth_outside||[];return{object_id:"",index:t,sqrt_price:i,liquidity_net:r,liquidity_gross:n,fee_growth_outside_a:s,fee_growth_outside_b:a,rewarders_growth_outside:c}}function Hp(e,t,i){let r=[],{timestampMs:n,events:s}=e,a=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent"];return s?.forEach((c,p)=>{let g=(0,Ue.extractStructTagFromType)(c.type).name;if(a.includes(g)){let v={tx_digest:c.id.txDigest,package_id:c.packageId,transaction_module:c.transactionModule,sender:c.sender,type:c.type,timestamp_ms:n||"0",parsed_json:c.parsedJson,index:`${t}_${p}`};switch(g){case"CollectFeeEvent":i.includes(v.parsed_json.position)&&((0,Ue.d)(v.parsed_json.amount_a).gt(0)||(0,Ue.d)(v.parsed_json.amount_b).gt(0))&&r.push(v);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":((0,Ue.d)(v.parsed_json.amount_a).gt(0)||(0,Ue.d)(v.parsed_json.amount_b).gt(0))&&r.push(v);break;case"CollectRewardEvent":case"HarvestEvent":case"CollectRewardV2Event":(i.includes(v.parsed_json.position)||i.includes(v.parsed_json.wrapped_position_id))&&(0,Ue.d)(v.parsed_json.amount).gt(0)&&r.push(v);break;default:break}}}),r}function Gp(e,t,i,r){let n=[],{timestampMs:s,events:a}=e;return a?.forEach((c,p)=>{let{name:g,address:v}=(0,Ue.extractStructTagFromType)(c.type);if(Bf.includes(g)&&v===i&&r===c.parsedJson.pool){let y={tx:c.id.txDigest,sender:c.sender,type:c.type,block_time:s||"0",index:`${t}_${p}`,parsed_json:c.parsedJson};n.push(y)}}),n}function ls(e,t,i,r){t.moveCall({target:`${e.sdkOptions.integrate.published_at}::${$f}::transfer_coin_to_sender`,typeArguments:[r],arguments:[i]})}function Vp(e,t,i,r,n){n!=null?t.transferObjects([i],t.pure.address(n)):ls(e,t,i,r)}var Zp=1e4,Er=class{static parseClmmVestInfo(e){let t=(0,Dt.getObjectFields)(e),i=(0,Dt.getObjectType)(e),r=(0,Dt.extractStructTagFromType)(i),n=t.global_vesting_periods.map(s=>({period:s.fields.period,release_time:s.fields.release_time,redeemed_amount:s.fields.redeemed_amount,percentage:(0,Dt.d)(s.fields.percentage).div(Zp).toNumber()}));return{id:t.id.id,balance:t.balance,global_vesting_periods:n,total_value:t.total_value,total_cetus_amount:t.total_cetus_amount,redeemed_amount:t.redeemed_amount,start_time:t.start_time,type:r.full_address,positions:{id:t.positions.fields.id,size:t.positions.fields.size}}}static parsePositionVesting(e){return{position_id:e.position_id,cetus_amount:e.cetus_amount,redeemed_amount:e.redeemed_amount,is_paused:e.is_paused,impaired_a:e.impaired_a,impaired_b:e.impaired_b,period_details:e.period_details,coin_type_a:(0,Dt.fixCoinType)(e.coin_a.name,!1),coin_type_b:(0,Dt.fixCoinType)(e.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(e){let t=(0,Dt.getObjectFields)(e);return{current_sqrt_price:t.current_sqrt_price,remove_percent:(0,Dt.d)(t.remove_percent).div(1e6).toString(),snapshots:{id:t.snapshots.fields.id.id,size:t.snapshots.fields.size}}}static parsePositionSnapshot(e){let t=(0,Dt.getObjectFields)(e),i=t.value.fields.value.fields;return{position_id:t.name,liquidity:i.liquidity,tick_lower_index:(0,Dt.asIntN)(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:(0,Dt.asIntN)(BigInt(i.tick_upper_index.fields.bits)),fee_owned_a:i.fee_owned_a,fee_owned_b:i.fee_owned_b,value_cut:i.value_cut,rewards:i.rewards}}},Kp=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}async getPositionList(e,t="all"){let i={data:[],has_next_page:!0},r=await this._sdk.FullClient.getDynamicFieldsByPage(e,t);i.has_next_page=r.has_next_page,i.next_cursor=r.next_cursor;let n=r.data.map(a=>(a.error!=null&&tt("InvalidConfig",`when getPositionList get position objects error: ${a.error}, please check the rpc, contracts address config and position id.`,{[de.DETAILS_KEYS.METHOD_NAME]:"getPositionList"}),a.name.value)),s=await this._sdk.Position.getSimplePositionList(n);return i.data=s,i}async getPoolImmutablesWithPage(e="all",t=!1){let{package_id:i}=this._sdk.sdkOptions.clmm_pool,r=[],n={data:[],has_next_page:!1},s=e==="all",a=`${i}_getPoolImmutables`;if(s){let c=this._sdk.getCache(a,t);c&&r.push(...c)}if(r.length===0)try{let c=`${i}::factory::CreatePoolEvent`,p=await this._sdk.FullClient.queryEventsByPage({MoveEventType:c},e);n.has_next_page=p.has_next_page,n.next_cursor=p.next_cursor,p.data.forEach(g=>{let v=g.parsedJson;v&&r.push({id:v.pool_id,tick_spacing:v.tick_spacing,coin_type_a:(0,de.extractStructTagFromType)(v.coin_type_a).full_address,coin_type_b:(0,de.extractStructTagFromType)(v.coin_type_b).full_address})})}catch(c){return ji("FetchError",c,{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolImmutables"})}return n.data=r,s&&this._sdk.updateCache(`${i}_getPoolImmutables`,r,de.CACHE_TIME_24H),n}async getPoolsWithPage(e="all",t=!1){let i={data:[],has_next_page:!1},r=await this.getPoolImmutablesWithPage(e,t),n=await this._sdk.FullClient.batchGetObjects(r.data.map(s=>s.id),{showContent:!0,showType:!0});for(let s of n){(s.error!=null||s.data?.content?.dataType!=="moveObject")&&tt("InvalidPoolObject",`getPoolWithPages error code: ${s.error?.code??"unknown error"}, please check config and object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolsWithPage"});let a=Yo(s);i.data.push(a);let c=`${a.id}_getPoolObject`;this._sdk.updateCache(c,a,de.CACHE_TIME_24H)}return i.has_next_page=r.has_next_page,i.next_cursor=r.next_cursor,i}async getPoolLiquiditySnapshot(e,t=!1){try{let i=await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"0x1::string::String",value:Ff}}),r=Er.parsePoolLiquiditySnapshot(i);if(t){let n=(await this._sdk.FullClient.getDynamicFieldsByPage(r.snapshots.id)).data.map(s=>s.objectId);if(n.length>0){let s=await this._sdk.FullClient.batchGetObjects(n,{showContent:!0,showType:!0}),a=[];s.forEach(c=>{let p=Er.parsePositionSnapshot(c);a.push(p)}),r.position_snapshots=a}}return r}catch(i){return ji("InvalidPoolObject",i,{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolLiquiditySnapshot",[de.DETAILS_KEYS.REQUEST_PARAMS]:e})}}async getPositionSnapshot(e,t){let i=await this._sdk.FullClient.getDynamicFieldObjects(e,t,"0x2::object::ID","address"),r=[];return i.forEach(n=>{try{let s=Er.parsePositionSnapshot(n);r.push(s)}catch(s){console.log("getPositionSnapshot error: ",s)}}),r}async getAssignPools(e){if(e.length===0)return[];let t=[],i=await this._sdk.FullClient.batchGetObjects(e,{showContent:!0,showType:!0});for(let r of i){(r.error!=null||r.data?.content?.dataType!=="moveObject")&&tt("InvalidPoolObject",`getPools error code: ${r.error?.code??"unknown error"}, please check config and object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getAssignPools"});let n=Yo(r);t.push(n);let s=`${n.id}_getPoolObject`;this._sdk.updateCache(s,n,de.CACHE_TIME_24H)}return t}async getPool(e,t=!0,i=!1){let r=`${e}_getPoolObject`,n=this._sdk.getCache(r,t);if(n!==void 0)return n;let s=await this._sdk.FullClient.getObject({id:e,options:{showType:!0,showContent:!0}});(s.error!=null||s.data?.content?.dataType!=="moveObject")&&tt("InvalidPoolObject",`getPool error code: ${s.error?.code??"unknown error"}, please check config and object id`,{[de.DETAILS_KEYS.METHOD_NAME]:"getPool"});let a=Yo(s);if(i){let c=await this.getPoolStatus(e);c&&(a.pool_status=c)}return this._sdk.updateCache(r,a),a}async getPoolByCoins(e,t){if(e.length===0)return[];for(let c=0;c<e.length;c++)e[c]==="0x2::sui::SUI"&&(e[c]="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI");let i=this._sdk.sdkOptions.stats_pools_url;i||tt("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins"}),i+=`?order_by=-fees&limit=100&has_mining=true&has_farming=true&no_incentives=true&display_all_pools=true&coin_type=${e.join(",")}`;let r=await fetch(i),n;try{n=await r.json()}catch(c){ji("FetchError",c,{[de.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins",[de.DETAILS_KEYS.REQUEST_PARAMS]:i})}let s=n.data.lp_list,a=[];for(let c of s)e.includes(c.coin_a_address)&&e.includes(c.coin_b_address)&&(t!=null?c.object.feeRate===t&&a.push(c.address):a.push(c.address));return a.length>0?await this.getAssignPools(a):[]}async createPoolPayload(e,t){if((0,de.isSortedSymbols)((0,ar.normalizeSuiAddress)(e.coin_type_a),(0,ar.normalizeSuiAddress)(e.coin_type_b))){let i=e.coin_type_b;e.coin_type_b=e.coin_type_a,e.coin_type_a=i;let r=e.metadata_b;e.metadata_b=e.metadata_a,e.metadata_a=r}return await this.createPoolAndAddLiquidity(e,t)}async createPoolRowPayload(e,t){if((0,de.isSortedSymbols)((0,ar.normalizeSuiAddress)(e.coin_type_a),(0,ar.normalizeSuiAddress)(e.coin_type_b))){let i=e.coin_type_b;e.coin_type_b=e.coin_type_a,e.coin_type_a=i;let r=e.metadata_b;e.metadata_b=e.metadata_a,e.metadata_a=r}return await this.createPoolAndAddLiquidityRow(e,t)}async getClmmConfigs(e=!1){let{package_id:t}=this._sdk.sdkOptions.clmm_pool,i=`${t}_getInitEvent`,r=this._sdk.getCache(i,e);if(r!==void 0)return r;let n=await this._sdk.FullClient.getObject({id:t,options:{showPreviousTransaction:!0}}),s=(0,de.getObjectPreviousTransactionDigest)(n),a=(await this._sdk.FullClient.queryEventsByPage({Transaction:s})).data,c={pools_id:"",global_config_id:"",global_vault_id:"",admin_cap_id:""};return a.length>0&&(a.forEach(p=>{let g=p.parsedJson;if(p.type)switch((0,de.extractStructTagFromType)(p.type).full_address){case`${t}::config::InitConfigEvent`:c.global_config_id=g.global_config_id,c.admin_cap_id=g.admin_cap_id;break;case`${t}::factory::InitFactoryEvent`:c.pools_id=g.pools_id;break;case`${t}::rewarder::RewarderInitEvent`:c.global_vault_id=g.global_vault_id;break;case`${t}::partner::InitPartnerEvent`:c.partners_id=g.partners_id;break;default:break}}),this._sdk.updateCache(i,c,de.CACHE_TIME_24H)),c}async getPoolTransactionList({pool_id:e,pagination_args:t,order:i="descending",full_rpc_url:r}){let{FullClient:n,sdkOptions:s}=this._sdk,a;r?a=(0,de.createFullClient)(new Ll.SuiClient({url:r})):a=n;let c={data:[],has_next_page:!1},p=50,g=t,v=t.limit||10;do{let y=await a.queryTransactionBlocksByPage({ChangedObject:e},{...g,limit:50},i);y.data.forEach((A,k)=>{c.next_cursor=y.next_cursor;let U=Gp(A,k,s.clmm_pool.package_id,e);c.data=[...c.data,...U]}),c.has_next_page=y.has_next_page,c.next_cursor=y.next_cursor,g.cursor=y.next_cursor}while(c.data.length<v&&c.has_next_page);return c.data.length>v&&(c.data=c.data.slice(0,v),c.next_cursor=c.data[c.data.length-1].tx),c}async calculateCreatePoolWithPrice(e){let{current_price:t,slippage:i,tick_spacing:r,add_mode_params:n,price_base_coin:s,coin_decimals_a:a,coin_decimals_b:c}=e,p=de.TickMath.priceToSqrtPriceX64(s==="coin_a"?(0,de.d)(t):(0,de.d)(1).div(t),a,c),g=0,v=0;if(n.is_full_range)g=de.TickUtil.getMinIndex(r),v=de.TickUtil.getMaxIndex(r);else{let{min_price:K,max_price:X}=n;g=de.TickMath.priceToInitializeTickIndex(s==="coin_a"?(0,de.d)(K):(0,de.d)(1).div(X),a,c,r),v=de.TickMath.priceToInitializeTickIndex(s==="coin_a"?(0,de.d)(X):(0,de.d)(1).div(K),a,c,r)}let{coin_amount:y,fix_amount_a:A}=e,{coin_amount_limit_a:k,coin_amount_limit_b:U,liquidity_amount:P,coin_amount_a:W,coin_amount_b:j}=de.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(g,v,new Lf.default(y),A,!0,i,p);return{coin_amount_a:W,coin_amount_b:j,coin_amount_limit_a:k,coin_amount_limit_b:U,liquidity:P,initialize_sqrt_price:p.toString(),tick_lower:g,tick_upper:v,fix_amount_a:A}}async createPoolAndAddLiquidity(e,t){t=t||new yr.Transaction,t.setSender(this.sdk.getSenderAddress());let{integrate:i,clmm_pool:r}=this.sdk.sdkOptions,n=(0,de.getPackagerConfigs)(r),s=n.global_config_id,a=n.pools_id,c=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),p=de.CoinAssist.buildCoinForAmount(t,c,BigInt(e.amount_a),e.coin_type_a,!1,!0),g=de.CoinAssist.buildCoinForAmount(t,c,BigInt(e.amount_b),e.coin_type_b,!1,!0),v=[t.object(s),t.object(a),t.pure.u32(e.tick_spacing),t.pure.u128(e.initialize_sqrt_price),t.pure.string(e.uri),t.pure.u32(Number((0,de.asUintN)(BigInt(e.tick_lower)).toString())),t.pure.u32(Number((0,de.asUintN)(BigInt(e.tick_upper)).toString())),p.target_coin,g.target_coin,t.object(e.metadata_a),t.object(e.metadata_b),t.pure.bool(e.fix_amount_a),t.object(de.CLOCK_ADDRESS)];return t.moveCall({target:`${i.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[e.coin_type_a,e.coin_type_b],arguments:v}),ls(this._sdk,t,p.target_coin,e.coin_type_a),ls(this._sdk,t,g.target_coin,e.coin_type_b),t}async createPoolAndAddLiquidityRow(e,t){t=t||new yr.Transaction;let{clmm_pool:i}=this.sdk.sdkOptions,r=(0,de.getPackagerConfigs)(i),n=r.global_config_id,s=r.pools_id,a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),c=de.CoinAssist.buildCoinForAmount(t,a,BigInt(e.amount_a),e.coin_type_a,!1,!0),p=de.CoinAssist.buildCoinForAmount(t,a,BigInt(e.amount_b),e.coin_type_b,!1,!0),g=[t.object(n),t.object(s),t.pure.u32(e.tick_spacing),t.pure.u128(e.initialize_sqrt_price),t.pure.string(e.uri),t.pure.u32(Number((0,de.asUintN)(BigInt(e.tick_lower)).toString())),t.pure.u32(Number((0,de.asUintN)(BigInt(e.tick_upper)).toString())),c.target_coin,p.target_coin,t.object(e.metadata_a),t.object(e.metadata_b),t.pure.bool(e.fix_amount_a),t.object(de.CLOCK_ADDRESS)],v=t.moveCall({target:`${i.published_at}::pool_creator::create_pool_v2`,typeArguments:[e.coin_type_a,e.coin_type_b],arguments:g});return{tx:t,pos_id:v[0],remain_coin_a:v[1],remain_coin_b:v[2],remain_coin_type_a:e.coin_type_a,remain_coin_type_b:e.coin_type_b}}async createPoolWithPriceReturnPositionPayload(e,t){let{coin_type_a:i,coin_type_b:r,tick_spacing:n,uri:s,calculate_result:a}=e,{initialize_sqrt_price:c,tick_lower:p,tick_upper:g,liquidity:v,coin_amount_a:y,coin_amount_b:A,fix_amount_a:k,coin_amount_limit_a:U,coin_amount_limit_b:P}=a,W=await this._sdk.FullClient.fetchCoinMetadata(i),j=await this._sdk.FullClient.fetchCoinMetadata(r);if(W===null)return tt("FetchError",`fetch coin ${i} metadata failed`,{[de.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[de.DETAILS_KEYS.REQUEST_PARAMS]:e});if(j===null)return tt("FetchError",`fetch coin ${r} metadata failed`,{[de.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[de.DETAILS_KEYS.REQUEST_PARAMS]:e});let K=W.id,X=j.id;return this.createPoolRowPayload({tick_spacing:n,initialize_sqrt_price:c,uri:s||"",coin_type_a:i,coin_type_b:r,amount_a:k?y:U,amount_b:k?P:A,fix_amount_a:k,tick_lower:p,tick_upper:g,metadata_a:K,metadata_b:X},t)}async createPoolWithPricePayload(e){let{coin_type_a:t,coin_type_b:i,tick_spacing:r,uri:n,calculate_result:s}=e,{initialize_sqrt_price:a,tick_lower:c,tick_upper:p,liquidity:g,coin_amount_a:v,coin_amount_b:y,fix_amount_a:A,coin_amount_limit_a:k,coin_amount_limit_b:U}=s,P=await this._sdk.FullClient.fetchCoinMetadata(t),W=await this._sdk.FullClient.fetchCoinMetadata(i);if(P===null)return tt("FetchError",`fetch coin ${t} metadata failed`,{[de.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[de.DETAILS_KEYS.REQUEST_PARAMS]:e});if(W===null)return tt("FetchError",`fetch coin ${i} metadata failed`,{[de.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[de.DETAILS_KEYS.REQUEST_PARAMS]:e});let j=P.id,K=W.id;return this.createPoolPayload({tick_spacing:r,initialize_sqrt_price:a,uri:n||"",coin_type_a:t,coin_type_b:i,amount_a:A?v:k,amount_b:A?U:y,fix_amount_a:A,tick_lower:c,tick_upper:p,metadata_a:j,metadata_b:K})}async fetchTicks(e){let t=[],i=[];for(;;){let r=await this.getTicks({pool_id:e.pool_id,coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b,start:i,limit:512});if(t=[...t,...r],r.length<512)break;i=[Number((0,de.asUintN)(BigInt(r[r.length-1].index)))]}return t}async getTicks(e){let{integrate:t}=this.sdk.sdkOptions,i=[],r=[e.coin_type_a,e.coin_type_b],n=new yr.Transaction,s=n.makeMoveVec({elements:e.start.map(p=>n.pure.u32(p)),type:"u32"}),a=[n.object(e.pool_id),s,n.pure.u64(e.limit.toString())];n.moveCall({target:`${t.published_at}::${Ir}::fetch_ticks`,arguments:a,typeArguments:r});let c=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,ar.normalizeSuiAddress)("0x0")});return c.error!=null&&tt("InvalidTickObjectId",`getTicks error code: ${c.error??"unknown error"}, please check config and tick object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getTicks",[de.DETAILS_KEYS.REQUEST_PARAMS]:e}),c.events?.forEach(p=>{(0,de.extractStructTagFromType)(p.type).name==="FetchTicksResultEvent"&&p.parsedJson.ticks.forEach(g=>{i.push($p(g))})}),i}async fetchPoolPositionInfoList(e){let{integrate:t}=this.sdk.sdkOptions,i=[],r=[],n=512;for(;;){let s=[e.coin_type_a,e.coin_type_b],a=new yr.Transaction,c=a.pure.vector("id",r.map(y=>y)),p=[a.object(e.pool_id),c,a.pure.u64(n)];a.moveCall({target:`${t.published_at}::${Ir}::fetch_positions`,arguments:p,typeArguments:s});let g=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:a,sender:(0,ar.normalizeSuiAddress)("0x0")});g.error!=null&&tt("InvalidPositionRewardObject",`fetch position info error code: ${g.error??"unknown error"}, please check config and tick object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"fetchPoolPositionInfoList",[de.DETAILS_KEYS.REQUEST_PARAMS]:e});let v=[];if(g?.events?.forEach(y=>{(0,de.extractStructTagFromType)(y.type).name==="FetchPositionsEvent"&&y.parsedJson.positions.forEach(A=>{let k=as(A);v.push(k)})}),i.push(...v),v.length<n)break;r=[v[v.length-1].pos_object_id]}return i}async fetchTicksByRpc(e){let t=[],i=null,r=50;for(;;){let n=[],s=await this.sdk.FullClient.getDynamicFields({parentId:e,cursor:i,limit:r});if(i=s.nextCursor,s.data.forEach(a=>{(0,de.extractStructTagFromType)(a.objectType).module==="skip_list"&&n.push(a.objectId)}),t=[...t,...await this.getTicksByRpc(n)],!s.hasNextPage)break}return t}async getTicksByRpc(e){let t=[],i=await this.sdk.FullClient.batchGetObjects(e,{showContent:!0,showType:!0});for(let r of i){(r.error!=null||r.data?.content?.dataType!=="moveObject")&&tt("InvalidTickObjectId",`getTicksByRpc error code: ${r.error?.code??"unknown error"}, please check config and tick object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getTicksByRpc"});let n=es(r);n!=null&&t.push(n)}return t}async getTickDataByIndex(e,t){let i={type:"u64",value:(0,de.asUintN)(BigInt((0,de.tickScore)(t).toString())).toString()},r=await this.sdk.FullClient.getDynamicFieldObject({parentId:e,name:i});return(r.error!=null||r.data?.content?.dataType!=="moveObject")&&tt("InvalidTickIndex",`get tick by index: ${t} error: ${r.error}`,{[de.DETAILS_KEYS.METHOD_NAME]:"getTickDataByIndex"}),es(r)}async getTickDataByObjectId(e){let t=await this.sdk.FullClient.getObject({id:e,options:{showContent:!0}});return(t.error!=null||t.data?.content?.dataType!=="moveObject")&&tt("InvalidTickObjectId",`getTicksByRpc error code: ${t.error?.code??"unknown error"}, please check config and tick object ids`,{[de.DETAILS_KEYS.METHOD_NAME]:"getTickDataByObjectId"}),es(t)}async getPartnerRefFeeAmount(e,t=!0){let i=await this._sdk.FullClient.batchGetObjects([e],{showOwner:!0,showContent:!0,showDisplay:t,showType:!0});i[0].data?.content?.dataType!=="moveObject"&&tt("NotFoundPartnerObject",`get partner by object id: ${e} error: ${i[0].error}`,{[de.DETAILS_KEYS.METHOD_NAME]:"getPartnerRefFeeAmount"});let r=i[0].data.content.fields.balances,n=await this._sdk.FullClient.getDynamicFieldsByPage(r.fields.id.id),s=[];n.data.forEach(c=>{c.objectId!=null&&s.push(c.objectId)});let a=[];return(await this._sdk.FullClient.batchGetObjects(s,{showOwner:!0,showContent:!0,showDisplay:t,showType:!0})).forEach(c=>{(c.error!=null||c.data?.content?.dataType!=="moveObject")&&tt("InvalidPartnerRefFeeFields",`get coin by object id: ${c.data.objectId} error: ${c.error}`,{[de.DETAILS_KEYS.METHOD_NAME]:"getPartnerRefFeeAmount"});let p={coin_type:c.data.content.fields.name,coin_object_id:c.data.objectId,balance:BigInt(c.data.content.fields.value)};a.push(p)}),a}async claimPartnerRefFeePayload(e,t,i){let r=new yr.Transaction,{clmm_pool:n}=this.sdk.sdkOptions,{global_config_id:s}=(0,de.getPackagerConfigs)(n),a=[i],c=[r.object(s),r.object(e),r.object(t)];return r.moveCall({target:`${n.published_at}::${jf}::claim_ref_fee`,arguments:c,typeArguments:a}),r}async getPoolStatus(e){try{let t=await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"0x1::string::String",value:"pool_status"}}),i=(0,de.getObjectFields)(t).position.fields.status;if(i)return i}catch(t){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",t)}}},Ln=qi($i()),Wp=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}buildPositionType(){return`${this._sdk.sdkOptions.clmm_pool.package_id}::position::Position`}async getPositionTransactionList({pos_id:e,origin_pos_id:t,full_rpc_url:i,pagination_args:r="all",order:n="ascending"}){let{FullClient:s}=this._sdk,a=[e];t&&a.push(t);let c;i?c=(0,pe.createFullClient)(new zl.SuiClient({url:i})):c=s;let p={data:[],has_next_page:!1};try{let g=await c.queryTransactionBlocksByPage({ChangedObject:e},r,n);return g.data.forEach((v,y)=>{let A=Hp(v,y,a);p.data=[...p.data,...A]}),p.has_next_page=g.has_next_page,p.next_cursor=g.next_cursor,p}catch(g){ji("FetchError",g,{[pe.DETAILS_KEYS.METHOD_NAME]:"getPositionTransactionList"})}return p}async getPositionList(e,t=[],i=!0){let r=[],n=await this._sdk.FullClient.getOwnedObjectsByPage(e,{options:{showType:!0,showContent:!0,showDisplay:i,showOwner:!0},filter:{Package:this._sdk.sdkOptions.clmm_pool.package_id}}),s=t.length>0;for(let a of n.data)if((0,pe.extractStructTagFromType)(a.data.type).full_address===this.buildPositionType()){let c=Qo(a),p=`${c.pos_object_id}_getPositionList`;this._sdk.updateCache(p,c),s?t.includes(c.pool)&&r.push(c):r.push(c)}return r}async getPosition(e,t,i=!0,r=!0){let n=await this.getSimplePosition(t,r);return i&&(n=await this.updatePositionInfo(e,n)),n}async getPositionById(e,t=!0,i=!0){let r=await this.getSimplePosition(e,i);if(t){let n=await this._sdk.Pool.getPool(r.pool,!1);return await this.updatePositionInfo(n.position_manager.positions_handle,r)}return r}async getSimplePosition(e,t=!0){let i=`${e}_getPositionList`,r=this.getSimplePositionByCache(e);if(r===void 0){let n=await this.sdk.FullClient.getObject({id:e,options:{showContent:!0,showType:!0,showDisplay:t,showOwner:!0}});r=Qo(n),this._sdk.updateCache(i,r)}return r}getSimplePositionByCache(e){let t=`${e}_getPositionList`;return this._sdk.getCache(t)}async getSimplePositionList(e,t=!0){let i=[],r=[];return e.forEach(n=>{let s=this.getSimplePositionByCache(n);s?i.push(s):r.push(n)}),r.length>0&&(await this._sdk.FullClient.batchGetObjects(r,{showOwner:!0,showContent:!0,showDisplay:t,showType:!0})).forEach(n=>{if(n.error==null){let s=Qo(n);i.push(s);let a=`${s.pos_object_id}_getPositionList`;this._sdk.updateCache(a,s)}}),i}async updatePositionInfo(e,t){let i=await this.getPositionInfo(e,t.pos_object_id);return{...t,...i}}async getPositionInfo(e,t){try{let i=await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"0x2::object::ID",value:t}}),r=(0,pe.getObjectFields)(i.data).value.fields.value;return as(r)}catch(i){return ji("FetchError",i,{[pe.DETAILS_KEYS.METHOD_NAME]:"getPositionInfo",[pe.DETAILS_KEYS.REQUEST_PARAMS]:{position_handle:e,position_id:t}})}}async getPositionInfoList(e){try{let t=[],i=[];return e.forEach(async r=>{let{position_handle:n,position_ids:s}=r;s.forEach(a=>{let c=(0,pe.deriveDynamicFieldIdByType)(n,a,"0x2::object::ID","address");i.push(c)})}),i.length===0?[]:((await this._sdk.FullClient.batchGetObjects(i,{showContent:!0,showType:!0,showOwner:!0})).forEach(r=>{try{let n=(0,pe.getObjectFields)(r.data).value.fields.value,s=as(n);t.push(s)}catch(n){console.log("getPositionInfoList error",n)}}),t)}catch(t){return ji("FetchError",t,{[pe.DETAILS_KEYS.METHOD_NAME]:"getPositionInfoList",[pe.DETAILS_KEYS.REQUEST_PARAMS]:{options:e}})}}buildFetchPosFee(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions,n=[e.coin_type_a,e.coin_type_b],s=[t.object((0,pe.getPackagerConfigs)(i).global_config_id),t.object(e.pool_id),t.pure.address(e.position_id)];t.moveCall({target:`${r.published_at}::${Ir}::fetch_position_fees`,arguments:s,typeArguments:n})}parsedPosFeeData(e){let t={},i=e.events?.filter(r=>r.type.includes("fetcher_script::FetchPositionFeesEvent"));for(let r=0;r<i.length;r+=1){let{parsedJson:n}=i[r],s={position_id:n.position_id,fee_owned_a:n.fee_owned_a,fee_owned_b:n.fee_owned_b};t[n.position_id]=s}return t}async fetchPosFeeAmount(e){let{clmm_pool:t,integrate:i}=this.sdk.sdkOptions,r=new ki.Transaction;for(let c of e)this.buildFetchPosFee(c,r);let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:(0,Jn.normalizeSuiAddress)("0x0")});n.error!=null&&tt("InvalidPoolObject",`fetch position fee error code: ${n.error??"unknown error"}, please check config and position and pool object ids`,{[pe.DETAILS_KEYS.METHOD_NAME]:"fetchPosFeeAmount"});let s=[],a=this.parsedPosFeeData(n);for(let c=0;c<e.length;c+=1){let p=a[e[c].position_id];if(p){let g={fee_owned_a:p.fee_owned_a,fee_owned_b:p.fee_owned_b,position_id:e[c].position_id};s.push(g)}}return s}async batchFetchPositionFees(e){let t=[];for(let r of e){let n=await this._sdk.Position.getPositionById(r,!1),s=await this._sdk.Pool.getPool(n.pool,!1);t.push({pool_id:s.id,position_id:n.pos_object_id,coin_type_a:s.coin_type_a,coin_type_b:s.coin_type_b})}let i={};if(t.length>0){let r=await this.fetchPosFeeAmount(t);for(let n of r)i[n.position_id]=n;return i}return i}async createAddLiquidityFixTokenPayload(e,t,i,r,n){let s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(t){let{is_adjust_coin_a:a,is_adjust_coin_b:c}=Kn(e);if(e=e,e.fix_amount_a&&a||!e.fix_amount_a&&c)return i=await lr.buildAddLiquidityFixTokenForGas(this._sdk,s,e,t,i,r,n),i}return lr.buildAddLiquidityFixToken(this._sdk,s,e,i,r,n)}async createAddLiquidityPayload(e,t,i,r){let{integrate:n,clmm_pool:s}=this._sdk.sdkOptions,a=(0,pe.asUintN)(BigInt(e.tick_lower)).toString(),c=(0,pe.asUintN)(BigInt(e.tick_upper)).toString(),p=[e.coin_type_a,e.coin_type_b];t=t||new ki.Transaction;let g=!(0,Jn.isValidSuiObjectId)(e.pos_id),v=BigInt(e.max_amount_a),y=BigInt(e.max_amount_b),A,k;if(i==null||r==null){let U=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());A=pe.CoinAssist.buildCoinForAmount(t,U,v,e.coin_type_a,!1,!0),k=pe.CoinAssist.buildCoinForAmount(t,U,y,e.coin_type_b,!1,!0)}else A={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},k={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]};if(g)t.moveCall({target:`${n.published_at}::${Cr}::open_position_with_liquidity`,typeArguments:p,arguments:[t.object((0,pe.getPackagerConfigs)(s).global_config_id),t.object(e.pool_id),t.pure.u32(Number(a)),t.pure.u32(Number(c)),A.target_coin,k.target_coin,t.pure.u64(e.max_amount_a),t.pure.u64(e.max_amount_b),t.pure.u128(e.delta_liquidity),t.object(pe.CLOCK_ADDRESS)]});else{let U=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());t=lr.createCollectRewarderAndFeeParams(this._sdk,t,e,U,A.remain_coins,k.remain_coins),t.moveCall({target:`${n.published_at}::${Cr}::add_liquidity`,typeArguments:p,arguments:[t.object((0,pe.getPackagerConfigs)(s).global_config_id),t.object(e.pool_id),t.object(e.pos_id),A.target_coin,k.target_coin,t.pure.u64(e.max_amount_a),t.pure.u64(e.max_amount_b),t.pure.u128(e.delta_liquidity),t.object(pe.CLOCK_ADDRESS)]})}return t}async removeLiquidityPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions,n="remove_liquidity";t=t||new ki.Transaction;let s=[e.coin_type_a,e.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());t=lr.createCollectRewarderAndFeeParams(this._sdk,t,e,a);let c=[t.object((0,pe.getPackagerConfigs)(i).global_config_id),t.object(e.pool_id),t.object(e.pos_id),t.pure.u128(e.delta_liquidity),t.pure.u64(e.min_amount_a),t.pure.u64(e.min_amount_b),t.object(pe.CLOCK_ADDRESS)];return t.moveCall({target:`${r.published_at}::${Rn}::${n}`,typeArguments:s,arguments:c}),t}async closePositionPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions;t=t||new ki.Transaction;let n=[e.coin_type_a,e.coin_type_b],s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return t=lr.createCollectRewarderAndFeeParams(this._sdk,t,e,s),t.moveCall({target:`${r.published_at}::${Rn}::close_position`,typeArguments:n,arguments:[t.object((0,pe.getPackagerConfigs)(i).global_config_id),t.object(e.pool_id),t.object(e.pos_id),t.pure.u64(e.min_amount_a),t.pure.u64(e.min_amount_b),t.object(pe.CLOCK_ADDRESS)]}),t}openPositionPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions;t=t||new ki.Transaction;let n=[e.coin_type_a,e.coin_type_b],s=(0,pe.asUintN)(BigInt(e.tick_lower)).toString(),a=(0,pe.asUintN)(BigInt(e.tick_upper)).toString(),c=[t.object((0,pe.getPackagerConfigs)(i).global_config_id),t.object(e.pool_id),t.pure.u32(Number(s)),t.pure.u32(Number(a))];return t.moveCall({target:`${r.published_at}::${Rn}::open_position`,typeArguments:n,arguments:c}),t}async openPositionWithPricePayload(e,t){let{pool_id:i}=e,{clmm_pool:r,integrate:n}=this.sdk.sdkOptions;t=t||new ki.Transaction;let s=await this.sdk.Pool.getPool(i,!1),a=Number(s.tick_spacing),c=0,p=0;if(e.is_full_range)c=pe.TickUtil.getMinIndex(a),p=pe.TickUtil.getMaxIndex(a);else{let{price_base_coin:y,min_price:A,max_price:k}=e;c=pe.TickMath.priceToInitializeTickIndex(y==="coin_a"?(0,pe.d)(A):(0,pe.d)(1).div(k),e.coin_decimals_a,e.coin_decimals_b,a),p=pe.TickMath.priceToInitializeTickIndex(y==="coin_a"?(0,pe.d)(k):(0,pe.d)(1).div(A),e.coin_decimals_a,e.coin_decimals_b,a)}let g=[s.coin_type_a,s.coin_type_b],v=[t.object((0,pe.getPackagerConfigs)(r).global_config_id),t.object(e.pool_id),t.pure.u32(Number((0,pe.asUintN)(BigInt(c)))),t.pure.u32(Number((0,pe.asUintN)(BigInt(p))))];return t.moveCall({target:`${n.published_at}::${Rn}::open_position`,typeArguments:g,arguments:v}),t}async collectFeePayload(e,t,i,r){t=t||new ki.Transaction;let n=i||pe.CoinAssist.buildCoinWithBalance(BigInt(0),e.coin_type_a,t),s=r||pe.CoinAssist.buildCoinWithBalance(BigInt(0),e.coin_type_b,t);return this.createCollectFeePayload(e,t,n,s),t}createCollectFeePayload(e,t,i,r){let{clmm_pool:n,integrate:s}=this.sdk.sdkOptions,a=[e.coin_type_a,e.coin_type_b],c=[t.object((0,pe.getPackagerConfigs)(n).global_config_id),t.object(e.pool_id),t.object(e.pos_id),i,r];return t.moveCall({target:`${s.published_at}::${Cr}::collect_fee`,typeArguments:a,arguments:c}),t}async calculateAddLiquidityResultWithPrice(e){let{pool_id:t,slippage:i,refresh_pool_price:r,add_mode_params:n}=e,s=await this.sdk.Pool.getPool(t,r),a=Number(s.tick_spacing),c=0,p=0;if(n.is_full_range)c=pe.TickUtil.getMinIndex(a),p=pe.TickUtil.getMaxIndex(a);else{let{price_base_coin:W,min_price:j,max_price:K}=n;c=pe.TickMath.priceToInitializeTickIndex(W==="coin_a"?(0,pe.d)(j):(0,pe.d)(1).div(K),n.coin_decimals_a,n.coin_decimals_b,a),p=pe.TickMath.priceToInitializeTickIndex(W==="coin_a"?(0,pe.d)(K):(0,pe.d)(1).div(j),n.coin_decimals_a,n.coin_decimals_b,a)}if("liquidity"in e){let{liquidity:W}=e,j=pe.TickMath.tickIndexToSqrtPriceX64(c),K=pe.TickMath.tickIndexToSqrtPriceX64(p),{coin_amount_a:X,coin_amount_b:Q}=pe.ClmmPoolUtil.getCoinAmountFromLiquidity(new Ln.default(W),new Ln.default(s.current_sqrt_price),j,K,!1),se=(0,pe.d)(X).mul(1+i).toFixed(0,Ot.ROUND_UP),Y=(0,pe.d)(Q).mul(1+i).toFixed(0,Ot.ROUND_UP);return{coin_amount_a:X,coin_amount_b:Q,coin_amount_limit_a:se,coin_amount_limit_b:Y,liquidity:W,tick_lower:c,tick_upper:p}}let{coin_amount:g,fix_amount_a:v}=e,{coin_amount_limit_a:y,coin_amount_limit_b:A,liquidity_amount:k,coin_amount_a:U,coin_amount_b:P}=pe.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(c,p,new Ln.default(g),v,!0,i,new Ln.default(s.current_sqrt_price));return{coin_amount_a:U,coin_amount_b:P,coin_amount_limit_a:y,coin_amount_limit_b:A,liquidity:k,tick_lower:c,tick_upper:p,fix_amount_a:v}}async addLiquidityWithPricePayload(e,t,i,r){let{pool_id:n,calculate_result:s}=e,{coin_amount_limit_a:a,coin_amount_limit_b:c,liquidity:p,tick_lower:g,tick_upper:v}=s;t=t||new ki.Transaction;let y=await this.sdk.Pool.getPool(n,!1);return await this.createAddLiquidityPayload({delta_liquidity:p,max_amount_a:a,max_amount_b:c,tick_lower:g,tick_upper:v,collect_fee:!1,rewarder_coin_types:[],coin_type_a:y.coin_type_a,coin_type_b:y.coin_type_b,pool_id:n,pos_id:""},t,i,r),t}async createAddLiquidityFixCoinWithPricePayload(e,t,i,r){let{pool_id:n,calculate_result:s}=e,{coin_amount_limit_a:a,coin_amount_limit_b:c,liquidity:p,tick_lower:g,tick_upper:v,fix_amount_a:y,coin_amount_a:A,coin_amount_b:k}=s;if(y===void 0)throw tt("InvalidParams","fix_amount_a is undefined",{[pe.DETAILS_KEYS.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[pe.DETAILS_KEYS.REQUEST_PARAMS]:e});t=t||new ki.Transaction;let U=await this.sdk.Pool.getPool(n,!1);return await this.createAddLiquidityFixTokenPayload({amount_a:y?A:a,amount_b:y?c:k,slippage:0,fix_amount_a:y,is_open:!0,tick_lower:g,tick_upper:v,collect_fee:!1,rewarder_coin_types:[],coin_type_a:U.coin_type_a,coin_type_b:U.coin_type_b,pool_id:n,pos_id:""},void 0,t,i,r),t}createCollectFeeNoSendPayload(e,t,i,r){let{clmm_pool:n,integrate:s}=this.sdk.sdkOptions,a=[e.coin_type_a,e.coin_type_b],c=[t.object((0,pe.getPackagerConfigs)(n).global_config_id),t.object(e.pool_id),t.object(e.pos_id),i,r];return t.moveCall({target:`${s.published_at}::${Fl}::collect_fee`,typeArguments:a,arguments:c}),t}},gl=qi($i()),zp=class{constructor(e){this._sdk=e,this.growthGlobal=[lt.ZERO,lt.ZERO,lt.ZERO]}get sdk(){return this._sdk}async emissionsEveryDay(e){let t=(await this.sdk.Pool.getPool(e)).rewarder_infos;if(!t)return null;let i=[];for(let r of t){let n=lt.MathUtil.fromX64(new gl.default(r.emissions_per_second));i.push({emissions:Math.floor(n.toNumber()*60*60*24),coin_type:r.coin_type})}return i}async batchFetchPositionRewarders(e){let t=[];for(let r of e){let n=await this._sdk.Position.getPositionById(r,!1),s=await this._sdk.Pool.getPool(n.pool,!1);t.push({pool_id:s.id,position_id:n.pos_object_id,coin_type_a:s.coin_type_a,coin_type_b:s.coin_type_b,rewarder_types:s.rewarder_infos.map(a=>a.coin_type)})}let i={};if(t.length>0){let r=await this.fetchPosRewardersAmount(t);for(let n of r)i[n.position_id]=n.rewarder_amounts;return i}return i}async fetchPositionRewarders(e,t){let i={pool_id:e.id,position_id:t,coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b,rewarder_types:e.rewarder_infos.map(r=>r.coin_type)};return(await this.fetchPosRewardersAmount([i]))[0].rewarder_amounts}async batchFetchPositionFees(e){return await this._sdk.Position.batchFetchPositionFees(e)}async fetchPosFeeAmount(e){return await this._sdk.Position.fetchPosFeeAmount(e)}buildFetchPosReward(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions,n=[e.coin_type_a,e.coin_type_b],s=[t.object((0,lt.getPackagerConfigs)(i).global_config_id),t.object(e.pool_id),t.pure.address(e.position_id),t.object(lt.CLOCK_ADDRESS)];t.moveCall({target:`${r.published_at}::${Ir}::fetch_position_rewards`,arguments:s,typeArguments:n})}async fetchPosRewardersAmount(e){let t=new $n.Transaction;for(let s of e)this.buildFetchPosReward(s,t);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:t,sender:(0,Xl.normalizeSuiAddress)("0x")});i.error!=null&&tt("InvalidConfig",`fetch position rewards error code: ${i.error??"unknown error"}, please check config and params`,{[lt.DETAILS_KEYS.METHOD_NAME]:"fetchPosRewardersAmount",[lt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}});let r=this.parsedPosRewardData(i),n=[];for(let s=0;s<e.length;s+=1){let a=r[e[s].position_id];if(a){let c={pool_id:e[s].pool_id,position_id:e[s].position_id,rewarder_amounts:a.rewarder_amount.map((p,g)=>({amount_owned:p,coin_type:e[s].rewarder_types[g]}))};n.push(c)}}return n}parsedPosRewardData(e){let t={},i=e.events?.filter(r=>r.type.includes("fetcher_script::FetchPositionRewardsEvent"));for(let r=0;r<i.length;r+=1){let{parsedJson:n}=i[r],s={position_id:n.position_id,rewarder_amount:n.data};t[n.position_id]=s}return t}async fetchPoolRewardersAmount(e,t){let i=await this.sdk.Pool.getPool(t),r=await this.sdk.Position.getPositionList(e,[t]),n=[];for(let c of r)n.push({pool_id:i.id,position_id:c.pos_object_id,rewarder_types:i.rewarder_infos.map(p=>p.coin_type),coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b});let s=await this.fetchPosRewardersAmount(n),a=[lt.ZERO,lt.ZERO,lt.ZERO];if(s!=null)for(let c of s)for(let p=0;p<c.rewarder_amounts.length;p+=1)a[p]=a[p].add(new gl.default(c.rewarder_amounts[p].amount_owned));return a}async getPoolLowerAndUpperTicks(e,t){let i=[],r=[];for(let n of t){let s=await this.sdk.Pool.getTickDataByIndex(e,n.tick_lower_index),a=await this.sdk.Pool.getTickDataByIndex(e,n.tick_upper_index);i.push(s),r.push(a)}return[i,r]}async collectRewarderPayload(e){let t=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null),i=new $n.Transaction;return i=lr.createCollectRewarderAndFeeParams(this._sdk,i,e,t),i}async batchCollectRewardsPayload(e,t,i,r){let n=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null);t=t||new $n.Transaction;let s={};return e.forEach(a=>{let c=(0,lt.normalizeCoinType)(a.coin_type_a),p=(0,lt.normalizeCoinType)(a.coin_type_b);if(a.collect_fee){let v=s[c];v==null&&(i==null?v=lt.CoinAssist.buildCoinForAmount(t,n,BigInt(0),c,!1):v={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},s[c]=v);let y=s[p];y==null&&(r==null?y=lt.CoinAssist.buildCoinForAmount(t,n,BigInt(0),p,!1):y={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},s[p]=y),t=this._sdk.Position.createCollectFeeNoSendPayload({pool_id:a.pool_id,pos_id:a.pos_id,coin_type_a:a.coin_type_a,coin_type_b:a.coin_type_b},t,v.target_coin,y.target_coin)}let g=[];a.rewarder_coin_types.forEach(v=>{let y=(0,lt.normalizeCoinType)(v),A=s[v];A===void 0&&(A=lt.CoinAssist.buildCoinForAmount(t,n,BigInt(0),y,!1),s[y]=A),g.push(A.target_coin)}),t=this.createCollectRewarderNoSendPayload(a,t,g)}),Object.keys(s).forEach(a=>{let c=s[a];c.is_mint_zero_coin&&Vp(this.sdk,t,c.target_coin,a,this.sdk.getSenderAddress())}),t}createCollectRewarderPayload(e,t,i){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,s=(0,lt.getPackagerConfigs)(r),a=[e.coin_type_a,e.coin_type_b];return e.rewarder_coin_types.forEach((c,p)=>{t&&t.moveCall({target:`${n.published_at}::${Cr}::collect_reward`,typeArguments:[...a,c],arguments:[t.object(s.global_config_id),t.object(e.pool_id),t.object(e.pos_id),t.object(s.global_vault_id),i[p],t.object(lt.CLOCK_ADDRESS)]})}),t}createCollectRewarderNoSendPayload(e,t,i){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,s=(0,lt.getPackagerConfigs)(r),a=[e.coin_type_a,e.coin_type_b];return e.rewarder_coin_types.forEach((c,p)=>{t&&t.moveCall({target:`${n.published_at}::${Fl}::collect_reward`,typeArguments:[...a,c],arguments:[t.object(s.global_config_id),t.object(e.pool_id),t.object(e.pos_id),t.object(s.global_vault_id),i[p],t.object(lt.CLOCK_ADDRESS)]})}),t}},br=qi($i());var Xp=class{constructor(e){this.calculateSingleImpact=(t,i)=>i.minus(t).div(i).mul(100),this._sdk=e}get sdk(){return this._sdk}calculateSwapFee(e){let t=(0,Mt.d)(0);return e.forEach(i=>{let r=i.base_paths.length;if(r>0){let n=i.base_paths[0],s=n.label==="Cetus"?new Ot(n.fee_rate).div(10**6):new Ot(n.fee_rate).div(10**9),a=(0,Mt.d)(n.input_amount).div(10**n.from_decimal).mul(s);if(t=t.add(a),r>1){let c=i.base_paths[1],p=n.direction?n.current_price:new Ot(1).div(n.current_price),g=c.direction?c.current_price:new Ot(1).div(c.current_price),v=c.label==="Cetus"?new Ot(c.fee_rate).div(10**6):new Ot(c.fee_rate).div(10**9),y=(0,Mt.d)(c.output_amount).div(10**c.to_decimal).mul(v).div(p.mul(g));t=t.add(y)}}}),t.toString()}calculateSwapPriceImpact(e){let t=(0,Mt.d)(0);return e.forEach(i=>{let r=i.base_paths.length;if(r===1){let n=i.base_paths[0],s=(0,Mt.d)(n.output_amount).div(10**n.to_decimal),a=(0,Mt.d)(n.input_amount).div(10**n.from_decimal),c=s.div(a),p=n.direction?new Ot(n.current_price):new Ot(1).div(n.current_price);t=t.add(this.calculateSingleImpact(c,p))}if(r===2){let n=i.base_paths[0],s=i.base_paths[1],a=n.direction?new Ot(n.current_price):new Ot(1).div(n.current_price),c=s.direction?new Ot(s.current_price):new Ot(1).div(s.current_price),p=a.mul(c),g=new Ot(s.output_amount).div(10**s.to_decimal),v=new Ot(n.input_amount).div(10**n.from_decimal),y=g.div(v);t=t.add(this.calculateSingleImpact(y,p))}}),t.toString()}async preSwapWithMultiPool(e){let{integrate:t}=this.sdk.sdkOptions,i=new us.Transaction,r=[e.coin_type_a,e.coin_type_b];for(let p=0;p<e.pool_ids.length;p+=1){let g=[i.object(e.pool_ids[p]),i.pure.bool(e.a2b),i.pure.bool(e.by_amount_in),i.pure.u64(e.amount)];i.moveCall({target:`${t.published_at}::${Ir}::calculate_swap_result`,arguments:g,typeArguments:r})}let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,cs.normalizeSuiAddress)("0x0")});n.error!=null&&tt("InvalidConfig",`pre swap with multi pools error code: ${n.error??"unknown error"}, please check config and params`,{[Mt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[Mt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}});let s=n.events?.filter(p=>(0,Mt.extractStructTagFromType)(p.type).name==="CalculatedSwapResultEvent");if(s.length===0)return null;s.length!==e.pool_ids.length&&tt("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[Mt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[Mt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}});let a=e.by_amount_in?Mt.ZERO:Mt.U64_MAX,c=0;for(let p=0;p<s.length;p+=1)if(!s[p].parsedJson.data.is_exceed)if(e.by_amount_in){let g=new br.default(s[p].parsedJson.data.amount_out);g.gt(a)&&(c=p,a=g)}else{let g=new br.default(s[p].parsedJson.data.amount_out);g.lt(a)&&(c=p,a=g)}return this.transformSwapWithMultiPoolData({pool_address:e.pool_ids[c],a2b:e.a2b,by_amount_in:e.by_amount_in,amount:e.amount,coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b},s[c].parsedJson)}async preSwap(e){let{integrate:t}=this.sdk.sdkOptions,i=new us.Transaction,r=[e.coin_type_a,e.coin_type_b],n=[i.object(e.pool.id),i.pure.bool(e.a2b),i.pure.bool(e.by_amount_in),i.pure.u64(e.amount)];i.moveCall({target:`${t.published_at}::${Ir}::calculate_swap_result`,arguments:n,typeArguments:r});let s=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,cs.normalizeSuiAddress)("0x0")});if(s.error!=null)return tt("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Mt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[Mt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}});let a=s.events?.filter(c=>(0,Mt.extractStructTagFromType)(c.type).name==="CalculatedSwapResultEvent");return a.length===0?tt("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Mt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[Mt.DETAILS_KEYS.REQUEST_PARAMS]:{params:e}}):this.transformSwapData(e,a[0].parsedJson.data)}transformSwapData(e,t){let i=t.amount_in&&t.fee_amount?new br.default(t.amount_in).add(new br.default(t.fee_amount)).toString():"";return{pool_address:e.pool.id,current_sqrt_price:e.current_sqrt_price,estimated_amount_in:i,estimated_amount_out:t.amount_out,estimated_end_sqrt_price:t.after_sqrt_price,estimated_fee_amount:t.fee_amount,is_exceed:t.is_exceed,amount:e.amount,a2b:e.a2b,by_amount_in:e.by_amount_in}}transformSwapWithMultiPoolData(e,t){let{data:i}=t;console.log("json data. ",i);let r=i.amount_in&&i.fee_amount?new br.default(i.amount_in).add(new br.default(i.fee_amount)).toString():"";return{pool_address:e.pool_address,estimated_amount_in:r,estimated_amount_out:i.amount_out,estimated_end_sqrt_price:i.after_sqrt_price,estimated_start_sqrt_price:i.step_results[0].current_sqrt_price,estimated_fee_amount:i.fee_amount,is_exceed:i.is_exceed,amount:e.amount,a2b:e.a2b,by_amount_in:e.by_amount_in}}calculateRates(e){let{current_pool:t}=e,i=Bp(t),r;e.a2b?r=e.swap_ticks.sort((y,A)=>A.index-y.index):r=e.swap_ticks.sort((y,A)=>y.index-A.index);let n=jp(e.a2b,e.by_amount_in,e.amount,i,r),s=!1;e.by_amount_in?s=n.amount_in.lt(e.amount):s=n.amount_out.lt(e.amount);let a=Mr.getDefaultSqrtPriceLimit(e.a2b);e.a2b&&n.next_sqrt_price.lt(a)&&(s=!0),!e.a2b&&n.next_sqrt_price.gt(a)&&(s=!0);let c=0;n.cross_tick_num>6&&n.cross_tick_num<40&&(c=22e3*(n.cross_tick_num-6)),n.cross_tick_num>40&&(s=!0);let p=Mt.TickMath.sqrtPriceX64ToPrice(i.current_sqrt_price,e.decimals_a,e.decimals_b).toNumber(),g=Mt.TickMath.sqrtPriceX64ToPrice(n.next_sqrt_price,e.decimals_a,e.decimals_b).toNumber(),v=Math.abs(p-g)/p*100;return{estimated_amount_in:n.amount_in,estimated_amount_out:n.amount_out,estimated_end_sqrt_price:n.next_sqrt_price,estimated_fee_amount:n.fee_amount,is_exceed:s,extra_compute_limit:c,amount:e.amount,a2b:e.a2b,by_amount_in:e.by_amount_in,price_impact_pct:v}}async createSwapPayload(e,t){let i=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(t){let{is_adjust_coin_a:r,is_adjust_coin_b:n}=Kn(e);if(e.a2b&&r||!e.a2b&&n)return await Mr.buildSwapTransactionForGas(this._sdk,e,i,t)}return Mr.buildSwapTransaction(this.sdk,e,i)}async createSwapWithoutTransferCoinsPayload(e,t){let i=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(t){let{is_adjust_coin_a:r,is_adjust_coin_b:n}=Kn(e);if(e.a2b&&r||!e.a2b&&n)return await Mr.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,e,i,t)}return Mr.buildSwapTransactionWithoutTransferCoins(this.sdk,e,i)}},Jp=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}async getClmmVestInfoList(){let{clmm_vest:e}=this._sdk.sdkOptions;if(e===void 0)return tt("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[qt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo"});let t=[];try{let i=`${e.package_id}::clmm_vester::CreateEvent`,r=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:i})).data.map(n=>n.parsedJson.clmm_vester_id);return r.length>0&&(await this._sdk.FullClient.batchGetObjects(r,{showContent:!0,showType:!0})).forEach(n=>{let s=Er.parseClmmVestInfo(n),a=`${s.id}-ClmmVestInfo`;this._sdk.updateCache(a,s),t.push(s)}),t}catch(i){ji("ClmmVestFetchError",i,{[qt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(e=!0){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return tt("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[qt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:i}=(0,qt.getPackagerConfigs)(t),r=`${i}-ClmmVestInfo`,n=this._sdk.getCache(r,e);if(n)return n;try{let s=await this._sdk.FullClient.getObject({id:i,options:{showContent:!0,showType:!0}}),a=Er.parseClmmVestInfo(s);return this._sdk.updateCache(r,a),a}catch(s){return ji("ClmmVestFetchError",s,{[qt.DETAILS_KEYS.METHOD_NAME]:"getClmmVestInfo",[qt.DETAILS_KEYS.REQUEST_PARAMS]:{clmm_vest_id:i}})}}async getPositionVesting(e){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return tt("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[qt.DETAILS_KEYS.METHOD_NAME]:"getPositionVesting"});if(e.length===0)return[];let{clmm_vest_id:i}=(0,qt.getPackagerConfigs)(t),r=new ds.Transaction;e.forEach(a=>{let{clmm_pool_id:c,coin_type_a:p,coin_type_b:g,clmm_position_ids:v}=a;r.moveCall({package:t.published_at,module:"clmm_vester",function:"get_positions_vesting",typeArguments:[p,g],arguments:[r.object(i),r.object(c),r.pure.vector("id",v)]})});let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:(0,Jl.normalizeSuiAddress)("0x0")}),s=[];return n.events?.forEach(a=>{if(a.type.includes("clmm_vester::GetPositionsVestingEvent")){let{parsedJson:c}=a;s.push(...c.position_vestings.map(p=>Er.parsePositionVesting(p)))}}),s}buildRedeemPayload(e,t){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return tt("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[qt.DETAILS_KEYS.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:r,clmm_vest_id:n,cetus_coin_type:s}=(0,qt.getPackagerConfigs)(i);return t=t||new ds.Transaction,e.forEach(a=>{let{clmm_pool_id:c,clmm_position_id:p,coin_type_a:g,coin_type_b:v,period:y}=a,A=t.moveCall({package:i.published_at,module:"clmm_vester",function:"redeem",arguments:[t.object(r),t.object(n),t.object(c),typeof p=="string"?t.object(p):p,t.pure.u16(y),t.object(qt.CLOCK_ADDRESS)],typeArguments:[g,v]}),k=qt.CoinAssist.fromBalance(A,s,t);t.transferObjects([k],this._sdk.getSenderAddress())}),t}},_l={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"}},Yp={env:"mainnet",full_rpc_url:Yl.FullRpcUrlMainnet,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:_l.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0x75b2e9ecad34944b8d0c874e568c90db0cf9437f0d7392abfd4cb902972f3e40",version:12,config:_l.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"}}},Qp={env:"testnet",full_rpc_url:Ql.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"}}},eu=class Hn extends wl.SdkWrapper{constructor(t){super(t),this._swap=new Xp(this),this._pool=new Kp(this),this._position=new Wp(this),this._config=new Rf(this),this._rewarder=new zp(this),this._vest=new Jp(this)}get Pool(){return this._pool}get Position(){return this._position}get CetusConfig(){return this._config}get Rewarder(){return this._rewarder}get Swap(){return this._swap}get Vest(){return this._vest}static createSDK(t){let{env:i="mainnet"}=t;return i==="mainnet"?Hn.createCustomSDK({...Yp,...t}):Hn.createCustomSDK({...Qp,...t})}static createCustomSDK(t){return new Hn(t)}},Yn=qi($i()),h1=new Yn.default(365),f1=new Yn.default(24),p1=new Yn.default(3600),m1=new Yn.default(.5);var ou=require("@pythnetwork/pyth-sui-js"),Hr=class e extends iu.SdkWrapper{constructor(t,i){super(t),this._suilendModule=new Yr(this),this._leverageModules=new ln(this),this._aggregatorClient=new $r.AggregatorClient({signer:(0,ru.normalizeSuiAddress)("0x0"),client:t.sui_client||new nu.SuiClient({url:t.full_rpc_url}),env:t.env==="testnet"?$r.Env.Testnet:$r.Env.Mainnet,pythUrls:t.pyth_urls}),this._clmmSDK=i||eu.createSDK({env:t.env,full_rpc_url:t.full_rpc_url}),this._pythConnection=new ou.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(t){return e.createCustomSDK({...Qn,...t})}static createCustomSDK(t){return new e(t)}};var em=Hr;0&&(module.exports={CetusLeverageSDK,leverage_mainnet});
|
|
1
|
+
"use strict";var kr=Object.create;var bt=Object.defineProperty;var Ar=Object.getOwnPropertyDescriptor;var Sr=Object.getOwnPropertyNames;var Cr=Object.getPrototypeOf,Pr=Object.prototype.hasOwnProperty;var xr=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports),Lr=(i,r)=>{for(var n in r)bt(i,n,{get:r[n],enumerable:!0})},Bi=(i,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of Sr(r))!Pr.call(i,t)&&t!==n&&bt(i,t,{get:()=>r[t],enumerable:!(s=Ar(r,t))||s.enumerable});return i};var ri=(i,r,n)=>(n=i!=null?kr(Cr(i)):{},Bi(r||!i||!i.__esModule?bt(n,"default",{value:i,enumerable:!0}):n,i)),Ir=i=>Bi(bt({},"__esModule",{value:!0}),i);var pr=xr((dr,vi)=>{"use strict";(function(i,r){"use strict";function n(c,e){if(!c)throw new Error(e||"Assertion failed")}function s(c,e){c.super_=e;var o=function(){};o.prototype=e.prototype,c.prototype=new o,c.prototype.constructor=c}function t(c,e,o){if(t.isBN(c))return c;this.negative=0,this.words=null,this.length=0,this.red=null,c!==null&&((e==="le"||e==="be")&&(o=e,e=10),this._init(c||0,e||10,o||"be"))}typeof i=="object"?i.exports=t:r.BN=t,t.BN=t,t.wordSize=26;var f;try{typeof window<"u"&&typeof window.Buffer<"u"?f=window.Buffer:f=require("buffer").Buffer}catch{}t.isBN=function(e){return e instanceof t?!0:e!==null&&typeof e=="object"&&e.constructor.wordSize===t.wordSize&&Array.isArray(e.words)},t.max=function(e,o){return e.cmp(o)>0?e:o},t.min=function(e,o){return e.cmp(o)<0?e:o},t.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),n(o===(o|0)&&o>=2&&o<=36),e=e.toString().replace(/\s+/g,"");var u=0;e[0]==="-"&&(u++,this.negative=1),u<e.length&&(o===16?this._parseHex(e,u,l):(this._parseBase(e,o,u),l==="le"&&this._initArray(this.toArray(),o,l)))},t.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):(n(e<9007199254740992),this.words=[e&67108863,e/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),o,l)},t.prototype._initArray=function(e,o,l){if(n(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 u=0;u<this.length;u++)this.words[u]=0;var h,g,k=0;if(l==="be")for(u=e.length-1,h=0;u>=0;u-=3)g=e[u]|e[u-1]<<8|e[u-2]<<16,this.words[h]|=g<<k&67108863,this.words[h+1]=g>>>26-k&67108863,k+=24,k>=26&&(k-=26,h++);else if(l==="le")for(u=0,h=0;u<e.length;u+=3)g=e[u]|e[u+1]<<8|e[u+2]<<16,this.words[h]|=g<<k&67108863,this.words[h+1]=g>>>26-k&67108863,k+=24,k>=26&&(k-=26,h++);return this._strip()};function d(c,e){var o=c.charCodeAt(e);if(o>=48&&o<=57)return o-48;if(o>=65&&o<=70)return o-55;if(o>=97&&o<=102)return o-87;n(!1,"Invalid character in "+c)}function v(c,e,o){var l=d(c,o);return o-1>=e&&(l|=d(c,o-1)<<4),l}t.prototype._parseHex=function(e,o,l){this.length=Math.ceil((e.length-o)/6),this.words=new Array(this.length);for(var u=0;u<this.length;u++)this.words[u]=0;var h=0,g=0,k;if(l==="be")for(u=e.length-1;u>=o;u-=2)k=v(e,o,u)<<h,this.words[g]|=k&67108863,h>=18?(h-=18,g+=1,this.words[g]|=k>>>26):h+=8;else{var p=e.length-o;for(u=p%2===0?o+1:o;u<e.length;u+=2)k=v(e,o,u)<<h,this.words[g]|=k&67108863,h>=18?(h-=18,g+=1,this.words[g]|=k>>>26):h+=8}this._strip()};function M(c,e,o,l){for(var u=0,h=0,g=Math.min(c.length,o),k=e;k<g;k++){var p=c.charCodeAt(k)-48;u*=l,p>=49?h=p-49+10:p>=17?h=p-17+10:h=p,n(p>=0&&h<l,"Invalid character"),u+=h}return u}t.prototype._parseBase=function(e,o,l){this.words=[0],this.length=1;for(var u=0,h=1;h<=67108863;h*=o)u++;u--,h=h/o|0;for(var g=e.length-l,k=g%u,p=Math.min(g,g-k)+l,a=0,y=l;y<p;y+=u)a=M(e,y,y+u,o),this.imuln(h),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(k!==0){var E=1;for(a=M(e,y,e.length,o),y=0;y<k;y++)E*=o;this.imuln(E),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this._strip()},t.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 w(c,e){c.words=e.words,c.length=e.length,c.negative=e.negative,c.red=e.red}if(t.prototype._move=function(e){w(e,this)},t.prototype.clone=function(){var e=new t(null);return this.copy(e),e},t.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},t.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},t.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{t.prototype[Symbol.for("nodejs.util.inspect.custom")]=A}catch{t.prototype.inspect=A}else t.prototype.inspect=A;function A(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var x=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],C=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],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];t.prototype.toString=function(e,o){e=e||10,o=o|0||1;var l;if(e===16||e==="hex"){l="";for(var u=0,h=0,g=0;g<this.length;g++){var k=this.words[g],p=((k<<u|h)&16777215).toString(16);h=k>>>24-u&16777215,u+=2,u>=26&&(u-=26,g--),h!==0||g!==this.length-1?l=x[6-p.length]+p+l:l=p+l}for(h!==0&&(l=h.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 a=C[e],y=L[e];l="";var E=this.clone();for(E.negative=0;!E.isZero();){var R=E.modrn(y).toString(e);E=E.idivn(y),E.isZero()?l=R+l:l=x[a-R.length]+R+l}for(this.isZero()&&(l="0"+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}n(!1,"Base should be between 2 and 36")},t.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&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-e:e},t.prototype.toJSON=function(){return this.toString(16,2)},f&&(t.prototype.toBuffer=function(e,o){return this.toArrayLike(f,e,o)}),t.prototype.toArray=function(e,o){return this.toArrayLike(Array,e,o)};var B=function(e,o){return e.allocUnsafe?e.allocUnsafe(o):new e(o)};t.prototype.toArrayLike=function(e,o,l){this._strip();var u=this.byteLength(),h=l||Math.max(1,u);n(u<=h,"byte array longer than desired length"),n(h>0,"Requested array length <= 0");var g=B(e,h),k=o==="le"?"LE":"BE";return this["_toArrayLike"+k](g,u),g},t.prototype._toArrayLikeLE=function(e,o){for(var l=0,u=0,h=0,g=0;h<this.length;h++){var k=this.words[h]<<g|u;e[l++]=k&255,l<e.length&&(e[l++]=k>>8&255),l<e.length&&(e[l++]=k>>16&255),g===6?(l<e.length&&(e[l++]=k>>24&255),u=0,g=0):(u=k>>>24,g+=2)}if(l<e.length)for(e[l++]=u;l<e.length;)e[l++]=0},t.prototype._toArrayLikeBE=function(e,o){for(var l=e.length-1,u=0,h=0,g=0;h<this.length;h++){var k=this.words[h]<<g|u;e[l--]=k&255,l>=0&&(e[l--]=k>>8&255),l>=0&&(e[l--]=k>>16&255),g===6?(l>=0&&(e[l--]=k>>24&255),u=0,g=0):(u=k>>>24,g+=2)}if(l>=0)for(e[l--]=u;l>=0;)e[l--]=0},Math.clz32?t.prototype._countBits=function(e){return 32-Math.clz32(e)}:t.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},t.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},t.prototype.bitLength=function(){var e=this.words[this.length-1],o=this._countBits(e);return(this.length-1)*26+o};function D(c){for(var e=new Array(c.bitLength()),o=0;o<e.length;o++){var l=o/26|0,u=o%26;e[o]=c.words[l]>>>u&1}return e}t.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},t.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},t.prototype.toTwos=function(e){return this.negative!==0?this.abs().inotn(e).iaddn(1):this.clone()},t.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},t.prototype.isNeg=function(){return this.negative!==0},t.prototype.neg=function(){return this.clone().ineg()},t.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},t.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()},t.prototype.ior=function(e){return n((this.negative|e.negative)===0),this.iuor(e)},t.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},t.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},t.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()},t.prototype.iand=function(e){return n((this.negative|e.negative)===0),this.iuand(e)},t.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},t.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},t.prototype.iuxor=function(e){var o,l;this.length>e.length?(o=this,l=e):(o=e,l=this);for(var u=0;u<l.length;u++)this.words[u]=o.words[u]^l.words[u];if(this!==o)for(;u<o.length;u++)this.words[u]=o.words[u];return this.length=o.length,this._strip()},t.prototype.ixor=function(e){return n((this.negative|e.negative)===0),this.iuxor(e)},t.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},t.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},t.prototype.inotn=function(e){n(typeof e=="number"&&e>=0);var o=Math.ceil(e/26)|0,l=e%26;this._expand(o),l>0&&o--;for(var u=0;u<o;u++)this.words[u]=~this.words[u]&67108863;return l>0&&(this.words[u]=~this.words[u]&67108863>>26-l),this._strip()},t.prototype.notn=function(e){return this.clone().inotn(e)},t.prototype.setn=function(e,o){n(typeof e=="number"&&e>=0);var l=e/26|0,u=e%26;return this._expand(l+1),o?this.words[l]=this.words[l]|1<<u:this.words[l]=this.words[l]&~(1<<u),this._strip()},t.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,u;this.length>e.length?(l=this,u=e):(l=e,u=this);for(var h=0,g=0;g<u.length;g++)o=(l.words[g]|0)+(u.words[g]|0)+h,this.words[g]=o&67108863,h=o>>>26;for(;h!==0&&g<l.length;g++)o=(l.words[g]|0)+h,this.words[g]=o&67108863,h=o>>>26;if(this.length=l.length,h!==0)this.words[this.length]=h,this.length++;else if(l!==this)for(;g<l.length;g++)this.words[g]=l.words[g];return this},t.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)},t.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 u,h;l>0?(u=this,h=e):(u=e,h=this);for(var g=0,k=0;k<h.length;k++)o=(u.words[k]|0)-(h.words[k]|0)+g,g=o>>26,this.words[k]=o&67108863;for(;g!==0&&k<u.length;k++)o=(u.words[k]|0)+g,g=o>>26,this.words[k]=o&67108863;if(g===0&&k<u.length&&u!==this)for(;k<u.length;k++)this.words[k]=u.words[k];return this.length=Math.max(this.length,k),u!==this&&(this.negative=1),this._strip()},t.prototype.sub=function(e){return this.clone().isub(e)};function Z(c,e,o){o.negative=e.negative^c.negative;var l=c.length+e.length|0;o.length=l,l=l-1|0;var u=c.words[0]|0,h=e.words[0]|0,g=u*h,k=g&67108863,p=g/67108864|0;o.words[0]=k;for(var a=1;a<l;a++){for(var y=p>>>26,E=p&67108863,R=Math.min(a,e.length-1),T=Math.max(0,a-c.length+1);T<=R;T++){var U=a-T|0;u=c.words[U]|0,h=e.words[T]|0,g=u*h+E,y+=g/67108864|0,E=g&67108863}o.words[a]=E|0,p=y|0}return p!==0?o.words[a]=p|0:o.length--,o._strip()}var j=function(e,o,l){var u=e.words,h=o.words,g=l.words,k=0,p,a,y,E=u[0]|0,R=E&8191,T=E>>>13,U=u[1]|0,V=U&8191,J=U>>>13,He=u[2]|0,Q=He&8191,te=He>>>13,ze=u[3]|0,Y=ze&8191,W=ze>>>13,bi=u[4]|0,oe=bi&8191,se=bi>>>13,_i=u[5]|0,ae=_i&8191,le=_i>>>13,ki=u[6]|0,fe=ki&8191,ue=ki>>>13,Ai=u[7]|0,he=Ai&8191,ce=Ai>>>13,Si=u[8]|0,de=Si&8191,pe=Si>>>13,Ci=u[9]|0,ge=Ci&8191,me=Ci>>>13,Pi=h[0]|0,ve=Pi&8191,we=Pi>>>13,xi=h[1]|0,Me=xi&8191,ye=xi>>>13,Li=h[2]|0,be=Li&8191,_e=Li>>>13,Ii=h[3]|0,ke=Ii&8191,Ae=Ii>>>13,Oi=h[4]|0,Se=Oi&8191,Ce=Oi>>>13,Ni=h[5]|0,Pe=Ni&8191,xe=Ni>>>13,Ri=h[6]|0,Le=Ri&8191,Ie=Ri>>>13,Ti=h[7]|0,Oe=Ti&8191,Ne=Ti>>>13,Di=h[8]|0,Re=Di&8191,Te=Di>>>13,Ei=h[9]|0,De=Ei&8191,Ee=Ei>>>13;l.negative=e.negative^o.negative,l.length=19,p=Math.imul(R,ve),a=Math.imul(R,we),a=a+Math.imul(T,ve)|0,y=Math.imul(T,we);var Ft=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ft>>>26)|0,Ft&=67108863,p=Math.imul(V,ve),a=Math.imul(V,we),a=a+Math.imul(J,ve)|0,y=Math.imul(J,we),p=p+Math.imul(R,Me)|0,a=a+Math.imul(R,ye)|0,a=a+Math.imul(T,Me)|0,y=y+Math.imul(T,ye)|0;var qt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(qt>>>26)|0,qt&=67108863,p=Math.imul(Q,ve),a=Math.imul(Q,we),a=a+Math.imul(te,ve)|0,y=Math.imul(te,we),p=p+Math.imul(V,Me)|0,a=a+Math.imul(V,ye)|0,a=a+Math.imul(J,Me)|0,y=y+Math.imul(J,ye)|0,p=p+Math.imul(R,be)|0,a=a+Math.imul(R,_e)|0,a=a+Math.imul(T,be)|0,y=y+Math.imul(T,_e)|0;var Ut=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,p=Math.imul(Y,ve),a=Math.imul(Y,we),a=a+Math.imul(W,ve)|0,y=Math.imul(W,we),p=p+Math.imul(Q,Me)|0,a=a+Math.imul(Q,ye)|0,a=a+Math.imul(te,Me)|0,y=y+Math.imul(te,ye)|0,p=p+Math.imul(V,be)|0,a=a+Math.imul(V,_e)|0,a=a+Math.imul(J,be)|0,y=y+Math.imul(J,_e)|0,p=p+Math.imul(R,ke)|0,a=a+Math.imul(R,Ae)|0,a=a+Math.imul(T,ke)|0,y=y+Math.imul(T,Ae)|0;var Zt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,p=Math.imul(oe,ve),a=Math.imul(oe,we),a=a+Math.imul(se,ve)|0,y=Math.imul(se,we),p=p+Math.imul(Y,Me)|0,a=a+Math.imul(Y,ye)|0,a=a+Math.imul(W,Me)|0,y=y+Math.imul(W,ye)|0,p=p+Math.imul(Q,be)|0,a=a+Math.imul(Q,_e)|0,a=a+Math.imul(te,be)|0,y=y+Math.imul(te,_e)|0,p=p+Math.imul(V,ke)|0,a=a+Math.imul(V,Ae)|0,a=a+Math.imul(J,ke)|0,y=y+Math.imul(J,Ae)|0,p=p+Math.imul(R,Se)|0,a=a+Math.imul(R,Ce)|0,a=a+Math.imul(T,Se)|0,y=y+Math.imul(T,Ce)|0;var jt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(jt>>>26)|0,jt&=67108863,p=Math.imul(ae,ve),a=Math.imul(ae,we),a=a+Math.imul(le,ve)|0,y=Math.imul(le,we),p=p+Math.imul(oe,Me)|0,a=a+Math.imul(oe,ye)|0,a=a+Math.imul(se,Me)|0,y=y+Math.imul(se,ye)|0,p=p+Math.imul(Y,be)|0,a=a+Math.imul(Y,_e)|0,a=a+Math.imul(W,be)|0,y=y+Math.imul(W,_e)|0,p=p+Math.imul(Q,ke)|0,a=a+Math.imul(Q,Ae)|0,a=a+Math.imul(te,ke)|0,y=y+Math.imul(te,Ae)|0,p=p+Math.imul(V,Se)|0,a=a+Math.imul(V,Ce)|0,a=a+Math.imul(J,Se)|0,y=y+Math.imul(J,Ce)|0,p=p+Math.imul(R,Pe)|0,a=a+Math.imul(R,xe)|0,a=a+Math.imul(T,Pe)|0,y=y+Math.imul(T,xe)|0;var zt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(zt>>>26)|0,zt&=67108863,p=Math.imul(fe,ve),a=Math.imul(fe,we),a=a+Math.imul(ue,ve)|0,y=Math.imul(ue,we),p=p+Math.imul(ae,Me)|0,a=a+Math.imul(ae,ye)|0,a=a+Math.imul(le,Me)|0,y=y+Math.imul(le,ye)|0,p=p+Math.imul(oe,be)|0,a=a+Math.imul(oe,_e)|0,a=a+Math.imul(se,be)|0,y=y+Math.imul(se,_e)|0,p=p+Math.imul(Y,ke)|0,a=a+Math.imul(Y,Ae)|0,a=a+Math.imul(W,ke)|0,y=y+Math.imul(W,Ae)|0,p=p+Math.imul(Q,Se)|0,a=a+Math.imul(Q,Ce)|0,a=a+Math.imul(te,Se)|0,y=y+Math.imul(te,Ce)|0,p=p+Math.imul(V,Pe)|0,a=a+Math.imul(V,xe)|0,a=a+Math.imul(J,Pe)|0,y=y+Math.imul(J,xe)|0,p=p+Math.imul(R,Le)|0,a=a+Math.imul(R,Ie)|0,a=a+Math.imul(T,Le)|0,y=y+Math.imul(T,Ie)|0;var $t=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+($t>>>26)|0,$t&=67108863,p=Math.imul(he,ve),a=Math.imul(he,we),a=a+Math.imul(ce,ve)|0,y=Math.imul(ce,we),p=p+Math.imul(fe,Me)|0,a=a+Math.imul(fe,ye)|0,a=a+Math.imul(ue,Me)|0,y=y+Math.imul(ue,ye)|0,p=p+Math.imul(ae,be)|0,a=a+Math.imul(ae,_e)|0,a=a+Math.imul(le,be)|0,y=y+Math.imul(le,_e)|0,p=p+Math.imul(oe,ke)|0,a=a+Math.imul(oe,Ae)|0,a=a+Math.imul(se,ke)|0,y=y+Math.imul(se,Ae)|0,p=p+Math.imul(Y,Se)|0,a=a+Math.imul(Y,Ce)|0,a=a+Math.imul(W,Se)|0,y=y+Math.imul(W,Ce)|0,p=p+Math.imul(Q,Pe)|0,a=a+Math.imul(Q,xe)|0,a=a+Math.imul(te,Pe)|0,y=y+Math.imul(te,xe)|0,p=p+Math.imul(V,Le)|0,a=a+Math.imul(V,Ie)|0,a=a+Math.imul(J,Le)|0,y=y+Math.imul(J,Ie)|0,p=p+Math.imul(R,Oe)|0,a=a+Math.imul(R,Ne)|0,a=a+Math.imul(T,Oe)|0,y=y+Math.imul(T,Ne)|0;var Kt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,p=Math.imul(de,ve),a=Math.imul(de,we),a=a+Math.imul(pe,ve)|0,y=Math.imul(pe,we),p=p+Math.imul(he,Me)|0,a=a+Math.imul(he,ye)|0,a=a+Math.imul(ce,Me)|0,y=y+Math.imul(ce,ye)|0,p=p+Math.imul(fe,be)|0,a=a+Math.imul(fe,_e)|0,a=a+Math.imul(ue,be)|0,y=y+Math.imul(ue,_e)|0,p=p+Math.imul(ae,ke)|0,a=a+Math.imul(ae,Ae)|0,a=a+Math.imul(le,ke)|0,y=y+Math.imul(le,Ae)|0,p=p+Math.imul(oe,Se)|0,a=a+Math.imul(oe,Ce)|0,a=a+Math.imul(se,Se)|0,y=y+Math.imul(se,Ce)|0,p=p+Math.imul(Y,Pe)|0,a=a+Math.imul(Y,xe)|0,a=a+Math.imul(W,Pe)|0,y=y+Math.imul(W,xe)|0,p=p+Math.imul(Q,Le)|0,a=a+Math.imul(Q,Ie)|0,a=a+Math.imul(te,Le)|0,y=y+Math.imul(te,Ie)|0,p=p+Math.imul(V,Oe)|0,a=a+Math.imul(V,Ne)|0,a=a+Math.imul(J,Oe)|0,y=y+Math.imul(J,Ne)|0,p=p+Math.imul(R,Re)|0,a=a+Math.imul(R,Te)|0,a=a+Math.imul(T,Re)|0,y=y+Math.imul(T,Te)|0;var Ht=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,p=Math.imul(ge,ve),a=Math.imul(ge,we),a=a+Math.imul(me,ve)|0,y=Math.imul(me,we),p=p+Math.imul(de,Me)|0,a=a+Math.imul(de,ye)|0,a=a+Math.imul(pe,Me)|0,y=y+Math.imul(pe,ye)|0,p=p+Math.imul(he,be)|0,a=a+Math.imul(he,_e)|0,a=a+Math.imul(ce,be)|0,y=y+Math.imul(ce,_e)|0,p=p+Math.imul(fe,ke)|0,a=a+Math.imul(fe,Ae)|0,a=a+Math.imul(ue,ke)|0,y=y+Math.imul(ue,Ae)|0,p=p+Math.imul(ae,Se)|0,a=a+Math.imul(ae,Ce)|0,a=a+Math.imul(le,Se)|0,y=y+Math.imul(le,Ce)|0,p=p+Math.imul(oe,Pe)|0,a=a+Math.imul(oe,xe)|0,a=a+Math.imul(se,Pe)|0,y=y+Math.imul(se,xe)|0,p=p+Math.imul(Y,Le)|0,a=a+Math.imul(Y,Ie)|0,a=a+Math.imul(W,Le)|0,y=y+Math.imul(W,Ie)|0,p=p+Math.imul(Q,Oe)|0,a=a+Math.imul(Q,Ne)|0,a=a+Math.imul(te,Oe)|0,y=y+Math.imul(te,Ne)|0,p=p+Math.imul(V,Re)|0,a=a+Math.imul(V,Te)|0,a=a+Math.imul(J,Re)|0,y=y+Math.imul(J,Te)|0,p=p+Math.imul(R,De)|0,a=a+Math.imul(R,Ee)|0,a=a+Math.imul(T,De)|0,y=y+Math.imul(T,Ee)|0;var Wt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,p=Math.imul(ge,Me),a=Math.imul(ge,ye),a=a+Math.imul(me,Me)|0,y=Math.imul(me,ye),p=p+Math.imul(de,be)|0,a=a+Math.imul(de,_e)|0,a=a+Math.imul(pe,be)|0,y=y+Math.imul(pe,_e)|0,p=p+Math.imul(he,ke)|0,a=a+Math.imul(he,Ae)|0,a=a+Math.imul(ce,ke)|0,y=y+Math.imul(ce,Ae)|0,p=p+Math.imul(fe,Se)|0,a=a+Math.imul(fe,Ce)|0,a=a+Math.imul(ue,Se)|0,y=y+Math.imul(ue,Ce)|0,p=p+Math.imul(ae,Pe)|0,a=a+Math.imul(ae,xe)|0,a=a+Math.imul(le,Pe)|0,y=y+Math.imul(le,xe)|0,p=p+Math.imul(oe,Le)|0,a=a+Math.imul(oe,Ie)|0,a=a+Math.imul(se,Le)|0,y=y+Math.imul(se,Ie)|0,p=p+Math.imul(Y,Oe)|0,a=a+Math.imul(Y,Ne)|0,a=a+Math.imul(W,Oe)|0,y=y+Math.imul(W,Ne)|0,p=p+Math.imul(Q,Re)|0,a=a+Math.imul(Q,Te)|0,a=a+Math.imul(te,Re)|0,y=y+Math.imul(te,Te)|0,p=p+Math.imul(V,De)|0,a=a+Math.imul(V,Ee)|0,a=a+Math.imul(J,De)|0,y=y+Math.imul(J,Ee)|0;var Gt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,p=Math.imul(ge,be),a=Math.imul(ge,_e),a=a+Math.imul(me,be)|0,y=Math.imul(me,_e),p=p+Math.imul(de,ke)|0,a=a+Math.imul(de,Ae)|0,a=a+Math.imul(pe,ke)|0,y=y+Math.imul(pe,Ae)|0,p=p+Math.imul(he,Se)|0,a=a+Math.imul(he,Ce)|0,a=a+Math.imul(ce,Se)|0,y=y+Math.imul(ce,Ce)|0,p=p+Math.imul(fe,Pe)|0,a=a+Math.imul(fe,xe)|0,a=a+Math.imul(ue,Pe)|0,y=y+Math.imul(ue,xe)|0,p=p+Math.imul(ae,Le)|0,a=a+Math.imul(ae,Ie)|0,a=a+Math.imul(le,Le)|0,y=y+Math.imul(le,Ie)|0,p=p+Math.imul(oe,Oe)|0,a=a+Math.imul(oe,Ne)|0,a=a+Math.imul(se,Oe)|0,y=y+Math.imul(se,Ne)|0,p=p+Math.imul(Y,Re)|0,a=a+Math.imul(Y,Te)|0,a=a+Math.imul(W,Re)|0,y=y+Math.imul(W,Te)|0,p=p+Math.imul(Q,De)|0,a=a+Math.imul(Q,Ee)|0,a=a+Math.imul(te,De)|0,y=y+Math.imul(te,Ee)|0;var Vt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,p=Math.imul(ge,ke),a=Math.imul(ge,Ae),a=a+Math.imul(me,ke)|0,y=Math.imul(me,Ae),p=p+Math.imul(de,Se)|0,a=a+Math.imul(de,Ce)|0,a=a+Math.imul(pe,Se)|0,y=y+Math.imul(pe,Ce)|0,p=p+Math.imul(he,Pe)|0,a=a+Math.imul(he,xe)|0,a=a+Math.imul(ce,Pe)|0,y=y+Math.imul(ce,xe)|0,p=p+Math.imul(fe,Le)|0,a=a+Math.imul(fe,Ie)|0,a=a+Math.imul(ue,Le)|0,y=y+Math.imul(ue,Ie)|0,p=p+Math.imul(ae,Oe)|0,a=a+Math.imul(ae,Ne)|0,a=a+Math.imul(le,Oe)|0,y=y+Math.imul(le,Ne)|0,p=p+Math.imul(oe,Re)|0,a=a+Math.imul(oe,Te)|0,a=a+Math.imul(se,Re)|0,y=y+Math.imul(se,Te)|0,p=p+Math.imul(Y,De)|0,a=a+Math.imul(Y,Ee)|0,a=a+Math.imul(W,De)|0,y=y+Math.imul(W,Ee)|0;var Xt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,p=Math.imul(ge,Se),a=Math.imul(ge,Ce),a=a+Math.imul(me,Se)|0,y=Math.imul(me,Ce),p=p+Math.imul(de,Pe)|0,a=a+Math.imul(de,xe)|0,a=a+Math.imul(pe,Pe)|0,y=y+Math.imul(pe,xe)|0,p=p+Math.imul(he,Le)|0,a=a+Math.imul(he,Ie)|0,a=a+Math.imul(ce,Le)|0,y=y+Math.imul(ce,Ie)|0,p=p+Math.imul(fe,Oe)|0,a=a+Math.imul(fe,Ne)|0,a=a+Math.imul(ue,Oe)|0,y=y+Math.imul(ue,Ne)|0,p=p+Math.imul(ae,Re)|0,a=a+Math.imul(ae,Te)|0,a=a+Math.imul(le,Re)|0,y=y+Math.imul(le,Te)|0,p=p+Math.imul(oe,De)|0,a=a+Math.imul(oe,Ee)|0,a=a+Math.imul(se,De)|0,y=y+Math.imul(se,Ee)|0;var Qt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,p=Math.imul(ge,Pe),a=Math.imul(ge,xe),a=a+Math.imul(me,Pe)|0,y=Math.imul(me,xe),p=p+Math.imul(de,Le)|0,a=a+Math.imul(de,Ie)|0,a=a+Math.imul(pe,Le)|0,y=y+Math.imul(pe,Ie)|0,p=p+Math.imul(he,Oe)|0,a=a+Math.imul(he,Ne)|0,a=a+Math.imul(ce,Oe)|0,y=y+Math.imul(ce,Ne)|0,p=p+Math.imul(fe,Re)|0,a=a+Math.imul(fe,Te)|0,a=a+Math.imul(ue,Re)|0,y=y+Math.imul(ue,Te)|0,p=p+Math.imul(ae,De)|0,a=a+Math.imul(ae,Ee)|0,a=a+Math.imul(le,De)|0,y=y+Math.imul(le,Ee)|0;var Yt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,p=Math.imul(ge,Le),a=Math.imul(ge,Ie),a=a+Math.imul(me,Le)|0,y=Math.imul(me,Ie),p=p+Math.imul(de,Oe)|0,a=a+Math.imul(de,Ne)|0,a=a+Math.imul(pe,Oe)|0,y=y+Math.imul(pe,Ne)|0,p=p+Math.imul(he,Re)|0,a=a+Math.imul(he,Te)|0,a=a+Math.imul(ce,Re)|0,y=y+Math.imul(ce,Te)|0,p=p+Math.imul(fe,De)|0,a=a+Math.imul(fe,Ee)|0,a=a+Math.imul(ue,De)|0,y=y+Math.imul(ue,Ee)|0;var Jt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,p=Math.imul(ge,Oe),a=Math.imul(ge,Ne),a=a+Math.imul(me,Oe)|0,y=Math.imul(me,Ne),p=p+Math.imul(de,Re)|0,a=a+Math.imul(de,Te)|0,a=a+Math.imul(pe,Re)|0,y=y+Math.imul(pe,Te)|0,p=p+Math.imul(he,De)|0,a=a+Math.imul(he,Ee)|0,a=a+Math.imul(ce,De)|0,y=y+Math.imul(ce,Ee)|0;var ei=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(ei>>>26)|0,ei&=67108863,p=Math.imul(ge,Re),a=Math.imul(ge,Te),a=a+Math.imul(me,Re)|0,y=Math.imul(me,Te),p=p+Math.imul(de,De)|0,a=a+Math.imul(de,Ee)|0,a=a+Math.imul(pe,De)|0,y=y+Math.imul(pe,Ee)|0;var ti=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(ti>>>26)|0,ti&=67108863,p=Math.imul(ge,De),a=Math.imul(ge,Ee),a=a+Math.imul(me,De)|0,y=Math.imul(me,Ee);var ii=(k+p|0)+((a&8191)<<13)|0;return k=(y+(a>>>13)|0)+(ii>>>26)|0,ii&=67108863,g[0]=Ft,g[1]=qt,g[2]=Ut,g[3]=Zt,g[4]=jt,g[5]=zt,g[6]=$t,g[7]=Kt,g[8]=Ht,g[9]=Wt,g[10]=Gt,g[11]=Vt,g[12]=Xt,g[13]=Qt,g[14]=Yt,g[15]=Jt,g[16]=ei,g[17]=ti,g[18]=ii,k!==0&&(g[19]=k,l.length++),l};Math.imul||(j=Z);function I(c,e,o){o.negative=e.negative^c.negative,o.length=c.length+e.length;for(var l=0,u=0,h=0;h<o.length-1;h++){var g=u;u=0;for(var k=l&67108863,p=Math.min(h,e.length-1),a=Math.max(0,h-c.length+1);a<=p;a++){var y=h-a,E=c.words[y]|0,R=e.words[a]|0,T=E*R,U=T&67108863;g=g+(T/67108864|0)|0,U=U+k|0,k=U&67108863,g=g+(U>>>26)|0,u+=g>>>26,g&=67108863}o.words[h]=k,l=g,g=u}return l!==0?o.words[h]=l:o.length--,o._strip()}function F(c,e,o){return I(c,e,o)}t.prototype.mulTo=function(e,o){var l,u=this.length+e.length;return this.length===10&&e.length===10?l=j(this,e,o):u<63?l=Z(this,e,o):u<1024?l=I(this,e,o):l=F(this,e,o),l};function q(c,e){this.x=c,this.y=e}q.prototype.makeRBT=function(e){for(var o=new Array(e),l=t.prototype._countBits(e)-1,u=0;u<e;u++)o[u]=this.revBin(u,l,e);return o},q.prototype.revBin=function(e,o,l){if(e===0||e===l-1)return e;for(var u=0,h=0;h<o;h++)u|=(e&1)<<o-h-1,e>>=1;return u},q.prototype.permute=function(e,o,l,u,h,g){for(var k=0;k<g;k++)u[k]=o[e[k]],h[k]=l[e[k]]},q.prototype.transform=function(e,o,l,u,h,g){this.permute(g,e,o,l,u,h);for(var k=1;k<h;k<<=1)for(var p=k<<1,a=Math.cos(2*Math.PI/p),y=Math.sin(2*Math.PI/p),E=0;E<h;E+=p)for(var R=a,T=y,U=0;U<k;U++){var V=l[E+U],J=u[E+U],He=l[E+U+k],Q=u[E+U+k],te=R*He-T*Q;Q=R*Q+T*He,He=te,l[E+U]=V+He,u[E+U]=J+Q,l[E+U+k]=V-He,u[E+U+k]=J-Q,U!==p&&(te=a*R-y*T,T=a*T+y*R,R=te)}},q.prototype.guessLen13b=function(e,o){var l=Math.max(o,e)|1,u=l&1,h=0;for(l=l/2|0;l;l=l>>>1)h++;return 1<<h+1+u},q.prototype.conjugate=function(e,o,l){if(!(l<=1))for(var u=0;u<l/2;u++){var h=e[u];e[u]=e[l-u-1],e[l-u-1]=h,h=o[u],o[u]=-o[l-u-1],o[l-u-1]=-h}},q.prototype.normalize13b=function(e,o){for(var l=0,u=0;u<o/2;u++){var h=Math.round(e[2*u+1]/o)*8192+Math.round(e[2*u]/o)+l;e[u]=h&67108863,h<67108864?l=0:l=h/67108864|0}return e},q.prototype.convert13b=function(e,o,l,u){for(var h=0,g=0;g<o;g++)h=h+(e[g]|0),l[2*g]=h&8191,h=h>>>13,l[2*g+1]=h&8191,h=h>>>13;for(g=2*o;g<u;++g)l[g]=0;n(h===0),n((h&-8192)===0)},q.prototype.stub=function(e){for(var o=new Array(e),l=0;l<e;l++)o[l]=0;return o},q.prototype.mulp=function(e,o,l){var u=2*this.guessLen13b(e.length,o.length),h=this.makeRBT(u),g=this.stub(u),k=new Array(u),p=new Array(u),a=new Array(u),y=new Array(u),E=new Array(u),R=new Array(u),T=l.words;T.length=u,this.convert13b(e.words,e.length,k,u),this.convert13b(o.words,o.length,y,u),this.transform(k,g,p,a,u,h),this.transform(y,g,E,R,u,h);for(var U=0;U<u;U++){var V=p[U]*E[U]-a[U]*R[U];a[U]=p[U]*R[U]+a[U]*E[U],p[U]=V}return this.conjugate(p,a,u),this.transform(p,a,T,g,u,h),this.conjugate(T,g,u),this.normalize13b(T,u),l.negative=e.negative^o.negative,l.length=e.length+o.length,l._strip()},t.prototype.mul=function(e){var o=new t(null);return o.words=new Array(this.length+e.length),this.mulTo(e,o)},t.prototype.mulf=function(e){var o=new t(null);return o.words=new Array(this.length+e.length),F(this,e,o)},t.prototype.imul=function(e){return this.clone().mulTo(e,this)},t.prototype.imuln=function(e){var o=e<0;o&&(e=-e),n(typeof e=="number"),n(e<67108864);for(var l=0,u=0;u<this.length;u++){var h=(this.words[u]|0)*e,g=(h&67108863)+(l&67108863);l>>=26,l+=h/67108864|0,l+=g>>>26,this.words[u]=g&67108863}return l!==0&&(this.words[u]=l,this.length++),this.length=e===0?1:this.length,o?this.ineg():this},t.prototype.muln=function(e){return this.clone().imuln(e)},t.prototype.sqr=function(){return this.mul(this)},t.prototype.isqr=function(){return this.imul(this.clone())},t.prototype.pow=function(e){var o=D(e);if(o.length===0)return new t(1);for(var l=this,u=0;u<o.length&&o[u]===0;u++,l=l.sqr());if(++u<o.length)for(var h=l.sqr();u<o.length;u++,h=h.sqr())o[u]!==0&&(l=l.mul(h));return l},t.prototype.iushln=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26,u=67108863>>>26-o<<26-o,h;if(o!==0){var g=0;for(h=0;h<this.length;h++){var k=this.words[h]&u,p=(this.words[h]|0)-k<<o;this.words[h]=p|g,g=k>>>26-o}g&&(this.words[h]=g,this.length++)}if(l!==0){for(h=this.length-1;h>=0;h--)this.words[h+l]=this.words[h];for(h=0;h<l;h++)this.words[h]=0;this.length+=l}return this._strip()},t.prototype.ishln=function(e){return n(this.negative===0),this.iushln(e)},t.prototype.iushrn=function(e,o,l){n(typeof e=="number"&&e>=0);var u;o?u=(o-o%26)/26:u=0;var h=e%26,g=Math.min((e-h)/26,this.length),k=67108863^67108863>>>h<<h,p=l;if(u-=g,u=Math.max(0,u),p){for(var a=0;a<g;a++)p.words[a]=this.words[a];p.length=g}if(g!==0)if(this.length>g)for(this.length-=g,a=0;a<this.length;a++)this.words[a]=this.words[a+g];else this.words[0]=0,this.length=1;var y=0;for(a=this.length-1;a>=0&&(y!==0||a>=u);a--){var E=this.words[a]|0;this.words[a]=y<<26-h|E>>>h,y=E&k}return p&&y!==0&&(p.words[p.length++]=y),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},t.prototype.ishrn=function(e,o,l){return n(this.negative===0),this.iushrn(e,o,l)},t.prototype.shln=function(e){return this.clone().ishln(e)},t.prototype.ushln=function(e){return this.clone().iushln(e)},t.prototype.shrn=function(e){return this.clone().ishrn(e)},t.prototype.ushrn=function(e){return this.clone().iushrn(e)},t.prototype.testn=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26,u=1<<o;if(this.length<=l)return!1;var h=this.words[l];return!!(h&u)},t.prototype.imaskn=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26;if(n(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 u=67108863^67108863>>>o<<o;this.words[this.length-1]&=u}return this._strip()},t.prototype.maskn=function(e){return this.clone().imaskn(e)},t.prototype.iaddn=function(e){return n(typeof e=="number"),n(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)},t.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},t.prototype.isubn=function(e){if(n(typeof e=="number"),n(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()},t.prototype.addn=function(e){return this.clone().iaddn(e)},t.prototype.subn=function(e){return this.clone().isubn(e)},t.prototype.iabs=function(){return this.negative=0,this},t.prototype.abs=function(){return this.clone().iabs()},t.prototype._ishlnsubmul=function(e,o,l){var u=e.length+l,h;this._expand(u);var g,k=0;for(h=0;h<e.length;h++){g=(this.words[h+l]|0)+k;var p=(e.words[h]|0)*o;g-=p&67108863,k=(g>>26)-(p/67108864|0),this.words[h+l]=g&67108863}for(;h<this.length-l;h++)g=(this.words[h+l]|0)+k,k=g>>26,this.words[h+l]=g&67108863;if(k===0)return this._strip();for(n(k===-1),k=0,h=0;h<this.length;h++)g=-(this.words[h]|0)+k,k=g>>26,this.words[h]=g&67108863;return this.negative=1,this._strip()},t.prototype._wordDiv=function(e,o){var l=this.length-e.length,u=this.clone(),h=e,g=h.words[h.length-1]|0,k=this._countBits(g);l=26-k,l!==0&&(h=h.ushln(l),u.iushln(l),g=h.words[h.length-1]|0);var p=u.length-h.length,a;if(o!=="mod"){a=new t(null),a.length=p+1,a.words=new Array(a.length);for(var y=0;y<a.length;y++)a.words[y]=0}var E=u.clone()._ishlnsubmul(h,1,p);E.negative===0&&(u=E,a&&(a.words[p]=1));for(var R=p-1;R>=0;R--){var T=(u.words[h.length+R]|0)*67108864+(u.words[h.length+R-1]|0);for(T=Math.min(T/g|0,67108863),u._ishlnsubmul(h,T,R);u.negative!==0;)T--,u.negative=0,u._ishlnsubmul(h,1,R),u.isZero()||(u.negative^=1);a&&(a.words[R]=T)}return a&&a._strip(),u._strip(),o!=="div"&&l!==0&&u.iushrn(l),{div:a||null,mod:u}},t.prototype.divmod=function(e,o,l){if(n(!e.isZero()),this.isZero())return{div:new t(0),mod:new t(0)};var u,h,g;return this.negative!==0&&e.negative===0?(g=this.neg().divmod(e,o),o!=="mod"&&(u=g.div.neg()),o!=="div"&&(h=g.mod.neg(),l&&h.negative!==0&&h.iadd(e)),{div:u,mod:h}):this.negative===0&&e.negative!==0?(g=this.divmod(e.neg(),o),o!=="mod"&&(u=g.div.neg()),{div:u,mod:g.mod}):(this.negative&e.negative)!==0?(g=this.neg().divmod(e.neg(),o),o!=="div"&&(h=g.mod.neg(),l&&h.negative!==0&&h.isub(e)),{div:g.div,mod:h}):e.length>this.length||this.cmp(e)<0?{div:new t(0),mod:this}:e.length===1?o==="div"?{div:this.divn(e.words[0]),mod:null}:o==="mod"?{div:null,mod:new t(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new t(this.modrn(e.words[0]))}:this._wordDiv(e,o)},t.prototype.div=function(e){return this.divmod(e,"div",!1).div},t.prototype.mod=function(e){return this.divmod(e,"mod",!1).mod},t.prototype.umod=function(e){return this.divmod(e,"mod",!0).mod},t.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,u=e.ushrn(1),h=e.andln(1),g=l.cmp(u);return g<0||h===1&&g===0?o.div:o.div.negative!==0?o.div.isubn(1):o.div.iaddn(1)},t.prototype.modrn=function(e){var o=e<0;o&&(e=-e),n(e<=67108863);for(var l=(1<<26)%e,u=0,h=this.length-1;h>=0;h--)u=(l*u+(this.words[h]|0))%e;return o?-u:u},t.prototype.modn=function(e){return this.modrn(e)},t.prototype.idivn=function(e){var o=e<0;o&&(e=-e),n(e<=67108863);for(var l=0,u=this.length-1;u>=0;u--){var h=(this.words[u]|0)+l*67108864;this.words[u]=h/e|0,l=h%e}return this._strip(),o?this.ineg():this},t.prototype.divn=function(e){return this.clone().idivn(e)},t.prototype.egcd=function(e){n(e.negative===0),n(!e.isZero());var o=this,l=e.clone();o.negative!==0?o=o.umod(e):o=o.clone();for(var u=new t(1),h=new t(0),g=new t(0),k=new t(1),p=0;o.isEven()&&l.isEven();)o.iushrn(1),l.iushrn(1),++p;for(var a=l.clone(),y=o.clone();!o.isZero();){for(var E=0,R=1;(o.words[0]&R)===0&&E<26;++E,R<<=1);if(E>0)for(o.iushrn(E);E-- >0;)(u.isOdd()||h.isOdd())&&(u.iadd(a),h.isub(y)),u.iushrn(1),h.iushrn(1);for(var T=0,U=1;(l.words[0]&U)===0&&T<26;++T,U<<=1);if(T>0)for(l.iushrn(T);T-- >0;)(g.isOdd()||k.isOdd())&&(g.iadd(a),k.isub(y)),g.iushrn(1),k.iushrn(1);o.cmp(l)>=0?(o.isub(l),u.isub(g),h.isub(k)):(l.isub(o),g.isub(u),k.isub(h))}return{a:g,b:k,gcd:l.iushln(p)}},t.prototype._invmp=function(e){n(e.negative===0),n(!e.isZero());var o=this,l=e.clone();o.negative!==0?o=o.umod(e):o=o.clone();for(var u=new t(1),h=new t(0),g=l.clone();o.cmpn(1)>0&&l.cmpn(1)>0;){for(var k=0,p=1;(o.words[0]&p)===0&&k<26;++k,p<<=1);if(k>0)for(o.iushrn(k);k-- >0;)u.isOdd()&&u.iadd(g),u.iushrn(1);for(var a=0,y=1;(l.words[0]&y)===0&&a<26;++a,y<<=1);if(a>0)for(l.iushrn(a);a-- >0;)h.isOdd()&&h.iadd(g),h.iushrn(1);o.cmp(l)>=0?(o.isub(l),u.isub(h)):(l.isub(o),h.isub(u))}var E;return o.cmpn(1)===0?E=u:E=h,E.cmpn(0)<0&&E.iadd(e),E},t.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 u=0;o.isEven()&&l.isEven();u++)o.iushrn(1),l.iushrn(1);do{for(;o.isEven();)o.iushrn(1);for(;l.isEven();)l.iushrn(1);var h=o.cmp(l);if(h<0){var g=o;o=l,l=g}else if(h===0||l.cmpn(1)===0)break;o.isub(l)}while(!0);return l.iushln(u)},t.prototype.invm=function(e){return this.egcd(e).a.umod(e)},t.prototype.isEven=function(){return(this.words[0]&1)===0},t.prototype.isOdd=function(){return(this.words[0]&1)===1},t.prototype.andln=function(e){return this.words[0]&e},t.prototype.bincn=function(e){n(typeof e=="number");var o=e%26,l=(e-o)/26,u=1<<o;if(this.length<=l)return this._expand(l+1),this.words[l]|=u,this;for(var h=u,g=l;h!==0&&g<this.length;g++){var k=this.words[g]|0;k+=h,h=k>>>26,k&=67108863,this.words[g]=k}return h!==0&&(this.words[g]=h,this.length++),this},t.prototype.isZero=function(){return this.length===1&&this.words[0]===0},t.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),n(e<=67108863,"Number is too big");var u=this.words[0]|0;l=u===e?0:u<e?-1:1}return this.negative!==0?-l|0:l},t.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},t.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 u=this.words[l]|0,h=e.words[l]|0;if(u!==h){u<h?o=-1:u>h&&(o=1);break}}return o},t.prototype.gtn=function(e){return this.cmpn(e)===1},t.prototype.gt=function(e){return this.cmp(e)===1},t.prototype.gten=function(e){return this.cmpn(e)>=0},t.prototype.gte=function(e){return this.cmp(e)>=0},t.prototype.ltn=function(e){return this.cmpn(e)===-1},t.prototype.lt=function(e){return this.cmp(e)===-1},t.prototype.lten=function(e){return this.cmpn(e)<=0},t.prototype.lte=function(e){return this.cmp(e)<=0},t.prototype.eqn=function(e){return this.cmpn(e)===0},t.prototype.eq=function(e){return this.cmp(e)===0},t.red=function(e){return new P(e)},t.prototype.toRed=function(e){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),e.convertTo(this)._forceRed(e)},t.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},t.prototype._forceRed=function(e){return this.red=e,this},t.prototype.forceRed=function(e){return n(!this.red,"Already a number in reduction context"),this._forceRed(e)},t.prototype.redAdd=function(e){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},t.prototype.redIAdd=function(e){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},t.prototype.redSub=function(e){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},t.prototype.redISub=function(e){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},t.prototype.redShl=function(e){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},t.prototype.redMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},t.prototype.redIMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},t.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},t.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},t.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},t.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},t.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},t.prototype.redPow=function(e){return n(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var ee={k256:null,p224:null,p192:null,p25519:null};function $(c,e){this.name=c,this.p=new t(e,16),this.n=this.p.bitLength(),this.k=new t(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}$.prototype._tmp=function(){var e=new t(null);return e.words=new Array(Math.ceil(this.n/13)),e},$.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 u=l<this.n?-1:o.ucmp(this.p);return u===0?(o.words[0]=0,o.length=1):u>0?o.isub(this.p):o.strip!==void 0?o.strip():o._strip(),o},$.prototype.split=function(e,o){e.iushrn(this.n,0,o)},$.prototype.imulK=function(e){return e.imul(this.k)};function X(){$.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(X,$),X.prototype.split=function(e,o){for(var l=4194303,u=Math.min(e.length,9),h=0;h<u;h++)o.words[h]=e.words[h];if(o.length=u,e.length<=9){e.words[0]=0,e.length=1;return}var g=e.words[9];for(o.words[o.length++]=g&l,h=10;h<e.length;h++){var k=e.words[h]|0;e.words[h-10]=(k&l)<<4|g>>>22,g=k}g>>>=22,e.words[h-10]=g,g===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 u=e.words[l]|0;o+=u*977,e.words[l]=o&67108863,o=u*64+(o/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function m(){$.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(m,$);function b(){$.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(b,$);function _(){$.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(_,$),_.prototype.imulK=function(e){for(var o=0,l=0;l<e.length;l++){var u=(e.words[l]|0)*19+o,h=u&67108863;u>>>=26,e.words[l]=h,o=u}return o!==0&&(e.words[e.length++]=o),e},t._prime=function(e){if(ee[e])return ee[e];var o;if(e==="k256")o=new X;else if(e==="p224")o=new m;else if(e==="p192")o=new b;else if(e==="p25519")o=new _;else throw new Error("Unknown prime "+e);return ee[e]=o,o};function P(c){if(typeof c=="string"){var e=t._prime(c);this.m=e.p,this.prime=e}else n(c.gtn(1),"modulus must be greater than 1"),this.m=c,this.prime=null}P.prototype._verify1=function(e){n(e.negative===0,"red works only with positives"),n(e.red,"red works only with red numbers")},P.prototype._verify2=function(e,o){n((e.negative|o.negative)===0,"red works only with positives"),n(e.red&&e.red===o.red,"red works only with red numbers")},P.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(w(e,e.umod(this.m)._forceRed(this)),e)},P.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},P.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)},P.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},P.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)},P.prototype.isub=function(e,o){this._verify2(e,o);var l=e.isub(o);return l.cmpn(0)<0&&l.iadd(this.m),l},P.prototype.shl=function(e,o){return this._verify1(e),this.imod(e.ushln(o))},P.prototype.imul=function(e,o){return this._verify2(e,o),this.imod(e.imul(o))},P.prototype.mul=function(e,o){return this._verify2(e,o),this.imod(e.mul(o))},P.prototype.isqr=function(e){return this.imul(e,e.clone())},P.prototype.sqr=function(e){return this.mul(e,e)},P.prototype.sqrt=function(e){if(e.isZero())return e.clone();var o=this.m.andln(3);if(n(o%2===1),o===3){var l=this.m.add(new t(1)).iushrn(2);return this.pow(e,l)}for(var u=this.m.subn(1),h=0;!u.isZero()&&u.andln(1)===0;)h++,u.iushrn(1);n(!u.isZero());var g=new t(1).toRed(this),k=g.redNeg(),p=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new t(2*a*a).toRed(this);this.pow(a,p).cmp(k)!==0;)a.redIAdd(k);for(var y=this.pow(a,u),E=this.pow(e,u.addn(1).iushrn(1)),R=this.pow(e,u),T=h;R.cmp(g)!==0;){for(var U=R,V=0;U.cmp(g)!==0;V++)U=U.redSqr();n(V<T);var J=this.pow(y,new t(1).iushln(T-V-1));E=E.redMul(J),y=J.redSqr(),R=R.redMul(y),T=V}return E},P.prototype.invm=function(e){var o=e._invmp(this.m);return o.negative!==0?(o.negative=0,this.imod(o).redNeg()):this.imod(o)},P.prototype.pow=function(e,o){if(o.isZero())return new t(1).toRed(this);if(o.cmpn(1)===0)return e.clone();var l=4,u=new Array(1<<l);u[0]=new t(1).toRed(this),u[1]=e;for(var h=2;h<u.length;h++)u[h]=this.mul(u[h-1],e);var g=u[0],k=0,p=0,a=o.bitLength()%26;for(a===0&&(a=26),h=o.length-1;h>=0;h--){for(var y=o.words[h],E=a-1;E>=0;E--){var R=y>>E&1;if(g!==u[0]&&(g=this.sqr(g)),R===0&&k===0){p=0;continue}k<<=1,k|=R,p++,!(p!==l&&(h!==0||E!==0))&&(g=this.mul(g,u[k]),p=0,k=0)}a=26}return g},P.prototype.convertTo=function(e){var o=e.umod(this.m);return o===e?o.clone():o},P.prototype.convertFrom=function(e){var o=e.clone();return o.red=null,o},t.mont=function(e){return new S(e)};function S(c){P.call(this,c),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new t(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(S,P),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),u=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(u).iushrn(this.shift),g=h;return h.cmp(this.m)>=0?g=h.isub(this.m):h.cmpn(0)<0&&(g=h.iadd(this.m)),g._forceRed(this)},S.prototype.mul=function(e,o){if(e.isZero()||o.isZero())return new t(0)._forceRed(this);var l=e.mul(o),u=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(u).iushrn(this.shift),g=h;return h.cmp(this.m)>=0?g=h.isub(this.m):h.cmpn(0)<0&&(g=h.iadd(this.m)),g._forceRed(this)},S.prototype.invm=function(e){var o=this.imod(e._invmp(this.m).mul(this.r2));return o._forceRed(this)}})(typeof vi>"u"||vi,dr)});var Ln={};Lr(Ln,{CetusLeverageSDK:()=>yt,default:()=>xn,leverage_mainnet:()=>ni});module.exports=Ir(Ln);var wr=require("@cetusprotocol/common-sdk");var _t=require("@cetusprotocol/common-sdk");var ni={full_rpc_url:_t.FullRpcUrlMainnet,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:_t.DefaultProviders,leverage:{package_id:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",published_at:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",version:0,config:{global_config_id:"0xf6c5da03798ff33dd4036aa1fe8b8321f8d41b279247abb5c01254e12b05c19b",markets_table_id:"0x2720d2dfe2b50f700edb69dabd8b51d611961521682a935f09c01d191000f8d0"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{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 Qi=require("@suilend/sdk/client"),re=require("@suilend/sdk");var Or=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,oi=Math.ceil,Ge=Math.floor,$e="[BigNumber Error] ",Fi=$e+"Number primitive has more than 15 significant digits: ",Xe=1e14,G=14,si=9007199254740991,ai=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],at=1e7,Fe=1e9;function qi(i){var r,n,s,t=I.prototype={constructor:I,toString:null,valueOf:null},f=new I(1),d=20,v=4,M=-7,w=21,A=-1e7,x=1e7,C=!1,L=1,B=0,D={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},Z="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function I(m,b){var _,P,S,c,e,o,l,u,h=this;if(!(h instanceof I))return new I(m,b);if(b==null){if(m&&m._isBigNumber===!0){h.s=m.s,!m.c||m.e>x?h.c=h.e=null:m.e<A?h.c=[h.e=0]:(h.e=m.e,h.c=m.c.slice());return}if((o=typeof m=="number")&&m*0==0){if(h.s=1/m<0?(m=-m,-1):1,m===~~m){for(c=0,e=m;e>=10;e/=10,c++);c>x?h.c=h.e=null:(h.e=c,h.c=[m]);return}u=String(m)}else{if(!Or.test(u=String(m)))return s(h,u,o);h.s=u.charCodeAt(0)==45?(u=u.slice(1),-1):1}(c=u.indexOf("."))>-1&&(u=u.replace(".","")),(e=u.search(/e/i))>0?(c<0&&(c=e),c+=+u.slice(e+1),u=u.substring(0,e)):c<0&&(c=u.length)}else{if(ne(b,2,Z.length,"Base"),b==10&&j)return h=new I(m),$(h,d+h.e+1,v);if(u=String(m),o=typeof m=="number"){if(m*0!=0)return s(h,u,o,b);if(h.s=1/m<0?(u=u.slice(1),-1):1,I.DEBUG&&u.replace(/^0\.0*|\./,"").length>15)throw Error(Fi+m)}else h.s=u.charCodeAt(0)===45?(u=u.slice(1),-1):1;for(_=Z.slice(0,b),c=e=0,l=u.length;e<l;e++)if(_.indexOf(P=u.charAt(e))<0){if(P=="."){if(e>c){c=l;continue}}else if(!S&&(u==u.toUpperCase()&&(u=u.toLowerCase())||u==u.toLowerCase()&&(u=u.toUpperCase()))){S=!0,e=-1,c=0;continue}return s(h,String(m),o,b)}o=!1,u=n(u,b,10,h.s),(c=u.indexOf("."))>-1?u=u.replace(".",""):c=u.length}for(e=0;u.charCodeAt(e)===48;e++);for(l=u.length;u.charCodeAt(--l)===48;);if(u=u.slice(e,++l)){if(l-=e,o&&I.DEBUG&&l>15&&(m>si||m!==Ge(m)))throw Error(Fi+h.s*m);if((c=c-e-1)>x)h.c=h.e=null;else if(c<A)h.c=[h.e=0];else{if(h.e=c,h.c=[],e=(c+1)%G,c<0&&(e+=G),e<l){for(e&&h.c.push(+u.slice(0,e)),l-=G;e<l;)h.c.push(+u.slice(e,e+=G));e=G-(u=u.slice(e)).length}else e-=l;for(;e--;u+="0");h.c.push(+u)}}else h.c=[h.e=0]}I.clone=qi,I.ROUND_UP=0,I.ROUND_DOWN=1,I.ROUND_CEIL=2,I.ROUND_FLOOR=3,I.ROUND_HALF_UP=4,I.ROUND_HALF_DOWN=5,I.ROUND_HALF_EVEN=6,I.ROUND_HALF_CEIL=7,I.ROUND_HALF_FLOOR=8,I.EUCLID=9,I.config=I.set=function(m){var b,_;if(m!=null)if(typeof m=="object"){if(m.hasOwnProperty(b="DECIMAL_PLACES")&&(_=m[b],ne(_,0,Fe,b),d=_),m.hasOwnProperty(b="ROUNDING_MODE")&&(_=m[b],ne(_,0,8,b),v=_),m.hasOwnProperty(b="EXPONENTIAL_AT")&&(_=m[b],_&&_.pop?(ne(_[0],-Fe,0,b),ne(_[1],0,Fe,b),M=_[0],w=_[1]):(ne(_,-Fe,Fe,b),M=-(w=_<0?-_:_))),m.hasOwnProperty(b="RANGE"))if(_=m[b],_&&_.pop)ne(_[0],-Fe,-1,b),ne(_[1],1,Fe,b),A=_[0],x=_[1];else if(ne(_,-Fe,Fe,b),_)A=-(x=_<0?-_:_);else throw Error($e+b+" cannot be zero: "+_);if(m.hasOwnProperty(b="CRYPTO"))if(_=m[b],_===!!_)if(_)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))C=_;else throw C=!_,Error($e+"crypto unavailable");else C=_;else throw Error($e+b+" not true or false: "+_);if(m.hasOwnProperty(b="MODULO_MODE")&&(_=m[b],ne(_,0,9,b),L=_),m.hasOwnProperty(b="POW_PRECISION")&&(_=m[b],ne(_,0,Fe,b),B=_),m.hasOwnProperty(b="FORMAT"))if(_=m[b],typeof _=="object")D=_;else throw Error($e+b+" not an object: "+_);if(m.hasOwnProperty(b="ALPHABET"))if(_=m[b],typeof _=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(_))j=_.slice(0,10)=="0123456789",Z=_;else throw Error($e+b+" invalid: "+_)}else throw Error($e+"Object expected: "+m);return{DECIMAL_PLACES:d,ROUNDING_MODE:v,EXPONENTIAL_AT:[M,w],RANGE:[A,x],CRYPTO:C,MODULO_MODE:L,POW_PRECISION:B,FORMAT:D,ALPHABET:Z}},I.isBigNumber=function(m){if(!m||m._isBigNumber!==!0)return!1;if(!I.DEBUG)return!0;var b,_,P=m.c,S=m.e,c=m.s;e:if({}.toString.call(P)=="[object Array]"){if((c===1||c===-1)&&S>=-Fe&&S<=Fe&&S===Ge(S)){if(P[0]===0){if(S===0&&P.length===1)return!0;break e}if(b=(S+1)%G,b<1&&(b+=G),String(P[0]).length==b){for(b=0;b<P.length;b++)if(_=P[b],_<0||_>=Xe||_!==Ge(_))break e;if(_!==0)return!0}}}else if(P===null&&S===null&&(c===null||c===1||c===-1))return!0;throw Error($e+"Invalid BigNumber: "+m)},I.maximum=I.max=function(){return q(arguments,-1)},I.minimum=I.min=function(){return q(arguments,1)},I.random=(function(){var m=9007199254740992,b=Math.random()*m&2097151?function(){return Ge(Math.random()*m)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(_){var P,S,c,e,o,l=0,u=[],h=new I(f);if(_==null?_=d:ne(_,0,Fe),e=oi(_/G),C)if(crypto.getRandomValues){for(P=crypto.getRandomValues(new Uint32Array(e*=2));l<e;)o=P[l]*131072+(P[l+1]>>>11),o>=9e15?(S=crypto.getRandomValues(new Uint32Array(2)),P[l]=S[0],P[l+1]=S[1]):(u.push(o%1e14),l+=2);l=e/2}else if(crypto.randomBytes){for(P=crypto.randomBytes(e*=7);l<e;)o=(P[l]&31)*281474976710656+P[l+1]*1099511627776+P[l+2]*4294967296+P[l+3]*16777216+(P[l+4]<<16)+(P[l+5]<<8)+P[l+6],o>=9e15?crypto.randomBytes(7).copy(P,l):(u.push(o%1e14),l+=7);l=e/7}else throw C=!1,Error($e+"crypto unavailable");if(!C)for(;l<e;)o=b(),o<9e15&&(u[l++]=o%1e14);for(e=u[--l],_%=G,e&&_&&(o=ai[G-_],u[l]=Ge(e/o)*o);u[l]===0;u.pop(),l--);if(l<0)u=[c=0];else{for(c=-1;u[0]===0;u.splice(0,1),c-=G);for(l=1,o=u[0];o>=10;o/=10,l++);l<G&&(c-=G-l)}return h.e=c,h.c=u,h}})(),I.sum=function(){for(var m=1,b=arguments,_=new I(b[0]);m<b.length;)_=_.plus(b[m++]);return _},n=(function(){var m="0123456789";function b(_,P,S,c){for(var e,o=[0],l,u=0,h=_.length;u<h;){for(l=o.length;l--;o[l]*=P);for(o[0]+=c.indexOf(_.charAt(u++)),e=0;e<o.length;e++)o[e]>S-1&&(o[e+1]==null&&(o[e+1]=0),o[e+1]+=o[e]/S|0,o[e]%=S)}return o.reverse()}return function(_,P,S,c,e){var o,l,u,h,g,k,p,a,y=_.indexOf("."),E=d,R=v;for(y>=0&&(h=B,B=0,_=_.replace(".",""),a=new I(P),k=a.pow(_.length-y),B=h,a.c=b(rt(We(k.c),k.e,"0"),10,S,m),a.e=a.c.length),p=b(_,P,S,e?(o=Z,m):(o=m,Z)),u=h=p.length;p[--h]==0;p.pop());if(!p[0])return o.charAt(0);if(y<0?--u:(k.c=p,k.e=u,k.s=c,k=r(k,a,E,R,S),p=k.c,g=k.r,u=k.e),l=u+E+1,y=p[l],h=S/2,g=g||l<0||p[l+1]!=null,g=R<4?(y!=null||g)&&(R==0||R==(k.s<0?3:2)):y>h||y==h&&(R==4||g||R==6&&p[l-1]&1||R==(k.s<0?8:7)),l<1||!p[0])_=g?rt(o.charAt(1),-E,o.charAt(0)):o.charAt(0);else{if(p.length=l,g)for(--S;++p[--l]>S;)p[l]=0,l||(++u,p=[1].concat(p));for(h=p.length;!p[--h];);for(y=0,_="";y<=h;_+=o.charAt(p[y++]));_=rt(_,u,o.charAt(0))}return _}})(),r=(function(){function m(P,S,c){var e,o,l,u,h=0,g=P.length,k=S%at,p=S/at|0;for(P=P.slice();g--;)l=P[g]%at,u=P[g]/at|0,e=p*l+u*k,o=k*l+e%at*at+h,h=(o/c|0)+(e/at|0)+p*u,P[g]=o%c;return h&&(P=[h].concat(P)),P}function b(P,S,c,e){var o,l;if(c!=e)l=c>e?1:-1;else for(o=l=0;o<c;o++)if(P[o]!=S[o]){l=P[o]>S[o]?1:-1;break}return l}function _(P,S,c,e){for(var o=0;c--;)P[c]-=o,o=P[c]<S[c]?1:0,P[c]=o*e+P[c]-S[c];for(;!P[0]&&P.length>1;P.splice(0,1));}return function(P,S,c,e,o){var l,u,h,g,k,p,a,y,E,R,T,U,V,J,He,Q,te,ze=P.s==S.s?1:-1,Y=P.c,W=S.c;if(!Y||!Y[0]||!W||!W[0])return new I(!P.s||!S.s||(Y?W&&Y[0]==W[0]:!W)?NaN:Y&&Y[0]==0||!W?ze*0:ze/0);for(y=new I(ze),E=y.c=[],u=P.e-S.e,ze=c+u+1,o||(o=Xe,u=Ve(P.e/G)-Ve(S.e/G),ze=ze/G|0),h=0;W[h]==(Y[h]||0);h++);if(W[h]>(Y[h]||0)&&u--,ze<0)E.push(1),g=!0;else{for(J=Y.length,Q=W.length,h=0,ze+=2,k=Ge(o/(W[0]+1)),k>1&&(W=m(W,k,o),Y=m(Y,k,o),Q=W.length,J=Y.length),V=Q,R=Y.slice(0,Q),T=R.length;T<Q;R[T++]=0);te=W.slice(),te=[0].concat(te),He=W[0],W[1]>=o/2&&He++;do{if(k=0,l=b(W,R,Q,T),l<0){if(U=R[0],Q!=T&&(U=U*o+(R[1]||0)),k=Ge(U/He),k>1)for(k>=o&&(k=o-1),p=m(W,k,o),a=p.length,T=R.length;b(p,R,a,T)==1;)k--,_(p,Q<a?te:W,a,o),a=p.length,l=1;else k==0&&(l=k=1),p=W.slice(),a=p.length;if(a<T&&(p=[0].concat(p)),_(R,p,T,o),T=R.length,l==-1)for(;b(W,R,Q,T)<1;)k++,_(R,Q<T?te:W,T,o),T=R.length}else l===0&&(k++,R=[0]);E[h++]=k,R[0]?R[T++]=Y[V]||0:(R=[Y[V]],T=1)}while((V++<J||R[0]!=null)&&ze--);g=R[0]!=null,E[0]||E.splice(0,1)}if(o==Xe){for(h=1,ze=E[0];ze>=10;ze/=10,h++);$(y,c+(y.e=h+u*G-1)+1,e,g)}else y.e=u,y.r=+g;return y}})();function F(m,b,_,P){var S,c,e,o,l;if(_==null?_=v:ne(_,0,8),!m.c)return m.toString();if(S=m.c[0],e=m.e,b==null)l=We(m.c),l=P==1||P==2&&(e<=M||e>=w)?At(l,e):rt(l,e,"0");else if(m=$(new I(m),b,_),c=m.e,l=We(m.c),o=l.length,P==1||P==2&&(b<=c||c<=M)){for(;o<b;l+="0",o++);l=At(l,c)}else if(b-=e+(P===2&&c>e),l=rt(l,c,"0"),c+1>o){if(--b>0)for(l+=".";b--;l+="0");}else if(b+=c-o,b>0)for(c+1==o&&(l+=".");b--;l+="0");return m.s<0&&S?"-"+l:l}function q(m,b){for(var _,P,S=1,c=new I(m[0]);S<m.length;S++)P=new I(m[S]),(!P.s||(_=ct(c,P))===b||_===0&&c.s===b)&&(c=P);return c}function ee(m,b,_){for(var P=1,S=b.length;!b[--S];b.pop());for(S=b[0];S>=10;S/=10,P++);return(_=P+_*G-1)>x?m.c=m.e=null:_<A?m.c=[m.e=0]:(m.e=_,m.c=b),m}s=(function(){var m=/^(-?)0([xbo])(?=\w[\w.]*$)/i,b=/^([^.]+)\.$/,_=/^\.([^.]+)$/,P=/^-?(Infinity|NaN)$/,S=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(c,e,o,l){var u,h=o?e:e.replace(S,"");if(P.test(h))c.s=isNaN(h)?null:h<0?-1:1;else{if(!o&&(h=h.replace(m,function(g,k,p){return u=(p=p.toLowerCase())=="x"?16:p=="b"?2:8,!l||l==u?k:g}),l&&(u=l,h=h.replace(b,"$1").replace(_,"0.$1")),e!=h))return new I(h,u);if(I.DEBUG)throw Error($e+"Not a"+(l?" base "+l:"")+" number: "+e);c.s=null}c.c=c.e=null}})();function $(m,b,_,P){var S,c,e,o,l,u,h,g=m.c,k=ai;if(g){e:{for(S=1,o=g[0];o>=10;o/=10,S++);if(c=b-S,c<0)c+=G,e=b,l=g[u=0],h=Ge(l/k[S-e-1]%10);else if(u=oi((c+1)/G),u>=g.length)if(P){for(;g.length<=u;g.push(0));l=h=0,S=1,c%=G,e=c-G+1}else break e;else{for(l=o=g[u],S=1;o>=10;o/=10,S++);c%=G,e=c-G+S,h=e<0?0:Ge(l/k[S-e-1]%10)}if(P=P||b<0||g[u+1]!=null||(e<0?l:l%k[S-e-1]),P=_<4?(h||P)&&(_==0||_==(m.s<0?3:2)):h>5||h==5&&(_==4||P||_==6&&(c>0?e>0?l/k[S-e]:0:g[u-1])%10&1||_==(m.s<0?8:7)),b<1||!g[0])return g.length=0,P?(b-=m.e+1,g[0]=k[(G-b%G)%G],m.e=-b||0):g[0]=m.e=0,m;if(c==0?(g.length=u,o=1,u--):(g.length=u+1,o=k[G-c],g[u]=e>0?Ge(l/k[S-e]%k[e])*o:0),P)for(;;)if(u==0){for(c=1,e=g[0];e>=10;e/=10,c++);for(e=g[0]+=o,o=1;e>=10;e/=10,o++);c!=o&&(m.e++,g[0]==Xe&&(g[0]=1));break}else{if(g[u]+=o,g[u]!=Xe)break;g[u--]=0,o=1}for(c=g.length;g[--c]===0;g.pop());}m.e>x?m.c=m.e=null:m.e<A&&(m.c=[m.e=0])}return m}function X(m){var b,_=m.e;return _===null?m.toString():(b=We(m.c),b=_<=M||_>=w?At(b,_):rt(b,_,"0"),m.s<0?"-"+b:b)}return t.absoluteValue=t.abs=function(){var m=new I(this);return m.s<0&&(m.s=1),m},t.comparedTo=function(m,b){return ct(this,new I(m,b))},t.decimalPlaces=t.dp=function(m,b){var _,P,S,c=this;if(m!=null)return ne(m,0,Fe),b==null?b=v:ne(b,0,8),$(new I(c),m+c.e+1,b);if(!(_=c.c))return null;if(P=((S=_.length-1)-Ve(this.e/G))*G,S=_[S])for(;S%10==0;S/=10,P--);return P<0&&(P=0),P},t.dividedBy=t.div=function(m,b){return r(this,new I(m,b),d,v)},t.dividedToIntegerBy=t.idiv=function(m,b){return r(this,new I(m,b),0,1)},t.exponentiatedBy=t.pow=function(m,b){var _,P,S,c,e,o,l,u,h,g=this;if(m=new I(m),m.c&&!m.isInteger())throw Error($e+"Exponent not an integer: "+X(m));if(b!=null&&(b=new I(b)),o=m.e>14,!g.c||!g.c[0]||g.c[0]==1&&!g.e&&g.c.length==1||!m.c||!m.c[0])return h=new I(Math.pow(+X(g),o?m.s*(2-kt(m)):+X(m))),b?h.mod(b):h;if(l=m.s<0,b){if(b.c?!b.c[0]:!b.s)return new I(NaN);P=!l&&g.isInteger()&&b.isInteger(),P&&(g=g.mod(b))}else{if(m.e>9&&(g.e>0||g.e<-1||(g.e==0?g.c[0]>1||o&&g.c[1]>=24e7:g.c[0]<8e13||o&&g.c[0]<=9999975e7)))return c=g.s<0&&kt(m)?-0:0,g.e>-1&&(c=1/c),new I(l?1/c:c);B&&(c=oi(B/G+2))}for(o?(_=new I(.5),l&&(m.s=1),u=kt(m)):(S=Math.abs(+X(m)),u=S%2),h=new I(f);;){if(u){if(h=h.times(g),!h.c)break;c?h.c.length>c&&(h.c.length=c):P&&(h=h.mod(b))}if(S){if(S=Ge(S/2),S===0)break;u=S%2}else if(m=m.times(_),$(m,m.e+1,1),m.e>14)u=kt(m);else{if(S=+X(m),S===0)break;u=S%2}g=g.times(g),c?g.c&&g.c.length>c&&(g.c.length=c):P&&(g=g.mod(b))}return P?h:(l&&(h=f.div(h)),b?h.mod(b):c?$(h,B,v,e):h)},t.integerValue=function(m){var b=new I(this);return m==null?m=v:ne(m,0,8),$(b,b.e+1,m)},t.isEqualTo=t.eq=function(m,b){return ct(this,new I(m,b))===0},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(m,b){return ct(this,new I(m,b))>0},t.isGreaterThanOrEqualTo=t.gte=function(m,b){return(b=ct(this,new I(m,b)))===1||b===0},t.isInteger=function(){return!!this.c&&Ve(this.e/G)>this.c.length-2},t.isLessThan=t.lt=function(m,b){return ct(this,new I(m,b))<0},t.isLessThanOrEqualTo=t.lte=function(m,b){return(b=ct(this,new I(m,b)))===-1||b===0},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return this.s>0},t.isZero=function(){return!!this.c&&this.c[0]==0},t.minus=function(m,b){var _,P,S,c,e=this,o=e.s;if(m=new I(m,b),b=m.s,!o||!b)return new I(NaN);if(o!=b)return m.s=-b,e.plus(m);var l=e.e/G,u=m.e/G,h=e.c,g=m.c;if(!l||!u){if(!h||!g)return h?(m.s=-b,m):new I(g?e:NaN);if(!h[0]||!g[0])return g[0]?(m.s=-b,m):new I(h[0]?e:v==3?-0:0)}if(l=Ve(l),u=Ve(u),h=h.slice(),o=l-u){for((c=o<0)?(o=-o,S=h):(u=l,S=g),S.reverse(),b=o;b--;S.push(0));S.reverse()}else for(P=(c=(o=h.length)<(b=g.length))?o:b,o=b=0;b<P;b++)if(h[b]!=g[b]){c=h[b]<g[b];break}if(c&&(S=h,h=g,g=S,m.s=-m.s),b=(P=g.length)-(_=h.length),b>0)for(;b--;h[_++]=0);for(b=Xe-1;P>o;){if(h[--P]<g[P]){for(_=P;_&&!h[--_];h[_]=b);--h[_],h[P]+=Xe}h[P]-=g[P]}for(;h[0]==0;h.splice(0,1),--u);return h[0]?ee(m,h,u):(m.s=v==3?-1:1,m.c=[m.e=0],m)},t.modulo=t.mod=function(m,b){var _,P,S=this;return m=new I(m,b),!S.c||!m.s||m.c&&!m.c[0]?new I(NaN):!m.c||S.c&&!S.c[0]?new I(S):(L==9?(P=m.s,m.s=1,_=r(S,m,0,3),m.s=P,_.s*=P):_=r(S,m,0,L),m=S.minus(_.times(m)),!m.c[0]&&L==1&&(m.s=S.s),m)},t.multipliedBy=t.times=function(m,b){var _,P,S,c,e,o,l,u,h,g,k,p,a,y,E,R=this,T=R.c,U=(m=new I(m,b)).c;if(!T||!U||!T[0]||!U[0])return!R.s||!m.s||T&&!T[0]&&!U||U&&!U[0]&&!T?m.c=m.e=m.s=null:(m.s*=R.s,!T||!U?m.c=m.e=null:(m.c=[0],m.e=0)),m;for(P=Ve(R.e/G)+Ve(m.e/G),m.s*=R.s,l=T.length,g=U.length,l<g&&(a=T,T=U,U=a,S=l,l=g,g=S),S=l+g,a=[];S--;a.push(0));for(y=Xe,E=at,S=g;--S>=0;){for(_=0,k=U[S]%E,p=U[S]/E|0,e=l,c=S+e;c>S;)u=T[--e]%E,h=T[e]/E|0,o=p*u+h*k,u=k*u+o%E*E+a[c]+_,_=(u/y|0)+(o/E|0)+p*h,a[c--]=u%y;a[c]=_}return _?++P:a.splice(0,1),ee(m,a,P)},t.negated=function(){var m=new I(this);return m.s=-m.s||null,m},t.plus=function(m,b){var _,P=this,S=P.s;if(m=new I(m,b),b=m.s,!S||!b)return new I(NaN);if(S!=b)return m.s=-b,P.minus(m);var c=P.e/G,e=m.e/G,o=P.c,l=m.c;if(!c||!e){if(!o||!l)return new I(S/0);if(!o[0]||!l[0])return l[0]?m:new I(o[0]?P:S*0)}if(c=Ve(c),e=Ve(e),o=o.slice(),S=c-e){for(S>0?(e=c,_=l):(S=-S,_=o),_.reverse();S--;_.push(0));_.reverse()}for(S=o.length,b=l.length,S-b<0&&(_=l,l=o,o=_,b=S),S=0;b;)S=(o[--b]=o[b]+l[b]+S)/Xe|0,o[b]=Xe===o[b]?0:o[b]%Xe;return S&&(o=[S].concat(o),++e),ee(m,o,e)},t.precision=t.sd=function(m,b){var _,P,S,c=this;if(m!=null&&m!==!!m)return ne(m,1,Fe),b==null?b=v:ne(b,0,8),$(new I(c),m,b);if(!(_=c.c))return null;if(S=_.length-1,P=S*G+1,S=_[S]){for(;S%10==0;S/=10,P--);for(S=_[0];S>=10;S/=10,P++);}return m&&c.e+1>P&&(P=c.e+1),P},t.shiftedBy=function(m){return ne(m,-si,si),this.times("1e"+m)},t.squareRoot=t.sqrt=function(){var m,b,_,P,S,c=this,e=c.c,o=c.s,l=c.e,u=d+4,h=new I("0.5");if(o!==1||!e||!e[0])return new I(!o||o<0&&(!e||e[0])?NaN:e?c:1/0);if(o=Math.sqrt(+X(c)),o==0||o==1/0?(b=We(e),(b.length+l)%2==0&&(b+="0"),o=Math.sqrt(+b),l=Ve((l+1)/2)-(l<0||l%2),o==1/0?b="5e"+l:(b=o.toExponential(),b=b.slice(0,b.indexOf("e")+1)+l),_=new I(b)):_=new I(o+""),_.c[0]){for(l=_.e,o=l+u,o<3&&(o=0);;)if(S=_,_=h.times(S.plus(r(c,S,u,1))),We(S.c).slice(0,o)===(b=We(_.c)).slice(0,o))if(_.e<l&&--o,b=b.slice(o-3,o+1),b=="9999"||!P&&b=="4999"){if(!P&&($(S,S.e+d+2,0),S.times(S).eq(c))){_=S;break}u+=4,o+=4,P=1}else{(!+b||!+b.slice(1)&&b.charAt(0)=="5")&&($(_,_.e+d+2,1),m=!_.times(_).eq(c));break}}return $(_,_.e+d+1,v,m)},t.toExponential=function(m,b){return m!=null&&(ne(m,0,Fe),m++),F(this,m,b,1)},t.toFixed=function(m,b){return m!=null&&(ne(m,0,Fe),m=m+this.e+1),F(this,m,b)},t.toFormat=function(m,b,_){var P,S=this;if(_==null)m!=null&&b&&typeof b=="object"?(_=b,b=null):m&&typeof m=="object"?(_=m,m=b=null):_=D;else if(typeof _!="object")throw Error($e+"Argument not an object: "+_);if(P=S.toFixed(m,b),S.c){var c,e=P.split("."),o=+_.groupSize,l=+_.secondaryGroupSize,u=_.groupSeparator||"",h=e[0],g=e[1],k=S.s<0,p=k?h.slice(1):h,a=p.length;if(l&&(c=o,o=l,l=c,a-=c),o>0&&a>0){for(c=a%o||o,h=p.substr(0,c);c<a;c+=o)h+=u+p.substr(c,o);l>0&&(h+=u+p.slice(c)),k&&(h="-"+h)}P=g?h+(_.decimalSeparator||"")+((l=+_.fractionGroupSize)?g.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(_.fractionGroupSeparator||"")):g):h}return(_.prefix||"")+P+(_.suffix||"")},t.toFraction=function(m){var b,_,P,S,c,e,o,l,u,h,g,k,p=this,a=p.c;if(m!=null&&(o=new I(m),!o.isInteger()&&(o.c||o.s!==1)||o.lt(f)))throw Error($e+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+X(o));if(!a)return new I(p);for(b=new I(f),u=_=new I(f),P=l=new I(f),k=We(a),c=b.e=k.length-p.e-1,b.c[0]=ai[(e=c%G)<0?G+e:e],m=!m||o.comparedTo(b)>0?c>0?b:u:o,e=x,x=1/0,o=new I(k),l.c[0]=0;h=r(o,b,0,1),S=_.plus(h.times(P)),S.comparedTo(m)!=1;)_=P,P=S,u=l.plus(h.times(S=u)),l=S,b=o.minus(h.times(S=b)),o=S;return S=r(m.minus(_),P,0,1),l=l.plus(S.times(u)),_=_.plus(S.times(P)),l.s=u.s=p.s,c=c*2,g=r(u,P,c,v).minus(p).abs().comparedTo(r(l,_,c,v).minus(p).abs())<1?[u,P]:[l,_],x=e,g},t.toNumber=function(){return+X(this)},t.toPrecision=function(m,b){return m!=null&&ne(m,1,Fe),F(this,m,b,2)},t.toString=function(m){var b,_=this,P=_.s,S=_.e;return S===null?P?(b="Infinity",P<0&&(b="-"+b)):b="NaN":(m==null?b=S<=M||S>=w?At(We(_.c),S):rt(We(_.c),S,"0"):m===10&&j?(_=$(new I(_),d+S+1,v),b=rt(We(_.c),_.e,"0")):(ne(m,2,Z.length,"Base"),b=n(rt(We(_.c),S,"0"),10,m,P,!0)),P<0&&_.c[0]&&(b="-"+b)),b},t.valueOf=t.toJSON=function(){return X(this)},t._isBigNumber=!0,t[Symbol.toStringTag]="BigNumber",t[Symbol.for("nodejs.util.inspect.custom")]=t.valueOf,i!=null&&I.set(i),I}function Ve(i){var r=i|0;return i>0||i===r?r:r-1}function We(i){for(var r,n,s=1,t=i.length,f=i[0]+"";s<t;){for(r=i[s++]+"",n=G-r.length;n--;r="0"+r);f+=r}for(t=f.length;f.charCodeAt(--t)===48;);return f.slice(0,t+1||1)}function ct(i,r){var n,s,t=i.c,f=r.c,d=i.s,v=r.s,M=i.e,w=r.e;if(!d||!v)return null;if(n=t&&!t[0],s=f&&!f[0],n||s)return n?s?0:-v:d;if(d!=v)return d;if(n=d<0,s=M==w,!t||!f)return s?0:!t^n?1:-1;if(!s)return M>w^n?1:-1;for(v=(M=t.length)<(w=f.length)?M:w,d=0;d<v;d++)if(t[d]!=f[d])return t[d]>f[d]^n?1:-1;return M==w?0:M>w^n?1:-1}function ne(i,r,n,s){if(i<r||i>n||i!==Ge(i))throw Error($e+(s||"Argument")+(typeof i=="number"?i<r||i>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(i))}function kt(i){var r=i.c.length-1;return Ve(i.e/G)==r&&i.c[r]%2!=0}function At(i,r){return(i.length>1?i.charAt(0)+"."+i.slice(1):i)+(r<0?"e":"e+")+r}function rt(i,r,n){var s,t;if(r<0){for(t=n+".";++r;t+=n);i=t+i}else if(s=i.length,++r>s){for(t=n,r-=s;--r;t+=n);i+=t}else r<s&&(i=i.slice(0,r)+"."+i.slice(r));return i}var Nr=qi(),Ye=Nr;var Je=require("@suilend/sdk"),dt=require("@suilend/sui-fe");var Ui=ri(require("crypto")),Ct=new Uint8Array(256),St=Ct.length;function li(){return St>Ct.length-16&&(Ui.default.randomFillSync(Ct),St=0),Ct.slice(St,St+=16)}var qe=[];for(let i=0;i<256;++i)qe.push((i+256).toString(16).slice(1));function Zi(i,r=0){return qe[i[r+0]]+qe[i[r+1]]+qe[i[r+2]]+qe[i[r+3]]+"-"+qe[i[r+4]]+qe[i[r+5]]+"-"+qe[i[r+6]]+qe[i[r+7]]+"-"+qe[i[r+8]]+qe[i[r+9]]+"-"+qe[i[r+10]]+qe[i[r+11]]+qe[i[r+12]]+qe[i[r+13]]+qe[i[r+14]]+qe[i[r+15]]}var ji=ri(require("crypto")),fi={randomUUID:ji.default.randomUUID};function Rr(i,r,n){if(fi.randomUUID&&!r&&!i)return fi.randomUUID();i=i||{};let s=i.random||(i.rng||li)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,r){n=n||0;for(let t=0;t<16;++t)r[n+t]=s[t];return r}return Zi(s)}var Pt=Rr;var zi=require("@cetusprotocol/common-sdk"),ui=10n;function $i(i){return i.depositedAmount.eq(0)?new Ye(0):i.borrowedAmount.div(i.depositedAmount).times(100)}function hi(i){let r=$i(i);if(!r.gt(100))return(0,Je.linearlyInterpolate)(i.config.interestRate,"utilPercent","aprPercent",r)}function Ki(i){let r=$i(i),n=hi(i);if(!(n===void 0||r.gt(100)))return new Ye(r.div(100)).times(n.div(100)).times(1-i.config.spreadFeeBps/1e4).times(100)}function Hi(i,r,n,s){let{apiUrl:t}=(0,zi.getPackagerConfigs)(s.sdkOptions.suilend);i===Je.Side.DEPOSIT&&([dt.NORMALIZED_flSUI_COINTYPE,dt.NORMALIZED_jugSUI_COINTYPE].includes(r.coinType)&&n.push({stats:{id:Pt(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${t}/partners/LiqAg.png`,perDay:new Ye(.036),side:Je.Side.DEPOSIT},obligationClaims:{}}),r.coinType===dt.NORMALIZED_LBTC_COINTYPE&&n.push({stats:{id:Pt(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${t}/partners/Lombard Lux.png`,perDay:new Ye(0),side:Je.Side.DEPOSIT},obligationClaims:{}}))}function Wi(i,r,n){return{...i,depositedAmount:r===Je.Side.DEPOSIT?Ye.max(i.depositedAmount.plus(n),0):i.depositedAmount,borrowedAmount:r===Je.Side.BORROW?Ye.max(i.borrowedAmount.plus(n),0):i.borrowedAmount}}function Gi(i,r,n){let s=i===Je.Side.DEPOSIT?r.depositedAmount:r.borrowedAmount,t=i===Je.Side.DEPOSIT?n.depositedAmount:n.borrowedAmount,f=t.eq(0)?new Ye(-1):s.div(t);return{multiplier:f,isValid:!f.eq(-1)}}function Vi(i,r,n,s){let t=i.map(d=>({...d,stats:{...d.stats,perDay:s?d.stats.perDay.times(n):void 0}})),f=r.map(d=>({...d,stats:{...d.stats,aprPercent:s?d.stats.aprPercent.times(n):void 0}}));return{newPerDayRewards:t,newAprRewards:f}}function Xi(i,r){if(!ui)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(r<0n){let n=10n**(ui- -r);return i*n}return i/10n**(r+ui)}var Ze=require("@cetusprotocol/common-sdk"),Yi=require("@mysten/sui/utils"),xt=class{constructor(r){this.getSuiLendCoinInfo=(r,n)=>{let{allLendingMarketData:s,lstAprPercentMap:t}=this.lendingMarketCache??{};if(!s||!t)throw new Error("lendingMarketCache is not initialized");let f=Object.values(s??{})[0],d=f.lendingMarket.reserves.find(X=>X.coinType===r);if(!d)throw new Error("reserve not found");let v=this.obligationsCache?.[f.lendingMarket.id],M="borrow",w=v.rewardMap[d.token.coinType]?.[M]??[],A=(0,re.getFilteredRewards)(w);Hi(M,d,A,this.sdk);let x=(0,re.getStakingYieldAprPercent)(M,d.coinType,t),C=M===re.Side.DEPOSIT?d.depositAprPercent:d.borrowAprPercent,L=C,B=Wi(d,M,n);L=M===re.Side.DEPOSIT?Ki(B):hi(B);let{multiplier:D,isValid:Z}=Gi(M,d,B),j=(0,re.getDedupedPerDayRewards)(A),I=(0,re.getDedupedAprRewards)(A),{newPerDayRewards:F,newAprRewards:q}=Vi(j,I,D,Z),ee=(0,re.getTotalAprPercent)(M,C,A,x),$=L===void 0||q.some(X=>X.stats.aprPercent===void 0)?void 0:(0,re.getTotalAprPercent)(M,L,q,x);return{borrowLimit:d.config.borrowLimit.toString(),borrowedAmount:d.borrowedAmount.toString(),remainingBorrowLimit:(0,Ze.d)(d.config.borrowLimit.toString()).sub((0,Ze.d)(d.borrowedAmount.toString())).toString(),depositAprPercent:d.depositAprPercent.toString(),totalAprPercent:ee.toString(),borrowInterest:C.toString(),stakingYieldAprPercent:x?.toString(),rewardAprPercent:I[0]?.stats.aprPercent?.toString()}};this.createObligation=async r=>{let{lendingMarketId:n,lendingMarketType:s}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(n,s)).createObligation(r)};this.refreshReservePrices=async(r,n,s)=>{let{lendingMarketId:t,lendingMarketType:f}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),d=`${t}_${f}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let v=await this.suilendClientCache[d].pythClient.getPriceFeedObjectId(n);console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:322 ~ SuiLendModule ~ priceInfoObjectId:",v),this.suilendClientCache[d].pythConnection.getLatestPriceFeeds,this.suilendClientCache[d].refreshReservePrices(r,v,s)};this.getLatestPriceFeeds=async r=>{let{lendingMarketId:n,lendingMarketType:s}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),t=`${n}_${s}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let f=Array.from(new Set(r.map(M=>(0,Yi.toHEX)(new Uint8Array(M.priceIdentifier.bytes))))),d=await this.suilendClientCache[t].pythConnection.getLatestPriceFeeds(f),v={};return d?.forEach((M,w)=>{let A=M.getPriceUnchecked(),x=r[w];if(A){let{price:C,expo:L}=A,B=(0,Ze.d)(C).mul((0,Ze.d)(10).pow((0,Ze.d)(L))).toString(),D={coin_type:x.coinType.name,price:B,oracle_price:0n,last_update_time:A.publishTime};D.oracle_price=Xi(BigInt(C),BigInt(L)),v[x.coinType.name]=D,this.sdk.updateCache(`getLatestPrice_${D.coin_type}`,D)}}),v};this.getSuiLendReserveInfo=async(r,n)=>{let{lendingMarketId:s}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),{allLendingMarketData:t}=await this.getLendingMarketData(),f=t[s].reserveMap[r],d=t[s].reserveMap[n],v=t[s].refreshedRawReserves.filter(M=>M.coinType.name==(0,Ze.removeHexPrefix)(r)||M.coinType.name==(0,Ze.removeHexPrefix)(n));return{baseReserveArrayIndex:f.arrayIndex.toString(),quoteReserveArrayIndex:d.arrayIndex.toString(),reserve:v}};this.sdk=r}async getSuilendClient(r,n){let s=`${r}_${n}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[s]||(this.suilendClientCache[s]=await Qi.SuilendClient.initialize(r,n,this.sdk.FullClient,!0)),this.suilendClientCache[s]}async getLendingMarketData(r=!1){if(!r&&this.lendingMarketCache)return this.lendingMarketCache;let n=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend)?.lendingMarket||[];if(!n.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[s,t]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(n.map(async d=>{let v=await this.getSuilendClient(d.id,d.type),{lendingMarket:M,coinMetadataMap:w,refreshedRawReserves:A,reserveMap:x,reserveCoinTypes:C,reserveCoinMetadataMap:L,rewardCoinTypes:B,activeRewardCoinTypes:D,rewardCoinMetadataMap:Z}=await(0,re.initializeSuilend)(this.sdk.FullClient,v),{rewardPriceMap:j}=await(0,re.initializeSuilendRewards)(x,D);return[d.id,{suilendClient:v,lendingMarket:M,coinMetadataMap:w,refreshedRawReserves:A,reserveMap:x,reserveCoinTypes:C,reserveCoinMetadataMap:L,rewardPriceMap:j,rewardCoinTypes:B,activeRewardCoinTypes:D,rewardCoinMetadataMap:Z}]}))))(),(async()=>{try{let f=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.apiUrl}/springsui/apy`),d=await f.json();if(f?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(d).map(([v,M])=>[v,new Ye(M)]))}catch(f){return console.error(f),{}}})()]);return this.lendingMarketCache={allLendingMarketData:s,lstAprPercentMap:t},this.lendingMarketCache}catch(s){throw console.log("\u{1F680} getLendingMarketData error:",s),s}}async getInitializeObligations(r,n=!1){if(!n&&this.obligationsCache)return this.obligationsCache;r||(r=await this.getLendingMarketData());let s={};for(let t of Object.values(r.allLendingMarketData)){let{obligationOwnerCaps:f,obligations:d}=await(0,re.initializeObligations)(this.sdk.FullClient,t.suilendClient,t.refreshedRawReserves,t.reserveMap,this.sdk.senderAddress),v=(0,re.formatRewards)(t.reserveMap,t.rewardCoinMetadataMap,t.rewardPriceMap,d);s[t.lendingMarket.id]={obligationOwnerCaps:f,obligations:d,rewardMap:v}}return this.obligationsCache=s,this.obligationsCache}async getSuiLendUserData(r,n=!1){let{lstAprPercentMap:s}=this.lendingMarketCache??{},t=this.obligationsCache??{},{lendingMarketId:f}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),d=t[f];if(!d)throw new Error(`No user data found for lending market: ${f}`);if(r){let v=d.obligations.find(w=>w.id===r);if(!v)throw new Error(`Obligation not found: ${r}`);let M=(0,re.getNetAprPercent)(v,d.rewardMap,s??{});return{obligation:v,netAprPercent:M,deposits:v.deposits,borrowedAmount:v.borrowedAmount,depositedAmount:v.depositedAmount,netValueUsd:v.netValueUsd,rewardMap:d.rewardMap}}}priceCheck(r,n=60){let s=Math.floor(Date.now()/1e3);if(!(Math.abs(s-r.last_update_time)>n))return r}};var N=require("@cetusprotocol/common-sdk");var pt=9e15,ht=1e9,ci="0123456789abcdef",Ot="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Nt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",di={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-pt,maxE:pt,crypto:!1},ir,nt,H=!0,Tt="[DecimalError] ",ut=Tt+"Invalid argument: ",rr=Tt+"Precision limit exceeded",nr=Tt+"crypto unavailable",or="[object Decimal]",je=Math.floor,Be=Math.pow,Tr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Dr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Er=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,sr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Qe=1e7,K=7,Br=9007199254740991,Fr=Ot.length-1,pi=Nt.length-1,O={toStringTag:or};O.absoluteValue=O.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),z(i)};O.ceil=function(){return z(new this.constructor(this),this.e+1,2)};O.clampedTo=O.clamp=function(i,r){var n,s=this,t=s.constructor;if(i=new t(i),r=new t(r),!i.s||!r.s)return new t(NaN);if(i.gt(r))throw Error(ut+r);return n=s.cmp(i),n<0?i:s.cmp(r)>0?r:new t(s)};O.comparedTo=O.cmp=function(i){var r,n,s,t,f=this,d=f.d,v=(i=new f.constructor(i)).d,M=f.s,w=i.s;if(!d||!v)return!M||!w?NaN:M!==w?M:d===v?0:!d^M<0?1:-1;if(!d[0]||!v[0])return d[0]?M:v[0]?-w:0;if(M!==w)return M;if(f.e!==i.e)return f.e>i.e^M<0?1:-1;for(s=d.length,t=v.length,r=0,n=s<t?s:t;r<n;++r)if(d[r]!==v[r])return d[r]>v[r]^M<0?1:-1;return s===t?0:s>t^M<0?1:-1};O.cosine=O.cos=function(){var i,r,n=this,s=n.constructor;return n.d?n.d[0]?(i=s.precision,r=s.rounding,s.precision=i+Math.max(n.e,n.sd())+K,s.rounding=1,n=qr(s,hr(s,n)),s.precision=i,s.rounding=r,z(nt==2||nt==3?n.neg():n,i,r,!0)):new s(1):new s(NaN)};O.cubeRoot=O.cbrt=function(){var i,r,n,s,t,f,d,v,M,w,A=this,x=A.constructor;if(!A.isFinite()||A.isZero())return new x(A);for(H=!1,f=A.s*Be(A.s*A,1/3),!f||Math.abs(f)==1/0?(n=Ue(A.d),i=A.e,(f=(i-n.length+1)%3)&&(n+=f==1||f==-2?"0":"00"),f=Be(n,1/3),i=je((i+1)/3)-(i%3==(i<0?-1:2)),f==1/0?n="5e"+i:(n=f.toExponential(),n=n.slice(0,n.indexOf("e")+1)+i),s=new x(n),s.s=A.s):s=new x(f.toString()),d=(i=x.precision)+3;;)if(v=s,M=v.times(v).times(v),w=M.plus(A),s=ie(w.plus(A).times(v),w.plus(M),d+2,1),Ue(v.d).slice(0,d)===(n=Ue(s.d)).slice(0,d))if(n=n.slice(d-3,d+1),n=="9999"||!t&&n=="4999"){if(!t&&(z(v,i+1,0),v.times(v).times(v).eq(A))){s=v;break}d+=4,t=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(z(s,i+1,1),r=!s.times(s).times(s).eq(A));break}return H=!0,z(s,i,x.rounding,r)};O.decimalPlaces=O.dp=function(){var i,r=this.d,n=NaN;if(r){if(i=r.length-1,n=(i-je(this.e/K))*K,i=r[i],i)for(;i%10==0;i/=10)n--;n<0&&(n=0)}return n};O.dividedBy=O.div=function(i){return ie(this,new this.constructor(i))};O.dividedToIntegerBy=O.divToInt=function(i){var r=this,n=r.constructor;return z(ie(r,new n(i),0,1,1),n.precision,n.rounding)};O.equals=O.eq=function(i){return this.cmp(i)===0};O.floor=function(){return z(new this.constructor(this),this.e+1,3)};O.greaterThan=O.gt=function(i){return this.cmp(i)>0};O.greaterThanOrEqualTo=O.gte=function(i){var r=this.cmp(i);return r==1||r===0};O.hyperbolicCosine=O.cosh=function(){var i,r,n,s,t,f=this,d=f.constructor,v=new d(1);if(!f.isFinite())return new d(f.s?1/0:NaN);if(f.isZero())return v;n=d.precision,s=d.rounding,d.precision=n+Math.max(f.e,f.sd())+4,d.rounding=1,t=f.d.length,t<32?(i=Math.ceil(t/3),r=(1/Et(4,i)).toString()):(i=16,r="2.3283064365386962890625e-10"),f=gt(d,1,f.times(r),new d(1),!0);for(var M,w=i,A=new d(8);w--;)M=f.times(f),f=v.minus(M.times(A.minus(M.times(A))));return z(f,d.precision=n,d.rounding=s,!0)};O.hyperbolicSine=O.sinh=function(){var i,r,n,s,t=this,f=t.constructor;if(!t.isFinite()||t.isZero())return new f(t);if(r=f.precision,n=f.rounding,f.precision=r+Math.max(t.e,t.sd())+4,f.rounding=1,s=t.d.length,s<3)t=gt(f,2,t,t,!0);else{i=1.4*Math.sqrt(s),i=i>16?16:i|0,t=t.times(1/Et(5,i)),t=gt(f,2,t,t,!0);for(var d,v=new f(5),M=new f(16),w=new f(20);i--;)d=t.times(t),t=t.times(v.plus(d.times(M.times(d).plus(w))))}return f.precision=r,f.rounding=n,z(t,r,n,!0)};O.hyperbolicTangent=O.tanh=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+7,s.rounding=1,ie(n.sinh(),n.cosh(),s.precision=i,s.rounding=r)):new s(n.s)};O.inverseCosine=O.acos=function(){var i=this,r=i.constructor,n=i.abs().cmp(1),s=r.precision,t=r.rounding;return n!==-1?n===0?i.isNeg()?et(r,s,t):new r(0):new r(NaN):i.isZero()?et(r,s+4,t).times(.5):(r.precision=s+6,r.rounding=1,i=new r(1).minus(i).div(i.plus(1)).sqrt().atan(),r.precision=s,r.rounding=t,i.times(2))};O.inverseHyperbolicCosine=O.acosh=function(){var i,r,n=this,s=n.constructor;return n.lte(1)?new s(n.eq(1)?0:NaN):n.isFinite()?(i=s.precision,r=s.rounding,s.precision=i+Math.max(Math.abs(n.e),n.sd())+4,s.rounding=1,H=!1,n=n.times(n).minus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln()):new s(n)};O.inverseHyperbolicSine=O.asinh=function(){var i,r,n=this,s=n.constructor;return!n.isFinite()||n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+2*Math.max(Math.abs(n.e),n.sd())+6,s.rounding=1,H=!1,n=n.times(n).plus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln())};O.inverseHyperbolicTangent=O.atanh=function(){var i,r,n,s,t=this,f=t.constructor;return t.isFinite()?t.e>=0?new f(t.abs().eq(1)?t.s/0:t.isZero()?t:NaN):(i=f.precision,r=f.rounding,s=t.sd(),Math.max(s,i)<2*-t.e-1?z(new f(t),i,r,!0):(f.precision=n=s-t.e,t=ie(t.plus(1),new f(1).minus(t),n+i,1),f.precision=i+4,f.rounding=1,t=t.ln(),f.precision=i,f.rounding=r,t.times(.5))):new f(NaN)};O.inverseSine=O.asin=function(){var i,r,n,s,t=this,f=t.constructor;return t.isZero()?new f(t):(r=t.abs().cmp(1),n=f.precision,s=f.rounding,r!==-1?r===0?(i=et(f,n+4,s).times(.5),i.s=t.s,i):new f(NaN):(f.precision=n+6,f.rounding=1,t=t.div(new f(1).minus(t.times(t)).sqrt().plus(1)).atan(),f.precision=n,f.rounding=s,t.times(2)))};O.inverseTangent=O.atan=function(){var i,r,n,s,t,f,d,v,M,w=this,A=w.constructor,x=A.precision,C=A.rounding;if(w.isFinite()){if(w.isZero())return new A(w);if(w.abs().eq(1)&&x+4<=pi)return d=et(A,x+4,C).times(.25),d.s=w.s,d}else{if(!w.s)return new A(NaN);if(x+4<=pi)return d=et(A,x+4,C).times(.5),d.s=w.s,d}for(A.precision=v=x+10,A.rounding=1,n=Math.min(28,v/K+2|0),i=n;i;--i)w=w.div(w.times(w).plus(1).sqrt().plus(1));for(H=!1,r=Math.ceil(v/K),s=1,M=w.times(w),d=new A(w),t=w;i!==-1;)if(t=t.times(M),f=d.minus(t.div(s+=2)),t=t.times(M),d=f.plus(t.div(s+=2)),d.d[r]!==void 0)for(i=r;d.d[i]===f.d[i]&&i--;);return n&&(d=d.times(2<<n-1)),H=!0,z(d,A.precision=x,A.rounding=C,!0)};O.isFinite=function(){return!!this.d};O.isInteger=O.isInt=function(){return!!this.d&&je(this.e/K)>this.d.length-2};O.isNaN=function(){return!this.s};O.isNegative=O.isNeg=function(){return this.s<0};O.isPositive=O.isPos=function(){return this.s>0};O.isZero=function(){return!!this.d&&this.d[0]===0};O.lessThan=O.lt=function(i){return this.cmp(i)<0};O.lessThanOrEqualTo=O.lte=function(i){return this.cmp(i)<1};O.logarithm=O.log=function(i){var r,n,s,t,f,d,v,M,w=this,A=w.constructor,x=A.precision,C=A.rounding,L=5;if(i==null)i=new A(10),r=!0;else{if(i=new A(i),n=i.d,i.s<0||!n||!n[0]||i.eq(1))return new A(NaN);r=i.eq(10)}if(n=w.d,w.s<0||!n||!n[0]||w.eq(1))return new A(n&&!n[0]?-1/0:w.s!=1?NaN:n?0:1/0);if(r)if(n.length>1)f=!0;else{for(t=n[0];t%10===0;)t/=10;f=t!==1}if(H=!1,v=x+L,d=ft(w,v),s=r?Rt(A,v+10):ft(i,v),M=ie(d,s,v,1),vt(M.d,t=x,C))do if(v+=10,d=ft(w,v),s=r?Rt(A,v+10):ft(i,v),M=ie(d,s,v,1),!f){+Ue(M.d).slice(t+1,t+15)+1==1e14&&(M=z(M,x+1,0));break}while(vt(M.d,t+=10,C));return H=!0,z(M,x,C)};O.minus=O.sub=function(i){var r,n,s,t,f,d,v,M,w,A,x,C,L=this,B=L.constructor;if(i=new B(i),!L.d||!i.d)return!L.s||!i.s?i=new B(NaN):L.d?i.s=-i.s:i=new B(i.d||L.s!==i.s?L:NaN),i;if(L.s!=i.s)return i.s=-i.s,L.plus(i);if(w=L.d,C=i.d,v=B.precision,M=B.rounding,!w[0]||!C[0]){if(C[0])i.s=-i.s;else if(w[0])i=new B(L);else return new B(M===3?-0:0);return H?z(i,v,M):i}if(n=je(i.e/K),A=je(L.e/K),w=w.slice(),f=A-n,f){for(x=f<0,x?(r=w,f=-f,d=C.length):(r=C,n=A,d=w.length),s=Math.max(Math.ceil(v/K),d)+2,f>s&&(f=s,r.length=1),r.reverse(),s=f;s--;)r.push(0);r.reverse()}else{for(s=w.length,d=C.length,x=s<d,x&&(d=s),s=0;s<d;s++)if(w[s]!=C[s]){x=w[s]<C[s];break}f=0}for(x&&(r=w,w=C,C=r,i.s=-i.s),d=w.length,s=C.length-d;s>0;--s)w[d++]=0;for(s=C.length;s>f;){if(w[--s]<C[s]){for(t=s;t&&w[--t]===0;)w[t]=Qe-1;--w[t],w[s]+=Qe}w[s]-=C[s]}for(;w[--d]===0;)w.pop();for(;w[0]===0;w.shift())--n;return w[0]?(i.d=w,i.e=Dt(w,n),H?z(i,v,M):i):new B(M===3?-0:0)};O.modulo=O.mod=function(i){var r,n=this,s=n.constructor;return i=new s(i),!n.d||!i.s||i.d&&!i.d[0]?new s(NaN):!i.d||n.d&&!n.d[0]?z(new s(n),s.precision,s.rounding):(H=!1,s.modulo==9?(r=ie(n,i.abs(),0,3,1),r.s*=i.s):r=ie(n,i,0,s.modulo,1),r=r.times(i),H=!0,n.minus(r))};O.naturalExponential=O.exp=function(){return gi(this)};O.naturalLogarithm=O.ln=function(){return ft(this)};O.negated=O.neg=function(){var i=new this.constructor(this);return i.s=-i.s,z(i)};O.plus=O.add=function(i){var r,n,s,t,f,d,v,M,w,A,x=this,C=x.constructor;if(i=new C(i),!x.d||!i.d)return!x.s||!i.s?i=new C(NaN):x.d||(i=new C(i.d||x.s===i.s?x:NaN)),i;if(x.s!=i.s)return i.s=-i.s,x.minus(i);if(w=x.d,A=i.d,v=C.precision,M=C.rounding,!w[0]||!A[0])return A[0]||(i=new C(x)),H?z(i,v,M):i;if(f=je(x.e/K),s=je(i.e/K),w=w.slice(),t=f-s,t){for(t<0?(n=w,t=-t,d=A.length):(n=A,s=f,d=w.length),f=Math.ceil(v/K),d=f>d?f+1:d+1,t>d&&(t=d,n.length=1),n.reverse();t--;)n.push(0);n.reverse()}for(d=w.length,t=A.length,d-t<0&&(t=d,n=A,A=w,w=n),r=0;t;)r=(w[--t]=w[t]+A[t]+r)/Qe|0,w[t]%=Qe;for(r&&(w.unshift(r),++s),d=w.length;w[--d]==0;)w.pop();return i.d=w,i.e=Dt(w,s),H?z(i,v,M):i};O.precision=O.sd=function(i){var r,n=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(ut+i);return n.d?(r=ar(n.d),i&&n.e+1>r&&(r=n.e+1)):r=NaN,r};O.round=function(){var i=this,r=i.constructor;return z(new r(i),i.e+1,r.rounding)};O.sine=O.sin=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+Math.max(n.e,n.sd())+K,s.rounding=1,n=Zr(s,hr(s,n)),s.precision=i,s.rounding=r,z(nt>2?n.neg():n,i,r,!0)):new s(NaN)};O.squareRoot=O.sqrt=function(){var i,r,n,s,t,f,d=this,v=d.d,M=d.e,w=d.s,A=d.constructor;if(w!==1||!v||!v[0])return new A(!w||w<0&&(!v||v[0])?NaN:v?d:1/0);for(H=!1,w=Math.sqrt(+d),w==0||w==1/0?(r=Ue(v),(r.length+M)%2==0&&(r+="0"),w=Math.sqrt(r),M=je((M+1)/2)-(M<0||M%2),w==1/0?r="5e"+M:(r=w.toExponential(),r=r.slice(0,r.indexOf("e")+1)+M),s=new A(r)):s=new A(w.toString()),n=(M=A.precision)+3;;)if(f=s,s=f.plus(ie(d,f,n+2,1)).times(.5),Ue(f.d).slice(0,n)===(r=Ue(s.d)).slice(0,n))if(r=r.slice(n-3,n+1),r=="9999"||!t&&r=="4999"){if(!t&&(z(f,M+1,0),f.times(f).eq(d))){s=f;break}n+=4,t=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(z(s,M+1,1),i=!s.times(s).eq(d));break}return H=!0,z(s,M,A.rounding,i)};O.tangent=O.tan=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+10,s.rounding=1,n=n.sin(),n.s=1,n=ie(n,new s(1).minus(n.times(n)).sqrt(),i+10,0),s.precision=i,s.rounding=r,z(nt==2||nt==4?n.neg():n,i,r,!0)):new s(NaN)};O.times=O.mul=function(i){var r,n,s,t,f,d,v,M,w,A=this,x=A.constructor,C=A.d,L=(i=new x(i)).d;if(i.s*=A.s,!C||!C[0]||!L||!L[0])return new x(!i.s||C&&!C[0]&&!L||L&&!L[0]&&!C?NaN:!C||!L?i.s/0:i.s*0);for(n=je(A.e/K)+je(i.e/K),M=C.length,w=L.length,M<w&&(f=C,C=L,L=f,d=M,M=w,w=d),f=[],d=M+w,s=d;s--;)f.push(0);for(s=w;--s>=0;){for(r=0,t=M+s;t>s;)v=f[t]+L[s]*C[t-s-1]+r,f[t--]=v%Qe|0,r=v/Qe|0;f[t]=(f[t]+r)%Qe|0}for(;!f[--d];)f.pop();return r?++n:f.shift(),i.d=f,i.e=Dt(f,n),H?z(i,x.precision,x.rounding):i};O.toBinary=function(i,r){return mi(this,2,i,r)};O.toDecimalPlaces=O.toDP=function(i,r){var n=this,s=n.constructor;return n=new s(n),i===void 0?n:(Ke(i,0,ht),r===void 0?r=s.rounding:Ke(r,0,8),z(n,i+n.e+1,r))};O.toExponential=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=tt(s,!0):(Ke(i,0,ht),r===void 0?r=t.rounding:Ke(r,0,8),s=z(new t(s),i+1,r),n=tt(s,!0,i+1)),s.isNeg()&&!s.isZero()?"-"+n:n};O.toFixed=function(i,r){var n,s,t=this,f=t.constructor;return i===void 0?n=tt(t):(Ke(i,0,ht),r===void 0?r=f.rounding:Ke(r,0,8),s=z(new f(t),i+t.e+1,r),n=tt(s,!1,i+s.e+1)),t.isNeg()&&!t.isZero()?"-"+n:n};O.toFraction=function(i){var r,n,s,t,f,d,v,M,w,A,x,C,L=this,B=L.d,D=L.constructor;if(!B)return new D(L);if(w=n=new D(1),s=M=new D(0),r=new D(s),f=r.e=ar(B)-L.e-1,d=f%K,r.d[0]=Be(10,d<0?K+d:d),i==null)i=f>0?r:w;else{if(v=new D(i),!v.isInt()||v.lt(w))throw Error(ut+v);i=v.gt(r)?f>0?r:w:v}for(H=!1,v=new D(Ue(B)),A=D.precision,D.precision=f=B.length*K*2;x=ie(v,r,0,1,1),t=n.plus(x.times(s)),t.cmp(i)!=1;)n=s,s=t,t=w,w=M.plus(x.times(t)),M=t,t=r,r=v.minus(x.times(t)),v=t;return t=ie(i.minus(n),s,0,1,1),M=M.plus(t.times(w)),n=n.plus(t.times(s)),M.s=w.s=L.s,C=ie(w,s,f,1).minus(L).abs().cmp(ie(M,n,f,1).minus(L).abs())<1?[w,s]:[M,n],D.precision=A,H=!0,C};O.toHexadecimal=O.toHex=function(i,r){return mi(this,16,i,r)};O.toNearest=function(i,r){var n=this,s=n.constructor;if(n=new s(n),i==null){if(!n.d)return n;i=new s(1),r=s.rounding}else{if(i=new s(i),r===void 0?r=s.rounding:Ke(r,0,8),!n.d)return i.s?n:i;if(!i.d)return i.s&&(i.s=n.s),i}return i.d[0]?(H=!1,n=ie(n,i,0,r,1).times(i),H=!0,z(n)):(i.s=n.s,n=i),n};O.toNumber=function(){return+this};O.toOctal=function(i,r){return mi(this,8,i,r)};O.toPower=O.pow=function(i){var r,n,s,t,f,d,v=this,M=v.constructor,w=+(i=new M(i));if(!v.d||!i.d||!v.d[0]||!i.d[0])return new M(Be(+v,w));if(v=new M(v),v.eq(1))return v;if(s=M.precision,f=M.rounding,i.eq(1))return z(v,s,f);if(r=je(i.e/K),r>=i.d.length-1&&(n=w<0?-w:w)<=Br)return t=lr(M,v,n,s),i.s<0?new M(1).div(t):z(t,s,f);if(d=v.s,d<0){if(r<i.d.length-1)return new M(NaN);if((i.d[r]&1)==0&&(d=1),v.e==0&&v.d[0]==1&&v.d.length==1)return v.s=d,v}return n=Be(+v,w),r=n==0||!isFinite(n)?je(w*(Math.log("0."+Ue(v.d))/Math.LN10+v.e+1)):new M(n+"").e,r>M.maxE+1||r<M.minE-1?new M(r>0?d/0:0):(H=!1,M.rounding=v.s=1,n=Math.min(12,(r+"").length),t=gi(i.times(ft(v,s+n)),s),t.d&&(t=z(t,s+5,1),vt(t.d,s,f)&&(r=s+10,t=z(gi(i.times(ft(v,r+n)),r),r+5,1),+Ue(t.d).slice(s+1,s+15)+1==1e14&&(t=z(t,s+1,0)))),t.s=d,H=!0,M.rounding=f,z(t,s,f))};O.toPrecision=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=tt(s,s.e<=t.toExpNeg||s.e>=t.toExpPos):(Ke(i,1,ht),r===void 0?r=t.rounding:Ke(r,0,8),s=z(new t(s),i,r),n=tt(s,i<=s.e||s.e<=t.toExpNeg,i)),s.isNeg()&&!s.isZero()?"-"+n:n};O.toSignificantDigits=O.toSD=function(i,r){var n=this,s=n.constructor;return i===void 0?(i=s.precision,r=s.rounding):(Ke(i,1,ht),r===void 0?r=s.rounding:Ke(r,0,8)),z(new s(n),i,r)};O.toString=function(){var i=this,r=i.constructor,n=tt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()&&!i.isZero()?"-"+n:n};O.truncated=O.trunc=function(){return z(new this.constructor(this),this.e+1,1)};O.valueOf=O.toJSON=function(){var i=this,r=i.constructor,n=tt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()?"-"+n:n};function Ue(i){var r,n,s,t=i.length-1,f="",d=i[0];if(t>0){for(f+=d,r=1;r<t;r++)s=i[r]+"",n=K-s.length,n&&(f+=lt(n)),f+=s;d=i[r],s=d+"",n=K-s.length,n&&(f+=lt(n))}else if(d===0)return"0";for(;d%10===0;)d/=10;return f+d}function Ke(i,r,n){if(i!==~~i||i<r||i>n)throw Error(ut+i)}function vt(i,r,n,s){var t,f,d,v;for(f=i[0];f>=10;f/=10)--r;return--r<0?(r+=K,t=0):(t=Math.ceil((r+1)/K),r%=K),f=Be(10,K-r),v=i[t]%f|0,s==null?r<3?(r==0?v=v/100|0:r==1&&(v=v/10|0),d=n<4&&v==99999||n>3&&v==49999||v==5e4||v==0):d=(n<4&&v+1==f||n>3&&v+1==f/2)&&(i[t+1]/f/100|0)==Be(10,r-2)-1||(v==f/2||v==0)&&(i[t+1]/f/100|0)==0:r<4?(r==0?v=v/1e3|0:r==1?v=v/100|0:r==2&&(v=v/10|0),d=(s||n<4)&&v==9999||!s&&n>3&&v==4999):d=((s||n<4)&&v+1==f||!s&&n>3&&v+1==f/2)&&(i[t+1]/f/1e3|0)==Be(10,r-3)-1,d}function Lt(i,r,n){for(var s,t=[0],f,d=0,v=i.length;d<v;){for(f=t.length;f--;)t[f]*=r;for(t[0]+=ci.indexOf(i.charAt(d++)),s=0;s<t.length;s++)t[s]>n-1&&(t[s+1]===void 0&&(t[s+1]=0),t[s+1]+=t[s]/n|0,t[s]%=n)}return t.reverse()}function qr(i,r){var n,s,t;if(r.isZero())return r;s=r.d.length,s<32?(n=Math.ceil(s/3),t=(1/Et(4,n)).toString()):(n=16,t="2.3283064365386962890625e-10"),i.precision+=n,r=gt(i,1,r.times(t),new i(1));for(var f=n;f--;){var d=r.times(r);r=d.times(d).minus(d).times(8).plus(1)}return i.precision-=n,r}var ie=(function(){function i(s,t,f){var d,v=0,M=s.length;for(s=s.slice();M--;)d=s[M]*t+v,s[M]=d%f|0,v=d/f|0;return v&&s.unshift(v),s}function r(s,t,f,d){var v,M;if(f!=d)M=f>d?1:-1;else for(v=M=0;v<f;v++)if(s[v]!=t[v]){M=s[v]>t[v]?1:-1;break}return M}function n(s,t,f,d){for(var v=0;f--;)s[f]-=v,v=s[f]<t[f]?1:0,s[f]=v*d+s[f]-t[f];for(;!s[0]&&s.length>1;)s.shift()}return function(s,t,f,d,v,M){var w,A,x,C,L,B,D,Z,j,I,F,q,ee,$,X,m,b,_,P,S,c=s.constructor,e=s.s==t.s?1:-1,o=s.d,l=t.d;if(!o||!o[0]||!l||!l[0])return new c(!s.s||!t.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?e*0:e/0);for(M?(L=1,A=s.e-t.e):(M=Qe,L=K,A=je(s.e/L)-je(t.e/L)),P=l.length,b=o.length,j=new c(e),I=j.d=[],x=0;l[x]==(o[x]||0);x++);if(l[x]>(o[x]||0)&&A--,f==null?($=f=c.precision,d=c.rounding):v?$=f+(s.e-t.e)+1:$=f,$<0)I.push(1),B=!0;else{if($=$/L+2|0,x=0,P==1){for(C=0,l=l[0],$++;(x<b||C)&&$--;x++)X=C*M+(o[x]||0),I[x]=X/l|0,C=X%l|0;B=C||x<b}else{for(C=M/(l[0]+1)|0,C>1&&(l=i(l,C,M),o=i(o,C,M),P=l.length,b=o.length),m=P,F=o.slice(0,P),q=F.length;q<P;)F[q++]=0;S=l.slice(),S.unshift(0),_=l[0],l[1]>=M/2&&++_;do C=0,w=r(l,F,P,q),w<0?(ee=F[0],P!=q&&(ee=ee*M+(F[1]||0)),C=ee/_|0,C>1?(C>=M&&(C=M-1),D=i(l,C,M),Z=D.length,q=F.length,w=r(D,F,Z,q),w==1&&(C--,n(D,P<Z?S:l,Z,M))):(C==0&&(w=C=1),D=l.slice()),Z=D.length,Z<q&&D.unshift(0),n(F,D,q,M),w==-1&&(q=F.length,w=r(l,F,P,q),w<1&&(C++,n(F,P<q?S:l,q,M))),q=F.length):w===0&&(C++,F=[0]),I[x++]=C,w&&F[0]?F[q++]=o[m]||0:(F=[o[m]],q=1);while((m++<b||F[0]!==void 0)&&$--);B=F[0]!==void 0}I[0]||I.shift()}if(L==1)j.e=A,ir=B;else{for(x=1,C=I[0];C>=10;C/=10)x++;j.e=x+A*L-1,z(j,v?f+j.e+1:f,d,B)}return j}})();function z(i,r,n,s){var t,f,d,v,M,w,A,x,C,L=i.constructor;e:if(r!=null){if(x=i.d,!x)return i;for(t=1,v=x[0];v>=10;v/=10)t++;if(f=r-t,f<0)f+=K,d=r,A=x[C=0],M=A/Be(10,t-d-1)%10|0;else if(C=Math.ceil((f+1)/K),v=x.length,C>=v)if(s){for(;v++<=C;)x.push(0);A=M=0,t=1,f%=K,d=f-K+1}else break e;else{for(A=v=x[C],t=1;v>=10;v/=10)t++;f%=K,d=f-K+t,M=d<0?0:A/Be(10,t-d-1)%10|0}if(s=s||r<0||x[C+1]!==void 0||(d<0?A:A%Be(10,t-d-1)),w=n<4?(M||s)&&(n==0||n==(i.s<0?3:2)):M>5||M==5&&(n==4||s||n==6&&(f>0?d>0?A/Be(10,t-d):0:x[C-1])%10&1||n==(i.s<0?8:7)),r<1||!x[0])return x.length=0,w?(r-=i.e+1,x[0]=Be(10,(K-r%K)%K),i.e=-r||0):x[0]=i.e=0,i;if(f==0?(x.length=C,v=1,C--):(x.length=C+1,v=Be(10,K-f),x[C]=d>0?(A/Be(10,t-d)%Be(10,d)|0)*v:0),w)for(;;)if(C==0){for(f=1,d=x[0];d>=10;d/=10)f++;for(d=x[0]+=v,v=1;d>=10;d/=10)v++;f!=v&&(i.e++,x[0]==Qe&&(x[0]=1));break}else{if(x[C]+=v,x[C]!=Qe)break;x[C--]=0,v=1}for(f=x.length;x[--f]===0;)x.pop()}return H&&(i.e>L.maxE?(i.d=null,i.e=NaN):i.e<L.minE&&(i.e=0,i.d=[0])),i}function tt(i,r,n){if(!i.isFinite())return ur(i);var s,t=i.e,f=Ue(i.d),d=f.length;return r?(n&&(s=n-d)>0?f=f.charAt(0)+"."+f.slice(1)+lt(s):d>1&&(f=f.charAt(0)+"."+f.slice(1)),f=f+(i.e<0?"e":"e+")+i.e):t<0?(f="0."+lt(-t-1)+f,n&&(s=n-d)>0&&(f+=lt(s))):t>=d?(f+=lt(t+1-d),n&&(s=n-t-1)>0&&(f=f+"."+lt(s))):((s=t+1)<d&&(f=f.slice(0,s)+"."+f.slice(s)),n&&(s=n-d)>0&&(t+1===d&&(f+="."),f+=lt(s))),f}function Dt(i,r){var n=i[0];for(r*=K;n>=10;n/=10)r++;return r}function Rt(i,r,n){if(r>Fr)throw H=!0,n&&(i.precision=n),Error(rr);return z(new i(Ot),r,1,!0)}function et(i,r,n){if(r>pi)throw Error(rr);return z(new i(Nt),r,n,!0)}function ar(i){var r=i.length-1,n=r*K+1;if(r=i[r],r){for(;r%10==0;r/=10)n--;for(r=i[0];r>=10;r/=10)n++}return n}function lt(i){for(var r="";i--;)r+="0";return r}function lr(i,r,n,s){var t,f=new i(1),d=Math.ceil(s/K+4);for(H=!1;;){if(n%2&&(f=f.times(r),er(f.d,d)&&(t=!0)),n=je(n/2),n===0){n=f.d.length-1,t&&f.d[n]===0&&++f.d[n];break}r=r.times(r),er(r.d,d)}return H=!0,f}function Ji(i){return i.d[i.d.length-1]&1}function fr(i,r,n){for(var s,t,f=new i(r[0]),d=0;++d<r.length;){if(t=new i(r[d]),!t.s){f=t;break}s=f.cmp(t),(s===n||s===0&&f.s===n)&&(f=t)}return f}function gi(i,r){var n,s,t,f,d,v,M,w=0,A=0,x=0,C=i.constructor,L=C.rounding,B=C.precision;if(!i.d||!i.d[0]||i.e>17)return new C(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(r==null?(H=!1,M=B):M=r,v=new C(.03125);i.e>-2;)i=i.times(v),x+=5;for(s=Math.log(Be(2,x))/Math.LN10*2+5|0,M+=s,n=f=d=new C(1),C.precision=M;;){if(f=z(f.times(i),M,1),n=n.times(++A),v=d.plus(ie(f,n,M,1)),Ue(v.d).slice(0,M)===Ue(d.d).slice(0,M)){for(t=x;t--;)d=z(d.times(d),M,1);if(r==null)if(w<3&&vt(d.d,M-s,L,w))C.precision=M+=10,n=f=v=new C(1),A=0,w++;else return z(d,C.precision=B,L,H=!0);else return C.precision=B,d}d=v}}function ft(i,r){var n,s,t,f,d,v,M,w,A,x,C,L=1,B=10,D=i,Z=D.d,j=D.constructor,I=j.rounding,F=j.precision;if(D.s<0||!Z||!Z[0]||!D.e&&Z[0]==1&&Z.length==1)return new j(Z&&!Z[0]?-1/0:D.s!=1?NaN:Z?0:D);if(r==null?(H=!1,A=F):A=r,j.precision=A+=B,n=Ue(Z),s=n.charAt(0),Math.abs(f=D.e)<15e14){for(;s<7&&s!=1||s==1&&n.charAt(1)>3;)D=D.times(i),n=Ue(D.d),s=n.charAt(0),L++;f=D.e,s>1?(D=new j("0."+n),f++):D=new j(s+"."+n.slice(1))}else return w=Rt(j,A+2,F).times(f+""),D=ft(new j(s+"."+n.slice(1)),A-B).plus(w),j.precision=F,r==null?z(D,F,I,H=!0):D;for(x=D,M=d=D=ie(D.minus(1),D.plus(1),A,1),C=z(D.times(D),A,1),t=3;;){if(d=z(d.times(C),A,1),w=M.plus(ie(d,new j(t),A,1)),Ue(w.d).slice(0,A)===Ue(M.d).slice(0,A))if(M=M.times(2),f!==0&&(M=M.plus(Rt(j,A+2,F).times(f+""))),M=ie(M,new j(L),A,1),r==null)if(vt(M.d,A-B,I,v))j.precision=A+=B,w=d=D=ie(x.minus(1),x.plus(1),A,1),C=z(D.times(D),A,1),t=v=1;else return z(M,j.precision=F,I,H=!0);else return j.precision=F,M;M=w,t+=2}}function ur(i){return String(i.s*i.s/0)}function It(i,r){var n,s,t;for((n=r.indexOf("."))>-1&&(r=r.replace(".","")),(s=r.search(/e/i))>0?(n<0&&(n=s),n+=+r.slice(s+1),r=r.substring(0,s)):n<0&&(n=r.length),s=0;r.charCodeAt(s)===48;s++);for(t=r.length;r.charCodeAt(t-1)===48;--t);if(r=r.slice(s,t),r){if(t-=s,i.e=n=n-s-1,i.d=[],s=(n+1)%K,n<0&&(s+=K),s<t){for(s&&i.d.push(+r.slice(0,s)),t-=K;s<t;)i.d.push(+r.slice(s,s+=K));r=r.slice(s),s=K-r.length}else s-=t;for(;s--;)r+="0";i.d.push(+r),H&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function Ur(i,r){var n,s,t,f,d,v,M,w,A;if(r.indexOf("_")>-1){if(r=r.replace(/(\d)_(?=\d)/g,"$1"),sr.test(r))return It(i,r)}else if(r==="Infinity"||r==="NaN")return+r||(i.s=NaN),i.e=NaN,i.d=null,i;if(Dr.test(r))n=16,r=r.toLowerCase();else if(Tr.test(r))n=2;else if(Er.test(r))n=8;else throw Error(ut+r);for(f=r.search(/p/i),f>0?(M=+r.slice(f+1),r=r.substring(2,f)):r=r.slice(2),f=r.indexOf("."),d=f>=0,s=i.constructor,d&&(r=r.replace(".",""),v=r.length,f=v-f,t=lr(s,new s(n),f,f*2)),w=Lt(r,n,Qe),A=w.length-1,f=A;w[f]===0;--f)w.pop();return f<0?new s(i.s*0):(i.e=Dt(w,A),i.d=w,H=!1,d&&(i=ie(i,t,v*4)),M&&(i=i.times(Math.abs(M)<54?Be(2,M):wt.pow(2,M))),H=!0,i)}function Zr(i,r){var n,s=r.d.length;if(s<3)return r.isZero()?r:gt(i,2,r,r);n=1.4*Math.sqrt(s),n=n>16?16:n|0,r=r.times(1/Et(5,n)),r=gt(i,2,r,r);for(var t,f=new i(5),d=new i(16),v=new i(20);n--;)t=r.times(r),r=r.times(f.plus(t.times(d.times(t).minus(v))));return r}function gt(i,r,n,s,t){var f,d,v,M,w=1,A=i.precision,x=Math.ceil(A/K);for(H=!1,M=n.times(n),v=new i(s);;){if(d=ie(v.times(M),new i(r++*r++),A,1),v=t?s.plus(d):s.minus(d),s=ie(d.times(M),new i(r++*r++),A,1),d=v.plus(s),d.d[x]!==void 0){for(f=x;d.d[f]===v.d[f]&&f--;);if(f==-1)break}f=v,v=s,s=d,d=f,w++}return H=!0,d.d.length=x+1,d}function Et(i,r){for(var n=i;--r;)n*=i;return n}function hr(i,r){var n,s=r.s<0,t=et(i,i.precision,1),f=t.times(.5);if(r=r.abs(),r.lte(f))return nt=s?4:1,r;if(n=r.divToInt(t),n.isZero())nt=s?3:2;else{if(r=r.minus(n.times(t)),r.lte(f))return nt=Ji(n)?s?2:3:s?4:1,r;nt=Ji(n)?s?1:4:s?3:2}return r.minus(t).abs()}function mi(i,r,n,s){var t,f,d,v,M,w,A,x,C,L=i.constructor,B=n!==void 0;if(B?(Ke(n,1,ht),s===void 0?s=L.rounding:Ke(s,0,8)):(n=L.precision,s=L.rounding),!i.isFinite())A=ur(i);else{for(A=tt(i),d=A.indexOf("."),B?(t=2,r==16?n=n*4-3:r==8&&(n=n*3-2)):t=r,d>=0&&(A=A.replace(".",""),C=new L(1),C.e=A.length-d,C.d=Lt(tt(C),10,t),C.e=C.d.length),x=Lt(A,10,t),f=M=x.length;x[--M]==0;)x.pop();if(!x[0])A=B?"0p+0":"0";else{if(d<0?f--:(i=new L(i),i.d=x,i.e=f,i=ie(i,C,n,s,0,t),x=i.d,f=i.e,w=ir),d=x[n],v=t/2,w=w||x[n+1]!==void 0,w=s<4?(d!==void 0||w)&&(s===0||s===(i.s<0?3:2)):d>v||d===v&&(s===4||w||s===6&&x[n-1]&1||s===(i.s<0?8:7)),x.length=n,w)for(;++x[--n]>t-1;)x[n]=0,n||(++f,x.unshift(1));for(M=x.length;!x[M-1];--M);for(d=0,A="";d<M;d++)A+=ci.charAt(x[d]);if(B){if(M>1)if(r==16||r==8){for(d=r==16?4:3,--M;M%d;M++)A+="0";for(x=Lt(A,t,r),M=x.length;!x[M-1];--M);for(d=1,A="1.";d<M;d++)A+=ci.charAt(x[d])}else A=A.charAt(0)+"."+A.slice(1);A=A+(f<0?"p":"p+")+f}else if(f<0){for(;++f;)A="0"+A;A="0."+A}else if(++f>M)for(f-=M;f--;)A+="0";else f<M&&(A=A.slice(0,f)+"."+A.slice(f))}A=(r==16?"0x":r==2?"0b":r==8?"0o":"")+A}return i.s<0?"-"+A:A}function er(i,r){if(i.length>r)return i.length=r,!0}function jr(i){return new this(i).abs()}function zr(i){return new this(i).acos()}function $r(i){return new this(i).acosh()}function Kr(i,r){return new this(i).plus(r)}function Hr(i){return new this(i).asin()}function Wr(i){return new this(i).asinh()}function Gr(i){return new this(i).atan()}function Vr(i){return new this(i).atanh()}function Xr(i,r){i=new this(i),r=new this(r);var n,s=this.precision,t=this.rounding,f=s+4;return!i.s||!r.s?n=new this(NaN):!i.d&&!r.d?(n=et(this,f,1).times(r.s>0?.25:.75),n.s=i.s):!r.d||i.isZero()?(n=r.s<0?et(this,s,t):new this(0),n.s=i.s):!i.d||r.isZero()?(n=et(this,f,1).times(.5),n.s=i.s):r.s<0?(this.precision=f,this.rounding=1,n=this.atan(ie(i,r,f,1)),r=et(this,f,1),this.precision=s,this.rounding=t,n=i.s<0?n.minus(r):n.plus(r)):n=this.atan(ie(i,r,f,1)),n}function Qr(i){return new this(i).cbrt()}function Yr(i){return z(i=new this(i),i.e+1,2)}function Jr(i,r,n){return new this(i).clamp(r,n)}function en(i){if(!i||typeof i!="object")throw Error(Tt+"Object expected");var r,n,s,t=i.defaults===!0,f=["precision",1,ht,"rounding",0,8,"toExpNeg",-pt,0,"toExpPos",0,pt,"maxE",0,pt,"minE",-pt,0,"modulo",0,9];for(r=0;r<f.length;r+=3)if(n=f[r],t&&(this[n]=di[n]),(s=i[n])!==void 0)if(je(s)===s&&s>=f[r+1]&&s<=f[r+2])this[n]=s;else throw Error(ut+n+": "+s);if(n="crypto",t&&(this[n]=di[n]),(s=i[n])!==void 0)if(s===!0||s===!1||s===0||s===1)if(s)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(nr);else this[n]=!1;else throw Error(ut+n+": "+s);return this}function tn(i){return new this(i).cos()}function rn(i){return new this(i).cosh()}function cr(i){var r,n,s;function t(f){var d,v,M,w=this;if(!(w instanceof t))return new t(f);if(w.constructor=t,tr(f)){w.s=f.s,H?!f.d||f.e>t.maxE?(w.e=NaN,w.d=null):f.e<t.minE?(w.e=0,w.d=[0]):(w.e=f.e,w.d=f.d.slice()):(w.e=f.e,w.d=f.d?f.d.slice():f.d);return}if(M=typeof f,M==="number"){if(f===0){w.s=1/f<0?-1:1,w.e=0,w.d=[0];return}if(f<0?(f=-f,w.s=-1):w.s=1,f===~~f&&f<1e7){for(d=0,v=f;v>=10;v/=10)d++;H?d>t.maxE?(w.e=NaN,w.d=null):d<t.minE?(w.e=0,w.d=[0]):(w.e=d,w.d=[f]):(w.e=d,w.d=[f]);return}if(f*0!==0){f||(w.s=NaN),w.e=NaN,w.d=null;return}return It(w,f.toString())}if(M==="string")return(v=f.charCodeAt(0))===45?(f=f.slice(1),w.s=-1):(v===43&&(f=f.slice(1)),w.s=1),sr.test(f)?It(w,f):Ur(w,f);if(M==="bigint")return f<0?(f=-f,w.s=-1):w.s=1,It(w,f.toString());throw Error(ut+f)}if(t.prototype=O,t.ROUND_UP=0,t.ROUND_DOWN=1,t.ROUND_CEIL=2,t.ROUND_FLOOR=3,t.ROUND_HALF_UP=4,t.ROUND_HALF_DOWN=5,t.ROUND_HALF_EVEN=6,t.ROUND_HALF_CEIL=7,t.ROUND_HALF_FLOOR=8,t.EUCLID=9,t.config=t.set=en,t.clone=cr,t.isDecimal=tr,t.abs=jr,t.acos=zr,t.acosh=$r,t.add=Kr,t.asin=Hr,t.asinh=Wr,t.atan=Gr,t.atanh=Vr,t.atan2=Xr,t.cbrt=Qr,t.ceil=Yr,t.clamp=Jr,t.cos=tn,t.cosh=rn,t.div=nn,t.exp=on,t.floor=sn,t.hypot=an,t.ln=ln,t.log=fn,t.log10=hn,t.log2=un,t.max=cn,t.min=dn,t.mod=pn,t.mul=gn,t.pow=mn,t.random=vn,t.round=wn,t.sign=Mn,t.sin=yn,t.sinh=bn,t.sqrt=_n,t.sub=kn,t.sum=An,t.tan=Sn,t.tanh=Cn,t.trunc=Pn,i===void 0&&(i={}),i&&i.defaults!==!0)for(s=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],r=0;r<s.length;)i.hasOwnProperty(n=s[r++])||(i[n]=this[n]);return t.config(i),t}function nn(i,r){return new this(i).div(r)}function on(i){return new this(i).exp()}function sn(i){return z(i=new this(i),i.e+1,3)}function an(){var i,r,n=new this(0);for(H=!1,i=0;i<arguments.length;)if(r=new this(arguments[i++]),r.d)n.d&&(n=n.plus(r.times(r)));else{if(r.s)return H=!0,new this(1/0);n=r}return H=!0,n.sqrt()}function tr(i){return i instanceof wt||i&&i.toStringTag===or||!1}function ln(i){return new this(i).ln()}function fn(i,r){return new this(i).log(r)}function un(i){return new this(i).log(2)}function hn(i){return new this(i).log(10)}function cn(){return fr(this,arguments,-1)}function dn(){return fr(this,arguments,1)}function pn(i,r){return new this(i).mod(r)}function gn(i,r){return new this(i).mul(r)}function mn(i,r){return new this(i).pow(r)}function vn(i){var r,n,s,t,f=0,d=new this(1),v=[];if(i===void 0?i=this.precision:Ke(i,1,ht),s=Math.ceil(i/K),this.crypto)if(crypto.getRandomValues)for(r=crypto.getRandomValues(new Uint32Array(s));f<s;)t=r[f],t>=429e7?r[f]=crypto.getRandomValues(new Uint32Array(1))[0]:v[f++]=t%1e7;else if(crypto.randomBytes){for(r=crypto.randomBytes(s*=4);f<s;)t=r[f]+(r[f+1]<<8)+(r[f+2]<<16)+((r[f+3]&127)<<24),t>=214e7?crypto.randomBytes(4).copy(r,f):(v.push(t%1e7),f+=4);f=s/4}else throw Error(nr);else for(;f<s;)v[f++]=Math.random()*1e7|0;for(s=v[--f],i%=K,s&&i&&(t=Be(10,K-i),v[f]=(s/t|0)*t);v[f]===0;f--)v.pop();if(f<0)n=0,v=[0];else{for(n=-1;v[0]===0;n-=K)v.shift();for(s=1,t=v[0];t>=10;t/=10)s++;s<K&&(n-=K-s)}return d.e=n,d.d=v,d}function wn(i){return z(i=new this(i),i.e+1,this.rounding)}function Mn(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function yn(i){return new this(i).sin()}function bn(i){return new this(i).sinh()}function _n(i){return new this(i).sqrt()}function kn(i,r){return new this(i).sub(r)}function An(){var i=0,r=arguments,n=new this(r[i]);for(H=!1;n.s&&++i<r.length;)n=n.plus(r[i]);return H=!0,z(n,this.precision,this.rounding)}function Sn(i){return new this(i).tan()}function Cn(i){return new this(i).tanh()}function Pn(i){return z(i=new this(i),i.e+1,1)}O[Symbol.for("nodejs.util.inspect.custom")]=O.toString;O[Symbol.toStringTag]="Decimal";var wt=O.constructor=cr(di);Ot=new wt(Ot);Nt=new wt(Nt);var it=wt;var yi=ri(pr()),ot=require("@mysten/sui/transactions");var mt=require("@cetusprotocol/common-sdk"),gr=i=>{let r=[];return i.forEach(n=>{r.push(wi(n))}),r},wi=i=>{let r=(0,mt.getObjectFields)(i);return{marketId:r.id.id,baseToken:(0,mt.addHexPrefix)(r.base_token.fields.name),quoteToken:(0,mt.addHexPrefix)(r.quote_token.fields.name),isOpenPause:r.is_open_pause,isClosePause:r.is_close_pause,maxLongLeverage:r.max_long_leverage,maxShortLeverage:r.max_short_leverage,openFeeRate:(r.open_fee_rate/1e6).toString(),closeFeeRate:(r.close_fee_rate/1e6).toString(),positionsHandle:r.positions.fields.id.id}},Mi=i=>{let r=(0,mt.getObjectFields)(i);return{createdAt:r.created_ts,id:r.id.id,initDepositAmount:r.init_deposit_amount,isLong:r.is_long,lendingMarketId:r.lending_market_id,obligationOwnerCap:r.obligation_owner_cap.fields.obligation_id}};var st=require("@mysten/sui/utils"),mr=require("@suilend/sdk/parsers/obligation"),vr=require("@suilend/sdk/_generated/suilend/lending-market/functions"),Bt=class{constructor(r){this.getLeverageConfig=async()=>{let r=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.leverage);return(await this._sdk.FullClient.getObject({id:r.global_config_id,options:{showContent:!0}})).data.content.fields};this.getLeverageMarketsList=async(r=!1)=>{let n="leverage_markets_list",s=this._sdk.getCache(n,r);if(s)return s;let t=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.leverage),f=50,d=null,v=[];for(;;){let C=await this._sdk.FullClient.getDynamicFields({parentId:t.markets_table_id,limit:f,cursor:d});if(C.data.forEach(L=>{v.push(L.objectId)}),C.data.length<f)break;d=C.nextCursor}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:63 ~ LeverageModules ~ marketSimpleIdList:",v);let M=await this._sdk.FullClient.batchGetObjects(v,{showContent:!0}),w=[];M.forEach(C=>{w.push(C.data.content.fields.value.fields.market_id)});let A=await this._sdk.FullClient.batchGetObjects(w,{showContent:!0}),x=gr(A);return this._sdk.updateCache(n,x,N.CACHE_TIME_5MIN),x};this.getLeverageMarketInfo=async r=>{let n=`leverage_market_info_${r}`,s=this._sdk.getCache(n);if(s)return s;let t=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}}),f=wi(t);return this._sdk.updateCache(n,f,N.CACHE_TIME_5MIN),f};this.getLeveragePositionList=async()=>{let r=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{Package:this._sdk.sdkOptions.leverage.package_id}]}}),{lendingMarketId:n,lendingMarketType:s}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),t=await this._sdk.SuiLendModule.getSuilendClient(n,s),f=[];for(let d=0;d<r.data.length;d++){let v=Mi(r.data[d]),M=await t.getObligation(v.obligationOwnerCap);f.push({...v,...M})}return f};this.getLeveragePosition=async r=>{let n=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{ObjectId:r}}),s=Mi(n.data[0]),{lendingMarketId:t,lendingMarketType:f}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),d=await this._sdk.SuiLendModule.getSuilendClient(t,f),{allLendingMarketData:v}=await this._sdk.SuiLendModule.getLendingMarketData(),M=v[t].reserveMap,w=await d.getObligation(s.obligationOwnerCap);return{...(0,mr.parseObligation)(w,M||{}),...s}};this.getClmmPoolInfo=async r=>{let n=await this._sdk.ClmmSDK.Pool.getPool(r),{coin_type_a:s,coin_type_b:t,fee_rate:f}=n;return{clmmFeeTier:f/1e6,clmmPoolCoinTypeA:s,clmmPoolCoinTypeB:t}};this.openLeveragePosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:f,slippage:d,leverage:v,marketId:M}=r,{lendingMarketId:w}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),A=new ot.Transaction,{openFeeRate:x,baseToken:C,quoteToken:L}=await this.getLeverageMarketInfo(M),{clmmFeeTier:B,clmmPoolCoinTypeA:D,clmmPoolCoinTypeB:Z}=await this.getClmmPoolInfo(f);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",B,D,Z);let{baseReserveArrayIndex:j,quoteReserveArrayIndex:I,reserve:F}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(C,L),q=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",q);let ee=t.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",ee);let $,X;if(q){let T=s&&n?L:C,U=s&&n?C:L,V=await this.findRouters(T,U,t,!0,[f]);if(ee=V?.amount_out.toString(),V){let J=N.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),T,A);X=await this.routerSwap({router:V.route_obj,slippage:d,inputCoin:J,txb:A}),$=X}}else $=N.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),n?L:C,A);let{flashAmount:m}=await this.calculateFlashLoanParams({isLong:s,leverage:v,baseToken:C,quoteToken:L,initDepositAmount:ee,reserve:F});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",m);let b=s?L:C;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",b);let _=D===b;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",D),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",_);let P=(0,N.d)(m).mul(B).toString(),{balanceA:S,balanceB:c,receipt:e}=this.flashLoan({amount:(0,N.d)(m),clmmPool:f,clmmPoolCoinTypeA:D,clmmPoolCoinTypeB:Z,flashLoanCoin:b,tx:A}),o=s?L:C,l=s?C:L,u=await this.findRouters(o,l,(0,N.d)(m),!0,[f]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:u,debtFrom:o,debtTo:l,clmmPoolCoinTypeA:D,clmmPoolCoinTypeB:Z});let h=(0,N.d)(u?.amount_out||0),g;u&&(g=await this.routerSwap({router:u.route_obj,inputCoin:_?N.CoinAssist.fromBalance(S,D,A):N.CoinAssist.fromBalance(c,Z,A),slippage:d,txb:A}));let k=(0,N.d)(h).add(ee).mul(1-x).toDP(0,it.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:258 ~ LeverageModules ~ totalDepositAmount:",k,ee,h);let p=this.createLeveragePosition({leverage:v,marketId:M,baseToken:C,quoteToken:L,isLong:s,totalDepositAmount:k,tx:A});for(let T=0;T<F.length;T++){let U=(0,st.toHEX)(new Uint8Array(F[T].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,U,BigInt(F[T].arrayIndex))}let a=s?j:I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",$),await A.mergeCoins(g,[$]),await this.depositToLeveragePosition({isLong:s,marketId:M,position:p,depositReserveArrayIndex:a,inputCoin:g},A);let y=(0,N.d)(m).add(P).toDP(0,it.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",y,m,P);let E=await this.borrowAsset({position:p,reserveArrayIndex:s?I:j,borrowAmount:(0,N.d)(y),baseToken:C,quoteToken:L,isLong:s,lendingMarketId:w},A);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",E);let R=N.CoinAssist.mintBalanceZero(_?Z:D,A);return this.repayFlashLoan({tx:A,clmmPool:f,repayBase:_?N.CoinAssist.intoBalance(E,D,A):R,repayQuote:_?R:N.CoinAssist.intoBalance(E,Z,A),receipt:e,clmmPoolCoinTypeA:D,clmmPoolCoinTypeB:Z}),A.transferObjects([p],A.pure.address(this._sdk.getSenderAddress())),N.CoinAssist.destroyBalanceZero(_?c:S,_?Z:D,A),A};this.positionManageSizeDeposit=async r=>{let{marketId:n,positionId:s,isQuote:t,depositAmount:f,clmmPool:d,slippage:v,leverage:M,txb:w}=r,{lendingMarketId:A}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{baseToken:x,quoteToken:C}=await this.getLeverageMarketInfo(n),{isLong:L,deposits:B,borrows:D}=await this.getLeveragePosition(s),{reserve:Z}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(x,C),{clmmFeeTier:j,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F}=await this.getClmmPoolInfo(d),q=w||new ot.Transaction,ee=B[0].reserveArrayIndex.toString(),$=D[0].reserveArrayIndex.toString(),X=t&&L||!t&&!L,m;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",X);let b;if(X){let E=t&&L?C:x,R=t&&L?x:C,T=await this.findRouters(E,R,f,!0,[d]);if(T){let U=N.CoinAssist.buildCoinWithBalance(BigInt(f.toString()),E,q);b=await this.routerSwap({router:T.route_obj,inputCoin:U,slippage:v,txb:q}),m=b}}else m=N.CoinAssist.buildCoinWithBalance(BigInt(f.toString()),t?C:x,q);let _=L?C:x;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",_);let{flashAmount:P}=await this.calculateFlashLoanParams({isLong:L,leverage:M,baseToken:x,quoteToken:C,initDepositAmount:f.toString(),reserve:Z}),S=(0,N.d)(P).mul(j).toString(),c=I===_;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",c);let{balanceA:e,balanceB:o,receipt:l}=this.flashLoan({amount:(0,N.d)(P),clmmPool:d,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F,flashLoanCoin:_,tx:q}),u=L?C:x,h=L?x:C,g=await this.findRouters(u,h,(0,N.d)(P),!0,[d]),k;g&&(k=await this.routerSwap({router:g.route_obj,inputCoin:c?N.CoinAssist.fromBalance(e,I,q):N.CoinAssist.fromBalance(o,F,q),slippage:v,txb:q})),q.mergeCoins(k,[m]);for(let E=0;E<Z.length;E++){let R=(0,st.toHEX)(new Uint8Array(Z[E].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(q,R,BigInt(Z[E].arrayIndex))}this.depositToLeveragePosition({isLong:L,marketId:n,positionId:s,depositReserveArrayIndex:ee,inputCoin:k},q);let p=(0,N.d)(P).add(S).toDP(0,it.ROUND_UP).toString(),a=this.borrowAsset({positionId:s,reserveArrayIndex:$,borrowAmount:(0,N.d)(p),baseToken:x,quoteToken:C,isLong:L,lendingMarketId:A},q),y=N.CoinAssist.mintBalanceZero(c?F:I,q);return this.repayFlashLoan({tx:q,clmmPool:d,repayBase:c?N.CoinAssist.intoBalance(a,I,q):y,repayQuote:c?y:N.CoinAssist.intoBalance(a,F,q),receipt:l,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F}),N.CoinAssist.destroyBalanceZero(c?o:e,c?F:I,q),q};this.positionManageSizeWithdraw=async r=>{let{marketId:n,positionId:s,withdrawAmount:t,isQuote:f,txb:d,clmmPool:v,slippage:M,leverage:w}=r,{lendingMarketType:A,lendingMarketId:x}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),C=d||new ot.Transaction,{baseToken:L,quoteToken:B}=await this.getLeverageMarketInfo(n),{isLong:D,deposits:Z,borrows:j}=await this.getLeveragePosition(s),{reserve:I}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(L,B),F=f&&D||!f&&!D;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:479 ~ LeverageModules ~ hasSwap:",F);let q=t;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:482 ~ LeverageModules ~ withdrawCtokenAmount:",q);let ee=null;if(F){let k=L,p=B;ee=await this.findRouters(k,p,t,!1,[v]),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ routers:",{hasSwapRouters:ee,from:k,to:p}),q=ee?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",q);for(let k=0;k<I.length;k++){let p=(0,st.toHEX)(new Uint8Array(I[k].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(C,p,BigInt(I[k].arrayIndex))}let{token:$}=j[0].reserve,X=(0,N.d)(Z[0].depositedCtokenAmount.toString()).div((0,N.d)(w)).toDP(0,it.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",X);let m=(0,N.d)(q).div((0,N.d)(X)).toString(),b=(0,N.d)(j[0].borrowedAmount.toString()).mul(10**$.decimals).toString(),_=(0,N.d)(b).mul(m).toDP(0,it.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:508 ~ LeverageModules ~ repayAmount:",{\u9700\u8981\u507F\u8FD8\u591A\u5C11borrowAmount:_,\u63D0\u53D6\u4FDD\u8BC1\u91D1\u6570\u91CF:q,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:X});let P=await this._sdk.SuiLendModule.getSuilendClient(x,A),S=await this._sdk.PythConnection.getPriceFeedsUpdateData([Z[0].reserve.priceIdentifier]),c=await P.pythClient.updatePriceFeeds(C,S,[Z[0].reserve.priceIdentifier]),e=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:(0,N.d)(q),withdrawReserveArrayIndex:Z[0].reserveArrayIndex.toString(),withdrawCoinType:D?L:B,baseToken:L,quoteToken:B,priceObjectId:c&&c[0]},C),o=D?L:B,l=D?B:L;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let u=await this.findRouters(o,l,(0,N.d)(_),!1,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:530 ~ LeverageModules ~ debtRouter:",{debtRouter:u,debtFrom:o,debtTo:l});let h;u&&(h=await this.routerSwap({router:u.route_obj,inputCoin:e,slippage:M,txb:C}));let g=C.splitCoins(h,[_]);return this.repay({txb:C,positionId:s,repayReserveArrayIndex:j[0].reserveArrayIndex.toString(),repayCoin:g,repayCoinType:D?B:L,repayAmount:(0,N.d)(0)}),C.transferObjects([h,g],this._sdk.getSenderAddress()),C};this.positionManageLeverageIncrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:f,targetLeverage:d,clmmPool:v,slippage:M}=r,{baseToken:w,quoteToken:A}=await this.getLeverageMarketInfo(n),{deposits:x,borrows:C}=await this.getLeveragePosition(s),{reserve:L}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(w,A),{clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:D,clmmFeeTier:Z}=await this.getClmmPoolInfo(v),{lendingMarketId:j}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{token:I}=C[0].reserve,F=new ot.Transaction,q=(0,N.d)(C[0].borrowedAmount.toString()).mul((0,N.d)(d).sub((0,N.d)(f))).mul(10**I.decimals).toDP(0,it.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",q);let ee=q,$=t?A:w,{balanceA:X,balanceB:m,receipt:b}=this.flashLoan({tx:F,amount:(0,N.d)(ee),clmmPool:v,clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:D,flashLoanCoin:$}),_=t?A:w,P=t?w:A,S=await this.findRouters(_,P,(0,N.d)(q),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:592 ~ LeverageModules ~ routers:",S,_,P);let c=await this.routerSwap({router:S?.route_obj,inputCoin:t?N.CoinAssist.fromBalance(m,D,F):N.CoinAssist.fromBalance(X,B,F),slippage:M,txb:F});for(let h=0;h<L.length;h++){let g=(0,st.toHEX)(new Uint8Array(L[h].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(F,g,BigInt(L[h].arrayIndex))}this.depositToLeveragePosition({isLong:t,marketId:n,positionId:s,depositReserveArrayIndex:t?x[0].reserveArrayIndex.toString():C[0].reserveArrayIndex.toString(),inputCoin:c},F);let e=(0,N.d)(ee).mul((0,N.d)(1).add(Z)).toDP(0,it.ROUND_UP).toString(),o=await this.borrowAsset({positionId:s,reserveArrayIndex:C[0].reserveArrayIndex.toString(),borrowAmount:(0,N.d)(e),baseToken:w,quoteToken:A,isLong:t,lendingMarketId:j},F),l=N.CoinAssist.mintBalanceZero(t?w:A,F),u=B===$;return this.repayFlashLoan({tx:F,clmmPool:v,repayBase:t?l:N.CoinAssist.intoBalance(o,w,F),repayQuote:t?N.CoinAssist.intoBalance(o,A,F):l,receipt:b,clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:D}),N.CoinAssist.destroyBalanceZero(u?m:X,u?D:B,F),F};this.positionManageLeverageDecrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:f,targetLeverage:d,clmmPool:v,slippage:M}=r,{baseToken:w,quoteToken:A,closeFeeRate:x}=await this.getLeverageMarketInfo(n),{deposits:C,borrows:L}=await this.getLeveragePosition(s),{reserve:B}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(w,A),{lendingMarketId:D,lendingMarketType:Z}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),j=new ot.Transaction,I=(0,N.d)(C[0].depositedCtokenAmount.toString()).mul((0,N.d)(f).sub((0,N.d)(d))).toString(),F=(0,N.d)(I).toDP(0,it.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",F);for(let S=0;S<B.length;S++){let c=(0,st.toHEX)(new Uint8Array(B[S].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(j,c,BigInt(B[S].arrayIndex))}let q=await this._sdk.SuiLendModule.getSuilendClient(D,Z),ee=await this._sdk.PythConnection.getPriceFeedsUpdateData([C[0].reserve.priceIdentifier]),$=await q.pythClient.updatePriceFeeds(j,ee,[C[0].reserve.priceIdentifier]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:672 ~ LeverageModules ~ baseToken:",w);let X=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:(0,N.d)(F),withdrawReserveArrayIndex:C[0].reserveArrayIndex.toString(),withdrawCoinType:t?w:A,baseToken:w,quoteToken:A,priceObjectId:$&&$[0]},j),m=t?w:A,b=t?A:w,_=await this.findRouters(m,b,(0,N.d)(F),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:681 ~ LeverageModules ~ routers:",_,_?.route_obj.paths,m,b);let P=await this.routerSwap({router:_?.route_obj,inputCoin:X,slippage:M,txb:j});return this.repay({txb:j,positionId:s,repayReserveArrayIndex:L[0].reserveArrayIndex.toString(),repayCoin:P,repayCoinType:t?A:w,repayAmount:(0,N.d)(0)}),P&&j.transferObjects([P],this._sdk.getSenderAddress()),j};this.leveragePositionClose=async(r,n)=>{let s=n||new ot.Transaction,{marketId:t,positionId:f}=r,{leverage:d}=this._sdk.sdkOptions,{global_config_id:v}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.leverage),{lendingMarketType:M,lendingMarketId:w}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{baseToken:A,quoteToken:x}=await this.getLeverageMarketInfo(t),C=await this.getLeveragePosition(f);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:541 ~ LeverageModules ~ positionInfo:",C.original.id);let L=(0,vr.obligation)(s,M,{obligationId:C.original.id,lendingMarket:s.object(w)});return s.moveCall({target:`${d.published_at}::position::close_Position`,typeArguments:[M,A,x],arguments:[s.object(v),s.object(t),s.object(f),L,s.object(N.CLOCK_ADDRESS)]}),s};this.flashLoan=r=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:698 ~ LeverageModules ~ params:",r);let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:s}=(0,N.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:t,clmmPool:f,clmmPoolCoinTypeA:d,clmmPoolCoinTypeB:v,flashLoanCoin:M,tx:w}=r,A=d===M,[x,C,L]=w.moveCall({target:`${n.published_at}::pool::flash_loan`,arguments:[w.object(s),w.object(f),w.pure.bool(A),w.pure.u64(t.toString())],typeArguments:[d,v]});return{balanceA:x,balanceB:C,receipt:L}};this.repayFlashLoan=r=>{let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:s}=(0,N.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:t,repayBase:f,repayQuote:d,receipt:v,clmmPool:M,clmmPoolCoinTypeA:w,clmmPoolCoinTypeB:A}=r;return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:612 ~ LeverageModules ~ params:",r),t.moveCall({target:`${n.published_at}::pool::repay_flash_loan`,arguments:[t.object(s),t.object(M),f,d,v],typeArguments:[w,A]}),t};this.borrowAsset=(r,n)=>{let{position:s,reserveArrayIndex:t,borrowAmount:f,baseToken:d,quoteToken:v,lendingMarketId:M,isLong:w,positionId:A}=r;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:677 ~ LeverageModules ~ params:",r);let{leverage:x}=this._sdk.sdkOptions,{lendingMarketType:C}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend);return N.CoinAssist.isSuiCoin(w?v:d)?n.moveCall({target:`${x.published_at}::position::borrow_sui`,typeArguments:[C],arguments:[n.object(M),s,n.pure.u64(t),n.pure.u64(f.toString()),n.object(st.SUI_SYSTEM_STATE_OBJECT_ID),n.object(N.CLOCK_ADDRESS)]}):n.moveCall({target:`${x.published_at}::position::borrow_not_sui`,typeArguments:[C,w?v:d],arguments:[n.object(M),A?n.object(A):s,n.pure.u64(t),n.pure.u64(f.toString()),n.object(N.CLOCK_ADDRESS)]})};this.withdrawAsset=(r,n)=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:749 ~ LeverageModules ~ params:",r);let{leverage:s}=this._sdk.sdkOptions,{lendingMarketId:t,lendingMarketType:f}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{package_id:d}=this._sdk.sdkOptions.suilend,{marketId:v,positionId:M,withdrawAmount:w,withdrawReserveArrayIndex:A,withdrawCoinType:x,baseToken:C,quoteToken:L,priceObjectId:B}=r,[D]=n.moveCall({target:"0x1::option::none",typeArguments:[`${d}::lending_market::RateLimiterExemption<${f}, ${x}>`],arguments:[]});return N.CoinAssist.isSuiCoin(x)?n.moveCall({target:`${s.published_at}::position::withdraw_sui`,typeArguments:[f,C,L],arguments:[n.object(t),n.object(v),n.object(M),n.object(B),n.object(D),n.pure.u64(w.toString()),n.pure.u64(A),n.object(st.SUI_SYSTEM_STATE_OBJECT_ID),n.object(N.CLOCK_ADDRESS)]}):n.moveCall({target:`${s.published_at}::position::withdraw_not_sui`,typeArguments:[f,C,L,x],arguments:[n.object(t),n.object(v),n.object(M),n.object(B),n.object(D),n.pure.u64(w.toString()),n.pure.u64(A),n.object(N.CLOCK_ADDRESS)]})};this.repay=r=>{let{leverage:n}=this._sdk.sdkOptions,{lendingMarketId:s,lendingMarketType:t}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{txb:f,positionId:d,repayAmount:v,repayCoinType:M,repayCoin:w,repayReserveArrayIndex:A}=r,x=f||new ot.Transaction,C=w||N.CoinAssist.buildCoinWithBalance(BigInt(v.toString()),M,x);x.moveCall({target:`${n.published_at}::position::repay`,typeArguments:[t,M],arguments:[x.object(s),x.object(d),x.object(C),x.pure.u64(A.toString()),x.object(N.CLOCK_ADDRESS)]})};this.routerSwap=async r=>{let{slippage:n,txb:s,inputCoin:t,router:f}=r,d=s||new ot.Transaction;if(f)return await this._sdk.AggregatorClient.routerSwap({router:f,inputCoin:t,slippage:n,txb:d})};this.calculateOpenPosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:f,slippage:d,leverage:v,marketId:M}=r,{baseToken:w,quoteToken:A}=await this.getLeverageMarketInfo(M),{reserve:x}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(w,A),C=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",C);let L=t.toString();if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",L),C){let I=s&&n?A:w,F=s&&n?w:A;L=(await this.findRouters(I,F,t,!0,[f]))?.amount_out.toString()}let{flashAmount:B}=await this.calculateFlashLoanParams({isLong:s,leverage:v,baseToken:w,quoteToken:A,initDepositAmount:L,reserve:x});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",B);let D=s?A:w,Z=s?w:A,j=await this.findRouters(D,Z,(0,N.d)(B),!0,[f]);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:956 ~ LeverageModules ~ debtRouters:",j),j};this._sdk=r}async calculateFlashLoanParams(r){let{isLong:n,leverage:s,baseToken:t,quoteToken:f,initDepositAmount:d,reserve:v}=r,M=await this._sdk.SuiLendModule.getLatestPriceFeeds(v);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:587 ~ LeverageModules ~ calculateFlashLoanParams ~ priceUpdateData:",M,f,t);let w=M[(0,N.removeHexPrefix)(f)]?.price,A=M[(0,N.removeHexPrefix)(t)]?.price,x=n?(0,N.d)(A).div((0,N.d)(w)).toString():(0,N.d)(w).div((0,N.d)(A)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",d.toString(),n,x,w,A),{flashAmount:(0,N.d)(d).mul(s-1).mul(x).toDP(0,it.ROUND_UP).toString(),rate:x,quotePrice:w,basePrice:A}}createLeveragePosition(r){let{lendingMarketId:n,lendingMarketType:s}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{global_config_id:t}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.leverage),f=this._sdk.sdkOptions.leverage,{leverage:d,marketId:v,baseToken:M,quoteToken:w,isLong:A,totalDepositAmount:x,tx:C}=r;return C.moveCall({target:`${f.published_at}::position::open_position`,arguments:[C.object(t),C.object(v),C.object(n),C.pure.u64(x),C.pure.u64(d*1e4),C.object(N.CLOCK_ADDRESS)],typeArguments:[s,M,w,A?M:w]})}async depositToLeveragePosition(r,n){console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:651 ~ LeverageModules ~ depositToLeveragePosition ~ params:",r);let{leverage:s}=this._sdk.sdkOptions,{lendingMarketType:t,lendingMarketId:f}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{isLong:d,marketId:v,position:M,positionId:w,depositReserveArrayIndex:A,inputCoin:x}=r,{baseToken:C,quoteToken:L}=await this.getLeverageMarketInfo(v);return n.moveCall({target:`${s.published_at}::position::deposit`,typeArguments:[t,C,L,d?C:L],arguments:[n.object(f),n.object(v),M||n.object(w),x,n.pure.u64(A),n.object(N.CLOCK_ADDRESS)]}),n}async findRouters(r,n,s,t,f){let{providers:d}=this._sdk.sdkOptions;try{let v={from:r,target:n,amount:new yi.default(s.toFixed(0).toString()),byAmountIn:t,depth:3,providers:d},M=await this._sdk.AggregatorClient.findRouters(v);if(M?.error?.code===10001)return{...M,is_exceed:M.insufficientLiquidity};if(M?.insufficientLiquidity)return{...M,is_exceed:M.insufficientLiquidity};if(!M?.paths||M?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:M.amountIn.toString(),amount_out:M.amountOut.toString(),is_exceed:M.insufficientLiquidity,route_obj:M,byAmountIn:!0,originRes:M}}catch{try{if(f){let M=await this._sdk.AggregatorClient.swapInPools({from:r,target:n,amount:new yi.default(s.toFixed(0).toString()),byAmountIn:t,pools:f});return M?{amount_in:M.routeData.amountIn.toString(),amount_out:M.routeData.amountOut.toString(),is_exceed:M.isExceed,route_obj:M.routeData,byAmountIn:!0,originRes:M}:null}return null}catch{return null}}}};var Mt=require("@cetusprotocol/aggregator-sdk"),Mr=require("@mysten/sui/utils"),yr=require("@mysten/sui/client"),br=require("@cetusprotocol/sui-clmm-sdk"),_r=require("@pythnetwork/pyth-sui-js"),yt=class i extends wr.SdkWrapper{constructor(r,n){super(r),this._suilendModule=new xt(this),this._leverageModules=new Bt(this),this._aggregatorClient=new Mt.AggregatorClient({signer:(0,Mr.normalizeSuiAddress)("0x0"),client:r.sui_client||new yr.SuiClient({url:r.full_rpc_url}),env:r.env==="testnet"?Mt.Env.Testnet:Mt.Env.Mainnet,pythUrls:r.pyth_urls}),this._clmmSDK=n||br.CetusClmmSDK.createSDK({env:r.env,full_rpc_url:r.full_rpc_url}),this._pythConnection=new _r.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(r){return i.createCustomSDK({...ni,...r})}static createCustomSDK(r){return new i(r)}};var xn=yt;0&&(module.exports={CetusLeverageSDK,leverage_mainnet});
|
|
10
2
|
/*! Bundled license information:
|
|
11
3
|
|
|
12
|
-
decimal.js/decimal.mjs:
|
|
13
|
-
(*!
|
|
14
|
-
* decimal.js v10.6.0
|
|
15
|
-
* An arbitrary-precision Decimal type for JavaScript.
|
|
16
|
-
* https://github.com/MikeMcl/decimal.js
|
|
17
|
-
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
18
|
-
* MIT Licence
|
|
19
|
-
*)
|
|
20
|
-
*/
|
|
21
|
-
/*! Bundled license information:
|
|
22
|
-
|
|
23
|
-
@cetusprotocol/aggregator-sdk/dist/index.js:
|
|
24
|
-
(*! Bundled license information:
|
|
25
|
-
|
|
26
|
-
decimal.js/decimal.mjs:
|
|
27
|
-
(*!
|
|
28
|
-
* decimal.js v10.4.3
|
|
29
|
-
* An arbitrary-precision Decimal type for JavaScript.
|
|
30
|
-
* https://github.com/MikeMcl/decimal.js
|
|
31
|
-
* Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
32
|
-
* MIT Licence
|
|
33
|
-
*)
|
|
34
|
-
*)
|
|
35
|
-
|
|
36
4
|
decimal.js/decimal.mjs:
|
|
37
5
|
(*!
|
|
38
6
|
* decimal.js v10.6.0
|