lll-sdk 0.0.0-experimental-20250902202808 → 0.0.0-experimental-20250903112628

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.mjs CHANGED
@@ -1,4 +1,4 @@
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 Sr=(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 Cr=(i,r,n)=>(n=i!=null?vr(yr(i)):{},Sr(r||!i||!i.__esModule?Ri(n,"default",{value:i,enumerable:!0}):n,i));var ur=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 u;try{typeof window<"u"&&typeof window.Buffer<"u"?u=window.Buffer:u=_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 f=0;e[0]==="-"&&(f++,this.negative=1),f<e.length&&(o===16?this._parseHex(e,f,l):(this._parseBase(e,o,f),l==="le"&&this._initArray(this.toArray(),o,l)))},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 f=0;f<this.length;f++)this.words[f]=0;var h,g,S=0;if(l==="be")for(f=e.length-1,h=0;f>=0;f-=3)g=e[f]|e[f-1]<<8|e[f-2]<<16,this.words[h]|=g<<S&67108863,this.words[h+1]=g>>>26-S&67108863,S+=24,S>=26&&(S-=26,h++);else if(l==="le")for(f=0,h=0;f<e.length;f+=3)g=e[f]|e[f+1]<<8|e[f+2]<<16,this.words[h]|=g<<S&67108863,this.words[h+1]=g>>>26-S&67108863,S+=24,S>=26&&(S-=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 f=0;f<this.length;f++)this.words[f]=0;var h=0,g=0,S;if(l==="be")for(f=e.length-1;f>=o;f-=2)S=v(e,o,f)<<h,this.words[g]|=S&67108863,h>=18?(h-=18,g+=1,this.words[g]|=S>>>26):h+=8;else{var p=e.length-o;for(f=p%2===0?o+1:o;f<e.length;f+=2)S=v(e,o,f)<<h,this.words[g]|=S&67108863,h>=18?(h-=18,g+=1,this.words[g]|=S>>>26):h+=8}this._strip()};function w(c,e,o,l){for(var f=0,h=0,g=Math.min(c.length,o),S=e;S<g;S++){var p=c.charCodeAt(S)-48;f*=l,p>=49?h=p-49+10:p>=17?h=p-17+10:h=p,n(p>=0&&h<l,"Invalid character"),f+=h}return f}t.prototype._parseBase=function(e,o,l){this.words=[0],this.length=1;for(var f=0,h=1;h<=67108863;h*=o)f++;f--,h=h/o|0;for(var g=e.length-l,S=g%f,p=Math.min(g,g-S)+l,a=0,y=l;y<p;y+=f)a=w(e,y,y+f,o),this.imuln(h),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(S!==0){var D=1;for(a=w(e,y,e.length,o),y=0;y<S;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 M(c,e){c.words=e.words,c.length=e.length,c.negative=e.negative,c.red=e.red}if(t.prototype._move=function(e){M(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")]=_}catch{t.prototype.inspect=_}else t.prototype.inspect=_;function _(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var C=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],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],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 f=0,h=0,g=0;g<this.length;g++){var S=this.words[g],p=((S<<f|h)&16777215).toString(16);h=S>>>24-f&16777215,f+=2,f>=26&&(f-=26,g--),h!==0||g!==this.length-1?l=C[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=A[e],y=L[e];l="";var D=this.clone();for(D.negative=0;!D.isZero();){var R=D.modrn(y).toString(e);D=D.idivn(y),D.isZero()?l=R+l:l=C[a-R.length]+R+l}for(this.isZero()&&(l="0"+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}n(!1,"Base should be between 2 and 36")},t.prototype.toNumber=function(){var e=this.words[0];return this.length===2?e+=this.words[1]*67108864:this.length===3&&this.words[2]===1?e+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-e:e},t.prototype.toJSON=function(){return this.toString(16,2)},u&&(t.prototype.toBuffer=function(e,o){return this.toArrayLike(u,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 f=this.byteLength(),h=l||Math.max(1,f);n(f<=h,"byte array longer than desired length"),n(h>0,"Requested array length <= 0");var g=E(e,h),S=o==="le"?"LE":"BE";return this["_toArrayLike"+S](g,f),g},t.prototype._toArrayLikeLE=function(e,o){for(var l=0,f=0,h=0,g=0;h<this.length;h++){var S=this.words[h]<<g|f;e[l++]=S&255,l<e.length&&(e[l++]=S>>8&255),l<e.length&&(e[l++]=S>>16&255),g===6?(l<e.length&&(e[l++]=S>>24&255),f=0,g=0):(f=S>>>24,g+=2)}if(l<e.length)for(e[l++]=f;l<e.length;)e[l++]=0},t.prototype._toArrayLikeBE=function(e,o){for(var l=e.length-1,f=0,h=0,g=0;h<this.length;h++){var S=this.words[h]<<g|f;e[l--]=S&255,l>=0&&(e[l--]=S>>8&255),l>=0&&(e[l--]=S>>16&255),g===6?(l>=0&&(e[l--]=S>>24&255),f=0,g=0):(f=S>>>24,g+=2)}if(l>=0)for(e[l--]=f;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 N(c){for(var e=new Array(c.bitLength()),o=0;o<e.length;o++){var l=o/26|0,f=o%26;e[o]=c.words[l]>>>f&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 f=0;f<l.length;f++)this.words[f]=o.words[f]^l.words[f];if(this!==o)for(;f<o.length;f++)this.words[f]=o.words[f];return this.length=o.length,this._strip()},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 f=0;f<o;f++)this.words[f]=~this.words[f]&67108863;return l>0&&(this.words[f]=~this.words[f]&67108863>>26-l),this._strip()},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,f=e%26;return this._expand(l+1),o?this.words[l]=this.words[l]|1<<f:this.words[l]=this.words[l]&~(1<<f),this._strip()},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,f;this.length>e.length?(l=this,f=e):(l=e,f=this);for(var h=0,g=0;g<f.length;g++)o=(l.words[g]|0)+(f.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 f,h;l>0?(f=this,h=e):(f=e,h=this);for(var g=0,S=0;S<h.length;S++)o=(f.words[S]|0)-(h.words[S]|0)+g,g=o>>26,this.words[S]=o&67108863;for(;g!==0&&S<f.length;S++)o=(f.words[S]|0)+g,g=o>>26,this.words[S]=o&67108863;if(g===0&&S<f.length&&f!==this)for(;S<f.length;S++)this.words[S]=f.words[S];return this.length=Math.max(this.length,S),f!==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 f=c.words[0]|0,h=e.words[0]|0,g=f*h,S=g&67108863,p=g/67108864|0;o.words[0]=S;for(var a=1;a<l;a++){for(var y=p>>>26,D=p&67108863,R=Math.min(a,e.length-1),T=Math.max(0,a-c.length+1);T<=R;T++){var q=a-T|0;f=c.words[q]|0,h=e.words[T]|0,g=f*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 j=function(e,o,l){var f=e.words,h=o.words,g=l.words,S=0,p,a,y,D=f[0]|0,R=D&8191,T=D>>>13,q=f[1]|0,X=q&8191,ee=q>>>13,He=f[2]|0,Q=He&8191,te=He>>>13,ze=f[3]|0,Y=ze&8191,W=ze>>>13,vi=f[4]|0,oe=vi&8191,se=vi>>>13,wi=f[5]|0,ae=wi&8191,le=wi>>>13,Mi=f[6]|0,ue=Mi&8191,fe=Mi>>>13,yi=f[7]|0,he=yi&8191,ce=yi>>>13,bi=f[8]|0,de=bi&8191,pe=bi>>>13,_i=f[9]|0,ge=_i&8191,me=_i>>>13,ki=h[0]|0,ve=ki&8191,we=ki>>>13,Si=h[1]|0,Me=Si&8191,ye=Si>>>13,Ci=h[2]|0,be=Ci&8191,_e=Ci>>>13,Ai=h[3]|0,ke=Ai&8191,Se=Ai>>>13,Pi=h[4]|0,Ce=Pi&8191,Ae=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(R,ve),a=Math.imul(R,we),a=a+Math.imul(T,ve)|0,y=Math.imul(T,we);var Et=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Et>>>26)|0,Et&=67108863,p=Math.imul(X,ve),a=Math.imul(X,we),a=a+Math.imul(ee,ve)|0,y=Math.imul(ee,we),p=p+Math.imul(R,Me)|0,a=a+Math.imul(R,ye)|0,a=a+Math.imul(T,Me)|0,y=y+Math.imul(T,ye)|0;var Bt=(S+p|0)+((a&8191)<<13)|0;S=(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(X,Me)|0,a=a+Math.imul(X,ye)|0,a=a+Math.imul(ee,Me)|0,y=y+Math.imul(ee,ye)|0,p=p+Math.imul(R,be)|0,a=a+Math.imul(R,_e)|0,a=a+Math.imul(T,be)|0,y=y+Math.imul(T,_e)|0;var Ft=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Ft>>>26)|0,Ft&=67108863,p=Math.imul(Y,ve),a=Math.imul(Y,we),a=a+Math.imul(W,ve)|0,y=Math.imul(W,we),p=p+Math.imul(Q,Me)|0,a=a+Math.imul(Q,ye)|0,a=a+Math.imul(te,Me)|0,y=y+Math.imul(te,ye)|0,p=p+Math.imul(X,be)|0,a=a+Math.imul(X,_e)|0,a=a+Math.imul(ee,be)|0,y=y+Math.imul(ee,_e)|0,p=p+Math.imul(R,ke)|0,a=a+Math.imul(R,Se)|0,a=a+Math.imul(T,ke)|0,y=y+Math.imul(T,Se)|0;var qt=(S+p|0)+((a&8191)<<13)|0;S=(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(W,Me)|0,y=y+Math.imul(W,ye)|0,p=p+Math.imul(Q,be)|0,a=a+Math.imul(Q,_e)|0,a=a+Math.imul(te,be)|0,y=y+Math.imul(te,_e)|0,p=p+Math.imul(X,ke)|0,a=a+Math.imul(X,Se)|0,a=a+Math.imul(ee,ke)|0,y=y+Math.imul(ee,Se)|0,p=p+Math.imul(R,Ce)|0,a=a+Math.imul(R,Ae)|0,a=a+Math.imul(T,Ce)|0,y=y+Math.imul(T,Ae)|0;var Ut=(S+p|0)+((a&8191)<<13)|0;S=(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(W,be)|0,y=y+Math.imul(W,_e)|0,p=p+Math.imul(Q,ke)|0,a=a+Math.imul(Q,Se)|0,a=a+Math.imul(te,ke)|0,y=y+Math.imul(te,Se)|0,p=p+Math.imul(X,Ce)|0,a=a+Math.imul(X,Ae)|0,a=a+Math.imul(ee,Ce)|0,y=y+Math.imul(ee,Ae)|0,p=p+Math.imul(R,Pe)|0,a=a+Math.imul(R,xe)|0,a=a+Math.imul(T,Pe)|0,y=y+Math.imul(T,xe)|0;var jt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(jt>>>26)|0,jt&=67108863,p=Math.imul(ue,ve),a=Math.imul(ue,we),a=a+Math.imul(fe,ve)|0,y=Math.imul(fe,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,Se)|0,a=a+Math.imul(W,ke)|0,y=y+Math.imul(W,Se)|0,p=p+Math.imul(Q,Ce)|0,a=a+Math.imul(Q,Ae)|0,a=a+Math.imul(te,Ce)|0,y=y+Math.imul(te,Ae)|0,p=p+Math.imul(X,Pe)|0,a=a+Math.imul(X,xe)|0,a=a+Math.imul(ee,Pe)|0,y=y+Math.imul(ee,xe)|0,p=p+Math.imul(R,Le)|0,a=a+Math.imul(R,Ie)|0,a=a+Math.imul(T,Le)|0,y=y+Math.imul(T,Ie)|0;var Zt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Zt>>>26)|0,Zt&=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(ue,Me)|0,a=a+Math.imul(ue,ye)|0,a=a+Math.imul(fe,Me)|0,y=y+Math.imul(fe,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,Se)|0,a=a+Math.imul(se,ke)|0,y=y+Math.imul(se,Se)|0,p=p+Math.imul(Y,Ce)|0,a=a+Math.imul(Y,Ae)|0,a=a+Math.imul(W,Ce)|0,y=y+Math.imul(W,Ae)|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(X,Le)|0,a=a+Math.imul(X,Ie)|0,a=a+Math.imul(ee,Le)|0,y=y+Math.imul(ee,Ie)|0,p=p+Math.imul(R,Oe)|0,a=a+Math.imul(R,Ne)|0,a=a+Math.imul(T,Oe)|0,y=y+Math.imul(T,Ne)|0;var zt=(S+p|0)+((a&8191)<<13)|0;S=(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(ue,be)|0,a=a+Math.imul(ue,_e)|0,a=a+Math.imul(fe,be)|0,y=y+Math.imul(fe,_e)|0,p=p+Math.imul(ae,ke)|0,a=a+Math.imul(ae,Se)|0,a=a+Math.imul(le,ke)|0,y=y+Math.imul(le,Se)|0,p=p+Math.imul(oe,Ce)|0,a=a+Math.imul(oe,Ae)|0,a=a+Math.imul(se,Ce)|0,y=y+Math.imul(se,Ae)|0,p=p+Math.imul(Y,Pe)|0,a=a+Math.imul(Y,xe)|0,a=a+Math.imul(W,Pe)|0,y=y+Math.imul(W,xe)|0,p=p+Math.imul(Q,Le)|0,a=a+Math.imul(Q,Ie)|0,a=a+Math.imul(te,Le)|0,y=y+Math.imul(te,Ie)|0,p=p+Math.imul(X,Oe)|0,a=a+Math.imul(X,Ne)|0,a=a+Math.imul(ee,Oe)|0,y=y+Math.imul(ee,Ne)|0,p=p+Math.imul(R,Re)|0,a=a+Math.imul(R,Te)|0,a=a+Math.imul(T,Re)|0,y=y+Math.imul(T,Te)|0;var $t=(S+p|0)+((a&8191)<<13)|0;S=(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(ue,ke)|0,a=a+Math.imul(ue,Se)|0,a=a+Math.imul(fe,ke)|0,y=y+Math.imul(fe,Se)|0,p=p+Math.imul(ae,Ce)|0,a=a+Math.imul(ae,Ae)|0,a=a+Math.imul(le,Ce)|0,y=y+Math.imul(le,Ae)|0,p=p+Math.imul(oe,Pe)|0,a=a+Math.imul(oe,xe)|0,a=a+Math.imul(se,Pe)|0,y=y+Math.imul(se,xe)|0,p=p+Math.imul(Y,Le)|0,a=a+Math.imul(Y,Ie)|0,a=a+Math.imul(W,Le)|0,y=y+Math.imul(W,Ie)|0,p=p+Math.imul(Q,Oe)|0,a=a+Math.imul(Q,Ne)|0,a=a+Math.imul(te,Oe)|0,y=y+Math.imul(te,Ne)|0,p=p+Math.imul(X,Re)|0,a=a+Math.imul(X,Te)|0,a=a+Math.imul(ee,Re)|0,y=y+Math.imul(ee,Te)|0,p=p+Math.imul(R,De)|0,a=a+Math.imul(R,Ee)|0,a=a+Math.imul(T,De)|0,y=y+Math.imul(T,Ee)|0;var Kt=(S+p|0)+((a&8191)<<13)|0;S=(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,Se)|0,a=a+Math.imul(ce,ke)|0,y=y+Math.imul(ce,Se)|0,p=p+Math.imul(ue,Ce)|0,a=a+Math.imul(ue,Ae)|0,a=a+Math.imul(fe,Ce)|0,y=y+Math.imul(fe,Ae)|0,p=p+Math.imul(ae,Pe)|0,a=a+Math.imul(ae,xe)|0,a=a+Math.imul(le,Pe)|0,y=y+Math.imul(le,xe)|0,p=p+Math.imul(oe,Le)|0,a=a+Math.imul(oe,Ie)|0,a=a+Math.imul(se,Le)|0,y=y+Math.imul(se,Ie)|0,p=p+Math.imul(Y,Oe)|0,a=a+Math.imul(Y,Ne)|0,a=a+Math.imul(W,Oe)|0,y=y+Math.imul(W,Ne)|0,p=p+Math.imul(Q,Re)|0,a=a+Math.imul(Q,Te)|0,a=a+Math.imul(te,Re)|0,y=y+Math.imul(te,Te)|0,p=p+Math.imul(X,De)|0,a=a+Math.imul(X,Ee)|0,a=a+Math.imul(ee,De)|0,y=y+Math.imul(ee,Ee)|0;var Ht=(S+p|0)+((a&8191)<<13)|0;S=(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,Se)|0,a=a+Math.imul(pe,ke)|0,y=y+Math.imul(pe,Se)|0,p=p+Math.imul(he,Ce)|0,a=a+Math.imul(he,Ae)|0,a=a+Math.imul(ce,Ce)|0,y=y+Math.imul(ce,Ae)|0,p=p+Math.imul(ue,Pe)|0,a=a+Math.imul(ue,xe)|0,a=a+Math.imul(fe,Pe)|0,y=y+Math.imul(fe,xe)|0,p=p+Math.imul(ae,Le)|0,a=a+Math.imul(ae,Ie)|0,a=a+Math.imul(le,Le)|0,y=y+Math.imul(le,Ie)|0,p=p+Math.imul(oe,Oe)|0,a=a+Math.imul(oe,Ne)|0,a=a+Math.imul(se,Oe)|0,y=y+Math.imul(se,Ne)|0,p=p+Math.imul(Y,Re)|0,a=a+Math.imul(Y,Te)|0,a=a+Math.imul(W,Re)|0,y=y+Math.imul(W,Te)|0,p=p+Math.imul(Q,De)|0,a=a+Math.imul(Q,Ee)|0,a=a+Math.imul(te,De)|0,y=y+Math.imul(te,Ee)|0;var Wt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,p=Math.imul(ge,ke),a=Math.imul(ge,Se),a=a+Math.imul(me,ke)|0,y=Math.imul(me,Se),p=p+Math.imul(de,Ce)|0,a=a+Math.imul(de,Ae)|0,a=a+Math.imul(pe,Ce)|0,y=y+Math.imul(pe,Ae)|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(ue,Le)|0,a=a+Math.imul(ue,Ie)|0,a=a+Math.imul(fe,Le)|0,y=y+Math.imul(fe,Ie)|0,p=p+Math.imul(ae,Oe)|0,a=a+Math.imul(ae,Ne)|0,a=a+Math.imul(le,Oe)|0,y=y+Math.imul(le,Ne)|0,p=p+Math.imul(oe,Re)|0,a=a+Math.imul(oe,Te)|0,a=a+Math.imul(se,Re)|0,y=y+Math.imul(se,Te)|0,p=p+Math.imul(Y,De)|0,a=a+Math.imul(Y,Ee)|0,a=a+Math.imul(W,De)|0,y=y+Math.imul(W,Ee)|0;var Gt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,p=Math.imul(ge,Ce),a=Math.imul(ge,Ae),a=a+Math.imul(me,Ce)|0,y=Math.imul(me,Ae),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(ue,Oe)|0,a=a+Math.imul(ue,Ne)|0,a=a+Math.imul(fe,Oe)|0,y=y+Math.imul(fe,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=(S+p|0)+((a&8191)<<13)|0;S=(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(ue,Re)|0,a=a+Math.imul(ue,Te)|0,a=a+Math.imul(fe,Re)|0,y=y+Math.imul(fe,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=(S+p|0)+((a&8191)<<13)|0;S=(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(ue,De)|0,a=a+Math.imul(ue,Ee)|0,a=a+Math.imul(fe,De)|0,y=y+Math.imul(fe,Ee)|0;var Qt=(S+p|0)+((a&8191)<<13)|0;S=(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=(S+p|0)+((a&8191)<<13)|0;S=(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=(S+p|0)+((a&8191)<<13)|0;S=(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=(S+p|0)+((a&8191)<<13)|0;return S=(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]=jt,g[6]=Zt,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,S!==0&&(g[19]=S,l.length++),l};Math.imul||(j=U);function I(c,e,o){o.negative=e.negative^c.negative,o.length=c.length+e.length;for(var l=0,f=0,h=0;h<o.length-1;h++){var g=f;f=0;for(var S=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,R=e.words[a]|0,T=D*R,q=T&67108863;g=g+(T/67108864|0)|0,q=q+S|0,S=q&67108863,g=g+(q>>>26)|0,f+=g>>>26,g&=67108863}o.words[h]=S,l=g,g=f}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,f=this.length+e.length;return this.length===10&&e.length===10?l=j(this,e,o):f<63?l=U(this,e,o):f<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,f=0;f<e;f++)o[f]=this.revBin(f,l,e);return o},F.prototype.revBin=function(e,o,l){if(e===0||e===l-1)return e;for(var f=0,h=0;h<o;h++)f|=(e&1)<<o-h-1,e>>=1;return f},F.prototype.permute=function(e,o,l,f,h,g){for(var S=0;S<g;S++)f[S]=o[e[S]],h[S]=l[e[S]]},F.prototype.transform=function(e,o,l,f,h,g){this.permute(g,e,o,l,f,h);for(var S=1;S<h;S<<=1)for(var p=S<<1,a=Math.cos(2*Math.PI/p),y=Math.sin(2*Math.PI/p),D=0;D<h;D+=p)for(var R=a,T=y,q=0;q<S;q++){var X=l[D+q],ee=f[D+q],He=l[D+q+S],Q=f[D+q+S],te=R*He-T*Q;Q=R*Q+T*He,He=te,l[D+q]=X+He,f[D+q]=ee+Q,l[D+q+S]=X-He,f[D+q+S]=ee-Q,q!==p&&(te=a*R-y*T,T=a*T+y*R,R=te)}},F.prototype.guessLen13b=function(e,o){var l=Math.max(o,e)|1,f=l&1,h=0;for(l=l/2|0;l;l=l>>>1)h++;return 1<<h+1+f},F.prototype.conjugate=function(e,o,l){if(!(l<=1))for(var f=0;f<l/2;f++){var h=e[f];e[f]=e[l-f-1],e[l-f-1]=h,h=o[f],o[f]=-o[l-f-1],o[l-f-1]=-h}},F.prototype.normalize13b=function(e,o){for(var l=0,f=0;f<o/2;f++){var h=Math.round(e[2*f+1]/o)*8192+Math.round(e[2*f]/o)+l;e[f]=h&67108863,h<67108864?l=0:l=h/67108864|0}return e},F.prototype.convert13b=function(e,o,l,f){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<f;++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 f=2*this.guessLen13b(e.length,o.length),h=this.makeRBT(f),g=this.stub(f),S=new Array(f),p=new Array(f),a=new Array(f),y=new Array(f),D=new Array(f),R=new Array(f),T=l.words;T.length=f,this.convert13b(e.words,e.length,S,f),this.convert13b(o.words,o.length,y,f),this.transform(S,g,p,a,f,h),this.transform(y,g,D,R,f,h);for(var q=0;q<f;q++){var X=p[q]*D[q]-a[q]*R[q];a[q]=p[q]*R[q]+a[q]*D[q],p[q]=X}return this.conjugate(p,a,f),this.transform(p,a,T,g,f,h),this.conjugate(T,g,f),this.normalize13b(T,f),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,f=0;f<this.length;f++){var h=(this.words[f]|0)*e,g=(h&67108863)+(l&67108863);l>>=26,l+=h/67108864|0,l+=g>>>26,this.words[f]=g&67108863}return l!==0&&(this.words[f]=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=N(e);if(o.length===0)return new t(1);for(var l=this,f=0;f<o.length&&o[f]===0;f++,l=l.sqr());if(++f<o.length)for(var h=l.sqr();f<o.length;f++,h=h.sqr())o[f]!==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,f=67108863>>>26-o<<26-o,h;if(o!==0){var g=0;for(h=0;h<this.length;h++){var S=this.words[h]&f,p=(this.words[h]|0)-S<<o;this.words[h]=p|g,g=S>>>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 f;o?f=(o-o%26)/26:f=0;var h=e%26,g=Math.min((e-h)/26,this.length),S=67108863^67108863>>>h<<h,p=l;if(f-=g,f=Math.max(0,f),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>=f);a--){var D=this.words[a]|0;this.words[a]=y<<26-h|D>>>h,y=D&S}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,f=1<<o;if(this.length<=l)return!1;var h=this.words[l];return!!(h&f)},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 f=67108863^67108863>>>o<<o;this.words[this.length-1]&=f}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 f=e.length+l,h;this._expand(f);var g,S=0;for(h=0;h<e.length;h++){g=(this.words[h+l]|0)+S;var p=(e.words[h]|0)*o;g-=p&67108863,S=(g>>26)-(p/67108864|0),this.words[h+l]=g&67108863}for(;h<this.length-l;h++)g=(this.words[h+l]|0)+S,S=g>>26,this.words[h+l]=g&67108863;if(S===0)return this._strip();for(n(S===-1),S=0,h=0;h<this.length;h++)g=-(this.words[h]|0)+S,S=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,f=this.clone(),h=e,g=h.words[h.length-1]|0,S=this._countBits(g);l=26-S,l!==0&&(h=h.ushln(l),f.iushln(l),g=h.words[h.length-1]|0);var p=f.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=f.clone()._ishlnsubmul(h,1,p);D.negative===0&&(f=D,a&&(a.words[p]=1));for(var R=p-1;R>=0;R--){var T=(f.words[h.length+R]|0)*67108864+(f.words[h.length+R-1]|0);for(T=Math.min(T/g|0,67108863),f._ishlnsubmul(h,T,R);f.negative!==0;)T--,f.negative=0,f._ishlnsubmul(h,1,R),f.isZero()||(f.negative^=1);a&&(a.words[R]=T)}return a&&a._strip(),f._strip(),o!=="div"&&l!==0&&f.iushrn(l),{div:a||null,mod:f}},t.prototype.divmod=function(e,o,l){if(n(!e.isZero()),this.isZero())return{div:new t(0),mod:new t(0)};var f,h,g;return this.negative!==0&&e.negative===0?(g=this.neg().divmod(e,o),o!=="mod"&&(f=g.div.neg()),o!=="div"&&(h=g.mod.neg(),l&&h.negative!==0&&h.iadd(e)),{div:f,mod:h}):this.negative===0&&e.negative!==0?(g=this.divmod(e.neg(),o),o!=="mod"&&(f=g.div.neg()),{div:f,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,f=e.ushrn(1),h=e.andln(1),g=l.cmp(f);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,f=0,h=this.length-1;h>=0;h--)f=(l*f+(this.words[h]|0))%e;return o?-f:f},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,f=this.length-1;f>=0;f--){var h=(this.words[f]|0)+l*67108864;this.words[f]=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 f=new t(1),h=new t(0),g=new t(0),S=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,R=1;(o.words[0]&R)===0&&D<26;++D,R<<=1);if(D>0)for(o.iushrn(D);D-- >0;)(f.isOdd()||h.isOdd())&&(f.iadd(a),h.isub(y)),f.iushrn(1),h.iushrn(1);for(var T=0,q=1;(l.words[0]&q)===0&&T<26;++T,q<<=1);if(T>0)for(l.iushrn(T);T-- >0;)(g.isOdd()||S.isOdd())&&(g.iadd(a),S.isub(y)),g.iushrn(1),S.iushrn(1);o.cmp(l)>=0?(o.isub(l),f.isub(g),h.isub(S)):(l.isub(o),g.isub(f),S.isub(h))}return{a:g,b:S,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 f=new t(1),h=new t(0),g=l.clone();o.cmpn(1)>0&&l.cmpn(1)>0;){for(var S=0,p=1;(o.words[0]&p)===0&&S<26;++S,p<<=1);if(S>0)for(o.iushrn(S);S-- >0;)f.isOdd()&&f.iadd(g),f.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),f.isub(h)):(l.isub(o),h.isub(f))}var D;return o.cmpn(1)===0?D=f: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 f=0;o.isEven()&&l.isEven();f++)o.iushrn(1),l.iushrn(1);do{for(;o.isEven();)o.iushrn(1);for(;l.isEven();)l.iushrn(1);var 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(f)},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,f=1<<o;if(this.length<=l)return this._expand(l+1),this.words[l]|=f,this;for(var h=f,g=l;h!==0&&g<this.length;g++){var S=this.words[g]|0;S+=h,h=S>>>26,S&=67108863,this.words[g]=S}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 f=this.words[0]|0;l=f===e?0:f<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 f=this.words[l]|0,h=e.words[l]|0;if(f!==h){f<h?o=-1:f>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 x(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 J={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 f=l<this.n?-1:o.ucmp(this.p);return f===0?(o.words[0]=0,o.length=1):f>0?o.isub(this.p):o.strip!==void 0?o.strip():o._strip(),o},z.prototype.split=function(e,o){e.iushrn(this.n,0,o)},z.prototype.imulK=function(e){return e.imul(this.k)};function V(){z.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(V,z),V.prototype.split=function(e,o){for(var l=4194303,f=Math.min(e.length,9),h=0;h<f;h++)o.words[h]=e.words[h];if(o.length=f,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 S=e.words[h]|0;e.words[h-10]=(S&l)<<4|g>>>22,g=S}g>>>=22,e.words[h-10]=g,g===0&&e.length>10?e.length-=10:e.length-=9},V.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var o=0,l=0;l<e.length;l++){var f=e.words[l]|0;o+=f*977,e.words[l]=o&67108863,o=f*64+(o/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function 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 k(){z.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(k,z),k.prototype.imulK=function(e){for(var o=0,l=0;l<e.length;l++){var f=(e.words[l]|0)*19+o,h=f&67108863;f>>>=26,e.words[l]=h,o=f}return o!==0&&(e.words[e.length++]=o),e},t._prime=function(e){if(J[e])return J[e];var o;if(e==="k256")o=new V;else if(e==="p224")o=new m;else if(e==="p192")o=new b;else if(e==="p25519")o=new k;else throw new Error("Unknown prime "+e);return J[e]=o,o};function x(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}x.prototype._verify1=function(e){n(e.negative===0,"red works only with positives"),n(e.red,"red works only with red numbers")},x.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")},x.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(M(e,e.umod(this.m)._forceRed(this)),e)},x.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},x.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)},x.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},x.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)},x.prototype.isub=function(e,o){this._verify2(e,o);var l=e.isub(o);return l.cmpn(0)<0&&l.iadd(this.m),l},x.prototype.shl=function(e,o){return this._verify1(e),this.imod(e.ushln(o))},x.prototype.imul=function(e,o){return this._verify2(e,o),this.imod(e.imul(o))},x.prototype.mul=function(e,o){return this._verify2(e,o),this.imod(e.mul(o))},x.prototype.isqr=function(e){return this.imul(e,e.clone())},x.prototype.sqr=function(e){return this.mul(e,e)},x.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 f=this.m.subn(1),h=0;!f.isZero()&&f.andln(1)===0;)h++,f.iushrn(1);n(!f.isZero());var g=new t(1).toRed(this),S=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(S)!==0;)a.redIAdd(S);for(var y=this.pow(a,f),D=this.pow(e,f.addn(1).iushrn(1)),R=this.pow(e,f),T=h;R.cmp(g)!==0;){for(var q=R,X=0;q.cmp(g)!==0;X++)q=q.redSqr();n(X<T);var ee=this.pow(y,new t(1).iushln(T-X-1));D=D.redMul(ee),y=ee.redSqr(),R=R.redMul(y),T=X}return D},x.prototype.invm=function(e){var o=e._invmp(this.m);return o.negative!==0?(o.negative=0,this.imod(o).redNeg()):this.imod(o)},x.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,f=new Array(1<<l);f[0]=new t(1).toRed(this),f[1]=e;for(var h=2;h<f.length;h++)f[h]=this.mul(f[h-1],e);var g=f[0],S=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 R=y>>D&1;if(g!==f[0]&&(g=this.sqr(g)),R===0&&S===0){p=0;continue}S<<=1,S|=R,p++,!(p!==l&&(h!==0||D!==0))&&(g=this.mul(g,f[S]),p=0,S=0)}a=26}return g},x.prototype.convertTo=function(e){var o=e.umod(this.m);return o===e?o.clone():o},x.prototype.convertFrom=function(e){var o=e.clone();return o.red=null,o},t.mont=function(e){return new P(e)};function P(c){x.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(P,x),P.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},P.prototype.convertFrom=function(e){var o=this.imod(e.mul(this.rinv));return o.red=null,o},P.prototype.imul=function(e,o){if(e.isZero()||o.isZero())return e.words[0]=0,e.length=1,e;var l=e.imul(o),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).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)},P.prototype.mul=function(e,o){if(e.isZero()||o.isZero())return new t(0)._forceRed(this);var l=e.mul(o),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).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)},P.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 Ar,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:Ar,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 jr,formatRewards as Zr,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,G=14,ii=9007199254740991,ri=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],ot=1e7,qe=1e9;function Ei(i){var r,n,s,t=I.prototype={constructor:I,toString:null,valueOf:null},u=new I(1),d=20,v=4,w=-7,M=21,_=-1e7,C=1e7,A=!1,L=1,E=0,N={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},U="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function I(m,b){var k,x,P,c,e,o,l,f,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>C?h.c=h.e=null:m.e<_?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>C?h.c=h.e=null:(h.e=c,h.c=[m]);return}f=String(m)}else{if(!xr.test(f=String(m)))return s(h,f,o);h.s=f.charCodeAt(0)==45?(f=f.slice(1),-1):1}(c=f.indexOf("."))>-1&&(f=f.replace(".","")),(e=f.search(/e/i))>0?(c<0&&(c=e),c+=+f.slice(e+1),f=f.substring(0,e)):c<0&&(c=f.length)}else{if(ne(b,2,U.length,"Base"),b==10&&j)return h=new I(m),z(h,d+h.e+1,v);if(f=String(m),o=typeof m=="number"){if(m*0!=0)return s(h,f,o,b);if(h.s=1/m<0?(f=f.slice(1),-1):1,I.DEBUG&&f.replace(/^0\.0*|\./,"").length>15)throw Error(Di+m)}else h.s=f.charCodeAt(0)===45?(f=f.slice(1),-1):1;for(k=U.slice(0,b),c=e=0,l=f.length;e<l;e++)if(k.indexOf(x=f.charAt(e))<0){if(x=="."){if(e>c){c=l;continue}}else if(!P&&(f==f.toUpperCase()&&(f=f.toLowerCase())||f==f.toLowerCase()&&(f=f.toUpperCase()))){P=!0,e=-1,c=0;continue}return s(h,String(m),o,b)}o=!1,f=n(f,b,10,h.s),(c=f.indexOf("."))>-1?f=f.replace(".",""):c=f.length}for(e=0;f.charCodeAt(e)===48;e++);for(l=f.length;f.charCodeAt(--l)===48;);if(f=f.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)>C)h.c=h.e=null;else if(c<_)h.c=[h.e=0];else{if(h.e=c,h.c=[],e=(c+1)%G,c<0&&(e+=G),e<l){for(e&&h.c.push(+f.slice(0,e)),l-=G;e<l;)h.c.push(+f.slice(e,e+=G));e=G-(f=f.slice(e)).length}else e-=l;for(;e--;f+="0");h.c.push(+f)}}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,k;if(m!=null)if(typeof m=="object"){if(m.hasOwnProperty(b="DECIMAL_PLACES")&&(k=m[b],ne(k,0,qe,b),d=k),m.hasOwnProperty(b="ROUNDING_MODE")&&(k=m[b],ne(k,0,8,b),v=k),m.hasOwnProperty(b="EXPONENTIAL_AT")&&(k=m[b],k&&k.pop?(ne(k[0],-qe,0,b),ne(k[1],0,qe,b),w=k[0],M=k[1]):(ne(k,-qe,qe,b),w=-(M=k<0?-k:k))),m.hasOwnProperty(b="RANGE"))if(k=m[b],k&&k.pop)ne(k[0],-qe,-1,b),ne(k[1],1,qe,b),_=k[0],C=k[1];else if(ne(k,-qe,qe,b),k)_=-(C=k<0?-k:k);else throw Error($e+b+" cannot be zero: "+k);if(m.hasOwnProperty(b="CRYPTO"))if(k=m[b],k===!!k)if(k)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))A=k;else throw A=!k,Error($e+"crypto unavailable");else A=k;else throw Error($e+b+" not true or false: "+k);if(m.hasOwnProperty(b="MODULO_MODE")&&(k=m[b],ne(k,0,9,b),L=k),m.hasOwnProperty(b="POW_PRECISION")&&(k=m[b],ne(k,0,qe,b),E=k),m.hasOwnProperty(b="FORMAT"))if(k=m[b],typeof k=="object")N=k;else throw Error($e+b+" not an object: "+k);if(m.hasOwnProperty(b="ALPHABET"))if(k=m[b],typeof k=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(k))j=k.slice(0,10)=="0123456789",U=k;else throw Error($e+b+" invalid: "+k)}else throw Error($e+"Object expected: "+m);return{DECIMAL_PLACES:d,ROUNDING_MODE:v,EXPONENTIAL_AT:[w,M],RANGE:[_,C],CRYPTO:A,MODULO_MODE:L,POW_PRECISION:E,FORMAT:N,ALPHABET:U}},I.isBigNumber=function(m){if(!m||m._isBigNumber!==!0)return!1;if(!I.DEBUG)return!0;var b,k,x=m.c,P=m.e,c=m.s;e:if({}.toString.call(x)=="[object Array]"){if((c===1||c===-1)&&P>=-qe&&P<=qe&&P===Ge(P)){if(x[0]===0){if(P===0&&x.length===1)return!0;break e}if(b=(P+1)%G,b<1&&(b+=G),String(x[0]).length==b){for(b=0;b<x.length;b++)if(k=x[b],k<0||k>=Xe||k!==Ge(k))break e;if(k!==0)return!0}}}else if(x===null&&P===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(k){var x,P,c,e,o,l=0,f=[],h=new I(u);if(k==null?k=d:ne(k,0,qe),e=ti(k/G),A)if(crypto.getRandomValues){for(x=crypto.getRandomValues(new Uint32Array(e*=2));l<e;)o=x[l]*131072+(x[l+1]>>>11),o>=9e15?(P=crypto.getRandomValues(new Uint32Array(2)),x[l]=P[0],x[l+1]=P[1]):(f.push(o%1e14),l+=2);l=e/2}else if(crypto.randomBytes){for(x=crypto.randomBytes(e*=7);l<e;)o=(x[l]&31)*281474976710656+x[l+1]*1099511627776+x[l+2]*4294967296+x[l+3]*16777216+(x[l+4]<<16)+(x[l+5]<<8)+x[l+6],o>=9e15?crypto.randomBytes(7).copy(x,l):(f.push(o%1e14),l+=7);l=e/7}else throw A=!1,Error($e+"crypto unavailable");if(!A)for(;l<e;)o=b(),o<9e15&&(f[l++]=o%1e14);for(e=f[--l],k%=G,e&&k&&(o=ri[G-k],f[l]=Ge(e/o)*o);f[l]===0;f.pop(),l--);if(l<0)f=[c=0];else{for(c=-1;f[0]===0;f.splice(0,1),c-=G);for(l=1,o=f[0];o>=10;o/=10,l++);l<G&&(c-=G-l)}return h.e=c,h.c=f,h}})(),I.sum=function(){for(var m=1,b=arguments,k=new I(b[0]);m<b.length;)k=k.plus(b[m++]);return k},n=(function(){var m="0123456789";function b(k,x,P,c){for(var e,o=[0],l,f=0,h=k.length;f<h;){for(l=o.length;l--;o[l]*=x);for(o[0]+=c.indexOf(k.charAt(f++)),e=0;e<o.length;e++)o[e]>P-1&&(o[e+1]==null&&(o[e+1]=0),o[e+1]+=o[e]/P|0,o[e]%=P)}return o.reverse()}return function(k,x,P,c,e){var o,l,f,h,g,S,p,a,y=k.indexOf("."),D=d,R=v;for(y>=0&&(h=E,E=0,k=k.replace(".",""),a=new I(x),S=a.pow(k.length-y),E=h,a.c=b(rt(We(S.c),S.e,"0"),10,P,m),a.e=a.c.length),p=b(k,x,P,e?(o=U,m):(o=m,U)),f=h=p.length;p[--h]==0;p.pop());if(!p[0])return o.charAt(0);if(y<0?--f:(S.c=p,S.e=f,S.s=c,S=r(S,a,D,R,P),p=S.c,g=S.r,f=S.e),l=f+D+1,y=p[l],h=P/2,g=g||l<0||p[l+1]!=null,g=R<4?(y!=null||g)&&(R==0||R==(S.s<0?3:2)):y>h||y==h&&(R==4||g||R==6&&p[l-1]&1||R==(S.s<0?8:7)),l<1||!p[0])k=g?rt(o.charAt(1),-D,o.charAt(0)):o.charAt(0);else{if(p.length=l,g)for(--P;++p[--l]>P;)p[l]=0,l||(++f,p=[1].concat(p));for(h=p.length;!p[--h];);for(y=0,k="";y<=h;k+=o.charAt(p[y++]));k=rt(k,f,o.charAt(0))}return k}})(),r=(function(){function m(x,P,c){var e,o,l,f,h=0,g=x.length,S=P%ot,p=P/ot|0;for(x=x.slice();g--;)l=x[g]%ot,f=x[g]/ot|0,e=p*l+f*S,o=S*l+e%ot*ot+h,h=(o/c|0)+(e/ot|0)+p*f,x[g]=o%c;return h&&(x=[h].concat(x)),x}function b(x,P,c,e){var o,l;if(c!=e)l=c>e?1:-1;else for(o=l=0;o<c;o++)if(x[o]!=P[o]){l=x[o]>P[o]?1:-1;break}return l}function k(x,P,c,e){for(var o=0;c--;)x[c]-=o,o=x[c]<P[c]?1:0,x[c]=o*e+x[c]-P[c];for(;!x[0]&&x.length>1;x.splice(0,1));}return function(x,P,c,e,o){var l,f,h,g,S,p,a,y,D,R,T,q,X,ee,He,Q,te,ze=x.s==P.s?1:-1,Y=x.c,W=P.c;if(!Y||!Y[0]||!W||!W[0])return new I(!x.s||!P.s||(Y?W&&Y[0]==W[0]:!W)?NaN:Y&&Y[0]==0||!W?ze*0:ze/0);for(y=new I(ze),D=y.c=[],f=x.e-P.e,ze=c+f+1,o||(o=Xe,f=Ve(x.e/G)-Ve(P.e/G),ze=ze/G|0),h=0;W[h]==(Y[h]||0);h++);if(W[h]>(Y[h]||0)&&f--,ze<0)D.push(1),g=!0;else{for(ee=Y.length,Q=W.length,h=0,ze+=2,S=Ge(o/(W[0]+1)),S>1&&(W=m(W,S,o),Y=m(Y,S,o),Q=W.length,ee=Y.length),X=Q,R=Y.slice(0,Q),T=R.length;T<Q;R[T++]=0);te=W.slice(),te=[0].concat(te),He=W[0],W[1]>=o/2&&He++;do{if(S=0,l=b(W,R,Q,T),l<0){if(q=R[0],Q!=T&&(q=q*o+(R[1]||0)),S=Ge(q/He),S>1)for(S>=o&&(S=o-1),p=m(W,S,o),a=p.length,T=R.length;b(p,R,a,T)==1;)S--,k(p,Q<a?te:W,a,o),a=p.length,l=1;else S==0&&(l=S=1),p=W.slice(),a=p.length;if(a<T&&(p=[0].concat(p)),k(R,p,T,o),T=R.length,l==-1)for(;b(W,R,Q,T)<1;)S++,k(R,Q<T?te:W,T,o),T=R.length}else l===0&&(S++,R=[0]);D[h++]=S,R[0]?R[T++]=Y[X]||0:(R=[Y[X]],T=1)}while((X++<ee||R[0]!=null)&&ze--);g=R[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+f*G-1)+1,e,g)}else y.e=f,y.r=+g;return y}})();function B(m,b,k,x){var P,c,e,o,l;if(k==null?k=v:ne(k,0,8),!m.c)return m.toString();if(P=m.c[0],e=m.e,b==null)l=We(m.c),l=x==1||x==2&&(e<=w||e>=M)?bt(l,e):rt(l,e,"0");else if(m=z(new I(m),b,k),c=m.e,l=We(m.c),o=l.length,x==1||x==2&&(b<=c||c<=w)){for(;o<b;l+="0",o++);l=bt(l,c)}else if(b-=e+(x===2&&c>e),l=rt(l,c,"0"),c+1>o){if(--b>0)for(l+=".";b--;l+="0");}else if(b+=c-o,b>0)for(c+1==o&&(l+=".");b--;l+="0");return m.s<0&&P?"-"+l:l}function F(m,b){for(var k,x,P=1,c=new I(m[0]);P<m.length;P++)x=new I(m[P]),(!x.s||(k=ht(c,x))===b||k===0&&c.s===b)&&(c=x);return c}function J(m,b,k){for(var x=1,P=b.length;!b[--P];b.pop());for(P=b[0];P>=10;P/=10,x++);return(k=x+k*G-1)>C?m.c=m.e=null:k<_?m.c=[m.e=0]:(m.e=k,m.c=b),m}s=(function(){var m=/^(-?)0([xbo])(?=\w[\w.]*$)/i,b=/^([^.]+)\.$/,k=/^\.([^.]+)$/,x=/^-?(Infinity|NaN)$/,P=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(c,e,o,l){var f,h=o?e:e.replace(P,"");if(x.test(h))c.s=isNaN(h)?null:h<0?-1:1;else{if(!o&&(h=h.replace(m,function(g,S,p){return f=(p=p.toLowerCase())=="x"?16:p=="b"?2:8,!l||l==f?S:g}),l&&(f=l,h=h.replace(b,"$1").replace(k,"0.$1")),e!=h))return new I(h,f);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,k,x){var P,c,e,o,l,f,h,g=m.c,S=ri;if(g){e:{for(P=1,o=g[0];o>=10;o/=10,P++);if(c=b-P,c<0)c+=G,e=b,l=g[f=0],h=Ge(l/S[P-e-1]%10);else if(f=ti((c+1)/G),f>=g.length)if(x){for(;g.length<=f;g.push(0));l=h=0,P=1,c%=G,e=c-G+1}else break e;else{for(l=o=g[f],P=1;o>=10;o/=10,P++);c%=G,e=c-G+P,h=e<0?0:Ge(l/S[P-e-1]%10)}if(x=x||b<0||g[f+1]!=null||(e<0?l:l%S[P-e-1]),x=k<4?(h||x)&&(k==0||k==(m.s<0?3:2)):h>5||h==5&&(k==4||x||k==6&&(c>0?e>0?l/S[P-e]:0:g[f-1])%10&1||k==(m.s<0?8:7)),b<1||!g[0])return g.length=0,x?(b-=m.e+1,g[0]=S[(G-b%G)%G],m.e=-b||0):g[0]=m.e=0,m;if(c==0?(g.length=f,o=1,f--):(g.length=f+1,o=S[G-c],g[f]=e>0?Ge(l/S[P-e]%S[e])*o:0),x)for(;;)if(f==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[f]+=o,g[f]!=Xe)break;g[f--]=0,o=1}for(c=g.length;g[--c]===0;g.pop());}m.e>C?m.c=m.e=null:m.e<_&&(m.c=[m.e=0])}return m}function V(m){var b,k=m.e;return k===null?m.toString():(b=We(m.c),b=k<=w||k>=M?bt(b,k):rt(b,k,"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 k,x,P,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(!(k=c.c))return null;if(x=((P=k.length-1)-Ve(this.e/G))*G,P=k[P])for(;P%10==0;P/=10,x--);return x<0&&(x=0),x},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 k,x,P,c,e,o,l,f,h,g=this;if(m=new I(m),m.c&&!m.isInteger())throw Error($e+"Exponent not an integer: "+V(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(+V(g),o?m.s*(2-yt(m)):+V(m))),b?h.mod(b):h;if(l=m.s<0,b){if(b.c?!b.c[0]:!b.s)return new I(NaN);x=!l&&g.isInteger()&&b.isInteger(),x&&(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/G+2))}for(o?(k=new I(.5),l&&(m.s=1),f=yt(m)):(P=Math.abs(+V(m)),f=P%2),h=new I(u);;){if(f){if(h=h.times(g),!h.c)break;c?h.c.length>c&&(h.c.length=c):x&&(h=h.mod(b))}if(P){if(P=Ge(P/2),P===0)break;f=P%2}else if(m=m.times(k),z(m,m.e+1,1),m.e>14)f=yt(m);else{if(P=+V(m),P===0)break;f=P%2}g=g.times(g),c?g.c&&g.c.length>c&&(g.c.length=c):x&&(g=g.mod(b))}return x?h:(l&&(h=u.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/G)>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 k,x,P,c,e=this,o=e.s;if(m=new I(m,b),b=m.s,!o||!b)return new I(NaN);if(o!=b)return m.s=-b,e.plus(m);var l=e.e/G,f=m.e/G,h=e.c,g=m.c;if(!l||!f){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),f=Ve(f),h=h.slice(),o=l-f){for((c=o<0)?(o=-o,P=h):(f=l,P=g),P.reverse(),b=o;b--;P.push(0));P.reverse()}else for(x=(c=(o=h.length)<(b=g.length))?o:b,o=b=0;b<x;b++)if(h[b]!=g[b]){c=h[b]<g[b];break}if(c&&(P=h,h=g,g=P,m.s=-m.s),b=(x=g.length)-(k=h.length),b>0)for(;b--;h[k++]=0);for(b=Xe-1;x>o;){if(h[--x]<g[x]){for(k=x;k&&!h[--k];h[k]=b);--h[k],h[x]+=Xe}h[x]-=g[x]}for(;h[0]==0;h.splice(0,1),--f);return h[0]?J(m,h,f):(m.s=v==3?-1:1,m.c=[m.e=0],m)},t.modulo=t.mod=function(m,b){var k,x,P=this;return m=new I(m,b),!P.c||!m.s||m.c&&!m.c[0]?new I(NaN):!m.c||P.c&&!P.c[0]?new I(P):(L==9?(x=m.s,m.s=1,k=r(P,m,0,3),m.s=x,k.s*=x):k=r(P,m,0,L),m=P.minus(k.times(m)),!m.c[0]&&L==1&&(m.s=P.s),m)},t.multipliedBy=t.times=function(m,b){var k,x,P,c,e,o,l,f,h,g,S,p,a,y,D,R=this,T=R.c,q=(m=new I(m,b)).c;if(!T||!q||!T[0]||!q[0])return!R.s||!m.s||T&&!T[0]&&!q||q&&!q[0]&&!T?m.c=m.e=m.s=null:(m.s*=R.s,!T||!q?m.c=m.e=null:(m.c=[0],m.e=0)),m;for(x=Ve(R.e/G)+Ve(m.e/G),m.s*=R.s,l=T.length,g=q.length,l<g&&(a=T,T=q,q=a,P=l,l=g,g=P),P=l+g,a=[];P--;a.push(0));for(y=Xe,D=ot,P=g;--P>=0;){for(k=0,S=q[P]%D,p=q[P]/D|0,e=l,c=P+e;c>P;)f=T[--e]%D,h=T[e]/D|0,o=p*f+h*S,f=S*f+o%D*D+a[c]+k,k=(f/y|0)+(o/D|0)+p*h,a[c--]=f%y;a[c]=k}return k?++x:a.splice(0,1),J(m,a,x)},t.negated=function(){var m=new I(this);return m.s=-m.s||null,m},t.plus=function(m,b){var k,x=this,P=x.s;if(m=new I(m,b),b=m.s,!P||!b)return new I(NaN);if(P!=b)return m.s=-b,x.minus(m);var c=x.e/G,e=m.e/G,o=x.c,l=m.c;if(!c||!e){if(!o||!l)return new I(P/0);if(!o[0]||!l[0])return l[0]?m:new I(o[0]?x:P*0)}if(c=Ve(c),e=Ve(e),o=o.slice(),P=c-e){for(P>0?(e=c,k=l):(P=-P,k=o),k.reverse();P--;k.push(0));k.reverse()}for(P=o.length,b=l.length,P-b<0&&(k=l,l=o,o=k,b=P),P=0;b;)P=(o[--b]=o[b]+l[b]+P)/Xe|0,o[b]=Xe===o[b]?0:o[b]%Xe;return P&&(o=[P].concat(o),++e),J(m,o,e)},t.precision=t.sd=function(m,b){var k,x,P,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(!(k=c.c))return null;if(P=k.length-1,x=P*G+1,P=k[P]){for(;P%10==0;P/=10,x--);for(P=k[0];P>=10;P/=10,x++);}return m&&c.e+1>x&&(x=c.e+1),x},t.shiftedBy=function(m){return ne(m,-ii,ii),this.times("1e"+m)},t.squareRoot=t.sqrt=function(){var m,b,k,x,P,c=this,e=c.c,o=c.s,l=c.e,f=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(+V(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),k=new I(b)):k=new I(o+""),k.c[0]){for(l=k.e,o=l+f,o<3&&(o=0);;)if(P=k,k=h.times(P.plus(r(c,P,f,1))),We(P.c).slice(0,o)===(b=We(k.c)).slice(0,o))if(k.e<l&&--o,b=b.slice(o-3,o+1),b=="9999"||!x&&b=="4999"){if(!x&&(z(P,P.e+d+2,0),P.times(P).eq(c))){k=P;break}f+=4,o+=4,x=1}else{(!+b||!+b.slice(1)&&b.charAt(0)=="5")&&(z(k,k.e+d+2,1),m=!k.times(k).eq(c));break}}return z(k,k.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,k){var x,P=this;if(k==null)m!=null&&b&&typeof b=="object"?(k=b,b=null):m&&typeof m=="object"?(k=m,m=b=null):k=N;else if(typeof k!="object")throw Error($e+"Argument not an object: "+k);if(x=P.toFixed(m,b),P.c){var c,e=x.split("."),o=+k.groupSize,l=+k.secondaryGroupSize,f=k.groupSeparator||"",h=e[0],g=e[1],S=P.s<0,p=S?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+=f+p.substr(c,o);l>0&&(h+=f+p.slice(c)),S&&(h="-"+h)}x=g?h+(k.decimalSeparator||"")+((l=+k.fractionGroupSize)?g.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(k.fractionGroupSeparator||"")):g):h}return(k.prefix||"")+x+(k.suffix||"")},t.toFraction=function(m){var b,k,x,P,c,e,o,l,f,h,g,S,p=this,a=p.c;if(m!=null&&(o=new I(m),!o.isInteger()&&(o.c||o.s!==1)||o.lt(u)))throw Error($e+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+V(o));if(!a)return new I(p);for(b=new I(u),f=k=new I(u),x=l=new I(u),S=We(a),c=b.e=S.length-p.e-1,b.c[0]=ri[(e=c%G)<0?G+e:e],m=!m||o.comparedTo(b)>0?c>0?b:f:o,e=C,C=1/0,o=new I(S),l.c[0]=0;h=r(o,b,0,1),P=k.plus(h.times(x)),P.comparedTo(m)!=1;)k=x,x=P,f=l.plus(h.times(P=f)),l=P,b=o.minus(h.times(P=b)),o=P;return P=r(m.minus(k),x,0,1),l=l.plus(P.times(f)),k=k.plus(P.times(x)),l.s=f.s=p.s,c=c*2,g=r(f,x,c,v).minus(p).abs().comparedTo(r(l,k,c,v).minus(p).abs())<1?[f,x]:[l,k],C=e,g},t.toNumber=function(){return+V(this)},t.toPrecision=function(m,b){return m!=null&&ne(m,1,qe),B(this,m,b,2)},t.toString=function(m){var b,k=this,x=k.s,P=k.e;return P===null?x?(b="Infinity",x<0&&(b="-"+b)):b="NaN":(m==null?b=P<=w||P>=M?bt(We(k.c),P):rt(We(k.c),P,"0"):m===10&&j?(k=z(new I(k),d+P+1,v),b=rt(We(k.c),k.e,"0")):(ne(m,2,U.length,"Base"),b=n(rt(We(k.c),P,"0"),10,m,x,!0)),x<0&&k.c[0]&&(b="-"+b)),b},t.valueOf=t.toJSON=function(){return V(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,u=i[0]+"";s<t;){for(r=i[s++]+"",n=G-r.length;n--;r="0"+r);u+=r}for(t=u.length;u.charCodeAt(--t)===48;);return u.slice(0,t+1||1)}function ht(i,r){var n,s,t=i.c,u=r.c,d=i.s,v=r.s,w=i.e,M=r.e;if(!d||!v)return null;if(n=t&&!t[0],s=u&&!u[0],n||s)return n?s?0:-v:d;if(d!=v)return d;if(n=d<0,s=w==M,!t||!u)return s?0:!t^n?1:-1;if(!s)return w>M^n?1:-1;for(v=(w=t.length)<(M=u.length)?w:M,d=0;d<v;d++)if(t[d]!=u[d])return t[d]>u[d]^n?1:-1;return w==M?0:w>M^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/G)==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 rt(i,r,n){var s,t;if(r<0){for(t=n+".";++r;t+=n);i=t+i}else if(s=i.length,++r>s){for(t=n,r-=s;--r;t+=n);i+=t}else r<s&&(i=i.slice(0,r)+"."+i.slice(r));return i}var Lr=Ei(),Je=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 St=Nr;import{getPackagerConfigs as Br}from"@cetusprotocol/common-sdk";var si=10n;function Fi(i){return i.depositedAmount.eq(0)?new Je(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 Je(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:St(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${t}/partners/LiqAg.png`,perDay:new Je(.036),side:ct.DEPOSIT},obligationClaims:{}}),r.coinType===Er&&n.push({stats:{id:St(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${t}/partners/Lombard Lux.png`,perDay:new Je(0),side:ct.DEPOSIT},obligationClaims:{}}))}function ji(i,r,n){return{...i,depositedAmount:r===ct.DEPOSIT?Je.max(i.depositedAmount.plus(n),0):i.depositedAmount,borrowedAmount:r===ct.BORROW?Je.max(i.borrowedAmount.plus(n),0):i.borrowedAmount}}function Zi(i,r,n){let s=i===ct.DEPOSIT?r.depositedAmount:r.borrowedAmount,t=i===ct.DEPOSIT?n.depositedAmount:n.borrowedAmount,u=t.eq(0)?new Je(-1):s.div(t);return{multiplier:u,isValid:!u.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}})),u=r.map(d=>({...d,stats:{...d.stats,aprPercent:s?d.stats.aprPercent.times(n):void 0}}));return{newPerDayRewards:t,newAprRewards:u}}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 Ct=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 u=Object.values(s??{})[0],d=u.lendingMarket.reserves.find(V=>V.coinType===r);if(!d)throw new Error("reserve not found");let v=this.obligationsCache?.[u.lendingMarket.id],w="borrow",M=v.rewardMap[d.token.coinType]?.[w]??[],_=zr(M);Ui(w,d,_,this.sdk);let C=$r(w,d.coinType,t),A=w===Ki.DEPOSIT?d.depositAprPercent:d.borrowAprPercent,L=A,E=ji(d,w,n);L=w===Ki.DEPOSIT?qi(E):ai(E);let{multiplier:N,isValid:U}=Zi(w,d,E),j=Kr(_),I=Hr(_),{newPerDayRewards:B,newAprRewards:F}=zi(j,I,N,U),J=Hi(w,A,_,C),z=L===void 0||F.some(V=>V.stats.aprPercent===void 0)?void 0:Hi(w,L,F,C);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:J.toString(),borrowInterest:A.toString(),stakingYieldAprPercent:C?.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:u}=dt(this.sdk.sdkOptions?.suilend),d=`${t}_${u}`;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 u=Array.from(new Set(r.map(w=>Gr(new Uint8Array(w.priceIdentifier.bytes))))),d=await this.suilendClientCache[t].pythConnection.getLatestPriceFeeds(u),v={};return d?.forEach((w,M)=>{let _=w.getPriceUnchecked(),C=r[M];if(_){let{price:A,expo:L}=_,E=mt(A).mul(mt(10).pow(mt(L))).toString(),N={coin_type:C.coinType.name,price:E,oracle_price:0n,last_update_time:_.publishTime};N.oracle_price=$i(BigInt(A),BigInt(L)),v[C.coinType.name]=N,this.sdk.updateCache(`getLatestPrice_${N.coin_type}`,N)}}),v};this.getSuiLendReserveInfo=async(r,n)=>{let{lendingMarketId:s}=dt(this.sdk.sdkOptions?.suilend),{allLendingMarketData:t}=await this.getLendingMarketData(),u=t[s].reserveMap[r],d=t[s].reserveMap[n],v=t[s].refreshedRawReserves.filter(w=>w.coinType.name==Wi(r)||w.coinType.name==Wi(n));return{baseReserveArrayIndex:u.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:w,coinMetadataMap:M,refreshedRawReserves:_,reserveMap:C,reserveCoinTypes:A,reserveCoinMetadataMap:L,rewardCoinTypes:E,activeRewardCoinTypes:N,rewardCoinMetadataMap:U}=await qr(this.sdk.FullClient,v),{rewardPriceMap:j}=await Ur(C,N);return[d.id,{suilendClient:v,lendingMarket:w,coinMetadataMap:M,refreshedRawReserves:_,reserveMap:C,reserveCoinTypes:A,reserveCoinMetadataMap:L,rewardPriceMap:j,rewardCoinTypes:E,activeRewardCoinTypes:N,rewardCoinMetadataMap:U}]}))))(),(async()=>{try{let u=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.apiUrl}/springsui/apy`),d=await u.json();if(u?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(d).map(([v,w])=>[v,new Je(w)]))}catch(u){return console.error(u),{}}})()]);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:u,obligations:d}=await jr(this.sdk.FullClient,t.suilendClient,t.refreshedRawReserves,t.reserveMap,this.sdk.senderAddress),v=Zr(t.reserveMap,t.rewardCoinMetadataMap,t.rewardPriceMap,d);s[t.lendingMarket.id]={obligationOwnerCaps:u,obligations:d,rewardMap:v}}return this.obligationsCache=s,this.obligationsCache}async getSuiLendUserData(r,n=!1){let{lstAprPercentMap:s}=this.lendingMarketCache??{},t=this.obligationsCache??{},{lendingMarketId:u}=dt(this.sdk.sdkOptions?.suilend),d=t[u];if(!d)throw new Error(`No user data found for lending market: ${u}`);if(r){let v=d.obligations.find(M=>M.id===r);if(!v)throw new Error(`Obligation not found: ${r}`);let w=Wr(v,d.rewardMap,s??{});return{obligation:v,netAprPercent:w,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 Be,CACHE_TIME_5MIN as dr,CoinAssist as ie,CLOCK_ADDRESS as ft,d as K,removeHexPrefix as pr}from"@cetusprotocol/common-sdk";var pt=9e15,ut=1e9,li="0123456789abcdef",xt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Lt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ui={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-pt,maxE:pt,crypto:!1},Qi,nt,H=!0,Ot="[DecimalError] ",lt=Ot+"Invalid argument: ",Yi=Ot+"Precision limit exceeded",Ji=Ot+"crypto unavailable",er="[object Decimal]",Ze=Math.floor,Fe=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,fi=Lt.length-1,O={toStringTag:er};O.absoluteValue=O.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),Z(i)};O.ceil=function(){return Z(new this.constructor(this),this.e+1,2)};O.clampedTo=O.clamp=function(i,r){var n,s=this,t=s.constructor;if(i=new t(i),r=new t(r),!i.s||!r.s)return new t(NaN);if(i.gt(r))throw Error(lt+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,u=this,d=u.d,v=(i=new u.constructor(i)).d,w=u.s,M=i.s;if(!d||!v)return!w||!M?NaN:w!==M?w:d===v?0:!d^w<0?1:-1;if(!d[0]||!v[0])return d[0]?w:v[0]?-M:0;if(w!==M)return w;if(u.e!==i.e)return u.e>i.e^w<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]^w<0?1:-1;return s===t?0:s>t^w<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,Z(nt==2||nt==3?n.neg():n,i,r,!0)):new s(1):new s(NaN)};O.cubeRoot=O.cbrt=function(){var i,r,n,s,t,u,d,v,w,M,_=this,C=_.constructor;if(!_.isFinite()||_.isZero())return new C(_);for(H=!1,u=_.s*Fe(_.s*_,1/3),!u||Math.abs(u)==1/0?(n=je(_.d),i=_.e,(u=(i-n.length+1)%3)&&(n+=u==1||u==-2?"0":"00"),u=Fe(n,1/3),i=Ze((i+1)/3)-(i%3==(i<0?-1:2)),u==1/0?n="5e"+i:(n=u.toExponential(),n=n.slice(0,n.indexOf("e")+1)+i),s=new C(n),s.s=_.s):s=new C(u.toString()),d=(i=C.precision)+3;;)if(v=s,w=v.times(v).times(v),M=w.plus(_),s=re(M.plus(_).times(v),M.plus(w),d+2,1),je(v.d).slice(0,d)===(n=je(s.d)).slice(0,d))if(n=n.slice(d-3,d+1),n=="9999"||!t&&n=="4999"){if(!t&&(Z(v,i+1,0),v.times(v).times(v).eq(_))){s=v;break}d+=4,t=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(Z(s,i+1,1),r=!s.times(s).times(s).eq(_));break}return H=!0,Z(s,i,C.rounding,r)};O.decimalPlaces=O.dp=function(){var i,r=this.d,n=NaN;if(r){if(i=r.length-1,n=(i-Ze(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 re(this,new this.constructor(i))};O.dividedToIntegerBy=O.divToInt=function(i){var r=this,n=r.constructor;return Z(re(r,new n(i),0,1,1),n.precision,n.rounding)};O.equals=O.eq=function(i){return this.cmp(i)===0};O.floor=function(){return Z(new this.constructor(this),this.e+1,3)};O.greaterThan=O.gt=function(i){return this.cmp(i)>0};O.greaterThanOrEqualTo=O.gte=function(i){var r=this.cmp(i);return r==1||r===0};O.hyperbolicCosine=O.cosh=function(){var i,r,n,s,t,u=this,d=u.constructor,v=new d(1);if(!u.isFinite())return new d(u.s?1/0:NaN);if(u.isZero())return v;n=d.precision,s=d.rounding,d.precision=n+Math.max(u.e,u.sd())+4,d.rounding=1,t=u.d.length,t<32?(i=Math.ceil(t/3),r=(1/Rt(4,i)).toString()):(i=16,r="2.3283064365386962890625e-10"),u=gt(d,1,u.times(r),new d(1),!0);for(var w,M=i,_=new d(8);M--;)w=u.times(u),u=v.minus(w.times(_.minus(w.times(_))));return Z(u,d.precision=n,d.rounding=s,!0)};O.hyperbolicSine=O.sinh=function(){var i,r,n,s,t=this,u=t.constructor;if(!t.isFinite()||t.isZero())return new u(t);if(r=u.precision,n=u.rounding,u.precision=r+Math.max(t.e,t.sd())+4,u.rounding=1,s=t.d.length,s<3)t=gt(u,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(u,2,t,t,!0);for(var d,v=new u(5),w=new u(16),M=new u(20);i--;)d=t.times(t),t=t.times(v.plus(d.times(w.times(d).plus(M))))}return u.precision=r,u.rounding=n,Z(t,r,n,!0)};O.hyperbolicTangent=O.tanh=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+7,s.rounding=1,re(n.sinh(),n.cosh(),s.precision=i,s.rounding=r)):new s(n.s)};O.inverseCosine=O.acos=function(){var i=this,r=i.constructor,n=i.abs().cmp(1),s=r.precision,t=r.rounding;return n!==-1?n===0?i.isNeg()?et(r,s,t):new r(0):new r(NaN):i.isZero()?et(r,s+4,t).times(.5):(r.precision=s+6,r.rounding=1,i=new r(1).minus(i).div(i.plus(1)).sqrt().atan(),r.precision=s,r.rounding=t,i.times(2))};O.inverseHyperbolicCosine=O.acosh=function(){var i,r,n=this,s=n.constructor;return n.lte(1)?new s(n.eq(1)?0:NaN):n.isFinite()?(i=s.precision,r=s.rounding,s.precision=i+Math.max(Math.abs(n.e),n.sd())+4,s.rounding=1,H=!1,n=n.times(n).minus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln()):new s(n)};O.inverseHyperbolicSine=O.asinh=function(){var i,r,n=this,s=n.constructor;return!n.isFinite()||n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+2*Math.max(Math.abs(n.e),n.sd())+6,s.rounding=1,H=!1,n=n.times(n).plus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln())};O.inverseHyperbolicTangent=O.atanh=function(){var i,r,n,s,t=this,u=t.constructor;return t.isFinite()?t.e>=0?new u(t.abs().eq(1)?t.s/0:t.isZero()?t:NaN):(i=u.precision,r=u.rounding,s=t.sd(),Math.max(s,i)<2*-t.e-1?Z(new u(t),i,r,!0):(u.precision=n=s-t.e,t=re(t.plus(1),new u(1).minus(t),n+i,1),u.precision=i+4,u.rounding=1,t=t.ln(),u.precision=i,u.rounding=r,t.times(.5))):new u(NaN)};O.inverseSine=O.asin=function(){var i,r,n,s,t=this,u=t.constructor;return t.isZero()?new u(t):(r=t.abs().cmp(1),n=u.precision,s=u.rounding,r!==-1?r===0?(i=et(u,n+4,s).times(.5),i.s=t.s,i):new u(NaN):(u.precision=n+6,u.rounding=1,t=t.div(new u(1).minus(t.times(t)).sqrt().plus(1)).atan(),u.precision=n,u.rounding=s,t.times(2)))};O.inverseTangent=O.atan=function(){var i,r,n,s,t,u,d,v,w,M=this,_=M.constructor,C=_.precision,A=_.rounding;if(M.isFinite()){if(M.isZero())return new _(M);if(M.abs().eq(1)&&C+4<=fi)return d=et(_,C+4,A).times(.25),d.s=M.s,d}else{if(!M.s)return new _(NaN);if(C+4<=fi)return d=et(_,C+4,A).times(.5),d.s=M.s,d}for(_.precision=v=C+10,_.rounding=1,n=Math.min(28,v/$+2|0),i=n;i;--i)M=M.div(M.times(M).plus(1).sqrt().plus(1));for(H=!1,r=Math.ceil(v/$),s=1,w=M.times(M),d=new _(M),t=M;i!==-1;)if(t=t.times(w),u=d.minus(t.div(s+=2)),t=t.times(w),d=u.plus(t.div(s+=2)),d.d[r]!==void 0)for(i=r;d.d[i]===u.d[i]&&i--;);return n&&(d=d.times(2<<n-1)),H=!0,Z(d,_.precision=C,_.rounding=A,!0)};O.isFinite=function(){return!!this.d};O.isInteger=O.isInt=function(){return!!this.d&&Ze(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,u,d,v,w,M=this,_=M.constructor,C=_.precision,A=_.rounding,L=5;if(i==null)i=new _(10),r=!0;else{if(i=new _(i),n=i.d,i.s<0||!n||!n[0]||i.eq(1))return new _(NaN);r=i.eq(10)}if(n=M.d,M.s<0||!n||!n[0]||M.eq(1))return new _(n&&!n[0]?-1/0:M.s!=1?NaN:n?0:1/0);if(r)if(n.length>1)u=!0;else{for(t=n[0];t%10===0;)t/=10;u=t!==1}if(H=!1,v=C+L,d=at(M,v),s=r?It(_,v+10):at(i,v),w=re(d,s,v,1),vt(w.d,t=C,A))do if(v+=10,d=at(M,v),s=r?It(_,v+10):at(i,v),w=re(d,s,v,1),!u){+je(w.d).slice(t+1,t+15)+1==1e14&&(w=Z(w,C+1,0));break}while(vt(w.d,t+=10,A));return H=!0,Z(w,C,A)};O.minus=O.sub=function(i){var r,n,s,t,u,d,v,w,M,_,C,A,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(M=L.d,A=i.d,v=E.precision,w=E.rounding,!M[0]||!A[0]){if(A[0])i.s=-i.s;else if(M[0])i=new E(L);else return new E(w===3?-0:0);return H?Z(i,v,w):i}if(n=Ze(i.e/$),_=Ze(L.e/$),M=M.slice(),u=_-n,u){for(C=u<0,C?(r=M,u=-u,d=A.length):(r=A,n=_,d=M.length),s=Math.max(Math.ceil(v/$),d)+2,u>s&&(u=s,r.length=1),r.reverse(),s=u;s--;)r.push(0);r.reverse()}else{for(s=M.length,d=A.length,C=s<d,C&&(d=s),s=0;s<d;s++)if(M[s]!=A[s]){C=M[s]<A[s];break}u=0}for(C&&(r=M,M=A,A=r,i.s=-i.s),d=M.length,s=A.length-d;s>0;--s)M[d++]=0;for(s=A.length;s>u;){if(M[--s]<A[s]){for(t=s;t&&M[--t]===0;)M[t]=Qe-1;--M[t],M[s]+=Qe}M[s]-=A[s]}for(;M[--d]===0;)M.pop();for(;M[0]===0;M.shift())--n;return M[0]?(i.d=M,i.e=Nt(M,n),H?Z(i,v,w):i):new E(w===3?-0:0)};O.modulo=O.mod=function(i){var r,n=this,s=n.constructor;return i=new s(i),!n.d||!i.s||i.d&&!i.d[0]?new s(NaN):!i.d||n.d&&!n.d[0]?Z(new s(n),s.precision,s.rounding):(H=!1,s.modulo==9?(r=re(n,i.abs(),0,3,1),r.s*=i.s):r=re(n,i,0,s.modulo,1),r=r.times(i),H=!0,n.minus(r))};O.naturalExponential=O.exp=function(){return hi(this)};O.naturalLogarithm=O.ln=function(){return at(this)};O.negated=O.neg=function(){var i=new this.constructor(this);return i.s=-i.s,Z(i)};O.plus=O.add=function(i){var r,n,s,t,u,d,v,w,M,_,C=this,A=C.constructor;if(i=new A(i),!C.d||!i.d)return!C.s||!i.s?i=new A(NaN):C.d||(i=new A(i.d||C.s===i.s?C:NaN)),i;if(C.s!=i.s)return i.s=-i.s,C.minus(i);if(M=C.d,_=i.d,v=A.precision,w=A.rounding,!M[0]||!_[0])return _[0]||(i=new A(C)),H?Z(i,v,w):i;if(u=Ze(C.e/$),s=Ze(i.e/$),M=M.slice(),t=u-s,t){for(t<0?(n=M,t=-t,d=_.length):(n=_,s=u,d=M.length),u=Math.ceil(v/$),d=u>d?u+1:d+1,t>d&&(t=d,n.length=1),n.reverse();t--;)n.push(0);n.reverse()}for(d=M.length,t=_.length,d-t<0&&(t=d,n=_,_=M,M=n),r=0;t;)r=(M[--t]=M[t]+_[t]+r)/Qe|0,M[t]%=Qe;for(r&&(M.unshift(r),++s),d=M.length;M[--d]==0;)M.pop();return i.d=M,i.e=Nt(M,s),H?Z(i,v,w):i};O.precision=O.sd=function(i){var r,n=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(lt+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 Z(new r(i),i.e+1,r.rounding)};O.sine=O.sin=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+Math.max(n.e,n.sd())+$,s.rounding=1,n=rn(s,sr(s,n)),s.precision=i,s.rounding=r,Z(nt>2?n.neg():n,i,r,!0)):new s(NaN)};O.squareRoot=O.sqrt=function(){var i,r,n,s,t,u,d=this,v=d.d,w=d.e,M=d.s,_=d.constructor;if(M!==1||!v||!v[0])return new _(!M||M<0&&(!v||v[0])?NaN:v?d:1/0);for(H=!1,M=Math.sqrt(+d),M==0||M==1/0?(r=je(v),(r.length+w)%2==0&&(r+="0"),M=Math.sqrt(r),w=Ze((w+1)/2)-(w<0||w%2),M==1/0?r="5e"+w:(r=M.toExponential(),r=r.slice(0,r.indexOf("e")+1)+w),s=new _(r)):s=new _(M.toString()),n=(w=_.precision)+3;;)if(u=s,s=u.plus(re(d,u,n+2,1)).times(.5),je(u.d).slice(0,n)===(r=je(s.d)).slice(0,n))if(r=r.slice(n-3,n+1),r=="9999"||!t&&r=="4999"){if(!t&&(Z(u,w+1,0),u.times(u).eq(d))){s=u;break}n+=4,t=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(Z(s,w+1,1),i=!s.times(s).eq(d));break}return H=!0,Z(s,w,_.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=re(n,new s(1).minus(n.times(n)).sqrt(),i+10,0),s.precision=i,s.rounding=r,Z(nt==2||nt==4?n.neg():n,i,r,!0)):new s(NaN)};O.times=O.mul=function(i){var r,n,s,t,u,d,v,w,M,_=this,C=_.constructor,A=_.d,L=(i=new C(i)).d;if(i.s*=_.s,!A||!A[0]||!L||!L[0])return new C(!i.s||A&&!A[0]&&!L||L&&!L[0]&&!A?NaN:!A||!L?i.s/0:i.s*0);for(n=Ze(_.e/$)+Ze(i.e/$),w=A.length,M=L.length,w<M&&(u=A,A=L,L=u,d=w,w=M,M=d),u=[],d=w+M,s=d;s--;)u.push(0);for(s=M;--s>=0;){for(r=0,t=w+s;t>s;)v=u[t]+L[s]*A[t-s-1]+r,u[t--]=v%Qe|0,r=v/Qe|0;u[t]=(u[t]+r)%Qe|0}for(;!u[--d];)u.pop();return r?++n:u.shift(),i.d=u,i.e=Nt(u,n),H?Z(i,C.precision,C.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,ut),r===void 0?r=s.rounding:Ke(r,0,8),Z(n,i+n.e+1,r))};O.toExponential=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=tt(s,!0):(Ke(i,0,ut),r===void 0?r=t.rounding:Ke(r,0,8),s=Z(new t(s),i+1,r),n=tt(s,!0,i+1)),s.isNeg()&&!s.isZero()?"-"+n:n};O.toFixed=function(i,r){var n,s,t=this,u=t.constructor;return i===void 0?n=tt(t):(Ke(i,0,ut),r===void 0?r=u.rounding:Ke(r,0,8),s=Z(new u(t),i+t.e+1,r),n=tt(s,!1,i+s.e+1)),t.isNeg()&&!t.isZero()?"-"+n:n};O.toFraction=function(i){var r,n,s,t,u,d,v,w,M,_,C,A,L=this,E=L.d,N=L.constructor;if(!E)return new N(L);if(M=n=new N(1),s=w=new N(0),r=new N(s),u=r.e=ir(E)-L.e-1,d=u%$,r.d[0]=Fe(10,d<0?$+d:d),i==null)i=u>0?r:M;else{if(v=new N(i),!v.isInt()||v.lt(M))throw Error(lt+v);i=v.gt(r)?u>0?r:M:v}for(H=!1,v=new N(je(E)),_=N.precision,N.precision=u=E.length*$*2;C=re(v,r,0,1,1),t=n.plus(C.times(s)),t.cmp(i)!=1;)n=s,s=t,t=M,M=w.plus(C.times(t)),w=t,t=r,r=v.minus(C.times(t)),v=t;return t=re(i.minus(n),s,0,1,1),w=w.plus(t.times(M)),n=n.plus(t.times(s)),w.s=M.s=L.s,A=re(M,s,u,1).minus(L).abs().cmp(re(w,n,u,1).minus(L).abs())<1?[M,s]:[w,n],N.precision=_,H=!0,A};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]?(H=!1,n=re(n,i,0,r,1).times(i),H=!0,Z(n)):(i.s=n.s,n=i),n};O.toNumber=function(){return+this};O.toOctal=function(i,r){return ci(this,8,i,r)};O.toPower=O.pow=function(i){var r,n,s,t,u,d,v=this,w=v.constructor,M=+(i=new w(i));if(!v.d||!i.d||!v.d[0]||!i.d[0])return new w(Fe(+v,M));if(v=new w(v),v.eq(1))return v;if(s=w.precision,u=w.rounding,i.eq(1))return Z(v,s,u);if(r=Ze(i.e/$),r>=i.d.length-1&&(n=M<0?-M:M)<=Yr)return t=rr(w,v,n,s),i.s<0?new w(1).div(t):Z(t,s,u);if(d=v.s,d<0){if(r<i.d.length-1)return new w(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=Fe(+v,M),r=n==0||!isFinite(n)?Ze(M*(Math.log("0."+je(v.d))/Math.LN10+v.e+1)):new w(n+"").e,r>w.maxE+1||r<w.minE-1?new w(r>0?d/0:0):(H=!1,w.rounding=v.s=1,n=Math.min(12,(r+"").length),t=hi(i.times(at(v,s+n)),s),t.d&&(t=Z(t,s+5,1),vt(t.d,s,u)&&(r=s+10,t=Z(hi(i.times(at(v,r+n)),r),r+5,1),+je(t.d).slice(s+1,s+15)+1==1e14&&(t=Z(t,s+1,0)))),t.s=d,H=!0,w.rounding=u,Z(t,s,u))};O.toPrecision=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=tt(s,s.e<=t.toExpNeg||s.e>=t.toExpPos):(Ke(i,1,ut),r===void 0?r=t.rounding:Ke(r,0,8),s=Z(new t(s),i,r),n=tt(s,i<=s.e||s.e<=t.toExpNeg,i)),s.isNeg()&&!s.isZero()?"-"+n:n};O.toSignificantDigits=O.toSD=function(i,r){var n=this,s=n.constructor;return i===void 0?(i=s.precision,r=s.rounding):(Ke(i,1,ut),r===void 0?r=s.rounding:Ke(r,0,8)),Z(new s(n),i,r)};O.toString=function(){var i=this,r=i.constructor,n=tt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()&&!i.isZero()?"-"+n:n};O.truncated=O.trunc=function(){return Z(new this.constructor(this),this.e+1,1)};O.valueOf=O.toJSON=function(){var i=this,r=i.constructor,n=tt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()?"-"+n:n};function je(i){var r,n,s,t=i.length-1,u="",d=i[0];if(t>0){for(u+=d,r=1;r<t;r++)s=i[r]+"",n=$-s.length,n&&(u+=st(n)),u+=s;d=i[r],s=d+"",n=$-s.length,n&&(u+=st(n))}else if(d===0)return"0";for(;d%10===0;)d/=10;return u+d}function Ke(i,r,n){if(i!==~~i||i<r||i>n)throw Error(lt+i)}function vt(i,r,n,s){var t,u,d,v;for(u=i[0];u>=10;u/=10)--r;return--r<0?(r+=$,t=0):(t=Math.ceil((r+1)/$),r%=$),u=Fe(10,$-r),v=i[t]%u|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==u||n>3&&v+1==u/2)&&(i[t+1]/u/100|0)==Fe(10,r-2)-1||(v==u/2||v==0)&&(i[t+1]/u/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==u||!s&&n>3&&v+1==u/2)&&(i[t+1]/u/1e3|0)==Fe(10,r-3)-1,d}function At(i,r,n){for(var s,t=[0],u,d=0,v=i.length;d<v;){for(u=t.length;u--;)t[u]*=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 u=n;u--;){var d=r.times(r);r=d.times(d).minus(d).times(8).plus(1)}return i.precision-=n,r}var re=(function(){function i(s,t,u){var d,v=0,w=s.length;for(s=s.slice();w--;)d=s[w]*t+v,s[w]=d%u|0,v=d/u|0;return v&&s.unshift(v),s}function r(s,t,u,d){var v,w;if(u!=d)w=u>d?1:-1;else for(v=w=0;v<u;v++)if(s[v]!=t[v]){w=s[v]>t[v]?1:-1;break}return w}function n(s,t,u,d){for(var v=0;u--;)s[u]-=v,v=s[u]<t[u]?1:0,s[u]=v*d+s[u]-t[u];for(;!s[0]&&s.length>1;)s.shift()}return function(s,t,u,d,v,w){var M,_,C,A,L,E,N,U,j,I,B,F,J,z,V,m,b,k,x,P,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(w?(L=1,_=s.e-t.e):(w=Qe,L=$,_=Ze(s.e/L)-Ze(t.e/L)),x=l.length,b=o.length,j=new c(e),I=j.d=[],C=0;l[C]==(o[C]||0);C++);if(l[C]>(o[C]||0)&&_--,u==null?(z=u=c.precision,d=c.rounding):v?z=u+(s.e-t.e)+1:z=u,z<0)I.push(1),E=!0;else{if(z=z/L+2|0,C=0,x==1){for(A=0,l=l[0],z++;(C<b||A)&&z--;C++)V=A*w+(o[C]||0),I[C]=V/l|0,A=V%l|0;E=A||C<b}else{for(A=w/(l[0]+1)|0,A>1&&(l=i(l,A,w),o=i(o,A,w),x=l.length,b=o.length),m=x,B=o.slice(0,x),F=B.length;F<x;)B[F++]=0;P=l.slice(),P.unshift(0),k=l[0],l[1]>=w/2&&++k;do A=0,M=r(l,B,x,F),M<0?(J=B[0],x!=F&&(J=J*w+(B[1]||0)),A=J/k|0,A>1?(A>=w&&(A=w-1),N=i(l,A,w),U=N.length,F=B.length,M=r(N,B,U,F),M==1&&(A--,n(N,x<U?P:l,U,w))):(A==0&&(M=A=1),N=l.slice()),U=N.length,U<F&&N.unshift(0),n(B,N,F,w),M==-1&&(F=B.length,M=r(l,B,x,F),M<1&&(A++,n(B,x<F?P:l,F,w))),F=B.length):M===0&&(A++,B=[0]),I[C++]=A,M&&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)j.e=_,Qi=E;else{for(C=1,A=I[0];A>=10;A/=10)C++;j.e=C+_*L-1,Z(j,v?u+j.e+1:u,d,E)}return j}})();function Z(i,r,n,s){var t,u,d,v,w,M,_,C,A,L=i.constructor;e:if(r!=null){if(C=i.d,!C)return i;for(t=1,v=C[0];v>=10;v/=10)t++;if(u=r-t,u<0)u+=$,d=r,_=C[A=0],w=_/Fe(10,t-d-1)%10|0;else if(A=Math.ceil((u+1)/$),v=C.length,A>=v)if(s){for(;v++<=A;)C.push(0);_=w=0,t=1,u%=$,d=u-$+1}else break e;else{for(_=v=C[A],t=1;v>=10;v/=10)t++;u%=$,d=u-$+t,w=d<0?0:_/Fe(10,t-d-1)%10|0}if(s=s||r<0||C[A+1]!==void 0||(d<0?_:_%Fe(10,t-d-1)),M=n<4?(w||s)&&(n==0||n==(i.s<0?3:2)):w>5||w==5&&(n==4||s||n==6&&(u>0?d>0?_/Fe(10,t-d):0:C[A-1])%10&1||n==(i.s<0?8:7)),r<1||!C[0])return C.length=0,M?(r-=i.e+1,C[0]=Fe(10,($-r%$)%$),i.e=-r||0):C[0]=i.e=0,i;if(u==0?(C.length=A,v=1,A--):(C.length=A+1,v=Fe(10,$-u),C[A]=d>0?(_/Fe(10,t-d)%Fe(10,d)|0)*v:0),M)for(;;)if(A==0){for(u=1,d=C[0];d>=10;d/=10)u++;for(d=C[0]+=v,v=1;d>=10;d/=10)v++;u!=v&&(i.e++,C[0]==Qe&&(C[0]=1));break}else{if(C[A]+=v,C[A]!=Qe)break;C[A--]=0,v=1}for(u=C.length;C[--u]===0;)C.pop()}return H&&(i.e>L.maxE?(i.d=null,i.e=NaN):i.e<L.minE&&(i.e=0,i.d=[0])),i}function tt(i,r,n){if(!i.isFinite())return or(i);var s,t=i.e,u=je(i.d),d=u.length;return r?(n&&(s=n-d)>0?u=u.charAt(0)+"."+u.slice(1)+st(s):d>1&&(u=u.charAt(0)+"."+u.slice(1)),u=u+(i.e<0?"e":"e+")+i.e):t<0?(u="0."+st(-t-1)+u,n&&(s=n-d)>0&&(u+=st(s))):t>=d?(u+=st(t+1-d),n&&(s=n-t-1)>0&&(u=u+"."+st(s))):((s=t+1)<d&&(u=u.slice(0,s)+"."+u.slice(s)),n&&(s=n-d)>0&&(t+1===d&&(u+="."),u+=st(s))),u}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 H=!0,n&&(i.precision=n),Error(Yi);return Z(new i(xt),r,1,!0)}function et(i,r,n){if(r>fi)throw Error(Yi);return Z(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 st(i){for(var r="";i--;)r+="0";return r}function rr(i,r,n,s){var t,u=new i(1),d=Math.ceil(s/$+4);for(H=!1;;){if(n%2&&(u=u.times(r),Vi(u.d,d)&&(t=!0)),n=Ze(n/2),n===0){n=u.d.length-1,t&&u.d[n]===0&&++u.d[n];break}r=r.times(r),Vi(r.d,d)}return H=!0,u}function Gi(i){return i.d[i.d.length-1]&1}function nr(i,r,n){for(var s,t,u=new i(r[0]),d=0;++d<r.length;){if(t=new i(r[d]),!t.s){u=t;break}s=u.cmp(t),(s===n||s===0&&u.s===n)&&(u=t)}return u}function hi(i,r){var n,s,t,u,d,v,w,M=0,_=0,C=0,A=i.constructor,L=A.rounding,E=A.precision;if(!i.d||!i.d[0]||i.e>17)return new A(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(r==null?(H=!1,w=E):w=r,v=new A(.03125);i.e>-2;)i=i.times(v),C+=5;for(s=Math.log(Fe(2,C))/Math.LN10*2+5|0,w+=s,n=u=d=new A(1),A.precision=w;;){if(u=Z(u.times(i),w,1),n=n.times(++_),v=d.plus(re(u,n,w,1)),je(v.d).slice(0,w)===je(d.d).slice(0,w)){for(t=C;t--;)d=Z(d.times(d),w,1);if(r==null)if(M<3&&vt(d.d,w-s,L,M))A.precision=w+=10,n=u=v=new A(1),_=0,M++;else return Z(d,A.precision=E,L,H=!0);else return A.precision=E,d}d=v}}function at(i,r){var n,s,t,u,d,v,w,M,_,C,A,L=1,E=10,N=i,U=N.d,j=N.constructor,I=j.rounding,B=j.precision;if(N.s<0||!U||!U[0]||!N.e&&U[0]==1&&U.length==1)return new j(U&&!U[0]?-1/0:N.s!=1?NaN:U?0:N);if(r==null?(H=!1,_=B):_=r,j.precision=_+=E,n=je(U),s=n.charAt(0),Math.abs(u=N.e)<15e14){for(;s<7&&s!=1||s==1&&n.charAt(1)>3;)N=N.times(i),n=je(N.d),s=n.charAt(0),L++;u=N.e,s>1?(N=new j("0."+n),u++):N=new j(s+"."+n.slice(1))}else return M=It(j,_+2,B).times(u+""),N=at(new j(s+"."+n.slice(1)),_-E).plus(M),j.precision=B,r==null?Z(N,B,I,H=!0):N;for(C=N,w=d=N=re(N.minus(1),N.plus(1),_,1),A=Z(N.times(N),_,1),t=3;;){if(d=Z(d.times(A),_,1),M=w.plus(re(d,new j(t),_,1)),je(M.d).slice(0,_)===je(w.d).slice(0,_))if(w=w.times(2),u!==0&&(w=w.plus(It(j,_+2,B).times(u+""))),w=re(w,new j(L),_,1),r==null)if(vt(w.d,_-E,I,v))j.precision=_+=E,M=d=N=re(C.minus(1),C.plus(1),_,1),A=Z(N.times(N),_,1),t=v=1;else return Z(w,j.precision=B,I,H=!0);else return j.precision=B,w;w=M,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),H&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function tn(i,r){var n,s,t,u,d,v,w,M,_;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(lt+r);for(u=r.search(/p/i),u>0?(w=+r.slice(u+1),r=r.substring(2,u)):r=r.slice(2),u=r.indexOf("."),d=u>=0,s=i.constructor,d&&(r=r.replace(".",""),v=r.length,u=v-u,t=rr(s,new s(n),u,u*2)),M=At(r,n,Qe),_=M.length-1,u=_;M[u]===0;--u)M.pop();return u<0?new s(i.s*0):(i.e=Nt(M,_),i.d=M,H=!1,d&&(i=re(i,t,v*4)),w&&(i=i.times(Math.abs(w)<54?Fe(2,w):wt.pow(2,w))),H=!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,u=new i(5),d=new i(16),v=new i(20);n--;)t=r.times(r),r=r.times(u.plus(t.times(d.times(t).minus(v))));return r}function gt(i,r,n,s,t){var u,d,v,w,M=1,_=i.precision,C=Math.ceil(_/$);for(H=!1,w=n.times(n),v=new i(s);;){if(d=re(v.times(w),new i(r++*r++),_,1),v=t?s.plus(d):s.minus(d),s=re(d.times(w),new i(r++*r++),_,1),d=v.plus(s),d.d[C]!==void 0){for(u=C;d.d[u]===v.d[u]&&u--;);if(u==-1)break}u=v,v=s,s=d,d=u,M++}return H=!0,d.d.length=C+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=et(i,i.precision,1),u=t.times(.5);if(r=r.abs(),r.lte(u))return nt=s?4:1,r;if(n=r.divToInt(t),n.isZero())nt=s?3:2;else{if(r=r.minus(n.times(t)),r.lte(u))return nt=Gi(n)?s?2:3:s?4:1,r;nt=Gi(n)?s?1:4:s?3:2}return r.minus(t).abs()}function ci(i,r,n,s){var t,u,d,v,w,M,_,C,A,L=i.constructor,E=n!==void 0;if(E?(Ke(n,1,ut),s===void 0?s=L.rounding:Ke(s,0,8)):(n=L.precision,s=L.rounding),!i.isFinite())_=or(i);else{for(_=tt(i),d=_.indexOf("."),E?(t=2,r==16?n=n*4-3:r==8&&(n=n*3-2)):t=r,d>=0&&(_=_.replace(".",""),A=new L(1),A.e=_.length-d,A.d=At(tt(A),10,t),A.e=A.d.length),C=At(_,10,t),u=w=C.length;C[--w]==0;)C.pop();if(!C[0])_=E?"0p+0":"0";else{if(d<0?u--:(i=new L(i),i.d=C,i.e=u,i=re(i,A,n,s,0,t),C=i.d,u=i.e,M=Qi),d=C[n],v=t/2,M=M||C[n+1]!==void 0,M=s<4?(d!==void 0||M)&&(s===0||s===(i.s<0?3:2)):d>v||d===v&&(s===4||M||s===6&&C[n-1]&1||s===(i.s<0?8:7)),C.length=n,M)for(;++C[--n]>t-1;)C[n]=0,n||(++u,C.unshift(1));for(w=C.length;!C[w-1];--w);for(d=0,_="";d<w;d++)_+=li.charAt(C[d]);if(E){if(w>1)if(r==16||r==8){for(d=r==16?4:3,--w;w%d;w++)_+="0";for(C=At(_,t,r),w=C.length;!C[w-1];--w);for(d=1,_="1.";d<w;d++)_+=li.charAt(C[d])}else _=_.charAt(0)+"."+_.slice(1);_=_+(u<0?"p":"p+")+u}else if(u<0){for(;++u;)_="0"+_;_="0."+_}else if(++u>w)for(u-=w;u--;)_+="0";else u<w&&(_=_.slice(0,u)+"."+_.slice(u))}_=(r==16?"0x":r==2?"0b":r==8?"0o":"")+_}return i.s<0?"-"+_:_}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 un(i){return new this(i).asinh()}function fn(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,u=s+4;return!i.s||!r.s?n=new this(NaN):!i.d&&!r.d?(n=et(this,u,1).times(r.s>0?.25:.75),n.s=i.s):!r.d||i.isZero()?(n=r.s<0?et(this,s,t):new this(0),n.s=i.s):!i.d||r.isZero()?(n=et(this,u,1).times(.5),n.s=i.s):r.s<0?(this.precision=u,this.rounding=1,n=this.atan(re(i,r,u,1)),r=et(this,u,1),this.precision=s,this.rounding=t,n=i.s<0?n.minus(r):n.plus(r)):n=this.atan(re(i,r,u,1)),n}function dn(i){return new this(i).cbrt()}function pn(i){return Z(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,u=["precision",1,ut,"rounding",0,8,"toExpNeg",-pt,0,"toExpPos",0,pt,"maxE",0,pt,"minE",-pt,0,"modulo",0,9];for(r=0;r<u.length;r+=3)if(n=u[r],t&&(this[n]=ui[n]),(s=i[n])!==void 0)if(Ze(s)===s&&s>=u[r+1]&&s<=u[r+2])this[n]=s;else throw Error(lt+n+": "+s);if(n="crypto",t&&(this[n]=ui[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(lt+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(u){var d,v,w,M=this;if(!(M instanceof t))return new t(u);if(M.constructor=t,Xi(u)){M.s=u.s,H?!u.d||u.e>t.maxE?(M.e=NaN,M.d=null):u.e<t.minE?(M.e=0,M.d=[0]):(M.e=u.e,M.d=u.d.slice()):(M.e=u.e,M.d=u.d?u.d.slice():u.d);return}if(w=typeof u,w==="number"){if(u===0){M.s=1/u<0?-1:1,M.e=0,M.d=[0];return}if(u<0?(u=-u,M.s=-1):M.s=1,u===~~u&&u<1e7){for(d=0,v=u;v>=10;v/=10)d++;H?d>t.maxE?(M.e=NaN,M.d=null):d<t.minE?(M.e=0,M.d=[0]):(M.e=d,M.d=[u]):(M.e=d,M.d=[u]);return}if(u*0!==0){u||(M.s=NaN),M.e=NaN,M.d=null;return}return Pt(M,u.toString())}if(w==="string")return(v=u.charCodeAt(0))===45?(u=u.slice(1),M.s=-1):(v===43&&(u=u.slice(1)),M.s=1),tr.test(u)?Pt(M,u):tn(M,u);if(w==="bigint")return u<0?(u=-u,M.s=-1):M.s=1,Pt(M,u.toString());throw Error(lt+u)}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=un,t.atan=fn,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=Sn,t.log10=An,t.log2=Cn,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=jn,t.trunc=Zn,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 Z(i=new this(i),i.e+1,3)}function _n(){var i,r,n=new this(0);for(H=!1,i=0;i<arguments.length;)if(r=new this(arguments[i++]),r.d)n.d&&(n=n.plus(r.times(r)));else{if(r.s)return H=!0,new this(1/0);n=r}return H=!0,n.sqrt()}function Xi(i){return i instanceof wt||i&&i.toStringTag===er||!1}function kn(i){return new this(i).ln()}function Sn(i,r){return new this(i).log(r)}function Cn(i){return new this(i).log(2)}function An(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,u=0,d=new this(1),v=[];if(i===void 0?i=this.precision:Ke(i,1,ut),s=Math.ceil(i/$),this.crypto)if(crypto.getRandomValues)for(r=crypto.getRandomValues(new Uint32Array(s));u<s;)t=r[u],t>=429e7?r[u]=crypto.getRandomValues(new Uint32Array(1))[0]:v[u++]=t%1e7;else if(crypto.randomBytes){for(r=crypto.randomBytes(s*=4);u<s;)t=r[u]+(r[u+1]<<8)+(r[u+2]<<16)+((r[u+3]&127)<<24),t>=214e7?crypto.randomBytes(4).copy(r,u):(v.push(t%1e7),u+=4);u=s/4}else throw Error(Ji);else for(;u<s;)v[u++]=Math.random()*1e7|0;for(s=v[--u],i%=$,s&&i&&(t=Fe(10,$-i),v[u]=(s/t|0)*t);v[u]===0;u--)v.pop();if(u<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 Z(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(H=!1;n.s&&++i<r.length;)n=n.plus(r[i]);return H=!0,Z(n,this.precision,this.rounding)}function Un(i){return new this(i).tan()}function jn(i){return new this(i).tanh()}function Zn(i){return Z(i=new this(i),i.e+1,1)}O[Symbol.for("nodejs.util.inspect.custom")]=O.toString;O[Symbol.toStringTag]="Decimal";var wt=O.constructor=ar(ui);xt=new wt(xt);Lt=new wt(Lt);var Ye=wt;var mi=Cr(ur());import{Transaction as it}from"@mysten/sui/transactions";import{addHexPrefix as fr,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:fr(r.base_token.fields.name),quoteToken:fr(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=Be(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=Be(this._sdk.sdkOptions.leverage),u=50,d=null,v=[];for(;;){let A=await this._sdk.FullClient.getDynamicFields({parentId:t.markets_table_id,limit:u,cursor:d});if(A.data.forEach(L=>{v.push(L.objectId)}),A.data.length<u)break;d=A.nextCursor}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:63 ~ LeverageModules ~ marketSimpleIdList:",v);let w=await this._sdk.FullClient.batchGetObjects(v,{showContent:!0}),M=[];w.forEach(A=>{M.push(A.data.content.fields.value.fields.market_id)});let _=await this._sdk.FullClient.batchGetObjects(M,{showContent:!0}),C=cr(_);return this._sdk.updateCache(n,C,dr),C};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}}),u=pi(t);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:106 ~ LeverageModules ~ marketInfo:",u),this._sdk.updateCache(n,u,dr),u};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}=Be(this._sdk.sdkOptions.suilend),t=await this._sdk.SuiLendModule.getSuilendClient(n,s),u=[];for(let d=0;d<r.data.length;d++){let v=gi(r.data[d]),w=await t.getObligation(v.obligationOwnerCap);u.push({...v,...w})}return u};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:u}=Be(this._sdk.sdkOptions.suilend),d=await this._sdk.SuiLendModule.getSuilendClient(t,u),{allLendingMarketData:v}=await this._sdk.SuiLendModule.getLendingMarketData(),w=v[t].reserveMap,M=await d.getObligation(s.obligationOwnerCap);return{...zn(M,w||{}),...s}};this.getClmmPoolInfo=async r=>{let n=await this._sdk.ClmmSDK.Pool.getPool(r),{coin_type_a:s,coin_type_b:t,fee_rate:u}=n;return{clmmFeeTier:u/1e6,clmmPoolCoinTypeA:s,clmmPoolCoinTypeB:t}};this.openLeveragePosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:u,slippage:d,leverage:v,marketId:w}=r,{lendingMarketId:M}=Be(this._sdk.sdkOptions.suilend),_=new it,{openFeeRate:C,baseToken:A,quoteToken:L}=await this.getLeverageMarketInfo(w),{clmmFeeTier:E,clmmPoolCoinTypeA:N,clmmPoolCoinTypeB:U}=await this.getClmmPoolInfo(u);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",E,N,U);let{baseReserveArrayIndex:j,quoteReserveArrayIndex:I,reserve:B}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(A,L),F=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",F);let J=t.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",J);let z,V;if(F){let T=s&&n?L:A,q=s&&n?A:L,X=await this.findRouters(T,q,t,!0,[u]);if(J=X?.amount_out.toString(),X){let ee=ie.buildCoinWithBalance(BigInt(t.toString()),T,_);V=await this.routerSwap({router:X.route_obj,slippage:d,inputCoin:ee,txb:_}),z=V}}else z=ie.buildCoinWithBalance(BigInt(t.toString()),n?L:A,_);let{flashAmount:m}=await this.calculateFlashLoanParams({isLong:s,leverage:v,baseToken:A,quoteToken:L,initDepositAmount:J,reserve:B});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",m);let b=s?L:A;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",b);let k=N===b;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",N),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",k);let x=K(m).mul(E).toString(),{balanceA:P,balanceB:c,receipt:e}=this.flashLoan({amount:K(m),clmmPool:u,clmmPoolCoinTypeA:N,clmmPoolCoinTypeB:U,flashLoanCoin:b,tx:_}),o=s?L:A,l=s?A:L,f=await this.findRouters(o,l,K(m),!0,[u]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:f,debtFrom:o,debtTo:l,clmmPoolCoinTypeA:N,clmmPoolCoinTypeB:U});let h=K(f?.amount_out||0),g;f&&(g=await this.routerSwap({router:f.route_obj,inputCoin:k?ie.fromBalance(P,N,_):ie.fromBalance(c,U,_),slippage:d,txb:_}));let S=K(h).add(J).mul(1-C).toDP(0,Ye.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:258 ~ LeverageModules ~ totalDepositAmount:",S,J,h);let p=this.createLeveragePosition({leverage:v,marketId:w,baseToken:A,quoteToken:L,isLong:s,totalDepositAmount:S,tx:_});for(let T=0;T<B.length;T++){let q=Mt(new Uint8Array(B[T].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(_,q,BigInt(B[T].arrayIndex))}let a=s?j:I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",z),await _.mergeCoins(g,[z]),await this.depositToLeveragePosition({isLong:s,marketId:w,position:p,depositReserveArrayIndex:a,inputCoin:g},_);let y=K(m).add(x).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",y,m,x);let D=await this.borrowAsset({position:p,reserveArrayIndex:s?I:j,borrowAmount:K(y),baseToken:A,quoteToken:L,isLong:s,lendingMarketId:M},_);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",D);let R=ie.mintBalanceZero(k?U:N,_);return this.repayFlashLoan({tx:_,clmmPool:u,repayBase:k?ie.intoBalance(D,N,_):R,repayQuote:k?R:ie.intoBalance(D,U,_),receipt:e,clmmPoolCoinTypeA:N,clmmPoolCoinTypeB:U}),_.transferObjects([p],_.pure.address(this._sdk.getSenderAddress())),ie.destroyBalanceZero(k?c:P,k?U:N,_),_};this.positionManageSizeDeposit=async r=>{let{marketId:n,positionId:s,isQuote:t,depositAmount:u,clmmPool:d,slippage:v,leverage:w,txb:M}=r,{lendingMarketId:_}=Be(this._sdk.sdkOptions.suilend),{baseToken:C,quoteToken:A}=await this.getLeverageMarketInfo(n),{isLong:L,deposits:E,borrows:N}=await this.getLeveragePosition(s),{reserve:U}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(C,A),{clmmFeeTier:j,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B}=await this.getClmmPoolInfo(d),F=M||new it,J=E[0].reserveArrayIndex.toString(),z=N[0].reserveArrayIndex.toString(),V=t&&L||!t&&!L,m;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",V);let b;if(V){let D=t&&L?A:C,R=t&&L?C:A,T=await this.findRouters(D,R,u,!0,[d]);if(T){let q=ie.buildCoinWithBalance(BigInt(u.toString()),D,F);b=await this.routerSwap({router:T.route_obj,inputCoin:q,slippage:v,txb:F}),m=b}}else m=ie.buildCoinWithBalance(BigInt(u.toString()),t?A:C,F);let k=L?A:C;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",k);let{flashAmount:x}=await this.calculateFlashLoanParams({isLong:L,leverage:w,baseToken:C,quoteToken:A,initDepositAmount:u.toString(),reserve:U}),P=K(x).mul(j).toString(),c=I===k;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",c);let{balanceA:e,balanceB:o,receipt:l}=this.flashLoan({amount:K(x),clmmPool:d,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B,flashLoanCoin:k,tx:F}),f=L?A:C,h=L?C:A,g=await this.findRouters(f,h,K(x),!0,[d]),S;g&&(S=await this.routerSwap({router:g.route_obj,inputCoin:c?ie.fromBalance(e,I,F):ie.fromBalance(o,B,F),slippage:v,txb:F})),F.mergeCoins(S,[m]);for(let D=0;D<U.length;D++){let R=Mt(new Uint8Array(U[D].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(F,R,BigInt(U[D].arrayIndex))}this.depositToLeveragePosition({isLong:L,marketId:n,positionId:s,depositReserveArrayIndex:J,inputCoin:S},F);let p=K(x).add(P).toDP(0,Ye.ROUND_UP).toString(),a=this.borrowAsset({positionId:s,reserveArrayIndex:z,borrowAmount:K(p),baseToken:C,quoteToken:A,isLong:L,lendingMarketId:_},F),y=ie.mintBalanceZero(c?B:I,F);return this.repayFlashLoan({tx:F,clmmPool:d,repayBase:c?ie.intoBalance(a,I,F):y,repayQuote:c?y:ie.intoBalance(a,B,F),receipt:l,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B}),ie.destroyBalanceZero(c?o:e,c?B:I,F),F};this.positionManageSizeWithdraw=async r=>{let{marketId:n,positionId:s,withdrawAmount:t,isQuote:u,txb:d,clmmPool:v,slippage:w,leverage:M}=r,{lendingMarketType:_,lendingMarketId:C}=Be(this._sdk.sdkOptions.suilend),A=d||new it,{baseToken:L,quoteToken:E}=await this.getLeverageMarketInfo(n),{isLong:N,deposits:U,borrows:j}=await this.getLeveragePosition(s),{reserve:I}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(L,E),B=u&&N||!u&&!N;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 J=null;if(B){let S=L,p=E;J=await this.findRouters(S,p,t,!1,[v]),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ routers:",{hasSwapRouters:J,from:S,to:p}),F=J?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",F);for(let S=0;S<I.length;S++){let p=Mt(new Uint8Array(I[S].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,p,BigInt(I[S].arrayIndex))}let{token:z}=j[0].reserve,V=K(U[0].depositedCtokenAmount.toString()).div(K(M)).toDP(0,Ye.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",V);let m=K(F).div(K(V)).toString(),b=K(j[0].borrowedAmount.toString()).mul(10**z.decimals).toString(),k=K(b).mul(m).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:508 ~ LeverageModules ~ repayAmount:",{\u9700\u8981\u507F\u8FD8\u591A\u5C11borrowAmount:k,\u63D0\u53D6\u4FDD\u8BC1\u91D1\u6570\u91CF:F,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:V});let x=await this._sdk.SuiLendModule.getSuilendClient(C,_),P=await this._sdk.PythConnection.getPriceFeedsUpdateData([U[0].reserve.priceIdentifier]),c=await x.pythClient.updatePriceFeeds(A,P,[U[0].reserve.priceIdentifier]),e=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:K(F),withdrawReserveArrayIndex:U[0].reserveArrayIndex.toString(),withdrawCoinType:N?L:E,baseToken:L,quoteToken:E,priceObjectId:c&&c[0]},A),o=N?L:E,l=N?E:L;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let f=await this.findRouters(o,l,K(k),!1,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:530 ~ LeverageModules ~ debtRouter:",{debtRouter:f,debtFrom:o,debtTo:l});let h;f&&(h=await this.routerSwap({router:f.route_obj,inputCoin:e,slippage:w,txb:A}));let g=A.splitCoins(h,[k]);return this.repay({txb:A,positionId:s,repayReserveArrayIndex:j[0].reserveArrayIndex.toString(),repayCoin:g,repayCoinType:N?E:L,repayAmount:K(0)}),A.transferObjects([h,g],this._sdk.getSenderAddress()),A};this.positionManageLeverageIncrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:u,targetLeverage:d,clmmPool:v,slippage:w}=r,{baseToken:M,quoteToken:_}=await this.getLeverageMarketInfo(n),{deposits:C,borrows:A}=await this.getLeveragePosition(s),{reserve:L}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_),{clmmPoolCoinTypeA:E,clmmPoolCoinTypeB:N,clmmFeeTier:U}=await this.getClmmPoolInfo(v),{lendingMarketId:j}=Be(this._sdk.sdkOptions.suilend),{token:I}=A[0].reserve,B=new it,F=K(A[0].borrowedAmount.toString()).mul(K(d).sub(K(u))).mul(10**I.decimals).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",F);let J=F,z=t?_:M,{balanceA:V,balanceB:m,receipt:b}=this.flashLoan({tx:B,amount:K(J),clmmPool:v,clmmPoolCoinTypeA:E,clmmPoolCoinTypeB:N,flashLoanCoin:z}),k=t?_:M,x=t?M:_,P=await this.findRouters(k,x,K(F),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:592 ~ LeverageModules ~ routers:",P,k,x);let c=await this.routerSwap({router:P?.route_obj,inputCoin:t?ie.fromBalance(m,N,B):ie.fromBalance(V,E,B),slippage:w,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?C[0].reserveArrayIndex.toString():A[0].reserveArrayIndex.toString(),inputCoin:c},B);let e=K(J).mul(K(1).add(U)).toDP(0,Ye.ROUND_UP).toString(),o=await this.borrowAsset({positionId:s,reserveArrayIndex:A[0].reserveArrayIndex.toString(),borrowAmount:K(e),baseToken:M,quoteToken:_,isLong:t,lendingMarketId:j},B),l=ie.mintBalanceZero(t?M:_,B),f=E===z;return this.repayFlashLoan({tx:B,clmmPool:v,repayBase:t?l:ie.intoBalance(o,M,B),repayQuote:t?ie.intoBalance(o,_,B):l,receipt:b,clmmPoolCoinTypeA:E,clmmPoolCoinTypeB:N}),ie.destroyBalanceZero(f?m:V,f?N:E,B),B};this.positionManageLeverageDecrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:u,targetLeverage:d,clmmPool:v,slippage:w}=r,{baseToken:M,quoteToken:_,closeFeeRate:C}=await this.getLeverageMarketInfo(n),{deposits:A,borrows:L}=await this.getLeveragePosition(s),{reserve:E}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_),{lendingMarketId:N,lendingMarketType:U}=Be(this._sdk.sdkOptions.suilend),j=new it,I=K(A[0].depositedCtokenAmount.toString()).mul(K(u).sub(K(d))).toString(),B=K(I).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",B);for(let P=0;P<E.length;P++){let c=Mt(new Uint8Array(E[P].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(j,c,BigInt(E[P].arrayIndex))}let F=await this._sdk.SuiLendModule.getSuilendClient(N,U),J=await this._sdk.PythConnection.getPriceFeedsUpdateData([A[0].reserve.priceIdentifier]),z=await F.pythClient.updatePriceFeeds(j,J,[A[0].reserve.priceIdentifier]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:672 ~ LeverageModules ~ baseToken:",M);let V=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:K(B),withdrawReserveArrayIndex:A[0].reserveArrayIndex.toString(),withdrawCoinType:t?M:_,baseToken:M,quoteToken:_,priceObjectId:z&&z[0]},j),m=t?M:_,b=t?_:M,k=await this.findRouters(m,b,K(B),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:681 ~ LeverageModules ~ routers:",k,k?.route_obj.paths,m,b);let x=await this.routerSwap({router:k?.route_obj,inputCoin:V,slippage:w,txb:j});return this.repay({txb:j,positionId:s,repayReserveArrayIndex:L[0].reserveArrayIndex.toString(),repayCoin:x,repayCoinType:t?_:M,repayAmount:K(0)}),x&&j.transferObjects([x],this._sdk.getSenderAddress()),j};this.leveragePositionClose=async(r,n)=>{let s=n||new it,{marketId:t,positionId:u}=r,{leverage:d}=this._sdk.sdkOptions,{global_config_id:v}=Be(this._sdk.sdkOptions.leverage),{lendingMarketType:w,lendingMarketId:M}=Be(this._sdk.sdkOptions.suilend),{baseToken:_,quoteToken:C}=await this.getLeverageMarketInfo(t),A=await this.getLeveragePosition(u);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:719 ~ LeverageModules ~ positionInfo:",A.original.id),s.moveCall({target:`${d.published_at}::position::close_Position`,typeArguments:[w,_,C],arguments:[s.object(v),s.object(t),s.object(u),$n(s,w,{obligationId:A.original.id,lendingMarket:s.object(M)}),s.object(ft)]}),s};this.positionRepay=async r=>{let{marketId:n,positionId:s,amount:t,isQuote:u,clmmPool:d,slippage:v}=r,{baseToken:w,quoteToken:M,isLong:_}=await this.getLeverageMarketInfo(n),{deposits:C,borrows:A}=await this.getLeveragePosition(s),{token:L}=A[0].reserve,E=K(A[0].borrowedAmount.toString()).mul(10**L.decimals),N=new it,U=A[0].reserve.coinType;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:751 ~ LeverageModules ~ repayCoinType:",U);let j=u?M==U:w==U,I,B=!1;if(j){let F=await this.findRouters(_?w:M,U,t,!0,[d]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:756 ~ LeverageModules ~ routers:",F?.amount_out.toString(),E.toString()),K(F?.amount_out.toString()).gte(E)&&(B=!0);let J=ie.buildCoinWithBalance(BigInt(t.toString()),_?w:M,N);I=await this.routerSwap({router:F?.route_obj,inputCoin:J,slippage:v,txb:N})}else t.gte(E)&&(B=!0),I=ie.buildCoinWithBalance(BigInt(t.toString()),_?M:w,N);if(this.repay({txb:N,positionId:s,repayReserveArrayIndex:A[0].reserveArrayIndex.toString(),repayCoin:I,repayCoinType:_?M:w,repayAmount:K(0)}),N.transferObjects([I],this._sdk.getSenderAddress()),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:786 ~ LeverageModules ~ isClose:",B),B){let{lendingMarketType:F,lendingMarketId:J}=Be(this._sdk.sdkOptions.suilend),z=await this._sdk.SuiLendModule.getSuilendClient(J,F),V=await this._sdk.PythConnection.getPriceFeedsUpdateData([C[0].reserve.priceIdentifier]),m=await z.pythClient.updatePriceFeeds(N,V,[C[0].reserve.priceIdentifier]);this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:K(C[0].depositedCtokenAmount.toString()),withdrawReserveArrayIndex:C[0].reserveArrayIndex.toString(),withdrawCoinType:_?w:M,baseToken:w,quoteToken:M,priceObjectId:m&&m[0]},N),this.leveragePositionClose({marketId:n,positionId:s},N)}return N};this.positionTopUpCoken=async r=>{let{marketId:n,positionId:s,amount:t,isQuote:u,clmmPool:d,slippage:v}=r,w=new it,{baseToken:M,quoteToken:_}=await this.getLeverageMarketInfo(n),{isLong:C}=await this.getLeveragePosition(s),A=C&&u||!C&&!u,L;if(A){let j=await this.findRouters(u?_:M,u?M:_,t,!0,[d]),I=ie.buildCoinWithBalance(BigInt(t.toString()),u?_:M,w);L=await this.routerSwap({router:j?.route_obj,inputCoin:I,slippage:v,txb:w})}else L=ie.buildCoinWithBalance(BigInt(t.toString()),u?_:M,w);let{baseReserveArrayIndex:E,quoteReserveArrayIndex:N,reserve:U}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_);return this.depositToLeveragePosition({isLong:C,marketId:n,positionId:s,depositReserveArrayIndex:C?E:N,inputCoin:L},w),w};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}=Be(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:t,clmmPool:u,clmmPoolCoinTypeA:d,clmmPoolCoinTypeB:v,flashLoanCoin:w,tx:M}=r,_=d===w,[C,A,L]=M.moveCall({target:`${n.published_at}::pool::flash_loan`,arguments:[M.object(s),M.object(u),M.pure.bool(_),M.pure.u64(t.toString())],typeArguments:[d,v]});return{balanceA:C,balanceB:A,receipt:L}};this.repayFlashLoan=r=>{let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:s}=Be(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:t,repayBase:u,repayQuote:d,receipt:v,clmmPool:w,clmmPoolCoinTypeA:M,clmmPoolCoinTypeB:_}=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(w),u,d,v],typeArguments:[M,_]}),t};this.borrowAsset=(r,n)=>{let{position:s,reserveArrayIndex:t,borrowAmount:u,baseToken:d,quoteToken:v,lendingMarketId:w,isLong:M,positionId:_}=r;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:677 ~ LeverageModules ~ params:",r);let{leverage:C}=this._sdk.sdkOptions,{lendingMarketType:A}=Be(this._sdk.sdkOptions.suilend);return ie.isSuiCoin(M?v:d)?n.moveCall({target:`${C.published_at}::position::borrow_sui`,typeArguments:[A],arguments:[n.object(w),s,n.pure.u64(t),n.pure.u64(u.toString()),n.object(gr),n.object(ft)]}):n.moveCall({target:`${C.published_at}::position::borrow_not_sui`,typeArguments:[A,M?v:d],arguments:[n.object(w),_?n.object(_):s,n.pure.u64(t),n.pure.u64(u.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:u}=Be(this._sdk.sdkOptions.suilend),{package_id:d}=this._sdk.sdkOptions.suilend,{marketId:v,positionId:w,withdrawAmount:M,withdrawReserveArrayIndex:_,withdrawCoinType:C,baseToken:A,quoteToken:L,priceObjectId:E}=r,[N]=n.moveCall({target:"0x1::option::none",typeArguments:[`${d}::lending_market::RateLimiterExemption<${u}, ${C}>`],arguments:[]});return ie.isSuiCoin(C)?n.moveCall({target:`${s.published_at}::position::withdraw_sui`,typeArguments:[u,A,L],arguments:[n.object(t),n.object(v),n.object(w),n.object(E),n.object(N),n.pure.u64(M.toString()),n.pure.u64(_),n.object(gr),n.object(ft)]}):n.moveCall({target:`${s.published_at}::position::withdraw_not_sui`,typeArguments:[u,A,L,C],arguments:[n.object(t),n.object(v),n.object(w),n.object(E),n.object(N),n.pure.u64(M.toString()),n.pure.u64(_),n.object(ft)]})};this.repay=r=>{let{leverage:n}=this._sdk.sdkOptions,{lendingMarketId:s,lendingMarketType:t}=Be(this._sdk.sdkOptions.suilend),{txb:u,positionId:d,repayAmount:v,repayCoinType:w,repayCoin:M,repayReserveArrayIndex:_}=r,C=u||new it,A=M||ie.buildCoinWithBalance(BigInt(v.toString()),w,C);C.moveCall({target:`${n.published_at}::position::repay`,typeArguments:[t,w],arguments:[C.object(s),C.object(d),A,C.pure.u64(_.toString()),C.object(ft)]})};this.routerSwap=async r=>{let{slippage:n,txb:s,inputCoin:t,router:u}=r,d=s||new it;if(u)return await this._sdk.AggregatorClient.routerSwap({router:u,inputCoin:t,slippage:n,txb:d})};this.calculateOpenPosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:u,slippage:d,leverage:v,baseToken:w,quoteToken:M}=r,_=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:1193 ~ LeverageModules ~ hasSwap:",_);let C=K(t).mul(v);if(_){let A=s&&n?M:w,L=s&&n?w:M,E=await this.findRouters(A,L,C,!0,[u]);return{amountIn:E?.amount_in.toString(),amountOut:E?.amount_out.toString(),amountOutLimit:K(E?.amount_out.toString()).mul(K(1).sub(d)).toDP(0,Ye.ROUND_DOWN).toString()}}else return{amountIn:t.toString(),amountOut:C.toString(),amountOutLimit:C.toString()}};this._sdk=r}async calculateFlashLoanParams(r){let{isLong:n,leverage:s,baseToken:t,quoteToken:u,initDepositAmount:d,reserve:v}=r,w=await this._sdk.SuiLendModule.getLatestPriceFeeds(v);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:587 ~ LeverageModules ~ calculateFlashLoanParams ~ priceUpdateData:",w,u,t);let M=w[pr(u)]?.price,_=w[pr(t)]?.price,C=n?K(_).div(K(M)).toString():K(M).div(K(_)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",d.toString(),n,C,M,_),{flashAmount:K(d).mul(s-1).mul(C).toDP(0,Ye.ROUND_UP).toString(),rate:C,quotePrice:M,basePrice:_}}createLeveragePosition(r){let{lendingMarketId:n,lendingMarketType:s}=Be(this._sdk.sdkOptions.suilend),{global_config_id:t}=Be(this._sdk.sdkOptions.leverage),u=this._sdk.sdkOptions.leverage,{leverage:d,marketId:v,baseToken:w,quoteToken:M,isLong:_,totalDepositAmount:C,tx:A}=r;return A.moveCall({target:`${u.published_at}::position::open_position`,arguments:[A.object(t),A.object(v),A.object(n),A.pure.u64(C),A.pure.u64(d*1e4),A.object(ft)],typeArguments:[s,w,M,_?w:M]})}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:u}=Be(this._sdk.sdkOptions.suilend),{isLong:d,marketId:v,position:w,positionId:M,depositReserveArrayIndex:_,inputCoin:C}=r,{baseToken:A,quoteToken:L}=await this.getLeverageMarketInfo(v);return n.moveCall({target:`${s.published_at}::position::deposit`,typeArguments:[t,A,L,d?A:L],arguments:[n.object(u),n.object(v),w||n.object(M),C,n.pure.u64(_),n.object(ft)]}),n}async findRouters(r,n,s,t,u){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},w=await this._sdk.AggregatorClient.findRouters(v);if(w?.error?.code===10001)return{...w,is_exceed:w.insufficientLiquidity};if(w?.insufficientLiquidity)return{...w,is_exceed:w.insufficientLiquidity};if(!w?.paths||w?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:w.amountIn.toString(),amount_out:w.amountOut.toString(),is_exceed:w.insufficientLiquidity,route_obj:w,byAmountIn:!0,originRes:w}}catch{try{if(u){let w=await this._sdk.AggregatorClient.swapInPools({from:r,target:n,amount:new mi.default(s.toFixed(0).toString()),byAmountIn:t,pools:u});return w?{amount_in:w.routeData.amountIn.toString(),amount_out:w.routeData.amountOut.toString(),is_exceed:w.isExceed,route_obj:w.routeData,byAmountIn:!0,originRes:w}: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 Ct(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};
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 Sr=(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 Cr=(i,r,n)=>(n=i!=null?vr(yr(i)):{},Sr(r||!i||!i.__esModule?Ri(n,"default",{value:i,enumerable:!0}):n,i));var ur=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 u;try{typeof window<"u"&&typeof window.Buffer<"u"?u=window.Buffer:u=_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 f=0;e[0]==="-"&&(f++,this.negative=1),f<e.length&&(o===16?this._parseHex(e,f,l):(this._parseBase(e,o,f),l==="le"&&this._initArray(this.toArray(),o,l)))},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 f=0;f<this.length;f++)this.words[f]=0;var h,g,S=0;if(l==="be")for(f=e.length-1,h=0;f>=0;f-=3)g=e[f]|e[f-1]<<8|e[f-2]<<16,this.words[h]|=g<<S&67108863,this.words[h+1]=g>>>26-S&67108863,S+=24,S>=26&&(S-=26,h++);else if(l==="le")for(f=0,h=0;f<e.length;f+=3)g=e[f]|e[f+1]<<8|e[f+2]<<16,this.words[h]|=g<<S&67108863,this.words[h+1]=g>>>26-S&67108863,S+=24,S>=26&&(S-=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 f=0;f<this.length;f++)this.words[f]=0;var h=0,g=0,S;if(l==="be")for(f=e.length-1;f>=o;f-=2)S=v(e,o,f)<<h,this.words[g]|=S&67108863,h>=18?(h-=18,g+=1,this.words[g]|=S>>>26):h+=8;else{var p=e.length-o;for(f=p%2===0?o+1:o;f<e.length;f+=2)S=v(e,o,f)<<h,this.words[g]|=S&67108863,h>=18?(h-=18,g+=1,this.words[g]|=S>>>26):h+=8}this._strip()};function w(c,e,o,l){for(var f=0,h=0,g=Math.min(c.length,o),S=e;S<g;S++){var p=c.charCodeAt(S)-48;f*=l,p>=49?h=p-49+10:p>=17?h=p-17+10:h=p,n(p>=0&&h<l,"Invalid character"),f+=h}return f}t.prototype._parseBase=function(e,o,l){this.words=[0],this.length=1;for(var f=0,h=1;h<=67108863;h*=o)f++;f--,h=h/o|0;for(var g=e.length-l,S=g%f,p=Math.min(g,g-S)+l,a=0,y=l;y<p;y+=f)a=w(e,y,y+f,o),this.imuln(h),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(S!==0){var D=1;for(a=w(e,y,e.length,o),y=0;y<S;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 M(c,e){c.words=e.words,c.length=e.length,c.negative=e.negative,c.red=e.red}if(t.prototype._move=function(e){M(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")]=_}catch{t.prototype.inspect=_}else t.prototype.inspect=_;function _(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var C=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],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],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 f=0,h=0,g=0;g<this.length;g++){var S=this.words[g],p=((S<<f|h)&16777215).toString(16);h=S>>>24-f&16777215,f+=2,f>=26&&(f-=26,g--),h!==0||g!==this.length-1?l=C[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=A[e],y=L[e];l="";var D=this.clone();for(D.negative=0;!D.isZero();){var R=D.modrn(y).toString(e);D=D.idivn(y),D.isZero()?l=R+l:l=C[a-R.length]+R+l}for(this.isZero()&&(l="0"+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}n(!1,"Base should be between 2 and 36")},t.prototype.toNumber=function(){var e=this.words[0];return this.length===2?e+=this.words[1]*67108864:this.length===3&&this.words[2]===1?e+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-e:e},t.prototype.toJSON=function(){return this.toString(16,2)},u&&(t.prototype.toBuffer=function(e,o){return this.toArrayLike(u,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 f=this.byteLength(),h=l||Math.max(1,f);n(f<=h,"byte array longer than desired length"),n(h>0,"Requested array length <= 0");var g=E(e,h),S=o==="le"?"LE":"BE";return this["_toArrayLike"+S](g,f),g},t.prototype._toArrayLikeLE=function(e,o){for(var l=0,f=0,h=0,g=0;h<this.length;h++){var S=this.words[h]<<g|f;e[l++]=S&255,l<e.length&&(e[l++]=S>>8&255),l<e.length&&(e[l++]=S>>16&255),g===6?(l<e.length&&(e[l++]=S>>24&255),f=0,g=0):(f=S>>>24,g+=2)}if(l<e.length)for(e[l++]=f;l<e.length;)e[l++]=0},t.prototype._toArrayLikeBE=function(e,o){for(var l=e.length-1,f=0,h=0,g=0;h<this.length;h++){var S=this.words[h]<<g|f;e[l--]=S&255,l>=0&&(e[l--]=S>>8&255),l>=0&&(e[l--]=S>>16&255),g===6?(l>=0&&(e[l--]=S>>24&255),f=0,g=0):(f=S>>>24,g+=2)}if(l>=0)for(e[l--]=f;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 N(c){for(var e=new Array(c.bitLength()),o=0;o<e.length;o++){var l=o/26|0,f=o%26;e[o]=c.words[l]>>>f&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 f=0;f<l.length;f++)this.words[f]=o.words[f]^l.words[f];if(this!==o)for(;f<o.length;f++)this.words[f]=o.words[f];return this.length=o.length,this._strip()},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 f=0;f<o;f++)this.words[f]=~this.words[f]&67108863;return l>0&&(this.words[f]=~this.words[f]&67108863>>26-l),this._strip()},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,f=e%26;return this._expand(l+1),o?this.words[l]=this.words[l]|1<<f:this.words[l]=this.words[l]&~(1<<f),this._strip()},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,f;this.length>e.length?(l=this,f=e):(l=e,f=this);for(var h=0,g=0;g<f.length;g++)o=(l.words[g]|0)+(f.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 f,h;l>0?(f=this,h=e):(f=e,h=this);for(var g=0,S=0;S<h.length;S++)o=(f.words[S]|0)-(h.words[S]|0)+g,g=o>>26,this.words[S]=o&67108863;for(;g!==0&&S<f.length;S++)o=(f.words[S]|0)+g,g=o>>26,this.words[S]=o&67108863;if(g===0&&S<f.length&&f!==this)for(;S<f.length;S++)this.words[S]=f.words[S];return this.length=Math.max(this.length,S),f!==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 f=c.words[0]|0,h=e.words[0]|0,g=f*h,S=g&67108863,p=g/67108864|0;o.words[0]=S;for(var a=1;a<l;a++){for(var y=p>>>26,D=p&67108863,R=Math.min(a,e.length-1),T=Math.max(0,a-c.length+1);T<=R;T++){var q=a-T|0;f=c.words[q]|0,h=e.words[T]|0,g=f*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 j=function(e,o,l){var f=e.words,h=o.words,g=l.words,S=0,p,a,y,D=f[0]|0,R=D&8191,T=D>>>13,q=f[1]|0,X=q&8191,ee=q>>>13,He=f[2]|0,Q=He&8191,te=He>>>13,ze=f[3]|0,Y=ze&8191,W=ze>>>13,vi=f[4]|0,oe=vi&8191,se=vi>>>13,wi=f[5]|0,ae=wi&8191,le=wi>>>13,Mi=f[6]|0,ue=Mi&8191,fe=Mi>>>13,yi=f[7]|0,he=yi&8191,ce=yi>>>13,bi=f[8]|0,de=bi&8191,pe=bi>>>13,_i=f[9]|0,ge=_i&8191,me=_i>>>13,ki=h[0]|0,ve=ki&8191,we=ki>>>13,Si=h[1]|0,Me=Si&8191,ye=Si>>>13,Ci=h[2]|0,be=Ci&8191,_e=Ci>>>13,Ai=h[3]|0,ke=Ai&8191,Se=Ai>>>13,Pi=h[4]|0,Ce=Pi&8191,Ae=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(R,ve),a=Math.imul(R,we),a=a+Math.imul(T,ve)|0,y=Math.imul(T,we);var Et=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Et>>>26)|0,Et&=67108863,p=Math.imul(X,ve),a=Math.imul(X,we),a=a+Math.imul(ee,ve)|0,y=Math.imul(ee,we),p=p+Math.imul(R,Me)|0,a=a+Math.imul(R,ye)|0,a=a+Math.imul(T,Me)|0,y=y+Math.imul(T,ye)|0;var Bt=(S+p|0)+((a&8191)<<13)|0;S=(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(X,Me)|0,a=a+Math.imul(X,ye)|0,a=a+Math.imul(ee,Me)|0,y=y+Math.imul(ee,ye)|0,p=p+Math.imul(R,be)|0,a=a+Math.imul(R,_e)|0,a=a+Math.imul(T,be)|0,y=y+Math.imul(T,_e)|0;var Ft=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Ft>>>26)|0,Ft&=67108863,p=Math.imul(Y,ve),a=Math.imul(Y,we),a=a+Math.imul(W,ve)|0,y=Math.imul(W,we),p=p+Math.imul(Q,Me)|0,a=a+Math.imul(Q,ye)|0,a=a+Math.imul(te,Me)|0,y=y+Math.imul(te,ye)|0,p=p+Math.imul(X,be)|0,a=a+Math.imul(X,_e)|0,a=a+Math.imul(ee,be)|0,y=y+Math.imul(ee,_e)|0,p=p+Math.imul(R,ke)|0,a=a+Math.imul(R,Se)|0,a=a+Math.imul(T,ke)|0,y=y+Math.imul(T,Se)|0;var qt=(S+p|0)+((a&8191)<<13)|0;S=(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(W,Me)|0,y=y+Math.imul(W,ye)|0,p=p+Math.imul(Q,be)|0,a=a+Math.imul(Q,_e)|0,a=a+Math.imul(te,be)|0,y=y+Math.imul(te,_e)|0,p=p+Math.imul(X,ke)|0,a=a+Math.imul(X,Se)|0,a=a+Math.imul(ee,ke)|0,y=y+Math.imul(ee,Se)|0,p=p+Math.imul(R,Ce)|0,a=a+Math.imul(R,Ae)|0,a=a+Math.imul(T,Ce)|0,y=y+Math.imul(T,Ae)|0;var Ut=(S+p|0)+((a&8191)<<13)|0;S=(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(W,be)|0,y=y+Math.imul(W,_e)|0,p=p+Math.imul(Q,ke)|0,a=a+Math.imul(Q,Se)|0,a=a+Math.imul(te,ke)|0,y=y+Math.imul(te,Se)|0,p=p+Math.imul(X,Ce)|0,a=a+Math.imul(X,Ae)|0,a=a+Math.imul(ee,Ce)|0,y=y+Math.imul(ee,Ae)|0,p=p+Math.imul(R,Pe)|0,a=a+Math.imul(R,xe)|0,a=a+Math.imul(T,Pe)|0,y=y+Math.imul(T,xe)|0;var jt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(jt>>>26)|0,jt&=67108863,p=Math.imul(ue,ve),a=Math.imul(ue,we),a=a+Math.imul(fe,ve)|0,y=Math.imul(fe,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,Se)|0,a=a+Math.imul(W,ke)|0,y=y+Math.imul(W,Se)|0,p=p+Math.imul(Q,Ce)|0,a=a+Math.imul(Q,Ae)|0,a=a+Math.imul(te,Ce)|0,y=y+Math.imul(te,Ae)|0,p=p+Math.imul(X,Pe)|0,a=a+Math.imul(X,xe)|0,a=a+Math.imul(ee,Pe)|0,y=y+Math.imul(ee,xe)|0,p=p+Math.imul(R,Le)|0,a=a+Math.imul(R,Ie)|0,a=a+Math.imul(T,Le)|0,y=y+Math.imul(T,Ie)|0;var Zt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Zt>>>26)|0,Zt&=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(ue,Me)|0,a=a+Math.imul(ue,ye)|0,a=a+Math.imul(fe,Me)|0,y=y+Math.imul(fe,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,Se)|0,a=a+Math.imul(se,ke)|0,y=y+Math.imul(se,Se)|0,p=p+Math.imul(Y,Ce)|0,a=a+Math.imul(Y,Ae)|0,a=a+Math.imul(W,Ce)|0,y=y+Math.imul(W,Ae)|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(X,Le)|0,a=a+Math.imul(X,Ie)|0,a=a+Math.imul(ee,Le)|0,y=y+Math.imul(ee,Ie)|0,p=p+Math.imul(R,Oe)|0,a=a+Math.imul(R,Ne)|0,a=a+Math.imul(T,Oe)|0,y=y+Math.imul(T,Ne)|0;var zt=(S+p|0)+((a&8191)<<13)|0;S=(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(ue,be)|0,a=a+Math.imul(ue,_e)|0,a=a+Math.imul(fe,be)|0,y=y+Math.imul(fe,_e)|0,p=p+Math.imul(ae,ke)|0,a=a+Math.imul(ae,Se)|0,a=a+Math.imul(le,ke)|0,y=y+Math.imul(le,Se)|0,p=p+Math.imul(oe,Ce)|0,a=a+Math.imul(oe,Ae)|0,a=a+Math.imul(se,Ce)|0,y=y+Math.imul(se,Ae)|0,p=p+Math.imul(Y,Pe)|0,a=a+Math.imul(Y,xe)|0,a=a+Math.imul(W,Pe)|0,y=y+Math.imul(W,xe)|0,p=p+Math.imul(Q,Le)|0,a=a+Math.imul(Q,Ie)|0,a=a+Math.imul(te,Le)|0,y=y+Math.imul(te,Ie)|0,p=p+Math.imul(X,Oe)|0,a=a+Math.imul(X,Ne)|0,a=a+Math.imul(ee,Oe)|0,y=y+Math.imul(ee,Ne)|0,p=p+Math.imul(R,Re)|0,a=a+Math.imul(R,Te)|0,a=a+Math.imul(T,Re)|0,y=y+Math.imul(T,Te)|0;var $t=(S+p|0)+((a&8191)<<13)|0;S=(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(ue,ke)|0,a=a+Math.imul(ue,Se)|0,a=a+Math.imul(fe,ke)|0,y=y+Math.imul(fe,Se)|0,p=p+Math.imul(ae,Ce)|0,a=a+Math.imul(ae,Ae)|0,a=a+Math.imul(le,Ce)|0,y=y+Math.imul(le,Ae)|0,p=p+Math.imul(oe,Pe)|0,a=a+Math.imul(oe,xe)|0,a=a+Math.imul(se,Pe)|0,y=y+Math.imul(se,xe)|0,p=p+Math.imul(Y,Le)|0,a=a+Math.imul(Y,Ie)|0,a=a+Math.imul(W,Le)|0,y=y+Math.imul(W,Ie)|0,p=p+Math.imul(Q,Oe)|0,a=a+Math.imul(Q,Ne)|0,a=a+Math.imul(te,Oe)|0,y=y+Math.imul(te,Ne)|0,p=p+Math.imul(X,Re)|0,a=a+Math.imul(X,Te)|0,a=a+Math.imul(ee,Re)|0,y=y+Math.imul(ee,Te)|0,p=p+Math.imul(R,De)|0,a=a+Math.imul(R,Ee)|0,a=a+Math.imul(T,De)|0,y=y+Math.imul(T,Ee)|0;var Kt=(S+p|0)+((a&8191)<<13)|0;S=(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,Se)|0,a=a+Math.imul(ce,ke)|0,y=y+Math.imul(ce,Se)|0,p=p+Math.imul(ue,Ce)|0,a=a+Math.imul(ue,Ae)|0,a=a+Math.imul(fe,Ce)|0,y=y+Math.imul(fe,Ae)|0,p=p+Math.imul(ae,Pe)|0,a=a+Math.imul(ae,xe)|0,a=a+Math.imul(le,Pe)|0,y=y+Math.imul(le,xe)|0,p=p+Math.imul(oe,Le)|0,a=a+Math.imul(oe,Ie)|0,a=a+Math.imul(se,Le)|0,y=y+Math.imul(se,Ie)|0,p=p+Math.imul(Y,Oe)|0,a=a+Math.imul(Y,Ne)|0,a=a+Math.imul(W,Oe)|0,y=y+Math.imul(W,Ne)|0,p=p+Math.imul(Q,Re)|0,a=a+Math.imul(Q,Te)|0,a=a+Math.imul(te,Re)|0,y=y+Math.imul(te,Te)|0,p=p+Math.imul(X,De)|0,a=a+Math.imul(X,Ee)|0,a=a+Math.imul(ee,De)|0,y=y+Math.imul(ee,Ee)|0;var Ht=(S+p|0)+((a&8191)<<13)|0;S=(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,Se)|0,a=a+Math.imul(pe,ke)|0,y=y+Math.imul(pe,Se)|0,p=p+Math.imul(he,Ce)|0,a=a+Math.imul(he,Ae)|0,a=a+Math.imul(ce,Ce)|0,y=y+Math.imul(ce,Ae)|0,p=p+Math.imul(ue,Pe)|0,a=a+Math.imul(ue,xe)|0,a=a+Math.imul(fe,Pe)|0,y=y+Math.imul(fe,xe)|0,p=p+Math.imul(ae,Le)|0,a=a+Math.imul(ae,Ie)|0,a=a+Math.imul(le,Le)|0,y=y+Math.imul(le,Ie)|0,p=p+Math.imul(oe,Oe)|0,a=a+Math.imul(oe,Ne)|0,a=a+Math.imul(se,Oe)|0,y=y+Math.imul(se,Ne)|0,p=p+Math.imul(Y,Re)|0,a=a+Math.imul(Y,Te)|0,a=a+Math.imul(W,Re)|0,y=y+Math.imul(W,Te)|0,p=p+Math.imul(Q,De)|0,a=a+Math.imul(Q,Ee)|0,a=a+Math.imul(te,De)|0,y=y+Math.imul(te,Ee)|0;var Wt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,p=Math.imul(ge,ke),a=Math.imul(ge,Se),a=a+Math.imul(me,ke)|0,y=Math.imul(me,Se),p=p+Math.imul(de,Ce)|0,a=a+Math.imul(de,Ae)|0,a=a+Math.imul(pe,Ce)|0,y=y+Math.imul(pe,Ae)|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(ue,Le)|0,a=a+Math.imul(ue,Ie)|0,a=a+Math.imul(fe,Le)|0,y=y+Math.imul(fe,Ie)|0,p=p+Math.imul(ae,Oe)|0,a=a+Math.imul(ae,Ne)|0,a=a+Math.imul(le,Oe)|0,y=y+Math.imul(le,Ne)|0,p=p+Math.imul(oe,Re)|0,a=a+Math.imul(oe,Te)|0,a=a+Math.imul(se,Re)|0,y=y+Math.imul(se,Te)|0,p=p+Math.imul(Y,De)|0,a=a+Math.imul(Y,Ee)|0,a=a+Math.imul(W,De)|0,y=y+Math.imul(W,Ee)|0;var Gt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,p=Math.imul(ge,Ce),a=Math.imul(ge,Ae),a=a+Math.imul(me,Ce)|0,y=Math.imul(me,Ae),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(ue,Oe)|0,a=a+Math.imul(ue,Ne)|0,a=a+Math.imul(fe,Oe)|0,y=y+Math.imul(fe,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=(S+p|0)+((a&8191)<<13)|0;S=(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(ue,Re)|0,a=a+Math.imul(ue,Te)|0,a=a+Math.imul(fe,Re)|0,y=y+Math.imul(fe,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=(S+p|0)+((a&8191)<<13)|0;S=(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(ue,De)|0,a=a+Math.imul(ue,Ee)|0,a=a+Math.imul(fe,De)|0,y=y+Math.imul(fe,Ee)|0;var Qt=(S+p|0)+((a&8191)<<13)|0;S=(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=(S+p|0)+((a&8191)<<13)|0;S=(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=(S+p|0)+((a&8191)<<13)|0;S=(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=(S+p|0)+((a&8191)<<13)|0;return S=(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]=jt,g[6]=Zt,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,S!==0&&(g[19]=S,l.length++),l};Math.imul||(j=U);function I(c,e,o){o.negative=e.negative^c.negative,o.length=c.length+e.length;for(var l=0,f=0,h=0;h<o.length-1;h++){var g=f;f=0;for(var S=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,R=e.words[a]|0,T=D*R,q=T&67108863;g=g+(T/67108864|0)|0,q=q+S|0,S=q&67108863,g=g+(q>>>26)|0,f+=g>>>26,g&=67108863}o.words[h]=S,l=g,g=f}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,f=this.length+e.length;return this.length===10&&e.length===10?l=j(this,e,o):f<63?l=U(this,e,o):f<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,f=0;f<e;f++)o[f]=this.revBin(f,l,e);return o},F.prototype.revBin=function(e,o,l){if(e===0||e===l-1)return e;for(var f=0,h=0;h<o;h++)f|=(e&1)<<o-h-1,e>>=1;return f},F.prototype.permute=function(e,o,l,f,h,g){for(var S=0;S<g;S++)f[S]=o[e[S]],h[S]=l[e[S]]},F.prototype.transform=function(e,o,l,f,h,g){this.permute(g,e,o,l,f,h);for(var S=1;S<h;S<<=1)for(var p=S<<1,a=Math.cos(2*Math.PI/p),y=Math.sin(2*Math.PI/p),D=0;D<h;D+=p)for(var R=a,T=y,q=0;q<S;q++){var X=l[D+q],ee=f[D+q],He=l[D+q+S],Q=f[D+q+S],te=R*He-T*Q;Q=R*Q+T*He,He=te,l[D+q]=X+He,f[D+q]=ee+Q,l[D+q+S]=X-He,f[D+q+S]=ee-Q,q!==p&&(te=a*R-y*T,T=a*T+y*R,R=te)}},F.prototype.guessLen13b=function(e,o){var l=Math.max(o,e)|1,f=l&1,h=0;for(l=l/2|0;l;l=l>>>1)h++;return 1<<h+1+f},F.prototype.conjugate=function(e,o,l){if(!(l<=1))for(var f=0;f<l/2;f++){var h=e[f];e[f]=e[l-f-1],e[l-f-1]=h,h=o[f],o[f]=-o[l-f-1],o[l-f-1]=-h}},F.prototype.normalize13b=function(e,o){for(var l=0,f=0;f<o/2;f++){var h=Math.round(e[2*f+1]/o)*8192+Math.round(e[2*f]/o)+l;e[f]=h&67108863,h<67108864?l=0:l=h/67108864|0}return e},F.prototype.convert13b=function(e,o,l,f){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<f;++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 f=2*this.guessLen13b(e.length,o.length),h=this.makeRBT(f),g=this.stub(f),S=new Array(f),p=new Array(f),a=new Array(f),y=new Array(f),D=new Array(f),R=new Array(f),T=l.words;T.length=f,this.convert13b(e.words,e.length,S,f),this.convert13b(o.words,o.length,y,f),this.transform(S,g,p,a,f,h),this.transform(y,g,D,R,f,h);for(var q=0;q<f;q++){var X=p[q]*D[q]-a[q]*R[q];a[q]=p[q]*R[q]+a[q]*D[q],p[q]=X}return this.conjugate(p,a,f),this.transform(p,a,T,g,f,h),this.conjugate(T,g,f),this.normalize13b(T,f),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,f=0;f<this.length;f++){var h=(this.words[f]|0)*e,g=(h&67108863)+(l&67108863);l>>=26,l+=h/67108864|0,l+=g>>>26,this.words[f]=g&67108863}return l!==0&&(this.words[f]=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=N(e);if(o.length===0)return new t(1);for(var l=this,f=0;f<o.length&&o[f]===0;f++,l=l.sqr());if(++f<o.length)for(var h=l.sqr();f<o.length;f++,h=h.sqr())o[f]!==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,f=67108863>>>26-o<<26-o,h;if(o!==0){var g=0;for(h=0;h<this.length;h++){var S=this.words[h]&f,p=(this.words[h]|0)-S<<o;this.words[h]=p|g,g=S>>>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 f;o?f=(o-o%26)/26:f=0;var h=e%26,g=Math.min((e-h)/26,this.length),S=67108863^67108863>>>h<<h,p=l;if(f-=g,f=Math.max(0,f),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>=f);a--){var D=this.words[a]|0;this.words[a]=y<<26-h|D>>>h,y=D&S}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,f=1<<o;if(this.length<=l)return!1;var h=this.words[l];return!!(h&f)},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 f=67108863^67108863>>>o<<o;this.words[this.length-1]&=f}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 f=e.length+l,h;this._expand(f);var g,S=0;for(h=0;h<e.length;h++){g=(this.words[h+l]|0)+S;var p=(e.words[h]|0)*o;g-=p&67108863,S=(g>>26)-(p/67108864|0),this.words[h+l]=g&67108863}for(;h<this.length-l;h++)g=(this.words[h+l]|0)+S,S=g>>26,this.words[h+l]=g&67108863;if(S===0)return this._strip();for(n(S===-1),S=0,h=0;h<this.length;h++)g=-(this.words[h]|0)+S,S=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,f=this.clone(),h=e,g=h.words[h.length-1]|0,S=this._countBits(g);l=26-S,l!==0&&(h=h.ushln(l),f.iushln(l),g=h.words[h.length-1]|0);var p=f.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=f.clone()._ishlnsubmul(h,1,p);D.negative===0&&(f=D,a&&(a.words[p]=1));for(var R=p-1;R>=0;R--){var T=(f.words[h.length+R]|0)*67108864+(f.words[h.length+R-1]|0);for(T=Math.min(T/g|0,67108863),f._ishlnsubmul(h,T,R);f.negative!==0;)T--,f.negative=0,f._ishlnsubmul(h,1,R),f.isZero()||(f.negative^=1);a&&(a.words[R]=T)}return a&&a._strip(),f._strip(),o!=="div"&&l!==0&&f.iushrn(l),{div:a||null,mod:f}},t.prototype.divmod=function(e,o,l){if(n(!e.isZero()),this.isZero())return{div:new t(0),mod:new t(0)};var f,h,g;return this.negative!==0&&e.negative===0?(g=this.neg().divmod(e,o),o!=="mod"&&(f=g.div.neg()),o!=="div"&&(h=g.mod.neg(),l&&h.negative!==0&&h.iadd(e)),{div:f,mod:h}):this.negative===0&&e.negative!==0?(g=this.divmod(e.neg(),o),o!=="mod"&&(f=g.div.neg()),{div:f,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,f=e.ushrn(1),h=e.andln(1),g=l.cmp(f);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,f=0,h=this.length-1;h>=0;h--)f=(l*f+(this.words[h]|0))%e;return o?-f:f},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,f=this.length-1;f>=0;f--){var h=(this.words[f]|0)+l*67108864;this.words[f]=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 f=new t(1),h=new t(0),g=new t(0),S=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,R=1;(o.words[0]&R)===0&&D<26;++D,R<<=1);if(D>0)for(o.iushrn(D);D-- >0;)(f.isOdd()||h.isOdd())&&(f.iadd(a),h.isub(y)),f.iushrn(1),h.iushrn(1);for(var T=0,q=1;(l.words[0]&q)===0&&T<26;++T,q<<=1);if(T>0)for(l.iushrn(T);T-- >0;)(g.isOdd()||S.isOdd())&&(g.iadd(a),S.isub(y)),g.iushrn(1),S.iushrn(1);o.cmp(l)>=0?(o.isub(l),f.isub(g),h.isub(S)):(l.isub(o),g.isub(f),S.isub(h))}return{a:g,b:S,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 f=new t(1),h=new t(0),g=l.clone();o.cmpn(1)>0&&l.cmpn(1)>0;){for(var S=0,p=1;(o.words[0]&p)===0&&S<26;++S,p<<=1);if(S>0)for(o.iushrn(S);S-- >0;)f.isOdd()&&f.iadd(g),f.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),f.isub(h)):(l.isub(o),h.isub(f))}var D;return o.cmpn(1)===0?D=f: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 f=0;o.isEven()&&l.isEven();f++)o.iushrn(1),l.iushrn(1);do{for(;o.isEven();)o.iushrn(1);for(;l.isEven();)l.iushrn(1);var 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(f)},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,f=1<<o;if(this.length<=l)return this._expand(l+1),this.words[l]|=f,this;for(var h=f,g=l;h!==0&&g<this.length;g++){var S=this.words[g]|0;S+=h,h=S>>>26,S&=67108863,this.words[g]=S}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 f=this.words[0]|0;l=f===e?0:f<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 f=this.words[l]|0,h=e.words[l]|0;if(f!==h){f<h?o=-1:f>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 x(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 J={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 f=l<this.n?-1:o.ucmp(this.p);return f===0?(o.words[0]=0,o.length=1):f>0?o.isub(this.p):o.strip!==void 0?o.strip():o._strip(),o},z.prototype.split=function(e,o){e.iushrn(this.n,0,o)},z.prototype.imulK=function(e){return e.imul(this.k)};function V(){z.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(V,z),V.prototype.split=function(e,o){for(var l=4194303,f=Math.min(e.length,9),h=0;h<f;h++)o.words[h]=e.words[h];if(o.length=f,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 S=e.words[h]|0;e.words[h-10]=(S&l)<<4|g>>>22,g=S}g>>>=22,e.words[h-10]=g,g===0&&e.length>10?e.length-=10:e.length-=9},V.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var o=0,l=0;l<e.length;l++){var f=e.words[l]|0;o+=f*977,e.words[l]=o&67108863,o=f*64+(o/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function 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 k(){z.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(k,z),k.prototype.imulK=function(e){for(var o=0,l=0;l<e.length;l++){var f=(e.words[l]|0)*19+o,h=f&67108863;f>>>=26,e.words[l]=h,o=f}return o!==0&&(e.words[e.length++]=o),e},t._prime=function(e){if(J[e])return J[e];var o;if(e==="k256")o=new V;else if(e==="p224")o=new m;else if(e==="p192")o=new b;else if(e==="p25519")o=new k;else throw new Error("Unknown prime "+e);return J[e]=o,o};function x(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}x.prototype._verify1=function(e){n(e.negative===0,"red works only with positives"),n(e.red,"red works only with red numbers")},x.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")},x.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(M(e,e.umod(this.m)._forceRed(this)),e)},x.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},x.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)},x.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},x.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)},x.prototype.isub=function(e,o){this._verify2(e,o);var l=e.isub(o);return l.cmpn(0)<0&&l.iadd(this.m),l},x.prototype.shl=function(e,o){return this._verify1(e),this.imod(e.ushln(o))},x.prototype.imul=function(e,o){return this._verify2(e,o),this.imod(e.imul(o))},x.prototype.mul=function(e,o){return this._verify2(e,o),this.imod(e.mul(o))},x.prototype.isqr=function(e){return this.imul(e,e.clone())},x.prototype.sqr=function(e){return this.mul(e,e)},x.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 f=this.m.subn(1),h=0;!f.isZero()&&f.andln(1)===0;)h++,f.iushrn(1);n(!f.isZero());var g=new t(1).toRed(this),S=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(S)!==0;)a.redIAdd(S);for(var y=this.pow(a,f),D=this.pow(e,f.addn(1).iushrn(1)),R=this.pow(e,f),T=h;R.cmp(g)!==0;){for(var q=R,X=0;q.cmp(g)!==0;X++)q=q.redSqr();n(X<T);var ee=this.pow(y,new t(1).iushln(T-X-1));D=D.redMul(ee),y=ee.redSqr(),R=R.redMul(y),T=X}return D},x.prototype.invm=function(e){var o=e._invmp(this.m);return o.negative!==0?(o.negative=0,this.imod(o).redNeg()):this.imod(o)},x.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,f=new Array(1<<l);f[0]=new t(1).toRed(this),f[1]=e;for(var h=2;h<f.length;h++)f[h]=this.mul(f[h-1],e);var g=f[0],S=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 R=y>>D&1;if(g!==f[0]&&(g=this.sqr(g)),R===0&&S===0){p=0;continue}S<<=1,S|=R,p++,!(p!==l&&(h!==0||D!==0))&&(g=this.mul(g,f[S]),p=0,S=0)}a=26}return g},x.prototype.convertTo=function(e){var o=e.umod(this.m);return o===e?o.clone():o},x.prototype.convertFrom=function(e){var o=e.clone();return o.red=null,o},t.mont=function(e){return new P(e)};function P(c){x.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(P,x),P.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},P.prototype.convertFrom=function(e){var o=this.imod(e.mul(this.rinv));return o.red=null,o},P.prototype.imul=function(e,o){if(e.isZero()||o.isZero())return e.words[0]=0,e.length=1,e;var l=e.imul(o),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).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)},P.prototype.mul=function(e,o){if(e.isZero()||o.isZero())return new t(0)._forceRed(this);var l=e.mul(o),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).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)},P.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 Ar,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:Ar,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 jr,formatRewards as Zr,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,G=14,ii=9007199254740991,ri=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],ot=1e7,qe=1e9;function Ei(i){var r,n,s,t=I.prototype={constructor:I,toString:null,valueOf:null},u=new I(1),d=20,v=4,w=-7,M=21,_=-1e7,C=1e7,A=!1,L=1,E=0,N={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},U="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function I(m,b){var k,x,P,c,e,o,l,f,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>C?h.c=h.e=null:m.e<_?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>C?h.c=h.e=null:(h.e=c,h.c=[m]);return}f=String(m)}else{if(!xr.test(f=String(m)))return s(h,f,o);h.s=f.charCodeAt(0)==45?(f=f.slice(1),-1):1}(c=f.indexOf("."))>-1&&(f=f.replace(".","")),(e=f.search(/e/i))>0?(c<0&&(c=e),c+=+f.slice(e+1),f=f.substring(0,e)):c<0&&(c=f.length)}else{if(ne(b,2,U.length,"Base"),b==10&&j)return h=new I(m),z(h,d+h.e+1,v);if(f=String(m),o=typeof m=="number"){if(m*0!=0)return s(h,f,o,b);if(h.s=1/m<0?(f=f.slice(1),-1):1,I.DEBUG&&f.replace(/^0\.0*|\./,"").length>15)throw Error(Di+m)}else h.s=f.charCodeAt(0)===45?(f=f.slice(1),-1):1;for(k=U.slice(0,b),c=e=0,l=f.length;e<l;e++)if(k.indexOf(x=f.charAt(e))<0){if(x=="."){if(e>c){c=l;continue}}else if(!P&&(f==f.toUpperCase()&&(f=f.toLowerCase())||f==f.toLowerCase()&&(f=f.toUpperCase()))){P=!0,e=-1,c=0;continue}return s(h,String(m),o,b)}o=!1,f=n(f,b,10,h.s),(c=f.indexOf("."))>-1?f=f.replace(".",""):c=f.length}for(e=0;f.charCodeAt(e)===48;e++);for(l=f.length;f.charCodeAt(--l)===48;);if(f=f.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)>C)h.c=h.e=null;else if(c<_)h.c=[h.e=0];else{if(h.e=c,h.c=[],e=(c+1)%G,c<0&&(e+=G),e<l){for(e&&h.c.push(+f.slice(0,e)),l-=G;e<l;)h.c.push(+f.slice(e,e+=G));e=G-(f=f.slice(e)).length}else e-=l;for(;e--;f+="0");h.c.push(+f)}}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,k;if(m!=null)if(typeof m=="object"){if(m.hasOwnProperty(b="DECIMAL_PLACES")&&(k=m[b],ne(k,0,qe,b),d=k),m.hasOwnProperty(b="ROUNDING_MODE")&&(k=m[b],ne(k,0,8,b),v=k),m.hasOwnProperty(b="EXPONENTIAL_AT")&&(k=m[b],k&&k.pop?(ne(k[0],-qe,0,b),ne(k[1],0,qe,b),w=k[0],M=k[1]):(ne(k,-qe,qe,b),w=-(M=k<0?-k:k))),m.hasOwnProperty(b="RANGE"))if(k=m[b],k&&k.pop)ne(k[0],-qe,-1,b),ne(k[1],1,qe,b),_=k[0],C=k[1];else if(ne(k,-qe,qe,b),k)_=-(C=k<0?-k:k);else throw Error($e+b+" cannot be zero: "+k);if(m.hasOwnProperty(b="CRYPTO"))if(k=m[b],k===!!k)if(k)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))A=k;else throw A=!k,Error($e+"crypto unavailable");else A=k;else throw Error($e+b+" not true or false: "+k);if(m.hasOwnProperty(b="MODULO_MODE")&&(k=m[b],ne(k,0,9,b),L=k),m.hasOwnProperty(b="POW_PRECISION")&&(k=m[b],ne(k,0,qe,b),E=k),m.hasOwnProperty(b="FORMAT"))if(k=m[b],typeof k=="object")N=k;else throw Error($e+b+" not an object: "+k);if(m.hasOwnProperty(b="ALPHABET"))if(k=m[b],typeof k=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(k))j=k.slice(0,10)=="0123456789",U=k;else throw Error($e+b+" invalid: "+k)}else throw Error($e+"Object expected: "+m);return{DECIMAL_PLACES:d,ROUNDING_MODE:v,EXPONENTIAL_AT:[w,M],RANGE:[_,C],CRYPTO:A,MODULO_MODE:L,POW_PRECISION:E,FORMAT:N,ALPHABET:U}},I.isBigNumber=function(m){if(!m||m._isBigNumber!==!0)return!1;if(!I.DEBUG)return!0;var b,k,x=m.c,P=m.e,c=m.s;e:if({}.toString.call(x)=="[object Array]"){if((c===1||c===-1)&&P>=-qe&&P<=qe&&P===Ge(P)){if(x[0]===0){if(P===0&&x.length===1)return!0;break e}if(b=(P+1)%G,b<1&&(b+=G),String(x[0]).length==b){for(b=0;b<x.length;b++)if(k=x[b],k<0||k>=Xe||k!==Ge(k))break e;if(k!==0)return!0}}}else if(x===null&&P===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(k){var x,P,c,e,o,l=0,f=[],h=new I(u);if(k==null?k=d:ne(k,0,qe),e=ti(k/G),A)if(crypto.getRandomValues){for(x=crypto.getRandomValues(new Uint32Array(e*=2));l<e;)o=x[l]*131072+(x[l+1]>>>11),o>=9e15?(P=crypto.getRandomValues(new Uint32Array(2)),x[l]=P[0],x[l+1]=P[1]):(f.push(o%1e14),l+=2);l=e/2}else if(crypto.randomBytes){for(x=crypto.randomBytes(e*=7);l<e;)o=(x[l]&31)*281474976710656+x[l+1]*1099511627776+x[l+2]*4294967296+x[l+3]*16777216+(x[l+4]<<16)+(x[l+5]<<8)+x[l+6],o>=9e15?crypto.randomBytes(7).copy(x,l):(f.push(o%1e14),l+=7);l=e/7}else throw A=!1,Error($e+"crypto unavailable");if(!A)for(;l<e;)o=b(),o<9e15&&(f[l++]=o%1e14);for(e=f[--l],k%=G,e&&k&&(o=ri[G-k],f[l]=Ge(e/o)*o);f[l]===0;f.pop(),l--);if(l<0)f=[c=0];else{for(c=-1;f[0]===0;f.splice(0,1),c-=G);for(l=1,o=f[0];o>=10;o/=10,l++);l<G&&(c-=G-l)}return h.e=c,h.c=f,h}})(),I.sum=function(){for(var m=1,b=arguments,k=new I(b[0]);m<b.length;)k=k.plus(b[m++]);return k},n=(function(){var m="0123456789";function b(k,x,P,c){for(var e,o=[0],l,f=0,h=k.length;f<h;){for(l=o.length;l--;o[l]*=x);for(o[0]+=c.indexOf(k.charAt(f++)),e=0;e<o.length;e++)o[e]>P-1&&(o[e+1]==null&&(o[e+1]=0),o[e+1]+=o[e]/P|0,o[e]%=P)}return o.reverse()}return function(k,x,P,c,e){var o,l,f,h,g,S,p,a,y=k.indexOf("."),D=d,R=v;for(y>=0&&(h=E,E=0,k=k.replace(".",""),a=new I(x),S=a.pow(k.length-y),E=h,a.c=b(rt(We(S.c),S.e,"0"),10,P,m),a.e=a.c.length),p=b(k,x,P,e?(o=U,m):(o=m,U)),f=h=p.length;p[--h]==0;p.pop());if(!p[0])return o.charAt(0);if(y<0?--f:(S.c=p,S.e=f,S.s=c,S=r(S,a,D,R,P),p=S.c,g=S.r,f=S.e),l=f+D+1,y=p[l],h=P/2,g=g||l<0||p[l+1]!=null,g=R<4?(y!=null||g)&&(R==0||R==(S.s<0?3:2)):y>h||y==h&&(R==4||g||R==6&&p[l-1]&1||R==(S.s<0?8:7)),l<1||!p[0])k=g?rt(o.charAt(1),-D,o.charAt(0)):o.charAt(0);else{if(p.length=l,g)for(--P;++p[--l]>P;)p[l]=0,l||(++f,p=[1].concat(p));for(h=p.length;!p[--h];);for(y=0,k="";y<=h;k+=o.charAt(p[y++]));k=rt(k,f,o.charAt(0))}return k}})(),r=(function(){function m(x,P,c){var e,o,l,f,h=0,g=x.length,S=P%ot,p=P/ot|0;for(x=x.slice();g--;)l=x[g]%ot,f=x[g]/ot|0,e=p*l+f*S,o=S*l+e%ot*ot+h,h=(o/c|0)+(e/ot|0)+p*f,x[g]=o%c;return h&&(x=[h].concat(x)),x}function b(x,P,c,e){var o,l;if(c!=e)l=c>e?1:-1;else for(o=l=0;o<c;o++)if(x[o]!=P[o]){l=x[o]>P[o]?1:-1;break}return l}function k(x,P,c,e){for(var o=0;c--;)x[c]-=o,o=x[c]<P[c]?1:0,x[c]=o*e+x[c]-P[c];for(;!x[0]&&x.length>1;x.splice(0,1));}return function(x,P,c,e,o){var l,f,h,g,S,p,a,y,D,R,T,q,X,ee,He,Q,te,ze=x.s==P.s?1:-1,Y=x.c,W=P.c;if(!Y||!Y[0]||!W||!W[0])return new I(!x.s||!P.s||(Y?W&&Y[0]==W[0]:!W)?NaN:Y&&Y[0]==0||!W?ze*0:ze/0);for(y=new I(ze),D=y.c=[],f=x.e-P.e,ze=c+f+1,o||(o=Xe,f=Ve(x.e/G)-Ve(P.e/G),ze=ze/G|0),h=0;W[h]==(Y[h]||0);h++);if(W[h]>(Y[h]||0)&&f--,ze<0)D.push(1),g=!0;else{for(ee=Y.length,Q=W.length,h=0,ze+=2,S=Ge(o/(W[0]+1)),S>1&&(W=m(W,S,o),Y=m(Y,S,o),Q=W.length,ee=Y.length),X=Q,R=Y.slice(0,Q),T=R.length;T<Q;R[T++]=0);te=W.slice(),te=[0].concat(te),He=W[0],W[1]>=o/2&&He++;do{if(S=0,l=b(W,R,Q,T),l<0){if(q=R[0],Q!=T&&(q=q*o+(R[1]||0)),S=Ge(q/He),S>1)for(S>=o&&(S=o-1),p=m(W,S,o),a=p.length,T=R.length;b(p,R,a,T)==1;)S--,k(p,Q<a?te:W,a,o),a=p.length,l=1;else S==0&&(l=S=1),p=W.slice(),a=p.length;if(a<T&&(p=[0].concat(p)),k(R,p,T,o),T=R.length,l==-1)for(;b(W,R,Q,T)<1;)S++,k(R,Q<T?te:W,T,o),T=R.length}else l===0&&(S++,R=[0]);D[h++]=S,R[0]?R[T++]=Y[X]||0:(R=[Y[X]],T=1)}while((X++<ee||R[0]!=null)&&ze--);g=R[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+f*G-1)+1,e,g)}else y.e=f,y.r=+g;return y}})();function B(m,b,k,x){var P,c,e,o,l;if(k==null?k=v:ne(k,0,8),!m.c)return m.toString();if(P=m.c[0],e=m.e,b==null)l=We(m.c),l=x==1||x==2&&(e<=w||e>=M)?bt(l,e):rt(l,e,"0");else if(m=z(new I(m),b,k),c=m.e,l=We(m.c),o=l.length,x==1||x==2&&(b<=c||c<=w)){for(;o<b;l+="0",o++);l=bt(l,c)}else if(b-=e+(x===2&&c>e),l=rt(l,c,"0"),c+1>o){if(--b>0)for(l+=".";b--;l+="0");}else if(b+=c-o,b>0)for(c+1==o&&(l+=".");b--;l+="0");return m.s<0&&P?"-"+l:l}function F(m,b){for(var k,x,P=1,c=new I(m[0]);P<m.length;P++)x=new I(m[P]),(!x.s||(k=ht(c,x))===b||k===0&&c.s===b)&&(c=x);return c}function J(m,b,k){for(var x=1,P=b.length;!b[--P];b.pop());for(P=b[0];P>=10;P/=10,x++);return(k=x+k*G-1)>C?m.c=m.e=null:k<_?m.c=[m.e=0]:(m.e=k,m.c=b),m}s=(function(){var m=/^(-?)0([xbo])(?=\w[\w.]*$)/i,b=/^([^.]+)\.$/,k=/^\.([^.]+)$/,x=/^-?(Infinity|NaN)$/,P=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(c,e,o,l){var f,h=o?e:e.replace(P,"");if(x.test(h))c.s=isNaN(h)?null:h<0?-1:1;else{if(!o&&(h=h.replace(m,function(g,S,p){return f=(p=p.toLowerCase())=="x"?16:p=="b"?2:8,!l||l==f?S:g}),l&&(f=l,h=h.replace(b,"$1").replace(k,"0.$1")),e!=h))return new I(h,f);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,k,x){var P,c,e,o,l,f,h,g=m.c,S=ri;if(g){e:{for(P=1,o=g[0];o>=10;o/=10,P++);if(c=b-P,c<0)c+=G,e=b,l=g[f=0],h=Ge(l/S[P-e-1]%10);else if(f=ti((c+1)/G),f>=g.length)if(x){for(;g.length<=f;g.push(0));l=h=0,P=1,c%=G,e=c-G+1}else break e;else{for(l=o=g[f],P=1;o>=10;o/=10,P++);c%=G,e=c-G+P,h=e<0?0:Ge(l/S[P-e-1]%10)}if(x=x||b<0||g[f+1]!=null||(e<0?l:l%S[P-e-1]),x=k<4?(h||x)&&(k==0||k==(m.s<0?3:2)):h>5||h==5&&(k==4||x||k==6&&(c>0?e>0?l/S[P-e]:0:g[f-1])%10&1||k==(m.s<0?8:7)),b<1||!g[0])return g.length=0,x?(b-=m.e+1,g[0]=S[(G-b%G)%G],m.e=-b||0):g[0]=m.e=0,m;if(c==0?(g.length=f,o=1,f--):(g.length=f+1,o=S[G-c],g[f]=e>0?Ge(l/S[P-e]%S[e])*o:0),x)for(;;)if(f==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[f]+=o,g[f]!=Xe)break;g[f--]=0,o=1}for(c=g.length;g[--c]===0;g.pop());}m.e>C?m.c=m.e=null:m.e<_&&(m.c=[m.e=0])}return m}function V(m){var b,k=m.e;return k===null?m.toString():(b=We(m.c),b=k<=w||k>=M?bt(b,k):rt(b,k,"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 k,x,P,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(!(k=c.c))return null;if(x=((P=k.length-1)-Ve(this.e/G))*G,P=k[P])for(;P%10==0;P/=10,x--);return x<0&&(x=0),x},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 k,x,P,c,e,o,l,f,h,g=this;if(m=new I(m),m.c&&!m.isInteger())throw Error($e+"Exponent not an integer: "+V(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(+V(g),o?m.s*(2-yt(m)):+V(m))),b?h.mod(b):h;if(l=m.s<0,b){if(b.c?!b.c[0]:!b.s)return new I(NaN);x=!l&&g.isInteger()&&b.isInteger(),x&&(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/G+2))}for(o?(k=new I(.5),l&&(m.s=1),f=yt(m)):(P=Math.abs(+V(m)),f=P%2),h=new I(u);;){if(f){if(h=h.times(g),!h.c)break;c?h.c.length>c&&(h.c.length=c):x&&(h=h.mod(b))}if(P){if(P=Ge(P/2),P===0)break;f=P%2}else if(m=m.times(k),z(m,m.e+1,1),m.e>14)f=yt(m);else{if(P=+V(m),P===0)break;f=P%2}g=g.times(g),c?g.c&&g.c.length>c&&(g.c.length=c):x&&(g=g.mod(b))}return x?h:(l&&(h=u.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/G)>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 k,x,P,c,e=this,o=e.s;if(m=new I(m,b),b=m.s,!o||!b)return new I(NaN);if(o!=b)return m.s=-b,e.plus(m);var l=e.e/G,f=m.e/G,h=e.c,g=m.c;if(!l||!f){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),f=Ve(f),h=h.slice(),o=l-f){for((c=o<0)?(o=-o,P=h):(f=l,P=g),P.reverse(),b=o;b--;P.push(0));P.reverse()}else for(x=(c=(o=h.length)<(b=g.length))?o:b,o=b=0;b<x;b++)if(h[b]!=g[b]){c=h[b]<g[b];break}if(c&&(P=h,h=g,g=P,m.s=-m.s),b=(x=g.length)-(k=h.length),b>0)for(;b--;h[k++]=0);for(b=Xe-1;x>o;){if(h[--x]<g[x]){for(k=x;k&&!h[--k];h[k]=b);--h[k],h[x]+=Xe}h[x]-=g[x]}for(;h[0]==0;h.splice(0,1),--f);return h[0]?J(m,h,f):(m.s=v==3?-1:1,m.c=[m.e=0],m)},t.modulo=t.mod=function(m,b){var k,x,P=this;return m=new I(m,b),!P.c||!m.s||m.c&&!m.c[0]?new I(NaN):!m.c||P.c&&!P.c[0]?new I(P):(L==9?(x=m.s,m.s=1,k=r(P,m,0,3),m.s=x,k.s*=x):k=r(P,m,0,L),m=P.minus(k.times(m)),!m.c[0]&&L==1&&(m.s=P.s),m)},t.multipliedBy=t.times=function(m,b){var k,x,P,c,e,o,l,f,h,g,S,p,a,y,D,R=this,T=R.c,q=(m=new I(m,b)).c;if(!T||!q||!T[0]||!q[0])return!R.s||!m.s||T&&!T[0]&&!q||q&&!q[0]&&!T?m.c=m.e=m.s=null:(m.s*=R.s,!T||!q?m.c=m.e=null:(m.c=[0],m.e=0)),m;for(x=Ve(R.e/G)+Ve(m.e/G),m.s*=R.s,l=T.length,g=q.length,l<g&&(a=T,T=q,q=a,P=l,l=g,g=P),P=l+g,a=[];P--;a.push(0));for(y=Xe,D=ot,P=g;--P>=0;){for(k=0,S=q[P]%D,p=q[P]/D|0,e=l,c=P+e;c>P;)f=T[--e]%D,h=T[e]/D|0,o=p*f+h*S,f=S*f+o%D*D+a[c]+k,k=(f/y|0)+(o/D|0)+p*h,a[c--]=f%y;a[c]=k}return k?++x:a.splice(0,1),J(m,a,x)},t.negated=function(){var m=new I(this);return m.s=-m.s||null,m},t.plus=function(m,b){var k,x=this,P=x.s;if(m=new I(m,b),b=m.s,!P||!b)return new I(NaN);if(P!=b)return m.s=-b,x.minus(m);var c=x.e/G,e=m.e/G,o=x.c,l=m.c;if(!c||!e){if(!o||!l)return new I(P/0);if(!o[0]||!l[0])return l[0]?m:new I(o[0]?x:P*0)}if(c=Ve(c),e=Ve(e),o=o.slice(),P=c-e){for(P>0?(e=c,k=l):(P=-P,k=o),k.reverse();P--;k.push(0));k.reverse()}for(P=o.length,b=l.length,P-b<0&&(k=l,l=o,o=k,b=P),P=0;b;)P=(o[--b]=o[b]+l[b]+P)/Xe|0,o[b]=Xe===o[b]?0:o[b]%Xe;return P&&(o=[P].concat(o),++e),J(m,o,e)},t.precision=t.sd=function(m,b){var k,x,P,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(!(k=c.c))return null;if(P=k.length-1,x=P*G+1,P=k[P]){for(;P%10==0;P/=10,x--);for(P=k[0];P>=10;P/=10,x++);}return m&&c.e+1>x&&(x=c.e+1),x},t.shiftedBy=function(m){return ne(m,-ii,ii),this.times("1e"+m)},t.squareRoot=t.sqrt=function(){var m,b,k,x,P,c=this,e=c.c,o=c.s,l=c.e,f=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(+V(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),k=new I(b)):k=new I(o+""),k.c[0]){for(l=k.e,o=l+f,o<3&&(o=0);;)if(P=k,k=h.times(P.plus(r(c,P,f,1))),We(P.c).slice(0,o)===(b=We(k.c)).slice(0,o))if(k.e<l&&--o,b=b.slice(o-3,o+1),b=="9999"||!x&&b=="4999"){if(!x&&(z(P,P.e+d+2,0),P.times(P).eq(c))){k=P;break}f+=4,o+=4,x=1}else{(!+b||!+b.slice(1)&&b.charAt(0)=="5")&&(z(k,k.e+d+2,1),m=!k.times(k).eq(c));break}}return z(k,k.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,k){var x,P=this;if(k==null)m!=null&&b&&typeof b=="object"?(k=b,b=null):m&&typeof m=="object"?(k=m,m=b=null):k=N;else if(typeof k!="object")throw Error($e+"Argument not an object: "+k);if(x=P.toFixed(m,b),P.c){var c,e=x.split("."),o=+k.groupSize,l=+k.secondaryGroupSize,f=k.groupSeparator||"",h=e[0],g=e[1],S=P.s<0,p=S?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+=f+p.substr(c,o);l>0&&(h+=f+p.slice(c)),S&&(h="-"+h)}x=g?h+(k.decimalSeparator||"")+((l=+k.fractionGroupSize)?g.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(k.fractionGroupSeparator||"")):g):h}return(k.prefix||"")+x+(k.suffix||"")},t.toFraction=function(m){var b,k,x,P,c,e,o,l,f,h,g,S,p=this,a=p.c;if(m!=null&&(o=new I(m),!o.isInteger()&&(o.c||o.s!==1)||o.lt(u)))throw Error($e+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+V(o));if(!a)return new I(p);for(b=new I(u),f=k=new I(u),x=l=new I(u),S=We(a),c=b.e=S.length-p.e-1,b.c[0]=ri[(e=c%G)<0?G+e:e],m=!m||o.comparedTo(b)>0?c>0?b:f:o,e=C,C=1/0,o=new I(S),l.c[0]=0;h=r(o,b,0,1),P=k.plus(h.times(x)),P.comparedTo(m)!=1;)k=x,x=P,f=l.plus(h.times(P=f)),l=P,b=o.minus(h.times(P=b)),o=P;return P=r(m.minus(k),x,0,1),l=l.plus(P.times(f)),k=k.plus(P.times(x)),l.s=f.s=p.s,c=c*2,g=r(f,x,c,v).minus(p).abs().comparedTo(r(l,k,c,v).minus(p).abs())<1?[f,x]:[l,k],C=e,g},t.toNumber=function(){return+V(this)},t.toPrecision=function(m,b){return m!=null&&ne(m,1,qe),B(this,m,b,2)},t.toString=function(m){var b,k=this,x=k.s,P=k.e;return P===null?x?(b="Infinity",x<0&&(b="-"+b)):b="NaN":(m==null?b=P<=w||P>=M?bt(We(k.c),P):rt(We(k.c),P,"0"):m===10&&j?(k=z(new I(k),d+P+1,v),b=rt(We(k.c),k.e,"0")):(ne(m,2,U.length,"Base"),b=n(rt(We(k.c),P,"0"),10,m,x,!0)),x<0&&k.c[0]&&(b="-"+b)),b},t.valueOf=t.toJSON=function(){return V(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,u=i[0]+"";s<t;){for(r=i[s++]+"",n=G-r.length;n--;r="0"+r);u+=r}for(t=u.length;u.charCodeAt(--t)===48;);return u.slice(0,t+1||1)}function ht(i,r){var n,s,t=i.c,u=r.c,d=i.s,v=r.s,w=i.e,M=r.e;if(!d||!v)return null;if(n=t&&!t[0],s=u&&!u[0],n||s)return n?s?0:-v:d;if(d!=v)return d;if(n=d<0,s=w==M,!t||!u)return s?0:!t^n?1:-1;if(!s)return w>M^n?1:-1;for(v=(w=t.length)<(M=u.length)?w:M,d=0;d<v;d++)if(t[d]!=u[d])return t[d]>u[d]^n?1:-1;return w==M?0:w>M^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/G)==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 rt(i,r,n){var s,t;if(r<0){for(t=n+".";++r;t+=n);i=t+i}else if(s=i.length,++r>s){for(t=n,r-=s;--r;t+=n);i+=t}else r<s&&(i=i.slice(0,r)+"."+i.slice(r));return i}var Lr=Ei(),Je=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 St=Nr;import{getPackagerConfigs as Br}from"@cetusprotocol/common-sdk";var si=10n;function Fi(i){return i.depositedAmount.eq(0)?new Je(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 Je(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:St(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${t}/partners/LiqAg.png`,perDay:new Je(.036),side:ct.DEPOSIT},obligationClaims:{}}),r.coinType===Er&&n.push({stats:{id:St(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${t}/partners/Lombard Lux.png`,perDay:new Je(0),side:ct.DEPOSIT},obligationClaims:{}}))}function ji(i,r,n){return{...i,depositedAmount:r===ct.DEPOSIT?Je.max(i.depositedAmount.plus(n),0):i.depositedAmount,borrowedAmount:r===ct.BORROW?Je.max(i.borrowedAmount.plus(n),0):i.borrowedAmount}}function Zi(i,r,n){let s=i===ct.DEPOSIT?r.depositedAmount:r.borrowedAmount,t=i===ct.DEPOSIT?n.depositedAmount:n.borrowedAmount,u=t.eq(0)?new Je(-1):s.div(t);return{multiplier:u,isValid:!u.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}})),u=r.map(d=>({...d,stats:{...d.stats,aprPercent:s?d.stats.aprPercent.times(n):void 0}}));return{newPerDayRewards:t,newAprRewards:u}}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 Ct=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 u=Object.values(s??{})[0],d=u.lendingMarket.reserves.find(V=>V.coinType===r);if(!d)throw new Error("reserve not found");let v=this.obligationsCache?.[u.lendingMarket.id],w="borrow",M=v.rewardMap[d.token.coinType]?.[w]??[],_=zr(M);Ui(w,d,_,this.sdk);let C=$r(w,d.coinType,t),A=w===Ki.DEPOSIT?d.depositAprPercent:d.borrowAprPercent,L=A,E=ji(d,w,n);L=w===Ki.DEPOSIT?qi(E):ai(E);let{multiplier:N,isValid:U}=Zi(w,d,E),j=Kr(_),I=Hr(_),{newPerDayRewards:B,newAprRewards:F}=zi(j,I,N,U),J=Hi(w,A,_,C),z=L===void 0||F.some(V=>V.stats.aprPercent===void 0)?void 0:Hi(w,L,F,C);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:J.toString(),borrowInterest:A.toString(),stakingYieldAprPercent:C?.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:u}=dt(this.sdk.sdkOptions?.suilend),d=`${t}_${u}`;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 u=Array.from(new Set(r.map(w=>Gr(new Uint8Array(w.priceIdentifier.bytes))))),d=await this.suilendClientCache[t].pythConnection.getLatestPriceFeeds(u),v={};return d?.forEach((w,M)=>{let _=w.getPriceUnchecked(),C=r[M];if(_){let{price:A,expo:L}=_,E=mt(A).mul(mt(10).pow(mt(L))).toString(),N={coin_type:C.coinType.name,price:E,oracle_price:0n,last_update_time:_.publishTime};N.oracle_price=$i(BigInt(A),BigInt(L)),v[C.coinType.name]=N,this.sdk.updateCache(`getLatestPrice_${N.coin_type}`,N)}}),v};this.getSuiLendReserveInfo=async(r,n)=>{let{lendingMarketId:s}=dt(this.sdk.sdkOptions?.suilend),{allLendingMarketData:t}=await this.getLendingMarketData(),u=t[s].reserveMap[r],d=t[s].reserveMap[n],v=t[s].refreshedRawReserves.filter(w=>w.coinType.name==Wi(r)||w.coinType.name==Wi(n));return{baseReserveArrayIndex:u.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:w,coinMetadataMap:M,refreshedRawReserves:_,reserveMap:C,reserveCoinTypes:A,reserveCoinMetadataMap:L,rewardCoinTypes:E,activeRewardCoinTypes:N,rewardCoinMetadataMap:U}=await qr(this.sdk.FullClient,v),{rewardPriceMap:j}=await Ur(C,N);return[d.id,{suilendClient:v,lendingMarket:w,coinMetadataMap:M,refreshedRawReserves:_,reserveMap:C,reserveCoinTypes:A,reserveCoinMetadataMap:L,rewardPriceMap:j,rewardCoinTypes:E,activeRewardCoinTypes:N,rewardCoinMetadataMap:U}]}))))(),(async()=>{try{let u=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.apiUrl}/springsui/apy`),d=await u.json();if(u?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(d).map(([v,w])=>[v,new Je(w)]))}catch(u){return console.error(u),{}}})()]);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:u,obligations:d}=await jr(this.sdk.FullClient,t.suilendClient,t.refreshedRawReserves,t.reserveMap,this.sdk.senderAddress),v=Zr(t.reserveMap,t.rewardCoinMetadataMap,t.rewardPriceMap,d);s[t.lendingMarket.id]={obligationOwnerCaps:u,obligations:d,rewardMap:v}}return this.obligationsCache=s,this.obligationsCache}async getSuiLendUserData(r,n=!1){let{lstAprPercentMap:s}=this.lendingMarketCache??{},t=this.obligationsCache??{},{lendingMarketId:u}=dt(this.sdk.sdkOptions?.suilend),d=t[u];if(!d)throw new Error(`No user data found for lending market: ${u}`);if(r){let v=d.obligations.find(M=>M.id===r);if(!v)throw new Error(`Obligation not found: ${r}`);let w=Wr(v,d.rewardMap,s??{});return{obligation:v,netAprPercent:w,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 Be,CACHE_TIME_5MIN as dr,CoinAssist as ie,CLOCK_ADDRESS as ft,d as K,removeHexPrefix as pr}from"@cetusprotocol/common-sdk";var pt=9e15,ut=1e9,li="0123456789abcdef",xt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Lt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ui={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-pt,maxE:pt,crypto:!1},Qi,nt,H=!0,Ot="[DecimalError] ",lt=Ot+"Invalid argument: ",Yi=Ot+"Precision limit exceeded",Ji=Ot+"crypto unavailable",er="[object Decimal]",Ze=Math.floor,Fe=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,fi=Lt.length-1,O={toStringTag:er};O.absoluteValue=O.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),Z(i)};O.ceil=function(){return Z(new this.constructor(this),this.e+1,2)};O.clampedTo=O.clamp=function(i,r){var n,s=this,t=s.constructor;if(i=new t(i),r=new t(r),!i.s||!r.s)return new t(NaN);if(i.gt(r))throw Error(lt+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,u=this,d=u.d,v=(i=new u.constructor(i)).d,w=u.s,M=i.s;if(!d||!v)return!w||!M?NaN:w!==M?w:d===v?0:!d^w<0?1:-1;if(!d[0]||!v[0])return d[0]?w:v[0]?-M:0;if(w!==M)return w;if(u.e!==i.e)return u.e>i.e^w<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]^w<0?1:-1;return s===t?0:s>t^w<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,Z(nt==2||nt==3?n.neg():n,i,r,!0)):new s(1):new s(NaN)};O.cubeRoot=O.cbrt=function(){var i,r,n,s,t,u,d,v,w,M,_=this,C=_.constructor;if(!_.isFinite()||_.isZero())return new C(_);for(H=!1,u=_.s*Fe(_.s*_,1/3),!u||Math.abs(u)==1/0?(n=je(_.d),i=_.e,(u=(i-n.length+1)%3)&&(n+=u==1||u==-2?"0":"00"),u=Fe(n,1/3),i=Ze((i+1)/3)-(i%3==(i<0?-1:2)),u==1/0?n="5e"+i:(n=u.toExponential(),n=n.slice(0,n.indexOf("e")+1)+i),s=new C(n),s.s=_.s):s=new C(u.toString()),d=(i=C.precision)+3;;)if(v=s,w=v.times(v).times(v),M=w.plus(_),s=re(M.plus(_).times(v),M.plus(w),d+2,1),je(v.d).slice(0,d)===(n=je(s.d)).slice(0,d))if(n=n.slice(d-3,d+1),n=="9999"||!t&&n=="4999"){if(!t&&(Z(v,i+1,0),v.times(v).times(v).eq(_))){s=v;break}d+=4,t=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(Z(s,i+1,1),r=!s.times(s).times(s).eq(_));break}return H=!0,Z(s,i,C.rounding,r)};O.decimalPlaces=O.dp=function(){var i,r=this.d,n=NaN;if(r){if(i=r.length-1,n=(i-Ze(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 re(this,new this.constructor(i))};O.dividedToIntegerBy=O.divToInt=function(i){var r=this,n=r.constructor;return Z(re(r,new n(i),0,1,1),n.precision,n.rounding)};O.equals=O.eq=function(i){return this.cmp(i)===0};O.floor=function(){return Z(new this.constructor(this),this.e+1,3)};O.greaterThan=O.gt=function(i){return this.cmp(i)>0};O.greaterThanOrEqualTo=O.gte=function(i){var r=this.cmp(i);return r==1||r===0};O.hyperbolicCosine=O.cosh=function(){var i,r,n,s,t,u=this,d=u.constructor,v=new d(1);if(!u.isFinite())return new d(u.s?1/0:NaN);if(u.isZero())return v;n=d.precision,s=d.rounding,d.precision=n+Math.max(u.e,u.sd())+4,d.rounding=1,t=u.d.length,t<32?(i=Math.ceil(t/3),r=(1/Rt(4,i)).toString()):(i=16,r="2.3283064365386962890625e-10"),u=gt(d,1,u.times(r),new d(1),!0);for(var w,M=i,_=new d(8);M--;)w=u.times(u),u=v.minus(w.times(_.minus(w.times(_))));return Z(u,d.precision=n,d.rounding=s,!0)};O.hyperbolicSine=O.sinh=function(){var i,r,n,s,t=this,u=t.constructor;if(!t.isFinite()||t.isZero())return new u(t);if(r=u.precision,n=u.rounding,u.precision=r+Math.max(t.e,t.sd())+4,u.rounding=1,s=t.d.length,s<3)t=gt(u,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(u,2,t,t,!0);for(var d,v=new u(5),w=new u(16),M=new u(20);i--;)d=t.times(t),t=t.times(v.plus(d.times(w.times(d).plus(M))))}return u.precision=r,u.rounding=n,Z(t,r,n,!0)};O.hyperbolicTangent=O.tanh=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+7,s.rounding=1,re(n.sinh(),n.cosh(),s.precision=i,s.rounding=r)):new s(n.s)};O.inverseCosine=O.acos=function(){var i=this,r=i.constructor,n=i.abs().cmp(1),s=r.precision,t=r.rounding;return n!==-1?n===0?i.isNeg()?et(r,s,t):new r(0):new r(NaN):i.isZero()?et(r,s+4,t).times(.5):(r.precision=s+6,r.rounding=1,i=new r(1).minus(i).div(i.plus(1)).sqrt().atan(),r.precision=s,r.rounding=t,i.times(2))};O.inverseHyperbolicCosine=O.acosh=function(){var i,r,n=this,s=n.constructor;return n.lte(1)?new s(n.eq(1)?0:NaN):n.isFinite()?(i=s.precision,r=s.rounding,s.precision=i+Math.max(Math.abs(n.e),n.sd())+4,s.rounding=1,H=!1,n=n.times(n).minus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln()):new s(n)};O.inverseHyperbolicSine=O.asinh=function(){var i,r,n=this,s=n.constructor;return!n.isFinite()||n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+2*Math.max(Math.abs(n.e),n.sd())+6,s.rounding=1,H=!1,n=n.times(n).plus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln())};O.inverseHyperbolicTangent=O.atanh=function(){var i,r,n,s,t=this,u=t.constructor;return t.isFinite()?t.e>=0?new u(t.abs().eq(1)?t.s/0:t.isZero()?t:NaN):(i=u.precision,r=u.rounding,s=t.sd(),Math.max(s,i)<2*-t.e-1?Z(new u(t),i,r,!0):(u.precision=n=s-t.e,t=re(t.plus(1),new u(1).minus(t),n+i,1),u.precision=i+4,u.rounding=1,t=t.ln(),u.precision=i,u.rounding=r,t.times(.5))):new u(NaN)};O.inverseSine=O.asin=function(){var i,r,n,s,t=this,u=t.constructor;return t.isZero()?new u(t):(r=t.abs().cmp(1),n=u.precision,s=u.rounding,r!==-1?r===0?(i=et(u,n+4,s).times(.5),i.s=t.s,i):new u(NaN):(u.precision=n+6,u.rounding=1,t=t.div(new u(1).minus(t.times(t)).sqrt().plus(1)).atan(),u.precision=n,u.rounding=s,t.times(2)))};O.inverseTangent=O.atan=function(){var i,r,n,s,t,u,d,v,w,M=this,_=M.constructor,C=_.precision,A=_.rounding;if(M.isFinite()){if(M.isZero())return new _(M);if(M.abs().eq(1)&&C+4<=fi)return d=et(_,C+4,A).times(.25),d.s=M.s,d}else{if(!M.s)return new _(NaN);if(C+4<=fi)return d=et(_,C+4,A).times(.5),d.s=M.s,d}for(_.precision=v=C+10,_.rounding=1,n=Math.min(28,v/$+2|0),i=n;i;--i)M=M.div(M.times(M).plus(1).sqrt().plus(1));for(H=!1,r=Math.ceil(v/$),s=1,w=M.times(M),d=new _(M),t=M;i!==-1;)if(t=t.times(w),u=d.minus(t.div(s+=2)),t=t.times(w),d=u.plus(t.div(s+=2)),d.d[r]!==void 0)for(i=r;d.d[i]===u.d[i]&&i--;);return n&&(d=d.times(2<<n-1)),H=!0,Z(d,_.precision=C,_.rounding=A,!0)};O.isFinite=function(){return!!this.d};O.isInteger=O.isInt=function(){return!!this.d&&Ze(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,u,d,v,w,M=this,_=M.constructor,C=_.precision,A=_.rounding,L=5;if(i==null)i=new _(10),r=!0;else{if(i=new _(i),n=i.d,i.s<0||!n||!n[0]||i.eq(1))return new _(NaN);r=i.eq(10)}if(n=M.d,M.s<0||!n||!n[0]||M.eq(1))return new _(n&&!n[0]?-1/0:M.s!=1?NaN:n?0:1/0);if(r)if(n.length>1)u=!0;else{for(t=n[0];t%10===0;)t/=10;u=t!==1}if(H=!1,v=C+L,d=at(M,v),s=r?It(_,v+10):at(i,v),w=re(d,s,v,1),vt(w.d,t=C,A))do if(v+=10,d=at(M,v),s=r?It(_,v+10):at(i,v),w=re(d,s,v,1),!u){+je(w.d).slice(t+1,t+15)+1==1e14&&(w=Z(w,C+1,0));break}while(vt(w.d,t+=10,A));return H=!0,Z(w,C,A)};O.minus=O.sub=function(i){var r,n,s,t,u,d,v,w,M,_,C,A,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(M=L.d,A=i.d,v=E.precision,w=E.rounding,!M[0]||!A[0]){if(A[0])i.s=-i.s;else if(M[0])i=new E(L);else return new E(w===3?-0:0);return H?Z(i,v,w):i}if(n=Ze(i.e/$),_=Ze(L.e/$),M=M.slice(),u=_-n,u){for(C=u<0,C?(r=M,u=-u,d=A.length):(r=A,n=_,d=M.length),s=Math.max(Math.ceil(v/$),d)+2,u>s&&(u=s,r.length=1),r.reverse(),s=u;s--;)r.push(0);r.reverse()}else{for(s=M.length,d=A.length,C=s<d,C&&(d=s),s=0;s<d;s++)if(M[s]!=A[s]){C=M[s]<A[s];break}u=0}for(C&&(r=M,M=A,A=r,i.s=-i.s),d=M.length,s=A.length-d;s>0;--s)M[d++]=0;for(s=A.length;s>u;){if(M[--s]<A[s]){for(t=s;t&&M[--t]===0;)M[t]=Qe-1;--M[t],M[s]+=Qe}M[s]-=A[s]}for(;M[--d]===0;)M.pop();for(;M[0]===0;M.shift())--n;return M[0]?(i.d=M,i.e=Nt(M,n),H?Z(i,v,w):i):new E(w===3?-0:0)};O.modulo=O.mod=function(i){var r,n=this,s=n.constructor;return i=new s(i),!n.d||!i.s||i.d&&!i.d[0]?new s(NaN):!i.d||n.d&&!n.d[0]?Z(new s(n),s.precision,s.rounding):(H=!1,s.modulo==9?(r=re(n,i.abs(),0,3,1),r.s*=i.s):r=re(n,i,0,s.modulo,1),r=r.times(i),H=!0,n.minus(r))};O.naturalExponential=O.exp=function(){return hi(this)};O.naturalLogarithm=O.ln=function(){return at(this)};O.negated=O.neg=function(){var i=new this.constructor(this);return i.s=-i.s,Z(i)};O.plus=O.add=function(i){var r,n,s,t,u,d,v,w,M,_,C=this,A=C.constructor;if(i=new A(i),!C.d||!i.d)return!C.s||!i.s?i=new A(NaN):C.d||(i=new A(i.d||C.s===i.s?C:NaN)),i;if(C.s!=i.s)return i.s=-i.s,C.minus(i);if(M=C.d,_=i.d,v=A.precision,w=A.rounding,!M[0]||!_[0])return _[0]||(i=new A(C)),H?Z(i,v,w):i;if(u=Ze(C.e/$),s=Ze(i.e/$),M=M.slice(),t=u-s,t){for(t<0?(n=M,t=-t,d=_.length):(n=_,s=u,d=M.length),u=Math.ceil(v/$),d=u>d?u+1:d+1,t>d&&(t=d,n.length=1),n.reverse();t--;)n.push(0);n.reverse()}for(d=M.length,t=_.length,d-t<0&&(t=d,n=_,_=M,M=n),r=0;t;)r=(M[--t]=M[t]+_[t]+r)/Qe|0,M[t]%=Qe;for(r&&(M.unshift(r),++s),d=M.length;M[--d]==0;)M.pop();return i.d=M,i.e=Nt(M,s),H?Z(i,v,w):i};O.precision=O.sd=function(i){var r,n=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(lt+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 Z(new r(i),i.e+1,r.rounding)};O.sine=O.sin=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+Math.max(n.e,n.sd())+$,s.rounding=1,n=rn(s,sr(s,n)),s.precision=i,s.rounding=r,Z(nt>2?n.neg():n,i,r,!0)):new s(NaN)};O.squareRoot=O.sqrt=function(){var i,r,n,s,t,u,d=this,v=d.d,w=d.e,M=d.s,_=d.constructor;if(M!==1||!v||!v[0])return new _(!M||M<0&&(!v||v[0])?NaN:v?d:1/0);for(H=!1,M=Math.sqrt(+d),M==0||M==1/0?(r=je(v),(r.length+w)%2==0&&(r+="0"),M=Math.sqrt(r),w=Ze((w+1)/2)-(w<0||w%2),M==1/0?r="5e"+w:(r=M.toExponential(),r=r.slice(0,r.indexOf("e")+1)+w),s=new _(r)):s=new _(M.toString()),n=(w=_.precision)+3;;)if(u=s,s=u.plus(re(d,u,n+2,1)).times(.5),je(u.d).slice(0,n)===(r=je(s.d)).slice(0,n))if(r=r.slice(n-3,n+1),r=="9999"||!t&&r=="4999"){if(!t&&(Z(u,w+1,0),u.times(u).eq(d))){s=u;break}n+=4,t=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(Z(s,w+1,1),i=!s.times(s).eq(d));break}return H=!0,Z(s,w,_.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=re(n,new s(1).minus(n.times(n)).sqrt(),i+10,0),s.precision=i,s.rounding=r,Z(nt==2||nt==4?n.neg():n,i,r,!0)):new s(NaN)};O.times=O.mul=function(i){var r,n,s,t,u,d,v,w,M,_=this,C=_.constructor,A=_.d,L=(i=new C(i)).d;if(i.s*=_.s,!A||!A[0]||!L||!L[0])return new C(!i.s||A&&!A[0]&&!L||L&&!L[0]&&!A?NaN:!A||!L?i.s/0:i.s*0);for(n=Ze(_.e/$)+Ze(i.e/$),w=A.length,M=L.length,w<M&&(u=A,A=L,L=u,d=w,w=M,M=d),u=[],d=w+M,s=d;s--;)u.push(0);for(s=M;--s>=0;){for(r=0,t=w+s;t>s;)v=u[t]+L[s]*A[t-s-1]+r,u[t--]=v%Qe|0,r=v/Qe|0;u[t]=(u[t]+r)%Qe|0}for(;!u[--d];)u.pop();return r?++n:u.shift(),i.d=u,i.e=Nt(u,n),H?Z(i,C.precision,C.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,ut),r===void 0?r=s.rounding:Ke(r,0,8),Z(n,i+n.e+1,r))};O.toExponential=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=tt(s,!0):(Ke(i,0,ut),r===void 0?r=t.rounding:Ke(r,0,8),s=Z(new t(s),i+1,r),n=tt(s,!0,i+1)),s.isNeg()&&!s.isZero()?"-"+n:n};O.toFixed=function(i,r){var n,s,t=this,u=t.constructor;return i===void 0?n=tt(t):(Ke(i,0,ut),r===void 0?r=u.rounding:Ke(r,0,8),s=Z(new u(t),i+t.e+1,r),n=tt(s,!1,i+s.e+1)),t.isNeg()&&!t.isZero()?"-"+n:n};O.toFraction=function(i){var r,n,s,t,u,d,v,w,M,_,C,A,L=this,E=L.d,N=L.constructor;if(!E)return new N(L);if(M=n=new N(1),s=w=new N(0),r=new N(s),u=r.e=ir(E)-L.e-1,d=u%$,r.d[0]=Fe(10,d<0?$+d:d),i==null)i=u>0?r:M;else{if(v=new N(i),!v.isInt()||v.lt(M))throw Error(lt+v);i=v.gt(r)?u>0?r:M:v}for(H=!1,v=new N(je(E)),_=N.precision,N.precision=u=E.length*$*2;C=re(v,r,0,1,1),t=n.plus(C.times(s)),t.cmp(i)!=1;)n=s,s=t,t=M,M=w.plus(C.times(t)),w=t,t=r,r=v.minus(C.times(t)),v=t;return t=re(i.minus(n),s,0,1,1),w=w.plus(t.times(M)),n=n.plus(t.times(s)),w.s=M.s=L.s,A=re(M,s,u,1).minus(L).abs().cmp(re(w,n,u,1).minus(L).abs())<1?[M,s]:[w,n],N.precision=_,H=!0,A};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]?(H=!1,n=re(n,i,0,r,1).times(i),H=!0,Z(n)):(i.s=n.s,n=i),n};O.toNumber=function(){return+this};O.toOctal=function(i,r){return ci(this,8,i,r)};O.toPower=O.pow=function(i){var r,n,s,t,u,d,v=this,w=v.constructor,M=+(i=new w(i));if(!v.d||!i.d||!v.d[0]||!i.d[0])return new w(Fe(+v,M));if(v=new w(v),v.eq(1))return v;if(s=w.precision,u=w.rounding,i.eq(1))return Z(v,s,u);if(r=Ze(i.e/$),r>=i.d.length-1&&(n=M<0?-M:M)<=Yr)return t=rr(w,v,n,s),i.s<0?new w(1).div(t):Z(t,s,u);if(d=v.s,d<0){if(r<i.d.length-1)return new w(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=Fe(+v,M),r=n==0||!isFinite(n)?Ze(M*(Math.log("0."+je(v.d))/Math.LN10+v.e+1)):new w(n+"").e,r>w.maxE+1||r<w.minE-1?new w(r>0?d/0:0):(H=!1,w.rounding=v.s=1,n=Math.min(12,(r+"").length),t=hi(i.times(at(v,s+n)),s),t.d&&(t=Z(t,s+5,1),vt(t.d,s,u)&&(r=s+10,t=Z(hi(i.times(at(v,r+n)),r),r+5,1),+je(t.d).slice(s+1,s+15)+1==1e14&&(t=Z(t,s+1,0)))),t.s=d,H=!0,w.rounding=u,Z(t,s,u))};O.toPrecision=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=tt(s,s.e<=t.toExpNeg||s.e>=t.toExpPos):(Ke(i,1,ut),r===void 0?r=t.rounding:Ke(r,0,8),s=Z(new t(s),i,r),n=tt(s,i<=s.e||s.e<=t.toExpNeg,i)),s.isNeg()&&!s.isZero()?"-"+n:n};O.toSignificantDigits=O.toSD=function(i,r){var n=this,s=n.constructor;return i===void 0?(i=s.precision,r=s.rounding):(Ke(i,1,ut),r===void 0?r=s.rounding:Ke(r,0,8)),Z(new s(n),i,r)};O.toString=function(){var i=this,r=i.constructor,n=tt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()&&!i.isZero()?"-"+n:n};O.truncated=O.trunc=function(){return Z(new this.constructor(this),this.e+1,1)};O.valueOf=O.toJSON=function(){var i=this,r=i.constructor,n=tt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()?"-"+n:n};function je(i){var r,n,s,t=i.length-1,u="",d=i[0];if(t>0){for(u+=d,r=1;r<t;r++)s=i[r]+"",n=$-s.length,n&&(u+=st(n)),u+=s;d=i[r],s=d+"",n=$-s.length,n&&(u+=st(n))}else if(d===0)return"0";for(;d%10===0;)d/=10;return u+d}function Ke(i,r,n){if(i!==~~i||i<r||i>n)throw Error(lt+i)}function vt(i,r,n,s){var t,u,d,v;for(u=i[0];u>=10;u/=10)--r;return--r<0?(r+=$,t=0):(t=Math.ceil((r+1)/$),r%=$),u=Fe(10,$-r),v=i[t]%u|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==u||n>3&&v+1==u/2)&&(i[t+1]/u/100|0)==Fe(10,r-2)-1||(v==u/2||v==0)&&(i[t+1]/u/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==u||!s&&n>3&&v+1==u/2)&&(i[t+1]/u/1e3|0)==Fe(10,r-3)-1,d}function At(i,r,n){for(var s,t=[0],u,d=0,v=i.length;d<v;){for(u=t.length;u--;)t[u]*=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 u=n;u--;){var d=r.times(r);r=d.times(d).minus(d).times(8).plus(1)}return i.precision-=n,r}var re=(function(){function i(s,t,u){var d,v=0,w=s.length;for(s=s.slice();w--;)d=s[w]*t+v,s[w]=d%u|0,v=d/u|0;return v&&s.unshift(v),s}function r(s,t,u,d){var v,w;if(u!=d)w=u>d?1:-1;else for(v=w=0;v<u;v++)if(s[v]!=t[v]){w=s[v]>t[v]?1:-1;break}return w}function n(s,t,u,d){for(var v=0;u--;)s[u]-=v,v=s[u]<t[u]?1:0,s[u]=v*d+s[u]-t[u];for(;!s[0]&&s.length>1;)s.shift()}return function(s,t,u,d,v,w){var M,_,C,A,L,E,N,U,j,I,B,F,J,z,V,m,b,k,x,P,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(w?(L=1,_=s.e-t.e):(w=Qe,L=$,_=Ze(s.e/L)-Ze(t.e/L)),x=l.length,b=o.length,j=new c(e),I=j.d=[],C=0;l[C]==(o[C]||0);C++);if(l[C]>(o[C]||0)&&_--,u==null?(z=u=c.precision,d=c.rounding):v?z=u+(s.e-t.e)+1:z=u,z<0)I.push(1),E=!0;else{if(z=z/L+2|0,C=0,x==1){for(A=0,l=l[0],z++;(C<b||A)&&z--;C++)V=A*w+(o[C]||0),I[C]=V/l|0,A=V%l|0;E=A||C<b}else{for(A=w/(l[0]+1)|0,A>1&&(l=i(l,A,w),o=i(o,A,w),x=l.length,b=o.length),m=x,B=o.slice(0,x),F=B.length;F<x;)B[F++]=0;P=l.slice(),P.unshift(0),k=l[0],l[1]>=w/2&&++k;do A=0,M=r(l,B,x,F),M<0?(J=B[0],x!=F&&(J=J*w+(B[1]||0)),A=J/k|0,A>1?(A>=w&&(A=w-1),N=i(l,A,w),U=N.length,F=B.length,M=r(N,B,U,F),M==1&&(A--,n(N,x<U?P:l,U,w))):(A==0&&(M=A=1),N=l.slice()),U=N.length,U<F&&N.unshift(0),n(B,N,F,w),M==-1&&(F=B.length,M=r(l,B,x,F),M<1&&(A++,n(B,x<F?P:l,F,w))),F=B.length):M===0&&(A++,B=[0]),I[C++]=A,M&&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)j.e=_,Qi=E;else{for(C=1,A=I[0];A>=10;A/=10)C++;j.e=C+_*L-1,Z(j,v?u+j.e+1:u,d,E)}return j}})();function Z(i,r,n,s){var t,u,d,v,w,M,_,C,A,L=i.constructor;e:if(r!=null){if(C=i.d,!C)return i;for(t=1,v=C[0];v>=10;v/=10)t++;if(u=r-t,u<0)u+=$,d=r,_=C[A=0],w=_/Fe(10,t-d-1)%10|0;else if(A=Math.ceil((u+1)/$),v=C.length,A>=v)if(s){for(;v++<=A;)C.push(0);_=w=0,t=1,u%=$,d=u-$+1}else break e;else{for(_=v=C[A],t=1;v>=10;v/=10)t++;u%=$,d=u-$+t,w=d<0?0:_/Fe(10,t-d-1)%10|0}if(s=s||r<0||C[A+1]!==void 0||(d<0?_:_%Fe(10,t-d-1)),M=n<4?(w||s)&&(n==0||n==(i.s<0?3:2)):w>5||w==5&&(n==4||s||n==6&&(u>0?d>0?_/Fe(10,t-d):0:C[A-1])%10&1||n==(i.s<0?8:7)),r<1||!C[0])return C.length=0,M?(r-=i.e+1,C[0]=Fe(10,($-r%$)%$),i.e=-r||0):C[0]=i.e=0,i;if(u==0?(C.length=A,v=1,A--):(C.length=A+1,v=Fe(10,$-u),C[A]=d>0?(_/Fe(10,t-d)%Fe(10,d)|0)*v:0),M)for(;;)if(A==0){for(u=1,d=C[0];d>=10;d/=10)u++;for(d=C[0]+=v,v=1;d>=10;d/=10)v++;u!=v&&(i.e++,C[0]==Qe&&(C[0]=1));break}else{if(C[A]+=v,C[A]!=Qe)break;C[A--]=0,v=1}for(u=C.length;C[--u]===0;)C.pop()}return H&&(i.e>L.maxE?(i.d=null,i.e=NaN):i.e<L.minE&&(i.e=0,i.d=[0])),i}function tt(i,r,n){if(!i.isFinite())return or(i);var s,t=i.e,u=je(i.d),d=u.length;return r?(n&&(s=n-d)>0?u=u.charAt(0)+"."+u.slice(1)+st(s):d>1&&(u=u.charAt(0)+"."+u.slice(1)),u=u+(i.e<0?"e":"e+")+i.e):t<0?(u="0."+st(-t-1)+u,n&&(s=n-d)>0&&(u+=st(s))):t>=d?(u+=st(t+1-d),n&&(s=n-t-1)>0&&(u=u+"."+st(s))):((s=t+1)<d&&(u=u.slice(0,s)+"."+u.slice(s)),n&&(s=n-d)>0&&(t+1===d&&(u+="."),u+=st(s))),u}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 H=!0,n&&(i.precision=n),Error(Yi);return Z(new i(xt),r,1,!0)}function et(i,r,n){if(r>fi)throw Error(Yi);return Z(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 st(i){for(var r="";i--;)r+="0";return r}function rr(i,r,n,s){var t,u=new i(1),d=Math.ceil(s/$+4);for(H=!1;;){if(n%2&&(u=u.times(r),Vi(u.d,d)&&(t=!0)),n=Ze(n/2),n===0){n=u.d.length-1,t&&u.d[n]===0&&++u.d[n];break}r=r.times(r),Vi(r.d,d)}return H=!0,u}function Gi(i){return i.d[i.d.length-1]&1}function nr(i,r,n){for(var s,t,u=new i(r[0]),d=0;++d<r.length;){if(t=new i(r[d]),!t.s){u=t;break}s=u.cmp(t),(s===n||s===0&&u.s===n)&&(u=t)}return u}function hi(i,r){var n,s,t,u,d,v,w,M=0,_=0,C=0,A=i.constructor,L=A.rounding,E=A.precision;if(!i.d||!i.d[0]||i.e>17)return new A(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(r==null?(H=!1,w=E):w=r,v=new A(.03125);i.e>-2;)i=i.times(v),C+=5;for(s=Math.log(Fe(2,C))/Math.LN10*2+5|0,w+=s,n=u=d=new A(1),A.precision=w;;){if(u=Z(u.times(i),w,1),n=n.times(++_),v=d.plus(re(u,n,w,1)),je(v.d).slice(0,w)===je(d.d).slice(0,w)){for(t=C;t--;)d=Z(d.times(d),w,1);if(r==null)if(M<3&&vt(d.d,w-s,L,M))A.precision=w+=10,n=u=v=new A(1),_=0,M++;else return Z(d,A.precision=E,L,H=!0);else return A.precision=E,d}d=v}}function at(i,r){var n,s,t,u,d,v,w,M,_,C,A,L=1,E=10,N=i,U=N.d,j=N.constructor,I=j.rounding,B=j.precision;if(N.s<0||!U||!U[0]||!N.e&&U[0]==1&&U.length==1)return new j(U&&!U[0]?-1/0:N.s!=1?NaN:U?0:N);if(r==null?(H=!1,_=B):_=r,j.precision=_+=E,n=je(U),s=n.charAt(0),Math.abs(u=N.e)<15e14){for(;s<7&&s!=1||s==1&&n.charAt(1)>3;)N=N.times(i),n=je(N.d),s=n.charAt(0),L++;u=N.e,s>1?(N=new j("0."+n),u++):N=new j(s+"."+n.slice(1))}else return M=It(j,_+2,B).times(u+""),N=at(new j(s+"."+n.slice(1)),_-E).plus(M),j.precision=B,r==null?Z(N,B,I,H=!0):N;for(C=N,w=d=N=re(N.minus(1),N.plus(1),_,1),A=Z(N.times(N),_,1),t=3;;){if(d=Z(d.times(A),_,1),M=w.plus(re(d,new j(t),_,1)),je(M.d).slice(0,_)===je(w.d).slice(0,_))if(w=w.times(2),u!==0&&(w=w.plus(It(j,_+2,B).times(u+""))),w=re(w,new j(L),_,1),r==null)if(vt(w.d,_-E,I,v))j.precision=_+=E,M=d=N=re(C.minus(1),C.plus(1),_,1),A=Z(N.times(N),_,1),t=v=1;else return Z(w,j.precision=B,I,H=!0);else return j.precision=B,w;w=M,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),H&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function tn(i,r){var n,s,t,u,d,v,w,M,_;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(lt+r);for(u=r.search(/p/i),u>0?(w=+r.slice(u+1),r=r.substring(2,u)):r=r.slice(2),u=r.indexOf("."),d=u>=0,s=i.constructor,d&&(r=r.replace(".",""),v=r.length,u=v-u,t=rr(s,new s(n),u,u*2)),M=At(r,n,Qe),_=M.length-1,u=_;M[u]===0;--u)M.pop();return u<0?new s(i.s*0):(i.e=Nt(M,_),i.d=M,H=!1,d&&(i=re(i,t,v*4)),w&&(i=i.times(Math.abs(w)<54?Fe(2,w):wt.pow(2,w))),H=!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,u=new i(5),d=new i(16),v=new i(20);n--;)t=r.times(r),r=r.times(u.plus(t.times(d.times(t).minus(v))));return r}function gt(i,r,n,s,t){var u,d,v,w,M=1,_=i.precision,C=Math.ceil(_/$);for(H=!1,w=n.times(n),v=new i(s);;){if(d=re(v.times(w),new i(r++*r++),_,1),v=t?s.plus(d):s.minus(d),s=re(d.times(w),new i(r++*r++),_,1),d=v.plus(s),d.d[C]!==void 0){for(u=C;d.d[u]===v.d[u]&&u--;);if(u==-1)break}u=v,v=s,s=d,d=u,M++}return H=!0,d.d.length=C+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=et(i,i.precision,1),u=t.times(.5);if(r=r.abs(),r.lte(u))return nt=s?4:1,r;if(n=r.divToInt(t),n.isZero())nt=s?3:2;else{if(r=r.minus(n.times(t)),r.lte(u))return nt=Gi(n)?s?2:3:s?4:1,r;nt=Gi(n)?s?1:4:s?3:2}return r.minus(t).abs()}function ci(i,r,n,s){var t,u,d,v,w,M,_,C,A,L=i.constructor,E=n!==void 0;if(E?(Ke(n,1,ut),s===void 0?s=L.rounding:Ke(s,0,8)):(n=L.precision,s=L.rounding),!i.isFinite())_=or(i);else{for(_=tt(i),d=_.indexOf("."),E?(t=2,r==16?n=n*4-3:r==8&&(n=n*3-2)):t=r,d>=0&&(_=_.replace(".",""),A=new L(1),A.e=_.length-d,A.d=At(tt(A),10,t),A.e=A.d.length),C=At(_,10,t),u=w=C.length;C[--w]==0;)C.pop();if(!C[0])_=E?"0p+0":"0";else{if(d<0?u--:(i=new L(i),i.d=C,i.e=u,i=re(i,A,n,s,0,t),C=i.d,u=i.e,M=Qi),d=C[n],v=t/2,M=M||C[n+1]!==void 0,M=s<4?(d!==void 0||M)&&(s===0||s===(i.s<0?3:2)):d>v||d===v&&(s===4||M||s===6&&C[n-1]&1||s===(i.s<0?8:7)),C.length=n,M)for(;++C[--n]>t-1;)C[n]=0,n||(++u,C.unshift(1));for(w=C.length;!C[w-1];--w);for(d=0,_="";d<w;d++)_+=li.charAt(C[d]);if(E){if(w>1)if(r==16||r==8){for(d=r==16?4:3,--w;w%d;w++)_+="0";for(C=At(_,t,r),w=C.length;!C[w-1];--w);for(d=1,_="1.";d<w;d++)_+=li.charAt(C[d])}else _=_.charAt(0)+"."+_.slice(1);_=_+(u<0?"p":"p+")+u}else if(u<0){for(;++u;)_="0"+_;_="0."+_}else if(++u>w)for(u-=w;u--;)_+="0";else u<w&&(_=_.slice(0,u)+"."+_.slice(u))}_=(r==16?"0x":r==2?"0b":r==8?"0o":"")+_}return i.s<0?"-"+_:_}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 un(i){return new this(i).asinh()}function fn(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,u=s+4;return!i.s||!r.s?n=new this(NaN):!i.d&&!r.d?(n=et(this,u,1).times(r.s>0?.25:.75),n.s=i.s):!r.d||i.isZero()?(n=r.s<0?et(this,s,t):new this(0),n.s=i.s):!i.d||r.isZero()?(n=et(this,u,1).times(.5),n.s=i.s):r.s<0?(this.precision=u,this.rounding=1,n=this.atan(re(i,r,u,1)),r=et(this,u,1),this.precision=s,this.rounding=t,n=i.s<0?n.minus(r):n.plus(r)):n=this.atan(re(i,r,u,1)),n}function dn(i){return new this(i).cbrt()}function pn(i){return Z(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,u=["precision",1,ut,"rounding",0,8,"toExpNeg",-pt,0,"toExpPos",0,pt,"maxE",0,pt,"minE",-pt,0,"modulo",0,9];for(r=0;r<u.length;r+=3)if(n=u[r],t&&(this[n]=ui[n]),(s=i[n])!==void 0)if(Ze(s)===s&&s>=u[r+1]&&s<=u[r+2])this[n]=s;else throw Error(lt+n+": "+s);if(n="crypto",t&&(this[n]=ui[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(lt+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(u){var d,v,w,M=this;if(!(M instanceof t))return new t(u);if(M.constructor=t,Xi(u)){M.s=u.s,H?!u.d||u.e>t.maxE?(M.e=NaN,M.d=null):u.e<t.minE?(M.e=0,M.d=[0]):(M.e=u.e,M.d=u.d.slice()):(M.e=u.e,M.d=u.d?u.d.slice():u.d);return}if(w=typeof u,w==="number"){if(u===0){M.s=1/u<0?-1:1,M.e=0,M.d=[0];return}if(u<0?(u=-u,M.s=-1):M.s=1,u===~~u&&u<1e7){for(d=0,v=u;v>=10;v/=10)d++;H?d>t.maxE?(M.e=NaN,M.d=null):d<t.minE?(M.e=0,M.d=[0]):(M.e=d,M.d=[u]):(M.e=d,M.d=[u]);return}if(u*0!==0){u||(M.s=NaN),M.e=NaN,M.d=null;return}return Pt(M,u.toString())}if(w==="string")return(v=u.charCodeAt(0))===45?(u=u.slice(1),M.s=-1):(v===43&&(u=u.slice(1)),M.s=1),tr.test(u)?Pt(M,u):tn(M,u);if(w==="bigint")return u<0?(u=-u,M.s=-1):M.s=1,Pt(M,u.toString());throw Error(lt+u)}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=un,t.atan=fn,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=Sn,t.log10=An,t.log2=Cn,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=jn,t.trunc=Zn,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 Z(i=new this(i),i.e+1,3)}function _n(){var i,r,n=new this(0);for(H=!1,i=0;i<arguments.length;)if(r=new this(arguments[i++]),r.d)n.d&&(n=n.plus(r.times(r)));else{if(r.s)return H=!0,new this(1/0);n=r}return H=!0,n.sqrt()}function Xi(i){return i instanceof wt||i&&i.toStringTag===er||!1}function kn(i){return new this(i).ln()}function Sn(i,r){return new this(i).log(r)}function Cn(i){return new this(i).log(2)}function An(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,u=0,d=new this(1),v=[];if(i===void 0?i=this.precision:Ke(i,1,ut),s=Math.ceil(i/$),this.crypto)if(crypto.getRandomValues)for(r=crypto.getRandomValues(new Uint32Array(s));u<s;)t=r[u],t>=429e7?r[u]=crypto.getRandomValues(new Uint32Array(1))[0]:v[u++]=t%1e7;else if(crypto.randomBytes){for(r=crypto.randomBytes(s*=4);u<s;)t=r[u]+(r[u+1]<<8)+(r[u+2]<<16)+((r[u+3]&127)<<24),t>=214e7?crypto.randomBytes(4).copy(r,u):(v.push(t%1e7),u+=4);u=s/4}else throw Error(Ji);else for(;u<s;)v[u++]=Math.random()*1e7|0;for(s=v[--u],i%=$,s&&i&&(t=Fe(10,$-i),v[u]=(s/t|0)*t);v[u]===0;u--)v.pop();if(u<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 Z(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(H=!1;n.s&&++i<r.length;)n=n.plus(r[i]);return H=!0,Z(n,this.precision,this.rounding)}function Un(i){return new this(i).tan()}function jn(i){return new this(i).tanh()}function Zn(i){return Z(i=new this(i),i.e+1,1)}O[Symbol.for("nodejs.util.inspect.custom")]=O.toString;O[Symbol.toStringTag]="Decimal";var wt=O.constructor=ar(ui);xt=new wt(xt);Lt=new wt(Lt);var Ye=wt;var mi=Cr(ur());import{Transaction as it}from"@mysten/sui/transactions";import{addHexPrefix as fr,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:fr(r.base_token.fields.name),quoteToken:fr(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=Be(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=Be(this._sdk.sdkOptions.leverage),u=50,d=null,v=[];for(;;){let A=await this._sdk.FullClient.getDynamicFields({parentId:t.markets_table_id,limit:u,cursor:d});if(A.data.forEach(L=>{v.push(L.objectId)}),A.data.length<u)break;d=A.nextCursor}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:63 ~ LeverageModules ~ marketSimpleIdList:",v);let w=await this._sdk.FullClient.batchGetObjects(v,{showContent:!0}),M=[];w.forEach(A=>{M.push(A.data.content.fields.value.fields.market_id)});let _=await this._sdk.FullClient.batchGetObjects(M,{showContent:!0}),C=cr(_);return this._sdk.updateCache(n,C,dr),C};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}}),u=pi(t);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:106 ~ LeverageModules ~ marketInfo:",u),this._sdk.updateCache(n,u,dr),u};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}=Be(this._sdk.sdkOptions.suilend),t=await this._sdk.SuiLendModule.getSuilendClient(n,s),u=[];for(let d=0;d<r.data.length;d++){let v=gi(r.data[d]),w=await t.getObligation(v.obligationOwnerCap);u.push({...v,...w})}return u};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:u}=Be(this._sdk.sdkOptions.suilend),d=await this._sdk.SuiLendModule.getSuilendClient(t,u),{allLendingMarketData:v}=await this._sdk.SuiLendModule.getLendingMarketData(),w=v[t].reserveMap,M=await d.getObligation(s.obligationOwnerCap);return{...zn(M,w||{}),...s}};this.getClmmPoolInfo=async r=>{let n=await this._sdk.ClmmSDK.Pool.getPool(r),{coin_type_a:s,coin_type_b:t,fee_rate:u}=n;return{clmmFeeTier:u/1e6,clmmPoolCoinTypeA:s,clmmPoolCoinTypeB:t}};this.openLeveragePosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:u,slippage:d,leverage:v,marketId:w}=r,{lendingMarketId:M}=Be(this._sdk.sdkOptions.suilend),_=new it,{openFeeRate:C,baseToken:A,quoteToken:L}=await this.getLeverageMarketInfo(w),{clmmFeeTier:E,clmmPoolCoinTypeA:N,clmmPoolCoinTypeB:U}=await this.getClmmPoolInfo(u);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",E,N,U);let{baseReserveArrayIndex:j,quoteReserveArrayIndex:I,reserve:B}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(A,L),F=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",F);let J=t.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",J);let z,V;if(F){let T=s&&n?L:A,q=s&&n?A:L,X=await this.findRouters(T,q,t,!0,[u]);if(J=X?.amount_out.toString(),X){let ee=ie.buildCoinWithBalance(BigInt(t.toString()),T,_);V=await this.routerSwap({router:X.route_obj,slippage:d,inputCoin:ee,txb:_}),z=V}}else z=ie.buildCoinWithBalance(BigInt(t.toString()),n?L:A,_);let{flashAmount:m}=await this.calculateFlashLoanParams({isLong:s,leverage:v,baseToken:A,quoteToken:L,initDepositAmount:J,reserve:B});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",m);let b=s?L:A;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",b);let k=N===b;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",N),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",k);let x=K(m).mul(E).toString(),{balanceA:P,balanceB:c,receipt:e}=this.flashLoan({amount:K(m),clmmPool:u,clmmPoolCoinTypeA:N,clmmPoolCoinTypeB:U,flashLoanCoin:b,tx:_}),o=s?L:A,l=s?A:L,f=await this.findRouters(o,l,K(m),!0,[u]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:f,debtFrom:o,debtTo:l,clmmPoolCoinTypeA:N,clmmPoolCoinTypeB:U});let h=K(f?.amount_out||0),g;f&&(g=await this.routerSwap({router:f.route_obj,inputCoin:k?ie.fromBalance(P,N,_):ie.fromBalance(c,U,_),slippage:d,txb:_}));let S=K(h).add(J).mul(1-C).toDP(0,Ye.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:258 ~ LeverageModules ~ totalDepositAmount:",S,J,h);let p=this.createLeveragePosition({leverage:v,marketId:w,baseToken:A,quoteToken:L,isLong:s,totalDepositAmount:S,tx:_});for(let T=0;T<B.length;T++){let q=Mt(new Uint8Array(B[T].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(_,q,BigInt(B[T].arrayIndex))}let a=s?j:I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",z),await _.mergeCoins(g,[z]),await this.depositToLeveragePosition({isLong:s,marketId:w,position:p,depositReserveArrayIndex:a,inputCoin:g},_);let y=K(m).add(x).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",y,m,x);let D=await this.borrowAsset({position:p,reserveArrayIndex:s?I:j,borrowAmount:K(y),baseToken:A,quoteToken:L,isLong:s,lendingMarketId:M},_);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",D);let R=ie.mintBalanceZero(k?U:N,_);return this.repayFlashLoan({tx:_,clmmPool:u,repayBase:k?ie.intoBalance(D,N,_):R,repayQuote:k?R:ie.intoBalance(D,U,_),receipt:e,clmmPoolCoinTypeA:N,clmmPoolCoinTypeB:U}),_.transferObjects([p],_.pure.address(this._sdk.getSenderAddress())),ie.destroyBalanceZero(k?c:P,k?U:N,_),_};this.positionManageSizeDeposit=async r=>{let{marketId:n,positionId:s,isQuote:t,depositAmount:u,clmmPool:d,slippage:v,leverage:w,txb:M}=r,{lendingMarketId:_}=Be(this._sdk.sdkOptions.suilend),{baseToken:C,quoteToken:A}=await this.getLeverageMarketInfo(n),{isLong:L,deposits:E,borrows:N}=await this.getLeveragePosition(s),{reserve:U}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(C,A),{clmmFeeTier:j,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B}=await this.getClmmPoolInfo(d),F=M||new it,J=E[0].reserveArrayIndex.toString(),z=N[0].reserveArrayIndex.toString(),V=t&&L||!t&&!L,m;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",V);let b;if(V){let D=t&&L?A:C,R=t&&L?C:A,T=await this.findRouters(D,R,u,!0,[d]);if(T){let q=ie.buildCoinWithBalance(BigInt(u.toString()),D,F);b=await this.routerSwap({router:T.route_obj,inputCoin:q,slippage:v,txb:F}),m=b}}else m=ie.buildCoinWithBalance(BigInt(u.toString()),t?A:C,F);let k=L?A:C;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",k);let{flashAmount:x}=await this.calculateFlashLoanParams({isLong:L,leverage:w,baseToken:C,quoteToken:A,initDepositAmount:u.toString(),reserve:U}),P=K(x).mul(j).toString(),c=I===k;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",c);let{balanceA:e,balanceB:o,receipt:l}=this.flashLoan({amount:K(x),clmmPool:d,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B,flashLoanCoin:k,tx:F}),f=L?A:C,h=L?C:A,g=await this.findRouters(f,h,K(x),!0,[d]),S;g&&(S=await this.routerSwap({router:g.route_obj,inputCoin:c?ie.fromBalance(e,I,F):ie.fromBalance(o,B,F),slippage:v,txb:F})),F.mergeCoins(S,[m]);for(let D=0;D<U.length;D++){let R=Mt(new Uint8Array(U[D].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(F,R,BigInt(U[D].arrayIndex))}this.depositToLeveragePosition({isLong:L,marketId:n,positionId:s,depositReserveArrayIndex:J,inputCoin:S},F);let p=K(x).add(P).toDP(0,Ye.ROUND_UP).toString(),a=this.borrowAsset({positionId:s,reserveArrayIndex:z,borrowAmount:K(p),baseToken:C,quoteToken:A,isLong:L,lendingMarketId:_},F),y=ie.mintBalanceZero(c?B:I,F);return this.repayFlashLoan({tx:F,clmmPool:d,repayBase:c?ie.intoBalance(a,I,F):y,repayQuote:c?y:ie.intoBalance(a,B,F),receipt:l,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:B}),ie.destroyBalanceZero(c?o:e,c?B:I,F),F};this.positionManageSizeWithdraw=async r=>{let{marketId:n,positionId:s,withdrawAmount:t,isQuote:u,txb:d,clmmPool:v,slippage:w,leverage:M}=r,{lendingMarketType:_,lendingMarketId:C}=Be(this._sdk.sdkOptions.suilend),A=d||new it,{baseToken:L,quoteToken:E}=await this.getLeverageMarketInfo(n),{isLong:N,deposits:U,borrows:j}=await this.getLeveragePosition(s),{reserve:I}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(L,E),B=u&&N||!u&&!N;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 J=null;if(B){let S=L,p=E;J=await this.findRouters(S,p,t,!1,[v]),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ routers:",{hasSwapRouters:J,from:S,to:p}),F=J?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",F);for(let S=0;S<I.length;S++){let p=Mt(new Uint8Array(I[S].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,p,BigInt(I[S].arrayIndex))}let{token:z}=j[0].reserve,V=K(U[0].depositedCtokenAmount.toString()).div(K(M)).toDP(0,Ye.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",V);let m=K(F).div(K(V)).toString(),b=K(j[0].borrowedAmount.toString()).mul(10**z.decimals).toString(),k=K(b).mul(m).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:508 ~ LeverageModules ~ repayAmount:",{\u9700\u8981\u507F\u8FD8\u591A\u5C11borrowAmount:k,\u63D0\u53D6\u4FDD\u8BC1\u91D1\u6570\u91CF:F,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:V});let x=await this._sdk.SuiLendModule.getSuilendClient(C,_),P=await this._sdk.PythConnection.getPriceFeedsUpdateData([U[0].reserve.priceIdentifier]),c=await x.pythClient.updatePriceFeeds(A,P,[U[0].reserve.priceIdentifier]),e=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:K(F),withdrawReserveArrayIndex:U[0].reserveArrayIndex.toString(),withdrawCoinType:N?L:E,baseToken:L,quoteToken:E,priceObjectId:c&&c[0]},A),o=N?L:E,l=N?E:L;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let f=await this.findRouters(o,l,K(k),!1,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:530 ~ LeverageModules ~ debtRouter:",{debtRouter:f,debtFrom:o,debtTo:l});let h;f&&(h=await this.routerSwap({router:f.route_obj,inputCoin:e,slippage:w,txb:A}));let g=A.splitCoins(h,[k]);return this.repay({txb:A,positionId:s,repayReserveArrayIndex:j[0].reserveArrayIndex.toString(),repayCoin:g,repayCoinType:N?E:L,repayAmount:K(0)}),A.transferObjects([h,g],this._sdk.getSenderAddress()),A};this.positionManageLeverageIncrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:u,targetLeverage:d,clmmPool:v,slippage:w}=r,{baseToken:M,quoteToken:_}=await this.getLeverageMarketInfo(n),{deposits:C,borrows:A}=await this.getLeveragePosition(s),{reserve:L}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_),{clmmPoolCoinTypeA:E,clmmPoolCoinTypeB:N,clmmFeeTier:U}=await this.getClmmPoolInfo(v),{lendingMarketId:j}=Be(this._sdk.sdkOptions.suilend),{token:I}=A[0].reserve,B=new it,F=K(A[0].borrowedAmount.toString()).mul(K(d).sub(K(u))).mul(10**I.decimals).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",F);let J=F,z=t?_:M,{balanceA:V,balanceB:m,receipt:b}=this.flashLoan({tx:B,amount:K(J),clmmPool:v,clmmPoolCoinTypeA:E,clmmPoolCoinTypeB:N,flashLoanCoin:z}),k=t?_:M,x=t?M:_,P=await this.findRouters(k,x,K(F),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:592 ~ LeverageModules ~ routers:",P,k,x);let c=await this.routerSwap({router:P?.route_obj,inputCoin:t?ie.fromBalance(m,N,B):ie.fromBalance(V,E,B),slippage:w,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?C[0].reserveArrayIndex.toString():A[0].reserveArrayIndex.toString(),inputCoin:c},B);let e=K(J).mul(K(1).add(U)).toDP(0,Ye.ROUND_UP).toString(),o=await this.borrowAsset({positionId:s,reserveArrayIndex:A[0].reserveArrayIndex.toString(),borrowAmount:K(e),baseToken:M,quoteToken:_,isLong:t,lendingMarketId:j},B),l=ie.mintBalanceZero(t?M:_,B),f=E===z;return this.repayFlashLoan({tx:B,clmmPool:v,repayBase:t?l:ie.intoBalance(o,M,B),repayQuote:t?ie.intoBalance(o,_,B):l,receipt:b,clmmPoolCoinTypeA:E,clmmPoolCoinTypeB:N}),ie.destroyBalanceZero(f?m:V,f?N:E,B),B};this.positionManageLeverageDecrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:u,targetLeverage:d,clmmPool:v,slippage:w}=r,{baseToken:M,quoteToken:_,closeFeeRate:C}=await this.getLeverageMarketInfo(n),{deposits:A,borrows:L}=await this.getLeveragePosition(s),{reserve:E}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_),{lendingMarketId:N,lendingMarketType:U}=Be(this._sdk.sdkOptions.suilend),j=new it,I=K(A[0].depositedCtokenAmount.toString()).mul(K(u).sub(K(d))).toString(),B=K(I).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",B);for(let P=0;P<E.length;P++){let c=Mt(new Uint8Array(E[P].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(j,c,BigInt(E[P].arrayIndex))}let F=await this._sdk.SuiLendModule.getSuilendClient(N,U),J=await this._sdk.PythConnection.getPriceFeedsUpdateData([A[0].reserve.priceIdentifier]),z=await F.pythClient.updatePriceFeeds(j,J,[A[0].reserve.priceIdentifier]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:672 ~ LeverageModules ~ baseToken:",M);let V=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:K(B),withdrawReserveArrayIndex:A[0].reserveArrayIndex.toString(),withdrawCoinType:t?M:_,baseToken:M,quoteToken:_,priceObjectId:z&&z[0]},j),m=t?M:_,b=t?_:M,k=await this.findRouters(m,b,K(B),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:681 ~ LeverageModules ~ routers:",k,k?.route_obj.paths,m,b);let x=await this.routerSwap({router:k?.route_obj,inputCoin:V,slippage:w,txb:j});return this.repay({txb:j,positionId:s,repayReserveArrayIndex:L[0].reserveArrayIndex.toString(),repayCoin:x,repayCoinType:t?_:M,repayAmount:K(0)}),x&&j.transferObjects([x],this._sdk.getSenderAddress()),j};this.leveragePositionClose=async(r,n)=>{let s=n||new it,{marketId:t,positionId:u}=r,{leverage:d}=this._sdk.sdkOptions,{global_config_id:v}=Be(this._sdk.sdkOptions.leverage),{lendingMarketType:w,lendingMarketId:M}=Be(this._sdk.sdkOptions.suilend),{baseToken:_,quoteToken:C}=await this.getLeverageMarketInfo(t),A=await this.getLeveragePosition(u);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:719 ~ LeverageModules ~ positionInfo:",A.original.id),s.moveCall({target:`${d.published_at}::position::close_Position`,typeArguments:[w,_,C],arguments:[s.object(v),s.object(t),s.object(u),$n(s,w,{obligationId:A.original.id,lendingMarket:s.object(M)}),s.object(ft)]}),s};this.positionRepay=async r=>{let{marketId:n,positionId:s,amount:t,isQuote:u,clmmPool:d,slippage:v}=r,{baseToken:w,quoteToken:M,isLong:_}=await this.getLeverageMarketInfo(n),{deposits:C,borrows:A}=await this.getLeveragePosition(s),{token:L}=A[0].reserve,E=K(A[0].borrowedAmount.toString()).mul(10**L.decimals),N=new it,U=A[0].reserve.coinType;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:751 ~ LeverageModules ~ repayCoinType:",U);let j=u?M==U:w==U,I,B=!1;if(j){let F=await this.findRouters(_?w:M,U,t,!0,[d]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:756 ~ LeverageModules ~ routers:",F?.amount_out.toString(),E.toString()),K(F?.amount_out.toString()).gte(E)&&(B=!0);let J=ie.buildCoinWithBalance(BigInt(t.toString()),_?w:M,N);I=await this.routerSwap({router:F?.route_obj,inputCoin:J,slippage:v,txb:N})}else t.gte(E)&&(B=!0),I=ie.buildCoinWithBalance(BigInt(t.toString()),_?M:w,N);if(this.repay({txb:N,positionId:s,repayReserveArrayIndex:A[0].reserveArrayIndex.toString(),repayCoin:I,repayCoinType:_?M:w,repayAmount:K(0)}),N.transferObjects([I],this._sdk.getSenderAddress()),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:786 ~ LeverageModules ~ isClose:",B),B){let{lendingMarketType:F,lendingMarketId:J}=Be(this._sdk.sdkOptions.suilend),z=await this._sdk.SuiLendModule.getSuilendClient(J,F),V=await this._sdk.PythConnection.getPriceFeedsUpdateData([C[0].reserve.priceIdentifier]),m=await z.pythClient.updatePriceFeeds(N,V,[C[0].reserve.priceIdentifier]);this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:K(C[0].depositedCtokenAmount.toString()),withdrawReserveArrayIndex:C[0].reserveArrayIndex.toString(),withdrawCoinType:_?w:M,baseToken:w,quoteToken:M,priceObjectId:m&&m[0]},N),this.leveragePositionClose({marketId:n,positionId:s},N)}return N};this.positionTopUpCoken=async r=>{let{marketId:n,positionId:s,amount:t,isQuote:u,clmmPool:d,slippage:v}=r,w=new it,{baseToken:M,quoteToken:_}=await this.getLeverageMarketInfo(n),{isLong:C}=await this.getLeveragePosition(s),A=C&&u||!C&&!u,L;if(A){let j=await this.findRouters(u?_:M,u?M:_,t,!0,[d]),I=ie.buildCoinWithBalance(BigInt(t.toString()),u?_:M,w);L=await this.routerSwap({router:j?.route_obj,inputCoin:I,slippage:v,txb:w})}else L=ie.buildCoinWithBalance(BigInt(t.toString()),u?_:M,w);let{baseReserveArrayIndex:E,quoteReserveArrayIndex:N,reserve:U}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_);return this.depositToLeveragePosition({isLong:C,marketId:n,positionId:s,depositReserveArrayIndex:C?E:N,inputCoin:L},w),w};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}=Be(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:t,clmmPool:u,clmmPoolCoinTypeA:d,clmmPoolCoinTypeB:v,flashLoanCoin:w,tx:M}=r,_=d===w,[C,A,L]=M.moveCall({target:`${n.published_at}::pool::flash_loan`,arguments:[M.object(s),M.object(u),M.pure.bool(_),M.pure.u64(t.toString())],typeArguments:[d,v]});return{balanceA:C,balanceB:A,receipt:L}};this.repayFlashLoan=r=>{let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:s}=Be(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:t,repayBase:u,repayQuote:d,receipt:v,clmmPool:w,clmmPoolCoinTypeA:M,clmmPoolCoinTypeB:_}=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(w),u,d,v],typeArguments:[M,_]}),t};this.borrowAsset=(r,n)=>{let{position:s,reserveArrayIndex:t,borrowAmount:u,baseToken:d,quoteToken:v,lendingMarketId:w,isLong:M,positionId:_}=r;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:677 ~ LeverageModules ~ params:",r);let{leverage:C}=this._sdk.sdkOptions,{lendingMarketType:A}=Be(this._sdk.sdkOptions.suilend);return ie.isSuiCoin(M?v:d)?n.moveCall({target:`${C.published_at}::position::borrow_sui`,typeArguments:[A],arguments:[n.object(w),s,n.pure.u64(t),n.pure.u64(u.toString()),n.object(gr),n.object(ft)]}):n.moveCall({target:`${C.published_at}::position::borrow_not_sui`,typeArguments:[A,M?v:d],arguments:[n.object(w),_?n.object(_):s,n.pure.u64(t),n.pure.u64(u.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:u}=Be(this._sdk.sdkOptions.suilend),{package_id:d}=this._sdk.sdkOptions.suilend,{marketId:v,positionId:w,withdrawAmount:M,withdrawReserveArrayIndex:_,withdrawCoinType:C,baseToken:A,quoteToken:L,priceObjectId:E}=r,[N]=n.moveCall({target:"0x1::option::none",typeArguments:[`${d}::lending_market::RateLimiterExemption<${u}, ${C}>`],arguments:[]});return ie.isSuiCoin(C)?n.moveCall({target:`${s.published_at}::position::withdraw_sui`,typeArguments:[u,A,L],arguments:[n.object(t),n.object(v),n.object(w),n.object(E),n.object(N),n.pure.u64(M.toString()),n.pure.u64(_),n.object(gr),n.object(ft)]}):n.moveCall({target:`${s.published_at}::position::withdraw_not_sui`,typeArguments:[u,A,L,C],arguments:[n.object(t),n.object(v),n.object(w),n.object(E),n.object(N),n.pure.u64(M.toString()),n.pure.u64(_),n.object(ft)]})};this.repay=r=>{let{leverage:n}=this._sdk.sdkOptions,{lendingMarketId:s,lendingMarketType:t}=Be(this._sdk.sdkOptions.suilend),{txb:u,positionId:d,repayAmount:v,repayCoinType:w,repayCoin:M,repayReserveArrayIndex:_}=r,C=u||new it,A=M||ie.buildCoinWithBalance(BigInt(v.toString()),w,C);C.moveCall({target:`${n.published_at}::position::repay`,typeArguments:[t,w],arguments:[C.object(s),C.object(d),A,C.pure.u64(_.toString()),C.object(ft)]})};this.routerSwap=async r=>{let{slippage:n,txb:s,inputCoin:t,router:u}=r,d=s||new it;if(u)return await this._sdk.AggregatorClient.routerSwap({router:u,inputCoin:t,slippage:n,txb:d})};this.calculateOpenPosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:u,slippage:d,leverage:v,baseToken:w,quoteToken:M}=r,_=s&&n||!s&&n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:1193 ~ LeverageModules ~ hasSwap:",_);let C=K(t).mul(v);if(_){let A=M,L=w,E=await this.findRouters(A,L,C,!0,[u]);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:1196 ~ LeverageModules ~ routers:",E,A,L),{amountIn:E?.amount_in.toString(),amountOut:E?.amount_out.toString(),amountOutLimit:K(E?.amount_out.toString()).mul(K(1).sub(d)).toDP(0,Ye.ROUND_DOWN).toString()}}else return{amountIn:t.toString(),amountOut:C.toString(),amountOutLimit:C.toString()}};this._sdk=r}async calculateFlashLoanParams(r){let{isLong:n,leverage:s,baseToken:t,quoteToken:u,initDepositAmount:d,reserve:v}=r,w=await this._sdk.SuiLendModule.getLatestPriceFeeds(v);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:587 ~ LeverageModules ~ calculateFlashLoanParams ~ priceUpdateData:",w,u,t);let M=w[pr(u)]?.price,_=w[pr(t)]?.price,C=n?K(_).div(K(M)).toString():K(M).div(K(_)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",d.toString(),n,C,M,_),{flashAmount:K(d).mul(s-1).mul(C).toDP(0,Ye.ROUND_UP).toString(),rate:C,quotePrice:M,basePrice:_}}createLeveragePosition(r){let{lendingMarketId:n,lendingMarketType:s}=Be(this._sdk.sdkOptions.suilend),{global_config_id:t}=Be(this._sdk.sdkOptions.leverage),u=this._sdk.sdkOptions.leverage,{leverage:d,marketId:v,baseToken:w,quoteToken:M,isLong:_,totalDepositAmount:C,tx:A}=r;return A.moveCall({target:`${u.published_at}::position::open_position`,arguments:[A.object(t),A.object(v),A.object(n),A.pure.u64(C),A.pure.u64(d*1e4),A.object(ft)],typeArguments:[s,w,M,_?w:M]})}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:u}=Be(this._sdk.sdkOptions.suilend),{isLong:d,marketId:v,position:w,positionId:M,depositReserveArrayIndex:_,inputCoin:C}=r,{baseToken:A,quoteToken:L}=await this.getLeverageMarketInfo(v);return n.moveCall({target:`${s.published_at}::position::deposit`,typeArguments:[t,A,L,d?A:L],arguments:[n.object(u),n.object(v),w||n.object(M),C,n.pure.u64(_),n.object(ft)]}),n}async findRouters(r,n,s,t,u){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},w=await this._sdk.AggregatorClient.findRouters(v);if(w?.error?.code===10001)return{...w,is_exceed:w.insufficientLiquidity};if(w?.insufficientLiquidity)return{...w,is_exceed:w.insufficientLiquidity};if(!w?.paths||w?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:w.amountIn.toString(),amount_out:w.amountOut.toString(),is_exceed:w.insufficientLiquidity,route_obj:w,byAmountIn:!0,originRes:w}}catch{try{if(u){let w=await this._sdk.AggregatorClient.swapInPools({from:r,target:n,amount:new mi.default(s.toFixed(0).toString()),byAmountIn:t,pools:u});return w?{amount_in:w.routeData.amountIn.toString(),amount_out:w.routeData.amountOut.toString(),is_exceed:w.isExceed,route_obj:w.routeData,byAmountIn:!0,originRes:w}: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 Ct(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};
2
2
  /*! Bundled license information:
3
3
 
4
4
  decimal.js/decimal.mjs: