lll-sdk 0.0.0-experimental-20250902145508 → 0.0.0-experimental-20250902202808
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.d.mts +30 -25
- package/dist/index.d.ts +30 -25
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var kr=Object.create;var bt=Object.defineProperty;var Ar=Object.getOwnPropertyDescriptor;var Sr=Object.getOwnPropertyNames;var Cr=Object.getPrototypeOf,Pr=Object.prototype.hasOwnProperty;var xr=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports),Lr=(i,r)=>{for(var n in r)bt(i,n,{get:r[n],enumerable:!0})},Bi=(i,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of Sr(r))!Pr.call(i,t)&&t!==n&&bt(i,t,{get:()=>r[t],enumerable:!(s=Ar(r,t))||s.enumerable});return i};var ri=(i,r,n)=>(n=i!=null?kr(Cr(i)):{},Bi(r||!i||!i.__esModule?bt(n,"default",{value:i,enumerable:!0}):n,i)),Ir=i=>Bi(bt({},"__esModule",{value:!0}),i);var pr=xr((dr,vi)=>{"use strict";(function(i,r){"use strict";function n(c,e){if(!c)throw new Error(e||"Assertion failed")}function s(c,e){c.super_=e;var o=function(){};o.prototype=e.prototype,c.prototype=new o,c.prototype.constructor=c}function t(c,e,o){if(t.isBN(c))return c;this.negative=0,this.words=null,this.length=0,this.red=null,c!==null&&((e==="le"||e==="be")&&(o=e,e=10),this._init(c||0,e||10,o||"be"))}typeof i=="object"?i.exports=t:r.BN=t,t.BN=t,t.wordSize=26;var f;try{typeof window<"u"&&typeof window.Buffer<"u"?f=window.Buffer:f=require("buffer").Buffer}catch{}t.isBN=function(e){return e instanceof t?!0:e!==null&&typeof e=="object"&&e.constructor.wordSize===t.wordSize&&Array.isArray(e.words)},t.max=function(e,o){return e.cmp(o)>0?e:o},t.min=function(e,o){return e.cmp(o)<0?e:o},t.prototype._init=function(e,o,l){if(typeof e=="number")return this._initNumber(e,o,l);if(typeof e=="object")return this._initArray(e,o,l);o==="hex"&&(o=16),n(o===(o|0)&&o>=2&&o<=36),e=e.toString().replace(/\s+/g,"");var u=0;e[0]==="-"&&(u++,this.negative=1),u<e.length&&(o===16?this._parseHex(e,u,l):(this._parseBase(e,o,u),l==="le"&&this._initArray(this.toArray(),o,l)))},t.prototype._initNumber=function(e,o,l){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[e&67108863],this.length=1):e<4503599627370496?(this.words=[e&67108863,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[e&67108863,e/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),o,l)},t.prototype._initArray=function(e,o,l){if(n(typeof e.length=="number"),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var u=0;u<this.length;u++)this.words[u]=0;var h,g,k=0;if(l==="be")for(u=e.length-1,h=0;u>=0;u-=3)g=e[u]|e[u-1]<<8|e[u-2]<<16,this.words[h]|=g<<k&67108863,this.words[h+1]=g>>>26-k&67108863,k+=24,k>=26&&(k-=26,h++);else if(l==="le")for(u=0,h=0;u<e.length;u+=3)g=e[u]|e[u+1]<<8|e[u+2]<<16,this.words[h]|=g<<k&67108863,this.words[h+1]=g>>>26-k&67108863,k+=24,k>=26&&(k-=26,h++);return this._strip()};function d(c,e){var o=c.charCodeAt(e);if(o>=48&&o<=57)return o-48;if(o>=65&&o<=70)return o-55;if(o>=97&&o<=102)return o-87;n(!1,"Invalid character in "+c)}function v(c,e,o){var l=d(c,o);return o-1>=e&&(l|=d(c,o-1)<<4),l}t.prototype._parseHex=function(e,o,l){this.length=Math.ceil((e.length-o)/6),this.words=new Array(this.length);for(var u=0;u<this.length;u++)this.words[u]=0;var h=0,g=0,k;if(l==="be")for(u=e.length-1;u>=o;u-=2)k=v(e,o,u)<<h,this.words[g]|=k&67108863,h>=18?(h-=18,g+=1,this.words[g]|=k>>>26):h+=8;else{var p=e.length-o;for(u=p%2===0?o+1:o;u<e.length;u+=2)k=v(e,o,u)<<h,this.words[g]|=k&67108863,h>=18?(h-=18,g+=1,this.words[g]|=k>>>26):h+=8}this._strip()};function M(c,e,o,l){for(var u=0,h=0,g=Math.min(c.length,o),k=e;k<g;k++){var p=c.charCodeAt(k)-48;u*=l,p>=49?h=p-49+10:p>=17?h=p-17+10:h=p,n(p>=0&&h<l,"Invalid character"),u+=h}return u}t.prototype._parseBase=function(e,o,l){this.words=[0],this.length=1;for(var u=0,h=1;h<=67108863;h*=o)u++;u--,h=h/o|0;for(var g=e.length-l,k=g%u,p=Math.min(g,g-k)+l,a=0,y=l;y<p;y+=u)a=M(e,y,y+u,o),this.imuln(h),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(k!==0){var E=1;for(a=M(e,y,e.length,o),y=0;y<k;y++)E*=o;this.imuln(E),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this._strip()},t.prototype.copy=function(e){e.words=new Array(this.length);for(var o=0;o<this.length;o++)e.words[o]=this.words[o];e.length=this.length,e.negative=this.negative,e.red=this.red};function w(c,e){c.words=e.words,c.length=e.length,c.negative=e.negative,c.red=e.red}if(t.prototype._move=function(e){w(e,this)},t.prototype.clone=function(){var e=new t(null);return this.copy(e),e},t.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},t.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},t.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{t.prototype[Symbol.for("nodejs.util.inspect.custom")]=A}catch{t.prototype.inspect=A}else t.prototype.inspect=A;function A(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var x=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],C=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],L=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];t.prototype.toString=function(e,o){e=e||10,o=o|0||1;var l;if(e===16||e==="hex"){l="";for(var u=0,h=0,g=0;g<this.length;g++){var k=this.words[g],p=((k<<u|h)&16777215).toString(16);h=k>>>24-u&16777215,u+=2,u>=26&&(u-=26,g--),h!==0||g!==this.length-1?l=x[6-p.length]+p+l:l=p+l}for(h!==0&&(l=h.toString(16)+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(e===(e|0)&&e>=2&&e<=36){var a=C[e],y=L[e];l="";var E=this.clone();for(E.negative=0;!E.isZero();){var R=E.modrn(y).toString(e);E=E.idivn(y),E.isZero()?l=R+l:l=x[a-R.length]+R+l}for(this.isZero()&&(l="0"+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}n(!1,"Base should be between 2 and 36")},t.prototype.toNumber=function(){var e=this.words[0];return this.length===2?e+=this.words[1]*67108864:this.length===3&&this.words[2]===1?e+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-e:e},t.prototype.toJSON=function(){return this.toString(16,2)},f&&(t.prototype.toBuffer=function(e,o){return this.toArrayLike(f,e,o)}),t.prototype.toArray=function(e,o){return this.toArrayLike(Array,e,o)};var B=function(e,o){return e.allocUnsafe?e.allocUnsafe(o):new e(o)};t.prototype.toArrayLike=function(e,o,l){this._strip();var u=this.byteLength(),h=l||Math.max(1,u);n(u<=h,"byte array longer than desired length"),n(h>0,"Requested array length <= 0");var g=B(e,h),k=o==="le"?"LE":"BE";return this["_toArrayLike"+k](g,u),g},t.prototype._toArrayLikeLE=function(e,o){for(var l=0,u=0,h=0,g=0;h<this.length;h++){var k=this.words[h]<<g|u;e[l++]=k&255,l<e.length&&(e[l++]=k>>8&255),l<e.length&&(e[l++]=k>>16&255),g===6?(l<e.length&&(e[l++]=k>>24&255),u=0,g=0):(u=k>>>24,g+=2)}if(l<e.length)for(e[l++]=u;l<e.length;)e[l++]=0},t.prototype._toArrayLikeBE=function(e,o){for(var l=e.length-1,u=0,h=0,g=0;h<this.length;h++){var k=this.words[h]<<g|u;e[l--]=k&255,l>=0&&(e[l--]=k>>8&255),l>=0&&(e[l--]=k>>16&255),g===6?(l>=0&&(e[l--]=k>>24&255),u=0,g=0):(u=k>>>24,g+=2)}if(l>=0)for(e[l--]=u;l>=0;)e[l--]=0},Math.clz32?t.prototype._countBits=function(e){return 32-Math.clz32(e)}:t.prototype._countBits=function(e){var o=e,l=0;return o>=4096&&(l+=13,o>>>=13),o>=64&&(l+=7,o>>>=7),o>=8&&(l+=4,o>>>=4),o>=2&&(l+=2,o>>>=2),l+o},t.prototype._zeroBits=function(e){if(e===0)return 26;var o=e,l=0;return(o&8191)===0&&(l+=13,o>>>=13),(o&127)===0&&(l+=7,o>>>=7),(o&15)===0&&(l+=4,o>>>=4),(o&3)===0&&(l+=2,o>>>=2),(o&1)===0&&l++,l},t.prototype.bitLength=function(){var e=this.words[this.length-1],o=this._countBits(e);return(this.length-1)*26+o};function D(c){for(var e=new Array(c.bitLength()),o=0;o<e.length;o++){var l=o/26|0,u=o%26;e[o]=c.words[l]>>>u&1}return e}t.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,o=0;o<this.length;o++){var l=this._zeroBits(this.words[o]);if(e+=l,l!==26)break}return e},t.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},t.prototype.toTwos=function(e){return this.negative!==0?this.abs().inotn(e).iaddn(1):this.clone()},t.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},t.prototype.isNeg=function(){return this.negative!==0},t.prototype.neg=function(){return this.clone().ineg()},t.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},t.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var o=0;o<e.length;o++)this.words[o]=this.words[o]|e.words[o];return this._strip()},t.prototype.ior=function(e){return n((this.negative|e.negative)===0),this.iuor(e)},t.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},t.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},t.prototype.iuand=function(e){var o;this.length>e.length?o=e:o=this;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]&e.words[l];return this.length=o.length,this._strip()},t.prototype.iand=function(e){return n((this.negative|e.negative)===0),this.iuand(e)},t.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},t.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},t.prototype.iuxor=function(e){var o,l;this.length>e.length?(o=this,l=e):(o=e,l=this);for(var u=0;u<l.length;u++)this.words[u]=o.words[u]^l.words[u];if(this!==o)for(;u<o.length;u++)this.words[u]=o.words[u];return this.length=o.length,this._strip()},t.prototype.ixor=function(e){return n((this.negative|e.negative)===0),this.iuxor(e)},t.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},t.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},t.prototype.inotn=function(e){n(typeof e=="number"&&e>=0);var o=Math.ceil(e/26)|0,l=e%26;this._expand(o),l>0&&o--;for(var u=0;u<o;u++)this.words[u]=~this.words[u]&67108863;return l>0&&(this.words[u]=~this.words[u]&67108863>>26-l),this._strip()},t.prototype.notn=function(e){return this.clone().inotn(e)},t.prototype.setn=function(e,o){n(typeof e=="number"&&e>=0);var l=e/26|0,u=e%26;return this._expand(l+1),o?this.words[l]=this.words[l]|1<<u:this.words[l]=this.words[l]&~(1<<u),this._strip()},t.prototype.iadd=function(e){var o;if(this.negative!==0&&e.negative===0)return this.negative=0,o=this.isub(e),this.negative^=1,this._normSign();if(this.negative===0&&e.negative!==0)return e.negative=0,o=this.isub(e),e.negative=1,o._normSign();var l,u;this.length>e.length?(l=this,u=e):(l=e,u=this);for(var h=0,g=0;g<u.length;g++)o=(l.words[g]|0)+(u.words[g]|0)+h,this.words[g]=o&67108863,h=o>>>26;for(;h!==0&&g<l.length;g++)o=(l.words[g]|0)+h,this.words[g]=o&67108863,h=o>>>26;if(this.length=l.length,h!==0)this.words[this.length]=h,this.length++;else if(l!==this)for(;g<l.length;g++)this.words[g]=l.words[g];return this},t.prototype.add=function(e){var o;return e.negative!==0&&this.negative===0?(e.negative=0,o=this.sub(e),e.negative^=1,o):e.negative===0&&this.negative!==0?(this.negative=0,o=e.sub(this),this.negative=1,o):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},t.prototype.isub=function(e){if(e.negative!==0){e.negative=0;var o=this.iadd(e);return e.negative=1,o._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var l=this.cmp(e);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var u,h;l>0?(u=this,h=e):(u=e,h=this);for(var g=0,k=0;k<h.length;k++)o=(u.words[k]|0)-(h.words[k]|0)+g,g=o>>26,this.words[k]=o&67108863;for(;g!==0&&k<u.length;k++)o=(u.words[k]|0)+g,g=o>>26,this.words[k]=o&67108863;if(g===0&&k<u.length&&u!==this)for(;k<u.length;k++)this.words[k]=u.words[k];return this.length=Math.max(this.length,k),u!==this&&(this.negative=1),this._strip()},t.prototype.sub=function(e){return this.clone().isub(e)};function Z(c,e,o){o.negative=e.negative^c.negative;var l=c.length+e.length|0;o.length=l,l=l-1|0;var u=c.words[0]|0,h=e.words[0]|0,g=u*h,k=g&67108863,p=g/67108864|0;o.words[0]=k;for(var a=1;a<l;a++){for(var y=p>>>26,E=p&67108863,R=Math.min(a,e.length-1),T=Math.max(0,a-c.length+1);T<=R;T++){var U=a-T|0;u=c.words[U]|0,h=e.words[T]|0,g=u*h+E,y+=g/67108864|0,E=g&67108863}o.words[a]=E|0,p=y|0}return p!==0?o.words[a]=p|0:o.length--,o._strip()}var j=function(e,o,l){var u=e.words,h=o.words,g=l.words,k=0,p,a,y,E=u[0]|0,R=E&8191,T=E>>>13,U=u[1]|0,V=U&8191,J=U>>>13,He=u[2]|0,Q=He&8191,te=He>>>13,ze=u[3]|0,Y=ze&8191,W=ze>>>13,bi=u[4]|0,oe=bi&8191,se=bi>>>13,_i=u[5]|0,ae=_i&8191,le=_i>>>13,ki=u[6]|0,fe=ki&8191,ue=ki>>>13,Ai=u[7]|0,he=Ai&8191,ce=Ai>>>13,Si=u[8]|0,de=Si&8191,pe=Si>>>13,Ci=u[9]|0,ge=Ci&8191,me=Ci>>>13,Pi=h[0]|0,ve=Pi&8191,we=Pi>>>13,xi=h[1]|0,Me=xi&8191,ye=xi>>>13,Li=h[2]|0,be=Li&8191,_e=Li>>>13,Ii=h[3]|0,ke=Ii&8191,Ae=Ii>>>13,Oi=h[4]|0,Se=Oi&8191,Ce=Oi>>>13,Ni=h[5]|0,Pe=Ni&8191,xe=Ni>>>13,Ri=h[6]|0,Le=Ri&8191,Ie=Ri>>>13,Ti=h[7]|0,Oe=Ti&8191,Ne=Ti>>>13,Di=h[8]|0,Re=Di&8191,Te=Di>>>13,Ei=h[9]|0,De=Ei&8191,Ee=Ei>>>13;l.negative=e.negative^o.negative,l.length=19,p=Math.imul(R,ve),a=Math.imul(R,we),a=a+Math.imul(T,ve)|0,y=Math.imul(T,we);var Ft=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ft>>>26)|0,Ft&=67108863,p=Math.imul(V,ve),a=Math.imul(V,we),a=a+Math.imul(J,ve)|0,y=Math.imul(J,we),p=p+Math.imul(R,Me)|0,a=a+Math.imul(R,ye)|0,a=a+Math.imul(T,Me)|0,y=y+Math.imul(T,ye)|0;var qt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(qt>>>26)|0,qt&=67108863,p=Math.imul(Q,ve),a=Math.imul(Q,we),a=a+Math.imul(te,ve)|0,y=Math.imul(te,we),p=p+Math.imul(V,Me)|0,a=a+Math.imul(V,ye)|0,a=a+Math.imul(J,Me)|0,y=y+Math.imul(J,ye)|0,p=p+Math.imul(R,be)|0,a=a+Math.imul(R,_e)|0,a=a+Math.imul(T,be)|0,y=y+Math.imul(T,_e)|0;var Ut=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,p=Math.imul(Y,ve),a=Math.imul(Y,we),a=a+Math.imul(W,ve)|0,y=Math.imul(W,we),p=p+Math.imul(Q,Me)|0,a=a+Math.imul(Q,ye)|0,a=a+Math.imul(te,Me)|0,y=y+Math.imul(te,ye)|0,p=p+Math.imul(V,be)|0,a=a+Math.imul(V,_e)|0,a=a+Math.imul(J,be)|0,y=y+Math.imul(J,_e)|0,p=p+Math.imul(R,ke)|0,a=a+Math.imul(R,Ae)|0,a=a+Math.imul(T,ke)|0,y=y+Math.imul(T,Ae)|0;var Zt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,p=Math.imul(oe,ve),a=Math.imul(oe,we),a=a+Math.imul(se,ve)|0,y=Math.imul(se,we),p=p+Math.imul(Y,Me)|0,a=a+Math.imul(Y,ye)|0,a=a+Math.imul(W,Me)|0,y=y+Math.imul(W,ye)|0,p=p+Math.imul(Q,be)|0,a=a+Math.imul(Q,_e)|0,a=a+Math.imul(te,be)|0,y=y+Math.imul(te,_e)|0,p=p+Math.imul(V,ke)|0,a=a+Math.imul(V,Ae)|0,a=a+Math.imul(J,ke)|0,y=y+Math.imul(J,Ae)|0,p=p+Math.imul(R,Se)|0,a=a+Math.imul(R,Ce)|0,a=a+Math.imul(T,Se)|0,y=y+Math.imul(T,Ce)|0;var jt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(jt>>>26)|0,jt&=67108863,p=Math.imul(ae,ve),a=Math.imul(ae,we),a=a+Math.imul(le,ve)|0,y=Math.imul(le,we),p=p+Math.imul(oe,Me)|0,a=a+Math.imul(oe,ye)|0,a=a+Math.imul(se,Me)|0,y=y+Math.imul(se,ye)|0,p=p+Math.imul(Y,be)|0,a=a+Math.imul(Y,_e)|0,a=a+Math.imul(W,be)|0,y=y+Math.imul(W,_e)|0,p=p+Math.imul(Q,ke)|0,a=a+Math.imul(Q,Ae)|0,a=a+Math.imul(te,ke)|0,y=y+Math.imul(te,Ae)|0,p=p+Math.imul(V,Se)|0,a=a+Math.imul(V,Ce)|0,a=a+Math.imul(J,Se)|0,y=y+Math.imul(J,Ce)|0,p=p+Math.imul(R,Pe)|0,a=a+Math.imul(R,xe)|0,a=a+Math.imul(T,Pe)|0,y=y+Math.imul(T,xe)|0;var zt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(zt>>>26)|0,zt&=67108863,p=Math.imul(fe,ve),a=Math.imul(fe,we),a=a+Math.imul(ue,ve)|0,y=Math.imul(ue,we),p=p+Math.imul(ae,Me)|0,a=a+Math.imul(ae,ye)|0,a=a+Math.imul(le,Me)|0,y=y+Math.imul(le,ye)|0,p=p+Math.imul(oe,be)|0,a=a+Math.imul(oe,_e)|0,a=a+Math.imul(se,be)|0,y=y+Math.imul(se,_e)|0,p=p+Math.imul(Y,ke)|0,a=a+Math.imul(Y,Ae)|0,a=a+Math.imul(W,ke)|0,y=y+Math.imul(W,Ae)|0,p=p+Math.imul(Q,Se)|0,a=a+Math.imul(Q,Ce)|0,a=a+Math.imul(te,Se)|0,y=y+Math.imul(te,Ce)|0,p=p+Math.imul(V,Pe)|0,a=a+Math.imul(V,xe)|0,a=a+Math.imul(J,Pe)|0,y=y+Math.imul(J,xe)|0,p=p+Math.imul(R,Le)|0,a=a+Math.imul(R,Ie)|0,a=a+Math.imul(T,Le)|0,y=y+Math.imul(T,Ie)|0;var $t=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+($t>>>26)|0,$t&=67108863,p=Math.imul(he,ve),a=Math.imul(he,we),a=a+Math.imul(ce,ve)|0,y=Math.imul(ce,we),p=p+Math.imul(fe,Me)|0,a=a+Math.imul(fe,ye)|0,a=a+Math.imul(ue,Me)|0,y=y+Math.imul(ue,ye)|0,p=p+Math.imul(ae,be)|0,a=a+Math.imul(ae,_e)|0,a=a+Math.imul(le,be)|0,y=y+Math.imul(le,_e)|0,p=p+Math.imul(oe,ke)|0,a=a+Math.imul(oe,Ae)|0,a=a+Math.imul(se,ke)|0,y=y+Math.imul(se,Ae)|0,p=p+Math.imul(Y,Se)|0,a=a+Math.imul(Y,Ce)|0,a=a+Math.imul(W,Se)|0,y=y+Math.imul(W,Ce)|0,p=p+Math.imul(Q,Pe)|0,a=a+Math.imul(Q,xe)|0,a=a+Math.imul(te,Pe)|0,y=y+Math.imul(te,xe)|0,p=p+Math.imul(V,Le)|0,a=a+Math.imul(V,Ie)|0,a=a+Math.imul(J,Le)|0,y=y+Math.imul(J,Ie)|0,p=p+Math.imul(R,Oe)|0,a=a+Math.imul(R,Ne)|0,a=a+Math.imul(T,Oe)|0,y=y+Math.imul(T,Ne)|0;var Kt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,p=Math.imul(de,ve),a=Math.imul(de,we),a=a+Math.imul(pe,ve)|0,y=Math.imul(pe,we),p=p+Math.imul(he,Me)|0,a=a+Math.imul(he,ye)|0,a=a+Math.imul(ce,Me)|0,y=y+Math.imul(ce,ye)|0,p=p+Math.imul(fe,be)|0,a=a+Math.imul(fe,_e)|0,a=a+Math.imul(ue,be)|0,y=y+Math.imul(ue,_e)|0,p=p+Math.imul(ae,ke)|0,a=a+Math.imul(ae,Ae)|0,a=a+Math.imul(le,ke)|0,y=y+Math.imul(le,Ae)|0,p=p+Math.imul(oe,Se)|0,a=a+Math.imul(oe,Ce)|0,a=a+Math.imul(se,Se)|0,y=y+Math.imul(se,Ce)|0,p=p+Math.imul(Y,Pe)|0,a=a+Math.imul(Y,xe)|0,a=a+Math.imul(W,Pe)|0,y=y+Math.imul(W,xe)|0,p=p+Math.imul(Q,Le)|0,a=a+Math.imul(Q,Ie)|0,a=a+Math.imul(te,Le)|0,y=y+Math.imul(te,Ie)|0,p=p+Math.imul(V,Oe)|0,a=a+Math.imul(V,Ne)|0,a=a+Math.imul(J,Oe)|0,y=y+Math.imul(J,Ne)|0,p=p+Math.imul(R,Re)|0,a=a+Math.imul(R,Te)|0,a=a+Math.imul(T,Re)|0,y=y+Math.imul(T,Te)|0;var Ht=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,p=Math.imul(ge,ve),a=Math.imul(ge,we),a=a+Math.imul(me,ve)|0,y=Math.imul(me,we),p=p+Math.imul(de,Me)|0,a=a+Math.imul(de,ye)|0,a=a+Math.imul(pe,Me)|0,y=y+Math.imul(pe,ye)|0,p=p+Math.imul(he,be)|0,a=a+Math.imul(he,_e)|0,a=a+Math.imul(ce,be)|0,y=y+Math.imul(ce,_e)|0,p=p+Math.imul(fe,ke)|0,a=a+Math.imul(fe,Ae)|0,a=a+Math.imul(ue,ke)|0,y=y+Math.imul(ue,Ae)|0,p=p+Math.imul(ae,Se)|0,a=a+Math.imul(ae,Ce)|0,a=a+Math.imul(le,Se)|0,y=y+Math.imul(le,Ce)|0,p=p+Math.imul(oe,Pe)|0,a=a+Math.imul(oe,xe)|0,a=a+Math.imul(se,Pe)|0,y=y+Math.imul(se,xe)|0,p=p+Math.imul(Y,Le)|0,a=a+Math.imul(Y,Ie)|0,a=a+Math.imul(W,Le)|0,y=y+Math.imul(W,Ie)|0,p=p+Math.imul(Q,Oe)|0,a=a+Math.imul(Q,Ne)|0,a=a+Math.imul(te,Oe)|0,y=y+Math.imul(te,Ne)|0,p=p+Math.imul(V,Re)|0,a=a+Math.imul(V,Te)|0,a=a+Math.imul(J,Re)|0,y=y+Math.imul(J,Te)|0,p=p+Math.imul(R,De)|0,a=a+Math.imul(R,Ee)|0,a=a+Math.imul(T,De)|0,y=y+Math.imul(T,Ee)|0;var Wt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,p=Math.imul(ge,Me),a=Math.imul(ge,ye),a=a+Math.imul(me,Me)|0,y=Math.imul(me,ye),p=p+Math.imul(de,be)|0,a=a+Math.imul(de,_e)|0,a=a+Math.imul(pe,be)|0,y=y+Math.imul(pe,_e)|0,p=p+Math.imul(he,ke)|0,a=a+Math.imul(he,Ae)|0,a=a+Math.imul(ce,ke)|0,y=y+Math.imul(ce,Ae)|0,p=p+Math.imul(fe,Se)|0,a=a+Math.imul(fe,Ce)|0,a=a+Math.imul(ue,Se)|0,y=y+Math.imul(ue,Ce)|0,p=p+Math.imul(ae,Pe)|0,a=a+Math.imul(ae,xe)|0,a=a+Math.imul(le,Pe)|0,y=y+Math.imul(le,xe)|0,p=p+Math.imul(oe,Le)|0,a=a+Math.imul(oe,Ie)|0,a=a+Math.imul(se,Le)|0,y=y+Math.imul(se,Ie)|0,p=p+Math.imul(Y,Oe)|0,a=a+Math.imul(Y,Ne)|0,a=a+Math.imul(W,Oe)|0,y=y+Math.imul(W,Ne)|0,p=p+Math.imul(Q,Re)|0,a=a+Math.imul(Q,Te)|0,a=a+Math.imul(te,Re)|0,y=y+Math.imul(te,Te)|0,p=p+Math.imul(V,De)|0,a=a+Math.imul(V,Ee)|0,a=a+Math.imul(J,De)|0,y=y+Math.imul(J,Ee)|0;var Gt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,p=Math.imul(ge,be),a=Math.imul(ge,_e),a=a+Math.imul(me,be)|0,y=Math.imul(me,_e),p=p+Math.imul(de,ke)|0,a=a+Math.imul(de,Ae)|0,a=a+Math.imul(pe,ke)|0,y=y+Math.imul(pe,Ae)|0,p=p+Math.imul(he,Se)|0,a=a+Math.imul(he,Ce)|0,a=a+Math.imul(ce,Se)|0,y=y+Math.imul(ce,Ce)|0,p=p+Math.imul(fe,Pe)|0,a=a+Math.imul(fe,xe)|0,a=a+Math.imul(ue,Pe)|0,y=y+Math.imul(ue,xe)|0,p=p+Math.imul(ae,Le)|0,a=a+Math.imul(ae,Ie)|0,a=a+Math.imul(le,Le)|0,y=y+Math.imul(le,Ie)|0,p=p+Math.imul(oe,Oe)|0,a=a+Math.imul(oe,Ne)|0,a=a+Math.imul(se,Oe)|0,y=y+Math.imul(se,Ne)|0,p=p+Math.imul(Y,Re)|0,a=a+Math.imul(Y,Te)|0,a=a+Math.imul(W,Re)|0,y=y+Math.imul(W,Te)|0,p=p+Math.imul(Q,De)|0,a=a+Math.imul(Q,Ee)|0,a=a+Math.imul(te,De)|0,y=y+Math.imul(te,Ee)|0;var Vt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,p=Math.imul(ge,ke),a=Math.imul(ge,Ae),a=a+Math.imul(me,ke)|0,y=Math.imul(me,Ae),p=p+Math.imul(de,Se)|0,a=a+Math.imul(de,Ce)|0,a=a+Math.imul(pe,Se)|0,y=y+Math.imul(pe,Ce)|0,p=p+Math.imul(he,Pe)|0,a=a+Math.imul(he,xe)|0,a=a+Math.imul(ce,Pe)|0,y=y+Math.imul(ce,xe)|0,p=p+Math.imul(fe,Le)|0,a=a+Math.imul(fe,Ie)|0,a=a+Math.imul(ue,Le)|0,y=y+Math.imul(ue,Ie)|0,p=p+Math.imul(ae,Oe)|0,a=a+Math.imul(ae,Ne)|0,a=a+Math.imul(le,Oe)|0,y=y+Math.imul(le,Ne)|0,p=p+Math.imul(oe,Re)|0,a=a+Math.imul(oe,Te)|0,a=a+Math.imul(se,Re)|0,y=y+Math.imul(se,Te)|0,p=p+Math.imul(Y,De)|0,a=a+Math.imul(Y,Ee)|0,a=a+Math.imul(W,De)|0,y=y+Math.imul(W,Ee)|0;var Xt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,p=Math.imul(ge,Se),a=Math.imul(ge,Ce),a=a+Math.imul(me,Se)|0,y=Math.imul(me,Ce),p=p+Math.imul(de,Pe)|0,a=a+Math.imul(de,xe)|0,a=a+Math.imul(pe,Pe)|0,y=y+Math.imul(pe,xe)|0,p=p+Math.imul(he,Le)|0,a=a+Math.imul(he,Ie)|0,a=a+Math.imul(ce,Le)|0,y=y+Math.imul(ce,Ie)|0,p=p+Math.imul(fe,Oe)|0,a=a+Math.imul(fe,Ne)|0,a=a+Math.imul(ue,Oe)|0,y=y+Math.imul(ue,Ne)|0,p=p+Math.imul(ae,Re)|0,a=a+Math.imul(ae,Te)|0,a=a+Math.imul(le,Re)|0,y=y+Math.imul(le,Te)|0,p=p+Math.imul(oe,De)|0,a=a+Math.imul(oe,Ee)|0,a=a+Math.imul(se,De)|0,y=y+Math.imul(se,Ee)|0;var Qt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,p=Math.imul(ge,Pe),a=Math.imul(ge,xe),a=a+Math.imul(me,Pe)|0,y=Math.imul(me,xe),p=p+Math.imul(de,Le)|0,a=a+Math.imul(de,Ie)|0,a=a+Math.imul(pe,Le)|0,y=y+Math.imul(pe,Ie)|0,p=p+Math.imul(he,Oe)|0,a=a+Math.imul(he,Ne)|0,a=a+Math.imul(ce,Oe)|0,y=y+Math.imul(ce,Ne)|0,p=p+Math.imul(fe,Re)|0,a=a+Math.imul(fe,Te)|0,a=a+Math.imul(ue,Re)|0,y=y+Math.imul(ue,Te)|0,p=p+Math.imul(ae,De)|0,a=a+Math.imul(ae,Ee)|0,a=a+Math.imul(le,De)|0,y=y+Math.imul(le,Ee)|0;var Yt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,p=Math.imul(ge,Le),a=Math.imul(ge,Ie),a=a+Math.imul(me,Le)|0,y=Math.imul(me,Ie),p=p+Math.imul(de,Oe)|0,a=a+Math.imul(de,Ne)|0,a=a+Math.imul(pe,Oe)|0,y=y+Math.imul(pe,Ne)|0,p=p+Math.imul(he,Re)|0,a=a+Math.imul(he,Te)|0,a=a+Math.imul(ce,Re)|0,y=y+Math.imul(ce,Te)|0,p=p+Math.imul(fe,De)|0,a=a+Math.imul(fe,Ee)|0,a=a+Math.imul(ue,De)|0,y=y+Math.imul(ue,Ee)|0;var Jt=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,p=Math.imul(ge,Oe),a=Math.imul(ge,Ne),a=a+Math.imul(me,Oe)|0,y=Math.imul(me,Ne),p=p+Math.imul(de,Re)|0,a=a+Math.imul(de,Te)|0,a=a+Math.imul(pe,Re)|0,y=y+Math.imul(pe,Te)|0,p=p+Math.imul(he,De)|0,a=a+Math.imul(he,Ee)|0,a=a+Math.imul(ce,De)|0,y=y+Math.imul(ce,Ee)|0;var ei=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(ei>>>26)|0,ei&=67108863,p=Math.imul(ge,Re),a=Math.imul(ge,Te),a=a+Math.imul(me,Re)|0,y=Math.imul(me,Te),p=p+Math.imul(de,De)|0,a=a+Math.imul(de,Ee)|0,a=a+Math.imul(pe,De)|0,y=y+Math.imul(pe,Ee)|0;var ti=(k+p|0)+((a&8191)<<13)|0;k=(y+(a>>>13)|0)+(ti>>>26)|0,ti&=67108863,p=Math.imul(ge,De),a=Math.imul(ge,Ee),a=a+Math.imul(me,De)|0,y=Math.imul(me,Ee);var ii=(k+p|0)+((a&8191)<<13)|0;return k=(y+(a>>>13)|0)+(ii>>>26)|0,ii&=67108863,g[0]=Ft,g[1]=qt,g[2]=Ut,g[3]=Zt,g[4]=jt,g[5]=zt,g[6]=$t,g[7]=Kt,g[8]=Ht,g[9]=Wt,g[10]=Gt,g[11]=Vt,g[12]=Xt,g[13]=Qt,g[14]=Yt,g[15]=Jt,g[16]=ei,g[17]=ti,g[18]=ii,k!==0&&(g[19]=k,l.length++),l};Math.imul||(j=Z);function I(c,e,o){o.negative=e.negative^c.negative,o.length=c.length+e.length;for(var l=0,u=0,h=0;h<o.length-1;h++){var g=u;u=0;for(var k=l&67108863,p=Math.min(h,e.length-1),a=Math.max(0,h-c.length+1);a<=p;a++){var y=h-a,E=c.words[y]|0,R=e.words[a]|0,T=E*R,U=T&67108863;g=g+(T/67108864|0)|0,U=U+k|0,k=U&67108863,g=g+(U>>>26)|0,u+=g>>>26,g&=67108863}o.words[h]=k,l=g,g=u}return l!==0?o.words[h]=l:o.length--,o._strip()}function F(c,e,o){return I(c,e,o)}t.prototype.mulTo=function(e,o){var l,u=this.length+e.length;return this.length===10&&e.length===10?l=j(this,e,o):u<63?l=Z(this,e,o):u<1024?l=I(this,e,o):l=F(this,e,o),l};function q(c,e){this.x=c,this.y=e}q.prototype.makeRBT=function(e){for(var o=new Array(e),l=t.prototype._countBits(e)-1,u=0;u<e;u++)o[u]=this.revBin(u,l,e);return o},q.prototype.revBin=function(e,o,l){if(e===0||e===l-1)return e;for(var u=0,h=0;h<o;h++)u|=(e&1)<<o-h-1,e>>=1;return u},q.prototype.permute=function(e,o,l,u,h,g){for(var k=0;k<g;k++)u[k]=o[e[k]],h[k]=l[e[k]]},q.prototype.transform=function(e,o,l,u,h,g){this.permute(g,e,o,l,u,h);for(var k=1;k<h;k<<=1)for(var p=k<<1,a=Math.cos(2*Math.PI/p),y=Math.sin(2*Math.PI/p),E=0;E<h;E+=p)for(var R=a,T=y,U=0;U<k;U++){var V=l[E+U],J=u[E+U],He=l[E+U+k],Q=u[E+U+k],te=R*He-T*Q;Q=R*Q+T*He,He=te,l[E+U]=V+He,u[E+U]=J+Q,l[E+U+k]=V-He,u[E+U+k]=J-Q,U!==p&&(te=a*R-y*T,T=a*T+y*R,R=te)}},q.prototype.guessLen13b=function(e,o){var l=Math.max(o,e)|1,u=l&1,h=0;for(l=l/2|0;l;l=l>>>1)h++;return 1<<h+1+u},q.prototype.conjugate=function(e,o,l){if(!(l<=1))for(var u=0;u<l/2;u++){var h=e[u];e[u]=e[l-u-1],e[l-u-1]=h,h=o[u],o[u]=-o[l-u-1],o[l-u-1]=-h}},q.prototype.normalize13b=function(e,o){for(var l=0,u=0;u<o/2;u++){var h=Math.round(e[2*u+1]/o)*8192+Math.round(e[2*u]/o)+l;e[u]=h&67108863,h<67108864?l=0:l=h/67108864|0}return e},q.prototype.convert13b=function(e,o,l,u){for(var h=0,g=0;g<o;g++)h=h+(e[g]|0),l[2*g]=h&8191,h=h>>>13,l[2*g+1]=h&8191,h=h>>>13;for(g=2*o;g<u;++g)l[g]=0;n(h===0),n((h&-8192)===0)},q.prototype.stub=function(e){for(var o=new Array(e),l=0;l<e;l++)o[l]=0;return o},q.prototype.mulp=function(e,o,l){var u=2*this.guessLen13b(e.length,o.length),h=this.makeRBT(u),g=this.stub(u),k=new Array(u),p=new Array(u),a=new Array(u),y=new Array(u),E=new Array(u),R=new Array(u),T=l.words;T.length=u,this.convert13b(e.words,e.length,k,u),this.convert13b(o.words,o.length,y,u),this.transform(k,g,p,a,u,h),this.transform(y,g,E,R,u,h);for(var U=0;U<u;U++){var V=p[U]*E[U]-a[U]*R[U];a[U]=p[U]*R[U]+a[U]*E[U],p[U]=V}return this.conjugate(p,a,u),this.transform(p,a,T,g,u,h),this.conjugate(T,g,u),this.normalize13b(T,u),l.negative=e.negative^o.negative,l.length=e.length+o.length,l._strip()},t.prototype.mul=function(e){var o=new t(null);return o.words=new Array(this.length+e.length),this.mulTo(e,o)},t.prototype.mulf=function(e){var o=new t(null);return o.words=new Array(this.length+e.length),F(this,e,o)},t.prototype.imul=function(e){return this.clone().mulTo(e,this)},t.prototype.imuln=function(e){var o=e<0;o&&(e=-e),n(typeof e=="number"),n(e<67108864);for(var l=0,u=0;u<this.length;u++){var h=(this.words[u]|0)*e,g=(h&67108863)+(l&67108863);l>>=26,l+=h/67108864|0,l+=g>>>26,this.words[u]=g&67108863}return l!==0&&(this.words[u]=l,this.length++),this.length=e===0?1:this.length,o?this.ineg():this},t.prototype.muln=function(e){return this.clone().imuln(e)},t.prototype.sqr=function(){return this.mul(this)},t.prototype.isqr=function(){return this.imul(this.clone())},t.prototype.pow=function(e){var o=D(e);if(o.length===0)return new t(1);for(var l=this,u=0;u<o.length&&o[u]===0;u++,l=l.sqr());if(++u<o.length)for(var h=l.sqr();u<o.length;u++,h=h.sqr())o[u]!==0&&(l=l.mul(h));return l},t.prototype.iushln=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26,u=67108863>>>26-o<<26-o,h;if(o!==0){var g=0;for(h=0;h<this.length;h++){var k=this.words[h]&u,p=(this.words[h]|0)-k<<o;this.words[h]=p|g,g=k>>>26-o}g&&(this.words[h]=g,this.length++)}if(l!==0){for(h=this.length-1;h>=0;h--)this.words[h+l]=this.words[h];for(h=0;h<l;h++)this.words[h]=0;this.length+=l}return this._strip()},t.prototype.ishln=function(e){return n(this.negative===0),this.iushln(e)},t.prototype.iushrn=function(e,o,l){n(typeof e=="number"&&e>=0);var u;o?u=(o-o%26)/26:u=0;var h=e%26,g=Math.min((e-h)/26,this.length),k=67108863^67108863>>>h<<h,p=l;if(u-=g,u=Math.max(0,u),p){for(var a=0;a<g;a++)p.words[a]=this.words[a];p.length=g}if(g!==0)if(this.length>g)for(this.length-=g,a=0;a<this.length;a++)this.words[a]=this.words[a+g];else this.words[0]=0,this.length=1;var y=0;for(a=this.length-1;a>=0&&(y!==0||a>=u);a--){var E=this.words[a]|0;this.words[a]=y<<26-h|E>>>h,y=E&k}return p&&y!==0&&(p.words[p.length++]=y),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},t.prototype.ishrn=function(e,o,l){return n(this.negative===0),this.iushrn(e,o,l)},t.prototype.shln=function(e){return this.clone().ishln(e)},t.prototype.ushln=function(e){return this.clone().iushln(e)},t.prototype.shrn=function(e){return this.clone().ishrn(e)},t.prototype.ushrn=function(e){return this.clone().iushrn(e)},t.prototype.testn=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26,u=1<<o;if(this.length<=l)return!1;var h=this.words[l];return!!(h&u)},t.prototype.imaskn=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(o!==0&&l++,this.length=Math.min(l,this.length),o!==0){var u=67108863^67108863>>>o<<o;this.words[this.length-1]&=u}return this._strip()},t.prototype.maskn=function(e){return this.clone().imaskn(e)},t.prototype.iaddn=function(e){return n(typeof e=="number"),n(e<67108864),e<0?this.isubn(-e):this.negative!==0?this.length===1&&(this.words[0]|0)<=e?(this.words[0]=e-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},t.prototype._iaddn=function(e){this.words[0]+=e;for(var o=0;o<this.length&&this.words[o]>=67108864;o++)this.words[o]-=67108864,o===this.length-1?this.words[o+1]=1:this.words[o+1]++;return this.length=Math.max(this.length,o+1),this},t.prototype.isubn=function(e){if(n(typeof e=="number"),n(e<67108864),e<0)return this.iaddn(-e);if(this.negative!==0)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var o=0;o<this.length&&this.words[o]<0;o++)this.words[o]+=67108864,this.words[o+1]-=1;return this._strip()},t.prototype.addn=function(e){return this.clone().iaddn(e)},t.prototype.subn=function(e){return this.clone().isubn(e)},t.prototype.iabs=function(){return this.negative=0,this},t.prototype.abs=function(){return this.clone().iabs()},t.prototype._ishlnsubmul=function(e,o,l){var u=e.length+l,h;this._expand(u);var g,k=0;for(h=0;h<e.length;h++){g=(this.words[h+l]|0)+k;var p=(e.words[h]|0)*o;g-=p&67108863,k=(g>>26)-(p/67108864|0),this.words[h+l]=g&67108863}for(;h<this.length-l;h++)g=(this.words[h+l]|0)+k,k=g>>26,this.words[h+l]=g&67108863;if(k===0)return this._strip();for(n(k===-1),k=0,h=0;h<this.length;h++)g=-(this.words[h]|0)+k,k=g>>26,this.words[h]=g&67108863;return this.negative=1,this._strip()},t.prototype._wordDiv=function(e,o){var l=this.length-e.length,u=this.clone(),h=e,g=h.words[h.length-1]|0,k=this._countBits(g);l=26-k,l!==0&&(h=h.ushln(l),u.iushln(l),g=h.words[h.length-1]|0);var p=u.length-h.length,a;if(o!=="mod"){a=new t(null),a.length=p+1,a.words=new Array(a.length);for(var y=0;y<a.length;y++)a.words[y]=0}var E=u.clone()._ishlnsubmul(h,1,p);E.negative===0&&(u=E,a&&(a.words[p]=1));for(var R=p-1;R>=0;R--){var T=(u.words[h.length+R]|0)*67108864+(u.words[h.length+R-1]|0);for(T=Math.min(T/g|0,67108863),u._ishlnsubmul(h,T,R);u.negative!==0;)T--,u.negative=0,u._ishlnsubmul(h,1,R),u.isZero()||(u.negative^=1);a&&(a.words[R]=T)}return a&&a._strip(),u._strip(),o!=="div"&&l!==0&&u.iushrn(l),{div:a||null,mod:u}},t.prototype.divmod=function(e,o,l){if(n(!e.isZero()),this.isZero())return{div:new t(0),mod:new t(0)};var u,h,g;return this.negative!==0&&e.negative===0?(g=this.neg().divmod(e,o),o!=="mod"&&(u=g.div.neg()),o!=="div"&&(h=g.mod.neg(),l&&h.negative!==0&&h.iadd(e)),{div:u,mod:h}):this.negative===0&&e.negative!==0?(g=this.divmod(e.neg(),o),o!=="mod"&&(u=g.div.neg()),{div:u,mod:g.mod}):(this.negative&e.negative)!==0?(g=this.neg().divmod(e.neg(),o),o!=="div"&&(h=g.mod.neg(),l&&h.negative!==0&&h.isub(e)),{div:g.div,mod:h}):e.length>this.length||this.cmp(e)<0?{div:new t(0),mod:this}:e.length===1?o==="div"?{div:this.divn(e.words[0]),mod:null}:o==="mod"?{div:null,mod:new t(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new t(this.modrn(e.words[0]))}:this._wordDiv(e,o)},t.prototype.div=function(e){return this.divmod(e,"div",!1).div},t.prototype.mod=function(e){return this.divmod(e,"mod",!1).mod},t.prototype.umod=function(e){return this.divmod(e,"mod",!0).mod},t.prototype.divRound=function(e){var o=this.divmod(e);if(o.mod.isZero())return o.div;var l=o.div.negative!==0?o.mod.isub(e):o.mod,u=e.ushrn(1),h=e.andln(1),g=l.cmp(u);return g<0||h===1&&g===0?o.div:o.div.negative!==0?o.div.isubn(1):o.div.iaddn(1)},t.prototype.modrn=function(e){var o=e<0;o&&(e=-e),n(e<=67108863);for(var l=(1<<26)%e,u=0,h=this.length-1;h>=0;h--)u=(l*u+(this.words[h]|0))%e;return o?-u:u},t.prototype.modn=function(e){return this.modrn(e)},t.prototype.idivn=function(e){var o=e<0;o&&(e=-e),n(e<=67108863);for(var l=0,u=this.length-1;u>=0;u--){var h=(this.words[u]|0)+l*67108864;this.words[u]=h/e|0,l=h%e}return this._strip(),o?this.ineg():this},t.prototype.divn=function(e){return this.clone().idivn(e)},t.prototype.egcd=function(e){n(e.negative===0),n(!e.isZero());var o=this,l=e.clone();o.negative!==0?o=o.umod(e):o=o.clone();for(var u=new t(1),h=new t(0),g=new t(0),k=new t(1),p=0;o.isEven()&&l.isEven();)o.iushrn(1),l.iushrn(1),++p;for(var a=l.clone(),y=o.clone();!o.isZero();){for(var E=0,R=1;(o.words[0]&R)===0&&E<26;++E,R<<=1);if(E>0)for(o.iushrn(E);E-- >0;)(u.isOdd()||h.isOdd())&&(u.iadd(a),h.isub(y)),u.iushrn(1),h.iushrn(1);for(var T=0,U=1;(l.words[0]&U)===0&&T<26;++T,U<<=1);if(T>0)for(l.iushrn(T);T-- >0;)(g.isOdd()||k.isOdd())&&(g.iadd(a),k.isub(y)),g.iushrn(1),k.iushrn(1);o.cmp(l)>=0?(o.isub(l),u.isub(g),h.isub(k)):(l.isub(o),g.isub(u),k.isub(h))}return{a:g,b:k,gcd:l.iushln(p)}},t.prototype._invmp=function(e){n(e.negative===0),n(!e.isZero());var o=this,l=e.clone();o.negative!==0?o=o.umod(e):o=o.clone();for(var u=new t(1),h=new t(0),g=l.clone();o.cmpn(1)>0&&l.cmpn(1)>0;){for(var k=0,p=1;(o.words[0]&p)===0&&k<26;++k,p<<=1);if(k>0)for(o.iushrn(k);k-- >0;)u.isOdd()&&u.iadd(g),u.iushrn(1);for(var a=0,y=1;(l.words[0]&y)===0&&a<26;++a,y<<=1);if(a>0)for(l.iushrn(a);a-- >0;)h.isOdd()&&h.iadd(g),h.iushrn(1);o.cmp(l)>=0?(o.isub(l),u.isub(h)):(l.isub(o),h.isub(u))}var E;return o.cmpn(1)===0?E=u:E=h,E.cmpn(0)<0&&E.iadd(e),E},t.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var o=this.clone(),l=e.clone();o.negative=0,l.negative=0;for(var u=0;o.isEven()&&l.isEven();u++)o.iushrn(1),l.iushrn(1);do{for(;o.isEven();)o.iushrn(1);for(;l.isEven();)l.iushrn(1);var h=o.cmp(l);if(h<0){var g=o;o=l,l=g}else if(h===0||l.cmpn(1)===0)break;o.isub(l)}while(!0);return l.iushln(u)},t.prototype.invm=function(e){return this.egcd(e).a.umod(e)},t.prototype.isEven=function(){return(this.words[0]&1)===0},t.prototype.isOdd=function(){return(this.words[0]&1)===1},t.prototype.andln=function(e){return this.words[0]&e},t.prototype.bincn=function(e){n(typeof e=="number");var o=e%26,l=(e-o)/26,u=1<<o;if(this.length<=l)return this._expand(l+1),this.words[l]|=u,this;for(var h=u,g=l;h!==0&&g<this.length;g++){var k=this.words[g]|0;k+=h,h=k>>>26,k&=67108863,this.words[g]=k}return h!==0&&(this.words[g]=h,this.length++),this},t.prototype.isZero=function(){return this.length===1&&this.words[0]===0},t.prototype.cmpn=function(e){var o=e<0;if(this.negative!==0&&!o)return-1;if(this.negative===0&&o)return 1;this._strip();var l;if(this.length>1)l=1;else{o&&(e=-e),n(e<=67108863,"Number is too big");var u=this.words[0]|0;l=u===e?0:u<e?-1:1}return this.negative!==0?-l|0:l},t.prototype.cmp=function(e){if(this.negative!==0&&e.negative===0)return-1;if(this.negative===0&&e.negative!==0)return 1;var o=this.ucmp(e);return this.negative!==0?-o|0:o},t.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var o=0,l=this.length-1;l>=0;l--){var u=this.words[l]|0,h=e.words[l]|0;if(u!==h){u<h?o=-1:u>h&&(o=1);break}}return o},t.prototype.gtn=function(e){return this.cmpn(e)===1},t.prototype.gt=function(e){return this.cmp(e)===1},t.prototype.gten=function(e){return this.cmpn(e)>=0},t.prototype.gte=function(e){return this.cmp(e)>=0},t.prototype.ltn=function(e){return this.cmpn(e)===-1},t.prototype.lt=function(e){return this.cmp(e)===-1},t.prototype.lten=function(e){return this.cmpn(e)<=0},t.prototype.lte=function(e){return this.cmp(e)<=0},t.prototype.eqn=function(e){return this.cmpn(e)===0},t.prototype.eq=function(e){return this.cmp(e)===0},t.red=function(e){return new P(e)},t.prototype.toRed=function(e){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),e.convertTo(this)._forceRed(e)},t.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},t.prototype._forceRed=function(e){return this.red=e,this},t.prototype.forceRed=function(e){return n(!this.red,"Already a number in reduction context"),this._forceRed(e)},t.prototype.redAdd=function(e){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},t.prototype.redIAdd=function(e){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},t.prototype.redSub=function(e){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},t.prototype.redISub=function(e){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},t.prototype.redShl=function(e){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},t.prototype.redMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},t.prototype.redIMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},t.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},t.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},t.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},t.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},t.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},t.prototype.redPow=function(e){return n(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var ee={k256:null,p224:null,p192:null,p25519:null};function $(c,e){this.name=c,this.p=new t(e,16),this.n=this.p.bitLength(),this.k=new t(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}$.prototype._tmp=function(){var e=new t(null);return e.words=new Array(Math.ceil(this.n/13)),e},$.prototype.ireduce=function(e){var o=e,l;do this.split(o,this.tmp),o=this.imulK(o),o=o.iadd(this.tmp),l=o.bitLength();while(l>this.n);var u=l<this.n?-1:o.ucmp(this.p);return u===0?(o.words[0]=0,o.length=1):u>0?o.isub(this.p):o.strip!==void 0?o.strip():o._strip(),o},$.prototype.split=function(e,o){e.iushrn(this.n,0,o)},$.prototype.imulK=function(e){return e.imul(this.k)};function X(){$.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(X,$),X.prototype.split=function(e,o){for(var l=4194303,u=Math.min(e.length,9),h=0;h<u;h++)o.words[h]=e.words[h];if(o.length=u,e.length<=9){e.words[0]=0,e.length=1;return}var g=e.words[9];for(o.words[o.length++]=g&l,h=10;h<e.length;h++){var k=e.words[h]|0;e.words[h-10]=(k&l)<<4|g>>>22,g=k}g>>>=22,e.words[h-10]=g,g===0&&e.length>10?e.length-=10:e.length-=9},X.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var o=0,l=0;l<e.length;l++){var u=e.words[l]|0;o+=u*977,e.words[l]=o&67108863,o=u*64+(o/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function m(){$.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(m,$);function b(){$.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(b,$);function _(){$.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(_,$),_.prototype.imulK=function(e){for(var o=0,l=0;l<e.length;l++){var u=(e.words[l]|0)*19+o,h=u&67108863;u>>>=26,e.words[l]=h,o=u}return o!==0&&(e.words[e.length++]=o),e},t._prime=function(e){if(ee[e])return ee[e];var o;if(e==="k256")o=new X;else if(e==="p224")o=new m;else if(e==="p192")o=new b;else if(e==="p25519")o=new _;else throw new Error("Unknown prime "+e);return ee[e]=o,o};function P(c){if(typeof c=="string"){var e=t._prime(c);this.m=e.p,this.prime=e}else n(c.gtn(1),"modulus must be greater than 1"),this.m=c,this.prime=null}P.prototype._verify1=function(e){n(e.negative===0,"red works only with positives"),n(e.red,"red works only with red numbers")},P.prototype._verify2=function(e,o){n((e.negative|o.negative)===0,"red works only with positives"),n(e.red&&e.red===o.red,"red works only with red numbers")},P.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(w(e,e.umod(this.m)._forceRed(this)),e)},P.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},P.prototype.add=function(e,o){this._verify2(e,o);var l=e.add(o);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},P.prototype.iadd=function(e,o){this._verify2(e,o);var l=e.iadd(o);return l.cmp(this.m)>=0&&l.isub(this.m),l},P.prototype.sub=function(e,o){this._verify2(e,o);var l=e.sub(o);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},P.prototype.isub=function(e,o){this._verify2(e,o);var l=e.isub(o);return l.cmpn(0)<0&&l.iadd(this.m),l},P.prototype.shl=function(e,o){return this._verify1(e),this.imod(e.ushln(o))},P.prototype.imul=function(e,o){return this._verify2(e,o),this.imod(e.imul(o))},P.prototype.mul=function(e,o){return this._verify2(e,o),this.imod(e.mul(o))},P.prototype.isqr=function(e){return this.imul(e,e.clone())},P.prototype.sqr=function(e){return this.mul(e,e)},P.prototype.sqrt=function(e){if(e.isZero())return e.clone();var o=this.m.andln(3);if(n(o%2===1),o===3){var l=this.m.add(new t(1)).iushrn(2);return this.pow(e,l)}for(var u=this.m.subn(1),h=0;!u.isZero()&&u.andln(1)===0;)h++,u.iushrn(1);n(!u.isZero());var g=new t(1).toRed(this),k=g.redNeg(),p=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new t(2*a*a).toRed(this);this.pow(a,p).cmp(k)!==0;)a.redIAdd(k);for(var y=this.pow(a,u),E=this.pow(e,u.addn(1).iushrn(1)),R=this.pow(e,u),T=h;R.cmp(g)!==0;){for(var U=R,V=0;U.cmp(g)!==0;V++)U=U.redSqr();n(V<T);var J=this.pow(y,new t(1).iushln(T-V-1));E=E.redMul(J),y=J.redSqr(),R=R.redMul(y),T=V}return E},P.prototype.invm=function(e){var o=e._invmp(this.m);return o.negative!==0?(o.negative=0,this.imod(o).redNeg()):this.imod(o)},P.prototype.pow=function(e,o){if(o.isZero())return new t(1).toRed(this);if(o.cmpn(1)===0)return e.clone();var l=4,u=new Array(1<<l);u[0]=new t(1).toRed(this),u[1]=e;for(var h=2;h<u.length;h++)u[h]=this.mul(u[h-1],e);var g=u[0],k=0,p=0,a=o.bitLength()%26;for(a===0&&(a=26),h=o.length-1;h>=0;h--){for(var y=o.words[h],E=a-1;E>=0;E--){var R=y>>E&1;if(g!==u[0]&&(g=this.sqr(g)),R===0&&k===0){p=0;continue}k<<=1,k|=R,p++,!(p!==l&&(h!==0||E!==0))&&(g=this.mul(g,u[k]),p=0,k=0)}a=26}return g},P.prototype.convertTo=function(e){var o=e.umod(this.m);return o===e?o.clone():o},P.prototype.convertFrom=function(e){var o=e.clone();return o.red=null,o},t.mont=function(e){return new S(e)};function S(c){P.call(this,c),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new t(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}s(S,P),S.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},S.prototype.convertFrom=function(e){var o=this.imod(e.mul(this.rinv));return o.red=null,o},S.prototype.imul=function(e,o){if(e.isZero()||o.isZero())return e.words[0]=0,e.length=1,e;var l=e.imul(o),u=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(u).iushrn(this.shift),g=h;return h.cmp(this.m)>=0?g=h.isub(this.m):h.cmpn(0)<0&&(g=h.iadd(this.m)),g._forceRed(this)},S.prototype.mul=function(e,o){if(e.isZero()||o.isZero())return new t(0)._forceRed(this);var l=e.mul(o),u=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(u).iushrn(this.shift),g=h;return h.cmp(this.m)>=0?g=h.isub(this.m):h.cmpn(0)<0&&(g=h.iadd(this.m)),g._forceRed(this)},S.prototype.invm=function(e){var o=this.imod(e._invmp(this.m).mul(this.r2));return o._forceRed(this)}})(typeof vi>"u"||vi,dr)});var Ln={};Lr(Ln,{CetusLeverageSDK:()=>yt,default:()=>xn,leverage_mainnet:()=>ni});module.exports=Ir(Ln);var wr=require("@cetusprotocol/common-sdk");var _t=require("@cetusprotocol/common-sdk");var ni={full_rpc_url:_t.FullRpcUrlMainnet,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:_t.DefaultProviders,leverage:{package_id:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",published_at:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",version:0,config:{global_config_id:"0xf6c5da03798ff33dd4036aa1fe8b8321f8d41b279247abb5c01254e12b05c19b",markets_table_id:"0x2720d2dfe2b50f700edb69dabd8b51d611961521682a935f09c01d191000f8d0"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{lendingMarket:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",ownerCapId:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",ownerCapId:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",isHidden:!0}],lendingMarketId:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lendingMarketType:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",apiUrl:"https://d10td5ybgrf39v.cloudfront.net"}}};var Qi=require("@suilend/sdk/client"),re=require("@suilend/sdk");var Or=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,oi=Math.ceil,Ge=Math.floor,$e="[BigNumber Error] ",Fi=$e+"Number primitive has more than 15 significant digits: ",Xe=1e14,G=14,si=9007199254740991,ai=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],at=1e7,Fe=1e9;function qi(i){var r,n,s,t=I.prototype={constructor:I,toString:null,valueOf:null},f=new I(1),d=20,v=4,M=-7,w=21,A=-1e7,x=1e7,C=!1,L=1,B=0,D={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},Z="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function I(m,b){var _,P,S,c,e,o,l,u,h=this;if(!(h instanceof I))return new I(m,b);if(b==null){if(m&&m._isBigNumber===!0){h.s=m.s,!m.c||m.e>x?h.c=h.e=null:m.e<A?h.c=[h.e=0]:(h.e=m.e,h.c=m.c.slice());return}if((o=typeof m=="number")&&m*0==0){if(h.s=1/m<0?(m=-m,-1):1,m===~~m){for(c=0,e=m;e>=10;e/=10,c++);c>x?h.c=h.e=null:(h.e=c,h.c=[m]);return}u=String(m)}else{if(!Or.test(u=String(m)))return s(h,u,o);h.s=u.charCodeAt(0)==45?(u=u.slice(1),-1):1}(c=u.indexOf("."))>-1&&(u=u.replace(".","")),(e=u.search(/e/i))>0?(c<0&&(c=e),c+=+u.slice(e+1),u=u.substring(0,e)):c<0&&(c=u.length)}else{if(ne(b,2,Z.length,"Base"),b==10&&j)return h=new I(m),$(h,d+h.e+1,v);if(u=String(m),o=typeof m=="number"){if(m*0!=0)return s(h,u,o,b);if(h.s=1/m<0?(u=u.slice(1),-1):1,I.DEBUG&&u.replace(/^0\.0*|\./,"").length>15)throw Error(Fi+m)}else h.s=u.charCodeAt(0)===45?(u=u.slice(1),-1):1;for(_=Z.slice(0,b),c=e=0,l=u.length;e<l;e++)if(_.indexOf(P=u.charAt(e))<0){if(P=="."){if(e>c){c=l;continue}}else if(!S&&(u==u.toUpperCase()&&(u=u.toLowerCase())||u==u.toLowerCase()&&(u=u.toUpperCase()))){S=!0,e=-1,c=0;continue}return s(h,String(m),o,b)}o=!1,u=n(u,b,10,h.s),(c=u.indexOf("."))>-1?u=u.replace(".",""):c=u.length}for(e=0;u.charCodeAt(e)===48;e++);for(l=u.length;u.charCodeAt(--l)===48;);if(u=u.slice(e,++l)){if(l-=e,o&&I.DEBUG&&l>15&&(m>si||m!==Ge(m)))throw Error(Fi+h.s*m);if((c=c-e-1)>x)h.c=h.e=null;else if(c<A)h.c=[h.e=0];else{if(h.e=c,h.c=[],e=(c+1)%G,c<0&&(e+=G),e<l){for(e&&h.c.push(+u.slice(0,e)),l-=G;e<l;)h.c.push(+u.slice(e,e+=G));e=G-(u=u.slice(e)).length}else e-=l;for(;e--;u+="0");h.c.push(+u)}}else h.c=[h.e=0]}I.clone=qi,I.ROUND_UP=0,I.ROUND_DOWN=1,I.ROUND_CEIL=2,I.ROUND_FLOOR=3,I.ROUND_HALF_UP=4,I.ROUND_HALF_DOWN=5,I.ROUND_HALF_EVEN=6,I.ROUND_HALF_CEIL=7,I.ROUND_HALF_FLOOR=8,I.EUCLID=9,I.config=I.set=function(m){var b,_;if(m!=null)if(typeof m=="object"){if(m.hasOwnProperty(b="DECIMAL_PLACES")&&(_=m[b],ne(_,0,Fe,b),d=_),m.hasOwnProperty(b="ROUNDING_MODE")&&(_=m[b],ne(_,0,8,b),v=_),m.hasOwnProperty(b="EXPONENTIAL_AT")&&(_=m[b],_&&_.pop?(ne(_[0],-Fe,0,b),ne(_[1],0,Fe,b),M=_[0],w=_[1]):(ne(_,-Fe,Fe,b),M=-(w=_<0?-_:_))),m.hasOwnProperty(b="RANGE"))if(_=m[b],_&&_.pop)ne(_[0],-Fe,-1,b),ne(_[1],1,Fe,b),A=_[0],x=_[1];else if(ne(_,-Fe,Fe,b),_)A=-(x=_<0?-_:_);else throw Error($e+b+" cannot be zero: "+_);if(m.hasOwnProperty(b="CRYPTO"))if(_=m[b],_===!!_)if(_)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))C=_;else throw C=!_,Error($e+"crypto unavailable");else C=_;else throw Error($e+b+" not true or false: "+_);if(m.hasOwnProperty(b="MODULO_MODE")&&(_=m[b],ne(_,0,9,b),L=_),m.hasOwnProperty(b="POW_PRECISION")&&(_=m[b],ne(_,0,Fe,b),B=_),m.hasOwnProperty(b="FORMAT"))if(_=m[b],typeof _=="object")D=_;else throw Error($e+b+" not an object: "+_);if(m.hasOwnProperty(b="ALPHABET"))if(_=m[b],typeof _=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(_))j=_.slice(0,10)=="0123456789",Z=_;else throw Error($e+b+" invalid: "+_)}else throw Error($e+"Object expected: "+m);return{DECIMAL_PLACES:d,ROUNDING_MODE:v,EXPONENTIAL_AT:[M,w],RANGE:[A,x],CRYPTO:C,MODULO_MODE:L,POW_PRECISION:B,FORMAT:D,ALPHABET:Z}},I.isBigNumber=function(m){if(!m||m._isBigNumber!==!0)return!1;if(!I.DEBUG)return!0;var b,_,P=m.c,S=m.e,c=m.s;e:if({}.toString.call(P)=="[object Array]"){if((c===1||c===-1)&&S>=-Fe&&S<=Fe&&S===Ge(S)){if(P[0]===0){if(S===0&&P.length===1)return!0;break e}if(b=(S+1)%G,b<1&&(b+=G),String(P[0]).length==b){for(b=0;b<P.length;b++)if(_=P[b],_<0||_>=Xe||_!==Ge(_))break e;if(_!==0)return!0}}}else if(P===null&&S===null&&(c===null||c===1||c===-1))return!0;throw Error($e+"Invalid BigNumber: "+m)},I.maximum=I.max=function(){return q(arguments,-1)},I.minimum=I.min=function(){return q(arguments,1)},I.random=(function(){var m=9007199254740992,b=Math.random()*m&2097151?function(){return Ge(Math.random()*m)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(_){var P,S,c,e,o,l=0,u=[],h=new I(f);if(_==null?_=d:ne(_,0,Fe),e=oi(_/G),C)if(crypto.getRandomValues){for(P=crypto.getRandomValues(new Uint32Array(e*=2));l<e;)o=P[l]*131072+(P[l+1]>>>11),o>=9e15?(S=crypto.getRandomValues(new Uint32Array(2)),P[l]=S[0],P[l+1]=S[1]):(u.push(o%1e14),l+=2);l=e/2}else if(crypto.randomBytes){for(P=crypto.randomBytes(e*=7);l<e;)o=(P[l]&31)*281474976710656+P[l+1]*1099511627776+P[l+2]*4294967296+P[l+3]*16777216+(P[l+4]<<16)+(P[l+5]<<8)+P[l+6],o>=9e15?crypto.randomBytes(7).copy(P,l):(u.push(o%1e14),l+=7);l=e/7}else throw C=!1,Error($e+"crypto unavailable");if(!C)for(;l<e;)o=b(),o<9e15&&(u[l++]=o%1e14);for(e=u[--l],_%=G,e&&_&&(o=ai[G-_],u[l]=Ge(e/o)*o);u[l]===0;u.pop(),l--);if(l<0)u=[c=0];else{for(c=-1;u[0]===0;u.splice(0,1),c-=G);for(l=1,o=u[0];o>=10;o/=10,l++);l<G&&(c-=G-l)}return h.e=c,h.c=u,h}})(),I.sum=function(){for(var m=1,b=arguments,_=new I(b[0]);m<b.length;)_=_.plus(b[m++]);return _},n=(function(){var m="0123456789";function b(_,P,S,c){for(var e,o=[0],l,u=0,h=_.length;u<h;){for(l=o.length;l--;o[l]*=P);for(o[0]+=c.indexOf(_.charAt(u++)),e=0;e<o.length;e++)o[e]>S-1&&(o[e+1]==null&&(o[e+1]=0),o[e+1]+=o[e]/S|0,o[e]%=S)}return o.reverse()}return function(_,P,S,c,e){var o,l,u,h,g,k,p,a,y=_.indexOf("."),E=d,R=v;for(y>=0&&(h=B,B=0,_=_.replace(".",""),a=new I(P),k=a.pow(_.length-y),B=h,a.c=b(rt(We(k.c),k.e,"0"),10,S,m),a.e=a.c.length),p=b(_,P,S,e?(o=Z,m):(o=m,Z)),u=h=p.length;p[--h]==0;p.pop());if(!p[0])return o.charAt(0);if(y<0?--u:(k.c=p,k.e=u,k.s=c,k=r(k,a,E,R,S),p=k.c,g=k.r,u=k.e),l=u+E+1,y=p[l],h=S/2,g=g||l<0||p[l+1]!=null,g=R<4?(y!=null||g)&&(R==0||R==(k.s<0?3:2)):y>h||y==h&&(R==4||g||R==6&&p[l-1]&1||R==(k.s<0?8:7)),l<1||!p[0])_=g?rt(o.charAt(1),-E,o.charAt(0)):o.charAt(0);else{if(p.length=l,g)for(--S;++p[--l]>S;)p[l]=0,l||(++u,p=[1].concat(p));for(h=p.length;!p[--h];);for(y=0,_="";y<=h;_+=o.charAt(p[y++]));_=rt(_,u,o.charAt(0))}return _}})(),r=(function(){function m(P,S,c){var e,o,l,u,h=0,g=P.length,k=S%at,p=S/at|0;for(P=P.slice();g--;)l=P[g]%at,u=P[g]/at|0,e=p*l+u*k,o=k*l+e%at*at+h,h=(o/c|0)+(e/at|0)+p*u,P[g]=o%c;return h&&(P=[h].concat(P)),P}function b(P,S,c,e){var o,l;if(c!=e)l=c>e?1:-1;else for(o=l=0;o<c;o++)if(P[o]!=S[o]){l=P[o]>S[o]?1:-1;break}return l}function _(P,S,c,e){for(var o=0;c--;)P[c]-=o,o=P[c]<S[c]?1:0,P[c]=o*e+P[c]-S[c];for(;!P[0]&&P.length>1;P.splice(0,1));}return function(P,S,c,e,o){var l,u,h,g,k,p,a,y,E,R,T,U,V,J,He,Q,te,ze=P.s==S.s?1:-1,Y=P.c,W=S.c;if(!Y||!Y[0]||!W||!W[0])return new I(!P.s||!S.s||(Y?W&&Y[0]==W[0]:!W)?NaN:Y&&Y[0]==0||!W?ze*0:ze/0);for(y=new I(ze),E=y.c=[],u=P.e-S.e,ze=c+u+1,o||(o=Xe,u=Ve(P.e/G)-Ve(S.e/G),ze=ze/G|0),h=0;W[h]==(Y[h]||0);h++);if(W[h]>(Y[h]||0)&&u--,ze<0)E.push(1),g=!0;else{for(J=Y.length,Q=W.length,h=0,ze+=2,k=Ge(o/(W[0]+1)),k>1&&(W=m(W,k,o),Y=m(Y,k,o),Q=W.length,J=Y.length),V=Q,R=Y.slice(0,Q),T=R.length;T<Q;R[T++]=0);te=W.slice(),te=[0].concat(te),He=W[0],W[1]>=o/2&&He++;do{if(k=0,l=b(W,R,Q,T),l<0){if(U=R[0],Q!=T&&(U=U*o+(R[1]||0)),k=Ge(U/He),k>1)for(k>=o&&(k=o-1),p=m(W,k,o),a=p.length,T=R.length;b(p,R,a,T)==1;)k--,_(p,Q<a?te:W,a,o),a=p.length,l=1;else k==0&&(l=k=1),p=W.slice(),a=p.length;if(a<T&&(p=[0].concat(p)),_(R,p,T,o),T=R.length,l==-1)for(;b(W,R,Q,T)<1;)k++,_(R,Q<T?te:W,T,o),T=R.length}else l===0&&(k++,R=[0]);E[h++]=k,R[0]?R[T++]=Y[V]||0:(R=[Y[V]],T=1)}while((V++<J||R[0]!=null)&&ze--);g=R[0]!=null,E[0]||E.splice(0,1)}if(o==Xe){for(h=1,ze=E[0];ze>=10;ze/=10,h++);$(y,c+(y.e=h+u*G-1)+1,e,g)}else y.e=u,y.r=+g;return y}})();function F(m,b,_,P){var S,c,e,o,l;if(_==null?_=v:ne(_,0,8),!m.c)return m.toString();if(S=m.c[0],e=m.e,b==null)l=We(m.c),l=P==1||P==2&&(e<=M||e>=w)?At(l,e):rt(l,e,"0");else if(m=$(new I(m),b,_),c=m.e,l=We(m.c),o=l.length,P==1||P==2&&(b<=c||c<=M)){for(;o<b;l+="0",o++);l=At(l,c)}else if(b-=e+(P===2&&c>e),l=rt(l,c,"0"),c+1>o){if(--b>0)for(l+=".";b--;l+="0");}else if(b+=c-o,b>0)for(c+1==o&&(l+=".");b--;l+="0");return m.s<0&&S?"-"+l:l}function q(m,b){for(var _,P,S=1,c=new I(m[0]);S<m.length;S++)P=new I(m[S]),(!P.s||(_=ct(c,P))===b||_===0&&c.s===b)&&(c=P);return c}function ee(m,b,_){for(var P=1,S=b.length;!b[--S];b.pop());for(S=b[0];S>=10;S/=10,P++);return(_=P+_*G-1)>x?m.c=m.e=null:_<A?m.c=[m.e=0]:(m.e=_,m.c=b),m}s=(function(){var m=/^(-?)0([xbo])(?=\w[\w.]*$)/i,b=/^([^.]+)\.$/,_=/^\.([^.]+)$/,P=/^-?(Infinity|NaN)$/,S=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(c,e,o,l){var u,h=o?e:e.replace(S,"");if(P.test(h))c.s=isNaN(h)?null:h<0?-1:1;else{if(!o&&(h=h.replace(m,function(g,k,p){return u=(p=p.toLowerCase())=="x"?16:p=="b"?2:8,!l||l==u?k:g}),l&&(u=l,h=h.replace(b,"$1").replace(_,"0.$1")),e!=h))return new I(h,u);if(I.DEBUG)throw Error($e+"Not a"+(l?" base "+l:"")+" number: "+e);c.s=null}c.c=c.e=null}})();function $(m,b,_,P){var S,c,e,o,l,u,h,g=m.c,k=ai;if(g){e:{for(S=1,o=g[0];o>=10;o/=10,S++);if(c=b-S,c<0)c+=G,e=b,l=g[u=0],h=Ge(l/k[S-e-1]%10);else if(u=oi((c+1)/G),u>=g.length)if(P){for(;g.length<=u;g.push(0));l=h=0,S=1,c%=G,e=c-G+1}else break e;else{for(l=o=g[u],S=1;o>=10;o/=10,S++);c%=G,e=c-G+S,h=e<0?0:Ge(l/k[S-e-1]%10)}if(P=P||b<0||g[u+1]!=null||(e<0?l:l%k[S-e-1]),P=_<4?(h||P)&&(_==0||_==(m.s<0?3:2)):h>5||h==5&&(_==4||P||_==6&&(c>0?e>0?l/k[S-e]:0:g[u-1])%10&1||_==(m.s<0?8:7)),b<1||!g[0])return g.length=0,P?(b-=m.e+1,g[0]=k[(G-b%G)%G],m.e=-b||0):g[0]=m.e=0,m;if(c==0?(g.length=u,o=1,u--):(g.length=u+1,o=k[G-c],g[u]=e>0?Ge(l/k[S-e]%k[e])*o:0),P)for(;;)if(u==0){for(c=1,e=g[0];e>=10;e/=10,c++);for(e=g[0]+=o,o=1;e>=10;e/=10,o++);c!=o&&(m.e++,g[0]==Xe&&(g[0]=1));break}else{if(g[u]+=o,g[u]!=Xe)break;g[u--]=0,o=1}for(c=g.length;g[--c]===0;g.pop());}m.e>x?m.c=m.e=null:m.e<A&&(m.c=[m.e=0])}return m}function X(m){var b,_=m.e;return _===null?m.toString():(b=We(m.c),b=_<=M||_>=w?At(b,_):rt(b,_,"0"),m.s<0?"-"+b:b)}return t.absoluteValue=t.abs=function(){var m=new I(this);return m.s<0&&(m.s=1),m},t.comparedTo=function(m,b){return ct(this,new I(m,b))},t.decimalPlaces=t.dp=function(m,b){var _,P,S,c=this;if(m!=null)return ne(m,0,Fe),b==null?b=v:ne(b,0,8),$(new I(c),m+c.e+1,b);if(!(_=c.c))return null;if(P=((S=_.length-1)-Ve(this.e/G))*G,S=_[S])for(;S%10==0;S/=10,P--);return P<0&&(P=0),P},t.dividedBy=t.div=function(m,b){return r(this,new I(m,b),d,v)},t.dividedToIntegerBy=t.idiv=function(m,b){return r(this,new I(m,b),0,1)},t.exponentiatedBy=t.pow=function(m,b){var _,P,S,c,e,o,l,u,h,g=this;if(m=new I(m),m.c&&!m.isInteger())throw Error($e+"Exponent not an integer: "+X(m));if(b!=null&&(b=new I(b)),o=m.e>14,!g.c||!g.c[0]||g.c[0]==1&&!g.e&&g.c.length==1||!m.c||!m.c[0])return h=new I(Math.pow(+X(g),o?m.s*(2-kt(m)):+X(m))),b?h.mod(b):h;if(l=m.s<0,b){if(b.c?!b.c[0]:!b.s)return new I(NaN);P=!l&&g.isInteger()&&b.isInteger(),P&&(g=g.mod(b))}else{if(m.e>9&&(g.e>0||g.e<-1||(g.e==0?g.c[0]>1||o&&g.c[1]>=24e7:g.c[0]<8e13||o&&g.c[0]<=9999975e7)))return c=g.s<0&&kt(m)?-0:0,g.e>-1&&(c=1/c),new I(l?1/c:c);B&&(c=oi(B/G+2))}for(o?(_=new I(.5),l&&(m.s=1),u=kt(m)):(S=Math.abs(+X(m)),u=S%2),h=new I(f);;){if(u){if(h=h.times(g),!h.c)break;c?h.c.length>c&&(h.c.length=c):P&&(h=h.mod(b))}if(S){if(S=Ge(S/2),S===0)break;u=S%2}else if(m=m.times(_),$(m,m.e+1,1),m.e>14)u=kt(m);else{if(S=+X(m),S===0)break;u=S%2}g=g.times(g),c?g.c&&g.c.length>c&&(g.c.length=c):P&&(g=g.mod(b))}return P?h:(l&&(h=f.div(h)),b?h.mod(b):c?$(h,B,v,e):h)},t.integerValue=function(m){var b=new I(this);return m==null?m=v:ne(m,0,8),$(b,b.e+1,m)},t.isEqualTo=t.eq=function(m,b){return ct(this,new I(m,b))===0},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(m,b){return ct(this,new I(m,b))>0},t.isGreaterThanOrEqualTo=t.gte=function(m,b){return(b=ct(this,new I(m,b)))===1||b===0},t.isInteger=function(){return!!this.c&&Ve(this.e/G)>this.c.length-2},t.isLessThan=t.lt=function(m,b){return ct(this,new I(m,b))<0},t.isLessThanOrEqualTo=t.lte=function(m,b){return(b=ct(this,new I(m,b)))===-1||b===0},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return this.s>0},t.isZero=function(){return!!this.c&&this.c[0]==0},t.minus=function(m,b){var _,P,S,c,e=this,o=e.s;if(m=new I(m,b),b=m.s,!o||!b)return new I(NaN);if(o!=b)return m.s=-b,e.plus(m);var l=e.e/G,u=m.e/G,h=e.c,g=m.c;if(!l||!u){if(!h||!g)return h?(m.s=-b,m):new I(g?e:NaN);if(!h[0]||!g[0])return g[0]?(m.s=-b,m):new I(h[0]?e:v==3?-0:0)}if(l=Ve(l),u=Ve(u),h=h.slice(),o=l-u){for((c=o<0)?(o=-o,S=h):(u=l,S=g),S.reverse(),b=o;b--;S.push(0));S.reverse()}else for(P=(c=(o=h.length)<(b=g.length))?o:b,o=b=0;b<P;b++)if(h[b]!=g[b]){c=h[b]<g[b];break}if(c&&(S=h,h=g,g=S,m.s=-m.s),b=(P=g.length)-(_=h.length),b>0)for(;b--;h[_++]=0);for(b=Xe-1;P>o;){if(h[--P]<g[P]){for(_=P;_&&!h[--_];h[_]=b);--h[_],h[P]+=Xe}h[P]-=g[P]}for(;h[0]==0;h.splice(0,1),--u);return h[0]?ee(m,h,u):(m.s=v==3?-1:1,m.c=[m.e=0],m)},t.modulo=t.mod=function(m,b){var _,P,S=this;return m=new I(m,b),!S.c||!m.s||m.c&&!m.c[0]?new I(NaN):!m.c||S.c&&!S.c[0]?new I(S):(L==9?(P=m.s,m.s=1,_=r(S,m,0,3),m.s=P,_.s*=P):_=r(S,m,0,L),m=S.minus(_.times(m)),!m.c[0]&&L==1&&(m.s=S.s),m)},t.multipliedBy=t.times=function(m,b){var _,P,S,c,e,o,l,u,h,g,k,p,a,y,E,R=this,T=R.c,U=(m=new I(m,b)).c;if(!T||!U||!T[0]||!U[0])return!R.s||!m.s||T&&!T[0]&&!U||U&&!U[0]&&!T?m.c=m.e=m.s=null:(m.s*=R.s,!T||!U?m.c=m.e=null:(m.c=[0],m.e=0)),m;for(P=Ve(R.e/G)+Ve(m.e/G),m.s*=R.s,l=T.length,g=U.length,l<g&&(a=T,T=U,U=a,S=l,l=g,g=S),S=l+g,a=[];S--;a.push(0));for(y=Xe,E=at,S=g;--S>=0;){for(_=0,k=U[S]%E,p=U[S]/E|0,e=l,c=S+e;c>S;)u=T[--e]%E,h=T[e]/E|0,o=p*u+h*k,u=k*u+o%E*E+a[c]+_,_=(u/y|0)+(o/E|0)+p*h,a[c--]=u%y;a[c]=_}return _?++P:a.splice(0,1),ee(m,a,P)},t.negated=function(){var m=new I(this);return m.s=-m.s||null,m},t.plus=function(m,b){var _,P=this,S=P.s;if(m=new I(m,b),b=m.s,!S||!b)return new I(NaN);if(S!=b)return m.s=-b,P.minus(m);var c=P.e/G,e=m.e/G,o=P.c,l=m.c;if(!c||!e){if(!o||!l)return new I(S/0);if(!o[0]||!l[0])return l[0]?m:new I(o[0]?P:S*0)}if(c=Ve(c),e=Ve(e),o=o.slice(),S=c-e){for(S>0?(e=c,_=l):(S=-S,_=o),_.reverse();S--;_.push(0));_.reverse()}for(S=o.length,b=l.length,S-b<0&&(_=l,l=o,o=_,b=S),S=0;b;)S=(o[--b]=o[b]+l[b]+S)/Xe|0,o[b]=Xe===o[b]?0:o[b]%Xe;return S&&(o=[S].concat(o),++e),ee(m,o,e)},t.precision=t.sd=function(m,b){var _,P,S,c=this;if(m!=null&&m!==!!m)return ne(m,1,Fe),b==null?b=v:ne(b,0,8),$(new I(c),m,b);if(!(_=c.c))return null;if(S=_.length-1,P=S*G+1,S=_[S]){for(;S%10==0;S/=10,P--);for(S=_[0];S>=10;S/=10,P++);}return m&&c.e+1>P&&(P=c.e+1),P},t.shiftedBy=function(m){return ne(m,-si,si),this.times("1e"+m)},t.squareRoot=t.sqrt=function(){var m,b,_,P,S,c=this,e=c.c,o=c.s,l=c.e,u=d+4,h=new I("0.5");if(o!==1||!e||!e[0])return new I(!o||o<0&&(!e||e[0])?NaN:e?c:1/0);if(o=Math.sqrt(+X(c)),o==0||o==1/0?(b=We(e),(b.length+l)%2==0&&(b+="0"),o=Math.sqrt(+b),l=Ve((l+1)/2)-(l<0||l%2),o==1/0?b="5e"+l:(b=o.toExponential(),b=b.slice(0,b.indexOf("e")+1)+l),_=new I(b)):_=new I(o+""),_.c[0]){for(l=_.e,o=l+u,o<3&&(o=0);;)if(S=_,_=h.times(S.plus(r(c,S,u,1))),We(S.c).slice(0,o)===(b=We(_.c)).slice(0,o))if(_.e<l&&--o,b=b.slice(o-3,o+1),b=="9999"||!P&&b=="4999"){if(!P&&($(S,S.e+d+2,0),S.times(S).eq(c))){_=S;break}u+=4,o+=4,P=1}else{(!+b||!+b.slice(1)&&b.charAt(0)=="5")&&($(_,_.e+d+2,1),m=!_.times(_).eq(c));break}}return $(_,_.e+d+1,v,m)},t.toExponential=function(m,b){return m!=null&&(ne(m,0,Fe),m++),F(this,m,b,1)},t.toFixed=function(m,b){return m!=null&&(ne(m,0,Fe),m=m+this.e+1),F(this,m,b)},t.toFormat=function(m,b,_){var P,S=this;if(_==null)m!=null&&b&&typeof b=="object"?(_=b,b=null):m&&typeof m=="object"?(_=m,m=b=null):_=D;else if(typeof _!="object")throw Error($e+"Argument not an object: "+_);if(P=S.toFixed(m,b),S.c){var c,e=P.split("."),o=+_.groupSize,l=+_.secondaryGroupSize,u=_.groupSeparator||"",h=e[0],g=e[1],k=S.s<0,p=k?h.slice(1):h,a=p.length;if(l&&(c=o,o=l,l=c,a-=c),o>0&&a>0){for(c=a%o||o,h=p.substr(0,c);c<a;c+=o)h+=u+p.substr(c,o);l>0&&(h+=u+p.slice(c)),k&&(h="-"+h)}P=g?h+(_.decimalSeparator||"")+((l=+_.fractionGroupSize)?g.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(_.fractionGroupSeparator||"")):g):h}return(_.prefix||"")+P+(_.suffix||"")},t.toFraction=function(m){var b,_,P,S,c,e,o,l,u,h,g,k,p=this,a=p.c;if(m!=null&&(o=new I(m),!o.isInteger()&&(o.c||o.s!==1)||o.lt(f)))throw Error($e+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+X(o));if(!a)return new I(p);for(b=new I(f),u=_=new I(f),P=l=new I(f),k=We(a),c=b.e=k.length-p.e-1,b.c[0]=ai[(e=c%G)<0?G+e:e],m=!m||o.comparedTo(b)>0?c>0?b:u:o,e=x,x=1/0,o=new I(k),l.c[0]=0;h=r(o,b,0,1),S=_.plus(h.times(P)),S.comparedTo(m)!=1;)_=P,P=S,u=l.plus(h.times(S=u)),l=S,b=o.minus(h.times(S=b)),o=S;return S=r(m.minus(_),P,0,1),l=l.plus(S.times(u)),_=_.plus(S.times(P)),l.s=u.s=p.s,c=c*2,g=r(u,P,c,v).minus(p).abs().comparedTo(r(l,_,c,v).minus(p).abs())<1?[u,P]:[l,_],x=e,g},t.toNumber=function(){return+X(this)},t.toPrecision=function(m,b){return m!=null&&ne(m,1,Fe),F(this,m,b,2)},t.toString=function(m){var b,_=this,P=_.s,S=_.e;return S===null?P?(b="Infinity",P<0&&(b="-"+b)):b="NaN":(m==null?b=S<=M||S>=w?At(We(_.c),S):rt(We(_.c),S,"0"):m===10&&j?(_=$(new I(_),d+S+1,v),b=rt(We(_.c),_.e,"0")):(ne(m,2,Z.length,"Base"),b=n(rt(We(_.c),S,"0"),10,m,P,!0)),P<0&&_.c[0]&&(b="-"+b)),b},t.valueOf=t.toJSON=function(){return X(this)},t._isBigNumber=!0,t[Symbol.toStringTag]="BigNumber",t[Symbol.for("nodejs.util.inspect.custom")]=t.valueOf,i!=null&&I.set(i),I}function Ve(i){var r=i|0;return i>0||i===r?r:r-1}function We(i){for(var r,n,s=1,t=i.length,f=i[0]+"";s<t;){for(r=i[s++]+"",n=G-r.length;n--;r="0"+r);f+=r}for(t=f.length;f.charCodeAt(--t)===48;);return f.slice(0,t+1||1)}function ct(i,r){var n,s,t=i.c,f=r.c,d=i.s,v=r.s,M=i.e,w=r.e;if(!d||!v)return null;if(n=t&&!t[0],s=f&&!f[0],n||s)return n?s?0:-v:d;if(d!=v)return d;if(n=d<0,s=M==w,!t||!f)return s?0:!t^n?1:-1;if(!s)return M>w^n?1:-1;for(v=(M=t.length)<(w=f.length)?M:w,d=0;d<v;d++)if(t[d]!=f[d])return t[d]>f[d]^n?1:-1;return M==w?0:M>w^n?1:-1}function ne(i,r,n,s){if(i<r||i>n||i!==Ge(i))throw Error($e+(s||"Argument")+(typeof i=="number"?i<r||i>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(i))}function kt(i){var r=i.c.length-1;return Ve(i.e/G)==r&&i.c[r]%2!=0}function At(i,r){return(i.length>1?i.charAt(0)+"."+i.slice(1):i)+(r<0?"e":"e+")+r}function rt(i,r,n){var s,t;if(r<0){for(t=n+".";++r;t+=n);i=t+i}else if(s=i.length,++r>s){for(t=n,r-=s;--r;t+=n);i+=t}else r<s&&(i=i.slice(0,r)+"."+i.slice(r));return i}var Nr=qi(),Ye=Nr;var Je=require("@suilend/sdk"),dt=require("@suilend/sui-fe");var Ui=ri(require("crypto")),Ct=new Uint8Array(256),St=Ct.length;function li(){return St>Ct.length-16&&(Ui.default.randomFillSync(Ct),St=0),Ct.slice(St,St+=16)}var qe=[];for(let i=0;i<256;++i)qe.push((i+256).toString(16).slice(1));function Zi(i,r=0){return qe[i[r+0]]+qe[i[r+1]]+qe[i[r+2]]+qe[i[r+3]]+"-"+qe[i[r+4]]+qe[i[r+5]]+"-"+qe[i[r+6]]+qe[i[r+7]]+"-"+qe[i[r+8]]+qe[i[r+9]]+"-"+qe[i[r+10]]+qe[i[r+11]]+qe[i[r+12]]+qe[i[r+13]]+qe[i[r+14]]+qe[i[r+15]]}var ji=ri(require("crypto")),fi={randomUUID:ji.default.randomUUID};function Rr(i,r,n){if(fi.randomUUID&&!r&&!i)return fi.randomUUID();i=i||{};let s=i.random||(i.rng||li)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,r){n=n||0;for(let t=0;t<16;++t)r[n+t]=s[t];return r}return Zi(s)}var Pt=Rr;var zi=require("@cetusprotocol/common-sdk"),ui=10n;function $i(i){return i.depositedAmount.eq(0)?new Ye(0):i.borrowedAmount.div(i.depositedAmount).times(100)}function hi(i){let r=$i(i);if(!r.gt(100))return(0,Je.linearlyInterpolate)(i.config.interestRate,"utilPercent","aprPercent",r)}function Ki(i){let r=$i(i),n=hi(i);if(!(n===void 0||r.gt(100)))return new Ye(r.div(100)).times(n.div(100)).times(1-i.config.spreadFeeBps/1e4).times(100)}function Hi(i,r,n,s){let{apiUrl:t}=(0,zi.getPackagerConfigs)(s.sdkOptions.suilend);i===Je.Side.DEPOSIT&&([dt.NORMALIZED_flSUI_COINTYPE,dt.NORMALIZED_jugSUI_COINTYPE].includes(r.coinType)&&n.push({stats:{id:Pt(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${t}/partners/LiqAg.png`,perDay:new Ye(.036),side:Je.Side.DEPOSIT},obligationClaims:{}}),r.coinType===dt.NORMALIZED_LBTC_COINTYPE&&n.push({stats:{id:Pt(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${t}/partners/Lombard Lux.png`,perDay:new Ye(0),side:Je.Side.DEPOSIT},obligationClaims:{}}))}function Wi(i,r,n){return{...i,depositedAmount:r===Je.Side.DEPOSIT?Ye.max(i.depositedAmount.plus(n),0):i.depositedAmount,borrowedAmount:r===Je.Side.BORROW?Ye.max(i.borrowedAmount.plus(n),0):i.borrowedAmount}}function Gi(i,r,n){let s=i===Je.Side.DEPOSIT?r.depositedAmount:r.borrowedAmount,t=i===Je.Side.DEPOSIT?n.depositedAmount:n.borrowedAmount,f=t.eq(0)?new Ye(-1):s.div(t);return{multiplier:f,isValid:!f.eq(-1)}}function Vi(i,r,n,s){let t=i.map(d=>({...d,stats:{...d.stats,perDay:s?d.stats.perDay.times(n):void 0}})),f=r.map(d=>({...d,stats:{...d.stats,aprPercent:s?d.stats.aprPercent.times(n):void 0}}));return{newPerDayRewards:t,newAprRewards:f}}function Xi(i,r){if(!ui)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(r<0n){let n=10n**(ui- -r);return i*n}return i/10n**(r+ui)}var Ze=require("@cetusprotocol/common-sdk"),Yi=require("@mysten/sui/utils"),xt=class{constructor(r){this.getSuiLendCoinInfo=(r,n)=>{let{allLendingMarketData:s,lstAprPercentMap:t}=this.lendingMarketCache??{};if(!s||!t)throw new Error("lendingMarketCache is not initialized");let f=Object.values(s??{})[0],d=f.lendingMarket.reserves.find(X=>X.coinType===r);if(!d)throw new Error("reserve not found");let v=this.obligationsCache?.[f.lendingMarket.id],M="borrow",w=v.rewardMap[d.token.coinType]?.[M]??[],A=(0,re.getFilteredRewards)(w);Hi(M,d,A,this.sdk);let x=(0,re.getStakingYieldAprPercent)(M,d.coinType,t),C=M===re.Side.DEPOSIT?d.depositAprPercent:d.borrowAprPercent,L=C,B=Wi(d,M,n);L=M===re.Side.DEPOSIT?Ki(B):hi(B);let{multiplier:D,isValid:Z}=Gi(M,d,B),j=(0,re.getDedupedPerDayRewards)(A),I=(0,re.getDedupedAprRewards)(A),{newPerDayRewards:F,newAprRewards:q}=Vi(j,I,D,Z),ee=(0,re.getTotalAprPercent)(M,C,A,x),$=L===void 0||q.some(X=>X.stats.aprPercent===void 0)?void 0:(0,re.getTotalAprPercent)(M,L,q,x);return{borrowLimit:d.config.borrowLimit.toString(),borrowedAmount:d.borrowedAmount.toString(),remainingBorrowLimit:(0,Ze.d)(d.config.borrowLimit.toString()).sub((0,Ze.d)(d.borrowedAmount.toString())).toString(),depositAprPercent:d.depositAprPercent.toString(),totalAprPercent:ee.toString(),borrowInterest:C.toString(),stakingYieldAprPercent:x?.toString(),rewardAprPercent:I[0]?.stats.aprPercent?.toString()}};this.createObligation=async r=>{let{lendingMarketId:n,lendingMarketType:s}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(n,s)).createObligation(r)};this.refreshReservePrices=async(r,n,s)=>{let{lendingMarketId:t,lendingMarketType:f}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),d=`${t}_${f}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let v=await this.suilendClientCache[d].pythClient.getPriceFeedObjectId(n);console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:322 ~ SuiLendModule ~ priceInfoObjectId:",v),this.suilendClientCache[d].pythConnection.getLatestPriceFeeds,this.suilendClientCache[d].refreshReservePrices(r,v,s)};this.getLatestPriceFeeds=async r=>{let{lendingMarketId:n,lendingMarketType:s}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),t=`${n}_${s}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let f=Array.from(new Set(r.map(M=>(0,Yi.toHEX)(new Uint8Array(M.priceIdentifier.bytes))))),d=await this.suilendClientCache[t].pythConnection.getLatestPriceFeeds(f),v={};return d?.forEach((M,w)=>{let A=M.getPriceUnchecked(),x=r[w];if(A){let{price:C,expo:L}=A,B=(0,Ze.d)(C).mul((0,Ze.d)(10).pow((0,Ze.d)(L))).toString(),D={coin_type:x.coinType.name,price:B,oracle_price:0n,last_update_time:A.publishTime};D.oracle_price=Xi(BigInt(C),BigInt(L)),v[x.coinType.name]=D,this.sdk.updateCache(`getLatestPrice_${D.coin_type}`,D)}}),v};this.getSuiLendReserveInfo=async(r,n)=>{let{lendingMarketId:s}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),{allLendingMarketData:t}=await this.getLendingMarketData(),f=t[s].reserveMap[r],d=t[s].reserveMap[n],v=t[s].refreshedRawReserves.filter(M=>M.coinType.name==(0,Ze.removeHexPrefix)(r)||M.coinType.name==(0,Ze.removeHexPrefix)(n));return{baseReserveArrayIndex:f.arrayIndex.toString(),quoteReserveArrayIndex:d.arrayIndex.toString(),reserve:v}};this.sdk=r}async getSuilendClient(r,n){let s=`${r}_${n}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[s]||(this.suilendClientCache[s]=await Qi.SuilendClient.initialize(r,n,this.sdk.FullClient,!0)),this.suilendClientCache[s]}async getLendingMarketData(r=!1){if(!r&&this.lendingMarketCache)return this.lendingMarketCache;let n=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend)?.lendingMarket||[];if(!n.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[s,t]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(n.map(async d=>{let v=await this.getSuilendClient(d.id,d.type),{lendingMarket:M,coinMetadataMap:w,refreshedRawReserves:A,reserveMap:x,reserveCoinTypes:C,reserveCoinMetadataMap:L,rewardCoinTypes:B,activeRewardCoinTypes:D,rewardCoinMetadataMap:Z}=await(0,re.initializeSuilend)(this.sdk.FullClient,v),{rewardPriceMap:j}=await(0,re.initializeSuilendRewards)(x,D);return[d.id,{suilendClient:v,lendingMarket:M,coinMetadataMap:w,refreshedRawReserves:A,reserveMap:x,reserveCoinTypes:C,reserveCoinMetadataMap:L,rewardPriceMap:j,rewardCoinTypes:B,activeRewardCoinTypes:D,rewardCoinMetadataMap:Z}]}))))(),(async()=>{try{let f=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.apiUrl}/springsui/apy`),d=await f.json();if(f?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(d).map(([v,M])=>[v,new Ye(M)]))}catch(f){return console.error(f),{}}})()]);return this.lendingMarketCache={allLendingMarketData:s,lstAprPercentMap:t},this.lendingMarketCache}catch(s){throw console.log("\u{1F680} getLendingMarketData error:",s),s}}async getInitializeObligations(r,n=!1){if(!n&&this.obligationsCache)return this.obligationsCache;r||(r=await this.getLendingMarketData());let s={};for(let t of Object.values(r.allLendingMarketData)){let{obligationOwnerCaps:f,obligations:d}=await(0,re.initializeObligations)(this.sdk.FullClient,t.suilendClient,t.refreshedRawReserves,t.reserveMap,this.sdk.senderAddress),v=(0,re.formatRewards)(t.reserveMap,t.rewardCoinMetadataMap,t.rewardPriceMap,d);s[t.lendingMarket.id]={obligationOwnerCaps:f,obligations:d,rewardMap:v}}return this.obligationsCache=s,this.obligationsCache}async getSuiLendUserData(r,n=!1){let{lstAprPercentMap:s}=this.lendingMarketCache??{},t=this.obligationsCache??{},{lendingMarketId:f}=(0,Ze.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),d=t[f];if(!d)throw new Error(`No user data found for lending market: ${f}`);if(r){let v=d.obligations.find(w=>w.id===r);if(!v)throw new Error(`Obligation not found: ${r}`);let M=(0,re.getNetAprPercent)(v,d.rewardMap,s??{});return{obligation:v,netAprPercent:M,deposits:v.deposits,borrowedAmount:v.borrowedAmount,depositedAmount:v.depositedAmount,netValueUsd:v.netValueUsd,rewardMap:d.rewardMap}}}priceCheck(r,n=60){let s=Math.floor(Date.now()/1e3);if(!(Math.abs(s-r.last_update_time)>n))return r}};var N=require("@cetusprotocol/common-sdk");var pt=9e15,ht=1e9,ci="0123456789abcdef",Ot="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Nt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",di={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-pt,maxE:pt,crypto:!1},ir,nt,H=!0,Tt="[DecimalError] ",ut=Tt+"Invalid argument: ",rr=Tt+"Precision limit exceeded",nr=Tt+"crypto unavailable",or="[object Decimal]",je=Math.floor,Be=Math.pow,Tr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Dr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Er=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,sr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Qe=1e7,K=7,Br=9007199254740991,Fr=Ot.length-1,pi=Nt.length-1,O={toStringTag:or};O.absoluteValue=O.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),z(i)};O.ceil=function(){return z(new this.constructor(this),this.e+1,2)};O.clampedTo=O.clamp=function(i,r){var n,s=this,t=s.constructor;if(i=new t(i),r=new t(r),!i.s||!r.s)return new t(NaN);if(i.gt(r))throw Error(ut+r);return n=s.cmp(i),n<0?i:s.cmp(r)>0?r:new t(s)};O.comparedTo=O.cmp=function(i){var r,n,s,t,f=this,d=f.d,v=(i=new f.constructor(i)).d,M=f.s,w=i.s;if(!d||!v)return!M||!w?NaN:M!==w?M:d===v?0:!d^M<0?1:-1;if(!d[0]||!v[0])return d[0]?M:v[0]?-w:0;if(M!==w)return M;if(f.e!==i.e)return f.e>i.e^M<0?1:-1;for(s=d.length,t=v.length,r=0,n=s<t?s:t;r<n;++r)if(d[r]!==v[r])return d[r]>v[r]^M<0?1:-1;return s===t?0:s>t^M<0?1:-1};O.cosine=O.cos=function(){var i,r,n=this,s=n.constructor;return n.d?n.d[0]?(i=s.precision,r=s.rounding,s.precision=i+Math.max(n.e,n.sd())+K,s.rounding=1,n=qr(s,hr(s,n)),s.precision=i,s.rounding=r,z(nt==2||nt==3?n.neg():n,i,r,!0)):new s(1):new s(NaN)};O.cubeRoot=O.cbrt=function(){var i,r,n,s,t,f,d,v,M,w,A=this,x=A.constructor;if(!A.isFinite()||A.isZero())return new x(A);for(H=!1,f=A.s*Be(A.s*A,1/3),!f||Math.abs(f)==1/0?(n=Ue(A.d),i=A.e,(f=(i-n.length+1)%3)&&(n+=f==1||f==-2?"0":"00"),f=Be(n,1/3),i=je((i+1)/3)-(i%3==(i<0?-1:2)),f==1/0?n="5e"+i:(n=f.toExponential(),n=n.slice(0,n.indexOf("e")+1)+i),s=new x(n),s.s=A.s):s=new x(f.toString()),d=(i=x.precision)+3;;)if(v=s,M=v.times(v).times(v),w=M.plus(A),s=ie(w.plus(A).times(v),w.plus(M),d+2,1),Ue(v.d).slice(0,d)===(n=Ue(s.d)).slice(0,d))if(n=n.slice(d-3,d+1),n=="9999"||!t&&n=="4999"){if(!t&&(z(v,i+1,0),v.times(v).times(v).eq(A))){s=v;break}d+=4,t=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(z(s,i+1,1),r=!s.times(s).times(s).eq(A));break}return H=!0,z(s,i,x.rounding,r)};O.decimalPlaces=O.dp=function(){var i,r=this.d,n=NaN;if(r){if(i=r.length-1,n=(i-je(this.e/K))*K,i=r[i],i)for(;i%10==0;i/=10)n--;n<0&&(n=0)}return n};O.dividedBy=O.div=function(i){return ie(this,new this.constructor(i))};O.dividedToIntegerBy=O.divToInt=function(i){var r=this,n=r.constructor;return z(ie(r,new n(i),0,1,1),n.precision,n.rounding)};O.equals=O.eq=function(i){return this.cmp(i)===0};O.floor=function(){return z(new this.constructor(this),this.e+1,3)};O.greaterThan=O.gt=function(i){return this.cmp(i)>0};O.greaterThanOrEqualTo=O.gte=function(i){var r=this.cmp(i);return r==1||r===0};O.hyperbolicCosine=O.cosh=function(){var i,r,n,s,t,f=this,d=f.constructor,v=new d(1);if(!f.isFinite())return new d(f.s?1/0:NaN);if(f.isZero())return v;n=d.precision,s=d.rounding,d.precision=n+Math.max(f.e,f.sd())+4,d.rounding=1,t=f.d.length,t<32?(i=Math.ceil(t/3),r=(1/Et(4,i)).toString()):(i=16,r="2.3283064365386962890625e-10"),f=gt(d,1,f.times(r),new d(1),!0);for(var M,w=i,A=new d(8);w--;)M=f.times(f),f=v.minus(M.times(A.minus(M.times(A))));return z(f,d.precision=n,d.rounding=s,!0)};O.hyperbolicSine=O.sinh=function(){var i,r,n,s,t=this,f=t.constructor;if(!t.isFinite()||t.isZero())return new f(t);if(r=f.precision,n=f.rounding,f.precision=r+Math.max(t.e,t.sd())+4,f.rounding=1,s=t.d.length,s<3)t=gt(f,2,t,t,!0);else{i=1.4*Math.sqrt(s),i=i>16?16:i|0,t=t.times(1/Et(5,i)),t=gt(f,2,t,t,!0);for(var d,v=new f(5),M=new f(16),w=new f(20);i--;)d=t.times(t),t=t.times(v.plus(d.times(M.times(d).plus(w))))}return f.precision=r,f.rounding=n,z(t,r,n,!0)};O.hyperbolicTangent=O.tanh=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+7,s.rounding=1,ie(n.sinh(),n.cosh(),s.precision=i,s.rounding=r)):new s(n.s)};O.inverseCosine=O.acos=function(){var i=this,r=i.constructor,n=i.abs().cmp(1),s=r.precision,t=r.rounding;return n!==-1?n===0?i.isNeg()?et(r,s,t):new r(0):new r(NaN):i.isZero()?et(r,s+4,t).times(.5):(r.precision=s+6,r.rounding=1,i=new r(1).minus(i).div(i.plus(1)).sqrt().atan(),r.precision=s,r.rounding=t,i.times(2))};O.inverseHyperbolicCosine=O.acosh=function(){var i,r,n=this,s=n.constructor;return n.lte(1)?new s(n.eq(1)?0:NaN):n.isFinite()?(i=s.precision,r=s.rounding,s.precision=i+Math.max(Math.abs(n.e),n.sd())+4,s.rounding=1,H=!1,n=n.times(n).minus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln()):new s(n)};O.inverseHyperbolicSine=O.asinh=function(){var i,r,n=this,s=n.constructor;return!n.isFinite()||n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+2*Math.max(Math.abs(n.e),n.sd())+6,s.rounding=1,H=!1,n=n.times(n).plus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln())};O.inverseHyperbolicTangent=O.atanh=function(){var i,r,n,s,t=this,f=t.constructor;return t.isFinite()?t.e>=0?new f(t.abs().eq(1)?t.s/0:t.isZero()?t:NaN):(i=f.precision,r=f.rounding,s=t.sd(),Math.max(s,i)<2*-t.e-1?z(new f(t),i,r,!0):(f.precision=n=s-t.e,t=ie(t.plus(1),new f(1).minus(t),n+i,1),f.precision=i+4,f.rounding=1,t=t.ln(),f.precision=i,f.rounding=r,t.times(.5))):new f(NaN)};O.inverseSine=O.asin=function(){var i,r,n,s,t=this,f=t.constructor;return t.isZero()?new f(t):(r=t.abs().cmp(1),n=f.precision,s=f.rounding,r!==-1?r===0?(i=et(f,n+4,s).times(.5),i.s=t.s,i):new f(NaN):(f.precision=n+6,f.rounding=1,t=t.div(new f(1).minus(t.times(t)).sqrt().plus(1)).atan(),f.precision=n,f.rounding=s,t.times(2)))};O.inverseTangent=O.atan=function(){var i,r,n,s,t,f,d,v,M,w=this,A=w.constructor,x=A.precision,C=A.rounding;if(w.isFinite()){if(w.isZero())return new A(w);if(w.abs().eq(1)&&x+4<=pi)return d=et(A,x+4,C).times(.25),d.s=w.s,d}else{if(!w.s)return new A(NaN);if(x+4<=pi)return d=et(A,x+4,C).times(.5),d.s=w.s,d}for(A.precision=v=x+10,A.rounding=1,n=Math.min(28,v/K+2|0),i=n;i;--i)w=w.div(w.times(w).plus(1).sqrt().plus(1));for(H=!1,r=Math.ceil(v/K),s=1,M=w.times(w),d=new A(w),t=w;i!==-1;)if(t=t.times(M),f=d.minus(t.div(s+=2)),t=t.times(M),d=f.plus(t.div(s+=2)),d.d[r]!==void 0)for(i=r;d.d[i]===f.d[i]&&i--;);return n&&(d=d.times(2<<n-1)),H=!0,z(d,A.precision=x,A.rounding=C,!0)};O.isFinite=function(){return!!this.d};O.isInteger=O.isInt=function(){return!!this.d&&je(this.e/K)>this.d.length-2};O.isNaN=function(){return!this.s};O.isNegative=O.isNeg=function(){return this.s<0};O.isPositive=O.isPos=function(){return this.s>0};O.isZero=function(){return!!this.d&&this.d[0]===0};O.lessThan=O.lt=function(i){return this.cmp(i)<0};O.lessThanOrEqualTo=O.lte=function(i){return this.cmp(i)<1};O.logarithm=O.log=function(i){var r,n,s,t,f,d,v,M,w=this,A=w.constructor,x=A.precision,C=A.rounding,L=5;if(i==null)i=new A(10),r=!0;else{if(i=new A(i),n=i.d,i.s<0||!n||!n[0]||i.eq(1))return new A(NaN);r=i.eq(10)}if(n=w.d,w.s<0||!n||!n[0]||w.eq(1))return new A(n&&!n[0]?-1/0:w.s!=1?NaN:n?0:1/0);if(r)if(n.length>1)f=!0;else{for(t=n[0];t%10===0;)t/=10;f=t!==1}if(H=!1,v=x+L,d=ft(w,v),s=r?Rt(A,v+10):ft(i,v),M=ie(d,s,v,1),vt(M.d,t=x,C))do if(v+=10,d=ft(w,v),s=r?Rt(A,v+10):ft(i,v),M=ie(d,s,v,1),!f){+Ue(M.d).slice(t+1,t+15)+1==1e14&&(M=z(M,x+1,0));break}while(vt(M.d,t+=10,C));return H=!0,z(M,x,C)};O.minus=O.sub=function(i){var r,n,s,t,f,d,v,M,w,A,x,C,L=this,B=L.constructor;if(i=new B(i),!L.d||!i.d)return!L.s||!i.s?i=new B(NaN):L.d?i.s=-i.s:i=new B(i.d||L.s!==i.s?L:NaN),i;if(L.s!=i.s)return i.s=-i.s,L.plus(i);if(w=L.d,C=i.d,v=B.precision,M=B.rounding,!w[0]||!C[0]){if(C[0])i.s=-i.s;else if(w[0])i=new B(L);else return new B(M===3?-0:0);return H?z(i,v,M):i}if(n=je(i.e/K),A=je(L.e/K),w=w.slice(),f=A-n,f){for(x=f<0,x?(r=w,f=-f,d=C.length):(r=C,n=A,d=w.length),s=Math.max(Math.ceil(v/K),d)+2,f>s&&(f=s,r.length=1),r.reverse(),s=f;s--;)r.push(0);r.reverse()}else{for(s=w.length,d=C.length,x=s<d,x&&(d=s),s=0;s<d;s++)if(w[s]!=C[s]){x=w[s]<C[s];break}f=0}for(x&&(r=w,w=C,C=r,i.s=-i.s),d=w.length,s=C.length-d;s>0;--s)w[d++]=0;for(s=C.length;s>f;){if(w[--s]<C[s]){for(t=s;t&&w[--t]===0;)w[t]=Qe-1;--w[t],w[s]+=Qe}w[s]-=C[s]}for(;w[--d]===0;)w.pop();for(;w[0]===0;w.shift())--n;return w[0]?(i.d=w,i.e=Dt(w,n),H?z(i,v,M):i):new B(M===3?-0:0)};O.modulo=O.mod=function(i){var r,n=this,s=n.constructor;return i=new s(i),!n.d||!i.s||i.d&&!i.d[0]?new s(NaN):!i.d||n.d&&!n.d[0]?z(new s(n),s.precision,s.rounding):(H=!1,s.modulo==9?(r=ie(n,i.abs(),0,3,1),r.s*=i.s):r=ie(n,i,0,s.modulo,1),r=r.times(i),H=!0,n.minus(r))};O.naturalExponential=O.exp=function(){return gi(this)};O.naturalLogarithm=O.ln=function(){return ft(this)};O.negated=O.neg=function(){var i=new this.constructor(this);return i.s=-i.s,z(i)};O.plus=O.add=function(i){var r,n,s,t,f,d,v,M,w,A,x=this,C=x.constructor;if(i=new C(i),!x.d||!i.d)return!x.s||!i.s?i=new C(NaN):x.d||(i=new C(i.d||x.s===i.s?x:NaN)),i;if(x.s!=i.s)return i.s=-i.s,x.minus(i);if(w=x.d,A=i.d,v=C.precision,M=C.rounding,!w[0]||!A[0])return A[0]||(i=new C(x)),H?z(i,v,M):i;if(f=je(x.e/K),s=je(i.e/K),w=w.slice(),t=f-s,t){for(t<0?(n=w,t=-t,d=A.length):(n=A,s=f,d=w.length),f=Math.ceil(v/K),d=f>d?f+1:d+1,t>d&&(t=d,n.length=1),n.reverse();t--;)n.push(0);n.reverse()}for(d=w.length,t=A.length,d-t<0&&(t=d,n=A,A=w,w=n),r=0;t;)r=(w[--t]=w[t]+A[t]+r)/Qe|0,w[t]%=Qe;for(r&&(w.unshift(r),++s),d=w.length;w[--d]==0;)w.pop();return i.d=w,i.e=Dt(w,s),H?z(i,v,M):i};O.precision=O.sd=function(i){var r,n=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(ut+i);return n.d?(r=ar(n.d),i&&n.e+1>r&&(r=n.e+1)):r=NaN,r};O.round=function(){var i=this,r=i.constructor;return z(new r(i),i.e+1,r.rounding)};O.sine=O.sin=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+Math.max(n.e,n.sd())+K,s.rounding=1,n=Zr(s,hr(s,n)),s.precision=i,s.rounding=r,z(nt>2?n.neg():n,i,r,!0)):new s(NaN)};O.squareRoot=O.sqrt=function(){var i,r,n,s,t,f,d=this,v=d.d,M=d.e,w=d.s,A=d.constructor;if(w!==1||!v||!v[0])return new A(!w||w<0&&(!v||v[0])?NaN:v?d:1/0);for(H=!1,w=Math.sqrt(+d),w==0||w==1/0?(r=Ue(v),(r.length+M)%2==0&&(r+="0"),w=Math.sqrt(r),M=je((M+1)/2)-(M<0||M%2),w==1/0?r="5e"+M:(r=w.toExponential(),r=r.slice(0,r.indexOf("e")+1)+M),s=new A(r)):s=new A(w.toString()),n=(M=A.precision)+3;;)if(f=s,s=f.plus(ie(d,f,n+2,1)).times(.5),Ue(f.d).slice(0,n)===(r=Ue(s.d)).slice(0,n))if(r=r.slice(n-3,n+1),r=="9999"||!t&&r=="4999"){if(!t&&(z(f,M+1,0),f.times(f).eq(d))){s=f;break}n+=4,t=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(z(s,M+1,1),i=!s.times(s).eq(d));break}return H=!0,z(s,M,A.rounding,i)};O.tangent=O.tan=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+10,s.rounding=1,n=n.sin(),n.s=1,n=ie(n,new s(1).minus(n.times(n)).sqrt(),i+10,0),s.precision=i,s.rounding=r,z(nt==2||nt==4?n.neg():n,i,r,!0)):new s(NaN)};O.times=O.mul=function(i){var r,n,s,t,f,d,v,M,w,A=this,x=A.constructor,C=A.d,L=(i=new x(i)).d;if(i.s*=A.s,!C||!C[0]||!L||!L[0])return new x(!i.s||C&&!C[0]&&!L||L&&!L[0]&&!C?NaN:!C||!L?i.s/0:i.s*0);for(n=je(A.e/K)+je(i.e/K),M=C.length,w=L.length,M<w&&(f=C,C=L,L=f,d=M,M=w,w=d),f=[],d=M+w,s=d;s--;)f.push(0);for(s=w;--s>=0;){for(r=0,t=M+s;t>s;)v=f[t]+L[s]*C[t-s-1]+r,f[t--]=v%Qe|0,r=v/Qe|0;f[t]=(f[t]+r)%Qe|0}for(;!f[--d];)f.pop();return r?++n:f.shift(),i.d=f,i.e=Dt(f,n),H?z(i,x.precision,x.rounding):i};O.toBinary=function(i,r){return mi(this,2,i,r)};O.toDecimalPlaces=O.toDP=function(i,r){var n=this,s=n.constructor;return n=new s(n),i===void 0?n:(Ke(i,0,ht),r===void 0?r=s.rounding:Ke(r,0,8),z(n,i+n.e+1,r))};O.toExponential=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=tt(s,!0):(Ke(i,0,ht),r===void 0?r=t.rounding:Ke(r,0,8),s=z(new t(s),i+1,r),n=tt(s,!0,i+1)),s.isNeg()&&!s.isZero()?"-"+n:n};O.toFixed=function(i,r){var n,s,t=this,f=t.constructor;return i===void 0?n=tt(t):(Ke(i,0,ht),r===void 0?r=f.rounding:Ke(r,0,8),s=z(new f(t),i+t.e+1,r),n=tt(s,!1,i+s.e+1)),t.isNeg()&&!t.isZero()?"-"+n:n};O.toFraction=function(i){var r,n,s,t,f,d,v,M,w,A,x,C,L=this,B=L.d,D=L.constructor;if(!B)return new D(L);if(w=n=new D(1),s=M=new D(0),r=new D(s),f=r.e=ar(B)-L.e-1,d=f%K,r.d[0]=Be(10,d<0?K+d:d),i==null)i=f>0?r:w;else{if(v=new D(i),!v.isInt()||v.lt(w))throw Error(ut+v);i=v.gt(r)?f>0?r:w:v}for(H=!1,v=new D(Ue(B)),A=D.precision,D.precision=f=B.length*K*2;x=ie(v,r,0,1,1),t=n.plus(x.times(s)),t.cmp(i)!=1;)n=s,s=t,t=w,w=M.plus(x.times(t)),M=t,t=r,r=v.minus(x.times(t)),v=t;return t=ie(i.minus(n),s,0,1,1),M=M.plus(t.times(w)),n=n.plus(t.times(s)),M.s=w.s=L.s,C=ie(w,s,f,1).minus(L).abs().cmp(ie(M,n,f,1).minus(L).abs())<1?[w,s]:[M,n],D.precision=A,H=!0,C};O.toHexadecimal=O.toHex=function(i,r){return mi(this,16,i,r)};O.toNearest=function(i,r){var n=this,s=n.constructor;if(n=new s(n),i==null){if(!n.d)return n;i=new s(1),r=s.rounding}else{if(i=new s(i),r===void 0?r=s.rounding:Ke(r,0,8),!n.d)return i.s?n:i;if(!i.d)return i.s&&(i.s=n.s),i}return i.d[0]?(H=!1,n=ie(n,i,0,r,1).times(i),H=!0,z(n)):(i.s=n.s,n=i),n};O.toNumber=function(){return+this};O.toOctal=function(i,r){return mi(this,8,i,r)};O.toPower=O.pow=function(i){var r,n,s,t,f,d,v=this,M=v.constructor,w=+(i=new M(i));if(!v.d||!i.d||!v.d[0]||!i.d[0])return new M(Be(+v,w));if(v=new M(v),v.eq(1))return v;if(s=M.precision,f=M.rounding,i.eq(1))return z(v,s,f);if(r=je(i.e/K),r>=i.d.length-1&&(n=w<0?-w:w)<=Br)return t=lr(M,v,n,s),i.s<0?new M(1).div(t):z(t,s,f);if(d=v.s,d<0){if(r<i.d.length-1)return new M(NaN);if((i.d[r]&1)==0&&(d=1),v.e==0&&v.d[0]==1&&v.d.length==1)return v.s=d,v}return n=Be(+v,w),r=n==0||!isFinite(n)?je(w*(Math.log("0."+Ue(v.d))/Math.LN10+v.e+1)):new M(n+"").e,r>M.maxE+1||r<M.minE-1?new M(r>0?d/0:0):(H=!1,M.rounding=v.s=1,n=Math.min(12,(r+"").length),t=gi(i.times(ft(v,s+n)),s),t.d&&(t=z(t,s+5,1),vt(t.d,s,f)&&(r=s+10,t=z(gi(i.times(ft(v,r+n)),r),r+5,1),+Ue(t.d).slice(s+1,s+15)+1==1e14&&(t=z(t,s+1,0)))),t.s=d,H=!0,M.rounding=f,z(t,s,f))};O.toPrecision=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=tt(s,s.e<=t.toExpNeg||s.e>=t.toExpPos):(Ke(i,1,ht),r===void 0?r=t.rounding:Ke(r,0,8),s=z(new t(s),i,r),n=tt(s,i<=s.e||s.e<=t.toExpNeg,i)),s.isNeg()&&!s.isZero()?"-"+n:n};O.toSignificantDigits=O.toSD=function(i,r){var n=this,s=n.constructor;return i===void 0?(i=s.precision,r=s.rounding):(Ke(i,1,ht),r===void 0?r=s.rounding:Ke(r,0,8)),z(new s(n),i,r)};O.toString=function(){var i=this,r=i.constructor,n=tt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()&&!i.isZero()?"-"+n:n};O.truncated=O.trunc=function(){return z(new this.constructor(this),this.e+1,1)};O.valueOf=O.toJSON=function(){var i=this,r=i.constructor,n=tt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()?"-"+n:n};function Ue(i){var r,n,s,t=i.length-1,f="",d=i[0];if(t>0){for(f+=d,r=1;r<t;r++)s=i[r]+"",n=K-s.length,n&&(f+=lt(n)),f+=s;d=i[r],s=d+"",n=K-s.length,n&&(f+=lt(n))}else if(d===0)return"0";for(;d%10===0;)d/=10;return f+d}function Ke(i,r,n){if(i!==~~i||i<r||i>n)throw Error(ut+i)}function vt(i,r,n,s){var t,f,d,v;for(f=i[0];f>=10;f/=10)--r;return--r<0?(r+=K,t=0):(t=Math.ceil((r+1)/K),r%=K),f=Be(10,K-r),v=i[t]%f|0,s==null?r<3?(r==0?v=v/100|0:r==1&&(v=v/10|0),d=n<4&&v==99999||n>3&&v==49999||v==5e4||v==0):d=(n<4&&v+1==f||n>3&&v+1==f/2)&&(i[t+1]/f/100|0)==Be(10,r-2)-1||(v==f/2||v==0)&&(i[t+1]/f/100|0)==0:r<4?(r==0?v=v/1e3|0:r==1?v=v/100|0:r==2&&(v=v/10|0),d=(s||n<4)&&v==9999||!s&&n>3&&v==4999):d=((s||n<4)&&v+1==f||!s&&n>3&&v+1==f/2)&&(i[t+1]/f/1e3|0)==Be(10,r-3)-1,d}function Lt(i,r,n){for(var s,t=[0],f,d=0,v=i.length;d<v;){for(f=t.length;f--;)t[f]*=r;for(t[0]+=ci.indexOf(i.charAt(d++)),s=0;s<t.length;s++)t[s]>n-1&&(t[s+1]===void 0&&(t[s+1]=0),t[s+1]+=t[s]/n|0,t[s]%=n)}return t.reverse()}function qr(i,r){var n,s,t;if(r.isZero())return r;s=r.d.length,s<32?(n=Math.ceil(s/3),t=(1/Et(4,n)).toString()):(n=16,t="2.3283064365386962890625e-10"),i.precision+=n,r=gt(i,1,r.times(t),new i(1));for(var f=n;f--;){var d=r.times(r);r=d.times(d).minus(d).times(8).plus(1)}return i.precision-=n,r}var ie=(function(){function i(s,t,f){var d,v=0,M=s.length;for(s=s.slice();M--;)d=s[M]*t+v,s[M]=d%f|0,v=d/f|0;return v&&s.unshift(v),s}function r(s,t,f,d){var v,M;if(f!=d)M=f>d?1:-1;else for(v=M=0;v<f;v++)if(s[v]!=t[v]){M=s[v]>t[v]?1:-1;break}return M}function n(s,t,f,d){for(var v=0;f--;)s[f]-=v,v=s[f]<t[f]?1:0,s[f]=v*d+s[f]-t[f];for(;!s[0]&&s.length>1;)s.shift()}return function(s,t,f,d,v,M){var w,A,x,C,L,B,D,Z,j,I,F,q,ee,$,X,m,b,_,P,S,c=s.constructor,e=s.s==t.s?1:-1,o=s.d,l=t.d;if(!o||!o[0]||!l||!l[0])return new c(!s.s||!t.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?e*0:e/0);for(M?(L=1,A=s.e-t.e):(M=Qe,L=K,A=je(s.e/L)-je(t.e/L)),P=l.length,b=o.length,j=new c(e),I=j.d=[],x=0;l[x]==(o[x]||0);x++);if(l[x]>(o[x]||0)&&A--,f==null?($=f=c.precision,d=c.rounding):v?$=f+(s.e-t.e)+1:$=f,$<0)I.push(1),B=!0;else{if($=$/L+2|0,x=0,P==1){for(C=0,l=l[0],$++;(x<b||C)&&$--;x++)X=C*M+(o[x]||0),I[x]=X/l|0,C=X%l|0;B=C||x<b}else{for(C=M/(l[0]+1)|0,C>1&&(l=i(l,C,M),o=i(o,C,M),P=l.length,b=o.length),m=P,F=o.slice(0,P),q=F.length;q<P;)F[q++]=0;S=l.slice(),S.unshift(0),_=l[0],l[1]>=M/2&&++_;do C=0,w=r(l,F,P,q),w<0?(ee=F[0],P!=q&&(ee=ee*M+(F[1]||0)),C=ee/_|0,C>1?(C>=M&&(C=M-1),D=i(l,C,M),Z=D.length,q=F.length,w=r(D,F,Z,q),w==1&&(C--,n(D,P<Z?S:l,Z,M))):(C==0&&(w=C=1),D=l.slice()),Z=D.length,Z<q&&D.unshift(0),n(F,D,q,M),w==-1&&(q=F.length,w=r(l,F,P,q),w<1&&(C++,n(F,P<q?S:l,q,M))),q=F.length):w===0&&(C++,F=[0]),I[x++]=C,w&&F[0]?F[q++]=o[m]||0:(F=[o[m]],q=1);while((m++<b||F[0]!==void 0)&&$--);B=F[0]!==void 0}I[0]||I.shift()}if(L==1)j.e=A,ir=B;else{for(x=1,C=I[0];C>=10;C/=10)x++;j.e=x+A*L-1,z(j,v?f+j.e+1:f,d,B)}return j}})();function z(i,r,n,s){var t,f,d,v,M,w,A,x,C,L=i.constructor;e:if(r!=null){if(x=i.d,!x)return i;for(t=1,v=x[0];v>=10;v/=10)t++;if(f=r-t,f<0)f+=K,d=r,A=x[C=0],M=A/Be(10,t-d-1)%10|0;else if(C=Math.ceil((f+1)/K),v=x.length,C>=v)if(s){for(;v++<=C;)x.push(0);A=M=0,t=1,f%=K,d=f-K+1}else break e;else{for(A=v=x[C],t=1;v>=10;v/=10)t++;f%=K,d=f-K+t,M=d<0?0:A/Be(10,t-d-1)%10|0}if(s=s||r<0||x[C+1]!==void 0||(d<0?A:A%Be(10,t-d-1)),w=n<4?(M||s)&&(n==0||n==(i.s<0?3:2)):M>5||M==5&&(n==4||s||n==6&&(f>0?d>0?A/Be(10,t-d):0:x[C-1])%10&1||n==(i.s<0?8:7)),r<1||!x[0])return x.length=0,w?(r-=i.e+1,x[0]=Be(10,(K-r%K)%K),i.e=-r||0):x[0]=i.e=0,i;if(f==0?(x.length=C,v=1,C--):(x.length=C+1,v=Be(10,K-f),x[C]=d>0?(A/Be(10,t-d)%Be(10,d)|0)*v:0),w)for(;;)if(C==0){for(f=1,d=x[0];d>=10;d/=10)f++;for(d=x[0]+=v,v=1;d>=10;d/=10)v++;f!=v&&(i.e++,x[0]==Qe&&(x[0]=1));break}else{if(x[C]+=v,x[C]!=Qe)break;x[C--]=0,v=1}for(f=x.length;x[--f]===0;)x.pop()}return H&&(i.e>L.maxE?(i.d=null,i.e=NaN):i.e<L.minE&&(i.e=0,i.d=[0])),i}function tt(i,r,n){if(!i.isFinite())return ur(i);var s,t=i.e,f=Ue(i.d),d=f.length;return r?(n&&(s=n-d)>0?f=f.charAt(0)+"."+f.slice(1)+lt(s):d>1&&(f=f.charAt(0)+"."+f.slice(1)),f=f+(i.e<0?"e":"e+")+i.e):t<0?(f="0."+lt(-t-1)+f,n&&(s=n-d)>0&&(f+=lt(s))):t>=d?(f+=lt(t+1-d),n&&(s=n-t-1)>0&&(f=f+"."+lt(s))):((s=t+1)<d&&(f=f.slice(0,s)+"."+f.slice(s)),n&&(s=n-d)>0&&(t+1===d&&(f+="."),f+=lt(s))),f}function Dt(i,r){var n=i[0];for(r*=K;n>=10;n/=10)r++;return r}function Rt(i,r,n){if(r>Fr)throw H=!0,n&&(i.precision=n),Error(rr);return z(new i(Ot),r,1,!0)}function et(i,r,n){if(r>pi)throw Error(rr);return z(new i(Nt),r,n,!0)}function ar(i){var r=i.length-1,n=r*K+1;if(r=i[r],r){for(;r%10==0;r/=10)n--;for(r=i[0];r>=10;r/=10)n++}return n}function lt(i){for(var r="";i--;)r+="0";return r}function lr(i,r,n,s){var t,f=new i(1),d=Math.ceil(s/K+4);for(H=!1;;){if(n%2&&(f=f.times(r),er(f.d,d)&&(t=!0)),n=je(n/2),n===0){n=f.d.length-1,t&&f.d[n]===0&&++f.d[n];break}r=r.times(r),er(r.d,d)}return H=!0,f}function Ji(i){return i.d[i.d.length-1]&1}function fr(i,r,n){for(var s,t,f=new i(r[0]),d=0;++d<r.length;){if(t=new i(r[d]),!t.s){f=t;break}s=f.cmp(t),(s===n||s===0&&f.s===n)&&(f=t)}return f}function gi(i,r){var n,s,t,f,d,v,M,w=0,A=0,x=0,C=i.constructor,L=C.rounding,B=C.precision;if(!i.d||!i.d[0]||i.e>17)return new C(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(r==null?(H=!1,M=B):M=r,v=new C(.03125);i.e>-2;)i=i.times(v),x+=5;for(s=Math.log(Be(2,x))/Math.LN10*2+5|0,M+=s,n=f=d=new C(1),C.precision=M;;){if(f=z(f.times(i),M,1),n=n.times(++A),v=d.plus(ie(f,n,M,1)),Ue(v.d).slice(0,M)===Ue(d.d).slice(0,M)){for(t=x;t--;)d=z(d.times(d),M,1);if(r==null)if(w<3&&vt(d.d,M-s,L,w))C.precision=M+=10,n=f=v=new C(1),A=0,w++;else return z(d,C.precision=B,L,H=!0);else return C.precision=B,d}d=v}}function ft(i,r){var n,s,t,f,d,v,M,w,A,x,C,L=1,B=10,D=i,Z=D.d,j=D.constructor,I=j.rounding,F=j.precision;if(D.s<0||!Z||!Z[0]||!D.e&&Z[0]==1&&Z.length==1)return new j(Z&&!Z[0]?-1/0:D.s!=1?NaN:Z?0:D);if(r==null?(H=!1,A=F):A=r,j.precision=A+=B,n=Ue(Z),s=n.charAt(0),Math.abs(f=D.e)<15e14){for(;s<7&&s!=1||s==1&&n.charAt(1)>3;)D=D.times(i),n=Ue(D.d),s=n.charAt(0),L++;f=D.e,s>1?(D=new j("0."+n),f++):D=new j(s+"."+n.slice(1))}else return w=Rt(j,A+2,F).times(f+""),D=ft(new j(s+"."+n.slice(1)),A-B).plus(w),j.precision=F,r==null?z(D,F,I,H=!0):D;for(x=D,M=d=D=ie(D.minus(1),D.plus(1),A,1),C=z(D.times(D),A,1),t=3;;){if(d=z(d.times(C),A,1),w=M.plus(ie(d,new j(t),A,1)),Ue(w.d).slice(0,A)===Ue(M.d).slice(0,A))if(M=M.times(2),f!==0&&(M=M.plus(Rt(j,A+2,F).times(f+""))),M=ie(M,new j(L),A,1),r==null)if(vt(M.d,A-B,I,v))j.precision=A+=B,w=d=D=ie(x.minus(1),x.plus(1),A,1),C=z(D.times(D),A,1),t=v=1;else return z(M,j.precision=F,I,H=!0);else return j.precision=F,M;M=w,t+=2}}function ur(i){return String(i.s*i.s/0)}function It(i,r){var n,s,t;for((n=r.indexOf("."))>-1&&(r=r.replace(".","")),(s=r.search(/e/i))>0?(n<0&&(n=s),n+=+r.slice(s+1),r=r.substring(0,s)):n<0&&(n=r.length),s=0;r.charCodeAt(s)===48;s++);for(t=r.length;r.charCodeAt(t-1)===48;--t);if(r=r.slice(s,t),r){if(t-=s,i.e=n=n-s-1,i.d=[],s=(n+1)%K,n<0&&(s+=K),s<t){for(s&&i.d.push(+r.slice(0,s)),t-=K;s<t;)i.d.push(+r.slice(s,s+=K));r=r.slice(s),s=K-r.length}else s-=t;for(;s--;)r+="0";i.d.push(+r),H&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function Ur(i,r){var n,s,t,f,d,v,M,w,A;if(r.indexOf("_")>-1){if(r=r.replace(/(\d)_(?=\d)/g,"$1"),sr.test(r))return It(i,r)}else if(r==="Infinity"||r==="NaN")return+r||(i.s=NaN),i.e=NaN,i.d=null,i;if(Dr.test(r))n=16,r=r.toLowerCase();else if(Tr.test(r))n=2;else if(Er.test(r))n=8;else throw Error(ut+r);for(f=r.search(/p/i),f>0?(M=+r.slice(f+1),r=r.substring(2,f)):r=r.slice(2),f=r.indexOf("."),d=f>=0,s=i.constructor,d&&(r=r.replace(".",""),v=r.length,f=v-f,t=lr(s,new s(n),f,f*2)),w=Lt(r,n,Qe),A=w.length-1,f=A;w[f]===0;--f)w.pop();return f<0?new s(i.s*0):(i.e=Dt(w,A),i.d=w,H=!1,d&&(i=ie(i,t,v*4)),M&&(i=i.times(Math.abs(M)<54?Be(2,M):wt.pow(2,M))),H=!0,i)}function Zr(i,r){var n,s=r.d.length;if(s<3)return r.isZero()?r:gt(i,2,r,r);n=1.4*Math.sqrt(s),n=n>16?16:n|0,r=r.times(1/Et(5,n)),r=gt(i,2,r,r);for(var t,f=new i(5),d=new i(16),v=new i(20);n--;)t=r.times(r),r=r.times(f.plus(t.times(d.times(t).minus(v))));return r}function gt(i,r,n,s,t){var f,d,v,M,w=1,A=i.precision,x=Math.ceil(A/K);for(H=!1,M=n.times(n),v=new i(s);;){if(d=ie(v.times(M),new i(r++*r++),A,1),v=t?s.plus(d):s.minus(d),s=ie(d.times(M),new i(r++*r++),A,1),d=v.plus(s),d.d[x]!==void 0){for(f=x;d.d[f]===v.d[f]&&f--;);if(f==-1)break}f=v,v=s,s=d,d=f,w++}return H=!0,d.d.length=x+1,d}function Et(i,r){for(var n=i;--r;)n*=i;return n}function hr(i,r){var n,s=r.s<0,t=et(i,i.precision,1),f=t.times(.5);if(r=r.abs(),r.lte(f))return nt=s?4:1,r;if(n=r.divToInt(t),n.isZero())nt=s?3:2;else{if(r=r.minus(n.times(t)),r.lte(f))return nt=Ji(n)?s?2:3:s?4:1,r;nt=Ji(n)?s?1:4:s?3:2}return r.minus(t).abs()}function mi(i,r,n,s){var t,f,d,v,M,w,A,x,C,L=i.constructor,B=n!==void 0;if(B?(Ke(n,1,ht),s===void 0?s=L.rounding:Ke(s,0,8)):(n=L.precision,s=L.rounding),!i.isFinite())A=ur(i);else{for(A=tt(i),d=A.indexOf("."),B?(t=2,r==16?n=n*4-3:r==8&&(n=n*3-2)):t=r,d>=0&&(A=A.replace(".",""),C=new L(1),C.e=A.length-d,C.d=Lt(tt(C),10,t),C.e=C.d.length),x=Lt(A,10,t),f=M=x.length;x[--M]==0;)x.pop();if(!x[0])A=B?"0p+0":"0";else{if(d<0?f--:(i=new L(i),i.d=x,i.e=f,i=ie(i,C,n,s,0,t),x=i.d,f=i.e,w=ir),d=x[n],v=t/2,w=w||x[n+1]!==void 0,w=s<4?(d!==void 0||w)&&(s===0||s===(i.s<0?3:2)):d>v||d===v&&(s===4||w||s===6&&x[n-1]&1||s===(i.s<0?8:7)),x.length=n,w)for(;++x[--n]>t-1;)x[n]=0,n||(++f,x.unshift(1));for(M=x.length;!x[M-1];--M);for(d=0,A="";d<M;d++)A+=ci.charAt(x[d]);if(B){if(M>1)if(r==16||r==8){for(d=r==16?4:3,--M;M%d;M++)A+="0";for(x=Lt(A,t,r),M=x.length;!x[M-1];--M);for(d=1,A="1.";d<M;d++)A+=ci.charAt(x[d])}else A=A.charAt(0)+"."+A.slice(1);A=A+(f<0?"p":"p+")+f}else if(f<0){for(;++f;)A="0"+A;A="0."+A}else if(++f>M)for(f-=M;f--;)A+="0";else f<M&&(A=A.slice(0,f)+"."+A.slice(f))}A=(r==16?"0x":r==2?"0b":r==8?"0o":"")+A}return i.s<0?"-"+A:A}function er(i,r){if(i.length>r)return i.length=r,!0}function jr(i){return new this(i).abs()}function zr(i){return new this(i).acos()}function $r(i){return new this(i).acosh()}function Kr(i,r){return new this(i).plus(r)}function Hr(i){return new this(i).asin()}function Wr(i){return new this(i).asinh()}function Gr(i){return new this(i).atan()}function Vr(i){return new this(i).atanh()}function Xr(i,r){i=new this(i),r=new this(r);var n,s=this.precision,t=this.rounding,f=s+4;return!i.s||!r.s?n=new this(NaN):!i.d&&!r.d?(n=et(this,f,1).times(r.s>0?.25:.75),n.s=i.s):!r.d||i.isZero()?(n=r.s<0?et(this,s,t):new this(0),n.s=i.s):!i.d||r.isZero()?(n=et(this,f,1).times(.5),n.s=i.s):r.s<0?(this.precision=f,this.rounding=1,n=this.atan(ie(i,r,f,1)),r=et(this,f,1),this.precision=s,this.rounding=t,n=i.s<0?n.minus(r):n.plus(r)):n=this.atan(ie(i,r,f,1)),n}function Qr(i){return new this(i).cbrt()}function Yr(i){return z(i=new this(i),i.e+1,2)}function Jr(i,r,n){return new this(i).clamp(r,n)}function en(i){if(!i||typeof i!="object")throw Error(Tt+"Object expected");var r,n,s,t=i.defaults===!0,f=["precision",1,ht,"rounding",0,8,"toExpNeg",-pt,0,"toExpPos",0,pt,"maxE",0,pt,"minE",-pt,0,"modulo",0,9];for(r=0;r<f.length;r+=3)if(n=f[r],t&&(this[n]=di[n]),(s=i[n])!==void 0)if(je(s)===s&&s>=f[r+1]&&s<=f[r+2])this[n]=s;else throw Error(ut+n+": "+s);if(n="crypto",t&&(this[n]=di[n]),(s=i[n])!==void 0)if(s===!0||s===!1||s===0||s===1)if(s)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(nr);else this[n]=!1;else throw Error(ut+n+": "+s);return this}function tn(i){return new this(i).cos()}function rn(i){return new this(i).cosh()}function cr(i){var r,n,s;function t(f){var d,v,M,w=this;if(!(w instanceof t))return new t(f);if(w.constructor=t,tr(f)){w.s=f.s,H?!f.d||f.e>t.maxE?(w.e=NaN,w.d=null):f.e<t.minE?(w.e=0,w.d=[0]):(w.e=f.e,w.d=f.d.slice()):(w.e=f.e,w.d=f.d?f.d.slice():f.d);return}if(M=typeof f,M==="number"){if(f===0){w.s=1/f<0?-1:1,w.e=0,w.d=[0];return}if(f<0?(f=-f,w.s=-1):w.s=1,f===~~f&&f<1e7){for(d=0,v=f;v>=10;v/=10)d++;H?d>t.maxE?(w.e=NaN,w.d=null):d<t.minE?(w.e=0,w.d=[0]):(w.e=d,w.d=[f]):(w.e=d,w.d=[f]);return}if(f*0!==0){f||(w.s=NaN),w.e=NaN,w.d=null;return}return It(w,f.toString())}if(M==="string")return(v=f.charCodeAt(0))===45?(f=f.slice(1),w.s=-1):(v===43&&(f=f.slice(1)),w.s=1),sr.test(f)?It(w,f):Ur(w,f);if(M==="bigint")return f<0?(f=-f,w.s=-1):w.s=1,It(w,f.toString());throw Error(ut+f)}if(t.prototype=O,t.ROUND_UP=0,t.ROUND_DOWN=1,t.ROUND_CEIL=2,t.ROUND_FLOOR=3,t.ROUND_HALF_UP=4,t.ROUND_HALF_DOWN=5,t.ROUND_HALF_EVEN=6,t.ROUND_HALF_CEIL=7,t.ROUND_HALF_FLOOR=8,t.EUCLID=9,t.config=t.set=en,t.clone=cr,t.isDecimal=tr,t.abs=jr,t.acos=zr,t.acosh=$r,t.add=Kr,t.asin=Hr,t.asinh=Wr,t.atan=Gr,t.atanh=Vr,t.atan2=Xr,t.cbrt=Qr,t.ceil=Yr,t.clamp=Jr,t.cos=tn,t.cosh=rn,t.div=nn,t.exp=on,t.floor=sn,t.hypot=an,t.ln=ln,t.log=fn,t.log10=hn,t.log2=un,t.max=cn,t.min=dn,t.mod=pn,t.mul=gn,t.pow=mn,t.random=vn,t.round=wn,t.sign=Mn,t.sin=yn,t.sinh=bn,t.sqrt=_n,t.sub=kn,t.sum=An,t.tan=Sn,t.tanh=Cn,t.trunc=Pn,i===void 0&&(i={}),i&&i.defaults!==!0)for(s=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],r=0;r<s.length;)i.hasOwnProperty(n=s[r++])||(i[n]=this[n]);return t.config(i),t}function nn(i,r){return new this(i).div(r)}function on(i){return new this(i).exp()}function sn(i){return z(i=new this(i),i.e+1,3)}function an(){var i,r,n=new this(0);for(H=!1,i=0;i<arguments.length;)if(r=new this(arguments[i++]),r.d)n.d&&(n=n.plus(r.times(r)));else{if(r.s)return H=!0,new this(1/0);n=r}return H=!0,n.sqrt()}function tr(i){return i instanceof wt||i&&i.toStringTag===or||!1}function ln(i){return new this(i).ln()}function fn(i,r){return new this(i).log(r)}function un(i){return new this(i).log(2)}function hn(i){return new this(i).log(10)}function cn(){return fr(this,arguments,-1)}function dn(){return fr(this,arguments,1)}function pn(i,r){return new this(i).mod(r)}function gn(i,r){return new this(i).mul(r)}function mn(i,r){return new this(i).pow(r)}function vn(i){var r,n,s,t,f=0,d=new this(1),v=[];if(i===void 0?i=this.precision:Ke(i,1,ht),s=Math.ceil(i/K),this.crypto)if(crypto.getRandomValues)for(r=crypto.getRandomValues(new Uint32Array(s));f<s;)t=r[f],t>=429e7?r[f]=crypto.getRandomValues(new Uint32Array(1))[0]:v[f++]=t%1e7;else if(crypto.randomBytes){for(r=crypto.randomBytes(s*=4);f<s;)t=r[f]+(r[f+1]<<8)+(r[f+2]<<16)+((r[f+3]&127)<<24),t>=214e7?crypto.randomBytes(4).copy(r,f):(v.push(t%1e7),f+=4);f=s/4}else throw Error(nr);else for(;f<s;)v[f++]=Math.random()*1e7|0;for(s=v[--f],i%=K,s&&i&&(t=Be(10,K-i),v[f]=(s/t|0)*t);v[f]===0;f--)v.pop();if(f<0)n=0,v=[0];else{for(n=-1;v[0]===0;n-=K)v.shift();for(s=1,t=v[0];t>=10;t/=10)s++;s<K&&(n-=K-s)}return d.e=n,d.d=v,d}function wn(i){return z(i=new this(i),i.e+1,this.rounding)}function Mn(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function yn(i){return new this(i).sin()}function bn(i){return new this(i).sinh()}function _n(i){return new this(i).sqrt()}function kn(i,r){return new this(i).sub(r)}function An(){var i=0,r=arguments,n=new this(r[i]);for(H=!1;n.s&&++i<r.length;)n=n.plus(r[i]);return H=!0,z(n,this.precision,this.rounding)}function Sn(i){return new this(i).tan()}function Cn(i){return new this(i).tanh()}function Pn(i){return z(i=new this(i),i.e+1,1)}O[Symbol.for("nodejs.util.inspect.custom")]=O.toString;O[Symbol.toStringTag]="Decimal";var wt=O.constructor=cr(di);Ot=new wt(Ot);Nt=new wt(Nt);var it=wt;var yi=ri(pr()),ot=require("@mysten/sui/transactions");var mt=require("@cetusprotocol/common-sdk"),gr=i=>{let r=[];return i.forEach(n=>{r.push(wi(n))}),r},wi=i=>{let r=(0,mt.getObjectFields)(i);return{marketId:r.id.id,baseToken:(0,mt.addHexPrefix)(r.base_token.fields.name),quoteToken:(0,mt.addHexPrefix)(r.quote_token.fields.name),isOpenPause:r.is_open_pause,isClosePause:r.is_close_pause,maxLongLeverage:r.max_long_leverage,maxShortLeverage:r.max_short_leverage,openFeeRate:(r.open_fee_rate/1e6).toString(),closeFeeRate:(r.close_fee_rate/1e6).toString(),positionsHandle:r.positions.fields.id.id}},Mi=i=>{let r=(0,mt.getObjectFields)(i);return{createdAt:r.created_ts,id:r.id.id,initDepositAmount:r.init_deposit_amount,isLong:r.is_long,lendingMarketId:r.lending_market_id,obligationOwnerCap:r.obligation_owner_cap.fields.obligation_id}};var st=require("@mysten/sui/utils"),mr=require("@suilend/sdk/parsers/obligation"),vr=require("@suilend/sdk/_generated/suilend/lending-market/functions"),Bt=class{constructor(r){this.getLeverageConfig=async()=>{let r=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.leverage);return(await this._sdk.FullClient.getObject({id:r.global_config_id,options:{showContent:!0}})).data.content.fields};this.getLeverageMarketsList=async(r=!1)=>{let n="leverage_markets_list",s=this._sdk.getCache(n,r);if(s)return s;let t=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.leverage),f=50,d=null,v=[];for(;;){let C=await this._sdk.FullClient.getDynamicFields({parentId:t.markets_table_id,limit:f,cursor:d});if(C.data.forEach(L=>{v.push(L.objectId)}),C.data.length<f)break;d=C.nextCursor}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:63 ~ LeverageModules ~ marketSimpleIdList:",v);let M=await this._sdk.FullClient.batchGetObjects(v,{showContent:!0}),w=[];M.forEach(C=>{w.push(C.data.content.fields.value.fields.market_id)});let A=await this._sdk.FullClient.batchGetObjects(w,{showContent:!0}),x=gr(A);return this._sdk.updateCache(n,x,N.CACHE_TIME_5MIN),x};this.getLeverageMarketInfo=async r=>{let n=`leverage_market_info_${r}`,s=this._sdk.getCache(n);if(s)return s;let t=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}}),f=wi(t);return this._sdk.updateCache(n,f,N.CACHE_TIME_5MIN),f};this.getLeveragePositionList=async()=>{let r=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{Package:this._sdk.sdkOptions.leverage.package_id}]}}),{lendingMarketId:n,lendingMarketType:s}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),t=await this._sdk.SuiLendModule.getSuilendClient(n,s),f=[];for(let d=0;d<r.data.length;d++){let v=Mi(r.data[d]),M=await t.getObligation(v.obligationOwnerCap);f.push({...v,...M})}return f};this.getLeveragePosition=async r=>{let n=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{ObjectId:r}}),s=Mi(n.data[0]),{lendingMarketId:t,lendingMarketType:f}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),d=await this._sdk.SuiLendModule.getSuilendClient(t,f),{allLendingMarketData:v}=await this._sdk.SuiLendModule.getLendingMarketData(),M=v[t].reserveMap,w=await d.getObligation(s.obligationOwnerCap);return{...(0,mr.parseObligation)(w,M||{}),...s}};this.getClmmPoolInfo=async r=>{let n=await this._sdk.ClmmSDK.Pool.getPool(r),{coin_type_a:s,coin_type_b:t,fee_rate:f}=n;return{clmmFeeTier:f/1e6,clmmPoolCoinTypeA:s,clmmPoolCoinTypeB:t}};this.openLeveragePosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:f,slippage:d,leverage:v,marketId:M}=r,{lendingMarketId:w}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),A=new ot.Transaction,{openFeeRate:x,baseToken:C,quoteToken:L}=await this.getLeverageMarketInfo(M),{clmmFeeTier:B,clmmPoolCoinTypeA:D,clmmPoolCoinTypeB:Z}=await this.getClmmPoolInfo(f);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",B,D,Z);let{baseReserveArrayIndex:j,quoteReserveArrayIndex:I,reserve:F}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(C,L),q=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",q);let ee=t.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",ee);let $,X;if(q){let T=s&&n?L:C,U=s&&n?C:L,V=await this.findRouters(T,U,t,!0,[f]);if(ee=V?.amount_out.toString(),V){let J=N.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),T,A);X=await this.routerSwap({router:V.route_obj,slippage:d,inputCoin:J,txb:A}),$=X}}else $=N.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),n?L:C,A);let{flashAmount:m}=await this.calculateFlashLoanParams({isLong:s,leverage:v,baseToken:C,quoteToken:L,initDepositAmount:ee,reserve:F});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",m);let b=s?L:C;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",b);let _=D===b;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",D),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",_);let P=(0,N.d)(m).mul(B).toString(),{balanceA:S,balanceB:c,receipt:e}=this.flashLoan({amount:(0,N.d)(m),clmmPool:f,clmmPoolCoinTypeA:D,clmmPoolCoinTypeB:Z,flashLoanCoin:b,tx:A}),o=s?L:C,l=s?C:L,u=await this.findRouters(o,l,(0,N.d)(m),!0,[f]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:u,debtFrom:o,debtTo:l,clmmPoolCoinTypeA:D,clmmPoolCoinTypeB:Z});let h=(0,N.d)(u?.amount_out||0),g;u&&(g=await this.routerSwap({router:u.route_obj,inputCoin:_?N.CoinAssist.fromBalance(S,D,A):N.CoinAssist.fromBalance(c,Z,A),slippage:d,txb:A}));let k=(0,N.d)(h).add(ee).mul(1-x).toDP(0,it.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:258 ~ LeverageModules ~ totalDepositAmount:",k,ee,h);let p=this.createLeveragePosition({leverage:v,marketId:M,baseToken:C,quoteToken:L,isLong:s,totalDepositAmount:k,tx:A});for(let T=0;T<F.length;T++){let U=(0,st.toHEX)(new Uint8Array(F[T].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,U,BigInt(F[T].arrayIndex))}let a=s?j:I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",$),await A.mergeCoins(g,[$]),await this.depositToLeveragePosition({isLong:s,marketId:M,position:p,depositReserveArrayIndex:a,inputCoin:g},A);let y=(0,N.d)(m).add(P).toDP(0,it.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",y,m,P);let E=await this.borrowAsset({position:p,reserveArrayIndex:s?I:j,borrowAmount:(0,N.d)(y),baseToken:C,quoteToken:L,isLong:s,lendingMarketId:w},A);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",E);let R=N.CoinAssist.mintBalanceZero(_?Z:D,A);return this.repayFlashLoan({tx:A,clmmPool:f,repayBase:_?N.CoinAssist.intoBalance(E,D,A):R,repayQuote:_?R:N.CoinAssist.intoBalance(E,Z,A),receipt:e,clmmPoolCoinTypeA:D,clmmPoolCoinTypeB:Z}),A.transferObjects([p],A.pure.address(this._sdk.getSenderAddress())),N.CoinAssist.destroyBalanceZero(_?c:S,_?Z:D,A),A};this.positionManageSizeDeposit=async r=>{let{marketId:n,positionId:s,isQuote:t,depositAmount:f,clmmPool:d,slippage:v,leverage:M,txb:w}=r,{lendingMarketId:A}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{baseToken:x,quoteToken:C}=await this.getLeverageMarketInfo(n),{isLong:L,deposits:B,borrows:D}=await this.getLeveragePosition(s),{reserve:Z}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(x,C),{clmmFeeTier:j,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F}=await this.getClmmPoolInfo(d),q=w||new ot.Transaction,ee=B[0].reserveArrayIndex.toString(),$=D[0].reserveArrayIndex.toString(),X=t&&L||!t&&!L,m;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",X);let b;if(X){let E=t&&L?C:x,R=t&&L?x:C,T=await this.findRouters(E,R,f,!0,[d]);if(T){let U=N.CoinAssist.buildCoinWithBalance(BigInt(f.toString()),E,q);b=await this.routerSwap({router:T.route_obj,inputCoin:U,slippage:v,txb:q}),m=b}}else m=N.CoinAssist.buildCoinWithBalance(BigInt(f.toString()),t?C:x,q);let _=L?C:x;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",_);let{flashAmount:P}=await this.calculateFlashLoanParams({isLong:L,leverage:M,baseToken:x,quoteToken:C,initDepositAmount:f.toString(),reserve:Z}),S=(0,N.d)(P).mul(j).toString(),c=I===_;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",c);let{balanceA:e,balanceB:o,receipt:l}=this.flashLoan({amount:(0,N.d)(P),clmmPool:d,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F,flashLoanCoin:_,tx:q}),u=L?C:x,h=L?x:C,g=await this.findRouters(u,h,(0,N.d)(P),!0,[d]),k;g&&(k=await this.routerSwap({router:g.route_obj,inputCoin:c?N.CoinAssist.fromBalance(e,I,q):N.CoinAssist.fromBalance(o,F,q),slippage:v,txb:q})),q.mergeCoins(k,[m]);for(let E=0;E<Z.length;E++){let R=(0,st.toHEX)(new Uint8Array(Z[E].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(q,R,BigInt(Z[E].arrayIndex))}this.depositToLeveragePosition({isLong:L,marketId:n,positionId:s,depositReserveArrayIndex:ee,inputCoin:k},q);let p=(0,N.d)(P).add(S).toDP(0,it.ROUND_UP).toString(),a=this.borrowAsset({positionId:s,reserveArrayIndex:$,borrowAmount:(0,N.d)(p),baseToken:x,quoteToken:C,isLong:L,lendingMarketId:A},q),y=N.CoinAssist.mintBalanceZero(c?F:I,q);return this.repayFlashLoan({tx:q,clmmPool:d,repayBase:c?N.CoinAssist.intoBalance(a,I,q):y,repayQuote:c?y:N.CoinAssist.intoBalance(a,F,q),receipt:l,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F}),N.CoinAssist.destroyBalanceZero(c?o:e,c?F:I,q),q};this.positionManageSizeWithdraw=async r=>{let{marketId:n,positionId:s,withdrawAmount:t,isQuote:f,txb:d,clmmPool:v,slippage:M,leverage:w}=r,{lendingMarketType:A,lendingMarketId:x}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),C=d||new ot.Transaction,{baseToken:L,quoteToken:B}=await this.getLeverageMarketInfo(n),{isLong:D,deposits:Z,borrows:j}=await this.getLeveragePosition(s),{reserve:I}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(L,B),F=f&&D||!f&&!D;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:479 ~ LeverageModules ~ hasSwap:",F);let q=t;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:482 ~ LeverageModules ~ withdrawCtokenAmount:",q);let ee=null;if(F){let k=L,p=B;ee=await this.findRouters(k,p,t,!1,[v]),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ routers:",{hasSwapRouters:ee,from:k,to:p}),q=ee?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",q);for(let k=0;k<I.length;k++){let p=(0,st.toHEX)(new Uint8Array(I[k].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(C,p,BigInt(I[k].arrayIndex))}let{token:$}=j[0].reserve,X=(0,N.d)(Z[0].depositedCtokenAmount.toString()).div((0,N.d)(w)).toDP(0,it.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",X);let m=(0,N.d)(q).div((0,N.d)(X)).toString(),b=(0,N.d)(j[0].borrowedAmount.toString()).mul(10**$.decimals).toString(),_=(0,N.d)(b).mul(m).toDP(0,it.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:508 ~ LeverageModules ~ repayAmount:",{\u9700\u8981\u507F\u8FD8\u591A\u5C11borrowAmount:_,\u63D0\u53D6\u4FDD\u8BC1\u91D1\u6570\u91CF:q,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:X});let P=await this._sdk.SuiLendModule.getSuilendClient(x,A),S=await this._sdk.PythConnection.getPriceFeedsUpdateData([Z[0].reserve.priceIdentifier]),c=await P.pythClient.updatePriceFeeds(C,S,[Z[0].reserve.priceIdentifier]),e=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:(0,N.d)(q),withdrawReserveArrayIndex:Z[0].reserveArrayIndex.toString(),withdrawCoinType:D?L:B,baseToken:L,quoteToken:B,priceObjectId:c&&c[0]},C),o=D?L:B,l=D?B:L;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let u=await this.findRouters(o,l,(0,N.d)(_),!1,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:530 ~ LeverageModules ~ debtRouter:",{debtRouter:u,debtFrom:o,debtTo:l});let h;u&&(h=await this.routerSwap({router:u.route_obj,inputCoin:e,slippage:M,txb:C}));let g=C.splitCoins(h,[_]);return this.repay({txb:C,positionId:s,repayReserveArrayIndex:j[0].reserveArrayIndex.toString(),repayCoin:g,repayCoinType:D?B:L,repayAmount:(0,N.d)(0)}),C.transferObjects([h,g],this._sdk.getSenderAddress()),C};this.positionManageLeverageIncrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:f,targetLeverage:d,clmmPool:v,slippage:M}=r,{baseToken:w,quoteToken:A}=await this.getLeverageMarketInfo(n),{deposits:x,borrows:C}=await this.getLeveragePosition(s),{reserve:L}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(w,A),{clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:D,clmmFeeTier:Z}=await this.getClmmPoolInfo(v),{lendingMarketId:j}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{token:I}=C[0].reserve,F=new ot.Transaction,q=(0,N.d)(C[0].borrowedAmount.toString()).mul((0,N.d)(d).sub((0,N.d)(f))).mul(10**I.decimals).toDP(0,it.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",q);let ee=q,$=t?A:w,{balanceA:X,balanceB:m,receipt:b}=this.flashLoan({tx:F,amount:(0,N.d)(ee),clmmPool:v,clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:D,flashLoanCoin:$}),_=t?A:w,P=t?w:A,S=await this.findRouters(_,P,(0,N.d)(q),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:592 ~ LeverageModules ~ routers:",S,_,P);let c=await this.routerSwap({router:S?.route_obj,inputCoin:t?N.CoinAssist.fromBalance(m,D,F):N.CoinAssist.fromBalance(X,B,F),slippage:M,txb:F});for(let h=0;h<L.length;h++){let g=(0,st.toHEX)(new Uint8Array(L[h].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(F,g,BigInt(L[h].arrayIndex))}this.depositToLeveragePosition({isLong:t,marketId:n,positionId:s,depositReserveArrayIndex:t?x[0].reserveArrayIndex.toString():C[0].reserveArrayIndex.toString(),inputCoin:c},F);let e=(0,N.d)(ee).mul((0,N.d)(1).add(Z)).toDP(0,it.ROUND_UP).toString(),o=await this.borrowAsset({positionId:s,reserveArrayIndex:C[0].reserveArrayIndex.toString(),borrowAmount:(0,N.d)(e),baseToken:w,quoteToken:A,isLong:t,lendingMarketId:j},F),l=N.CoinAssist.mintBalanceZero(t?w:A,F),u=B===$;return this.repayFlashLoan({tx:F,clmmPool:v,repayBase:t?l:N.CoinAssist.intoBalance(o,w,F),repayQuote:t?N.CoinAssist.intoBalance(o,A,F):l,receipt:b,clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:D}),N.CoinAssist.destroyBalanceZero(u?m:X,u?D:B,F),F};this.positionManageLeverageDecrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:f,targetLeverage:d,clmmPool:v,slippage:M}=r,{baseToken:w,quoteToken:A,closeFeeRate:x}=await this.getLeverageMarketInfo(n),{deposits:C,borrows:L}=await this.getLeveragePosition(s),{reserve:B}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(w,A),{lendingMarketId:D,lendingMarketType:Z}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),j=new ot.Transaction,I=(0,N.d)(C[0].depositedCtokenAmount.toString()).mul((0,N.d)(f).sub((0,N.d)(d))).toString(),F=(0,N.d)(I).toDP(0,it.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",F);for(let S=0;S<B.length;S++){let c=(0,st.toHEX)(new Uint8Array(B[S].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(j,c,BigInt(B[S].arrayIndex))}let q=await this._sdk.SuiLendModule.getSuilendClient(D,Z),ee=await this._sdk.PythConnection.getPriceFeedsUpdateData([C[0].reserve.priceIdentifier]),$=await q.pythClient.updatePriceFeeds(j,ee,[C[0].reserve.priceIdentifier]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:672 ~ LeverageModules ~ baseToken:",w);let X=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:(0,N.d)(F),withdrawReserveArrayIndex:C[0].reserveArrayIndex.toString(),withdrawCoinType:t?w:A,baseToken:w,quoteToken:A,priceObjectId:$&&$[0]},j),m=t?w:A,b=t?A:w,_=await this.findRouters(m,b,(0,N.d)(F),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:681 ~ LeverageModules ~ routers:",_,_?.route_obj.paths,m,b);let P=await this.routerSwap({router:_?.route_obj,inputCoin:X,slippage:M,txb:j});return this.repay({txb:j,positionId:s,repayReserveArrayIndex:L[0].reserveArrayIndex.toString(),repayCoin:P,repayCoinType:t?A:w,repayAmount:(0,N.d)(0)}),P&&j.transferObjects([P],this._sdk.getSenderAddress()),j};this.leveragePositionClose=async(r,n)=>{let s=n||new ot.Transaction,{marketId:t,positionId:f}=r,{leverage:d}=this._sdk.sdkOptions,{global_config_id:v}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.leverage),{lendingMarketType:M,lendingMarketId:w}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{baseToken:A,quoteToken:x}=await this.getLeverageMarketInfo(t),C=await this.getLeveragePosition(f);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:541 ~ LeverageModules ~ positionInfo:",C.original.id);let L=(0,vr.obligation)(s,M,{obligationId:C.original.id,lendingMarket:s.object(w)});return s.moveCall({target:`${d.published_at}::position::close_Position`,typeArguments:[M,A,x],arguments:[s.object(v),s.object(t),s.object(f),L,s.object(N.CLOCK_ADDRESS)]}),s};this.flashLoan=r=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:698 ~ LeverageModules ~ params:",r);let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:s}=(0,N.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:t,clmmPool:f,clmmPoolCoinTypeA:d,clmmPoolCoinTypeB:v,flashLoanCoin:M,tx:w}=r,A=d===M,[x,C,L]=w.moveCall({target:`${n.published_at}::pool::flash_loan`,arguments:[w.object(s),w.object(f),w.pure.bool(A),w.pure.u64(t.toString())],typeArguments:[d,v]});return{balanceA:x,balanceB:C,receipt:L}};this.repayFlashLoan=r=>{let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:s}=(0,N.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:t,repayBase:f,repayQuote:d,receipt:v,clmmPool:M,clmmPoolCoinTypeA:w,clmmPoolCoinTypeB:A}=r;return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:612 ~ LeverageModules ~ params:",r),t.moveCall({target:`${n.published_at}::pool::repay_flash_loan`,arguments:[t.object(s),t.object(M),f,d,v],typeArguments:[w,A]}),t};this.borrowAsset=(r,n)=>{let{position:s,reserveArrayIndex:t,borrowAmount:f,baseToken:d,quoteToken:v,lendingMarketId:M,isLong:w,positionId:A}=r;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:677 ~ LeverageModules ~ params:",r);let{leverage:x}=this._sdk.sdkOptions,{lendingMarketType:C}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend);return N.CoinAssist.isSuiCoin(w?v:d)?n.moveCall({target:`${x.published_at}::position::borrow_sui`,typeArguments:[C],arguments:[n.object(M),s,n.pure.u64(t),n.pure.u64(f.toString()),n.object(st.SUI_SYSTEM_STATE_OBJECT_ID),n.object(N.CLOCK_ADDRESS)]}):n.moveCall({target:`${x.published_at}::position::borrow_not_sui`,typeArguments:[C,w?v:d],arguments:[n.object(M),A?n.object(A):s,n.pure.u64(t),n.pure.u64(f.toString()),n.object(N.CLOCK_ADDRESS)]})};this.withdrawAsset=(r,n)=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:749 ~ LeverageModules ~ params:",r);let{leverage:s}=this._sdk.sdkOptions,{lendingMarketId:t,lendingMarketType:f}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{package_id:d}=this._sdk.sdkOptions.suilend,{marketId:v,positionId:M,withdrawAmount:w,withdrawReserveArrayIndex:A,withdrawCoinType:x,baseToken:C,quoteToken:L,priceObjectId:B}=r,[D]=n.moveCall({target:"0x1::option::none",typeArguments:[`${d}::lending_market::RateLimiterExemption<${f}, ${x}>`],arguments:[]});return N.CoinAssist.isSuiCoin(x)?n.moveCall({target:`${s.published_at}::position::withdraw_sui`,typeArguments:[f,C,L],arguments:[n.object(t),n.object(v),n.object(M),n.object(B),n.object(D),n.pure.u64(w.toString()),n.pure.u64(A),n.object(st.SUI_SYSTEM_STATE_OBJECT_ID),n.object(N.CLOCK_ADDRESS)]}):n.moveCall({target:`${s.published_at}::position::withdraw_not_sui`,typeArguments:[f,C,L,x],arguments:[n.object(t),n.object(v),n.object(M),n.object(B),n.object(D),n.pure.u64(w.toString()),n.pure.u64(A),n.object(N.CLOCK_ADDRESS)]})};this.repay=r=>{let{leverage:n}=this._sdk.sdkOptions,{lendingMarketId:s,lendingMarketType:t}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{txb:f,positionId:d,repayAmount:v,repayCoinType:M,repayCoin:w,repayReserveArrayIndex:A}=r,x=f||new ot.Transaction,C=w||N.CoinAssist.buildCoinWithBalance(BigInt(v.toString()),M,x);x.moveCall({target:`${n.published_at}::position::repay`,typeArguments:[t,M],arguments:[x.object(s),x.object(d),x.object(C),x.pure.u64(A.toString()),x.object(N.CLOCK_ADDRESS)]})};this.routerSwap=async r=>{let{slippage:n,txb:s,inputCoin:t,router:f}=r,d=s||new ot.Transaction;if(f)return await this._sdk.AggregatorClient.routerSwap({router:f,inputCoin:t,slippage:n,txb:d})};this.calculateOpenPosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:f,slippage:d,leverage:v,marketId:M}=r,{baseToken:w,quoteToken:A}=await this.getLeverageMarketInfo(M),{reserve:x}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(w,A),C=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",C);let L=t.toString();if(console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",L),C){let I=s&&n?A:w,F=s&&n?w:A;L=(await this.findRouters(I,F,t,!0,[f]))?.amount_out.toString()}let{flashAmount:B}=await this.calculateFlashLoanParams({isLong:s,leverage:v,baseToken:w,quoteToken:A,initDepositAmount:L,reserve:x});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",B);let D=s?A:w,Z=s?w:A,j=await this.findRouters(D,Z,(0,N.d)(B),!0,[f]);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:956 ~ LeverageModules ~ debtRouters:",j),j};this._sdk=r}async calculateFlashLoanParams(r){let{isLong:n,leverage:s,baseToken:t,quoteToken:f,initDepositAmount:d,reserve:v}=r,M=await this._sdk.SuiLendModule.getLatestPriceFeeds(v);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:587 ~ LeverageModules ~ calculateFlashLoanParams ~ priceUpdateData:",M,f,t);let w=M[(0,N.removeHexPrefix)(f)]?.price,A=M[(0,N.removeHexPrefix)(t)]?.price,x=n?(0,N.d)(A).div((0,N.d)(w)).toString():(0,N.d)(w).div((0,N.d)(A)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",d.toString(),n,x,w,A),{flashAmount:(0,N.d)(d).mul(s-1).mul(x).toDP(0,it.ROUND_UP).toString(),rate:x,quotePrice:w,basePrice:A}}createLeveragePosition(r){let{lendingMarketId:n,lendingMarketType:s}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{global_config_id:t}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.leverage),f=this._sdk.sdkOptions.leverage,{leverage:d,marketId:v,baseToken:M,quoteToken:w,isLong:A,totalDepositAmount:x,tx:C}=r;return C.moveCall({target:`${f.published_at}::position::open_position`,arguments:[C.object(t),C.object(v),C.object(n),C.pure.u64(x),C.pure.u64(d*1e4),C.object(N.CLOCK_ADDRESS)],typeArguments:[s,M,w,A?M:w]})}async depositToLeveragePosition(r,n){console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:651 ~ LeverageModules ~ depositToLeveragePosition ~ params:",r);let{leverage:s}=this._sdk.sdkOptions,{lendingMarketType:t,lendingMarketId:f}=(0,N.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{isLong:d,marketId:v,position:M,positionId:w,depositReserveArrayIndex:A,inputCoin:x}=r,{baseToken:C,quoteToken:L}=await this.getLeverageMarketInfo(v);return n.moveCall({target:`${s.published_at}::position::deposit`,typeArguments:[t,C,L,d?C:L],arguments:[n.object(f),n.object(v),M||n.object(w),x,n.pure.u64(A),n.object(N.CLOCK_ADDRESS)]}),n}async findRouters(r,n,s,t,f){let{providers:d}=this._sdk.sdkOptions;try{let v={from:r,target:n,amount:new yi.default(s.toFixed(0).toString()),byAmountIn:t,depth:3,providers:d},M=await this._sdk.AggregatorClient.findRouters(v);if(M?.error?.code===10001)return{...M,is_exceed:M.insufficientLiquidity};if(M?.insufficientLiquidity)return{...M,is_exceed:M.insufficientLiquidity};if(!M?.paths||M?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:M.amountIn.toString(),amount_out:M.amountOut.toString(),is_exceed:M.insufficientLiquidity,route_obj:M,byAmountIn:!0,originRes:M}}catch{try{if(f){let M=await this._sdk.AggregatorClient.swapInPools({from:r,target:n,amount:new yi.default(s.toFixed(0).toString()),byAmountIn:t,pools:f});return M?{amount_in:M.routeData.amountIn.toString(),amount_out:M.routeData.amountOut.toString(),is_exceed:M.isExceed,route_obj:M.routeData,byAmountIn:!0,originRes:M}:null}return null}catch{return null}}}};var Mt=require("@cetusprotocol/aggregator-sdk"),Mr=require("@mysten/sui/utils"),yr=require("@mysten/sui/client"),br=require("@cetusprotocol/sui-clmm-sdk"),_r=require("@pythnetwork/pyth-sui-js"),yt=class i extends wr.SdkWrapper{constructor(r,n){super(r),this._suilendModule=new xt(this),this._leverageModules=new Bt(this),this._aggregatorClient=new Mt.AggregatorClient({signer:(0,Mr.normalizeSuiAddress)("0x0"),client:r.sui_client||new yr.SuiClient({url:r.full_rpc_url}),env:r.env==="testnet"?Mt.Env.Testnet:Mt.Env.Mainnet,pythUrls:r.pyth_urls}),this._clmmSDK=n||br.CetusClmmSDK.createSDK({env:r.env,full_rpc_url:r.full_rpc_url}),this._pythConnection=new _r.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(r){return i.createCustomSDK({...ni,...r})}static createCustomSDK(r){return new i(r)}};var xn=yt;0&&(module.exports={CetusLeverageSDK,leverage_mainnet});
|
|
1
|
+
"use strict";var kr=Object.create;var bt=Object.defineProperty;var Sr=Object.getOwnPropertyDescriptor;var Cr=Object.getOwnPropertyNames;var Ar=Object.getPrototypeOf,Pr=Object.prototype.hasOwnProperty;var xr=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports),Lr=(i,r)=>{for(var n in r)bt(i,n,{get:r[n],enumerable:!0})},Bi=(i,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of Cr(r))!Pr.call(i,t)&&t!==n&&bt(i,t,{get:()=>r[t],enumerable:!(s=Sr(r,t))||s.enumerable});return i};var ri=(i,r,n)=>(n=i!=null?kr(Ar(i)):{},Bi(r||!i||!i.__esModule?bt(n,"default",{value:i,enumerable:!0}):n,i)),Ir=i=>Bi(bt({},"__esModule",{value:!0}),i);var pr=xr((dr,vi)=>{"use strict";(function(i,r){"use strict";function n(c,e){if(!c)throw new Error(e||"Assertion failed")}function s(c,e){c.super_=e;var o=function(){};o.prototype=e.prototype,c.prototype=new o,c.prototype.constructor=c}function t(c,e,o){if(t.isBN(c))return c;this.negative=0,this.words=null,this.length=0,this.red=null,c!==null&&((e==="le"||e==="be")&&(o=e,e=10),this._init(c||0,e||10,o||"be"))}typeof i=="object"?i.exports=t:r.BN=t,t.BN=t,t.wordSize=26;var u;try{typeof window<"u"&&typeof window.Buffer<"u"?u=window.Buffer:u=require("buffer").Buffer}catch{}t.isBN=function(e){return e instanceof t?!0:e!==null&&typeof e=="object"&&e.constructor.wordSize===t.wordSize&&Array.isArray(e.words)},t.max=function(e,o){return e.cmp(o)>0?e:o},t.min=function(e,o){return e.cmp(o)<0?e:o},t.prototype._init=function(e,o,l){if(typeof e=="number")return this._initNumber(e,o,l);if(typeof e=="object")return this._initArray(e,o,l);o==="hex"&&(o=16),n(o===(o|0)&&o>=2&&o<=36),e=e.toString().replace(/\s+/g,"");var f=0;e[0]==="-"&&(f++,this.negative=1),f<e.length&&(o===16?this._parseHex(e,f,l):(this._parseBase(e,o,f),l==="le"&&this._initArray(this.toArray(),o,l)))},t.prototype._initNumber=function(e,o,l){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[e&67108863],this.length=1):e<4503599627370496?(this.words=[e&67108863,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[e&67108863,e/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),o,l)},t.prototype._initArray=function(e,o,l){if(n(typeof e.length=="number"),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var h,g,S=0;if(l==="be")for(f=e.length-1,h=0;f>=0;f-=3)g=e[f]|e[f-1]<<8|e[f-2]<<16,this.words[h]|=g<<S&67108863,this.words[h+1]=g>>>26-S&67108863,S+=24,S>=26&&(S-=26,h++);else if(l==="le")for(f=0,h=0;f<e.length;f+=3)g=e[f]|e[f+1]<<8|e[f+2]<<16,this.words[h]|=g<<S&67108863,this.words[h+1]=g>>>26-S&67108863,S+=24,S>=26&&(S-=26,h++);return this._strip()};function d(c,e){var o=c.charCodeAt(e);if(o>=48&&o<=57)return o-48;if(o>=65&&o<=70)return o-55;if(o>=97&&o<=102)return o-87;n(!1,"Invalid character in "+c)}function v(c,e,o){var l=d(c,o);return o-1>=e&&(l|=d(c,o-1)<<4),l}t.prototype._parseHex=function(e,o,l){this.length=Math.ceil((e.length-o)/6),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var h=0,g=0,S;if(l==="be")for(f=e.length-1;f>=o;f-=2)S=v(e,o,f)<<h,this.words[g]|=S&67108863,h>=18?(h-=18,g+=1,this.words[g]|=S>>>26):h+=8;else{var p=e.length-o;for(f=p%2===0?o+1:o;f<e.length;f+=2)S=v(e,o,f)<<h,this.words[g]|=S&67108863,h>=18?(h-=18,g+=1,this.words[g]|=S>>>26):h+=8}this._strip()};function w(c,e,o,l){for(var f=0,h=0,g=Math.min(c.length,o),S=e;S<g;S++){var p=c.charCodeAt(S)-48;f*=l,p>=49?h=p-49+10:p>=17?h=p-17+10:h=p,n(p>=0&&h<l,"Invalid character"),f+=h}return f}t.prototype._parseBase=function(e,o,l){this.words=[0],this.length=1;for(var f=0,h=1;h<=67108863;h*=o)f++;f--,h=h/o|0;for(var g=e.length-l,S=g%f,p=Math.min(g,g-S)+l,a=0,y=l;y<p;y+=f)a=w(e,y,y+f,o),this.imuln(h),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(S!==0){var E=1;for(a=w(e,y,e.length,o),y=0;y<S;y++)E*=o;this.imuln(E),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this._strip()},t.prototype.copy=function(e){e.words=new Array(this.length);for(var o=0;o<this.length;o++)e.words[o]=this.words[o];e.length=this.length,e.negative=this.negative,e.red=this.red};function M(c,e){c.words=e.words,c.length=e.length,c.negative=e.negative,c.red=e.red}if(t.prototype._move=function(e){M(e,this)},t.prototype.clone=function(){var e=new t(null);return this.copy(e),e},t.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},t.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},t.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{t.prototype[Symbol.for("nodejs.util.inspect.custom")]=_}catch{t.prototype.inspect=_}else t.prototype.inspect=_;function _(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var C=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],A=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],L=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];t.prototype.toString=function(e,o){e=e||10,o=o|0||1;var l;if(e===16||e==="hex"){l="";for(var f=0,h=0,g=0;g<this.length;g++){var S=this.words[g],p=((S<<f|h)&16777215).toString(16);h=S>>>24-f&16777215,f+=2,f>=26&&(f-=26,g--),h!==0||g!==this.length-1?l=C[6-p.length]+p+l:l=p+l}for(h!==0&&(l=h.toString(16)+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(e===(e|0)&&e>=2&&e<=36){var a=A[e],y=L[e];l="";var E=this.clone();for(E.negative=0;!E.isZero();){var T=E.modrn(y).toString(e);E=E.idivn(y),E.isZero()?l=T+l:l=C[a-T.length]+T+l}for(this.isZero()&&(l="0"+l);l.length%o!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}n(!1,"Base should be between 2 and 36")},t.prototype.toNumber=function(){var e=this.words[0];return this.length===2?e+=this.words[1]*67108864:this.length===3&&this.words[2]===1?e+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-e:e},t.prototype.toJSON=function(){return this.toString(16,2)},u&&(t.prototype.toBuffer=function(e,o){return this.toArrayLike(u,e,o)}),t.prototype.toArray=function(e,o){return this.toArrayLike(Array,e,o)};var B=function(e,o){return e.allocUnsafe?e.allocUnsafe(o):new e(o)};t.prototype.toArrayLike=function(e,o,l){this._strip();var f=this.byteLength(),h=l||Math.max(1,f);n(f<=h,"byte array longer than desired length"),n(h>0,"Requested array length <= 0");var g=B(e,h),S=o==="le"?"LE":"BE";return this["_toArrayLike"+S](g,f),g},t.prototype._toArrayLikeLE=function(e,o){for(var l=0,f=0,h=0,g=0;h<this.length;h++){var S=this.words[h]<<g|f;e[l++]=S&255,l<e.length&&(e[l++]=S>>8&255),l<e.length&&(e[l++]=S>>16&255),g===6?(l<e.length&&(e[l++]=S>>24&255),f=0,g=0):(f=S>>>24,g+=2)}if(l<e.length)for(e[l++]=f;l<e.length;)e[l++]=0},t.prototype._toArrayLikeBE=function(e,o){for(var l=e.length-1,f=0,h=0,g=0;h<this.length;h++){var S=this.words[h]<<g|f;e[l--]=S&255,l>=0&&(e[l--]=S>>8&255),l>=0&&(e[l--]=S>>16&255),g===6?(l>=0&&(e[l--]=S>>24&255),f=0,g=0):(f=S>>>24,g+=2)}if(l>=0)for(e[l--]=f;l>=0;)e[l--]=0},Math.clz32?t.prototype._countBits=function(e){return 32-Math.clz32(e)}:t.prototype._countBits=function(e){var o=e,l=0;return o>=4096&&(l+=13,o>>>=13),o>=64&&(l+=7,o>>>=7),o>=8&&(l+=4,o>>>=4),o>=2&&(l+=2,o>>>=2),l+o},t.prototype._zeroBits=function(e){if(e===0)return 26;var o=e,l=0;return(o&8191)===0&&(l+=13,o>>>=13),(o&127)===0&&(l+=7,o>>>=7),(o&15)===0&&(l+=4,o>>>=4),(o&3)===0&&(l+=2,o>>>=2),(o&1)===0&&l++,l},t.prototype.bitLength=function(){var e=this.words[this.length-1],o=this._countBits(e);return(this.length-1)*26+o};function R(c){for(var e=new Array(c.bitLength()),o=0;o<e.length;o++){var l=o/26|0,f=o%26;e[o]=c.words[l]>>>f&1}return e}t.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,o=0;o<this.length;o++){var l=this._zeroBits(this.words[o]);if(e+=l,l!==26)break}return e},t.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},t.prototype.toTwos=function(e){return this.negative!==0?this.abs().inotn(e).iaddn(1):this.clone()},t.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},t.prototype.isNeg=function(){return this.negative!==0},t.prototype.neg=function(){return this.clone().ineg()},t.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},t.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var o=0;o<e.length;o++)this.words[o]=this.words[o]|e.words[o];return this._strip()},t.prototype.ior=function(e){return n((this.negative|e.negative)===0),this.iuor(e)},t.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},t.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},t.prototype.iuand=function(e){var o;this.length>e.length?o=e:o=this;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]&e.words[l];return this.length=o.length,this._strip()},t.prototype.iand=function(e){return n((this.negative|e.negative)===0),this.iuand(e)},t.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},t.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},t.prototype.iuxor=function(e){var o,l;this.length>e.length?(o=this,l=e):(o=e,l=this);for(var f=0;f<l.length;f++)this.words[f]=o.words[f]^l.words[f];if(this!==o)for(;f<o.length;f++)this.words[f]=o.words[f];return this.length=o.length,this._strip()},t.prototype.ixor=function(e){return n((this.negative|e.negative)===0),this.iuxor(e)},t.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},t.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},t.prototype.inotn=function(e){n(typeof e=="number"&&e>=0);var o=Math.ceil(e/26)|0,l=e%26;this._expand(o),l>0&&o--;for(var f=0;f<o;f++)this.words[f]=~this.words[f]&67108863;return l>0&&(this.words[f]=~this.words[f]&67108863>>26-l),this._strip()},t.prototype.notn=function(e){return this.clone().inotn(e)},t.prototype.setn=function(e,o){n(typeof e=="number"&&e>=0);var l=e/26|0,f=e%26;return this._expand(l+1),o?this.words[l]=this.words[l]|1<<f:this.words[l]=this.words[l]&~(1<<f),this._strip()},t.prototype.iadd=function(e){var o;if(this.negative!==0&&e.negative===0)return this.negative=0,o=this.isub(e),this.negative^=1,this._normSign();if(this.negative===0&&e.negative!==0)return e.negative=0,o=this.isub(e),e.negative=1,o._normSign();var l,f;this.length>e.length?(l=this,f=e):(l=e,f=this);for(var h=0,g=0;g<f.length;g++)o=(l.words[g]|0)+(f.words[g]|0)+h,this.words[g]=o&67108863,h=o>>>26;for(;h!==0&&g<l.length;g++)o=(l.words[g]|0)+h,this.words[g]=o&67108863,h=o>>>26;if(this.length=l.length,h!==0)this.words[this.length]=h,this.length++;else if(l!==this)for(;g<l.length;g++)this.words[g]=l.words[g];return this},t.prototype.add=function(e){var o;return e.negative!==0&&this.negative===0?(e.negative=0,o=this.sub(e),e.negative^=1,o):e.negative===0&&this.negative!==0?(this.negative=0,o=e.sub(this),this.negative=1,o):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},t.prototype.isub=function(e){if(e.negative!==0){e.negative=0;var o=this.iadd(e);return e.negative=1,o._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var l=this.cmp(e);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var f,h;l>0?(f=this,h=e):(f=e,h=this);for(var g=0,S=0;S<h.length;S++)o=(f.words[S]|0)-(h.words[S]|0)+g,g=o>>26,this.words[S]=o&67108863;for(;g!==0&&S<f.length;S++)o=(f.words[S]|0)+g,g=o>>26,this.words[S]=o&67108863;if(g===0&&S<f.length&&f!==this)for(;S<f.length;S++)this.words[S]=f.words[S];return this.length=Math.max(this.length,S),f!==this&&(this.negative=1),this._strip()},t.prototype.sub=function(e){return this.clone().isub(e)};function j(c,e,o){o.negative=e.negative^c.negative;var l=c.length+e.length|0;o.length=l,l=l-1|0;var f=c.words[0]|0,h=e.words[0]|0,g=f*h,S=g&67108863,p=g/67108864|0;o.words[0]=S;for(var a=1;a<l;a++){for(var y=p>>>26,E=p&67108863,T=Math.min(a,e.length-1),D=Math.max(0,a-c.length+1);D<=T;D++){var U=a-D|0;f=c.words[U]|0,h=e.words[D]|0,g=f*h+E,y+=g/67108864|0,E=g&67108863}o.words[a]=E|0,p=y|0}return p!==0?o.words[a]=p|0:o.length--,o._strip()}var Z=function(e,o,l){var f=e.words,h=o.words,g=l.words,S=0,p,a,y,E=f[0]|0,T=E&8191,D=E>>>13,U=f[1]|0,X=U&8191,ee=U>>>13,He=f[2]|0,Q=He&8191,te=He>>>13,ze=f[3]|0,Y=ze&8191,W=ze>>>13,bi=f[4]|0,oe=bi&8191,se=bi>>>13,_i=f[5]|0,ae=_i&8191,le=_i>>>13,ki=f[6]|0,ue=ki&8191,fe=ki>>>13,Si=f[7]|0,he=Si&8191,ce=Si>>>13,Ci=f[8]|0,de=Ci&8191,pe=Ci>>>13,Ai=f[9]|0,ge=Ai&8191,me=Ai>>>13,Pi=h[0]|0,ve=Pi&8191,we=Pi>>>13,xi=h[1]|0,Me=xi&8191,ye=xi>>>13,Li=h[2]|0,be=Li&8191,_e=Li>>>13,Ii=h[3]|0,ke=Ii&8191,Se=Ii>>>13,Oi=h[4]|0,Ce=Oi&8191,Ae=Oi>>>13,Ni=h[5]|0,Pe=Ni&8191,xe=Ni>>>13,Ri=h[6]|0,Le=Ri&8191,Ie=Ri>>>13,Ti=h[7]|0,Oe=Ti&8191,Ne=Ti>>>13,Di=h[8]|0,Re=Di&8191,Te=Di>>>13,Ei=h[9]|0,De=Ei&8191,Ee=Ei>>>13;l.negative=e.negative^o.negative,l.length=19,p=Math.imul(T,ve),a=Math.imul(T,we),a=a+Math.imul(D,ve)|0,y=Math.imul(D,we);var Ft=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Ft>>>26)|0,Ft&=67108863,p=Math.imul(X,ve),a=Math.imul(X,we),a=a+Math.imul(ee,ve)|0,y=Math.imul(ee,we),p=p+Math.imul(T,Me)|0,a=a+Math.imul(T,ye)|0,a=a+Math.imul(D,Me)|0,y=y+Math.imul(D,ye)|0;var qt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(qt>>>26)|0,qt&=67108863,p=Math.imul(Q,ve),a=Math.imul(Q,we),a=a+Math.imul(te,ve)|0,y=Math.imul(te,we),p=p+Math.imul(X,Me)|0,a=a+Math.imul(X,ye)|0,a=a+Math.imul(ee,Me)|0,y=y+Math.imul(ee,ye)|0,p=p+Math.imul(T,be)|0,a=a+Math.imul(T,_e)|0,a=a+Math.imul(D,be)|0,y=y+Math.imul(D,_e)|0;var Ut=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,p=Math.imul(Y,ve),a=Math.imul(Y,we),a=a+Math.imul(W,ve)|0,y=Math.imul(W,we),p=p+Math.imul(Q,Me)|0,a=a+Math.imul(Q,ye)|0,a=a+Math.imul(te,Me)|0,y=y+Math.imul(te,ye)|0,p=p+Math.imul(X,be)|0,a=a+Math.imul(X,_e)|0,a=a+Math.imul(ee,be)|0,y=y+Math.imul(ee,_e)|0,p=p+Math.imul(T,ke)|0,a=a+Math.imul(T,Se)|0,a=a+Math.imul(D,ke)|0,y=y+Math.imul(D,Se)|0;var jt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(jt>>>26)|0,jt&=67108863,p=Math.imul(oe,ve),a=Math.imul(oe,we),a=a+Math.imul(se,ve)|0,y=Math.imul(se,we),p=p+Math.imul(Y,Me)|0,a=a+Math.imul(Y,ye)|0,a=a+Math.imul(W,Me)|0,y=y+Math.imul(W,ye)|0,p=p+Math.imul(Q,be)|0,a=a+Math.imul(Q,_e)|0,a=a+Math.imul(te,be)|0,y=y+Math.imul(te,_e)|0,p=p+Math.imul(X,ke)|0,a=a+Math.imul(X,Se)|0,a=a+Math.imul(ee,ke)|0,y=y+Math.imul(ee,Se)|0,p=p+Math.imul(T,Ce)|0,a=a+Math.imul(T,Ae)|0,a=a+Math.imul(D,Ce)|0,y=y+Math.imul(D,Ae)|0;var Zt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,p=Math.imul(ae,ve),a=Math.imul(ae,we),a=a+Math.imul(le,ve)|0,y=Math.imul(le,we),p=p+Math.imul(oe,Me)|0,a=a+Math.imul(oe,ye)|0,a=a+Math.imul(se,Me)|0,y=y+Math.imul(se,ye)|0,p=p+Math.imul(Y,be)|0,a=a+Math.imul(Y,_e)|0,a=a+Math.imul(W,be)|0,y=y+Math.imul(W,_e)|0,p=p+Math.imul(Q,ke)|0,a=a+Math.imul(Q,Se)|0,a=a+Math.imul(te,ke)|0,y=y+Math.imul(te,Se)|0,p=p+Math.imul(X,Ce)|0,a=a+Math.imul(X,Ae)|0,a=a+Math.imul(ee,Ce)|0,y=y+Math.imul(ee,Ae)|0,p=p+Math.imul(T,Pe)|0,a=a+Math.imul(T,xe)|0,a=a+Math.imul(D,Pe)|0,y=y+Math.imul(D,xe)|0;var zt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(zt>>>26)|0,zt&=67108863,p=Math.imul(ue,ve),a=Math.imul(ue,we),a=a+Math.imul(fe,ve)|0,y=Math.imul(fe,we),p=p+Math.imul(ae,Me)|0,a=a+Math.imul(ae,ye)|0,a=a+Math.imul(le,Me)|0,y=y+Math.imul(le,ye)|0,p=p+Math.imul(oe,be)|0,a=a+Math.imul(oe,_e)|0,a=a+Math.imul(se,be)|0,y=y+Math.imul(se,_e)|0,p=p+Math.imul(Y,ke)|0,a=a+Math.imul(Y,Se)|0,a=a+Math.imul(W,ke)|0,y=y+Math.imul(W,Se)|0,p=p+Math.imul(Q,Ce)|0,a=a+Math.imul(Q,Ae)|0,a=a+Math.imul(te,Ce)|0,y=y+Math.imul(te,Ae)|0,p=p+Math.imul(X,Pe)|0,a=a+Math.imul(X,xe)|0,a=a+Math.imul(ee,Pe)|0,y=y+Math.imul(ee,xe)|0,p=p+Math.imul(T,Le)|0,a=a+Math.imul(T,Ie)|0,a=a+Math.imul(D,Le)|0,y=y+Math.imul(D,Ie)|0;var $t=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+($t>>>26)|0,$t&=67108863,p=Math.imul(he,ve),a=Math.imul(he,we),a=a+Math.imul(ce,ve)|0,y=Math.imul(ce,we),p=p+Math.imul(ue,Me)|0,a=a+Math.imul(ue,ye)|0,a=a+Math.imul(fe,Me)|0,y=y+Math.imul(fe,ye)|0,p=p+Math.imul(ae,be)|0,a=a+Math.imul(ae,_e)|0,a=a+Math.imul(le,be)|0,y=y+Math.imul(le,_e)|0,p=p+Math.imul(oe,ke)|0,a=a+Math.imul(oe,Se)|0,a=a+Math.imul(se,ke)|0,y=y+Math.imul(se,Se)|0,p=p+Math.imul(Y,Ce)|0,a=a+Math.imul(Y,Ae)|0,a=a+Math.imul(W,Ce)|0,y=y+Math.imul(W,Ae)|0,p=p+Math.imul(Q,Pe)|0,a=a+Math.imul(Q,xe)|0,a=a+Math.imul(te,Pe)|0,y=y+Math.imul(te,xe)|0,p=p+Math.imul(X,Le)|0,a=a+Math.imul(X,Ie)|0,a=a+Math.imul(ee,Le)|0,y=y+Math.imul(ee,Ie)|0,p=p+Math.imul(T,Oe)|0,a=a+Math.imul(T,Ne)|0,a=a+Math.imul(D,Oe)|0,y=y+Math.imul(D,Ne)|0;var Kt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,p=Math.imul(de,ve),a=Math.imul(de,we),a=a+Math.imul(pe,ve)|0,y=Math.imul(pe,we),p=p+Math.imul(he,Me)|0,a=a+Math.imul(he,ye)|0,a=a+Math.imul(ce,Me)|0,y=y+Math.imul(ce,ye)|0,p=p+Math.imul(ue,be)|0,a=a+Math.imul(ue,_e)|0,a=a+Math.imul(fe,be)|0,y=y+Math.imul(fe,_e)|0,p=p+Math.imul(ae,ke)|0,a=a+Math.imul(ae,Se)|0,a=a+Math.imul(le,ke)|0,y=y+Math.imul(le,Se)|0,p=p+Math.imul(oe,Ce)|0,a=a+Math.imul(oe,Ae)|0,a=a+Math.imul(se,Ce)|0,y=y+Math.imul(se,Ae)|0,p=p+Math.imul(Y,Pe)|0,a=a+Math.imul(Y,xe)|0,a=a+Math.imul(W,Pe)|0,y=y+Math.imul(W,xe)|0,p=p+Math.imul(Q,Le)|0,a=a+Math.imul(Q,Ie)|0,a=a+Math.imul(te,Le)|0,y=y+Math.imul(te,Ie)|0,p=p+Math.imul(X,Oe)|0,a=a+Math.imul(X,Ne)|0,a=a+Math.imul(ee,Oe)|0,y=y+Math.imul(ee,Ne)|0,p=p+Math.imul(T,Re)|0,a=a+Math.imul(T,Te)|0,a=a+Math.imul(D,Re)|0,y=y+Math.imul(D,Te)|0;var Ht=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,p=Math.imul(ge,ve),a=Math.imul(ge,we),a=a+Math.imul(me,ve)|0,y=Math.imul(me,we),p=p+Math.imul(de,Me)|0,a=a+Math.imul(de,ye)|0,a=a+Math.imul(pe,Me)|0,y=y+Math.imul(pe,ye)|0,p=p+Math.imul(he,be)|0,a=a+Math.imul(he,_e)|0,a=a+Math.imul(ce,be)|0,y=y+Math.imul(ce,_e)|0,p=p+Math.imul(ue,ke)|0,a=a+Math.imul(ue,Se)|0,a=a+Math.imul(fe,ke)|0,y=y+Math.imul(fe,Se)|0,p=p+Math.imul(ae,Ce)|0,a=a+Math.imul(ae,Ae)|0,a=a+Math.imul(le,Ce)|0,y=y+Math.imul(le,Ae)|0,p=p+Math.imul(oe,Pe)|0,a=a+Math.imul(oe,xe)|0,a=a+Math.imul(se,Pe)|0,y=y+Math.imul(se,xe)|0,p=p+Math.imul(Y,Le)|0,a=a+Math.imul(Y,Ie)|0,a=a+Math.imul(W,Le)|0,y=y+Math.imul(W,Ie)|0,p=p+Math.imul(Q,Oe)|0,a=a+Math.imul(Q,Ne)|0,a=a+Math.imul(te,Oe)|0,y=y+Math.imul(te,Ne)|0,p=p+Math.imul(X,Re)|0,a=a+Math.imul(X,Te)|0,a=a+Math.imul(ee,Re)|0,y=y+Math.imul(ee,Te)|0,p=p+Math.imul(T,De)|0,a=a+Math.imul(T,Ee)|0,a=a+Math.imul(D,De)|0,y=y+Math.imul(D,Ee)|0;var Wt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,p=Math.imul(ge,Me),a=Math.imul(ge,ye),a=a+Math.imul(me,Me)|0,y=Math.imul(me,ye),p=p+Math.imul(de,be)|0,a=a+Math.imul(de,_e)|0,a=a+Math.imul(pe,be)|0,y=y+Math.imul(pe,_e)|0,p=p+Math.imul(he,ke)|0,a=a+Math.imul(he,Se)|0,a=a+Math.imul(ce,ke)|0,y=y+Math.imul(ce,Se)|0,p=p+Math.imul(ue,Ce)|0,a=a+Math.imul(ue,Ae)|0,a=a+Math.imul(fe,Ce)|0,y=y+Math.imul(fe,Ae)|0,p=p+Math.imul(ae,Pe)|0,a=a+Math.imul(ae,xe)|0,a=a+Math.imul(le,Pe)|0,y=y+Math.imul(le,xe)|0,p=p+Math.imul(oe,Le)|0,a=a+Math.imul(oe,Ie)|0,a=a+Math.imul(se,Le)|0,y=y+Math.imul(se,Ie)|0,p=p+Math.imul(Y,Oe)|0,a=a+Math.imul(Y,Ne)|0,a=a+Math.imul(W,Oe)|0,y=y+Math.imul(W,Ne)|0,p=p+Math.imul(Q,Re)|0,a=a+Math.imul(Q,Te)|0,a=a+Math.imul(te,Re)|0,y=y+Math.imul(te,Te)|0,p=p+Math.imul(X,De)|0,a=a+Math.imul(X,Ee)|0,a=a+Math.imul(ee,De)|0,y=y+Math.imul(ee,Ee)|0;var Gt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,p=Math.imul(ge,be),a=Math.imul(ge,_e),a=a+Math.imul(me,be)|0,y=Math.imul(me,_e),p=p+Math.imul(de,ke)|0,a=a+Math.imul(de,Se)|0,a=a+Math.imul(pe,ke)|0,y=y+Math.imul(pe,Se)|0,p=p+Math.imul(he,Ce)|0,a=a+Math.imul(he,Ae)|0,a=a+Math.imul(ce,Ce)|0,y=y+Math.imul(ce,Ae)|0,p=p+Math.imul(ue,Pe)|0,a=a+Math.imul(ue,xe)|0,a=a+Math.imul(fe,Pe)|0,y=y+Math.imul(fe,xe)|0,p=p+Math.imul(ae,Le)|0,a=a+Math.imul(ae,Ie)|0,a=a+Math.imul(le,Le)|0,y=y+Math.imul(le,Ie)|0,p=p+Math.imul(oe,Oe)|0,a=a+Math.imul(oe,Ne)|0,a=a+Math.imul(se,Oe)|0,y=y+Math.imul(se,Ne)|0,p=p+Math.imul(Y,Re)|0,a=a+Math.imul(Y,Te)|0,a=a+Math.imul(W,Re)|0,y=y+Math.imul(W,Te)|0,p=p+Math.imul(Q,De)|0,a=a+Math.imul(Q,Ee)|0,a=a+Math.imul(te,De)|0,y=y+Math.imul(te,Ee)|0;var Vt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,p=Math.imul(ge,ke),a=Math.imul(ge,Se),a=a+Math.imul(me,ke)|0,y=Math.imul(me,Se),p=p+Math.imul(de,Ce)|0,a=a+Math.imul(de,Ae)|0,a=a+Math.imul(pe,Ce)|0,y=y+Math.imul(pe,Ae)|0,p=p+Math.imul(he,Pe)|0,a=a+Math.imul(he,xe)|0,a=a+Math.imul(ce,Pe)|0,y=y+Math.imul(ce,xe)|0,p=p+Math.imul(ue,Le)|0,a=a+Math.imul(ue,Ie)|0,a=a+Math.imul(fe,Le)|0,y=y+Math.imul(fe,Ie)|0,p=p+Math.imul(ae,Oe)|0,a=a+Math.imul(ae,Ne)|0,a=a+Math.imul(le,Oe)|0,y=y+Math.imul(le,Ne)|0,p=p+Math.imul(oe,Re)|0,a=a+Math.imul(oe,Te)|0,a=a+Math.imul(se,Re)|0,y=y+Math.imul(se,Te)|0,p=p+Math.imul(Y,De)|0,a=a+Math.imul(Y,Ee)|0,a=a+Math.imul(W,De)|0,y=y+Math.imul(W,Ee)|0;var Xt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,p=Math.imul(ge,Ce),a=Math.imul(ge,Ae),a=a+Math.imul(me,Ce)|0,y=Math.imul(me,Ae),p=p+Math.imul(de,Pe)|0,a=a+Math.imul(de,xe)|0,a=a+Math.imul(pe,Pe)|0,y=y+Math.imul(pe,xe)|0,p=p+Math.imul(he,Le)|0,a=a+Math.imul(he,Ie)|0,a=a+Math.imul(ce,Le)|0,y=y+Math.imul(ce,Ie)|0,p=p+Math.imul(ue,Oe)|0,a=a+Math.imul(ue,Ne)|0,a=a+Math.imul(fe,Oe)|0,y=y+Math.imul(fe,Ne)|0,p=p+Math.imul(ae,Re)|0,a=a+Math.imul(ae,Te)|0,a=a+Math.imul(le,Re)|0,y=y+Math.imul(le,Te)|0,p=p+Math.imul(oe,De)|0,a=a+Math.imul(oe,Ee)|0,a=a+Math.imul(se,De)|0,y=y+Math.imul(se,Ee)|0;var Qt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,p=Math.imul(ge,Pe),a=Math.imul(ge,xe),a=a+Math.imul(me,Pe)|0,y=Math.imul(me,xe),p=p+Math.imul(de,Le)|0,a=a+Math.imul(de,Ie)|0,a=a+Math.imul(pe,Le)|0,y=y+Math.imul(pe,Ie)|0,p=p+Math.imul(he,Oe)|0,a=a+Math.imul(he,Ne)|0,a=a+Math.imul(ce,Oe)|0,y=y+Math.imul(ce,Ne)|0,p=p+Math.imul(ue,Re)|0,a=a+Math.imul(ue,Te)|0,a=a+Math.imul(fe,Re)|0,y=y+Math.imul(fe,Te)|0,p=p+Math.imul(ae,De)|0,a=a+Math.imul(ae,Ee)|0,a=a+Math.imul(le,De)|0,y=y+Math.imul(le,Ee)|0;var Yt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,p=Math.imul(ge,Le),a=Math.imul(ge,Ie),a=a+Math.imul(me,Le)|0,y=Math.imul(me,Ie),p=p+Math.imul(de,Oe)|0,a=a+Math.imul(de,Ne)|0,a=a+Math.imul(pe,Oe)|0,y=y+Math.imul(pe,Ne)|0,p=p+Math.imul(he,Re)|0,a=a+Math.imul(he,Te)|0,a=a+Math.imul(ce,Re)|0,y=y+Math.imul(ce,Te)|0,p=p+Math.imul(ue,De)|0,a=a+Math.imul(ue,Ee)|0,a=a+Math.imul(fe,De)|0,y=y+Math.imul(fe,Ee)|0;var Jt=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,p=Math.imul(ge,Oe),a=Math.imul(ge,Ne),a=a+Math.imul(me,Oe)|0,y=Math.imul(me,Ne),p=p+Math.imul(de,Re)|0,a=a+Math.imul(de,Te)|0,a=a+Math.imul(pe,Re)|0,y=y+Math.imul(pe,Te)|0,p=p+Math.imul(he,De)|0,a=a+Math.imul(he,Ee)|0,a=a+Math.imul(ce,De)|0,y=y+Math.imul(ce,Ee)|0;var ei=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(ei>>>26)|0,ei&=67108863,p=Math.imul(ge,Re),a=Math.imul(ge,Te),a=a+Math.imul(me,Re)|0,y=Math.imul(me,Te),p=p+Math.imul(de,De)|0,a=a+Math.imul(de,Ee)|0,a=a+Math.imul(pe,De)|0,y=y+Math.imul(pe,Ee)|0;var ti=(S+p|0)+((a&8191)<<13)|0;S=(y+(a>>>13)|0)+(ti>>>26)|0,ti&=67108863,p=Math.imul(ge,De),a=Math.imul(ge,Ee),a=a+Math.imul(me,De)|0,y=Math.imul(me,Ee);var ii=(S+p|0)+((a&8191)<<13)|0;return S=(y+(a>>>13)|0)+(ii>>>26)|0,ii&=67108863,g[0]=Ft,g[1]=qt,g[2]=Ut,g[3]=jt,g[4]=Zt,g[5]=zt,g[6]=$t,g[7]=Kt,g[8]=Ht,g[9]=Wt,g[10]=Gt,g[11]=Vt,g[12]=Xt,g[13]=Qt,g[14]=Yt,g[15]=Jt,g[16]=ei,g[17]=ti,g[18]=ii,S!==0&&(g[19]=S,l.length++),l};Math.imul||(Z=j);function I(c,e,o){o.negative=e.negative^c.negative,o.length=c.length+e.length;for(var l=0,f=0,h=0;h<o.length-1;h++){var g=f;f=0;for(var S=l&67108863,p=Math.min(h,e.length-1),a=Math.max(0,h-c.length+1);a<=p;a++){var y=h-a,E=c.words[y]|0,T=e.words[a]|0,D=E*T,U=D&67108863;g=g+(D/67108864|0)|0,U=U+S|0,S=U&67108863,g=g+(U>>>26)|0,f+=g>>>26,g&=67108863}o.words[h]=S,l=g,g=f}return l!==0?o.words[h]=l:o.length--,o._strip()}function F(c,e,o){return I(c,e,o)}t.prototype.mulTo=function(e,o){var l,f=this.length+e.length;return this.length===10&&e.length===10?l=Z(this,e,o):f<63?l=j(this,e,o):f<1024?l=I(this,e,o):l=F(this,e,o),l};function q(c,e){this.x=c,this.y=e}q.prototype.makeRBT=function(e){for(var o=new Array(e),l=t.prototype._countBits(e)-1,f=0;f<e;f++)o[f]=this.revBin(f,l,e);return o},q.prototype.revBin=function(e,o,l){if(e===0||e===l-1)return e;for(var f=0,h=0;h<o;h++)f|=(e&1)<<o-h-1,e>>=1;return f},q.prototype.permute=function(e,o,l,f,h,g){for(var S=0;S<g;S++)f[S]=o[e[S]],h[S]=l[e[S]]},q.prototype.transform=function(e,o,l,f,h,g){this.permute(g,e,o,l,f,h);for(var S=1;S<h;S<<=1)for(var p=S<<1,a=Math.cos(2*Math.PI/p),y=Math.sin(2*Math.PI/p),E=0;E<h;E+=p)for(var T=a,D=y,U=0;U<S;U++){var X=l[E+U],ee=f[E+U],He=l[E+U+S],Q=f[E+U+S],te=T*He-D*Q;Q=T*Q+D*He,He=te,l[E+U]=X+He,f[E+U]=ee+Q,l[E+U+S]=X-He,f[E+U+S]=ee-Q,U!==p&&(te=a*T-y*D,D=a*D+y*T,T=te)}},q.prototype.guessLen13b=function(e,o){var l=Math.max(o,e)|1,f=l&1,h=0;for(l=l/2|0;l;l=l>>>1)h++;return 1<<h+1+f},q.prototype.conjugate=function(e,o,l){if(!(l<=1))for(var f=0;f<l/2;f++){var h=e[f];e[f]=e[l-f-1],e[l-f-1]=h,h=o[f],o[f]=-o[l-f-1],o[l-f-1]=-h}},q.prototype.normalize13b=function(e,o){for(var l=0,f=0;f<o/2;f++){var h=Math.round(e[2*f+1]/o)*8192+Math.round(e[2*f]/o)+l;e[f]=h&67108863,h<67108864?l=0:l=h/67108864|0}return e},q.prototype.convert13b=function(e,o,l,f){for(var h=0,g=0;g<o;g++)h=h+(e[g]|0),l[2*g]=h&8191,h=h>>>13,l[2*g+1]=h&8191,h=h>>>13;for(g=2*o;g<f;++g)l[g]=0;n(h===0),n((h&-8192)===0)},q.prototype.stub=function(e){for(var o=new Array(e),l=0;l<e;l++)o[l]=0;return o},q.prototype.mulp=function(e,o,l){var f=2*this.guessLen13b(e.length,o.length),h=this.makeRBT(f),g=this.stub(f),S=new Array(f),p=new Array(f),a=new Array(f),y=new Array(f),E=new Array(f),T=new Array(f),D=l.words;D.length=f,this.convert13b(e.words,e.length,S,f),this.convert13b(o.words,o.length,y,f),this.transform(S,g,p,a,f,h),this.transform(y,g,E,T,f,h);for(var U=0;U<f;U++){var X=p[U]*E[U]-a[U]*T[U];a[U]=p[U]*T[U]+a[U]*E[U],p[U]=X}return this.conjugate(p,a,f),this.transform(p,a,D,g,f,h),this.conjugate(D,g,f),this.normalize13b(D,f),l.negative=e.negative^o.negative,l.length=e.length+o.length,l._strip()},t.prototype.mul=function(e){var o=new t(null);return o.words=new Array(this.length+e.length),this.mulTo(e,o)},t.prototype.mulf=function(e){var o=new t(null);return o.words=new Array(this.length+e.length),F(this,e,o)},t.prototype.imul=function(e){return this.clone().mulTo(e,this)},t.prototype.imuln=function(e){var o=e<0;o&&(e=-e),n(typeof e=="number"),n(e<67108864);for(var l=0,f=0;f<this.length;f++){var h=(this.words[f]|0)*e,g=(h&67108863)+(l&67108863);l>>=26,l+=h/67108864|0,l+=g>>>26,this.words[f]=g&67108863}return l!==0&&(this.words[f]=l,this.length++),this.length=e===0?1:this.length,o?this.ineg():this},t.prototype.muln=function(e){return this.clone().imuln(e)},t.prototype.sqr=function(){return this.mul(this)},t.prototype.isqr=function(){return this.imul(this.clone())},t.prototype.pow=function(e){var o=R(e);if(o.length===0)return new t(1);for(var l=this,f=0;f<o.length&&o[f]===0;f++,l=l.sqr());if(++f<o.length)for(var h=l.sqr();f<o.length;f++,h=h.sqr())o[f]!==0&&(l=l.mul(h));return l},t.prototype.iushln=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26,f=67108863>>>26-o<<26-o,h;if(o!==0){var g=0;for(h=0;h<this.length;h++){var S=this.words[h]&f,p=(this.words[h]|0)-S<<o;this.words[h]=p|g,g=S>>>26-o}g&&(this.words[h]=g,this.length++)}if(l!==0){for(h=this.length-1;h>=0;h--)this.words[h+l]=this.words[h];for(h=0;h<l;h++)this.words[h]=0;this.length+=l}return this._strip()},t.prototype.ishln=function(e){return n(this.negative===0),this.iushln(e)},t.prototype.iushrn=function(e,o,l){n(typeof e=="number"&&e>=0);var f;o?f=(o-o%26)/26:f=0;var h=e%26,g=Math.min((e-h)/26,this.length),S=67108863^67108863>>>h<<h,p=l;if(f-=g,f=Math.max(0,f),p){for(var a=0;a<g;a++)p.words[a]=this.words[a];p.length=g}if(g!==0)if(this.length>g)for(this.length-=g,a=0;a<this.length;a++)this.words[a]=this.words[a+g];else this.words[0]=0,this.length=1;var y=0;for(a=this.length-1;a>=0&&(y!==0||a>=f);a--){var E=this.words[a]|0;this.words[a]=y<<26-h|E>>>h,y=E&S}return p&&y!==0&&(p.words[p.length++]=y),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},t.prototype.ishrn=function(e,o,l){return n(this.negative===0),this.iushrn(e,o,l)},t.prototype.shln=function(e){return this.clone().ishln(e)},t.prototype.ushln=function(e){return this.clone().iushln(e)},t.prototype.shrn=function(e){return this.clone().ishrn(e)},t.prototype.ushrn=function(e){return this.clone().iushrn(e)},t.prototype.testn=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26,f=1<<o;if(this.length<=l)return!1;var h=this.words[l];return!!(h&f)},t.prototype.imaskn=function(e){n(typeof e=="number"&&e>=0);var o=e%26,l=(e-o)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(o!==0&&l++,this.length=Math.min(l,this.length),o!==0){var f=67108863^67108863>>>o<<o;this.words[this.length-1]&=f}return this._strip()},t.prototype.maskn=function(e){return this.clone().imaskn(e)},t.prototype.iaddn=function(e){return n(typeof e=="number"),n(e<67108864),e<0?this.isubn(-e):this.negative!==0?this.length===1&&(this.words[0]|0)<=e?(this.words[0]=e-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},t.prototype._iaddn=function(e){this.words[0]+=e;for(var o=0;o<this.length&&this.words[o]>=67108864;o++)this.words[o]-=67108864,o===this.length-1?this.words[o+1]=1:this.words[o+1]++;return this.length=Math.max(this.length,o+1),this},t.prototype.isubn=function(e){if(n(typeof e=="number"),n(e<67108864),e<0)return this.iaddn(-e);if(this.negative!==0)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var o=0;o<this.length&&this.words[o]<0;o++)this.words[o]+=67108864,this.words[o+1]-=1;return this._strip()},t.prototype.addn=function(e){return this.clone().iaddn(e)},t.prototype.subn=function(e){return this.clone().isubn(e)},t.prototype.iabs=function(){return this.negative=0,this},t.prototype.abs=function(){return this.clone().iabs()},t.prototype._ishlnsubmul=function(e,o,l){var f=e.length+l,h;this._expand(f);var g,S=0;for(h=0;h<e.length;h++){g=(this.words[h+l]|0)+S;var p=(e.words[h]|0)*o;g-=p&67108863,S=(g>>26)-(p/67108864|0),this.words[h+l]=g&67108863}for(;h<this.length-l;h++)g=(this.words[h+l]|0)+S,S=g>>26,this.words[h+l]=g&67108863;if(S===0)return this._strip();for(n(S===-1),S=0,h=0;h<this.length;h++)g=-(this.words[h]|0)+S,S=g>>26,this.words[h]=g&67108863;return this.negative=1,this._strip()},t.prototype._wordDiv=function(e,o){var l=this.length-e.length,f=this.clone(),h=e,g=h.words[h.length-1]|0,S=this._countBits(g);l=26-S,l!==0&&(h=h.ushln(l),f.iushln(l),g=h.words[h.length-1]|0);var p=f.length-h.length,a;if(o!=="mod"){a=new t(null),a.length=p+1,a.words=new Array(a.length);for(var y=0;y<a.length;y++)a.words[y]=0}var E=f.clone()._ishlnsubmul(h,1,p);E.negative===0&&(f=E,a&&(a.words[p]=1));for(var T=p-1;T>=0;T--){var D=(f.words[h.length+T]|0)*67108864+(f.words[h.length+T-1]|0);for(D=Math.min(D/g|0,67108863),f._ishlnsubmul(h,D,T);f.negative!==0;)D--,f.negative=0,f._ishlnsubmul(h,1,T),f.isZero()||(f.negative^=1);a&&(a.words[T]=D)}return a&&a._strip(),f._strip(),o!=="div"&&l!==0&&f.iushrn(l),{div:a||null,mod:f}},t.prototype.divmod=function(e,o,l){if(n(!e.isZero()),this.isZero())return{div:new t(0),mod:new t(0)};var f,h,g;return this.negative!==0&&e.negative===0?(g=this.neg().divmod(e,o),o!=="mod"&&(f=g.div.neg()),o!=="div"&&(h=g.mod.neg(),l&&h.negative!==0&&h.iadd(e)),{div:f,mod:h}):this.negative===0&&e.negative!==0?(g=this.divmod(e.neg(),o),o!=="mod"&&(f=g.div.neg()),{div:f,mod:g.mod}):(this.negative&e.negative)!==0?(g=this.neg().divmod(e.neg(),o),o!=="div"&&(h=g.mod.neg(),l&&h.negative!==0&&h.isub(e)),{div:g.div,mod:h}):e.length>this.length||this.cmp(e)<0?{div:new t(0),mod:this}:e.length===1?o==="div"?{div:this.divn(e.words[0]),mod:null}:o==="mod"?{div:null,mod:new t(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new t(this.modrn(e.words[0]))}:this._wordDiv(e,o)},t.prototype.div=function(e){return this.divmod(e,"div",!1).div},t.prototype.mod=function(e){return this.divmod(e,"mod",!1).mod},t.prototype.umod=function(e){return this.divmod(e,"mod",!0).mod},t.prototype.divRound=function(e){var o=this.divmod(e);if(o.mod.isZero())return o.div;var l=o.div.negative!==0?o.mod.isub(e):o.mod,f=e.ushrn(1),h=e.andln(1),g=l.cmp(f);return g<0||h===1&&g===0?o.div:o.div.negative!==0?o.div.isubn(1):o.div.iaddn(1)},t.prototype.modrn=function(e){var o=e<0;o&&(e=-e),n(e<=67108863);for(var l=(1<<26)%e,f=0,h=this.length-1;h>=0;h--)f=(l*f+(this.words[h]|0))%e;return o?-f:f},t.prototype.modn=function(e){return this.modrn(e)},t.prototype.idivn=function(e){var o=e<0;o&&(e=-e),n(e<=67108863);for(var l=0,f=this.length-1;f>=0;f--){var h=(this.words[f]|0)+l*67108864;this.words[f]=h/e|0,l=h%e}return this._strip(),o?this.ineg():this},t.prototype.divn=function(e){return this.clone().idivn(e)},t.prototype.egcd=function(e){n(e.negative===0),n(!e.isZero());var o=this,l=e.clone();o.negative!==0?o=o.umod(e):o=o.clone();for(var f=new t(1),h=new t(0),g=new t(0),S=new t(1),p=0;o.isEven()&&l.isEven();)o.iushrn(1),l.iushrn(1),++p;for(var a=l.clone(),y=o.clone();!o.isZero();){for(var E=0,T=1;(o.words[0]&T)===0&&E<26;++E,T<<=1);if(E>0)for(o.iushrn(E);E-- >0;)(f.isOdd()||h.isOdd())&&(f.iadd(a),h.isub(y)),f.iushrn(1),h.iushrn(1);for(var D=0,U=1;(l.words[0]&U)===0&&D<26;++D,U<<=1);if(D>0)for(l.iushrn(D);D-- >0;)(g.isOdd()||S.isOdd())&&(g.iadd(a),S.isub(y)),g.iushrn(1),S.iushrn(1);o.cmp(l)>=0?(o.isub(l),f.isub(g),h.isub(S)):(l.isub(o),g.isub(f),S.isub(h))}return{a:g,b:S,gcd:l.iushln(p)}},t.prototype._invmp=function(e){n(e.negative===0),n(!e.isZero());var o=this,l=e.clone();o.negative!==0?o=o.umod(e):o=o.clone();for(var f=new t(1),h=new t(0),g=l.clone();o.cmpn(1)>0&&l.cmpn(1)>0;){for(var S=0,p=1;(o.words[0]&p)===0&&S<26;++S,p<<=1);if(S>0)for(o.iushrn(S);S-- >0;)f.isOdd()&&f.iadd(g),f.iushrn(1);for(var a=0,y=1;(l.words[0]&y)===0&&a<26;++a,y<<=1);if(a>0)for(l.iushrn(a);a-- >0;)h.isOdd()&&h.iadd(g),h.iushrn(1);o.cmp(l)>=0?(o.isub(l),f.isub(h)):(l.isub(o),h.isub(f))}var E;return o.cmpn(1)===0?E=f:E=h,E.cmpn(0)<0&&E.iadd(e),E},t.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var o=this.clone(),l=e.clone();o.negative=0,l.negative=0;for(var f=0;o.isEven()&&l.isEven();f++)o.iushrn(1),l.iushrn(1);do{for(;o.isEven();)o.iushrn(1);for(;l.isEven();)l.iushrn(1);var h=o.cmp(l);if(h<0){var g=o;o=l,l=g}else if(h===0||l.cmpn(1)===0)break;o.isub(l)}while(!0);return l.iushln(f)},t.prototype.invm=function(e){return this.egcd(e).a.umod(e)},t.prototype.isEven=function(){return(this.words[0]&1)===0},t.prototype.isOdd=function(){return(this.words[0]&1)===1},t.prototype.andln=function(e){return this.words[0]&e},t.prototype.bincn=function(e){n(typeof e=="number");var o=e%26,l=(e-o)/26,f=1<<o;if(this.length<=l)return this._expand(l+1),this.words[l]|=f,this;for(var h=f,g=l;h!==0&&g<this.length;g++){var S=this.words[g]|0;S+=h,h=S>>>26,S&=67108863,this.words[g]=S}return h!==0&&(this.words[g]=h,this.length++),this},t.prototype.isZero=function(){return this.length===1&&this.words[0]===0},t.prototype.cmpn=function(e){var o=e<0;if(this.negative!==0&&!o)return-1;if(this.negative===0&&o)return 1;this._strip();var l;if(this.length>1)l=1;else{o&&(e=-e),n(e<=67108863,"Number is too big");var f=this.words[0]|0;l=f===e?0:f<e?-1:1}return this.negative!==0?-l|0:l},t.prototype.cmp=function(e){if(this.negative!==0&&e.negative===0)return-1;if(this.negative===0&&e.negative!==0)return 1;var o=this.ucmp(e);return this.negative!==0?-o|0:o},t.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var o=0,l=this.length-1;l>=0;l--){var f=this.words[l]|0,h=e.words[l]|0;if(f!==h){f<h?o=-1:f>h&&(o=1);break}}return o},t.prototype.gtn=function(e){return this.cmpn(e)===1},t.prototype.gt=function(e){return this.cmp(e)===1},t.prototype.gten=function(e){return this.cmpn(e)>=0},t.prototype.gte=function(e){return this.cmp(e)>=0},t.prototype.ltn=function(e){return this.cmpn(e)===-1},t.prototype.lt=function(e){return this.cmp(e)===-1},t.prototype.lten=function(e){return this.cmpn(e)<=0},t.prototype.lte=function(e){return this.cmp(e)<=0},t.prototype.eqn=function(e){return this.cmpn(e)===0},t.prototype.eq=function(e){return this.cmp(e)===0},t.red=function(e){return new x(e)},t.prototype.toRed=function(e){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),e.convertTo(this)._forceRed(e)},t.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},t.prototype._forceRed=function(e){return this.red=e,this},t.prototype.forceRed=function(e){return n(!this.red,"Already a number in reduction context"),this._forceRed(e)},t.prototype.redAdd=function(e){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},t.prototype.redIAdd=function(e){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},t.prototype.redSub=function(e){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},t.prototype.redISub=function(e){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},t.prototype.redShl=function(e){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},t.prototype.redMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},t.prototype.redIMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},t.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},t.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},t.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},t.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},t.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},t.prototype.redPow=function(e){return n(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var J={k256:null,p224:null,p192:null,p25519:null};function $(c,e){this.name=c,this.p=new t(e,16),this.n=this.p.bitLength(),this.k=new t(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}$.prototype._tmp=function(){var e=new t(null);return e.words=new Array(Math.ceil(this.n/13)),e},$.prototype.ireduce=function(e){var o=e,l;do this.split(o,this.tmp),o=this.imulK(o),o=o.iadd(this.tmp),l=o.bitLength();while(l>this.n);var f=l<this.n?-1:o.ucmp(this.p);return f===0?(o.words[0]=0,o.length=1):f>0?o.isub(this.p):o.strip!==void 0?o.strip():o._strip(),o},$.prototype.split=function(e,o){e.iushrn(this.n,0,o)},$.prototype.imulK=function(e){return e.imul(this.k)};function V(){$.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(V,$),V.prototype.split=function(e,o){for(var l=4194303,f=Math.min(e.length,9),h=0;h<f;h++)o.words[h]=e.words[h];if(o.length=f,e.length<=9){e.words[0]=0,e.length=1;return}var g=e.words[9];for(o.words[o.length++]=g&l,h=10;h<e.length;h++){var S=e.words[h]|0;e.words[h-10]=(S&l)<<4|g>>>22,g=S}g>>>=22,e.words[h-10]=g,g===0&&e.length>10?e.length-=10:e.length-=9},V.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var o=0,l=0;l<e.length;l++){var f=e.words[l]|0;o+=f*977,e.words[l]=o&67108863,o=f*64+(o/67108864|0)}return e.words[e.length-1]===0&&(e.length--,e.words[e.length-1]===0&&e.length--),e};function m(){$.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(m,$);function b(){$.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(b,$);function k(){$.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(k,$),k.prototype.imulK=function(e){for(var o=0,l=0;l<e.length;l++){var f=(e.words[l]|0)*19+o,h=f&67108863;f>>>=26,e.words[l]=h,o=f}return o!==0&&(e.words[e.length++]=o),e},t._prime=function(e){if(J[e])return J[e];var o;if(e==="k256")o=new V;else if(e==="p224")o=new m;else if(e==="p192")o=new b;else if(e==="p25519")o=new k;else throw new Error("Unknown prime "+e);return J[e]=o,o};function x(c){if(typeof c=="string"){var e=t._prime(c);this.m=e.p,this.prime=e}else n(c.gtn(1),"modulus must be greater than 1"),this.m=c,this.prime=null}x.prototype._verify1=function(e){n(e.negative===0,"red works only with positives"),n(e.red,"red works only with red numbers")},x.prototype._verify2=function(e,o){n((e.negative|o.negative)===0,"red works only with positives"),n(e.red&&e.red===o.red,"red works only with red numbers")},x.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(M(e,e.umod(this.m)._forceRed(this)),e)},x.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},x.prototype.add=function(e,o){this._verify2(e,o);var l=e.add(o);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},x.prototype.iadd=function(e,o){this._verify2(e,o);var l=e.iadd(o);return l.cmp(this.m)>=0&&l.isub(this.m),l},x.prototype.sub=function(e,o){this._verify2(e,o);var l=e.sub(o);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},x.prototype.isub=function(e,o){this._verify2(e,o);var l=e.isub(o);return l.cmpn(0)<0&&l.iadd(this.m),l},x.prototype.shl=function(e,o){return this._verify1(e),this.imod(e.ushln(o))},x.prototype.imul=function(e,o){return this._verify2(e,o),this.imod(e.imul(o))},x.prototype.mul=function(e,o){return this._verify2(e,o),this.imod(e.mul(o))},x.prototype.isqr=function(e){return this.imul(e,e.clone())},x.prototype.sqr=function(e){return this.mul(e,e)},x.prototype.sqrt=function(e){if(e.isZero())return e.clone();var o=this.m.andln(3);if(n(o%2===1),o===3){var l=this.m.add(new t(1)).iushrn(2);return this.pow(e,l)}for(var f=this.m.subn(1),h=0;!f.isZero()&&f.andln(1)===0;)h++,f.iushrn(1);n(!f.isZero());var g=new t(1).toRed(this),S=g.redNeg(),p=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new t(2*a*a).toRed(this);this.pow(a,p).cmp(S)!==0;)a.redIAdd(S);for(var y=this.pow(a,f),E=this.pow(e,f.addn(1).iushrn(1)),T=this.pow(e,f),D=h;T.cmp(g)!==0;){for(var U=T,X=0;U.cmp(g)!==0;X++)U=U.redSqr();n(X<D);var ee=this.pow(y,new t(1).iushln(D-X-1));E=E.redMul(ee),y=ee.redSqr(),T=T.redMul(y),D=X}return E},x.prototype.invm=function(e){var o=e._invmp(this.m);return o.negative!==0?(o.negative=0,this.imod(o).redNeg()):this.imod(o)},x.prototype.pow=function(e,o){if(o.isZero())return new t(1).toRed(this);if(o.cmpn(1)===0)return e.clone();var l=4,f=new Array(1<<l);f[0]=new t(1).toRed(this),f[1]=e;for(var h=2;h<f.length;h++)f[h]=this.mul(f[h-1],e);var g=f[0],S=0,p=0,a=o.bitLength()%26;for(a===0&&(a=26),h=o.length-1;h>=0;h--){for(var y=o.words[h],E=a-1;E>=0;E--){var T=y>>E&1;if(g!==f[0]&&(g=this.sqr(g)),T===0&&S===0){p=0;continue}S<<=1,S|=T,p++,!(p!==l&&(h!==0||E!==0))&&(g=this.mul(g,f[S]),p=0,S=0)}a=26}return g},x.prototype.convertTo=function(e){var o=e.umod(this.m);return o===e?o.clone():o},x.prototype.convertFrom=function(e){var o=e.clone();return o.red=null,o},t.mont=function(e){return new P(e)};function P(c){x.call(this,c),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new t(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}s(P,x),P.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},P.prototype.convertFrom=function(e){var o=this.imod(e.mul(this.rinv));return o.red=null,o},P.prototype.imul=function(e,o){if(e.isZero()||o.isZero())return e.words[0]=0,e.length=1,e;var l=e.imul(o),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).iushrn(this.shift),g=h;return h.cmp(this.m)>=0?g=h.isub(this.m):h.cmpn(0)<0&&(g=h.iadd(this.m)),g._forceRed(this)},P.prototype.mul=function(e,o){if(e.isZero()||o.isZero())return new t(0)._forceRed(this);var l=e.mul(o),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=l.isub(f).iushrn(this.shift),g=h;return h.cmp(this.m)>=0?g=h.isub(this.m):h.cmpn(0)<0&&(g=h.iadd(this.m)),g._forceRed(this)},P.prototype.invm=function(e){var o=this.imod(e._invmp(this.m).mul(this.r2));return o._forceRed(this)}})(typeof vi>"u"||vi,dr)});var Ln={};Lr(Ln,{CetusLeverageSDK:()=>yt,default:()=>xn,leverage_mainnet:()=>ni});module.exports=Ir(Ln);var wr=require("@cetusprotocol/common-sdk");var _t=require("@cetusprotocol/common-sdk");var ni={full_rpc_url:_t.FullRpcUrlMainnet,env:"mainnet",aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:_t.DefaultProviders,leverage:{package_id:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",published_at:"0xa65b136a35b9371b74a00f6d4ee21100c0cfce95ae3bef10c123ce698a2cf2b7",version:0,config:{global_config_id:"0xf6c5da03798ff33dd4036aa1fe8b8321f8d41b279247abb5c01254e12b05c19b",markets_table_id:"0x2720d2dfe2b50f700edb69dabd8b51d611961521682a935f09c01d191000f8d0"}},suilend:{package_id:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf",published_at:"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444",config:{lendingMarket:[{name:"Main market",slug:"main",id:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",type:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",ownerCapId:"0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927"},{name:"STEAMM LM",slug:"steamm-lm",id:"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",type:"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",ownerCapId:"0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",isHidden:!0}],lendingMarketId:"0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",lendingMarketType:"0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",apiUrl:"https://d10td5ybgrf39v.cloudfront.net"}}};var Qi=require("@suilend/sdk/client"),re=require("@suilend/sdk");var Or=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,oi=Math.ceil,Ge=Math.floor,$e="[BigNumber Error] ",Fi=$e+"Number primitive has more than 15 significant digits: ",Xe=1e14,G=14,si=9007199254740991,ai=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],at=1e7,Fe=1e9;function qi(i){var r,n,s,t=I.prototype={constructor:I,toString:null,valueOf:null},u=new I(1),d=20,v=4,w=-7,M=21,_=-1e7,C=1e7,A=!1,L=1,B=0,R={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},j="0123456789abcdefghijklmnopqrstuvwxyz",Z=!0;function I(m,b){var k,x,P,c,e,o,l,f,h=this;if(!(h instanceof I))return new I(m,b);if(b==null){if(m&&m._isBigNumber===!0){h.s=m.s,!m.c||m.e>C?h.c=h.e=null:m.e<_?h.c=[h.e=0]:(h.e=m.e,h.c=m.c.slice());return}if((o=typeof m=="number")&&m*0==0){if(h.s=1/m<0?(m=-m,-1):1,m===~~m){for(c=0,e=m;e>=10;e/=10,c++);c>C?h.c=h.e=null:(h.e=c,h.c=[m]);return}f=String(m)}else{if(!Or.test(f=String(m)))return s(h,f,o);h.s=f.charCodeAt(0)==45?(f=f.slice(1),-1):1}(c=f.indexOf("."))>-1&&(f=f.replace(".","")),(e=f.search(/e/i))>0?(c<0&&(c=e),c+=+f.slice(e+1),f=f.substring(0,e)):c<0&&(c=f.length)}else{if(ne(b,2,j.length,"Base"),b==10&&Z)return h=new I(m),$(h,d+h.e+1,v);if(f=String(m),o=typeof m=="number"){if(m*0!=0)return s(h,f,o,b);if(h.s=1/m<0?(f=f.slice(1),-1):1,I.DEBUG&&f.replace(/^0\.0*|\./,"").length>15)throw Error(Fi+m)}else h.s=f.charCodeAt(0)===45?(f=f.slice(1),-1):1;for(k=j.slice(0,b),c=e=0,l=f.length;e<l;e++)if(k.indexOf(x=f.charAt(e))<0){if(x=="."){if(e>c){c=l;continue}}else if(!P&&(f==f.toUpperCase()&&(f=f.toLowerCase())||f==f.toLowerCase()&&(f=f.toUpperCase()))){P=!0,e=-1,c=0;continue}return s(h,String(m),o,b)}o=!1,f=n(f,b,10,h.s),(c=f.indexOf("."))>-1?f=f.replace(".",""):c=f.length}for(e=0;f.charCodeAt(e)===48;e++);for(l=f.length;f.charCodeAt(--l)===48;);if(f=f.slice(e,++l)){if(l-=e,o&&I.DEBUG&&l>15&&(m>si||m!==Ge(m)))throw Error(Fi+h.s*m);if((c=c-e-1)>C)h.c=h.e=null;else if(c<_)h.c=[h.e=0];else{if(h.e=c,h.c=[],e=(c+1)%G,c<0&&(e+=G),e<l){for(e&&h.c.push(+f.slice(0,e)),l-=G;e<l;)h.c.push(+f.slice(e,e+=G));e=G-(f=f.slice(e)).length}else e-=l;for(;e--;f+="0");h.c.push(+f)}}else h.c=[h.e=0]}I.clone=qi,I.ROUND_UP=0,I.ROUND_DOWN=1,I.ROUND_CEIL=2,I.ROUND_FLOOR=3,I.ROUND_HALF_UP=4,I.ROUND_HALF_DOWN=5,I.ROUND_HALF_EVEN=6,I.ROUND_HALF_CEIL=7,I.ROUND_HALF_FLOOR=8,I.EUCLID=9,I.config=I.set=function(m){var b,k;if(m!=null)if(typeof m=="object"){if(m.hasOwnProperty(b="DECIMAL_PLACES")&&(k=m[b],ne(k,0,Fe,b),d=k),m.hasOwnProperty(b="ROUNDING_MODE")&&(k=m[b],ne(k,0,8,b),v=k),m.hasOwnProperty(b="EXPONENTIAL_AT")&&(k=m[b],k&&k.pop?(ne(k[0],-Fe,0,b),ne(k[1],0,Fe,b),w=k[0],M=k[1]):(ne(k,-Fe,Fe,b),w=-(M=k<0?-k:k))),m.hasOwnProperty(b="RANGE"))if(k=m[b],k&&k.pop)ne(k[0],-Fe,-1,b),ne(k[1],1,Fe,b),_=k[0],C=k[1];else if(ne(k,-Fe,Fe,b),k)_=-(C=k<0?-k:k);else throw Error($e+b+" cannot be zero: "+k);if(m.hasOwnProperty(b="CRYPTO"))if(k=m[b],k===!!k)if(k)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))A=k;else throw A=!k,Error($e+"crypto unavailable");else A=k;else throw Error($e+b+" not true or false: "+k);if(m.hasOwnProperty(b="MODULO_MODE")&&(k=m[b],ne(k,0,9,b),L=k),m.hasOwnProperty(b="POW_PRECISION")&&(k=m[b],ne(k,0,Fe,b),B=k),m.hasOwnProperty(b="FORMAT"))if(k=m[b],typeof k=="object")R=k;else throw Error($e+b+" not an object: "+k);if(m.hasOwnProperty(b="ALPHABET"))if(k=m[b],typeof k=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(k))Z=k.slice(0,10)=="0123456789",j=k;else throw Error($e+b+" invalid: "+k)}else throw Error($e+"Object expected: "+m);return{DECIMAL_PLACES:d,ROUNDING_MODE:v,EXPONENTIAL_AT:[w,M],RANGE:[_,C],CRYPTO:A,MODULO_MODE:L,POW_PRECISION:B,FORMAT:R,ALPHABET:j}},I.isBigNumber=function(m){if(!m||m._isBigNumber!==!0)return!1;if(!I.DEBUG)return!0;var b,k,x=m.c,P=m.e,c=m.s;e:if({}.toString.call(x)=="[object Array]"){if((c===1||c===-1)&&P>=-Fe&&P<=Fe&&P===Ge(P)){if(x[0]===0){if(P===0&&x.length===1)return!0;break e}if(b=(P+1)%G,b<1&&(b+=G),String(x[0]).length==b){for(b=0;b<x.length;b++)if(k=x[b],k<0||k>=Xe||k!==Ge(k))break e;if(k!==0)return!0}}}else if(x===null&&P===null&&(c===null||c===1||c===-1))return!0;throw Error($e+"Invalid BigNumber: "+m)},I.maximum=I.max=function(){return q(arguments,-1)},I.minimum=I.min=function(){return q(arguments,1)},I.random=(function(){var m=9007199254740992,b=Math.random()*m&2097151?function(){return Ge(Math.random()*m)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(k){var x,P,c,e,o,l=0,f=[],h=new I(u);if(k==null?k=d:ne(k,0,Fe),e=oi(k/G),A)if(crypto.getRandomValues){for(x=crypto.getRandomValues(new Uint32Array(e*=2));l<e;)o=x[l]*131072+(x[l+1]>>>11),o>=9e15?(P=crypto.getRandomValues(new Uint32Array(2)),x[l]=P[0],x[l+1]=P[1]):(f.push(o%1e14),l+=2);l=e/2}else if(crypto.randomBytes){for(x=crypto.randomBytes(e*=7);l<e;)o=(x[l]&31)*281474976710656+x[l+1]*1099511627776+x[l+2]*4294967296+x[l+3]*16777216+(x[l+4]<<16)+(x[l+5]<<8)+x[l+6],o>=9e15?crypto.randomBytes(7).copy(x,l):(f.push(o%1e14),l+=7);l=e/7}else throw A=!1,Error($e+"crypto unavailable");if(!A)for(;l<e;)o=b(),o<9e15&&(f[l++]=o%1e14);for(e=f[--l],k%=G,e&&k&&(o=ai[G-k],f[l]=Ge(e/o)*o);f[l]===0;f.pop(),l--);if(l<0)f=[c=0];else{for(c=-1;f[0]===0;f.splice(0,1),c-=G);for(l=1,o=f[0];o>=10;o/=10,l++);l<G&&(c-=G-l)}return h.e=c,h.c=f,h}})(),I.sum=function(){for(var m=1,b=arguments,k=new I(b[0]);m<b.length;)k=k.plus(b[m++]);return k},n=(function(){var m="0123456789";function b(k,x,P,c){for(var e,o=[0],l,f=0,h=k.length;f<h;){for(l=o.length;l--;o[l]*=x);for(o[0]+=c.indexOf(k.charAt(f++)),e=0;e<o.length;e++)o[e]>P-1&&(o[e+1]==null&&(o[e+1]=0),o[e+1]+=o[e]/P|0,o[e]%=P)}return o.reverse()}return function(k,x,P,c,e){var o,l,f,h,g,S,p,a,y=k.indexOf("."),E=d,T=v;for(y>=0&&(h=B,B=0,k=k.replace(".",""),a=new I(x),S=a.pow(k.length-y),B=h,a.c=b(nt(We(S.c),S.e,"0"),10,P,m),a.e=a.c.length),p=b(k,x,P,e?(o=j,m):(o=m,j)),f=h=p.length;p[--h]==0;p.pop());if(!p[0])return o.charAt(0);if(y<0?--f:(S.c=p,S.e=f,S.s=c,S=r(S,a,E,T,P),p=S.c,g=S.r,f=S.e),l=f+E+1,y=p[l],h=P/2,g=g||l<0||p[l+1]!=null,g=T<4?(y!=null||g)&&(T==0||T==(S.s<0?3:2)):y>h||y==h&&(T==4||g||T==6&&p[l-1]&1||T==(S.s<0?8:7)),l<1||!p[0])k=g?nt(o.charAt(1),-E,o.charAt(0)):o.charAt(0);else{if(p.length=l,g)for(--P;++p[--l]>P;)p[l]=0,l||(++f,p=[1].concat(p));for(h=p.length;!p[--h];);for(y=0,k="";y<=h;k+=o.charAt(p[y++]));k=nt(k,f,o.charAt(0))}return k}})(),r=(function(){function m(x,P,c){var e,o,l,f,h=0,g=x.length,S=P%at,p=P/at|0;for(x=x.slice();g--;)l=x[g]%at,f=x[g]/at|0,e=p*l+f*S,o=S*l+e%at*at+h,h=(o/c|0)+(e/at|0)+p*f,x[g]=o%c;return h&&(x=[h].concat(x)),x}function b(x,P,c,e){var o,l;if(c!=e)l=c>e?1:-1;else for(o=l=0;o<c;o++)if(x[o]!=P[o]){l=x[o]>P[o]?1:-1;break}return l}function k(x,P,c,e){for(var o=0;c--;)x[c]-=o,o=x[c]<P[c]?1:0,x[c]=o*e+x[c]-P[c];for(;!x[0]&&x.length>1;x.splice(0,1));}return function(x,P,c,e,o){var l,f,h,g,S,p,a,y,E,T,D,U,X,ee,He,Q,te,ze=x.s==P.s?1:-1,Y=x.c,W=P.c;if(!Y||!Y[0]||!W||!W[0])return new I(!x.s||!P.s||(Y?W&&Y[0]==W[0]:!W)?NaN:Y&&Y[0]==0||!W?ze*0:ze/0);for(y=new I(ze),E=y.c=[],f=x.e-P.e,ze=c+f+1,o||(o=Xe,f=Ve(x.e/G)-Ve(P.e/G),ze=ze/G|0),h=0;W[h]==(Y[h]||0);h++);if(W[h]>(Y[h]||0)&&f--,ze<0)E.push(1),g=!0;else{for(ee=Y.length,Q=W.length,h=0,ze+=2,S=Ge(o/(W[0]+1)),S>1&&(W=m(W,S,o),Y=m(Y,S,o),Q=W.length,ee=Y.length),X=Q,T=Y.slice(0,Q),D=T.length;D<Q;T[D++]=0);te=W.slice(),te=[0].concat(te),He=W[0],W[1]>=o/2&&He++;do{if(S=0,l=b(W,T,Q,D),l<0){if(U=T[0],Q!=D&&(U=U*o+(T[1]||0)),S=Ge(U/He),S>1)for(S>=o&&(S=o-1),p=m(W,S,o),a=p.length,D=T.length;b(p,T,a,D)==1;)S--,k(p,Q<a?te:W,a,o),a=p.length,l=1;else S==0&&(l=S=1),p=W.slice(),a=p.length;if(a<D&&(p=[0].concat(p)),k(T,p,D,o),D=T.length,l==-1)for(;b(W,T,Q,D)<1;)S++,k(T,Q<D?te:W,D,o),D=T.length}else l===0&&(S++,T=[0]);E[h++]=S,T[0]?T[D++]=Y[X]||0:(T=[Y[X]],D=1)}while((X++<ee||T[0]!=null)&&ze--);g=T[0]!=null,E[0]||E.splice(0,1)}if(o==Xe){for(h=1,ze=E[0];ze>=10;ze/=10,h++);$(y,c+(y.e=h+f*G-1)+1,e,g)}else y.e=f,y.r=+g;return y}})();function F(m,b,k,x){var P,c,e,o,l;if(k==null?k=v:ne(k,0,8),!m.c)return m.toString();if(P=m.c[0],e=m.e,b==null)l=We(m.c),l=x==1||x==2&&(e<=w||e>=M)?St(l,e):nt(l,e,"0");else if(m=$(new I(m),b,k),c=m.e,l=We(m.c),o=l.length,x==1||x==2&&(b<=c||c<=w)){for(;o<b;l+="0",o++);l=St(l,c)}else if(b-=e+(x===2&&c>e),l=nt(l,c,"0"),c+1>o){if(--b>0)for(l+=".";b--;l+="0");}else if(b+=c-o,b>0)for(c+1==o&&(l+=".");b--;l+="0");return m.s<0&&P?"-"+l:l}function q(m,b){for(var k,x,P=1,c=new I(m[0]);P<m.length;P++)x=new I(m[P]),(!x.s||(k=ct(c,x))===b||k===0&&c.s===b)&&(c=x);return c}function J(m,b,k){for(var x=1,P=b.length;!b[--P];b.pop());for(P=b[0];P>=10;P/=10,x++);return(k=x+k*G-1)>C?m.c=m.e=null:k<_?m.c=[m.e=0]:(m.e=k,m.c=b),m}s=(function(){var m=/^(-?)0([xbo])(?=\w[\w.]*$)/i,b=/^([^.]+)\.$/,k=/^\.([^.]+)$/,x=/^-?(Infinity|NaN)$/,P=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(c,e,o,l){var f,h=o?e:e.replace(P,"");if(x.test(h))c.s=isNaN(h)?null:h<0?-1:1;else{if(!o&&(h=h.replace(m,function(g,S,p){return f=(p=p.toLowerCase())=="x"?16:p=="b"?2:8,!l||l==f?S:g}),l&&(f=l,h=h.replace(b,"$1").replace(k,"0.$1")),e!=h))return new I(h,f);if(I.DEBUG)throw Error($e+"Not a"+(l?" base "+l:"")+" number: "+e);c.s=null}c.c=c.e=null}})();function $(m,b,k,x){var P,c,e,o,l,f,h,g=m.c,S=ai;if(g){e:{for(P=1,o=g[0];o>=10;o/=10,P++);if(c=b-P,c<0)c+=G,e=b,l=g[f=0],h=Ge(l/S[P-e-1]%10);else if(f=oi((c+1)/G),f>=g.length)if(x){for(;g.length<=f;g.push(0));l=h=0,P=1,c%=G,e=c-G+1}else break e;else{for(l=o=g[f],P=1;o>=10;o/=10,P++);c%=G,e=c-G+P,h=e<0?0:Ge(l/S[P-e-1]%10)}if(x=x||b<0||g[f+1]!=null||(e<0?l:l%S[P-e-1]),x=k<4?(h||x)&&(k==0||k==(m.s<0?3:2)):h>5||h==5&&(k==4||x||k==6&&(c>0?e>0?l/S[P-e]:0:g[f-1])%10&1||k==(m.s<0?8:7)),b<1||!g[0])return g.length=0,x?(b-=m.e+1,g[0]=S[(G-b%G)%G],m.e=-b||0):g[0]=m.e=0,m;if(c==0?(g.length=f,o=1,f--):(g.length=f+1,o=S[G-c],g[f]=e>0?Ge(l/S[P-e]%S[e])*o:0),x)for(;;)if(f==0){for(c=1,e=g[0];e>=10;e/=10,c++);for(e=g[0]+=o,o=1;e>=10;e/=10,o++);c!=o&&(m.e++,g[0]==Xe&&(g[0]=1));break}else{if(g[f]+=o,g[f]!=Xe)break;g[f--]=0,o=1}for(c=g.length;g[--c]===0;g.pop());}m.e>C?m.c=m.e=null:m.e<_&&(m.c=[m.e=0])}return m}function V(m){var b,k=m.e;return k===null?m.toString():(b=We(m.c),b=k<=w||k>=M?St(b,k):nt(b,k,"0"),m.s<0?"-"+b:b)}return t.absoluteValue=t.abs=function(){var m=new I(this);return m.s<0&&(m.s=1),m},t.comparedTo=function(m,b){return ct(this,new I(m,b))},t.decimalPlaces=t.dp=function(m,b){var k,x,P,c=this;if(m!=null)return ne(m,0,Fe),b==null?b=v:ne(b,0,8),$(new I(c),m+c.e+1,b);if(!(k=c.c))return null;if(x=((P=k.length-1)-Ve(this.e/G))*G,P=k[P])for(;P%10==0;P/=10,x--);return x<0&&(x=0),x},t.dividedBy=t.div=function(m,b){return r(this,new I(m,b),d,v)},t.dividedToIntegerBy=t.idiv=function(m,b){return r(this,new I(m,b),0,1)},t.exponentiatedBy=t.pow=function(m,b){var k,x,P,c,e,o,l,f,h,g=this;if(m=new I(m),m.c&&!m.isInteger())throw Error($e+"Exponent not an integer: "+V(m));if(b!=null&&(b=new I(b)),o=m.e>14,!g.c||!g.c[0]||g.c[0]==1&&!g.e&&g.c.length==1||!m.c||!m.c[0])return h=new I(Math.pow(+V(g),o?m.s*(2-kt(m)):+V(m))),b?h.mod(b):h;if(l=m.s<0,b){if(b.c?!b.c[0]:!b.s)return new I(NaN);x=!l&&g.isInteger()&&b.isInteger(),x&&(g=g.mod(b))}else{if(m.e>9&&(g.e>0||g.e<-1||(g.e==0?g.c[0]>1||o&&g.c[1]>=24e7:g.c[0]<8e13||o&&g.c[0]<=9999975e7)))return c=g.s<0&&kt(m)?-0:0,g.e>-1&&(c=1/c),new I(l?1/c:c);B&&(c=oi(B/G+2))}for(o?(k=new I(.5),l&&(m.s=1),f=kt(m)):(P=Math.abs(+V(m)),f=P%2),h=new I(u);;){if(f){if(h=h.times(g),!h.c)break;c?h.c.length>c&&(h.c.length=c):x&&(h=h.mod(b))}if(P){if(P=Ge(P/2),P===0)break;f=P%2}else if(m=m.times(k),$(m,m.e+1,1),m.e>14)f=kt(m);else{if(P=+V(m),P===0)break;f=P%2}g=g.times(g),c?g.c&&g.c.length>c&&(g.c.length=c):x&&(g=g.mod(b))}return x?h:(l&&(h=u.div(h)),b?h.mod(b):c?$(h,B,v,e):h)},t.integerValue=function(m){var b=new I(this);return m==null?m=v:ne(m,0,8),$(b,b.e+1,m)},t.isEqualTo=t.eq=function(m,b){return ct(this,new I(m,b))===0},t.isFinite=function(){return!!this.c},t.isGreaterThan=t.gt=function(m,b){return ct(this,new I(m,b))>0},t.isGreaterThanOrEqualTo=t.gte=function(m,b){return(b=ct(this,new I(m,b)))===1||b===0},t.isInteger=function(){return!!this.c&&Ve(this.e/G)>this.c.length-2},t.isLessThan=t.lt=function(m,b){return ct(this,new I(m,b))<0},t.isLessThanOrEqualTo=t.lte=function(m,b){return(b=ct(this,new I(m,b)))===-1||b===0},t.isNaN=function(){return!this.s},t.isNegative=function(){return this.s<0},t.isPositive=function(){return this.s>0},t.isZero=function(){return!!this.c&&this.c[0]==0},t.minus=function(m,b){var k,x,P,c,e=this,o=e.s;if(m=new I(m,b),b=m.s,!o||!b)return new I(NaN);if(o!=b)return m.s=-b,e.plus(m);var l=e.e/G,f=m.e/G,h=e.c,g=m.c;if(!l||!f){if(!h||!g)return h?(m.s=-b,m):new I(g?e:NaN);if(!h[0]||!g[0])return g[0]?(m.s=-b,m):new I(h[0]?e:v==3?-0:0)}if(l=Ve(l),f=Ve(f),h=h.slice(),o=l-f){for((c=o<0)?(o=-o,P=h):(f=l,P=g),P.reverse(),b=o;b--;P.push(0));P.reverse()}else for(x=(c=(o=h.length)<(b=g.length))?o:b,o=b=0;b<x;b++)if(h[b]!=g[b]){c=h[b]<g[b];break}if(c&&(P=h,h=g,g=P,m.s=-m.s),b=(x=g.length)-(k=h.length),b>0)for(;b--;h[k++]=0);for(b=Xe-1;x>o;){if(h[--x]<g[x]){for(k=x;k&&!h[--k];h[k]=b);--h[k],h[x]+=Xe}h[x]-=g[x]}for(;h[0]==0;h.splice(0,1),--f);return h[0]?J(m,h,f):(m.s=v==3?-1:1,m.c=[m.e=0],m)},t.modulo=t.mod=function(m,b){var k,x,P=this;return m=new I(m,b),!P.c||!m.s||m.c&&!m.c[0]?new I(NaN):!m.c||P.c&&!P.c[0]?new I(P):(L==9?(x=m.s,m.s=1,k=r(P,m,0,3),m.s=x,k.s*=x):k=r(P,m,0,L),m=P.minus(k.times(m)),!m.c[0]&&L==1&&(m.s=P.s),m)},t.multipliedBy=t.times=function(m,b){var k,x,P,c,e,o,l,f,h,g,S,p,a,y,E,T=this,D=T.c,U=(m=new I(m,b)).c;if(!D||!U||!D[0]||!U[0])return!T.s||!m.s||D&&!D[0]&&!U||U&&!U[0]&&!D?m.c=m.e=m.s=null:(m.s*=T.s,!D||!U?m.c=m.e=null:(m.c=[0],m.e=0)),m;for(x=Ve(T.e/G)+Ve(m.e/G),m.s*=T.s,l=D.length,g=U.length,l<g&&(a=D,D=U,U=a,P=l,l=g,g=P),P=l+g,a=[];P--;a.push(0));for(y=Xe,E=at,P=g;--P>=0;){for(k=0,S=U[P]%E,p=U[P]/E|0,e=l,c=P+e;c>P;)f=D[--e]%E,h=D[e]/E|0,o=p*f+h*S,f=S*f+o%E*E+a[c]+k,k=(f/y|0)+(o/E|0)+p*h,a[c--]=f%y;a[c]=k}return k?++x:a.splice(0,1),J(m,a,x)},t.negated=function(){var m=new I(this);return m.s=-m.s||null,m},t.plus=function(m,b){var k,x=this,P=x.s;if(m=new I(m,b),b=m.s,!P||!b)return new I(NaN);if(P!=b)return m.s=-b,x.minus(m);var c=x.e/G,e=m.e/G,o=x.c,l=m.c;if(!c||!e){if(!o||!l)return new I(P/0);if(!o[0]||!l[0])return l[0]?m:new I(o[0]?x:P*0)}if(c=Ve(c),e=Ve(e),o=o.slice(),P=c-e){for(P>0?(e=c,k=l):(P=-P,k=o),k.reverse();P--;k.push(0));k.reverse()}for(P=o.length,b=l.length,P-b<0&&(k=l,l=o,o=k,b=P),P=0;b;)P=(o[--b]=o[b]+l[b]+P)/Xe|0,o[b]=Xe===o[b]?0:o[b]%Xe;return P&&(o=[P].concat(o),++e),J(m,o,e)},t.precision=t.sd=function(m,b){var k,x,P,c=this;if(m!=null&&m!==!!m)return ne(m,1,Fe),b==null?b=v:ne(b,0,8),$(new I(c),m,b);if(!(k=c.c))return null;if(P=k.length-1,x=P*G+1,P=k[P]){for(;P%10==0;P/=10,x--);for(P=k[0];P>=10;P/=10,x++);}return m&&c.e+1>x&&(x=c.e+1),x},t.shiftedBy=function(m){return ne(m,-si,si),this.times("1e"+m)},t.squareRoot=t.sqrt=function(){var m,b,k,x,P,c=this,e=c.c,o=c.s,l=c.e,f=d+4,h=new I("0.5");if(o!==1||!e||!e[0])return new I(!o||o<0&&(!e||e[0])?NaN:e?c:1/0);if(o=Math.sqrt(+V(c)),o==0||o==1/0?(b=We(e),(b.length+l)%2==0&&(b+="0"),o=Math.sqrt(+b),l=Ve((l+1)/2)-(l<0||l%2),o==1/0?b="5e"+l:(b=o.toExponential(),b=b.slice(0,b.indexOf("e")+1)+l),k=new I(b)):k=new I(o+""),k.c[0]){for(l=k.e,o=l+f,o<3&&(o=0);;)if(P=k,k=h.times(P.plus(r(c,P,f,1))),We(P.c).slice(0,o)===(b=We(k.c)).slice(0,o))if(k.e<l&&--o,b=b.slice(o-3,o+1),b=="9999"||!x&&b=="4999"){if(!x&&($(P,P.e+d+2,0),P.times(P).eq(c))){k=P;break}f+=4,o+=4,x=1}else{(!+b||!+b.slice(1)&&b.charAt(0)=="5")&&($(k,k.e+d+2,1),m=!k.times(k).eq(c));break}}return $(k,k.e+d+1,v,m)},t.toExponential=function(m,b){return m!=null&&(ne(m,0,Fe),m++),F(this,m,b,1)},t.toFixed=function(m,b){return m!=null&&(ne(m,0,Fe),m=m+this.e+1),F(this,m,b)},t.toFormat=function(m,b,k){var x,P=this;if(k==null)m!=null&&b&&typeof b=="object"?(k=b,b=null):m&&typeof m=="object"?(k=m,m=b=null):k=R;else if(typeof k!="object")throw Error($e+"Argument not an object: "+k);if(x=P.toFixed(m,b),P.c){var c,e=x.split("."),o=+k.groupSize,l=+k.secondaryGroupSize,f=k.groupSeparator||"",h=e[0],g=e[1],S=P.s<0,p=S?h.slice(1):h,a=p.length;if(l&&(c=o,o=l,l=c,a-=c),o>0&&a>0){for(c=a%o||o,h=p.substr(0,c);c<a;c+=o)h+=f+p.substr(c,o);l>0&&(h+=f+p.slice(c)),S&&(h="-"+h)}x=g?h+(k.decimalSeparator||"")+((l=+k.fractionGroupSize)?g.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(k.fractionGroupSeparator||"")):g):h}return(k.prefix||"")+x+(k.suffix||"")},t.toFraction=function(m){var b,k,x,P,c,e,o,l,f,h,g,S,p=this,a=p.c;if(m!=null&&(o=new I(m),!o.isInteger()&&(o.c||o.s!==1)||o.lt(u)))throw Error($e+"Argument "+(o.isInteger()?"out of range: ":"not an integer: ")+V(o));if(!a)return new I(p);for(b=new I(u),f=k=new I(u),x=l=new I(u),S=We(a),c=b.e=S.length-p.e-1,b.c[0]=ai[(e=c%G)<0?G+e:e],m=!m||o.comparedTo(b)>0?c>0?b:f:o,e=C,C=1/0,o=new I(S),l.c[0]=0;h=r(o,b,0,1),P=k.plus(h.times(x)),P.comparedTo(m)!=1;)k=x,x=P,f=l.plus(h.times(P=f)),l=P,b=o.minus(h.times(P=b)),o=P;return P=r(m.minus(k),x,0,1),l=l.plus(P.times(f)),k=k.plus(P.times(x)),l.s=f.s=p.s,c=c*2,g=r(f,x,c,v).minus(p).abs().comparedTo(r(l,k,c,v).minus(p).abs())<1?[f,x]:[l,k],C=e,g},t.toNumber=function(){return+V(this)},t.toPrecision=function(m,b){return m!=null&&ne(m,1,Fe),F(this,m,b,2)},t.toString=function(m){var b,k=this,x=k.s,P=k.e;return P===null?x?(b="Infinity",x<0&&(b="-"+b)):b="NaN":(m==null?b=P<=w||P>=M?St(We(k.c),P):nt(We(k.c),P,"0"):m===10&&Z?(k=$(new I(k),d+P+1,v),b=nt(We(k.c),k.e,"0")):(ne(m,2,j.length,"Base"),b=n(nt(We(k.c),P,"0"),10,m,x,!0)),x<0&&k.c[0]&&(b="-"+b)),b},t.valueOf=t.toJSON=function(){return V(this)},t._isBigNumber=!0,t[Symbol.toStringTag]="BigNumber",t[Symbol.for("nodejs.util.inspect.custom")]=t.valueOf,i!=null&&I.set(i),I}function Ve(i){var r=i|0;return i>0||i===r?r:r-1}function We(i){for(var r,n,s=1,t=i.length,u=i[0]+"";s<t;){for(r=i[s++]+"",n=G-r.length;n--;r="0"+r);u+=r}for(t=u.length;u.charCodeAt(--t)===48;);return u.slice(0,t+1||1)}function ct(i,r){var n,s,t=i.c,u=r.c,d=i.s,v=r.s,w=i.e,M=r.e;if(!d||!v)return null;if(n=t&&!t[0],s=u&&!u[0],n||s)return n?s?0:-v:d;if(d!=v)return d;if(n=d<0,s=w==M,!t||!u)return s?0:!t^n?1:-1;if(!s)return w>M^n?1:-1;for(v=(w=t.length)<(M=u.length)?w:M,d=0;d<v;d++)if(t[d]!=u[d])return t[d]>u[d]^n?1:-1;return w==M?0:w>M^n?1:-1}function ne(i,r,n,s){if(i<r||i>n||i!==Ge(i))throw Error($e+(s||"Argument")+(typeof i=="number"?i<r||i>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(i))}function kt(i){var r=i.c.length-1;return Ve(i.e/G)==r&&i.c[r]%2!=0}function St(i,r){return(i.length>1?i.charAt(0)+"."+i.slice(1):i)+(r<0?"e":"e+")+r}function nt(i,r,n){var s,t;if(r<0){for(t=n+".";++r;t+=n);i=t+i}else if(s=i.length,++r>s){for(t=n,r-=s;--r;t+=n);i+=t}else r<s&&(i=i.slice(0,r)+"."+i.slice(r));return i}var Nr=qi(),et=Nr;var tt=require("@suilend/sdk"),dt=require("@suilend/sui-fe");var Ui=ri(require("crypto")),At=new Uint8Array(256),Ct=At.length;function li(){return Ct>At.length-16&&(Ui.default.randomFillSync(At),Ct=0),At.slice(Ct,Ct+=16)}var qe=[];for(let i=0;i<256;++i)qe.push((i+256).toString(16).slice(1));function ji(i,r=0){return qe[i[r+0]]+qe[i[r+1]]+qe[i[r+2]]+qe[i[r+3]]+"-"+qe[i[r+4]]+qe[i[r+5]]+"-"+qe[i[r+6]]+qe[i[r+7]]+"-"+qe[i[r+8]]+qe[i[r+9]]+"-"+qe[i[r+10]]+qe[i[r+11]]+qe[i[r+12]]+qe[i[r+13]]+qe[i[r+14]]+qe[i[r+15]]}var Zi=ri(require("crypto")),ui={randomUUID:Zi.default.randomUUID};function Rr(i,r,n){if(ui.randomUUID&&!r&&!i)return ui.randomUUID();i=i||{};let s=i.random||(i.rng||li)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,r){n=n||0;for(let t=0;t<16;++t)r[n+t]=s[t];return r}return ji(s)}var Pt=Rr;var zi=require("@cetusprotocol/common-sdk"),fi=10n;function $i(i){return i.depositedAmount.eq(0)?new et(0):i.borrowedAmount.div(i.depositedAmount).times(100)}function hi(i){let r=$i(i);if(!r.gt(100))return(0,tt.linearlyInterpolate)(i.config.interestRate,"utilPercent","aprPercent",r)}function Ki(i){let r=$i(i),n=hi(i);if(!(n===void 0||r.gt(100)))return new et(r.div(100)).times(n.div(100)).times(1-i.config.spreadFeeBps/1e4).times(100)}function Hi(i,r,n,s){let{apiUrl:t}=(0,zi.getPackagerConfigs)(s.sdkOptions.suilend);i===tt.Side.DEPOSIT&&([dt.NORMALIZED_flSUI_COINTYPE,dt.NORMALIZED_jugSUI_COINTYPE].includes(r.coinType)&&n.push({stats:{id:Pt(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LIQ_AG",mintDecimals:0,symbol:"LiqAg Points",iconUrl:`${t}/partners/LiqAg.png`,perDay:new et(.036),side:tt.Side.DEPOSIT},obligationClaims:{}}),r.coinType===dt.NORMALIZED_LBTC_COINTYPE&&n.push({stats:{id:Pt(),isActive:!0,rewardIndex:-1,reserve:r,rewardCoinType:"LOMBARD",mintDecimals:0,symbol:"3x Lombard Lux",iconUrl:`${t}/partners/Lombard Lux.png`,perDay:new et(0),side:tt.Side.DEPOSIT},obligationClaims:{}}))}function Wi(i,r,n){return{...i,depositedAmount:r===tt.Side.DEPOSIT?et.max(i.depositedAmount.plus(n),0):i.depositedAmount,borrowedAmount:r===tt.Side.BORROW?et.max(i.borrowedAmount.plus(n),0):i.borrowedAmount}}function Gi(i,r,n){let s=i===tt.Side.DEPOSIT?r.depositedAmount:r.borrowedAmount,t=i===tt.Side.DEPOSIT?n.depositedAmount:n.borrowedAmount,u=t.eq(0)?new et(-1):s.div(t);return{multiplier:u,isValid:!u.eq(-1)}}function Vi(i,r,n,s){let t=i.map(d=>({...d,stats:{...d.stats,perDay:s?d.stats.perDay.times(n):void 0}})),u=r.map(d=>({...d,stats:{...d.stats,aprPercent:s?d.stats.aprPercent.times(n):void 0}}));return{newPerDayRewards:t,newAprRewards:u}}function Xi(i,r){if(!fi)throw new Error("oraclePriceMultiplierDecimal is required");if(i===0n)throw new Error("Invalid oracle price");if(r<0n){let n=10n**(fi- -r);return i*n}return i/10n**(r+fi)}var je=require("@cetusprotocol/common-sdk"),Yi=require("@mysten/sui/utils"),xt=class{constructor(r){this.getSuiLendCoinInfo=(r,n)=>{let{allLendingMarketData:s,lstAprPercentMap:t}=this.lendingMarketCache??{};if(!s||!t)throw new Error("lendingMarketCache is not initialized");let u=Object.values(s??{})[0],d=u.lendingMarket.reserves.find(V=>V.coinType===r);if(!d)throw new Error("reserve not found");let v=this.obligationsCache?.[u.lendingMarket.id],w="borrow",M=v.rewardMap[d.token.coinType]?.[w]??[],_=(0,re.getFilteredRewards)(M);Hi(w,d,_,this.sdk);let C=(0,re.getStakingYieldAprPercent)(w,d.coinType,t),A=w===re.Side.DEPOSIT?d.depositAprPercent:d.borrowAprPercent,L=A,B=Wi(d,w,n);L=w===re.Side.DEPOSIT?Ki(B):hi(B);let{multiplier:R,isValid:j}=Gi(w,d,B),Z=(0,re.getDedupedPerDayRewards)(_),I=(0,re.getDedupedAprRewards)(_),{newPerDayRewards:F,newAprRewards:q}=Vi(Z,I,R,j),J=(0,re.getTotalAprPercent)(w,A,_,C),$=L===void 0||q.some(V=>V.stats.aprPercent===void 0)?void 0:(0,re.getTotalAprPercent)(w,L,q,C);return{borrowLimit:d.config.borrowLimit.toString(),borrowedAmount:d.borrowedAmount.toString(),remainingBorrowLimit:(0,je.d)(d.config.borrowLimit.toString()).sub((0,je.d)(d.borrowedAmount.toString())).toString(),depositAprPercent:d.depositAprPercent.toString(),totalAprPercent:J.toString(),borrowInterest:A.toString(),stakingYieldAprPercent:C?.toString(),rewardAprPercent:I[0]?.stats.aprPercent?.toString()}};this.createObligation=async r=>{let{lendingMarketId:n,lendingMarketType:s}=(0,je.getPackagerConfigs)(this.sdk.sdkOptions?.suilend);return(await this.getSuilendClient(n,s)).createObligation(r)};this.refreshReservePrices=async(r,n,s)=>{let{lendingMarketId:t,lendingMarketType:u}=(0,je.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),d=`${t}_${u}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let v=await this.suilendClientCache[d].pythClient.getPriceFeedObjectId(n);console.log("\u{1F680}\u{1F680}\u{1F680} ~ suilendModule.ts:322 ~ SuiLendModule ~ priceInfoObjectId:",v),this.suilendClientCache[d].pythConnection.getLatestPriceFeeds,this.suilendClientCache[d].refreshReservePrices(r,v,s)};this.getLatestPriceFeeds=async r=>{let{lendingMarketId:n,lendingMarketType:s}=(0,je.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),t=`${n}_${s}`;if(!this.suilendClientCache)throw new Error("suilendClientCache is not initialized");let u=Array.from(new Set(r.map(w=>(0,Yi.toHEX)(new Uint8Array(w.priceIdentifier.bytes))))),d=await this.suilendClientCache[t].pythConnection.getLatestPriceFeeds(u),v={};return d?.forEach((w,M)=>{let _=w.getPriceUnchecked(),C=r[M];if(_){let{price:A,expo:L}=_,B=(0,je.d)(A).mul((0,je.d)(10).pow((0,je.d)(L))).toString(),R={coin_type:C.coinType.name,price:B,oracle_price:0n,last_update_time:_.publishTime};R.oracle_price=Xi(BigInt(A),BigInt(L)),v[C.coinType.name]=R,this.sdk.updateCache(`getLatestPrice_${R.coin_type}`,R)}}),v};this.getSuiLendReserveInfo=async(r,n)=>{let{lendingMarketId:s}=(0,je.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),{allLendingMarketData:t}=await this.getLendingMarketData(),u=t[s].reserveMap[r],d=t[s].reserveMap[n],v=t[s].refreshedRawReserves.filter(w=>w.coinType.name==(0,je.removeHexPrefix)(r)||w.coinType.name==(0,je.removeHexPrefix)(n));return{baseReserveArrayIndex:u.arrayIndex.toString(),quoteReserveArrayIndex:d.arrayIndex.toString(),reserve:v}};this.sdk=r}async getSuilendClient(r,n){let s=`${r}_${n}`;return this.suilendClientCache||(this.suilendClientCache={}),this.suilendClientCache[s]||(this.suilendClientCache[s]=await Qi.SuilendClient.initialize(r,n,this.sdk.FullClient,!0)),this.suilendClientCache[s]}async getLendingMarketData(r=!1){if(!r&&this.lendingMarketCache)return this.lendingMarketCache;let n=(0,je.getPackagerConfigs)(this.sdk.sdkOptions?.suilend)?.lendingMarket||[];if(!n.length)return console.warn("\u26A0\uFE0F No lending markets configured."),{};try{let[s,t]=await Promise.all([(async()=>Object.fromEntries(await Promise.all(n.map(async d=>{let v=await this.getSuilendClient(d.id,d.type),{lendingMarket:w,coinMetadataMap:M,refreshedRawReserves:_,reserveMap:C,reserveCoinTypes:A,reserveCoinMetadataMap:L,rewardCoinTypes:B,activeRewardCoinTypes:R,rewardCoinMetadataMap:j}=await(0,re.initializeSuilend)(this.sdk.FullClient,v),{rewardPriceMap:Z}=await(0,re.initializeSuilendRewards)(C,R);return[d.id,{suilendClient:v,lendingMarket:w,coinMetadataMap:M,refreshedRawReserves:_,reserveMap:C,reserveCoinTypes:A,reserveCoinMetadataMap:L,rewardPriceMap:Z,rewardCoinTypes:B,activeRewardCoinTypes:R,rewardCoinMetadataMap:j}]}))))(),(async()=>{try{let u=await fetch(`${this.sdk.sdkOptions?.suilend?.config?.apiUrl}/springsui/apy`),d=await u.json();if(u?.statusCode===500)throw new Error("Failed to fetch SpringSui LST APRs");return Object.fromEntries(Object.entries(d).map(([v,w])=>[v,new et(w)]))}catch(u){return console.error(u),{}}})()]);return this.lendingMarketCache={allLendingMarketData:s,lstAprPercentMap:t},this.lendingMarketCache}catch(s){throw console.log("\u{1F680} getLendingMarketData error:",s),s}}async getInitializeObligations(r,n=!1){if(!n&&this.obligationsCache)return this.obligationsCache;r||(r=await this.getLendingMarketData());let s={};for(let t of Object.values(r.allLendingMarketData)){let{obligationOwnerCaps:u,obligations:d}=await(0,re.initializeObligations)(this.sdk.FullClient,t.suilendClient,t.refreshedRawReserves,t.reserveMap,this.sdk.senderAddress),v=(0,re.formatRewards)(t.reserveMap,t.rewardCoinMetadataMap,t.rewardPriceMap,d);s[t.lendingMarket.id]={obligationOwnerCaps:u,obligations:d,rewardMap:v}}return this.obligationsCache=s,this.obligationsCache}async getSuiLendUserData(r,n=!1){let{lstAprPercentMap:s}=this.lendingMarketCache??{},t=this.obligationsCache??{},{lendingMarketId:u}=(0,je.getPackagerConfigs)(this.sdk.sdkOptions?.suilend),d=t[u];if(!d)throw new Error(`No user data found for lending market: ${u}`);if(r){let v=d.obligations.find(M=>M.id===r);if(!v)throw new Error(`Obligation not found: ${r}`);let w=(0,re.getNetAprPercent)(v,d.rewardMap,s??{});return{obligation:v,netAprPercent:w,deposits:v.deposits,borrowedAmount:v.borrowedAmount,depositedAmount:v.depositedAmount,netValueUsd:v.netValueUsd,rewardMap:d.rewardMap}}}priceCheck(r,n=60){let s=Math.floor(Date.now()/1e3);if(!(Math.abs(s-r.last_update_time)>n))return r}};var O=require("@cetusprotocol/common-sdk");var pt=9e15,ht=1e9,ci="0123456789abcdef",Ot="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Nt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",di={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-pt,maxE:pt,crypto:!1},ir,ot,H=!0,Tt="[DecimalError] ",ft=Tt+"Invalid argument: ",rr=Tt+"Precision limit exceeded",nr=Tt+"crypto unavailable",or="[object Decimal]",Ze=Math.floor,Be=Math.pow,Tr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Dr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Er=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,sr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Qe=1e7,K=7,Br=9007199254740991,Fr=Ot.length-1,pi=Nt.length-1,N={toStringTag:or};N.absoluteValue=N.abs=function(){var i=new this.constructor(this);return i.s<0&&(i.s=1),z(i)};N.ceil=function(){return z(new this.constructor(this),this.e+1,2)};N.clampedTo=N.clamp=function(i,r){var n,s=this,t=s.constructor;if(i=new t(i),r=new t(r),!i.s||!r.s)return new t(NaN);if(i.gt(r))throw Error(ft+r);return n=s.cmp(i),n<0?i:s.cmp(r)>0?r:new t(s)};N.comparedTo=N.cmp=function(i){var r,n,s,t,u=this,d=u.d,v=(i=new u.constructor(i)).d,w=u.s,M=i.s;if(!d||!v)return!w||!M?NaN:w!==M?w:d===v?0:!d^w<0?1:-1;if(!d[0]||!v[0])return d[0]?w:v[0]?-M:0;if(w!==M)return w;if(u.e!==i.e)return u.e>i.e^w<0?1:-1;for(s=d.length,t=v.length,r=0,n=s<t?s:t;r<n;++r)if(d[r]!==v[r])return d[r]>v[r]^w<0?1:-1;return s===t?0:s>t^w<0?1:-1};N.cosine=N.cos=function(){var i,r,n=this,s=n.constructor;return n.d?n.d[0]?(i=s.precision,r=s.rounding,s.precision=i+Math.max(n.e,n.sd())+K,s.rounding=1,n=qr(s,hr(s,n)),s.precision=i,s.rounding=r,z(ot==2||ot==3?n.neg():n,i,r,!0)):new s(1):new s(NaN)};N.cubeRoot=N.cbrt=function(){var i,r,n,s,t,u,d,v,w,M,_=this,C=_.constructor;if(!_.isFinite()||_.isZero())return new C(_);for(H=!1,u=_.s*Be(_.s*_,1/3),!u||Math.abs(u)==1/0?(n=Ue(_.d),i=_.e,(u=(i-n.length+1)%3)&&(n+=u==1||u==-2?"0":"00"),u=Be(n,1/3),i=Ze((i+1)/3)-(i%3==(i<0?-1:2)),u==1/0?n="5e"+i:(n=u.toExponential(),n=n.slice(0,n.indexOf("e")+1)+i),s=new C(n),s.s=_.s):s=new C(u.toString()),d=(i=C.precision)+3;;)if(v=s,w=v.times(v).times(v),M=w.plus(_),s=ie(M.plus(_).times(v),M.plus(w),d+2,1),Ue(v.d).slice(0,d)===(n=Ue(s.d)).slice(0,d))if(n=n.slice(d-3,d+1),n=="9999"||!t&&n=="4999"){if(!t&&(z(v,i+1,0),v.times(v).times(v).eq(_))){s=v;break}d+=4,t=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(z(s,i+1,1),r=!s.times(s).times(s).eq(_));break}return H=!0,z(s,i,C.rounding,r)};N.decimalPlaces=N.dp=function(){var i,r=this.d,n=NaN;if(r){if(i=r.length-1,n=(i-Ze(this.e/K))*K,i=r[i],i)for(;i%10==0;i/=10)n--;n<0&&(n=0)}return n};N.dividedBy=N.div=function(i){return ie(this,new this.constructor(i))};N.dividedToIntegerBy=N.divToInt=function(i){var r=this,n=r.constructor;return z(ie(r,new n(i),0,1,1),n.precision,n.rounding)};N.equals=N.eq=function(i){return this.cmp(i)===0};N.floor=function(){return z(new this.constructor(this),this.e+1,3)};N.greaterThan=N.gt=function(i){return this.cmp(i)>0};N.greaterThanOrEqualTo=N.gte=function(i){var r=this.cmp(i);return r==1||r===0};N.hyperbolicCosine=N.cosh=function(){var i,r,n,s,t,u=this,d=u.constructor,v=new d(1);if(!u.isFinite())return new d(u.s?1/0:NaN);if(u.isZero())return v;n=d.precision,s=d.rounding,d.precision=n+Math.max(u.e,u.sd())+4,d.rounding=1,t=u.d.length,t<32?(i=Math.ceil(t/3),r=(1/Et(4,i)).toString()):(i=16,r="2.3283064365386962890625e-10"),u=gt(d,1,u.times(r),new d(1),!0);for(var w,M=i,_=new d(8);M--;)w=u.times(u),u=v.minus(w.times(_.minus(w.times(_))));return z(u,d.precision=n,d.rounding=s,!0)};N.hyperbolicSine=N.sinh=function(){var i,r,n,s,t=this,u=t.constructor;if(!t.isFinite()||t.isZero())return new u(t);if(r=u.precision,n=u.rounding,u.precision=r+Math.max(t.e,t.sd())+4,u.rounding=1,s=t.d.length,s<3)t=gt(u,2,t,t,!0);else{i=1.4*Math.sqrt(s),i=i>16?16:i|0,t=t.times(1/Et(5,i)),t=gt(u,2,t,t,!0);for(var d,v=new u(5),w=new u(16),M=new u(20);i--;)d=t.times(t),t=t.times(v.plus(d.times(w.times(d).plus(M))))}return u.precision=r,u.rounding=n,z(t,r,n,!0)};N.hyperbolicTangent=N.tanh=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+7,s.rounding=1,ie(n.sinh(),n.cosh(),s.precision=i,s.rounding=r)):new s(n.s)};N.inverseCosine=N.acos=function(){var i=this,r=i.constructor,n=i.abs().cmp(1),s=r.precision,t=r.rounding;return n!==-1?n===0?i.isNeg()?it(r,s,t):new r(0):new r(NaN):i.isZero()?it(r,s+4,t).times(.5):(r.precision=s+6,r.rounding=1,i=new r(1).minus(i).div(i.plus(1)).sqrt().atan(),r.precision=s,r.rounding=t,i.times(2))};N.inverseHyperbolicCosine=N.acosh=function(){var i,r,n=this,s=n.constructor;return n.lte(1)?new s(n.eq(1)?0:NaN):n.isFinite()?(i=s.precision,r=s.rounding,s.precision=i+Math.max(Math.abs(n.e),n.sd())+4,s.rounding=1,H=!1,n=n.times(n).minus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln()):new s(n)};N.inverseHyperbolicSine=N.asinh=function(){var i,r,n=this,s=n.constructor;return!n.isFinite()||n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+2*Math.max(Math.abs(n.e),n.sd())+6,s.rounding=1,H=!1,n=n.times(n).plus(1).sqrt().plus(n),H=!0,s.precision=i,s.rounding=r,n.ln())};N.inverseHyperbolicTangent=N.atanh=function(){var i,r,n,s,t=this,u=t.constructor;return t.isFinite()?t.e>=0?new u(t.abs().eq(1)?t.s/0:t.isZero()?t:NaN):(i=u.precision,r=u.rounding,s=t.sd(),Math.max(s,i)<2*-t.e-1?z(new u(t),i,r,!0):(u.precision=n=s-t.e,t=ie(t.plus(1),new u(1).minus(t),n+i,1),u.precision=i+4,u.rounding=1,t=t.ln(),u.precision=i,u.rounding=r,t.times(.5))):new u(NaN)};N.inverseSine=N.asin=function(){var i,r,n,s,t=this,u=t.constructor;return t.isZero()?new u(t):(r=t.abs().cmp(1),n=u.precision,s=u.rounding,r!==-1?r===0?(i=it(u,n+4,s).times(.5),i.s=t.s,i):new u(NaN):(u.precision=n+6,u.rounding=1,t=t.div(new u(1).minus(t.times(t)).sqrt().plus(1)).atan(),u.precision=n,u.rounding=s,t.times(2)))};N.inverseTangent=N.atan=function(){var i,r,n,s,t,u,d,v,w,M=this,_=M.constructor,C=_.precision,A=_.rounding;if(M.isFinite()){if(M.isZero())return new _(M);if(M.abs().eq(1)&&C+4<=pi)return d=it(_,C+4,A).times(.25),d.s=M.s,d}else{if(!M.s)return new _(NaN);if(C+4<=pi)return d=it(_,C+4,A).times(.5),d.s=M.s,d}for(_.precision=v=C+10,_.rounding=1,n=Math.min(28,v/K+2|0),i=n;i;--i)M=M.div(M.times(M).plus(1).sqrt().plus(1));for(H=!1,r=Math.ceil(v/K),s=1,w=M.times(M),d=new _(M),t=M;i!==-1;)if(t=t.times(w),u=d.minus(t.div(s+=2)),t=t.times(w),d=u.plus(t.div(s+=2)),d.d[r]!==void 0)for(i=r;d.d[i]===u.d[i]&&i--;);return n&&(d=d.times(2<<n-1)),H=!0,z(d,_.precision=C,_.rounding=A,!0)};N.isFinite=function(){return!!this.d};N.isInteger=N.isInt=function(){return!!this.d&&Ze(this.e/K)>this.d.length-2};N.isNaN=function(){return!this.s};N.isNegative=N.isNeg=function(){return this.s<0};N.isPositive=N.isPos=function(){return this.s>0};N.isZero=function(){return!!this.d&&this.d[0]===0};N.lessThan=N.lt=function(i){return this.cmp(i)<0};N.lessThanOrEqualTo=N.lte=function(i){return this.cmp(i)<1};N.logarithm=N.log=function(i){var r,n,s,t,u,d,v,w,M=this,_=M.constructor,C=_.precision,A=_.rounding,L=5;if(i==null)i=new _(10),r=!0;else{if(i=new _(i),n=i.d,i.s<0||!n||!n[0]||i.eq(1))return new _(NaN);r=i.eq(10)}if(n=M.d,M.s<0||!n||!n[0]||M.eq(1))return new _(n&&!n[0]?-1/0:M.s!=1?NaN:n?0:1/0);if(r)if(n.length>1)u=!0;else{for(t=n[0];t%10===0;)t/=10;u=t!==1}if(H=!1,v=C+L,d=ut(M,v),s=r?Rt(_,v+10):ut(i,v),w=ie(d,s,v,1),vt(w.d,t=C,A))do if(v+=10,d=ut(M,v),s=r?Rt(_,v+10):ut(i,v),w=ie(d,s,v,1),!u){+Ue(w.d).slice(t+1,t+15)+1==1e14&&(w=z(w,C+1,0));break}while(vt(w.d,t+=10,A));return H=!0,z(w,C,A)};N.minus=N.sub=function(i){var r,n,s,t,u,d,v,w,M,_,C,A,L=this,B=L.constructor;if(i=new B(i),!L.d||!i.d)return!L.s||!i.s?i=new B(NaN):L.d?i.s=-i.s:i=new B(i.d||L.s!==i.s?L:NaN),i;if(L.s!=i.s)return i.s=-i.s,L.plus(i);if(M=L.d,A=i.d,v=B.precision,w=B.rounding,!M[0]||!A[0]){if(A[0])i.s=-i.s;else if(M[0])i=new B(L);else return new B(w===3?-0:0);return H?z(i,v,w):i}if(n=Ze(i.e/K),_=Ze(L.e/K),M=M.slice(),u=_-n,u){for(C=u<0,C?(r=M,u=-u,d=A.length):(r=A,n=_,d=M.length),s=Math.max(Math.ceil(v/K),d)+2,u>s&&(u=s,r.length=1),r.reverse(),s=u;s--;)r.push(0);r.reverse()}else{for(s=M.length,d=A.length,C=s<d,C&&(d=s),s=0;s<d;s++)if(M[s]!=A[s]){C=M[s]<A[s];break}u=0}for(C&&(r=M,M=A,A=r,i.s=-i.s),d=M.length,s=A.length-d;s>0;--s)M[d++]=0;for(s=A.length;s>u;){if(M[--s]<A[s]){for(t=s;t&&M[--t]===0;)M[t]=Qe-1;--M[t],M[s]+=Qe}M[s]-=A[s]}for(;M[--d]===0;)M.pop();for(;M[0]===0;M.shift())--n;return M[0]?(i.d=M,i.e=Dt(M,n),H?z(i,v,w):i):new B(w===3?-0:0)};N.modulo=N.mod=function(i){var r,n=this,s=n.constructor;return i=new s(i),!n.d||!i.s||i.d&&!i.d[0]?new s(NaN):!i.d||n.d&&!n.d[0]?z(new s(n),s.precision,s.rounding):(H=!1,s.modulo==9?(r=ie(n,i.abs(),0,3,1),r.s*=i.s):r=ie(n,i,0,s.modulo,1),r=r.times(i),H=!0,n.minus(r))};N.naturalExponential=N.exp=function(){return gi(this)};N.naturalLogarithm=N.ln=function(){return ut(this)};N.negated=N.neg=function(){var i=new this.constructor(this);return i.s=-i.s,z(i)};N.plus=N.add=function(i){var r,n,s,t,u,d,v,w,M,_,C=this,A=C.constructor;if(i=new A(i),!C.d||!i.d)return!C.s||!i.s?i=new A(NaN):C.d||(i=new A(i.d||C.s===i.s?C:NaN)),i;if(C.s!=i.s)return i.s=-i.s,C.minus(i);if(M=C.d,_=i.d,v=A.precision,w=A.rounding,!M[0]||!_[0])return _[0]||(i=new A(C)),H?z(i,v,w):i;if(u=Ze(C.e/K),s=Ze(i.e/K),M=M.slice(),t=u-s,t){for(t<0?(n=M,t=-t,d=_.length):(n=_,s=u,d=M.length),u=Math.ceil(v/K),d=u>d?u+1:d+1,t>d&&(t=d,n.length=1),n.reverse();t--;)n.push(0);n.reverse()}for(d=M.length,t=_.length,d-t<0&&(t=d,n=_,_=M,M=n),r=0;t;)r=(M[--t]=M[t]+_[t]+r)/Qe|0,M[t]%=Qe;for(r&&(M.unshift(r),++s),d=M.length;M[--d]==0;)M.pop();return i.d=M,i.e=Dt(M,s),H?z(i,v,w):i};N.precision=N.sd=function(i){var r,n=this;if(i!==void 0&&i!==!!i&&i!==1&&i!==0)throw Error(ft+i);return n.d?(r=ar(n.d),i&&n.e+1>r&&(r=n.e+1)):r=NaN,r};N.round=function(){var i=this,r=i.constructor;return z(new r(i),i.e+1,r.rounding)};N.sine=N.sin=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+Math.max(n.e,n.sd())+K,s.rounding=1,n=jr(s,hr(s,n)),s.precision=i,s.rounding=r,z(ot>2?n.neg():n,i,r,!0)):new s(NaN)};N.squareRoot=N.sqrt=function(){var i,r,n,s,t,u,d=this,v=d.d,w=d.e,M=d.s,_=d.constructor;if(M!==1||!v||!v[0])return new _(!M||M<0&&(!v||v[0])?NaN:v?d:1/0);for(H=!1,M=Math.sqrt(+d),M==0||M==1/0?(r=Ue(v),(r.length+w)%2==0&&(r+="0"),M=Math.sqrt(r),w=Ze((w+1)/2)-(w<0||w%2),M==1/0?r="5e"+w:(r=M.toExponential(),r=r.slice(0,r.indexOf("e")+1)+w),s=new _(r)):s=new _(M.toString()),n=(w=_.precision)+3;;)if(u=s,s=u.plus(ie(d,u,n+2,1)).times(.5),Ue(u.d).slice(0,n)===(r=Ue(s.d)).slice(0,n))if(r=r.slice(n-3,n+1),r=="9999"||!t&&r=="4999"){if(!t&&(z(u,w+1,0),u.times(u).eq(d))){s=u;break}n+=4,t=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(z(s,w+1,1),i=!s.times(s).eq(d));break}return H=!0,z(s,w,_.rounding,i)};N.tangent=N.tan=function(){var i,r,n=this,s=n.constructor;return n.isFinite()?n.isZero()?new s(n):(i=s.precision,r=s.rounding,s.precision=i+10,s.rounding=1,n=n.sin(),n.s=1,n=ie(n,new s(1).minus(n.times(n)).sqrt(),i+10,0),s.precision=i,s.rounding=r,z(ot==2||ot==4?n.neg():n,i,r,!0)):new s(NaN)};N.times=N.mul=function(i){var r,n,s,t,u,d,v,w,M,_=this,C=_.constructor,A=_.d,L=(i=new C(i)).d;if(i.s*=_.s,!A||!A[0]||!L||!L[0])return new C(!i.s||A&&!A[0]&&!L||L&&!L[0]&&!A?NaN:!A||!L?i.s/0:i.s*0);for(n=Ze(_.e/K)+Ze(i.e/K),w=A.length,M=L.length,w<M&&(u=A,A=L,L=u,d=w,w=M,M=d),u=[],d=w+M,s=d;s--;)u.push(0);for(s=M;--s>=0;){for(r=0,t=w+s;t>s;)v=u[t]+L[s]*A[t-s-1]+r,u[t--]=v%Qe|0,r=v/Qe|0;u[t]=(u[t]+r)%Qe|0}for(;!u[--d];)u.pop();return r?++n:u.shift(),i.d=u,i.e=Dt(u,n),H?z(i,C.precision,C.rounding):i};N.toBinary=function(i,r){return mi(this,2,i,r)};N.toDecimalPlaces=N.toDP=function(i,r){var n=this,s=n.constructor;return n=new s(n),i===void 0?n:(Ke(i,0,ht),r===void 0?r=s.rounding:Ke(r,0,8),z(n,i+n.e+1,r))};N.toExponential=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=rt(s,!0):(Ke(i,0,ht),r===void 0?r=t.rounding:Ke(r,0,8),s=z(new t(s),i+1,r),n=rt(s,!0,i+1)),s.isNeg()&&!s.isZero()?"-"+n:n};N.toFixed=function(i,r){var n,s,t=this,u=t.constructor;return i===void 0?n=rt(t):(Ke(i,0,ht),r===void 0?r=u.rounding:Ke(r,0,8),s=z(new u(t),i+t.e+1,r),n=rt(s,!1,i+s.e+1)),t.isNeg()&&!t.isZero()?"-"+n:n};N.toFraction=function(i){var r,n,s,t,u,d,v,w,M,_,C,A,L=this,B=L.d,R=L.constructor;if(!B)return new R(L);if(M=n=new R(1),s=w=new R(0),r=new R(s),u=r.e=ar(B)-L.e-1,d=u%K,r.d[0]=Be(10,d<0?K+d:d),i==null)i=u>0?r:M;else{if(v=new R(i),!v.isInt()||v.lt(M))throw Error(ft+v);i=v.gt(r)?u>0?r:M:v}for(H=!1,v=new R(Ue(B)),_=R.precision,R.precision=u=B.length*K*2;C=ie(v,r,0,1,1),t=n.plus(C.times(s)),t.cmp(i)!=1;)n=s,s=t,t=M,M=w.plus(C.times(t)),w=t,t=r,r=v.minus(C.times(t)),v=t;return t=ie(i.minus(n),s,0,1,1),w=w.plus(t.times(M)),n=n.plus(t.times(s)),w.s=M.s=L.s,A=ie(M,s,u,1).minus(L).abs().cmp(ie(w,n,u,1).minus(L).abs())<1?[M,s]:[w,n],R.precision=_,H=!0,A};N.toHexadecimal=N.toHex=function(i,r){return mi(this,16,i,r)};N.toNearest=function(i,r){var n=this,s=n.constructor;if(n=new s(n),i==null){if(!n.d)return n;i=new s(1),r=s.rounding}else{if(i=new s(i),r===void 0?r=s.rounding:Ke(r,0,8),!n.d)return i.s?n:i;if(!i.d)return i.s&&(i.s=n.s),i}return i.d[0]?(H=!1,n=ie(n,i,0,r,1).times(i),H=!0,z(n)):(i.s=n.s,n=i),n};N.toNumber=function(){return+this};N.toOctal=function(i,r){return mi(this,8,i,r)};N.toPower=N.pow=function(i){var r,n,s,t,u,d,v=this,w=v.constructor,M=+(i=new w(i));if(!v.d||!i.d||!v.d[0]||!i.d[0])return new w(Be(+v,M));if(v=new w(v),v.eq(1))return v;if(s=w.precision,u=w.rounding,i.eq(1))return z(v,s,u);if(r=Ze(i.e/K),r>=i.d.length-1&&(n=M<0?-M:M)<=Br)return t=lr(w,v,n,s),i.s<0?new w(1).div(t):z(t,s,u);if(d=v.s,d<0){if(r<i.d.length-1)return new w(NaN);if((i.d[r]&1)==0&&(d=1),v.e==0&&v.d[0]==1&&v.d.length==1)return v.s=d,v}return n=Be(+v,M),r=n==0||!isFinite(n)?Ze(M*(Math.log("0."+Ue(v.d))/Math.LN10+v.e+1)):new w(n+"").e,r>w.maxE+1||r<w.minE-1?new w(r>0?d/0:0):(H=!1,w.rounding=v.s=1,n=Math.min(12,(r+"").length),t=gi(i.times(ut(v,s+n)),s),t.d&&(t=z(t,s+5,1),vt(t.d,s,u)&&(r=s+10,t=z(gi(i.times(ut(v,r+n)),r),r+5,1),+Ue(t.d).slice(s+1,s+15)+1==1e14&&(t=z(t,s+1,0)))),t.s=d,H=!0,w.rounding=u,z(t,s,u))};N.toPrecision=function(i,r){var n,s=this,t=s.constructor;return i===void 0?n=rt(s,s.e<=t.toExpNeg||s.e>=t.toExpPos):(Ke(i,1,ht),r===void 0?r=t.rounding:Ke(r,0,8),s=z(new t(s),i,r),n=rt(s,i<=s.e||s.e<=t.toExpNeg,i)),s.isNeg()&&!s.isZero()?"-"+n:n};N.toSignificantDigits=N.toSD=function(i,r){var n=this,s=n.constructor;return i===void 0?(i=s.precision,r=s.rounding):(Ke(i,1,ht),r===void 0?r=s.rounding:Ke(r,0,8)),z(new s(n),i,r)};N.toString=function(){var i=this,r=i.constructor,n=rt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()&&!i.isZero()?"-"+n:n};N.truncated=N.trunc=function(){return z(new this.constructor(this),this.e+1,1)};N.valueOf=N.toJSON=function(){var i=this,r=i.constructor,n=rt(i,i.e<=r.toExpNeg||i.e>=r.toExpPos);return i.isNeg()?"-"+n:n};function Ue(i){var r,n,s,t=i.length-1,u="",d=i[0];if(t>0){for(u+=d,r=1;r<t;r++)s=i[r]+"",n=K-s.length,n&&(u+=lt(n)),u+=s;d=i[r],s=d+"",n=K-s.length,n&&(u+=lt(n))}else if(d===0)return"0";for(;d%10===0;)d/=10;return u+d}function Ke(i,r,n){if(i!==~~i||i<r||i>n)throw Error(ft+i)}function vt(i,r,n,s){var t,u,d,v;for(u=i[0];u>=10;u/=10)--r;return--r<0?(r+=K,t=0):(t=Math.ceil((r+1)/K),r%=K),u=Be(10,K-r),v=i[t]%u|0,s==null?r<3?(r==0?v=v/100|0:r==1&&(v=v/10|0),d=n<4&&v==99999||n>3&&v==49999||v==5e4||v==0):d=(n<4&&v+1==u||n>3&&v+1==u/2)&&(i[t+1]/u/100|0)==Be(10,r-2)-1||(v==u/2||v==0)&&(i[t+1]/u/100|0)==0:r<4?(r==0?v=v/1e3|0:r==1?v=v/100|0:r==2&&(v=v/10|0),d=(s||n<4)&&v==9999||!s&&n>3&&v==4999):d=((s||n<4)&&v+1==u||!s&&n>3&&v+1==u/2)&&(i[t+1]/u/1e3|0)==Be(10,r-3)-1,d}function Lt(i,r,n){for(var s,t=[0],u,d=0,v=i.length;d<v;){for(u=t.length;u--;)t[u]*=r;for(t[0]+=ci.indexOf(i.charAt(d++)),s=0;s<t.length;s++)t[s]>n-1&&(t[s+1]===void 0&&(t[s+1]=0),t[s+1]+=t[s]/n|0,t[s]%=n)}return t.reverse()}function qr(i,r){var n,s,t;if(r.isZero())return r;s=r.d.length,s<32?(n=Math.ceil(s/3),t=(1/Et(4,n)).toString()):(n=16,t="2.3283064365386962890625e-10"),i.precision+=n,r=gt(i,1,r.times(t),new i(1));for(var u=n;u--;){var d=r.times(r);r=d.times(d).minus(d).times(8).plus(1)}return i.precision-=n,r}var ie=(function(){function i(s,t,u){var d,v=0,w=s.length;for(s=s.slice();w--;)d=s[w]*t+v,s[w]=d%u|0,v=d/u|0;return v&&s.unshift(v),s}function r(s,t,u,d){var v,w;if(u!=d)w=u>d?1:-1;else for(v=w=0;v<u;v++)if(s[v]!=t[v]){w=s[v]>t[v]?1:-1;break}return w}function n(s,t,u,d){for(var v=0;u--;)s[u]-=v,v=s[u]<t[u]?1:0,s[u]=v*d+s[u]-t[u];for(;!s[0]&&s.length>1;)s.shift()}return function(s,t,u,d,v,w){var M,_,C,A,L,B,R,j,Z,I,F,q,J,$,V,m,b,k,x,P,c=s.constructor,e=s.s==t.s?1:-1,o=s.d,l=t.d;if(!o||!o[0]||!l||!l[0])return new c(!s.s||!t.s||(o?l&&o[0]==l[0]:!l)?NaN:o&&o[0]==0||!l?e*0:e/0);for(w?(L=1,_=s.e-t.e):(w=Qe,L=K,_=Ze(s.e/L)-Ze(t.e/L)),x=l.length,b=o.length,Z=new c(e),I=Z.d=[],C=0;l[C]==(o[C]||0);C++);if(l[C]>(o[C]||0)&&_--,u==null?($=u=c.precision,d=c.rounding):v?$=u+(s.e-t.e)+1:$=u,$<0)I.push(1),B=!0;else{if($=$/L+2|0,C=0,x==1){for(A=0,l=l[0],$++;(C<b||A)&&$--;C++)V=A*w+(o[C]||0),I[C]=V/l|0,A=V%l|0;B=A||C<b}else{for(A=w/(l[0]+1)|0,A>1&&(l=i(l,A,w),o=i(o,A,w),x=l.length,b=o.length),m=x,F=o.slice(0,x),q=F.length;q<x;)F[q++]=0;P=l.slice(),P.unshift(0),k=l[0],l[1]>=w/2&&++k;do A=0,M=r(l,F,x,q),M<0?(J=F[0],x!=q&&(J=J*w+(F[1]||0)),A=J/k|0,A>1?(A>=w&&(A=w-1),R=i(l,A,w),j=R.length,q=F.length,M=r(R,F,j,q),M==1&&(A--,n(R,x<j?P:l,j,w))):(A==0&&(M=A=1),R=l.slice()),j=R.length,j<q&&R.unshift(0),n(F,R,q,w),M==-1&&(q=F.length,M=r(l,F,x,q),M<1&&(A++,n(F,x<q?P:l,q,w))),q=F.length):M===0&&(A++,F=[0]),I[C++]=A,M&&F[0]?F[q++]=o[m]||0:(F=[o[m]],q=1);while((m++<b||F[0]!==void 0)&&$--);B=F[0]!==void 0}I[0]||I.shift()}if(L==1)Z.e=_,ir=B;else{for(C=1,A=I[0];A>=10;A/=10)C++;Z.e=C+_*L-1,z(Z,v?u+Z.e+1:u,d,B)}return Z}})();function z(i,r,n,s){var t,u,d,v,w,M,_,C,A,L=i.constructor;e:if(r!=null){if(C=i.d,!C)return i;for(t=1,v=C[0];v>=10;v/=10)t++;if(u=r-t,u<0)u+=K,d=r,_=C[A=0],w=_/Be(10,t-d-1)%10|0;else if(A=Math.ceil((u+1)/K),v=C.length,A>=v)if(s){for(;v++<=A;)C.push(0);_=w=0,t=1,u%=K,d=u-K+1}else break e;else{for(_=v=C[A],t=1;v>=10;v/=10)t++;u%=K,d=u-K+t,w=d<0?0:_/Be(10,t-d-1)%10|0}if(s=s||r<0||C[A+1]!==void 0||(d<0?_:_%Be(10,t-d-1)),M=n<4?(w||s)&&(n==0||n==(i.s<0?3:2)):w>5||w==5&&(n==4||s||n==6&&(u>0?d>0?_/Be(10,t-d):0:C[A-1])%10&1||n==(i.s<0?8:7)),r<1||!C[0])return C.length=0,M?(r-=i.e+1,C[0]=Be(10,(K-r%K)%K),i.e=-r||0):C[0]=i.e=0,i;if(u==0?(C.length=A,v=1,A--):(C.length=A+1,v=Be(10,K-u),C[A]=d>0?(_/Be(10,t-d)%Be(10,d)|0)*v:0),M)for(;;)if(A==0){for(u=1,d=C[0];d>=10;d/=10)u++;for(d=C[0]+=v,v=1;d>=10;d/=10)v++;u!=v&&(i.e++,C[0]==Qe&&(C[0]=1));break}else{if(C[A]+=v,C[A]!=Qe)break;C[A--]=0,v=1}for(u=C.length;C[--u]===0;)C.pop()}return H&&(i.e>L.maxE?(i.d=null,i.e=NaN):i.e<L.minE&&(i.e=0,i.d=[0])),i}function rt(i,r,n){if(!i.isFinite())return fr(i);var s,t=i.e,u=Ue(i.d),d=u.length;return r?(n&&(s=n-d)>0?u=u.charAt(0)+"."+u.slice(1)+lt(s):d>1&&(u=u.charAt(0)+"."+u.slice(1)),u=u+(i.e<0?"e":"e+")+i.e):t<0?(u="0."+lt(-t-1)+u,n&&(s=n-d)>0&&(u+=lt(s))):t>=d?(u+=lt(t+1-d),n&&(s=n-t-1)>0&&(u=u+"."+lt(s))):((s=t+1)<d&&(u=u.slice(0,s)+"."+u.slice(s)),n&&(s=n-d)>0&&(t+1===d&&(u+="."),u+=lt(s))),u}function Dt(i,r){var n=i[0];for(r*=K;n>=10;n/=10)r++;return r}function Rt(i,r,n){if(r>Fr)throw H=!0,n&&(i.precision=n),Error(rr);return z(new i(Ot),r,1,!0)}function it(i,r,n){if(r>pi)throw Error(rr);return z(new i(Nt),r,n,!0)}function ar(i){var r=i.length-1,n=r*K+1;if(r=i[r],r){for(;r%10==0;r/=10)n--;for(r=i[0];r>=10;r/=10)n++}return n}function lt(i){for(var r="";i--;)r+="0";return r}function lr(i,r,n,s){var t,u=new i(1),d=Math.ceil(s/K+4);for(H=!1;;){if(n%2&&(u=u.times(r),er(u.d,d)&&(t=!0)),n=Ze(n/2),n===0){n=u.d.length-1,t&&u.d[n]===0&&++u.d[n];break}r=r.times(r),er(r.d,d)}return H=!0,u}function Ji(i){return i.d[i.d.length-1]&1}function ur(i,r,n){for(var s,t,u=new i(r[0]),d=0;++d<r.length;){if(t=new i(r[d]),!t.s){u=t;break}s=u.cmp(t),(s===n||s===0&&u.s===n)&&(u=t)}return u}function gi(i,r){var n,s,t,u,d,v,w,M=0,_=0,C=0,A=i.constructor,L=A.rounding,B=A.precision;if(!i.d||!i.d[0]||i.e>17)return new A(i.d?i.d[0]?i.s<0?0:1/0:1:i.s?i.s<0?0:i:NaN);for(r==null?(H=!1,w=B):w=r,v=new A(.03125);i.e>-2;)i=i.times(v),C+=5;for(s=Math.log(Be(2,C))/Math.LN10*2+5|0,w+=s,n=u=d=new A(1),A.precision=w;;){if(u=z(u.times(i),w,1),n=n.times(++_),v=d.plus(ie(u,n,w,1)),Ue(v.d).slice(0,w)===Ue(d.d).slice(0,w)){for(t=C;t--;)d=z(d.times(d),w,1);if(r==null)if(M<3&&vt(d.d,w-s,L,M))A.precision=w+=10,n=u=v=new A(1),_=0,M++;else return z(d,A.precision=B,L,H=!0);else return A.precision=B,d}d=v}}function ut(i,r){var n,s,t,u,d,v,w,M,_,C,A,L=1,B=10,R=i,j=R.d,Z=R.constructor,I=Z.rounding,F=Z.precision;if(R.s<0||!j||!j[0]||!R.e&&j[0]==1&&j.length==1)return new Z(j&&!j[0]?-1/0:R.s!=1?NaN:j?0:R);if(r==null?(H=!1,_=F):_=r,Z.precision=_+=B,n=Ue(j),s=n.charAt(0),Math.abs(u=R.e)<15e14){for(;s<7&&s!=1||s==1&&n.charAt(1)>3;)R=R.times(i),n=Ue(R.d),s=n.charAt(0),L++;u=R.e,s>1?(R=new Z("0."+n),u++):R=new Z(s+"."+n.slice(1))}else return M=Rt(Z,_+2,F).times(u+""),R=ut(new Z(s+"."+n.slice(1)),_-B).plus(M),Z.precision=F,r==null?z(R,F,I,H=!0):R;for(C=R,w=d=R=ie(R.minus(1),R.plus(1),_,1),A=z(R.times(R),_,1),t=3;;){if(d=z(d.times(A),_,1),M=w.plus(ie(d,new Z(t),_,1)),Ue(M.d).slice(0,_)===Ue(w.d).slice(0,_))if(w=w.times(2),u!==0&&(w=w.plus(Rt(Z,_+2,F).times(u+""))),w=ie(w,new Z(L),_,1),r==null)if(vt(w.d,_-B,I,v))Z.precision=_+=B,M=d=R=ie(C.minus(1),C.plus(1),_,1),A=z(R.times(R),_,1),t=v=1;else return z(w,Z.precision=F,I,H=!0);else return Z.precision=F,w;w=M,t+=2}}function fr(i){return String(i.s*i.s/0)}function It(i,r){var n,s,t;for((n=r.indexOf("."))>-1&&(r=r.replace(".","")),(s=r.search(/e/i))>0?(n<0&&(n=s),n+=+r.slice(s+1),r=r.substring(0,s)):n<0&&(n=r.length),s=0;r.charCodeAt(s)===48;s++);for(t=r.length;r.charCodeAt(t-1)===48;--t);if(r=r.slice(s,t),r){if(t-=s,i.e=n=n-s-1,i.d=[],s=(n+1)%K,n<0&&(s+=K),s<t){for(s&&i.d.push(+r.slice(0,s)),t-=K;s<t;)i.d.push(+r.slice(s,s+=K));r=r.slice(s),s=K-r.length}else s-=t;for(;s--;)r+="0";i.d.push(+r),H&&(i.e>i.constructor.maxE?(i.d=null,i.e=NaN):i.e<i.constructor.minE&&(i.e=0,i.d=[0]))}else i.e=0,i.d=[0];return i}function Ur(i,r){var n,s,t,u,d,v,w,M,_;if(r.indexOf("_")>-1){if(r=r.replace(/(\d)_(?=\d)/g,"$1"),sr.test(r))return It(i,r)}else if(r==="Infinity"||r==="NaN")return+r||(i.s=NaN),i.e=NaN,i.d=null,i;if(Dr.test(r))n=16,r=r.toLowerCase();else if(Tr.test(r))n=2;else if(Er.test(r))n=8;else throw Error(ft+r);for(u=r.search(/p/i),u>0?(w=+r.slice(u+1),r=r.substring(2,u)):r=r.slice(2),u=r.indexOf("."),d=u>=0,s=i.constructor,d&&(r=r.replace(".",""),v=r.length,u=v-u,t=lr(s,new s(n),u,u*2)),M=Lt(r,n,Qe),_=M.length-1,u=_;M[u]===0;--u)M.pop();return u<0?new s(i.s*0):(i.e=Dt(M,_),i.d=M,H=!1,d&&(i=ie(i,t,v*4)),w&&(i=i.times(Math.abs(w)<54?Be(2,w):wt.pow(2,w))),H=!0,i)}function jr(i,r){var n,s=r.d.length;if(s<3)return r.isZero()?r:gt(i,2,r,r);n=1.4*Math.sqrt(s),n=n>16?16:n|0,r=r.times(1/Et(5,n)),r=gt(i,2,r,r);for(var t,u=new i(5),d=new i(16),v=new i(20);n--;)t=r.times(r),r=r.times(u.plus(t.times(d.times(t).minus(v))));return r}function gt(i,r,n,s,t){var u,d,v,w,M=1,_=i.precision,C=Math.ceil(_/K);for(H=!1,w=n.times(n),v=new i(s);;){if(d=ie(v.times(w),new i(r++*r++),_,1),v=t?s.plus(d):s.minus(d),s=ie(d.times(w),new i(r++*r++),_,1),d=v.plus(s),d.d[C]!==void 0){for(u=C;d.d[u]===v.d[u]&&u--;);if(u==-1)break}u=v,v=s,s=d,d=u,M++}return H=!0,d.d.length=C+1,d}function Et(i,r){for(var n=i;--r;)n*=i;return n}function hr(i,r){var n,s=r.s<0,t=it(i,i.precision,1),u=t.times(.5);if(r=r.abs(),r.lte(u))return ot=s?4:1,r;if(n=r.divToInt(t),n.isZero())ot=s?3:2;else{if(r=r.minus(n.times(t)),r.lte(u))return ot=Ji(n)?s?2:3:s?4:1,r;ot=Ji(n)?s?1:4:s?3:2}return r.minus(t).abs()}function mi(i,r,n,s){var t,u,d,v,w,M,_,C,A,L=i.constructor,B=n!==void 0;if(B?(Ke(n,1,ht),s===void 0?s=L.rounding:Ke(s,0,8)):(n=L.precision,s=L.rounding),!i.isFinite())_=fr(i);else{for(_=rt(i),d=_.indexOf("."),B?(t=2,r==16?n=n*4-3:r==8&&(n=n*3-2)):t=r,d>=0&&(_=_.replace(".",""),A=new L(1),A.e=_.length-d,A.d=Lt(rt(A),10,t),A.e=A.d.length),C=Lt(_,10,t),u=w=C.length;C[--w]==0;)C.pop();if(!C[0])_=B?"0p+0":"0";else{if(d<0?u--:(i=new L(i),i.d=C,i.e=u,i=ie(i,A,n,s,0,t),C=i.d,u=i.e,M=ir),d=C[n],v=t/2,M=M||C[n+1]!==void 0,M=s<4?(d!==void 0||M)&&(s===0||s===(i.s<0?3:2)):d>v||d===v&&(s===4||M||s===6&&C[n-1]&1||s===(i.s<0?8:7)),C.length=n,M)for(;++C[--n]>t-1;)C[n]=0,n||(++u,C.unshift(1));for(w=C.length;!C[w-1];--w);for(d=0,_="";d<w;d++)_+=ci.charAt(C[d]);if(B){if(w>1)if(r==16||r==8){for(d=r==16?4:3,--w;w%d;w++)_+="0";for(C=Lt(_,t,r),w=C.length;!C[w-1];--w);for(d=1,_="1.";d<w;d++)_+=ci.charAt(C[d])}else _=_.charAt(0)+"."+_.slice(1);_=_+(u<0?"p":"p+")+u}else if(u<0){for(;++u;)_="0"+_;_="0."+_}else if(++u>w)for(u-=w;u--;)_+="0";else u<w&&(_=_.slice(0,u)+"."+_.slice(u))}_=(r==16?"0x":r==2?"0b":r==8?"0o":"")+_}return i.s<0?"-"+_:_}function er(i,r){if(i.length>r)return i.length=r,!0}function Zr(i){return new this(i).abs()}function zr(i){return new this(i).acos()}function $r(i){return new this(i).acosh()}function Kr(i,r){return new this(i).plus(r)}function Hr(i){return new this(i).asin()}function Wr(i){return new this(i).asinh()}function Gr(i){return new this(i).atan()}function Vr(i){return new this(i).atanh()}function Xr(i,r){i=new this(i),r=new this(r);var n,s=this.precision,t=this.rounding,u=s+4;return!i.s||!r.s?n=new this(NaN):!i.d&&!r.d?(n=it(this,u,1).times(r.s>0?.25:.75),n.s=i.s):!r.d||i.isZero()?(n=r.s<0?it(this,s,t):new this(0),n.s=i.s):!i.d||r.isZero()?(n=it(this,u,1).times(.5),n.s=i.s):r.s<0?(this.precision=u,this.rounding=1,n=this.atan(ie(i,r,u,1)),r=it(this,u,1),this.precision=s,this.rounding=t,n=i.s<0?n.minus(r):n.plus(r)):n=this.atan(ie(i,r,u,1)),n}function Qr(i){return new this(i).cbrt()}function Yr(i){return z(i=new this(i),i.e+1,2)}function Jr(i,r,n){return new this(i).clamp(r,n)}function en(i){if(!i||typeof i!="object")throw Error(Tt+"Object expected");var r,n,s,t=i.defaults===!0,u=["precision",1,ht,"rounding",0,8,"toExpNeg",-pt,0,"toExpPos",0,pt,"maxE",0,pt,"minE",-pt,0,"modulo",0,9];for(r=0;r<u.length;r+=3)if(n=u[r],t&&(this[n]=di[n]),(s=i[n])!==void 0)if(Ze(s)===s&&s>=u[r+1]&&s<=u[r+2])this[n]=s;else throw Error(ft+n+": "+s);if(n="crypto",t&&(this[n]=di[n]),(s=i[n])!==void 0)if(s===!0||s===!1||s===0||s===1)if(s)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(nr);else this[n]=!1;else throw Error(ft+n+": "+s);return this}function tn(i){return new this(i).cos()}function rn(i){return new this(i).cosh()}function cr(i){var r,n,s;function t(u){var d,v,w,M=this;if(!(M instanceof t))return new t(u);if(M.constructor=t,tr(u)){M.s=u.s,H?!u.d||u.e>t.maxE?(M.e=NaN,M.d=null):u.e<t.minE?(M.e=0,M.d=[0]):(M.e=u.e,M.d=u.d.slice()):(M.e=u.e,M.d=u.d?u.d.slice():u.d);return}if(w=typeof u,w==="number"){if(u===0){M.s=1/u<0?-1:1,M.e=0,M.d=[0];return}if(u<0?(u=-u,M.s=-1):M.s=1,u===~~u&&u<1e7){for(d=0,v=u;v>=10;v/=10)d++;H?d>t.maxE?(M.e=NaN,M.d=null):d<t.minE?(M.e=0,M.d=[0]):(M.e=d,M.d=[u]):(M.e=d,M.d=[u]);return}if(u*0!==0){u||(M.s=NaN),M.e=NaN,M.d=null;return}return It(M,u.toString())}if(w==="string")return(v=u.charCodeAt(0))===45?(u=u.slice(1),M.s=-1):(v===43&&(u=u.slice(1)),M.s=1),sr.test(u)?It(M,u):Ur(M,u);if(w==="bigint")return u<0?(u=-u,M.s=-1):M.s=1,It(M,u.toString());throw Error(ft+u)}if(t.prototype=N,t.ROUND_UP=0,t.ROUND_DOWN=1,t.ROUND_CEIL=2,t.ROUND_FLOOR=3,t.ROUND_HALF_UP=4,t.ROUND_HALF_DOWN=5,t.ROUND_HALF_EVEN=6,t.ROUND_HALF_CEIL=7,t.ROUND_HALF_FLOOR=8,t.EUCLID=9,t.config=t.set=en,t.clone=cr,t.isDecimal=tr,t.abs=Zr,t.acos=zr,t.acosh=$r,t.add=Kr,t.asin=Hr,t.asinh=Wr,t.atan=Gr,t.atanh=Vr,t.atan2=Xr,t.cbrt=Qr,t.ceil=Yr,t.clamp=Jr,t.cos=tn,t.cosh=rn,t.div=nn,t.exp=on,t.floor=sn,t.hypot=an,t.ln=ln,t.log=un,t.log10=hn,t.log2=fn,t.max=cn,t.min=dn,t.mod=pn,t.mul=gn,t.pow=mn,t.random=vn,t.round=wn,t.sign=Mn,t.sin=yn,t.sinh=bn,t.sqrt=_n,t.sub=kn,t.sum=Sn,t.tan=Cn,t.tanh=An,t.trunc=Pn,i===void 0&&(i={}),i&&i.defaults!==!0)for(s=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],r=0;r<s.length;)i.hasOwnProperty(n=s[r++])||(i[n]=this[n]);return t.config(i),t}function nn(i,r){return new this(i).div(r)}function on(i){return new this(i).exp()}function sn(i){return z(i=new this(i),i.e+1,3)}function an(){var i,r,n=new this(0);for(H=!1,i=0;i<arguments.length;)if(r=new this(arguments[i++]),r.d)n.d&&(n=n.plus(r.times(r)));else{if(r.s)return H=!0,new this(1/0);n=r}return H=!0,n.sqrt()}function tr(i){return i instanceof wt||i&&i.toStringTag===or||!1}function ln(i){return new this(i).ln()}function un(i,r){return new this(i).log(r)}function fn(i){return new this(i).log(2)}function hn(i){return new this(i).log(10)}function cn(){return ur(this,arguments,-1)}function dn(){return ur(this,arguments,1)}function pn(i,r){return new this(i).mod(r)}function gn(i,r){return new this(i).mul(r)}function mn(i,r){return new this(i).pow(r)}function vn(i){var r,n,s,t,u=0,d=new this(1),v=[];if(i===void 0?i=this.precision:Ke(i,1,ht),s=Math.ceil(i/K),this.crypto)if(crypto.getRandomValues)for(r=crypto.getRandomValues(new Uint32Array(s));u<s;)t=r[u],t>=429e7?r[u]=crypto.getRandomValues(new Uint32Array(1))[0]:v[u++]=t%1e7;else if(crypto.randomBytes){for(r=crypto.randomBytes(s*=4);u<s;)t=r[u]+(r[u+1]<<8)+(r[u+2]<<16)+((r[u+3]&127)<<24),t>=214e7?crypto.randomBytes(4).copy(r,u):(v.push(t%1e7),u+=4);u=s/4}else throw Error(nr);else for(;u<s;)v[u++]=Math.random()*1e7|0;for(s=v[--u],i%=K,s&&i&&(t=Be(10,K-i),v[u]=(s/t|0)*t);v[u]===0;u--)v.pop();if(u<0)n=0,v=[0];else{for(n=-1;v[0]===0;n-=K)v.shift();for(s=1,t=v[0];t>=10;t/=10)s++;s<K&&(n-=K-s)}return d.e=n,d.d=v,d}function wn(i){return z(i=new this(i),i.e+1,this.rounding)}function Mn(i){return i=new this(i),i.d?i.d[0]?i.s:0*i.s:i.s||NaN}function yn(i){return new this(i).sin()}function bn(i){return new this(i).sinh()}function _n(i){return new this(i).sqrt()}function kn(i,r){return new this(i).sub(r)}function Sn(){var i=0,r=arguments,n=new this(r[i]);for(H=!1;n.s&&++i<r.length;)n=n.plus(r[i]);return H=!0,z(n,this.precision,this.rounding)}function Cn(i){return new this(i).tan()}function An(i){return new this(i).tanh()}function Pn(i){return z(i=new this(i),i.e+1,1)}N[Symbol.for("nodejs.util.inspect.custom")]=N.toString;N[Symbol.toStringTag]="Decimal";var wt=N.constructor=cr(di);Ot=new wt(Ot);Nt=new wt(Nt);var Ye=wt;var yi=ri(pr()),Je=require("@mysten/sui/transactions");var mt=require("@cetusprotocol/common-sdk"),gr=i=>{let r=[];return i.forEach(n=>{r.push(wi(n))}),r},wi=i=>{let r=(0,mt.getObjectFields)(i);return{marketId:r.id.id,baseToken:(0,mt.addHexPrefix)(r.base_token.fields.name),quoteToken:(0,mt.addHexPrefix)(r.quote_token.fields.name),isOpenPause:r.is_open_pause,isClosePause:r.is_close_pause,maxLongLeverage:r.max_long_leverage,maxShortLeverage:r.max_short_leverage,openFeeRate:(r.open_fee_rate/1e6).toString(),closeFeeRate:(r.close_fee_rate/1e6).toString(),positionsHandle:r.positions.fields.id.id}},Mi=i=>{let r=(0,mt.getObjectFields)(i);return{createdAt:r.created_ts,id:r.id.id,initDepositAmount:r.init_deposit_amount,isLong:r.is_long,lendingMarketId:r.lending_market_id,obligationOwnerCap:r.obligation_owner_cap.fields.obligation_id}};var st=require("@mysten/sui/utils"),mr=require("@suilend/sdk/parsers/obligation"),vr=require("@suilend/sdk/_generated/suilend/lending-market/functions"),Bt=class{constructor(r){this.getLeverageConfig=async()=>{let r=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.leverage);return(await this._sdk.FullClient.getObject({id:r.global_config_id,options:{showContent:!0}})).data.content.fields};this.getLeverageMarketsList=async(r=!1)=>{let n="leverage_markets_list",s=this._sdk.getCache(n,r);if(s)return s;let t=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.leverage),u=50,d=null,v=[];for(;;){let A=await this._sdk.FullClient.getDynamicFields({parentId:t.markets_table_id,limit:u,cursor:d});if(A.data.forEach(L=>{v.push(L.objectId)}),A.data.length<u)break;d=A.nextCursor}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:63 ~ LeverageModules ~ marketSimpleIdList:",v);let w=await this._sdk.FullClient.batchGetObjects(v,{showContent:!0}),M=[];w.forEach(A=>{M.push(A.data.content.fields.value.fields.market_id)});let _=await this._sdk.FullClient.batchGetObjects(M,{showContent:!0}),C=gr(_);return this._sdk.updateCache(n,C,O.CACHE_TIME_5MIN),C};this.getLeverageMarketInfo=async r=>{let n=`leverage_market_info_${r}`,s=this._sdk.getCache(n);if(s)return s;let t=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}}),u=wi(t);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:106 ~ LeverageModules ~ marketInfo:",u),this._sdk.updateCache(n,u,O.CACHE_TIME_5MIN),u};this.getLeveragePositionList=async()=>{let r=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{MatchAny:[{Package:this._sdk.sdkOptions.leverage.package_id}]}}),{lendingMarketId:n,lendingMarketType:s}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),t=await this._sdk.SuiLendModule.getSuilendClient(n,s),u=[];for(let d=0;d<r.data.length;d++){let v=Mi(r.data[d]),w=await t.getObligation(v.obligationOwnerCap);u.push({...v,...w})}return u};this.getLeveragePosition=async r=>{let n=await this._sdk.FullClient.getOwnedObjectsByPage(this._sdk.getSenderAddress(),{options:{showType:!0,showContent:!0,showOwner:!0},filter:{ObjectId:r}}),s=Mi(n.data[0]),{lendingMarketId:t,lendingMarketType:u}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),d=await this._sdk.SuiLendModule.getSuilendClient(t,u),{allLendingMarketData:v}=await this._sdk.SuiLendModule.getLendingMarketData(),w=v[t].reserveMap,M=await d.getObligation(s.obligationOwnerCap);return{...(0,mr.parseObligation)(M,w||{}),...s}};this.getClmmPoolInfo=async r=>{let n=await this._sdk.ClmmSDK.Pool.getPool(r),{coin_type_a:s,coin_type_b:t,fee_rate:u}=n;return{clmmFeeTier:u/1e6,clmmPoolCoinTypeA:s,clmmPoolCoinTypeB:t}};this.openLeveragePosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:u,slippage:d,leverage:v,marketId:w}=r,{lendingMarketId:M}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),_=new Je.Transaction,{openFeeRate:C,baseToken:A,quoteToken:L}=await this.getLeverageMarketInfo(w),{clmmFeeTier:B,clmmPoolCoinTypeA:R,clmmPoolCoinTypeB:j}=await this.getClmmPoolInfo(u);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:196 ~ LeverageModules ~ clmmFeeTier:",B,R,j);let{baseReserveArrayIndex:Z,quoteReserveArrayIndex:I,reserve:F}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(A,L),q=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ hasSwap:",q);let J=t.toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:203 ~ LeverageModules ~ initDepositAmount:",J);let $,V;if(q){let D=s&&n?L:A,U=s&&n?A:L,X=await this.findRouters(D,U,t,!0,[u]);if(J=X?.amount_out.toString(),X){let ee=O.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),D,_);V=await this.routerSwap({router:X.route_obj,slippage:d,inputCoin:ee,txb:_}),$=V}}else $=O.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),n?L:A,_);let{flashAmount:m}=await this.calculateFlashLoanParams({isLong:s,leverage:v,baseToken:A,quoteToken:L,initDepositAmount:J,reserve:F});console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:226 ~ LeverageModules ~ flashAmount:",m);let b=s?L:A;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",b);let k=R===b;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:240 ~ LeverageModules ~ clmmPoolCoinTypeA:",R),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",k);let x=(0,O.d)(m).mul(B).toString(),{balanceA:P,balanceB:c,receipt:e}=this.flashLoan({amount:(0,O.d)(m),clmmPool:u,clmmPoolCoinTypeA:R,clmmPoolCoinTypeB:j,flashLoanCoin:b,tx:_}),o=s?L:A,l=s?A:L,f=await this.findRouters(o,l,(0,O.d)(m),!0,[u]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:555 ~ LeverageModules ~ debtFrom:",{debtRouters:f,debtFrom:o,debtTo:l,clmmPoolCoinTypeA:R,clmmPoolCoinTypeB:j});let h=(0,O.d)(f?.amount_out||0),g;f&&(g=await this.routerSwap({router:f.route_obj,inputCoin:k?O.CoinAssist.fromBalance(P,R,_):O.CoinAssist.fromBalance(c,j,_),slippage:d,txb:_}));let S=(0,O.d)(h).add(J).mul(1-C).toDP(0,Ye.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:258 ~ LeverageModules ~ totalDepositAmount:",S,J,h);let p=this.createLeveragePosition({leverage:v,marketId:w,baseToken:A,quoteToken:L,isLong:s,totalDepositAmount:S,tx:_});for(let D=0;D<F.length;D++){let U=(0,st.toHEX)(new Uint8Array(F[D].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(_,U,BigInt(F[D].arrayIndex))}let a=s?Z:I;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:279 ~ LeverageModules ~ depositCoin:",$),await _.mergeCoins(g,[$]),await this.depositToLeveragePosition({isLong:s,marketId:w,position:p,depositReserveArrayIndex:a,inputCoin:g},_);let y=(0,O.d)(m).add(x).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:296 ~ LeverageModules ~ borrowAmount:",y,m,x);let E=await this.borrowAsset({position:p,reserveArrayIndex:s?I:Z,borrowAmount:(0,O.d)(y),baseToken:A,quoteToken:L,isLong:s,lendingMarketId:M},_);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:309 ~ LeverageModules ~ borrowCoin:",E);let T=O.CoinAssist.mintBalanceZero(k?j:R,_);return this.repayFlashLoan({tx:_,clmmPool:u,repayBase:k?O.CoinAssist.intoBalance(E,R,_):T,repayQuote:k?T:O.CoinAssist.intoBalance(E,j,_),receipt:e,clmmPoolCoinTypeA:R,clmmPoolCoinTypeB:j}),_.transferObjects([p],_.pure.address(this._sdk.getSenderAddress())),O.CoinAssist.destroyBalanceZero(k?c:P,k?j:R,_),_};this.positionManageSizeDeposit=async r=>{let{marketId:n,positionId:s,isQuote:t,depositAmount:u,clmmPool:d,slippage:v,leverage:w,txb:M}=r,{lendingMarketId:_}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{baseToken:C,quoteToken:A}=await this.getLeverageMarketInfo(n),{isLong:L,deposits:B,borrows:R}=await this.getLeveragePosition(s),{reserve:j}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(C,A),{clmmFeeTier:Z,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F}=await this.getClmmPoolInfo(d),q=M||new Je.Transaction,J=B[0].reserveArrayIndex.toString(),$=R[0].reserveArrayIndex.toString(),V=t&&L||!t&&!L,m;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:362 ~ LeverageModules ~ hasSwap:",V);let b;if(V){let E=t&&L?A:C,T=t&&L?C:A,D=await this.findRouters(E,T,u,!0,[d]);if(D){let U=O.CoinAssist.buildCoinWithBalance(BigInt(u.toString()),E,q);b=await this.routerSwap({router:D.route_obj,inputCoin:U,slippage:v,txb:q}),m=b}}else m=O.CoinAssist.buildCoinWithBalance(BigInt(u.toString()),t?A:C,q);let k=L?A:C;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:378 ~ LeverageModules ~ flashLoanCoin:",k);let{flashAmount:x}=await this.calculateFlashLoanParams({isLong:L,leverage:w,baseToken:C,quoteToken:A,initDepositAmount:u.toString(),reserve:j}),P=(0,O.d)(x).mul(Z).toString(),c=I===k;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:383 ~ LeverageModules ~ isFlashA:",c);let{balanceA:e,balanceB:o,receipt:l}=this.flashLoan({amount:(0,O.d)(x),clmmPool:d,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F,flashLoanCoin:k,tx:q}),f=L?A:C,h=L?C:A,g=await this.findRouters(f,h,(0,O.d)(x),!0,[d]),S;g&&(S=await this.routerSwap({router:g.route_obj,inputCoin:c?O.CoinAssist.fromBalance(e,I,q):O.CoinAssist.fromBalance(o,F,q),slippage:v,txb:q})),q.mergeCoins(S,[m]);for(let E=0;E<j.length;E++){let T=(0,st.toHEX)(new Uint8Array(j[E].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(q,T,BigInt(j[E].arrayIndex))}this.depositToLeveragePosition({isLong:L,marketId:n,positionId:s,depositReserveArrayIndex:J,inputCoin:S},q);let p=(0,O.d)(x).add(P).toDP(0,Ye.ROUND_UP).toString(),a=this.borrowAsset({positionId:s,reserveArrayIndex:$,borrowAmount:(0,O.d)(p),baseToken:C,quoteToken:A,isLong:L,lendingMarketId:_},q),y=O.CoinAssist.mintBalanceZero(c?F:I,q);return this.repayFlashLoan({tx:q,clmmPool:d,repayBase:c?O.CoinAssist.intoBalance(a,I,q):y,repayQuote:c?y:O.CoinAssist.intoBalance(a,F,q),receipt:l,clmmPoolCoinTypeA:I,clmmPoolCoinTypeB:F}),O.CoinAssist.destroyBalanceZero(c?o:e,c?F:I,q),q};this.positionManageSizeWithdraw=async r=>{let{marketId:n,positionId:s,withdrawAmount:t,isQuote:u,txb:d,clmmPool:v,slippage:w,leverage:M}=r,{lendingMarketType:_,lendingMarketId:C}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),A=d||new Je.Transaction,{baseToken:L,quoteToken:B}=await this.getLeverageMarketInfo(n),{isLong:R,deposits:j,borrows:Z}=await this.getLeveragePosition(s),{reserve:I}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(L,B),F=u&&R||!u&&!R;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:479 ~ LeverageModules ~ hasSwap:",F);let q=t;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:482 ~ LeverageModules ~ withdrawCtokenAmount:",q);let J=null;if(F){let S=L,p=B;J=await this.findRouters(S,p,t,!1,[v]),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ routers:",{hasSwapRouters:J,from:S,to:p}),q=J?.amount_in}console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:486 ~ LeverageModules ~ withdrawBorrowAmount:",q);for(let S=0;S<I.length;S++){let p=(0,st.toHEX)(new Uint8Array(I[S].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(A,p,BigInt(I[S].arrayIndex))}let{token:$}=Z[0].reserve,V=(0,O.d)(j[0].depositedCtokenAmount.toString()).div((0,O.d)(M)).toDP(0,Ye.ROUND_DOWN).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:502 ~ LeverageModules ~ cTokenAmount:",V);let m=(0,O.d)(q).div((0,O.d)(V)).toString(),b=(0,O.d)(Z[0].borrowedAmount.toString()).mul(10**$.decimals).toString(),k=(0,O.d)(b).mul(m).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:508 ~ LeverageModules ~ repayAmount:",{\u9700\u8981\u507F\u8FD8\u591A\u5C11borrowAmount:k,\u63D0\u53D6\u4FDD\u8BC1\u91D1\u6570\u91CF:q,\u73B0\u6709\u4FDD\u8BC1\u91D1\u6570\u91CF:V});let x=await this._sdk.SuiLendModule.getSuilendClient(C,_),P=await this._sdk.PythConnection.getPriceFeedsUpdateData([j[0].reserve.priceIdentifier]),c=await x.pythClient.updatePriceFeeds(A,P,[j[0].reserve.priceIdentifier]),e=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:(0,O.d)(q),withdrawReserveArrayIndex:j[0].reserveArrayIndex.toString(),withdrawCoinType:R?L:B,baseToken:L,quoteToken:B,priceObjectId:c&&c[0]},A),o=R?L:B,l=R?B:L;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:557 ~ LeverageModules ~ debtTo:",l);let f=await this.findRouters(o,l,(0,O.d)(k),!1,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:530 ~ LeverageModules ~ debtRouter:",{debtRouter:f,debtFrom:o,debtTo:l});let h;f&&(h=await this.routerSwap({router:f.route_obj,inputCoin:e,slippage:w,txb:A}));let g=A.splitCoins(h,[k]);return this.repay({txb:A,positionId:s,repayReserveArrayIndex:Z[0].reserveArrayIndex.toString(),repayCoin:g,repayCoinType:R?B:L,repayAmount:(0,O.d)(0)}),A.transferObjects([h,g],this._sdk.getSenderAddress()),A};this.positionManageLeverageIncrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:u,targetLeverage:d,clmmPool:v,slippage:w}=r,{baseToken:M,quoteToken:_}=await this.getLeverageMarketInfo(n),{deposits:C,borrows:A}=await this.getLeveragePosition(s),{reserve:L}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_),{clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:R,clmmFeeTier:j}=await this.getClmmPoolInfo(v),{lendingMarketId:Z}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{token:I}=A[0].reserve,F=new Je.Transaction,q=(0,O.d)(A[0].borrowedAmount.toString()).mul((0,O.d)(d).sub((0,O.d)(u))).mul(10**I.decimals).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:579 ~ LeverageModules ~ amount:",q);let J=q,$=t?_:M,{balanceA:V,balanceB:m,receipt:b}=this.flashLoan({tx:F,amount:(0,O.d)(J),clmmPool:v,clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:R,flashLoanCoin:$}),k=t?_:M,x=t?M:_,P=await this.findRouters(k,x,(0,O.d)(q),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:592 ~ LeverageModules ~ routers:",P,k,x);let c=await this.routerSwap({router:P?.route_obj,inputCoin:t?O.CoinAssist.fromBalance(m,R,F):O.CoinAssist.fromBalance(V,B,F),slippage:w,txb:F});for(let h=0;h<L.length;h++){let g=(0,st.toHEX)(new Uint8Array(L[h].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(F,g,BigInt(L[h].arrayIndex))}this.depositToLeveragePosition({isLong:t,marketId:n,positionId:s,depositReserveArrayIndex:t?C[0].reserveArrayIndex.toString():A[0].reserveArrayIndex.toString(),inputCoin:c},F);let e=(0,O.d)(J).mul((0,O.d)(1).add(j)).toDP(0,Ye.ROUND_UP).toString(),o=await this.borrowAsset({positionId:s,reserveArrayIndex:A[0].reserveArrayIndex.toString(),borrowAmount:(0,O.d)(e),baseToken:M,quoteToken:_,isLong:t,lendingMarketId:Z},F),l=O.CoinAssist.mintBalanceZero(t?M:_,F),f=B===$;return this.repayFlashLoan({tx:F,clmmPool:v,repayBase:t?l:O.CoinAssist.intoBalance(o,M,F),repayQuote:t?O.CoinAssist.intoBalance(o,_,F):l,receipt:b,clmmPoolCoinTypeA:B,clmmPoolCoinTypeB:R}),O.CoinAssist.destroyBalanceZero(f?m:V,f?R:B,F),F};this.positionManageLeverageDecrease=async r=>{let{marketId:n,positionId:s,isLong:t,currentLeverage:u,targetLeverage:d,clmmPool:v,slippage:w}=r,{baseToken:M,quoteToken:_,closeFeeRate:C}=await this.getLeverageMarketInfo(n),{deposits:A,borrows:L}=await this.getLeveragePosition(s),{reserve:B}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_),{lendingMarketId:R,lendingMarketType:j}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),Z=new Je.Transaction,I=(0,O.d)(A[0].depositedCtokenAmount.toString()).mul((0,O.d)(u).sub((0,O.d)(d))).toString(),F=(0,O.d)(I).toDP(0,Ye.ROUND_UP).toString();console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:654 ~ LeverageModules ~ withdrawCtokenAmount:",F);for(let P=0;P<B.length;P++){let c=(0,st.toHEX)(new Uint8Array(B[P].priceIdentifier.bytes));await this._sdk.SuiLendModule.refreshReservePrices(Z,c,BigInt(B[P].arrayIndex))}let q=await this._sdk.SuiLendModule.getSuilendClient(R,j),J=await this._sdk.PythConnection.getPriceFeedsUpdateData([A[0].reserve.priceIdentifier]),$=await q.pythClient.updatePriceFeeds(Z,J,[A[0].reserve.priceIdentifier]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:672 ~ LeverageModules ~ baseToken:",M);let V=this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:(0,O.d)(F),withdrawReserveArrayIndex:A[0].reserveArrayIndex.toString(),withdrawCoinType:t?M:_,baseToken:M,quoteToken:_,priceObjectId:$&&$[0]},Z),m=t?M:_,b=t?_:M,k=await this.findRouters(m,b,(0,O.d)(F),!0,[v]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:681 ~ LeverageModules ~ routers:",k,k?.route_obj.paths,m,b);let x=await this.routerSwap({router:k?.route_obj,inputCoin:V,slippage:w,txb:Z});return this.repay({txb:Z,positionId:s,repayReserveArrayIndex:L[0].reserveArrayIndex.toString(),repayCoin:x,repayCoinType:t?_:M,repayAmount:(0,O.d)(0)}),x&&Z.transferObjects([x],this._sdk.getSenderAddress()),Z};this.leveragePositionClose=async(r,n)=>{let s=n||new Je.Transaction,{marketId:t,positionId:u}=r,{leverage:d}=this._sdk.sdkOptions,{global_config_id:v}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.leverage),{lendingMarketType:w,lendingMarketId:M}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{baseToken:_,quoteToken:C}=await this.getLeverageMarketInfo(t),A=await this.getLeveragePosition(u);return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:719 ~ LeverageModules ~ positionInfo:",A.original.id),s.moveCall({target:`${d.published_at}::position::close_Position`,typeArguments:[w,_,C],arguments:[s.object(v),s.object(t),s.object(u),(0,vr.obligation)(s,w,{obligationId:A.original.id,lendingMarket:s.object(M)}),s.object(O.CLOCK_ADDRESS)]}),s};this.positionRepay=async r=>{let{marketId:n,positionId:s,amount:t,isQuote:u,clmmPool:d,slippage:v}=r,{baseToken:w,quoteToken:M,isLong:_}=await this.getLeverageMarketInfo(n),{deposits:C,borrows:A}=await this.getLeveragePosition(s),{token:L}=A[0].reserve,B=(0,O.d)(A[0].borrowedAmount.toString()).mul(10**L.decimals),R=new Je.Transaction,j=A[0].reserve.coinType;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:751 ~ LeverageModules ~ repayCoinType:",j);let Z=u?M==j:w==j,I,F=!1;if(Z){let q=await this.findRouters(_?w:M,j,t,!0,[d]);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:756 ~ LeverageModules ~ routers:",q?.amount_out.toString(),B.toString()),(0,O.d)(q?.amount_out.toString()).gte(B)&&(F=!0);let J=O.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),_?w:M,R);I=await this.routerSwap({router:q?.route_obj,inputCoin:J,slippage:v,txb:R})}else t.gte(B)&&(F=!0),I=O.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),_?M:w,R);if(this.repay({txb:R,positionId:s,repayReserveArrayIndex:A[0].reserveArrayIndex.toString(),repayCoin:I,repayCoinType:_?M:w,repayAmount:(0,O.d)(0)}),R.transferObjects([I],this._sdk.getSenderAddress()),console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:786 ~ LeverageModules ~ isClose:",F),F){let{lendingMarketType:q,lendingMarketId:J}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),$=await this._sdk.SuiLendModule.getSuilendClient(J,q),V=await this._sdk.PythConnection.getPriceFeedsUpdateData([C[0].reserve.priceIdentifier]),m=await $.pythClient.updatePriceFeeds(R,V,[C[0].reserve.priceIdentifier]);this.withdrawAsset({marketId:n,positionId:s,withdrawAmount:(0,O.d)(C[0].depositedCtokenAmount.toString()),withdrawReserveArrayIndex:C[0].reserveArrayIndex.toString(),withdrawCoinType:_?w:M,baseToken:w,quoteToken:M,priceObjectId:m&&m[0]},R),this.leveragePositionClose({marketId:n,positionId:s},R)}return R};this.positionTopUpCoken=async r=>{let{marketId:n,positionId:s,amount:t,isQuote:u,clmmPool:d,slippage:v}=r,w=new Je.Transaction,{baseToken:M,quoteToken:_}=await this.getLeverageMarketInfo(n),{isLong:C}=await this.getLeveragePosition(s),A=C&&u||!C&&!u,L;if(A){let Z=await this.findRouters(u?_:M,u?M:_,t,!0,[d]),I=O.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),u?_:M,w);L=await this.routerSwap({router:Z?.route_obj,inputCoin:I,slippage:v,txb:w})}else L=O.CoinAssist.buildCoinWithBalance(BigInt(t.toString()),u?_:M,w);let{baseReserveArrayIndex:B,quoteReserveArrayIndex:R,reserve:j}=await this._sdk.SuiLendModule.getSuiLendReserveInfo(M,_);return this.depositToLeveragePosition({isLong:C,marketId:n,positionId:s,depositReserveArrayIndex:C?B:R,inputCoin:L},w),w};this.flashLoan=r=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:698 ~ LeverageModules ~ params:",r);let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:s}=(0,O.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{amount:t,clmmPool:u,clmmPoolCoinTypeA:d,clmmPoolCoinTypeB:v,flashLoanCoin:w,tx:M}=r,_=d===w,[C,A,L]=M.moveCall({target:`${n.published_at}::pool::flash_loan`,arguments:[M.object(s),M.object(u),M.pure.bool(_),M.pure.u64(t.toString())],typeArguments:[d,v]});return{balanceA:C,balanceB:A,receipt:L}};this.repayFlashLoan=r=>{let{clmm_pool:n}=this._sdk.ClmmSDK.sdkOptions,{global_config_id:s}=(0,O.getPackagerConfigs)(this._sdk.ClmmSDK.sdkOptions.clmm_pool),{tx:t,repayBase:u,repayQuote:d,receipt:v,clmmPool:w,clmmPoolCoinTypeA:M,clmmPoolCoinTypeB:_}=r;return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:612 ~ LeverageModules ~ params:",r),t.moveCall({target:`${n.published_at}::pool::repay_flash_loan`,arguments:[t.object(s),t.object(w),u,d,v],typeArguments:[M,_]}),t};this.borrowAsset=(r,n)=>{let{position:s,reserveArrayIndex:t,borrowAmount:u,baseToken:d,quoteToken:v,lendingMarketId:w,isLong:M,positionId:_}=r;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:677 ~ LeverageModules ~ params:",r);let{leverage:C}=this._sdk.sdkOptions,{lendingMarketType:A}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend);return O.CoinAssist.isSuiCoin(M?v:d)?n.moveCall({target:`${C.published_at}::position::borrow_sui`,typeArguments:[A],arguments:[n.object(w),s,n.pure.u64(t),n.pure.u64(u.toString()),n.object(st.SUI_SYSTEM_STATE_OBJECT_ID),n.object(O.CLOCK_ADDRESS)]}):n.moveCall({target:`${C.published_at}::position::borrow_not_sui`,typeArguments:[A,M?v:d],arguments:[n.object(w),_?n.object(_):s,n.pure.u64(t),n.pure.u64(u.toString()),n.object(O.CLOCK_ADDRESS)]})};this.withdrawAsset=(r,n)=>{console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:749 ~ LeverageModules ~ params:",r);let{leverage:s}=this._sdk.sdkOptions,{lendingMarketId:t,lendingMarketType:u}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{package_id:d}=this._sdk.sdkOptions.suilend,{marketId:v,positionId:w,withdrawAmount:M,withdrawReserveArrayIndex:_,withdrawCoinType:C,baseToken:A,quoteToken:L,priceObjectId:B}=r,[R]=n.moveCall({target:"0x1::option::none",typeArguments:[`${d}::lending_market::RateLimiterExemption<${u}, ${C}>`],arguments:[]});return O.CoinAssist.isSuiCoin(C)?n.moveCall({target:`${s.published_at}::position::withdraw_sui`,typeArguments:[u,A,L],arguments:[n.object(t),n.object(v),n.object(w),n.object(B),n.object(R),n.pure.u64(M.toString()),n.pure.u64(_),n.object(st.SUI_SYSTEM_STATE_OBJECT_ID),n.object(O.CLOCK_ADDRESS)]}):n.moveCall({target:`${s.published_at}::position::withdraw_not_sui`,typeArguments:[u,A,L,C],arguments:[n.object(t),n.object(v),n.object(w),n.object(B),n.object(R),n.pure.u64(M.toString()),n.pure.u64(_),n.object(O.CLOCK_ADDRESS)]})};this.repay=r=>{let{leverage:n}=this._sdk.sdkOptions,{lendingMarketId:s,lendingMarketType:t}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{txb:u,positionId:d,repayAmount:v,repayCoinType:w,repayCoin:M,repayReserveArrayIndex:_}=r,C=u||new Je.Transaction,A=M||O.CoinAssist.buildCoinWithBalance(BigInt(v.toString()),w,C);C.moveCall({target:`${n.published_at}::position::repay`,typeArguments:[t,w],arguments:[C.object(s),C.object(d),A,C.pure.u64(_.toString()),C.object(O.CLOCK_ADDRESS)]})};this.routerSwap=async r=>{let{slippage:n,txb:s,inputCoin:t,router:u}=r,d=s||new Je.Transaction;if(u)return await this._sdk.AggregatorClient.routerSwap({router:u,inputCoin:t,slippage:n,txb:d})};this.calculateOpenPosition=async r=>{let{isQuote:n,isLong:s,depositAmount:t,clmmPool:u,slippage:d,leverage:v,baseToken:w,quoteToken:M}=r,_=s&&n||!s&&!n;console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:1193 ~ LeverageModules ~ hasSwap:",_);let C=(0,O.d)(t).mul(v);if(_){let A=s&&n?M:w,L=s&&n?w:M,B=await this.findRouters(A,L,C,!0,[u]);return{amountIn:B?.amount_in.toString(),amountOut:B?.amount_out.toString(),amountOutLimit:(0,O.d)(B?.amount_out.toString()).mul((0,O.d)(1).sub(d)).toDP(0,Ye.ROUND_DOWN).toString()}}else return{amountIn:t.toString(),amountOut:C.toString(),amountOutLimit:C.toString()}};this._sdk=r}async calculateFlashLoanParams(r){let{isLong:n,leverage:s,baseToken:t,quoteToken:u,initDepositAmount:d,reserve:v}=r,w=await this._sdk.SuiLendModule.getLatestPriceFeeds(v);console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:587 ~ LeverageModules ~ calculateFlashLoanParams ~ priceUpdateData:",w,u,t);let M=w[(0,O.removeHexPrefix)(u)]?.price,_=w[(0,O.removeHexPrefix)(t)]?.price,C=n?(0,O.d)(_).div((0,O.d)(M)).toString():(0,O.d)(M).div((0,O.d)(_)).toString();return console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:136 ~ LeverageModules ~ rate:",d.toString(),n,C,M,_),{flashAmount:(0,O.d)(d).mul(s-1).mul(C).toDP(0,Ye.ROUND_UP).toString(),rate:C,quotePrice:M,basePrice:_}}createLeveragePosition(r){let{lendingMarketId:n,lendingMarketType:s}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{global_config_id:t}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.leverage),u=this._sdk.sdkOptions.leverage,{leverage:d,marketId:v,baseToken:w,quoteToken:M,isLong:_,totalDepositAmount:C,tx:A}=r;return A.moveCall({target:`${u.published_at}::position::open_position`,arguments:[A.object(t),A.object(v),A.object(n),A.pure.u64(C),A.pure.u64(d*1e4),A.object(O.CLOCK_ADDRESS)],typeArguments:[s,w,M,_?w:M]})}async depositToLeveragePosition(r,n){console.log("\u{1F680}\u{1F680}\u{1F680} ~ leverageModules.ts:651 ~ LeverageModules ~ depositToLeveragePosition ~ params:",r);let{leverage:s}=this._sdk.sdkOptions,{lendingMarketType:t,lendingMarketId:u}=(0,O.getPackagerConfigs)(this._sdk.sdkOptions.suilend),{isLong:d,marketId:v,position:w,positionId:M,depositReserveArrayIndex:_,inputCoin:C}=r,{baseToken:A,quoteToken:L}=await this.getLeverageMarketInfo(v);return n.moveCall({target:`${s.published_at}::position::deposit`,typeArguments:[t,A,L,d?A:L],arguments:[n.object(u),n.object(v),w||n.object(M),C,n.pure.u64(_),n.object(O.CLOCK_ADDRESS)]}),n}async findRouters(r,n,s,t,u){let{providers:d}=this._sdk.sdkOptions;try{let v={from:r,target:n,amount:new yi.default(s.toFixed(0).toString()),byAmountIn:t,depth:3,providers:d},w=await this._sdk.AggregatorClient.findRouters(v);if(w?.error?.code===10001)return{...w,is_exceed:w.insufficientLiquidity};if(w?.insufficientLiquidity)return{...w,is_exceed:w.insufficientLiquidity};if(!w?.paths||w?.paths?.length===0)throw Error("Aggregator no router");return{amount_in:w.amountIn.toString(),amount_out:w.amountOut.toString(),is_exceed:w.insufficientLiquidity,route_obj:w,byAmountIn:!0,originRes:w}}catch{try{if(u){let w=await this._sdk.AggregatorClient.swapInPools({from:r,target:n,amount:new yi.default(s.toFixed(0).toString()),byAmountIn:t,pools:u});return w?{amount_in:w.routeData.amountIn.toString(),amount_out:w.routeData.amountOut.toString(),is_exceed:w.isExceed,route_obj:w.routeData,byAmountIn:!0,originRes:w}:null}return null}catch{return null}}}};var Mt=require("@cetusprotocol/aggregator-sdk"),Mr=require("@mysten/sui/utils"),yr=require("@mysten/sui/client"),br=require("@cetusprotocol/sui-clmm-sdk"),_r=require("@pythnetwork/pyth-sui-js"),yt=class i extends wr.SdkWrapper{constructor(r,n){super(r),this._suilendModule=new xt(this),this._leverageModules=new Bt(this),this._aggregatorClient=new Mt.AggregatorClient({signer:(0,Mr.normalizeSuiAddress)("0x0"),client:r.sui_client||new yr.SuiClient({url:r.full_rpc_url}),env:r.env==="testnet"?Mt.Env.Testnet:Mt.Env.Mainnet,pythUrls:r.pyth_urls}),this._clmmSDK=n||br.CetusClmmSDK.createSDK({env:r.env,full_rpc_url:r.full_rpc_url}),this._pythConnection=new _r.SuiPriceServiceConnection("https://hermes.pyth.network",{timeout:30*1e3})}get SuiLendModule(){return this._suilendModule}get LeverageModules(){return this._leverageModules}get AggregatorClient(){return this._aggregatorClient}get ClmmSDK(){return this._clmmSDK}get PythConnection(){return this._pythConnection}static createSDK(r){return i.createCustomSDK({...ni,...r})}static createCustomSDK(r){return new i(r)}};var xn=yt;0&&(module.exports={CetusLeverageSDK,leverage_mainnet});
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
decimal.js/decimal.mjs:
|