llll-sdk 0.0.0-experimental-20260119174721 → 0.0.0-experimental-20260120162634

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,u){if(typeof e=="number")return this._initNumber(e,s,u);if(typeof e=="object")return this._initArray(e,s,u);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,u):(this._parseBase(e,s,f),u==="le"&&this._initArray(this.toArray(),s,u)))},t.prototype._initNumber=function(e,s,u){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),u==="le"&&this._initArray(this.toArray(),s,u)},t.prototype._initArray=function(e,s,u){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,P=0;if(u==="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<<P&67108863,this.words[h+1]=v>>>26-P&67108863,P+=24,P>=26&&(P-=26,h++);else if(u==="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<<P&67108863,this.words[h+1]=v>>>26-P&67108863,P+=24,P>=26&&(P-=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 u=d(p,s);return s-1>=e&&(u|=d(p,s-1)<<4),u}t.prototype._parseHex=function(e,s,u){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,P;if(u==="be")for(f=e.length-1;f>=s;f-=2)P=c(e,s,f)<<h,this.words[v]|=P&67108863,h>=18?(h-=18,v+=1,this.words[v]|=P>>>26):h+=8;else{var _=e.length-s;for(f=_%2===0?s+1:s;f<e.length;f+=2)P=c(e,s,f)<<h,this.words[v]|=P&67108863,h>=18?(h-=18,v+=1,this.words[v]|=P>>>26):h+=8}this._strip()};function g(p,e,s,u){for(var f=0,h=0,v=Math.min(p.length,s),P=e;P<v;P++){var _=p.charCodeAt(P)-48;f*=u,_>=49?h=_-49+10:_>=17?h=_-17+10:h=_,r(_>=0&&h<u,"Invalid character"),f+=h}return f}t.prototype._parseBase=function(e,s,u){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-u,P=v%f,_=Math.min(v,v-P)+u,l=0,y=u;y<_;y+=f)l=g(e,y,y+f,s),this.imuln(h),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if(P!==0){var U=1;for(l=g(e,y,e.length,s),y=0;y<P;y++)U*=s;this.imuln(U),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}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 m(p,e){p.words=e.words,p.length=e.length,p.negative=e.negative,p.red=e.red}if(t.prototype._move=function(e){m(e,this)},t.prototype.clone=function(){var e=new t(null);return this.copy(e),e},t.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},t.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},t.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{t.prototype[Symbol.for("nodejs.util.inspect.custom")]=M}catch{t.prototype.inspect=M}else t.prototype.inspect=M;function M(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var S=["","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],T=[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 u;if(e===16||e==="hex"){u="";for(var f=0,h=0,v=0;v<this.length;v++){var P=this.words[v],_=((P<<f|h)&16777215).toString(16);h=P>>>24-f&16777215,f+=2,f>=26&&(f-=26,v--),h!==0||v!==this.length-1?u=S[6-_.length]+_+u:u=_+u}for(h!==0&&(u=h.toString(16)+u);u.length%s!==0;)u="0"+u;return this.negative!==0&&(u="-"+u),u}if(e===(e|0)&&e>=2&&e<=36){var l=A[e],y=T[e];u="";var U=this.clone();for(U.negative=0;!U.isZero();){var q=U.modrn(y).toString(e);U=U.idivn(y),U.isZero()?u=q+u:u=S[l-q.length]+q+u}for(this.isZero()&&(u="0"+u);u.length%s!==0;)u="0"+u;return this.negative!==0&&(u="-"+u),u}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 D=function(e,s){return e.allocUnsafe?e.allocUnsafe(s):new e(s)};t.prototype.toArrayLike=function(e,s,u){this._strip();var f=this.byteLength(),h=u||Math.max(1,f);r(f<=h,"byte array longer than desired length"),r(h>0,"Requested array length <= 0");var v=D(e,h),P=s==="le"?"LE":"BE";return this["_toArrayLike"+P](v,f),v},t.prototype._toArrayLikeLE=function(e,s){for(var u=0,f=0,h=0,v=0;h<this.length;h++){var P=this.words[h]<<v|f;e[u++]=P&255,u<e.length&&(e[u++]=P>>8&255),u<e.length&&(e[u++]=P>>16&255),v===6?(u<e.length&&(e[u++]=P>>24&255),f=0,v=0):(f=P>>>24,v+=2)}if(u<e.length)for(e[u++]=f;u<e.length;)e[u++]=0},t.prototype._toArrayLikeBE=function(e,s){for(var u=e.length-1,f=0,h=0,v=0;h<this.length;h++){var P=this.words[h]<<v|f;e[u--]=P&255,u>=0&&(e[u--]=P>>8&255),u>=0&&(e[u--]=P>>16&255),v===6?(u>=0&&(e[u--]=P>>24&255),f=0,v=0):(f=P>>>24,v+=2)}if(u>=0)for(e[u--]=f;u>=0;)e[u--]=0},Math.clz32?t.prototype._countBits=function(e){return 32-Math.clz32(e)}:t.prototype._countBits=function(e){var s=e,u=0;return s>=4096&&(u+=13,s>>>=13),s>=64&&(u+=7,s>>>=7),s>=8&&(u+=4,s>>>=4),s>=2&&(u+=2,s>>>=2),u+s},t.prototype._zeroBits=function(e){if(e===0)return 26;var s=e,u=0;return(s&8191)===0&&(u+=13,s>>>=13),(s&127)===0&&(u+=7,s>>>=7),(s&15)===0&&(u+=4,s>>>=4),(s&3)===0&&(u+=2,s>>>=2),(s&1)===0&&u++,u},t.prototype.bitLength=function(){var e=this.words[this.length-1],s=this._countBits(e);return(this.length-1)*26+s};function R(p){for(var e=new Array(p.bitLength()),s=0;s<e.length;s++){var u=s/26|0,f=s%26;e[s]=p.words[u]>>>f&1}return e}t.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,s=0;s<this.length;s++){var u=this._zeroBits(this.words[s]);if(e+=u,u!==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 u=0;u<s.length;u++)this.words[u]=this.words[u]&e.words[u];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,u;this.length>e.length?(s=this,u=e):(s=e,u=this);for(var f=0;f<u.length;f++)this.words[f]=s.words[f]^u.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,u=e%26;this._expand(s),u>0&&s--;for(var f=0;f<s;f++)this.words[f]=~this.words[f]&67108863;return u>0&&(this.words[f]=~this.words[f]&67108863>>26-u),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 u=e/26|0,f=e%26;return this._expand(u+1),s?this.words[u]=this.words[u]|1<<f:this.words[u]=this.words[u]&~(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 u,f;this.length>e.length?(u=this,f=e):(u=e,f=this);for(var h=0,v=0;v<f.length;v++)s=(u.words[v]|0)+(f.words[v]|0)+h,this.words[v]=s&67108863,h=s>>>26;for(;h!==0&&v<u.length;v++)s=(u.words[v]|0)+h,this.words[v]=s&67108863,h=s>>>26;if(this.length=u.length,h!==0)this.words[this.length]=h,this.length++;else if(u!==this)for(;v<u.length;v++)this.words[v]=u.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 u=this.cmp(e);if(u===0)return this.negative=0,this.length=1,this.words[0]=0,this;var f,h;u>0?(f=this,h=e):(f=e,h=this);for(var v=0,P=0;P<h.length;P++)s=(f.words[P]|0)-(h.words[P]|0)+v,v=s>>26,this.words[P]=s&67108863;for(;v!==0&&P<f.length;P++)s=(f.words[P]|0)+v,v=s>>26,this.words[P]=s&67108863;if(v===0&&P<f.length&&f!==this)for(;P<f.length;P++)this.words[P]=f.words[P];return this.length=Math.max(this.length,P),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 u=p.length+e.length|0;s.length=u,u=u-1|0;var f=p.words[0]|0,h=e.words[0]|0,v=f*h,P=v&67108863,_=v/67108864|0;s.words[0]=P;for(var l=1;l<u;l++){for(var y=_>>>26,U=_&67108863,q=Math.min(l,e.length-1),$=Math.max(0,l-p.length+1);$<=q;$++){var K=l-$|0;f=p.words[K]|0,h=e.words[$]|0,v=f*h+U,y+=v/67108864|0,U=v&67108863}s.words[l]=U|0,_=y|0}return _!==0?s.words[l]=_|0:s.length--,s._strip()}var L=function(e,s,u){var f=e.words,h=s.words,v=u.words,P=0,_,l,y,U=f[0]|0,q=U&8191,$=U>>>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,Tt=Xi&8191,Dt=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;u.negative=e.negative^s.negative,u.length=19,_=Math.imul(q,bt),l=Math.imul(q,yt),l=l+Math.imul($,bt)|0,y=Math.imul($,yt);var ii=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(ii>>>26)|0,ii&=67108863,_=Math.imul(G,bt),l=Math.imul(G,yt),l=l+Math.imul(J,bt)|0,y=Math.imul(J,yt),_=_+Math.imul(q,kt)|0,l=l+Math.imul(q,St)|0,l=l+Math.imul($,kt)|0,y=y+Math.imul($,St)|0;var ri=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(ri>>>26)|0,ri&=67108863,_=Math.imul(V,bt),l=Math.imul(V,yt),l=l+Math.imul(it,bt)|0,y=Math.imul(it,yt),_=_+Math.imul(G,kt)|0,l=l+Math.imul(G,St)|0,l=l+Math.imul(J,kt)|0,y=y+Math.imul(J,St)|0,_=_+Math.imul(q,Pt)|0,l=l+Math.imul(q,At)|0,l=l+Math.imul($,Pt)|0,y=y+Math.imul($,At)|0;var ni=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(ni>>>26)|0,ni&=67108863,_=Math.imul(et,bt),l=Math.imul(et,yt),l=l+Math.imul(X,bt)|0,y=Math.imul(X,yt),_=_+Math.imul(V,kt)|0,l=l+Math.imul(V,St)|0,l=l+Math.imul(it,kt)|0,y=y+Math.imul(it,St)|0,_=_+Math.imul(G,Pt)|0,l=l+Math.imul(G,At)|0,l=l+Math.imul(J,Pt)|0,y=y+Math.imul(J,At)|0,_=_+Math.imul(q,Ct)|0,l=l+Math.imul(q,xt)|0,l=l+Math.imul($,Ct)|0,y=y+Math.imul($,xt)|0;var oi=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(oi>>>26)|0,oi&=67108863,_=Math.imul(ct,bt),l=Math.imul(ct,yt),l=l+Math.imul(st,bt)|0,y=Math.imul(st,yt),_=_+Math.imul(et,kt)|0,l=l+Math.imul(et,St)|0,l=l+Math.imul(X,kt)|0,y=y+Math.imul(X,St)|0,_=_+Math.imul(V,Pt)|0,l=l+Math.imul(V,At)|0,l=l+Math.imul(it,Pt)|0,y=y+Math.imul(it,At)|0,_=_+Math.imul(G,Ct)|0,l=l+Math.imul(G,xt)|0,l=l+Math.imul(J,Ct)|0,y=y+Math.imul(J,xt)|0,_=_+Math.imul(q,Tt)|0,l=l+Math.imul(q,Dt)|0,l=l+Math.imul($,Tt)|0,y=y+Math.imul($,Dt)|0;var si=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(si>>>26)|0,si&=67108863,_=Math.imul(nt,bt),l=Math.imul(nt,yt),l=l+Math.imul(at,bt)|0,y=Math.imul(at,yt),_=_+Math.imul(ct,kt)|0,l=l+Math.imul(ct,St)|0,l=l+Math.imul(st,kt)|0,y=y+Math.imul(st,St)|0,_=_+Math.imul(et,Pt)|0,l=l+Math.imul(et,At)|0,l=l+Math.imul(X,Pt)|0,y=y+Math.imul(X,At)|0,_=_+Math.imul(V,Ct)|0,l=l+Math.imul(V,xt)|0,l=l+Math.imul(it,Ct)|0,y=y+Math.imul(it,xt)|0,_=_+Math.imul(G,Tt)|0,l=l+Math.imul(G,Dt)|0,l=l+Math.imul(J,Tt)|0,y=y+Math.imul(J,Dt)|0,_=_+Math.imul(q,Ot)|0,l=l+Math.imul(q,Rt)|0,l=l+Math.imul($,Ot)|0,y=y+Math.imul($,Rt)|0;var ai=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(ai>>>26)|0,ai&=67108863,_=Math.imul(dt,bt),l=Math.imul(dt,yt),l=l+Math.imul(pt,bt)|0,y=Math.imul(pt,yt),_=_+Math.imul(nt,kt)|0,l=l+Math.imul(nt,St)|0,l=l+Math.imul(at,kt)|0,y=y+Math.imul(at,St)|0,_=_+Math.imul(ct,Pt)|0,l=l+Math.imul(ct,At)|0,l=l+Math.imul(st,Pt)|0,y=y+Math.imul(st,At)|0,_=_+Math.imul(et,Ct)|0,l=l+Math.imul(et,xt)|0,l=l+Math.imul(X,Ct)|0,y=y+Math.imul(X,xt)|0,_=_+Math.imul(V,Tt)|0,l=l+Math.imul(V,Dt)|0,l=l+Math.imul(it,Tt)|0,y=y+Math.imul(it,Dt)|0,_=_+Math.imul(G,Ot)|0,l=l+Math.imul(G,Rt)|0,l=l+Math.imul(J,Ot)|0,y=y+Math.imul(J,Rt)|0,_=_+Math.imul(q,Lt)|0,l=l+Math.imul(q,Nt)|0,l=l+Math.imul($,Lt)|0,y=y+Math.imul($,Nt)|0;var li=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(li>>>26)|0,li&=67108863,_=Math.imul(mt,bt),l=Math.imul(mt,yt),l=l+Math.imul(gt,bt)|0,y=Math.imul(gt,yt),_=_+Math.imul(dt,kt)|0,l=l+Math.imul(dt,St)|0,l=l+Math.imul(pt,kt)|0,y=y+Math.imul(pt,St)|0,_=_+Math.imul(nt,Pt)|0,l=l+Math.imul(nt,At)|0,l=l+Math.imul(at,Pt)|0,y=y+Math.imul(at,At)|0,_=_+Math.imul(ct,Ct)|0,l=l+Math.imul(ct,xt)|0,l=l+Math.imul(st,Ct)|0,y=y+Math.imul(st,xt)|0,_=_+Math.imul(et,Tt)|0,l=l+Math.imul(et,Dt)|0,l=l+Math.imul(X,Tt)|0,y=y+Math.imul(X,Dt)|0,_=_+Math.imul(V,Ot)|0,l=l+Math.imul(V,Rt)|0,l=l+Math.imul(it,Ot)|0,y=y+Math.imul(it,Rt)|0,_=_+Math.imul(G,Lt)|0,l=l+Math.imul(G,Nt)|0,l=l+Math.imul(J,Lt)|0,y=y+Math.imul(J,Nt)|0,_=_+Math.imul(q,Et)|0,l=l+Math.imul(q,It)|0,l=l+Math.imul($,Et)|0,y=y+Math.imul($,It)|0;var ui=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(ui>>>26)|0,ui&=67108863,_=Math.imul(_t,bt),l=Math.imul(_t,yt),l=l+Math.imul(wt,bt)|0,y=Math.imul(wt,yt),_=_+Math.imul(mt,kt)|0,l=l+Math.imul(mt,St)|0,l=l+Math.imul(gt,kt)|0,y=y+Math.imul(gt,St)|0,_=_+Math.imul(dt,Pt)|0,l=l+Math.imul(dt,At)|0,l=l+Math.imul(pt,Pt)|0,y=y+Math.imul(pt,At)|0,_=_+Math.imul(nt,Ct)|0,l=l+Math.imul(nt,xt)|0,l=l+Math.imul(at,Ct)|0,y=y+Math.imul(at,xt)|0,_=_+Math.imul(ct,Tt)|0,l=l+Math.imul(ct,Dt)|0,l=l+Math.imul(st,Tt)|0,y=y+Math.imul(st,Dt)|0,_=_+Math.imul(et,Ot)|0,l=l+Math.imul(et,Rt)|0,l=l+Math.imul(X,Ot)|0,y=y+Math.imul(X,Rt)|0,_=_+Math.imul(V,Lt)|0,l=l+Math.imul(V,Nt)|0,l=l+Math.imul(it,Lt)|0,y=y+Math.imul(it,Nt)|0,_=_+Math.imul(G,Et)|0,l=l+Math.imul(G,It)|0,l=l+Math.imul(J,Et)|0,y=y+Math.imul(J,It)|0,_=_+Math.imul(q,Bt)|0,l=l+Math.imul(q,qt)|0,l=l+Math.imul($,Bt)|0,y=y+Math.imul($,qt)|0;var ci=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(ci>>>26)|0,ci&=67108863,_=Math.imul(vt,bt),l=Math.imul(vt,yt),l=l+Math.imul(Mt,bt)|0,y=Math.imul(Mt,yt),_=_+Math.imul(_t,kt)|0,l=l+Math.imul(_t,St)|0,l=l+Math.imul(wt,kt)|0,y=y+Math.imul(wt,St)|0,_=_+Math.imul(mt,Pt)|0,l=l+Math.imul(mt,At)|0,l=l+Math.imul(gt,Pt)|0,y=y+Math.imul(gt,At)|0,_=_+Math.imul(dt,Ct)|0,l=l+Math.imul(dt,xt)|0,l=l+Math.imul(pt,Ct)|0,y=y+Math.imul(pt,xt)|0,_=_+Math.imul(nt,Tt)|0,l=l+Math.imul(nt,Dt)|0,l=l+Math.imul(at,Tt)|0,y=y+Math.imul(at,Dt)|0,_=_+Math.imul(ct,Ot)|0,l=l+Math.imul(ct,Rt)|0,l=l+Math.imul(st,Ot)|0,y=y+Math.imul(st,Rt)|0,_=_+Math.imul(et,Lt)|0,l=l+Math.imul(et,Nt)|0,l=l+Math.imul(X,Lt)|0,y=y+Math.imul(X,Nt)|0,_=_+Math.imul(V,Et)|0,l=l+Math.imul(V,It)|0,l=l+Math.imul(it,Et)|0,y=y+Math.imul(it,It)|0,_=_+Math.imul(G,Bt)|0,l=l+Math.imul(G,qt)|0,l=l+Math.imul(J,Bt)|0,y=y+Math.imul(J,qt)|0,_=_+Math.imul(q,Ft)|0,l=l+Math.imul(q,Ut)|0,l=l+Math.imul($,Ft)|0,y=y+Math.imul($,Ut)|0;var fi=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(fi>>>26)|0,fi&=67108863,_=Math.imul(vt,kt),l=Math.imul(vt,St),l=l+Math.imul(Mt,kt)|0,y=Math.imul(Mt,St),_=_+Math.imul(_t,Pt)|0,l=l+Math.imul(_t,At)|0,l=l+Math.imul(wt,Pt)|0,y=y+Math.imul(wt,At)|0,_=_+Math.imul(mt,Ct)|0,l=l+Math.imul(mt,xt)|0,l=l+Math.imul(gt,Ct)|0,y=y+Math.imul(gt,xt)|0,_=_+Math.imul(dt,Tt)|0,l=l+Math.imul(dt,Dt)|0,l=l+Math.imul(pt,Tt)|0,y=y+Math.imul(pt,Dt)|0,_=_+Math.imul(nt,Ot)|0,l=l+Math.imul(nt,Rt)|0,l=l+Math.imul(at,Ot)|0,y=y+Math.imul(at,Rt)|0,_=_+Math.imul(ct,Lt)|0,l=l+Math.imul(ct,Nt)|0,l=l+Math.imul(st,Lt)|0,y=y+Math.imul(st,Nt)|0,_=_+Math.imul(et,Et)|0,l=l+Math.imul(et,It)|0,l=l+Math.imul(X,Et)|0,y=y+Math.imul(X,It)|0,_=_+Math.imul(V,Bt)|0,l=l+Math.imul(V,qt)|0,l=l+Math.imul(it,Bt)|0,y=y+Math.imul(it,qt)|0,_=_+Math.imul(G,Ft)|0,l=l+Math.imul(G,Ut)|0,l=l+Math.imul(J,Ft)|0,y=y+Math.imul(J,Ut)|0;var di=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(di>>>26)|0,di&=67108863,_=Math.imul(vt,Pt),l=Math.imul(vt,At),l=l+Math.imul(Mt,Pt)|0,y=Math.imul(Mt,At),_=_+Math.imul(_t,Ct)|0,l=l+Math.imul(_t,xt)|0,l=l+Math.imul(wt,Ct)|0,y=y+Math.imul(wt,xt)|0,_=_+Math.imul(mt,Tt)|0,l=l+Math.imul(mt,Dt)|0,l=l+Math.imul(gt,Tt)|0,y=y+Math.imul(gt,Dt)|0,_=_+Math.imul(dt,Ot)|0,l=l+Math.imul(dt,Rt)|0,l=l+Math.imul(pt,Ot)|0,y=y+Math.imul(pt,Rt)|0,_=_+Math.imul(nt,Lt)|0,l=l+Math.imul(nt,Nt)|0,l=l+Math.imul(at,Lt)|0,y=y+Math.imul(at,Nt)|0,_=_+Math.imul(ct,Et)|0,l=l+Math.imul(ct,It)|0,l=l+Math.imul(st,Et)|0,y=y+Math.imul(st,It)|0,_=_+Math.imul(et,Bt)|0,l=l+Math.imul(et,qt)|0,l=l+Math.imul(X,Bt)|0,y=y+Math.imul(X,qt)|0,_=_+Math.imul(V,Ft)|0,l=l+Math.imul(V,Ut)|0,l=l+Math.imul(it,Ft)|0,y=y+Math.imul(it,Ut)|0;var hi=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(hi>>>26)|0,hi&=67108863,_=Math.imul(vt,Ct),l=Math.imul(vt,xt),l=l+Math.imul(Mt,Ct)|0,y=Math.imul(Mt,xt),_=_+Math.imul(_t,Tt)|0,l=l+Math.imul(_t,Dt)|0,l=l+Math.imul(wt,Tt)|0,y=y+Math.imul(wt,Dt)|0,_=_+Math.imul(mt,Ot)|0,l=l+Math.imul(mt,Rt)|0,l=l+Math.imul(gt,Ot)|0,y=y+Math.imul(gt,Rt)|0,_=_+Math.imul(dt,Lt)|0,l=l+Math.imul(dt,Nt)|0,l=l+Math.imul(pt,Lt)|0,y=y+Math.imul(pt,Nt)|0,_=_+Math.imul(nt,Et)|0,l=l+Math.imul(nt,It)|0,l=l+Math.imul(at,Et)|0,y=y+Math.imul(at,It)|0,_=_+Math.imul(ct,Bt)|0,l=l+Math.imul(ct,qt)|0,l=l+Math.imul(st,Bt)|0,y=y+Math.imul(st,qt)|0,_=_+Math.imul(et,Ft)|0,l=l+Math.imul(et,Ut)|0,l=l+Math.imul(X,Ft)|0,y=y+Math.imul(X,Ut)|0;var pi=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(pi>>>26)|0,pi&=67108863,_=Math.imul(vt,Tt),l=Math.imul(vt,Dt),l=l+Math.imul(Mt,Tt)|0,y=Math.imul(Mt,Dt),_=_+Math.imul(_t,Ot)|0,l=l+Math.imul(_t,Rt)|0,l=l+Math.imul(wt,Ot)|0,y=y+Math.imul(wt,Rt)|0,_=_+Math.imul(mt,Lt)|0,l=l+Math.imul(mt,Nt)|0,l=l+Math.imul(gt,Lt)|0,y=y+Math.imul(gt,Nt)|0,_=_+Math.imul(dt,Et)|0,l=l+Math.imul(dt,It)|0,l=l+Math.imul(pt,Et)|0,y=y+Math.imul(pt,It)|0,_=_+Math.imul(nt,Bt)|0,l=l+Math.imul(nt,qt)|0,l=l+Math.imul(at,Bt)|0,y=y+Math.imul(at,qt)|0,_=_+Math.imul(ct,Ft)|0,l=l+Math.imul(ct,Ut)|0,l=l+Math.imul(st,Ft)|0,y=y+Math.imul(st,Ut)|0;var mi=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(mi>>>26)|0,mi&=67108863,_=Math.imul(vt,Ot),l=Math.imul(vt,Rt),l=l+Math.imul(Mt,Ot)|0,y=Math.imul(Mt,Rt),_=_+Math.imul(_t,Lt)|0,l=l+Math.imul(_t,Nt)|0,l=l+Math.imul(wt,Lt)|0,y=y+Math.imul(wt,Nt)|0,_=_+Math.imul(mt,Et)|0,l=l+Math.imul(mt,It)|0,l=l+Math.imul(gt,Et)|0,y=y+Math.imul(gt,It)|0,_=_+Math.imul(dt,Bt)|0,l=l+Math.imul(dt,qt)|0,l=l+Math.imul(pt,Bt)|0,y=y+Math.imul(pt,qt)|0,_=_+Math.imul(nt,Ft)|0,l=l+Math.imul(nt,Ut)|0,l=l+Math.imul(at,Ft)|0,y=y+Math.imul(at,Ut)|0;var gi=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(gi>>>26)|0,gi&=67108863,_=Math.imul(vt,Lt),l=Math.imul(vt,Nt),l=l+Math.imul(Mt,Lt)|0,y=Math.imul(Mt,Nt),_=_+Math.imul(_t,Et)|0,l=l+Math.imul(_t,It)|0,l=l+Math.imul(wt,Et)|0,y=y+Math.imul(wt,It)|0,_=_+Math.imul(mt,Bt)|0,l=l+Math.imul(mt,qt)|0,l=l+Math.imul(gt,Bt)|0,y=y+Math.imul(gt,qt)|0,_=_+Math.imul(dt,Ft)|0,l=l+Math.imul(dt,Ut)|0,l=l+Math.imul(pt,Ft)|0,y=y+Math.imul(pt,Ut)|0;var _i=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(_i>>>26)|0,_i&=67108863,_=Math.imul(vt,Et),l=Math.imul(vt,It),l=l+Math.imul(Mt,Et)|0,y=Math.imul(Mt,It),_=_+Math.imul(_t,Bt)|0,l=l+Math.imul(_t,qt)|0,l=l+Math.imul(wt,Bt)|0,y=y+Math.imul(wt,qt)|0,_=_+Math.imul(mt,Ft)|0,l=l+Math.imul(mt,Ut)|0,l=l+Math.imul(gt,Ft)|0,y=y+Math.imul(gt,Ut)|0;var wi=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(wi>>>26)|0,wi&=67108863,_=Math.imul(vt,Bt),l=Math.imul(vt,qt),l=l+Math.imul(Mt,Bt)|0,y=Math.imul(Mt,qt),_=_+Math.imul(_t,Ft)|0,l=l+Math.imul(_t,Ut)|0,l=l+Math.imul(wt,Ft)|0,y=y+Math.imul(wt,Ut)|0;var vi=(P+_|0)+((l&8191)<<13)|0;P=(y+(l>>>13)|0)+(vi>>>26)|0,vi&=67108863,_=Math.imul(vt,Ft),l=Math.imul(vt,Ut),l=l+Math.imul(Mt,Ft)|0,y=Math.imul(Mt,Ut);var Mi=(P+_|0)+((l&8191)<<13)|0;return P=(y+(l>>>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,P!==0&&(v[19]=P,u.length++),u};Math.imul||(L=N);function O(p,e,s){s.negative=e.negative^p.negative,s.length=p.length+e.length;for(var u=0,f=0,h=0;h<s.length-1;h++){var v=f;f=0;for(var P=u&67108863,_=Math.min(h,e.length-1),l=Math.max(0,h-p.length+1);l<=_;l++){var y=h-l,U=p.words[y]|0,q=e.words[l]|0,$=U*q,K=$&67108863;v=v+($/67108864|0)|0,K=K+P|0,P=K&67108863,v=v+(K>>>26)|0,f+=v>>>26,v&=67108863}s.words[h]=P,u=v,v=f}return u!==0?s.words[h]=u:s.length--,s._strip()}function B(p,e,s){return O(p,e,s)}t.prototype.mulTo=function(e,s){var u,f=this.length+e.length;return this.length===10&&e.length===10?u=L(this,e,s):f<63?u=N(this,e,s):f<1024?u=O(this,e,s):u=B(this,e,s),u};function F(p,e){this.x=p,this.y=e}F.prototype.makeRBT=function(e){for(var s=new Array(e),u=t.prototype._countBits(e)-1,f=0;f<e;f++)s[f]=this.revBin(f,u,e);return s},F.prototype.revBin=function(e,s,u){if(e===0||e===u-1)return e;for(var f=0,h=0;h<s;h++)f|=(e&1)<<s-h-1,e>>=1;return f},F.prototype.permute=function(e,s,u,f,h,v){for(var P=0;P<v;P++)f[P]=s[e[P]],h[P]=u[e[P]]},F.prototype.transform=function(e,s,u,f,h,v){this.permute(v,e,s,u,f,h);for(var P=1;P<h;P<<=1)for(var _=P<<1,l=Math.cos(2*Math.PI/_),y=Math.sin(2*Math.PI/_),U=0;U<h;U+=_)for(var q=l,$=y,K=0;K<P;K++){var G=u[U+K],J=f[U+K],rt=u[U+K+P],V=f[U+K+P],it=q*rt-$*V;V=q*V+$*rt,rt=it,u[U+K]=G+rt,f[U+K]=J+V,u[U+K+P]=G-rt,f[U+K+P]=J-V,K!==_&&(it=l*q-y*$,$=l*$+y*q,q=it)}},F.prototype.guessLen13b=function(e,s){var u=Math.max(s,e)|1,f=u&1,h=0;for(u=u/2|0;u;u=u>>>1)h++;return 1<<h+1+f},F.prototype.conjugate=function(e,s,u){if(!(u<=1))for(var f=0;f<u/2;f++){var h=e[f];e[f]=e[u-f-1],e[u-f-1]=h,h=s[f],s[f]=-s[u-f-1],s[u-f-1]=-h}},F.prototype.normalize13b=function(e,s){for(var u=0,f=0;f<s/2;f++){var h=Math.round(e[2*f+1]/s)*8192+Math.round(e[2*f]/s)+u;e[f]=h&67108863,h<67108864?u=0:u=h/67108864|0}return e},F.prototype.convert13b=function(e,s,u,f){for(var h=0,v=0;v<s;v++)h=h+(e[v]|0),u[2*v]=h&8191,h=h>>>13,u[2*v+1]=h&8191,h=h>>>13;for(v=2*s;v<f;++v)u[v]=0;r(h===0),r((h&-8192)===0)},F.prototype.stub=function(e){for(var s=new Array(e),u=0;u<e;u++)s[u]=0;return s},F.prototype.mulp=function(e,s,u){var f=2*this.guessLen13b(e.length,s.length),h=this.makeRBT(f),v=this.stub(f),P=new Array(f),_=new Array(f),l=new Array(f),y=new Array(f),U=new Array(f),q=new Array(f),$=u.words;$.length=f,this.convert13b(e.words,e.length,P,f),this.convert13b(s.words,s.length,y,f),this.transform(P,v,_,l,f,h),this.transform(y,v,U,q,f,h);for(var K=0;K<f;K++){var G=_[K]*U[K]-l[K]*q[K];l[K]=_[K]*q[K]+l[K]*U[K],_[K]=G}return this.conjugate(_,l,f),this.transform(_,l,$,v,f,h),this.conjugate($,v,f),this.normalize13b($,f),u.negative=e.negative^s.negative,u.length=e.length+s.length,u._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),B(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 u=0,f=0;f<this.length;f++){var h=(this.words[f]|0)*e,v=(h&67108863)+(u&67108863);u>>=26,u+=h/67108864|0,u+=v>>>26,this.words[f]=v&67108863}return u!==0&&(this.words[f]=u,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=R(e);if(s.length===0)return new t(1);for(var u=this,f=0;f<s.length&&s[f]===0;f++,u=u.sqr());if(++f<s.length)for(var h=u.sqr();f<s.length;f++,h=h.sqr())s[f]!==0&&(u=u.mul(h));return u},t.prototype.iushln=function(e){r(typeof e=="number"&&e>=0);var s=e%26,u=(e-s)/26,f=67108863>>>26-s<<26-s,h;if(s!==0){var v=0;for(h=0;h<this.length;h++){var P=this.words[h]&f,_=(this.words[h]|0)-P<<s;this.words[h]=_|v,v=P>>>26-s}v&&(this.words[h]=v,this.length++)}if(u!==0){for(h=this.length-1;h>=0;h--)this.words[h+u]=this.words[h];for(h=0;h<u;h++)this.words[h]=0;this.length+=u}return this._strip()},t.prototype.ishln=function(e){return r(this.negative===0),this.iushln(e)},t.prototype.iushrn=function(e,s,u){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),P=67108863^67108863>>>h<<h,_=u;if(f-=v,f=Math.max(0,f),_){for(var l=0;l<v;l++)_.words[l]=this.words[l];_.length=v}if(v!==0)if(this.length>v)for(this.length-=v,l=0;l<this.length;l++)this.words[l]=this.words[l+v];else this.words[0]=0,this.length=1;var y=0;for(l=this.length-1;l>=0&&(y!==0||l>=f);l--){var U=this.words[l]|0;this.words[l]=y<<26-h|U>>>h,y=U&P}return _&&y!==0&&(_.words[_.length++]=y),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},t.prototype.ishrn=function(e,s,u){return r(this.negative===0),this.iushrn(e,s,u)},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,u=(e-s)/26,f=1<<s;if(this.length<=u)return!1;var h=this.words[u];return!!(h&f)},t.prototype.imaskn=function(e){r(typeof e=="number"&&e>=0);var s=e%26,u=(e-s)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=u)return this;if(s!==0&&u++,this.length=Math.min(u,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,u){var f=e.length+u,h;this._expand(f);var v,P=0;for(h=0;h<e.length;h++){v=(this.words[h+u]|0)+P;var _=(e.words[h]|0)*s;v-=_&67108863,P=(v>>26)-(_/67108864|0),this.words[h+u]=v&67108863}for(;h<this.length-u;h++)v=(this.words[h+u]|0)+P,P=v>>26,this.words[h+u]=v&67108863;if(P===0)return this._strip();for(r(P===-1),P=0,h=0;h<this.length;h++)v=-(this.words[h]|0)+P,P=v>>26,this.words[h]=v&67108863;return this.negative=1,this._strip()},t.prototype._wordDiv=function(e,s){var u=this.length-e.length,f=this.clone(),h=e,v=h.words[h.length-1]|0,P=this._countBits(v);u=26-P,u!==0&&(h=h.ushln(u),f.iushln(u),v=h.words[h.length-1]|0);var _=f.length-h.length,l;if(s!=="mod"){l=new t(null),l.length=_+1,l.words=new Array(l.length);for(var y=0;y<l.length;y++)l.words[y]=0}var U=f.clone()._ishlnsubmul(h,1,_);U.negative===0&&(f=U,l&&(l.words[_]=1));for(var q=_-1;q>=0;q--){var $=(f.words[h.length+q]|0)*67108864+(f.words[h.length+q-1]|0);for($=Math.min($/v|0,67108863),f._ishlnsubmul(h,$,q);f.negative!==0;)$--,f.negative=0,f._ishlnsubmul(h,1,q),f.isZero()||(f.negative^=1);l&&(l.words[q]=$)}return l&&l._strip(),f._strip(),s!=="div"&&u!==0&&f.iushrn(u),{div:l||null,mod:f}},t.prototype.divmod=function(e,s,u){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(),u&&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(),u&&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 u=s.div.negative!==0?s.mod.isub(e):s.mod,f=e.ushrn(1),h=e.andln(1),v=u.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 u=(1<<26)%e,f=0,h=this.length-1;h>=0;h--)f=(u*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 u=0,f=this.length-1;f>=0;f--){var h=(this.words[f]|0)+u*67108864;this.words[f]=h/e|0,u=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,u=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),P=new t(1),_=0;s.isEven()&&u.isEven();)s.iushrn(1),u.iushrn(1),++_;for(var l=u.clone(),y=s.clone();!s.isZero();){for(var U=0,q=1;(s.words[0]&q)===0&&U<26;++U,q<<=1);if(U>0)for(s.iushrn(U);U-- >0;)(f.isOdd()||h.isOdd())&&(f.iadd(l),h.isub(y)),f.iushrn(1),h.iushrn(1);for(var $=0,K=1;(u.words[0]&K)===0&&$<26;++$,K<<=1);if($>0)for(u.iushrn($);$-- >0;)(v.isOdd()||P.isOdd())&&(v.iadd(l),P.isub(y)),v.iushrn(1),P.iushrn(1);s.cmp(u)>=0?(s.isub(u),f.isub(v),h.isub(P)):(u.isub(s),v.isub(f),P.isub(h))}return{a:v,b:P,gcd:u.iushln(_)}},t.prototype._invmp=function(e){r(e.negative===0),r(!e.isZero());var s=this,u=e.clone();s.negative!==0?s=s.umod(e):s=s.clone();for(var f=new t(1),h=new t(0),v=u.clone();s.cmpn(1)>0&&u.cmpn(1)>0;){for(var P=0,_=1;(s.words[0]&_)===0&&P<26;++P,_<<=1);if(P>0)for(s.iushrn(P);P-- >0;)f.isOdd()&&f.iadd(v),f.iushrn(1);for(var l=0,y=1;(u.words[0]&y)===0&&l<26;++l,y<<=1);if(l>0)for(u.iushrn(l);l-- >0;)h.isOdd()&&h.iadd(v),h.iushrn(1);s.cmp(u)>=0?(s.isub(u),f.isub(h)):(u.isub(s),h.isub(f))}var U;return s.cmpn(1)===0?U=f:U=h,U.cmpn(0)<0&&U.iadd(e),U},t.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var s=this.clone(),u=e.clone();s.negative=0,u.negative=0;for(var f=0;s.isEven()&&u.isEven();f++)s.iushrn(1),u.iushrn(1);do{for(;s.isEven();)s.iushrn(1);for(;u.isEven();)u.iushrn(1);var h=s.cmp(u);if(h<0){var v=s;s=u,u=v}else if(h===0||u.cmpn(1)===0)break;s.isub(u)}while(!0);return u.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,u=(e-s)/26,f=1<<s;if(this.length<=u)return this._expand(u+1),this.words[u]|=f,this;for(var h=f,v=u;h!==0&&v<this.length;v++){var P=this.words[v]|0;P+=h,h=P>>>26,P&=67108863,this.words[v]=P}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 u;if(this.length>1)u=1;else{s&&(e=-e),r(e<=67108863,"Number is too big");var f=this.words[0]|0;u=f===e?0:f<e?-1:1}return this.negative!==0?-u|0:u},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,u=this.length-1;u>=0;u--){var f=this.words[u]|0,h=e.words[u]|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 x(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 j(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()}j.prototype._tmp=function(){var e=new t(null);return e.words=new Array(Math.ceil(this.n/13)),e},j.prototype.ireduce=function(e){var s=e,u;do this.split(s,this.tmp),s=this.imulK(s),s=s.iadd(this.tmp),u=s.bitLength();while(u>this.n);var f=u<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},j.prototype.split=function(e,s){e.iushrn(this.n,0,s)},j.prototype.imulK=function(e){return e.imul(this.k)};function Z(){j.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}o(Z,j),Z.prototype.split=function(e,s){for(var u=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&u,h=10;h<e.length;h++){var P=e.words[h]|0;e.words[h-10]=(P&u)<<4|v>>>22,v=P}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,u=0;u<e.length;u++){var f=e.words[u]|0;s+=f*977,e.words[u]=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 w(){j.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}o(w,j);function b(){j.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}o(b,j);function k(){j.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}o(k,j),k.prototype.imulK=function(e){for(var s=0,u=0;u<e.length;u++){var f=(e.words[u]|0)*19+s,h=f&67108863;f>>>=26,e.words[u]=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 w;else if(e==="p192")s=new b;else if(e==="p25519")s=new k;else throw new Error("Unknown prime "+e);return W[e]=s,s};function x(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}x.prototype._verify1=function(e){r(e.negative===0,"red works only with positives"),r(e.red,"red works only with red numbers")},x.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")},x.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(m(e,e.umod(this.m)._forceRed(this)),e)},x.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},x.prototype.add=function(e,s){this._verify2(e,s);var u=e.add(s);return u.cmp(this.m)>=0&&u.isub(this.m),u._forceRed(this)},x.prototype.iadd=function(e,s){this._verify2(e,s);var u=e.iadd(s);return u.cmp(this.m)>=0&&u.isub(this.m),u},x.prototype.sub=function(e,s){this._verify2(e,s);var u=e.sub(s);return u.cmpn(0)<0&&u.iadd(this.m),u._forceRed(this)},x.prototype.isub=function(e,s){this._verify2(e,s);var u=e.isub(s);return u.cmpn(0)<0&&u.iadd(this.m),u},x.prototype.shl=function(e,s){return this._verify1(e),this.imod(e.ushln(s))},x.prototype.imul=function(e,s){return this._verify2(e,s),this.imod(e.imul(s))},x.prototype.mul=function(e,s){return this._verify2(e,s),this.imod(e.mul(s))},x.prototype.isqr=function(e){return this.imul(e,e.clone())},x.prototype.sqr=function(e){return this.mul(e,e)},x.prototype.sqrt=function(e){if(e.isZero())return e.clone();var s=this.m.andln(3);if(r(s%2===1),s===3){var u=this.m.add(new t(1)).iushrn(2);return this.pow(e,u)}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),P=v.redNeg(),_=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new t(2*l*l).toRed(this);this.pow(l,_).cmp(P)!==0;)l.redIAdd(P);for(var y=this.pow(l,f),U=this.pow(e,f.addn(1).iushrn(1)),q=this.pow(e,f),$=h;q.cmp(v)!==0;){for(var K=q,G=0;K.cmp(v)!==0;G++)K=K.redSqr();r(G<$);var J=this.pow(y,new t(1).iushln($-G-1));U=U.redMul(J),y=J.redSqr(),q=q.redMul(y),$=G}return U},x.prototype.invm=function(e){var s=e._invmp(this.m);return s.negative!==0?(s.negative=0,this.imod(s).redNeg()):this.imod(s)},x.prototype.pow=function(e,s){if(s.isZero())return new t(1).toRed(this);if(s.cmpn(1)===0)return e.clone();var u=4,f=new Array(1<<u);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],P=0,_=0,l=s.bitLength()%26;for(l===0&&(l=26),h=s.length-1;h>=0;h--){for(var y=s.words[h],U=l-1;U>=0;U--){var q=y>>U&1;if(v!==f[0]&&(v=this.sqr(v)),q===0&&P===0){_=0;continue}P<<=1,P|=q,_++,!(_!==u&&(h!==0||U!==0))&&(v=this.mul(v,f[P]),_=0,P=0)}l=26}return v},x.prototype.convertTo=function(e){var s=e.umod(this.m);return s===e?s.clone():s},x.prototype.convertFrom=function(e){var s=e.clone();return s.red=null,s},t.mont=function(e){return new C(e)};function C(p){x.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(C,x),C.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},C.prototype.convertFrom=function(e){var s=this.imod(e.mul(this.rinv));return s.red=null,s},C.prototype.imul=function(e,s){if(e.isZero()||s.isZero())return e.words[0]=0,e.length=1,e;var u=e.imul(s),f=u.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=u.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)},C.prototype.mul=function(e,s){if(e.isZero()||s.isZero())return new t(0)._forceRed(this);var u=e.mul(s),f=u.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=u.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)},C.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:"0xa079129c989dacac4f5ccb7b2bb2b8f233b13694c465466a344e2e095e987407",published_at:"0xa079129c989dacac4f5ccb7b2bb2b8f233b13694c465466a344e2e095e987407",version:0,config:{versioned_id:"0x85d30849a1e172e1f90bb42e22ed87457a8110dad7658d51c806baa84f5dcd94",admin_cap_id:"0xdae1da9a2bacb4738411365e9719b739b655ce6b737155ff58137b78c944112a",global_config_id:"0x267de967e72360eb09837bb595a0c6b54bb98a2a1ae47436ccab4a99e6b84f25",markets:"0xe0986f697a300da740d384e64c2ba010aa9caf37a54ed0cc8b4098c4d4e592d0",markets_table_id:"0xe9dd2dbc3d68c00f297dd84e57ad28f6a504effbf6b1b869b9e4138ead14c731"}},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],g=oe(c.reserve.config.closeLtvPct).div(100).toString(),m=oe(c.reserve.config.openLtvPct).div(100).toString(),M=a.depositedAmountUsd.gt(0)?a.borrowedAmountUsd.div(a.depositedAmountUsd).toString():"0",S=oe(1).div(g).toString(),A=oe(g).sub(M).toString(),T="0",D="0",R="0",N="0";if(a.borrows&&a.borrows.length>0){let L=a.borrows[0],O=t[L?.coinType];O&&(T=or(sr.BORROW,L?.reserve.borrowAprPercent,ar(O.borrow)).toString()),R=L.borrowedAmountUsd.toString(),N=L.borrowedAmount.toString()}if(a.deposits&&a.deposits.length>0){let L=a.deposits[0],O=t[L?.coinType];O&&(D=or(sr.DEPOSIT,L?.reserve.depositAprPercent,ar(O.deposit)).toString())}return{...n,...a,origin_obligation:i,net_apr_percent:d.toString(),supplied_apr:oe(D).toString(),borrowed_apr:oe(T).toString(),close_ltv:g,open_ltv:m,cr:M,ltr:S,liquidation_buffer:A,deposited_amount_usd:c.depositedAmountUsd.toString(),borrowed_amount_usd:R,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,g=new Ne;return g.moveCall({target:`${r}::market::set_fee_rate`,arguments:[g.object(t),g.object(a),g.pure.u64(d),g.pure.u64(c),g.object(o)],typeArguments:[]}),g};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:g}=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,g]}),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,g=(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:g}}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`,g=(await this._sdk.FullClient.queryEventsByPage({MoveEventType:d})).data.map(m=>m.parsedJson.market_id);return g.length>0?((await this._sdk.FullClient.batchGetObjects(g,{showContent:!0,showType:!0})).forEach(M=>{let S=bi(M),A=`margin_trading_market_info_${S.market_id}`;this._sdk.updateCache(A,S),a.push(S)}),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:g}=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 m=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:a,lstAprPercentMap:d},!0),M=m[t].rewardMap[r],S=m[t].rewardMap[o],{depositedAmountUsd:A,borrowedAmountUsd:T,depositAprPercent:D,borrowAprPercent:R,depositedAmount:N,borrowedAmount:L}=c,{depositLimit:O,borrowLimit:B}=c.config,{depositedAmountUsd:F,borrowedAmountUsd:W,depositAprPercent:j,borrowAprPercent:Z,depositedAmount:w,borrowedAmount:b}=g,{depositLimit:k,borrowLimit:x}=g.config,C=Ee(Se.DEPOSIT,D,he(M.deposit),ur(Se.DEPOSIT,r,d)),p=Ee(Se.BORROW,R,he(M.borrow)),e=Ee(Se.DEPOSIT,j,he(S.deposit),ur(Se.DEPOSIT,r,d)),s=Ee(Se.BORROW,Z,he(S.borrow)),u=se(F.toString()).sub(W.toString()).toString(),f=se(A.toString()).sub(T.toString()).toString(),h=se(O.toString()).sub(se(N.toString())).toString(),v=se(B.toString()).sub(se(L.toString())).toString(),P=se(k.toString()).sub(se(w.toString())).toString(),_=se(x.toString()).sub(se(b.toString())).toString();return{long_liquidity:u,short_liquidity:f,base_total_deposit_apr_percent:C.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:P,quote_token_available_borrow_amount:_,base_deposit_rewards:he(M.deposit),quote_deposit_rewards:he(S.deposit),base_borrow_rewards:he(M.borrow),quote_borrow_rewards:he(S.borrow),base_deposit_apr_percent:D.toString(),base_borrow_apr_percent:R.toString(),quote_deposit_apr_percent:j.toString(),quote_borrow_apr_percent:Z.toString(),obligations:m[t],base_reserve_map_info:c,quote_reserve_map_info:g}}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:g,borrow_permissions_pause:m,repay_permissions_pause:M}=Si(t);return{open_permissions_pause:a,close_permissions_pause:d,deposit_permissions_pause:c,withdraw_permissions_pause:g,borrow_permissions_pause:m,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,g=-7,m=21,M=-1e7,S=1e7,A=!1,T=1,D=0,R={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},N="0123456789abcdefghijklmnopqrstuvwxyz",L=!0;function O(w,b){var k,x,C,p,e,s,u,f,h=this;if(!(h instanceof O))return new O(w,b);if(b==null){if(w&&w._isBigNumber===!0){h.s=w.s,!w.c||w.e>S?h.c=h.e=null:w.e<M?h.c=[h.e=0]:(h.e=w.e,h.c=w.c.slice());return}if((s=typeof w=="number")&&w*0==0){if(h.s=1/w<0?(w=-w,-1):1,w===~~w){for(p=0,e=w;e>=10;e/=10,p++);p>S?h.c=h.e=null:(h.e=p,h.c=[w]);return}f=String(w)}else{if(!Qr.test(f=String(w)))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&&L)return h=new O(w),j(h,d+h.e+1,c);if(f=String(w),s=typeof w=="number"){if(w*0!=0)return o(h,f,s,b);if(h.s=1/w<0?(f=f.slice(1),-1):1,O.DEBUG&&f.replace(/^0\.0*|\./,"").length>15)throw Error(cr+w)}else h.s=f.charCodeAt(0)===45?(f=f.slice(1),-1):1;for(k=N.slice(0,b),p=e=0,u=f.length;e<u;e++)if(k.indexOf(x=f.charAt(e))<0){if(x=="."){if(e>p){p=u;continue}}else if(!C&&(f==f.toUpperCase()&&(f=f.toLowerCase())||f==f.toLowerCase()&&(f=f.toUpperCase()))){C=!0,e=-1,p=0;continue}return o(h,String(w),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(u=f.length;f.charCodeAt(--u)===48;);if(f=f.slice(e,++u)){if(u-=e,s&&O.DEBUG&&u>15&&(w>Ci||w!==Qt(w)))throw Error(cr+h.s*w);if((p=p-e-1)>S)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<u){for(e&&h.c.push(+f.slice(0,e)),u-=tt;e<u;)h.c.push(+f.slice(e,e+=tt));e=tt-(f=f.slice(e)).length}else e-=u;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(w){var b,k;if(w!=null)if(typeof w=="object"){if(w.hasOwnProperty(b="DECIMAL_PLACES")&&(k=w[b],ft(k,0,Wt,b),d=k),w.hasOwnProperty(b="ROUNDING_MODE")&&(k=w[b],ft(k,0,8,b),c=k),w.hasOwnProperty(b="EXPONENTIAL_AT")&&(k=w[b],k&&k.pop?(ft(k[0],-Wt,0,b),ft(k[1],0,Wt,b),g=k[0],m=k[1]):(ft(k,-Wt,Wt,b),g=-(m=k<0?-k:k))),w.hasOwnProperty(b="RANGE"))if(k=w[b],k&&k.pop)ft(k[0],-Wt,-1,b),ft(k[1],1,Wt,b),M=k[0],S=k[1];else if(ft(k,-Wt,Wt,b),k)M=-(S=k<0?-k:k);else throw Error(Vt+b+" cannot be zero: "+k);if(w.hasOwnProperty(b="CRYPTO"))if(k=w[b],k===!!k)if(k)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))A=k;else throw A=!k,Error(Vt+"crypto unavailable");else A=k;else throw Error(Vt+b+" not true or false: "+k);if(w.hasOwnProperty(b="MODULO_MODE")&&(k=w[b],ft(k,0,9,b),T=k),w.hasOwnProperty(b="POW_PRECISION")&&(k=w[b],ft(k,0,Wt,b),D=k),w.hasOwnProperty(b="FORMAT"))if(k=w[b],typeof k=="object")R=k;else throw Error(Vt+b+" not an object: "+k);if(w.hasOwnProperty(b="ALPHABET"))if(k=w[b],typeof k=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(k))L=k.slice(0,10)=="0123456789",N=k;else throw Error(Vt+b+" invalid: "+k)}else throw Error(Vt+"Object expected: "+w);return{DECIMAL_PLACES:d,ROUNDING_MODE:c,EXPONENTIAL_AT:[g,m],RANGE:[M,S],CRYPTO:A,MODULO_MODE:T,POW_PRECISION:D,FORMAT:R,ALPHABET:N}},O.isBigNumber=function(w){if(!w||w._isBigNumber!==!0)return!1;if(!O.DEBUG)return!0;var b,k,x=w.c,C=w.e,p=w.s;t:if({}.toString.call(x)=="[object Array]"){if((p===1||p===-1)&&C>=-Wt&&C<=Wt&&C===Qt(C)){if(x[0]===0){if(C===0&&x.length===1)return!0;break t}if(b=(C+1)%tt,b<1&&(b+=tt),String(x[0]).length==b){for(b=0;b<x.length;b++)if(k=x[b],k<0||k>=ie||k!==Qt(k))break t;if(k!==0)return!0}}}else if(x===null&&C===null&&(p===null||p===1||p===-1))return!0;throw Error(Vt+"Invalid BigNumber: "+w)},O.maximum=O.max=function(){return F(arguments,-1)},O.minimum=O.min=function(){return F(arguments,1)},O.random=(function(){var w=9007199254740992,b=Math.random()*w&2097151?function(){return Qt(Math.random()*w)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(k){var x,C,p,e,s,u=0,f=[],h=new O(a);if(k==null?k=d:ft(k,0,Wt),e=Ai(k/tt),A)if(crypto.getRandomValues){for(x=crypto.getRandomValues(new Uint32Array(e*=2));u<e;)s=x[u]*131072+(x[u+1]>>>11),s>=9e15?(C=crypto.getRandomValues(new Uint32Array(2)),x[u]=C[0],x[u+1]=C[1]):(f.push(s%1e14),u+=2);u=e/2}else if(crypto.randomBytes){for(x=crypto.randomBytes(e*=7);u<e;)s=(x[u]&31)*281474976710656+x[u+1]*1099511627776+x[u+2]*4294967296+x[u+3]*16777216+(x[u+4]<<16)+(x[u+5]<<8)+x[u+6],s>=9e15?crypto.randomBytes(7).copy(x,u):(f.push(s%1e14),u+=7);u=e/7}else throw A=!1,Error(Vt+"crypto unavailable");if(!A)for(;u<e;)s=b(),s<9e15&&(f[u++]=s%1e14);for(e=f[--u],k%=tt,e&&k&&(s=xi[tt-k],f[u]=Qt(e/s)*s);f[u]===0;f.pop(),u--);if(u<0)f=[p=0];else{for(p=-1;f[0]===0;f.splice(0,1),p-=tt);for(u=1,s=f[0];s>=10;s/=10,u++);u<tt&&(p-=tt-u)}return h.e=p,h.c=f,h}})(),O.sum=function(){for(var w=1,b=arguments,k=new O(b[0]);w<b.length;)k=k.plus(b[w++]);return k},r=(function(){var w="0123456789";function b(k,x,C,p){for(var e,s=[0],u,f=0,h=k.length;f<h;){for(u=s.length;u--;s[u]*=x);for(s[0]+=p.indexOf(k.charAt(f++)),e=0;e<s.length;e++)s[e]>C-1&&(s[e+1]==null&&(s[e+1]=0),s[e+1]+=s[e]/C|0,s[e]%=C)}return s.reverse()}return function(k,x,C,p,e){var s,u,f,h,v,P,_,l,y=k.indexOf("."),U=d,q=c;for(y>=0&&(h=D,D=0,k=k.replace(".",""),l=new O(x),P=l.pow(k.length-y),D=h,l.c=b(ce(Yt(P.c),P.e,"0"),10,C,w),l.e=l.c.length),_=b(k,x,C,e?(s=N,w):(s=w,N)),f=h=_.length;_[--h]==0;_.pop());if(!_[0])return s.charAt(0);if(y<0?--f:(P.c=_,P.e=f,P.s=p,P=i(P,l,U,q,C),_=P.c,v=P.r,f=P.e),u=f+U+1,y=_[u],h=C/2,v=v||u<0||_[u+1]!=null,v=q<4?(y!=null||v)&&(q==0||q==(P.s<0?3:2)):y>h||y==h&&(q==4||v||q==6&&_[u-1]&1||q==(P.s<0?8:7)),u<1||!_[0])k=v?ce(s.charAt(1),-U,s.charAt(0)):s.charAt(0);else{if(_.length=u,v)for(--C;++_[--u]>C;)_[u]=0,u||(++f,_=[1].concat(_));for(h=_.length;!_[--h];);for(y=0,k="";y<=h;k+=s.charAt(_[y++]));k=ce(k,f,s.charAt(0))}return k}})(),i=(function(){function w(x,C,p){var e,s,u,f,h=0,v=x.length,P=C%pe,_=C/pe|0;for(x=x.slice();v--;)u=x[v]%pe,f=x[v]/pe|0,e=_*u+f*P,s=P*u+e%pe*pe+h,h=(s/p|0)+(e/pe|0)+_*f,x[v]=s%p;return h&&(x=[h].concat(x)),x}function b(x,C,p,e){var s,u;if(p!=e)u=p>e?1:-1;else for(s=u=0;s<p;s++)if(x[s]!=C[s]){u=x[s]>C[s]?1:-1;break}return u}function k(x,C,p,e){for(var s=0;p--;)x[p]-=s,s=x[p]<C[p]?1:0,x[p]=s*e+x[p]-C[p];for(;!x[0]&&x.length>1;x.splice(0,1));}return function(x,C,p,e,s){var u,f,h,v,P,_,l,y,U,q,$,K,G,J,rt,V,it,ut=x.s==C.s?1:-1,et=x.c,X=C.c;if(!et||!et[0]||!X||!X[0])return new O(!x.s||!C.s||(et?X&&et[0]==X[0]:!X)?NaN:et&&et[0]==0||!X?ut*0:ut/0);for(y=new O(ut),U=y.c=[],f=x.e-C.e,ut=p+f+1,s||(s=ie,f=te(x.e/tt)-te(C.e/tt),ut=ut/tt|0),h=0;X[h]==(et[h]||0);h++);if(X[h]>(et[h]||0)&&f--,ut<0)U.push(1),v=!0;else{for(J=et.length,V=X.length,h=0,ut+=2,P=Qt(s/(X[0]+1)),P>1&&(X=w(X,P,s),et=w(et,P,s),V=X.length,J=et.length),G=V,q=et.slice(0,V),$=q.length;$<V;q[$++]=0);it=X.slice(),it=[0].concat(it),rt=X[0],X[1]>=s/2&&rt++;do{if(P=0,u=b(X,q,V,$),u<0){if(K=q[0],V!=$&&(K=K*s+(q[1]||0)),P=Qt(K/rt),P>1)for(P>=s&&(P=s-1),_=w(X,P,s),l=_.length,$=q.length;b(_,q,l,$)==1;)P--,k(_,V<l?it:X,l,s),l=_.length,u=1;else P==0&&(u=P=1),_=X.slice(),l=_.length;if(l<$&&(_=[0].concat(_)),k(q,_,$,s),$=q.length,u==-1)for(;b(X,q,V,$)<1;)P++,k(q,V<$?it:X,$,s),$=q.length}else u===0&&(P++,q=[0]);U[h++]=P,q[0]?q[$++]=et[G]||0:(q=[et[G]],$=1)}while((G++<J||q[0]!=null)&&ut--);v=q[0]!=null,U[0]||U.splice(0,1)}if(s==ie){for(h=1,ut=U[0];ut>=10;ut/=10,h++);j(y,p+(y.e=h+f*tt-1)+1,e,v)}else y.e=f,y.r=+v;return y}})();function B(w,b,k,x){var C,p,e,s,u;if(k==null?k=c:ft(k,0,8),!w.c)return w.toString();if(C=w.c[0],e=w.e,b==null)u=Yt(w.c),u=x==1||x==2&&(e<=g||e>=m)?Fe(u,e):ce(u,e,"0");else if(w=j(new O(w),b,k),p=w.e,u=Yt(w.c),s=u.length,x==1||x==2&&(b<=p||p<=g)){for(;s<b;u+="0",s++);u=Fe(u,p)}else if(b-=e+(x===2&&p>e),u=ce(u,p,"0"),p+1>s){if(--b>0)for(u+=".";b--;u+="0");}else if(b+=p-s,b>0)for(p+1==s&&(u+=".");b--;u+="0");return w.s<0&&C?"-"+u:u}function F(w,b){for(var k,x,C=1,p=new O(w[0]);C<w.length;C++)x=new O(w[C]),(!x.s||(k=Me(p,x))===b||k===0&&p.s===b)&&(p=x);return p}function W(w,b,k){for(var x=1,C=b.length;!b[--C];b.pop());for(C=b[0];C>=10;C/=10,x++);return(k=x+k*tt-1)>S?w.c=w.e=null:k<M?w.c=[w.e=0]:(w.e=k,w.c=b),w}o=(function(){var w=/^(-?)0([xbo])(?=\w[\w.]*$)/i,b=/^([^.]+)\.$/,k=/^\.([^.]+)$/,x=/^-?(Infinity|NaN)$/,C=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(p,e,s,u){var f,h=s?e:e.replace(C,"");if(x.test(h))p.s=isNaN(h)?null:h<0?-1:1;else{if(!s&&(h=h.replace(w,function(v,P,_){return f=(_=_.toLowerCase())=="x"?16:_=="b"?2:8,!u||u==f?P:v}),u&&(f=u,h=h.replace(b,"$1").replace(k,"0.$1")),e!=h))return new O(h,f);if(O.DEBUG)throw Error(Vt+"Not a"+(u?" base "+u:"")+" number: "+e);p.s=null}p.c=p.e=null}})();function j(w,b,k,x){var C,p,e,s,u,f,h,v=w.c,P=xi;if(v){t:{for(C=1,s=v[0];s>=10;s/=10,C++);if(p=b-C,p<0)p+=tt,e=b,u=v[f=0],h=Qt(u/P[C-e-1]%10);else if(f=Ai((p+1)/tt),f>=v.length)if(x){for(;v.length<=f;v.push(0));u=h=0,C=1,p%=tt,e=p-tt+1}else break t;else{for(u=s=v[f],C=1;s>=10;s/=10,C++);p%=tt,e=p-tt+C,h=e<0?0:Qt(u/P[C-e-1]%10)}if(x=x||b<0||v[f+1]!=null||(e<0?u:u%P[C-e-1]),x=k<4?(h||x)&&(k==0||k==(w.s<0?3:2)):h>5||h==5&&(k==4||x||k==6&&(p>0?e>0?u/P[C-e]:0:v[f-1])%10&1||k==(w.s<0?8:7)),b<1||!v[0])return v.length=0,x?(b-=w.e+1,v[0]=P[(tt-b%tt)%tt],w.e=-b||0):v[0]=w.e=0,w;if(p==0?(v.length=f,s=1,f--):(v.length=f+1,s=P[tt-p],v[f]=e>0?Qt(u/P[C-e]%P[e])*s:0),x)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&&(w.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());}w.e>S?w.c=w.e=null:w.e<M&&(w.c=[w.e=0])}return w}function Z(w){var b,k=w.e;return k===null?w.toString():(b=Yt(w.c),b=k<=g||k>=m?Fe(b,k):ce(b,k,"0"),w.s<0?"-"+b:b)}return t.absoluteValue=t.abs=function(){var w=new O(this);return w.s<0&&(w.s=1),w},t.comparedTo=function(w,b){return Me(this,new O(w,b))},t.decimalPlaces=t.dp=function(w,b){var k,x,C,p=this;if(w!=null)return ft(w,0,Wt),b==null?b=c:ft(b,0,8),j(new O(p),w+p.e+1,b);if(!(k=p.c))return null;if(x=((C=k.length-1)-te(this.e/tt))*tt,C=k[C])for(;C%10==0;C/=10,x--);return x<0&&(x=0),x},t.dividedBy=t.div=function(w,b){return i(this,new O(w,b),d,c)},t.dividedToIntegerBy=t.idiv=function(w,b){return i(this,new O(w,b),0,1)},t.exponentiatedBy=t.pow=function(w,b){var k,x,C,p,e,s,u,f,h,v=this;if(w=new O(w),w.c&&!w.isInteger())throw Error(Vt+"Exponent not an integer: "+Z(w));if(b!=null&&(b=new O(b)),s=w.e>14,!v.c||!v.c[0]||v.c[0]==1&&!v.e&&v.c.length==1||!w.c||!w.c[0])return h=new O(Math.pow(+Z(v),s?w.s*(2-qe(w)):+Z(w))),b?h.mod(b):h;if(u=w.s<0,b){if(b.c?!b.c[0]:!b.s)return new O(NaN);x=!u&&v.isInteger()&&b.isInteger(),x&&(v=v.mod(b))}else{if(w.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(w)?-0:0,v.e>-1&&(p=1/p),new O(u?1/p:p);D&&(p=Ai(D/tt+2))}for(s?(k=new O(.5),u&&(w.s=1),f=qe(w)):(C=Math.abs(+Z(w)),f=C%2),h=new O(a);;){if(f){if(h=h.times(v),!h.c)break;p?h.c.length>p&&(h.c.length=p):x&&(h=h.mod(b))}if(C){if(C=Qt(C/2),C===0)break;f=C%2}else if(w=w.times(k),j(w,w.e+1,1),w.e>14)f=qe(w);else{if(C=+Z(w),C===0)break;f=C%2}v=v.times(v),p?v.c&&v.c.length>p&&(v.c.length=p):x&&(v=v.mod(b))}return x?h:(u&&(h=a.div(h)),b?h.mod(b):p?j(h,D,c,e):h)},t.integerValue=function(w){var b=new O(this);return w==null?w=c:ft(w,0,8),j(b,b.e+1,w)},t.isEqualTo=t.eq=function(w,b){return Me(this,new O(w,b))===0},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(w,b){return Me(this,new O(w,b))>0},t.isGreaterThanOrEqualTo=t.gte=function(w,b){return(b=Me(this,new O(w,b)))===1||b===0},t.isInteger=function(){return!!this.c&&te(this.e/tt)>this.c.length-2},t.isLessThan=t.lt=function(w,b){return Me(this,new O(w,b))<0},t.isLessThanOrEqualTo=t.lte=function(w,b){return(b=Me(this,new O(w,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(w,b){var k,x,C,p,e=this,s=e.s;if(w=new O(w,b),b=w.s,!s||!b)return new O(NaN);if(s!=b)return w.s=-b,e.plus(w);var u=e.e/tt,f=w.e/tt,h=e.c,v=w.c;if(!u||!f){if(!h||!v)return h?(w.s=-b,w):new O(v?e:NaN);if(!h[0]||!v[0])return v[0]?(w.s=-b,w):new O(h[0]?e:c==3?-0:0)}if(u=te(u),f=te(f),h=h.slice(),s=u-f){for((p=s<0)?(s=-s,C=h):(f=u,C=v),C.reverse(),b=s;b--;C.push(0));C.reverse()}else for(x=(p=(s=h.length)<(b=v.length))?s:b,s=b=0;b<x;b++)if(h[b]!=v[b]){p=h[b]<v[b];break}if(p&&(C=h,h=v,v=C,w.s=-w.s),b=(x=v.length)-(k=h.length),b>0)for(;b--;h[k++]=0);for(b=ie-1;x>s;){if(h[--x]<v[x]){for(k=x;k&&!h[--k];h[k]=b);--h[k],h[x]+=ie}h[x]-=v[x]}for(;h[0]==0;h.splice(0,1),--f);return h[0]?W(w,h,f):(w.s=c==3?-1:1,w.c=[w.e=0],w)},t.modulo=t.mod=function(w,b){var k,x,C=this;return w=new O(w,b),!C.c||!w.s||w.c&&!w.c[0]?new O(NaN):!w.c||C.c&&!C.c[0]?new O(C):(T==9?(x=w.s,w.s=1,k=i(C,w,0,3),w.s=x,k.s*=x):k=i(C,w,0,T),w=C.minus(k.times(w)),!w.c[0]&&T==1&&(w.s=C.s),w)},t.multipliedBy=t.times=function(w,b){var k,x,C,p,e,s,u,f,h,v,P,_,l,y,U,q=this,$=q.c,K=(w=new O(w,b)).c;if(!$||!K||!$[0]||!K[0])return!q.s||!w.s||$&&!$[0]&&!K||K&&!K[0]&&!$?w.c=w.e=w.s=null:(w.s*=q.s,!$||!K?w.c=w.e=null:(w.c=[0],w.e=0)),w;for(x=te(q.e/tt)+te(w.e/tt),w.s*=q.s,u=$.length,v=K.length,u<v&&(l=$,$=K,K=l,C=u,u=v,v=C),C=u+v,l=[];C--;l.push(0));for(y=ie,U=pe,C=v;--C>=0;){for(k=0,P=K[C]%U,_=K[C]/U|0,e=u,p=C+e;p>C;)f=$[--e]%U,h=$[e]/U|0,s=_*f+h*P,f=P*f+s%U*U+l[p]+k,k=(f/y|0)+(s/U|0)+_*h,l[p--]=f%y;l[p]=k}return k?++x:l.splice(0,1),W(w,l,x)},t.negated=function(){var w=new O(this);return w.s=-w.s||null,w},t.plus=function(w,b){var k,x=this,C=x.s;if(w=new O(w,b),b=w.s,!C||!b)return new O(NaN);if(C!=b)return w.s=-b,x.minus(w);var p=x.e/tt,e=w.e/tt,s=x.c,u=w.c;if(!p||!e){if(!s||!u)return new O(C/0);if(!s[0]||!u[0])return u[0]?w:new O(s[0]?x:C*0)}if(p=te(p),e=te(e),s=s.slice(),C=p-e){for(C>0?(e=p,k=u):(C=-C,k=s),k.reverse();C--;k.push(0));k.reverse()}for(C=s.length,b=u.length,C-b<0&&(k=u,u=s,s=k,b=C),C=0;b;)C=(s[--b]=s[b]+u[b]+C)/ie|0,s[b]=ie===s[b]?0:s[b]%ie;return C&&(s=[C].concat(s),++e),W(w,s,e)},t.precision=t.sd=function(w,b){var k,x,C,p=this;if(w!=null&&w!==!!w)return ft(w,1,Wt),b==null?b=c:ft(b,0,8),j(new O(p),w,b);if(!(k=p.c))return null;if(C=k.length-1,x=C*tt+1,C=k[C]){for(;C%10==0;C/=10,x--);for(C=k[0];C>=10;C/=10,x++);}return w&&p.e+1>x&&(x=p.e+1),x},t.shiftedBy=function(w){return ft(w,-Ci,Ci),this.times("1e"+w)},t.squareRoot=t.sqrt=function(){var w,b,k,x,C,p=this,e=p.c,s=p.s,u=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+u)%2==0&&(b+="0"),s=Math.sqrt(+b),u=te((u+1)/2)-(u<0||u%2),s==1/0?b="5e"+u:(b=s.toExponential(),b=b.slice(0,b.indexOf("e")+1)+u),k=new O(b)):k=new O(s+""),k.c[0]){for(u=k.e,s=u+f,s<3&&(s=0);;)if(C=k,k=h.times(C.plus(i(p,C,f,1))),Yt(C.c).slice(0,s)===(b=Yt(k.c)).slice(0,s))if(k.e<u&&--s,b=b.slice(s-3,s+1),b=="9999"||!x&&b=="4999"){if(!x&&(j(C,C.e+d+2,0),C.times(C).eq(p))){k=C;break}f+=4,s+=4,x=1}else{(!+b||!+b.slice(1)&&b.charAt(0)=="5")&&(j(k,k.e+d+2,1),w=!k.times(k).eq(p));break}}return j(k,k.e+d+1,c,w)},t.toExponential=function(w,b){return w!=null&&(ft(w,0,Wt),w++),B(this,w,b,1)},t.toFixed=function(w,b){return w!=null&&(ft(w,0,Wt),w=w+this.e+1),B(this,w,b)},t.toFormat=function(w,b,k){var x,C=this;if(k==null)w!=null&&b&&typeof b=="object"?(k=b,b=null):w&&typeof w=="object"?(k=w,w=b=null):k=R;else if(typeof k!="object")throw Error(Vt+"Argument not an object: "+k);if(x=C.toFixed(w,b),C.c){var p,e=x.split("."),s=+k.groupSize,u=+k.secondaryGroupSize,f=k.groupSeparator||"",h=e[0],v=e[1],P=C.s<0,_=P?h.slice(1):h,l=_.length;if(u&&(p=s,s=u,u=p,l-=p),s>0&&l>0){for(p=l%s||s,h=_.substr(0,p);p<l;p+=s)h+=f+_.substr(p,s);u>0&&(h+=f+_.slice(p)),P&&(h="-"+h)}x=v?h+(k.decimalSeparator||"")+((u=+k.fractionGroupSize)?v.replace(new RegExp("\\d{"+u+"}\\B","g"),"$&"+(k.fractionGroupSeparator||"")):v):h}return(k.prefix||"")+x+(k.suffix||"")},t.toFraction=function(w){var b,k,x,C,p,e,s,u,f,h,v,P,_=this,l=_.c;if(w!=null&&(s=new O(w),!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(!l)return new O(_);for(b=new O(a),f=k=new O(a),x=u=new O(a),P=Yt(l),p=b.e=P.length-_.e-1,b.c[0]=xi[(e=p%tt)<0?tt+e:e],w=!w||s.comparedTo(b)>0?p>0?b:f:s,e=S,S=1/0,s=new O(P),u.c[0]=0;h=i(s,b,0,1),C=k.plus(h.times(x)),C.comparedTo(w)!=1;)k=x,x=C,f=u.plus(h.times(C=f)),u=C,b=s.minus(h.times(C=b)),s=C;return C=i(w.minus(k),x,0,1),u=u.plus(C.times(f)),k=k.plus(C.times(x)),u.s=f.s=_.s,p=p*2,v=i(f,x,p,c).minus(_).abs().comparedTo(i(u,k,p,c).minus(_).abs())<1?[f,x]:[u,k],S=e,v},t.toNumber=function(){return+Z(this)},t.toPrecision=function(w,b){return w!=null&&ft(w,1,Wt),B(this,w,b,2)},t.toString=function(w){var b,k=this,x=k.s,C=k.e;return C===null?x?(b="Infinity",x<0&&(b="-"+b)):b="NaN":(w==null?b=C<=g||C>=m?Fe(Yt(k.c),C):ce(Yt(k.c),C,"0"):w===10&&L?(k=j(new O(k),d+C+1,c),b=ce(Yt(k.c),k.e,"0")):(ft(w,2,N.length,"Base"),b=r(ce(Yt(k.c),C,"0"),10,w,x,!0)),x<0&&k.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,g=n.e,m=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=g==m,!t||!a)return o?0:!t^r?1:-1;if(!o)return g>m^r?1:-1;for(c=(g=t.length)<(m=a.length)?g:m,d=0;d<c;d++)if(t[d]!=a[d])return t[d]>a[d]^r?1:-1;return g==m?0:g>m^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,Ti="0123456789abcdef",$e="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",We="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Di={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,I={toStringTag:wr};I.absoluteValue=I.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),z(n)};I.ceil=function(){return z(new this.constructor(this),this.e+1,2)};I.clampedTo=I.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)};I.comparedTo=I.cmp=function(n){var i,r,o,t,a=this,d=a.d,c=(n=new a.constructor(n)).d,g=a.s,m=n.s;if(!d||!c)return!g||!m?NaN:g!==m?g:d===c?0:!d^g<0?1:-1;if(!d[0]||!c[0])return d[0]?g:c[0]?-m:0;if(g!==m)return g;if(a.e!==n.e)return a.e>n.e^g<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]^g<0?1:-1;return o===t?0:o>t^g<0?1:-1};I.cosine=I.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)};I.cubeRoot=I.cbrt=function(){var n,i,r,o,t,a,d,c,g,m,M=this,S=M.constructor;if(!M.isFinite()||M.isZero())return new S(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 S(r),o.s=M.s):o=new S(a.toString()),d=(n=S.precision)+3;;)if(c=o,g=c.times(c).times(c),m=g.plus(M),o=ot(m.plus(M).times(c),m.plus(g),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,S.rounding,i)};I.decimalPlaces=I.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};I.dividedBy=I.div=function(n){return ot(this,new this.constructor(n))};I.dividedToIntegerBy=I.divToInt=function(n){var i=this,r=i.constructor;return z(ot(i,new r(n),0,1,1),r.precision,r.rounding)};I.equals=I.eq=function(n){return this.cmp(n)===0};I.floor=function(){return z(new this.constructor(this),this.e+1,3)};I.greaterThan=I.gt=function(n){return this.cmp(n)>0};I.greaterThanOrEqualTo=I.gte=function(n){var i=this.cmp(n);return i==1||i===0};I.hyperbolicCosine=I.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 g,m=n,M=new d(8);m--;)g=a.times(a),a=c.minus(g.times(M.minus(g.times(M))));return z(a,d.precision=r,d.rounding=o,!0)};I.hyperbolicSine=I.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),g=new a(16),m=new a(20);n--;)d=t.times(t),t=t.times(c.plus(d.times(g.times(d).plus(m))))}return a.precision=i,a.rounding=r,z(t,i,r,!0)};I.hyperbolicTangent=I.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)};I.inverseCosine=I.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))};I.inverseHyperbolicCosine=I.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)};I.inverseHyperbolicSine=I.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())};I.inverseHyperbolicTangent=I.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)};I.inverseSine=I.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)))};I.inverseTangent=I.atan=function(){var n,i,r,o,t,a,d,c,g,m=this,M=m.constructor,S=M.precision,A=M.rounding;if(m.isFinite()){if(m.isZero())return new M(m);if(m.abs().eq(1)&&S+4<=Oi)return d=ae(M,S+4,A).times(.25),d.s=m.s,d}else{if(!m.s)return new M(NaN);if(S+4<=Oi)return d=ae(M,S+4,A).times(.5),d.s=m.s,d}for(M.precision=c=S+10,M.rounding=1,r=Math.min(28,c/H+2|0),n=r;n;--n)m=m.div(m.times(m).plus(1).sqrt().plus(1));for(Y=!1,i=Math.ceil(c/H),o=1,g=m.times(m),d=new M(m),t=m;n!==-1;)if(t=t.times(g),a=d.minus(t.div(o+=2)),t=t.times(g),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=S,M.rounding=A,!0)};I.isFinite=function(){return!!this.d};I.isInteger=I.isInt=function(){return!!this.d&&zt(this.e/H)>this.d.length-2};I.isNaN=function(){return!this.s};I.isNegative=I.isNeg=function(){return this.s<0};I.isPositive=I.isPos=function(){return this.s>0};I.isZero=function(){return!!this.d&&this.d[0]===0};I.lessThan=I.lt=function(n){return this.cmp(n)<0};I.lessThanOrEqualTo=I.lte=function(n){return this.cmp(n)<1};I.logarithm=I.log=function(n){var i,r,o,t,a,d,c,g,m=this,M=m.constructor,S=M.precision,A=M.rounding,T=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=m.d,m.s<0||!r||!r[0]||m.eq(1))return new M(r&&!r[0]?-1/0:m.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=S+T,d=ge(m,c),o=i?Ze(M,c+10):ge(n,c),g=ot(d,o,c,1),De(g.d,t=S,A))do if(c+=10,d=ge(m,c),o=i?Ze(M,c+10):ge(n,c),g=ot(d,o,c,1),!a){+Zt(g.d).slice(t+1,t+15)+1==1e14&&(g=z(g,S+1,0));break}while(De(g.d,t+=10,A));return Y=!0,z(g,S,A)};I.minus=I.sub=function(n){var i,r,o,t,a,d,c,g,m,M,S,A,T=this,D=T.constructor;if(n=new D(n),!T.d||!n.d)return!T.s||!n.s?n=new D(NaN):T.d?n.s=-n.s:n=new D(n.d||T.s!==n.s?T:NaN),n;if(T.s!=n.s)return n.s=-n.s,T.plus(n);if(m=T.d,A=n.d,c=D.precision,g=D.rounding,!m[0]||!A[0]){if(A[0])n.s=-n.s;else if(m[0])n=new D(T);else return new D(g===3?-0:0);return Y?z(n,c,g):n}if(r=zt(n.e/H),M=zt(T.e/H),m=m.slice(),a=M-r,a){for(S=a<0,S?(i=m,a=-a,d=A.length):(i=A,r=M,d=m.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=m.length,d=A.length,S=o<d,S&&(d=o),o=0;o<d;o++)if(m[o]!=A[o]){S=m[o]<A[o];break}a=0}for(S&&(i=m,m=A,A=i,n.s=-n.s),d=m.length,o=A.length-d;o>0;--o)m[d++]=0;for(o=A.length;o>a;){if(m[--o]<A[o]){for(t=o;t&&m[--t]===0;)m[t]=re-1;--m[t],m[o]+=re}m[o]-=A[o]}for(;m[--d]===0;)m.pop();for(;m[0]===0;m.shift())--r;return m[0]?(n.d=m,n.e=ze(m,r),Y?z(n,c,g):n):new D(g===3?-0:0)};I.modulo=I.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))};I.naturalExponential=I.exp=function(){return Ri(this)};I.naturalLogarithm=I.ln=function(){return ge(this)};I.negated=I.neg=function(){var n=new this.constructor(this);return n.s=-n.s,z(n)};I.plus=I.add=function(n){var i,r,o,t,a,d,c,g,m,M,S=this,A=S.constructor;if(n=new A(n),!S.d||!n.d)return!S.s||!n.s?n=new A(NaN):S.d||(n=new A(n.d||S.s===n.s?S:NaN)),n;if(S.s!=n.s)return n.s=-n.s,S.minus(n);if(m=S.d,M=n.d,c=A.precision,g=A.rounding,!m[0]||!M[0])return M[0]||(n=new A(S)),Y?z(n,c,g):n;if(a=zt(S.e/H),o=zt(n.e/H),m=m.slice(),t=a-o,t){for(t<0?(r=m,t=-t,d=M.length):(r=M,o=a,d=m.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=m.length,t=M.length,d-t<0&&(t=d,r=M,M=m,m=r),i=0;t;)i=(m[--t]=m[t]+M[t]+i)/re|0,m[t]%=re;for(i&&(m.unshift(i),++o),d=m.length;m[--d]==0;)m.pop();return n.d=m,n.e=ze(m,o),Y?z(n,c,g):n};I.precision=I.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};I.round=function(){var n=this,i=n.constructor;return z(new i(n),n.e+1,i.rounding)};I.sine=I.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)};I.squareRoot=I.sqrt=function(){var n,i,r,o,t,a,d=this,c=d.d,g=d.e,m=d.s,M=d.constructor;if(m!==1||!c||!c[0])return new M(!m||m<0&&(!c||c[0])?NaN:c?d:1/0);for(Y=!1,m=Math.sqrt(+d),m==0||m==1/0?(i=Zt(c),(i.length+g)%2==0&&(i+="0"),m=Math.sqrt(i),g=zt((g+1)/2)-(g<0||g%2),m==1/0?i="5e"+g:(i=m.toExponential(),i=i.slice(0,i.indexOf("e")+1)+g),o=new M(i)):o=new M(m.toString()),r=(g=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,g+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,g+1,1),n=!o.times(o).eq(d));break}return Y=!0,z(o,g,M.rounding,n)};I.tangent=I.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)};I.times=I.mul=function(n){var i,r,o,t,a,d,c,g,m,M=this,S=M.constructor,A=M.d,T=(n=new S(n)).d;if(n.s*=M.s,!A||!A[0]||!T||!T[0])return new S(!n.s||A&&!A[0]&&!T||T&&!T[0]&&!A?NaN:!A||!T?n.s/0:n.s*0);for(r=zt(M.e/H)+zt(n.e/H),g=A.length,m=T.length,g<m&&(a=A,A=T,T=a,d=g,g=m,m=d),a=[],d=g+m,o=d;o--;)a.push(0);for(o=m;--o>=0;){for(i=0,t=g+o;t>o;)c=a[t]+T[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,S.precision,S.rounding):n};I.toBinary=function(n,i){return Li(this,2,n,i)};I.toDecimalPlaces=I.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))};I.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};I.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};I.toFraction=function(n){var i,r,o,t,a,d,c,g,m,M,S,A,T=this,D=T.d,R=T.constructor;if(!D)return new R(T);if(m=r=new R(1),o=g=new R(0),i=new R(o),a=i.e=Mr(D)-T.e-1,d=a%H,i.d[0]=$t(10,d<0?H+d:d),n==null)n=a>0?i:m;else{if(c=new R(n),!c.isInt()||c.lt(m))throw Error(_e+c);n=c.gt(i)?a>0?i:m:c}for(Y=!1,c=new R(Zt(D)),M=R.precision,R.precision=a=D.length*H*2;S=ot(c,i,0,1,1),t=r.plus(S.times(o)),t.cmp(n)!=1;)r=o,o=t,t=m,m=g.plus(S.times(t)),g=t,t=i,i=c.minus(S.times(t)),c=t;return t=ot(n.minus(r),o,0,1,1),g=g.plus(t.times(m)),r=r.plus(t.times(o)),g.s=m.s=T.s,A=ot(m,o,a,1).minus(T).abs().cmp(ot(g,r,a,1).minus(T).abs())<1?[m,o]:[g,r],R.precision=M,Y=!0,A};I.toHexadecimal=I.toHex=function(n,i){return Li(this,16,n,i)};I.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};I.toNumber=function(){return+this};I.toOctal=function(n,i){return Li(this,8,n,i)};I.toPower=I.pow=function(n){var i,r,o,t,a,d,c=this,g=c.constructor,m=+(n=new g(n));if(!c.d||!n.d||!c.d[0]||!n.d[0])return new g($t(+c,m));if(c=new g(c),c.eq(1))return c;if(o=g.precision,a=g.rounding,n.eq(1))return z(c,o,a);if(i=zt(n.e/H),i>=n.d.length-1&&(r=m<0?-m:m)<=on)return t=br(g,c,r,o),n.s<0?new g(1).div(t):z(t,o,a);if(d=c.s,d<0){if(i<n.d.length-1)return new g(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,m),i=r==0||!isFinite(r)?zt(m*(Math.log("0."+Zt(c.d))/Math.LN10+c.e+1)):new g(r+"").e,i>g.maxE+1||i<g.minE-1?new g(i>0?d/0:0):(Y=!1,g.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),De(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,g.rounding=a,z(t,o,a))};I.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};I.toSignificantDigits=I.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)};I.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};I.truncated=I.trunc=function(){return z(new this.constructor(this),this.e+1,1)};I.valueOf=I.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 De(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]+=Ti.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,g=o.length;for(o=o.slice();g--;)d=o[g]*t+c,o[g]=d%a|0,c=d/a|0;return c&&o.unshift(c),o}function i(o,t,a,d){var c,g;if(a!=d)g=a>d?1:-1;else for(c=g=0;c<a;c++)if(o[c]!=t[c]){g=o[c]>t[c]?1:-1;break}return g}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,g){var m,M,S,A,T,D,R,N,L,O,B,F,W,j,Z,w,b,k,x,C,p=o.constructor,e=o.s==t.s?1:-1,s=o.d,u=t.d;if(!s||!s[0]||!u||!u[0])return new p(!o.s||!t.s||(s?u&&s[0]==u[0]:!u)?NaN:s&&s[0]==0||!u?e*0:e/0);for(g?(T=1,M=o.e-t.e):(g=re,T=H,M=zt(o.e/T)-zt(t.e/T)),x=u.length,b=s.length,L=new p(e),O=L.d=[],S=0;u[S]==(s[S]||0);S++);if(u[S]>(s[S]||0)&&M--,a==null?(j=a=p.precision,d=p.rounding):c?j=a+(o.e-t.e)+1:j=a,j<0)O.push(1),D=!0;else{if(j=j/T+2|0,S=0,x==1){for(A=0,u=u[0],j++;(S<b||A)&&j--;S++)Z=A*g+(s[S]||0),O[S]=Z/u|0,A=Z%u|0;D=A||S<b}else{for(A=g/(u[0]+1)|0,A>1&&(u=n(u,A,g),s=n(s,A,g),x=u.length,b=s.length),w=x,B=s.slice(0,x),F=B.length;F<x;)B[F++]=0;C=u.slice(),C.unshift(0),k=u[0],u[1]>=g/2&&++k;do A=0,m=i(u,B,x,F),m<0?(W=B[0],x!=F&&(W=W*g+(B[1]||0)),A=W/k|0,A>1?(A>=g&&(A=g-1),R=n(u,A,g),N=R.length,F=B.length,m=i(R,B,N,F),m==1&&(A--,r(R,x<N?C:u,N,g))):(A==0&&(m=A=1),R=u.slice()),N=R.length,N<F&&R.unshift(0),r(B,R,F,g),m==-1&&(F=B.length,m=i(u,B,x,F),m<1&&(A++,r(B,x<F?C:u,F,g))),F=B.length):m===0&&(A++,B=[0]),O[S++]=A,m&&B[0]?B[F++]=s[w]||0:(B=[s[w]],F=1);while((w++<b||B[0]!==void 0)&&j--);D=B[0]!==void 0}O[0]||O.shift()}if(T==1)L.e=M,mr=D;else{for(S=1,A=O[0];A>=10;A/=10)S++;L.e=S+M*T-1,z(L,c?a+L.e+1:a,d,D)}return L}})();function z(n,i,r,o){var t,a,d,c,g,m,M,S,A,T=n.constructor;t:if(i!=null){if(S=n.d,!S)return n;for(t=1,c=S[0];c>=10;c/=10)t++;if(a=i-t,a<0)a+=H,d=i,M=S[A=0],g=M/$t(10,t-d-1)%10|0;else if(A=Math.ceil((a+1)/H),c=S.length,A>=c)if(o){for(;c++<=A;)S.push(0);M=g=0,t=1,a%=H,d=a-H+1}else break t;else{for(M=c=S[A],t=1;c>=10;c/=10)t++;a%=H,d=a-H+t,g=d<0?0:M/$t(10,t-d-1)%10|0}if(o=o||i<0||S[A+1]!==void 0||(d<0?M:M%$t(10,t-d-1)),m=r<4?(g||o)&&(r==0||r==(n.s<0?3:2)):g>5||g==5&&(r==4||o||r==6&&(a>0?d>0?M/$t(10,t-d):0:S[A-1])%10&1||r==(n.s<0?8:7)),i<1||!S[0])return S.length=0,m?(i-=n.e+1,S[0]=$t(10,(H-i%H)%H),n.e=-i||0):S[0]=n.e=0,n;if(a==0?(S.length=A,c=1,A--):(S.length=A+1,c=$t(10,H-a),S[A]=d>0?(M/$t(10,t-d)%$t(10,d)|0)*c:0),m)for(;;)if(A==0){for(a=1,d=S[0];d>=10;d/=10)a++;for(d=S[0]+=c,c=1;d>=10;d/=10)c++;a!=c&&(n.e++,S[0]==re&&(S[0]=1));break}else{if(S[A]+=c,S[A]!=re)break;S[A--]=0,c=1}for(a=S.length;S[--a]===0;)S.pop()}return Y&&(n.e>T.maxE?(n.d=null,n.e=NaN):n.e<T.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,g,m=0,M=0,S=0,A=n.constructor,T=A.rounding,D=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,g=D):g=i,c=new A(.03125);n.e>-2;)n=n.times(c),S+=5;for(o=Math.log($t(2,S))/Math.LN10*2+5|0,g+=o,r=a=d=new A(1),A.precision=g;;){if(a=z(a.times(n),g,1),r=r.times(++M),c=d.plus(ot(a,r,g,1)),Zt(c.d).slice(0,g)===Zt(d.d).slice(0,g)){for(t=S;t--;)d=z(d.times(d),g,1);if(i==null)if(m<3&&De(d.d,g-o,T,m))A.precision=g+=10,r=a=c=new A(1),M=0,m++;else return z(d,A.precision=D,T,Y=!0);else return A.precision=D,d}d=c}}function ge(n,i){var r,o,t,a,d,c,g,m,M,S,A,T=1,D=10,R=n,N=R.d,L=R.constructor,O=L.rounding,B=L.precision;if(R.s<0||!N||!N[0]||!R.e&&N[0]==1&&N.length==1)return new L(N&&!N[0]?-1/0:R.s!=1?NaN:N?0:R);if(i==null?(Y=!1,M=B):M=i,L.precision=M+=D,r=Zt(N),o=r.charAt(0),Math.abs(a=R.e)<15e14){for(;o<7&&o!=1||o==1&&r.charAt(1)>3;)R=R.times(n),r=Zt(R.d),o=r.charAt(0),T++;a=R.e,o>1?(R=new L("0."+r),a++):R=new L(o+"."+r.slice(1))}else return m=Ze(L,M+2,B).times(a+""),R=ge(new L(o+"."+r.slice(1)),M-D).plus(m),L.precision=B,i==null?z(R,B,O,Y=!0):R;for(S=R,g=d=R=ot(R.minus(1),R.plus(1),M,1),A=z(R.times(R),M,1),t=3;;){if(d=z(d.times(A),M,1),m=g.plus(ot(d,new L(t),M,1)),Zt(m.d).slice(0,M)===Zt(g.d).slice(0,M))if(g=g.times(2),a!==0&&(g=g.plus(Ze(L,M+2,B).times(a+""))),g=ot(g,new L(T),M,1),i==null)if(De(g.d,M-D,O,c))L.precision=M+=D,m=d=R=ot(S.minus(1),S.plus(1),M,1),A=z(R.times(R),M,1),t=c=1;else return z(g,L.precision=B,O,Y=!0);else return L.precision=B,g;g=m,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,g,m,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?(g=+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)),m=Ue(i,r,re),M=m.length-1,a=M;m[a]===0;--a)m.pop();return a<0?new o(n.s*0):(n.e=ze(m,M),n.d=m,Y=!1,d&&(n=ot(n,t,c*4)),g&&(n=n.times(Math.abs(g)<54?$t(2,g):Oe.pow(2,g))),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,g,m=1,M=n.precision,S=Math.ceil(M/H);for(Y=!1,g=r.times(r),c=new n(o);;){if(d=ot(c.times(g),new n(i++*i++),M,1),c=t?o.plus(d):o.minus(d),o=ot(d.times(g),new n(i++*i++),M,1),d=c.plus(o),d.d[S]!==void 0){for(a=S;d.d[a]===c.d[a]&&a--;);if(a==-1)break}a=c,c=o,o=d,d=a,m++}return Y=!0,d.d.length=S+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,g,m,M,S,A,T=n.constructor,D=r!==void 0;if(D?(Xt(r,1,we),o===void 0?o=T.rounding:Xt(o,0,8)):(r=T.precision,o=T.rounding),!n.isFinite())M=kr(n);else{for(M=le(n),d=M.indexOf("."),D?(t=2,i==16?r=r*4-3:i==8&&(r=r*3-2)):t=i,d>=0&&(M=M.replace(".",""),A=new T(1),A.e=M.length-d,A.d=Ue(le(A),10,t),A.e=A.d.length),S=Ue(M,10,t),a=g=S.length;S[--g]==0;)S.pop();if(!S[0])M=D?"0p+0":"0";else{if(d<0?a--:(n=new T(n),n.d=S,n.e=a,n=ot(n,A,r,o,0,t),S=n.d,a=n.e,m=mr),d=S[r],c=t/2,m=m||S[r+1]!==void 0,m=o<4?(d!==void 0||m)&&(o===0||o===(n.s<0?3:2)):d>c||d===c&&(o===4||m||o===6&&S[r-1]&1||o===(n.s<0?8:7)),S.length=r,m)for(;++S[--r]>t-1;)S[r]=0,r||(++a,S.unshift(1));for(g=S.length;!S[g-1];--g);for(d=0,M="";d<g;d++)M+=Ti.charAt(S[d]);if(D){if(g>1)if(i==16||i==8){for(d=i==16?4:3,--g;g%d;g++)M+="0";for(S=Ue(M,t,i),g=S.length;!S[g-1];--g);for(d=1,M="1.";d<g;d++)M+=Ti.charAt(S[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>g)for(a-=g;a--;)M+="0";else a<g&&(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]=Di[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]=Di[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,g,m=this;if(!(m instanceof t))return new t(a);if(m.constructor=t,pr(a)){m.s=a.s,Y?!a.d||a.e>t.maxE?(m.e=NaN,m.d=null):a.e<t.minE?(m.e=0,m.d=[0]):(m.e=a.e,m.d=a.d.slice()):(m.e=a.e,m.d=a.d?a.d.slice():a.d);return}if(g=typeof a,g==="number"){if(a===0){m.s=1/a<0?-1:1,m.e=0,m.d=[0];return}if(a<0?(a=-a,m.s=-1):m.s=1,a===~~a&&a<1e7){for(d=0,c=a;c>=10;c/=10)d++;Y?d>t.maxE?(m.e=NaN,m.d=null):d<t.minE?(m.e=0,m.d=[0]):(m.e=d,m.d=[a]):(m.e=d,m.d=[a]);return}if(a*0!==0){a||(m.s=NaN),m.e=NaN,m.d=null;return}return je(m,a.toString())}if(g==="string")return(c=a.charCodeAt(0))===45?(a=a.slice(1),m.s=-1):(c===43&&(a=a.slice(1)),m.s=1),vr.test(a)?je(m,a):ln(m,a);if(g==="bigint")return a<0?(a=-a,m.s=-1):m.s=1,je(m,a.toString());throw Error(_e+a)}if(t.prototype=I,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=Tn,t.log=Dn,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 Tn(n){return new this(n).ln()}function Dn(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)}I[Symbol.for("nodejs.util.inspect.custom")]=I.toString;I[Symbol.toStringTag]="Decimal";var Oe=I.constructor=Pr(Di);$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 g=await this._sdk.SuiLendModule.getSuilendClient(o,t);console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:48 ~ PositionModules ~ suiLendClient:",g);let{allLendingMarketData:m,lstAprPercentMap:M}=await this._sdk.SuiLendModule.getLendingMarketData();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:50 ~ PositionModules ~ allLendingMarketData:",m);let S=m[o].reserveMap;d||(d=new Map);let A=[];for(let N=0;N<c.data.length;N++){let L=Ar(c.data[N]);L.position_id&&A.push(L.position_id),L.id.id&&d.set(L.id.id,L.position_id)}await this._sdk.updateCache(a,d,Vn);let T=await this._sdk.FullClient.batchGetObjects(A,{showContent:!0});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:73 ~ PositionModules ~ positionRes:",T);let D=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:m,lstAprPercentMap:M},!0);console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:75 ~ PositionModules ~ obligations:",D);let R=[];for(let N=0;N<T.length;N++){let L=A[N],O="";for(let[Z,w]of d.entries())if(w===L){O=Z;break}let B=yi(T[N],O),F=await g.getObligation(B.obligation_owner_cap),W=ki(B,F,S||{},M||{},D[o].rewardMap),j=this.getObligationRewardsInfo(F,Object.values(S));R.push({...W,claimable_rewards:j})}return R}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 F=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<F.data.length;W++){let j=Ar(F.data[W]);j.id.id&&a.set(j.id.id,j.position_id),j.position_id===i&&(d=j.id.id)}}let c=await this._sdk.FullClient.batchGetObjects([i],{showContent:!0}),g=yi(c[0],d||""),{lending_market_id:m,lending_market_type:M}=jt(this._sdk.sdkOptions.suilend),S=await this._sdk.SuiLendModule.getSuilendClient(m,M),{allLendingMarketData:A,lstAprPercentMap:T}=await this._sdk.SuiLendModule.getLendingMarketData(),D=A[m].reserveMap,R=await this._sdk.SuiLendModule.getInitializeObligations({allLendingMarketData:A,lstAprPercentMap:T},!0),N=await S.getObligation(g.obligation_owner_cap),L=this.getObligationRewardsInfo(N,Object.values(D));return{...ki(g,N,D||{},T||{},R[m].rewardMap),claimable_rewards:L}};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:g,repay_coin_type:m,repay_coin:M,repay_reserve_array_index:S,market_id:A,position_cap_id:T,margin_trading_context:D}=i,R=c||new ne,N=M||Q.buildCoinWithBalance(BigInt(g.toString()),m,R);R.moveCall({target:`${r.published_at}::router::repay`,typeArguments:[t,m],arguments:[D,R.object(a),R.object(o),R.object(A),R.object(T),N,R.pure.u64(S.toString()),R.object(be),R.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:g}=this._sdk.sdkOptions.suilend,{market_id:m,withdraw_amount:M,withdraw_reserve_array_index:S,withdraw_coin_type:A,position_cap_id:T,margin_trading_context:D}=i,[R]=r.moveCall({target:"0x1::option::none",typeArguments:[`${g}::lending_market::RateLimiterExemption<${a}, ${A}>`],arguments:[]});return r.moveCall({target:`${o.published_at}::router::withdraw`,typeArguments:[a,A],arguments:[D,r.object(d),r.object(t),r.object(m),r.object(T),r.object(R),r.pure.u64(M),r.pure.u64(S),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:g,market_id:m,position_cap_id:M,position_cap:S,margin_trading_context:A}=i,{margin_trading:T}=this._sdk.sdkOptions,{lending_market_type:D}=jt(this._sdk.sdkOptions.suilend),{global_config_id:R,versioned_id:N}=jt(this._sdk.sdkOptions.margin_trading);return r.moveCall({target:`${T.published_at}::router::borrow`,typeArguments:[D,g?d:a],arguments:[A,r.object(R),r.object(c),r.object(m),M?r.object(M):S,r.pure.u64(o),r.pure.u64(t.toString()),r.object(Cr),r.object(be),r.object(N)]})};this.createMarginTradingContext=(i,r)=>{let{published_at:o}=this._sdk.sdkOptions.margin_trading,{market_id:t,position_cap_id:a,action:d,coin_type:c,amount:g}=i;return r.moveCall({target:`${o}::router::create_margin_trading_context`,arguments:[r.object(t),r.object(a),r.pure.string(d),r.pure.u64(g)],typeArguments:[c]})};this.marginTradingContextConfirm=(i,r)=>{let{published_at:o}=this._sdk.sdkOptions.margin_trading;return r.moveCall({target:`${o}::router::confirm`,arguments:[i],typeArguments:[]}),r};this.openPosition=async i=>{let{is_quote:r,is_long:o,amount:t,swap_clmm_pool:a="",slippage:d,leverage:c,market_id:g}=i,{lending_market_id:m}=jt(this._sdk.sdkOptions.suilend),M=new ne,{base_token:S,quote_token:A}=await this._sdk.MarketModules.getMarketInfo(g),{flash_amount:T,flash_loan_coin:D,is_flash_a:R,borrow_amount:N,clmm_pool_coin_type_a:L,clmm_pool_coin_type_b:O,clmm_pool:B,base_reserve_array_index:F,quote_reserve_array_index:W,reserve:j,has_swap:Z,routers:w}=await this.calculatePositionDeposit({is_long:o,is_quote:r,amount:t,swap_clmm_pool:a,leverage:c,slippage:d,market_id:g,base_token:S,quote_token:A,is_submit:!0});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:492 ~ PositionModules ~ routers:",w),await this._sdk.SuiLendModule.refreshReservePrices(M,j);let{balance_a:b,balance_b:k,receipt:x}=this._sdk.SwapModules.flashLoan({amount:T,clmm_pool:B,clmm_pool_coin_type_a:L,clmm_pool_coin_type_b:O,flash_loan_coin:D,tx:M}),C=o?A:S,p=o?S:A,e=Q.buildCoinWithBalance(BigInt(t),r?A:S,M),s=Q.fromBalance(b,L,M),u=Q.fromBalance(k,O,M);Z&&(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:515 ~ PositionModules ~ is_flash_a:",R),M.mergeCoins(e,[R?s:u])),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:521 ~ PositionModules ~ d(flash_amount).add(amount).toString():",E(T).add(t).toString(),C,p);let f=await this._sdk.SwapModules.handleSwap({from:C,to:p,amount:Z?E(T).add(t).toString():T,input_coin:Z?e:R?s:u,swap_clmm_pool:a,slippage:d,tx:M}),{position_cap:h,margin_trading_context:v}=this.createLeveragePosition({leverage:c,market_id:g,base_token:S,quote_token:A,is_long:o,init_deposit_amount:E(t).toString(),init_coin_type:r?A:S,tx:M}),P=o?F:W;f.swap_out_coin&&!Z&&M.mergeCoins(f.swap_out_coin,[e]),await this.depositToLeveragePosition({is_long:o,market_id:g,position_cap:h,deposit_reserve_array_index:P,input_coin:f.swap_out_coin,margin_trading_context:v,base_token:S,quote_token:A},M),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:580 ~ PositionModules ~ borrow_amount:",N);let _=this.borrowAsset({position_cap:h,reserve_array_index:o?W:F,borrow_amount:N,base_token:S,quote_token:A,is_long:o,lending_market_id:m,market_id:g,margin_trading_context:v},M),l=Q.mintBalanceZero(R?O:L,M);return this._sdk.SwapModules.repayFlashLoan({tx:M,clmm_pool:B,repay_base:R?Q.intoBalance(_,L,M):l,repay_quote:R?l:Q.intoBalance(_,O,M),receipt:x,clmm_pool_coin_type_a:L,clmm_pool_coin_type_b:O}),M.transferObjects([h],M.pure.address(this._sdk.getSenderAddress())),Q.destroyBalanceZero(R?Q.intoBalance(u,O,M):Q.intoBalance(s,L,M),R?O:L,M),this.marginTradingContextConfirm(v,M),M};this.positionDeposit=async i=>{let{position_id:r,swap_clmm_pool:o="",is_quote:t,amount:a,slippage:d,leverage:c,txb:g}=i,{lending_market_id:m}=jt(this._sdk.sdkOptions.suilend),{is_long:M,deposits:S,borrows:A,position_cap_id:T,market_id:D}=await this.getPositionInfo(r),{base_token:R,quote_token:N}=await this._sdk.MarketModules.getMarketInfo(D),L=g||new ne,O=this.createMarginTradingContext({market_id:D,position_cap_id:T,action:"increase_size",coin_type:t?N:R,amount:a.toString()},L),B=S[0].reserveArrayIndex.toString(),F=A[0].reserveArrayIndex.toString(),{flash_amount:W,flash_loan_coin:j,is_flash_a:Z,borrow_amount:w,clmm_pool_coin_type_a:b,clmm_pool_coin_type_b:k,clmm_pool:x,reserve:C,has_swap:p}=await this.calculatePositionDeposit({market_id:D,is_long:M,is_quote:t,amount:a,swap_clmm_pool:o,leverage:c,slippage:d,base_token:R,quote_token:N,position_id:r,is_open:!1});console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:603 ~ PositionModules ~ flash_amount:",W),await this._sdk.SuiLendModule.refreshReservePrices(L,C);let{balance_a:e,balance_b:s,receipt:u}=this._sdk.SwapModules.flashLoan({amount:W,clmm_pool:x,clmm_pool_coin_type_a:b,clmm_pool_coin_type_b:k,flash_loan_coin:j,tx:L}),f=M?N:R,h=M?R:N,v=Q.buildCoinWithBalance(BigInt(a),t?N:R,L),P=Q.fromBalance(e,b,L),_=Q.fromBalance(s,k,L);p&&L.mergeCoins(v,[Z?P:_]);let l=await this._sdk.SwapModules.handleSwap({from:f,to:h,amount:p?E(W).add(a).toString():W,input_coin:p?v:Z?P:_,swap_clmm_pool:o,slippage:d,tx:L});l.swap_out_coin&&!p&&L.mergeCoins(l.swap_out_coin,[v]),await this.depositToLeveragePosition({is_long:M,market_id:D,position_cap_id:T,deposit_reserve_array_index:B,input_coin:l.swap_out_coin,margin_trading_context:O,base_token:R,quote_token:N},L);let y=await this.borrowAsset({position_cap_id:T,reserve_array_index:F,borrow_amount:w,base_token:R,quote_token:N,is_long:M,lending_market_id:m,market_id:D,margin_trading_context:O},L),U=Q.mintBalanceZero(Z?k:b,L);return this._sdk.SwapModules.repayFlashLoan({tx:L,clmm_pool:x,repay_base:Z?Q.intoBalance(y,b,L):U,repay_quote:Z?U:Q.intoBalance(y,k,L),receipt:u,clmm_pool_coin_type_a:b,clmm_pool_coin_type_b:k}),Q.destroyBalanceZero(Z?Q.intoBalance(_,k,L):Q.intoBalance(P,b,L),Z?k:b,L),await this.marginTradingContextConfirm(O,L),L};this.positionWithdraw=async i=>{let{amount:r,is_quote:o,txb:t,swap_clmm_pool:a="",slippage:d,position_id:c,leverage:g}=i,m=t||new ne,{withdraw_ctoken_amount:M,repay_amount:S,is_close:A,deposits:T,borrows:D,reserve:R,base_token:N,quote_token:L,clmm_pool:O,clmm_pool_coin_type_a:B,clmm_pool_coin_type_b:F,position_cap_id:W,market_id:j,is_long:Z,swap_convert_all:w,flash_loan_amount:b,routers:k,repay_flash_loan_amount:x="0",partial_amount_in:C,withdraw_amount:p,has_flash_loan:e}=await this.calculatePositionWithdraw({position_id:c,is_quote:o,swap_clmm_pool:a,amount:r,leverage:g,slippage:d});if(A)return this.positionClose({position_id:c,is_quote:o,leverage:g,slippage:d,swap_clmm_pool:a});let s=this.createMarginTradingContext({market_id:j,position_cap_id:W,action:"decrease_size",coin_type:o?L:N,amount:r.toString()},m);await this._sdk.SuiLendModule.refreshReservePrices(m,R);let u,f;if(e){let{balance_a:_,balance_b:l,receipt:y,is_loan_a:U}=this._sdk.SwapModules.flashLoan({tx:m,amount:b,flash_loan_coin:D[0].reserve.coinType,clmm_pool:O,clmm_pool_coin_type_a:B,clmm_pool_coin_type_b:F});u=y,f=U,Q.destroyBalanceZero(f?l:_,f?F:B,m);let q=U?Q.fromBalance(_,B,m):Q.fromBalance(l,F,m);this.repay({txb:m,position_cap_id:W,repay_reserve_array_index:D[0].reserveArrayIndex.toString(),repay_coin:q,repay_coin_type:Z?L:N,repay_amount:"0",market_id:j,margin_trading_context:s}),m.transferObjects([q],this._sdk.getSenderAddress())}let h=this.withdrawAsset({market_id:j,position_cap_id:W,withdraw_amount:M.toString(),withdraw_reserve_array_index:T[0].reserveArrayIndex.toString(),withdraw_coin_type:Z?N:L,margin_trading_context:s},m);for(let _=1;_<T.length;_++){let l=this.withdrawAsset({market_id:j,position_cap_id:W,withdraw_amount:Ni.toString(),withdraw_reserve_array_index:T[_].reserveArrayIndex.toString(),withdraw_coin_type:T[_].coinType,margin_trading_context:s},m);m.transferObjects([l],this._sdk.getSenderAddress())}let v;if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:778 ~ PositionModules ~ swap_convert_all:",{swap_convert_all:w,has_flash_loan:e}),w)v=await this._sdk.SwapModules.routerSwap({router:k?.route_obj,input_coin:h,slippage:d,txb:m});else{let _=m.splitCoins(h,[m.pure.u64(C?.toString()||"0")]);v=await this._sdk.SwapModules.routerSwap({router:k?.route_obj,input_coin:_,slippage:d,txb:m})}let P;if(v&&e&&(P=m.splitCoins(v,[m.pure.u64(x.toString())])),P&&e){let _=Q.mintBalanceZero(f?F:B,m);this._sdk.SwapModules.repayFlashLoan({tx:m,clmm_pool:O,repay_base:f?Q.intoBalance(P,B,m):_,repay_quote:f?_:Q.intoBalance(P,F,m),clmm_pool_coin_type_a:B,clmm_pool_coin_type_b:F,receipt:u})}else if(v){let _=m.splitCoins(v,[m.pure.u64(x.toString())]);this.repay({txb:m,position_cap_id:W,repay_reserve_array_index:D[0].reserveArrayIndex.toString(),repay_coin:_,repay_coin_type:Z?L:N,repay_amount:"0",market_id:j,margin_trading_context:s}),m.transferObjects([_],this._sdk.getSenderAddress())}return v&&m.transferObjects([v],this._sdk.getSenderAddress()),w||m.transferObjects([h],this._sdk.getSenderAddress()),await this.marginTradingContextConfirm(s,m),m};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:g,versioned_id:m}=jt(this._sdk.sdkOptions.margin_trading),{lending_market_type:M,lending_market_id:S}=jt(this._sdk.sdkOptions.suilend),A=new ne,{deposits:T,borrows:D,base_token:R,quote_token:N,clmm_pool:L,clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:B,position_cap_id:F,market_id:W,swap_convert_all:j,routers:Z,partial_amount_in:w,is_long:b,flash_loan_amount:k,reserve:x,repay_flash_loan_amount:C="0",claimable_rewards:p}=await this.calculatePositionWithdraw({position_id:r,is_quote:o,swap_clmm_pool:d,amount:Ni.toString(),leverage:a,slippage:t}),e=this.createMarginTradingContext({market_id:W,position_cap_id:F,action:"close_position",coin_type:o?N:R,amount:"0"},A);await this._sdk.SuiLendModule.refreshReservePrices(A,x);let s,u;if(E(k).gt(0)){let{balance_a:v,balance_b:P,receipt:_,is_loan_a:l}=this._sdk.SwapModules.flashLoan({tx:A,amount:k,flash_loan_coin:b?N:R,clmm_pool:L,clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:B});s=_,u=l,Q.destroyBalanceZero(u?P:v,u?B:O,A);let y=u?Q.fromBalance(v,O,A):Q.fromBalance(P,B,A);this.repay({txb:A,position_cap_id:F,repay_reserve_array_index:D[0].reserveArrayIndex.toString(),repay_coin:y,repay_coin_type:D[0].reserve.coinType,repay_amount:"0",market_id:W,margin_trading_context:e}),A.transferObjects([y],this._sdk.getSenderAddress())}let f=this.withdrawAsset({market_id:W,position_cap_id:F,withdraw_amount:Ni.toString(),withdraw_reserve_array_index:T[0].reserveArrayIndex.toString(),withdraw_coin_type:b?R:N,margin_trading_context:e},A);await this.buildClaimRewardsMoveCall(p,W,F,A);let h;if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:895 ~ PositionModules ~ swap_convert_all:",j),j)h=await this._sdk.SwapModules.routerSwap({router:Z?.route_obj,input_coin:f,slippage:t,txb:A});else if(w&&E(w).gt(0)){let v=A.splitCoins(f,[A.pure.u64(w?.toString()||"0")]);h=await this._sdk.SwapModules.routerSwap({router:Z?.route_obj,input_coin:v,slippage:t,txb:A})}if(h&&s){let v=Q.mintBalanceZero(u?B:O,A),P=A.splitCoins(h,[A.pure.u64(C?.toString()||"0")]);this._sdk.SwapModules.repayFlashLoan({tx:A,clmm_pool:L,repay_base:u?Q.intoBalance(P,O,A):v,repay_quote:u?v:Q.intoBalance(P,B,A),clmm_pool_coin_type_a:O,clmm_pool_coin_type_b:B,receipt:s})}return A.moveCall({target:`${c.published_at}::router::close_position`,typeArguments:[M],arguments:[e,A.object(g),A.object(S),A.object(W),A.object(F),A.object(be),A.object(m)]}),h&&A.transferObjects([h],this._sdk.getSenderAddress()),j||A.transferObjects([f],this._sdk.getSenderAddress()),this.marginTradingContextConfirm(e,A),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),g=new ne,{flash_loan_amount:m,quote_token:M,base_token:S,reserve:A,deposits:T,borrow_amount:D,routers:R,position_cap_id:N,is_long:L,market_id:O,is_flash_loan:B}=await this.calculatePositionLeverage({position_id:d,current_leverage:r,target_leverage:o,swap_clmm_pool:t,slippage:a}),F=L?M:S,W=this.createMarginTradingContext({market_id:O,position_cap_id:N,action:"increase_leverage",coin_type:L?S:M,amount:"0"},g);if(await this._sdk.SuiLendModule.refreshReservePrices(g,A),B){let{clmm_pool_coin_type_a:j,clmm_pool_coin_type_b:Z,clmm_pool:w}=await this._sdk.SwapModules.getFlashLoanPool(F,m?.toString()||""),{balance_a:b,balance_b:k,receipt:x,is_loan_a:C}=this._sdk.SwapModules.flashLoan({tx:g,amount:m?.toString()||"0",clmm_pool:w,clmm_pool_coin_type_a:j,clmm_pool_coin_type_b:Z,flash_loan_coin:F}),p=await this._sdk.SwapModules.routerSwap({router:R?.route_obj,input_coin:C?Q.fromBalance(b,j,g):Q.fromBalance(k,Z,g),slippage:a,txb:g});this.depositToLeveragePosition({is_long:L,market_id:O,position_cap_id:N,deposit_reserve_array_index:T[0].reserveArrayIndex.toString(),input_coin:p,margin_trading_context:W,base_token:S,quote_token:M},g);let e=this.borrowAsset({position_cap_id:N,reserve_array_index:L?A[1].arrayIndex.toString():A[0].arrayIndex.toString(),borrow_amount:D,base_token:S,quote_token:M,is_long:L,lending_market_id:c,market_id:O,margin_trading_context:W},g),s=Q.mintBalanceZero(C?Z:j,g);this._sdk.SwapModules.repayFlashLoan({tx:g,clmm_pool:w,repay_base:C?Q.intoBalance(e,j,g):s,repay_quote:C?s:Q.intoBalance(e,Z,g),receipt:x,clmm_pool_coin_type_a:j,clmm_pool_coin_type_b:Z}),Q.destroyBalanceZero(C?k:b,C?Z:j,g)}else{let j=this.borrowAsset({position_cap_id:N,reserve_array_index:L?A[1].arrayIndex.toString():A[0].arrayIndex.toString(),borrow_amount:D,base_token:S,quote_token:M,is_long:L,lending_market_id:c,market_id:O,margin_trading_context:W},g),Z=await this._sdk.SwapModules.routerSwap({router:R?.route_obj,input_coin:j,slippage:a,txb:g});this.depositToLeveragePosition({is_long:L,market_id:O,position_cap_id:N,deposit_reserve_array_index:T[0].reserveArrayIndex.toString(),input_coin:Z,margin_trading_context:W,base_token:S,quote_token:M},g)}return await this.marginTradingContextConfirm(W,g),g};this.positionLeverageDecrease=async i=>{let{current_leverage:r,target_leverage:o,swap_clmm_pool:t="",slippage:a,position_id:d}=i,{deposits:c,borrows:g,position_cap_id:m,market_id:M,is_long:S}=await this.getPositionInfo(d),{base_token:A,quote_token:T}=await this._sdk.MarketModules.getMarketInfo(M),D=new ne,{withdraw_ctoken_amount:R,routers:N,reserve:L,is_flash_loan:O}=await this.calculatePositionLeverage({position_id:d,current_leverage:r,target_leverage:o,swap_clmm_pool:t,slippage:a}),B=this.createMarginTradingContext({market_id:M,position_cap_id:m,action:"decrease_leverage",coin_type:S?A:T,amount:"0"},D);if(await this._sdk.SuiLendModule.refreshReservePrices(D,L),O){let{clmm_pool_coin_type_a:F,clmm_pool_coin_type_b:W,clmm_pool:j,clmm_fee_tier:Z}=await this._sdk.SwapModules.getFlashLoanPool(c[0].reserve.coinType,R.toString()),{balance_a:w,balance_b:b,receipt:k,is_loan_a:x}=this._sdk.SwapModules.flashLoan({tx:D,amount:R,clmm_pool:j,clmm_pool_coin_type_a:F,clmm_pool_coin_type_b:W,flash_loan_coin:c[0].reserve.coinType}),C=await this._sdk.SwapModules.routerSwap({router:N?.route_obj,input_coin:x?Q.fromBalance(w,F,D):Q.fromBalance(b,W,D),slippage:a,txb:D});this.repay({txb:D,market_id:M,position_cap_id:m,repay_reserve_array_index:g[0].reserveArrayIndex.toString(),repay_coin:C,repay_coin_type:S?T:A,repay_amount:"0",margin_trading_context:B}),C&&D.transferObjects([C],this._sdk.getSenderAddress());let p=E(R).mul(Z).toString(),e=E(R).add(p).toDP(0,ht.ROUND_UP),s=this.withdrawAsset({market_id:M,position_cap_id:m,withdraw_amount:e.toString(),withdraw_reserve_array_index:c[0].reserveArrayIndex.toString(),withdraw_coin_type:S?A:T,margin_trading_context:B},D),u=D.splitCoins(s,[e.toString()]);this._sdk.SwapModules.repayFlashLoan({tx:D,clmm_pool:j,repay_base:x?Q.intoBalance(u,F,D):w,repay_quote:x?b:Q.intoBalance(u,W,D),receipt:k,clmm_pool_coin_type_a:F,clmm_pool_coin_type_b:W}),D.transferObjects([s],this._sdk.getSenderAddress())}else{let F=this.withdrawAsset({market_id:M,position_cap_id:m,withdraw_amount:R.toString(),withdraw_reserve_array_index:c[0].reserveArrayIndex.toString(),withdraw_coin_type:S?A:T,margin_trading_context:B},D);D.transferObjects([F],this._sdk.getSenderAddress())}return await this.marginTradingContextConfirm(B,D),D};this.positionRepay=async i=>{let{position_id:r,amount:o,is_quote:t,slippage:a}=i,{routers:d,repay_coin_type:c,base_token:g,quote_token:m,borrows:M,deposits:S,market_id:A,position_cap_id:T}=await this.calculatePositionRepay({position_id:r,amount:o,is_quote:t}),D=this.extractOtherTokenTypes(S,M,g,m),{reserve:R}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(g,m,void 0,D),N=new ne;await this._sdk.SuiLendModule.refreshReservePrices(N,R);let L=t?m!==c:g!==c,O,B=this.createMarginTradingContext({market_id:A,position_cap_id:T,action:"repay_debt",coin_type:t?m:g,amount:o.toString()},N);if(L){let F=Q.buildCoinWithBalance(BigInt(o.toString()),t?m:g,N);O=await this._sdk.SwapModules.routerSwap({router:d?.route_obj,input_coin:F,slippage:a,txb:N})}else O=Q.buildCoinWithBalance(BigInt(o.toString()),t?m:g,N);return this.repay({txb:N,position_cap_id:T,repay_reserve_array_index:M[0].reserveArrayIndex.toString(),repay_coin:O,repay_coin_type:c,repay_amount:"0",market_id:A,margin_trading_context:B}),N.transferObjects([O],this._sdk.getSenderAddress()),await this.marginTradingContextConfirm(B,N),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:g,market_id:m,position_cap_id:M,deposits:S,borrows:A}=await this.getPositionInfo(r),{base_token:T,quote_token:D}=await this._sdk.MarketModules.getMarketInfo(m),R=g&&t||!g&&!t,N=await this.createMarginTradingContext({market_id:m,position_cap_id:M,action:"top_up_collateral",coin_type:t?D:T,amount:o.toString()},c),L=this.extractOtherTokenTypes(S,A,T,D),{base_reserve_array_index:O,quote_reserve_array_index:B,reserve:F}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(T,D,void 0,L);await this._sdk.SuiLendModule.refreshReservePrices(c,F);let W;if(R){let j=await this._sdk.SwapModules.findRouters(t?D:T,t?T:D,o,!0,[a]),Z=Q.buildCoinWithBalance(BigInt(o.toString()),t?D:T,c);W=await this._sdk.SwapModules.routerSwap({router:j?.route_obj,input_coin:Z,slippage:d,txb:c})}else W=Q.buildCoinWithBalance(BigInt(o.toString()),t?D:T,c);return await this.depositToLeveragePosition({is_long:g,market_id:m,position_cap_id:M,deposit_reserve_array_index:g?O:B,input_coin:W,margin_trading_context:N,base_token:T,quote_token:D},c),await this.marginTradingContextConfirm(N,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:g,market_id:m,position_cap_id:M,deposits:S,borrows:A}=await this.getPositionInfo(r),{base_token:T,quote_token:D}=await this._sdk.MarketModules.getMarketInfo(m),R=g&&t||!g&&!t,N=await this.createMarginTradingContext({market_id:m,position_cap_id:M,action:"withdraw_collateral",coin_type:t?D:T,amount:o.toString()},c),L=this.extractOtherTokenTypes(S,A,T,D),{base_reserve_array_index:O,quote_reserve_array_index:B,reserve:F}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(T,D,void 0,L);await this._sdk.SuiLendModule.refreshReservePrices(c,F);let W=await this._sdk.SuiLendModule.getLatestPriceFeeds(F,!0),j=W[xe(D)]?.price,Z=W[xe(T)]?.price,w=g?E(j).div(E(Z)).toString():E(Z).div(E(j)).toString(),b=F[0].mintDecimals,k=F[1].mintDecimals,x=R?E(o).mul(w).div(10**(t?k:b)).mul(10**(g?b:k)).toDP(0,ht.ROUND_DOWN).toString():o.toString(),C=this.withdrawAsset({market_id:m,position_cap_id:M,withdraw_amount:x,withdraw_reserve_array_index:g?O:B,withdraw_coin_type:g?T:D,margin_trading_context:N},c);if(R){let p=await this._sdk.SwapModules.findRouters(g?T:D,t?D:T,x,!0,[a]),e=await this._sdk.SwapModules.routerSwap({router:p?.route_obj,input_coin:C,slippage:d,txb:c});e&&c.transferObjects([e],this._sdk.getSenderAddress())}else c.transferObjects([C],this._sdk.getSenderAddress());return await this.marginTradingContextConfirm(N,c),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:g,quote_token:m,is_submit:M=!1,is_open:S=!0,position_id:A}=i,T=[],D=[],R=[];if(!S&&A){let{deposits:rt,borrows:V}=await this.getPositionInfo(A);D=rt,R=V,T=this.extractOtherTokenTypes(D,R,g,m)}let{reserve:N,base_reserve_array_index:L,quote_reserve_array_index:O}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(g,m,void 0,T),B=N[0].mintDecimals,F=N[1].mintDecimals,W=t.toString(),j=o&&r||!o&&!r,Z=await this._sdk.SuiLendModule.getLatestPriceFeedsByCoinTypes([g,m]),w=Z&&Z[m]?.price,b=Z&&Z[g]?.price;if(!w||!b)throw Gt("PriceNotFound","Price not found");if(j&&M){let rt=o?E(w).div(E(b)).toString():E(b).div(E(w)).toString();W=E(t).mul(rt).div(10**(r?F:B)).mul(10**(o?B:F)).toString(),console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:492 ~ PositionModules ~ initDepositAmount:",{initDepositAmount:W,rate:rt})}else if(j&&!M){let rt=o?m:g,V=o?g:m;W=(await this._sdk.SwapModules.findRouters(rt,V,W,!0,[a]))?.amount_out.toString()}else W=t;let{base_price:k,quote_price:x,flash_amount:C,flash_loan_fee:p,flash_loan_coin:e,is_flash_a:s,clmm_pool:u,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:g,quote_token:m,deposit_amount:W,reserve:N,base_token_decimal:B,quote_token_decimal:F}),P=await this._sdk.SwapModules.findRouters(o?m:g,o?g:m,C.toString(),!0,[a]),_=E(W).add(E(P?.amount_out.toString())).toDP(0,ht.ROUND_DOWN).toString(),l=E(_).mul(o?k:x).toString(),y=E(C).add(p).toDP(0,ht.ROUND_UP).toString(),U=E(y).mul(o?x:k).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ positionModules.ts:1575 ~ PositionModules ~ depositAmount:",{depositAmount:_,borrowAmount:y});let q=r?E(t).div(10**(r?F:B)).mul(10**B).mul(d).div(k).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:",q);let $="0",K="0",G="0",J="0";return!S&&A&&(R&&R.length>0&&($=E(R[0].borrowedAmount.toString()).mul(o?10**F:10**B).add(E(y)).toString(),K=E($).mul(o?w:b).toString()),G=E(D[0].depositedAmount.toString()).mul(o?10**B:10**F).add(E(_)).toString(),J=E(G).mul(o?b:w).toString()),{routers:P,leverage_deposit_amount:q,quote_price:x,base_price:k,clmm_fee_tier:f,flash_loan_fee:p,flash_loan_coin:e,deposit_amount:_,borrow_amount:y,deposit_amount_usd:l,borrow_amount_usd:U,after_borrow_amount:$,after_borrow_amount_usd:K,after_deposit_amount:G,after_deposit_amount_usd:J,flash_amount:C,is_flash_a:s,init_deposit_amount:W,clmm_pool_coin_type_a:h,clmm_pool_coin_type_b:v,clmm_pool:u,base_reserve_array_index:L,quote_reserve_array_index:O,reserve:N,has_swap:j}};this.calculatePositionWithdraw=async i=>{let{position_id:r,is_quote:o,swap_clmm_pool:t="",amount:a,leverage:d,slippage:c,withdraw_max:g}=i,{deposits:m,borrows:M,origin_obligation:S,position_cap_id:A,market_id:T,is_long:D,claimable_rewards:R}=await this.getPositionInfo(r),{base_token:N,quote_token:L}=await this._sdk.MarketModules.getMarketInfo(T),O=r?this.extractOtherTokenTypes(m,M,N,L):[],{reserve:B,base_reserve_map_info:F,quote_reserve_map_info:W}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(N,L,void 0,O),j=B[0].mintDecimals,Z=B[1].mintDecimals,w=D?F.cTokenExchangeRate:W.cTokenExchangeRate,b=await this._sdk.SuiLendModule.getLatestPriceFeeds(B,!0),k=b[xe(L)]?.price,x=b[xe(N)]?.price,C=E(0),p;D?(C=E(o?E(a).mul(k).toString():E(a).mul(x).toString()).div(o?10**Z:10**j),p=o?E(a).div(x).div(10**Z).mul(10**j).toString():E(a)):(C=E(o?E(a).mul(k).toString():E(a).mul(x).toString()).div(o?10**Z:10**j),p=o?E(a):E(a).mul(x).div(10**j).mul(10**Z).toString());let e=E(m[0].depositedAmountUsd.toString()).sub(E(M&&M.length>0?M[0].borrowedAmountUsd.toString():"0")).toString(),s=C.div(E(e)),u=g||E(s).gte(1),f,h=new ht(0);S&&S.borrows&&S.borrows.length>0&&(f=Xn(S.borrows[0],D?B[1]:B[0]),h=E(f.borrowedAmount.value.toString()).div(10**18).toDP(0,ht.ROUND_UP));let v=h.mul(u?1:s).toDP(0,ht.ROUND_UP).toString(),P=v.toString(),_,l,y,U,q,$;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(D?L:N,P);q=nt||"",$=at||"",y=ue||0,U=dt||"",_=E(P).mul(ue).toString(),l=E(P).mul(E(1).add(ue)).toDP(0,ht.ROUND_UP).toString()}let K=D&&o||!D&&!o,G,J;if(K){let nt=E(m[0].depositedAmount.toString()).mul(10**(D?j:Z)).mul(u?1:s).toDP(0,ht.ROUND_DOWN).toString();G=await this._sdk.SwapModules.findRouters(m[0].reserve.coinType,D?L:N,nt,!0,[t])}else{let nt=m[0].reserve.coinType==="0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC"?.01:.0025;J=E(v).mul(D?k:x).div(10**(D?Z:j)).mul(10**(D?j:Z)).div(D?x:k).mul(E(1).add(nt)).toDP(0,ht.ROUND_DOWN).toString(),G=await this._sdk.SwapModules.findRouters(m[0].reserve.coinType,D?L:N,J.toString(),!0,[t]),u||(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(),C=E(C).mul(d);let rt=h.mul(E(1).sub(s)).toString(),V=E(rt).mul(D?k:x).toString(),it=E(m[0].depositedAmount.toString()).mul(D?10**j:10**Z).sub(E(p)).toString(),ut=E(it).mul(D?x:k).toString(),et=E(G?.amount_in.toString()).toString(),X=E(G?.amount_out.toString()).toString(),de=E(p).div(w.toString()).toDP(0,ht.ROUND_DOWN).toString(),ct=E(V).div(E(10**(D?Z:j))),st=E(ut).div(E(10**(D?j:Z))),ke=!0;if(M.length>0){let nt=E(M[0].borrowedAmountUsd.toString()),at=nt.div(st).toString(),ue=E(m[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:m[0].reserve.coinType,to:D?N:L,after_borrow_amount:rt,after_borrow_amount_usd:V,after_deposit_amount:it,after_deposit_amount_usd:ut,flash_loan_fee:_,clmm_fee_tier:y,withdraw_amount:p,withdraw_ctoken_amount:de,repay_amount:v,ratio:s,is_close:u,is_long:D,deposits:m,borrows:M,reserve:B,base_token:N,quote_token:L,clmm_pool:U,clmm_pool_coin_type_a:q,clmm_pool_coin_type_b:$,position_cap_id:A,market_id:T,swap_convert_all:K,flash_loan_amount:P,routers:G,repay_flash_loan_amount:l,partial_amount_in:J,has_flash_loan:ke,claimable_rewards:R}};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:g,deposits:m,is_long:M,position_cap_id:S,market_id:A}=await this.getPositionInfo(r),{base_token:T,quote_token:D}=await this._sdk.MarketModules.getMarketInfo(A),R=this.extractOtherTokenTypes(m,g,T,D),{reserve:N}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(T,D,void 0,R),L=N[0].mintDecimals,O=N[1].mintDecimals,B=await this._sdk.SuiLendModule.getLatestPriceFeeds(N,!0),F=B[xe(D)]?.price,W=B[xe(T)]?.price,j=g.length>0,Z=m[0].depositedAmountUsd.toString(),w=m[0].depositedAmount.toString(),b=j?E(g[0].borrowedAmount.toString()).mul(10**(M?O:L)):E(0),k=j?g[0].borrowedAmountUsd.toString():E(0),x=j?E(g[0].reserve.config.borrowWeightBps.toString()).div(1e4).toString():"1",C=E(m[0].reserve.config.openLtvPct).mul(E(.95)).div(100).div(x).toString(),p=E(Z).sub(E(k)).mul(C).toString();if(c){let e=E(Z).div(o).mul(d),s=e.add(k).div(Z).toString(),u=e.div(M?F:W).mul(10**(M?O:L)).toDP(0,ht.ROUND_UP),f=E(s).gt(C),h=u,v=M?D:T,P=M?T:D,_=await this._sdk.SwapModules.findRouters(v,P,h.toString(),!0,[a]),l=E(_?.amount_out.toString()).toString(),y=E(l).mul(M?W:F).toString(),U,q,$,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());$=st,K=X,G=de,U=h.mul($).toString(),q=M?K==D:G==T,J=E(h).add(U).toDP(0,ht.ROUND_UP).toString(),rt=E(J).mul(M?F:W).toString()}else J=u.toString(),rt=e.toString();let V=E(w).add(E(l).div(10**(M?L:O))).toString(),it=E(V).mul(M?W:F).toString(),ut=E(b).add(E(J)).div(10**(M?O:L)).toString(),et=E(ut).mul(M?F:W).toString();return{amount_in:_?.amount_in.toString(),amount_out:_?.amount_out.toString(),flash_loan_fee:U,deposit_amount:l,borrow_amount:J,deposit_amount_usd:y,borrow_amount_usd:rt,flash_loan_amount:h,base_token:T,quote_token:D,reserve:N,deposits:m,borrows:g,clmm_fee_tier:$,is_flash_loan:f,is_loan_a:q,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:S,market_id:A,is_long:M,routers:_}}else{let s=E(Z).div(o).mul(d.abs()).div(M?F:W).mul(10**(M?O:L)).toDP(0,ht.ROUND_UP),u=await this._sdk.SwapModules.findRouters(m[0].reserve.coinType,g[0].reserve.coinType,s.toString(),!1,[a]),f=u?.amount_in.toString(),h=E(f).mul(M?W:F).div(10**(M?L:O)).toString(),v=E(Z).mul(C).toString(),P=E(k).div(E(Z).sub(E(h))).toString(),_=E(P).gt(C),l=s.toString(),y=E(l).mul(M?F:W).toString(),U=f,q=E(U).mul(M?W:F).toString(),$,K="",G="";if(_){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(g[0].reserve.coinType,l.toString());$=de,K=ut,G=et}let J=E(w).sub(E(U).div(10**(M?L:O))).toString(),rt=E(J).mul(M?W:F).toString(),V=E(b).sub(E(l)).div(10**(M?O:L)).toString(),it=E(V).mul(M?F:W).toString();return{amount_in:u?.amount_in.toString(),amount_out:u?.amount_out.toString(),deposit_amount:U,borrow_amount:l,deposit_amount_usd:q,borrow_amount_usd:y,base_token:T,quote_token:D,reserve:N,deposits:m,borrows:g,clmm_fee_tier:$,withdraw_ctoken_amount:f,is_flash_loan:_,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:S,market_id:A,is_long:M,routers:u}}};this.calculatePositionRepay=async i=>{let{position_id:r,amount:o,is_quote:t}=i,{borrows:a,deposits:d,is_long:c,market_id:g,position_cap_id:m}=await this._sdk.PositionModules.getPositionInfo(r),M=a[0].reserve.coinType,S=c?d[0].reserve.coinType:a[0].reserve.coinType,A=c?a[0].reserve.coinType:d[0].reserve.coinType,T,D=c?!t:t;return D&&(T=await this._sdk.SwapModules.findRouters(t?A:S,M,o,!0,[])),{routers:T,repay_coin_type:M,base_token:S,quote_token:A,is_long:c,borrows:a,deposits:d,market_id:g,position_cap_id:m,has_swap:D}};this._sdk=i}getObligationRewardsInfo(i,r){let o=[],t=new lt(10).pow(18),a={},d=Date.now();for(let g of r){let m=g.coinType,M=g.arrayIndex.toString(),S=g.depositsPoolRewardManager.poolRewards||[];for(let T of S){if(!T)continue;let D=T.id,R=T.coinType,N=parseInt(T.startTimeMs),L=parseInt(T.endTimeMs),O=d>=N&&d<L,B=T.mintDecimals,F=lt(T.cumulativeRewardsPerShare).times(10**B);a[D]={coinType:R,mintDecimals:B,isActive:O,reserveType:"deposit",reserveArrayIndex:M,reserveCoinType:m,globalCumulativePerShare:F,rewardIndex:T.rewardIndex,reserve:g}}let A=g.borrowsPoolRewardManager.poolRewards||[];for(let T of A){if(!T)continue;let D=T.id,R=T.coinType,N=parseInt(T.startTimeMs),L=parseInt(T.endTimeMs),O=d>=N&&d<L,B=T.mintDecimals,F=lt(T.cumulativeRewardsPerShare).times(10**B);a[D]={coinType:R,mintDecimals:B,isActive:O,reserveType:"borrow",reserveCoinType:m,reserveArrayIndex:M,rewardIndex:T.rewardIndex,globalCumulativePerShare:F,reserve:g}}}let c=i.userRewardManagers;for(let g of c)for(let m=0;m<g.rewards.length;m++){let M=g.rewards[m];if(!M)continue;let S=a[M.poolRewardId];if(!S)continue;let A=S.globalCumulativePerShare,T=new lt(M.cumulativeRewardsPerShare.value.toString()).div(t),D=new lt(g.share).times(A.minus(T)),R=new lt(M.earnedRewards.value).div(t),N=new lt(R).plus(D),L=S.reserve.price,O=N.div(10**S.mintDecimals),B=L?O.times(L).toFixed(12):0;E(B).gt(0)&&o.push({poolRewardId:M.poolRewardId,coinType:S.coinType,earnedRewards:N.toString(),earnedRewardsUsd:B,earnedRewardsFormatted:O.toFixed(12),isActive:S.isActive,reserveType:S.reserveType,reserveCoinType:S.reserveCoinType,reserveArrayIndex:S.reserveArrayIndex,rewardIndex:S.rewardIndex,rewardInfo:S})}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:g,base_token:m,quote_token:M,is_long:S,init_deposit_amount:A,tx:T,init_coin_type:D}=i,[R,N]=T.moveCall({target:`${d.published_at}::router::open_position`,arguments:[T.object(t),T.object(g),T.object(r),T.pure.u64(A),T.pure.u64(E(c).mul(1e4).toString()),T.object(be),T.object(a)],typeArguments:[o,S?m:M,D]});return{position_cap:R,margin_trading_context:N}}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:g,position_cap:m,deposit_reserve_array_index:M,input_coin:S,margin_trading_context:A,base_token:T,quote_token:D}=i,{global_config_id:R,versioned_id:N}=jt(this._sdk.sdkOptions.margin_trading);return r.moveCall({target:`${o.published_at}::router::deposit`,typeArguments:[t,d?T:D],arguments:[A,r.object(R),r.object(a),r.object(c),g?r.object(g):m,S,r.pure.u64(M),r.object(be),r.object(N)]}),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,g=jt(a).lending_market_type,{global_config_id:m,versioned_id:M}=jt(this._sdk.sdkOptions.margin_trading);for(let S=0;S<i.length;S++){let A=await this.createMarginTradingContext({market_id:r,position_cap_id:o,action:"claim_reward",coin_type:i[S].coinType,amount:E(i[S].earnedRewards).toFixed(0)},t),T=t.moveCall({target:`${d.published_at}::router::claim_rewards`,arguments:[A,t.object(m),t.object(c),t.object(r),t.object(o),t.pure.u64(i[S].reserveArrayIndex.toString()),t.pure.u64(i[S].rewardIndex.toString()),t.pure.bool(i[S].reserveType==="deposit"),t.object(be),t.object(M)],typeArguments:[g,i[S].coinType]});t.transferObjects([T],this._sdk.getSenderAddress()),await this.marginTradingContextConfirm(A,t)}}};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 Tr(n){return n.depositedAmount.eq(0)?new lt(0):n.borrowedAmount.div(n.depositedAmount).times(100)}function qi(n){let i=Tr(n);if(!i.gt(100))return to(n.config.interestRate,"utilPercent","aprPercent",i)}function Dr(n){let i=Tr(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 Te,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],g=c.lendingMarket.reserves.find(w=>w.coinType===i);if(!g)throw new Error("reserve not found");let M=(this.obligationsCache?.[c.lendingMarket.id]).rewardMap[g.token.coinType]?.[o]??[],S=fo(M),A=ho(o,g.coinType,d),T=o===ve.DEPOSIT?g.depositAprPercent:g.borrowAprPercent,D=T,R=new lt(1),N=!0;if(o!==void 0&&t!==void 0&&t.gt(0)){let w={...g,depositedAmount:o===ve.DEPOSIT?lt.max(g.depositedAmount.plus(o===ve.DEPOSIT?t:t.negated()),0):g.depositedAmount,borrowedAmount:o===ve.BORROW?lt.max(g.borrowedAmount.plus(o===ve.BORROW?t:t.negated()),0):g.borrowedAmount};D=o===ve.DEPOSIT?Dr(w):qi(w);let b=o===ve.DEPOSIT?g.depositedAmount:g.borrowedAmount,k=o===ve.DEPOSIT?w.depositedAmount:w.borrowedAmount;R=k.eq(0)?new lt(-1):b.div(k),N=!R.eq(-1)}let B=po(S).map(w=>({...w,stats:{...w.stats,perDay:N?w.stats.perDay.times(R):void 0}})),W=mo(S).map(w=>({...w,stats:{...w.stats,aprPercent:N?w.stats.aprPercent.times(R):void 0}})),j=Rr(o,T,S,A),Z=D===void 0||W.some(w=>w.stats.aprPercent===void 0)?void 0:Rr(o,D,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:j.toString()}};this.refreshReservePrice=async(i,r,o)=>{let{lending_market_id:t,lending_market_type:a}=Te(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}=Te(this.sdk.sdkOptions?.suilend),a={},d=[];if(i.forEach(M=>{let S=this.sdk.getCache(`getLatestPrice_${M.coinType.name}`,r);S&&this.priceCheck(S,60)?a[M.coinType.name]=S: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 g=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(g))?.forEach((M,S)=>{let A=M.getPriceUnchecked(),T=i[S];if(A){let{price:D,expo:R}=A,N=Fi(D).mul(Fi(10).pow(Fi(R))).toString(),L={coin_type:T.coinType.name||T.coinType,price:N,oracle_price:0n,last_update_time:A.publishTime};L.oracle_price=Or(BigInt(D),BigInt(R)),a[T.coinType.name||T.coinType]=L,this.sdk.updateCache(`getLatestPrice_${L.coin_type}`,L)}}),a};this.getLatestPriceFeedsByCoinTypes=async(i,r=!1)=>{try{let{lending_market_id:o}=Te(this.sdk.sdkOptions?.suilend),{allLendingMarketData:t}=await this.getLendingMarketData(!1),a=[];return i.forEach(c=>{let g=t[o].reserveMap[c];a.push(g)}),await this.getLatestPriceFeeds(a,r)}catch(o){Gt("FetchError",o);return}};this.getSuiLendReserveInfo=async(i,r,o,t)=>{let{lending_market_id:a}=Te(this.sdk.sdkOptions?.suilend);o||(o=(await this.getLendingMarketData(!1)).allLendingMarketData);let d=o[a].reserveMap[i],c=o[a].reserveMap[r],g=o[a].refreshedRawReserves.filter(T=>T.coinType.name==Ye(i)),m=o[a].refreshedRawReserves.filter(T=>T.coinType.name==Ye(r)),M=o[a].reserveMap[i],S=o[a].reserveMap[r],A=[];return t&&t.forEach(T=>{let D=o[a].refreshedRawReserves.filter(R=>R.coinType.name==Ye(T));A.push(...D)}),{base_reserve_array_index:d.arrayIndex.toString(),quote_reserve_array_index:c.arrayIndex.toString(),reserve:[g[0],m[0],...A],base_reserve_map_info:M,quote_reserve_map_info:S}};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=Te(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 g=>{let m=await this.getSuilendClient(g.id,g.type),{lendingMarket:M,coinMetadataMap:S,refreshedRawReserves:A,reserveMap:T,reserveCoinTypes:D,reserveCoinMetadataMap:R,rewardCoinTypes:N,activeRewardCoinTypes:L,rewardCoinMetadataMap:O}=await ao(this.sdk.FullClient,m),{rewardPriceMap:B}=await lo(T,L);return[g.id,{suilendClient:m,lendingMarket:M,coinMetadataMap:S,refreshedRawReserves:A,reserveMap:T,reserveCoinTypes:D,reserveCoinMetadataMap:R,rewardPriceMap:B,rewardCoinTypes:N,activeRewardCoinTypes:L,rewardCoinMetadataMap:O}]}))))(),(async()=>{try{let c=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.api_url}/springsui/apy`),g=await c.json();if(c?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(g).map(([m,M])=>[m,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}=Te(this.sdk.sdkOptions?.suilend),c=a[d];if(!c)throw new Error(`No user data found for lending market: ${d}`);let g=c.obligations.find(M=>M.id===i);if(!g)throw new Error(`Obligation not found: ${i}`);let m=go(g,c.rewardMap,t??{});return{obligation:g,netAprPercent:m,deposits:g.deposits,borrowedAmount:g.borrowedAmount,depositedAmount:g.depositedAmount,netValueUsd:g.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:g,tx:m}=i,M=wo(d)===g;console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:188 ~ SwapModules ~ isLoanA:",M);let[S,A,T]=m.moveCall({target:`${r.published_at}::pool::flash_loan`,arguments:[m.object(o),m.object(a),m.pure.bool(M),m.pure.u64(t.toString())],typeArguments:[d,c]});return{balance_a:S,balance_b:A,receipt:T,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:g,clmm_pool_coin_type_a:m,clmm_pool_coin_type_b:M}=i;return t.moveCall({target:`${r.published_at}::pool::repay_flash_loan`,arguments:[t.object(o),t.object(g),a,d,c],typeArguments:[m,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:g,tx:m}=i,M=r&&o||!r&&!o,S,A,T=t;if(M){let D=r&&o?d:a,R=r&&o?a:d,N=await this.findRouters(D,R,t,!0,[c]);if(T=N?.amount_out.toString(),N){let L=ji.buildCoinWithBalance(BigInt(t),D,m);A=await this.routerSwap({router:N.route_obj,slippage:g,input_coin:L,txb:m}),S=A}}else S=ji.buildCoinWithBalance(BigInt(t.toString()),o?d:a,m);return{has_swap:M,input_coin:S,init_deposit_amount:T}}async handleSwap(i){let{swap_clmm_pool:r="",slippage:o,amount:t,from:a,to:d,tx:c,input_coin:g}=i,m=await this.findRouters(a,d,t,!0,[r]),M=m.amount_out.toString();return{swap_out_coin:await this.routerSwap({router:m.route_obj,slippage:o,input_coin:g||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:g,quote_token_decimal:m}=i,M=await this._sdk.SuiLendModule.getLatestPriceFeeds(c),S=M&&M[Br(a)]?.price,A=M&&M[Br(t)]?.price,T=r?ee(A).div(ee(S)).toString():ee(S).div(ee(A)).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ swapModules.ts:267 ~ SwapModules ~ calculateFlashLoan ~ deposit_amount:",d,T,g,m);let D=ee(d).mul(ee(o).sub(1)).mul(T).div(10**(r?g:m)).mul(10**(r?m:g)).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(T).div(10**(r?g:m)).mul(10**(r?m:g)).toString(),D);let R=r?a:t,{clmm_pool_coin_type_a:N,clmm_fee_tier:L,clmm_pool:O,clmm_pool_coin_type_b:B}=await this.getFlashLoanPool(R,D),F=N===R,W=ee(D).mul(L).toString();return{flash_amount:D,rate:T,quote_price:S,base_price:A,flash_loan_coin:R,is_flash_a:F,flash_loan_fee:W,clmm_pool:O,clmm_pool_coin_type_a:N,clmm_pool_coin_type_b:B,clmm_fee_tier:L}}};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,Dr as calculateDepositAprPercent,Tr 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 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};
2
2
  /*! Bundled license information:
3
3
 
4
4
  decimal.js/decimal.mjs: