llll-sdk 0.0.0-experimental-20260120162634 → 0.0.0-experimental-20260121164846

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 Fr=Object.create;var ir=Object.defineProperty;var Ur=Object.getOwnPropertyDescriptor;var jr=Object.getOwnPropertyNames;var $r=Object.getPrototypeOf,Wr=Object.prototype.hasOwnProperty;var Zr=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(i,r)=>(typeof require<"u"?require:i)[r]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var Kr=(n,i)=>()=>(i||n((i={exports:{}}).exports,i),i.exports);var zr=(n,i,r,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of jr(i))!Wr.call(n,t)&&t!==r&&ir(n,t,{get:()=>i[t],enumerable:!(o=Ur(i,t))||o.enumerable});return n};var Gr=(n,i,r)=>(r=n!=null?Fr($r(n)):{},zr(i||!n||!n.__esModule?ir(r,"default",{value:n,enumerable:!0}):r,n));var Er=Kr((Nr,Ui)=>{"use strict";(function(n,i){"use strict";function r(p,e){if(!p)throw new Error(e||"Assertion failed")}function o(p,e){p.super_=e;var s=function(){};s.prototype=e.prototype,p.prototype=new s,p.prototype.constructor=p}function t(p,e,s){if(t.isBN(p))return p;this.negative=0,this.words=null,this.length=0,this.red=null,p!==null&&((e==="le"||e==="be")&&(s=e,e=10),this._init(p||0,e||10,s||"be"))}typeof n=="object"?n.exports=t:i.BN=t,t.BN=t,t.wordSize=26;var a;try{typeof window<"u"&&typeof window.Buffer<"u"?a=window.Buffer:a=Zr("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,s){return e.cmp(s)>0?e:s},t.min=function(e,s){return e.cmp(s)<0?e:s},t.prototype._init=function(e,s,l){if(typeof e=="number")return this._initNumber(e,s,l);if(typeof e=="object")return this._initArray(e,s,l);s==="hex"&&(s=16),r(s===(s|0)&&s>=2&&s<=36),e=e.toString().replace(/\s+/g,"");var f=0;e[0]==="-"&&(f++,this.negative=1),f<e.length&&(s===16?this._parseHex(e,f,l):(this._parseBase(e,s,f),l==="le"&&this._initArray(this.toArray(),s,l)))},t.prototype._initNumber=function(e,s,l){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[e&67108863],this.length=1):e<4503599627370496?(this.words=[e&67108863,e/67108864&67108863],this.length=2):(r(e<9007199254740992),this.words=[e&67108863,e/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),s,l)},t.prototype._initArray=function(e,s,l){if(r(typeof e.length=="number"),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var h,v,k=0;if(l==="be")for(f=e.length-1,h=0;f>=0;f-=3)v=e[f]|e[f-1]<<8|e[f-2]<<16,this.words[h]|=v<<k&67108863,this.words[h+1]=v>>>26-k&67108863,k+=24,k>=26&&(k-=26,h++);else if(l==="le")for(f=0,h=0;f<e.length;f+=3)v=e[f]|e[f+1]<<8|e[f+2]<<16,this.words[h]|=v<<k&67108863,this.words[h+1]=v>>>26-k&67108863,k+=24,k>=26&&(k-=26,h++);return this._strip()};function d(p,e){var s=p.charCodeAt(e);if(s>=48&&s<=57)return s-48;if(s>=65&&s<=70)return s-55;if(s>=97&&s<=102)return s-87;r(!1,"Invalid character in "+p)}function c(p,e,s){var l=d(p,s);return s-1>=e&&(l|=d(p,s-1)<<4),l}t.prototype._parseHex=function(e,s,l){this.length=Math.ceil((e.length-s)/6),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var h=0,v=0,k;if(l==="be")for(f=e.length-1;f>=s;f-=2)k=c(e,s,f)<<h,this.words[v]|=k&67108863,h>=18?(h-=18,v+=1,this.words[v]|=k>>>26):h+=8;else{var w=e.length-s;for(f=w%2===0?s+1:s;f<e.length;f+=2)k=c(e,s,f)<<h,this.words[v]|=k&67108863,h>=18?(h-=18,v+=1,this.words[v]|=k>>>26):h+=8}this._strip()};function m(p,e,s,l){for(var f=0,h=0,v=Math.min(p.length,s),k=e;k<v;k++){var w=p.charCodeAt(k)-48;f*=l,w>=49?h=w-49+10:w>=17?h=w-17+10:h=w,r(w>=0&&h<l,"Invalid character"),f+=h}return f}t.prototype._parseBase=function(e,s,l){this.words=[0],this.length=1;for(var f=0,h=1;h<=67108863;h*=s)f++;f--,h=h/s|0;for(var v=e.length-l,k=v%f,w=Math.min(v,v-k)+l,u=0,y=l;y<w;y+=f)u=m(e,y,y+f,s),this.imuln(h),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(k!==0){var $=1;for(u=m(e,y,e.length,s),y=0;y<k;y++)$*=s;this.imuln($),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},t.prototype.copy=function(e){e.words=new Array(this.length);for(var s=0;s<this.length;s++)e.words[s]=this.words[s];e.length=this.length,e.negative=this.negative,e.red=this.red};function g(p,e){p.words=e.words,p.length=e.length,p.negative=e.negative,p.red=e.red}if(t.prototype._move=function(e){g(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")]=M}catch{t.prototype.inspect=M}else t.prototype.inspect=M;function M(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var P=["","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],D=[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,s){e=e||10,s=s|0||1;var l;if(e===16||e==="hex"){l="";for(var f=0,h=0,v=0;v<this.length;v++){var k=this.words[v],w=((k<<f|h)&16777215).toString(16);h=k>>>24-f&16777215,f+=2,f>=26&&(f-=26,v--),h!==0||v!==this.length-1?l=P[6-w.length]+w+l:l=w+l}for(h!==0&&(l=h.toString(16)+l);l.length%s!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(e===(e|0)&&e>=2&&e<=36){var u=A[e],y=D[e];l="";var $=this.clone();for($.negative=0;!$.isZero();){var F=$.modrn(y).toString(e);$=$.idivn(y),$.isZero()?l=F+l:l=P[u-F.length]+F+l}for(this.isZero()&&(l="0"+l);l.length%s!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}r(!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&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-e:e},t.prototype.toJSON=function(){return this.toString(16,2)},a&&(t.prototype.toBuffer=function(e,s){return this.toArrayLike(a,e,s)}),t.prototype.toArray=function(e,s){return this.toArrayLike(Array,e,s)};var T=function(e,s){return e.allocUnsafe?e.allocUnsafe(s):new e(s)};t.prototype.toArrayLike=function(e,s,l){this._strip();var f=this.byteLength(),h=l||Math.max(1,f);r(f<=h,"byte array longer than desired length"),r(h>0,"Requested array length <= 0");var v=T(e,h),k=s==="le"?"LE":"BE";return this["_toArrayLike"+k](v,f),v},t.prototype._toArrayLikeLE=function(e,s){for(var l=0,f=0,h=0,v=0;h<this.length;h++){var k=this.words[h]<<v|f;e[l++]=k&255,l<e.length&&(e[l++]=k>>8&255),l<e.length&&(e[l++]=k>>16&255),v===6?(l<e.length&&(e[l++]=k>>24&255),f=0,v=0):(f=k>>>24,v+=2)}if(l<e.length)for(e[l++]=f;l<e.length;)e[l++]=0},t.prototype._toArrayLikeBE=function(e,s){for(var l=e.length-1,f=0,h=0,v=0;h<this.length;h++){var k=this.words[h]<<v|f;e[l--]=k&255,l>=0&&(e[l--]=k>>8&255),l>=0&&(e[l--]=k>>16&255),v===6?(l>=0&&(e[l--]=k>>24&255),f=0,v=0):(f=k>>>24,v+=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 s=e,l=0;return s>=4096&&(l+=13,s>>>=13),s>=64&&(l+=7,s>>>=7),s>=8&&(l+=4,s>>>=4),s>=2&&(l+=2,s>>>=2),l+s},t.prototype._zeroBits=function(e){if(e===0)return 26;var s=e,l=0;return(s&8191)===0&&(l+=13,s>>>=13),(s&127)===0&&(l+=7,s>>>=7),(s&15)===0&&(l+=4,s>>>=4),(s&3)===0&&(l+=2,s>>>=2),(s&1)===0&&l++,l},t.prototype.bitLength=function(){var e=this.words[this.length-1],s=this._countBits(e);return(this.length-1)*26+s};function L(p){for(var e=new Array(p.bitLength()),s=0;s<e.length;s++){var l=s/26|0,f=s%26;e[s]=p.words[l]>>>f&1}return e}t.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,s=0;s<this.length;s++){var l=this._zeroBits(this.words[s]);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 s=0;s<e.length;s++)this.words[s]=this.words[s]|e.words[s];return this._strip()},t.prototype.ior=function(e){return r((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 s;this.length>e.length?s=e:s=this;for(var l=0;l<s.length;l++)this.words[l]=this.words[l]&e.words[l];return this.length=s.length,this._strip()},t.prototype.iand=function(e){return r((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 s,l;this.length>e.length?(s=this,l=e):(s=e,l=this);for(var f=0;f<l.length;f++)this.words[f]=s.words[f]^l.words[f];if(this!==s)for(;f<s.length;f++)this.words[f]=s.words[f];return this.length=s.length,this._strip()},t.prototype.ixor=function(e){return r((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){r(typeof e=="number"&&e>=0);var s=Math.ceil(e/26)|0,l=e%26;this._expand(s),l>0&&s--;for(var f=0;f<s;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,s){r(typeof e=="number"&&e>=0);var l=e/26|0,f=e%26;return this._expand(l+1),s?this.words[l]=this.words[l]|1<<f:this.words[l]=this.words[l]&~(1<<f),this._strip()},t.prototype.iadd=function(e){var s;if(this.negative!==0&&e.negative===0)return this.negative=0,s=this.isub(e),this.negative^=1,this._normSign();if(this.negative===0&&e.negative!==0)return e.negative=0,s=this.isub(e),e.negative=1,s._normSign();var l,f;this.length>e.length?(l=this,f=e):(l=e,f=this);for(var h=0,v=0;v<f.length;v++)s=(l.words[v]|0)+(f.words[v]|0)+h,this.words[v]=s&67108863,h=s>>>26;for(;h!==0&&v<l.length;v++)s=(l.words[v]|0)+h,this.words[v]=s&67108863,h=s>>>26;if(this.length=l.length,h!==0)this.words[this.length]=h,this.length++;else if(l!==this)for(;v<l.length;v++)this.words[v]=l.words[v];return this},t.prototype.add=function(e){var s;return e.negative!==0&&this.negative===0?(e.negative=0,s=this.sub(e),e.negative^=1,s):e.negative===0&&this.negative!==0?(this.negative=0,s=e.sub(this),this.negative=1,s):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 s=this.iadd(e);return e.negative=1,s._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 v=0,k=0;k<h.length;k++)s=(f.words[k]|0)-(h.words[k]|0)+v,v=s>>26,this.words[k]=s&67108863;for(;v!==0&&k<f.length;k++)s=(f.words[k]|0)+v,v=s>>26,this.words[k]=s&67108863;if(v===0&&k<f.length&&f!==this)for(;k<f.length;k++)this.words[k]=f.words[k];return this.length=Math.max(this.length,k),f!==this&&(this.negative=1),this._strip()},t.prototype.sub=function(e){return this.clone().isub(e)};function N(p,e,s){s.negative=e.negative^p.negative;var l=p.length+e.length|0;s.length=l,l=l-1|0;var f=p.words[0]|0,h=e.words[0]|0,v=f*h,k=v&67108863,w=v/67108864|0;s.words[0]=k;for(var u=1;u<l;u++){for(var y=w>>>26,$=w&67108863,F=Math.min(u,e.length-1),j=Math.max(0,u-p.length+1);j<=F;j++){var K=u-j|0;f=p.words[K]|0,h=e.words[j]|0,v=f*h+$,y+=v/67108864|0,$=v&67108863}s.words[u]=$|0,w=y|0}return w!==0?s.words[u]=w|0:s.length--,s._strip()}var R=function(e,s,l){var f=e.words,h=s.words,v=l.words,k=0,w,u,y,$=f[0]|0,F=$&8191,j=$>>>13,K=f[1]|0,G=K&8191,J=K>>>13,rt=f[2]|0,V=rt&8191,it=rt>>>13,ut=f[3]|0,et=ut&8191,X=ut>>>13,de=f[4]|0,ct=de&8191,st=de>>>13,ke=f[5]|0,nt=ke&8191,at=ke>>>13,ue=f[6]|0,dt=ue&8191,pt=ue>>>13,Wi=f[7]|0,mt=Wi&8191,gt=Wi>>>13,Zi=f[8]|0,_t=Zi&8191,wt=Zi>>>13,Ki=f[9]|0,vt=Ki&8191,Mt=Ki>>>13,zi=h[0]|0,bt=zi&8191,yt=zi>>>13,Gi=h[1]|0,kt=Gi&8191,St=Gi>>>13,Hi=h[2]|0,Pt=Hi&8191,At=Hi>>>13,Vi=h[3]|0,Ct=Vi&8191,xt=Vi>>>13,Xi=h[4]|0,Dt=Xi&8191,Tt=Xi>>>13,Ji=h[5]|0,Ot=Ji&8191,Rt=Ji>>>13,Yi=h[6]|0,Lt=Yi&8191,Nt=Yi>>>13,Qi=h[7]|0,Et=Qi&8191,It=Qi>>>13,tr=h[8]|0,Bt=tr&8191,qt=tr>>>13,er=h[9]|0,Ft=er&8191,Ut=er>>>13;l.negative=e.negative^s.negative,l.length=19,w=Math.imul(F,bt),u=Math.imul(F,yt),u=u+Math.imul(j,bt)|0,y=Math.imul(j,yt);var ii=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,w=Math.imul(G,bt),u=Math.imul(G,yt),u=u+Math.imul(J,bt)|0,y=Math.imul(J,yt),w=w+Math.imul(F,kt)|0,u=u+Math.imul(F,St)|0,u=u+Math.imul(j,kt)|0,y=y+Math.imul(j,St)|0;var ri=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,w=Math.imul(V,bt),u=Math.imul(V,yt),u=u+Math.imul(it,bt)|0,y=Math.imul(it,yt),w=w+Math.imul(G,kt)|0,u=u+Math.imul(G,St)|0,u=u+Math.imul(J,kt)|0,y=y+Math.imul(J,St)|0,w=w+Math.imul(F,Pt)|0,u=u+Math.imul(F,At)|0,u=u+Math.imul(j,Pt)|0,y=y+Math.imul(j,At)|0;var ni=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,w=Math.imul(et,bt),u=Math.imul(et,yt),u=u+Math.imul(X,bt)|0,y=Math.imul(X,yt),w=w+Math.imul(V,kt)|0,u=u+Math.imul(V,St)|0,u=u+Math.imul(it,kt)|0,y=y+Math.imul(it,St)|0,w=w+Math.imul(G,Pt)|0,u=u+Math.imul(G,At)|0,u=u+Math.imul(J,Pt)|0,y=y+Math.imul(J,At)|0,w=w+Math.imul(F,Ct)|0,u=u+Math.imul(F,xt)|0,u=u+Math.imul(j,Ct)|0,y=y+Math.imul(j,xt)|0;var oi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,w=Math.imul(ct,bt),u=Math.imul(ct,yt),u=u+Math.imul(st,bt)|0,y=Math.imul(st,yt),w=w+Math.imul(et,kt)|0,u=u+Math.imul(et,St)|0,u=u+Math.imul(X,kt)|0,y=y+Math.imul(X,St)|0,w=w+Math.imul(V,Pt)|0,u=u+Math.imul(V,At)|0,u=u+Math.imul(it,Pt)|0,y=y+Math.imul(it,At)|0,w=w+Math.imul(G,Ct)|0,u=u+Math.imul(G,xt)|0,u=u+Math.imul(J,Ct)|0,y=y+Math.imul(J,xt)|0,w=w+Math.imul(F,Dt)|0,u=u+Math.imul(F,Tt)|0,u=u+Math.imul(j,Dt)|0,y=y+Math.imul(j,Tt)|0;var si=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(si>>>26)|0,si&=67108863,w=Math.imul(nt,bt),u=Math.imul(nt,yt),u=u+Math.imul(at,bt)|0,y=Math.imul(at,yt),w=w+Math.imul(ct,kt)|0,u=u+Math.imul(ct,St)|0,u=u+Math.imul(st,kt)|0,y=y+Math.imul(st,St)|0,w=w+Math.imul(et,Pt)|0,u=u+Math.imul(et,At)|0,u=u+Math.imul(X,Pt)|0,y=y+Math.imul(X,At)|0,w=w+Math.imul(V,Ct)|0,u=u+Math.imul(V,xt)|0,u=u+Math.imul(it,Ct)|0,y=y+Math.imul(it,xt)|0,w=w+Math.imul(G,Dt)|0,u=u+Math.imul(G,Tt)|0,u=u+Math.imul(J,Dt)|0,y=y+Math.imul(J,Tt)|0,w=w+Math.imul(F,Ot)|0,u=u+Math.imul(F,Rt)|0,u=u+Math.imul(j,Ot)|0,y=y+Math.imul(j,Rt)|0;var ai=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,w=Math.imul(dt,bt),u=Math.imul(dt,yt),u=u+Math.imul(pt,bt)|0,y=Math.imul(pt,yt),w=w+Math.imul(nt,kt)|0,u=u+Math.imul(nt,St)|0,u=u+Math.imul(at,kt)|0,y=y+Math.imul(at,St)|0,w=w+Math.imul(ct,Pt)|0,u=u+Math.imul(ct,At)|0,u=u+Math.imul(st,Pt)|0,y=y+Math.imul(st,At)|0,w=w+Math.imul(et,Ct)|0,u=u+Math.imul(et,xt)|0,u=u+Math.imul(X,Ct)|0,y=y+Math.imul(X,xt)|0,w=w+Math.imul(V,Dt)|0,u=u+Math.imul(V,Tt)|0,u=u+Math.imul(it,Dt)|0,y=y+Math.imul(it,Tt)|0,w=w+Math.imul(G,Ot)|0,u=u+Math.imul(G,Rt)|0,u=u+Math.imul(J,Ot)|0,y=y+Math.imul(J,Rt)|0,w=w+Math.imul(F,Lt)|0,u=u+Math.imul(F,Nt)|0,u=u+Math.imul(j,Lt)|0,y=y+Math.imul(j,Nt)|0;var li=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(li>>>26)|0,li&=67108863,w=Math.imul(mt,bt),u=Math.imul(mt,yt),u=u+Math.imul(gt,bt)|0,y=Math.imul(gt,yt),w=w+Math.imul(dt,kt)|0,u=u+Math.imul(dt,St)|0,u=u+Math.imul(pt,kt)|0,y=y+Math.imul(pt,St)|0,w=w+Math.imul(nt,Pt)|0,u=u+Math.imul(nt,At)|0,u=u+Math.imul(at,Pt)|0,y=y+Math.imul(at,At)|0,w=w+Math.imul(ct,Ct)|0,u=u+Math.imul(ct,xt)|0,u=u+Math.imul(st,Ct)|0,y=y+Math.imul(st,xt)|0,w=w+Math.imul(et,Dt)|0,u=u+Math.imul(et,Tt)|0,u=u+Math.imul(X,Dt)|0,y=y+Math.imul(X,Tt)|0,w=w+Math.imul(V,Ot)|0,u=u+Math.imul(V,Rt)|0,u=u+Math.imul(it,Ot)|0,y=y+Math.imul(it,Rt)|0,w=w+Math.imul(G,Lt)|0,u=u+Math.imul(G,Nt)|0,u=u+Math.imul(J,Lt)|0,y=y+Math.imul(J,Nt)|0,w=w+Math.imul(F,Et)|0,u=u+Math.imul(F,It)|0,u=u+Math.imul(j,Et)|0,y=y+Math.imul(j,It)|0;var ui=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ui>>>26)|0,ui&=67108863,w=Math.imul(_t,bt),u=Math.imul(_t,yt),u=u+Math.imul(wt,bt)|0,y=Math.imul(wt,yt),w=w+Math.imul(mt,kt)|0,u=u+Math.imul(mt,St)|0,u=u+Math.imul(gt,kt)|0,y=y+Math.imul(gt,St)|0,w=w+Math.imul(dt,Pt)|0,u=u+Math.imul(dt,At)|0,u=u+Math.imul(pt,Pt)|0,y=y+Math.imul(pt,At)|0,w=w+Math.imul(nt,Ct)|0,u=u+Math.imul(nt,xt)|0,u=u+Math.imul(at,Ct)|0,y=y+Math.imul(at,xt)|0,w=w+Math.imul(ct,Dt)|0,u=u+Math.imul(ct,Tt)|0,u=u+Math.imul(st,Dt)|0,y=y+Math.imul(st,Tt)|0,w=w+Math.imul(et,Ot)|0,u=u+Math.imul(et,Rt)|0,u=u+Math.imul(X,Ot)|0,y=y+Math.imul(X,Rt)|0,w=w+Math.imul(V,Lt)|0,u=u+Math.imul(V,Nt)|0,u=u+Math.imul(it,Lt)|0,y=y+Math.imul(it,Nt)|0,w=w+Math.imul(G,Et)|0,u=u+Math.imul(G,It)|0,u=u+Math.imul(J,Et)|0,y=y+Math.imul(J,It)|0,w=w+Math.imul(F,Bt)|0,u=u+Math.imul(F,qt)|0,u=u+Math.imul(j,Bt)|0,y=y+Math.imul(j,qt)|0;var ci=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ci>>>26)|0,ci&=67108863,w=Math.imul(vt,bt),u=Math.imul(vt,yt),u=u+Math.imul(Mt,bt)|0,y=Math.imul(Mt,yt),w=w+Math.imul(_t,kt)|0,u=u+Math.imul(_t,St)|0,u=u+Math.imul(wt,kt)|0,y=y+Math.imul(wt,St)|0,w=w+Math.imul(mt,Pt)|0,u=u+Math.imul(mt,At)|0,u=u+Math.imul(gt,Pt)|0,y=y+Math.imul(gt,At)|0,w=w+Math.imul(dt,Ct)|0,u=u+Math.imul(dt,xt)|0,u=u+Math.imul(pt,Ct)|0,y=y+Math.imul(pt,xt)|0,w=w+Math.imul(nt,Dt)|0,u=u+Math.imul(nt,Tt)|0,u=u+Math.imul(at,Dt)|0,y=y+Math.imul(at,Tt)|0,w=w+Math.imul(ct,Ot)|0,u=u+Math.imul(ct,Rt)|0,u=u+Math.imul(st,Ot)|0,y=y+Math.imul(st,Rt)|0,w=w+Math.imul(et,Lt)|0,u=u+Math.imul(et,Nt)|0,u=u+Math.imul(X,Lt)|0,y=y+Math.imul(X,Nt)|0,w=w+Math.imul(V,Et)|0,u=u+Math.imul(V,It)|0,u=u+Math.imul(it,Et)|0,y=y+Math.imul(it,It)|0,w=w+Math.imul(G,Bt)|0,u=u+Math.imul(G,qt)|0,u=u+Math.imul(J,Bt)|0,y=y+Math.imul(J,qt)|0,w=w+Math.imul(F,Ft)|0,u=u+Math.imul(F,Ut)|0,u=u+Math.imul(j,Ft)|0,y=y+Math.imul(j,Ut)|0;var fi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(fi>>>26)|0,fi&=67108863,w=Math.imul(vt,kt),u=Math.imul(vt,St),u=u+Math.imul(Mt,kt)|0,y=Math.imul(Mt,St),w=w+Math.imul(_t,Pt)|0,u=u+Math.imul(_t,At)|0,u=u+Math.imul(wt,Pt)|0,y=y+Math.imul(wt,At)|0,w=w+Math.imul(mt,Ct)|0,u=u+Math.imul(mt,xt)|0,u=u+Math.imul(gt,Ct)|0,y=y+Math.imul(gt,xt)|0,w=w+Math.imul(dt,Dt)|0,u=u+Math.imul(dt,Tt)|0,u=u+Math.imul(pt,Dt)|0,y=y+Math.imul(pt,Tt)|0,w=w+Math.imul(nt,Ot)|0,u=u+Math.imul(nt,Rt)|0,u=u+Math.imul(at,Ot)|0,y=y+Math.imul(at,Rt)|0,w=w+Math.imul(ct,Lt)|0,u=u+Math.imul(ct,Nt)|0,u=u+Math.imul(st,Lt)|0,y=y+Math.imul(st,Nt)|0,w=w+Math.imul(et,Et)|0,u=u+Math.imul(et,It)|0,u=u+Math.imul(X,Et)|0,y=y+Math.imul(X,It)|0,w=w+Math.imul(V,Bt)|0,u=u+Math.imul(V,qt)|0,u=u+Math.imul(it,Bt)|0,y=y+Math.imul(it,qt)|0,w=w+Math.imul(G,Ft)|0,u=u+Math.imul(G,Ut)|0,u=u+Math.imul(J,Ft)|0,y=y+Math.imul(J,Ut)|0;var di=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(di>>>26)|0,di&=67108863,w=Math.imul(vt,Pt),u=Math.imul(vt,At),u=u+Math.imul(Mt,Pt)|0,y=Math.imul(Mt,At),w=w+Math.imul(_t,Ct)|0,u=u+Math.imul(_t,xt)|0,u=u+Math.imul(wt,Ct)|0,y=y+Math.imul(wt,xt)|0,w=w+Math.imul(mt,Dt)|0,u=u+Math.imul(mt,Tt)|0,u=u+Math.imul(gt,Dt)|0,y=y+Math.imul(gt,Tt)|0,w=w+Math.imul(dt,Ot)|0,u=u+Math.imul(dt,Rt)|0,u=u+Math.imul(pt,Ot)|0,y=y+Math.imul(pt,Rt)|0,w=w+Math.imul(nt,Lt)|0,u=u+Math.imul(nt,Nt)|0,u=u+Math.imul(at,Lt)|0,y=y+Math.imul(at,Nt)|0,w=w+Math.imul(ct,Et)|0,u=u+Math.imul(ct,It)|0,u=u+Math.imul(st,Et)|0,y=y+Math.imul(st,It)|0,w=w+Math.imul(et,Bt)|0,u=u+Math.imul(et,qt)|0,u=u+Math.imul(X,Bt)|0,y=y+Math.imul(X,qt)|0,w=w+Math.imul(V,Ft)|0,u=u+Math.imul(V,Ut)|0,u=u+Math.imul(it,Ft)|0,y=y+Math.imul(it,Ut)|0;var hi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(hi>>>26)|0,hi&=67108863,w=Math.imul(vt,Ct),u=Math.imul(vt,xt),u=u+Math.imul(Mt,Ct)|0,y=Math.imul(Mt,xt),w=w+Math.imul(_t,Dt)|0,u=u+Math.imul(_t,Tt)|0,u=u+Math.imul(wt,Dt)|0,y=y+Math.imul(wt,Tt)|0,w=w+Math.imul(mt,Ot)|0,u=u+Math.imul(mt,Rt)|0,u=u+Math.imul(gt,Ot)|0,y=y+Math.imul(gt,Rt)|0,w=w+Math.imul(dt,Lt)|0,u=u+Math.imul(dt,Nt)|0,u=u+Math.imul(pt,Lt)|0,y=y+Math.imul(pt,Nt)|0,w=w+Math.imul(nt,Et)|0,u=u+Math.imul(nt,It)|0,u=u+Math.imul(at,Et)|0,y=y+Math.imul(at,It)|0,w=w+Math.imul(ct,Bt)|0,u=u+Math.imul(ct,qt)|0,u=u+Math.imul(st,Bt)|0,y=y+Math.imul(st,qt)|0,w=w+Math.imul(et,Ft)|0,u=u+Math.imul(et,Ut)|0,u=u+Math.imul(X,Ft)|0,y=y+Math.imul(X,Ut)|0;var pi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(pi>>>26)|0,pi&=67108863,w=Math.imul(vt,Dt),u=Math.imul(vt,Tt),u=u+Math.imul(Mt,Dt)|0,y=Math.imul(Mt,Tt),w=w+Math.imul(_t,Ot)|0,u=u+Math.imul(_t,Rt)|0,u=u+Math.imul(wt,Ot)|0,y=y+Math.imul(wt,Rt)|0,w=w+Math.imul(mt,Lt)|0,u=u+Math.imul(mt,Nt)|0,u=u+Math.imul(gt,Lt)|0,y=y+Math.imul(gt,Nt)|0,w=w+Math.imul(dt,Et)|0,u=u+Math.imul(dt,It)|0,u=u+Math.imul(pt,Et)|0,y=y+Math.imul(pt,It)|0,w=w+Math.imul(nt,Bt)|0,u=u+Math.imul(nt,qt)|0,u=u+Math.imul(at,Bt)|0,y=y+Math.imul(at,qt)|0,w=w+Math.imul(ct,Ft)|0,u=u+Math.imul(ct,Ut)|0,u=u+Math.imul(st,Ft)|0,y=y+Math.imul(st,Ut)|0;var mi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(mi>>>26)|0,mi&=67108863,w=Math.imul(vt,Ot),u=Math.imul(vt,Rt),u=u+Math.imul(Mt,Ot)|0,y=Math.imul(Mt,Rt),w=w+Math.imul(_t,Lt)|0,u=u+Math.imul(_t,Nt)|0,u=u+Math.imul(wt,Lt)|0,y=y+Math.imul(wt,Nt)|0,w=w+Math.imul(mt,Et)|0,u=u+Math.imul(mt,It)|0,u=u+Math.imul(gt,Et)|0,y=y+Math.imul(gt,It)|0,w=w+Math.imul(dt,Bt)|0,u=u+Math.imul(dt,qt)|0,u=u+Math.imul(pt,Bt)|0,y=y+Math.imul(pt,qt)|0,w=w+Math.imul(nt,Ft)|0,u=u+Math.imul(nt,Ut)|0,u=u+Math.imul(at,Ft)|0,y=y+Math.imul(at,Ut)|0;var gi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(gi>>>26)|0,gi&=67108863,w=Math.imul(vt,Lt),u=Math.imul(vt,Nt),u=u+Math.imul(Mt,Lt)|0,y=Math.imul(Mt,Nt),w=w+Math.imul(_t,Et)|0,u=u+Math.imul(_t,It)|0,u=u+Math.imul(wt,Et)|0,y=y+Math.imul(wt,It)|0,w=w+Math.imul(mt,Bt)|0,u=u+Math.imul(mt,qt)|0,u=u+Math.imul(gt,Bt)|0,y=y+Math.imul(gt,qt)|0,w=w+Math.imul(dt,Ft)|0,u=u+Math.imul(dt,Ut)|0,u=u+Math.imul(pt,Ft)|0,y=y+Math.imul(pt,Ut)|0;var _i=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(_i>>>26)|0,_i&=67108863,w=Math.imul(vt,Et),u=Math.imul(vt,It),u=u+Math.imul(Mt,Et)|0,y=Math.imul(Mt,It),w=w+Math.imul(_t,Bt)|0,u=u+Math.imul(_t,qt)|0,u=u+Math.imul(wt,Bt)|0,y=y+Math.imul(wt,qt)|0,w=w+Math.imul(mt,Ft)|0,u=u+Math.imul(mt,Ut)|0,u=u+Math.imul(gt,Ft)|0,y=y+Math.imul(gt,Ut)|0;var wi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(wi>>>26)|0,wi&=67108863,w=Math.imul(vt,Bt),u=Math.imul(vt,qt),u=u+Math.imul(Mt,Bt)|0,y=Math.imul(Mt,qt),w=w+Math.imul(_t,Ft)|0,u=u+Math.imul(_t,Ut)|0,u=u+Math.imul(wt,Ft)|0,y=y+Math.imul(wt,Ut)|0;var vi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(vi>>>26)|0,vi&=67108863,w=Math.imul(vt,Ft),u=Math.imul(vt,Ut),u=u+Math.imul(Mt,Ft)|0,y=Math.imul(Mt,Ut);var Mi=(k+w|0)+((u&8191)<<13)|0;return k=(y+(u>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,v[0]=ii,v[1]=ri,v[2]=ni,v[3]=oi,v[4]=si,v[5]=ai,v[6]=li,v[7]=ui,v[8]=ci,v[9]=fi,v[10]=di,v[11]=hi,v[12]=pi,v[13]=mi,v[14]=gi,v[15]=_i,v[16]=wi,v[17]=vi,v[18]=Mi,k!==0&&(v[19]=k,l.length++),l};Math.imul||(R=N);function O(p,e,s){s.negative=e.negative^p.negative,s.length=p.length+e.length;for(var l=0,f=0,h=0;h<s.length-1;h++){var v=f;f=0;for(var k=l&67108863,w=Math.min(h,e.length-1),u=Math.max(0,h-p.length+1);u<=w;u++){var y=h-u,$=p.words[y]|0,F=e.words[u]|0,j=$*F,K=j&67108863;v=v+(j/67108864|0)|0,K=K+k|0,k=K&67108863,v=v+(K>>>26)|0,f+=v>>>26,v&=67108863}s.words[h]=k,l=v,v=f}return l!==0?s.words[h]=l:s.length--,s._strip()}function I(p,e,s){return O(p,e,s)}t.prototype.mulTo=function(e,s){var l,f=this.length+e.length;return this.length===10&&e.length===10?l=R(this,e,s):f<63?l=N(this,e,s):f<1024?l=O(this,e,s):l=I(this,e,s),l};function U(p,e){this.x=p,this.y=e}U.prototype.makeRBT=function(e){for(var s=new Array(e),l=t.prototype._countBits(e)-1,f=0;f<e;f++)s[f]=this.revBin(f,l,e);return s},U.prototype.revBin=function(e,s,l){if(e===0||e===l-1)return e;for(var f=0,h=0;h<s;h++)f|=(e&1)<<s-h-1,e>>=1;return f},U.prototype.permute=function(e,s,l,f,h,v){for(var k=0;k<v;k++)f[k]=s[e[k]],h[k]=l[e[k]]},U.prototype.transform=function(e,s,l,f,h,v){this.permute(v,e,s,l,f,h);for(var k=1;k<h;k<<=1)for(var w=k<<1,u=Math.cos(2*Math.PI/w),y=Math.sin(2*Math.PI/w),$=0;$<h;$+=w)for(var F=u,j=y,K=0;K<k;K++){var G=l[$+K],J=f[$+K],rt=l[$+K+k],V=f[$+K+k],it=F*rt-j*V;V=F*V+j*rt,rt=it,l[$+K]=G+rt,f[$+K]=J+V,l[$+K+k]=G-rt,f[$+K+k]=J-V,K!==w&&(it=u*F-y*j,j=u*j+y*F,F=it)}},U.prototype.guessLen13b=function(e,s){var l=Math.max(s,e)|1,f=l&1,h=0;for(l=l/2|0;l;l=l>>>1)h++;return 1<<h+1+f},U.prototype.conjugate=function(e,s,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=s[f],s[f]=-s[l-f-1],s[l-f-1]=-h}},U.prototype.normalize13b=function(e,s){for(var l=0,f=0;f<s/2;f++){var h=Math.round(e[2*f+1]/s)*8192+Math.round(e[2*f]/s)+l;e[f]=h&67108863,h<67108864?l=0:l=h/67108864|0}return e},U.prototype.convert13b=function(e,s,l,f){for(var h=0,v=0;v<s;v++)h=h+(e[v]|0),l[2*v]=h&8191,h=h>>>13,l[2*v+1]=h&8191,h=h>>>13;for(v=2*s;v<f;++v)l[v]=0;r(h===0),r((h&-8192)===0)},U.prototype.stub=function(e){for(var s=new Array(e),l=0;l<e;l++)s[l]=0;return s},U.prototype.mulp=function(e,s,l){var f=2*this.guessLen13b(e.length,s.length),h=this.makeRBT(f),v=this.stub(f),k=new Array(f),w=new Array(f),u=new Array(f),y=new Array(f),$=new Array(f),F=new Array(f),j=l.words;j.length=f,this.convert13b(e.words,e.length,k,f),this.convert13b(s.words,s.length,y,f),this.transform(k,v,w,u,f,h),this.transform(y,v,$,F,f,h);for(var K=0;K<f;K++){var G=w[K]*$[K]-u[K]*F[K];u[K]=w[K]*F[K]+u[K]*$[K],w[K]=G}return this.conjugate(w,u,f),this.transform(w,u,j,v,f,h),this.conjugate(j,v,f),this.normalize13b(j,f),l.negative=e.negative^s.negative,l.length=e.length+s.length,l._strip()},t.prototype.mul=function(e){var s=new t(null);return s.words=new Array(this.length+e.length),this.mulTo(e,s)},t.prototype.mulf=function(e){var s=new t(null);return s.words=new Array(this.length+e.length),I(this,e,s)},t.prototype.imul=function(e){return this.clone().mulTo(e,this)},t.prototype.imuln=function(e){var s=e<0;s&&(e=-e),r(typeof e=="number"),r(e<67108864);for(var l=0,f=0;f<this.length;f++){var h=(this.words[f]|0)*e,v=(h&67108863)+(l&67108863);l>>=26,l+=h/67108864|0,l+=v>>>26,this.words[f]=v&67108863}return l!==0&&(this.words[f]=l,this.length++),this.length=e===0?1:this.length,s?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 s=L(e);if(s.length===0)return new t(1);for(var l=this,f=0;f<s.length&&s[f]===0;f++,l=l.sqr());if(++f<s.length)for(var h=l.sqr();f<s.length;f++,h=h.sqr())s[f]!==0&&(l=l.mul(h));return l},t.prototype.iushln=function(e){r(typeof e=="number"&&e>=0);var s=e%26,l=(e-s)/26,f=67108863>>>26-s<<26-s,h;if(s!==0){var v=0;for(h=0;h<this.length;h++){var k=this.words[h]&f,w=(this.words[h]|0)-k<<s;this.words[h]=w|v,v=k>>>26-s}v&&(this.words[h]=v,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 r(this.negative===0),this.iushln(e)},t.prototype.iushrn=function(e,s,l){r(typeof e=="number"&&e>=0);var f;s?f=(s-s%26)/26:f=0;var h=e%26,v=Math.min((e-h)/26,this.length),k=67108863^67108863>>>h<<h,w=l;if(f-=v,f=Math.max(0,f),w){for(var u=0;u<v;u++)w.words[u]=this.words[u];w.length=v}if(v!==0)if(this.length>v)for(this.length-=v,u=0;u<this.length;u++)this.words[u]=this.words[u+v];else this.words[0]=0,this.length=1;var y=0;for(u=this.length-1;u>=0&&(y!==0||u>=f);u--){var $=this.words[u]|0;this.words[u]=y<<26-h|$>>>h,y=$&k}return w&&y!==0&&(w.words[w.length++]=y),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},t.prototype.ishrn=function(e,s,l){return r(this.negative===0),this.iushrn(e,s,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){r(typeof e=="number"&&e>=0);var s=e%26,l=(e-s)/26,f=1<<s;if(this.length<=l)return!1;var h=this.words[l];return!!(h&f)},t.prototype.imaskn=function(e){r(typeof e=="number"&&e>=0);var s=e%26,l=(e-s)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(s!==0&&l++,this.length=Math.min(l,this.length),s!==0){var f=67108863^67108863>>>s<<s;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 r(typeof e=="number"),r(e<67108864),e<0?this.isubn(-e):this.negative!==0?this.length===1&&(this.words[0]|0)<=e?(this.words[0]=e-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},t.prototype._iaddn=function(e){this.words[0]+=e;for(var s=0;s<this.length&&this.words[s]>=67108864;s++)this.words[s]-=67108864,s===this.length-1?this.words[s+1]=1:this.words[s+1]++;return this.length=Math.max(this.length,s+1),this},t.prototype.isubn=function(e){if(r(typeof e=="number"),r(e<67108864),e<0)return this.iaddn(-e);if(this.negative!==0)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var s=0;s<this.length&&this.words[s]<0;s++)this.words[s]+=67108864,this.words[s+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,s,l){var f=e.length+l,h;this._expand(f);var v,k=0;for(h=0;h<e.length;h++){v=(this.words[h+l]|0)+k;var w=(e.words[h]|0)*s;v-=w&67108863,k=(v>>26)-(w/67108864|0),this.words[h+l]=v&67108863}for(;h<this.length-l;h++)v=(this.words[h+l]|0)+k,k=v>>26,this.words[h+l]=v&67108863;if(k===0)return this._strip();for(r(k===-1),k=0,h=0;h<this.length;h++)v=-(this.words[h]|0)+k,k=v>>26,this.words[h]=v&67108863;return this.negative=1,this._strip()},t.prototype._wordDiv=function(e,s){var l=this.length-e.length,f=this.clone(),h=e,v=h.words[h.length-1]|0,k=this._countBits(v);l=26-k,l!==0&&(h=h.ushln(l),f.iushln(l),v=h.words[h.length-1]|0);var w=f.length-h.length,u;if(s!=="mod"){u=new t(null),u.length=w+1,u.words=new Array(u.length);for(var y=0;y<u.length;y++)u.words[y]=0}var $=f.clone()._ishlnsubmul(h,1,w);$.negative===0&&(f=$,u&&(u.words[w]=1));for(var F=w-1;F>=0;F--){var j=(f.words[h.length+F]|0)*67108864+(f.words[h.length+F-1]|0);for(j=Math.min(j/v|0,67108863),f._ishlnsubmul(h,j,F);f.negative!==0;)j--,f.negative=0,f._ishlnsubmul(h,1,F),f.isZero()||(f.negative^=1);u&&(u.words[F]=j)}return u&&u._strip(),f._strip(),s!=="div"&&l!==0&&f.iushrn(l),{div:u||null,mod:f}},t.prototype.divmod=function(e,s,l){if(r(!e.isZero()),this.isZero())return{div:new t(0),mod:new t(0)};var f,h,v;return this.negative!==0&&e.negative===0?(v=this.neg().divmod(e,s),s!=="mod"&&(f=v.div.neg()),s!=="div"&&(h=v.mod.neg(),l&&h.negative!==0&&h.iadd(e)),{div:f,mod:h}):this.negative===0&&e.negative!==0?(v=this.divmod(e.neg(),s),s!=="mod"&&(f=v.div.neg()),{div:f,mod:v.mod}):(this.negative&e.negative)!==0?(v=this.neg().divmod(e.neg(),s),s!=="div"&&(h=v.mod.neg(),l&&h.negative!==0&&h.isub(e)),{div:v.div,mod:h}):e.length>this.length||this.cmp(e)<0?{div:new t(0),mod:this}:e.length===1?s==="div"?{div:this.divn(e.words[0]),mod:null}:s==="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,s)},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 s=this.divmod(e);if(s.mod.isZero())return s.div;var l=s.div.negative!==0?s.mod.isub(e):s.mod,f=e.ushrn(1),h=e.andln(1),v=l.cmp(f);return v<0||h===1&&v===0?s.div:s.div.negative!==0?s.div.isubn(1):s.div.iaddn(1)},t.prototype.modrn=function(e){var s=e<0;s&&(e=-e),r(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 s?-f:f},t.prototype.modn=function(e){return this.modrn(e)},t.prototype.idivn=function(e){var s=e<0;s&&(e=-e),r(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(),s?this.ineg():this},t.prototype.divn=function(e){return this.clone().idivn(e)},t.prototype.egcd=function(e){r(e.negative===0),r(!e.isZero());var s=this,l=e.clone();s.negative!==0?s=s.umod(e):s=s.clone();for(var f=new t(1),h=new t(0),v=new t(0),k=new t(1),w=0;s.isEven()&&l.isEven();)s.iushrn(1),l.iushrn(1),++w;for(var u=l.clone(),y=s.clone();!s.isZero();){for(var $=0,F=1;(s.words[0]&F)===0&&$<26;++$,F<<=1);if($>0)for(s.iushrn($);$-- >0;)(f.isOdd()||h.isOdd())&&(f.iadd(u),h.isub(y)),f.iushrn(1),h.iushrn(1);for(var j=0,K=1;(l.words[0]&K)===0&&j<26;++j,K<<=1);if(j>0)for(l.iushrn(j);j-- >0;)(v.isOdd()||k.isOdd())&&(v.iadd(u),k.isub(y)),v.iushrn(1),k.iushrn(1);s.cmp(l)>=0?(s.isub(l),f.isub(v),h.isub(k)):(l.isub(s),v.isub(f),k.isub(h))}return{a:v,b:k,gcd:l.iushln(w)}},t.prototype._invmp=function(e){r(e.negative===0),r(!e.isZero());var s=this,l=e.clone();s.negative!==0?s=s.umod(e):s=s.clone();for(var f=new t(1),h=new t(0),v=l.clone();s.cmpn(1)>0&&l.cmpn(1)>0;){for(var k=0,w=1;(s.words[0]&w)===0&&k<26;++k,w<<=1);if(k>0)for(s.iushrn(k);k-- >0;)f.isOdd()&&f.iadd(v),f.iushrn(1);for(var u=0,y=1;(l.words[0]&y)===0&&u<26;++u,y<<=1);if(u>0)for(l.iushrn(u);u-- >0;)h.isOdd()&&h.iadd(v),h.iushrn(1);s.cmp(l)>=0?(s.isub(l),f.isub(h)):(l.isub(s),h.isub(f))}var $;return s.cmpn(1)===0?$=f:$=h,$.cmpn(0)<0&&$.iadd(e),$},t.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var s=this.clone(),l=e.clone();s.negative=0,l.negative=0;for(var f=0;s.isEven()&&l.isEven();f++)s.iushrn(1),l.iushrn(1);do{for(;s.isEven();)s.iushrn(1);for(;l.isEven();)l.iushrn(1);var h=s.cmp(l);if(h<0){var v=s;s=l,l=v}else if(h===0||l.cmpn(1)===0)break;s.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){r(typeof e=="number");var s=e%26,l=(e-s)/26,f=1<<s;if(this.length<=l)return this._expand(l+1),this.words[l]|=f,this;for(var h=f,v=l;h!==0&&v<this.length;v++){var k=this.words[v]|0;k+=h,h=k>>>26,k&=67108863,this.words[v]=k}return h!==0&&(this.words[v]=h,this.length++),this},t.prototype.isZero=function(){return this.length===1&&this.words[0]===0},t.prototype.cmpn=function(e){var s=e<0;if(this.negative!==0&&!s)return-1;if(this.negative===0&&s)return 1;this._strip();var l;if(this.length>1)l=1;else{s&&(e=-e),r(e<=67108863,"Number is too big");var f=this.words[0]|0;l=f===e?0:f<e?-1:1}return this.negative!==0?-l|0:l},t.prototype.cmp=function(e){if(this.negative!==0&&e.negative===0)return-1;if(this.negative===0&&e.negative!==0)return 1;var s=this.ucmp(e);return this.negative!==0?-s|0:s},t.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var s=0,l=this.length-1;l>=0;l--){var f=this.words[l]|0,h=e.words[l]|0;if(f!==h){f<h?s=-1:f>h&&(s=1);break}}return s},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 C(e)},t.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),e.convertTo(this)._forceRed(e)},t.prototype.fromRed=function(){return r(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 r(!this.red,"Already a number in reduction context"),this._forceRed(e)},t.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},t.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},t.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},t.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},t.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},t.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},t.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},t.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},t.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},t.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},t.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},t.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},t.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var W={k256:null,p224:null,p192:null,p25519:null};function q(p,e){this.name=p,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()}q.prototype._tmp=function(){var e=new t(null);return e.words=new Array(Math.ceil(this.n/13)),e},q.prototype.ireduce=function(e){var s=e,l;do this.split(s,this.tmp),s=this.imulK(s),s=s.iadd(this.tmp),l=s.bitLength();while(l>this.n);var f=l<this.n?-1:s.ucmp(this.p);return f===0?(s.words[0]=0,s.length=1):f>0?s.isub(this.p):s.strip!==void 0?s.strip():s._strip(),s},q.prototype.split=function(e,s){e.iushrn(this.n,0,s)},q.prototype.imulK=function(e){return e.imul(this.k)};function Z(){q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}o(Z,q),Z.prototype.split=function(e,s){for(var l=4194303,f=Math.min(e.length,9),h=0;h<f;h++)s.words[h]=e.words[h];if(s.length=f,e.length<=9){e.words[0]=0,e.length=1;return}var v=e.words[9];for(s.words[s.length++]=v&l,h=10;h<e.length;h++){var k=e.words[h]|0;e.words[h-10]=(k&l)<<4|v>>>22,v=k}v>>>=22,e.words[h-10]=v,v===0&&e.length>10?e.length-=10:e.length-=9},Z.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var s=0,l=0;l<e.length;l++){var f=e.words[l]|0;s+=f*977,e.words[l]=s&67108863,s=f*64+(s/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function _(){q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}o(_,q);function b(){q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}o(b,q);function S(){q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}o(S,q),S.prototype.imulK=function(e){for(var s=0,l=0;l<e.length;l++){var f=(e.words[l]|0)*19+s,h=f&67108863;f>>>=26,e.words[l]=h,s=f}return s!==0&&(e.words[e.length++]=s),e},t._prime=function(e){if(W[e])return W[e];var s;if(e==="k256")s=new Z;else if(e==="p224")s=new _;else if(e==="p192")s=new b;else if(e==="p25519")s=new S;else throw new Error("Unknown prime "+e);return W[e]=s,s};function C(p){if(typeof p=="string"){var e=t._prime(p);this.m=e.p,this.prime=e}else r(p.gtn(1),"modulus must be greater than 1"),this.m=p,this.prime=null}C.prototype._verify1=function(e){r(e.negative===0,"red works only with positives"),r(e.red,"red works only with red numbers")},C.prototype._verify2=function(e,s){r((e.negative|s.negative)===0,"red works only with positives"),r(e.red&&e.red===s.red,"red works only with red numbers")},C.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(g(e,e.umod(this.m)._forceRed(this)),e)},C.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},C.prototype.add=function(e,s){this._verify2(e,s);var l=e.add(s);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},C.prototype.iadd=function(e,s){this._verify2(e,s);var l=e.iadd(s);return l.cmp(this.m)>=0&&l.isub(this.m),l},C.prototype.sub=function(e,s){this._verify2(e,s);var l=e.sub(s);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},C.prototype.isub=function(e,s){this._verify2(e,s);var l=e.isub(s);return l.cmpn(0)<0&&l.iadd(this.m),l},C.prototype.shl=function(e,s){return this._verify1(e),this.imod(e.ushln(s))},C.prototype.imul=function(e,s){return this._verify2(e,s),this.imod(e.imul(s))},C.prototype.mul=function(e,s){return this._verify2(e,s),this.imod(e.mul(s))},C.prototype.isqr=function(e){return this.imul(e,e.clone())},C.prototype.sqr=function(e){return this.mul(e,e)},C.prototype.sqrt=function(e){if(e.isZero())return e.clone();var s=this.m.andln(3);if(r(s%2===1),s===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);r(!f.isZero());var v=new t(1).toRed(this),k=v.redNeg(),w=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new t(2*u*u).toRed(this);this.pow(u,w).cmp(k)!==0;)u.redIAdd(k);for(var y=this.pow(u,f),$=this.pow(e,f.addn(1).iushrn(1)),F=this.pow(e,f),j=h;F.cmp(v)!==0;){for(var K=F,G=0;K.cmp(v)!==0;G++)K=K.redSqr();r(G<j);var J=this.pow(y,new t(1).iushln(j-G-1));$=$.redMul(J),y=J.redSqr(),F=F.redMul(y),j=G}return $},C.prototype.invm=function(e){var s=e._invmp(this.m);return s.negative!==0?(s.negative=0,this.imod(s).redNeg()):this.imod(s)},C.prototype.pow=function(e,s){if(s.isZero())return new t(1).toRed(this);if(s.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 v=f[0],k=0,w=0,u=s.bitLength()%26;for(u===0&&(u=26),h=s.length-1;h>=0;h--){for(var y=s.words[h],$=u-1;$>=0;$--){var F=y>>$&1;if(v!==f[0]&&(v=this.sqr(v)),F===0&&k===0){w=0;continue}k<<=1,k|=F,w++,!(w!==l&&(h!==0||$!==0))&&(v=this.mul(v,f[k]),w=0,k=0)}u=26}return v},C.prototype.convertTo=function(e){var s=e.umod(this.m);return s===e?s.clone():s},C.prototype.convertFrom=function(e){var s=e.clone();return s.red=null,s},t.mont=function(e){return new x(e)};function x(p){C.call(this,p),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)}o(x,C),x.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},x.prototype.convertFrom=function(e){var s=this.imod(e.mul(this.rinv));return s.red=null,s},x.prototype.imul=function(e,s){if(e.isZero()||s.isZero())return e.words[0]=0,e.length=1,e;var l=e.imul(s),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).iushrn(this.shift),v=h;return h.cmp(this.m)>=0?v=h.isub(this.m):h.cmpn(0)<0&&(v=h.iadd(this.m)),v._forceRed(this)},x.prototype.mul=function(e,s){if(e.isZero()||s.isZero())return new t(0)._forceRed(this);var l=e.mul(s),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).iushrn(this.shift),v=h;return h.cmp(this.m)>=0?v=h.isub(this.m):h.cmpn(0)<0&&(v=h.iadd(this.m)),v._forceRed(this)},x.prototype.invm=function(e){var s=this.imod(e._invmp(this.m).mul(this.r2));return s._forceRed(this)}})(typeof Ui>"u"||Ui,Nr)});import{SuiClient as vo}from"@mysten/sui/client";import{normalizeSuiAddress as Mo}from"@mysten/sui/utils";import{SuiPriceServiceConnection as bo}from"@pythnetwork/pyth-sui-js";import{SdkWrapper as yo}from"@cetusprotocol/common-sdk";import{CetusClmmSDK as ko}from"@cetusprotocol/sui-clmm-sdk";import{AggregatorClient as So,Env as qr}from"@cetusprotocol/aggregator-sdk";import{FullRpcUrlMainnet as Hr}from"@cetusprotocol/common-sdk";var rr={full_rpc_url:Hr,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",margin_trading:{package_id:"0xd36d24553943160f960d3c0065cb6b77910328d23669233d304290b84e101400",published_at:"0xd36d24553943160f960d3c0065cb6b77910328d23669233d304290b84e101400",version:0,config:{versioned_id:"0x7408869c4ef21ea5e7027e2a49933954669862b707d5bec5c2741bf1297a6cc9",admin_cap_id:"0x621d93c68cc44043acea6c95dfbe1176ffb710e84ad78fe7e3fc4057f64596a2",global_config_id:"0x0627a2c9ddc7c8e39ae2946e0d51d80554d9e3857f3a7e0efafcc60e2ee10096",markets:"0x01f934d67fbd524ff1b9570531fecf198dcda1b41996c3ac8752cf7f1cc66420",markets_table_id:"0x999a28a63aab15342799909fb352d2a8c7a92adf061dbb14339cdd7ff6e23184"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{lending_market:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",owner_cap_id:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",owner_cap_id:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",is_hidden:!0}],lending_market_id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lending_market_type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",api_url:"https://d10td5ybgrf39v.cloudfront.net"}}};import{CACHE_TIME_5MIN as Yr,d as se,getPackagerConfigs as Le}from"@cetusprotocol/common-sdk";import{Transaction as Ne}from"@mysten/sui/transactions";import{addHexPrefix as nr,d as oe,getObjectFields as lr}from"@cetusprotocol/common-sdk";import{parseObligation as Vr}from"@suilend/sdk/parsers/obligation";import{getNetAprPercent as Xr,getTotalAprPercent as or,Side as sr,getFilteredRewards as ar}from"@suilend/sdk";var bi=n=>{let i=lr(n),{open_permissions_pause:r,close_permissions_pause:o,deposit_permissions_pause:t,withdraw_permissions_pause:a,borrow_permissions_pause:d,repay_permissions_pause:c}=Si(i.permissions.toString(2));return{market_id:i.id.id,base_token:nr(i.base_token.fields.name),quote_token:nr(i.quote_token.fields.name),max_long_leverage:oe(i.max_long_leverage).div(10**6).toString(),max_short_leverage:oe(i.max_short_leverage).div(10**6).toString(),open_fee_rate:oe(i.open_fee_rate).div(10**6).toString(),close_fee_rate:oe(i.close_fee_rate).div(10**6).toString(),open_permissions_pause:r,close_permissions_pause:o,deposit_permissions_pause:t,withdraw_permissions_pause:a,borrow_permissions_pause:d,repay_permissions_pause:c}},yi=(n,i)=>{let r=lr(n);return{created_at:r.created_ts,position_id:r.id.id,init_deposit_amount:r.init_deposit_amount,is_long:r.is_long,lending_market_id:r.lending_market_id,obligation_owner_cap:r.obligation_owner_cap.fields.obligation_id,market_id:r.market_id,position_cap_id:i}},ki=(n,i,r,o,t)=>{let a=Vr(i,r),d=Xr(a,t,o);if(!a.deposits||a.deposits.length===0)throw new Error("No deposits found in obligation data");let c=a.deposits[0],m=oe(c.reserve.config.closeLtvPct).div(100).toString(),g=oe(c.reserve.config.openLtvPct).div(100).toString(),M=a.depositedAmountUsd.gt(0)?a.borrowedAmountUsd.div(a.depositedAmountUsd).toString():"0",P=oe(1).div(m).toString(),A=oe(m).sub(M).toString(),D="0",T="0",L="0",N="0";if(a.borrows&&a.borrows.length>0){let R=a.borrows[0],O=t[R?.coinType];O&&(D=or(sr.BORROW,R?.reserve.borrowAprPercent,ar(O.borrow)).toString()),L=R.borrowedAmountUsd.toString(),N=R.borrowedAmount.toString()}if(a.deposits&&a.deposits.length>0){let R=a.deposits[0],O=t[R?.coinType];O&&(T=or(sr.DEPOSIT,R?.reserve.depositAprPercent,ar(O.deposit)).toString())}return{...n,...a,origin_obligation:i,net_apr_percent:d.toString(),supplied_apr:oe(T).toString(),borrowed_apr:oe(D).toString(),close_ltv:m,open_ltv:g,cr:M,ltr:P,liquidation_buffer:A,deposited_amount_usd:c.depositedAmountUsd.toString(),borrowed_amount_usd:L,deposited_amount:c.depositedAmount.toString(),borrowed_amount:N}},Si=n=>{let i=n.length,r=n.substring(i-1,i)==="0",o=n.substring(i-2,i-1)==="0",t=n.substring(i-3,i-2)==="0",a=n.substring(i-4,i-3)==="0",d=n.substring(i-5,i-4)==="0",c=n.substring(i-6,i-5)==="0";return{open_permissions_pause:r,close_permissions_pause:o,deposit_permissions_pause:t,withdraw_permissions_pause:d,borrow_permissions_pause:a,repay_permissions_pause:c}};import{getFilteredRewards as he,getStakingYieldAprPercent as ur,getTotalAprPercent as Ee,Side as Se}from"@suilend/sdk";import{BaseError as Jr}from"@cetusprotocol/common-sdk";var Re=class extends Jr{constructor(i,r,o){super(i,r||"UnknownError",o)}static isCrossSwapErrorCode(i,r){return this.isErrorCode(i,r)}},Gt=(n,i,r)=>{let o={...r,stack:i instanceof Error?i.stack:void 0};throw i instanceof Error?new Re(i.message,n,o):new Re(i,n,o)};var Ie=class{constructor(i){this.createMarket=async i=>{let{package_id:r}=this._sdk.sdkOptions.margin_trading,{versioned_id:o,admin_cap_id:t,markets:a,global_config_id:d}=Le(this._sdk.sdkOptions.margin_trading),c=new Ne;return c.moveCall({target:`${r}::market::create_market`,arguments:[c.object(t),c.object(d),c.object(a),c.pure.u64(i.open_fee_rate),c.pure.u64(i.close_fee_rate),c.object(o)],typeArguments:[i.base_token,i.quote_token]}),c};this.updateMarketFeeRate=async i=>{let{package_id:r}=this._sdk.sdkOptions.margin_trading,{versioned_id:o,admin_cap_id:t}=Le(this._sdk.sdkOptions.margin_trading),{market_id:a,open_fee_rate:d,close_fee_rate:c}=i,m=new Ne;return m.moveCall({target:`${r}::market::set_fee_rate`,arguments:[m.object(t),m.object(a),m.pure.u64(d),m.pure.u64(c),m.object(o)],typeArguments:[]}),m};this.claimMarketFees=async(i,r)=>{let{package_id:o}=this._sdk.sdkOptions.margin_trading,{versioned_id:t,admin_cap_id:a}=Le(this._sdk.sdkOptions.margin_trading),d=r||new Ne,{base_token:c,quote_token:m}=await this._sdk.MarketModules.getMarketInfo(i);return d.moveCall({target:`${o}::market::claim_fees`,arguments:[d.object(a),d.object(i),d.object(t)],typeArguments:[c,m]}),d};this.claimAllMarketFees=async i=>{let r=new Ne;for(let o=0;o<i.length;o++){let t=i[o];this.claimMarketFees(t,r)}return r};this.getMarginTradingConfig=async()=>{let{package_id:i}=this._sdk.sdkOptions.margin_trading;try{let r=await this._sdk.FullClient.queryEventsByPage({MoveEventType:`${i}::versioned::InitEvent`}),o=await this._sdk.FullClient.queryEventsByPage({MoveEventType:`${i}::admin_cap::InitEvent`}),t=await this._sdk.FullClient.queryEventsByPage({MoveEventType:`${i}::config::InitEvent`}),d=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:`${i}::market::InitEvent`})).data[0].parsedJson.markets_id,m=(await this._sdk.FullClient.getObject({id:d,options:{showContent:!0}})).data.content.fields.list.fields.id.id;return{versioned_id:r.data[0].parsedJson.versioned_id,admin_cap_id:o.data[0].parsedJson.admin_cap_id,global_config_id:t.data[0].parsedJson.global_config_id,markets:d,markets_table_id:m}}catch(r){return Gt("FetchError",r),{versioned_id:"",admin_cap_id:"",global_config_id:"",markets_table_id:"",markets:""}}};this.getMarketList=async(i=!1)=>{let o=this._sdk.getCache("margin_trading_markets_list",i);if(o)return o;let{package_id:t}=this._sdk.sdkOptions.margin_trading,a=[];try{let d=`${t}::market::CreateMarketEvent`,m=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:d})).data.map(g=>g.parsedJson.market_id);return m.length>0?((await this._sdk.FullClient.batchGetObjects(m,{showContent:!0,showType:!0})).forEach(M=>{let P=bi(M),A=`margin_trading_market_info_${P.market_id}`;this._sdk.updateCache(A,P),a.push(P)}),a):(Gt("MarketNotFound","Market not found"),[])}catch(d){return Gt("FetchError",d),[]}};this.getMarketInfo=async(i,r=!1)=>{let o=`margin_trading_market_info_${i}`,t=this._sdk.getCache(o,r);if(t)return t;try{let a=await this._sdk.FullClient.getObject({id:i,options:{showContent:!0}}),d=bi(a);return this._sdk.updateCache(o,d,Yr),d}catch(a){return Gt("FetchError",a),{}}};this.getMarketSuilendInfo=async i=>{try{let{base_token:r,quote_token:o}=await this.getMarketInfo(i),{lending_market_id:t}=Le(this._sdk.sdkOptions.suilend),{allLendingMarketData:a,lstAprPercentMap:d}=await this._sdk.SuiLendModule.getLendingMarketData(!0),{base_reserve_map_info:c,quote_reserve_map_info:m}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(r,o,a);console.log("\u{1F680}\u{1F680}\u{1F680} ~ marketModules.ts:188 ~ MarketModules ~ base_reserve_map_info:",c);let g=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:a,lstAprPercentMap:d},!0),M=g[t].rewardMap[r],P=g[t].rewardMap[o],{depositedAmountUsd:A,borrowedAmountUsd:D,depositAprPercent:T,borrowAprPercent:L,depositedAmount:N,borrowedAmount:R}=c,{depositLimit:O,borrowLimit:I}=c.config,{depositedAmountUsd:U,borrowedAmountUsd:W,depositAprPercent:q,borrowAprPercent:Z,depositedAmount:_,borrowedAmount:b}=m,{depositLimit:S,borrowLimit:C}=m.config,x=Ee(Se.DEPOSIT,T,he(M.deposit),ur(Se.DEPOSIT,r,d)),p=Ee(Se.BORROW,L,he(M.borrow)),e=Ee(Se.DEPOSIT,q,he(P.deposit),ur(Se.DEPOSIT,r,d)),s=Ee(Se.BORROW,Z,he(P.borrow)),l=se(U.toString()).sub(W.toString()).toString(),f=se(A.toString()).sub(D.toString()).toString(),h=se(O.toString()).sub(se(N.toString())).toString(),v=se(I.toString()).sub(se(R.toString())).toString(),k=se(S.toString()).sub(se(_.toString())).toString(),w=se(C.toString()).sub(se(b.toString())).toString();return{long_liquidity:l,short_liquidity:f,base_total_deposit_apr_percent:x.toString(),base_total_borrow_apr_percent:p.toString(),quote_total_deposit_apr_percent:e.toString(),quote_total_borrow_apr_percent:s.toString(),base_token_available_deposit_amount:h,base_token_available_borrow_amount:v,quote_token_available_deposit_amount:k,quote_token_available_borrow_amount:w,base_deposit_rewards:he(M.deposit),quote_deposit_rewards:he(P.deposit),base_borrow_rewards:he(M.borrow),quote_borrow_rewards:he(P.borrow),base_deposit_apr_percent:T.toString(),base_borrow_apr_percent:L.toString(),quote_deposit_apr_percent:q.toString(),quote_borrow_apr_percent:Z.toString(),obligations:g[t],base_reserve_map_info:c,quote_reserve_map_info:m}}catch(r){return Gt("FetchError",r),{}}};this._sdk=i}};import{CLOCK_ADDRESS as Pe,getPackagerConfigs as Jt}from"@cetusprotocol/common-sdk";import{Transaction as Ht}from"@mysten/sui/transactions";var Be=class{constructor(i){this.queryGlobalPermissions=async()=>{let i=this._sdk.sdkOptions.margin_trading,{global_config_id:r}=Jt(i),o=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}});if(o){let t=o.data.content.fields.permissions.toString(2),{open_permissions_pause:a,close_permissions_pause:d,deposit_permissions_pause:c,withdraw_permissions_pause:m,borrow_permissions_pause:g,repay_permissions_pause:M}=Si(t);return{open_permissions_pause:a,close_permissions_pause:d,deposit_permissions_pause:c,withdraw_permissions_pause:m,borrow_permissions_pause:g,repay_permissions_pause:M}}};this.updateGlobalPermissions=async i=>{let r=new Ht;return this.updateGlobalOpenPositionPermissions(i,r),this.updateGlobalClosePositionPermissions(i,r),this.updateGlobalDepositPermissions(i,r),this.updateGlobalBorrowPermissions(i,r),this.updateGlobalWithdrawPermissions(i,r),this.updateGlobalRepayPermissions(i,r),r};this.updateGlobalOpenPositionPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_open_position_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalClosePositionPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_close_position_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalDepositPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_deposit_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalBorrowPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_borrow_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalWithdrawPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_withdraw_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalRepayPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_repay_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateMarketCreatePositionPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_open_position_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketClosePositionPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_close_position_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketDepositPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_deposit_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketWithdrawPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_withdraw_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketBorrowPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_borrow_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketRepayPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_repay_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketPermissions=async(i,r,o)=>{let t=o||new Ht;return this.updateMarketCreatePositionPermissions(i,r,t),this.updateMarketClosePositionPermissions(i,r,t),this.updateMarketDepositPermissions(i,r,t),this.updateMarketWithdrawPermissions(i,r,t),this.updateMarketBorrowPermissions(i,r,t),this.updateMarketRepayPermissions(i,r,t),t};this._sdk=i}};import{CACHE_TIME_24H as Vn,CLOCK_ADDRESS as be,CoinAssist as Q,d as E,getObjectFields as Ar,getPackagerConfigs as jt,removeHexPrefix as xe,SUI_SYSTEM_STATE_OBJECT_ID as Cr,U64_MAX as Ni}from"@cetusprotocol/common-sdk";var Qr=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Ai=Math.ceil,Qt=Math.floor,Vt="[BigNumber Error] ",cr=Vt+"Number primitive has more than 15 significant digits: ",ie=1e14,tt=14,Ci=9007199254740991,xi=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],pe=1e7,Wt=1e9;function fr(n){var i,r,o,t=O.prototype={constructor:O,toString:null,valueOf:null},a=new O(1),d=20,c=4,m=-7,g=21,M=-1e7,P=1e7,A=!1,D=1,T=0,L={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},N="0123456789abcdefghijklmnopqrstuvwxyz",R=!0;function O(_,b){var S,C,x,p,e,s,l,f,h=this;if(!(h instanceof O))return new O(_,b);if(b==null){if(_&&_._isBigNumber===!0){h.s=_.s,!_.c||_.e>P?h.c=h.e=null:_.e<M?h.c=[h.e=0]:(h.e=_.e,h.c=_.c.slice());return}if((s=typeof _=="number")&&_*0==0){if(h.s=1/_<0?(_=-_,-1):1,_===~~_){for(p=0,e=_;e>=10;e/=10,p++);p>P?h.c=h.e=null:(h.e=p,h.c=[_]);return}f=String(_)}else{if(!Qr.test(f=String(_)))return o(h,f,s);h.s=f.charCodeAt(0)==45?(f=f.slice(1),-1):1}(p=f.indexOf("."))>-1&&(f=f.replace(".","")),(e=f.search(/e/i))>0?(p<0&&(p=e),p+=+f.slice(e+1),f=f.substring(0,e)):p<0&&(p=f.length)}else{if(ft(b,2,N.length,"Base"),b==10&&R)return h=new O(_),q(h,d+h.e+1,c);if(f=String(_),s=typeof _=="number"){if(_*0!=0)return o(h,f,s,b);if(h.s=1/_<0?(f=f.slice(1),-1):1,O.DEBUG&&f.replace(/^0\.0*|\./,"").length>15)throw Error(cr+_)}else h.s=f.charCodeAt(0)===45?(f=f.slice(1),-1):1;for(S=N.slice(0,b),p=e=0,l=f.length;e<l;e++)if(S.indexOf(C=f.charAt(e))<0){if(C=="."){if(e>p){p=l;continue}}else if(!x&&(f==f.toUpperCase()&&(f=f.toLowerCase())||f==f.toLowerCase()&&(f=f.toUpperCase()))){x=!0,e=-1,p=0;continue}return o(h,String(_),s,b)}s=!1,f=r(f,b,10,h.s),(p=f.indexOf("."))>-1?f=f.replace(".",""):p=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,s&&O.DEBUG&&l>15&&(_>Ci||_!==Qt(_)))throw Error(cr+h.s*_);if((p=p-e-1)>P)h.c=h.e=null;else if(p<M)h.c=[h.e=0];else{if(h.e=p,h.c=[],e=(p+1)%tt,p<0&&(e+=tt),e<l){for(e&&h.c.push(+f.slice(0,e)),l-=tt;e<l;)h.c.push(+f.slice(e,e+=tt));e=tt-(f=f.slice(e)).length}else e-=l;for(;e--;f+="0");h.c.push(+f)}}else h.c=[h.e=0]}O.clone=fr,O.ROUND_UP=0,O.ROUND_DOWN=1,O.ROUND_CEIL=2,O.ROUND_FLOOR=3,O.ROUND_HALF_UP=4,O.ROUND_HALF_DOWN=5,O.ROUND_HALF_EVEN=6,O.ROUND_HALF_CEIL=7,O.ROUND_HALF_FLOOR=8,O.EUCLID=9,O.config=O.set=function(_){var b,S;if(_!=null)if(typeof _=="object"){if(_.hasOwnProperty(b="DECIMAL_PLACES")&&(S=_[b],ft(S,0,Wt,b),d=S),_.hasOwnProperty(b="ROUNDING_MODE")&&(S=_[b],ft(S,0,8,b),c=S),_.hasOwnProperty(b="EXPONENTIAL_AT")&&(S=_[b],S&&S.pop?(ft(S[0],-Wt,0,b),ft(S[1],0,Wt,b),m=S[0],g=S[1]):(ft(S,-Wt,Wt,b),m=-(g=S<0?-S:S))),_.hasOwnProperty(b="RANGE"))if(S=_[b],S&&S.pop)ft(S[0],-Wt,-1,b),ft(S[1],1,Wt,b),M=S[0],P=S[1];else if(ft(S,-Wt,Wt,b),S)M=-(P=S<0?-S:S);else throw Error(Vt+b+" cannot be zero: "+S);if(_.hasOwnProperty(b="CRYPTO"))if(S=_[b],S===!!S)if(S)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))A=S;else throw A=!S,Error(Vt+"crypto unavailable");else A=S;else throw Error(Vt+b+" not true or false: "+S);if(_.hasOwnProperty(b="MODULO_MODE")&&(S=_[b],ft(S,0,9,b),D=S),_.hasOwnProperty(b="POW_PRECISION")&&(S=_[b],ft(S,0,Wt,b),T=S),_.hasOwnProperty(b="FORMAT"))if(S=_[b],typeof S=="object")L=S;else throw Error(Vt+b+" not an object: "+S);if(_.hasOwnProperty(b="ALPHABET"))if(S=_[b],typeof S=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(S))R=S.slice(0,10)=="0123456789",N=S;else throw Error(Vt+b+" invalid: "+S)}else throw Error(Vt+"Object expected: "+_);return{DECIMAL_PLACES:d,ROUNDING_MODE:c,EXPONENTIAL_AT:[m,g],RANGE:[M,P],CRYPTO:A,MODULO_MODE:D,POW_PRECISION:T,FORMAT:L,ALPHABET:N}},O.isBigNumber=function(_){if(!_||_._isBigNumber!==!0)return!1;if(!O.DEBUG)return!0;var b,S,C=_.c,x=_.e,p=_.s;t:if({}.toString.call(C)=="[object Array]"){if((p===1||p===-1)&&x>=-Wt&&x<=Wt&&x===Qt(x)){if(C[0]===0){if(x===0&&C.length===1)return!0;break t}if(b=(x+1)%tt,b<1&&(b+=tt),String(C[0]).length==b){for(b=0;b<C.length;b++)if(S=C[b],S<0||S>=ie||S!==Qt(S))break t;if(S!==0)return!0}}}else if(C===null&&x===null&&(p===null||p===1||p===-1))return!0;throw Error(Vt+"Invalid BigNumber: "+_)},O.maximum=O.max=function(){return U(arguments,-1)},O.minimum=O.min=function(){return U(arguments,1)},O.random=(function(){var _=9007199254740992,b=Math.random()*_&2097151?function(){return Qt(Math.random()*_)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(S){var C,x,p,e,s,l=0,f=[],h=new O(a);if(S==null?S=d:ft(S,0,Wt),e=Ai(S/tt),A)if(crypto.getRandomValues){for(C=crypto.getRandomValues(new Uint32Array(e*=2));l<e;)s=C[l]*131072+(C[l+1]>>>11),s>=9e15?(x=crypto.getRandomValues(new Uint32Array(2)),C[l]=x[0],C[l+1]=x[1]):(f.push(s%1e14),l+=2);l=e/2}else if(crypto.randomBytes){for(C=crypto.randomBytes(e*=7);l<e;)s=(C[l]&31)*281474976710656+C[l+1]*1099511627776+C[l+2]*4294967296+C[l+3]*16777216+(C[l+4]<<16)+(C[l+5]<<8)+C[l+6],s>=9e15?crypto.randomBytes(7).copy(C,l):(f.push(s%1e14),l+=7);l=e/7}else throw A=!1,Error(Vt+"crypto unavailable");if(!A)for(;l<e;)s=b(),s<9e15&&(f[l++]=s%1e14);for(e=f[--l],S%=tt,e&&S&&(s=xi[tt-S],f[l]=Qt(e/s)*s);f[l]===0;f.pop(),l--);if(l<0)f=[p=0];else{for(p=-1;f[0]===0;f.splice(0,1),p-=tt);for(l=1,s=f[0];s>=10;s/=10,l++);l<tt&&(p-=tt-l)}return h.e=p,h.c=f,h}})(),O.sum=function(){for(var _=1,b=arguments,S=new O(b[0]);_<b.length;)S=S.plus(b[_++]);return S},r=(function(){var _="0123456789";function b(S,C,x,p){for(var e,s=[0],l,f=0,h=S.length;f<h;){for(l=s.length;l--;s[l]*=C);for(s[0]+=p.indexOf(S.charAt(f++)),e=0;e<s.length;e++)s[e]>x-1&&(s[e+1]==null&&(s[e+1]=0),s[e+1]+=s[e]/x|0,s[e]%=x)}return s.reverse()}return function(S,C,x,p,e){var s,l,f,h,v,k,w,u,y=S.indexOf("."),$=d,F=c;for(y>=0&&(h=T,T=0,S=S.replace(".",""),u=new O(C),k=u.pow(S.length-y),T=h,u.c=b(ce(Yt(k.c),k.e,"0"),10,x,_),u.e=u.c.length),w=b(S,C,x,e?(s=N,_):(s=_,N)),f=h=w.length;w[--h]==0;w.pop());if(!w[0])return s.charAt(0);if(y<0?--f:(k.c=w,k.e=f,k.s=p,k=i(k,u,$,F,x),w=k.c,v=k.r,f=k.e),l=f+$+1,y=w[l],h=x/2,v=v||l<0||w[l+1]!=null,v=F<4?(y!=null||v)&&(F==0||F==(k.s<0?3:2)):y>h||y==h&&(F==4||v||F==6&&w[l-1]&1||F==(k.s<0?8:7)),l<1||!w[0])S=v?ce(s.charAt(1),-$,s.charAt(0)):s.charAt(0);else{if(w.length=l,v)for(--x;++w[--l]>x;)w[l]=0,l||(++f,w=[1].concat(w));for(h=w.length;!w[--h];);for(y=0,S="";y<=h;S+=s.charAt(w[y++]));S=ce(S,f,s.charAt(0))}return S}})(),i=(function(){function _(C,x,p){var e,s,l,f,h=0,v=C.length,k=x%pe,w=x/pe|0;for(C=C.slice();v--;)l=C[v]%pe,f=C[v]/pe|0,e=w*l+f*k,s=k*l+e%pe*pe+h,h=(s/p|0)+(e/pe|0)+w*f,C[v]=s%p;return h&&(C=[h].concat(C)),C}function b(C,x,p,e){var s,l;if(p!=e)l=p>e?1:-1;else for(s=l=0;s<p;s++)if(C[s]!=x[s]){l=C[s]>x[s]?1:-1;break}return l}function S(C,x,p,e){for(var s=0;p--;)C[p]-=s,s=C[p]<x[p]?1:0,C[p]=s*e+C[p]-x[p];for(;!C[0]&&C.length>1;C.splice(0,1));}return function(C,x,p,e,s){var l,f,h,v,k,w,u,y,$,F,j,K,G,J,rt,V,it,ut=C.s==x.s?1:-1,et=C.c,X=x.c;if(!et||!et[0]||!X||!X[0])return new O(!C.s||!x.s||(et?X&&et[0]==X[0]:!X)?NaN:et&&et[0]==0||!X?ut*0:ut/0);for(y=new O(ut),$=y.c=[],f=C.e-x.e,ut=p+f+1,s||(s=ie,f=te(C.e/tt)-te(x.e/tt),ut=ut/tt|0),h=0;X[h]==(et[h]||0);h++);if(X[h]>(et[h]||0)&&f--,ut<0)$.push(1),v=!0;else{for(J=et.length,V=X.length,h=0,ut+=2,k=Qt(s/(X[0]+1)),k>1&&(X=_(X,k,s),et=_(et,k,s),V=X.length,J=et.length),G=V,F=et.slice(0,V),j=F.length;j<V;F[j++]=0);it=X.slice(),it=[0].concat(it),rt=X[0],X[1]>=s/2&&rt++;do{if(k=0,l=b(X,F,V,j),l<0){if(K=F[0],V!=j&&(K=K*s+(F[1]||0)),k=Qt(K/rt),k>1)for(k>=s&&(k=s-1),w=_(X,k,s),u=w.length,j=F.length;b(w,F,u,j)==1;)k--,S(w,V<u?it:X,u,s),u=w.length,l=1;else k==0&&(l=k=1),w=X.slice(),u=w.length;if(u<j&&(w=[0].concat(w)),S(F,w,j,s),j=F.length,l==-1)for(;b(X,F,V,j)<1;)k++,S(F,V<j?it:X,j,s),j=F.length}else l===0&&(k++,F=[0]);$[h++]=k,F[0]?F[j++]=et[G]||0:(F=[et[G]],j=1)}while((G++<J||F[0]!=null)&&ut--);v=F[0]!=null,$[0]||$.splice(0,1)}if(s==ie){for(h=1,ut=$[0];ut>=10;ut/=10,h++);q(y,p+(y.e=h+f*tt-1)+1,e,v)}else y.e=f,y.r=+v;return y}})();function I(_,b,S,C){var x,p,e,s,l;if(S==null?S=c:ft(S,0,8),!_.c)return _.toString();if(x=_.c[0],e=_.e,b==null)l=Yt(_.c),l=C==1||C==2&&(e<=m||e>=g)?Fe(l,e):ce(l,e,"0");else if(_=q(new O(_),b,S),p=_.e,l=Yt(_.c),s=l.length,C==1||C==2&&(b<=p||p<=m)){for(;s<b;l+="0",s++);l=Fe(l,p)}else if(b-=e+(C===2&&p>e),l=ce(l,p,"0"),p+1>s){if(--b>0)for(l+=".";b--;l+="0");}else if(b+=p-s,b>0)for(p+1==s&&(l+=".");b--;l+="0");return _.s<0&&x?"-"+l:l}function U(_,b){for(var S,C,x=1,p=new O(_[0]);x<_.length;x++)C=new O(_[x]),(!C.s||(S=Me(p,C))===b||S===0&&p.s===b)&&(p=C);return p}function W(_,b,S){for(var C=1,x=b.length;!b[--x];b.pop());for(x=b[0];x>=10;x/=10,C++);return(S=C+S*tt-1)>P?_.c=_.e=null:S<M?_.c=[_.e=0]:(_.e=S,_.c=b),_}o=(function(){var _=/^(-?)0([xbo])(?=\w[\w.]*$)/i,b=/^([^.]+)\.$/,S=/^\.([^.]+)$/,C=/^-?(Infinity|NaN)$/,x=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(p,e,s,l){var f,h=s?e:e.replace(x,"");if(C.test(h))p.s=isNaN(h)?null:h<0?-1:1;else{if(!s&&(h=h.replace(_,function(v,k,w){return f=(w=w.toLowerCase())=="x"?16:w=="b"?2:8,!l||l==f?k:v}),l&&(f=l,h=h.replace(b,"$1").replace(S,"0.$1")),e!=h))return new O(h,f);if(O.DEBUG)throw Error(Vt+"Not a"+(l?" base "+l:"")+" number: "+e);p.s=null}p.c=p.e=null}})();function q(_,b,S,C){var x,p,e,s,l,f,h,v=_.c,k=xi;if(v){t:{for(x=1,s=v[0];s>=10;s/=10,x++);if(p=b-x,p<0)p+=tt,e=b,l=v[f=0],h=Qt(l/k[x-e-1]%10);else if(f=Ai((p+1)/tt),f>=v.length)if(C){for(;v.length<=f;v.push(0));l=h=0,x=1,p%=tt,e=p-tt+1}else break t;else{for(l=s=v[f],x=1;s>=10;s/=10,x++);p%=tt,e=p-tt+x,h=e<0?0:Qt(l/k[x-e-1]%10)}if(C=C||b<0||v[f+1]!=null||(e<0?l:l%k[x-e-1]),C=S<4?(h||C)&&(S==0||S==(_.s<0?3:2)):h>5||h==5&&(S==4||C||S==6&&(p>0?e>0?l/k[x-e]:0:v[f-1])%10&1||S==(_.s<0?8:7)),b<1||!v[0])return v.length=0,C?(b-=_.e+1,v[0]=k[(tt-b%tt)%tt],_.e=-b||0):v[0]=_.e=0,_;if(p==0?(v.length=f,s=1,f--):(v.length=f+1,s=k[tt-p],v[f]=e>0?Qt(l/k[x-e]%k[e])*s:0),C)for(;;)if(f==0){for(p=1,e=v[0];e>=10;e/=10,p++);for(e=v[0]+=s,s=1;e>=10;e/=10,s++);p!=s&&(_.e++,v[0]==ie&&(v[0]=1));break}else{if(v[f]+=s,v[f]!=ie)break;v[f--]=0,s=1}for(p=v.length;v[--p]===0;v.pop());}_.e>P?_.c=_.e=null:_.e<M&&(_.c=[_.e=0])}return _}function Z(_){var b,S=_.e;return S===null?_.toString():(b=Yt(_.c),b=S<=m||S>=g?Fe(b,S):ce(b,S,"0"),_.s<0?"-"+b:b)}return t.absoluteValue=t.abs=function(){var _=new O(this);return _.s<0&&(_.s=1),_},t.comparedTo=function(_,b){return Me(this,new O(_,b))},t.decimalPlaces=t.dp=function(_,b){var S,C,x,p=this;if(_!=null)return ft(_,0,Wt),b==null?b=c:ft(b,0,8),q(new O(p),_+p.e+1,b);if(!(S=p.c))return null;if(C=((x=S.length-1)-te(this.e/tt))*tt,x=S[x])for(;x%10==0;x/=10,C--);return C<0&&(C=0),C},t.dividedBy=t.div=function(_,b){return i(this,new O(_,b),d,c)},t.dividedToIntegerBy=t.idiv=function(_,b){return i(this,new O(_,b),0,1)},t.exponentiatedBy=t.pow=function(_,b){var S,C,x,p,e,s,l,f,h,v=this;if(_=new O(_),_.c&&!_.isInteger())throw Error(Vt+"Exponent not an integer: "+Z(_));if(b!=null&&(b=new O(b)),s=_.e>14,!v.c||!v.c[0]||v.c[0]==1&&!v.e&&v.c.length==1||!_.c||!_.c[0])return h=new O(Math.pow(+Z(v),s?_.s*(2-qe(_)):+Z(_))),b?h.mod(b):h;if(l=_.s<0,b){if(b.c?!b.c[0]:!b.s)return new O(NaN);C=!l&&v.isInteger()&&b.isInteger(),C&&(v=v.mod(b))}else{if(_.e>9&&(v.e>0||v.e<-1||(v.e==0?v.c[0]>1||s&&v.c[1]>=24e7:v.c[0]<8e13||s&&v.c[0]<=9999975e7)))return p=v.s<0&&qe(_)?-0:0,v.e>-1&&(p=1/p),new O(l?1/p:p);T&&(p=Ai(T/tt+2))}for(s?(S=new O(.5),l&&(_.s=1),f=qe(_)):(x=Math.abs(+Z(_)),f=x%2),h=new O(a);;){if(f){if(h=h.times(v),!h.c)break;p?h.c.length>p&&(h.c.length=p):C&&(h=h.mod(b))}if(x){if(x=Qt(x/2),x===0)break;f=x%2}else if(_=_.times(S),q(_,_.e+1,1),_.e>14)f=qe(_);else{if(x=+Z(_),x===0)break;f=x%2}v=v.times(v),p?v.c&&v.c.length>p&&(v.c.length=p):C&&(v=v.mod(b))}return C?h:(l&&(h=a.div(h)),b?h.mod(b):p?q(h,T,c,e):h)},t.integerValue=function(_){var b=new O(this);return _==null?_=c:ft(_,0,8),q(b,b.e+1,_)},t.isEqualTo=t.eq=function(_,b){return Me(this,new O(_,b))===0},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(_,b){return Me(this,new O(_,b))>0},t.isGreaterThanOrEqualTo=t.gte=function(_,b){return(b=Me(this,new O(_,b)))===1||b===0},t.isInteger=function(){return!!this.c&&te(this.e/tt)>this.c.length-2},t.isLessThan=t.lt=function(_,b){return Me(this,new O(_,b))<0},t.isLessThanOrEqualTo=t.lte=function(_,b){return(b=Me(this,new O(_,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(_,b){var S,C,x,p,e=this,s=e.s;if(_=new O(_,b),b=_.s,!s||!b)return new O(NaN);if(s!=b)return _.s=-b,e.plus(_);var l=e.e/tt,f=_.e/tt,h=e.c,v=_.c;if(!l||!f){if(!h||!v)return h?(_.s=-b,_):new O(v?e:NaN);if(!h[0]||!v[0])return v[0]?(_.s=-b,_):new O(h[0]?e:c==3?-0:0)}if(l=te(l),f=te(f),h=h.slice(),s=l-f){for((p=s<0)?(s=-s,x=h):(f=l,x=v),x.reverse(),b=s;b--;x.push(0));x.reverse()}else for(C=(p=(s=h.length)<(b=v.length))?s:b,s=b=0;b<C;b++)if(h[b]!=v[b]){p=h[b]<v[b];break}if(p&&(x=h,h=v,v=x,_.s=-_.s),b=(C=v.length)-(S=h.length),b>0)for(;b--;h[S++]=0);for(b=ie-1;C>s;){if(h[--C]<v[C]){for(S=C;S&&!h[--S];h[S]=b);--h[S],h[C]+=ie}h[C]-=v[C]}for(;h[0]==0;h.splice(0,1),--f);return h[0]?W(_,h,f):(_.s=c==3?-1:1,_.c=[_.e=0],_)},t.modulo=t.mod=function(_,b){var S,C,x=this;return _=new O(_,b),!x.c||!_.s||_.c&&!_.c[0]?new O(NaN):!_.c||x.c&&!x.c[0]?new O(x):(D==9?(C=_.s,_.s=1,S=i(x,_,0,3),_.s=C,S.s*=C):S=i(x,_,0,D),_=x.minus(S.times(_)),!_.c[0]&&D==1&&(_.s=x.s),_)},t.multipliedBy=t.times=function(_,b){var S,C,x,p,e,s,l,f,h,v,k,w,u,y,$,F=this,j=F.c,K=(_=new O(_,b)).c;if(!j||!K||!j[0]||!K[0])return!F.s||!_.s||j&&!j[0]&&!K||K&&!K[0]&&!j?_.c=_.e=_.s=null:(_.s*=F.s,!j||!K?_.c=_.e=null:(_.c=[0],_.e=0)),_;for(C=te(F.e/tt)+te(_.e/tt),_.s*=F.s,l=j.length,v=K.length,l<v&&(u=j,j=K,K=u,x=l,l=v,v=x),x=l+v,u=[];x--;u.push(0));for(y=ie,$=pe,x=v;--x>=0;){for(S=0,k=K[x]%$,w=K[x]/$|0,e=l,p=x+e;p>x;)f=j[--e]%$,h=j[e]/$|0,s=w*f+h*k,f=k*f+s%$*$+u[p]+S,S=(f/y|0)+(s/$|0)+w*h,u[p--]=f%y;u[p]=S}return S?++C:u.splice(0,1),W(_,u,C)},t.negated=function(){var _=new O(this);return _.s=-_.s||null,_},t.plus=function(_,b){var S,C=this,x=C.s;if(_=new O(_,b),b=_.s,!x||!b)return new O(NaN);if(x!=b)return _.s=-b,C.minus(_);var p=C.e/tt,e=_.e/tt,s=C.c,l=_.c;if(!p||!e){if(!s||!l)return new O(x/0);if(!s[0]||!l[0])return l[0]?_:new O(s[0]?C:x*0)}if(p=te(p),e=te(e),s=s.slice(),x=p-e){for(x>0?(e=p,S=l):(x=-x,S=s),S.reverse();x--;S.push(0));S.reverse()}for(x=s.length,b=l.length,x-b<0&&(S=l,l=s,s=S,b=x),x=0;b;)x=(s[--b]=s[b]+l[b]+x)/ie|0,s[b]=ie===s[b]?0:s[b]%ie;return x&&(s=[x].concat(s),++e),W(_,s,e)},t.precision=t.sd=function(_,b){var S,C,x,p=this;if(_!=null&&_!==!!_)return ft(_,1,Wt),b==null?b=c:ft(b,0,8),q(new O(p),_,b);if(!(S=p.c))return null;if(x=S.length-1,C=x*tt+1,x=S[x]){for(;x%10==0;x/=10,C--);for(x=S[0];x>=10;x/=10,C++);}return _&&p.e+1>C&&(C=p.e+1),C},t.shiftedBy=function(_){return ft(_,-Ci,Ci),this.times("1e"+_)},t.squareRoot=t.sqrt=function(){var _,b,S,C,x,p=this,e=p.c,s=p.s,l=p.e,f=d+4,h=new O("0.5");if(s!==1||!e||!e[0])return new O(!s||s<0&&(!e||e[0])?NaN:e?p:1/0);if(s=Math.sqrt(+Z(p)),s==0||s==1/0?(b=Yt(e),(b.length+l)%2==0&&(b+="0"),s=Math.sqrt(+b),l=te((l+1)/2)-(l<0||l%2),s==1/0?b="5e"+l:(b=s.toExponential(),b=b.slice(0,b.indexOf("e")+1)+l),S=new O(b)):S=new O(s+""),S.c[0]){for(l=S.e,s=l+f,s<3&&(s=0);;)if(x=S,S=h.times(x.plus(i(p,x,f,1))),Yt(x.c).slice(0,s)===(b=Yt(S.c)).slice(0,s))if(S.e<l&&--s,b=b.slice(s-3,s+1),b=="9999"||!C&&b=="4999"){if(!C&&(q(x,x.e+d+2,0),x.times(x).eq(p))){S=x;break}f+=4,s+=4,C=1}else{(!+b||!+b.slice(1)&&b.charAt(0)=="5")&&(q(S,S.e+d+2,1),_=!S.times(S).eq(p));break}}return q(S,S.e+d+1,c,_)},t.toExponential=function(_,b){return _!=null&&(ft(_,0,Wt),_++),I(this,_,b,1)},t.toFixed=function(_,b){return _!=null&&(ft(_,0,Wt),_=_+this.e+1),I(this,_,b)},t.toFormat=function(_,b,S){var C,x=this;if(S==null)_!=null&&b&&typeof b=="object"?(S=b,b=null):_&&typeof _=="object"?(S=_,_=b=null):S=L;else if(typeof S!="object")throw Error(Vt+"Argument not an object: "+S);if(C=x.toFixed(_,b),x.c){var p,e=C.split("."),s=+S.groupSize,l=+S.secondaryGroupSize,f=S.groupSeparator||"",h=e[0],v=e[1],k=x.s<0,w=k?h.slice(1):h,u=w.length;if(l&&(p=s,s=l,l=p,u-=p),s>0&&u>0){for(p=u%s||s,h=w.substr(0,p);p<u;p+=s)h+=f+w.substr(p,s);l>0&&(h+=f+w.slice(p)),k&&(h="-"+h)}C=v?h+(S.decimalSeparator||"")+((l=+S.fractionGroupSize)?v.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(S.fractionGroupSeparator||"")):v):h}return(S.prefix||"")+C+(S.suffix||"")},t.toFraction=function(_){var b,S,C,x,p,e,s,l,f,h,v,k,w=this,u=w.c;if(_!=null&&(s=new O(_),!s.isInteger()&&(s.c||s.s!==1)||s.lt(a)))throw Error(Vt+"Argument "+(s.isInteger()?"out of range: ":"not an integer: ")+Z(s));if(!u)return new O(w);for(b=new O(a),f=S=new O(a),C=l=new O(a),k=Yt(u),p=b.e=k.length-w.e-1,b.c[0]=xi[(e=p%tt)<0?tt+e:e],_=!_||s.comparedTo(b)>0?p>0?b:f:s,e=P,P=1/0,s=new O(k),l.c[0]=0;h=i(s,b,0,1),x=S.plus(h.times(C)),x.comparedTo(_)!=1;)S=C,C=x,f=l.plus(h.times(x=f)),l=x,b=s.minus(h.times(x=b)),s=x;return x=i(_.minus(S),C,0,1),l=l.plus(x.times(f)),S=S.plus(x.times(C)),l.s=f.s=w.s,p=p*2,v=i(f,C,p,c).minus(w).abs().comparedTo(i(l,S,p,c).minus(w).abs())<1?[f,C]:[l,S],P=e,v},t.toNumber=function(){return+Z(this)},t.toPrecision=function(_,b){return _!=null&&ft(_,1,Wt),I(this,_,b,2)},t.toString=function(_){var b,S=this,C=S.s,x=S.e;return x===null?C?(b="Infinity",C<0&&(b="-"+b)):b="NaN":(_==null?b=x<=m||x>=g?Fe(Yt(S.c),x):ce(Yt(S.c),x,"0"):_===10&&R?(S=q(new O(S),d+x+1,c),b=ce(Yt(S.c),S.e,"0")):(ft(_,2,N.length,"Base"),b=r(ce(Yt(S.c),x,"0"),10,_,C,!0)),C<0&&S.c[0]&&(b="-"+b)),b},t.valueOf=t.toJSON=function(){return Z(this)},t._isBigNumber=!0,t[Symbol.toStringTag]="BigNumber",t[Symbol.for("nodejs.util.inspect.custom")]=t.valueOf,n!=null&&O.set(n),O}function te(n){var i=n|0;return n>0||n===i?i:i-1}function Yt(n){for(var i,r,o=1,t=n.length,a=n[0]+"";o<t;){for(i=n[o++]+"",r=tt-i.length;r--;i="0"+i);a+=i}for(t=a.length;a.charCodeAt(--t)===48;);return a.slice(0,t+1||1)}function Me(n,i){var r,o,t=n.c,a=i.c,d=n.s,c=i.s,m=n.e,g=i.e;if(!d||!c)return null;if(r=t&&!t[0],o=a&&!a[0],r||o)return r?o?0:-c:d;if(d!=c)return d;if(r=d<0,o=m==g,!t||!a)return o?0:!t^r?1:-1;if(!o)return m>g^r?1:-1;for(c=(m=t.length)<(g=a.length)?m:g,d=0;d<c;d++)if(t[d]!=a[d])return t[d]>a[d]^r?1:-1;return m==g?0:m>g^r?1:-1}function ft(n,i,r,o){if(n<i||n>r||n!==Qt(n))throw Error(Vt+(o||"Argument")+(typeof n=="number"?n<i||n>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(n))}function qe(n){var i=n.c.length-1;return te(n.e/tt)==i&&n.c[i]%2!=0}function Fe(n,i){return(n.length>1?n.charAt(0)+"."+n.slice(1):n)+(i<0?"e":"e+")+i}function ce(n,i,r){var o,t;if(i<0){for(t=r+".";++i;t+=r);n=t+n}else if(o=n.length,++i>o){for(t=r,i-=o;--i;t+=r);n+=t}else i<o&&(n=n.slice(0,i)+"."+n.slice(i));return n}var tn=fr(),lt=tn;import{Transaction as ne}from"@mysten/sui/transactions";var Ae=9e15,we=1e9,Di="0123456789abcdef",$e="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",We="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ti={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ae,maxE:Ae,crypto:!1},mr,fe,Y=!0,Ke="[DecimalError] ",_e=Ke+"Invalid argument: ",gr=Ke+"Precision limit exceeded",_r=Ke+"crypto unavailable",wr="[object Decimal]",zt=Math.floor,$t=Math.pow,en=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,rn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,nn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,vr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,re=1e7,H=7,on=9007199254740991,sn=$e.length-1,Oi=We.length-1,B={toStringTag:wr};B.absoluteValue=B.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),z(n)};B.ceil=function(){return z(new this.constructor(this),this.e+1,2)};B.clampedTo=B.clamp=function(n,i){var r,o=this,t=o.constructor;if(n=new t(n),i=new t(i),!n.s||!i.s)return new t(NaN);if(n.gt(i))throw Error(_e+i);return r=o.cmp(n),r<0?n:o.cmp(i)>0?i:new t(o)};B.comparedTo=B.cmp=function(n){var i,r,o,t,a=this,d=a.d,c=(n=new a.constructor(n)).d,m=a.s,g=n.s;if(!d||!c)return!m||!g?NaN:m!==g?m:d===c?0:!d^m<0?1:-1;if(!d[0]||!c[0])return d[0]?m:c[0]?-g:0;if(m!==g)return m;if(a.e!==n.e)return a.e>n.e^m<0?1:-1;for(o=d.length,t=c.length,i=0,r=o<t?o:t;i<r;++i)if(d[i]!==c[i])return d[i]>c[i]^m<0?1:-1;return o===t?0:o>t^m<0?1:-1};B.cosine=B.cos=function(){var n,i,r=this,o=r.constructor;return r.d?r.d[0]?(n=o.precision,i=o.rounding,o.precision=n+Math.max(r.e,r.sd())+H,o.rounding=1,r=an(o,Sr(o,r)),o.precision=n,o.rounding=i,z(fe==2||fe==3?r.neg():r,n,i,!0)):new o(1):new o(NaN)};B.cubeRoot=B.cbrt=function(){var n,i,r,o,t,a,d,c,m,g,M=this,P=M.constructor;if(!M.isFinite()||M.isZero())return new P(M);for(Y=!1,a=M.s*$t(M.s*M,1/3),!a||Math.abs(a)==1/0?(r=Zt(M.d),n=M.e,(a=(n-r.length+1)%3)&&(r+=a==1||a==-2?"0":"00"),a=$t(r,1/3),n=zt((n+1)/3)-(n%3==(n<0?-1:2)),a==1/0?r="5e"+n:(r=a.toExponential(),r=r.slice(0,r.indexOf("e")+1)+n),o=new P(r),o.s=M.s):o=new P(a.toString()),d=(n=P.precision)+3;;)if(c=o,m=c.times(c).times(c),g=m.plus(M),o=ot(g.plus(M).times(c),g.plus(m),d+2,1),Zt(c.d).slice(0,d)===(r=Zt(o.d)).slice(0,d))if(r=r.slice(d-3,d+1),r=="9999"||!t&&r=="4999"){if(!t&&(z(c,n+1,0),c.times(c).times(c).eq(M))){o=c;break}d+=4,t=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(z(o,n+1,1),i=!o.times(o).times(o).eq(M));break}return Y=!0,z(o,n,P.rounding,i)};B.decimalPlaces=B.dp=function(){var n,i=this.d,r=NaN;if(i){if(n=i.length-1,r=(n-zt(this.e/H))*H,n=i[n],n)for(;n%10==0;n/=10)r--;r<0&&(r=0)}return r};B.dividedBy=B.div=function(n){return ot(this,new this.constructor(n))};B.dividedToIntegerBy=B.divToInt=function(n){var i=this,r=i.constructor;return z(ot(i,new r(n),0,1,1),r.precision,r.rounding)};B.equals=B.eq=function(n){return this.cmp(n)===0};B.floor=function(){return z(new this.constructor(this),this.e+1,3)};B.greaterThan=B.gt=function(n){return this.cmp(n)>0};B.greaterThanOrEqualTo=B.gte=function(n){var i=this.cmp(n);return i==1||i===0};B.hyperbolicCosine=B.cosh=function(){var n,i,r,o,t,a=this,d=a.constructor,c=new d(1);if(!a.isFinite())return new d(a.s?1/0:NaN);if(a.isZero())return c;r=d.precision,o=d.rounding,d.precision=r+Math.max(a.e,a.sd())+4,d.rounding=1,t=a.d.length,t<32?(n=Math.ceil(t/3),i=(1/Ge(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),a=Ce(d,1,a.times(i),new d(1),!0);for(var m,g=n,M=new d(8);g--;)m=a.times(a),a=c.minus(m.times(M.minus(m.times(M))));return z(a,d.precision=r,d.rounding=o,!0)};B.hyperbolicSine=B.sinh=function(){var n,i,r,o,t=this,a=t.constructor;if(!t.isFinite()||t.isZero())return new a(t);if(i=a.precision,r=a.rounding,a.precision=i+Math.max(t.e,t.sd())+4,a.rounding=1,o=t.d.length,o<3)t=Ce(a,2,t,t,!0);else{n=1.4*Math.sqrt(o),n=n>16?16:n|0,t=t.times(1/Ge(5,n)),t=Ce(a,2,t,t,!0);for(var d,c=new a(5),m=new a(16),g=new a(20);n--;)d=t.times(t),t=t.times(c.plus(d.times(m.times(d).plus(g))))}return a.precision=i,a.rounding=r,z(t,i,r,!0)};B.hyperbolicTangent=B.tanh=function(){var n,i,r=this,o=r.constructor;return r.isFinite()?r.isZero()?new o(r):(n=o.precision,i=o.rounding,o.precision=n+7,o.rounding=1,ot(r.sinh(),r.cosh(),o.precision=n,o.rounding=i)):new o(r.s)};B.inverseCosine=B.acos=function(){var n=this,i=n.constructor,r=n.abs().cmp(1),o=i.precision,t=i.rounding;return r!==-1?r===0?n.isNeg()?ae(i,o,t):new i(0):new i(NaN):n.isZero()?ae(i,o+4,t).times(.5):(i.precision=o+6,i.rounding=1,n=new i(1).minus(n).div(n.plus(1)).sqrt().atan(),i.precision=o,i.rounding=t,n.times(2))};B.inverseHyperbolicCosine=B.acosh=function(){var n,i,r=this,o=r.constructor;return r.lte(1)?new o(r.eq(1)?0:NaN):r.isFinite()?(n=o.precision,i=o.rounding,o.precision=n+Math.max(Math.abs(r.e),r.sd())+4,o.rounding=1,Y=!1,r=r.times(r).minus(1).sqrt().plus(r),Y=!0,o.precision=n,o.rounding=i,r.ln()):new o(r)};B.inverseHyperbolicSine=B.asinh=function(){var n,i,r=this,o=r.constructor;return!r.isFinite()||r.isZero()?new o(r):(n=o.precision,i=o.rounding,o.precision=n+2*Math.max(Math.abs(r.e),r.sd())+6,o.rounding=1,Y=!1,r=r.times(r).plus(1).sqrt().plus(r),Y=!0,o.precision=n,o.rounding=i,r.ln())};B.inverseHyperbolicTangent=B.atanh=function(){var n,i,r,o,t=this,a=t.constructor;return t.isFinite()?t.e>=0?new a(t.abs().eq(1)?t.s/0:t.isZero()?t:NaN):(n=a.precision,i=a.rounding,o=t.sd(),Math.max(o,n)<2*-t.e-1?z(new a(t),n,i,!0):(a.precision=r=o-t.e,t=ot(t.plus(1),new a(1).minus(t),r+n,1),a.precision=n+4,a.rounding=1,t=t.ln(),a.precision=n,a.rounding=i,t.times(.5))):new a(NaN)};B.inverseSine=B.asin=function(){var n,i,r,o,t=this,a=t.constructor;return t.isZero()?new a(t):(i=t.abs().cmp(1),r=a.precision,o=a.rounding,i!==-1?i===0?(n=ae(a,r+4,o).times(.5),n.s=t.s,n):new a(NaN):(a.precision=r+6,a.rounding=1,t=t.div(new a(1).minus(t.times(t)).sqrt().plus(1)).atan(),a.precision=r,a.rounding=o,t.times(2)))};B.inverseTangent=B.atan=function(){var n,i,r,o,t,a,d,c,m,g=this,M=g.constructor,P=M.precision,A=M.rounding;if(g.isFinite()){if(g.isZero())return new M(g);if(g.abs().eq(1)&&P+4<=Oi)return d=ae(M,P+4,A).times(.25),d.s=g.s,d}else{if(!g.s)return new M(NaN);if(P+4<=Oi)return d=ae(M,P+4,A).times(.5),d.s=g.s,d}for(M.precision=c=P+10,M.rounding=1,r=Math.min(28,c/H+2|0),n=r;n;--n)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(Y=!1,i=Math.ceil(c/H),o=1,m=g.times(g),d=new M(g),t=g;n!==-1;)if(t=t.times(m),a=d.minus(t.div(o+=2)),t=t.times(m),d=a.plus(t.div(o+=2)),d.d[i]!==void 0)for(n=i;d.d[n]===a.d[n]&&n--;);return r&&(d=d.times(2<<r-1)),Y=!0,z(d,M.precision=P,M.rounding=A,!0)};B.isFinite=function(){return!!this.d};B.isInteger=B.isInt=function(){return!!this.d&&zt(this.e/H)>this.d.length-2};B.isNaN=function(){return!this.s};B.isNegative=B.isNeg=function(){return this.s<0};B.isPositive=B.isPos=function(){return this.s>0};B.isZero=function(){return!!this.d&&this.d[0]===0};B.lessThan=B.lt=function(n){return this.cmp(n)<0};B.lessThanOrEqualTo=B.lte=function(n){return this.cmp(n)<1};B.logarithm=B.log=function(n){var i,r,o,t,a,d,c,m,g=this,M=g.constructor,P=M.precision,A=M.rounding,D=5;if(n==null)n=new M(10),i=!0;else{if(n=new M(n),r=n.d,n.s<0||!r||!r[0]||n.eq(1))return new M(NaN);i=n.eq(10)}if(r=g.d,g.s<0||!r||!r[0]||g.eq(1))return new M(r&&!r[0]?-1/0:g.s!=1?NaN:r?0:1/0);if(i)if(r.length>1)a=!0;else{for(t=r[0];t%10===0;)t/=10;a=t!==1}if(Y=!1,c=P+D,d=ge(g,c),o=i?Ze(M,c+10):ge(n,c),m=ot(d,o,c,1),Te(m.d,t=P,A))do if(c+=10,d=ge(g,c),o=i?Ze(M,c+10):ge(n,c),m=ot(d,o,c,1),!a){+Zt(m.d).slice(t+1,t+15)+1==1e14&&(m=z(m,P+1,0));break}while(Te(m.d,t+=10,A));return Y=!0,z(m,P,A)};B.minus=B.sub=function(n){var i,r,o,t,a,d,c,m,g,M,P,A,D=this,T=D.constructor;if(n=new T(n),!D.d||!n.d)return!D.s||!n.s?n=new T(NaN):D.d?n.s=-n.s:n=new T(n.d||D.s!==n.s?D:NaN),n;if(D.s!=n.s)return n.s=-n.s,D.plus(n);if(g=D.d,A=n.d,c=T.precision,m=T.rounding,!g[0]||!A[0]){if(A[0])n.s=-n.s;else if(g[0])n=new T(D);else return new T(m===3?-0:0);return Y?z(n,c,m):n}if(r=zt(n.e/H),M=zt(D.e/H),g=g.slice(),a=M-r,a){for(P=a<0,P?(i=g,a=-a,d=A.length):(i=A,r=M,d=g.length),o=Math.max(Math.ceil(c/H),d)+2,a>o&&(a=o,i.length=1),i.reverse(),o=a;o--;)i.push(0);i.reverse()}else{for(o=g.length,d=A.length,P=o<d,P&&(d=o),o=0;o<d;o++)if(g[o]!=A[o]){P=g[o]<A[o];break}a=0}for(P&&(i=g,g=A,A=i,n.s=-n.s),d=g.length,o=A.length-d;o>0;--o)g[d++]=0;for(o=A.length;o>a;){if(g[--o]<A[o]){for(t=o;t&&g[--t]===0;)g[t]=re-1;--g[t],g[o]+=re}g[o]-=A[o]}for(;g[--d]===0;)g.pop();for(;g[0]===0;g.shift())--r;return g[0]?(n.d=g,n.e=ze(g,r),Y?z(n,c,m):n):new T(m===3?-0:0)};B.modulo=B.mod=function(n){var i,r=this,o=r.constructor;return n=new o(n),!r.d||!n.s||n.d&&!n.d[0]?new o(NaN):!n.d||r.d&&!r.d[0]?z(new o(r),o.precision,o.rounding):(Y=!1,o.modulo==9?(i=ot(r,n.abs(),0,3,1),i.s*=n.s):i=ot(r,n,0,o.modulo,1),i=i.times(n),Y=!0,r.minus(i))};B.naturalExponential=B.exp=function(){return Ri(this)};B.naturalLogarithm=B.ln=function(){return ge(this)};B.negated=B.neg=function(){var n=new this.constructor(this);return n.s=-n.s,z(n)};B.plus=B.add=function(n){var i,r,o,t,a,d,c,m,g,M,P=this,A=P.constructor;if(n=new A(n),!P.d||!n.d)return!P.s||!n.s?n=new A(NaN):P.d||(n=new A(n.d||P.s===n.s?P:NaN)),n;if(P.s!=n.s)return n.s=-n.s,P.minus(n);if(g=P.d,M=n.d,c=A.precision,m=A.rounding,!g[0]||!M[0])return M[0]||(n=new A(P)),Y?z(n,c,m):n;if(a=zt(P.e/H),o=zt(n.e/H),g=g.slice(),t=a-o,t){for(t<0?(r=g,t=-t,d=M.length):(r=M,o=a,d=g.length),a=Math.ceil(c/H),d=a>d?a+1:d+1,t>d&&(t=d,r.length=1),r.reverse();t--;)r.push(0);r.reverse()}for(d=g.length,t=M.length,d-t<0&&(t=d,r=M,M=g,g=r),i=0;t;)i=(g[--t]=g[t]+M[t]+i)/re|0,g[t]%=re;for(i&&(g.unshift(i),++o),d=g.length;g[--d]==0;)g.pop();return n.d=g,n.e=ze(g,o),Y?z(n,c,m):n};B.precision=B.sd=function(n){var i,r=this;if(n!==void 0&&n!==!!n&&n!==1&&n!==0)throw Error(_e+n);return r.d?(i=Mr(r.d),n&&r.e+1>i&&(i=r.e+1)):i=NaN,i};B.round=function(){var n=this,i=n.constructor;return z(new i(n),n.e+1,i.rounding)};B.sine=B.sin=function(){var n,i,r=this,o=r.constructor;return r.isFinite()?r.isZero()?new o(r):(n=o.precision,i=o.rounding,o.precision=n+Math.max(r.e,r.sd())+H,o.rounding=1,r=un(o,Sr(o,r)),o.precision=n,o.rounding=i,z(fe>2?r.neg():r,n,i,!0)):new o(NaN)};B.squareRoot=B.sqrt=function(){var n,i,r,o,t,a,d=this,c=d.d,m=d.e,g=d.s,M=d.constructor;if(g!==1||!c||!c[0])return new M(!g||g<0&&(!c||c[0])?NaN:c?d:1/0);for(Y=!1,g=Math.sqrt(+d),g==0||g==1/0?(i=Zt(c),(i.length+m)%2==0&&(i+="0"),g=Math.sqrt(i),m=zt((m+1)/2)-(m<0||m%2),g==1/0?i="5e"+m:(i=g.toExponential(),i=i.slice(0,i.indexOf("e")+1)+m),o=new M(i)):o=new M(g.toString()),r=(m=M.precision)+3;;)if(a=o,o=a.plus(ot(d,a,r+2,1)).times(.5),Zt(a.d).slice(0,r)===(i=Zt(o.d)).slice(0,r))if(i=i.slice(r-3,r+1),i=="9999"||!t&&i=="4999"){if(!t&&(z(a,m+1,0),a.times(a).eq(d))){o=a;break}r+=4,t=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(z(o,m+1,1),n=!o.times(o).eq(d));break}return Y=!0,z(o,m,M.rounding,n)};B.tangent=B.tan=function(){var n,i,r=this,o=r.constructor;return r.isFinite()?r.isZero()?new o(r):(n=o.precision,i=o.rounding,o.precision=n+10,o.rounding=1,r=r.sin(),r.s=1,r=ot(r,new o(1).minus(r.times(r)).sqrt(),n+10,0),o.precision=n,o.rounding=i,z(fe==2||fe==4?r.neg():r,n,i,!0)):new o(NaN)};B.times=B.mul=function(n){var i,r,o,t,a,d,c,m,g,M=this,P=M.constructor,A=M.d,D=(n=new P(n)).d;if(n.s*=M.s,!A||!A[0]||!D||!D[0])return new P(!n.s||A&&!A[0]&&!D||D&&!D[0]&&!A?NaN:!A||!D?n.s/0:n.s*0);for(r=zt(M.e/H)+zt(n.e/H),m=A.length,g=D.length,m<g&&(a=A,A=D,D=a,d=m,m=g,g=d),a=[],d=m+g,o=d;o--;)a.push(0);for(o=g;--o>=0;){for(i=0,t=m+o;t>o;)c=a[t]+D[o]*A[t-o-1]+i,a[t--]=c%re|0,i=c/re|0;a[t]=(a[t]+i)%re|0}for(;!a[--d];)a.pop();return i?++r:a.shift(),n.d=a,n.e=ze(a,r),Y?z(n,P.precision,P.rounding):n};B.toBinary=function(n,i){return Li(this,2,n,i)};B.toDecimalPlaces=B.toDP=function(n,i){var r=this,o=r.constructor;return r=new o(r),n===void 0?r:(Xt(n,0,we),i===void 0?i=o.rounding:Xt(i,0,8),z(r,n+r.e+1,i))};B.toExponential=function(n,i){var r,o=this,t=o.constructor;return n===void 0?r=le(o,!0):(Xt(n,0,we),i===void 0?i=t.rounding:Xt(i,0,8),o=z(new t(o),n+1,i),r=le(o,!0,n+1)),o.isNeg()&&!o.isZero()?"-"+r:r};B.toFixed=function(n,i){var r,o,t=this,a=t.constructor;return n===void 0?r=le(t):(Xt(n,0,we),i===void 0?i=a.rounding:Xt(i,0,8),o=z(new a(t),n+t.e+1,i),r=le(o,!1,n+o.e+1)),t.isNeg()&&!t.isZero()?"-"+r:r};B.toFraction=function(n){var i,r,o,t,a,d,c,m,g,M,P,A,D=this,T=D.d,L=D.constructor;if(!T)return new L(D);if(g=r=new L(1),o=m=new L(0),i=new L(o),a=i.e=Mr(T)-D.e-1,d=a%H,i.d[0]=$t(10,d<0?H+d:d),n==null)n=a>0?i:g;else{if(c=new L(n),!c.isInt()||c.lt(g))throw Error(_e+c);n=c.gt(i)?a>0?i:g:c}for(Y=!1,c=new L(Zt(T)),M=L.precision,L.precision=a=T.length*H*2;P=ot(c,i,0,1,1),t=r.plus(P.times(o)),t.cmp(n)!=1;)r=o,o=t,t=g,g=m.plus(P.times(t)),m=t,t=i,i=c.minus(P.times(t)),c=t;return t=ot(n.minus(r),o,0,1,1),m=m.plus(t.times(g)),r=r.plus(t.times(o)),m.s=g.s=D.s,A=ot(g,o,a,1).minus(D).abs().cmp(ot(m,r,a,1).minus(D).abs())<1?[g,o]:[m,r],L.precision=M,Y=!0,A};B.toHexadecimal=B.toHex=function(n,i){return Li(this,16,n,i)};B.toNearest=function(n,i){var r=this,o=r.constructor;if(r=new o(r),n==null){if(!r.d)return r;n=new o(1),i=o.rounding}else{if(n=new o(n),i===void 0?i=o.rounding:Xt(i,0,8),!r.d)return n.s?r:n;if(!n.d)return n.s&&(n.s=r.s),n}return n.d[0]?(Y=!1,r=ot(r,n,0,i,1).times(n),Y=!0,z(r)):(n.s=r.s,r=n),r};B.toNumber=function(){return+this};B.toOctal=function(n,i){return Li(this,8,n,i)};B.toPower=B.pow=function(n){var i,r,o,t,a,d,c=this,m=c.constructor,g=+(n=new m(n));if(!c.d||!n.d||!c.d[0]||!n.d[0])return new m($t(+c,g));if(c=new m(c),c.eq(1))return c;if(o=m.precision,a=m.rounding,n.eq(1))return z(c,o,a);if(i=zt(n.e/H),i>=n.d.length-1&&(r=g<0?-g:g)<=on)return t=br(m,c,r,o),n.s<0?new m(1).div(t):z(t,o,a);if(d=c.s,d<0){if(i<n.d.length-1)return new m(NaN);if((n.d[i]&1)==0&&(d=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=d,c}return r=$t(+c,g),i=r==0||!isFinite(r)?zt(g*(Math.log("0."+Zt(c.d))/Math.LN10+c.e+1)):new m(r+"").e,i>m.maxE+1||i<m.minE-1?new m(i>0?d/0:0):(Y=!1,m.rounding=c.s=1,r=Math.min(12,(i+"").length),t=Ri(n.times(ge(c,o+r)),o),t.d&&(t=z(t,o+5,1),Te(t.d,o,a)&&(i=o+10,t=z(Ri(n.times(ge(c,i+r)),i),i+5,1),+Zt(t.d).slice(o+1,o+15)+1==1e14&&(t=z(t,o+1,0)))),t.s=d,Y=!0,m.rounding=a,z(t,o,a))};B.toPrecision=function(n,i){var r,o=this,t=o.constructor;return n===void 0?r=le(o,o.e<=t.toExpNeg||o.e>=t.toExpPos):(Xt(n,1,we),i===void 0?i=t.rounding:Xt(i,0,8),o=z(new t(o),n,i),r=le(o,n<=o.e||o.e<=t.toExpNeg,n)),o.isNeg()&&!o.isZero()?"-"+r:r};B.toSignificantDigits=B.toSD=function(n,i){var r=this,o=r.constructor;return n===void 0?(n=o.precision,i=o.rounding):(Xt(n,1,we),i===void 0?i=o.rounding:Xt(i,0,8)),z(new o(r),n,i)};B.toString=function(){var n=this,i=n.constructor,r=le(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()&&!n.isZero()?"-"+r:r};B.truncated=B.trunc=function(){return z(new this.constructor(this),this.e+1,1)};B.valueOf=B.toJSON=function(){var n=this,i=n.constructor,r=le(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()?"-"+r:r};function Zt(n){var i,r,o,t=n.length-1,a="",d=n[0];if(t>0){for(a+=d,i=1;i<t;i++)o=n[i]+"",r=H-o.length,r&&(a+=me(r)),a+=o;d=n[i],o=d+"",r=H-o.length,r&&(a+=me(r))}else if(d===0)return"0";for(;d%10===0;)d/=10;return a+d}function Xt(n,i,r){if(n!==~~n||n<i||n>r)throw Error(_e+n)}function Te(n,i,r,o){var t,a,d,c;for(a=n[0];a>=10;a/=10)--i;return--i<0?(i+=H,t=0):(t=Math.ceil((i+1)/H),i%=H),a=$t(10,H-i),c=n[t]%a|0,o==null?i<3?(i==0?c=c/100|0:i==1&&(c=c/10|0),d=r<4&&c==99999||r>3&&c==49999||c==5e4||c==0):d=(r<4&&c+1==a||r>3&&c+1==a/2)&&(n[t+1]/a/100|0)==$t(10,i-2)-1||(c==a/2||c==0)&&(n[t+1]/a/100|0)==0:i<4?(i==0?c=c/1e3|0:i==1?c=c/100|0:i==2&&(c=c/10|0),d=(o||r<4)&&c==9999||!o&&r>3&&c==4999):d=((o||r<4)&&c+1==a||!o&&r>3&&c+1==a/2)&&(n[t+1]/a/1e3|0)==$t(10,i-3)-1,d}function Ue(n,i,r){for(var o,t=[0],a,d=0,c=n.length;d<c;){for(a=t.length;a--;)t[a]*=i;for(t[0]+=Di.indexOf(n.charAt(d++)),o=0;o<t.length;o++)t[o]>r-1&&(t[o+1]===void 0&&(t[o+1]=0),t[o+1]+=t[o]/r|0,t[o]%=r)}return t.reverse()}function an(n,i){var r,o,t;if(i.isZero())return i;o=i.d.length,o<32?(r=Math.ceil(o/3),t=(1/Ge(4,r)).toString()):(r=16,t="2.3283064365386962890625e-10"),n.precision+=r,i=Ce(n,1,i.times(t),new n(1));for(var a=r;a--;){var d=i.times(i);i=d.times(d).minus(d).times(8).plus(1)}return n.precision-=r,i}var ot=(function(){function n(o,t,a){var d,c=0,m=o.length;for(o=o.slice();m--;)d=o[m]*t+c,o[m]=d%a|0,c=d/a|0;return c&&o.unshift(c),o}function i(o,t,a,d){var c,m;if(a!=d)m=a>d?1:-1;else for(c=m=0;c<a;c++)if(o[c]!=t[c]){m=o[c]>t[c]?1:-1;break}return m}function r(o,t,a,d){for(var c=0;a--;)o[a]-=c,c=o[a]<t[a]?1:0,o[a]=c*d+o[a]-t[a];for(;!o[0]&&o.length>1;)o.shift()}return function(o,t,a,d,c,m){var g,M,P,A,D,T,L,N,R,O,I,U,W,q,Z,_,b,S,C,x,p=o.constructor,e=o.s==t.s?1:-1,s=o.d,l=t.d;if(!s||!s[0]||!l||!l[0])return new p(!o.s||!t.s||(s?l&&s[0]==l[0]:!l)?NaN:s&&s[0]==0||!l?e*0:e/0);for(m?(D=1,M=o.e-t.e):(m=re,D=H,M=zt(o.e/D)-zt(t.e/D)),C=l.length,b=s.length,R=new p(e),O=R.d=[],P=0;l[P]==(s[P]||0);P++);if(l[P]>(s[P]||0)&&M--,a==null?(q=a=p.precision,d=p.rounding):c?q=a+(o.e-t.e)+1:q=a,q<0)O.push(1),T=!0;else{if(q=q/D+2|0,P=0,C==1){for(A=0,l=l[0],q++;(P<b||A)&&q--;P++)Z=A*m+(s[P]||0),O[P]=Z/l|0,A=Z%l|0;T=A||P<b}else{for(A=m/(l[0]+1)|0,A>1&&(l=n(l,A,m),s=n(s,A,m),C=l.length,b=s.length),_=C,I=s.slice(0,C),U=I.length;U<C;)I[U++]=0;x=l.slice(),x.unshift(0),S=l[0],l[1]>=m/2&&++S;do A=0,g=i(l,I,C,U),g<0?(W=I[0],C!=U&&(W=W*m+(I[1]||0)),A=W/S|0,A>1?(A>=m&&(A=m-1),L=n(l,A,m),N=L.length,U=I.length,g=i(L,I,N,U),g==1&&(A--,r(L,C<N?x:l,N,m))):(A==0&&(g=A=1),L=l.slice()),N=L.length,N<U&&L.unshift(0),r(I,L,U,m),g==-1&&(U=I.length,g=i(l,I,C,U),g<1&&(A++,r(I,C<U?x:l,U,m))),U=I.length):g===0&&(A++,I=[0]),O[P++]=A,g&&I[0]?I[U++]=s[_]||0:(I=[s[_]],U=1);while((_++<b||I[0]!==void 0)&&q--);T=I[0]!==void 0}O[0]||O.shift()}if(D==1)R.e=M,mr=T;else{for(P=1,A=O[0];A>=10;A/=10)P++;R.e=P+M*D-1,z(R,c?a+R.e+1:a,d,T)}return R}})();function z(n,i,r,o){var t,a,d,c,m,g,M,P,A,D=n.constructor;t:if(i!=null){if(P=n.d,!P)return n;for(t=1,c=P[0];c>=10;c/=10)t++;if(a=i-t,a<0)a+=H,d=i,M=P[A=0],m=M/$t(10,t-d-1)%10|0;else if(A=Math.ceil((a+1)/H),c=P.length,A>=c)if(o){for(;c++<=A;)P.push(0);M=m=0,t=1,a%=H,d=a-H+1}else break t;else{for(M=c=P[A],t=1;c>=10;c/=10)t++;a%=H,d=a-H+t,m=d<0?0:M/$t(10,t-d-1)%10|0}if(o=o||i<0||P[A+1]!==void 0||(d<0?M:M%$t(10,t-d-1)),g=r<4?(m||o)&&(r==0||r==(n.s<0?3:2)):m>5||m==5&&(r==4||o||r==6&&(a>0?d>0?M/$t(10,t-d):0:P[A-1])%10&1||r==(n.s<0?8:7)),i<1||!P[0])return P.length=0,g?(i-=n.e+1,P[0]=$t(10,(H-i%H)%H),n.e=-i||0):P[0]=n.e=0,n;if(a==0?(P.length=A,c=1,A--):(P.length=A+1,c=$t(10,H-a),P[A]=d>0?(M/$t(10,t-d)%$t(10,d)|0)*c:0),g)for(;;)if(A==0){for(a=1,d=P[0];d>=10;d/=10)a++;for(d=P[0]+=c,c=1;d>=10;d/=10)c++;a!=c&&(n.e++,P[0]==re&&(P[0]=1));break}else{if(P[A]+=c,P[A]!=re)break;P[A--]=0,c=1}for(a=P.length;P[--a]===0;)P.pop()}return Y&&(n.e>D.maxE?(n.d=null,n.e=NaN):n.e<D.minE&&(n.e=0,n.d=[0])),n}function le(n,i,r){if(!n.isFinite())return kr(n);var o,t=n.e,a=Zt(n.d),d=a.length;return i?(r&&(o=r-d)>0?a=a.charAt(0)+"."+a.slice(1)+me(o):d>1&&(a=a.charAt(0)+"."+a.slice(1)),a=a+(n.e<0?"e":"e+")+n.e):t<0?(a="0."+me(-t-1)+a,r&&(o=r-d)>0&&(a+=me(o))):t>=d?(a+=me(t+1-d),r&&(o=r-t-1)>0&&(a=a+"."+me(o))):((o=t+1)<d&&(a=a.slice(0,o)+"."+a.slice(o)),r&&(o=r-d)>0&&(t+1===d&&(a+="."),a+=me(o))),a}function ze(n,i){var r=n[0];for(i*=H;r>=10;r/=10)i++;return i}function Ze(n,i,r){if(i>sn)throw Y=!0,r&&(n.precision=r),Error(gr);return z(new n($e),i,1,!0)}function ae(n,i,r){if(i>Oi)throw Error(gr);return z(new n(We),i,r,!0)}function Mr(n){var i=n.length-1,r=i*H+1;if(i=n[i],i){for(;i%10==0;i/=10)r--;for(i=n[0];i>=10;i/=10)r++}return r}function me(n){for(var i="";n--;)i+="0";return i}function br(n,i,r,o){var t,a=new n(1),d=Math.ceil(o/H+4);for(Y=!1;;){if(r%2&&(a=a.times(i),hr(a.d,d)&&(t=!0)),r=zt(r/2),r===0){r=a.d.length-1,t&&a.d[r]===0&&++a.d[r];break}i=i.times(i),hr(i.d,d)}return Y=!0,a}function dr(n){return n.d[n.d.length-1]&1}function yr(n,i,r){for(var o,t,a=new n(i[0]),d=0;++d<i.length;){if(t=new n(i[d]),!t.s){a=t;break}o=a.cmp(t),(o===r||o===0&&a.s===r)&&(a=t)}return a}function Ri(n,i){var r,o,t,a,d,c,m,g=0,M=0,P=0,A=n.constructor,D=A.rounding,T=A.precision;if(!n.d||!n.d[0]||n.e>17)return new A(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(i==null?(Y=!1,m=T):m=i,c=new A(.03125);n.e>-2;)n=n.times(c),P+=5;for(o=Math.log($t(2,P))/Math.LN10*2+5|0,m+=o,r=a=d=new A(1),A.precision=m;;){if(a=z(a.times(n),m,1),r=r.times(++M),c=d.plus(ot(a,r,m,1)),Zt(c.d).slice(0,m)===Zt(d.d).slice(0,m)){for(t=P;t--;)d=z(d.times(d),m,1);if(i==null)if(g<3&&Te(d.d,m-o,D,g))A.precision=m+=10,r=a=c=new A(1),M=0,g++;else return z(d,A.precision=T,D,Y=!0);else return A.precision=T,d}d=c}}function ge(n,i){var r,o,t,a,d,c,m,g,M,P,A,D=1,T=10,L=n,N=L.d,R=L.constructor,O=R.rounding,I=R.precision;if(L.s<0||!N||!N[0]||!L.e&&N[0]==1&&N.length==1)return new R(N&&!N[0]?-1/0:L.s!=1?NaN:N?0:L);if(i==null?(Y=!1,M=I):M=i,R.precision=M+=T,r=Zt(N),o=r.charAt(0),Math.abs(a=L.e)<15e14){for(;o<7&&o!=1||o==1&&r.charAt(1)>3;)L=L.times(n),r=Zt(L.d),o=r.charAt(0),D++;a=L.e,o>1?(L=new R("0."+r),a++):L=new R(o+"."+r.slice(1))}else return g=Ze(R,M+2,I).times(a+""),L=ge(new R(o+"."+r.slice(1)),M-T).plus(g),R.precision=I,i==null?z(L,I,O,Y=!0):L;for(P=L,m=d=L=ot(L.minus(1),L.plus(1),M,1),A=z(L.times(L),M,1),t=3;;){if(d=z(d.times(A),M,1),g=m.plus(ot(d,new R(t),M,1)),Zt(g.d).slice(0,M)===Zt(m.d).slice(0,M))if(m=m.times(2),a!==0&&(m=m.plus(Ze(R,M+2,I).times(a+""))),m=ot(m,new R(D),M,1),i==null)if(Te(m.d,M-T,O,c))R.precision=M+=T,g=d=L=ot(P.minus(1),P.plus(1),M,1),A=z(L.times(L),M,1),t=c=1;else return z(m,R.precision=I,O,Y=!0);else return R.precision=I,m;m=g,t+=2}}function kr(n){return String(n.s*n.s/0)}function je(n,i){var r,o,t;for((r=i.indexOf("."))>-1&&(i=i.replace(".","")),(o=i.search(/e/i))>0?(r<0&&(r=o),r+=+i.slice(o+1),i=i.substring(0,o)):r<0&&(r=i.length),o=0;i.charCodeAt(o)===48;o++);for(t=i.length;i.charCodeAt(t-1)===48;--t);if(i=i.slice(o,t),i){if(t-=o,n.e=r=r-o-1,n.d=[],o=(r+1)%H,r<0&&(o+=H),o<t){for(o&&n.d.push(+i.slice(0,o)),t-=H;o<t;)n.d.push(+i.slice(o,o+=H));i=i.slice(o),o=H-i.length}else o-=t;for(;o--;)i+="0";n.d.push(+i),Y&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function ln(n,i){var r,o,t,a,d,c,m,g,M;if(i.indexOf("_")>-1){if(i=i.replace(/(\d)_(?=\d)/g,"$1"),vr.test(i))return je(n,i)}else if(i==="Infinity"||i==="NaN")return+i||(n.s=NaN),n.e=NaN,n.d=null,n;if(rn.test(i))r=16,i=i.toLowerCase();else if(en.test(i))r=2;else if(nn.test(i))r=8;else throw Error(_e+i);for(a=i.search(/p/i),a>0?(m=+i.slice(a+1),i=i.substring(2,a)):i=i.slice(2),a=i.indexOf("."),d=a>=0,o=n.constructor,d&&(i=i.replace(".",""),c=i.length,a=c-a,t=br(o,new o(r),a,a*2)),g=Ue(i,r,re),M=g.length-1,a=M;g[a]===0;--a)g.pop();return a<0?new o(n.s*0):(n.e=ze(g,M),n.d=g,Y=!1,d&&(n=ot(n,t,c*4)),m&&(n=n.times(Math.abs(m)<54?$t(2,m):Oe.pow(2,m))),Y=!0,n)}function un(n,i){var r,o=i.d.length;if(o<3)return i.isZero()?i:Ce(n,2,i,i);r=1.4*Math.sqrt(o),r=r>16?16:r|0,i=i.times(1/Ge(5,r)),i=Ce(n,2,i,i);for(var t,a=new n(5),d=new n(16),c=new n(20);r--;)t=i.times(i),i=i.times(a.plus(t.times(d.times(t).minus(c))));return i}function Ce(n,i,r,o,t){var a,d,c,m,g=1,M=n.precision,P=Math.ceil(M/H);for(Y=!1,m=r.times(r),c=new n(o);;){if(d=ot(c.times(m),new n(i++*i++),M,1),c=t?o.plus(d):o.minus(d),o=ot(d.times(m),new n(i++*i++),M,1),d=c.plus(o),d.d[P]!==void 0){for(a=P;d.d[a]===c.d[a]&&a--;);if(a==-1)break}a=c,c=o,o=d,d=a,g++}return Y=!0,d.d.length=P+1,d}function Ge(n,i){for(var r=n;--i;)r*=n;return r}function Sr(n,i){var r,o=i.s<0,t=ae(n,n.precision,1),a=t.times(.5);if(i=i.abs(),i.lte(a))return fe=o?4:1,i;if(r=i.divToInt(t),r.isZero())fe=o?3:2;else{if(i=i.minus(r.times(t)),i.lte(a))return fe=dr(r)?o?2:3:o?4:1,i;fe=dr(r)?o?1:4:o?3:2}return i.minus(t).abs()}function Li(n,i,r,o){var t,a,d,c,m,g,M,P,A,D=n.constructor,T=r!==void 0;if(T?(Xt(r,1,we),o===void 0?o=D.rounding:Xt(o,0,8)):(r=D.precision,o=D.rounding),!n.isFinite())M=kr(n);else{for(M=le(n),d=M.indexOf("."),T?(t=2,i==16?r=r*4-3:i==8&&(r=r*3-2)):t=i,d>=0&&(M=M.replace(".",""),A=new D(1),A.e=M.length-d,A.d=Ue(le(A),10,t),A.e=A.d.length),P=Ue(M,10,t),a=m=P.length;P[--m]==0;)P.pop();if(!P[0])M=T?"0p+0":"0";else{if(d<0?a--:(n=new D(n),n.d=P,n.e=a,n=ot(n,A,r,o,0,t),P=n.d,a=n.e,g=mr),d=P[r],c=t/2,g=g||P[r+1]!==void 0,g=o<4?(d!==void 0||g)&&(o===0||o===(n.s<0?3:2)):d>c||d===c&&(o===4||g||o===6&&P[r-1]&1||o===(n.s<0?8:7)),P.length=r,g)for(;++P[--r]>t-1;)P[r]=0,r||(++a,P.unshift(1));for(m=P.length;!P[m-1];--m);for(d=0,M="";d<m;d++)M+=Di.charAt(P[d]);if(T){if(m>1)if(i==16||i==8){for(d=i==16?4:3,--m;m%d;m++)M+="0";for(P=Ue(M,t,i),m=P.length;!P[m-1];--m);for(d=1,M="1.";d<m;d++)M+=Di.charAt(P[d])}else M=M.charAt(0)+"."+M.slice(1);M=M+(a<0?"p":"p+")+a}else if(a<0){for(;++a;)M="0"+M;M="0."+M}else if(++a>m)for(a-=m;a--;)M+="0";else a<m&&(M=M.slice(0,a)+"."+M.slice(a))}M=(i==16?"0x":i==2?"0b":i==8?"0o":"")+M}return n.s<0?"-"+M:M}function hr(n,i){if(n.length>i)return n.length=i,!0}function cn(n){return new this(n).abs()}function fn(n){return new this(n).acos()}function dn(n){return new this(n).acosh()}function hn(n,i){return new this(n).plus(i)}function pn(n){return new this(n).asin()}function mn(n){return new this(n).asinh()}function gn(n){return new this(n).atan()}function _n(n){return new this(n).atanh()}function wn(n,i){n=new this(n),i=new this(i);var r,o=this.precision,t=this.rounding,a=o+4;return!n.s||!i.s?r=new this(NaN):!n.d&&!i.d?(r=ae(this,a,1).times(i.s>0?.25:.75),r.s=n.s):!i.d||n.isZero()?(r=i.s<0?ae(this,o,t):new this(0),r.s=n.s):!n.d||i.isZero()?(r=ae(this,a,1).times(.5),r.s=n.s):i.s<0?(this.precision=a,this.rounding=1,r=this.atan(ot(n,i,a,1)),i=ae(this,a,1),this.precision=o,this.rounding=t,r=n.s<0?r.minus(i):r.plus(i)):r=this.atan(ot(n,i,a,1)),r}function vn(n){return new this(n).cbrt()}function Mn(n){return z(n=new this(n),n.e+1,2)}function bn(n,i,r){return new this(n).clamp(i,r)}function yn(n){if(!n||typeof n!="object")throw Error(Ke+"Object expected");var i,r,o,t=n.defaults===!0,a=["precision",1,we,"rounding",0,8,"toExpNeg",-Ae,0,"toExpPos",0,Ae,"maxE",0,Ae,"minE",-Ae,0,"modulo",0,9];for(i=0;i<a.length;i+=3)if(r=a[i],t&&(this[r]=Ti[r]),(o=n[r])!==void 0)if(zt(o)===o&&o>=a[i+1]&&o<=a[i+2])this[r]=o;else throw Error(_e+r+": "+o);if(r="crypto",t&&(this[r]=Ti[r]),(o=n[r])!==void 0)if(o===!0||o===!1||o===0||o===1)if(o)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(_r);else this[r]=!1;else throw Error(_e+r+": "+o);return this}function kn(n){return new this(n).cos()}function Sn(n){return new this(n).cosh()}function Pr(n){var i,r,o;function t(a){var d,c,m,g=this;if(!(g instanceof t))return new t(a);if(g.constructor=t,pr(a)){g.s=a.s,Y?!a.d||a.e>t.maxE?(g.e=NaN,g.d=null):a.e<t.minE?(g.e=0,g.d=[0]):(g.e=a.e,g.d=a.d.slice()):(g.e=a.e,g.d=a.d?a.d.slice():a.d);return}if(m=typeof a,m==="number"){if(a===0){g.s=1/a<0?-1:1,g.e=0,g.d=[0];return}if(a<0?(a=-a,g.s=-1):g.s=1,a===~~a&&a<1e7){for(d=0,c=a;c>=10;c/=10)d++;Y?d>t.maxE?(g.e=NaN,g.d=null):d<t.minE?(g.e=0,g.d=[0]):(g.e=d,g.d=[a]):(g.e=d,g.d=[a]);return}if(a*0!==0){a||(g.s=NaN),g.e=NaN,g.d=null;return}return je(g,a.toString())}if(m==="string")return(c=a.charCodeAt(0))===45?(a=a.slice(1),g.s=-1):(c===43&&(a=a.slice(1)),g.s=1),vr.test(a)?je(g,a):ln(g,a);if(m==="bigint")return a<0?(a=-a,g.s=-1):g.s=1,je(g,a.toString());throw Error(_e+a)}if(t.prototype=B,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=yn,t.clone=Pr,t.isDecimal=pr,t.abs=cn,t.acos=fn,t.acosh=dn,t.add=hn,t.asin=pn,t.asinh=mn,t.atan=gn,t.atanh=_n,t.atan2=wn,t.cbrt=vn,t.ceil=Mn,t.clamp=bn,t.cos=kn,t.cosh=Sn,t.div=Pn,t.exp=An,t.floor=Cn,t.hypot=xn,t.ln=Dn,t.log=Tn,t.log10=Rn,t.log2=On,t.max=Ln,t.min=Nn,t.mod=En,t.mul=In,t.pow=Bn,t.random=qn,t.round=Fn,t.sign=Un,t.sin=jn,t.sinh=$n,t.sqrt=Wn,t.sub=Zn,t.sum=Kn,t.tan=zn,t.tanh=Gn,t.trunc=Hn,n===void 0&&(n={}),n&&n.defaults!==!0)for(o=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],i=0;i<o.length;)n.hasOwnProperty(r=o[i++])||(n[r]=this[r]);return t.config(n),t}function Pn(n,i){return new this(n).div(i)}function An(n){return new this(n).exp()}function Cn(n){return z(n=new this(n),n.e+1,3)}function xn(){var n,i,r=new this(0);for(Y=!1,n=0;n<arguments.length;)if(i=new this(arguments[n++]),i.d)r.d&&(r=r.plus(i.times(i)));else{if(i.s)return Y=!0,new this(1/0);r=i}return Y=!0,r.sqrt()}function pr(n){return n instanceof Oe||n&&n.toStringTag===wr||!1}function Dn(n){return new this(n).ln()}function Tn(n,i){return new this(n).log(i)}function On(n){return new this(n).log(2)}function Rn(n){return new this(n).log(10)}function Ln(){return yr(this,arguments,-1)}function Nn(){return yr(this,arguments,1)}function En(n,i){return new this(n).mod(i)}function In(n,i){return new this(n).mul(i)}function Bn(n,i){return new this(n).pow(i)}function qn(n){var i,r,o,t,a=0,d=new this(1),c=[];if(n===void 0?n=this.precision:Xt(n,1,we),o=Math.ceil(n/H),this.crypto)if(crypto.getRandomValues)for(i=crypto.getRandomValues(new Uint32Array(o));a<o;)t=i[a],t>=429e7?i[a]=crypto.getRandomValues(new Uint32Array(1))[0]:c[a++]=t%1e7;else if(crypto.randomBytes){for(i=crypto.randomBytes(o*=4);a<o;)t=i[a]+(i[a+1]<<8)+(i[a+2]<<16)+((i[a+3]&127)<<24),t>=214e7?crypto.randomBytes(4).copy(i,a):(c.push(t%1e7),a+=4);a=o/4}else throw Error(_r);else for(;a<o;)c[a++]=Math.random()*1e7|0;for(o=c[--a],n%=H,o&&n&&(t=$t(10,H-n),c[a]=(o/t|0)*t);c[a]===0;a--)c.pop();if(a<0)r=0,c=[0];else{for(r=-1;c[0]===0;r-=H)c.shift();for(o=1,t=c[0];t>=10;t/=10)o++;o<H&&(r-=H-o)}return d.e=r,d.d=c,d}function Fn(n){return z(n=new this(n),n.e+1,this.rounding)}function Un(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function jn(n){return new this(n).sin()}function $n(n){return new this(n).sinh()}function Wn(n){return new this(n).sqrt()}function Zn(n,i){return new this(n).sub(i)}function Kn(){var n=0,i=arguments,r=new this(i[n]);for(Y=!1;r.s&&++n<i.length;)r=r.plus(i[n]);return Y=!0,z(r,this.precision,this.rounding)}function zn(n){return new this(n).tan()}function Gn(n){return new this(n).tanh()}function Hn(n){return z(n=new this(n),n.e+1,1)}B[Symbol.for("nodejs.util.inspect.custom")]=B.toString;B[Symbol.toStringTag]="Decimal";var Oe=B.constructor=Pr(Ti);$e=new Oe($e);We=new Oe(We);var ht=Oe;import{compoundDebt as Xn}from"@suilend/sdk";var He=class{constructor(i){this.getPositionList=async(i=this._sdk.getSenderAddress(),r=!1)=>{let{lending_market_id:o,lending_market_type:t}=jt(this._sdk.sdkOptions.suilend);try{let a=`cap_to_position_mapping_${i}`,d=this._sdk.getCache(a,r),c=await this._sdk.FullClient.getOwnedObjectsByPage(i,{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{StructType:`${this._sdk.sdkOptions.margin_trading.package_id}::position::PositionCap`}]}});if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:42 ~ PositionModules ~ ownerRes.data.length:",c.data.length),c.data.length===0)return Gt("PositionNotFound","Position not found"),[];let m=await this._sdk.SuiLendModule.getSuilendClient(o,t);console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:48 ~ PositionModules ~ suiLendClient:",m);let{allLendingMarketData:g,lstAprPercentMap:M}=await this._sdk.SuiLendModule.getLendingMarketData();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:50 ~ PositionModules ~ allLendingMarketData:",g);let P=g[o].reserveMap;d||(d=new Map);let A=[];for(let N=0;N<c.data.length;N++){let R=Ar(c.data[N]);R.position_id&&A.push(R.position_id),R.id.id&&d.set(R.id.id,R.position_id)}await this._sdk.updateCache(a,d,Vn);let D=await this._sdk.FullClient.batchGetObjects(A,{showContent:!0});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:73 ~ PositionModules ~ positionRes:",D);let T=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:g,lstAprPercentMap:M},!0);console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:75 ~ PositionModules ~ obligations:",T);let L=[];for(let N=0;N<D.length;N++){let R=A[N],O="";for(let[Z,_]of d.entries())if(_===R){O=Z;break}let I=yi(D[N],O),U=await m.getObligation(I.obligation_owner_cap),W=ki(I,U,P||{},M||{},T[o].rewardMap),q=this.getObligationRewardsInfo(U,Object.values(P));L.push({...W,claimable_rewards:q})}return L}catch(a){return Gt("FetchError",a),[]}};this.getPositionInfo=async(i,r=this._sdk.getSenderAddress(),o=!0)=>{let t=`cap_to_position_mapping_${r}`,a=this._sdk.getCache(t,o);a||(a=new Map);let d=this.getCapIdByPositionId(i,r)||"";if(!d){let U=await this._sdk.FullClient.getOwnedObjectsByPage(r,{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{StructType:`${this._sdk.sdkOptions.margin_trading.package_id}::position::PositionCap`}]}});for(let W=0;W<U.data.length;W++){let q=Ar(U.data[W]);q.id.id&&a.set(q.id.id,q.position_id),q.position_id===i&&(d=q.id.id)}}let c=await this._sdk.FullClient.batchGetObjects([i],{showContent:!0}),m=yi(c[0],d||""),{lending_market_id:g,lending_market_type:M}=jt(this._sdk.sdkOptions.suilend),P=await this._sdk.SuiLendModule.getSuilendClient(g,M),{allLendingMarketData:A,lstAprPercentMap:D}=await this._sdk.SuiLendModule.getLendingMarketData(),T=A[g].reserveMap,L=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:A,lstAprPercentMap:D},!0),N=await P.getObligation(m.obligation_owner_cap),R=this.getObligationRewardsInfo(N,Object.values(T));return{...ki(m,N,T||{},D||{},L[g].rewardMap),claimable_rewards:R}};this.getCapIdByPositionId=(i,r=this._sdk.getSenderAddress())=>{let o=`cap_to_position_mapping_${r}`,t=this._sdk.getCache(o,!1);if(!t)return"";for(let[a,d]of t.entries())if(d===i)return a;return""};this.repay=i=>{let{margin_trading:r}=this._sdk.sdkOptions,{lending_market_id:o,lending_market_type:t}=jt(this._sdk.sdkOptions.suilend),{global_config_id:a,versioned_id:d}=jt(this._sdk.sdkOptions.margin_trading),{txb:c,repay_amount:m,repay_coin_type:g,repay_coin:M,repay_reserve_array_index:P,market_id:A,position_cap_id:D}=i,T=c||new ne,L=M||Q.buildCoinWithBalance(BigInt(m.toString()),g,T);T.moveCall({target:`${r.published_at}::router::repay`,typeArguments:[t,g],arguments:[T.object(a),T.object(o),T.object(A),T.object(D),L,T.pure.u64(P.toString()),T.object(be),T.object(d)]})};this.withdrawAsset=(i,r)=>{let{margin_trading:o}=this._sdk.sdkOptions,{lending_market_id:t,lending_market_type:a}=jt(this._sdk.sdkOptions.suilend),{global_config_id:d,versioned_id:c}=jt(this._sdk.sdkOptions.margin_trading),{package_id:m}=this._sdk.sdkOptions.suilend,{market_id:g,withdraw_amount:M,withdraw_reserve_array_index:P,withdraw_coin_type:A,position_cap_id:D}=i,[T]=r.moveCall({target:"0x1::option::none",typeArguments:[`${m}::lending_market::RateLimiterExemption<${a}, ${A}>`],arguments:[]});return r.moveCall({target:`${o.published_at}::router::withdraw`,typeArguments:[a,A],arguments:[r.object(d),r.object(t),r.object(g),r.object(D),r.object(T),r.pure.u64(M),r.pure.u64(P),r.object(Cr),r.object(be),r.object(c)]})};this.borrowAsset=(i,r)=>{let{reserve_array_index:o,borrow_amount:t,base_token:a,quote_token:d,lending_market_id:c,is_long:m,market_id:g,position_cap_id:M,position_cap:P}=i,{margin_trading:A}=this._sdk.sdkOptions,{lending_market_type:D}=jt(this._sdk.sdkOptions.suilend),{global_config_id:T,versioned_id:L}=jt(this._sdk.sdkOptions.margin_trading);return r.moveCall({target:`${A.published_at}::router::borrow`,typeArguments:[D,m?d:a],arguments:[r.object(T),r.object(c),r.object(g),M?r.object(M):P,r.pure.u64(o),r.pure.u64(t.toString()),r.object(Cr),r.object(be),r.object(L)]})};this.openPosition=async i=>{let{is_quote:r,is_long:o,amount:t,swap_clmm_pool:a="",slippage:d,leverage:c,market_id:m}=i,{lending_market_id:g}=jt(this._sdk.sdkOptions.suilend),M=new ne,{base_token:P,quote_token:A}=await this._sdk.MarketModules.getMarketInfo(m),{flash_amount:D,flash_loan_coin:T,is_flash_a:L,borrow_amount:N,clmm_pool_coin_type_a:R,clmm_pool_coin_type_b:O,clmm_pool:I,base_reserve_array_index:U,quote_reserve_array_index:W,reserve:q,has_swap:Z,routers:_}=await this.calculatePositionDeposit({is_long:o,is_quote:r,amount:t,swap_clmm_pool:a,leverage:c,slippage:d,market_id:m,base_token:P,quote_token:A,is_submit:!0});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:492 ~ PositionModules ~ routers:",_),await this._sdk.SuiLendModule.refreshReservePrices(M,q);let{balance_a:b,balance_b:S,receipt:C}=this._sdk.SwapModules.flashLoan({amount:D,clmm_pool:I,clmm_pool_coin_type_a:R,clmm_pool_coin_type_b:O,flash_loan_coin:T,tx:M}),x=o?A:P,p=o?P:A,e=Q.buildCoinWithBalance(BigInt(t),r?A:P,M),s=Q.fromBalance(b,R,M),l=Q.fromBalance(S,O,M);Z&&(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:515 ~ PositionModules ~ is_flash_a:",L),M.mergeCoins(e,[L?s:l])),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:521 ~ PositionModules ~ d(flash_amount).add(amount).toString():",E(D).add(t).toString(),x,p);let f=await this._sdk.SwapModules.handleSwap({from:x,to:p,amount:Z?E(D).add(t).toString():D,input_coin:Z?e:L?s:l,swap_clmm_pool:a,slippage:d,tx:M}),h=this.createLeveragePosition({leverage:c,market_id:m,base_token:P,quote_token:A,is_long:o,init_deposit_amount:E(t).toString(),init_coin_type:r?A:P,tx:M}),v=o?U:W;f.swap_out_coin&&!Z&&M.mergeCoins(f.swap_out_coin,[e]),await this.depositToLeveragePosition({is_long:o,market_id:m,position_cap:h,deposit_reserve_array_index:v,input_coin:f.swap_out_coin,base_token:P,quote_token:A},M),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:580 ~ PositionModules ~ borrow_amount:",N);let k=this.borrowAsset({position_cap:h,reserve_array_index:o?W:U,borrow_amount:N,base_token:P,quote_token:A,is_long:o,lending_market_id:g,market_id:m},M),w=Q.mintBalanceZero(L?O:R,M);return this._sdk.SwapModules.repayFlashLoan({tx:M,clmm_pool:I,repay_base:L?Q.intoBalance(k,R,M):w,repay_quote:L?w:Q.intoBalance(k,O,M),receipt:C,clmm_pool_coin_type_a:R,clmm_pool_coin_type_b:O}),M.transferObjects([h],M.pure.address(this._sdk.getSenderAddress())),Q.destroyBalanceZero(L?Q.intoBalance(l,O,M):Q.intoBalance(s,R,M),L?O:R,M),M};this.positionDeposit=async i=>{let{position_id:r,swap_clmm_pool:o="",is_quote:t,amount:a,slippage:d,leverage:c,txb:m}=i,{lending_market_id:g}=jt(this._sdk.sdkOptions.suilend),{is_long:M,deposits:P,borrows:A,position_cap_id:D,market_id:T}=await this.getPositionInfo(r),{base_token:L,quote_token:N}=await this._sdk.MarketModules.getMarketInfo(T),R=m||new ne,O=P[0].reserveArrayIndex.toString(),I=A[0].reserveArrayIndex.toString(),{flash_amount:U,flash_loan_coin:W,is_flash_a:q,borrow_amount:Z,clmm_pool_coin_type_a:_,clmm_pool_coin_type_b:b,clmm_pool:S,reserve:C,has_swap:x}=await this.calculatePositionDeposit({market_id:T,is_long:M,is_quote:t,amount:a,swap_clmm_pool:o,leverage:c,slippage:d,base_token:L,quote_token:N,position_id:r,is_open:!1});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:603 ~ PositionModules ~ flash_amount:",U),await this._sdk.SuiLendModule.refreshReservePrices(R,C);let{balance_a:p,balance_b:e,receipt:s}=this._sdk.SwapModules.flashLoan({amount:U,clmm_pool:S,clmm_pool_coin_type_a:_,clmm_pool_coin_type_b:b,flash_loan_coin:W,tx:R}),l=M?N:L,f=M?L:N,h=Q.buildCoinWithBalance(BigInt(a),t?N:L,R),v=Q.fromBalance(p,_,R),k=Q.fromBalance(e,b,R);x&&R.mergeCoins(h,[q?v:k]);let w=await this._sdk.SwapModules.handleSwap({from:l,to:f,amount:x?E(U).add(a).toString():U,input_coin:x?h:q?v:k,swap_clmm_pool:o,slippage:d,tx:R});w.swap_out_coin&&!x&&R.mergeCoins(w.swap_out_coin,[h]),await this.depositToLeveragePosition({is_long:M,market_id:T,position_cap_id:D,deposit_reserve_array_index:O,input_coin:w.swap_out_coin,base_token:L,quote_token:N},R);let u=await this.borrowAsset({position_cap_id:D,reserve_array_index:I,borrow_amount:Z,base_token:L,quote_token:N,is_long:M,lending_market_id:g,market_id:T},R),y=Q.mintBalanceZero(q?b:_,R);return this._sdk.SwapModules.repayFlashLoan({tx:R,clmm_pool:S,repay_base:q?Q.intoBalance(u,_,R):y,repay_quote:q?y:Q.intoBalance(u,b,R),receipt:s,clmm_pool_coin_type_a:_,clmm_pool_coin_type_b:b}),Q.destroyBalanceZero(q?Q.intoBalance(k,b,R):Q.intoBalance(v,_,R),q?b:_,R),R};this.positionWithdraw=async i=>{let{amount:r,is_quote:o,txb:t,swap_clmm_pool:a="",slippage:d,position_id:c,leverage:m}=i,g=t||new ne,{withdraw_ctoken_amount:M,repay_amount:P,is_close:A,deposits:D,borrows:T,reserve:L,base_token:N,quote_token:R,clmm_pool:O,clmm_pool_coin_type_a:I,clmm_pool_coin_type_b:U,position_cap_id:W,market_id:q,is_long:Z,swap_convert_all:_,flash_loan_amount:b,routers:S,repay_flash_loan_amount:C="0",partial_amount_in:x,withdraw_amount:p,has_flash_loan:e}=await this.calculatePositionWithdraw({position_id:c,is_quote:o,swap_clmm_pool:a,amount:r,leverage:m,slippage:d});if(A)return this.positionClose({position_id:c,is_quote:o,leverage:m,slippage:d,swap_clmm_pool:a});await this._sdk.SuiLendModule.refreshReservePrices(g,L);let s,l;if(e){let{balance_a:k,balance_b:w,receipt:u,is_loan_a:y}=this._sdk.SwapModules.flashLoan({tx:g,amount:b,flash_loan_coin:T[0].reserve.coinType,clmm_pool:O,clmm_pool_coin_type_a:I,clmm_pool_coin_type_b:U});s=u,l=y,Q.destroyBalanceZero(l?w:k,l?U:I,g);let $=y?Q.fromBalance(k,I,g):Q.fromBalance(w,U,g);this.repay({txb:g,position_cap_id:W,repay_reserve_array_index:T[0].reserveArrayIndex.toString(),repay_coin:$,repay_coin_type:Z?R:N,repay_amount:"0",market_id:q}),g.transferObjects([$],this._sdk.getSenderAddress())}let f=this.withdrawAsset({market_id:q,position_cap_id:W,withdraw_amount:M.toString(),withdraw_reserve_array_index:D[0].reserveArrayIndex.toString(),withdraw_coin_type:Z?N:R},g);for(let k=1;k<D.length;k++){let w=this.withdrawAsset({market_id:q,position_cap_id:W,withdraw_amount:Ni.toString(),withdraw_reserve_array_index:D[k].reserveArrayIndex.toString(),withdraw_coin_type:D[k].coinType},g);g.transferObjects([w],this._sdk.getSenderAddress())}let h;if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:778 ~ PositionModules ~ swap_convert_all:",{swap_convert_all:_,has_flash_loan:e}),_)h=await this._sdk.SwapModules.routerSwap({router:S?.route_obj,input_coin:f,slippage:d,txb:g});else{let k=g.splitCoins(f,[g.pure.u64(x?.toString()||"0")]);h=await this._sdk.SwapModules.routerSwap({router:S?.route_obj,input_coin:k,slippage:d,txb:g})}let v;if(h&&e&&(v=g.splitCoins(h,[g.pure.u64(C.toString())])),v&&e){let k=Q.mintBalanceZero(l?U:I,g);this._sdk.SwapModules.repayFlashLoan({tx:g,clmm_pool:O,repay_base:l?Q.intoBalance(v,I,g):k,repay_quote:l?k:Q.intoBalance(v,U,g),clmm_pool_coin_type_a:I,clmm_pool_coin_type_b:U,receipt:s})}else if(h){let k=g.splitCoins(h,[g.pure.u64(C.toString())]);this.repay({txb:g,position_cap_id:W,repay_reserve_array_index:T[0].reserveArrayIndex.toString(),repay_coin:k,repay_coin_type:Z?R:N,repay_amount:"0",market_id:q}),g.transferObjects([k],this._sdk.getSenderAddress())}return h&&g.transferObjects([h],this._sdk.getSenderAddress()),_||g.transferObjects([f],this._sdk.getSenderAddress()),g};this.positionClose=async i=>{let{position_id:r,is_quote:o,slippage:t,leverage:a,swap_clmm_pool:d=""}=i,{margin_trading:c}=this._sdk.sdkOptions,{global_config_id:m,versioned_id:g}=jt(this._sdk.sdkOptions.margin_trading),{lending_market_type:M,lending_market_id:P}=jt(this._sdk.sdkOptions.suilend),A=new ne,{deposits:D,borrows:T,base_token:L,quote_token:N,clmm_pool:R,clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:I,position_cap_id:U,market_id:W,swap_convert_all:q,routers:Z,partial_amount_in:_,is_long:b,flash_loan_amount:S,reserve:C,repay_flash_loan_amount:x="0",claimable_rewards:p}=await this.calculatePositionWithdraw({position_id:r,is_quote:o,swap_clmm_pool:d,amount:Ni.toString(),leverage:a,slippage:t});await this._sdk.SuiLendModule.refreshReservePrices(A,C);let e,s;if(E(S).gt(0)){let{balance_a:h,balance_b:v,receipt:k,is_loan_a:w}=this._sdk.SwapModules.flashLoan({tx:A,amount:S,flash_loan_coin:b?N:L,clmm_pool:R,clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:I});e=k,s=w,Q.destroyBalanceZero(s?v:h,s?I:O,A);let u=s?Q.fromBalance(h,O,A):Q.fromBalance(v,I,A);this.repay({txb:A,position_cap_id:U,repay_reserve_array_index:T[0].reserveArrayIndex.toString(),repay_coin:u,repay_coin_type:T[0].reserve.coinType,repay_amount:"0",market_id:W}),A.transferObjects([u],this._sdk.getSenderAddress())}let l=this.withdrawAsset({market_id:W,position_cap_id:U,withdraw_amount:Ni.toString(),withdraw_reserve_array_index:D[0].reserveArrayIndex.toString(),withdraw_coin_type:b?L:N},A);await this.buildClaimRewardsMoveCall(p,W,U,A);let f;if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:895 ~ PositionModules ~ swap_convert_all:",q),q)f=await this._sdk.SwapModules.routerSwap({router:Z?.route_obj,input_coin:l,slippage:t,txb:A});else if(_&&E(_).gt(0)){let h=A.splitCoins(l,[A.pure.u64(_?.toString()||"0")]);f=await this._sdk.SwapModules.routerSwap({router:Z?.route_obj,input_coin:h,slippage:t,txb:A})}if(f&&e){let h=Q.mintBalanceZero(s?I:O,A),v=A.splitCoins(f,[A.pure.u64(x?.toString()||"0")]);this._sdk.SwapModules.repayFlashLoan({tx:A,clmm_pool:R,repay_base:s?Q.intoBalance(v,O,A):h,repay_quote:s?h:Q.intoBalance(v,I,A),clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:I,receipt:e})}return A.moveCall({target:`${c.published_at}::router::close_position`,typeArguments:[M],arguments:[A.object(m),A.object(P),A.object(W),A.object(U),A.object(be),A.object(g)]}),f&&A.transferObjects([f],this._sdk.getSenderAddress()),q||A.transferObjects([l],this._sdk.getSenderAddress()),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:951 ~ PositionModules ~ tx:",A),A};this.positionLeverageIncrease=async i=>{let{current_leverage:r,target_leverage:o,swap_clmm_pool:t="",slippage:a,position_id:d}=i,{lending_market_id:c}=jt(this._sdk.sdkOptions.suilend),m=new ne,{flash_loan_amount:g,quote_token:M,base_token:P,reserve:A,deposits:D,borrow_amount:T,routers:L,position_cap_id:N,is_long:R,market_id:O,is_flash_loan:I}=await this.calculatePositionLeverage({position_id:d,current_leverage:r,target_leverage:o,swap_clmm_pool:t,slippage:a}),U=R?M:P;if(await this._sdk.SuiLendModule.refreshReservePrices(m,A),I){let{clmm_pool_coin_type_a:W,clmm_pool_coin_type_b:q,clmm_pool:Z}=await this._sdk.SwapModules.getFlashLoanPool(U,g?.toString()||""),{balance_a:_,balance_b:b,receipt:S,is_loan_a:C}=this._sdk.SwapModules.flashLoan({tx:m,amount:g?.toString()||"0",clmm_pool:Z,clmm_pool_coin_type_a:W,clmm_pool_coin_type_b:q,flash_loan_coin:U}),x=await this._sdk.SwapModules.routerSwap({router:L?.route_obj,input_coin:C?Q.fromBalance(_,W,m):Q.fromBalance(b,q,m),slippage:a,txb:m});this.depositToLeveragePosition({is_long:R,market_id:O,position_cap_id:N,deposit_reserve_array_index:D[0].reserveArrayIndex.toString(),input_coin:x,base_token:P,quote_token:M},m);let p=this.borrowAsset({position_cap_id:N,reserve_array_index:R?A[1].arrayIndex.toString():A[0].arrayIndex.toString(),borrow_amount:T,base_token:P,quote_token:M,is_long:R,lending_market_id:c,market_id:O},m),e=Q.mintBalanceZero(C?q:W,m);this._sdk.SwapModules.repayFlashLoan({tx:m,clmm_pool:Z,repay_base:C?Q.intoBalance(p,W,m):e,repay_quote:C?e:Q.intoBalance(p,q,m),receipt:S,clmm_pool_coin_type_a:W,clmm_pool_coin_type_b:q}),Q.destroyBalanceZero(C?b:_,C?q:W,m)}else{let W=this.borrowAsset({position_cap_id:N,reserve_array_index:R?A[1].arrayIndex.toString():A[0].arrayIndex.toString(),borrow_amount:T,base_token:P,quote_token:M,is_long:R,lending_market_id:c,market_id:O},m),q=await this._sdk.SwapModules.routerSwap({router:L?.route_obj,input_coin:W,slippage:a,txb:m});this.depositToLeveragePosition({is_long:R,market_id:O,position_cap_id:N,deposit_reserve_array_index:D[0].reserveArrayIndex.toString(),input_coin:q,base_token:P,quote_token:M},m)}return m};this.positionLeverageDecrease=async i=>{let{current_leverage:r,target_leverage:o,swap_clmm_pool:t="",slippage:a,position_id:d}=i,{deposits:c,borrows:m,position_cap_id:g,market_id:M,is_long:P}=await this.getPositionInfo(d),{base_token:A,quote_token:D}=await this._sdk.MarketModules.getMarketInfo(M),T=new ne,{withdraw_ctoken_amount:L,routers:N,reserve:R,is_flash_loan:O}=await this.calculatePositionLeverage({position_id:d,current_leverage:r,target_leverage:o,swap_clmm_pool:t,slippage:a});if(await this._sdk.SuiLendModule.refreshReservePrices(T,R),O){let{clmm_pool_coin_type_a:I,clmm_pool_coin_type_b:U,clmm_pool:W,clmm_fee_tier:q}=await this._sdk.SwapModules.getFlashLoanPool(c[0].reserve.coinType,L.toString()),{balance_a:Z,balance_b:_,receipt:b,is_loan_a:S}=this._sdk.SwapModules.flashLoan({tx:T,amount:L,clmm_pool:W,clmm_pool_coin_type_a:I,clmm_pool_coin_type_b:U,flash_loan_coin:c[0].reserve.coinType}),C=await this._sdk.SwapModules.routerSwap({router:N?.route_obj,input_coin:S?Q.fromBalance(Z,I,T):Q.fromBalance(_,U,T),slippage:a,txb:T});this.repay({txb:T,market_id:M,position_cap_id:g,repay_reserve_array_index:m[0].reserveArrayIndex.toString(),repay_coin:C,repay_coin_type:P?D:A,repay_amount:"0"}),C&&T.transferObjects([C],this._sdk.getSenderAddress());let x=E(L).mul(q).toString(),p=E(L).add(x).toDP(0,ht.ROUND_UP),e=this.withdrawAsset({market_id:M,position_cap_id:g,withdraw_amount:p.toString(),withdraw_reserve_array_index:c[0].reserveArrayIndex.toString(),withdraw_coin_type:P?A:D},T),s=T.splitCoins(e,[p.toString()]);this._sdk.SwapModules.repayFlashLoan({tx:T,clmm_pool:W,repay_base:S?Q.intoBalance(s,I,T):Z,repay_quote:S?_:Q.intoBalance(s,U,T),receipt:b,clmm_pool_coin_type_a:I,clmm_pool_coin_type_b:U}),T.transferObjects([e],this._sdk.getSenderAddress())}else{let I=this.withdrawAsset({market_id:M,position_cap_id:g,withdraw_amount:L.toString(),withdraw_reserve_array_index:c[0].reserveArrayIndex.toString(),withdraw_coin_type:P?A:D},T);T.transferObjects([I],this._sdk.getSenderAddress())}return T};this.positionRepay=async i=>{let{position_id:r,amount:o,is_quote:t,slippage:a}=i,{routers:d,repay_coin_type:c,base_token:m,quote_token:g,borrows:M,deposits:P,market_id:A,position_cap_id:D}=await this.calculatePositionRepay({position_id:r,amount:o,is_quote:t}),T=this.extractOtherTokenTypes(P,M,m,g),{reserve:L}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(m,g,void 0,T),N=new ne;await this._sdk.SuiLendModule.refreshReservePrices(N,L);let R=t?g!==c:m!==c,O;if(R){let I=Q.buildCoinWithBalance(BigInt(o.toString()),t?g:m,N);O=await this._sdk.SwapModules.routerSwap({router:d?.route_obj,input_coin:I,slippage:a,txb:N})}else O=Q.buildCoinWithBalance(BigInt(o.toString()),t?g:m,N);return this.repay({txb:N,position_cap_id:D,repay_reserve_array_index:M[0].reserveArrayIndex.toString(),repay_coin:O,repay_coin_type:c,repay_amount:"0",market_id:A}),N.transferObjects([O],this._sdk.getSenderAddress()),N};this.positionTopUpCToken=async i=>{let{position_id:r,amount:o,is_quote:t,swap_clmm_pool:a="",slippage:d}=i,c=new ne,{is_long:m,market_id:g,position_cap_id:M,deposits:P,borrows:A}=await this.getPositionInfo(r),{base_token:D,quote_token:T}=await this._sdk.MarketModules.getMarketInfo(g),L=m&&t||!m&&!t,N=this.extractOtherTokenTypes(P,A,D,T),{base_reserve_array_index:R,quote_reserve_array_index:O,reserve:I}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(D,T,void 0,N);await this._sdk.SuiLendModule.refreshReservePrices(c,I);let U;if(L){let W=await this._sdk.SwapModules.findRouters(t?T:D,t?D:T,o,!0,[a]),q=Q.buildCoinWithBalance(BigInt(o.toString()),t?T:D,c);U=await this._sdk.SwapModules.routerSwap({router:W?.route_obj,input_coin:q,slippage:d,txb:c})}else U=Q.buildCoinWithBalance(BigInt(o.toString()),t?T:D,c);return await this.depositToLeveragePosition({is_long:m,market_id:g,position_cap_id:M,deposit_reserve_array_index:m?R:O,input_coin:U,base_token:D,quote_token:T},c),c};this.positionWithdrawCToken=async i=>{let{position_id:r,amount:o,is_quote:t,swap_clmm_pool:a="",slippage:d}=i,c=new ne,{is_long:m,market_id:g,position_cap_id:M,deposits:P,borrows:A}=await this.getPositionInfo(r),{base_token:D,quote_token:T}=await this._sdk.MarketModules.getMarketInfo(g),L=m&&t||!m&&!t,N=this.extractOtherTokenTypes(P,A,D,T),{base_reserve_array_index:R,quote_reserve_array_index:O,reserve:I}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(D,T,void 0,N);await this._sdk.SuiLendModule.refreshReservePrices(c,I);let U=await this._sdk.SuiLendModule.getLatestPriceFeeds(I,!0),W=U[xe(T)]?.price,q=U[xe(D)]?.price,Z=m?E(W).div(E(q)).toString():E(q).div(E(W)).toString(),_=I[0].mintDecimals,b=I[1].mintDecimals,S=L?E(o).mul(Z).div(10**(t?b:_)).mul(10**(m?_:b)).toDP(0,ht.ROUND_DOWN).toString():o.toString(),C=this.withdrawAsset({market_id:g,position_cap_id:M,withdraw_amount:S,withdraw_reserve_array_index:m?R:O,withdraw_coin_type:m?D:T},c);if(L){let x=await this._sdk.SwapModules.findRouters(m?D:T,t?T:D,S,!0,[a]),p=await this._sdk.SwapModules.routerSwap({router:x?.route_obj,input_coin:C,slippage:d,txb:c});p&&c.transferObjects([p],this._sdk.getSenderAddress())}else c.transferObjects([C],this._sdk.getSenderAddress());return c};this.positionClaim=async i=>{let r=new ne,{position_cap_id:o,obligation_owner_cap:t,market_id:a,claimable_rewards:d}=await this.getPositionInfo(i);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1650 ~ PositionModules ~ claimable_rewards:",d),await this.buildClaimRewardsMoveCall(d,a,o,r),r};this.calculatePositionDeposit=async i=>{let{is_quote:r,is_long:o,amount:t,swap_clmm_pool:a="",leverage:d,by_amount_in:c=!0,base_token:m,quote_token:g,is_submit:M=!1,is_open:P=!0,position_id:A}=i,D=[],T=[],L=[];if(!P&&A){let{deposits:rt,borrows:V}=await this.getPositionInfo(A);T=rt,L=V,D=this.extractOtherTokenTypes(T,L,m,g)}let{reserve:N,base_reserve_array_index:R,quote_reserve_array_index:O}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(m,g,void 0,D),I=N[0].mintDecimals,U=N[1].mintDecimals,W=t.toString(),q=o&&r||!o&&!r,Z=await this._sdk.SuiLendModule.getLatestPriceFeedsByCoinTypes([m,g]),_=Z&&Z[g]?.price,b=Z&&Z[m]?.price;if(!_||!b)throw Gt("PriceNotFound","Price not found");if(q&&M){let rt=o?E(_).div(E(b)).toString():E(b).div(E(_)).toString();W=E(t).mul(rt).div(10**(r?U:I)).mul(10**(o?I:U)).toString(),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:492 ~ PositionModules ~ initDepositAmount:",{initDepositAmount:W,rate:rt})}else if(q&&!M){let rt=o?g:m,V=o?m:g;W=(await this._sdk.SwapModules.findRouters(rt,V,W,!0,[a]))?.amount_out.toString()}else W=t;let{base_price:S,quote_price:C,flash_amount:x,flash_loan_fee:p,flash_loan_coin:e,is_flash_a:s,clmm_pool:l,clmm_fee_tier:f,clmm_pool_coin_type_a:h,clmm_pool_coin_type_b:v}=await this._sdk.SwapModules.calculateFlashLoan({is_long:o,leverage:d,base_token:m,quote_token:g,deposit_amount:W,reserve:N,base_token_decimal:I,quote_token_decimal:U}),k=await this._sdk.SwapModules.findRouters(o?g:m,o?m:g,x.toString(),!0,[a]),w=E(W).add(E(k?.amount_out.toString())).toDP(0,ht.ROUND_DOWN).toString(),u=E(w).mul(o?S:C).toString(),y=E(x).add(p).toDP(0,ht.ROUND_UP).toString(),$=E(y).mul(o?C:S).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1575 ~ PositionModules ~ depositAmount:",{depositAmount:w,borrowAmount:y});let F=r?E(t).div(10**(r?U:I)).mul(10**I).mul(d).div(S).toDP(0,ht.ROUND_DOWN).toString():E(t).mul(d).toDP(0,ht.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1583 ~ PositionModules ~ leverageDepositAmount:",F);let j="0",K="0",G="0",J="0";return!P&&A&&(L&&L.length>0&&(j=E(L[0].borrowedAmount.toString()).mul(o?10**U:10**I).add(E(y)).toString(),K=E(j).mul(o?_:b).toString()),G=E(T[0].depositedAmount.toString()).mul(o?10**I:10**U).add(E(w)).toString(),J=E(G).mul(o?b:_).toString()),{routers:k,leverage_deposit_amount:F,quote_price:C,base_price:S,clmm_fee_tier:f,flash_loan_fee:p,flash_loan_coin:e,deposit_amount:w,borrow_amount:y,deposit_amount_usd:u,borrow_amount_usd:$,after_borrow_amount:j,after_borrow_amount_usd:K,after_deposit_amount:G,after_deposit_amount_usd:J,flash_amount:x,is_flash_a:s,init_deposit_amount:W,clmm_pool_coin_type_a:h,clmm_pool_coin_type_b:v,clmm_pool:l,base_reserve_array_index:R,quote_reserve_array_index:O,reserve:N,has_swap:q}};this.calculatePositionWithdraw=async i=>{let{position_id:r,is_quote:o,swap_clmm_pool:t="",amount:a,leverage:d,slippage:c,withdraw_max:m}=i,{deposits:g,borrows:M,origin_obligation:P,position_cap_id:A,market_id:D,is_long:T,claimable_rewards:L}=await this.getPositionInfo(r),{base_token:N,quote_token:R}=await this._sdk.MarketModules.getMarketInfo(D),O=r?this.extractOtherTokenTypes(g,M,N,R):[],{reserve:I,base_reserve_map_info:U,quote_reserve_map_info:W}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(N,R,void 0,O),q=I[0].mintDecimals,Z=I[1].mintDecimals,_=T?U.cTokenExchangeRate:W.cTokenExchangeRate,b=await this._sdk.SuiLendModule.getLatestPriceFeeds(I,!0),S=b[xe(R)]?.price,C=b[xe(N)]?.price,x=E(0),p;T?(x=E(o?E(a).mul(S).toString():E(a).mul(C).toString()).div(o?10**Z:10**q),p=o?E(a).div(C).div(10**Z).mul(10**q).toString():E(a)):(x=E(o?E(a).mul(S).toString():E(a).mul(C).toString()).div(o?10**Z:10**q),p=o?E(a):E(a).mul(C).div(10**q).mul(10**Z).toString());let e=E(g[0].depositedAmountUsd.toString()).sub(E(M&&M.length>0?M[0].borrowedAmountUsd.toString():"0")).toString(),s=x.div(E(e)),l=m||E(s).gte(1),f,h=new ht(0);P&&P.borrows&&P.borrows.length>0&&(f=Xn(P.borrows[0],T?I[1]:I[0]),h=E(f.borrowedAmount.value.toString()).div(10**18).toDP(0,ht.ROUND_UP));let v=h.mul(l?1:s).toDP(0,ht.ROUND_UP).toString(),k=v.toString(),w,u,y,$,F,j;if(E(v).gt(0)){let{clmm_pool_coin_type_a:nt,clmm_pool_coin_type_b:at,clmm_fee_tier:ue,clmm_pool:dt}=await this._sdk.SwapModules.getFlashLoanPool(T?R:N,k);F=nt||"",j=at||"",y=ue||0,$=dt||"",w=E(k).mul(ue).toString(),u=E(k).mul(E(1).add(ue)).toDP(0,ht.ROUND_UP).toString()}let K=T&&o||!T&&!o,G,J;if(K){let nt=E(g[0].depositedAmount.toString()).mul(10**(T?q:Z)).mul(l?1:s).toDP(0,ht.ROUND_DOWN).toString();G=await this._sdk.SwapModules.findRouters(g[0].reserve.coinType,T?R:N,nt,!0,[t])}else{let nt=g[0].reserve.coinType==="0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC"?.01:.0025;J=E(v).mul(T?S:C).div(10**(T?Z:q)).mul(10**(T?q:Z)).div(T?C:S).mul(E(1).add(nt)).toDP(0,ht.ROUND_DOWN).toString(),G=await this._sdk.SwapModules.findRouters(g[0].reserve.coinType,T?R:N,J.toString(),!0,[t]),l||(v=E(G?.amount_out.toString()).mul(E(1).sub(c)).toDP(0,ht.ROUND_DOWN).toString())}p=E(p).mul(d).toDP(0,ht.ROUND_DOWN).toString(),x=E(x).mul(d);let rt=h.mul(E(1).sub(s)).toString(),V=E(rt).mul(T?S:C).toString(),it=E(g[0].depositedAmount.toString()).mul(T?10**q:10**Z).sub(E(p)).toString(),ut=E(it).mul(T?C:S).toString(),et=E(G?.amount_in.toString()).toString(),X=E(G?.amount_out.toString()).toString(),de=E(p).div(_.toString()).toDP(0,ht.ROUND_DOWN).toString(),ct=E(V).div(E(10**(T?Z:q))),st=E(ut).div(E(10**(T?q:Z))),ke=!0;if(M.length>0){let nt=E(M[0].borrowedAmountUsd.toString()),at=nt.div(st).toString(),ue=E(g[0].reserve.config.openLtvPct).mul(E(.95)).div(100).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1459 ~ PositionModules ~ afterLTV:",{afterLTV:at,ltv:ue,afterDepositAmount:it,afterDepositAmountUSD:st,afterBorrowAmount:rt,afterBorrowAmountUSD:ct,withdrawAmount:p,currentBorrowAmountUSD:nt}),E(at).lte(ue)&&(ke=!1)}return{amount_in:et,amount_out:X,from:g[0].reserve.coinType,to:T?N:R,after_borrow_amount:rt,after_borrow_amount_usd:V,after_deposit_amount:it,after_deposit_amount_usd:ut,flash_loan_fee:w,clmm_fee_tier:y,withdraw_amount:p,withdraw_ctoken_amount:de,repay_amount:v,ratio:s,is_close:l,is_long:T,deposits:g,borrows:M,reserve:I,base_token:N,quote_token:R,clmm_pool:$,clmm_pool_coin_type_a:F,clmm_pool_coin_type_b:j,position_cap_id:A,market_id:D,swap_convert_all:K,flash_loan_amount:k,routers:G,repay_flash_loan_amount:u,partial_amount_in:J,has_flash_loan:ke,claimable_rewards:L}};this.calculatePositionLeverage=async i=>{let{position_id:r,current_leverage:o,target_leverage:t,swap_clmm_pool:a=""}=i,d=E(t).sub(E(o)),c=d.gt(0),{borrows:m,deposits:g,is_long:M,position_cap_id:P,market_id:A}=await this.getPositionInfo(r),{base_token:D,quote_token:T}=await this._sdk.MarketModules.getMarketInfo(A),L=this.extractOtherTokenTypes(g,m,D,T),{reserve:N}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(D,T,void 0,L),R=N[0].mintDecimals,O=N[1].mintDecimals,I=await this._sdk.SuiLendModule.getLatestPriceFeeds(N,!0),U=I[xe(T)]?.price,W=I[xe(D)]?.price,q=m.length>0,Z=g[0].depositedAmountUsd.toString(),_=g[0].depositedAmount.toString(),b=q?E(m[0].borrowedAmount.toString()).mul(10**(M?O:R)):E(0),S=q?m[0].borrowedAmountUsd.toString():E(0),C=q?E(m[0].reserve.config.borrowWeightBps.toString()).div(1e4).toString():"1",x=E(g[0].reserve.config.openLtvPct).mul(E(.95)).div(100).div(C).toString(),p=E(Z).sub(E(S)).mul(x).toString();if(c){let e=E(Z).div(o).mul(d),s=e.add(S).div(Z).toString(),l=e.div(M?U:W).mul(10**(M?O:R)).toDP(0,ht.ROUND_UP),f=E(s).gt(x),h=l,v=M?T:D,k=M?D:T,w=await this._sdk.SwapModules.findRouters(v,k,h.toString(),!0,[a]),u=E(w?.amount_out.toString()).toString(),y=E(u).mul(M?W:U).toString(),$,F,j,K,G,J="0",rt="0";if(f){let{clmm_pool_coin_type_a:X,clmm_pool_coin_type_b:de,clmm_pool:ct,clmm_fee_tier:st}=await this._sdk.SwapModules.getFlashLoanPool(v,h.toString());j=st,K=X,G=de,$=h.mul(j).toString(),F=M?K==T:G==D,J=E(h).add($).toDP(0,ht.ROUND_UP).toString(),rt=E(J).mul(M?U:W).toString()}else J=l.toString(),rt=e.toString();let V=E(_).add(E(u).div(10**(M?R:O))).toString(),it=E(V).mul(M?W:U).toString(),ut=E(b).add(E(J)).div(10**(M?O:R)).toString(),et=E(ut).mul(M?U:W).toString();return{amount_in:w?.amount_in.toString(),amount_out:w?.amount_out.toString(),flash_loan_fee:$,deposit_amount:u,borrow_amount:J,deposit_amount_usd:y,borrow_amount_usd:rt,flash_loan_amount:h,base_token:D,quote_token:T,reserve:N,deposits:g,borrows:m,clmm_fee_tier:j,is_flash_loan:f,is_loan_a:F,clmm_pool_coin_type_a:K,clmm_pool_coin_type_b:G,after_deposit_amount:V,after_borrow_amount:ut,after_deposit_amount_usd:it,after_borrow_amount_usd:et,position_cap_id:P,market_id:A,is_long:M,routers:w}}else{let s=E(Z).div(o).mul(d.abs()).div(M?U:W).mul(10**(M?O:R)).toDP(0,ht.ROUND_UP),l=await this._sdk.SwapModules.findRouters(g[0].reserve.coinType,m[0].reserve.coinType,s.toString(),!1,[a]),f=l?.amount_in.toString(),h=E(f).mul(M?W:U).div(10**(M?R:O)).toString(),v=E(Z).mul(x).toString(),k=E(S).div(E(Z).sub(E(h))).toString(),w=E(k).gt(x),u=s.toString(),y=E(u).mul(M?U:W).toString(),$=f,F=E($).mul(M?W:U).toString(),j,K="",G="";if(w){let{clmm_pool_coin_type_a:ut,clmm_pool_coin_type_b:et,clmm_pool:X,clmm_fee_tier:de}=await this._sdk.SwapModules.getFlashLoanPool(m[0].reserve.coinType,u.toString());j=de,K=ut,G=et}let J=E(_).sub(E($).div(10**(M?R:O))).toString(),rt=E(J).mul(M?W:U).toString(),V=E(b).sub(E(u)).div(10**(M?O:R)).toString(),it=E(V).mul(M?U:W).toString();return{amount_in:l?.amount_in.toString(),amount_out:l?.amount_out.toString(),deposit_amount:$,borrow_amount:u,deposit_amount_usd:F,borrow_amount_usd:y,base_token:D,quote_token:T,reserve:N,deposits:g,borrows:m,clmm_fee_tier:j,withdraw_ctoken_amount:f,is_flash_loan:w,clmm_pool_coin_type_a:K,clmm_pool_coin_type_b:G,after_deposit_amount:J,after_borrow_amount:V,after_deposit_amount_usd:rt,after_borrow_amount_usd:it,position_cap_id:P,market_id:A,is_long:M,routers:l}}};this.calculatePositionRepay=async i=>{let{position_id:r,amount:o,is_quote:t}=i,{borrows:a,deposits:d,is_long:c,market_id:m,position_cap_id:g}=await this._sdk.PositionModules.getPositionInfo(r),M=a[0].reserve.coinType,P=c?d[0].reserve.coinType:a[0].reserve.coinType,A=c?a[0].reserve.coinType:d[0].reserve.coinType,D,T=c?!t:t;return T&&(D=await this._sdk.SwapModules.findRouters(t?A:P,M,o,!0,[])),{routers:D,repay_coin_type:M,base_token:P,quote_token:A,is_long:c,borrows:a,deposits:d,market_id:m,position_cap_id:g,has_swap:T}};this._sdk=i}getObligationRewardsInfo(i,r){let o=[],t=new lt(10).pow(18),a={},d=Date.now();for(let m of r){let g=m.coinType,M=m.arrayIndex.toString(),P=m.depositsPoolRewardManager.poolRewards||[];for(let D of P){if(!D)continue;let T=D.id,L=D.coinType,N=parseInt(D.startTimeMs),R=parseInt(D.endTimeMs),O=d>=N&&d<R,I=D.mintDecimals,U=lt(D.cumulativeRewardsPerShare).times(10**I);a[T]={coinType:L,mintDecimals:I,isActive:O,reserveType:"deposit",reserveArrayIndex:M,reserveCoinType:g,globalCumulativePerShare:U,rewardIndex:D.rewardIndex,reserve:m}}let A=m.borrowsPoolRewardManager.poolRewards||[];for(let D of A){if(!D)continue;let T=D.id,L=D.coinType,N=parseInt(D.startTimeMs),R=parseInt(D.endTimeMs),O=d>=N&&d<R,I=D.mintDecimals,U=lt(D.cumulativeRewardsPerShare).times(10**I);a[T]={coinType:L,mintDecimals:I,isActive:O,reserveType:"borrow",reserveCoinType:g,reserveArrayIndex:M,rewardIndex:D.rewardIndex,globalCumulativePerShare:U,reserve:m}}}let c=i.userRewardManagers;for(let m of c)for(let g=0;g<m.rewards.length;g++){let M=m.rewards[g];if(!M)continue;let P=a[M.poolRewardId];if(!P)continue;let A=P.globalCumulativePerShare,D=new lt(M.cumulativeRewardsPerShare.value.toString()).div(t),T=new lt(m.share).times(A.minus(D)),L=new lt(M.earnedRewards.value).div(t),N=new lt(L).plus(T),R=P.reserve.price,O=N.div(10**P.mintDecimals),I=R?O.times(R).toFixed(12):0;E(I).gt(0)&&o.push({poolRewardId:M.poolRewardId,coinType:P.coinType,earnedRewards:N.toString(),earnedRewardsUsd:I,earnedRewardsFormatted:O.toFixed(12),isActive:P.isActive,reserveType:P.reserveType,reserveCoinType:P.reserveCoinType,reserveArrayIndex:P.reserveArrayIndex,rewardIndex:P.rewardIndex,rewardInfo:P})}return o}createLeveragePosition(i){let{lending_market_id:r,lending_market_type:o}=jt(this._sdk.sdkOptions.suilend),{global_config_id:t,versioned_id:a}=jt(this._sdk.sdkOptions.margin_trading),d=this._sdk.sdkOptions.margin_trading,{leverage:c,market_id:m,base_token:g,quote_token:M,is_long:P,init_deposit_amount:A,tx:D,init_coin_type:T}=i;return D.moveCall({target:`${d.published_at}::router::open_position`,arguments:[D.object(t),D.object(m),D.object(r),D.pure.u64(A),D.pure.u64(E(c).mul(1e4).toString()),D.object(be),D.object(a)],typeArguments:[o,P?g:M,T]})}async depositToLeveragePosition(i,r){let{margin_trading:o}=this._sdk.sdkOptions,{lending_market_type:t,lending_market_id:a}=jt(this._sdk.sdkOptions.suilend),{is_long:d,market_id:c,position_cap_id:m,position_cap:g,deposit_reserve_array_index:M,input_coin:P,base_token:A,quote_token:D}=i,{global_config_id:T,versioned_id:L}=jt(this._sdk.sdkOptions.margin_trading);return r.moveCall({target:`${o.published_at}::router::deposit`,typeArguments:[t,d?A:D],arguments:[r.object(T),r.object(a),r.object(c),m?r.object(m):g,P,r.pure.u64(M),r.object(be),r.object(L)]}),r}extractOtherTokenTypes(i,r,o,t){let a=[];return i.forEach(d=>{d.reserve.coinType!==o&&d.reserve.coinType!==t&&a.push(d.reserve.coinType)}),r.forEach(d=>{d.reserve.coinType!==o&&d.reserve.coinType!==t&&a.push(d.reserve.coinType)}),a}async buildClaimRewardsMoveCall(i,r,o,t){let{suilend:a,margin_trading:d}=this._sdk.sdkOptions,c=jt(a).lending_market_id,m=jt(a).lending_market_type,{global_config_id:g,versioned_id:M}=jt(this._sdk.sdkOptions.margin_trading);for(let P=0;P<i.length;P++){let A=t.moveCall({target:`${d.published_at}::router::claim_rewards`,arguments:[t.object(g),t.object(c),t.object(r),t.object(o),t.pure.u64(i[P].reserveArrayIndex.toString()),t.pure.u64(i[P].rewardIndex.toString()),t.pure.bool(i[P].reserveType==="deposit"),t.object(be),t.object(M)],typeArguments:[m,i[P].coinType]});t.transferObjects([A],this._sdk.getSenderAddress())}}};import{SuilendClient as so}from"@suilend/sdk/client";import{initializeSuilend as ao,initializeSuilendRewards as lo,initializeObligations as uo,formatRewards as co,Side as ve,getFilteredRewards as fo,getStakingYieldAprPercent as ho,getDedupedPerDayRewards as po,getDedupedAprRewards as mo,getTotalAprPercent as Rr,getNetAprPercent as go}from"@suilend/sdk";import{linearlyInterpolate as to,Side as ye}from"@suilend/sdk";import{NORMALIZED_flSUI_COINTYPE as eo,NORMALIZED_jugSUI_COINTYPE as io,NORMALIZED_LBTC_COINTYPE as ro,formatLtvPercent as no}from"@suilend/sui-fe";import Jn from"crypto";var Xe=new Uint8Array(256),Ve=Xe.length;function Ei(){return Ve>Xe.length-16&&(Jn.randomFillSync(Xe),Ve=0),Xe.slice(Ve,Ve+=16)}var Kt=[];for(let n=0;n<256;++n)Kt.push((n+256).toString(16).slice(1));function xr(n,i=0){return Kt[n[i+0]]+Kt[n[i+1]]+Kt[n[i+2]]+Kt[n[i+3]]+"-"+Kt[n[i+4]]+Kt[n[i+5]]+"-"+Kt[n[i+6]]+Kt[n[i+7]]+"-"+Kt[n[i+8]]+Kt[n[i+9]]+"-"+Kt[n[i+10]]+Kt[n[i+11]]+Kt[n[i+12]]+Kt[n[i+13]]+Kt[n[i+14]]+Kt[n[i+15]]}import Yn from"crypto";var Ii={randomUUID:Yn.randomUUID};function Qn(n,i,r){if(Ii.randomUUID&&!i&&!n)return Ii.randomUUID();n=n||{};let o=n.random||(n.rng||Ei)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,i){r=r||0;for(let t=0;t<16;++t)i[r+t]=o[t];return i}return xr(o)}var Je=Qn;import{getPackagerConfigs as oo}from"@cetusprotocol/common-sdk";var Bi=10n;function Dr(n){return n.depositedAmount.eq(0)?new lt(0):n.borrowedAmount.div(n.depositedAmount).times(100)}function qi(n){let i=Dr(n);if(!i.gt(100))return to(n.config.interestRate,"utilPercent","aprPercent",i)}function Tr(n){let i=Dr(n),r=qi(n);if(!(r===void 0||i.gt(100)))return new lt(i.div(100)).times(r.div(100)).times(1-n.config.spreadFeeBps/1e4).times(100)}function ys(n,i,r,o){let{api_url:t}=oo(o.sdkOptions.suilend);n===ye.DEPOSIT&&([eo,io].includes(i.coinType)&&r.push({stats:{id:Je(),isActive:!0,rewardIndex:-1,reserve:i,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${t}/partners/LiqAg.png`,perDay:new lt(.036),side:ye.DEPOSIT},obligationClaims:{}}),i.coinType===ro&&r.push({stats:{id:Je(),isActive:!0,rewardIndex:-1,reserve:i,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${t}/partners/Lombard Lux.png`,perDay:new lt(0),side:ye.DEPOSIT},obligationClaims:{}}))}function ks(n,i,r){return{...n,depositedAmount:i===ye.DEPOSIT?lt.max(n.depositedAmount.plus(r),0):n.depositedAmount,borrowedAmount:i===ye.BORROW?lt.max(n.borrowedAmount.plus(r),0):n.borrowedAmount}}function Ss(n,i,r){let o=n===ye.DEPOSIT?i.depositedAmount:i.borrowedAmount,t=n===ye.DEPOSIT?r.depositedAmount:r.borrowedAmount,a=t.eq(0)?new lt(-1):o.div(t);return{multiplier:a,isValid:!a.eq(-1)}}function Ps(n,i,r,o){let t=n.map(d=>({...d,stats:{...d.stats,perDay:o?d.stats.perDay.times(r):void 0}})),a=i.map(d=>({...d,stats:{...d.stats,aprPercent:o?d.stats.aprPercent.times(r):void 0}}));return{newPerDayRewards:t,newAprRewards:a}}function Or(n,i){if(!Bi)throw new Error("oraclePriceMultiplierDecimal is required");if(n===0n)throw new Error("Invalid oracle price");if(i<0n){let r=10n**(Bi- -i);return n*r}return n/10n**(i+Bi)}function As(n){return no(new lt(n))}import{d as Fi,getPackagerConfigs as De,removeHexPrefix as Ye}from"@cetusprotocol/common-sdk";import{toHEX as Lr}from"@mysten/sui/utils";var Qe=class{constructor(i){this.getCoinAprByAmount=async(i,r,o)=>{let t=new lt(r.toString()),{allLendingMarketData:a,lstAprPercentMap:d}=await this.getLendingMarketData(!1);if(await this.getInitializeObligations({allLendingMarketData:a,lstAprPercentMap:d},!0),!a||!d)throw new Error("lendingMarketCache is not initialized");let c=Object.values(a??{})[0],m=c.lendingMarket.reserves.find(_=>_.coinType===i);if(!m)throw new Error("reserve not found");let M=(this.obligationsCache?.[c.lendingMarket.id]).rewardMap[m.token.coinType]?.[o]??[],P=fo(M),A=ho(o,m.coinType,d),D=o===ve.DEPOSIT?m.depositAprPercent:m.borrowAprPercent,T=D,L=new lt(1),N=!0;if(o!==void 0&&t!==void 0&&t.gt(0)){let _={...m,depositedAmount:o===ve.DEPOSIT?lt.max(m.depositedAmount.plus(o===ve.DEPOSIT?t:t.negated()),0):m.depositedAmount,borrowedAmount:o===ve.BORROW?lt.max(m.borrowedAmount.plus(o===ve.BORROW?t:t.negated()),0):m.borrowedAmount};T=o===ve.DEPOSIT?Tr(_):qi(_);let b=o===ve.DEPOSIT?m.depositedAmount:m.borrowedAmount,S=o===ve.DEPOSIT?_.depositedAmount:_.borrowedAmount;L=S.eq(0)?new lt(-1):b.div(S),N=!L.eq(-1)}let I=po(P).map(_=>({..._,stats:{..._.stats,perDay:N?_.stats.perDay.times(L):void 0}})),W=mo(P).map(_=>({..._,stats:{..._.stats,aprPercent:N?_.stats.aprPercent.times(L):void 0}})),q=Rr(o,D,P,A),Z=T===void 0||W.some(_=>_.stats.aprPercent===void 0)?void 0:Rr(o,T,W,A);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:315 ~ SuiLendModule ~ newTotalAprPercent:",Z?.toString()),{new_total_apr_percent:Z?.toString(),total_apr_percent:q.toString()}};this.refreshReservePrice=async(i,r,o)=>{let{lending_market_id:t,lending_market_type:a}=De(this.sdk.sdkOptions?.suilend),d=`${t}_${a}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let c=await this.suilendClientCache[d].pythClient.getPriceFeedObjectId(r);this.suilendClientCache[d].refreshReservePrices(i,c,o)};this.getLatestPriceFeeds=async(i,r=!1)=>{let{lending_market_id:o,lending_market_type:t}=De(this.sdk.sdkOptions?.suilend),a={},d=[];if(i.forEach(M=>{let P=this.sdk.getCache(`getLatestPrice_${M.coinType.name}`,r);P&&this.priceCheck(P,60)?a[M.coinType.name]=P:d.push(M.coinType.name)}),d.length==0)return a;let c=`${o}_${t}`;if(!this.suilendClientCache)throw new Error("suilendClient is not initialized");let m=Array.from(new Set(i.map(M=>M?.priceIdentifier?.bytes?Lr(new Uint8Array(M.priceIdentifier.bytes)):Ye(M.priceIdentifier.toString()))));return(await this.suilendClientCache[c].pythConnection.getLatestPriceFeeds(m))?.forEach((M,P)=>{let A=M.getPriceUnchecked(),D=i[P];if(A){let{price:T,expo:L}=A,N=Fi(T).mul(Fi(10).pow(Fi(L))).toString(),R={coin_type:D.coinType.name||D.coinType,price:N,oracle_price:0n,last_update_time:A.publishTime};R.oracle_price=Or(BigInt(T),BigInt(L)),a[D.coinType.name||D.coinType]=R,this.sdk.updateCache(`getLatestPrice_${R.coin_type}`,R)}}),a};this.getLatestPriceFeedsByCoinTypes=async(i,r=!1)=>{try{let{lending_market_id:o}=De(this.sdk.sdkOptions?.suilend),{allLendingMarketData:t}=await this.getLendingMarketData(!1),a=[];return i.forEach(c=>{let m=t[o].reserveMap[c];a.push(m)}),await this.getLatestPriceFeeds(a,r)}catch(o){Gt("FetchError",o);return}};this.getSuiLendReserveInfo=async(i,r,o,t)=>{let{lending_market_id:a}=De(this.sdk.sdkOptions?.suilend);o||(o=(await this.getLendingMarketData(!1)).allLendingMarketData);let d=o[a].reserveMap[i],c=o[a].reserveMap[r],m=o[a].refreshedRawReserves.filter(D=>D.coinType.name==Ye(i)),g=o[a].refreshedRawReserves.filter(D=>D.coinType.name==Ye(r)),M=o[a].reserveMap[i],P=o[a].reserveMap[r],A=[];return t&&t.forEach(D=>{let T=o[a].refreshedRawReserves.filter(L=>L.coinType.name==Ye(D));A.push(...T)}),{base_reserve_array_index:d.arrayIndex.toString(),quote_reserve_array_index:c.arrayIndex.toString(),reserve:[m[0],g[0],...A],base_reserve_map_info:M,quote_reserve_map_info:P}};this.refreshReservePrices=async(i,r)=>{for(let o=0;o<r.length;o++){let t=Lr(new Uint8Array(r[o].priceIdentifier.bytes));await this.refreshReservePrice(i,t,BigInt(r[o].arrayIndex))}};this.refreshReservePricesV2=async(i,r)=>{for(let o=0;o<r.length;o++){let t=r[o].priceIdentifier.toString();await this.refreshReservePrice(i,t,BigInt(r[o].arrayIndex))}};this.sdk=i}async getSuilendClient(i,r){let o=`${i}_${r}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[o]||(this.suilendClientCache[o]=await so.initialize(i,r,this.sdk.FullClient,!0)),this.suilendClientCache[o]}async getLendingMarketData(i=!0){let r="lendingMarketData",o=this.sdk.getCache(r,i);if(o)return o;let t=De(this.sdk.sdkOptions?.suilend)?.lending_market||[];if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:67 ~ SuiLendModule ~ getLendingMarketData ~ lendingMarkets:",t),!t.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[a,d]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(t.map(async m=>{let g=await this.getSuilendClient(m.id,m.type),{lendingMarket:M,coinMetadataMap:P,refreshedRawReserves:A,reserveMap:D,reserveCoinTypes:T,reserveCoinMetadataMap:L,rewardCoinTypes:N,activeRewardCoinTypes:R,rewardCoinMetadataMap:O}=await ao(this.sdk.FullClient,g),{rewardPriceMap:I}=await lo(D,R);return[m.id,{suilendClient:g,lendingMarket:M,coinMetadataMap:P,refreshedRawReserves:A,reserveMap:D,reserveCoinTypes:T,reserveCoinMetadataMap:L,rewardPriceMap:I,rewardCoinTypes:N,activeRewardCoinTypes:R,rewardCoinMetadataMap:O}]}))))(),(async()=>{try{let c=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.api_url}/springsui/apy`),m=await c.json();if(c?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(m).map(([g,M])=>[g,new lt(M)]))}catch(c){return console.error(c),{}}})()]);return this.sdk.updateCache(r,{allLendingMarketData:a,lstAprPercentMap:d},30*1e3),{allLendingMarketData:a,lstAprPercentMap:d}}catch(a){throw console.log("\u{1F680} getLendingMarketData error:",a),a}}async getInitializeObligations(i,r=!1){if(!r&&this.obligationsCache)return this.obligationsCache;i||(i=await this.getLendingMarketData(!1));let o={};for(let t of Object.values(i.allLendingMarketData)){let{obligationOwnerCaps:a,obligations:d}=await uo(this.sdk.FullClient,t.suilendClient,t.refreshedRawReserves,t.reserveMap,this.sdk.senderAddress);d.length>0&&console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:181 ~ SuiLendModule ~ getInitializeObligations ~ obligations:",d[0].original.allowedBorrowValueUsd.value.toString());let c=co(t.reserveMap,t.rewardCoinMetadataMap,t.rewardPriceMap,d);o[t.lendingMarket.id]={obligationOwnerCaps:a,obligations:d,rewardMap:c}}return this.obligationsCache=o,this.obligationsCache}async getSuiLendUserData(i,r=!1){let{allLendingMarketData:o,lstAprPercentMap:t}=await this.getLendingMarketData(!1),a=await this.getInitializeObligations({allLendingMarketData:o,lstAprPercentMap:t},!1),{lending_market_id:d}=De(this.sdk.sdkOptions?.suilend),c=a[d];if(!c)throw new Error(`No user data found for lending market: ${d}`);let m=c.obligations.find(M=>M.id===i);if(!m)throw new Error(`Obligation not found: ${i}`);let g=go(m,c.rewardMap,t??{});return{obligation:m,netAprPercent:g,deposits:m.deposits,borrowedAmount:m.borrowedAmount,depositedAmount:m.depositedAmount,netValueUsd:m.netValueUsd,rewardMap:c.rewardMap}}priceCheck(i,r=60){let o=Math.floor(Date.now()/1e3);if(!(Math.abs(o-i.last_update_time)>r))return i}};var $i=Gr(Er());import{Transaction as _o}from"@mysten/sui/transactions";import{addHexPrefix as wo,CoinAssist as ji,d as ee,getPackagerConfigs as Ir,removeHexPrefix as Br}from"@cetusprotocol/common-sdk";var ti=class{constructor(i){this.routerSwap=async i=>{let{slippage:r,txb:o,input_coin:t,router:a}=i,d=o||new _o;if(a)return await this._sdk.AggregatorClient.routerSwap({router:a,inputCoin:t,slippage:r,txb:d})};this.flashLoan=i=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:183 ~ SwapModules ~ params:",i);let{clmm_pool:r}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:o}=Ir(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:t,clmm_pool:a,clmm_pool_coin_type_a:d,clmm_pool_coin_type_b:c,flash_loan_coin:m,tx:g}=i,M=wo(d)===m;console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:188 ~ SwapModules ~ isLoanA:",M);let[P,A,D]=g.moveCall({target:`${r.published_at}::pool::flash_loan`,arguments:[g.object(o),g.object(a),g.pure.bool(M),g.pure.u64(t.toString())],typeArguments:[d,c]});return{balance_a:P,balance_b:A,receipt:D,is_loan_a:M,loan_coin_type:M?d:c}};this.getFlashLoanPool=async(i,r)=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:201 ~ SwapModules ~ flash_amount:",r,i);try{let o=await fetch(`https://api-sui.cetus.zone/v3/sui/margin_trading/pools?coin_type=${i}&min_amount=${r}`),{data:t}=await o.json();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:206 ~ SwapModules ~ data:",t),t&&t.length>0?{clmm_pool_coin_type_a:t[0].coin_type_a,clmm_pool_coin_type_b:t[0].coin_type_b,clmm_pool:t[0].pool_id,clmm_fee_tier:ee(t[0].fee_rate).div(1e6).toString()}:(Gt("FlashLoanPoolNotFound","FlashLoanPoolNotFound"),{clmm_pool_coin_type_a:"",clmm_pool_coin_type_b:"",clmm_pool:"",clmm_fee_tier:""})}catch(o){return Gt("FetchError",o),{clmm_pool_coin_type_a:"",clmm_pool_coin_type_b:"",clmm_pool:"",clmm_fee_tier:""}}};this.repayFlashLoan=i=>{let{clmm_pool:r}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:o}=Ir(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:t,repay_base:a,repay_quote:d,receipt:c,clmm_pool:m,clmm_pool_coin_type_a:g,clmm_pool_coin_type_b:M}=i;return t.moveCall({target:`${r.published_at}::pool::repay_flash_loan`,arguments:[t.object(o),t.object(m),a,d,c],typeArguments:[g,M]}),t};this._sdk=i}async findRouters(i,r,o,t,a){try{let d={from:i,target:r,amount:new $i.default(ee(o).toFixed(0).toString()),byAmountIn:t,depth:3},c=await this._sdk.AggregatorClient.findRouters(d);if(c?.error?.code===10001)return{...c,is_exceed:c.insufficientLiquidity};if(c?.insufficientLiquidity)return{...c,is_exceed:c.insufficientLiquidity};if(!c?.paths||c?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:c.amountIn.toString(),amount_out:c.amountOut.toString(),is_exceed:c.insufficientLiquidity,route_obj:c,by_amount_in:!0,origin_res:c}}catch{try{if(a){let c=await this._sdk.AggregatorClient.swapInPools({from:i,target:r,amount:new $i.default(ee(o).toFixed(0).toString()),byAmountIn:t,pools:a});return c?{amount_in:c.routeData.amountIn.toString(),amount_out:c.routeData.amountOut.toString(),is_exceed:c.isExceed,route_obj:c.routeData,by_amount_in:!0,origin_res:c}:null}return null}catch{return null}}}async handleSwapLogic(i){let{is_long:r,is_quote:o,amount:t,base_token:a,quote_token:d,swap_clmm_pool:c="",slippage:m,tx:g}=i,M=r&&o||!r&&!o,P,A,D=t;if(M){let T=r&&o?d:a,L=r&&o?a:d,N=await this.findRouters(T,L,t,!0,[c]);if(D=N?.amount_out.toString(),N){let R=ji.buildCoinWithBalance(BigInt(t),T,g);A=await this.routerSwap({router:N.route_obj,slippage:m,input_coin:R,txb:g}),P=A}}else P=ji.buildCoinWithBalance(BigInt(t.toString()),o?d:a,g);return{has_swap:M,input_coin:P,init_deposit_amount:D}}async handleSwap(i){let{swap_clmm_pool:r="",slippage:o,amount:t,from:a,to:d,tx:c,input_coin:m}=i,g=await this.findRouters(a,d,t,!0,[r]),M=g.amount_out.toString();return{swap_out_coin:await this.routerSwap({router:g.route_obj,slippage:o,input_coin:m||ji.buildCoinWithBalance(BigInt(t),a,c),txb:c}),amount_out:M}}async calculateFlashLoan(i){let{is_long:r,leverage:o,base_token:t,quote_token:a,deposit_amount:d,reserve:c,base_token_decimal:m,quote_token_decimal:g}=i,M=await this._sdk.SuiLendModule.getLatestPriceFeeds(c),P=M&&M[Br(a)]?.price,A=M&&M[Br(t)]?.price,D=r?ee(A).div(ee(P)).toString():ee(P).div(ee(A)).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:267 ~ SwapModules ~ calculateFlashLoan ~ deposit_amount:",d,D,m,g);let T=ee(d).mul(ee(o).sub(1)).mul(D).div(10**(r?m:g)).mul(10**(r?g:m)).toDP(0,ht.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:274 ~ SwapModules ~ calculateFlashLoan ~ flashAmount:",ee(d).mul(ee(o).sub(1)).mul(D).div(10**(r?m:g)).mul(10**(r?g:m)).toString(),T);let L=r?a:t,{clmm_pool_coin_type_a:N,clmm_fee_tier:R,clmm_pool:O,clmm_pool_coin_type_b:I}=await this.getFlashLoanPool(L,T),U=N===L,W=ee(T).mul(R).toString();return{flash_amount:T,rate:D,quote_price:P,base_price:A,flash_loan_coin:L,is_flash_a:U,flash_loan_fee:W,clmm_pool:O,clmm_pool_coin_type_a:N,clmm_pool_coin_type_b:I,clmm_fee_tier:R}}};var ei=class n extends yo{constructor(i,r){super(i),this._suilendModule=new Qe(this),this._permissionModules=new Be(this),this._marketModules=new Ie(this),this._positionModules=new He(this),this._swapModules=new ti(this),this._aggregatorClient=new So({signer:Mo("0x0"),client:i.sui_client||new vo({url:i.full_rpc_url}),env:i.env==="testnet"?qr.Testnet:qr.Mainnet}),this._clmmSDK=r||ko.createSDK({env:i.env,full_rpc_url:i.full_rpc_url}),this._pythConnection=new bo("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get PermissionModules(){return this._permissionModules}get MarketModules(){return this._marketModules}get PositionModules(){return this._positionModules}get SwapModules(){return this._swapModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(i){return n.createCustomSDK({...rr,...i})}static createCustomSDK(i){return new n(i)}};var da=ei;export{ei as CetusMarginTradingSDK,ys as appendExtraRewards,qi as calculateBorrowAprPercent,Tr as calculateDepositAprPercent,Dr as calculateUtilizationPercent,da as default,As as formatLtvPercentValue,Or as getPriceWithFormattedDecimals,Ss as getRewardsAprMultiplier,ks as getUpdatedReserve,rr as margin_trading_mainnet,ki as mergePositionData,Bi as oraclePriceMultiplierDecimal,Ps as updateRewardsWithMultiplier,bi as wrapMarketInfo,Si as wrapMarketPermissions,yi as wrapPosition};
1
+ var Fr=Object.create;var ir=Object.defineProperty;var Ur=Object.getOwnPropertyDescriptor;var jr=Object.getOwnPropertyNames;var $r=Object.getPrototypeOf,Wr=Object.prototype.hasOwnProperty;var Zr=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(i,r)=>(typeof require<"u"?require:i)[r]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var Kr=(n,i)=>()=>(i||n((i={exports:{}}).exports,i),i.exports);var zr=(n,i,r,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of jr(i))!Wr.call(n,t)&&t!==r&&ir(n,t,{get:()=>i[t],enumerable:!(o=Ur(i,t))||o.enumerable});return n};var Gr=(n,i,r)=>(r=n!=null?Fr($r(n)):{},zr(i||!n||!n.__esModule?ir(r,"default",{value:n,enumerable:!0}):r,n));var Ir=Kr((Nr,Ui)=>{"use strict";(function(n,i){"use strict";function r(p,e){if(!p)throw new Error(e||"Assertion failed")}function o(p,e){p.super_=e;var s=function(){};s.prototype=e.prototype,p.prototype=new s,p.prototype.constructor=p}function t(p,e,s){if(t.isBN(p))return p;this.negative=0,this.words=null,this.length=0,this.red=null,p!==null&&((e==="le"||e==="be")&&(s=e,e=10),this._init(p||0,e||10,s||"be"))}typeof n=="object"?n.exports=t:i.BN=t,t.BN=t,t.wordSize=26;var a;try{typeof window<"u"&&typeof window.Buffer<"u"?a=window.Buffer:a=Zr("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,s){return e.cmp(s)>0?e:s},t.min=function(e,s){return e.cmp(s)<0?e:s},t.prototype._init=function(e,s,l){if(typeof e=="number")return this._initNumber(e,s,l);if(typeof e=="object")return this._initArray(e,s,l);s==="hex"&&(s=16),r(s===(s|0)&&s>=2&&s<=36),e=e.toString().replace(/\s+/g,"");var f=0;e[0]==="-"&&(f++,this.negative=1),f<e.length&&(s===16?this._parseHex(e,f,l):(this._parseBase(e,s,f),l==="le"&&this._initArray(this.toArray(),s,l)))},t.prototype._initNumber=function(e,s,l){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[e&67108863],this.length=1):e<4503599627370496?(this.words=[e&67108863,e/67108864&67108863],this.length=2):(r(e<9007199254740992),this.words=[e&67108863,e/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),s,l)},t.prototype._initArray=function(e,s,l){if(r(typeof e.length=="number"),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var h,v,k=0;if(l==="be")for(f=e.length-1,h=0;f>=0;f-=3)v=e[f]|e[f-1]<<8|e[f-2]<<16,this.words[h]|=v<<k&67108863,this.words[h+1]=v>>>26-k&67108863,k+=24,k>=26&&(k-=26,h++);else if(l==="le")for(f=0,h=0;f<e.length;f+=3)v=e[f]|e[f+1]<<8|e[f+2]<<16,this.words[h]|=v<<k&67108863,this.words[h+1]=v>>>26-k&67108863,k+=24,k>=26&&(k-=26,h++);return this._strip()};function d(p,e){var s=p.charCodeAt(e);if(s>=48&&s<=57)return s-48;if(s>=65&&s<=70)return s-55;if(s>=97&&s<=102)return s-87;r(!1,"Invalid character in "+p)}function c(p,e,s){var l=d(p,s);return s-1>=e&&(l|=d(p,s-1)<<4),l}t.prototype._parseHex=function(e,s,l){this.length=Math.ceil((e.length-s)/6),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var h=0,v=0,k;if(l==="be")for(f=e.length-1;f>=s;f-=2)k=c(e,s,f)<<h,this.words[v]|=k&67108863,h>=18?(h-=18,v+=1,this.words[v]|=k>>>26):h+=8;else{var w=e.length-s;for(f=w%2===0?s+1:s;f<e.length;f+=2)k=c(e,s,f)<<h,this.words[v]|=k&67108863,h>=18?(h-=18,v+=1,this.words[v]|=k>>>26):h+=8}this._strip()};function m(p,e,s,l){for(var f=0,h=0,v=Math.min(p.length,s),k=e;k<v;k++){var w=p.charCodeAt(k)-48;f*=l,w>=49?h=w-49+10:w>=17?h=w-17+10:h=w,r(w>=0&&h<l,"Invalid character"),f+=h}return f}t.prototype._parseBase=function(e,s,l){this.words=[0],this.length=1;for(var f=0,h=1;h<=67108863;h*=s)f++;f--,h=h/s|0;for(var v=e.length-l,k=v%f,w=Math.min(v,v-k)+l,u=0,y=l;y<w;y+=f)u=m(e,y,y+f,s),this.imuln(h),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(k!==0){var $=1;for(u=m(e,y,e.length,s),y=0;y<k;y++)$*=s;this.imuln($),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},t.prototype.copy=function(e){e.words=new Array(this.length);for(var s=0;s<this.length;s++)e.words[s]=this.words[s];e.length=this.length,e.negative=this.negative,e.red=this.red};function g(p,e){p.words=e.words,p.length=e.length,p.negative=e.negative,p.red=e.red}if(t.prototype._move=function(e){g(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")]=M}catch{t.prototype.inspect=M}else t.prototype.inspect=M;function M(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var P=["","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],D=[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,s){e=e||10,s=s|0||1;var l;if(e===16||e==="hex"){l="";for(var f=0,h=0,v=0;v<this.length;v++){var k=this.words[v],w=((k<<f|h)&16777215).toString(16);h=k>>>24-f&16777215,f+=2,f>=26&&(f-=26,v--),h!==0||v!==this.length-1?l=P[6-w.length]+w+l:l=w+l}for(h!==0&&(l=h.toString(16)+l);l.length%s!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(e===(e|0)&&e>=2&&e<=36){var u=A[e],y=D[e];l="";var $=this.clone();for($.negative=0;!$.isZero();){var U=$.modrn(y).toString(e);$=$.idivn(y),$.isZero()?l=U+l:l=P[u-U.length]+U+l}for(this.isZero()&&(l="0"+l);l.length%s!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}r(!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&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-e:e},t.prototype.toJSON=function(){return this.toString(16,2)},a&&(t.prototype.toBuffer=function(e,s){return this.toArrayLike(a,e,s)}),t.prototype.toArray=function(e,s){return this.toArrayLike(Array,e,s)};var T=function(e,s){return e.allocUnsafe?e.allocUnsafe(s):new e(s)};t.prototype.toArrayLike=function(e,s,l){this._strip();var f=this.byteLength(),h=l||Math.max(1,f);r(f<=h,"byte array longer than desired length"),r(h>0,"Requested array length <= 0");var v=T(e,h),k=s==="le"?"LE":"BE";return this["_toArrayLike"+k](v,f),v},t.prototype._toArrayLikeLE=function(e,s){for(var l=0,f=0,h=0,v=0;h<this.length;h++){var k=this.words[h]<<v|f;e[l++]=k&255,l<e.length&&(e[l++]=k>>8&255),l<e.length&&(e[l++]=k>>16&255),v===6?(l<e.length&&(e[l++]=k>>24&255),f=0,v=0):(f=k>>>24,v+=2)}if(l<e.length)for(e[l++]=f;l<e.length;)e[l++]=0},t.prototype._toArrayLikeBE=function(e,s){for(var l=e.length-1,f=0,h=0,v=0;h<this.length;h++){var k=this.words[h]<<v|f;e[l--]=k&255,l>=0&&(e[l--]=k>>8&255),l>=0&&(e[l--]=k>>16&255),v===6?(l>=0&&(e[l--]=k>>24&255),f=0,v=0):(f=k>>>24,v+=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 s=e,l=0;return s>=4096&&(l+=13,s>>>=13),s>=64&&(l+=7,s>>>=7),s>=8&&(l+=4,s>>>=4),s>=2&&(l+=2,s>>>=2),l+s},t.prototype._zeroBits=function(e){if(e===0)return 26;var s=e,l=0;return(s&8191)===0&&(l+=13,s>>>=13),(s&127)===0&&(l+=7,s>>>=7),(s&15)===0&&(l+=4,s>>>=4),(s&3)===0&&(l+=2,s>>>=2),(s&1)===0&&l++,l},t.prototype.bitLength=function(){var e=this.words[this.length-1],s=this._countBits(e);return(this.length-1)*26+s};function L(p){for(var e=new Array(p.bitLength()),s=0;s<e.length;s++){var l=s/26|0,f=s%26;e[s]=p.words[l]>>>f&1}return e}t.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,s=0;s<this.length;s++){var l=this._zeroBits(this.words[s]);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 s=0;s<e.length;s++)this.words[s]=this.words[s]|e.words[s];return this._strip()},t.prototype.ior=function(e){return r((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 s;this.length>e.length?s=e:s=this;for(var l=0;l<s.length;l++)this.words[l]=this.words[l]&e.words[l];return this.length=s.length,this._strip()},t.prototype.iand=function(e){return r((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 s,l;this.length>e.length?(s=this,l=e):(s=e,l=this);for(var f=0;f<l.length;f++)this.words[f]=s.words[f]^l.words[f];if(this!==s)for(;f<s.length;f++)this.words[f]=s.words[f];return this.length=s.length,this._strip()},t.prototype.ixor=function(e){return r((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){r(typeof e=="number"&&e>=0);var s=Math.ceil(e/26)|0,l=e%26;this._expand(s),l>0&&s--;for(var f=0;f<s;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,s){r(typeof e=="number"&&e>=0);var l=e/26|0,f=e%26;return this._expand(l+1),s?this.words[l]=this.words[l]|1<<f:this.words[l]=this.words[l]&~(1<<f),this._strip()},t.prototype.iadd=function(e){var s;if(this.negative!==0&&e.negative===0)return this.negative=0,s=this.isub(e),this.negative^=1,this._normSign();if(this.negative===0&&e.negative!==0)return e.negative=0,s=this.isub(e),e.negative=1,s._normSign();var l,f;this.length>e.length?(l=this,f=e):(l=e,f=this);for(var h=0,v=0;v<f.length;v++)s=(l.words[v]|0)+(f.words[v]|0)+h,this.words[v]=s&67108863,h=s>>>26;for(;h!==0&&v<l.length;v++)s=(l.words[v]|0)+h,this.words[v]=s&67108863,h=s>>>26;if(this.length=l.length,h!==0)this.words[this.length]=h,this.length++;else if(l!==this)for(;v<l.length;v++)this.words[v]=l.words[v];return this},t.prototype.add=function(e){var s;return e.negative!==0&&this.negative===0?(e.negative=0,s=this.sub(e),e.negative^=1,s):e.negative===0&&this.negative!==0?(this.negative=0,s=e.sub(this),this.negative=1,s):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 s=this.iadd(e);return e.negative=1,s._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 v=0,k=0;k<h.length;k++)s=(f.words[k]|0)-(h.words[k]|0)+v,v=s>>26,this.words[k]=s&67108863;for(;v!==0&&k<f.length;k++)s=(f.words[k]|0)+v,v=s>>26,this.words[k]=s&67108863;if(v===0&&k<f.length&&f!==this)for(;k<f.length;k++)this.words[k]=f.words[k];return this.length=Math.max(this.length,k),f!==this&&(this.negative=1),this._strip()},t.prototype.sub=function(e){return this.clone().isub(e)};function N(p,e,s){s.negative=e.negative^p.negative;var l=p.length+e.length|0;s.length=l,l=l-1|0;var f=p.words[0]|0,h=e.words[0]|0,v=f*h,k=v&67108863,w=v/67108864|0;s.words[0]=k;for(var u=1;u<l;u++){for(var y=w>>>26,$=w&67108863,U=Math.min(u,e.length-1),j=Math.max(0,u-p.length+1);j<=U;j++){var K=u-j|0;f=p.words[K]|0,h=e.words[j]|0,v=f*h+$,y+=v/67108864|0,$=v&67108863}s.words[u]=$|0,w=y|0}return w!==0?s.words[u]=w|0:s.length--,s._strip()}var R=function(e,s,l){var f=e.words,h=s.words,v=l.words,k=0,w,u,y,$=f[0]|0,U=$&8191,j=$>>>13,K=f[1]|0,G=K&8191,J=K>>>13,rt=f[2]|0,V=rt&8191,it=rt>>>13,ut=f[3]|0,et=ut&8191,X=ut>>>13,de=f[4]|0,ct=de&8191,at=de>>>13,ke=f[5]|0,nt=ke&8191,ot=ke>>>13,ue=f[6]|0,dt=ue&8191,pt=ue>>>13,Wi=f[7]|0,mt=Wi&8191,gt=Wi>>>13,Zi=f[8]|0,_t=Zi&8191,wt=Zi>>>13,Ki=f[9]|0,vt=Ki&8191,Mt=Ki>>>13,zi=h[0]|0,bt=zi&8191,yt=zi>>>13,Gi=h[1]|0,kt=Gi&8191,St=Gi>>>13,Hi=h[2]|0,Pt=Hi&8191,At=Hi>>>13,Vi=h[3]|0,Ct=Vi&8191,xt=Vi>>>13,Xi=h[4]|0,Dt=Xi&8191,Tt=Xi>>>13,Ji=h[5]|0,Ot=Ji&8191,Rt=Ji>>>13,Yi=h[6]|0,Lt=Yi&8191,Nt=Yi>>>13,Qi=h[7]|0,It=Qi&8191,Et=Qi>>>13,tr=h[8]|0,Bt=tr&8191,qt=tr>>>13,er=h[9]|0,Ft=er&8191,Ut=er>>>13;l.negative=e.negative^s.negative,l.length=19,w=Math.imul(U,bt),u=Math.imul(U,yt),u=u+Math.imul(j,bt)|0,y=Math.imul(j,yt);var ii=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ii>>>26)|0,ii&=67108863,w=Math.imul(G,bt),u=Math.imul(G,yt),u=u+Math.imul(J,bt)|0,y=Math.imul(J,yt),w=w+Math.imul(U,kt)|0,u=u+Math.imul(U,St)|0,u=u+Math.imul(j,kt)|0,y=y+Math.imul(j,St)|0;var ri=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ri>>>26)|0,ri&=67108863,w=Math.imul(V,bt),u=Math.imul(V,yt),u=u+Math.imul(it,bt)|0,y=Math.imul(it,yt),w=w+Math.imul(G,kt)|0,u=u+Math.imul(G,St)|0,u=u+Math.imul(J,kt)|0,y=y+Math.imul(J,St)|0,w=w+Math.imul(U,Pt)|0,u=u+Math.imul(U,At)|0,u=u+Math.imul(j,Pt)|0,y=y+Math.imul(j,At)|0;var ni=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ni>>>26)|0,ni&=67108863,w=Math.imul(et,bt),u=Math.imul(et,yt),u=u+Math.imul(X,bt)|0,y=Math.imul(X,yt),w=w+Math.imul(V,kt)|0,u=u+Math.imul(V,St)|0,u=u+Math.imul(it,kt)|0,y=y+Math.imul(it,St)|0,w=w+Math.imul(G,Pt)|0,u=u+Math.imul(G,At)|0,u=u+Math.imul(J,Pt)|0,y=y+Math.imul(J,At)|0,w=w+Math.imul(U,Ct)|0,u=u+Math.imul(U,xt)|0,u=u+Math.imul(j,Ct)|0,y=y+Math.imul(j,xt)|0;var oi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(oi>>>26)|0,oi&=67108863,w=Math.imul(ct,bt),u=Math.imul(ct,yt),u=u+Math.imul(at,bt)|0,y=Math.imul(at,yt),w=w+Math.imul(et,kt)|0,u=u+Math.imul(et,St)|0,u=u+Math.imul(X,kt)|0,y=y+Math.imul(X,St)|0,w=w+Math.imul(V,Pt)|0,u=u+Math.imul(V,At)|0,u=u+Math.imul(it,Pt)|0,y=y+Math.imul(it,At)|0,w=w+Math.imul(G,Ct)|0,u=u+Math.imul(G,xt)|0,u=u+Math.imul(J,Ct)|0,y=y+Math.imul(J,xt)|0,w=w+Math.imul(U,Dt)|0,u=u+Math.imul(U,Tt)|0,u=u+Math.imul(j,Dt)|0,y=y+Math.imul(j,Tt)|0;var si=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(si>>>26)|0,si&=67108863,w=Math.imul(nt,bt),u=Math.imul(nt,yt),u=u+Math.imul(ot,bt)|0,y=Math.imul(ot,yt),w=w+Math.imul(ct,kt)|0,u=u+Math.imul(ct,St)|0,u=u+Math.imul(at,kt)|0,y=y+Math.imul(at,St)|0,w=w+Math.imul(et,Pt)|0,u=u+Math.imul(et,At)|0,u=u+Math.imul(X,Pt)|0,y=y+Math.imul(X,At)|0,w=w+Math.imul(V,Ct)|0,u=u+Math.imul(V,xt)|0,u=u+Math.imul(it,Ct)|0,y=y+Math.imul(it,xt)|0,w=w+Math.imul(G,Dt)|0,u=u+Math.imul(G,Tt)|0,u=u+Math.imul(J,Dt)|0,y=y+Math.imul(J,Tt)|0,w=w+Math.imul(U,Ot)|0,u=u+Math.imul(U,Rt)|0,u=u+Math.imul(j,Ot)|0,y=y+Math.imul(j,Rt)|0;var ai=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ai>>>26)|0,ai&=67108863,w=Math.imul(dt,bt),u=Math.imul(dt,yt),u=u+Math.imul(pt,bt)|0,y=Math.imul(pt,yt),w=w+Math.imul(nt,kt)|0,u=u+Math.imul(nt,St)|0,u=u+Math.imul(ot,kt)|0,y=y+Math.imul(ot,St)|0,w=w+Math.imul(ct,Pt)|0,u=u+Math.imul(ct,At)|0,u=u+Math.imul(at,Pt)|0,y=y+Math.imul(at,At)|0,w=w+Math.imul(et,Ct)|0,u=u+Math.imul(et,xt)|0,u=u+Math.imul(X,Ct)|0,y=y+Math.imul(X,xt)|0,w=w+Math.imul(V,Dt)|0,u=u+Math.imul(V,Tt)|0,u=u+Math.imul(it,Dt)|0,y=y+Math.imul(it,Tt)|0,w=w+Math.imul(G,Ot)|0,u=u+Math.imul(G,Rt)|0,u=u+Math.imul(J,Ot)|0,y=y+Math.imul(J,Rt)|0,w=w+Math.imul(U,Lt)|0,u=u+Math.imul(U,Nt)|0,u=u+Math.imul(j,Lt)|0,y=y+Math.imul(j,Nt)|0;var li=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(li>>>26)|0,li&=67108863,w=Math.imul(mt,bt),u=Math.imul(mt,yt),u=u+Math.imul(gt,bt)|0,y=Math.imul(gt,yt),w=w+Math.imul(dt,kt)|0,u=u+Math.imul(dt,St)|0,u=u+Math.imul(pt,kt)|0,y=y+Math.imul(pt,St)|0,w=w+Math.imul(nt,Pt)|0,u=u+Math.imul(nt,At)|0,u=u+Math.imul(ot,Pt)|0,y=y+Math.imul(ot,At)|0,w=w+Math.imul(ct,Ct)|0,u=u+Math.imul(ct,xt)|0,u=u+Math.imul(at,Ct)|0,y=y+Math.imul(at,xt)|0,w=w+Math.imul(et,Dt)|0,u=u+Math.imul(et,Tt)|0,u=u+Math.imul(X,Dt)|0,y=y+Math.imul(X,Tt)|0,w=w+Math.imul(V,Ot)|0,u=u+Math.imul(V,Rt)|0,u=u+Math.imul(it,Ot)|0,y=y+Math.imul(it,Rt)|0,w=w+Math.imul(G,Lt)|0,u=u+Math.imul(G,Nt)|0,u=u+Math.imul(J,Lt)|0,y=y+Math.imul(J,Nt)|0,w=w+Math.imul(U,It)|0,u=u+Math.imul(U,Et)|0,u=u+Math.imul(j,It)|0,y=y+Math.imul(j,Et)|0;var ui=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ui>>>26)|0,ui&=67108863,w=Math.imul(_t,bt),u=Math.imul(_t,yt),u=u+Math.imul(wt,bt)|0,y=Math.imul(wt,yt),w=w+Math.imul(mt,kt)|0,u=u+Math.imul(mt,St)|0,u=u+Math.imul(gt,kt)|0,y=y+Math.imul(gt,St)|0,w=w+Math.imul(dt,Pt)|0,u=u+Math.imul(dt,At)|0,u=u+Math.imul(pt,Pt)|0,y=y+Math.imul(pt,At)|0,w=w+Math.imul(nt,Ct)|0,u=u+Math.imul(nt,xt)|0,u=u+Math.imul(ot,Ct)|0,y=y+Math.imul(ot,xt)|0,w=w+Math.imul(ct,Dt)|0,u=u+Math.imul(ct,Tt)|0,u=u+Math.imul(at,Dt)|0,y=y+Math.imul(at,Tt)|0,w=w+Math.imul(et,Ot)|0,u=u+Math.imul(et,Rt)|0,u=u+Math.imul(X,Ot)|0,y=y+Math.imul(X,Rt)|0,w=w+Math.imul(V,Lt)|0,u=u+Math.imul(V,Nt)|0,u=u+Math.imul(it,Lt)|0,y=y+Math.imul(it,Nt)|0,w=w+Math.imul(G,It)|0,u=u+Math.imul(G,Et)|0,u=u+Math.imul(J,It)|0,y=y+Math.imul(J,Et)|0,w=w+Math.imul(U,Bt)|0,u=u+Math.imul(U,qt)|0,u=u+Math.imul(j,Bt)|0,y=y+Math.imul(j,qt)|0;var ci=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(ci>>>26)|0,ci&=67108863,w=Math.imul(vt,bt),u=Math.imul(vt,yt),u=u+Math.imul(Mt,bt)|0,y=Math.imul(Mt,yt),w=w+Math.imul(_t,kt)|0,u=u+Math.imul(_t,St)|0,u=u+Math.imul(wt,kt)|0,y=y+Math.imul(wt,St)|0,w=w+Math.imul(mt,Pt)|0,u=u+Math.imul(mt,At)|0,u=u+Math.imul(gt,Pt)|0,y=y+Math.imul(gt,At)|0,w=w+Math.imul(dt,Ct)|0,u=u+Math.imul(dt,xt)|0,u=u+Math.imul(pt,Ct)|0,y=y+Math.imul(pt,xt)|0,w=w+Math.imul(nt,Dt)|0,u=u+Math.imul(nt,Tt)|0,u=u+Math.imul(ot,Dt)|0,y=y+Math.imul(ot,Tt)|0,w=w+Math.imul(ct,Ot)|0,u=u+Math.imul(ct,Rt)|0,u=u+Math.imul(at,Ot)|0,y=y+Math.imul(at,Rt)|0,w=w+Math.imul(et,Lt)|0,u=u+Math.imul(et,Nt)|0,u=u+Math.imul(X,Lt)|0,y=y+Math.imul(X,Nt)|0,w=w+Math.imul(V,It)|0,u=u+Math.imul(V,Et)|0,u=u+Math.imul(it,It)|0,y=y+Math.imul(it,Et)|0,w=w+Math.imul(G,Bt)|0,u=u+Math.imul(G,qt)|0,u=u+Math.imul(J,Bt)|0,y=y+Math.imul(J,qt)|0,w=w+Math.imul(U,Ft)|0,u=u+Math.imul(U,Ut)|0,u=u+Math.imul(j,Ft)|0,y=y+Math.imul(j,Ut)|0;var fi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(fi>>>26)|0,fi&=67108863,w=Math.imul(vt,kt),u=Math.imul(vt,St),u=u+Math.imul(Mt,kt)|0,y=Math.imul(Mt,St),w=w+Math.imul(_t,Pt)|0,u=u+Math.imul(_t,At)|0,u=u+Math.imul(wt,Pt)|0,y=y+Math.imul(wt,At)|0,w=w+Math.imul(mt,Ct)|0,u=u+Math.imul(mt,xt)|0,u=u+Math.imul(gt,Ct)|0,y=y+Math.imul(gt,xt)|0,w=w+Math.imul(dt,Dt)|0,u=u+Math.imul(dt,Tt)|0,u=u+Math.imul(pt,Dt)|0,y=y+Math.imul(pt,Tt)|0,w=w+Math.imul(nt,Ot)|0,u=u+Math.imul(nt,Rt)|0,u=u+Math.imul(ot,Ot)|0,y=y+Math.imul(ot,Rt)|0,w=w+Math.imul(ct,Lt)|0,u=u+Math.imul(ct,Nt)|0,u=u+Math.imul(at,Lt)|0,y=y+Math.imul(at,Nt)|0,w=w+Math.imul(et,It)|0,u=u+Math.imul(et,Et)|0,u=u+Math.imul(X,It)|0,y=y+Math.imul(X,Et)|0,w=w+Math.imul(V,Bt)|0,u=u+Math.imul(V,qt)|0,u=u+Math.imul(it,Bt)|0,y=y+Math.imul(it,qt)|0,w=w+Math.imul(G,Ft)|0,u=u+Math.imul(G,Ut)|0,u=u+Math.imul(J,Ft)|0,y=y+Math.imul(J,Ut)|0;var di=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(di>>>26)|0,di&=67108863,w=Math.imul(vt,Pt),u=Math.imul(vt,At),u=u+Math.imul(Mt,Pt)|0,y=Math.imul(Mt,At),w=w+Math.imul(_t,Ct)|0,u=u+Math.imul(_t,xt)|0,u=u+Math.imul(wt,Ct)|0,y=y+Math.imul(wt,xt)|0,w=w+Math.imul(mt,Dt)|0,u=u+Math.imul(mt,Tt)|0,u=u+Math.imul(gt,Dt)|0,y=y+Math.imul(gt,Tt)|0,w=w+Math.imul(dt,Ot)|0,u=u+Math.imul(dt,Rt)|0,u=u+Math.imul(pt,Ot)|0,y=y+Math.imul(pt,Rt)|0,w=w+Math.imul(nt,Lt)|0,u=u+Math.imul(nt,Nt)|0,u=u+Math.imul(ot,Lt)|0,y=y+Math.imul(ot,Nt)|0,w=w+Math.imul(ct,It)|0,u=u+Math.imul(ct,Et)|0,u=u+Math.imul(at,It)|0,y=y+Math.imul(at,Et)|0,w=w+Math.imul(et,Bt)|0,u=u+Math.imul(et,qt)|0,u=u+Math.imul(X,Bt)|0,y=y+Math.imul(X,qt)|0,w=w+Math.imul(V,Ft)|0,u=u+Math.imul(V,Ut)|0,u=u+Math.imul(it,Ft)|0,y=y+Math.imul(it,Ut)|0;var hi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(hi>>>26)|0,hi&=67108863,w=Math.imul(vt,Ct),u=Math.imul(vt,xt),u=u+Math.imul(Mt,Ct)|0,y=Math.imul(Mt,xt),w=w+Math.imul(_t,Dt)|0,u=u+Math.imul(_t,Tt)|0,u=u+Math.imul(wt,Dt)|0,y=y+Math.imul(wt,Tt)|0,w=w+Math.imul(mt,Ot)|0,u=u+Math.imul(mt,Rt)|0,u=u+Math.imul(gt,Ot)|0,y=y+Math.imul(gt,Rt)|0,w=w+Math.imul(dt,Lt)|0,u=u+Math.imul(dt,Nt)|0,u=u+Math.imul(pt,Lt)|0,y=y+Math.imul(pt,Nt)|0,w=w+Math.imul(nt,It)|0,u=u+Math.imul(nt,Et)|0,u=u+Math.imul(ot,It)|0,y=y+Math.imul(ot,Et)|0,w=w+Math.imul(ct,Bt)|0,u=u+Math.imul(ct,qt)|0,u=u+Math.imul(at,Bt)|0,y=y+Math.imul(at,qt)|0,w=w+Math.imul(et,Ft)|0,u=u+Math.imul(et,Ut)|0,u=u+Math.imul(X,Ft)|0,y=y+Math.imul(X,Ut)|0;var pi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(pi>>>26)|0,pi&=67108863,w=Math.imul(vt,Dt),u=Math.imul(vt,Tt),u=u+Math.imul(Mt,Dt)|0,y=Math.imul(Mt,Tt),w=w+Math.imul(_t,Ot)|0,u=u+Math.imul(_t,Rt)|0,u=u+Math.imul(wt,Ot)|0,y=y+Math.imul(wt,Rt)|0,w=w+Math.imul(mt,Lt)|0,u=u+Math.imul(mt,Nt)|0,u=u+Math.imul(gt,Lt)|0,y=y+Math.imul(gt,Nt)|0,w=w+Math.imul(dt,It)|0,u=u+Math.imul(dt,Et)|0,u=u+Math.imul(pt,It)|0,y=y+Math.imul(pt,Et)|0,w=w+Math.imul(nt,Bt)|0,u=u+Math.imul(nt,qt)|0,u=u+Math.imul(ot,Bt)|0,y=y+Math.imul(ot,qt)|0,w=w+Math.imul(ct,Ft)|0,u=u+Math.imul(ct,Ut)|0,u=u+Math.imul(at,Ft)|0,y=y+Math.imul(at,Ut)|0;var mi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(mi>>>26)|0,mi&=67108863,w=Math.imul(vt,Ot),u=Math.imul(vt,Rt),u=u+Math.imul(Mt,Ot)|0,y=Math.imul(Mt,Rt),w=w+Math.imul(_t,Lt)|0,u=u+Math.imul(_t,Nt)|0,u=u+Math.imul(wt,Lt)|0,y=y+Math.imul(wt,Nt)|0,w=w+Math.imul(mt,It)|0,u=u+Math.imul(mt,Et)|0,u=u+Math.imul(gt,It)|0,y=y+Math.imul(gt,Et)|0,w=w+Math.imul(dt,Bt)|0,u=u+Math.imul(dt,qt)|0,u=u+Math.imul(pt,Bt)|0,y=y+Math.imul(pt,qt)|0,w=w+Math.imul(nt,Ft)|0,u=u+Math.imul(nt,Ut)|0,u=u+Math.imul(ot,Ft)|0,y=y+Math.imul(ot,Ut)|0;var gi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(gi>>>26)|0,gi&=67108863,w=Math.imul(vt,Lt),u=Math.imul(vt,Nt),u=u+Math.imul(Mt,Lt)|0,y=Math.imul(Mt,Nt),w=w+Math.imul(_t,It)|0,u=u+Math.imul(_t,Et)|0,u=u+Math.imul(wt,It)|0,y=y+Math.imul(wt,Et)|0,w=w+Math.imul(mt,Bt)|0,u=u+Math.imul(mt,qt)|0,u=u+Math.imul(gt,Bt)|0,y=y+Math.imul(gt,qt)|0,w=w+Math.imul(dt,Ft)|0,u=u+Math.imul(dt,Ut)|0,u=u+Math.imul(pt,Ft)|0,y=y+Math.imul(pt,Ut)|0;var _i=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(_i>>>26)|0,_i&=67108863,w=Math.imul(vt,It),u=Math.imul(vt,Et),u=u+Math.imul(Mt,It)|0,y=Math.imul(Mt,Et),w=w+Math.imul(_t,Bt)|0,u=u+Math.imul(_t,qt)|0,u=u+Math.imul(wt,Bt)|0,y=y+Math.imul(wt,qt)|0,w=w+Math.imul(mt,Ft)|0,u=u+Math.imul(mt,Ut)|0,u=u+Math.imul(gt,Ft)|0,y=y+Math.imul(gt,Ut)|0;var wi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(wi>>>26)|0,wi&=67108863,w=Math.imul(vt,Bt),u=Math.imul(vt,qt),u=u+Math.imul(Mt,Bt)|0,y=Math.imul(Mt,qt),w=w+Math.imul(_t,Ft)|0,u=u+Math.imul(_t,Ut)|0,u=u+Math.imul(wt,Ft)|0,y=y+Math.imul(wt,Ut)|0;var vi=(k+w|0)+((u&8191)<<13)|0;k=(y+(u>>>13)|0)+(vi>>>26)|0,vi&=67108863,w=Math.imul(vt,Ft),u=Math.imul(vt,Ut),u=u+Math.imul(Mt,Ft)|0,y=Math.imul(Mt,Ut);var Mi=(k+w|0)+((u&8191)<<13)|0;return k=(y+(u>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,v[0]=ii,v[1]=ri,v[2]=ni,v[3]=oi,v[4]=si,v[5]=ai,v[6]=li,v[7]=ui,v[8]=ci,v[9]=fi,v[10]=di,v[11]=hi,v[12]=pi,v[13]=mi,v[14]=gi,v[15]=_i,v[16]=wi,v[17]=vi,v[18]=Mi,k!==0&&(v[19]=k,l.length++),l};Math.imul||(R=N);function O(p,e,s){s.negative=e.negative^p.negative,s.length=p.length+e.length;for(var l=0,f=0,h=0;h<s.length-1;h++){var v=f;f=0;for(var k=l&67108863,w=Math.min(h,e.length-1),u=Math.max(0,h-p.length+1);u<=w;u++){var y=h-u,$=p.words[y]|0,U=e.words[u]|0,j=$*U,K=j&67108863;v=v+(j/67108864|0)|0,K=K+k|0,k=K&67108863,v=v+(K>>>26)|0,f+=v>>>26,v&=67108863}s.words[h]=k,l=v,v=f}return l!==0?s.words[h]=l:s.length--,s._strip()}function E(p,e,s){return O(p,e,s)}t.prototype.mulTo=function(e,s){var l,f=this.length+e.length;return this.length===10&&e.length===10?l=R(this,e,s):f<63?l=N(this,e,s):f<1024?l=O(this,e,s):l=E(this,e,s),l};function q(p,e){this.x=p,this.y=e}q.prototype.makeRBT=function(e){for(var s=new Array(e),l=t.prototype._countBits(e)-1,f=0;f<e;f++)s[f]=this.revBin(f,l,e);return s},q.prototype.revBin=function(e,s,l){if(e===0||e===l-1)return e;for(var f=0,h=0;h<s;h++)f|=(e&1)<<s-h-1,e>>=1;return f},q.prototype.permute=function(e,s,l,f,h,v){for(var k=0;k<v;k++)f[k]=s[e[k]],h[k]=l[e[k]]},q.prototype.transform=function(e,s,l,f,h,v){this.permute(v,e,s,l,f,h);for(var k=1;k<h;k<<=1)for(var w=k<<1,u=Math.cos(2*Math.PI/w),y=Math.sin(2*Math.PI/w),$=0;$<h;$+=w)for(var U=u,j=y,K=0;K<k;K++){var G=l[$+K],J=f[$+K],rt=l[$+K+k],V=f[$+K+k],it=U*rt-j*V;V=U*V+j*rt,rt=it,l[$+K]=G+rt,f[$+K]=J+V,l[$+K+k]=G-rt,f[$+K+k]=J-V,K!==w&&(it=u*U-y*j,j=u*j+y*U,U=it)}},q.prototype.guessLen13b=function(e,s){var l=Math.max(s,e)|1,f=l&1,h=0;for(l=l/2|0;l;l=l>>>1)h++;return 1<<h+1+f},q.prototype.conjugate=function(e,s,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=s[f],s[f]=-s[l-f-1],s[l-f-1]=-h}},q.prototype.normalize13b=function(e,s){for(var l=0,f=0;f<s/2;f++){var h=Math.round(e[2*f+1]/s)*8192+Math.round(e[2*f]/s)+l;e[f]=h&67108863,h<67108864?l=0:l=h/67108864|0}return e},q.prototype.convert13b=function(e,s,l,f){for(var h=0,v=0;v<s;v++)h=h+(e[v]|0),l[2*v]=h&8191,h=h>>>13,l[2*v+1]=h&8191,h=h>>>13;for(v=2*s;v<f;++v)l[v]=0;r(h===0),r((h&-8192)===0)},q.prototype.stub=function(e){for(var s=new Array(e),l=0;l<e;l++)s[l]=0;return s},q.prototype.mulp=function(e,s,l){var f=2*this.guessLen13b(e.length,s.length),h=this.makeRBT(f),v=this.stub(f),k=new Array(f),w=new Array(f),u=new Array(f),y=new Array(f),$=new Array(f),U=new Array(f),j=l.words;j.length=f,this.convert13b(e.words,e.length,k,f),this.convert13b(s.words,s.length,y,f),this.transform(k,v,w,u,f,h),this.transform(y,v,$,U,f,h);for(var K=0;K<f;K++){var G=w[K]*$[K]-u[K]*U[K];u[K]=w[K]*U[K]+u[K]*$[K],w[K]=G}return this.conjugate(w,u,f),this.transform(w,u,j,v,f,h),this.conjugate(j,v,f),this.normalize13b(j,f),l.negative=e.negative^s.negative,l.length=e.length+s.length,l._strip()},t.prototype.mul=function(e){var s=new t(null);return s.words=new Array(this.length+e.length),this.mulTo(e,s)},t.prototype.mulf=function(e){var s=new t(null);return s.words=new Array(this.length+e.length),E(this,e,s)},t.prototype.imul=function(e){return this.clone().mulTo(e,this)},t.prototype.imuln=function(e){var s=e<0;s&&(e=-e),r(typeof e=="number"),r(e<67108864);for(var l=0,f=0;f<this.length;f++){var h=(this.words[f]|0)*e,v=(h&67108863)+(l&67108863);l>>=26,l+=h/67108864|0,l+=v>>>26,this.words[f]=v&67108863}return l!==0&&(this.words[f]=l,this.length++),this.length=e===0?1:this.length,s?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 s=L(e);if(s.length===0)return new t(1);for(var l=this,f=0;f<s.length&&s[f]===0;f++,l=l.sqr());if(++f<s.length)for(var h=l.sqr();f<s.length;f++,h=h.sqr())s[f]!==0&&(l=l.mul(h));return l},t.prototype.iushln=function(e){r(typeof e=="number"&&e>=0);var s=e%26,l=(e-s)/26,f=67108863>>>26-s<<26-s,h;if(s!==0){var v=0;for(h=0;h<this.length;h++){var k=this.words[h]&f,w=(this.words[h]|0)-k<<s;this.words[h]=w|v,v=k>>>26-s}v&&(this.words[h]=v,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 r(this.negative===0),this.iushln(e)},t.prototype.iushrn=function(e,s,l){r(typeof e=="number"&&e>=0);var f;s?f=(s-s%26)/26:f=0;var h=e%26,v=Math.min((e-h)/26,this.length),k=67108863^67108863>>>h<<h,w=l;if(f-=v,f=Math.max(0,f),w){for(var u=0;u<v;u++)w.words[u]=this.words[u];w.length=v}if(v!==0)if(this.length>v)for(this.length-=v,u=0;u<this.length;u++)this.words[u]=this.words[u+v];else this.words[0]=0,this.length=1;var y=0;for(u=this.length-1;u>=0&&(y!==0||u>=f);u--){var $=this.words[u]|0;this.words[u]=y<<26-h|$>>>h,y=$&k}return w&&y!==0&&(w.words[w.length++]=y),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},t.prototype.ishrn=function(e,s,l){return r(this.negative===0),this.iushrn(e,s,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){r(typeof e=="number"&&e>=0);var s=e%26,l=(e-s)/26,f=1<<s;if(this.length<=l)return!1;var h=this.words[l];return!!(h&f)},t.prototype.imaskn=function(e){r(typeof e=="number"&&e>=0);var s=e%26,l=(e-s)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(s!==0&&l++,this.length=Math.min(l,this.length),s!==0){var f=67108863^67108863>>>s<<s;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 r(typeof e=="number"),r(e<67108864),e<0?this.isubn(-e):this.negative!==0?this.length===1&&(this.words[0]|0)<=e?(this.words[0]=e-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},t.prototype._iaddn=function(e){this.words[0]+=e;for(var s=0;s<this.length&&this.words[s]>=67108864;s++)this.words[s]-=67108864,s===this.length-1?this.words[s+1]=1:this.words[s+1]++;return this.length=Math.max(this.length,s+1),this},t.prototype.isubn=function(e){if(r(typeof e=="number"),r(e<67108864),e<0)return this.iaddn(-e);if(this.negative!==0)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var s=0;s<this.length&&this.words[s]<0;s++)this.words[s]+=67108864,this.words[s+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,s,l){var f=e.length+l,h;this._expand(f);var v,k=0;for(h=0;h<e.length;h++){v=(this.words[h+l]|0)+k;var w=(e.words[h]|0)*s;v-=w&67108863,k=(v>>26)-(w/67108864|0),this.words[h+l]=v&67108863}for(;h<this.length-l;h++)v=(this.words[h+l]|0)+k,k=v>>26,this.words[h+l]=v&67108863;if(k===0)return this._strip();for(r(k===-1),k=0,h=0;h<this.length;h++)v=-(this.words[h]|0)+k,k=v>>26,this.words[h]=v&67108863;return this.negative=1,this._strip()},t.prototype._wordDiv=function(e,s){var l=this.length-e.length,f=this.clone(),h=e,v=h.words[h.length-1]|0,k=this._countBits(v);l=26-k,l!==0&&(h=h.ushln(l),f.iushln(l),v=h.words[h.length-1]|0);var w=f.length-h.length,u;if(s!=="mod"){u=new t(null),u.length=w+1,u.words=new Array(u.length);for(var y=0;y<u.length;y++)u.words[y]=0}var $=f.clone()._ishlnsubmul(h,1,w);$.negative===0&&(f=$,u&&(u.words[w]=1));for(var U=w-1;U>=0;U--){var j=(f.words[h.length+U]|0)*67108864+(f.words[h.length+U-1]|0);for(j=Math.min(j/v|0,67108863),f._ishlnsubmul(h,j,U);f.negative!==0;)j--,f.negative=0,f._ishlnsubmul(h,1,U),f.isZero()||(f.negative^=1);u&&(u.words[U]=j)}return u&&u._strip(),f._strip(),s!=="div"&&l!==0&&f.iushrn(l),{div:u||null,mod:f}},t.prototype.divmod=function(e,s,l){if(r(!e.isZero()),this.isZero())return{div:new t(0),mod:new t(0)};var f,h,v;return this.negative!==0&&e.negative===0?(v=this.neg().divmod(e,s),s!=="mod"&&(f=v.div.neg()),s!=="div"&&(h=v.mod.neg(),l&&h.negative!==0&&h.iadd(e)),{div:f,mod:h}):this.negative===0&&e.negative!==0?(v=this.divmod(e.neg(),s),s!=="mod"&&(f=v.div.neg()),{div:f,mod:v.mod}):(this.negative&e.negative)!==0?(v=this.neg().divmod(e.neg(),s),s!=="div"&&(h=v.mod.neg(),l&&h.negative!==0&&h.isub(e)),{div:v.div,mod:h}):e.length>this.length||this.cmp(e)<0?{div:new t(0),mod:this}:e.length===1?s==="div"?{div:this.divn(e.words[0]),mod:null}:s==="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,s)},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 s=this.divmod(e);if(s.mod.isZero())return s.div;var l=s.div.negative!==0?s.mod.isub(e):s.mod,f=e.ushrn(1),h=e.andln(1),v=l.cmp(f);return v<0||h===1&&v===0?s.div:s.div.negative!==0?s.div.isubn(1):s.div.iaddn(1)},t.prototype.modrn=function(e){var s=e<0;s&&(e=-e),r(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 s?-f:f},t.prototype.modn=function(e){return this.modrn(e)},t.prototype.idivn=function(e){var s=e<0;s&&(e=-e),r(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(),s?this.ineg():this},t.prototype.divn=function(e){return this.clone().idivn(e)},t.prototype.egcd=function(e){r(e.negative===0),r(!e.isZero());var s=this,l=e.clone();s.negative!==0?s=s.umod(e):s=s.clone();for(var f=new t(1),h=new t(0),v=new t(0),k=new t(1),w=0;s.isEven()&&l.isEven();)s.iushrn(1),l.iushrn(1),++w;for(var u=l.clone(),y=s.clone();!s.isZero();){for(var $=0,U=1;(s.words[0]&U)===0&&$<26;++$,U<<=1);if($>0)for(s.iushrn($);$-- >0;)(f.isOdd()||h.isOdd())&&(f.iadd(u),h.isub(y)),f.iushrn(1),h.iushrn(1);for(var j=0,K=1;(l.words[0]&K)===0&&j<26;++j,K<<=1);if(j>0)for(l.iushrn(j);j-- >0;)(v.isOdd()||k.isOdd())&&(v.iadd(u),k.isub(y)),v.iushrn(1),k.iushrn(1);s.cmp(l)>=0?(s.isub(l),f.isub(v),h.isub(k)):(l.isub(s),v.isub(f),k.isub(h))}return{a:v,b:k,gcd:l.iushln(w)}},t.prototype._invmp=function(e){r(e.negative===0),r(!e.isZero());var s=this,l=e.clone();s.negative!==0?s=s.umod(e):s=s.clone();for(var f=new t(1),h=new t(0),v=l.clone();s.cmpn(1)>0&&l.cmpn(1)>0;){for(var k=0,w=1;(s.words[0]&w)===0&&k<26;++k,w<<=1);if(k>0)for(s.iushrn(k);k-- >0;)f.isOdd()&&f.iadd(v),f.iushrn(1);for(var u=0,y=1;(l.words[0]&y)===0&&u<26;++u,y<<=1);if(u>0)for(l.iushrn(u);u-- >0;)h.isOdd()&&h.iadd(v),h.iushrn(1);s.cmp(l)>=0?(s.isub(l),f.isub(h)):(l.isub(s),h.isub(f))}var $;return s.cmpn(1)===0?$=f:$=h,$.cmpn(0)<0&&$.iadd(e),$},t.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var s=this.clone(),l=e.clone();s.negative=0,l.negative=0;for(var f=0;s.isEven()&&l.isEven();f++)s.iushrn(1),l.iushrn(1);do{for(;s.isEven();)s.iushrn(1);for(;l.isEven();)l.iushrn(1);var h=s.cmp(l);if(h<0){var v=s;s=l,l=v}else if(h===0||l.cmpn(1)===0)break;s.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){r(typeof e=="number");var s=e%26,l=(e-s)/26,f=1<<s;if(this.length<=l)return this._expand(l+1),this.words[l]|=f,this;for(var h=f,v=l;h!==0&&v<this.length;v++){var k=this.words[v]|0;k+=h,h=k>>>26,k&=67108863,this.words[v]=k}return h!==0&&(this.words[v]=h,this.length++),this},t.prototype.isZero=function(){return this.length===1&&this.words[0]===0},t.prototype.cmpn=function(e){var s=e<0;if(this.negative!==0&&!s)return-1;if(this.negative===0&&s)return 1;this._strip();var l;if(this.length>1)l=1;else{s&&(e=-e),r(e<=67108863,"Number is too big");var f=this.words[0]|0;l=f===e?0:f<e?-1:1}return this.negative!==0?-l|0:l},t.prototype.cmp=function(e){if(this.negative!==0&&e.negative===0)return-1;if(this.negative===0&&e.negative!==0)return 1;var s=this.ucmp(e);return this.negative!==0?-s|0:s},t.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var s=0,l=this.length-1;l>=0;l--){var f=this.words[l]|0,h=e.words[l]|0;if(f!==h){f<h?s=-1:f>h&&(s=1);break}}return s},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 C(e)},t.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),e.convertTo(this)._forceRed(e)},t.prototype.fromRed=function(){return r(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 r(!this.red,"Already a number in reduction context"),this._forceRed(e)},t.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},t.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},t.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},t.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},t.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},t.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},t.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},t.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},t.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},t.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},t.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},t.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},t.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var W={k256:null,p224:null,p192:null,p25519:null};function F(p,e){this.name=p,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()}F.prototype._tmp=function(){var e=new t(null);return e.words=new Array(Math.ceil(this.n/13)),e},F.prototype.ireduce=function(e){var s=e,l;do this.split(s,this.tmp),s=this.imulK(s),s=s.iadd(this.tmp),l=s.bitLength();while(l>this.n);var f=l<this.n?-1:s.ucmp(this.p);return f===0?(s.words[0]=0,s.length=1):f>0?s.isub(this.p):s.strip!==void 0?s.strip():s._strip(),s},F.prototype.split=function(e,s){e.iushrn(this.n,0,s)},F.prototype.imulK=function(e){return e.imul(this.k)};function Z(){F.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}o(Z,F),Z.prototype.split=function(e,s){for(var l=4194303,f=Math.min(e.length,9),h=0;h<f;h++)s.words[h]=e.words[h];if(s.length=f,e.length<=9){e.words[0]=0,e.length=1;return}var v=e.words[9];for(s.words[s.length++]=v&l,h=10;h<e.length;h++){var k=e.words[h]|0;e.words[h-10]=(k&l)<<4|v>>>22,v=k}v>>>=22,e.words[h-10]=v,v===0&&e.length>10?e.length-=10:e.length-=9},Z.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var s=0,l=0;l<e.length;l++){var f=e.words[l]|0;s+=f*977,e.words[l]=s&67108863,s=f*64+(s/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function _(){F.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}o(_,F);function b(){F.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}o(b,F);function S(){F.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}o(S,F),S.prototype.imulK=function(e){for(var s=0,l=0;l<e.length;l++){var f=(e.words[l]|0)*19+s,h=f&67108863;f>>>=26,e.words[l]=h,s=f}return s!==0&&(e.words[e.length++]=s),e},t._prime=function(e){if(W[e])return W[e];var s;if(e==="k256")s=new Z;else if(e==="p224")s=new _;else if(e==="p192")s=new b;else if(e==="p25519")s=new S;else throw new Error("Unknown prime "+e);return W[e]=s,s};function C(p){if(typeof p=="string"){var e=t._prime(p);this.m=e.p,this.prime=e}else r(p.gtn(1),"modulus must be greater than 1"),this.m=p,this.prime=null}C.prototype._verify1=function(e){r(e.negative===0,"red works only with positives"),r(e.red,"red works only with red numbers")},C.prototype._verify2=function(e,s){r((e.negative|s.negative)===0,"red works only with positives"),r(e.red&&e.red===s.red,"red works only with red numbers")},C.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(g(e,e.umod(this.m)._forceRed(this)),e)},C.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},C.prototype.add=function(e,s){this._verify2(e,s);var l=e.add(s);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},C.prototype.iadd=function(e,s){this._verify2(e,s);var l=e.iadd(s);return l.cmp(this.m)>=0&&l.isub(this.m),l},C.prototype.sub=function(e,s){this._verify2(e,s);var l=e.sub(s);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},C.prototype.isub=function(e,s){this._verify2(e,s);var l=e.isub(s);return l.cmpn(0)<0&&l.iadd(this.m),l},C.prototype.shl=function(e,s){return this._verify1(e),this.imod(e.ushln(s))},C.prototype.imul=function(e,s){return this._verify2(e,s),this.imod(e.imul(s))},C.prototype.mul=function(e,s){return this._verify2(e,s),this.imod(e.mul(s))},C.prototype.isqr=function(e){return this.imul(e,e.clone())},C.prototype.sqr=function(e){return this.mul(e,e)},C.prototype.sqrt=function(e){if(e.isZero())return e.clone();var s=this.m.andln(3);if(r(s%2===1),s===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);r(!f.isZero());var v=new t(1).toRed(this),k=v.redNeg(),w=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new t(2*u*u).toRed(this);this.pow(u,w).cmp(k)!==0;)u.redIAdd(k);for(var y=this.pow(u,f),$=this.pow(e,f.addn(1).iushrn(1)),U=this.pow(e,f),j=h;U.cmp(v)!==0;){for(var K=U,G=0;K.cmp(v)!==0;G++)K=K.redSqr();r(G<j);var J=this.pow(y,new t(1).iushln(j-G-1));$=$.redMul(J),y=J.redSqr(),U=U.redMul(y),j=G}return $},C.prototype.invm=function(e){var s=e._invmp(this.m);return s.negative!==0?(s.negative=0,this.imod(s).redNeg()):this.imod(s)},C.prototype.pow=function(e,s){if(s.isZero())return new t(1).toRed(this);if(s.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 v=f[0],k=0,w=0,u=s.bitLength()%26;for(u===0&&(u=26),h=s.length-1;h>=0;h--){for(var y=s.words[h],$=u-1;$>=0;$--){var U=y>>$&1;if(v!==f[0]&&(v=this.sqr(v)),U===0&&k===0){w=0;continue}k<<=1,k|=U,w++,!(w!==l&&(h!==0||$!==0))&&(v=this.mul(v,f[k]),w=0,k=0)}u=26}return v},C.prototype.convertTo=function(e){var s=e.umod(this.m);return s===e?s.clone():s},C.prototype.convertFrom=function(e){var s=e.clone();return s.red=null,s},t.mont=function(e){return new x(e)};function x(p){C.call(this,p),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)}o(x,C),x.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},x.prototype.convertFrom=function(e){var s=this.imod(e.mul(this.rinv));return s.red=null,s},x.prototype.imul=function(e,s){if(e.isZero()||s.isZero())return e.words[0]=0,e.length=1,e;var l=e.imul(s),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).iushrn(this.shift),v=h;return h.cmp(this.m)>=0?v=h.isub(this.m):h.cmpn(0)<0&&(v=h.iadd(this.m)),v._forceRed(this)},x.prototype.mul=function(e,s){if(e.isZero()||s.isZero())return new t(0)._forceRed(this);var l=e.mul(s),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).iushrn(this.shift),v=h;return h.cmp(this.m)>=0?v=h.isub(this.m):h.cmpn(0)<0&&(v=h.iadd(this.m)),v._forceRed(this)},x.prototype.invm=function(e){var s=this.imod(e._invmp(this.m).mul(this.r2));return s._forceRed(this)}})(typeof Ui>"u"||Ui,Nr)});import{SuiClient as vo}from"@mysten/sui/client";import{normalizeSuiAddress as Mo}from"@mysten/sui/utils";import{SuiPriceServiceConnection as bo}from"@pythnetwork/pyth-sui-js";import{SdkWrapper as yo}from"@cetusprotocol/common-sdk";import{CetusClmmSDK as ko}from"@cetusprotocol/sui-clmm-sdk";import{AggregatorClient as So,Env as qr}from"@cetusprotocol/aggregator-sdk";import{FullRpcUrlMainnet as Hr}from"@cetusprotocol/common-sdk";var rr={full_rpc_url:Hr,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",margin_trading:{package_id:"0xd36d24553943160f960d3c0065cb6b77910328d23669233d304290b84e101400",published_at:"0xd36d24553943160f960d3c0065cb6b77910328d23669233d304290b84e101400",version:0,config:{versioned_id:"0x7408869c4ef21ea5e7027e2a49933954669862b707d5bec5c2741bf1297a6cc9",admin_cap_id:"0x621d93c68cc44043acea6c95dfbe1176ffb710e84ad78fe7e3fc4057f64596a2",global_config_id:"0x0627a2c9ddc7c8e39ae2946e0d51d80554d9e3857f3a7e0efafcc60e2ee10096",markets:"0x01f934d67fbd524ff1b9570531fecf198dcda1b41996c3ac8752cf7f1cc66420",markets_table_id:"0x999a28a63aab15342799909fb352d2a8c7a92adf061dbb14339cdd7ff6e23184"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{lending_market:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",owner_cap_id:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",owner_cap_id:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",is_hidden:!0}],lending_market_id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lending_market_type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",api_url:"https://d10td5ybgrf39v.cloudfront.net"}}};import{CACHE_TIME_5MIN as Yr,d as se,getPackagerConfigs as Le}from"@cetusprotocol/common-sdk";import{Transaction as Ne}from"@mysten/sui/transactions";import{addHexPrefix as nr,d as oe,getObjectFields as lr}from"@cetusprotocol/common-sdk";import{parseObligation as Vr}from"@suilend/sdk/parsers/obligation";import{getNetAprPercent as Xr,getTotalAprPercent as or,Side as sr,getFilteredRewards as ar}from"@suilend/sdk";var bi=n=>{let i=lr(n),{open_permissions_pause:r,close_permissions_pause:o,deposit_permissions_pause:t,withdraw_permissions_pause:a,borrow_permissions_pause:d,repay_permissions_pause:c}=Si(i.permissions.toString(2));return{market_id:i.id.id,base_token:nr(i.base_token.fields.name),quote_token:nr(i.quote_token.fields.name),max_long_leverage:oe(i.max_long_leverage).div(10**6).toString(),max_short_leverage:oe(i.max_short_leverage).div(10**6).toString(),open_fee_rate:oe(i.open_fee_rate).div(10**6).toString(),close_fee_rate:oe(i.close_fee_rate).div(10**6).toString(),open_permissions_pause:r,close_permissions_pause:o,deposit_permissions_pause:t,withdraw_permissions_pause:a,borrow_permissions_pause:d,repay_permissions_pause:c}},yi=(n,i)=>{let r=lr(n);return{created_at:r.created_ts,position_id:r.id.id,init_deposit_amount:r.init_deposit_amount,is_long:r.is_long,lending_market_id:r.lending_market_id,obligation_owner_cap:r.obligation_owner_cap.fields.obligation_id,market_id:r.market_id,position_cap_id:i}},ki=(n,i,r,o,t)=>{let a=Vr(i,r),d=Xr(a,t,o);if(!a.deposits||a.deposits.length===0)throw new Error("No deposits found in obligation data");let c=a.deposits[0],m=oe(c.reserve.config.closeLtvPct).div(100).toString(),g=oe(c.reserve.config.openLtvPct).div(100).toString(),M=a.depositedAmountUsd.gt(0)?a.borrowedAmountUsd.div(a.depositedAmountUsd).toString():"0",P=oe(1).div(m).toString(),A=oe(m).sub(M).toString(),D="0",T="0",L="0",N="0";if(a.borrows&&a.borrows.length>0){let R=a.borrows[0],O=t[R?.coinType];O&&(D=or(sr.BORROW,R?.reserve.borrowAprPercent,ar(O.borrow)).toString()),L=R.borrowedAmountUsd.toString(),N=R.borrowedAmount.toString()}if(a.deposits&&a.deposits.length>0){let R=a.deposits[0],O=t[R?.coinType];O&&(T=or(sr.DEPOSIT,R?.reserve.depositAprPercent,ar(O.deposit)).toString())}return{...n,...a,origin_obligation:i,net_apr_percent:d.toString(),supplied_apr:oe(T).toString(),borrowed_apr:oe(D).toString(),close_ltv:m,open_ltv:g,cr:M,ltr:P,liquidation_buffer:A,deposited_amount_usd:c.depositedAmountUsd.toString(),borrowed_amount_usd:L,deposited_amount:c.depositedAmount.toString(),borrowed_amount:N}},Si=n=>{let i=n.length,r=n.substring(i-1,i)==="0",o=n.substring(i-2,i-1)==="0",t=n.substring(i-3,i-2)==="0",a=n.substring(i-4,i-3)==="0",d=n.substring(i-5,i-4)==="0",c=n.substring(i-6,i-5)==="0";return{open_permissions_pause:r,close_permissions_pause:o,deposit_permissions_pause:t,withdraw_permissions_pause:d,borrow_permissions_pause:a,repay_permissions_pause:c}};import{getFilteredRewards as he,getStakingYieldAprPercent as ur,getTotalAprPercent as Ie,Side as Se}from"@suilend/sdk";import{BaseError as Jr}from"@cetusprotocol/common-sdk";var Re=class extends Jr{constructor(i,r,o){super(i,r||"UnknownError",o)}static isCrossSwapErrorCode(i,r){return this.isErrorCode(i,r)}},Gt=(n,i,r)=>{let o={...r,stack:i instanceof Error?i.stack:void 0};throw i instanceof Error?new Re(i.message,n,o):new Re(i,n,o)};var Ee=class{constructor(i){this.createMarket=async i=>{let{package_id:r}=this._sdk.sdkOptions.margin_trading,{versioned_id:o,admin_cap_id:t,markets:a,global_config_id:d}=Le(this._sdk.sdkOptions.margin_trading),c=new Ne;return c.moveCall({target:`${r}::market::create_market`,arguments:[c.object(t),c.object(d),c.object(a),c.pure.u64(i.open_fee_rate),c.pure.u64(i.close_fee_rate),c.object(o)],typeArguments:[i.base_token,i.quote_token]}),c};this.updateMarketFeeRate=async i=>{let{package_id:r}=this._sdk.sdkOptions.margin_trading,{versioned_id:o,admin_cap_id:t}=Le(this._sdk.sdkOptions.margin_trading),{market_id:a,open_fee_rate:d,close_fee_rate:c}=i,m=new Ne;return m.moveCall({target:`${r}::market::set_fee_rate`,arguments:[m.object(t),m.object(a),m.pure.u64(d),m.pure.u64(c),m.object(o)],typeArguments:[]}),m};this.claimMarketFees=async(i,r)=>{let{package_id:o}=this._sdk.sdkOptions.margin_trading,{versioned_id:t,admin_cap_id:a}=Le(this._sdk.sdkOptions.margin_trading),d=r||new Ne,{base_token:c,quote_token:m}=await this._sdk.MarketModules.getMarketInfo(i);return d.moveCall({target:`${o}::market::claim_fees`,arguments:[d.object(a),d.object(i),d.object(t)],typeArguments:[c,m]}),d};this.claimAllMarketFees=async i=>{let r=new Ne;for(let o=0;o<i.length;o++){let t=i[o];this.claimMarketFees(t,r)}return r};this.getMarginTradingConfig=async()=>{let{package_id:i}=this._sdk.sdkOptions.margin_trading;try{let r=await this._sdk.FullClient.queryEventsByPage({MoveEventType:`${i}::versioned::InitEvent`}),o=await this._sdk.FullClient.queryEventsByPage({MoveEventType:`${i}::admin_cap::InitEvent`}),t=await this._sdk.FullClient.queryEventsByPage({MoveEventType:`${i}::config::InitEvent`}),d=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:`${i}::market::InitEvent`})).data[0].parsedJson.markets_id,m=(await this._sdk.FullClient.getObject({id:d,options:{showContent:!0}})).data.content.fields.list.fields.id.id;return{versioned_id:r.data[0].parsedJson.versioned_id,admin_cap_id:o.data[0].parsedJson.admin_cap_id,global_config_id:t.data[0].parsedJson.global_config_id,markets:d,markets_table_id:m}}catch(r){return Gt("FetchError",r),{versioned_id:"",admin_cap_id:"",global_config_id:"",markets_table_id:"",markets:""}}};this.getMarketList=async(i=!1)=>{let o=this._sdk.getCache("margin_trading_markets_list",i);if(o)return o;let{package_id:t}=this._sdk.sdkOptions.margin_trading,a=[];try{let d=`${t}::market::CreateMarketEvent`,m=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:d})).data.map(g=>g.parsedJson.market_id);return m.length>0?((await this._sdk.FullClient.batchGetObjects(m,{showContent:!0,showType:!0})).forEach(M=>{let P=bi(M),A=`margin_trading_market_info_${P.market_id}`;this._sdk.updateCache(A,P),a.push(P)}),a):(Gt("MarketNotFound","Market not found"),[])}catch(d){return Gt("FetchError",d),[]}};this.getMarketInfo=async(i,r=!1)=>{let o=`margin_trading_market_info_${i}`,t=this._sdk.getCache(o,r);if(t)return t;try{let a=await this._sdk.FullClient.getObject({id:i,options:{showContent:!0}}),d=bi(a);return this._sdk.updateCache(o,d,Yr),d}catch(a){return Gt("FetchError",a),{}}};this.getMarketSuilendInfo=async i=>{try{let{base_token:r,quote_token:o}=await this.getMarketInfo(i),{lending_market_id:t}=Le(this._sdk.sdkOptions.suilend),{allLendingMarketData:a,lstAprPercentMap:d}=await this._sdk.SuiLendModule.getLendingMarketData(!0),{base_reserve_map_info:c,quote_reserve_map_info:m}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(r,o,a);console.log("\u{1F680}\u{1F680}\u{1F680} ~ marketModules.ts:188 ~ MarketModules ~ base_reserve_map_info:",c);let g=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:a,lstAprPercentMap:d},!0),M=g[t].rewardMap[r],P=g[t].rewardMap[o],{depositedAmountUsd:A,borrowedAmountUsd:D,depositAprPercent:T,borrowAprPercent:L,depositedAmount:N,borrowedAmount:R}=c,{depositLimit:O,borrowLimit:E}=c.config,{depositedAmountUsd:q,borrowedAmountUsd:W,depositAprPercent:F,borrowAprPercent:Z,depositedAmount:_,borrowedAmount:b}=m,{depositLimit:S,borrowLimit:C}=m.config,x=Ie(Se.DEPOSIT,T,he(M.deposit),ur(Se.DEPOSIT,r,d)),p=Ie(Se.BORROW,L,he(M.borrow)),e=Ie(Se.DEPOSIT,F,he(P.deposit),ur(Se.DEPOSIT,r,d)),s=Ie(Se.BORROW,Z,he(P.borrow)),l=se(q.toString()).sub(W.toString()).toString(),f=se(A.toString()).sub(D.toString()).toString(),h=se(O.toString()).sub(se(N.toString())).toString(),v=se(E.toString()).sub(se(R.toString())).toString(),k=se(S.toString()).sub(se(_.toString())).toString(),w=se(C.toString()).sub(se(b.toString())).toString();return{long_liquidity:l,short_liquidity:f,base_total_deposit_apr_percent:x.toString(),base_total_borrow_apr_percent:p.toString(),quote_total_deposit_apr_percent:e.toString(),quote_total_borrow_apr_percent:s.toString(),base_token_available_deposit_amount:h,base_token_available_borrow_amount:v,quote_token_available_deposit_amount:k,quote_token_available_borrow_amount:w,base_deposit_rewards:he(M.deposit),quote_deposit_rewards:he(P.deposit),base_borrow_rewards:he(M.borrow),quote_borrow_rewards:he(P.borrow),base_deposit_apr_percent:T.toString(),base_borrow_apr_percent:L.toString(),quote_deposit_apr_percent:F.toString(),quote_borrow_apr_percent:Z.toString(),obligations:g[t],base_reserve_map_info:c,quote_reserve_map_info:m}}catch(r){return Gt("FetchError",r),{}}};this._sdk=i}};import{CLOCK_ADDRESS as Pe,getPackagerConfigs as Jt}from"@cetusprotocol/common-sdk";import{Transaction as Ht}from"@mysten/sui/transactions";var Be=class{constructor(i){this.queryGlobalPermissions=async()=>{let i=this._sdk.sdkOptions.margin_trading,{global_config_id:r}=Jt(i),o=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}});if(o){let t=o.data.content.fields.permissions.toString(2),{open_permissions_pause:a,close_permissions_pause:d,deposit_permissions_pause:c,withdraw_permissions_pause:m,borrow_permissions_pause:g,repay_permissions_pause:M}=Si(t);return{open_permissions_pause:a,close_permissions_pause:d,deposit_permissions_pause:c,withdraw_permissions_pause:m,borrow_permissions_pause:g,repay_permissions_pause:M}}};this.updateGlobalPermissions=async i=>{let r=new Ht;return this.updateGlobalOpenPositionPermissions(i,r),this.updateGlobalClosePositionPermissions(i,r),this.updateGlobalDepositPermissions(i,r),this.updateGlobalBorrowPermissions(i,r),this.updateGlobalWithdrawPermissions(i,r),this.updateGlobalRepayPermissions(i,r),r};this.updateGlobalOpenPositionPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_open_position_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalClosePositionPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_close_position_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalDepositPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_deposit_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalBorrowPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_borrow_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalWithdrawPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_withdraw_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateGlobalRepayPermissions=async(i,r)=>{let o=this._sdk.sdkOptions.margin_trading,{global_config_id:t,versioned_id:a,admin_cap_id:d}=Jt(o),c=r||new Ht;return c.moveCall({target:`${o.published_at}::config::update_global_repay_permissions`,arguments:[c.object(d),c.object(t),c.pure.bool(i),c.object(Pe),c.object(a)],typeArguments:[]}),c};this.updateMarketCreatePositionPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_open_position_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketClosePositionPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_close_position_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketDepositPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_deposit_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketWithdrawPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_withdraw_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketBorrowPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_borrow_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketRepayPermissions=async(i,r,o)=>{let t=this._sdk.sdkOptions.margin_trading,{versioned_id:a,admin_cap_id:d}=Jt(t),c=o||new Ht;return c.moveCall({target:`${t.published_at}::market::update_market_repay_permission`,arguments:[c.object(d),c.object(i),c.pure.bool(r),c.object(a)],typeArguments:[]}),c};this.updateMarketPermissions=async(i,r,o)=>{let t=o||new Ht;return this.updateMarketCreatePositionPermissions(i,r,t),this.updateMarketClosePositionPermissions(i,r,t),this.updateMarketDepositPermissions(i,r,t),this.updateMarketWithdrawPermissions(i,r,t),this.updateMarketBorrowPermissions(i,r,t),this.updateMarketRepayPermissions(i,r,t),t};this._sdk=i}};import{CACHE_TIME_24H as Vn,CLOCK_ADDRESS as be,CoinAssist as Q,d as I,getObjectFields as Ar,getPackagerConfigs as jt,removeHexPrefix as xe,SUI_SYSTEM_STATE_OBJECT_ID as Cr,U64_MAX as Ni}from"@cetusprotocol/common-sdk";var Qr=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Ai=Math.ceil,Qt=Math.floor,Vt="[BigNumber Error] ",cr=Vt+"Number primitive has more than 15 significant digits: ",ie=1e14,tt=14,Ci=9007199254740991,xi=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],pe=1e7,Wt=1e9;function fr(n){var i,r,o,t=O.prototype={constructor:O,toString:null,valueOf:null},a=new O(1),d=20,c=4,m=-7,g=21,M=-1e7,P=1e7,A=!1,D=1,T=0,L={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},N="0123456789abcdefghijklmnopqrstuvwxyz",R=!0;function O(_,b){var S,C,x,p,e,s,l,f,h=this;if(!(h instanceof O))return new O(_,b);if(b==null){if(_&&_._isBigNumber===!0){h.s=_.s,!_.c||_.e>P?h.c=h.e=null:_.e<M?h.c=[h.e=0]:(h.e=_.e,h.c=_.c.slice());return}if((s=typeof _=="number")&&_*0==0){if(h.s=1/_<0?(_=-_,-1):1,_===~~_){for(p=0,e=_;e>=10;e/=10,p++);p>P?h.c=h.e=null:(h.e=p,h.c=[_]);return}f=String(_)}else{if(!Qr.test(f=String(_)))return o(h,f,s);h.s=f.charCodeAt(0)==45?(f=f.slice(1),-1):1}(p=f.indexOf("."))>-1&&(f=f.replace(".","")),(e=f.search(/e/i))>0?(p<0&&(p=e),p+=+f.slice(e+1),f=f.substring(0,e)):p<0&&(p=f.length)}else{if(ft(b,2,N.length,"Base"),b==10&&R)return h=new O(_),F(h,d+h.e+1,c);if(f=String(_),s=typeof _=="number"){if(_*0!=0)return o(h,f,s,b);if(h.s=1/_<0?(f=f.slice(1),-1):1,O.DEBUG&&f.replace(/^0\.0*|\./,"").length>15)throw Error(cr+_)}else h.s=f.charCodeAt(0)===45?(f=f.slice(1),-1):1;for(S=N.slice(0,b),p=e=0,l=f.length;e<l;e++)if(S.indexOf(C=f.charAt(e))<0){if(C=="."){if(e>p){p=l;continue}}else if(!x&&(f==f.toUpperCase()&&(f=f.toLowerCase())||f==f.toLowerCase()&&(f=f.toUpperCase()))){x=!0,e=-1,p=0;continue}return o(h,String(_),s,b)}s=!1,f=r(f,b,10,h.s),(p=f.indexOf("."))>-1?f=f.replace(".",""):p=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,s&&O.DEBUG&&l>15&&(_>Ci||_!==Qt(_)))throw Error(cr+h.s*_);if((p=p-e-1)>P)h.c=h.e=null;else if(p<M)h.c=[h.e=0];else{if(h.e=p,h.c=[],e=(p+1)%tt,p<0&&(e+=tt),e<l){for(e&&h.c.push(+f.slice(0,e)),l-=tt;e<l;)h.c.push(+f.slice(e,e+=tt));e=tt-(f=f.slice(e)).length}else e-=l;for(;e--;f+="0");h.c.push(+f)}}else h.c=[h.e=0]}O.clone=fr,O.ROUND_UP=0,O.ROUND_DOWN=1,O.ROUND_CEIL=2,O.ROUND_FLOOR=3,O.ROUND_HALF_UP=4,O.ROUND_HALF_DOWN=5,O.ROUND_HALF_EVEN=6,O.ROUND_HALF_CEIL=7,O.ROUND_HALF_FLOOR=8,O.EUCLID=9,O.config=O.set=function(_){var b,S;if(_!=null)if(typeof _=="object"){if(_.hasOwnProperty(b="DECIMAL_PLACES")&&(S=_[b],ft(S,0,Wt,b),d=S),_.hasOwnProperty(b="ROUNDING_MODE")&&(S=_[b],ft(S,0,8,b),c=S),_.hasOwnProperty(b="EXPONENTIAL_AT")&&(S=_[b],S&&S.pop?(ft(S[0],-Wt,0,b),ft(S[1],0,Wt,b),m=S[0],g=S[1]):(ft(S,-Wt,Wt,b),m=-(g=S<0?-S:S))),_.hasOwnProperty(b="RANGE"))if(S=_[b],S&&S.pop)ft(S[0],-Wt,-1,b),ft(S[1],1,Wt,b),M=S[0],P=S[1];else if(ft(S,-Wt,Wt,b),S)M=-(P=S<0?-S:S);else throw Error(Vt+b+" cannot be zero: "+S);if(_.hasOwnProperty(b="CRYPTO"))if(S=_[b],S===!!S)if(S)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))A=S;else throw A=!S,Error(Vt+"crypto unavailable");else A=S;else throw Error(Vt+b+" not true or false: "+S);if(_.hasOwnProperty(b="MODULO_MODE")&&(S=_[b],ft(S,0,9,b),D=S),_.hasOwnProperty(b="POW_PRECISION")&&(S=_[b],ft(S,0,Wt,b),T=S),_.hasOwnProperty(b="FORMAT"))if(S=_[b],typeof S=="object")L=S;else throw Error(Vt+b+" not an object: "+S);if(_.hasOwnProperty(b="ALPHABET"))if(S=_[b],typeof S=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(S))R=S.slice(0,10)=="0123456789",N=S;else throw Error(Vt+b+" invalid: "+S)}else throw Error(Vt+"Object expected: "+_);return{DECIMAL_PLACES:d,ROUNDING_MODE:c,EXPONENTIAL_AT:[m,g],RANGE:[M,P],CRYPTO:A,MODULO_MODE:D,POW_PRECISION:T,FORMAT:L,ALPHABET:N}},O.isBigNumber=function(_){if(!_||_._isBigNumber!==!0)return!1;if(!O.DEBUG)return!0;var b,S,C=_.c,x=_.e,p=_.s;t:if({}.toString.call(C)=="[object Array]"){if((p===1||p===-1)&&x>=-Wt&&x<=Wt&&x===Qt(x)){if(C[0]===0){if(x===0&&C.length===1)return!0;break t}if(b=(x+1)%tt,b<1&&(b+=tt),String(C[0]).length==b){for(b=0;b<C.length;b++)if(S=C[b],S<0||S>=ie||S!==Qt(S))break t;if(S!==0)return!0}}}else if(C===null&&x===null&&(p===null||p===1||p===-1))return!0;throw Error(Vt+"Invalid BigNumber: "+_)},O.maximum=O.max=function(){return q(arguments,-1)},O.minimum=O.min=function(){return q(arguments,1)},O.random=(function(){var _=9007199254740992,b=Math.random()*_&2097151?function(){return Qt(Math.random()*_)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(S){var C,x,p,e,s,l=0,f=[],h=new O(a);if(S==null?S=d:ft(S,0,Wt),e=Ai(S/tt),A)if(crypto.getRandomValues){for(C=crypto.getRandomValues(new Uint32Array(e*=2));l<e;)s=C[l]*131072+(C[l+1]>>>11),s>=9e15?(x=crypto.getRandomValues(new Uint32Array(2)),C[l]=x[0],C[l+1]=x[1]):(f.push(s%1e14),l+=2);l=e/2}else if(crypto.randomBytes){for(C=crypto.randomBytes(e*=7);l<e;)s=(C[l]&31)*281474976710656+C[l+1]*1099511627776+C[l+2]*4294967296+C[l+3]*16777216+(C[l+4]<<16)+(C[l+5]<<8)+C[l+6],s>=9e15?crypto.randomBytes(7).copy(C,l):(f.push(s%1e14),l+=7);l=e/7}else throw A=!1,Error(Vt+"crypto unavailable");if(!A)for(;l<e;)s=b(),s<9e15&&(f[l++]=s%1e14);for(e=f[--l],S%=tt,e&&S&&(s=xi[tt-S],f[l]=Qt(e/s)*s);f[l]===0;f.pop(),l--);if(l<0)f=[p=0];else{for(p=-1;f[0]===0;f.splice(0,1),p-=tt);for(l=1,s=f[0];s>=10;s/=10,l++);l<tt&&(p-=tt-l)}return h.e=p,h.c=f,h}})(),O.sum=function(){for(var _=1,b=arguments,S=new O(b[0]);_<b.length;)S=S.plus(b[_++]);return S},r=(function(){var _="0123456789";function b(S,C,x,p){for(var e,s=[0],l,f=0,h=S.length;f<h;){for(l=s.length;l--;s[l]*=C);for(s[0]+=p.indexOf(S.charAt(f++)),e=0;e<s.length;e++)s[e]>x-1&&(s[e+1]==null&&(s[e+1]=0),s[e+1]+=s[e]/x|0,s[e]%=x)}return s.reverse()}return function(S,C,x,p,e){var s,l,f,h,v,k,w,u,y=S.indexOf("."),$=d,U=c;for(y>=0&&(h=T,T=0,S=S.replace(".",""),u=new O(C),k=u.pow(S.length-y),T=h,u.c=b(ce(Yt(k.c),k.e,"0"),10,x,_),u.e=u.c.length),w=b(S,C,x,e?(s=N,_):(s=_,N)),f=h=w.length;w[--h]==0;w.pop());if(!w[0])return s.charAt(0);if(y<0?--f:(k.c=w,k.e=f,k.s=p,k=i(k,u,$,U,x),w=k.c,v=k.r,f=k.e),l=f+$+1,y=w[l],h=x/2,v=v||l<0||w[l+1]!=null,v=U<4?(y!=null||v)&&(U==0||U==(k.s<0?3:2)):y>h||y==h&&(U==4||v||U==6&&w[l-1]&1||U==(k.s<0?8:7)),l<1||!w[0])S=v?ce(s.charAt(1),-$,s.charAt(0)):s.charAt(0);else{if(w.length=l,v)for(--x;++w[--l]>x;)w[l]=0,l||(++f,w=[1].concat(w));for(h=w.length;!w[--h];);for(y=0,S="";y<=h;S+=s.charAt(w[y++]));S=ce(S,f,s.charAt(0))}return S}})(),i=(function(){function _(C,x,p){var e,s,l,f,h=0,v=C.length,k=x%pe,w=x/pe|0;for(C=C.slice();v--;)l=C[v]%pe,f=C[v]/pe|0,e=w*l+f*k,s=k*l+e%pe*pe+h,h=(s/p|0)+(e/pe|0)+w*f,C[v]=s%p;return h&&(C=[h].concat(C)),C}function b(C,x,p,e){var s,l;if(p!=e)l=p>e?1:-1;else for(s=l=0;s<p;s++)if(C[s]!=x[s]){l=C[s]>x[s]?1:-1;break}return l}function S(C,x,p,e){for(var s=0;p--;)C[p]-=s,s=C[p]<x[p]?1:0,C[p]=s*e+C[p]-x[p];for(;!C[0]&&C.length>1;C.splice(0,1));}return function(C,x,p,e,s){var l,f,h,v,k,w,u,y,$,U,j,K,G,J,rt,V,it,ut=C.s==x.s?1:-1,et=C.c,X=x.c;if(!et||!et[0]||!X||!X[0])return new O(!C.s||!x.s||(et?X&&et[0]==X[0]:!X)?NaN:et&&et[0]==0||!X?ut*0:ut/0);for(y=new O(ut),$=y.c=[],f=C.e-x.e,ut=p+f+1,s||(s=ie,f=te(C.e/tt)-te(x.e/tt),ut=ut/tt|0),h=0;X[h]==(et[h]||0);h++);if(X[h]>(et[h]||0)&&f--,ut<0)$.push(1),v=!0;else{for(J=et.length,V=X.length,h=0,ut+=2,k=Qt(s/(X[0]+1)),k>1&&(X=_(X,k,s),et=_(et,k,s),V=X.length,J=et.length),G=V,U=et.slice(0,V),j=U.length;j<V;U[j++]=0);it=X.slice(),it=[0].concat(it),rt=X[0],X[1]>=s/2&&rt++;do{if(k=0,l=b(X,U,V,j),l<0){if(K=U[0],V!=j&&(K=K*s+(U[1]||0)),k=Qt(K/rt),k>1)for(k>=s&&(k=s-1),w=_(X,k,s),u=w.length,j=U.length;b(w,U,u,j)==1;)k--,S(w,V<u?it:X,u,s),u=w.length,l=1;else k==0&&(l=k=1),w=X.slice(),u=w.length;if(u<j&&(w=[0].concat(w)),S(U,w,j,s),j=U.length,l==-1)for(;b(X,U,V,j)<1;)k++,S(U,V<j?it:X,j,s),j=U.length}else l===0&&(k++,U=[0]);$[h++]=k,U[0]?U[j++]=et[G]||0:(U=[et[G]],j=1)}while((G++<J||U[0]!=null)&&ut--);v=U[0]!=null,$[0]||$.splice(0,1)}if(s==ie){for(h=1,ut=$[0];ut>=10;ut/=10,h++);F(y,p+(y.e=h+f*tt-1)+1,e,v)}else y.e=f,y.r=+v;return y}})();function E(_,b,S,C){var x,p,e,s,l;if(S==null?S=c:ft(S,0,8),!_.c)return _.toString();if(x=_.c[0],e=_.e,b==null)l=Yt(_.c),l=C==1||C==2&&(e<=m||e>=g)?Fe(l,e):ce(l,e,"0");else if(_=F(new O(_),b,S),p=_.e,l=Yt(_.c),s=l.length,C==1||C==2&&(b<=p||p<=m)){for(;s<b;l+="0",s++);l=Fe(l,p)}else if(b-=e+(C===2&&p>e),l=ce(l,p,"0"),p+1>s){if(--b>0)for(l+=".";b--;l+="0");}else if(b+=p-s,b>0)for(p+1==s&&(l+=".");b--;l+="0");return _.s<0&&x?"-"+l:l}function q(_,b){for(var S,C,x=1,p=new O(_[0]);x<_.length;x++)C=new O(_[x]),(!C.s||(S=Me(p,C))===b||S===0&&p.s===b)&&(p=C);return p}function W(_,b,S){for(var C=1,x=b.length;!b[--x];b.pop());for(x=b[0];x>=10;x/=10,C++);return(S=C+S*tt-1)>P?_.c=_.e=null:S<M?_.c=[_.e=0]:(_.e=S,_.c=b),_}o=(function(){var _=/^(-?)0([xbo])(?=\w[\w.]*$)/i,b=/^([^.]+)\.$/,S=/^\.([^.]+)$/,C=/^-?(Infinity|NaN)$/,x=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(p,e,s,l){var f,h=s?e:e.replace(x,"");if(C.test(h))p.s=isNaN(h)?null:h<0?-1:1;else{if(!s&&(h=h.replace(_,function(v,k,w){return f=(w=w.toLowerCase())=="x"?16:w=="b"?2:8,!l||l==f?k:v}),l&&(f=l,h=h.replace(b,"$1").replace(S,"0.$1")),e!=h))return new O(h,f);if(O.DEBUG)throw Error(Vt+"Not a"+(l?" base "+l:"")+" number: "+e);p.s=null}p.c=p.e=null}})();function F(_,b,S,C){var x,p,e,s,l,f,h,v=_.c,k=xi;if(v){t:{for(x=1,s=v[0];s>=10;s/=10,x++);if(p=b-x,p<0)p+=tt,e=b,l=v[f=0],h=Qt(l/k[x-e-1]%10);else if(f=Ai((p+1)/tt),f>=v.length)if(C){for(;v.length<=f;v.push(0));l=h=0,x=1,p%=tt,e=p-tt+1}else break t;else{for(l=s=v[f],x=1;s>=10;s/=10,x++);p%=tt,e=p-tt+x,h=e<0?0:Qt(l/k[x-e-1]%10)}if(C=C||b<0||v[f+1]!=null||(e<0?l:l%k[x-e-1]),C=S<4?(h||C)&&(S==0||S==(_.s<0?3:2)):h>5||h==5&&(S==4||C||S==6&&(p>0?e>0?l/k[x-e]:0:v[f-1])%10&1||S==(_.s<0?8:7)),b<1||!v[0])return v.length=0,C?(b-=_.e+1,v[0]=k[(tt-b%tt)%tt],_.e=-b||0):v[0]=_.e=0,_;if(p==0?(v.length=f,s=1,f--):(v.length=f+1,s=k[tt-p],v[f]=e>0?Qt(l/k[x-e]%k[e])*s:0),C)for(;;)if(f==0){for(p=1,e=v[0];e>=10;e/=10,p++);for(e=v[0]+=s,s=1;e>=10;e/=10,s++);p!=s&&(_.e++,v[0]==ie&&(v[0]=1));break}else{if(v[f]+=s,v[f]!=ie)break;v[f--]=0,s=1}for(p=v.length;v[--p]===0;v.pop());}_.e>P?_.c=_.e=null:_.e<M&&(_.c=[_.e=0])}return _}function Z(_){var b,S=_.e;return S===null?_.toString():(b=Yt(_.c),b=S<=m||S>=g?Fe(b,S):ce(b,S,"0"),_.s<0?"-"+b:b)}return t.absoluteValue=t.abs=function(){var _=new O(this);return _.s<0&&(_.s=1),_},t.comparedTo=function(_,b){return Me(this,new O(_,b))},t.decimalPlaces=t.dp=function(_,b){var S,C,x,p=this;if(_!=null)return ft(_,0,Wt),b==null?b=c:ft(b,0,8),F(new O(p),_+p.e+1,b);if(!(S=p.c))return null;if(C=((x=S.length-1)-te(this.e/tt))*tt,x=S[x])for(;x%10==0;x/=10,C--);return C<0&&(C=0),C},t.dividedBy=t.div=function(_,b){return i(this,new O(_,b),d,c)},t.dividedToIntegerBy=t.idiv=function(_,b){return i(this,new O(_,b),0,1)},t.exponentiatedBy=t.pow=function(_,b){var S,C,x,p,e,s,l,f,h,v=this;if(_=new O(_),_.c&&!_.isInteger())throw Error(Vt+"Exponent not an integer: "+Z(_));if(b!=null&&(b=new O(b)),s=_.e>14,!v.c||!v.c[0]||v.c[0]==1&&!v.e&&v.c.length==1||!_.c||!_.c[0])return h=new O(Math.pow(+Z(v),s?_.s*(2-qe(_)):+Z(_))),b?h.mod(b):h;if(l=_.s<0,b){if(b.c?!b.c[0]:!b.s)return new O(NaN);C=!l&&v.isInteger()&&b.isInteger(),C&&(v=v.mod(b))}else{if(_.e>9&&(v.e>0||v.e<-1||(v.e==0?v.c[0]>1||s&&v.c[1]>=24e7:v.c[0]<8e13||s&&v.c[0]<=9999975e7)))return p=v.s<0&&qe(_)?-0:0,v.e>-1&&(p=1/p),new O(l?1/p:p);T&&(p=Ai(T/tt+2))}for(s?(S=new O(.5),l&&(_.s=1),f=qe(_)):(x=Math.abs(+Z(_)),f=x%2),h=new O(a);;){if(f){if(h=h.times(v),!h.c)break;p?h.c.length>p&&(h.c.length=p):C&&(h=h.mod(b))}if(x){if(x=Qt(x/2),x===0)break;f=x%2}else if(_=_.times(S),F(_,_.e+1,1),_.e>14)f=qe(_);else{if(x=+Z(_),x===0)break;f=x%2}v=v.times(v),p?v.c&&v.c.length>p&&(v.c.length=p):C&&(v=v.mod(b))}return C?h:(l&&(h=a.div(h)),b?h.mod(b):p?F(h,T,c,e):h)},t.integerValue=function(_){var b=new O(this);return _==null?_=c:ft(_,0,8),F(b,b.e+1,_)},t.isEqualTo=t.eq=function(_,b){return Me(this,new O(_,b))===0},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(_,b){return Me(this,new O(_,b))>0},t.isGreaterThanOrEqualTo=t.gte=function(_,b){return(b=Me(this,new O(_,b)))===1||b===0},t.isInteger=function(){return!!this.c&&te(this.e/tt)>this.c.length-2},t.isLessThan=t.lt=function(_,b){return Me(this,new O(_,b))<0},t.isLessThanOrEqualTo=t.lte=function(_,b){return(b=Me(this,new O(_,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(_,b){var S,C,x,p,e=this,s=e.s;if(_=new O(_,b),b=_.s,!s||!b)return new O(NaN);if(s!=b)return _.s=-b,e.plus(_);var l=e.e/tt,f=_.e/tt,h=e.c,v=_.c;if(!l||!f){if(!h||!v)return h?(_.s=-b,_):new O(v?e:NaN);if(!h[0]||!v[0])return v[0]?(_.s=-b,_):new O(h[0]?e:c==3?-0:0)}if(l=te(l),f=te(f),h=h.slice(),s=l-f){for((p=s<0)?(s=-s,x=h):(f=l,x=v),x.reverse(),b=s;b--;x.push(0));x.reverse()}else for(C=(p=(s=h.length)<(b=v.length))?s:b,s=b=0;b<C;b++)if(h[b]!=v[b]){p=h[b]<v[b];break}if(p&&(x=h,h=v,v=x,_.s=-_.s),b=(C=v.length)-(S=h.length),b>0)for(;b--;h[S++]=0);for(b=ie-1;C>s;){if(h[--C]<v[C]){for(S=C;S&&!h[--S];h[S]=b);--h[S],h[C]+=ie}h[C]-=v[C]}for(;h[0]==0;h.splice(0,1),--f);return h[0]?W(_,h,f):(_.s=c==3?-1:1,_.c=[_.e=0],_)},t.modulo=t.mod=function(_,b){var S,C,x=this;return _=new O(_,b),!x.c||!_.s||_.c&&!_.c[0]?new O(NaN):!_.c||x.c&&!x.c[0]?new O(x):(D==9?(C=_.s,_.s=1,S=i(x,_,0,3),_.s=C,S.s*=C):S=i(x,_,0,D),_=x.minus(S.times(_)),!_.c[0]&&D==1&&(_.s=x.s),_)},t.multipliedBy=t.times=function(_,b){var S,C,x,p,e,s,l,f,h,v,k,w,u,y,$,U=this,j=U.c,K=(_=new O(_,b)).c;if(!j||!K||!j[0]||!K[0])return!U.s||!_.s||j&&!j[0]&&!K||K&&!K[0]&&!j?_.c=_.e=_.s=null:(_.s*=U.s,!j||!K?_.c=_.e=null:(_.c=[0],_.e=0)),_;for(C=te(U.e/tt)+te(_.e/tt),_.s*=U.s,l=j.length,v=K.length,l<v&&(u=j,j=K,K=u,x=l,l=v,v=x),x=l+v,u=[];x--;u.push(0));for(y=ie,$=pe,x=v;--x>=0;){for(S=0,k=K[x]%$,w=K[x]/$|0,e=l,p=x+e;p>x;)f=j[--e]%$,h=j[e]/$|0,s=w*f+h*k,f=k*f+s%$*$+u[p]+S,S=(f/y|0)+(s/$|0)+w*h,u[p--]=f%y;u[p]=S}return S?++C:u.splice(0,1),W(_,u,C)},t.negated=function(){var _=new O(this);return _.s=-_.s||null,_},t.plus=function(_,b){var S,C=this,x=C.s;if(_=new O(_,b),b=_.s,!x||!b)return new O(NaN);if(x!=b)return _.s=-b,C.minus(_);var p=C.e/tt,e=_.e/tt,s=C.c,l=_.c;if(!p||!e){if(!s||!l)return new O(x/0);if(!s[0]||!l[0])return l[0]?_:new O(s[0]?C:x*0)}if(p=te(p),e=te(e),s=s.slice(),x=p-e){for(x>0?(e=p,S=l):(x=-x,S=s),S.reverse();x--;S.push(0));S.reverse()}for(x=s.length,b=l.length,x-b<0&&(S=l,l=s,s=S,b=x),x=0;b;)x=(s[--b]=s[b]+l[b]+x)/ie|0,s[b]=ie===s[b]?0:s[b]%ie;return x&&(s=[x].concat(s),++e),W(_,s,e)},t.precision=t.sd=function(_,b){var S,C,x,p=this;if(_!=null&&_!==!!_)return ft(_,1,Wt),b==null?b=c:ft(b,0,8),F(new O(p),_,b);if(!(S=p.c))return null;if(x=S.length-1,C=x*tt+1,x=S[x]){for(;x%10==0;x/=10,C--);for(x=S[0];x>=10;x/=10,C++);}return _&&p.e+1>C&&(C=p.e+1),C},t.shiftedBy=function(_){return ft(_,-Ci,Ci),this.times("1e"+_)},t.squareRoot=t.sqrt=function(){var _,b,S,C,x,p=this,e=p.c,s=p.s,l=p.e,f=d+4,h=new O("0.5");if(s!==1||!e||!e[0])return new O(!s||s<0&&(!e||e[0])?NaN:e?p:1/0);if(s=Math.sqrt(+Z(p)),s==0||s==1/0?(b=Yt(e),(b.length+l)%2==0&&(b+="0"),s=Math.sqrt(+b),l=te((l+1)/2)-(l<0||l%2),s==1/0?b="5e"+l:(b=s.toExponential(),b=b.slice(0,b.indexOf("e")+1)+l),S=new O(b)):S=new O(s+""),S.c[0]){for(l=S.e,s=l+f,s<3&&(s=0);;)if(x=S,S=h.times(x.plus(i(p,x,f,1))),Yt(x.c).slice(0,s)===(b=Yt(S.c)).slice(0,s))if(S.e<l&&--s,b=b.slice(s-3,s+1),b=="9999"||!C&&b=="4999"){if(!C&&(F(x,x.e+d+2,0),x.times(x).eq(p))){S=x;break}f+=4,s+=4,C=1}else{(!+b||!+b.slice(1)&&b.charAt(0)=="5")&&(F(S,S.e+d+2,1),_=!S.times(S).eq(p));break}}return F(S,S.e+d+1,c,_)},t.toExponential=function(_,b){return _!=null&&(ft(_,0,Wt),_++),E(this,_,b,1)},t.toFixed=function(_,b){return _!=null&&(ft(_,0,Wt),_=_+this.e+1),E(this,_,b)},t.toFormat=function(_,b,S){var C,x=this;if(S==null)_!=null&&b&&typeof b=="object"?(S=b,b=null):_&&typeof _=="object"?(S=_,_=b=null):S=L;else if(typeof S!="object")throw Error(Vt+"Argument not an object: "+S);if(C=x.toFixed(_,b),x.c){var p,e=C.split("."),s=+S.groupSize,l=+S.secondaryGroupSize,f=S.groupSeparator||"",h=e[0],v=e[1],k=x.s<0,w=k?h.slice(1):h,u=w.length;if(l&&(p=s,s=l,l=p,u-=p),s>0&&u>0){for(p=u%s||s,h=w.substr(0,p);p<u;p+=s)h+=f+w.substr(p,s);l>0&&(h+=f+w.slice(p)),k&&(h="-"+h)}C=v?h+(S.decimalSeparator||"")+((l=+S.fractionGroupSize)?v.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(S.fractionGroupSeparator||"")):v):h}return(S.prefix||"")+C+(S.suffix||"")},t.toFraction=function(_){var b,S,C,x,p,e,s,l,f,h,v,k,w=this,u=w.c;if(_!=null&&(s=new O(_),!s.isInteger()&&(s.c||s.s!==1)||s.lt(a)))throw Error(Vt+"Argument "+(s.isInteger()?"out of range: ":"not an integer: ")+Z(s));if(!u)return new O(w);for(b=new O(a),f=S=new O(a),C=l=new O(a),k=Yt(u),p=b.e=k.length-w.e-1,b.c[0]=xi[(e=p%tt)<0?tt+e:e],_=!_||s.comparedTo(b)>0?p>0?b:f:s,e=P,P=1/0,s=new O(k),l.c[0]=0;h=i(s,b,0,1),x=S.plus(h.times(C)),x.comparedTo(_)!=1;)S=C,C=x,f=l.plus(h.times(x=f)),l=x,b=s.minus(h.times(x=b)),s=x;return x=i(_.minus(S),C,0,1),l=l.plus(x.times(f)),S=S.plus(x.times(C)),l.s=f.s=w.s,p=p*2,v=i(f,C,p,c).minus(w).abs().comparedTo(i(l,S,p,c).minus(w).abs())<1?[f,C]:[l,S],P=e,v},t.toNumber=function(){return+Z(this)},t.toPrecision=function(_,b){return _!=null&&ft(_,1,Wt),E(this,_,b,2)},t.toString=function(_){var b,S=this,C=S.s,x=S.e;return x===null?C?(b="Infinity",C<0&&(b="-"+b)):b="NaN":(_==null?b=x<=m||x>=g?Fe(Yt(S.c),x):ce(Yt(S.c),x,"0"):_===10&&R?(S=F(new O(S),d+x+1,c),b=ce(Yt(S.c),S.e,"0")):(ft(_,2,N.length,"Base"),b=r(ce(Yt(S.c),x,"0"),10,_,C,!0)),C<0&&S.c[0]&&(b="-"+b)),b},t.valueOf=t.toJSON=function(){return Z(this)},t._isBigNumber=!0,t[Symbol.toStringTag]="BigNumber",t[Symbol.for("nodejs.util.inspect.custom")]=t.valueOf,n!=null&&O.set(n),O}function te(n){var i=n|0;return n>0||n===i?i:i-1}function Yt(n){for(var i,r,o=1,t=n.length,a=n[0]+"";o<t;){for(i=n[o++]+"",r=tt-i.length;r--;i="0"+i);a+=i}for(t=a.length;a.charCodeAt(--t)===48;);return a.slice(0,t+1||1)}function Me(n,i){var r,o,t=n.c,a=i.c,d=n.s,c=i.s,m=n.e,g=i.e;if(!d||!c)return null;if(r=t&&!t[0],o=a&&!a[0],r||o)return r?o?0:-c:d;if(d!=c)return d;if(r=d<0,o=m==g,!t||!a)return o?0:!t^r?1:-1;if(!o)return m>g^r?1:-1;for(c=(m=t.length)<(g=a.length)?m:g,d=0;d<c;d++)if(t[d]!=a[d])return t[d]>a[d]^r?1:-1;return m==g?0:m>g^r?1:-1}function ft(n,i,r,o){if(n<i||n>r||n!==Qt(n))throw Error(Vt+(o||"Argument")+(typeof n=="number"?n<i||n>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(n))}function qe(n){var i=n.c.length-1;return te(n.e/tt)==i&&n.c[i]%2!=0}function Fe(n,i){return(n.length>1?n.charAt(0)+"."+n.slice(1):n)+(i<0?"e":"e+")+i}function ce(n,i,r){var o,t;if(i<0){for(t=r+".";++i;t+=r);n=t+n}else if(o=n.length,++i>o){for(t=r,i-=o;--i;t+=r);n+=t}else i<o&&(n=n.slice(0,i)+"."+n.slice(i));return n}var tn=fr(),lt=tn;import{Transaction as ne}from"@mysten/sui/transactions";var Ae=9e15,we=1e9,Di="0123456789abcdef",$e="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",We="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ti={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ae,maxE:Ae,crypto:!1},mr,fe,Y=!0,Ke="[DecimalError] ",_e=Ke+"Invalid argument: ",gr=Ke+"Precision limit exceeded",_r=Ke+"crypto unavailable",wr="[object Decimal]",zt=Math.floor,$t=Math.pow,en=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,rn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,nn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,vr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,re=1e7,H=7,on=9007199254740991,sn=$e.length-1,Oi=We.length-1,B={toStringTag:wr};B.absoluteValue=B.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),z(n)};B.ceil=function(){return z(new this.constructor(this),this.e+1,2)};B.clampedTo=B.clamp=function(n,i){var r,o=this,t=o.constructor;if(n=new t(n),i=new t(i),!n.s||!i.s)return new t(NaN);if(n.gt(i))throw Error(_e+i);return r=o.cmp(n),r<0?n:o.cmp(i)>0?i:new t(o)};B.comparedTo=B.cmp=function(n){var i,r,o,t,a=this,d=a.d,c=(n=new a.constructor(n)).d,m=a.s,g=n.s;if(!d||!c)return!m||!g?NaN:m!==g?m:d===c?0:!d^m<0?1:-1;if(!d[0]||!c[0])return d[0]?m:c[0]?-g:0;if(m!==g)return m;if(a.e!==n.e)return a.e>n.e^m<0?1:-1;for(o=d.length,t=c.length,i=0,r=o<t?o:t;i<r;++i)if(d[i]!==c[i])return d[i]>c[i]^m<0?1:-1;return o===t?0:o>t^m<0?1:-1};B.cosine=B.cos=function(){var n,i,r=this,o=r.constructor;return r.d?r.d[0]?(n=o.precision,i=o.rounding,o.precision=n+Math.max(r.e,r.sd())+H,o.rounding=1,r=an(o,Sr(o,r)),o.precision=n,o.rounding=i,z(fe==2||fe==3?r.neg():r,n,i,!0)):new o(1):new o(NaN)};B.cubeRoot=B.cbrt=function(){var n,i,r,o,t,a,d,c,m,g,M=this,P=M.constructor;if(!M.isFinite()||M.isZero())return new P(M);for(Y=!1,a=M.s*$t(M.s*M,1/3),!a||Math.abs(a)==1/0?(r=Zt(M.d),n=M.e,(a=(n-r.length+1)%3)&&(r+=a==1||a==-2?"0":"00"),a=$t(r,1/3),n=zt((n+1)/3)-(n%3==(n<0?-1:2)),a==1/0?r="5e"+n:(r=a.toExponential(),r=r.slice(0,r.indexOf("e")+1)+n),o=new P(r),o.s=M.s):o=new P(a.toString()),d=(n=P.precision)+3;;)if(c=o,m=c.times(c).times(c),g=m.plus(M),o=st(g.plus(M).times(c),g.plus(m),d+2,1),Zt(c.d).slice(0,d)===(r=Zt(o.d)).slice(0,d))if(r=r.slice(d-3,d+1),r=="9999"||!t&&r=="4999"){if(!t&&(z(c,n+1,0),c.times(c).times(c).eq(M))){o=c;break}d+=4,t=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(z(o,n+1,1),i=!o.times(o).times(o).eq(M));break}return Y=!0,z(o,n,P.rounding,i)};B.decimalPlaces=B.dp=function(){var n,i=this.d,r=NaN;if(i){if(n=i.length-1,r=(n-zt(this.e/H))*H,n=i[n],n)for(;n%10==0;n/=10)r--;r<0&&(r=0)}return r};B.dividedBy=B.div=function(n){return st(this,new this.constructor(n))};B.dividedToIntegerBy=B.divToInt=function(n){var i=this,r=i.constructor;return z(st(i,new r(n),0,1,1),r.precision,r.rounding)};B.equals=B.eq=function(n){return this.cmp(n)===0};B.floor=function(){return z(new this.constructor(this),this.e+1,3)};B.greaterThan=B.gt=function(n){return this.cmp(n)>0};B.greaterThanOrEqualTo=B.gte=function(n){var i=this.cmp(n);return i==1||i===0};B.hyperbolicCosine=B.cosh=function(){var n,i,r,o,t,a=this,d=a.constructor,c=new d(1);if(!a.isFinite())return new d(a.s?1/0:NaN);if(a.isZero())return c;r=d.precision,o=d.rounding,d.precision=r+Math.max(a.e,a.sd())+4,d.rounding=1,t=a.d.length,t<32?(n=Math.ceil(t/3),i=(1/Ge(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),a=Ce(d,1,a.times(i),new d(1),!0);for(var m,g=n,M=new d(8);g--;)m=a.times(a),a=c.minus(m.times(M.minus(m.times(M))));return z(a,d.precision=r,d.rounding=o,!0)};B.hyperbolicSine=B.sinh=function(){var n,i,r,o,t=this,a=t.constructor;if(!t.isFinite()||t.isZero())return new a(t);if(i=a.precision,r=a.rounding,a.precision=i+Math.max(t.e,t.sd())+4,a.rounding=1,o=t.d.length,o<3)t=Ce(a,2,t,t,!0);else{n=1.4*Math.sqrt(o),n=n>16?16:n|0,t=t.times(1/Ge(5,n)),t=Ce(a,2,t,t,!0);for(var d,c=new a(5),m=new a(16),g=new a(20);n--;)d=t.times(t),t=t.times(c.plus(d.times(m.times(d).plus(g))))}return a.precision=i,a.rounding=r,z(t,i,r,!0)};B.hyperbolicTangent=B.tanh=function(){var n,i,r=this,o=r.constructor;return r.isFinite()?r.isZero()?new o(r):(n=o.precision,i=o.rounding,o.precision=n+7,o.rounding=1,st(r.sinh(),r.cosh(),o.precision=n,o.rounding=i)):new o(r.s)};B.inverseCosine=B.acos=function(){var n=this,i=n.constructor,r=n.abs().cmp(1),o=i.precision,t=i.rounding;return r!==-1?r===0?n.isNeg()?ae(i,o,t):new i(0):new i(NaN):n.isZero()?ae(i,o+4,t).times(.5):(i.precision=o+6,i.rounding=1,n=new i(1).minus(n).div(n.plus(1)).sqrt().atan(),i.precision=o,i.rounding=t,n.times(2))};B.inverseHyperbolicCosine=B.acosh=function(){var n,i,r=this,o=r.constructor;return r.lte(1)?new o(r.eq(1)?0:NaN):r.isFinite()?(n=o.precision,i=o.rounding,o.precision=n+Math.max(Math.abs(r.e),r.sd())+4,o.rounding=1,Y=!1,r=r.times(r).minus(1).sqrt().plus(r),Y=!0,o.precision=n,o.rounding=i,r.ln()):new o(r)};B.inverseHyperbolicSine=B.asinh=function(){var n,i,r=this,o=r.constructor;return!r.isFinite()||r.isZero()?new o(r):(n=o.precision,i=o.rounding,o.precision=n+2*Math.max(Math.abs(r.e),r.sd())+6,o.rounding=1,Y=!1,r=r.times(r).plus(1).sqrt().plus(r),Y=!0,o.precision=n,o.rounding=i,r.ln())};B.inverseHyperbolicTangent=B.atanh=function(){var n,i,r,o,t=this,a=t.constructor;return t.isFinite()?t.e>=0?new a(t.abs().eq(1)?t.s/0:t.isZero()?t:NaN):(n=a.precision,i=a.rounding,o=t.sd(),Math.max(o,n)<2*-t.e-1?z(new a(t),n,i,!0):(a.precision=r=o-t.e,t=st(t.plus(1),new a(1).minus(t),r+n,1),a.precision=n+4,a.rounding=1,t=t.ln(),a.precision=n,a.rounding=i,t.times(.5))):new a(NaN)};B.inverseSine=B.asin=function(){var n,i,r,o,t=this,a=t.constructor;return t.isZero()?new a(t):(i=t.abs().cmp(1),r=a.precision,o=a.rounding,i!==-1?i===0?(n=ae(a,r+4,o).times(.5),n.s=t.s,n):new a(NaN):(a.precision=r+6,a.rounding=1,t=t.div(new a(1).minus(t.times(t)).sqrt().plus(1)).atan(),a.precision=r,a.rounding=o,t.times(2)))};B.inverseTangent=B.atan=function(){var n,i,r,o,t,a,d,c,m,g=this,M=g.constructor,P=M.precision,A=M.rounding;if(g.isFinite()){if(g.isZero())return new M(g);if(g.abs().eq(1)&&P+4<=Oi)return d=ae(M,P+4,A).times(.25),d.s=g.s,d}else{if(!g.s)return new M(NaN);if(P+4<=Oi)return d=ae(M,P+4,A).times(.5),d.s=g.s,d}for(M.precision=c=P+10,M.rounding=1,r=Math.min(28,c/H+2|0),n=r;n;--n)g=g.div(g.times(g).plus(1).sqrt().plus(1));for(Y=!1,i=Math.ceil(c/H),o=1,m=g.times(g),d=new M(g),t=g;n!==-1;)if(t=t.times(m),a=d.minus(t.div(o+=2)),t=t.times(m),d=a.plus(t.div(o+=2)),d.d[i]!==void 0)for(n=i;d.d[n]===a.d[n]&&n--;);return r&&(d=d.times(2<<r-1)),Y=!0,z(d,M.precision=P,M.rounding=A,!0)};B.isFinite=function(){return!!this.d};B.isInteger=B.isInt=function(){return!!this.d&&zt(this.e/H)>this.d.length-2};B.isNaN=function(){return!this.s};B.isNegative=B.isNeg=function(){return this.s<0};B.isPositive=B.isPos=function(){return this.s>0};B.isZero=function(){return!!this.d&&this.d[0]===0};B.lessThan=B.lt=function(n){return this.cmp(n)<0};B.lessThanOrEqualTo=B.lte=function(n){return this.cmp(n)<1};B.logarithm=B.log=function(n){var i,r,o,t,a,d,c,m,g=this,M=g.constructor,P=M.precision,A=M.rounding,D=5;if(n==null)n=new M(10),i=!0;else{if(n=new M(n),r=n.d,n.s<0||!r||!r[0]||n.eq(1))return new M(NaN);i=n.eq(10)}if(r=g.d,g.s<0||!r||!r[0]||g.eq(1))return new M(r&&!r[0]?-1/0:g.s!=1?NaN:r?0:1/0);if(i)if(r.length>1)a=!0;else{for(t=r[0];t%10===0;)t/=10;a=t!==1}if(Y=!1,c=P+D,d=ge(g,c),o=i?Ze(M,c+10):ge(n,c),m=st(d,o,c,1),Te(m.d,t=P,A))do if(c+=10,d=ge(g,c),o=i?Ze(M,c+10):ge(n,c),m=st(d,o,c,1),!a){+Zt(m.d).slice(t+1,t+15)+1==1e14&&(m=z(m,P+1,0));break}while(Te(m.d,t+=10,A));return Y=!0,z(m,P,A)};B.minus=B.sub=function(n){var i,r,o,t,a,d,c,m,g,M,P,A,D=this,T=D.constructor;if(n=new T(n),!D.d||!n.d)return!D.s||!n.s?n=new T(NaN):D.d?n.s=-n.s:n=new T(n.d||D.s!==n.s?D:NaN),n;if(D.s!=n.s)return n.s=-n.s,D.plus(n);if(g=D.d,A=n.d,c=T.precision,m=T.rounding,!g[0]||!A[0]){if(A[0])n.s=-n.s;else if(g[0])n=new T(D);else return new T(m===3?-0:0);return Y?z(n,c,m):n}if(r=zt(n.e/H),M=zt(D.e/H),g=g.slice(),a=M-r,a){for(P=a<0,P?(i=g,a=-a,d=A.length):(i=A,r=M,d=g.length),o=Math.max(Math.ceil(c/H),d)+2,a>o&&(a=o,i.length=1),i.reverse(),o=a;o--;)i.push(0);i.reverse()}else{for(o=g.length,d=A.length,P=o<d,P&&(d=o),o=0;o<d;o++)if(g[o]!=A[o]){P=g[o]<A[o];break}a=0}for(P&&(i=g,g=A,A=i,n.s=-n.s),d=g.length,o=A.length-d;o>0;--o)g[d++]=0;for(o=A.length;o>a;){if(g[--o]<A[o]){for(t=o;t&&g[--t]===0;)g[t]=re-1;--g[t],g[o]+=re}g[o]-=A[o]}for(;g[--d]===0;)g.pop();for(;g[0]===0;g.shift())--r;return g[0]?(n.d=g,n.e=ze(g,r),Y?z(n,c,m):n):new T(m===3?-0:0)};B.modulo=B.mod=function(n){var i,r=this,o=r.constructor;return n=new o(n),!r.d||!n.s||n.d&&!n.d[0]?new o(NaN):!n.d||r.d&&!r.d[0]?z(new o(r),o.precision,o.rounding):(Y=!1,o.modulo==9?(i=st(r,n.abs(),0,3,1),i.s*=n.s):i=st(r,n,0,o.modulo,1),i=i.times(n),Y=!0,r.minus(i))};B.naturalExponential=B.exp=function(){return Ri(this)};B.naturalLogarithm=B.ln=function(){return ge(this)};B.negated=B.neg=function(){var n=new this.constructor(this);return n.s=-n.s,z(n)};B.plus=B.add=function(n){var i,r,o,t,a,d,c,m,g,M,P=this,A=P.constructor;if(n=new A(n),!P.d||!n.d)return!P.s||!n.s?n=new A(NaN):P.d||(n=new A(n.d||P.s===n.s?P:NaN)),n;if(P.s!=n.s)return n.s=-n.s,P.minus(n);if(g=P.d,M=n.d,c=A.precision,m=A.rounding,!g[0]||!M[0])return M[0]||(n=new A(P)),Y?z(n,c,m):n;if(a=zt(P.e/H),o=zt(n.e/H),g=g.slice(),t=a-o,t){for(t<0?(r=g,t=-t,d=M.length):(r=M,o=a,d=g.length),a=Math.ceil(c/H),d=a>d?a+1:d+1,t>d&&(t=d,r.length=1),r.reverse();t--;)r.push(0);r.reverse()}for(d=g.length,t=M.length,d-t<0&&(t=d,r=M,M=g,g=r),i=0;t;)i=(g[--t]=g[t]+M[t]+i)/re|0,g[t]%=re;for(i&&(g.unshift(i),++o),d=g.length;g[--d]==0;)g.pop();return n.d=g,n.e=ze(g,o),Y?z(n,c,m):n};B.precision=B.sd=function(n){var i,r=this;if(n!==void 0&&n!==!!n&&n!==1&&n!==0)throw Error(_e+n);return r.d?(i=Mr(r.d),n&&r.e+1>i&&(i=r.e+1)):i=NaN,i};B.round=function(){var n=this,i=n.constructor;return z(new i(n),n.e+1,i.rounding)};B.sine=B.sin=function(){var n,i,r=this,o=r.constructor;return r.isFinite()?r.isZero()?new o(r):(n=o.precision,i=o.rounding,o.precision=n+Math.max(r.e,r.sd())+H,o.rounding=1,r=un(o,Sr(o,r)),o.precision=n,o.rounding=i,z(fe>2?r.neg():r,n,i,!0)):new o(NaN)};B.squareRoot=B.sqrt=function(){var n,i,r,o,t,a,d=this,c=d.d,m=d.e,g=d.s,M=d.constructor;if(g!==1||!c||!c[0])return new M(!g||g<0&&(!c||c[0])?NaN:c?d:1/0);for(Y=!1,g=Math.sqrt(+d),g==0||g==1/0?(i=Zt(c),(i.length+m)%2==0&&(i+="0"),g=Math.sqrt(i),m=zt((m+1)/2)-(m<0||m%2),g==1/0?i="5e"+m:(i=g.toExponential(),i=i.slice(0,i.indexOf("e")+1)+m),o=new M(i)):o=new M(g.toString()),r=(m=M.precision)+3;;)if(a=o,o=a.plus(st(d,a,r+2,1)).times(.5),Zt(a.d).slice(0,r)===(i=Zt(o.d)).slice(0,r))if(i=i.slice(r-3,r+1),i=="9999"||!t&&i=="4999"){if(!t&&(z(a,m+1,0),a.times(a).eq(d))){o=a;break}r+=4,t=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(z(o,m+1,1),n=!o.times(o).eq(d));break}return Y=!0,z(o,m,M.rounding,n)};B.tangent=B.tan=function(){var n,i,r=this,o=r.constructor;return r.isFinite()?r.isZero()?new o(r):(n=o.precision,i=o.rounding,o.precision=n+10,o.rounding=1,r=r.sin(),r.s=1,r=st(r,new o(1).minus(r.times(r)).sqrt(),n+10,0),o.precision=n,o.rounding=i,z(fe==2||fe==4?r.neg():r,n,i,!0)):new o(NaN)};B.times=B.mul=function(n){var i,r,o,t,a,d,c,m,g,M=this,P=M.constructor,A=M.d,D=(n=new P(n)).d;if(n.s*=M.s,!A||!A[0]||!D||!D[0])return new P(!n.s||A&&!A[0]&&!D||D&&!D[0]&&!A?NaN:!A||!D?n.s/0:n.s*0);for(r=zt(M.e/H)+zt(n.e/H),m=A.length,g=D.length,m<g&&(a=A,A=D,D=a,d=m,m=g,g=d),a=[],d=m+g,o=d;o--;)a.push(0);for(o=g;--o>=0;){for(i=0,t=m+o;t>o;)c=a[t]+D[o]*A[t-o-1]+i,a[t--]=c%re|0,i=c/re|0;a[t]=(a[t]+i)%re|0}for(;!a[--d];)a.pop();return i?++r:a.shift(),n.d=a,n.e=ze(a,r),Y?z(n,P.precision,P.rounding):n};B.toBinary=function(n,i){return Li(this,2,n,i)};B.toDecimalPlaces=B.toDP=function(n,i){var r=this,o=r.constructor;return r=new o(r),n===void 0?r:(Xt(n,0,we),i===void 0?i=o.rounding:Xt(i,0,8),z(r,n+r.e+1,i))};B.toExponential=function(n,i){var r,o=this,t=o.constructor;return n===void 0?r=le(o,!0):(Xt(n,0,we),i===void 0?i=t.rounding:Xt(i,0,8),o=z(new t(o),n+1,i),r=le(o,!0,n+1)),o.isNeg()&&!o.isZero()?"-"+r:r};B.toFixed=function(n,i){var r,o,t=this,a=t.constructor;return n===void 0?r=le(t):(Xt(n,0,we),i===void 0?i=a.rounding:Xt(i,0,8),o=z(new a(t),n+t.e+1,i),r=le(o,!1,n+o.e+1)),t.isNeg()&&!t.isZero()?"-"+r:r};B.toFraction=function(n){var i,r,o,t,a,d,c,m,g,M,P,A,D=this,T=D.d,L=D.constructor;if(!T)return new L(D);if(g=r=new L(1),o=m=new L(0),i=new L(o),a=i.e=Mr(T)-D.e-1,d=a%H,i.d[0]=$t(10,d<0?H+d:d),n==null)n=a>0?i:g;else{if(c=new L(n),!c.isInt()||c.lt(g))throw Error(_e+c);n=c.gt(i)?a>0?i:g:c}for(Y=!1,c=new L(Zt(T)),M=L.precision,L.precision=a=T.length*H*2;P=st(c,i,0,1,1),t=r.plus(P.times(o)),t.cmp(n)!=1;)r=o,o=t,t=g,g=m.plus(P.times(t)),m=t,t=i,i=c.minus(P.times(t)),c=t;return t=st(n.minus(r),o,0,1,1),m=m.plus(t.times(g)),r=r.plus(t.times(o)),m.s=g.s=D.s,A=st(g,o,a,1).minus(D).abs().cmp(st(m,r,a,1).minus(D).abs())<1?[g,o]:[m,r],L.precision=M,Y=!0,A};B.toHexadecimal=B.toHex=function(n,i){return Li(this,16,n,i)};B.toNearest=function(n,i){var r=this,o=r.constructor;if(r=new o(r),n==null){if(!r.d)return r;n=new o(1),i=o.rounding}else{if(n=new o(n),i===void 0?i=o.rounding:Xt(i,0,8),!r.d)return n.s?r:n;if(!n.d)return n.s&&(n.s=r.s),n}return n.d[0]?(Y=!1,r=st(r,n,0,i,1).times(n),Y=!0,z(r)):(n.s=r.s,r=n),r};B.toNumber=function(){return+this};B.toOctal=function(n,i){return Li(this,8,n,i)};B.toPower=B.pow=function(n){var i,r,o,t,a,d,c=this,m=c.constructor,g=+(n=new m(n));if(!c.d||!n.d||!c.d[0]||!n.d[0])return new m($t(+c,g));if(c=new m(c),c.eq(1))return c;if(o=m.precision,a=m.rounding,n.eq(1))return z(c,o,a);if(i=zt(n.e/H),i>=n.d.length-1&&(r=g<0?-g:g)<=on)return t=br(m,c,r,o),n.s<0?new m(1).div(t):z(t,o,a);if(d=c.s,d<0){if(i<n.d.length-1)return new m(NaN);if((n.d[i]&1)==0&&(d=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=d,c}return r=$t(+c,g),i=r==0||!isFinite(r)?zt(g*(Math.log("0."+Zt(c.d))/Math.LN10+c.e+1)):new m(r+"").e,i>m.maxE+1||i<m.minE-1?new m(i>0?d/0:0):(Y=!1,m.rounding=c.s=1,r=Math.min(12,(i+"").length),t=Ri(n.times(ge(c,o+r)),o),t.d&&(t=z(t,o+5,1),Te(t.d,o,a)&&(i=o+10,t=z(Ri(n.times(ge(c,i+r)),i),i+5,1),+Zt(t.d).slice(o+1,o+15)+1==1e14&&(t=z(t,o+1,0)))),t.s=d,Y=!0,m.rounding=a,z(t,o,a))};B.toPrecision=function(n,i){var r,o=this,t=o.constructor;return n===void 0?r=le(o,o.e<=t.toExpNeg||o.e>=t.toExpPos):(Xt(n,1,we),i===void 0?i=t.rounding:Xt(i,0,8),o=z(new t(o),n,i),r=le(o,n<=o.e||o.e<=t.toExpNeg,n)),o.isNeg()&&!o.isZero()?"-"+r:r};B.toSignificantDigits=B.toSD=function(n,i){var r=this,o=r.constructor;return n===void 0?(n=o.precision,i=o.rounding):(Xt(n,1,we),i===void 0?i=o.rounding:Xt(i,0,8)),z(new o(r),n,i)};B.toString=function(){var n=this,i=n.constructor,r=le(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()&&!n.isZero()?"-"+r:r};B.truncated=B.trunc=function(){return z(new this.constructor(this),this.e+1,1)};B.valueOf=B.toJSON=function(){var n=this,i=n.constructor,r=le(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()?"-"+r:r};function Zt(n){var i,r,o,t=n.length-1,a="",d=n[0];if(t>0){for(a+=d,i=1;i<t;i++)o=n[i]+"",r=H-o.length,r&&(a+=me(r)),a+=o;d=n[i],o=d+"",r=H-o.length,r&&(a+=me(r))}else if(d===0)return"0";for(;d%10===0;)d/=10;return a+d}function Xt(n,i,r){if(n!==~~n||n<i||n>r)throw Error(_e+n)}function Te(n,i,r,o){var t,a,d,c;for(a=n[0];a>=10;a/=10)--i;return--i<0?(i+=H,t=0):(t=Math.ceil((i+1)/H),i%=H),a=$t(10,H-i),c=n[t]%a|0,o==null?i<3?(i==0?c=c/100|0:i==1&&(c=c/10|0),d=r<4&&c==99999||r>3&&c==49999||c==5e4||c==0):d=(r<4&&c+1==a||r>3&&c+1==a/2)&&(n[t+1]/a/100|0)==$t(10,i-2)-1||(c==a/2||c==0)&&(n[t+1]/a/100|0)==0:i<4?(i==0?c=c/1e3|0:i==1?c=c/100|0:i==2&&(c=c/10|0),d=(o||r<4)&&c==9999||!o&&r>3&&c==4999):d=((o||r<4)&&c+1==a||!o&&r>3&&c+1==a/2)&&(n[t+1]/a/1e3|0)==$t(10,i-3)-1,d}function Ue(n,i,r){for(var o,t=[0],a,d=0,c=n.length;d<c;){for(a=t.length;a--;)t[a]*=i;for(t[0]+=Di.indexOf(n.charAt(d++)),o=0;o<t.length;o++)t[o]>r-1&&(t[o+1]===void 0&&(t[o+1]=0),t[o+1]+=t[o]/r|0,t[o]%=r)}return t.reverse()}function an(n,i){var r,o,t;if(i.isZero())return i;o=i.d.length,o<32?(r=Math.ceil(o/3),t=(1/Ge(4,r)).toString()):(r=16,t="2.3283064365386962890625e-10"),n.precision+=r,i=Ce(n,1,i.times(t),new n(1));for(var a=r;a--;){var d=i.times(i);i=d.times(d).minus(d).times(8).plus(1)}return n.precision-=r,i}var st=(function(){function n(o,t,a){var d,c=0,m=o.length;for(o=o.slice();m--;)d=o[m]*t+c,o[m]=d%a|0,c=d/a|0;return c&&o.unshift(c),o}function i(o,t,a,d){var c,m;if(a!=d)m=a>d?1:-1;else for(c=m=0;c<a;c++)if(o[c]!=t[c]){m=o[c]>t[c]?1:-1;break}return m}function r(o,t,a,d){for(var c=0;a--;)o[a]-=c,c=o[a]<t[a]?1:0,o[a]=c*d+o[a]-t[a];for(;!o[0]&&o.length>1;)o.shift()}return function(o,t,a,d,c,m){var g,M,P,A,D,T,L,N,R,O,E,q,W,F,Z,_,b,S,C,x,p=o.constructor,e=o.s==t.s?1:-1,s=o.d,l=t.d;if(!s||!s[0]||!l||!l[0])return new p(!o.s||!t.s||(s?l&&s[0]==l[0]:!l)?NaN:s&&s[0]==0||!l?e*0:e/0);for(m?(D=1,M=o.e-t.e):(m=re,D=H,M=zt(o.e/D)-zt(t.e/D)),C=l.length,b=s.length,R=new p(e),O=R.d=[],P=0;l[P]==(s[P]||0);P++);if(l[P]>(s[P]||0)&&M--,a==null?(F=a=p.precision,d=p.rounding):c?F=a+(o.e-t.e)+1:F=a,F<0)O.push(1),T=!0;else{if(F=F/D+2|0,P=0,C==1){for(A=0,l=l[0],F++;(P<b||A)&&F--;P++)Z=A*m+(s[P]||0),O[P]=Z/l|0,A=Z%l|0;T=A||P<b}else{for(A=m/(l[0]+1)|0,A>1&&(l=n(l,A,m),s=n(s,A,m),C=l.length,b=s.length),_=C,E=s.slice(0,C),q=E.length;q<C;)E[q++]=0;x=l.slice(),x.unshift(0),S=l[0],l[1]>=m/2&&++S;do A=0,g=i(l,E,C,q),g<0?(W=E[0],C!=q&&(W=W*m+(E[1]||0)),A=W/S|0,A>1?(A>=m&&(A=m-1),L=n(l,A,m),N=L.length,q=E.length,g=i(L,E,N,q),g==1&&(A--,r(L,C<N?x:l,N,m))):(A==0&&(g=A=1),L=l.slice()),N=L.length,N<q&&L.unshift(0),r(E,L,q,m),g==-1&&(q=E.length,g=i(l,E,C,q),g<1&&(A++,r(E,C<q?x:l,q,m))),q=E.length):g===0&&(A++,E=[0]),O[P++]=A,g&&E[0]?E[q++]=s[_]||0:(E=[s[_]],q=1);while((_++<b||E[0]!==void 0)&&F--);T=E[0]!==void 0}O[0]||O.shift()}if(D==1)R.e=M,mr=T;else{for(P=1,A=O[0];A>=10;A/=10)P++;R.e=P+M*D-1,z(R,c?a+R.e+1:a,d,T)}return R}})();function z(n,i,r,o){var t,a,d,c,m,g,M,P,A,D=n.constructor;t:if(i!=null){if(P=n.d,!P)return n;for(t=1,c=P[0];c>=10;c/=10)t++;if(a=i-t,a<0)a+=H,d=i,M=P[A=0],m=M/$t(10,t-d-1)%10|0;else if(A=Math.ceil((a+1)/H),c=P.length,A>=c)if(o){for(;c++<=A;)P.push(0);M=m=0,t=1,a%=H,d=a-H+1}else break t;else{for(M=c=P[A],t=1;c>=10;c/=10)t++;a%=H,d=a-H+t,m=d<0?0:M/$t(10,t-d-1)%10|0}if(o=o||i<0||P[A+1]!==void 0||(d<0?M:M%$t(10,t-d-1)),g=r<4?(m||o)&&(r==0||r==(n.s<0?3:2)):m>5||m==5&&(r==4||o||r==6&&(a>0?d>0?M/$t(10,t-d):0:P[A-1])%10&1||r==(n.s<0?8:7)),i<1||!P[0])return P.length=0,g?(i-=n.e+1,P[0]=$t(10,(H-i%H)%H),n.e=-i||0):P[0]=n.e=0,n;if(a==0?(P.length=A,c=1,A--):(P.length=A+1,c=$t(10,H-a),P[A]=d>0?(M/$t(10,t-d)%$t(10,d)|0)*c:0),g)for(;;)if(A==0){for(a=1,d=P[0];d>=10;d/=10)a++;for(d=P[0]+=c,c=1;d>=10;d/=10)c++;a!=c&&(n.e++,P[0]==re&&(P[0]=1));break}else{if(P[A]+=c,P[A]!=re)break;P[A--]=0,c=1}for(a=P.length;P[--a]===0;)P.pop()}return Y&&(n.e>D.maxE?(n.d=null,n.e=NaN):n.e<D.minE&&(n.e=0,n.d=[0])),n}function le(n,i,r){if(!n.isFinite())return kr(n);var o,t=n.e,a=Zt(n.d),d=a.length;return i?(r&&(o=r-d)>0?a=a.charAt(0)+"."+a.slice(1)+me(o):d>1&&(a=a.charAt(0)+"."+a.slice(1)),a=a+(n.e<0?"e":"e+")+n.e):t<0?(a="0."+me(-t-1)+a,r&&(o=r-d)>0&&(a+=me(o))):t>=d?(a+=me(t+1-d),r&&(o=r-t-1)>0&&(a=a+"."+me(o))):((o=t+1)<d&&(a=a.slice(0,o)+"."+a.slice(o)),r&&(o=r-d)>0&&(t+1===d&&(a+="."),a+=me(o))),a}function ze(n,i){var r=n[0];for(i*=H;r>=10;r/=10)i++;return i}function Ze(n,i,r){if(i>sn)throw Y=!0,r&&(n.precision=r),Error(gr);return z(new n($e),i,1,!0)}function ae(n,i,r){if(i>Oi)throw Error(gr);return z(new n(We),i,r,!0)}function Mr(n){var i=n.length-1,r=i*H+1;if(i=n[i],i){for(;i%10==0;i/=10)r--;for(i=n[0];i>=10;i/=10)r++}return r}function me(n){for(var i="";n--;)i+="0";return i}function br(n,i,r,o){var t,a=new n(1),d=Math.ceil(o/H+4);for(Y=!1;;){if(r%2&&(a=a.times(i),hr(a.d,d)&&(t=!0)),r=zt(r/2),r===0){r=a.d.length-1,t&&a.d[r]===0&&++a.d[r];break}i=i.times(i),hr(i.d,d)}return Y=!0,a}function dr(n){return n.d[n.d.length-1]&1}function yr(n,i,r){for(var o,t,a=new n(i[0]),d=0;++d<i.length;){if(t=new n(i[d]),!t.s){a=t;break}o=a.cmp(t),(o===r||o===0&&a.s===r)&&(a=t)}return a}function Ri(n,i){var r,o,t,a,d,c,m,g=0,M=0,P=0,A=n.constructor,D=A.rounding,T=A.precision;if(!n.d||!n.d[0]||n.e>17)return new A(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(i==null?(Y=!1,m=T):m=i,c=new A(.03125);n.e>-2;)n=n.times(c),P+=5;for(o=Math.log($t(2,P))/Math.LN10*2+5|0,m+=o,r=a=d=new A(1),A.precision=m;;){if(a=z(a.times(n),m,1),r=r.times(++M),c=d.plus(st(a,r,m,1)),Zt(c.d).slice(0,m)===Zt(d.d).slice(0,m)){for(t=P;t--;)d=z(d.times(d),m,1);if(i==null)if(g<3&&Te(d.d,m-o,D,g))A.precision=m+=10,r=a=c=new A(1),M=0,g++;else return z(d,A.precision=T,D,Y=!0);else return A.precision=T,d}d=c}}function ge(n,i){var r,o,t,a,d,c,m,g,M,P,A,D=1,T=10,L=n,N=L.d,R=L.constructor,O=R.rounding,E=R.precision;if(L.s<0||!N||!N[0]||!L.e&&N[0]==1&&N.length==1)return new R(N&&!N[0]?-1/0:L.s!=1?NaN:N?0:L);if(i==null?(Y=!1,M=E):M=i,R.precision=M+=T,r=Zt(N),o=r.charAt(0),Math.abs(a=L.e)<15e14){for(;o<7&&o!=1||o==1&&r.charAt(1)>3;)L=L.times(n),r=Zt(L.d),o=r.charAt(0),D++;a=L.e,o>1?(L=new R("0."+r),a++):L=new R(o+"."+r.slice(1))}else return g=Ze(R,M+2,E).times(a+""),L=ge(new R(o+"."+r.slice(1)),M-T).plus(g),R.precision=E,i==null?z(L,E,O,Y=!0):L;for(P=L,m=d=L=st(L.minus(1),L.plus(1),M,1),A=z(L.times(L),M,1),t=3;;){if(d=z(d.times(A),M,1),g=m.plus(st(d,new R(t),M,1)),Zt(g.d).slice(0,M)===Zt(m.d).slice(0,M))if(m=m.times(2),a!==0&&(m=m.plus(Ze(R,M+2,E).times(a+""))),m=st(m,new R(D),M,1),i==null)if(Te(m.d,M-T,O,c))R.precision=M+=T,g=d=L=st(P.minus(1),P.plus(1),M,1),A=z(L.times(L),M,1),t=c=1;else return z(m,R.precision=E,O,Y=!0);else return R.precision=E,m;m=g,t+=2}}function kr(n){return String(n.s*n.s/0)}function je(n,i){var r,o,t;for((r=i.indexOf("."))>-1&&(i=i.replace(".","")),(o=i.search(/e/i))>0?(r<0&&(r=o),r+=+i.slice(o+1),i=i.substring(0,o)):r<0&&(r=i.length),o=0;i.charCodeAt(o)===48;o++);for(t=i.length;i.charCodeAt(t-1)===48;--t);if(i=i.slice(o,t),i){if(t-=o,n.e=r=r-o-1,n.d=[],o=(r+1)%H,r<0&&(o+=H),o<t){for(o&&n.d.push(+i.slice(0,o)),t-=H;o<t;)n.d.push(+i.slice(o,o+=H));i=i.slice(o),o=H-i.length}else o-=t;for(;o--;)i+="0";n.d.push(+i),Y&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function ln(n,i){var r,o,t,a,d,c,m,g,M;if(i.indexOf("_")>-1){if(i=i.replace(/(\d)_(?=\d)/g,"$1"),vr.test(i))return je(n,i)}else if(i==="Infinity"||i==="NaN")return+i||(n.s=NaN),n.e=NaN,n.d=null,n;if(rn.test(i))r=16,i=i.toLowerCase();else if(en.test(i))r=2;else if(nn.test(i))r=8;else throw Error(_e+i);for(a=i.search(/p/i),a>0?(m=+i.slice(a+1),i=i.substring(2,a)):i=i.slice(2),a=i.indexOf("."),d=a>=0,o=n.constructor,d&&(i=i.replace(".",""),c=i.length,a=c-a,t=br(o,new o(r),a,a*2)),g=Ue(i,r,re),M=g.length-1,a=M;g[a]===0;--a)g.pop();return a<0?new o(n.s*0):(n.e=ze(g,M),n.d=g,Y=!1,d&&(n=st(n,t,c*4)),m&&(n=n.times(Math.abs(m)<54?$t(2,m):Oe.pow(2,m))),Y=!0,n)}function un(n,i){var r,o=i.d.length;if(o<3)return i.isZero()?i:Ce(n,2,i,i);r=1.4*Math.sqrt(o),r=r>16?16:r|0,i=i.times(1/Ge(5,r)),i=Ce(n,2,i,i);for(var t,a=new n(5),d=new n(16),c=new n(20);r--;)t=i.times(i),i=i.times(a.plus(t.times(d.times(t).minus(c))));return i}function Ce(n,i,r,o,t){var a,d,c,m,g=1,M=n.precision,P=Math.ceil(M/H);for(Y=!1,m=r.times(r),c=new n(o);;){if(d=st(c.times(m),new n(i++*i++),M,1),c=t?o.plus(d):o.minus(d),o=st(d.times(m),new n(i++*i++),M,1),d=c.plus(o),d.d[P]!==void 0){for(a=P;d.d[a]===c.d[a]&&a--;);if(a==-1)break}a=c,c=o,o=d,d=a,g++}return Y=!0,d.d.length=P+1,d}function Ge(n,i){for(var r=n;--i;)r*=n;return r}function Sr(n,i){var r,o=i.s<0,t=ae(n,n.precision,1),a=t.times(.5);if(i=i.abs(),i.lte(a))return fe=o?4:1,i;if(r=i.divToInt(t),r.isZero())fe=o?3:2;else{if(i=i.minus(r.times(t)),i.lte(a))return fe=dr(r)?o?2:3:o?4:1,i;fe=dr(r)?o?1:4:o?3:2}return i.minus(t).abs()}function Li(n,i,r,o){var t,a,d,c,m,g,M,P,A,D=n.constructor,T=r!==void 0;if(T?(Xt(r,1,we),o===void 0?o=D.rounding:Xt(o,0,8)):(r=D.precision,o=D.rounding),!n.isFinite())M=kr(n);else{for(M=le(n),d=M.indexOf("."),T?(t=2,i==16?r=r*4-3:i==8&&(r=r*3-2)):t=i,d>=0&&(M=M.replace(".",""),A=new D(1),A.e=M.length-d,A.d=Ue(le(A),10,t),A.e=A.d.length),P=Ue(M,10,t),a=m=P.length;P[--m]==0;)P.pop();if(!P[0])M=T?"0p+0":"0";else{if(d<0?a--:(n=new D(n),n.d=P,n.e=a,n=st(n,A,r,o,0,t),P=n.d,a=n.e,g=mr),d=P[r],c=t/2,g=g||P[r+1]!==void 0,g=o<4?(d!==void 0||g)&&(o===0||o===(n.s<0?3:2)):d>c||d===c&&(o===4||g||o===6&&P[r-1]&1||o===(n.s<0?8:7)),P.length=r,g)for(;++P[--r]>t-1;)P[r]=0,r||(++a,P.unshift(1));for(m=P.length;!P[m-1];--m);for(d=0,M="";d<m;d++)M+=Di.charAt(P[d]);if(T){if(m>1)if(i==16||i==8){for(d=i==16?4:3,--m;m%d;m++)M+="0";for(P=Ue(M,t,i),m=P.length;!P[m-1];--m);for(d=1,M="1.";d<m;d++)M+=Di.charAt(P[d])}else M=M.charAt(0)+"."+M.slice(1);M=M+(a<0?"p":"p+")+a}else if(a<0){for(;++a;)M="0"+M;M="0."+M}else if(++a>m)for(a-=m;a--;)M+="0";else a<m&&(M=M.slice(0,a)+"."+M.slice(a))}M=(i==16?"0x":i==2?"0b":i==8?"0o":"")+M}return n.s<0?"-"+M:M}function hr(n,i){if(n.length>i)return n.length=i,!0}function cn(n){return new this(n).abs()}function fn(n){return new this(n).acos()}function dn(n){return new this(n).acosh()}function hn(n,i){return new this(n).plus(i)}function pn(n){return new this(n).asin()}function mn(n){return new this(n).asinh()}function gn(n){return new this(n).atan()}function _n(n){return new this(n).atanh()}function wn(n,i){n=new this(n),i=new this(i);var r,o=this.precision,t=this.rounding,a=o+4;return!n.s||!i.s?r=new this(NaN):!n.d&&!i.d?(r=ae(this,a,1).times(i.s>0?.25:.75),r.s=n.s):!i.d||n.isZero()?(r=i.s<0?ae(this,o,t):new this(0),r.s=n.s):!n.d||i.isZero()?(r=ae(this,a,1).times(.5),r.s=n.s):i.s<0?(this.precision=a,this.rounding=1,r=this.atan(st(n,i,a,1)),i=ae(this,a,1),this.precision=o,this.rounding=t,r=n.s<0?r.minus(i):r.plus(i)):r=this.atan(st(n,i,a,1)),r}function vn(n){return new this(n).cbrt()}function Mn(n){return z(n=new this(n),n.e+1,2)}function bn(n,i,r){return new this(n).clamp(i,r)}function yn(n){if(!n||typeof n!="object")throw Error(Ke+"Object expected");var i,r,o,t=n.defaults===!0,a=["precision",1,we,"rounding",0,8,"toExpNeg",-Ae,0,"toExpPos",0,Ae,"maxE",0,Ae,"minE",-Ae,0,"modulo",0,9];for(i=0;i<a.length;i+=3)if(r=a[i],t&&(this[r]=Ti[r]),(o=n[r])!==void 0)if(zt(o)===o&&o>=a[i+1]&&o<=a[i+2])this[r]=o;else throw Error(_e+r+": "+o);if(r="crypto",t&&(this[r]=Ti[r]),(o=n[r])!==void 0)if(o===!0||o===!1||o===0||o===1)if(o)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(_r);else this[r]=!1;else throw Error(_e+r+": "+o);return this}function kn(n){return new this(n).cos()}function Sn(n){return new this(n).cosh()}function Pr(n){var i,r,o;function t(a){var d,c,m,g=this;if(!(g instanceof t))return new t(a);if(g.constructor=t,pr(a)){g.s=a.s,Y?!a.d||a.e>t.maxE?(g.e=NaN,g.d=null):a.e<t.minE?(g.e=0,g.d=[0]):(g.e=a.e,g.d=a.d.slice()):(g.e=a.e,g.d=a.d?a.d.slice():a.d);return}if(m=typeof a,m==="number"){if(a===0){g.s=1/a<0?-1:1,g.e=0,g.d=[0];return}if(a<0?(a=-a,g.s=-1):g.s=1,a===~~a&&a<1e7){for(d=0,c=a;c>=10;c/=10)d++;Y?d>t.maxE?(g.e=NaN,g.d=null):d<t.minE?(g.e=0,g.d=[0]):(g.e=d,g.d=[a]):(g.e=d,g.d=[a]);return}if(a*0!==0){a||(g.s=NaN),g.e=NaN,g.d=null;return}return je(g,a.toString())}if(m==="string")return(c=a.charCodeAt(0))===45?(a=a.slice(1),g.s=-1):(c===43&&(a=a.slice(1)),g.s=1),vr.test(a)?je(g,a):ln(g,a);if(m==="bigint")return a<0?(a=-a,g.s=-1):g.s=1,je(g,a.toString());throw Error(_e+a)}if(t.prototype=B,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=yn,t.clone=Pr,t.isDecimal=pr,t.abs=cn,t.acos=fn,t.acosh=dn,t.add=hn,t.asin=pn,t.asinh=mn,t.atan=gn,t.atanh=_n,t.atan2=wn,t.cbrt=vn,t.ceil=Mn,t.clamp=bn,t.cos=kn,t.cosh=Sn,t.div=Pn,t.exp=An,t.floor=Cn,t.hypot=xn,t.ln=Dn,t.log=Tn,t.log10=Rn,t.log2=On,t.max=Ln,t.min=Nn,t.mod=In,t.mul=En,t.pow=Bn,t.random=qn,t.round=Fn,t.sign=Un,t.sin=jn,t.sinh=$n,t.sqrt=Wn,t.sub=Zn,t.sum=Kn,t.tan=zn,t.tanh=Gn,t.trunc=Hn,n===void 0&&(n={}),n&&n.defaults!==!0)for(o=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],i=0;i<o.length;)n.hasOwnProperty(r=o[i++])||(n[r]=this[r]);return t.config(n),t}function Pn(n,i){return new this(n).div(i)}function An(n){return new this(n).exp()}function Cn(n){return z(n=new this(n),n.e+1,3)}function xn(){var n,i,r=new this(0);for(Y=!1,n=0;n<arguments.length;)if(i=new this(arguments[n++]),i.d)r.d&&(r=r.plus(i.times(i)));else{if(i.s)return Y=!0,new this(1/0);r=i}return Y=!0,r.sqrt()}function pr(n){return n instanceof Oe||n&&n.toStringTag===wr||!1}function Dn(n){return new this(n).ln()}function Tn(n,i){return new this(n).log(i)}function On(n){return new this(n).log(2)}function Rn(n){return new this(n).log(10)}function Ln(){return yr(this,arguments,-1)}function Nn(){return yr(this,arguments,1)}function In(n,i){return new this(n).mod(i)}function En(n,i){return new this(n).mul(i)}function Bn(n,i){return new this(n).pow(i)}function qn(n){var i,r,o,t,a=0,d=new this(1),c=[];if(n===void 0?n=this.precision:Xt(n,1,we),o=Math.ceil(n/H),this.crypto)if(crypto.getRandomValues)for(i=crypto.getRandomValues(new Uint32Array(o));a<o;)t=i[a],t>=429e7?i[a]=crypto.getRandomValues(new Uint32Array(1))[0]:c[a++]=t%1e7;else if(crypto.randomBytes){for(i=crypto.randomBytes(o*=4);a<o;)t=i[a]+(i[a+1]<<8)+(i[a+2]<<16)+((i[a+3]&127)<<24),t>=214e7?crypto.randomBytes(4).copy(i,a):(c.push(t%1e7),a+=4);a=o/4}else throw Error(_r);else for(;a<o;)c[a++]=Math.random()*1e7|0;for(o=c[--a],n%=H,o&&n&&(t=$t(10,H-n),c[a]=(o/t|0)*t);c[a]===0;a--)c.pop();if(a<0)r=0,c=[0];else{for(r=-1;c[0]===0;r-=H)c.shift();for(o=1,t=c[0];t>=10;t/=10)o++;o<H&&(r-=H-o)}return d.e=r,d.d=c,d}function Fn(n){return z(n=new this(n),n.e+1,this.rounding)}function Un(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function jn(n){return new this(n).sin()}function $n(n){return new this(n).sinh()}function Wn(n){return new this(n).sqrt()}function Zn(n,i){return new this(n).sub(i)}function Kn(){var n=0,i=arguments,r=new this(i[n]);for(Y=!1;r.s&&++n<i.length;)r=r.plus(i[n]);return Y=!0,z(r,this.precision,this.rounding)}function zn(n){return new this(n).tan()}function Gn(n){return new this(n).tanh()}function Hn(n){return z(n=new this(n),n.e+1,1)}B[Symbol.for("nodejs.util.inspect.custom")]=B.toString;B[Symbol.toStringTag]="Decimal";var Oe=B.constructor=Pr(Ti);$e=new Oe($e);We=new Oe(We);var ht=Oe;import{compoundDebt as Xn}from"@suilend/sdk";var He=class{constructor(i){this.getPositionList=async(i=this._sdk.getSenderAddress(),r=!1)=>{let{lending_market_id:o,lending_market_type:t}=jt(this._sdk.sdkOptions.suilend);try{let a=`cap_to_position_mapping_${i}`,d=this._sdk.getCache(a,r),c=await this._sdk.FullClient.getOwnedObjectsByPage(i,{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{StructType:`${this._sdk.sdkOptions.margin_trading.package_id}::position::PositionCap`}]}});if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:42 ~ PositionModules ~ ownerRes.data.length:",c.data.length),c.data.length===0)return Gt("PositionNotFound","Position not found"),[];let m=await this._sdk.SuiLendModule.getSuilendClient(o,t);console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:48 ~ PositionModules ~ suiLendClient:",m);let{allLendingMarketData:g,lstAprPercentMap:M}=await this._sdk.SuiLendModule.getLendingMarketData();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:50 ~ PositionModules ~ allLendingMarketData:",g);let P=g[o].reserveMap;d||(d=new Map);let A=[];for(let N=0;N<c.data.length;N++){let R=Ar(c.data[N]);R.position_id&&A.push(R.position_id),R.id.id&&d.set(R.id.id,R.position_id)}await this._sdk.updateCache(a,d,Vn);let D=await this._sdk.FullClient.batchGetObjects(A,{showContent:!0});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:73 ~ PositionModules ~ positionRes:",D);let T=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:g,lstAprPercentMap:M},!0);console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:75 ~ PositionModules ~ obligations:",T);let L=[];for(let N=0;N<D.length;N++){let R=A[N],O="";for(let[Z,_]of d.entries())if(_===R){O=Z;break}let E=yi(D[N],O),q=await m.getObligation(E.obligation_owner_cap),W=ki(E,q,P||{},M||{},T[o].rewardMap),F=this.getObligationRewardsInfo(q,Object.values(P));L.push({...W,claimable_rewards:F})}return L}catch(a){return Gt("FetchError",a),[]}};this.getPositionInfo=async(i,r=this._sdk.getSenderAddress(),o=!0)=>{let t=`cap_to_position_mapping_${r}`,a=this._sdk.getCache(t,o);a||(a=new Map);let d=this.getCapIdByPositionId(i,r)||"";if(!d){let q=await this._sdk.FullClient.getOwnedObjectsByPage(r,{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{StructType:`${this._sdk.sdkOptions.margin_trading.package_id}::position::PositionCap`}]}});for(let W=0;W<q.data.length;W++){let F=Ar(q.data[W]);F.id.id&&a.set(F.id.id,F.position_id),F.position_id===i&&(d=F.id.id)}}let c=await this._sdk.FullClient.batchGetObjects([i],{showContent:!0}),m=yi(c[0],d||""),{lending_market_id:g,lending_market_type:M}=jt(this._sdk.sdkOptions.suilend),P=await this._sdk.SuiLendModule.getSuilendClient(g,M),{allLendingMarketData:A,lstAprPercentMap:D}=await this._sdk.SuiLendModule.getLendingMarketData(),T=A[g].reserveMap,L=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:A,lstAprPercentMap:D},!0),N=await P.getObligation(m.obligation_owner_cap),R=this.getObligationRewardsInfo(N,Object.values(T));return{...ki(m,N,T||{},D||{},L[g].rewardMap),claimable_rewards:R}};this.getCapIdByPositionId=(i,r=this._sdk.getSenderAddress())=>{let o=`cap_to_position_mapping_${r}`,t=this._sdk.getCache(o,!1);if(!t)return"";for(let[a,d]of t.entries())if(d===i)return a;return""};this.repay=i=>{let{margin_trading:r}=this._sdk.sdkOptions,{lending_market_id:o,lending_market_type:t}=jt(this._sdk.sdkOptions.suilend),{global_config_id:a,versioned_id:d}=jt(this._sdk.sdkOptions.margin_trading),{txb:c,repay_amount:m,repay_coin_type:g,repay_coin:M,repay_reserve_array_index:P,market_id:A,position_cap_id:D}=i,T=c||new ne,L=M||Q.buildCoinWithBalance(BigInt(m.toString()),g,T);T.moveCall({target:`${r.published_at}::router::repay`,typeArguments:[t,g],arguments:[T.object(a),T.object(o),T.object(A),T.object(D),L,T.pure.u64(P.toString()),T.object(be),T.object(d)]})};this.withdrawAsset=(i,r)=>{let{margin_trading:o}=this._sdk.sdkOptions,{lending_market_id:t,lending_market_type:a}=jt(this._sdk.sdkOptions.suilend),{global_config_id:d,versioned_id:c}=jt(this._sdk.sdkOptions.margin_trading),{package_id:m}=this._sdk.sdkOptions.suilend,{market_id:g,withdraw_amount:M,withdraw_reserve_array_index:P,withdraw_coin_type:A,position_cap_id:D}=i,[T]=r.moveCall({target:"0x1::option::none",typeArguments:[`${m}::lending_market::RateLimiterExemption<${a}, ${A}>`],arguments:[]});return r.moveCall({target:`${o.published_at}::router::withdraw`,typeArguments:[a,A],arguments:[r.object(d),r.object(t),r.object(g),r.object(D),r.object(T),r.pure.u64(M),r.pure.u64(P),r.object(Cr),r.object(be),r.object(c)]})};this.borrowAsset=(i,r)=>{let{reserve_array_index:o,borrow_amount:t,base_token:a,quote_token:d,lending_market_id:c,is_long:m,market_id:g,position_cap_id:M,position_cap:P}=i,{margin_trading:A}=this._sdk.sdkOptions,{lending_market_type:D}=jt(this._sdk.sdkOptions.suilend),{global_config_id:T,versioned_id:L}=jt(this._sdk.sdkOptions.margin_trading);return r.moveCall({target:`${A.published_at}::router::borrow`,typeArguments:[D,m?d:a],arguments:[r.object(T),r.object(c),r.object(g),M?r.object(M):P,r.pure.u64(o),r.pure.u64(t.toString()),r.object(Cr),r.object(be),r.object(L)]})};this.openPosition=async i=>{let{is_quote:r,is_long:o,amount:t,swap_clmm_pool:a="",slippage:d,leverage:c,market_id:m}=i,{lending_market_id:g}=jt(this._sdk.sdkOptions.suilend),M=new ne,{base_token:P,quote_token:A}=await this._sdk.MarketModules.getMarketInfo(m),{flash_amount:D,flash_loan_coin:T,is_flash_a:L,borrow_amount:N,clmm_pool_coin_type_a:R,clmm_pool_coin_type_b:O,clmm_pool:E,base_reserve_array_index:q,quote_reserve_array_index:W,reserve:F,has_swap:Z,routers:_}=await this.calculatePositionDeposit({is_long:o,is_quote:r,amount:t,swap_clmm_pool:a,leverage:c,slippage:d,market_id:m,base_token:P,quote_token:A,is_submit:!0});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:492 ~ PositionModules ~ routers:",_),await this._sdk.SuiLendModule.refreshReservePrices(M,F);let{balance_a:b,balance_b:S,receipt:C}=this._sdk.SwapModules.flashLoan({amount:D,clmm_pool:E,clmm_pool_coin_type_a:R,clmm_pool_coin_type_b:O,flash_loan_coin:T,tx:M}),x=o?A:P,p=o?P:A,e=Q.buildCoinWithBalance(BigInt(t),r?A:P,M),s=Q.fromBalance(b,R,M),l=Q.fromBalance(S,O,M);Z&&(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:515 ~ PositionModules ~ is_flash_a:",L),M.mergeCoins(e,[L?s:l])),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:521 ~ PositionModules ~ d(flash_amount).add(amount).toString():",I(D).add(t).toString(),x,p);let f=await this._sdk.SwapModules.handleSwap({from:x,to:p,amount:Z?I(D).add(t).toString():D,input_coin:Z?e:L?s:l,swap_clmm_pool:a,slippage:d,tx:M}),h=this.createLeveragePosition({leverage:c,market_id:m,base_token:P,quote_token:A,is_long:o,init_deposit_amount:I(t).toString(),init_coin_type:r?A:P,tx:M}),v=o?q:W;f.swap_out_coin&&!Z&&M.mergeCoins(f.swap_out_coin,[e]),await this.depositToLeveragePosition({is_long:o,market_id:m,position_cap:h,deposit_reserve_array_index:v,input_coin:f.swap_out_coin,base_token:P,quote_token:A},M),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:580 ~ PositionModules ~ borrow_amount:",N);let k=this.borrowAsset({position_cap:h,reserve_array_index:o?W:q,borrow_amount:N,base_token:P,quote_token:A,is_long:o,lending_market_id:g,market_id:m},M),w=Q.mintBalanceZero(L?O:R,M);return this._sdk.SwapModules.repayFlashLoan({tx:M,clmm_pool:E,repay_base:L?Q.intoBalance(k,R,M):w,repay_quote:L?w:Q.intoBalance(k,O,M),receipt:C,clmm_pool_coin_type_a:R,clmm_pool_coin_type_b:O}),M.transferObjects([h],M.pure.address(this._sdk.getSenderAddress())),Q.destroyBalanceZero(L?Q.intoBalance(l,O,M):Q.intoBalance(s,R,M),L?O:R,M),M};this.positionDeposit=async i=>{let{position_id:r,swap_clmm_pool:o="",is_quote:t,amount:a,slippage:d,leverage:c,txb:m}=i,{lending_market_id:g}=jt(this._sdk.sdkOptions.suilend),{is_long:M,deposits:P,borrows:A,position_cap_id:D,market_id:T}=await this.getPositionInfo(r),{base_token:L,quote_token:N}=await this._sdk.MarketModules.getMarketInfo(T),R=m||new ne,O=P[0].reserveArrayIndex.toString(),E=A[0].reserveArrayIndex.toString(),{flash_amount:q,flash_loan_coin:W,is_flash_a:F,borrow_amount:Z,clmm_pool_coin_type_a:_,clmm_pool_coin_type_b:b,clmm_pool:S,reserve:C,has_swap:x}=await this.calculatePositionDeposit({market_id:T,is_long:M,is_quote:t,amount:a,swap_clmm_pool:o,leverage:c,slippage:d,base_token:L,quote_token:N,position_id:r,is_open:!1});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:603 ~ PositionModules ~ flash_amount:",q),await this._sdk.SuiLendModule.refreshReservePrices(R,C);let{balance_a:p,balance_b:e,receipt:s}=this._sdk.SwapModules.flashLoan({amount:q,clmm_pool:S,clmm_pool_coin_type_a:_,clmm_pool_coin_type_b:b,flash_loan_coin:W,tx:R}),l=M?N:L,f=M?L:N,h=Q.buildCoinWithBalance(BigInt(a),t?N:L,R),v=Q.fromBalance(p,_,R),k=Q.fromBalance(e,b,R);x&&R.mergeCoins(h,[F?v:k]);let w=await this._sdk.SwapModules.handleSwap({from:l,to:f,amount:x?I(q).add(a).toString():q,input_coin:x?h:F?v:k,swap_clmm_pool:o,slippage:d,tx:R});w.swap_out_coin&&!x&&R.mergeCoins(w.swap_out_coin,[h]),await this.depositToLeveragePosition({is_long:M,market_id:T,position_cap_id:D,deposit_reserve_array_index:O,input_coin:w.swap_out_coin,base_token:L,quote_token:N},R);let u=await this.borrowAsset({position_cap_id:D,reserve_array_index:E,borrow_amount:Z,base_token:L,quote_token:N,is_long:M,lending_market_id:g,market_id:T},R),y=Q.mintBalanceZero(F?b:_,R);return this._sdk.SwapModules.repayFlashLoan({tx:R,clmm_pool:S,repay_base:F?Q.intoBalance(u,_,R):y,repay_quote:F?y:Q.intoBalance(u,b,R),receipt:s,clmm_pool_coin_type_a:_,clmm_pool_coin_type_b:b}),Q.destroyBalanceZero(F?Q.intoBalance(k,b,R):Q.intoBalance(v,_,R),F?b:_,R),R};this.positionWithdraw=async i=>{let{amount:r,is_quote:o,txb:t,swap_clmm_pool:a="",slippage:d,position_id:c,leverage:m}=i,g=t||new ne,{withdraw_ctoken_amount:M,repay_amount:P,is_close:A,deposits:D,borrows:T,reserve:L,base_token:N,quote_token:R,clmm_pool:O,clmm_pool_coin_type_a:E,clmm_pool_coin_type_b:q,position_cap_id:W,market_id:F,is_long:Z,swap_convert_all:_,flash_loan_amount:b,routers:S,repay_flash_loan_amount:C="0",partial_amount_in:x,withdraw_amount:p,has_flash_loan:e}=await this.calculatePositionWithdraw({position_id:c,is_quote:o,swap_clmm_pool:a,amount:r,leverage:m,slippage:d});if(A)return this.positionClose({position_id:c,is_quote:o,leverage:m,slippage:d,swap_clmm_pool:a});await this._sdk.SuiLendModule.refreshReservePrices(g,L);let s,l;if(e){let{balance_a:k,balance_b:w,receipt:u,is_loan_a:y}=this._sdk.SwapModules.flashLoan({tx:g,amount:b,flash_loan_coin:T[0].reserve.coinType,clmm_pool:O,clmm_pool_coin_type_a:E,clmm_pool_coin_type_b:q});s=u,l=y,Q.destroyBalanceZero(l?w:k,l?q:E,g);let $=y?Q.fromBalance(k,E,g):Q.fromBalance(w,q,g);this.repay({txb:g,position_cap_id:W,repay_reserve_array_index:T[0].reserveArrayIndex.toString(),repay_coin:$,repay_coin_type:Z?R:N,repay_amount:"0",market_id:F}),g.transferObjects([$],this._sdk.getSenderAddress())}let f=this.withdrawAsset({market_id:F,position_cap_id:W,withdraw_amount:M.toString(),withdraw_reserve_array_index:D[0].reserveArrayIndex.toString(),withdraw_coin_type:Z?N:R},g);for(let k=1;k<D.length;k++){let w=this.withdrawAsset({market_id:F,position_cap_id:W,withdraw_amount:Ni.toString(),withdraw_reserve_array_index:D[k].reserveArrayIndex.toString(),withdraw_coin_type:D[k].coinType},g);g.transferObjects([w],this._sdk.getSenderAddress())}let h;if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:778 ~ PositionModules ~ swap_convert_all:",{swap_convert_all:_,has_flash_loan:e}),_)h=await this._sdk.SwapModules.routerSwap({router:S?.route_obj,input_coin:f,slippage:d,txb:g});else{let k=g.splitCoins(f,[g.pure.u64(x?.toString()||"0")]);h=await this._sdk.SwapModules.routerSwap({router:S?.route_obj,input_coin:k,slippage:d,txb:g})}let v;if(h&&e&&(v=g.splitCoins(h,[g.pure.u64(C.toString())])),v&&e){let k=Q.mintBalanceZero(l?q:E,g);this._sdk.SwapModules.repayFlashLoan({tx:g,clmm_pool:O,repay_base:l?Q.intoBalance(v,E,g):k,repay_quote:l?k:Q.intoBalance(v,q,g),clmm_pool_coin_type_a:E,clmm_pool_coin_type_b:q,receipt:s})}else if(h){let k=g.splitCoins(h,[g.pure.u64(C.toString())]);this.repay({txb:g,position_cap_id:W,repay_reserve_array_index:T[0].reserveArrayIndex.toString(),repay_coin:k,repay_coin_type:Z?R:N,repay_amount:"0",market_id:F}),g.transferObjects([k],this._sdk.getSenderAddress())}return h&&g.transferObjects([h],this._sdk.getSenderAddress()),_||g.transferObjects([f],this._sdk.getSenderAddress()),g};this.positionClose=async i=>{let{position_id:r,is_quote:o,slippage:t,leverage:a,swap_clmm_pool:d=""}=i,{margin_trading:c}=this._sdk.sdkOptions,{global_config_id:m,versioned_id:g}=jt(this._sdk.sdkOptions.margin_trading),{lending_market_type:M,lending_market_id:P}=jt(this._sdk.sdkOptions.suilend),A=new ne,{deposits:D,borrows:T,base_token:L,quote_token:N,clmm_pool:R,clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:E,position_cap_id:q,market_id:W,swap_convert_all:F,routers:Z,partial_amount_in:_,is_long:b,flash_loan_amount:S,reserve:C,repay_flash_loan_amount:x="0",claimable_rewards:p}=await this.calculatePositionWithdraw({position_id:r,is_quote:o,swap_clmm_pool:d,amount:Ni.toString(),leverage:a,slippage:t});await this._sdk.SuiLendModule.refreshReservePrices(A,C);let e,s;if(I(S).gt(0)){let{balance_a:h,balance_b:v,receipt:k,is_loan_a:w}=this._sdk.SwapModules.flashLoan({tx:A,amount:S,flash_loan_coin:b?N:L,clmm_pool:R,clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:E});e=k,s=w,Q.destroyBalanceZero(s?v:h,s?E:O,A);let u=s?Q.fromBalance(h,O,A):Q.fromBalance(v,E,A);this.repay({txb:A,position_cap_id:q,repay_reserve_array_index:T[0].reserveArrayIndex.toString(),repay_coin:u,repay_coin_type:T[0].reserve.coinType,repay_amount:"0",market_id:W}),A.transferObjects([u],this._sdk.getSenderAddress())}let l=this.withdrawAsset({market_id:W,position_cap_id:q,withdraw_amount:Ni.toString(),withdraw_reserve_array_index:D[0].reserveArrayIndex.toString(),withdraw_coin_type:b?L:N},A);await this.buildClaimRewardsMoveCall(p,W,q,A);let f;if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:895 ~ PositionModules ~ swap_convert_all:",F),F)f=await this._sdk.SwapModules.routerSwap({router:Z?.route_obj,input_coin:l,slippage:t,txb:A});else if(_&&I(_).gt(0)){let h=A.splitCoins(l,[A.pure.u64(_?.toString()||"0")]);f=await this._sdk.SwapModules.routerSwap({router:Z?.route_obj,input_coin:h,slippage:t,txb:A})}if(f&&e){let h=Q.mintBalanceZero(s?E:O,A),v=A.splitCoins(f,[A.pure.u64(x?.toString()||"0")]);this._sdk.SwapModules.repayFlashLoan({tx:A,clmm_pool:R,repay_base:s?Q.intoBalance(v,O,A):h,repay_quote:s?h:Q.intoBalance(v,E,A),clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:E,receipt:e})}return A.moveCall({target:`${c.published_at}::router::close_position`,typeArguments:[M],arguments:[A.object(m),A.object(P),A.object(W),A.object(q),A.object(be),A.object(g)]}),f&&A.transferObjects([f],this._sdk.getSenderAddress()),F||A.transferObjects([l],this._sdk.getSenderAddress()),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:951 ~ PositionModules ~ tx:",A),A};this.positionLeverageIncrease=async i=>{let{current_leverage:r,target_leverage:o,swap_clmm_pool:t="",slippage:a,position_id:d}=i,{lending_market_id:c}=jt(this._sdk.sdkOptions.suilend),m=new ne,{flash_loan_amount:g,quote_token:M,base_token:P,reserve:A,deposits:D,borrow_amount:T,routers:L,position_cap_id:N,is_long:R,market_id:O,is_flash_loan:E}=await this.calculatePositionLeverage({position_id:d,current_leverage:r,target_leverage:o,swap_clmm_pool:t,slippage:a}),q=R?M:P;if(await this._sdk.SuiLendModule.refreshReservePrices(m,A),E){let{clmm_pool_coin_type_a:W,clmm_pool_coin_type_b:F,clmm_pool:Z}=await this._sdk.SwapModules.getFlashLoanPool(q,g?.toString()||""),{balance_a:_,balance_b:b,receipt:S,is_loan_a:C}=this._sdk.SwapModules.flashLoan({tx:m,amount:g?.toString()||"0",clmm_pool:Z,clmm_pool_coin_type_a:W,clmm_pool_coin_type_b:F,flash_loan_coin:q}),x=await this._sdk.SwapModules.routerSwap({router:L?.route_obj,input_coin:C?Q.fromBalance(_,W,m):Q.fromBalance(b,F,m),slippage:a,txb:m});this.depositToLeveragePosition({is_long:R,market_id:O,position_cap_id:N,deposit_reserve_array_index:D[0].reserveArrayIndex.toString(),input_coin:x,base_token:P,quote_token:M},m);let p=this.borrowAsset({position_cap_id:N,reserve_array_index:R?A[1].arrayIndex.toString():A[0].arrayIndex.toString(),borrow_amount:T,base_token:P,quote_token:M,is_long:R,lending_market_id:c,market_id:O},m),e=Q.mintBalanceZero(C?F:W,m);this._sdk.SwapModules.repayFlashLoan({tx:m,clmm_pool:Z,repay_base:C?Q.intoBalance(p,W,m):e,repay_quote:C?e:Q.intoBalance(p,F,m),receipt:S,clmm_pool_coin_type_a:W,clmm_pool_coin_type_b:F}),Q.destroyBalanceZero(C?b:_,C?F:W,m)}else{let W=this.borrowAsset({position_cap_id:N,reserve_array_index:R?A[1].arrayIndex.toString():A[0].arrayIndex.toString(),borrow_amount:T,base_token:P,quote_token:M,is_long:R,lending_market_id:c,market_id:O},m),F=await this._sdk.SwapModules.routerSwap({router:L?.route_obj,input_coin:W,slippage:a,txb:m});this.depositToLeveragePosition({is_long:R,market_id:O,position_cap_id:N,deposit_reserve_array_index:D[0].reserveArrayIndex.toString(),input_coin:F,base_token:P,quote_token:M},m)}return m};this.positionLeverageDecrease=async i=>{let{current_leverage:r,target_leverage:o,swap_clmm_pool:t="",slippage:a,position_id:d}=i,{deposits:c,borrows:m,position_cap_id:g,market_id:M,is_long:P}=await this.getPositionInfo(d),{base_token:A,quote_token:D}=await this._sdk.MarketModules.getMarketInfo(M),T=new ne,{withdraw_ctoken_amount:L,routers:N,reserve:R,is_flash_loan:O}=await this.calculatePositionLeverage({position_id:d,current_leverage:r,target_leverage:o,swap_clmm_pool:t,slippage:a});if(await this._sdk.SuiLendModule.refreshReservePrices(T,R),O){let{clmm_pool_coin_type_a:E,clmm_pool_coin_type_b:q,clmm_pool:W,clmm_fee_tier:F}=await this._sdk.SwapModules.getFlashLoanPool(c[0].reserve.coinType,L.toString()),{balance_a:Z,balance_b:_,receipt:b,is_loan_a:S}=this._sdk.SwapModules.flashLoan({tx:T,amount:L,clmm_pool:W,clmm_pool_coin_type_a:E,clmm_pool_coin_type_b:q,flash_loan_coin:c[0].reserve.coinType}),C=await this._sdk.SwapModules.routerSwap({router:N?.route_obj,input_coin:S?Q.fromBalance(Z,E,T):Q.fromBalance(_,q,T),slippage:a,txb:T});this.repay({txb:T,market_id:M,position_cap_id:g,repay_reserve_array_index:m[0].reserveArrayIndex.toString(),repay_coin:C,repay_coin_type:P?D:A,repay_amount:"0"}),C&&T.transferObjects([C],this._sdk.getSenderAddress());let x=I(L).mul(F).toString(),p=I(L).add(x).toDP(0,ht.ROUND_UP),e=this.withdrawAsset({market_id:M,position_cap_id:g,withdraw_amount:p.toString(),withdraw_reserve_array_index:c[0].reserveArrayIndex.toString(),withdraw_coin_type:P?A:D},T),s=T.splitCoins(e,[p.toString()]);this._sdk.SwapModules.repayFlashLoan({tx:T,clmm_pool:W,repay_base:S?Q.intoBalance(s,E,T):Z,repay_quote:S?_:Q.intoBalance(s,q,T),receipt:b,clmm_pool_coin_type_a:E,clmm_pool_coin_type_b:q}),T.transferObjects([e],this._sdk.getSenderAddress())}else{let E=this.withdrawAsset({market_id:M,position_cap_id:g,withdraw_amount:L.toString(),withdraw_reserve_array_index:c[0].reserveArrayIndex.toString(),withdraw_coin_type:P?A:D},T),q=await this._sdk.SwapModules.routerSwap({router:N?.route_obj,input_coin:E,slippage:a,txb:T});this.repay({txb:T,market_id:M,position_cap_id:g,repay_reserve_array_index:m[0].reserveArrayIndex.toString(),repay_coin:q,repay_coin_type:P?D:A,repay_amount:"0"}),T.transferObjects([q],this._sdk.getSenderAddress())}return T};this.positionRepay=async i=>{let{position_id:r,amount:o,is_quote:t,slippage:a}=i,{routers:d,repay_coin_type:c,base_token:m,quote_token:g,borrows:M,deposits:P,market_id:A,position_cap_id:D}=await this.calculatePositionRepay({position_id:r,amount:o,is_quote:t}),T=this.extractOtherTokenTypes(P,M,m,g),{reserve:L}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(m,g,void 0,T),N=new ne;await this._sdk.SuiLendModule.refreshReservePrices(N,L);let R=t?g!==c:m!==c,O;if(R){let E=Q.buildCoinWithBalance(BigInt(o.toString()),t?g:m,N);O=await this._sdk.SwapModules.routerSwap({router:d?.route_obj,input_coin:E,slippage:a,txb:N})}else O=Q.buildCoinWithBalance(BigInt(o.toString()),t?g:m,N);return this.repay({txb:N,position_cap_id:D,repay_reserve_array_index:M[0].reserveArrayIndex.toString(),repay_coin:O,repay_coin_type:c,repay_amount:"0",market_id:A}),N.transferObjects([O],this._sdk.getSenderAddress()),N};this.positionTopUpCToken=async i=>{let{position_id:r,amount:o,is_quote:t,swap_clmm_pool:a="",slippage:d}=i,c=new ne,{is_long:m,market_id:g,position_cap_id:M,deposits:P,borrows:A}=await this.getPositionInfo(r),{base_token:D,quote_token:T}=await this._sdk.MarketModules.getMarketInfo(g),L=m&&t||!m&&!t,N=this.extractOtherTokenTypes(P,A,D,T),{base_reserve_array_index:R,quote_reserve_array_index:O,reserve:E}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(D,T,void 0,N);await this._sdk.SuiLendModule.refreshReservePrices(c,E);let q;if(L){let W=await this._sdk.SwapModules.findRouters(t?T:D,t?D:T,o,!0,[a]),F=Q.buildCoinWithBalance(BigInt(o.toString()),t?T:D,c);q=await this._sdk.SwapModules.routerSwap({router:W?.route_obj,input_coin:F,slippage:d,txb:c})}else q=Q.buildCoinWithBalance(BigInt(o.toString()),t?T:D,c);return await this.depositToLeveragePosition({is_long:m,market_id:g,position_cap_id:M,deposit_reserve_array_index:m?R:O,input_coin:q,base_token:D,quote_token:T},c),c};this.positionWithdrawCToken=async i=>{let{position_id:r,amount:o,is_quote:t,swap_clmm_pool:a="",slippage:d}=i,c=new ne,{is_long:m,market_id:g,position_cap_id:M,deposits:P,borrows:A}=await this.getPositionInfo(r),{base_token:D,quote_token:T}=await this._sdk.MarketModules.getMarketInfo(g),L=m&&t||!m&&!t,N=this.extractOtherTokenTypes(P,A,D,T),{base_reserve_array_index:R,quote_reserve_array_index:O,reserve:E}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(D,T,void 0,N);await this._sdk.SuiLendModule.refreshReservePrices(c,E);let q=await this._sdk.SuiLendModule.getLatestPriceFeeds(E,!0),W=q[xe(T)]?.price,F=q[xe(D)]?.price,Z=m?I(W).div(I(F)).toString():I(F).div(I(W)).toString(),_=E[0].mintDecimals,b=E[1].mintDecimals,S=L?I(o).mul(Z).div(10**(t?b:_)).mul(10**(m?_:b)).toDP(0,ht.ROUND_DOWN).toString():o.toString(),C=this.withdrawAsset({market_id:g,position_cap_id:M,withdraw_amount:S,withdraw_reserve_array_index:m?R:O,withdraw_coin_type:m?D:T},c);if(L){let x=await this._sdk.SwapModules.findRouters(m?D:T,t?T:D,S,!0,[a]),p=await this._sdk.SwapModules.routerSwap({router:x?.route_obj,input_coin:C,slippage:d,txb:c});p&&c.transferObjects([p],this._sdk.getSenderAddress())}else c.transferObjects([C],this._sdk.getSenderAddress());return c};this.positionClaim=async i=>{let r=new ne,{position_cap_id:o,obligation_owner_cap:t,market_id:a,claimable_rewards:d}=await this.getPositionInfo(i);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1650 ~ PositionModules ~ claimable_rewards:",d),await this.buildClaimRewardsMoveCall(d,a,o,r),r};this.calculatePositionDeposit=async i=>{let{is_quote:r,is_long:o,amount:t,swap_clmm_pool:a="",leverage:d,by_amount_in:c=!0,base_token:m,quote_token:g,is_submit:M=!1,is_open:P=!0,position_id:A}=i,D=[],T=[],L=[];if(!P&&A){let{deposits:rt,borrows:V}=await this.getPositionInfo(A);T=rt,L=V,D=this.extractOtherTokenTypes(T,L,m,g)}let{reserve:N,base_reserve_array_index:R,quote_reserve_array_index:O}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(m,g,void 0,D),E=N[0].mintDecimals,q=N[1].mintDecimals,W=t.toString(),F=o&&r||!o&&!r,Z=await this._sdk.SuiLendModule.getLatestPriceFeedsByCoinTypes([m,g]),_=Z&&Z[g]?.price,b=Z&&Z[m]?.price;if(!_||!b)throw Gt("PriceNotFound","Price not found");if(F&&M){let rt=o?I(_).div(I(b)).toString():I(b).div(I(_)).toString();W=I(t).mul(rt).div(10**(r?q:E)).mul(10**(o?E:q)).toString(),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:492 ~ PositionModules ~ initDepositAmount:",{initDepositAmount:W,rate:rt})}else if(F&&!M){let rt=o?g:m,V=o?m:g;W=(await this._sdk.SwapModules.findRouters(rt,V,W,!0,[a]))?.amount_out.toString()}else W=t;let{base_price:S,quote_price:C,flash_amount:x,flash_loan_fee:p,flash_loan_coin:e,is_flash_a:s,clmm_pool:l,clmm_fee_tier:f,clmm_pool_coin_type_a:h,clmm_pool_coin_type_b:v}=await this._sdk.SwapModules.calculateFlashLoan({is_long:o,leverage:d,base_token:m,quote_token:g,deposit_amount:W,reserve:N,base_token_decimal:E,quote_token_decimal:q}),k=await this._sdk.SwapModules.findRouters(o?g:m,o?m:g,x.toString(),!0,[a]),w=I(W).add(I(k?.amount_out.toString())).toDP(0,ht.ROUND_DOWN).toString(),u=I(w).mul(o?S:C).toString(),y=I(x).add(p).toDP(0,ht.ROUND_UP).toString(),$=I(y).mul(o?C:S).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1575 ~ PositionModules ~ depositAmount:",{depositAmount:w,borrowAmount:y});let U=r?I(t).div(10**(r?q:E)).mul(10**E).mul(d).div(S).toDP(0,ht.ROUND_DOWN).toString():I(t).mul(d).toDP(0,ht.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1583 ~ PositionModules ~ leverageDepositAmount:",U);let j="0",K="0",G="0",J="0";return!P&&A&&(L&&L.length>0&&(j=I(L[0].borrowedAmount.toString()).mul(o?10**q:10**E).add(I(y)).toString(),K=I(j).mul(o?_:b).toString()),G=I(T[0].depositedAmount.toString()).mul(o?10**E:10**q).add(I(w)).toString(),J=I(G).mul(o?b:_).toString()),{routers:k,leverage_deposit_amount:U,quote_price:C,base_price:S,clmm_fee_tier:f,flash_loan_fee:p,flash_loan_coin:e,deposit_amount:w,borrow_amount:y,deposit_amount_usd:u,borrow_amount_usd:$,after_borrow_amount:j,after_borrow_amount_usd:K,after_deposit_amount:G,after_deposit_amount_usd:J,flash_amount:x,is_flash_a:s,init_deposit_amount:W,clmm_pool_coin_type_a:h,clmm_pool_coin_type_b:v,clmm_pool:l,base_reserve_array_index:R,quote_reserve_array_index:O,reserve:N,has_swap:F}};this.calculatePositionWithdraw=async i=>{let{position_id:r,is_quote:o,swap_clmm_pool:t="",amount:a,leverage:d,slippage:c,withdraw_max:m}=i,{deposits:g,borrows:M,origin_obligation:P,position_cap_id:A,market_id:D,is_long:T,claimable_rewards:L}=await this.getPositionInfo(r),{base_token:N,quote_token:R}=await this._sdk.MarketModules.getMarketInfo(D),O=r?this.extractOtherTokenTypes(g,M,N,R):[],{reserve:E,base_reserve_map_info:q,quote_reserve_map_info:W}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(N,R,void 0,O),F=E[0].mintDecimals,Z=E[1].mintDecimals,_=T?q.cTokenExchangeRate:W.cTokenExchangeRate,b=await this._sdk.SuiLendModule.getLatestPriceFeeds(E,!0),S=b[xe(R)]?.price,C=b[xe(N)]?.price,x=I(0),p;T?(x=I(o?I(a).mul(S).toString():I(a).mul(C).toString()).div(o?10**Z:10**F),p=o?I(a).div(C).div(10**Z).mul(10**F).toString():I(a)):(x=I(o?I(a).mul(S).toString():I(a).mul(C).toString()).div(o?10**Z:10**F),p=o?I(a):I(a).mul(C).div(10**F).mul(10**Z).toString());let e=I(g[0].depositedAmountUsd.toString()).sub(I(M&&M.length>0?M[0].borrowedAmountUsd.toString():"0")).toString(),s=x.div(I(e)),l=m||I(s).gte(1),f,h=new ht(0);P&&P.borrows&&P.borrows.length>0&&(f=Xn(P.borrows[0],T?E[1]:E[0]),h=I(f.borrowedAmount.value.toString()).div(10**18).toDP(0,ht.ROUND_UP));let v=h.mul(l?1:s).toDP(0,ht.ROUND_UP).toString(),k=v.toString(),w,u,y,$,U,j;if(I(v).gt(0)){let{clmm_pool_coin_type_a:nt,clmm_pool_coin_type_b:ot,clmm_fee_tier:ue,clmm_pool:dt}=await this._sdk.SwapModules.getFlashLoanPool(T?R:N,k);U=nt||"",j=ot||"",y=ue||0,$=dt||"",w=I(k).mul(ue).toString(),u=I(k).mul(I(1).add(ue)).toDP(0,ht.ROUND_UP).toString()}let K=T&&o||!T&&!o,G,J;if(K){let nt=I(g[0].depositedAmount.toString()).mul(10**(T?F:Z)).mul(l?1:s).toDP(0,ht.ROUND_DOWN).toString();G=await this._sdk.SwapModules.findRouters(g[0].reserve.coinType,T?R:N,nt,!0,[t])}else{let ot=N==="0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC"||R==="0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC"?.01:.0025;J=I(v).mul(T?S:C).div(10**(T?Z:F)).mul(10**(T?F:Z)).div(T?C:S).mul(I(1).add(ot)).toDP(0,ht.ROUND_DOWN).toString(),G=await this._sdk.SwapModules.findRouters(g[0].reserve.coinType,T?R:N,J.toString(),!0,[t]),l||(v=I(G?.amount_out.toString()).mul(I(1).sub(c)).toDP(0,ht.ROUND_DOWN).toString())}p=I(p).mul(d).toDP(0,ht.ROUND_DOWN).toString(),x=I(x).mul(d);let rt=h.mul(I(1).sub(s)).toString(),V=I(rt).mul(T?S:C).toString(),it=I(g[0].depositedAmount.toString()).mul(T?10**F:10**Z).sub(I(p)).toString(),ut=I(it).mul(T?C:S).toString(),et=I(G?.amount_in.toString()).toString(),X=I(G?.amount_out.toString()).toString(),de=I(p).div(_.toString()).toDP(0,ht.ROUND_DOWN).toString(),ct=I(V).div(I(10**(T?Z:F))),at=I(ut).div(I(10**(T?F:Z))),ke=!0;if(M.length>0){let nt=I(M[0].borrowedAmountUsd.toString()),ot=nt.div(at).toString(),ue=I(g[0].reserve.config.openLtvPct).mul(I(.95)).div(100).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1459 ~ PositionModules ~ afterLTV:",{afterLTV:ot,ltv:ue,afterDepositAmount:it,afterDepositAmountUSD:at,afterBorrowAmount:rt,afterBorrowAmountUSD:ct,withdrawAmount:p,currentBorrowAmountUSD:nt}),I(ot).lte(ue)&&(ke=!1)}return{amount_in:et,amount_out:X,from:g[0].reserve.coinType,to:T?N:R,after_borrow_amount:rt,after_borrow_amount_usd:V,after_deposit_amount:it,after_deposit_amount_usd:ut,flash_loan_fee:w,clmm_fee_tier:y,withdraw_amount:p,withdraw_ctoken_amount:de,repay_amount:v,ratio:s,is_close:l,is_long:T,deposits:g,borrows:M,reserve:E,base_token:N,quote_token:R,clmm_pool:$,clmm_pool_coin_type_a:U,clmm_pool_coin_type_b:j,position_cap_id:A,market_id:D,swap_convert_all:K,flash_loan_amount:k,routers:G,repay_flash_loan_amount:u,partial_amount_in:J,has_flash_loan:ke,claimable_rewards:L}};this.calculatePositionLeverage=async i=>{let{position_id:r,current_leverage:o,target_leverage:t,swap_clmm_pool:a=""}=i,d=I(t).sub(I(o)),c=d.gt(0),{borrows:m,deposits:g,is_long:M,position_cap_id:P,market_id:A}=await this.getPositionInfo(r),{base_token:D,quote_token:T}=await this._sdk.MarketModules.getMarketInfo(A),L=this.extractOtherTokenTypes(g,m,D,T),{reserve:N}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(D,T,void 0,L),R=N[0].mintDecimals,O=N[1].mintDecimals,E=await this._sdk.SuiLendModule.getLatestPriceFeeds(N,!0),q=E[xe(T)]?.price,W=E[xe(D)]?.price,F=m.length>0,Z=g[0].depositedAmountUsd.toString(),_=g[0].depositedAmount.toString(),b=F?I(m[0].borrowedAmount.toString()).mul(10**(M?O:R)):I(0),S=F?m[0].borrowedAmountUsd.toString():I(0),C=F?I(m[0].reserve.config.borrowWeightBps.toString()).div(1e4).toString():"1",x=I(g[0].reserve.config.openLtvPct).mul(I(.95)).div(100).div(C).toString(),p=I(Z).sub(I(S)).mul(x).toString();if(c){let e=I(Z).div(o).mul(d),s=e.add(S).div(Z).toString(),l=e.div(M?q:W).mul(10**(M?O:R)).toDP(0,ht.ROUND_UP),f=I(s).gt(x),h=l,v=M?T:D,k=M?D:T,w=await this._sdk.SwapModules.findRouters(v,k,h.toString(),!0,[a]),u=I(w?.amount_out.toString()).toString(),y=I(u).mul(M?W:q).toString(),$,U,j,K,G,J="0",rt="0";if(f){let{clmm_pool_coin_type_a:X,clmm_pool_coin_type_b:de,clmm_pool:ct,clmm_fee_tier:at}=await this._sdk.SwapModules.getFlashLoanPool(v,h.toString());j=at,K=X,G=de,$=h.mul(j).toString(),U=M?K==T:G==D,J=I(h).add($).toDP(0,ht.ROUND_UP).toString(),rt=I(J).mul(M?q:W).toString()}else J=l.toString(),rt=e.toString();let V=I(_).add(I(u).div(10**(M?R:O))).toString(),it=I(V).mul(M?W:q).toString(),ut=I(b).add(I(J)).div(10**(M?O:R)).toString(),et=I(ut).mul(M?q:W).toString();return{amount_in:w?.amount_in.toString(),amount_out:w?.amount_out.toString(),flash_loan_fee:$,deposit_amount:u,borrow_amount:J,deposit_amount_usd:y,borrow_amount_usd:rt,flash_loan_amount:h,base_token:D,quote_token:T,reserve:N,deposits:g,borrows:m,clmm_fee_tier:j,is_flash_loan:f,is_loan_a:U,clmm_pool_coin_type_a:K,clmm_pool_coin_type_b:G,after_deposit_amount:V,after_borrow_amount:ut,after_deposit_amount_usd:it,after_borrow_amount_usd:et,position_cap_id:P,market_id:A,is_long:M,routers:w}}else{let s=I(Z).div(o).mul(d.abs()).div(M?q:W).mul(10**(M?O:R)).toDP(0,ht.ROUND_UP),l=await this._sdk.SwapModules.findRouters(g[0].reserve.coinType,m[0].reserve.coinType,s.toString(),!1,[a]),f=l?.amount_in.toString(),h=I(f).mul(M?W:q).div(10**(M?R:O)).toString(),v=I(Z).mul(x).toString(),k=I(S).div(I(Z).sub(I(h))).toString(),w=I(k).gt(x),u=s.toString(),y=I(u).mul(M?q:W).toString(),$=f,U=I($).mul(M?W:q).toString(),j,K="",G="";if(w){let{clmm_pool_coin_type_a:ut,clmm_pool_coin_type_b:et,clmm_pool:X,clmm_fee_tier:de}=await this._sdk.SwapModules.getFlashLoanPool(m[0].reserve.coinType,u.toString());j=de,K=ut,G=et}let J=I(_).sub(I($).div(10**(M?R:O))).toString(),rt=I(J).mul(M?W:q).toString(),V=I(b).sub(I(u)).div(10**(M?O:R)).toString(),it=I(V).mul(M?q:W).toString();return{amount_in:l?.amount_in.toString(),amount_out:l?.amount_out.toString(),deposit_amount:$,borrow_amount:u,deposit_amount_usd:U,borrow_amount_usd:y,base_token:D,quote_token:T,reserve:N,deposits:g,borrows:m,clmm_fee_tier:j,withdraw_ctoken_amount:f,is_flash_loan:w,clmm_pool_coin_type_a:K,clmm_pool_coin_type_b:G,after_deposit_amount:J,after_borrow_amount:V,after_deposit_amount_usd:rt,after_borrow_amount_usd:it,position_cap_id:P,market_id:A,is_long:M,routers:l}}};this.calculatePositionRepay=async i=>{let{position_id:r,amount:o,is_quote:t}=i,{borrows:a,deposits:d,is_long:c,market_id:m,position_cap_id:g}=await this._sdk.PositionModules.getPositionInfo(r),M=a[0].reserve.coinType,P=c?d[0].reserve.coinType:a[0].reserve.coinType,A=c?a[0].reserve.coinType:d[0].reserve.coinType,D,T=c?!t:t;return T&&(D=await this._sdk.SwapModules.findRouters(t?A:P,M,o,!0,[])),{routers:D,repay_coin_type:M,base_token:P,quote_token:A,is_long:c,borrows:a,deposits:d,market_id:m,position_cap_id:g,has_swap:T}};this._sdk=i}getObligationRewardsInfo(i,r){let o=[],t=new lt(10).pow(18),a={},d=Date.now();for(let m of r){let g=m.coinType,M=m.arrayIndex.toString(),P=m.depositsPoolRewardManager.poolRewards||[];for(let D of P){if(!D)continue;let T=D.id,L=D.coinType,N=parseInt(D.startTimeMs),R=parseInt(D.endTimeMs),O=d>=N&&d<R,E=D.mintDecimals,q=lt(D.cumulativeRewardsPerShare).times(10**E);a[T]={coinType:L,mintDecimals:E,isActive:O,reserveType:"deposit",reserveArrayIndex:M,reserveCoinType:g,globalCumulativePerShare:q,rewardIndex:D.rewardIndex,reserve:m}}let A=m.borrowsPoolRewardManager.poolRewards||[];for(let D of A){if(!D)continue;let T=D.id,L=D.coinType,N=parseInt(D.startTimeMs),R=parseInt(D.endTimeMs),O=d>=N&&d<R,E=D.mintDecimals,q=lt(D.cumulativeRewardsPerShare).times(10**E);a[T]={coinType:L,mintDecimals:E,isActive:O,reserveType:"borrow",reserveCoinType:g,reserveArrayIndex:M,rewardIndex:D.rewardIndex,globalCumulativePerShare:q,reserve:m}}}let c=i.userRewardManagers;for(let m of c)for(let g=0;g<m.rewards.length;g++){let M=m.rewards[g];if(!M)continue;let P=a[M.poolRewardId];if(!P)continue;let A=P.globalCumulativePerShare,D=new lt(M.cumulativeRewardsPerShare.value.toString()).div(t),T=new lt(m.share).times(A.minus(D)),L=new lt(M.earnedRewards.value).div(t),N=new lt(L).plus(T),R=P.reserve.price,O=N.div(10**P.mintDecimals),E=R?O.times(R).toFixed(12):0;I(E).gt(0)&&o.push({poolRewardId:M.poolRewardId,coinType:P.coinType,earnedRewards:N.toString(),earnedRewardsUsd:E,earnedRewardsFormatted:O.toFixed(12),isActive:P.isActive,reserveType:P.reserveType,reserveCoinType:P.reserveCoinType,reserveArrayIndex:P.reserveArrayIndex,rewardIndex:P.rewardIndex,rewardInfo:P})}return o}createLeveragePosition(i){let{lending_market_id:r,lending_market_type:o}=jt(this._sdk.sdkOptions.suilend),{global_config_id:t,versioned_id:a}=jt(this._sdk.sdkOptions.margin_trading),d=this._sdk.sdkOptions.margin_trading,{leverage:c,market_id:m,base_token:g,quote_token:M,is_long:P,init_deposit_amount:A,tx:D,init_coin_type:T}=i;return D.moveCall({target:`${d.published_at}::router::open_position`,arguments:[D.object(t),D.object(m),D.object(r),D.pure.u64(A),D.pure.u64(I(c).mul(1e4).toString()),D.object(be),D.object(a)],typeArguments:[o,P?g:M,T]})}async depositToLeveragePosition(i,r){let{margin_trading:o}=this._sdk.sdkOptions,{lending_market_type:t,lending_market_id:a}=jt(this._sdk.sdkOptions.suilend),{is_long:d,market_id:c,position_cap_id:m,position_cap:g,deposit_reserve_array_index:M,input_coin:P,base_token:A,quote_token:D}=i,{global_config_id:T,versioned_id:L}=jt(this._sdk.sdkOptions.margin_trading);return r.moveCall({target:`${o.published_at}::router::deposit`,typeArguments:[t,d?A:D],arguments:[r.object(T),r.object(a),r.object(c),m?r.object(m):g,P,r.pure.u64(M),r.object(be),r.object(L)]}),r}extractOtherTokenTypes(i,r,o,t){let a=[];return i.forEach(d=>{d.reserve.coinType!==o&&d.reserve.coinType!==t&&a.push(d.reserve.coinType)}),r.forEach(d=>{d.reserve.coinType!==o&&d.reserve.coinType!==t&&a.push(d.reserve.coinType)}),a}async buildClaimRewardsMoveCall(i,r,o,t){let{suilend:a,margin_trading:d}=this._sdk.sdkOptions,c=jt(a).lending_market_id,m=jt(a).lending_market_type,{global_config_id:g,versioned_id:M}=jt(this._sdk.sdkOptions.margin_trading);for(let P=0;P<i.length;P++){let A=t.moveCall({target:`${d.published_at}::router::claim_rewards`,arguments:[t.object(g),t.object(c),t.object(r),t.object(o),t.pure.u64(i[P].reserveArrayIndex.toString()),t.pure.u64(i[P].rewardIndex.toString()),t.pure.bool(i[P].reserveType==="deposit"),t.object(be),t.object(M)],typeArguments:[m,i[P].coinType]});t.transferObjects([A],this._sdk.getSenderAddress())}}};import{SuilendClient as so}from"@suilend/sdk/client";import{initializeSuilend as ao,initializeSuilendRewards as lo,initializeObligations as uo,formatRewards as co,Side as ve,getFilteredRewards as fo,getStakingYieldAprPercent as ho,getDedupedPerDayRewards as po,getDedupedAprRewards as mo,getTotalAprPercent as Rr,getNetAprPercent as go}from"@suilend/sdk";import{linearlyInterpolate as to,Side as ye}from"@suilend/sdk";import{NORMALIZED_flSUI_COINTYPE as eo,NORMALIZED_jugSUI_COINTYPE as io,NORMALIZED_LBTC_COINTYPE as ro,formatLtvPercent as no}from"@suilend/sui-fe";import Jn from"crypto";var Xe=new Uint8Array(256),Ve=Xe.length;function Ii(){return Ve>Xe.length-16&&(Jn.randomFillSync(Xe),Ve=0),Xe.slice(Ve,Ve+=16)}var Kt=[];for(let n=0;n<256;++n)Kt.push((n+256).toString(16).slice(1));function xr(n,i=0){return Kt[n[i+0]]+Kt[n[i+1]]+Kt[n[i+2]]+Kt[n[i+3]]+"-"+Kt[n[i+4]]+Kt[n[i+5]]+"-"+Kt[n[i+6]]+Kt[n[i+7]]+"-"+Kt[n[i+8]]+Kt[n[i+9]]+"-"+Kt[n[i+10]]+Kt[n[i+11]]+Kt[n[i+12]]+Kt[n[i+13]]+Kt[n[i+14]]+Kt[n[i+15]]}import Yn from"crypto";var Ei={randomUUID:Yn.randomUUID};function Qn(n,i,r){if(Ei.randomUUID&&!i&&!n)return Ei.randomUUID();n=n||{};let o=n.random||(n.rng||Ii)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,i){r=r||0;for(let t=0;t<16;++t)i[r+t]=o[t];return i}return xr(o)}var Je=Qn;import{getPackagerConfigs as oo}from"@cetusprotocol/common-sdk";var Bi=10n;function Dr(n){return n.depositedAmount.eq(0)?new lt(0):n.borrowedAmount.div(n.depositedAmount).times(100)}function qi(n){let i=Dr(n);if(!i.gt(100))return to(n.config.interestRate,"utilPercent","aprPercent",i)}function Tr(n){let i=Dr(n),r=qi(n);if(!(r===void 0||i.gt(100)))return new lt(i.div(100)).times(r.div(100)).times(1-n.config.spreadFeeBps/1e4).times(100)}function ys(n,i,r,o){let{api_url:t}=oo(o.sdkOptions.suilend);n===ye.DEPOSIT&&([eo,io].includes(i.coinType)&&r.push({stats:{id:Je(),isActive:!0,rewardIndex:-1,reserve:i,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${t}/partners/LiqAg.png`,perDay:new lt(.036),side:ye.DEPOSIT},obligationClaims:{}}),i.coinType===ro&&r.push({stats:{id:Je(),isActive:!0,rewardIndex:-1,reserve:i,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${t}/partners/Lombard Lux.png`,perDay:new lt(0),side:ye.DEPOSIT},obligationClaims:{}}))}function ks(n,i,r){return{...n,depositedAmount:i===ye.DEPOSIT?lt.max(n.depositedAmount.plus(r),0):n.depositedAmount,borrowedAmount:i===ye.BORROW?lt.max(n.borrowedAmount.plus(r),0):n.borrowedAmount}}function Ss(n,i,r){let o=n===ye.DEPOSIT?i.depositedAmount:i.borrowedAmount,t=n===ye.DEPOSIT?r.depositedAmount:r.borrowedAmount,a=t.eq(0)?new lt(-1):o.div(t);return{multiplier:a,isValid:!a.eq(-1)}}function Ps(n,i,r,o){let t=n.map(d=>({...d,stats:{...d.stats,perDay:o?d.stats.perDay.times(r):void 0}})),a=i.map(d=>({...d,stats:{...d.stats,aprPercent:o?d.stats.aprPercent.times(r):void 0}}));return{newPerDayRewards:t,newAprRewards:a}}function Or(n,i){if(!Bi)throw new Error("oraclePriceMultiplierDecimal is required");if(n===0n)throw new Error("Invalid oracle price");if(i<0n){let r=10n**(Bi- -i);return n*r}return n/10n**(i+Bi)}function As(n){return no(new lt(n))}import{d as Fi,getPackagerConfigs as De,removeHexPrefix as Ye}from"@cetusprotocol/common-sdk";import{toHEX as Lr}from"@mysten/sui/utils";var Qe=class{constructor(i){this.getCoinAprByAmount=async(i,r,o)=>{let t=new lt(r.toString()),{allLendingMarketData:a,lstAprPercentMap:d}=await this.getLendingMarketData(!1);if(await this.getInitializeObligations({allLendingMarketData:a,lstAprPercentMap:d},!0),!a||!d)throw new Error("lendingMarketCache is not initialized");let c=Object.values(a??{})[0],m=c.lendingMarket.reserves.find(_=>_.coinType===i);if(!m)throw new Error("reserve not found");let M=(this.obligationsCache?.[c.lendingMarket.id]).rewardMap[m.token.coinType]?.[o]??[],P=fo(M),A=ho(o,m.coinType,d),D=o===ve.DEPOSIT?m.depositAprPercent:m.borrowAprPercent,T=D,L=new lt(1),N=!0;if(o!==void 0&&t!==void 0&&t.gt(0)){let _={...m,depositedAmount:o===ve.DEPOSIT?lt.max(m.depositedAmount.plus(o===ve.DEPOSIT?t:t.negated()),0):m.depositedAmount,borrowedAmount:o===ve.BORROW?lt.max(m.borrowedAmount.plus(o===ve.BORROW?t:t.negated()),0):m.borrowedAmount};T=o===ve.DEPOSIT?Tr(_):qi(_);let b=o===ve.DEPOSIT?m.depositedAmount:m.borrowedAmount,S=o===ve.DEPOSIT?_.depositedAmount:_.borrowedAmount;L=S.eq(0)?new lt(-1):b.div(S),N=!L.eq(-1)}let E=po(P).map(_=>({..._,stats:{..._.stats,perDay:N?_.stats.perDay.times(L):void 0}})),W=mo(P).map(_=>({..._,stats:{..._.stats,aprPercent:N?_.stats.aprPercent.times(L):void 0}})),F=Rr(o,D,P,A),Z=T===void 0||W.some(_=>_.stats.aprPercent===void 0)?void 0:Rr(o,T,W,A);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:315 ~ SuiLendModule ~ newTotalAprPercent:",Z?.toString()),{new_total_apr_percent:Z?.toString(),total_apr_percent:F.toString()}};this.refreshReservePrice=async(i,r,o)=>{let{lending_market_id:t,lending_market_type:a}=De(this.sdk.sdkOptions?.suilend),d=`${t}_${a}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let c=await this.suilendClientCache[d].pythClient.getPriceFeedObjectId(r);this.suilendClientCache[d].refreshReservePrices(i,c,o)};this.getLatestPriceFeeds=async(i,r=!1)=>{let{lending_market_id:o,lending_market_type:t}=De(this.sdk.sdkOptions?.suilend),a={},d=[];if(i.forEach(M=>{let P=this.sdk.getCache(`getLatestPrice_${M.coinType.name}`,r);P&&this.priceCheck(P,60)?a[M.coinType.name]=P:d.push(M.coinType.name)}),d.length==0)return a;let c=`${o}_${t}`;if(!this.suilendClientCache)throw new Error("suilendClient is not initialized");let m=Array.from(new Set(i.map(M=>M?.priceIdentifier?.bytes?Lr(new Uint8Array(M.priceIdentifier.bytes)):Ye(M.priceIdentifier.toString()))));return(await this.suilendClientCache[c].pythConnection.getLatestPriceFeeds(m))?.forEach((M,P)=>{let A=M.getPriceUnchecked(),D=i[P];if(A){let{price:T,expo:L}=A,N=Fi(T).mul(Fi(10).pow(Fi(L))).toString(),R={coin_type:D.coinType.name||D.coinType,price:N,oracle_price:0n,last_update_time:A.publishTime};R.oracle_price=Or(BigInt(T),BigInt(L)),a[D.coinType.name||D.coinType]=R,this.sdk.updateCache(`getLatestPrice_${R.coin_type}`,R)}}),a};this.getLatestPriceFeedsByCoinTypes=async(i,r=!1)=>{try{let{lending_market_id:o}=De(this.sdk.sdkOptions?.suilend),{allLendingMarketData:t}=await this.getLendingMarketData(!1),a=[];return i.forEach(c=>{let m=t[o].reserveMap[c];a.push(m)}),await this.getLatestPriceFeeds(a,r)}catch(o){Gt("FetchError",o);return}};this.getSuiLendReserveInfo=async(i,r,o,t)=>{let{lending_market_id:a}=De(this.sdk.sdkOptions?.suilend);o||(o=(await this.getLendingMarketData(!1)).allLendingMarketData);let d=o[a].reserveMap[i],c=o[a].reserveMap[r],m=o[a].refreshedRawReserves.filter(D=>D.coinType.name==Ye(i)),g=o[a].refreshedRawReserves.filter(D=>D.coinType.name==Ye(r)),M=o[a].reserveMap[i],P=o[a].reserveMap[r],A=[];return t&&t.forEach(D=>{let T=o[a].refreshedRawReserves.filter(L=>L.coinType.name==Ye(D));A.push(...T)}),{base_reserve_array_index:d.arrayIndex.toString(),quote_reserve_array_index:c.arrayIndex.toString(),reserve:[m[0],g[0],...A],base_reserve_map_info:M,quote_reserve_map_info:P}};this.refreshReservePrices=async(i,r)=>{for(let o=0;o<r.length;o++){let t=Lr(new Uint8Array(r[o].priceIdentifier.bytes));await this.refreshReservePrice(i,t,BigInt(r[o].arrayIndex))}};this.refreshReservePricesV2=async(i,r)=>{for(let o=0;o<r.length;o++){let t=r[o].priceIdentifier.toString();await this.refreshReservePrice(i,t,BigInt(r[o].arrayIndex))}};this.sdk=i}async getSuilendClient(i,r){let o=`${i}_${r}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[o]||(this.suilendClientCache[o]=await so.initialize(i,r,this.sdk.FullClient,!0)),this.suilendClientCache[o]}async getLendingMarketData(i=!0){let r="lendingMarketData",o=this.sdk.getCache(r,i);if(o)return o;let t=De(this.sdk.sdkOptions?.suilend)?.lending_market||[];if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:67 ~ SuiLendModule ~ getLendingMarketData ~ lendingMarkets:",t),!t.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[a,d]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(t.map(async m=>{let g=await this.getSuilendClient(m.id,m.type),{lendingMarket:M,coinMetadataMap:P,refreshedRawReserves:A,reserveMap:D,reserveCoinTypes:T,reserveCoinMetadataMap:L,rewardCoinTypes:N,activeRewardCoinTypes:R,rewardCoinMetadataMap:O}=await ao(this.sdk.FullClient,g),{rewardPriceMap:E}=await lo(D,R);return[m.id,{suilendClient:g,lendingMarket:M,coinMetadataMap:P,refreshedRawReserves:A,reserveMap:D,reserveCoinTypes:T,reserveCoinMetadataMap:L,rewardPriceMap:E,rewardCoinTypes:N,activeRewardCoinTypes:R,rewardCoinMetadataMap:O}]}))))(),(async()=>{try{let c=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.api_url}/springsui/apy`),m=await c.json();if(c?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(m).map(([g,M])=>[g,new lt(M)]))}catch(c){return console.error(c),{}}})()]);return this.sdk.updateCache(r,{allLendingMarketData:a,lstAprPercentMap:d},30*1e3),{allLendingMarketData:a,lstAprPercentMap:d}}catch(a){throw console.log("\u{1F680} getLendingMarketData error:",a),a}}async getInitializeObligations(i,r=!1){if(!r&&this.obligationsCache)return this.obligationsCache;i||(i=await this.getLendingMarketData(!1));let o={};for(let t of Object.values(i.allLendingMarketData)){let{obligationOwnerCaps:a,obligations:d}=await uo(this.sdk.FullClient,t.suilendClient,t.refreshedRawReserves,t.reserveMap,this.sdk.senderAddress);d.length>0&&console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:181 ~ SuiLendModule ~ getInitializeObligations ~ obligations:",d[0].original.allowedBorrowValueUsd.value.toString());let c=co(t.reserveMap,t.rewardCoinMetadataMap,t.rewardPriceMap,d);o[t.lendingMarket.id]={obligationOwnerCaps:a,obligations:d,rewardMap:c}}return this.obligationsCache=o,this.obligationsCache}async getSuiLendUserData(i,r=!1){let{allLendingMarketData:o,lstAprPercentMap:t}=await this.getLendingMarketData(!1),a=await this.getInitializeObligations({allLendingMarketData:o,lstAprPercentMap:t},!1),{lending_market_id:d}=De(this.sdk.sdkOptions?.suilend),c=a[d];if(!c)throw new Error(`No user data found for lending market: ${d}`);let m=c.obligations.find(M=>M.id===i);if(!m)throw new Error(`Obligation not found: ${i}`);let g=go(m,c.rewardMap,t??{});return{obligation:m,netAprPercent:g,deposits:m.deposits,borrowedAmount:m.borrowedAmount,depositedAmount:m.depositedAmount,netValueUsd:m.netValueUsd,rewardMap:c.rewardMap}}priceCheck(i,r=60){let o=Math.floor(Date.now()/1e3);if(!(Math.abs(o-i.last_update_time)>r))return i}};var $i=Gr(Ir());import{Transaction as _o}from"@mysten/sui/transactions";import{addHexPrefix as wo,CoinAssist as ji,d as ee,getPackagerConfigs as Er,removeHexPrefix as Br}from"@cetusprotocol/common-sdk";var ti=class{constructor(i){this.routerSwap=async i=>{let{slippage:r,txb:o,input_coin:t,router:a}=i,d=o||new _o;if(a)return await this._sdk.AggregatorClient.routerSwap({router:a,inputCoin:t,slippage:r,txb:d})};this.flashLoan=i=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:183 ~ SwapModules ~ params:",i);let{clmm_pool:r}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:o}=Er(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:t,clmm_pool:a,clmm_pool_coin_type_a:d,clmm_pool_coin_type_b:c,flash_loan_coin:m,tx:g}=i,M=wo(d)===m;console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:188 ~ SwapModules ~ isLoanA:",M);let[P,A,D]=g.moveCall({target:`${r.published_at}::pool::flash_loan`,arguments:[g.object(o),g.object(a),g.pure.bool(M),g.pure.u64(t.toString())],typeArguments:[d,c]});return{balance_a:P,balance_b:A,receipt:D,is_loan_a:M,loan_coin_type:M?d:c}};this.getFlashLoanPool=async(i,r)=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:201 ~ SwapModules ~ flash_amount:",r,i);try{let o=await fetch(`https://api-sui.cetus.zone/v3/sui/margin_trading/pools?coin_type=${i}&min_amount=${r}`),{data:t}=await o.json();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:206 ~ SwapModules ~ data:",t),t&&t.length>0?{clmm_pool_coin_type_a:t[0].coin_type_a,clmm_pool_coin_type_b:t[0].coin_type_b,clmm_pool:t[0].pool_id,clmm_fee_tier:ee(t[0].fee_rate).div(1e6).toString()}:(Gt("FlashLoanPoolNotFound","FlashLoanPoolNotFound"),{clmm_pool_coin_type_a:"",clmm_pool_coin_type_b:"",clmm_pool:"",clmm_fee_tier:""})}catch(o){return Gt("FetchError",o),{clmm_pool_coin_type_a:"",clmm_pool_coin_type_b:"",clmm_pool:"",clmm_fee_tier:""}}};this.repayFlashLoan=i=>{let{clmm_pool:r}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:o}=Er(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:t,repay_base:a,repay_quote:d,receipt:c,clmm_pool:m,clmm_pool_coin_type_a:g,clmm_pool_coin_type_b:M}=i;return t.moveCall({target:`${r.published_at}::pool::repay_flash_loan`,arguments:[t.object(o),t.object(m),a,d,c],typeArguments:[g,M]}),t};this._sdk=i}async findRouters(i,r,o,t,a){try{let d={from:i,target:r,amount:new $i.default(ee(o).toFixed(0).toString()),byAmountIn:t,depth:3},c=await this._sdk.AggregatorClient.findRouters(d);if(c?.error?.code===10001)return{...c,is_exceed:c.insufficientLiquidity};if(c?.insufficientLiquidity)return{...c,is_exceed:c.insufficientLiquidity};if(!c?.paths||c?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:c.amountIn.toString(),amount_out:c.amountOut.toString(),is_exceed:c.insufficientLiquidity,route_obj:c,by_amount_in:!0,origin_res:c}}catch{try{if(a){let c=await this._sdk.AggregatorClient.swapInPools({from:i,target:r,amount:new $i.default(ee(o).toFixed(0).toString()),byAmountIn:t,pools:a});return c?{amount_in:c.routeData.amountIn.toString(),amount_out:c.routeData.amountOut.toString(),is_exceed:c.isExceed,route_obj:c.routeData,by_amount_in:!0,origin_res:c}:null}return null}catch{return null}}}async handleSwapLogic(i){let{is_long:r,is_quote:o,amount:t,base_token:a,quote_token:d,swap_clmm_pool:c="",slippage:m,tx:g}=i,M=r&&o||!r&&!o,P,A,D=t;if(M){let T=r&&o?d:a,L=r&&o?a:d,N=await this.findRouters(T,L,t,!0,[c]);if(D=N?.amount_out.toString(),N){let R=ji.buildCoinWithBalance(BigInt(t),T,g);A=await this.routerSwap({router:N.route_obj,slippage:m,input_coin:R,txb:g}),P=A}}else P=ji.buildCoinWithBalance(BigInt(t.toString()),o?d:a,g);return{has_swap:M,input_coin:P,init_deposit_amount:D}}async handleSwap(i){let{swap_clmm_pool:r="",slippage:o,amount:t,from:a,to:d,tx:c,input_coin:m}=i,g=await this.findRouters(a,d,t,!0,[r]),M=g.amount_out.toString();return{swap_out_coin:await this.routerSwap({router:g.route_obj,slippage:o,input_coin:m||ji.buildCoinWithBalance(BigInt(t),a,c),txb:c}),amount_out:M}}async calculateFlashLoan(i){let{is_long:r,leverage:o,base_token:t,quote_token:a,deposit_amount:d,reserve:c,base_token_decimal:m,quote_token_decimal:g}=i,M=await this._sdk.SuiLendModule.getLatestPriceFeeds(c),P=M&&M[Br(a)]?.price,A=M&&M[Br(t)]?.price,D=r?ee(A).div(ee(P)).toString():ee(P).div(ee(A)).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:267 ~ SwapModules ~ calculateFlashLoan ~ deposit_amount:",d,D,m,g);let T=ee(d).mul(ee(o).sub(1)).mul(D).div(10**(r?m:g)).mul(10**(r?g:m)).toDP(0,ht.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:274 ~ SwapModules ~ calculateFlashLoan ~ flashAmount:",ee(d).mul(ee(o).sub(1)).mul(D).div(10**(r?m:g)).mul(10**(r?g:m)).toString(),T);let L=r?a:t,{clmm_pool_coin_type_a:N,clmm_fee_tier:R,clmm_pool:O,clmm_pool_coin_type_b:E}=await this.getFlashLoanPool(L,T),q=N===L,W=ee(T).mul(R).toString();return{flash_amount:T,rate:D,quote_price:P,base_price:A,flash_loan_coin:L,is_flash_a:q,flash_loan_fee:W,clmm_pool:O,clmm_pool_coin_type_a:N,clmm_pool_coin_type_b:E,clmm_fee_tier:R}}};var ei=class n extends yo{constructor(i,r){super(i),this._suilendModule=new Qe(this),this._permissionModules=new Be(this),this._marketModules=new Ee(this),this._positionModules=new He(this),this._swapModules=new ti(this),this._aggregatorClient=new So({signer:Mo("0x0"),client:i.sui_client||new vo({url:i.full_rpc_url}),env:i.env==="testnet"?qr.Testnet:qr.Mainnet}),this._clmmSDK=r||ko.createSDK({env:i.env,full_rpc_url:i.full_rpc_url}),this._pythConnection=new bo("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get PermissionModules(){return this._permissionModules}get MarketModules(){return this._marketModules}get PositionModules(){return this._positionModules}get SwapModules(){return this._swapModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(i){return n.createCustomSDK({...rr,...i})}static createCustomSDK(i){return new n(i)}};var da=ei;export{ei as CetusMarginTradingSDK,ys as appendExtraRewards,qi as calculateBorrowAprPercent,Tr as calculateDepositAprPercent,Dr as calculateUtilizationPercent,da as default,As as formatLtvPercentValue,Or as getPriceWithFormattedDecimals,Ss as getRewardsAprMultiplier,ks as getUpdatedReserve,rr as margin_trading_mainnet,ki as mergePositionData,Bi as oraclePriceMultiplierDecimal,Ps as updateRewardsWithMultiplier,bi as wrapMarketInfo,Si as wrapMarketPermissions,yi as wrapPosition};
2
2
  /*! Bundled license information:
3
3
 
4
4
  decimal.js/decimal.mjs: