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.mjs
CHANGED
|
@@ -1,38 +1,6 @@
|
|
|
1
|
-
var Ku=Object.create;var Hs=Object.defineProperty;var Wu=Object.getOwnPropertyDescriptor;var zu=Object.getOwnPropertyNames;var Xu=Object.getPrototypeOf,Ju=Object.prototype.hasOwnProperty;var vt=(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')});var dr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Yu=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of zu(t))!Ju.call(e,n)&&n!==i&&Hs(e,n,{get:()=>t[n],enumerable:!(r=Wu(t,n))||r.enumerable});return e};var Gs=(e,t,i)=>(i=e!=null?Ku(Xu(e)):{},Yu(t||!e||!e.__esModule?Hs(i,"default",{value:e,enumerable:!0}):i,e));var ba=dr((wa,Io)=>{"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=vt("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,le=d[6]|0,Ee=le&8191,ce=le>>>13,pe=d[7]|0,Ce=pe&8191,ue=pe>>>13,Se=d[8]|0,et=Se&8191,fe=Se>>>13,Re=d[9]|0,Ye=Re&8191,he=Re>>>13,Ie=m[0]|0,ze=Ie&8191,de=Ie>>>13,Ue=m[1]|0,ot=Ue&8191,me=Ue>>>13,je=m[2]|0,st=je&8191,ge=je>>>13,qe=m[3]|0,at=qe&8191,_e=qe>>>13,$e=m[4]|0,lt=$e&8191,ve=$e>>>13,He=m[5]|0,ut=He&8191,we=He>>>13,Ge=m[6]|0,ct=Ge&8191,be=Ge>>>13,Ve=m[7]|0,dt=Ve&8191,ye=Ve>>>13,Ze=m[8]|0,ht=Ze&8191,Me=Ze>>>13,Ke=m[9]|0,ft=Ke&8191,Ae=Ke>>>13;l.negative=h.negative^o.negative,l.length=19,w=Math.imul(q,ze),f=Math.imul(q,de),f=f+Math.imul($,ze)|0,u=Math.imul($,de);var Be=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Be>>>26)|0,Be&=67108863,w=Math.imul(ie,ze),f=Math.imul(ie,de),f=f+Math.imul(C,ze)|0,u=Math.imul(C,de),w=w+Math.imul(q,ot)|0,f=f+Math.imul(q,me)|0,f=f+Math.imul($,ot)|0,u=u+Math.imul($,me)|0;var Gt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,w=Math.imul(x,ze),f=Math.imul(x,de),f=f+Math.imul(F,ze)|0,u=Math.imul(F,de),w=w+Math.imul(ie,ot)|0,f=f+Math.imul(ie,me)|0,f=f+Math.imul(C,ot)|0,u=u+Math.imul(C,me)|0,w=w+Math.imul(q,st)|0,f=f+Math.imul(q,ge)|0,f=f+Math.imul($,st)|0,u=u+Math.imul($,ge)|0;var Vt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,w=Math.imul(G,ze),f=Math.imul(G,de),f=f+Math.imul(B,ze)|0,u=Math.imul(B,de),w=w+Math.imul(x,ot)|0,f=f+Math.imul(x,me)|0,f=f+Math.imul(F,ot)|0,u=u+Math.imul(F,me)|0,w=w+Math.imul(ie,st)|0,f=f+Math.imul(ie,ge)|0,f=f+Math.imul(C,st)|0,u=u+Math.imul(C,ge)|0,w=w+Math.imul(q,at)|0,f=f+Math.imul(q,_e)|0,f=f+Math.imul($,at)|0,u=u+Math.imul($,_e)|0;var Zt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,w=Math.imul(Z,ze),f=Math.imul(Z,de),f=f+Math.imul(H,ze)|0,u=Math.imul(H,de),w=w+Math.imul(G,ot)|0,f=f+Math.imul(G,me)|0,f=f+Math.imul(B,ot)|0,u=u+Math.imul(B,me)|0,w=w+Math.imul(x,st)|0,f=f+Math.imul(x,ge)|0,f=f+Math.imul(F,st)|0,u=u+Math.imul(F,ge)|0,w=w+Math.imul(ie,at)|0,f=f+Math.imul(ie,_e)|0,f=f+Math.imul(C,at)|0,u=u+Math.imul(C,_e)|0,w=w+Math.imul(q,lt)|0,f=f+Math.imul(q,ve)|0,f=f+Math.imul($,lt)|0,u=u+Math.imul($,ve)|0;var Kt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,w=Math.imul(ee,ze),f=Math.imul(ee,de),f=f+Math.imul(te,ze)|0,u=Math.imul(te,de),w=w+Math.imul(Z,ot)|0,f=f+Math.imul(Z,me)|0,f=f+Math.imul(H,ot)|0,u=u+Math.imul(H,me)|0,w=w+Math.imul(G,st)|0,f=f+Math.imul(G,ge)|0,f=f+Math.imul(B,st)|0,u=u+Math.imul(B,ge)|0,w=w+Math.imul(x,at)|0,f=f+Math.imul(x,_e)|0,f=f+Math.imul(F,at)|0,u=u+Math.imul(F,_e)|0,w=w+Math.imul(ie,lt)|0,f=f+Math.imul(ie,ve)|0,f=f+Math.imul(C,lt)|0,u=u+Math.imul(C,ve)|0,w=w+Math.imul(q,ut)|0,f=f+Math.imul(q,we)|0,f=f+Math.imul($,ut)|0,u=u+Math.imul($,we)|0;var Wt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,w=Math.imul(Ee,ze),f=Math.imul(Ee,de),f=f+Math.imul(ce,ze)|0,u=Math.imul(ce,de),w=w+Math.imul(ee,ot)|0,f=f+Math.imul(ee,me)|0,f=f+Math.imul(te,ot)|0,u=u+Math.imul(te,me)|0,w=w+Math.imul(Z,st)|0,f=f+Math.imul(Z,ge)|0,f=f+Math.imul(H,st)|0,u=u+Math.imul(H,ge)|0,w=w+Math.imul(G,at)|0,f=f+Math.imul(G,_e)|0,f=f+Math.imul(B,at)|0,u=u+Math.imul(B,_e)|0,w=w+Math.imul(x,lt)|0,f=f+Math.imul(x,ve)|0,f=f+Math.imul(F,lt)|0,u=u+Math.imul(F,ve)|0,w=w+Math.imul(ie,ut)|0,f=f+Math.imul(ie,we)|0,f=f+Math.imul(C,ut)|0,u=u+Math.imul(C,we)|0,w=w+Math.imul(q,ct)|0,f=f+Math.imul(q,be)|0,f=f+Math.imul($,ct)|0,u=u+Math.imul($,be)|0;var zt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(zt>>>26)|0,zt&=67108863,w=Math.imul(Ce,ze),f=Math.imul(Ce,de),f=f+Math.imul(ue,ze)|0,u=Math.imul(ue,de),w=w+Math.imul(Ee,ot)|0,f=f+Math.imul(Ee,me)|0,f=f+Math.imul(ce,ot)|0,u=u+Math.imul(ce,me)|0,w=w+Math.imul(ee,st)|0,f=f+Math.imul(ee,ge)|0,f=f+Math.imul(te,st)|0,u=u+Math.imul(te,ge)|0,w=w+Math.imul(Z,at)|0,f=f+Math.imul(Z,_e)|0,f=f+Math.imul(H,at)|0,u=u+Math.imul(H,_e)|0,w=w+Math.imul(G,lt)|0,f=f+Math.imul(G,ve)|0,f=f+Math.imul(B,lt)|0,u=u+Math.imul(B,ve)|0,w=w+Math.imul(x,ut)|0,f=f+Math.imul(x,we)|0,f=f+Math.imul(F,ut)|0,u=u+Math.imul(F,we)|0,w=w+Math.imul(ie,ct)|0,f=f+Math.imul(ie,be)|0,f=f+Math.imul(C,ct)|0,u=u+Math.imul(C,be)|0,w=w+Math.imul(q,dt)|0,f=f+Math.imul(q,ye)|0,f=f+Math.imul($,dt)|0,u=u+Math.imul($,ye)|0;var Xt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,w=Math.imul(et,ze),f=Math.imul(et,de),f=f+Math.imul(fe,ze)|0,u=Math.imul(fe,de),w=w+Math.imul(Ce,ot)|0,f=f+Math.imul(Ce,me)|0,f=f+Math.imul(ue,ot)|0,u=u+Math.imul(ue,me)|0,w=w+Math.imul(Ee,st)|0,f=f+Math.imul(Ee,ge)|0,f=f+Math.imul(ce,st)|0,u=u+Math.imul(ce,ge)|0,w=w+Math.imul(ee,at)|0,f=f+Math.imul(ee,_e)|0,f=f+Math.imul(te,at)|0,u=u+Math.imul(te,_e)|0,w=w+Math.imul(Z,lt)|0,f=f+Math.imul(Z,ve)|0,f=f+Math.imul(H,lt)|0,u=u+Math.imul(H,ve)|0,w=w+Math.imul(G,ut)|0,f=f+Math.imul(G,we)|0,f=f+Math.imul(B,ut)|0,u=u+Math.imul(B,we)|0,w=w+Math.imul(x,ct)|0,f=f+Math.imul(x,be)|0,f=f+Math.imul(F,ct)|0,u=u+Math.imul(F,be)|0,w=w+Math.imul(ie,dt)|0,f=f+Math.imul(ie,ye)|0,f=f+Math.imul(C,dt)|0,u=u+Math.imul(C,ye)|0,w=w+Math.imul(q,ht)|0,f=f+Math.imul(q,Me)|0,f=f+Math.imul($,ht)|0,u=u+Math.imul($,Me)|0;var Jt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,w=Math.imul(Ye,ze),f=Math.imul(Ye,de),f=f+Math.imul(he,ze)|0,u=Math.imul(he,de),w=w+Math.imul(et,ot)|0,f=f+Math.imul(et,me)|0,f=f+Math.imul(fe,ot)|0,u=u+Math.imul(fe,me)|0,w=w+Math.imul(Ce,st)|0,f=f+Math.imul(Ce,ge)|0,f=f+Math.imul(ue,st)|0,u=u+Math.imul(ue,ge)|0,w=w+Math.imul(Ee,at)|0,f=f+Math.imul(Ee,_e)|0,f=f+Math.imul(ce,at)|0,u=u+Math.imul(ce,_e)|0,w=w+Math.imul(ee,lt)|0,f=f+Math.imul(ee,ve)|0,f=f+Math.imul(te,lt)|0,u=u+Math.imul(te,ve)|0,w=w+Math.imul(Z,ut)|0,f=f+Math.imul(Z,we)|0,f=f+Math.imul(H,ut)|0,u=u+Math.imul(H,we)|0,w=w+Math.imul(G,ct)|0,f=f+Math.imul(G,be)|0,f=f+Math.imul(B,ct)|0,u=u+Math.imul(B,be)|0,w=w+Math.imul(x,dt)|0,f=f+Math.imul(x,ye)|0,f=f+Math.imul(F,dt)|0,u=u+Math.imul(F,ye)|0,w=w+Math.imul(ie,ht)|0,f=f+Math.imul(ie,Me)|0,f=f+Math.imul(C,ht)|0,u=u+Math.imul(C,Me)|0,w=w+Math.imul(q,ft)|0,f=f+Math.imul(q,Ae)|0,f=f+Math.imul($,ft)|0,u=u+Math.imul($,Ae)|0;var Yt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,w=Math.imul(Ye,ot),f=Math.imul(Ye,me),f=f+Math.imul(he,ot)|0,u=Math.imul(he,me),w=w+Math.imul(et,st)|0,f=f+Math.imul(et,ge)|0,f=f+Math.imul(fe,st)|0,u=u+Math.imul(fe,ge)|0,w=w+Math.imul(Ce,at)|0,f=f+Math.imul(Ce,_e)|0,f=f+Math.imul(ue,at)|0,u=u+Math.imul(ue,_e)|0,w=w+Math.imul(Ee,lt)|0,f=f+Math.imul(Ee,ve)|0,f=f+Math.imul(ce,lt)|0,u=u+Math.imul(ce,ve)|0,w=w+Math.imul(ee,ut)|0,f=f+Math.imul(ee,we)|0,f=f+Math.imul(te,ut)|0,u=u+Math.imul(te,we)|0,w=w+Math.imul(Z,ct)|0,f=f+Math.imul(Z,be)|0,f=f+Math.imul(H,ct)|0,u=u+Math.imul(H,be)|0,w=w+Math.imul(G,dt)|0,f=f+Math.imul(G,ye)|0,f=f+Math.imul(B,dt)|0,u=u+Math.imul(B,ye)|0,w=w+Math.imul(x,ht)|0,f=f+Math.imul(x,Me)|0,f=f+Math.imul(F,ht)|0,u=u+Math.imul(F,Me)|0,w=w+Math.imul(ie,ft)|0,f=f+Math.imul(ie,Ae)|0,f=f+Math.imul(C,ft)|0,u=u+Math.imul(C,Ae)|0;var Qt=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,w=Math.imul(Ye,st),f=Math.imul(Ye,ge),f=f+Math.imul(he,st)|0,u=Math.imul(he,ge),w=w+Math.imul(et,at)|0,f=f+Math.imul(et,_e)|0,f=f+Math.imul(fe,at)|0,u=u+Math.imul(fe,_e)|0,w=w+Math.imul(Ce,lt)|0,f=f+Math.imul(Ce,ve)|0,f=f+Math.imul(ue,lt)|0,u=u+Math.imul(ue,ve)|0,w=w+Math.imul(Ee,ut)|0,f=f+Math.imul(Ee,we)|0,f=f+Math.imul(ce,ut)|0,u=u+Math.imul(ce,we)|0,w=w+Math.imul(ee,ct)|0,f=f+Math.imul(ee,be)|0,f=f+Math.imul(te,ct)|0,u=u+Math.imul(te,be)|0,w=w+Math.imul(Z,dt)|0,f=f+Math.imul(Z,ye)|0,f=f+Math.imul(H,dt)|0,u=u+Math.imul(H,ye)|0,w=w+Math.imul(G,ht)|0,f=f+Math.imul(G,Me)|0,f=f+Math.imul(B,ht)|0,u=u+Math.imul(B,Me)|0,w=w+Math.imul(x,ft)|0,f=f+Math.imul(x,Ae)|0,f=f+Math.imul(F,ft)|0,u=u+Math.imul(F,Ae)|0;var ei=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ei>>>26)|0,ei&=67108863,w=Math.imul(Ye,at),f=Math.imul(Ye,_e),f=f+Math.imul(he,at)|0,u=Math.imul(he,_e),w=w+Math.imul(et,lt)|0,f=f+Math.imul(et,ve)|0,f=f+Math.imul(fe,lt)|0,u=u+Math.imul(fe,ve)|0,w=w+Math.imul(Ce,ut)|0,f=f+Math.imul(Ce,we)|0,f=f+Math.imul(ue,ut)|0,u=u+Math.imul(ue,we)|0,w=w+Math.imul(Ee,ct)|0,f=f+Math.imul(Ee,be)|0,f=f+Math.imul(ce,ct)|0,u=u+Math.imul(ce,be)|0,w=w+Math.imul(ee,dt)|0,f=f+Math.imul(ee,ye)|0,f=f+Math.imul(te,dt)|0,u=u+Math.imul(te,ye)|0,w=w+Math.imul(Z,ht)|0,f=f+Math.imul(Z,Me)|0,f=f+Math.imul(H,ht)|0,u=u+Math.imul(H,Me)|0,w=w+Math.imul(G,ft)|0,f=f+Math.imul(G,Ae)|0,f=f+Math.imul(B,ft)|0,u=u+Math.imul(B,Ae)|0;var ti=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ti>>>26)|0,ti&=67108863,w=Math.imul(Ye,lt),f=Math.imul(Ye,ve),f=f+Math.imul(he,lt)|0,u=Math.imul(he,ve),w=w+Math.imul(et,ut)|0,f=f+Math.imul(et,we)|0,f=f+Math.imul(fe,ut)|0,u=u+Math.imul(fe,we)|0,w=w+Math.imul(Ce,ct)|0,f=f+Math.imul(Ce,be)|0,f=f+Math.imul(ue,ct)|0,u=u+Math.imul(ue,be)|0,w=w+Math.imul(Ee,dt)|0,f=f+Math.imul(Ee,ye)|0,f=f+Math.imul(ce,dt)|0,u=u+Math.imul(ce,ye)|0,w=w+Math.imul(ee,ht)|0,f=f+Math.imul(ee,Me)|0,f=f+Math.imul(te,ht)|0,u=u+Math.imul(te,Me)|0,w=w+Math.imul(Z,ft)|0,f=f+Math.imul(Z,Ae)|0,f=f+Math.imul(H,ft)|0,u=u+Math.imul(H,Ae)|0;var ii=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ii>>>26)|0,ii&=67108863,w=Math.imul(Ye,ut),f=Math.imul(Ye,we),f=f+Math.imul(he,ut)|0,u=Math.imul(he,we),w=w+Math.imul(et,ct)|0,f=f+Math.imul(et,be)|0,f=f+Math.imul(fe,ct)|0,u=u+Math.imul(fe,be)|0,w=w+Math.imul(Ce,dt)|0,f=f+Math.imul(Ce,ye)|0,f=f+Math.imul(ue,dt)|0,u=u+Math.imul(ue,ye)|0,w=w+Math.imul(Ee,ht)|0,f=f+Math.imul(Ee,Me)|0,f=f+Math.imul(ce,ht)|0,u=u+Math.imul(ce,Me)|0,w=w+Math.imul(ee,ft)|0,f=f+Math.imul(ee,Ae)|0,f=f+Math.imul(te,ft)|0,u=u+Math.imul(te,Ae)|0;var ri=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ri>>>26)|0,ri&=67108863,w=Math.imul(Ye,ct),f=Math.imul(Ye,be),f=f+Math.imul(he,ct)|0,u=Math.imul(he,be),w=w+Math.imul(et,dt)|0,f=f+Math.imul(et,ye)|0,f=f+Math.imul(fe,dt)|0,u=u+Math.imul(fe,ye)|0,w=w+Math.imul(Ce,ht)|0,f=f+Math.imul(Ce,Me)|0,f=f+Math.imul(ue,ht)|0,u=u+Math.imul(ue,Me)|0,w=w+Math.imul(Ee,ft)|0,f=f+Math.imul(Ee,Ae)|0,f=f+Math.imul(ce,ft)|0,u=u+Math.imul(ce,Ae)|0;var ni=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(ni>>>26)|0,ni&=67108863,w=Math.imul(Ye,dt),f=Math.imul(Ye,ye),f=f+Math.imul(he,dt)|0,u=Math.imul(he,ye),w=w+Math.imul(et,ht)|0,f=f+Math.imul(et,Me)|0,f=f+Math.imul(fe,ht)|0,u=u+Math.imul(fe,Me)|0,w=w+Math.imul(Ce,ft)|0,f=f+Math.imul(Ce,Ae)|0,f=f+Math.imul(ue,ft)|0,u=u+Math.imul(ue,Ae)|0;var oi=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(oi>>>26)|0,oi&=67108863,w=Math.imul(Ye,ht),f=Math.imul(Ye,Me),f=f+Math.imul(he,ht)|0,u=Math.imul(he,Me),w=w+Math.imul(et,ft)|0,f=f+Math.imul(et,Ae)|0,f=f+Math.imul(fe,ft)|0,u=u+Math.imul(fe,Ae)|0;var si=(b+w|0)+((f&8191)<<13)|0;b=(u+(f>>>13)|0)+(si>>>26)|0,si&=67108863,w=Math.imul(Ye,ft),f=Math.imul(Ye,Ae),f=f+Math.imul(he,ft)|0,u=Math.imul(he,Ae);var ai=(b+w|0)+((f&8191)<<13)|0;return b=(u+(f>>>13)|0)+(ai>>>26)|0,ai&=67108863,_[0]=Be,_[1]=Gt,_[2]=Vt,_[3]=Zt,_[4]=Kt,_[5]=Wt,_[6]=zt,_[7]=Xt,_[8]=Jt,_[9]=Yt,_[10]=Qt,_[11]=ei,_[12]=ti,_[13]=ii,_[14]=ri,_[15]=ni,_[16]=oi,_[17]=si,_[18]=ai,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 ae(){Y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(ae,Y),ae.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},ae.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 ae;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 Io>"u"||Io,wa)});var Po=dr((Ia,wn)=>{"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,ae,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=ae(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},ae=(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,le,Ee,ce=x.indexOf("."),pe=R,Ce=N;for(ce>=0&&(V=_,_=0,x=x.replace(".",""),Ee=new u(F),te=Ee.pow(x.length-ce),_=V,Ee.c=T(Q(P(te.c),te.e,"0"),10,L,C),Ee.e=Ee.c.length),le=T(x,F,L,B?(D=w,C):(D=C,w)),H=V=le.length;le[--V]==0;le.pop());if(!le[0])return D.charAt(0);if(ce<0?--H:(te.c=le,te.e=H,te.s=G,te=Y(te,Ee,pe,Ce,L),le=te.c,ee=te.r,H=te.e),Z=H+pe+1,ce=le[Z],V=L/2,ee=ee||Z<0||le[Z+1]!=null,ee=Ce<4?(ce!=null||ee)&&(Ce==0||Ce==(te.s<0?3:2)):ce>V||ce==V&&(Ce==4||ee||Ce==6&&le[Z-1]&1||Ce==(te.s<0?8:7)),Z<1||!le[0])x=ee?Q(D.charAt(1),-pe,D.charAt(0)):D.charAt(0);else{if(le.length=Z,ee)for(--L;++le[--Z]>L;)le[Z]=0,Z||(++H,le=[1].concat(le));for(V=le.length;!le[--V];);for(ce=0,x="";ce<=V;x+=D.charAt(le[ce++]));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,le=L/y|0;for(F=F.slice();ee--;)Z=F[ee]%y,H=F[ee]/y|0,B=le*Z+H*te,D=te*Z+B%y*y+V,V=(D/G|0)+(B/y|0)+le*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,le,Ee,ce,pe,Ce,ue,Se,et,fe,Re,Ye,he,Ie=F.s==L.s?1:-1,ze=F.c,de=L.c;if(!ze||!ze[0]||!de||!de[0])return new u(!F.s||!L.s||(ze?de&&ze[0]==de[0]:!de)?NaN:ze&&ze[0]==0||!de?Ie*0:Ie/0);for(ce=new u(Ie),pe=ce.c=[],H=F.e-L.e,Ie=G+H+1,D||(D=c,H=U(F.e/p)-U(L.e/p),Ie=Ie/p|0),V=0;de[V]==(ze[V]||0);V++);if(de[V]>(ze[V]||0)&&H--,Ie<0)pe.push(1),ee=!0;else{for(fe=ze.length,Ye=de.length,V=0,Ie+=2,te=n(D/(de[0]+1)),te>1&&(de=C(de,te,D),ze=C(ze,te,D),Ye=de.length,fe=ze.length),et=Ye,Ce=ze.slice(0,Ye),ue=Ce.length;ue<Ye;Ce[ue++]=0);he=de.slice(),he=[0].concat(he),Re=de[0],de[1]>=D/2&&Re++;do{if(te=0,Z=T(de,Ce,Ye,ue),Z<0){if(Se=Ce[0],Ye!=ue&&(Se=Se*D+(Ce[1]||0)),te=n(Se/Re),te>1)for(te>=D&&(te=D-1),le=C(de,te,D),Ee=le.length,ue=Ce.length;T(le,Ce,Ee,ue)==1;)te--,x(le,Ye<Ee?he:de,Ee,D),Ee=le.length,Z=1;else te==0&&(Z=te=1),le=de.slice(),Ee=le.length;if(Ee<ue&&(le=[0].concat(le)),x(Ce,le,ue,D),ue=Ce.length,Z==-1)for(;T(de,Ce,Ye,ue)<1;)te++,x(Ce,Ye<ue?he:de,ue,D),ue=Ce.length}else Z===0&&(te++,Ce=[0]);pe[V++]=te,Ce[0]?Ce[ue++]=ze[et]||0:(Ce=[ze[et]],ue=1)}while((et++<fe||Ce[0]!=null)&&Ie--);ee=Ce[0]!=null,pe[0]||pe.splice(0,1)}if(D==c){for(V=1,Ie=pe[0];Ie>=10;Ie/=10,V++);z(ce,G+(ce.e=V+H*p-1)+1,B,ee)}else ce.e=H,ce.r=+ee;return ce}})();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,le){return H=(le=le.toLowerCase())=="x"?16:le=="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,le,Ee,ce,pe,Ce=this,ue=Ce.c,Se=(C=new u(C,T)).c;if(!ue||!Se||!ue[0]||!Se[0])return!Ce.s||!C.s||ue&&!ue[0]&&!Se||Se&&!Se[0]&&!ue?C.c=C.e=C.s=null:(C.s*=Ce.s,!ue||!Se?C.c=C.e=null:(C.c=[0],C.e=0)),C;for(F=U(Ce.e/p)+U(C.e/p),C.s*=Ce.s,Z=ue.length,ee=Se.length,Z<ee&&(Ee=ue,ue=Se,Se=Ee,L=Z,Z=ee,ee=L),L=Z+ee,Ee=[];L--;Ee.push(0));for(ce=c,pe=y,L=ee;--L>=0;){for(x=0,te=Se[L]%pe,le=Se[L]/pe|0,B=Z,G=L+B;G>L;)H=ue[--B]%pe,V=ue[B]/pe|0,D=le*H+V*te,H=te*H+D%pe*pe+Ee[G]+x,x=(H/ce|0)+(D/pe|0)+le*V,Ee[G--]=H%ce;Ee[G]=x}return x?++F:Ee.splice(0,1),$(C,Ee,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,le=te?V.slice(1):V,Ee=le.length;if(Z&&(G=D,D=Z,Z=G,Ee-=G),D>0&&Ee>0){for(G=Ee%D||D,V=le.substr(0,G);G<Ee;G+=D)V+=H+le.substr(G,D);Z>0&&(V+=H+le.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,le=this,Ee=le.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(!Ee)return new u(le);for(T=new u(O),H=x=new u(O),F=Z=new u(O),te=P(Ee),G=T.e=te.length-le.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=le.s,G=G*2,ee=Y(H,F,G,N).minus(le).abs().comparedTo(Y(Z,x,G,N).minus(le).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=ae(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,ae,E=1,I=se.length,O=se[0]+"";E<I;){for(Y=se[E++]+"",ae=p-Y.length;ae--;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 ae,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(ae=I&&!I[0],E=O&&!O[0],ae||E)return ae?E?0:-N:R;if(R!=N)return R;if(ae=R<0,E=S==h,!I||!O)return E?0:!I^ae?1:-1;if(!E)return S>h^ae?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]^ae?1:-1;return S==h?0:S>h^ae?1:-1}function j(se,Y,ae,E){if(se<Y||se>ae||se!==n(se))throw Error(s+(E||"Argument")+(typeof se=="number"?se<Y||se>ae?" 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,ae){var E,I;if(Y<0){for(I=ae+".";++Y;I+=ae);se=I+se}else if(E=se.length,++Y>E){for(I=ae,Y-=E;--Y;I+=ae);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 wn<"u"&&wn.exports?wn.exports=t:(e||(e=typeof self<"u"&&self?self:window),e.BigNumber=t)})(Ia)});var Pa=dr((zg,Oa)=>{"use strict";var ka=Po(),Ta=Oa.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 ka||ka.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 Ta.stringify!="function"&&(Ta.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 Na=dr((Xg,xa)=>{"use strict";var bn=null,_c=/(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/,vc=/(?: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)/,wc=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 bn==null&&(bn=Po()),W.length>15?t.storeAsString?W:t.useNativeBigInt?BigInt(W):new bn(W):t.alwaysParseAsBig?t.useNativeBigInt?BigInt(P):new bn(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+'"'),_c.test(P)===!0?t.protoAction==="error"?a("Object contains forbidden prototype property"):t.protoAction==="ignore"?A():W[P]=A():vc.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,ae=X[Q];return ae&&typeof ae=="object"&&Object.keys(ae).forEach(function(E){Y=K(ae,E),Y!==void 0?ae[E]=Y:delete ae[E]}),W.call(X,Q,ae)})({"":j},""):j}};xa.exports=wc});var Fa=dr((Jg,yn)=>{"use strict";var Ra=Pa().stringify,La=Na();yn.exports=function(e){return{parse:La(e),stringify:Ra}};yn.exports.parse=La();yn.exports.stringify=Ra});var Bl=dr(J=>{"use strict";var xo=vt("@mysten/sui/transactions"),bc=Fa(),pt=vt("@mysten/sui/utils"),Da=vt("@mysten/sui/client"),Ba=vt("@pythnetwork/pyth-sui-js");function yc(e){return e&&e.__esModule?e:{default:e}}var Mc=yc(bc),Ac=Object.create,qo=Object.defineProperty,Sc=Object.defineProperties,Cc=Object.getOwnPropertyDescriptor,Ec=Object.getOwnPropertyDescriptors,Qa=Object.getOwnPropertyNames,Ua=Object.getOwnPropertySymbols,Ic=Object.getPrototypeOf,el=Object.prototype.hasOwnProperty,kc=Object.prototype.propertyIsEnumerable,ja=(e,t,i)=>t in e?qo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Hr=(e,t)=>{for(var i in t||(t={}))el.call(t,i)&&ja(e,i,t[i]);if(Ua)for(var i of Ua(t))kc.call(t,i)&&ja(e,i,t[i]);return e},Sn=(e,t)=>Sc(e,Ec(t)),Tc=(e=>typeof vt<"u"?vt:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof vt<"u"?vt:t)[i]}):e)(function(e){if(typeof vt<"u")return vt.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),Oc=(e,t)=>function(){return t||(0,e[Qa(e)[0]])((t={exports:{}}).exports,t),t.exports},Pc=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Qa(t))!el.call(e,n)&&n!==i&&qo(e,n,{get:()=>t[n],enumerable:!(r=Cc(t,n))||r.enumerable});return e},wr=(e,t,i)=>(i=e!=null?Ac(Ic(e)):{},Pc(!e||!e.__esModule?qo(i,"default",{value:e,enumerable:!0}):i,e)),It=(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())}),br=Oc({"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=Tc("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,le=ee>>>13,Ee=m[6]|0,ce=Ee&8191,pe=Ee>>>13,Ce=m[7]|0,ue=Ce&8191,Se=Ce>>>13,et=m[8]|0,fe=et&8191,Re=et>>>13,Ye=m[9]|0,he=Ye&8191,Ie=Ye>>>13,ze=_[0]|0,de=ze&8191,Ue=ze>>>13,ot=_[1]|0,me=ot&8191,je=ot>>>13,st=_[2]|0,ge=st&8191,qe=st>>>13,at=_[3]|0,_e=at&8191,$e=at>>>13,lt=_[4]|0,ve=lt&8191,He=lt>>>13,ut=_[5]|0,we=ut&8191,Ge=ut>>>13,ct=_[6]|0,be=ct&8191,Ve=ct>>>13,dt=_[7]|0,ye=dt&8191,Ze=dt>>>13,ht=_[8]|0,Me=ht&8191,Ke=ht>>>13,ft=_[9]|0,Ae=ft&8191,Be=ft>>>13;d.negative=o.negative^l.negative,d.length=19,f=Math.imul($,de),u=Math.imul($,Ue),u=u+Math.imul(z,de)|0,M=Math.imul(z,Ue);var Gt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,f=Math.imul(C,de),u=Math.imul(C,Ue),u=u+Math.imul(T,de)|0,M=Math.imul(T,Ue),f=f+Math.imul($,me)|0,u=u+Math.imul($,je)|0,u=u+Math.imul(z,me)|0,M=M+Math.imul(z,je)|0;var Vt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,f=Math.imul(F,de),u=Math.imul(F,Ue),u=u+Math.imul(L,de)|0,M=Math.imul(L,Ue),f=f+Math.imul(C,me)|0,u=u+Math.imul(C,je)|0,u=u+Math.imul(T,me)|0,M=M+Math.imul(T,je)|0,f=f+Math.imul($,ge)|0,u=u+Math.imul($,qe)|0,u=u+Math.imul(z,ge)|0,M=M+Math.imul(z,qe)|0;var Zt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,f=Math.imul(B,de),u=Math.imul(B,Ue),u=u+Math.imul(D,de)|0,M=Math.imul(D,Ue),f=f+Math.imul(F,me)|0,u=u+Math.imul(F,je)|0,u=u+Math.imul(L,me)|0,M=M+Math.imul(L,je)|0,f=f+Math.imul(C,ge)|0,u=u+Math.imul(C,qe)|0,u=u+Math.imul(T,ge)|0,M=M+Math.imul(T,qe)|0,f=f+Math.imul($,_e)|0,u=u+Math.imul($,$e)|0,u=u+Math.imul(z,_e)|0,M=M+Math.imul(z,$e)|0;var Kt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,f=Math.imul(H,de),u=Math.imul(H,Ue),u=u+Math.imul(V,de)|0,M=Math.imul(V,Ue),f=f+Math.imul(B,me)|0,u=u+Math.imul(B,je)|0,u=u+Math.imul(D,me)|0,M=M+Math.imul(D,je)|0,f=f+Math.imul(F,ge)|0,u=u+Math.imul(F,qe)|0,u=u+Math.imul(L,ge)|0,M=M+Math.imul(L,qe)|0,f=f+Math.imul(C,_e)|0,u=u+Math.imul(C,$e)|0,u=u+Math.imul(T,_e)|0,M=M+Math.imul(T,$e)|0,f=f+Math.imul($,ve)|0,u=u+Math.imul($,He)|0,u=u+Math.imul(z,ve)|0,M=M+Math.imul(z,He)|0;var Wt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,f=Math.imul(te,de),u=Math.imul(te,Ue),u=u+Math.imul(le,de)|0,M=Math.imul(le,Ue),f=f+Math.imul(H,me)|0,u=u+Math.imul(H,je)|0,u=u+Math.imul(V,me)|0,M=M+Math.imul(V,je)|0,f=f+Math.imul(B,ge)|0,u=u+Math.imul(B,qe)|0,u=u+Math.imul(D,ge)|0,M=M+Math.imul(D,qe)|0,f=f+Math.imul(F,_e)|0,u=u+Math.imul(F,$e)|0,u=u+Math.imul(L,_e)|0,M=M+Math.imul(L,$e)|0,f=f+Math.imul(C,ve)|0,u=u+Math.imul(C,He)|0,u=u+Math.imul(T,ve)|0,M=M+Math.imul(T,He)|0,f=f+Math.imul($,we)|0,u=u+Math.imul($,Ge)|0,u=u+Math.imul(z,we)|0,M=M+Math.imul(z,Ge)|0;var zt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(zt>>>26)|0,zt&=67108863,f=Math.imul(ce,de),u=Math.imul(ce,Ue),u=u+Math.imul(pe,de)|0,M=Math.imul(pe,Ue),f=f+Math.imul(te,me)|0,u=u+Math.imul(te,je)|0,u=u+Math.imul(le,me)|0,M=M+Math.imul(le,je)|0,f=f+Math.imul(H,ge)|0,u=u+Math.imul(H,qe)|0,u=u+Math.imul(V,ge)|0,M=M+Math.imul(V,qe)|0,f=f+Math.imul(B,_e)|0,u=u+Math.imul(B,$e)|0,u=u+Math.imul(D,_e)|0,M=M+Math.imul(D,$e)|0,f=f+Math.imul(F,ve)|0,u=u+Math.imul(F,He)|0,u=u+Math.imul(L,ve)|0,M=M+Math.imul(L,He)|0,f=f+Math.imul(C,we)|0,u=u+Math.imul(C,Ge)|0,u=u+Math.imul(T,we)|0,M=M+Math.imul(T,Ge)|0,f=f+Math.imul($,be)|0,u=u+Math.imul($,Ve)|0,u=u+Math.imul(z,be)|0,M=M+Math.imul(z,Ve)|0;var Xt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,f=Math.imul(ue,de),u=Math.imul(ue,Ue),u=u+Math.imul(Se,de)|0,M=Math.imul(Se,Ue),f=f+Math.imul(ce,me)|0,u=u+Math.imul(ce,je)|0,u=u+Math.imul(pe,me)|0,M=M+Math.imul(pe,je)|0,f=f+Math.imul(te,ge)|0,u=u+Math.imul(te,qe)|0,u=u+Math.imul(le,ge)|0,M=M+Math.imul(le,qe)|0,f=f+Math.imul(H,_e)|0,u=u+Math.imul(H,$e)|0,u=u+Math.imul(V,_e)|0,M=M+Math.imul(V,$e)|0,f=f+Math.imul(B,ve)|0,u=u+Math.imul(B,He)|0,u=u+Math.imul(D,ve)|0,M=M+Math.imul(D,He)|0,f=f+Math.imul(F,we)|0,u=u+Math.imul(F,Ge)|0,u=u+Math.imul(L,we)|0,M=M+Math.imul(L,Ge)|0,f=f+Math.imul(C,be)|0,u=u+Math.imul(C,Ve)|0,u=u+Math.imul(T,be)|0,M=M+Math.imul(T,Ve)|0,f=f+Math.imul($,ye)|0,u=u+Math.imul($,Ze)|0,u=u+Math.imul(z,ye)|0,M=M+Math.imul(z,Ze)|0;var Jt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,f=Math.imul(fe,de),u=Math.imul(fe,Ue),u=u+Math.imul(Re,de)|0,M=Math.imul(Re,Ue),f=f+Math.imul(ue,me)|0,u=u+Math.imul(ue,je)|0,u=u+Math.imul(Se,me)|0,M=M+Math.imul(Se,je)|0,f=f+Math.imul(ce,ge)|0,u=u+Math.imul(ce,qe)|0,u=u+Math.imul(pe,ge)|0,M=M+Math.imul(pe,qe)|0,f=f+Math.imul(te,_e)|0,u=u+Math.imul(te,$e)|0,u=u+Math.imul(le,_e)|0,M=M+Math.imul(le,$e)|0,f=f+Math.imul(H,ve)|0,u=u+Math.imul(H,He)|0,u=u+Math.imul(V,ve)|0,M=M+Math.imul(V,He)|0,f=f+Math.imul(B,we)|0,u=u+Math.imul(B,Ge)|0,u=u+Math.imul(D,we)|0,M=M+Math.imul(D,Ge)|0,f=f+Math.imul(F,be)|0,u=u+Math.imul(F,Ve)|0,u=u+Math.imul(L,be)|0,M=M+Math.imul(L,Ve)|0,f=f+Math.imul(C,ye)|0,u=u+Math.imul(C,Ze)|0,u=u+Math.imul(T,ye)|0,M=M+Math.imul(T,Ze)|0,f=f+Math.imul($,Me)|0,u=u+Math.imul($,Ke)|0,u=u+Math.imul(z,Me)|0,M=M+Math.imul(z,Ke)|0;var Yt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,f=Math.imul(he,de),u=Math.imul(he,Ue),u=u+Math.imul(Ie,de)|0,M=Math.imul(Ie,Ue),f=f+Math.imul(fe,me)|0,u=u+Math.imul(fe,je)|0,u=u+Math.imul(Re,me)|0,M=M+Math.imul(Re,je)|0,f=f+Math.imul(ue,ge)|0,u=u+Math.imul(ue,qe)|0,u=u+Math.imul(Se,ge)|0,M=M+Math.imul(Se,qe)|0,f=f+Math.imul(ce,_e)|0,u=u+Math.imul(ce,$e)|0,u=u+Math.imul(pe,_e)|0,M=M+Math.imul(pe,$e)|0,f=f+Math.imul(te,ve)|0,u=u+Math.imul(te,He)|0,u=u+Math.imul(le,ve)|0,M=M+Math.imul(le,He)|0,f=f+Math.imul(H,we)|0,u=u+Math.imul(H,Ge)|0,u=u+Math.imul(V,we)|0,M=M+Math.imul(V,Ge)|0,f=f+Math.imul(B,be)|0,u=u+Math.imul(B,Ve)|0,u=u+Math.imul(D,be)|0,M=M+Math.imul(D,Ve)|0,f=f+Math.imul(F,ye)|0,u=u+Math.imul(F,Ze)|0,u=u+Math.imul(L,ye)|0,M=M+Math.imul(L,Ze)|0,f=f+Math.imul(C,Me)|0,u=u+Math.imul(C,Ke)|0,u=u+Math.imul(T,Me)|0,M=M+Math.imul(T,Ke)|0,f=f+Math.imul($,Ae)|0,u=u+Math.imul($,Be)|0,u=u+Math.imul(z,Ae)|0,M=M+Math.imul(z,Be)|0;var Qt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,f=Math.imul(he,me),u=Math.imul(he,je),u=u+Math.imul(Ie,me)|0,M=Math.imul(Ie,je),f=f+Math.imul(fe,ge)|0,u=u+Math.imul(fe,qe)|0,u=u+Math.imul(Re,ge)|0,M=M+Math.imul(Re,qe)|0,f=f+Math.imul(ue,_e)|0,u=u+Math.imul(ue,$e)|0,u=u+Math.imul(Se,_e)|0,M=M+Math.imul(Se,$e)|0,f=f+Math.imul(ce,ve)|0,u=u+Math.imul(ce,He)|0,u=u+Math.imul(pe,ve)|0,M=M+Math.imul(pe,He)|0,f=f+Math.imul(te,we)|0,u=u+Math.imul(te,Ge)|0,u=u+Math.imul(le,we)|0,M=M+Math.imul(le,Ge)|0,f=f+Math.imul(H,be)|0,u=u+Math.imul(H,Ve)|0,u=u+Math.imul(V,be)|0,M=M+Math.imul(V,Ve)|0,f=f+Math.imul(B,ye)|0,u=u+Math.imul(B,Ze)|0,u=u+Math.imul(D,ye)|0,M=M+Math.imul(D,Ze)|0,f=f+Math.imul(F,Me)|0,u=u+Math.imul(F,Ke)|0,u=u+Math.imul(L,Me)|0,M=M+Math.imul(L,Ke)|0,f=f+Math.imul(C,Ae)|0,u=u+Math.imul(C,Be)|0,u=u+Math.imul(T,Ae)|0,M=M+Math.imul(T,Be)|0;var ei=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,f=Math.imul(he,ge),u=Math.imul(he,qe),u=u+Math.imul(Ie,ge)|0,M=Math.imul(Ie,qe),f=f+Math.imul(fe,_e)|0,u=u+Math.imul(fe,$e)|0,u=u+Math.imul(Re,_e)|0,M=M+Math.imul(Re,$e)|0,f=f+Math.imul(ue,ve)|0,u=u+Math.imul(ue,He)|0,u=u+Math.imul(Se,ve)|0,M=M+Math.imul(Se,He)|0,f=f+Math.imul(ce,we)|0,u=u+Math.imul(ce,Ge)|0,u=u+Math.imul(pe,we)|0,M=M+Math.imul(pe,Ge)|0,f=f+Math.imul(te,be)|0,u=u+Math.imul(te,Ve)|0,u=u+Math.imul(le,be)|0,M=M+Math.imul(le,Ve)|0,f=f+Math.imul(H,ye)|0,u=u+Math.imul(H,Ze)|0,u=u+Math.imul(V,ye)|0,M=M+Math.imul(V,Ze)|0,f=f+Math.imul(B,Me)|0,u=u+Math.imul(B,Ke)|0,u=u+Math.imul(D,Me)|0,M=M+Math.imul(D,Ke)|0,f=f+Math.imul(F,Ae)|0,u=u+Math.imul(F,Be)|0,u=u+Math.imul(L,Ae)|0,M=M+Math.imul(L,Be)|0;var ti=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,f=Math.imul(he,_e),u=Math.imul(he,$e),u=u+Math.imul(Ie,_e)|0,M=Math.imul(Ie,$e),f=f+Math.imul(fe,ve)|0,u=u+Math.imul(fe,He)|0,u=u+Math.imul(Re,ve)|0,M=M+Math.imul(Re,He)|0,f=f+Math.imul(ue,we)|0,u=u+Math.imul(ue,Ge)|0,u=u+Math.imul(Se,we)|0,M=M+Math.imul(Se,Ge)|0,f=f+Math.imul(ce,be)|0,u=u+Math.imul(ce,Ve)|0,u=u+Math.imul(pe,be)|0,M=M+Math.imul(pe,Ve)|0,f=f+Math.imul(te,ye)|0,u=u+Math.imul(te,Ze)|0,u=u+Math.imul(le,ye)|0,M=M+Math.imul(le,Ze)|0,f=f+Math.imul(H,Me)|0,u=u+Math.imul(H,Ke)|0,u=u+Math.imul(V,Me)|0,M=M+Math.imul(V,Ke)|0,f=f+Math.imul(B,Ae)|0,u=u+Math.imul(B,Be)|0,u=u+Math.imul(D,Ae)|0,M=M+Math.imul(D,Be)|0;var ii=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,f=Math.imul(he,ve),u=Math.imul(he,He),u=u+Math.imul(Ie,ve)|0,M=Math.imul(Ie,He),f=f+Math.imul(fe,we)|0,u=u+Math.imul(fe,Ge)|0,u=u+Math.imul(Re,we)|0,M=M+Math.imul(Re,Ge)|0,f=f+Math.imul(ue,be)|0,u=u+Math.imul(ue,Ve)|0,u=u+Math.imul(Se,be)|0,M=M+Math.imul(Se,Ve)|0,f=f+Math.imul(ce,ye)|0,u=u+Math.imul(ce,Ze)|0,u=u+Math.imul(pe,ye)|0,M=M+Math.imul(pe,Ze)|0,f=f+Math.imul(te,Me)|0,u=u+Math.imul(te,Ke)|0,u=u+Math.imul(le,Me)|0,M=M+Math.imul(le,Ke)|0,f=f+Math.imul(H,Ae)|0,u=u+Math.imul(H,Be)|0,u=u+Math.imul(V,Ae)|0,M=M+Math.imul(V,Be)|0;var ri=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,f=Math.imul(he,we),u=Math.imul(he,Ge),u=u+Math.imul(Ie,we)|0,M=Math.imul(Ie,Ge),f=f+Math.imul(fe,be)|0,u=u+Math.imul(fe,Ve)|0,u=u+Math.imul(Re,be)|0,M=M+Math.imul(Re,Ve)|0,f=f+Math.imul(ue,ye)|0,u=u+Math.imul(ue,Ze)|0,u=u+Math.imul(Se,ye)|0,M=M+Math.imul(Se,Ze)|0,f=f+Math.imul(ce,Me)|0,u=u+Math.imul(ce,Ke)|0,u=u+Math.imul(pe,Me)|0,M=M+Math.imul(pe,Ke)|0,f=f+Math.imul(te,Ae)|0,u=u+Math.imul(te,Be)|0,u=u+Math.imul(le,Ae)|0,M=M+Math.imul(le,Be)|0;var ni=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,f=Math.imul(he,be),u=Math.imul(he,Ve),u=u+Math.imul(Ie,be)|0,M=Math.imul(Ie,Ve),f=f+Math.imul(fe,ye)|0,u=u+Math.imul(fe,Ze)|0,u=u+Math.imul(Re,ye)|0,M=M+Math.imul(Re,Ze)|0,f=f+Math.imul(ue,Me)|0,u=u+Math.imul(ue,Ke)|0,u=u+Math.imul(Se,Me)|0,M=M+Math.imul(Se,Ke)|0,f=f+Math.imul(ce,Ae)|0,u=u+Math.imul(ce,Be)|0,u=u+Math.imul(pe,Ae)|0,M=M+Math.imul(pe,Be)|0;var oi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,f=Math.imul(he,ye),u=Math.imul(he,Ze),u=u+Math.imul(Ie,ye)|0,M=Math.imul(Ie,Ze),f=f+Math.imul(fe,Me)|0,u=u+Math.imul(fe,Ke)|0,u=u+Math.imul(Re,Me)|0,M=M+Math.imul(Re,Ke)|0,f=f+Math.imul(ue,Ae)|0,u=u+Math.imul(ue,Be)|0,u=u+Math.imul(Se,Ae)|0,M=M+Math.imul(Se,Be)|0;var si=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(si>>>26)|0,si&=67108863,f=Math.imul(he,Me),u=Math.imul(he,Ke),u=u+Math.imul(Ie,Me)|0,M=Math.imul(Ie,Ke),f=f+Math.imul(fe,Ae)|0,u=u+Math.imul(fe,Be)|0,u=u+Math.imul(Re,Ae)|0,M=M+Math.imul(Re,Be)|0;var ai=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,f=Math.imul(he,Ae),u=Math.imul(he,Be),u=u+Math.imul(Ie,Ae)|0,M=Math.imul(Ie,Be);var rr=(w+f|0)+((u&8191)<<13)|0;return w=(M+(u>>>13)|0)+(rr>>>26)|0,rr&=67108863,b[0]=Gt,b[1]=Vt,b[2]=Zt,b[3]=Kt,b[4]=Wt,b[5]=zt,b[6]=Xt,b[7]=Jt,b[8]=Yt,b[9]=Qt,b[10]=ei,b[11]=ti,b[12]=ii,b[13]=ri,b[14]=ni,b[15]=oi,b[16]=si,b[17]=ai,b[18]=rr,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 ae(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()}ae.prototype._tmp=function(){var o=new a(null);return o.words=new Array(Math.ceil(this.n/13)),o},ae.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},ae.prototype.split=function(o,l){o.iushrn(this.n,0,l)},ae.prototype.imulK=function(o){return o.imul(this.k)};function E(){ae.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(E,ae),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(){ae.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(I,ae);function O(){ae.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(O,ae);function R(){ae.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(R,ae),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)}}),gt=wr(br()),mr=wr(br()),tl=(e=>(e.InvalidType="InvalidType",e))(tl||{}),il=(e=>(e.MissAggregatorPackage="MissAggregatorPackage",e.MissGlobalConfig="MissGlobalConfig",e.InvalidWallet="InvalidWallet",e.SimulateError="SimulateError",e))(il||{}),rl=(e=>(e.InsufficientBalance="InsufficientBalance",e.SimulateEventError="simulateEventError",e.CannotGetDecimals="CannotGetDecimals",e.MissCoinA="MissCoinA",e.MissCoinB="MissCoinB",e.MissTurbosFeeType="MissTurbosFeeType",e.MissAftermathLpSupplyType="MissAftermathLpSupplyType",e))(rl||{}),nl=(e=>(e[e.NumberTooLarge=1e3]="NumberTooLarge",e[e.RateLimitExceeded=1001]="RateLimitExceeded",e[e.InsufficientLiquidity=1002]="InsufficientLiquidity",e[e.HoneyPot=1003]="HoneyPot",e))(nl||{});function Mn(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 xc=class ol extends Error{constructor(t,i){super(t),this.message=t,this.errorCode=i}static isAggregatorErrorCode(t,i){return t instanceof ol&&t.errorCode===i}},Nc=0,sl=1,Rc=2;function qa(e,t){return e===t?Nc:e<t?sl:Rc}function Lc(e,t){let i=0,r=e.length<=t.length?e.length:t.length,n=qa(e.length,t.length);for(;i<r;){let s=qa(e.charCodeAt(i),t.charCodeAt(i));if(i+=1,s!==0)return s}return n}function Fc(e,t){return Lc(e,t)===sl}function No(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 Dc(e){return e.split("::")[0]}function _r(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=_r(i),g=Sn(Hr({},p),{type_arguments:n.map(v=>_r(v).source_address)});return g.type_arguments=g.type_arguments.map(v=>ci.isSuiCoin(v)?v:_r(v).source_address),g.source_address=No(g.full_address,g.type_arguments),g}let s=i.split("::"),c={full_address:i,address:i===$o||i===ul?"0x2":pt.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=No(c.full_address,c.type_arguments),c}catch{return{full_address:e,address:"",module:"",name:"",type_arguments:[],source_address:e}}}function Ro(e){return _r(e).source_address}function al(e){return e.toLowerCase().startsWith("0x")?pt.normalizeSuiObjectId(e):e}function ll(e){for(let t in e){let i=typeof e[t];if(i==="object")ll(e[t]);else if(i==="string"){let r=e[t];e[t]=al(r)}}}function Bc(e,t,i){return`${e}::${t}::${i}`}var Uc="0x2::coin::Coin",jc=/^0x2::coin::Coin<(.+)>$/,qc=1e3,$c=500,Hc=100,Gc=100,Vc=1e3,$o="0x2::sui::SUI",ul="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Zc="SUI",Kc=450,Wc="0x0000000000000000000000000000000000000005",ci=class Gi{static getCoinTypeArg(t){let i=t.type.match(jc);return i?i[1]:null}static isSUI(t){let i=Gi.getCoinTypeArg(t);return i?Gi.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`${Uc}<${t}>`}static getCoinAssets(t,i){let r=[];return i.forEach(n=>{Ro(n.coinAddress)===Ro(t)&&r.push(n)}),r}static isSuiCoin(t){return _r(t).full_address===$o}static selectCoinObjectIdGreaterThanOrEqual(t,i,r=[]){let n=Gi.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=Gi.sortByBalance(t.filter(g=>!r.includes(g.coinObjectId))),s=Gi.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:Gi.sortByBalance(c),remainingCoins:Gi.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 Oi(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 cl(e,t){return e.moveCall({target:"0x2::coin::zero",typeArguments:[t],arguments:[]})}function dl(e,t){e=Oi(e),t=Oi(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 zc(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 Xc(e){let t=/<([^>]*)>/,i=e.match(t);if(i)return i[1]}function Jc(e,t,i,r){let n=ci.getCoinAssets(r,t);if(i===BigInt(0))return ci.isSuiCoin(r)||n.length===0&&!ci.isSuiCoin(r)?{targetCoin:cl(e,r),isMintZeroCoin:!0,targetCoinAmount:0}:{targetCoin:e.object(n[0].coinObjectId),isMintZeroCoin:!1,targetCoinAmount:Number(n[0].balance.toString())};if(ci.calculateTotalBalance(n)<i)throw new AggregateError("Insufficient balance when build merge coin, coinType: "+r,"InsufficientBalance"+r);if(ci.isSuiCoin(r))return{targetCoin:e.splitCoins(e.gas,[e.pure.u64(i.toString())]),isMintZeroCoin:!0,targetCoinAmount:Number(i.toString())};let a=ci.sortByBalance(n);a.slice(0,3).reduce((A,k)=>A+k.balance,BigInt(0))<BigInt(i)&&(a=ci.sortByBalanceDes(n));let p=ci.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 Kr=wr(br()),sr=new Kr.default(0),Yc=new Kr.default(1),hl=new Kr.default(2),Qc=hl.pow(new Kr.default(128)),ed=new Kr.default("18446744073709551615"),Cn="18446744073709551615",td=1e9,id="aggregator",rd="CETUS",nd="DEEPBOOK",od="KRIYA",sd="FLOWX",ad="TURBOS",ld="AFTERMATH",ud="integrate",cd="cetus",dd="deepbook",hd="kriya",fd="utils",pd="pool",md="pay",gd="flowx_amm",_d="turbos",vd="aftermath",fl="custodian_v2",pl="clob_v2",wd="flash_swap",bd="flash_swap_with_partner",yd="repay_flash_swap",Md="repay_flash_swap_with_partner",Ad="flash_swap_a2b",Sd="flash_swap_b2a",Cd="flash_swap_with_partner_a2b",Ed="flash_swap_with_partner_b2a",Id="repay_flash_swap_a2b",kd="repay_flash_swap_b2a",Td="repay_flash_swap_with_partner_a2b",Od="repay_flash_swap_with_partner_b2a",Pd="swap_a2b",xd="swap_b2a",Nd="transfer_or_destroy_coin",Rd="check_coins_threshold",Ld="join_vec",Fd="transfer_account_cap",Dd="0x0000000000000000000000000000000000000000000000000000000000000006",Bd="0x1::coin::CoinInfo",Ud="0x1::coin::CoinStore",jd="0x2::coin::zero",ml="0x000000000000000000000000000000000000000000000000000000000000dee9",gl="0x000000000000000000000000000000000000000000000000000000000000dee9",qd="0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a",_l="0x550dcd6070230d8bf18d99d34e3b2ca1d3657b76cc80ffdacdb2b5d28d7e0124",$d="0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",Hd="0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a",Gd="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511",Vd="",Zd="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f",Kd="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",Wd="",zd="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",Xd="",Jd="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",Yd="",Qd="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",eh="",th="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278",ih="",Gr={AGGREGATOR_V3:"aggregator_v3"},rh="https://api-sui.cetus.zone/router_v3",nh="https://api-sui.cetus.zone/router_v2",oh={Testnet:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},Mainnet:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}},Pn={V2:{Mainnet:"0x8ae871505a80d8bf6bf9c05906cda6edfeea460c85bebe2e26a4313f5e67874a",Testnet:"0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"},V2_EXTEND:{Mainnet:"0x8a2f7a5b20665eeccc79de3aa37c3b6c473eca233ada1e1cd4678ec07d4d4073",Testnet:"0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"},V2_EXTEND2:{Mainnet:"0x5cb7499fc49c2642310e24a4ecffdbee00133f97e80e2b45bca90c64d55de880",Testnet:"0x0"}},Vr={Mainnet:"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",Testnet:"0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"},ki={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"}},Qe={FEE_DENOMINATOR:1e6,MAX_FEE_RATE:1e5,MAX_AMOUNT_IN:Cn,DEFAULT_PUBLISHED_AT:{Mainnet:"0x07c27e879ba9282506284b0fef26d393978906fc9496550d978c6f493dbfa3e5",Testnet:"0x0"}},vl=1010102;function sh(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 mr.default(e.amount_in.toString()),amountOut:new mr.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 wl(e,t,i,r,n){return It(this,null,function*(){let s;if(i.liquidityChanges&&i.liquidityChanges.length>0?s=yield lh(e,i):s=yield ah(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:Mn(p)}}}let a=Mc.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:Mn(1003)}};if(a.data!=null){let p=sh(a.data,i.byAmountIn);if(r>0&&n!=="0x0")if(i.byAmountIn){let g=p.amountOut.mul(new mr.default(r)).div(new mr.default(1e6));p.overlayFee=Number(g.toString()),p.amountOut=p.amountOut.sub(g)}else{let g=p.amountIn.mul(new mr.default(r)).div(new mr.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:Mn(1002)}}})}function ah(e,t,i){return It(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=Oi(r),k=Oi(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=${vl}`,console.log("url",U),yield fetch(U)}catch(r){return console.error(r),null}})}function lh(e,t){return It(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=Oi(i),k=Oi(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:vl};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 uh(e){return It(this,null,function*(){let t=`${e}/deepbookv3_config`;try{return(yield fetch(t)).json()}catch(i){return console.error("Error:",i),null}})}function Lo(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 bl=(e=>(e[e.Mainnet=0]="Mainnet",e[e.Testnet=1]="Testnet",e))(bl||{}),ch=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}},dh=wr(br()),gr=9e15,Wi=1e9,Fo="0123456789abcdef",En="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",In="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Do={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-gr,maxE:gr,crypto:!1},yl,Ti,Fe=!0,xn="[DecimalError] ",Ki=xn+"Invalid argument: ",Ml=xn+"Precision limit exceeded",Al=xn+"crypto unavailable",Sl="[object Decimal]",xt=Math.floor,yt=Math.pow,hh=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,fh=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,ph=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Cl=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,hi=1e7,xe=7,mh=9007199254740991,gh=En.length-1,Bo=In.length-1,ne={toStringTag:Sl};ne.absoluteValue=ne.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Te(e)};ne.ceil=function(){return Te(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(Ki+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())+xe,r.rounding=1,i=_h(r,Ol(r,i)),r.precision=e,r.rounding=t,Te(Ti==2||Ti==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(Fe=!1,s=v.s*yt(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=kt(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=yt(i,1/3),e=xt((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=it(g.plus(v).times(c),g.plus(p),a+2,1),kt(c.d).slice(0,a)===(i=kt(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(Te(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")&&(Te(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return Fe=!0,Te(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-xt(this.e/xe))*xe,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};ne.dividedBy=ne.div=function(e){return it(this,new this.constructor(e))};ne.dividedToIntegerBy=ne.divToInt=function(e){var t=this,i=t.constructor;return Te(it(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 Te(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/Rn(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=vr(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 Te(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=vr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/Rn(5,e)),n=vr(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,Te(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,it(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()?di(i,n,s):new i(0):new i(NaN):t.isZero()?di(i,n+4,s).times(.5):(i.precision=n+6,i.rounding=1,t=t.asin(),e=di(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,Fe=!1,i=i.times(i).minus(1).sqrt().plus(i),Fe=!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,Fe=!1,i=i.times(i).plus(1).sqrt().plus(i),Fe=!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?Te(new s(n),e,t,!0):(s.precision=i=r-n.e,n=it(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=di(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<=Bo)return a=di(v,y+4,A).times(.25),a.s=g.s,a}else{if(!g.s)return new v(NaN);if(y+4<=Bo)return a=di(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/xe+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(Fe=!1,t=Math.ceil(c/xe),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)),Fe=!0,Te(a,v.precision=y,v.rounding=A,!0)};ne.isFinite=function(){return!!this.d};ne.isInteger=ne.isInt=function(){return!!this.d&&xt(this.e/xe)>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(Fe=!1,c=y+k,a=Zi(g,c),r=t?kn(v,c+10):Zi(e,c),p=it(a,r,c,1),Zr(p.d,n=y,A))do if(c+=10,a=Zi(g,c),r=t?kn(v,c+10):Zi(e,c),p=it(a,r,c,1),!s){+kt(p.d).slice(n+1,n+15)+1==1e14&&(p=Te(p,y+1,0));break}while(Zr(p.d,n+=10,A));return Fe=!0,Te(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 Fe?Te(e,c,p):e}if(i=xt(e.e/xe),v=xt(k.e/xe),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/xe),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]=hi-1;--g[n],g[r]+=hi}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=Nn(g,i),Fe?Te(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]?Te(new r(i),r.precision,r.rounding):(Fe=!1,r.modulo==9?(t=it(i,e.abs(),0,3,1),t.s*=e.s):t=it(i,e,0,r.modulo,1),t=t.times(e),Fe=!0,i.minus(t))};ne.naturalExponential=ne.exp=function(){return Uo(this)};ne.naturalLogarithm=ne.ln=function(){return Zi(this)};ne.negated=ne.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Te(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)),Fe?Te(e,c,p):e;if(s=xt(y.e/xe),r=xt(e.e/xe),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/xe),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)/hi|0,g[n]%=hi;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=Nn(g,r),Fe?Te(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(Ki+e);return i.d?(t=El(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};ne.round=function(){var e=this,t=e.constructor;return Te(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())+xe,r.rounding=1,i=wh(r,Ol(r,i)),r.precision=e,r.rounding=t,Te(Ti>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(Fe=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=kt(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=xt((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(it(a,s,i+2,1)).times(.5),kt(s.d).slice(0,i)===(t=kt(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(Te(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")&&(Te(r,p+1,1),e=!r.times(r).eq(a));break}return Fe=!0,Te(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=it(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Te(Ti==2||Ti==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=xt(v.e/xe)+xt(e.e/xe),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%hi|0,t=c/hi|0;s[n]=(s[n]+t)%hi|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=Nn(s,i),Fe?Te(e,y.precision,y.rounding):e};ne.toBinary=function(e,t){return Ho(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:(Ft(e,0,Wi),t===void 0?t=r.rounding:Ft(t,0,8),Te(i,e+i.e+1,t))};ne.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=yi(r,!0):(Ft(e,0,Wi),t===void 0?t=n.rounding:Ft(t,0,8),r=Te(new n(r),e+1,t),i=yi(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=yi(n):(Ft(e,0,Wi),t===void 0?t=s.rounding:Ft(t,0,8),r=Te(new s(n),e+n.e+1,t),i=yi(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=El(U)-k.e-1,a=s%xe,t.d[0]=yt(10,a<0?xe+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(Ki+c);e=c.gt(t)?s>0?t:g:c}for(Fe=!1,c=new P(kt(U)),v=P.precision,P.precision=s=U.length*xe*2;y=it(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=it(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=it(g,r,s,1).minus(k).abs().cmp(it(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,Fe=!0,A};ne.toHexadecimal=ne.toHex=function(e,t){return Ho(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:Ft(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]?(Fe=!1,i=it(i,e,0,t,1).times(e),Fe=!0,Te(i)):(e.s=i.s,i=e),i};ne.toNumber=function(){return+this};ne.toOctal=function(e,t){return Ho(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(yt(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return Te(c,r,s);if(t=xt(e.e/xe),t>=e.d.length-1&&(i=g<0?-g:g)<=mh)return n=Il(p,c,i,r),e.s<0?new p(1).div(n):Te(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=yt(+c,g),t=i==0||!isFinite(i)?xt(g*(Math.log("0."+kt(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):(Fe=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=Uo(e.times(Zi(c,r+i)),r),n.d&&(n=Te(n,r+5,1),Zr(n.d,r,s)&&(t=r+10,n=Te(Uo(e.times(Zi(c,t+i)),t),t+5,1),+kt(n.d).slice(r+1,r+15)+1==1e14&&(n=Te(n,r+1,0)))),n.s=a,Fe=!0,p.rounding=s,Te(n,r,s))};ne.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=yi(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Ft(e,1,Wi),t===void 0?t=n.rounding:Ft(t,0,8),r=Te(new n(r),e,t),i=yi(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):(Ft(e,1,Wi),t===void 0?t=r.rounding:Ft(t,0,8)),Te(new r(i),e,t)};ne.toString=function(){var e=this,t=e.constructor,i=yi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};ne.truncated=ne.trunc=function(){return Te(new this.constructor(this),this.e+1,1)};ne.valueOf=ne.toJSON=function(){var e=this,t=e.constructor,i=yi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function kt(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=xe-r.length,i&&(s+=Vi(i)),s+=r;a=e[t],r=a+"",i=xe-r.length,i&&(s+=Vi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Ft(e,t,i){if(e!==~~e||e<t||e>i)throw Error(Ki+e)}function Zr(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=xe,n=0):(n=Math.ceil((t+1)/xe),t%=xe),s=yt(10,xe-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)==yt(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)==yt(10,t-3)-1,a}function An(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]+=Fo.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 _h(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/Rn(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=vr(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 it=(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,ae,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=hi,k=xe,v=xt(r.e/k)-xt(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++)ae=A*p+(o[y]||0),K[y]=ae/l|0,A=ae%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,yl=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,Te(j,c?s+j.e+1:s,a,U)}return j}})();function Te(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+=xe,a=t,v=y[A=0],p=v/yt(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/xe),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=xe,a=s-xe+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=xe,a=s-xe+n,p=a<0?0:v/yt(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%yt(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/yt(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]=yt(10,(xe-t%xe)%xe),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=yt(10,xe-s),y[A]=a>0?(v/yt(10,n-a)%yt(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]==hi&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=hi)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return Fe&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function yi(e,t,i){if(!e.isFinite())return Tl(e);var r,n=e.e,s=kt(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+Vi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+Vi(-n-1)+s,i&&(r=i-a)>0&&(s+=Vi(r))):n>=a?(s+=Vi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+Vi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=Vi(r))),s}function Nn(e,t){var i=e[0];for(t*=xe;i>=10;i/=10)t++;return t}function kn(e,t,i){if(t>gh)throw Fe=!0,i&&(e.precision=i),Error(Ml);return Te(new e(En),t,1,!0)}function di(e,t,i){if(t>Bo)throw Error(Ml);return Te(new e(In),t,i,!0)}function El(e){var t=e.length-1,i=t*xe+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 Vi(e){for(var t="";e--;)t+="0";return t}function Il(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/xe+4);for(Fe=!1;;){if(i%2&&(s=s.times(t),Ha(s.d,a)&&(n=!0)),i=xt(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 Fe=!0,s}function $a(e){return e.d[e.d.length-1]&1}function kl(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 Uo(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?(Fe=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(yt(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=Te(s.times(e),p,1),i=i.times(++v),c=a.plus(it(s,i,p,1)),kt(c.d).slice(0,p)===kt(a.d).slice(0,p)){for(n=y;n--;)a=Te(a.times(a),p,1);if(t==null)if(g<3&&Zr(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return Te(a,A.precision=U,k,Fe=!0);else return A.precision=U,a}a=c}}function Zi(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?(Fe=!1,v=X):v=t,j.precision=v+=U,i=kt(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=kt(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=kn(j,v+2,X).times(s+""),P=Zi(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?Te(P,X,K,Fe=!0):P;for(y=P,p=a=P=it(P.minus(1),P.plus(1),v,1),A=Te(P.times(P),v,1),n=3;;){if(a=Te(a.times(A),v,1),g=p.plus(it(a,new j(n),v,1)),kt(g.d).slice(0,v)===kt(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(kn(j,v+2,X).times(s+""))),p=it(p,new j(k),v,1),t==null)if(Zr(p.d,v-U,K,c))j.precision=v+=U,g=a=P=it(y.minus(1),y.plus(1),v,1),A=Te(P.times(P),v,1),n=c=1;else return Te(p,j.precision=X,K,Fe=!0);else return j.precision=X,p;p=g,n+=2}}function Tl(e){return String(e.s*e.s/0)}function jo(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)%xe,i<0&&(r+=xe),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=xe;r<n;)e.d.push(+t.slice(r,r+=xe));t=t.slice(r),r=xe-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),Fe&&(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 vh(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Cl.test(t))return jo(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(fh.test(t))i=16,t=t.toLowerCase();else if(hh.test(t))i=2;else if(ph.test(t))i=8;else throw Error(Ki+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=Il(r,new r(i),s,s*2)),g=An(t,i,hi),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=Nn(g,v),e.d=g,Fe=!1,a&&(e=it(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?yt(2,p):Wr.pow(2,p))),Fe=!0,e)}function wh(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:vr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/Rn(5,i)),t=vr(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 vr(e,t,i,r,n){var s,a,c,p,g=e.precision,v=Math.ceil(g/xe);for(Fe=!1,p=i.times(i),c=new e(r);;){if(a=it(c.times(p),new e(t++*t++),g,1),c=n?r.plus(a):r.minus(a),r=it(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 Fe=!0,a.d.length=v+1,a}function Rn(e,t){for(var i=e;--t;)i*=e;return i}function Ol(e,t){var i,r=t.s<0,n=di(e,e.precision,1),s=n.times(.5);if(t=t.abs(),t.lte(s))return Ti=r?4:1,t;if(i=t.divToInt(n),i.isZero())Ti=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Ti=$a(i)?r?2:3:r?4:1,t;Ti=$a(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?(Ft(i,1,Wi),r===void 0?r=k.rounding:Ft(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=Tl(e);else{for(v=yi(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=An(yi(A),10,n),A.e=A.d.length),y=An(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=it(e,A,i,r,0,n),y=e.d,s=e.e,g=yl),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+=Fo.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=An(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=Fo.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 bh(e){return new this(e).abs()}function yh(e){return new this(e).acos()}function Mh(e){return new this(e).acosh()}function Ah(e,t){return new this(e).plus(t)}function Sh(e){return new this(e).asin()}function Ch(e){return new this(e).asinh()}function Eh(e){return new this(e).atan()}function Ih(e){return new this(e).atanh()}function kh(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=di(this,s,1).times(t.s>0?.25:.75),i.s=e.s):!t.d||e.isZero()?(i=t.s<0?di(this,r,n):new this(0),i.s=e.s):!e.d||t.isZero()?(i=di(this,s,1).times(.5),i.s=e.s):t.s<0?(this.precision=s,this.rounding=1,i=this.atan(it(e,t,s,1)),t=di(this,s,1),this.precision=r,this.rounding=n,i=e.s<0?i.minus(t):i.plus(t)):i=this.atan(it(e,t,s,1)),i}function Th(e){return new this(e).cbrt()}function Oh(e){return Te(e=new this(e),e.e+1,2)}function Ph(e,t,i){return new this(e).clamp(t,i)}function xh(e){if(!e||typeof e!="object")throw Error(xn+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,Wi,"rounding",0,8,"toExpNeg",-gr,0,"toExpPos",0,gr,"maxE",0,gr,"minE",-gr,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(i=s[t],n&&(this[i]=Do[i]),(r=e[i])!==void 0)if(xt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(Ki+i+": "+r);if(i="crypto",n&&(this[i]=Do[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(Al);else this[i]=!1;else throw Error(Ki+i+": "+r);return this}function Nh(e){return new this(e).cos()}function Rh(e){return new this(e).cosh()}function Pl(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,Ga(s)){g.s=s.s,Fe?!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++;Fe?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 jo(g,s.toString())}else if(p!=="string")throw Error(Ki+s);return(c=s.charCodeAt(0))===45?(s=s.slice(1),g.s=-1):(c===43&&(s=s.slice(1)),g.s=1),Cl.test(s)?jo(g,s):vh(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=xh,n.clone=Pl,n.isDecimal=Ga,n.abs=bh,n.acos=yh,n.acosh=Mh,n.add=Ah,n.asin=Sh,n.asinh=Ch,n.atan=Eh,n.atanh=Ih,n.atan2=kh,n.cbrt=Th,n.ceil=Oh,n.clamp=Ph,n.cos=Nh,n.cosh=Rh,n.div=Lh,n.exp=Fh,n.floor=Dh,n.hypot=Bh,n.ln=Uh,n.log=jh,n.log10=$h,n.log2=qh,n.max=Hh,n.min=Gh,n.mod=Vh,n.mul=Zh,n.pow=Kh,n.random=Wh,n.round=zh,n.sign=Xh,n.sin=Jh,n.sinh=Yh,n.sqrt=Qh,n.sub=ef,n.sum=tf,n.tan=rf,n.tanh=nf,n.trunc=of,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 Lh(e,t){return new this(e).div(t)}function Fh(e){return new this(e).exp()}function Dh(e){return Te(e=new this(e),e.e+1,3)}function Bh(){var e,t,i=new this(0);for(Fe=!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 Fe=!0,new this(1/0);i=t}return Fe=!0,i.sqrt()}function Ga(e){return e instanceof Wr||e&&e.toStringTag===Sl||!1}function Uh(e){return new this(e).ln()}function jh(e,t){return new this(e).log(t)}function qh(e){return new this(e).log(2)}function $h(e){return new this(e).log(10)}function Hh(){return kl(this,arguments,"lt")}function Gh(){return kl(this,arguments,"gt")}function Vh(e,t){return new this(e).mod(t)}function Zh(e,t){return new this(e).mul(t)}function Kh(e,t){return new this(e).pow(t)}function Wh(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Ft(e,1,Wi),r=Math.ceil(e/xe),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(Al);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=xe,r&&e&&(n=yt(10,xe-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-=xe)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<xe&&(i-=xe-r)}return a.e=i,a.d=c,a}function zh(e){return Te(e=new this(e),e.e+1,this.rounding)}function Xh(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Jh(e){return new this(e).sin()}function Yh(e){return new this(e).sinh()}function Qh(e){return new this(e).sqrt()}function ef(e,t){return new this(e).sub(t)}function tf(){var e=0,t=arguments,i=new this(t[e]);for(Fe=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return Fe=!0,Te(i,this.precision,this.rounding)}function rf(e){return new this(e).tan()}function nf(e){return new this(e).tanh()}function of(e){return Te(e=new this(e),e.e+1,1)}ne[Symbol.for("nodejs.util.inspect.custom")]=ne.toString;ne[Symbol.toStringTag]="Decimal";var Wr=ne.constructor=Pl(Do);En=new Wr(En);In=new Wr(In);var Tn=Wr;function sf(e,t,i){return Number(xl(new Tn(e.toString()),t,i).toFixed(0))}function Va(e,t,i){let r=xl(new Tn(e.toString()),t,i);return new dh.default(r.toFixed(0))}function xl(e,t,i){return t?e.mul(1-i):e.mul(1+i)}var Za=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?Qe.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(pt.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(pt.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})}},af=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::kriya_clmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},lf=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::flowx_clmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},uf=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::turbos::swap`,typeArguments:[t.coinAType,t.coinBType,t.feeType],arguments:r})}},cf=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::bluefin::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},df=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::momentum::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},hf=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::magma::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},ff=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?Qe.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})}},pf=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?Qe.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})}},mf=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?Qe.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})}},gf=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::deepbookv3::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:s})}getDeepFeeType(){return this.env===0?Vr.Mainnet:Vr.Testnet}},_f=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})}},vf=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?Qe.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(pt.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})}},wf=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?Qe.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(pt.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})}},Ka=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?Qe.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})}},bf=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::haedal_hmm::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},yf=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::obric::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},Mf=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?Qe.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(pt.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(pt.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})}},Af=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?Qe.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(pt.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(pt.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(pt.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})}},Sf=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?Qe.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(pt.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(pt.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(pt.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})}},Cf="0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI",Ef="0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD",If="0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH",kf=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?Qe.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 Cf:{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 Ef:case If:{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(pt.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})}},Tf=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?Qe.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})}},Of=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?Qe.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})}},Pf=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?Qe.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})}},xf=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?Qe.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})}},Nf=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?Qe.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})}},Rf=Qe.DEFAULT_PUBLISHED_AT.Mainnet;function zr(e,t){return e&&e.has(Gr.AGGREGATOR_V3)?e.get(Gr.AGGREGATOR_V3):t||Rf}function Wa(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=zr(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 za(e,t){let{swapContext:i,targetCoinType:r,aggregatorPublishedAt:n,packages:s}=e,a=zr(s,n);return t.moveCall({target:`${a}::router::confirm_swap`,typeArguments:[r],arguments:[i]})}function Lf(e,t){let{coinType:i,amount:r,swapCtx:n,aggregatorPublishedAt:s,packages:a}=e,c=zr(a,s),p=[n,t.pure.u64(r.toString())];return t.moveCall({target:`${c}::router::take_balance`,typeArguments:[i],arguments:p})}function Ff(e,t){let{balance:i,coinType:r,recipient:n,aggregatorPublishedAt:s,packages:a}=e,c=zr(a,s),p=[i,t.pure.address(n)];t.moveCall({target:`${c}::router::transfer_balance`,typeArguments:[r],arguments:p})}function Df(e,t){let{coin:i,coinType:r,aggregatorPublishedAt:n,packages:s}=e,a=zr(s,n);t.moveCall({target:`${a}::router::transfer_or_destroy_coin`,typeArguments:[r],arguments:[i]})}function Bf(){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 Uf(){let e=Date.now(),t=Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");return`downgrade_${e.toString(16)}_${t}`}function Nl(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 jf(e){if(!Nl(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 qf(e,t,i){return It(this,null,function*(){let r=yield $f(t,i);return r!==null?{accountCap:e.object(r),isCreate:!1}:{accountCap:e.moveCall({target:`${gl}::${pl}::create_account`,typeArguments:[],arguments:[]}),isCreate:!0}})}function $f(e,t){return It(this,null,function*(){let i=50,r=null;for(;;){let n=e.getOwnedObjects({owner:t,cursor:r,limit:i,filter:{MoveModule:{package:ml,module:fl}}});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 Hf(e,t){return t?.has("aggregator_v2")?t.get("aggregator_v2"):e||Pn.V2.Mainnet}function Gf(e,t){return t?.has("aggregator_v2_extend")?t.get("aggregator_v2_extend"):e||Pn.V2_EXTEND.Mainnet}function Vf(e,t){return t?.has("aggregator_v2_extend2")?t.get("aggregator_v2_extend2"):e||Pn.V2_EXTEND2.Mainnet}var Bt=wr(br());function Zf(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:Kf(r),gasUsed:r.computationCost||"0",gasPrice:"1000",success:!0}}function Kf(e){let t=new Bt.default(e.computationCost||"0"),i=new Bt.default(e.storageCost||"0"),r=new Bt.default(e.storageRebate||"0"),n=new Bt.default(e.nonRefundableStorageFee||"0");return t.add(i).sub(r).add(n).toString()}function Wf(e,t){let i=new Bt.default(t);return i.isZero()?0:e.div(i).toNumber()}function zf(e,t,i=1){let r=e.mul(new Bt.default(Math.floor(i*1e6))).div(new Bt.default(1e6));return r.isZero()?0:r.sub(t).mul(new Bt.default(1e4)).div(r).toNumber()/100}function Xf(e,t){let i=e.filter(c=>c.gasMetrics.success),r=t.filter(c=>c.gasMetrics.success),n=Xa(i),s=Xa(r),a=n.isZero()?0:n.sub(s).mul(new Bt.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 Xa(e){return e.length===0?new Bt.default(0):e.reduce((i,r)=>i.add(new Bt.default(r.gasMetrics.totalGasCost)),new Bt.default(0)).div(new Bt.default(e.length))}function Jf(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 Yf(e){return JSON.stringify(e,null,2)}function Qf(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 Ja=wr(br()),ep=e=>{var t,i,r;return Sn(Hr({},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=Sn(Hr({},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})})},tp=e=>{var t;return Sn(Hr({},e),{amountIn:new Ja.default(e?.amountIn),amountOut:new Ja.default(e?.amountIn),paths:(t=e?.paths)==null?void 0:t.map(r=>{var n,s,a,c;let p=Hr({},r);return r?.initialPrice&&(p.initialPrice=new Tn((n=r?.initialPrice)==null?void 0:n.toString())),(s=r?.extendedDetails)!=null&&s.after_sqrt_price&&(p.extendedDetails={after_sqrt_price:new Tn((c=(a=r?.extendedDetails)==null?void 0:a.after_sqrt_price)==null?void 0:c.toString())}),p})})};function ip(e,t=!0){return It(this,null,function*(){console.log("inputs",e.getData().inputs),e.getData().commands.forEach((i,r)=>{t&&console.log(`transaction ${r}: `,JSON.stringify(i,rp,2))})})}function rp(e,t){return typeof t=="bigint"?t.toString():t}function np(e){return!(!e.startsWith("0x")||e.length!==66)}var op=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::haedal_hmm_v2::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},sp=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?Qe.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(pt.SUI_CLOCK_OBJECT_ID)];e.moveCall({target:`${t.publishedAt}::fullsail::swap`,typeArguments:[t.coinAType,t.coinBType],arguments:r})}},On="CETUS",ap="DEEPBOOK",Go="KRIYA",Vo="FLOWX",Zo="FLOWXV3",Ko="KRIYAV3",Wo="TURBOS",zo="AFTERMATH",Xo="HAEDAL",Jo="VOLO",Yo="AFSUI",Qo="BLUEMOVE",es="DEEPBOOKV3",ts="SCALLOP",is="SUILEND",rs="BLUEFIN",Ln="HAEDALPMM",ns="ALPHAFI",os="SPRINGSUI",ss="STEAMM",Fn="METASTABLE",Dn="OBRIC",as="HAWAL",Bn="STEAMM_OMM",ls="MOMENTUM",Un="STEAMM_OMM_V2",us="MAGMA",jn="SEVENK",qn="HAEDALHMMV2",cs="FULLSAIL",Ll="https://api-sui.cetus.zone/router_v3",$n=[On,Go,Vo,Zo,Ko,Wo,zo,Xo,Jo,Yo,Qo,es,ts,is,rs,Ln,ns,os,ss,Fn,Dn,as,ls,Bn,Un,us,jn,qn,cs];function lp(){return $n}function up(e){return $n.filter(t=>!e.includes(t))}function cp(e){return $n.filter(t=>e.includes(t))}function Ya(e){let t=new Set;for(let i of e){if(i.provider===Ln&&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===Fn&&(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===Dn&&(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===Bn||i.provider===Un)&&(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===jn&&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===qn&&i.extendedDetails&&i.extendedDetails.haedalhmmv2_base_price_seed&&t.add(i.extendedDetails.haedalhmmv2_base_price_seed)}return Array.from(t)}var Fl=class Dl{constructor(t){var i,r;this.endpoint=t.endpoint?Rl(t.endpoint):Ll,this.client=t.client||new Da.SuiClient({url:Da.getFullnodeUrl("mainnet")}),this.signer=t.signer||"",this.env=t.env||0;let n=Dl.CONFIG[this.env];if(this.pythConnections=this.newPythClients((i=t.pythUrls)!=null?i:[]),this.pythClient=new Ba.SuiPythClient(this.client,n.pythStateId,n.wormholeStateId),this.apiKey=t.apiKey||"",this.partner=t.partner,t.overlayFeeRate)if(t.overlayFeeRate>0&&t.overlayFeeRate<=ki.MAX_OVERLAY_FEE_RATE){if(this.overlayFeeRate=t.overlayFeeRate*Qe.FEE_DENOMINATOR,this.overlayFeeRate>Qe.MAX_FEE_RATE)throw new Error(ki.ERRORS.INVALID_OVERLAY_FEE_RATE)}else throw new Error(ki.ERRORS.INVALID_OVERLAY_FEE_RATE);else this.overlayFeeRate=0;this.overlayFeeReceiver=(r=t.overlayFeeReceiver)!=null?r:ki.DEFAULT_OVERLAY_FEE_RECEIVER}newPythClients(t){return t.includes("https://hermes.pyth.network")||t.push("https://hermes.pyth.network"),t.map(r=>new Ba.SuiPriceServiceConnection(r,{timeout:3e3}))}deepbookv3DeepFeeType(){return this.env===0?Vr.Mainnet:Vr.Testnet}getOneCoinUsedToMerge(t){return It(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 It(this,null,function*(){return wl(this.endpoint,this.apiKey,t,this.overlayFeeRate,this.overlayFeeReceiver)})}executeFlexibleInputSwap(t,i,r,n,s,a,c,p,g){return It(this,null,function*(){})}newDexRouterV3(t,i,r){switch(t){case On:return new Za(this.env,r);case Ko:return new af(this.env);case Zo:return new lf(this.env);case Wo:return new uf(this.env);case rs:return new cf(this.env);case ls:return new df(this.env);case us:return new hf(this.env);case Go:return new ff(this.env);case Vo:return new pf(this.env);case Qo:return new mf(this.env);case es:return new gf(this.env);case zo:return new _f(this.env);case ss:return new vf(this.env);case ts:return new wf(this.env);case is:return new Ka(this.env);case os:return new Ka(this.env);case Ln:return new bf(this.env,i);case Dn:return new yf(this.env,i);case jn:return new Mf(this.env,i);case Bn:return new Af(this.env,i);case Un:return new Sf(this.env,i);case Fn:return new kf(this.env,i);case ns:return new Tf(this.env);case Jo:return new Of(this.env);case Yo:return new Pf(this.env);case Xo:return new xf(this.env);case as:return new Nf(this.env);case qn:return new op(this.env,i);case cs:return new sp(this.env);default:throw new Error(`${ki.ERRORS.UNSUPPORTED_DEX} ${t}`)}}expectInputSwapV3(t,i,r,n,s,a,c){if(r.quoteID==null)throw new Error(ki.ERRORS.QUOTE_ID_REQUIRED);let p=Lo(r),g=Wa({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 za({swapContext:g,targetCoinType:p.targetCoinType,packages:p.packages},t)}expectOutputSwapV3(t,i,r,n,s,a){let c=[],p=new Za(this.env,a),g=Lo(r),v=Wa({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=fp(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=Lf({coinType:g.fromCoinType,amount:Cn,swapCtx:v,packages:g.packages},t);return Ff({balance:U,coinType:g.fromCoinType,recipient:this.signer,packages:g.packages},t),za({swapContext:v,targetCoinType:g.targetCoinType,packages:g.packages},t)}routerSwap(t){return It(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(ki.ERRORS.INVALID_SLIPPAGE);let p=t.router.byAmountIn,g=i.amountIn,v=i.amountOut,y=new gt.default(0);this.overlayFeeRate>0&&this.overlayFeeReceiver!=="0x0"&&(p?y=v.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)):y=g.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)));let A=p?v.sub(y):v,k=p?g:g.add(y),U=Va(p?A:k,p,n);if(!t.router.packages||!t.router.packages.get(Gr.AGGREGATOR_V3))throw new Error(ki.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 It(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 gt.default(this.overlayFeeRate)).div(new gt.default(1e6)).toString()):v=Number(i.amountIn.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)).toString()));let y=g?i.amountOut.sub(new gt.default(v)):i.amountOut,A=g?i.amountIn:i.amountIn.add(new gt.default(v)),k=sf(g?y:A,g,r),U=g?A:k,P=xo.coinWithBalance({balance:BigInt(U.toString()),useGasCoin:!0,type:c}),W;a&&a>0&&(W=xo.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(ci.isSuiCoin(p))n.mergeCoins(n.gas,[K]);else{let X=yield this.getOneCoinUsedToMerge(p);X!=null?n.mergeCoins(n.object(X),[K]):Df({coin:K,coinType:p,packages:i.packages},n)}})}fixableRouterSwapV3(t){return It(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 gt.default(this.overlayFeeRate)).div(new gt.default(1e6)).toString()):p=Number(i.amountIn.mul(new gt.default(this.overlayFeeRate)).div(new gt.default(1e6)).toString()));let g=i.byAmountIn?i.amountOut.sub(new gt.default(p)):i.amountOut,v=i.byAmountIn?i.amountIn:i.amountIn.add(new gt.default(p)),y=Va(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 It(this,null,function*(){var i,r,n,s;let{from:a,target:c,amount:p,byAmountIn:g,pools:v}=t,y=Oi(a),A=Oi(c),k=new xo.Transaction,U=dl(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 gt.default(0):new gt.default(Cn),Y=0;for(let l=0;l<Q.length;l+=1)if(!Q[l].parsedJson.data.is_exceed)if(t.byAmountIn){let d=new gt.default(Q[l].parsedJson.data.amount_out);d.gt(se)&&(Y=l,se=d)}else{let d=new gt.default(Q[l].parsedJson.data.amount_out);d.lt(se)&&(Y=l,se=d)}let ae=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(ae.fee_rate)/1e6,R=new gt.default((r=ae.amount_in)!=null?r:0),N=new gt.default((n=ae.fee_amount)!=null?n:0),S=R.add(N),h={amountIn:S,amountOut:new gt.default((s=ae.amount_out)!=null?s:0),paths:[{id:v[Y],direction:U,provider:On,from:y,target:A,feeRate:O,amountIn:S.toString(),amountOut:ae.amount_out,publishedAt:_l,extendedDetails:{afterSqrtPrice:ae.after_sqrt_price}}],insufficientLiquidity:!1,byAmountIn:t.byAmountIn,quoteID:`degraded-${hp()}`,packages:new Map([[Gr.AGGREGATOR_V3,Qe.DEFAULT_PUBLISHED_AT.Mainnet]])};return{isExceed:ae.is_exceed,routeData:h}})}updatePythPriceIDs(t,i){return It(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 It(this,null,function*(){return yield this.client.devInspectTransactionBlock({transactionBlock:t,sender:this.signer})})}sendTransaction(t,i){return It(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:t,signer:i})})}};Fl.CONFIG={1:{wormholeStateId:"0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",pythStateId:"0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"},0:{wormholeStateId:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",pythStateId:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"}};var dp=Fl;function hp(){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 fp(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 pp=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=Yo;J.AFTERMATH=zo;J.AFTERMATH_AMM=ld;J.AFTERMATH_MODULE=vd;J.AGGREGATOR=id;J.AGGREGATOR_V3_CONFIG=Qe;J.ALL_DEXES=$n;J.ALPHAFI=ns;J.AggregatorClient=dp;J.AggregatorConfig=ch;J.AggregatorError=xc;J.AggregatorServerErrorCode=nl;J.BLUEFIN=rs;J.BLUEMOVE=Qo;J.CETUS=On;J.CETUS_DEX=rd;J.CETUS_MODULE=cd;J.CETUS_PUBLISHED_AT=qd;J.CETUS_V3_PUBLISHED_AT=_l;J.CHECK_COINS_THRESHOLD_FUNC=Rd;J.CLIENT_CONFIG=ki;J.CLOCK_ADDRESS=Dd;J.CoinInfoAddress=Bd;J.CoinStoreAddress=Ud;J.CoinUtils=ci;J.ConfigErrorCode=il;J.DEEPBOOKV2=ap;J.DEEPBOOKV3=es;J.DEEPBOOK_CLOB_V2_MODULE=pl;J.DEEPBOOK_CUSTODIAN_V2_MODULE=fl;J.DEEPBOOK_DEX=nd;J.DEEPBOOK_MODULE=dd;J.DEEPBOOK_PACKAGE_ID=ml;J.DEEPBOOK_PUBLISHED_AT=gl;J.DEEPBOOK_V3_DEEP_FEE_TYPES=Vr;J.DEFAULT_AGG_V2_ENDPOINT=nh;J.DEFAULT_AGG_V3_ENDPOINT=rh;J.DEFAULT_ENDPOINT=Ll;J.DEFAULT_GAS_BUDGET_FOR_MERGE=$c;J.DEFAULT_GAS_BUDGET_FOR_SPLIT=qc;J.DEFAULT_GAS_BUDGET_FOR_STAKE=Vc;J.DEFAULT_GAS_BUDGET_FOR_TRANSFER=Hc;J.DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI=Gc;J.DEFAULT_NFT_TRANSFER_GAS_FEE=Kc;J.Env=bl;J.FLOWXV2=Vo;J.FLOWXV3=Zo;J.FLOWX_AMM=sd;J.FLOWX_AMM_MODULE=gd;J.FULLSAIL=cs;J.FlashSwapA2BFunc=Ad;J.FlashSwapB2AFunc=Sd;J.FlashSwapFunc=wd;J.FlashSwapWithPartnerA2BFunc=Cd;J.FlashSwapWithPartnerB2AFunc=Ed;J.FlashSwapWithPartnerFunc=bd;J.GAS_SYMBOL=Zc;J.GAS_TYPE_ARG=$o;J.GAS_TYPE_ARG_LONG=ul;J.HAEDAL=Xo;J.HAEDALHMMV2=qn;J.HAEDALPMM=Ln;J.HAWAL=as;J.INTEGRATE=ud;J.JOIN_FUNC=Ld;J.KRIYA=Go;J.KRIYAV3=Ko;J.KRIYA_DEX=od;J.KRIYA_MODULE=hd;J.MAGMA=us;J.MAINNET_AFTERMATH_INSURANCE_FUND_ID=Qd;J.MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=zd;J.MAINNET_AFTERMATH_REFERRAL_VAULT_ID=th;J.MAINNET_AFTERMATH_REGISTRY_ID=Kd;J.MAINNET_AFTERMATH_TREASURY_ID=Jd;J.MAINNET_CETUS_GLOBAL_CONFIG_ID=$d;J.MAINNET_FLOWX_AMM_CONTAINER_ID=Gd;J.METASTABLE=Fn;J.MOMENTUM=ls;J.OBRIC=Dn;J.ONE=Yc;J.PACKAGE_NAMES=Gr;J.PAY_MODULE=md;J.POOL_MODULT=pd;J.PUBLISHED_ADDRESSES=Pn;J.PYTH_CONFIG=oh;J.REPAY_FLASH_SWAP_A2B_FUNC=Id;J.REPAY_FLASH_SWAP_B2A_FUNC=kd;J.REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC=Td;J.REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC=Od;J.RepayFalshSwapFunc=yd;J.RepayFlashSwapWithPartnerFunc=Md;J.SCALLOP=ts;J.SEVENK=jn;J.SPRINGSUI=os;J.STEAMM=ss;J.STEAMM_OMM=Bn;J.STEAMM_OMM_V2=Un;J.SUILEND=is;J.SUI_SYSTEM_STATE_OBJECT_ID=Wc;J.SWAP_A2B_FUNC=Pd;J.SWAP_B2A_FUNC=xd;J.SuiZeroCoinFn=jd;J.TEN_POW_NINE=td;J.TESTNET_AFTERMATH_INSURANCE_FUND_ID=eh;J.TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID=Xd;J.TESTNET_AFTERMATH_REFERRAL_VAULT_ID=ih;J.TESTNET_AFTERMATH_REGISTRY_ID=Wd;J.TESTNET_AFTERMATH_TREASURY_ID=Yd;J.TESTNET_CETUS_GLOBAL_CONFIG_ID=Hd;J.TESTNET_FLOWX_AMM_CONTAINER_ID=Vd;J.TRANSFER_ACCOUNT_CAP=Fd;J.TRANSFER_OR_DESTORY_COIN_FUNC=Nd;J.TURBOS=Wo;J.TURBOS_DEX=ad;J.TURBOS_MODULE=_d;J.TURBOS_VERSIONED=Zd;J.TWO=hl;J.TransactionErrorCode=rl;J.TypesErrorCode=tl;J.U128=Qc;J.U64_MAX=Cn;J.U64_MAX_BN=ed;J.UTILS_MODULE=fd;J.VOLO=Jo;J.ZERO=sr;J.buildInputCoin=Jc;J.calculateGasEfficiency=Wf;J.calculatePriceImpact=zf;J.checkInvalidSuiAddress=np;J.compareCoins=dl;J.compareGasMetrics=Xf;J.completionCoin=Oi;J.composeType=No;J.createTarget=Bc;J.dealWithFastRouterSwapParamsForMsafe=ep;J.exportToCSV=Qf;J.exportToJSON=Yf;J.extractAddressFromType=Dc;J.extractGasMetrics=Zf;J.extractStructTagFromType=_r;J.extractTimestampFromDowngradeUuid6=jf;J.fixSuiObjectId=al;J.formatGasMetrics=Jf;J.generateDowngradeUuid6=Bf;J.generateSimpleDowngradeUuid6=Uf;J.getAggregatorServerErrorMessage=Mn;J.getAggregatorV2Extend2PublishedAt=Vf;J.getAggregatorV2ExtendPublishedAt=Gf;J.getAggregatorV2PublishedAt=Hf;J.getAllProviders=lp;J.getDeepbookV3Config=uh;J.getDefaultSuiInputType=pp;J.getOrCreateAccountCap=qf;J.getProvidersExcluding=up;J.getProvidersIncluding=cp;J.getRouterResult=wl;J.isSortedSymbols=Fc;J.isValidDowngradeUuid6=Nl;J.mintZeroCoin=cl;J.normalizeCoinType=Ro;J.parseAftermathFeeType=Xc;J.parseTurbosPoolFeeType=zc;J.patchFixSuiObjectId=ll;J.printTransaction=ip;J.processEndpoint=Rl;J.processFlattenRoutes=Lo;J.restituteMsafeFastRouterSwapParams=tp});import{SdkWrapper as Y1}from"@cetusprotocol/common-sdk";import{DefaultProviders as Qu,FullRpcUrlMainnet as e0}from"@cetusprotocol/common-sdk";var Vs={full_rpc_url:e0,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:Qu,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"}}};import{SuilendClient as d0}from"@suilend/sdk/client";import{initializeSuilend as h0,initializeSuilendRewards as f0,initializeObligations as p0,formatRewards as m0,Side as ia,getFilteredRewards as g0,getStakingYieldAprPercent as _0,getDedupedPerDayRewards as v0,getDedupedAprRewards as w0,getTotalAprPercent as ra,getNetAprPercent as b0}from"@suilend/sdk";var t0=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,mo=Math.ceil,$t=Math.floor,Rt="[BigNumber Error] ",Zs=Rt+"Number primitive has more than 15 significant digits: ",li=1e14,We=14,go=9007199254740991,_o=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Di=1e7,At=1e9;function Ks(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(!t0.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(_t(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(Zs+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>go||E!==$t(E)))throw Error(Zs+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)%We,S<0&&(h+=We),h<l){for(h&&m.c.push(+d.slice(0,h)),l-=We;h<l;)m.c.push(+d.slice(h,h+=We));h=We-(d=d.slice(h)).length}else h-=l;for(;h--;d+="0");m.c.push(+d)}}else m.c=[m.e=0]}K.clone=Ks,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],_t(O,0,At,I),a=O),E.hasOwnProperty(I="ROUNDING_MODE")&&(O=E[I],_t(O,0,8,I),c=O),E.hasOwnProperty(I="EXPONENTIAL_AT")&&(O=E[I],O&&O.pop?(_t(O[0],-At,0,I),_t(O[1],0,At,I),p=O[0],g=O[1]):(_t(O,-At,At,I),p=-(g=O<0?-O:O))),E.hasOwnProperty(I="RANGE"))if(O=E[I],O&&O.pop)_t(O[0],-At,-1,I),_t(O[1],1,At,I),v=O[0],y=O[1];else if(_t(O,-At,At,I),O)v=-(y=O<0?-O:O);else throw Error(Rt+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(Rt+"crypto unavailable");else A=O;else throw Error(Rt+I+" not true or false: "+O);if(E.hasOwnProperty(I="MODULO_MODE")&&(O=E[I],_t(O,0,9,I),k=O),E.hasOwnProperty(I="POW_PRECISION")&&(O=E[I],_t(O,0,At,I),U=O),E.hasOwnProperty(I="FORMAT"))if(O=E[I],typeof O=="object")P=O;else throw Error(Rt+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(Rt+I+" invalid: "+O)}else throw Error(Rt+"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>=-At&&N<=At&&N===$t(N)){if(R[0]===0){if(N===0&&R.length===1)return!0;break e}if(I=(N+1)%We,I<1&&(I+=We),String(R[0]).length==I){for(I=0;I<R.length;I++)if(O=R[I],O<0||O>=li||O!==$t(O))break e;if(O!==0)return!0}}}else if(R===null&&N===null&&(S===null||S===1||S===-1))return!0;throw Error(Rt+"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 $t(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:_t(O,0,At),h=mo(O/We),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(Rt+"crypto unavailable");if(!A)for(;l<h;)o=I(),o<9e15&&(d[l++]=o%1e14);for(h=d[--l],O%=We,h&&O&&(o=_o[We-O],d[l]=$t(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-=We);for(l=1,o=d[0];o>=10;o/=10,l++);l<We&&(S-=We-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(Ei(qt(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=_?Ei(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=Ei(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%Di,w=N/Di|0;for(R=R.slice();_--;)l=R[_]%Di,d=R[_]/Di|0,h=w*l+d*b,o=b*l+h%Di*Di+m,m=(o/S|0)+(h/Di|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=li,d=Ht(R.e/We)-Ht(N.e/We),L=L/We|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=$t(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=$t(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==li){for(m=1,L=M[0];L>=10;L/=10,m++);Y(u,S+(u.e=m+d*We-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:_t(O,0,8),!E.c)return E.toString();if(N=E.c[0],h=E.e,I==null)l=qt(E.c),l=R==1||R==2&&(h<=p||h>=g)?on(l,h):Ei(l,h,"0");else if(E=Y(new K(E),I,O),S=E.e,l=qt(E.c),o=l.length,R==1||R==2&&(I<=S||S<=p)){for(;o<I;l+="0",o++);l=on(l,S)}else if(I-=h+(R===2&&S>h),l=Ei(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=nr(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*We-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(Rt+"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=_o;if(_){e:{for(N=1,o=_[0];o>=10;o/=10,N++);if(S=I-N,S<0)S+=We,h=I,l=_[d=0],m=$t(l/b[N-h-1]%10);else if(d=mo((S+1)/We),d>=_.length)if(R){for(;_.length<=d;_.push(0));l=m=0,N=1,S%=We,h=S-We+1}else break e;else{for(l=o=_[d],N=1;o>=10;o/=10,N++);S%=We,h=S-We+N,m=h<0?0:$t(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[(We-I%We)%We],E.e=-I||0):_[0]=E.e=0,E;if(S==0?(_.length=d,o=1,d--):(_.length=d+1,o=b[We-S],_[d]=h>0?$t(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]==li&&(_[0]=1));break}else{if(_[d]+=o,_[d]!=li)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 ae(E){var I,O=E.e;return O===null?E.toString():(I=qt(E.c),I=O<=p||O>=g?on(I,O):Ei(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 nr(this,new K(E,I))},n.decimalPlaces=n.dp=function(E,I){var O,R,N,S=this;if(E!=null)return _t(E,0,At),I==null?I=c:_t(I,0,8),Y(new K(S),E+S.e+1,I);if(!(O=S.c))return null;if(R=((N=O.length-1)-Ht(this.e/We))*We,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(Rt+"Exponent not an integer: "+ae(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(+ae(_),o?E.s*(2-nn(E)):+ae(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&&nn(E)?-0:0,_.e>-1&&(S=1/S),new K(l?1/S:S);U&&(S=mo(U/We+2))}for(o?(O=new K(.5),l&&(E.s=1),d=nn(E)):(N=Math.abs(+ae(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=$t(N/2),N===0)break;d=N%2}else if(E=E.times(O),Y(E,E.e+1,1),E.e>14)d=nn(E);else{if(N=+ae(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:_t(E,0,8),Y(I,I.e+1,E)},n.isEqualTo=n.eq=function(E,I){return nr(this,new K(E,I))===0},n.isFinite=function(){return!!this.c},n.isGreaterThan=n.gt=function(E,I){return nr(this,new K(E,I))>0},n.isGreaterThanOrEqualTo=n.gte=function(E,I){return(I=nr(this,new K(E,I)))===1||I===0},n.isInteger=function(){return!!this.c&&Ht(this.e/We)>this.c.length-2},n.isLessThan=n.lt=function(E,I){return nr(this,new K(E,I))<0},n.isLessThanOrEqualTo=n.lte=function(E,I){return(I=nr(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/We,d=E.e/We,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=Ht(l),d=Ht(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=li-1;R>o;){if(m[--R]<_[R]){for(O=R;O&&!m[--O];m[O]=I);--m[O],m[R]+=li}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=Ht(q.e/We)+Ht(E.e/We),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=li,M=Di,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/We,h=E.e/We,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=Ht(S),h=Ht(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)/li|0,o[I]=li===o[I]?0:o[I]%li;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 _t(E,1,At),I==null?I=c:_t(I,0,8),Y(new K(S),E,I);if(!(O=S.c))return null;if(N=O.length-1,R=N*We+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 _t(E,-go,go),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(+ae(S)),o==0||o==1/0?(I=qt(h),(I.length+l)%2==0&&(I+="0"),o=Math.sqrt(+I),l=Ht((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))),qt(N.c).slice(0,o)===(I=qt(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&&(_t(E,0,At),E++),X(this,E,I,1)},n.toFixed=function(E,I){return E!=null&&(_t(E,0,At),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(Rt+"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(Rt+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+ae(o));if(!f)return new K(w);for(I=new K(s),d=O=new K(s),R=l=new K(s),b=qt(f),S=I.e=b.length-w.e-1,I.c[0]=_o[(h=S%We)<0?We+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+ae(this)},n.toPrecision=function(E,I){return E!=null&&_t(E,1,At),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?on(qt(O.c),N):Ei(qt(O.c),N,"0"):E===10&&j?(O=Y(new K(O),a+N+1,c),I=Ei(qt(O.c),O.e,"0")):(_t(E,2,W.length,"Base"),I=i(Ei(qt(O.c),N,"0"),10,E,R,!0)),R<0&&O.c[0]&&(I="-"+I)),I},n.valueOf=n.toJSON=function(){return ae(this)},n._isBigNumber=!0,n[Symbol.toStringTag]="BigNumber",n[Symbol.for("nodejs.util.inspect.custom")]=n.valueOf,e!=null&&K.set(e),K}function Ht(e){var t=e|0;return e>0||e===t?t:t-1}function qt(e){for(var t,i,r=1,n=e.length,s=e[0]+"";r<n;){for(t=e[r++]+"",i=We-t.length;i--;t="0"+t);s+=t}for(n=s.length;s.charCodeAt(--n)===48;);return s.slice(0,n+1||1)}function nr(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 _t(e,t,i,r){if(e<t||e>i||e!==$t(e))throw Error(Rt+(r||"Argument")+(typeof e=="number"?e<t||e>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function nn(e){var t=e.c.length-1;return Ht(e.e/We)==t&&e.c[t]%2!=0}function on(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function Ei(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 i0=Ks(),_i=i0;import{linearlyInterpolate as s0,Side as or}from"@suilend/sdk";import{NORMALIZED_flSUI_COINTYPE as a0,NORMALIZED_jugSUI_COINTYPE as l0,NORMALIZED_LBTC_COINTYPE as u0}from"@suilend/sui-fe";import r0 from"crypto";var an=new Uint8Array(256),sn=an.length;function vo(){return sn>an.length-16&&(r0.randomFillSync(an),sn=0),an.slice(sn,sn+=16)}var Ct=[];for(let e=0;e<256;++e)Ct.push((e+256).toString(16).slice(1));function Ws(e,t=0){return Ct[e[t+0]]+Ct[e[t+1]]+Ct[e[t+2]]+Ct[e[t+3]]+"-"+Ct[e[t+4]]+Ct[e[t+5]]+"-"+Ct[e[t+6]]+Ct[e[t+7]]+"-"+Ct[e[t+8]]+Ct[e[t+9]]+"-"+Ct[e[t+10]]+Ct[e[t+11]]+Ct[e[t+12]]+Ct[e[t+13]]+Ct[e[t+14]]+Ct[e[t+15]]}import n0 from"crypto";var wo={randomUUID:n0.randomUUID};function o0(e,t,i){if(wo.randomUUID&&!t&&!e)return wo.randomUUID();e=e||{};let r=e.random||(e.rng||vo)();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 ln=o0;import{getPackagerConfigs as c0}from"@cetusprotocol/common-sdk";var bo=10n;function zs(e){return e.depositedAmount.eq(0)?new _i(0):e.borrowedAmount.div(e.depositedAmount).times(100)}function yo(e){let t=zs(e);if(!t.gt(100))return s0(e.config.interestRate,"utilPercent","aprPercent",t)}function Xs(e){let t=zs(e),i=yo(e);if(!(i===void 0||t.gt(100)))return new _i(t.div(100)).times(i.div(100)).times(1-e.config.spreadFeeBps/1e4).times(100)}function Js(e,t,i,r){let{apiUrl:n}=c0(r.sdkOptions.suilend);e===or.DEPOSIT&&([a0,l0].includes(t.coinType)&&i.push({stats:{id:ln(),isActive:!0,rewardIndex:-1,reserve:t,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${n}/partners/LiqAg.png`,perDay:new _i(.036),side:or.DEPOSIT},obligationClaims:{}}),t.coinType===u0&&i.push({stats:{id:ln(),isActive:!0,rewardIndex:-1,reserve:t,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${n}/partners/Lombard Lux.png`,perDay:new _i(0),side:or.DEPOSIT},obligationClaims:{}}))}function Ys(e,t,i){return{...e,depositedAmount:t===or.DEPOSIT?_i.max(e.depositedAmount.plus(i),0):e.depositedAmount,borrowedAmount:t===or.BORROW?_i.max(e.borrowedAmount.plus(i),0):e.borrowedAmount}}function Qs(e,t,i){let r=e===or.DEPOSIT?t.depositedAmount:t.borrowedAmount,n=e===or.DEPOSIT?i.depositedAmount:i.borrowedAmount,s=n.eq(0)?new _i(-1):r.div(n);return{multiplier:s,isValid:!s.eq(-1)}}function ea(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 ta(e,t){if(!bo)throw new Error("oraclePriceMultiplierDecimal is required");if(e===0n)throw new Error("Invalid oracle price");if(t<0n){let i=10n**(bo- -t);return e*i}return e/10n**(t+bo)}import{d as Ur,getPackagerConfigs as hr,removeHexPrefix as na}from"@cetusprotocol/common-sdk";import{toHEX as y0}from"@mysten/sui/utils";var un=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(ae=>ae.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=g0(g);Js(p,a,v,this.sdk);let y=_0(p,a.coinType,n),A=p===ia.DEPOSIT?a.depositAprPercent:a.borrowAprPercent,k=A,U=Ys(a,p,i);k=p===ia.DEPOSIT?Xs(U):yo(U);let{multiplier:P,isValid:W}=Qs(p,a,U),j=v0(v),K=w0(v),{newPerDayRewards:X,newAprRewards:Q}=ea(j,K,P,W),se=ra(p,A,v,y),Y=k===void 0||Q.some(ae=>ae.stats.aprPercent===void 0)?void 0:ra(p,k,Q,y);return{borrowLimit:a.config.borrowLimit.toString(),borrowedAmount:a.borrowedAmount.toString(),remainingBorrowLimit:Ur(a.config.borrowLimit.toString()).sub(Ur(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}=hr(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(i,r)).createObligation(t)};this.refreshReservePrices=async(t,i,r)=>{let{lendingMarketId:n,lendingMarketType:s}=hr(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}=hr(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=>y0(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=Ur(A).mul(Ur(10).pow(Ur(k))).toString(),P={coin_type:y.coinType.name,price:U,oracle_price:0n,last_update_time:v.publishTime};P.oracle_price=ta(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}=hr(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==na(t)||p.coinType.name==na(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 d0.initialize(t,i,this.sdk.FullClient,!0)),this.suilendClientCache[r]}async getLendingMarketData(t=!1){if(!t&&this.lendingMarketCache)return this.lendingMarketCache;let i=hr(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 h0(this.sdk.FullClient,c),{rewardPriceMap:j}=await f0(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 _i(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 p0(this.sdk.FullClient,n.suilendClient,n.refreshedRawReserves,n.reserveMap,this.sdk.senderAddress),c=m0(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}=hr(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=b0(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}};import{getPackagerConfigs as bt,CACHE_TIME_5MIN as Sa,CoinAssist as mt,CLOCK_ADDRESS as $i,d as Xe,removeHexPrefix as Ca}from"@cetusprotocol/common-sdk";var fr=9e15,qi=1e9,Mo="0123456789abcdef",hn="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",fn="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ao={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-fr,maxE:fr,crypto:!1},la,Ii,Le=!0,mn="[DecimalError] ",ji=mn+"Invalid argument: ",ua=mn+"Precision limit exceeded",ca=mn+"crypto unavailable",da="[object Decimal]",Pt=Math.floor,wt=Math.pow,M0=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,A0=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,S0=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,ha=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ui=1e7,Pe=7,C0=9007199254740991,E0=hn.length-1,So=fn.length-1,re={toStringTag:da};re.absoluteValue=re.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),ke(e)};re.ceil=function(){return ke(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(ji+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())+Pe,r.rounding=1,i=I0(r,_a(r,i)),r.precision=e,r.rounding=t,ke(Ii==2||Ii==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(Le=!1,s=v.s*wt(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=Et(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=wt(i,1/3),e=Pt((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=tt(g.plus(v).times(c),g.plus(p),a+2,1),Et(c.d).slice(0,a)===(i=Et(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(ke(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")&&(ke(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return Le=!0,ke(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-Pt(this.e/Pe))*Pe,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};re.dividedBy=re.div=function(e){return tt(this,new this.constructor(e))};re.dividedToIntegerBy=re.divToInt=function(e){var t=this,i=t.constructor;return ke(tt(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 ke(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/_n(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=pr(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 ke(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=pr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/_n(5,e)),n=pr(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,ke(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,tt(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()?vi(t,r,n):new t(0):new t(NaN):e.isZero()?vi(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,Le=!1,i=i.times(i).minus(1).sqrt().plus(i),Le=!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,Le=!1,i=i.times(i).plus(1).sqrt().plus(i),Le=!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?ke(new s(n),e,t,!0):(s.precision=i=r-n.e,n=tt(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=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)))};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<=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/Pe+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(Le=!1,t=Math.ceil(c/Pe),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)),Le=!0,ke(a,v.precision=y,v.rounding=A,!0)};re.isFinite=function(){return!!this.d};re.isInteger=re.isInt=function(){return!!this.d&&Pt(this.e/Pe)>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(Le=!1,c=y+k,a=Ui(g,c),r=t?pn(v,c+10):Ui(e,c),p=tt(a,r,c,1),jr(p.d,n=y,A))do if(c+=10,a=Ui(g,c),r=t?pn(v,c+10):Ui(e,c),p=tt(a,r,c,1),!s){+Et(p.d).slice(n+1,n+15)+1==1e14&&(p=ke(p,y+1,0));break}while(jr(p.d,n+=10,A));return Le=!0,ke(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 Le?ke(e,c,p):e}if(i=Pt(e.e/Pe),v=Pt(k.e/Pe),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/Pe),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]=ui-1;--g[n],g[r]+=ui}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=gn(g,i),Le?ke(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]?ke(new r(i),r.precision,r.rounding):(Le=!1,r.modulo==9?(t=tt(i,e.abs(),0,3,1),t.s*=e.s):t=tt(i,e,0,r.modulo,1),t=t.times(e),Le=!0,i.minus(t))};re.naturalExponential=re.exp=function(){return Co(this)};re.naturalLogarithm=re.ln=function(){return Ui(this)};re.negated=re.neg=function(){var e=new this.constructor(this);return e.s=-e.s,ke(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)),Le?ke(e,c,p):e;if(s=Pt(y.e/Pe),r=Pt(e.e/Pe),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/Pe),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)/ui|0,g[n]%=ui;for(t&&(g.unshift(t),++r),a=g.length;g[--a]==0;)g.pop();return e.d=g,e.e=gn(g,r),Le?ke(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(ji+e);return i.d?(t=fa(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};re.round=function(){var e=this,t=e.constructor;return ke(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())+Pe,r.rounding=1,i=T0(r,_a(r,i)),r.precision=e,r.rounding=t,ke(Ii>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(Le=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=Et(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=Pt((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(tt(a,s,i+2,1)).times(.5),Et(s.d).slice(0,i)===(t=Et(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(ke(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")&&(ke(r,p+1,1),e=!r.times(r).eq(a));break}return Le=!0,ke(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=tt(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,ke(Ii==2||Ii==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=Pt(v.e/Pe)+Pt(e.e/Pe),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%ui|0,t=c/ui|0;s[n]=(s[n]+t)%ui|0}for(;!s[--a];)s.pop();return t?++i:s.shift(),e.d=s,e.e=gn(s,i),Le?ke(e,y.precision,y.rounding):e};re.toBinary=function(e,t){return Eo(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:(Lt(e,0,qi),t===void 0?t=r.rounding:Lt(t,0,8),ke(i,e+i.e+1,t))};re.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=wi(r,!0):(Lt(e,0,qi),t===void 0?t=n.rounding:Lt(t,0,8),r=ke(new n(r),e+1,t),i=wi(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=wi(n):(Lt(e,0,qi),t===void 0?t=s.rounding:Lt(t,0,8),r=ke(new s(n),e+n.e+1,t),i=wi(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=fa(U)-k.e-1,a=s%Pe,t.d[0]=wt(10,a<0?Pe+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(Le=!1,c=new P(Et(U)),v=P.precision,P.precision=s=U.length*Pe*2;y=tt(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=tt(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=tt(g,r,s,1).minus(k).abs().cmp(tt(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,Le=!0,A};re.toHexadecimal=re.toHex=function(e,t){return Eo(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:Lt(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]?(Le=!1,i=tt(i,e,0,t,1).times(e),Le=!0,ke(i)):(e.s=i.s,i=e),i};re.toNumber=function(){return+this};re.toOctal=function(e,t){return Eo(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(wt(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return ke(c,r,s);if(t=Pt(e.e/Pe),t>=e.d.length-1&&(i=g<0?-g:g)<=C0)return n=pa(p,c,i,r),e.s<0?new p(1).div(n):ke(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=wt(+c,g),t=i==0||!isFinite(i)?Pt(g*(Math.log("0."+Et(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):(Le=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=Co(e.times(Ui(c,r+i)),r),n.d&&(n=ke(n,r+5,1),jr(n.d,r,s)&&(t=r+10,n=ke(Co(e.times(Ui(c,t+i)),t),t+5,1),+Et(n.d).slice(r+1,r+15)+1==1e14&&(n=ke(n,r+1,0)))),n.s=a,Le=!0,p.rounding=s,ke(n,r,s))};re.toPrecision=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=wi(r,r.e<=n.toExpNeg||r.e>=n.toExpPos):(Lt(e,1,qi),t===void 0?t=n.rounding:Lt(t,0,8),r=ke(new n(r),e,t),i=wi(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):(Lt(e,1,qi),t===void 0?t=r.rounding:Lt(t,0,8)),ke(new r(i),e,t)};re.toString=function(){var e=this,t=e.constructor,i=wi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};re.truncated=re.trunc=function(){return ke(new this.constructor(this),this.e+1,1)};re.valueOf=re.toJSON=function(){var e=this,t=e.constructor,i=wi(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+i:i};function Et(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=Pe-r.length,i&&(s+=Bi(i)),s+=r;a=e[t],r=a+"",i=Pe-r.length,i&&(s+=Bi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Lt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(ji+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+=Pe,n=0):(n=Math.ceil((t+1)/Pe),t%=Pe),s=wt(10,Pe-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)==wt(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)==wt(10,t-3)-1,a}function cn(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 I0(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/_n(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=pr(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 tt=(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,ae,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=ui,k=Pe,v=Pt(r.e/k)-Pt(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++)ae=A*p+(o[y]||0),K[y]=ae/l|0,A=ae%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,la=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,ke(j,c?s+j.e+1:s,a,U)}return j}})();function ke(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+=Pe,a=t,v=y[A=0],p=v/wt(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/Pe),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=Pe,a=s-Pe+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=Pe,a=s-Pe+n,p=a<0?0:v/wt(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%wt(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/wt(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]=wt(10,(Pe-t%Pe)%Pe),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=wt(10,Pe-s),y[A]=a>0?(v/wt(10,n-a)%wt(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]==ui&&(y[0]=1));break}else{if(y[A]+=c,y[A]!=ui)break;y[A--]=0,c=1}for(s=y.length;y[--s]===0;)y.pop()}return Le&&(e.e>k.maxE?(e.d=null,e.e=NaN):e.e<k.minE&&(e.e=0,e.d=[0])),e}function wi(e,t,i){if(!e.isFinite())return ga(e);var r,n=e.e,s=Et(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+Bi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+Bi(-n-1)+s,i&&(r=i-a)>0&&(s+=Bi(r))):n>=a?(s+=Bi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+Bi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=Bi(r))),s}function gn(e,t){var i=e[0];for(t*=Pe;i>=10;i/=10)t++;return t}function pn(e,t,i){if(t>E0)throw Le=!0,i&&(e.precision=i),Error(ua);return ke(new e(hn),t,1,!0)}function vi(e,t,i){if(t>So)throw Error(ua);return ke(new e(fn),t,i,!0)}function fa(e){var t=e.length-1,i=t*Pe+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 Bi(e){for(var t="";e--;)t+="0";return t}function pa(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/Pe+4);for(Le=!1;;){if(i%2&&(s=s.times(t),sa(s.d,a)&&(n=!0)),i=Pt(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),sa(t.d,a)}return Le=!0,s}function oa(e){return e.d[e.d.length-1]&1}function ma(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?(Le=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(wt(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=ke(s.times(e),p,1),i=i.times(++v),c=a.plus(tt(s,i,p,1)),Et(c.d).slice(0,p)===Et(a.d).slice(0,p)){for(n=y;n--;)a=ke(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 ke(a,A.precision=U,k,Le=!0);else return A.precision=U,a}a=c}}function Ui(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?(Le=!1,v=X):v=t,j.precision=v+=U,i=Et(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=Et(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=pn(j,v+2,X).times(s+""),P=Ui(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?ke(P,X,K,Le=!0):P;for(y=P,p=a=P=tt(P.minus(1),P.plus(1),v,1),A=ke(P.times(P),v,1),n=3;;){if(a=ke(a.times(A),v,1),g=p.plus(tt(a,new j(n),v,1)),Et(g.d).slice(0,v)===Et(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(pn(j,v+2,X).times(s+""))),p=tt(p,new j(k),v,1),t==null)if(jr(p.d,v-U,K,c))j.precision=v+=U,g=a=P=tt(y.minus(1),y.plus(1),v,1),A=ke(P.times(P),v,1),n=c=1;else return ke(p,j.precision=X,K,Le=!0);else return j.precision=X,p;p=g,n+=2}}function ga(e){return String(e.s*e.s/0)}function dn(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)%Pe,i<0&&(r+=Pe),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=Pe;r<n;)e.d.push(+t.slice(r,r+=Pe));t=t.slice(r),r=Pe-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),Le&&(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 k0(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),ha.test(t))return dn(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(A0.test(t))i=16,t=t.toLowerCase();else if(M0.test(t))i=2;else if(S0.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=pa(r,new r(i),s,s*2)),g=cn(t,i,ui),v=g.length-1,s=v;g[s]===0;--s)g.pop();return s<0?new r(e.s*0):(e.e=gn(g,v),e.d=g,Le=!1,a&&(e=tt(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?wt(2,p):qr.pow(2,p))),Le=!0,e)}function T0(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:pr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/_n(5,i)),t=pr(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 pr(e,t,i,r,n){var s,a,c,p,g=1,v=e.precision,y=Math.ceil(v/Pe);for(Le=!1,p=i.times(i),c=new e(r);;){if(a=tt(c.times(p),new e(t++*t++),v,1),c=n?r.plus(a):r.minus(a),r=tt(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 Le=!0,a.d.length=y+1,a}function _n(e,t){for(var i=e;--t;)i*=e;return i}function _a(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 Ii=r?4:1,t;if(i=t.divToInt(n),i.isZero())Ii=r?3:2;else{if(t=t.minus(i.times(n)),t.lte(s))return Ii=oa(i)?r?2:3:r?4:1,t;Ii=oa(i)?r?1:4:r?3:2}return t.minus(n).abs()}function Eo(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Lt(i,1,qi),r===void 0?r=k.rounding:Lt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=ga(e);else{for(v=wi(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=cn(wi(A),10,n),A.e=A.d.length),y=cn(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=tt(e,A,i,r,0,n),y=e.d,s=e.e,g=la),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=cn(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 sa(e,t){if(e.length>t)return e.length=t,!0}function O0(e){return new this(e).abs()}function P0(e){return new this(e).acos()}function x0(e){return new this(e).acosh()}function N0(e,t){return new this(e).plus(t)}function R0(e){return new this(e).asin()}function L0(e){return new this(e).asinh()}function F0(e){return new this(e).atan()}function D0(e){return new this(e).atanh()}function B0(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(tt(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(tt(e,t,s,1)),i}function U0(e){return new this(e).cbrt()}function j0(e){return ke(e=new this(e),e.e+1,2)}function q0(e,t,i){return new this(e).clamp(t,i)}function $0(e){if(!e||typeof e!="object")throw Error(mn+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,qi,"rounding",0,8,"toExpNeg",-fr,0,"toExpPos",0,fr,"maxE",0,fr,"minE",-fr,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(Pt(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(ca);else this[i]=!1;else throw Error(ji+i+": "+r);return this}function H0(e){return new this(e).cos()}function G0(e){return new this(e).cosh()}function va(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,aa(s)){g.s=s.s,Le?!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++;Le?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 dn(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),ha.test(s)?dn(g,s):k0(g,s);if(p==="bigint")return s<0?(s=-s,g.s=-1):g.s=1,dn(g,s.toString());throw Error(ji+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=$0,n.clone=va,n.isDecimal=aa,n.abs=O0,n.acos=P0,n.acosh=x0,n.add=N0,n.asin=R0,n.asinh=L0,n.atan=F0,n.atanh=D0,n.atan2=B0,n.cbrt=U0,n.ceil=j0,n.clamp=q0,n.cos=H0,n.cosh=G0,n.div=V0,n.exp=Z0,n.floor=K0,n.hypot=W0,n.ln=z0,n.log=X0,n.log10=Y0,n.log2=J0,n.max=Q0,n.min=ec,n.mod=tc,n.mul=ic,n.pow=rc,n.random=nc,n.round=oc,n.sign=sc,n.sin=ac,n.sinh=lc,n.sqrt=uc,n.sub=cc,n.sum=dc,n.tan=hc,n.tanh=fc,n.trunc=pc,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 V0(e,t){return new this(e).div(t)}function Z0(e){return new this(e).exp()}function K0(e){return ke(e=new this(e),e.e+1,3)}function W0(){var e,t,i=new this(0);for(Le=!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 Le=!0,new this(1/0);i=t}return Le=!0,i.sqrt()}function aa(e){return e instanceof qr||e&&e.toStringTag===da||!1}function z0(e){return new this(e).ln()}function X0(e,t){return new this(e).log(t)}function J0(e){return new this(e).log(2)}function Y0(e){return new this(e).log(10)}function Q0(){return ma(this,arguments,-1)}function ec(){return ma(this,arguments,1)}function tc(e,t){return new this(e).mod(t)}function ic(e,t){return new this(e).mul(t)}function rc(e,t){return new this(e).pow(t)}function nc(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Lt(e,1,qi),r=Math.ceil(e/Pe),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(ca);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=Pe,r&&e&&(n=wt(10,Pe-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-=Pe)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<Pe&&(i-=Pe-r)}return a.e=i,a.d=c,a}function oc(e){return ke(e=new this(e),e.e+1,this.rounding)}function sc(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function ac(e){return new this(e).sin()}function lc(e){return new this(e).sinh()}function uc(e){return new this(e).sqrt()}function cc(e,t){return new this(e).sub(t)}function dc(){var e=0,t=arguments,i=new this(t[e]);for(Le=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return Le=!0,ke(i,this.precision,this.rounding)}function hc(e){return new this(e).tan()}function fc(e){return new this(e).tanh()}function pc(e){return ke(e=new this(e),e.e+1,1)}re[Symbol.for("nodejs.util.inspect.custom")]=re.toString;re[Symbol.toStringTag]="Decimal";var qr=re.constructor=va(Ao);hn=new qr(hn);fn=new qr(fn);var bi=qr;var Oo=Gs(ba());import{Transaction as Hi}from"@mysten/sui/transactions";import{addHexPrefix as ya,getObjectFields as Ma}from"@cetusprotocol/common-sdk";var Aa=e=>{let t=[];return e.forEach(i=>{t.push(ko(i))}),t},ko=e=>{let t=Ma(e);return{marketId:t.id.id,baseToken:ya(t.base_token.fields.name),quoteToken:ya(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}},To=e=>{let t=Ma(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}};import{SUI_SYSTEM_STATE_OBJECT_ID as Ea,toHEX as $r}from"@mysten/sui/utils";import{parseObligation as mc}from"@suilend/sdk/parsers/obligation";import{obligation as gc}from"@suilend/sdk/_generated/suilend/lending-market/functions";var vn=class{constructor(t){this.getLeverageConfig=async()=>{let t=bt(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=bt(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=Aa(v);return this._sdk.updateCache(i,y,Sa),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=ko(n);return this._sdk.updateCache(i,s,Sa),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}=bt(this._sdk.sdkOptions.suilend),n=await this._sdk.SuiLendModule.getSuilendClient(i,r),s=[];for(let a=0;a<t.data.length;a++){let c=To(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=To(i.data[0]),{lendingMarketId:n,lendingMarketType:s}=bt(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{...mc(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}=bt(this._sdk.sdkOptions.suilend),v=new Hi,{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,ae;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=mt.buildCoinWithBalance(BigInt(n.toString()),$,v);ae=await this.routerSwap({router:ie.route_obj,slippage:a,inputCoin:C,txb:v}),Y=ae}}else Y=mt.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=Xe(E).mul(U).toString(),{balanceA:N,balanceB:S,receipt:h}=this.flashLoan({amount:Xe(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,Xe(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=Xe(d?.amount_out||0),_;d&&(_=await this.routerSwap({router:d.route_obj,inputCoin:O?mt.fromBalance(N,P,v):mt.fromBalance(S,W,v),slippage:a,txb:v}));let b=Xe(m).add(se).mul(1-y).toDP(0,bi.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=$r(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=Xe(E).add(R).toDP(0,bi.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:Xe(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=mt.mintBalanceZero(O?W:P,v);return this.repayFlashLoan({tx:v,clmmPool:s,repayBase:O?mt.intoBalance(M,P,v):q,repayQuote:O?q:mt.intoBalance(M,W,v),receipt:h,clmmPoolCoinTypeA:P,clmmPoolCoinTypeB:W}),v.transferObjects([w],v.pure.address(this._sdk.getSenderAddress())),mt.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}=bt(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 Hi,se=U[0].reserveArrayIndex.toString(),Y=P[0].reserveArrayIndex.toString(),ae=n&&k||!n&&!k,E;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",ae);let I;if(ae){let M=n&&k?A:y,q=n&&k?y:A,$=await this.findRouters(M,q,s,!0,[a]);if($){let z=mt.buildCoinWithBalance(BigInt(s.toString()),M,Q);I=await this.routerSwap({router:$.route_obj,inputCoin:z,slippage:c,txb:Q}),E=I}}else E=mt.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=Xe(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:Xe(R),clmmPool:a,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X,flashLoanCoin:O,tx:Q}),d=k?A:y,m=k?y:A,_=await this.findRouters(d,m,Xe(R),!0,[a]),b;_&&(b=await this.routerSwap({router:_.route_obj,inputCoin:S?mt.fromBalance(h,K,Q):mt.fromBalance(o,X,Q),slippage:c,txb:Q})),Q.mergeCoins(b,[E]);for(let M=0;M<W.length;M++){let q=$r(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=Xe(R).add(N).toDP(0,bi.ROUND_UP).toString(),f=this.borrowAsset({positionId:r,reserveArrayIndex:Y,borrowAmount:Xe(w),baseToken:y,quoteToken:A,isLong:k,lendingMarketId:v},Q),u=mt.mintBalanceZero(S?X:K,Q);return this.repayFlashLoan({tx:Q,clmmPool:a,repayBase:S?mt.intoBalance(f,K,Q):u,repayQuote:S?u:mt.intoBalance(f,X,Q),receipt:l,clmmPoolCoinTypeA:K,clmmPoolCoinTypeB:X}),mt.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}=bt(this._sdk.sdkOptions.suilend),A=a||new Hi,{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=$r(new Uint8Array(K[b].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,w,BigInt(K[b].arrayIndex))}let{token:Y}=j[0].reserve,ae=Xe(W[0].depositedCtokenAmount.toString()).div(Xe(g)).toDP(0,bi.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",ae);let E=Xe(Q).div(Xe(ae)).toString(),I=Xe(j[0].borrowedAmount.toString()).mul(10**Y.decimals).toString(),O=Xe(I).mul(E).toDP(0,bi.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:ae});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:Xe(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,Xe(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:Xe(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}=bt(this._sdk.sdkOptions.suilend),{token:K}=A[0].reserve,X=new Hi,Q=Xe(A[0].borrowedAmount.toString()).mul(Xe(a).sub(Xe(s))).mul(10**K.decimals).toDP(0,bi.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:ae,balanceB:E,receipt:I}=this.flashLoan({tx:X,amount:Xe(se),clmmPool:c,clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P,flashLoanCoin:Y}),O=n?v:g,R=n?g:v,N=await this.findRouters(O,R,Xe(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?mt.fromBalance(E,P,X):mt.fromBalance(ae,U,X),slippage:p,txb:X});for(let m=0;m<k.length;m++){let _=$r(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=Xe(se).mul(Xe(1).add(W)).toDP(0,bi.ROUND_UP).toString(),o=await this.borrowAsset({positionId:r,reserveArrayIndex:A[0].reserveArrayIndex.toString(),borrowAmount:Xe(h),baseToken:g,quoteToken:v,isLong:n,lendingMarketId:j},X),l=mt.mintBalanceZero(n?g:v,X),d=U===Y;return this.repayFlashLoan({tx:X,clmmPool:c,repayBase:n?l:mt.intoBalance(o,g,X),repayQuote:n?mt.intoBalance(o,v,X):l,receipt:I,clmmPoolCoinTypeA:U,clmmPoolCoinTypeB:P}),mt.destroyBalanceZero(d?E:ae,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}=bt(this._sdk.sdkOptions.suilend),j=new Hi,K=Xe(A[0].depositedCtokenAmount.toString()).mul(Xe(s).sub(Xe(a))).toString(),X=Xe(K).toDP(0,bi.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=$r(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 ae=this.withdrawAsset({marketId:i,positionId:r,withdrawAmount:Xe(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,Xe(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:ae,slippage:p,txb:j});return this.repay({txb:j,positionId:r,repayReserveArrayIndex:k[0].reserveArrayIndex.toString(),repayCoin:R,repayCoinType:n?v:g,repayAmount:Xe(0)}),R&&j.transferObjects([R],this._sdk.getSenderAddress()),j};this.leveragePositionClose=async(t,i)=>{let r=i||new Hi,{marketId:n,positionId:s}=t,{leverage:a}=this._sdk.sdkOptions,{global_config_id:c}=bt(this._sdk.sdkOptions.leverage),{lendingMarketType:p,lendingMarketId:g}=bt(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=gc(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($i)]}),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}=bt(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}=bt(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}=bt(this._sdk.sdkOptions.suilend);return mt.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(Ea),i.object($i)]}):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($i)]})};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}=bt(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 mt.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(Ea),i.object($i)]}):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($i)]})};this.repay=t=>{let{leverage:i}=this._sdk.sdkOptions,{lendingMarketId:r,lendingMarketType:n}=bt(this._sdk.sdkOptions.suilend),{txb:s,positionId:a,repayAmount:c,repayCoinType:p,repayCoin:g,repayReserveArrayIndex:v}=t,y=s||new Hi,A=g||mt.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($i)]})};this.routerSwap=async t=>{let{slippage:i,txb:r,inputCoin:n,router:s}=t,a=r||new Hi;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,Xe(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[Ca(s)]?.price,v=p[Ca(n)]?.price,y=i?Xe(v).div(Xe(g)).toString():Xe(g).div(Xe(v)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",a.toString(),i,y,g,v),{flashAmount:Xe(a).mul(r-1).mul(y).toDP(0,bi.ROUND_UP).toString(),rate:y,quotePrice:g,basePrice:v}}createLeveragePosition(t){let{lendingMarketId:i,lendingMarketType:r}=bt(this._sdk.sdkOptions.suilend),{global_config_id:n}=bt(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($i)],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}=bt(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($i)]}),i}async findRouters(t,i,r,n,s){let{providers:a}=this._sdk.sdkOptions;try{let c={from:t,target:i,amount:new Oo.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 Oo.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 rn=Gs(Bl());import{normalizeSuiAddress as Q1}from"@mysten/sui/utils";import{SuiClient as eg}from"@mysten/sui/client";import{SdkWrapper as Ap}from"@cetusprotocol/common-sdk";import{normalizeSuiObjectId as ds}from"@mysten/sui/utils";import{CACHE_TIME_24H as fi,CACHE_TIME_5MIN as Sp,CachedContent as Cp,DETAILS_KEYS as Xr,extractStructTagFromType as hs,fixCoinType as Ep,getFutureTime as Ul,getObjectFields as Hn,getObjectId as fs,getObjectPreviousTransactionDigest as Ip,getObjectType as kp,getPackagerConfigs as zi,normalizeCoinType as jl}from"@cetusprotocol/common-sdk";import{BaseError as Up}from"@cetusprotocol/common-sdk";import{SuiClient as Jp}from"@mysten/sui/client";import{Transaction as Jr}from"@mysten/sui/transactions";import{normalizeSuiAddress as yr}from"@mysten/sui/utils";import{asUintN as Zl,FEE_RATE_DENOMINATOR as Vn,getDeltaDownFromOutput as Kl,getDeltaUpFromInput as Wl,getNextSqrtPriceFromInput as tm,getNextSqrtPriceFromOutput as im,MathUtil as lr,ZERO as pi}from"@cetusprotocol/common-sdk";import{Transaction as ms}from"@mysten/sui/transactions";import{adjustForSlippage as nm,CLOCK_ADDRESS as Zn,CoinAssist as Ut,getPackagerConfigs as zl,MathUtil as U_,MAX_SQRT_PRICE as om,MIN_SQRT_PRICE as sm,U64_MAX as am,ZERO as lm}from"@cetusprotocol/common-sdk";import{Transaction as gs}from"@mysten/sui/transactions";import{asUintN as Xl,ClmmPoolUtil as fm,CLOCK_ADDRESS as Jl,CoinAssist as jt,getPackagerConfigs as pm,normalizeCoinType as _s}from"@cetusprotocol/common-sdk";import{asIntN as cr,buildNFT as h1,d as Yr,DETAILS_KEYS as ho,extractStructTagFromType as Dr,getMoveObjectType as Vu,getObjectDeletedResponse as f1,getObjectFields as $s,getObjectId as Fs,getObjectNotExistsResponse as p1,getObjectOwner as m1,MathUtil as g1}from"@cetusprotocol/common-sdk";import{asUintN as Mr,CACHE_TIME_24H as Wn,ClmmPoolUtil as M1,CLOCK_ADDRESS as tu,CoinAssist as zn,createFullClient as A1,d as Ar,DETAILS_KEYS as rt,extractStructTagFromType as Sr,getObjectFields as S1,getObjectPreviousTransactionDigest as C1,getPackagerConfigs as ys,isSortedSymbols as iu,TickMath as Ms,tickScore as E1,TickUtil as ru}from"@cetusprotocol/common-sdk";import{asIntN as nu,d as ou,extractStructTagFromType as I1,fixCoinType as su,getObjectFields as As,getObjectType as k1}from"@cetusprotocol/common-sdk";import{SuiClient as P1}from"@mysten/sui/client";import{Transaction as Pi}from"@mysten/sui/transactions";import{isValidSuiObjectId as x1,normalizeSuiAddress as N1}from"@mysten/sui/utils";import{asUintN as Cr,ClmmPoolUtil as au,CLOCK_ADDRESS as Jn,CoinAssist as Yn,d as Mi,DETAILS_KEYS as Xi,extractStructTagFromType as R1,getObjectFields as lu,getPackagerConfigs as xi,TickMath as Er,TickUtil as Qn,createFullClient as L1,deriveDynamicFieldIdByType as F1}from"@cetusprotocol/common-sdk";import{Transaction as Ss}from"@mysten/sui/transactions";import{normalizeSuiAddress as B1}from"@mysten/sui/utils";import{CLOCK_ADDRESS as Cs,CoinAssist as Es,DETAILS_KEYS as cu,getPackagerConfigs as Is,MathUtil as U1,normalizeCoinType as ks,ZERO as Ir}from"@cetusprotocol/common-sdk";import{Transaction as du}from"@mysten/sui/transactions";import{normalizeSuiAddress as hu}from"@mysten/sui/utils";import{d as Tr,DETAILS_KEYS as Ji,extractStructTagFromType as fu,TickMath as pu,U64_MAX as q1,ZERO as $1}from"@cetusprotocol/common-sdk";import{CLOCK_ADDRESS as G1,CoinAssist as V1,DETAILS_KEYS as ar,getPackagerConfigs as Ts}from"@cetusprotocol/common-sdk";import{Transaction as mu}from"@mysten/sui/transactions";import{normalizeSuiAddress as Z1}from"@mysten/sui/utils";import{FullRpcUrlMainnet as W1}from"@cetusprotocol/common-sdk";import{FullRpcUrlTestnet as X1}from"@cetusprotocol/common-sdk";import{MathUtil as av,TickMath as lv}from"@cetusprotocol/common-sdk";var mp=Object.create,_u=Object.defineProperty,gp=Object.getOwnPropertyDescriptor,_p=Object.getOwnPropertyNames,vp=Object.getPrototypeOf,wp=Object.prototype.hasOwnProperty,bp=(e=>typeof vt<"u"?vt:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof vt<"u"?vt:t)[i]}):e)(function(e){if(typeof vt<"u")return vt.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),yp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Mp=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of _p(t))!wp.call(e,n)&&n!==i&&_u(e,n,{get:()=>t[n],enumerable:!(r=gp(t,n))||r.enumerable});return e},Li=(e,t,i)=>(i=e!=null?mp(vp(e)):{},Mp(t||!e||!e.__esModule?_u(i,"default",{value:e,enumerable:!0}):i,e)),Fi=yp((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=bp("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,le=ee>>>13,Ee=m[6]|0,ce=Ee&8191,pe=Ee>>>13,Ce=m[7]|0,ue=Ce&8191,Se=Ce>>>13,et=m[8]|0,fe=et&8191,Re=et>>>13,Ye=m[9]|0,he=Ye&8191,Ie=Ye>>>13,ze=_[0]|0,de=ze&8191,Ue=ze>>>13,ot=_[1]|0,me=ot&8191,je=ot>>>13,st=_[2]|0,ge=st&8191,qe=st>>>13,at=_[3]|0,_e=at&8191,$e=at>>>13,lt=_[4]|0,ve=lt&8191,He=lt>>>13,ut=_[5]|0,we=ut&8191,Ge=ut>>>13,ct=_[6]|0,be=ct&8191,Ve=ct>>>13,dt=_[7]|0,ye=dt&8191,Ze=dt>>>13,ht=_[8]|0,Me=ht&8191,Ke=ht>>>13,ft=_[9]|0,Ae=ft&8191,Be=ft>>>13;d.negative=o.negative^l.negative,d.length=19,f=Math.imul($,de),u=Math.imul($,Ue),u=u+Math.imul(z,de)|0,M=Math.imul(z,Ue);var Gt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,f=Math.imul(C,de),u=Math.imul(C,Ue),u=u+Math.imul(T,de)|0,M=Math.imul(T,Ue),f=f+Math.imul($,me)|0,u=u+Math.imul($,je)|0,u=u+Math.imul(z,me)|0,M=M+Math.imul(z,je)|0;var Vt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,f=Math.imul(F,de),u=Math.imul(F,Ue),u=u+Math.imul(L,de)|0,M=Math.imul(L,Ue),f=f+Math.imul(C,me)|0,u=u+Math.imul(C,je)|0,u=u+Math.imul(T,me)|0,M=M+Math.imul(T,je)|0,f=f+Math.imul($,ge)|0,u=u+Math.imul($,qe)|0,u=u+Math.imul(z,ge)|0,M=M+Math.imul(z,qe)|0;var Zt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,f=Math.imul(B,de),u=Math.imul(B,Ue),u=u+Math.imul(D,de)|0,M=Math.imul(D,Ue),f=f+Math.imul(F,me)|0,u=u+Math.imul(F,je)|0,u=u+Math.imul(L,me)|0,M=M+Math.imul(L,je)|0,f=f+Math.imul(C,ge)|0,u=u+Math.imul(C,qe)|0,u=u+Math.imul(T,ge)|0,M=M+Math.imul(T,qe)|0,f=f+Math.imul($,_e)|0,u=u+Math.imul($,$e)|0,u=u+Math.imul(z,_e)|0,M=M+Math.imul(z,$e)|0;var Kt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,f=Math.imul(H,de),u=Math.imul(H,Ue),u=u+Math.imul(V,de)|0,M=Math.imul(V,Ue),f=f+Math.imul(B,me)|0,u=u+Math.imul(B,je)|0,u=u+Math.imul(D,me)|0,M=M+Math.imul(D,je)|0,f=f+Math.imul(F,ge)|0,u=u+Math.imul(F,qe)|0,u=u+Math.imul(L,ge)|0,M=M+Math.imul(L,qe)|0,f=f+Math.imul(C,_e)|0,u=u+Math.imul(C,$e)|0,u=u+Math.imul(T,_e)|0,M=M+Math.imul(T,$e)|0,f=f+Math.imul($,ve)|0,u=u+Math.imul($,He)|0,u=u+Math.imul(z,ve)|0,M=M+Math.imul(z,He)|0;var Wt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,f=Math.imul(te,de),u=Math.imul(te,Ue),u=u+Math.imul(le,de)|0,M=Math.imul(le,Ue),f=f+Math.imul(H,me)|0,u=u+Math.imul(H,je)|0,u=u+Math.imul(V,me)|0,M=M+Math.imul(V,je)|0,f=f+Math.imul(B,ge)|0,u=u+Math.imul(B,qe)|0,u=u+Math.imul(D,ge)|0,M=M+Math.imul(D,qe)|0,f=f+Math.imul(F,_e)|0,u=u+Math.imul(F,$e)|0,u=u+Math.imul(L,_e)|0,M=M+Math.imul(L,$e)|0,f=f+Math.imul(C,ve)|0,u=u+Math.imul(C,He)|0,u=u+Math.imul(T,ve)|0,M=M+Math.imul(T,He)|0,f=f+Math.imul($,we)|0,u=u+Math.imul($,Ge)|0,u=u+Math.imul(z,we)|0,M=M+Math.imul(z,Ge)|0;var zt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(zt>>>26)|0,zt&=67108863,f=Math.imul(ce,de),u=Math.imul(ce,Ue),u=u+Math.imul(pe,de)|0,M=Math.imul(pe,Ue),f=f+Math.imul(te,me)|0,u=u+Math.imul(te,je)|0,u=u+Math.imul(le,me)|0,M=M+Math.imul(le,je)|0,f=f+Math.imul(H,ge)|0,u=u+Math.imul(H,qe)|0,u=u+Math.imul(V,ge)|0,M=M+Math.imul(V,qe)|0,f=f+Math.imul(B,_e)|0,u=u+Math.imul(B,$e)|0,u=u+Math.imul(D,_e)|0,M=M+Math.imul(D,$e)|0,f=f+Math.imul(F,ve)|0,u=u+Math.imul(F,He)|0,u=u+Math.imul(L,ve)|0,M=M+Math.imul(L,He)|0,f=f+Math.imul(C,we)|0,u=u+Math.imul(C,Ge)|0,u=u+Math.imul(T,we)|0,M=M+Math.imul(T,Ge)|0,f=f+Math.imul($,be)|0,u=u+Math.imul($,Ve)|0,u=u+Math.imul(z,be)|0,M=M+Math.imul(z,Ve)|0;var Xt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,f=Math.imul(ue,de),u=Math.imul(ue,Ue),u=u+Math.imul(Se,de)|0,M=Math.imul(Se,Ue),f=f+Math.imul(ce,me)|0,u=u+Math.imul(ce,je)|0,u=u+Math.imul(pe,me)|0,M=M+Math.imul(pe,je)|0,f=f+Math.imul(te,ge)|0,u=u+Math.imul(te,qe)|0,u=u+Math.imul(le,ge)|0,M=M+Math.imul(le,qe)|0,f=f+Math.imul(H,_e)|0,u=u+Math.imul(H,$e)|0,u=u+Math.imul(V,_e)|0,M=M+Math.imul(V,$e)|0,f=f+Math.imul(B,ve)|0,u=u+Math.imul(B,He)|0,u=u+Math.imul(D,ve)|0,M=M+Math.imul(D,He)|0,f=f+Math.imul(F,we)|0,u=u+Math.imul(F,Ge)|0,u=u+Math.imul(L,we)|0,M=M+Math.imul(L,Ge)|0,f=f+Math.imul(C,be)|0,u=u+Math.imul(C,Ve)|0,u=u+Math.imul(T,be)|0,M=M+Math.imul(T,Ve)|0,f=f+Math.imul($,ye)|0,u=u+Math.imul($,Ze)|0,u=u+Math.imul(z,ye)|0,M=M+Math.imul(z,Ze)|0;var Jt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,f=Math.imul(fe,de),u=Math.imul(fe,Ue),u=u+Math.imul(Re,de)|0,M=Math.imul(Re,Ue),f=f+Math.imul(ue,me)|0,u=u+Math.imul(ue,je)|0,u=u+Math.imul(Se,me)|0,M=M+Math.imul(Se,je)|0,f=f+Math.imul(ce,ge)|0,u=u+Math.imul(ce,qe)|0,u=u+Math.imul(pe,ge)|0,M=M+Math.imul(pe,qe)|0,f=f+Math.imul(te,_e)|0,u=u+Math.imul(te,$e)|0,u=u+Math.imul(le,_e)|0,M=M+Math.imul(le,$e)|0,f=f+Math.imul(H,ve)|0,u=u+Math.imul(H,He)|0,u=u+Math.imul(V,ve)|0,M=M+Math.imul(V,He)|0,f=f+Math.imul(B,we)|0,u=u+Math.imul(B,Ge)|0,u=u+Math.imul(D,we)|0,M=M+Math.imul(D,Ge)|0,f=f+Math.imul(F,be)|0,u=u+Math.imul(F,Ve)|0,u=u+Math.imul(L,be)|0,M=M+Math.imul(L,Ve)|0,f=f+Math.imul(C,ye)|0,u=u+Math.imul(C,Ze)|0,u=u+Math.imul(T,ye)|0,M=M+Math.imul(T,Ze)|0,f=f+Math.imul($,Me)|0,u=u+Math.imul($,Ke)|0,u=u+Math.imul(z,Me)|0,M=M+Math.imul(z,Ke)|0;var Yt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,f=Math.imul(he,de),u=Math.imul(he,Ue),u=u+Math.imul(Ie,de)|0,M=Math.imul(Ie,Ue),f=f+Math.imul(fe,me)|0,u=u+Math.imul(fe,je)|0,u=u+Math.imul(Re,me)|0,M=M+Math.imul(Re,je)|0,f=f+Math.imul(ue,ge)|0,u=u+Math.imul(ue,qe)|0,u=u+Math.imul(Se,ge)|0,M=M+Math.imul(Se,qe)|0,f=f+Math.imul(ce,_e)|0,u=u+Math.imul(ce,$e)|0,u=u+Math.imul(pe,_e)|0,M=M+Math.imul(pe,$e)|0,f=f+Math.imul(te,ve)|0,u=u+Math.imul(te,He)|0,u=u+Math.imul(le,ve)|0,M=M+Math.imul(le,He)|0,f=f+Math.imul(H,we)|0,u=u+Math.imul(H,Ge)|0,u=u+Math.imul(V,we)|0,M=M+Math.imul(V,Ge)|0,f=f+Math.imul(B,be)|0,u=u+Math.imul(B,Ve)|0,u=u+Math.imul(D,be)|0,M=M+Math.imul(D,Ve)|0,f=f+Math.imul(F,ye)|0,u=u+Math.imul(F,Ze)|0,u=u+Math.imul(L,ye)|0,M=M+Math.imul(L,Ze)|0,f=f+Math.imul(C,Me)|0,u=u+Math.imul(C,Ke)|0,u=u+Math.imul(T,Me)|0,M=M+Math.imul(T,Ke)|0,f=f+Math.imul($,Ae)|0,u=u+Math.imul($,Be)|0,u=u+Math.imul(z,Ae)|0,M=M+Math.imul(z,Be)|0;var Qt=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,f=Math.imul(he,me),u=Math.imul(he,je),u=u+Math.imul(Ie,me)|0,M=Math.imul(Ie,je),f=f+Math.imul(fe,ge)|0,u=u+Math.imul(fe,qe)|0,u=u+Math.imul(Re,ge)|0,M=M+Math.imul(Re,qe)|0,f=f+Math.imul(ue,_e)|0,u=u+Math.imul(ue,$e)|0,u=u+Math.imul(Se,_e)|0,M=M+Math.imul(Se,$e)|0,f=f+Math.imul(ce,ve)|0,u=u+Math.imul(ce,He)|0,u=u+Math.imul(pe,ve)|0,M=M+Math.imul(pe,He)|0,f=f+Math.imul(te,we)|0,u=u+Math.imul(te,Ge)|0,u=u+Math.imul(le,we)|0,M=M+Math.imul(le,Ge)|0,f=f+Math.imul(H,be)|0,u=u+Math.imul(H,Ve)|0,u=u+Math.imul(V,be)|0,M=M+Math.imul(V,Ve)|0,f=f+Math.imul(B,ye)|0,u=u+Math.imul(B,Ze)|0,u=u+Math.imul(D,ye)|0,M=M+Math.imul(D,Ze)|0,f=f+Math.imul(F,Me)|0,u=u+Math.imul(F,Ke)|0,u=u+Math.imul(L,Me)|0,M=M+Math.imul(L,Ke)|0,f=f+Math.imul(C,Ae)|0,u=u+Math.imul(C,Be)|0,u=u+Math.imul(T,Ae)|0,M=M+Math.imul(T,Be)|0;var ei=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ei>>>26)|0,ei&=67108863,f=Math.imul(he,ge),u=Math.imul(he,qe),u=u+Math.imul(Ie,ge)|0,M=Math.imul(Ie,qe),f=f+Math.imul(fe,_e)|0,u=u+Math.imul(fe,$e)|0,u=u+Math.imul(Re,_e)|0,M=M+Math.imul(Re,$e)|0,f=f+Math.imul(ue,ve)|0,u=u+Math.imul(ue,He)|0,u=u+Math.imul(Se,ve)|0,M=M+Math.imul(Se,He)|0,f=f+Math.imul(ce,we)|0,u=u+Math.imul(ce,Ge)|0,u=u+Math.imul(pe,we)|0,M=M+Math.imul(pe,Ge)|0,f=f+Math.imul(te,be)|0,u=u+Math.imul(te,Ve)|0,u=u+Math.imul(le,be)|0,M=M+Math.imul(le,Ve)|0,f=f+Math.imul(H,ye)|0,u=u+Math.imul(H,Ze)|0,u=u+Math.imul(V,ye)|0,M=M+Math.imul(V,Ze)|0,f=f+Math.imul(B,Me)|0,u=u+Math.imul(B,Ke)|0,u=u+Math.imul(D,Me)|0,M=M+Math.imul(D,Ke)|0,f=f+Math.imul(F,Ae)|0,u=u+Math.imul(F,Be)|0,u=u+Math.imul(L,Ae)|0,M=M+Math.imul(L,Be)|0;var ti=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ti>>>26)|0,ti&=67108863,f=Math.imul(he,_e),u=Math.imul(he,$e),u=u+Math.imul(Ie,_e)|0,M=Math.imul(Ie,$e),f=f+Math.imul(fe,ve)|0,u=u+Math.imul(fe,He)|0,u=u+Math.imul(Re,ve)|0,M=M+Math.imul(Re,He)|0,f=f+Math.imul(ue,we)|0,u=u+Math.imul(ue,Ge)|0,u=u+Math.imul(Se,we)|0,M=M+Math.imul(Se,Ge)|0,f=f+Math.imul(ce,be)|0,u=u+Math.imul(ce,Ve)|0,u=u+Math.imul(pe,be)|0,M=M+Math.imul(pe,Ve)|0,f=f+Math.imul(te,ye)|0,u=u+Math.imul(te,Ze)|0,u=u+Math.imul(le,ye)|0,M=M+Math.imul(le,Ze)|0,f=f+Math.imul(H,Me)|0,u=u+Math.imul(H,Ke)|0,u=u+Math.imul(V,Me)|0,M=M+Math.imul(V,Ke)|0,f=f+Math.imul(B,Ae)|0,u=u+Math.imul(B,Be)|0,u=u+Math.imul(D,Ae)|0,M=M+Math.imul(D,Be)|0;var ii=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,f=Math.imul(he,ve),u=Math.imul(he,He),u=u+Math.imul(Ie,ve)|0,M=Math.imul(Ie,He),f=f+Math.imul(fe,we)|0,u=u+Math.imul(fe,Ge)|0,u=u+Math.imul(Re,we)|0,M=M+Math.imul(Re,Ge)|0,f=f+Math.imul(ue,be)|0,u=u+Math.imul(ue,Ve)|0,u=u+Math.imul(Se,be)|0,M=M+Math.imul(Se,Ve)|0,f=f+Math.imul(ce,ye)|0,u=u+Math.imul(ce,Ze)|0,u=u+Math.imul(pe,ye)|0,M=M+Math.imul(pe,Ze)|0,f=f+Math.imul(te,Me)|0,u=u+Math.imul(te,Ke)|0,u=u+Math.imul(le,Me)|0,M=M+Math.imul(le,Ke)|0,f=f+Math.imul(H,Ae)|0,u=u+Math.imul(H,Be)|0,u=u+Math.imul(V,Ae)|0,M=M+Math.imul(V,Be)|0;var ri=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,f=Math.imul(he,we),u=Math.imul(he,Ge),u=u+Math.imul(Ie,we)|0,M=Math.imul(Ie,Ge),f=f+Math.imul(fe,be)|0,u=u+Math.imul(fe,Ve)|0,u=u+Math.imul(Re,be)|0,M=M+Math.imul(Re,Ve)|0,f=f+Math.imul(ue,ye)|0,u=u+Math.imul(ue,Ze)|0,u=u+Math.imul(Se,ye)|0,M=M+Math.imul(Se,Ze)|0,f=f+Math.imul(ce,Me)|0,u=u+Math.imul(ce,Ke)|0,u=u+Math.imul(pe,Me)|0,M=M+Math.imul(pe,Ke)|0,f=f+Math.imul(te,Ae)|0,u=u+Math.imul(te,Be)|0,u=u+Math.imul(le,Ae)|0,M=M+Math.imul(le,Be)|0;var ni=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,f=Math.imul(he,be),u=Math.imul(he,Ve),u=u+Math.imul(Ie,be)|0,M=Math.imul(Ie,Ve),f=f+Math.imul(fe,ye)|0,u=u+Math.imul(fe,Ze)|0,u=u+Math.imul(Re,ye)|0,M=M+Math.imul(Re,Ze)|0,f=f+Math.imul(ue,Me)|0,u=u+Math.imul(ue,Ke)|0,u=u+Math.imul(Se,Me)|0,M=M+Math.imul(Se,Ke)|0,f=f+Math.imul(ce,Ae)|0,u=u+Math.imul(ce,Be)|0,u=u+Math.imul(pe,Ae)|0,M=M+Math.imul(pe,Be)|0;var oi=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,f=Math.imul(he,ye),u=Math.imul(he,Ze),u=u+Math.imul(Ie,ye)|0,M=Math.imul(Ie,Ze),f=f+Math.imul(fe,Me)|0,u=u+Math.imul(fe,Ke)|0,u=u+Math.imul(Re,Me)|0,M=M+Math.imul(Re,Ke)|0,f=f+Math.imul(ue,Ae)|0,u=u+Math.imul(ue,Be)|0,u=u+Math.imul(Se,Ae)|0,M=M+Math.imul(Se,Be)|0;var si=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(si>>>26)|0,si&=67108863,f=Math.imul(he,Me),u=Math.imul(he,Ke),u=u+Math.imul(Ie,Me)|0,M=Math.imul(Ie,Ke),f=f+Math.imul(fe,Ae)|0,u=u+Math.imul(fe,Be)|0,u=u+Math.imul(Re,Ae)|0,M=M+Math.imul(Re,Be)|0;var ai=(w+f|0)+((u&8191)<<13)|0;w=(M+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,f=Math.imul(he,Ae),u=Math.imul(he,Be),u=u+Math.imul(Ie,Ae)|0,M=Math.imul(Ie,Be);var rr=(w+f|0)+((u&8191)<<13)|0;return w=(M+(u>>>13)|0)+(rr>>>26)|0,rr&=67108863,b[0]=Gt,b[1]=Vt,b[2]=Zt,b[3]=Kt,b[4]=Wt,b[5]=zt,b[6]=Xt,b[7]=Jt,b[8]=Yt,b[9]=Qt,b[10]=ei,b[11]=ti,b[12]=ii,b[13]=ri,b[14]=ni,b[15]=oi,b[16]=si,b[17]=ai,b[18]=rr,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 ae={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(ae[o])return ae[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 ae[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)}),vu="3.7.8",Tp=vu,Br=typeof Buffer=="function",ql=typeof TextDecoder=="function"?new TextDecoder:void 0,$l=typeof TextEncoder=="function"?new TextEncoder:void 0,Op="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Qr=Array.prototype.slice.call(Op),Gn=(e=>{let t={};return e.forEach((i,r)=>t[i]=r),t})(Qr),Pp=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Tt=String.fromCharCode.bind(String),Hl=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),wu=e=>e.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),bu=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),yu=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+=Qr[t>>18&63]+Qr[t>>12&63]+Qr[t>>6&63]+Qr[t&63]}return a?s.slice(0,a-3)+"===".substring(a):s},Us=typeof btoa=="function"?e=>btoa(e):Br?e=>Buffer.from(e,"binary").toString("base64"):yu,Os=Br?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let i=0,r=e.length;i<r;i+=4096)t.push(Tt.apply(null,e.subarray(i,i+4096)));return Us(t.join(""))},eo=(e,t=!1)=>t?wu(Os(e)):Os(e),xp=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?Tt(192|t>>>6)+Tt(128|t&63):Tt(224|t>>>12&15)+Tt(128|t>>>6&63)+Tt(128|t&63)}else{var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return Tt(240|t>>>18&7)+Tt(128|t>>>12&63)+Tt(128|t>>>6&63)+Tt(128|t&63)}},Np=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,Mu=e=>e.replace(Np,xp),Gl=Br?e=>Buffer.from(e,"utf8").toString("base64"):$l?e=>Os($l.encode(e)):e=>Us(Mu(e)),xr=(e,t=!1)=>t?wu(Gl(e)):Gl(e),Vl=e=>xr(e,!0),Rp=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,Lp=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 Tt((i>>>10)+55296)+Tt((i&1023)+56320);case 3:return Tt((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return Tt((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},Au=e=>e.replace(Rp,Lp),Su=e=>{if(e=e.replace(/\s+/g,""),!Pp.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=Gn[e.charAt(s++)]<<18|Gn[e.charAt(s++)]<<12|(i=Gn[e.charAt(s++)])<<6|(r=Gn[e.charAt(s++)]),i===64?n.push(Tt(t>>16&255)):r===64?n.push(Tt(t>>16&255,t>>8&255)):n.push(Tt(t>>16&255,t>>8&255,t&255));return n.join("")},js=typeof atob=="function"?e=>atob(bu(e)):Br?e=>Buffer.from(e,"base64").toString("binary"):Su,Cu=Br?e=>Hl(Buffer.from(e,"base64")):e=>Hl(js(e).split("").map(t=>t.charCodeAt(0))),Eu=e=>Cu(Iu(e)),Fp=Br?e=>Buffer.from(e,"base64").toString("utf8"):ql?e=>ql.decode(Cu(e)):e=>Au(js(e)),Iu=e=>bu(e.replace(/[-_]/g,t=>t=="-"?"+":"/")),Ps=e=>Fp(Iu(e)),Dp=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)},ku=e=>({value:e,enumerable:!1,writable:!0,configurable:!0}),Tu=function(){let e=(t,i)=>Object.defineProperty(String.prototype,t,ku(i));e("fromBase64",function(){return Ps(this)}),e("toBase64",function(t){return xr(this,t)}),e("toBase64URI",function(){return xr(this,!0)}),e("toBase64URL",function(){return xr(this,!0)}),e("toUint8Array",function(){return Eu(this)})},Ou=function(){let e=(t,i)=>Object.defineProperty(Uint8Array.prototype,t,ku(i));e("toBase64",function(t){return eo(this,t)}),e("toBase64URI",function(){return eo(this,!0)}),e("toBase64URL",function(){return eo(this,!0)})},Bp=()=>{Tu(),Ou()},ps={version:vu,VERSION:Tp,atob:js,atobPolyfill:Su,btoa:Us,btoaPolyfill:yu,fromBase64:Ps,toBase64:xr,encode:xr,encodeURI:Vl,encodeURL:Vl,utob:Mu,btou:Au,decode:Ps,isValid:Dp,fromUint8Array:eo,toUint8Array:Eu,extendString:Tu,extendUint8Array:Ou,extendBuiltins:Bp},jp=(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))(jp||{}),qp=(e=>(e.InvalidTickEvent="InvalidTickEvent",e.InvalidPositionObject="InvalidPositionObject",e.InvalidPositionRewardObject="InvalidPositionRewardObject",e.InvalidParams="InvalidParams",e.FetchError="FetchError",e))(qp||{}),$p=(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))($p||{}),Hp=(e=>(e.ClmmVestNotSet="ClmmVestNotSet",e.ClmmVestFetchError="ClmmVestFetchError",e))(Hp||{}),Gp=(e=>(e.NotFoundPartnerObject="NotFoundPartnerObject",e.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",e))(Gp||{}),Vp=(e=>(e.InvalidConfig="InvalidConfig",e.InvalidConfigHandle="InvalidConfigHandle",e.InvalidSimulateAccount="InvalidSimulateAccount",e))(Vp||{}),Zp=(e=>(e.InvalidSendAddress="InvalidSendAddress",e.InvalidRecipientAddress="InvalidRecipientAddress",e.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",e.InsufficientBalance="InsufficientBalance",e.InvalidTarget="InvalidTarget",e.InvalidTransactionBuilder="InvalidTransactionBuilder",e))(Zp||{}),Kp=(e=>(e.InvalidCoin="InvalidCoin",e.NotFoundPath="NotFoundPath",e.NoDowngradeNeedParams="NoDowngradeNeedParams",e.InvalidSwapCountUrl="InvalidSwapCountUrl",e.InvalidTransactionBuilder="InvalidTransactionBuilder",e.InvalidServerResponse="InvalidServerResponse",e))(Kp||{}),Wp=(e=>(e.InvalidType="InvalidType",e))(Wp||{}),Pu=class extends Up{constructor(e,t,i){super(e,t||"UnknownError",i)}static isVaultsErrorCode(e,t){return this.isErrorCode(e,t)}},Ri=(e,t,i)=>{throw new Pu(t.message,e,i)},Je=(e,t,i)=>{throw new Pu(t,e,i)},zp=class{constructor(e){this._cache={},this._sdk=e}get sdk(){return this._sdk}setTokenListCache(e){let{coin_list_handle:t}=zi(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}=zi(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(jl(c)===jl(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,fi)}else console.log(`not found ${a}`)}}return t}async getCoinConfigs(e=!1,t=!0){let{coin_list_handle:i}=zi(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")&&Je("FetchError",`when getCoinConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getCoinConfigs"});let g=this.buildCoinConfig(p,t);this.updateCache(`${i}_${g.address}_getCoinConfig`,g,fi),c.push({...g})}),this.updateCache(r,c,fi),c}async getCoinConfig(e,t=!1,i=!0){let{coin_list_handle:r}=zi(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:Ep(e)}}});(a.error!=null||a.data?.content?.dataType!=="moveObject")&&Je("FetchError",`when getCoinConfig get object error: ${a.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getCoinConfig"});let c=this.buildCoinConfig(a,i);return this.updateCache(n,c,fi),c}buildCoinConfig(e,t=!0){let i=Hn(e);i=i.value.fields;let r={...i};return r.id=fs(e),r.address=hs(i.coin_type.fields.name).full_address,i.pyth_id&&(r.pyth_id=ds(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}=zi(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")&&Je("FetchError",`when getClmmPoolsConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getClmmPoolConfigs"});let g=this.buildClmmPoolConfig(p,t);this.updateCache(`${g.pool_address}_getClmmPoolConfig`,g,fi),c.push({...g})}),this.updateCache(r,c,fi),c}async getClmmPoolConfig(e,t=!1,i=!0){let{clmm_pools_handle:r}=zi(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,fi),c}buildClmmPoolConfig(e,t=!0){let i=Hn(e);i=i.value.fields;let r={...i};return r.id=fs(e),r.pool_address=ds(i.pool_address),this.transformExtensions(r,i.extension_fields.fields.contents,t),r}async getLaunchpadPoolConfigs(e=!1,t=!0){let{launchpad_pools_handle:i}=zi(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")&&Je("FetchError",`when getCoinConfigs get objects error: ${p.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getLaunchpadPoolConfigs"});let g=this.buildLaunchpadPoolConfig(p,t);this.updateCache(`${g.pool_address}_getLaunchpadPoolConfig`,g,fi),c.push({...g})}),this.updateCache(r,c,fi),c}async getLaunchpadPoolConfig(e,t=!1,i=!0){let{launchpad_pools_handle:r}=zi(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,fi),c}buildLaunchpadPoolConfig(e,t=!0){let i=Hn(e);i=i.value.fields;let r={...i};r.id=fs(e),r.pool_address=ds(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(ps.decode(r.regulation).replace(/%/g,"%25"))}catch{r.regulation=ps.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(ps.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=Ip(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(hs(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,fi),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")&&Je("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${i.error}, please check the rpc and contracts address config.`,{[Xr.METHOD_NAME]:"getCetusConfigHandle"});let r=Hn(i),n=kp(i);switch(hs(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=Sp){let r=this._cache[e];r?(r.overdue_time=Ul(i),r.value=t):r=new Cp(t,Ul(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}}},Xp=Li(Fi()),Yp="position_liquidity_snapshot",Qp=(e=>(e.Deleted="Deleted",e.Exists="Exists",e.NotExists="NotExists",e))(Qp||{}),em=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent"],Ai=Li(Fi()),rm=Li(Fi()),um="partner",Kn="pool_script",Nr="pool_script_v2",xu="pool_script_v3",Nu="router",cm="router_with_partner",Lr="fetcher_script";var dm="utils";var hm=Li(Fi()),Pr=9e15,ir=1e9,xs="0123456789abcdef",no="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",oo="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ns={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Pr,maxE:Pr,crypto:!1},Ru,Ni,De=!0,lo="[DecimalError] ",tr=lo+"Invalid argument: ",Lu=lo+"Precision limit exceeded",Fu=lo+"crypto unavailable",Du="[object Decimal]",Nt=Math.floor,Mt=Math.pow,mm=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,gm=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,_m=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Bu=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,gi=1e7,Ne=7,vm=9007199254740991,wm=no.length-1,Rs=oo.length-1,oe={toStringTag:Du};oe.absoluteValue=oe.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Oe(e)};oe.ceil=function(){return Oe(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(tr+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())+Ne,r.rounding=1,i=bm(r,Hu(r,i)),r.precision=e,r.rounding=t,Oe(Ni==2||Ni==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(De=!1,s=v.s*Mt(v.s*v,1/3),!s||Math.abs(s)==1/0?(i=Ot(v.d),e=v.e,(s=(e-i.length+1)%3)&&(i+=s==1||s==-2?"0":"00"),s=Mt(i,1/3),e=Nt((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=nt(g.plus(v).times(c),g.plus(p),a+2,1),Ot(c.d).slice(0,a)===(i=Ot(r.d)).slice(0,a))if(i=i.slice(a-3,a+1),i=="9999"||!n&&i=="4999"){if(!n&&(Oe(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")&&(Oe(r,e+1,1),t=!r.times(r).times(r).eq(v));break}return De=!0,Oe(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-Nt(this.e/Ne))*Ne,e=t[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};oe.dividedBy=oe.div=function(e){return nt(this,new this.constructor(e))};oe.dividedToIntegerBy=oe.divToInt=function(e){var t=this,i=t.constructor;return Oe(nt(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 Oe(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/co(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=Fr(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 Oe(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=Fr(s,2,n,n,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,n=n.times(1/co(5,e)),n=Fr(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,Oe(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,nt(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()?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))};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,De=!1,i=i.times(i).minus(1).sqrt().plus(i),De=!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,De=!1,i=i.times(i).plus(1).sqrt().plus(i),De=!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?Oe(new s(n),e,t,!0):(s.precision=i=r-n.e,n=nt(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=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)))};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<=Rs)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<=Rs)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/Ne+2|0),e=i;e;--e)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(De=!1,t=Math.ceil(c/Ne),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)),De=!0,Oe(a,v.precision=y,v.rounding=A,!0)};oe.isFinite=function(){return!!this.d};oe.isInteger=oe.isInt=function(){return!!this.d&&Nt(this.e/Ne)>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(De=!1,c=y+k,a=er(g,c),r=t?so(v,c+10):er(e,c),p=nt(a,r,c,1),en(p.d,n=y,A))do if(c+=10,a=er(g,c),r=t?so(v,c+10):er(e,c),p=nt(a,r,c,1),!s){+Ot(p.d).slice(n+1,n+15)+1==1e14&&(p=Oe(p,y+1,0));break}while(en(p.d,n+=10,A));return De=!0,Oe(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 De?Oe(e,c,p):e}if(i=Nt(e.e/Ne),v=Nt(k.e/Ne),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/Ne),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=uo(g,i),De?Oe(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]?Oe(new r(i),r.precision,r.rounding):(De=!1,r.modulo==9?(t=nt(i,e.abs(),0,3,1),t.s*=e.s):t=nt(i,e,0,r.modulo,1),t=t.times(e),De=!0,i.minus(t))};oe.naturalExponential=oe.exp=function(){return Ls(this)};oe.naturalLogarithm=oe.ln=function(){return er(this)};oe.negated=oe.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Oe(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)),De?Oe(e,c,p):e;if(s=Nt(y.e/Ne),r=Nt(e.e/Ne),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/Ne),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=uo(g,r),De?Oe(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(tr+e);return i.d?(t=Uu(i.d),e&&i.e+1>t&&(t=i.e+1)):t=NaN,t};oe.round=function(){var e=this,t=e.constructor;return Oe(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())+Ne,r.rounding=1,i=Mm(r,Hu(r,i)),r.precision=e,r.rounding=t,Oe(Ni>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(De=!1,g=Math.sqrt(+a),g==0||g==1/0?(t=Ot(c),(t.length+p)%2==0&&(t+="0"),g=Math.sqrt(t),p=Nt((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(nt(a,s,i+2,1)).times(.5),Ot(s.d).slice(0,i)===(t=Ot(r.d)).slice(0,i))if(t=t.slice(i-3,i+1),t=="9999"||!n&&t=="4999"){if(!n&&(Oe(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")&&(Oe(r,p+1,1),e=!r.times(r).eq(a));break}return De=!0,Oe(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=nt(i,new r(1).minus(i.times(i)).sqrt(),e+10,0),r.precision=e,r.rounding=t,Oe(Ni==2||Ni==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=Nt(v.e/Ne)+Nt(e.e/Ne),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=uo(s,i),De?Oe(e,y.precision,y.rounding):e};oe.toBinary=function(e,t){return qs(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:(Dt(e,0,ir),t===void 0?t=r.rounding:Dt(t,0,8),Oe(i,e+i.e+1,t))};oe.toExponential=function(e,t){var i,r=this,n=r.constructor;return e===void 0?i=Ci(r,!0):(Dt(e,0,ir),t===void 0?t=n.rounding:Dt(t,0,8),r=Oe(new n(r),e+1,t),i=Ci(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=Ci(n):(Dt(e,0,ir),t===void 0?t=s.rounding:Dt(t,0,8),r=Oe(new s(n),e+n.e+1,t),i=Ci(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=Uu(U)-k.e-1,a=s%Ne,t.d[0]=Mt(10,a<0?Ne+a:a),e==null)e=s>0?t:g;else{if(c=new P(e),!c.isInt()||c.lt(g))throw Error(tr+c);e=c.gt(t)?s>0?t:g:c}for(De=!1,c=new P(Ot(U)),v=P.precision,P.precision=s=U.length*Ne*2;y=nt(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=nt(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=nt(g,r,s,1).minus(k).abs().cmp(nt(p,i,s,1).minus(k).abs())<1?[g,r]:[p,i],P.precision=v,De=!0,A};oe.toHexadecimal=oe.toHex=function(e,t){return qs(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:Dt(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]?(De=!1,i=nt(i,e,0,t,1).times(e),De=!0,Oe(i)):(e.s=i.s,i=e),i};oe.toNumber=function(){return+this};oe.toOctal=function(e,t){return qs(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(Mt(+c,g));if(c=new p(c),c.eq(1))return c;if(r=p.precision,s=p.rounding,e.eq(1))return Oe(c,r,s);if(t=Nt(e.e/Ne),t>=e.d.length-1&&(i=g<0?-g:g)<=vm)return n=ju(p,c,i,r),e.s<0?new p(1).div(n):Oe(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=Mt(+c,g),t=i==0||!isFinite(i)?Nt(g*(Math.log("0."+Ot(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):(De=!1,p.rounding=c.s=1,i=Math.min(12,(t+"").length),n=Ls(e.times(er(c,r+i)),r),n.d&&(n=Oe(n,r+5,1),en(n.d,r,s)&&(t=r+10,n=Oe(Ls(e.times(er(c,t+i)),t),t+5,1),+Ot(n.d).slice(r+1,r+15)+1==1e14&&(n=Oe(n,r+1,0)))),n.s=a,De=!0,p.rounding=s,Oe(n,r,s))};oe.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):(Dt(e,1,ir),t===void 0?t=n.rounding:Dt(t,0,8),r=Oe(new n(r),e,t),i=Ci(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):(Dt(e,1,ir),t===void 0?t=r.rounding:Dt(t,0,8)),Oe(new r(i),e,t)};oe.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};oe.truncated=oe.trunc=function(){return Oe(new this.constructor(this),this.e+1,1)};oe.valueOf=oe.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 Ot(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=Ne-r.length,i&&(s+=Qi(i)),s+=r;a=e[t],r=a+"",i=Ne-r.length,i&&(s+=Qi(i))}else if(a===0)return"0";for(;a%10===0;)a/=10;return s+a}function Dt(e,t,i){if(e!==~~e||e<t||e>i)throw Error(tr+e)}function en(e,t,i,r){var n,s,a,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Ne,n=0):(n=Math.ceil((t+1)/Ne),t%=Ne),s=Mt(10,Ne-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)==Mt(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)==Mt(10,t-3)-1,a}function to(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]+=xs.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 bm(e,t){var i,r,n;if(t.isZero())return t;r=t.d.length,r<32?(i=Math.ceil(r/3),n=(1/co(4,i)).toString()):(i=16,n="2.3283064365386962890625e-10"),e.precision+=i,t=Fr(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 nt=(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,ae,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=Ne,v=Nt(r.e/k)-Nt(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++)ae=A*p+(o[y]||0),K[y]=ae/l|0,A=ae%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,Ru=U;else{for(y=1,A=K[0];A>=10;A/=10)y++;j.e=y+v*k-1,Oe(j,c?s+j.e+1:s,a,U)}return j}})();function Oe(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+=Ne,a=t,v=y[A=0],p=v/Mt(10,n-a-1)%10|0;else if(A=Math.ceil((s+1)/Ne),c=y.length,A>=c)if(r){for(;c++<=A;)y.push(0);v=p=0,n=1,s%=Ne,a=s-Ne+1}else break e;else{for(v=c=y[A],n=1;c>=10;c/=10)n++;s%=Ne,a=s-Ne+n,p=a<0?0:v/Mt(10,n-a-1)%10|0}if(r=r||t<0||y[A+1]!==void 0||(a<0?v:v%Mt(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/Mt(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]=Mt(10,(Ne-t%Ne)%Ne),e.e=-t||0):y[0]=e.e=0,e;if(s==0?(y.length=A,c=1,A--):(y.length=A+1,c=Mt(10,Ne-s),y[A]=a>0?(v/Mt(10,n-a)%Mt(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 De&&(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 $u(e);var r,n=e.e,s=Ot(e.d),a=s.length;return t?(i&&(r=i-a)>0?s=s.charAt(0)+"."+s.slice(1)+Qi(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):n<0?(s="0."+Qi(-n-1)+s,i&&(r=i-a)>0&&(s+=Qi(r))):n>=a?(s+=Qi(n+1-a),i&&(r=i-n-1)>0&&(s=s+"."+Qi(r))):((r=n+1)<a&&(s=s.slice(0,r)+"."+s.slice(r)),i&&(r=i-a)>0&&(n+1===a&&(s+="."),s+=Qi(r))),s}function uo(e,t){var i=e[0];for(t*=Ne;i>=10;i/=10)t++;return t}function so(e,t,i){if(t>wm)throw De=!0,i&&(e.precision=i),Error(Lu);return Oe(new e(no),t,1,!0)}function Si(e,t,i){if(t>Rs)throw Error(Lu);return Oe(new e(oo),t,i,!0)}function Uu(e){var t=e.length-1,i=t*Ne+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 Qi(e){for(var t="";e--;)t+="0";return t}function ju(e,t,i,r){var n,s=new e(1),a=Math.ceil(r/Ne+4);for(De=!1;;){if(i%2&&(s=s.times(t),Ql(s.d,a)&&(n=!0)),i=Nt(i/2),i===0){i=s.d.length-1,n&&s.d[i]===0&&++s.d[i];break}t=t.times(t),Ql(t.d,a)}return De=!0,s}function Yl(e){return e.d[e.d.length-1]&1}function qu(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 Ls(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?(De=!1,p=U):p=t,c=new A(.03125);e.e>-2;)e=e.times(c),y+=5;for(r=Math.log(Mt(2,y))/Math.LN10*2+5|0,p+=r,i=s=a=new A(1),A.precision=p;;){if(s=Oe(s.times(e),p,1),i=i.times(++v),c=a.plus(nt(s,i,p,1)),Ot(c.d).slice(0,p)===Ot(a.d).slice(0,p)){for(n=y;n--;)a=Oe(a.times(a),p,1);if(t==null)if(g<3&&en(a.d,p-r,k,g))A.precision=p+=10,i=s=c=new A(1),v=0,g++;else return Oe(a,A.precision=U,k,De=!0);else return A.precision=U,a}a=c}}function er(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?(De=!1,v=X):v=t,j.precision=v+=U,i=Ot(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=Ot(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=so(j,v+2,X).times(s+""),P=er(new j(r+"."+i.slice(1)),v-U).plus(g),j.precision=X,t==null?Oe(P,X,K,De=!0):P;for(y=P,p=a=P=nt(P.minus(1),P.plus(1),v,1),A=Oe(P.times(P),v,1),n=3;;){if(a=Oe(a.times(A),v,1),g=p.plus(nt(a,new j(n),v,1)),Ot(g.d).slice(0,v)===Ot(p.d).slice(0,v))if(p=p.times(2),s!==0&&(p=p.plus(so(j,v+2,X).times(s+""))),p=nt(p,new j(k),v,1),t==null)if(en(p.d,v-U,K,c))j.precision=v+=U,g=a=P=nt(y.minus(1),y.plus(1),v,1),A=Oe(P.times(P),v,1),n=c=1;else return Oe(p,j.precision=X,K,De=!0);else return j.precision=X,p;p=g,n+=2}}function $u(e){return String(e.s*e.s/0)}function io(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)%Ne,i<0&&(r+=Ne),r<n){for(r&&e.d.push(+t.slice(0,r)),n-=Ne;r<n;)e.d.push(+t.slice(r,r+=Ne));t=t.slice(r),r=Ne-t.length}else r-=n;for(;r--;)t+="0";e.d.push(+t),De&&(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 ym(e,t){var i,r,n,s,a,c,p,g,v;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Bu.test(t))return io(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(gm.test(t))i=16,t=t.toLowerCase();else if(mm.test(t))i=2;else if(_m.test(t))i=8;else throw Error(tr+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=ju(r,new r(i),s,s*2)),g=to(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=uo(g,v),e.d=g,De=!1,a&&(e=nt(e,n,c*4)),p&&(e=e.times(Math.abs(p)<54?Mt(2,p):tn.pow(2,p))),De=!0,e)}function Mm(e,t){var i,r=t.d.length;if(r<3)return t.isZero()?t:Fr(e,2,t,t);i=1.4*Math.sqrt(r),i=i>16?16:i|0,t=t.times(1/co(5,i)),t=Fr(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 Fr(e,t,i,r,n){var s,a,c,p,g=1,v=e.precision,y=Math.ceil(v/Ne);for(De=!1,p=i.times(i),c=new e(r);;){if(a=nt(c.times(p),new e(t++*t++),v,1),c=n?r.plus(a):r.minus(a),r=nt(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 De=!0,a.d.length=y+1,a}function co(e,t){for(var i=e;--t;)i*=e;return i}function Hu(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=Yl(i)?r?2:3:r?4:1,t;Ni=Yl(i)?r?1:4:r?3:2}return t.minus(n).abs()}function qs(e,t,i,r){var n,s,a,c,p,g,v,y,A,k=e.constructor,U=i!==void 0;if(U?(Dt(i,1,ir),r===void 0?r=k.rounding:Dt(r,0,8)):(i=k.precision,r=k.rounding),!e.isFinite())v=$u(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=to(Ci(A),10,n),A.e=A.d.length),y=to(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=nt(e,A,i,r,0,n),y=e.d,s=e.e,g=Ru),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+=xs.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=to(v,n,t),p=y.length;!y[p-1];--p);for(a=1,v="1.";a<p;a++)v+=xs.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 Ql(e,t){if(e.length>t)return e.length=t,!0}function Am(e){return new this(e).abs()}function Sm(e){return new this(e).acos()}function Cm(e){return new this(e).acosh()}function Em(e,t){return new this(e).plus(t)}function Im(e){return new this(e).asin()}function km(e){return new this(e).asinh()}function Tm(e){return new this(e).atan()}function Om(e){return new this(e).atanh()}function Pm(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(nt(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(nt(e,t,s,1)),i}function xm(e){return new this(e).cbrt()}function Nm(e){return Oe(e=new this(e),e.e+1,2)}function Rm(e,t,i){return new this(e).clamp(t,i)}function Lm(e){if(!e||typeof e!="object")throw Error(lo+"Object expected");var t,i,r,n=e.defaults===!0,s=["precision",1,ir,"rounding",0,8,"toExpNeg",-Pr,0,"toExpPos",0,Pr,"maxE",0,Pr,"minE",-Pr,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(Nt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[i]=r;else throw Error(tr+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(Fu);else this[i]=!1;else throw Error(tr+i+": "+r);return this}function Fm(e){return new this(e).cos()}function Dm(e){return new this(e).cosh()}function Gu(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,eu(s)){g.s=s.s,De?!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++;De?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 io(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),Bu.test(s)?io(g,s):ym(g,s);if(p==="bigint")return s<0?(s=-s,g.s=-1):g.s=1,io(g,s.toString());throw Error(tr+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=Lm,n.clone=Gu,n.isDecimal=eu,n.abs=Am,n.acos=Sm,n.acosh=Cm,n.add=Em,n.asin=Im,n.asinh=km,n.atan=Tm,n.atanh=Om,n.atan2=Pm,n.cbrt=xm,n.ceil=Nm,n.clamp=Rm,n.cos=Fm,n.cosh=Dm,n.div=Bm,n.exp=Um,n.floor=jm,n.hypot=qm,n.ln=$m,n.log=Hm,n.log10=Vm,n.log2=Gm,n.max=Zm,n.min=Km,n.mod=Wm,n.mul=zm,n.pow=Xm,n.random=Jm,n.round=Ym,n.sign=Qm,n.sin=e1,n.sinh=t1,n.sqrt=i1,n.sub=r1,n.sum=n1,n.tan=o1,n.tanh=s1,n.trunc=a1,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 Bm(e,t){return new this(e).div(t)}function Um(e){return new this(e).exp()}function jm(e){return Oe(e=new this(e),e.e+1,3)}function qm(){var e,t,i=new this(0);for(De=!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 De=!0,new this(1/0);i=t}return De=!0,i.sqrt()}function eu(e){return e instanceof tn||e&&e.toStringTag===Du||!1}function $m(e){return new this(e).ln()}function Hm(e,t){return new this(e).log(t)}function Gm(e){return new this(e).log(2)}function Vm(e){return new this(e).log(10)}function Zm(){return qu(this,arguments,-1)}function Km(){return qu(this,arguments,1)}function Wm(e,t){return new this(e).mod(t)}function zm(e,t){return new this(e).mul(t)}function Xm(e,t){return new this(e).pow(t)}function Jm(e){var t,i,r,n,s=0,a=new this(1),c=[];if(e===void 0?e=this.precision:Dt(e,1,ir),r=Math.ceil(e/Ne),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(Fu);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=Ne,r&&e&&(n=Mt(10,Ne-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-=Ne)c.shift();for(r=1,n=c[0];n>=10;n/=10)r++;r<Ne&&(i-=Ne-r)}return a.e=i,a.d=c,a}function Ym(e){return Oe(e=new this(e),e.e+1,this.rounding)}function Qm(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function e1(e){return new this(e).sin()}function t1(e){return new this(e).sinh()}function i1(e){return new this(e).sqrt()}function r1(e,t){return new this(e).sub(t)}function n1(){var e=0,t=arguments,i=new this(t[e]);for(De=!1;i.s&&++e<t.length;)i=i.plus(t[e]);return De=!0,Oe(i,this.precision,this.rounding)}function o1(e){return new this(e).tan()}function s1(e){return new this(e).tanh()}function a1(e){return Oe(e=new this(e),e.e+1,1)}oe[Symbol.for("nodejs.util.inspect.custom")]=oe.toString;oe[Symbol.toStringTag]="Decimal";var tn=oe.constructor=Gu(Ns);no=new tn(no);oo=new tn(oo);var St=tn;function ao(e){let t=jt.isSuiCoin(e.coin_type_a),i=jt.isSuiCoin(e.coin_type_b);return{is_adjust_coin_a:t,is_adjust_coin_b:i}}function l1(e,t){return St.ceil(St(e).div(1+t)).toString()}var ur=class{static createCollectRewarderAndFeeParams(e,t,i,r,n,s){n===void 0&&(n=[...r]),s===void 0&&(s=[...r]);let a=_s(i.coin_type_a),c=_s(i.coin_type_b);if(i.collect_fee){let g=jt.buildCoinForAmount(t,n,BigInt(0),a,!1);n=g.remain_coins;let v=jt.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(_s(g)){case a:p.push(jt.buildCoinForAmount(t,n,BigInt(0),g,!1).target_coin);break;case c:p.push(jt.buildCoinForAmount(t,s,BigInt(0),g,!1).target_coin);break;default:p.push(jt.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=jt.selectCoinAssetGreaterThanOrEqual(t,i).selected_coins,s=jt.calculateTotalBalance(t);if(n.length===0&&Je("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${s}`),s-i>1e9)return{fixAmount:i};let a=await e.FullClient.calculationTxGas(gs.from(r));if(jt.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&&Je("InsufficientBalance","gas Insufficient balance");let p=new gs;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}=ao(i),p=c?i.amount_a:i.amount_b,g=await this.adjustTransactionForGas(e,jt.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 gs;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?jt.buildCoinForAmountInterval(e,s,{amount_second:BigInt(l1(i,r)),amount_first:BigInt(i)},n,a,c):jt.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=fm.estLiquidityAndCoinAmountFromOneAmounts(Number(e.tick_lower),Number(e.tick_upper),new hm.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=pm(p),y=r.is_open?[e.object(v.global_config_id),e.object(r.pool_id),e.pure.u32(Number(Xl(BigInt(r.tick_lower)).toString())),e.pure.u32(Number(Xl(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(Jl)]:[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(Jl)];return e.moveCall({target:`${g.published_at}::${Nr}::${c}`,typeArguments:a,arguments:y}),e}static checkCoinThreshold(e,t,i,r,n,s){t&&i.moveCall({target:`${e.sdkOptions.integrate.published_at}::${Nu}::check_coin_threshold`,typeArguments:[s],arguments:[r,i.pure.u64(n)]})}},Or=class Yi{static getDefaultSqrtPriceLimit(t){return new rm.default(t?sm:om)}static getDefaultOtherAmountThreshold(t){return t?lm:am}static async buildSwapTransactionForGas(t,i,r,n){let s=this.buildSwapTransaction(t,i,r);s.setSender(t.getSenderAddress());let a=await this.adjustTransactionForGas(t,Ut.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=Ut.buildCoinForAmount(s,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a),v=Ut.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=Yi.getDefaultSqrtPriceLimit(i.a2b),g=[i.coin_type_a,i.coin_type_b],{global_config_id:v}=zl(a);v===void 0&&Je("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(Zn)]:[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(Zn)];return t.moveCall({target:`${c.published_at}::${Nr}::${A}`,typeArguments:g,arguments:k}),t}static async adjustTransactionForGas(t,i,r,n){n.setSender(t.getSenderAddress());let s=Ut.selectCoinAssetGreaterThanOrEqual(i,r).selected_coins,a=Ut.calculateTotalBalance(i);if(s.length===0&&Je("InsufficientBalance",`Insufficient balance exceed amount ${r} real amount ${a}`),a-r>1e9)return{fixAmount:r};let c=await t.FullClient.calculationTxGas(n);if(Ut.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&&Je("InsufficientBalance","gas Insufficient balance");let g=new ms;return{fixAmount:r,newTx:g}}}return{fixAmount:r}}static buildSwapTransaction(t,i,r){let n=new ms;n.setSender(t.getSenderAddress());let s=Ut.buildCoinForAmount(n,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1),a=Ut.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=nm(a,r.slippage,!r.by_amount_in);i.amount_limit=c.toString()}catch(s){Ri("InvalidConfig",s)}return i}static async buildSwapTransactionWithoutTransferCoinsForGas(t,i,r,n){let{tx:s,coin_ab_s:a}=Yi.buildSwapTransactionWithoutTransferCoins(t,i,r);s.setSender(t.getSenderAddress());let c=await Yi.adjustTransactionForGas(t,Ut.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 Yi.fixSwapParams(t,i,n);let v=Ut.buildCoinForAmount(s,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1,!0),y=Ut.buildCoinForAmount(s,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1,!0),A=Yi.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 ms;n.setSender(t.getSenderAddress());let s=Ut.buildCoinForAmount(n,r,i.a2b?BigInt(i.by_amount_in?i.amount:i.amount_limit):BigInt(0),i.coin_type_a,!1,!0),a=Ut.buildCoinForAmount(n,r,i.a2b?BigInt(0):BigInt(i.by_amount_in?i.amount:i.amount_limit),i.coin_type_b,!1,!0),c=Yi.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=Yi.getDefaultSqrtPriceLimit(r.a2b),{global_config_id:v}=zl(c);v===void 0&&Je("InvalidConfig","clmm.config.global_config_id is undefined");let y=r.swap_partner!==void 0,A=y?"swap_with_partner":"swap",k=y?cm:Nu,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(Zn)]:[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(Zn)],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);ur.checkCoinThreshold(t,r.by_amount_in,i,K,X,j)}return{tx:i,txRes:W}}};function u1(e){return{coin_type_a:e.coin_type_a,coin_type_b:e.coin_type_b,current_sqrt_price:new Ai.default(e.current_sqrt_price),current_tick_index:e.current_tick_index,fee_growth_global_a:new Ai.default(e.fee_growth_global_a),fee_growth_global_b:new Ai.default(e.fee_growth_global_b),fee_protocol_coin_a:new Ai.default(e.fee_protocol_coin_a),fee_protocol_coin_b:new Ai.default(e.fee_protocol_coin_b),fee_rate:new Ai.default(e.fee_rate),liquidity:new Ai.default(e.liquidity),tick_indexes:[],tick_spacing:Number(e.tick_spacing),ticks:[],collection_name:""}}function c1(e,t,i,r,n,s){if(i===pi)return{amount_in:pi,amount_out:pi,next_sqrt_price:t,fee_amount:pi};let a=e.gte(t),c,p,g,v;if(s){let y=lr.checkMulDivFloor(r,lr.checkUnsignedSub(Vn,n),Vn,64),A=Wl(e,t,i,a);A.gt(y)?(c=y,v=lr.checkUnsignedSub(r,y),g=tm(e,i,y,a)):(c=A,v=lr.checkMulDivCeil(c,n,Vn.sub(n),64),g=t),p=Kl(e,g,i,a)}else{let y=Kl(e,t,i,a);y.gt(r)?(p=r,g=im(e,i,r,a)):(p=y,g=t),c=Wl(e,g,i,a),v=lr.checkMulDivCeil(c,n,Vn.sub(n),64)}return{amount_in:c,amount_out:p,next_sqrt_price:g,fee_amount:v}}function d1(e,t,i,r,n){let s=i,a=r.liquidity,{current_sqrt_price:c}=r,p={amount_in:pi,amount_out:pi,fee_amount:pi,ref_amount:pi,next_sqrt_price:pi,cross_tick_num:0},g,v,y=Or.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=c1(c,g,a,s,r.fee_rate,t);if(k.amount_in.eq(pi)||(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 Ai.default(-1)),e?lr.is_neg(v)?a=a.add(new Ai.default(Zl(BigInt(v.toString()),128))):a=a.add(v):lr.is_neg(v)?a=a.sub(new Ai.default(Zl(BigInt(v.toString()),128))):a=a.sub(v),c=A.sqrt_price):c=k.next_sqrt_price,p.cross_tick_num+=1,s.eq(pi))break}return p.amount_in=p.amount_in.add(p.fee_amount),p.next_sqrt_price=c,p}var mi=Li(Fi());function _1(e,t,i){let r=Dr(e).name,n=Dr(t).name;return`${r}-${n}[${i}]`}function vs(e){let t=Vu(e),i=Dr(t),r=$s(e);r==null&&Je("InvalidPoolObject",`Pool id ${Fs(e)} not exists.`,{[ho.METHOD_NAME]:"buildPool"});let n=[];r.rewarder_manager.fields.rewarders.forEach(p=>{let{emissions_per_second:g}=p.fields,v=g1.fromX64(new mi.default(g)),y=Math.floor(v.toNumber()*60*60*24);n.push({emissions_per_second:g,coin_type:Dr(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:Fs(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:cr(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=_1(c.coin_type_a,c.coin_type_b,c.tick_spacing),c}function ws(e){(e.error!=null||e.data?.content?.dataType!=="moveObject")&&Je("InvalidPositionObject",`Position not exists. Get Position error:${e.error}`,{[ho.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=$s(e);if(r){let a=Vu(e),c=m1(e);"nft"in r?(r=r.nft.fields,t.description=r.description,t.name=r.name,t.link=r.url):t=h1(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:cr(BigInt(r.tick_lower_index.fields.bits)),tick_upper_index:cr(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=f1(e);n&&(i.pos_object_id=n.objectId,i.position_status="Deleted");let s=p1(e);return s&&(i.pos_object_id=s,i.position_status="NotExists"),i}function Ds(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:cr(BigInt(i)),tick_upper_index:cr(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 bs(e){(e.error!=null||e.data?.content?.dataType!=="moveObject")&&Je("InvalidTickObject",`Tick not exists. Get tick data error:${e.error}`,{[ho.METHOD_NAME]:"buildTickData"});let t=$s(e).value.fields.value.fields;return{object_id:Fs(e),index:cr(BigInt(t.index.fields.bits)),sqrt_price:new mi.default(t.sqrt_price),liquidity_net:new mi.default(t.liquidity_net.fields.bits),liquidity_gross:new mi.default(t.liquidity_gross),fee_growth_outside_a:new mi.default(t.fee_growth_outside_a),fee_growth_outside_b:new mi.default(t.fee_growth_outside_b),rewarders_growth_outside:t.rewards_growth_outside}}function v1(e){(!e||!e.index||!e.sqrt_price||!e.liquidity_net||!e.liquidity_gross||!e.fee_growth_outside_a||!e.fee_growth_outside_b)&&Je("InvalidTickFields","Invalid tick fields.",{[ho.METHOD_NAME]:"buildTickDataByEvent"});let t=cr(BigInt(e.index.bits)),i=new mi.default(e.sqrt_price),r=new mi.default(e.liquidity_net.bits),n=new mi.default(e.liquidity_gross),s=new mi.default(e.fee_growth_outside_a),a=new mi.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 w1(e,t,i){let r=[],{timestampMs:n,events:s}=e,a=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent"];return s?.forEach((c,p)=>{let g=Dr(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)&&(Yr(v.parsed_json.amount_a).gt(0)||Yr(v.parsed_json.amount_b).gt(0))&&r.push(v);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":(Yr(v.parsed_json.amount_a).gt(0)||Yr(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))&&Yr(v.parsed_json.amount).gt(0)&&r.push(v);break;default:break}}}),r}function b1(e,t,i,r){let n=[],{timestampMs:s,events:a}=e;return a?.forEach((c,p)=>{let{name:g,address:v}=Dr(c.type);if(em.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 Bs(e,t,i,r){t.moveCall({target:`${e.sdkOptions.integrate.published_at}::${dm}::transfer_coin_to_sender`,typeArguments:[r],arguments:[i]})}function y1(e,t,i,r,n){n!=null?t.transferObjects([i],t.pure.address(n)):Bs(e,t,i,r)}var T1=1e4,Rr=class{static parseClmmVestInfo(e){let t=As(e),i=k1(e),r=I1(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:ou(s.fields.percentage).div(T1).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:su(e.coin_a.name,!1),coin_type_b:su(e.coin_b.name,!1)}}static parsePoolLiquiditySnapshot(e){let t=As(e);return{current_sqrt_price:t.current_sqrt_price,remove_percent:ou(t.remove_percent).div(1e6).toString(),snapshots:{id:t.snapshots.fields.id.id,size:t.snapshots.fields.size}}}static parsePositionSnapshot(e){let t=As(e),i=t.value.fields.value.fields;return{position_id:t.name,liquidity:i.liquidity,tick_lower_index:nu(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:nu(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}}},O1=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&&Je("InvalidConfig",`when getPositionList get position objects error: ${a.error}, please check the rpc, contracts address config and position id.`,{[rt.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:Sr(v.coin_type_a).full_address,coin_type_b:Sr(v.coin_type_b).full_address})})}catch(c){return Ri("FetchError",c,{[rt.METHOD_NAME]:"getPoolImmutables"})}return n.data=r,s&&this._sdk.updateCache(`${i}_getPoolImmutables`,r,Wn),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")&&Je("InvalidPoolObject",`getPoolWithPages error code: ${s.error?.code??"unknown error"}, please check config and object ids`,{[rt.METHOD_NAME]:"getPoolsWithPage"});let a=vs(s);i.data.push(a);let c=`${a.id}_getPoolObject`;this._sdk.updateCache(c,a,Wn)}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:Yp}}),r=Rr.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=Rr.parsePositionSnapshot(c);a.push(p)}),r.position_snapshots=a}}return r}catch(i){return Ri("InvalidPoolObject",i,{[rt.METHOD_NAME]:"getPoolLiquiditySnapshot",[rt.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=Rr.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")&&Je("InvalidPoolObject",`getPools error code: ${r.error?.code??"unknown error"}, please check config and object ids`,{[rt.METHOD_NAME]:"getAssignPools"});let n=vs(r);t.push(n);let s=`${n.id}_getPoolObject`;this._sdk.updateCache(s,n,Wn)}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")&&Je("InvalidPoolObject",`getPool error code: ${s.error?.code??"unknown error"}, please check config and object id`,{[rt.METHOD_NAME]:"getPool"});let a=vs(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||Je("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[rt.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){Ri("FetchError",c,{[rt.METHOD_NAME]:"getPoolByCoins",[rt.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(iu(yr(e.coin_type_a),yr(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(iu(yr(e.coin_type_a),yr(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=C1(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(Sr(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,Wn)),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=A1(new Jp({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=b1(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=Ms.priceToSqrtPriceX64(s==="coin_a"?Ar(t):Ar(1).div(t),a,c),g=0,v=0;if(n.is_full_range)g=ru.getMinIndex(r),v=ru.getMaxIndex(r);else{let{min_price:K,max_price:X}=n;g=Ms.priceToInitializeTickIndex(s==="coin_a"?Ar(K):Ar(1).div(X),a,c,r),v=Ms.priceToInitializeTickIndex(s==="coin_a"?Ar(X):Ar(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}=M1.estLiquidityAndCoinAmountFromOneAmounts(g,v,new Xp.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 Jr,t.setSender(this.sdk.getSenderAddress());let{integrate:i,clmm_pool:r}=this.sdk.sdkOptions,n=ys(r),s=n.global_config_id,a=n.pools_id,c=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),p=zn.buildCoinForAmount(t,c,BigInt(e.amount_a),e.coin_type_a,!1,!0),g=zn.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(Mr(BigInt(e.tick_lower)).toString())),t.pure.u32(Number(Mr(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(tu)];return t.moveCall({target:`${i.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[e.coin_type_a,e.coin_type_b],arguments:v}),Bs(this._sdk,t,p.target_coin,e.coin_type_a),Bs(this._sdk,t,g.target_coin,e.coin_type_b),t}async createPoolAndAddLiquidityRow(e,t){t=t||new Jr;let{clmm_pool:i}=this.sdk.sdkOptions,r=ys(i),n=r.global_config_id,s=r.pools_id,a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),c=zn.buildCoinForAmount(t,a,BigInt(e.amount_a),e.coin_type_a,!1,!0),p=zn.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(Mr(BigInt(e.tick_lower)).toString())),t.pure.u32(Number(Mr(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(tu)],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 Je("FetchError",`fetch coin ${i} metadata failed`,{[rt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[rt.REQUEST_PARAMS]:e});if(j===null)return Je("FetchError",`fetch coin ${r} metadata failed`,{[rt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[rt.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 Je("FetchError",`fetch coin ${t} metadata failed`,{[rt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[rt.REQUEST_PARAMS]:e});if(W===null)return Je("FetchError",`fetch coin ${i} metadata failed`,{[rt.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[rt.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(Mr(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 Jr,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}::${Lr}::fetch_ticks`,arguments:a,typeArguments:r});let c=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:yr("0x0")});return c.error!=null&&Je("InvalidTickObjectId",`getTicks error code: ${c.error??"unknown error"}, please check config and tick object ids`,{[rt.METHOD_NAME]:"getTicks",[rt.REQUEST_PARAMS]:e}),c.events?.forEach(p=>{Sr(p.type).name==="FetchTicksResultEvent"&&p.parsedJson.ticks.forEach(g=>{i.push(v1(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 Jr,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}::${Lr}::fetch_positions`,arguments:p,typeArguments:s});let g=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:a,sender:yr("0x0")});g.error!=null&&Je("InvalidPositionRewardObject",`fetch position info error code: ${g.error??"unknown error"}, please check config and tick object ids`,{[rt.METHOD_NAME]:"fetchPoolPositionInfoList",[rt.REQUEST_PARAMS]:e});let v=[];if(g?.events?.forEach(y=>{Sr(y.type).name==="FetchPositionsEvent"&&y.parsedJson.positions.forEach(A=>{let k=Ds(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=>{Sr(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")&&Je("InvalidTickObjectId",`getTicksByRpc error code: ${r.error?.code??"unknown error"}, please check config and tick object ids`,{[rt.METHOD_NAME]:"getTicksByRpc"});let n=bs(r);n!=null&&t.push(n)}return t}async getTickDataByIndex(e,t){let i={type:"u64",value:Mr(BigInt(E1(t).toString())).toString()},r=await this.sdk.FullClient.getDynamicFieldObject({parentId:e,name:i});return(r.error!=null||r.data?.content?.dataType!=="moveObject")&&Je("InvalidTickIndex",`get tick by index: ${t} error: ${r.error}`,{[rt.METHOD_NAME]:"getTickDataByIndex"}),bs(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")&&Je("InvalidTickObjectId",`getTicksByRpc error code: ${t.error?.code??"unknown error"}, please check config and tick object ids`,{[rt.METHOD_NAME]:"getTickDataByObjectId"}),bs(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"&&Je("NotFoundPartnerObject",`get partner by object id: ${e} error: ${i[0].error}`,{[rt.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")&&Je("InvalidPartnerRefFeeFields",`get coin by object id: ${c.data.objectId} error: ${c.error}`,{[rt.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 Jr,{clmm_pool:n}=this.sdk.sdkOptions,{global_config_id:s}=ys(n),a=[i],c=[r.object(s),r.object(e),r.object(t)];return r.moveCall({target:`${n.published_at}::${um}::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=S1(t).position.fields.status;if(i)return i}catch(t){console.log("\u{1F680} ~ file: poolModule.ts:1093 ~ PoolModule ~ getPoolStatus ~ error:",t)}}},Xn=Li(Fi()),D1=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=L1(new P1({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=w1(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){Ri("FetchError",g,{[Xi.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(R1(a.data.type).full_address===this.buildPositionType()){let c=ws(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=ws(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=ws(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=lu(i.data).value.fields.value;return Ds(r)}catch(i){return Ri("FetchError",i,{[Xi.METHOD_NAME]:"getPositionInfo",[Xi.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=F1(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=lu(r.data).value.fields.value,s=Ds(n);t.push(s)}catch(n){console.log("getPositionInfoList error",n)}}),t)}catch(t){return Ri("FetchError",t,{[Xi.METHOD_NAME]:"getPositionInfoList",[Xi.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(xi(i).global_config_id),t.object(e.pool_id),t.pure.address(e.position_id)];t.moveCall({target:`${r.published_at}::${Lr}::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 Pi;for(let c of e)this.buildFetchPosFee(c,r);let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:N1("0x0")});n.error!=null&&Je("InvalidPoolObject",`fetch position fee error code: ${n.error??"unknown error"}, please check config and position and pool object ids`,{[Xi.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}=ao(e);if(e=e,e.fix_amount_a&&a||!e.fix_amount_a&&c)return i=await ur.buildAddLiquidityFixTokenForGas(this._sdk,s,e,t,i,r,n),i}return ur.buildAddLiquidityFixToken(this._sdk,s,e,i,r,n)}async createAddLiquidityPayload(e,t,i,r){let{integrate:n,clmm_pool:s}=this._sdk.sdkOptions,a=Cr(BigInt(e.tick_lower)).toString(),c=Cr(BigInt(e.tick_upper)).toString(),p=[e.coin_type_a,e.coin_type_b];t=t||new Pi;let g=!x1(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=Yn.buildCoinForAmount(t,U,v,e.coin_type_a,!1,!0),k=Yn.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}::${Nr}::open_position_with_liquidity`,typeArguments:p,arguments:[t.object(xi(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(Jn)]});else{let U=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());t=ur.createCollectRewarderAndFeeParams(this._sdk,t,e,U,A.remain_coins,k.remain_coins),t.moveCall({target:`${n.published_at}::${Nr}::add_liquidity`,typeArguments:p,arguments:[t.object(xi(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(Jn)]})}return t}async removeLiquidityPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions,n="remove_liquidity";t=t||new Pi;let s=[e.coin_type_a,e.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());t=ur.createCollectRewarderAndFeeParams(this._sdk,t,e,a);let c=[t.object(xi(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(Jn)];return t.moveCall({target:`${r.published_at}::${Kn}::${n}`,typeArguments:s,arguments:c}),t}async closePositionPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions;t=t||new Pi;let n=[e.coin_type_a,e.coin_type_b],s=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return t=ur.createCollectRewarderAndFeeParams(this._sdk,t,e,s),t.moveCall({target:`${r.published_at}::${Kn}::close_position`,typeArguments:n,arguments:[t.object(xi(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(Jn)]}),t}openPositionPayload(e,t){let{clmm_pool:i,integrate:r}=this.sdk.sdkOptions;t=t||new Pi;let n=[e.coin_type_a,e.coin_type_b],s=Cr(BigInt(e.tick_lower)).toString(),a=Cr(BigInt(e.tick_upper)).toString(),c=[t.object(xi(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}::${Kn}::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 Pi;let s=await this.sdk.Pool.getPool(i,!1),a=Number(s.tick_spacing),c=0,p=0;if(e.is_full_range)c=Qn.getMinIndex(a),p=Qn.getMaxIndex(a);else{let{price_base_coin:y,min_price:A,max_price:k}=e;c=Er.priceToInitializeTickIndex(y==="coin_a"?Mi(A):Mi(1).div(k),e.coin_decimals_a,e.coin_decimals_b,a),p=Er.priceToInitializeTickIndex(y==="coin_a"?Mi(k):Mi(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(xi(r).global_config_id),t.object(e.pool_id),t.pure.u32(Number(Cr(BigInt(c)))),t.pure.u32(Number(Cr(BigInt(p))))];return t.moveCall({target:`${n.published_at}::${Kn}::open_position`,typeArguments:g,arguments:v}),t}async collectFeePayload(e,t,i,r){t=t||new Pi;let n=i||Yn.buildCoinWithBalance(BigInt(0),e.coin_type_a,t),s=r||Yn.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(xi(n).global_config_id),t.object(e.pool_id),t.object(e.pos_id),i,r];return t.moveCall({target:`${s.published_at}::${Nr}::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=Qn.getMinIndex(a),p=Qn.getMaxIndex(a);else{let{price_base_coin:W,min_price:j,max_price:K}=n;c=Er.priceToInitializeTickIndex(W==="coin_a"?Mi(j):Mi(1).div(K),n.coin_decimals_a,n.coin_decimals_b,a),p=Er.priceToInitializeTickIndex(W==="coin_a"?Mi(K):Mi(1).div(j),n.coin_decimals_a,n.coin_decimals_b,a)}if("liquidity"in e){let{liquidity:W}=e,j=Er.tickIndexToSqrtPriceX64(c),K=Er.tickIndexToSqrtPriceX64(p),{coin_amount_a:X,coin_amount_b:Q}=au.getCoinAmountFromLiquidity(new Xn.default(W),new Xn.default(s.current_sqrt_price),j,K,!1),se=Mi(X).mul(1+i).toFixed(0,St.ROUND_UP),Y=Mi(Q).mul(1+i).toFixed(0,St.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}=au.estLiquidityAndCoinAmountFromOneAmounts(c,p,new Xn.default(g),v,!0,i,new Xn.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 Pi;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 Je("InvalidParams","fix_amount_a is undefined",{[Xi.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[Xi.REQUEST_PARAMS]:e});t=t||new Pi;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(xi(n).global_config_id),t.object(e.pool_id),t.object(e.pos_id),i,r];return t.moveCall({target:`${s.published_at}::${xu}::collect_fee`,typeArguments:a,arguments:c}),t}},uu=Li(Fi()),j1=class{constructor(e){this._sdk=e,this.growthGlobal=[Ir,Ir,Ir]}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=U1.fromX64(new uu.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(Is(i).global_config_id),t.object(e.pool_id),t.pure.address(e.position_id),t.object(Cs)];t.moveCall({target:`${r.published_at}::${Lr}::fetch_position_rewards`,arguments:s,typeArguments:n})}async fetchPosRewardersAmount(e){let t=new Ss;for(let s of e)this.buildFetchPosReward(s,t);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:t,sender:B1("0x")});i.error!=null&&Je("InvalidConfig",`fetch position rewards error code: ${i.error??"unknown error"}, please check config and params`,{[cu.METHOD_NAME]:"fetchPosRewardersAmount",[cu.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=[Ir,Ir,Ir];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 uu.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 Ss;return i=ur.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 Ss;let s={};return e.forEach(a=>{let c=ks(a.coin_type_a),p=ks(a.coin_type_b);if(a.collect_fee){let v=s[c];v==null&&(i==null?v=Es.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=Es.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=ks(v),A=s[v];A===void 0&&(A=Es.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&&y1(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=Is(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}::${Nr}::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(Cs)]})}),t}createCollectRewarderNoSendPayload(e,t,i){let{clmm_pool:r,integrate:n}=this.sdk.sdkOptions,s=Is(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}::${xu}::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(Cs)]})}),t}},kr=Li(Fi());var H1=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=Tr(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 St(n.fee_rate).div(10**6):new St(n.fee_rate).div(10**9),a=Tr(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 St(1).div(n.current_price),g=c.direction?c.current_price:new St(1).div(c.current_price),v=c.label==="Cetus"?new St(c.fee_rate).div(10**6):new St(c.fee_rate).div(10**9),y=Tr(c.output_amount).div(10**c.to_decimal).mul(v).div(p.mul(g));t=t.add(y)}}}),t.toString()}calculateSwapPriceImpact(e){let t=Tr(0);return e.forEach(i=>{let r=i.base_paths.length;if(r===1){let n=i.base_paths[0],s=Tr(n.output_amount).div(10**n.to_decimal),a=Tr(n.input_amount).div(10**n.from_decimal),c=s.div(a),p=n.direction?new St(n.current_price):new St(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 St(n.current_price):new St(1).div(n.current_price),c=s.direction?new St(s.current_price):new St(1).div(s.current_price),p=a.mul(c),g=new St(s.output_amount).div(10**s.to_decimal),v=new St(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 du,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}::${Lr}::calculate_swap_result`,arguments:g,typeArguments:r})}let n=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:hu("0x0")});n.error!=null&&Je("InvalidConfig",`pre swap with multi pools error code: ${n.error??"unknown error"}, please check config and params`,{[Ji.METHOD_NAME]:"preSwapWithMultiPool",[Ji.REQUEST_PARAMS]:{params:e}});let s=n.events?.filter(p=>fu(p.type).name==="CalculatedSwapResultEvent");if(s.length===0)return null;s.length!==e.pool_ids.length&&Je("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[Ji.METHOD_NAME]:"preSwapWithMultiPool",[Ji.REQUEST_PARAMS]:{params:e}});let a=e.by_amount_in?$1:q1,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 kr.default(s[p].parsedJson.data.amount_out);g.gt(a)&&(c=p,a=g)}else{let g=new kr.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 du,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}::${Lr}::calculate_swap_result`,arguments:n,typeArguments:r});let s=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:hu("0x0")});if(s.error!=null)return Je("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Ji.METHOD_NAME]:"preSwap",[Ji.REQUEST_PARAMS]:{params:e}});let a=s.events?.filter(c=>fu(c.type).name==="CalculatedSwapResultEvent");return a.length===0?Je("InvalidConfig",`preSwap error code: ${s.error??"unknown error"}, please check config and params`,{[Ji.METHOD_NAME]:"preSwap",[Ji.REQUEST_PARAMS]:{params:e}}):this.transformSwapData(e,a[0].parsedJson.data)}transformSwapData(e,t){let i=t.amount_in&&t.fee_amount?new kr.default(t.amount_in).add(new kr.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 kr.default(i.amount_in).add(new kr.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=u1(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=d1(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=Or.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=pu.sqrtPriceX64ToPrice(i.current_sqrt_price,e.decimals_a,e.decimals_b).toNumber(),g=pu.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}=ao(e);if(e.a2b&&r||!e.a2b&&n)return await Or.buildSwapTransactionForGas(this._sdk,e,i,t)}return Or.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}=ao(e);if(e.a2b&&r||!e.a2b&&n)return await Or.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,e,i,t)}return Or.buildSwapTransactionWithoutTransferCoins(this.sdk,e,i)}},K1=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 Je("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ar.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=Rr.parseClmmVestInfo(n),a=`${s.id}-ClmmVestInfo`;this._sdk.updateCache(a,s),t.push(s)}),t}catch(i){Ri("ClmmVestFetchError",i,{[ar.METHOD_NAME]:"getClmmVestInfoList"})}return[]}async getClmmVestInfo(e=!0){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return Je("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ar.METHOD_NAME]:"getClmmVestInfo"});let{clmm_vest_id:i}=Ts(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=Rr.parseClmmVestInfo(s);return this._sdk.updateCache(r,a),a}catch(s){return Ri("ClmmVestFetchError",s,{[ar.METHOD_NAME]:"getClmmVestInfo",[ar.REQUEST_PARAMS]:{clmm_vest_id:i}})}}async getPositionVesting(e){let{clmm_vest:t}=this._sdk.sdkOptions;if(t===void 0)return Je("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ar.METHOD_NAME]:"getPositionVesting"});if(e.length===0)return[];let{clmm_vest_id:i}=Ts(t),r=new mu;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:Z1("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=>Rr.parsePositionVesting(p)))}}),s}buildRedeemPayload(e,t){let{clmm_vest:i}=this._sdk.sdkOptions;if(i===void 0)return Je("ClmmVestNotSet","clmm_vest is not set config in sdk options",{[ar.METHOD_NAME]:"buildRedeemVestPayload"});let{versioned_id:r,clmm_vest_id:n,cetus_coin_type:s}=Ts(i);return t=t||new mu,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(G1)],typeArguments:[g,v]}),k=V1.fromBalance(A,s,t);t.transferObjects([k],this._sdk.getSenderAddress())}),t}},gu={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"}},z1={env:"mainnet",full_rpc_url:W1,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0xba7e740c3c002673dbe69ad5fbdb0691ec260170e141297cefb982e7081fde52",version:2,config:gu.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0x75b2e9ecad34944b8d0c874e568c90db0cf9437f0d7392abfd4cb902972f3e40",version:12,config:gu.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"}}},J1={env:"testnet",full_rpc_url:X1,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"}}},Zu=class ro extends Ap{constructor(t){super(t),this._swap=new H1(this),this._pool=new O1(this),this._position=new D1(this),this._config=new zp(this),this._rewarder=new j1(this),this._vest=new K1(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"?ro.createCustomSDK({...z1,...t}):ro.createCustomSDK({...J1,...t})}static createCustomSDK(t){return new ro(t)}},fo=Li(Fi()),uv=new fo.default(365),cv=new fo.default(24),dv=new fo.default(3600),hv=new fo.default(.5);import{SuiPriceServiceConnection as tg}from"@pythnetwork/pyth-sui-js";var po=class e extends Y1{constructor(t,i){super(t),this._suilendModule=new un(this),this._leverageModules=new vn(this),this._aggregatorClient=new rn.AggregatorClient({signer:Q1("0x0"),client:t.sui_client||new eg({url:t.full_rpc_url}),env:t.env==="testnet"?rn.Env.Testnet:rn.Env.Mainnet,pythUrls:t.pyth_urls}),this._clmmSDK=i||Zu.createSDK({env:t.env,full_rpc_url:t.full_rpc_url}),this._pythConnection=new tg("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({...Vs,...t})}static createCustomSDK(t){return new e(t)}};var Lv=po;export{po as CetusLeverageSDK,Lv as default,Vs as leverage_mainnet};
|
|
1
|
+
var vr=Object.create;var Ri=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var Mr=Object.getOwnPropertyNames;var yr=Object.getPrototypeOf,br=Object.prototype.hasOwnProperty;var _r=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(r,n)=>(typeof require<"u"?require:r)[n]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var kr=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports);var Ar=(i,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of Mr(r))!br.call(i,t)&&t!==n&&Ri(i,t,{get:()=>r[t],enumerable:!(s=wr(r,t))||s.enumerable});return i};var Sr=(i,r,n)=>(n=i!=null?vr(yr(i)):{},Ar(r||!i||!i.__esModule?Ri(n,"default",{value:i,enumerable:!0}):n,i));var fr=kr((lr,di)=>{"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=_r("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 D=1;for(a=M(e,y,e.length,o),y=0;y<k;y++)D*=o;this.imuln(D),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 D=this.clone();for(D.negative=0;!D.isZero();){var N=D.modrn(y).toString(e);D=D.idivn(y),D.isZero()?l=N+l:l=x[a-N.length]+N+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 E=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=E(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 T(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 U(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,D=p&67108863,N=Math.min(a,e.length-1),R=Math.max(0,a-c.length+1);R<=N;R++){var q=a-R|0;u=c.words[q]|0,h=e.words[R]|0,g=u*h+D,y+=g/67108864|0,D=g&67108863}o.words[a]=D|0,p=y|0}return p!==0?o.words[a]=p|0:o.length--,o._strip()}var Z=function(e,o,l){var u=e.words,h=o.words,g=l.words,k=0,p,a,y,D=u[0]|0,N=D&8191,R=D>>>13,q=u[1]|0,V=q&8191,J=q>>>13,He=u[2]|0,Q=He&8191,te=He>>>13,ze=u[3]|0,Y=ze&8191,H=ze>>>13,vi=u[4]|0,oe=vi&8191,se=vi>>>13,wi=u[5]|0,ae=wi&8191,le=wi>>>13,Mi=u[6]|0,fe=Mi&8191,ue=Mi>>>13,yi=u[7]|0,he=yi&8191,ce=yi>>>13,bi=u[8]|0,de=bi&8191,pe=bi>>>13,_i=u[9]|0,ge=_i&8191,me=_i>>>13,ki=h[0]|0,ve=ki&8191,we=ki>>>13,Ai=h[1]|0,Me=Ai&8191,ye=Ai>>>13,Si=h[2]|0,be=Si&8191,_e=Si>>>13,Ci=h[3]|0,ke=Ci&8191,Ae=Ci>>>13,Pi=h[4]|0,Se=Pi&8191,Ce=Pi>>>13,xi=h[5]|0,Pe=xi&8191,xe=xi>>>13,Li=h[6]|0,Le=Li&8191,Ie=Li>>>13,Ii=h[7]|0,Oe=Ii&8191,Ne=Ii>>>13,Oi=h[8]|0,Re=Oi&8191,Te=Oi>>>13,Ni=h[9]|0,De=Ni&8191,Ee=Ni>>>13;l.negative=e.negative^o.negative,l.length=19,p=Math.imul(N,ve),a=Math.imul(N,we),a=a+Math.imul(R,ve)|0,y=Math.imul(R,we);var Et=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Et>>>26)|0,Et&=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(N,Me)|0,a=a+Math.imul(N,ye)|0,a=a+Math.imul(R,Me)|0,y=y+Math.imul(R,ye)|0;var Bt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Bt>>>26)|0,Bt&=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(N,be)|0,a=a+Math.imul(N,_e)|0,a=a+Math.imul(R,be)|0,y=y+Math.imul(R,_e)|0;var Ft=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ft>>>26)|0,Ft&=67108863,p=Math.imul(Y,ve),a=Math.imul(Y,we),a=a+Math.imul(H,ve)|0,y=Math.imul(H,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(N,ke)|0,a=a+Math.imul(N,Ae)|0,a=a+Math.imul(R,ke)|0,y=y+Math.imul(R,Ae)|0;var qt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(qt>>>26)|0,qt&=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(H,Me)|0,y=y+Math.imul(H,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(N,Se)|0,a=a+Math.imul(N,Ce)|0,a=a+Math.imul(R,Se)|0,y=y+Math.imul(R,Ce)|0;var Ut=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ut>>>26)|0,Ut&=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(H,be)|0,y=y+Math.imul(H,_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(N,Pe)|0,a=a+Math.imul(N,xe)|0,a=a+Math.imul(R,Pe)|0,y=y+Math.imul(R,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(H,ke)|0,y=y+Math.imul(H,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(N,Le)|0,a=a+Math.imul(N,Ie)|0,a=a+Math.imul(R,Le)|0,y=y+Math.imul(R,Ie)|0;var jt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(jt>>>26)|0,jt&=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(H,Se)|0,y=y+Math.imul(H,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(N,Oe)|0,a=a+Math.imul(N,Ne)|0,a=a+Math.imul(R,Oe)|0,y=y+Math.imul(R,Ne)|0;var zt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(zt>>>26)|0,zt&=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(H,Pe)|0,y=y+Math.imul(H,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(N,Re)|0,a=a+Math.imul(N,Te)|0,a=a+Math.imul(R,Re)|0,y=y+Math.imul(R,Te)|0;var $t=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+($t>>>26)|0,$t&=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(H,Le)|0,y=y+Math.imul(H,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(N,De)|0,a=a+Math.imul(N,Ee)|0,a=a+Math.imul(R,De)|0,y=y+Math.imul(R,Ee)|0;var Kt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Kt>>>26)|0,Kt&=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(H,Oe)|0,y=y+Math.imul(H,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 Ht=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ht>>>26)|0,Ht&=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(H,Re)|0,y=y+Math.imul(H,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 Wt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Wt>>>26)|0,Wt&=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(H,De)|0,y=y+Math.imul(H,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,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 Vt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Vt>>>26)|0,Vt&=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 Xt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Xt>>>26)|0,Xt&=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 Qt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Qt>>>26)|0,Qt&=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 Yt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Yt>>>26)|0,Yt&=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 Jt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,p=Math.imul(ge,De),a=Math.imul(ge,Ee),a=a+Math.imul(me,De)|0,y=Math.imul(me,Ee);var ei=(k+p|0)+((a&8191)<<13)|0;return k=(y+(a>>>13)|0)+(ei>>>26)|0,ei&=67108863,g[0]=Et,g[1]=Bt,g[2]=Ft,g[3]=qt,g[4]=Ut,g[5]=Zt,g[6]=jt,g[7]=zt,g[8]=$t,g[9]=Kt,g[10]=Ht,g[11]=Wt,g[12]=Gt,g[13]=Vt,g[14]=Xt,g[15]=Qt,g[16]=Yt,g[17]=Jt,g[18]=ei,k!==0&&(g[19]=k,l.length++),l};Math.imul||(Z=U);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,D=c.words[y]|0,N=e.words[a]|0,R=D*N,q=R&67108863;g=g+(R/67108864|0)|0,q=q+k|0,k=q&67108863,g=g+(q>>>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 B(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=Z(this,e,o):u<63?l=U(this,e,o):u<1024?l=I(this,e,o):l=B(this,e,o),l};function F(c,e){this.x=c,this.y=e}F.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},F.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},F.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]]},F.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),D=0;D<h;D+=p)for(var N=a,R=y,q=0;q<k;q++){var V=l[D+q],J=u[D+q],He=l[D+q+k],Q=u[D+q+k],te=N*He-R*Q;Q=N*Q+R*He,He=te,l[D+q]=V+He,u[D+q]=J+Q,l[D+q+k]=V-He,u[D+q+k]=J-Q,q!==p&&(te=a*N-y*R,R=a*R+y*N,N=te)}},F.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},F.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}},F.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},F.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)},F.prototype.stub=function(e){for(var o=new Array(e),l=0;l<e;l++)o[l]=0;return o},F.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),D=new Array(u),N=new Array(u),R=l.words;R.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,D,N,u,h);for(var q=0;q<u;q++){var V=p[q]*D[q]-a[q]*N[q];a[q]=p[q]*N[q]+a[q]*D[q],p[q]=V}return this.conjugate(p,a,u),this.transform(p,a,R,g,u,h),this.conjugate(R,g,u),this.normalize13b(R,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),B(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=T(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 D=this.words[a]|0;this.words[a]=y<<26-h|D>>>h,y=D&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 D=u.clone()._ishlnsubmul(h,1,p);D.negative===0&&(u=D,a&&(a.words[p]=1));for(var N=p-1;N>=0;N--){var R=(u.words[h.length+N]|0)*67108864+(u.words[h.length+N-1]|0);for(R=Math.min(R/g|0,67108863),u._ishlnsubmul(h,R,N);u.negative!==0;)R--,u.negative=0,u._ishlnsubmul(h,1,N),u.isZero()||(u.negative^=1);a&&(a.words[N]=R)}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 D=0,N=1;(o.words[0]&N)===0&&D<26;++D,N<<=1);if(D>0)for(o.iushrn(D);D-- >0;)(u.isOdd()||h.isOdd())&&(u.iadd(a),h.isub(y)),u.iushrn(1),h.iushrn(1);for(var R=0,q=1;(l.words[0]&q)===0&&R<26;++R,q<<=1);if(R>0)for(l.iushrn(R);R-- >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 D;return o.cmpn(1)===0?D=u:D=h,D.cmpn(0)<0&&D.iadd(e),D},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 z(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()}z.prototype._tmp=function(){var e=new t(null);return e.words=new Array(Math.ceil(this.n/13)),e},z.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},z.prototype.split=function(e,o){e.iushrn(this.n,0,o)},z.prototype.imulK=function(e){return e.imul(this.k)};function X(){z.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(X,z),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(){z.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(m,z);function b(){z.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(b,z);function _(){z.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(_,z),_.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),D=this.pow(e,u.addn(1).iushrn(1)),N=this.pow(e,u),R=h;N.cmp(g)!==0;){for(var q=N,V=0;q.cmp(g)!==0;V++)q=q.redSqr();n(V<R);var J=this.pow(y,new t(1).iushln(R-V-1));D=D.redMul(J),y=J.redSqr(),N=N.redMul(y),R=V}return D},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],D=a-1;D>=0;D--){var N=y>>D&1;if(g!==u[0]&&(g=this.sqr(g)),N===0&&k===0){p=0;continue}k<<=1,k|=N,p++,!(p!==l&&(h!==0||D!==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 di>"u"||di,lr)});import{SdkWrapper as Kn}from"@cetusprotocol/common-sdk";import{DefaultProviders as Cr,FullRpcUrlMainnet as Pr}from"@cetusprotocol/common-sdk";var Ti={full_rpc_url:Pr,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:Cr,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"}}};import{SuilendClient as Fr}from"@suilend/sdk/client";import{initializeSuilend as qr,initializeSuilendRewards as Ur,initializeObligations as Zr,formatRewards as jr,Side as Ki,getFilteredRewards as zr,getStakingYieldAprPercent as $r,getDedupedPerDayRewards as Kr,getDedupedAprRewards as Hr,getTotalAprPercent as Hi,getNetAprPercent as Wr}from"@suilend/sdk";var xr=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,ti=Math.ceil,Ge=Math.floor,$e="[BigNumber Error] ",Di=$e+"Number primitive has more than 15 significant digits: ",Xe=1e14,W=14,ii=9007199254740991,ri=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],nt=1e7,qe=1e9;function Ei(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,E=0,T={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},U="0123456789abcdefghijklmnopqrstuvwxyz",Z=!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(!xr.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,U.length,"Base"),b==10&&Z)return h=new I(m),z(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(Di+m)}else h.s=u.charCodeAt(0)===45?(u=u.slice(1),-1):1;for(_=U.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>ii||m!==Ge(m)))throw Error(Di+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)%W,c<0&&(e+=W),e<l){for(e&&h.c.push(+u.slice(0,e)),l-=W;e<l;)h.c.push(+u.slice(e,e+=W));e=W-(u=u.slice(e)).length}else e-=l;for(;e--;u+="0");h.c.push(+u)}}else h.c=[h.e=0]}I.clone=Ei,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,qe,b),d=_),m.hasOwnProperty(b="ROUNDING_MODE")&&(_=m[b],ne(_,0,8,b),v=_),m.hasOwnProperty(b="EXPONENTIAL_AT")&&(_=m[b],_&&_.pop?(ne(_[0],-qe,0,b),ne(_[1],0,qe,b),M=_[0],w=_[1]):(ne(_,-qe,qe,b),M=-(w=_<0?-_:_))),m.hasOwnProperty(b="RANGE"))if(_=m[b],_&&_.pop)ne(_[0],-qe,-1,b),ne(_[1],1,qe,b),A=_[0],x=_[1];else if(ne(_,-qe,qe,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,qe,b),E=_),m.hasOwnProperty(b="FORMAT"))if(_=m[b],typeof _=="object")T=_;else throw Error($e+b+" not an object: "+_);if(m.hasOwnProperty(b="ALPHABET"))if(_=m[b],typeof _=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(_))Z=_.slice(0,10)=="0123456789",U=_;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:E,FORMAT:T,ALPHABET:U}},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>=-qe&&S<=qe&&S===Ge(S)){if(P[0]===0){if(S===0&&P.length===1)return!0;break e}if(b=(S+1)%W,b<1&&(b+=W),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 F(arguments,-1)},I.minimum=I.min=function(){return F(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,qe),e=ti(_/W),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],_%=W,e&&_&&(o=ri[W-_],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-=W);for(l=1,o=u[0];o>=10;o/=10,l++);l<W&&(c-=W-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("."),D=d,N=v;for(y>=0&&(h=E,E=0,_=_.replace(".",""),a=new I(P),k=a.pow(_.length-y),E=h,a.c=b(it(We(k.c),k.e,"0"),10,S,m),a.e=a.c.length),p=b(_,P,S,e?(o=U,m):(o=m,U)),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,D,N,S),p=k.c,g=k.r,u=k.e),l=u+D+1,y=p[l],h=S/2,g=g||l<0||p[l+1]!=null,g=N<4?(y!=null||g)&&(N==0||N==(k.s<0?3:2)):y>h||y==h&&(N==4||g||N==6&&p[l-1]&1||N==(k.s<0?8:7)),l<1||!p[0])_=g?it(o.charAt(1),-D,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++]));_=it(_,u,o.charAt(0))}return _}})(),r=(function(){function m(P,S,c){var e,o,l,u,h=0,g=P.length,k=S%nt,p=S/nt|0;for(P=P.slice();g--;)l=P[g]%nt,u=P[g]/nt|0,e=p*l+u*k,o=k*l+e%nt*nt+h,h=(o/c|0)+(e/nt|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,D,N,R,q,V,J,He,Q,te,ze=P.s==S.s?1:-1,Y=P.c,H=S.c;if(!Y||!Y[0]||!H||!H[0])return new I(!P.s||!S.s||(Y?H&&Y[0]==H[0]:!H)?NaN:Y&&Y[0]==0||!H?ze*0:ze/0);for(y=new I(ze),D=y.c=[],u=P.e-S.e,ze=c+u+1,o||(o=Xe,u=Ve(P.e/W)-Ve(S.e/W),ze=ze/W|0),h=0;H[h]==(Y[h]||0);h++);if(H[h]>(Y[h]||0)&&u--,ze<0)D.push(1),g=!0;else{for(J=Y.length,Q=H.length,h=0,ze+=2,k=Ge(o/(H[0]+1)),k>1&&(H=m(H,k,o),Y=m(Y,k,o),Q=H.length,J=Y.length),V=Q,N=Y.slice(0,Q),R=N.length;R<Q;N[R++]=0);te=H.slice(),te=[0].concat(te),He=H[0],H[1]>=o/2&&He++;do{if(k=0,l=b(H,N,Q,R),l<0){if(q=N[0],Q!=R&&(q=q*o+(N[1]||0)),k=Ge(q/He),k>1)for(k>=o&&(k=o-1),p=m(H,k,o),a=p.length,R=N.length;b(p,N,a,R)==1;)k--,_(p,Q<a?te:H,a,o),a=p.length,l=1;else k==0&&(l=k=1),p=H.slice(),a=p.length;if(a<R&&(p=[0].concat(p)),_(N,p,R,o),R=N.length,l==-1)for(;b(H,N,Q,R)<1;)k++,_(N,Q<R?te:H,R,o),R=N.length}else l===0&&(k++,N=[0]);D[h++]=k,N[0]?N[R++]=Y[V]||0:(N=[Y[V]],R=1)}while((V++<J||N[0]!=null)&&ze--);g=N[0]!=null,D[0]||D.splice(0,1)}if(o==Xe){for(h=1,ze=D[0];ze>=10;ze/=10,h++);z(y,c+(y.e=h+u*W-1)+1,e,g)}else y.e=u,y.r=+g;return y}})();function B(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)?bt(l,e):it(l,e,"0");else if(m=z(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=bt(l,c)}else if(b-=e+(P===2&&c>e),l=it(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 F(m,b){for(var _,P,S=1,c=new I(m[0]);S<m.length;S++)P=new I(m[S]),(!P.s||(_=ht(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+_*W-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 z(m,b,_,P){var S,c,e,o,l,u,h,g=m.c,k=ri;if(g){e:{for(S=1,o=g[0];o>=10;o/=10,S++);if(c=b-S,c<0)c+=W,e=b,l=g[u=0],h=Ge(l/k[S-e-1]%10);else if(u=ti((c+1)/W),u>=g.length)if(P){for(;g.length<=u;g.push(0));l=h=0,S=1,c%=W,e=c-W+1}else break e;else{for(l=o=g[u],S=1;o>=10;o/=10,S++);c%=W,e=c-W+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[(W-b%W)%W],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[W-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?bt(b,_):it(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 ht(this,new I(m,b))},t.decimalPlaces=t.dp=function(m,b){var _,P,S,c=this;if(m!=null)return ne(m,0,qe),b==null?b=v:ne(b,0,8),z(new I(c),m+c.e+1,b);if(!(_=c.c))return null;if(P=((S=_.length-1)-Ve(this.e/W))*W,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-yt(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&&yt(m)?-0:0,g.e>-1&&(c=1/c),new I(l?1/c:c);E&&(c=ti(E/W+2))}for(o?(_=new I(.5),l&&(m.s=1),u=yt(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(_),z(m,m.e+1,1),m.e>14)u=yt(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?z(h,E,v,e):h)},t.integerValue=function(m){var b=new I(this);return m==null?m=v:ne(m,0,8),z(b,b.e+1,m)},t.isEqualTo=t.eq=function(m,b){return ht(this,new I(m,b))===0},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(m,b){return ht(this,new I(m,b))>0},t.isGreaterThanOrEqualTo=t.gte=function(m,b){return(b=ht(this,new I(m,b)))===1||b===0},t.isInteger=function(){return!!this.c&&Ve(this.e/W)>this.c.length-2},t.isLessThan=t.lt=function(m,b){return ht(this,new I(m,b))<0},t.isLessThanOrEqualTo=t.lte=function(m,b){return(b=ht(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/W,u=m.e/W,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,D,N=this,R=N.c,q=(m=new I(m,b)).c;if(!R||!q||!R[0]||!q[0])return!N.s||!m.s||R&&!R[0]&&!q||q&&!q[0]&&!R?m.c=m.e=m.s=null:(m.s*=N.s,!R||!q?m.c=m.e=null:(m.c=[0],m.e=0)),m;for(P=Ve(N.e/W)+Ve(m.e/W),m.s*=N.s,l=R.length,g=q.length,l<g&&(a=R,R=q,q=a,S=l,l=g,g=S),S=l+g,a=[];S--;a.push(0));for(y=Xe,D=nt,S=g;--S>=0;){for(_=0,k=q[S]%D,p=q[S]/D|0,e=l,c=S+e;c>S;)u=R[--e]%D,h=R[e]/D|0,o=p*u+h*k,u=k*u+o%D*D+a[c]+_,_=(u/y|0)+(o/D|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/W,e=m.e/W,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,qe),b==null?b=v:ne(b,0,8),z(new I(c),m,b);if(!(_=c.c))return null;if(S=_.length-1,P=S*W+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,-ii,ii),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&&(z(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")&&(z(_,_.e+d+2,1),m=!_.times(_).eq(c));break}}return z(_,_.e+d+1,v,m)},t.toExponential=function(m,b){return m!=null&&(ne(m,0,qe),m++),B(this,m,b,1)},t.toFixed=function(m,b){return m!=null&&(ne(m,0,qe),m=m+this.e+1),B(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):_=T;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]=ri[(e=c%W)<0?W+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,qe),B(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?bt(We(_.c),S):it(We(_.c),S,"0"):m===10&&Z?(_=z(new I(_),d+S+1,v),b=it(We(_.c),_.e,"0")):(ne(m,2,U.length,"Base"),b=n(it(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=W-r.length;n--;r="0"+r);f+=r}for(t=f.length;f.charCodeAt(--t)===48;);return f.slice(0,t+1||1)}function ht(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 yt(i){var r=i.c.length-1;return Ve(i.e/W)==r&&i.c[r]%2!=0}function bt(i,r){return(i.length>1?i.charAt(0)+"."+i.slice(1):i)+(r<0?"e":"e+")+r}function it(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 Lr=Ei(),Ye=Lr;import{linearlyInterpolate as Rr,Side as ct}from"@suilend/sdk";import{NORMALIZED_flSUI_COINTYPE as Tr,NORMALIZED_jugSUI_COINTYPE as Dr,NORMALIZED_LBTC_COINTYPE as Er}from"@suilend/sui-fe";import Ir from"crypto";var kt=new Uint8Array(256),_t=kt.length;function ni(){return _t>kt.length-16&&(Ir.randomFillSync(kt),_t=0),kt.slice(_t,_t+=16)}var Ue=[];for(let i=0;i<256;++i)Ue.push((i+256).toString(16).slice(1));function Bi(i,r=0){return Ue[i[r+0]]+Ue[i[r+1]]+Ue[i[r+2]]+Ue[i[r+3]]+"-"+Ue[i[r+4]]+Ue[i[r+5]]+"-"+Ue[i[r+6]]+Ue[i[r+7]]+"-"+Ue[i[r+8]]+Ue[i[r+9]]+"-"+Ue[i[r+10]]+Ue[i[r+11]]+Ue[i[r+12]]+Ue[i[r+13]]+Ue[i[r+14]]+Ue[i[r+15]]}import Or from"crypto";var oi={randomUUID:Or.randomUUID};function Nr(i,r,n){if(oi.randomUUID&&!r&&!i)return oi.randomUUID();i=i||{};let s=i.random||(i.rng||ni)();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 Bi(s)}var At=Nr;import{getPackagerConfigs as Br}from"@cetusprotocol/common-sdk";var si=10n;function Fi(i){return i.depositedAmount.eq(0)?new Ye(0):i.borrowedAmount.div(i.depositedAmount).times(100)}function ai(i){let r=Fi(i);if(!r.gt(100))return Rr(i.config.interestRate,"utilPercent","aprPercent",r)}function qi(i){let r=Fi(i),n=ai(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 Ui(i,r,n,s){let{apiUrl:t}=Br(s.sdkOptions.suilend);i===ct.DEPOSIT&&([Tr,Dr].includes(r.coinType)&&n.push({stats:{id:At(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${t}/partners/LiqAg.png`,perDay:new Ye(.036),side:ct.DEPOSIT},obligationClaims:{}}),r.coinType===Er&&n.push({stats:{id:At(),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:ct.DEPOSIT},obligationClaims:{}}))}function Zi(i,r,n){return{...i,depositedAmount:r===ct.DEPOSIT?Ye.max(i.depositedAmount.plus(n),0):i.depositedAmount,borrowedAmount:r===ct.BORROW?Ye.max(i.borrowedAmount.plus(n),0):i.borrowedAmount}}function ji(i,r,n){let s=i===ct.DEPOSIT?r.depositedAmount:r.borrowedAmount,t=i===ct.DEPOSIT?n.depositedAmount:n.borrowedAmount,f=t.eq(0)?new Ye(-1):s.div(t);return{multiplier:f,isValid:!f.eq(-1)}}function zi(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 $i(i,r){if(!si)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(r<0n){let n=10n**(si- -r);return i*n}return i/10n**(r+si)}import{d as mt,getPackagerConfigs as dt,removeHexPrefix as Wi}from"@cetusprotocol/common-sdk";import{toHEX as Gr}from"@mysten/sui/utils";var St=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=zr(w);Ui(M,d,A,this.sdk);let x=$r(M,d.coinType,t),C=M===Ki.DEPOSIT?d.depositAprPercent:d.borrowAprPercent,L=C,E=Zi(d,M,n);L=M===Ki.DEPOSIT?qi(E):ai(E);let{multiplier:T,isValid:U}=ji(M,d,E),Z=Kr(A),I=Hr(A),{newPerDayRewards:B,newAprRewards:F}=zi(Z,I,T,U),ee=Hi(M,C,A,x),z=L===void 0||F.some(X=>X.stats.aprPercent===void 0)?void 0:Hi(M,L,F,x);return{borrowLimit:d.config.borrowLimit.toString(),borrowedAmount:d.borrowedAmount.toString(),remainingBorrowLimit:mt(d.config.borrowLimit.toString()).sub(mt(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}=dt(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(n,s)).createObligation(r)};this.refreshReservePrices=async(r,n,s)=>{let{lendingMarketId:t,lendingMarketType:f}=dt(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}=dt(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=>Gr(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,E=mt(C).mul(mt(10).pow(mt(L))).toString(),T={coin_type:x.coinType.name,price:E,oracle_price:0n,last_update_time:A.publishTime};T.oracle_price=$i(BigInt(C),BigInt(L)),v[x.coinType.name]=T,this.sdk.updateCache(`getLatestPrice_${T.coin_type}`,T)}}),v};this.getSuiLendReserveInfo=async(r,n)=>{let{lendingMarketId:s}=dt(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==Wi(r)||M.coinType.name==Wi(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 Fr.initialize(r,n,this.sdk.FullClient,!0)),this.suilendClientCache[s]}async getLendingMarketData(r=!1){if(!r&&this.lendingMarketCache)return this.lendingMarketCache;let n=dt(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:E,activeRewardCoinTypes:T,rewardCoinMetadataMap:U}=await qr(this.sdk.FullClient,v),{rewardPriceMap:Z}=await Ur(x,T);return[d.id,{suilendClient:v,lendingMarket:M,coinMetadataMap:w,refreshedRawReserves:A,reserveMap:x,reserveCoinTypes:C,reserveCoinMetadataMap:L,rewardPriceMap:Z,rewardCoinTypes:E,activeRewardCoinTypes:T,rewardCoinMetadataMap:U}]}))))(),(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 Zr(this.sdk.FullClient,t.suilendClient,t.refreshedRawReserves,t.reserveMap,this.sdk.senderAddress),v=jr(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}=dt(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=Wr(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}};import{getPackagerConfigs as Fe,CACHE_TIME_5MIN as dr,CoinAssist as re,CLOCK_ADDRESS as ft,d as G,removeHexPrefix as pr}from"@cetusprotocol/common-sdk";var pt=9e15,lt=1e9,li="0123456789abcdef",xt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Lt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",fi={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-pt,maxE:pt,crypto:!1},Qi,rt,K=!0,Ot="[DecimalError] ",at=Ot+"Invalid argument: ",Yi=Ot+"Precision limit exceeded",Ji=Ot+"crypto unavailable",er="[object Decimal]",je=Math.floor,Be=Math.pow,Vr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Xr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Qr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,tr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Qe=1e7,$=7,Yr=9007199254740991,Jr=xt.length-1,ui=Lt.length-1,O={toStringTag:er};O.absoluteValue=O.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),j(i)};O.ceil=function(){return j(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(at+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())+$,s.rounding=1,n=en(s,sr(s,n)),s.precision=i,s.rounding=r,j(rt==2||rt==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(K=!1,f=A.s*Be(A.s*A,1/3),!f||Math.abs(f)==1/0?(n=Ze(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),Ze(v.d).slice(0,d)===(n=Ze(s.d)).slice(0,d))if(n=n.slice(d-3,d+1),n=="9999"||!t&&n=="4999"){if(!t&&(j(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")&&(j(s,i+1,1),r=!s.times(s).times(s).eq(A));break}return K=!0,j(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/$))*$,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 j(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 j(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/Rt(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 j(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/Rt(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,j(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()?Je(r,s,t):new r(0):new r(NaN):i.isZero()?Je(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,K=!1,n=n.times(n).minus(1).sqrt().plus(n),K=!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,K=!1,n=n.times(n).plus(1).sqrt().plus(n),K=!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?j(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=Je(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<=ui)return d=Je(A,x+4,C).times(.25),d.s=w.s,d}else{if(!w.s)return new A(NaN);if(x+4<=ui)return d=Je(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/$+2|0),i=n;i;--i)w=w.div(w.times(w).plus(1).sqrt().plus(1));for(K=!1,r=Math.ceil(v/$),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)),K=!0,j(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/$)>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(K=!1,v=x+L,d=st(w,v),s=r?It(A,v+10):st(i,v),M=ie(d,s,v,1),vt(M.d,t=x,C))do if(v+=10,d=st(w,v),s=r?It(A,v+10):st(i,v),M=ie(d,s,v,1),!f){+Ze(M.d).slice(t+1,t+15)+1==1e14&&(M=j(M,x+1,0));break}while(vt(M.d,t+=10,C));return K=!0,j(M,x,C)};O.minus=O.sub=function(i){var r,n,s,t,f,d,v,M,w,A,x,C,L=this,E=L.constructor;if(i=new E(i),!L.d||!i.d)return!L.s||!i.s?i=new E(NaN):L.d?i.s=-i.s:i=new E(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=E.precision,M=E.rounding,!w[0]||!C[0]){if(C[0])i.s=-i.s;else if(w[0])i=new E(L);else return new E(M===3?-0:0);return K?j(i,v,M):i}if(n=je(i.e/$),A=je(L.e/$),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/$),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=Nt(w,n),K?j(i,v,M):i):new E(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]?j(new s(n),s.precision,s.rounding):(K=!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),K=!0,n.minus(r))};O.naturalExponential=O.exp=function(){return hi(this)};O.naturalLogarithm=O.ln=function(){return st(this)};O.negated=O.neg=function(){var i=new this.constructor(this);return i.s=-i.s,j(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)),K?j(i,v,M):i;if(f=je(x.e/$),s=je(i.e/$),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/$),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=Nt(w,s),K?j(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(at+i);return n.d?(r=ir(n.d),i&&n.e+1>r&&(r=n.e+1)):r=NaN,r};O.round=function(){var i=this,r=i.constructor;return j(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())+$,s.rounding=1,n=rn(s,sr(s,n)),s.precision=i,s.rounding=r,j(rt>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(K=!1,w=Math.sqrt(+d),w==0||w==1/0?(r=Ze(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),Ze(f.d).slice(0,n)===(r=Ze(s.d)).slice(0,n))if(r=r.slice(n-3,n+1),r=="9999"||!t&&r=="4999"){if(!t&&(j(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")&&(j(s,M+1,1),i=!s.times(s).eq(d));break}return K=!0,j(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,j(rt==2||rt==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/$)+je(i.e/$),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=Nt(f,n),K?j(i,x.precision,x.rounding):i};O.toBinary=function(i,r){return ci(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,lt),r===void 0?r=s.rounding:Ke(r,0,8),j(n,i+n.e+1,r))};O.toExponential=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=et(s,!0):(Ke(i,0,lt),r===void 0?r=t.rounding:Ke(r,0,8),s=j(new t(s),i+1,r),n=et(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=et(t):(Ke(i,0,lt),r===void 0?r=f.rounding:Ke(r,0,8),s=j(new f(t),i+t.e+1,r),n=et(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,E=L.d,T=L.constructor;if(!E)return new T(L);if(w=n=new T(1),s=M=new T(0),r=new T(s),f=r.e=ir(E)-L.e-1,d=f%$,r.d[0]=Be(10,d<0?$+d:d),i==null)i=f>0?r:w;else{if(v=new T(i),!v.isInt()||v.lt(w))throw Error(at+v);i=v.gt(r)?f>0?r:w:v}for(K=!1,v=new T(Ze(E)),A=T.precision,T.precision=f=E.length*$*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],T.precision=A,K=!0,C};O.toHexadecimal=O.toHex=function(i,r){return ci(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]?(K=!1,n=ie(n,i,0,r,1).times(i),K=!0,j(n)):(i.s=n.s,n=i),n};O.toNumber=function(){return+this};O.toOctal=function(i,r){return ci(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 j(v,s,f);if(r=je(i.e/$),r>=i.d.length-1&&(n=w<0?-w:w)<=Yr)return t=rr(M,v,n,s),i.s<0?new M(1).div(t):j(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."+Ze(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):(K=!1,M.rounding=v.s=1,n=Math.min(12,(r+"").length),t=hi(i.times(st(v,s+n)),s),t.d&&(t=j(t,s+5,1),vt(t.d,s,f)&&(r=s+10,t=j(hi(i.times(st(v,r+n)),r),r+5,1),+Ze(t.d).slice(s+1,s+15)+1==1e14&&(t=j(t,s+1,0)))),t.s=d,K=!0,M.rounding=f,j(t,s,f))};O.toPrecision=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=et(s,s.e<=t.toExpNeg||s.e>=t.toExpPos):(Ke(i,1,lt),r===void 0?r=t.rounding:Ke(r,0,8),s=j(new t(s),i,r),n=et(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,lt),r===void 0?r=s.rounding:Ke(r,0,8)),j(new s(n),i,r)};O.toString=function(){var i=this,r=i.constructor,n=et(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()&&!i.isZero()?"-"+n:n};O.truncated=O.trunc=function(){return j(new this.constructor(this),this.e+1,1)};O.valueOf=O.toJSON=function(){var i=this,r=i.constructor,n=et(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()?"-"+n:n};function Ze(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=$-s.length,n&&(f+=ot(n)),f+=s;d=i[r],s=d+"",n=$-s.length,n&&(f+=ot(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(at+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+=$,t=0):(t=Math.ceil((r+1)/$),r%=$),f=Be(10,$-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 Ct(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]+=li.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 en(i,r){var n,s,t;if(r.isZero())return r;s=r.d.length,s<32?(n=Math.ceil(s/3),t=(1/Rt(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,E,T,U,Z,I,B,F,ee,z,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=$,A=je(s.e/L)-je(t.e/L)),P=l.length,b=o.length,Z=new c(e),I=Z.d=[],x=0;l[x]==(o[x]||0);x++);if(l[x]>(o[x]||0)&&A--,f==null?(z=f=c.precision,d=c.rounding):v?z=f+(s.e-t.e)+1:z=f,z<0)I.push(1),E=!0;else{if(z=z/L+2|0,x=0,P==1){for(C=0,l=l[0],z++;(x<b||C)&&z--;x++)X=C*M+(o[x]||0),I[x]=X/l|0,C=X%l|0;E=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,B=o.slice(0,P),F=B.length;F<P;)B[F++]=0;S=l.slice(),S.unshift(0),_=l[0],l[1]>=M/2&&++_;do C=0,w=r(l,B,P,F),w<0?(ee=B[0],P!=F&&(ee=ee*M+(B[1]||0)),C=ee/_|0,C>1?(C>=M&&(C=M-1),T=i(l,C,M),U=T.length,F=B.length,w=r(T,B,U,F),w==1&&(C--,n(T,P<U?S:l,U,M))):(C==0&&(w=C=1),T=l.slice()),U=T.length,U<F&&T.unshift(0),n(B,T,F,M),w==-1&&(F=B.length,w=r(l,B,P,F),w<1&&(C++,n(B,P<F?S:l,F,M))),F=B.length):w===0&&(C++,B=[0]),I[x++]=C,w&&B[0]?B[F++]=o[m]||0:(B=[o[m]],F=1);while((m++<b||B[0]!==void 0)&&z--);E=B[0]!==void 0}I[0]||I.shift()}if(L==1)Z.e=A,Qi=E;else{for(x=1,C=I[0];C>=10;C/=10)x++;Z.e=x+A*L-1,j(Z,v?f+Z.e+1:f,d,E)}return Z}})();function j(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+=$,d=r,A=x[C=0],M=A/Be(10,t-d-1)%10|0;else if(C=Math.ceil((f+1)/$),v=x.length,C>=v)if(s){for(;v++<=C;)x.push(0);A=M=0,t=1,f%=$,d=f-$+1}else break e;else{for(A=v=x[C],t=1;v>=10;v/=10)t++;f%=$,d=f-$+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,($-r%$)%$),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,$-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 K&&(i.e>L.maxE?(i.d=null,i.e=NaN):i.e<L.minE&&(i.e=0,i.d=[0])),i}function et(i,r,n){if(!i.isFinite())return or(i);var s,t=i.e,f=Ze(i.d),d=f.length;return r?(n&&(s=n-d)>0?f=f.charAt(0)+"."+f.slice(1)+ot(s):d>1&&(f=f.charAt(0)+"."+f.slice(1)),f=f+(i.e<0?"e":"e+")+i.e):t<0?(f="0."+ot(-t-1)+f,n&&(s=n-d)>0&&(f+=ot(s))):t>=d?(f+=ot(t+1-d),n&&(s=n-t-1)>0&&(f=f+"."+ot(s))):((s=t+1)<d&&(f=f.slice(0,s)+"."+f.slice(s)),n&&(s=n-d)>0&&(t+1===d&&(f+="."),f+=ot(s))),f}function Nt(i,r){var n=i[0];for(r*=$;n>=10;n/=10)r++;return r}function It(i,r,n){if(r>Jr)throw K=!0,n&&(i.precision=n),Error(Yi);return j(new i(xt),r,1,!0)}function Je(i,r,n){if(r>ui)throw Error(Yi);return j(new i(Lt),r,n,!0)}function ir(i){var r=i.length-1,n=r*$+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 ot(i){for(var r="";i--;)r+="0";return r}function rr(i,r,n,s){var t,f=new i(1),d=Math.ceil(s/$+4);for(K=!1;;){if(n%2&&(f=f.times(r),Vi(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),Vi(r.d,d)}return K=!0,f}function Gi(i){return i.d[i.d.length-1]&1}function nr(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 hi(i,r){var n,s,t,f,d,v,M,w=0,A=0,x=0,C=i.constructor,L=C.rounding,E=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?(K=!1,M=E):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=j(f.times(i),M,1),n=n.times(++A),v=d.plus(ie(f,n,M,1)),Ze(v.d).slice(0,M)===Ze(d.d).slice(0,M)){for(t=x;t--;)d=j(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 j(d,C.precision=E,L,K=!0);else return C.precision=E,d}d=v}}function st(i,r){var n,s,t,f,d,v,M,w,A,x,C,L=1,E=10,T=i,U=T.d,Z=T.constructor,I=Z.rounding,B=Z.precision;if(T.s<0||!U||!U[0]||!T.e&&U[0]==1&&U.length==1)return new Z(U&&!U[0]?-1/0:T.s!=1?NaN:U?0:T);if(r==null?(K=!1,A=B):A=r,Z.precision=A+=E,n=Ze(U),s=n.charAt(0),Math.abs(f=T.e)<15e14){for(;s<7&&s!=1||s==1&&n.charAt(1)>3;)T=T.times(i),n=Ze(T.d),s=n.charAt(0),L++;f=T.e,s>1?(T=new Z("0."+n),f++):T=new Z(s+"."+n.slice(1))}else return w=It(Z,A+2,B).times(f+""),T=st(new Z(s+"."+n.slice(1)),A-E).plus(w),Z.precision=B,r==null?j(T,B,I,K=!0):T;for(x=T,M=d=T=ie(T.minus(1),T.plus(1),A,1),C=j(T.times(T),A,1),t=3;;){if(d=j(d.times(C),A,1),w=M.plus(ie(d,new Z(t),A,1)),Ze(w.d).slice(0,A)===Ze(M.d).slice(0,A))if(M=M.times(2),f!==0&&(M=M.plus(It(Z,A+2,B).times(f+""))),M=ie(M,new Z(L),A,1),r==null)if(vt(M.d,A-E,I,v))Z.precision=A+=E,w=d=T=ie(x.minus(1),x.plus(1),A,1),C=j(T.times(T),A,1),t=v=1;else return j(M,Z.precision=B,I,K=!0);else return Z.precision=B,M;M=w,t+=2}}function or(i){return String(i.s*i.s/0)}function Pt(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)%$,n<0&&(s+=$),s<t){for(s&&i.d.push(+r.slice(0,s)),t-=$;s<t;)i.d.push(+r.slice(s,s+=$));r=r.slice(s),s=$-r.length}else s-=t;for(;s--;)r+="0";i.d.push(+r),K&&(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 tn(i,r){var n,s,t,f,d,v,M,w,A;if(r.indexOf("_")>-1){if(r=r.replace(/(\d)_(?=\d)/g,"$1"),tr.test(r))return Pt(i,r)}else if(r==="Infinity"||r==="NaN")return+r||(i.s=NaN),i.e=NaN,i.d=null,i;if(Xr.test(r))n=16,r=r.toLowerCase();else if(Vr.test(r))n=2;else if(Qr.test(r))n=8;else throw Error(at+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=rr(s,new s(n),f,f*2)),w=Ct(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=Nt(w,A),i.d=w,K=!1,d&&(i=ie(i,t,v*4)),M&&(i=i.times(Math.abs(M)<54?Be(2,M):wt.pow(2,M))),K=!0,i)}function rn(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/Rt(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/$);for(K=!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 K=!0,d.d.length=x+1,d}function Rt(i,r){for(var n=i;--r;)n*=i;return n}function sr(i,r){var n,s=r.s<0,t=Je(i,i.precision,1),f=t.times(.5);if(r=r.abs(),r.lte(f))return rt=s?4:1,r;if(n=r.divToInt(t),n.isZero())rt=s?3:2;else{if(r=r.minus(n.times(t)),r.lte(f))return rt=Gi(n)?s?2:3:s?4:1,r;rt=Gi(n)?s?1:4:s?3:2}return r.minus(t).abs()}function ci(i,r,n,s){var t,f,d,v,M,w,A,x,C,L=i.constructor,E=n!==void 0;if(E?(Ke(n,1,lt),s===void 0?s=L.rounding:Ke(s,0,8)):(n=L.precision,s=L.rounding),!i.isFinite())A=or(i);else{for(A=et(i),d=A.indexOf("."),E?(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=Ct(et(C),10,t),C.e=C.d.length),x=Ct(A,10,t),f=M=x.length;x[--M]==0;)x.pop();if(!x[0])A=E?"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=Qi),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+=li.charAt(x[d]);if(E){if(M>1)if(r==16||r==8){for(d=r==16?4:3,--M;M%d;M++)A+="0";for(x=Ct(A,t,r),M=x.length;!x[M-1];--M);for(d=1,A="1.";d<M;d++)A+=li.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 Vi(i,r){if(i.length>r)return i.length=r,!0}function nn(i){return new this(i).abs()}function on(i){return new this(i).acos()}function sn(i){return new this(i).acosh()}function an(i,r){return new this(i).plus(r)}function ln(i){return new this(i).asin()}function fn(i){return new this(i).asinh()}function un(i){return new this(i).atan()}function hn(i){return new this(i).atanh()}function cn(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=Je(this,f,1).times(r.s>0?.25:.75),n.s=i.s):!r.d||i.isZero()?(n=r.s<0?Je(this,s,t):new this(0),n.s=i.s):!i.d||r.isZero()?(n=Je(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=Je(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 dn(i){return new this(i).cbrt()}function pn(i){return j(i=new this(i),i.e+1,2)}function gn(i,r,n){return new this(i).clamp(r,n)}function mn(i){if(!i||typeof i!="object")throw Error(Ot+"Object expected");var r,n,s,t=i.defaults===!0,f=["precision",1,lt,"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]=fi[n]),(s=i[n])!==void 0)if(je(s)===s&&s>=f[r+1]&&s<=f[r+2])this[n]=s;else throw Error(at+n+": "+s);if(n="crypto",t&&(this[n]=fi[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(Ji);else this[n]=!1;else throw Error(at+n+": "+s);return this}function vn(i){return new this(i).cos()}function wn(i){return new this(i).cosh()}function ar(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,Xi(f)){w.s=f.s,K?!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++;K?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 Pt(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),tr.test(f)?Pt(w,f):tn(w,f);if(M==="bigint")return f<0?(f=-f,w.s=-1):w.s=1,Pt(w,f.toString());throw Error(at+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=mn,t.clone=ar,t.isDecimal=Xi,t.abs=nn,t.acos=on,t.acosh=sn,t.add=an,t.asin=ln,t.asinh=fn,t.atan=un,t.atanh=hn,t.atan2=cn,t.cbrt=dn,t.ceil=pn,t.clamp=gn,t.cos=vn,t.cosh=wn,t.div=Mn,t.exp=yn,t.floor=bn,t.hypot=_n,t.ln=kn,t.log=An,t.log10=Cn,t.log2=Sn,t.max=Pn,t.min=xn,t.mod=Ln,t.mul=In,t.pow=On,t.random=Nn,t.round=Rn,t.sign=Tn,t.sin=Dn,t.sinh=En,t.sqrt=Bn,t.sub=Fn,t.sum=qn,t.tan=Un,t.tanh=Zn,t.trunc=jn,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 Mn(i,r){return new this(i).div(r)}function yn(i){return new this(i).exp()}function bn(i){return j(i=new this(i),i.e+1,3)}function _n(){var i,r,n=new this(0);for(K=!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 K=!0,new this(1/0);n=r}return K=!0,n.sqrt()}function Xi(i){return i instanceof wt||i&&i.toStringTag===er||!1}function kn(i){return new this(i).ln()}function An(i,r){return new this(i).log(r)}function Sn(i){return new this(i).log(2)}function Cn(i){return new this(i).log(10)}function Pn(){return nr(this,arguments,-1)}function xn(){return nr(this,arguments,1)}function Ln(i,r){return new this(i).mod(r)}function In(i,r){return new this(i).mul(r)}function On(i,r){return new this(i).pow(r)}function Nn(i){var r,n,s,t,f=0,d=new this(1),v=[];if(i===void 0?i=this.precision:Ke(i,1,lt),s=Math.ceil(i/$),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(Ji);else for(;f<s;)v[f++]=Math.random()*1e7|0;for(s=v[--f],i%=$,s&&i&&(t=Be(10,$-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-=$)v.shift();for(s=1,t=v[0];t>=10;t/=10)s++;s<$&&(n-=$-s)}return d.e=n,d.d=v,d}function Rn(i){return j(i=new this(i),i.e+1,this.rounding)}function Tn(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function Dn(i){return new this(i).sin()}function En(i){return new this(i).sinh()}function Bn(i){return new this(i).sqrt()}function Fn(i,r){return new this(i).sub(r)}function qn(){var i=0,r=arguments,n=new this(r[i]);for(K=!1;n.s&&++i<r.length;)n=n.plus(r[i]);return K=!0,j(n,this.precision,this.rounding)}function Un(i){return new this(i).tan()}function Zn(i){return new this(i).tanh()}function jn(i){return j(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=ar(fi);xt=new wt(xt);Lt=new wt(Lt);var tt=wt;var mi=Sr(fr());import{Transaction as ut}from"@mysten/sui/transactions";import{addHexPrefix as ur,getObjectFields as hr}from"@cetusprotocol/common-sdk";var cr=i=>{let r=[];return i.forEach(n=>{r.push(pi(n))}),r},pi=i=>{let r=hr(i);return{marketId:r.id.id,baseToken:ur(r.base_token.fields.name),quoteToken:ur(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}},gi=i=>{let r=hr(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}};import{SUI_SYSTEM_STATE_OBJECT_ID as gr,toHEX as Mt}from"@mysten/sui/utils";import{parseObligation as zn}from"@suilend/sdk/parsers/obligation";import{obligation as $n}from"@suilend/sdk/_generated/suilend/lending-market/functions";var Tt=class{constructor(r){this.getLeverageConfig=async()=>{let r=Fe(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=Fe(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=cr(A);return this._sdk.updateCache(n,x,dr),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=pi(t);return this._sdk.updateCache(n,f,dr),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}=Fe(this._sdk.sdkOptions.suilend),t=await this._sdk.SuiLendModule.getSuilendClient(n,s),f=[];for(let d=0;d<r.data.length;d++){let v=gi(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=gi(n.data[0]),{lendingMarketId:t,lendingMarketType:f}=Fe(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{...zn(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}=Fe(this._sdk.sdkOptions.suilend),A=new ut,{openFeeRate:x,baseToken:C,quoteToken:L}=await this.getLeverageMarketInfo(M),{clmmFeeTier:E,clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:U}=await this.getClmmPoolInfo(f);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",E,T,U);let{baseReserveArrayIndex:Z,quoteReserveArrayIndex:I,reserve:B}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(C,L),F=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",F);let ee=t.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",ee);let z,X;if(F){let R=s&&n?L:C,q=s&&n?C:L,V=await this.findRouters(R,q,t,!0,[f]);if(ee=V?.amount_out.toString(),V){let J=re.buildCoinWithBalance(BigInt(t.toString()),R,A);X=await this.routerSwap({router:V.route_obj,slippage:d,inputCoin:J,txb:A}),z=X}}else z=re.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:B});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 _=T===b;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",T),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",_);let P=G(m).mul(E).toString(),{balanceA:S,balanceB:c,receipt:e}=this.flashLoan({amount:G(m),clmmPool:f,clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:U,flashLoanCoin:b,tx:A}),o=s?L:C,l=s?C:L,u=await this.findRouters(o,l,G(m),!0,[f]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:u,debtFrom:o,debtTo:l,clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:U});let h=G(u?.amount_out||0),g;u&&(g=await this.routerSwap({router:u.route_obj,inputCoin:_?re.fromBalance(S,T,A):re.fromBalance(c,U,A),slippage:d,txb:A}));let k=G(h).add(ee).mul(1-x).toDP(0,tt.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 R=0;R<B.length;R++){let q=Mt(new Uint8Array(B[R].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,q,BigInt(B[R].arrayIndex))}let a=s?Z:I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",z),await A.mergeCoins(g,[z]),await this.depositToLeveragePosition({isLong:s,marketId:M,position:p,depositReserveArrayIndex:a,inputCoin:g},A);let y=G(m).add(P).toDP(0,tt.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",y,m,P);let D=await this.borrowAsset({position:p,reserveArrayIndex:s?I:Z,borrowAmount:G(y),baseToken:C,quoteToken:L,isLong:s,lendingMarketId:w},A);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",D);let N=re.mintBalanceZero(_?U:T,A);return this.repayFlashLoan({tx:A,clmmPool:f,repayBase:_?re.intoBalance(D,T,A):N,repayQuote:_?N:re.intoBalance(D,U,A),receipt:e,clmmPoolCoinTypeA:T,clmmPoolCoinTypeB:U}),A.transferObjects([p],A.pure.address(this._sdk.getSenderAddress())),re.destroyBalanceZero(_?c:S,_?U:T,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}=Fe(this._sdk.sdkOptions.suilend),{baseToken:x,quoteToken:C}=await this.getLeverageMarketInfo(n),{isLong:L,deposits:E,borrows:T}=await this.getLeveragePosition(s),{reserve:U}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(x,C),{clmmFeeTier:Z,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B}=await this.getClmmPoolInfo(d),F=w||new ut,ee=E[0].reserveArrayIndex.toString(),z=T[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 D=t&&L?C:x,N=t&&L?x:C,R=await this.findRouters(D,N,f,!0,[d]);if(R){let q=re.buildCoinWithBalance(BigInt(f.toString()),D,F);b=await this.routerSwap({router:R.route_obj,inputCoin:q,slippage:v,txb:F}),m=b}}else m=re.buildCoinWithBalance(BigInt(f.toString()),t?C:x,F);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:U}),S=G(P).mul(Z).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:G(P),clmmPool:d,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B,flashLoanCoin:_,tx:F}),u=L?C:x,h=L?x:C,g=await this.findRouters(u,h,G(P),!0,[d]),k;g&&(k=await this.routerSwap({router:g.route_obj,inputCoin:c?re.fromBalance(e,I,F):re.fromBalance(o,B,F),slippage:v,txb:F})),F.mergeCoins(k,[m]);for(let D=0;D<U.length;D++){let N=Mt(new Uint8Array(U[D].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(F,N,BigInt(U[D].arrayIndex))}this.depositToLeveragePosition({isLong:L,marketId:n,positionId:s,depositReserveArrayIndex:ee,inputCoin:k},F);let p=G(P).add(S).toDP(0,tt.ROUND_UP).toString(),a=this.borrowAsset({positionId:s,reserveArrayIndex:z,borrowAmount:G(p),baseToken:x,quoteToken:C,isLong:L,lendingMarketId:A},F),y=re.mintBalanceZero(c?B:I,F);return this.repayFlashLoan({tx:F,clmmPool:d,repayBase:c?re.intoBalance(a,I,F):y,repayQuote:c?y:re.intoBalance(a,B,F),receipt:l,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B}),re.destroyBalanceZero(c?o:e,c?B:I,F),F};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}=Fe(this._sdk.sdkOptions.suilend),C=d||new ut,{baseToken:L,quoteToken:E}=await this.getLeverageMarketInfo(n),{isLong:T,deposits:U,borrows:Z}=await this.getLeveragePosition(s),{reserve:I}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(L,E),B=f&&T||!f&&!T;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:479 ~ LeverageModules ~ hasSwap:",B);let F=t;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:482 ~ LeverageModules ~ withdrawCtokenAmount:",F);let ee=null;if(B){let k=L,p=E;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}),F=ee?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",F);for(let k=0;k<I.length;k++){let p=Mt(new Uint8Array(I[k].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(C,p,BigInt(I[k].arrayIndex))}let{token:z}=Z[0].reserve,X=G(U[0].depositedCtokenAmount.toString()).div(G(w)).toDP(0,tt.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",X);let m=G(F).div(G(X)).toString(),b=G(Z[0].borrowedAmount.toString()).mul(10**z.decimals).toString(),_=G(b).mul(m).toDP(0,tt.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:F,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:X});let P=await this._sdk.SuiLendModule.getSuilendClient(x,A),S=await this._sdk.PythConnection.getPriceFeedsUpdateData([U[0].reserve.priceIdentifier]),c=await P.pythClient.updatePriceFeeds(C,S,[U[0].reserve.priceIdentifier]),e=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:G(F),withdrawReserveArrayIndex:U[0].reserveArrayIndex.toString(),withdrawCoinType:T?L:E,baseToken:L,quoteToken:E,priceObjectId:c&&c[0]},C),o=T?L:E,l=T?E:L;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let u=await this.findRouters(o,l,G(_),!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:Z[0].reserveArrayIndex.toString(),repayCoin:g,repayCoinType:T?E:L,repayAmount:G(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:E,clmmPoolCoinTypeB:T,clmmFeeTier:U}=await this.getClmmPoolInfo(v),{lendingMarketId:Z}=Fe(this._sdk.sdkOptions.suilend),{token:I}=C[0].reserve,B=new ut,F=G(C[0].borrowedAmount.toString()).mul(G(d).sub(G(f))).mul(10**I.decimals).toDP(0,tt.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",F);let ee=F,z=t?A:w,{balanceA:X,balanceB:m,receipt:b}=this.flashLoan({tx:B,amount:G(ee),clmmPool:v,clmmPoolCoinTypeA:E,clmmPoolCoinTypeB:T,flashLoanCoin:z}),_=t?A:w,P=t?w:A,S=await this.findRouters(_,P,G(F),!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?re.fromBalance(m,T,B):re.fromBalance(X,E,B),slippage:M,txb:B});for(let h=0;h<L.length;h++){let g=Mt(new Uint8Array(L[h].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(B,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},B);let e=G(ee).mul(G(1).add(U)).toDP(0,tt.ROUND_UP).toString(),o=await this.borrowAsset({positionId:s,reserveArrayIndex:C[0].reserveArrayIndex.toString(),borrowAmount:G(e),baseToken:w,quoteToken:A,isLong:t,lendingMarketId:Z},B),l=re.mintBalanceZero(t?w:A,B),u=E===z;return this.repayFlashLoan({tx:B,clmmPool:v,repayBase:t?l:re.intoBalance(o,w,B),repayQuote:t?re.intoBalance(o,A,B):l,receipt:b,clmmPoolCoinTypeA:E,clmmPoolCoinTypeB:T}),re.destroyBalanceZero(u?m:X,u?T:E,B),B};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:E}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(w,A),{lendingMarketId:T,lendingMarketType:U}=Fe(this._sdk.sdkOptions.suilend),Z=new ut,I=G(C[0].depositedCtokenAmount.toString()).mul(G(f).sub(G(d))).toString(),B=G(I).toDP(0,tt.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",B);for(let S=0;S<E.length;S++){let c=Mt(new Uint8Array(E[S].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(Z,c,BigInt(E[S].arrayIndex))}let F=await this._sdk.SuiLendModule.getSuilendClient(T,U),ee=await this._sdk.PythConnection.getPriceFeedsUpdateData([C[0].reserve.priceIdentifier]),z=await F.pythClient.updatePriceFeeds(Z,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:G(B),withdrawReserveArrayIndex:C[0].reserveArrayIndex.toString(),withdrawCoinType:t?w:A,baseToken:w,quoteToken:A,priceObjectId:z&&z[0]},Z),m=t?w:A,b=t?A:w,_=await this.findRouters(m,b,G(B),!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:Z});return this.repay({txb:Z,positionId:s,repayReserveArrayIndex:L[0].reserveArrayIndex.toString(),repayCoin:P,repayCoinType:t?A:w,repayAmount:G(0)}),P&&Z.transferObjects([P],this._sdk.getSenderAddress()),Z};this.leveragePositionClose=async(r,n)=>{let s=n||new ut,{marketId:t,positionId:f}=r,{leverage:d}=this._sdk.sdkOptions,{global_config_id:v}=Fe(this._sdk.sdkOptions.leverage),{lendingMarketType:M,lendingMarketId:w}=Fe(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=$n(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(ft)]}),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}=Fe(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}=Fe(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}=Fe(this._sdk.sdkOptions.suilend);return re.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(gr),n.object(ft)]}):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(ft)]})};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}=Fe(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:E}=r,[T]=n.moveCall({target:"0x1::option::none",typeArguments:[`${d}::lending_market::RateLimiterExemption<${f}, ${x}>`],arguments:[]});return re.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(E),n.object(T),n.pure.u64(w.toString()),n.pure.u64(A),n.object(gr),n.object(ft)]}):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(E),n.object(T),n.pure.u64(w.toString()),n.pure.u64(A),n.object(ft)]})};this.repay=r=>{let{leverage:n}=this._sdk.sdkOptions,{lendingMarketId:s,lendingMarketType:t}=Fe(this._sdk.sdkOptions.suilend),{txb:f,positionId:d,repayAmount:v,repayCoinType:M,repayCoin:w,repayReserveArrayIndex:A}=r,x=f||new ut,C=w||re.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(ft)]})};this.routerSwap=async r=>{let{slippage:n,txb:s,inputCoin:t,router:f}=r,d=s||new ut;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,B=s&&n?w:A;L=(await this.findRouters(I,B,t,!0,[f]))?.amount_out.toString()}let{flashAmount:E}=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:",E);let T=s?A:w,U=s?w:A,Z=await this.findRouters(T,U,G(E),!0,[f]);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:956 ~ LeverageModules ~ debtRouters:",Z),Z};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[pr(f)]?.price,A=M[pr(t)]?.price,x=n?G(A).div(G(w)).toString():G(w).div(G(A)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",d.toString(),n,x,w,A),{flashAmount:G(d).mul(s-1).mul(x).toDP(0,tt.ROUND_UP).toString(),rate:x,quotePrice:w,basePrice:A}}createLeveragePosition(r){let{lendingMarketId:n,lendingMarketType:s}=Fe(this._sdk.sdkOptions.suilend),{global_config_id:t}=Fe(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(ft)],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}=Fe(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(ft)]}),n}async findRouters(r,n,s,t,f){let{providers:d}=this._sdk.sdkOptions;try{let v={from:r,target:n,amount:new mi.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 mi.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}}}};import{AggregatorClient as Hn,Env as mr}from"@cetusprotocol/aggregator-sdk";import{normalizeSuiAddress as Wn}from"@mysten/sui/utils";import{SuiClient as Gn}from"@mysten/sui/client";import{CetusClmmSDK as Vn}from"@cetusprotocol/sui-clmm-sdk";import{SuiPriceServiceConnection as Xn}from"@pythnetwork/pyth-sui-js";var Dt=class i extends Kn{constructor(r,n){super(r),this._suilendModule=new St(this),this._leverageModules=new Tt(this),this._aggregatorClient=new Hn({signer:Wn("0x0"),client:r.sui_client||new Gn({url:r.full_rpc_url}),env:r.env==="testnet"?mr.Testnet:mr.Mainnet,pythUrls:r.pyth_urls}),this._clmmSDK=n||Vn.createSDK({env:r.env,full_rpc_url:r.full_rpc_url}),this._pythConnection=new Xn("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({...Ti,...r})}static createCustomSDK(r){return new i(r)}};var rs=Dt;export{Dt as CetusLeverageSDK,rs as default,Ti as 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
|